]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.9.9-201307050017.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.9.9-201307050017.patch
CommitLineData
1698fd10
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 9591325..1457ef3 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 738fcba..7a43500 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..510061e 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@@ -63,11 +64,35 @@ extern int __put_user_bad(void);
2117 static inline void set_fs(mm_segment_t fs)
2118 {
2119 current_thread_info()->addr_limit = fs;
2120- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2121+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2122 }
2123
2124 #define segment_eq(a,b) ((a) == (b))
2125
2126+static inline void pax_open_userland(void)
2127+{
2128+
2129+#ifdef CONFIG_PAX_MEMORY_UDEREF
2130+ if (segment_eq(get_fs(), USER_DS) {
2131+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2132+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2133+ }
2134+#endif
2135+
2136+}
2137+
2138+static inline void pax_close_userland(void)
2139+{
2140+
2141+#ifdef CONFIG_PAX_MEMORY_UDEREF
2142+ if (segment_eq(get_fs(), USER_DS) {
2143+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2144+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2145+ }
2146+#endif
2147+
2148+}
2149+
2150 #define __addr_ok(addr) ({ \
2151 unsigned long flag; \
2152 __asm__("cmp %2, %0; movlo %0, #0" \
2153@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2154
2155 #define get_user(x,p) \
2156 ({ \
2157+ int __e; \
2158 might_fault(); \
2159- __get_user_check(x,p); \
2160+ pax_open_userland(); \
2161+ __e = __get_user_check(x,p); \
2162+ pax_close_userland(); \
2163+ __e; \
2164 })
2165
2166 extern int __put_user_1(void *, unsigned int);
2167@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2168
2169 #define put_user(x,p) \
2170 ({ \
2171+ int __e; \
2172 might_fault(); \
2173- __put_user_check(x,p); \
2174+ pax_open_userland(); \
2175+ __e = __put_user_check(x,p); \
2176+ pax_close_userland(); \
2177+ __e; \
2178 })
2179
2180 #else /* CONFIG_MMU */
2181@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2182 #define __get_user(x,ptr) \
2183 ({ \
2184 long __gu_err = 0; \
2185+ pax_open_userland(); \
2186 __get_user_err((x),(ptr),__gu_err); \
2187+ pax_close_userland(); \
2188 __gu_err; \
2189 })
2190
2191 #define __get_user_error(x,ptr,err) \
2192 ({ \
2193+ pax_open_userland(); \
2194 __get_user_err((x),(ptr),err); \
2195+ pax_close_userland(); \
2196 (void) 0; \
2197 })
2198
2199@@ -312,13 +349,17 @@ do { \
2200 #define __put_user(x,ptr) \
2201 ({ \
2202 long __pu_err = 0; \
2203+ pax_open_userland(); \
2204 __put_user_err((x),(ptr),__pu_err); \
2205+ pax_close_userland(); \
2206 __pu_err; \
2207 })
2208
2209 #define __put_user_error(x,ptr,err) \
2210 ({ \
2211+ pax_open_userland(); \
2212 __put_user_err((x),(ptr),err); \
2213+ pax_close_userland(); \
2214 (void) 0; \
2215 })
2216
2217@@ -418,11 +459,44 @@ do { \
2218
2219
2220 #ifdef CONFIG_MMU
2221-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2222-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2223+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2224+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2225+
2226+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2227+{
2228+ unsigned long ret;
2229+
2230+ check_object_size(to, n, false);
2231+ pax_open_userland();
2232+ ret = ___copy_from_user(to, from, n);
2233+ pax_close_userland();
2234+ return ret;
2235+}
2236+
2237+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2238+{
2239+ unsigned long ret;
2240+
2241+ check_object_size(from, n, true);
2242+ pax_open_userland();
2243+ ret = ___copy_to_user(to, from, n);
2244+ pax_close_userland();
2245+ return ret;
2246+}
2247+
2248 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, 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(void __user *addr, unsigned long n);
2251 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2252+
2253+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2254+{
2255+ unsigned long ret;
2256+ pax_open_userland();
2257+ ret = ___clear_user(addr, n);
2258+ pax_close_userland();
2259+ return ret;
2260+}
2261+
2262 #else
2263 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2264 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2265@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2266
2267 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2268 {
2269+ if ((long)n < 0)
2270+ return n;
2271+
2272 if (access_ok(VERIFY_READ, from, n))
2273 n = __copy_from_user(to, from, n);
2274 else /* security hole - plug it */
2275@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2276
2277 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2278 {
2279+ if ((long)n < 0)
2280+ return n;
2281+
2282 if (access_ok(VERIFY_WRITE, to, n))
2283 n = __copy_to_user(to, from, n);
2284 return n;
2285diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2286index 96ee092..37f1844 100644
2287--- a/arch/arm/include/uapi/asm/ptrace.h
2288+++ b/arch/arm/include/uapi/asm/ptrace.h
2289@@ -73,7 +73,7 @@
2290 * ARMv7 groups of PSR bits
2291 */
2292 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2293-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2294+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2295 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2296 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2297
2298diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2299index 60d3b73..e5a0f22 100644
2300--- a/arch/arm/kernel/armksyms.c
2301+++ b/arch/arm/kernel/armksyms.c
2302@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2303
2304 /* networking */
2305 EXPORT_SYMBOL(csum_partial);
2306-EXPORT_SYMBOL(csum_partial_copy_from_user);
2307+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2308 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2309 EXPORT_SYMBOL(__csum_ipv6_magic);
2310
2311@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2312 #ifdef CONFIG_MMU
2313 EXPORT_SYMBOL(copy_page);
2314
2315-EXPORT_SYMBOL(__copy_from_user);
2316-EXPORT_SYMBOL(__copy_to_user);
2317-EXPORT_SYMBOL(__clear_user);
2318+EXPORT_SYMBOL(___copy_from_user);
2319+EXPORT_SYMBOL(___copy_to_user);
2320+EXPORT_SYMBOL(___clear_user);
2321
2322 EXPORT_SYMBOL(__get_user_1);
2323 EXPORT_SYMBOL(__get_user_2);
2324diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2325index 0f82098..fb3d3d5 100644
2326--- a/arch/arm/kernel/entry-armv.S
2327+++ b/arch/arm/kernel/entry-armv.S
2328@@ -47,6 +47,87 @@
2329 9997:
2330 .endm
2331
2332+ .macro pax_enter_kernel
2333+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2334+ @ make aligned space for saved DACR
2335+ sub sp, sp, #8
2336+ @ save regs
2337+ stmdb sp!, {r1, r2}
2338+ @ read DACR from cpu_domain into r1
2339+ mov r2, sp
2340+ @ assume 8K pages, since we have to split the immediate in two
2341+ bic r2, r2, #(0x1fc0)
2342+ bic r2, r2, #(0x3f)
2343+ ldr r1, [r2, #TI_CPU_DOMAIN]
2344+ @ store old DACR on stack
2345+ str r1, [sp, #8]
2346+#ifdef CONFIG_PAX_KERNEXEC
2347+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2348+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2349+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2350+#endif
2351+#ifdef CONFIG_PAX_MEMORY_UDEREF
2352+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2353+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2354+#endif
2355+ @ write r1 to current_thread_info()->cpu_domain
2356+ str r1, [r2, #TI_CPU_DOMAIN]
2357+ @ write r1 to DACR
2358+ mcr p15, 0, r1, c3, c0, 0
2359+ @ instruction sync
2360+ instr_sync
2361+ @ restore regs
2362+ ldmia sp!, {r1, r2}
2363+#endif
2364+ .endm
2365+
2366+ .macro pax_open_userland
2367+#ifdef CONFIG_PAX_MEMORY_UDEREF
2368+ @ save regs
2369+ stmdb sp!, {r0, r1}
2370+ @ read DACR from cpu_domain into r1
2371+ mov r0, sp
2372+ @ assume 8K pages, since we have to split the immediate in two
2373+ bic r0, r0, #(0x1fc0)
2374+ bic r0, r0, #(0x3f)
2375+ ldr r1, [r0, #TI_CPU_DOMAIN]
2376+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2377+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2378+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2379+ @ write r1 to current_thread_info()->cpu_domain
2380+ str r1, [r0, #TI_CPU_DOMAIN]
2381+ @ write r1 to DACR
2382+ mcr p15, 0, r1, c3, c0, 0
2383+ @ instruction sync
2384+ instr_sync
2385+ @ restore regs
2386+ ldmia sp!, {r0, r1}
2387+#endif
2388+ .endm
2389+
2390+ .macro pax_close_userland
2391+#ifdef CONFIG_PAX_MEMORY_UDEREF
2392+ @ save regs
2393+ stmdb sp!, {r0, r1}
2394+ @ read DACR from cpu_domain into r1
2395+ mov r0, sp
2396+ @ assume 8K pages, since we have to split the immediate in two
2397+ bic r0, r0, #(0x1fc0)
2398+ bic r0, r0, #(0x3f)
2399+ ldr r1, [r0, #TI_CPU_DOMAIN]
2400+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2401+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2402+ @ write r1 to current_thread_info()->cpu_domain
2403+ str r1, [r0, #TI_CPU_DOMAIN]
2404+ @ write r1 to DACR
2405+ mcr p15, 0, r1, c3, c0, 0
2406+ @ instruction sync
2407+ instr_sync
2408+ @ restore regs
2409+ ldmia sp!, {r0, r1}
2410+#endif
2411+ .endm
2412+
2413 .macro pabt_helper
2414 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2415 #ifdef MULTI_PABORT
2416@@ -89,11 +170,15 @@
2417 * Invalid mode handlers
2418 */
2419 .macro inv_entry, reason
2420+
2421+ pax_enter_kernel
2422+
2423 sub sp, sp, #S_FRAME_SIZE
2424 ARM( stmib sp, {r1 - lr} )
2425 THUMB( stmia sp, {r0 - r12} )
2426 THUMB( str sp, [sp, #S_SP] )
2427 THUMB( str lr, [sp, #S_LR] )
2428+
2429 mov r1, #\reason
2430 .endm
2431
2432@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2433 .macro svc_entry, stack_hole=0
2434 UNWIND(.fnstart )
2435 UNWIND(.save {r0 - pc} )
2436+
2437+ pax_enter_kernel
2438+
2439 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2440+
2441 #ifdef CONFIG_THUMB2_KERNEL
2442 SPFIX( str r0, [sp] ) @ temporarily saved
2443 SPFIX( mov r0, sp )
2444@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2445 ldmia r0, {r3 - r5}
2446 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2447 mov r6, #-1 @ "" "" "" ""
2448+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2449+ @ offset sp by 8 as done in pax_enter_kernel
2450+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2451+#else
2452 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2453+#endif
2454 SPFIX( addeq r2, r2, #4 )
2455 str r3, [sp, #-4]! @ save the "real" r0 copied
2456 @ from the exception stack
2457@@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2458 .macro usr_entry
2459 UNWIND(.fnstart )
2460 UNWIND(.cantunwind ) @ don't unwind the user space
2461+
2462+ pax_enter_kernel_user
2463+
2464 sub sp, sp, #S_FRAME_SIZE
2465 ARM( stmib sp, {r1 - r12} )
2466 THUMB( stmia sp, {r0 - r12} )
2467@@ -456,7 +553,9 @@ __und_usr:
2468 tst r3, #PSR_T_BIT @ Thumb mode?
2469 bne __und_usr_thumb
2470 sub r4, r2, #4 @ ARM instr at LR - 4
2471+ pax_open_userland
2472 1: ldrt r0, [r4]
2473+ pax_close_userland
2474 #ifdef CONFIG_CPU_ENDIAN_BE8
2475 rev r0, r0 @ little endian instruction
2476 #endif
2477@@ -491,10 +590,14 @@ __und_usr_thumb:
2478 */
2479 .arch armv6t2
2480 #endif
2481+ pax_open_userland
2482 2: ldrht r5, [r4]
2483+ pax_close_userland
2484 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2485 blo __und_usr_fault_16 @ 16bit undefined instruction
2486+ pax_open_userland
2487 3: ldrht r0, [r2]
2488+ pax_close_userland
2489 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2490 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2491 orr r0, r0, r5, lsl #16
2492@@ -733,7 +836,7 @@ ENTRY(__switch_to)
2493 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2494 THUMB( str sp, [ip], #4 )
2495 THUMB( str lr, [ip], #4 )
2496-#ifdef CONFIG_CPU_USE_DOMAINS
2497+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2498 ldr r6, [r2, #TI_CPU_DOMAIN]
2499 #endif
2500 set_tls r3, r4, r5
2501@@ -742,7 +845,7 @@ ENTRY(__switch_to)
2502 ldr r8, =__stack_chk_guard
2503 ldr r7, [r7, #TSK_STACK_CANARY]
2504 #endif
2505-#ifdef CONFIG_CPU_USE_DOMAINS
2506+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2507 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2508 #endif
2509 mov r5, r0
2510diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2511index fefd7f9..e6f250e 100644
2512--- a/arch/arm/kernel/entry-common.S
2513+++ b/arch/arm/kernel/entry-common.S
2514@@ -10,18 +10,46 @@
2515
2516 #include <asm/unistd.h>
2517 #include <asm/ftrace.h>
2518+#include <asm/domain.h>
2519 #include <asm/unwind.h>
2520
2521+#include "entry-header.S"
2522+
2523 #ifdef CONFIG_NEED_RET_TO_USER
2524 #include <mach/entry-macro.S>
2525 #else
2526 .macro arch_ret_to_user, tmp1, tmp2
2527+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2528+ @ save regs
2529+ stmdb sp!, {r1, r2}
2530+ @ read DACR from cpu_domain into r1
2531+ mov r2, sp
2532+ @ assume 8K pages, since we have to split the immediate in two
2533+ bic r2, r2, #(0x1fc0)
2534+ bic r2, r2, #(0x3f)
2535+ ldr r1, [r2, #TI_CPU_DOMAIN]
2536+#ifdef CONFIG_PAX_KERNEXEC
2537+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2538+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2539+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2540+#endif
2541+#ifdef CONFIG_PAX_MEMORY_UDEREF
2542+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2543+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2544+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2545+#endif
2546+ @ write r1 to current_thread_info()->cpu_domain
2547+ str r1, [r2, #TI_CPU_DOMAIN]
2548+ @ write r1 to DACR
2549+ mcr p15, 0, r1, c3, c0, 0
2550+ @ instruction sync
2551+ instr_sync
2552+ @ restore regs
2553+ ldmia sp!, {r1, r2}
2554+#endif
2555 .endm
2556 #endif
2557
2558-#include "entry-header.S"
2559-
2560-
2561 .align 5
2562 /*
2563 * This is the fast syscall return path. We do as little as
2564@@ -351,6 +379,7 @@ ENDPROC(ftrace_stub)
2565
2566 .align 5
2567 ENTRY(vector_swi)
2568+
2569 sub sp, sp, #S_FRAME_SIZE
2570 stmia sp, {r0 - r12} @ Calling r0 - r12
2571 ARM( add r8, sp, #S_PC )
2572@@ -400,6 +429,12 @@ ENTRY(vector_swi)
2573 ldr scno, [lr, #-4] @ get SWI instruction
2574 #endif
2575
2576+ /*
2577+ * do this here to avoid a performance hit of wrapping the code above
2578+ * that directly dereferences userland to parse the SWI instruction
2579+ */
2580+ pax_enter_kernel_user
2581+
2582 #ifdef CONFIG_ALIGNMENT_TRAP
2583 ldr ip, __cr_alignment
2584 ldr ip, [ip]
2585diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2586index 9a8531e..812e287 100644
2587--- a/arch/arm/kernel/entry-header.S
2588+++ b/arch/arm/kernel/entry-header.S
2589@@ -73,9 +73,66 @@
2590 msr cpsr_c, \rtemp @ switch back to the SVC mode
2591 .endm
2592
2593+ .macro pax_enter_kernel_user
2594+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2595+ @ save regs
2596+ stmdb sp!, {r0, r1}
2597+ @ read DACR from cpu_domain into r1
2598+ mov r0, sp
2599+ @ assume 8K pages, since we have to split the immediate in two
2600+ bic r0, r0, #(0x1fc0)
2601+ bic r0, r0, #(0x3f)
2602+ ldr r1, [r0, #TI_CPU_DOMAIN]
2603+#ifdef CONFIG_PAX_MEMORY_UDEREF
2604+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2605+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2606+#endif
2607+#ifdef CONFIG_PAX_KERNEXEC
2608+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2609+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2610+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2611+#endif
2612+ @ write r1 to current_thread_info()->cpu_domain
2613+ str r1, [r0, #TI_CPU_DOMAIN]
2614+ @ write r1 to DACR
2615+ mcr p15, 0, r1, c3, c0, 0
2616+ @ instruction sync
2617+ instr_sync
2618+ @ restore regs
2619+ ldmia sp!, {r0, r1}
2620+#endif
2621+ .endm
2622+
2623+ .macro pax_exit_kernel
2624+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625+ @ save regs
2626+ stmdb sp!, {r0, r1}
2627+ @ read old DACR from stack into r1
2628+ ldr r1, [sp, #(8 + S_SP)]
2629+ sub r1, r1, #8
2630+ ldr r1, [r1]
2631+
2632+ @ write r1 to current_thread_info()->cpu_domain
2633+ mov r0, sp
2634+ @ assume 8K pages, since we have to split the immediate in two
2635+ bic r0, r0, #(0x1fc0)
2636+ bic r0, r0, #(0x3f)
2637+ str r1, [r0, #TI_CPU_DOMAIN]
2638+ @ write r1 to DACR
2639+ mcr p15, 0, r1, c3, c0, 0
2640+ @ instruction sync
2641+ instr_sync
2642+ @ restore regs
2643+ ldmia sp!, {r0, r1}
2644+#endif
2645+ .endm
2646+
2647 #ifndef CONFIG_THUMB2_KERNEL
2648 .macro svc_exit, rpsr
2649 msr spsr_cxsf, \rpsr
2650+
2651+ pax_exit_kernel
2652+
2653 #if defined(CONFIG_CPU_V6)
2654 ldr r0, [sp]
2655 strex r1, r2, [sp] @ clear the exclusive monitor
2656@@ -121,6 +178,9 @@
2657 .endm
2658 #else /* CONFIG_THUMB2_KERNEL */
2659 .macro svc_exit, rpsr
2660+
2661+ pax_exit_kernel
2662+
2663 ldr lr, [sp, #S_SP] @ top of the stack
2664 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2665 clrex @ clear the exclusive monitor
2666diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2667index 2adda11..7fbe958 100644
2668--- a/arch/arm/kernel/fiq.c
2669+++ b/arch/arm/kernel/fiq.c
2670@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2671 #if defined(CONFIG_CPU_USE_DOMAINS)
2672 memcpy((void *)0xffff001c, start, length);
2673 #else
2674+ pax_open_kernel();
2675 memcpy(vectors_page + 0x1c, start, length);
2676+ pax_close_kernel();
2677 #endif
2678 flush_icache_range(0xffff001c, 0xffff001c + length);
2679 if (!vectors_high())
2680diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2681index 8bac553..caee108 100644
2682--- a/arch/arm/kernel/head.S
2683+++ b/arch/arm/kernel/head.S
2684@@ -52,7 +52,9 @@
2685 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2686
2687 .macro pgtbl, rd, phys
2688- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2689+ mov \rd, #TEXT_OFFSET
2690+ sub \rd, #PG_DIR_SIZE
2691+ add \rd, \rd, \phys
2692 .endm
2693
2694 /*
2695@@ -434,7 +436,7 @@ __enable_mmu:
2696 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2697 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2698 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2699- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2700+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2701 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2702 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2703 #endif
2704diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2705index 1fd749e..47adb08 100644
2706--- a/arch/arm/kernel/hw_breakpoint.c
2707+++ b/arch/arm/kernel/hw_breakpoint.c
2708@@ -1029,7 +1029,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2709 return NOTIFY_OK;
2710 }
2711
2712-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2713+static struct notifier_block dbg_reset_nb = {
2714 .notifier_call = dbg_reset_notify,
2715 };
2716
2717diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2718index 1e9be5d..03edbc2 100644
2719--- a/arch/arm/kernel/module.c
2720+++ b/arch/arm/kernel/module.c
2721@@ -37,12 +37,37 @@
2722 #endif
2723
2724 #ifdef CONFIG_MMU
2725-void *module_alloc(unsigned long size)
2726+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2727 {
2728+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2729+ return NULL;
2730 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2731- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2732+ GFP_KERNEL, prot, -1,
2733 __builtin_return_address(0));
2734 }
2735+
2736+void *module_alloc(unsigned long size)
2737+{
2738+
2739+#ifdef CONFIG_PAX_KERNEXEC
2740+ return __module_alloc(size, PAGE_KERNEL);
2741+#else
2742+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2743+#endif
2744+
2745+}
2746+
2747+#ifdef CONFIG_PAX_KERNEXEC
2748+void module_free_exec(struct module *mod, void *module_region)
2749+{
2750+ module_free(mod, module_region);
2751+}
2752+
2753+void *module_alloc_exec(unsigned long size)
2754+{
2755+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2756+}
2757+#endif
2758 #endif
2759
2760 int
2761diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2762index 07314af..c46655c 100644
2763--- a/arch/arm/kernel/patch.c
2764+++ b/arch/arm/kernel/patch.c
2765@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2766 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2767 int size;
2768
2769+ pax_open_kernel();
2770 if (thumb2 && __opcode_is_thumb16(insn)) {
2771 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2772 size = sizeof(u16);
2773@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2774 *(u32 *)addr = insn;
2775 size = sizeof(u32);
2776 }
2777+ pax_close_kernel();
2778
2779 flush_icache_range((uintptr_t)(addr),
2780 (uintptr_t)(addr) + size);
2781diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2782index 1f2740e..b36e225 100644
2783--- a/arch/arm/kernel/perf_event_cpu.c
2784+++ b/arch/arm/kernel/perf_event_cpu.c
2785@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2786 return NOTIFY_OK;
2787 }
2788
2789-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2790+static struct notifier_block cpu_pmu_hotplug_notifier = {
2791 .notifier_call = cpu_pmu_notify,
2792 };
2793
2794diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2795index 047d3e4..7e96107 100644
2796--- a/arch/arm/kernel/process.c
2797+++ b/arch/arm/kernel/process.c
2798@@ -28,7 +28,6 @@
2799 #include <linux/tick.h>
2800 #include <linux/utsname.h>
2801 #include <linux/uaccess.h>
2802-#include <linux/random.h>
2803 #include <linux/hw_breakpoint.h>
2804 #include <linux/cpuidle.h>
2805 #include <linux/leds.h>
2806@@ -251,9 +250,10 @@ void machine_power_off(void)
2807 machine_shutdown();
2808 if (pm_power_off)
2809 pm_power_off();
2810+ BUG();
2811 }
2812
2813-void machine_restart(char *cmd)
2814+__noreturn void machine_restart(char *cmd)
2815 {
2816 machine_shutdown();
2817
2818@@ -278,8 +278,8 @@ void __show_regs(struct pt_regs *regs)
2819 init_utsname()->release,
2820 (int)strcspn(init_utsname()->version, " "),
2821 init_utsname()->version);
2822- print_symbol("PC is at %s\n", instruction_pointer(regs));
2823- print_symbol("LR is at %s\n", regs->ARM_lr);
2824+ printk("PC is at %pA\n", instruction_pointer(regs));
2825+ printk("LR is at %pA\n", regs->ARM_lr);
2826 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2827 "sp : %08lx ip : %08lx fp : %08lx\n",
2828 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2829@@ -447,12 +447,6 @@ unsigned long get_wchan(struct task_struct *p)
2830 return 0;
2831 }
2832
2833-unsigned long arch_randomize_brk(struct mm_struct *mm)
2834-{
2835- unsigned long range_end = mm->brk + 0x02000000;
2836- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2837-}
2838-
2839 #ifdef CONFIG_MMU
2840 /*
2841 * The vectors page is always readable from user space for the
2842@@ -465,9 +459,8 @@ static int __init gate_vma_init(void)
2843 {
2844 gate_vma.vm_start = 0xffff0000;
2845 gate_vma.vm_end = 0xffff0000 + PAGE_SIZE;
2846- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2847- gate_vma.vm_flags = VM_READ | VM_EXEC |
2848- VM_MAYREAD | VM_MAYEXEC;
2849+ gate_vma.vm_flags = VM_NONE;
2850+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2851 return 0;
2852 }
2853 arch_initcall(gate_vma_init);
2854diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2855index 3653164..d83e55d 100644
2856--- a/arch/arm/kernel/psci.c
2857+++ b/arch/arm/kernel/psci.c
2858@@ -24,7 +24,7 @@
2859 #include <asm/opcodes-virt.h>
2860 #include <asm/psci.h>
2861
2862-struct psci_operations psci_ops;
2863+struct psci_operations psci_ops __read_only;
2864
2865 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2866
2867diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2868index 03deeff..741ce88 100644
2869--- a/arch/arm/kernel/ptrace.c
2870+++ b/arch/arm/kernel/ptrace.c
2871@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2872 return current_thread_info()->syscall;
2873 }
2874
2875+#ifdef CONFIG_GRKERNSEC_SETXID
2876+extern void gr_delayed_cred_worker(void);
2877+#endif
2878+
2879 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2880 {
2881 current_thread_info()->syscall = scno;
2882
2883+#ifdef CONFIG_GRKERNSEC_SETXID
2884+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2885+ gr_delayed_cred_worker();
2886+#endif
2887+
2888 /* Do the secure computing check first; failures should be fast. */
2889 if (secure_computing(scno) == -1)
2890 return -1;
2891diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2892index 234e339..81264a1 100644
2893--- a/arch/arm/kernel/setup.c
2894+++ b/arch/arm/kernel/setup.c
2895@@ -96,21 +96,23 @@ EXPORT_SYMBOL(system_serial_high);
2896 unsigned int elf_hwcap __read_mostly;
2897 EXPORT_SYMBOL(elf_hwcap);
2898
2899+pteval_t __supported_pte_mask __read_only;
2900+pmdval_t __supported_pmd_mask __read_only;
2901
2902 #ifdef MULTI_CPU
2903-struct processor processor __read_mostly;
2904+struct processor processor;
2905 #endif
2906 #ifdef MULTI_TLB
2907-struct cpu_tlb_fns cpu_tlb __read_mostly;
2908+struct cpu_tlb_fns cpu_tlb __read_only;
2909 #endif
2910 #ifdef MULTI_USER
2911-struct cpu_user_fns cpu_user __read_mostly;
2912+struct cpu_user_fns cpu_user __read_only;
2913 #endif
2914 #ifdef MULTI_CACHE
2915-struct cpu_cache_fns cpu_cache __read_mostly;
2916+struct cpu_cache_fns cpu_cache __read_only;
2917 #endif
2918 #ifdef CONFIG_OUTER_CACHE
2919-struct outer_cache_fns outer_cache __read_mostly;
2920+struct outer_cache_fns outer_cache __read_only;
2921 EXPORT_SYMBOL(outer_cache);
2922 #endif
2923
2924@@ -235,9 +237,13 @@ static int __get_cpu_architecture(void)
2925 asm("mrc p15, 0, %0, c0, c1, 4"
2926 : "=r" (mmfr0));
2927 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2928- (mmfr0 & 0x000000f0) >= 0x00000030)
2929+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2930 cpu_arch = CPU_ARCH_ARMv7;
2931- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2932+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2933+ __supported_pte_mask |= L_PTE_PXN;
2934+ __supported_pmd_mask |= PMD_PXNTABLE;
2935+ }
2936+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2937 (mmfr0 & 0x000000f0) == 0x00000020)
2938 cpu_arch = CPU_ARCH_ARMv6;
2939 else
2940@@ -478,7 +484,7 @@ static void __init setup_processor(void)
2941 __cpu_architecture = __get_cpu_architecture();
2942
2943 #ifdef MULTI_CPU
2944- processor = *list->proc;
2945+ memcpy((void *)&processor, list->proc, sizeof processor);
2946 #endif
2947 #ifdef MULTI_TLB
2948 cpu_tlb = *list->tlb;
2949diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
2950index 296786b..a8d4dd5 100644
2951--- a/arch/arm/kernel/signal.c
2952+++ b/arch/arm/kernel/signal.c
2953@@ -396,22 +396,14 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
2954 __put_user(sigreturn_codes[idx+1], rc+1))
2955 return 1;
2956
2957- if (cpsr & MODE32_BIT) {
2958- /*
2959- * 32-bit code can use the new high-page
2960- * signal return code support.
2961- */
2962- retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
2963- } else {
2964- /*
2965- * Ensure that the instruction cache sees
2966- * the return code written onto the stack.
2967- */
2968- flush_icache_range((unsigned long)rc,
2969- (unsigned long)(rc + 2));
2970+ /*
2971+ * Ensure that the instruction cache sees
2972+ * the return code written onto the stack.
2973+ */
2974+ flush_icache_range((unsigned long)rc,
2975+ (unsigned long)(rc + 2));
2976
2977- retcode = ((unsigned long)rc) + thumb;
2978- }
2979+ retcode = ((unsigned long)rc) + thumb;
2980 }
2981
2982 regs->ARM_r0 = map_sig(ksig->sig);
2983diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2984index 1f2cccc..f40c02e 100644
2985--- a/arch/arm/kernel/smp.c
2986+++ b/arch/arm/kernel/smp.c
2987@@ -70,7 +70,7 @@ enum ipi_msg_type {
2988
2989 static DECLARE_COMPLETION(cpu_running);
2990
2991-static struct smp_operations smp_ops;
2992+static struct smp_operations smp_ops __read_only;
2993
2994 void __init smp_set_ops(struct smp_operations *ops)
2995 {
2996diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2997index 1c08911..264f009 100644
2998--- a/arch/arm/kernel/traps.c
2999+++ b/arch/arm/kernel/traps.c
3000@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3001 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3002 {
3003 #ifdef CONFIG_KALLSYMS
3004- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3005+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3006 #else
3007 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3008 #endif
3009@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3010 static int die_owner = -1;
3011 static unsigned int die_nest_count;
3012
3013+extern void gr_handle_kernel_exploit(void);
3014+
3015 static unsigned long oops_begin(void)
3016 {
3017 int cpu;
3018@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3019 panic("Fatal exception in interrupt");
3020 if (panic_on_oops)
3021 panic("Fatal exception");
3022+
3023+ gr_handle_kernel_exploit();
3024+
3025 if (signr)
3026 do_exit(signr);
3027 }
3028@@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3029 * The user helper at 0xffff0fe0 must be used instead.
3030 * (see entry-armv.S for details)
3031 */
3032+ pax_open_kernel();
3033 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3034+ pax_close_kernel();
3035 }
3036 return 0;
3037
3038@@ -841,13 +848,10 @@ void __init early_trap_init(void *vectors_base)
3039 */
3040 kuser_get_tls_init(vectors);
3041
3042- /*
3043- * Copy signal return handlers into the vector page, and
3044- * set sigreturn to be a pointer to these.
3045- */
3046- memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE),
3047- sigreturn_codes, sizeof(sigreturn_codes));
3048-
3049 flush_icache_range(vectors, vectors + PAGE_SIZE);
3050- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3051+
3052+#ifndef CONFIG_PAX_MEMORY_UDEREF
3053+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3054+#endif
3055+
3056 }
3057diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3058index b571484..4b2fc9b 100644
3059--- a/arch/arm/kernel/vmlinux.lds.S
3060+++ b/arch/arm/kernel/vmlinux.lds.S
3061@@ -8,7 +8,11 @@
3062 #include <asm/thread_info.h>
3063 #include <asm/memory.h>
3064 #include <asm/page.h>
3065-
3066+
3067+#ifdef CONFIG_PAX_KERNEXEC
3068+#include <asm/pgtable.h>
3069+#endif
3070+
3071 #define PROC_INFO \
3072 . = ALIGN(4); \
3073 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3074@@ -94,6 +98,11 @@ SECTIONS
3075 _text = .;
3076 HEAD_TEXT
3077 }
3078+
3079+#ifdef CONFIG_PAX_KERNEXEC
3080+ . = ALIGN(1<<SECTION_SHIFT);
3081+#endif
3082+
3083 .text : { /* Real text segment */
3084 _stext = .; /* Text and read-only data */
3085 __exception_text_start = .;
3086@@ -116,6 +125,8 @@ SECTIONS
3087 ARM_CPU_KEEP(PROC_INFO)
3088 }
3089
3090+ _etext = .; /* End of text section */
3091+
3092 RO_DATA(PAGE_SIZE)
3093
3094 . = ALIGN(4);
3095@@ -146,7 +157,9 @@ SECTIONS
3096
3097 NOTES
3098
3099- _etext = .; /* End of text and rodata section */
3100+#ifdef CONFIG_PAX_KERNEXEC
3101+ . = ALIGN(1<<SECTION_SHIFT);
3102+#endif
3103
3104 #ifndef CONFIG_XIP_KERNEL
3105 . = ALIGN(PAGE_SIZE);
3106@@ -207,6 +220,11 @@ SECTIONS
3107 . = PAGE_OFFSET + TEXT_OFFSET;
3108 #else
3109 __init_end = .;
3110+
3111+#ifdef CONFIG_PAX_KERNEXEC
3112+ . = ALIGN(1<<SECTION_SHIFT);
3113+#endif
3114+
3115 . = ALIGN(THREAD_SIZE);
3116 __data_loc = .;
3117 #endif
3118diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3119index 14a0d98..7771a7d 100644
3120--- a/arch/arm/lib/clear_user.S
3121+++ b/arch/arm/lib/clear_user.S
3122@@ -12,14 +12,14 @@
3123
3124 .text
3125
3126-/* Prototype: int __clear_user(void *addr, size_t sz)
3127+/* Prototype: int ___clear_user(void *addr, size_t sz)
3128 * Purpose : clear some user memory
3129 * Params : addr - user memory address to clear
3130 * : sz - number of bytes to clear
3131 * Returns : number of bytes NOT cleared
3132 */
3133 ENTRY(__clear_user_std)
3134-WEAK(__clear_user)
3135+WEAK(___clear_user)
3136 stmfd sp!, {r1, lr}
3137 mov r2, #0
3138 cmp r1, #4
3139@@ -44,7 +44,7 @@ WEAK(__clear_user)
3140 USER( strnebt r2, [r0])
3141 mov r0, #0
3142 ldmfd sp!, {r1, pc}
3143-ENDPROC(__clear_user)
3144+ENDPROC(___clear_user)
3145 ENDPROC(__clear_user_std)
3146
3147 .pushsection .fixup,"ax"
3148diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3149index 66a477a..bee61d3 100644
3150--- a/arch/arm/lib/copy_from_user.S
3151+++ b/arch/arm/lib/copy_from_user.S
3152@@ -16,7 +16,7 @@
3153 /*
3154 * Prototype:
3155 *
3156- * size_t __copy_from_user(void *to, const void *from, size_t n)
3157+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3158 *
3159 * Purpose:
3160 *
3161@@ -84,11 +84,11 @@
3162
3163 .text
3164
3165-ENTRY(__copy_from_user)
3166+ENTRY(___copy_from_user)
3167
3168 #include "copy_template.S"
3169
3170-ENDPROC(__copy_from_user)
3171+ENDPROC(___copy_from_user)
3172
3173 .pushsection .fixup,"ax"
3174 .align 0
3175diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3176index 6ee2f67..d1cce76 100644
3177--- a/arch/arm/lib/copy_page.S
3178+++ b/arch/arm/lib/copy_page.S
3179@@ -10,6 +10,7 @@
3180 * ASM optimised string functions
3181 */
3182 #include <linux/linkage.h>
3183+#include <linux/const.h>
3184 #include <asm/assembler.h>
3185 #include <asm/asm-offsets.h>
3186 #include <asm/cache.h>
3187diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3188index d066df6..df28194 100644
3189--- a/arch/arm/lib/copy_to_user.S
3190+++ b/arch/arm/lib/copy_to_user.S
3191@@ -16,7 +16,7 @@
3192 /*
3193 * Prototype:
3194 *
3195- * size_t __copy_to_user(void *to, const void *from, size_t n)
3196+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3197 *
3198 * Purpose:
3199 *
3200@@ -88,11 +88,11 @@
3201 .text
3202
3203 ENTRY(__copy_to_user_std)
3204-WEAK(__copy_to_user)
3205+WEAK(___copy_to_user)
3206
3207 #include "copy_template.S"
3208
3209-ENDPROC(__copy_to_user)
3210+ENDPROC(___copy_to_user)
3211 ENDPROC(__copy_to_user_std)
3212
3213 .pushsection .fixup,"ax"
3214diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3215index 7d08b43..f7ca7ea 100644
3216--- a/arch/arm/lib/csumpartialcopyuser.S
3217+++ b/arch/arm/lib/csumpartialcopyuser.S
3218@@ -57,8 +57,8 @@
3219 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3220 */
3221
3222-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3223-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3224+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3225+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3226
3227 #include "csumpartialcopygeneric.S"
3228
3229diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3230index 64dbfa5..84a3fd9 100644
3231--- a/arch/arm/lib/delay.c
3232+++ b/arch/arm/lib/delay.c
3233@@ -28,7 +28,7 @@
3234 /*
3235 * Default to the loop-based delay implementation.
3236 */
3237-struct arm_delay_ops arm_delay_ops = {
3238+struct arm_delay_ops arm_delay_ops __read_only = {
3239 .delay = __loop_delay,
3240 .const_udelay = __loop_const_udelay,
3241 .udelay = __loop_udelay,
3242diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3243index 025f742..8432b08 100644
3244--- a/arch/arm/lib/uaccess_with_memcpy.c
3245+++ b/arch/arm/lib/uaccess_with_memcpy.c
3246@@ -104,7 +104,7 @@ out:
3247 }
3248
3249 unsigned long
3250-__copy_to_user(void __user *to, const void *from, unsigned long n)
3251+___copy_to_user(void __user *to, const void *from, unsigned long n)
3252 {
3253 /*
3254 * This test is stubbed out of the main function above to keep
3255diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3256index 49792a0..f192052 100644
3257--- a/arch/arm/mach-kirkwood/common.c
3258+++ b/arch/arm/mach-kirkwood/common.c
3259@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3260 clk_gate_ops.disable(hw);
3261 }
3262
3263-static struct clk_ops clk_gate_fn_ops;
3264+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3265+{
3266+ return clk_gate_ops.is_enabled(hw);
3267+}
3268+
3269+static struct clk_ops clk_gate_fn_ops = {
3270+ .enable = clk_gate_fn_enable,
3271+ .disable = clk_gate_fn_disable,
3272+ .is_enabled = clk_gate_fn_is_enabled,
3273+};
3274
3275 static struct clk __init *clk_register_gate_fn(struct device *dev,
3276 const char *name,
3277@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3278 gate_fn->fn_en = fn_en;
3279 gate_fn->fn_dis = fn_dis;
3280
3281- /* ops is the gate ops, but with our enable/disable functions */
3282- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3283- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3284- clk_gate_fn_ops = clk_gate_ops;
3285- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3286- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3287- }
3288-
3289 clk = clk_register(dev, &gate_fn->gate.hw);
3290
3291 if (IS_ERR(clk))
3292diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3293index f6eeb87..cc90868 100644
3294--- a/arch/arm/mach-omap2/board-n8x0.c
3295+++ b/arch/arm/mach-omap2/board-n8x0.c
3296@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3297 }
3298 #endif
3299
3300-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3301+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3302 .late_init = n8x0_menelaus_late_init,
3303 };
3304
3305diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3306index 410e1ba..1d2dd59 100644
3307--- a/arch/arm/mach-omap2/gpmc.c
3308+++ b/arch/arm/mach-omap2/gpmc.c
3309@@ -145,7 +145,6 @@ struct omap3_gpmc_regs {
3310 };
3311
3312 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3313-static struct irq_chip gpmc_irq_chip;
3314 static unsigned gpmc_irq_start;
3315
3316 static struct resource gpmc_mem_root;
3317@@ -707,6 +706,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3318
3319 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3320
3321+static struct irq_chip gpmc_irq_chip = {
3322+ .name = "gpmc",
3323+ .irq_startup = gpmc_irq_noop_ret,
3324+ .irq_enable = gpmc_irq_enable,
3325+ .irq_disable = gpmc_irq_disable,
3326+ .irq_shutdown = gpmc_irq_noop,
3327+ .irq_ack = gpmc_irq_noop,
3328+ .irq_mask = gpmc_irq_noop,
3329+ .irq_unmask = gpmc_irq_noop,
3330+
3331+};
3332+
3333 static int gpmc_setup_irq(void)
3334 {
3335 int i;
3336@@ -721,15 +732,6 @@ static int gpmc_setup_irq(void)
3337 return gpmc_irq_start;
3338 }
3339
3340- gpmc_irq_chip.name = "gpmc";
3341- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3342- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3343- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3344- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3345- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3346- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3347- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3348-
3349 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3350 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3351
3352diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3353index f8bb3b9..831e7b8 100644
3354--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3355+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3356@@ -339,7 +339,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3357 return NOTIFY_OK;
3358 }
3359
3360-static struct notifier_block __refdata irq_hotplug_notifier = {
3361+static struct notifier_block irq_hotplug_notifier = {
3362 .notifier_call = irq_cpu_hotplug_notify,
3363 };
3364
3365diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3366index 381be7a..89b9c7e 100644
3367--- a/arch/arm/mach-omap2/omap_device.c
3368+++ b/arch/arm/mach-omap2/omap_device.c
3369@@ -499,7 +499,7 @@ void omap_device_delete(struct omap_device *od)
3370 struct platform_device __init *omap_device_build(const char *pdev_name,
3371 int pdev_id,
3372 struct omap_hwmod *oh,
3373- void *pdata, int pdata_len)
3374+ const void *pdata, int pdata_len)
3375 {
3376 struct omap_hwmod *ohs[] = { oh };
3377
3378@@ -527,7 +527,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3379 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3380 int pdev_id,
3381 struct omap_hwmod **ohs,
3382- int oh_cnt, void *pdata,
3383+ int oh_cnt, const void *pdata,
3384 int pdata_len)
3385 {
3386 int ret = -ENOMEM;
3387diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3388index 044c31d..2ee0861 100644
3389--- a/arch/arm/mach-omap2/omap_device.h
3390+++ b/arch/arm/mach-omap2/omap_device.h
3391@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3392 /* Core code interface */
3393
3394 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3395- struct omap_hwmod *oh, void *pdata,
3396+ struct omap_hwmod *oh, const void *pdata,
3397 int pdata_len);
3398
3399 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3400 struct omap_hwmod **oh, int oh_cnt,
3401- void *pdata, int pdata_len);
3402+ const void *pdata, int pdata_len);
3403
3404 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3405 struct omap_hwmod **ohs, int oh_cnt);
3406diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3407index 3a750de..4c9b88f 100644
3408--- a/arch/arm/mach-omap2/omap_hwmod.c
3409+++ b/arch/arm/mach-omap2/omap_hwmod.c
3410@@ -191,10 +191,10 @@ struct omap_hwmod_soc_ops {
3411 int (*init_clkdm)(struct omap_hwmod *oh);
3412 void (*update_context_lost)(struct omap_hwmod *oh);
3413 int (*get_context_lost)(struct omap_hwmod *oh);
3414-};
3415+} __no_const;
3416
3417 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3418-static struct omap_hwmod_soc_ops soc_ops;
3419+static struct omap_hwmod_soc_ops soc_ops __read_only;
3420
3421 /* omap_hwmod_list contains all registered struct omap_hwmods */
3422 static LIST_HEAD(omap_hwmod_list);
3423diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3424index d15c7bb..b2d1f0c 100644
3425--- a/arch/arm/mach-omap2/wd_timer.c
3426+++ b/arch/arm/mach-omap2/wd_timer.c
3427@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3428 struct omap_hwmod *oh;
3429 char *oh_name = "wd_timer2";
3430 char *dev_name = "omap_wdt";
3431- struct omap_wd_timer_platform_data pdata;
3432+ static struct omap_wd_timer_platform_data pdata = {
3433+ .read_reset_sources = prm_read_reset_sources
3434+ };
3435
3436 if (!cpu_class_is_omap2() || of_have_populated_dt())
3437 return 0;
3438@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3439 return -EINVAL;
3440 }
3441
3442- pdata.read_reset_sources = prm_read_reset_sources;
3443-
3444 pdev = omap_device_build(dev_name, id, oh, &pdata,
3445 sizeof(struct omap_wd_timer_platform_data));
3446 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3447diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3448index bddce2b..3eb04e2 100644
3449--- a/arch/arm/mach-ux500/include/mach/setup.h
3450+++ b/arch/arm/mach-ux500/include/mach/setup.h
3451@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3452 .type = MT_DEVICE, \
3453 }
3454
3455-#define __MEM_DEV_DESC(x, sz) { \
3456- .virtual = IO_ADDRESS(x), \
3457- .pfn = __phys_to_pfn(x), \
3458- .length = sz, \
3459- .type = MT_MEMORY, \
3460-}
3461-
3462 extern struct smp_operations ux500_smp_ops;
3463 extern void ux500_cpu_die(unsigned int cpu);
3464
3465diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3466index 4045c49..0263c07 100644
3467--- a/arch/arm/mm/Kconfig
3468+++ b/arch/arm/mm/Kconfig
3469@@ -425,7 +425,7 @@ config CPU_32v5
3470
3471 config CPU_32v6
3472 bool
3473- select CPU_USE_DOMAINS if CPU_V6 && MMU
3474+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3475 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3476
3477 config CPU_32v6K
3478@@ -574,6 +574,7 @@ config CPU_CP15_MPU
3479
3480 config CPU_USE_DOMAINS
3481 bool
3482+ depends on !ARM_LPAE && !PAX_KERNEXEC
3483 help
3484 This option enables or disables the use of domain switching
3485 via the set_fs() function.
3486diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3487index db26e2e..ee44569 100644
3488--- a/arch/arm/mm/alignment.c
3489+++ b/arch/arm/mm/alignment.c
3490@@ -211,10 +211,12 @@ union offset_union {
3491 #define __get16_unaligned_check(ins,val,addr) \
3492 do { \
3493 unsigned int err = 0, v, a = addr; \
3494+ pax_open_userland(); \
3495 __get8_unaligned_check(ins,v,a,err); \
3496 val = v << ((BE) ? 8 : 0); \
3497 __get8_unaligned_check(ins,v,a,err); \
3498 val |= v << ((BE) ? 0 : 8); \
3499+ pax_close_userland(); \
3500 if (err) \
3501 goto fault; \
3502 } while (0)
3503@@ -228,6 +230,7 @@ union offset_union {
3504 #define __get32_unaligned_check(ins,val,addr) \
3505 do { \
3506 unsigned int err = 0, v, a = addr; \
3507+ pax_open_userland(); \
3508 __get8_unaligned_check(ins,v,a,err); \
3509 val = v << ((BE) ? 24 : 0); \
3510 __get8_unaligned_check(ins,v,a,err); \
3511@@ -236,6 +239,7 @@ union offset_union {
3512 val |= v << ((BE) ? 8 : 16); \
3513 __get8_unaligned_check(ins,v,a,err); \
3514 val |= v << ((BE) ? 0 : 24); \
3515+ pax_close_userland(); \
3516 if (err) \
3517 goto fault; \
3518 } while (0)
3519@@ -249,6 +253,7 @@ union offset_union {
3520 #define __put16_unaligned_check(ins,val,addr) \
3521 do { \
3522 unsigned int err = 0, v = val, a = addr; \
3523+ pax_open_userland(); \
3524 __asm__( FIRST_BYTE_16 \
3525 ARM( "1: "ins" %1, [%2], #1\n" ) \
3526 THUMB( "1: "ins" %1, [%2]\n" ) \
3527@@ -268,6 +273,7 @@ union offset_union {
3528 " .popsection\n" \
3529 : "=r" (err), "=&r" (v), "=&r" (a) \
3530 : "0" (err), "1" (v), "2" (a)); \
3531+ pax_close_userland(); \
3532 if (err) \
3533 goto fault; \
3534 } while (0)
3535@@ -281,6 +287,7 @@ union offset_union {
3536 #define __put32_unaligned_check(ins,val,addr) \
3537 do { \
3538 unsigned int err = 0, v = val, a = addr; \
3539+ pax_open_userland(); \
3540 __asm__( FIRST_BYTE_32 \
3541 ARM( "1: "ins" %1, [%2], #1\n" ) \
3542 THUMB( "1: "ins" %1, [%2]\n" ) \
3543@@ -310,6 +317,7 @@ union offset_union {
3544 " .popsection\n" \
3545 : "=r" (err), "=&r" (v), "=&r" (a) \
3546 : "0" (err), "1" (v), "2" (a)); \
3547+ pax_close_userland(); \
3548 if (err) \
3549 goto fault; \
3550 } while (0)
3551diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3552index 5dbf13f..1a60561 100644
3553--- a/arch/arm/mm/fault.c
3554+++ b/arch/arm/mm/fault.c
3555@@ -25,6 +25,7 @@
3556 #include <asm/system_misc.h>
3557 #include <asm/system_info.h>
3558 #include <asm/tlbflush.h>
3559+#include <asm/sections.h>
3560
3561 #include "fault.h"
3562
3563@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3564 if (fixup_exception(regs))
3565 return;
3566
3567+#ifdef CONFIG_PAX_KERNEXEC
3568+ if ((fsr & FSR_WRITE) &&
3569+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3570+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3571+ {
3572+ if (current->signal->curr_ip)
3573+ 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),
3574+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3575+ else
3576+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3577+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3578+ }
3579+#endif
3580+
3581 /*
3582 * No handler, we'll have to terminate things with extreme prejudice.
3583 */
3584@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3585 }
3586 #endif
3587
3588+#ifdef CONFIG_PAX_PAGEEXEC
3589+ if (fsr & FSR_LNX_PF) {
3590+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3591+ do_group_exit(SIGKILL);
3592+ }
3593+#endif
3594+
3595 tsk->thread.address = addr;
3596 tsk->thread.error_code = fsr;
3597 tsk->thread.trap_no = 14;
3598@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3599 }
3600 #endif /* CONFIG_MMU */
3601
3602+#ifdef CONFIG_PAX_PAGEEXEC
3603+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3604+{
3605+ long i;
3606+
3607+ printk(KERN_ERR "PAX: bytes at PC: ");
3608+ for (i = 0; i < 20; i++) {
3609+ unsigned char c;
3610+ if (get_user(c, (__force unsigned char __user *)pc+i))
3611+ printk(KERN_CONT "?? ");
3612+ else
3613+ printk(KERN_CONT "%02x ", c);
3614+ }
3615+ printk("\n");
3616+
3617+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3618+ for (i = -1; i < 20; i++) {
3619+ unsigned long c;
3620+ if (get_user(c, (__force unsigned long __user *)sp+i))
3621+ printk(KERN_CONT "???????? ");
3622+ else
3623+ printk(KERN_CONT "%08lx ", c);
3624+ }
3625+ printk("\n");
3626+}
3627+#endif
3628+
3629 /*
3630 * First Level Translation Fault Handler
3631 *
3632@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3633 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3634 struct siginfo info;
3635
3636+#ifdef CONFIG_PAX_MEMORY_UDEREF
3637+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3638+ if (current->signal->curr_ip)
3639+ 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),
3640+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3641+ else
3642+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3643+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3644+ goto die;
3645+ }
3646+#endif
3647+
3648 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3649 return;
3650
3651+die:
3652 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3653 inf->name, fsr, addr);
3654
3655@@ -575,9 +637,49 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3656 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3657 struct siginfo info;
3658
3659+ if (user_mode(regs)) {
3660+ if (addr == 0xffff0fe0UL) {
3661+ /*
3662+ * PaX: __kuser_get_tls emulation
3663+ */
3664+ regs->ARM_r0 = current_thread_info()->tp_value;
3665+ regs->ARM_pc = regs->ARM_lr;
3666+ return;
3667+ }
3668+ }
3669+
3670+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3671+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3672+ if (current->signal->curr_ip)
3673+ 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),
3674+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3675+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3676+ else
3677+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3678+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3679+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3680+ goto die;
3681+ }
3682+#endif
3683+
3684+#ifdef CONFIG_PAX_REFCOUNT
3685+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3686+ unsigned int bkpt;
3687+
3688+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3689+ current->thread.error_code = ifsr;
3690+ current->thread.trap_no = 0;
3691+ pax_report_refcount_overflow(regs);
3692+ fixup_exception(regs);
3693+ return;
3694+ }
3695+ }
3696+#endif
3697+
3698 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3699 return;
3700
3701+die:
3702 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3703 inf->name, ifsr, addr);
3704
3705diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3706index cf08bdf..772656c 100644
3707--- a/arch/arm/mm/fault.h
3708+++ b/arch/arm/mm/fault.h
3709@@ -3,6 +3,7 @@
3710
3711 /*
3712 * Fault status register encodings. We steal bit 31 for our own purposes.
3713+ * Set when the FSR value is from an instruction fault.
3714 */
3715 #define FSR_LNX_PF (1 << 31)
3716 #define FSR_WRITE (1 << 11)
3717@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3718 }
3719 #endif
3720
3721+/* valid for LPAE and !LPAE */
3722+static inline int is_xn_fault(unsigned int fsr)
3723+{
3724+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3725+}
3726+
3727+static inline int is_domain_fault(unsigned int fsr)
3728+{
3729+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3730+}
3731+
3732 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3733 unsigned long search_exception_table(unsigned long addr);
3734
3735diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3736index ad722f1..763fdd3 100644
3737--- a/arch/arm/mm/init.c
3738+++ b/arch/arm/mm/init.c
3739@@ -30,6 +30,8 @@
3740 #include <asm/setup.h>
3741 #include <asm/tlb.h>
3742 #include <asm/fixmap.h>
3743+#include <asm/system_info.h>
3744+#include <asm/cp15.h>
3745
3746 #include <asm/mach/arch.h>
3747 #include <asm/mach/map.h>
3748@@ -736,7 +738,46 @@ void free_initmem(void)
3749 {
3750 #ifdef CONFIG_HAVE_TCM
3751 extern char __tcm_start, __tcm_end;
3752+#endif
3753
3754+#ifdef CONFIG_PAX_KERNEXEC
3755+ unsigned long addr;
3756+ pgd_t *pgd;
3757+ pud_t *pud;
3758+ pmd_t *pmd;
3759+ int cpu_arch = cpu_architecture();
3760+ unsigned int cr = get_cr();
3761+
3762+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3763+ /* make pages tables, etc before .text NX */
3764+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3765+ pgd = pgd_offset_k(addr);
3766+ pud = pud_offset(pgd, addr);
3767+ pmd = pmd_offset(pud, addr);
3768+ __section_update(pmd, addr, PMD_SECT_XN);
3769+ }
3770+ /* make init NX */
3771+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3772+ pgd = pgd_offset_k(addr);
3773+ pud = pud_offset(pgd, addr);
3774+ pmd = pmd_offset(pud, addr);
3775+ __section_update(pmd, addr, PMD_SECT_XN);
3776+ }
3777+ /* make kernel code/rodata RX */
3778+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3779+ pgd = pgd_offset_k(addr);
3780+ pud = pud_offset(pgd, addr);
3781+ pmd = pmd_offset(pud, addr);
3782+#ifdef CONFIG_ARM_LPAE
3783+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3784+#else
3785+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3786+#endif
3787+ }
3788+ }
3789+#endif
3790+
3791+#ifdef CONFIG_HAVE_TCM
3792 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3793 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3794 __phys_to_pfn(__pa(&__tcm_end)),
3795diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3796index 04d9006..c547d85 100644
3797--- a/arch/arm/mm/ioremap.c
3798+++ b/arch/arm/mm/ioremap.c
3799@@ -392,9 +392,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3800 unsigned int mtype;
3801
3802 if (cached)
3803- mtype = MT_MEMORY;
3804+ mtype = MT_MEMORY_RX;
3805 else
3806- mtype = MT_MEMORY_NONCACHED;
3807+ mtype = MT_MEMORY_NONCACHED_RX;
3808
3809 return __arm_ioremap_caller(phys_addr, size, mtype,
3810 __builtin_return_address(0));
3811diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3812index 10062ce..8695745 100644
3813--- a/arch/arm/mm/mmap.c
3814+++ b/arch/arm/mm/mmap.c
3815@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3816 struct vm_area_struct *vma;
3817 int do_align = 0;
3818 int aliasing = cache_is_vipt_aliasing();
3819+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3820 struct vm_unmapped_area_info info;
3821
3822 /*
3823@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3824 if (len > TASK_SIZE)
3825 return -ENOMEM;
3826
3827+#ifdef CONFIG_PAX_RANDMMAP
3828+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3829+#endif
3830+
3831 if (addr) {
3832 if (do_align)
3833 addr = COLOUR_ALIGN(addr, pgoff);
3834@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3835 addr = PAGE_ALIGN(addr);
3836
3837 vma = find_vma(mm, addr);
3838- if (TASK_SIZE - len >= addr &&
3839- (!vma || addr + len <= vma->vm_start))
3840+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3841 return addr;
3842 }
3843
3844@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3845 info.high_limit = TASK_SIZE;
3846 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3847 info.align_offset = pgoff << PAGE_SHIFT;
3848+ info.threadstack_offset = offset;
3849 return vm_unmapped_area(&info);
3850 }
3851
3852@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3853 unsigned long addr = addr0;
3854 int do_align = 0;
3855 int aliasing = cache_is_vipt_aliasing();
3856+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3857 struct vm_unmapped_area_info info;
3858
3859 /*
3860@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3861 return addr;
3862 }
3863
3864+#ifdef CONFIG_PAX_RANDMMAP
3865+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3866+#endif
3867+
3868 /* requesting a specific address */
3869 if (addr) {
3870 if (do_align)
3871@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3872 else
3873 addr = PAGE_ALIGN(addr);
3874 vma = find_vma(mm, addr);
3875- if (TASK_SIZE - len >= addr &&
3876- (!vma || addr + len <= vma->vm_start))
3877+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3878 return addr;
3879 }
3880
3881@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3882 info.high_limit = mm->mmap_base;
3883 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3884 info.align_offset = pgoff << PAGE_SHIFT;
3885+ info.threadstack_offset = offset;
3886 addr = vm_unmapped_area(&info);
3887
3888 /*
3889@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3890 {
3891 unsigned long random_factor = 0UL;
3892
3893+#ifdef CONFIG_PAX_RANDMMAP
3894+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3895+#endif
3896+
3897 /* 8 bits of randomness in 20 address space bits */
3898 if ((current->flags & PF_RANDOMIZE) &&
3899 !(current->personality & ADDR_NO_RANDOMIZE))
3900@@ -180,10 +194,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3901
3902 if (mmap_is_legacy()) {
3903 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3904+
3905+#ifdef CONFIG_PAX_RANDMMAP
3906+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3907+ mm->mmap_base += mm->delta_mmap;
3908+#endif
3909+
3910 mm->get_unmapped_area = arch_get_unmapped_area;
3911 mm->unmap_area = arch_unmap_area;
3912 } else {
3913 mm->mmap_base = mmap_base(random_factor);
3914+
3915+#ifdef CONFIG_PAX_RANDMMAP
3916+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3917+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3918+#endif
3919+
3920 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3921 mm->unmap_area = arch_unmap_area_topdown;
3922 }
3923diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3924index a84ff76..f221c1d 100644
3925--- a/arch/arm/mm/mmu.c
3926+++ b/arch/arm/mm/mmu.c
3927@@ -36,6 +36,22 @@
3928 #include "mm.h"
3929 #include "tcm.h"
3930
3931+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3932+void modify_domain(unsigned int dom, unsigned int type)
3933+{
3934+ struct thread_info *thread = current_thread_info();
3935+ unsigned int domain = thread->cpu_domain;
3936+ /*
3937+ * DOMAIN_MANAGER might be defined to some other value,
3938+ * use the arch-defined constant
3939+ */
3940+ domain &= ~domain_val(dom, 3);
3941+ thread->cpu_domain = domain | domain_val(dom, type);
3942+ set_domain(thread->cpu_domain);
3943+}
3944+EXPORT_SYMBOL(modify_domain);
3945+#endif
3946+
3947 /*
3948 * empty_zero_page is a special page that is used for
3949 * zero-initialized data and COW.
3950@@ -211,10 +227,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
3951 }
3952 #endif
3953
3954-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
3955+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
3956 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
3957
3958-static struct mem_type mem_types[] = {
3959+#ifdef CONFIG_PAX_KERNEXEC
3960+#define L_PTE_KERNEXEC L_PTE_RDONLY
3961+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
3962+#else
3963+#define L_PTE_KERNEXEC L_PTE_DIRTY
3964+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
3965+#endif
3966+
3967+static struct mem_type mem_types[] __read_only = {
3968 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
3969 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
3970 L_PTE_SHARED,
3971@@ -243,16 +267,16 @@ static struct mem_type mem_types[] = {
3972 [MT_UNCACHED] = {
3973 .prot_pte = PROT_PTE_DEVICE,
3974 .prot_l1 = PMD_TYPE_TABLE,
3975- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3976+ .prot_sect = PROT_SECT_DEVICE,
3977 .domain = DOMAIN_IO,
3978 },
3979 [MT_CACHECLEAN] = {
3980- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3981+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3982 .domain = DOMAIN_KERNEL,
3983 },
3984 #ifndef CONFIG_ARM_LPAE
3985 [MT_MINICLEAN] = {
3986- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
3987+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
3988 .domain = DOMAIN_KERNEL,
3989 },
3990 #endif
3991@@ -260,36 +284,54 @@ static struct mem_type mem_types[] = {
3992 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3993 L_PTE_RDONLY,
3994 .prot_l1 = PMD_TYPE_TABLE,
3995- .domain = DOMAIN_USER,
3996+ .domain = DOMAIN_VECTORS,
3997 },
3998 [MT_HIGH_VECTORS] = {
3999 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4000- L_PTE_USER | L_PTE_RDONLY,
4001+ L_PTE_RDONLY,
4002 .prot_l1 = PMD_TYPE_TABLE,
4003- .domain = DOMAIN_USER,
4004+ .domain = DOMAIN_VECTORS,
4005 },
4006- [MT_MEMORY] = {
4007+ [MT_MEMORY_RWX] = {
4008 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4009 .prot_l1 = PMD_TYPE_TABLE,
4010 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4011 .domain = DOMAIN_KERNEL,
4012 },
4013+ [MT_MEMORY_RW] = {
4014+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4015+ .prot_l1 = PMD_TYPE_TABLE,
4016+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4017+ .domain = DOMAIN_KERNEL,
4018+ },
4019+ [MT_MEMORY_RX] = {
4020+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4021+ .prot_l1 = PMD_TYPE_TABLE,
4022+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4023+ .domain = DOMAIN_KERNEL,
4024+ },
4025 [MT_ROM] = {
4026- .prot_sect = PMD_TYPE_SECT,
4027+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4028 .domain = DOMAIN_KERNEL,
4029 },
4030- [MT_MEMORY_NONCACHED] = {
4031+ [MT_MEMORY_NONCACHED_RW] = {
4032 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4033 L_PTE_MT_BUFFERABLE,
4034 .prot_l1 = PMD_TYPE_TABLE,
4035 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4036 .domain = DOMAIN_KERNEL,
4037 },
4038+ [MT_MEMORY_NONCACHED_RX] = {
4039+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4040+ L_PTE_MT_BUFFERABLE,
4041+ .prot_l1 = PMD_TYPE_TABLE,
4042+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4043+ .domain = DOMAIN_KERNEL,
4044+ },
4045 [MT_MEMORY_DTCM] = {
4046- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4047- L_PTE_XN,
4048+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4049 .prot_l1 = PMD_TYPE_TABLE,
4050- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4051+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4052 .domain = DOMAIN_KERNEL,
4053 },
4054 [MT_MEMORY_ITCM] = {
4055@@ -299,10 +341,10 @@ static struct mem_type mem_types[] = {
4056 },
4057 [MT_MEMORY_SO] = {
4058 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4059- L_PTE_MT_UNCACHED | L_PTE_XN,
4060+ L_PTE_MT_UNCACHED,
4061 .prot_l1 = PMD_TYPE_TABLE,
4062 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4063- PMD_SECT_UNCACHED | PMD_SECT_XN,
4064+ PMD_SECT_UNCACHED,
4065 .domain = DOMAIN_KERNEL,
4066 },
4067 [MT_MEMORY_DMA_READY] = {
4068@@ -388,9 +430,35 @@ static void __init build_mem_type_table(void)
4069 * to prevent speculative instruction fetches.
4070 */
4071 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4072+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4073 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4074+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4075 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4076+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4077 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4078+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4079+
4080+ /* Mark other regions on ARMv6+ as execute-never */
4081+
4082+#ifdef CONFIG_PAX_KERNEXEC
4083+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4084+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4085+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4086+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4087+#ifndef CONFIG_ARM_LPAE
4088+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4089+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4090+#endif
4091+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4092+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4093+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4094+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4095+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4096+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4097+#endif
4098+
4099+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4100+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4101 }
4102 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4103 /*
4104@@ -451,6 +519,9 @@ static void __init build_mem_type_table(void)
4105 * from SVC mode and no access from userspace.
4106 */
4107 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4108+#ifdef CONFIG_PAX_KERNEXEC
4109+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4110+#endif
4111 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4112 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4113 #endif
4114@@ -468,11 +539,17 @@ static void __init build_mem_type_table(void)
4115 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4116 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4117 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4118- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4119- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4120+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4121+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4122+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4123+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4124+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4125+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4126 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4127- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4128- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4129+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4130+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4131+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4132+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4133 }
4134 }
4135
4136@@ -483,15 +560,20 @@ static void __init build_mem_type_table(void)
4137 if (cpu_arch >= CPU_ARCH_ARMv6) {
4138 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4139 /* Non-cacheable Normal is XCB = 001 */
4140- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4141+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4142+ PMD_SECT_BUFFERED;
4143+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4144 PMD_SECT_BUFFERED;
4145 } else {
4146 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4147- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4148+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4149+ PMD_SECT_TEX(1);
4150+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4151 PMD_SECT_TEX(1);
4152 }
4153 } else {
4154- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4155+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4156+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4157 }
4158
4159 #ifdef CONFIG_ARM_LPAE
4160@@ -507,6 +589,8 @@ static void __init build_mem_type_table(void)
4161 vecs_pgprot |= PTE_EXT_AF;
4162 #endif
4163
4164+ user_pgprot |= __supported_pte_mask;
4165+
4166 for (i = 0; i < 16; i++) {
4167 pteval_t v = pgprot_val(protection_map[i]);
4168 protection_map[i] = __pgprot(v | user_pgprot);
4169@@ -524,10 +608,15 @@ static void __init build_mem_type_table(void)
4170
4171 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4172 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4173- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4174- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4175+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4176+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4177+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4178+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4179+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4180+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4181 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4182- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4183+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4184+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4185 mem_types[MT_ROM].prot_sect |= cp->pmd;
4186
4187 switch (cp->pmd) {
4188@@ -1147,18 +1236,15 @@ void __init arm_mm_memblock_reserve(void)
4189 * called function. This means you can't use any function or debugging
4190 * method which may touch any device, otherwise the kernel _will_ crash.
4191 */
4192+
4193+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4194+
4195 static void __init devicemaps_init(struct machine_desc *mdesc)
4196 {
4197 struct map_desc map;
4198 unsigned long addr;
4199- void *vectors;
4200
4201- /*
4202- * Allocate the vector page early.
4203- */
4204- vectors = early_alloc(PAGE_SIZE);
4205-
4206- early_trap_init(vectors);
4207+ early_trap_init(&vectors);
4208
4209 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4210 pmd_clear(pmd_off_k(addr));
4211@@ -1198,7 +1284,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4212 * location (0xffff0000). If we aren't using high-vectors, also
4213 * create a mapping at the low-vectors virtual address.
4214 */
4215- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4216+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4217 map.virtual = 0xffff0000;
4218 map.length = PAGE_SIZE;
4219 map.type = MT_HIGH_VECTORS;
4220@@ -1256,8 +1342,39 @@ static void __init map_lowmem(void)
4221 map.pfn = __phys_to_pfn(start);
4222 map.virtual = __phys_to_virt(start);
4223 map.length = end - start;
4224- map.type = MT_MEMORY;
4225
4226+#ifdef CONFIG_PAX_KERNEXEC
4227+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4228+ struct map_desc kernel;
4229+ struct map_desc initmap;
4230+
4231+ /* when freeing initmem we will make this RW */
4232+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4233+ initmap.virtual = (unsigned long)__init_begin;
4234+ initmap.length = _sdata - __init_begin;
4235+ initmap.type = MT_MEMORY_RWX;
4236+ create_mapping(&initmap);
4237+
4238+ /* when freeing initmem we will make this RX */
4239+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4240+ kernel.virtual = (unsigned long)_stext;
4241+ kernel.length = __init_begin - _stext;
4242+ kernel.type = MT_MEMORY_RWX;
4243+ create_mapping(&kernel);
4244+
4245+ if (map.virtual < (unsigned long)_stext) {
4246+ map.length = (unsigned long)_stext - map.virtual;
4247+ map.type = MT_MEMORY_RWX;
4248+ create_mapping(&map);
4249+ }
4250+
4251+ map.pfn = __phys_to_pfn(__pa(_sdata));
4252+ map.virtual = (unsigned long)_sdata;
4253+ map.length = end - __pa(_sdata);
4254+ }
4255+#endif
4256+
4257+ map.type = MT_MEMORY_RW;
4258 create_mapping(&map);
4259 }
4260 }
4261diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4262index 78f520b..31f0cb6 100644
4263--- a/arch/arm/mm/proc-v7-2level.S
4264+++ b/arch/arm/mm/proc-v7-2level.S
4265@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4266 tst r1, #L_PTE_XN
4267 orrne r3, r3, #PTE_EXT_XN
4268
4269+ tst r1, #L_PTE_PXN
4270+ orrne r3, r3, #PTE_EXT_PXN
4271+
4272 tst r1, #L_PTE_YOUNG
4273 tstne r1, #L_PTE_VALID
4274 #ifndef CONFIG_CPU_USE_DOMAINS
4275diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4276index a5bc92d..0bb4730 100644
4277--- a/arch/arm/plat-omap/sram.c
4278+++ b/arch/arm/plat-omap/sram.c
4279@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4280 * Looks like we need to preserve some bootloader code at the
4281 * beginning of SRAM for jumping to flash for reboot to work...
4282 */
4283+ pax_open_kernel();
4284 memset_io(omap_sram_base + omap_sram_skip, 0,
4285 omap_sram_size - omap_sram_skip);
4286+ pax_close_kernel();
4287 }
4288diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4289index 1141782..0959d64 100644
4290--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4291+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4292@@ -48,7 +48,7 @@ struct samsung_dma_ops {
4293 int (*started)(unsigned ch);
4294 int (*flush)(unsigned ch);
4295 int (*stop)(unsigned ch);
4296-};
4297+} __no_const;
4298
4299 extern void *samsung_dmadev_get_ops(void);
4300 extern void *s3c_dma_get_ops(void);
4301diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4302index f4726dc..39ed646 100644
4303--- a/arch/arm64/kernel/debug-monitors.c
4304+++ b/arch/arm64/kernel/debug-monitors.c
4305@@ -149,7 +149,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4306 return NOTIFY_OK;
4307 }
4308
4309-static struct notifier_block __cpuinitdata os_lock_nb = {
4310+static struct notifier_block os_lock_nb = {
4311 .notifier_call = os_lock_notify,
4312 };
4313
4314diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4315index 5ab825c..96aaec8 100644
4316--- a/arch/arm64/kernel/hw_breakpoint.c
4317+++ b/arch/arm64/kernel/hw_breakpoint.c
4318@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4319 return NOTIFY_OK;
4320 }
4321
4322-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4323+static struct notifier_block hw_breakpoint_reset_nb = {
4324 .notifier_call = hw_breakpoint_reset_notify,
4325 };
4326
4327diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4328index c3a58a1..78fbf54 100644
4329--- a/arch/avr32/include/asm/cache.h
4330+++ b/arch/avr32/include/asm/cache.h
4331@@ -1,8 +1,10 @@
4332 #ifndef __ASM_AVR32_CACHE_H
4333 #define __ASM_AVR32_CACHE_H
4334
4335+#include <linux/const.h>
4336+
4337 #define L1_CACHE_SHIFT 5
4338-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4339+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4340
4341 /*
4342 * Memory returned by kmalloc() may be used for DMA, so we must make
4343diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4344index d232888..87c8df1 100644
4345--- a/arch/avr32/include/asm/elf.h
4346+++ b/arch/avr32/include/asm/elf.h
4347@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4348 the loader. We need to make sure that it is out of the way of the program
4349 that it will "exec", and that there is sufficient room for the brk. */
4350
4351-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4352+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4353
4354+#ifdef CONFIG_PAX_ASLR
4355+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4356+
4357+#define PAX_DELTA_MMAP_LEN 15
4358+#define PAX_DELTA_STACK_LEN 15
4359+#endif
4360
4361 /* This yields a mask that user programs can use to figure out what
4362 instruction set this CPU supports. This could be done in user space,
4363diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4364index 479330b..53717a8 100644
4365--- a/arch/avr32/include/asm/kmap_types.h
4366+++ b/arch/avr32/include/asm/kmap_types.h
4367@@ -2,9 +2,9 @@
4368 #define __ASM_AVR32_KMAP_TYPES_H
4369
4370 #ifdef CONFIG_DEBUG_HIGHMEM
4371-# define KM_TYPE_NR 29
4372+# define KM_TYPE_NR 30
4373 #else
4374-# define KM_TYPE_NR 14
4375+# define KM_TYPE_NR 15
4376 #endif
4377
4378 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4379diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4380index b2f2d2d..d1c85cb 100644
4381--- a/arch/avr32/mm/fault.c
4382+++ b/arch/avr32/mm/fault.c
4383@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4384
4385 int exception_trace = 1;
4386
4387+#ifdef CONFIG_PAX_PAGEEXEC
4388+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4389+{
4390+ unsigned long i;
4391+
4392+ printk(KERN_ERR "PAX: bytes at PC: ");
4393+ for (i = 0; i < 20; i++) {
4394+ unsigned char c;
4395+ if (get_user(c, (unsigned char *)pc+i))
4396+ printk(KERN_CONT "???????? ");
4397+ else
4398+ printk(KERN_CONT "%02x ", c);
4399+ }
4400+ printk("\n");
4401+}
4402+#endif
4403+
4404 /*
4405 * This routine handles page faults. It determines the address and the
4406 * problem, and then passes it off to one of the appropriate routines.
4407@@ -174,6 +191,16 @@ bad_area:
4408 up_read(&mm->mmap_sem);
4409
4410 if (user_mode(regs)) {
4411+
4412+#ifdef CONFIG_PAX_PAGEEXEC
4413+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4414+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4415+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4416+ do_group_exit(SIGKILL);
4417+ }
4418+ }
4419+#endif
4420+
4421 if (exception_trace && printk_ratelimit())
4422 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4423 "sp %08lx ecr %lu\n",
4424diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4425index 568885a..f8008df 100644
4426--- a/arch/blackfin/include/asm/cache.h
4427+++ b/arch/blackfin/include/asm/cache.h
4428@@ -7,6 +7,7 @@
4429 #ifndef __ARCH_BLACKFIN_CACHE_H
4430 #define __ARCH_BLACKFIN_CACHE_H
4431
4432+#include <linux/const.h>
4433 #include <linux/linkage.h> /* for asmlinkage */
4434
4435 /*
4436@@ -14,7 +15,7 @@
4437 * Blackfin loads 32 bytes for cache
4438 */
4439 #define L1_CACHE_SHIFT 5
4440-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4441+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4442 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4443
4444 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4445diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4446index aea2718..3639a60 100644
4447--- a/arch/cris/include/arch-v10/arch/cache.h
4448+++ b/arch/cris/include/arch-v10/arch/cache.h
4449@@ -1,8 +1,9 @@
4450 #ifndef _ASM_ARCH_CACHE_H
4451 #define _ASM_ARCH_CACHE_H
4452
4453+#include <linux/const.h>
4454 /* Etrax 100LX have 32-byte cache-lines. */
4455-#define L1_CACHE_BYTES 32
4456 #define L1_CACHE_SHIFT 5
4457+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4458
4459 #endif /* _ASM_ARCH_CACHE_H */
4460diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4461index 7caf25d..ee65ac5 100644
4462--- a/arch/cris/include/arch-v32/arch/cache.h
4463+++ b/arch/cris/include/arch-v32/arch/cache.h
4464@@ -1,11 +1,12 @@
4465 #ifndef _ASM_CRIS_ARCH_CACHE_H
4466 #define _ASM_CRIS_ARCH_CACHE_H
4467
4468+#include <linux/const.h>
4469 #include <arch/hwregs/dma.h>
4470
4471 /* A cache-line is 32 bytes. */
4472-#define L1_CACHE_BYTES 32
4473 #define L1_CACHE_SHIFT 5
4474+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4475
4476 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4477
4478diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4479index b86329d..6709906 100644
4480--- a/arch/frv/include/asm/atomic.h
4481+++ b/arch/frv/include/asm/atomic.h
4482@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4483 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4484 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4485
4486+#define atomic64_read_unchecked(v) atomic64_read(v)
4487+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4488+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4489+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4490+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4491+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4492+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4493+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4494+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4495+
4496 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4497 {
4498 int c, old;
4499diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4500index 2797163..c2a401d 100644
4501--- a/arch/frv/include/asm/cache.h
4502+++ b/arch/frv/include/asm/cache.h
4503@@ -12,10 +12,11 @@
4504 #ifndef __ASM_CACHE_H
4505 #define __ASM_CACHE_H
4506
4507+#include <linux/const.h>
4508
4509 /* bytes per L1 cache line */
4510 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4511-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4512+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4513
4514 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4515 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4516diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4517index 43901f2..0d8b865 100644
4518--- a/arch/frv/include/asm/kmap_types.h
4519+++ b/arch/frv/include/asm/kmap_types.h
4520@@ -2,6 +2,6 @@
4521 #ifndef _ASM_KMAP_TYPES_H
4522 #define _ASM_KMAP_TYPES_H
4523
4524-#define KM_TYPE_NR 17
4525+#define KM_TYPE_NR 18
4526
4527 #endif
4528diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4529index 836f147..4cf23f5 100644
4530--- a/arch/frv/mm/elf-fdpic.c
4531+++ b/arch/frv/mm/elf-fdpic.c
4532@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4533 {
4534 struct vm_area_struct *vma;
4535 struct vm_unmapped_area_info info;
4536+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4537
4538 if (len > TASK_SIZE)
4539 return -ENOMEM;
4540@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4541 if (addr) {
4542 addr = PAGE_ALIGN(addr);
4543 vma = find_vma(current->mm, addr);
4544- if (TASK_SIZE - len >= addr &&
4545- (!vma || addr + len <= vma->vm_start))
4546+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4547 goto success;
4548 }
4549
4550@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4551 info.high_limit = (current->mm->start_stack - 0x00200000);
4552 info.align_mask = 0;
4553 info.align_offset = 0;
4554+ info.threadstack_offset = offset;
4555 addr = vm_unmapped_area(&info);
4556 if (!(addr & ~PAGE_MASK))
4557 goto success;
4558diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4559index f4ca594..adc72fd6 100644
4560--- a/arch/hexagon/include/asm/cache.h
4561+++ b/arch/hexagon/include/asm/cache.h
4562@@ -21,9 +21,11 @@
4563 #ifndef __ASM_CACHE_H
4564 #define __ASM_CACHE_H
4565
4566+#include <linux/const.h>
4567+
4568 /* Bytes per L1 cache line */
4569-#define L1_CACHE_SHIFT (5)
4570-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4571+#define L1_CACHE_SHIFT 5
4572+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4573
4574 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4575 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4576diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4577index 6e6fe18..a6ae668 100644
4578--- a/arch/ia64/include/asm/atomic.h
4579+++ b/arch/ia64/include/asm/atomic.h
4580@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4581 #define atomic64_inc(v) atomic64_add(1, (v))
4582 #define atomic64_dec(v) atomic64_sub(1, (v))
4583
4584+#define atomic64_read_unchecked(v) atomic64_read(v)
4585+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4586+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4587+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4588+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4589+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4590+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4591+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4592+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4593+
4594 /* Atomic operations are already serializing */
4595 #define smp_mb__before_atomic_dec() barrier()
4596 #define smp_mb__after_atomic_dec() barrier()
4597diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4598index 988254a..e1ee885 100644
4599--- a/arch/ia64/include/asm/cache.h
4600+++ b/arch/ia64/include/asm/cache.h
4601@@ -1,6 +1,7 @@
4602 #ifndef _ASM_IA64_CACHE_H
4603 #define _ASM_IA64_CACHE_H
4604
4605+#include <linux/const.h>
4606
4607 /*
4608 * Copyright (C) 1998-2000 Hewlett-Packard Co
4609@@ -9,7 +10,7 @@
4610
4611 /* Bytes per L1 (data) cache line. */
4612 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4613-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4614+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4615
4616 #ifdef CONFIG_SMP
4617 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4618diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4619index 5a83c5c..4d7f553 100644
4620--- a/arch/ia64/include/asm/elf.h
4621+++ b/arch/ia64/include/asm/elf.h
4622@@ -42,6 +42,13 @@
4623 */
4624 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4625
4626+#ifdef CONFIG_PAX_ASLR
4627+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4628+
4629+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4630+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4631+#endif
4632+
4633 #define PT_IA_64_UNWIND 0x70000001
4634
4635 /* IA-64 relocations: */
4636diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4637index 96a8d92..617a1cf 100644
4638--- a/arch/ia64/include/asm/pgalloc.h
4639+++ b/arch/ia64/include/asm/pgalloc.h
4640@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4641 pgd_val(*pgd_entry) = __pa(pud);
4642 }
4643
4644+static inline void
4645+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4646+{
4647+ pgd_populate(mm, pgd_entry, pud);
4648+}
4649+
4650 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4651 {
4652 return quicklist_alloc(0, GFP_KERNEL, NULL);
4653@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4654 pud_val(*pud_entry) = __pa(pmd);
4655 }
4656
4657+static inline void
4658+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4659+{
4660+ pud_populate(mm, pud_entry, pmd);
4661+}
4662+
4663 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4664 {
4665 return quicklist_alloc(0, GFP_KERNEL, NULL);
4666diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4667index 815810c..d60bd4c 100644
4668--- a/arch/ia64/include/asm/pgtable.h
4669+++ b/arch/ia64/include/asm/pgtable.h
4670@@ -12,7 +12,7 @@
4671 * David Mosberger-Tang <davidm@hpl.hp.com>
4672 */
4673
4674-
4675+#include <linux/const.h>
4676 #include <asm/mman.h>
4677 #include <asm/page.h>
4678 #include <asm/processor.h>
4679@@ -142,6 +142,17 @@
4680 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4681 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4682 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4683+
4684+#ifdef CONFIG_PAX_PAGEEXEC
4685+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4686+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4687+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4688+#else
4689+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4690+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4691+# define PAGE_COPY_NOEXEC PAGE_COPY
4692+#endif
4693+
4694 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4695 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4696 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4697diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4698index 54ff557..70c88b7 100644
4699--- a/arch/ia64/include/asm/spinlock.h
4700+++ b/arch/ia64/include/asm/spinlock.h
4701@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4702 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4703
4704 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4705- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4706+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4707 }
4708
4709 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4710diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4711index 449c8c0..18965fb 100644
4712--- a/arch/ia64/include/asm/uaccess.h
4713+++ b/arch/ia64/include/asm/uaccess.h
4714@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4715 static inline unsigned long
4716 __copy_to_user (void __user *to, const void *from, unsigned long count)
4717 {
4718+ if (count > INT_MAX)
4719+ return count;
4720+
4721+ if (!__builtin_constant_p(count))
4722+ check_object_size(from, count, true);
4723+
4724 return __copy_user(to, (__force void __user *) from, count);
4725 }
4726
4727 static inline unsigned long
4728 __copy_from_user (void *to, const void __user *from, unsigned long count)
4729 {
4730+ if (count > INT_MAX)
4731+ return count;
4732+
4733+ if (!__builtin_constant_p(count))
4734+ check_object_size(to, count, false);
4735+
4736 return __copy_user((__force void __user *) to, from, count);
4737 }
4738
4739@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4740 ({ \
4741 void __user *__cu_to = (to); \
4742 const void *__cu_from = (from); \
4743- long __cu_len = (n); \
4744+ unsigned long __cu_len = (n); \
4745 \
4746- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4747+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4748+ if (!__builtin_constant_p(n)) \
4749+ check_object_size(__cu_from, __cu_len, true); \
4750 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4751+ } \
4752 __cu_len; \
4753 })
4754
4755@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4756 ({ \
4757 void *__cu_to = (to); \
4758 const void __user *__cu_from = (from); \
4759- long __cu_len = (n); \
4760+ unsigned long __cu_len = (n); \
4761 \
4762 __chk_user_ptr(__cu_from); \
4763- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4764+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4765+ if (!__builtin_constant_p(n)) \
4766+ check_object_size(__cu_to, __cu_len, false); \
4767 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4768+ } \
4769 __cu_len; \
4770 })
4771
4772diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4773index 2d67317..07d8bfa 100644
4774--- a/arch/ia64/kernel/err_inject.c
4775+++ b/arch/ia64/kernel/err_inject.c
4776@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4777 return NOTIFY_OK;
4778 }
4779
4780-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4781+static struct notifier_block err_inject_cpu_notifier =
4782 {
4783 .notifier_call = err_inject_cpu_callback,
4784 };
4785diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4786index d7396db..b33e873 100644
4787--- a/arch/ia64/kernel/mca.c
4788+++ b/arch/ia64/kernel/mca.c
4789@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4790 return NOTIFY_OK;
4791 }
4792
4793-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4794+static struct notifier_block mca_cpu_notifier = {
4795 .notifier_call = mca_cpu_callback
4796 };
4797
4798diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4799index 24603be..948052d 100644
4800--- a/arch/ia64/kernel/module.c
4801+++ b/arch/ia64/kernel/module.c
4802@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4803 void
4804 module_free (struct module *mod, void *module_region)
4805 {
4806- if (mod && mod->arch.init_unw_table &&
4807- module_region == mod->module_init) {
4808+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4809 unw_remove_unwind_table(mod->arch.init_unw_table);
4810 mod->arch.init_unw_table = NULL;
4811 }
4812@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4813 }
4814
4815 static inline int
4816+in_init_rx (const struct module *mod, uint64_t addr)
4817+{
4818+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4819+}
4820+
4821+static inline int
4822+in_init_rw (const struct module *mod, uint64_t addr)
4823+{
4824+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4825+}
4826+
4827+static inline int
4828 in_init (const struct module *mod, uint64_t addr)
4829 {
4830- return addr - (uint64_t) mod->module_init < mod->init_size;
4831+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4832+}
4833+
4834+static inline int
4835+in_core_rx (const struct module *mod, uint64_t addr)
4836+{
4837+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4838+}
4839+
4840+static inline int
4841+in_core_rw (const struct module *mod, uint64_t addr)
4842+{
4843+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4844 }
4845
4846 static inline int
4847 in_core (const struct module *mod, uint64_t addr)
4848 {
4849- return addr - (uint64_t) mod->module_core < mod->core_size;
4850+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4851 }
4852
4853 static inline int
4854@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4855 break;
4856
4857 case RV_BDREL:
4858- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4859+ if (in_init_rx(mod, val))
4860+ val -= (uint64_t) mod->module_init_rx;
4861+ else if (in_init_rw(mod, val))
4862+ val -= (uint64_t) mod->module_init_rw;
4863+ else if (in_core_rx(mod, val))
4864+ val -= (uint64_t) mod->module_core_rx;
4865+ else if (in_core_rw(mod, val))
4866+ val -= (uint64_t) mod->module_core_rw;
4867 break;
4868
4869 case RV_LTV:
4870@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4871 * addresses have been selected...
4872 */
4873 uint64_t gp;
4874- if (mod->core_size > MAX_LTOFF)
4875+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4876 /*
4877 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4878 * at the end of the module.
4879 */
4880- gp = mod->core_size - MAX_LTOFF / 2;
4881+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4882 else
4883- gp = mod->core_size / 2;
4884- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4885+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4886+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4887 mod->arch.gp = gp;
4888 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4889 }
4890diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4891index 79521d5..43dddff 100644
4892--- a/arch/ia64/kernel/palinfo.c
4893+++ b/arch/ia64/kernel/palinfo.c
4894@@ -1006,7 +1006,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4895 return NOTIFY_OK;
4896 }
4897
4898-static struct notifier_block __refdata palinfo_cpu_notifier =
4899+static struct notifier_block palinfo_cpu_notifier =
4900 {
4901 .notifier_call = palinfo_cpu_callback,
4902 .priority = 0,
4903diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4904index aa527d7..f237752 100644
4905--- a/arch/ia64/kernel/salinfo.c
4906+++ b/arch/ia64/kernel/salinfo.c
4907@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4908 return NOTIFY_OK;
4909 }
4910
4911-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4912+static struct notifier_block salinfo_cpu_notifier =
4913 {
4914 .notifier_call = salinfo_cpu_callback,
4915 .priority = 0,
4916diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4917index 41e33f8..65180b2 100644
4918--- a/arch/ia64/kernel/sys_ia64.c
4919+++ b/arch/ia64/kernel/sys_ia64.c
4920@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4921 unsigned long align_mask = 0;
4922 struct mm_struct *mm = current->mm;
4923 struct vm_unmapped_area_info info;
4924+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4925
4926 if (len > RGN_MAP_LIMIT)
4927 return -ENOMEM;
4928@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4929 if (REGION_NUMBER(addr) == RGN_HPAGE)
4930 addr = 0;
4931 #endif
4932+
4933+#ifdef CONFIG_PAX_RANDMMAP
4934+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4935+ addr = mm->free_area_cache;
4936+ else
4937+#endif
4938+
4939 if (!addr)
4940 addr = TASK_UNMAPPED_BASE;
4941
4942@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4943 info.high_limit = TASK_SIZE;
4944 info.align_mask = align_mask;
4945 info.align_offset = 0;
4946+ info.threadstack_offset = offset;
4947 return vm_unmapped_area(&info);
4948 }
4949
4950diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
4951index dc00b2c..cce53c2 100644
4952--- a/arch/ia64/kernel/topology.c
4953+++ b/arch/ia64/kernel/topology.c
4954@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
4955 return NOTIFY_OK;
4956 }
4957
4958-static struct notifier_block __cpuinitdata cache_cpu_notifier =
4959+static struct notifier_block cache_cpu_notifier =
4960 {
4961 .notifier_call = cache_cpu_callback
4962 };
4963diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
4964index 0ccb28f..8992469 100644
4965--- a/arch/ia64/kernel/vmlinux.lds.S
4966+++ b/arch/ia64/kernel/vmlinux.lds.S
4967@@ -198,7 +198,7 @@ SECTIONS {
4968 /* Per-cpu data: */
4969 . = ALIGN(PERCPU_PAGE_SIZE);
4970 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
4971- __phys_per_cpu_start = __per_cpu_load;
4972+ __phys_per_cpu_start = per_cpu_load;
4973 /*
4974 * ensure percpu data fits
4975 * into percpu page size
4976diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
4977index 6cf0341..d352594 100644
4978--- a/arch/ia64/mm/fault.c
4979+++ b/arch/ia64/mm/fault.c
4980@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
4981 return pte_present(pte);
4982 }
4983
4984+#ifdef CONFIG_PAX_PAGEEXEC
4985+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4986+{
4987+ unsigned long i;
4988+
4989+ printk(KERN_ERR "PAX: bytes at PC: ");
4990+ for (i = 0; i < 8; i++) {
4991+ unsigned int c;
4992+ if (get_user(c, (unsigned int *)pc+i))
4993+ printk(KERN_CONT "???????? ");
4994+ else
4995+ printk(KERN_CONT "%08x ", c);
4996+ }
4997+ printk("\n");
4998+}
4999+#endif
5000+
5001 # define VM_READ_BIT 0
5002 # define VM_WRITE_BIT 1
5003 # define VM_EXEC_BIT 2
5004@@ -149,8 +166,21 @@ retry:
5005 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5006 goto bad_area;
5007
5008- if ((vma->vm_flags & mask) != mask)
5009+ if ((vma->vm_flags & mask) != mask) {
5010+
5011+#ifdef CONFIG_PAX_PAGEEXEC
5012+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5013+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5014+ goto bad_area;
5015+
5016+ up_read(&mm->mmap_sem);
5017+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5018+ do_group_exit(SIGKILL);
5019+ }
5020+#endif
5021+
5022 goto bad_area;
5023+ }
5024
5025 /*
5026 * If for any reason at all we couldn't handle the fault, make
5027diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5028index 76069c1..c2aa816 100644
5029--- a/arch/ia64/mm/hugetlbpage.c
5030+++ b/arch/ia64/mm/hugetlbpage.c
5031@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5032 unsigned long pgoff, unsigned long flags)
5033 {
5034 struct vm_unmapped_area_info info;
5035+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5036
5037 if (len > RGN_MAP_LIMIT)
5038 return -ENOMEM;
5039@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5040 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5041 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5042 info.align_offset = 0;
5043+ info.threadstack_offset = offset;
5044 return vm_unmapped_area(&info);
5045 }
5046
5047diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5048index 20bc967..a26993e 100644
5049--- a/arch/ia64/mm/init.c
5050+++ b/arch/ia64/mm/init.c
5051@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5052 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5053 vma->vm_end = vma->vm_start + PAGE_SIZE;
5054 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5055+
5056+#ifdef CONFIG_PAX_PAGEEXEC
5057+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5058+ vma->vm_flags &= ~VM_EXEC;
5059+
5060+#ifdef CONFIG_PAX_MPROTECT
5061+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5062+ vma->vm_flags &= ~VM_MAYEXEC;
5063+#endif
5064+
5065+ }
5066+#endif
5067+
5068 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5069 down_write(&current->mm->mmap_sem);
5070 if (insert_vm_struct(current->mm, vma)) {
5071diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5072index 40b3ee9..8c2c112 100644
5073--- a/arch/m32r/include/asm/cache.h
5074+++ b/arch/m32r/include/asm/cache.h
5075@@ -1,8 +1,10 @@
5076 #ifndef _ASM_M32R_CACHE_H
5077 #define _ASM_M32R_CACHE_H
5078
5079+#include <linux/const.h>
5080+
5081 /* L1 cache line size */
5082 #define L1_CACHE_SHIFT 4
5083-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5084+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5085
5086 #endif /* _ASM_M32R_CACHE_H */
5087diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5088index 82abd15..d95ae5d 100644
5089--- a/arch/m32r/lib/usercopy.c
5090+++ b/arch/m32r/lib/usercopy.c
5091@@ -14,6 +14,9 @@
5092 unsigned long
5093 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5094 {
5095+ if ((long)n < 0)
5096+ return n;
5097+
5098 prefetch(from);
5099 if (access_ok(VERIFY_WRITE, to, n))
5100 __copy_user(to,from,n);
5101@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5102 unsigned long
5103 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5104 {
5105+ if ((long)n < 0)
5106+ return n;
5107+
5108 prefetchw(to);
5109 if (access_ok(VERIFY_READ, from, n))
5110 __copy_user_zeroing(to,from,n);
5111diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5112index 0395c51..5f26031 100644
5113--- a/arch/m68k/include/asm/cache.h
5114+++ b/arch/m68k/include/asm/cache.h
5115@@ -4,9 +4,11 @@
5116 #ifndef __ARCH_M68K_CACHE_H
5117 #define __ARCH_M68K_CACHE_H
5118
5119+#include <linux/const.h>
5120+
5121 /* bytes per L1 cache line */
5122 #define L1_CACHE_SHIFT 4
5123-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5124+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5125
5126 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5127
5128diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5129index 3c52fa6..11b2ad8 100644
5130--- a/arch/metag/mm/hugetlbpage.c
5131+++ b/arch/metag/mm/hugetlbpage.c
5132@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5133 info.high_limit = TASK_SIZE;
5134 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5135 info.align_offset = 0;
5136+ info.threadstack_offset = 0;
5137 return vm_unmapped_area(&info);
5138 }
5139
5140diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5141index 4efe96a..60e8699 100644
5142--- a/arch/microblaze/include/asm/cache.h
5143+++ b/arch/microblaze/include/asm/cache.h
5144@@ -13,11 +13,12 @@
5145 #ifndef _ASM_MICROBLAZE_CACHE_H
5146 #define _ASM_MICROBLAZE_CACHE_H
5147
5148+#include <linux/const.h>
5149 #include <asm/registers.h>
5150
5151 #define L1_CACHE_SHIFT 5
5152 /* word-granular cache in microblaze */
5153-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5154+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5155
5156 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5157
5158diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5159index 08b6079..eb272cf 100644
5160--- a/arch/mips/include/asm/atomic.h
5161+++ b/arch/mips/include/asm/atomic.h
5162@@ -21,6 +21,10 @@
5163 #include <asm/cmpxchg.h>
5164 #include <asm/war.h>
5165
5166+#ifdef CONFIG_GENERIC_ATOMIC64
5167+#include <asm-generic/atomic64.h>
5168+#endif
5169+
5170 #define ATOMIC_INIT(i) { (i) }
5171
5172 /*
5173@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5174 */
5175 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5176
5177+#define atomic64_read_unchecked(v) atomic64_read(v)
5178+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5179+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5180+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5181+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5182+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5183+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5184+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5185+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5186+
5187 #endif /* CONFIG_64BIT */
5188
5189 /*
5190diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5191index b4db69f..8f3b093 100644
5192--- a/arch/mips/include/asm/cache.h
5193+++ b/arch/mips/include/asm/cache.h
5194@@ -9,10 +9,11 @@
5195 #ifndef _ASM_CACHE_H
5196 #define _ASM_CACHE_H
5197
5198+#include <linux/const.h>
5199 #include <kmalloc.h>
5200
5201 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5202-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5203+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5204
5205 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5206 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5207diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5208index cf3ae24..238d22f 100644
5209--- a/arch/mips/include/asm/elf.h
5210+++ b/arch/mips/include/asm/elf.h
5211@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5212 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5213 #endif
5214
5215+#ifdef CONFIG_PAX_ASLR
5216+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5217+
5218+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5219+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5220+#endif
5221+
5222 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5223 struct linux_binprm;
5224 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5225 int uses_interp);
5226
5227-struct mm_struct;
5228-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5229-#define arch_randomize_brk arch_randomize_brk
5230-
5231 #endif /* _ASM_ELF_H */
5232diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5233index c1f6afa..38cc6e9 100644
5234--- a/arch/mips/include/asm/exec.h
5235+++ b/arch/mips/include/asm/exec.h
5236@@ -12,6 +12,6 @@
5237 #ifndef _ASM_EXEC_H
5238 #define _ASM_EXEC_H
5239
5240-extern unsigned long arch_align_stack(unsigned long sp);
5241+#define arch_align_stack(x) ((x) & ~0xfUL)
5242
5243 #endif /* _ASM_EXEC_H */
5244diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5245index eab99e5..607c98e 100644
5246--- a/arch/mips/include/asm/page.h
5247+++ b/arch/mips/include/asm/page.h
5248@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5249 #ifdef CONFIG_CPU_MIPS32
5250 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5251 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5252- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5253+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5254 #else
5255 typedef struct { unsigned long long pte; } pte_t;
5256 #define pte_val(x) ((x).pte)
5257diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5258index 881d18b..cea38bc 100644
5259--- a/arch/mips/include/asm/pgalloc.h
5260+++ b/arch/mips/include/asm/pgalloc.h
5261@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5262 {
5263 set_pud(pud, __pud((unsigned long)pmd));
5264 }
5265+
5266+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5267+{
5268+ pud_populate(mm, pud, pmd);
5269+}
5270 #endif
5271
5272 /*
5273diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5274index 178f792..8ebc510 100644
5275--- a/arch/mips/include/asm/thread_info.h
5276+++ b/arch/mips/include/asm/thread_info.h
5277@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5278 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5279 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5280 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5281+/* li takes a 32bit immediate */
5282+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5283 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5284
5285 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5286@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5287 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5288 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5289 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5290+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5291+
5292+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5293
5294 /* work to do in syscall_trace_leave() */
5295-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5296+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5297
5298 /* work to do on interrupt/exception return */
5299 #define _TIF_WORK_MASK \
5300 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5301 /* work to do on any return to u-space */
5302-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5303+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5304
5305 #endif /* __KERNEL__ */
5306
5307diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5308index e06f777..3244284 100644
5309--- a/arch/mips/kernel/binfmt_elfn32.c
5310+++ b/arch/mips/kernel/binfmt_elfn32.c
5311@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5312 #undef ELF_ET_DYN_BASE
5313 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5314
5315+#ifdef CONFIG_PAX_ASLR
5316+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5317+
5318+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5319+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5320+#endif
5321+
5322 #include <asm/processor.h>
5323 #include <linux/module.h>
5324 #include <linux/elfcore.h>
5325diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5326index 556a435..b4fd2e3 100644
5327--- a/arch/mips/kernel/binfmt_elfo32.c
5328+++ b/arch/mips/kernel/binfmt_elfo32.c
5329@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5330 #undef ELF_ET_DYN_BASE
5331 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5332
5333+#ifdef CONFIG_PAX_ASLR
5334+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5335+
5336+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5337+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5338+#endif
5339+
5340 #include <asm/processor.h>
5341
5342 /*
5343diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5344index 3be4405..a799827 100644
5345--- a/arch/mips/kernel/process.c
5346+++ b/arch/mips/kernel/process.c
5347@@ -461,15 +461,3 @@ unsigned long get_wchan(struct task_struct *task)
5348 out:
5349 return pc;
5350 }
5351-
5352-/*
5353- * Don't forget that the stack pointer must be aligned on a 8 bytes
5354- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5355- */
5356-unsigned long arch_align_stack(unsigned long sp)
5357-{
5358- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5359- sp -= get_random_int() & ~PAGE_MASK;
5360-
5361- return sp & ALMASK;
5362-}
5363diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5364index 9c6299c..2fb4c22 100644
5365--- a/arch/mips/kernel/ptrace.c
5366+++ b/arch/mips/kernel/ptrace.c
5367@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5368 return arch;
5369 }
5370
5371+#ifdef CONFIG_GRKERNSEC_SETXID
5372+extern void gr_delayed_cred_worker(void);
5373+#endif
5374+
5375 /*
5376 * Notification of system call entry/exit
5377 * - triggered by current->work.syscall_trace
5378@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5379 /* do the secure computing check first */
5380 secure_computing_strict(regs->regs[2]);
5381
5382+#ifdef CONFIG_GRKERNSEC_SETXID
5383+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5384+ gr_delayed_cred_worker();
5385+#endif
5386+
5387 if (!(current->ptrace & PT_PTRACED))
5388 goto out;
5389
5390diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5391index 9ea2964..c4329c3 100644
5392--- a/arch/mips/kernel/scall32-o32.S
5393+++ b/arch/mips/kernel/scall32-o32.S
5394@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5395
5396 stack_done:
5397 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5398- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5399+ li t1, _TIF_SYSCALL_WORK
5400 and t0, t1
5401 bnez t0, syscall_trace_entry # -> yes
5402
5403diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5404index 36cfd40..b1436e0 100644
5405--- a/arch/mips/kernel/scall64-64.S
5406+++ b/arch/mips/kernel/scall64-64.S
5407@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5408
5409 sd a3, PT_R26(sp) # save a3 for syscall restarting
5410
5411- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5412+ li t1, _TIF_SYSCALL_WORK
5413 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5414 and t0, t1, t0
5415 bnez t0, syscall_trace_entry
5416diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5417index 693d60b..ae0ba75 100644
5418--- a/arch/mips/kernel/scall64-n32.S
5419+++ b/arch/mips/kernel/scall64-n32.S
5420@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5421
5422 sd a3, PT_R26(sp) # save a3 for syscall restarting
5423
5424- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5425+ li t1, _TIF_SYSCALL_WORK
5426 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5427 and t0, t1, t0
5428 bnez t0, n32_syscall_trace_entry
5429diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5430index af8887f..611ccb6 100644
5431--- a/arch/mips/kernel/scall64-o32.S
5432+++ b/arch/mips/kernel/scall64-o32.S
5433@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5434 PTR 4b, bad_stack
5435 .previous
5436
5437- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5438+ li t1, _TIF_SYSCALL_WORK
5439 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5440 and t0, t1, t0
5441 bnez t0, trace_a_syscall
5442diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5443index 0fead53..a2c0fb5 100644
5444--- a/arch/mips/mm/fault.c
5445+++ b/arch/mips/mm/fault.c
5446@@ -27,6 +27,23 @@
5447 #include <asm/highmem.h> /* For VMALLOC_END */
5448 #include <linux/kdebug.h>
5449
5450+#ifdef CONFIG_PAX_PAGEEXEC
5451+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5452+{
5453+ unsigned long i;
5454+
5455+ printk(KERN_ERR "PAX: bytes at PC: ");
5456+ for (i = 0; i < 5; i++) {
5457+ unsigned int c;
5458+ if (get_user(c, (unsigned int *)pc+i))
5459+ printk(KERN_CONT "???????? ");
5460+ else
5461+ printk(KERN_CONT "%08x ", c);
5462+ }
5463+ printk("\n");
5464+}
5465+#endif
5466+
5467 /*
5468 * This routine handles page faults. It determines the address,
5469 * and the problem, and then passes it off to one of the appropriate
5470diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5471index 7e5fe27..9656513 100644
5472--- a/arch/mips/mm/mmap.c
5473+++ b/arch/mips/mm/mmap.c
5474@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5475 struct vm_area_struct *vma;
5476 unsigned long addr = addr0;
5477 int do_color_align;
5478+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5479 struct vm_unmapped_area_info info;
5480
5481 if (unlikely(len > TASK_SIZE))
5482@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5483 do_color_align = 1;
5484
5485 /* requesting a specific address */
5486+
5487+#ifdef CONFIG_PAX_RANDMMAP
5488+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5489+#endif
5490+
5491 if (addr) {
5492 if (do_color_align)
5493 addr = COLOUR_ALIGN(addr, pgoff);
5494@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5495 addr = PAGE_ALIGN(addr);
5496
5497 vma = find_vma(mm, addr);
5498- if (TASK_SIZE - len >= addr &&
5499- (!vma || addr + len <= vma->vm_start))
5500+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5501 return addr;
5502 }
5503
5504 info.length = len;
5505 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
5506 info.align_offset = pgoff << PAGE_SHIFT;
5507+ info.threadstack_offset = offset;
5508
5509 if (dir == DOWN) {
5510 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
5511@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5512 {
5513 unsigned long random_factor = 0UL;
5514
5515+#ifdef CONFIG_PAX_RANDMMAP
5516+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5517+#endif
5518+
5519 if (current->flags & PF_RANDOMIZE) {
5520 random_factor = get_random_int();
5521 random_factor = random_factor << PAGE_SHIFT;
5522@@ -157,42 +167,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5523
5524 if (mmap_is_legacy()) {
5525 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5526+
5527+#ifdef CONFIG_PAX_RANDMMAP
5528+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5529+ mm->mmap_base += mm->delta_mmap;
5530+#endif
5531+
5532 mm->get_unmapped_area = arch_get_unmapped_area;
5533 mm->unmap_area = arch_unmap_area;
5534 } else {
5535 mm->mmap_base = mmap_base(random_factor);
5536+
5537+#ifdef CONFIG_PAX_RANDMMAP
5538+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5539+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5540+#endif
5541+
5542 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5543 mm->unmap_area = arch_unmap_area_topdown;
5544 }
5545 }
5546
5547-static inline unsigned long brk_rnd(void)
5548-{
5549- unsigned long rnd = get_random_int();
5550-
5551- rnd = rnd << PAGE_SHIFT;
5552- /* 8MB for 32bit, 256MB for 64bit */
5553- if (TASK_IS_32BIT_ADDR)
5554- rnd = rnd & 0x7ffffful;
5555- else
5556- rnd = rnd & 0xffffffful;
5557-
5558- return rnd;
5559-}
5560-
5561-unsigned long arch_randomize_brk(struct mm_struct *mm)
5562-{
5563- unsigned long base = mm->brk;
5564- unsigned long ret;
5565-
5566- ret = PAGE_ALIGN(base + brk_rnd());
5567-
5568- if (ret < mm->brk)
5569- return mm->brk;
5570-
5571- return ret;
5572-}
5573-
5574 int __virt_addr_valid(const volatile void *kaddr)
5575 {
5576 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5577diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5578index 967d144..db12197 100644
5579--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5580+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5581@@ -11,12 +11,14 @@
5582 #ifndef _ASM_PROC_CACHE_H
5583 #define _ASM_PROC_CACHE_H
5584
5585+#include <linux/const.h>
5586+
5587 /* L1 cache */
5588
5589 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5590 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5591-#define L1_CACHE_BYTES 16 /* bytes per entry */
5592 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5593+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5594 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5595
5596 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5597diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5598index bcb5df2..84fabd2 100644
5599--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5600+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5601@@ -16,13 +16,15 @@
5602 #ifndef _ASM_PROC_CACHE_H
5603 #define _ASM_PROC_CACHE_H
5604
5605+#include <linux/const.h>
5606+
5607 /*
5608 * L1 cache
5609 */
5610 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5611 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5612-#define L1_CACHE_BYTES 32 /* bytes per entry */
5613 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5614+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5615 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5616
5617 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5618diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5619index 4ce7a01..449202a 100644
5620--- a/arch/openrisc/include/asm/cache.h
5621+++ b/arch/openrisc/include/asm/cache.h
5622@@ -19,11 +19,13 @@
5623 #ifndef __ASM_OPENRISC_CACHE_H
5624 #define __ASM_OPENRISC_CACHE_H
5625
5626+#include <linux/const.h>
5627+
5628 /* FIXME: How can we replace these with values from the CPU...
5629 * they shouldn't be hard-coded!
5630 */
5631
5632-#define L1_CACHE_BYTES 16
5633 #define L1_CACHE_SHIFT 4
5634+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5635
5636 #endif /* __ASM_OPENRISC_CACHE_H */
5637diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5638index f38e198..4179e38 100644
5639--- a/arch/parisc/include/asm/atomic.h
5640+++ b/arch/parisc/include/asm/atomic.h
5641@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5642
5643 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5644
5645+#define atomic64_read_unchecked(v) atomic64_read(v)
5646+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5647+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5648+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5649+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5650+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5651+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5652+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5653+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5654+
5655 #endif /* !CONFIG_64BIT */
5656
5657
5658diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5659index 47f11c7..3420df2 100644
5660--- a/arch/parisc/include/asm/cache.h
5661+++ b/arch/parisc/include/asm/cache.h
5662@@ -5,6 +5,7 @@
5663 #ifndef __ARCH_PARISC_CACHE_H
5664 #define __ARCH_PARISC_CACHE_H
5665
5666+#include <linux/const.h>
5667
5668 /*
5669 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5670@@ -15,13 +16,13 @@
5671 * just ruin performance.
5672 */
5673 #ifdef CONFIG_PA20
5674-#define L1_CACHE_BYTES 64
5675 #define L1_CACHE_SHIFT 6
5676 #else
5677-#define L1_CACHE_BYTES 32
5678 #define L1_CACHE_SHIFT 5
5679 #endif
5680
5681+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5682+
5683 #ifndef __ASSEMBLY__
5684
5685 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5686diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5687index ad2b503..bdf1651 100644
5688--- a/arch/parisc/include/asm/elf.h
5689+++ b/arch/parisc/include/asm/elf.h
5690@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5691
5692 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5693
5694+#ifdef CONFIG_PAX_ASLR
5695+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5696+
5697+#define PAX_DELTA_MMAP_LEN 16
5698+#define PAX_DELTA_STACK_LEN 16
5699+#endif
5700+
5701 /* This yields a mask that user programs can use to figure out what
5702 instruction set this CPU supports. This could be done in user space,
5703 but it's not easy, and we've already done it here. */
5704diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5705index fc987a1..6e068ef 100644
5706--- a/arch/parisc/include/asm/pgalloc.h
5707+++ b/arch/parisc/include/asm/pgalloc.h
5708@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5709 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5710 }
5711
5712+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5713+{
5714+ pgd_populate(mm, pgd, pmd);
5715+}
5716+
5717 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5718 {
5719 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5720@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5721 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5722 #define pmd_free(mm, x) do { } while (0)
5723 #define pgd_populate(mm, pmd, pte) BUG()
5724+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5725
5726 #endif
5727
5728diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5729index 1e40d7f..a3eb445 100644
5730--- a/arch/parisc/include/asm/pgtable.h
5731+++ b/arch/parisc/include/asm/pgtable.h
5732@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5733 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5734 #define PAGE_COPY PAGE_EXECREAD
5735 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5736+
5737+#ifdef CONFIG_PAX_PAGEEXEC
5738+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5739+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5740+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5741+#else
5742+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5743+# define PAGE_COPY_NOEXEC PAGE_COPY
5744+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5745+#endif
5746+
5747 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5748 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5749 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5750diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5751index e0a8235..ce2f1e1 100644
5752--- a/arch/parisc/include/asm/uaccess.h
5753+++ b/arch/parisc/include/asm/uaccess.h
5754@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5755 const void __user *from,
5756 unsigned long n)
5757 {
5758- int sz = __compiletime_object_size(to);
5759+ size_t sz = __compiletime_object_size(to);
5760 int ret = -EFAULT;
5761
5762- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5763+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5764 ret = __copy_from_user(to, from, n);
5765 else
5766 copy_from_user_overflow();
5767diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5768index 2a625fb..9908930 100644
5769--- a/arch/parisc/kernel/module.c
5770+++ b/arch/parisc/kernel/module.c
5771@@ -98,16 +98,38 @@
5772
5773 /* three functions to determine where in the module core
5774 * or init pieces the location is */
5775+static inline int in_init_rx(struct module *me, void *loc)
5776+{
5777+ return (loc >= me->module_init_rx &&
5778+ loc < (me->module_init_rx + me->init_size_rx));
5779+}
5780+
5781+static inline int in_init_rw(struct module *me, void *loc)
5782+{
5783+ return (loc >= me->module_init_rw &&
5784+ loc < (me->module_init_rw + me->init_size_rw));
5785+}
5786+
5787 static inline int in_init(struct module *me, void *loc)
5788 {
5789- return (loc >= me->module_init &&
5790- loc <= (me->module_init + me->init_size));
5791+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5792+}
5793+
5794+static inline int in_core_rx(struct module *me, void *loc)
5795+{
5796+ return (loc >= me->module_core_rx &&
5797+ loc < (me->module_core_rx + me->core_size_rx));
5798+}
5799+
5800+static inline int in_core_rw(struct module *me, void *loc)
5801+{
5802+ return (loc >= me->module_core_rw &&
5803+ loc < (me->module_core_rw + me->core_size_rw));
5804 }
5805
5806 static inline int in_core(struct module *me, void *loc)
5807 {
5808- return (loc >= me->module_core &&
5809- loc <= (me->module_core + me->core_size));
5810+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5811 }
5812
5813 static inline int in_local(struct module *me, void *loc)
5814@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5815 }
5816
5817 /* align things a bit */
5818- me->core_size = ALIGN(me->core_size, 16);
5819- me->arch.got_offset = me->core_size;
5820- me->core_size += gots * sizeof(struct got_entry);
5821+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5822+ me->arch.got_offset = me->core_size_rw;
5823+ me->core_size_rw += gots * sizeof(struct got_entry);
5824
5825- me->core_size = ALIGN(me->core_size, 16);
5826- me->arch.fdesc_offset = me->core_size;
5827- me->core_size += fdescs * sizeof(Elf_Fdesc);
5828+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5829+ me->arch.fdesc_offset = me->core_size_rw;
5830+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5831
5832 me->arch.got_max = gots;
5833 me->arch.fdesc_max = fdescs;
5834@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5835
5836 BUG_ON(value == 0);
5837
5838- got = me->module_core + me->arch.got_offset;
5839+ got = me->module_core_rw + me->arch.got_offset;
5840 for (i = 0; got[i].addr; i++)
5841 if (got[i].addr == value)
5842 goto out;
5843@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5844 #ifdef CONFIG_64BIT
5845 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5846 {
5847- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5848+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5849
5850 if (!value) {
5851 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5852@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5853
5854 /* Create new one */
5855 fdesc->addr = value;
5856- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5857+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5858 return (Elf_Addr)fdesc;
5859 }
5860 #endif /* CONFIG_64BIT */
5861@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5862
5863 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5864 end = table + sechdrs[me->arch.unwind_section].sh_size;
5865- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5866+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5867
5868 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5869 me->arch.unwind_section, table, end, gp);
5870diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5871index 5dfd248..64914ac 100644
5872--- a/arch/parisc/kernel/sys_parisc.c
5873+++ b/arch/parisc/kernel/sys_parisc.c
5874@@ -33,9 +33,11 @@
5875 #include <linux/utsname.h>
5876 #include <linux/personality.h>
5877
5878-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5879+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5880+ unsigned long flags)
5881 {
5882 struct vm_unmapped_area_info info;
5883+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5884
5885 info.flags = 0;
5886 info.length = len;
5887@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5888 info.high_limit = TASK_SIZE;
5889 info.align_mask = 0;
5890 info.align_offset = 0;
5891+ info.threadstack_offset = offset;
5892 return vm_unmapped_area(&info);
5893 }
5894
5895@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
5896 return (unsigned long) mapping >> 8;
5897 }
5898
5899-static unsigned long get_shared_area(struct address_space *mapping,
5900- unsigned long addr, unsigned long len, unsigned long pgoff)
5901+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5902+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5903 {
5904 struct vm_unmapped_area_info info;
5905+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5906
5907 info.flags = 0;
5908 info.length = len;
5909@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5910 info.high_limit = TASK_SIZE;
5911 info.align_mask = PAGE_MASK & (SHMLBA - 1);
5912 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
5913+ info.threadstack_offset = offset;
5914 return vm_unmapped_area(&info);
5915 }
5916
5917@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5918 return -EINVAL;
5919 return addr;
5920 }
5921- if (!addr)
5922+ if (!addr) {
5923 addr = TASK_UNMAPPED_BASE;
5924
5925+#ifdef CONFIG_PAX_RANDMMAP
5926+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
5927+ addr += current->mm->delta_mmap;
5928+#endif
5929+
5930+ }
5931+
5932 if (filp) {
5933- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5934+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5935 } else if(flags & MAP_SHARED) {
5936- addr = get_shared_area(NULL, addr, len, pgoff);
5937+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
5938 } else {
5939- addr = get_unshared_area(addr, len);
5940+ addr = get_unshared_area(filp, addr, len, flags);
5941 }
5942 return addr;
5943 }
5944diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
5945index c6ae9f5..e9c3cf4 100644
5946--- a/arch/parisc/kernel/traps.c
5947+++ b/arch/parisc/kernel/traps.c
5948@@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
5949
5950 down_read(&current->mm->mmap_sem);
5951 vma = find_vma(current->mm,regs->iaoq[0]);
5952- if (vma && (regs->iaoq[0] >= vma->vm_start)
5953- && (vma->vm_flags & VM_EXEC)) {
5954-
5955+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
5956 fault_address = regs->iaoq[0];
5957 fault_space = regs->iasq[0];
5958
5959diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
5960index f247a34..dc0f219 100644
5961--- a/arch/parisc/mm/fault.c
5962+++ b/arch/parisc/mm/fault.c
5963@@ -15,6 +15,7 @@
5964 #include <linux/sched.h>
5965 #include <linux/interrupt.h>
5966 #include <linux/module.h>
5967+#include <linux/unistd.h>
5968
5969 #include <asm/uaccess.h>
5970 #include <asm/traps.h>
5971@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
5972 static unsigned long
5973 parisc_acctyp(unsigned long code, unsigned int inst)
5974 {
5975- if (code == 6 || code == 16)
5976+ if (code == 6 || code == 7 || code == 16)
5977 return VM_EXEC;
5978
5979 switch (inst & 0xf0000000) {
5980@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
5981 }
5982 #endif
5983
5984+#ifdef CONFIG_PAX_PAGEEXEC
5985+/*
5986+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
5987+ *
5988+ * returns 1 when task should be killed
5989+ * 2 when rt_sigreturn trampoline was detected
5990+ * 3 when unpatched PLT trampoline was detected
5991+ */
5992+static int pax_handle_fetch_fault(struct pt_regs *regs)
5993+{
5994+
5995+#ifdef CONFIG_PAX_EMUPLT
5996+ int err;
5997+
5998+ do { /* PaX: unpatched PLT emulation */
5999+ unsigned int bl, depwi;
6000+
6001+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6002+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6003+
6004+ if (err)
6005+ break;
6006+
6007+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6008+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6009+
6010+ err = get_user(ldw, (unsigned int *)addr);
6011+ err |= get_user(bv, (unsigned int *)(addr+4));
6012+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6013+
6014+ if (err)
6015+ break;
6016+
6017+ if (ldw == 0x0E801096U &&
6018+ bv == 0xEAC0C000U &&
6019+ ldw2 == 0x0E881095U)
6020+ {
6021+ unsigned int resolver, map;
6022+
6023+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6024+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6025+ if (err)
6026+ break;
6027+
6028+ regs->gr[20] = instruction_pointer(regs)+8;
6029+ regs->gr[21] = map;
6030+ regs->gr[22] = resolver;
6031+ regs->iaoq[0] = resolver | 3UL;
6032+ regs->iaoq[1] = regs->iaoq[0] + 4;
6033+ return 3;
6034+ }
6035+ }
6036+ } while (0);
6037+#endif
6038+
6039+#ifdef CONFIG_PAX_EMUTRAMP
6040+
6041+#ifndef CONFIG_PAX_EMUSIGRT
6042+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6043+ return 1;
6044+#endif
6045+
6046+ do { /* PaX: rt_sigreturn emulation */
6047+ unsigned int ldi1, ldi2, bel, nop;
6048+
6049+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6050+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6051+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6052+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6053+
6054+ if (err)
6055+ break;
6056+
6057+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6058+ ldi2 == 0x3414015AU &&
6059+ bel == 0xE4008200U &&
6060+ nop == 0x08000240U)
6061+ {
6062+ regs->gr[25] = (ldi1 & 2) >> 1;
6063+ regs->gr[20] = __NR_rt_sigreturn;
6064+ regs->gr[31] = regs->iaoq[1] + 16;
6065+ regs->sr[0] = regs->iasq[1];
6066+ regs->iaoq[0] = 0x100UL;
6067+ regs->iaoq[1] = regs->iaoq[0] + 4;
6068+ regs->iasq[0] = regs->sr[2];
6069+ regs->iasq[1] = regs->sr[2];
6070+ return 2;
6071+ }
6072+ } while (0);
6073+#endif
6074+
6075+ return 1;
6076+}
6077+
6078+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6079+{
6080+ unsigned long i;
6081+
6082+ printk(KERN_ERR "PAX: bytes at PC: ");
6083+ for (i = 0; i < 5; i++) {
6084+ unsigned int c;
6085+ if (get_user(c, (unsigned int *)pc+i))
6086+ printk(KERN_CONT "???????? ");
6087+ else
6088+ printk(KERN_CONT "%08x ", c);
6089+ }
6090+ printk("\n");
6091+}
6092+#endif
6093+
6094 int fixup_exception(struct pt_regs *regs)
6095 {
6096 const struct exception_table_entry *fix;
6097@@ -194,8 +305,33 @@ good_area:
6098
6099 acc_type = parisc_acctyp(code,regs->iir);
6100
6101- if ((vma->vm_flags & acc_type) != acc_type)
6102+ if ((vma->vm_flags & acc_type) != acc_type) {
6103+
6104+#ifdef CONFIG_PAX_PAGEEXEC
6105+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6106+ (address & ~3UL) == instruction_pointer(regs))
6107+ {
6108+ up_read(&mm->mmap_sem);
6109+ switch (pax_handle_fetch_fault(regs)) {
6110+
6111+#ifdef CONFIG_PAX_EMUPLT
6112+ case 3:
6113+ return;
6114+#endif
6115+
6116+#ifdef CONFIG_PAX_EMUTRAMP
6117+ case 2:
6118+ return;
6119+#endif
6120+
6121+ }
6122+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6123+ do_group_exit(SIGKILL);
6124+ }
6125+#endif
6126+
6127 goto bad_area;
6128+ }
6129
6130 /*
6131 * If for any reason at all we couldn't handle the fault, make
6132diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6133index e3b1d41..8e81edf 100644
6134--- a/arch/powerpc/include/asm/atomic.h
6135+++ b/arch/powerpc/include/asm/atomic.h
6136@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6137 return t1;
6138 }
6139
6140+#define atomic64_read_unchecked(v) atomic64_read(v)
6141+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6142+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6143+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6144+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6145+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6146+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6147+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6148+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6149+
6150 #endif /* __powerpc64__ */
6151
6152 #endif /* __KERNEL__ */
6153diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6154index 9e495c9..b6878e5 100644
6155--- a/arch/powerpc/include/asm/cache.h
6156+++ b/arch/powerpc/include/asm/cache.h
6157@@ -3,6 +3,7 @@
6158
6159 #ifdef __KERNEL__
6160
6161+#include <linux/const.h>
6162
6163 /* bytes per L1 cache line */
6164 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6165@@ -22,7 +23,7 @@
6166 #define L1_CACHE_SHIFT 7
6167 #endif
6168
6169-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6170+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6171
6172 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6173
6174diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6175index ac9790f..6d30741 100644
6176--- a/arch/powerpc/include/asm/elf.h
6177+++ b/arch/powerpc/include/asm/elf.h
6178@@ -28,8 +28,19 @@
6179 the loader. We need to make sure that it is out of the way of the program
6180 that it will "exec", and that there is sufficient room for the brk. */
6181
6182-extern unsigned long randomize_et_dyn(unsigned long base);
6183-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6184+#define ELF_ET_DYN_BASE (0x20000000)
6185+
6186+#ifdef CONFIG_PAX_ASLR
6187+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6188+
6189+#ifdef __powerpc64__
6190+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6191+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6192+#else
6193+#define PAX_DELTA_MMAP_LEN 15
6194+#define PAX_DELTA_STACK_LEN 15
6195+#endif
6196+#endif
6197
6198 /*
6199 * Our registers are always unsigned longs, whether we're a 32 bit
6200@@ -122,10 +133,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6201 (0x7ff >> (PAGE_SHIFT - 12)) : \
6202 (0x3ffff >> (PAGE_SHIFT - 12)))
6203
6204-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6205-#define arch_randomize_brk arch_randomize_brk
6206-
6207-
6208 #ifdef CONFIG_SPU_BASE
6209 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6210 #define NT_SPU 1
6211diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6212index 8196e9c..d83a9f3 100644
6213--- a/arch/powerpc/include/asm/exec.h
6214+++ b/arch/powerpc/include/asm/exec.h
6215@@ -4,6 +4,6 @@
6216 #ifndef _ASM_POWERPC_EXEC_H
6217 #define _ASM_POWERPC_EXEC_H
6218
6219-extern unsigned long arch_align_stack(unsigned long sp);
6220+#define arch_align_stack(x) ((x) & ~0xfUL)
6221
6222 #endif /* _ASM_POWERPC_EXEC_H */
6223diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6224index 5acabbd..7ea14fa 100644
6225--- a/arch/powerpc/include/asm/kmap_types.h
6226+++ b/arch/powerpc/include/asm/kmap_types.h
6227@@ -10,7 +10,7 @@
6228 * 2 of the License, or (at your option) any later version.
6229 */
6230
6231-#define KM_TYPE_NR 16
6232+#define KM_TYPE_NR 17
6233
6234 #endif /* __KERNEL__ */
6235 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6236diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6237index 8565c25..2865190 100644
6238--- a/arch/powerpc/include/asm/mman.h
6239+++ b/arch/powerpc/include/asm/mman.h
6240@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6241 }
6242 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6243
6244-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6245+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6246 {
6247 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6248 }
6249diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6250index f072e97..b436dee 100644
6251--- a/arch/powerpc/include/asm/page.h
6252+++ b/arch/powerpc/include/asm/page.h
6253@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6254 * and needs to be executable. This means the whole heap ends
6255 * up being executable.
6256 */
6257-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6258- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6259+#define VM_DATA_DEFAULT_FLAGS32 \
6260+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6261+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6262
6263 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6264 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6265@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6266 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6267 #endif
6268
6269+#define ktla_ktva(addr) (addr)
6270+#define ktva_ktla(addr) (addr)
6271+
6272 /*
6273 * Use the top bit of the higher-level page table entries to indicate whether
6274 * the entries we point to contain hugepages. This works because we know that
6275diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6276index cd915d6..c10cee8 100644
6277--- a/arch/powerpc/include/asm/page_64.h
6278+++ b/arch/powerpc/include/asm/page_64.h
6279@@ -154,15 +154,18 @@ do { \
6280 * stack by default, so in the absence of a PT_GNU_STACK program header
6281 * we turn execute permission off.
6282 */
6283-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6284- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6285+#define VM_STACK_DEFAULT_FLAGS32 \
6286+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6287+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6288
6289 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6290 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6291
6292+#ifndef CONFIG_PAX_PAGEEXEC
6293 #define VM_STACK_DEFAULT_FLAGS \
6294 (is_32bit_task() ? \
6295 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6296+#endif
6297
6298 #include <asm-generic/getorder.h>
6299
6300diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6301index 292725c..f87ae14 100644
6302--- a/arch/powerpc/include/asm/pgalloc-64.h
6303+++ b/arch/powerpc/include/asm/pgalloc-64.h
6304@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6305 #ifndef CONFIG_PPC_64K_PAGES
6306
6307 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6308+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6309
6310 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6311 {
6312@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6313 pud_set(pud, (unsigned long)pmd);
6314 }
6315
6316+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6317+{
6318+ pud_populate(mm, pud, pmd);
6319+}
6320+
6321 #define pmd_populate(mm, pmd, pte_page) \
6322 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6323 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6324@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6325 #else /* CONFIG_PPC_64K_PAGES */
6326
6327 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6328+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6329
6330 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6331 pte_t *pte)
6332diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6333index a9cbd3b..3b67efa 100644
6334--- a/arch/powerpc/include/asm/pgtable.h
6335+++ b/arch/powerpc/include/asm/pgtable.h
6336@@ -2,6 +2,7 @@
6337 #define _ASM_POWERPC_PGTABLE_H
6338 #ifdef __KERNEL__
6339
6340+#include <linux/const.h>
6341 #ifndef __ASSEMBLY__
6342 #include <asm/processor.h> /* For TASK_SIZE */
6343 #include <asm/mmu.h>
6344diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6345index 4aad413..85d86bf 100644
6346--- a/arch/powerpc/include/asm/pte-hash32.h
6347+++ b/arch/powerpc/include/asm/pte-hash32.h
6348@@ -21,6 +21,7 @@
6349 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6350 #define _PAGE_USER 0x004 /* usermode access allowed */
6351 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6352+#define _PAGE_EXEC _PAGE_GUARDED
6353 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6354 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6355 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6356diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6357index 3b097a8..8f8c774 100644
6358--- a/arch/powerpc/include/asm/reg.h
6359+++ b/arch/powerpc/include/asm/reg.h
6360@@ -234,6 +234,7 @@
6361 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6362 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6363 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6364+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6365 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6366 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6367 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6368diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
6369index 195ce2a..ab5c614 100644
6370--- a/arch/powerpc/include/asm/smp.h
6371+++ b/arch/powerpc/include/asm/smp.h
6372@@ -50,7 +50,7 @@ struct smp_ops_t {
6373 int (*cpu_disable)(void);
6374 void (*cpu_die)(unsigned int nr);
6375 int (*cpu_bootable)(unsigned int nr);
6376-};
6377+} __no_const;
6378
6379 extern void smp_send_debugger_break(void);
6380 extern void start_secondary_resume(void);
6381diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6382index 406b7b9..af63426 100644
6383--- a/arch/powerpc/include/asm/thread_info.h
6384+++ b/arch/powerpc/include/asm/thread_info.h
6385@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6386 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6387 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6388 #define TIF_SINGLESTEP 8 /* singlestepping active */
6389-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6390 #define TIF_SECCOMP 10 /* secure computing */
6391 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6392 #define TIF_NOERROR 12 /* Force successful syscall return */
6393@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6394 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6395 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6396 for stack store? */
6397+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6398+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6399+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6400
6401 /* as above, but as bit values */
6402 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6403@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6404 #define _TIF_UPROBE (1<<TIF_UPROBE)
6405 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6406 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6407+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6408 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6409- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6410+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6411+ _TIF_GRSEC_SETXID)
6412
6413 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6414 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6415diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6416index 4db4959..aba5c41 100644
6417--- a/arch/powerpc/include/asm/uaccess.h
6418+++ b/arch/powerpc/include/asm/uaccess.h
6419@@ -318,52 +318,6 @@ do { \
6420 extern unsigned long __copy_tofrom_user(void __user *to,
6421 const void __user *from, unsigned long size);
6422
6423-#ifndef __powerpc64__
6424-
6425-static inline unsigned long copy_from_user(void *to,
6426- const void __user *from, unsigned long n)
6427-{
6428- unsigned long over;
6429-
6430- if (access_ok(VERIFY_READ, from, n))
6431- return __copy_tofrom_user((__force void __user *)to, from, n);
6432- if ((unsigned long)from < TASK_SIZE) {
6433- over = (unsigned long)from + n - TASK_SIZE;
6434- return __copy_tofrom_user((__force void __user *)to, from,
6435- n - over) + over;
6436- }
6437- return n;
6438-}
6439-
6440-static inline unsigned long copy_to_user(void __user *to,
6441- const void *from, unsigned long n)
6442-{
6443- unsigned long over;
6444-
6445- if (access_ok(VERIFY_WRITE, to, n))
6446- return __copy_tofrom_user(to, (__force void __user *)from, n);
6447- if ((unsigned long)to < TASK_SIZE) {
6448- over = (unsigned long)to + n - TASK_SIZE;
6449- return __copy_tofrom_user(to, (__force void __user *)from,
6450- n - over) + over;
6451- }
6452- return n;
6453-}
6454-
6455-#else /* __powerpc64__ */
6456-
6457-#define __copy_in_user(to, from, size) \
6458- __copy_tofrom_user((to), (from), (size))
6459-
6460-extern unsigned long copy_from_user(void *to, const void __user *from,
6461- unsigned long n);
6462-extern unsigned long copy_to_user(void __user *to, const void *from,
6463- unsigned long n);
6464-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6465- unsigned long n);
6466-
6467-#endif /* __powerpc64__ */
6468-
6469 static inline unsigned long __copy_from_user_inatomic(void *to,
6470 const void __user *from, unsigned long n)
6471 {
6472@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6473 if (ret == 0)
6474 return 0;
6475 }
6476+
6477+ if (!__builtin_constant_p(n))
6478+ check_object_size(to, n, false);
6479+
6480 return __copy_tofrom_user((__force void __user *)to, from, n);
6481 }
6482
6483@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6484 if (ret == 0)
6485 return 0;
6486 }
6487+
6488+ if (!__builtin_constant_p(n))
6489+ check_object_size(from, n, true);
6490+
6491 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6492 }
6493
6494@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6495 return __copy_to_user_inatomic(to, from, size);
6496 }
6497
6498+#ifndef __powerpc64__
6499+
6500+static inline unsigned long __must_check copy_from_user(void *to,
6501+ const void __user *from, unsigned long n)
6502+{
6503+ unsigned long over;
6504+
6505+ if ((long)n < 0)
6506+ return n;
6507+
6508+ if (access_ok(VERIFY_READ, from, n)) {
6509+ if (!__builtin_constant_p(n))
6510+ check_object_size(to, n, false);
6511+ return __copy_tofrom_user((__force void __user *)to, from, n);
6512+ }
6513+ if ((unsigned long)from < TASK_SIZE) {
6514+ over = (unsigned long)from + n - TASK_SIZE;
6515+ if (!__builtin_constant_p(n - over))
6516+ check_object_size(to, n - over, false);
6517+ return __copy_tofrom_user((__force void __user *)to, from,
6518+ n - over) + over;
6519+ }
6520+ return n;
6521+}
6522+
6523+static inline unsigned long __must_check copy_to_user(void __user *to,
6524+ const void *from, unsigned long n)
6525+{
6526+ unsigned long over;
6527+
6528+ if ((long)n < 0)
6529+ return n;
6530+
6531+ if (access_ok(VERIFY_WRITE, to, n)) {
6532+ if (!__builtin_constant_p(n))
6533+ check_object_size(from, n, true);
6534+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6535+ }
6536+ if ((unsigned long)to < TASK_SIZE) {
6537+ over = (unsigned long)to + n - TASK_SIZE;
6538+ if (!__builtin_constant_p(n))
6539+ check_object_size(from, n - over, true);
6540+ return __copy_tofrom_user(to, (__force void __user *)from,
6541+ n - over) + over;
6542+ }
6543+ return n;
6544+}
6545+
6546+#else /* __powerpc64__ */
6547+
6548+#define __copy_in_user(to, from, size) \
6549+ __copy_tofrom_user((to), (from), (size))
6550+
6551+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6552+{
6553+ if ((long)n < 0 || n > INT_MAX)
6554+ return n;
6555+
6556+ if (!__builtin_constant_p(n))
6557+ check_object_size(to, n, false);
6558+
6559+ if (likely(access_ok(VERIFY_READ, from, n)))
6560+ n = __copy_from_user(to, from, n);
6561+ else
6562+ memset(to, 0, n);
6563+ return n;
6564+}
6565+
6566+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6567+{
6568+ if ((long)n < 0 || n > INT_MAX)
6569+ return n;
6570+
6571+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6572+ if (!__builtin_constant_p(n))
6573+ check_object_size(from, n, true);
6574+ n = __copy_to_user(to, from, n);
6575+ }
6576+ return n;
6577+}
6578+
6579+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6580+ unsigned long n);
6581+
6582+#endif /* __powerpc64__ */
6583+
6584 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6585
6586 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6587diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6588index ae54553..cf2184d 100644
6589--- a/arch/powerpc/kernel/exceptions-64e.S
6590+++ b/arch/powerpc/kernel/exceptions-64e.S
6591@@ -716,6 +716,7 @@ storage_fault_common:
6592 std r14,_DAR(r1)
6593 std r15,_DSISR(r1)
6594 addi r3,r1,STACK_FRAME_OVERHEAD
6595+ bl .save_nvgprs
6596 mr r4,r14
6597 mr r5,r15
6598 ld r14,PACA_EXGEN+EX_R14(r13)
6599@@ -724,8 +725,7 @@ storage_fault_common:
6600 cmpdi r3,0
6601 bne- 1f
6602 b .ret_from_except_lite
6603-1: bl .save_nvgprs
6604- mr r5,r3
6605+1: mr r5,r3
6606 addi r3,r1,STACK_FRAME_OVERHEAD
6607 ld r4,_DAR(r1)
6608 bl .bad_page_fault
6609diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6610index 644378e..b6f2c26 100644
6611--- a/arch/powerpc/kernel/exceptions-64s.S
6612+++ b/arch/powerpc/kernel/exceptions-64s.S
6613@@ -1390,10 +1390,10 @@ handle_page_fault:
6614 11: ld r4,_DAR(r1)
6615 ld r5,_DSISR(r1)
6616 addi r3,r1,STACK_FRAME_OVERHEAD
6617+ bl .save_nvgprs
6618 bl .do_page_fault
6619 cmpdi r3,0
6620 beq+ 12f
6621- bl .save_nvgprs
6622 mr r5,r3
6623 addi r3,r1,STACK_FRAME_OVERHEAD
6624 lwz r4,_DAR(r1)
6625diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6626index 2e3200c..72095ce 100644
6627--- a/arch/powerpc/kernel/module_32.c
6628+++ b/arch/powerpc/kernel/module_32.c
6629@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6630 me->arch.core_plt_section = i;
6631 }
6632 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6633- printk("Module doesn't contain .plt or .init.plt sections.\n");
6634+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6635 return -ENOEXEC;
6636 }
6637
6638@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6639
6640 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6641 /* Init, or core PLT? */
6642- if (location >= mod->module_core
6643- && location < mod->module_core + mod->core_size)
6644+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6645+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6646 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6647- else
6648+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6649+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6650 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6651+ else {
6652+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6653+ return ~0UL;
6654+ }
6655
6656 /* Find this entry, or if that fails, the next avail. entry */
6657 while (entry->jump[0]) {
6658diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6659index 0d86c8a..df4c5f2 100644
6660--- a/arch/powerpc/kernel/process.c
6661+++ b/arch/powerpc/kernel/process.c
6662@@ -871,8 +871,8 @@ void show_regs(struct pt_regs * regs)
6663 * Lookup NIP late so we have the best change of getting the
6664 * above info out without failing
6665 */
6666- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6667- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6668+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6669+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6670 #endif
6671 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
6672 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
6673@@ -1331,10 +1331,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6674 newsp = stack[0];
6675 ip = stack[STACK_FRAME_LR_SAVE];
6676 if (!firstframe || ip != lr) {
6677- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6678+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6679 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6680 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6681- printk(" (%pS)",
6682+ printk(" (%pA)",
6683 (void *)current->ret_stack[curr_frame].ret);
6684 curr_frame--;
6685 }
6686@@ -1354,7 +1354,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6687 struct pt_regs *regs = (struct pt_regs *)
6688 (sp + STACK_FRAME_OVERHEAD);
6689 lr = regs->link;
6690- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6691+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6692 regs->trap, (void *)regs->nip, (void *)lr);
6693 firstframe = 1;
6694 }
6695@@ -1396,58 +1396,3 @@ void notrace __ppc64_runlatch_off(void)
6696 mtspr(SPRN_CTRLT, ctrl);
6697 }
6698 #endif /* CONFIG_PPC64 */
6699-
6700-unsigned long arch_align_stack(unsigned long sp)
6701-{
6702- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6703- sp -= get_random_int() & ~PAGE_MASK;
6704- return sp & ~0xf;
6705-}
6706-
6707-static inline unsigned long brk_rnd(void)
6708-{
6709- unsigned long rnd = 0;
6710-
6711- /* 8MB for 32bit, 1GB for 64bit */
6712- if (is_32bit_task())
6713- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6714- else
6715- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6716-
6717- return rnd << PAGE_SHIFT;
6718-}
6719-
6720-unsigned long arch_randomize_brk(struct mm_struct *mm)
6721-{
6722- unsigned long base = mm->brk;
6723- unsigned long ret;
6724-
6725-#ifdef CONFIG_PPC_STD_MMU_64
6726- /*
6727- * If we are using 1TB segments and we are allowed to randomise
6728- * the heap, we can put it above 1TB so it is backed by a 1TB
6729- * segment. Otherwise the heap will be in the bottom 1TB
6730- * which always uses 256MB segments and this may result in a
6731- * performance penalty.
6732- */
6733- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6734- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6735-#endif
6736-
6737- ret = PAGE_ALIGN(base + brk_rnd());
6738-
6739- if (ret < mm->brk)
6740- return mm->brk;
6741-
6742- return ret;
6743-}
6744-
6745-unsigned long randomize_et_dyn(unsigned long base)
6746-{
6747- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6748-
6749- if (ret < base)
6750- return base;
6751-
6752- return ret;
6753-}
6754diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6755index f9b30c6..d72e7a3 100644
6756--- a/arch/powerpc/kernel/ptrace.c
6757+++ b/arch/powerpc/kernel/ptrace.c
6758@@ -1771,6 +1771,10 @@ long arch_ptrace(struct task_struct *child, long request,
6759 return ret;
6760 }
6761
6762+#ifdef CONFIG_GRKERNSEC_SETXID
6763+extern void gr_delayed_cred_worker(void);
6764+#endif
6765+
6766 /*
6767 * We must return the syscall number to actually look up in the table.
6768 * This can be -1L to skip running any syscall at all.
6769@@ -1781,6 +1785,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6770
6771 secure_computing_strict(regs->gpr[0]);
6772
6773+#ifdef CONFIG_GRKERNSEC_SETXID
6774+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6775+ gr_delayed_cred_worker();
6776+#endif
6777+
6778 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6779 tracehook_report_syscall_entry(regs))
6780 /*
6781@@ -1815,6 +1824,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6782 {
6783 int step;
6784
6785+#ifdef CONFIG_GRKERNSEC_SETXID
6786+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6787+ gr_delayed_cred_worker();
6788+#endif
6789+
6790 audit_syscall_exit(regs);
6791
6792 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6793diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6794index 201385c..0f01828 100644
6795--- a/arch/powerpc/kernel/signal_32.c
6796+++ b/arch/powerpc/kernel/signal_32.c
6797@@ -976,7 +976,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6798 /* Save user registers on the stack */
6799 frame = &rt_sf->uc.uc_mcontext;
6800 addr = frame;
6801- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6802+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6803 sigret = 0;
6804 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6805 } else {
6806diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6807index 3459473..2d40783 100644
6808--- a/arch/powerpc/kernel/signal_64.c
6809+++ b/arch/powerpc/kernel/signal_64.c
6810@@ -749,7 +749,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6811 #endif
6812
6813 /* Set up to return from userspace. */
6814- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6815+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6816 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6817 } else {
6818 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6819diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6820index 3ce1f86..c30e629 100644
6821--- a/arch/powerpc/kernel/sysfs.c
6822+++ b/arch/powerpc/kernel/sysfs.c
6823@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6824 return NOTIFY_OK;
6825 }
6826
6827-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6828+static struct notifier_block sysfs_cpu_nb = {
6829 .notifier_call = sysfs_cpu_notify,
6830 };
6831
6832diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6833index bf33ace..e836d8b 100644
6834--- a/arch/powerpc/kernel/traps.c
6835+++ b/arch/powerpc/kernel/traps.c
6836@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6837 return flags;
6838 }
6839
6840+extern void gr_handle_kernel_exploit(void);
6841+
6842 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6843 int signr)
6844 {
6845@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6846 panic("Fatal exception in interrupt");
6847 if (panic_on_oops)
6848 panic("Fatal exception");
6849+
6850+ gr_handle_kernel_exploit();
6851+
6852 do_exit(signr);
6853 }
6854
6855diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6856index 1b2076f..835e4be 100644
6857--- a/arch/powerpc/kernel/vdso.c
6858+++ b/arch/powerpc/kernel/vdso.c
6859@@ -34,6 +34,7 @@
6860 #include <asm/firmware.h>
6861 #include <asm/vdso.h>
6862 #include <asm/vdso_datapage.h>
6863+#include <asm/mman.h>
6864
6865 #include "setup.h"
6866
6867@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6868 vdso_base = VDSO32_MBASE;
6869 #endif
6870
6871- current->mm->context.vdso_base = 0;
6872+ current->mm->context.vdso_base = ~0UL;
6873
6874 /* vDSO has a problem and was disabled, just don't "enable" it for the
6875 * process
6876@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6877 vdso_base = get_unmapped_area(NULL, vdso_base,
6878 (vdso_pages << PAGE_SHIFT) +
6879 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6880- 0, 0);
6881+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6882 if (IS_ERR_VALUE(vdso_base)) {
6883 rc = vdso_base;
6884 goto fail_mmapsem;
6885diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6886index 5eea6f3..5d10396 100644
6887--- a/arch/powerpc/lib/usercopy_64.c
6888+++ b/arch/powerpc/lib/usercopy_64.c
6889@@ -9,22 +9,6 @@
6890 #include <linux/module.h>
6891 #include <asm/uaccess.h>
6892
6893-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6894-{
6895- if (likely(access_ok(VERIFY_READ, from, n)))
6896- n = __copy_from_user(to, from, n);
6897- else
6898- memset(to, 0, n);
6899- return n;
6900-}
6901-
6902-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6903-{
6904- if (likely(access_ok(VERIFY_WRITE, to, n)))
6905- n = __copy_to_user(to, from, n);
6906- return n;
6907-}
6908-
6909 unsigned long copy_in_user(void __user *to, const void __user *from,
6910 unsigned long n)
6911 {
6912@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6913 return n;
6914 }
6915
6916-EXPORT_SYMBOL(copy_from_user);
6917-EXPORT_SYMBOL(copy_to_user);
6918 EXPORT_SYMBOL(copy_in_user);
6919
6920diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6921index 229951f..cdeca42 100644
6922--- a/arch/powerpc/mm/fault.c
6923+++ b/arch/powerpc/mm/fault.c
6924@@ -32,6 +32,10 @@
6925 #include <linux/perf_event.h>
6926 #include <linux/magic.h>
6927 #include <linux/ratelimit.h>
6928+#include <linux/slab.h>
6929+#include <linux/pagemap.h>
6930+#include <linux/compiler.h>
6931+#include <linux/unistd.h>
6932
6933 #include <asm/firmware.h>
6934 #include <asm/page.h>
6935@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6936 }
6937 #endif
6938
6939+#ifdef CONFIG_PAX_PAGEEXEC
6940+/*
6941+ * PaX: decide what to do with offenders (regs->nip = fault address)
6942+ *
6943+ * returns 1 when task should be killed
6944+ */
6945+static int pax_handle_fetch_fault(struct pt_regs *regs)
6946+{
6947+ return 1;
6948+}
6949+
6950+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6951+{
6952+ unsigned long i;
6953+
6954+ printk(KERN_ERR "PAX: bytes at PC: ");
6955+ for (i = 0; i < 5; i++) {
6956+ unsigned int c;
6957+ if (get_user(c, (unsigned int __user *)pc+i))
6958+ printk(KERN_CONT "???????? ");
6959+ else
6960+ printk(KERN_CONT "%08x ", c);
6961+ }
6962+ printk("\n");
6963+}
6964+#endif
6965+
6966 /*
6967 * Check whether the instruction at regs->nip is a store using
6968 * an update addressing form which will update r1.
6969@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
6970 * indicate errors in DSISR but can validly be set in SRR1.
6971 */
6972 if (trap == 0x400)
6973- error_code &= 0x48200000;
6974+ error_code &= 0x58200000;
6975 else
6976 is_write = error_code & DSISR_ISSTORE;
6977 #else
6978@@ -364,7 +395,7 @@ good_area:
6979 * "undefined". Of those that can be set, this is the only
6980 * one which seems bad.
6981 */
6982- if (error_code & 0x10000000)
6983+ if (error_code & DSISR_GUARDED)
6984 /* Guarded storage error. */
6985 goto bad_area;
6986 #endif /* CONFIG_8xx */
6987@@ -379,7 +410,7 @@ good_area:
6988 * processors use the same I/D cache coherency mechanism
6989 * as embedded.
6990 */
6991- if (error_code & DSISR_PROTFAULT)
6992+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
6993 goto bad_area;
6994 #endif /* CONFIG_PPC_STD_MMU */
6995
6996@@ -462,6 +493,23 @@ bad_area:
6997 bad_area_nosemaphore:
6998 /* User mode accesses cause a SIGSEGV */
6999 if (user_mode(regs)) {
7000+
7001+#ifdef CONFIG_PAX_PAGEEXEC
7002+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7003+#ifdef CONFIG_PPC_STD_MMU
7004+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7005+#else
7006+ if (is_exec && regs->nip == address) {
7007+#endif
7008+ switch (pax_handle_fetch_fault(regs)) {
7009+ }
7010+
7011+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7012+ do_group_exit(SIGKILL);
7013+ }
7014+ }
7015+#endif
7016+
7017 _exception(SIGSEGV, regs, code, address);
7018 return 0;
7019 }
7020diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7021index 67a42ed..cd463e0 100644
7022--- a/arch/powerpc/mm/mmap_64.c
7023+++ b/arch/powerpc/mm/mmap_64.c
7024@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7025 {
7026 unsigned long rnd = 0;
7027
7028+#ifdef CONFIG_PAX_RANDMMAP
7029+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7030+#endif
7031+
7032 if (current->flags & PF_RANDOMIZE) {
7033 /* 8MB for 32bit, 1GB for 64bit */
7034 if (is_32bit_task())
7035@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7036 */
7037 if (mmap_is_legacy()) {
7038 mm->mmap_base = TASK_UNMAPPED_BASE;
7039+
7040+#ifdef CONFIG_PAX_RANDMMAP
7041+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7042+ mm->mmap_base += mm->delta_mmap;
7043+#endif
7044+
7045 mm->get_unmapped_area = arch_get_unmapped_area;
7046 mm->unmap_area = arch_unmap_area;
7047 } else {
7048 mm->mmap_base = mmap_base();
7049+
7050+#ifdef CONFIG_PAX_RANDMMAP
7051+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7052+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7053+#endif
7054+
7055 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7056 mm->unmap_area = arch_unmap_area_topdown;
7057 }
7058diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7059index e779642..e5bb889 100644
7060--- a/arch/powerpc/mm/mmu_context_nohash.c
7061+++ b/arch/powerpc/mm/mmu_context_nohash.c
7062@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7063 return NOTIFY_OK;
7064 }
7065
7066-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7067+static struct notifier_block mmu_context_cpu_nb = {
7068 .notifier_call = mmu_context_cpu_notify,
7069 };
7070
7071diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7072index 6a252c4..3024d81 100644
7073--- a/arch/powerpc/mm/numa.c
7074+++ b/arch/powerpc/mm/numa.c
7075@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7076 return ret;
7077 }
7078
7079-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7080+static struct notifier_block ppc64_numa_nb = {
7081 .notifier_call = cpu_numa_callback,
7082 .priority = 1 /* Must run before sched domains notifier. */
7083 };
7084diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7085index cf9dada..241529f 100644
7086--- a/arch/powerpc/mm/slice.c
7087+++ b/arch/powerpc/mm/slice.c
7088@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7089 if ((mm->task_size - len) < addr)
7090 return 0;
7091 vma = find_vma(mm, addr);
7092- return (!vma || (addr + len) <= vma->vm_start);
7093+ return check_heap_stack_gap(vma, addr, len, 0);
7094 }
7095
7096 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7097@@ -272,7 +272,7 @@ full_search:
7098 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
7099 continue;
7100 }
7101- if (!vma || addr + len <= vma->vm_start) {
7102+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7103 /*
7104 * Remember the place where we stopped the search:
7105 */
7106@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7107 }
7108 }
7109
7110- addr = mm->mmap_base;
7111- while (addr > len) {
7112+ if (mm->mmap_base < len)
7113+ addr = -ENOMEM;
7114+ else
7115+ addr = mm->mmap_base - len;
7116+
7117+ while (!IS_ERR_VALUE(addr)) {
7118 /* Go down by chunk size */
7119- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
7120+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
7121
7122 /* Check for hit with different page size */
7123 mask = slice_range_to_mask(addr, len);
7124@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7125 * return with success:
7126 */
7127 vma = find_vma(mm, addr);
7128- if (!vma || (addr + len) <= vma->vm_start) {
7129+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7130 /* remember the address as a hint for next time */
7131 if (use_cache)
7132 mm->free_area_cache = addr;
7133@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7134 mm->cached_hole_size = vma->vm_start - addr;
7135
7136 /* try just below the current vma->vm_start */
7137- addr = vma->vm_start;
7138+ addr = skip_heap_stack_gap(vma, len, 0);
7139 }
7140
7141 /*
7142@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7143 if (fixed && addr > (mm->task_size - len))
7144 return -EINVAL;
7145
7146+#ifdef CONFIG_PAX_RANDMMAP
7147+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7148+ addr = 0;
7149+#endif
7150+
7151 /* If hint, make sure it matches our alignment restrictions */
7152 if (!fixed && addr) {
7153 addr = _ALIGN_UP(addr, 1ul << pshift);
7154diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
7155index 68c57d3..1fdcfb2 100644
7156--- a/arch/powerpc/platforms/cell/spufs/file.c
7157+++ b/arch/powerpc/platforms/cell/spufs/file.c
7158@@ -281,9 +281,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7159 return VM_FAULT_NOPAGE;
7160 }
7161
7162-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
7163+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
7164 unsigned long address,
7165- void *buf, int len, int write)
7166+ void *buf, size_t len, int write)
7167 {
7168 struct spu_context *ctx = vma->vm_file->private_data;
7169 unsigned long offset = address - vma->vm_start;
7170diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7171index bdb738a..49c9f95 100644
7172--- a/arch/powerpc/platforms/powermac/smp.c
7173+++ b/arch/powerpc/platforms/powermac/smp.c
7174@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7175 return NOTIFY_OK;
7176 }
7177
7178-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7179+static struct notifier_block smp_core99_cpu_nb = {
7180 .notifier_call = smp_core99_cpu_notify,
7181 };
7182 #endif /* CONFIG_HOTPLUG_CPU */
7183diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7184index c797832..ce575c8 100644
7185--- a/arch/s390/include/asm/atomic.h
7186+++ b/arch/s390/include/asm/atomic.h
7187@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7188 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7189 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7190
7191+#define atomic64_read_unchecked(v) atomic64_read(v)
7192+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7193+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7194+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7195+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7196+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7197+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7198+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7199+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7200+
7201 #define smp_mb__before_atomic_dec() smp_mb()
7202 #define smp_mb__after_atomic_dec() smp_mb()
7203 #define smp_mb__before_atomic_inc() smp_mb()
7204diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7205index 4d7ccac..d03d0ad 100644
7206--- a/arch/s390/include/asm/cache.h
7207+++ b/arch/s390/include/asm/cache.h
7208@@ -9,8 +9,10 @@
7209 #ifndef __ARCH_S390_CACHE_H
7210 #define __ARCH_S390_CACHE_H
7211
7212-#define L1_CACHE_BYTES 256
7213+#include <linux/const.h>
7214+
7215 #define L1_CACHE_SHIFT 8
7216+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7217 #define NET_SKB_PAD 32
7218
7219 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7220diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7221index 1bfdf24..9c9ab2e 100644
7222--- a/arch/s390/include/asm/elf.h
7223+++ b/arch/s390/include/asm/elf.h
7224@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
7225 the loader. We need to make sure that it is out of the way of the program
7226 that it will "exec", and that there is sufficient room for the brk. */
7227
7228-extern unsigned long randomize_et_dyn(unsigned long base);
7229-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7230+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7231+
7232+#ifdef CONFIG_PAX_ASLR
7233+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7234+
7235+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7236+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7237+#endif
7238
7239 /* This yields a mask that user programs can use to figure out what
7240 instruction set this CPU supports. */
7241@@ -207,9 +213,6 @@ struct linux_binprm;
7242 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7243 int arch_setup_additional_pages(struct linux_binprm *, int);
7244
7245-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7246-#define arch_randomize_brk arch_randomize_brk
7247-
7248 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7249
7250 #endif
7251diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7252index c4a93d6..4d2a9b4 100644
7253--- a/arch/s390/include/asm/exec.h
7254+++ b/arch/s390/include/asm/exec.h
7255@@ -7,6 +7,6 @@
7256 #ifndef __ASM_EXEC_H
7257 #define __ASM_EXEC_H
7258
7259-extern unsigned long arch_align_stack(unsigned long sp);
7260+#define arch_align_stack(x) ((x) & ~0xfUL)
7261
7262 #endif /* __ASM_EXEC_H */
7263diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7264index 9c33ed4..e40cbef 100644
7265--- a/arch/s390/include/asm/uaccess.h
7266+++ b/arch/s390/include/asm/uaccess.h
7267@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7268 copy_to_user(void __user *to, const void *from, unsigned long n)
7269 {
7270 might_fault();
7271+
7272+ if ((long)n < 0)
7273+ return n;
7274+
7275 return __copy_to_user(to, from, n);
7276 }
7277
7278@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7279 static inline unsigned long __must_check
7280 __copy_from_user(void *to, const void __user *from, unsigned long n)
7281 {
7282+ if ((long)n < 0)
7283+ return n;
7284+
7285 if (__builtin_constant_p(n) && (n <= 256))
7286 return uaccess.copy_from_user_small(n, from, to);
7287 else
7288@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7289 static inline unsigned long __must_check
7290 copy_from_user(void *to, const void __user *from, unsigned long n)
7291 {
7292- unsigned int sz = __compiletime_object_size(to);
7293+ size_t sz = __compiletime_object_size(to);
7294
7295 might_fault();
7296- if (unlikely(sz != -1 && sz < n)) {
7297+
7298+ if ((long)n < 0)
7299+ return n;
7300+
7301+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7302 copy_from_user_overflow();
7303 return n;
7304 }
7305diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7306index 7845e15..59c4353 100644
7307--- a/arch/s390/kernel/module.c
7308+++ b/arch/s390/kernel/module.c
7309@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7310
7311 /* Increase core size by size of got & plt and set start
7312 offsets for got and plt. */
7313- me->core_size = ALIGN(me->core_size, 4);
7314- me->arch.got_offset = me->core_size;
7315- me->core_size += me->arch.got_size;
7316- me->arch.plt_offset = me->core_size;
7317- me->core_size += me->arch.plt_size;
7318+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7319+ me->arch.got_offset = me->core_size_rw;
7320+ me->core_size_rw += me->arch.got_size;
7321+ me->arch.plt_offset = me->core_size_rx;
7322+ me->core_size_rx += me->arch.plt_size;
7323 return 0;
7324 }
7325
7326@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7327 if (info->got_initialized == 0) {
7328 Elf_Addr *gotent;
7329
7330- gotent = me->module_core + me->arch.got_offset +
7331+ gotent = me->module_core_rw + me->arch.got_offset +
7332 info->got_offset;
7333 *gotent = val;
7334 info->got_initialized = 1;
7335@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7336 rc = apply_rela_bits(loc, val, 0, 64, 0);
7337 else if (r_type == R_390_GOTENT ||
7338 r_type == R_390_GOTPLTENT) {
7339- val += (Elf_Addr) me->module_core - loc;
7340+ val += (Elf_Addr) me->module_core_rw - loc;
7341 rc = apply_rela_bits(loc, val, 1, 32, 1);
7342 }
7343 break;
7344@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7345 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7346 if (info->plt_initialized == 0) {
7347 unsigned int *ip;
7348- ip = me->module_core + me->arch.plt_offset +
7349+ ip = me->module_core_rx + me->arch.plt_offset +
7350 info->plt_offset;
7351 #ifndef CONFIG_64BIT
7352 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7353@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7354 val - loc + 0xffffUL < 0x1ffffeUL) ||
7355 (r_type == R_390_PLT32DBL &&
7356 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7357- val = (Elf_Addr) me->module_core +
7358+ val = (Elf_Addr) me->module_core_rx +
7359 me->arch.plt_offset +
7360 info->plt_offset;
7361 val += rela->r_addend - loc;
7362@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7363 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7364 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7365 val = val + rela->r_addend -
7366- ((Elf_Addr) me->module_core + me->arch.got_offset);
7367+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7368 if (r_type == R_390_GOTOFF16)
7369 rc = apply_rela_bits(loc, val, 0, 16, 0);
7370 else if (r_type == R_390_GOTOFF32)
7371@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7372 break;
7373 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7374 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7375- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7376+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7377 rela->r_addend - loc;
7378 if (r_type == R_390_GOTPC)
7379 rc = apply_rela_bits(loc, val, 1, 32, 0);
7380diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7381index 536d645..4a5bd9e 100644
7382--- a/arch/s390/kernel/process.c
7383+++ b/arch/s390/kernel/process.c
7384@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7385 }
7386 return 0;
7387 }
7388-
7389-unsigned long arch_align_stack(unsigned long sp)
7390-{
7391- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7392- sp -= get_random_int() & ~PAGE_MASK;
7393- return sp & ~0xf;
7394-}
7395-
7396-static inline unsigned long brk_rnd(void)
7397-{
7398- /* 8MB for 32bit, 1GB for 64bit */
7399- if (is_32bit_task())
7400- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7401- else
7402- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7403-}
7404-
7405-unsigned long arch_randomize_brk(struct mm_struct *mm)
7406-{
7407- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7408-
7409- if (ret < mm->brk)
7410- return mm->brk;
7411- return ret;
7412-}
7413-
7414-unsigned long randomize_et_dyn(unsigned long base)
7415-{
7416- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7417-
7418- if (!(current->flags & PF_RANDOMIZE))
7419- return base;
7420- if (ret < base)
7421- return base;
7422- return ret;
7423-}
7424diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7425index 06bafec..2bca531 100644
7426--- a/arch/s390/mm/mmap.c
7427+++ b/arch/s390/mm/mmap.c
7428@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7429 */
7430 if (mmap_is_legacy()) {
7431 mm->mmap_base = TASK_UNMAPPED_BASE;
7432+
7433+#ifdef CONFIG_PAX_RANDMMAP
7434+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7435+ mm->mmap_base += mm->delta_mmap;
7436+#endif
7437+
7438 mm->get_unmapped_area = arch_get_unmapped_area;
7439 mm->unmap_area = arch_unmap_area;
7440 } else {
7441 mm->mmap_base = mmap_base();
7442+
7443+#ifdef CONFIG_PAX_RANDMMAP
7444+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7445+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7446+#endif
7447+
7448 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7449 mm->unmap_area = arch_unmap_area_topdown;
7450 }
7451@@ -175,10 +187,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7452 */
7453 if (mmap_is_legacy()) {
7454 mm->mmap_base = TASK_UNMAPPED_BASE;
7455+
7456+#ifdef CONFIG_PAX_RANDMMAP
7457+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7458+ mm->mmap_base += mm->delta_mmap;
7459+#endif
7460+
7461 mm->get_unmapped_area = s390_get_unmapped_area;
7462 mm->unmap_area = arch_unmap_area;
7463 } else {
7464 mm->mmap_base = mmap_base();
7465+
7466+#ifdef CONFIG_PAX_RANDMMAP
7467+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7468+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7469+#endif
7470+
7471 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7472 mm->unmap_area = arch_unmap_area_topdown;
7473 }
7474diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7475index ae3d59f..f65f075 100644
7476--- a/arch/score/include/asm/cache.h
7477+++ b/arch/score/include/asm/cache.h
7478@@ -1,7 +1,9 @@
7479 #ifndef _ASM_SCORE_CACHE_H
7480 #define _ASM_SCORE_CACHE_H
7481
7482+#include <linux/const.h>
7483+
7484 #define L1_CACHE_SHIFT 4
7485-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7486+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7487
7488 #endif /* _ASM_SCORE_CACHE_H */
7489diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7490index f9f3cd5..58ff438 100644
7491--- a/arch/score/include/asm/exec.h
7492+++ b/arch/score/include/asm/exec.h
7493@@ -1,6 +1,6 @@
7494 #ifndef _ASM_SCORE_EXEC_H
7495 #define _ASM_SCORE_EXEC_H
7496
7497-extern unsigned long arch_align_stack(unsigned long sp);
7498+#define arch_align_stack(x) (x)
7499
7500 #endif /* _ASM_SCORE_EXEC_H */
7501diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7502index 7956846..5f37677 100644
7503--- a/arch/score/kernel/process.c
7504+++ b/arch/score/kernel/process.c
7505@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7506
7507 return task_pt_regs(task)->cp0_epc;
7508 }
7509-
7510-unsigned long arch_align_stack(unsigned long sp)
7511-{
7512- return sp;
7513-}
7514diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7515index ef9e555..331bd29 100644
7516--- a/arch/sh/include/asm/cache.h
7517+++ b/arch/sh/include/asm/cache.h
7518@@ -9,10 +9,11 @@
7519 #define __ASM_SH_CACHE_H
7520 #ifdef __KERNEL__
7521
7522+#include <linux/const.h>
7523 #include <linux/init.h>
7524 #include <cpu/cache.h>
7525
7526-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7527+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7528
7529 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7530
7531diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7532index 03f2b55..b0270327 100644
7533--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7534+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7535@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7536 return NOTIFY_OK;
7537 }
7538
7539-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7540+static struct notifier_block shx3_cpu_notifier = {
7541 .notifier_call = shx3_cpu_callback,
7542 };
7543
7544diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7545index 6777177..cb5e44f 100644
7546--- a/arch/sh/mm/mmap.c
7547+++ b/arch/sh/mm/mmap.c
7548@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7549 struct mm_struct *mm = current->mm;
7550 struct vm_area_struct *vma;
7551 int do_colour_align;
7552+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7553 struct vm_unmapped_area_info info;
7554
7555 if (flags & MAP_FIXED) {
7556@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7557 if (filp || (flags & MAP_SHARED))
7558 do_colour_align = 1;
7559
7560+#ifdef CONFIG_PAX_RANDMMAP
7561+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7562+#endif
7563+
7564 if (addr) {
7565 if (do_colour_align)
7566 addr = COLOUR_ALIGN(addr, pgoff);
7567@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7568 addr = PAGE_ALIGN(addr);
7569
7570 vma = find_vma(mm, addr);
7571- if (TASK_SIZE - len >= addr &&
7572- (!vma || addr + len <= vma->vm_start))
7573+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7574 return addr;
7575 }
7576
7577 info.flags = 0;
7578 info.length = len;
7579- info.low_limit = TASK_UNMAPPED_BASE;
7580+ info.low_limit = mm->mmap_base;
7581 info.high_limit = TASK_SIZE;
7582 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7583 info.align_offset = pgoff << PAGE_SHIFT;
7584@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7585 struct mm_struct *mm = current->mm;
7586 unsigned long addr = addr0;
7587 int do_colour_align;
7588+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7589 struct vm_unmapped_area_info info;
7590
7591 if (flags & MAP_FIXED) {
7592@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7593 if (filp || (flags & MAP_SHARED))
7594 do_colour_align = 1;
7595
7596+#ifdef CONFIG_PAX_RANDMMAP
7597+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7598+#endif
7599+
7600 /* requesting a specific address */
7601 if (addr) {
7602 if (do_colour_align)
7603@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7604 addr = PAGE_ALIGN(addr);
7605
7606 vma = find_vma(mm, addr);
7607- if (TASK_SIZE - len >= addr &&
7608- (!vma || addr + len <= vma->vm_start))
7609+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7610 return addr;
7611 }
7612
7613@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7614 VM_BUG_ON(addr != -ENOMEM);
7615 info.flags = 0;
7616 info.low_limit = TASK_UNMAPPED_BASE;
7617+
7618+#ifdef CONFIG_PAX_RANDMMAP
7619+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7620+ info.low_limit += mm->delta_mmap;
7621+#endif
7622+
7623 info.high_limit = TASK_SIZE;
7624 addr = vm_unmapped_area(&info);
7625 }
7626diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7627index be56a24..443328f 100644
7628--- a/arch/sparc/include/asm/atomic_64.h
7629+++ b/arch/sparc/include/asm/atomic_64.h
7630@@ -14,18 +14,40 @@
7631 #define ATOMIC64_INIT(i) { (i) }
7632
7633 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7634+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7635+{
7636+ return v->counter;
7637+}
7638 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7639+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7640+{
7641+ return v->counter;
7642+}
7643
7644 #define atomic_set(v, i) (((v)->counter) = i)
7645+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7646+{
7647+ v->counter = i;
7648+}
7649 #define atomic64_set(v, i) (((v)->counter) = i)
7650+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7651+{
7652+ v->counter = i;
7653+}
7654
7655 extern void atomic_add(int, atomic_t *);
7656+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7657 extern void atomic64_add(long, atomic64_t *);
7658+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7659 extern void atomic_sub(int, atomic_t *);
7660+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7661 extern void atomic64_sub(long, atomic64_t *);
7662+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7663
7664 extern int atomic_add_ret(int, atomic_t *);
7665+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7666 extern long atomic64_add_ret(long, atomic64_t *);
7667+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7668 extern int atomic_sub_ret(int, atomic_t *);
7669 extern long atomic64_sub_ret(long, atomic64_t *);
7670
7671@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7672 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7673
7674 #define atomic_inc_return(v) atomic_add_ret(1, v)
7675+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7676+{
7677+ return atomic_add_ret_unchecked(1, v);
7678+}
7679 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7680+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7681+{
7682+ return atomic64_add_ret_unchecked(1, v);
7683+}
7684
7685 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7686 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7687
7688 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7689+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7690+{
7691+ return atomic_add_ret_unchecked(i, v);
7692+}
7693 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7694+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7695+{
7696+ return atomic64_add_ret_unchecked(i, v);
7697+}
7698
7699 /*
7700 * atomic_inc_and_test - increment and test
7701@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7702 * other cases.
7703 */
7704 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7705+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7706+{
7707+ return atomic_inc_return_unchecked(v) == 0;
7708+}
7709 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7710
7711 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7712@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7713 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7714
7715 #define atomic_inc(v) atomic_add(1, v)
7716+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7717+{
7718+ atomic_add_unchecked(1, v);
7719+}
7720 #define atomic64_inc(v) atomic64_add(1, v)
7721+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7722+{
7723+ atomic64_add_unchecked(1, v);
7724+}
7725
7726 #define atomic_dec(v) atomic_sub(1, v)
7727+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7728+{
7729+ atomic_sub_unchecked(1, v);
7730+}
7731 #define atomic64_dec(v) atomic64_sub(1, v)
7732+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7733+{
7734+ atomic64_sub_unchecked(1, v);
7735+}
7736
7737 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7738 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7739
7740 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7741+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7742+{
7743+ return cmpxchg(&v->counter, old, new);
7744+}
7745 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7746+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7747+{
7748+ return xchg(&v->counter, new);
7749+}
7750
7751 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7752 {
7753- int c, old;
7754+ int c, old, new;
7755 c = atomic_read(v);
7756 for (;;) {
7757- if (unlikely(c == (u)))
7758+ if (unlikely(c == u))
7759 break;
7760- old = atomic_cmpxchg((v), c, c + (a));
7761+
7762+ asm volatile("addcc %2, %0, %0\n"
7763+
7764+#ifdef CONFIG_PAX_REFCOUNT
7765+ "tvs %%icc, 6\n"
7766+#endif
7767+
7768+ : "=r" (new)
7769+ : "0" (c), "ir" (a)
7770+ : "cc");
7771+
7772+ old = atomic_cmpxchg(v, c, new);
7773 if (likely(old == c))
7774 break;
7775 c = old;
7776@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7777 #define atomic64_cmpxchg(v, o, n) \
7778 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7779 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7780+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7781+{
7782+ return xchg(&v->counter, new);
7783+}
7784
7785 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7786 {
7787- long c, old;
7788+ long c, old, new;
7789 c = atomic64_read(v);
7790 for (;;) {
7791- if (unlikely(c == (u)))
7792+ if (unlikely(c == u))
7793 break;
7794- old = atomic64_cmpxchg((v), c, c + (a));
7795+
7796+ asm volatile("addcc %2, %0, %0\n"
7797+
7798+#ifdef CONFIG_PAX_REFCOUNT
7799+ "tvs %%xcc, 6\n"
7800+#endif
7801+
7802+ : "=r" (new)
7803+ : "0" (c), "ir" (a)
7804+ : "cc");
7805+
7806+ old = atomic64_cmpxchg(v, c, new);
7807 if (likely(old == c))
7808 break;
7809 c = old;
7810 }
7811- return c != (u);
7812+ return c != u;
7813 }
7814
7815 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7816diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7817index 5bb6991..5c2132e 100644
7818--- a/arch/sparc/include/asm/cache.h
7819+++ b/arch/sparc/include/asm/cache.h
7820@@ -7,10 +7,12 @@
7821 #ifndef _SPARC_CACHE_H
7822 #define _SPARC_CACHE_H
7823
7824+#include <linux/const.h>
7825+
7826 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7827
7828 #define L1_CACHE_SHIFT 5
7829-#define L1_CACHE_BYTES 32
7830+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7831
7832 #ifdef CONFIG_SPARC32
7833 #define SMP_CACHE_BYTES_SHIFT 5
7834diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7835index a24e41f..47677ff 100644
7836--- a/arch/sparc/include/asm/elf_32.h
7837+++ b/arch/sparc/include/asm/elf_32.h
7838@@ -114,6 +114,13 @@ typedef struct {
7839
7840 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7841
7842+#ifdef CONFIG_PAX_ASLR
7843+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7844+
7845+#define PAX_DELTA_MMAP_LEN 16
7846+#define PAX_DELTA_STACK_LEN 16
7847+#endif
7848+
7849 /* This yields a mask that user programs can use to figure out what
7850 instruction set this cpu supports. This can NOT be done in userspace
7851 on Sparc. */
7852diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7853index 370ca1e..d4f4a98 100644
7854--- a/arch/sparc/include/asm/elf_64.h
7855+++ b/arch/sparc/include/asm/elf_64.h
7856@@ -189,6 +189,13 @@ typedef struct {
7857 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7858 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7859
7860+#ifdef CONFIG_PAX_ASLR
7861+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7862+
7863+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7864+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7865+#endif
7866+
7867 extern unsigned long sparc64_elf_hwcap;
7868 #define ELF_HWCAP sparc64_elf_hwcap
7869
7870diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7871index 9b1c36d..209298b 100644
7872--- a/arch/sparc/include/asm/pgalloc_32.h
7873+++ b/arch/sparc/include/asm/pgalloc_32.h
7874@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7875 }
7876
7877 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7878+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7879
7880 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7881 unsigned long address)
7882diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7883index bcfe063..b333142 100644
7884--- a/arch/sparc/include/asm/pgalloc_64.h
7885+++ b/arch/sparc/include/asm/pgalloc_64.h
7886@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7887 }
7888
7889 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7890+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7891
7892 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7893 {
7894diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7895index 6fc1348..390c50a 100644
7896--- a/arch/sparc/include/asm/pgtable_32.h
7897+++ b/arch/sparc/include/asm/pgtable_32.h
7898@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7899 #define PAGE_SHARED SRMMU_PAGE_SHARED
7900 #define PAGE_COPY SRMMU_PAGE_COPY
7901 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7902+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7903+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7904+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7905 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7906
7907 /* Top-level page directory - dummy used by init-mm.
7908@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7909
7910 /* xwr */
7911 #define __P000 PAGE_NONE
7912-#define __P001 PAGE_READONLY
7913-#define __P010 PAGE_COPY
7914-#define __P011 PAGE_COPY
7915+#define __P001 PAGE_READONLY_NOEXEC
7916+#define __P010 PAGE_COPY_NOEXEC
7917+#define __P011 PAGE_COPY_NOEXEC
7918 #define __P100 PAGE_READONLY
7919 #define __P101 PAGE_READONLY
7920 #define __P110 PAGE_COPY
7921 #define __P111 PAGE_COPY
7922
7923 #define __S000 PAGE_NONE
7924-#define __S001 PAGE_READONLY
7925-#define __S010 PAGE_SHARED
7926-#define __S011 PAGE_SHARED
7927+#define __S001 PAGE_READONLY_NOEXEC
7928+#define __S010 PAGE_SHARED_NOEXEC
7929+#define __S011 PAGE_SHARED_NOEXEC
7930 #define __S100 PAGE_READONLY
7931 #define __S101 PAGE_READONLY
7932 #define __S110 PAGE_SHARED
7933diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7934index 79da178..c2eede8 100644
7935--- a/arch/sparc/include/asm/pgtsrmmu.h
7936+++ b/arch/sparc/include/asm/pgtsrmmu.h
7937@@ -115,6 +115,11 @@
7938 SRMMU_EXEC | SRMMU_REF)
7939 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7940 SRMMU_EXEC | SRMMU_REF)
7941+
7942+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7943+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7944+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7945+
7946 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7947 SRMMU_DIRTY | SRMMU_REF)
7948
7949diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7950index 9689176..63c18ea 100644
7951--- a/arch/sparc/include/asm/spinlock_64.h
7952+++ b/arch/sparc/include/asm/spinlock_64.h
7953@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7954
7955 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7956
7957-static void inline arch_read_lock(arch_rwlock_t *lock)
7958+static inline void arch_read_lock(arch_rwlock_t *lock)
7959 {
7960 unsigned long tmp1, tmp2;
7961
7962 __asm__ __volatile__ (
7963 "1: ldsw [%2], %0\n"
7964 " brlz,pn %0, 2f\n"
7965-"4: add %0, 1, %1\n"
7966+"4: addcc %0, 1, %1\n"
7967+
7968+#ifdef CONFIG_PAX_REFCOUNT
7969+" tvs %%icc, 6\n"
7970+#endif
7971+
7972 " cas [%2], %0, %1\n"
7973 " cmp %0, %1\n"
7974 " bne,pn %%icc, 1b\n"
7975@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
7976 " .previous"
7977 : "=&r" (tmp1), "=&r" (tmp2)
7978 : "r" (lock)
7979- : "memory");
7980+ : "memory", "cc");
7981 }
7982
7983-static int inline arch_read_trylock(arch_rwlock_t *lock)
7984+static inline int arch_read_trylock(arch_rwlock_t *lock)
7985 {
7986 int tmp1, tmp2;
7987
7988@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7989 "1: ldsw [%2], %0\n"
7990 " brlz,a,pn %0, 2f\n"
7991 " mov 0, %0\n"
7992-" add %0, 1, %1\n"
7993+" addcc %0, 1, %1\n"
7994+
7995+#ifdef CONFIG_PAX_REFCOUNT
7996+" tvs %%icc, 6\n"
7997+#endif
7998+
7999 " cas [%2], %0, %1\n"
8000 " cmp %0, %1\n"
8001 " bne,pn %%icc, 1b\n"
8002@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8003 return tmp1;
8004 }
8005
8006-static void inline arch_read_unlock(arch_rwlock_t *lock)
8007+static inline void arch_read_unlock(arch_rwlock_t *lock)
8008 {
8009 unsigned long tmp1, tmp2;
8010
8011 __asm__ __volatile__(
8012 "1: lduw [%2], %0\n"
8013-" sub %0, 1, %1\n"
8014+" subcc %0, 1, %1\n"
8015+
8016+#ifdef CONFIG_PAX_REFCOUNT
8017+" tvs %%icc, 6\n"
8018+#endif
8019+
8020 " cas [%2], %0, %1\n"
8021 " cmp %0, %1\n"
8022 " bne,pn %%xcc, 1b\n"
8023@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8024 : "memory");
8025 }
8026
8027-static void inline arch_write_lock(arch_rwlock_t *lock)
8028+static inline void arch_write_lock(arch_rwlock_t *lock)
8029 {
8030 unsigned long mask, tmp1, tmp2;
8031
8032@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8033 : "memory");
8034 }
8035
8036-static void inline arch_write_unlock(arch_rwlock_t *lock)
8037+static inline void arch_write_unlock(arch_rwlock_t *lock)
8038 {
8039 __asm__ __volatile__(
8040 " stw %%g0, [%0]"
8041@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8042 : "memory");
8043 }
8044
8045-static int inline arch_write_trylock(arch_rwlock_t *lock)
8046+static inline int arch_write_trylock(arch_rwlock_t *lock)
8047 {
8048 unsigned long mask, tmp1, tmp2, result;
8049
8050diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8051index 25849ae..924c54b 100644
8052--- a/arch/sparc/include/asm/thread_info_32.h
8053+++ b/arch/sparc/include/asm/thread_info_32.h
8054@@ -49,6 +49,8 @@ struct thread_info {
8055 unsigned long w_saved;
8056
8057 struct restart_block restart_block;
8058+
8059+ unsigned long lowest_stack;
8060 };
8061
8062 /*
8063diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8064index 269bd92..e46a9b8 100644
8065--- a/arch/sparc/include/asm/thread_info_64.h
8066+++ b/arch/sparc/include/asm/thread_info_64.h
8067@@ -63,6 +63,8 @@ struct thread_info {
8068 struct pt_regs *kern_una_regs;
8069 unsigned int kern_una_insn;
8070
8071+ unsigned long lowest_stack;
8072+
8073 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8074 };
8075
8076@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8077 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8078 /* flag bit 6 is available */
8079 #define TIF_32BIT 7 /* 32-bit binary */
8080-/* flag bit 8 is available */
8081+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8082 #define TIF_SECCOMP 9 /* secure computing */
8083 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8084 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8085+
8086 /* NOTE: Thread flags >= 12 should be ones we have no interest
8087 * in using in assembly, else we can't use the mask as
8088 * an immediate value in instructions such as andcc.
8089@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8090 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8091 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8092 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8093+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8094
8095 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8096 _TIF_DO_NOTIFY_RESUME_MASK | \
8097 _TIF_NEED_RESCHED)
8098 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8099
8100+#define _TIF_WORK_SYSCALL \
8101+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8102+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8103+
8104+
8105 /*
8106 * Thread-synchronous status.
8107 *
8108diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8109index 0167d26..767bb0c 100644
8110--- a/arch/sparc/include/asm/uaccess.h
8111+++ b/arch/sparc/include/asm/uaccess.h
8112@@ -1,5 +1,6 @@
8113 #ifndef ___ASM_SPARC_UACCESS_H
8114 #define ___ASM_SPARC_UACCESS_H
8115+
8116 #if defined(__sparc__) && defined(__arch64__)
8117 #include <asm/uaccess_64.h>
8118 #else
8119diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8120index 53a28dd..50c38c3 100644
8121--- a/arch/sparc/include/asm/uaccess_32.h
8122+++ b/arch/sparc/include/asm/uaccess_32.h
8123@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8124
8125 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8126 {
8127- if (n && __access_ok((unsigned long) to, n))
8128+ if ((long)n < 0)
8129+ return n;
8130+
8131+ if (n && __access_ok((unsigned long) to, n)) {
8132+ if (!__builtin_constant_p(n))
8133+ check_object_size(from, n, true);
8134 return __copy_user(to, (__force void __user *) from, n);
8135- else
8136+ } else
8137 return n;
8138 }
8139
8140 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8141 {
8142+ if ((long)n < 0)
8143+ return n;
8144+
8145+ if (!__builtin_constant_p(n))
8146+ check_object_size(from, n, true);
8147+
8148 return __copy_user(to, (__force void __user *) from, n);
8149 }
8150
8151 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8152 {
8153- if (n && __access_ok((unsigned long) from, n))
8154+ if ((long)n < 0)
8155+ return n;
8156+
8157+ if (n && __access_ok((unsigned long) from, n)) {
8158+ if (!__builtin_constant_p(n))
8159+ check_object_size(to, n, false);
8160 return __copy_user((__force void __user *) to, from, n);
8161- else
8162+ } else
8163 return n;
8164 }
8165
8166 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8167 {
8168+ if ((long)n < 0)
8169+ return n;
8170+
8171 return __copy_user((__force void __user *) to, from, n);
8172 }
8173
8174diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8175index e562d3c..191f176 100644
8176--- a/arch/sparc/include/asm/uaccess_64.h
8177+++ b/arch/sparc/include/asm/uaccess_64.h
8178@@ -10,6 +10,7 @@
8179 #include <linux/compiler.h>
8180 #include <linux/string.h>
8181 #include <linux/thread_info.h>
8182+#include <linux/kernel.h>
8183 #include <asm/asi.h>
8184 #include <asm/spitfire.h>
8185 #include <asm-generic/uaccess-unaligned.h>
8186@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8187 static inline unsigned long __must_check
8188 copy_from_user(void *to, const void __user *from, unsigned long size)
8189 {
8190- unsigned long ret = ___copy_from_user(to, from, size);
8191+ unsigned long ret;
8192
8193+ if ((long)size < 0 || size > INT_MAX)
8194+ return size;
8195+
8196+ if (!__builtin_constant_p(size))
8197+ check_object_size(to, size, false);
8198+
8199+ ret = ___copy_from_user(to, from, size);
8200 if (unlikely(ret))
8201 ret = copy_from_user_fixup(to, from, size);
8202
8203@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8204 static inline unsigned long __must_check
8205 copy_to_user(void __user *to, const void *from, unsigned long size)
8206 {
8207- unsigned long ret = ___copy_to_user(to, from, size);
8208+ unsigned long ret;
8209
8210+ if ((long)size < 0 || size > INT_MAX)
8211+ return size;
8212+
8213+ if (!__builtin_constant_p(size))
8214+ check_object_size(from, size, true);
8215+
8216+ ret = ___copy_to_user(to, from, size);
8217 if (unlikely(ret))
8218 ret = copy_to_user_fixup(to, from, size);
8219 return ret;
8220diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8221index 6cf591b..b49e65a 100644
8222--- a/arch/sparc/kernel/Makefile
8223+++ b/arch/sparc/kernel/Makefile
8224@@ -3,7 +3,7 @@
8225 #
8226
8227 asflags-y := -ansi
8228-ccflags-y := -Werror
8229+#ccflags-y := -Werror
8230
8231 extra-y := head_$(BITS).o
8232
8233diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8234index 62eede1..9c5b904 100644
8235--- a/arch/sparc/kernel/process_32.c
8236+++ b/arch/sparc/kernel/process_32.c
8237@@ -125,14 +125,14 @@ void show_regs(struct pt_regs *r)
8238
8239 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8240 r->psr, r->pc, r->npc, r->y, print_tainted());
8241- printk("PC: <%pS>\n", (void *) r->pc);
8242+ printk("PC: <%pA>\n", (void *) r->pc);
8243 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8244 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8245 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8246 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8247 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8248 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8249- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8250+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8251
8252 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8253 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8254@@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8255 rw = (struct reg_window32 *) fp;
8256 pc = rw->ins[7];
8257 printk("[%08lx : ", pc);
8258- printk("%pS ] ", (void *) pc);
8259+ printk("%pA ] ", (void *) pc);
8260 fp = rw->ins[6];
8261 } while (++count < 16);
8262 printk("\n");
8263diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8264index cdb80b2..5ca141d 100644
8265--- a/arch/sparc/kernel/process_64.c
8266+++ b/arch/sparc/kernel/process_64.c
8267@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8268 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8269 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8270 if (regs->tstate & TSTATE_PRIV)
8271- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8272+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8273 }
8274
8275 void show_regs(struct pt_regs *regs)
8276 {
8277 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8278 regs->tpc, regs->tnpc, regs->y, print_tainted());
8279- printk("TPC: <%pS>\n", (void *) regs->tpc);
8280+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8281 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8282 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8283 regs->u_regs[3]);
8284@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8285 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8286 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8287 regs->u_regs[15]);
8288- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8289+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8290 show_regwindow(regs);
8291 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8292 }
8293@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8294 ((tp && tp->task) ? tp->task->pid : -1));
8295
8296 if (gp->tstate & TSTATE_PRIV) {
8297- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8298+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8299 (void *) gp->tpc,
8300 (void *) gp->o7,
8301 (void *) gp->i7,
8302diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
8303index 9f20566..67eb41b 100644
8304--- a/arch/sparc/kernel/prom_common.c
8305+++ b/arch/sparc/kernel/prom_common.c
8306@@ -143,7 +143,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
8307
8308 unsigned int prom_early_allocated __initdata;
8309
8310-static struct of_pdt_ops prom_sparc_ops __initdata = {
8311+static struct of_pdt_ops prom_sparc_ops __initconst = {
8312 .nextprop = prom_common_nextprop,
8313 .getproplen = prom_getproplen,
8314 .getproperty = prom_getproperty,
8315diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8316index 7ff45e4..a58f271 100644
8317--- a/arch/sparc/kernel/ptrace_64.c
8318+++ b/arch/sparc/kernel/ptrace_64.c
8319@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8320 return ret;
8321 }
8322
8323+#ifdef CONFIG_GRKERNSEC_SETXID
8324+extern void gr_delayed_cred_worker(void);
8325+#endif
8326+
8327 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8328 {
8329 int ret = 0;
8330@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8331 /* do the secure computing check first */
8332 secure_computing_strict(regs->u_regs[UREG_G1]);
8333
8334+#ifdef CONFIG_GRKERNSEC_SETXID
8335+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8336+ gr_delayed_cred_worker();
8337+#endif
8338+
8339 if (test_thread_flag(TIF_SYSCALL_TRACE))
8340 ret = tracehook_report_syscall_entry(regs);
8341
8342@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8343
8344 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8345 {
8346+#ifdef CONFIG_GRKERNSEC_SETXID
8347+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8348+ gr_delayed_cred_worker();
8349+#endif
8350+
8351 audit_syscall_exit(regs);
8352
8353 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8354diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8355index 3a8d184..49498a8 100644
8356--- a/arch/sparc/kernel/sys_sparc_32.c
8357+++ b/arch/sparc/kernel/sys_sparc_32.c
8358@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8359 if (len > TASK_SIZE - PAGE_SIZE)
8360 return -ENOMEM;
8361 if (!addr)
8362- addr = TASK_UNMAPPED_BASE;
8363+ addr = current->mm->mmap_base;
8364
8365 info.flags = 0;
8366 info.length = len;
8367diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8368index 708bc29..6bfdfad 100644
8369--- a/arch/sparc/kernel/sys_sparc_64.c
8370+++ b/arch/sparc/kernel/sys_sparc_64.c
8371@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8372 struct vm_area_struct * vma;
8373 unsigned long task_size = TASK_SIZE;
8374 int do_color_align;
8375+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8376 struct vm_unmapped_area_info info;
8377
8378 if (flags & MAP_FIXED) {
8379 /* We do not accept a shared mapping if it would violate
8380 * cache aliasing constraints.
8381 */
8382- if ((flags & MAP_SHARED) &&
8383+ if ((filp || (flags & MAP_SHARED)) &&
8384 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8385 return -EINVAL;
8386 return addr;
8387@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8388 if (filp || (flags & MAP_SHARED))
8389 do_color_align = 1;
8390
8391+#ifdef CONFIG_PAX_RANDMMAP
8392+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8393+#endif
8394+
8395 if (addr) {
8396 if (do_color_align)
8397 addr = COLOR_ALIGN(addr, pgoff);
8398@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8399 addr = PAGE_ALIGN(addr);
8400
8401 vma = find_vma(mm, addr);
8402- if (task_size - len >= addr &&
8403- (!vma || addr + len <= vma->vm_start))
8404+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8405 return addr;
8406 }
8407
8408 info.flags = 0;
8409 info.length = len;
8410- info.low_limit = TASK_UNMAPPED_BASE;
8411+ info.low_limit = mm->mmap_base;
8412 info.high_limit = min(task_size, VA_EXCLUDE_START);
8413 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8414 info.align_offset = pgoff << PAGE_SHIFT;
8415+ info.threadstack_offset = offset;
8416 addr = vm_unmapped_area(&info);
8417
8418 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8419 VM_BUG_ON(addr != -ENOMEM);
8420 info.low_limit = VA_EXCLUDE_END;
8421+
8422+#ifdef CONFIG_PAX_RANDMMAP
8423+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8424+ info.low_limit += mm->delta_mmap;
8425+#endif
8426+
8427 info.high_limit = task_size;
8428 addr = vm_unmapped_area(&info);
8429 }
8430@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8431 unsigned long task_size = STACK_TOP32;
8432 unsigned long addr = addr0;
8433 int do_color_align;
8434+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8435 struct vm_unmapped_area_info info;
8436
8437 /* This should only ever run for 32-bit processes. */
8438@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8439 /* We do not accept a shared mapping if it would violate
8440 * cache aliasing constraints.
8441 */
8442- if ((flags & MAP_SHARED) &&
8443+ if ((filp || (flags & MAP_SHARED)) &&
8444 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8445 return -EINVAL;
8446 return addr;
8447@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8448 if (filp || (flags & MAP_SHARED))
8449 do_color_align = 1;
8450
8451+#ifdef CONFIG_PAX_RANDMMAP
8452+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8453+#endif
8454+
8455 /* requesting a specific address */
8456 if (addr) {
8457 if (do_color_align)
8458@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8459 addr = PAGE_ALIGN(addr);
8460
8461 vma = find_vma(mm, addr);
8462- if (task_size - len >= addr &&
8463- (!vma || addr + len <= vma->vm_start))
8464+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8465 return addr;
8466 }
8467
8468@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8469 info.high_limit = mm->mmap_base;
8470 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8471 info.align_offset = pgoff << PAGE_SHIFT;
8472+ info.threadstack_offset = offset;
8473 addr = vm_unmapped_area(&info);
8474
8475 /*
8476@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8477 VM_BUG_ON(addr != -ENOMEM);
8478 info.flags = 0;
8479 info.low_limit = TASK_UNMAPPED_BASE;
8480+
8481+#ifdef CONFIG_PAX_RANDMMAP
8482+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8483+ info.low_limit += mm->delta_mmap;
8484+#endif
8485+
8486 info.high_limit = STACK_TOP32;
8487 addr = vm_unmapped_area(&info);
8488 }
8489@@ -264,6 +286,10 @@ static unsigned long mmap_rnd(void)
8490 {
8491 unsigned long rnd = 0UL;
8492
8493+#ifdef CONFIG_PAX_RANDMMAP
8494+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8495+#endif
8496+
8497 if (current->flags & PF_RANDOMIZE) {
8498 unsigned long val = get_random_int();
8499 if (test_thread_flag(TIF_32BIT))
8500@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8501 gap == RLIM_INFINITY ||
8502 sysctl_legacy_va_layout) {
8503 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8504+
8505+#ifdef CONFIG_PAX_RANDMMAP
8506+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8507+ mm->mmap_base += mm->delta_mmap;
8508+#endif
8509+
8510 mm->get_unmapped_area = arch_get_unmapped_area;
8511 mm->unmap_area = arch_unmap_area;
8512 } else {
8513@@ -301,6 +333,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8514 gap = (task_size / 6 * 5);
8515
8516 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8517+
8518+#ifdef CONFIG_PAX_RANDMMAP
8519+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8520+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8521+#endif
8522+
8523 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8524 mm->unmap_area = arch_unmap_area_topdown;
8525 }
8526diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8527index 22a1098..6255eb9 100644
8528--- a/arch/sparc/kernel/syscalls.S
8529+++ b/arch/sparc/kernel/syscalls.S
8530@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
8531 #endif
8532 .align 32
8533 1: ldx [%g6 + TI_FLAGS], %l5
8534- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8535+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8536 be,pt %icc, rtrap
8537 nop
8538 call syscall_trace_leave
8539@@ -184,7 +184,7 @@ linux_sparc_syscall32:
8540
8541 srl %i5, 0, %o5 ! IEU1
8542 srl %i2, 0, %o2 ! IEU0 Group
8543- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8544+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8545 bne,pn %icc, linux_syscall_trace32 ! CTI
8546 mov %i0, %l5 ! IEU1
8547 call %l7 ! CTI Group brk forced
8548@@ -207,7 +207,7 @@ linux_sparc_syscall:
8549
8550 mov %i3, %o3 ! IEU1
8551 mov %i4, %o4 ! IEU0 Group
8552- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8553+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8554 bne,pn %icc, linux_syscall_trace ! CTI Group
8555 mov %i0, %l5 ! IEU0
8556 2: call %l7 ! CTI Group brk forced
8557@@ -223,7 +223,7 @@ ret_sys_call:
8558
8559 cmp %o0, -ERESTART_RESTARTBLOCK
8560 bgeu,pn %xcc, 1f
8561- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8562+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8563 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8564
8565 2:
8566diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8567index 654e8aa..45f431b 100644
8568--- a/arch/sparc/kernel/sysfs.c
8569+++ b/arch/sparc/kernel/sysfs.c
8570@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8571 return NOTIFY_OK;
8572 }
8573
8574-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8575+static struct notifier_block sysfs_cpu_nb = {
8576 .notifier_call = sysfs_cpu_notify,
8577 };
8578
8579diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8580index 6629829..036032d 100644
8581--- a/arch/sparc/kernel/traps_32.c
8582+++ b/arch/sparc/kernel/traps_32.c
8583@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8584 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8585 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8586
8587+extern void gr_handle_kernel_exploit(void);
8588+
8589 void die_if_kernel(char *str, struct pt_regs *regs)
8590 {
8591 static int die_counter;
8592@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8593 count++ < 30 &&
8594 (((unsigned long) rw) >= PAGE_OFFSET) &&
8595 !(((unsigned long) rw) & 0x7)) {
8596- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8597+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8598 (void *) rw->ins[7]);
8599 rw = (struct reg_window32 *)rw->ins[6];
8600 }
8601 }
8602 printk("Instruction DUMP:");
8603 instruction_dump ((unsigned long *) regs->pc);
8604- if(regs->psr & PSR_PS)
8605+ if(regs->psr & PSR_PS) {
8606+ gr_handle_kernel_exploit();
8607 do_exit(SIGKILL);
8608+ }
8609 do_exit(SIGSEGV);
8610 }
8611
8612diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8613index 8d38ca9..845b1d6 100644
8614--- a/arch/sparc/kernel/traps_64.c
8615+++ b/arch/sparc/kernel/traps_64.c
8616@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8617 i + 1,
8618 p->trapstack[i].tstate, p->trapstack[i].tpc,
8619 p->trapstack[i].tnpc, p->trapstack[i].tt);
8620- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8621+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8622 }
8623 }
8624
8625@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8626
8627 lvl -= 0x100;
8628 if (regs->tstate & TSTATE_PRIV) {
8629+
8630+#ifdef CONFIG_PAX_REFCOUNT
8631+ if (lvl == 6)
8632+ pax_report_refcount_overflow(regs);
8633+#endif
8634+
8635 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8636 die_if_kernel(buffer, regs);
8637 }
8638@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8639 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8640 {
8641 char buffer[32];
8642-
8643+
8644 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8645 0, lvl, SIGTRAP) == NOTIFY_STOP)
8646 return;
8647
8648+#ifdef CONFIG_PAX_REFCOUNT
8649+ if (lvl == 6)
8650+ pax_report_refcount_overflow(regs);
8651+#endif
8652+
8653 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8654
8655 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8656@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8657 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8658 printk("%s" "ERROR(%d): ",
8659 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8660- printk("TPC<%pS>\n", (void *) regs->tpc);
8661+ printk("TPC<%pA>\n", (void *) regs->tpc);
8662 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8663 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8664 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8665@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8666 smp_processor_id(),
8667 (type & 0x1) ? 'I' : 'D',
8668 regs->tpc);
8669- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8670+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8671 panic("Irrecoverable Cheetah+ parity error.");
8672 }
8673
8674@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8675 smp_processor_id(),
8676 (type & 0x1) ? 'I' : 'D',
8677 regs->tpc);
8678- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8679+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8680 }
8681
8682 struct sun4v_error_entry {
8683@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8684
8685 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8686 regs->tpc, tl);
8687- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8688+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8689 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8690- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8691+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8692 (void *) regs->u_regs[UREG_I7]);
8693 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8694 "pte[%lx] error[%lx]\n",
8695@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8696
8697 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8698 regs->tpc, tl);
8699- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8700+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8701 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8702- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8703+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8704 (void *) regs->u_regs[UREG_I7]);
8705 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8706 "pte[%lx] error[%lx]\n",
8707@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8708 fp = (unsigned long)sf->fp + STACK_BIAS;
8709 }
8710
8711- printk(" [%016lx] %pS\n", pc, (void *) pc);
8712+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8713 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8714 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8715 int index = tsk->curr_ret_stack;
8716 if (tsk->ret_stack && index >= graph) {
8717 pc = tsk->ret_stack[index - graph].ret;
8718- printk(" [%016lx] %pS\n", pc, (void *) pc);
8719+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8720 graph++;
8721 }
8722 }
8723@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8724 return (struct reg_window *) (fp + STACK_BIAS);
8725 }
8726
8727+extern void gr_handle_kernel_exploit(void);
8728+
8729 void die_if_kernel(char *str, struct pt_regs *regs)
8730 {
8731 static int die_counter;
8732@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8733 while (rw &&
8734 count++ < 30 &&
8735 kstack_valid(tp, (unsigned long) rw)) {
8736- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8737+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8738 (void *) rw->ins[7]);
8739
8740 rw = kernel_stack_up(rw);
8741@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8742 }
8743 user_instruction_dump ((unsigned int __user *) regs->tpc);
8744 }
8745- if (regs->tstate & TSTATE_PRIV)
8746+ if (regs->tstate & TSTATE_PRIV) {
8747+ gr_handle_kernel_exploit();
8748 do_exit(SIGKILL);
8749+ }
8750 do_exit(SIGSEGV);
8751 }
8752 EXPORT_SYMBOL(die_if_kernel);
8753diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8754index 8201c25e..072a2a7 100644
8755--- a/arch/sparc/kernel/unaligned_64.c
8756+++ b/arch/sparc/kernel/unaligned_64.c
8757@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8758 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8759
8760 if (__ratelimit(&ratelimit)) {
8761- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8762+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8763 regs->tpc, (void *) regs->tpc);
8764 }
8765 }
8766diff --git a/arch/sparc/kernel/us3_cpufreq.c b/arch/sparc/kernel/us3_cpufreq.c
8767index eb1624b..55100de 100644
8768--- a/arch/sparc/kernel/us3_cpufreq.c
8769+++ b/arch/sparc/kernel/us3_cpufreq.c
8770@@ -18,14 +18,12 @@
8771 #include <asm/head.h>
8772 #include <asm/timer.h>
8773
8774-static struct cpufreq_driver *cpufreq_us3_driver;
8775-
8776 struct us3_freq_percpu_info {
8777 struct cpufreq_frequency_table table[4];
8778 };
8779
8780 /* Indexed by cpu number. */
8781-static struct us3_freq_percpu_info *us3_freq_table;
8782+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
8783
8784 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
8785 * in the Safari config register.
8786@@ -191,12 +189,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
8787
8788 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
8789 {
8790- if (cpufreq_us3_driver)
8791- us3_set_cpu_divider_index(policy->cpu, 0);
8792+ us3_set_cpu_divider_index(policy->cpu, 0);
8793
8794 return 0;
8795 }
8796
8797+static int __init us3_freq_init(void);
8798+static void __exit us3_freq_exit(void);
8799+
8800+static struct cpufreq_driver cpufreq_us3_driver = {
8801+ .init = us3_freq_cpu_init,
8802+ .verify = us3_freq_verify,
8803+ .target = us3_freq_target,
8804+ .get = us3_freq_get,
8805+ .exit = us3_freq_cpu_exit,
8806+ .owner = THIS_MODULE,
8807+ .name = "UltraSPARC-III",
8808+
8809+};
8810+
8811 static int __init us3_freq_init(void)
8812 {
8813 unsigned long manuf, impl, ver;
8814@@ -213,57 +224,15 @@ static int __init us3_freq_init(void)
8815 (impl == CHEETAH_IMPL ||
8816 impl == CHEETAH_PLUS_IMPL ||
8817 impl == JAGUAR_IMPL ||
8818- impl == PANTHER_IMPL)) {
8819- struct cpufreq_driver *driver;
8820-
8821- ret = -ENOMEM;
8822- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
8823- if (!driver)
8824- goto err_out;
8825-
8826- us3_freq_table = kzalloc(
8827- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
8828- GFP_KERNEL);
8829- if (!us3_freq_table)
8830- goto err_out;
8831-
8832- driver->init = us3_freq_cpu_init;
8833- driver->verify = us3_freq_verify;
8834- driver->target = us3_freq_target;
8835- driver->get = us3_freq_get;
8836- driver->exit = us3_freq_cpu_exit;
8837- driver->owner = THIS_MODULE,
8838- strcpy(driver->name, "UltraSPARC-III");
8839-
8840- cpufreq_us3_driver = driver;
8841- ret = cpufreq_register_driver(driver);
8842- if (ret)
8843- goto err_out;
8844-
8845- return 0;
8846-
8847-err_out:
8848- if (driver) {
8849- kfree(driver);
8850- cpufreq_us3_driver = NULL;
8851- }
8852- kfree(us3_freq_table);
8853- us3_freq_table = NULL;
8854- return ret;
8855- }
8856+ impl == PANTHER_IMPL))
8857+ return cpufreq_register_driver(&cpufreq_us3_driver);
8858
8859 return -ENODEV;
8860 }
8861
8862 static void __exit us3_freq_exit(void)
8863 {
8864- if (cpufreq_us3_driver) {
8865- cpufreq_unregister_driver(cpufreq_us3_driver);
8866- kfree(cpufreq_us3_driver);
8867- cpufreq_us3_driver = NULL;
8868- kfree(us3_freq_table);
8869- us3_freq_table = NULL;
8870- }
8871+ cpufreq_unregister_driver(&cpufreq_us3_driver);
8872 }
8873
8874 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
8875diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8876index 8410065f2..4fd4ca22 100644
8877--- a/arch/sparc/lib/Makefile
8878+++ b/arch/sparc/lib/Makefile
8879@@ -2,7 +2,7 @@
8880 #
8881
8882 asflags-y := -ansi -DST_DIV0=0x02
8883-ccflags-y := -Werror
8884+#ccflags-y := -Werror
8885
8886 lib-$(CONFIG_SPARC32) += ashrdi3.o
8887 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8888diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8889index 85c233d..68500e0 100644
8890--- a/arch/sparc/lib/atomic_64.S
8891+++ b/arch/sparc/lib/atomic_64.S
8892@@ -17,7 +17,12 @@
8893 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8894 BACKOFF_SETUP(%o2)
8895 1: lduw [%o1], %g1
8896- add %g1, %o0, %g7
8897+ addcc %g1, %o0, %g7
8898+
8899+#ifdef CONFIG_PAX_REFCOUNT
8900+ tvs %icc, 6
8901+#endif
8902+
8903 cas [%o1], %g1, %g7
8904 cmp %g1, %g7
8905 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8906@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8907 2: BACKOFF_SPIN(%o2, %o3, 1b)
8908 ENDPROC(atomic_add)
8909
8910+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8911+ BACKOFF_SETUP(%o2)
8912+1: lduw [%o1], %g1
8913+ add %g1, %o0, %g7
8914+ cas [%o1], %g1, %g7
8915+ cmp %g1, %g7
8916+ bne,pn %icc, 2f
8917+ nop
8918+ retl
8919+ nop
8920+2: BACKOFF_SPIN(%o2, %o3, 1b)
8921+ENDPROC(atomic_add_unchecked)
8922+
8923 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8924 BACKOFF_SETUP(%o2)
8925 1: lduw [%o1], %g1
8926- sub %g1, %o0, %g7
8927+ subcc %g1, %o0, %g7
8928+
8929+#ifdef CONFIG_PAX_REFCOUNT
8930+ tvs %icc, 6
8931+#endif
8932+
8933 cas [%o1], %g1, %g7
8934 cmp %g1, %g7
8935 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8936@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8937 2: BACKOFF_SPIN(%o2, %o3, 1b)
8938 ENDPROC(atomic_sub)
8939
8940+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8941+ BACKOFF_SETUP(%o2)
8942+1: lduw [%o1], %g1
8943+ sub %g1, %o0, %g7
8944+ cas [%o1], %g1, %g7
8945+ cmp %g1, %g7
8946+ bne,pn %icc, 2f
8947+ nop
8948+ retl
8949+ nop
8950+2: BACKOFF_SPIN(%o2, %o3, 1b)
8951+ENDPROC(atomic_sub_unchecked)
8952+
8953 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8954 BACKOFF_SETUP(%o2)
8955 1: lduw [%o1], %g1
8956- add %g1, %o0, %g7
8957+ addcc %g1, %o0, %g7
8958+
8959+#ifdef CONFIG_PAX_REFCOUNT
8960+ tvs %icc, 6
8961+#endif
8962+
8963 cas [%o1], %g1, %g7
8964 cmp %g1, %g7
8965 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8966@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8967 2: BACKOFF_SPIN(%o2, %o3, 1b)
8968 ENDPROC(atomic_add_ret)
8969
8970+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8971+ BACKOFF_SETUP(%o2)
8972+1: lduw [%o1], %g1
8973+ addcc %g1, %o0, %g7
8974+ cas [%o1], %g1, %g7
8975+ cmp %g1, %g7
8976+ bne,pn %icc, 2f
8977+ add %g7, %o0, %g7
8978+ sra %g7, 0, %o0
8979+ retl
8980+ nop
8981+2: BACKOFF_SPIN(%o2, %o3, 1b)
8982+ENDPROC(atomic_add_ret_unchecked)
8983+
8984 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8985 BACKOFF_SETUP(%o2)
8986 1: lduw [%o1], %g1
8987- sub %g1, %o0, %g7
8988+ subcc %g1, %o0, %g7
8989+
8990+#ifdef CONFIG_PAX_REFCOUNT
8991+ tvs %icc, 6
8992+#endif
8993+
8994 cas [%o1], %g1, %g7
8995 cmp %g1, %g7
8996 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8997@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8998 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8999 BACKOFF_SETUP(%o2)
9000 1: ldx [%o1], %g1
9001- add %g1, %o0, %g7
9002+ addcc %g1, %o0, %g7
9003+
9004+#ifdef CONFIG_PAX_REFCOUNT
9005+ tvs %xcc, 6
9006+#endif
9007+
9008 casx [%o1], %g1, %g7
9009 cmp %g1, %g7
9010 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9011@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
9012 2: BACKOFF_SPIN(%o2, %o3, 1b)
9013 ENDPROC(atomic64_add)
9014
9015+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9016+ BACKOFF_SETUP(%o2)
9017+1: ldx [%o1], %g1
9018+ addcc %g1, %o0, %g7
9019+ casx [%o1], %g1, %g7
9020+ cmp %g1, %g7
9021+ bne,pn %xcc, 2f
9022+ nop
9023+ retl
9024+ nop
9025+2: BACKOFF_SPIN(%o2, %o3, 1b)
9026+ENDPROC(atomic64_add_unchecked)
9027+
9028 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9029 BACKOFF_SETUP(%o2)
9030 1: ldx [%o1], %g1
9031- sub %g1, %o0, %g7
9032+ subcc %g1, %o0, %g7
9033+
9034+#ifdef CONFIG_PAX_REFCOUNT
9035+ tvs %xcc, 6
9036+#endif
9037+
9038 casx [%o1], %g1, %g7
9039 cmp %g1, %g7
9040 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9041@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9042 2: BACKOFF_SPIN(%o2, %o3, 1b)
9043 ENDPROC(atomic64_sub)
9044
9045+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9046+ BACKOFF_SETUP(%o2)
9047+1: ldx [%o1], %g1
9048+ subcc %g1, %o0, %g7
9049+ casx [%o1], %g1, %g7
9050+ cmp %g1, %g7
9051+ bne,pn %xcc, 2f
9052+ nop
9053+ retl
9054+ nop
9055+2: BACKOFF_SPIN(%o2, %o3, 1b)
9056+ENDPROC(atomic64_sub_unchecked)
9057+
9058 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9059 BACKOFF_SETUP(%o2)
9060 1: ldx [%o1], %g1
9061- add %g1, %o0, %g7
9062+ addcc %g1, %o0, %g7
9063+
9064+#ifdef CONFIG_PAX_REFCOUNT
9065+ tvs %xcc, 6
9066+#endif
9067+
9068 casx [%o1], %g1, %g7
9069 cmp %g1, %g7
9070 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9071@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9072 2: BACKOFF_SPIN(%o2, %o3, 1b)
9073 ENDPROC(atomic64_add_ret)
9074
9075+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9076+ BACKOFF_SETUP(%o2)
9077+1: ldx [%o1], %g1
9078+ addcc %g1, %o0, %g7
9079+ casx [%o1], %g1, %g7
9080+ cmp %g1, %g7
9081+ bne,pn %xcc, 2f
9082+ add %g7, %o0, %g7
9083+ mov %g7, %o0
9084+ retl
9085+ nop
9086+2: BACKOFF_SPIN(%o2, %o3, 1b)
9087+ENDPROC(atomic64_add_ret_unchecked)
9088+
9089 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9090 BACKOFF_SETUP(%o2)
9091 1: ldx [%o1], %g1
9092- sub %g1, %o0, %g7
9093+ subcc %g1, %o0, %g7
9094+
9095+#ifdef CONFIG_PAX_REFCOUNT
9096+ tvs %xcc, 6
9097+#endif
9098+
9099 casx [%o1], %g1, %g7
9100 cmp %g1, %g7
9101 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9102diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9103index 0c4e35e..745d3e4 100644
9104--- a/arch/sparc/lib/ksyms.c
9105+++ b/arch/sparc/lib/ksyms.c
9106@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9107
9108 /* Atomic counter implementation. */
9109 EXPORT_SYMBOL(atomic_add);
9110+EXPORT_SYMBOL(atomic_add_unchecked);
9111 EXPORT_SYMBOL(atomic_add_ret);
9112+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9113 EXPORT_SYMBOL(atomic_sub);
9114+EXPORT_SYMBOL(atomic_sub_unchecked);
9115 EXPORT_SYMBOL(atomic_sub_ret);
9116 EXPORT_SYMBOL(atomic64_add);
9117+EXPORT_SYMBOL(atomic64_add_unchecked);
9118 EXPORT_SYMBOL(atomic64_add_ret);
9119+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9120 EXPORT_SYMBOL(atomic64_sub);
9121+EXPORT_SYMBOL(atomic64_sub_unchecked);
9122 EXPORT_SYMBOL(atomic64_sub_ret);
9123 EXPORT_SYMBOL(atomic64_dec_if_positive);
9124
9125diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9126index 30c3ecc..736f015 100644
9127--- a/arch/sparc/mm/Makefile
9128+++ b/arch/sparc/mm/Makefile
9129@@ -2,7 +2,7 @@
9130 #
9131
9132 asflags-y := -ansi
9133-ccflags-y := -Werror
9134+#ccflags-y := -Werror
9135
9136 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9137 obj-y += fault_$(BITS).o
9138diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9139index e98bfda..ea8d221 100644
9140--- a/arch/sparc/mm/fault_32.c
9141+++ b/arch/sparc/mm/fault_32.c
9142@@ -21,6 +21,9 @@
9143 #include <linux/perf_event.h>
9144 #include <linux/interrupt.h>
9145 #include <linux/kdebug.h>
9146+#include <linux/slab.h>
9147+#include <linux/pagemap.h>
9148+#include <linux/compiler.h>
9149
9150 #include <asm/page.h>
9151 #include <asm/pgtable.h>
9152@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9153 return safe_compute_effective_address(regs, insn);
9154 }
9155
9156+#ifdef CONFIG_PAX_PAGEEXEC
9157+#ifdef CONFIG_PAX_DLRESOLVE
9158+static void pax_emuplt_close(struct vm_area_struct *vma)
9159+{
9160+ vma->vm_mm->call_dl_resolve = 0UL;
9161+}
9162+
9163+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9164+{
9165+ unsigned int *kaddr;
9166+
9167+ vmf->page = alloc_page(GFP_HIGHUSER);
9168+ if (!vmf->page)
9169+ return VM_FAULT_OOM;
9170+
9171+ kaddr = kmap(vmf->page);
9172+ memset(kaddr, 0, PAGE_SIZE);
9173+ kaddr[0] = 0x9DE3BFA8U; /* save */
9174+ flush_dcache_page(vmf->page);
9175+ kunmap(vmf->page);
9176+ return VM_FAULT_MAJOR;
9177+}
9178+
9179+static const struct vm_operations_struct pax_vm_ops = {
9180+ .close = pax_emuplt_close,
9181+ .fault = pax_emuplt_fault
9182+};
9183+
9184+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9185+{
9186+ int ret;
9187+
9188+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9189+ vma->vm_mm = current->mm;
9190+ vma->vm_start = addr;
9191+ vma->vm_end = addr + PAGE_SIZE;
9192+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9193+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9194+ vma->vm_ops = &pax_vm_ops;
9195+
9196+ ret = insert_vm_struct(current->mm, vma);
9197+ if (ret)
9198+ return ret;
9199+
9200+ ++current->mm->total_vm;
9201+ return 0;
9202+}
9203+#endif
9204+
9205+/*
9206+ * PaX: decide what to do with offenders (regs->pc = fault address)
9207+ *
9208+ * returns 1 when task should be killed
9209+ * 2 when patched PLT trampoline was detected
9210+ * 3 when unpatched PLT trampoline was detected
9211+ */
9212+static int pax_handle_fetch_fault(struct pt_regs *regs)
9213+{
9214+
9215+#ifdef CONFIG_PAX_EMUPLT
9216+ int err;
9217+
9218+ do { /* PaX: patched PLT emulation #1 */
9219+ unsigned int sethi1, sethi2, jmpl;
9220+
9221+ err = get_user(sethi1, (unsigned int *)regs->pc);
9222+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9223+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9224+
9225+ if (err)
9226+ break;
9227+
9228+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9229+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9230+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9231+ {
9232+ unsigned int addr;
9233+
9234+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9235+ addr = regs->u_regs[UREG_G1];
9236+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9237+ regs->pc = addr;
9238+ regs->npc = addr+4;
9239+ return 2;
9240+ }
9241+ } while (0);
9242+
9243+ do { /* PaX: patched PLT emulation #2 */
9244+ unsigned int ba;
9245+
9246+ err = get_user(ba, (unsigned int *)regs->pc);
9247+
9248+ if (err)
9249+ break;
9250+
9251+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9252+ unsigned int addr;
9253+
9254+ if ((ba & 0xFFC00000U) == 0x30800000U)
9255+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9256+ else
9257+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9258+ regs->pc = addr;
9259+ regs->npc = addr+4;
9260+ return 2;
9261+ }
9262+ } while (0);
9263+
9264+ do { /* PaX: patched PLT emulation #3 */
9265+ unsigned int sethi, bajmpl, nop;
9266+
9267+ err = get_user(sethi, (unsigned int *)regs->pc);
9268+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9269+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9270+
9271+ if (err)
9272+ break;
9273+
9274+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9275+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9276+ nop == 0x01000000U)
9277+ {
9278+ unsigned int addr;
9279+
9280+ addr = (sethi & 0x003FFFFFU) << 10;
9281+ regs->u_regs[UREG_G1] = addr;
9282+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9283+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9284+ else
9285+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9286+ regs->pc = addr;
9287+ regs->npc = addr+4;
9288+ return 2;
9289+ }
9290+ } while (0);
9291+
9292+ do { /* PaX: unpatched PLT emulation step 1 */
9293+ unsigned int sethi, ba, nop;
9294+
9295+ err = get_user(sethi, (unsigned int *)regs->pc);
9296+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9297+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9298+
9299+ if (err)
9300+ break;
9301+
9302+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9303+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9304+ nop == 0x01000000U)
9305+ {
9306+ unsigned int addr, save, call;
9307+
9308+ if ((ba & 0xFFC00000U) == 0x30800000U)
9309+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9310+ else
9311+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9312+
9313+ err = get_user(save, (unsigned int *)addr);
9314+ err |= get_user(call, (unsigned int *)(addr+4));
9315+ err |= get_user(nop, (unsigned int *)(addr+8));
9316+ if (err)
9317+ break;
9318+
9319+#ifdef CONFIG_PAX_DLRESOLVE
9320+ if (save == 0x9DE3BFA8U &&
9321+ (call & 0xC0000000U) == 0x40000000U &&
9322+ nop == 0x01000000U)
9323+ {
9324+ struct vm_area_struct *vma;
9325+ unsigned long call_dl_resolve;
9326+
9327+ down_read(&current->mm->mmap_sem);
9328+ call_dl_resolve = current->mm->call_dl_resolve;
9329+ up_read(&current->mm->mmap_sem);
9330+ if (likely(call_dl_resolve))
9331+ goto emulate;
9332+
9333+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9334+
9335+ down_write(&current->mm->mmap_sem);
9336+ if (current->mm->call_dl_resolve) {
9337+ call_dl_resolve = current->mm->call_dl_resolve;
9338+ up_write(&current->mm->mmap_sem);
9339+ if (vma)
9340+ kmem_cache_free(vm_area_cachep, vma);
9341+ goto emulate;
9342+ }
9343+
9344+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9345+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9346+ up_write(&current->mm->mmap_sem);
9347+ if (vma)
9348+ kmem_cache_free(vm_area_cachep, vma);
9349+ return 1;
9350+ }
9351+
9352+ if (pax_insert_vma(vma, call_dl_resolve)) {
9353+ up_write(&current->mm->mmap_sem);
9354+ kmem_cache_free(vm_area_cachep, vma);
9355+ return 1;
9356+ }
9357+
9358+ current->mm->call_dl_resolve = call_dl_resolve;
9359+ up_write(&current->mm->mmap_sem);
9360+
9361+emulate:
9362+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9363+ regs->pc = call_dl_resolve;
9364+ regs->npc = addr+4;
9365+ return 3;
9366+ }
9367+#endif
9368+
9369+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9370+ if ((save & 0xFFC00000U) == 0x05000000U &&
9371+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9372+ nop == 0x01000000U)
9373+ {
9374+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9375+ regs->u_regs[UREG_G2] = addr + 4;
9376+ addr = (save & 0x003FFFFFU) << 10;
9377+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9378+ regs->pc = addr;
9379+ regs->npc = addr+4;
9380+ return 3;
9381+ }
9382+ }
9383+ } while (0);
9384+
9385+ do { /* PaX: unpatched PLT emulation step 2 */
9386+ unsigned int save, call, nop;
9387+
9388+ err = get_user(save, (unsigned int *)(regs->pc-4));
9389+ err |= get_user(call, (unsigned int *)regs->pc);
9390+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9391+ if (err)
9392+ break;
9393+
9394+ if (save == 0x9DE3BFA8U &&
9395+ (call & 0xC0000000U) == 0x40000000U &&
9396+ nop == 0x01000000U)
9397+ {
9398+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9399+
9400+ regs->u_regs[UREG_RETPC] = regs->pc;
9401+ regs->pc = dl_resolve;
9402+ regs->npc = dl_resolve+4;
9403+ return 3;
9404+ }
9405+ } while (0);
9406+#endif
9407+
9408+ return 1;
9409+}
9410+
9411+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9412+{
9413+ unsigned long i;
9414+
9415+ printk(KERN_ERR "PAX: bytes at PC: ");
9416+ for (i = 0; i < 8; i++) {
9417+ unsigned int c;
9418+ if (get_user(c, (unsigned int *)pc+i))
9419+ printk(KERN_CONT "???????? ");
9420+ else
9421+ printk(KERN_CONT "%08x ", c);
9422+ }
9423+ printk("\n");
9424+}
9425+#endif
9426+
9427 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9428 int text_fault)
9429 {
9430@@ -230,6 +504,24 @@ good_area:
9431 if (!(vma->vm_flags & VM_WRITE))
9432 goto bad_area;
9433 } else {
9434+
9435+#ifdef CONFIG_PAX_PAGEEXEC
9436+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9437+ up_read(&mm->mmap_sem);
9438+ switch (pax_handle_fetch_fault(regs)) {
9439+
9440+#ifdef CONFIG_PAX_EMUPLT
9441+ case 2:
9442+ case 3:
9443+ return;
9444+#endif
9445+
9446+ }
9447+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9448+ do_group_exit(SIGKILL);
9449+ }
9450+#endif
9451+
9452 /* Allow reads even for write-only mappings */
9453 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9454 goto bad_area;
9455diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9456index 5062ff3..e0b75f3 100644
9457--- a/arch/sparc/mm/fault_64.c
9458+++ b/arch/sparc/mm/fault_64.c
9459@@ -21,6 +21,9 @@
9460 #include <linux/kprobes.h>
9461 #include <linux/kdebug.h>
9462 #include <linux/percpu.h>
9463+#include <linux/slab.h>
9464+#include <linux/pagemap.h>
9465+#include <linux/compiler.h>
9466
9467 #include <asm/page.h>
9468 #include <asm/pgtable.h>
9469@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9470 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9471 regs->tpc);
9472 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9473- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9474+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9475 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9476 dump_stack();
9477 unhandled_fault(regs->tpc, current, regs);
9478@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9479 show_regs(regs);
9480 }
9481
9482+#ifdef CONFIG_PAX_PAGEEXEC
9483+#ifdef CONFIG_PAX_DLRESOLVE
9484+static void pax_emuplt_close(struct vm_area_struct *vma)
9485+{
9486+ vma->vm_mm->call_dl_resolve = 0UL;
9487+}
9488+
9489+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9490+{
9491+ unsigned int *kaddr;
9492+
9493+ vmf->page = alloc_page(GFP_HIGHUSER);
9494+ if (!vmf->page)
9495+ return VM_FAULT_OOM;
9496+
9497+ kaddr = kmap(vmf->page);
9498+ memset(kaddr, 0, PAGE_SIZE);
9499+ kaddr[0] = 0x9DE3BFA8U; /* save */
9500+ flush_dcache_page(vmf->page);
9501+ kunmap(vmf->page);
9502+ return VM_FAULT_MAJOR;
9503+}
9504+
9505+static const struct vm_operations_struct pax_vm_ops = {
9506+ .close = pax_emuplt_close,
9507+ .fault = pax_emuplt_fault
9508+};
9509+
9510+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9511+{
9512+ int ret;
9513+
9514+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9515+ vma->vm_mm = current->mm;
9516+ vma->vm_start = addr;
9517+ vma->vm_end = addr + PAGE_SIZE;
9518+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9519+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9520+ vma->vm_ops = &pax_vm_ops;
9521+
9522+ ret = insert_vm_struct(current->mm, vma);
9523+ if (ret)
9524+ return ret;
9525+
9526+ ++current->mm->total_vm;
9527+ return 0;
9528+}
9529+#endif
9530+
9531+/*
9532+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9533+ *
9534+ * returns 1 when task should be killed
9535+ * 2 when patched PLT trampoline was detected
9536+ * 3 when unpatched PLT trampoline was detected
9537+ */
9538+static int pax_handle_fetch_fault(struct pt_regs *regs)
9539+{
9540+
9541+#ifdef CONFIG_PAX_EMUPLT
9542+ int err;
9543+
9544+ do { /* PaX: patched PLT emulation #1 */
9545+ unsigned int sethi1, sethi2, jmpl;
9546+
9547+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9548+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9549+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9550+
9551+ if (err)
9552+ break;
9553+
9554+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9555+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9556+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9557+ {
9558+ unsigned long addr;
9559+
9560+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9561+ addr = regs->u_regs[UREG_G1];
9562+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9563+
9564+ if (test_thread_flag(TIF_32BIT))
9565+ addr &= 0xFFFFFFFFUL;
9566+
9567+ regs->tpc = addr;
9568+ regs->tnpc = addr+4;
9569+ return 2;
9570+ }
9571+ } while (0);
9572+
9573+ do { /* PaX: patched PLT emulation #2 */
9574+ unsigned int ba;
9575+
9576+ err = get_user(ba, (unsigned int *)regs->tpc);
9577+
9578+ if (err)
9579+ break;
9580+
9581+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9582+ unsigned long addr;
9583+
9584+ if ((ba & 0xFFC00000U) == 0x30800000U)
9585+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9586+ else
9587+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9588+
9589+ if (test_thread_flag(TIF_32BIT))
9590+ addr &= 0xFFFFFFFFUL;
9591+
9592+ regs->tpc = addr;
9593+ regs->tnpc = addr+4;
9594+ return 2;
9595+ }
9596+ } while (0);
9597+
9598+ do { /* PaX: patched PLT emulation #3 */
9599+ unsigned int sethi, bajmpl, nop;
9600+
9601+ err = get_user(sethi, (unsigned int *)regs->tpc);
9602+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9603+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9604+
9605+ if (err)
9606+ break;
9607+
9608+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9609+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9610+ nop == 0x01000000U)
9611+ {
9612+ unsigned long addr;
9613+
9614+ addr = (sethi & 0x003FFFFFU) << 10;
9615+ regs->u_regs[UREG_G1] = addr;
9616+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9617+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9618+ else
9619+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9620+
9621+ if (test_thread_flag(TIF_32BIT))
9622+ addr &= 0xFFFFFFFFUL;
9623+
9624+ regs->tpc = addr;
9625+ regs->tnpc = addr+4;
9626+ return 2;
9627+ }
9628+ } while (0);
9629+
9630+ do { /* PaX: patched PLT emulation #4 */
9631+ unsigned int sethi, mov1, call, mov2;
9632+
9633+ err = get_user(sethi, (unsigned int *)regs->tpc);
9634+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9635+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9636+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9637+
9638+ if (err)
9639+ break;
9640+
9641+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9642+ mov1 == 0x8210000FU &&
9643+ (call & 0xC0000000U) == 0x40000000U &&
9644+ mov2 == 0x9E100001U)
9645+ {
9646+ unsigned long addr;
9647+
9648+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9649+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9650+
9651+ if (test_thread_flag(TIF_32BIT))
9652+ addr &= 0xFFFFFFFFUL;
9653+
9654+ regs->tpc = addr;
9655+ regs->tnpc = addr+4;
9656+ return 2;
9657+ }
9658+ } while (0);
9659+
9660+ do { /* PaX: patched PLT emulation #5 */
9661+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9662+
9663+ err = get_user(sethi, (unsigned int *)regs->tpc);
9664+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9665+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9666+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9667+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9668+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9669+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9670+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9671+
9672+ if (err)
9673+ break;
9674+
9675+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9676+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9677+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9678+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9679+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9680+ sllx == 0x83287020U &&
9681+ jmpl == 0x81C04005U &&
9682+ nop == 0x01000000U)
9683+ {
9684+ unsigned long addr;
9685+
9686+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9687+ regs->u_regs[UREG_G1] <<= 32;
9688+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9689+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9690+ regs->tpc = addr;
9691+ regs->tnpc = addr+4;
9692+ return 2;
9693+ }
9694+ } while (0);
9695+
9696+ do { /* PaX: patched PLT emulation #6 */
9697+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9698+
9699+ err = get_user(sethi, (unsigned int *)regs->tpc);
9700+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9701+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9702+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9703+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9704+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9705+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9706+
9707+ if (err)
9708+ break;
9709+
9710+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9711+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9712+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9713+ sllx == 0x83287020U &&
9714+ (or & 0xFFFFE000U) == 0x8A116000U &&
9715+ jmpl == 0x81C04005U &&
9716+ nop == 0x01000000U)
9717+ {
9718+ unsigned long addr;
9719+
9720+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9721+ regs->u_regs[UREG_G1] <<= 32;
9722+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9723+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9724+ regs->tpc = addr;
9725+ regs->tnpc = addr+4;
9726+ return 2;
9727+ }
9728+ } while (0);
9729+
9730+ do { /* PaX: unpatched PLT emulation step 1 */
9731+ unsigned int sethi, ba, nop;
9732+
9733+ err = get_user(sethi, (unsigned int *)regs->tpc);
9734+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9735+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9736+
9737+ if (err)
9738+ break;
9739+
9740+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9741+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9742+ nop == 0x01000000U)
9743+ {
9744+ unsigned long addr;
9745+ unsigned int save, call;
9746+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9747+
9748+ if ((ba & 0xFFC00000U) == 0x30800000U)
9749+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9750+ else
9751+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9752+
9753+ if (test_thread_flag(TIF_32BIT))
9754+ addr &= 0xFFFFFFFFUL;
9755+
9756+ err = get_user(save, (unsigned int *)addr);
9757+ err |= get_user(call, (unsigned int *)(addr+4));
9758+ err |= get_user(nop, (unsigned int *)(addr+8));
9759+ if (err)
9760+ break;
9761+
9762+#ifdef CONFIG_PAX_DLRESOLVE
9763+ if (save == 0x9DE3BFA8U &&
9764+ (call & 0xC0000000U) == 0x40000000U &&
9765+ nop == 0x01000000U)
9766+ {
9767+ struct vm_area_struct *vma;
9768+ unsigned long call_dl_resolve;
9769+
9770+ down_read(&current->mm->mmap_sem);
9771+ call_dl_resolve = current->mm->call_dl_resolve;
9772+ up_read(&current->mm->mmap_sem);
9773+ if (likely(call_dl_resolve))
9774+ goto emulate;
9775+
9776+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9777+
9778+ down_write(&current->mm->mmap_sem);
9779+ if (current->mm->call_dl_resolve) {
9780+ call_dl_resolve = current->mm->call_dl_resolve;
9781+ up_write(&current->mm->mmap_sem);
9782+ if (vma)
9783+ kmem_cache_free(vm_area_cachep, vma);
9784+ goto emulate;
9785+ }
9786+
9787+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9788+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9789+ up_write(&current->mm->mmap_sem);
9790+ if (vma)
9791+ kmem_cache_free(vm_area_cachep, vma);
9792+ return 1;
9793+ }
9794+
9795+ if (pax_insert_vma(vma, call_dl_resolve)) {
9796+ up_write(&current->mm->mmap_sem);
9797+ kmem_cache_free(vm_area_cachep, vma);
9798+ return 1;
9799+ }
9800+
9801+ current->mm->call_dl_resolve = call_dl_resolve;
9802+ up_write(&current->mm->mmap_sem);
9803+
9804+emulate:
9805+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9806+ regs->tpc = call_dl_resolve;
9807+ regs->tnpc = addr+4;
9808+ return 3;
9809+ }
9810+#endif
9811+
9812+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9813+ if ((save & 0xFFC00000U) == 0x05000000U &&
9814+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9815+ nop == 0x01000000U)
9816+ {
9817+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9818+ regs->u_regs[UREG_G2] = addr + 4;
9819+ addr = (save & 0x003FFFFFU) << 10;
9820+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9821+
9822+ if (test_thread_flag(TIF_32BIT))
9823+ addr &= 0xFFFFFFFFUL;
9824+
9825+ regs->tpc = addr;
9826+ regs->tnpc = addr+4;
9827+ return 3;
9828+ }
9829+
9830+ /* PaX: 64-bit PLT stub */
9831+ err = get_user(sethi1, (unsigned int *)addr);
9832+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9833+ err |= get_user(or1, (unsigned int *)(addr+8));
9834+ err |= get_user(or2, (unsigned int *)(addr+12));
9835+ err |= get_user(sllx, (unsigned int *)(addr+16));
9836+ err |= get_user(add, (unsigned int *)(addr+20));
9837+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9838+ err |= get_user(nop, (unsigned int *)(addr+28));
9839+ if (err)
9840+ break;
9841+
9842+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9843+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9844+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9845+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9846+ sllx == 0x89293020U &&
9847+ add == 0x8A010005U &&
9848+ jmpl == 0x89C14000U &&
9849+ nop == 0x01000000U)
9850+ {
9851+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9852+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9853+ regs->u_regs[UREG_G4] <<= 32;
9854+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9855+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9856+ regs->u_regs[UREG_G4] = addr + 24;
9857+ addr = regs->u_regs[UREG_G5];
9858+ regs->tpc = addr;
9859+ regs->tnpc = addr+4;
9860+ return 3;
9861+ }
9862+ }
9863+ } while (0);
9864+
9865+#ifdef CONFIG_PAX_DLRESOLVE
9866+ do { /* PaX: unpatched PLT emulation step 2 */
9867+ unsigned int save, call, nop;
9868+
9869+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9870+ err |= get_user(call, (unsigned int *)regs->tpc);
9871+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9872+ if (err)
9873+ break;
9874+
9875+ if (save == 0x9DE3BFA8U &&
9876+ (call & 0xC0000000U) == 0x40000000U &&
9877+ nop == 0x01000000U)
9878+ {
9879+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9880+
9881+ if (test_thread_flag(TIF_32BIT))
9882+ dl_resolve &= 0xFFFFFFFFUL;
9883+
9884+ regs->u_regs[UREG_RETPC] = regs->tpc;
9885+ regs->tpc = dl_resolve;
9886+ regs->tnpc = dl_resolve+4;
9887+ return 3;
9888+ }
9889+ } while (0);
9890+#endif
9891+
9892+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9893+ unsigned int sethi, ba, nop;
9894+
9895+ err = get_user(sethi, (unsigned int *)regs->tpc);
9896+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9897+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9898+
9899+ if (err)
9900+ break;
9901+
9902+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9903+ (ba & 0xFFF00000U) == 0x30600000U &&
9904+ nop == 0x01000000U)
9905+ {
9906+ unsigned long addr;
9907+
9908+ addr = (sethi & 0x003FFFFFU) << 10;
9909+ regs->u_regs[UREG_G1] = addr;
9910+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9911+
9912+ if (test_thread_flag(TIF_32BIT))
9913+ addr &= 0xFFFFFFFFUL;
9914+
9915+ regs->tpc = addr;
9916+ regs->tnpc = addr+4;
9917+ return 2;
9918+ }
9919+ } while (0);
9920+
9921+#endif
9922+
9923+ return 1;
9924+}
9925+
9926+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9927+{
9928+ unsigned long i;
9929+
9930+ printk(KERN_ERR "PAX: bytes at PC: ");
9931+ for (i = 0; i < 8; i++) {
9932+ unsigned int c;
9933+ if (get_user(c, (unsigned int *)pc+i))
9934+ printk(KERN_CONT "???????? ");
9935+ else
9936+ printk(KERN_CONT "%08x ", c);
9937+ }
9938+ printk("\n");
9939+}
9940+#endif
9941+
9942 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9943 {
9944 struct mm_struct *mm = current->mm;
9945@@ -341,6 +804,29 @@ retry:
9946 if (!vma)
9947 goto bad_area;
9948
9949+#ifdef CONFIG_PAX_PAGEEXEC
9950+ /* PaX: detect ITLB misses on non-exec pages */
9951+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9952+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9953+ {
9954+ if (address != regs->tpc)
9955+ goto good_area;
9956+
9957+ up_read(&mm->mmap_sem);
9958+ switch (pax_handle_fetch_fault(regs)) {
9959+
9960+#ifdef CONFIG_PAX_EMUPLT
9961+ case 2:
9962+ case 3:
9963+ return;
9964+#endif
9965+
9966+ }
9967+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9968+ do_group_exit(SIGKILL);
9969+ }
9970+#endif
9971+
9972 /* Pure DTLB misses do not tell us whether the fault causing
9973 * load/store/atomic was a write or not, it only says that there
9974 * was no match. So in such a case we (carefully) read the
9975diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9976index d2b5944..bd813f2 100644
9977--- a/arch/sparc/mm/hugetlbpage.c
9978+++ b/arch/sparc/mm/hugetlbpage.c
9979@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9980
9981 info.flags = 0;
9982 info.length = len;
9983- info.low_limit = TASK_UNMAPPED_BASE;
9984+ info.low_limit = mm->mmap_base;
9985 info.high_limit = min(task_size, VA_EXCLUDE_START);
9986 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9987 info.align_offset = 0;
9988@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9989 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9990 VM_BUG_ON(addr != -ENOMEM);
9991 info.low_limit = VA_EXCLUDE_END;
9992+
9993+#ifdef CONFIG_PAX_RANDMMAP
9994+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9995+ info.low_limit += mm->delta_mmap;
9996+#endif
9997+
9998 info.high_limit = task_size;
9999 addr = vm_unmapped_area(&info);
10000 }
10001@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10002 VM_BUG_ON(addr != -ENOMEM);
10003 info.flags = 0;
10004 info.low_limit = TASK_UNMAPPED_BASE;
10005+
10006+#ifdef CONFIG_PAX_RANDMMAP
10007+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10008+ info.low_limit += mm->delta_mmap;
10009+#endif
10010+
10011 info.high_limit = STACK_TOP32;
10012 addr = vm_unmapped_area(&info);
10013 }
10014@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10015 struct mm_struct *mm = current->mm;
10016 struct vm_area_struct *vma;
10017 unsigned long task_size = TASK_SIZE;
10018+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
10019
10020 if (test_thread_flag(TIF_32BIT))
10021 task_size = STACK_TOP32;
10022@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10023 return addr;
10024 }
10025
10026+#ifdef CONFIG_PAX_RANDMMAP
10027+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10028+#endif
10029+
10030 if (addr) {
10031 addr = ALIGN(addr, HPAGE_SIZE);
10032 vma = find_vma(mm, addr);
10033- if (task_size - len >= addr &&
10034- (!vma || addr + len <= vma->vm_start))
10035+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10036 return addr;
10037 }
10038 if (mm->get_unmapped_area == arch_get_unmapped_area)
10039diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c
10040index 83d89bc..37e7bc4 100644
10041--- a/arch/sparc/mm/tlb.c
10042+++ b/arch/sparc/mm/tlb.c
10043@@ -85,8 +85,8 @@ static void tlb_batch_add_one(struct mm_struct *mm, unsigned long vaddr,
10044 }
10045
10046 if (!tb->active) {
10047- global_flush_tlb_page(mm, vaddr);
10048 flush_tsb_user_page(mm, vaddr);
10049+ global_flush_tlb_page(mm, vaddr);
10050 goto out;
10051 }
10052
10053diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
10054index f4500c6..889656c 100644
10055--- a/arch/tile/include/asm/atomic_64.h
10056+++ b/arch/tile/include/asm/atomic_64.h
10057@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10058
10059 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10060
10061+#define atomic64_read_unchecked(v) atomic64_read(v)
10062+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10063+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10064+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10065+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10066+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10067+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10068+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10069+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10070+
10071 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
10072 #define smp_mb__before_atomic_dec() smp_mb()
10073 #define smp_mb__after_atomic_dec() smp_mb()
10074diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
10075index a9a5299..0fce79e 100644
10076--- a/arch/tile/include/asm/cache.h
10077+++ b/arch/tile/include/asm/cache.h
10078@@ -15,11 +15,12 @@
10079 #ifndef _ASM_TILE_CACHE_H
10080 #define _ASM_TILE_CACHE_H
10081
10082+#include <linux/const.h>
10083 #include <arch/chip.h>
10084
10085 /* bytes per L1 data cache line */
10086 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10087-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10088+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10089
10090 /* bytes per L2 cache line */
10091 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10092diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10093index 9ab078a..d6635c2 100644
10094--- a/arch/tile/include/asm/uaccess.h
10095+++ b/arch/tile/include/asm/uaccess.h
10096@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10097 const void __user *from,
10098 unsigned long n)
10099 {
10100- int sz = __compiletime_object_size(to);
10101+ size_t sz = __compiletime_object_size(to);
10102
10103- if (likely(sz == -1 || sz >= n))
10104+ if (likely(sz == (size_t)-1 || sz >= n))
10105 n = _copy_from_user(to, from, n);
10106 else
10107 copy_from_user_overflow();
10108diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
10109index 650ccff..45fe2d6 100644
10110--- a/arch/tile/mm/hugetlbpage.c
10111+++ b/arch/tile/mm/hugetlbpage.c
10112@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
10113 info.high_limit = TASK_SIZE;
10114 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10115 info.align_offset = 0;
10116+ info.threadstack_offset = 0;
10117 return vm_unmapped_area(&info);
10118 }
10119
10120@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
10121 info.high_limit = current->mm->mmap_base;
10122 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10123 info.align_offset = 0;
10124+ info.threadstack_offset = 0;
10125 addr = vm_unmapped_area(&info);
10126
10127 /*
10128diff --git a/arch/um/Makefile b/arch/um/Makefile
10129index 133f7de..1d6f2f1 100644
10130--- a/arch/um/Makefile
10131+++ b/arch/um/Makefile
10132@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10133 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10134 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10135
10136+ifdef CONSTIFY_PLUGIN
10137+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10138+endif
10139+
10140 #This will adjust *FLAGS accordingly to the platform.
10141 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10142
10143diff --git a/arch/um/defconfig b/arch/um/defconfig
10144index 08107a7..ab22afe 100644
10145--- a/arch/um/defconfig
10146+++ b/arch/um/defconfig
10147@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
10148 CONFIG_X86_L1_CACHE_SHIFT=5
10149 CONFIG_X86_XADD=y
10150 CONFIG_X86_PPRO_FENCE=y
10151-CONFIG_X86_WP_WORKS_OK=y
10152 CONFIG_X86_INVLPG=y
10153 CONFIG_X86_BSWAP=y
10154 CONFIG_X86_POPAD_OK=y
10155diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10156index 19e1bdd..3665b77 100644
10157--- a/arch/um/include/asm/cache.h
10158+++ b/arch/um/include/asm/cache.h
10159@@ -1,6 +1,7 @@
10160 #ifndef __UM_CACHE_H
10161 #define __UM_CACHE_H
10162
10163+#include <linux/const.h>
10164
10165 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10166 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10167@@ -12,6 +13,6 @@
10168 # define L1_CACHE_SHIFT 5
10169 #endif
10170
10171-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10172+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10173
10174 #endif
10175diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10176index 2e0a6b1..a64d0f5 100644
10177--- a/arch/um/include/asm/kmap_types.h
10178+++ b/arch/um/include/asm/kmap_types.h
10179@@ -8,6 +8,6 @@
10180
10181 /* No more #include "asm/arch/kmap_types.h" ! */
10182
10183-#define KM_TYPE_NR 14
10184+#define KM_TYPE_NR 15
10185
10186 #endif
10187diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10188index 5ff53d9..5850cdf 100644
10189--- a/arch/um/include/asm/page.h
10190+++ b/arch/um/include/asm/page.h
10191@@ -14,6 +14,9 @@
10192 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10193 #define PAGE_MASK (~(PAGE_SIZE-1))
10194
10195+#define ktla_ktva(addr) (addr)
10196+#define ktva_ktla(addr) (addr)
10197+
10198 #ifndef __ASSEMBLY__
10199
10200 struct page;
10201diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10202index 0032f92..cd151e0 100644
10203--- a/arch/um/include/asm/pgtable-3level.h
10204+++ b/arch/um/include/asm/pgtable-3level.h
10205@@ -58,6 +58,7 @@
10206 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10207 #define pud_populate(mm, pud, pmd) \
10208 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10209+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10210
10211 #ifdef CONFIG_64BIT
10212 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10213diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10214index b462b13..e7a19aa 100644
10215--- a/arch/um/kernel/process.c
10216+++ b/arch/um/kernel/process.c
10217@@ -386,22 +386,6 @@ int singlestepping(void * t)
10218 return 2;
10219 }
10220
10221-/*
10222- * Only x86 and x86_64 have an arch_align_stack().
10223- * All other arches have "#define arch_align_stack(x) (x)"
10224- * in their asm/system.h
10225- * As this is included in UML from asm-um/system-generic.h,
10226- * we can use it to behave as the subarch does.
10227- */
10228-#ifndef arch_align_stack
10229-unsigned long arch_align_stack(unsigned long sp)
10230-{
10231- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10232- sp -= get_random_int() % 8192;
10233- return sp & ~0xf;
10234-}
10235-#endif
10236-
10237 unsigned long get_wchan(struct task_struct *p)
10238 {
10239 unsigned long stack_page, sp, ip;
10240diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10241index ad8f795..2c7eec6 100644
10242--- a/arch/unicore32/include/asm/cache.h
10243+++ b/arch/unicore32/include/asm/cache.h
10244@@ -12,8 +12,10 @@
10245 #ifndef __UNICORE_CACHE_H__
10246 #define __UNICORE_CACHE_H__
10247
10248-#define L1_CACHE_SHIFT (5)
10249-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10250+#include <linux/const.h>
10251+
10252+#define L1_CACHE_SHIFT 5
10253+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10254
10255 /*
10256 * Memory returned by kmalloc() may be used for DMA, so we must make
10257diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10258index de80b33..c0f0899 100644
10259--- a/arch/x86/Kconfig
10260+++ b/arch/x86/Kconfig
10261@@ -243,7 +243,7 @@ config X86_HT
10262
10263 config X86_32_LAZY_GS
10264 def_bool y
10265- depends on X86_32 && !CC_STACKPROTECTOR
10266+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10267
10268 config ARCH_HWEIGHT_CFLAGS
10269 string
10270@@ -1076,6 +1076,7 @@ config MICROCODE_EARLY
10271
10272 config X86_MSR
10273 tristate "/dev/cpu/*/msr - Model-specific register support"
10274+ depends on !GRKERNSEC_KMEM
10275 ---help---
10276 This device gives privileged processes access to the x86
10277 Model-Specific Registers (MSRs). It is a character device with
10278@@ -1099,7 +1100,7 @@ choice
10279
10280 config NOHIGHMEM
10281 bool "off"
10282- depends on !X86_NUMAQ
10283+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10284 ---help---
10285 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10286 However, the address space of 32-bit x86 processors is only 4
10287@@ -1136,7 +1137,7 @@ config NOHIGHMEM
10288
10289 config HIGHMEM4G
10290 bool "4GB"
10291- depends on !X86_NUMAQ
10292+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10293 ---help---
10294 Select this if you have a 32-bit processor and between 1 and 4
10295 gigabytes of physical RAM.
10296@@ -1189,7 +1190,7 @@ config PAGE_OFFSET
10297 hex
10298 default 0xB0000000 if VMSPLIT_3G_OPT
10299 default 0x80000000 if VMSPLIT_2G
10300- default 0x78000000 if VMSPLIT_2G_OPT
10301+ default 0x70000000 if VMSPLIT_2G_OPT
10302 default 0x40000000 if VMSPLIT_1G
10303 default 0xC0000000
10304 depends on X86_32
10305@@ -1587,6 +1588,7 @@ config SECCOMP
10306
10307 config CC_STACKPROTECTOR
10308 bool "Enable -fstack-protector buffer overflow detection"
10309+ depends on X86_64 || !PAX_MEMORY_UDEREF
10310 ---help---
10311 This option turns on the -fstack-protector GCC feature. This
10312 feature puts, at the beginning of functions, a canary value on
10313@@ -1706,6 +1708,8 @@ config X86_NEED_RELOCS
10314 config PHYSICAL_ALIGN
10315 hex "Alignment value to which kernel should be aligned" if X86_32
10316 default "0x1000000"
10317+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
10318+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
10319 range 0x2000 0x1000000
10320 ---help---
10321 This value puts the alignment restrictions on physical address
10322@@ -1781,9 +1785,10 @@ config DEBUG_HOTPLUG_CPU0
10323 If unsure, say N.
10324
10325 config COMPAT_VDSO
10326- def_bool y
10327+ def_bool n
10328 prompt "Compat VDSO support"
10329 depends on X86_32 || IA32_EMULATION
10330+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10331 ---help---
10332 Map the 32-bit VDSO to the predictable old-style address too.
10333
10334diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10335index c026cca..14657ae 100644
10336--- a/arch/x86/Kconfig.cpu
10337+++ b/arch/x86/Kconfig.cpu
10338@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10339
10340 config X86_F00F_BUG
10341 def_bool y
10342- depends on M586MMX || M586TSC || M586 || M486
10343+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10344
10345 config X86_INVD_BUG
10346 def_bool y
10347@@ -327,7 +327,7 @@ config X86_INVD_BUG
10348
10349 config X86_ALIGNMENT_16
10350 def_bool y
10351- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10352+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10353
10354 config X86_INTEL_USERCOPY
10355 def_bool y
10356@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10357 # generates cmov.
10358 config X86_CMOV
10359 def_bool y
10360- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10361+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10362
10363 config X86_MINIMUM_CPU_FAMILY
10364 int
10365diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10366index b322f12..652d0d9 100644
10367--- a/arch/x86/Kconfig.debug
10368+++ b/arch/x86/Kconfig.debug
10369@@ -84,7 +84,7 @@ config X86_PTDUMP
10370 config DEBUG_RODATA
10371 bool "Write protect kernel read-only data structures"
10372 default y
10373- depends on DEBUG_KERNEL
10374+ depends on DEBUG_KERNEL && BROKEN
10375 ---help---
10376 Mark the kernel read-only data as write-protected in the pagetables,
10377 in order to catch accidental (and incorrect) writes to such const
10378@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10379
10380 config DEBUG_SET_MODULE_RONX
10381 bool "Set loadable kernel module data as NX and text as RO"
10382- depends on MODULES
10383+ depends on MODULES && BROKEN
10384 ---help---
10385 This option helps catch unintended modifications to loadable
10386 kernel module's text and read-only data. It also prevents execution
10387@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
10388
10389 config DEBUG_STRICT_USER_COPY_CHECKS
10390 bool "Strict copy size checks"
10391- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
10392+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
10393 ---help---
10394 Enabling this option turns a certain set of sanity checks for user
10395 copy operations into compile time failures.
10396diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10397index 5c47726..8c4fa67 100644
10398--- a/arch/x86/Makefile
10399+++ b/arch/x86/Makefile
10400@@ -54,6 +54,7 @@ else
10401 UTS_MACHINE := x86_64
10402 CHECKFLAGS += -D__x86_64__ -m64
10403
10404+ biarch := $(call cc-option,-m64)
10405 KBUILD_AFLAGS += -m64
10406 KBUILD_CFLAGS += -m64
10407
10408@@ -234,3 +235,12 @@ define archhelp
10409 echo ' FDARGS="..." arguments for the booted kernel'
10410 echo ' FDINITRD=file initrd for the booted kernel'
10411 endef
10412+
10413+define OLD_LD
10414+
10415+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10416+*** Please upgrade your binutils to 2.18 or newer
10417+endef
10418+
10419+archprepare:
10420+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10421diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10422index 379814b..add62ce 100644
10423--- a/arch/x86/boot/Makefile
10424+++ b/arch/x86/boot/Makefile
10425@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10426 $(call cc-option, -fno-stack-protector) \
10427 $(call cc-option, -mpreferred-stack-boundary=2)
10428 KBUILD_CFLAGS += $(call cc-option, -m32)
10429+ifdef CONSTIFY_PLUGIN
10430+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10431+endif
10432 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10433 GCOV_PROFILE := n
10434
10435diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10436index 878e4b9..20537ab 100644
10437--- a/arch/x86/boot/bitops.h
10438+++ b/arch/x86/boot/bitops.h
10439@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10440 u8 v;
10441 const u32 *p = (const u32 *)addr;
10442
10443- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10444+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10445 return v;
10446 }
10447
10448@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10449
10450 static inline void set_bit(int nr, void *addr)
10451 {
10452- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10453+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10454 }
10455
10456 #endif /* BOOT_BITOPS_H */
10457diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10458index 5b75319..331a4ca 100644
10459--- a/arch/x86/boot/boot.h
10460+++ b/arch/x86/boot/boot.h
10461@@ -85,7 +85,7 @@ static inline void io_delay(void)
10462 static inline u16 ds(void)
10463 {
10464 u16 seg;
10465- asm("movw %%ds,%0" : "=rm" (seg));
10466+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10467 return seg;
10468 }
10469
10470@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10471 static inline int memcmp(const void *s1, const void *s2, size_t len)
10472 {
10473 u8 diff;
10474- asm("repe; cmpsb; setnz %0"
10475+ asm volatile("repe; cmpsb; setnz %0"
10476 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10477 return diff;
10478 }
10479diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10480index 5ef205c..342191d 100644
10481--- a/arch/x86/boot/compressed/Makefile
10482+++ b/arch/x86/boot/compressed/Makefile
10483@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10484 KBUILD_CFLAGS += $(cflags-y)
10485 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10486 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10487+ifdef CONSTIFY_PLUGIN
10488+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10489+endif
10490
10491 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10492 GCOV_PROFILE := n
10493diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10494index c205035..5853587 100644
10495--- a/arch/x86/boot/compressed/eboot.c
10496+++ b/arch/x86/boot/compressed/eboot.c
10497@@ -150,7 +150,6 @@ again:
10498 *addr = max_addr;
10499 }
10500
10501-free_pool:
10502 efi_call_phys1(sys_table->boottime->free_pool, map);
10503
10504 fail:
10505@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10506 if (i == map_size / desc_size)
10507 status = EFI_NOT_FOUND;
10508
10509-free_pool:
10510 efi_call_phys1(sys_table->boottime->free_pool, map);
10511 fail:
10512 return status;
10513diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
10514index a53440e..c3dbf1e 100644
10515--- a/arch/x86/boot/compressed/efi_stub_32.S
10516+++ b/arch/x86/boot/compressed/efi_stub_32.S
10517@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
10518 * parameter 2, ..., param n. To make things easy, we save the return
10519 * address of efi_call_phys in a global variable.
10520 */
10521- popl %ecx
10522- movl %ecx, saved_return_addr(%edx)
10523- /* get the function pointer into ECX*/
10524- popl %ecx
10525- movl %ecx, efi_rt_function_ptr(%edx)
10526+ popl saved_return_addr(%edx)
10527+ popl efi_rt_function_ptr(%edx)
10528
10529 /*
10530 * 3. Call the physical function.
10531 */
10532- call *%ecx
10533+ call *efi_rt_function_ptr(%edx)
10534
10535 /*
10536 * 4. Balance the stack. And because EAX contain the return value,
10537@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
10538 1: popl %edx
10539 subl $1b, %edx
10540
10541- movl efi_rt_function_ptr(%edx), %ecx
10542- pushl %ecx
10543+ pushl efi_rt_function_ptr(%edx)
10544
10545 /*
10546 * 10. Push the saved return address onto the stack and return.
10547 */
10548- movl saved_return_addr(%edx), %ecx
10549- pushl %ecx
10550- ret
10551+ jmpl *saved_return_addr(%edx)
10552 ENDPROC(efi_call_phys)
10553 .previous
10554
10555diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10556index 1e3184f..0d11e2e 100644
10557--- a/arch/x86/boot/compressed/head_32.S
10558+++ b/arch/x86/boot/compressed/head_32.S
10559@@ -118,7 +118,7 @@ preferred_addr:
10560 notl %eax
10561 andl %eax, %ebx
10562 #else
10563- movl $LOAD_PHYSICAL_ADDR, %ebx
10564+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10565 #endif
10566
10567 /* Target address to relocate to for decompression */
10568@@ -204,7 +204,7 @@ relocated:
10569 * and where it was actually loaded.
10570 */
10571 movl %ebp, %ebx
10572- subl $LOAD_PHYSICAL_ADDR, %ebx
10573+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10574 jz 2f /* Nothing to be done if loaded at compiled addr. */
10575 /*
10576 * Process relocations.
10577@@ -212,8 +212,7 @@ relocated:
10578
10579 1: subl $4, %edi
10580 movl (%edi), %ecx
10581- testl %ecx, %ecx
10582- jz 2f
10583+ jecxz 2f
10584 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10585 jmp 1b
10586 2:
10587diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10588index c1d383d..57ab51c 100644
10589--- a/arch/x86/boot/compressed/head_64.S
10590+++ b/arch/x86/boot/compressed/head_64.S
10591@@ -97,7 +97,7 @@ ENTRY(startup_32)
10592 notl %eax
10593 andl %eax, %ebx
10594 #else
10595- movl $LOAD_PHYSICAL_ADDR, %ebx
10596+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10597 #endif
10598
10599 /* Target address to relocate to for decompression */
10600@@ -272,7 +272,7 @@ preferred_addr:
10601 notq %rax
10602 andq %rax, %rbp
10603 #else
10604- movq $LOAD_PHYSICAL_ADDR, %rbp
10605+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10606 #endif
10607
10608 /* Target address to relocate to for decompression */
10609@@ -363,8 +363,8 @@ gdt:
10610 .long gdt
10611 .word 0
10612 .quad 0x0000000000000000 /* NULL descriptor */
10613- .quad 0x00af9a000000ffff /* __KERNEL_CS */
10614- .quad 0x00cf92000000ffff /* __KERNEL_DS */
10615+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
10616+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
10617 .quad 0x0080890000000000 /* TS descriptor */
10618 .quad 0x0000000000000000 /* TS continued */
10619 gdt_end:
10620diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10621index 7cb56c6..d382d84 100644
10622--- a/arch/x86/boot/compressed/misc.c
10623+++ b/arch/x86/boot/compressed/misc.c
10624@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10625 case PT_LOAD:
10626 #ifdef CONFIG_RELOCATABLE
10627 dest = output;
10628- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10629+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10630 #else
10631 dest = (void *)(phdr->p_paddr);
10632 #endif
10633@@ -354,7 +354,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10634 error("Destination address too large");
10635 #endif
10636 #ifndef CONFIG_RELOCATABLE
10637- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10638+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10639 error("Wrong destination address");
10640 #endif
10641
10642diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10643index 4d3ff03..e4972ff 100644
10644--- a/arch/x86/boot/cpucheck.c
10645+++ b/arch/x86/boot/cpucheck.c
10646@@ -74,7 +74,7 @@ static int has_fpu(void)
10647 u16 fcw = -1, fsw = -1;
10648 u32 cr0;
10649
10650- asm("movl %%cr0,%0" : "=r" (cr0));
10651+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10652 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10653 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10654 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10655@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10656 {
10657 u32 f0, f1;
10658
10659- asm("pushfl ; "
10660+ asm volatile("pushfl ; "
10661 "pushfl ; "
10662 "popl %0 ; "
10663 "movl %0,%1 ; "
10664@@ -115,7 +115,7 @@ static void get_flags(void)
10665 set_bit(X86_FEATURE_FPU, cpu.flags);
10666
10667 if (has_eflag(X86_EFLAGS_ID)) {
10668- asm("cpuid"
10669+ asm volatile("cpuid"
10670 : "=a" (max_intel_level),
10671 "=b" (cpu_vendor[0]),
10672 "=d" (cpu_vendor[1]),
10673@@ -124,7 +124,7 @@ static void get_flags(void)
10674
10675 if (max_intel_level >= 0x00000001 &&
10676 max_intel_level <= 0x0000ffff) {
10677- asm("cpuid"
10678+ asm volatile("cpuid"
10679 : "=a" (tfms),
10680 "=c" (cpu.flags[4]),
10681 "=d" (cpu.flags[0])
10682@@ -136,7 +136,7 @@ static void get_flags(void)
10683 cpu.model += ((tfms >> 16) & 0xf) << 4;
10684 }
10685
10686- asm("cpuid"
10687+ asm volatile("cpuid"
10688 : "=a" (max_amd_level)
10689 : "a" (0x80000000)
10690 : "ebx", "ecx", "edx");
10691@@ -144,7 +144,7 @@ static void get_flags(void)
10692 if (max_amd_level >= 0x80000001 &&
10693 max_amd_level <= 0x8000ffff) {
10694 u32 eax = 0x80000001;
10695- asm("cpuid"
10696+ asm volatile("cpuid"
10697 : "+a" (eax),
10698 "=c" (cpu.flags[6]),
10699 "=d" (cpu.flags[1])
10700@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10701 u32 ecx = MSR_K7_HWCR;
10702 u32 eax, edx;
10703
10704- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10705+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10706 eax &= ~(1 << 15);
10707- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10708+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10709
10710 get_flags(); /* Make sure it really did something */
10711 err = check_flags();
10712@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10713 u32 ecx = MSR_VIA_FCR;
10714 u32 eax, edx;
10715
10716- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10717+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10718 eax |= (1<<1)|(1<<7);
10719- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10720+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10721
10722 set_bit(X86_FEATURE_CX8, cpu.flags);
10723 err = check_flags();
10724@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10725 u32 eax, edx;
10726 u32 level = 1;
10727
10728- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10729- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10730- asm("cpuid"
10731+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10732+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10733+ asm volatile("cpuid"
10734 : "+a" (level), "=d" (cpu.flags[0])
10735 : : "ecx", "ebx");
10736- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10737+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10738
10739 err = check_flags();
10740 }
10741diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10742index 9ec06a1..2c25e79 100644
10743--- a/arch/x86/boot/header.S
10744+++ b/arch/x86/boot/header.S
10745@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10746 # single linked list of
10747 # struct setup_data
10748
10749-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10750+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10751
10752 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10753+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10754+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10755+#else
10756 #define VO_INIT_SIZE (VO__end - VO__text)
10757+#endif
10758 #if ZO_INIT_SIZE > VO_INIT_SIZE
10759 #define INIT_SIZE ZO_INIT_SIZE
10760 #else
10761diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10762index db75d07..8e6d0af 100644
10763--- a/arch/x86/boot/memory.c
10764+++ b/arch/x86/boot/memory.c
10765@@ -19,7 +19,7 @@
10766
10767 static int detect_memory_e820(void)
10768 {
10769- int count = 0;
10770+ unsigned int count = 0;
10771 struct biosregs ireg, oreg;
10772 struct e820entry *desc = boot_params.e820_map;
10773 static struct e820entry buf; /* static so it is zeroed */
10774diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10775index 11e8c6e..fdbb1ed 100644
10776--- a/arch/x86/boot/video-vesa.c
10777+++ b/arch/x86/boot/video-vesa.c
10778@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10779
10780 boot_params.screen_info.vesapm_seg = oreg.es;
10781 boot_params.screen_info.vesapm_off = oreg.di;
10782+ boot_params.screen_info.vesapm_size = oreg.cx;
10783 }
10784
10785 /*
10786diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10787index 43eda28..5ab5fdb 100644
10788--- a/arch/x86/boot/video.c
10789+++ b/arch/x86/boot/video.c
10790@@ -96,7 +96,7 @@ static void store_mode_params(void)
10791 static unsigned int get_entry(void)
10792 {
10793 char entry_buf[4];
10794- int i, len = 0;
10795+ unsigned int i, len = 0;
10796 int key;
10797 unsigned int v;
10798
10799diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10800index 9105655..5e37f27 100644
10801--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10802+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10803@@ -8,6 +8,8 @@
10804 * including this sentence is retained in full.
10805 */
10806
10807+#include <asm/alternative-asm.h>
10808+
10809 .extern crypto_ft_tab
10810 .extern crypto_it_tab
10811 .extern crypto_fl_tab
10812@@ -70,6 +72,8 @@
10813 je B192; \
10814 leaq 32(r9),r9;
10815
10816+#define ret pax_force_retaddr 0, 1; ret
10817+
10818 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10819 movq r1,r2; \
10820 movq r3,r4; \
10821diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10822index 04b7977..402f223 100644
10823--- a/arch/x86/crypto/aesni-intel_asm.S
10824+++ b/arch/x86/crypto/aesni-intel_asm.S
10825@@ -31,6 +31,7 @@
10826
10827 #include <linux/linkage.h>
10828 #include <asm/inst.h>
10829+#include <asm/alternative-asm.h>
10830
10831 #ifdef __x86_64__
10832 .data
10833@@ -1435,6 +1436,7 @@ _return_T_done_decrypt:
10834 pop %r14
10835 pop %r13
10836 pop %r12
10837+ pax_force_retaddr 0, 1
10838 ret
10839 ENDPROC(aesni_gcm_dec)
10840
10841@@ -1699,6 +1701,7 @@ _return_T_done_encrypt:
10842 pop %r14
10843 pop %r13
10844 pop %r12
10845+ pax_force_retaddr 0, 1
10846 ret
10847 ENDPROC(aesni_gcm_enc)
10848
10849@@ -1716,6 +1719,7 @@ _key_expansion_256a:
10850 pxor %xmm1, %xmm0
10851 movaps %xmm0, (TKEYP)
10852 add $0x10, TKEYP
10853+ pax_force_retaddr_bts
10854 ret
10855 ENDPROC(_key_expansion_128)
10856 ENDPROC(_key_expansion_256a)
10857@@ -1742,6 +1746,7 @@ _key_expansion_192a:
10858 shufps $0b01001110, %xmm2, %xmm1
10859 movaps %xmm1, 0x10(TKEYP)
10860 add $0x20, TKEYP
10861+ pax_force_retaddr_bts
10862 ret
10863 ENDPROC(_key_expansion_192a)
10864
10865@@ -1762,6 +1767,7 @@ _key_expansion_192b:
10866
10867 movaps %xmm0, (TKEYP)
10868 add $0x10, TKEYP
10869+ pax_force_retaddr_bts
10870 ret
10871 ENDPROC(_key_expansion_192b)
10872
10873@@ -1775,6 +1781,7 @@ _key_expansion_256b:
10874 pxor %xmm1, %xmm2
10875 movaps %xmm2, (TKEYP)
10876 add $0x10, TKEYP
10877+ pax_force_retaddr_bts
10878 ret
10879 ENDPROC(_key_expansion_256b)
10880
10881@@ -1888,6 +1895,7 @@ ENTRY(aesni_set_key)
10882 #ifndef __x86_64__
10883 popl KEYP
10884 #endif
10885+ pax_force_retaddr 0, 1
10886 ret
10887 ENDPROC(aesni_set_key)
10888
10889@@ -1910,6 +1918,7 @@ ENTRY(aesni_enc)
10890 popl KLEN
10891 popl KEYP
10892 #endif
10893+ pax_force_retaddr 0, 1
10894 ret
10895 ENDPROC(aesni_enc)
10896
10897@@ -1968,6 +1977,7 @@ _aesni_enc1:
10898 AESENC KEY STATE
10899 movaps 0x70(TKEYP), KEY
10900 AESENCLAST KEY STATE
10901+ pax_force_retaddr_bts
10902 ret
10903 ENDPROC(_aesni_enc1)
10904
10905@@ -2077,6 +2087,7 @@ _aesni_enc4:
10906 AESENCLAST KEY STATE2
10907 AESENCLAST KEY STATE3
10908 AESENCLAST KEY STATE4
10909+ pax_force_retaddr_bts
10910 ret
10911 ENDPROC(_aesni_enc4)
10912
10913@@ -2100,6 +2111,7 @@ ENTRY(aesni_dec)
10914 popl KLEN
10915 popl KEYP
10916 #endif
10917+ pax_force_retaddr 0, 1
10918 ret
10919 ENDPROC(aesni_dec)
10920
10921@@ -2158,6 +2170,7 @@ _aesni_dec1:
10922 AESDEC KEY STATE
10923 movaps 0x70(TKEYP), KEY
10924 AESDECLAST KEY STATE
10925+ pax_force_retaddr_bts
10926 ret
10927 ENDPROC(_aesni_dec1)
10928
10929@@ -2267,6 +2280,7 @@ _aesni_dec4:
10930 AESDECLAST KEY STATE2
10931 AESDECLAST KEY STATE3
10932 AESDECLAST KEY STATE4
10933+ pax_force_retaddr_bts
10934 ret
10935 ENDPROC(_aesni_dec4)
10936
10937@@ -2325,6 +2339,7 @@ ENTRY(aesni_ecb_enc)
10938 popl KEYP
10939 popl LEN
10940 #endif
10941+ pax_force_retaddr 0, 1
10942 ret
10943 ENDPROC(aesni_ecb_enc)
10944
10945@@ -2384,6 +2399,7 @@ ENTRY(aesni_ecb_dec)
10946 popl KEYP
10947 popl LEN
10948 #endif
10949+ pax_force_retaddr 0, 1
10950 ret
10951 ENDPROC(aesni_ecb_dec)
10952
10953@@ -2426,6 +2442,7 @@ ENTRY(aesni_cbc_enc)
10954 popl LEN
10955 popl IVP
10956 #endif
10957+ pax_force_retaddr 0, 1
10958 ret
10959 ENDPROC(aesni_cbc_enc)
10960
10961@@ -2517,6 +2534,7 @@ ENTRY(aesni_cbc_dec)
10962 popl LEN
10963 popl IVP
10964 #endif
10965+ pax_force_retaddr 0, 1
10966 ret
10967 ENDPROC(aesni_cbc_dec)
10968
10969@@ -2544,6 +2562,7 @@ _aesni_inc_init:
10970 mov $1, TCTR_LOW
10971 MOVQ_R64_XMM TCTR_LOW INC
10972 MOVQ_R64_XMM CTR TCTR_LOW
10973+ pax_force_retaddr_bts
10974 ret
10975 ENDPROC(_aesni_inc_init)
10976
10977@@ -2573,6 +2592,7 @@ _aesni_inc:
10978 .Linc_low:
10979 movaps CTR, IV
10980 PSHUFB_XMM BSWAP_MASK IV
10981+ pax_force_retaddr_bts
10982 ret
10983 ENDPROC(_aesni_inc)
10984
10985@@ -2634,6 +2654,7 @@ ENTRY(aesni_ctr_enc)
10986 .Lctr_enc_ret:
10987 movups IV, (IVP)
10988 .Lctr_enc_just_ret:
10989+ pax_force_retaddr 0, 1
10990 ret
10991 ENDPROC(aesni_ctr_enc)
10992 #endif
10993diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10994index 246c670..4d1ed00 100644
10995--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10996+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10997@@ -21,6 +21,7 @@
10998 */
10999
11000 #include <linux/linkage.h>
11001+#include <asm/alternative-asm.h>
11002
11003 .file "blowfish-x86_64-asm.S"
11004 .text
11005@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
11006 jnz .L__enc_xor;
11007
11008 write_block();
11009+ pax_force_retaddr 0, 1
11010 ret;
11011 .L__enc_xor:
11012 xor_block();
11013+ pax_force_retaddr 0, 1
11014 ret;
11015 ENDPROC(__blowfish_enc_blk)
11016
11017@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
11018
11019 movq %r11, %rbp;
11020
11021+ pax_force_retaddr 0, 1
11022 ret;
11023 ENDPROC(blowfish_dec_blk)
11024
11025@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
11026
11027 popq %rbx;
11028 popq %rbp;
11029+ pax_force_retaddr 0, 1
11030 ret;
11031
11032 .L__enc_xor4:
11033@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
11034
11035 popq %rbx;
11036 popq %rbp;
11037+ pax_force_retaddr 0, 1
11038 ret;
11039 ENDPROC(__blowfish_enc_blk_4way)
11040
11041@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
11042 popq %rbx;
11043 popq %rbp;
11044
11045+ pax_force_retaddr 0, 1
11046 ret;
11047 ENDPROC(blowfish_dec_blk_4way)
11048diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
11049index 310319c..ce174a4 100644
11050--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
11051+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
11052@@ -21,6 +21,7 @@
11053 */
11054
11055 #include <linux/linkage.h>
11056+#include <asm/alternative-asm.h>
11057
11058 .file "camellia-x86_64-asm_64.S"
11059 .text
11060@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
11061 enc_outunpack(mov, RT1);
11062
11063 movq RRBP, %rbp;
11064+ pax_force_retaddr 0, 1
11065 ret;
11066
11067 .L__enc_xor:
11068 enc_outunpack(xor, RT1);
11069
11070 movq RRBP, %rbp;
11071+ pax_force_retaddr 0, 1
11072 ret;
11073 ENDPROC(__camellia_enc_blk)
11074
11075@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
11076 dec_outunpack();
11077
11078 movq RRBP, %rbp;
11079+ pax_force_retaddr 0, 1
11080 ret;
11081 ENDPROC(camellia_dec_blk)
11082
11083@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
11084
11085 movq RRBP, %rbp;
11086 popq %rbx;
11087+ pax_force_retaddr 0, 1
11088 ret;
11089
11090 .L__enc2_xor:
11091@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
11092
11093 movq RRBP, %rbp;
11094 popq %rbx;
11095+ pax_force_retaddr 0, 1
11096 ret;
11097 ENDPROC(__camellia_enc_blk_2way)
11098
11099@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
11100
11101 movq RRBP, %rbp;
11102 movq RXOR, %rbx;
11103+ pax_force_retaddr 0, 1
11104 ret;
11105 ENDPROC(camellia_dec_blk_2way)
11106diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11107index c35fd5d..c1ee236 100644
11108--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11109+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11110@@ -24,6 +24,7 @@
11111 */
11112
11113 #include <linux/linkage.h>
11114+#include <asm/alternative-asm.h>
11115
11116 .file "cast5-avx-x86_64-asm_64.S"
11117
11118@@ -281,6 +282,7 @@ __cast5_enc_blk16:
11119 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11120 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11121
11122+ pax_force_retaddr 0, 1
11123 ret;
11124 ENDPROC(__cast5_enc_blk16)
11125
11126@@ -352,6 +354,7 @@ __cast5_dec_blk16:
11127 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11128 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11129
11130+ pax_force_retaddr 0, 1
11131 ret;
11132
11133 .L__skip_dec:
11134@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
11135 vmovdqu RR4, (6*4*4)(%r11);
11136 vmovdqu RL4, (7*4*4)(%r11);
11137
11138+ pax_force_retaddr
11139 ret;
11140 ENDPROC(cast5_ecb_enc_16way)
11141
11142@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
11143 vmovdqu RR4, (6*4*4)(%r11);
11144 vmovdqu RL4, (7*4*4)(%r11);
11145
11146+ pax_force_retaddr
11147 ret;
11148 ENDPROC(cast5_ecb_dec_16way)
11149
11150@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
11151
11152 popq %r12;
11153
11154+ pax_force_retaddr
11155 ret;
11156 ENDPROC(cast5_cbc_dec_16way)
11157
11158@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
11159
11160 popq %r12;
11161
11162+ pax_force_retaddr
11163 ret;
11164 ENDPROC(cast5_ctr_16way)
11165diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11166index f93b610..c09bf40 100644
11167--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11168+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11169@@ -24,6 +24,7 @@
11170 */
11171
11172 #include <linux/linkage.h>
11173+#include <asm/alternative-asm.h>
11174 #include "glue_helper-asm-avx.S"
11175
11176 .file "cast6-avx-x86_64-asm_64.S"
11177@@ -293,6 +294,7 @@ __cast6_enc_blk8:
11178 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11179 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11180
11181+ pax_force_retaddr 0, 1
11182 ret;
11183 ENDPROC(__cast6_enc_blk8)
11184
11185@@ -338,6 +340,7 @@ __cast6_dec_blk8:
11186 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11187 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11188
11189+ pax_force_retaddr 0, 1
11190 ret;
11191 ENDPROC(__cast6_dec_blk8)
11192
11193@@ -356,6 +359,7 @@ ENTRY(cast6_ecb_enc_8way)
11194
11195 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11196
11197+ pax_force_retaddr
11198 ret;
11199 ENDPROC(cast6_ecb_enc_8way)
11200
11201@@ -374,6 +378,7 @@ ENTRY(cast6_ecb_dec_8way)
11202
11203 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11204
11205+ pax_force_retaddr
11206 ret;
11207 ENDPROC(cast6_ecb_dec_8way)
11208
11209@@ -397,6 +402,7 @@ ENTRY(cast6_cbc_dec_8way)
11210
11211 popq %r12;
11212
11213+ pax_force_retaddr
11214 ret;
11215 ENDPROC(cast6_cbc_dec_8way)
11216
11217@@ -422,5 +428,6 @@ ENTRY(cast6_ctr_8way)
11218
11219 popq %r12;
11220
11221+ pax_force_retaddr
11222 ret;
11223 ENDPROC(cast6_ctr_8way)
11224diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11225index 9279e0b..9270820 100644
11226--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11227+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11228@@ -1,4 +1,5 @@
11229 #include <linux/linkage.h>
11230+#include <asm/alternative-asm.h>
11231
11232 # enter salsa20_encrypt_bytes
11233 ENTRY(salsa20_encrypt_bytes)
11234@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
11235 add %r11,%rsp
11236 mov %rdi,%rax
11237 mov %rsi,%rdx
11238+ pax_force_retaddr 0, 1
11239 ret
11240 # bytesatleast65:
11241 ._bytesatleast65:
11242@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
11243 add %r11,%rsp
11244 mov %rdi,%rax
11245 mov %rsi,%rdx
11246+ pax_force_retaddr
11247 ret
11248 ENDPROC(salsa20_keysetup)
11249
11250@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
11251 add %r11,%rsp
11252 mov %rdi,%rax
11253 mov %rsi,%rdx
11254+ pax_force_retaddr
11255 ret
11256 ENDPROC(salsa20_ivsetup)
11257diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11258index 43c9386..a0e2d60 100644
11259--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11260+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11261@@ -25,6 +25,7 @@
11262 */
11263
11264 #include <linux/linkage.h>
11265+#include <asm/alternative-asm.h>
11266 #include "glue_helper-asm-avx.S"
11267
11268 .file "serpent-avx-x86_64-asm_64.S"
11269@@ -617,6 +618,7 @@ __serpent_enc_blk8_avx:
11270 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11271 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11272
11273+ pax_force_retaddr
11274 ret;
11275 ENDPROC(__serpent_enc_blk8_avx)
11276
11277@@ -671,6 +673,7 @@ __serpent_dec_blk8_avx:
11278 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11279 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11280
11281+ pax_force_retaddr
11282 ret;
11283 ENDPROC(__serpent_dec_blk8_avx)
11284
11285@@ -687,6 +690,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
11286
11287 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11288
11289+ pax_force_retaddr
11290 ret;
11291 ENDPROC(serpent_ecb_enc_8way_avx)
11292
11293@@ -703,6 +707,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
11294
11295 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11296
11297+ pax_force_retaddr
11298 ret;
11299 ENDPROC(serpent_ecb_dec_8way_avx)
11300
11301@@ -719,6 +724,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
11302
11303 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11304
11305+ pax_force_retaddr
11306 ret;
11307 ENDPROC(serpent_cbc_dec_8way_avx)
11308
11309@@ -737,5 +743,6 @@ ENTRY(serpent_ctr_8way_avx)
11310
11311 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11312
11313+ pax_force_retaddr
11314 ret;
11315 ENDPROC(serpent_ctr_8way_avx)
11316diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11317index acc066c..1559cc4 100644
11318--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11319+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11320@@ -25,6 +25,7 @@
11321 */
11322
11323 #include <linux/linkage.h>
11324+#include <asm/alternative-asm.h>
11325
11326 .file "serpent-sse2-x86_64-asm_64.S"
11327 .text
11328@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
11329 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11330 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11331
11332+ pax_force_retaddr
11333 ret;
11334
11335 .L__enc_xor8:
11336 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11337 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11338
11339+ pax_force_retaddr
11340 ret;
11341 ENDPROC(__serpent_enc_blk_8way)
11342
11343@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
11344 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11345 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11346
11347+ pax_force_retaddr
11348 ret;
11349 ENDPROC(serpent_dec_blk_8way)
11350diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11351index a410950..3356d42 100644
11352--- a/arch/x86/crypto/sha1_ssse3_asm.S
11353+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11354@@ -29,6 +29,7 @@
11355 */
11356
11357 #include <linux/linkage.h>
11358+#include <asm/alternative-asm.h>
11359
11360 #define CTX %rdi // arg1
11361 #define BUF %rsi // arg2
11362@@ -104,6 +105,7 @@
11363 pop %r12
11364 pop %rbp
11365 pop %rbx
11366+ pax_force_retaddr 0, 1
11367 ret
11368
11369 ENDPROC(\name)
11370diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11371index 8d3e113..898b161 100644
11372--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11373+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11374@@ -24,6 +24,7 @@
11375 */
11376
11377 #include <linux/linkage.h>
11378+#include <asm/alternative-asm.h>
11379 #include "glue_helper-asm-avx.S"
11380
11381 .file "twofish-avx-x86_64-asm_64.S"
11382@@ -282,6 +283,7 @@ __twofish_enc_blk8:
11383 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11384 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11385
11386+ pax_force_retaddr 0, 1
11387 ret;
11388 ENDPROC(__twofish_enc_blk8)
11389
11390@@ -322,6 +324,7 @@ __twofish_dec_blk8:
11391 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11392 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11393
11394+ pax_force_retaddr 0, 1
11395 ret;
11396 ENDPROC(__twofish_dec_blk8)
11397
11398@@ -340,6 +343,7 @@ ENTRY(twofish_ecb_enc_8way)
11399
11400 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11401
11402+ pax_force_retaddr 0, 1
11403 ret;
11404 ENDPROC(twofish_ecb_enc_8way)
11405
11406@@ -358,6 +362,7 @@ ENTRY(twofish_ecb_dec_8way)
11407
11408 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11409
11410+ pax_force_retaddr 0, 1
11411 ret;
11412 ENDPROC(twofish_ecb_dec_8way)
11413
11414@@ -381,6 +386,7 @@ ENTRY(twofish_cbc_dec_8way)
11415
11416 popq %r12;
11417
11418+ pax_force_retaddr 0, 1
11419 ret;
11420 ENDPROC(twofish_cbc_dec_8way)
11421
11422@@ -406,5 +412,6 @@ ENTRY(twofish_ctr_8way)
11423
11424 popq %r12;
11425
11426+ pax_force_retaddr 0, 1
11427 ret;
11428 ENDPROC(twofish_ctr_8way)
11429diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11430index 1c3b7ce..b365c5e 100644
11431--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11432+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11433@@ -21,6 +21,7 @@
11434 */
11435
11436 #include <linux/linkage.h>
11437+#include <asm/alternative-asm.h>
11438
11439 .file "twofish-x86_64-asm-3way.S"
11440 .text
11441@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
11442 popq %r13;
11443 popq %r14;
11444 popq %r15;
11445+ pax_force_retaddr 0, 1
11446 ret;
11447
11448 .L__enc_xor3:
11449@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
11450 popq %r13;
11451 popq %r14;
11452 popq %r15;
11453+ pax_force_retaddr 0, 1
11454 ret;
11455 ENDPROC(__twofish_enc_blk_3way)
11456
11457@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
11458 popq %r13;
11459 popq %r14;
11460 popq %r15;
11461+ pax_force_retaddr 0, 1
11462 ret;
11463 ENDPROC(twofish_dec_blk_3way)
11464diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11465index a039d21..29e7615 100644
11466--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11467+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11468@@ -22,6 +22,7 @@
11469
11470 #include <linux/linkage.h>
11471 #include <asm/asm-offsets.h>
11472+#include <asm/alternative-asm.h>
11473
11474 #define a_offset 0
11475 #define b_offset 4
11476@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
11477
11478 popq R1
11479 movq $1,%rax
11480+ pax_force_retaddr 0, 1
11481 ret
11482 ENDPROC(twofish_enc_blk)
11483
11484@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
11485
11486 popq R1
11487 movq $1,%rax
11488+ pax_force_retaddr 0, 1
11489 ret
11490 ENDPROC(twofish_dec_blk)
11491diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11492index 03abf9b..a42ba29 100644
11493--- a/arch/x86/ia32/ia32_aout.c
11494+++ b/arch/x86/ia32/ia32_aout.c
11495@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11496 unsigned long dump_start, dump_size;
11497 struct user32 dump;
11498
11499+ memset(&dump, 0, sizeof(dump));
11500+
11501 fs = get_fs();
11502 set_fs(KERNEL_DS);
11503 has_dumped = 1;
11504diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11505index cf1a471..3bc4cf8 100644
11506--- a/arch/x86/ia32/ia32_signal.c
11507+++ b/arch/x86/ia32/ia32_signal.c
11508@@ -340,7 +340,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
11509 sp -= frame_size;
11510 /* Align the stack pointer according to the i386 ABI,
11511 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11512- sp = ((sp + 4) & -16ul) - 4;
11513+ sp = ((sp - 12) & -16ul) - 4;
11514 return (void __user *) sp;
11515 }
11516
11517@@ -398,7 +398,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
11518 * These are actually not used anymore, but left because some
11519 * gdb versions depend on them as a marker.
11520 */
11521- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11522+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11523 } put_user_catch(err);
11524
11525 if (err)
11526@@ -440,7 +440,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11527 0xb8,
11528 __NR_ia32_rt_sigreturn,
11529 0x80cd,
11530- 0,
11531+ 0
11532 };
11533
11534 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
11535@@ -463,16 +463,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11536
11537 if (ksig->ka.sa.sa_flags & SA_RESTORER)
11538 restorer = ksig->ka.sa.sa_restorer;
11539+ else if (current->mm->context.vdso)
11540+ /* Return stub is in 32bit vsyscall page */
11541+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11542 else
11543- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11544- rt_sigreturn);
11545+ restorer = &frame->retcode;
11546 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11547
11548 /*
11549 * Not actually used anymore, but left because some gdb
11550 * versions need it.
11551 */
11552- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11553+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11554 } put_user_catch(err);
11555
11556 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
11557diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11558index 474dc1b..24aaa3e 100644
11559--- a/arch/x86/ia32/ia32entry.S
11560+++ b/arch/x86/ia32/ia32entry.S
11561@@ -15,8 +15,10 @@
11562 #include <asm/irqflags.h>
11563 #include <asm/asm.h>
11564 #include <asm/smap.h>
11565+#include <asm/pgtable.h>
11566 #include <linux/linkage.h>
11567 #include <linux/err.h>
11568+#include <asm/alternative-asm.h>
11569
11570 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11571 #include <linux/elf-em.h>
11572@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11573 ENDPROC(native_irq_enable_sysexit)
11574 #endif
11575
11576+ .macro pax_enter_kernel_user
11577+ pax_set_fptr_mask
11578+#ifdef CONFIG_PAX_MEMORY_UDEREF
11579+ call pax_enter_kernel_user
11580+#endif
11581+ .endm
11582+
11583+ .macro pax_exit_kernel_user
11584+#ifdef CONFIG_PAX_MEMORY_UDEREF
11585+ call pax_exit_kernel_user
11586+#endif
11587+#ifdef CONFIG_PAX_RANDKSTACK
11588+ pushq %rax
11589+ pushq %r11
11590+ call pax_randomize_kstack
11591+ popq %r11
11592+ popq %rax
11593+#endif
11594+ .endm
11595+
11596+ .macro pax_erase_kstack
11597+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11598+ call pax_erase_kstack
11599+#endif
11600+ .endm
11601+
11602 /*
11603 * 32bit SYSENTER instruction entry.
11604 *
11605@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11606 CFI_REGISTER rsp,rbp
11607 SWAPGS_UNSAFE_STACK
11608 movq PER_CPU_VAR(kernel_stack), %rsp
11609- addq $(KERNEL_STACK_OFFSET),%rsp
11610- /*
11611- * No need to follow this irqs on/off section: the syscall
11612- * disabled irqs, here we enable it straight after entry:
11613- */
11614- ENABLE_INTERRUPTS(CLBR_NONE)
11615 movl %ebp,%ebp /* zero extension */
11616 pushq_cfi $__USER32_DS
11617 /*CFI_REL_OFFSET ss,0*/
11618@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11619 CFI_REL_OFFSET rsp,0
11620 pushfq_cfi
11621 /*CFI_REL_OFFSET rflags,0*/
11622- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11623- CFI_REGISTER rip,r10
11624+ orl $X86_EFLAGS_IF,(%rsp)
11625+ GET_THREAD_INFO(%r11)
11626+ movl TI_sysenter_return(%r11), %r11d
11627+ CFI_REGISTER rip,r11
11628 pushq_cfi $__USER32_CS
11629 /*CFI_REL_OFFSET cs,0*/
11630 movl %eax, %eax
11631- pushq_cfi %r10
11632+ pushq_cfi %r11
11633 CFI_REL_OFFSET rip,0
11634 pushq_cfi %rax
11635 cld
11636 SAVE_ARGS 0,1,0
11637+ pax_enter_kernel_user
11638+
11639+#ifdef CONFIG_PAX_RANDKSTACK
11640+ pax_erase_kstack
11641+#endif
11642+
11643+ /*
11644+ * No need to follow this irqs on/off section: the syscall
11645+ * disabled irqs, here we enable it straight after entry:
11646+ */
11647+ ENABLE_INTERRUPTS(CLBR_NONE)
11648 /* no need to do an access_ok check here because rbp has been
11649 32bit zero extended */
11650+
11651+#ifdef CONFIG_PAX_MEMORY_UDEREF
11652+ mov pax_user_shadow_base,%r11
11653+ add %r11,%rbp
11654+#endif
11655+
11656 ASM_STAC
11657 1: movl (%rbp),%ebp
11658 _ASM_EXTABLE(1b,ia32_badarg)
11659 ASM_CLAC
11660- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11661- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11662+ GET_THREAD_INFO(%r11)
11663+ orl $TS_COMPAT,TI_status(%r11)
11664+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11665 CFI_REMEMBER_STATE
11666 jnz sysenter_tracesys
11667 cmpq $(IA32_NR_syscalls-1),%rax
11668@@ -162,12 +204,15 @@ sysenter_do_call:
11669 sysenter_dispatch:
11670 call *ia32_sys_call_table(,%rax,8)
11671 movq %rax,RAX-ARGOFFSET(%rsp)
11672+ GET_THREAD_INFO(%r11)
11673 DISABLE_INTERRUPTS(CLBR_NONE)
11674 TRACE_IRQS_OFF
11675- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11676+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11677 jnz sysexit_audit
11678 sysexit_from_sys_call:
11679- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11680+ pax_exit_kernel_user
11681+ pax_erase_kstack
11682+ andl $~TS_COMPAT,TI_status(%r11)
11683 /* clear IF, that popfq doesn't enable interrupts early */
11684 andl $~0x200,EFLAGS-R11(%rsp)
11685 movl RIP-R11(%rsp),%edx /* User %eip */
11686@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11687 movl %eax,%esi /* 2nd arg: syscall number */
11688 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11689 call __audit_syscall_entry
11690+
11691+ pax_erase_kstack
11692+
11693 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11694 cmpq $(IA32_NR_syscalls-1),%rax
11695 ja ia32_badsys
11696@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11697 .endm
11698
11699 .macro auditsys_exit exit
11700- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11701+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11702 jnz ia32_ret_from_sys_call
11703 TRACE_IRQS_ON
11704 ENABLE_INTERRUPTS(CLBR_NONE)
11705@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11706 1: setbe %al /* 1 if error, 0 if not */
11707 movzbl %al,%edi /* zero-extend that into %edi */
11708 call __audit_syscall_exit
11709+ GET_THREAD_INFO(%r11)
11710 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11711 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11712 DISABLE_INTERRUPTS(CLBR_NONE)
11713 TRACE_IRQS_OFF
11714- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11715+ testl %edi,TI_flags(%r11)
11716 jz \exit
11717 CLEAR_RREGS -ARGOFFSET
11718 jmp int_with_check
11719@@ -237,7 +286,7 @@ sysexit_audit:
11720
11721 sysenter_tracesys:
11722 #ifdef CONFIG_AUDITSYSCALL
11723- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11724+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11725 jz sysenter_auditsys
11726 #endif
11727 SAVE_REST
11728@@ -249,6 +298,9 @@ sysenter_tracesys:
11729 RESTORE_REST
11730 cmpq $(IA32_NR_syscalls-1),%rax
11731 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11732+
11733+ pax_erase_kstack
11734+
11735 jmp sysenter_do_call
11736 CFI_ENDPROC
11737 ENDPROC(ia32_sysenter_target)
11738@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11739 ENTRY(ia32_cstar_target)
11740 CFI_STARTPROC32 simple
11741 CFI_SIGNAL_FRAME
11742- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11743+ CFI_DEF_CFA rsp,0
11744 CFI_REGISTER rip,rcx
11745 /*CFI_REGISTER rflags,r11*/
11746 SWAPGS_UNSAFE_STACK
11747 movl %esp,%r8d
11748 CFI_REGISTER rsp,r8
11749 movq PER_CPU_VAR(kernel_stack),%rsp
11750+ SAVE_ARGS 8*6,0,0
11751+ pax_enter_kernel_user
11752+
11753+#ifdef CONFIG_PAX_RANDKSTACK
11754+ pax_erase_kstack
11755+#endif
11756+
11757 /*
11758 * No need to follow this irqs on/off section: the syscall
11759 * disabled irqs and here we enable it straight after entry:
11760 */
11761 ENABLE_INTERRUPTS(CLBR_NONE)
11762- SAVE_ARGS 8,0,0
11763 movl %eax,%eax /* zero extension */
11764 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11765 movq %rcx,RIP-ARGOFFSET(%rsp)
11766@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11767 /* no need to do an access_ok check here because r8 has been
11768 32bit zero extended */
11769 /* hardware stack frame is complete now */
11770+
11771+#ifdef CONFIG_PAX_MEMORY_UDEREF
11772+ mov pax_user_shadow_base,%r11
11773+ add %r11,%r8
11774+#endif
11775+
11776 ASM_STAC
11777 1: movl (%r8),%r9d
11778 _ASM_EXTABLE(1b,ia32_badarg)
11779 ASM_CLAC
11780- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11781- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11782+ GET_THREAD_INFO(%r11)
11783+ orl $TS_COMPAT,TI_status(%r11)
11784+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11785 CFI_REMEMBER_STATE
11786 jnz cstar_tracesys
11787 cmpq $IA32_NR_syscalls-1,%rax
11788@@ -319,12 +384,15 @@ cstar_do_call:
11789 cstar_dispatch:
11790 call *ia32_sys_call_table(,%rax,8)
11791 movq %rax,RAX-ARGOFFSET(%rsp)
11792+ GET_THREAD_INFO(%r11)
11793 DISABLE_INTERRUPTS(CLBR_NONE)
11794 TRACE_IRQS_OFF
11795- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11796+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11797 jnz sysretl_audit
11798 sysretl_from_sys_call:
11799- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11800+ pax_exit_kernel_user
11801+ pax_erase_kstack
11802+ andl $~TS_COMPAT,TI_status(%r11)
11803 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11804 movl RIP-ARGOFFSET(%rsp),%ecx
11805 CFI_REGISTER rip,rcx
11806@@ -352,7 +420,7 @@ sysretl_audit:
11807
11808 cstar_tracesys:
11809 #ifdef CONFIG_AUDITSYSCALL
11810- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11811+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11812 jz cstar_auditsys
11813 #endif
11814 xchgl %r9d,%ebp
11815@@ -366,6 +434,9 @@ cstar_tracesys:
11816 xchgl %ebp,%r9d
11817 cmpq $(IA32_NR_syscalls-1),%rax
11818 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11819+
11820+ pax_erase_kstack
11821+
11822 jmp cstar_do_call
11823 END(ia32_cstar_target)
11824
11825@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11826 CFI_REL_OFFSET rip,RIP-RIP
11827 PARAVIRT_ADJUST_EXCEPTION_FRAME
11828 SWAPGS
11829- /*
11830- * No need to follow this irqs on/off section: the syscall
11831- * disabled irqs and here we enable it straight after entry:
11832- */
11833- ENABLE_INTERRUPTS(CLBR_NONE)
11834 movl %eax,%eax
11835 pushq_cfi %rax
11836 cld
11837 /* note the registers are not zero extended to the sf.
11838 this could be a problem. */
11839 SAVE_ARGS 0,1,0
11840- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11841- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11842+ pax_enter_kernel_user
11843+
11844+#ifdef CONFIG_PAX_RANDKSTACK
11845+ pax_erase_kstack
11846+#endif
11847+
11848+ /*
11849+ * No need to follow this irqs on/off section: the syscall
11850+ * disabled irqs and here we enable it straight after entry:
11851+ */
11852+ ENABLE_INTERRUPTS(CLBR_NONE)
11853+ GET_THREAD_INFO(%r11)
11854+ orl $TS_COMPAT,TI_status(%r11)
11855+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11856 jnz ia32_tracesys
11857 cmpq $(IA32_NR_syscalls-1),%rax
11858 ja ia32_badsys
11859@@ -442,6 +520,9 @@ ia32_tracesys:
11860 RESTORE_REST
11861 cmpq $(IA32_NR_syscalls-1),%rax
11862 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11863+
11864+ pax_erase_kstack
11865+
11866 jmp ia32_do_call
11867 END(ia32_syscall)
11868
11869diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11870index ad7a20c..1ffa3c1 100644
11871--- a/arch/x86/ia32/sys_ia32.c
11872+++ b/arch/x86/ia32/sys_ia32.c
11873@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11874 */
11875 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11876 {
11877- typeof(ubuf->st_uid) uid = 0;
11878- typeof(ubuf->st_gid) gid = 0;
11879+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11880+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11881 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11882 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11883 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11884@@ -205,7 +205,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11885 return -EFAULT;
11886
11887 set_fs(KERNEL_DS);
11888- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11889+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11890 count);
11891 set_fs(old_fs);
11892
11893diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11894index 372231c..a5aa1a1 100644
11895--- a/arch/x86/include/asm/alternative-asm.h
11896+++ b/arch/x86/include/asm/alternative-asm.h
11897@@ -18,6 +18,45 @@
11898 .endm
11899 #endif
11900
11901+#ifdef KERNEXEC_PLUGIN
11902+ .macro pax_force_retaddr_bts rip=0
11903+ btsq $63,\rip(%rsp)
11904+ .endm
11905+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11906+ .macro pax_force_retaddr rip=0, reload=0
11907+ btsq $63,\rip(%rsp)
11908+ .endm
11909+ .macro pax_force_fptr ptr
11910+ btsq $63,\ptr
11911+ .endm
11912+ .macro pax_set_fptr_mask
11913+ .endm
11914+#endif
11915+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11916+ .macro pax_force_retaddr rip=0, reload=0
11917+ .if \reload
11918+ pax_set_fptr_mask
11919+ .endif
11920+ orq %r10,\rip(%rsp)
11921+ .endm
11922+ .macro pax_force_fptr ptr
11923+ orq %r10,\ptr
11924+ .endm
11925+ .macro pax_set_fptr_mask
11926+ movabs $0x8000000000000000,%r10
11927+ .endm
11928+#endif
11929+#else
11930+ .macro pax_force_retaddr rip=0, reload=0
11931+ .endm
11932+ .macro pax_force_fptr ptr
11933+ .endm
11934+ .macro pax_force_retaddr_bts rip=0
11935+ .endm
11936+ .macro pax_set_fptr_mask
11937+ .endm
11938+#endif
11939+
11940 .macro altinstruction_entry orig alt feature orig_len alt_len
11941 .long \orig - .
11942 .long \alt - .
11943diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11944index 58ed6d9..f1cbe58 100644
11945--- a/arch/x86/include/asm/alternative.h
11946+++ b/arch/x86/include/asm/alternative.h
11947@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11948 ".pushsection .discard,\"aw\",@progbits\n" \
11949 DISCARD_ENTRY(1) \
11950 ".popsection\n" \
11951- ".pushsection .altinstr_replacement, \"ax\"\n" \
11952+ ".pushsection .altinstr_replacement, \"a\"\n" \
11953 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11954 ".popsection"
11955
11956@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11957 DISCARD_ENTRY(1) \
11958 DISCARD_ENTRY(2) \
11959 ".popsection\n" \
11960- ".pushsection .altinstr_replacement, \"ax\"\n" \
11961+ ".pushsection .altinstr_replacement, \"a\"\n" \
11962 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11963 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11964 ".popsection"
11965diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11966index 3388034..050f0b9 100644
11967--- a/arch/x86/include/asm/apic.h
11968+++ b/arch/x86/include/asm/apic.h
11969@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11970
11971 #ifdef CONFIG_X86_LOCAL_APIC
11972
11973-extern unsigned int apic_verbosity;
11974+extern int apic_verbosity;
11975 extern int local_apic_timer_c2_ok;
11976
11977 extern int disable_apic;
11978diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11979index 20370c6..a2eb9b0 100644
11980--- a/arch/x86/include/asm/apm.h
11981+++ b/arch/x86/include/asm/apm.h
11982@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11983 __asm__ __volatile__(APM_DO_ZERO_SEGS
11984 "pushl %%edi\n\t"
11985 "pushl %%ebp\n\t"
11986- "lcall *%%cs:apm_bios_entry\n\t"
11987+ "lcall *%%ss:apm_bios_entry\n\t"
11988 "setc %%al\n\t"
11989 "popl %%ebp\n\t"
11990 "popl %%edi\n\t"
11991@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11992 __asm__ __volatile__(APM_DO_ZERO_SEGS
11993 "pushl %%edi\n\t"
11994 "pushl %%ebp\n\t"
11995- "lcall *%%cs:apm_bios_entry\n\t"
11996+ "lcall *%%ss:apm_bios_entry\n\t"
11997 "setc %%bl\n\t"
11998 "popl %%ebp\n\t"
11999 "popl %%edi\n\t"
12000diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
12001index 722aa3b..3a0bb27 100644
12002--- a/arch/x86/include/asm/atomic.h
12003+++ b/arch/x86/include/asm/atomic.h
12004@@ -22,7 +22,18 @@
12005 */
12006 static inline int atomic_read(const atomic_t *v)
12007 {
12008- return (*(volatile int *)&(v)->counter);
12009+ return (*(volatile const int *)&(v)->counter);
12010+}
12011+
12012+/**
12013+ * atomic_read_unchecked - read atomic variable
12014+ * @v: pointer of type atomic_unchecked_t
12015+ *
12016+ * Atomically reads the value of @v.
12017+ */
12018+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
12019+{
12020+ return (*(volatile const int *)&(v)->counter);
12021 }
12022
12023 /**
12024@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
12025 }
12026
12027 /**
12028+ * atomic_set_unchecked - set atomic variable
12029+ * @v: pointer of type atomic_unchecked_t
12030+ * @i: required value
12031+ *
12032+ * Atomically sets the value of @v to @i.
12033+ */
12034+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
12035+{
12036+ v->counter = i;
12037+}
12038+
12039+/**
12040 * atomic_add - add integer to atomic variable
12041 * @i: integer value to add
12042 * @v: pointer of type atomic_t
12043@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
12044 */
12045 static inline void atomic_add(int i, atomic_t *v)
12046 {
12047- asm volatile(LOCK_PREFIX "addl %1,%0"
12048+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12049+
12050+#ifdef CONFIG_PAX_REFCOUNT
12051+ "jno 0f\n"
12052+ LOCK_PREFIX "subl %1,%0\n"
12053+ "int $4\n0:\n"
12054+ _ASM_EXTABLE(0b, 0b)
12055+#endif
12056+
12057+ : "+m" (v->counter)
12058+ : "ir" (i));
12059+}
12060+
12061+/**
12062+ * atomic_add_unchecked - add integer to atomic variable
12063+ * @i: integer value to add
12064+ * @v: pointer of type atomic_unchecked_t
12065+ *
12066+ * Atomically adds @i to @v.
12067+ */
12068+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
12069+{
12070+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12071 : "+m" (v->counter)
12072 : "ir" (i));
12073 }
12074@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
12075 */
12076 static inline void atomic_sub(int i, atomic_t *v)
12077 {
12078- asm volatile(LOCK_PREFIX "subl %1,%0"
12079+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12080+
12081+#ifdef CONFIG_PAX_REFCOUNT
12082+ "jno 0f\n"
12083+ LOCK_PREFIX "addl %1,%0\n"
12084+ "int $4\n0:\n"
12085+ _ASM_EXTABLE(0b, 0b)
12086+#endif
12087+
12088+ : "+m" (v->counter)
12089+ : "ir" (i));
12090+}
12091+
12092+/**
12093+ * atomic_sub_unchecked - subtract integer from atomic variable
12094+ * @i: integer value to subtract
12095+ * @v: pointer of type atomic_unchecked_t
12096+ *
12097+ * Atomically subtracts @i from @v.
12098+ */
12099+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
12100+{
12101+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12102 : "+m" (v->counter)
12103 : "ir" (i));
12104 }
12105@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12106 {
12107 unsigned char c;
12108
12109- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
12110+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
12111+
12112+#ifdef CONFIG_PAX_REFCOUNT
12113+ "jno 0f\n"
12114+ LOCK_PREFIX "addl %2,%0\n"
12115+ "int $4\n0:\n"
12116+ _ASM_EXTABLE(0b, 0b)
12117+#endif
12118+
12119+ "sete %1\n"
12120 : "+m" (v->counter), "=qm" (c)
12121 : "ir" (i) : "memory");
12122 return c;
12123@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12124 */
12125 static inline void atomic_inc(atomic_t *v)
12126 {
12127- asm volatile(LOCK_PREFIX "incl %0"
12128+ asm volatile(LOCK_PREFIX "incl %0\n"
12129+
12130+#ifdef CONFIG_PAX_REFCOUNT
12131+ "jno 0f\n"
12132+ LOCK_PREFIX "decl %0\n"
12133+ "int $4\n0:\n"
12134+ _ASM_EXTABLE(0b, 0b)
12135+#endif
12136+
12137+ : "+m" (v->counter));
12138+}
12139+
12140+/**
12141+ * atomic_inc_unchecked - increment atomic variable
12142+ * @v: pointer of type atomic_unchecked_t
12143+ *
12144+ * Atomically increments @v by 1.
12145+ */
12146+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12147+{
12148+ asm volatile(LOCK_PREFIX "incl %0\n"
12149 : "+m" (v->counter));
12150 }
12151
12152@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12153 */
12154 static inline void atomic_dec(atomic_t *v)
12155 {
12156- asm volatile(LOCK_PREFIX "decl %0"
12157+ asm volatile(LOCK_PREFIX "decl %0\n"
12158+
12159+#ifdef CONFIG_PAX_REFCOUNT
12160+ "jno 0f\n"
12161+ LOCK_PREFIX "incl %0\n"
12162+ "int $4\n0:\n"
12163+ _ASM_EXTABLE(0b, 0b)
12164+#endif
12165+
12166+ : "+m" (v->counter));
12167+}
12168+
12169+/**
12170+ * atomic_dec_unchecked - decrement atomic variable
12171+ * @v: pointer of type atomic_unchecked_t
12172+ *
12173+ * Atomically decrements @v by 1.
12174+ */
12175+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12176+{
12177+ asm volatile(LOCK_PREFIX "decl %0\n"
12178 : "+m" (v->counter));
12179 }
12180
12181@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12182 {
12183 unsigned char c;
12184
12185- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12186+ asm volatile(LOCK_PREFIX "decl %0\n"
12187+
12188+#ifdef CONFIG_PAX_REFCOUNT
12189+ "jno 0f\n"
12190+ LOCK_PREFIX "incl %0\n"
12191+ "int $4\n0:\n"
12192+ _ASM_EXTABLE(0b, 0b)
12193+#endif
12194+
12195+ "sete %1\n"
12196 : "+m" (v->counter), "=qm" (c)
12197 : : "memory");
12198 return c != 0;
12199@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12200 {
12201 unsigned char c;
12202
12203- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12204+ asm volatile(LOCK_PREFIX "incl %0\n"
12205+
12206+#ifdef CONFIG_PAX_REFCOUNT
12207+ "jno 0f\n"
12208+ LOCK_PREFIX "decl %0\n"
12209+ "int $4\n0:\n"
12210+ _ASM_EXTABLE(0b, 0b)
12211+#endif
12212+
12213+ "sete %1\n"
12214+ : "+m" (v->counter), "=qm" (c)
12215+ : : "memory");
12216+ return c != 0;
12217+}
12218+
12219+/**
12220+ * atomic_inc_and_test_unchecked - increment and test
12221+ * @v: pointer of type atomic_unchecked_t
12222+ *
12223+ * Atomically increments @v by 1
12224+ * and returns true if the result is zero, or false for all
12225+ * other cases.
12226+ */
12227+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12228+{
12229+ unsigned char c;
12230+
12231+ asm volatile(LOCK_PREFIX "incl %0\n"
12232+ "sete %1\n"
12233 : "+m" (v->counter), "=qm" (c)
12234 : : "memory");
12235 return c != 0;
12236@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12237 {
12238 unsigned char c;
12239
12240- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12241+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12242+
12243+#ifdef CONFIG_PAX_REFCOUNT
12244+ "jno 0f\n"
12245+ LOCK_PREFIX "subl %2,%0\n"
12246+ "int $4\n0:\n"
12247+ _ASM_EXTABLE(0b, 0b)
12248+#endif
12249+
12250+ "sets %1\n"
12251 : "+m" (v->counter), "=qm" (c)
12252 : "ir" (i) : "memory");
12253 return c;
12254@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12255 */
12256 static inline int atomic_add_return(int i, atomic_t *v)
12257 {
12258+ return i + xadd_check_overflow(&v->counter, i);
12259+}
12260+
12261+/**
12262+ * atomic_add_return_unchecked - add integer and return
12263+ * @i: integer value to add
12264+ * @v: pointer of type atomic_unchecked_t
12265+ *
12266+ * Atomically adds @i to @v and returns @i + @v
12267+ */
12268+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12269+{
12270 return i + xadd(&v->counter, i);
12271 }
12272
12273@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12274 }
12275
12276 #define atomic_inc_return(v) (atomic_add_return(1, v))
12277+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12278+{
12279+ return atomic_add_return_unchecked(1, v);
12280+}
12281 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12282
12283 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12284@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12285 return cmpxchg(&v->counter, old, new);
12286 }
12287
12288+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12289+{
12290+ return cmpxchg(&v->counter, old, new);
12291+}
12292+
12293 static inline int atomic_xchg(atomic_t *v, int new)
12294 {
12295 return xchg(&v->counter, new);
12296 }
12297
12298+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12299+{
12300+ return xchg(&v->counter, new);
12301+}
12302+
12303 /**
12304 * __atomic_add_unless - add unless the number is already a given value
12305 * @v: pointer of type atomic_t
12306@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12307 */
12308 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12309 {
12310- int c, old;
12311+ int c, old, new;
12312 c = atomic_read(v);
12313 for (;;) {
12314- if (unlikely(c == (u)))
12315+ if (unlikely(c == u))
12316 break;
12317- old = atomic_cmpxchg((v), c, c + (a));
12318+
12319+ asm volatile("addl %2,%0\n"
12320+
12321+#ifdef CONFIG_PAX_REFCOUNT
12322+ "jno 0f\n"
12323+ "subl %2,%0\n"
12324+ "int $4\n0:\n"
12325+ _ASM_EXTABLE(0b, 0b)
12326+#endif
12327+
12328+ : "=r" (new)
12329+ : "0" (c), "ir" (a));
12330+
12331+ old = atomic_cmpxchg(v, c, new);
12332 if (likely(old == c))
12333 break;
12334 c = old;
12335@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12336 }
12337
12338 /**
12339+ * atomic_inc_not_zero_hint - increment if not null
12340+ * @v: pointer of type atomic_t
12341+ * @hint: probable value of the atomic before the increment
12342+ *
12343+ * This version of atomic_inc_not_zero() gives a hint of probable
12344+ * value of the atomic. This helps processor to not read the memory
12345+ * before doing the atomic read/modify/write cycle, lowering
12346+ * number of bus transactions on some arches.
12347+ *
12348+ * Returns: 0 if increment was not done, 1 otherwise.
12349+ */
12350+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12351+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12352+{
12353+ int val, c = hint, new;
12354+
12355+ /* sanity test, should be removed by compiler if hint is a constant */
12356+ if (!hint)
12357+ return __atomic_add_unless(v, 1, 0);
12358+
12359+ do {
12360+ asm volatile("incl %0\n"
12361+
12362+#ifdef CONFIG_PAX_REFCOUNT
12363+ "jno 0f\n"
12364+ "decl %0\n"
12365+ "int $4\n0:\n"
12366+ _ASM_EXTABLE(0b, 0b)
12367+#endif
12368+
12369+ : "=r" (new)
12370+ : "0" (c));
12371+
12372+ val = atomic_cmpxchg(v, c, new);
12373+ if (val == c)
12374+ return 1;
12375+ c = val;
12376+ } while (c);
12377+
12378+ return 0;
12379+}
12380+
12381+/**
12382 * atomic_inc_short - increment of a short integer
12383 * @v: pointer to type int
12384 *
12385@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12386 #endif
12387
12388 /* These are x86-specific, used by some header files */
12389-#define atomic_clear_mask(mask, addr) \
12390- asm volatile(LOCK_PREFIX "andl %0,%1" \
12391- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12392+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12393+{
12394+ asm volatile(LOCK_PREFIX "andl %1,%0"
12395+ : "+m" (v->counter)
12396+ : "r" (~(mask))
12397+ : "memory");
12398+}
12399
12400-#define atomic_set_mask(mask, addr) \
12401- asm volatile(LOCK_PREFIX "orl %0,%1" \
12402- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12403- : "memory")
12404+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12405+{
12406+ asm volatile(LOCK_PREFIX "andl %1,%0"
12407+ : "+m" (v->counter)
12408+ : "r" (~(mask))
12409+ : "memory");
12410+}
12411+
12412+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12413+{
12414+ asm volatile(LOCK_PREFIX "orl %1,%0"
12415+ : "+m" (v->counter)
12416+ : "r" (mask)
12417+ : "memory");
12418+}
12419+
12420+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12421+{
12422+ asm volatile(LOCK_PREFIX "orl %1,%0"
12423+ : "+m" (v->counter)
12424+ : "r" (mask)
12425+ : "memory");
12426+}
12427
12428 /* Atomic operations are already serializing on x86 */
12429 #define smp_mb__before_atomic_dec() barrier()
12430diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12431index b154de7..aadebd8 100644
12432--- a/arch/x86/include/asm/atomic64_32.h
12433+++ b/arch/x86/include/asm/atomic64_32.h
12434@@ -12,6 +12,14 @@ typedef struct {
12435 u64 __aligned(8) counter;
12436 } atomic64_t;
12437
12438+#ifdef CONFIG_PAX_REFCOUNT
12439+typedef struct {
12440+ u64 __aligned(8) counter;
12441+} atomic64_unchecked_t;
12442+#else
12443+typedef atomic64_t atomic64_unchecked_t;
12444+#endif
12445+
12446 #define ATOMIC64_INIT(val) { (val) }
12447
12448 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12449@@ -37,21 +45,31 @@ typedef struct {
12450 ATOMIC64_DECL_ONE(sym##_386)
12451
12452 ATOMIC64_DECL_ONE(add_386);
12453+ATOMIC64_DECL_ONE(add_unchecked_386);
12454 ATOMIC64_DECL_ONE(sub_386);
12455+ATOMIC64_DECL_ONE(sub_unchecked_386);
12456 ATOMIC64_DECL_ONE(inc_386);
12457+ATOMIC64_DECL_ONE(inc_unchecked_386);
12458 ATOMIC64_DECL_ONE(dec_386);
12459+ATOMIC64_DECL_ONE(dec_unchecked_386);
12460 #endif
12461
12462 #define alternative_atomic64(f, out, in...) \
12463 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12464
12465 ATOMIC64_DECL(read);
12466+ATOMIC64_DECL(read_unchecked);
12467 ATOMIC64_DECL(set);
12468+ATOMIC64_DECL(set_unchecked);
12469 ATOMIC64_DECL(xchg);
12470 ATOMIC64_DECL(add_return);
12471+ATOMIC64_DECL(add_return_unchecked);
12472 ATOMIC64_DECL(sub_return);
12473+ATOMIC64_DECL(sub_return_unchecked);
12474 ATOMIC64_DECL(inc_return);
12475+ATOMIC64_DECL(inc_return_unchecked);
12476 ATOMIC64_DECL(dec_return);
12477+ATOMIC64_DECL(dec_return_unchecked);
12478 ATOMIC64_DECL(dec_if_positive);
12479 ATOMIC64_DECL(inc_not_zero);
12480 ATOMIC64_DECL(add_unless);
12481@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12482 }
12483
12484 /**
12485+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12486+ * @p: pointer to type atomic64_unchecked_t
12487+ * @o: expected value
12488+ * @n: new value
12489+ *
12490+ * Atomically sets @v to @n if it was equal to @o and returns
12491+ * the old value.
12492+ */
12493+
12494+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12495+{
12496+ return cmpxchg64(&v->counter, o, n);
12497+}
12498+
12499+/**
12500 * atomic64_xchg - xchg atomic64 variable
12501 * @v: pointer to type atomic64_t
12502 * @n: value to assign
12503@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12504 }
12505
12506 /**
12507+ * atomic64_set_unchecked - set atomic64 variable
12508+ * @v: pointer to type atomic64_unchecked_t
12509+ * @n: value to assign
12510+ *
12511+ * Atomically sets the value of @v to @n.
12512+ */
12513+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12514+{
12515+ unsigned high = (unsigned)(i >> 32);
12516+ unsigned low = (unsigned)i;
12517+ alternative_atomic64(set, /* no output */,
12518+ "S" (v), "b" (low), "c" (high)
12519+ : "eax", "edx", "memory");
12520+}
12521+
12522+/**
12523 * atomic64_read - read atomic64 variable
12524 * @v: pointer to type atomic64_t
12525 *
12526@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12527 }
12528
12529 /**
12530+ * atomic64_read_unchecked - read atomic64 variable
12531+ * @v: pointer to type atomic64_unchecked_t
12532+ *
12533+ * Atomically reads the value of @v and returns it.
12534+ */
12535+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12536+{
12537+ long long r;
12538+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12539+ return r;
12540+ }
12541+
12542+/**
12543 * atomic64_add_return - add and return
12544 * @i: integer value to add
12545 * @v: pointer to type atomic64_t
12546@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12547 return i;
12548 }
12549
12550+/**
12551+ * atomic64_add_return_unchecked - add and return
12552+ * @i: integer value to add
12553+ * @v: pointer to type atomic64_unchecked_t
12554+ *
12555+ * Atomically adds @i to @v and returns @i + *@v
12556+ */
12557+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12558+{
12559+ alternative_atomic64(add_return_unchecked,
12560+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12561+ ASM_NO_INPUT_CLOBBER("memory"));
12562+ return i;
12563+}
12564+
12565 /*
12566 * Other variants with different arithmetic operators:
12567 */
12568@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12569 return a;
12570 }
12571
12572+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12573+{
12574+ long long a;
12575+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12576+ "S" (v) : "memory", "ecx");
12577+ return a;
12578+}
12579+
12580 static inline long long atomic64_dec_return(atomic64_t *v)
12581 {
12582 long long a;
12583@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12584 }
12585
12586 /**
12587+ * atomic64_add_unchecked - add integer to atomic64 variable
12588+ * @i: integer value to add
12589+ * @v: pointer to type atomic64_unchecked_t
12590+ *
12591+ * Atomically adds @i to @v.
12592+ */
12593+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12594+{
12595+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12596+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12597+ ASM_NO_INPUT_CLOBBER("memory"));
12598+ return i;
12599+}
12600+
12601+/**
12602 * atomic64_sub - subtract the atomic64 variable
12603 * @i: integer value to subtract
12604 * @v: pointer to type atomic64_t
12605diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12606index 0e1cbfc..5623683 100644
12607--- a/arch/x86/include/asm/atomic64_64.h
12608+++ b/arch/x86/include/asm/atomic64_64.h
12609@@ -18,7 +18,19 @@
12610 */
12611 static inline long atomic64_read(const atomic64_t *v)
12612 {
12613- return (*(volatile long *)&(v)->counter);
12614+ return (*(volatile const long *)&(v)->counter);
12615+}
12616+
12617+/**
12618+ * atomic64_read_unchecked - read atomic64 variable
12619+ * @v: pointer of type atomic64_unchecked_t
12620+ *
12621+ * Atomically reads the value of @v.
12622+ * Doesn't imply a read memory barrier.
12623+ */
12624+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12625+{
12626+ return (*(volatile const long *)&(v)->counter);
12627 }
12628
12629 /**
12630@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12631 }
12632
12633 /**
12634+ * atomic64_set_unchecked - set atomic64 variable
12635+ * @v: pointer to type atomic64_unchecked_t
12636+ * @i: required value
12637+ *
12638+ * Atomically sets the value of @v to @i.
12639+ */
12640+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12641+{
12642+ v->counter = i;
12643+}
12644+
12645+/**
12646 * atomic64_add - add integer to atomic64 variable
12647 * @i: integer value to add
12648 * @v: pointer to type atomic64_t
12649@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12650 */
12651 static inline void atomic64_add(long i, atomic64_t *v)
12652 {
12653+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12654+
12655+#ifdef CONFIG_PAX_REFCOUNT
12656+ "jno 0f\n"
12657+ LOCK_PREFIX "subq %1,%0\n"
12658+ "int $4\n0:\n"
12659+ _ASM_EXTABLE(0b, 0b)
12660+#endif
12661+
12662+ : "=m" (v->counter)
12663+ : "er" (i), "m" (v->counter));
12664+}
12665+
12666+/**
12667+ * atomic64_add_unchecked - add integer to atomic64 variable
12668+ * @i: integer value to add
12669+ * @v: pointer to type atomic64_unchecked_t
12670+ *
12671+ * Atomically adds @i to @v.
12672+ */
12673+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12674+{
12675 asm volatile(LOCK_PREFIX "addq %1,%0"
12676 : "=m" (v->counter)
12677 : "er" (i), "m" (v->counter));
12678@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12679 */
12680 static inline void atomic64_sub(long i, atomic64_t *v)
12681 {
12682- asm volatile(LOCK_PREFIX "subq %1,%0"
12683+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12684+
12685+#ifdef CONFIG_PAX_REFCOUNT
12686+ "jno 0f\n"
12687+ LOCK_PREFIX "addq %1,%0\n"
12688+ "int $4\n0:\n"
12689+ _ASM_EXTABLE(0b, 0b)
12690+#endif
12691+
12692+ : "=m" (v->counter)
12693+ : "er" (i), "m" (v->counter));
12694+}
12695+
12696+/**
12697+ * atomic64_sub_unchecked - subtract the atomic64 variable
12698+ * @i: integer value to subtract
12699+ * @v: pointer to type atomic64_unchecked_t
12700+ *
12701+ * Atomically subtracts @i from @v.
12702+ */
12703+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12704+{
12705+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12706 : "=m" (v->counter)
12707 : "er" (i), "m" (v->counter));
12708 }
12709@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12710 {
12711 unsigned char c;
12712
12713- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12714+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12715+
12716+#ifdef CONFIG_PAX_REFCOUNT
12717+ "jno 0f\n"
12718+ LOCK_PREFIX "addq %2,%0\n"
12719+ "int $4\n0:\n"
12720+ _ASM_EXTABLE(0b, 0b)
12721+#endif
12722+
12723+ "sete %1\n"
12724 : "=m" (v->counter), "=qm" (c)
12725 : "er" (i), "m" (v->counter) : "memory");
12726 return c;
12727@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12728 */
12729 static inline void atomic64_inc(atomic64_t *v)
12730 {
12731+ asm volatile(LOCK_PREFIX "incq %0\n"
12732+
12733+#ifdef CONFIG_PAX_REFCOUNT
12734+ "jno 0f\n"
12735+ LOCK_PREFIX "decq %0\n"
12736+ "int $4\n0:\n"
12737+ _ASM_EXTABLE(0b, 0b)
12738+#endif
12739+
12740+ : "=m" (v->counter)
12741+ : "m" (v->counter));
12742+}
12743+
12744+/**
12745+ * atomic64_inc_unchecked - increment atomic64 variable
12746+ * @v: pointer to type atomic64_unchecked_t
12747+ *
12748+ * Atomically increments @v by 1.
12749+ */
12750+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12751+{
12752 asm volatile(LOCK_PREFIX "incq %0"
12753 : "=m" (v->counter)
12754 : "m" (v->counter));
12755@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12756 */
12757 static inline void atomic64_dec(atomic64_t *v)
12758 {
12759- asm volatile(LOCK_PREFIX "decq %0"
12760+ asm volatile(LOCK_PREFIX "decq %0\n"
12761+
12762+#ifdef CONFIG_PAX_REFCOUNT
12763+ "jno 0f\n"
12764+ LOCK_PREFIX "incq %0\n"
12765+ "int $4\n0:\n"
12766+ _ASM_EXTABLE(0b, 0b)
12767+#endif
12768+
12769+ : "=m" (v->counter)
12770+ : "m" (v->counter));
12771+}
12772+
12773+/**
12774+ * atomic64_dec_unchecked - decrement atomic64 variable
12775+ * @v: pointer to type atomic64_t
12776+ *
12777+ * Atomically decrements @v by 1.
12778+ */
12779+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12780+{
12781+ asm volatile(LOCK_PREFIX "decq %0\n"
12782 : "=m" (v->counter)
12783 : "m" (v->counter));
12784 }
12785@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12786 {
12787 unsigned char c;
12788
12789- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12790+ asm volatile(LOCK_PREFIX "decq %0\n"
12791+
12792+#ifdef CONFIG_PAX_REFCOUNT
12793+ "jno 0f\n"
12794+ LOCK_PREFIX "incq %0\n"
12795+ "int $4\n0:\n"
12796+ _ASM_EXTABLE(0b, 0b)
12797+#endif
12798+
12799+ "sete %1\n"
12800 : "=m" (v->counter), "=qm" (c)
12801 : "m" (v->counter) : "memory");
12802 return c != 0;
12803@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12804 {
12805 unsigned char c;
12806
12807- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12808+ asm volatile(LOCK_PREFIX "incq %0\n"
12809+
12810+#ifdef CONFIG_PAX_REFCOUNT
12811+ "jno 0f\n"
12812+ LOCK_PREFIX "decq %0\n"
12813+ "int $4\n0:\n"
12814+ _ASM_EXTABLE(0b, 0b)
12815+#endif
12816+
12817+ "sete %1\n"
12818 : "=m" (v->counter), "=qm" (c)
12819 : "m" (v->counter) : "memory");
12820 return c != 0;
12821@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12822 {
12823 unsigned char c;
12824
12825- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12826+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12827+
12828+#ifdef CONFIG_PAX_REFCOUNT
12829+ "jno 0f\n"
12830+ LOCK_PREFIX "subq %2,%0\n"
12831+ "int $4\n0:\n"
12832+ _ASM_EXTABLE(0b, 0b)
12833+#endif
12834+
12835+ "sets %1\n"
12836 : "=m" (v->counter), "=qm" (c)
12837 : "er" (i), "m" (v->counter) : "memory");
12838 return c;
12839@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12840 */
12841 static inline long atomic64_add_return(long i, atomic64_t *v)
12842 {
12843+ return i + xadd_check_overflow(&v->counter, i);
12844+}
12845+
12846+/**
12847+ * atomic64_add_return_unchecked - add and return
12848+ * @i: integer value to add
12849+ * @v: pointer to type atomic64_unchecked_t
12850+ *
12851+ * Atomically adds @i to @v and returns @i + @v
12852+ */
12853+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12854+{
12855 return i + xadd(&v->counter, i);
12856 }
12857
12858@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12859 }
12860
12861 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12862+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12863+{
12864+ return atomic64_add_return_unchecked(1, v);
12865+}
12866 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12867
12868 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12869@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12870 return cmpxchg(&v->counter, old, new);
12871 }
12872
12873+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12874+{
12875+ return cmpxchg(&v->counter, old, new);
12876+}
12877+
12878 static inline long atomic64_xchg(atomic64_t *v, long new)
12879 {
12880 return xchg(&v->counter, new);
12881@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12882 */
12883 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12884 {
12885- long c, old;
12886+ long c, old, new;
12887 c = atomic64_read(v);
12888 for (;;) {
12889- if (unlikely(c == (u)))
12890+ if (unlikely(c == u))
12891 break;
12892- old = atomic64_cmpxchg((v), c, c + (a));
12893+
12894+ asm volatile("add %2,%0\n"
12895+
12896+#ifdef CONFIG_PAX_REFCOUNT
12897+ "jno 0f\n"
12898+ "sub %2,%0\n"
12899+ "int $4\n0:\n"
12900+ _ASM_EXTABLE(0b, 0b)
12901+#endif
12902+
12903+ : "=r" (new)
12904+ : "0" (c), "ir" (a));
12905+
12906+ old = atomic64_cmpxchg(v, c, new);
12907 if (likely(old == c))
12908 break;
12909 c = old;
12910 }
12911- return c != (u);
12912+ return c != u;
12913 }
12914
12915 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12916diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12917index 6dfd019..28e188d 100644
12918--- a/arch/x86/include/asm/bitops.h
12919+++ b/arch/x86/include/asm/bitops.h
12920@@ -40,7 +40,7 @@
12921 * a mask operation on a byte.
12922 */
12923 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12924-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12925+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12926 #define CONST_MASK(nr) (1 << ((nr) & 7))
12927
12928 /**
12929@@ -486,7 +486,7 @@ static inline int fls(int x)
12930 * at position 64.
12931 */
12932 #ifdef CONFIG_X86_64
12933-static __always_inline int fls64(__u64 x)
12934+static __always_inline long fls64(__u64 x)
12935 {
12936 int bitpos = -1;
12937 /*
12938diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12939index 4fa687a..60f2d39 100644
12940--- a/arch/x86/include/asm/boot.h
12941+++ b/arch/x86/include/asm/boot.h
12942@@ -6,10 +6,15 @@
12943 #include <uapi/asm/boot.h>
12944
12945 /* Physical address where kernel should be loaded. */
12946-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12947+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12948 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12949 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12950
12951+#ifndef __ASSEMBLY__
12952+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12953+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12954+#endif
12955+
12956 /* Minimum kernel alignment, as a power of two */
12957 #ifdef CONFIG_X86_64
12958 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12959diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12960index 48f99f1..d78ebf9 100644
12961--- a/arch/x86/include/asm/cache.h
12962+++ b/arch/x86/include/asm/cache.h
12963@@ -5,12 +5,13 @@
12964
12965 /* L1 cache line size */
12966 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12967-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12968+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12969
12970 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12971+#define __read_only __attribute__((__section__(".data..read_only")))
12972
12973 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12974-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12975+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12976
12977 #ifdef CONFIG_X86_VSMP
12978 #ifdef CONFIG_SMP
12979diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12980index 9863ee3..4a1f8e1 100644
12981--- a/arch/x86/include/asm/cacheflush.h
12982+++ b/arch/x86/include/asm/cacheflush.h
12983@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12984 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12985
12986 if (pg_flags == _PGMT_DEFAULT)
12987- return -1;
12988+ return ~0UL;
12989 else if (pg_flags == _PGMT_WC)
12990 return _PAGE_CACHE_WC;
12991 else if (pg_flags == _PGMT_UC_MINUS)
12992diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12993index 46fc474..b02b0f9 100644
12994--- a/arch/x86/include/asm/checksum_32.h
12995+++ b/arch/x86/include/asm/checksum_32.h
12996@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12997 int len, __wsum sum,
12998 int *src_err_ptr, int *dst_err_ptr);
12999
13000+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
13001+ int len, __wsum sum,
13002+ int *src_err_ptr, int *dst_err_ptr);
13003+
13004+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
13005+ int len, __wsum sum,
13006+ int *src_err_ptr, int *dst_err_ptr);
13007+
13008 /*
13009 * Note: when you get a NULL pointer exception here this means someone
13010 * passed in an incorrect kernel address to one of these functions.
13011@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
13012 int *err_ptr)
13013 {
13014 might_sleep();
13015- return csum_partial_copy_generic((__force void *)src, dst,
13016+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
13017 len, sum, err_ptr, NULL);
13018 }
13019
13020@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
13021 {
13022 might_sleep();
13023 if (access_ok(VERIFY_WRITE, dst, len))
13024- return csum_partial_copy_generic(src, (__force void *)dst,
13025+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
13026 len, sum, NULL, err_ptr);
13027
13028 if (len)
13029diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
13030index 8d871ea..c1a0dc9 100644
13031--- a/arch/x86/include/asm/cmpxchg.h
13032+++ b/arch/x86/include/asm/cmpxchg.h
13033@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
13034 __compiletime_error("Bad argument size for cmpxchg");
13035 extern void __xadd_wrong_size(void)
13036 __compiletime_error("Bad argument size for xadd");
13037+extern void __xadd_check_overflow_wrong_size(void)
13038+ __compiletime_error("Bad argument size for xadd_check_overflow");
13039 extern void __add_wrong_size(void)
13040 __compiletime_error("Bad argument size for add");
13041+extern void __add_check_overflow_wrong_size(void)
13042+ __compiletime_error("Bad argument size for add_check_overflow");
13043
13044 /*
13045 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
13046@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
13047 __ret; \
13048 })
13049
13050+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
13051+ ({ \
13052+ __typeof__ (*(ptr)) __ret = (arg); \
13053+ switch (sizeof(*(ptr))) { \
13054+ case __X86_CASE_L: \
13055+ asm volatile (lock #op "l %0, %1\n" \
13056+ "jno 0f\n" \
13057+ "mov %0,%1\n" \
13058+ "int $4\n0:\n" \
13059+ _ASM_EXTABLE(0b, 0b) \
13060+ : "+r" (__ret), "+m" (*(ptr)) \
13061+ : : "memory", "cc"); \
13062+ break; \
13063+ case __X86_CASE_Q: \
13064+ asm volatile (lock #op "q %q0, %1\n" \
13065+ "jno 0f\n" \
13066+ "mov %0,%1\n" \
13067+ "int $4\n0:\n" \
13068+ _ASM_EXTABLE(0b, 0b) \
13069+ : "+r" (__ret), "+m" (*(ptr)) \
13070+ : : "memory", "cc"); \
13071+ break; \
13072+ default: \
13073+ __ ## op ## _check_overflow_wrong_size(); \
13074+ } \
13075+ __ret; \
13076+ })
13077+
13078 /*
13079 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
13080 * Since this is generally used to protect other memory information, we
13081@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
13082 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
13083 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
13084
13085+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
13086+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
13087+
13088 #define __add(ptr, inc, lock) \
13089 ({ \
13090 __typeof__ (*(ptr)) __ret = (inc); \
13091diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
13092index 59c6c40..5e0b22c 100644
13093--- a/arch/x86/include/asm/compat.h
13094+++ b/arch/x86/include/asm/compat.h
13095@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
13096 typedef u32 compat_uint_t;
13097 typedef u32 compat_ulong_t;
13098 typedef u64 __attribute__((aligned(4))) compat_u64;
13099-typedef u32 compat_uptr_t;
13100+typedef u32 __user compat_uptr_t;
13101
13102 struct compat_timespec {
13103 compat_time_t tv_sec;
13104diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
13105index 93fe929..90858b7 100644
13106--- a/arch/x86/include/asm/cpufeature.h
13107+++ b/arch/x86/include/asm/cpufeature.h
13108@@ -207,7 +207,7 @@
13109 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
13110 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
13111 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
13112-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
13113+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
13114 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
13115 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
13116 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
13117@@ -377,7 +377,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
13118 ".section .discard,\"aw\",@progbits\n"
13119 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
13120 ".previous\n"
13121- ".section .altinstr_replacement,\"ax\"\n"
13122+ ".section .altinstr_replacement,\"a\"\n"
13123 "3: movb $1,%0\n"
13124 "4:\n"
13125 ".previous\n"
13126diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
13127index 8bf1c06..b6ae785 100644
13128--- a/arch/x86/include/asm/desc.h
13129+++ b/arch/x86/include/asm/desc.h
13130@@ -4,6 +4,7 @@
13131 #include <asm/desc_defs.h>
13132 #include <asm/ldt.h>
13133 #include <asm/mmu.h>
13134+#include <asm/pgtable.h>
13135
13136 #include <linux/smp.h>
13137 #include <linux/percpu.h>
13138@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13139
13140 desc->type = (info->read_exec_only ^ 1) << 1;
13141 desc->type |= info->contents << 2;
13142+ desc->type |= info->seg_not_present ^ 1;
13143
13144 desc->s = 1;
13145 desc->dpl = 0x3;
13146@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13147 }
13148
13149 extern struct desc_ptr idt_descr;
13150-extern gate_desc idt_table[];
13151 extern struct desc_ptr nmi_idt_descr;
13152-extern gate_desc nmi_idt_table[];
13153-
13154-struct gdt_page {
13155- struct desc_struct gdt[GDT_ENTRIES];
13156-} __attribute__((aligned(PAGE_SIZE)));
13157-
13158-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13159+extern gate_desc idt_table[256];
13160+extern gate_desc nmi_idt_table[256];
13161
13162+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13163 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13164 {
13165- return per_cpu(gdt_page, cpu).gdt;
13166+ return cpu_gdt_table[cpu];
13167 }
13168
13169 #ifdef CONFIG_X86_64
13170@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13171 unsigned long base, unsigned dpl, unsigned flags,
13172 unsigned short seg)
13173 {
13174- gate->a = (seg << 16) | (base & 0xffff);
13175- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13176+ gate->gate.offset_low = base;
13177+ gate->gate.seg = seg;
13178+ gate->gate.reserved = 0;
13179+ gate->gate.type = type;
13180+ gate->gate.s = 0;
13181+ gate->gate.dpl = dpl;
13182+ gate->gate.p = 1;
13183+ gate->gate.offset_high = base >> 16;
13184 }
13185
13186 #endif
13187@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13188
13189 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13190 {
13191+ pax_open_kernel();
13192 memcpy(&idt[entry], gate, sizeof(*gate));
13193+ pax_close_kernel();
13194 }
13195
13196 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13197 {
13198+ pax_open_kernel();
13199 memcpy(&ldt[entry], desc, 8);
13200+ pax_close_kernel();
13201 }
13202
13203 static inline void
13204@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13205 default: size = sizeof(*gdt); break;
13206 }
13207
13208+ pax_open_kernel();
13209 memcpy(&gdt[entry], desc, size);
13210+ pax_close_kernel();
13211 }
13212
13213 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13214@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13215
13216 static inline void native_load_tr_desc(void)
13217 {
13218+ pax_open_kernel();
13219 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13220+ pax_close_kernel();
13221 }
13222
13223 static inline void native_load_gdt(const struct desc_ptr *dtr)
13224@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13225 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13226 unsigned int i;
13227
13228+ pax_open_kernel();
13229 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13230 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13231+ pax_close_kernel();
13232 }
13233
13234 #define _LDT_empty(info) \
13235@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13236 preempt_enable();
13237 }
13238
13239-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13240+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13241 {
13242 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13243 }
13244@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13245 }
13246
13247 #ifdef CONFIG_X86_64
13248-static inline void set_nmi_gate(int gate, void *addr)
13249+static inline void set_nmi_gate(int gate, const void *addr)
13250 {
13251 gate_desc s;
13252
13253@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13254 }
13255 #endif
13256
13257-static inline void _set_gate(int gate, unsigned type, void *addr,
13258+static inline void _set_gate(int gate, unsigned type, const void *addr,
13259 unsigned dpl, unsigned ist, unsigned seg)
13260 {
13261 gate_desc s;
13262@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13263 * Pentium F0 0F bugfix can have resulted in the mapped
13264 * IDT being write-protected.
13265 */
13266-static inline void set_intr_gate(unsigned int n, void *addr)
13267+static inline void set_intr_gate(unsigned int n, const void *addr)
13268 {
13269 BUG_ON((unsigned)n > 0xFF);
13270 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13271@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13272 /*
13273 * This routine sets up an interrupt gate at directory privilege level 3.
13274 */
13275-static inline void set_system_intr_gate(unsigned int n, void *addr)
13276+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13277 {
13278 BUG_ON((unsigned)n > 0xFF);
13279 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13280 }
13281
13282-static inline void set_system_trap_gate(unsigned int n, void *addr)
13283+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13284 {
13285 BUG_ON((unsigned)n > 0xFF);
13286 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13287 }
13288
13289-static inline void set_trap_gate(unsigned int n, void *addr)
13290+static inline void set_trap_gate(unsigned int n, const void *addr)
13291 {
13292 BUG_ON((unsigned)n > 0xFF);
13293 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13294@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13295 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13296 {
13297 BUG_ON((unsigned)n > 0xFF);
13298- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13299+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13300 }
13301
13302-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13303+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13304 {
13305 BUG_ON((unsigned)n > 0xFF);
13306 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13307 }
13308
13309-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13310+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13311 {
13312 BUG_ON((unsigned)n > 0xFF);
13313 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13314 }
13315
13316+#ifdef CONFIG_X86_32
13317+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13318+{
13319+ struct desc_struct d;
13320+
13321+ if (likely(limit))
13322+ limit = (limit - 1UL) >> PAGE_SHIFT;
13323+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13324+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13325+}
13326+#endif
13327+
13328 #endif /* _ASM_X86_DESC_H */
13329diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13330index 278441f..b95a174 100644
13331--- a/arch/x86/include/asm/desc_defs.h
13332+++ b/arch/x86/include/asm/desc_defs.h
13333@@ -31,6 +31,12 @@ struct desc_struct {
13334 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13335 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13336 };
13337+ struct {
13338+ u16 offset_low;
13339+ u16 seg;
13340+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13341+ unsigned offset_high: 16;
13342+ } gate;
13343 };
13344 } __attribute__((packed));
13345
13346diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13347index ced283a..ffe04cc 100644
13348--- a/arch/x86/include/asm/div64.h
13349+++ b/arch/x86/include/asm/div64.h
13350@@ -39,7 +39,7 @@
13351 __mod; \
13352 })
13353
13354-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13355+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13356 {
13357 union {
13358 u64 v64;
13359diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13360index 9c999c1..3860cb8 100644
13361--- a/arch/x86/include/asm/elf.h
13362+++ b/arch/x86/include/asm/elf.h
13363@@ -243,7 +243,25 @@ extern int force_personality32;
13364 the loader. We need to make sure that it is out of the way of the program
13365 that it will "exec", and that there is sufficient room for the brk. */
13366
13367+#ifdef CONFIG_PAX_SEGMEXEC
13368+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13369+#else
13370 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13371+#endif
13372+
13373+#ifdef CONFIG_PAX_ASLR
13374+#ifdef CONFIG_X86_32
13375+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13376+
13377+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13378+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13379+#else
13380+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13381+
13382+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13383+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13384+#endif
13385+#endif
13386
13387 /* This yields a mask that user programs can use to figure out what
13388 instruction set this CPU supports. This could be done in user space,
13389@@ -296,16 +314,12 @@ do { \
13390
13391 #define ARCH_DLINFO \
13392 do { \
13393- if (vdso_enabled) \
13394- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13395- (unsigned long)current->mm->context.vdso); \
13396+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13397 } while (0)
13398
13399 #define ARCH_DLINFO_X32 \
13400 do { \
13401- if (vdso_enabled) \
13402- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13403- (unsigned long)current->mm->context.vdso); \
13404+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13405 } while (0)
13406
13407 #define AT_SYSINFO 32
13408@@ -320,7 +334,7 @@ else \
13409
13410 #endif /* !CONFIG_X86_32 */
13411
13412-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13413+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13414
13415 #define VDSO_ENTRY \
13416 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13417@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13418 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13419 #define compat_arch_setup_additional_pages syscall32_setup_pages
13420
13421-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13422-#define arch_randomize_brk arch_randomize_brk
13423-
13424 /*
13425 * True on X86_32 or when emulating IA32 on X86_64
13426 */
13427diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13428index 75ce3f4..882e801 100644
13429--- a/arch/x86/include/asm/emergency-restart.h
13430+++ b/arch/x86/include/asm/emergency-restart.h
13431@@ -13,6 +13,6 @@ enum reboot_type {
13432
13433 extern enum reboot_type reboot_type;
13434
13435-extern void machine_emergency_restart(void);
13436+extern void machine_emergency_restart(void) __noreturn;
13437
13438 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13439diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13440index e25cc33..425d099 100644
13441--- a/arch/x86/include/asm/fpu-internal.h
13442+++ b/arch/x86/include/asm/fpu-internal.h
13443@@ -127,7 +127,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13444 ({ \
13445 int err; \
13446 asm volatile(ASM_STAC "\n" \
13447- "1:" #insn "\n\t" \
13448+ "1:" \
13449+ __copyuser_seg \
13450+ #insn "\n\t" \
13451 "2: " ASM_CLAC "\n" \
13452 ".section .fixup,\"ax\"\n" \
13453 "3: movl $-1,%[err]\n" \
13454@@ -300,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13455 "emms\n\t" /* clear stack tags */
13456 "fildl %P[addr]", /* set F?P to defined value */
13457 X86_FEATURE_FXSAVE_LEAK,
13458- [addr] "m" (tsk->thread.fpu.has_fpu));
13459+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13460
13461 return fpu_restore_checking(&tsk->thread.fpu);
13462 }
13463diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13464index be27ba1..8f13ff9 100644
13465--- a/arch/x86/include/asm/futex.h
13466+++ b/arch/x86/include/asm/futex.h
13467@@ -12,6 +12,7 @@
13468 #include <asm/smap.h>
13469
13470 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13471+ typecheck(u32 __user *, uaddr); \
13472 asm volatile("\t" ASM_STAC "\n" \
13473 "1:\t" insn "\n" \
13474 "2:\t" ASM_CLAC "\n" \
13475@@ -20,15 +21,16 @@
13476 "\tjmp\t2b\n" \
13477 "\t.previous\n" \
13478 _ASM_EXTABLE(1b, 3b) \
13479- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13480+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13481 : "i" (-EFAULT), "0" (oparg), "1" (0))
13482
13483 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13484+ typecheck(u32 __user *, uaddr); \
13485 asm volatile("\t" ASM_STAC "\n" \
13486 "1:\tmovl %2, %0\n" \
13487 "\tmovl\t%0, %3\n" \
13488 "\t" insn "\n" \
13489- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13490+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13491 "\tjnz\t1b\n" \
13492 "3:\t" ASM_CLAC "\n" \
13493 "\t.section .fixup,\"ax\"\n" \
13494@@ -38,7 +40,7 @@
13495 _ASM_EXTABLE(1b, 4b) \
13496 _ASM_EXTABLE(2b, 4b) \
13497 : "=&a" (oldval), "=&r" (ret), \
13498- "+m" (*uaddr), "=&r" (tem) \
13499+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13500 : "r" (oparg), "i" (-EFAULT), "1" (0))
13501
13502 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13503@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13504
13505 switch (op) {
13506 case FUTEX_OP_SET:
13507- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13508+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13509 break;
13510 case FUTEX_OP_ADD:
13511- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13512+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13513 uaddr, oparg);
13514 break;
13515 case FUTEX_OP_OR:
13516@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13517 return -EFAULT;
13518
13519 asm volatile("\t" ASM_STAC "\n"
13520- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13521+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13522 "2:\t" ASM_CLAC "\n"
13523 "\t.section .fixup, \"ax\"\n"
13524 "3:\tmov %3, %0\n"
13525 "\tjmp 2b\n"
13526 "\t.previous\n"
13527 _ASM_EXTABLE(1b, 3b)
13528- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13529+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13530 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13531 : "memory"
13532 );
13533diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13534index 10a78c3..cc77143 100644
13535--- a/arch/x86/include/asm/hw_irq.h
13536+++ b/arch/x86/include/asm/hw_irq.h
13537@@ -147,8 +147,8 @@ extern void setup_ioapic_dest(void);
13538 extern void enable_IO_APIC(void);
13539
13540 /* Statistics */
13541-extern atomic_t irq_err_count;
13542-extern atomic_t irq_mis_count;
13543+extern atomic_unchecked_t irq_err_count;
13544+extern atomic_unchecked_t irq_mis_count;
13545
13546 /* EISA */
13547 extern void eisa_set_level_irq(unsigned int irq);
13548diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13549index a203659..9889f1c 100644
13550--- a/arch/x86/include/asm/i8259.h
13551+++ b/arch/x86/include/asm/i8259.h
13552@@ -62,7 +62,7 @@ struct legacy_pic {
13553 void (*init)(int auto_eoi);
13554 int (*irq_pending)(unsigned int irq);
13555 void (*make_irq)(unsigned int irq);
13556-};
13557+} __do_const;
13558
13559 extern struct legacy_pic *legacy_pic;
13560 extern struct legacy_pic null_legacy_pic;
13561diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13562index d8e8eef..1765f78 100644
13563--- a/arch/x86/include/asm/io.h
13564+++ b/arch/x86/include/asm/io.h
13565@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13566 "m" (*(volatile type __force *)addr) barrier); }
13567
13568 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13569-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13570-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13571+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13572+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13573
13574 build_mmio_read(__readb, "b", unsigned char, "=q", )
13575-build_mmio_read(__readw, "w", unsigned short, "=r", )
13576-build_mmio_read(__readl, "l", unsigned int, "=r", )
13577+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13578+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13579
13580 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13581 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13582@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13583 return ioremap_nocache(offset, size);
13584 }
13585
13586-extern void iounmap(volatile void __iomem *addr);
13587+extern void iounmap(const volatile void __iomem *addr);
13588
13589 extern void set_iounmap_nonlazy(void);
13590
13591@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13592
13593 #include <linux/vmalloc.h>
13594
13595+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13596+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13597+{
13598+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13599+}
13600+
13601+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13602+{
13603+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13604+}
13605+
13606 /*
13607 * Convert a virtual cached pointer to an uncached pointer
13608 */
13609diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13610index bba3cf8..06bc8da 100644
13611--- a/arch/x86/include/asm/irqflags.h
13612+++ b/arch/x86/include/asm/irqflags.h
13613@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13614 sti; \
13615 sysexit
13616
13617+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13618+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13619+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13620+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13621+
13622 #else
13623 #define INTERRUPT_RETURN iret
13624 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13625diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13626index 5a6d287..f815789 100644
13627--- a/arch/x86/include/asm/kprobes.h
13628+++ b/arch/x86/include/asm/kprobes.h
13629@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13630 #define RELATIVEJUMP_SIZE 5
13631 #define RELATIVECALL_OPCODE 0xe8
13632 #define RELATIVE_ADDR_SIZE 4
13633-#define MAX_STACK_SIZE 64
13634-#define MIN_STACK_SIZE(ADDR) \
13635- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13636- THREAD_SIZE - (unsigned long)(ADDR))) \
13637- ? (MAX_STACK_SIZE) \
13638- : (((unsigned long)current_thread_info()) + \
13639- THREAD_SIZE - (unsigned long)(ADDR)))
13640+#define MAX_STACK_SIZE 64UL
13641+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13642
13643 #define flush_insn_slot(p) do { } while (0)
13644
13645diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13646index 2d89e39..baee879 100644
13647--- a/arch/x86/include/asm/local.h
13648+++ b/arch/x86/include/asm/local.h
13649@@ -10,33 +10,97 @@ typedef struct {
13650 atomic_long_t a;
13651 } local_t;
13652
13653+typedef struct {
13654+ atomic_long_unchecked_t a;
13655+} local_unchecked_t;
13656+
13657 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13658
13659 #define local_read(l) atomic_long_read(&(l)->a)
13660+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13661 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13662+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13663
13664 static inline void local_inc(local_t *l)
13665 {
13666- asm volatile(_ASM_INC "%0"
13667+ asm volatile(_ASM_INC "%0\n"
13668+
13669+#ifdef CONFIG_PAX_REFCOUNT
13670+ "jno 0f\n"
13671+ _ASM_DEC "%0\n"
13672+ "int $4\n0:\n"
13673+ _ASM_EXTABLE(0b, 0b)
13674+#endif
13675+
13676+ : "+m" (l->a.counter));
13677+}
13678+
13679+static inline void local_inc_unchecked(local_unchecked_t *l)
13680+{
13681+ asm volatile(_ASM_INC "%0\n"
13682 : "+m" (l->a.counter));
13683 }
13684
13685 static inline void local_dec(local_t *l)
13686 {
13687- asm volatile(_ASM_DEC "%0"
13688+ asm volatile(_ASM_DEC "%0\n"
13689+
13690+#ifdef CONFIG_PAX_REFCOUNT
13691+ "jno 0f\n"
13692+ _ASM_INC "%0\n"
13693+ "int $4\n0:\n"
13694+ _ASM_EXTABLE(0b, 0b)
13695+#endif
13696+
13697+ : "+m" (l->a.counter));
13698+}
13699+
13700+static inline void local_dec_unchecked(local_unchecked_t *l)
13701+{
13702+ asm volatile(_ASM_DEC "%0\n"
13703 : "+m" (l->a.counter));
13704 }
13705
13706 static inline void local_add(long i, local_t *l)
13707 {
13708- asm volatile(_ASM_ADD "%1,%0"
13709+ asm volatile(_ASM_ADD "%1,%0\n"
13710+
13711+#ifdef CONFIG_PAX_REFCOUNT
13712+ "jno 0f\n"
13713+ _ASM_SUB "%1,%0\n"
13714+ "int $4\n0:\n"
13715+ _ASM_EXTABLE(0b, 0b)
13716+#endif
13717+
13718+ : "+m" (l->a.counter)
13719+ : "ir" (i));
13720+}
13721+
13722+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13723+{
13724+ asm volatile(_ASM_ADD "%1,%0\n"
13725 : "+m" (l->a.counter)
13726 : "ir" (i));
13727 }
13728
13729 static inline void local_sub(long i, local_t *l)
13730 {
13731- asm volatile(_ASM_SUB "%1,%0"
13732+ asm volatile(_ASM_SUB "%1,%0\n"
13733+
13734+#ifdef CONFIG_PAX_REFCOUNT
13735+ "jno 0f\n"
13736+ _ASM_ADD "%1,%0\n"
13737+ "int $4\n0:\n"
13738+ _ASM_EXTABLE(0b, 0b)
13739+#endif
13740+
13741+ : "+m" (l->a.counter)
13742+ : "ir" (i));
13743+}
13744+
13745+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13746+{
13747+ asm volatile(_ASM_SUB "%1,%0\n"
13748 : "+m" (l->a.counter)
13749 : "ir" (i));
13750 }
13751@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13752 {
13753 unsigned char c;
13754
13755- asm volatile(_ASM_SUB "%2,%0; sete %1"
13756+ asm volatile(_ASM_SUB "%2,%0\n"
13757+
13758+#ifdef CONFIG_PAX_REFCOUNT
13759+ "jno 0f\n"
13760+ _ASM_ADD "%2,%0\n"
13761+ "int $4\n0:\n"
13762+ _ASM_EXTABLE(0b, 0b)
13763+#endif
13764+
13765+ "sete %1\n"
13766 : "+m" (l->a.counter), "=qm" (c)
13767 : "ir" (i) : "memory");
13768 return c;
13769@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13770 {
13771 unsigned char c;
13772
13773- asm volatile(_ASM_DEC "%0; sete %1"
13774+ asm volatile(_ASM_DEC "%0\n"
13775+
13776+#ifdef CONFIG_PAX_REFCOUNT
13777+ "jno 0f\n"
13778+ _ASM_INC "%0\n"
13779+ "int $4\n0:\n"
13780+ _ASM_EXTABLE(0b, 0b)
13781+#endif
13782+
13783+ "sete %1\n"
13784 : "+m" (l->a.counter), "=qm" (c)
13785 : : "memory");
13786 return c != 0;
13787@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13788 {
13789 unsigned char c;
13790
13791- asm volatile(_ASM_INC "%0; sete %1"
13792+ asm volatile(_ASM_INC "%0\n"
13793+
13794+#ifdef CONFIG_PAX_REFCOUNT
13795+ "jno 0f\n"
13796+ _ASM_DEC "%0\n"
13797+ "int $4\n0:\n"
13798+ _ASM_EXTABLE(0b, 0b)
13799+#endif
13800+
13801+ "sete %1\n"
13802 : "+m" (l->a.counter), "=qm" (c)
13803 : : "memory");
13804 return c != 0;
13805@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13806 {
13807 unsigned char c;
13808
13809- asm volatile(_ASM_ADD "%2,%0; sets %1"
13810+ asm volatile(_ASM_ADD "%2,%0\n"
13811+
13812+#ifdef CONFIG_PAX_REFCOUNT
13813+ "jno 0f\n"
13814+ _ASM_SUB "%2,%0\n"
13815+ "int $4\n0:\n"
13816+ _ASM_EXTABLE(0b, 0b)
13817+#endif
13818+
13819+ "sets %1\n"
13820 : "+m" (l->a.counter), "=qm" (c)
13821 : "ir" (i) : "memory");
13822 return c;
13823@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13824 static inline long local_add_return(long i, local_t *l)
13825 {
13826 long __i = i;
13827+ asm volatile(_ASM_XADD "%0, %1\n"
13828+
13829+#ifdef CONFIG_PAX_REFCOUNT
13830+ "jno 0f\n"
13831+ _ASM_MOV "%0,%1\n"
13832+ "int $4\n0:\n"
13833+ _ASM_EXTABLE(0b, 0b)
13834+#endif
13835+
13836+ : "+r" (i), "+m" (l->a.counter)
13837+ : : "memory");
13838+ return i + __i;
13839+}
13840+
13841+/**
13842+ * local_add_return_unchecked - add and return
13843+ * @i: integer value to add
13844+ * @l: pointer to type local_unchecked_t
13845+ *
13846+ * Atomically adds @i to @l and returns @i + @l
13847+ */
13848+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13849+{
13850+ long __i = i;
13851 asm volatile(_ASM_XADD "%0, %1;"
13852 : "+r" (i), "+m" (l->a.counter)
13853 : : "memory");
13854@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13855
13856 #define local_cmpxchg(l, o, n) \
13857 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13858+#define local_cmpxchg_unchecked(l, o, n) \
13859+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13860 /* Always has a lock prefix */
13861 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13862
13863diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13864new file mode 100644
13865index 0000000..2bfd3ba
13866--- /dev/null
13867+++ b/arch/x86/include/asm/mman.h
13868@@ -0,0 +1,15 @@
13869+#ifndef _X86_MMAN_H
13870+#define _X86_MMAN_H
13871+
13872+#include <uapi/asm/mman.h>
13873+
13874+#ifdef __KERNEL__
13875+#ifndef __ASSEMBLY__
13876+#ifdef CONFIG_X86_32
13877+#define arch_mmap_check i386_mmap_check
13878+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13879+#endif
13880+#endif
13881+#endif
13882+
13883+#endif /* X86_MMAN_H */
13884diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13885index 5f55e69..e20bfb1 100644
13886--- a/arch/x86/include/asm/mmu.h
13887+++ b/arch/x86/include/asm/mmu.h
13888@@ -9,7 +9,7 @@
13889 * we put the segment information here.
13890 */
13891 typedef struct {
13892- void *ldt;
13893+ struct desc_struct *ldt;
13894 int size;
13895
13896 #ifdef CONFIG_X86_64
13897@@ -18,7 +18,19 @@ typedef struct {
13898 #endif
13899
13900 struct mutex lock;
13901- void *vdso;
13902+ unsigned long vdso;
13903+
13904+#ifdef CONFIG_X86_32
13905+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13906+ unsigned long user_cs_base;
13907+ unsigned long user_cs_limit;
13908+
13909+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13910+ cpumask_t cpu_user_cs_mask;
13911+#endif
13912+
13913+#endif
13914+#endif
13915 } mm_context_t;
13916
13917 #ifdef CONFIG_SMP
13918diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13919index cdbf367..adb37ac 100644
13920--- a/arch/x86/include/asm/mmu_context.h
13921+++ b/arch/x86/include/asm/mmu_context.h
13922@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13923
13924 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13925 {
13926+
13927+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13928+ unsigned int i;
13929+ pgd_t *pgd;
13930+
13931+ pax_open_kernel();
13932+ pgd = get_cpu_pgd(smp_processor_id());
13933+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13934+ set_pgd_batched(pgd+i, native_make_pgd(0));
13935+ pax_close_kernel();
13936+#endif
13937+
13938 #ifdef CONFIG_SMP
13939 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13940 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13941@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13942 struct task_struct *tsk)
13943 {
13944 unsigned cpu = smp_processor_id();
13945+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13946+ int tlbstate = TLBSTATE_OK;
13947+#endif
13948
13949 if (likely(prev != next)) {
13950 #ifdef CONFIG_SMP
13951+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13952+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13953+#endif
13954 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13955 this_cpu_write(cpu_tlbstate.active_mm, next);
13956 #endif
13957 cpumask_set_cpu(cpu, mm_cpumask(next));
13958
13959 /* Re-load page tables */
13960+#ifdef CONFIG_PAX_PER_CPU_PGD
13961+ pax_open_kernel();
13962+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13963+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13964+ pax_close_kernel();
13965+ load_cr3(get_cpu_pgd(cpu));
13966+#else
13967 load_cr3(next->pgd);
13968+#endif
13969
13970 /* stop flush ipis for the previous mm */
13971 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13972@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13973 */
13974 if (unlikely(prev->context.ldt != next->context.ldt))
13975 load_LDT_nolock(&next->context);
13976- }
13977+
13978+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13979+ if (!(__supported_pte_mask & _PAGE_NX)) {
13980+ smp_mb__before_clear_bit();
13981+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13982+ smp_mb__after_clear_bit();
13983+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13984+ }
13985+#endif
13986+
13987+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13988+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13989+ prev->context.user_cs_limit != next->context.user_cs_limit))
13990+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13991 #ifdef CONFIG_SMP
13992+ else if (unlikely(tlbstate != TLBSTATE_OK))
13993+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13994+#endif
13995+#endif
13996+
13997+ }
13998 else {
13999+
14000+#ifdef CONFIG_PAX_PER_CPU_PGD
14001+ pax_open_kernel();
14002+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
14003+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
14004+ pax_close_kernel();
14005+ load_cr3(get_cpu_pgd(cpu));
14006+#endif
14007+
14008+#ifdef CONFIG_SMP
14009 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
14010 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
14011
14012@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14013 * tlb flush IPI delivery. We must reload CR3
14014 * to make sure to use no freed page tables.
14015 */
14016+
14017+#ifndef CONFIG_PAX_PER_CPU_PGD
14018 load_cr3(next->pgd);
14019+#endif
14020+
14021 load_LDT_nolock(&next->context);
14022+
14023+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14024+ if (!(__supported_pte_mask & _PAGE_NX))
14025+ cpu_set(cpu, next->context.cpu_user_cs_mask);
14026+#endif
14027+
14028+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14029+#ifdef CONFIG_PAX_PAGEEXEC
14030+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
14031+#endif
14032+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14033+#endif
14034+
14035 }
14036+#endif
14037 }
14038-#endif
14039 }
14040
14041 #define activate_mm(prev, next) \
14042diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
14043index e3b7819..b257c64 100644
14044--- a/arch/x86/include/asm/module.h
14045+++ b/arch/x86/include/asm/module.h
14046@@ -5,6 +5,7 @@
14047
14048 #ifdef CONFIG_X86_64
14049 /* X86_64 does not define MODULE_PROC_FAMILY */
14050+#define MODULE_PROC_FAMILY ""
14051 #elif defined CONFIG_M486
14052 #define MODULE_PROC_FAMILY "486 "
14053 #elif defined CONFIG_M586
14054@@ -57,8 +58,20 @@
14055 #error unknown processor family
14056 #endif
14057
14058-#ifdef CONFIG_X86_32
14059-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
14060+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14061+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
14062+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
14063+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
14064+#else
14065+#define MODULE_PAX_KERNEXEC ""
14066 #endif
14067
14068+#ifdef CONFIG_PAX_MEMORY_UDEREF
14069+#define MODULE_PAX_UDEREF "UDEREF "
14070+#else
14071+#define MODULE_PAX_UDEREF ""
14072+#endif
14073+
14074+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
14075+
14076 #endif /* _ASM_X86_MODULE_H */
14077diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
14078index c0fa356..07a498a 100644
14079--- a/arch/x86/include/asm/nmi.h
14080+++ b/arch/x86/include/asm/nmi.h
14081@@ -42,11 +42,11 @@ struct nmiaction {
14082 nmi_handler_t handler;
14083 unsigned long flags;
14084 const char *name;
14085-};
14086+} __do_const;
14087
14088 #define register_nmi_handler(t, fn, fg, n, init...) \
14089 ({ \
14090- static struct nmiaction init fn##_na = { \
14091+ static const struct nmiaction init fn##_na = { \
14092 .handler = (fn), \
14093 .name = (n), \
14094 .flags = (fg), \
14095@@ -54,7 +54,7 @@ struct nmiaction {
14096 __register_nmi_handler((t), &fn##_na); \
14097 })
14098
14099-int __register_nmi_handler(unsigned int, struct nmiaction *);
14100+int __register_nmi_handler(unsigned int, const struct nmiaction *);
14101
14102 void unregister_nmi_handler(unsigned int, const char *);
14103
14104diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
14105index c878924..21f4889 100644
14106--- a/arch/x86/include/asm/page.h
14107+++ b/arch/x86/include/asm/page.h
14108@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
14109 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
14110
14111 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
14112+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
14113
14114 #define __boot_va(x) __va(x)
14115 #define __boot_pa(x) __pa(x)
14116diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
14117index 0f1ddee..e2fc3d1 100644
14118--- a/arch/x86/include/asm/page_64.h
14119+++ b/arch/x86/include/asm/page_64.h
14120@@ -7,9 +7,9 @@
14121
14122 /* duplicated to the one in bootmem.h */
14123 extern unsigned long max_pfn;
14124-extern unsigned long phys_base;
14125+extern const unsigned long phys_base;
14126
14127-static inline unsigned long __phys_addr_nodebug(unsigned long x)
14128+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
14129 {
14130 unsigned long y = x - __START_KERNEL_map;
14131
14132diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
14133index 7361e47..16dc226 100644
14134--- a/arch/x86/include/asm/paravirt.h
14135+++ b/arch/x86/include/asm/paravirt.h
14136@@ -564,7 +564,7 @@ static inline pmd_t __pmd(pmdval_t val)
14137 return (pmd_t) { ret };
14138 }
14139
14140-static inline pmdval_t pmd_val(pmd_t pmd)
14141+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14142 {
14143 pmdval_t ret;
14144
14145@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14146 val);
14147 }
14148
14149+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14150+{
14151+ pgdval_t val = native_pgd_val(pgd);
14152+
14153+ if (sizeof(pgdval_t) > sizeof(long))
14154+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14155+ val, (u64)val >> 32);
14156+ else
14157+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14158+ val);
14159+}
14160+
14161 static inline void pgd_clear(pgd_t *pgdp)
14162 {
14163 set_pgd(pgdp, __pgd(0));
14164@@ -714,6 +726,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14165 pv_mmu_ops.set_fixmap(idx, phys, flags);
14166 }
14167
14168+#ifdef CONFIG_PAX_KERNEXEC
14169+static inline unsigned long pax_open_kernel(void)
14170+{
14171+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14172+}
14173+
14174+static inline unsigned long pax_close_kernel(void)
14175+{
14176+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14177+}
14178+#else
14179+static inline unsigned long pax_open_kernel(void) { return 0; }
14180+static inline unsigned long pax_close_kernel(void) { return 0; }
14181+#endif
14182+
14183 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14184
14185 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14186@@ -930,7 +957,7 @@ extern void default_banner(void);
14187
14188 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14189 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14190-#define PARA_INDIRECT(addr) *%cs:addr
14191+#define PARA_INDIRECT(addr) *%ss:addr
14192 #endif
14193
14194 #define INTERRUPT_RETURN \
14195@@ -1005,6 +1032,21 @@ extern void default_banner(void);
14196 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14197 CLBR_NONE, \
14198 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14199+
14200+#define GET_CR0_INTO_RDI \
14201+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14202+ mov %rax,%rdi
14203+
14204+#define SET_RDI_INTO_CR0 \
14205+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14206+
14207+#define GET_CR3_INTO_RDI \
14208+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14209+ mov %rax,%rdi
14210+
14211+#define SET_RDI_INTO_CR3 \
14212+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14213+
14214 #endif /* CONFIG_X86_32 */
14215
14216 #endif /* __ASSEMBLY__ */
14217diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14218index b3b0ec1..b1cd3eb 100644
14219--- a/arch/x86/include/asm/paravirt_types.h
14220+++ b/arch/x86/include/asm/paravirt_types.h
14221@@ -84,7 +84,7 @@ struct pv_init_ops {
14222 */
14223 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14224 unsigned long addr, unsigned len);
14225-};
14226+} __no_const;
14227
14228
14229 struct pv_lazy_ops {
14230@@ -98,7 +98,7 @@ struct pv_time_ops {
14231 unsigned long long (*sched_clock)(void);
14232 unsigned long long (*steal_clock)(int cpu);
14233 unsigned long (*get_tsc_khz)(void);
14234-};
14235+} __no_const;
14236
14237 struct pv_cpu_ops {
14238 /* hooks for various privileged instructions */
14239@@ -192,7 +192,7 @@ struct pv_cpu_ops {
14240
14241 void (*start_context_switch)(struct task_struct *prev);
14242 void (*end_context_switch)(struct task_struct *next);
14243-};
14244+} __no_const;
14245
14246 struct pv_irq_ops {
14247 /*
14248@@ -223,7 +223,7 @@ struct pv_apic_ops {
14249 unsigned long start_eip,
14250 unsigned long start_esp);
14251 #endif
14252-};
14253+} __no_const;
14254
14255 struct pv_mmu_ops {
14256 unsigned long (*read_cr2)(void);
14257@@ -313,6 +313,7 @@ struct pv_mmu_ops {
14258 struct paravirt_callee_save make_pud;
14259
14260 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14261+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14262 #endif /* PAGETABLE_LEVELS == 4 */
14263 #endif /* PAGETABLE_LEVELS >= 3 */
14264
14265@@ -324,6 +325,12 @@ struct pv_mmu_ops {
14266 an mfn. We can tell which is which from the index. */
14267 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14268 phys_addr_t phys, pgprot_t flags);
14269+
14270+#ifdef CONFIG_PAX_KERNEXEC
14271+ unsigned long (*pax_open_kernel)(void);
14272+ unsigned long (*pax_close_kernel)(void);
14273+#endif
14274+
14275 };
14276
14277 struct arch_spinlock;
14278@@ -334,7 +341,7 @@ struct pv_lock_ops {
14279 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14280 int (*spin_trylock)(struct arch_spinlock *lock);
14281 void (*spin_unlock)(struct arch_spinlock *lock);
14282-};
14283+} __no_const;
14284
14285 /* This contains all the paravirt structures: we get a convenient
14286 * number for each function using the offset which we use to indicate
14287diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14288index b4389a4..7024269 100644
14289--- a/arch/x86/include/asm/pgalloc.h
14290+++ b/arch/x86/include/asm/pgalloc.h
14291@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14292 pmd_t *pmd, pte_t *pte)
14293 {
14294 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14295+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14296+}
14297+
14298+static inline void pmd_populate_user(struct mm_struct *mm,
14299+ pmd_t *pmd, pte_t *pte)
14300+{
14301+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14302 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14303 }
14304
14305@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14306
14307 #ifdef CONFIG_X86_PAE
14308 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14309+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14310+{
14311+ pud_populate(mm, pudp, pmd);
14312+}
14313 #else /* !CONFIG_X86_PAE */
14314 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14315 {
14316 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14317 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14318 }
14319+
14320+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14321+{
14322+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14323+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14324+}
14325 #endif /* CONFIG_X86_PAE */
14326
14327 #if PAGETABLE_LEVELS > 3
14328@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14329 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14330 }
14331
14332+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14333+{
14334+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14335+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14336+}
14337+
14338 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14339 {
14340 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14341diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14342index f2b489c..4f7e2e5 100644
14343--- a/arch/x86/include/asm/pgtable-2level.h
14344+++ b/arch/x86/include/asm/pgtable-2level.h
14345@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14346
14347 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14348 {
14349+ pax_open_kernel();
14350 *pmdp = pmd;
14351+ pax_close_kernel();
14352 }
14353
14354 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14355diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14356index 4cc9f2b..5fd9226 100644
14357--- a/arch/x86/include/asm/pgtable-3level.h
14358+++ b/arch/x86/include/asm/pgtable-3level.h
14359@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14360
14361 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14362 {
14363+ pax_open_kernel();
14364 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14365+ pax_close_kernel();
14366 }
14367
14368 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14369 {
14370+ pax_open_kernel();
14371 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14372+ pax_close_kernel();
14373 }
14374
14375 /*
14376diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14377index 1e67223..dd6e7ea 100644
14378--- a/arch/x86/include/asm/pgtable.h
14379+++ b/arch/x86/include/asm/pgtable.h
14380@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14381
14382 #ifndef __PAGETABLE_PUD_FOLDED
14383 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14384+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14385 #define pgd_clear(pgd) native_pgd_clear(pgd)
14386 #endif
14387
14388@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14389
14390 #define arch_end_context_switch(prev) do {} while(0)
14391
14392+#define pax_open_kernel() native_pax_open_kernel()
14393+#define pax_close_kernel() native_pax_close_kernel()
14394 #endif /* CONFIG_PARAVIRT */
14395
14396+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14397+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14398+
14399+#ifdef CONFIG_PAX_KERNEXEC
14400+static inline unsigned long native_pax_open_kernel(void)
14401+{
14402+ unsigned long cr0;
14403+
14404+ preempt_disable();
14405+ barrier();
14406+ cr0 = read_cr0() ^ X86_CR0_WP;
14407+ BUG_ON(cr0 & X86_CR0_WP);
14408+ write_cr0(cr0);
14409+ return cr0 ^ X86_CR0_WP;
14410+}
14411+
14412+static inline unsigned long native_pax_close_kernel(void)
14413+{
14414+ unsigned long cr0;
14415+
14416+ cr0 = read_cr0() ^ X86_CR0_WP;
14417+ BUG_ON(!(cr0 & X86_CR0_WP));
14418+ write_cr0(cr0);
14419+ barrier();
14420+ preempt_enable_no_resched();
14421+ return cr0 ^ X86_CR0_WP;
14422+}
14423+#else
14424+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14425+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14426+#endif
14427+
14428 /*
14429 * The following only work if pte_present() is true.
14430 * Undefined behaviour if not..
14431 */
14432+static inline int pte_user(pte_t pte)
14433+{
14434+ return pte_val(pte) & _PAGE_USER;
14435+}
14436+
14437 static inline int pte_dirty(pte_t pte)
14438 {
14439 return pte_flags(pte) & _PAGE_DIRTY;
14440@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
14441 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
14442 }
14443
14444+static inline unsigned long pgd_pfn(pgd_t pgd)
14445+{
14446+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
14447+}
14448+
14449 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
14450
14451 static inline int pmd_large(pmd_t pte)
14452@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14453 return pte_clear_flags(pte, _PAGE_RW);
14454 }
14455
14456+static inline pte_t pte_mkread(pte_t pte)
14457+{
14458+ return __pte(pte_val(pte) | _PAGE_USER);
14459+}
14460+
14461 static inline pte_t pte_mkexec(pte_t pte)
14462 {
14463- return pte_clear_flags(pte, _PAGE_NX);
14464+#ifdef CONFIG_X86_PAE
14465+ if (__supported_pte_mask & _PAGE_NX)
14466+ return pte_clear_flags(pte, _PAGE_NX);
14467+ else
14468+#endif
14469+ return pte_set_flags(pte, _PAGE_USER);
14470+}
14471+
14472+static inline pte_t pte_exprotect(pte_t pte)
14473+{
14474+#ifdef CONFIG_X86_PAE
14475+ if (__supported_pte_mask & _PAGE_NX)
14476+ return pte_set_flags(pte, _PAGE_NX);
14477+ else
14478+#endif
14479+ return pte_clear_flags(pte, _PAGE_USER);
14480 }
14481
14482 static inline pte_t pte_mkdirty(pte_t pte)
14483@@ -394,6 +459,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14484 #endif
14485
14486 #ifndef __ASSEMBLY__
14487+
14488+#ifdef CONFIG_PAX_PER_CPU_PGD
14489+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14490+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14491+{
14492+ return cpu_pgd[cpu];
14493+}
14494+#endif
14495+
14496 #include <linux/mm_types.h>
14497 #include <linux/log2.h>
14498
14499@@ -529,7 +603,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
14500 * Currently stuck as a macro due to indirect forward reference to
14501 * linux/mmzone.h's __section_mem_map_addr() definition:
14502 */
14503-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
14504+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
14505
14506 /* Find an entry in the second-level page table.. */
14507 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
14508@@ -569,7 +643,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
14509 * Currently stuck as a macro due to indirect forward reference to
14510 * linux/mmzone.h's __section_mem_map_addr() definition:
14511 */
14512-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
14513+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
14514
14515 /* to find an entry in a page-table-directory. */
14516 static inline unsigned long pud_index(unsigned long address)
14517@@ -584,7 +658,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14518
14519 static inline int pgd_bad(pgd_t pgd)
14520 {
14521- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14522+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14523 }
14524
14525 static inline int pgd_none(pgd_t pgd)
14526@@ -607,7 +681,12 @@ static inline int pgd_none(pgd_t pgd)
14527 * pgd_offset() returns a (pgd_t *)
14528 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14529 */
14530-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14531+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14532+
14533+#ifdef CONFIG_PAX_PER_CPU_PGD
14534+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14535+#endif
14536+
14537 /*
14538 * a shortcut which implies the use of the kernel's pgd, instead
14539 * of a process's
14540@@ -618,6 +697,22 @@ static inline int pgd_none(pgd_t pgd)
14541 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14542 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14543
14544+#ifdef CONFIG_X86_32
14545+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14546+#else
14547+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14548+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14549+
14550+#ifdef CONFIG_PAX_MEMORY_UDEREF
14551+#ifdef __ASSEMBLY__
14552+#define pax_user_shadow_base pax_user_shadow_base(%rip)
14553+#else
14554+extern unsigned long pax_user_shadow_base;
14555+#endif
14556+#endif
14557+
14558+#endif
14559+
14560 #ifndef __ASSEMBLY__
14561
14562 extern int direct_gbpages;
14563@@ -784,11 +879,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14564 * dst and src can be on the same page, but the range must not overlap,
14565 * and must not cross a page boundary.
14566 */
14567-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14568+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14569 {
14570- memcpy(dst, src, count * sizeof(pgd_t));
14571+ pax_open_kernel();
14572+ while (count--)
14573+ *dst++ = *src++;
14574+ pax_close_kernel();
14575 }
14576
14577+#ifdef CONFIG_PAX_PER_CPU_PGD
14578+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14579+#endif
14580+
14581+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14582+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14583+#else
14584+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14585+#endif
14586+
14587 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
14588 static inline int page_level_shift(enum pg_level level)
14589 {
14590diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14591index 9ee3221..b979c6b 100644
14592--- a/arch/x86/include/asm/pgtable_32.h
14593+++ b/arch/x86/include/asm/pgtable_32.h
14594@@ -25,9 +25,6 @@
14595 struct mm_struct;
14596 struct vm_area_struct;
14597
14598-extern pgd_t swapper_pg_dir[1024];
14599-extern pgd_t initial_page_table[1024];
14600-
14601 static inline void pgtable_cache_init(void) { }
14602 static inline void check_pgt_cache(void) { }
14603 void paging_init(void);
14604@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14605 # include <asm/pgtable-2level.h>
14606 #endif
14607
14608+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14609+extern pgd_t initial_page_table[PTRS_PER_PGD];
14610+#ifdef CONFIG_X86_PAE
14611+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14612+#endif
14613+
14614 #if defined(CONFIG_HIGHPTE)
14615 #define pte_offset_map(dir, address) \
14616 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14617@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14618 /* Clear a kernel PTE and flush it from the TLB */
14619 #define kpte_clear_flush(ptep, vaddr) \
14620 do { \
14621+ pax_open_kernel(); \
14622 pte_clear(&init_mm, (vaddr), (ptep)); \
14623+ pax_close_kernel(); \
14624 __flush_tlb_one((vaddr)); \
14625 } while (0)
14626
14627 #endif /* !__ASSEMBLY__ */
14628
14629+#define HAVE_ARCH_UNMAPPED_AREA
14630+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14631+
14632 /*
14633 * kern_addr_valid() is (1) for FLATMEM and (0) for
14634 * SPARSEMEM and DISCONTIGMEM
14635diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14636index ed5903b..c7fe163 100644
14637--- a/arch/x86/include/asm/pgtable_32_types.h
14638+++ b/arch/x86/include/asm/pgtable_32_types.h
14639@@ -8,7 +8,7 @@
14640 */
14641 #ifdef CONFIG_X86_PAE
14642 # include <asm/pgtable-3level_types.h>
14643-# define PMD_SIZE (1UL << PMD_SHIFT)
14644+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14645 # define PMD_MASK (~(PMD_SIZE - 1))
14646 #else
14647 # include <asm/pgtable-2level_types.h>
14648@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14649 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14650 #endif
14651
14652+#ifdef CONFIG_PAX_KERNEXEC
14653+#ifndef __ASSEMBLY__
14654+extern unsigned char MODULES_EXEC_VADDR[];
14655+extern unsigned char MODULES_EXEC_END[];
14656+#endif
14657+#include <asm/boot.h>
14658+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14659+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14660+#else
14661+#define ktla_ktva(addr) (addr)
14662+#define ktva_ktla(addr) (addr)
14663+#endif
14664+
14665 #define MODULES_VADDR VMALLOC_START
14666 #define MODULES_END VMALLOC_END
14667 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14668diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14669index e22c1db..23a625a 100644
14670--- a/arch/x86/include/asm/pgtable_64.h
14671+++ b/arch/x86/include/asm/pgtable_64.h
14672@@ -16,10 +16,14 @@
14673
14674 extern pud_t level3_kernel_pgt[512];
14675 extern pud_t level3_ident_pgt[512];
14676+extern pud_t level3_vmalloc_start_pgt[512];
14677+extern pud_t level3_vmalloc_end_pgt[512];
14678+extern pud_t level3_vmemmap_pgt[512];
14679+extern pud_t level2_vmemmap_pgt[512];
14680 extern pmd_t level2_kernel_pgt[512];
14681 extern pmd_t level2_fixmap_pgt[512];
14682-extern pmd_t level2_ident_pgt[512];
14683-extern pgd_t init_level4_pgt[];
14684+extern pmd_t level2_ident_pgt[512*2];
14685+extern pgd_t init_level4_pgt[512];
14686
14687 #define swapper_pg_dir init_level4_pgt
14688
14689@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14690
14691 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14692 {
14693+ pax_open_kernel();
14694 *pmdp = pmd;
14695+ pax_close_kernel();
14696 }
14697
14698 static inline void native_pmd_clear(pmd_t *pmd)
14699@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14700
14701 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14702 {
14703+ pax_open_kernel();
14704 *pudp = pud;
14705+ pax_close_kernel();
14706 }
14707
14708 static inline void native_pud_clear(pud_t *pud)
14709@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14710
14711 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14712 {
14713+ pax_open_kernel();
14714+ *pgdp = pgd;
14715+ pax_close_kernel();
14716+}
14717+
14718+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14719+{
14720 *pgdp = pgd;
14721 }
14722
14723diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14724index 2d88344..4679fc3 100644
14725--- a/arch/x86/include/asm/pgtable_64_types.h
14726+++ b/arch/x86/include/asm/pgtable_64_types.h
14727@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
14728 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14729 #define MODULES_END _AC(0xffffffffff000000, UL)
14730 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14731+#define MODULES_EXEC_VADDR MODULES_VADDR
14732+#define MODULES_EXEC_END MODULES_END
14733+
14734+#define ktla_ktva(addr) (addr)
14735+#define ktva_ktla(addr) (addr)
14736
14737 #define EARLY_DYNAMIC_PAGE_TABLES 64
14738
14739diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14740index 567b5d0..bd91d64 100644
14741--- a/arch/x86/include/asm/pgtable_types.h
14742+++ b/arch/x86/include/asm/pgtable_types.h
14743@@ -16,13 +16,12 @@
14744 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14745 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14746 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14747-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14748+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14749 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14750 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14751 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14752-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14753-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14754-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14755+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14756+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14757 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14758
14759 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14760@@ -40,7 +39,6 @@
14761 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14762 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14763 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14764-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14765 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14766 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14767 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14768@@ -57,8 +55,10 @@
14769
14770 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14771 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14772-#else
14773+#elif defined(CONFIG_KMEMCHECK)
14774 #define _PAGE_NX (_AT(pteval_t, 0))
14775+#else
14776+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14777 #endif
14778
14779 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14780@@ -116,6 +116,9 @@
14781 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14782 _PAGE_ACCESSED)
14783
14784+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14785+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14786+
14787 #define __PAGE_KERNEL_EXEC \
14788 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14789 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14790@@ -126,7 +129,7 @@
14791 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14792 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14793 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14794-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14795+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14796 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14797 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14798 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14799@@ -188,8 +191,8 @@
14800 * bits are combined, this will alow user to access the high address mapped
14801 * VDSO in the presence of CONFIG_COMPAT_VDSO
14802 */
14803-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14804-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14805+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14806+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14807 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14808 #endif
14809
14810@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14811 {
14812 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14813 }
14814+#endif
14815
14816+#if PAGETABLE_LEVELS == 3
14817+#include <asm-generic/pgtable-nopud.h>
14818+#endif
14819+
14820+#if PAGETABLE_LEVELS == 2
14821+#include <asm-generic/pgtable-nopmd.h>
14822+#endif
14823+
14824+#ifndef __ASSEMBLY__
14825 #if PAGETABLE_LEVELS > 3
14826 typedef struct { pudval_t pud; } pud_t;
14827
14828@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14829 return pud.pud;
14830 }
14831 #else
14832-#include <asm-generic/pgtable-nopud.h>
14833-
14834 static inline pudval_t native_pud_val(pud_t pud)
14835 {
14836 return native_pgd_val(pud.pgd);
14837@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14838 return pmd.pmd;
14839 }
14840 #else
14841-#include <asm-generic/pgtable-nopmd.h>
14842-
14843 static inline pmdval_t native_pmd_val(pmd_t pmd)
14844 {
14845 return native_pgd_val(pmd.pud.pgd);
14846@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14847
14848 extern pteval_t __supported_pte_mask;
14849 extern void set_nx(void);
14850-extern int nx_enabled;
14851
14852 #define pgprot_writecombine pgprot_writecombine
14853 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14854diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14855index 3270116..8d99d82 100644
14856--- a/arch/x86/include/asm/processor.h
14857+++ b/arch/x86/include/asm/processor.h
14858@@ -285,7 +285,7 @@ struct tss_struct {
14859
14860 } ____cacheline_aligned;
14861
14862-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14863+extern struct tss_struct init_tss[NR_CPUS];
14864
14865 /*
14866 * Save the original ist values for checking stack pointers during debugging
14867@@ -826,11 +826,18 @@ static inline void spin_lock_prefetch(const void *x)
14868 */
14869 #define TASK_SIZE PAGE_OFFSET
14870 #define TASK_SIZE_MAX TASK_SIZE
14871+
14872+#ifdef CONFIG_PAX_SEGMEXEC
14873+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14874+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14875+#else
14876 #define STACK_TOP TASK_SIZE
14877-#define STACK_TOP_MAX STACK_TOP
14878+#endif
14879+
14880+#define STACK_TOP_MAX TASK_SIZE
14881
14882 #define INIT_THREAD { \
14883- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14884+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14885 .vm86_info = NULL, \
14886 .sysenter_cs = __KERNEL_CS, \
14887 .io_bitmap_ptr = NULL, \
14888@@ -844,7 +851,7 @@ static inline void spin_lock_prefetch(const void *x)
14889 */
14890 #define INIT_TSS { \
14891 .x86_tss = { \
14892- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14893+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14894 .ss0 = __KERNEL_DS, \
14895 .ss1 = __KERNEL_CS, \
14896 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14897@@ -855,11 +862,7 @@ static inline void spin_lock_prefetch(const void *x)
14898 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14899
14900 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14901-#define KSTK_TOP(info) \
14902-({ \
14903- unsigned long *__ptr = (unsigned long *)(info); \
14904- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14905-})
14906+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14907
14908 /*
14909 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14910@@ -874,7 +877,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14911 #define task_pt_regs(task) \
14912 ({ \
14913 struct pt_regs *__regs__; \
14914- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14915+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14916 __regs__ - 1; \
14917 })
14918
14919@@ -884,13 +887,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14920 /*
14921 * User space process size. 47bits minus one guard page.
14922 */
14923-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14924+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14925
14926 /* This decides where the kernel will search for a free chunk of vm
14927 * space during mmap's.
14928 */
14929 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14930- 0xc0000000 : 0xFFFFe000)
14931+ 0xc0000000 : 0xFFFFf000)
14932
14933 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14934 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14935@@ -901,11 +904,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14936 #define STACK_TOP_MAX TASK_SIZE_MAX
14937
14938 #define INIT_THREAD { \
14939- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14940+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14941 }
14942
14943 #define INIT_TSS { \
14944- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14945+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14946 }
14947
14948 /*
14949@@ -933,6 +936,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14950 */
14951 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14952
14953+#ifdef CONFIG_PAX_SEGMEXEC
14954+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14955+#endif
14956+
14957 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14958
14959 /* Get/set a process' ability to use the timestamp counter instruction */
14960@@ -993,7 +1000,7 @@ extern bool cpu_has_amd_erratum(const int *);
14961 #define cpu_has_amd_erratum(x) (false)
14962 #endif /* CONFIG_CPU_SUP_AMD */
14963
14964-extern unsigned long arch_align_stack(unsigned long sp);
14965+#define arch_align_stack(x) ((x) & ~0xfUL)
14966 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14967
14968 void default_idle(void);
14969@@ -1003,6 +1010,6 @@ bool xen_set_default_idle(void);
14970 #define xen_set_default_idle 0
14971 #endif
14972
14973-void stop_this_cpu(void *dummy);
14974+void stop_this_cpu(void *dummy) __noreturn;
14975
14976 #endif /* _ASM_X86_PROCESSOR_H */
14977diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14978index 942a086..6c26446 100644
14979--- a/arch/x86/include/asm/ptrace.h
14980+++ b/arch/x86/include/asm/ptrace.h
14981@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14982 }
14983
14984 /*
14985- * user_mode_vm(regs) determines whether a register set came from user mode.
14986+ * user_mode(regs) determines whether a register set came from user mode.
14987 * This is true if V8086 mode was enabled OR if the register set was from
14988 * protected mode with RPL-3 CS value. This tricky test checks that with
14989 * one comparison. Many places in the kernel can bypass this full check
14990- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14991+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14992+ * be used.
14993 */
14994-static inline int user_mode(struct pt_regs *regs)
14995+static inline int user_mode_novm(struct pt_regs *regs)
14996 {
14997 #ifdef CONFIG_X86_32
14998 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14999 #else
15000- return !!(regs->cs & 3);
15001+ return !!(regs->cs & SEGMENT_RPL_MASK);
15002 #endif
15003 }
15004
15005-static inline int user_mode_vm(struct pt_regs *regs)
15006+static inline int user_mode(struct pt_regs *regs)
15007 {
15008 #ifdef CONFIG_X86_32
15009 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
15010 USER_RPL;
15011 #else
15012- return user_mode(regs);
15013+ return user_mode_novm(regs);
15014 #endif
15015 }
15016
15017@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
15018 #ifdef CONFIG_X86_64
15019 static inline bool user_64bit_mode(struct pt_regs *regs)
15020 {
15021+ unsigned long cs = regs->cs & 0xffff;
15022 #ifndef CONFIG_PARAVIRT
15023 /*
15024 * On non-paravirt systems, this is the only long mode CPL 3
15025 * selector. We do not allow long mode selectors in the LDT.
15026 */
15027- return regs->cs == __USER_CS;
15028+ return cs == __USER_CS;
15029 #else
15030 /* Headers are too twisted for this to go in paravirt.h. */
15031- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
15032+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
15033 #endif
15034 }
15035
15036@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
15037 * Traps from the kernel do not save sp and ss.
15038 * Use the helper function to retrieve sp.
15039 */
15040- if (offset == offsetof(struct pt_regs, sp) &&
15041- regs->cs == __KERNEL_CS)
15042- return kernel_stack_pointer(regs);
15043+ if (offset == offsetof(struct pt_regs, sp)) {
15044+ unsigned long cs = regs->cs & 0xffff;
15045+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
15046+ return kernel_stack_pointer(regs);
15047+ }
15048 #endif
15049 return *(unsigned long *)((unsigned long)regs + offset);
15050 }
15051diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
15052index 9c6b890..5305f53 100644
15053--- a/arch/x86/include/asm/realmode.h
15054+++ b/arch/x86/include/asm/realmode.h
15055@@ -22,16 +22,14 @@ struct real_mode_header {
15056 #endif
15057 /* APM/BIOS reboot */
15058 u32 machine_real_restart_asm;
15059-#ifdef CONFIG_X86_64
15060 u32 machine_real_restart_seg;
15061-#endif
15062 };
15063
15064 /* This must match data at trampoline_32/64.S */
15065 struct trampoline_header {
15066 #ifdef CONFIG_X86_32
15067 u32 start;
15068- u16 gdt_pad;
15069+ u16 boot_cs;
15070 u16 gdt_limit;
15071 u32 gdt_base;
15072 #else
15073diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
15074index a82c4f1..ac45053 100644
15075--- a/arch/x86/include/asm/reboot.h
15076+++ b/arch/x86/include/asm/reboot.h
15077@@ -6,13 +6,13 @@
15078 struct pt_regs;
15079
15080 struct machine_ops {
15081- void (*restart)(char *cmd);
15082- void (*halt)(void);
15083- void (*power_off)(void);
15084+ void (* __noreturn restart)(char *cmd);
15085+ void (* __noreturn halt)(void);
15086+ void (* __noreturn power_off)(void);
15087 void (*shutdown)(void);
15088 void (*crash_shutdown)(struct pt_regs *);
15089- void (*emergency_restart)(void);
15090-};
15091+ void (* __noreturn emergency_restart)(void);
15092+} __no_const;
15093
15094 extern struct machine_ops machine_ops;
15095
15096diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
15097index 2dbe4a7..ce1db00 100644
15098--- a/arch/x86/include/asm/rwsem.h
15099+++ b/arch/x86/include/asm/rwsem.h
15100@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
15101 {
15102 asm volatile("# beginning down_read\n\t"
15103 LOCK_PREFIX _ASM_INC "(%1)\n\t"
15104+
15105+#ifdef CONFIG_PAX_REFCOUNT
15106+ "jno 0f\n"
15107+ LOCK_PREFIX _ASM_DEC "(%1)\n"
15108+ "int $4\n0:\n"
15109+ _ASM_EXTABLE(0b, 0b)
15110+#endif
15111+
15112 /* adds 0x00000001 */
15113 " jns 1f\n"
15114 " call call_rwsem_down_read_failed\n"
15115@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
15116 "1:\n\t"
15117 " mov %1,%2\n\t"
15118 " add %3,%2\n\t"
15119+
15120+#ifdef CONFIG_PAX_REFCOUNT
15121+ "jno 0f\n"
15122+ "sub %3,%2\n"
15123+ "int $4\n0:\n"
15124+ _ASM_EXTABLE(0b, 0b)
15125+#endif
15126+
15127 " jle 2f\n\t"
15128 LOCK_PREFIX " cmpxchg %2,%0\n\t"
15129 " jnz 1b\n\t"
15130@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
15131 long tmp;
15132 asm volatile("# beginning down_write\n\t"
15133 LOCK_PREFIX " xadd %1,(%2)\n\t"
15134+
15135+#ifdef CONFIG_PAX_REFCOUNT
15136+ "jno 0f\n"
15137+ "mov %1,(%2)\n"
15138+ "int $4\n0:\n"
15139+ _ASM_EXTABLE(0b, 0b)
15140+#endif
15141+
15142 /* adds 0xffff0001, returns the old value */
15143 " test %1,%1\n\t"
15144 /* was the count 0 before? */
15145@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
15146 long tmp;
15147 asm volatile("# beginning __up_read\n\t"
15148 LOCK_PREFIX " xadd %1,(%2)\n\t"
15149+
15150+#ifdef CONFIG_PAX_REFCOUNT
15151+ "jno 0f\n"
15152+ "mov %1,(%2)\n"
15153+ "int $4\n0:\n"
15154+ _ASM_EXTABLE(0b, 0b)
15155+#endif
15156+
15157 /* subtracts 1, returns the old value */
15158 " jns 1f\n\t"
15159 " call call_rwsem_wake\n" /* expects old value in %edx */
15160@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
15161 long tmp;
15162 asm volatile("# beginning __up_write\n\t"
15163 LOCK_PREFIX " xadd %1,(%2)\n\t"
15164+
15165+#ifdef CONFIG_PAX_REFCOUNT
15166+ "jno 0f\n"
15167+ "mov %1,(%2)\n"
15168+ "int $4\n0:\n"
15169+ _ASM_EXTABLE(0b, 0b)
15170+#endif
15171+
15172 /* subtracts 0xffff0001, returns the old value */
15173 " jns 1f\n\t"
15174 " call call_rwsem_wake\n" /* expects old value in %edx */
15175@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15176 {
15177 asm volatile("# beginning __downgrade_write\n\t"
15178 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15179+
15180+#ifdef CONFIG_PAX_REFCOUNT
15181+ "jno 0f\n"
15182+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15183+ "int $4\n0:\n"
15184+ _ASM_EXTABLE(0b, 0b)
15185+#endif
15186+
15187 /*
15188 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15189 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15190@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15191 */
15192 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15193 {
15194- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15195+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15196+
15197+#ifdef CONFIG_PAX_REFCOUNT
15198+ "jno 0f\n"
15199+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15200+ "int $4\n0:\n"
15201+ _ASM_EXTABLE(0b, 0b)
15202+#endif
15203+
15204 : "+m" (sem->count)
15205 : "er" (delta));
15206 }
15207@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15208 */
15209 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15210 {
15211- return delta + xadd(&sem->count, delta);
15212+ return delta + xadd_check_overflow(&sem->count, delta);
15213 }
15214
15215 #endif /* __KERNEL__ */
15216diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15217index c48a950..c6d7468 100644
15218--- a/arch/x86/include/asm/segment.h
15219+++ b/arch/x86/include/asm/segment.h
15220@@ -64,10 +64,15 @@
15221 * 26 - ESPFIX small SS
15222 * 27 - per-cpu [ offset to per-cpu data area ]
15223 * 28 - stack_canary-20 [ for stack protector ]
15224- * 29 - unused
15225- * 30 - unused
15226+ * 29 - PCI BIOS CS
15227+ * 30 - PCI BIOS DS
15228 * 31 - TSS for double fault handler
15229 */
15230+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15231+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15232+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15233+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15234+
15235 #define GDT_ENTRY_TLS_MIN 6
15236 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15237
15238@@ -79,6 +84,8 @@
15239
15240 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15241
15242+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15243+
15244 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15245
15246 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15247@@ -104,6 +111,12 @@
15248 #define __KERNEL_STACK_CANARY 0
15249 #endif
15250
15251+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15252+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15253+
15254+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15255+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15256+
15257 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15258
15259 /*
15260@@ -141,7 +154,7 @@
15261 */
15262
15263 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15264-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15265+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15266
15267
15268 #else
15269@@ -165,6 +178,8 @@
15270 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15271 #define __USER32_DS __USER_DS
15272
15273+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15274+
15275 #define GDT_ENTRY_TSS 8 /* needs two entries */
15276 #define GDT_ENTRY_LDT 10 /* needs two entries */
15277 #define GDT_ENTRY_TLS_MIN 12
15278@@ -185,6 +200,7 @@
15279 #endif
15280
15281 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15282+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15283 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15284 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15285 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15286@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15287 {
15288 unsigned long __limit;
15289 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15290- return __limit + 1;
15291+ return __limit;
15292 }
15293
15294 #endif /* !__ASSEMBLY__ */
15295diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15296index b073aae..39f9bdd 100644
15297--- a/arch/x86/include/asm/smp.h
15298+++ b/arch/x86/include/asm/smp.h
15299@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15300 /* cpus sharing the last level cache: */
15301 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15302 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15303-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15304+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15305
15306 static inline struct cpumask *cpu_sibling_mask(int cpu)
15307 {
15308@@ -79,7 +79,7 @@ struct smp_ops {
15309
15310 void (*send_call_func_ipi)(const struct cpumask *mask);
15311 void (*send_call_func_single_ipi)(int cpu);
15312-};
15313+} __no_const;
15314
15315 /* Globals due to paravirt */
15316 extern void set_cpu_sibling_map(int cpu);
15317@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15318 extern int safe_smp_processor_id(void);
15319
15320 #elif defined(CONFIG_X86_64_SMP)
15321-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15322-
15323-#define stack_smp_processor_id() \
15324-({ \
15325- struct thread_info *ti; \
15326- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15327- ti->cpu; \
15328-})
15329+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15330+#define stack_smp_processor_id() raw_smp_processor_id()
15331 #define safe_smp_processor_id() smp_processor_id()
15332
15333 #endif
15334diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15335index 33692ea..350a534 100644
15336--- a/arch/x86/include/asm/spinlock.h
15337+++ b/arch/x86/include/asm/spinlock.h
15338@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15339 static inline void arch_read_lock(arch_rwlock_t *rw)
15340 {
15341 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15342+
15343+#ifdef CONFIG_PAX_REFCOUNT
15344+ "jno 0f\n"
15345+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15346+ "int $4\n0:\n"
15347+ _ASM_EXTABLE(0b, 0b)
15348+#endif
15349+
15350 "jns 1f\n"
15351 "call __read_lock_failed\n\t"
15352 "1:\n"
15353@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15354 static inline void arch_write_lock(arch_rwlock_t *rw)
15355 {
15356 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15357+
15358+#ifdef CONFIG_PAX_REFCOUNT
15359+ "jno 0f\n"
15360+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15361+ "int $4\n0:\n"
15362+ _ASM_EXTABLE(0b, 0b)
15363+#endif
15364+
15365 "jz 1f\n"
15366 "call __write_lock_failed\n\t"
15367 "1:\n"
15368@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15369
15370 static inline void arch_read_unlock(arch_rwlock_t *rw)
15371 {
15372- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15373+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15374+
15375+#ifdef CONFIG_PAX_REFCOUNT
15376+ "jno 0f\n"
15377+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15378+ "int $4\n0:\n"
15379+ _ASM_EXTABLE(0b, 0b)
15380+#endif
15381+
15382 :"+m" (rw->lock) : : "memory");
15383 }
15384
15385 static inline void arch_write_unlock(arch_rwlock_t *rw)
15386 {
15387- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15388+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15389+
15390+#ifdef CONFIG_PAX_REFCOUNT
15391+ "jno 0f\n"
15392+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15393+ "int $4\n0:\n"
15394+ _ASM_EXTABLE(0b, 0b)
15395+#endif
15396+
15397 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15398 }
15399
15400diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15401index 6a99859..03cb807 100644
15402--- a/arch/x86/include/asm/stackprotector.h
15403+++ b/arch/x86/include/asm/stackprotector.h
15404@@ -47,7 +47,7 @@
15405 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15406 */
15407 #define GDT_STACK_CANARY_INIT \
15408- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15409+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15410
15411 /*
15412 * Initialize the stackprotector canary value.
15413@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15414
15415 static inline void load_stack_canary_segment(void)
15416 {
15417-#ifdef CONFIG_X86_32
15418+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15419 asm volatile ("mov %0, %%gs" : : "r" (0));
15420 #endif
15421 }
15422diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15423index 70bbe39..4ae2bd4 100644
15424--- a/arch/x86/include/asm/stacktrace.h
15425+++ b/arch/x86/include/asm/stacktrace.h
15426@@ -11,28 +11,20 @@
15427
15428 extern int kstack_depth_to_print;
15429
15430-struct thread_info;
15431+struct task_struct;
15432 struct stacktrace_ops;
15433
15434-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15435- unsigned long *stack,
15436- unsigned long bp,
15437- const struct stacktrace_ops *ops,
15438- void *data,
15439- unsigned long *end,
15440- int *graph);
15441+typedef unsigned long walk_stack_t(struct task_struct *task,
15442+ void *stack_start,
15443+ unsigned long *stack,
15444+ unsigned long bp,
15445+ const struct stacktrace_ops *ops,
15446+ void *data,
15447+ unsigned long *end,
15448+ int *graph);
15449
15450-extern unsigned long
15451-print_context_stack(struct thread_info *tinfo,
15452- unsigned long *stack, unsigned long bp,
15453- const struct stacktrace_ops *ops, void *data,
15454- unsigned long *end, int *graph);
15455-
15456-extern unsigned long
15457-print_context_stack_bp(struct thread_info *tinfo,
15458- unsigned long *stack, unsigned long bp,
15459- const struct stacktrace_ops *ops, void *data,
15460- unsigned long *end, int *graph);
15461+extern walk_stack_t print_context_stack;
15462+extern walk_stack_t print_context_stack_bp;
15463
15464 /* Generic stack tracer with callbacks */
15465
15466@@ -40,7 +32,7 @@ struct stacktrace_ops {
15467 void (*address)(void *data, unsigned long address, int reliable);
15468 /* On negative return stop dumping */
15469 int (*stack)(void *data, char *name);
15470- walk_stack_t walk_stack;
15471+ walk_stack_t *walk_stack;
15472 };
15473
15474 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15475diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15476index 4ec45b3..a4f0a8a 100644
15477--- a/arch/x86/include/asm/switch_to.h
15478+++ b/arch/x86/include/asm/switch_to.h
15479@@ -108,7 +108,7 @@ do { \
15480 "call __switch_to\n\t" \
15481 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15482 __switch_canary \
15483- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15484+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15485 "movq %%rax,%%rdi\n\t" \
15486 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15487 "jnz ret_from_fork\n\t" \
15488@@ -119,7 +119,7 @@ do { \
15489 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15490 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15491 [_tif_fork] "i" (_TIF_FORK), \
15492- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15493+ [thread_info] "m" (current_tinfo), \
15494 [current_task] "m" (current_task) \
15495 __switch_canary_iparam \
15496 : "memory", "cc" __EXTRA_CLOBBER)
15497diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15498index 2cd056e..0224df8 100644
15499--- a/arch/x86/include/asm/thread_info.h
15500+++ b/arch/x86/include/asm/thread_info.h
15501@@ -10,6 +10,7 @@
15502 #include <linux/compiler.h>
15503 #include <asm/page.h>
15504 #include <asm/types.h>
15505+#include <asm/percpu.h>
15506
15507 /*
15508 * low level task data that entry.S needs immediate access to
15509@@ -23,7 +24,6 @@ struct exec_domain;
15510 #include <linux/atomic.h>
15511
15512 struct thread_info {
15513- struct task_struct *task; /* main task structure */
15514 struct exec_domain *exec_domain; /* execution domain */
15515 __u32 flags; /* low level flags */
15516 __u32 status; /* thread synchronous flags */
15517@@ -33,19 +33,13 @@ struct thread_info {
15518 mm_segment_t addr_limit;
15519 struct restart_block restart_block;
15520 void __user *sysenter_return;
15521-#ifdef CONFIG_X86_32
15522- unsigned long previous_esp; /* ESP of the previous stack in
15523- case of nested (IRQ) stacks
15524- */
15525- __u8 supervisor_stack[0];
15526-#endif
15527+ unsigned long lowest_stack;
15528 unsigned int sig_on_uaccess_error:1;
15529 unsigned int uaccess_err:1; /* uaccess failed */
15530 };
15531
15532-#define INIT_THREAD_INFO(tsk) \
15533+#define INIT_THREAD_INFO \
15534 { \
15535- .task = &tsk, \
15536 .exec_domain = &default_exec_domain, \
15537 .flags = 0, \
15538 .cpu = 0, \
15539@@ -56,7 +50,7 @@ struct thread_info {
15540 }, \
15541 }
15542
15543-#define init_thread_info (init_thread_union.thread_info)
15544+#define init_thread_info (init_thread_union.stack)
15545 #define init_stack (init_thread_union.stack)
15546
15547 #else /* !__ASSEMBLY__ */
15548@@ -97,6 +91,7 @@ struct thread_info {
15549 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15550 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15551 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15552+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15553
15554 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15555 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15556@@ -121,17 +116,18 @@ struct thread_info {
15557 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15558 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15559 #define _TIF_X32 (1 << TIF_X32)
15560+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15561
15562 /* work to do in syscall_trace_enter() */
15563 #define _TIF_WORK_SYSCALL_ENTRY \
15564 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15565 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15566- _TIF_NOHZ)
15567+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15568
15569 /* work to do in syscall_trace_leave() */
15570 #define _TIF_WORK_SYSCALL_EXIT \
15571 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15572- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15573+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15574
15575 /* work to do on interrupt/exception return */
15576 #define _TIF_WORK_MASK \
15577@@ -142,7 +138,7 @@ struct thread_info {
15578 /* work to do on any return to user space */
15579 #define _TIF_ALLWORK_MASK \
15580 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15581- _TIF_NOHZ)
15582+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15583
15584 /* Only used for 64 bit */
15585 #define _TIF_DO_NOTIFY_MASK \
15586@@ -158,45 +154,40 @@ struct thread_info {
15587
15588 #define PREEMPT_ACTIVE 0x10000000
15589
15590-#ifdef CONFIG_X86_32
15591-
15592-#define STACK_WARN (THREAD_SIZE/8)
15593-/*
15594- * macros/functions for gaining access to the thread information structure
15595- *
15596- * preempt_count needs to be 1 initially, until the scheduler is functional.
15597- */
15598-#ifndef __ASSEMBLY__
15599-
15600-
15601-/* how to get the current stack pointer from C */
15602-register unsigned long current_stack_pointer asm("esp") __used;
15603-
15604-/* how to get the thread information struct from C */
15605-static inline struct thread_info *current_thread_info(void)
15606-{
15607- return (struct thread_info *)
15608- (current_stack_pointer & ~(THREAD_SIZE - 1));
15609-}
15610-
15611-#else /* !__ASSEMBLY__ */
15612-
15613+#ifdef __ASSEMBLY__
15614 /* how to get the thread information struct from ASM */
15615 #define GET_THREAD_INFO(reg) \
15616- movl $-THREAD_SIZE, reg; \
15617- andl %esp, reg
15618+ mov PER_CPU_VAR(current_tinfo), reg
15619
15620 /* use this one if reg already contains %esp */
15621-#define GET_THREAD_INFO_WITH_ESP(reg) \
15622- andl $-THREAD_SIZE, reg
15623+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15624+#else
15625+/* how to get the thread information struct from C */
15626+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15627+
15628+static __always_inline struct thread_info *current_thread_info(void)
15629+{
15630+ return this_cpu_read_stable(current_tinfo);
15631+}
15632+#endif
15633+
15634+#ifdef CONFIG_X86_32
15635+
15636+#define STACK_WARN (THREAD_SIZE/8)
15637+/*
15638+ * macros/functions for gaining access to the thread information structure
15639+ *
15640+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15641+ */
15642+#ifndef __ASSEMBLY__
15643+
15644+/* how to get the current stack pointer from C */
15645+register unsigned long current_stack_pointer asm("esp") __used;
15646
15647 #endif
15648
15649 #else /* X86_32 */
15650
15651-#include <asm/percpu.h>
15652-#define KERNEL_STACK_OFFSET (5*8)
15653-
15654 /*
15655 * macros/functions for gaining access to the thread information structure
15656 * preempt_count needs to be 1 initially, until the scheduler is functional.
15657@@ -204,27 +195,8 @@ static inline struct thread_info *current_thread_info(void)
15658 #ifndef __ASSEMBLY__
15659 DECLARE_PER_CPU(unsigned long, kernel_stack);
15660
15661-static inline struct thread_info *current_thread_info(void)
15662-{
15663- struct thread_info *ti;
15664- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15665- KERNEL_STACK_OFFSET - THREAD_SIZE);
15666- return ti;
15667-}
15668-
15669-#else /* !__ASSEMBLY__ */
15670-
15671-/* how to get the thread information struct from ASM */
15672-#define GET_THREAD_INFO(reg) \
15673- movq PER_CPU_VAR(kernel_stack),reg ; \
15674- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15675-
15676-/*
15677- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15678- * a certain register (to be used in assembler memory operands).
15679- */
15680-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15681-
15682+/* how to get the current stack pointer from C */
15683+register unsigned long current_stack_pointer asm("rsp") __used;
15684 #endif
15685
15686 #endif /* !X86_32 */
15687@@ -285,5 +257,12 @@ static inline bool is_ia32_task(void)
15688 extern void arch_task_cache_init(void);
15689 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15690 extern void arch_release_task_struct(struct task_struct *tsk);
15691+
15692+#define __HAVE_THREAD_FUNCTIONS
15693+#define task_thread_info(task) (&(task)->tinfo)
15694+#define task_stack_page(task) ((task)->stack)
15695+#define setup_thread_stack(p, org) do {} while (0)
15696+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15697+
15698 #endif
15699 #endif /* _ASM_X86_THREAD_INFO_H */
15700diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15701index 5ee2687..70d5895 100644
15702--- a/arch/x86/include/asm/uaccess.h
15703+++ b/arch/x86/include/asm/uaccess.h
15704@@ -7,6 +7,7 @@
15705 #include <linux/compiler.h>
15706 #include <linux/thread_info.h>
15707 #include <linux/string.h>
15708+#include <linux/sched.h>
15709 #include <asm/asm.h>
15710 #include <asm/page.h>
15711 #include <asm/smap.h>
15712@@ -29,7 +30,12 @@
15713
15714 #define get_ds() (KERNEL_DS)
15715 #define get_fs() (current_thread_info()->addr_limit)
15716+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15717+void __set_fs(mm_segment_t x);
15718+void set_fs(mm_segment_t x);
15719+#else
15720 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15721+#endif
15722
15723 #define segment_eq(a, b) ((a).seg == (b).seg)
15724
15725@@ -77,8 +83,33 @@
15726 * checks that the pointer is in the user space range - after calling
15727 * this function, memory access functions may still return -EFAULT.
15728 */
15729-#define access_ok(type, addr, size) \
15730- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15731+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15732+#define access_ok(type, addr, size) \
15733+({ \
15734+ long __size = size; \
15735+ unsigned long __addr = (unsigned long)addr; \
15736+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15737+ unsigned long __end_ao = __addr + __size - 1; \
15738+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15739+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15740+ while(__addr_ao <= __end_ao) { \
15741+ char __c_ao; \
15742+ __addr_ao += PAGE_SIZE; \
15743+ if (__size > PAGE_SIZE) \
15744+ cond_resched(); \
15745+ if (__get_user(__c_ao, (char __user *)__addr)) \
15746+ break; \
15747+ if (type != VERIFY_WRITE) { \
15748+ __addr = __addr_ao; \
15749+ continue; \
15750+ } \
15751+ if (__put_user(__c_ao, (char __user *)__addr)) \
15752+ break; \
15753+ __addr = __addr_ao; \
15754+ } \
15755+ } \
15756+ __ret_ao; \
15757+})
15758
15759 /*
15760 * The exception table consists of pairs of addresses relative to the
15761@@ -176,13 +207,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15762 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15763 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15764
15765-
15766+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15767+#define __copyuser_seg "gs;"
15768+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15769+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15770+#else
15771+#define __copyuser_seg
15772+#define __COPYUSER_SET_ES
15773+#define __COPYUSER_RESTORE_ES
15774+#endif
15775
15776 #ifdef CONFIG_X86_32
15777 #define __put_user_asm_u64(x, addr, err, errret) \
15778 asm volatile(ASM_STAC "\n" \
15779- "1: movl %%eax,0(%2)\n" \
15780- "2: movl %%edx,4(%2)\n" \
15781+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15782+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15783 "3: " ASM_CLAC "\n" \
15784 ".section .fixup,\"ax\"\n" \
15785 "4: movl %3,%0\n" \
15786@@ -195,8 +234,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15787
15788 #define __put_user_asm_ex_u64(x, addr) \
15789 asm volatile(ASM_STAC "\n" \
15790- "1: movl %%eax,0(%1)\n" \
15791- "2: movl %%edx,4(%1)\n" \
15792+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15793+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15794 "3: " ASM_CLAC "\n" \
15795 _ASM_EXTABLE_EX(1b, 2b) \
15796 _ASM_EXTABLE_EX(2b, 3b) \
15797@@ -246,7 +285,7 @@ extern void __put_user_8(void);
15798 __typeof__(*(ptr)) __pu_val; \
15799 __chk_user_ptr(ptr); \
15800 might_fault(); \
15801- __pu_val = x; \
15802+ __pu_val = (x); \
15803 switch (sizeof(*(ptr))) { \
15804 case 1: \
15805 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15806@@ -345,7 +384,7 @@ do { \
15807
15808 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15809 asm volatile(ASM_STAC "\n" \
15810- "1: mov"itype" %2,%"rtype"1\n" \
15811+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15812 "2: " ASM_CLAC "\n" \
15813 ".section .fixup,\"ax\"\n" \
15814 "3: mov %3,%0\n" \
15815@@ -353,7 +392,7 @@ do { \
15816 " jmp 2b\n" \
15817 ".previous\n" \
15818 _ASM_EXTABLE(1b, 3b) \
15819- : "=r" (err), ltype(x) \
15820+ : "=r" (err), ltype (x) \
15821 : "m" (__m(addr)), "i" (errret), "0" (err))
15822
15823 #define __get_user_size_ex(x, ptr, size) \
15824@@ -378,7 +417,7 @@ do { \
15825 } while (0)
15826
15827 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15828- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15829+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15830 "2:\n" \
15831 _ASM_EXTABLE_EX(1b, 2b) \
15832 : ltype(x) : "m" (__m(addr)))
15833@@ -395,13 +434,24 @@ do { \
15834 int __gu_err; \
15835 unsigned long __gu_val; \
15836 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15837- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15838+ (x) = (__typeof__(*(ptr)))__gu_val; \
15839 __gu_err; \
15840 })
15841
15842 /* FIXME: this hack is definitely wrong -AK */
15843 struct __large_struct { unsigned long buf[100]; };
15844-#define __m(x) (*(struct __large_struct __user *)(x))
15845+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15846+#define ____m(x) \
15847+({ \
15848+ unsigned long ____x = (unsigned long)(x); \
15849+ if (____x < pax_user_shadow_base) \
15850+ ____x += pax_user_shadow_base; \
15851+ (typeof(x))____x; \
15852+})
15853+#else
15854+#define ____m(x) (x)
15855+#endif
15856+#define __m(x) (*(struct __large_struct __user *)____m(x))
15857
15858 /*
15859 * Tell gcc we read from memory instead of writing: this is because
15860@@ -410,7 +460,7 @@ struct __large_struct { unsigned long buf[100]; };
15861 */
15862 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15863 asm volatile(ASM_STAC "\n" \
15864- "1: mov"itype" %"rtype"1,%2\n" \
15865+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15866 "2: " ASM_CLAC "\n" \
15867 ".section .fixup,\"ax\"\n" \
15868 "3: mov %3,%0\n" \
15869@@ -418,10 +468,10 @@ struct __large_struct { unsigned long buf[100]; };
15870 ".previous\n" \
15871 _ASM_EXTABLE(1b, 3b) \
15872 : "=r"(err) \
15873- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15874+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15875
15876 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15877- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15878+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15879 "2:\n" \
15880 _ASM_EXTABLE_EX(1b, 2b) \
15881 : : ltype(x), "m" (__m(addr)))
15882@@ -460,8 +510,12 @@ struct __large_struct { unsigned long buf[100]; };
15883 * On error, the variable @x is set to zero.
15884 */
15885
15886+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15887+#define __get_user(x, ptr) get_user((x), (ptr))
15888+#else
15889 #define __get_user(x, ptr) \
15890 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15891+#endif
15892
15893 /**
15894 * __put_user: - Write a simple value into user space, with less checking.
15895@@ -483,8 +537,12 @@ struct __large_struct { unsigned long buf[100]; };
15896 * Returns zero on success, or -EFAULT on error.
15897 */
15898
15899+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15900+#define __put_user(x, ptr) put_user((x), (ptr))
15901+#else
15902 #define __put_user(x, ptr) \
15903 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15904+#endif
15905
15906 #define __get_user_unaligned __get_user
15907 #define __put_user_unaligned __put_user
15908@@ -502,7 +560,7 @@ struct __large_struct { unsigned long buf[100]; };
15909 #define get_user_ex(x, ptr) do { \
15910 unsigned long __gue_val; \
15911 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15912- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15913+ (x) = (__typeof__(*(ptr)))__gue_val; \
15914 } while (0)
15915
15916 #define put_user_try uaccess_try
15917@@ -519,8 +577,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15918 extern __must_check long strlen_user(const char __user *str);
15919 extern __must_check long strnlen_user(const char __user *str, long n);
15920
15921-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15922-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15923+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15924+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15925
15926 /*
15927 * movsl can be slow when source and dest are not both 8-byte aligned
15928diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15929index 7f760a9..04b1c65 100644
15930--- a/arch/x86/include/asm/uaccess_32.h
15931+++ b/arch/x86/include/asm/uaccess_32.h
15932@@ -11,15 +11,15 @@
15933 #include <asm/page.h>
15934
15935 unsigned long __must_check __copy_to_user_ll
15936- (void __user *to, const void *from, unsigned long n);
15937+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15938 unsigned long __must_check __copy_from_user_ll
15939- (void *to, const void __user *from, unsigned long n);
15940+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15941 unsigned long __must_check __copy_from_user_ll_nozero
15942- (void *to, const void __user *from, unsigned long n);
15943+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15944 unsigned long __must_check __copy_from_user_ll_nocache
15945- (void *to, const void __user *from, unsigned long n);
15946+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15947 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15948- (void *to, const void __user *from, unsigned long n);
15949+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15950
15951 /**
15952 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15953@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15954 static __always_inline unsigned long __must_check
15955 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15956 {
15957+ if ((long)n < 0)
15958+ return n;
15959+
15960+ check_object_size(from, n, true);
15961+
15962 if (__builtin_constant_p(n)) {
15963 unsigned long ret;
15964
15965@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15966 __copy_to_user(void __user *to, const void *from, unsigned long n)
15967 {
15968 might_fault();
15969+
15970 return __copy_to_user_inatomic(to, from, n);
15971 }
15972
15973 static __always_inline unsigned long
15974 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15975 {
15976+ if ((long)n < 0)
15977+ return n;
15978+
15979 /* Avoid zeroing the tail if the copy fails..
15980 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15981 * but as the zeroing behaviour is only significant when n is not
15982@@ -137,6 +146,12 @@ static __always_inline unsigned long
15983 __copy_from_user(void *to, const void __user *from, unsigned long n)
15984 {
15985 might_fault();
15986+
15987+ if ((long)n < 0)
15988+ return n;
15989+
15990+ check_object_size(to, n, false);
15991+
15992 if (__builtin_constant_p(n)) {
15993 unsigned long ret;
15994
15995@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15996 const void __user *from, unsigned long n)
15997 {
15998 might_fault();
15999+
16000+ if ((long)n < 0)
16001+ return n;
16002+
16003 if (__builtin_constant_p(n)) {
16004 unsigned long ret;
16005
16006@@ -181,15 +200,19 @@ static __always_inline unsigned long
16007 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
16008 unsigned long n)
16009 {
16010- return __copy_from_user_ll_nocache_nozero(to, from, n);
16011+ if ((long)n < 0)
16012+ return n;
16013+
16014+ return __copy_from_user_ll_nocache_nozero(to, from, n);
16015 }
16016
16017-unsigned long __must_check copy_to_user(void __user *to,
16018- const void *from, unsigned long n);
16019-unsigned long __must_check _copy_from_user(void *to,
16020- const void __user *from,
16021- unsigned long n);
16022-
16023+extern void copy_to_user_overflow(void)
16024+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16025+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16026+#else
16027+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16028+#endif
16029+;
16030
16031 extern void copy_from_user_overflow(void)
16032 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16033@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
16034 #endif
16035 ;
16036
16037-static inline unsigned long __must_check copy_from_user(void *to,
16038- const void __user *from,
16039- unsigned long n)
16040+/**
16041+ * copy_to_user: - Copy a block of data into user space.
16042+ * @to: Destination address, in user space.
16043+ * @from: Source address, in kernel space.
16044+ * @n: Number of bytes to copy.
16045+ *
16046+ * Context: User context only. This function may sleep.
16047+ *
16048+ * Copy data from kernel space to user space.
16049+ *
16050+ * Returns number of bytes that could not be copied.
16051+ * On success, this will be zero.
16052+ */
16053+static inline unsigned long __must_check
16054+copy_to_user(void __user *to, const void *from, unsigned long n)
16055 {
16056- int sz = __compiletime_object_size(to);
16057+ size_t sz = __compiletime_object_size(from);
16058
16059- if (likely(sz == -1 || sz >= n))
16060- n = _copy_from_user(to, from, n);
16061- else
16062+ if (unlikely(sz != (size_t)-1 && sz < n))
16063+ copy_to_user_overflow();
16064+ else if (access_ok(VERIFY_WRITE, to, n))
16065+ n = __copy_to_user(to, from, n);
16066+ return n;
16067+}
16068+
16069+/**
16070+ * copy_from_user: - Copy a block of data from user space.
16071+ * @to: Destination address, in kernel space.
16072+ * @from: Source address, in user space.
16073+ * @n: Number of bytes to copy.
16074+ *
16075+ * Context: User context only. This function may sleep.
16076+ *
16077+ * Copy data from user space to kernel space.
16078+ *
16079+ * Returns number of bytes that could not be copied.
16080+ * On success, this will be zero.
16081+ *
16082+ * If some data could not be copied, this function will pad the copied
16083+ * data to the requested size using zero bytes.
16084+ */
16085+static inline unsigned long __must_check
16086+copy_from_user(void *to, const void __user *from, unsigned long n)
16087+{
16088+ size_t sz = __compiletime_object_size(to);
16089+
16090+ check_object_size(to, n, false);
16091+
16092+ if (unlikely(sz != (size_t)-1 && sz < n))
16093 copy_from_user_overflow();
16094-
16095+ else if (access_ok(VERIFY_READ, from, n))
16096+ n = __copy_from_user(to, from, n);
16097+ else if ((long)n > 0)
16098+ memset(to, 0, n);
16099 return n;
16100 }
16101
16102diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
16103index 142810c..1f2a0a7 100644
16104--- a/arch/x86/include/asm/uaccess_64.h
16105+++ b/arch/x86/include/asm/uaccess_64.h
16106@@ -10,6 +10,9 @@
16107 #include <asm/alternative.h>
16108 #include <asm/cpufeature.h>
16109 #include <asm/page.h>
16110+#include <asm/pgtable.h>
16111+
16112+#define set_fs(x) (current_thread_info()->addr_limit = (x))
16113
16114 /*
16115 * Copy To/From Userspace
16116@@ -17,13 +20,13 @@
16117
16118 /* Handles exceptions in both to and from, but doesn't do access_ok */
16119 __must_check unsigned long
16120-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
16121+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
16122 __must_check unsigned long
16123-copy_user_generic_string(void *to, const void *from, unsigned len);
16124+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
16125 __must_check unsigned long
16126-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
16127+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
16128
16129-static __always_inline __must_check unsigned long
16130+static __always_inline __must_check __size_overflow(3) unsigned long
16131 copy_user_generic(void *to, const void *from, unsigned len)
16132 {
16133 unsigned ret;
16134@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
16135 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
16136 "=d" (len)),
16137 "1" (to), "2" (from), "3" (len)
16138- : "memory", "rcx", "r8", "r9", "r10", "r11");
16139+ : "memory", "rcx", "r8", "r9", "r11");
16140 return ret;
16141 }
16142
16143+static __always_inline __must_check unsigned long
16144+__copy_to_user(void __user *to, const void *from, unsigned long len);
16145+static __always_inline __must_check unsigned long
16146+__copy_from_user(void *to, const void __user *from, unsigned long len);
16147 __must_check unsigned long
16148-_copy_to_user(void __user *to, const void *from, unsigned len);
16149-__must_check unsigned long
16150-_copy_from_user(void *to, const void __user *from, unsigned len);
16151-__must_check unsigned long
16152-copy_in_user(void __user *to, const void __user *from, unsigned len);
16153+copy_in_user(void __user *to, const void __user *from, unsigned long len);
16154+
16155+extern void copy_to_user_overflow(void)
16156+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16157+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16158+#else
16159+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16160+#endif
16161+;
16162+
16163+extern void copy_from_user_overflow(void)
16164+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16165+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16166+#else
16167+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16168+#endif
16169+;
16170
16171 static inline unsigned long __must_check copy_from_user(void *to,
16172 const void __user *from,
16173 unsigned long n)
16174 {
16175- int sz = __compiletime_object_size(to);
16176-
16177 might_fault();
16178- if (likely(sz == -1 || sz >= n))
16179- n = _copy_from_user(to, from, n);
16180-#ifdef CONFIG_DEBUG_VM
16181- else
16182- WARN(1, "Buffer overflow detected!\n");
16183-#endif
16184+
16185+ check_object_size(to, n, false);
16186+
16187+ if (access_ok(VERIFY_READ, from, n))
16188+ n = __copy_from_user(to, from, n);
16189+ else if (n < INT_MAX)
16190+ memset(to, 0, n);
16191 return n;
16192 }
16193
16194 static __always_inline __must_check
16195-int copy_to_user(void __user *dst, const void *src, unsigned size)
16196+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16197 {
16198 might_fault();
16199
16200- return _copy_to_user(dst, src, size);
16201+ if (access_ok(VERIFY_WRITE, dst, size))
16202+ size = __copy_to_user(dst, src, size);
16203+ return size;
16204 }
16205
16206 static __always_inline __must_check
16207-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16208+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16209 {
16210- int ret = 0;
16211+ size_t sz = __compiletime_object_size(dst);
16212+ unsigned ret = 0;
16213
16214 might_fault();
16215+
16216+ if (size > INT_MAX)
16217+ return size;
16218+
16219+ check_object_size(dst, size, false);
16220+
16221+#ifdef CONFIG_PAX_MEMORY_UDEREF
16222+ if (!__access_ok(VERIFY_READ, src, size))
16223+ return size;
16224+#endif
16225+
16226+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16227+ copy_from_user_overflow();
16228+ return size;
16229+ }
16230+
16231 if (!__builtin_constant_p(size))
16232- return copy_user_generic(dst, (__force void *)src, size);
16233+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16234 switch (size) {
16235- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16236+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16237 ret, "b", "b", "=q", 1);
16238 return ret;
16239- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16240+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16241 ret, "w", "w", "=r", 2);
16242 return ret;
16243- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16244+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16245 ret, "l", "k", "=r", 4);
16246 return ret;
16247- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16248+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16249 ret, "q", "", "=r", 8);
16250 return ret;
16251 case 10:
16252- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16253+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16254 ret, "q", "", "=r", 10);
16255 if (unlikely(ret))
16256 return ret;
16257 __get_user_asm(*(u16 *)(8 + (char *)dst),
16258- (u16 __user *)(8 + (char __user *)src),
16259+ (const u16 __user *)(8 + (const char __user *)src),
16260 ret, "w", "w", "=r", 2);
16261 return ret;
16262 case 16:
16263- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16264+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16265 ret, "q", "", "=r", 16);
16266 if (unlikely(ret))
16267 return ret;
16268 __get_user_asm(*(u64 *)(8 + (char *)dst),
16269- (u64 __user *)(8 + (char __user *)src),
16270+ (const u64 __user *)(8 + (const char __user *)src),
16271 ret, "q", "", "=r", 8);
16272 return ret;
16273 default:
16274- return copy_user_generic(dst, (__force void *)src, size);
16275+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16276 }
16277 }
16278
16279 static __always_inline __must_check
16280-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16281+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16282 {
16283- int ret = 0;
16284+ size_t sz = __compiletime_object_size(src);
16285+ unsigned ret = 0;
16286
16287 might_fault();
16288+
16289+ if (size > INT_MAX)
16290+ return size;
16291+
16292+ check_object_size(src, size, true);
16293+
16294+#ifdef CONFIG_PAX_MEMORY_UDEREF
16295+ if (!__access_ok(VERIFY_WRITE, dst, size))
16296+ return size;
16297+#endif
16298+
16299+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16300+ copy_to_user_overflow();
16301+ return size;
16302+ }
16303+
16304 if (!__builtin_constant_p(size))
16305- return copy_user_generic((__force void *)dst, src, size);
16306+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16307 switch (size) {
16308- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16309+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16310 ret, "b", "b", "iq", 1);
16311 return ret;
16312- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16313+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16314 ret, "w", "w", "ir", 2);
16315 return ret;
16316- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16317+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16318 ret, "l", "k", "ir", 4);
16319 return ret;
16320- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16321+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16322 ret, "q", "", "er", 8);
16323 return ret;
16324 case 10:
16325- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16326+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16327 ret, "q", "", "er", 10);
16328 if (unlikely(ret))
16329 return ret;
16330 asm("":::"memory");
16331- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16332+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16333 ret, "w", "w", "ir", 2);
16334 return ret;
16335 case 16:
16336- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16337+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16338 ret, "q", "", "er", 16);
16339 if (unlikely(ret))
16340 return ret;
16341 asm("":::"memory");
16342- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16343+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16344 ret, "q", "", "er", 8);
16345 return ret;
16346 default:
16347- return copy_user_generic((__force void *)dst, src, size);
16348+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16349 }
16350 }
16351
16352 static __always_inline __must_check
16353-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16354+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16355 {
16356- int ret = 0;
16357+ unsigned ret = 0;
16358
16359 might_fault();
16360+
16361+ if (size > INT_MAX)
16362+ return size;
16363+
16364+#ifdef CONFIG_PAX_MEMORY_UDEREF
16365+ if (!__access_ok(VERIFY_READ, src, size))
16366+ return size;
16367+ if (!__access_ok(VERIFY_WRITE, dst, size))
16368+ return size;
16369+#endif
16370+
16371 if (!__builtin_constant_p(size))
16372- return copy_user_generic((__force void *)dst,
16373- (__force void *)src, size);
16374+ return copy_user_generic((__force_kernel void *)____m(dst),
16375+ (__force_kernel const void *)____m(src), size);
16376 switch (size) {
16377 case 1: {
16378 u8 tmp;
16379- __get_user_asm(tmp, (u8 __user *)src,
16380+ __get_user_asm(tmp, (const u8 __user *)src,
16381 ret, "b", "b", "=q", 1);
16382 if (likely(!ret))
16383 __put_user_asm(tmp, (u8 __user *)dst,
16384@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16385 }
16386 case 2: {
16387 u16 tmp;
16388- __get_user_asm(tmp, (u16 __user *)src,
16389+ __get_user_asm(tmp, (const u16 __user *)src,
16390 ret, "w", "w", "=r", 2);
16391 if (likely(!ret))
16392 __put_user_asm(tmp, (u16 __user *)dst,
16393@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16394
16395 case 4: {
16396 u32 tmp;
16397- __get_user_asm(tmp, (u32 __user *)src,
16398+ __get_user_asm(tmp, (const u32 __user *)src,
16399 ret, "l", "k", "=r", 4);
16400 if (likely(!ret))
16401 __put_user_asm(tmp, (u32 __user *)dst,
16402@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16403 }
16404 case 8: {
16405 u64 tmp;
16406- __get_user_asm(tmp, (u64 __user *)src,
16407+ __get_user_asm(tmp, (const u64 __user *)src,
16408 ret, "q", "", "=r", 8);
16409 if (likely(!ret))
16410 __put_user_asm(tmp, (u64 __user *)dst,
16411@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16412 return ret;
16413 }
16414 default:
16415- return copy_user_generic((__force void *)dst,
16416- (__force void *)src, size);
16417+ return copy_user_generic((__force_kernel void *)____m(dst),
16418+ (__force_kernel const void *)____m(src), size);
16419 }
16420 }
16421
16422 static __must_check __always_inline int
16423-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16424+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16425 {
16426- return copy_user_generic(dst, (__force const void *)src, size);
16427+ if (size > INT_MAX)
16428+ return size;
16429+
16430+#ifdef CONFIG_PAX_MEMORY_UDEREF
16431+ if (!__access_ok(VERIFY_READ, src, size))
16432+ return size;
16433+#endif
16434+
16435+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16436 }
16437
16438-static __must_check __always_inline int
16439-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16440+static __must_check __always_inline unsigned long
16441+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16442 {
16443- return copy_user_generic((__force void *)dst, src, size);
16444+ if (size > INT_MAX)
16445+ return size;
16446+
16447+#ifdef CONFIG_PAX_MEMORY_UDEREF
16448+ if (!__access_ok(VERIFY_WRITE, dst, size))
16449+ return size;
16450+#endif
16451+
16452+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16453 }
16454
16455-extern long __copy_user_nocache(void *dst, const void __user *src,
16456- unsigned size, int zerorest);
16457+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16458+ unsigned long size, int zerorest) __size_overflow(3);
16459
16460-static inline int
16461-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16462+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16463 {
16464 might_sleep();
16465+
16466+ if (size > INT_MAX)
16467+ return size;
16468+
16469+#ifdef CONFIG_PAX_MEMORY_UDEREF
16470+ if (!__access_ok(VERIFY_READ, src, size))
16471+ return size;
16472+#endif
16473+
16474 return __copy_user_nocache(dst, src, size, 1);
16475 }
16476
16477-static inline int
16478-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16479- unsigned size)
16480+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16481+ unsigned long size)
16482 {
16483+ if (size > INT_MAX)
16484+ return size;
16485+
16486+#ifdef CONFIG_PAX_MEMORY_UDEREF
16487+ if (!__access_ok(VERIFY_READ, src, size))
16488+ return size;
16489+#endif
16490+
16491 return __copy_user_nocache(dst, src, size, 0);
16492 }
16493
16494-unsigned long
16495-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16496+extern unsigned long
16497+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16498
16499 #endif /* _ASM_X86_UACCESS_64_H */
16500diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16501index 5b238981..77fdd78 100644
16502--- a/arch/x86/include/asm/word-at-a-time.h
16503+++ b/arch/x86/include/asm/word-at-a-time.h
16504@@ -11,7 +11,7 @@
16505 * and shift, for example.
16506 */
16507 struct word_at_a_time {
16508- const unsigned long one_bits, high_bits;
16509+ unsigned long one_bits, high_bits;
16510 };
16511
16512 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16513diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16514index d8d9922..bf6cecb 100644
16515--- a/arch/x86/include/asm/x86_init.h
16516+++ b/arch/x86/include/asm/x86_init.h
16517@@ -129,7 +129,7 @@ struct x86_init_ops {
16518 struct x86_init_timers timers;
16519 struct x86_init_iommu iommu;
16520 struct x86_init_pci pci;
16521-};
16522+} __no_const;
16523
16524 /**
16525 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16526@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
16527 void (*setup_percpu_clockev)(void);
16528 void (*early_percpu_clock_init)(void);
16529 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16530-};
16531+} __no_const;
16532
16533 /**
16534 * struct x86_platform_ops - platform specific runtime functions
16535@@ -166,7 +166,7 @@ struct x86_platform_ops {
16536 void (*save_sched_clock_state)(void);
16537 void (*restore_sched_clock_state)(void);
16538 void (*apic_post_init)(void);
16539-};
16540+} __no_const;
16541
16542 struct pci_dev;
16543 struct msi_msg;
16544@@ -180,7 +180,7 @@ struct x86_msi_ops {
16545 void (*teardown_msi_irqs)(struct pci_dev *dev);
16546 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16547 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
16548-};
16549+} __no_const;
16550
16551 struct IO_APIC_route_entry;
16552 struct io_apic_irq_attr;
16553@@ -201,7 +201,7 @@ struct x86_io_apic_ops {
16554 unsigned int destination, int vector,
16555 struct io_apic_irq_attr *attr);
16556 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
16557-};
16558+} __no_const;
16559
16560 extern struct x86_init_ops x86_init;
16561 extern struct x86_cpuinit_ops x86_cpuinit;
16562diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16563index 0415cda..b43d877 100644
16564--- a/arch/x86/include/asm/xsave.h
16565+++ b/arch/x86/include/asm/xsave.h
16566@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16567 return -EFAULT;
16568
16569 __asm__ __volatile__(ASM_STAC "\n"
16570- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16571+ "1:"
16572+ __copyuser_seg
16573+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16574 "2: " ASM_CLAC "\n"
16575 ".section .fixup,\"ax\"\n"
16576 "3: movl $-1,%[err]\n"
16577@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16578 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16579 {
16580 int err;
16581- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16582+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16583 u32 lmask = mask;
16584 u32 hmask = mask >> 32;
16585
16586 __asm__ __volatile__(ASM_STAC "\n"
16587- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16588+ "1:"
16589+ __copyuser_seg
16590+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16591 "2: " ASM_CLAC "\n"
16592 ".section .fixup,\"ax\"\n"
16593 "3: movl $-1,%[err]\n"
16594diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16595index bbae024..e1528f9 100644
16596--- a/arch/x86/include/uapi/asm/e820.h
16597+++ b/arch/x86/include/uapi/asm/e820.h
16598@@ -63,7 +63,7 @@ struct e820map {
16599 #define ISA_START_ADDRESS 0xa0000
16600 #define ISA_END_ADDRESS 0x100000
16601
16602-#define BIOS_BEGIN 0x000a0000
16603+#define BIOS_BEGIN 0x000c0000
16604 #define BIOS_END 0x00100000
16605
16606 #define BIOS_ROM_BASE 0xffe00000
16607diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16608index 7bd3bd3..5dac791 100644
16609--- a/arch/x86/kernel/Makefile
16610+++ b/arch/x86/kernel/Makefile
16611@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16612 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16613 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16614 obj-y += probe_roms.o
16615-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16616+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16617 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16618 obj-y += syscall_$(BITS).o
16619 obj-$(CONFIG_X86_64) += vsyscall_64.o
16620diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16621index 230c8ea..f915130 100644
16622--- a/arch/x86/kernel/acpi/boot.c
16623+++ b/arch/x86/kernel/acpi/boot.c
16624@@ -1361,7 +1361,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16625 * If your system is blacklisted here, but you find that acpi=force
16626 * works for you, please contact linux-acpi@vger.kernel.org
16627 */
16628-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16629+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16630 /*
16631 * Boxes that need ACPI disabled
16632 */
16633@@ -1436,7 +1436,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16634 };
16635
16636 /* second table for DMI checks that should run after early-quirks */
16637-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16638+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16639 /*
16640 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16641 * which includes some code which overrides all temperature
16642diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16643index 0532f5d..36afc0a 100644
16644--- a/arch/x86/kernel/acpi/sleep.c
16645+++ b/arch/x86/kernel/acpi/sleep.c
16646@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16647 #else /* CONFIG_64BIT */
16648 #ifdef CONFIG_SMP
16649 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16650+
16651+ pax_open_kernel();
16652 early_gdt_descr.address =
16653 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16654+ pax_close_kernel();
16655+
16656 initial_gs = per_cpu_offset(smp_processor_id());
16657 #endif
16658 initial_code = (unsigned long)wakeup_long64;
16659diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16660index 13ab720..95d5442 100644
16661--- a/arch/x86/kernel/acpi/wakeup_32.S
16662+++ b/arch/x86/kernel/acpi/wakeup_32.S
16663@@ -30,13 +30,11 @@ wakeup_pmode_return:
16664 # and restore the stack ... but you need gdt for this to work
16665 movl saved_context_esp, %esp
16666
16667- movl %cs:saved_magic, %eax
16668- cmpl $0x12345678, %eax
16669+ cmpl $0x12345678, saved_magic
16670 jne bogus_magic
16671
16672 # jump to place where we left off
16673- movl saved_eip, %eax
16674- jmp *%eax
16675+ jmp *(saved_eip)
16676
16677 bogus_magic:
16678 jmp bogus_magic
16679diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16680index ef5ccca..bd83949 100644
16681--- a/arch/x86/kernel/alternative.c
16682+++ b/arch/x86/kernel/alternative.c
16683@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16684 */
16685 for (a = start; a < end; a++) {
16686 instr = (u8 *)&a->instr_offset + a->instr_offset;
16687+
16688+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16689+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16690+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16691+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16692+#endif
16693+
16694 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16695 BUG_ON(a->replacementlen > a->instrlen);
16696 BUG_ON(a->instrlen > sizeof(insnbuf));
16697@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16698 for (poff = start; poff < end; poff++) {
16699 u8 *ptr = (u8 *)poff + *poff;
16700
16701+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16702+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16703+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16704+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16705+#endif
16706+
16707 if (!*poff || ptr < text || ptr >= text_end)
16708 continue;
16709 /* turn DS segment override prefix into lock prefix */
16710- if (*ptr == 0x3e)
16711+ if (*ktla_ktva(ptr) == 0x3e)
16712 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16713 }
16714 mutex_unlock(&text_mutex);
16715@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16716 for (poff = start; poff < end; poff++) {
16717 u8 *ptr = (u8 *)poff + *poff;
16718
16719+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16720+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16721+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16722+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16723+#endif
16724+
16725 if (!*poff || ptr < text || ptr >= text_end)
16726 continue;
16727 /* turn lock prefix into DS segment override prefix */
16728- if (*ptr == 0xf0)
16729+ if (*ktla_ktva(ptr) == 0xf0)
16730 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16731 }
16732 mutex_unlock(&text_mutex);
16733@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16734
16735 BUG_ON(p->len > MAX_PATCH_LEN);
16736 /* prep the buffer with the original instructions */
16737- memcpy(insnbuf, p->instr, p->len);
16738+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16739 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16740 (unsigned long)p->instr, p->len);
16741
16742@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16743 if (!uniproc_patched || num_possible_cpus() == 1)
16744 free_init_pages("SMP alternatives",
16745 (unsigned long)__smp_locks,
16746- (unsigned long)__smp_locks_end);
16747+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16748 #endif
16749
16750 apply_paravirt(__parainstructions, __parainstructions_end);
16751@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16752 * instructions. And on the local CPU you need to be protected again NMI or MCE
16753 * handlers seeing an inconsistent instruction while you patch.
16754 */
16755-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16756+void *__kprobes text_poke_early(void *addr, const void *opcode,
16757 size_t len)
16758 {
16759 unsigned long flags;
16760 local_irq_save(flags);
16761- memcpy(addr, opcode, len);
16762+
16763+ pax_open_kernel();
16764+ memcpy(ktla_ktva(addr), opcode, len);
16765 sync_core();
16766+ pax_close_kernel();
16767+
16768 local_irq_restore(flags);
16769 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16770 that causes hangs on some VIA CPUs. */
16771@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16772 */
16773 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16774 {
16775- unsigned long flags;
16776- char *vaddr;
16777+ unsigned char *vaddr = ktla_ktva(addr);
16778 struct page *pages[2];
16779- int i;
16780+ size_t i;
16781
16782 if (!core_kernel_text((unsigned long)addr)) {
16783- pages[0] = vmalloc_to_page(addr);
16784- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16785+ pages[0] = vmalloc_to_page(vaddr);
16786+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16787 } else {
16788- pages[0] = virt_to_page(addr);
16789+ pages[0] = virt_to_page(vaddr);
16790 WARN_ON(!PageReserved(pages[0]));
16791- pages[1] = virt_to_page(addr + PAGE_SIZE);
16792+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16793 }
16794 BUG_ON(!pages[0]);
16795- local_irq_save(flags);
16796- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16797- if (pages[1])
16798- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16799- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16800- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16801- clear_fixmap(FIX_TEXT_POKE0);
16802- if (pages[1])
16803- clear_fixmap(FIX_TEXT_POKE1);
16804- local_flush_tlb();
16805- sync_core();
16806- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16807- that causes hangs on some VIA CPUs. */
16808+ text_poke_early(addr, opcode, len);
16809 for (i = 0; i < len; i++)
16810- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16811- local_irq_restore(flags);
16812+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16813 return addr;
16814 }
16815
16816diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16817index 904611b..004dde6 100644
16818--- a/arch/x86/kernel/apic/apic.c
16819+++ b/arch/x86/kernel/apic/apic.c
16820@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16821 /*
16822 * Debug level, exported for io_apic.c
16823 */
16824-unsigned int apic_verbosity;
16825+int apic_verbosity;
16826
16827 int pic_mode;
16828
16829@@ -1955,7 +1955,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16830 apic_write(APIC_ESR, 0);
16831 v1 = apic_read(APIC_ESR);
16832 ack_APIC_irq();
16833- atomic_inc(&irq_err_count);
16834+ atomic_inc_unchecked(&irq_err_count);
16835
16836 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16837 smp_processor_id(), v0 , v1);
16838diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16839index 00c77cf..2dc6a2d 100644
16840--- a/arch/x86/kernel/apic/apic_flat_64.c
16841+++ b/arch/x86/kernel/apic/apic_flat_64.c
16842@@ -157,7 +157,7 @@ static int flat_probe(void)
16843 return 1;
16844 }
16845
16846-static struct apic apic_flat = {
16847+static struct apic apic_flat __read_only = {
16848 .name = "flat",
16849 .probe = flat_probe,
16850 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16851@@ -271,7 +271,7 @@ static int physflat_probe(void)
16852 return 0;
16853 }
16854
16855-static struct apic apic_physflat = {
16856+static struct apic apic_physflat __read_only = {
16857
16858 .name = "physical flat",
16859 .probe = physflat_probe,
16860diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16861index e145f28..2752888 100644
16862--- a/arch/x86/kernel/apic/apic_noop.c
16863+++ b/arch/x86/kernel/apic/apic_noop.c
16864@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16865 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16866 }
16867
16868-struct apic apic_noop = {
16869+struct apic apic_noop __read_only = {
16870 .name = "noop",
16871 .probe = noop_probe,
16872 .acpi_madt_oem_check = NULL,
16873diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16874index d50e364..543bee3 100644
16875--- a/arch/x86/kernel/apic/bigsmp_32.c
16876+++ b/arch/x86/kernel/apic/bigsmp_32.c
16877@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16878 return dmi_bigsmp;
16879 }
16880
16881-static struct apic apic_bigsmp = {
16882+static struct apic apic_bigsmp __read_only = {
16883
16884 .name = "bigsmp",
16885 .probe = probe_bigsmp,
16886diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16887index 0874799..a7a7892 100644
16888--- a/arch/x86/kernel/apic/es7000_32.c
16889+++ b/arch/x86/kernel/apic/es7000_32.c
16890@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16891 return ret && es7000_apic_is_cluster();
16892 }
16893
16894-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16895-static struct apic __refdata apic_es7000_cluster = {
16896+static struct apic apic_es7000_cluster __read_only = {
16897
16898 .name = "es7000",
16899 .probe = probe_es7000,
16900@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16901 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16902 };
16903
16904-static struct apic __refdata apic_es7000 = {
16905+static struct apic apic_es7000 __read_only = {
16906
16907 .name = "es7000",
16908 .probe = probe_es7000,
16909diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16910index 9ed796c..e930fe4 100644
16911--- a/arch/x86/kernel/apic/io_apic.c
16912+++ b/arch/x86/kernel/apic/io_apic.c
16913@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16914 }
16915 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16916
16917-void lock_vector_lock(void)
16918+void lock_vector_lock(void) __acquires(vector_lock)
16919 {
16920 /* Used to the online set of cpus does not change
16921 * during assign_irq_vector.
16922@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
16923 raw_spin_lock(&vector_lock);
16924 }
16925
16926-void unlock_vector_lock(void)
16927+void unlock_vector_lock(void) __releases(vector_lock)
16928 {
16929 raw_spin_unlock(&vector_lock);
16930 }
16931@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
16932 ack_APIC_irq();
16933 }
16934
16935-atomic_t irq_mis_count;
16936+atomic_unchecked_t irq_mis_count;
16937
16938 #ifdef CONFIG_GENERIC_PENDING_IRQ
16939 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16940@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
16941 * at the cpu.
16942 */
16943 if (!(v & (1 << (i & 0x1f)))) {
16944- atomic_inc(&irq_mis_count);
16945+ atomic_inc_unchecked(&irq_mis_count);
16946
16947 eoi_ioapic_irq(irq, cfg);
16948 }
16949diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16950index d661ee9..791fd33 100644
16951--- a/arch/x86/kernel/apic/numaq_32.c
16952+++ b/arch/x86/kernel/apic/numaq_32.c
16953@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16954 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16955 }
16956
16957-/* Use __refdata to keep false positive warning calm. */
16958-static struct apic __refdata apic_numaq = {
16959+static struct apic apic_numaq __read_only = {
16960
16961 .name = "NUMAQ",
16962 .probe = probe_numaq,
16963diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16964index eb35ef9..f184a21 100644
16965--- a/arch/x86/kernel/apic/probe_32.c
16966+++ b/arch/x86/kernel/apic/probe_32.c
16967@@ -72,7 +72,7 @@ static int probe_default(void)
16968 return 1;
16969 }
16970
16971-static struct apic apic_default = {
16972+static struct apic apic_default __read_only = {
16973
16974 .name = "default",
16975 .probe = probe_default,
16976diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16977index 77c95c0..434f8a4 100644
16978--- a/arch/x86/kernel/apic/summit_32.c
16979+++ b/arch/x86/kernel/apic/summit_32.c
16980@@ -486,7 +486,7 @@ void setup_summit(void)
16981 }
16982 #endif
16983
16984-static struct apic apic_summit = {
16985+static struct apic apic_summit __read_only = {
16986
16987 .name = "summit",
16988 .probe = probe_summit,
16989diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16990index c88baa4..757aee1 100644
16991--- a/arch/x86/kernel/apic/x2apic_cluster.c
16992+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16993@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16994 return notifier_from_errno(err);
16995 }
16996
16997-static struct notifier_block __refdata x2apic_cpu_notifier = {
16998+static struct notifier_block x2apic_cpu_notifier = {
16999 .notifier_call = update_clusterinfo,
17000 };
17001
17002@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
17003 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
17004 }
17005
17006-static struct apic apic_x2apic_cluster = {
17007+static struct apic apic_x2apic_cluster __read_only = {
17008
17009 .name = "cluster x2apic",
17010 .probe = x2apic_cluster_probe,
17011diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
17012index 562a76d..a003c0f 100644
17013--- a/arch/x86/kernel/apic/x2apic_phys.c
17014+++ b/arch/x86/kernel/apic/x2apic_phys.c
17015@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
17016 return apic == &apic_x2apic_phys;
17017 }
17018
17019-static struct apic apic_x2apic_phys = {
17020+static struct apic apic_x2apic_phys __read_only = {
17021
17022 .name = "physical x2apic",
17023 .probe = x2apic_phys_probe,
17024diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
17025index 794f6eb..67e1db2 100644
17026--- a/arch/x86/kernel/apic/x2apic_uv_x.c
17027+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
17028@@ -342,7 +342,7 @@ static int uv_probe(void)
17029 return apic == &apic_x2apic_uv_x;
17030 }
17031
17032-static struct apic __refdata apic_x2apic_uv_x = {
17033+static struct apic apic_x2apic_uv_x __read_only = {
17034
17035 .name = "UV large system",
17036 .probe = uv_probe,
17037diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
17038index 66b5faf..3442423 100644
17039--- a/arch/x86/kernel/apm_32.c
17040+++ b/arch/x86/kernel/apm_32.c
17041@@ -434,7 +434,7 @@ static DEFINE_MUTEX(apm_mutex);
17042 * This is for buggy BIOS's that refer to (real mode) segment 0x40
17043 * even though they are called in protected mode.
17044 */
17045-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
17046+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
17047 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
17048
17049 static const char driver_version[] = "1.16ac"; /* no spaces */
17050@@ -612,7 +612,10 @@ static long __apm_bios_call(void *_call)
17051 BUG_ON(cpu != 0);
17052 gdt = get_cpu_gdt_table(cpu);
17053 save_desc_40 = gdt[0x40 / 8];
17054+
17055+ pax_open_kernel();
17056 gdt[0x40 / 8] = bad_bios_desc;
17057+ pax_close_kernel();
17058
17059 apm_irq_save(flags);
17060 APM_DO_SAVE_SEGS;
17061@@ -621,7 +624,11 @@ static long __apm_bios_call(void *_call)
17062 &call->esi);
17063 APM_DO_RESTORE_SEGS;
17064 apm_irq_restore(flags);
17065+
17066+ pax_open_kernel();
17067 gdt[0x40 / 8] = save_desc_40;
17068+ pax_close_kernel();
17069+
17070 put_cpu();
17071
17072 return call->eax & 0xff;
17073@@ -688,7 +695,10 @@ static long __apm_bios_call_simple(void *_call)
17074 BUG_ON(cpu != 0);
17075 gdt = get_cpu_gdt_table(cpu);
17076 save_desc_40 = gdt[0x40 / 8];
17077+
17078+ pax_open_kernel();
17079 gdt[0x40 / 8] = bad_bios_desc;
17080+ pax_close_kernel();
17081
17082 apm_irq_save(flags);
17083 APM_DO_SAVE_SEGS;
17084@@ -696,7 +706,11 @@ static long __apm_bios_call_simple(void *_call)
17085 &call->eax);
17086 APM_DO_RESTORE_SEGS;
17087 apm_irq_restore(flags);
17088+
17089+ pax_open_kernel();
17090 gdt[0x40 / 8] = save_desc_40;
17091+ pax_close_kernel();
17092+
17093 put_cpu();
17094 return error;
17095 }
17096@@ -2363,12 +2377,15 @@ static int __init apm_init(void)
17097 * code to that CPU.
17098 */
17099 gdt = get_cpu_gdt_table(0);
17100+
17101+ pax_open_kernel();
17102 set_desc_base(&gdt[APM_CS >> 3],
17103 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
17104 set_desc_base(&gdt[APM_CS_16 >> 3],
17105 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
17106 set_desc_base(&gdt[APM_DS >> 3],
17107 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
17108+ pax_close_kernel();
17109
17110 proc_create("apm", 0, NULL, &apm_file_ops);
17111
17112diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
17113index 2861082..6d4718e 100644
17114--- a/arch/x86/kernel/asm-offsets.c
17115+++ b/arch/x86/kernel/asm-offsets.c
17116@@ -33,6 +33,8 @@ void common(void) {
17117 OFFSET(TI_status, thread_info, status);
17118 OFFSET(TI_addr_limit, thread_info, addr_limit);
17119 OFFSET(TI_preempt_count, thread_info, preempt_count);
17120+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
17121+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
17122
17123 BLANK();
17124 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
17125@@ -53,8 +55,26 @@ void common(void) {
17126 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
17127 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
17128 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
17129+
17130+#ifdef CONFIG_PAX_KERNEXEC
17131+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
17132 #endif
17133
17134+#ifdef CONFIG_PAX_MEMORY_UDEREF
17135+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
17136+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
17137+#ifdef CONFIG_X86_64
17138+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
17139+#endif
17140+#endif
17141+
17142+#endif
17143+
17144+ BLANK();
17145+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
17146+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
17147+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
17148+
17149 #ifdef CONFIG_XEN
17150 BLANK();
17151 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17152diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17153index 1b4754f..fbb4227 100644
17154--- a/arch/x86/kernel/asm-offsets_64.c
17155+++ b/arch/x86/kernel/asm-offsets_64.c
17156@@ -76,6 +76,7 @@ int main(void)
17157 BLANK();
17158 #undef ENTRY
17159
17160+ DEFINE(TSS_size, sizeof(struct tss_struct));
17161 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17162 BLANK();
17163
17164diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17165index a0e067d..9c7db16 100644
17166--- a/arch/x86/kernel/cpu/Makefile
17167+++ b/arch/x86/kernel/cpu/Makefile
17168@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17169 CFLAGS_REMOVE_perf_event.o = -pg
17170 endif
17171
17172-# Make sure load_percpu_segment has no stackprotector
17173-nostackp := $(call cc-option, -fno-stack-protector)
17174-CFLAGS_common.o := $(nostackp)
17175-
17176 obj-y := intel_cacheinfo.o scattered.o topology.o
17177 obj-y += proc.o capflags.o powerflags.o common.o
17178 obj-y += vmware.o hypervisor.o mshyperv.o
17179diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17180index fa96eb0..03efe73 100644
17181--- a/arch/x86/kernel/cpu/amd.c
17182+++ b/arch/x86/kernel/cpu/amd.c
17183@@ -737,7 +737,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17184 unsigned int size)
17185 {
17186 /* AMD errata T13 (order #21922) */
17187- if ((c->x86 == 6)) {
17188+ if (c->x86 == 6) {
17189 /* Duron Rev A0 */
17190 if (c->x86_model == 3 && c->x86_mask == 0)
17191 size = 64;
17192diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17193index d814772..c615653 100644
17194--- a/arch/x86/kernel/cpu/common.c
17195+++ b/arch/x86/kernel/cpu/common.c
17196@@ -88,60 +88,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17197
17198 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17199
17200-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17201-#ifdef CONFIG_X86_64
17202- /*
17203- * We need valid kernel segments for data and code in long mode too
17204- * IRET will check the segment types kkeil 2000/10/28
17205- * Also sysret mandates a special GDT layout
17206- *
17207- * TLS descriptors are currently at a different place compared to i386.
17208- * Hopefully nobody expects them at a fixed place (Wine?)
17209- */
17210- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17211- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17212- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17213- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17214- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17215- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17216-#else
17217- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17218- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17219- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17220- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17221- /*
17222- * Segments used for calling PnP BIOS have byte granularity.
17223- * They code segments and data segments have fixed 64k limits,
17224- * the transfer segment sizes are set at run time.
17225- */
17226- /* 32-bit code */
17227- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17228- /* 16-bit code */
17229- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17230- /* 16-bit data */
17231- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17232- /* 16-bit data */
17233- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17234- /* 16-bit data */
17235- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17236- /*
17237- * The APM segments have byte granularity and their bases
17238- * are set at run time. All have 64k limits.
17239- */
17240- /* 32-bit code */
17241- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17242- /* 16-bit code */
17243- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17244- /* data */
17245- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17246-
17247- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17248- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17249- GDT_STACK_CANARY_INIT
17250-#endif
17251-} };
17252-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17253-
17254 static int __init x86_xsave_setup(char *s)
17255 {
17256 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17257@@ -386,7 +332,7 @@ void switch_to_new_gdt(int cpu)
17258 {
17259 struct desc_ptr gdt_descr;
17260
17261- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17262+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17263 gdt_descr.size = GDT_SIZE - 1;
17264 load_gdt(&gdt_descr);
17265 /* Reload the per-cpu base */
17266@@ -882,6 +828,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17267 /* Filter out anything that depends on CPUID levels we don't have */
17268 filter_cpuid_features(c, true);
17269
17270+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17271+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17272+#endif
17273+
17274 /* If the model name is still unset, do table lookup. */
17275 if (!c->x86_model_id[0]) {
17276 const char *p;
17277@@ -1065,10 +1015,12 @@ static __init int setup_disablecpuid(char *arg)
17278 }
17279 __setup("clearcpuid=", setup_disablecpuid);
17280
17281+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17282+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17283+
17284 #ifdef CONFIG_X86_64
17285 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17286-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17287- (unsigned long) nmi_idt_table };
17288+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17289
17290 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17291 irq_stack_union) __aligned(PAGE_SIZE);
17292@@ -1082,7 +1034,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17293 EXPORT_PER_CPU_SYMBOL(current_task);
17294
17295 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17296- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17297+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17298 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17299
17300 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17301@@ -1227,7 +1179,7 @@ void __cpuinit cpu_init(void)
17302 load_ucode_ap();
17303
17304 cpu = stack_smp_processor_id();
17305- t = &per_cpu(init_tss, cpu);
17306+ t = init_tss + cpu;
17307 oist = &per_cpu(orig_ist, cpu);
17308
17309 #ifdef CONFIG_NUMA
17310@@ -1253,7 +1205,7 @@ void __cpuinit cpu_init(void)
17311 switch_to_new_gdt(cpu);
17312 loadsegment(fs, 0);
17313
17314- load_idt((const struct desc_ptr *)&idt_descr);
17315+ load_idt(&idt_descr);
17316
17317 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17318 syscall_init();
17319@@ -1262,7 +1214,6 @@ void __cpuinit cpu_init(void)
17320 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17321 barrier();
17322
17323- x86_configure_nx();
17324 enable_x2apic();
17325
17326 /*
17327@@ -1314,7 +1265,7 @@ void __cpuinit cpu_init(void)
17328 {
17329 int cpu = smp_processor_id();
17330 struct task_struct *curr = current;
17331- struct tss_struct *t = &per_cpu(init_tss, cpu);
17332+ struct tss_struct *t = init_tss + cpu;
17333 struct thread_struct *thread = &curr->thread;
17334
17335 show_ucode_info_early();
17336diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
17337index 1905ce9..a7ac587 100644
17338--- a/arch/x86/kernel/cpu/intel.c
17339+++ b/arch/x86/kernel/cpu/intel.c
17340@@ -173,7 +173,7 @@ static void __cpuinit trap_init_f00f_bug(void)
17341 * Update the IDT descriptor and reload the IDT so that
17342 * it uses the read-only mapped virtual address.
17343 */
17344- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
17345+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
17346 load_idt(&idt_descr);
17347 }
17348 #endif
17349diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17350index 7c6f7d5..8cac382 100644
17351--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17352+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17353@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17354 };
17355
17356 #ifdef CONFIG_AMD_NB
17357+static struct attribute *default_attrs_amd_nb[] = {
17358+ &type.attr,
17359+ &level.attr,
17360+ &coherency_line_size.attr,
17361+ &physical_line_partition.attr,
17362+ &ways_of_associativity.attr,
17363+ &number_of_sets.attr,
17364+ &size.attr,
17365+ &shared_cpu_map.attr,
17366+ &shared_cpu_list.attr,
17367+ NULL,
17368+ NULL,
17369+ NULL,
17370+ NULL
17371+};
17372+
17373 static struct attribute ** __cpuinit amd_l3_attrs(void)
17374 {
17375 static struct attribute **attrs;
17376@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17377
17378 n = ARRAY_SIZE(default_attrs);
17379
17380- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17381- n += 2;
17382-
17383- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17384- n += 1;
17385-
17386- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17387- if (attrs == NULL)
17388- return attrs = default_attrs;
17389-
17390- for (n = 0; default_attrs[n]; n++)
17391- attrs[n] = default_attrs[n];
17392+ attrs = default_attrs_amd_nb;
17393
17394 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17395 attrs[n++] = &cache_disable_0.attr;
17396@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17397 .default_attrs = default_attrs,
17398 };
17399
17400+#ifdef CONFIG_AMD_NB
17401+static struct kobj_type ktype_cache_amd_nb = {
17402+ .sysfs_ops = &sysfs_ops,
17403+ .default_attrs = default_attrs_amd_nb,
17404+};
17405+#endif
17406+
17407 static struct kobj_type ktype_percpu_entry = {
17408 .sysfs_ops = &sysfs_ops,
17409 };
17410@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17411 return retval;
17412 }
17413
17414+#ifdef CONFIG_AMD_NB
17415+ amd_l3_attrs();
17416+#endif
17417+
17418 for (i = 0; i < num_cache_leaves; i++) {
17419+ struct kobj_type *ktype;
17420+
17421 this_object = INDEX_KOBJECT_PTR(cpu, i);
17422 this_object->cpu = cpu;
17423 this_object->index = i;
17424
17425 this_leaf = CPUID4_INFO_IDX(cpu, i);
17426
17427- ktype_cache.default_attrs = default_attrs;
17428+ ktype = &ktype_cache;
17429 #ifdef CONFIG_AMD_NB
17430 if (this_leaf->base.nb)
17431- ktype_cache.default_attrs = amd_l3_attrs();
17432+ ktype = &ktype_cache_amd_nb;
17433 #endif
17434 retval = kobject_init_and_add(&(this_object->kobj),
17435- &ktype_cache,
17436+ ktype,
17437 per_cpu(ici_cache_kobject, cpu),
17438 "index%1lu", i);
17439 if (unlikely(retval)) {
17440@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17441 return NOTIFY_OK;
17442 }
17443
17444-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17445+static struct notifier_block cacheinfo_cpu_notifier = {
17446 .notifier_call = cacheinfo_cpu_callback,
17447 };
17448
17449diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17450index 7bc1263..bff5686 100644
17451--- a/arch/x86/kernel/cpu/mcheck/mce.c
17452+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17453@@ -45,6 +45,7 @@
17454 #include <asm/processor.h>
17455 #include <asm/mce.h>
17456 #include <asm/msr.h>
17457+#include <asm/local.h>
17458
17459 #include "mce-internal.h"
17460
17461@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17462 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17463 m->cs, m->ip);
17464
17465- if (m->cs == __KERNEL_CS)
17466+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17467 print_symbol("{%s}", m->ip);
17468 pr_cont("\n");
17469 }
17470@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17471
17472 #define PANIC_TIMEOUT 5 /* 5 seconds */
17473
17474-static atomic_t mce_paniced;
17475+static atomic_unchecked_t mce_paniced;
17476
17477 static int fake_panic;
17478-static atomic_t mce_fake_paniced;
17479+static atomic_unchecked_t mce_fake_paniced;
17480
17481 /* Panic in progress. Enable interrupts and wait for final IPI */
17482 static void wait_for_panic(void)
17483@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17484 /*
17485 * Make sure only one CPU runs in machine check panic
17486 */
17487- if (atomic_inc_return(&mce_paniced) > 1)
17488+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17489 wait_for_panic();
17490 barrier();
17491
17492@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17493 console_verbose();
17494 } else {
17495 /* Don't log too much for fake panic */
17496- if (atomic_inc_return(&mce_fake_paniced) > 1)
17497+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17498 return;
17499 }
17500 /* First print corrected ones that are still unlogged */
17501@@ -353,7 +354,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17502 if (!fake_panic) {
17503 if (panic_timeout == 0)
17504 panic_timeout = mca_cfg.panic_timeout;
17505- panic(msg);
17506+ panic("%s", msg);
17507 } else
17508 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
17509 }
17510@@ -683,7 +684,7 @@ static int mce_timed_out(u64 *t)
17511 * might have been modified by someone else.
17512 */
17513 rmb();
17514- if (atomic_read(&mce_paniced))
17515+ if (atomic_read_unchecked(&mce_paniced))
17516 wait_for_panic();
17517 if (!mca_cfg.monarch_timeout)
17518 goto out;
17519@@ -1654,7 +1655,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17520 }
17521
17522 /* Call the installed machine check handler for this CPU setup. */
17523-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17524+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17525 unexpected_machine_check;
17526
17527 /*
17528@@ -1677,7 +1678,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17529 return;
17530 }
17531
17532+ pax_open_kernel();
17533 machine_check_vector = do_machine_check;
17534+ pax_close_kernel();
17535
17536 __mcheck_cpu_init_generic();
17537 __mcheck_cpu_init_vendor(c);
17538@@ -1691,7 +1694,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17539 */
17540
17541 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17542-static int mce_chrdev_open_count; /* #times opened */
17543+static local_t mce_chrdev_open_count; /* #times opened */
17544 static int mce_chrdev_open_exclu; /* already open exclusive? */
17545
17546 static int mce_chrdev_open(struct inode *inode, struct file *file)
17547@@ -1699,7 +1702,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17548 spin_lock(&mce_chrdev_state_lock);
17549
17550 if (mce_chrdev_open_exclu ||
17551- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17552+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17553 spin_unlock(&mce_chrdev_state_lock);
17554
17555 return -EBUSY;
17556@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17557
17558 if (file->f_flags & O_EXCL)
17559 mce_chrdev_open_exclu = 1;
17560- mce_chrdev_open_count++;
17561+ local_inc(&mce_chrdev_open_count);
17562
17563 spin_unlock(&mce_chrdev_state_lock);
17564
17565@@ -1718,7 +1721,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17566 {
17567 spin_lock(&mce_chrdev_state_lock);
17568
17569- mce_chrdev_open_count--;
17570+ local_dec(&mce_chrdev_open_count);
17571 mce_chrdev_open_exclu = 0;
17572
17573 spin_unlock(&mce_chrdev_state_lock);
17574@@ -2364,7 +2367,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17575 return NOTIFY_OK;
17576 }
17577
17578-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17579+static struct notifier_block mce_cpu_notifier = {
17580 .notifier_call = mce_cpu_callback,
17581 };
17582
17583@@ -2374,7 +2377,7 @@ static __init void mce_init_banks(void)
17584
17585 for (i = 0; i < mca_cfg.banks; i++) {
17586 struct mce_bank *b = &mce_banks[i];
17587- struct device_attribute *a = &b->attr;
17588+ device_attribute_no_const *a = &b->attr;
17589
17590 sysfs_attr_init(&a->attr);
17591 a->attr.name = b->attrname;
17592@@ -2442,7 +2445,7 @@ struct dentry *mce_get_debugfs_dir(void)
17593 static void mce_reset(void)
17594 {
17595 cpu_missing = 0;
17596- atomic_set(&mce_fake_paniced, 0);
17597+ atomic_set_unchecked(&mce_fake_paniced, 0);
17598 atomic_set(&mce_executing, 0);
17599 atomic_set(&mce_callin, 0);
17600 atomic_set(&global_nwo, 0);
17601diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17602index 1c044b1..37a2a43 100644
17603--- a/arch/x86/kernel/cpu/mcheck/p5.c
17604+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17605@@ -11,6 +11,7 @@
17606 #include <asm/processor.h>
17607 #include <asm/mce.h>
17608 #include <asm/msr.h>
17609+#include <asm/pgtable.h>
17610
17611 /* By default disabled */
17612 int mce_p5_enabled __read_mostly;
17613@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17614 if (!cpu_has(c, X86_FEATURE_MCE))
17615 return;
17616
17617+ pax_open_kernel();
17618 machine_check_vector = pentium_machine_check;
17619+ pax_close_kernel();
17620 /* Make sure the vector pointer is visible before we enable MCEs: */
17621 wmb();
17622
17623diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17624index 47a1870..8c019a7 100644
17625--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17626+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17627@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17628 return notifier_from_errno(err);
17629 }
17630
17631-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17632+static struct notifier_block thermal_throttle_cpu_notifier =
17633 {
17634 .notifier_call = thermal_throttle_cpu_callback,
17635 };
17636diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17637index e9a701a..35317d6 100644
17638--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17639+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17640@@ -10,6 +10,7 @@
17641 #include <asm/processor.h>
17642 #include <asm/mce.h>
17643 #include <asm/msr.h>
17644+#include <asm/pgtable.h>
17645
17646 /* Machine check handler for WinChip C6: */
17647 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17648@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17649 {
17650 u32 lo, hi;
17651
17652+ pax_open_kernel();
17653 machine_check_vector = winchip_machine_check;
17654+ pax_close_kernel();
17655 /* Make sure the vector pointer is visible before we enable MCEs: */
17656 wmb();
17657
17658diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17659index 726bf96..81f0526 100644
17660--- a/arch/x86/kernel/cpu/mtrr/main.c
17661+++ b/arch/x86/kernel/cpu/mtrr/main.c
17662@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17663 u64 size_or_mask, size_and_mask;
17664 static bool mtrr_aps_delayed_init;
17665
17666-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17667+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17668
17669 const struct mtrr_ops *mtrr_if;
17670
17671diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17672index df5e41f..816c719 100644
17673--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17674+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17675@@ -25,7 +25,7 @@ struct mtrr_ops {
17676 int (*validate_add_page)(unsigned long base, unsigned long size,
17677 unsigned int type);
17678 int (*have_wrcomb)(void);
17679-};
17680+} __do_const;
17681
17682 extern int generic_get_free_region(unsigned long base, unsigned long size,
17683 int replace_reg);
17684diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17685index bf0f01a..9adfee1 100644
17686--- a/arch/x86/kernel/cpu/perf_event.c
17687+++ b/arch/x86/kernel/cpu/perf_event.c
17688@@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17689 pr_info("no hardware sampling interrupt available.\n");
17690 }
17691
17692-static struct attribute_group x86_pmu_format_group = {
17693+static attribute_group_no_const x86_pmu_format_group = {
17694 .name = "format",
17695 .attrs = NULL,
17696 };
17697@@ -1374,7 +1374,7 @@ static struct attribute *events_attr[] = {
17698 NULL,
17699 };
17700
17701-static struct attribute_group x86_pmu_events_group = {
17702+static attribute_group_no_const x86_pmu_events_group = {
17703 .name = "events",
17704 .attrs = events_attr,
17705 };
17706@@ -1873,7 +1873,7 @@ static unsigned long get_segment_base(unsigned int segment)
17707 if (idx > GDT_ENTRIES)
17708 return 0;
17709
17710- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17711+ desc = get_cpu_gdt_table(smp_processor_id());
17712 }
17713
17714 return get_desc_base(desc + idx);
17715@@ -1963,7 +1963,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17716 break;
17717
17718 perf_callchain_store(entry, frame.return_address);
17719- fp = frame.next_frame;
17720+ fp = (const void __force_user *)frame.next_frame;
17721 }
17722 }
17723
17724diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17725index 4a0a462..be3b204 100644
17726--- a/arch/x86/kernel/cpu/perf_event_intel.c
17727+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17728@@ -1994,10 +1994,10 @@ __init int intel_pmu_init(void)
17729 * v2 and above have a perf capabilities MSR
17730 */
17731 if (version > 1) {
17732- u64 capabilities;
17733+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17734
17735- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17736- x86_pmu.intel_cap.capabilities = capabilities;
17737+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17738+ x86_pmu.intel_cap.capabilities = capabilities;
17739 }
17740
17741 intel_ds_init();
17742diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17743index 3e091f0..d2dc8d6 100644
17744--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17745+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17746@@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17747 static int __init uncore_type_init(struct intel_uncore_type *type)
17748 {
17749 struct intel_uncore_pmu *pmus;
17750- struct attribute_group *attr_group;
17751+ attribute_group_no_const *attr_group;
17752 struct attribute **attrs;
17753 int i, j;
17754
17755@@ -2826,7 +2826,7 @@ static int
17756 return NOTIFY_OK;
17757 }
17758
17759-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17760+static struct notifier_block uncore_cpu_nb = {
17761 .notifier_call = uncore_cpu_notifier,
17762 /*
17763 * to migrate uncore events, our notifier should be executed
17764diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17765index e68a455..975a932 100644
17766--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17767+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17768@@ -428,7 +428,7 @@ struct intel_uncore_box {
17769 struct uncore_event_desc {
17770 struct kobj_attribute attr;
17771 const char *config;
17772-};
17773+} __do_const;
17774
17775 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17776 { \
17777diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17778index 1e4dbcf..b9a34c2 100644
17779--- a/arch/x86/kernel/cpuid.c
17780+++ b/arch/x86/kernel/cpuid.c
17781@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17782 return notifier_from_errno(err);
17783 }
17784
17785-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17786+static struct notifier_block cpuid_class_cpu_notifier =
17787 {
17788 .notifier_call = cpuid_class_cpu_callback,
17789 };
17790diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17791index 74467fe..18793d5 100644
17792--- a/arch/x86/kernel/crash.c
17793+++ b/arch/x86/kernel/crash.c
17794@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17795 {
17796 #ifdef CONFIG_X86_32
17797 struct pt_regs fixed_regs;
17798-#endif
17799
17800-#ifdef CONFIG_X86_32
17801- if (!user_mode_vm(regs)) {
17802+ if (!user_mode(regs)) {
17803 crash_fixup_ss_esp(&fixed_regs, regs);
17804 regs = &fixed_regs;
17805 }
17806diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
17807index afa64ad..dce67dd 100644
17808--- a/arch/x86/kernel/crash_dump_64.c
17809+++ b/arch/x86/kernel/crash_dump_64.c
17810@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
17811 return -ENOMEM;
17812
17813 if (userbuf) {
17814- if (copy_to_user(buf, vaddr + offset, csize)) {
17815+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
17816 iounmap(vaddr);
17817 return -EFAULT;
17818 }
17819diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17820index 37250fe..bf2ec74 100644
17821--- a/arch/x86/kernel/doublefault_32.c
17822+++ b/arch/x86/kernel/doublefault_32.c
17823@@ -11,7 +11,7 @@
17824
17825 #define DOUBLEFAULT_STACKSIZE (1024)
17826 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17827-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17828+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17829
17830 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17831
17832@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17833 unsigned long gdt, tss;
17834
17835 store_gdt(&gdt_desc);
17836- gdt = gdt_desc.address;
17837+ gdt = (unsigned long)gdt_desc.address;
17838
17839 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17840
17841@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17842 /* 0x2 bit is always set */
17843 .flags = X86_EFLAGS_SF | 0x2,
17844 .sp = STACK_START,
17845- .es = __USER_DS,
17846+ .es = __KERNEL_DS,
17847 .cs = __KERNEL_CS,
17848 .ss = __KERNEL_DS,
17849- .ds = __USER_DS,
17850+ .ds = __KERNEL_DS,
17851 .fs = __KERNEL_PERCPU,
17852
17853 .__cr3 = __pa_nodebug(swapper_pg_dir),
17854diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17855index c8797d5..c605e53 100644
17856--- a/arch/x86/kernel/dumpstack.c
17857+++ b/arch/x86/kernel/dumpstack.c
17858@@ -2,6 +2,9 @@
17859 * Copyright (C) 1991, 1992 Linus Torvalds
17860 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17861 */
17862+#ifdef CONFIG_GRKERNSEC_HIDESYM
17863+#define __INCLUDED_BY_HIDESYM 1
17864+#endif
17865 #include <linux/kallsyms.h>
17866 #include <linux/kprobes.h>
17867 #include <linux/uaccess.h>
17868@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17869 static void
17870 print_ftrace_graph_addr(unsigned long addr, void *data,
17871 const struct stacktrace_ops *ops,
17872- struct thread_info *tinfo, int *graph)
17873+ struct task_struct *task, int *graph)
17874 {
17875- struct task_struct *task;
17876 unsigned long ret_addr;
17877 int index;
17878
17879 if (addr != (unsigned long)return_to_handler)
17880 return;
17881
17882- task = tinfo->task;
17883 index = task->curr_ret_stack;
17884
17885 if (!task->ret_stack || index < *graph)
17886@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17887 static inline void
17888 print_ftrace_graph_addr(unsigned long addr, void *data,
17889 const struct stacktrace_ops *ops,
17890- struct thread_info *tinfo, int *graph)
17891+ struct task_struct *task, int *graph)
17892 { }
17893 #endif
17894
17895@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17896 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17897 */
17898
17899-static inline int valid_stack_ptr(struct thread_info *tinfo,
17900- void *p, unsigned int size, void *end)
17901+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17902 {
17903- void *t = tinfo;
17904 if (end) {
17905 if (p < end && p >= (end-THREAD_SIZE))
17906 return 1;
17907@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17908 }
17909
17910 unsigned long
17911-print_context_stack(struct thread_info *tinfo,
17912+print_context_stack(struct task_struct *task, void *stack_start,
17913 unsigned long *stack, unsigned long bp,
17914 const struct stacktrace_ops *ops, void *data,
17915 unsigned long *end, int *graph)
17916 {
17917 struct stack_frame *frame = (struct stack_frame *)bp;
17918
17919- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17920+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17921 unsigned long addr;
17922
17923 addr = *stack;
17924@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17925 } else {
17926 ops->address(data, addr, 0);
17927 }
17928- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17929+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17930 }
17931 stack++;
17932 }
17933@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17934 EXPORT_SYMBOL_GPL(print_context_stack);
17935
17936 unsigned long
17937-print_context_stack_bp(struct thread_info *tinfo,
17938+print_context_stack_bp(struct task_struct *task, void *stack_start,
17939 unsigned long *stack, unsigned long bp,
17940 const struct stacktrace_ops *ops, void *data,
17941 unsigned long *end, int *graph)
17942@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17943 struct stack_frame *frame = (struct stack_frame *)bp;
17944 unsigned long *ret_addr = &frame->return_address;
17945
17946- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17947+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17948 unsigned long addr = *ret_addr;
17949
17950 if (!__kernel_text_address(addr))
17951@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17952 ops->address(data, addr, 1);
17953 frame = frame->next_frame;
17954 ret_addr = &frame->return_address;
17955- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17956+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17957 }
17958
17959 return (unsigned long)frame;
17960@@ -189,7 +188,7 @@ void dump_stack(void)
17961
17962 bp = stack_frame(current, NULL);
17963 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17964- current->pid, current->comm, print_tainted(),
17965+ task_pid_nr(current), current->comm, print_tainted(),
17966 init_utsname()->release,
17967 (int)strcspn(init_utsname()->version, " "),
17968 init_utsname()->version);
17969@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17970 }
17971 EXPORT_SYMBOL_GPL(oops_begin);
17972
17973+extern void gr_handle_kernel_exploit(void);
17974+
17975 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17976 {
17977 if (regs && kexec_should_crash(current))
17978@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17979 panic("Fatal exception in interrupt");
17980 if (panic_on_oops)
17981 panic("Fatal exception");
17982- do_exit(signr);
17983+
17984+ gr_handle_kernel_exploit();
17985+
17986+ do_group_exit(signr);
17987 }
17988
17989 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17990@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17991 print_modules();
17992 show_regs(regs);
17993 #ifdef CONFIG_X86_32
17994- if (user_mode_vm(regs)) {
17995+ if (user_mode(regs)) {
17996 sp = regs->sp;
17997 ss = regs->ss & 0xffff;
17998 } else {
17999@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
18000 unsigned long flags = oops_begin();
18001 int sig = SIGSEGV;
18002
18003- if (!user_mode_vm(regs))
18004+ if (!user_mode(regs))
18005 report_bug(regs->ip, regs);
18006
18007 if (__die(str, regs, err))
18008diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
18009index 1038a41..db2c12b 100644
18010--- a/arch/x86/kernel/dumpstack_32.c
18011+++ b/arch/x86/kernel/dumpstack_32.c
18012@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18013 bp = stack_frame(task, regs);
18014
18015 for (;;) {
18016- struct thread_info *context;
18017+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18018
18019- context = (struct thread_info *)
18020- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
18021- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
18022+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18023
18024- stack = (unsigned long *)context->previous_esp;
18025- if (!stack)
18026+ if (stack_start == task_stack_page(task))
18027 break;
18028+ stack = *(unsigned long **)stack_start;
18029 if (ops->stack(data, "IRQ") < 0)
18030 break;
18031 touch_nmi_watchdog();
18032@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
18033 {
18034 int i;
18035
18036- __show_regs(regs, !user_mode_vm(regs));
18037+ __show_regs(regs, !user_mode(regs));
18038
18039 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
18040 TASK_COMM_LEN, current->comm, task_pid_nr(current),
18041@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
18042 * When in-kernel, we also print out the stack and code at the
18043 * time of the fault..
18044 */
18045- if (!user_mode_vm(regs)) {
18046+ if (!user_mode(regs)) {
18047 unsigned int code_prologue = code_bytes * 43 / 64;
18048 unsigned int code_len = code_bytes;
18049 unsigned char c;
18050 u8 *ip;
18051+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
18052
18053 pr_emerg("Stack:\n");
18054 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
18055
18056 pr_emerg("Code:");
18057
18058- ip = (u8 *)regs->ip - code_prologue;
18059+ ip = (u8 *)regs->ip - code_prologue + cs_base;
18060 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
18061 /* try starting at IP */
18062- ip = (u8 *)regs->ip;
18063+ ip = (u8 *)regs->ip + cs_base;
18064 code_len = code_len - code_prologue + 1;
18065 }
18066 for (i = 0; i < code_len; i++, ip++) {
18067@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
18068 pr_cont(" Bad EIP value.");
18069 break;
18070 }
18071- if (ip == (u8 *)regs->ip)
18072+ if (ip == (u8 *)regs->ip + cs_base)
18073 pr_cont(" <%02x>", c);
18074 else
18075 pr_cont(" %02x", c);
18076@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
18077 {
18078 unsigned short ud2;
18079
18080+ ip = ktla_ktva(ip);
18081 if (ip < PAGE_OFFSET)
18082 return 0;
18083 if (probe_kernel_address((unsigned short *)ip, ud2))
18084@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
18085
18086 return ud2 == 0x0b0f;
18087 }
18088+
18089+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18090+void pax_check_alloca(unsigned long size)
18091+{
18092+ unsigned long sp = (unsigned long)&sp, stack_left;
18093+
18094+ /* all kernel stacks are of the same size */
18095+ stack_left = sp & (THREAD_SIZE - 1);
18096+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18097+}
18098+EXPORT_SYMBOL(pax_check_alloca);
18099+#endif
18100diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
18101index b653675..51cc8c0 100644
18102--- a/arch/x86/kernel/dumpstack_64.c
18103+++ b/arch/x86/kernel/dumpstack_64.c
18104@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18105 unsigned long *irq_stack_end =
18106 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
18107 unsigned used = 0;
18108- struct thread_info *tinfo;
18109 int graph = 0;
18110 unsigned long dummy;
18111+ void *stack_start;
18112
18113 if (!task)
18114 task = current;
18115@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18116 * current stack address. If the stacks consist of nested
18117 * exceptions
18118 */
18119- tinfo = task_thread_info(task);
18120 for (;;) {
18121 char *id;
18122 unsigned long *estack_end;
18123+
18124 estack_end = in_exception_stack(cpu, (unsigned long)stack,
18125 &used, &id);
18126
18127@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18128 if (ops->stack(data, id) < 0)
18129 break;
18130
18131- bp = ops->walk_stack(tinfo, stack, bp, ops,
18132+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
18133 data, estack_end, &graph);
18134 ops->stack(data, "<EOE>");
18135 /*
18136@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18137 * second-to-last pointer (index -2 to end) in the
18138 * exception stack:
18139 */
18140+ if ((u16)estack_end[-1] != __KERNEL_DS)
18141+ goto out;
18142 stack = (unsigned long *) estack_end[-2];
18143 continue;
18144 }
18145@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18146 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18147 if (ops->stack(data, "IRQ") < 0)
18148 break;
18149- bp = ops->walk_stack(tinfo, stack, bp,
18150+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18151 ops, data, irq_stack_end, &graph);
18152 /*
18153 * We link to the next stack (which would be
18154@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18155 /*
18156 * This handles the process stack:
18157 */
18158- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18159+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18160+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18161+out:
18162 put_cpu();
18163 }
18164 EXPORT_SYMBOL(dump_trace);
18165@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
18166 {
18167 int i;
18168 unsigned long sp;
18169- const int cpu = smp_processor_id();
18170+ const int cpu = raw_smp_processor_id();
18171 struct task_struct *cur = current;
18172
18173 sp = regs->sp;
18174@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
18175
18176 return ud2 == 0x0b0f;
18177 }
18178+
18179+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18180+void pax_check_alloca(unsigned long size)
18181+{
18182+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18183+ unsigned cpu, used;
18184+ char *id;
18185+
18186+ /* check the process stack first */
18187+ stack_start = (unsigned long)task_stack_page(current);
18188+ stack_end = stack_start + THREAD_SIZE;
18189+ if (likely(stack_start <= sp && sp < stack_end)) {
18190+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18191+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18192+ return;
18193+ }
18194+
18195+ cpu = get_cpu();
18196+
18197+ /* check the irq stacks */
18198+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18199+ stack_start = stack_end - IRQ_STACK_SIZE;
18200+ if (stack_start <= sp && sp < stack_end) {
18201+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18202+ put_cpu();
18203+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18204+ return;
18205+ }
18206+
18207+ /* check the exception stacks */
18208+ used = 0;
18209+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18210+ stack_start = stack_end - EXCEPTION_STKSZ;
18211+ if (stack_end && stack_start <= sp && sp < stack_end) {
18212+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18213+ put_cpu();
18214+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18215+ return;
18216+ }
18217+
18218+ put_cpu();
18219+
18220+ /* unknown stack */
18221+ BUG();
18222+}
18223+EXPORT_SYMBOL(pax_check_alloca);
18224+#endif
18225diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
18226index d32abea..74daf4f 100644
18227--- a/arch/x86/kernel/e820.c
18228+++ b/arch/x86/kernel/e820.c
18229@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
18230
18231 static void early_panic(char *msg)
18232 {
18233- early_printk(msg);
18234- panic(msg);
18235+ early_printk("%s", msg);
18236+ panic("%s", msg);
18237 }
18238
18239 static int userdef __initdata;
18240diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18241index 9b9f18b..9fcaa04 100644
18242--- a/arch/x86/kernel/early_printk.c
18243+++ b/arch/x86/kernel/early_printk.c
18244@@ -7,6 +7,7 @@
18245 #include <linux/pci_regs.h>
18246 #include <linux/pci_ids.h>
18247 #include <linux/errno.h>
18248+#include <linux/sched.h>
18249 #include <asm/io.h>
18250 #include <asm/processor.h>
18251 #include <asm/fcntl.h>
18252diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18253index 8f3e2de..caecc4e 100644
18254--- a/arch/x86/kernel/entry_32.S
18255+++ b/arch/x86/kernel/entry_32.S
18256@@ -177,13 +177,153 @@
18257 /*CFI_REL_OFFSET gs, PT_GS*/
18258 .endm
18259 .macro SET_KERNEL_GS reg
18260+
18261+#ifdef CONFIG_CC_STACKPROTECTOR
18262 movl $(__KERNEL_STACK_CANARY), \reg
18263+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18264+ movl $(__USER_DS), \reg
18265+#else
18266+ xorl \reg, \reg
18267+#endif
18268+
18269 movl \reg, %gs
18270 .endm
18271
18272 #endif /* CONFIG_X86_32_LAZY_GS */
18273
18274-.macro SAVE_ALL
18275+.macro pax_enter_kernel
18276+#ifdef CONFIG_PAX_KERNEXEC
18277+ call pax_enter_kernel
18278+#endif
18279+.endm
18280+
18281+.macro pax_exit_kernel
18282+#ifdef CONFIG_PAX_KERNEXEC
18283+ call pax_exit_kernel
18284+#endif
18285+.endm
18286+
18287+#ifdef CONFIG_PAX_KERNEXEC
18288+ENTRY(pax_enter_kernel)
18289+#ifdef CONFIG_PARAVIRT
18290+ pushl %eax
18291+ pushl %ecx
18292+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18293+ mov %eax, %esi
18294+#else
18295+ mov %cr0, %esi
18296+#endif
18297+ bts $16, %esi
18298+ jnc 1f
18299+ mov %cs, %esi
18300+ cmp $__KERNEL_CS, %esi
18301+ jz 3f
18302+ ljmp $__KERNEL_CS, $3f
18303+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18304+2:
18305+#ifdef CONFIG_PARAVIRT
18306+ mov %esi, %eax
18307+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18308+#else
18309+ mov %esi, %cr0
18310+#endif
18311+3:
18312+#ifdef CONFIG_PARAVIRT
18313+ popl %ecx
18314+ popl %eax
18315+#endif
18316+ ret
18317+ENDPROC(pax_enter_kernel)
18318+
18319+ENTRY(pax_exit_kernel)
18320+#ifdef CONFIG_PARAVIRT
18321+ pushl %eax
18322+ pushl %ecx
18323+#endif
18324+ mov %cs, %esi
18325+ cmp $__KERNEXEC_KERNEL_CS, %esi
18326+ jnz 2f
18327+#ifdef CONFIG_PARAVIRT
18328+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18329+ mov %eax, %esi
18330+#else
18331+ mov %cr0, %esi
18332+#endif
18333+ btr $16, %esi
18334+ ljmp $__KERNEL_CS, $1f
18335+1:
18336+#ifdef CONFIG_PARAVIRT
18337+ mov %esi, %eax
18338+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18339+#else
18340+ mov %esi, %cr0
18341+#endif
18342+2:
18343+#ifdef CONFIG_PARAVIRT
18344+ popl %ecx
18345+ popl %eax
18346+#endif
18347+ ret
18348+ENDPROC(pax_exit_kernel)
18349+#endif
18350+
18351+ .macro pax_erase_kstack
18352+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18353+ call pax_erase_kstack
18354+#endif
18355+ .endm
18356+
18357+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18358+/*
18359+ * ebp: thread_info
18360+ */
18361+ENTRY(pax_erase_kstack)
18362+ pushl %edi
18363+ pushl %ecx
18364+ pushl %eax
18365+
18366+ mov TI_lowest_stack(%ebp), %edi
18367+ mov $-0xBEEF, %eax
18368+ std
18369+
18370+1: mov %edi, %ecx
18371+ and $THREAD_SIZE_asm - 1, %ecx
18372+ shr $2, %ecx
18373+ repne scasl
18374+ jecxz 2f
18375+
18376+ cmp $2*16, %ecx
18377+ jc 2f
18378+
18379+ mov $2*16, %ecx
18380+ repe scasl
18381+ jecxz 2f
18382+ jne 1b
18383+
18384+2: cld
18385+ mov %esp, %ecx
18386+ sub %edi, %ecx
18387+
18388+ cmp $THREAD_SIZE_asm, %ecx
18389+ jb 3f
18390+ ud2
18391+3:
18392+
18393+ shr $2, %ecx
18394+ rep stosl
18395+
18396+ mov TI_task_thread_sp0(%ebp), %edi
18397+ sub $128, %edi
18398+ mov %edi, TI_lowest_stack(%ebp)
18399+
18400+ popl %eax
18401+ popl %ecx
18402+ popl %edi
18403+ ret
18404+ENDPROC(pax_erase_kstack)
18405+#endif
18406+
18407+.macro __SAVE_ALL _DS
18408 cld
18409 PUSH_GS
18410 pushl_cfi %fs
18411@@ -206,7 +346,7 @@
18412 CFI_REL_OFFSET ecx, 0
18413 pushl_cfi %ebx
18414 CFI_REL_OFFSET ebx, 0
18415- movl $(__USER_DS), %edx
18416+ movl $\_DS, %edx
18417 movl %edx, %ds
18418 movl %edx, %es
18419 movl $(__KERNEL_PERCPU), %edx
18420@@ -214,6 +354,15 @@
18421 SET_KERNEL_GS %edx
18422 .endm
18423
18424+.macro SAVE_ALL
18425+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18426+ __SAVE_ALL __KERNEL_DS
18427+ pax_enter_kernel
18428+#else
18429+ __SAVE_ALL __USER_DS
18430+#endif
18431+.endm
18432+
18433 .macro RESTORE_INT_REGS
18434 popl_cfi %ebx
18435 CFI_RESTORE ebx
18436@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18437 popfl_cfi
18438 jmp syscall_exit
18439 CFI_ENDPROC
18440-END(ret_from_fork)
18441+ENDPROC(ret_from_fork)
18442
18443 ENTRY(ret_from_kernel_thread)
18444 CFI_STARTPROC
18445@@ -344,7 +493,15 @@ ret_from_intr:
18446 andl $SEGMENT_RPL_MASK, %eax
18447 #endif
18448 cmpl $USER_RPL, %eax
18449+
18450+#ifdef CONFIG_PAX_KERNEXEC
18451+ jae resume_userspace
18452+
18453+ pax_exit_kernel
18454+ jmp resume_kernel
18455+#else
18456 jb resume_kernel # not returning to v8086 or userspace
18457+#endif
18458
18459 ENTRY(resume_userspace)
18460 LOCKDEP_SYS_EXIT
18461@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18462 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18463 # int/exception return?
18464 jne work_pending
18465- jmp restore_all
18466-END(ret_from_exception)
18467+ jmp restore_all_pax
18468+ENDPROC(ret_from_exception)
18469
18470 #ifdef CONFIG_PREEMPT
18471 ENTRY(resume_kernel)
18472@@ -372,7 +529,7 @@ need_resched:
18473 jz restore_all
18474 call preempt_schedule_irq
18475 jmp need_resched
18476-END(resume_kernel)
18477+ENDPROC(resume_kernel)
18478 #endif
18479 CFI_ENDPROC
18480 /*
18481@@ -406,30 +563,45 @@ sysenter_past_esp:
18482 /*CFI_REL_OFFSET cs, 0*/
18483 /*
18484 * Push current_thread_info()->sysenter_return to the stack.
18485- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18486- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18487 */
18488- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18489+ pushl_cfi $0
18490 CFI_REL_OFFSET eip, 0
18491
18492 pushl_cfi %eax
18493 SAVE_ALL
18494+ GET_THREAD_INFO(%ebp)
18495+ movl TI_sysenter_return(%ebp),%ebp
18496+ movl %ebp,PT_EIP(%esp)
18497 ENABLE_INTERRUPTS(CLBR_NONE)
18498
18499 /*
18500 * Load the potential sixth argument from user stack.
18501 * Careful about security.
18502 */
18503+ movl PT_OLDESP(%esp),%ebp
18504+
18505+#ifdef CONFIG_PAX_MEMORY_UDEREF
18506+ mov PT_OLDSS(%esp),%ds
18507+1: movl %ds:(%ebp),%ebp
18508+ push %ss
18509+ pop %ds
18510+#else
18511 cmpl $__PAGE_OFFSET-3,%ebp
18512 jae syscall_fault
18513 ASM_STAC
18514 1: movl (%ebp),%ebp
18515 ASM_CLAC
18516+#endif
18517+
18518 movl %ebp,PT_EBP(%esp)
18519 _ASM_EXTABLE(1b,syscall_fault)
18520
18521 GET_THREAD_INFO(%ebp)
18522
18523+#ifdef CONFIG_PAX_RANDKSTACK
18524+ pax_erase_kstack
18525+#endif
18526+
18527 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18528 jnz sysenter_audit
18529 sysenter_do_call:
18530@@ -444,12 +616,24 @@ sysenter_do_call:
18531 testl $_TIF_ALLWORK_MASK, %ecx
18532 jne sysexit_audit
18533 sysenter_exit:
18534+
18535+#ifdef CONFIG_PAX_RANDKSTACK
18536+ pushl_cfi %eax
18537+ movl %esp, %eax
18538+ call pax_randomize_kstack
18539+ popl_cfi %eax
18540+#endif
18541+
18542+ pax_erase_kstack
18543+
18544 /* if something modifies registers it must also disable sysexit */
18545 movl PT_EIP(%esp), %edx
18546 movl PT_OLDESP(%esp), %ecx
18547 xorl %ebp,%ebp
18548 TRACE_IRQS_ON
18549 1: mov PT_FS(%esp), %fs
18550+2: mov PT_DS(%esp), %ds
18551+3: mov PT_ES(%esp), %es
18552 PTGS_TO_GS
18553 ENABLE_INTERRUPTS_SYSEXIT
18554
18555@@ -466,6 +650,9 @@ sysenter_audit:
18556 movl %eax,%edx /* 2nd arg: syscall number */
18557 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18558 call __audit_syscall_entry
18559+
18560+ pax_erase_kstack
18561+
18562 pushl_cfi %ebx
18563 movl PT_EAX(%esp),%eax /* reload syscall number */
18564 jmp sysenter_do_call
18565@@ -491,10 +678,16 @@ sysexit_audit:
18566
18567 CFI_ENDPROC
18568 .pushsection .fixup,"ax"
18569-2: movl $0,PT_FS(%esp)
18570+4: movl $0,PT_FS(%esp)
18571+ jmp 1b
18572+5: movl $0,PT_DS(%esp)
18573+ jmp 1b
18574+6: movl $0,PT_ES(%esp)
18575 jmp 1b
18576 .popsection
18577- _ASM_EXTABLE(1b,2b)
18578+ _ASM_EXTABLE(1b,4b)
18579+ _ASM_EXTABLE(2b,5b)
18580+ _ASM_EXTABLE(3b,6b)
18581 PTGS_TO_GS_EX
18582 ENDPROC(ia32_sysenter_target)
18583
18584@@ -509,6 +702,11 @@ ENTRY(system_call)
18585 pushl_cfi %eax # save orig_eax
18586 SAVE_ALL
18587 GET_THREAD_INFO(%ebp)
18588+
18589+#ifdef CONFIG_PAX_RANDKSTACK
18590+ pax_erase_kstack
18591+#endif
18592+
18593 # system call tracing in operation / emulation
18594 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18595 jnz syscall_trace_entry
18596@@ -527,6 +725,15 @@ syscall_exit:
18597 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18598 jne syscall_exit_work
18599
18600+restore_all_pax:
18601+
18602+#ifdef CONFIG_PAX_RANDKSTACK
18603+ movl %esp, %eax
18604+ call pax_randomize_kstack
18605+#endif
18606+
18607+ pax_erase_kstack
18608+
18609 restore_all:
18610 TRACE_IRQS_IRET
18611 restore_all_notrace:
18612@@ -583,14 +790,34 @@ ldt_ss:
18613 * compensating for the offset by changing to the ESPFIX segment with
18614 * a base address that matches for the difference.
18615 */
18616-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18617+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18618 mov %esp, %edx /* load kernel esp */
18619 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18620 mov %dx, %ax /* eax: new kernel esp */
18621 sub %eax, %edx /* offset (low word is 0) */
18622+#ifdef CONFIG_SMP
18623+ movl PER_CPU_VAR(cpu_number), %ebx
18624+ shll $PAGE_SHIFT_asm, %ebx
18625+ addl $cpu_gdt_table, %ebx
18626+#else
18627+ movl $cpu_gdt_table, %ebx
18628+#endif
18629 shr $16, %edx
18630- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18631- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18632+
18633+#ifdef CONFIG_PAX_KERNEXEC
18634+ mov %cr0, %esi
18635+ btr $16, %esi
18636+ mov %esi, %cr0
18637+#endif
18638+
18639+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18640+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18641+
18642+#ifdef CONFIG_PAX_KERNEXEC
18643+ bts $16, %esi
18644+ mov %esi, %cr0
18645+#endif
18646+
18647 pushl_cfi $__ESPFIX_SS
18648 pushl_cfi %eax /* new kernel esp */
18649 /* Disable interrupts, but do not irqtrace this section: we
18650@@ -619,20 +846,18 @@ work_resched:
18651 movl TI_flags(%ebp), %ecx
18652 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18653 # than syscall tracing?
18654- jz restore_all
18655+ jz restore_all_pax
18656 testb $_TIF_NEED_RESCHED, %cl
18657 jnz work_resched
18658
18659 work_notifysig: # deal with pending signals and
18660 # notify-resume requests
18661+ movl %esp, %eax
18662 #ifdef CONFIG_VM86
18663 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18664- movl %esp, %eax
18665 jne work_notifysig_v86 # returning to kernel-space or
18666 # vm86-space
18667 1:
18668-#else
18669- movl %esp, %eax
18670 #endif
18671 TRACE_IRQS_ON
18672 ENABLE_INTERRUPTS(CLBR_NONE)
18673@@ -653,7 +878,7 @@ work_notifysig_v86:
18674 movl %eax, %esp
18675 jmp 1b
18676 #endif
18677-END(work_pending)
18678+ENDPROC(work_pending)
18679
18680 # perform syscall exit tracing
18681 ALIGN
18682@@ -661,11 +886,14 @@ syscall_trace_entry:
18683 movl $-ENOSYS,PT_EAX(%esp)
18684 movl %esp, %eax
18685 call syscall_trace_enter
18686+
18687+ pax_erase_kstack
18688+
18689 /* What it returned is what we'll actually use. */
18690 cmpl $(NR_syscalls), %eax
18691 jnae syscall_call
18692 jmp syscall_exit
18693-END(syscall_trace_entry)
18694+ENDPROC(syscall_trace_entry)
18695
18696 # perform syscall exit tracing
18697 ALIGN
18698@@ -678,21 +906,25 @@ syscall_exit_work:
18699 movl %esp, %eax
18700 call syscall_trace_leave
18701 jmp resume_userspace
18702-END(syscall_exit_work)
18703+ENDPROC(syscall_exit_work)
18704 CFI_ENDPROC
18705
18706 RING0_INT_FRAME # can't unwind into user space anyway
18707 syscall_fault:
18708+#ifdef CONFIG_PAX_MEMORY_UDEREF
18709+ push %ss
18710+ pop %ds
18711+#endif
18712 ASM_CLAC
18713 GET_THREAD_INFO(%ebp)
18714 movl $-EFAULT,PT_EAX(%esp)
18715 jmp resume_userspace
18716-END(syscall_fault)
18717+ENDPROC(syscall_fault)
18718
18719 syscall_badsys:
18720 movl $-ENOSYS,PT_EAX(%esp)
18721 jmp resume_userspace
18722-END(syscall_badsys)
18723+ENDPROC(syscall_badsys)
18724 CFI_ENDPROC
18725 /*
18726 * End of kprobes section
18727@@ -708,8 +940,15 @@ END(syscall_badsys)
18728 * normal stack and adjusts ESP with the matching offset.
18729 */
18730 /* fixup the stack */
18731- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18732- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18733+#ifdef CONFIG_SMP
18734+ movl PER_CPU_VAR(cpu_number), %ebx
18735+ shll $PAGE_SHIFT_asm, %ebx
18736+ addl $cpu_gdt_table, %ebx
18737+#else
18738+ movl $cpu_gdt_table, %ebx
18739+#endif
18740+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18741+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18742 shl $16, %eax
18743 addl %esp, %eax /* the adjusted stack pointer */
18744 pushl_cfi $__KERNEL_DS
18745@@ -762,7 +1001,7 @@ vector=vector+1
18746 .endr
18747 2: jmp common_interrupt
18748 .endr
18749-END(irq_entries_start)
18750+ENDPROC(irq_entries_start)
18751
18752 .previous
18753 END(interrupt)
18754@@ -813,7 +1052,7 @@ ENTRY(coprocessor_error)
18755 pushl_cfi $do_coprocessor_error
18756 jmp error_code
18757 CFI_ENDPROC
18758-END(coprocessor_error)
18759+ENDPROC(coprocessor_error)
18760
18761 ENTRY(simd_coprocessor_error)
18762 RING0_INT_FRAME
18763@@ -835,7 +1074,7 @@ ENTRY(simd_coprocessor_error)
18764 #endif
18765 jmp error_code
18766 CFI_ENDPROC
18767-END(simd_coprocessor_error)
18768+ENDPROC(simd_coprocessor_error)
18769
18770 ENTRY(device_not_available)
18771 RING0_INT_FRAME
18772@@ -844,18 +1083,18 @@ ENTRY(device_not_available)
18773 pushl_cfi $do_device_not_available
18774 jmp error_code
18775 CFI_ENDPROC
18776-END(device_not_available)
18777+ENDPROC(device_not_available)
18778
18779 #ifdef CONFIG_PARAVIRT
18780 ENTRY(native_iret)
18781 iret
18782 _ASM_EXTABLE(native_iret, iret_exc)
18783-END(native_iret)
18784+ENDPROC(native_iret)
18785
18786 ENTRY(native_irq_enable_sysexit)
18787 sti
18788 sysexit
18789-END(native_irq_enable_sysexit)
18790+ENDPROC(native_irq_enable_sysexit)
18791 #endif
18792
18793 ENTRY(overflow)
18794@@ -865,7 +1104,7 @@ ENTRY(overflow)
18795 pushl_cfi $do_overflow
18796 jmp error_code
18797 CFI_ENDPROC
18798-END(overflow)
18799+ENDPROC(overflow)
18800
18801 ENTRY(bounds)
18802 RING0_INT_FRAME
18803@@ -874,7 +1113,7 @@ ENTRY(bounds)
18804 pushl_cfi $do_bounds
18805 jmp error_code
18806 CFI_ENDPROC
18807-END(bounds)
18808+ENDPROC(bounds)
18809
18810 ENTRY(invalid_op)
18811 RING0_INT_FRAME
18812@@ -883,7 +1122,7 @@ ENTRY(invalid_op)
18813 pushl_cfi $do_invalid_op
18814 jmp error_code
18815 CFI_ENDPROC
18816-END(invalid_op)
18817+ENDPROC(invalid_op)
18818
18819 ENTRY(coprocessor_segment_overrun)
18820 RING0_INT_FRAME
18821@@ -892,7 +1131,7 @@ ENTRY(coprocessor_segment_overrun)
18822 pushl_cfi $do_coprocessor_segment_overrun
18823 jmp error_code
18824 CFI_ENDPROC
18825-END(coprocessor_segment_overrun)
18826+ENDPROC(coprocessor_segment_overrun)
18827
18828 ENTRY(invalid_TSS)
18829 RING0_EC_FRAME
18830@@ -900,7 +1139,7 @@ ENTRY(invalid_TSS)
18831 pushl_cfi $do_invalid_TSS
18832 jmp error_code
18833 CFI_ENDPROC
18834-END(invalid_TSS)
18835+ENDPROC(invalid_TSS)
18836
18837 ENTRY(segment_not_present)
18838 RING0_EC_FRAME
18839@@ -908,7 +1147,7 @@ ENTRY(segment_not_present)
18840 pushl_cfi $do_segment_not_present
18841 jmp error_code
18842 CFI_ENDPROC
18843-END(segment_not_present)
18844+ENDPROC(segment_not_present)
18845
18846 ENTRY(stack_segment)
18847 RING0_EC_FRAME
18848@@ -916,7 +1155,7 @@ ENTRY(stack_segment)
18849 pushl_cfi $do_stack_segment
18850 jmp error_code
18851 CFI_ENDPROC
18852-END(stack_segment)
18853+ENDPROC(stack_segment)
18854
18855 ENTRY(alignment_check)
18856 RING0_EC_FRAME
18857@@ -924,7 +1163,7 @@ ENTRY(alignment_check)
18858 pushl_cfi $do_alignment_check
18859 jmp error_code
18860 CFI_ENDPROC
18861-END(alignment_check)
18862+ENDPROC(alignment_check)
18863
18864 ENTRY(divide_error)
18865 RING0_INT_FRAME
18866@@ -933,7 +1172,7 @@ ENTRY(divide_error)
18867 pushl_cfi $do_divide_error
18868 jmp error_code
18869 CFI_ENDPROC
18870-END(divide_error)
18871+ENDPROC(divide_error)
18872
18873 #ifdef CONFIG_X86_MCE
18874 ENTRY(machine_check)
18875@@ -943,7 +1182,7 @@ ENTRY(machine_check)
18876 pushl_cfi machine_check_vector
18877 jmp error_code
18878 CFI_ENDPROC
18879-END(machine_check)
18880+ENDPROC(machine_check)
18881 #endif
18882
18883 ENTRY(spurious_interrupt_bug)
18884@@ -953,7 +1192,7 @@ ENTRY(spurious_interrupt_bug)
18885 pushl_cfi $do_spurious_interrupt_bug
18886 jmp error_code
18887 CFI_ENDPROC
18888-END(spurious_interrupt_bug)
18889+ENDPROC(spurious_interrupt_bug)
18890 /*
18891 * End of kprobes section
18892 */
18893@@ -1063,7 +1302,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
18894
18895 ENTRY(mcount)
18896 ret
18897-END(mcount)
18898+ENDPROC(mcount)
18899
18900 ENTRY(ftrace_caller)
18901 cmpl $0, function_trace_stop
18902@@ -1096,7 +1335,7 @@ ftrace_graph_call:
18903 .globl ftrace_stub
18904 ftrace_stub:
18905 ret
18906-END(ftrace_caller)
18907+ENDPROC(ftrace_caller)
18908
18909 ENTRY(ftrace_regs_caller)
18910 pushf /* push flags before compare (in cs location) */
18911@@ -1197,7 +1436,7 @@ trace:
18912 popl %ecx
18913 popl %eax
18914 jmp ftrace_stub
18915-END(mcount)
18916+ENDPROC(mcount)
18917 #endif /* CONFIG_DYNAMIC_FTRACE */
18918 #endif /* CONFIG_FUNCTION_TRACER */
18919
18920@@ -1215,7 +1454,7 @@ ENTRY(ftrace_graph_caller)
18921 popl %ecx
18922 popl %eax
18923 ret
18924-END(ftrace_graph_caller)
18925+ENDPROC(ftrace_graph_caller)
18926
18927 .globl return_to_handler
18928 return_to_handler:
18929@@ -1271,15 +1510,18 @@ error_code:
18930 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18931 REG_TO_PTGS %ecx
18932 SET_KERNEL_GS %ecx
18933- movl $(__USER_DS), %ecx
18934+ movl $(__KERNEL_DS), %ecx
18935 movl %ecx, %ds
18936 movl %ecx, %es
18937+
18938+ pax_enter_kernel
18939+
18940 TRACE_IRQS_OFF
18941 movl %esp,%eax # pt_regs pointer
18942 call *%edi
18943 jmp ret_from_exception
18944 CFI_ENDPROC
18945-END(page_fault)
18946+ENDPROC(page_fault)
18947
18948 /*
18949 * Debug traps and NMI can happen at the one SYSENTER instruction
18950@@ -1322,7 +1564,7 @@ debug_stack_correct:
18951 call do_debug
18952 jmp ret_from_exception
18953 CFI_ENDPROC
18954-END(debug)
18955+ENDPROC(debug)
18956
18957 /*
18958 * NMI is doubly nasty. It can happen _while_ we're handling
18959@@ -1360,6 +1602,9 @@ nmi_stack_correct:
18960 xorl %edx,%edx # zero error code
18961 movl %esp,%eax # pt_regs pointer
18962 call do_nmi
18963+
18964+ pax_exit_kernel
18965+
18966 jmp restore_all_notrace
18967 CFI_ENDPROC
18968
18969@@ -1396,12 +1641,15 @@ nmi_espfix_stack:
18970 FIXUP_ESPFIX_STACK # %eax == %esp
18971 xorl %edx,%edx # zero error code
18972 call do_nmi
18973+
18974+ pax_exit_kernel
18975+
18976 RESTORE_REGS
18977 lss 12+4(%esp), %esp # back to espfix stack
18978 CFI_ADJUST_CFA_OFFSET -24
18979 jmp irq_return
18980 CFI_ENDPROC
18981-END(nmi)
18982+ENDPROC(nmi)
18983
18984 ENTRY(int3)
18985 RING0_INT_FRAME
18986@@ -1414,14 +1662,14 @@ ENTRY(int3)
18987 call do_int3
18988 jmp ret_from_exception
18989 CFI_ENDPROC
18990-END(int3)
18991+ENDPROC(int3)
18992
18993 ENTRY(general_protection)
18994 RING0_EC_FRAME
18995 pushl_cfi $do_general_protection
18996 jmp error_code
18997 CFI_ENDPROC
18998-END(general_protection)
18999+ENDPROC(general_protection)
19000
19001 #ifdef CONFIG_KVM_GUEST
19002 ENTRY(async_page_fault)
19003@@ -1430,7 +1678,7 @@ ENTRY(async_page_fault)
19004 pushl_cfi $do_async_page_fault
19005 jmp error_code
19006 CFI_ENDPROC
19007-END(async_page_fault)
19008+ENDPROC(async_page_fault)
19009 #endif
19010
19011 /*
19012diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
19013index c1d01e6..a88cf02 100644
19014--- a/arch/x86/kernel/entry_64.S
19015+++ b/arch/x86/kernel/entry_64.S
19016@@ -59,6 +59,8 @@
19017 #include <asm/context_tracking.h>
19018 #include <asm/smap.h>
19019 #include <linux/err.h>
19020+#include <asm/pgtable.h>
19021+#include <asm/alternative-asm.h>
19022
19023 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
19024 #include <linux/elf-em.h>
19025@@ -80,8 +82,9 @@
19026 #ifdef CONFIG_DYNAMIC_FTRACE
19027
19028 ENTRY(function_hook)
19029+ pax_force_retaddr
19030 retq
19031-END(function_hook)
19032+ENDPROC(function_hook)
19033
19034 /* skip is set if stack has been adjusted */
19035 .macro ftrace_caller_setup skip=0
19036@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
19037 #endif
19038
19039 GLOBAL(ftrace_stub)
19040+ pax_force_retaddr
19041 retq
19042-END(ftrace_caller)
19043+ENDPROC(ftrace_caller)
19044
19045 ENTRY(ftrace_regs_caller)
19046 /* Save the current flags before compare (in SS location)*/
19047@@ -191,7 +195,7 @@ ftrace_restore_flags:
19048 popfq
19049 jmp ftrace_stub
19050
19051-END(ftrace_regs_caller)
19052+ENDPROC(ftrace_regs_caller)
19053
19054
19055 #else /* ! CONFIG_DYNAMIC_FTRACE */
19056@@ -212,6 +216,7 @@ ENTRY(function_hook)
19057 #endif
19058
19059 GLOBAL(ftrace_stub)
19060+ pax_force_retaddr
19061 retq
19062
19063 trace:
19064@@ -225,12 +230,13 @@ trace:
19065 #endif
19066 subq $MCOUNT_INSN_SIZE, %rdi
19067
19068+ pax_force_fptr ftrace_trace_function
19069 call *ftrace_trace_function
19070
19071 MCOUNT_RESTORE_FRAME
19072
19073 jmp ftrace_stub
19074-END(function_hook)
19075+ENDPROC(function_hook)
19076 #endif /* CONFIG_DYNAMIC_FTRACE */
19077 #endif /* CONFIG_FUNCTION_TRACER */
19078
19079@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
19080
19081 MCOUNT_RESTORE_FRAME
19082
19083+ pax_force_retaddr
19084 retq
19085-END(ftrace_graph_caller)
19086+ENDPROC(ftrace_graph_caller)
19087
19088 GLOBAL(return_to_handler)
19089 subq $24, %rsp
19090@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
19091 movq 8(%rsp), %rdx
19092 movq (%rsp), %rax
19093 addq $24, %rsp
19094+ pax_force_fptr %rdi
19095 jmp *%rdi
19096+ENDPROC(return_to_handler)
19097 #endif
19098
19099
19100@@ -284,6 +293,309 @@ ENTRY(native_usergs_sysret64)
19101 ENDPROC(native_usergs_sysret64)
19102 #endif /* CONFIG_PARAVIRT */
19103
19104+ .macro ljmpq sel, off
19105+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
19106+ .byte 0x48; ljmp *1234f(%rip)
19107+ .pushsection .rodata
19108+ .align 16
19109+ 1234: .quad \off; .word \sel
19110+ .popsection
19111+#else
19112+ pushq $\sel
19113+ pushq $\off
19114+ lretq
19115+#endif
19116+ .endm
19117+
19118+ .macro pax_enter_kernel
19119+ pax_set_fptr_mask
19120+#ifdef CONFIG_PAX_KERNEXEC
19121+ call pax_enter_kernel
19122+#endif
19123+ .endm
19124+
19125+ .macro pax_exit_kernel
19126+#ifdef CONFIG_PAX_KERNEXEC
19127+ call pax_exit_kernel
19128+#endif
19129+ .endm
19130+
19131+#ifdef CONFIG_PAX_KERNEXEC
19132+ENTRY(pax_enter_kernel)
19133+ pushq %rdi
19134+
19135+#ifdef CONFIG_PARAVIRT
19136+ PV_SAVE_REGS(CLBR_RDI)
19137+#endif
19138+
19139+ GET_CR0_INTO_RDI
19140+ bts $16,%rdi
19141+ jnc 3f
19142+ mov %cs,%edi
19143+ cmp $__KERNEL_CS,%edi
19144+ jnz 2f
19145+1:
19146+
19147+#ifdef CONFIG_PARAVIRT
19148+ PV_RESTORE_REGS(CLBR_RDI)
19149+#endif
19150+
19151+ popq %rdi
19152+ pax_force_retaddr
19153+ retq
19154+
19155+2: ljmpq __KERNEL_CS,1b
19156+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19157+4: SET_RDI_INTO_CR0
19158+ jmp 1b
19159+ENDPROC(pax_enter_kernel)
19160+
19161+ENTRY(pax_exit_kernel)
19162+ pushq %rdi
19163+
19164+#ifdef CONFIG_PARAVIRT
19165+ PV_SAVE_REGS(CLBR_RDI)
19166+#endif
19167+
19168+ mov %cs,%rdi
19169+ cmp $__KERNEXEC_KERNEL_CS,%edi
19170+ jz 2f
19171+ GET_CR0_INTO_RDI
19172+ bts $16,%rdi
19173+ jnc 4f
19174+1:
19175+
19176+#ifdef CONFIG_PARAVIRT
19177+ PV_RESTORE_REGS(CLBR_RDI);
19178+#endif
19179+
19180+ popq %rdi
19181+ pax_force_retaddr
19182+ retq
19183+
19184+2: GET_CR0_INTO_RDI
19185+ btr $16,%rdi
19186+ jnc 4f
19187+ ljmpq __KERNEL_CS,3f
19188+3: SET_RDI_INTO_CR0
19189+ jmp 1b
19190+4: ud2
19191+ jmp 4b
19192+ENDPROC(pax_exit_kernel)
19193+#endif
19194+
19195+ .macro pax_enter_kernel_user
19196+ pax_set_fptr_mask
19197+#ifdef CONFIG_PAX_MEMORY_UDEREF
19198+ call pax_enter_kernel_user
19199+#endif
19200+ .endm
19201+
19202+ .macro pax_exit_kernel_user
19203+#ifdef CONFIG_PAX_MEMORY_UDEREF
19204+ call pax_exit_kernel_user
19205+#endif
19206+#ifdef CONFIG_PAX_RANDKSTACK
19207+ pushq %rax
19208+ pushq %r11
19209+ call pax_randomize_kstack
19210+ popq %r11
19211+ popq %rax
19212+#endif
19213+ .endm
19214+
19215+#ifdef CONFIG_PAX_MEMORY_UDEREF
19216+ENTRY(pax_enter_kernel_user)
19217+ pushq %rdi
19218+ pushq %rbx
19219+
19220+#ifdef CONFIG_PARAVIRT
19221+ PV_SAVE_REGS(CLBR_RDI)
19222+#endif
19223+
19224+ GET_CR3_INTO_RDI
19225+ mov %rdi,%rbx
19226+ add $__START_KERNEL_map,%rbx
19227+ sub phys_base(%rip),%rbx
19228+
19229+#ifdef CONFIG_PARAVIRT
19230+ cmpl $0, pv_info+PARAVIRT_enabled
19231+ jz 1f
19232+ pushq %rdi
19233+ i = 0
19234+ .rept USER_PGD_PTRS
19235+ mov i*8(%rbx),%rsi
19236+ mov $0,%sil
19237+ lea i*8(%rbx),%rdi
19238+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19239+ i = i + 1
19240+ .endr
19241+ popq %rdi
19242+ jmp 2f
19243+1:
19244+#endif
19245+
19246+ i = 0
19247+ .rept USER_PGD_PTRS
19248+ movb $0,i*8(%rbx)
19249+ i = i + 1
19250+ .endr
19251+
19252+#ifdef CONFIG_PARAVIRT
19253+2:
19254+#endif
19255+ SET_RDI_INTO_CR3
19256+
19257+#ifdef CONFIG_PAX_KERNEXEC
19258+ GET_CR0_INTO_RDI
19259+ bts $16,%rdi
19260+ SET_RDI_INTO_CR0
19261+#endif
19262+
19263+#ifdef CONFIG_PARAVIRT
19264+ PV_RESTORE_REGS(CLBR_RDI)
19265+#endif
19266+
19267+ popq %rbx
19268+ popq %rdi
19269+ pax_force_retaddr
19270+ retq
19271+ENDPROC(pax_enter_kernel_user)
19272+
19273+ENTRY(pax_exit_kernel_user)
19274+ pushq %rdi
19275+ pushq %rbx
19276+
19277+#ifdef CONFIG_PARAVIRT
19278+ PV_SAVE_REGS(CLBR_RDI)
19279+#endif
19280+
19281+#ifdef CONFIG_PAX_KERNEXEC
19282+ GET_CR0_INTO_RDI
19283+ btr $16,%rdi
19284+ jnc 3f
19285+ SET_RDI_INTO_CR0
19286+#endif
19287+
19288+ GET_CR3_INTO_RDI
19289+ mov %rdi,%rbx
19290+ add $__START_KERNEL_map,%rbx
19291+ sub phys_base(%rip),%rbx
19292+
19293+#ifdef CONFIG_PARAVIRT
19294+ cmpl $0, pv_info+PARAVIRT_enabled
19295+ jz 1f
19296+ i = 0
19297+ .rept USER_PGD_PTRS
19298+ mov i*8(%rbx),%rsi
19299+ mov $0x67,%sil
19300+ lea i*8(%rbx),%rdi
19301+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19302+ i = i + 1
19303+ .endr
19304+ jmp 2f
19305+1:
19306+#endif
19307+
19308+ i = 0
19309+ .rept USER_PGD_PTRS
19310+ movb $0x67,i*8(%rbx)
19311+ i = i + 1
19312+ .endr
19313+
19314+#ifdef CONFIG_PARAVIRT
19315+2: PV_RESTORE_REGS(CLBR_RDI)
19316+#endif
19317+
19318+ popq %rbx
19319+ popq %rdi
19320+ pax_force_retaddr
19321+ retq
19322+3: ud2
19323+ jmp 3b
19324+ENDPROC(pax_exit_kernel_user)
19325+#endif
19326+
19327+ .macro pax_enter_kernel_nmi
19328+ pax_set_fptr_mask
19329+
19330+#ifdef CONFIG_PAX_KERNEXEC
19331+ GET_CR0_INTO_RDI
19332+ bts $16,%rdi
19333+ jc 110f
19334+ SET_RDI_INTO_CR0
19335+ or $2,%ebx
19336+110:
19337+#endif
19338+ .endm
19339+
19340+ .macro pax_exit_kernel_nmi
19341+#ifdef CONFIG_PAX_KERNEXEC
19342+ btr $1,%ebx
19343+ jnc 110f
19344+ GET_CR0_INTO_RDI
19345+ btr $16,%rdi
19346+ SET_RDI_INTO_CR0
19347+110:
19348+#endif
19349+ .endm
19350+
19351+ .macro pax_erase_kstack
19352+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19353+ call pax_erase_kstack
19354+#endif
19355+ .endm
19356+
19357+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19358+ENTRY(pax_erase_kstack)
19359+ pushq %rdi
19360+ pushq %rcx
19361+ pushq %rax
19362+ pushq %r11
19363+
19364+ GET_THREAD_INFO(%r11)
19365+ mov TI_lowest_stack(%r11), %rdi
19366+ mov $-0xBEEF, %rax
19367+ std
19368+
19369+1: mov %edi, %ecx
19370+ and $THREAD_SIZE_asm - 1, %ecx
19371+ shr $3, %ecx
19372+ repne scasq
19373+ jecxz 2f
19374+
19375+ cmp $2*8, %ecx
19376+ jc 2f
19377+
19378+ mov $2*8, %ecx
19379+ repe scasq
19380+ jecxz 2f
19381+ jne 1b
19382+
19383+2: cld
19384+ mov %esp, %ecx
19385+ sub %edi, %ecx
19386+
19387+ cmp $THREAD_SIZE_asm, %rcx
19388+ jb 3f
19389+ ud2
19390+3:
19391+
19392+ shr $3, %ecx
19393+ rep stosq
19394+
19395+ mov TI_task_thread_sp0(%r11), %rdi
19396+ sub $256, %rdi
19397+ mov %rdi, TI_lowest_stack(%r11)
19398+
19399+ popq %r11
19400+ popq %rax
19401+ popq %rcx
19402+ popq %rdi
19403+ pax_force_retaddr
19404+ ret
19405+ENDPROC(pax_erase_kstack)
19406+#endif
19407
19408 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19409 #ifdef CONFIG_TRACE_IRQFLAGS
19410@@ -375,8 +687,8 @@ ENDPROC(native_usergs_sysret64)
19411 .endm
19412
19413 .macro UNFAKE_STACK_FRAME
19414- addq $8*6, %rsp
19415- CFI_ADJUST_CFA_OFFSET -(6*8)
19416+ addq $8*6 + ARG_SKIP, %rsp
19417+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19418 .endm
19419
19420 /*
19421@@ -463,7 +775,7 @@ ENDPROC(native_usergs_sysret64)
19422 movq %rsp, %rsi
19423
19424 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19425- testl $3, CS-RBP(%rsi)
19426+ testb $3, CS-RBP(%rsi)
19427 je 1f
19428 SWAPGS
19429 /*
19430@@ -498,9 +810,10 @@ ENTRY(save_rest)
19431 movq_cfi r15, R15+16
19432 movq %r11, 8(%rsp) /* return address */
19433 FIXUP_TOP_OF_STACK %r11, 16
19434+ pax_force_retaddr
19435 ret
19436 CFI_ENDPROC
19437-END(save_rest)
19438+ENDPROC(save_rest)
19439
19440 /* save complete stack frame */
19441 .pushsection .kprobes.text, "ax"
19442@@ -529,9 +842,10 @@ ENTRY(save_paranoid)
19443 js 1f /* negative -> in kernel */
19444 SWAPGS
19445 xorl %ebx,%ebx
19446-1: ret
19447+1: pax_force_retaddr_bts
19448+ ret
19449 CFI_ENDPROC
19450-END(save_paranoid)
19451+ENDPROC(save_paranoid)
19452 .popsection
19453
19454 /*
19455@@ -553,7 +867,7 @@ ENTRY(ret_from_fork)
19456
19457 RESTORE_REST
19458
19459- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19460+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19461 jz 1f
19462
19463 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19464@@ -571,7 +885,7 @@ ENTRY(ret_from_fork)
19465 RESTORE_REST
19466 jmp int_ret_from_sys_call
19467 CFI_ENDPROC
19468-END(ret_from_fork)
19469+ENDPROC(ret_from_fork)
19470
19471 /*
19472 * System call entry. Up to 6 arguments in registers are supported.
19473@@ -608,7 +922,7 @@ END(ret_from_fork)
19474 ENTRY(system_call)
19475 CFI_STARTPROC simple
19476 CFI_SIGNAL_FRAME
19477- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19478+ CFI_DEF_CFA rsp,0
19479 CFI_REGISTER rip,rcx
19480 /*CFI_REGISTER rflags,r11*/
19481 SWAPGS_UNSAFE_STACK
19482@@ -621,16 +935,23 @@ GLOBAL(system_call_after_swapgs)
19483
19484 movq %rsp,PER_CPU_VAR(old_rsp)
19485 movq PER_CPU_VAR(kernel_stack),%rsp
19486+ SAVE_ARGS 8*6,0
19487+ pax_enter_kernel_user
19488+
19489+#ifdef CONFIG_PAX_RANDKSTACK
19490+ pax_erase_kstack
19491+#endif
19492+
19493 /*
19494 * No need to follow this irqs off/on section - it's straight
19495 * and short:
19496 */
19497 ENABLE_INTERRUPTS(CLBR_NONE)
19498- SAVE_ARGS 8,0
19499 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19500 movq %rcx,RIP-ARGOFFSET(%rsp)
19501 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19502- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19503+ GET_THREAD_INFO(%rcx)
19504+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19505 jnz tracesys
19506 system_call_fastpath:
19507 #if __SYSCALL_MASK == ~0
19508@@ -640,7 +961,7 @@ system_call_fastpath:
19509 cmpl $__NR_syscall_max,%eax
19510 #endif
19511 ja badsys
19512- movq %r10,%rcx
19513+ movq R10-ARGOFFSET(%rsp),%rcx
19514 call *sys_call_table(,%rax,8) # XXX: rip relative
19515 movq %rax,RAX-ARGOFFSET(%rsp)
19516 /*
19517@@ -654,10 +975,13 @@ sysret_check:
19518 LOCKDEP_SYS_EXIT
19519 DISABLE_INTERRUPTS(CLBR_NONE)
19520 TRACE_IRQS_OFF
19521- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19522+ GET_THREAD_INFO(%rcx)
19523+ movl TI_flags(%rcx),%edx
19524 andl %edi,%edx
19525 jnz sysret_careful
19526 CFI_REMEMBER_STATE
19527+ pax_exit_kernel_user
19528+ pax_erase_kstack
19529 /*
19530 * sysretq will re-enable interrupts:
19531 */
19532@@ -709,14 +1033,18 @@ badsys:
19533 * jump back to the normal fast path.
19534 */
19535 auditsys:
19536- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19537+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19538 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19539 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19540 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19541 movq %rax,%rsi /* 2nd arg: syscall number */
19542 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19543 call __audit_syscall_entry
19544+
19545+ pax_erase_kstack
19546+
19547 LOAD_ARGS 0 /* reload call-clobbered registers */
19548+ pax_set_fptr_mask
19549 jmp system_call_fastpath
19550
19551 /*
19552@@ -737,7 +1065,7 @@ sysret_audit:
19553 /* Do syscall tracing */
19554 tracesys:
19555 #ifdef CONFIG_AUDITSYSCALL
19556- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19557+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19558 jz auditsys
19559 #endif
19560 SAVE_REST
19561@@ -745,12 +1073,16 @@ tracesys:
19562 FIXUP_TOP_OF_STACK %rdi
19563 movq %rsp,%rdi
19564 call syscall_trace_enter
19565+
19566+ pax_erase_kstack
19567+
19568 /*
19569 * Reload arg registers from stack in case ptrace changed them.
19570 * We don't reload %rax because syscall_trace_enter() returned
19571 * the value it wants us to use in the table lookup.
19572 */
19573 LOAD_ARGS ARGOFFSET, 1
19574+ pax_set_fptr_mask
19575 RESTORE_REST
19576 #if __SYSCALL_MASK == ~0
19577 cmpq $__NR_syscall_max,%rax
19578@@ -759,7 +1091,7 @@ tracesys:
19579 cmpl $__NR_syscall_max,%eax
19580 #endif
19581 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19582- movq %r10,%rcx /* fixup for C */
19583+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19584 call *sys_call_table(,%rax,8)
19585 movq %rax,RAX-ARGOFFSET(%rsp)
19586 /* Use IRET because user could have changed frame */
19587@@ -780,7 +1112,9 @@ GLOBAL(int_with_check)
19588 andl %edi,%edx
19589 jnz int_careful
19590 andl $~TS_COMPAT,TI_status(%rcx)
19591- jmp retint_swapgs
19592+ pax_exit_kernel_user
19593+ pax_erase_kstack
19594+ jmp retint_swapgs_pax
19595
19596 /* Either reschedule or signal or syscall exit tracking needed. */
19597 /* First do a reschedule test. */
19598@@ -826,7 +1160,7 @@ int_restore_rest:
19599 TRACE_IRQS_OFF
19600 jmp int_with_check
19601 CFI_ENDPROC
19602-END(system_call)
19603+ENDPROC(system_call)
19604
19605 .macro FORK_LIKE func
19606 ENTRY(stub_\func)
19607@@ -839,9 +1173,10 @@ ENTRY(stub_\func)
19608 DEFAULT_FRAME 0 8 /* offset 8: return address */
19609 call sys_\func
19610 RESTORE_TOP_OF_STACK %r11, 8
19611+ pax_force_retaddr
19612 ret $REST_SKIP /* pop extended registers */
19613 CFI_ENDPROC
19614-END(stub_\func)
19615+ENDPROC(stub_\func)
19616 .endm
19617
19618 .macro FIXED_FRAME label,func
19619@@ -851,9 +1186,10 @@ ENTRY(\label)
19620 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
19621 call \func
19622 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
19623+ pax_force_retaddr
19624 ret
19625 CFI_ENDPROC
19626-END(\label)
19627+ENDPROC(\label)
19628 .endm
19629
19630 FORK_LIKE clone
19631@@ -870,9 +1206,10 @@ ENTRY(ptregscall_common)
19632 movq_cfi_restore R12+8, r12
19633 movq_cfi_restore RBP+8, rbp
19634 movq_cfi_restore RBX+8, rbx
19635+ pax_force_retaddr
19636 ret $REST_SKIP /* pop extended registers */
19637 CFI_ENDPROC
19638-END(ptregscall_common)
19639+ENDPROC(ptregscall_common)
19640
19641 ENTRY(stub_execve)
19642 CFI_STARTPROC
19643@@ -885,7 +1222,7 @@ ENTRY(stub_execve)
19644 RESTORE_REST
19645 jmp int_ret_from_sys_call
19646 CFI_ENDPROC
19647-END(stub_execve)
19648+ENDPROC(stub_execve)
19649
19650 /*
19651 * sigreturn is special because it needs to restore all registers on return.
19652@@ -902,7 +1239,7 @@ ENTRY(stub_rt_sigreturn)
19653 RESTORE_REST
19654 jmp int_ret_from_sys_call
19655 CFI_ENDPROC
19656-END(stub_rt_sigreturn)
19657+ENDPROC(stub_rt_sigreturn)
19658
19659 #ifdef CONFIG_X86_X32_ABI
19660 ENTRY(stub_x32_rt_sigreturn)
19661@@ -916,7 +1253,7 @@ ENTRY(stub_x32_rt_sigreturn)
19662 RESTORE_REST
19663 jmp int_ret_from_sys_call
19664 CFI_ENDPROC
19665-END(stub_x32_rt_sigreturn)
19666+ENDPROC(stub_x32_rt_sigreturn)
19667
19668 ENTRY(stub_x32_execve)
19669 CFI_STARTPROC
19670@@ -930,7 +1267,7 @@ ENTRY(stub_x32_execve)
19671 RESTORE_REST
19672 jmp int_ret_from_sys_call
19673 CFI_ENDPROC
19674-END(stub_x32_execve)
19675+ENDPROC(stub_x32_execve)
19676
19677 #endif
19678
19679@@ -967,7 +1304,7 @@ vector=vector+1
19680 2: jmp common_interrupt
19681 .endr
19682 CFI_ENDPROC
19683-END(irq_entries_start)
19684+ENDPROC(irq_entries_start)
19685
19686 .previous
19687 END(interrupt)
19688@@ -987,6 +1324,16 @@ END(interrupt)
19689 subq $ORIG_RAX-RBP, %rsp
19690 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19691 SAVE_ARGS_IRQ
19692+#ifdef CONFIG_PAX_MEMORY_UDEREF
19693+ testb $3, CS(%rdi)
19694+ jnz 1f
19695+ pax_enter_kernel
19696+ jmp 2f
19697+1: pax_enter_kernel_user
19698+2:
19699+#else
19700+ pax_enter_kernel
19701+#endif
19702 call \func
19703 .endm
19704
19705@@ -1019,7 +1366,7 @@ ret_from_intr:
19706
19707 exit_intr:
19708 GET_THREAD_INFO(%rcx)
19709- testl $3,CS-ARGOFFSET(%rsp)
19710+ testb $3,CS-ARGOFFSET(%rsp)
19711 je retint_kernel
19712
19713 /* Interrupt came from user space */
19714@@ -1041,12 +1388,16 @@ retint_swapgs: /* return to user-space */
19715 * The iretq could re-enable interrupts:
19716 */
19717 DISABLE_INTERRUPTS(CLBR_ANY)
19718+ pax_exit_kernel_user
19719+retint_swapgs_pax:
19720 TRACE_IRQS_IRETQ
19721 SWAPGS
19722 jmp restore_args
19723
19724 retint_restore_args: /* return to kernel space */
19725 DISABLE_INTERRUPTS(CLBR_ANY)
19726+ pax_exit_kernel
19727+ pax_force_retaddr (RIP-ARGOFFSET)
19728 /*
19729 * The iretq could re-enable interrupts:
19730 */
19731@@ -1129,7 +1480,7 @@ ENTRY(retint_kernel)
19732 #endif
19733
19734 CFI_ENDPROC
19735-END(common_interrupt)
19736+ENDPROC(common_interrupt)
19737 /*
19738 * End of kprobes section
19739 */
19740@@ -1147,7 +1498,7 @@ ENTRY(\sym)
19741 interrupt \do_sym
19742 jmp ret_from_intr
19743 CFI_ENDPROC
19744-END(\sym)
19745+ENDPROC(\sym)
19746 .endm
19747
19748 #ifdef CONFIG_SMP
19749@@ -1203,12 +1554,22 @@ ENTRY(\sym)
19750 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19751 call error_entry
19752 DEFAULT_FRAME 0
19753+#ifdef CONFIG_PAX_MEMORY_UDEREF
19754+ testb $3, CS(%rsp)
19755+ jnz 1f
19756+ pax_enter_kernel
19757+ jmp 2f
19758+1: pax_enter_kernel_user
19759+2:
19760+#else
19761+ pax_enter_kernel
19762+#endif
19763 movq %rsp,%rdi /* pt_regs pointer */
19764 xorl %esi,%esi /* no error code */
19765 call \do_sym
19766 jmp error_exit /* %ebx: no swapgs flag */
19767 CFI_ENDPROC
19768-END(\sym)
19769+ENDPROC(\sym)
19770 .endm
19771
19772 .macro paranoidzeroentry sym do_sym
19773@@ -1221,15 +1582,25 @@ ENTRY(\sym)
19774 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19775 call save_paranoid
19776 TRACE_IRQS_OFF
19777+#ifdef CONFIG_PAX_MEMORY_UDEREF
19778+ testb $3, CS(%rsp)
19779+ jnz 1f
19780+ pax_enter_kernel
19781+ jmp 2f
19782+1: pax_enter_kernel_user
19783+2:
19784+#else
19785+ pax_enter_kernel
19786+#endif
19787 movq %rsp,%rdi /* pt_regs pointer */
19788 xorl %esi,%esi /* no error code */
19789 call \do_sym
19790 jmp paranoid_exit /* %ebx: no swapgs flag */
19791 CFI_ENDPROC
19792-END(\sym)
19793+ENDPROC(\sym)
19794 .endm
19795
19796-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19797+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19798 .macro paranoidzeroentry_ist sym do_sym ist
19799 ENTRY(\sym)
19800 INTR_FRAME
19801@@ -1240,14 +1611,30 @@ ENTRY(\sym)
19802 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19803 call save_paranoid
19804 TRACE_IRQS_OFF_DEBUG
19805+#ifdef CONFIG_PAX_MEMORY_UDEREF
19806+ testb $3, CS(%rsp)
19807+ jnz 1f
19808+ pax_enter_kernel
19809+ jmp 2f
19810+1: pax_enter_kernel_user
19811+2:
19812+#else
19813+ pax_enter_kernel
19814+#endif
19815 movq %rsp,%rdi /* pt_regs pointer */
19816 xorl %esi,%esi /* no error code */
19817+#ifdef CONFIG_SMP
19818+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19819+ lea init_tss(%r12), %r12
19820+#else
19821+ lea init_tss(%rip), %r12
19822+#endif
19823 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19824 call \do_sym
19825 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19826 jmp paranoid_exit /* %ebx: no swapgs flag */
19827 CFI_ENDPROC
19828-END(\sym)
19829+ENDPROC(\sym)
19830 .endm
19831
19832 .macro errorentry sym do_sym
19833@@ -1259,13 +1646,23 @@ ENTRY(\sym)
19834 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19835 call error_entry
19836 DEFAULT_FRAME 0
19837+#ifdef CONFIG_PAX_MEMORY_UDEREF
19838+ testb $3, CS(%rsp)
19839+ jnz 1f
19840+ pax_enter_kernel
19841+ jmp 2f
19842+1: pax_enter_kernel_user
19843+2:
19844+#else
19845+ pax_enter_kernel
19846+#endif
19847 movq %rsp,%rdi /* pt_regs pointer */
19848 movq ORIG_RAX(%rsp),%rsi /* get error code */
19849 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19850 call \do_sym
19851 jmp error_exit /* %ebx: no swapgs flag */
19852 CFI_ENDPROC
19853-END(\sym)
19854+ENDPROC(\sym)
19855 .endm
19856
19857 /* error code is on the stack already */
19858@@ -1279,13 +1676,23 @@ ENTRY(\sym)
19859 call save_paranoid
19860 DEFAULT_FRAME 0
19861 TRACE_IRQS_OFF
19862+#ifdef CONFIG_PAX_MEMORY_UDEREF
19863+ testb $3, CS(%rsp)
19864+ jnz 1f
19865+ pax_enter_kernel
19866+ jmp 2f
19867+1: pax_enter_kernel_user
19868+2:
19869+#else
19870+ pax_enter_kernel
19871+#endif
19872 movq %rsp,%rdi /* pt_regs pointer */
19873 movq ORIG_RAX(%rsp),%rsi /* get error code */
19874 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19875 call \do_sym
19876 jmp paranoid_exit /* %ebx: no swapgs flag */
19877 CFI_ENDPROC
19878-END(\sym)
19879+ENDPROC(\sym)
19880 .endm
19881
19882 zeroentry divide_error do_divide_error
19883@@ -1315,9 +1722,10 @@ gs_change:
19884 2: mfence /* workaround */
19885 SWAPGS
19886 popfq_cfi
19887+ pax_force_retaddr
19888 ret
19889 CFI_ENDPROC
19890-END(native_load_gs_index)
19891+ENDPROC(native_load_gs_index)
19892
19893 _ASM_EXTABLE(gs_change,bad_gs)
19894 .section .fixup,"ax"
19895@@ -1345,9 +1753,10 @@ ENTRY(call_softirq)
19896 CFI_DEF_CFA_REGISTER rsp
19897 CFI_ADJUST_CFA_OFFSET -8
19898 decl PER_CPU_VAR(irq_count)
19899+ pax_force_retaddr
19900 ret
19901 CFI_ENDPROC
19902-END(call_softirq)
19903+ENDPROC(call_softirq)
19904
19905 #ifdef CONFIG_XEN
19906 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19907@@ -1385,7 +1794,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19908 decl PER_CPU_VAR(irq_count)
19909 jmp error_exit
19910 CFI_ENDPROC
19911-END(xen_do_hypervisor_callback)
19912+ENDPROC(xen_do_hypervisor_callback)
19913
19914 /*
19915 * Hypervisor uses this for application faults while it executes.
19916@@ -1444,7 +1853,7 @@ ENTRY(xen_failsafe_callback)
19917 SAVE_ALL
19918 jmp error_exit
19919 CFI_ENDPROC
19920-END(xen_failsafe_callback)
19921+ENDPROC(xen_failsafe_callback)
19922
19923 apicinterrupt HYPERVISOR_CALLBACK_VECTOR \
19924 xen_hvm_callback_vector xen_evtchn_do_upcall
19925@@ -1496,18 +1905,33 @@ ENTRY(paranoid_exit)
19926 DEFAULT_FRAME
19927 DISABLE_INTERRUPTS(CLBR_NONE)
19928 TRACE_IRQS_OFF_DEBUG
19929- testl %ebx,%ebx /* swapgs needed? */
19930+ testl $1,%ebx /* swapgs needed? */
19931 jnz paranoid_restore
19932- testl $3,CS(%rsp)
19933+ testb $3,CS(%rsp)
19934 jnz paranoid_userspace
19935+#ifdef CONFIG_PAX_MEMORY_UDEREF
19936+ pax_exit_kernel
19937+ TRACE_IRQS_IRETQ 0
19938+ SWAPGS_UNSAFE_STACK
19939+ RESTORE_ALL 8
19940+ pax_force_retaddr_bts
19941+ jmp irq_return
19942+#endif
19943 paranoid_swapgs:
19944+#ifdef CONFIG_PAX_MEMORY_UDEREF
19945+ pax_exit_kernel_user
19946+#else
19947+ pax_exit_kernel
19948+#endif
19949 TRACE_IRQS_IRETQ 0
19950 SWAPGS_UNSAFE_STACK
19951 RESTORE_ALL 8
19952 jmp irq_return
19953 paranoid_restore:
19954+ pax_exit_kernel
19955 TRACE_IRQS_IRETQ_DEBUG 0
19956 RESTORE_ALL 8
19957+ pax_force_retaddr_bts
19958 jmp irq_return
19959 paranoid_userspace:
19960 GET_THREAD_INFO(%rcx)
19961@@ -1536,7 +1960,7 @@ paranoid_schedule:
19962 TRACE_IRQS_OFF
19963 jmp paranoid_userspace
19964 CFI_ENDPROC
19965-END(paranoid_exit)
19966+ENDPROC(paranoid_exit)
19967
19968 /*
19969 * Exception entry point. This expects an error code/orig_rax on the stack.
19970@@ -1563,12 +1987,13 @@ ENTRY(error_entry)
19971 movq_cfi r14, R14+8
19972 movq_cfi r15, R15+8
19973 xorl %ebx,%ebx
19974- testl $3,CS+8(%rsp)
19975+ testb $3,CS+8(%rsp)
19976 je error_kernelspace
19977 error_swapgs:
19978 SWAPGS
19979 error_sti:
19980 TRACE_IRQS_OFF
19981+ pax_force_retaddr_bts
19982 ret
19983
19984 /*
19985@@ -1595,7 +2020,7 @@ bstep_iret:
19986 movq %rcx,RIP+8(%rsp)
19987 jmp error_swapgs
19988 CFI_ENDPROC
19989-END(error_entry)
19990+ENDPROC(error_entry)
19991
19992
19993 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19994@@ -1606,7 +2031,7 @@ ENTRY(error_exit)
19995 DISABLE_INTERRUPTS(CLBR_NONE)
19996 TRACE_IRQS_OFF
19997 GET_THREAD_INFO(%rcx)
19998- testl %eax,%eax
19999+ testl $1,%eax
20000 jne retint_kernel
20001 LOCKDEP_SYS_EXIT_IRQ
20002 movl TI_flags(%rcx),%edx
20003@@ -1615,7 +2040,7 @@ ENTRY(error_exit)
20004 jnz retint_careful
20005 jmp retint_swapgs
20006 CFI_ENDPROC
20007-END(error_exit)
20008+ENDPROC(error_exit)
20009
20010 /*
20011 * Test if a given stack is an NMI stack or not.
20012@@ -1673,9 +2098,11 @@ ENTRY(nmi)
20013 * If %cs was not the kernel segment, then the NMI triggered in user
20014 * space, which means it is definitely not nested.
20015 */
20016+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
20017+ je 1f
20018 cmpl $__KERNEL_CS, 16(%rsp)
20019 jne first_nmi
20020-
20021+1:
20022 /*
20023 * Check the special variable on the stack to see if NMIs are
20024 * executing.
20025@@ -1709,8 +2136,7 @@ nested_nmi:
20026
20027 1:
20028 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
20029- leaq -1*8(%rsp), %rdx
20030- movq %rdx, %rsp
20031+ subq $8, %rsp
20032 CFI_ADJUST_CFA_OFFSET 1*8
20033 leaq -10*8(%rsp), %rdx
20034 pushq_cfi $__KERNEL_DS
20035@@ -1728,6 +2154,7 @@ nested_nmi_out:
20036 CFI_RESTORE rdx
20037
20038 /* No need to check faults here */
20039+# pax_force_retaddr_bts
20040 INTERRUPT_RETURN
20041
20042 CFI_RESTORE_STATE
20043@@ -1844,6 +2271,8 @@ end_repeat_nmi:
20044 */
20045 movq %cr2, %r12
20046
20047+ pax_enter_kernel_nmi
20048+
20049 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
20050 movq %rsp,%rdi
20051 movq $-1,%rsi
20052@@ -1856,26 +2285,31 @@ end_repeat_nmi:
20053 movq %r12, %cr2
20054 1:
20055
20056- testl %ebx,%ebx /* swapgs needed? */
20057+ testl $1,%ebx /* swapgs needed? */
20058 jnz nmi_restore
20059 nmi_swapgs:
20060 SWAPGS_UNSAFE_STACK
20061 nmi_restore:
20062+ pax_exit_kernel_nmi
20063 /* Pop the extra iret frame at once */
20064 RESTORE_ALL 6*8
20065+ testb $3, 8(%rsp)
20066+ jnz 1f
20067+ pax_force_retaddr_bts
20068+1:
20069
20070 /* Clear the NMI executing stack variable */
20071 movq $0, 5*8(%rsp)
20072 jmp irq_return
20073 CFI_ENDPROC
20074-END(nmi)
20075+ENDPROC(nmi)
20076
20077 ENTRY(ignore_sysret)
20078 CFI_STARTPROC
20079 mov $-ENOSYS,%eax
20080 sysret
20081 CFI_ENDPROC
20082-END(ignore_sysret)
20083+ENDPROC(ignore_sysret)
20084
20085 /*
20086 * End of kprobes section
20087diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
20088index 42a392a..fbbd930 100644
20089--- a/arch/x86/kernel/ftrace.c
20090+++ b/arch/x86/kernel/ftrace.c
20091@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
20092 {
20093 unsigned char replaced[MCOUNT_INSN_SIZE];
20094
20095+ ip = ktla_ktva(ip);
20096+
20097 /*
20098 * Note: Due to modules and __init, code can
20099 * disappear and change, we need to protect against faulting
20100@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20101 unsigned char old[MCOUNT_INSN_SIZE], *new;
20102 int ret;
20103
20104- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
20105+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
20106 new = ftrace_call_replace(ip, (unsigned long)func);
20107
20108 /* See comment above by declaration of modifying_ftrace_code */
20109@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20110 /* Also update the regs callback function */
20111 if (!ret) {
20112 ip = (unsigned long)(&ftrace_regs_call);
20113- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
20114+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
20115 new = ftrace_call_replace(ip, (unsigned long)func);
20116 ret = ftrace_modify_code(ip, old, new);
20117 }
20118@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
20119 * kernel identity mapping to modify code.
20120 */
20121 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
20122- ip = (unsigned long)__va(__pa_symbol(ip));
20123+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
20124
20125 return probe_kernel_write((void *)ip, val, size);
20126 }
20127@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
20128 unsigned char replaced[MCOUNT_INSN_SIZE];
20129 unsigned char brk = BREAKPOINT_INSTRUCTION;
20130
20131- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
20132+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
20133 return -EFAULT;
20134
20135 /* Make sure it is what we expect it to be */
20136@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
20137 return ret;
20138
20139 fail_update:
20140- probe_kernel_write((void *)ip, &old_code[0], 1);
20141+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
20142 goto out;
20143 }
20144
20145@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
20146 {
20147 unsigned char code[MCOUNT_INSN_SIZE];
20148
20149+ ip = ktla_ktva(ip);
20150+
20151 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
20152 return -EFAULT;
20153
20154diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
20155index 8f3201d..6898c0c 100644
20156--- a/arch/x86/kernel/head64.c
20157+++ b/arch/x86/kernel/head64.c
20158@@ -67,12 +67,12 @@ again:
20159 pgd = *pgd_p;
20160
20161 /*
20162- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
20163- * critical -- __PAGE_OFFSET would point us back into the dynamic
20164+ * The use of __early_va rather than __va here is critical:
20165+ * __va would point us back into the dynamic
20166 * range and we might end up looping forever...
20167 */
20168 if (pgd)
20169- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
20170+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
20171 else {
20172 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
20173 reset_early_page_tables();
20174@@ -82,13 +82,13 @@ again:
20175 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
20176 for (i = 0; i < PTRS_PER_PUD; i++)
20177 pud_p[i] = 0;
20178- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
20179+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
20180 }
20181 pud_p += pud_index(address);
20182 pud = *pud_p;
20183
20184 if (pud)
20185- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
20186+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
20187 else {
20188 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
20189 reset_early_page_tables();
20190@@ -98,7 +98,7 @@ again:
20191 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
20192 for (i = 0; i < PTRS_PER_PMD; i++)
20193 pmd_p[i] = 0;
20194- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
20195+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
20196 }
20197 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
20198 pmd_p[pmd_index(address)] = pmd;
20199@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
20200 if (console_loglevel == 10)
20201 early_printk("Kernel alive\n");
20202
20203- clear_page(init_level4_pgt);
20204 /* set init_level4_pgt kernel high mapping*/
20205 init_level4_pgt[511] = early_level4_pgt[511];
20206
20207diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
20208index 73afd11..d1670f5 100644
20209--- a/arch/x86/kernel/head_32.S
20210+++ b/arch/x86/kernel/head_32.S
20211@@ -26,6 +26,12 @@
20212 /* Physical address */
20213 #define pa(X) ((X) - __PAGE_OFFSET)
20214
20215+#ifdef CONFIG_PAX_KERNEXEC
20216+#define ta(X) (X)
20217+#else
20218+#define ta(X) ((X) - __PAGE_OFFSET)
20219+#endif
20220+
20221 /*
20222 * References to members of the new_cpu_data structure.
20223 */
20224@@ -55,11 +61,7 @@
20225 * and small than max_low_pfn, otherwise will waste some page table entries
20226 */
20227
20228-#if PTRS_PER_PMD > 1
20229-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
20230-#else
20231-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
20232-#endif
20233+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
20234
20235 /* Number of possible pages in the lowmem region */
20236 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
20237@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
20238 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20239
20240 /*
20241+ * Real beginning of normal "text" segment
20242+ */
20243+ENTRY(stext)
20244+ENTRY(_stext)
20245+
20246+/*
20247 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
20248 * %esi points to the real-mode code as a 32-bit pointer.
20249 * CS and DS must be 4 GB flat segments, but we don't depend on
20250@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20251 * can.
20252 */
20253 __HEAD
20254+
20255+#ifdef CONFIG_PAX_KERNEXEC
20256+ jmp startup_32
20257+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20258+.fill PAGE_SIZE-5,1,0xcc
20259+#endif
20260+
20261 ENTRY(startup_32)
20262 movl pa(stack_start),%ecx
20263
20264@@ -106,6 +121,59 @@ ENTRY(startup_32)
20265 2:
20266 leal -__PAGE_OFFSET(%ecx),%esp
20267
20268+#ifdef CONFIG_SMP
20269+ movl $pa(cpu_gdt_table),%edi
20270+ movl $__per_cpu_load,%eax
20271+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20272+ rorl $16,%eax
20273+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20274+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20275+ movl $__per_cpu_end - 1,%eax
20276+ subl $__per_cpu_start,%eax
20277+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20278+#endif
20279+
20280+#ifdef CONFIG_PAX_MEMORY_UDEREF
20281+ movl $NR_CPUS,%ecx
20282+ movl $pa(cpu_gdt_table),%edi
20283+1:
20284+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20285+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20286+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20287+ addl $PAGE_SIZE_asm,%edi
20288+ loop 1b
20289+#endif
20290+
20291+#ifdef CONFIG_PAX_KERNEXEC
20292+ movl $pa(boot_gdt),%edi
20293+ movl $__LOAD_PHYSICAL_ADDR,%eax
20294+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20295+ rorl $16,%eax
20296+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20297+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20298+ rorl $16,%eax
20299+
20300+ ljmp $(__BOOT_CS),$1f
20301+1:
20302+
20303+ movl $NR_CPUS,%ecx
20304+ movl $pa(cpu_gdt_table),%edi
20305+ addl $__PAGE_OFFSET,%eax
20306+1:
20307+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20308+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20309+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20310+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20311+ rorl $16,%eax
20312+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20313+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20314+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20315+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20316+ rorl $16,%eax
20317+ addl $PAGE_SIZE_asm,%edi
20318+ loop 1b
20319+#endif
20320+
20321 /*
20322 * Clear BSS first so that there are no surprises...
20323 */
20324@@ -201,8 +269,11 @@ ENTRY(startup_32)
20325 movl %eax, pa(max_pfn_mapped)
20326
20327 /* Do early initialization of the fixmap area */
20328- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20329- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20330+#ifdef CONFIG_COMPAT_VDSO
20331+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20332+#else
20333+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20334+#endif
20335 #else /* Not PAE */
20336
20337 page_pde_offset = (__PAGE_OFFSET >> 20);
20338@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20339 movl %eax, pa(max_pfn_mapped)
20340
20341 /* Do early initialization of the fixmap area */
20342- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20343- movl %eax,pa(initial_page_table+0xffc)
20344+#ifdef CONFIG_COMPAT_VDSO
20345+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20346+#else
20347+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20348+#endif
20349 #endif
20350
20351 #ifdef CONFIG_PARAVIRT
20352@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20353 cmpl $num_subarch_entries, %eax
20354 jae bad_subarch
20355
20356- movl pa(subarch_entries)(,%eax,4), %eax
20357- subl $__PAGE_OFFSET, %eax
20358- jmp *%eax
20359+ jmp *pa(subarch_entries)(,%eax,4)
20360
20361 bad_subarch:
20362 WEAK(lguest_entry)
20363@@ -261,10 +333,10 @@ WEAK(xen_entry)
20364 __INITDATA
20365
20366 subarch_entries:
20367- .long default_entry /* normal x86/PC */
20368- .long lguest_entry /* lguest hypervisor */
20369- .long xen_entry /* Xen hypervisor */
20370- .long default_entry /* Moorestown MID */
20371+ .long ta(default_entry) /* normal x86/PC */
20372+ .long ta(lguest_entry) /* lguest hypervisor */
20373+ .long ta(xen_entry) /* Xen hypervisor */
20374+ .long ta(default_entry) /* Moorestown MID */
20375 num_subarch_entries = (. - subarch_entries) / 4
20376 .previous
20377 #else
20378@@ -355,6 +427,7 @@ default_entry:
20379 movl pa(mmu_cr4_features),%eax
20380 movl %eax,%cr4
20381
20382+#ifdef CONFIG_X86_PAE
20383 testb $X86_CR4_PAE, %al # check if PAE is enabled
20384 jz enable_paging
20385
20386@@ -383,6 +456,9 @@ default_entry:
20387 /* Make changes effective */
20388 wrmsr
20389
20390+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20391+#endif
20392+
20393 enable_paging:
20394
20395 /*
20396@@ -451,14 +527,20 @@ is486:
20397 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20398 movl %eax,%ss # after changing gdt.
20399
20400- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20401+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20402 movl %eax,%ds
20403 movl %eax,%es
20404
20405 movl $(__KERNEL_PERCPU), %eax
20406 movl %eax,%fs # set this cpu's percpu
20407
20408+#ifdef CONFIG_CC_STACKPROTECTOR
20409 movl $(__KERNEL_STACK_CANARY),%eax
20410+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20411+ movl $(__USER_DS),%eax
20412+#else
20413+ xorl %eax,%eax
20414+#endif
20415 movl %eax,%gs
20416
20417 xorl %eax,%eax # Clear LDT
20418@@ -534,8 +616,11 @@ setup_once:
20419 * relocation. Manually set base address in stack canary
20420 * segment descriptor.
20421 */
20422- movl $gdt_page,%eax
20423+ movl $cpu_gdt_table,%eax
20424 movl $stack_canary,%ecx
20425+#ifdef CONFIG_SMP
20426+ addl $__per_cpu_load,%ecx
20427+#endif
20428 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20429 shrl $16, %ecx
20430 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20431@@ -566,7 +651,7 @@ ENDPROC(early_idt_handlers)
20432 /* This is global to keep gas from relaxing the jumps */
20433 ENTRY(early_idt_handler)
20434 cld
20435- cmpl $2,%ss:early_recursion_flag
20436+ cmpl $1,%ss:early_recursion_flag
20437 je hlt_loop
20438 incl %ss:early_recursion_flag
20439
20440@@ -604,8 +689,8 @@ ENTRY(early_idt_handler)
20441 pushl (20+6*4)(%esp) /* trapno */
20442 pushl $fault_msg
20443 call printk
20444-#endif
20445 call dump_stack
20446+#endif
20447 hlt_loop:
20448 hlt
20449 jmp hlt_loop
20450@@ -624,8 +709,11 @@ ENDPROC(early_idt_handler)
20451 /* This is the default interrupt "handler" :-) */
20452 ALIGN
20453 ignore_int:
20454- cld
20455 #ifdef CONFIG_PRINTK
20456+ cmpl $2,%ss:early_recursion_flag
20457+ je hlt_loop
20458+ incl %ss:early_recursion_flag
20459+ cld
20460 pushl %eax
20461 pushl %ecx
20462 pushl %edx
20463@@ -634,9 +722,6 @@ ignore_int:
20464 movl $(__KERNEL_DS),%eax
20465 movl %eax,%ds
20466 movl %eax,%es
20467- cmpl $2,early_recursion_flag
20468- je hlt_loop
20469- incl early_recursion_flag
20470 pushl 16(%esp)
20471 pushl 24(%esp)
20472 pushl 32(%esp)
20473@@ -670,29 +755,43 @@ ENTRY(setup_once_ref)
20474 /*
20475 * BSS section
20476 */
20477-__PAGE_ALIGNED_BSS
20478- .align PAGE_SIZE
20479 #ifdef CONFIG_X86_PAE
20480+.section .initial_pg_pmd,"a",@progbits
20481 initial_pg_pmd:
20482 .fill 1024*KPMDS,4,0
20483 #else
20484+.section .initial_page_table,"a",@progbits
20485 ENTRY(initial_page_table)
20486 .fill 1024,4,0
20487 #endif
20488+.section .initial_pg_fixmap,"a",@progbits
20489 initial_pg_fixmap:
20490 .fill 1024,4,0
20491+.section .empty_zero_page,"a",@progbits
20492 ENTRY(empty_zero_page)
20493 .fill 4096,1,0
20494+.section .swapper_pg_dir,"a",@progbits
20495 ENTRY(swapper_pg_dir)
20496+#ifdef CONFIG_X86_PAE
20497+ .fill 4,8,0
20498+#else
20499 .fill 1024,4,0
20500+#endif
20501+
20502+/*
20503+ * The IDT has to be page-aligned to simplify the Pentium
20504+ * F0 0F bug workaround.. We have a special link segment
20505+ * for this.
20506+ */
20507+.section .idt,"a",@progbits
20508+ENTRY(idt_table)
20509+ .fill 256,8,0
20510
20511 /*
20512 * This starts the data section.
20513 */
20514 #ifdef CONFIG_X86_PAE
20515-__PAGE_ALIGNED_DATA
20516- /* Page-aligned for the benefit of paravirt? */
20517- .align PAGE_SIZE
20518+.section .initial_page_table,"a",@progbits
20519 ENTRY(initial_page_table)
20520 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20521 # if KPMDS == 3
20522@@ -711,12 +810,20 @@ ENTRY(initial_page_table)
20523 # error "Kernel PMDs should be 1, 2 or 3"
20524 # endif
20525 .align PAGE_SIZE /* needs to be page-sized too */
20526+
20527+#ifdef CONFIG_PAX_PER_CPU_PGD
20528+ENTRY(cpu_pgd)
20529+ .rept NR_CPUS
20530+ .fill 4,8,0
20531+ .endr
20532+#endif
20533+
20534 #endif
20535
20536 .data
20537 .balign 4
20538 ENTRY(stack_start)
20539- .long init_thread_union+THREAD_SIZE
20540+ .long init_thread_union+THREAD_SIZE-8
20541
20542 __INITRODATA
20543 int_msg:
20544@@ -744,7 +851,7 @@ fault_msg:
20545 * segment size, and 32-bit linear address value:
20546 */
20547
20548- .data
20549+.section .rodata,"a",@progbits
20550 .globl boot_gdt_descr
20551 .globl idt_descr
20552
20553@@ -753,7 +860,7 @@ fault_msg:
20554 .word 0 # 32 bit align gdt_desc.address
20555 boot_gdt_descr:
20556 .word __BOOT_DS+7
20557- .long boot_gdt - __PAGE_OFFSET
20558+ .long pa(boot_gdt)
20559
20560 .word 0 # 32-bit align idt_desc.address
20561 idt_descr:
20562@@ -764,7 +871,7 @@ idt_descr:
20563 .word 0 # 32 bit align gdt_desc.address
20564 ENTRY(early_gdt_descr)
20565 .word GDT_ENTRIES*8-1
20566- .long gdt_page /* Overwritten for secondary CPUs */
20567+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20568
20569 /*
20570 * The boot_gdt must mirror the equivalent in setup.S and is
20571@@ -773,5 +880,65 @@ ENTRY(early_gdt_descr)
20572 .align L1_CACHE_BYTES
20573 ENTRY(boot_gdt)
20574 .fill GDT_ENTRY_BOOT_CS,8,0
20575- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20576- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20577+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20578+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20579+
20580+ .align PAGE_SIZE_asm
20581+ENTRY(cpu_gdt_table)
20582+ .rept NR_CPUS
20583+ .quad 0x0000000000000000 /* NULL descriptor */
20584+ .quad 0x0000000000000000 /* 0x0b reserved */
20585+ .quad 0x0000000000000000 /* 0x13 reserved */
20586+ .quad 0x0000000000000000 /* 0x1b reserved */
20587+
20588+#ifdef CONFIG_PAX_KERNEXEC
20589+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20590+#else
20591+ .quad 0x0000000000000000 /* 0x20 unused */
20592+#endif
20593+
20594+ .quad 0x0000000000000000 /* 0x28 unused */
20595+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20596+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20597+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20598+ .quad 0x0000000000000000 /* 0x4b reserved */
20599+ .quad 0x0000000000000000 /* 0x53 reserved */
20600+ .quad 0x0000000000000000 /* 0x5b reserved */
20601+
20602+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20603+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20604+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20605+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20606+
20607+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20608+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20609+
20610+ /*
20611+ * Segments used for calling PnP BIOS have byte granularity.
20612+ * The code segments and data segments have fixed 64k limits,
20613+ * the transfer segment sizes are set at run time.
20614+ */
20615+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20616+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20617+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20618+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20619+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20620+
20621+ /*
20622+ * The APM segments have byte granularity and their bases
20623+ * are set at run time. All have 64k limits.
20624+ */
20625+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20626+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20627+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20628+
20629+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20630+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20631+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20632+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20633+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20634+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20635+
20636+ /* Be sure this is zeroed to avoid false validations in Xen */
20637+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20638+ .endr
20639diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20640index 321d65e..ad8817d 100644
20641--- a/arch/x86/kernel/head_64.S
20642+++ b/arch/x86/kernel/head_64.S
20643@@ -20,6 +20,8 @@
20644 #include <asm/processor-flags.h>
20645 #include <asm/percpu.h>
20646 #include <asm/nops.h>
20647+#include <asm/cpufeature.h>
20648+#include <asm/alternative-asm.h>
20649
20650 #ifdef CONFIG_PARAVIRT
20651 #include <asm/asm-offsets.h>
20652@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20653 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20654 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20655 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20656+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20657+L3_VMALLOC_START = pud_index(VMALLOC_START)
20658+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20659+L3_VMALLOC_END = pud_index(VMALLOC_END)
20660+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20661+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20662
20663 .text
20664 __HEAD
20665@@ -89,11 +97,23 @@ startup_64:
20666 * Fixup the physical addresses in the page table
20667 */
20668 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
20669+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20670+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20671+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20672+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20673+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20674
20675- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20676- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20677+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
20678+#ifndef CONFIG_XEN
20679+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
20680+#endif
20681
20682- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20683+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20684+
20685+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20686+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
20687+
20688+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20689
20690 /*
20691 * Set up the identity mapping for the switchover. These
20692@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
20693 movq $(init_level4_pgt - __START_KERNEL_map), %rax
20694 1:
20695
20696- /* Enable PAE mode and PGE */
20697- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
20698+ /* Enable PAE mode and PSE/PGE */
20699+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
20700 movq %rcx, %cr4
20701
20702 /* Setup early boot stage 4 level pagetables. */
20703@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
20704 movl $MSR_EFER, %ecx
20705 rdmsr
20706 btsl $_EFER_SCE, %eax /* Enable System Call */
20707- btl $20,%edi /* No Execute supported? */
20708+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20709 jnc 1f
20710 btsl $_EFER_NX, %eax
20711 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
20712+ leaq init_level4_pgt(%rip), %rdi
20713+#ifndef CONFIG_EFI
20714+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20715+#endif
20716+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20717+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20718+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20719+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20720 1: wrmsr /* Make changes effective */
20721
20722 /* Setup cr0 */
20723@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
20724 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
20725 * address given in m16:64.
20726 */
20727+ pax_set_fptr_mask
20728 movq initial_code(%rip),%rax
20729 pushq $0 # fake return address to stop unwinder
20730 pushq $__KERNEL_CS # set correct cs
20731@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
20732 call dump_stack
20733 #ifdef CONFIG_KALLSYMS
20734 leaq early_idt_ripmsg(%rip),%rdi
20735- movq 40(%rsp),%rsi # %rip again
20736+ movq 88(%rsp),%rsi # %rip again
20737 call __print_symbol
20738 #endif
20739 #endif /* EARLY_PRINTK */
20740@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
20741 early_recursion_flag:
20742 .long 0
20743
20744+ .section .rodata,"a",@progbits
20745 #ifdef CONFIG_EARLY_PRINTK
20746 early_idt_msg:
20747 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20748@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
20749 NEXT_PAGE(early_dynamic_pgts)
20750 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
20751
20752- .data
20753+ .section .rodata,"a",@progbits
20754
20755-#ifndef CONFIG_XEN
20756 NEXT_PAGE(init_level4_pgt)
20757- .fill 512,8,0
20758-#else
20759-NEXT_PAGE(init_level4_pgt)
20760- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20761 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20762 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20763+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20764+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20765+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20766+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20767+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20768+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20769 .org init_level4_pgt + L4_START_KERNEL*8, 0
20770 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20771 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20772
20773+#ifdef CONFIG_PAX_PER_CPU_PGD
20774+NEXT_PAGE(cpu_pgd)
20775+ .rept NR_CPUS
20776+ .fill 512,8,0
20777+ .endr
20778+#endif
20779+
20780 NEXT_PAGE(level3_ident_pgt)
20781 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20782+#ifdef CONFIG_XEN
20783 .fill 511, 8, 0
20784+#else
20785+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20786+ .fill 510,8,0
20787+#endif
20788+
20789+NEXT_PAGE(level3_vmalloc_start_pgt)
20790+ .fill 512,8,0
20791+
20792+NEXT_PAGE(level3_vmalloc_end_pgt)
20793+ .fill 512,8,0
20794+
20795+NEXT_PAGE(level3_vmemmap_pgt)
20796+ .fill L3_VMEMMAP_START,8,0
20797+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20798+
20799 NEXT_PAGE(level2_ident_pgt)
20800- /* Since I easily can, map the first 1G.
20801+ /* Since I easily can, map the first 2G.
20802 * Don't set NX because code runs from these pages.
20803 */
20804- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20805-#endif
20806+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20807
20808 NEXT_PAGE(level3_kernel_pgt)
20809 .fill L3_START_KERNEL,8,0
20810@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
20811 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20812 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20813
20814+NEXT_PAGE(level2_vmemmap_pgt)
20815+ .fill 512,8,0
20816+
20817 NEXT_PAGE(level2_kernel_pgt)
20818 /*
20819 * 512 MB kernel mapping. We spend a full page on this pagetable
20820@@ -488,39 +544,64 @@ NEXT_PAGE(level2_kernel_pgt)
20821 KERNEL_IMAGE_SIZE/PMD_SIZE)
20822
20823 NEXT_PAGE(level2_fixmap_pgt)
20824- .fill 506,8,0
20825- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20826- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20827- .fill 5,8,0
20828+ .fill 507,8,0
20829+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20830+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20831+ .fill 4,8,0
20832
20833-NEXT_PAGE(level1_fixmap_pgt)
20834+NEXT_PAGE(level1_vsyscall_pgt)
20835 .fill 512,8,0
20836
20837 #undef PMDS
20838
20839- .data
20840+ .align PAGE_SIZE
20841+ENTRY(cpu_gdt_table)
20842+ .rept NR_CPUS
20843+ .quad 0x0000000000000000 /* NULL descriptor */
20844+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20845+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20846+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20847+ .quad 0x00cffb000000ffff /* __USER32_CS */
20848+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20849+ .quad 0x00affb000000ffff /* __USER_CS */
20850+
20851+#ifdef CONFIG_PAX_KERNEXEC
20852+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20853+#else
20854+ .quad 0x0 /* unused */
20855+#endif
20856+
20857+ .quad 0,0 /* TSS */
20858+ .quad 0,0 /* LDT */
20859+ .quad 0,0,0 /* three TLS descriptors */
20860+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20861+ /* asm/segment.h:GDT_ENTRIES must match this */
20862+
20863+ /* zero the remaining page */
20864+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20865+ .endr
20866+
20867 .align 16
20868 .globl early_gdt_descr
20869 early_gdt_descr:
20870 .word GDT_ENTRIES*8-1
20871 early_gdt_descr_base:
20872- .quad INIT_PER_CPU_VAR(gdt_page)
20873+ .quad cpu_gdt_table
20874
20875 ENTRY(phys_base)
20876 /* This must match the first entry in level2_kernel_pgt */
20877 .quad 0x0000000000000000
20878
20879 #include "../../x86/xen/xen-head.S"
20880-
20881- .section .bss, "aw", @nobits
20882+
20883+ .section .rodata,"a",@progbits
20884 .align L1_CACHE_BYTES
20885 ENTRY(idt_table)
20886- .skip IDT_ENTRIES * 16
20887+ .fill 512,8,0
20888
20889 .align L1_CACHE_BYTES
20890 ENTRY(nmi_idt_table)
20891- .skip IDT_ENTRIES * 16
20892+ .fill 512,8,0
20893
20894- __PAGE_ALIGNED_BSS
20895 NEXT_PAGE(empty_zero_page)
20896 .skip PAGE_SIZE
20897diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20898index 0fa6912..37fce70 100644
20899--- a/arch/x86/kernel/i386_ksyms_32.c
20900+++ b/arch/x86/kernel/i386_ksyms_32.c
20901@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20902 EXPORT_SYMBOL(cmpxchg8b_emu);
20903 #endif
20904
20905+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20906+
20907 /* Networking helper routines. */
20908 EXPORT_SYMBOL(csum_partial_copy_generic);
20909+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20910+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20911
20912 EXPORT_SYMBOL(__get_user_1);
20913 EXPORT_SYMBOL(__get_user_2);
20914@@ -37,3 +41,7 @@ EXPORT_SYMBOL(strstr);
20915
20916 EXPORT_SYMBOL(csum_partial);
20917 EXPORT_SYMBOL(empty_zero_page);
20918+
20919+#ifdef CONFIG_PAX_KERNEXEC
20920+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20921+#endif
20922diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20923index cb33909..1163b40 100644
20924--- a/arch/x86/kernel/i387.c
20925+++ b/arch/x86/kernel/i387.c
20926@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20927 static inline bool interrupted_user_mode(void)
20928 {
20929 struct pt_regs *regs = get_irq_regs();
20930- return regs && user_mode_vm(regs);
20931+ return regs && user_mode(regs);
20932 }
20933
20934 /*
20935diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20936index 9a5c460..84868423 100644
20937--- a/arch/x86/kernel/i8259.c
20938+++ b/arch/x86/kernel/i8259.c
20939@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
20940 static void make_8259A_irq(unsigned int irq)
20941 {
20942 disable_irq_nosync(irq);
20943- io_apic_irqs &= ~(1<<irq);
20944+ io_apic_irqs &= ~(1UL<<irq);
20945 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
20946 i8259A_chip.name);
20947 enable_irq(irq);
20948@@ -209,7 +209,7 @@ spurious_8259A_irq:
20949 "spurious 8259A interrupt: IRQ%d.\n", irq);
20950 spurious_irq_mask |= irqmask;
20951 }
20952- atomic_inc(&irq_err_count);
20953+ atomic_inc_unchecked(&irq_err_count);
20954 /*
20955 * Theoretically we do not have to handle this IRQ,
20956 * but in Linux this does not cause problems and is
20957@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20958 /* (slave's support for AEOI in flat mode is to be investigated) */
20959 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20960
20961+ pax_open_kernel();
20962 if (auto_eoi)
20963 /*
20964 * In AEOI mode we just have to mask the interrupt
20965 * when acking.
20966 */
20967- i8259A_chip.irq_mask_ack = disable_8259A_irq;
20968+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20969 else
20970- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20971+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20972+ pax_close_kernel();
20973
20974 udelay(100); /* wait for 8259A to initialize */
20975
20976diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20977index a979b5b..1d6db75 100644
20978--- a/arch/x86/kernel/io_delay.c
20979+++ b/arch/x86/kernel/io_delay.c
20980@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20981 * Quirk table for systems that misbehave (lock up, etc.) if port
20982 * 0x80 is used:
20983 */
20984-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20985+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20986 {
20987 .callback = dmi_io_delay_0xed_port,
20988 .ident = "Compaq Presario V6000",
20989diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20990index 4ddaf66..6292f4e 100644
20991--- a/arch/x86/kernel/ioport.c
20992+++ b/arch/x86/kernel/ioport.c
20993@@ -6,6 +6,7 @@
20994 #include <linux/sched.h>
20995 #include <linux/kernel.h>
20996 #include <linux/capability.h>
20997+#include <linux/security.h>
20998 #include <linux/errno.h>
20999 #include <linux/types.h>
21000 #include <linux/ioport.h>
21001@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
21002
21003 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
21004 return -EINVAL;
21005+#ifdef CONFIG_GRKERNSEC_IO
21006+ if (turn_on && grsec_disable_privio) {
21007+ gr_handle_ioperm();
21008+ return -EPERM;
21009+ }
21010+#endif
21011 if (turn_on && !capable(CAP_SYS_RAWIO))
21012 return -EPERM;
21013
21014@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
21015 * because the ->io_bitmap_max value must match the bitmap
21016 * contents:
21017 */
21018- tss = &per_cpu(init_tss, get_cpu());
21019+ tss = init_tss + get_cpu();
21020
21021 if (turn_on)
21022 bitmap_clear(t->io_bitmap_ptr, from, num);
21023@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
21024 return -EINVAL;
21025 /* Trying to gain more privileges? */
21026 if (level > old) {
21027+#ifdef CONFIG_GRKERNSEC_IO
21028+ if (grsec_disable_privio) {
21029+ gr_handle_iopl();
21030+ return -EPERM;
21031+ }
21032+#endif
21033 if (!capable(CAP_SYS_RAWIO))
21034 return -EPERM;
21035 }
21036diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
21037index 84b7789..e65e8be 100644
21038--- a/arch/x86/kernel/irq.c
21039+++ b/arch/x86/kernel/irq.c
21040@@ -18,7 +18,7 @@
21041 #include <asm/mce.h>
21042 #include <asm/hw_irq.h>
21043
21044-atomic_t irq_err_count;
21045+atomic_unchecked_t irq_err_count;
21046
21047 /* Function pointer for generic interrupt vector handling */
21048 void (*x86_platform_ipi_callback)(void) = NULL;
21049@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
21050 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
21051 seq_printf(p, " Machine check polls\n");
21052 #endif
21053- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
21054+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
21055 #if defined(CONFIG_X86_IO_APIC)
21056- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
21057+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
21058 #endif
21059 return 0;
21060 }
21061@@ -164,7 +164,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
21062
21063 u64 arch_irq_stat(void)
21064 {
21065- u64 sum = atomic_read(&irq_err_count);
21066+ u64 sum = atomic_read_unchecked(&irq_err_count);
21067 return sum;
21068 }
21069
21070diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
21071index 344faf8..355f60d 100644
21072--- a/arch/x86/kernel/irq_32.c
21073+++ b/arch/x86/kernel/irq_32.c
21074@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
21075 __asm__ __volatile__("andl %%esp,%0" :
21076 "=r" (sp) : "0" (THREAD_SIZE - 1));
21077
21078- return sp < (sizeof(struct thread_info) + STACK_WARN);
21079+ return sp < STACK_WARN;
21080 }
21081
21082 static void print_stack_overflow(void)
21083@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
21084 * per-CPU IRQ handling contexts (thread information and stack)
21085 */
21086 union irq_ctx {
21087- struct thread_info tinfo;
21088- u32 stack[THREAD_SIZE/sizeof(u32)];
21089+ unsigned long previous_esp;
21090+ u32 stack[THREAD_SIZE/sizeof(u32)];
21091 } __attribute__((aligned(THREAD_SIZE)));
21092
21093 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
21094@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
21095 static inline int
21096 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21097 {
21098- union irq_ctx *curctx, *irqctx;
21099+ union irq_ctx *irqctx;
21100 u32 *isp, arg1, arg2;
21101
21102- curctx = (union irq_ctx *) current_thread_info();
21103 irqctx = __this_cpu_read(hardirq_ctx);
21104
21105 /*
21106@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21107 * handler) we can't do that and just have to keep using the
21108 * current stack (which is the irq stack already after all)
21109 */
21110- if (unlikely(curctx == irqctx))
21111+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
21112 return 0;
21113
21114 /* build the stack frame on the IRQ stack */
21115- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21116- irqctx->tinfo.task = curctx->tinfo.task;
21117- irqctx->tinfo.previous_esp = current_stack_pointer;
21118+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21119+ irqctx->previous_esp = current_stack_pointer;
21120
21121- /* Copy the preempt_count so that the [soft]irq checks work. */
21122- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
21123+#ifdef CONFIG_PAX_MEMORY_UDEREF
21124+ __set_fs(MAKE_MM_SEG(0));
21125+#endif
21126
21127 if (unlikely(overflow))
21128 call_on_stack(print_stack_overflow, isp);
21129@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21130 : "0" (irq), "1" (desc), "2" (isp),
21131 "D" (desc->handle_irq)
21132 : "memory", "cc", "ecx");
21133+
21134+#ifdef CONFIG_PAX_MEMORY_UDEREF
21135+ __set_fs(current_thread_info()->addr_limit);
21136+#endif
21137+
21138 return 1;
21139 }
21140
21141@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21142 */
21143 void __cpuinit irq_ctx_init(int cpu)
21144 {
21145- union irq_ctx *irqctx;
21146-
21147 if (per_cpu(hardirq_ctx, cpu))
21148 return;
21149
21150- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21151- THREADINFO_GFP,
21152- THREAD_SIZE_ORDER));
21153- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21154- irqctx->tinfo.cpu = cpu;
21155- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
21156- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21157-
21158- per_cpu(hardirq_ctx, cpu) = irqctx;
21159-
21160- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21161- THREADINFO_GFP,
21162- THREAD_SIZE_ORDER));
21163- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21164- irqctx->tinfo.cpu = cpu;
21165- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21166-
21167- per_cpu(softirq_ctx, cpu) = irqctx;
21168+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21169+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21170+
21171+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21172+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21173
21174 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21175 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21176@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
21177 asmlinkage void do_softirq(void)
21178 {
21179 unsigned long flags;
21180- struct thread_info *curctx;
21181 union irq_ctx *irqctx;
21182 u32 *isp;
21183
21184@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
21185 local_irq_save(flags);
21186
21187 if (local_softirq_pending()) {
21188- curctx = current_thread_info();
21189 irqctx = __this_cpu_read(softirq_ctx);
21190- irqctx->tinfo.task = curctx->task;
21191- irqctx->tinfo.previous_esp = current_stack_pointer;
21192+ irqctx->previous_esp = current_stack_pointer;
21193
21194 /* build the stack frame on the softirq stack */
21195- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21196+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21197+
21198+#ifdef CONFIG_PAX_MEMORY_UDEREF
21199+ __set_fs(MAKE_MM_SEG(0));
21200+#endif
21201
21202 call_on_stack(__do_softirq, isp);
21203+
21204+#ifdef CONFIG_PAX_MEMORY_UDEREF
21205+ __set_fs(current_thread_info()->addr_limit);
21206+#endif
21207+
21208 /*
21209 * Shouldn't happen, we returned above if in_interrupt():
21210 */
21211@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21212 if (unlikely(!desc))
21213 return false;
21214
21215- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21216+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21217 if (unlikely(overflow))
21218 print_stack_overflow();
21219 desc->handle_irq(irq, desc);
21220diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21221index d04d3ec..ea4b374 100644
21222--- a/arch/x86/kernel/irq_64.c
21223+++ b/arch/x86/kernel/irq_64.c
21224@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21225 u64 estack_top, estack_bottom;
21226 u64 curbase = (u64)task_stack_page(current);
21227
21228- if (user_mode_vm(regs))
21229+ if (user_mode(regs))
21230 return;
21231
21232 if (regs->sp >= curbase + sizeof(struct thread_info) +
21233diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21234index dc1404b..bbc43e7 100644
21235--- a/arch/x86/kernel/kdebugfs.c
21236+++ b/arch/x86/kernel/kdebugfs.c
21237@@ -27,7 +27,7 @@ struct setup_data_node {
21238 u32 len;
21239 };
21240
21241-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21242+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21243 size_t count, loff_t *ppos)
21244 {
21245 struct setup_data_node *node = file->private_data;
21246diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21247index 836f832..a8bda67 100644
21248--- a/arch/x86/kernel/kgdb.c
21249+++ b/arch/x86/kernel/kgdb.c
21250@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21251 #ifdef CONFIG_X86_32
21252 switch (regno) {
21253 case GDB_SS:
21254- if (!user_mode_vm(regs))
21255+ if (!user_mode(regs))
21256 *(unsigned long *)mem = __KERNEL_DS;
21257 break;
21258 case GDB_SP:
21259- if (!user_mode_vm(regs))
21260+ if (!user_mode(regs))
21261 *(unsigned long *)mem = kernel_stack_pointer(regs);
21262 break;
21263 case GDB_GS:
21264@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21265 bp->attr.bp_addr = breakinfo[breakno].addr;
21266 bp->attr.bp_len = breakinfo[breakno].len;
21267 bp->attr.bp_type = breakinfo[breakno].type;
21268- info->address = breakinfo[breakno].addr;
21269+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21270+ info->address = ktla_ktva(breakinfo[breakno].addr);
21271+ else
21272+ info->address = breakinfo[breakno].addr;
21273 info->len = breakinfo[breakno].len;
21274 info->type = breakinfo[breakno].type;
21275 val = arch_install_hw_breakpoint(bp);
21276@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21277 case 'k':
21278 /* clear the trace bit */
21279 linux_regs->flags &= ~X86_EFLAGS_TF;
21280- atomic_set(&kgdb_cpu_doing_single_step, -1);
21281+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21282
21283 /* set the trace bit if we're stepping */
21284 if (remcomInBuffer[0] == 's') {
21285 linux_regs->flags |= X86_EFLAGS_TF;
21286- atomic_set(&kgdb_cpu_doing_single_step,
21287+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21288 raw_smp_processor_id());
21289 }
21290
21291@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21292
21293 switch (cmd) {
21294 case DIE_DEBUG:
21295- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21296+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21297 if (user_mode(regs))
21298 return single_step_cont(regs, args);
21299 break;
21300@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21301 #endif /* CONFIG_DEBUG_RODATA */
21302
21303 bpt->type = BP_BREAKPOINT;
21304- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21305+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21306 BREAK_INSTR_SIZE);
21307 if (err)
21308 return err;
21309- err = probe_kernel_write((char *)bpt->bpt_addr,
21310+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21311 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21312 #ifdef CONFIG_DEBUG_RODATA
21313 if (!err)
21314@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21315 return -EBUSY;
21316 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21317 BREAK_INSTR_SIZE);
21318- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21319+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21320 if (err)
21321 return err;
21322 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21323@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21324 if (mutex_is_locked(&text_mutex))
21325 goto knl_write;
21326 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21327- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21328+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21329 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21330 goto knl_write;
21331 return err;
21332 knl_write:
21333 #endif /* CONFIG_DEBUG_RODATA */
21334- return probe_kernel_write((char *)bpt->bpt_addr,
21335+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21336 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21337 }
21338
21339diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
21340index 7bfe318..383d238 100644
21341--- a/arch/x86/kernel/kprobes/core.c
21342+++ b/arch/x86/kernel/kprobes/core.c
21343@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21344 s32 raddr;
21345 } __packed *insn;
21346
21347- insn = (struct __arch_relative_insn *)from;
21348+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21349+
21350+ pax_open_kernel();
21351 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21352 insn->op = op;
21353+ pax_close_kernel();
21354 }
21355
21356 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21357@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21358 kprobe_opcode_t opcode;
21359 kprobe_opcode_t *orig_opcodes = opcodes;
21360
21361- if (search_exception_tables((unsigned long)opcodes))
21362+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21363 return 0; /* Page fault may occur on this address. */
21364
21365 retry:
21366@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21367 * for the first byte, we can recover the original instruction
21368 * from it and kp->opcode.
21369 */
21370- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21371+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21372 buf[0] = kp->opcode;
21373- return (unsigned long)buf;
21374+ return ktva_ktla((unsigned long)buf);
21375 }
21376
21377 /*
21378@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21379 /* Another subsystem puts a breakpoint, failed to recover */
21380 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21381 return 0;
21382+ pax_open_kernel();
21383 memcpy(dest, insn.kaddr, insn.length);
21384+ pax_close_kernel();
21385
21386 #ifdef CONFIG_X86_64
21387 if (insn_rip_relative(&insn)) {
21388@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21389 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
21390 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
21391 disp = (u8 *) dest + insn_offset_displacement(&insn);
21392+ pax_open_kernel();
21393 *(s32 *) disp = (s32) newdisp;
21394+ pax_close_kernel();
21395 }
21396 #endif
21397 return insn.length;
21398@@ -488,7 +495,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21399 * nor set current_kprobe, because it doesn't use single
21400 * stepping.
21401 */
21402- regs->ip = (unsigned long)p->ainsn.insn;
21403+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21404 preempt_enable_no_resched();
21405 return;
21406 }
21407@@ -505,9 +512,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21408 regs->flags &= ~X86_EFLAGS_IF;
21409 /* single step inline if the instruction is an int3 */
21410 if (p->opcode == BREAKPOINT_INSTRUCTION)
21411- regs->ip = (unsigned long)p->addr;
21412+ regs->ip = ktla_ktva((unsigned long)p->addr);
21413 else
21414- regs->ip = (unsigned long)p->ainsn.insn;
21415+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21416 }
21417
21418 /*
21419@@ -586,7 +593,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21420 setup_singlestep(p, regs, kcb, 0);
21421 return 1;
21422 }
21423- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21424+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21425 /*
21426 * The breakpoint instruction was removed right
21427 * after we hit it. Another cpu has removed
21428@@ -632,6 +639,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21429 " movq %rax, 152(%rsp)\n"
21430 RESTORE_REGS_STRING
21431 " popfq\n"
21432+#ifdef KERNEXEC_PLUGIN
21433+ " btsq $63,(%rsp)\n"
21434+#endif
21435 #else
21436 " pushf\n"
21437 SAVE_REGS_STRING
21438@@ -769,7 +779,7 @@ static void __kprobes
21439 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21440 {
21441 unsigned long *tos = stack_addr(regs);
21442- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21443+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21444 unsigned long orig_ip = (unsigned long)p->addr;
21445 kprobe_opcode_t *insn = p->ainsn.insn;
21446
21447@@ -951,7 +961,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21448 struct die_args *args = data;
21449 int ret = NOTIFY_DONE;
21450
21451- if (args->regs && user_mode_vm(args->regs))
21452+ if (args->regs && user_mode(args->regs))
21453 return ret;
21454
21455 switch (val) {
21456diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
21457index 76dc6f0..66bdfc3 100644
21458--- a/arch/x86/kernel/kprobes/opt.c
21459+++ b/arch/x86/kernel/kprobes/opt.c
21460@@ -79,6 +79,7 @@ found:
21461 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
21462 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
21463 {
21464+ pax_open_kernel();
21465 #ifdef CONFIG_X86_64
21466 *addr++ = 0x48;
21467 *addr++ = 0xbf;
21468@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
21469 *addr++ = 0xb8;
21470 #endif
21471 *(unsigned long *)addr = val;
21472+ pax_close_kernel();
21473 }
21474
21475 static void __used __kprobes kprobes_optinsn_template_holder(void)
21476@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21477 * Verify if the address gap is in 2GB range, because this uses
21478 * a relative jump.
21479 */
21480- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21481+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21482 if (abs(rel) > 0x7fffffff)
21483 return -ERANGE;
21484
21485@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21486 op->optinsn.size = ret;
21487
21488 /* Copy arch-dep-instance from template */
21489- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21490+ pax_open_kernel();
21491+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21492+ pax_close_kernel();
21493
21494 /* Set probe information */
21495 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21496
21497 /* Set probe function call */
21498- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21499+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21500
21501 /* Set returning jmp instruction at the tail of out-of-line buffer */
21502- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21503+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21504 (u8 *)op->kp.addr + op->optinsn.size);
21505
21506 flush_icache_range((unsigned long) buf,
21507@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21508 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21509
21510 /* Backup instructions which will be replaced by jump address */
21511- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21512+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21513 RELATIVE_ADDR_SIZE);
21514
21515 insn_buf[0] = RELATIVEJUMP_OPCODE;
21516@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21517 /* This kprobe is really able to run optimized path. */
21518 op = container_of(p, struct optimized_kprobe, kp);
21519 /* Detour through copied instructions */
21520- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21521+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21522 if (!reenter)
21523 reset_current_kprobe();
21524 preempt_enable_no_resched();
21525diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21526index b686a90..60d36fb 100644
21527--- a/arch/x86/kernel/kvm.c
21528+++ b/arch/x86/kernel/kvm.c
21529@@ -453,7 +453,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21530 return NOTIFY_OK;
21531 }
21532
21533-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21534+static struct notifier_block kvm_cpu_notifier = {
21535 .notifier_call = kvm_cpu_notify,
21536 };
21537 #endif
21538diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21539index ebc9873..1b9724b 100644
21540--- a/arch/x86/kernel/ldt.c
21541+++ b/arch/x86/kernel/ldt.c
21542@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21543 if (reload) {
21544 #ifdef CONFIG_SMP
21545 preempt_disable();
21546- load_LDT(pc);
21547+ load_LDT_nolock(pc);
21548 if (!cpumask_equal(mm_cpumask(current->mm),
21549 cpumask_of(smp_processor_id())))
21550 smp_call_function(flush_ldt, current->mm, 1);
21551 preempt_enable();
21552 #else
21553- load_LDT(pc);
21554+ load_LDT_nolock(pc);
21555 #endif
21556 }
21557 if (oldsize) {
21558@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21559 return err;
21560
21561 for (i = 0; i < old->size; i++)
21562- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21563+ write_ldt_entry(new->ldt, i, old->ldt + i);
21564 return 0;
21565 }
21566
21567@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21568 retval = copy_ldt(&mm->context, &old_mm->context);
21569 mutex_unlock(&old_mm->context.lock);
21570 }
21571+
21572+ if (tsk == current) {
21573+ mm->context.vdso = 0;
21574+
21575+#ifdef CONFIG_X86_32
21576+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21577+ mm->context.user_cs_base = 0UL;
21578+ mm->context.user_cs_limit = ~0UL;
21579+
21580+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21581+ cpus_clear(mm->context.cpu_user_cs_mask);
21582+#endif
21583+
21584+#endif
21585+#endif
21586+
21587+ }
21588+
21589 return retval;
21590 }
21591
21592@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21593 }
21594 }
21595
21596+#ifdef CONFIG_PAX_SEGMEXEC
21597+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21598+ error = -EINVAL;
21599+ goto out_unlock;
21600+ }
21601+#endif
21602+
21603 fill_ldt(&ldt, &ldt_info);
21604 if (oldmode)
21605 ldt.avl = 0;
21606diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21607index 5b19e4d..6476a76 100644
21608--- a/arch/x86/kernel/machine_kexec_32.c
21609+++ b/arch/x86/kernel/machine_kexec_32.c
21610@@ -26,7 +26,7 @@
21611 #include <asm/cacheflush.h>
21612 #include <asm/debugreg.h>
21613
21614-static void set_idt(void *newidt, __u16 limit)
21615+static void set_idt(struct desc_struct *newidt, __u16 limit)
21616 {
21617 struct desc_ptr curidt;
21618
21619@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21620 }
21621
21622
21623-static void set_gdt(void *newgdt, __u16 limit)
21624+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21625 {
21626 struct desc_ptr curgdt;
21627
21628@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21629 }
21630
21631 control_page = page_address(image->control_code_page);
21632- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21633+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21634
21635 relocate_kernel_ptr = control_page;
21636 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21637diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21638index 22db92b..d546bec 100644
21639--- a/arch/x86/kernel/microcode_core.c
21640+++ b/arch/x86/kernel/microcode_core.c
21641@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21642 return NOTIFY_OK;
21643 }
21644
21645-static struct notifier_block __refdata mc_cpu_notifier = {
21646+static struct notifier_block mc_cpu_notifier = {
21647 .notifier_call = mc_cpu_callback,
21648 };
21649
21650diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21651index 5fb2ceb..3ae90bb 100644
21652--- a/arch/x86/kernel/microcode_intel.c
21653+++ b/arch/x86/kernel/microcode_intel.c
21654@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21655
21656 static int get_ucode_user(void *to, const void *from, size_t n)
21657 {
21658- return copy_from_user(to, from, n);
21659+ return copy_from_user(to, (const void __force_user *)from, n);
21660 }
21661
21662 static enum ucode_state
21663 request_microcode_user(int cpu, const void __user *buf, size_t size)
21664 {
21665- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21666+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21667 }
21668
21669 static void microcode_fini_cpu(int cpu)
21670diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21671index 216a4d7..228255a 100644
21672--- a/arch/x86/kernel/module.c
21673+++ b/arch/x86/kernel/module.c
21674@@ -43,15 +43,60 @@ do { \
21675 } while (0)
21676 #endif
21677
21678-void *module_alloc(unsigned long size)
21679+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21680 {
21681- if (PAGE_ALIGN(size) > MODULES_LEN)
21682+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21683 return NULL;
21684 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21685- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21686+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21687 -1, __builtin_return_address(0));
21688 }
21689
21690+void *module_alloc(unsigned long size)
21691+{
21692+
21693+#ifdef CONFIG_PAX_KERNEXEC
21694+ return __module_alloc(size, PAGE_KERNEL);
21695+#else
21696+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21697+#endif
21698+
21699+}
21700+
21701+#ifdef CONFIG_PAX_KERNEXEC
21702+#ifdef CONFIG_X86_32
21703+void *module_alloc_exec(unsigned long size)
21704+{
21705+ struct vm_struct *area;
21706+
21707+ if (size == 0)
21708+ return NULL;
21709+
21710+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21711+ return area ? area->addr : NULL;
21712+}
21713+EXPORT_SYMBOL(module_alloc_exec);
21714+
21715+void module_free_exec(struct module *mod, void *module_region)
21716+{
21717+ vunmap(module_region);
21718+}
21719+EXPORT_SYMBOL(module_free_exec);
21720+#else
21721+void module_free_exec(struct module *mod, void *module_region)
21722+{
21723+ module_free(mod, module_region);
21724+}
21725+EXPORT_SYMBOL(module_free_exec);
21726+
21727+void *module_alloc_exec(unsigned long size)
21728+{
21729+ return __module_alloc(size, PAGE_KERNEL_RX);
21730+}
21731+EXPORT_SYMBOL(module_alloc_exec);
21732+#endif
21733+#endif
21734+
21735 #ifdef CONFIG_X86_32
21736 int apply_relocate(Elf32_Shdr *sechdrs,
21737 const char *strtab,
21738@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21739 unsigned int i;
21740 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21741 Elf32_Sym *sym;
21742- uint32_t *location;
21743+ uint32_t *plocation, location;
21744
21745 DEBUGP("Applying relocate section %u to %u\n",
21746 relsec, sechdrs[relsec].sh_info);
21747 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21748 /* This is where to make the change */
21749- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21750- + rel[i].r_offset;
21751+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21752+ location = (uint32_t)plocation;
21753+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21754+ plocation = ktla_ktva((void *)plocation);
21755 /* This is the symbol it is referring to. Note that all
21756 undefined symbols have been resolved. */
21757 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21758@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21759 switch (ELF32_R_TYPE(rel[i].r_info)) {
21760 case R_386_32:
21761 /* We add the value into the location given */
21762- *location += sym->st_value;
21763+ pax_open_kernel();
21764+ *plocation += sym->st_value;
21765+ pax_close_kernel();
21766 break;
21767 case R_386_PC32:
21768 /* Add the value, subtract its position */
21769- *location += sym->st_value - (uint32_t)location;
21770+ pax_open_kernel();
21771+ *plocation += sym->st_value - location;
21772+ pax_close_kernel();
21773 break;
21774 default:
21775 pr_err("%s: Unknown relocation: %u\n",
21776@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21777 case R_X86_64_NONE:
21778 break;
21779 case R_X86_64_64:
21780+ pax_open_kernel();
21781 *(u64 *)loc = val;
21782+ pax_close_kernel();
21783 break;
21784 case R_X86_64_32:
21785+ pax_open_kernel();
21786 *(u32 *)loc = val;
21787+ pax_close_kernel();
21788 if (val != *(u32 *)loc)
21789 goto overflow;
21790 break;
21791 case R_X86_64_32S:
21792+ pax_open_kernel();
21793 *(s32 *)loc = val;
21794+ pax_close_kernel();
21795 if ((s64)val != *(s32 *)loc)
21796 goto overflow;
21797 break;
21798 case R_X86_64_PC32:
21799 val -= (u64)loc;
21800+ pax_open_kernel();
21801 *(u32 *)loc = val;
21802+ pax_close_kernel();
21803+
21804 #if 0
21805 if ((s64)val != *(s32 *)loc)
21806 goto overflow;
21807diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21808index ce13049..e2e9c3c 100644
21809--- a/arch/x86/kernel/msr.c
21810+++ b/arch/x86/kernel/msr.c
21811@@ -233,7 +233,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21812 return notifier_from_errno(err);
21813 }
21814
21815-static struct notifier_block __refdata msr_class_cpu_notifier = {
21816+static struct notifier_block msr_class_cpu_notifier = {
21817 .notifier_call = msr_class_cpu_callback,
21818 };
21819
21820diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21821index 6030805..2d33f21 100644
21822--- a/arch/x86/kernel/nmi.c
21823+++ b/arch/x86/kernel/nmi.c
21824@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21825 return handled;
21826 }
21827
21828-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21829+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21830 {
21831 struct nmi_desc *desc = nmi_to_desc(type);
21832 unsigned long flags;
21833@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21834 * event confuses some handlers (kdump uses this flag)
21835 */
21836 if (action->flags & NMI_FLAG_FIRST)
21837- list_add_rcu(&action->list, &desc->head);
21838+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21839 else
21840- list_add_tail_rcu(&action->list, &desc->head);
21841+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21842
21843 spin_unlock_irqrestore(&desc->lock, flags);
21844 return 0;
21845@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21846 if (!strcmp(n->name, name)) {
21847 WARN(in_nmi(),
21848 "Trying to free NMI (%s) from NMI context!\n", n->name);
21849- list_del_rcu(&n->list);
21850+ pax_list_del_rcu((struct list_head *)&n->list);
21851 break;
21852 }
21853 }
21854@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21855 dotraplinkage notrace __kprobes void
21856 do_nmi(struct pt_regs *regs, long error_code)
21857 {
21858+
21859+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21860+ if (!user_mode(regs)) {
21861+ unsigned long cs = regs->cs & 0xFFFF;
21862+ unsigned long ip = ktva_ktla(regs->ip);
21863+
21864+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21865+ regs->ip = ip;
21866+ }
21867+#endif
21868+
21869 nmi_nesting_preprocess(regs);
21870
21871 nmi_enter();
21872diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21873index 6d9582e..f746287 100644
21874--- a/arch/x86/kernel/nmi_selftest.c
21875+++ b/arch/x86/kernel/nmi_selftest.c
21876@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21877 {
21878 /* trap all the unknown NMIs we may generate */
21879 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21880- __initdata);
21881+ __initconst);
21882 }
21883
21884 static void __init cleanup_nmi_testsuite(void)
21885@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21886 unsigned long timeout;
21887
21888 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21889- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21890+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21891 nmi_fail = FAILURE;
21892 return;
21893 }
21894diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21895index 676b8c7..870ba04 100644
21896--- a/arch/x86/kernel/paravirt-spinlocks.c
21897+++ b/arch/x86/kernel/paravirt-spinlocks.c
21898@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21899 arch_spin_lock(lock);
21900 }
21901
21902-struct pv_lock_ops pv_lock_ops = {
21903+struct pv_lock_ops pv_lock_ops __read_only = {
21904 #ifdef CONFIG_SMP
21905 .spin_is_locked = __ticket_spin_is_locked,
21906 .spin_is_contended = __ticket_spin_is_contended,
21907diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21908index 8bfb335..c1463c6 100644
21909--- a/arch/x86/kernel/paravirt.c
21910+++ b/arch/x86/kernel/paravirt.c
21911@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21912 {
21913 return x;
21914 }
21915+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21916+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21917+#endif
21918
21919 void __init default_banner(void)
21920 {
21921@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21922 if (opfunc == NULL)
21923 /* If there's no function, patch it with a ud2a (BUG) */
21924 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21925- else if (opfunc == _paravirt_nop)
21926+ else if (opfunc == (void *)_paravirt_nop)
21927 /* If the operation is a nop, then nop the callsite */
21928 ret = paravirt_patch_nop();
21929
21930 /* identity functions just return their single argument */
21931- else if (opfunc == _paravirt_ident_32)
21932+ else if (opfunc == (void *)_paravirt_ident_32)
21933 ret = paravirt_patch_ident_32(insnbuf, len);
21934- else if (opfunc == _paravirt_ident_64)
21935+ else if (opfunc == (void *)_paravirt_ident_64)
21936 ret = paravirt_patch_ident_64(insnbuf, len);
21937+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21938+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21939+ ret = paravirt_patch_ident_64(insnbuf, len);
21940+#endif
21941
21942 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21943 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21944@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21945 if (insn_len > len || start == NULL)
21946 insn_len = len;
21947 else
21948- memcpy(insnbuf, start, insn_len);
21949+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21950
21951 return insn_len;
21952 }
21953@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
21954 return this_cpu_read(paravirt_lazy_mode);
21955 }
21956
21957-struct pv_info pv_info = {
21958+struct pv_info pv_info __read_only = {
21959 .name = "bare hardware",
21960 .paravirt_enabled = 0,
21961 .kernel_rpl = 0,
21962@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21963 #endif
21964 };
21965
21966-struct pv_init_ops pv_init_ops = {
21967+struct pv_init_ops pv_init_ops __read_only = {
21968 .patch = native_patch,
21969 };
21970
21971-struct pv_time_ops pv_time_ops = {
21972+struct pv_time_ops pv_time_ops __read_only = {
21973 .sched_clock = native_sched_clock,
21974 .steal_clock = native_steal_clock,
21975 };
21976
21977-struct pv_irq_ops pv_irq_ops = {
21978+struct pv_irq_ops pv_irq_ops __read_only = {
21979 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21980 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21981 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21982@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21983 #endif
21984 };
21985
21986-struct pv_cpu_ops pv_cpu_ops = {
21987+struct pv_cpu_ops pv_cpu_ops __read_only = {
21988 .cpuid = native_cpuid,
21989 .get_debugreg = native_get_debugreg,
21990 .set_debugreg = native_set_debugreg,
21991@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21992 .end_context_switch = paravirt_nop,
21993 };
21994
21995-struct pv_apic_ops pv_apic_ops = {
21996+struct pv_apic_ops pv_apic_ops __read_only= {
21997 #ifdef CONFIG_X86_LOCAL_APIC
21998 .startup_ipi_hook = paravirt_nop,
21999 #endif
22000 };
22001
22002-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
22003+#ifdef CONFIG_X86_32
22004+#ifdef CONFIG_X86_PAE
22005+/* 64-bit pagetable entries */
22006+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
22007+#else
22008 /* 32-bit pagetable entries */
22009 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
22010+#endif
22011 #else
22012 /* 64-bit pagetable entries */
22013 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
22014 #endif
22015
22016-struct pv_mmu_ops pv_mmu_ops = {
22017+struct pv_mmu_ops pv_mmu_ops __read_only = {
22018
22019 .read_cr2 = native_read_cr2,
22020 .write_cr2 = native_write_cr2,
22021@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
22022 .make_pud = PTE_IDENT,
22023
22024 .set_pgd = native_set_pgd,
22025+ .set_pgd_batched = native_set_pgd_batched,
22026 #endif
22027 #endif /* PAGETABLE_LEVELS >= 3 */
22028
22029@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
22030 },
22031
22032 .set_fixmap = native_set_fixmap,
22033+
22034+#ifdef CONFIG_PAX_KERNEXEC
22035+ .pax_open_kernel = native_pax_open_kernel,
22036+ .pax_close_kernel = native_pax_close_kernel,
22037+#endif
22038+
22039 };
22040
22041 EXPORT_SYMBOL_GPL(pv_time_ops);
22042diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
22043index 299d493..2ccb0ee 100644
22044--- a/arch/x86/kernel/pci-calgary_64.c
22045+++ b/arch/x86/kernel/pci-calgary_64.c
22046@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
22047 tce_space = be64_to_cpu(readq(target));
22048 tce_space = tce_space & TAR_SW_BITS;
22049
22050- tce_space = tce_space & (~specified_table_size);
22051+ tce_space = tce_space & (~(unsigned long)specified_table_size);
22052 info->tce_space = (u64 *)__va(tce_space);
22053 }
22054 }
22055diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
22056index 35ccf75..7a15747 100644
22057--- a/arch/x86/kernel/pci-iommu_table.c
22058+++ b/arch/x86/kernel/pci-iommu_table.c
22059@@ -2,7 +2,7 @@
22060 #include <asm/iommu_table.h>
22061 #include <linux/string.h>
22062 #include <linux/kallsyms.h>
22063-
22064+#include <linux/sched.h>
22065
22066 #define DEBUG 1
22067
22068diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
22069index 6c483ba..d10ce2f 100644
22070--- a/arch/x86/kernel/pci-swiotlb.c
22071+++ b/arch/x86/kernel/pci-swiotlb.c
22072@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
22073 void *vaddr, dma_addr_t dma_addr,
22074 struct dma_attrs *attrs)
22075 {
22076- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
22077+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
22078 }
22079
22080 static struct dma_map_ops swiotlb_dma_ops = {
22081diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
22082index 14ae100..752a4f6 100644
22083--- a/arch/x86/kernel/process.c
22084+++ b/arch/x86/kernel/process.c
22085@@ -36,7 +36,8 @@
22086 * section. Since TSS's are completely CPU-local, we want them
22087 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
22088 */
22089-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
22090+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
22091+EXPORT_SYMBOL(init_tss);
22092
22093 #ifdef CONFIG_X86_64
22094 static DEFINE_PER_CPU(unsigned char, is_idle);
22095@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
22096 task_xstate_cachep =
22097 kmem_cache_create("task_xstate", xstate_size,
22098 __alignof__(union thread_xstate),
22099- SLAB_PANIC | SLAB_NOTRACK, NULL);
22100+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
22101 }
22102
22103 /*
22104@@ -105,7 +106,7 @@ void exit_thread(void)
22105 unsigned long *bp = t->io_bitmap_ptr;
22106
22107 if (bp) {
22108- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
22109+ struct tss_struct *tss = init_tss + get_cpu();
22110
22111 t->io_bitmap_ptr = NULL;
22112 clear_thread_flag(TIF_IO_BITMAP);
22113@@ -136,7 +137,7 @@ void show_regs_common(void)
22114 board = dmi_get_system_info(DMI_BOARD_NAME);
22115
22116 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
22117- current->pid, current->comm, print_tainted(),
22118+ task_pid_nr(current), current->comm, print_tainted(),
22119 init_utsname()->release,
22120 (int)strcspn(init_utsname()->version, " "),
22121 init_utsname()->version,
22122@@ -149,6 +150,9 @@ void flush_thread(void)
22123 {
22124 struct task_struct *tsk = current;
22125
22126+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
22127+ loadsegment(gs, 0);
22128+#endif
22129 flush_ptrace_hw_breakpoint(tsk);
22130 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
22131 drop_init_fpu(tsk);
22132@@ -295,7 +299,7 @@ static void __exit_idle(void)
22133 void exit_idle(void)
22134 {
22135 /* idle loop has pid 0 */
22136- if (current->pid)
22137+ if (task_pid_nr(current))
22138 return;
22139 __exit_idle();
22140 }
22141@@ -398,7 +402,7 @@ bool xen_set_default_idle(void)
22142 return ret;
22143 }
22144 #endif
22145-void stop_this_cpu(void *dummy)
22146+__noreturn void stop_this_cpu(void *dummy)
22147 {
22148 local_irq_disable();
22149 /*
22150@@ -544,16 +548,37 @@ static int __init idle_setup(char *str)
22151 }
22152 early_param("idle", idle_setup);
22153
22154-unsigned long arch_align_stack(unsigned long sp)
22155+#ifdef CONFIG_PAX_RANDKSTACK
22156+void pax_randomize_kstack(struct pt_regs *regs)
22157 {
22158- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
22159- sp -= get_random_int() % 8192;
22160- return sp & ~0xf;
22161-}
22162+ struct thread_struct *thread = &current->thread;
22163+ unsigned long time;
22164
22165-unsigned long arch_randomize_brk(struct mm_struct *mm)
22166-{
22167- unsigned long range_end = mm->brk + 0x02000000;
22168- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
22169-}
22170+ if (!randomize_va_space)
22171+ return;
22172+
22173+ if (v8086_mode(regs))
22174+ return;
22175
22176+ rdtscl(time);
22177+
22178+ /* P4 seems to return a 0 LSB, ignore it */
22179+#ifdef CONFIG_MPENTIUM4
22180+ time &= 0x3EUL;
22181+ time <<= 2;
22182+#elif defined(CONFIG_X86_64)
22183+ time &= 0xFUL;
22184+ time <<= 4;
22185+#else
22186+ time &= 0x1FUL;
22187+ time <<= 3;
22188+#endif
22189+
22190+ thread->sp0 ^= time;
22191+ load_sp0(init_tss + smp_processor_id(), thread);
22192+
22193+#ifdef CONFIG_X86_64
22194+ this_cpu_write(kernel_stack, thread->sp0);
22195+#endif
22196+}
22197+#endif
22198diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
22199index b5a8905..d9cacac 100644
22200--- a/arch/x86/kernel/process_32.c
22201+++ b/arch/x86/kernel/process_32.c
22202@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
22203 unsigned long thread_saved_pc(struct task_struct *tsk)
22204 {
22205 return ((unsigned long *)tsk->thread.sp)[3];
22206+//XXX return tsk->thread.eip;
22207 }
22208
22209 void __show_regs(struct pt_regs *regs, int all)
22210@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
22211 unsigned long sp;
22212 unsigned short ss, gs;
22213
22214- if (user_mode_vm(regs)) {
22215+ if (user_mode(regs)) {
22216 sp = regs->sp;
22217 ss = regs->ss & 0xffff;
22218- gs = get_user_gs(regs);
22219 } else {
22220 sp = kernel_stack_pointer(regs);
22221 savesegment(ss, ss);
22222- savesegment(gs, gs);
22223 }
22224+ gs = get_user_gs(regs);
22225
22226 show_regs_common();
22227
22228 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
22229 (u16)regs->cs, regs->ip, regs->flags,
22230- smp_processor_id());
22231+ raw_smp_processor_id());
22232 print_symbol("EIP is at %s\n", regs->ip);
22233
22234 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22235@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
22236 int copy_thread(unsigned long clone_flags, unsigned long sp,
22237 unsigned long arg, struct task_struct *p)
22238 {
22239- struct pt_regs *childregs = task_pt_regs(p);
22240+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22241 struct task_struct *tsk;
22242 int err;
22243
22244 p->thread.sp = (unsigned long) childregs;
22245 p->thread.sp0 = (unsigned long) (childregs+1);
22246+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22247
22248 if (unlikely(p->flags & PF_KTHREAD)) {
22249 /* kernel thread */
22250 memset(childregs, 0, sizeof(struct pt_regs));
22251 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22252- task_user_gs(p) = __KERNEL_STACK_CANARY;
22253- childregs->ds = __USER_DS;
22254- childregs->es = __USER_DS;
22255+ savesegment(gs, childregs->gs);
22256+ childregs->ds = __KERNEL_DS;
22257+ childregs->es = __KERNEL_DS;
22258 childregs->fs = __KERNEL_PERCPU;
22259 childregs->bx = sp; /* function */
22260 childregs->bp = arg;
22261@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22262 struct thread_struct *prev = &prev_p->thread,
22263 *next = &next_p->thread;
22264 int cpu = smp_processor_id();
22265- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22266+ struct tss_struct *tss = init_tss + cpu;
22267 fpu_switch_t fpu;
22268
22269 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22270@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22271 */
22272 lazy_save_gs(prev->gs);
22273
22274+#ifdef CONFIG_PAX_MEMORY_UDEREF
22275+ __set_fs(task_thread_info(next_p)->addr_limit);
22276+#endif
22277+
22278 /*
22279 * Load the per-thread Thread-Local Storage descriptor.
22280 */
22281@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22282 */
22283 arch_end_context_switch(next_p);
22284
22285+ this_cpu_write(current_task, next_p);
22286+ this_cpu_write(current_tinfo, &next_p->tinfo);
22287+
22288 /*
22289 * Restore %gs if needed (which is common)
22290 */
22291@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22292
22293 switch_fpu_finish(next_p, fpu);
22294
22295- this_cpu_write(current_task, next_p);
22296-
22297 return prev_p;
22298 }
22299
22300@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
22301 } while (count++ < 16);
22302 return 0;
22303 }
22304-
22305diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22306index 0f49677..fcbf88c 100644
22307--- a/arch/x86/kernel/process_64.c
22308+++ b/arch/x86/kernel/process_64.c
22309@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22310 struct pt_regs *childregs;
22311 struct task_struct *me = current;
22312
22313- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22314+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22315 childregs = task_pt_regs(p);
22316 p->thread.sp = (unsigned long) childregs;
22317 p->thread.usersp = me->thread.usersp;
22318+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22319 set_tsk_thread_flag(p, TIF_FORK);
22320 p->fpu_counter = 0;
22321 p->thread.io_bitmap_ptr = NULL;
22322@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22323 struct thread_struct *prev = &prev_p->thread;
22324 struct thread_struct *next = &next_p->thread;
22325 int cpu = smp_processor_id();
22326- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22327+ struct tss_struct *tss = init_tss + cpu;
22328 unsigned fsindex, gsindex;
22329 fpu_switch_t fpu;
22330
22331@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22332 prev->usersp = this_cpu_read(old_rsp);
22333 this_cpu_write(old_rsp, next->usersp);
22334 this_cpu_write(current_task, next_p);
22335+ this_cpu_write(current_tinfo, &next_p->tinfo);
22336
22337- this_cpu_write(kernel_stack,
22338- (unsigned long)task_stack_page(next_p) +
22339- THREAD_SIZE - KERNEL_STACK_OFFSET);
22340+ this_cpu_write(kernel_stack, next->sp0);
22341
22342 /*
22343 * Now maybe reload the debug registers and handle I/O bitmaps
22344@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
22345 if (!p || p == current || p->state == TASK_RUNNING)
22346 return 0;
22347 stack = (unsigned long)task_stack_page(p);
22348- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22349+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22350 return 0;
22351 fp = *(u64 *)(p->thread.sp);
22352 do {
22353- if (fp < (unsigned long)stack ||
22354- fp >= (unsigned long)stack+THREAD_SIZE)
22355+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22356 return 0;
22357 ip = *(u64 *)(fp+8);
22358 if (!in_sched_functions(ip))
22359diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22360index 29a8120..a50b5ee 100644
22361--- a/arch/x86/kernel/ptrace.c
22362+++ b/arch/x86/kernel/ptrace.c
22363@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22364 {
22365 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22366 unsigned long sp = (unsigned long)&regs->sp;
22367- struct thread_info *tinfo;
22368
22369- if (context == (sp & ~(THREAD_SIZE - 1)))
22370+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22371 return sp;
22372
22373- tinfo = (struct thread_info *)context;
22374- if (tinfo->previous_esp)
22375- return tinfo->previous_esp;
22376+ sp = *(unsigned long *)context;
22377+ if (sp)
22378+ return sp;
22379
22380 return (unsigned long)regs;
22381 }
22382@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22383 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22384 {
22385 int i;
22386- int dr7 = 0;
22387+ unsigned long dr7 = 0;
22388 struct arch_hw_breakpoint *info;
22389
22390 for (i = 0; i < HBP_NUM; i++) {
22391@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22392 unsigned long addr, unsigned long data)
22393 {
22394 int ret;
22395- unsigned long __user *datap = (unsigned long __user *)data;
22396+ unsigned long __user *datap = (__force unsigned long __user *)data;
22397
22398 switch (request) {
22399 /* read the word at location addr in the USER area. */
22400@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22401 if ((int) addr < 0)
22402 return -EIO;
22403 ret = do_get_thread_area(child, addr,
22404- (struct user_desc __user *)data);
22405+ (__force struct user_desc __user *) data);
22406 break;
22407
22408 case PTRACE_SET_THREAD_AREA:
22409 if ((int) addr < 0)
22410 return -EIO;
22411 ret = do_set_thread_area(child, addr,
22412- (struct user_desc __user *)data, 0);
22413+ (__force struct user_desc __user *) data, 0);
22414 break;
22415 #endif
22416
22417@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22418
22419 #ifdef CONFIG_X86_64
22420
22421-static struct user_regset x86_64_regsets[] __read_mostly = {
22422+static user_regset_no_const x86_64_regsets[] __read_only = {
22423 [REGSET_GENERAL] = {
22424 .core_note_type = NT_PRSTATUS,
22425 .n = sizeof(struct user_regs_struct) / sizeof(long),
22426@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22427 #endif /* CONFIG_X86_64 */
22428
22429 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22430-static struct user_regset x86_32_regsets[] __read_mostly = {
22431+static user_regset_no_const x86_32_regsets[] __read_only = {
22432 [REGSET_GENERAL] = {
22433 .core_note_type = NT_PRSTATUS,
22434 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22435@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22436 */
22437 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22438
22439-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22440+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22441 {
22442 #ifdef CONFIG_X86_64
22443 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22444@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22445 memset(info, 0, sizeof(*info));
22446 info->si_signo = SIGTRAP;
22447 info->si_code = si_code;
22448- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22449+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22450 }
22451
22452 void user_single_step_siginfo(struct task_struct *tsk,
22453@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22454 # define IS_IA32 0
22455 #endif
22456
22457+#ifdef CONFIG_GRKERNSEC_SETXID
22458+extern void gr_delayed_cred_worker(void);
22459+#endif
22460+
22461 /*
22462 * We must return the syscall number to actually look up in the table.
22463 * This can be -1L to skip running any syscall at all.
22464@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22465
22466 user_exit();
22467
22468+#ifdef CONFIG_GRKERNSEC_SETXID
22469+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22470+ gr_delayed_cred_worker();
22471+#endif
22472+
22473 /*
22474 * If we stepped into a sysenter/syscall insn, it trapped in
22475 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22476@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22477 */
22478 user_exit();
22479
22480+#ifdef CONFIG_GRKERNSEC_SETXID
22481+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22482+ gr_delayed_cred_worker();
22483+#endif
22484+
22485 audit_syscall_exit(regs);
22486
22487 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22488diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22489index 2cb9470..ff1fd80 100644
22490--- a/arch/x86/kernel/pvclock.c
22491+++ b/arch/x86/kernel/pvclock.c
22492@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22493 return pv_tsc_khz;
22494 }
22495
22496-static atomic64_t last_value = ATOMIC64_INIT(0);
22497+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22498
22499 void pvclock_resume(void)
22500 {
22501- atomic64_set(&last_value, 0);
22502+ atomic64_set_unchecked(&last_value, 0);
22503 }
22504
22505 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22506@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22507 * updating at the same time, and one of them could be slightly behind,
22508 * making the assumption that last_value always go forward fail to hold.
22509 */
22510- last = atomic64_read(&last_value);
22511+ last = atomic64_read_unchecked(&last_value);
22512 do {
22513 if (ret < last)
22514 return last;
22515- last = atomic64_cmpxchg(&last_value, last, ret);
22516+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22517 } while (unlikely(last != ret));
22518
22519 return ret;
22520diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22521index 76fa1e9..abf09ea 100644
22522--- a/arch/x86/kernel/reboot.c
22523+++ b/arch/x86/kernel/reboot.c
22524@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22525 EXPORT_SYMBOL(pm_power_off);
22526
22527 static const struct desc_ptr no_idt = {};
22528-static int reboot_mode;
22529+static unsigned short reboot_mode;
22530 enum reboot_type reboot_type = BOOT_ACPI;
22531 int reboot_force;
22532
22533@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22534
22535 void __noreturn machine_real_restart(unsigned int type)
22536 {
22537+
22538+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22539+ struct desc_struct *gdt;
22540+#endif
22541+
22542 local_irq_disable();
22543
22544 /*
22545@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22546
22547 /* Jump to the identity-mapped low memory code */
22548 #ifdef CONFIG_X86_32
22549- asm volatile("jmpl *%0" : :
22550+
22551+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22552+ gdt = get_cpu_gdt_table(smp_processor_id());
22553+ pax_open_kernel();
22554+#ifdef CONFIG_PAX_MEMORY_UDEREF
22555+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22556+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22557+ loadsegment(ds, __KERNEL_DS);
22558+ loadsegment(es, __KERNEL_DS);
22559+ loadsegment(ss, __KERNEL_DS);
22560+#endif
22561+#ifdef CONFIG_PAX_KERNEXEC
22562+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22563+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22564+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22565+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22566+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22567+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22568+#endif
22569+ pax_close_kernel();
22570+#endif
22571+
22572+ asm volatile("ljmpl *%0" : :
22573 "rm" (real_mode_header->machine_real_restart_asm),
22574 "a" (type));
22575 #else
22576@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22577 * try to force a triple fault and then cycle between hitting the keyboard
22578 * controller and doing that
22579 */
22580-static void native_machine_emergency_restart(void)
22581+static void __noreturn native_machine_emergency_restart(void)
22582 {
22583 int i;
22584 int attempt = 0;
22585@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22586 #endif
22587 }
22588
22589-static void __machine_emergency_restart(int emergency)
22590+static void __noreturn __machine_emergency_restart(int emergency)
22591 {
22592 reboot_emergency = emergency;
22593 machine_ops.emergency_restart();
22594 }
22595
22596-static void native_machine_restart(char *__unused)
22597+static void __noreturn native_machine_restart(char *__unused)
22598 {
22599 pr_notice("machine restart\n");
22600
22601@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22602 __machine_emergency_restart(0);
22603 }
22604
22605-static void native_machine_halt(void)
22606+static void __noreturn native_machine_halt(void)
22607 {
22608 /* Stop other cpus and apics */
22609 machine_shutdown();
22610@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22611 stop_this_cpu(NULL);
22612 }
22613
22614-static void native_machine_power_off(void)
22615+static void __noreturn native_machine_power_off(void)
22616 {
22617 if (pm_power_off) {
22618 if (!reboot_force)
22619@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22620 }
22621 /* A fallback in case there is no PM info available */
22622 tboot_shutdown(TB_SHUTDOWN_HALT);
22623+ unreachable();
22624 }
22625
22626-struct machine_ops machine_ops = {
22627+struct machine_ops machine_ops __read_only = {
22628 .power_off = native_machine_power_off,
22629 .shutdown = native_machine_shutdown,
22630 .emergency_restart = native_machine_emergency_restart,
22631diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22632index f2bb9c9..bed145d7 100644
22633--- a/arch/x86/kernel/relocate_kernel_64.S
22634+++ b/arch/x86/kernel/relocate_kernel_64.S
22635@@ -11,6 +11,7 @@
22636 #include <asm/kexec.h>
22637 #include <asm/processor-flags.h>
22638 #include <asm/pgtable_types.h>
22639+#include <asm/alternative-asm.h>
22640
22641 /*
22642 * Must be relocatable PIC code callable as a C function
22643@@ -167,6 +168,7 @@ identity_mapped:
22644 xorq %r14, %r14
22645 xorq %r15, %r15
22646
22647+ pax_force_retaddr 0, 1
22648 ret
22649
22650 1:
22651diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22652index fae9134..8fcd87c 100644
22653--- a/arch/x86/kernel/setup.c
22654+++ b/arch/x86/kernel/setup.c
22655@@ -111,6 +111,7 @@
22656 #include <asm/mce.h>
22657 #include <asm/alternative.h>
22658 #include <asm/prom.h>
22659+#include <asm/boot.h>
22660
22661 /*
22662 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
22663@@ -447,7 +448,7 @@ static void __init parse_setup_data(void)
22664
22665 switch (data->type) {
22666 case SETUP_E820_EXT:
22667- parse_e820_ext(data);
22668+ parse_e820_ext((struct setup_data __force_kernel *)data);
22669 break;
22670 case SETUP_DTB:
22671 add_dtb(pa_data);
22672@@ -774,7 +775,7 @@ static void __init trim_bios_range(void)
22673 * area (640->1Mb) as ram even though it is not.
22674 * take them out.
22675 */
22676- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22677+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22678
22679 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22680 }
22681@@ -782,7 +783,7 @@ static void __init trim_bios_range(void)
22682 /* called before trim_bios_range() to spare extra sanitize */
22683 static void __init e820_add_kernel_range(void)
22684 {
22685- u64 start = __pa_symbol(_text);
22686+ u64 start = __pa_symbol(ktla_ktva(_text));
22687 u64 size = __pa_symbol(_end) - start;
22688
22689 /*
22690@@ -844,8 +845,12 @@ static void __init trim_low_memory_range(void)
22691
22692 void __init setup_arch(char **cmdline_p)
22693 {
22694+#ifdef CONFIG_X86_32
22695+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
22696+#else
22697 memblock_reserve(__pa_symbol(_text),
22698 (unsigned long)__bss_stop - (unsigned long)_text);
22699+#endif
22700
22701 early_reserve_initrd();
22702
22703@@ -937,14 +942,14 @@ void __init setup_arch(char **cmdline_p)
22704
22705 if (!boot_params.hdr.root_flags)
22706 root_mountflags &= ~MS_RDONLY;
22707- init_mm.start_code = (unsigned long) _text;
22708- init_mm.end_code = (unsigned long) _etext;
22709+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22710+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22711 init_mm.end_data = (unsigned long) _edata;
22712 init_mm.brk = _brk_end;
22713
22714- code_resource.start = __pa_symbol(_text);
22715- code_resource.end = __pa_symbol(_etext)-1;
22716- data_resource.start = __pa_symbol(_etext);
22717+ code_resource.start = __pa_symbol(ktla_ktva(_text));
22718+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
22719+ data_resource.start = __pa_symbol(_sdata);
22720 data_resource.end = __pa_symbol(_edata)-1;
22721 bss_resource.start = __pa_symbol(__bss_start);
22722 bss_resource.end = __pa_symbol(__bss_stop)-1;
22723diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22724index 5cdff03..80fa283 100644
22725--- a/arch/x86/kernel/setup_percpu.c
22726+++ b/arch/x86/kernel/setup_percpu.c
22727@@ -21,19 +21,17 @@
22728 #include <asm/cpu.h>
22729 #include <asm/stackprotector.h>
22730
22731-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22732+#ifdef CONFIG_SMP
22733+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22734 EXPORT_PER_CPU_SYMBOL(cpu_number);
22735+#endif
22736
22737-#ifdef CONFIG_X86_64
22738 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22739-#else
22740-#define BOOT_PERCPU_OFFSET 0
22741-#endif
22742
22743 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22744 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22745
22746-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22747+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22748 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22749 };
22750 EXPORT_SYMBOL(__per_cpu_offset);
22751@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22752 {
22753 #ifdef CONFIG_NEED_MULTIPLE_NODES
22754 pg_data_t *last = NULL;
22755- unsigned int cpu;
22756+ int cpu;
22757
22758 for_each_possible_cpu(cpu) {
22759 int node = early_cpu_to_node(cpu);
22760@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22761 {
22762 #ifdef CONFIG_X86_32
22763 struct desc_struct gdt;
22764+ unsigned long base = per_cpu_offset(cpu);
22765
22766- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22767- 0x2 | DESCTYPE_S, 0x8);
22768- gdt.s = 1;
22769+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22770+ 0x83 | DESCTYPE_S, 0xC);
22771 write_gdt_entry(get_cpu_gdt_table(cpu),
22772 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22773 #endif
22774@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22775 /* alrighty, percpu areas up and running */
22776 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22777 for_each_possible_cpu(cpu) {
22778+#ifdef CONFIG_CC_STACKPROTECTOR
22779+#ifdef CONFIG_X86_32
22780+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22781+#endif
22782+#endif
22783 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22784 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22785 per_cpu(cpu_number, cpu) = cpu;
22786@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22787 */
22788 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22789 #endif
22790+#ifdef CONFIG_CC_STACKPROTECTOR
22791+#ifdef CONFIG_X86_32
22792+ if (!cpu)
22793+ per_cpu(stack_canary.canary, cpu) = canary;
22794+#endif
22795+#endif
22796 /*
22797 * Up to this point, the boot CPU has been using .init.data
22798 * area. Reload any changed state for the boot CPU.
22799diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22800index 6956299..f20beae 100644
22801--- a/arch/x86/kernel/signal.c
22802+++ b/arch/x86/kernel/signal.c
22803@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22804 * Align the stack pointer according to the i386 ABI,
22805 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22806 */
22807- sp = ((sp + 4) & -16ul) - 4;
22808+ sp = ((sp - 12) & -16ul) - 4;
22809 #else /* !CONFIG_X86_32 */
22810 sp = round_down(sp, 16) - 8;
22811 #endif
22812@@ -304,9 +304,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22813 }
22814
22815 if (current->mm->context.vdso)
22816- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22817+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22818 else
22819- restorer = &frame->retcode;
22820+ restorer = (void __user *)&frame->retcode;
22821 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22822 restorer = ksig->ka.sa.sa_restorer;
22823
22824@@ -320,7 +320,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22825 * reasons and because gdb uses it as a signature to notice
22826 * signal handler stack frames.
22827 */
22828- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22829+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22830
22831 if (err)
22832 return -EFAULT;
22833@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22834 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22835
22836 /* Set up to return from userspace. */
22837- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22838+ if (current->mm->context.vdso)
22839+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22840+ else
22841+ restorer = (void __user *)&frame->retcode;
22842 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22843 restorer = ksig->ka.sa.sa_restorer;
22844 put_user_ex(restorer, &frame->pretcode);
22845@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22846 * reasons and because gdb uses it as a signature to notice
22847 * signal handler stack frames.
22848 */
22849- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22850+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22851 } put_user_catch(err);
22852
22853 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
22854@@ -615,7 +618,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22855 {
22856 int usig = signr_convert(ksig->sig);
22857 sigset_t *set = sigmask_to_save();
22858- compat_sigset_t *cset = (compat_sigset_t *) set;
22859+ sigset_t sigcopy;
22860+ compat_sigset_t *cset;
22861+
22862+ sigcopy = *set;
22863+
22864+ cset = (compat_sigset_t *) &sigcopy;
22865
22866 /* Set up the stack frame */
22867 if (is_ia32_frame()) {
22868@@ -626,7 +634,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22869 } else if (is_x32_frame()) {
22870 return x32_setup_rt_frame(ksig, cset, regs);
22871 } else {
22872- return __setup_rt_frame(ksig->sig, ksig, set, regs);
22873+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
22874 }
22875 }
22876
22877diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22878index 48d2b7d..90d328a 100644
22879--- a/arch/x86/kernel/smp.c
22880+++ b/arch/x86/kernel/smp.c
22881@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22882
22883 __setup("nonmi_ipi", nonmi_ipi_setup);
22884
22885-struct smp_ops smp_ops = {
22886+struct smp_ops smp_ops __read_only = {
22887 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22888 .smp_prepare_cpus = native_smp_prepare_cpus,
22889 .smp_cpus_done = native_smp_cpus_done,
22890diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22891index 9f190a2..90a0688 100644
22892--- a/arch/x86/kernel/smpboot.c
22893+++ b/arch/x86/kernel/smpboot.c
22894@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22895 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22896 (THREAD_SIZE + task_stack_page(idle))) - 1);
22897 per_cpu(current_task, cpu) = idle;
22898+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22899
22900 #ifdef CONFIG_X86_32
22901 /* Stack for startup_32 can be just as for start_secondary onwards */
22902@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22903 #else
22904 clear_tsk_thread_flag(idle, TIF_FORK);
22905 initial_gs = per_cpu_offset(cpu);
22906- per_cpu(kernel_stack, cpu) =
22907- (unsigned long)task_stack_page(idle) -
22908- KERNEL_STACK_OFFSET + THREAD_SIZE;
22909+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22910 #endif
22911+
22912+ pax_open_kernel();
22913 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22914+ pax_close_kernel();
22915+
22916 initial_code = (unsigned long)start_secondary;
22917 stack_start = idle->thread.sp;
22918
22919@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22920 /* the FPU context is blank, nobody can own it */
22921 __cpu_disable_lazy_restore(cpu);
22922
22923+#ifdef CONFIG_PAX_PER_CPU_PGD
22924+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22925+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22926+ KERNEL_PGD_PTRS);
22927+#endif
22928+
22929+ /* the FPU context is blank, nobody can own it */
22930+ __cpu_disable_lazy_restore(cpu);
22931+
22932 err = do_boot_cpu(apicid, cpu, tidle);
22933 if (err) {
22934 pr_debug("do_boot_cpu failed %d\n", err);
22935diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22936index 9b4d51d..5d28b58 100644
22937--- a/arch/x86/kernel/step.c
22938+++ b/arch/x86/kernel/step.c
22939@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22940 struct desc_struct *desc;
22941 unsigned long base;
22942
22943- seg &= ~7UL;
22944+ seg >>= 3;
22945
22946 mutex_lock(&child->mm->context.lock);
22947- if (unlikely((seg >> 3) >= child->mm->context.size))
22948+ if (unlikely(seg >= child->mm->context.size))
22949 addr = -1L; /* bogus selector, access would fault */
22950 else {
22951 desc = child->mm->context.ldt + seg;
22952@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22953 addr += base;
22954 }
22955 mutex_unlock(&child->mm->context.lock);
22956- }
22957+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22958+ addr = ktla_ktva(addr);
22959
22960 return addr;
22961 }
22962@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22963 unsigned char opcode[15];
22964 unsigned long addr = convert_ip_to_linear(child, regs);
22965
22966+ if (addr == -EINVAL)
22967+ return 0;
22968+
22969 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22970 for (i = 0; i < copied; i++) {
22971 switch (opcode[i]) {
22972diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22973new file mode 100644
22974index 0000000..5877189
22975--- /dev/null
22976+++ b/arch/x86/kernel/sys_i386_32.c
22977@@ -0,0 +1,189 @@
22978+/*
22979+ * This file contains various random system calls that
22980+ * have a non-standard calling sequence on the Linux/i386
22981+ * platform.
22982+ */
22983+
22984+#include <linux/errno.h>
22985+#include <linux/sched.h>
22986+#include <linux/mm.h>
22987+#include <linux/fs.h>
22988+#include <linux/smp.h>
22989+#include <linux/sem.h>
22990+#include <linux/msg.h>
22991+#include <linux/shm.h>
22992+#include <linux/stat.h>
22993+#include <linux/syscalls.h>
22994+#include <linux/mman.h>
22995+#include <linux/file.h>
22996+#include <linux/utsname.h>
22997+#include <linux/ipc.h>
22998+#include <linux/elf.h>
22999+
23000+#include <linux/uaccess.h>
23001+#include <linux/unistd.h>
23002+
23003+#include <asm/syscalls.h>
23004+
23005+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
23006+{
23007+ unsigned long pax_task_size = TASK_SIZE;
23008+
23009+#ifdef CONFIG_PAX_SEGMEXEC
23010+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
23011+ pax_task_size = SEGMEXEC_TASK_SIZE;
23012+#endif
23013+
23014+ if (flags & MAP_FIXED)
23015+ if (len > pax_task_size || addr > pax_task_size - len)
23016+ return -EINVAL;
23017+
23018+ return 0;
23019+}
23020+
23021+/*
23022+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
23023+ */
23024+static unsigned long get_align_mask(void)
23025+{
23026+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
23027+ return 0;
23028+
23029+ if (!(current->flags & PF_RANDOMIZE))
23030+ return 0;
23031+
23032+ return va_align.mask;
23033+}
23034+
23035+unsigned long
23036+arch_get_unmapped_area(struct file *filp, unsigned long addr,
23037+ unsigned long len, unsigned long pgoff, unsigned long flags)
23038+{
23039+ struct mm_struct *mm = current->mm;
23040+ struct vm_area_struct *vma;
23041+ unsigned long pax_task_size = TASK_SIZE;
23042+ struct vm_unmapped_area_info info;
23043+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23044+
23045+#ifdef CONFIG_PAX_SEGMEXEC
23046+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23047+ pax_task_size = SEGMEXEC_TASK_SIZE;
23048+#endif
23049+
23050+ pax_task_size -= PAGE_SIZE;
23051+
23052+ if (len > pax_task_size)
23053+ return -ENOMEM;
23054+
23055+ if (flags & MAP_FIXED)
23056+ return addr;
23057+
23058+#ifdef CONFIG_PAX_RANDMMAP
23059+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23060+#endif
23061+
23062+ if (addr) {
23063+ addr = PAGE_ALIGN(addr);
23064+ if (pax_task_size - len >= addr) {
23065+ vma = find_vma(mm, addr);
23066+ if (check_heap_stack_gap(vma, addr, len, offset))
23067+ return addr;
23068+ }
23069+ }
23070+
23071+ info.flags = 0;
23072+ info.length = len;
23073+ info.align_mask = filp ? get_align_mask() : 0;
23074+ info.align_offset = pgoff << PAGE_SHIFT;
23075+ info.threadstack_offset = offset;
23076+
23077+#ifdef CONFIG_PAX_PAGEEXEC
23078+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
23079+ info.low_limit = 0x00110000UL;
23080+ info.high_limit = mm->start_code;
23081+
23082+#ifdef CONFIG_PAX_RANDMMAP
23083+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23084+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
23085+#endif
23086+
23087+ if (info.low_limit < info.high_limit) {
23088+ addr = vm_unmapped_area(&info);
23089+ if (!IS_ERR_VALUE(addr))
23090+ return addr;
23091+ }
23092+ } else
23093+#endif
23094+
23095+ info.low_limit = mm->mmap_base;
23096+ info.high_limit = pax_task_size;
23097+
23098+ return vm_unmapped_area(&info);
23099+}
23100+
23101+unsigned long
23102+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23103+ const unsigned long len, const unsigned long pgoff,
23104+ const unsigned long flags)
23105+{
23106+ struct vm_area_struct *vma;
23107+ struct mm_struct *mm = current->mm;
23108+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
23109+ struct vm_unmapped_area_info info;
23110+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23111+
23112+#ifdef CONFIG_PAX_SEGMEXEC
23113+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23114+ pax_task_size = SEGMEXEC_TASK_SIZE;
23115+#endif
23116+
23117+ pax_task_size -= PAGE_SIZE;
23118+
23119+ /* requested length too big for entire address space */
23120+ if (len > pax_task_size)
23121+ return -ENOMEM;
23122+
23123+ if (flags & MAP_FIXED)
23124+ return addr;
23125+
23126+#ifdef CONFIG_PAX_PAGEEXEC
23127+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
23128+ goto bottomup;
23129+#endif
23130+
23131+#ifdef CONFIG_PAX_RANDMMAP
23132+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23133+#endif
23134+
23135+ /* requesting a specific address */
23136+ if (addr) {
23137+ addr = PAGE_ALIGN(addr);
23138+ if (pax_task_size - len >= addr) {
23139+ vma = find_vma(mm, addr);
23140+ if (check_heap_stack_gap(vma, addr, len, offset))
23141+ return addr;
23142+ }
23143+ }
23144+
23145+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
23146+ info.length = len;
23147+ info.low_limit = PAGE_SIZE;
23148+ info.high_limit = mm->mmap_base;
23149+ info.align_mask = filp ? get_align_mask() : 0;
23150+ info.align_offset = pgoff << PAGE_SHIFT;
23151+ info.threadstack_offset = offset;
23152+
23153+ addr = vm_unmapped_area(&info);
23154+ if (!(addr & ~PAGE_MASK))
23155+ return addr;
23156+ VM_BUG_ON(addr != -ENOMEM);
23157+
23158+bottomup:
23159+ /*
23160+ * A failed mmap() very likely causes application failure,
23161+ * so fall back to the bottom-up function here. This scenario
23162+ * can happen with large stack limits and large mmap()
23163+ * allocations.
23164+ */
23165+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
23166+}
23167diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
23168index dbded5a..ace2781 100644
23169--- a/arch/x86/kernel/sys_x86_64.c
23170+++ b/arch/x86/kernel/sys_x86_64.c
23171@@ -81,8 +81,8 @@ out:
23172 return error;
23173 }
23174
23175-static void find_start_end(unsigned long flags, unsigned long *begin,
23176- unsigned long *end)
23177+static void find_start_end(struct mm_struct *mm, unsigned long flags,
23178+ unsigned long *begin, unsigned long *end)
23179 {
23180 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
23181 unsigned long new_begin;
23182@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
23183 *begin = new_begin;
23184 }
23185 } else {
23186- *begin = TASK_UNMAPPED_BASE;
23187+ *begin = mm->mmap_base;
23188 *end = TASK_SIZE;
23189 }
23190 }
23191@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23192 struct vm_area_struct *vma;
23193 struct vm_unmapped_area_info info;
23194 unsigned long begin, end;
23195+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23196
23197 if (flags & MAP_FIXED)
23198 return addr;
23199
23200- find_start_end(flags, &begin, &end);
23201+ find_start_end(mm, flags, &begin, &end);
23202
23203 if (len > end)
23204 return -ENOMEM;
23205
23206+#ifdef CONFIG_PAX_RANDMMAP
23207+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23208+#endif
23209+
23210 if (addr) {
23211 addr = PAGE_ALIGN(addr);
23212 vma = find_vma(mm, addr);
23213- if (end - len >= addr &&
23214- (!vma || addr + len <= vma->vm_start))
23215+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23216 return addr;
23217 }
23218
23219@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23220 info.high_limit = end;
23221 info.align_mask = filp ? get_align_mask() : 0;
23222 info.align_offset = pgoff << PAGE_SHIFT;
23223+ info.threadstack_offset = offset;
23224 return vm_unmapped_area(&info);
23225 }
23226
23227@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23228 struct mm_struct *mm = current->mm;
23229 unsigned long addr = addr0;
23230 struct vm_unmapped_area_info info;
23231+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23232
23233 /* requested length too big for entire address space */
23234 if (len > TASK_SIZE)
23235@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23236 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23237 goto bottomup;
23238
23239+#ifdef CONFIG_PAX_RANDMMAP
23240+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23241+#endif
23242+
23243 /* requesting a specific address */
23244 if (addr) {
23245 addr = PAGE_ALIGN(addr);
23246 vma = find_vma(mm, addr);
23247- if (TASK_SIZE - len >= addr &&
23248- (!vma || addr + len <= vma->vm_start))
23249+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23250 return addr;
23251 }
23252
23253@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23254 info.high_limit = mm->mmap_base;
23255 info.align_mask = filp ? get_align_mask() : 0;
23256 info.align_offset = pgoff << PAGE_SHIFT;
23257+ info.threadstack_offset = offset;
23258 addr = vm_unmapped_area(&info);
23259 if (!(addr & ~PAGE_MASK))
23260 return addr;
23261diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23262index f84fe00..f41d9f1 100644
23263--- a/arch/x86/kernel/tboot.c
23264+++ b/arch/x86/kernel/tboot.c
23265@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23266
23267 void tboot_shutdown(u32 shutdown_type)
23268 {
23269- void (*shutdown)(void);
23270+ void (* __noreturn shutdown)(void);
23271
23272 if (!tboot_enabled())
23273 return;
23274@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23275
23276 switch_to_tboot_pt();
23277
23278- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23279+ shutdown = (void *)tboot->shutdown_entry;
23280 shutdown();
23281
23282 /* should not reach here */
23283@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23284 return 0;
23285 }
23286
23287-static atomic_t ap_wfs_count;
23288+static atomic_unchecked_t ap_wfs_count;
23289
23290 static int tboot_wait_for_aps(int num_aps)
23291 {
23292@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23293 {
23294 switch (action) {
23295 case CPU_DYING:
23296- atomic_inc(&ap_wfs_count);
23297+ atomic_inc_unchecked(&ap_wfs_count);
23298 if (num_online_cpus() == 1)
23299- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23300+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23301 return NOTIFY_BAD;
23302 break;
23303 }
23304 return NOTIFY_OK;
23305 }
23306
23307-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23308+static struct notifier_block tboot_cpu_notifier =
23309 {
23310 .notifier_call = tboot_cpu_callback,
23311 };
23312@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23313
23314 tboot_create_trampoline();
23315
23316- atomic_set(&ap_wfs_count, 0);
23317+ atomic_set_unchecked(&ap_wfs_count, 0);
23318 register_hotcpu_notifier(&tboot_cpu_notifier);
23319
23320 acpi_os_set_prepare_sleep(&tboot_sleep);
23321diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23322index 24d3c91..d06b473 100644
23323--- a/arch/x86/kernel/time.c
23324+++ b/arch/x86/kernel/time.c
23325@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23326 {
23327 unsigned long pc = instruction_pointer(regs);
23328
23329- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23330+ if (!user_mode(regs) && in_lock_functions(pc)) {
23331 #ifdef CONFIG_FRAME_POINTER
23332- return *(unsigned long *)(regs->bp + sizeof(long));
23333+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23334 #else
23335 unsigned long *sp =
23336 (unsigned long *)kernel_stack_pointer(regs);
23337@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23338 * or above a saved flags. Eflags has bits 22-31 zero,
23339 * kernel addresses don't.
23340 */
23341+
23342+#ifdef CONFIG_PAX_KERNEXEC
23343+ return ktla_ktva(sp[0]);
23344+#else
23345 if (sp[0] >> 22)
23346 return sp[0];
23347 if (sp[1] >> 22)
23348 return sp[1];
23349 #endif
23350+
23351+#endif
23352 }
23353 return pc;
23354 }
23355diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23356index 9d9d2f9..cad418a 100644
23357--- a/arch/x86/kernel/tls.c
23358+++ b/arch/x86/kernel/tls.c
23359@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23360 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23361 return -EINVAL;
23362
23363+#ifdef CONFIG_PAX_SEGMEXEC
23364+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23365+ return -EINVAL;
23366+#endif
23367+
23368 set_tls_desc(p, idx, &info, 1);
23369
23370 return 0;
23371@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23372
23373 if (kbuf)
23374 info = kbuf;
23375- else if (__copy_from_user(infobuf, ubuf, count))
23376+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23377 return -EFAULT;
23378 else
23379 info = infobuf;
23380diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23381index 68bda7a..3ec7bb7 100644
23382--- a/arch/x86/kernel/traps.c
23383+++ b/arch/x86/kernel/traps.c
23384@@ -68,12 +68,6 @@
23385 #include <asm/setup.h>
23386
23387 asmlinkage int system_call(void);
23388-
23389-/*
23390- * The IDT has to be page-aligned to simplify the Pentium
23391- * F0 0F bug workaround.
23392- */
23393-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23394 #endif
23395
23396 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23397@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23398 }
23399
23400 static int __kprobes
23401-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23402+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23403 struct pt_regs *regs, long error_code)
23404 {
23405 #ifdef CONFIG_X86_32
23406- if (regs->flags & X86_VM_MASK) {
23407+ if (v8086_mode(regs)) {
23408 /*
23409 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23410 * On nmi (interrupt 2), do_trap should not be called.
23411@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23412 return -1;
23413 }
23414 #endif
23415- if (!user_mode(regs)) {
23416+ if (!user_mode_novm(regs)) {
23417 if (!fixup_exception(regs)) {
23418 tsk->thread.error_code = error_code;
23419 tsk->thread.trap_nr = trapnr;
23420+
23421+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23422+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23423+ str = "PAX: suspicious stack segment fault";
23424+#endif
23425+
23426 die(str, regs, error_code);
23427 }
23428+
23429+#ifdef CONFIG_PAX_REFCOUNT
23430+ if (trapnr == 4)
23431+ pax_report_refcount_overflow(regs);
23432+#endif
23433+
23434 return 0;
23435 }
23436
23437@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23438 }
23439
23440 static void __kprobes
23441-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23442+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23443 long error_code, siginfo_t *info)
23444 {
23445 struct task_struct *tsk = current;
23446@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23447 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23448 printk_ratelimit()) {
23449 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23450- tsk->comm, tsk->pid, str,
23451+ tsk->comm, task_pid_nr(tsk), str,
23452 regs->ip, regs->sp, error_code);
23453 print_vma_addr(" in ", regs->ip);
23454 pr_cont("\n");
23455@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23456 conditional_sti(regs);
23457
23458 #ifdef CONFIG_X86_32
23459- if (regs->flags & X86_VM_MASK) {
23460+ if (v8086_mode(regs)) {
23461 local_irq_enable();
23462 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23463 goto exit;
23464@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23465 #endif
23466
23467 tsk = current;
23468- if (!user_mode(regs)) {
23469+ if (!user_mode_novm(regs)) {
23470 if (fixup_exception(regs))
23471 goto exit;
23472
23473 tsk->thread.error_code = error_code;
23474 tsk->thread.trap_nr = X86_TRAP_GP;
23475 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23476- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23477+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23478+
23479+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23480+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23481+ die("PAX: suspicious general protection fault", regs, error_code);
23482+ else
23483+#endif
23484+
23485 die("general protection fault", regs, error_code);
23486+ }
23487 goto exit;
23488 }
23489
23490+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23491+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23492+ struct mm_struct *mm = tsk->mm;
23493+ unsigned long limit;
23494+
23495+ down_write(&mm->mmap_sem);
23496+ limit = mm->context.user_cs_limit;
23497+ if (limit < TASK_SIZE) {
23498+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23499+ up_write(&mm->mmap_sem);
23500+ return;
23501+ }
23502+ up_write(&mm->mmap_sem);
23503+ }
23504+#endif
23505+
23506 tsk->thread.error_code = error_code;
23507 tsk->thread.trap_nr = X86_TRAP_GP;
23508
23509@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23510 /* It's safe to allow irq's after DR6 has been saved */
23511 preempt_conditional_sti(regs);
23512
23513- if (regs->flags & X86_VM_MASK) {
23514+ if (v8086_mode(regs)) {
23515 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23516 X86_TRAP_DB);
23517 preempt_conditional_cli(regs);
23518@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23519 * We already checked v86 mode above, so we can check for kernel mode
23520 * by just checking the CPL of CS.
23521 */
23522- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23523+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23524 tsk->thread.debugreg6 &= ~DR_STEP;
23525 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23526 regs->flags &= ~X86_EFLAGS_TF;
23527@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23528 return;
23529 conditional_sti(regs);
23530
23531- if (!user_mode_vm(regs))
23532+ if (!user_mode(regs))
23533 {
23534 if (!fixup_exception(regs)) {
23535 task->thread.error_code = error_code;
23536diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23537index 0ba4cfb..4596bec 100644
23538--- a/arch/x86/kernel/uprobes.c
23539+++ b/arch/x86/kernel/uprobes.c
23540@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23541 int ret = NOTIFY_DONE;
23542
23543 /* We are only interested in userspace traps */
23544- if (regs && !user_mode_vm(regs))
23545+ if (regs && !user_mode(regs))
23546 return NOTIFY_DONE;
23547
23548 switch (val) {
23549diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23550index b9242ba..50c5edd 100644
23551--- a/arch/x86/kernel/verify_cpu.S
23552+++ b/arch/x86/kernel/verify_cpu.S
23553@@ -20,6 +20,7 @@
23554 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23555 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23556 * arch/x86/kernel/head_32.S: processor startup
23557+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23558 *
23559 * verify_cpu, returns the status of longmode and SSE in register %eax.
23560 * 0: Success 1: Failure
23561diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23562index 3dbdd9c..888b14e 100644
23563--- a/arch/x86/kernel/vm86_32.c
23564+++ b/arch/x86/kernel/vm86_32.c
23565@@ -44,6 +44,7 @@
23566 #include <linux/ptrace.h>
23567 #include <linux/audit.h>
23568 #include <linux/stddef.h>
23569+#include <linux/grsecurity.h>
23570
23571 #include <asm/uaccess.h>
23572 #include <asm/io.h>
23573@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23574 do_exit(SIGSEGV);
23575 }
23576
23577- tss = &per_cpu(init_tss, get_cpu());
23578+ tss = init_tss + get_cpu();
23579 current->thread.sp0 = current->thread.saved_sp0;
23580 current->thread.sysenter_cs = __KERNEL_CS;
23581 load_sp0(tss, &current->thread);
23582@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
23583
23584 if (tsk->thread.saved_sp0)
23585 goto out;
23586+
23587+#ifdef CONFIG_GRKERNSEC_VM86
23588+ if (!capable(CAP_SYS_RAWIO)) {
23589+ gr_handle_vm86();
23590+ goto out;
23591+ }
23592+#endif
23593+
23594 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
23595 offsetof(struct kernel_vm86_struct, vm86plus) -
23596 sizeof(info.regs));
23597@@ -242,6 +251,14 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
23598 int tmp, ret;
23599 struct vm86plus_struct __user *v86;
23600
23601+#ifdef CONFIG_GRKERNSEC_VM86
23602+ if (!capable(CAP_SYS_RAWIO)) {
23603+ gr_handle_vm86();
23604+ ret = -EPERM;
23605+ goto out;
23606+ }
23607+#endif
23608+
23609 tsk = current;
23610 switch (cmd) {
23611 case VM86_REQUEST_IRQ:
23612@@ -329,7 +346,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23613 tsk->thread.saved_fs = info->regs32->fs;
23614 tsk->thread.saved_gs = get_user_gs(info->regs32);
23615
23616- tss = &per_cpu(init_tss, get_cpu());
23617+ tss = init_tss + get_cpu();
23618 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23619 if (cpu_has_sep)
23620 tsk->thread.sysenter_cs = 0;
23621@@ -536,7 +553,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23622 goto cannot_handle;
23623 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23624 goto cannot_handle;
23625- intr_ptr = (unsigned long __user *) (i << 2);
23626+ intr_ptr = (__force unsigned long __user *) (i << 2);
23627 if (get_user(segoffs, intr_ptr))
23628 goto cannot_handle;
23629 if ((segoffs >> 16) == BIOSSEG)
23630diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23631index 22a1530..5efafbf 100644
23632--- a/arch/x86/kernel/vmlinux.lds.S
23633+++ b/arch/x86/kernel/vmlinux.lds.S
23634@@ -26,6 +26,13 @@
23635 #include <asm/page_types.h>
23636 #include <asm/cache.h>
23637 #include <asm/boot.h>
23638+#include <asm/segment.h>
23639+
23640+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23641+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23642+#else
23643+#define __KERNEL_TEXT_OFFSET 0
23644+#endif
23645
23646 #undef i386 /* in case the preprocessor is a 32bit one */
23647
23648@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23649
23650 PHDRS {
23651 text PT_LOAD FLAGS(5); /* R_E */
23652+#ifdef CONFIG_X86_32
23653+ module PT_LOAD FLAGS(5); /* R_E */
23654+#endif
23655+#ifdef CONFIG_XEN
23656+ rodata PT_LOAD FLAGS(5); /* R_E */
23657+#else
23658+ rodata PT_LOAD FLAGS(4); /* R__ */
23659+#endif
23660 data PT_LOAD FLAGS(6); /* RW_ */
23661-#ifdef CONFIG_X86_64
23662+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23663 #ifdef CONFIG_SMP
23664 percpu PT_LOAD FLAGS(6); /* RW_ */
23665 #endif
23666+ text.init PT_LOAD FLAGS(5); /* R_E */
23667+ text.exit PT_LOAD FLAGS(5); /* R_E */
23668 init PT_LOAD FLAGS(7); /* RWE */
23669-#endif
23670 note PT_NOTE FLAGS(0); /* ___ */
23671 }
23672
23673 SECTIONS
23674 {
23675 #ifdef CONFIG_X86_32
23676- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23677- phys_startup_32 = startup_32 - LOAD_OFFSET;
23678+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23679 #else
23680- . = __START_KERNEL;
23681- phys_startup_64 = startup_64 - LOAD_OFFSET;
23682+ . = __START_KERNEL;
23683 #endif
23684
23685 /* Text and read-only data */
23686- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23687- _text = .;
23688+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23689 /* bootstrapping code */
23690+#ifdef CONFIG_X86_32
23691+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23692+#else
23693+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23694+#endif
23695+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23696+ _text = .;
23697 HEAD_TEXT
23698 #ifdef CONFIG_X86_32
23699 . = ALIGN(PAGE_SIZE);
23700@@ -108,13 +128,48 @@ SECTIONS
23701 IRQENTRY_TEXT
23702 *(.fixup)
23703 *(.gnu.warning)
23704- /* End of text section */
23705- _etext = .;
23706 } :text = 0x9090
23707
23708- NOTES :text :note
23709+ . += __KERNEL_TEXT_OFFSET;
23710
23711- EXCEPTION_TABLE(16) :text = 0x9090
23712+#ifdef CONFIG_X86_32
23713+ . = ALIGN(PAGE_SIZE);
23714+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23715+
23716+#ifdef CONFIG_PAX_KERNEXEC
23717+ MODULES_EXEC_VADDR = .;
23718+ BYTE(0)
23719+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23720+ . = ALIGN(HPAGE_SIZE) - 1;
23721+ MODULES_EXEC_END = .;
23722+#endif
23723+
23724+ } :module
23725+#endif
23726+
23727+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23728+ /* End of text section */
23729+ BYTE(0)
23730+ _etext = . - __KERNEL_TEXT_OFFSET;
23731+ }
23732+
23733+#ifdef CONFIG_X86_32
23734+ . = ALIGN(PAGE_SIZE);
23735+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23736+ *(.idt)
23737+ . = ALIGN(PAGE_SIZE);
23738+ *(.empty_zero_page)
23739+ *(.initial_pg_fixmap)
23740+ *(.initial_pg_pmd)
23741+ *(.initial_page_table)
23742+ *(.swapper_pg_dir)
23743+ } :rodata
23744+#endif
23745+
23746+ . = ALIGN(PAGE_SIZE);
23747+ NOTES :rodata :note
23748+
23749+ EXCEPTION_TABLE(16) :rodata
23750
23751 #if defined(CONFIG_DEBUG_RODATA)
23752 /* .text should occupy whole number of pages */
23753@@ -126,16 +181,20 @@ SECTIONS
23754
23755 /* Data */
23756 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23757+
23758+#ifdef CONFIG_PAX_KERNEXEC
23759+ . = ALIGN(HPAGE_SIZE);
23760+#else
23761+ . = ALIGN(PAGE_SIZE);
23762+#endif
23763+
23764 /* Start of data section */
23765 _sdata = .;
23766
23767 /* init_task */
23768 INIT_TASK_DATA(THREAD_SIZE)
23769
23770-#ifdef CONFIG_X86_32
23771- /* 32 bit has nosave before _edata */
23772 NOSAVE_DATA
23773-#endif
23774
23775 PAGE_ALIGNED_DATA(PAGE_SIZE)
23776
23777@@ -176,12 +235,19 @@ SECTIONS
23778 #endif /* CONFIG_X86_64 */
23779
23780 /* Init code and data - will be freed after init */
23781- . = ALIGN(PAGE_SIZE);
23782 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23783+ BYTE(0)
23784+
23785+#ifdef CONFIG_PAX_KERNEXEC
23786+ . = ALIGN(HPAGE_SIZE);
23787+#else
23788+ . = ALIGN(PAGE_SIZE);
23789+#endif
23790+
23791 __init_begin = .; /* paired with __init_end */
23792- }
23793+ } :init.begin
23794
23795-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23796+#ifdef CONFIG_SMP
23797 /*
23798 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23799 * output PHDR, so the next output section - .init.text - should
23800@@ -190,12 +256,27 @@ SECTIONS
23801 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23802 #endif
23803
23804- INIT_TEXT_SECTION(PAGE_SIZE)
23805-#ifdef CONFIG_X86_64
23806- :init
23807-#endif
23808+ . = ALIGN(PAGE_SIZE);
23809+ init_begin = .;
23810+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23811+ VMLINUX_SYMBOL(_sinittext) = .;
23812+ INIT_TEXT
23813+ VMLINUX_SYMBOL(_einittext) = .;
23814+ . = ALIGN(PAGE_SIZE);
23815+ } :text.init
23816
23817- INIT_DATA_SECTION(16)
23818+ /*
23819+ * .exit.text is discard at runtime, not link time, to deal with
23820+ * references from .altinstructions and .eh_frame
23821+ */
23822+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23823+ EXIT_TEXT
23824+ . = ALIGN(16);
23825+ } :text.exit
23826+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23827+
23828+ . = ALIGN(PAGE_SIZE);
23829+ INIT_DATA_SECTION(16) :init
23830
23831 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23832 __x86_cpu_dev_start = .;
23833@@ -257,19 +338,12 @@ SECTIONS
23834 }
23835
23836 . = ALIGN(8);
23837- /*
23838- * .exit.text is discard at runtime, not link time, to deal with
23839- * references from .altinstructions and .eh_frame
23840- */
23841- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23842- EXIT_TEXT
23843- }
23844
23845 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23846 EXIT_DATA
23847 }
23848
23849-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23850+#ifndef CONFIG_SMP
23851 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23852 #endif
23853
23854@@ -288,16 +362,10 @@ SECTIONS
23855 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23856 __smp_locks = .;
23857 *(.smp_locks)
23858- . = ALIGN(PAGE_SIZE);
23859 __smp_locks_end = .;
23860+ . = ALIGN(PAGE_SIZE);
23861 }
23862
23863-#ifdef CONFIG_X86_64
23864- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23865- NOSAVE_DATA
23866- }
23867-#endif
23868-
23869 /* BSS */
23870 . = ALIGN(PAGE_SIZE);
23871 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23872@@ -313,6 +381,7 @@ SECTIONS
23873 __brk_base = .;
23874 . += 64 * 1024; /* 64k alignment slop space */
23875 *(.brk_reservation) /* areas brk users have reserved */
23876+ . = ALIGN(HPAGE_SIZE);
23877 __brk_limit = .;
23878 }
23879
23880@@ -339,13 +408,12 @@ SECTIONS
23881 * for the boot processor.
23882 */
23883 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23884-INIT_PER_CPU(gdt_page);
23885 INIT_PER_CPU(irq_stack_union);
23886
23887 /*
23888 * Build-time check on the image size:
23889 */
23890-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23891+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23892 "kernel image bigger than KERNEL_IMAGE_SIZE");
23893
23894 #ifdef CONFIG_SMP
23895diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23896index 9a907a6..f83f921 100644
23897--- a/arch/x86/kernel/vsyscall_64.c
23898+++ b/arch/x86/kernel/vsyscall_64.c
23899@@ -56,15 +56,13 @@
23900 DEFINE_VVAR(int, vgetcpu_mode);
23901 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23902
23903-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23904+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23905
23906 static int __init vsyscall_setup(char *str)
23907 {
23908 if (str) {
23909 if (!strcmp("emulate", str))
23910 vsyscall_mode = EMULATE;
23911- else if (!strcmp("native", str))
23912- vsyscall_mode = NATIVE;
23913 else if (!strcmp("none", str))
23914 vsyscall_mode = NONE;
23915 else
23916@@ -323,8 +321,7 @@ do_ret:
23917 return true;
23918
23919 sigsegv:
23920- force_sig(SIGSEGV, current);
23921- return true;
23922+ do_group_exit(SIGKILL);
23923 }
23924
23925 /*
23926@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23927 extern char __vvar_page;
23928 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23929
23930- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23931- vsyscall_mode == NATIVE
23932- ? PAGE_KERNEL_VSYSCALL
23933- : PAGE_KERNEL_VVAR);
23934+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23935 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23936 (unsigned long)VSYSCALL_START);
23937
23938diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23939index b014d94..6d6ca7b 100644
23940--- a/arch/x86/kernel/x8664_ksyms_64.c
23941+++ b/arch/x86/kernel/x8664_ksyms_64.c
23942@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23943 EXPORT_SYMBOL(copy_user_generic_unrolled);
23944 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23945 EXPORT_SYMBOL(__copy_user_nocache);
23946-EXPORT_SYMBOL(_copy_from_user);
23947-EXPORT_SYMBOL(_copy_to_user);
23948
23949 EXPORT_SYMBOL(copy_page);
23950 EXPORT_SYMBOL(clear_page);
23951diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23952index 45a14db..075bb9b 100644
23953--- a/arch/x86/kernel/x86_init.c
23954+++ b/arch/x86/kernel/x86_init.c
23955@@ -85,7 +85,7 @@ struct x86_init_ops x86_init __initdata = {
23956 },
23957 };
23958
23959-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23960+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23961 .early_percpu_clock_init = x86_init_noop,
23962 .setup_percpu_clockev = setup_secondary_APIC_clock,
23963 };
23964@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23965 static void default_nmi_init(void) { };
23966 static int default_i8042_detect(void) { return 1; };
23967
23968-struct x86_platform_ops x86_platform = {
23969+struct x86_platform_ops x86_platform __read_only = {
23970 .calibrate_tsc = native_calibrate_tsc,
23971 .get_wallclock = mach_get_cmos_time,
23972 .set_wallclock = mach_set_rtc_mmss,
23973@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
23974 };
23975
23976 EXPORT_SYMBOL_GPL(x86_platform);
23977-struct x86_msi_ops x86_msi = {
23978+struct x86_msi_ops x86_msi __read_only = {
23979 .setup_msi_irqs = native_setup_msi_irqs,
23980 .compose_msi_msg = native_compose_msi_msg,
23981 .teardown_msi_irq = native_teardown_msi_irq,
23982@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
23983 .setup_hpet_msi = default_setup_hpet_msi,
23984 };
23985
23986-struct x86_io_apic_ops x86_io_apic_ops = {
23987+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23988 .init = native_io_apic_init_mappings,
23989 .read = native_io_apic_read,
23990 .write = native_io_apic_write,
23991diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23992index ada87a3..afea76d 100644
23993--- a/arch/x86/kernel/xsave.c
23994+++ b/arch/x86/kernel/xsave.c
23995@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23996 {
23997 int err;
23998
23999+ buf = (struct xsave_struct __user *)____m(buf);
24000 if (use_xsave())
24001 err = xsave_user(buf);
24002 else if (use_fxsr())
24003@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
24004 */
24005 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
24006 {
24007+ buf = (void __user *)____m(buf);
24008 if (use_xsave()) {
24009 if ((unsigned long)buf % 64 || fx_only) {
24010 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
24011diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
24012index a20ecb5..d0e2194 100644
24013--- a/arch/x86/kvm/cpuid.c
24014+++ b/arch/x86/kvm/cpuid.c
24015@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
24016 struct kvm_cpuid2 *cpuid,
24017 struct kvm_cpuid_entry2 __user *entries)
24018 {
24019- int r;
24020+ int r, i;
24021
24022 r = -E2BIG;
24023 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
24024 goto out;
24025 r = -EFAULT;
24026- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
24027- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24028+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24029 goto out;
24030+ for (i = 0; i < cpuid->nent; ++i) {
24031+ struct kvm_cpuid_entry2 cpuid_entry;
24032+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
24033+ goto out;
24034+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
24035+ }
24036 vcpu->arch.cpuid_nent = cpuid->nent;
24037 kvm_apic_set_version(vcpu);
24038 kvm_x86_ops->cpuid_update(vcpu);
24039@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
24040 struct kvm_cpuid2 *cpuid,
24041 struct kvm_cpuid_entry2 __user *entries)
24042 {
24043- int r;
24044+ int r, i;
24045
24046 r = -E2BIG;
24047 if (cpuid->nent < vcpu->arch.cpuid_nent)
24048 goto out;
24049 r = -EFAULT;
24050- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
24051- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24052+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24053 goto out;
24054+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
24055+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
24056+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
24057+ goto out;
24058+ }
24059 return 0;
24060
24061 out:
24062diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
24063index 698eece..776b682 100644
24064--- a/arch/x86/kvm/emulate.c
24065+++ b/arch/x86/kvm/emulate.c
24066@@ -328,6 +328,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24067
24068 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
24069 do { \
24070+ unsigned long _tmp; \
24071 __asm__ __volatile__ ( \
24072 _PRE_EFLAGS("0", "4", "2") \
24073 _op _suffix " %"_x"3,%1; " \
24074@@ -342,8 +343,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24075 /* Raw emulation: instruction has two explicit operands. */
24076 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
24077 do { \
24078- unsigned long _tmp; \
24079- \
24080 switch ((ctxt)->dst.bytes) { \
24081 case 2: \
24082 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
24083@@ -359,7 +358,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24084
24085 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
24086 do { \
24087- unsigned long _tmp; \
24088 switch ((ctxt)->dst.bytes) { \
24089 case 1: \
24090 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
24091diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
24092index f77df1c..6f20690 100644
24093--- a/arch/x86/kvm/lapic.c
24094+++ b/arch/x86/kvm/lapic.c
24095@@ -55,7 +55,7 @@
24096 #define APIC_BUS_CYCLE_NS 1
24097
24098 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
24099-#define apic_debug(fmt, arg...)
24100+#define apic_debug(fmt, arg...) do {} while (0)
24101
24102 #define APIC_LVT_NUM 6
24103 /* 14 is the version for Xeon and Pentium 8.4.8*/
24104diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
24105index 105dd5b..1b0ccc2 100644
24106--- a/arch/x86/kvm/paging_tmpl.h
24107+++ b/arch/x86/kvm/paging_tmpl.h
24108@@ -208,7 +208,7 @@ retry_walk:
24109 if (unlikely(kvm_is_error_hva(host_addr)))
24110 goto error;
24111
24112- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
24113+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
24114 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
24115 goto error;
24116 walker->ptep_user[walker->level - 1] = ptep_user;
24117diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
24118index e1b1ce2..f7b4b43 100644
24119--- a/arch/x86/kvm/svm.c
24120+++ b/arch/x86/kvm/svm.c
24121@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
24122 int cpu = raw_smp_processor_id();
24123
24124 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
24125+
24126+ pax_open_kernel();
24127 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
24128+ pax_close_kernel();
24129+
24130 load_TR_desc();
24131 }
24132
24133@@ -3901,6 +3905,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
24134 #endif
24135 #endif
24136
24137+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24138+ __set_fs(current_thread_info()->addr_limit);
24139+#endif
24140+
24141 reload_tss(vcpu);
24142
24143 local_irq_disable();
24144diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
24145index 0af1807..06912bb 100644
24146--- a/arch/x86/kvm/vmx.c
24147+++ b/arch/x86/kvm/vmx.c
24148@@ -1184,12 +1184,12 @@ static void vmcs_write64(unsigned long field, u64 value)
24149 #endif
24150 }
24151
24152-static void vmcs_clear_bits(unsigned long field, u32 mask)
24153+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
24154 {
24155 vmcs_writel(field, vmcs_readl(field) & ~mask);
24156 }
24157
24158-static void vmcs_set_bits(unsigned long field, u32 mask)
24159+static void vmcs_set_bits(unsigned long field, unsigned long mask)
24160 {
24161 vmcs_writel(field, vmcs_readl(field) | mask);
24162 }
24163@@ -1390,7 +1390,11 @@ static void reload_tss(void)
24164 struct desc_struct *descs;
24165
24166 descs = (void *)gdt->address;
24167+
24168+ pax_open_kernel();
24169 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
24170+ pax_close_kernel();
24171+
24172 load_TR_desc();
24173 }
24174
24175@@ -1614,6 +1618,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
24176 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
24177 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
24178
24179+#ifdef CONFIG_PAX_PER_CPU_PGD
24180+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24181+#endif
24182+
24183 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
24184 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
24185 vmx->loaded_vmcs->cpu = cpu;
24186@@ -2779,8 +2787,11 @@ static __init int hardware_setup(void)
24187 if (!cpu_has_vmx_flexpriority())
24188 flexpriority_enabled = 0;
24189
24190- if (!cpu_has_vmx_tpr_shadow())
24191- kvm_x86_ops->update_cr8_intercept = NULL;
24192+ if (!cpu_has_vmx_tpr_shadow()) {
24193+ pax_open_kernel();
24194+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24195+ pax_close_kernel();
24196+ }
24197
24198 if (enable_ept && !cpu_has_vmx_ept_2m_page())
24199 kvm_disable_largepages();
24200@@ -2792,10 +2803,12 @@ static __init int hardware_setup(void)
24201 !cpu_has_vmx_virtual_intr_delivery())
24202 enable_apicv_reg_vid = 0;
24203
24204+ pax_open_kernel();
24205 if (enable_apicv_reg_vid)
24206- kvm_x86_ops->update_cr8_intercept = NULL;
24207+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24208 else
24209- kvm_x86_ops->hwapic_irr_update = NULL;
24210+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
24211+ pax_close_kernel();
24212
24213 if (nested)
24214 nested_vmx_setup_ctls_msrs();
24215@@ -3883,7 +3896,10 @@ static void vmx_set_constant_host_state(void)
24216
24217 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
24218 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
24219+
24220+#ifndef CONFIG_PAX_PER_CPU_PGD
24221 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24222+#endif
24223
24224 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
24225 #ifdef CONFIG_X86_64
24226@@ -3904,7 +3920,7 @@ static void vmx_set_constant_host_state(void)
24227 native_store_idt(&dt);
24228 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
24229
24230- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
24231+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
24232
24233 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
24234 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
24235@@ -6580,6 +6596,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24236 "jmp 2f \n\t"
24237 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
24238 "2: "
24239+
24240+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24241+ "ljmp %[cs],$3f\n\t"
24242+ "3: "
24243+#endif
24244+
24245 /* Save guest registers, load host registers, keep flags */
24246 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
24247 "pop %0 \n\t"
24248@@ -6632,6 +6654,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24249 #endif
24250 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
24251 [wordsize]"i"(sizeof(ulong))
24252+
24253+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24254+ ,[cs]"i"(__KERNEL_CS)
24255+#endif
24256+
24257 : "cc", "memory"
24258 #ifdef CONFIG_X86_64
24259 , "rax", "rbx", "rdi", "rsi"
24260@@ -6645,7 +6672,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24261 if (debugctlmsr)
24262 update_debugctlmsr(debugctlmsr);
24263
24264-#ifndef CONFIG_X86_64
24265+#ifdef CONFIG_X86_32
24266 /*
24267 * The sysexit path does not restore ds/es, so we must set them to
24268 * a reasonable value ourselves.
24269@@ -6654,8 +6681,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24270 * may be executed in interrupt context, which saves and restore segments
24271 * around it, nullifying its effect.
24272 */
24273- loadsegment(ds, __USER_DS);
24274- loadsegment(es, __USER_DS);
24275+ loadsegment(ds, __KERNEL_DS);
24276+ loadsegment(es, __KERNEL_DS);
24277+ loadsegment(ss, __KERNEL_DS);
24278+
24279+#ifdef CONFIG_PAX_KERNEXEC
24280+ loadsegment(fs, __KERNEL_PERCPU);
24281+#endif
24282+
24283+#ifdef CONFIG_PAX_MEMORY_UDEREF
24284+ __set_fs(current_thread_info()->addr_limit);
24285+#endif
24286+
24287 #endif
24288
24289 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24290diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24291index 8563b45..272f1fe 100644
24292--- a/arch/x86/kvm/x86.c
24293+++ b/arch/x86/kvm/x86.c
24294@@ -1685,8 +1685,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24295 {
24296 struct kvm *kvm = vcpu->kvm;
24297 int lm = is_long_mode(vcpu);
24298- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24299- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24300+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24301+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24302 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24303 : kvm->arch.xen_hvm_config.blob_size_32;
24304 u32 page_num = data & ~PAGE_MASK;
24305@@ -2566,6 +2566,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24306 if (n < msr_list.nmsrs)
24307 goto out;
24308 r = -EFAULT;
24309+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24310+ goto out;
24311 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24312 num_msrs_to_save * sizeof(u32)))
24313 goto out;
24314@@ -2695,7 +2697,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
24315 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
24316 struct kvm_interrupt *irq)
24317 {
24318- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
24319+ if (irq->irq >= KVM_NR_INTERRUPTS)
24320 return -EINVAL;
24321 if (irqchip_in_kernel(vcpu->kvm))
24322 return -ENXIO;
24323@@ -5246,7 +5248,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24324 };
24325 #endif
24326
24327-int kvm_arch_init(void *opaque)
24328+int kvm_arch_init(const void *opaque)
24329 {
24330 int r;
24331 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24332diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24333index 7114c63..a1018fc 100644
24334--- a/arch/x86/lguest/boot.c
24335+++ b/arch/x86/lguest/boot.c
24336@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24337 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24338 * Launcher to reboot us.
24339 */
24340-static void lguest_restart(char *reason)
24341+static __noreturn void lguest_restart(char *reason)
24342 {
24343 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24344+ BUG();
24345 }
24346
24347 /*G:050
24348diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24349index 00933d5..3a64af9 100644
24350--- a/arch/x86/lib/atomic64_386_32.S
24351+++ b/arch/x86/lib/atomic64_386_32.S
24352@@ -48,6 +48,10 @@ BEGIN(read)
24353 movl (v), %eax
24354 movl 4(v), %edx
24355 RET_ENDP
24356+BEGIN(read_unchecked)
24357+ movl (v), %eax
24358+ movl 4(v), %edx
24359+RET_ENDP
24360 #undef v
24361
24362 #define v %esi
24363@@ -55,6 +59,10 @@ BEGIN(set)
24364 movl %ebx, (v)
24365 movl %ecx, 4(v)
24366 RET_ENDP
24367+BEGIN(set_unchecked)
24368+ movl %ebx, (v)
24369+ movl %ecx, 4(v)
24370+RET_ENDP
24371 #undef v
24372
24373 #define v %esi
24374@@ -70,6 +78,20 @@ RET_ENDP
24375 BEGIN(add)
24376 addl %eax, (v)
24377 adcl %edx, 4(v)
24378+
24379+#ifdef CONFIG_PAX_REFCOUNT
24380+ jno 0f
24381+ subl %eax, (v)
24382+ sbbl %edx, 4(v)
24383+ int $4
24384+0:
24385+ _ASM_EXTABLE(0b, 0b)
24386+#endif
24387+
24388+RET_ENDP
24389+BEGIN(add_unchecked)
24390+ addl %eax, (v)
24391+ adcl %edx, 4(v)
24392 RET_ENDP
24393 #undef v
24394
24395@@ -77,6 +99,24 @@ RET_ENDP
24396 BEGIN(add_return)
24397 addl (v), %eax
24398 adcl 4(v), %edx
24399+
24400+#ifdef CONFIG_PAX_REFCOUNT
24401+ into
24402+1234:
24403+ _ASM_EXTABLE(1234b, 2f)
24404+#endif
24405+
24406+ movl %eax, (v)
24407+ movl %edx, 4(v)
24408+
24409+#ifdef CONFIG_PAX_REFCOUNT
24410+2:
24411+#endif
24412+
24413+RET_ENDP
24414+BEGIN(add_return_unchecked)
24415+ addl (v), %eax
24416+ adcl 4(v), %edx
24417 movl %eax, (v)
24418 movl %edx, 4(v)
24419 RET_ENDP
24420@@ -86,6 +126,20 @@ RET_ENDP
24421 BEGIN(sub)
24422 subl %eax, (v)
24423 sbbl %edx, 4(v)
24424+
24425+#ifdef CONFIG_PAX_REFCOUNT
24426+ jno 0f
24427+ addl %eax, (v)
24428+ adcl %edx, 4(v)
24429+ int $4
24430+0:
24431+ _ASM_EXTABLE(0b, 0b)
24432+#endif
24433+
24434+RET_ENDP
24435+BEGIN(sub_unchecked)
24436+ subl %eax, (v)
24437+ sbbl %edx, 4(v)
24438 RET_ENDP
24439 #undef v
24440
24441@@ -96,6 +150,27 @@ BEGIN(sub_return)
24442 sbbl $0, %edx
24443 addl (v), %eax
24444 adcl 4(v), %edx
24445+
24446+#ifdef CONFIG_PAX_REFCOUNT
24447+ into
24448+1234:
24449+ _ASM_EXTABLE(1234b, 2f)
24450+#endif
24451+
24452+ movl %eax, (v)
24453+ movl %edx, 4(v)
24454+
24455+#ifdef CONFIG_PAX_REFCOUNT
24456+2:
24457+#endif
24458+
24459+RET_ENDP
24460+BEGIN(sub_return_unchecked)
24461+ negl %edx
24462+ negl %eax
24463+ sbbl $0, %edx
24464+ addl (v), %eax
24465+ adcl 4(v), %edx
24466 movl %eax, (v)
24467 movl %edx, 4(v)
24468 RET_ENDP
24469@@ -105,6 +180,20 @@ RET_ENDP
24470 BEGIN(inc)
24471 addl $1, (v)
24472 adcl $0, 4(v)
24473+
24474+#ifdef CONFIG_PAX_REFCOUNT
24475+ jno 0f
24476+ subl $1, (v)
24477+ sbbl $0, 4(v)
24478+ int $4
24479+0:
24480+ _ASM_EXTABLE(0b, 0b)
24481+#endif
24482+
24483+RET_ENDP
24484+BEGIN(inc_unchecked)
24485+ addl $1, (v)
24486+ adcl $0, 4(v)
24487 RET_ENDP
24488 #undef v
24489
24490@@ -114,6 +203,26 @@ BEGIN(inc_return)
24491 movl 4(v), %edx
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+
24504+#ifdef CONFIG_PAX_REFCOUNT
24505+2:
24506+#endif
24507+
24508+RET_ENDP
24509+BEGIN(inc_return_unchecked)
24510+ movl (v), %eax
24511+ movl 4(v), %edx
24512+ addl $1, %eax
24513+ adcl $0, %edx
24514 movl %eax, (v)
24515 movl %edx, 4(v)
24516 RET_ENDP
24517@@ -123,6 +232,20 @@ RET_ENDP
24518 BEGIN(dec)
24519 subl $1, (v)
24520 sbbl $0, 4(v)
24521+
24522+#ifdef CONFIG_PAX_REFCOUNT
24523+ jno 0f
24524+ addl $1, (v)
24525+ adcl $0, 4(v)
24526+ int $4
24527+0:
24528+ _ASM_EXTABLE(0b, 0b)
24529+#endif
24530+
24531+RET_ENDP
24532+BEGIN(dec_unchecked)
24533+ subl $1, (v)
24534+ sbbl $0, 4(v)
24535 RET_ENDP
24536 #undef v
24537
24538@@ -132,6 +255,26 @@ BEGIN(dec_return)
24539 movl 4(v), %edx
24540 subl $1, %eax
24541 sbbl $0, %edx
24542+
24543+#ifdef CONFIG_PAX_REFCOUNT
24544+ into
24545+1234:
24546+ _ASM_EXTABLE(1234b, 2f)
24547+#endif
24548+
24549+ movl %eax, (v)
24550+ movl %edx, 4(v)
24551+
24552+#ifdef CONFIG_PAX_REFCOUNT
24553+2:
24554+#endif
24555+
24556+RET_ENDP
24557+BEGIN(dec_return_unchecked)
24558+ movl (v), %eax
24559+ movl 4(v), %edx
24560+ subl $1, %eax
24561+ sbbl $0, %edx
24562 movl %eax, (v)
24563 movl %edx, 4(v)
24564 RET_ENDP
24565@@ -143,6 +286,13 @@ BEGIN(add_unless)
24566 adcl %edx, %edi
24567 addl (v), %eax
24568 adcl 4(v), %edx
24569+
24570+#ifdef CONFIG_PAX_REFCOUNT
24571+ into
24572+1234:
24573+ _ASM_EXTABLE(1234b, 2f)
24574+#endif
24575+
24576 cmpl %eax, %ecx
24577 je 3f
24578 1:
24579@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24580 1:
24581 addl $1, %eax
24582 adcl $0, %edx
24583+
24584+#ifdef CONFIG_PAX_REFCOUNT
24585+ into
24586+1234:
24587+ _ASM_EXTABLE(1234b, 2f)
24588+#endif
24589+
24590 movl %eax, (v)
24591 movl %edx, 4(v)
24592 movl $1, %eax
24593@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24594 movl 4(v), %edx
24595 subl $1, %eax
24596 sbbl $0, %edx
24597+
24598+#ifdef CONFIG_PAX_REFCOUNT
24599+ into
24600+1234:
24601+ _ASM_EXTABLE(1234b, 1f)
24602+#endif
24603+
24604 js 1f
24605 movl %eax, (v)
24606 movl %edx, 4(v)
24607diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24608index f5cc9eb..51fa319 100644
24609--- a/arch/x86/lib/atomic64_cx8_32.S
24610+++ b/arch/x86/lib/atomic64_cx8_32.S
24611@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24612 CFI_STARTPROC
24613
24614 read64 %ecx
24615+ pax_force_retaddr
24616 ret
24617 CFI_ENDPROC
24618 ENDPROC(atomic64_read_cx8)
24619
24620+ENTRY(atomic64_read_unchecked_cx8)
24621+ CFI_STARTPROC
24622+
24623+ read64 %ecx
24624+ pax_force_retaddr
24625+ ret
24626+ CFI_ENDPROC
24627+ENDPROC(atomic64_read_unchecked_cx8)
24628+
24629 ENTRY(atomic64_set_cx8)
24630 CFI_STARTPROC
24631
24632@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24633 cmpxchg8b (%esi)
24634 jne 1b
24635
24636+ pax_force_retaddr
24637 ret
24638 CFI_ENDPROC
24639 ENDPROC(atomic64_set_cx8)
24640
24641+ENTRY(atomic64_set_unchecked_cx8)
24642+ CFI_STARTPROC
24643+
24644+1:
24645+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24646+ * are atomic on 586 and newer */
24647+ cmpxchg8b (%esi)
24648+ jne 1b
24649+
24650+ pax_force_retaddr
24651+ ret
24652+ CFI_ENDPROC
24653+ENDPROC(atomic64_set_unchecked_cx8)
24654+
24655 ENTRY(atomic64_xchg_cx8)
24656 CFI_STARTPROC
24657
24658@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24659 cmpxchg8b (%esi)
24660 jne 1b
24661
24662+ pax_force_retaddr
24663 ret
24664 CFI_ENDPROC
24665 ENDPROC(atomic64_xchg_cx8)
24666
24667-.macro addsub_return func ins insc
24668-ENTRY(atomic64_\func\()_return_cx8)
24669+.macro addsub_return func ins insc unchecked=""
24670+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24671 CFI_STARTPROC
24672 SAVE ebp
24673 SAVE ebx
24674@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24675 movl %edx, %ecx
24676 \ins\()l %esi, %ebx
24677 \insc\()l %edi, %ecx
24678+
24679+.ifb \unchecked
24680+#ifdef CONFIG_PAX_REFCOUNT
24681+ into
24682+2:
24683+ _ASM_EXTABLE(2b, 3f)
24684+#endif
24685+.endif
24686+
24687 LOCK_PREFIX
24688 cmpxchg8b (%ebp)
24689 jne 1b
24690-
24691-10:
24692 movl %ebx, %eax
24693 movl %ecx, %edx
24694+
24695+.ifb \unchecked
24696+#ifdef CONFIG_PAX_REFCOUNT
24697+3:
24698+#endif
24699+.endif
24700+
24701 RESTORE edi
24702 RESTORE esi
24703 RESTORE ebx
24704 RESTORE ebp
24705+ pax_force_retaddr
24706 ret
24707 CFI_ENDPROC
24708-ENDPROC(atomic64_\func\()_return_cx8)
24709+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24710 .endm
24711
24712 addsub_return add add adc
24713 addsub_return sub sub sbb
24714+addsub_return add add adc _unchecked
24715+addsub_return sub sub sbb _unchecked
24716
24717-.macro incdec_return func ins insc
24718-ENTRY(atomic64_\func\()_return_cx8)
24719+.macro incdec_return func ins insc unchecked=""
24720+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24721 CFI_STARTPROC
24722 SAVE ebx
24723
24724@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24725 movl %edx, %ecx
24726 \ins\()l $1, %ebx
24727 \insc\()l $0, %ecx
24728+
24729+.ifb \unchecked
24730+#ifdef CONFIG_PAX_REFCOUNT
24731+ into
24732+2:
24733+ _ASM_EXTABLE(2b, 3f)
24734+#endif
24735+.endif
24736+
24737 LOCK_PREFIX
24738 cmpxchg8b (%esi)
24739 jne 1b
24740
24741-10:
24742 movl %ebx, %eax
24743 movl %ecx, %edx
24744+
24745+.ifb \unchecked
24746+#ifdef CONFIG_PAX_REFCOUNT
24747+3:
24748+#endif
24749+.endif
24750+
24751 RESTORE ebx
24752+ pax_force_retaddr
24753 ret
24754 CFI_ENDPROC
24755-ENDPROC(atomic64_\func\()_return_cx8)
24756+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24757 .endm
24758
24759 incdec_return inc add adc
24760 incdec_return dec sub sbb
24761+incdec_return inc add adc _unchecked
24762+incdec_return dec sub sbb _unchecked
24763
24764 ENTRY(atomic64_dec_if_positive_cx8)
24765 CFI_STARTPROC
24766@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24767 movl %edx, %ecx
24768 subl $1, %ebx
24769 sbb $0, %ecx
24770+
24771+#ifdef CONFIG_PAX_REFCOUNT
24772+ into
24773+1234:
24774+ _ASM_EXTABLE(1234b, 2f)
24775+#endif
24776+
24777 js 2f
24778 LOCK_PREFIX
24779 cmpxchg8b (%esi)
24780@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24781 movl %ebx, %eax
24782 movl %ecx, %edx
24783 RESTORE ebx
24784+ pax_force_retaddr
24785 ret
24786 CFI_ENDPROC
24787 ENDPROC(atomic64_dec_if_positive_cx8)
24788@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24789 movl %edx, %ecx
24790 addl %ebp, %ebx
24791 adcl %edi, %ecx
24792+
24793+#ifdef CONFIG_PAX_REFCOUNT
24794+ into
24795+1234:
24796+ _ASM_EXTABLE(1234b, 3f)
24797+#endif
24798+
24799 LOCK_PREFIX
24800 cmpxchg8b (%esi)
24801 jne 1b
24802@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24803 CFI_ADJUST_CFA_OFFSET -8
24804 RESTORE ebx
24805 RESTORE ebp
24806+ pax_force_retaddr
24807 ret
24808 4:
24809 cmpl %edx, 4(%esp)
24810@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24811 xorl %ecx, %ecx
24812 addl $1, %ebx
24813 adcl %edx, %ecx
24814+
24815+#ifdef CONFIG_PAX_REFCOUNT
24816+ into
24817+1234:
24818+ _ASM_EXTABLE(1234b, 3f)
24819+#endif
24820+
24821 LOCK_PREFIX
24822 cmpxchg8b (%esi)
24823 jne 1b
24824@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24825 movl $1, %eax
24826 3:
24827 RESTORE ebx
24828+ pax_force_retaddr
24829 ret
24830 CFI_ENDPROC
24831 ENDPROC(atomic64_inc_not_zero_cx8)
24832diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24833index 2af5df3..62b1a5a 100644
24834--- a/arch/x86/lib/checksum_32.S
24835+++ b/arch/x86/lib/checksum_32.S
24836@@ -29,7 +29,8 @@
24837 #include <asm/dwarf2.h>
24838 #include <asm/errno.h>
24839 #include <asm/asm.h>
24840-
24841+#include <asm/segment.h>
24842+
24843 /*
24844 * computes a partial checksum, e.g. for TCP/UDP fragments
24845 */
24846@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24847
24848 #define ARGBASE 16
24849 #define FP 12
24850-
24851-ENTRY(csum_partial_copy_generic)
24852+
24853+ENTRY(csum_partial_copy_generic_to_user)
24854 CFI_STARTPROC
24855+
24856+#ifdef CONFIG_PAX_MEMORY_UDEREF
24857+ pushl_cfi %gs
24858+ popl_cfi %es
24859+ jmp csum_partial_copy_generic
24860+#endif
24861+
24862+ENTRY(csum_partial_copy_generic_from_user)
24863+
24864+#ifdef CONFIG_PAX_MEMORY_UDEREF
24865+ pushl_cfi %gs
24866+ popl_cfi %ds
24867+#endif
24868+
24869+ENTRY(csum_partial_copy_generic)
24870 subl $4,%esp
24871 CFI_ADJUST_CFA_OFFSET 4
24872 pushl_cfi %edi
24873@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24874 jmp 4f
24875 SRC(1: movw (%esi), %bx )
24876 addl $2, %esi
24877-DST( movw %bx, (%edi) )
24878+DST( movw %bx, %es:(%edi) )
24879 addl $2, %edi
24880 addw %bx, %ax
24881 adcl $0, %eax
24882@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24883 SRC(1: movl (%esi), %ebx )
24884 SRC( movl 4(%esi), %edx )
24885 adcl %ebx, %eax
24886-DST( movl %ebx, (%edi) )
24887+DST( movl %ebx, %es:(%edi) )
24888 adcl %edx, %eax
24889-DST( movl %edx, 4(%edi) )
24890+DST( movl %edx, %es:4(%edi) )
24891
24892 SRC( movl 8(%esi), %ebx )
24893 SRC( movl 12(%esi), %edx )
24894 adcl %ebx, %eax
24895-DST( movl %ebx, 8(%edi) )
24896+DST( movl %ebx, %es:8(%edi) )
24897 adcl %edx, %eax
24898-DST( movl %edx, 12(%edi) )
24899+DST( movl %edx, %es:12(%edi) )
24900
24901 SRC( movl 16(%esi), %ebx )
24902 SRC( movl 20(%esi), %edx )
24903 adcl %ebx, %eax
24904-DST( movl %ebx, 16(%edi) )
24905+DST( movl %ebx, %es:16(%edi) )
24906 adcl %edx, %eax
24907-DST( movl %edx, 20(%edi) )
24908+DST( movl %edx, %es:20(%edi) )
24909
24910 SRC( movl 24(%esi), %ebx )
24911 SRC( movl 28(%esi), %edx )
24912 adcl %ebx, %eax
24913-DST( movl %ebx, 24(%edi) )
24914+DST( movl %ebx, %es:24(%edi) )
24915 adcl %edx, %eax
24916-DST( movl %edx, 28(%edi) )
24917+DST( movl %edx, %es:28(%edi) )
24918
24919 lea 32(%esi), %esi
24920 lea 32(%edi), %edi
24921@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24922 shrl $2, %edx # This clears CF
24923 SRC(3: movl (%esi), %ebx )
24924 adcl %ebx, %eax
24925-DST( movl %ebx, (%edi) )
24926+DST( movl %ebx, %es:(%edi) )
24927 lea 4(%esi), %esi
24928 lea 4(%edi), %edi
24929 dec %edx
24930@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24931 jb 5f
24932 SRC( movw (%esi), %cx )
24933 leal 2(%esi), %esi
24934-DST( movw %cx, (%edi) )
24935+DST( movw %cx, %es:(%edi) )
24936 leal 2(%edi), %edi
24937 je 6f
24938 shll $16,%ecx
24939 SRC(5: movb (%esi), %cl )
24940-DST( movb %cl, (%edi) )
24941+DST( movb %cl, %es:(%edi) )
24942 6: addl %ecx, %eax
24943 adcl $0, %eax
24944 7:
24945@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24946
24947 6001:
24948 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24949- movl $-EFAULT, (%ebx)
24950+ movl $-EFAULT, %ss:(%ebx)
24951
24952 # zero the complete destination - computing the rest
24953 # is too much work
24954@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24955
24956 6002:
24957 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24958- movl $-EFAULT,(%ebx)
24959+ movl $-EFAULT,%ss:(%ebx)
24960 jmp 5000b
24961
24962 .previous
24963
24964+ pushl_cfi %ss
24965+ popl_cfi %ds
24966+ pushl_cfi %ss
24967+ popl_cfi %es
24968 popl_cfi %ebx
24969 CFI_RESTORE ebx
24970 popl_cfi %esi
24971@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24972 popl_cfi %ecx # equivalent to addl $4,%esp
24973 ret
24974 CFI_ENDPROC
24975-ENDPROC(csum_partial_copy_generic)
24976+ENDPROC(csum_partial_copy_generic_to_user)
24977
24978 #else
24979
24980 /* Version for PentiumII/PPro */
24981
24982 #define ROUND1(x) \
24983+ nop; nop; nop; \
24984 SRC(movl x(%esi), %ebx ) ; \
24985 addl %ebx, %eax ; \
24986- DST(movl %ebx, x(%edi) ) ;
24987+ DST(movl %ebx, %es:x(%edi)) ;
24988
24989 #define ROUND(x) \
24990+ nop; nop; nop; \
24991 SRC(movl x(%esi), %ebx ) ; \
24992 adcl %ebx, %eax ; \
24993- DST(movl %ebx, x(%edi) ) ;
24994+ DST(movl %ebx, %es:x(%edi)) ;
24995
24996 #define ARGBASE 12
24997-
24998-ENTRY(csum_partial_copy_generic)
24999+
25000+ENTRY(csum_partial_copy_generic_to_user)
25001 CFI_STARTPROC
25002+
25003+#ifdef CONFIG_PAX_MEMORY_UDEREF
25004+ pushl_cfi %gs
25005+ popl_cfi %es
25006+ jmp csum_partial_copy_generic
25007+#endif
25008+
25009+ENTRY(csum_partial_copy_generic_from_user)
25010+
25011+#ifdef CONFIG_PAX_MEMORY_UDEREF
25012+ pushl_cfi %gs
25013+ popl_cfi %ds
25014+#endif
25015+
25016+ENTRY(csum_partial_copy_generic)
25017 pushl_cfi %ebx
25018 CFI_REL_OFFSET ebx, 0
25019 pushl_cfi %edi
25020@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
25021 subl %ebx, %edi
25022 lea -1(%esi),%edx
25023 andl $-32,%edx
25024- lea 3f(%ebx,%ebx), %ebx
25025+ lea 3f(%ebx,%ebx,2), %ebx
25026 testl %esi, %esi
25027 jmp *%ebx
25028 1: addl $64,%esi
25029@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
25030 jb 5f
25031 SRC( movw (%esi), %dx )
25032 leal 2(%esi), %esi
25033-DST( movw %dx, (%edi) )
25034+DST( movw %dx, %es:(%edi) )
25035 leal 2(%edi), %edi
25036 je 6f
25037 shll $16,%edx
25038 5:
25039 SRC( movb (%esi), %dl )
25040-DST( movb %dl, (%edi) )
25041+DST( movb %dl, %es:(%edi) )
25042 6: addl %edx, %eax
25043 adcl $0, %eax
25044 7:
25045 .section .fixup, "ax"
25046 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
25047- movl $-EFAULT, (%ebx)
25048+ movl $-EFAULT, %ss:(%ebx)
25049 # zero the complete destination (computing the rest is too much work)
25050 movl ARGBASE+8(%esp),%edi # dst
25051 movl ARGBASE+12(%esp),%ecx # len
25052@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
25053 rep; stosb
25054 jmp 7b
25055 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25056- movl $-EFAULT, (%ebx)
25057+ movl $-EFAULT, %ss:(%ebx)
25058 jmp 7b
25059 .previous
25060
25061+#ifdef CONFIG_PAX_MEMORY_UDEREF
25062+ pushl_cfi %ss
25063+ popl_cfi %ds
25064+ pushl_cfi %ss
25065+ popl_cfi %es
25066+#endif
25067+
25068 popl_cfi %esi
25069 CFI_RESTORE esi
25070 popl_cfi %edi
25071@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
25072 CFI_RESTORE ebx
25073 ret
25074 CFI_ENDPROC
25075-ENDPROC(csum_partial_copy_generic)
25076+ENDPROC(csum_partial_copy_generic_to_user)
25077
25078 #undef ROUND
25079 #undef ROUND1
25080diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
25081index f2145cf..cea889d 100644
25082--- a/arch/x86/lib/clear_page_64.S
25083+++ b/arch/x86/lib/clear_page_64.S
25084@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
25085 movl $4096/8,%ecx
25086 xorl %eax,%eax
25087 rep stosq
25088+ pax_force_retaddr
25089 ret
25090 CFI_ENDPROC
25091 ENDPROC(clear_page_c)
25092@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
25093 movl $4096,%ecx
25094 xorl %eax,%eax
25095 rep stosb
25096+ pax_force_retaddr
25097 ret
25098 CFI_ENDPROC
25099 ENDPROC(clear_page_c_e)
25100@@ -43,6 +45,7 @@ ENTRY(clear_page)
25101 leaq 64(%rdi),%rdi
25102 jnz .Lloop
25103 nop
25104+ pax_force_retaddr
25105 ret
25106 CFI_ENDPROC
25107 .Lclear_page_end:
25108@@ -58,7 +61,7 @@ ENDPROC(clear_page)
25109
25110 #include <asm/cpufeature.h>
25111
25112- .section .altinstr_replacement,"ax"
25113+ .section .altinstr_replacement,"a"
25114 1: .byte 0xeb /* jmp <disp8> */
25115 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
25116 2: .byte 0xeb /* jmp <disp8> */
25117diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
25118index 1e572c5..2a162cd 100644
25119--- a/arch/x86/lib/cmpxchg16b_emu.S
25120+++ b/arch/x86/lib/cmpxchg16b_emu.S
25121@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
25122
25123 popf
25124 mov $1, %al
25125+ pax_force_retaddr
25126 ret
25127
25128 not_same:
25129 popf
25130 xor %al,%al
25131+ pax_force_retaddr
25132 ret
25133
25134 CFI_ENDPROC
25135diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
25136index 176cca6..1166c50 100644
25137--- a/arch/x86/lib/copy_page_64.S
25138+++ b/arch/x86/lib/copy_page_64.S
25139@@ -9,6 +9,7 @@ copy_page_rep:
25140 CFI_STARTPROC
25141 movl $4096/8, %ecx
25142 rep movsq
25143+ pax_force_retaddr
25144 ret
25145 CFI_ENDPROC
25146 ENDPROC(copy_page_rep)
25147@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
25148
25149 ENTRY(copy_page)
25150 CFI_STARTPROC
25151- subq $2*8, %rsp
25152- CFI_ADJUST_CFA_OFFSET 2*8
25153+ subq $3*8, %rsp
25154+ CFI_ADJUST_CFA_OFFSET 3*8
25155 movq %rbx, (%rsp)
25156 CFI_REL_OFFSET rbx, 0
25157 movq %r12, 1*8(%rsp)
25158 CFI_REL_OFFSET r12, 1*8
25159+ movq %r13, 2*8(%rsp)
25160+ CFI_REL_OFFSET r13, 2*8
25161
25162 movl $(4096/64)-5, %ecx
25163 .p2align 4
25164@@ -36,7 +39,7 @@ ENTRY(copy_page)
25165 movq 0x8*2(%rsi), %rdx
25166 movq 0x8*3(%rsi), %r8
25167 movq 0x8*4(%rsi), %r9
25168- movq 0x8*5(%rsi), %r10
25169+ movq 0x8*5(%rsi), %r13
25170 movq 0x8*6(%rsi), %r11
25171 movq 0x8*7(%rsi), %r12
25172
25173@@ -47,7 +50,7 @@ ENTRY(copy_page)
25174 movq %rdx, 0x8*2(%rdi)
25175 movq %r8, 0x8*3(%rdi)
25176 movq %r9, 0x8*4(%rdi)
25177- movq %r10, 0x8*5(%rdi)
25178+ movq %r13, 0x8*5(%rdi)
25179 movq %r11, 0x8*6(%rdi)
25180 movq %r12, 0x8*7(%rdi)
25181
25182@@ -66,7 +69,7 @@ ENTRY(copy_page)
25183 movq 0x8*2(%rsi), %rdx
25184 movq 0x8*3(%rsi), %r8
25185 movq 0x8*4(%rsi), %r9
25186- movq 0x8*5(%rsi), %r10
25187+ movq 0x8*5(%rsi), %r13
25188 movq 0x8*6(%rsi), %r11
25189 movq 0x8*7(%rsi), %r12
25190
25191@@ -75,7 +78,7 @@ ENTRY(copy_page)
25192 movq %rdx, 0x8*2(%rdi)
25193 movq %r8, 0x8*3(%rdi)
25194 movq %r9, 0x8*4(%rdi)
25195- movq %r10, 0x8*5(%rdi)
25196+ movq %r13, 0x8*5(%rdi)
25197 movq %r11, 0x8*6(%rdi)
25198 movq %r12, 0x8*7(%rdi)
25199
25200@@ -87,8 +90,11 @@ ENTRY(copy_page)
25201 CFI_RESTORE rbx
25202 movq 1*8(%rsp), %r12
25203 CFI_RESTORE r12
25204- addq $2*8, %rsp
25205- CFI_ADJUST_CFA_OFFSET -2*8
25206+ movq 2*8(%rsp), %r13
25207+ CFI_RESTORE r13
25208+ addq $3*8, %rsp
25209+ CFI_ADJUST_CFA_OFFSET -3*8
25210+ pax_force_retaddr
25211 ret
25212 .Lcopy_page_end:
25213 CFI_ENDPROC
25214@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25215
25216 #include <asm/cpufeature.h>
25217
25218- .section .altinstr_replacement,"ax"
25219+ .section .altinstr_replacement,"a"
25220 1: .byte 0xeb /* jmp <disp8> */
25221 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25222 2:
25223diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25224index a30ca15..d25fab6 100644
25225--- a/arch/x86/lib/copy_user_64.S
25226+++ b/arch/x86/lib/copy_user_64.S
25227@@ -18,6 +18,7 @@
25228 #include <asm/alternative-asm.h>
25229 #include <asm/asm.h>
25230 #include <asm/smap.h>
25231+#include <asm/pgtable.h>
25232
25233 /*
25234 * By placing feature2 after feature1 in altinstructions section, we logically
25235@@ -31,7 +32,7 @@
25236 .byte 0xe9 /* 32bit jump */
25237 .long \orig-1f /* by default jump to orig */
25238 1:
25239- .section .altinstr_replacement,"ax"
25240+ .section .altinstr_replacement,"a"
25241 2: .byte 0xe9 /* near jump with 32bit immediate */
25242 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25243 3: .byte 0xe9 /* near jump with 32bit immediate */
25244@@ -70,47 +71,20 @@
25245 #endif
25246 .endm
25247
25248-/* Standard copy_to_user with segment limit checking */
25249-ENTRY(_copy_to_user)
25250- CFI_STARTPROC
25251- GET_THREAD_INFO(%rax)
25252- movq %rdi,%rcx
25253- addq %rdx,%rcx
25254- jc bad_to_user
25255- cmpq TI_addr_limit(%rax),%rcx
25256- ja bad_to_user
25257- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25258- copy_user_generic_unrolled,copy_user_generic_string, \
25259- copy_user_enhanced_fast_string
25260- CFI_ENDPROC
25261-ENDPROC(_copy_to_user)
25262-
25263-/* Standard copy_from_user with segment limit checking */
25264-ENTRY(_copy_from_user)
25265- CFI_STARTPROC
25266- GET_THREAD_INFO(%rax)
25267- movq %rsi,%rcx
25268- addq %rdx,%rcx
25269- jc bad_from_user
25270- cmpq TI_addr_limit(%rax),%rcx
25271- ja bad_from_user
25272- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25273- copy_user_generic_unrolled,copy_user_generic_string, \
25274- copy_user_enhanced_fast_string
25275- CFI_ENDPROC
25276-ENDPROC(_copy_from_user)
25277-
25278 .section .fixup,"ax"
25279 /* must zero dest */
25280 ENTRY(bad_from_user)
25281 bad_from_user:
25282 CFI_STARTPROC
25283+ testl %edx,%edx
25284+ js bad_to_user
25285 movl %edx,%ecx
25286 xorl %eax,%eax
25287 rep
25288 stosb
25289 bad_to_user:
25290 movl %edx,%eax
25291+ pax_force_retaddr
25292 ret
25293 CFI_ENDPROC
25294 ENDPROC(bad_from_user)
25295@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25296 jz 17f
25297 1: movq (%rsi),%r8
25298 2: movq 1*8(%rsi),%r9
25299-3: movq 2*8(%rsi),%r10
25300+3: movq 2*8(%rsi),%rax
25301 4: movq 3*8(%rsi),%r11
25302 5: movq %r8,(%rdi)
25303 6: movq %r9,1*8(%rdi)
25304-7: movq %r10,2*8(%rdi)
25305+7: movq %rax,2*8(%rdi)
25306 8: movq %r11,3*8(%rdi)
25307 9: movq 4*8(%rsi),%r8
25308 10: movq 5*8(%rsi),%r9
25309-11: movq 6*8(%rsi),%r10
25310+11: movq 6*8(%rsi),%rax
25311 12: movq 7*8(%rsi),%r11
25312 13: movq %r8,4*8(%rdi)
25313 14: movq %r9,5*8(%rdi)
25314-15: movq %r10,6*8(%rdi)
25315+15: movq %rax,6*8(%rdi)
25316 16: movq %r11,7*8(%rdi)
25317 leaq 64(%rsi),%rsi
25318 leaq 64(%rdi),%rdi
25319@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25320 jnz 21b
25321 23: xor %eax,%eax
25322 ASM_CLAC
25323+ pax_force_retaddr
25324 ret
25325
25326 .section .fixup,"ax"
25327@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25328 movsb
25329 4: xorl %eax,%eax
25330 ASM_CLAC
25331+ pax_force_retaddr
25332 ret
25333
25334 .section .fixup,"ax"
25335@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25336 movsb
25337 2: xorl %eax,%eax
25338 ASM_CLAC
25339+ pax_force_retaddr
25340 ret
25341
25342 .section .fixup,"ax"
25343diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25344index 6a4f43c..f08b4a2 100644
25345--- a/arch/x86/lib/copy_user_nocache_64.S
25346+++ b/arch/x86/lib/copy_user_nocache_64.S
25347@@ -8,6 +8,7 @@
25348
25349 #include <linux/linkage.h>
25350 #include <asm/dwarf2.h>
25351+#include <asm/alternative-asm.h>
25352
25353 #define FIX_ALIGNMENT 1
25354
25355@@ -16,6 +17,7 @@
25356 #include <asm/thread_info.h>
25357 #include <asm/asm.h>
25358 #include <asm/smap.h>
25359+#include <asm/pgtable.h>
25360
25361 .macro ALIGN_DESTINATION
25362 #ifdef FIX_ALIGNMENT
25363@@ -49,6 +51,15 @@
25364 */
25365 ENTRY(__copy_user_nocache)
25366 CFI_STARTPROC
25367+
25368+#ifdef CONFIG_PAX_MEMORY_UDEREF
25369+ mov pax_user_shadow_base,%rcx
25370+ cmp %rcx,%rsi
25371+ jae 1f
25372+ add %rcx,%rsi
25373+1:
25374+#endif
25375+
25376 ASM_STAC
25377 cmpl $8,%edx
25378 jb 20f /* less then 8 bytes, go to byte copy loop */
25379@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25380 jz 17f
25381 1: movq (%rsi),%r8
25382 2: movq 1*8(%rsi),%r9
25383-3: movq 2*8(%rsi),%r10
25384+3: movq 2*8(%rsi),%rax
25385 4: movq 3*8(%rsi),%r11
25386 5: movnti %r8,(%rdi)
25387 6: movnti %r9,1*8(%rdi)
25388-7: movnti %r10,2*8(%rdi)
25389+7: movnti %rax,2*8(%rdi)
25390 8: movnti %r11,3*8(%rdi)
25391 9: movq 4*8(%rsi),%r8
25392 10: movq 5*8(%rsi),%r9
25393-11: movq 6*8(%rsi),%r10
25394+11: movq 6*8(%rsi),%rax
25395 12: movq 7*8(%rsi),%r11
25396 13: movnti %r8,4*8(%rdi)
25397 14: movnti %r9,5*8(%rdi)
25398-15: movnti %r10,6*8(%rdi)
25399+15: movnti %rax,6*8(%rdi)
25400 16: movnti %r11,7*8(%rdi)
25401 leaq 64(%rsi),%rsi
25402 leaq 64(%rdi),%rdi
25403@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25404 23: xorl %eax,%eax
25405 ASM_CLAC
25406 sfence
25407+ pax_force_retaddr
25408 ret
25409
25410 .section .fixup,"ax"
25411diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25412index 2419d5f..953ee51 100644
25413--- a/arch/x86/lib/csum-copy_64.S
25414+++ b/arch/x86/lib/csum-copy_64.S
25415@@ -9,6 +9,7 @@
25416 #include <asm/dwarf2.h>
25417 #include <asm/errno.h>
25418 #include <asm/asm.h>
25419+#include <asm/alternative-asm.h>
25420
25421 /*
25422 * Checksum copy with exception handling.
25423@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25424 CFI_RESTORE rbp
25425 addq $7*8, %rsp
25426 CFI_ADJUST_CFA_OFFSET -7*8
25427+ pax_force_retaddr 0, 1
25428 ret
25429 CFI_RESTORE_STATE
25430
25431diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25432index 25b7ae8..169fafc 100644
25433--- a/arch/x86/lib/csum-wrappers_64.c
25434+++ b/arch/x86/lib/csum-wrappers_64.c
25435@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25436 len -= 2;
25437 }
25438 }
25439- isum = csum_partial_copy_generic((__force const void *)src,
25440+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25441 dst, len, isum, errp, NULL);
25442 if (unlikely(*errp))
25443 goto out_err;
25444@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25445 }
25446
25447 *errp = 0;
25448- return csum_partial_copy_generic(src, (void __force *)dst,
25449+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25450 len, isum, NULL, errp);
25451 }
25452 EXPORT_SYMBOL(csum_partial_copy_to_user);
25453diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25454index a451235..79fb5cf 100644
25455--- a/arch/x86/lib/getuser.S
25456+++ b/arch/x86/lib/getuser.S
25457@@ -33,17 +33,40 @@
25458 #include <asm/thread_info.h>
25459 #include <asm/asm.h>
25460 #include <asm/smap.h>
25461+#include <asm/segment.h>
25462+#include <asm/pgtable.h>
25463+#include <asm/alternative-asm.h>
25464+
25465+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25466+#define __copyuser_seg gs;
25467+#else
25468+#define __copyuser_seg
25469+#endif
25470
25471 .text
25472 ENTRY(__get_user_1)
25473 CFI_STARTPROC
25474+
25475+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25476 GET_THREAD_INFO(%_ASM_DX)
25477 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25478 jae bad_get_user
25479 ASM_STAC
25480-1: movzbl (%_ASM_AX),%edx
25481+
25482+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25483+ mov pax_user_shadow_base,%_ASM_DX
25484+ cmp %_ASM_DX,%_ASM_AX
25485+ jae 1234f
25486+ add %_ASM_DX,%_ASM_AX
25487+1234:
25488+#endif
25489+
25490+#endif
25491+
25492+1: __copyuser_seg movzbl (%_ASM_AX),%edx
25493 xor %eax,%eax
25494 ASM_CLAC
25495+ pax_force_retaddr
25496 ret
25497 CFI_ENDPROC
25498 ENDPROC(__get_user_1)
25499@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
25500 ENTRY(__get_user_2)
25501 CFI_STARTPROC
25502 add $1,%_ASM_AX
25503+
25504+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25505 jc bad_get_user
25506 GET_THREAD_INFO(%_ASM_DX)
25507 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25508 jae bad_get_user
25509 ASM_STAC
25510-2: movzwl -1(%_ASM_AX),%edx
25511+
25512+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25513+ mov pax_user_shadow_base,%_ASM_DX
25514+ cmp %_ASM_DX,%_ASM_AX
25515+ jae 1234f
25516+ add %_ASM_DX,%_ASM_AX
25517+1234:
25518+#endif
25519+
25520+#endif
25521+
25522+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25523 xor %eax,%eax
25524 ASM_CLAC
25525+ pax_force_retaddr
25526 ret
25527 CFI_ENDPROC
25528 ENDPROC(__get_user_2)
25529@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
25530 ENTRY(__get_user_4)
25531 CFI_STARTPROC
25532 add $3,%_ASM_AX
25533+
25534+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25535 jc bad_get_user
25536 GET_THREAD_INFO(%_ASM_DX)
25537 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25538 jae bad_get_user
25539 ASM_STAC
25540-3: movl -3(%_ASM_AX),%edx
25541+
25542+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25543+ mov pax_user_shadow_base,%_ASM_DX
25544+ cmp %_ASM_DX,%_ASM_AX
25545+ jae 1234f
25546+ add %_ASM_DX,%_ASM_AX
25547+1234:
25548+#endif
25549+
25550+#endif
25551+
25552+3: __copyuser_seg movl -3(%_ASM_AX),%edx
25553 xor %eax,%eax
25554 ASM_CLAC
25555+ pax_force_retaddr
25556 ret
25557 CFI_ENDPROC
25558 ENDPROC(__get_user_4)
25559@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
25560 GET_THREAD_INFO(%_ASM_DX)
25561 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25562 jae bad_get_user
25563+
25564+#ifdef CONFIG_PAX_MEMORY_UDEREF
25565+ mov pax_user_shadow_base,%_ASM_DX
25566+ cmp %_ASM_DX,%_ASM_AX
25567+ jae 1234f
25568+ add %_ASM_DX,%_ASM_AX
25569+1234:
25570+#endif
25571+
25572 ASM_STAC
25573 4: movq -7(%_ASM_AX),%rdx
25574 xor %eax,%eax
25575 ASM_CLAC
25576+ pax_force_retaddr
25577 ret
25578 #else
25579 add $7,%_ASM_AX
25580@@ -102,6 +163,7 @@ ENTRY(__get_user_8)
25581 5: movl -3(%_ASM_AX),%ecx
25582 xor %eax,%eax
25583 ASM_CLAC
25584+ pax_force_retaddr
25585 ret
25586 #endif
25587 CFI_ENDPROC
25588@@ -113,6 +175,7 @@ bad_get_user:
25589 xor %edx,%edx
25590 mov $(-EFAULT),%_ASM_AX
25591 ASM_CLAC
25592+ pax_force_retaddr
25593 ret
25594 CFI_ENDPROC
25595 END(bad_get_user)
25596@@ -124,6 +187,7 @@ bad_get_user_8:
25597 xor %ecx,%ecx
25598 mov $(-EFAULT),%_ASM_AX
25599 ASM_CLAC
25600+ pax_force_retaddr
25601 ret
25602 CFI_ENDPROC
25603 END(bad_get_user_8)
25604diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25605index 54fcffe..7be149e 100644
25606--- a/arch/x86/lib/insn.c
25607+++ b/arch/x86/lib/insn.c
25608@@ -20,8 +20,10 @@
25609
25610 #ifdef __KERNEL__
25611 #include <linux/string.h>
25612+#include <asm/pgtable_types.h>
25613 #else
25614 #include <string.h>
25615+#define ktla_ktva(addr) addr
25616 #endif
25617 #include <asm/inat.h>
25618 #include <asm/insn.h>
25619@@ -53,8 +55,8 @@
25620 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25621 {
25622 memset(insn, 0, sizeof(*insn));
25623- insn->kaddr = kaddr;
25624- insn->next_byte = kaddr;
25625+ insn->kaddr = ktla_ktva(kaddr);
25626+ insn->next_byte = ktla_ktva(kaddr);
25627 insn->x86_64 = x86_64 ? 1 : 0;
25628 insn->opnd_bytes = 4;
25629 if (x86_64)
25630diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25631index 05a95e7..326f2fa 100644
25632--- a/arch/x86/lib/iomap_copy_64.S
25633+++ b/arch/x86/lib/iomap_copy_64.S
25634@@ -17,6 +17,7 @@
25635
25636 #include <linux/linkage.h>
25637 #include <asm/dwarf2.h>
25638+#include <asm/alternative-asm.h>
25639
25640 /*
25641 * override generic version in lib/iomap_copy.c
25642@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25643 CFI_STARTPROC
25644 movl %edx,%ecx
25645 rep movsd
25646+ pax_force_retaddr
25647 ret
25648 CFI_ENDPROC
25649 ENDPROC(__iowrite32_copy)
25650diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25651index 1c273be..da9cc0e 100644
25652--- a/arch/x86/lib/memcpy_64.S
25653+++ b/arch/x86/lib/memcpy_64.S
25654@@ -33,6 +33,7 @@
25655 rep movsq
25656 movl %edx, %ecx
25657 rep movsb
25658+ pax_force_retaddr
25659 ret
25660 .Lmemcpy_e:
25661 .previous
25662@@ -49,6 +50,7 @@
25663 movq %rdi, %rax
25664 movq %rdx, %rcx
25665 rep movsb
25666+ pax_force_retaddr
25667 ret
25668 .Lmemcpy_e_e:
25669 .previous
25670@@ -76,13 +78,13 @@ ENTRY(memcpy)
25671 */
25672 movq 0*8(%rsi), %r8
25673 movq 1*8(%rsi), %r9
25674- movq 2*8(%rsi), %r10
25675+ movq 2*8(%rsi), %rcx
25676 movq 3*8(%rsi), %r11
25677 leaq 4*8(%rsi), %rsi
25678
25679 movq %r8, 0*8(%rdi)
25680 movq %r9, 1*8(%rdi)
25681- movq %r10, 2*8(%rdi)
25682+ movq %rcx, 2*8(%rdi)
25683 movq %r11, 3*8(%rdi)
25684 leaq 4*8(%rdi), %rdi
25685 jae .Lcopy_forward_loop
25686@@ -105,12 +107,12 @@ ENTRY(memcpy)
25687 subq $0x20, %rdx
25688 movq -1*8(%rsi), %r8
25689 movq -2*8(%rsi), %r9
25690- movq -3*8(%rsi), %r10
25691+ movq -3*8(%rsi), %rcx
25692 movq -4*8(%rsi), %r11
25693 leaq -4*8(%rsi), %rsi
25694 movq %r8, -1*8(%rdi)
25695 movq %r9, -2*8(%rdi)
25696- movq %r10, -3*8(%rdi)
25697+ movq %rcx, -3*8(%rdi)
25698 movq %r11, -4*8(%rdi)
25699 leaq -4*8(%rdi), %rdi
25700 jae .Lcopy_backward_loop
25701@@ -130,12 +132,13 @@ ENTRY(memcpy)
25702 */
25703 movq 0*8(%rsi), %r8
25704 movq 1*8(%rsi), %r9
25705- movq -2*8(%rsi, %rdx), %r10
25706+ movq -2*8(%rsi, %rdx), %rcx
25707 movq -1*8(%rsi, %rdx), %r11
25708 movq %r8, 0*8(%rdi)
25709 movq %r9, 1*8(%rdi)
25710- movq %r10, -2*8(%rdi, %rdx)
25711+ movq %rcx, -2*8(%rdi, %rdx)
25712 movq %r11, -1*8(%rdi, %rdx)
25713+ pax_force_retaddr
25714 retq
25715 .p2align 4
25716 .Lless_16bytes:
25717@@ -148,6 +151,7 @@ ENTRY(memcpy)
25718 movq -1*8(%rsi, %rdx), %r9
25719 movq %r8, 0*8(%rdi)
25720 movq %r9, -1*8(%rdi, %rdx)
25721+ pax_force_retaddr
25722 retq
25723 .p2align 4
25724 .Lless_8bytes:
25725@@ -161,6 +165,7 @@ ENTRY(memcpy)
25726 movl -4(%rsi, %rdx), %r8d
25727 movl %ecx, (%rdi)
25728 movl %r8d, -4(%rdi, %rdx)
25729+ pax_force_retaddr
25730 retq
25731 .p2align 4
25732 .Lless_3bytes:
25733@@ -179,6 +184,7 @@ ENTRY(memcpy)
25734 movb %cl, (%rdi)
25735
25736 .Lend:
25737+ pax_force_retaddr
25738 retq
25739 CFI_ENDPROC
25740 ENDPROC(memcpy)
25741diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25742index ee16461..c39c199 100644
25743--- a/arch/x86/lib/memmove_64.S
25744+++ b/arch/x86/lib/memmove_64.S
25745@@ -61,13 +61,13 @@ ENTRY(memmove)
25746 5:
25747 sub $0x20, %rdx
25748 movq 0*8(%rsi), %r11
25749- movq 1*8(%rsi), %r10
25750+ movq 1*8(%rsi), %rcx
25751 movq 2*8(%rsi), %r9
25752 movq 3*8(%rsi), %r8
25753 leaq 4*8(%rsi), %rsi
25754
25755 movq %r11, 0*8(%rdi)
25756- movq %r10, 1*8(%rdi)
25757+ movq %rcx, 1*8(%rdi)
25758 movq %r9, 2*8(%rdi)
25759 movq %r8, 3*8(%rdi)
25760 leaq 4*8(%rdi), %rdi
25761@@ -81,10 +81,10 @@ ENTRY(memmove)
25762 4:
25763 movq %rdx, %rcx
25764 movq -8(%rsi, %rdx), %r11
25765- lea -8(%rdi, %rdx), %r10
25766+ lea -8(%rdi, %rdx), %r9
25767 shrq $3, %rcx
25768 rep movsq
25769- movq %r11, (%r10)
25770+ movq %r11, (%r9)
25771 jmp 13f
25772 .Lmemmove_end_forward:
25773
25774@@ -95,14 +95,14 @@ ENTRY(memmove)
25775 7:
25776 movq %rdx, %rcx
25777 movq (%rsi), %r11
25778- movq %rdi, %r10
25779+ movq %rdi, %r9
25780 leaq -8(%rsi, %rdx), %rsi
25781 leaq -8(%rdi, %rdx), %rdi
25782 shrq $3, %rcx
25783 std
25784 rep movsq
25785 cld
25786- movq %r11, (%r10)
25787+ movq %r11, (%r9)
25788 jmp 13f
25789
25790 /*
25791@@ -127,13 +127,13 @@ ENTRY(memmove)
25792 8:
25793 subq $0x20, %rdx
25794 movq -1*8(%rsi), %r11
25795- movq -2*8(%rsi), %r10
25796+ movq -2*8(%rsi), %rcx
25797 movq -3*8(%rsi), %r9
25798 movq -4*8(%rsi), %r8
25799 leaq -4*8(%rsi), %rsi
25800
25801 movq %r11, -1*8(%rdi)
25802- movq %r10, -2*8(%rdi)
25803+ movq %rcx, -2*8(%rdi)
25804 movq %r9, -3*8(%rdi)
25805 movq %r8, -4*8(%rdi)
25806 leaq -4*8(%rdi), %rdi
25807@@ -151,11 +151,11 @@ ENTRY(memmove)
25808 * Move data from 16 bytes to 31 bytes.
25809 */
25810 movq 0*8(%rsi), %r11
25811- movq 1*8(%rsi), %r10
25812+ movq 1*8(%rsi), %rcx
25813 movq -2*8(%rsi, %rdx), %r9
25814 movq -1*8(%rsi, %rdx), %r8
25815 movq %r11, 0*8(%rdi)
25816- movq %r10, 1*8(%rdi)
25817+ movq %rcx, 1*8(%rdi)
25818 movq %r9, -2*8(%rdi, %rdx)
25819 movq %r8, -1*8(%rdi, %rdx)
25820 jmp 13f
25821@@ -167,9 +167,9 @@ ENTRY(memmove)
25822 * Move data from 8 bytes to 15 bytes.
25823 */
25824 movq 0*8(%rsi), %r11
25825- movq -1*8(%rsi, %rdx), %r10
25826+ movq -1*8(%rsi, %rdx), %r9
25827 movq %r11, 0*8(%rdi)
25828- movq %r10, -1*8(%rdi, %rdx)
25829+ movq %r9, -1*8(%rdi, %rdx)
25830 jmp 13f
25831 10:
25832 cmpq $4, %rdx
25833@@ -178,9 +178,9 @@ ENTRY(memmove)
25834 * Move data from 4 bytes to 7 bytes.
25835 */
25836 movl (%rsi), %r11d
25837- movl -4(%rsi, %rdx), %r10d
25838+ movl -4(%rsi, %rdx), %r9d
25839 movl %r11d, (%rdi)
25840- movl %r10d, -4(%rdi, %rdx)
25841+ movl %r9d, -4(%rdi, %rdx)
25842 jmp 13f
25843 11:
25844 cmp $2, %rdx
25845@@ -189,9 +189,9 @@ ENTRY(memmove)
25846 * Move data from 2 bytes to 3 bytes.
25847 */
25848 movw (%rsi), %r11w
25849- movw -2(%rsi, %rdx), %r10w
25850+ movw -2(%rsi, %rdx), %r9w
25851 movw %r11w, (%rdi)
25852- movw %r10w, -2(%rdi, %rdx)
25853+ movw %r9w, -2(%rdi, %rdx)
25854 jmp 13f
25855 12:
25856 cmp $1, %rdx
25857@@ -202,6 +202,7 @@ ENTRY(memmove)
25858 movb (%rsi), %r11b
25859 movb %r11b, (%rdi)
25860 13:
25861+ pax_force_retaddr
25862 retq
25863 CFI_ENDPROC
25864
25865@@ -210,6 +211,7 @@ ENTRY(memmove)
25866 /* Forward moving data. */
25867 movq %rdx, %rcx
25868 rep movsb
25869+ pax_force_retaddr
25870 retq
25871 .Lmemmove_end_forward_efs:
25872 .previous
25873diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25874index 2dcb380..963660a 100644
25875--- a/arch/x86/lib/memset_64.S
25876+++ b/arch/x86/lib/memset_64.S
25877@@ -30,6 +30,7 @@
25878 movl %edx,%ecx
25879 rep stosb
25880 movq %r9,%rax
25881+ pax_force_retaddr
25882 ret
25883 .Lmemset_e:
25884 .previous
25885@@ -52,6 +53,7 @@
25886 movq %rdx,%rcx
25887 rep stosb
25888 movq %r9,%rax
25889+ pax_force_retaddr
25890 ret
25891 .Lmemset_e_e:
25892 .previous
25893@@ -59,7 +61,7 @@
25894 ENTRY(memset)
25895 ENTRY(__memset)
25896 CFI_STARTPROC
25897- movq %rdi,%r10
25898+ movq %rdi,%r11
25899
25900 /* expand byte value */
25901 movzbl %sil,%ecx
25902@@ -117,7 +119,8 @@ ENTRY(__memset)
25903 jnz .Lloop_1
25904
25905 .Lende:
25906- movq %r10,%rax
25907+ movq %r11,%rax
25908+ pax_force_retaddr
25909 ret
25910
25911 CFI_RESTORE_STATE
25912diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25913index c9f2d9b..e7fd2c0 100644
25914--- a/arch/x86/lib/mmx_32.c
25915+++ b/arch/x86/lib/mmx_32.c
25916@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25917 {
25918 void *p;
25919 int i;
25920+ unsigned long cr0;
25921
25922 if (unlikely(in_interrupt()))
25923 return __memcpy(to, from, len);
25924@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25925 kernel_fpu_begin();
25926
25927 __asm__ __volatile__ (
25928- "1: prefetch (%0)\n" /* This set is 28 bytes */
25929- " prefetch 64(%0)\n"
25930- " prefetch 128(%0)\n"
25931- " prefetch 192(%0)\n"
25932- " prefetch 256(%0)\n"
25933+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25934+ " prefetch 64(%1)\n"
25935+ " prefetch 128(%1)\n"
25936+ " prefetch 192(%1)\n"
25937+ " prefetch 256(%1)\n"
25938 "2: \n"
25939 ".section .fixup, \"ax\"\n"
25940- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25941+ "3: \n"
25942+
25943+#ifdef CONFIG_PAX_KERNEXEC
25944+ " movl %%cr0, %0\n"
25945+ " movl %0, %%eax\n"
25946+ " andl $0xFFFEFFFF, %%eax\n"
25947+ " movl %%eax, %%cr0\n"
25948+#endif
25949+
25950+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25951+
25952+#ifdef CONFIG_PAX_KERNEXEC
25953+ " movl %0, %%cr0\n"
25954+#endif
25955+
25956 " jmp 2b\n"
25957 ".previous\n"
25958 _ASM_EXTABLE(1b, 3b)
25959- : : "r" (from));
25960+ : "=&r" (cr0) : "r" (from) : "ax");
25961
25962 for ( ; i > 5; i--) {
25963 __asm__ __volatile__ (
25964- "1: prefetch 320(%0)\n"
25965- "2: movq (%0), %%mm0\n"
25966- " movq 8(%0), %%mm1\n"
25967- " movq 16(%0), %%mm2\n"
25968- " movq 24(%0), %%mm3\n"
25969- " movq %%mm0, (%1)\n"
25970- " movq %%mm1, 8(%1)\n"
25971- " movq %%mm2, 16(%1)\n"
25972- " movq %%mm3, 24(%1)\n"
25973- " movq 32(%0), %%mm0\n"
25974- " movq 40(%0), %%mm1\n"
25975- " movq 48(%0), %%mm2\n"
25976- " movq 56(%0), %%mm3\n"
25977- " movq %%mm0, 32(%1)\n"
25978- " movq %%mm1, 40(%1)\n"
25979- " movq %%mm2, 48(%1)\n"
25980- " movq %%mm3, 56(%1)\n"
25981+ "1: prefetch 320(%1)\n"
25982+ "2: movq (%1), %%mm0\n"
25983+ " movq 8(%1), %%mm1\n"
25984+ " movq 16(%1), %%mm2\n"
25985+ " movq 24(%1), %%mm3\n"
25986+ " movq %%mm0, (%2)\n"
25987+ " movq %%mm1, 8(%2)\n"
25988+ " movq %%mm2, 16(%2)\n"
25989+ " movq %%mm3, 24(%2)\n"
25990+ " movq 32(%1), %%mm0\n"
25991+ " movq 40(%1), %%mm1\n"
25992+ " movq 48(%1), %%mm2\n"
25993+ " movq 56(%1), %%mm3\n"
25994+ " movq %%mm0, 32(%2)\n"
25995+ " movq %%mm1, 40(%2)\n"
25996+ " movq %%mm2, 48(%2)\n"
25997+ " movq %%mm3, 56(%2)\n"
25998 ".section .fixup, \"ax\"\n"
25999- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26000+ "3:\n"
26001+
26002+#ifdef CONFIG_PAX_KERNEXEC
26003+ " movl %%cr0, %0\n"
26004+ " movl %0, %%eax\n"
26005+ " andl $0xFFFEFFFF, %%eax\n"
26006+ " movl %%eax, %%cr0\n"
26007+#endif
26008+
26009+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26010+
26011+#ifdef CONFIG_PAX_KERNEXEC
26012+ " movl %0, %%cr0\n"
26013+#endif
26014+
26015 " jmp 2b\n"
26016 ".previous\n"
26017 _ASM_EXTABLE(1b, 3b)
26018- : : "r" (from), "r" (to) : "memory");
26019+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26020
26021 from += 64;
26022 to += 64;
26023@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
26024 static void fast_copy_page(void *to, void *from)
26025 {
26026 int i;
26027+ unsigned long cr0;
26028
26029 kernel_fpu_begin();
26030
26031@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
26032 * but that is for later. -AV
26033 */
26034 __asm__ __volatile__(
26035- "1: prefetch (%0)\n"
26036- " prefetch 64(%0)\n"
26037- " prefetch 128(%0)\n"
26038- " prefetch 192(%0)\n"
26039- " prefetch 256(%0)\n"
26040+ "1: prefetch (%1)\n"
26041+ " prefetch 64(%1)\n"
26042+ " prefetch 128(%1)\n"
26043+ " prefetch 192(%1)\n"
26044+ " prefetch 256(%1)\n"
26045 "2: \n"
26046 ".section .fixup, \"ax\"\n"
26047- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26048+ "3: \n"
26049+
26050+#ifdef CONFIG_PAX_KERNEXEC
26051+ " movl %%cr0, %0\n"
26052+ " movl %0, %%eax\n"
26053+ " andl $0xFFFEFFFF, %%eax\n"
26054+ " movl %%eax, %%cr0\n"
26055+#endif
26056+
26057+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26058+
26059+#ifdef CONFIG_PAX_KERNEXEC
26060+ " movl %0, %%cr0\n"
26061+#endif
26062+
26063 " jmp 2b\n"
26064 ".previous\n"
26065- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26066+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26067
26068 for (i = 0; i < (4096-320)/64; i++) {
26069 __asm__ __volatile__ (
26070- "1: prefetch 320(%0)\n"
26071- "2: movq (%0), %%mm0\n"
26072- " movntq %%mm0, (%1)\n"
26073- " movq 8(%0), %%mm1\n"
26074- " movntq %%mm1, 8(%1)\n"
26075- " movq 16(%0), %%mm2\n"
26076- " movntq %%mm2, 16(%1)\n"
26077- " movq 24(%0), %%mm3\n"
26078- " movntq %%mm3, 24(%1)\n"
26079- " movq 32(%0), %%mm4\n"
26080- " movntq %%mm4, 32(%1)\n"
26081- " movq 40(%0), %%mm5\n"
26082- " movntq %%mm5, 40(%1)\n"
26083- " movq 48(%0), %%mm6\n"
26084- " movntq %%mm6, 48(%1)\n"
26085- " movq 56(%0), %%mm7\n"
26086- " movntq %%mm7, 56(%1)\n"
26087+ "1: prefetch 320(%1)\n"
26088+ "2: movq (%1), %%mm0\n"
26089+ " movntq %%mm0, (%2)\n"
26090+ " movq 8(%1), %%mm1\n"
26091+ " movntq %%mm1, 8(%2)\n"
26092+ " movq 16(%1), %%mm2\n"
26093+ " movntq %%mm2, 16(%2)\n"
26094+ " movq 24(%1), %%mm3\n"
26095+ " movntq %%mm3, 24(%2)\n"
26096+ " movq 32(%1), %%mm4\n"
26097+ " movntq %%mm4, 32(%2)\n"
26098+ " movq 40(%1), %%mm5\n"
26099+ " movntq %%mm5, 40(%2)\n"
26100+ " movq 48(%1), %%mm6\n"
26101+ " movntq %%mm6, 48(%2)\n"
26102+ " movq 56(%1), %%mm7\n"
26103+ " movntq %%mm7, 56(%2)\n"
26104 ".section .fixup, \"ax\"\n"
26105- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26106+ "3:\n"
26107+
26108+#ifdef CONFIG_PAX_KERNEXEC
26109+ " movl %%cr0, %0\n"
26110+ " movl %0, %%eax\n"
26111+ " andl $0xFFFEFFFF, %%eax\n"
26112+ " movl %%eax, %%cr0\n"
26113+#endif
26114+
26115+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26116+
26117+#ifdef CONFIG_PAX_KERNEXEC
26118+ " movl %0, %%cr0\n"
26119+#endif
26120+
26121 " jmp 2b\n"
26122 ".previous\n"
26123- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
26124+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26125
26126 from += 64;
26127 to += 64;
26128@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
26129 static void fast_copy_page(void *to, void *from)
26130 {
26131 int i;
26132+ unsigned long cr0;
26133
26134 kernel_fpu_begin();
26135
26136 __asm__ __volatile__ (
26137- "1: prefetch (%0)\n"
26138- " prefetch 64(%0)\n"
26139- " prefetch 128(%0)\n"
26140- " prefetch 192(%0)\n"
26141- " prefetch 256(%0)\n"
26142+ "1: prefetch (%1)\n"
26143+ " prefetch 64(%1)\n"
26144+ " prefetch 128(%1)\n"
26145+ " prefetch 192(%1)\n"
26146+ " prefetch 256(%1)\n"
26147 "2: \n"
26148 ".section .fixup, \"ax\"\n"
26149- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26150+ "3: \n"
26151+
26152+#ifdef CONFIG_PAX_KERNEXEC
26153+ " movl %%cr0, %0\n"
26154+ " movl %0, %%eax\n"
26155+ " andl $0xFFFEFFFF, %%eax\n"
26156+ " movl %%eax, %%cr0\n"
26157+#endif
26158+
26159+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26160+
26161+#ifdef CONFIG_PAX_KERNEXEC
26162+ " movl %0, %%cr0\n"
26163+#endif
26164+
26165 " jmp 2b\n"
26166 ".previous\n"
26167- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26168+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26169
26170 for (i = 0; i < 4096/64; i++) {
26171 __asm__ __volatile__ (
26172- "1: prefetch 320(%0)\n"
26173- "2: movq (%0), %%mm0\n"
26174- " movq 8(%0), %%mm1\n"
26175- " movq 16(%0), %%mm2\n"
26176- " movq 24(%0), %%mm3\n"
26177- " movq %%mm0, (%1)\n"
26178- " movq %%mm1, 8(%1)\n"
26179- " movq %%mm2, 16(%1)\n"
26180- " movq %%mm3, 24(%1)\n"
26181- " movq 32(%0), %%mm0\n"
26182- " movq 40(%0), %%mm1\n"
26183- " movq 48(%0), %%mm2\n"
26184- " movq 56(%0), %%mm3\n"
26185- " movq %%mm0, 32(%1)\n"
26186- " movq %%mm1, 40(%1)\n"
26187- " movq %%mm2, 48(%1)\n"
26188- " movq %%mm3, 56(%1)\n"
26189+ "1: prefetch 320(%1)\n"
26190+ "2: movq (%1), %%mm0\n"
26191+ " movq 8(%1), %%mm1\n"
26192+ " movq 16(%1), %%mm2\n"
26193+ " movq 24(%1), %%mm3\n"
26194+ " movq %%mm0, (%2)\n"
26195+ " movq %%mm1, 8(%2)\n"
26196+ " movq %%mm2, 16(%2)\n"
26197+ " movq %%mm3, 24(%2)\n"
26198+ " movq 32(%1), %%mm0\n"
26199+ " movq 40(%1), %%mm1\n"
26200+ " movq 48(%1), %%mm2\n"
26201+ " movq 56(%1), %%mm3\n"
26202+ " movq %%mm0, 32(%2)\n"
26203+ " movq %%mm1, 40(%2)\n"
26204+ " movq %%mm2, 48(%2)\n"
26205+ " movq %%mm3, 56(%2)\n"
26206 ".section .fixup, \"ax\"\n"
26207- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26208+ "3:\n"
26209+
26210+#ifdef CONFIG_PAX_KERNEXEC
26211+ " movl %%cr0, %0\n"
26212+ " movl %0, %%eax\n"
26213+ " andl $0xFFFEFFFF, %%eax\n"
26214+ " movl %%eax, %%cr0\n"
26215+#endif
26216+
26217+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26218+
26219+#ifdef CONFIG_PAX_KERNEXEC
26220+ " movl %0, %%cr0\n"
26221+#endif
26222+
26223 " jmp 2b\n"
26224 ".previous\n"
26225 _ASM_EXTABLE(1b, 3b)
26226- : : "r" (from), "r" (to) : "memory");
26227+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26228
26229 from += 64;
26230 to += 64;
26231diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26232index f6d13ee..aca5f0b 100644
26233--- a/arch/x86/lib/msr-reg.S
26234+++ b/arch/x86/lib/msr-reg.S
26235@@ -3,6 +3,7 @@
26236 #include <asm/dwarf2.h>
26237 #include <asm/asm.h>
26238 #include <asm/msr.h>
26239+#include <asm/alternative-asm.h>
26240
26241 #ifdef CONFIG_X86_64
26242 /*
26243@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26244 CFI_STARTPROC
26245 pushq_cfi %rbx
26246 pushq_cfi %rbp
26247- movq %rdi, %r10 /* Save pointer */
26248+ movq %rdi, %r9 /* Save pointer */
26249 xorl %r11d, %r11d /* Return value */
26250 movl (%rdi), %eax
26251 movl 4(%rdi), %ecx
26252@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26253 movl 28(%rdi), %edi
26254 CFI_REMEMBER_STATE
26255 1: \op
26256-2: movl %eax, (%r10)
26257+2: movl %eax, (%r9)
26258 movl %r11d, %eax /* Return value */
26259- movl %ecx, 4(%r10)
26260- movl %edx, 8(%r10)
26261- movl %ebx, 12(%r10)
26262- movl %ebp, 20(%r10)
26263- movl %esi, 24(%r10)
26264- movl %edi, 28(%r10)
26265+ movl %ecx, 4(%r9)
26266+ movl %edx, 8(%r9)
26267+ movl %ebx, 12(%r9)
26268+ movl %ebp, 20(%r9)
26269+ movl %esi, 24(%r9)
26270+ movl %edi, 28(%r9)
26271 popq_cfi %rbp
26272 popq_cfi %rbx
26273+ pax_force_retaddr
26274 ret
26275 3:
26276 CFI_RESTORE_STATE
26277diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26278index fc6ba17..d4d989d 100644
26279--- a/arch/x86/lib/putuser.S
26280+++ b/arch/x86/lib/putuser.S
26281@@ -16,7 +16,9 @@
26282 #include <asm/errno.h>
26283 #include <asm/asm.h>
26284 #include <asm/smap.h>
26285-
26286+#include <asm/segment.h>
26287+#include <asm/pgtable.h>
26288+#include <asm/alternative-asm.h>
26289
26290 /*
26291 * __put_user_X
26292@@ -30,57 +32,125 @@
26293 * as they get called from within inline assembly.
26294 */
26295
26296-#define ENTER CFI_STARTPROC ; \
26297- GET_THREAD_INFO(%_ASM_BX)
26298-#define EXIT ASM_CLAC ; \
26299- ret ; \
26300+#define ENTER CFI_STARTPROC
26301+#define EXIT ASM_CLAC ; \
26302+ pax_force_retaddr ; \
26303+ ret ; \
26304 CFI_ENDPROC
26305
26306+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26307+#define _DEST %_ASM_CX,%_ASM_BX
26308+#else
26309+#define _DEST %_ASM_CX
26310+#endif
26311+
26312+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26313+#define __copyuser_seg gs;
26314+#else
26315+#define __copyuser_seg
26316+#endif
26317+
26318 .text
26319 ENTRY(__put_user_1)
26320 ENTER
26321+
26322+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26323+ GET_THREAD_INFO(%_ASM_BX)
26324 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26325 jae bad_put_user
26326 ASM_STAC
26327-1: movb %al,(%_ASM_CX)
26328+
26329+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26330+ mov pax_user_shadow_base,%_ASM_BX
26331+ cmp %_ASM_BX,%_ASM_CX
26332+ jb 1234f
26333+ xor %ebx,%ebx
26334+1234:
26335+#endif
26336+
26337+#endif
26338+
26339+1: __copyuser_seg movb %al,(_DEST)
26340 xor %eax,%eax
26341 EXIT
26342 ENDPROC(__put_user_1)
26343
26344 ENTRY(__put_user_2)
26345 ENTER
26346+
26347+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26348+ GET_THREAD_INFO(%_ASM_BX)
26349 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26350 sub $1,%_ASM_BX
26351 cmp %_ASM_BX,%_ASM_CX
26352 jae bad_put_user
26353 ASM_STAC
26354-2: movw %ax,(%_ASM_CX)
26355+
26356+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26357+ mov pax_user_shadow_base,%_ASM_BX
26358+ cmp %_ASM_BX,%_ASM_CX
26359+ jb 1234f
26360+ xor %ebx,%ebx
26361+1234:
26362+#endif
26363+
26364+#endif
26365+
26366+2: __copyuser_seg movw %ax,(_DEST)
26367 xor %eax,%eax
26368 EXIT
26369 ENDPROC(__put_user_2)
26370
26371 ENTRY(__put_user_4)
26372 ENTER
26373+
26374+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26375+ GET_THREAD_INFO(%_ASM_BX)
26376 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26377 sub $3,%_ASM_BX
26378 cmp %_ASM_BX,%_ASM_CX
26379 jae bad_put_user
26380 ASM_STAC
26381-3: movl %eax,(%_ASM_CX)
26382+
26383+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26384+ mov pax_user_shadow_base,%_ASM_BX
26385+ cmp %_ASM_BX,%_ASM_CX
26386+ jb 1234f
26387+ xor %ebx,%ebx
26388+1234:
26389+#endif
26390+
26391+#endif
26392+
26393+3: __copyuser_seg movl %eax,(_DEST)
26394 xor %eax,%eax
26395 EXIT
26396 ENDPROC(__put_user_4)
26397
26398 ENTRY(__put_user_8)
26399 ENTER
26400+
26401+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26402+ GET_THREAD_INFO(%_ASM_BX)
26403 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26404 sub $7,%_ASM_BX
26405 cmp %_ASM_BX,%_ASM_CX
26406 jae bad_put_user
26407 ASM_STAC
26408-4: mov %_ASM_AX,(%_ASM_CX)
26409+
26410+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26411+ mov pax_user_shadow_base,%_ASM_BX
26412+ cmp %_ASM_BX,%_ASM_CX
26413+ jb 1234f
26414+ xor %ebx,%ebx
26415+1234:
26416+#endif
26417+
26418+#endif
26419+
26420+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26421 #ifdef CONFIG_X86_32
26422-5: movl %edx,4(%_ASM_CX)
26423+5: __copyuser_seg movl %edx,4(_DEST)
26424 #endif
26425 xor %eax,%eax
26426 EXIT
26427diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26428index 1cad221..de671ee 100644
26429--- a/arch/x86/lib/rwlock.S
26430+++ b/arch/x86/lib/rwlock.S
26431@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26432 FRAME
26433 0: LOCK_PREFIX
26434 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26435+
26436+#ifdef CONFIG_PAX_REFCOUNT
26437+ jno 1234f
26438+ LOCK_PREFIX
26439+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26440+ int $4
26441+1234:
26442+ _ASM_EXTABLE(1234b, 1234b)
26443+#endif
26444+
26445 1: rep; nop
26446 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26447 jne 1b
26448 LOCK_PREFIX
26449 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26450+
26451+#ifdef CONFIG_PAX_REFCOUNT
26452+ jno 1234f
26453+ LOCK_PREFIX
26454+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26455+ int $4
26456+1234:
26457+ _ASM_EXTABLE(1234b, 1234b)
26458+#endif
26459+
26460 jnz 0b
26461 ENDFRAME
26462+ pax_force_retaddr
26463 ret
26464 CFI_ENDPROC
26465 END(__write_lock_failed)
26466@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26467 FRAME
26468 0: LOCK_PREFIX
26469 READ_LOCK_SIZE(inc) (%__lock_ptr)
26470+
26471+#ifdef CONFIG_PAX_REFCOUNT
26472+ jno 1234f
26473+ LOCK_PREFIX
26474+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26475+ int $4
26476+1234:
26477+ _ASM_EXTABLE(1234b, 1234b)
26478+#endif
26479+
26480 1: rep; nop
26481 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26482 js 1b
26483 LOCK_PREFIX
26484 READ_LOCK_SIZE(dec) (%__lock_ptr)
26485+
26486+#ifdef CONFIG_PAX_REFCOUNT
26487+ jno 1234f
26488+ LOCK_PREFIX
26489+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26490+ int $4
26491+1234:
26492+ _ASM_EXTABLE(1234b, 1234b)
26493+#endif
26494+
26495 js 0b
26496 ENDFRAME
26497+ pax_force_retaddr
26498 ret
26499 CFI_ENDPROC
26500 END(__read_lock_failed)
26501diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26502index 5dff5f0..cadebf4 100644
26503--- a/arch/x86/lib/rwsem.S
26504+++ b/arch/x86/lib/rwsem.S
26505@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26506 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26507 CFI_RESTORE __ASM_REG(dx)
26508 restore_common_regs
26509+ pax_force_retaddr
26510 ret
26511 CFI_ENDPROC
26512 ENDPROC(call_rwsem_down_read_failed)
26513@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26514 movq %rax,%rdi
26515 call rwsem_down_write_failed
26516 restore_common_regs
26517+ pax_force_retaddr
26518 ret
26519 CFI_ENDPROC
26520 ENDPROC(call_rwsem_down_write_failed)
26521@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26522 movq %rax,%rdi
26523 call rwsem_wake
26524 restore_common_regs
26525-1: ret
26526+1: pax_force_retaddr
26527+ ret
26528 CFI_ENDPROC
26529 ENDPROC(call_rwsem_wake)
26530
26531@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26532 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26533 CFI_RESTORE __ASM_REG(dx)
26534 restore_common_regs
26535+ pax_force_retaddr
26536 ret
26537 CFI_ENDPROC
26538 ENDPROC(call_rwsem_downgrade_wake)
26539diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26540index a63efd6..ccecad8 100644
26541--- a/arch/x86/lib/thunk_64.S
26542+++ b/arch/x86/lib/thunk_64.S
26543@@ -8,6 +8,7 @@
26544 #include <linux/linkage.h>
26545 #include <asm/dwarf2.h>
26546 #include <asm/calling.h>
26547+#include <asm/alternative-asm.h>
26548
26549 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26550 .macro THUNK name, func, put_ret_addr_in_rdi=0
26551@@ -41,5 +42,6 @@
26552 SAVE_ARGS
26553 restore:
26554 RESTORE_ARGS
26555+ pax_force_retaddr
26556 ret
26557 CFI_ENDPROC
26558diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26559index f0312d7..9c39d63 100644
26560--- a/arch/x86/lib/usercopy_32.c
26561+++ b/arch/x86/lib/usercopy_32.c
26562@@ -42,11 +42,13 @@ do { \
26563 int __d0; \
26564 might_fault(); \
26565 __asm__ __volatile__( \
26566+ __COPYUSER_SET_ES \
26567 ASM_STAC "\n" \
26568 "0: rep; stosl\n" \
26569 " movl %2,%0\n" \
26570 "1: rep; stosb\n" \
26571 "2: " ASM_CLAC "\n" \
26572+ __COPYUSER_RESTORE_ES \
26573 ".section .fixup,\"ax\"\n" \
26574 "3: lea 0(%2,%0,4),%0\n" \
26575 " jmp 2b\n" \
26576@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26577
26578 #ifdef CONFIG_X86_INTEL_USERCOPY
26579 static unsigned long
26580-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26581+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26582 {
26583 int d0, d1;
26584 __asm__ __volatile__(
26585@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26586 " .align 2,0x90\n"
26587 "3: movl 0(%4), %%eax\n"
26588 "4: movl 4(%4), %%edx\n"
26589- "5: movl %%eax, 0(%3)\n"
26590- "6: movl %%edx, 4(%3)\n"
26591+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26592+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26593 "7: movl 8(%4), %%eax\n"
26594 "8: movl 12(%4),%%edx\n"
26595- "9: movl %%eax, 8(%3)\n"
26596- "10: movl %%edx, 12(%3)\n"
26597+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26598+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26599 "11: movl 16(%4), %%eax\n"
26600 "12: movl 20(%4), %%edx\n"
26601- "13: movl %%eax, 16(%3)\n"
26602- "14: movl %%edx, 20(%3)\n"
26603+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26604+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26605 "15: movl 24(%4), %%eax\n"
26606 "16: movl 28(%4), %%edx\n"
26607- "17: movl %%eax, 24(%3)\n"
26608- "18: movl %%edx, 28(%3)\n"
26609+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26610+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26611 "19: movl 32(%4), %%eax\n"
26612 "20: movl 36(%4), %%edx\n"
26613- "21: movl %%eax, 32(%3)\n"
26614- "22: movl %%edx, 36(%3)\n"
26615+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26616+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26617 "23: movl 40(%4), %%eax\n"
26618 "24: movl 44(%4), %%edx\n"
26619- "25: movl %%eax, 40(%3)\n"
26620- "26: movl %%edx, 44(%3)\n"
26621+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26622+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26623 "27: movl 48(%4), %%eax\n"
26624 "28: movl 52(%4), %%edx\n"
26625- "29: movl %%eax, 48(%3)\n"
26626- "30: movl %%edx, 52(%3)\n"
26627+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26628+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26629 "31: movl 56(%4), %%eax\n"
26630 "32: movl 60(%4), %%edx\n"
26631- "33: movl %%eax, 56(%3)\n"
26632- "34: movl %%edx, 60(%3)\n"
26633+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26634+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26635 " addl $-64, %0\n"
26636 " addl $64, %4\n"
26637 " addl $64, %3\n"
26638@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26639 " shrl $2, %0\n"
26640 " andl $3, %%eax\n"
26641 " cld\n"
26642+ __COPYUSER_SET_ES
26643 "99: rep; movsl\n"
26644 "36: movl %%eax, %0\n"
26645 "37: rep; movsb\n"
26646 "100:\n"
26647+ __COPYUSER_RESTORE_ES
26648 ".section .fixup,\"ax\"\n"
26649 "101: lea 0(%%eax,%0,4),%0\n"
26650 " jmp 100b\n"
26651@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26652 }
26653
26654 static unsigned long
26655+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26656+{
26657+ int d0, d1;
26658+ __asm__ __volatile__(
26659+ " .align 2,0x90\n"
26660+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26661+ " cmpl $67, %0\n"
26662+ " jbe 3f\n"
26663+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26664+ " .align 2,0x90\n"
26665+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26666+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26667+ "5: movl %%eax, 0(%3)\n"
26668+ "6: movl %%edx, 4(%3)\n"
26669+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26670+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26671+ "9: movl %%eax, 8(%3)\n"
26672+ "10: movl %%edx, 12(%3)\n"
26673+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26674+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26675+ "13: movl %%eax, 16(%3)\n"
26676+ "14: movl %%edx, 20(%3)\n"
26677+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26678+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26679+ "17: movl %%eax, 24(%3)\n"
26680+ "18: movl %%edx, 28(%3)\n"
26681+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26682+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26683+ "21: movl %%eax, 32(%3)\n"
26684+ "22: movl %%edx, 36(%3)\n"
26685+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26686+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26687+ "25: movl %%eax, 40(%3)\n"
26688+ "26: movl %%edx, 44(%3)\n"
26689+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26690+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26691+ "29: movl %%eax, 48(%3)\n"
26692+ "30: movl %%edx, 52(%3)\n"
26693+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26694+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26695+ "33: movl %%eax, 56(%3)\n"
26696+ "34: movl %%edx, 60(%3)\n"
26697+ " addl $-64, %0\n"
26698+ " addl $64, %4\n"
26699+ " addl $64, %3\n"
26700+ " cmpl $63, %0\n"
26701+ " ja 1b\n"
26702+ "35: movl %0, %%eax\n"
26703+ " shrl $2, %0\n"
26704+ " andl $3, %%eax\n"
26705+ " cld\n"
26706+ "99: rep; "__copyuser_seg" movsl\n"
26707+ "36: movl %%eax, %0\n"
26708+ "37: rep; "__copyuser_seg" movsb\n"
26709+ "100:\n"
26710+ ".section .fixup,\"ax\"\n"
26711+ "101: lea 0(%%eax,%0,4),%0\n"
26712+ " jmp 100b\n"
26713+ ".previous\n"
26714+ _ASM_EXTABLE(1b,100b)
26715+ _ASM_EXTABLE(2b,100b)
26716+ _ASM_EXTABLE(3b,100b)
26717+ _ASM_EXTABLE(4b,100b)
26718+ _ASM_EXTABLE(5b,100b)
26719+ _ASM_EXTABLE(6b,100b)
26720+ _ASM_EXTABLE(7b,100b)
26721+ _ASM_EXTABLE(8b,100b)
26722+ _ASM_EXTABLE(9b,100b)
26723+ _ASM_EXTABLE(10b,100b)
26724+ _ASM_EXTABLE(11b,100b)
26725+ _ASM_EXTABLE(12b,100b)
26726+ _ASM_EXTABLE(13b,100b)
26727+ _ASM_EXTABLE(14b,100b)
26728+ _ASM_EXTABLE(15b,100b)
26729+ _ASM_EXTABLE(16b,100b)
26730+ _ASM_EXTABLE(17b,100b)
26731+ _ASM_EXTABLE(18b,100b)
26732+ _ASM_EXTABLE(19b,100b)
26733+ _ASM_EXTABLE(20b,100b)
26734+ _ASM_EXTABLE(21b,100b)
26735+ _ASM_EXTABLE(22b,100b)
26736+ _ASM_EXTABLE(23b,100b)
26737+ _ASM_EXTABLE(24b,100b)
26738+ _ASM_EXTABLE(25b,100b)
26739+ _ASM_EXTABLE(26b,100b)
26740+ _ASM_EXTABLE(27b,100b)
26741+ _ASM_EXTABLE(28b,100b)
26742+ _ASM_EXTABLE(29b,100b)
26743+ _ASM_EXTABLE(30b,100b)
26744+ _ASM_EXTABLE(31b,100b)
26745+ _ASM_EXTABLE(32b,100b)
26746+ _ASM_EXTABLE(33b,100b)
26747+ _ASM_EXTABLE(34b,100b)
26748+ _ASM_EXTABLE(35b,100b)
26749+ _ASM_EXTABLE(36b,100b)
26750+ _ASM_EXTABLE(37b,100b)
26751+ _ASM_EXTABLE(99b,101b)
26752+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26753+ : "1"(to), "2"(from), "0"(size)
26754+ : "eax", "edx", "memory");
26755+ return size;
26756+}
26757+
26758+static unsigned long __size_overflow(3)
26759 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26760 {
26761 int d0, d1;
26762 __asm__ __volatile__(
26763 " .align 2,0x90\n"
26764- "0: movl 32(%4), %%eax\n"
26765+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26766 " cmpl $67, %0\n"
26767 " jbe 2f\n"
26768- "1: movl 64(%4), %%eax\n"
26769+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26770 " .align 2,0x90\n"
26771- "2: movl 0(%4), %%eax\n"
26772- "21: movl 4(%4), %%edx\n"
26773+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26774+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26775 " movl %%eax, 0(%3)\n"
26776 " movl %%edx, 4(%3)\n"
26777- "3: movl 8(%4), %%eax\n"
26778- "31: movl 12(%4),%%edx\n"
26779+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26780+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26781 " movl %%eax, 8(%3)\n"
26782 " movl %%edx, 12(%3)\n"
26783- "4: movl 16(%4), %%eax\n"
26784- "41: movl 20(%4), %%edx\n"
26785+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26786+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26787 " movl %%eax, 16(%3)\n"
26788 " movl %%edx, 20(%3)\n"
26789- "10: movl 24(%4), %%eax\n"
26790- "51: movl 28(%4), %%edx\n"
26791+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26792+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26793 " movl %%eax, 24(%3)\n"
26794 " movl %%edx, 28(%3)\n"
26795- "11: movl 32(%4), %%eax\n"
26796- "61: movl 36(%4), %%edx\n"
26797+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26798+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26799 " movl %%eax, 32(%3)\n"
26800 " movl %%edx, 36(%3)\n"
26801- "12: movl 40(%4), %%eax\n"
26802- "71: movl 44(%4), %%edx\n"
26803+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26804+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26805 " movl %%eax, 40(%3)\n"
26806 " movl %%edx, 44(%3)\n"
26807- "13: movl 48(%4), %%eax\n"
26808- "81: movl 52(%4), %%edx\n"
26809+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26810+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26811 " movl %%eax, 48(%3)\n"
26812 " movl %%edx, 52(%3)\n"
26813- "14: movl 56(%4), %%eax\n"
26814- "91: movl 60(%4), %%edx\n"
26815+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26816+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26817 " movl %%eax, 56(%3)\n"
26818 " movl %%edx, 60(%3)\n"
26819 " addl $-64, %0\n"
26820@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26821 " shrl $2, %0\n"
26822 " andl $3, %%eax\n"
26823 " cld\n"
26824- "6: rep; movsl\n"
26825+ "6: rep; "__copyuser_seg" movsl\n"
26826 " movl %%eax,%0\n"
26827- "7: rep; movsb\n"
26828+ "7: rep; "__copyuser_seg" movsb\n"
26829 "8:\n"
26830 ".section .fixup,\"ax\"\n"
26831 "9: lea 0(%%eax,%0,4),%0\n"
26832@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26833 * hyoshiok@miraclelinux.com
26834 */
26835
26836-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26837+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26838 const void __user *from, unsigned long size)
26839 {
26840 int d0, d1;
26841
26842 __asm__ __volatile__(
26843 " .align 2,0x90\n"
26844- "0: movl 32(%4), %%eax\n"
26845+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26846 " cmpl $67, %0\n"
26847 " jbe 2f\n"
26848- "1: movl 64(%4), %%eax\n"
26849+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26850 " .align 2,0x90\n"
26851- "2: movl 0(%4), %%eax\n"
26852- "21: movl 4(%4), %%edx\n"
26853+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26854+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26855 " movnti %%eax, 0(%3)\n"
26856 " movnti %%edx, 4(%3)\n"
26857- "3: movl 8(%4), %%eax\n"
26858- "31: movl 12(%4),%%edx\n"
26859+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26860+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26861 " movnti %%eax, 8(%3)\n"
26862 " movnti %%edx, 12(%3)\n"
26863- "4: movl 16(%4), %%eax\n"
26864- "41: movl 20(%4), %%edx\n"
26865+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26866+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26867 " movnti %%eax, 16(%3)\n"
26868 " movnti %%edx, 20(%3)\n"
26869- "10: movl 24(%4), %%eax\n"
26870- "51: movl 28(%4), %%edx\n"
26871+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26872+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26873 " movnti %%eax, 24(%3)\n"
26874 " movnti %%edx, 28(%3)\n"
26875- "11: movl 32(%4), %%eax\n"
26876- "61: movl 36(%4), %%edx\n"
26877+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26878+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26879 " movnti %%eax, 32(%3)\n"
26880 " movnti %%edx, 36(%3)\n"
26881- "12: movl 40(%4), %%eax\n"
26882- "71: movl 44(%4), %%edx\n"
26883+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26884+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26885 " movnti %%eax, 40(%3)\n"
26886 " movnti %%edx, 44(%3)\n"
26887- "13: movl 48(%4), %%eax\n"
26888- "81: movl 52(%4), %%edx\n"
26889+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26890+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26891 " movnti %%eax, 48(%3)\n"
26892 " movnti %%edx, 52(%3)\n"
26893- "14: movl 56(%4), %%eax\n"
26894- "91: movl 60(%4), %%edx\n"
26895+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26896+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26897 " movnti %%eax, 56(%3)\n"
26898 " movnti %%edx, 60(%3)\n"
26899 " addl $-64, %0\n"
26900@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26901 " shrl $2, %0\n"
26902 " andl $3, %%eax\n"
26903 " cld\n"
26904- "6: rep; movsl\n"
26905+ "6: rep; "__copyuser_seg" movsl\n"
26906 " movl %%eax,%0\n"
26907- "7: rep; movsb\n"
26908+ "7: rep; "__copyuser_seg" movsb\n"
26909 "8:\n"
26910 ".section .fixup,\"ax\"\n"
26911 "9: lea 0(%%eax,%0,4),%0\n"
26912@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26913 return size;
26914 }
26915
26916-static unsigned long __copy_user_intel_nocache(void *to,
26917+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26918 const void __user *from, unsigned long size)
26919 {
26920 int d0, d1;
26921
26922 __asm__ __volatile__(
26923 " .align 2,0x90\n"
26924- "0: movl 32(%4), %%eax\n"
26925+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26926 " cmpl $67, %0\n"
26927 " jbe 2f\n"
26928- "1: movl 64(%4), %%eax\n"
26929+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26930 " .align 2,0x90\n"
26931- "2: movl 0(%4), %%eax\n"
26932- "21: movl 4(%4), %%edx\n"
26933+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26934+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26935 " movnti %%eax, 0(%3)\n"
26936 " movnti %%edx, 4(%3)\n"
26937- "3: movl 8(%4), %%eax\n"
26938- "31: movl 12(%4),%%edx\n"
26939+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26940+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26941 " movnti %%eax, 8(%3)\n"
26942 " movnti %%edx, 12(%3)\n"
26943- "4: movl 16(%4), %%eax\n"
26944- "41: movl 20(%4), %%edx\n"
26945+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26946+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26947 " movnti %%eax, 16(%3)\n"
26948 " movnti %%edx, 20(%3)\n"
26949- "10: movl 24(%4), %%eax\n"
26950- "51: movl 28(%4), %%edx\n"
26951+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26952+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26953 " movnti %%eax, 24(%3)\n"
26954 " movnti %%edx, 28(%3)\n"
26955- "11: movl 32(%4), %%eax\n"
26956- "61: movl 36(%4), %%edx\n"
26957+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26958+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26959 " movnti %%eax, 32(%3)\n"
26960 " movnti %%edx, 36(%3)\n"
26961- "12: movl 40(%4), %%eax\n"
26962- "71: movl 44(%4), %%edx\n"
26963+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26964+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26965 " movnti %%eax, 40(%3)\n"
26966 " movnti %%edx, 44(%3)\n"
26967- "13: movl 48(%4), %%eax\n"
26968- "81: movl 52(%4), %%edx\n"
26969+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26970+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26971 " movnti %%eax, 48(%3)\n"
26972 " movnti %%edx, 52(%3)\n"
26973- "14: movl 56(%4), %%eax\n"
26974- "91: movl 60(%4), %%edx\n"
26975+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26976+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26977 " movnti %%eax, 56(%3)\n"
26978 " movnti %%edx, 60(%3)\n"
26979 " addl $-64, %0\n"
26980@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26981 " shrl $2, %0\n"
26982 " andl $3, %%eax\n"
26983 " cld\n"
26984- "6: rep; movsl\n"
26985+ "6: rep; "__copyuser_seg" movsl\n"
26986 " movl %%eax,%0\n"
26987- "7: rep; movsb\n"
26988+ "7: rep; "__copyuser_seg" movsb\n"
26989 "8:\n"
26990 ".section .fixup,\"ax\"\n"
26991 "9: lea 0(%%eax,%0,4),%0\n"
26992@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26993 */
26994 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26995 unsigned long size);
26996-unsigned long __copy_user_intel(void __user *to, const void *from,
26997+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26998+ unsigned long size);
26999+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
27000 unsigned long size);
27001 unsigned long __copy_user_zeroing_intel_nocache(void *to,
27002 const void __user *from, unsigned long size);
27003 #endif /* CONFIG_X86_INTEL_USERCOPY */
27004
27005 /* Generic arbitrary sized copy. */
27006-#define __copy_user(to, from, size) \
27007+#define __copy_user(to, from, size, prefix, set, restore) \
27008 do { \
27009 int __d0, __d1, __d2; \
27010 __asm__ __volatile__( \
27011+ set \
27012 " cmp $7,%0\n" \
27013 " jbe 1f\n" \
27014 " movl %1,%0\n" \
27015 " negl %0\n" \
27016 " andl $7,%0\n" \
27017 " subl %0,%3\n" \
27018- "4: rep; movsb\n" \
27019+ "4: rep; "prefix"movsb\n" \
27020 " movl %3,%0\n" \
27021 " shrl $2,%0\n" \
27022 " andl $3,%3\n" \
27023 " .align 2,0x90\n" \
27024- "0: rep; movsl\n" \
27025+ "0: rep; "prefix"movsl\n" \
27026 " movl %3,%0\n" \
27027- "1: rep; movsb\n" \
27028+ "1: rep; "prefix"movsb\n" \
27029 "2:\n" \
27030+ restore \
27031 ".section .fixup,\"ax\"\n" \
27032 "5: addl %3,%0\n" \
27033 " jmp 2b\n" \
27034@@ -538,14 +650,14 @@ do { \
27035 " negl %0\n" \
27036 " andl $7,%0\n" \
27037 " subl %0,%3\n" \
27038- "4: rep; movsb\n" \
27039+ "4: rep; "__copyuser_seg"movsb\n" \
27040 " movl %3,%0\n" \
27041 " shrl $2,%0\n" \
27042 " andl $3,%3\n" \
27043 " .align 2,0x90\n" \
27044- "0: rep; movsl\n" \
27045+ "0: rep; "__copyuser_seg"movsl\n" \
27046 " movl %3,%0\n" \
27047- "1: rep; movsb\n" \
27048+ "1: rep; "__copyuser_seg"movsb\n" \
27049 "2:\n" \
27050 ".section .fixup,\"ax\"\n" \
27051 "5: addl %3,%0\n" \
27052@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
27053 {
27054 stac();
27055 if (movsl_is_ok(to, from, n))
27056- __copy_user(to, from, n);
27057+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
27058 else
27059- n = __copy_user_intel(to, from, n);
27060+ n = __generic_copy_to_user_intel(to, from, n);
27061 clac();
27062 return n;
27063 }
27064@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
27065 {
27066 stac();
27067 if (movsl_is_ok(to, from, n))
27068- __copy_user(to, from, n);
27069+ __copy_user(to, from, n, __copyuser_seg, "", "");
27070 else
27071- n = __copy_user_intel((void __user *)to,
27072- (const void *)from, n);
27073+ n = __generic_copy_from_user_intel(to, from, n);
27074 clac();
27075 return n;
27076 }
27077@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
27078 if (n > 64 && cpu_has_xmm2)
27079 n = __copy_user_intel_nocache(to, from, n);
27080 else
27081- __copy_user(to, from, n);
27082+ __copy_user(to, from, n, __copyuser_seg, "", "");
27083 #else
27084- __copy_user(to, from, n);
27085+ __copy_user(to, from, n, __copyuser_seg, "", "");
27086 #endif
27087 clac();
27088 return n;
27089 }
27090 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
27091
27092-/**
27093- * copy_to_user: - Copy a block of data into user space.
27094- * @to: Destination address, in user space.
27095- * @from: Source address, in kernel space.
27096- * @n: Number of bytes to copy.
27097- *
27098- * Context: User context only. This function may sleep.
27099- *
27100- * Copy data from kernel space to user space.
27101- *
27102- * Returns number of bytes that could not be copied.
27103- * On success, this will be zero.
27104- */
27105-unsigned long
27106-copy_to_user(void __user *to, const void *from, unsigned long n)
27107-{
27108- if (access_ok(VERIFY_WRITE, to, n))
27109- n = __copy_to_user(to, from, n);
27110- return n;
27111-}
27112-EXPORT_SYMBOL(copy_to_user);
27113-
27114-/**
27115- * copy_from_user: - Copy a block of data from user space.
27116- * @to: Destination address, in kernel space.
27117- * @from: Source address, in user space.
27118- * @n: Number of bytes to copy.
27119- *
27120- * Context: User context only. This function may sleep.
27121- *
27122- * Copy data from user space to kernel space.
27123- *
27124- * Returns number of bytes that could not be copied.
27125- * On success, this will be zero.
27126- *
27127- * If some data could not be copied, this function will pad the copied
27128- * data to the requested size using zero bytes.
27129- */
27130-unsigned long
27131-_copy_from_user(void *to, const void __user *from, unsigned long n)
27132-{
27133- if (access_ok(VERIFY_READ, from, n))
27134- n = __copy_from_user(to, from, n);
27135- else
27136- memset(to, 0, n);
27137- return n;
27138-}
27139-EXPORT_SYMBOL(_copy_from_user);
27140-
27141 void copy_from_user_overflow(void)
27142 {
27143 WARN(1, "Buffer overflow detected!\n");
27144 }
27145 EXPORT_SYMBOL(copy_from_user_overflow);
27146+
27147+void copy_to_user_overflow(void)
27148+{
27149+ WARN(1, "Buffer overflow detected!\n");
27150+}
27151+EXPORT_SYMBOL(copy_to_user_overflow);
27152+
27153+#ifdef CONFIG_PAX_MEMORY_UDEREF
27154+void __set_fs(mm_segment_t x)
27155+{
27156+ switch (x.seg) {
27157+ case 0:
27158+ loadsegment(gs, 0);
27159+ break;
27160+ case TASK_SIZE_MAX:
27161+ loadsegment(gs, __USER_DS);
27162+ break;
27163+ case -1UL:
27164+ loadsegment(gs, __KERNEL_DS);
27165+ break;
27166+ default:
27167+ BUG();
27168+ }
27169+ return;
27170+}
27171+EXPORT_SYMBOL(__set_fs);
27172+
27173+void set_fs(mm_segment_t x)
27174+{
27175+ current_thread_info()->addr_limit = x;
27176+ __set_fs(x);
27177+}
27178+EXPORT_SYMBOL(set_fs);
27179+#endif
27180diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27181index 906fea3..ee8a097 100644
27182--- a/arch/x86/lib/usercopy_64.c
27183+++ b/arch/x86/lib/usercopy_64.c
27184@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27185 _ASM_EXTABLE(0b,3b)
27186 _ASM_EXTABLE(1b,2b)
27187 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27188- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27189+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27190 [zero] "r" (0UL), [eight] "r" (8UL));
27191 clac();
27192 return size;
27193@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27194 }
27195 EXPORT_SYMBOL(clear_user);
27196
27197-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27198+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27199 {
27200- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27201- return copy_user_generic((__force void *)to, (__force void *)from, len);
27202- }
27203- return len;
27204+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27205+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27206+ return len;
27207 }
27208 EXPORT_SYMBOL(copy_in_user);
27209
27210@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27211 * it is not necessary to optimize tail handling.
27212 */
27213 unsigned long
27214-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27215+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27216 {
27217 char c;
27218 unsigned zero_len;
27219@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27220 clac();
27221 return len;
27222 }
27223+
27224+void copy_from_user_overflow(void)
27225+{
27226+ WARN(1, "Buffer overflow detected!\n");
27227+}
27228+EXPORT_SYMBOL(copy_from_user_overflow);
27229+
27230+void copy_to_user_overflow(void)
27231+{
27232+ WARN(1, "Buffer overflow detected!\n");
27233+}
27234+EXPORT_SYMBOL(copy_to_user_overflow);
27235diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27236index 903ec1e..c4166b2 100644
27237--- a/arch/x86/mm/extable.c
27238+++ b/arch/x86/mm/extable.c
27239@@ -6,12 +6,24 @@
27240 static inline unsigned long
27241 ex_insn_addr(const struct exception_table_entry *x)
27242 {
27243- return (unsigned long)&x->insn + x->insn;
27244+ unsigned long reloc = 0;
27245+
27246+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27247+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27248+#endif
27249+
27250+ return (unsigned long)&x->insn + x->insn + reloc;
27251 }
27252 static inline unsigned long
27253 ex_fixup_addr(const struct exception_table_entry *x)
27254 {
27255- return (unsigned long)&x->fixup + x->fixup;
27256+ unsigned long reloc = 0;
27257+
27258+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27259+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27260+#endif
27261+
27262+ return (unsigned long)&x->fixup + x->fixup + reloc;
27263 }
27264
27265 int fixup_exception(struct pt_regs *regs)
27266@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27267 unsigned long new_ip;
27268
27269 #ifdef CONFIG_PNPBIOS
27270- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27271+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27272 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27273 extern u32 pnp_bios_is_utter_crap;
27274 pnp_bios_is_utter_crap = 1;
27275@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27276 i += 4;
27277 p->fixup -= i;
27278 i += 4;
27279+
27280+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27281+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27282+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27283+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27284+#endif
27285+
27286 }
27287 }
27288
27289diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27290index 0e88336..2bb9777 100644
27291--- a/arch/x86/mm/fault.c
27292+++ b/arch/x86/mm/fault.c
27293@@ -13,12 +13,19 @@
27294 #include <linux/perf_event.h> /* perf_sw_event */
27295 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27296 #include <linux/prefetch.h> /* prefetchw */
27297+#include <linux/unistd.h>
27298+#include <linux/compiler.h>
27299
27300 #include <asm/traps.h> /* dotraplinkage, ... */
27301 #include <asm/pgalloc.h> /* pgd_*(), ... */
27302 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27303 #include <asm/fixmap.h> /* VSYSCALL_START */
27304 #include <asm/context_tracking.h> /* exception_enter(), ... */
27305+#include <asm/tlbflush.h>
27306+
27307+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27308+#include <asm/stacktrace.h>
27309+#endif
27310
27311 /*
27312 * Page fault error code bits:
27313@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27314 int ret = 0;
27315
27316 /* kprobe_running() needs smp_processor_id() */
27317- if (kprobes_built_in() && !user_mode_vm(regs)) {
27318+ if (kprobes_built_in() && !user_mode(regs)) {
27319 preempt_disable();
27320 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27321 ret = 1;
27322@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27323 return !instr_lo || (instr_lo>>1) == 1;
27324 case 0x00:
27325 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27326- if (probe_kernel_address(instr, opcode))
27327+ if (user_mode(regs)) {
27328+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27329+ return 0;
27330+ } else if (probe_kernel_address(instr, opcode))
27331 return 0;
27332
27333 *prefetch = (instr_lo == 0xF) &&
27334@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27335 while (instr < max_instr) {
27336 unsigned char opcode;
27337
27338- if (probe_kernel_address(instr, opcode))
27339+ if (user_mode(regs)) {
27340+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27341+ break;
27342+ } else if (probe_kernel_address(instr, opcode))
27343 break;
27344
27345 instr++;
27346@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27347 force_sig_info(si_signo, &info, tsk);
27348 }
27349
27350+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27351+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27352+#endif
27353+
27354+#ifdef CONFIG_PAX_EMUTRAMP
27355+static int pax_handle_fetch_fault(struct pt_regs *regs);
27356+#endif
27357+
27358+#ifdef CONFIG_PAX_PAGEEXEC
27359+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27360+{
27361+ pgd_t *pgd;
27362+ pud_t *pud;
27363+ pmd_t *pmd;
27364+
27365+ pgd = pgd_offset(mm, address);
27366+ if (!pgd_present(*pgd))
27367+ return NULL;
27368+ pud = pud_offset(pgd, address);
27369+ if (!pud_present(*pud))
27370+ return NULL;
27371+ pmd = pmd_offset(pud, address);
27372+ if (!pmd_present(*pmd))
27373+ return NULL;
27374+ return pmd;
27375+}
27376+#endif
27377+
27378 DEFINE_SPINLOCK(pgd_lock);
27379 LIST_HEAD(pgd_list);
27380
27381@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27382 for (address = VMALLOC_START & PMD_MASK;
27383 address >= TASK_SIZE && address < FIXADDR_TOP;
27384 address += PMD_SIZE) {
27385+
27386+#ifdef CONFIG_PAX_PER_CPU_PGD
27387+ unsigned long cpu;
27388+#else
27389 struct page *page;
27390+#endif
27391
27392 spin_lock(&pgd_lock);
27393+
27394+#ifdef CONFIG_PAX_PER_CPU_PGD
27395+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27396+ pgd_t *pgd = get_cpu_pgd(cpu);
27397+ pmd_t *ret;
27398+#else
27399 list_for_each_entry(page, &pgd_list, lru) {
27400+ pgd_t *pgd;
27401 spinlock_t *pgt_lock;
27402 pmd_t *ret;
27403
27404@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
27405 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27406
27407 spin_lock(pgt_lock);
27408- ret = vmalloc_sync_one(page_address(page), address);
27409+ pgd = page_address(page);
27410+#endif
27411+
27412+ ret = vmalloc_sync_one(pgd, address);
27413+
27414+#ifndef CONFIG_PAX_PER_CPU_PGD
27415 spin_unlock(pgt_lock);
27416+#endif
27417
27418 if (!ret)
27419 break;
27420@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27421 * an interrupt in the middle of a task switch..
27422 */
27423 pgd_paddr = read_cr3();
27424+
27425+#ifdef CONFIG_PAX_PER_CPU_PGD
27426+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27427+#endif
27428+
27429 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27430 if (!pmd_k)
27431 return -1;
27432@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27433 * happen within a race in page table update. In the later
27434 * case just flush:
27435 */
27436+
27437+#ifdef CONFIG_PAX_PER_CPU_PGD
27438+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27439+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27440+#else
27441 pgd = pgd_offset(current->active_mm, address);
27442+#endif
27443+
27444 pgd_ref = pgd_offset_k(address);
27445 if (pgd_none(*pgd_ref))
27446 return -1;
27447@@ -543,7 +614,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27448 static int is_errata100(struct pt_regs *regs, unsigned long address)
27449 {
27450 #ifdef CONFIG_X86_64
27451- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27452+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27453 return 1;
27454 #endif
27455 return 0;
27456@@ -570,7 +641,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27457 }
27458
27459 static const char nx_warning[] = KERN_CRIT
27460-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27461+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27462
27463 static void
27464 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27465@@ -579,15 +650,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27466 if (!oops_may_print())
27467 return;
27468
27469- if (error_code & PF_INSTR) {
27470+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27471 unsigned int level;
27472
27473 pte_t *pte = lookup_address(address, &level);
27474
27475 if (pte && pte_present(*pte) && !pte_exec(*pte))
27476- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27477+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27478 }
27479
27480+#ifdef CONFIG_PAX_KERNEXEC
27481+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27482+ if (current->signal->curr_ip)
27483+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27484+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27485+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27486+ else
27487+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27488+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27489+ }
27490+#endif
27491+
27492 printk(KERN_ALERT "BUG: unable to handle kernel ");
27493 if (address < PAGE_SIZE)
27494 printk(KERN_CONT "NULL pointer dereference");
27495@@ -750,6 +833,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27496 return;
27497 }
27498 #endif
27499+
27500+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27501+ if (pax_is_fetch_fault(regs, error_code, address)) {
27502+
27503+#ifdef CONFIG_PAX_EMUTRAMP
27504+ switch (pax_handle_fetch_fault(regs)) {
27505+ case 2:
27506+ return;
27507+ }
27508+#endif
27509+
27510+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27511+ do_group_exit(SIGKILL);
27512+ }
27513+#endif
27514+
27515 /* Kernel addresses are always protection faults: */
27516 if (address >= TASK_SIZE)
27517 error_code |= PF_PROT;
27518@@ -835,7 +934,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27519 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27520 printk(KERN_ERR
27521 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27522- tsk->comm, tsk->pid, address);
27523+ tsk->comm, task_pid_nr(tsk), address);
27524 code = BUS_MCEERR_AR;
27525 }
27526 #endif
27527@@ -898,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27528 return 1;
27529 }
27530
27531+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27532+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27533+{
27534+ pte_t *pte;
27535+ pmd_t *pmd;
27536+ spinlock_t *ptl;
27537+ unsigned char pte_mask;
27538+
27539+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27540+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27541+ return 0;
27542+
27543+ /* PaX: it's our fault, let's handle it if we can */
27544+
27545+ /* PaX: take a look at read faults before acquiring any locks */
27546+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27547+ /* instruction fetch attempt from a protected page in user mode */
27548+ up_read(&mm->mmap_sem);
27549+
27550+#ifdef CONFIG_PAX_EMUTRAMP
27551+ switch (pax_handle_fetch_fault(regs)) {
27552+ case 2:
27553+ return 1;
27554+ }
27555+#endif
27556+
27557+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27558+ do_group_exit(SIGKILL);
27559+ }
27560+
27561+ pmd = pax_get_pmd(mm, address);
27562+ if (unlikely(!pmd))
27563+ return 0;
27564+
27565+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27566+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27567+ pte_unmap_unlock(pte, ptl);
27568+ return 0;
27569+ }
27570+
27571+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27572+ /* write attempt to a protected page in user mode */
27573+ pte_unmap_unlock(pte, ptl);
27574+ return 0;
27575+ }
27576+
27577+#ifdef CONFIG_SMP
27578+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27579+#else
27580+ if (likely(address > get_limit(regs->cs)))
27581+#endif
27582+ {
27583+ set_pte(pte, pte_mkread(*pte));
27584+ __flush_tlb_one(address);
27585+ pte_unmap_unlock(pte, ptl);
27586+ up_read(&mm->mmap_sem);
27587+ return 1;
27588+ }
27589+
27590+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27591+
27592+ /*
27593+ * PaX: fill DTLB with user rights and retry
27594+ */
27595+ __asm__ __volatile__ (
27596+ "orb %2,(%1)\n"
27597+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27598+/*
27599+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27600+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27601+ * page fault when examined during a TLB load attempt. this is true not only
27602+ * for PTEs holding a non-present entry but also present entries that will
27603+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27604+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27605+ * for our target pages since their PTEs are simply not in the TLBs at all.
27606+
27607+ * the best thing in omitting it is that we gain around 15-20% speed in the
27608+ * fast path of the page fault handler and can get rid of tracing since we
27609+ * can no longer flush unintended entries.
27610+ */
27611+ "invlpg (%0)\n"
27612+#endif
27613+ __copyuser_seg"testb $0,(%0)\n"
27614+ "xorb %3,(%1)\n"
27615+ :
27616+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27617+ : "memory", "cc");
27618+ pte_unmap_unlock(pte, ptl);
27619+ up_read(&mm->mmap_sem);
27620+ return 1;
27621+}
27622+#endif
27623+
27624 /*
27625 * Handle a spurious fault caused by a stale TLB entry.
27626 *
27627@@ -964,6 +1156,9 @@ int show_unhandled_signals = 1;
27628 static inline int
27629 access_error(unsigned long error_code, struct vm_area_struct *vma)
27630 {
27631+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27632+ return 1;
27633+
27634 if (error_code & PF_WRITE) {
27635 /* write, present and write, not present: */
27636 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27637@@ -992,7 +1187,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27638 if (error_code & PF_USER)
27639 return false;
27640
27641- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27642+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27643 return false;
27644
27645 return true;
27646@@ -1008,18 +1203,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27647 {
27648 struct vm_area_struct *vma;
27649 struct task_struct *tsk;
27650- unsigned long address;
27651 struct mm_struct *mm;
27652 int fault;
27653 int write = error_code & PF_WRITE;
27654 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27655 (write ? FAULT_FLAG_WRITE : 0);
27656
27657- tsk = current;
27658- mm = tsk->mm;
27659-
27660 /* Get the faulting address: */
27661- address = read_cr2();
27662+ unsigned long address = read_cr2();
27663+
27664+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27665+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
27666+ if (!search_exception_tables(regs->ip)) {
27667+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27668+ bad_area_nosemaphore(regs, error_code, address);
27669+ return;
27670+ }
27671+ if (address < pax_user_shadow_base) {
27672+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27673+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27674+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27675+ } else
27676+ address -= pax_user_shadow_base;
27677+ }
27678+#endif
27679+
27680+ tsk = current;
27681+ mm = tsk->mm;
27682
27683 /*
27684 * Detect and handle instructions that would cause a page fault for
27685@@ -1080,7 +1290,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27686 * User-mode registers count as a user access even for any
27687 * potential system fault or CPU buglet:
27688 */
27689- if (user_mode_vm(regs)) {
27690+ if (user_mode(regs)) {
27691 local_irq_enable();
27692 error_code |= PF_USER;
27693 } else {
27694@@ -1142,6 +1352,11 @@ retry:
27695 might_sleep();
27696 }
27697
27698+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27699+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27700+ return;
27701+#endif
27702+
27703 vma = find_vma(mm, address);
27704 if (unlikely(!vma)) {
27705 bad_area(regs, error_code, address);
27706@@ -1153,18 +1368,24 @@ retry:
27707 bad_area(regs, error_code, address);
27708 return;
27709 }
27710- if (error_code & PF_USER) {
27711- /*
27712- * Accessing the stack below %sp is always a bug.
27713- * The large cushion allows instructions like enter
27714- * and pusha to work. ("enter $65535, $31" pushes
27715- * 32 pointers and then decrements %sp by 65535.)
27716- */
27717- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27718- bad_area(regs, error_code, address);
27719- return;
27720- }
27721+ /*
27722+ * Accessing the stack below %sp is always a bug.
27723+ * The large cushion allows instructions like enter
27724+ * and pusha to work. ("enter $65535, $31" pushes
27725+ * 32 pointers and then decrements %sp by 65535.)
27726+ */
27727+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27728+ bad_area(regs, error_code, address);
27729+ return;
27730 }
27731+
27732+#ifdef CONFIG_PAX_SEGMEXEC
27733+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27734+ bad_area(regs, error_code, address);
27735+ return;
27736+ }
27737+#endif
27738+
27739 if (unlikely(expand_stack(vma, address))) {
27740 bad_area(regs, error_code, address);
27741 return;
27742@@ -1228,3 +1449,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27743 __do_page_fault(regs, error_code);
27744 exception_exit(regs);
27745 }
27746+
27747+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27748+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27749+{
27750+ struct mm_struct *mm = current->mm;
27751+ unsigned long ip = regs->ip;
27752+
27753+ if (v8086_mode(regs))
27754+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27755+
27756+#ifdef CONFIG_PAX_PAGEEXEC
27757+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27758+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27759+ return true;
27760+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27761+ return true;
27762+ return false;
27763+ }
27764+#endif
27765+
27766+#ifdef CONFIG_PAX_SEGMEXEC
27767+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27768+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27769+ return true;
27770+ return false;
27771+ }
27772+#endif
27773+
27774+ return false;
27775+}
27776+#endif
27777+
27778+#ifdef CONFIG_PAX_EMUTRAMP
27779+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27780+{
27781+ int err;
27782+
27783+ do { /* PaX: libffi trampoline emulation */
27784+ unsigned char mov, jmp;
27785+ unsigned int addr1, addr2;
27786+
27787+#ifdef CONFIG_X86_64
27788+ if ((regs->ip + 9) >> 32)
27789+ break;
27790+#endif
27791+
27792+ err = get_user(mov, (unsigned char __user *)regs->ip);
27793+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27794+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27795+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27796+
27797+ if (err)
27798+ break;
27799+
27800+ if (mov == 0xB8 && jmp == 0xE9) {
27801+ regs->ax = addr1;
27802+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27803+ return 2;
27804+ }
27805+ } while (0);
27806+
27807+ do { /* PaX: gcc trampoline emulation #1 */
27808+ unsigned char mov1, mov2;
27809+ unsigned short jmp;
27810+ unsigned int addr1, addr2;
27811+
27812+#ifdef CONFIG_X86_64
27813+ if ((regs->ip + 11) >> 32)
27814+ break;
27815+#endif
27816+
27817+ err = get_user(mov1, (unsigned char __user *)regs->ip);
27818+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27819+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27820+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27821+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27822+
27823+ if (err)
27824+ break;
27825+
27826+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27827+ regs->cx = addr1;
27828+ regs->ax = addr2;
27829+ regs->ip = addr2;
27830+ return 2;
27831+ }
27832+ } while (0);
27833+
27834+ do { /* PaX: gcc trampoline emulation #2 */
27835+ unsigned char mov, jmp;
27836+ unsigned int addr1, addr2;
27837+
27838+#ifdef CONFIG_X86_64
27839+ if ((regs->ip + 9) >> 32)
27840+ break;
27841+#endif
27842+
27843+ err = get_user(mov, (unsigned char __user *)regs->ip);
27844+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27845+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27846+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27847+
27848+ if (err)
27849+ break;
27850+
27851+ if (mov == 0xB9 && jmp == 0xE9) {
27852+ regs->cx = addr1;
27853+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27854+ return 2;
27855+ }
27856+ } while (0);
27857+
27858+ return 1; /* PaX in action */
27859+}
27860+
27861+#ifdef CONFIG_X86_64
27862+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27863+{
27864+ int err;
27865+
27866+ do { /* PaX: libffi trampoline emulation */
27867+ unsigned short mov1, mov2, jmp1;
27868+ unsigned char stcclc, jmp2;
27869+ unsigned long addr1, addr2;
27870+
27871+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27872+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27873+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27874+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27875+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27876+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27877+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27878+
27879+ if (err)
27880+ break;
27881+
27882+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27883+ regs->r11 = addr1;
27884+ regs->r10 = addr2;
27885+ if (stcclc == 0xF8)
27886+ regs->flags &= ~X86_EFLAGS_CF;
27887+ else
27888+ regs->flags |= X86_EFLAGS_CF;
27889+ regs->ip = addr1;
27890+ return 2;
27891+ }
27892+ } while (0);
27893+
27894+ do { /* PaX: gcc trampoline emulation #1 */
27895+ unsigned short mov1, mov2, jmp1;
27896+ unsigned char jmp2;
27897+ unsigned int addr1;
27898+ unsigned long addr2;
27899+
27900+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27901+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27902+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27903+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27904+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27905+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27906+
27907+ if (err)
27908+ break;
27909+
27910+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27911+ regs->r11 = addr1;
27912+ regs->r10 = addr2;
27913+ regs->ip = addr1;
27914+ return 2;
27915+ }
27916+ } while (0);
27917+
27918+ do { /* PaX: gcc trampoline emulation #2 */
27919+ unsigned short mov1, mov2, jmp1;
27920+ unsigned char jmp2;
27921+ unsigned long addr1, addr2;
27922+
27923+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27924+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27925+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27926+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27927+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27928+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27929+
27930+ if (err)
27931+ break;
27932+
27933+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27934+ regs->r11 = addr1;
27935+ regs->r10 = addr2;
27936+ regs->ip = addr1;
27937+ return 2;
27938+ }
27939+ } while (0);
27940+
27941+ return 1; /* PaX in action */
27942+}
27943+#endif
27944+
27945+/*
27946+ * PaX: decide what to do with offenders (regs->ip = fault address)
27947+ *
27948+ * returns 1 when task should be killed
27949+ * 2 when gcc trampoline was detected
27950+ */
27951+static int pax_handle_fetch_fault(struct pt_regs *regs)
27952+{
27953+ if (v8086_mode(regs))
27954+ return 1;
27955+
27956+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27957+ return 1;
27958+
27959+#ifdef CONFIG_X86_32
27960+ return pax_handle_fetch_fault_32(regs);
27961+#else
27962+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27963+ return pax_handle_fetch_fault_32(regs);
27964+ else
27965+ return pax_handle_fetch_fault_64(regs);
27966+#endif
27967+}
27968+#endif
27969+
27970+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27971+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27972+{
27973+ long i;
27974+
27975+ printk(KERN_ERR "PAX: bytes at PC: ");
27976+ for (i = 0; i < 20; i++) {
27977+ unsigned char c;
27978+ if (get_user(c, (unsigned char __force_user *)pc+i))
27979+ printk(KERN_CONT "?? ");
27980+ else
27981+ printk(KERN_CONT "%02x ", c);
27982+ }
27983+ printk("\n");
27984+
27985+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27986+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27987+ unsigned long c;
27988+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27989+#ifdef CONFIG_X86_32
27990+ printk(KERN_CONT "???????? ");
27991+#else
27992+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27993+ printk(KERN_CONT "???????? ???????? ");
27994+ else
27995+ printk(KERN_CONT "???????????????? ");
27996+#endif
27997+ } else {
27998+#ifdef CONFIG_X86_64
27999+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
28000+ printk(KERN_CONT "%08x ", (unsigned int)c);
28001+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
28002+ } else
28003+#endif
28004+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
28005+ }
28006+ }
28007+ printk("\n");
28008+}
28009+#endif
28010+
28011+/**
28012+ * probe_kernel_write(): safely attempt to write to a location
28013+ * @dst: address to write to
28014+ * @src: pointer to the data that shall be written
28015+ * @size: size of the data chunk
28016+ *
28017+ * Safely write to address @dst from the buffer at @src. If a kernel fault
28018+ * happens, handle that and return -EFAULT.
28019+ */
28020+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
28021+{
28022+ long ret;
28023+ mm_segment_t old_fs = get_fs();
28024+
28025+ set_fs(KERNEL_DS);
28026+ pagefault_disable();
28027+ pax_open_kernel();
28028+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
28029+ pax_close_kernel();
28030+ pagefault_enable();
28031+ set_fs(old_fs);
28032+
28033+ return ret ? -EFAULT : 0;
28034+}
28035diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
28036index dd74e46..7d26398 100644
28037--- a/arch/x86/mm/gup.c
28038+++ b/arch/x86/mm/gup.c
28039@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
28040 addr = start;
28041 len = (unsigned long) nr_pages << PAGE_SHIFT;
28042 end = start + len;
28043- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28044+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28045 (void __user *)start, len)))
28046 return 0;
28047
28048diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
28049index 6f31ee5..8ee4164 100644
28050--- a/arch/x86/mm/highmem_32.c
28051+++ b/arch/x86/mm/highmem_32.c
28052@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
28053 idx = type + KM_TYPE_NR*smp_processor_id();
28054 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28055 BUG_ON(!pte_none(*(kmap_pte-idx)));
28056+
28057+ pax_open_kernel();
28058 set_pte(kmap_pte-idx, mk_pte(page, prot));
28059+ pax_close_kernel();
28060+
28061 arch_flush_lazy_mmu_mode();
28062
28063 return (void *)vaddr;
28064diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
28065index ae1aa71..d9bea75 100644
28066--- a/arch/x86/mm/hugetlbpage.c
28067+++ b/arch/x86/mm/hugetlbpage.c
28068@@ -271,23 +271,30 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
28069 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
28070 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
28071 unsigned long addr, unsigned long len,
28072- unsigned long pgoff, unsigned long flags)
28073+ unsigned long pgoff, unsigned long flags, unsigned long offset)
28074 {
28075 struct hstate *h = hstate_file(file);
28076 struct vm_unmapped_area_info info;
28077-
28078+
28079 info.flags = 0;
28080 info.length = len;
28081 info.low_limit = TASK_UNMAPPED_BASE;
28082+
28083+#ifdef CONFIG_PAX_RANDMMAP
28084+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28085+ info.low_limit += current->mm->delta_mmap;
28086+#endif
28087+
28088 info.high_limit = TASK_SIZE;
28089 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28090 info.align_offset = 0;
28091+ info.threadstack_offset = offset;
28092 return vm_unmapped_area(&info);
28093 }
28094
28095 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28096 unsigned long addr0, unsigned long len,
28097- unsigned long pgoff, unsigned long flags)
28098+ unsigned long pgoff, unsigned long flags, unsigned long offset)
28099 {
28100 struct hstate *h = hstate_file(file);
28101 struct vm_unmapped_area_info info;
28102@@ -299,6 +306,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28103 info.high_limit = current->mm->mmap_base;
28104 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28105 info.align_offset = 0;
28106+ info.threadstack_offset = offset;
28107 addr = vm_unmapped_area(&info);
28108
28109 /*
28110@@ -311,6 +319,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28111 VM_BUG_ON(addr != -ENOMEM);
28112 info.flags = 0;
28113 info.low_limit = TASK_UNMAPPED_BASE;
28114+
28115+#ifdef CONFIG_PAX_RANDMMAP
28116+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28117+ info.low_limit += current->mm->delta_mmap;
28118+#endif
28119+
28120 info.high_limit = TASK_SIZE;
28121 addr = vm_unmapped_area(&info);
28122 }
28123@@ -325,10 +339,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28124 struct hstate *h = hstate_file(file);
28125 struct mm_struct *mm = current->mm;
28126 struct vm_area_struct *vma;
28127+ unsigned long pax_task_size = TASK_SIZE;
28128+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
28129
28130 if (len & ~huge_page_mask(h))
28131 return -EINVAL;
28132- if (len > TASK_SIZE)
28133+
28134+#ifdef CONFIG_PAX_SEGMEXEC
28135+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28136+ pax_task_size = SEGMEXEC_TASK_SIZE;
28137+#endif
28138+
28139+ pax_task_size -= PAGE_SIZE;
28140+
28141+ if (len > pax_task_size)
28142 return -ENOMEM;
28143
28144 if (flags & MAP_FIXED) {
28145@@ -337,19 +361,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28146 return addr;
28147 }
28148
28149+#ifdef CONFIG_PAX_RANDMMAP
28150+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28151+#endif
28152+
28153 if (addr) {
28154 addr = ALIGN(addr, huge_page_size(h));
28155 vma = find_vma(mm, addr);
28156- if (TASK_SIZE - len >= addr &&
28157- (!vma || addr + len <= vma->vm_start))
28158+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28159 return addr;
28160 }
28161 if (mm->get_unmapped_area == arch_get_unmapped_area)
28162 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
28163- pgoff, flags);
28164+ pgoff, flags, offset);
28165 else
28166 return hugetlb_get_unmapped_area_topdown(file, addr, len,
28167- pgoff, flags);
28168+ pgoff, flags, offset);
28169 }
28170
28171 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
28172diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
28173index 0c13708..ca05f23 100644
28174--- a/arch/x86/mm/init.c
28175+++ b/arch/x86/mm/init.c
28176@@ -4,6 +4,7 @@
28177 #include <linux/swap.h>
28178 #include <linux/memblock.h>
28179 #include <linux/bootmem.h> /* for max_low_pfn */
28180+#include <linux/tboot.h>
28181
28182 #include <asm/cacheflush.h>
28183 #include <asm/e820.h>
28184@@ -17,6 +18,8 @@
28185 #include <asm/proto.h>
28186 #include <asm/dma.h> /* for MAX_DMA_PFN */
28187 #include <asm/microcode.h>
28188+#include <asm/desc.h>
28189+#include <asm/bios_ebda.h>
28190
28191 #include "mm_internal.h"
28192
28193@@ -448,7 +451,15 @@ void __init init_mem_mapping(void)
28194 early_ioremap_page_table_range_init();
28195 #endif
28196
28197+#ifdef CONFIG_PAX_PER_CPU_PGD
28198+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28199+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28200+ KERNEL_PGD_PTRS);
28201+ load_cr3(get_cpu_pgd(0));
28202+#else
28203 load_cr3(swapper_pg_dir);
28204+#endif
28205+
28206 __flush_tlb_all();
28207
28208 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
28209@@ -464,10 +475,40 @@ void __init init_mem_mapping(void)
28210 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
28211 * mmio resources as well as potential bios/acpi data regions.
28212 */
28213+
28214+#ifdef CONFIG_GRKERNSEC_KMEM
28215+static unsigned int ebda_start __read_only;
28216+static unsigned int ebda_end __read_only;
28217+#endif
28218+
28219 int devmem_is_allowed(unsigned long pagenr)
28220 {
28221- if (pagenr < 256)
28222+#ifdef CONFIG_GRKERNSEC_KMEM
28223+ /* allow BDA */
28224+ if (!pagenr)
28225 return 1;
28226+ /* allow EBDA */
28227+ if (pagenr >= ebda_start && pagenr < ebda_end)
28228+ return 1;
28229+ /* if tboot is in use, allow access to its hardcoded serial log range */
28230+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28231+ return 1;
28232+#else
28233+ if (!pagenr)
28234+ return 1;
28235+#ifdef CONFIG_VM86
28236+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28237+ return 1;
28238+#endif
28239+#endif
28240+
28241+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28242+ return 1;
28243+#ifdef CONFIG_GRKERNSEC_KMEM
28244+ /* throw out everything else below 1MB */
28245+ if (pagenr <= 256)
28246+ return 0;
28247+#endif
28248 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28249 return 0;
28250 if (!page_is_ram(pagenr))
28251@@ -524,8 +565,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28252 #endif
28253 }
28254
28255+#ifdef CONFIG_GRKERNSEC_KMEM
28256+static inline void gr_init_ebda(void)
28257+{
28258+ unsigned int ebda_addr;
28259+ unsigned int ebda_size = 0;
28260+
28261+ ebda_addr = get_bios_ebda();
28262+ if (ebda_addr) {
28263+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28264+ ebda_size <<= 10;
28265+ }
28266+ if (ebda_addr && ebda_size) {
28267+ ebda_start = ebda_addr >> PAGE_SHIFT;
28268+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28269+ } else {
28270+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28271+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28272+ }
28273+}
28274+#else
28275+static inline void gr_init_ebda(void) { }
28276+#endif
28277+
28278 void free_initmem(void)
28279 {
28280+#ifdef CONFIG_PAX_KERNEXEC
28281+#ifdef CONFIG_X86_32
28282+ /* PaX: limit KERNEL_CS to actual size */
28283+ unsigned long addr, limit;
28284+ struct desc_struct d;
28285+ int cpu;
28286+#else
28287+ pgd_t *pgd;
28288+ pud_t *pud;
28289+ pmd_t *pmd;
28290+ unsigned long addr, end;
28291+#endif
28292+#endif
28293+
28294+ gr_init_ebda();
28295+
28296+#ifdef CONFIG_PAX_KERNEXEC
28297+#ifdef CONFIG_X86_32
28298+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28299+ limit = (limit - 1UL) >> PAGE_SHIFT;
28300+
28301+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28302+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28303+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28304+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28305+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28306+ }
28307+
28308+ /* PaX: make KERNEL_CS read-only */
28309+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28310+ if (!paravirt_enabled())
28311+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28312+/*
28313+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28314+ pgd = pgd_offset_k(addr);
28315+ pud = pud_offset(pgd, addr);
28316+ pmd = pmd_offset(pud, addr);
28317+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28318+ }
28319+*/
28320+#ifdef CONFIG_X86_PAE
28321+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28322+/*
28323+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28324+ pgd = pgd_offset_k(addr);
28325+ pud = pud_offset(pgd, addr);
28326+ pmd = pmd_offset(pud, addr);
28327+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28328+ }
28329+*/
28330+#endif
28331+
28332+#ifdef CONFIG_MODULES
28333+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28334+#endif
28335+
28336+#else
28337+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28338+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28339+ pgd = pgd_offset_k(addr);
28340+ pud = pud_offset(pgd, addr);
28341+ pmd = pmd_offset(pud, addr);
28342+ if (!pmd_present(*pmd))
28343+ continue;
28344+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28345+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28346+ else
28347+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28348+ }
28349+
28350+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28351+ end = addr + KERNEL_IMAGE_SIZE;
28352+ for (; addr < end; addr += PMD_SIZE) {
28353+ pgd = pgd_offset_k(addr);
28354+ pud = pud_offset(pgd, addr);
28355+ pmd = pmd_offset(pud, addr);
28356+ if (!pmd_present(*pmd))
28357+ continue;
28358+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28359+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28360+ }
28361+#endif
28362+
28363+ flush_tlb_all();
28364+#endif
28365+
28366 free_init_pages("unused kernel memory",
28367 (unsigned long)(&__init_begin),
28368 (unsigned long)(&__init_end));
28369diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28370index 2d19001..e549d98 100644
28371--- a/arch/x86/mm/init_32.c
28372+++ b/arch/x86/mm/init_32.c
28373@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
28374 bool __read_mostly __vmalloc_start_set = false;
28375
28376 /*
28377- * Creates a middle page table and puts a pointer to it in the
28378- * given global directory entry. This only returns the gd entry
28379- * in non-PAE compilation mode, since the middle layer is folded.
28380- */
28381-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28382-{
28383- pud_t *pud;
28384- pmd_t *pmd_table;
28385-
28386-#ifdef CONFIG_X86_PAE
28387- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28388- pmd_table = (pmd_t *)alloc_low_page();
28389- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28390- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28391- pud = pud_offset(pgd, 0);
28392- BUG_ON(pmd_table != pmd_offset(pud, 0));
28393-
28394- return pmd_table;
28395- }
28396-#endif
28397- pud = pud_offset(pgd, 0);
28398- pmd_table = pmd_offset(pud, 0);
28399-
28400- return pmd_table;
28401-}
28402-
28403-/*
28404 * Create a page table and place a pointer to it in a middle page
28405 * directory entry:
28406 */
28407@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28408 pte_t *page_table = (pte_t *)alloc_low_page();
28409
28410 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28411+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28412+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28413+#else
28414 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28415+#endif
28416 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28417 }
28418
28419 return pte_offset_kernel(pmd, 0);
28420 }
28421
28422+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28423+{
28424+ pud_t *pud;
28425+ pmd_t *pmd_table;
28426+
28427+ pud = pud_offset(pgd, 0);
28428+ pmd_table = pmd_offset(pud, 0);
28429+
28430+ return pmd_table;
28431+}
28432+
28433 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28434 {
28435 int pgd_idx = pgd_index(vaddr);
28436@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28437 int pgd_idx, pmd_idx;
28438 unsigned long vaddr;
28439 pgd_t *pgd;
28440+ pud_t *pud;
28441 pmd_t *pmd;
28442 pte_t *pte = NULL;
28443 unsigned long count = page_table_range_init_count(start, end);
28444@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28445 pgd = pgd_base + pgd_idx;
28446
28447 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28448- pmd = one_md_table_init(pgd);
28449- pmd = pmd + pmd_index(vaddr);
28450+ pud = pud_offset(pgd, vaddr);
28451+ pmd = pmd_offset(pud, vaddr);
28452+
28453+#ifdef CONFIG_X86_PAE
28454+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28455+#endif
28456+
28457 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28458 pmd++, pmd_idx++) {
28459 pte = page_table_kmap_check(one_page_table_init(pmd),
28460@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28461 }
28462 }
28463
28464-static inline int is_kernel_text(unsigned long addr)
28465+static inline int is_kernel_text(unsigned long start, unsigned long end)
28466 {
28467- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28468- return 1;
28469- return 0;
28470+ if ((start > ktla_ktva((unsigned long)_etext) ||
28471+ end <= ktla_ktva((unsigned long)_stext)) &&
28472+ (start > ktla_ktva((unsigned long)_einittext) ||
28473+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28474+
28475+#ifdef CONFIG_ACPI_SLEEP
28476+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28477+#endif
28478+
28479+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28480+ return 0;
28481+ return 1;
28482 }
28483
28484 /*
28485@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
28486 unsigned long last_map_addr = end;
28487 unsigned long start_pfn, end_pfn;
28488 pgd_t *pgd_base = swapper_pg_dir;
28489- int pgd_idx, pmd_idx, pte_ofs;
28490+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28491 unsigned long pfn;
28492 pgd_t *pgd;
28493+ pud_t *pud;
28494 pmd_t *pmd;
28495 pte_t *pte;
28496 unsigned pages_2m, pages_4k;
28497@@ -291,8 +295,13 @@ repeat:
28498 pfn = start_pfn;
28499 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28500 pgd = pgd_base + pgd_idx;
28501- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28502- pmd = one_md_table_init(pgd);
28503+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28504+ pud = pud_offset(pgd, 0);
28505+ pmd = pmd_offset(pud, 0);
28506+
28507+#ifdef CONFIG_X86_PAE
28508+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28509+#endif
28510
28511 if (pfn >= end_pfn)
28512 continue;
28513@@ -304,14 +313,13 @@ repeat:
28514 #endif
28515 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28516 pmd++, pmd_idx++) {
28517- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28518+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28519
28520 /*
28521 * Map with big pages if possible, otherwise
28522 * create normal page tables:
28523 */
28524 if (use_pse) {
28525- unsigned int addr2;
28526 pgprot_t prot = PAGE_KERNEL_LARGE;
28527 /*
28528 * first pass will use the same initial
28529@@ -322,11 +330,7 @@ repeat:
28530 _PAGE_PSE);
28531
28532 pfn &= PMD_MASK >> PAGE_SHIFT;
28533- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28534- PAGE_OFFSET + PAGE_SIZE-1;
28535-
28536- if (is_kernel_text(addr) ||
28537- is_kernel_text(addr2))
28538+ if (is_kernel_text(address, address + PMD_SIZE))
28539 prot = PAGE_KERNEL_LARGE_EXEC;
28540
28541 pages_2m++;
28542@@ -343,7 +347,7 @@ repeat:
28543 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28544 pte += pte_ofs;
28545 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28546- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28547+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28548 pgprot_t prot = PAGE_KERNEL;
28549 /*
28550 * first pass will use the same initial
28551@@ -351,7 +355,7 @@ repeat:
28552 */
28553 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28554
28555- if (is_kernel_text(addr))
28556+ if (is_kernel_text(address, address + PAGE_SIZE))
28557 prot = PAGE_KERNEL_EXEC;
28558
28559 pages_4k++;
28560@@ -482,7 +486,7 @@ void __init native_pagetable_init(void)
28561
28562 pud = pud_offset(pgd, va);
28563 pmd = pmd_offset(pud, va);
28564- if (!pmd_present(*pmd))
28565+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
28566 break;
28567
28568 /* should not be large page here */
28569@@ -540,12 +544,10 @@ void __init early_ioremap_page_table_range_init(void)
28570
28571 static void __init pagetable_init(void)
28572 {
28573- pgd_t *pgd_base = swapper_pg_dir;
28574-
28575- permanent_kmaps_init(pgd_base);
28576+ permanent_kmaps_init(swapper_pg_dir);
28577 }
28578
28579-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28580+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28581 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28582
28583 /* user-defined highmem size */
28584@@ -780,7 +782,7 @@ void __init mem_init(void)
28585 after_bootmem = 1;
28586
28587 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28588- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28589+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28590 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28591
28592 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28593@@ -821,10 +823,10 @@ void __init mem_init(void)
28594 ((unsigned long)&__init_end -
28595 (unsigned long)&__init_begin) >> 10,
28596
28597- (unsigned long)&_etext, (unsigned long)&_edata,
28598- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28599+ (unsigned long)&_sdata, (unsigned long)&_edata,
28600+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28601
28602- (unsigned long)&_text, (unsigned long)&_etext,
28603+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28604 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28605
28606 /*
28607@@ -914,6 +916,7 @@ void set_kernel_text_rw(void)
28608 if (!kernel_set_to_readonly)
28609 return;
28610
28611+ start = ktla_ktva(start);
28612 pr_debug("Set kernel text: %lx - %lx for read write\n",
28613 start, start+size);
28614
28615@@ -928,6 +931,7 @@ void set_kernel_text_ro(void)
28616 if (!kernel_set_to_readonly)
28617 return;
28618
28619+ start = ktla_ktva(start);
28620 pr_debug("Set kernel text: %lx - %lx for read only\n",
28621 start, start+size);
28622
28623@@ -956,6 +960,7 @@ void mark_rodata_ro(void)
28624 unsigned long start = PFN_ALIGN(_text);
28625 unsigned long size = PFN_ALIGN(_etext) - start;
28626
28627+ start = ktla_ktva(start);
28628 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28629 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28630 size >> 10);
28631diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28632index 474e28f..f016b6e 100644
28633--- a/arch/x86/mm/init_64.c
28634+++ b/arch/x86/mm/init_64.c
28635@@ -150,7 +150,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28636 * around without checking the pgd every time.
28637 */
28638
28639-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28640+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28641 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28642
28643 int force_personality32;
28644@@ -183,12 +183,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28645
28646 for (address = start; address <= end; address += PGDIR_SIZE) {
28647 const pgd_t *pgd_ref = pgd_offset_k(address);
28648+
28649+#ifdef CONFIG_PAX_PER_CPU_PGD
28650+ unsigned long cpu;
28651+#else
28652 struct page *page;
28653+#endif
28654
28655 if (pgd_none(*pgd_ref))
28656 continue;
28657
28658 spin_lock(&pgd_lock);
28659+
28660+#ifdef CONFIG_PAX_PER_CPU_PGD
28661+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28662+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28663+#else
28664 list_for_each_entry(page, &pgd_list, lru) {
28665 pgd_t *pgd;
28666 spinlock_t *pgt_lock;
28667@@ -197,6 +207,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28668 /* the pgt_lock only for Xen */
28669 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28670 spin_lock(pgt_lock);
28671+#endif
28672
28673 if (pgd_none(*pgd))
28674 set_pgd(pgd, *pgd_ref);
28675@@ -204,7 +215,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28676 BUG_ON(pgd_page_vaddr(*pgd)
28677 != pgd_page_vaddr(*pgd_ref));
28678
28679+#ifndef CONFIG_PAX_PER_CPU_PGD
28680 spin_unlock(pgt_lock);
28681+#endif
28682+
28683 }
28684 spin_unlock(&pgd_lock);
28685 }
28686@@ -237,7 +251,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28687 {
28688 if (pgd_none(*pgd)) {
28689 pud_t *pud = (pud_t *)spp_getpage();
28690- pgd_populate(&init_mm, pgd, pud);
28691+ pgd_populate_kernel(&init_mm, pgd, pud);
28692 if (pud != pud_offset(pgd, 0))
28693 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28694 pud, pud_offset(pgd, 0));
28695@@ -249,7 +263,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28696 {
28697 if (pud_none(*pud)) {
28698 pmd_t *pmd = (pmd_t *) spp_getpage();
28699- pud_populate(&init_mm, pud, pmd);
28700+ pud_populate_kernel(&init_mm, pud, pmd);
28701 if (pmd != pmd_offset(pud, 0))
28702 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28703 pmd, pmd_offset(pud, 0));
28704@@ -278,7 +292,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28705 pmd = fill_pmd(pud, vaddr);
28706 pte = fill_pte(pmd, vaddr);
28707
28708+ pax_open_kernel();
28709 set_pte(pte, new_pte);
28710+ pax_close_kernel();
28711
28712 /*
28713 * It's enough to flush this one mapping.
28714@@ -337,14 +353,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28715 pgd = pgd_offset_k((unsigned long)__va(phys));
28716 if (pgd_none(*pgd)) {
28717 pud = (pud_t *) spp_getpage();
28718- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28719- _PAGE_USER));
28720+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28721 }
28722 pud = pud_offset(pgd, (unsigned long)__va(phys));
28723 if (pud_none(*pud)) {
28724 pmd = (pmd_t *) spp_getpage();
28725- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28726- _PAGE_USER));
28727+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28728 }
28729 pmd = pmd_offset(pud, phys);
28730 BUG_ON(!pmd_none(*pmd));
28731@@ -585,7 +599,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28732 prot);
28733
28734 spin_lock(&init_mm.page_table_lock);
28735- pud_populate(&init_mm, pud, pmd);
28736+ pud_populate_kernel(&init_mm, pud, pmd);
28737 spin_unlock(&init_mm.page_table_lock);
28738 }
28739 __flush_tlb_all();
28740@@ -626,7 +640,7 @@ kernel_physical_mapping_init(unsigned long start,
28741 page_size_mask);
28742
28743 spin_lock(&init_mm.page_table_lock);
28744- pgd_populate(&init_mm, pgd, pud);
28745+ pgd_populate_kernel(&init_mm, pgd, pud);
28746 spin_unlock(&init_mm.page_table_lock);
28747 pgd_changed = true;
28748 }
28749@@ -1224,8 +1238,8 @@ int kern_addr_valid(unsigned long addr)
28750 static struct vm_area_struct gate_vma = {
28751 .vm_start = VSYSCALL_START,
28752 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28753- .vm_page_prot = PAGE_READONLY_EXEC,
28754- .vm_flags = VM_READ | VM_EXEC
28755+ .vm_page_prot = PAGE_READONLY,
28756+ .vm_flags = VM_READ
28757 };
28758
28759 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28760@@ -1259,7 +1273,7 @@ int in_gate_area_no_mm(unsigned long addr)
28761
28762 const char *arch_vma_name(struct vm_area_struct *vma)
28763 {
28764- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28765+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28766 return "[vdso]";
28767 if (vma == &gate_vma)
28768 return "[vsyscall]";
28769diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28770index 7b179b4..6bd17777 100644
28771--- a/arch/x86/mm/iomap_32.c
28772+++ b/arch/x86/mm/iomap_32.c
28773@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28774 type = kmap_atomic_idx_push();
28775 idx = type + KM_TYPE_NR * smp_processor_id();
28776 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28777+
28778+ pax_open_kernel();
28779 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28780+ pax_close_kernel();
28781+
28782 arch_flush_lazy_mmu_mode();
28783
28784 return (void *)vaddr;
28785diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28786index 78fe3f1..73b95e2 100644
28787--- a/arch/x86/mm/ioremap.c
28788+++ b/arch/x86/mm/ioremap.c
28789@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28790 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28791 int is_ram = page_is_ram(pfn);
28792
28793- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28794+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28795 return NULL;
28796 WARN_ON_ONCE(is_ram);
28797 }
28798@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28799 *
28800 * Caller must ensure there is only one unmapping for the same pointer.
28801 */
28802-void iounmap(volatile void __iomem *addr)
28803+void iounmap(const volatile void __iomem *addr)
28804 {
28805 struct vm_struct *p, *o;
28806
28807@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28808
28809 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28810 if (page_is_ram(start >> PAGE_SHIFT))
28811+#ifdef CONFIG_HIGHMEM
28812+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28813+#endif
28814 return __va(phys);
28815
28816 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28817@@ -327,6 +330,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28818 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
28819 {
28820 if (page_is_ram(phys >> PAGE_SHIFT))
28821+#ifdef CONFIG_HIGHMEM
28822+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
28823+#endif
28824 return;
28825
28826 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
28827@@ -344,7 +350,7 @@ static int __init early_ioremap_debug_setup(char *str)
28828 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28829
28830 static __initdata int after_paging_init;
28831-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28832+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28833
28834 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28835 {
28836@@ -381,8 +387,7 @@ void __init early_ioremap_init(void)
28837 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28838
28839 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28840- memset(bm_pte, 0, sizeof(bm_pte));
28841- pmd_populate_kernel(&init_mm, pmd, bm_pte);
28842+ pmd_populate_user(&init_mm, pmd, bm_pte);
28843
28844 /*
28845 * The boot-ioremap range spans multiple pmds, for which
28846diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28847index d87dd6d..bf3fa66 100644
28848--- a/arch/x86/mm/kmemcheck/kmemcheck.c
28849+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28850@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28851 * memory (e.g. tracked pages)? For now, we need this to avoid
28852 * invoking kmemcheck for PnP BIOS calls.
28853 */
28854- if (regs->flags & X86_VM_MASK)
28855+ if (v8086_mode(regs))
28856 return false;
28857- if (regs->cs != __KERNEL_CS)
28858+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28859 return false;
28860
28861 pte = kmemcheck_pte_lookup(address);
28862diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28863index 845df68..1d8d29f 100644
28864--- a/arch/x86/mm/mmap.c
28865+++ b/arch/x86/mm/mmap.c
28866@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28867 * Leave an at least ~128 MB hole with possible stack randomization.
28868 */
28869 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28870-#define MAX_GAP (TASK_SIZE/6*5)
28871+#define MAX_GAP (pax_task_size/6*5)
28872
28873 static int mmap_is_legacy(void)
28874 {
28875@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28876 return rnd << PAGE_SHIFT;
28877 }
28878
28879-static unsigned long mmap_base(void)
28880+static unsigned long mmap_base(struct mm_struct *mm)
28881 {
28882 unsigned long gap = rlimit(RLIMIT_STACK);
28883+ unsigned long pax_task_size = TASK_SIZE;
28884+
28885+#ifdef CONFIG_PAX_SEGMEXEC
28886+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28887+ pax_task_size = SEGMEXEC_TASK_SIZE;
28888+#endif
28889
28890 if (gap < MIN_GAP)
28891 gap = MIN_GAP;
28892 else if (gap > MAX_GAP)
28893 gap = MAX_GAP;
28894
28895- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28896+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28897 }
28898
28899 /*
28900 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28901 * does, but not when emulating X86_32
28902 */
28903-static unsigned long mmap_legacy_base(void)
28904+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28905 {
28906- if (mmap_is_ia32())
28907+ if (mmap_is_ia32()) {
28908+
28909+#ifdef CONFIG_PAX_SEGMEXEC
28910+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28911+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28912+ else
28913+#endif
28914+
28915 return TASK_UNMAPPED_BASE;
28916- else
28917+ } else
28918 return TASK_UNMAPPED_BASE + mmap_rnd();
28919 }
28920
28921@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28922 void arch_pick_mmap_layout(struct mm_struct *mm)
28923 {
28924 if (mmap_is_legacy()) {
28925- mm->mmap_base = mmap_legacy_base();
28926+ mm->mmap_base = mmap_legacy_base(mm);
28927+
28928+#ifdef CONFIG_PAX_RANDMMAP
28929+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28930+ mm->mmap_base += mm->delta_mmap;
28931+#endif
28932+
28933 mm->get_unmapped_area = arch_get_unmapped_area;
28934 mm->unmap_area = arch_unmap_area;
28935 } else {
28936- mm->mmap_base = mmap_base();
28937+ mm->mmap_base = mmap_base(mm);
28938+
28939+#ifdef CONFIG_PAX_RANDMMAP
28940+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28941+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28942+#endif
28943+
28944 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28945 mm->unmap_area = arch_unmap_area_topdown;
28946 }
28947diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28948index dc0b727..f612039 100644
28949--- a/arch/x86/mm/mmio-mod.c
28950+++ b/arch/x86/mm/mmio-mod.c
28951@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28952 break;
28953 default:
28954 {
28955- unsigned char *ip = (unsigned char *)instptr;
28956+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28957 my_trace->opcode = MMIO_UNKNOWN_OP;
28958 my_trace->width = 0;
28959 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28960@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28961 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28962 void __iomem *addr)
28963 {
28964- static atomic_t next_id;
28965+ static atomic_unchecked_t next_id;
28966 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28967 /* These are page-unaligned. */
28968 struct mmiotrace_map map = {
28969@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28970 .private = trace
28971 },
28972 .phys = offset,
28973- .id = atomic_inc_return(&next_id)
28974+ .id = atomic_inc_return_unchecked(&next_id)
28975 };
28976 map.map_id = trace->id;
28977
28978@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28979 ioremap_trace_core(offset, size, addr);
28980 }
28981
28982-static void iounmap_trace_core(volatile void __iomem *addr)
28983+static void iounmap_trace_core(const volatile void __iomem *addr)
28984 {
28985 struct mmiotrace_map map = {
28986 .phys = 0,
28987@@ -328,7 +328,7 @@ not_enabled:
28988 }
28989 }
28990
28991-void mmiotrace_iounmap(volatile void __iomem *addr)
28992+void mmiotrace_iounmap(const volatile void __iomem *addr)
28993 {
28994 might_sleep();
28995 if (is_enabled()) /* recheck and proper locking in *_core() */
28996diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
28997index 72fe01e..f1a8daa 100644
28998--- a/arch/x86/mm/numa.c
28999+++ b/arch/x86/mm/numa.c
29000@@ -477,7 +477,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
29001 return true;
29002 }
29003
29004-static int __init numa_register_memblks(struct numa_meminfo *mi)
29005+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
29006 {
29007 unsigned long uninitialized_var(pfn_align);
29008 int i, nid;
29009diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
29010index 0e38951..4ca8458 100644
29011--- a/arch/x86/mm/pageattr-test.c
29012+++ b/arch/x86/mm/pageattr-test.c
29013@@ -36,7 +36,7 @@ enum {
29014
29015 static int pte_testbit(pte_t pte)
29016 {
29017- return pte_flags(pte) & _PAGE_UNUSED1;
29018+ return pte_flags(pte) & _PAGE_CPA_TEST;
29019 }
29020
29021 struct split_state {
29022diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
29023index fb4e73e..43f7238 100644
29024--- a/arch/x86/mm/pageattr.c
29025+++ b/arch/x86/mm/pageattr.c
29026@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29027 */
29028 #ifdef CONFIG_PCI_BIOS
29029 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
29030- pgprot_val(forbidden) |= _PAGE_NX;
29031+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29032 #endif
29033
29034 /*
29035@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29036 * Does not cover __inittext since that is gone later on. On
29037 * 64bit we do not enforce !NX on the low mapping
29038 */
29039- if (within(address, (unsigned long)_text, (unsigned long)_etext))
29040- pgprot_val(forbidden) |= _PAGE_NX;
29041+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
29042+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29043
29044+#ifdef CONFIG_DEBUG_RODATA
29045 /*
29046 * The .rodata section needs to be read-only. Using the pfn
29047 * catches all aliases.
29048@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29049 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
29050 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
29051 pgprot_val(forbidden) |= _PAGE_RW;
29052+#endif
29053
29054 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
29055 /*
29056@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29057 }
29058 #endif
29059
29060+#ifdef CONFIG_PAX_KERNEXEC
29061+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
29062+ pgprot_val(forbidden) |= _PAGE_RW;
29063+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29064+ }
29065+#endif
29066+
29067 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
29068
29069 return prot;
29070@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
29071 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
29072 {
29073 /* change init_mm */
29074+ pax_open_kernel();
29075 set_pte_atomic(kpte, pte);
29076+
29077 #ifdef CONFIG_X86_32
29078 if (!SHARED_KERNEL_PMD) {
29079+
29080+#ifdef CONFIG_PAX_PER_CPU_PGD
29081+ unsigned long cpu;
29082+#else
29083 struct page *page;
29084+#endif
29085
29086+#ifdef CONFIG_PAX_PER_CPU_PGD
29087+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29088+ pgd_t *pgd = get_cpu_pgd(cpu);
29089+#else
29090 list_for_each_entry(page, &pgd_list, lru) {
29091- pgd_t *pgd;
29092+ pgd_t *pgd = (pgd_t *)page_address(page);
29093+#endif
29094+
29095 pud_t *pud;
29096 pmd_t *pmd;
29097
29098- pgd = (pgd_t *)page_address(page) + pgd_index(address);
29099+ pgd += pgd_index(address);
29100 pud = pud_offset(pgd, address);
29101 pmd = pmd_offset(pud, address);
29102 set_pte_atomic((pte_t *)pmd, pte);
29103 }
29104 }
29105 #endif
29106+ pax_close_kernel();
29107 }
29108
29109 static int
29110diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
29111index 6574388..87e9bef 100644
29112--- a/arch/x86/mm/pat.c
29113+++ b/arch/x86/mm/pat.c
29114@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
29115
29116 if (!entry) {
29117 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
29118- current->comm, current->pid, start, end - 1);
29119+ current->comm, task_pid_nr(current), start, end - 1);
29120 return -EINVAL;
29121 }
29122
29123@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29124
29125 while (cursor < to) {
29126 if (!devmem_is_allowed(pfn)) {
29127- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
29128- current->comm, from, to - 1);
29129+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
29130+ current->comm, from, to - 1, cursor);
29131 return 0;
29132 }
29133 cursor += PAGE_SIZE;
29134@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
29135 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
29136 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
29137 "for [mem %#010Lx-%#010Lx]\n",
29138- current->comm, current->pid,
29139+ current->comm, task_pid_nr(current),
29140 cattr_name(flags),
29141 base, (unsigned long long)(base + size-1));
29142 return -EINVAL;
29143@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29144 flags = lookup_memtype(paddr);
29145 if (want_flags != flags) {
29146 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
29147- current->comm, current->pid,
29148+ current->comm, task_pid_nr(current),
29149 cattr_name(want_flags),
29150 (unsigned long long)paddr,
29151 (unsigned long long)(paddr + size - 1),
29152@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29153 free_memtype(paddr, paddr + size);
29154 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
29155 " for [mem %#010Lx-%#010Lx], got %s\n",
29156- current->comm, current->pid,
29157+ current->comm, task_pid_nr(current),
29158 cattr_name(want_flags),
29159 (unsigned long long)paddr,
29160 (unsigned long long)(paddr + size - 1),
29161diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
29162index 9f0614d..92ae64a 100644
29163--- a/arch/x86/mm/pf_in.c
29164+++ b/arch/x86/mm/pf_in.c
29165@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
29166 int i;
29167 enum reason_type rv = OTHERS;
29168
29169- p = (unsigned char *)ins_addr;
29170+ p = (unsigned char *)ktla_ktva(ins_addr);
29171 p += skip_prefix(p, &prf);
29172 p += get_opcode(p, &opcode);
29173
29174@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
29175 struct prefix_bits prf;
29176 int i;
29177
29178- p = (unsigned char *)ins_addr;
29179+ p = (unsigned char *)ktla_ktva(ins_addr);
29180 p += skip_prefix(p, &prf);
29181 p += get_opcode(p, &opcode);
29182
29183@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29184 struct prefix_bits prf;
29185 int i;
29186
29187- p = (unsigned char *)ins_addr;
29188+ p = (unsigned char *)ktla_ktva(ins_addr);
29189 p += skip_prefix(p, &prf);
29190 p += get_opcode(p, &opcode);
29191
29192@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29193 struct prefix_bits prf;
29194 int i;
29195
29196- p = (unsigned char *)ins_addr;
29197+ p = (unsigned char *)ktla_ktva(ins_addr);
29198 p += skip_prefix(p, &prf);
29199 p += get_opcode(p, &opcode);
29200 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29201@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29202 struct prefix_bits prf;
29203 int i;
29204
29205- p = (unsigned char *)ins_addr;
29206+ p = (unsigned char *)ktla_ktva(ins_addr);
29207 p += skip_prefix(p, &prf);
29208 p += get_opcode(p, &opcode);
29209 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29210diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29211index 17fda6a..489c74a 100644
29212--- a/arch/x86/mm/pgtable.c
29213+++ b/arch/x86/mm/pgtable.c
29214@@ -91,10 +91,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29215 list_del(&page->lru);
29216 }
29217
29218-#define UNSHARED_PTRS_PER_PGD \
29219- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29220+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29221+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29222
29223+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29224+{
29225+ unsigned int count = USER_PGD_PTRS;
29226
29227+ while (count--)
29228+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29229+}
29230+#endif
29231+
29232+#ifdef CONFIG_PAX_PER_CPU_PGD
29233+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29234+{
29235+ unsigned int count = USER_PGD_PTRS;
29236+
29237+ while (count--) {
29238+ pgd_t pgd;
29239+
29240+#ifdef CONFIG_X86_64
29241+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29242+#else
29243+ pgd = *src++;
29244+#endif
29245+
29246+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29247+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29248+#endif
29249+
29250+ *dst++ = pgd;
29251+ }
29252+
29253+}
29254+#endif
29255+
29256+#ifdef CONFIG_X86_64
29257+#define pxd_t pud_t
29258+#define pyd_t pgd_t
29259+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29260+#define pxd_free(mm, pud) pud_free((mm), (pud))
29261+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29262+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29263+#define PYD_SIZE PGDIR_SIZE
29264+#else
29265+#define pxd_t pmd_t
29266+#define pyd_t pud_t
29267+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29268+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29269+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29270+#define pyd_offset(mm, address) pud_offset((mm), (address))
29271+#define PYD_SIZE PUD_SIZE
29272+#endif
29273+
29274+#ifdef CONFIG_PAX_PER_CPU_PGD
29275+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29276+static inline void pgd_dtor(pgd_t *pgd) {}
29277+#else
29278 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29279 {
29280 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29281@@ -135,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd)
29282 pgd_list_del(pgd);
29283 spin_unlock(&pgd_lock);
29284 }
29285+#endif
29286
29287 /*
29288 * List of all pgd's needed for non-PAE so it can invalidate entries
29289@@ -147,7 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
29290 * -- nyc
29291 */
29292
29293-#ifdef CONFIG_X86_PAE
29294+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29295 /*
29296 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29297 * updating the top-level pagetable entries to guarantee the
29298@@ -159,7 +214,7 @@ static void pgd_dtor(pgd_t *pgd)
29299 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29300 * and initialize the kernel pmds here.
29301 */
29302-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29303+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29304
29305 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29306 {
29307@@ -177,36 +232,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29308 */
29309 flush_tlb_mm(mm);
29310 }
29311+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29312+#define PREALLOCATED_PXDS USER_PGD_PTRS
29313 #else /* !CONFIG_X86_PAE */
29314
29315 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29316-#define PREALLOCATED_PMDS 0
29317+#define PREALLOCATED_PXDS 0
29318
29319 #endif /* CONFIG_X86_PAE */
29320
29321-static void free_pmds(pmd_t *pmds[])
29322+static void free_pxds(pxd_t *pxds[])
29323 {
29324 int i;
29325
29326- for(i = 0; i < PREALLOCATED_PMDS; i++)
29327- if (pmds[i])
29328- free_page((unsigned long)pmds[i]);
29329+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29330+ if (pxds[i])
29331+ free_page((unsigned long)pxds[i]);
29332 }
29333
29334-static int preallocate_pmds(pmd_t *pmds[])
29335+static int preallocate_pxds(pxd_t *pxds[])
29336 {
29337 int i;
29338 bool failed = false;
29339
29340- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29341- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29342- if (pmd == NULL)
29343+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29344+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29345+ if (pxd == NULL)
29346 failed = true;
29347- pmds[i] = pmd;
29348+ pxds[i] = pxd;
29349 }
29350
29351 if (failed) {
29352- free_pmds(pmds);
29353+ free_pxds(pxds);
29354 return -ENOMEM;
29355 }
29356
29357@@ -219,51 +276,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29358 * preallocate which never got a corresponding vma will need to be
29359 * freed manually.
29360 */
29361-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29362+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29363 {
29364 int i;
29365
29366- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29367+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29368 pgd_t pgd = pgdp[i];
29369
29370 if (pgd_val(pgd) != 0) {
29371- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29372+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29373
29374- pgdp[i] = native_make_pgd(0);
29375+ set_pgd(pgdp + i, native_make_pgd(0));
29376
29377- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29378- pmd_free(mm, pmd);
29379+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29380+ pxd_free(mm, pxd);
29381 }
29382 }
29383 }
29384
29385-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29386+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29387 {
29388- pud_t *pud;
29389+ pyd_t *pyd;
29390 unsigned long addr;
29391 int i;
29392
29393- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29394+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29395 return;
29396
29397- pud = pud_offset(pgd, 0);
29398+#ifdef CONFIG_X86_64
29399+ pyd = pyd_offset(mm, 0L);
29400+#else
29401+ pyd = pyd_offset(pgd, 0L);
29402+#endif
29403
29404- for (addr = i = 0; i < PREALLOCATED_PMDS;
29405- i++, pud++, addr += PUD_SIZE) {
29406- pmd_t *pmd = pmds[i];
29407+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29408+ i++, pyd++, addr += PYD_SIZE) {
29409+ pxd_t *pxd = pxds[i];
29410
29411 if (i >= KERNEL_PGD_BOUNDARY)
29412- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29413- sizeof(pmd_t) * PTRS_PER_PMD);
29414+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29415+ sizeof(pxd_t) * PTRS_PER_PMD);
29416
29417- pud_populate(mm, pud, pmd);
29418+ pyd_populate(mm, pyd, pxd);
29419 }
29420 }
29421
29422 pgd_t *pgd_alloc(struct mm_struct *mm)
29423 {
29424 pgd_t *pgd;
29425- pmd_t *pmds[PREALLOCATED_PMDS];
29426+ pxd_t *pxds[PREALLOCATED_PXDS];
29427
29428 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29429
29430@@ -272,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29431
29432 mm->pgd = pgd;
29433
29434- if (preallocate_pmds(pmds) != 0)
29435+ if (preallocate_pxds(pxds) != 0)
29436 goto out_free_pgd;
29437
29438 if (paravirt_pgd_alloc(mm) != 0)
29439- goto out_free_pmds;
29440+ goto out_free_pxds;
29441
29442 /*
29443 * Make sure that pre-populating the pmds is atomic with
29444@@ -286,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29445 spin_lock(&pgd_lock);
29446
29447 pgd_ctor(mm, pgd);
29448- pgd_prepopulate_pmd(mm, pgd, pmds);
29449+ pgd_prepopulate_pxd(mm, pgd, pxds);
29450
29451 spin_unlock(&pgd_lock);
29452
29453 return pgd;
29454
29455-out_free_pmds:
29456- free_pmds(pmds);
29457+out_free_pxds:
29458+ free_pxds(pxds);
29459 out_free_pgd:
29460 free_page((unsigned long)pgd);
29461 out:
29462@@ -302,7 +363,7 @@ out:
29463
29464 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29465 {
29466- pgd_mop_up_pmds(mm, pgd);
29467+ pgd_mop_up_pxds(mm, pgd);
29468 pgd_dtor(pgd);
29469 paravirt_pgd_free(mm, pgd);
29470 free_page((unsigned long)pgd);
29471diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29472index a69bcb8..19068ab 100644
29473--- a/arch/x86/mm/pgtable_32.c
29474+++ b/arch/x86/mm/pgtable_32.c
29475@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29476 return;
29477 }
29478 pte = pte_offset_kernel(pmd, vaddr);
29479+
29480+ pax_open_kernel();
29481 if (pte_val(pteval))
29482 set_pte_at(&init_mm, vaddr, pte, pteval);
29483 else
29484 pte_clear(&init_mm, vaddr, pte);
29485+ pax_close_kernel();
29486
29487 /*
29488 * It's enough to flush this one mapping.
29489diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29490index e666cbb..61788c45 100644
29491--- a/arch/x86/mm/physaddr.c
29492+++ b/arch/x86/mm/physaddr.c
29493@@ -10,7 +10,7 @@
29494 #ifdef CONFIG_X86_64
29495
29496 #ifdef CONFIG_DEBUG_VIRTUAL
29497-unsigned long __phys_addr(unsigned long x)
29498+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29499 {
29500 unsigned long y = x - __START_KERNEL_map;
29501
29502@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29503 #else
29504
29505 #ifdef CONFIG_DEBUG_VIRTUAL
29506-unsigned long __phys_addr(unsigned long x)
29507+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29508 {
29509 unsigned long phys_addr = x - PAGE_OFFSET;
29510 /* VMALLOC_* aren't constants */
29511diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29512index 410531d..0f16030 100644
29513--- a/arch/x86/mm/setup_nx.c
29514+++ b/arch/x86/mm/setup_nx.c
29515@@ -5,8 +5,10 @@
29516 #include <asm/pgtable.h>
29517 #include <asm/proto.h>
29518
29519+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29520 static int disable_nx __cpuinitdata;
29521
29522+#ifndef CONFIG_PAX_PAGEEXEC
29523 /*
29524 * noexec = on|off
29525 *
29526@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29527 return 0;
29528 }
29529 early_param("noexec", noexec_setup);
29530+#endif
29531+
29532+#endif
29533
29534 void __cpuinit x86_configure_nx(void)
29535 {
29536+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29537 if (cpu_has_nx && !disable_nx)
29538 __supported_pte_mask |= _PAGE_NX;
29539 else
29540+#endif
29541 __supported_pte_mask &= ~_PAGE_NX;
29542 }
29543
29544diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29545index 282375f..e03a98f 100644
29546--- a/arch/x86/mm/tlb.c
29547+++ b/arch/x86/mm/tlb.c
29548@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29549 BUG();
29550 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29551 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29552+
29553+#ifndef CONFIG_PAX_PER_CPU_PGD
29554 load_cr3(swapper_pg_dir);
29555+#endif
29556+
29557 }
29558 }
29559 EXPORT_SYMBOL_GPL(leave_mm);
29560diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29561index 877b9a1..a8ecf42 100644
29562--- a/arch/x86/net/bpf_jit.S
29563+++ b/arch/x86/net/bpf_jit.S
29564@@ -9,6 +9,7 @@
29565 */
29566 #include <linux/linkage.h>
29567 #include <asm/dwarf2.h>
29568+#include <asm/alternative-asm.h>
29569
29570 /*
29571 * Calling convention :
29572@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29573 jle bpf_slow_path_word
29574 mov (SKBDATA,%rsi),%eax
29575 bswap %eax /* ntohl() */
29576+ pax_force_retaddr
29577 ret
29578
29579 sk_load_half:
29580@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29581 jle bpf_slow_path_half
29582 movzwl (SKBDATA,%rsi),%eax
29583 rol $8,%ax # ntohs()
29584+ pax_force_retaddr
29585 ret
29586
29587 sk_load_byte:
29588@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29589 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29590 jle bpf_slow_path_byte
29591 movzbl (SKBDATA,%rsi),%eax
29592+ pax_force_retaddr
29593 ret
29594
29595 /**
29596@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29597 movzbl (SKBDATA,%rsi),%ebx
29598 and $15,%bl
29599 shl $2,%bl
29600+ pax_force_retaddr
29601 ret
29602
29603 /* rsi contains offset and can be scratched */
29604@@ -109,6 +114,7 @@ bpf_slow_path_word:
29605 js bpf_error
29606 mov -12(%rbp),%eax
29607 bswap %eax
29608+ pax_force_retaddr
29609 ret
29610
29611 bpf_slow_path_half:
29612@@ -117,12 +123,14 @@ bpf_slow_path_half:
29613 mov -12(%rbp),%ax
29614 rol $8,%ax
29615 movzwl %ax,%eax
29616+ pax_force_retaddr
29617 ret
29618
29619 bpf_slow_path_byte:
29620 bpf_slow_path_common(1)
29621 js bpf_error
29622 movzbl -12(%rbp),%eax
29623+ pax_force_retaddr
29624 ret
29625
29626 bpf_slow_path_byte_msh:
29627@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29628 and $15,%al
29629 shl $2,%al
29630 xchg %eax,%ebx
29631+ pax_force_retaddr
29632 ret
29633
29634 #define sk_negative_common(SIZE) \
29635@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29636 sk_negative_common(4)
29637 mov (%rax), %eax
29638 bswap %eax
29639+ pax_force_retaddr
29640 ret
29641
29642 bpf_slow_path_half_neg:
29643@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29644 mov (%rax),%ax
29645 rol $8,%ax
29646 movzwl %ax,%eax
29647+ pax_force_retaddr
29648 ret
29649
29650 bpf_slow_path_byte_neg:
29651@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29652 .globl sk_load_byte_negative_offset
29653 sk_negative_common(1)
29654 movzbl (%rax), %eax
29655+ pax_force_retaddr
29656 ret
29657
29658 bpf_slow_path_byte_msh_neg:
29659@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29660 and $15,%al
29661 shl $2,%al
29662 xchg %eax,%ebx
29663+ pax_force_retaddr
29664 ret
29665
29666 bpf_error:
29667@@ -197,4 +210,5 @@ bpf_error:
29668 xor %eax,%eax
29669 mov -8(%rbp),%rbx
29670 leaveq
29671+ pax_force_retaddr
29672 ret
29673diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29674index 3cbe4538..003d011 100644
29675--- a/arch/x86/net/bpf_jit_comp.c
29676+++ b/arch/x86/net/bpf_jit_comp.c
29677@@ -12,6 +12,7 @@
29678 #include <linux/netdevice.h>
29679 #include <linux/filter.h>
29680 #include <linux/if_vlan.h>
29681+#include <linux/random.h>
29682
29683 /*
29684 * Conventions :
29685@@ -49,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29686 return ptr + len;
29687 }
29688
29689+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29690+#define MAX_INSTR_CODE_SIZE 96
29691+#else
29692+#define MAX_INSTR_CODE_SIZE 64
29693+#endif
29694+
29695 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29696
29697 #define EMIT1(b1) EMIT(b1, 1)
29698 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29699 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29700 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29701+
29702+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29703+/* original constant will appear in ecx */
29704+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29705+do { \
29706+ /* mov ecx, randkey */ \
29707+ EMIT1(0xb9); \
29708+ EMIT(_key, 4); \
29709+ /* xor ecx, randkey ^ off */ \
29710+ EMIT2(0x81, 0xf1); \
29711+ EMIT((_key) ^ (_off), 4); \
29712+} while (0)
29713+
29714+#define EMIT1_off32(b1, _off) \
29715+do { \
29716+ switch (b1) { \
29717+ case 0x05: /* add eax, imm32 */ \
29718+ case 0x2d: /* sub eax, imm32 */ \
29719+ case 0x25: /* and eax, imm32 */ \
29720+ case 0x0d: /* or eax, imm32 */ \
29721+ case 0xb8: /* mov eax, imm32 */ \
29722+ case 0x35: /* xor eax, imm32 */ \
29723+ case 0x3d: /* cmp eax, imm32 */ \
29724+ case 0xa9: /* test eax, imm32 */ \
29725+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29726+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29727+ break; \
29728+ case 0xbb: /* mov ebx, imm32 */ \
29729+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29730+ /* mov ebx, ecx */ \
29731+ EMIT2(0x89, 0xcb); \
29732+ break; \
29733+ case 0xbe: /* mov esi, imm32 */ \
29734+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29735+ /* mov esi, ecx */ \
29736+ EMIT2(0x89, 0xce); \
29737+ break; \
29738+ case 0xe8: /* call rel imm32, always to known funcs */ \
29739+ EMIT1(b1); \
29740+ EMIT(_off, 4); \
29741+ break; \
29742+ case 0xe9: /* jmp rel imm32 */ \
29743+ EMIT1(b1); \
29744+ EMIT(_off, 4); \
29745+ /* prevent fall-through, we're not called if off = 0 */ \
29746+ EMIT(0xcccccccc, 4); \
29747+ EMIT(0xcccccccc, 4); \
29748+ break; \
29749+ default: \
29750+ BUILD_BUG(); \
29751+ } \
29752+} while (0)
29753+
29754+#define EMIT2_off32(b1, b2, _off) \
29755+do { \
29756+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29757+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29758+ EMIT(randkey, 4); \
29759+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29760+ EMIT((_off) - randkey, 4); \
29761+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29762+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29763+ /* imul eax, ecx */ \
29764+ EMIT3(0x0f, 0xaf, 0xc1); \
29765+ } else { \
29766+ BUILD_BUG(); \
29767+ } \
29768+} while (0)
29769+#else
29770 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29771+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29772+#endif
29773
29774 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29775 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29776@@ -90,6 +168,24 @@ do { \
29777 #define X86_JBE 0x76
29778 #define X86_JA 0x77
29779
29780+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29781+#define APPEND_FLOW_VERIFY() \
29782+do { \
29783+ /* mov ecx, randkey */ \
29784+ EMIT1(0xb9); \
29785+ EMIT(randkey, 4); \
29786+ /* cmp ecx, randkey */ \
29787+ EMIT2(0x81, 0xf9); \
29788+ EMIT(randkey, 4); \
29789+ /* jz after 8 int 3s */ \
29790+ EMIT2(0x74, 0x08); \
29791+ EMIT(0xcccccccc, 4); \
29792+ EMIT(0xcccccccc, 4); \
29793+} while (0)
29794+#else
29795+#define APPEND_FLOW_VERIFY() do { } while (0)
29796+#endif
29797+
29798 #define EMIT_COND_JMP(op, offset) \
29799 do { \
29800 if (is_near(offset)) \
29801@@ -97,6 +193,7 @@ do { \
29802 else { \
29803 EMIT2(0x0f, op + 0x10); \
29804 EMIT(offset, 4); /* jxx .+off32 */ \
29805+ APPEND_FLOW_VERIFY(); \
29806 } \
29807 } while (0)
29808
29809@@ -121,6 +218,11 @@ static inline void bpf_flush_icache(void *start, void *end)
29810 set_fs(old_fs);
29811 }
29812
29813+struct bpf_jit_work {
29814+ struct work_struct work;
29815+ void *image;
29816+};
29817+
29818 #define CHOOSE_LOAD_FUNC(K, func) \
29819 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29820
29821@@ -146,7 +248,7 @@ static int pkt_type_offset(void)
29822
29823 void bpf_jit_compile(struct sk_filter *fp)
29824 {
29825- u8 temp[64];
29826+ u8 temp[MAX_INSTR_CODE_SIZE];
29827 u8 *prog;
29828 unsigned int proglen, oldproglen = 0;
29829 int ilen, i;
29830@@ -159,6 +261,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29831 unsigned int *addrs;
29832 const struct sock_filter *filter = fp->insns;
29833 int flen = fp->len;
29834+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29835+ unsigned int randkey;
29836+#endif
29837
29838 if (!bpf_jit_enable)
29839 return;
29840@@ -167,11 +272,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29841 if (addrs == NULL)
29842 return;
29843
29844+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29845+ if (!fp->work)
29846+ goto out;
29847+
29848+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29849+ randkey = get_random_int();
29850+#endif
29851+
29852 /* Before first pass, make a rough estimation of addrs[]
29853- * each bpf instruction is translated to less than 64 bytes
29854+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29855 */
29856 for (proglen = 0, i = 0; i < flen; i++) {
29857- proglen += 64;
29858+ proglen += MAX_INSTR_CODE_SIZE;
29859 addrs[i] = proglen;
29860 }
29861 cleanup_addr = proglen; /* epilogue address */
29862@@ -282,10 +395,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29863 case BPF_S_ALU_MUL_K: /* A *= K */
29864 if (is_imm8(K))
29865 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29866- else {
29867- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29868- EMIT(K, 4);
29869- }
29870+ else
29871+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29872 break;
29873 case BPF_S_ALU_DIV_X: /* A /= X; */
29874 seen |= SEEN_XREG;
29875@@ -325,13 +436,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29876 break;
29877 case BPF_S_ALU_MOD_K: /* A %= K; */
29878 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29879+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29880+ DILUTE_CONST_SEQUENCE(K, randkey);
29881+#else
29882 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29883+#endif
29884 EMIT2(0xf7, 0xf1); /* div %ecx */
29885 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29886 break;
29887 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29888+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29889+ DILUTE_CONST_SEQUENCE(K, randkey);
29890+ // imul rax, rcx
29891+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29892+#else
29893 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29894 EMIT(K, 4);
29895+#endif
29896 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29897 break;
29898 case BPF_S_ALU_AND_X:
29899@@ -602,8 +723,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29900 if (is_imm8(K)) {
29901 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29902 } else {
29903- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29904- EMIT(K, 4);
29905+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29906 }
29907 } else {
29908 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29909@@ -686,17 +806,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29910 break;
29911 default:
29912 /* hmm, too complex filter, give up with jit compiler */
29913- goto out;
29914+ goto error;
29915 }
29916 ilen = prog - temp;
29917 if (image) {
29918 if (unlikely(proglen + ilen > oldproglen)) {
29919 pr_err("bpb_jit_compile fatal error\n");
29920- kfree(addrs);
29921- module_free(NULL, image);
29922- return;
29923+ module_free_exec(NULL, image);
29924+ goto error;
29925 }
29926+ pax_open_kernel();
29927 memcpy(image + proglen, temp, ilen);
29928+ pax_close_kernel();
29929 }
29930 proglen += ilen;
29931 addrs[i] = proglen;
29932@@ -717,11 +838,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29933 break;
29934 }
29935 if (proglen == oldproglen) {
29936- image = module_alloc(max_t(unsigned int,
29937- proglen,
29938- sizeof(struct work_struct)));
29939+ image = module_alloc_exec(proglen);
29940 if (!image)
29941- goto out;
29942+ goto error;
29943 }
29944 oldproglen = proglen;
29945 }
29946@@ -737,7 +856,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29947 bpf_flush_icache(image, image + proglen);
29948
29949 fp->bpf_func = (void *)image;
29950- }
29951+ } else
29952+error:
29953+ kfree(fp->work);
29954+
29955 out:
29956 kfree(addrs);
29957 return;
29958@@ -745,18 +867,20 @@ out:
29959
29960 static void jit_free_defer(struct work_struct *arg)
29961 {
29962- module_free(NULL, arg);
29963+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29964+ kfree(arg);
29965 }
29966
29967 /* run from softirq, we must use a work_struct to call
29968- * module_free() from process context
29969+ * module_free_exec() from process context
29970 */
29971 void bpf_jit_free(struct sk_filter *fp)
29972 {
29973 if (fp->bpf_func != sk_run_filter) {
29974- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29975+ struct work_struct *work = &fp->work->work;
29976
29977 INIT_WORK(work, jit_free_defer);
29978+ fp->work->image = fp->bpf_func;
29979 schedule_work(work);
29980 }
29981 }
29982diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29983index d6aa6e8..266395a 100644
29984--- a/arch/x86/oprofile/backtrace.c
29985+++ b/arch/x86/oprofile/backtrace.c
29986@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29987 struct stack_frame_ia32 *fp;
29988 unsigned long bytes;
29989
29990- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29991+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29992 if (bytes != sizeof(bufhead))
29993 return NULL;
29994
29995- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29996+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29997
29998 oprofile_add_trace(bufhead[0].return_address);
29999
30000@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
30001 struct stack_frame bufhead[2];
30002 unsigned long bytes;
30003
30004- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
30005+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
30006 if (bytes != sizeof(bufhead))
30007 return NULL;
30008
30009@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
30010 {
30011 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
30012
30013- if (!user_mode_vm(regs)) {
30014+ if (!user_mode(regs)) {
30015 unsigned long stack = kernel_stack_pointer(regs);
30016 if (depth)
30017 dump_trace(NULL, regs, (unsigned long *)stack, 0,
30018diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
30019index 48768df..ba9143c 100644
30020--- a/arch/x86/oprofile/nmi_int.c
30021+++ b/arch/x86/oprofile/nmi_int.c
30022@@ -23,6 +23,7 @@
30023 #include <asm/nmi.h>
30024 #include <asm/msr.h>
30025 #include <asm/apic.h>
30026+#include <asm/pgtable.h>
30027
30028 #include "op_counter.h"
30029 #include "op_x86_model.h"
30030@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
30031 if (ret)
30032 return ret;
30033
30034- if (!model->num_virt_counters)
30035- model->num_virt_counters = model->num_counters;
30036+ if (!model->num_virt_counters) {
30037+ pax_open_kernel();
30038+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
30039+ pax_close_kernel();
30040+ }
30041
30042 mux_init(ops);
30043
30044diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
30045index b2b9443..be58856 100644
30046--- a/arch/x86/oprofile/op_model_amd.c
30047+++ b/arch/x86/oprofile/op_model_amd.c
30048@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
30049 num_counters = AMD64_NUM_COUNTERS;
30050 }
30051
30052- op_amd_spec.num_counters = num_counters;
30053- op_amd_spec.num_controls = num_counters;
30054- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30055+ pax_open_kernel();
30056+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
30057+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
30058+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30059+ pax_close_kernel();
30060
30061 return 0;
30062 }
30063diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
30064index d90528e..0127e2b 100644
30065--- a/arch/x86/oprofile/op_model_ppro.c
30066+++ b/arch/x86/oprofile/op_model_ppro.c
30067@@ -19,6 +19,7 @@
30068 #include <asm/msr.h>
30069 #include <asm/apic.h>
30070 #include <asm/nmi.h>
30071+#include <asm/pgtable.h>
30072
30073 #include "op_x86_model.h"
30074 #include "op_counter.h"
30075@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
30076
30077 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
30078
30079- op_arch_perfmon_spec.num_counters = num_counters;
30080- op_arch_perfmon_spec.num_controls = num_counters;
30081+ pax_open_kernel();
30082+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
30083+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
30084+ pax_close_kernel();
30085 }
30086
30087 static int arch_perfmon_init(struct oprofile_operations *ignore)
30088diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
30089index 71e8a67..6a313bb 100644
30090--- a/arch/x86/oprofile/op_x86_model.h
30091+++ b/arch/x86/oprofile/op_x86_model.h
30092@@ -52,7 +52,7 @@ struct op_x86_model_spec {
30093 void (*switch_ctrl)(struct op_x86_model_spec const *model,
30094 struct op_msrs const * const msrs);
30095 #endif
30096-};
30097+} __do_const;
30098
30099 struct op_counter_config;
30100
30101diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
30102index e9e6ed5..e47ae67 100644
30103--- a/arch/x86/pci/amd_bus.c
30104+++ b/arch/x86/pci/amd_bus.c
30105@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
30106 return NOTIFY_OK;
30107 }
30108
30109-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
30110+static struct notifier_block amd_cpu_notifier = {
30111 .notifier_call = amd_cpu_notify,
30112 };
30113
30114diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
30115index 372e9b8..e775a6c 100644
30116--- a/arch/x86/pci/irq.c
30117+++ b/arch/x86/pci/irq.c
30118@@ -50,7 +50,7 @@ struct irq_router {
30119 struct irq_router_handler {
30120 u16 vendor;
30121 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
30122-};
30123+} __do_const;
30124
30125 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
30126 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
30127@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
30128 return 0;
30129 }
30130
30131-static __initdata struct irq_router_handler pirq_routers[] = {
30132+static __initconst const struct irq_router_handler pirq_routers[] = {
30133 { PCI_VENDOR_ID_INTEL, intel_router_probe },
30134 { PCI_VENDOR_ID_AL, ali_router_probe },
30135 { PCI_VENDOR_ID_ITE, ite_router_probe },
30136@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
30137 static void __init pirq_find_router(struct irq_router *r)
30138 {
30139 struct irq_routing_table *rt = pirq_table;
30140- struct irq_router_handler *h;
30141+ const struct irq_router_handler *h;
30142
30143 #ifdef CONFIG_PCI_BIOS
30144 if (!rt->signature) {
30145@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
30146 return 0;
30147 }
30148
30149-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
30150+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
30151 {
30152 .callback = fix_broken_hp_bios_irq9,
30153 .ident = "HP Pavilion N5400 Series Laptop",
30154diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
30155index 6eb18c4..20d83de 100644
30156--- a/arch/x86/pci/mrst.c
30157+++ b/arch/x86/pci/mrst.c
30158@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
30159 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
30160 pci_mmcfg_late_init();
30161 pcibios_enable_irq = mrst_pci_irq_enable;
30162- pci_root_ops = pci_mrst_ops;
30163+ pax_open_kernel();
30164+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
30165+ pax_close_kernel();
30166 pci_soc_mode = 1;
30167 /* Continue with standard init */
30168 return 1;
30169diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
30170index c77b24a..c979855 100644
30171--- a/arch/x86/pci/pcbios.c
30172+++ b/arch/x86/pci/pcbios.c
30173@@ -79,7 +79,7 @@ union bios32 {
30174 static struct {
30175 unsigned long address;
30176 unsigned short segment;
30177-} bios32_indirect = { 0, __KERNEL_CS };
30178+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
30179
30180 /*
30181 * Returns the entry point for the given service, NULL on error
30182@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30183 unsigned long length; /* %ecx */
30184 unsigned long entry; /* %edx */
30185 unsigned long flags;
30186+ struct desc_struct d, *gdt;
30187
30188 local_irq_save(flags);
30189- __asm__("lcall *(%%edi); cld"
30190+
30191+ gdt = get_cpu_gdt_table(smp_processor_id());
30192+
30193+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30194+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30195+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30196+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30197+
30198+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30199 : "=a" (return_code),
30200 "=b" (address),
30201 "=c" (length),
30202 "=d" (entry)
30203 : "0" (service),
30204 "1" (0),
30205- "D" (&bios32_indirect));
30206+ "D" (&bios32_indirect),
30207+ "r"(__PCIBIOS_DS)
30208+ : "memory");
30209+
30210+ pax_open_kernel();
30211+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30212+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30213+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30214+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30215+ pax_close_kernel();
30216+
30217 local_irq_restore(flags);
30218
30219 switch (return_code) {
30220- case 0:
30221- return address + entry;
30222- case 0x80: /* Not present */
30223- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30224- return 0;
30225- default: /* Shouldn't happen */
30226- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30227- service, return_code);
30228+ case 0: {
30229+ int cpu;
30230+ unsigned char flags;
30231+
30232+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30233+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30234+ printk(KERN_WARNING "bios32_service: not valid\n");
30235 return 0;
30236+ }
30237+ address = address + PAGE_OFFSET;
30238+ length += 16UL; /* some BIOSs underreport this... */
30239+ flags = 4;
30240+ if (length >= 64*1024*1024) {
30241+ length >>= PAGE_SHIFT;
30242+ flags |= 8;
30243+ }
30244+
30245+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30246+ gdt = get_cpu_gdt_table(cpu);
30247+ pack_descriptor(&d, address, length, 0x9b, flags);
30248+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30249+ pack_descriptor(&d, address, length, 0x93, flags);
30250+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30251+ }
30252+ return entry;
30253+ }
30254+ case 0x80: /* Not present */
30255+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30256+ return 0;
30257+ default: /* Shouldn't happen */
30258+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30259+ service, return_code);
30260+ return 0;
30261 }
30262 }
30263
30264 static struct {
30265 unsigned long address;
30266 unsigned short segment;
30267-} pci_indirect = { 0, __KERNEL_CS };
30268+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30269
30270-static int pci_bios_present;
30271+static int pci_bios_present __read_only;
30272
30273 static int check_pcibios(void)
30274 {
30275@@ -131,11 +174,13 @@ static int check_pcibios(void)
30276 unsigned long flags, pcibios_entry;
30277
30278 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30279- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30280+ pci_indirect.address = pcibios_entry;
30281
30282 local_irq_save(flags);
30283- __asm__(
30284- "lcall *(%%edi); cld\n\t"
30285+ __asm__("movw %w6, %%ds\n\t"
30286+ "lcall *%%ss:(%%edi); cld\n\t"
30287+ "push %%ss\n\t"
30288+ "pop %%ds\n\t"
30289 "jc 1f\n\t"
30290 "xor %%ah, %%ah\n"
30291 "1:"
30292@@ -144,7 +189,8 @@ static int check_pcibios(void)
30293 "=b" (ebx),
30294 "=c" (ecx)
30295 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30296- "D" (&pci_indirect)
30297+ "D" (&pci_indirect),
30298+ "r" (__PCIBIOS_DS)
30299 : "memory");
30300 local_irq_restore(flags);
30301
30302@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30303
30304 switch (len) {
30305 case 1:
30306- __asm__("lcall *(%%esi); cld\n\t"
30307+ __asm__("movw %w6, %%ds\n\t"
30308+ "lcall *%%ss:(%%esi); cld\n\t"
30309+ "push %%ss\n\t"
30310+ "pop %%ds\n\t"
30311 "jc 1f\n\t"
30312 "xor %%ah, %%ah\n"
30313 "1:"
30314@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30315 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30316 "b" (bx),
30317 "D" ((long)reg),
30318- "S" (&pci_indirect));
30319+ "S" (&pci_indirect),
30320+ "r" (__PCIBIOS_DS));
30321 /*
30322 * Zero-extend the result beyond 8 bits, do not trust the
30323 * BIOS having done it:
30324@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30325 *value &= 0xff;
30326 break;
30327 case 2:
30328- __asm__("lcall *(%%esi); cld\n\t"
30329+ __asm__("movw %w6, %%ds\n\t"
30330+ "lcall *%%ss:(%%esi); cld\n\t"
30331+ "push %%ss\n\t"
30332+ "pop %%ds\n\t"
30333 "jc 1f\n\t"
30334 "xor %%ah, %%ah\n"
30335 "1:"
30336@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30337 : "1" (PCIBIOS_READ_CONFIG_WORD),
30338 "b" (bx),
30339 "D" ((long)reg),
30340- "S" (&pci_indirect));
30341+ "S" (&pci_indirect),
30342+ "r" (__PCIBIOS_DS));
30343 /*
30344 * Zero-extend the result beyond 16 bits, do not trust the
30345 * BIOS having done it:
30346@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30347 *value &= 0xffff;
30348 break;
30349 case 4:
30350- __asm__("lcall *(%%esi); cld\n\t"
30351+ __asm__("movw %w6, %%ds\n\t"
30352+ "lcall *%%ss:(%%esi); cld\n\t"
30353+ "push %%ss\n\t"
30354+ "pop %%ds\n\t"
30355 "jc 1f\n\t"
30356 "xor %%ah, %%ah\n"
30357 "1:"
30358@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30359 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30360 "b" (bx),
30361 "D" ((long)reg),
30362- "S" (&pci_indirect));
30363+ "S" (&pci_indirect),
30364+ "r" (__PCIBIOS_DS));
30365 break;
30366 }
30367
30368@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30369
30370 switch (len) {
30371 case 1:
30372- __asm__("lcall *(%%esi); cld\n\t"
30373+ __asm__("movw %w6, %%ds\n\t"
30374+ "lcall *%%ss:(%%esi); cld\n\t"
30375+ "push %%ss\n\t"
30376+ "pop %%ds\n\t"
30377 "jc 1f\n\t"
30378 "xor %%ah, %%ah\n"
30379 "1:"
30380@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30381 "c" (value),
30382 "b" (bx),
30383 "D" ((long)reg),
30384- "S" (&pci_indirect));
30385+ "S" (&pci_indirect),
30386+ "r" (__PCIBIOS_DS));
30387 break;
30388 case 2:
30389- __asm__("lcall *(%%esi); cld\n\t"
30390+ __asm__("movw %w6, %%ds\n\t"
30391+ "lcall *%%ss:(%%esi); cld\n\t"
30392+ "push %%ss\n\t"
30393+ "pop %%ds\n\t"
30394 "jc 1f\n\t"
30395 "xor %%ah, %%ah\n"
30396 "1:"
30397@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30398 "c" (value),
30399 "b" (bx),
30400 "D" ((long)reg),
30401- "S" (&pci_indirect));
30402+ "S" (&pci_indirect),
30403+ "r" (__PCIBIOS_DS));
30404 break;
30405 case 4:
30406- __asm__("lcall *(%%esi); cld\n\t"
30407+ __asm__("movw %w6, %%ds\n\t"
30408+ "lcall *%%ss:(%%esi); cld\n\t"
30409+ "push %%ss\n\t"
30410+ "pop %%ds\n\t"
30411 "jc 1f\n\t"
30412 "xor %%ah, %%ah\n"
30413 "1:"
30414@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30415 "c" (value),
30416 "b" (bx),
30417 "D" ((long)reg),
30418- "S" (&pci_indirect));
30419+ "S" (&pci_indirect),
30420+ "r" (__PCIBIOS_DS));
30421 break;
30422 }
30423
30424@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30425
30426 DBG("PCI: Fetching IRQ routing table... ");
30427 __asm__("push %%es\n\t"
30428+ "movw %w8, %%ds\n\t"
30429 "push %%ds\n\t"
30430 "pop %%es\n\t"
30431- "lcall *(%%esi); cld\n\t"
30432+ "lcall *%%ss:(%%esi); cld\n\t"
30433 "pop %%es\n\t"
30434+ "push %%ss\n\t"
30435+ "pop %%ds\n"
30436 "jc 1f\n\t"
30437 "xor %%ah, %%ah\n"
30438 "1:"
30439@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30440 "1" (0),
30441 "D" ((long) &opt),
30442 "S" (&pci_indirect),
30443- "m" (opt)
30444+ "m" (opt),
30445+ "r" (__PCIBIOS_DS)
30446 : "memory");
30447 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30448 if (ret & 0xff00)
30449@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30450 {
30451 int ret;
30452
30453- __asm__("lcall *(%%esi); cld\n\t"
30454+ __asm__("movw %w5, %%ds\n\t"
30455+ "lcall *%%ss:(%%esi); cld\n\t"
30456+ "push %%ss\n\t"
30457+ "pop %%ds\n"
30458 "jc 1f\n\t"
30459 "xor %%ah, %%ah\n"
30460 "1:"
30461@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30462 : "0" (PCIBIOS_SET_PCI_HW_INT),
30463 "b" ((dev->bus->number << 8) | dev->devfn),
30464 "c" ((irq << 8) | (pin + 10)),
30465- "S" (&pci_indirect));
30466+ "S" (&pci_indirect),
30467+ "r" (__PCIBIOS_DS));
30468 return !(ret & 0xff00);
30469 }
30470 EXPORT_SYMBOL(pcibios_set_irq_routing);
30471diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30472index 40e4469..0592924 100644
30473--- a/arch/x86/platform/efi/efi_32.c
30474+++ b/arch/x86/platform/efi/efi_32.c
30475@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30476 {
30477 struct desc_ptr gdt_descr;
30478
30479+#ifdef CONFIG_PAX_KERNEXEC
30480+ struct desc_struct d;
30481+#endif
30482+
30483 local_irq_save(efi_rt_eflags);
30484
30485 load_cr3(initial_page_table);
30486 __flush_tlb_all();
30487
30488+#ifdef CONFIG_PAX_KERNEXEC
30489+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30490+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30491+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30492+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30493+#endif
30494+
30495 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30496 gdt_descr.size = GDT_SIZE - 1;
30497 load_gdt(&gdt_descr);
30498@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
30499 {
30500 struct desc_ptr gdt_descr;
30501
30502+#ifdef CONFIG_PAX_KERNEXEC
30503+ struct desc_struct d;
30504+
30505+ memset(&d, 0, sizeof d);
30506+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30507+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30508+#endif
30509+
30510 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30511 gdt_descr.size = GDT_SIZE - 1;
30512 load_gdt(&gdt_descr);
30513
30514+#ifdef CONFIG_PAX_PER_CPU_PGD
30515+ load_cr3(get_cpu_pgd(smp_processor_id()));
30516+#else
30517 load_cr3(swapper_pg_dir);
30518+#endif
30519+
30520 __flush_tlb_all();
30521
30522 local_irq_restore(efi_rt_eflags);
30523diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
30524index 2b20038..eaf558f 100644
30525--- a/arch/x86/platform/efi/efi_64.c
30526+++ b/arch/x86/platform/efi/efi_64.c
30527@@ -75,6 +75,11 @@ void __init efi_call_phys_prelog(void)
30528 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
30529 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
30530 }
30531+
30532+#ifdef CONFIG_PAX_PER_CPU_PGD
30533+ load_cr3(swapper_pg_dir);
30534+#endif
30535+
30536 __flush_tlb_all();
30537 }
30538
30539@@ -88,6 +93,11 @@ void __init efi_call_phys_epilog(void)
30540 for (pgd = 0; pgd < n_pgds; pgd++)
30541 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
30542 kfree(save_pgd);
30543+
30544+#ifdef CONFIG_PAX_PER_CPU_PGD
30545+ load_cr3(get_cpu_pgd(smp_processor_id()));
30546+#endif
30547+
30548 __flush_tlb_all();
30549 local_irq_restore(efi_flags);
30550 early_code_mapping_set_exec(0);
30551diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30552index fbe66e6..eae5e38 100644
30553--- a/arch/x86/platform/efi/efi_stub_32.S
30554+++ b/arch/x86/platform/efi/efi_stub_32.S
30555@@ -6,7 +6,9 @@
30556 */
30557
30558 #include <linux/linkage.h>
30559+#include <linux/init.h>
30560 #include <asm/page_types.h>
30561+#include <asm/segment.h>
30562
30563 /*
30564 * efi_call_phys(void *, ...) is a function with variable parameters.
30565@@ -20,7 +22,7 @@
30566 * service functions will comply with gcc calling convention, too.
30567 */
30568
30569-.text
30570+__INIT
30571 ENTRY(efi_call_phys)
30572 /*
30573 * 0. The function can only be called in Linux kernel. So CS has been
30574@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30575 * The mapping of lower virtual memory has been created in prelog and
30576 * epilog.
30577 */
30578- movl $1f, %edx
30579- subl $__PAGE_OFFSET, %edx
30580- jmp *%edx
30581+#ifdef CONFIG_PAX_KERNEXEC
30582+ movl $(__KERNEXEC_EFI_DS), %edx
30583+ mov %edx, %ds
30584+ mov %edx, %es
30585+ mov %edx, %ss
30586+ addl $2f,(1f)
30587+ ljmp *(1f)
30588+
30589+__INITDATA
30590+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30591+.previous
30592+
30593+2:
30594+ subl $2b,(1b)
30595+#else
30596+ jmp 1f-__PAGE_OFFSET
30597 1:
30598+#endif
30599
30600 /*
30601 * 2. Now on the top of stack is the return
30602@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30603 * parameter 2, ..., param n. To make things easy, we save the return
30604 * address of efi_call_phys in a global variable.
30605 */
30606- popl %edx
30607- movl %edx, saved_return_addr
30608- /* get the function pointer into ECX*/
30609- popl %ecx
30610- movl %ecx, efi_rt_function_ptr
30611- movl $2f, %edx
30612- subl $__PAGE_OFFSET, %edx
30613- pushl %edx
30614+ popl (saved_return_addr)
30615+ popl (efi_rt_function_ptr)
30616
30617 /*
30618 * 3. Clear PG bit in %CR0.
30619@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30620 /*
30621 * 5. Call the physical function.
30622 */
30623- jmp *%ecx
30624+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30625
30626-2:
30627 /*
30628 * 6. After EFI runtime service returns, control will return to
30629 * following instruction. We'd better readjust stack pointer first.
30630@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30631 movl %cr0, %edx
30632 orl $0x80000000, %edx
30633 movl %edx, %cr0
30634- jmp 1f
30635-1:
30636+
30637 /*
30638 * 8. Now restore the virtual mode from flat mode by
30639 * adding EIP with PAGE_OFFSET.
30640 */
30641- movl $1f, %edx
30642- jmp *%edx
30643+#ifdef CONFIG_PAX_KERNEXEC
30644+ movl $(__KERNEL_DS), %edx
30645+ mov %edx, %ds
30646+ mov %edx, %es
30647+ mov %edx, %ss
30648+ ljmp $(__KERNEL_CS),$1f
30649+#else
30650+ jmp 1f+__PAGE_OFFSET
30651+#endif
30652 1:
30653
30654 /*
30655 * 9. Balance the stack. And because EAX contain the return value,
30656 * we'd better not clobber it.
30657 */
30658- leal efi_rt_function_ptr, %edx
30659- movl (%edx), %ecx
30660- pushl %ecx
30661+ pushl (efi_rt_function_ptr)
30662
30663 /*
30664- * 10. Push the saved return address onto the stack and return.
30665+ * 10. Return to the saved return address.
30666 */
30667- leal saved_return_addr, %edx
30668- movl (%edx), %ecx
30669- pushl %ecx
30670- ret
30671+ jmpl *(saved_return_addr)
30672 ENDPROC(efi_call_phys)
30673 .previous
30674
30675-.data
30676+__INITDATA
30677 saved_return_addr:
30678 .long 0
30679 efi_rt_function_ptr:
30680diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30681index 4c07cca..2c8427d 100644
30682--- a/arch/x86/platform/efi/efi_stub_64.S
30683+++ b/arch/x86/platform/efi/efi_stub_64.S
30684@@ -7,6 +7,7 @@
30685 */
30686
30687 #include <linux/linkage.h>
30688+#include <asm/alternative-asm.h>
30689
30690 #define SAVE_XMM \
30691 mov %rsp, %rax; \
30692@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30693 call *%rdi
30694 addq $32, %rsp
30695 RESTORE_XMM
30696+ pax_force_retaddr 0, 1
30697 ret
30698 ENDPROC(efi_call0)
30699
30700@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30701 call *%rdi
30702 addq $32, %rsp
30703 RESTORE_XMM
30704+ pax_force_retaddr 0, 1
30705 ret
30706 ENDPROC(efi_call1)
30707
30708@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30709 call *%rdi
30710 addq $32, %rsp
30711 RESTORE_XMM
30712+ pax_force_retaddr 0, 1
30713 ret
30714 ENDPROC(efi_call2)
30715
30716@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30717 call *%rdi
30718 addq $32, %rsp
30719 RESTORE_XMM
30720+ pax_force_retaddr 0, 1
30721 ret
30722 ENDPROC(efi_call3)
30723
30724@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30725 call *%rdi
30726 addq $32, %rsp
30727 RESTORE_XMM
30728+ pax_force_retaddr 0, 1
30729 ret
30730 ENDPROC(efi_call4)
30731
30732@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30733 call *%rdi
30734 addq $48, %rsp
30735 RESTORE_XMM
30736+ pax_force_retaddr 0, 1
30737 ret
30738 ENDPROC(efi_call5)
30739
30740@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30741 call *%rdi
30742 addq $48, %rsp
30743 RESTORE_XMM
30744+ pax_force_retaddr 0, 1
30745 ret
30746 ENDPROC(efi_call6)
30747diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30748index e31bcd8..f12dc46 100644
30749--- a/arch/x86/platform/mrst/mrst.c
30750+++ b/arch/x86/platform/mrst/mrst.c
30751@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30752 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30753 int sfi_mrtc_num;
30754
30755-static void mrst_power_off(void)
30756+static __noreturn void mrst_power_off(void)
30757 {
30758+ BUG();
30759 }
30760
30761-static void mrst_reboot(void)
30762+static __noreturn void mrst_reboot(void)
30763 {
30764 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30765+ BUG();
30766 }
30767
30768 /* parse all the mtimer info to a static mtimer array */
30769diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30770index d6ee929..3637cb5 100644
30771--- a/arch/x86/platform/olpc/olpc_dt.c
30772+++ b/arch/x86/platform/olpc/olpc_dt.c
30773@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30774 return res;
30775 }
30776
30777-static struct of_pdt_ops prom_olpc_ops __initdata = {
30778+static struct of_pdt_ops prom_olpc_ops __initconst = {
30779 .nextprop = olpc_dt_nextprop,
30780 .getproplen = olpc_dt_getproplen,
30781 .getproperty = olpc_dt_getproperty,
30782diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30783index 3c68768..07e82b8 100644
30784--- a/arch/x86/power/cpu.c
30785+++ b/arch/x86/power/cpu.c
30786@@ -134,7 +134,7 @@ static void do_fpu_end(void)
30787 static void fix_processor_context(void)
30788 {
30789 int cpu = smp_processor_id();
30790- struct tss_struct *t = &per_cpu(init_tss, cpu);
30791+ struct tss_struct *t = init_tss + cpu;
30792
30793 set_tss_desc(cpu, t); /*
30794 * This just modifies memory; should not be
30795@@ -144,8 +144,6 @@ static void fix_processor_context(void)
30796 */
30797
30798 #ifdef CONFIG_X86_64
30799- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30800-
30801 syscall_init(); /* This sets MSR_*STAR and related */
30802 #endif
30803 load_TR_desc(); /* This does ltr */
30804diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30805index a44f457..9140171 100644
30806--- a/arch/x86/realmode/init.c
30807+++ b/arch/x86/realmode/init.c
30808@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
30809 __va(real_mode_header->trampoline_header);
30810
30811 #ifdef CONFIG_X86_32
30812- trampoline_header->start = __pa_symbol(startup_32_smp);
30813+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
30814+
30815+#ifdef CONFIG_PAX_KERNEXEC
30816+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30817+#endif
30818+
30819+ trampoline_header->boot_cs = __BOOT_CS;
30820 trampoline_header->gdt_limit = __BOOT_DS + 7;
30821 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
30822 #else
30823@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
30824 *trampoline_cr4_features = read_cr4();
30825
30826 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
30827- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
30828+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
30829 trampoline_pgd[511] = init_level4_pgt[511].pgd;
30830 #endif
30831 }
30832diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30833index 8869287..d577672 100644
30834--- a/arch/x86/realmode/rm/Makefile
30835+++ b/arch/x86/realmode/rm/Makefile
30836@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30837 $(call cc-option, -fno-unit-at-a-time)) \
30838 $(call cc-option, -fno-stack-protector) \
30839 $(call cc-option, -mpreferred-stack-boundary=2)
30840+ifdef CONSTIFY_PLUGIN
30841+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30842+endif
30843 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30844 GCOV_PROFILE := n
30845diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30846index a28221d..93c40f1 100644
30847--- a/arch/x86/realmode/rm/header.S
30848+++ b/arch/x86/realmode/rm/header.S
30849@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30850 #endif
30851 /* APM/BIOS reboot */
30852 .long pa_machine_real_restart_asm
30853-#ifdef CONFIG_X86_64
30854+#ifdef CONFIG_X86_32
30855+ .long __KERNEL_CS
30856+#else
30857 .long __KERNEL32_CS
30858 #endif
30859 END(real_mode_header)
30860diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30861index c1b2791..f9e31c7 100644
30862--- a/arch/x86/realmode/rm/trampoline_32.S
30863+++ b/arch/x86/realmode/rm/trampoline_32.S
30864@@ -25,6 +25,12 @@
30865 #include <asm/page_types.h>
30866 #include "realmode.h"
30867
30868+#ifdef CONFIG_PAX_KERNEXEC
30869+#define ta(X) (X)
30870+#else
30871+#define ta(X) (pa_ ## X)
30872+#endif
30873+
30874 .text
30875 .code16
30876
30877@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30878
30879 cli # We should be safe anyway
30880
30881- movl tr_start, %eax # where we need to go
30882-
30883 movl $0xA5A5A5A5, trampoline_status
30884 # write marker for master knows we're running
30885
30886@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30887 movw $1, %dx # protected mode (PE) bit
30888 lmsw %dx # into protected mode
30889
30890- ljmpl $__BOOT_CS, $pa_startup_32
30891+ ljmpl *(trampoline_header)
30892
30893 .section ".text32","ax"
30894 .code32
30895@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30896 .balign 8
30897 GLOBAL(trampoline_header)
30898 tr_start: .space 4
30899- tr_gdt_pad: .space 2
30900+ tr_boot_cs: .space 2
30901 tr_gdt: .space 6
30902 END(trampoline_header)
30903
30904diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30905index bb360dc..3e5945f 100644
30906--- a/arch/x86/realmode/rm/trampoline_64.S
30907+++ b/arch/x86/realmode/rm/trampoline_64.S
30908@@ -107,7 +107,7 @@ ENTRY(startup_32)
30909 wrmsr
30910
30911 # Enable paging and in turn activate Long Mode
30912- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30913+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
30914 movl %eax, %cr0
30915
30916 /*
30917diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30918index 79d67bd..c7e1b90 100644
30919--- a/arch/x86/tools/relocs.c
30920+++ b/arch/x86/tools/relocs.c
30921@@ -12,10 +12,13 @@
30922 #include <regex.h>
30923 #include <tools/le_byteshift.h>
30924
30925+#include "../../../include/generated/autoconf.h"
30926+
30927 static void die(char *fmt, ...);
30928
30929 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
30930 static Elf32_Ehdr ehdr;
30931+static Elf32_Phdr *phdr;
30932 static unsigned long reloc_count, reloc_idx;
30933 static unsigned long *relocs;
30934 static unsigned long reloc16_count, reloc16_idx;
30935@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
30936 }
30937 }
30938
30939+static void read_phdrs(FILE *fp)
30940+{
30941+ unsigned int i;
30942+
30943+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
30944+ if (!phdr) {
30945+ die("Unable to allocate %d program headers\n",
30946+ ehdr.e_phnum);
30947+ }
30948+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30949+ die("Seek to %d failed: %s\n",
30950+ ehdr.e_phoff, strerror(errno));
30951+ }
30952+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30953+ die("Cannot read ELF program headers: %s\n",
30954+ strerror(errno));
30955+ }
30956+ for(i = 0; i < ehdr.e_phnum; i++) {
30957+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
30958+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
30959+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
30960+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
30961+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
30962+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
30963+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
30964+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
30965+ }
30966+
30967+}
30968+
30969 static void read_shdrs(FILE *fp)
30970 {
30971- int i;
30972+ unsigned int i;
30973 Elf32_Shdr shdr;
30974
30975 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30976@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
30977
30978 static void read_strtabs(FILE *fp)
30979 {
30980- int i;
30981+ unsigned int i;
30982 for (i = 0; i < ehdr.e_shnum; i++) {
30983 struct section *sec = &secs[i];
30984 if (sec->shdr.sh_type != SHT_STRTAB) {
30985@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
30986
30987 static void read_symtabs(FILE *fp)
30988 {
30989- int i,j;
30990+ unsigned int i,j;
30991 for (i = 0; i < ehdr.e_shnum; i++) {
30992 struct section *sec = &secs[i];
30993 if (sec->shdr.sh_type != SHT_SYMTAB) {
30994@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
30995 }
30996
30997
30998-static void read_relocs(FILE *fp)
30999+static void read_relocs(FILE *fp, int use_real_mode)
31000 {
31001- int i,j;
31002+ unsigned int i,j;
31003+ uint32_t base;
31004+
31005 for (i = 0; i < ehdr.e_shnum; i++) {
31006 struct section *sec = &secs[i];
31007 if (sec->shdr.sh_type != SHT_REL) {
31008@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
31009 die("Cannot read symbol table: %s\n",
31010 strerror(errno));
31011 }
31012+ base = 0;
31013+
31014+#ifdef CONFIG_X86_32
31015+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
31016+ if (phdr[j].p_type != PT_LOAD )
31017+ continue;
31018+ 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)
31019+ continue;
31020+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
31021+ break;
31022+ }
31023+#endif
31024+
31025 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
31026 Elf32_Rel *rel = &sec->reltab[j];
31027- rel->r_offset = elf32_to_cpu(rel->r_offset);
31028+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
31029 rel->r_info = elf32_to_cpu(rel->r_info);
31030 }
31031 }
31032@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
31033
31034 static void print_absolute_symbols(void)
31035 {
31036- int i;
31037+ unsigned int i;
31038 printf("Absolute symbols\n");
31039 printf(" Num: Value Size Type Bind Visibility Name\n");
31040 for (i = 0; i < ehdr.e_shnum; i++) {
31041 struct section *sec = &secs[i];
31042 char *sym_strtab;
31043- int j;
31044+ unsigned int j;
31045
31046 if (sec->shdr.sh_type != SHT_SYMTAB) {
31047 continue;
31048@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
31049
31050 static void print_absolute_relocs(void)
31051 {
31052- int i, printed = 0;
31053+ unsigned int i, printed = 0;
31054
31055 for (i = 0; i < ehdr.e_shnum; i++) {
31056 struct section *sec = &secs[i];
31057 struct section *sec_applies, *sec_symtab;
31058 char *sym_strtab;
31059 Elf32_Sym *sh_symtab;
31060- int j;
31061+ unsigned int j;
31062 if (sec->shdr.sh_type != SHT_REL) {
31063 continue;
31064 }
31065@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
31066 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
31067 int use_real_mode)
31068 {
31069- int i;
31070+ unsigned int i;
31071 /* Walk through the relocations */
31072 for (i = 0; i < ehdr.e_shnum; i++) {
31073 char *sym_strtab;
31074 Elf32_Sym *sh_symtab;
31075 struct section *sec_applies, *sec_symtab;
31076- int j;
31077+ unsigned int j;
31078 struct section *sec = &secs[i];
31079
31080 if (sec->shdr.sh_type != SHT_REL) {
31081@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
31082 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
31083 r_type = ELF32_R_TYPE(rel->r_info);
31084
31085+ if (!use_real_mode) {
31086+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
31087+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
31088+ continue;
31089+
31090+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
31091+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
31092+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
31093+ continue;
31094+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
31095+ continue;
31096+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
31097+ continue;
31098+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
31099+ continue;
31100+#endif
31101+ }
31102+
31103 shn_abs = sym->st_shndx == SHN_ABS;
31104
31105 switch (r_type) {
31106@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
31107
31108 static void emit_relocs(int as_text, int use_real_mode)
31109 {
31110- int i;
31111+ unsigned int i;
31112 /* Count how many relocations I have and allocate space for them. */
31113 reloc_count = 0;
31114 walk_relocs(count_reloc, use_real_mode);
31115@@ -808,10 +874,11 @@ int main(int argc, char **argv)
31116 fname, strerror(errno));
31117 }
31118 read_ehdr(fp);
31119+ read_phdrs(fp);
31120 read_shdrs(fp);
31121 read_strtabs(fp);
31122 read_symtabs(fp);
31123- read_relocs(fp);
31124+ read_relocs(fp, use_real_mode);
31125 if (show_absolute_syms) {
31126 print_absolute_symbols();
31127 goto out;
31128diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
31129index fd14be1..e3c79c0 100644
31130--- a/arch/x86/vdso/Makefile
31131+++ b/arch/x86/vdso/Makefile
31132@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
31133 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
31134 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
31135
31136-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31137+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31138 GCOV_PROFILE := n
31139
31140 #
31141diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
31142index 0faad64..39ef157 100644
31143--- a/arch/x86/vdso/vdso32-setup.c
31144+++ b/arch/x86/vdso/vdso32-setup.c
31145@@ -25,6 +25,7 @@
31146 #include <asm/tlbflush.h>
31147 #include <asm/vdso.h>
31148 #include <asm/proto.h>
31149+#include <asm/mman.h>
31150
31151 enum {
31152 VDSO_DISABLED = 0,
31153@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
31154 void enable_sep_cpu(void)
31155 {
31156 int cpu = get_cpu();
31157- struct tss_struct *tss = &per_cpu(init_tss, cpu);
31158+ struct tss_struct *tss = init_tss + cpu;
31159
31160 if (!boot_cpu_has(X86_FEATURE_SEP)) {
31161 put_cpu();
31162@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
31163 gate_vma.vm_start = FIXADDR_USER_START;
31164 gate_vma.vm_end = FIXADDR_USER_END;
31165 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
31166- gate_vma.vm_page_prot = __P101;
31167+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
31168
31169 return 0;
31170 }
31171@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31172 if (compat)
31173 addr = VDSO_HIGH_BASE;
31174 else {
31175- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
31176+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
31177 if (IS_ERR_VALUE(addr)) {
31178 ret = addr;
31179 goto up_fail;
31180 }
31181 }
31182
31183- current->mm->context.vdso = (void *)addr;
31184+ current->mm->context.vdso = addr;
31185
31186 if (compat_uses_vma || !compat) {
31187 /*
31188@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31189 }
31190
31191 current_thread_info()->sysenter_return =
31192- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31193+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31194
31195 up_fail:
31196 if (ret)
31197- current->mm->context.vdso = NULL;
31198+ current->mm->context.vdso = 0;
31199
31200 up_write(&mm->mmap_sem);
31201
31202@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
31203
31204 const char *arch_vma_name(struct vm_area_struct *vma)
31205 {
31206- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31207+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31208 return "[vdso]";
31209+
31210+#ifdef CONFIG_PAX_SEGMEXEC
31211+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
31212+ return "[vdso]";
31213+#endif
31214+
31215 return NULL;
31216 }
31217
31218@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31219 * Check to see if the corresponding task was created in compat vdso
31220 * mode.
31221 */
31222- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
31223+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
31224 return &gate_vma;
31225 return NULL;
31226 }
31227diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
31228index 431e875..cbb23f3 100644
31229--- a/arch/x86/vdso/vma.c
31230+++ b/arch/x86/vdso/vma.c
31231@@ -16,8 +16,6 @@
31232 #include <asm/vdso.h>
31233 #include <asm/page.h>
31234
31235-unsigned int __read_mostly vdso_enabled = 1;
31236-
31237 extern char vdso_start[], vdso_end[];
31238 extern unsigned short vdso_sync_cpuid;
31239
31240@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31241 * unaligned here as a result of stack start randomization.
31242 */
31243 addr = PAGE_ALIGN(addr);
31244- addr = align_vdso_addr(addr);
31245
31246 return addr;
31247 }
31248@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31249 unsigned size)
31250 {
31251 struct mm_struct *mm = current->mm;
31252- unsigned long addr;
31253+ unsigned long addr = 0;
31254 int ret;
31255
31256- if (!vdso_enabled)
31257- return 0;
31258-
31259 down_write(&mm->mmap_sem);
31260+
31261+#ifdef CONFIG_PAX_RANDMMAP
31262+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31263+#endif
31264+
31265 addr = vdso_addr(mm->start_stack, size);
31266+ addr = align_vdso_addr(addr);
31267 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31268 if (IS_ERR_VALUE(addr)) {
31269 ret = addr;
31270 goto up_fail;
31271 }
31272
31273- current->mm->context.vdso = (void *)addr;
31274+ mm->context.vdso = addr;
31275
31276 ret = install_special_mapping(mm, addr, size,
31277 VM_READ|VM_EXEC|
31278 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31279 pages);
31280- if (ret) {
31281- current->mm->context.vdso = NULL;
31282- goto up_fail;
31283- }
31284+ if (ret)
31285+ mm->context.vdso = 0;
31286
31287 up_fail:
31288 up_write(&mm->mmap_sem);
31289@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31290 vdsox32_size);
31291 }
31292 #endif
31293-
31294-static __init int vdso_setup(char *s)
31295-{
31296- vdso_enabled = simple_strtoul(s, NULL, 0);
31297- return 0;
31298-}
31299-__setup("vdso=", vdso_setup);
31300diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31301index cf95e19..17e9f50 100644
31302--- a/arch/x86/xen/enlighten.c
31303+++ b/arch/x86/xen/enlighten.c
31304@@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31305
31306 struct shared_info xen_dummy_shared_info;
31307
31308-void *xen_initial_gdt;
31309-
31310 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31311 __read_mostly int xen_have_vector_callback;
31312 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31313@@ -511,8 +509,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31314 {
31315 unsigned long va = dtr->address;
31316 unsigned int size = dtr->size + 1;
31317- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31318- unsigned long frames[pages];
31319+ unsigned long frames[65536 / PAGE_SIZE];
31320 int f;
31321
31322 /*
31323@@ -560,8 +557,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31324 {
31325 unsigned long va = dtr->address;
31326 unsigned int size = dtr->size + 1;
31327- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31328- unsigned long frames[pages];
31329+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
31330 int f;
31331
31332 /*
31333@@ -569,7 +565,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31334 * 8-byte entries, or 16 4k pages..
31335 */
31336
31337- BUG_ON(size > 65536);
31338+ BUG_ON(size > GDT_SIZE);
31339 BUG_ON(va & ~PAGE_MASK);
31340
31341 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
31342@@ -954,7 +950,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31343 return 0;
31344 }
31345
31346-static void set_xen_basic_apic_ops(void)
31347+static void __init set_xen_basic_apic_ops(void)
31348 {
31349 apic->read = xen_apic_read;
31350 apic->write = xen_apic_write;
31351@@ -1260,30 +1256,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31352 #endif
31353 };
31354
31355-static void xen_reboot(int reason)
31356+static __noreturn void xen_reboot(int reason)
31357 {
31358 struct sched_shutdown r = { .reason = reason };
31359
31360- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31361- BUG();
31362+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31363+ BUG();
31364 }
31365
31366-static void xen_restart(char *msg)
31367+static __noreturn void xen_restart(char *msg)
31368 {
31369 xen_reboot(SHUTDOWN_reboot);
31370 }
31371
31372-static void xen_emergency_restart(void)
31373+static __noreturn void xen_emergency_restart(void)
31374 {
31375 xen_reboot(SHUTDOWN_reboot);
31376 }
31377
31378-static void xen_machine_halt(void)
31379+static __noreturn void xen_machine_halt(void)
31380 {
31381 xen_reboot(SHUTDOWN_poweroff);
31382 }
31383
31384-static void xen_machine_power_off(void)
31385+static __noreturn void xen_machine_power_off(void)
31386 {
31387 if (pm_power_off)
31388 pm_power_off();
31389@@ -1385,7 +1381,17 @@ asmlinkage void __init xen_start_kernel(void)
31390 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31391
31392 /* Work out if we support NX */
31393- x86_configure_nx();
31394+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31395+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31396+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31397+ unsigned l, h;
31398+
31399+ __supported_pte_mask |= _PAGE_NX;
31400+ rdmsr(MSR_EFER, l, h);
31401+ l |= EFER_NX;
31402+ wrmsr(MSR_EFER, l, h);
31403+ }
31404+#endif
31405
31406 xen_setup_features();
31407
31408@@ -1416,13 +1422,6 @@ asmlinkage void __init xen_start_kernel(void)
31409
31410 machine_ops = xen_machine_ops;
31411
31412- /*
31413- * The only reliable way to retain the initial address of the
31414- * percpu gdt_page is to remember it here, so we can go and
31415- * mark it RW later, when the initial percpu area is freed.
31416- */
31417- xen_initial_gdt = &per_cpu(gdt_page, 0);
31418-
31419 xen_smp_init();
31420
31421 #ifdef CONFIG_ACPI_NUMA
31422@@ -1616,7 +1615,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31423 return NOTIFY_OK;
31424 }
31425
31426-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31427+static struct notifier_block xen_hvm_cpu_notifier = {
31428 .notifier_call = xen_hvm_cpu_notify,
31429 };
31430
31431diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31432index e006c18..b9a7d6c 100644
31433--- a/arch/x86/xen/mmu.c
31434+++ b/arch/x86/xen/mmu.c
31435@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31436 /* L3_k[510] -> level2_kernel_pgt
31437 * L3_i[511] -> level2_fixmap_pgt */
31438 convert_pfn_mfn(level3_kernel_pgt);
31439+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31440+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31441+ convert_pfn_mfn(level3_vmemmap_pgt);
31442
31443 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31444 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31445@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31446 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31447 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31448 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31449+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31450+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31451+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31452 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31453 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31454+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31455 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31456 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31457
31458@@ -2110,6 +2117,7 @@ static void __init xen_post_allocator_init(void)
31459 pv_mmu_ops.set_pud = xen_set_pud;
31460 #if PAGETABLE_LEVELS == 4
31461 pv_mmu_ops.set_pgd = xen_set_pgd;
31462+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31463 #endif
31464
31465 /* This will work as long as patching hasn't happened yet
31466@@ -2188,6 +2196,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31467 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31468 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31469 .set_pgd = xen_set_pgd_hyper,
31470+ .set_pgd_batched = xen_set_pgd_hyper,
31471
31472 .alloc_pud = xen_alloc_pmd_init,
31473 .release_pud = xen_release_pmd_init,
31474diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31475index 96c4e85..284fded 100644
31476--- a/arch/x86/xen/smp.c
31477+++ b/arch/x86/xen/smp.c
31478@@ -230,11 +230,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31479 {
31480 BUG_ON(smp_processor_id() != 0);
31481 native_smp_prepare_boot_cpu();
31482-
31483- /* We've switched to the "real" per-cpu gdt, so make sure the
31484- old memory can be recycled */
31485- make_lowmem_page_readwrite(xen_initial_gdt);
31486-
31487 xen_filter_cpu_maps();
31488 xen_setup_vcpu_info_placement();
31489 }
31490@@ -304,7 +299,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31491 ctxt->user_regs.ss = __KERNEL_DS;
31492 #ifdef CONFIG_X86_32
31493 ctxt->user_regs.fs = __KERNEL_PERCPU;
31494- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31495+ savesegment(gs, ctxt->user_regs.gs);
31496 #else
31497 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31498 #endif
31499@@ -314,8 +309,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31500
31501 {
31502 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
31503- ctxt->user_regs.ds = __USER_DS;
31504- ctxt->user_regs.es = __USER_DS;
31505+ ctxt->user_regs.ds = __KERNEL_DS;
31506+ ctxt->user_regs.es = __KERNEL_DS;
31507
31508 xen_copy_trap_info(ctxt->trap_ctxt);
31509
31510@@ -360,13 +355,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31511 int rc;
31512
31513 per_cpu(current_task, cpu) = idle;
31514+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31515 #ifdef CONFIG_X86_32
31516 irq_ctx_init(cpu);
31517 #else
31518 clear_tsk_thread_flag(idle, TIF_FORK);
31519- per_cpu(kernel_stack, cpu) =
31520- (unsigned long)task_stack_page(idle) -
31521- KERNEL_STACK_OFFSET + THREAD_SIZE;
31522+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31523 #endif
31524 xen_setup_runstate_info(cpu);
31525 xen_setup_timer(cpu);
31526@@ -642,7 +636,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31527
31528 void __init xen_smp_init(void)
31529 {
31530- smp_ops = xen_smp_ops;
31531+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31532 xen_fill_possible_map();
31533 xen_init_spinlocks();
31534 }
31535diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31536index 33ca6e4..0ded929 100644
31537--- a/arch/x86/xen/xen-asm_32.S
31538+++ b/arch/x86/xen/xen-asm_32.S
31539@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31540 ESP_OFFSET=4 # bytes pushed onto stack
31541
31542 /*
31543- * Store vcpu_info pointer for easy access. Do it this way to
31544- * avoid having to reload %fs
31545+ * Store vcpu_info pointer for easy access.
31546 */
31547 #ifdef CONFIG_SMP
31548- GET_THREAD_INFO(%eax)
31549- movl %ss:TI_cpu(%eax), %eax
31550- movl %ss:__per_cpu_offset(,%eax,4), %eax
31551- mov %ss:xen_vcpu(%eax), %eax
31552+ push %fs
31553+ mov $(__KERNEL_PERCPU), %eax
31554+ mov %eax, %fs
31555+ mov PER_CPU_VAR(xen_vcpu), %eax
31556+ pop %fs
31557 #else
31558 movl %ss:xen_vcpu, %eax
31559 #endif
31560diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31561index 7faed58..ba4427c 100644
31562--- a/arch/x86/xen/xen-head.S
31563+++ b/arch/x86/xen/xen-head.S
31564@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31565 #ifdef CONFIG_X86_32
31566 mov %esi,xen_start_info
31567 mov $init_thread_union+THREAD_SIZE,%esp
31568+#ifdef CONFIG_SMP
31569+ movl $cpu_gdt_table,%edi
31570+ movl $__per_cpu_load,%eax
31571+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31572+ rorl $16,%eax
31573+ movb %al,__KERNEL_PERCPU + 4(%edi)
31574+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31575+ movl $__per_cpu_end - 1,%eax
31576+ subl $__per_cpu_start,%eax
31577+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31578+#endif
31579 #else
31580 mov %rsi,xen_start_info
31581 mov $init_thread_union+THREAD_SIZE,%rsp
31582diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31583index a95b417..b6dbd0b 100644
31584--- a/arch/x86/xen/xen-ops.h
31585+++ b/arch/x86/xen/xen-ops.h
31586@@ -10,8 +10,6 @@
31587 extern const char xen_hypervisor_callback[];
31588 extern const char xen_failsafe_callback[];
31589
31590-extern void *xen_initial_gdt;
31591-
31592 struct trap_info;
31593 void xen_copy_trap_info(struct trap_info *traps);
31594
31595diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31596index 525bd3d..ef888b1 100644
31597--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31598+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31599@@ -119,9 +119,9 @@
31600 ----------------------------------------------------------------------*/
31601
31602 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31603-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31604 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31605 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31606+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31607
31608 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31609 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31610diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31611index 2f33760..835e50a 100644
31612--- a/arch/xtensa/variants/fsf/include/variant/core.h
31613+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31614@@ -11,6 +11,7 @@
31615 #ifndef _XTENSA_CORE_H
31616 #define _XTENSA_CORE_H
31617
31618+#include <linux/const.h>
31619
31620 /****************************************************************************
31621 Parameters Useful for Any Code, USER or PRIVILEGED
31622@@ -112,9 +113,9 @@
31623 ----------------------------------------------------------------------*/
31624
31625 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31626-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31627 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31628 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31629+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31630
31631 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31632 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31633diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31634index af00795..2bb8105 100644
31635--- a/arch/xtensa/variants/s6000/include/variant/core.h
31636+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31637@@ -11,6 +11,7 @@
31638 #ifndef _XTENSA_CORE_CONFIGURATION_H
31639 #define _XTENSA_CORE_CONFIGURATION_H
31640
31641+#include <linux/const.h>
31642
31643 /****************************************************************************
31644 Parameters Useful for Any Code, USER or PRIVILEGED
31645@@ -118,9 +119,9 @@
31646 ----------------------------------------------------------------------*/
31647
31648 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31649-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31650 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31651 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31652+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31653
31654 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31655 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31656diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31657index 58916af..eb9dbcf6 100644
31658--- a/block/blk-iopoll.c
31659+++ b/block/blk-iopoll.c
31660@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31661 }
31662 EXPORT_SYMBOL(blk_iopoll_complete);
31663
31664-static void blk_iopoll_softirq(struct softirq_action *h)
31665+static void blk_iopoll_softirq(void)
31666 {
31667 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31668 int rearm = 0, budget = blk_iopoll_budget;
31669@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31670 return NOTIFY_OK;
31671 }
31672
31673-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31674+static struct notifier_block blk_iopoll_cpu_notifier = {
31675 .notifier_call = blk_iopoll_cpu_notify,
31676 };
31677
31678diff --git a/block/blk-map.c b/block/blk-map.c
31679index 623e1cd..ca1e109 100644
31680--- a/block/blk-map.c
31681+++ b/block/blk-map.c
31682@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31683 if (!len || !kbuf)
31684 return -EINVAL;
31685
31686- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31687+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31688 if (do_copy)
31689 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31690 else
31691diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31692index 467c8de..f3628c5 100644
31693--- a/block/blk-softirq.c
31694+++ b/block/blk-softirq.c
31695@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31696 * Softirq action handler - move entries to local list and loop over them
31697 * while passing them to the queue registered handler.
31698 */
31699-static void blk_done_softirq(struct softirq_action *h)
31700+static void blk_done_softirq(void)
31701 {
31702 struct list_head *cpu_list, local_list;
31703
31704@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31705 return NOTIFY_OK;
31706 }
31707
31708-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31709+static struct notifier_block blk_cpu_notifier = {
31710 .notifier_call = blk_cpu_notify,
31711 };
31712
31713diff --git a/block/bsg.c b/block/bsg.c
31714index 420a5a9..23834aa 100644
31715--- a/block/bsg.c
31716+++ b/block/bsg.c
31717@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31718 struct sg_io_v4 *hdr, struct bsg_device *bd,
31719 fmode_t has_write_perm)
31720 {
31721+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31722+ unsigned char *cmdptr;
31723+
31724 if (hdr->request_len > BLK_MAX_CDB) {
31725 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31726 if (!rq->cmd)
31727 return -ENOMEM;
31728- }
31729+ cmdptr = rq->cmd;
31730+ } else
31731+ cmdptr = tmpcmd;
31732
31733- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31734+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31735 hdr->request_len))
31736 return -EFAULT;
31737
31738+ if (cmdptr != rq->cmd)
31739+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31740+
31741 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31742 if (blk_verify_command(rq->cmd, has_write_perm))
31743 return -EPERM;
31744diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31745index 7c668c8..db3521c 100644
31746--- a/block/compat_ioctl.c
31747+++ b/block/compat_ioctl.c
31748@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31749 err |= __get_user(f->spec1, &uf->spec1);
31750 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31751 err |= __get_user(name, &uf->name);
31752- f->name = compat_ptr(name);
31753+ f->name = (void __force_kernel *)compat_ptr(name);
31754 if (err) {
31755 err = -EFAULT;
31756 goto out;
31757diff --git a/block/genhd.c b/block/genhd.c
31758index 3c001fb..d15a9e8 100644
31759--- a/block/genhd.c
31760+++ b/block/genhd.c
31761@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
31762
31763 /*
31764 * Register device numbers dev..(dev+range-1)
31765- * range must be nonzero
31766+ * Noop if @range is zero.
31767 * The hash chain is sorted on range, so that subranges can override.
31768 */
31769 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
31770 struct kobject *(*probe)(dev_t, int *, void *),
31771 int (*lock)(dev_t, void *), void *data)
31772 {
31773- kobj_map(bdev_map, devt, range, module, probe, lock, data);
31774+ if (range)
31775+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
31776 }
31777
31778 EXPORT_SYMBOL(blk_register_region);
31779
31780+/* undo blk_register_region(), noop if @range is zero */
31781 void blk_unregister_region(dev_t devt, unsigned long range)
31782 {
31783- kobj_unmap(bdev_map, devt, range);
31784+ if (range)
31785+ kobj_unmap(bdev_map, devt, range);
31786 }
31787
31788 EXPORT_SYMBOL(blk_unregister_region);
31789@@ -512,7 +515,7 @@ static void register_disk(struct gendisk *disk)
31790
31791 ddev->parent = disk->driverfs_dev;
31792
31793- dev_set_name(ddev, disk->disk_name);
31794+ dev_set_name(ddev, "%s", disk->disk_name);
31795
31796 /* delay uevents, until we scanned partition table */
31797 dev_set_uevent_suppress(ddev, 1);
31798diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31799index ff5804e..a88acad 100644
31800--- a/block/partitions/efi.c
31801+++ b/block/partitions/efi.c
31802@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31803 if (!gpt)
31804 return NULL;
31805
31806+ if (!le32_to_cpu(gpt->num_partition_entries))
31807+ return NULL;
31808+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31809+ if (!pte)
31810+ return NULL;
31811+
31812 count = le32_to_cpu(gpt->num_partition_entries) *
31813 le32_to_cpu(gpt->sizeof_partition_entry);
31814- if (!count)
31815- return NULL;
31816- pte = kzalloc(count, GFP_KERNEL);
31817- if (!pte)
31818- return NULL;
31819-
31820 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31821 (u8 *) pte,
31822 count) < count) {
31823diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31824index 9a87daa..fb17486 100644
31825--- a/block/scsi_ioctl.c
31826+++ b/block/scsi_ioctl.c
31827@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
31828 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31829 struct sg_io_hdr *hdr, fmode_t mode)
31830 {
31831- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31832+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31833+ unsigned char *cmdptr;
31834+
31835+ if (rq->cmd != rq->__cmd)
31836+ cmdptr = rq->cmd;
31837+ else
31838+ cmdptr = tmpcmd;
31839+
31840+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31841 return -EFAULT;
31842+
31843+ if (cmdptr != rq->cmd)
31844+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31845+
31846 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31847 return -EPERM;
31848
31849@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31850 int err;
31851 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31852 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31853+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31854+ unsigned char *cmdptr;
31855
31856 if (!sic)
31857 return -EINVAL;
31858@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31859 */
31860 err = -EFAULT;
31861 rq->cmd_len = cmdlen;
31862- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31863+
31864+ if (rq->cmd != rq->__cmd)
31865+ cmdptr = rq->cmd;
31866+ else
31867+ cmdptr = tmpcmd;
31868+
31869+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31870 goto error;
31871
31872+ if (rq->cmd != cmdptr)
31873+ memcpy(rq->cmd, cmdptr, cmdlen);
31874+
31875 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31876 goto error;
31877
31878diff --git a/crypto/algapi.c b/crypto/algapi.c
31879index 6149a6e..55ed50d 100644
31880--- a/crypto/algapi.c
31881+++ b/crypto/algapi.c
31882@@ -495,7 +495,7 @@ static struct crypto_template *__crypto_lookup_template(const char *name)
31883
31884 struct crypto_template *crypto_lookup_template(const char *name)
31885 {
31886- return try_then_request_module(__crypto_lookup_template(name), name);
31887+ return try_then_request_module(__crypto_lookup_template(name), "%s", name);
31888 }
31889 EXPORT_SYMBOL_GPL(crypto_lookup_template);
31890
31891diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31892index 7bdd61b..afec999 100644
31893--- a/crypto/cryptd.c
31894+++ b/crypto/cryptd.c
31895@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31896
31897 struct cryptd_blkcipher_request_ctx {
31898 crypto_completion_t complete;
31899-};
31900+} __no_const;
31901
31902 struct cryptd_hash_ctx {
31903 struct crypto_shash *child;
31904@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31905
31906 struct cryptd_aead_request_ctx {
31907 crypto_completion_t complete;
31908-};
31909+} __no_const;
31910
31911 static void cryptd_queue_worker(struct work_struct *work);
31912
31913diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
31914index b2c99dc..476c9fb 100644
31915--- a/crypto/pcrypt.c
31916+++ b/crypto/pcrypt.c
31917@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
31918 int ret;
31919
31920 pinst->kobj.kset = pcrypt_kset;
31921- ret = kobject_add(&pinst->kobj, NULL, name);
31922+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
31923 if (!ret)
31924 kobject_uevent(&pinst->kobj, KOBJ_ADD);
31925
31926@@ -455,8 +455,8 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
31927
31928 get_online_cpus();
31929
31930- pcrypt->wq = alloc_workqueue(name,
31931- WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
31932+ pcrypt->wq = alloc_workqueue("%s",
31933+ WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1, name);
31934 if (!pcrypt->wq)
31935 goto err;
31936
31937diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31938index f220d64..d359ad6 100644
31939--- a/drivers/acpi/apei/apei-internal.h
31940+++ b/drivers/acpi/apei/apei-internal.h
31941@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31942 struct apei_exec_ins_type {
31943 u32 flags;
31944 apei_exec_ins_func_t run;
31945-};
31946+} __do_const;
31947
31948 struct apei_exec_context {
31949 u32 ip;
31950diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31951index fefc2ca..12a535d 100644
31952--- a/drivers/acpi/apei/cper.c
31953+++ b/drivers/acpi/apei/cper.c
31954@@ -39,12 +39,12 @@
31955 */
31956 u64 cper_next_record_id(void)
31957 {
31958- static atomic64_t seq;
31959+ static atomic64_unchecked_t seq;
31960
31961- if (!atomic64_read(&seq))
31962- atomic64_set(&seq, ((u64)get_seconds()) << 32);
31963+ if (!atomic64_read_unchecked(&seq))
31964+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31965
31966- return atomic64_inc_return(&seq);
31967+ return atomic64_inc_return_unchecked(&seq);
31968 }
31969 EXPORT_SYMBOL_GPL(cper_next_record_id);
31970
31971diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31972index be60399..778b33e8 100644
31973--- a/drivers/acpi/bgrt.c
31974+++ b/drivers/acpi/bgrt.c
31975@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31976 return -ENODEV;
31977
31978 sysfs_bin_attr_init(&image_attr);
31979- image_attr.private = bgrt_image;
31980- image_attr.size = bgrt_image_size;
31981+ pax_open_kernel();
31982+ *(void **)&image_attr.private = bgrt_image;
31983+ *(size_t *)&image_attr.size = bgrt_image_size;
31984+ pax_close_kernel();
31985
31986 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31987 if (!bgrt_kobj)
31988diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31989index cb96296..b81293b 100644
31990--- a/drivers/acpi/blacklist.c
31991+++ b/drivers/acpi/blacklist.c
31992@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31993 u32 is_critical_error;
31994 };
31995
31996-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31997+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31998
31999 /*
32000 * POLICY: If *anything* doesn't work, put it on the blacklist.
32001@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
32002 return 0;
32003 }
32004
32005-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
32006+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
32007 {
32008 .callback = dmi_disable_osi_vista,
32009 .ident = "Fujitsu Siemens",
32010diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
32011index 7586544..636a2f0 100644
32012--- a/drivers/acpi/ec_sys.c
32013+++ b/drivers/acpi/ec_sys.c
32014@@ -12,6 +12,7 @@
32015 #include <linux/acpi.h>
32016 #include <linux/debugfs.h>
32017 #include <linux/module.h>
32018+#include <linux/uaccess.h>
32019 #include "internal.h"
32020
32021 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
32022@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32023 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
32024 */
32025 unsigned int size = EC_SPACE_SIZE;
32026- u8 *data = (u8 *) buf;
32027+ u8 data;
32028 loff_t init_off = *off;
32029 int err = 0;
32030
32031@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32032 size = count;
32033
32034 while (size) {
32035- err = ec_read(*off, &data[*off - init_off]);
32036+ err = ec_read(*off, &data);
32037 if (err)
32038 return err;
32039+ if (put_user(data, &buf[*off - init_off]))
32040+ return -EFAULT;
32041 *off += 1;
32042 size--;
32043 }
32044@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32045
32046 unsigned int size = count;
32047 loff_t init_off = *off;
32048- u8 *data = (u8 *) buf;
32049 int err = 0;
32050
32051 if (*off >= EC_SPACE_SIZE)
32052@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32053 }
32054
32055 while (size) {
32056- u8 byte_write = data[*off - init_off];
32057+ u8 byte_write;
32058+ if (get_user(byte_write, &buf[*off - init_off]))
32059+ return -EFAULT;
32060 err = ec_write(*off, byte_write);
32061 if (err)
32062 return err;
32063diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
32064index ee255c6..747c68b 100644
32065--- a/drivers/acpi/processor_idle.c
32066+++ b/drivers/acpi/processor_idle.c
32067@@ -986,7 +986,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
32068 {
32069 int i, count = CPUIDLE_DRIVER_STATE_START;
32070 struct acpi_processor_cx *cx;
32071- struct cpuidle_state *state;
32072+ cpuidle_state_no_const *state;
32073 struct cpuidle_driver *drv = &acpi_idle_driver;
32074
32075 if (!pr->flags.power_setup_done)
32076diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
32077index 41c0504..f8c0836 100644
32078--- a/drivers/acpi/sysfs.c
32079+++ b/drivers/acpi/sysfs.c
32080@@ -420,11 +420,11 @@ static u32 num_counters;
32081 static struct attribute **all_attrs;
32082 static u32 acpi_gpe_count;
32083
32084-static struct attribute_group interrupt_stats_attr_group = {
32085+static attribute_group_no_const interrupt_stats_attr_group = {
32086 .name = "interrupts",
32087 };
32088
32089-static struct kobj_attribute *counter_attrs;
32090+static kobj_attribute_no_const *counter_attrs;
32091
32092 static void delete_gpe_attr_array(void)
32093 {
32094diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
32095index 34c8216..f56c828 100644
32096--- a/drivers/ata/libahci.c
32097+++ b/drivers/ata/libahci.c
32098@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
32099 }
32100 EXPORT_SYMBOL_GPL(ahci_kick_engine);
32101
32102-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32103+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32104 struct ata_taskfile *tf, int is_cmd, u16 flags,
32105 unsigned long timeout_msec)
32106 {
32107diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
32108index 8038ee3..a19a6e6 100644
32109--- a/drivers/ata/libata-core.c
32110+++ b/drivers/ata/libata-core.c
32111@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
32112 struct ata_port *ap;
32113 unsigned int tag;
32114
32115- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32116+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32117 ap = qc->ap;
32118
32119 qc->flags = 0;
32120@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
32121 struct ata_port *ap;
32122 struct ata_link *link;
32123
32124- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32125+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32126 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
32127 ap = qc->ap;
32128 link = qc->dev->link;
32129@@ -5926,6 +5926,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32130 return;
32131
32132 spin_lock(&lock);
32133+ pax_open_kernel();
32134
32135 for (cur = ops->inherits; cur; cur = cur->inherits) {
32136 void **inherit = (void **)cur;
32137@@ -5939,8 +5940,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32138 if (IS_ERR(*pp))
32139 *pp = NULL;
32140
32141- ops->inherits = NULL;
32142+ *(struct ata_port_operations **)&ops->inherits = NULL;
32143
32144+ pax_close_kernel();
32145 spin_unlock(&lock);
32146 }
32147
32148diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
32149index 405022d..fb70e53 100644
32150--- a/drivers/ata/pata_arasan_cf.c
32151+++ b/drivers/ata/pata_arasan_cf.c
32152@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
32153 /* Handle platform specific quirks */
32154 if (pdata->quirk) {
32155 if (pdata->quirk & CF_BROKEN_PIO) {
32156- ap->ops->set_piomode = NULL;
32157+ pax_open_kernel();
32158+ *(void **)&ap->ops->set_piomode = NULL;
32159+ pax_close_kernel();
32160 ap->pio_mask = 0;
32161 }
32162 if (pdata->quirk & CF_BROKEN_MWDMA)
32163diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
32164index f9b983a..887b9d8 100644
32165--- a/drivers/atm/adummy.c
32166+++ b/drivers/atm/adummy.c
32167@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
32168 vcc->pop(vcc, skb);
32169 else
32170 dev_kfree_skb_any(skb);
32171- atomic_inc(&vcc->stats->tx);
32172+ atomic_inc_unchecked(&vcc->stats->tx);
32173
32174 return 0;
32175 }
32176diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
32177index 77a7480d..05cde58 100644
32178--- a/drivers/atm/ambassador.c
32179+++ b/drivers/atm/ambassador.c
32180@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
32181 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
32182
32183 // VC layer stats
32184- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32185+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32186
32187 // free the descriptor
32188 kfree (tx_descr);
32189@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32190 dump_skb ("<<<", vc, skb);
32191
32192 // VC layer stats
32193- atomic_inc(&atm_vcc->stats->rx);
32194+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32195 __net_timestamp(skb);
32196 // end of our responsibility
32197 atm_vcc->push (atm_vcc, skb);
32198@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32199 } else {
32200 PRINTK (KERN_INFO, "dropped over-size frame");
32201 // should we count this?
32202- atomic_inc(&atm_vcc->stats->rx_drop);
32203+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32204 }
32205
32206 } else {
32207@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
32208 }
32209
32210 if (check_area (skb->data, skb->len)) {
32211- atomic_inc(&atm_vcc->stats->tx_err);
32212+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
32213 return -ENOMEM; // ?
32214 }
32215
32216diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
32217index 0e3f8f9..765a7a5 100644
32218--- a/drivers/atm/atmtcp.c
32219+++ b/drivers/atm/atmtcp.c
32220@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32221 if (vcc->pop) vcc->pop(vcc,skb);
32222 else dev_kfree_skb(skb);
32223 if (dev_data) return 0;
32224- atomic_inc(&vcc->stats->tx_err);
32225+ atomic_inc_unchecked(&vcc->stats->tx_err);
32226 return -ENOLINK;
32227 }
32228 size = skb->len+sizeof(struct atmtcp_hdr);
32229@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32230 if (!new_skb) {
32231 if (vcc->pop) vcc->pop(vcc,skb);
32232 else dev_kfree_skb(skb);
32233- atomic_inc(&vcc->stats->tx_err);
32234+ atomic_inc_unchecked(&vcc->stats->tx_err);
32235 return -ENOBUFS;
32236 }
32237 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
32238@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32239 if (vcc->pop) vcc->pop(vcc,skb);
32240 else dev_kfree_skb(skb);
32241 out_vcc->push(out_vcc,new_skb);
32242- atomic_inc(&vcc->stats->tx);
32243- atomic_inc(&out_vcc->stats->rx);
32244+ atomic_inc_unchecked(&vcc->stats->tx);
32245+ atomic_inc_unchecked(&out_vcc->stats->rx);
32246 return 0;
32247 }
32248
32249@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32250 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32251 read_unlock(&vcc_sklist_lock);
32252 if (!out_vcc) {
32253- atomic_inc(&vcc->stats->tx_err);
32254+ atomic_inc_unchecked(&vcc->stats->tx_err);
32255 goto done;
32256 }
32257 skb_pull(skb,sizeof(struct atmtcp_hdr));
32258@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32259 __net_timestamp(new_skb);
32260 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32261 out_vcc->push(out_vcc,new_skb);
32262- atomic_inc(&vcc->stats->tx);
32263- atomic_inc(&out_vcc->stats->rx);
32264+ atomic_inc_unchecked(&vcc->stats->tx);
32265+ atomic_inc_unchecked(&out_vcc->stats->rx);
32266 done:
32267 if (vcc->pop) vcc->pop(vcc,skb);
32268 else dev_kfree_skb(skb);
32269diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
32270index b1955ba..b179940 100644
32271--- a/drivers/atm/eni.c
32272+++ b/drivers/atm/eni.c
32273@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
32274 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
32275 vcc->dev->number);
32276 length = 0;
32277- atomic_inc(&vcc->stats->rx_err);
32278+ atomic_inc_unchecked(&vcc->stats->rx_err);
32279 }
32280 else {
32281 length = ATM_CELL_SIZE-1; /* no HEC */
32282@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32283 size);
32284 }
32285 eff = length = 0;
32286- atomic_inc(&vcc->stats->rx_err);
32287+ atomic_inc_unchecked(&vcc->stats->rx_err);
32288 }
32289 else {
32290 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32291@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32292 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32293 vcc->dev->number,vcc->vci,length,size << 2,descr);
32294 length = eff = 0;
32295- atomic_inc(&vcc->stats->rx_err);
32296+ atomic_inc_unchecked(&vcc->stats->rx_err);
32297 }
32298 }
32299 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32300@@ -767,7 +767,7 @@ rx_dequeued++;
32301 vcc->push(vcc,skb);
32302 pushed++;
32303 }
32304- atomic_inc(&vcc->stats->rx);
32305+ atomic_inc_unchecked(&vcc->stats->rx);
32306 }
32307 wake_up(&eni_dev->rx_wait);
32308 }
32309@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32310 PCI_DMA_TODEVICE);
32311 if (vcc->pop) vcc->pop(vcc,skb);
32312 else dev_kfree_skb_irq(skb);
32313- atomic_inc(&vcc->stats->tx);
32314+ atomic_inc_unchecked(&vcc->stats->tx);
32315 wake_up(&eni_dev->tx_wait);
32316 dma_complete++;
32317 }
32318diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32319index b41c948..a002b17 100644
32320--- a/drivers/atm/firestream.c
32321+++ b/drivers/atm/firestream.c
32322@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32323 }
32324 }
32325
32326- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32327+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32328
32329 fs_dprintk (FS_DEBUG_TXMEM, "i");
32330 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32331@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32332 #endif
32333 skb_put (skb, qe->p1 & 0xffff);
32334 ATM_SKB(skb)->vcc = atm_vcc;
32335- atomic_inc(&atm_vcc->stats->rx);
32336+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32337 __net_timestamp(skb);
32338 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32339 atm_vcc->push (atm_vcc, skb);
32340@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32341 kfree (pe);
32342 }
32343 if (atm_vcc)
32344- atomic_inc(&atm_vcc->stats->rx_drop);
32345+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32346 break;
32347 case 0x1f: /* Reassembly abort: no buffers. */
32348 /* Silently increment error counter. */
32349 if (atm_vcc)
32350- atomic_inc(&atm_vcc->stats->rx_drop);
32351+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32352 break;
32353 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32354 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32355diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32356index 204814e..cede831 100644
32357--- a/drivers/atm/fore200e.c
32358+++ b/drivers/atm/fore200e.c
32359@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32360 #endif
32361 /* check error condition */
32362 if (*entry->status & STATUS_ERROR)
32363- atomic_inc(&vcc->stats->tx_err);
32364+ atomic_inc_unchecked(&vcc->stats->tx_err);
32365 else
32366- atomic_inc(&vcc->stats->tx);
32367+ atomic_inc_unchecked(&vcc->stats->tx);
32368 }
32369 }
32370
32371@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32372 if (skb == NULL) {
32373 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32374
32375- atomic_inc(&vcc->stats->rx_drop);
32376+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32377 return -ENOMEM;
32378 }
32379
32380@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32381
32382 dev_kfree_skb_any(skb);
32383
32384- atomic_inc(&vcc->stats->rx_drop);
32385+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32386 return -ENOMEM;
32387 }
32388
32389 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32390
32391 vcc->push(vcc, skb);
32392- atomic_inc(&vcc->stats->rx);
32393+ atomic_inc_unchecked(&vcc->stats->rx);
32394
32395 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32396
32397@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32398 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32399 fore200e->atm_dev->number,
32400 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32401- atomic_inc(&vcc->stats->rx_err);
32402+ atomic_inc_unchecked(&vcc->stats->rx_err);
32403 }
32404 }
32405
32406@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32407 goto retry_here;
32408 }
32409
32410- atomic_inc(&vcc->stats->tx_err);
32411+ atomic_inc_unchecked(&vcc->stats->tx_err);
32412
32413 fore200e->tx_sat++;
32414 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32415diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32416index d689126..e78e412 100644
32417--- a/drivers/atm/he.c
32418+++ b/drivers/atm/he.c
32419@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32420
32421 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32422 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32423- atomic_inc(&vcc->stats->rx_drop);
32424+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32425 goto return_host_buffers;
32426 }
32427
32428@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32429 RBRQ_LEN_ERR(he_dev->rbrq_head)
32430 ? "LEN_ERR" : "",
32431 vcc->vpi, vcc->vci);
32432- atomic_inc(&vcc->stats->rx_err);
32433+ atomic_inc_unchecked(&vcc->stats->rx_err);
32434 goto return_host_buffers;
32435 }
32436
32437@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32438 vcc->push(vcc, skb);
32439 spin_lock(&he_dev->global_lock);
32440
32441- atomic_inc(&vcc->stats->rx);
32442+ atomic_inc_unchecked(&vcc->stats->rx);
32443
32444 return_host_buffers:
32445 ++pdus_assembled;
32446@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32447 tpd->vcc->pop(tpd->vcc, tpd->skb);
32448 else
32449 dev_kfree_skb_any(tpd->skb);
32450- atomic_inc(&tpd->vcc->stats->tx_err);
32451+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32452 }
32453 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32454 return;
32455@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32456 vcc->pop(vcc, skb);
32457 else
32458 dev_kfree_skb_any(skb);
32459- atomic_inc(&vcc->stats->tx_err);
32460+ atomic_inc_unchecked(&vcc->stats->tx_err);
32461 return -EINVAL;
32462 }
32463
32464@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32465 vcc->pop(vcc, skb);
32466 else
32467 dev_kfree_skb_any(skb);
32468- atomic_inc(&vcc->stats->tx_err);
32469+ atomic_inc_unchecked(&vcc->stats->tx_err);
32470 return -EINVAL;
32471 }
32472 #endif
32473@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32474 vcc->pop(vcc, skb);
32475 else
32476 dev_kfree_skb_any(skb);
32477- atomic_inc(&vcc->stats->tx_err);
32478+ atomic_inc_unchecked(&vcc->stats->tx_err);
32479 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32480 return -ENOMEM;
32481 }
32482@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32483 vcc->pop(vcc, skb);
32484 else
32485 dev_kfree_skb_any(skb);
32486- atomic_inc(&vcc->stats->tx_err);
32487+ atomic_inc_unchecked(&vcc->stats->tx_err);
32488 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32489 return -ENOMEM;
32490 }
32491@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32492 __enqueue_tpd(he_dev, tpd, cid);
32493 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32494
32495- atomic_inc(&vcc->stats->tx);
32496+ atomic_inc_unchecked(&vcc->stats->tx);
32497
32498 return 0;
32499 }
32500diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32501index 1dc0519..1aadaf7 100644
32502--- a/drivers/atm/horizon.c
32503+++ b/drivers/atm/horizon.c
32504@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32505 {
32506 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32507 // VC layer stats
32508- atomic_inc(&vcc->stats->rx);
32509+ atomic_inc_unchecked(&vcc->stats->rx);
32510 __net_timestamp(skb);
32511 // end of our responsibility
32512 vcc->push (vcc, skb);
32513@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32514 dev->tx_iovec = NULL;
32515
32516 // VC layer stats
32517- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32518+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32519
32520 // free the skb
32521 hrz_kfree_skb (skb);
32522diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32523index 272f009..a18ba55 100644
32524--- a/drivers/atm/idt77252.c
32525+++ b/drivers/atm/idt77252.c
32526@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32527 else
32528 dev_kfree_skb(skb);
32529
32530- atomic_inc(&vcc->stats->tx);
32531+ atomic_inc_unchecked(&vcc->stats->tx);
32532 }
32533
32534 atomic_dec(&scq->used);
32535@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32536 if ((sb = dev_alloc_skb(64)) == NULL) {
32537 printk("%s: Can't allocate buffers for aal0.\n",
32538 card->name);
32539- atomic_add(i, &vcc->stats->rx_drop);
32540+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32541 break;
32542 }
32543 if (!atm_charge(vcc, sb->truesize)) {
32544 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32545 card->name);
32546- atomic_add(i - 1, &vcc->stats->rx_drop);
32547+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32548 dev_kfree_skb(sb);
32549 break;
32550 }
32551@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32552 ATM_SKB(sb)->vcc = vcc;
32553 __net_timestamp(sb);
32554 vcc->push(vcc, sb);
32555- atomic_inc(&vcc->stats->rx);
32556+ atomic_inc_unchecked(&vcc->stats->rx);
32557
32558 cell += ATM_CELL_PAYLOAD;
32559 }
32560@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32561 "(CDC: %08x)\n",
32562 card->name, len, rpp->len, readl(SAR_REG_CDC));
32563 recycle_rx_pool_skb(card, rpp);
32564- atomic_inc(&vcc->stats->rx_err);
32565+ atomic_inc_unchecked(&vcc->stats->rx_err);
32566 return;
32567 }
32568 if (stat & SAR_RSQE_CRC) {
32569 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32570 recycle_rx_pool_skb(card, rpp);
32571- atomic_inc(&vcc->stats->rx_err);
32572+ atomic_inc_unchecked(&vcc->stats->rx_err);
32573 return;
32574 }
32575 if (skb_queue_len(&rpp->queue) > 1) {
32576@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32577 RXPRINTK("%s: Can't alloc RX skb.\n",
32578 card->name);
32579 recycle_rx_pool_skb(card, rpp);
32580- atomic_inc(&vcc->stats->rx_err);
32581+ atomic_inc_unchecked(&vcc->stats->rx_err);
32582 return;
32583 }
32584 if (!atm_charge(vcc, skb->truesize)) {
32585@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32586 __net_timestamp(skb);
32587
32588 vcc->push(vcc, skb);
32589- atomic_inc(&vcc->stats->rx);
32590+ atomic_inc_unchecked(&vcc->stats->rx);
32591
32592 return;
32593 }
32594@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32595 __net_timestamp(skb);
32596
32597 vcc->push(vcc, skb);
32598- atomic_inc(&vcc->stats->rx);
32599+ atomic_inc_unchecked(&vcc->stats->rx);
32600
32601 if (skb->truesize > SAR_FB_SIZE_3)
32602 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32603@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32604 if (vcc->qos.aal != ATM_AAL0) {
32605 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32606 card->name, vpi, vci);
32607- atomic_inc(&vcc->stats->rx_drop);
32608+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32609 goto drop;
32610 }
32611
32612 if ((sb = dev_alloc_skb(64)) == NULL) {
32613 printk("%s: Can't allocate buffers for AAL0.\n",
32614 card->name);
32615- atomic_inc(&vcc->stats->rx_err);
32616+ atomic_inc_unchecked(&vcc->stats->rx_err);
32617 goto drop;
32618 }
32619
32620@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32621 ATM_SKB(sb)->vcc = vcc;
32622 __net_timestamp(sb);
32623 vcc->push(vcc, sb);
32624- atomic_inc(&vcc->stats->rx);
32625+ atomic_inc_unchecked(&vcc->stats->rx);
32626
32627 drop:
32628 skb_pull(queue, 64);
32629@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32630
32631 if (vc == NULL) {
32632 printk("%s: NULL connection in send().\n", card->name);
32633- atomic_inc(&vcc->stats->tx_err);
32634+ atomic_inc_unchecked(&vcc->stats->tx_err);
32635 dev_kfree_skb(skb);
32636 return -EINVAL;
32637 }
32638 if (!test_bit(VCF_TX, &vc->flags)) {
32639 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32640- atomic_inc(&vcc->stats->tx_err);
32641+ atomic_inc_unchecked(&vcc->stats->tx_err);
32642 dev_kfree_skb(skb);
32643 return -EINVAL;
32644 }
32645@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32646 break;
32647 default:
32648 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32649- atomic_inc(&vcc->stats->tx_err);
32650+ atomic_inc_unchecked(&vcc->stats->tx_err);
32651 dev_kfree_skb(skb);
32652 return -EINVAL;
32653 }
32654
32655 if (skb_shinfo(skb)->nr_frags != 0) {
32656 printk("%s: No scatter-gather yet.\n", card->name);
32657- atomic_inc(&vcc->stats->tx_err);
32658+ atomic_inc_unchecked(&vcc->stats->tx_err);
32659 dev_kfree_skb(skb);
32660 return -EINVAL;
32661 }
32662@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32663
32664 err = queue_skb(card, vc, skb, oam);
32665 if (err) {
32666- atomic_inc(&vcc->stats->tx_err);
32667+ atomic_inc_unchecked(&vcc->stats->tx_err);
32668 dev_kfree_skb(skb);
32669 return err;
32670 }
32671@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32672 skb = dev_alloc_skb(64);
32673 if (!skb) {
32674 printk("%s: Out of memory in send_oam().\n", card->name);
32675- atomic_inc(&vcc->stats->tx_err);
32676+ atomic_inc_unchecked(&vcc->stats->tx_err);
32677 return -ENOMEM;
32678 }
32679 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32680diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32681index 4217f29..88f547a 100644
32682--- a/drivers/atm/iphase.c
32683+++ b/drivers/atm/iphase.c
32684@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32685 status = (u_short) (buf_desc_ptr->desc_mode);
32686 if (status & (RX_CER | RX_PTE | RX_OFL))
32687 {
32688- atomic_inc(&vcc->stats->rx_err);
32689+ atomic_inc_unchecked(&vcc->stats->rx_err);
32690 IF_ERR(printk("IA: bad packet, dropping it");)
32691 if (status & RX_CER) {
32692 IF_ERR(printk(" cause: packet CRC error\n");)
32693@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32694 len = dma_addr - buf_addr;
32695 if (len > iadev->rx_buf_sz) {
32696 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32697- atomic_inc(&vcc->stats->rx_err);
32698+ atomic_inc_unchecked(&vcc->stats->rx_err);
32699 goto out_free_desc;
32700 }
32701
32702@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32703 ia_vcc = INPH_IA_VCC(vcc);
32704 if (ia_vcc == NULL)
32705 {
32706- atomic_inc(&vcc->stats->rx_err);
32707+ atomic_inc_unchecked(&vcc->stats->rx_err);
32708 atm_return(vcc, skb->truesize);
32709 dev_kfree_skb_any(skb);
32710 goto INCR_DLE;
32711@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32712 if ((length > iadev->rx_buf_sz) || (length >
32713 (skb->len - sizeof(struct cpcs_trailer))))
32714 {
32715- atomic_inc(&vcc->stats->rx_err);
32716+ atomic_inc_unchecked(&vcc->stats->rx_err);
32717 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32718 length, skb->len);)
32719 atm_return(vcc, skb->truesize);
32720@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32721
32722 IF_RX(printk("rx_dle_intr: skb push");)
32723 vcc->push(vcc,skb);
32724- atomic_inc(&vcc->stats->rx);
32725+ atomic_inc_unchecked(&vcc->stats->rx);
32726 iadev->rx_pkt_cnt++;
32727 }
32728 INCR_DLE:
32729@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32730 {
32731 struct k_sonet_stats *stats;
32732 stats = &PRIV(_ia_dev[board])->sonet_stats;
32733- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32734- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32735- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32736- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32737- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32738- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32739- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32740- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32741- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32742+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32743+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32744+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32745+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32746+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32747+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32748+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32749+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32750+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32751 }
32752 ia_cmds.status = 0;
32753 break;
32754@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32755 if ((desc == 0) || (desc > iadev->num_tx_desc))
32756 {
32757 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32758- atomic_inc(&vcc->stats->tx);
32759+ atomic_inc_unchecked(&vcc->stats->tx);
32760 if (vcc->pop)
32761 vcc->pop(vcc, skb);
32762 else
32763@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32764 ATM_DESC(skb) = vcc->vci;
32765 skb_queue_tail(&iadev->tx_dma_q, skb);
32766
32767- atomic_inc(&vcc->stats->tx);
32768+ atomic_inc_unchecked(&vcc->stats->tx);
32769 iadev->tx_pkt_cnt++;
32770 /* Increment transaction counter */
32771 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32772
32773 #if 0
32774 /* add flow control logic */
32775- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32776+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32777 if (iavcc->vc_desc_cnt > 10) {
32778 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32779 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32780diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32781index fa7d701..1e404c7 100644
32782--- a/drivers/atm/lanai.c
32783+++ b/drivers/atm/lanai.c
32784@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32785 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32786 lanai_endtx(lanai, lvcc);
32787 lanai_free_skb(lvcc->tx.atmvcc, skb);
32788- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32789+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32790 }
32791
32792 /* Try to fill the buffer - don't call unless there is backlog */
32793@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32794 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32795 __net_timestamp(skb);
32796 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32797- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32798+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32799 out:
32800 lvcc->rx.buf.ptr = end;
32801 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32802@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32803 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32804 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32805 lanai->stats.service_rxnotaal5++;
32806- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32807+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32808 return 0;
32809 }
32810 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32811@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32812 int bytes;
32813 read_unlock(&vcc_sklist_lock);
32814 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32815- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32816+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32817 lvcc->stats.x.aal5.service_trash++;
32818 bytes = (SERVICE_GET_END(s) * 16) -
32819 (((unsigned long) lvcc->rx.buf.ptr) -
32820@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32821 }
32822 if (s & SERVICE_STREAM) {
32823 read_unlock(&vcc_sklist_lock);
32824- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32825+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32826 lvcc->stats.x.aal5.service_stream++;
32827 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32828 "PDU on VCI %d!\n", lanai->number, vci);
32829@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32830 return 0;
32831 }
32832 DPRINTK("got rx crc error on vci %d\n", vci);
32833- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32834+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32835 lvcc->stats.x.aal5.service_rxcrc++;
32836 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32837 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32838diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32839index 6587dc2..149833d 100644
32840--- a/drivers/atm/nicstar.c
32841+++ b/drivers/atm/nicstar.c
32842@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32843 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32844 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32845 card->index);
32846- atomic_inc(&vcc->stats->tx_err);
32847+ atomic_inc_unchecked(&vcc->stats->tx_err);
32848 dev_kfree_skb_any(skb);
32849 return -EINVAL;
32850 }
32851@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32852 if (!vc->tx) {
32853 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32854 card->index);
32855- atomic_inc(&vcc->stats->tx_err);
32856+ atomic_inc_unchecked(&vcc->stats->tx_err);
32857 dev_kfree_skb_any(skb);
32858 return -EINVAL;
32859 }
32860@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32861 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32862 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32863 card->index);
32864- atomic_inc(&vcc->stats->tx_err);
32865+ atomic_inc_unchecked(&vcc->stats->tx_err);
32866 dev_kfree_skb_any(skb);
32867 return -EINVAL;
32868 }
32869
32870 if (skb_shinfo(skb)->nr_frags != 0) {
32871 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32872- atomic_inc(&vcc->stats->tx_err);
32873+ atomic_inc_unchecked(&vcc->stats->tx_err);
32874 dev_kfree_skb_any(skb);
32875 return -EINVAL;
32876 }
32877@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32878 }
32879
32880 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32881- atomic_inc(&vcc->stats->tx_err);
32882+ atomic_inc_unchecked(&vcc->stats->tx_err);
32883 dev_kfree_skb_any(skb);
32884 return -EIO;
32885 }
32886- atomic_inc(&vcc->stats->tx);
32887+ atomic_inc_unchecked(&vcc->stats->tx);
32888
32889 return 0;
32890 }
32891@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32892 printk
32893 ("nicstar%d: Can't allocate buffers for aal0.\n",
32894 card->index);
32895- atomic_add(i, &vcc->stats->rx_drop);
32896+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32897 break;
32898 }
32899 if (!atm_charge(vcc, sb->truesize)) {
32900 RXPRINTK
32901 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32902 card->index);
32903- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32904+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32905 dev_kfree_skb_any(sb);
32906 break;
32907 }
32908@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32909 ATM_SKB(sb)->vcc = vcc;
32910 __net_timestamp(sb);
32911 vcc->push(vcc, sb);
32912- atomic_inc(&vcc->stats->rx);
32913+ atomic_inc_unchecked(&vcc->stats->rx);
32914 cell += ATM_CELL_PAYLOAD;
32915 }
32916
32917@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32918 if (iovb == NULL) {
32919 printk("nicstar%d: Out of iovec buffers.\n",
32920 card->index);
32921- atomic_inc(&vcc->stats->rx_drop);
32922+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32923 recycle_rx_buf(card, skb);
32924 return;
32925 }
32926@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32927 small or large buffer itself. */
32928 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32929 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32930- atomic_inc(&vcc->stats->rx_err);
32931+ atomic_inc_unchecked(&vcc->stats->rx_err);
32932 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32933 NS_MAX_IOVECS);
32934 NS_PRV_IOVCNT(iovb) = 0;
32935@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32936 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32937 card->index);
32938 which_list(card, skb);
32939- atomic_inc(&vcc->stats->rx_err);
32940+ atomic_inc_unchecked(&vcc->stats->rx_err);
32941 recycle_rx_buf(card, skb);
32942 vc->rx_iov = NULL;
32943 recycle_iov_buf(card, iovb);
32944@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32945 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32946 card->index);
32947 which_list(card, skb);
32948- atomic_inc(&vcc->stats->rx_err);
32949+ atomic_inc_unchecked(&vcc->stats->rx_err);
32950 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32951 NS_PRV_IOVCNT(iovb));
32952 vc->rx_iov = NULL;
32953@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32954 printk(" - PDU size mismatch.\n");
32955 else
32956 printk(".\n");
32957- atomic_inc(&vcc->stats->rx_err);
32958+ atomic_inc_unchecked(&vcc->stats->rx_err);
32959 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32960 NS_PRV_IOVCNT(iovb));
32961 vc->rx_iov = NULL;
32962@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32963 /* skb points to a small buffer */
32964 if (!atm_charge(vcc, skb->truesize)) {
32965 push_rxbufs(card, skb);
32966- atomic_inc(&vcc->stats->rx_drop);
32967+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32968 } else {
32969 skb_put(skb, len);
32970 dequeue_sm_buf(card, skb);
32971@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32972 ATM_SKB(skb)->vcc = vcc;
32973 __net_timestamp(skb);
32974 vcc->push(vcc, skb);
32975- atomic_inc(&vcc->stats->rx);
32976+ atomic_inc_unchecked(&vcc->stats->rx);
32977 }
32978 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32979 struct sk_buff *sb;
32980@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32981 if (len <= NS_SMBUFSIZE) {
32982 if (!atm_charge(vcc, sb->truesize)) {
32983 push_rxbufs(card, sb);
32984- atomic_inc(&vcc->stats->rx_drop);
32985+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32986 } else {
32987 skb_put(sb, len);
32988 dequeue_sm_buf(card, sb);
32989@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32990 ATM_SKB(sb)->vcc = vcc;
32991 __net_timestamp(sb);
32992 vcc->push(vcc, sb);
32993- atomic_inc(&vcc->stats->rx);
32994+ atomic_inc_unchecked(&vcc->stats->rx);
32995 }
32996
32997 push_rxbufs(card, skb);
32998@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32999
33000 if (!atm_charge(vcc, skb->truesize)) {
33001 push_rxbufs(card, skb);
33002- atomic_inc(&vcc->stats->rx_drop);
33003+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33004 } else {
33005 dequeue_lg_buf(card, skb);
33006 #ifdef NS_USE_DESTRUCTORS
33007@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33008 ATM_SKB(skb)->vcc = vcc;
33009 __net_timestamp(skb);
33010 vcc->push(vcc, skb);
33011- atomic_inc(&vcc->stats->rx);
33012+ atomic_inc_unchecked(&vcc->stats->rx);
33013 }
33014
33015 push_rxbufs(card, sb);
33016@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33017 printk
33018 ("nicstar%d: Out of huge buffers.\n",
33019 card->index);
33020- atomic_inc(&vcc->stats->rx_drop);
33021+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33022 recycle_iovec_rx_bufs(card,
33023 (struct iovec *)
33024 iovb->data,
33025@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33026 card->hbpool.count++;
33027 } else
33028 dev_kfree_skb_any(hb);
33029- atomic_inc(&vcc->stats->rx_drop);
33030+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33031 } else {
33032 /* Copy the small buffer to the huge buffer */
33033 sb = (struct sk_buff *)iov->iov_base;
33034@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33035 #endif /* NS_USE_DESTRUCTORS */
33036 __net_timestamp(hb);
33037 vcc->push(vcc, hb);
33038- atomic_inc(&vcc->stats->rx);
33039+ atomic_inc_unchecked(&vcc->stats->rx);
33040 }
33041 }
33042
33043diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
33044index 32784d1..4a8434a 100644
33045--- a/drivers/atm/solos-pci.c
33046+++ b/drivers/atm/solos-pci.c
33047@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
33048 }
33049 atm_charge(vcc, skb->truesize);
33050 vcc->push(vcc, skb);
33051- atomic_inc(&vcc->stats->rx);
33052+ atomic_inc_unchecked(&vcc->stats->rx);
33053 break;
33054
33055 case PKT_STATUS:
33056@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
33057 vcc = SKB_CB(oldskb)->vcc;
33058
33059 if (vcc) {
33060- atomic_inc(&vcc->stats->tx);
33061+ atomic_inc_unchecked(&vcc->stats->tx);
33062 solos_pop(vcc, oldskb);
33063 } else {
33064 dev_kfree_skb_irq(oldskb);
33065diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
33066index 0215934..ce9f5b1 100644
33067--- a/drivers/atm/suni.c
33068+++ b/drivers/atm/suni.c
33069@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
33070
33071
33072 #define ADD_LIMITED(s,v) \
33073- atomic_add((v),&stats->s); \
33074- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
33075+ atomic_add_unchecked((v),&stats->s); \
33076+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
33077
33078
33079 static void suni_hz(unsigned long from_timer)
33080diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
33081index 5120a96..e2572bd 100644
33082--- a/drivers/atm/uPD98402.c
33083+++ b/drivers/atm/uPD98402.c
33084@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
33085 struct sonet_stats tmp;
33086 int error = 0;
33087
33088- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33089+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33090 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
33091 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
33092 if (zero && !error) {
33093@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
33094
33095
33096 #define ADD_LIMITED(s,v) \
33097- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
33098- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
33099- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33100+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
33101+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
33102+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33103
33104
33105 static void stat_event(struct atm_dev *dev)
33106@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
33107 if (reason & uPD98402_INT_PFM) stat_event(dev);
33108 if (reason & uPD98402_INT_PCO) {
33109 (void) GET(PCOCR); /* clear interrupt cause */
33110- atomic_add(GET(HECCT),
33111+ atomic_add_unchecked(GET(HECCT),
33112 &PRIV(dev)->sonet_stats.uncorr_hcs);
33113 }
33114 if ((reason & uPD98402_INT_RFO) &&
33115@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
33116 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
33117 uPD98402_INT_LOS),PIMR); /* enable them */
33118 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
33119- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33120- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
33121- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
33122+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33123+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
33124+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
33125 return 0;
33126 }
33127
33128diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
33129index 969c3c2..9b72956 100644
33130--- a/drivers/atm/zatm.c
33131+++ b/drivers/atm/zatm.c
33132@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33133 }
33134 if (!size) {
33135 dev_kfree_skb_irq(skb);
33136- if (vcc) atomic_inc(&vcc->stats->rx_err);
33137+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
33138 continue;
33139 }
33140 if (!atm_charge(vcc,skb->truesize)) {
33141@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33142 skb->len = size;
33143 ATM_SKB(skb)->vcc = vcc;
33144 vcc->push(vcc,skb);
33145- atomic_inc(&vcc->stats->rx);
33146+ atomic_inc_unchecked(&vcc->stats->rx);
33147 }
33148 zout(pos & 0xffff,MTA(mbx));
33149 #if 0 /* probably a stupid idea */
33150@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
33151 skb_queue_head(&zatm_vcc->backlog,skb);
33152 break;
33153 }
33154- atomic_inc(&vcc->stats->tx);
33155+ atomic_inc_unchecked(&vcc->stats->tx);
33156 wake_up(&zatm_vcc->tx_wait);
33157 }
33158
33159diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
33160index d78b204..ecc1929 100644
33161--- a/drivers/base/attribute_container.c
33162+++ b/drivers/base/attribute_container.c
33163@@ -167,7 +167,7 @@ attribute_container_add_device(struct device *dev,
33164 ic->classdev.parent = get_device(dev);
33165 ic->classdev.class = cont->class;
33166 cont->class->dev_release = attribute_container_release;
33167- dev_set_name(&ic->classdev, dev_name(dev));
33168+ dev_set_name(&ic->classdev, "%s", dev_name(dev));
33169 if (fn)
33170 fn(cont, dev, &ic->classdev);
33171 else
33172diff --git a/drivers/base/bus.c b/drivers/base/bus.c
33173index 519865b..e540db3 100644
33174--- a/drivers/base/bus.c
33175+++ b/drivers/base/bus.c
33176@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
33177 return -EINVAL;
33178
33179 mutex_lock(&subsys->p->mutex);
33180- list_add_tail(&sif->node, &subsys->p->interfaces);
33181+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
33182 if (sif->add_dev) {
33183 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33184 while ((dev = subsys_dev_iter_next(&iter)))
33185@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
33186 subsys = sif->subsys;
33187
33188 mutex_lock(&subsys->p->mutex);
33189- list_del_init(&sif->node);
33190+ pax_list_del_init((struct list_head *)&sif->node);
33191 if (sif->remove_dev) {
33192 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33193 while ((dev = subsys_dev_iter_next(&iter)))
33194diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
33195index 01fc5b0..917801f 100644
33196--- a/drivers/base/devtmpfs.c
33197+++ b/drivers/base/devtmpfs.c
33198@@ -348,7 +348,7 @@ int devtmpfs_mount(const char *mntdir)
33199 if (!thread)
33200 return 0;
33201
33202- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
33203+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
33204 if (err)
33205 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
33206 else
33207@@ -373,11 +373,11 @@ static int devtmpfsd(void *p)
33208 *err = sys_unshare(CLONE_NEWNS);
33209 if (*err)
33210 goto out;
33211- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
33212+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
33213 if (*err)
33214 goto out;
33215- sys_chdir("/.."); /* will traverse into overmounted root */
33216- sys_chroot(".");
33217+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
33218+ sys_chroot((char __force_user *)".");
33219 complete(&setup_done);
33220 while (1) {
33221 spin_lock(&req_lock);
33222diff --git a/drivers/base/node.c b/drivers/base/node.c
33223index fac124a..66bd4ab 100644
33224--- a/drivers/base/node.c
33225+++ b/drivers/base/node.c
33226@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
33227 struct node_attr {
33228 struct device_attribute attr;
33229 enum node_states state;
33230-};
33231+} __do_const;
33232
33233 static ssize_t show_node_state(struct device *dev,
33234 struct device_attribute *attr, char *buf)
33235diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
33236index 9a6b05a..2fc8fb9 100644
33237--- a/drivers/base/power/domain.c
33238+++ b/drivers/base/power/domain.c
33239@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
33240 {
33241 struct cpuidle_driver *cpuidle_drv;
33242 struct gpd_cpu_data *cpu_data;
33243- struct cpuidle_state *idle_state;
33244+ cpuidle_state_no_const *idle_state;
33245 int ret = 0;
33246
33247 if (IS_ERR_OR_NULL(genpd) || state < 0)
33248@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
33249 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
33250 {
33251 struct gpd_cpu_data *cpu_data;
33252- struct cpuidle_state *idle_state;
33253+ cpuidle_state_no_const *idle_state;
33254 int ret = 0;
33255
33256 if (IS_ERR_OR_NULL(genpd))
33257diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
33258index a53ebd2..8f73eeb 100644
33259--- a/drivers/base/power/sysfs.c
33260+++ b/drivers/base/power/sysfs.c
33261@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
33262 return -EIO;
33263 }
33264 }
33265- return sprintf(buf, p);
33266+ return sprintf(buf, "%s", p);
33267 }
33268
33269 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
33270diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
33271index 79715e7..df06b3b 100644
33272--- a/drivers/base/power/wakeup.c
33273+++ b/drivers/base/power/wakeup.c
33274@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
33275 * They need to be modified together atomically, so it's better to use one
33276 * atomic variable to hold them both.
33277 */
33278-static atomic_t combined_event_count = ATOMIC_INIT(0);
33279+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
33280
33281 #define IN_PROGRESS_BITS (sizeof(int) * 4)
33282 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
33283
33284 static void split_counters(unsigned int *cnt, unsigned int *inpr)
33285 {
33286- unsigned int comb = atomic_read(&combined_event_count);
33287+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
33288
33289 *cnt = (comb >> IN_PROGRESS_BITS);
33290 *inpr = comb & MAX_IN_PROGRESS;
33291@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33292 ws->start_prevent_time = ws->last_time;
33293
33294 /* Increment the counter of events in progress. */
33295- cec = atomic_inc_return(&combined_event_count);
33296+ cec = atomic_inc_return_unchecked(&combined_event_count);
33297
33298 trace_wakeup_source_activate(ws->name, cec);
33299 }
33300@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33301 * Increment the counter of registered wakeup events and decrement the
33302 * couter of wakeup events in progress simultaneously.
33303 */
33304- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33305+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33306 trace_wakeup_source_deactivate(ws->name, cec);
33307
33308 split_counters(&cnt, &inpr);
33309diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
33310index e8d11b6..7b1b36f 100644
33311--- a/drivers/base/syscore.c
33312+++ b/drivers/base/syscore.c
33313@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
33314 void register_syscore_ops(struct syscore_ops *ops)
33315 {
33316 mutex_lock(&syscore_ops_lock);
33317- list_add_tail(&ops->node, &syscore_ops_list);
33318+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33319 mutex_unlock(&syscore_ops_lock);
33320 }
33321 EXPORT_SYMBOL_GPL(register_syscore_ops);
33322@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33323 void unregister_syscore_ops(struct syscore_ops *ops)
33324 {
33325 mutex_lock(&syscore_ops_lock);
33326- list_del(&ops->node);
33327+ pax_list_del((struct list_head *)&ops->node);
33328 mutex_unlock(&syscore_ops_lock);
33329 }
33330 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33331diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33332index dadea48..a1f3835 100644
33333--- a/drivers/block/cciss.c
33334+++ b/drivers/block/cciss.c
33335@@ -1184,6 +1184,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33336 int err;
33337 u32 cp;
33338
33339+ memset(&arg64, 0, sizeof(arg64));
33340+
33341 err = 0;
33342 err |=
33343 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33344@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
33345 while (!list_empty(&h->reqQ)) {
33346 c = list_entry(h->reqQ.next, CommandList_struct, list);
33347 /* can't do anything if fifo is full */
33348- if ((h->access.fifo_full(h))) {
33349+ if ((h->access->fifo_full(h))) {
33350 dev_warn(&h->pdev->dev, "fifo full\n");
33351 break;
33352 }
33353@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
33354 h->Qdepth--;
33355
33356 /* Tell the controller execute command */
33357- h->access.submit_command(h, c);
33358+ h->access->submit_command(h, c);
33359
33360 /* Put job onto the completed Q */
33361 addQ(&h->cmpQ, c);
33362@@ -3441,17 +3443,17 @@ startio:
33363
33364 static inline unsigned long get_next_completion(ctlr_info_t *h)
33365 {
33366- return h->access.command_completed(h);
33367+ return h->access->command_completed(h);
33368 }
33369
33370 static inline int interrupt_pending(ctlr_info_t *h)
33371 {
33372- return h->access.intr_pending(h);
33373+ return h->access->intr_pending(h);
33374 }
33375
33376 static inline long interrupt_not_for_us(ctlr_info_t *h)
33377 {
33378- return ((h->access.intr_pending(h) == 0) ||
33379+ return ((h->access->intr_pending(h) == 0) ||
33380 (h->interrupts_enabled == 0));
33381 }
33382
33383@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
33384 u32 a;
33385
33386 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33387- return h->access.command_completed(h);
33388+ return h->access->command_completed(h);
33389
33390 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33391 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33392@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33393 trans_support & CFGTBL_Trans_use_short_tags);
33394
33395 /* Change the access methods to the performant access methods */
33396- h->access = SA5_performant_access;
33397+ h->access = &SA5_performant_access;
33398 h->transMethod = CFGTBL_Trans_Performant;
33399
33400 return;
33401@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33402 if (prod_index < 0)
33403 return -ENODEV;
33404 h->product_name = products[prod_index].product_name;
33405- h->access = *(products[prod_index].access);
33406+ h->access = products[prod_index].access;
33407
33408 if (cciss_board_disabled(h)) {
33409 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33410@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
33411 }
33412
33413 /* make sure the board interrupts are off */
33414- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33415+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33416 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33417 if (rc)
33418 goto clean2;
33419@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
33420 * fake ones to scoop up any residual completions.
33421 */
33422 spin_lock_irqsave(&h->lock, flags);
33423- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33424+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33425 spin_unlock_irqrestore(&h->lock, flags);
33426 free_irq(h->intr[h->intr_mode], h);
33427 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33428@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
33429 dev_info(&h->pdev->dev, "Board READY.\n");
33430 dev_info(&h->pdev->dev,
33431 "Waiting for stale completions to drain.\n");
33432- h->access.set_intr_mask(h, CCISS_INTR_ON);
33433+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33434 msleep(10000);
33435- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33436+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33437
33438 rc = controller_reset_failed(h->cfgtable);
33439 if (rc)
33440@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
33441 cciss_scsi_setup(h);
33442
33443 /* Turn the interrupts on so we can service requests */
33444- h->access.set_intr_mask(h, CCISS_INTR_ON);
33445+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33446
33447 /* Get the firmware version */
33448 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33449@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33450 kfree(flush_buf);
33451 if (return_code != IO_OK)
33452 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33453- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33454+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33455 free_irq(h->intr[h->intr_mode], h);
33456 }
33457
33458diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33459index 7fda30e..eb5dfe0 100644
33460--- a/drivers/block/cciss.h
33461+++ b/drivers/block/cciss.h
33462@@ -101,7 +101,7 @@ struct ctlr_info
33463 /* information about each logical volume */
33464 drive_info_struct *drv[CISS_MAX_LUN];
33465
33466- struct access_method access;
33467+ struct access_method *access;
33468
33469 /* queue and queue Info */
33470 struct list_head reqQ;
33471diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33472index 3f08713..87d4b4a 100644
33473--- a/drivers/block/cpqarray.c
33474+++ b/drivers/block/cpqarray.c
33475@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33476 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33477 goto Enomem4;
33478 }
33479- hba[i]->access.set_intr_mask(hba[i], 0);
33480+ hba[i]->access->set_intr_mask(hba[i], 0);
33481 if (request_irq(hba[i]->intr, do_ida_intr,
33482 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33483 {
33484@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33485 add_timer(&hba[i]->timer);
33486
33487 /* Enable IRQ now that spinlock and rate limit timer are set up */
33488- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33489+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33490
33491 for(j=0; j<NWD; j++) {
33492 struct gendisk *disk = ida_gendisk[i][j];
33493@@ -694,7 +694,7 @@ DBGINFO(
33494 for(i=0; i<NR_PRODUCTS; i++) {
33495 if (board_id == products[i].board_id) {
33496 c->product_name = products[i].product_name;
33497- c->access = *(products[i].access);
33498+ c->access = products[i].access;
33499 break;
33500 }
33501 }
33502@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33503 hba[ctlr]->intr = intr;
33504 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33505 hba[ctlr]->product_name = products[j].product_name;
33506- hba[ctlr]->access = *(products[j].access);
33507+ hba[ctlr]->access = products[j].access;
33508 hba[ctlr]->ctlr = ctlr;
33509 hba[ctlr]->board_id = board_id;
33510 hba[ctlr]->pci_dev = NULL; /* not PCI */
33511@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
33512
33513 while((c = h->reqQ) != NULL) {
33514 /* Can't do anything if we're busy */
33515- if (h->access.fifo_full(h) == 0)
33516+ if (h->access->fifo_full(h) == 0)
33517 return;
33518
33519 /* Get the first entry from the request Q */
33520@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
33521 h->Qdepth--;
33522
33523 /* Tell the controller to do our bidding */
33524- h->access.submit_command(h, c);
33525+ h->access->submit_command(h, c);
33526
33527 /* Get onto the completion Q */
33528 addQ(&h->cmpQ, c);
33529@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33530 unsigned long flags;
33531 __u32 a,a1;
33532
33533- istat = h->access.intr_pending(h);
33534+ istat = h->access->intr_pending(h);
33535 /* Is this interrupt for us? */
33536 if (istat == 0)
33537 return IRQ_NONE;
33538@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33539 */
33540 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33541 if (istat & FIFO_NOT_EMPTY) {
33542- while((a = h->access.command_completed(h))) {
33543+ while((a = h->access->command_completed(h))) {
33544 a1 = a; a &= ~3;
33545 if ((c = h->cmpQ) == NULL)
33546 {
33547@@ -1195,6 +1195,7 @@ out_passthru:
33548 ida_pci_info_struct pciinfo;
33549
33550 if (!arg) return -EINVAL;
33551+ memset(&pciinfo, 0, sizeof(pciinfo));
33552 pciinfo.bus = host->pci_dev->bus->number;
33553 pciinfo.dev_fn = host->pci_dev->devfn;
33554 pciinfo.board_id = host->board_id;
33555@@ -1449,11 +1450,11 @@ static int sendcmd(
33556 /*
33557 * Disable interrupt
33558 */
33559- info_p->access.set_intr_mask(info_p, 0);
33560+ info_p->access->set_intr_mask(info_p, 0);
33561 /* Make sure there is room in the command FIFO */
33562 /* Actually it should be completely empty at this time. */
33563 for (i = 200000; i > 0; i--) {
33564- temp = info_p->access.fifo_full(info_p);
33565+ temp = info_p->access->fifo_full(info_p);
33566 if (temp != 0) {
33567 break;
33568 }
33569@@ -1466,7 +1467,7 @@ DBG(
33570 /*
33571 * Send the cmd
33572 */
33573- info_p->access.submit_command(info_p, c);
33574+ info_p->access->submit_command(info_p, c);
33575 complete = pollcomplete(ctlr);
33576
33577 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33578@@ -1549,9 +1550,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33579 * we check the new geometry. Then turn interrupts back on when
33580 * we're done.
33581 */
33582- host->access.set_intr_mask(host, 0);
33583+ host->access->set_intr_mask(host, 0);
33584 getgeometry(ctlr);
33585- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33586+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33587
33588 for(i=0; i<NWD; i++) {
33589 struct gendisk *disk = ida_gendisk[ctlr][i];
33590@@ -1591,7 +1592,7 @@ static int pollcomplete(int ctlr)
33591 /* Wait (up to 2 seconds) for a command to complete */
33592
33593 for (i = 200000; i > 0; i--) {
33594- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33595+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33596 if (done == 0) {
33597 udelay(10); /* a short fixed delay */
33598 } else
33599diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33600index be73e9d..7fbf140 100644
33601--- a/drivers/block/cpqarray.h
33602+++ b/drivers/block/cpqarray.h
33603@@ -99,7 +99,7 @@ struct ctlr_info {
33604 drv_info_t drv[NWD];
33605 struct proc_dir_entry *proc;
33606
33607- struct access_method access;
33608+ struct access_method *access;
33609
33610 cmdlist_t *reqQ;
33611 cmdlist_t *cmpQ;
33612diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33613index 6b51afa..17e1191 100644
33614--- a/drivers/block/drbd/drbd_int.h
33615+++ b/drivers/block/drbd/drbd_int.h
33616@@ -582,7 +582,7 @@ struct drbd_epoch {
33617 struct drbd_tconn *tconn;
33618 struct list_head list;
33619 unsigned int barrier_nr;
33620- atomic_t epoch_size; /* increased on every request added. */
33621+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33622 atomic_t active; /* increased on every req. added, and dec on every finished. */
33623 unsigned long flags;
33624 };
33625@@ -1011,7 +1011,7 @@ struct drbd_conf {
33626 int al_tr_cycle;
33627 int al_tr_pos; /* position of the next transaction in the journal */
33628 wait_queue_head_t seq_wait;
33629- atomic_t packet_seq;
33630+ atomic_unchecked_t packet_seq;
33631 unsigned int peer_seq;
33632 spinlock_t peer_seq_lock;
33633 unsigned int minor;
33634@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33635 char __user *uoptval;
33636 int err;
33637
33638- uoptval = (char __user __force *)optval;
33639+ uoptval = (char __force_user *)optval;
33640
33641 set_fs(KERNEL_DS);
33642 if (level == SOL_SOCKET)
33643diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33644index 54d03d4..332f311 100644
33645--- a/drivers/block/drbd/drbd_main.c
33646+++ b/drivers/block/drbd/drbd_main.c
33647@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33648 p->sector = sector;
33649 p->block_id = block_id;
33650 p->blksize = blksize;
33651- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33652+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33653 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33654 }
33655
33656@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33657 return -EIO;
33658 p->sector = cpu_to_be64(req->i.sector);
33659 p->block_id = (unsigned long)req;
33660- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33661+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33662 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33663 if (mdev->state.conn >= C_SYNC_SOURCE &&
33664 mdev->state.conn <= C_PAUSED_SYNC_T)
33665@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33666 {
33667 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33668
33669- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33670- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33671+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33672+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33673 kfree(tconn->current_epoch);
33674
33675 idr_destroy(&tconn->volumes);
33676diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33677index 2f5fffd..b22a1ae 100644
33678--- a/drivers/block/drbd/drbd_receiver.c
33679+++ b/drivers/block/drbd/drbd_receiver.c
33680@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33681 {
33682 int err;
33683
33684- atomic_set(&mdev->packet_seq, 0);
33685+ atomic_set_unchecked(&mdev->packet_seq, 0);
33686 mdev->peer_seq = 0;
33687
33688 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33689@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33690 do {
33691 next_epoch = NULL;
33692
33693- epoch_size = atomic_read(&epoch->epoch_size);
33694+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33695
33696 switch (ev & ~EV_CLEANUP) {
33697 case EV_PUT:
33698@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33699 rv = FE_DESTROYED;
33700 } else {
33701 epoch->flags = 0;
33702- atomic_set(&epoch->epoch_size, 0);
33703+ atomic_set_unchecked(&epoch->epoch_size, 0);
33704 /* atomic_set(&epoch->active, 0); is already zero */
33705 if (rv == FE_STILL_LIVE)
33706 rv = FE_RECYCLED;
33707@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33708 conn_wait_active_ee_empty(tconn);
33709 drbd_flush(tconn);
33710
33711- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33712+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33713 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33714 if (epoch)
33715 break;
33716@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33717 }
33718
33719 epoch->flags = 0;
33720- atomic_set(&epoch->epoch_size, 0);
33721+ atomic_set_unchecked(&epoch->epoch_size, 0);
33722 atomic_set(&epoch->active, 0);
33723
33724 spin_lock(&tconn->epoch_lock);
33725- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33726+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33727 list_add(&epoch->list, &tconn->current_epoch->list);
33728 tconn->current_epoch = epoch;
33729 tconn->epochs++;
33730@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33731
33732 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33733 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33734- atomic_inc(&tconn->current_epoch->epoch_size);
33735+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33736 err2 = drbd_drain_block(mdev, pi->size);
33737 if (!err)
33738 err = err2;
33739@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33740
33741 spin_lock(&tconn->epoch_lock);
33742 peer_req->epoch = tconn->current_epoch;
33743- atomic_inc(&peer_req->epoch->epoch_size);
33744+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33745 atomic_inc(&peer_req->epoch->active);
33746 spin_unlock(&tconn->epoch_lock);
33747
33748@@ -4345,7 +4345,7 @@ struct data_cmd {
33749 int expect_payload;
33750 size_t pkt_size;
33751 int (*fn)(struct drbd_tconn *, struct packet_info *);
33752-};
33753+} __do_const;
33754
33755 static struct data_cmd drbd_cmd_handler[] = {
33756 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33757@@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33758 if (!list_empty(&tconn->current_epoch->list))
33759 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33760 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33761- atomic_set(&tconn->current_epoch->epoch_size, 0);
33762+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33763 tconn->send.seen_any_write_yet = false;
33764
33765 conn_info(tconn, "Connection closed\n");
33766@@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33767 struct asender_cmd {
33768 size_t pkt_size;
33769 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33770-};
33771+} __do_const;
33772
33773 static struct asender_cmd asender_tbl[] = {
33774 [P_PING] = { 0, got_Ping },
33775diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33776index dfe7583..83768bb 100644
33777--- a/drivers/block/loop.c
33778+++ b/drivers/block/loop.c
33779@@ -231,7 +231,7 @@ static int __do_lo_send_write(struct file *file,
33780 mm_segment_t old_fs = get_fs();
33781
33782 set_fs(get_ds());
33783- bw = file->f_op->write(file, buf, len, &pos);
33784+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33785 set_fs(old_fs);
33786 if (likely(bw == len))
33787 return 0;
33788diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
33789index 7fecc78..84d217c 100644
33790--- a/drivers/block/nbd.c
33791+++ b/drivers/block/nbd.c
33792@@ -714,7 +714,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
33793 else
33794 blk_queue_flush(nbd->disk->queue, 0);
33795
33796- thread = kthread_create(nbd_thread, nbd, nbd->disk->disk_name);
33797+ thread = kthread_create(nbd_thread, nbd, "%s", nbd->disk->disk_name);
33798 if (IS_ERR(thread)) {
33799 mutex_lock(&nbd->tx_lock);
33800 return PTR_ERR(thread);
33801diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
33802index 2e7de7a..ed86dc0 100644
33803--- a/drivers/block/pktcdvd.c
33804+++ b/drivers/block/pktcdvd.c
33805@@ -83,7 +83,7 @@
33806
33807 #define MAX_SPEED 0xffff
33808
33809-#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1))
33810+#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1UL))
33811
33812 static DEFINE_MUTEX(pktcdvd_mutex);
33813 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
33814diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33815index d620b44..d7538c2 100644
33816--- a/drivers/cdrom/cdrom.c
33817+++ b/drivers/cdrom/cdrom.c
33818@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33819 ENSURE(reset, CDC_RESET);
33820 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33821 cdi->mc_flags = 0;
33822- cdo->n_minors = 0;
33823 cdi->options = CDO_USE_FFLAGS;
33824
33825 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33826@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33827 else
33828 cdi->cdda_method = CDDA_OLD;
33829
33830- if (!cdo->generic_packet)
33831- cdo->generic_packet = cdrom_dummy_generic_packet;
33832+ if (!cdo->generic_packet) {
33833+ pax_open_kernel();
33834+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33835+ pax_close_kernel();
33836+ }
33837
33838 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33839 mutex_lock(&cdrom_mutex);
33840@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33841 if (cdi->exit)
33842 cdi->exit(cdi);
33843
33844- cdi->ops->n_minors--;
33845 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33846 }
33847
33848@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
33849 */
33850 nr = nframes;
33851 do {
33852- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33853+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33854 if (cgc.buffer)
33855 break;
33856
33857@@ -2882,7 +2883,7 @@ static noinline int mmc_ioctl_cdrom_read_data(struct cdrom_device_info *cdi,
33858 if (lba < 0)
33859 return -EINVAL;
33860
33861- cgc->buffer = kmalloc(blocksize, GFP_KERNEL);
33862+ cgc->buffer = kzalloc(blocksize, GFP_KERNEL);
33863 if (cgc->buffer == NULL)
33864 return -ENOMEM;
33865
33866@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
33867 struct cdrom_device_info *cdi;
33868 int ret;
33869
33870- ret = scnprintf(info + *pos, max_size - *pos, header);
33871+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
33872 if (!ret)
33873 return 1;
33874
33875diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33876index d59cdcb..11afddf 100644
33877--- a/drivers/cdrom/gdrom.c
33878+++ b/drivers/cdrom/gdrom.c
33879@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33880 .audio_ioctl = gdrom_audio_ioctl,
33881 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33882 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33883- .n_minors = 1,
33884 };
33885
33886 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33887diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33888index 3bb6fa3..34013fb 100644
33889--- a/drivers/char/Kconfig
33890+++ b/drivers/char/Kconfig
33891@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33892
33893 config DEVKMEM
33894 bool "/dev/kmem virtual device support"
33895- default y
33896+ default n
33897+ depends on !GRKERNSEC_KMEM
33898 help
33899 Say Y here if you want to support the /dev/kmem device. The
33900 /dev/kmem device is rarely used, but can be used for certain
33901@@ -582,6 +583,7 @@ config DEVPORT
33902 bool
33903 depends on !M68K
33904 depends on ISA || PCI
33905+ depends on !GRKERNSEC_KMEM
33906 default y
33907
33908 source "drivers/s390/char/Kconfig"
33909diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
33910index a48e05b..6bac831 100644
33911--- a/drivers/char/agp/compat_ioctl.c
33912+++ b/drivers/char/agp/compat_ioctl.c
33913@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
33914 return -ENOMEM;
33915 }
33916
33917- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
33918+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
33919 sizeof(*usegment) * ureserve.seg_count)) {
33920 kfree(usegment);
33921 kfree(ksegment);
33922diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33923index 2e04433..771f2cc 100644
33924--- a/drivers/char/agp/frontend.c
33925+++ b/drivers/char/agp/frontend.c
33926@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33927 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33928 return -EFAULT;
33929
33930- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33931+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33932 return -EFAULT;
33933
33934 client = agp_find_client_by_pid(reserve.pid);
33935@@ -847,7 +847,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33936 if (segment == NULL)
33937 return -ENOMEM;
33938
33939- if (copy_from_user(segment, (void __user *) reserve.seg_list,
33940+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
33941 sizeof(struct agp_segment) * reserve.seg_count)) {
33942 kfree(segment);
33943 return -EFAULT;
33944diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33945index 21cb980..f15107c 100644
33946--- a/drivers/char/genrtc.c
33947+++ b/drivers/char/genrtc.c
33948@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
33949 switch (cmd) {
33950
33951 case RTC_PLL_GET:
33952+ memset(&pll, 0, sizeof(pll));
33953 if (get_rtc_pll(&pll))
33954 return -EINVAL;
33955 else
33956diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33957index d784650..e8bfd69 100644
33958--- a/drivers/char/hpet.c
33959+++ b/drivers/char/hpet.c
33960@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33961 }
33962
33963 static int
33964-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33965+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33966 struct hpet_info *info)
33967 {
33968 struct hpet_timer __iomem *timer;
33969diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
33970index 86fe45c..c0ea948 100644
33971--- a/drivers/char/hw_random/intel-rng.c
33972+++ b/drivers/char/hw_random/intel-rng.c
33973@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
33974
33975 if (no_fwh_detect)
33976 return -ENODEV;
33977- printk(warning);
33978+ printk("%s", warning);
33979 return -EBUSY;
33980 }
33981
33982diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33983index 053201b0..8335cce 100644
33984--- a/drivers/char/ipmi/ipmi_msghandler.c
33985+++ b/drivers/char/ipmi/ipmi_msghandler.c
33986@@ -420,7 +420,7 @@ struct ipmi_smi {
33987 struct proc_dir_entry *proc_dir;
33988 char proc_dir_name[10];
33989
33990- atomic_t stats[IPMI_NUM_STATS];
33991+ atomic_unchecked_t stats[IPMI_NUM_STATS];
33992
33993 /*
33994 * run_to_completion duplicate of smb_info, smi_info
33995@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33996
33997
33998 #define ipmi_inc_stat(intf, stat) \
33999- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
34000+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
34001 #define ipmi_get_stat(intf, stat) \
34002- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
34003+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
34004
34005 static int is_lan_addr(struct ipmi_addr *addr)
34006 {
34007@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
34008 INIT_LIST_HEAD(&intf->cmd_rcvrs);
34009 init_waitqueue_head(&intf->waitq);
34010 for (i = 0; i < IPMI_NUM_STATS; i++)
34011- atomic_set(&intf->stats[i], 0);
34012+ atomic_set_unchecked(&intf->stats[i], 0);
34013
34014 intf->proc_dir = NULL;
34015
34016diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
34017index 0ac9b45..6179fb5 100644
34018--- a/drivers/char/ipmi/ipmi_si_intf.c
34019+++ b/drivers/char/ipmi/ipmi_si_intf.c
34020@@ -275,7 +275,7 @@ struct smi_info {
34021 unsigned char slave_addr;
34022
34023 /* Counters and things for the proc filesystem. */
34024- atomic_t stats[SI_NUM_STATS];
34025+ atomic_unchecked_t stats[SI_NUM_STATS];
34026
34027 struct task_struct *thread;
34028
34029@@ -284,9 +284,9 @@ struct smi_info {
34030 };
34031
34032 #define smi_inc_stat(smi, stat) \
34033- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
34034+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
34035 #define smi_get_stat(smi, stat) \
34036- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
34037+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
34038
34039 #define SI_MAX_PARMS 4
34040
34041@@ -3254,7 +3254,7 @@ static int try_smi_init(struct smi_info *new_smi)
34042 atomic_set(&new_smi->req_events, 0);
34043 new_smi->run_to_completion = 0;
34044 for (i = 0; i < SI_NUM_STATS; i++)
34045- atomic_set(&new_smi->stats[i], 0);
34046+ atomic_set_unchecked(&new_smi->stats[i], 0);
34047
34048 new_smi->interrupt_disabled = 1;
34049 atomic_set(&new_smi->stop_operation, 0);
34050diff --git a/drivers/char/mem.c b/drivers/char/mem.c
34051index 2c644af..4b7aede 100644
34052--- a/drivers/char/mem.c
34053+++ b/drivers/char/mem.c
34054@@ -18,6 +18,7 @@
34055 #include <linux/raw.h>
34056 #include <linux/tty.h>
34057 #include <linux/capability.h>
34058+#include <linux/security.h>
34059 #include <linux/ptrace.h>
34060 #include <linux/device.h>
34061 #include <linux/highmem.h>
34062@@ -37,6 +38,10 @@
34063
34064 #define DEVPORT_MINOR 4
34065
34066+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34067+extern const struct file_operations grsec_fops;
34068+#endif
34069+
34070 static inline unsigned long size_inside_page(unsigned long start,
34071 unsigned long size)
34072 {
34073@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34074
34075 while (cursor < to) {
34076 if (!devmem_is_allowed(pfn)) {
34077+#ifdef CONFIG_GRKERNSEC_KMEM
34078+ gr_handle_mem_readwrite(from, to);
34079+#else
34080 printk(KERN_INFO
34081 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
34082 current->comm, from, to);
34083+#endif
34084 return 0;
34085 }
34086 cursor += PAGE_SIZE;
34087@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34088 }
34089 return 1;
34090 }
34091+#elif defined(CONFIG_GRKERNSEC_KMEM)
34092+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34093+{
34094+ return 0;
34095+}
34096 #else
34097 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34098 {
34099@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34100
34101 while (count > 0) {
34102 unsigned long remaining;
34103+ char *temp;
34104
34105 sz = size_inside_page(p, count);
34106
34107@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34108 if (!ptr)
34109 return -EFAULT;
34110
34111- remaining = copy_to_user(buf, ptr, sz);
34112+#ifdef CONFIG_PAX_USERCOPY
34113+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34114+ if (!temp) {
34115+ unxlate_dev_mem_ptr(p, ptr);
34116+ return -ENOMEM;
34117+ }
34118+ memcpy(temp, ptr, sz);
34119+#else
34120+ temp = ptr;
34121+#endif
34122+
34123+ remaining = copy_to_user(buf, temp, sz);
34124+
34125+#ifdef CONFIG_PAX_USERCOPY
34126+ kfree(temp);
34127+#endif
34128+
34129 unxlate_dev_mem_ptr(p, ptr);
34130 if (remaining)
34131 return -EFAULT;
34132@@ -378,7 +409,7 @@ static ssize_t read_oldmem(struct file *file, char __user *buf,
34133 else
34134 csize = count;
34135
34136- rc = copy_oldmem_page(pfn, buf, csize, offset, 1);
34137+ rc = copy_oldmem_page(pfn, (char __force_kernel *)buf, csize, offset, 1);
34138 if (rc < 0)
34139 return rc;
34140 buf += csize;
34141@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34142 size_t count, loff_t *ppos)
34143 {
34144 unsigned long p = *ppos;
34145- ssize_t low_count, read, sz;
34146+ ssize_t low_count, read, sz, err = 0;
34147 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
34148- int err = 0;
34149
34150 read = 0;
34151 if (p < (unsigned long) high_memory) {
34152@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34153 }
34154 #endif
34155 while (low_count > 0) {
34156+ char *temp;
34157+
34158 sz = size_inside_page(p, low_count);
34159
34160 /*
34161@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34162 */
34163 kbuf = xlate_dev_kmem_ptr((char *)p);
34164
34165- if (copy_to_user(buf, kbuf, sz))
34166+#ifdef CONFIG_PAX_USERCOPY
34167+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34168+ if (!temp)
34169+ return -ENOMEM;
34170+ memcpy(temp, kbuf, sz);
34171+#else
34172+ temp = kbuf;
34173+#endif
34174+
34175+ err = copy_to_user(buf, temp, sz);
34176+
34177+#ifdef CONFIG_PAX_USERCOPY
34178+ kfree(temp);
34179+#endif
34180+
34181+ if (err)
34182 return -EFAULT;
34183 buf += sz;
34184 p += sz;
34185@@ -833,6 +880,9 @@ static const struct memdev {
34186 #ifdef CONFIG_CRASH_DUMP
34187 [12] = { "oldmem", 0, &oldmem_fops, NULL },
34188 #endif
34189+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34190+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
34191+#endif
34192 };
34193
34194 static int memory_open(struct inode *inode, struct file *filp)
34195@@ -904,7 +954,7 @@ static int __init chr_dev_init(void)
34196 continue;
34197
34198 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
34199- NULL, devlist[minor].name);
34200+ NULL, "%s", devlist[minor].name);
34201 }
34202
34203 return tty_init();
34204diff --git a/drivers/char/mwave/tp3780i.c b/drivers/char/mwave/tp3780i.c
34205index c689697..04e6d6a2 100644
34206--- a/drivers/char/mwave/tp3780i.c
34207+++ b/drivers/char/mwave/tp3780i.c
34208@@ -479,6 +479,7 @@ int tp3780I_QueryAbilities(THINKPAD_BD_DATA * pBDData, MW_ABILITIES * pAbilities
34209 PRINTK_2(TRACE_TP3780I,
34210 "tp3780i::tp3780I_QueryAbilities entry pBDData %p\n", pBDData);
34211
34212+ memset(pAbilities, 0, sizeof(*pAbilities));
34213 /* fill out standard constant fields */
34214 pAbilities->instr_per_sec = pBDData->rDspSettings.uIps;
34215 pAbilities->data_size = pBDData->rDspSettings.uDStoreSize;
34216diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
34217index 9df78e2..01ba9ae 100644
34218--- a/drivers/char/nvram.c
34219+++ b/drivers/char/nvram.c
34220@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
34221
34222 spin_unlock_irq(&rtc_lock);
34223
34224- if (copy_to_user(buf, contents, tmp - contents))
34225+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
34226 return -EFAULT;
34227
34228 *ppos = i;
34229diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
34230index 5c5cc00..ac9edb7 100644
34231--- a/drivers/char/pcmcia/synclink_cs.c
34232+++ b/drivers/char/pcmcia/synclink_cs.c
34233@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34234
34235 if (debug_level >= DEBUG_LEVEL_INFO)
34236 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
34237- __FILE__, __LINE__, info->device_name, port->count);
34238+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
34239
34240- WARN_ON(!port->count);
34241+ WARN_ON(!atomic_read(&port->count));
34242
34243 if (tty_port_close_start(port, tty, filp) == 0)
34244 goto cleanup;
34245@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34246 cleanup:
34247 if (debug_level >= DEBUG_LEVEL_INFO)
34248 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
34249- tty->driver->name, port->count);
34250+ tty->driver->name, atomic_read(&port->count));
34251 }
34252
34253 /* Wait until the transmitter is empty.
34254@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34255
34256 if (debug_level >= DEBUG_LEVEL_INFO)
34257 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
34258- __FILE__, __LINE__, tty->driver->name, port->count);
34259+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
34260
34261 /* If port is closing, signal caller to try again */
34262 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
34263@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34264 goto cleanup;
34265 }
34266 spin_lock(&port->lock);
34267- port->count++;
34268+ atomic_inc(&port->count);
34269 spin_unlock(&port->lock);
34270 spin_unlock_irqrestore(&info->netlock, flags);
34271
34272- if (port->count == 1) {
34273+ if (atomic_read(&port->count) == 1) {
34274 /* 1st open on this device, init hardware */
34275 retval = startup(info, tty);
34276 if (retval < 0)
34277@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
34278 unsigned short new_crctype;
34279
34280 /* return error if TTY interface open */
34281- if (info->port.count)
34282+ if (atomic_read(&info->port.count))
34283 return -EBUSY;
34284
34285 switch (encoding)
34286@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
34287
34288 /* arbitrate between network and tty opens */
34289 spin_lock_irqsave(&info->netlock, flags);
34290- if (info->port.count != 0 || info->netcount != 0) {
34291+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
34292 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
34293 spin_unlock_irqrestore(&info->netlock, flags);
34294 return -EBUSY;
34295@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34296 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
34297
34298 /* return error if TTY interface open */
34299- if (info->port.count)
34300+ if (atomic_read(&info->port.count))
34301 return -EBUSY;
34302
34303 if (cmd != SIOCWANDEV)
34304diff --git a/drivers/char/random.c b/drivers/char/random.c
34305index eccd7cc..98038d5 100644
34306--- a/drivers/char/random.c
34307+++ b/drivers/char/random.c
34308@@ -272,8 +272,13 @@
34309 /*
34310 * Configuration information
34311 */
34312+#ifdef CONFIG_GRKERNSEC_RANDNET
34313+#define INPUT_POOL_WORDS 512
34314+#define OUTPUT_POOL_WORDS 128
34315+#else
34316 #define INPUT_POOL_WORDS 128
34317 #define OUTPUT_POOL_WORDS 32
34318+#endif
34319 #define SEC_XFER_SIZE 512
34320 #define EXTRACT_SIZE 10
34321
34322@@ -313,10 +318,17 @@ static struct poolinfo {
34323 int poolwords;
34324 int tap1, tap2, tap3, tap4, tap5;
34325 } poolinfo_table[] = {
34326+#ifdef CONFIG_GRKERNSEC_RANDNET
34327+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
34328+ { 512, 411, 308, 208, 104, 1 },
34329+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
34330+ { 128, 103, 76, 51, 25, 1 },
34331+#else
34332 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
34333 { 128, 103, 76, 51, 25, 1 },
34334 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
34335 { 32, 26, 20, 14, 7, 1 },
34336+#endif
34337 #if 0
34338 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
34339 { 2048, 1638, 1231, 819, 411, 1 },
34340@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
34341 input_rotate += i ? 7 : 14;
34342 }
34343
34344- ACCESS_ONCE(r->input_rotate) = input_rotate;
34345- ACCESS_ONCE(r->add_ptr) = i;
34346+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
34347+ ACCESS_ONCE_RW(r->add_ptr) = i;
34348 smp_wmb();
34349
34350 if (out)
34351@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
34352
34353 extract_buf(r, tmp);
34354 i = min_t(int, nbytes, EXTRACT_SIZE);
34355- if (copy_to_user(buf, tmp, i)) {
34356+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
34357 ret = -EFAULT;
34358 break;
34359 }
34360@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
34361 #include <linux/sysctl.h>
34362
34363 static int min_read_thresh = 8, min_write_thresh;
34364-static int max_read_thresh = INPUT_POOL_WORDS * 32;
34365+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
34366 static int max_write_thresh = INPUT_POOL_WORDS * 32;
34367 static char sysctl_bootid[16];
34368
34369@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
34370 static int proc_do_uuid(ctl_table *table, int write,
34371 void __user *buffer, size_t *lenp, loff_t *ppos)
34372 {
34373- ctl_table fake_table;
34374+ ctl_table_no_const fake_table;
34375 unsigned char buf[64], tmp_uuid[16], *uuid;
34376
34377 uuid = table->data;
34378diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
34379index bf2349db..5456d53 100644
34380--- a/drivers/char/sonypi.c
34381+++ b/drivers/char/sonypi.c
34382@@ -54,6 +54,7 @@
34383
34384 #include <asm/uaccess.h>
34385 #include <asm/io.h>
34386+#include <asm/local.h>
34387
34388 #include <linux/sonypi.h>
34389
34390@@ -490,7 +491,7 @@ static struct sonypi_device {
34391 spinlock_t fifo_lock;
34392 wait_queue_head_t fifo_proc_list;
34393 struct fasync_struct *fifo_async;
34394- int open_count;
34395+ local_t open_count;
34396 int model;
34397 struct input_dev *input_jog_dev;
34398 struct input_dev *input_key_dev;
34399@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
34400 static int sonypi_misc_release(struct inode *inode, struct file *file)
34401 {
34402 mutex_lock(&sonypi_device.lock);
34403- sonypi_device.open_count--;
34404+ local_dec(&sonypi_device.open_count);
34405 mutex_unlock(&sonypi_device.lock);
34406 return 0;
34407 }
34408@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
34409 {
34410 mutex_lock(&sonypi_device.lock);
34411 /* Flush input queue on first open */
34412- if (!sonypi_device.open_count)
34413+ if (!local_read(&sonypi_device.open_count))
34414 kfifo_reset(&sonypi_device.fifo);
34415- sonypi_device.open_count++;
34416+ local_inc(&sonypi_device.open_count);
34417 mutex_unlock(&sonypi_device.lock);
34418
34419 return 0;
34420diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
34421index 64420b3..5c40b56 100644
34422--- a/drivers/char/tpm/tpm_acpi.c
34423+++ b/drivers/char/tpm/tpm_acpi.c
34424@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
34425 virt = acpi_os_map_memory(start, len);
34426 if (!virt) {
34427 kfree(log->bios_event_log);
34428+ log->bios_event_log = NULL;
34429 printk("%s: ERROR - Unable to map memory\n", __func__);
34430 return -EIO;
34431 }
34432
34433- memcpy_fromio(log->bios_event_log, virt, len);
34434+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34435
34436 acpi_os_unmap_memory(virt, len);
34437 return 0;
34438diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34439index 84ddc55..1d32f1e 100644
34440--- a/drivers/char/tpm/tpm_eventlog.c
34441+++ b/drivers/char/tpm/tpm_eventlog.c
34442@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34443 event = addr;
34444
34445 if ((event->event_type == 0 && event->event_size == 0) ||
34446- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34447+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34448 return NULL;
34449
34450 return addr;
34451@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34452 return NULL;
34453
34454 if ((event->event_type == 0 && event->event_size == 0) ||
34455- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34456+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34457 return NULL;
34458
34459 (*pos)++;
34460@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34461 int i;
34462
34463 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34464- seq_putc(m, data[i]);
34465+ if (!seq_putc(m, data[i]))
34466+ return -EFAULT;
34467
34468 return 0;
34469 }
34470diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34471index ce5f3fc..e2d3e55 100644
34472--- a/drivers/char/virtio_console.c
34473+++ b/drivers/char/virtio_console.c
34474@@ -679,7 +679,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34475 if (to_user) {
34476 ssize_t ret;
34477
34478- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34479+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34480 if (ret)
34481 return -EFAULT;
34482 } else {
34483@@ -778,7 +778,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34484 if (!port_has_data(port) && !port->host_connected)
34485 return 0;
34486
34487- return fill_readbuf(port, ubuf, count, true);
34488+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34489 }
34490
34491 static int wait_port_writable(struct port *port, bool nonblock)
34492diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
34493index d7ad425..3e3f81f 100644
34494--- a/drivers/clocksource/arm_arch_timer.c
34495+++ b/drivers/clocksource/arm_arch_timer.c
34496@@ -262,7 +262,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34497 return NOTIFY_OK;
34498 }
34499
34500-static struct notifier_block arch_timer_cpu_nb __cpuinitdata = {
34501+static struct notifier_block arch_timer_cpu_nb = {
34502 .notifier_call = arch_timer_cpu_notify,
34503 };
34504
34505diff --git a/drivers/clocksource/metag_generic.c b/drivers/clocksource/metag_generic.c
34506index ade7513..069445f 100644
34507--- a/drivers/clocksource/metag_generic.c
34508+++ b/drivers/clocksource/metag_generic.c
34509@@ -169,7 +169,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34510 return NOTIFY_OK;
34511 }
34512
34513-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34514+static struct notifier_block arch_timer_cpu_nb = {
34515 .notifier_call = arch_timer_cpu_notify,
34516 };
34517
34518diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34519index bb5939b..d9accb7 100644
34520--- a/drivers/cpufreq/acpi-cpufreq.c
34521+++ b/drivers/cpufreq/acpi-cpufreq.c
34522@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34523 return sprintf(buf, "%u\n", boost_enabled);
34524 }
34525
34526-static struct global_attr global_boost = __ATTR(boost, 0644,
34527+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34528 show_global_boost,
34529 store_global_boost);
34530
34531@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34532 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34533 per_cpu(acfreq_data, cpu) = data;
34534
34535- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34536- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34537+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34538+ pax_open_kernel();
34539+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34540+ pax_close_kernel();
34541+ }
34542
34543 result = acpi_processor_register_performance(data->acpi_data, cpu);
34544 if (result)
34545@@ -839,7 +842,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34546 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34547 break;
34548 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34549- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34550+ pax_open_kernel();
34551+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34552+ pax_close_kernel();
34553 policy->cur = get_cur_freq_on_cpu(cpu);
34554 break;
34555 default:
34556@@ -850,8 +855,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34557 acpi_processor_notify_smm(THIS_MODULE);
34558
34559 /* Check for APERF/MPERF support in hardware */
34560- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34561- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34562+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34563+ pax_open_kernel();
34564+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34565+ pax_close_kernel();
34566+ }
34567
34568 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34569 for (i = 0; i < perf->state_count; i++)
34570diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34571index b02824d..51e44aa 100644
34572--- a/drivers/cpufreq/cpufreq.c
34573+++ b/drivers/cpufreq/cpufreq.c
34574@@ -1813,7 +1813,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34575 return NOTIFY_OK;
34576 }
34577
34578-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34579+static struct notifier_block cpufreq_cpu_notifier = {
34580 .notifier_call = cpufreq_cpu_callback,
34581 };
34582
34583@@ -1845,8 +1845,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34584
34585 pr_debug("trying to register driver %s\n", driver_data->name);
34586
34587- if (driver_data->setpolicy)
34588- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34589+ if (driver_data->setpolicy) {
34590+ pax_open_kernel();
34591+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34592+ pax_close_kernel();
34593+ }
34594
34595 spin_lock_irqsave(&cpufreq_driver_lock, flags);
34596 if (cpufreq_driver) {
34597diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34598index 5a76086..0f4d394 100644
34599--- a/drivers/cpufreq/cpufreq_governor.c
34600+++ b/drivers/cpufreq/cpufreq_governor.c
34601@@ -201,8 +201,8 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34602 {
34603 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
34604 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
34605- struct cs_ops *cs_ops = NULL;
34606- struct od_ops *od_ops = NULL;
34607+ const struct cs_ops *cs_ops = NULL;
34608+ const struct od_ops *od_ops = NULL;
34609 struct od_dbs_tuners *od_tuners = dbs_data->tuners;
34610 struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
34611 struct cpu_dbs_common_info *cpu_cdbs;
34612diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34613index cc4bd2f..ad142bc 100644
34614--- a/drivers/cpufreq/cpufreq_governor.h
34615+++ b/drivers/cpufreq/cpufreq_governor.h
34616@@ -142,7 +142,7 @@ struct dbs_data {
34617 void (*gov_check_cpu)(int cpu, unsigned int load);
34618
34619 /* Governor specific ops, see below */
34620- void *gov_ops;
34621+ const void *gov_ops;
34622 };
34623
34624 /* Governor specific ops, will be passed to dbs_data->gov_ops */
34625diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34626index bfd6273..e39dd63 100644
34627--- a/drivers/cpufreq/cpufreq_stats.c
34628+++ b/drivers/cpufreq/cpufreq_stats.c
34629@@ -365,7 +365,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34630 }
34631
34632 /* priority=1 so this will get called before cpufreq_remove_dev */
34633-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34634+static struct notifier_block cpufreq_stat_cpu_notifier = {
34635 .notifier_call = cpufreq_stat_cpu_callback,
34636 .priority = 1,
34637 };
34638diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34639index 827629c9..0bc6a03 100644
34640--- a/drivers/cpufreq/p4-clockmod.c
34641+++ b/drivers/cpufreq/p4-clockmod.c
34642@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34643 case 0x0F: /* Core Duo */
34644 case 0x16: /* Celeron Core */
34645 case 0x1C: /* Atom */
34646- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34647+ pax_open_kernel();
34648+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34649+ pax_close_kernel();
34650 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34651 case 0x0D: /* Pentium M (Dothan) */
34652- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34653+ pax_open_kernel();
34654+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34655+ pax_close_kernel();
34656 /* fall through */
34657 case 0x09: /* Pentium M (Banias) */
34658 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34659@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34660
34661 /* on P-4s, the TSC runs with constant frequency independent whether
34662 * throttling is active or not. */
34663- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34664+ pax_open_kernel();
34665+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34666+ pax_close_kernel();
34667
34668 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34669 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34670diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34671index 3a953d5..f5993f6 100644
34672--- a/drivers/cpufreq/speedstep-centrino.c
34673+++ b/drivers/cpufreq/speedstep-centrino.c
34674@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34675 !cpu_has(cpu, X86_FEATURE_EST))
34676 return -ENODEV;
34677
34678- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34679- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34680+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34681+ pax_open_kernel();
34682+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34683+ pax_close_kernel();
34684+ }
34685
34686 if (policy->cpu != 0)
34687 return -ENODEV;
34688diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34689index eba6929..0f53baf 100644
34690--- a/drivers/cpuidle/cpuidle.c
34691+++ b/drivers/cpuidle/cpuidle.c
34692@@ -277,7 +277,7 @@ static int poll_idle(struct cpuidle_device *dev,
34693
34694 static void poll_idle_init(struct cpuidle_driver *drv)
34695 {
34696- struct cpuidle_state *state = &drv->states[0];
34697+ cpuidle_state_no_const *state = &drv->states[0];
34698
34699 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34700 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34701diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34702index ea2f8e7..70ac501 100644
34703--- a/drivers/cpuidle/governor.c
34704+++ b/drivers/cpuidle/governor.c
34705@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34706 mutex_lock(&cpuidle_lock);
34707 if (__cpuidle_find_governor(gov->name) == NULL) {
34708 ret = 0;
34709- list_add_tail(&gov->governor_list, &cpuidle_governors);
34710+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34711 if (!cpuidle_curr_governor ||
34712 cpuidle_curr_governor->rating < gov->rating)
34713 cpuidle_switch_governor(gov);
34714@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34715 new_gov = cpuidle_replace_governor(gov->rating);
34716 cpuidle_switch_governor(new_gov);
34717 }
34718- list_del(&gov->governor_list);
34719+ pax_list_del((struct list_head *)&gov->governor_list);
34720 mutex_unlock(&cpuidle_lock);
34721 }
34722
34723diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34724index 428754a..8bdf9cc 100644
34725--- a/drivers/cpuidle/sysfs.c
34726+++ b/drivers/cpuidle/sysfs.c
34727@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34728 NULL
34729 };
34730
34731-static struct attribute_group cpuidle_attr_group = {
34732+static attribute_group_no_const cpuidle_attr_group = {
34733 .attrs = cpuidle_default_attrs,
34734 .name = "cpuidle",
34735 };
34736diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34737index 3b36797..db0b0c0 100644
34738--- a/drivers/devfreq/devfreq.c
34739+++ b/drivers/devfreq/devfreq.c
34740@@ -477,7 +477,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
34741 GFP_KERNEL);
34742 devfreq->last_stat_updated = jiffies;
34743
34744- dev_set_name(&devfreq->dev, dev_name(dev));
34745+ dev_set_name(&devfreq->dev, "%s", dev_name(dev));
34746 err = device_register(&devfreq->dev);
34747 if (err) {
34748 put_device(&devfreq->dev);
34749@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34750 goto err_out;
34751 }
34752
34753- list_add(&governor->node, &devfreq_governor_list);
34754+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34755
34756 list_for_each_entry(devfreq, &devfreq_list, node) {
34757 int ret = 0;
34758@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34759 }
34760 }
34761
34762- list_del(&governor->node);
34763+ pax_list_del((struct list_head *)&governor->node);
34764 err_out:
34765 mutex_unlock(&devfreq_list_lock);
34766
34767diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34768index b70709b..1d8d02a 100644
34769--- a/drivers/dma/sh/shdma.c
34770+++ b/drivers/dma/sh/shdma.c
34771@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34772 return ret;
34773 }
34774
34775-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34776+static struct notifier_block sh_dmae_nmi_notifier = {
34777 .notifier_call = sh_dmae_nmi_handler,
34778
34779 /* Run before NMI debug handler and KGDB */
34780diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34781index 769d92e..a3dcc1e 100644
34782--- a/drivers/edac/edac_mc_sysfs.c
34783+++ b/drivers/edac/edac_mc_sysfs.c
34784@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34785 struct dev_ch_attribute {
34786 struct device_attribute attr;
34787 int channel;
34788-};
34789+} __do_const;
34790
34791 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34792 struct dev_ch_attribute dev_attr_legacy_##_name = \
34793@@ -1003,14 +1003,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
34794 }
34795
34796 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
34797+ pax_open_kernel();
34798 if (mci->get_sdram_scrub_rate) {
34799- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34800- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34801+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34802+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34803 }
34804 if (mci->set_sdram_scrub_rate) {
34805- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34806- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34807+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34808+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34809 }
34810+ pax_close_kernel();
34811 err = device_create_file(&mci->dev,
34812 &dev_attr_sdram_scrub_rate);
34813 if (err) {
34814diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34815index e8658e4..22746d6 100644
34816--- a/drivers/edac/edac_pci_sysfs.c
34817+++ b/drivers/edac/edac_pci_sysfs.c
34818@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34819 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34820 static int edac_pci_poll_msec = 1000; /* one second workq period */
34821
34822-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34823-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34824+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34825+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34826
34827 static struct kobject *edac_pci_top_main_kobj;
34828 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34829@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34830 void *value;
34831 ssize_t(*show) (void *, char *);
34832 ssize_t(*store) (void *, const char *, size_t);
34833-};
34834+} __do_const;
34835
34836 /* Set of show/store abstract level functions for PCI Parity object */
34837 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34838@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34839 edac_printk(KERN_CRIT, EDAC_PCI,
34840 "Signaled System Error on %s\n",
34841 pci_name(dev));
34842- atomic_inc(&pci_nonparity_count);
34843+ atomic_inc_unchecked(&pci_nonparity_count);
34844 }
34845
34846 if (status & (PCI_STATUS_PARITY)) {
34847@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34848 "Master Data Parity Error on %s\n",
34849 pci_name(dev));
34850
34851- atomic_inc(&pci_parity_count);
34852+ atomic_inc_unchecked(&pci_parity_count);
34853 }
34854
34855 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34856@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34857 "Detected Parity Error on %s\n",
34858 pci_name(dev));
34859
34860- atomic_inc(&pci_parity_count);
34861+ atomic_inc_unchecked(&pci_parity_count);
34862 }
34863 }
34864
34865@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34866 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34867 "Signaled System Error on %s\n",
34868 pci_name(dev));
34869- atomic_inc(&pci_nonparity_count);
34870+ atomic_inc_unchecked(&pci_nonparity_count);
34871 }
34872
34873 if (status & (PCI_STATUS_PARITY)) {
34874@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34875 "Master Data Parity Error on "
34876 "%s\n", pci_name(dev));
34877
34878- atomic_inc(&pci_parity_count);
34879+ atomic_inc_unchecked(&pci_parity_count);
34880 }
34881
34882 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34883@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34884 "Detected Parity Error on %s\n",
34885 pci_name(dev));
34886
34887- atomic_inc(&pci_parity_count);
34888+ atomic_inc_unchecked(&pci_parity_count);
34889 }
34890 }
34891 }
34892@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34893 if (!check_pci_errors)
34894 return;
34895
34896- before_count = atomic_read(&pci_parity_count);
34897+ before_count = atomic_read_unchecked(&pci_parity_count);
34898
34899 /* scan all PCI devices looking for a Parity Error on devices and
34900 * bridges.
34901@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34902 /* Only if operator has selected panic on PCI Error */
34903 if (edac_pci_get_panic_on_pe()) {
34904 /* If the count is different 'after' from 'before' */
34905- if (before_count != atomic_read(&pci_parity_count))
34906+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34907 panic("EDAC: PCI Parity Error");
34908 }
34909 }
34910diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34911index 51b7e3a..aa8a3e8 100644
34912--- a/drivers/edac/mce_amd.h
34913+++ b/drivers/edac/mce_amd.h
34914@@ -77,7 +77,7 @@ struct amd_decoder_ops {
34915 bool (*mc0_mce)(u16, u8);
34916 bool (*mc1_mce)(u16, u8);
34917 bool (*mc2_mce)(u16, u8);
34918-};
34919+} __no_const;
34920
34921 void amd_report_gart_errors(bool);
34922 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34923diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34924index 57ea7f4..789e3c3 100644
34925--- a/drivers/firewire/core-card.c
34926+++ b/drivers/firewire/core-card.c
34927@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34928
34929 void fw_core_remove_card(struct fw_card *card)
34930 {
34931- struct fw_card_driver dummy_driver = dummy_driver_template;
34932+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
34933
34934 card->driver->update_phy_reg(card, 4,
34935 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34936diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34937index 27ac423..13573e8 100644
34938--- a/drivers/firewire/core-cdev.c
34939+++ b/drivers/firewire/core-cdev.c
34940@@ -1366,8 +1366,7 @@ static int init_iso_resource(struct client *client,
34941 int ret;
34942
34943 if ((request->channels == 0 && request->bandwidth == 0) ||
34944- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34945- request->bandwidth < 0)
34946+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34947 return -EINVAL;
34948
34949 r = kmalloc(sizeof(*r), GFP_KERNEL);
34950diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34951index 03ce7d9..b70f5da 100644
34952--- a/drivers/firewire/core-device.c
34953+++ b/drivers/firewire/core-device.c
34954@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34955 struct config_rom_attribute {
34956 struct device_attribute attr;
34957 u32 key;
34958-};
34959+} __do_const;
34960
34961 static ssize_t show_immediate(struct device *dev,
34962 struct device_attribute *dattr, char *buf)
34963diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34964index 28a94c7..58da63a 100644
34965--- a/drivers/firewire/core-transaction.c
34966+++ b/drivers/firewire/core-transaction.c
34967@@ -38,6 +38,7 @@
34968 #include <linux/timer.h>
34969 #include <linux/types.h>
34970 #include <linux/workqueue.h>
34971+#include <linux/sched.h>
34972
34973 #include <asm/byteorder.h>
34974
34975diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34976index 515a42c..5ecf3ba 100644
34977--- a/drivers/firewire/core.h
34978+++ b/drivers/firewire/core.h
34979@@ -111,6 +111,7 @@ struct fw_card_driver {
34980
34981 int (*stop_iso)(struct fw_iso_context *ctx);
34982 };
34983+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
34984
34985 void fw_card_initialize(struct fw_card *card,
34986 const struct fw_card_driver *driver, struct device *device);
34987diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
34988index 94a58a0..f5eba42 100644
34989--- a/drivers/firmware/dmi-id.c
34990+++ b/drivers/firmware/dmi-id.c
34991@@ -16,7 +16,7 @@
34992 struct dmi_device_attribute{
34993 struct device_attribute dev_attr;
34994 int field;
34995-};
34996+} __do_const;
34997 #define to_dmi_dev_attr(_dev_attr) \
34998 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
34999
35000diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
35001index 4cd392d..4b629e1 100644
35002--- a/drivers/firmware/dmi_scan.c
35003+++ b/drivers/firmware/dmi_scan.c
35004@@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
35005 }
35006 }
35007 else {
35008- /*
35009- * no iounmap() for that ioremap(); it would be a no-op, but
35010- * it's so early in setup that sucker gets confused into doing
35011- * what it shouldn't if we actually call it.
35012- */
35013 p = dmi_ioremap(0xF0000, 0x10000);
35014 if (p == NULL)
35015 goto error;
35016@@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
35017 if (buf == NULL)
35018 return -1;
35019
35020- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
35021+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
35022
35023 iounmap(buf);
35024 return 0;
35025diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
35026index f4baa11..7970c3a 100644
35027--- a/drivers/firmware/efivars.c
35028+++ b/drivers/firmware/efivars.c
35029@@ -139,7 +139,7 @@ struct efivar_attribute {
35030 };
35031
35032 static struct efivars __efivars;
35033-static struct efivar_operations ops;
35034+static efivar_operations_no_const ops __read_only;
35035
35036 #define PSTORE_EFI_ATTRIBUTES \
35037 (EFI_VARIABLE_NON_VOLATILE | \
35038@@ -1844,7 +1844,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
35039 static int
35040 create_efivars_bin_attributes(struct efivars *efivars)
35041 {
35042- struct bin_attribute *attr;
35043+ bin_attribute_no_const *attr;
35044 int error;
35045
35046 /* new_var */
35047diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
35048index 2a90ba6..07f3733 100644
35049--- a/drivers/firmware/google/memconsole.c
35050+++ b/drivers/firmware/google/memconsole.c
35051@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
35052 if (!found_memconsole())
35053 return -ENODEV;
35054
35055- memconsole_bin_attr.size = memconsole_length;
35056+ pax_open_kernel();
35057+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
35058+ pax_close_kernel();
35059
35060 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
35061
35062diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
35063index de3c317..b7cd029 100644
35064--- a/drivers/gpio/gpio-ich.c
35065+++ b/drivers/gpio/gpio-ich.c
35066@@ -69,7 +69,7 @@ struct ichx_desc {
35067 /* Some chipsets have quirks, let these use their own request/get */
35068 int (*request)(struct gpio_chip *chip, unsigned offset);
35069 int (*get)(struct gpio_chip *chip, unsigned offset);
35070-};
35071+} __do_const;
35072
35073 static struct {
35074 spinlock_t lock;
35075diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
35076index 9902732..64b62dd 100644
35077--- a/drivers/gpio/gpio-vr41xx.c
35078+++ b/drivers/gpio/gpio-vr41xx.c
35079@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
35080 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
35081 maskl, pendl, maskh, pendh);
35082
35083- atomic_inc(&irq_err_count);
35084+ atomic_inc_unchecked(&irq_err_count);
35085
35086 return -EINVAL;
35087 }
35088diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
35089index 7b2d378..cc947ea 100644
35090--- a/drivers/gpu/drm/drm_crtc_helper.c
35091+++ b/drivers/gpu/drm/drm_crtc_helper.c
35092@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
35093 struct drm_crtc *tmp;
35094 int crtc_mask = 1;
35095
35096- WARN(!crtc, "checking null crtc?\n");
35097+ BUG_ON(!crtc);
35098
35099 dev = crtc->dev;
35100
35101diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
35102index 25f91cd..a376f55 100644
35103--- a/drivers/gpu/drm/drm_drv.c
35104+++ b/drivers/gpu/drm/drm_drv.c
35105@@ -306,7 +306,7 @@ module_exit(drm_core_exit);
35106 /**
35107 * Copy and IOCTL return string to user space
35108 */
35109-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
35110+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
35111 {
35112 int len;
35113
35114@@ -376,7 +376,7 @@ long drm_ioctl(struct file *filp,
35115 struct drm_file *file_priv = filp->private_data;
35116 struct drm_device *dev;
35117 struct drm_ioctl_desc *ioctl;
35118- drm_ioctl_t *func;
35119+ drm_ioctl_no_const_t func;
35120 unsigned int nr = DRM_IOCTL_NR(cmd);
35121 int retcode = -EINVAL;
35122 char stack_kdata[128];
35123@@ -389,7 +389,7 @@ long drm_ioctl(struct file *filp,
35124 return -ENODEV;
35125
35126 atomic_inc(&dev->ioctl_count);
35127- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
35128+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
35129 ++file_priv->ioctl_count;
35130
35131 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
35132diff --git a/drivers/gpu/drm/drm_encoder_slave.c b/drivers/gpu/drm/drm_encoder_slave.c
35133index 48c52f7..0cfb60f 100644
35134--- a/drivers/gpu/drm/drm_encoder_slave.c
35135+++ b/drivers/gpu/drm/drm_encoder_slave.c
35136@@ -54,16 +54,12 @@ int drm_i2c_encoder_init(struct drm_device *dev,
35137 struct i2c_adapter *adap,
35138 const struct i2c_board_info *info)
35139 {
35140- char modalias[sizeof(I2C_MODULE_PREFIX)
35141- + I2C_NAME_SIZE];
35142 struct module *module = NULL;
35143 struct i2c_client *client;
35144 struct drm_i2c_encoder_driver *encoder_drv;
35145 int err = 0;
35146
35147- snprintf(modalias, sizeof(modalias),
35148- "%s%s", I2C_MODULE_PREFIX, info->type);
35149- request_module(modalias);
35150+ request_module("%s%s", I2C_MODULE_PREFIX, info->type);
35151
35152 client = i2c_new_device(adap, info);
35153 if (!client) {
35154diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
35155index 429e07d..e681a2c 100644
35156--- a/drivers/gpu/drm/drm_fops.c
35157+++ b/drivers/gpu/drm/drm_fops.c
35158@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
35159 }
35160
35161 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
35162- atomic_set(&dev->counts[i], 0);
35163+ atomic_set_unchecked(&dev->counts[i], 0);
35164
35165 dev->sigdata.lock = NULL;
35166
35167@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
35168 if (drm_device_is_unplugged(dev))
35169 return -ENODEV;
35170
35171- if (!dev->open_count++)
35172+ if (local_inc_return(&dev->open_count) == 1)
35173 need_setup = 1;
35174 mutex_lock(&dev->struct_mutex);
35175 old_imapping = inode->i_mapping;
35176@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
35177 retcode = drm_open_helper(inode, filp, dev);
35178 if (retcode)
35179 goto err_undo;
35180- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
35181+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
35182 if (need_setup) {
35183 retcode = drm_setup(dev);
35184 if (retcode)
35185@@ -166,7 +166,7 @@ err_undo:
35186 iput(container_of(dev->dev_mapping, struct inode, i_data));
35187 dev->dev_mapping = old_mapping;
35188 mutex_unlock(&dev->struct_mutex);
35189- dev->open_count--;
35190+ local_dec(&dev->open_count);
35191 return retcode;
35192 }
35193 EXPORT_SYMBOL(drm_open);
35194@@ -441,7 +441,7 @@ int drm_release(struct inode *inode, struct file *filp)
35195
35196 mutex_lock(&drm_global_mutex);
35197
35198- DRM_DEBUG("open_count = %d\n", dev->open_count);
35199+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
35200
35201 if (dev->driver->preclose)
35202 dev->driver->preclose(dev, file_priv);
35203@@ -450,10 +450,10 @@ int drm_release(struct inode *inode, struct file *filp)
35204 * Begin inline drm_release
35205 */
35206
35207- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
35208+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
35209 task_pid_nr(current),
35210 (long)old_encode_dev(file_priv->minor->device),
35211- dev->open_count);
35212+ local_read(&dev->open_count));
35213
35214 /* Release any auth tokens that might point to this file_priv,
35215 (do that under the drm_global_mutex) */
35216@@ -550,8 +550,8 @@ int drm_release(struct inode *inode, struct file *filp)
35217 * End inline drm_release
35218 */
35219
35220- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
35221- if (!--dev->open_count) {
35222+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
35223+ if (local_dec_and_test(&dev->open_count)) {
35224 if (atomic_read(&dev->ioctl_count)) {
35225 DRM_ERROR("Device busy: %d\n",
35226 atomic_read(&dev->ioctl_count));
35227diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
35228index f731116..629842c 100644
35229--- a/drivers/gpu/drm/drm_global.c
35230+++ b/drivers/gpu/drm/drm_global.c
35231@@ -36,7 +36,7 @@
35232 struct drm_global_item {
35233 struct mutex mutex;
35234 void *object;
35235- int refcount;
35236+ atomic_t refcount;
35237 };
35238
35239 static struct drm_global_item glob[DRM_GLOBAL_NUM];
35240@@ -49,7 +49,7 @@ void drm_global_init(void)
35241 struct drm_global_item *item = &glob[i];
35242 mutex_init(&item->mutex);
35243 item->object = NULL;
35244- item->refcount = 0;
35245+ atomic_set(&item->refcount, 0);
35246 }
35247 }
35248
35249@@ -59,7 +59,7 @@ void drm_global_release(void)
35250 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
35251 struct drm_global_item *item = &glob[i];
35252 BUG_ON(item->object != NULL);
35253- BUG_ON(item->refcount != 0);
35254+ BUG_ON(atomic_read(&item->refcount) != 0);
35255 }
35256 }
35257
35258@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35259 void *object;
35260
35261 mutex_lock(&item->mutex);
35262- if (item->refcount == 0) {
35263+ if (atomic_read(&item->refcount) == 0) {
35264 item->object = kzalloc(ref->size, GFP_KERNEL);
35265 if (unlikely(item->object == NULL)) {
35266 ret = -ENOMEM;
35267@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35268 goto out_err;
35269
35270 }
35271- ++item->refcount;
35272+ atomic_inc(&item->refcount);
35273 ref->object = item->object;
35274 object = item->object;
35275 mutex_unlock(&item->mutex);
35276@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
35277 struct drm_global_item *item = &glob[ref->global_type];
35278
35279 mutex_lock(&item->mutex);
35280- BUG_ON(item->refcount == 0);
35281+ BUG_ON(atomic_read(&item->refcount) == 0);
35282 BUG_ON(ref->object != item->object);
35283- if (--item->refcount == 0) {
35284+ if (atomic_dec_and_test(&item->refcount)) {
35285 ref->release(ref);
35286 item->object = NULL;
35287 }
35288diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
35289index d4b20ce..77a8d41 100644
35290--- a/drivers/gpu/drm/drm_info.c
35291+++ b/drivers/gpu/drm/drm_info.c
35292@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
35293 struct drm_local_map *map;
35294 struct drm_map_list *r_list;
35295
35296- /* Hardcoded from _DRM_FRAME_BUFFER,
35297- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
35298- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
35299- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
35300+ static const char * const types[] = {
35301+ [_DRM_FRAME_BUFFER] = "FB",
35302+ [_DRM_REGISTERS] = "REG",
35303+ [_DRM_SHM] = "SHM",
35304+ [_DRM_AGP] = "AGP",
35305+ [_DRM_SCATTER_GATHER] = "SG",
35306+ [_DRM_CONSISTENT] = "PCI",
35307+ [_DRM_GEM] = "GEM" };
35308 const char *type;
35309 int i;
35310
35311@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
35312 map = r_list->map;
35313 if (!map)
35314 continue;
35315- if (map->type < 0 || map->type > 5)
35316+ if (map->type >= ARRAY_SIZE(types))
35317 type = "??";
35318 else
35319 type = types[map->type];
35320@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
35321 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
35322 vma->vm_flags & VM_LOCKED ? 'l' : '-',
35323 vma->vm_flags & VM_IO ? 'i' : '-',
35324+#ifdef CONFIG_GRKERNSEC_HIDESYM
35325+ 0);
35326+#else
35327 vma->vm_pgoff);
35328+#endif
35329
35330 #if defined(__i386__)
35331 pgprot = pgprot_val(vma->vm_page_prot);
35332diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
35333index 2f4c434..dd12cd2 100644
35334--- a/drivers/gpu/drm/drm_ioc32.c
35335+++ b/drivers/gpu/drm/drm_ioc32.c
35336@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
35337 request = compat_alloc_user_space(nbytes);
35338 if (!access_ok(VERIFY_WRITE, request, nbytes))
35339 return -EFAULT;
35340- list = (struct drm_buf_desc *) (request + 1);
35341+ list = (struct drm_buf_desc __user *) (request + 1);
35342
35343 if (__put_user(count, &request->count)
35344 || __put_user(list, &request->list))
35345@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
35346 request = compat_alloc_user_space(nbytes);
35347 if (!access_ok(VERIFY_WRITE, request, nbytes))
35348 return -EFAULT;
35349- list = (struct drm_buf_pub *) (request + 1);
35350+ list = (struct drm_buf_pub __user *) (request + 1);
35351
35352 if (__put_user(count, &request->count)
35353 || __put_user(list, &request->list))
35354@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
35355 return 0;
35356 }
35357
35358-drm_ioctl_compat_t *drm_compat_ioctls[] = {
35359+drm_ioctl_compat_t drm_compat_ioctls[] = {
35360 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
35361 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
35362 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
35363@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
35364 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35365 {
35366 unsigned int nr = DRM_IOCTL_NR(cmd);
35367- drm_ioctl_compat_t *fn;
35368 int ret;
35369
35370 /* Assume that ioctls without an explicit compat routine will just
35371@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35372 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
35373 return drm_ioctl(filp, cmd, arg);
35374
35375- fn = drm_compat_ioctls[nr];
35376-
35377- if (fn != NULL)
35378- ret = (*fn) (filp, cmd, arg);
35379+ if (drm_compat_ioctls[nr] != NULL)
35380+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
35381 else
35382 ret = drm_ioctl(filp, cmd, arg);
35383
35384diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
35385index e77bd8b..1571b85 100644
35386--- a/drivers/gpu/drm/drm_ioctl.c
35387+++ b/drivers/gpu/drm/drm_ioctl.c
35388@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
35389 stats->data[i].value =
35390 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
35391 else
35392- stats->data[i].value = atomic_read(&dev->counts[i]);
35393+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
35394 stats->data[i].type = dev->types[i];
35395 }
35396
35397diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
35398index d752c96..fe08455 100644
35399--- a/drivers/gpu/drm/drm_lock.c
35400+++ b/drivers/gpu/drm/drm_lock.c
35401@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35402 if (drm_lock_take(&master->lock, lock->context)) {
35403 master->lock.file_priv = file_priv;
35404 master->lock.lock_time = jiffies;
35405- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
35406+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
35407 break; /* Got lock */
35408 }
35409
35410@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35411 return -EINVAL;
35412 }
35413
35414- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
35415+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
35416
35417 if (drm_lock_free(&master->lock, lock->context)) {
35418 /* FIXME: Should really bail out here. */
35419diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
35420index 7d30802..42c6cbb 100644
35421--- a/drivers/gpu/drm/drm_stub.c
35422+++ b/drivers/gpu/drm/drm_stub.c
35423@@ -501,7 +501,7 @@ void drm_unplug_dev(struct drm_device *dev)
35424
35425 drm_device_set_unplugged(dev);
35426
35427- if (dev->open_count == 0) {
35428+ if (local_read(&dev->open_count) == 0) {
35429 drm_put_dev(dev);
35430 }
35431 mutex_unlock(&drm_global_mutex);
35432diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
35433index 0229665..f61329c 100644
35434--- a/drivers/gpu/drm/drm_sysfs.c
35435+++ b/drivers/gpu/drm/drm_sysfs.c
35436@@ -499,7 +499,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
35437 int drm_sysfs_device_add(struct drm_minor *minor)
35438 {
35439 int err;
35440- char *minor_str;
35441+ const char *minor_str;
35442
35443 minor->kdev.parent = minor->dev->dev;
35444
35445diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
35446index 004ecdf..db1f6e0 100644
35447--- a/drivers/gpu/drm/i810/i810_dma.c
35448+++ b/drivers/gpu/drm/i810/i810_dma.c
35449@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
35450 dma->buflist[vertex->idx],
35451 vertex->discard, vertex->used);
35452
35453- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35454- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35455+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35456+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35457 sarea_priv->last_enqueue = dev_priv->counter - 1;
35458 sarea_priv->last_dispatch = (int)hw_status[5];
35459
35460@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35461 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35462 mc->last_render);
35463
35464- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35465- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35466+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35467+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35468 sarea_priv->last_enqueue = dev_priv->counter - 1;
35469 sarea_priv->last_dispatch = (int)hw_status[5];
35470
35471diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35472index 6e0acad..93c8289 100644
35473--- a/drivers/gpu/drm/i810/i810_drv.h
35474+++ b/drivers/gpu/drm/i810/i810_drv.h
35475@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
35476 int page_flipping;
35477
35478 wait_queue_head_t irq_queue;
35479- atomic_t irq_received;
35480- atomic_t irq_emitted;
35481+ atomic_unchecked_t irq_received;
35482+ atomic_unchecked_t irq_emitted;
35483
35484 int front_offset;
35485 } drm_i810_private_t;
35486diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35487index 7299ea4..5314487 100644
35488--- a/drivers/gpu/drm/i915/i915_debugfs.c
35489+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35490@@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35491 I915_READ(GTIMR));
35492 }
35493 seq_printf(m, "Interrupts received: %d\n",
35494- atomic_read(&dev_priv->irq_received));
35495+ atomic_read_unchecked(&dev_priv->irq_received));
35496 for_each_ring(ring, dev_priv, i) {
35497 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35498 seq_printf(m,
35499diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35500index 4fa6beb..f930fec 100644
35501--- a/drivers/gpu/drm/i915/i915_dma.c
35502+++ b/drivers/gpu/drm/i915/i915_dma.c
35503@@ -1259,7 +1259,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35504 bool can_switch;
35505
35506 spin_lock(&dev->count_lock);
35507- can_switch = (dev->open_count == 0);
35508+ can_switch = (local_read(&dev->open_count) == 0);
35509 spin_unlock(&dev->count_lock);
35510 return can_switch;
35511 }
35512diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35513index ef99b1c..09ce7fb 100644
35514--- a/drivers/gpu/drm/i915/i915_drv.h
35515+++ b/drivers/gpu/drm/i915/i915_drv.h
35516@@ -893,7 +893,7 @@ typedef struct drm_i915_private {
35517 drm_dma_handle_t *status_page_dmah;
35518 struct resource mch_res;
35519
35520- atomic_t irq_received;
35521+ atomic_unchecked_t irq_received;
35522
35523 /* protects the irq masks */
35524 spinlock_t irq_lock;
35525@@ -1775,7 +1775,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35526 struct drm_i915_private *dev_priv, unsigned port);
35527 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35528 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35529-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35530+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35531 {
35532 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35533 }
35534diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35535index 9a48e1a..f0cbc3e 100644
35536--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35537+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35538@@ -729,9 +729,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35539
35540 static int
35541 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35542- int count)
35543+ unsigned int count)
35544 {
35545- int i;
35546+ unsigned int i;
35547 int relocs_total = 0;
35548 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35549
35550@@ -1195,7 +1195,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
35551 return -ENOMEM;
35552 }
35553 ret = copy_from_user(exec2_list,
35554- (struct drm_i915_relocation_entry __user *)
35555+ (struct drm_i915_gem_exec_object2 __user *)
35556 (uintptr_t) args->buffers_ptr,
35557 sizeof(*exec2_list) * args->buffer_count);
35558 if (ret != 0) {
35559diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35560index 3c59584..500f2e9 100644
35561--- a/drivers/gpu/drm/i915/i915_ioc32.c
35562+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35563@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35564 (unsigned long)request);
35565 }
35566
35567-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35568+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35569 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35570 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35571 [DRM_I915_GETPARAM] = compat_i915_getparam,
35572@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35573 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35574 {
35575 unsigned int nr = DRM_IOCTL_NR(cmd);
35576- drm_ioctl_compat_t *fn = NULL;
35577 int ret;
35578
35579 if (nr < DRM_COMMAND_BASE)
35580 return drm_compat_ioctl(filp, cmd, arg);
35581
35582- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35583- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35584-
35585- if (fn != NULL)
35586+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35587+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35588 ret = (*fn) (filp, cmd, arg);
35589- else
35590+ } else
35591 ret = drm_ioctl(filp, cmd, arg);
35592
35593 return ret;
35594diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35595index 3c7bb04..182e049 100644
35596--- a/drivers/gpu/drm/i915/i915_irq.c
35597+++ b/drivers/gpu/drm/i915/i915_irq.c
35598@@ -549,7 +549,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35599 int pipe;
35600 u32 pipe_stats[I915_MAX_PIPES];
35601
35602- atomic_inc(&dev_priv->irq_received);
35603+ atomic_inc_unchecked(&dev_priv->irq_received);
35604
35605 while (true) {
35606 iir = I915_READ(VLV_IIR);
35607@@ -705,7 +705,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35608 irqreturn_t ret = IRQ_NONE;
35609 int i;
35610
35611- atomic_inc(&dev_priv->irq_received);
35612+ atomic_inc_unchecked(&dev_priv->irq_received);
35613
35614 /* disable master interrupt before clearing iir */
35615 de_ier = I915_READ(DEIER);
35616@@ -791,7 +791,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35617 int ret = IRQ_NONE;
35618 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
35619
35620- atomic_inc(&dev_priv->irq_received);
35621+ atomic_inc_unchecked(&dev_priv->irq_received);
35622
35623 /* disable master interrupt before clearing iir */
35624 de_ier = I915_READ(DEIER);
35625@@ -1886,7 +1886,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35626 {
35627 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35628
35629- atomic_set(&dev_priv->irq_received, 0);
35630+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35631
35632 I915_WRITE(HWSTAM, 0xeffe);
35633
35634@@ -1912,7 +1912,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35635 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35636 int pipe;
35637
35638- atomic_set(&dev_priv->irq_received, 0);
35639+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35640
35641 /* VLV magic */
35642 I915_WRITE(VLV_IMR, 0);
35643@@ -2208,7 +2208,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35644 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35645 int pipe;
35646
35647- atomic_set(&dev_priv->irq_received, 0);
35648+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35649
35650 for_each_pipe(pipe)
35651 I915_WRITE(PIPESTAT(pipe), 0);
35652@@ -2259,7 +2259,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35653 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35654 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35655
35656- atomic_inc(&dev_priv->irq_received);
35657+ atomic_inc_unchecked(&dev_priv->irq_received);
35658
35659 iir = I915_READ16(IIR);
35660 if (iir == 0)
35661@@ -2344,7 +2344,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35662 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35663 int pipe;
35664
35665- atomic_set(&dev_priv->irq_received, 0);
35666+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35667
35668 if (I915_HAS_HOTPLUG(dev)) {
35669 I915_WRITE(PORT_HOTPLUG_EN, 0);
35670@@ -2448,7 +2448,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35671 };
35672 int pipe, ret = IRQ_NONE;
35673
35674- atomic_inc(&dev_priv->irq_received);
35675+ atomic_inc_unchecked(&dev_priv->irq_received);
35676
35677 iir = I915_READ(IIR);
35678 do {
35679@@ -2574,7 +2574,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35680 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35681 int pipe;
35682
35683- atomic_set(&dev_priv->irq_received, 0);
35684+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35685
35686 I915_WRITE(PORT_HOTPLUG_EN, 0);
35687 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35688@@ -2690,7 +2690,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35689 int irq_received;
35690 int ret = IRQ_NONE, pipe;
35691
35692- atomic_inc(&dev_priv->irq_received);
35693+ atomic_inc_unchecked(&dev_priv->irq_received);
35694
35695 iir = I915_READ(IIR);
35696
35697diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35698index 2ab65b4..acbd821 100644
35699--- a/drivers/gpu/drm/i915/intel_display.c
35700+++ b/drivers/gpu/drm/i915/intel_display.c
35701@@ -8742,13 +8742,13 @@ struct intel_quirk {
35702 int subsystem_vendor;
35703 int subsystem_device;
35704 void (*hook)(struct drm_device *dev);
35705-};
35706+} __do_const;
35707
35708 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35709 struct intel_dmi_quirk {
35710 void (*hook)(struct drm_device *dev);
35711 const struct dmi_system_id (*dmi_id_list)[];
35712-};
35713+} __do_const;
35714
35715 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35716 {
35717@@ -8756,18 +8756,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35718 return 1;
35719 }
35720
35721-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35722+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35723 {
35724- .dmi_id_list = &(const struct dmi_system_id[]) {
35725- {
35726- .callback = intel_dmi_reverse_brightness,
35727- .ident = "NCR Corporation",
35728- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35729- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35730- },
35731- },
35732- { } /* terminating entry */
35733+ .callback = intel_dmi_reverse_brightness,
35734+ .ident = "NCR Corporation",
35735+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35736+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35737 },
35738+ },
35739+ { } /* terminating entry */
35740+};
35741+
35742+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35743+ {
35744+ .dmi_id_list = &intel_dmi_quirks_table,
35745 .hook = quirk_invert_brightness,
35746 },
35747 };
35748diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35749index 54558a0..2d97005 100644
35750--- a/drivers/gpu/drm/mga/mga_drv.h
35751+++ b/drivers/gpu/drm/mga/mga_drv.h
35752@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35753 u32 clear_cmd;
35754 u32 maccess;
35755
35756- atomic_t vbl_received; /**< Number of vblanks received. */
35757+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35758 wait_queue_head_t fence_queue;
35759- atomic_t last_fence_retired;
35760+ atomic_unchecked_t last_fence_retired;
35761 u32 next_fence_to_post;
35762
35763 unsigned int fb_cpp;
35764diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35765index 709e90d..89a1c0d 100644
35766--- a/drivers/gpu/drm/mga/mga_ioc32.c
35767+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35768@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35769 return 0;
35770 }
35771
35772-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35773+drm_ioctl_compat_t mga_compat_ioctls[] = {
35774 [DRM_MGA_INIT] = compat_mga_init,
35775 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35776 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35777@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35778 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35779 {
35780 unsigned int nr = DRM_IOCTL_NR(cmd);
35781- drm_ioctl_compat_t *fn = NULL;
35782 int ret;
35783
35784 if (nr < DRM_COMMAND_BASE)
35785 return drm_compat_ioctl(filp, cmd, arg);
35786
35787- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35788- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35789-
35790- if (fn != NULL)
35791+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35792+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35793 ret = (*fn) (filp, cmd, arg);
35794- else
35795+ } else
35796 ret = drm_ioctl(filp, cmd, arg);
35797
35798 return ret;
35799diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35800index 598c281..60d590e 100644
35801--- a/drivers/gpu/drm/mga/mga_irq.c
35802+++ b/drivers/gpu/drm/mga/mga_irq.c
35803@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35804 if (crtc != 0)
35805 return 0;
35806
35807- return atomic_read(&dev_priv->vbl_received);
35808+ return atomic_read_unchecked(&dev_priv->vbl_received);
35809 }
35810
35811
35812@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35813 /* VBLANK interrupt */
35814 if (status & MGA_VLINEPEN) {
35815 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35816- atomic_inc(&dev_priv->vbl_received);
35817+ atomic_inc_unchecked(&dev_priv->vbl_received);
35818 drm_handle_vblank(dev, 0);
35819 handled = 1;
35820 }
35821@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35822 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35823 MGA_WRITE(MGA_PRIMEND, prim_end);
35824
35825- atomic_inc(&dev_priv->last_fence_retired);
35826+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35827 DRM_WAKEUP(&dev_priv->fence_queue);
35828 handled = 1;
35829 }
35830@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35831 * using fences.
35832 */
35833 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35834- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35835+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35836 - *sequence) <= (1 << 23)));
35837
35838 *sequence = cur_fence;
35839diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35840index 50a6dd0..ea66ed8 100644
35841--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35842+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35843@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35844 struct bit_table {
35845 const char id;
35846 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35847-};
35848+} __no_const;
35849
35850 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35851
35852diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35853index 9c39baf..30a22be 100644
35854--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35855+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35856@@ -81,7 +81,7 @@ struct nouveau_drm {
35857 struct drm_global_reference mem_global_ref;
35858 struct ttm_bo_global_ref bo_global_ref;
35859 struct ttm_bo_device bdev;
35860- atomic_t validate_sequence;
35861+ atomic_unchecked_t validate_sequence;
35862 int (*move)(struct nouveau_channel *,
35863 struct ttm_buffer_object *,
35864 struct ttm_mem_reg *, struct ttm_mem_reg *);
35865diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35866index b4b4d0c..b7edc15 100644
35867--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35868+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35869@@ -322,7 +322,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35870 int ret, i;
35871 struct nouveau_bo *res_bo = NULL;
35872
35873- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35874+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35875 retry:
35876 if (++trycnt > 100000) {
35877 NV_ERROR(cli, "%s failed and gave up.\n", __func__);
35878@@ -359,7 +359,7 @@ retry:
35879 if (ret) {
35880 validate_fini(op, NULL);
35881 if (unlikely(ret == -EAGAIN)) {
35882- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35883+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35884 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
35885 sequence);
35886 if (!ret)
35887diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35888index 08214bc..9208577 100644
35889--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35890+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35891@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35892 unsigned long arg)
35893 {
35894 unsigned int nr = DRM_IOCTL_NR(cmd);
35895- drm_ioctl_compat_t *fn = NULL;
35896+ drm_ioctl_compat_t fn = NULL;
35897 int ret;
35898
35899 if (nr < DRM_COMMAND_BASE)
35900diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35901index 25d3495..d81aaf6 100644
35902--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35903+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35904@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35905 bool can_switch;
35906
35907 spin_lock(&dev->count_lock);
35908- can_switch = (dev->open_count == 0);
35909+ can_switch = (local_read(&dev->open_count) == 0);
35910 spin_unlock(&dev->count_lock);
35911 return can_switch;
35912 }
35913diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35914index d4660cf..70dbe65 100644
35915--- a/drivers/gpu/drm/r128/r128_cce.c
35916+++ b/drivers/gpu/drm/r128/r128_cce.c
35917@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35918
35919 /* GH: Simple idle check.
35920 */
35921- atomic_set(&dev_priv->idle_count, 0);
35922+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35923
35924 /* We don't support anything other than bus-mastering ring mode,
35925 * but the ring can be in either AGP or PCI space for the ring
35926diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35927index 930c71b..499aded 100644
35928--- a/drivers/gpu/drm/r128/r128_drv.h
35929+++ b/drivers/gpu/drm/r128/r128_drv.h
35930@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35931 int is_pci;
35932 unsigned long cce_buffers_offset;
35933
35934- atomic_t idle_count;
35935+ atomic_unchecked_t idle_count;
35936
35937 int page_flipping;
35938 int current_page;
35939 u32 crtc_offset;
35940 u32 crtc_offset_cntl;
35941
35942- atomic_t vbl_received;
35943+ atomic_unchecked_t vbl_received;
35944
35945 u32 color_fmt;
35946 unsigned int front_offset;
35947diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35948index a954c54..9cc595c 100644
35949--- a/drivers/gpu/drm/r128/r128_ioc32.c
35950+++ b/drivers/gpu/drm/r128/r128_ioc32.c
35951@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35952 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35953 }
35954
35955-drm_ioctl_compat_t *r128_compat_ioctls[] = {
35956+drm_ioctl_compat_t r128_compat_ioctls[] = {
35957 [DRM_R128_INIT] = compat_r128_init,
35958 [DRM_R128_DEPTH] = compat_r128_depth,
35959 [DRM_R128_STIPPLE] = compat_r128_stipple,
35960@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35961 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35962 {
35963 unsigned int nr = DRM_IOCTL_NR(cmd);
35964- drm_ioctl_compat_t *fn = NULL;
35965 int ret;
35966
35967 if (nr < DRM_COMMAND_BASE)
35968 return drm_compat_ioctl(filp, cmd, arg);
35969
35970- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35971- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35972-
35973- if (fn != NULL)
35974+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35975+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35976 ret = (*fn) (filp, cmd, arg);
35977- else
35978+ } else
35979 ret = drm_ioctl(filp, cmd, arg);
35980
35981 return ret;
35982diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
35983index 2ea4f09..d391371 100644
35984--- a/drivers/gpu/drm/r128/r128_irq.c
35985+++ b/drivers/gpu/drm/r128/r128_irq.c
35986@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
35987 if (crtc != 0)
35988 return 0;
35989
35990- return atomic_read(&dev_priv->vbl_received);
35991+ return atomic_read_unchecked(&dev_priv->vbl_received);
35992 }
35993
35994 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35995@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35996 /* VBLANK interrupt */
35997 if (status & R128_CRTC_VBLANK_INT) {
35998 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
35999- atomic_inc(&dev_priv->vbl_received);
36000+ atomic_inc_unchecked(&dev_priv->vbl_received);
36001 drm_handle_vblank(dev, 0);
36002 return IRQ_HANDLED;
36003 }
36004diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
36005index 19bb7e6..de7e2a2 100644
36006--- a/drivers/gpu/drm/r128/r128_state.c
36007+++ b/drivers/gpu/drm/r128/r128_state.c
36008@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
36009
36010 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
36011 {
36012- if (atomic_read(&dev_priv->idle_count) == 0)
36013+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
36014 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
36015 else
36016- atomic_set(&dev_priv->idle_count, 0);
36017+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36018 }
36019
36020 #endif
36021diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
36022index 5a82b6b..9e69c73 100644
36023--- a/drivers/gpu/drm/radeon/mkregtable.c
36024+++ b/drivers/gpu/drm/radeon/mkregtable.c
36025@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
36026 regex_t mask_rex;
36027 regmatch_t match[4];
36028 char buf[1024];
36029- size_t end;
36030+ long end;
36031 int len;
36032 int done = 0;
36033 int r;
36034 unsigned o;
36035 struct offset *offset;
36036 char last_reg_s[10];
36037- int last_reg;
36038+ unsigned long last_reg;
36039
36040 if (regcomp
36041 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
36042diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
36043index 5073665..31d15a6 100644
36044--- a/drivers/gpu/drm/radeon/radeon_device.c
36045+++ b/drivers/gpu/drm/radeon/radeon_device.c
36046@@ -976,7 +976,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
36047 bool can_switch;
36048
36049 spin_lock(&dev->count_lock);
36050- can_switch = (dev->open_count == 0);
36051+ can_switch = (local_read(&dev->open_count) == 0);
36052 spin_unlock(&dev->count_lock);
36053 return can_switch;
36054 }
36055diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
36056index b369d42..8dd04eb 100644
36057--- a/drivers/gpu/drm/radeon/radeon_drv.h
36058+++ b/drivers/gpu/drm/radeon/radeon_drv.h
36059@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
36060
36061 /* SW interrupt */
36062 wait_queue_head_t swi_queue;
36063- atomic_t swi_emitted;
36064+ atomic_unchecked_t swi_emitted;
36065 int vblank_crtc;
36066 uint32_t irq_enable_reg;
36067 uint32_t r500_disp_irq_reg;
36068diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
36069index c180df8..5fd8186 100644
36070--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
36071+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
36072@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36073 request = compat_alloc_user_space(sizeof(*request));
36074 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
36075 || __put_user(req32.param, &request->param)
36076- || __put_user((void __user *)(unsigned long)req32.value,
36077+ || __put_user((unsigned long)req32.value,
36078 &request->value))
36079 return -EFAULT;
36080
36081@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36082 #define compat_radeon_cp_setparam NULL
36083 #endif /* X86_64 || IA64 */
36084
36085-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36086+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
36087 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
36088 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
36089 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
36090@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36091 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36092 {
36093 unsigned int nr = DRM_IOCTL_NR(cmd);
36094- drm_ioctl_compat_t *fn = NULL;
36095 int ret;
36096
36097 if (nr < DRM_COMMAND_BASE)
36098 return drm_compat_ioctl(filp, cmd, arg);
36099
36100- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
36101- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36102-
36103- if (fn != NULL)
36104+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
36105+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36106 ret = (*fn) (filp, cmd, arg);
36107- else
36108+ } else
36109 ret = drm_ioctl(filp, cmd, arg);
36110
36111 return ret;
36112diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
36113index 8d68e97..9dcfed8 100644
36114--- a/drivers/gpu/drm/radeon/radeon_irq.c
36115+++ b/drivers/gpu/drm/radeon/radeon_irq.c
36116@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
36117 unsigned int ret;
36118 RING_LOCALS;
36119
36120- atomic_inc(&dev_priv->swi_emitted);
36121- ret = atomic_read(&dev_priv->swi_emitted);
36122+ atomic_inc_unchecked(&dev_priv->swi_emitted);
36123+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
36124
36125 BEGIN_RING(4);
36126 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
36127@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
36128 drm_radeon_private_t *dev_priv =
36129 (drm_radeon_private_t *) dev->dev_private;
36130
36131- atomic_set(&dev_priv->swi_emitted, 0);
36132+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
36133 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
36134
36135 dev->max_vblank_count = 0x001fffff;
36136diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
36137index 4d20910..6726b6d 100644
36138--- a/drivers/gpu/drm/radeon/radeon_state.c
36139+++ b/drivers/gpu/drm/radeon/radeon_state.c
36140@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
36141 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
36142 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
36143
36144- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36145+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36146 sarea_priv->nbox * sizeof(depth_boxes[0])))
36147 return -EFAULT;
36148
36149@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
36150 {
36151 drm_radeon_private_t *dev_priv = dev->dev_private;
36152 drm_radeon_getparam_t *param = data;
36153- int value;
36154+ int value = 0;
36155
36156 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
36157
36158diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
36159index 6c0ce89..66f6d65 100644
36160--- a/drivers/gpu/drm/radeon/radeon_ttm.c
36161+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
36162@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
36163 man->size = size >> PAGE_SHIFT;
36164 }
36165
36166-static struct vm_operations_struct radeon_ttm_vm_ops;
36167+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
36168 static const struct vm_operations_struct *ttm_vm_ops = NULL;
36169
36170 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36171@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
36172 }
36173 if (unlikely(ttm_vm_ops == NULL)) {
36174 ttm_vm_ops = vma->vm_ops;
36175+ pax_open_kernel();
36176 radeon_ttm_vm_ops = *ttm_vm_ops;
36177 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
36178+ pax_close_kernel();
36179 }
36180 vma->vm_ops = &radeon_ttm_vm_ops;
36181 return 0;
36182@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
36183 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
36184 else
36185 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
36186- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36187- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36188- radeon_mem_types_list[i].driver_features = 0;
36189+ pax_open_kernel();
36190+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36191+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36192+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36193 if (i == 0)
36194- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36195+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36196 else
36197- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36198-
36199+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36200+ pax_close_kernel();
36201 }
36202 /* Add ttm page pool to debugfs */
36203 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
36204- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36205- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36206- radeon_mem_types_list[i].driver_features = 0;
36207- radeon_mem_types_list[i++].data = NULL;
36208+ pax_open_kernel();
36209+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36210+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36211+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36212+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36213+ pax_close_kernel();
36214 #ifdef CONFIG_SWIOTLB
36215 if (swiotlb_nr_tbl()) {
36216 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
36217- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36218- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36219- radeon_mem_types_list[i].driver_features = 0;
36220- radeon_mem_types_list[i++].data = NULL;
36221+ pax_open_kernel();
36222+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36223+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36224+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36225+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36226+ pax_close_kernel();
36227 }
36228 #endif
36229 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
36230diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
36231index fad6633..4ff94de 100644
36232--- a/drivers/gpu/drm/radeon/rs690.c
36233+++ b/drivers/gpu/drm/radeon/rs690.c
36234@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
36235 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
36236 rdev->pm.sideport_bandwidth.full)
36237 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
36238- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
36239+ read_delay_latency.full = dfixed_const(800 * 1000);
36240 read_delay_latency.full = dfixed_div(read_delay_latency,
36241 rdev->pm.igp_sideport_mclk);
36242+ a.full = dfixed_const(370);
36243+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
36244 } else {
36245 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
36246 rdev->pm.k8_bandwidth.full)
36247diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
36248index dbc2def..0a9f710 100644
36249--- a/drivers/gpu/drm/ttm/ttm_memory.c
36250+++ b/drivers/gpu/drm/ttm/ttm_memory.c
36251@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
36252 zone->glob = glob;
36253 glob->zone_kernel = zone;
36254 ret = kobject_init_and_add(
36255- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
36256+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
36257 if (unlikely(ret != 0)) {
36258 kobject_put(&zone->kobj);
36259 return ret;
36260@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
36261 zone->glob = glob;
36262 glob->zone_dma32 = zone;
36263 ret = kobject_init_and_add(
36264- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
36265+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
36266 if (unlikely(ret != 0)) {
36267 kobject_put(&zone->kobj);
36268 return ret;
36269diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36270index bd2a3b4..122d9ad 100644
36271--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
36272+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36273@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
36274 static int ttm_pool_mm_shrink(struct shrinker *shrink,
36275 struct shrink_control *sc)
36276 {
36277- static atomic_t start_pool = ATOMIC_INIT(0);
36278+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
36279 unsigned i;
36280- unsigned pool_offset = atomic_add_return(1, &start_pool);
36281+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
36282 struct ttm_page_pool *pool;
36283 int shrink_pages = sc->nr_to_scan;
36284
36285diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
36286index 9f4be3d..cbc9fcc 100644
36287--- a/drivers/gpu/drm/udl/udl_fb.c
36288+++ b/drivers/gpu/drm/udl/udl_fb.c
36289@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
36290 fb_deferred_io_cleanup(info);
36291 kfree(info->fbdefio);
36292 info->fbdefio = NULL;
36293- info->fbops->fb_mmap = udl_fb_mmap;
36294 }
36295
36296 pr_warn("released /dev/fb%d user=%d count=%d\n",
36297diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
36298index 893a650..6190d3b 100644
36299--- a/drivers/gpu/drm/via/via_drv.h
36300+++ b/drivers/gpu/drm/via/via_drv.h
36301@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
36302 typedef uint32_t maskarray_t[5];
36303
36304 typedef struct drm_via_irq {
36305- atomic_t irq_received;
36306+ atomic_unchecked_t irq_received;
36307 uint32_t pending_mask;
36308 uint32_t enable_mask;
36309 wait_queue_head_t irq_queue;
36310@@ -75,7 +75,7 @@ typedef struct drm_via_private {
36311 struct timeval last_vblank;
36312 int last_vblank_valid;
36313 unsigned usec_per_vblank;
36314- atomic_t vbl_received;
36315+ atomic_unchecked_t vbl_received;
36316 drm_via_state_t hc_state;
36317 char pci_buf[VIA_PCI_BUF_SIZE];
36318 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
36319diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
36320index ac98964..5dbf512 100644
36321--- a/drivers/gpu/drm/via/via_irq.c
36322+++ b/drivers/gpu/drm/via/via_irq.c
36323@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
36324 if (crtc != 0)
36325 return 0;
36326
36327- return atomic_read(&dev_priv->vbl_received);
36328+ return atomic_read_unchecked(&dev_priv->vbl_received);
36329 }
36330
36331 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36332@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36333
36334 status = VIA_READ(VIA_REG_INTERRUPT);
36335 if (status & VIA_IRQ_VBLANK_PENDING) {
36336- atomic_inc(&dev_priv->vbl_received);
36337- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
36338+ atomic_inc_unchecked(&dev_priv->vbl_received);
36339+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
36340 do_gettimeofday(&cur_vblank);
36341 if (dev_priv->last_vblank_valid) {
36342 dev_priv->usec_per_vblank =
36343@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36344 dev_priv->last_vblank = cur_vblank;
36345 dev_priv->last_vblank_valid = 1;
36346 }
36347- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
36348+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
36349 DRM_DEBUG("US per vblank is: %u\n",
36350 dev_priv->usec_per_vblank);
36351 }
36352@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36353
36354 for (i = 0; i < dev_priv->num_irqs; ++i) {
36355 if (status & cur_irq->pending_mask) {
36356- atomic_inc(&cur_irq->irq_received);
36357+ atomic_inc_unchecked(&cur_irq->irq_received);
36358 DRM_WAKEUP(&cur_irq->irq_queue);
36359 handled = 1;
36360 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
36361@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
36362 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36363 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
36364 masks[irq][4]));
36365- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
36366+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
36367 } else {
36368 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36369 (((cur_irq_sequence =
36370- atomic_read(&cur_irq->irq_received)) -
36371+ atomic_read_unchecked(&cur_irq->irq_received)) -
36372 *sequence) <= (1 << 23)));
36373 }
36374 *sequence = cur_irq_sequence;
36375@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
36376 }
36377
36378 for (i = 0; i < dev_priv->num_irqs; ++i) {
36379- atomic_set(&cur_irq->irq_received, 0);
36380+ atomic_set_unchecked(&cur_irq->irq_received, 0);
36381 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
36382 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
36383 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
36384@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
36385 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
36386 case VIA_IRQ_RELATIVE:
36387 irqwait->request.sequence +=
36388- atomic_read(&cur_irq->irq_received);
36389+ atomic_read_unchecked(&cur_irq->irq_received);
36390 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
36391 case VIA_IRQ_ABSOLUTE:
36392 break;
36393diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36394index 13aeda7..4a952d1 100644
36395--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36396+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36397@@ -290,7 +290,7 @@ struct vmw_private {
36398 * Fencing and IRQs.
36399 */
36400
36401- atomic_t marker_seq;
36402+ atomic_unchecked_t marker_seq;
36403 wait_queue_head_t fence_queue;
36404 wait_queue_head_t fifo_queue;
36405 int fence_queue_waiters; /* Protected by hw_mutex */
36406diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36407index 3eb1486..0a47ee9 100644
36408--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36409+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36410@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
36411 (unsigned int) min,
36412 (unsigned int) fifo->capabilities);
36413
36414- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36415+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36416 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
36417 vmw_marker_queue_init(&fifo->marker_queue);
36418 return vmw_fifo_send_fence(dev_priv, &dummy);
36419@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
36420 if (reserveable)
36421 iowrite32(bytes, fifo_mem +
36422 SVGA_FIFO_RESERVED);
36423- return fifo_mem + (next_cmd >> 2);
36424+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36425 } else {
36426 need_bounce = true;
36427 }
36428@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36429
36430 fm = vmw_fifo_reserve(dev_priv, bytes);
36431 if (unlikely(fm == NULL)) {
36432- *seqno = atomic_read(&dev_priv->marker_seq);
36433+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36434 ret = -ENOMEM;
36435 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36436 false, 3*HZ);
36437@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36438 }
36439
36440 do {
36441- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36442+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36443 } while (*seqno == 0);
36444
36445 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36446diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36447index c509d40..3b640c3 100644
36448--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36449+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36450@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
36451 int ret;
36452
36453 num_clips = arg->num_clips;
36454- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36455+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36456
36457 if (unlikely(num_clips == 0))
36458 return 0;
36459@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
36460 int ret;
36461
36462 num_clips = arg->num_clips;
36463- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36464+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36465
36466 if (unlikely(num_clips == 0))
36467 return 0;
36468diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36469index 4640adb..e1384ed 100644
36470--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36471+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36472@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36473 * emitted. Then the fence is stale and signaled.
36474 */
36475
36476- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36477+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36478 > VMW_FENCE_WRAP);
36479
36480 return ret;
36481@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36482
36483 if (fifo_idle)
36484 down_read(&fifo_state->rwsem);
36485- signal_seq = atomic_read(&dev_priv->marker_seq);
36486+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36487 ret = 0;
36488
36489 for (;;) {
36490diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36491index 8a8725c2..afed796 100644
36492--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36493+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36494@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36495 while (!vmw_lag_lt(queue, us)) {
36496 spin_lock(&queue->lock);
36497 if (list_empty(&queue->head))
36498- seqno = atomic_read(&dev_priv->marker_seq);
36499+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36500 else {
36501 marker = list_first_entry(&queue->head,
36502 struct vmw_marker, head);
36503diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36504index e6dbf09..3dd2540 100644
36505--- a/drivers/hid/hid-core.c
36506+++ b/drivers/hid/hid-core.c
36507@@ -2268,7 +2268,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36508
36509 int hid_add_device(struct hid_device *hdev)
36510 {
36511- static atomic_t id = ATOMIC_INIT(0);
36512+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36513 int ret;
36514
36515 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36516@@ -2302,7 +2302,7 @@ int hid_add_device(struct hid_device *hdev)
36517 /* XXX hack, any other cleaner solution after the driver core
36518 * is converted to allow more than 20 bytes as the device name? */
36519 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36520- hdev->vendor, hdev->product, atomic_inc_return(&id));
36521+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36522
36523 hid_debug_register(hdev, dev_name(&hdev->dev));
36524 ret = device_add(&hdev->dev);
36525diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36526index 90124ff..3761764 100644
36527--- a/drivers/hid/hid-wiimote-debug.c
36528+++ b/drivers/hid/hid-wiimote-debug.c
36529@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36530 else if (size == 0)
36531 return -EIO;
36532
36533- if (copy_to_user(u, buf, size))
36534+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36535 return -EFAULT;
36536
36537 *off += size;
36538diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36539index 0b122f8..b1d8160 100644
36540--- a/drivers/hv/channel.c
36541+++ b/drivers/hv/channel.c
36542@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36543 int ret = 0;
36544 int t;
36545
36546- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36547- atomic_inc(&vmbus_connection.next_gpadl_handle);
36548+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36549+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36550
36551 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36552 if (ret)
36553diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36554index 7311589..861e9ef 100644
36555--- a/drivers/hv/hv.c
36556+++ b/drivers/hv/hv.c
36557@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36558 u64 output_address = (output) ? virt_to_phys(output) : 0;
36559 u32 output_address_hi = output_address >> 32;
36560 u32 output_address_lo = output_address & 0xFFFFFFFF;
36561- void *hypercall_page = hv_context.hypercall_page;
36562+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36563
36564 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36565 "=a"(hv_status_lo) : "d" (control_hi),
36566diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36567index 12f2f9e..679603c 100644
36568--- a/drivers/hv/hyperv_vmbus.h
36569+++ b/drivers/hv/hyperv_vmbus.h
36570@@ -591,7 +591,7 @@ enum vmbus_connect_state {
36571 struct vmbus_connection {
36572 enum vmbus_connect_state conn_state;
36573
36574- atomic_t next_gpadl_handle;
36575+ atomic_unchecked_t next_gpadl_handle;
36576
36577 /*
36578 * Represents channel interrupts. Each bit position represents a
36579diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36580index bf421e0..ce2c897 100644
36581--- a/drivers/hv/vmbus_drv.c
36582+++ b/drivers/hv/vmbus_drv.c
36583@@ -668,10 +668,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36584 {
36585 int ret = 0;
36586
36587- static atomic_t device_num = ATOMIC_INIT(0);
36588+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36589
36590 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36591- atomic_inc_return(&device_num));
36592+ atomic_inc_return_unchecked(&device_num));
36593
36594 child_device_obj->device.bus = &hv_bus;
36595 child_device_obj->device.parent = &hv_acpi_dev->dev;
36596diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36597index 6351aba..dc4aaf4 100644
36598--- a/drivers/hwmon/acpi_power_meter.c
36599+++ b/drivers/hwmon/acpi_power_meter.c
36600@@ -117,7 +117,7 @@ struct sensor_template {
36601 struct device_attribute *devattr,
36602 const char *buf, size_t count);
36603 int index;
36604-};
36605+} __do_const;
36606
36607 /* Averaging interval */
36608 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36609@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36610 struct sensor_template *attrs)
36611 {
36612 struct device *dev = &resource->acpi_dev->dev;
36613- struct sensor_device_attribute *sensors =
36614+ sensor_device_attribute_no_const *sensors =
36615 &resource->sensors[resource->num_sensors];
36616 int res = 0;
36617
36618diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36619index b41baff..4953e4d 100644
36620--- a/drivers/hwmon/applesmc.c
36621+++ b/drivers/hwmon/applesmc.c
36622@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36623 {
36624 struct applesmc_node_group *grp;
36625 struct applesmc_dev_attr *node;
36626- struct attribute *attr;
36627+ attribute_no_const *attr;
36628 int ret, i;
36629
36630 for (grp = groups; grp->format; grp++) {
36631diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36632index b25c643..a13460d 100644
36633--- a/drivers/hwmon/asus_atk0110.c
36634+++ b/drivers/hwmon/asus_atk0110.c
36635@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36636 struct atk_sensor_data {
36637 struct list_head list;
36638 struct atk_data *data;
36639- struct device_attribute label_attr;
36640- struct device_attribute input_attr;
36641- struct device_attribute limit1_attr;
36642- struct device_attribute limit2_attr;
36643+ device_attribute_no_const label_attr;
36644+ device_attribute_no_const input_attr;
36645+ device_attribute_no_const limit1_attr;
36646+ device_attribute_no_const limit2_attr;
36647 char label_attr_name[ATTR_NAME_SIZE];
36648 char input_attr_name[ATTR_NAME_SIZE];
36649 char limit1_attr_name[ATTR_NAME_SIZE];
36650@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36651 static struct device_attribute atk_name_attr =
36652 __ATTR(name, 0444, atk_name_show, NULL);
36653
36654-static void atk_init_attribute(struct device_attribute *attr, char *name,
36655+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36656 sysfs_show_func show)
36657 {
36658 sysfs_attr_init(&attr->attr);
36659diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36660index 3f1e297..a6cafb5 100644
36661--- a/drivers/hwmon/coretemp.c
36662+++ b/drivers/hwmon/coretemp.c
36663@@ -791,7 +791,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36664 return NOTIFY_OK;
36665 }
36666
36667-static struct notifier_block coretemp_cpu_notifier __refdata = {
36668+static struct notifier_block coretemp_cpu_notifier = {
36669 .notifier_call = coretemp_cpu_callback,
36670 };
36671
36672diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36673index a14f634..2916ee2 100644
36674--- a/drivers/hwmon/ibmaem.c
36675+++ b/drivers/hwmon/ibmaem.c
36676@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
36677 struct aem_rw_sensor_template *rw)
36678 {
36679 struct device *dev = &data->pdev->dev;
36680- struct sensor_device_attribute *sensors = data->sensors;
36681+ sensor_device_attribute_no_const *sensors = data->sensors;
36682 int err;
36683
36684 /* Set up read-only sensors */
36685diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36686index 9add6092..ee7ba3f 100644
36687--- a/drivers/hwmon/pmbus/pmbus_core.c
36688+++ b/drivers/hwmon/pmbus/pmbus_core.c
36689@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
36690 return 0;
36691 }
36692
36693-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36694+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
36695 const char *name,
36696 umode_t mode,
36697 ssize_t (*show)(struct device *dev,
36698@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36699 dev_attr->store = store;
36700 }
36701
36702-static void pmbus_attr_init(struct sensor_device_attribute *a,
36703+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
36704 const char *name,
36705 umode_t mode,
36706 ssize_t (*show)(struct device *dev,
36707@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
36708 u16 reg, u8 mask)
36709 {
36710 struct pmbus_boolean *boolean;
36711- struct sensor_device_attribute *a;
36712+ sensor_device_attribute_no_const *a;
36713
36714 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
36715 if (!boolean)
36716@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
36717 bool update, bool readonly)
36718 {
36719 struct pmbus_sensor *sensor;
36720- struct device_attribute *a;
36721+ device_attribute_no_const *a;
36722
36723 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
36724 if (!sensor)
36725@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
36726 const char *lstring, int index)
36727 {
36728 struct pmbus_label *label;
36729- struct device_attribute *a;
36730+ device_attribute_no_const *a;
36731
36732 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
36733 if (!label)
36734diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36735index 2507f90..1645765 100644
36736--- a/drivers/hwmon/sht15.c
36737+++ b/drivers/hwmon/sht15.c
36738@@ -169,7 +169,7 @@ struct sht15_data {
36739 int supply_uv;
36740 bool supply_uv_valid;
36741 struct work_struct update_supply_work;
36742- atomic_t interrupt_handled;
36743+ atomic_unchecked_t interrupt_handled;
36744 };
36745
36746 /**
36747@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
36748 ret = gpio_direction_input(data->pdata->gpio_data);
36749 if (ret)
36750 return ret;
36751- atomic_set(&data->interrupt_handled, 0);
36752+ atomic_set_unchecked(&data->interrupt_handled, 0);
36753
36754 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36755 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36756 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36757 /* Only relevant if the interrupt hasn't occurred. */
36758- if (!atomic_read(&data->interrupt_handled))
36759+ if (!atomic_read_unchecked(&data->interrupt_handled))
36760 schedule_work(&data->read_work);
36761 }
36762 ret = wait_event_timeout(data->wait_queue,
36763@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36764
36765 /* First disable the interrupt */
36766 disable_irq_nosync(irq);
36767- atomic_inc(&data->interrupt_handled);
36768+ atomic_inc_unchecked(&data->interrupt_handled);
36769 /* Then schedule a reading work struct */
36770 if (data->state != SHT15_READING_NOTHING)
36771 schedule_work(&data->read_work);
36772@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36773 * If not, then start the interrupt again - care here as could
36774 * have gone low in meantime so verify it hasn't!
36775 */
36776- atomic_set(&data->interrupt_handled, 0);
36777+ atomic_set_unchecked(&data->interrupt_handled, 0);
36778 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36779 /* If still not occurred or another handler was scheduled */
36780 if (gpio_get_value(data->pdata->gpio_data)
36781- || atomic_read(&data->interrupt_handled))
36782+ || atomic_read_unchecked(&data->interrupt_handled))
36783 return;
36784 }
36785
36786diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36787index 76f157b..9c0db1b 100644
36788--- a/drivers/hwmon/via-cputemp.c
36789+++ b/drivers/hwmon/via-cputemp.c
36790@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36791 return NOTIFY_OK;
36792 }
36793
36794-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36795+static struct notifier_block via_cputemp_cpu_notifier = {
36796 .notifier_call = via_cputemp_cpu_callback,
36797 };
36798
36799diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36800index 378fcb5..5e91fa8 100644
36801--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36802+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36803@@ -43,7 +43,7 @@
36804 extern struct i2c_adapter amd756_smbus;
36805
36806 static struct i2c_adapter *s4882_adapter;
36807-static struct i2c_algorithm *s4882_algo;
36808+static i2c_algorithm_no_const *s4882_algo;
36809
36810 /* Wrapper access functions for multiplexed SMBus */
36811 static DEFINE_MUTEX(amd756_lock);
36812diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36813index 29015eb..af2d8e9 100644
36814--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36815+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36816@@ -41,7 +41,7 @@
36817 extern struct i2c_adapter *nforce2_smbus;
36818
36819 static struct i2c_adapter *s4985_adapter;
36820-static struct i2c_algorithm *s4985_algo;
36821+static i2c_algorithm_no_const *s4985_algo;
36822
36823 /* Wrapper access functions for multiplexed SMBus */
36824 static DEFINE_MUTEX(nforce2_lock);
36825diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
36826index c3ccdea..5b3dc1a 100644
36827--- a/drivers/i2c/i2c-dev.c
36828+++ b/drivers/i2c/i2c-dev.c
36829@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
36830 break;
36831 }
36832
36833- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
36834+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
36835 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
36836 if (IS_ERR(rdwr_pa[i].buf)) {
36837 res = PTR_ERR(rdwr_pa[i].buf);
36838diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36839index 8126824..55a2798 100644
36840--- a/drivers/ide/ide-cd.c
36841+++ b/drivers/ide/ide-cd.c
36842@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36843 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36844 if ((unsigned long)buf & alignment
36845 || blk_rq_bytes(rq) & q->dma_pad_mask
36846- || object_is_on_stack(buf))
36847+ || object_starts_on_stack(buf))
36848 drive->dma = 0;
36849 }
36850 }
36851diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36852index 8848f16..f8e6dd8 100644
36853--- a/drivers/iio/industrialio-core.c
36854+++ b/drivers/iio/industrialio-core.c
36855@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36856 }
36857
36858 static
36859-int __iio_device_attr_init(struct device_attribute *dev_attr,
36860+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36861 const char *postfix,
36862 struct iio_chan_spec const *chan,
36863 ssize_t (*readfunc)(struct device *dev,
36864diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36865index 784b97c..c9ceadf 100644
36866--- a/drivers/infiniband/core/cm.c
36867+++ b/drivers/infiniband/core/cm.c
36868@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36869
36870 struct cm_counter_group {
36871 struct kobject obj;
36872- atomic_long_t counter[CM_ATTR_COUNT];
36873+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36874 };
36875
36876 struct cm_counter_attribute {
36877@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36878 struct ib_mad_send_buf *msg = NULL;
36879 int ret;
36880
36881- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36882+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36883 counter[CM_REQ_COUNTER]);
36884
36885 /* Quick state check to discard duplicate REQs. */
36886@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36887 if (!cm_id_priv)
36888 return;
36889
36890- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36891+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36892 counter[CM_REP_COUNTER]);
36893 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36894 if (ret)
36895@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
36896 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36897 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36898 spin_unlock_irq(&cm_id_priv->lock);
36899- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36900+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36901 counter[CM_RTU_COUNTER]);
36902 goto out;
36903 }
36904@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
36905 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36906 dreq_msg->local_comm_id);
36907 if (!cm_id_priv) {
36908- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36909+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36910 counter[CM_DREQ_COUNTER]);
36911 cm_issue_drep(work->port, work->mad_recv_wc);
36912 return -EINVAL;
36913@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
36914 case IB_CM_MRA_REP_RCVD:
36915 break;
36916 case IB_CM_TIMEWAIT:
36917- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36918+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36919 counter[CM_DREQ_COUNTER]);
36920 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36921 goto unlock;
36922@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
36923 cm_free_msg(msg);
36924 goto deref;
36925 case IB_CM_DREQ_RCVD:
36926- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36927+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36928 counter[CM_DREQ_COUNTER]);
36929 goto unlock;
36930 default:
36931@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
36932 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36933 cm_id_priv->msg, timeout)) {
36934 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36935- atomic_long_inc(&work->port->
36936+ atomic_long_inc_unchecked(&work->port->
36937 counter_group[CM_RECV_DUPLICATES].
36938 counter[CM_MRA_COUNTER]);
36939 goto out;
36940@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
36941 break;
36942 case IB_CM_MRA_REQ_RCVD:
36943 case IB_CM_MRA_REP_RCVD:
36944- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36945+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36946 counter[CM_MRA_COUNTER]);
36947 /* fall through */
36948 default:
36949@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
36950 case IB_CM_LAP_IDLE:
36951 break;
36952 case IB_CM_MRA_LAP_SENT:
36953- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36954+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36955 counter[CM_LAP_COUNTER]);
36956 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36957 goto unlock;
36958@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
36959 cm_free_msg(msg);
36960 goto deref;
36961 case IB_CM_LAP_RCVD:
36962- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36963+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36964 counter[CM_LAP_COUNTER]);
36965 goto unlock;
36966 default:
36967@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36968 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36969 if (cur_cm_id_priv) {
36970 spin_unlock_irq(&cm.lock);
36971- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36972+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36973 counter[CM_SIDR_REQ_COUNTER]);
36974 goto out; /* Duplicate message. */
36975 }
36976@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36977 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36978 msg->retries = 1;
36979
36980- atomic_long_add(1 + msg->retries,
36981+ atomic_long_add_unchecked(1 + msg->retries,
36982 &port->counter_group[CM_XMIT].counter[attr_index]);
36983 if (msg->retries)
36984- atomic_long_add(msg->retries,
36985+ atomic_long_add_unchecked(msg->retries,
36986 &port->counter_group[CM_XMIT_RETRIES].
36987 counter[attr_index]);
36988
36989@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36990 }
36991
36992 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36993- atomic_long_inc(&port->counter_group[CM_RECV].
36994+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36995 counter[attr_id - CM_ATTR_ID_OFFSET]);
36996
36997 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36998@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36999 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
37000
37001 return sprintf(buf, "%ld\n",
37002- atomic_long_read(&group->counter[cm_attr->index]));
37003+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
37004 }
37005
37006 static const struct sysfs_ops cm_counter_ops = {
37007diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
37008index 9f5ad7c..588cd84 100644
37009--- a/drivers/infiniband/core/fmr_pool.c
37010+++ b/drivers/infiniband/core/fmr_pool.c
37011@@ -98,8 +98,8 @@ struct ib_fmr_pool {
37012
37013 struct task_struct *thread;
37014
37015- atomic_t req_ser;
37016- atomic_t flush_ser;
37017+ atomic_unchecked_t req_ser;
37018+ atomic_unchecked_t flush_ser;
37019
37020 wait_queue_head_t force_wait;
37021 };
37022@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37023 struct ib_fmr_pool *pool = pool_ptr;
37024
37025 do {
37026- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
37027+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
37028 ib_fmr_batch_release(pool);
37029
37030- atomic_inc(&pool->flush_ser);
37031+ atomic_inc_unchecked(&pool->flush_ser);
37032 wake_up_interruptible(&pool->force_wait);
37033
37034 if (pool->flush_function)
37035@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37036 }
37037
37038 set_current_state(TASK_INTERRUPTIBLE);
37039- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
37040+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
37041 !kthread_should_stop())
37042 schedule();
37043 __set_current_state(TASK_RUNNING);
37044@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
37045 pool->dirty_watermark = params->dirty_watermark;
37046 pool->dirty_len = 0;
37047 spin_lock_init(&pool->pool_lock);
37048- atomic_set(&pool->req_ser, 0);
37049- atomic_set(&pool->flush_ser, 0);
37050+ atomic_set_unchecked(&pool->req_ser, 0);
37051+ atomic_set_unchecked(&pool->flush_ser, 0);
37052 init_waitqueue_head(&pool->force_wait);
37053
37054 pool->thread = kthread_run(ib_fmr_cleanup_thread,
37055@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
37056 }
37057 spin_unlock_irq(&pool->pool_lock);
37058
37059- serial = atomic_inc_return(&pool->req_ser);
37060+ serial = atomic_inc_return_unchecked(&pool->req_ser);
37061 wake_up_process(pool->thread);
37062
37063 if (wait_event_interruptible(pool->force_wait,
37064- atomic_read(&pool->flush_ser) - serial >= 0))
37065+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
37066 return -EINTR;
37067
37068 return 0;
37069@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
37070 } else {
37071 list_add_tail(&fmr->list, &pool->dirty_list);
37072 if (++pool->dirty_len >= pool->dirty_watermark) {
37073- atomic_inc(&pool->req_ser);
37074+ atomic_inc_unchecked(&pool->req_ser);
37075 wake_up_process(pool->thread);
37076 }
37077 }
37078diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
37079index 903a92d..9262548 100644
37080--- a/drivers/infiniband/hw/cxgb4/mem.c
37081+++ b/drivers/infiniband/hw/cxgb4/mem.c
37082@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37083 int err;
37084 struct fw_ri_tpte tpt;
37085 u32 stag_idx;
37086- static atomic_t key;
37087+ static atomic_unchecked_t key;
37088
37089 if (c4iw_fatal_error(rdev))
37090 return -EIO;
37091@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37092 if (rdev->stats.stag.cur > rdev->stats.stag.max)
37093 rdev->stats.stag.max = rdev->stats.stag.cur;
37094 mutex_unlock(&rdev->stats.lock);
37095- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
37096+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
37097 }
37098 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
37099 __func__, stag_state, type, pdid, stag_idx);
37100diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
37101index 79b3dbc..96e5fcc 100644
37102--- a/drivers/infiniband/hw/ipath/ipath_rc.c
37103+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
37104@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37105 struct ib_atomic_eth *ateth;
37106 struct ipath_ack_entry *e;
37107 u64 vaddr;
37108- atomic64_t *maddr;
37109+ atomic64_unchecked_t *maddr;
37110 u64 sdata;
37111 u32 rkey;
37112 u8 next;
37113@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37114 IB_ACCESS_REMOTE_ATOMIC)))
37115 goto nack_acc_unlck;
37116 /* Perform atomic OP and save result. */
37117- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37118+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37119 sdata = be64_to_cpu(ateth->swap_data);
37120 e = &qp->s_ack_queue[qp->r_head_ack_queue];
37121 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
37122- (u64) atomic64_add_return(sdata, maddr) - sdata :
37123+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37124 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37125 be64_to_cpu(ateth->compare_data),
37126 sdata);
37127diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
37128index 1f95bba..9530f87 100644
37129--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
37130+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
37131@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
37132 unsigned long flags;
37133 struct ib_wc wc;
37134 u64 sdata;
37135- atomic64_t *maddr;
37136+ atomic64_unchecked_t *maddr;
37137 enum ib_wc_status send_status;
37138
37139 /*
37140@@ -382,11 +382,11 @@ again:
37141 IB_ACCESS_REMOTE_ATOMIC)))
37142 goto acc_err;
37143 /* Perform atomic OP and save result. */
37144- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37145+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37146 sdata = wqe->wr.wr.atomic.compare_add;
37147 *(u64 *) sqp->s_sge.sge.vaddr =
37148 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
37149- (u64) atomic64_add_return(sdata, maddr) - sdata :
37150+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37151 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37152 sdata, wqe->wr.wr.atomic.swap);
37153 goto send_comp;
37154diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
37155index 9d3e5c1..d9afe4a 100644
37156--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
37157+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
37158@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
37159 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
37160 }
37161
37162-int mthca_QUERY_FW(struct mthca_dev *dev)
37163+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
37164 {
37165 struct mthca_mailbox *mailbox;
37166 u32 *outbox;
37167diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
37168index ed9a989..e0c5871 100644
37169--- a/drivers/infiniband/hw/mthca/mthca_mr.c
37170+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
37171@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
37172 return key;
37173 }
37174
37175-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37176+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37177 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
37178 {
37179 struct mthca_mailbox *mailbox;
37180diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
37181index 4291410..d2ab1fb 100644
37182--- a/drivers/infiniband/hw/nes/nes.c
37183+++ b/drivers/infiniband/hw/nes/nes.c
37184@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
37185 LIST_HEAD(nes_adapter_list);
37186 static LIST_HEAD(nes_dev_list);
37187
37188-atomic_t qps_destroyed;
37189+atomic_unchecked_t qps_destroyed;
37190
37191 static unsigned int ee_flsh_adapter;
37192 static unsigned int sysfs_nonidx_addr;
37193@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
37194 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
37195 struct nes_adapter *nesadapter = nesdev->nesadapter;
37196
37197- atomic_inc(&qps_destroyed);
37198+ atomic_inc_unchecked(&qps_destroyed);
37199
37200 /* Free the control structures */
37201
37202diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
37203index 33cc589..3bd6538 100644
37204--- a/drivers/infiniband/hw/nes/nes.h
37205+++ b/drivers/infiniband/hw/nes/nes.h
37206@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
37207 extern unsigned int wqm_quanta;
37208 extern struct list_head nes_adapter_list;
37209
37210-extern atomic_t cm_connects;
37211-extern atomic_t cm_accepts;
37212-extern atomic_t cm_disconnects;
37213-extern atomic_t cm_closes;
37214-extern atomic_t cm_connecteds;
37215-extern atomic_t cm_connect_reqs;
37216-extern atomic_t cm_rejects;
37217-extern atomic_t mod_qp_timouts;
37218-extern atomic_t qps_created;
37219-extern atomic_t qps_destroyed;
37220-extern atomic_t sw_qps_destroyed;
37221+extern atomic_unchecked_t cm_connects;
37222+extern atomic_unchecked_t cm_accepts;
37223+extern atomic_unchecked_t cm_disconnects;
37224+extern atomic_unchecked_t cm_closes;
37225+extern atomic_unchecked_t cm_connecteds;
37226+extern atomic_unchecked_t cm_connect_reqs;
37227+extern atomic_unchecked_t cm_rejects;
37228+extern atomic_unchecked_t mod_qp_timouts;
37229+extern atomic_unchecked_t qps_created;
37230+extern atomic_unchecked_t qps_destroyed;
37231+extern atomic_unchecked_t sw_qps_destroyed;
37232 extern u32 mh_detected;
37233 extern u32 mh_pauses_sent;
37234 extern u32 cm_packets_sent;
37235@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
37236 extern u32 cm_packets_received;
37237 extern u32 cm_packets_dropped;
37238 extern u32 cm_packets_retrans;
37239-extern atomic_t cm_listens_created;
37240-extern atomic_t cm_listens_destroyed;
37241+extern atomic_unchecked_t cm_listens_created;
37242+extern atomic_unchecked_t cm_listens_destroyed;
37243 extern u32 cm_backlog_drops;
37244-extern atomic_t cm_loopbacks;
37245-extern atomic_t cm_nodes_created;
37246-extern atomic_t cm_nodes_destroyed;
37247-extern atomic_t cm_accel_dropped_pkts;
37248-extern atomic_t cm_resets_recvd;
37249-extern atomic_t pau_qps_created;
37250-extern atomic_t pau_qps_destroyed;
37251+extern atomic_unchecked_t cm_loopbacks;
37252+extern atomic_unchecked_t cm_nodes_created;
37253+extern atomic_unchecked_t cm_nodes_destroyed;
37254+extern atomic_unchecked_t cm_accel_dropped_pkts;
37255+extern atomic_unchecked_t cm_resets_recvd;
37256+extern atomic_unchecked_t pau_qps_created;
37257+extern atomic_unchecked_t pau_qps_destroyed;
37258
37259 extern u32 int_mod_timer_init;
37260 extern u32 int_mod_cq_depth_256;
37261diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
37262index 24b9f1a..00fd004 100644
37263--- a/drivers/infiniband/hw/nes/nes_cm.c
37264+++ b/drivers/infiniband/hw/nes/nes_cm.c
37265@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
37266 u32 cm_packets_retrans;
37267 u32 cm_packets_created;
37268 u32 cm_packets_received;
37269-atomic_t cm_listens_created;
37270-atomic_t cm_listens_destroyed;
37271+atomic_unchecked_t cm_listens_created;
37272+atomic_unchecked_t cm_listens_destroyed;
37273 u32 cm_backlog_drops;
37274-atomic_t cm_loopbacks;
37275-atomic_t cm_nodes_created;
37276-atomic_t cm_nodes_destroyed;
37277-atomic_t cm_accel_dropped_pkts;
37278-atomic_t cm_resets_recvd;
37279+atomic_unchecked_t cm_loopbacks;
37280+atomic_unchecked_t cm_nodes_created;
37281+atomic_unchecked_t cm_nodes_destroyed;
37282+atomic_unchecked_t cm_accel_dropped_pkts;
37283+atomic_unchecked_t cm_resets_recvd;
37284
37285 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
37286 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
37287@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
37288
37289 static struct nes_cm_core *g_cm_core;
37290
37291-atomic_t cm_connects;
37292-atomic_t cm_accepts;
37293-atomic_t cm_disconnects;
37294-atomic_t cm_closes;
37295-atomic_t cm_connecteds;
37296-atomic_t cm_connect_reqs;
37297-atomic_t cm_rejects;
37298+atomic_unchecked_t cm_connects;
37299+atomic_unchecked_t cm_accepts;
37300+atomic_unchecked_t cm_disconnects;
37301+atomic_unchecked_t cm_closes;
37302+atomic_unchecked_t cm_connecteds;
37303+atomic_unchecked_t cm_connect_reqs;
37304+atomic_unchecked_t cm_rejects;
37305
37306 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
37307 {
37308@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
37309 kfree(listener);
37310 listener = NULL;
37311 ret = 0;
37312- atomic_inc(&cm_listens_destroyed);
37313+ atomic_inc_unchecked(&cm_listens_destroyed);
37314 } else {
37315 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
37316 }
37317@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
37318 cm_node->rem_mac);
37319
37320 add_hte_node(cm_core, cm_node);
37321- atomic_inc(&cm_nodes_created);
37322+ atomic_inc_unchecked(&cm_nodes_created);
37323
37324 return cm_node;
37325 }
37326@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
37327 }
37328
37329 atomic_dec(&cm_core->node_cnt);
37330- atomic_inc(&cm_nodes_destroyed);
37331+ atomic_inc_unchecked(&cm_nodes_destroyed);
37332 nesqp = cm_node->nesqp;
37333 if (nesqp) {
37334 nesqp->cm_node = NULL;
37335@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
37336
37337 static void drop_packet(struct sk_buff *skb)
37338 {
37339- atomic_inc(&cm_accel_dropped_pkts);
37340+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37341 dev_kfree_skb_any(skb);
37342 }
37343
37344@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
37345 {
37346
37347 int reset = 0; /* whether to send reset in case of err.. */
37348- atomic_inc(&cm_resets_recvd);
37349+ atomic_inc_unchecked(&cm_resets_recvd);
37350 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
37351 " refcnt=%d\n", cm_node, cm_node->state,
37352 atomic_read(&cm_node->ref_count));
37353@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
37354 rem_ref_cm_node(cm_node->cm_core, cm_node);
37355 return NULL;
37356 }
37357- atomic_inc(&cm_loopbacks);
37358+ atomic_inc_unchecked(&cm_loopbacks);
37359 loopbackremotenode->loopbackpartner = cm_node;
37360 loopbackremotenode->tcp_cntxt.rcv_wscale =
37361 NES_CM_DEFAULT_RCV_WND_SCALE;
37362@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
37363 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
37364 else {
37365 rem_ref_cm_node(cm_core, cm_node);
37366- atomic_inc(&cm_accel_dropped_pkts);
37367+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37368 dev_kfree_skb_any(skb);
37369 }
37370 break;
37371@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37372
37373 if ((cm_id) && (cm_id->event_handler)) {
37374 if (issue_disconn) {
37375- atomic_inc(&cm_disconnects);
37376+ atomic_inc_unchecked(&cm_disconnects);
37377 cm_event.event = IW_CM_EVENT_DISCONNECT;
37378 cm_event.status = disconn_status;
37379 cm_event.local_addr = cm_id->local_addr;
37380@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37381 }
37382
37383 if (issue_close) {
37384- atomic_inc(&cm_closes);
37385+ atomic_inc_unchecked(&cm_closes);
37386 nes_disconnect(nesqp, 1);
37387
37388 cm_id->provider_data = nesqp;
37389@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37390
37391 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
37392 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
37393- atomic_inc(&cm_accepts);
37394+ atomic_inc_unchecked(&cm_accepts);
37395
37396 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
37397 netdev_refcnt_read(nesvnic->netdev));
37398@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
37399 struct nes_cm_core *cm_core;
37400 u8 *start_buff;
37401
37402- atomic_inc(&cm_rejects);
37403+ atomic_inc_unchecked(&cm_rejects);
37404 cm_node = (struct nes_cm_node *)cm_id->provider_data;
37405 loopback = cm_node->loopbackpartner;
37406 cm_core = cm_node->cm_core;
37407@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37408 ntohl(cm_id->local_addr.sin_addr.s_addr),
37409 ntohs(cm_id->local_addr.sin_port));
37410
37411- atomic_inc(&cm_connects);
37412+ atomic_inc_unchecked(&cm_connects);
37413 nesqp->active_conn = 1;
37414
37415 /* cache the cm_id in the qp */
37416@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
37417 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
37418 return err;
37419 }
37420- atomic_inc(&cm_listens_created);
37421+ atomic_inc_unchecked(&cm_listens_created);
37422 }
37423
37424 cm_id->add_ref(cm_id);
37425@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
37426
37427 if (nesqp->destroyed)
37428 return;
37429- atomic_inc(&cm_connecteds);
37430+ atomic_inc_unchecked(&cm_connecteds);
37431 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
37432 " local port 0x%04X. jiffies = %lu.\n",
37433 nesqp->hwqp.qp_id,
37434@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
37435
37436 cm_id->add_ref(cm_id);
37437 ret = cm_id->event_handler(cm_id, &cm_event);
37438- atomic_inc(&cm_closes);
37439+ atomic_inc_unchecked(&cm_closes);
37440 cm_event.event = IW_CM_EVENT_CLOSE;
37441 cm_event.status = 0;
37442 cm_event.provider_data = cm_id->provider_data;
37443@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
37444 return;
37445 cm_id = cm_node->cm_id;
37446
37447- atomic_inc(&cm_connect_reqs);
37448+ atomic_inc_unchecked(&cm_connect_reqs);
37449 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37450 cm_node, cm_id, jiffies);
37451
37452@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
37453 return;
37454 cm_id = cm_node->cm_id;
37455
37456- atomic_inc(&cm_connect_reqs);
37457+ atomic_inc_unchecked(&cm_connect_reqs);
37458 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37459 cm_node, cm_id, jiffies);
37460
37461diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
37462index 4166452..fc952c3 100644
37463--- a/drivers/infiniband/hw/nes/nes_mgt.c
37464+++ b/drivers/infiniband/hw/nes/nes_mgt.c
37465@@ -40,8 +40,8 @@
37466 #include "nes.h"
37467 #include "nes_mgt.h"
37468
37469-atomic_t pau_qps_created;
37470-atomic_t pau_qps_destroyed;
37471+atomic_unchecked_t pau_qps_created;
37472+atomic_unchecked_t pau_qps_destroyed;
37473
37474 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
37475 {
37476@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
37477 {
37478 struct sk_buff *skb;
37479 unsigned long flags;
37480- atomic_inc(&pau_qps_destroyed);
37481+ atomic_inc_unchecked(&pau_qps_destroyed);
37482
37483 /* Free packets that have not yet been forwarded */
37484 /* Lock is acquired by skb_dequeue when removing the skb */
37485@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
37486 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
37487 skb_queue_head_init(&nesqp->pau_list);
37488 spin_lock_init(&nesqp->pau_lock);
37489- atomic_inc(&pau_qps_created);
37490+ atomic_inc_unchecked(&pau_qps_created);
37491 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37492 }
37493
37494diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37495index 85cf4d1..05d8e71 100644
37496--- a/drivers/infiniband/hw/nes/nes_nic.c
37497+++ b/drivers/infiniband/hw/nes/nes_nic.c
37498@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37499 target_stat_values[++index] = mh_detected;
37500 target_stat_values[++index] = mh_pauses_sent;
37501 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37502- target_stat_values[++index] = atomic_read(&cm_connects);
37503- target_stat_values[++index] = atomic_read(&cm_accepts);
37504- target_stat_values[++index] = atomic_read(&cm_disconnects);
37505- target_stat_values[++index] = atomic_read(&cm_connecteds);
37506- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37507- target_stat_values[++index] = atomic_read(&cm_rejects);
37508- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37509- target_stat_values[++index] = atomic_read(&qps_created);
37510- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37511- target_stat_values[++index] = atomic_read(&qps_destroyed);
37512- target_stat_values[++index] = atomic_read(&cm_closes);
37513+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37514+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37515+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37516+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37517+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37518+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37519+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37520+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37521+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37522+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37523+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37524 target_stat_values[++index] = cm_packets_sent;
37525 target_stat_values[++index] = cm_packets_bounced;
37526 target_stat_values[++index] = cm_packets_created;
37527 target_stat_values[++index] = cm_packets_received;
37528 target_stat_values[++index] = cm_packets_dropped;
37529 target_stat_values[++index] = cm_packets_retrans;
37530- target_stat_values[++index] = atomic_read(&cm_listens_created);
37531- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37532+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37533+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37534 target_stat_values[++index] = cm_backlog_drops;
37535- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37536- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37537- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37538- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37539- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37540+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37541+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37542+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37543+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37544+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37545 target_stat_values[++index] = nesadapter->free_4kpbl;
37546 target_stat_values[++index] = nesadapter->free_256pbl;
37547 target_stat_values[++index] = int_mod_timer_init;
37548 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37549 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37550 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37551- target_stat_values[++index] = atomic_read(&pau_qps_created);
37552- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37553+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37554+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37555 }
37556
37557 /**
37558diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37559index 8f67fe2..8960859 100644
37560--- a/drivers/infiniband/hw/nes/nes_verbs.c
37561+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37562@@ -46,9 +46,9 @@
37563
37564 #include <rdma/ib_umem.h>
37565
37566-atomic_t mod_qp_timouts;
37567-atomic_t qps_created;
37568-atomic_t sw_qps_destroyed;
37569+atomic_unchecked_t mod_qp_timouts;
37570+atomic_unchecked_t qps_created;
37571+atomic_unchecked_t sw_qps_destroyed;
37572
37573 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37574
37575@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37576 if (init_attr->create_flags)
37577 return ERR_PTR(-EINVAL);
37578
37579- atomic_inc(&qps_created);
37580+ atomic_inc_unchecked(&qps_created);
37581 switch (init_attr->qp_type) {
37582 case IB_QPT_RC:
37583 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37584@@ -1465,7 +1465,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37585 struct iw_cm_event cm_event;
37586 int ret = 0;
37587
37588- atomic_inc(&sw_qps_destroyed);
37589+ atomic_inc_unchecked(&sw_qps_destroyed);
37590 nesqp->destroyed = 1;
37591
37592 /* Blow away the connection if it exists. */
37593diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37594index 4d11575..3e890e5 100644
37595--- a/drivers/infiniband/hw/qib/qib.h
37596+++ b/drivers/infiniband/hw/qib/qib.h
37597@@ -51,6 +51,7 @@
37598 #include <linux/completion.h>
37599 #include <linux/kref.h>
37600 #include <linux/sched.h>
37601+#include <linux/slab.h>
37602
37603 #include "qib_common.h"
37604 #include "qib_verbs.h"
37605diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37606index da739d9..da1c7f4 100644
37607--- a/drivers/input/gameport/gameport.c
37608+++ b/drivers/input/gameport/gameport.c
37609@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37610 */
37611 static void gameport_init_port(struct gameport *gameport)
37612 {
37613- static atomic_t gameport_no = ATOMIC_INIT(0);
37614+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37615
37616 __module_get(THIS_MODULE);
37617
37618 mutex_init(&gameport->drv_mutex);
37619 device_initialize(&gameport->dev);
37620 dev_set_name(&gameport->dev, "gameport%lu",
37621- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37622+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37623 gameport->dev.bus = &gameport_bus;
37624 gameport->dev.release = gameport_release_port;
37625 if (gameport->parent)
37626diff --git a/drivers/input/input.c b/drivers/input/input.c
37627index c044699..174d71a 100644
37628--- a/drivers/input/input.c
37629+++ b/drivers/input/input.c
37630@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37631 */
37632 int input_register_device(struct input_dev *dev)
37633 {
37634- static atomic_t input_no = ATOMIC_INIT(0);
37635+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37636 struct input_devres *devres = NULL;
37637 struct input_handler *handler;
37638 unsigned int packet_size;
37639@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37640 dev->setkeycode = input_default_setkeycode;
37641
37642 dev_set_name(&dev->dev, "input%ld",
37643- (unsigned long) atomic_inc_return(&input_no) - 1);
37644+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37645
37646 error = device_add(&dev->dev);
37647 if (error)
37648diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37649index 04c69af..5f92d00 100644
37650--- a/drivers/input/joystick/sidewinder.c
37651+++ b/drivers/input/joystick/sidewinder.c
37652@@ -30,6 +30,7 @@
37653 #include <linux/kernel.h>
37654 #include <linux/module.h>
37655 #include <linux/slab.h>
37656+#include <linux/sched.h>
37657 #include <linux/init.h>
37658 #include <linux/input.h>
37659 #include <linux/gameport.h>
37660diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37661index fa061d4..4a6957c 100644
37662--- a/drivers/input/joystick/xpad.c
37663+++ b/drivers/input/joystick/xpad.c
37664@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37665
37666 static int xpad_led_probe(struct usb_xpad *xpad)
37667 {
37668- static atomic_t led_seq = ATOMIC_INIT(0);
37669+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37670 long led_no;
37671 struct xpad_led *led;
37672 struct led_classdev *led_cdev;
37673@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37674 if (!led)
37675 return -ENOMEM;
37676
37677- led_no = (long)atomic_inc_return(&led_seq) - 1;
37678+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37679
37680 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37681 led->xpad = xpad;
37682diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37683index 2f0b39d..7370f13 100644
37684--- a/drivers/input/mouse/psmouse.h
37685+++ b/drivers/input/mouse/psmouse.h
37686@@ -116,7 +116,7 @@ struct psmouse_attribute {
37687 ssize_t (*set)(struct psmouse *psmouse, void *data,
37688 const char *buf, size_t count);
37689 bool protect;
37690-};
37691+} __do_const;
37692 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37693
37694 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37695diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37696index 4c842c3..590b0bf 100644
37697--- a/drivers/input/mousedev.c
37698+++ b/drivers/input/mousedev.c
37699@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37700
37701 spin_unlock_irq(&client->packet_lock);
37702
37703- if (copy_to_user(buffer, data, count))
37704+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37705 return -EFAULT;
37706
37707 return count;
37708diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37709index 25fc597..558bf3b3 100644
37710--- a/drivers/input/serio/serio.c
37711+++ b/drivers/input/serio/serio.c
37712@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37713 */
37714 static void serio_init_port(struct serio *serio)
37715 {
37716- static atomic_t serio_no = ATOMIC_INIT(0);
37717+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37718
37719 __module_get(THIS_MODULE);
37720
37721@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37722 mutex_init(&serio->drv_mutex);
37723 device_initialize(&serio->dev);
37724 dev_set_name(&serio->dev, "serio%ld",
37725- (long)atomic_inc_return(&serio_no) - 1);
37726+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37727 serio->dev.bus = &serio_bus;
37728 serio->dev.release = serio_release_port;
37729 serio->dev.groups = serio_device_attr_groups;
37730diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37731index b972d43..8943713 100644
37732--- a/drivers/iommu/iommu.c
37733+++ b/drivers/iommu/iommu.c
37734@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
37735 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37736 {
37737 bus_register_notifier(bus, &iommu_bus_nb);
37738- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37739+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37740 }
37741
37742 /**
37743diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
37744index dcfea4e..f4226b2 100644
37745--- a/drivers/iommu/irq_remapping.c
37746+++ b/drivers/iommu/irq_remapping.c
37747@@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
37748 void panic_if_irq_remap(const char *msg)
37749 {
37750 if (irq_remapping_enabled)
37751- panic(msg);
37752+ panic("%s", msg);
37753 }
37754
37755 static void ir_ack_apic_edge(struct irq_data *data)
37756@@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
37757
37758 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
37759 {
37760- chip->irq_print_chip = ir_print_prefix;
37761- chip->irq_ack = ir_ack_apic_edge;
37762- chip->irq_eoi = ir_ack_apic_level;
37763- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37764+ pax_open_kernel();
37765+ *(void **)&chip->irq_print_chip = ir_print_prefix;
37766+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
37767+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
37768+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37769+ pax_close_kernel();
37770 }
37771
37772 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
37773diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
37774index fc6aebf..762c5f5 100644
37775--- a/drivers/irqchip/irq-gic.c
37776+++ b/drivers/irqchip/irq-gic.c
37777@@ -83,7 +83,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
37778 * Supported arch specific GIC irq extension.
37779 * Default make them NULL.
37780 */
37781-struct irq_chip gic_arch_extn = {
37782+irq_chip_no_const gic_arch_extn = {
37783 .irq_eoi = NULL,
37784 .irq_mask = NULL,
37785 .irq_unmask = NULL,
37786@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
37787 chained_irq_exit(chip, desc);
37788 }
37789
37790-static struct irq_chip gic_chip = {
37791+static irq_chip_no_const gic_chip __read_only = {
37792 .name = "GIC",
37793 .irq_mask = gic_mask_irq,
37794 .irq_unmask = gic_unmask_irq,
37795diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37796index 89562a8..218999b 100644
37797--- a/drivers/isdn/capi/capi.c
37798+++ b/drivers/isdn/capi/capi.c
37799@@ -81,8 +81,8 @@ struct capiminor {
37800
37801 struct capi20_appl *ap;
37802 u32 ncci;
37803- atomic_t datahandle;
37804- atomic_t msgid;
37805+ atomic_unchecked_t datahandle;
37806+ atomic_unchecked_t msgid;
37807
37808 struct tty_port port;
37809 int ttyinstop;
37810@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37811 capimsg_setu16(s, 2, mp->ap->applid);
37812 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37813 capimsg_setu8 (s, 5, CAPI_RESP);
37814- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37815+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37816 capimsg_setu32(s, 8, mp->ncci);
37817 capimsg_setu16(s, 12, datahandle);
37818 }
37819@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37820 mp->outbytes -= len;
37821 spin_unlock_bh(&mp->outlock);
37822
37823- datahandle = atomic_inc_return(&mp->datahandle);
37824+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37825 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37826 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37827 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37828 capimsg_setu16(skb->data, 2, mp->ap->applid);
37829 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37830 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37831- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37832+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37833 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37834 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37835 capimsg_setu16(skb->data, 16, len); /* Data length */
37836diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c
37837index 9b1b274..c123709 100644
37838--- a/drivers/isdn/capi/kcapi.c
37839+++ b/drivers/isdn/capi/kcapi.c
37840@@ -93,7 +93,7 @@ capi_ctr_put(struct capi_ctr *ctr)
37841
37842 static inline struct capi_ctr *get_capi_ctr_by_nr(u16 contr)
37843 {
37844- if (contr - 1 >= CAPI_MAXCONTR)
37845+ if (contr < 1 || contr - 1 >= CAPI_MAXCONTR)
37846 return NULL;
37847
37848 return capi_controller[contr - 1];
37849@@ -103,7 +103,7 @@ static inline struct capi20_appl *__get_capi_appl_by_nr(u16 applid)
37850 {
37851 lockdep_assert_held(&capi_controller_lock);
37852
37853- if (applid - 1 >= CAPI_MAXAPPL)
37854+ if (applid < 1 || applid - 1 >= CAPI_MAXAPPL)
37855 return NULL;
37856
37857 return capi_applications[applid - 1];
37858@@ -111,7 +111,7 @@ static inline struct capi20_appl *__get_capi_appl_by_nr(u16 applid)
37859
37860 static inline struct capi20_appl *get_capi_appl_by_nr(u16 applid)
37861 {
37862- if (applid - 1 >= CAPI_MAXAPPL)
37863+ if (applid < 1 || applid - 1 >= CAPI_MAXAPPL)
37864 return NULL;
37865
37866 return rcu_dereference(capi_applications[applid - 1]);
37867diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37868index e2b5396..c5486dc 100644
37869--- a/drivers/isdn/gigaset/interface.c
37870+++ b/drivers/isdn/gigaset/interface.c
37871@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37872 }
37873 tty->driver_data = cs;
37874
37875- ++cs->port.count;
37876+ atomic_inc(&cs->port.count);
37877
37878- if (cs->port.count == 1) {
37879+ if (atomic_read(&cs->port.count) == 1) {
37880 tty_port_tty_set(&cs->port, tty);
37881 cs->port.low_latency = 1;
37882 }
37883@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37884
37885 if (!cs->connected)
37886 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37887- else if (!cs->port.count)
37888+ else if (!atomic_read(&cs->port.count))
37889 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37890- else if (!--cs->port.count)
37891+ else if (!atomic_dec_return(&cs->port.count))
37892 tty_port_tty_set(&cs->port, NULL);
37893
37894 mutex_unlock(&cs->mutex);
37895diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
37896index 821f7ac..28d4030 100644
37897--- a/drivers/isdn/hardware/avm/b1.c
37898+++ b/drivers/isdn/hardware/avm/b1.c
37899@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
37900 }
37901 if (left) {
37902 if (t4file->user) {
37903- if (copy_from_user(buf, dp, left))
37904+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37905 return -EFAULT;
37906 } else {
37907 memcpy(buf, dp, left);
37908@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
37909 }
37910 if (left) {
37911 if (config->user) {
37912- if (copy_from_user(buf, dp, left))
37913+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37914 return -EFAULT;
37915 } else {
37916 memcpy(buf, dp, left);
37917diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
37918index ebaebdf..acd4405 100644
37919--- a/drivers/isdn/i4l/isdn_tty.c
37920+++ b/drivers/isdn/i4l/isdn_tty.c
37921@@ -1511,9 +1511,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
37922
37923 #ifdef ISDN_DEBUG_MODEM_OPEN
37924 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37925- port->count);
37926+ atomic_read(&port->count));
37927 #endif
37928- port->count++;
37929+ atomic_inc(&port->count);
37930 port->tty = tty;
37931 /*
37932 * Start up serial port
37933@@ -1557,7 +1557,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37934 #endif
37935 return;
37936 }
37937- if ((tty->count == 1) && (port->count != 1)) {
37938+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37939 /*
37940 * Uh, oh. tty->count is 1, which means that the tty
37941 * structure will be freed. Info->count should always
37942@@ -1566,15 +1566,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37943 * serial port won't be shutdown.
37944 */
37945 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37946- "info->count is %d\n", port->count);
37947- port->count = 1;
37948+ "info->count is %d\n", atomic_read(&port->count));
37949+ atomic_set(&port->count, 1);
37950 }
37951- if (--port->count < 0) {
37952+ if (atomic_dec_return(&port->count) < 0) {
37953 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37954- info->line, port->count);
37955- port->count = 0;
37956+ info->line, atomic_read(&port->count));
37957+ atomic_set(&port->count, 0);
37958 }
37959- if (port->count) {
37960+ if (atomic_read(&port->count)) {
37961 #ifdef ISDN_DEBUG_MODEM_OPEN
37962 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37963 #endif
37964@@ -1628,7 +1628,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37965 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37966 return;
37967 isdn_tty_shutdown(info);
37968- port->count = 0;
37969+ atomic_set(&port->count, 0);
37970 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37971 port->tty = NULL;
37972 wake_up_interruptible(&port->open_wait);
37973@@ -1973,7 +1973,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37974 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37975 modem_info *info = &dev->mdm.info[i];
37976
37977- if (info->port.count == 0)
37978+ if (atomic_read(&info->port.count) == 0)
37979 continue;
37980 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37981 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37982diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37983index e74df7c..03a03ba 100644
37984--- a/drivers/isdn/icn/icn.c
37985+++ b/drivers/isdn/icn/icn.c
37986@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37987 if (count > len)
37988 count = len;
37989 if (user) {
37990- if (copy_from_user(msg, buf, count))
37991+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37992 return -EFAULT;
37993 } else
37994 memcpy(msg, buf, count);
37995diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37996index 6a8405d..0bd1c7e 100644
37997--- a/drivers/leds/leds-clevo-mail.c
37998+++ b/drivers/leds/leds-clevo-mail.c
37999@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
38000 * detected as working, but in reality it is not) as low as
38001 * possible.
38002 */
38003-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
38004+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
38005 {
38006 .callback = clevo_mail_led_dmi_callback,
38007 .ident = "Clevo D410J",
38008diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
38009index 64e204e..c6bf189 100644
38010--- a/drivers/leds/leds-ss4200.c
38011+++ b/drivers/leds/leds-ss4200.c
38012@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
38013 * detected as working, but in reality it is not) as low as
38014 * possible.
38015 */
38016-static struct dmi_system_id __initdata nas_led_whitelist[] = {
38017+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
38018 {
38019 .callback = ss4200_led_dmi_callback,
38020 .ident = "Intel SS4200-E",
38021diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
38022index a5ebc00..3de3364 100644
38023--- a/drivers/lguest/core.c
38024+++ b/drivers/lguest/core.c
38025@@ -92,9 +92,17 @@ static __init int map_switcher(void)
38026 * it's worked so far. The end address needs +1 because __get_vm_area
38027 * allocates an extra guard page, so we need space for that.
38028 */
38029+
38030+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
38031+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
38032+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
38033+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
38034+#else
38035 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
38036 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
38037 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
38038+#endif
38039+
38040 if (!switcher_vma) {
38041 err = -ENOMEM;
38042 printk("lguest: could not map switcher pages high\n");
38043@@ -119,7 +127,7 @@ static __init int map_switcher(void)
38044 * Now the Switcher is mapped at the right address, we can't fail!
38045 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
38046 */
38047- memcpy(switcher_vma->addr, start_switcher_text,
38048+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
38049 end_switcher_text - start_switcher_text);
38050
38051 printk(KERN_INFO "lguest: mapped switcher at %p\n",
38052diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
38053index 3b62be16..e33134a 100644
38054--- a/drivers/lguest/page_tables.c
38055+++ b/drivers/lguest/page_tables.c
38056@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
38057 /*:*/
38058
38059 #ifdef CONFIG_X86_PAE
38060-static void release_pmd(pmd_t *spmd)
38061+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
38062 {
38063 /* If the entry's not present, there's nothing to release. */
38064 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
38065diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
38066index 4af12e1..0e89afe 100644
38067--- a/drivers/lguest/x86/core.c
38068+++ b/drivers/lguest/x86/core.c
38069@@ -59,7 +59,7 @@ static struct {
38070 /* Offset from where switcher.S was compiled to where we've copied it */
38071 static unsigned long switcher_offset(void)
38072 {
38073- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
38074+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
38075 }
38076
38077 /* This cpu's struct lguest_pages. */
38078@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
38079 * These copies are pretty cheap, so we do them unconditionally: */
38080 /* Save the current Host top-level page directory.
38081 */
38082+
38083+#ifdef CONFIG_PAX_PER_CPU_PGD
38084+ pages->state.host_cr3 = read_cr3();
38085+#else
38086 pages->state.host_cr3 = __pa(current->mm->pgd);
38087+#endif
38088+
38089 /*
38090 * Set up the Guest's page tables to see this CPU's pages (and no
38091 * other CPU's pages).
38092@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
38093 * compiled-in switcher code and the high-mapped copy we just made.
38094 */
38095 for (i = 0; i < IDT_ENTRIES; i++)
38096- default_idt_entries[i] += switcher_offset();
38097+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
38098
38099 /*
38100 * Set up the Switcher's per-cpu areas.
38101@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
38102 * it will be undisturbed when we switch. To change %cs and jump we
38103 * need this structure to feed to Intel's "lcall" instruction.
38104 */
38105- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
38106+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
38107 lguest_entry.segment = LGUEST_CS;
38108
38109 /*
38110diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
38111index 40634b0..4f5855e 100644
38112--- a/drivers/lguest/x86/switcher_32.S
38113+++ b/drivers/lguest/x86/switcher_32.S
38114@@ -87,6 +87,7 @@
38115 #include <asm/page.h>
38116 #include <asm/segment.h>
38117 #include <asm/lguest.h>
38118+#include <asm/processor-flags.h>
38119
38120 // We mark the start of the code to copy
38121 // It's placed in .text tho it's never run here
38122@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
38123 // Changes type when we load it: damn Intel!
38124 // For after we switch over our page tables
38125 // That entry will be read-only: we'd crash.
38126+
38127+#ifdef CONFIG_PAX_KERNEXEC
38128+ mov %cr0, %edx
38129+ xor $X86_CR0_WP, %edx
38130+ mov %edx, %cr0
38131+#endif
38132+
38133 movl $(GDT_ENTRY_TSS*8), %edx
38134 ltr %dx
38135
38136@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
38137 // Let's clear it again for our return.
38138 // The GDT descriptor of the Host
38139 // Points to the table after two "size" bytes
38140- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
38141+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
38142 // Clear "used" from type field (byte 5, bit 2)
38143- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
38144+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
38145+
38146+#ifdef CONFIG_PAX_KERNEXEC
38147+ mov %cr0, %eax
38148+ xor $X86_CR0_WP, %eax
38149+ mov %eax, %cr0
38150+#endif
38151
38152 // Once our page table's switched, the Guest is live!
38153 // The Host fades as we run this final step.
38154@@ -295,13 +309,12 @@ deliver_to_host:
38155 // I consulted gcc, and it gave
38156 // These instructions, which I gladly credit:
38157 leal (%edx,%ebx,8), %eax
38158- movzwl (%eax),%edx
38159- movl 4(%eax), %eax
38160- xorw %ax, %ax
38161- orl %eax, %edx
38162+ movl 4(%eax), %edx
38163+ movw (%eax), %dx
38164 // Now the address of the handler's in %edx
38165 // We call it now: its "iret" drops us home.
38166- jmp *%edx
38167+ ljmp $__KERNEL_CS, $1f
38168+1: jmp *%edx
38169
38170 // Every interrupt can come to us here
38171 // But we must truly tell each apart.
38172diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
38173index 4fd9d6a..834fa03 100644
38174--- a/drivers/md/bitmap.c
38175+++ b/drivers/md/bitmap.c
38176@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
38177 chunk_kb ? "KB" : "B");
38178 if (bitmap->storage.file) {
38179 seq_printf(seq, ", file: ");
38180- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
38181+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
38182 }
38183
38184 seq_printf(seq, "\n");
38185diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
38186index aa04f02..2a1309e 100644
38187--- a/drivers/md/dm-ioctl.c
38188+++ b/drivers/md/dm-ioctl.c
38189@@ -1694,7 +1694,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
38190 cmd == DM_LIST_VERSIONS_CMD)
38191 return 0;
38192
38193- if ((cmd == DM_DEV_CREATE_CMD)) {
38194+ if (cmd == DM_DEV_CREATE_CMD) {
38195 if (!*param->name) {
38196 DMWARN("name not supplied when creating device");
38197 return -EINVAL;
38198diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
38199index d053098..05cc375 100644
38200--- a/drivers/md/dm-raid1.c
38201+++ b/drivers/md/dm-raid1.c
38202@@ -40,7 +40,7 @@ enum dm_raid1_error {
38203
38204 struct mirror {
38205 struct mirror_set *ms;
38206- atomic_t error_count;
38207+ atomic_unchecked_t error_count;
38208 unsigned long error_type;
38209 struct dm_dev *dev;
38210 sector_t offset;
38211@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
38212 struct mirror *m;
38213
38214 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
38215- if (!atomic_read(&m->error_count))
38216+ if (!atomic_read_unchecked(&m->error_count))
38217 return m;
38218
38219 return NULL;
38220@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
38221 * simple way to tell if a device has encountered
38222 * errors.
38223 */
38224- atomic_inc(&m->error_count);
38225+ atomic_inc_unchecked(&m->error_count);
38226
38227 if (test_and_set_bit(error_type, &m->error_type))
38228 return;
38229@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
38230 struct mirror *m = get_default_mirror(ms);
38231
38232 do {
38233- if (likely(!atomic_read(&m->error_count)))
38234+ if (likely(!atomic_read_unchecked(&m->error_count)))
38235 return m;
38236
38237 if (m-- == ms->mirror)
38238@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
38239 {
38240 struct mirror *default_mirror = get_default_mirror(m->ms);
38241
38242- return !atomic_read(&default_mirror->error_count);
38243+ return !atomic_read_unchecked(&default_mirror->error_count);
38244 }
38245
38246 static int mirror_available(struct mirror_set *ms, struct bio *bio)
38247@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
38248 */
38249 if (likely(region_in_sync(ms, region, 1)))
38250 m = choose_mirror(ms, bio->bi_sector);
38251- else if (m && atomic_read(&m->error_count))
38252+ else if (m && atomic_read_unchecked(&m->error_count))
38253 m = NULL;
38254
38255 if (likely(m))
38256@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
38257 }
38258
38259 ms->mirror[mirror].ms = ms;
38260- atomic_set(&(ms->mirror[mirror].error_count), 0);
38261+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
38262 ms->mirror[mirror].error_type = 0;
38263 ms->mirror[mirror].offset = offset;
38264
38265@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
38266 */
38267 static char device_status_char(struct mirror *m)
38268 {
38269- if (!atomic_read(&(m->error_count)))
38270+ if (!atomic_read_unchecked(&(m->error_count)))
38271 return 'A';
38272
38273 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
38274diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
38275index 7b8b2b9..9c7d145 100644
38276--- a/drivers/md/dm-stripe.c
38277+++ b/drivers/md/dm-stripe.c
38278@@ -20,7 +20,7 @@ struct stripe {
38279 struct dm_dev *dev;
38280 sector_t physical_start;
38281
38282- atomic_t error_count;
38283+ atomic_unchecked_t error_count;
38284 };
38285
38286 struct stripe_c {
38287@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
38288 kfree(sc);
38289 return r;
38290 }
38291- atomic_set(&(sc->stripe[i].error_count), 0);
38292+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
38293 }
38294
38295 ti->private = sc;
38296@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
38297 DMEMIT("%d ", sc->stripes);
38298 for (i = 0; i < sc->stripes; i++) {
38299 DMEMIT("%s ", sc->stripe[i].dev->name);
38300- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
38301+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
38302 'D' : 'A';
38303 }
38304 buffer[i] = '\0';
38305@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
38306 */
38307 for (i = 0; i < sc->stripes; i++)
38308 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
38309- atomic_inc(&(sc->stripe[i].error_count));
38310- if (atomic_read(&(sc->stripe[i].error_count)) <
38311+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
38312+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
38313 DM_IO_ERROR_THRESHOLD)
38314 schedule_work(&sc->trigger_event);
38315 }
38316diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
38317index 1ff252a..ee384c1 100644
38318--- a/drivers/md/dm-table.c
38319+++ b/drivers/md/dm-table.c
38320@@ -389,7 +389,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
38321 if (!dev_size)
38322 return 0;
38323
38324- if ((start >= dev_size) || (start + len > dev_size)) {
38325+ if ((start >= dev_size) || (len > dev_size - start)) {
38326 DMWARN("%s: %s too small for target: "
38327 "start=%llu, len=%llu, dev_size=%llu",
38328 dm_device_name(ti->table->md), bdevname(bdev, b),
38329diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
38330index 00cee02..b89a29d 100644
38331--- a/drivers/md/dm-thin-metadata.c
38332+++ b/drivers/md/dm-thin-metadata.c
38333@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38334 {
38335 pmd->info.tm = pmd->tm;
38336 pmd->info.levels = 2;
38337- pmd->info.value_type.context = pmd->data_sm;
38338+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38339 pmd->info.value_type.size = sizeof(__le64);
38340 pmd->info.value_type.inc = data_block_inc;
38341 pmd->info.value_type.dec = data_block_dec;
38342@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38343
38344 pmd->bl_info.tm = pmd->tm;
38345 pmd->bl_info.levels = 1;
38346- pmd->bl_info.value_type.context = pmd->data_sm;
38347+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38348 pmd->bl_info.value_type.size = sizeof(__le64);
38349 pmd->bl_info.value_type.inc = data_block_inc;
38350 pmd->bl_info.value_type.dec = data_block_dec;
38351diff --git a/drivers/md/dm.c b/drivers/md/dm.c
38352index 9a0bdad..4df9543 100644
38353--- a/drivers/md/dm.c
38354+++ b/drivers/md/dm.c
38355@@ -169,9 +169,9 @@ struct mapped_device {
38356 /*
38357 * Event handling.
38358 */
38359- atomic_t event_nr;
38360+ atomic_unchecked_t event_nr;
38361 wait_queue_head_t eventq;
38362- atomic_t uevent_seq;
38363+ atomic_unchecked_t uevent_seq;
38364 struct list_head uevent_list;
38365 spinlock_t uevent_lock; /* Protect access to uevent_list */
38366
38367@@ -1879,8 +1879,8 @@ static struct mapped_device *alloc_dev(int minor)
38368 rwlock_init(&md->map_lock);
38369 atomic_set(&md->holders, 1);
38370 atomic_set(&md->open_count, 0);
38371- atomic_set(&md->event_nr, 0);
38372- atomic_set(&md->uevent_seq, 0);
38373+ atomic_set_unchecked(&md->event_nr, 0);
38374+ atomic_set_unchecked(&md->uevent_seq, 0);
38375 INIT_LIST_HEAD(&md->uevent_list);
38376 spin_lock_init(&md->uevent_lock);
38377
38378@@ -2028,7 +2028,7 @@ static void event_callback(void *context)
38379
38380 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
38381
38382- atomic_inc(&md->event_nr);
38383+ atomic_inc_unchecked(&md->event_nr);
38384 wake_up(&md->eventq);
38385 }
38386
38387@@ -2685,18 +2685,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
38388
38389 uint32_t dm_next_uevent_seq(struct mapped_device *md)
38390 {
38391- return atomic_add_return(1, &md->uevent_seq);
38392+ return atomic_add_return_unchecked(1, &md->uevent_seq);
38393 }
38394
38395 uint32_t dm_get_event_nr(struct mapped_device *md)
38396 {
38397- return atomic_read(&md->event_nr);
38398+ return atomic_read_unchecked(&md->event_nr);
38399 }
38400
38401 int dm_wait_event(struct mapped_device *md, int event_nr)
38402 {
38403 return wait_event_interruptible(md->eventq,
38404- (event_nr != atomic_read(&md->event_nr)));
38405+ (event_nr != atomic_read_unchecked(&md->event_nr)));
38406 }
38407
38408 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
38409diff --git a/drivers/md/md.c b/drivers/md/md.c
38410index a4a93b9..4747b63 100644
38411--- a/drivers/md/md.c
38412+++ b/drivers/md/md.c
38413@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
38414 * start build, activate spare
38415 */
38416 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
38417-static atomic_t md_event_count;
38418+static atomic_unchecked_t md_event_count;
38419 void md_new_event(struct mddev *mddev)
38420 {
38421- atomic_inc(&md_event_count);
38422+ atomic_inc_unchecked(&md_event_count);
38423 wake_up(&md_event_waiters);
38424 }
38425 EXPORT_SYMBOL_GPL(md_new_event);
38426@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
38427 */
38428 static void md_new_event_inintr(struct mddev *mddev)
38429 {
38430- atomic_inc(&md_event_count);
38431+ atomic_inc_unchecked(&md_event_count);
38432 wake_up(&md_event_waiters);
38433 }
38434
38435@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
38436 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
38437 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
38438 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
38439- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38440+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38441
38442 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
38443 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
38444@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
38445 else
38446 sb->resync_offset = cpu_to_le64(0);
38447
38448- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
38449+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
38450
38451 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
38452 sb->size = cpu_to_le64(mddev->dev_sectors);
38453@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
38454 static ssize_t
38455 errors_show(struct md_rdev *rdev, char *page)
38456 {
38457- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
38458+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
38459 }
38460
38461 static ssize_t
38462@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
38463 char *e;
38464 unsigned long n = simple_strtoul(buf, &e, 10);
38465 if (*buf && (*e == 0 || *e == '\n')) {
38466- atomic_set(&rdev->corrected_errors, n);
38467+ atomic_set_unchecked(&rdev->corrected_errors, n);
38468 return len;
38469 }
38470 return -EINVAL;
38471@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
38472 rdev->sb_loaded = 0;
38473 rdev->bb_page = NULL;
38474 atomic_set(&rdev->nr_pending, 0);
38475- atomic_set(&rdev->read_errors, 0);
38476- atomic_set(&rdev->corrected_errors, 0);
38477+ atomic_set_unchecked(&rdev->read_errors, 0);
38478+ atomic_set_unchecked(&rdev->corrected_errors, 0);
38479
38480 INIT_LIST_HEAD(&rdev->same_set);
38481 init_waitqueue_head(&rdev->blocked_wait);
38482@@ -6994,7 +6994,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
38483
38484 spin_unlock(&pers_lock);
38485 seq_printf(seq, "\n");
38486- seq->poll_event = atomic_read(&md_event_count);
38487+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38488 return 0;
38489 }
38490 if (v == (void*)2) {
38491@@ -7097,7 +7097,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
38492 return error;
38493
38494 seq = file->private_data;
38495- seq->poll_event = atomic_read(&md_event_count);
38496+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38497 return error;
38498 }
38499
38500@@ -7111,7 +7111,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
38501 /* always allow read */
38502 mask = POLLIN | POLLRDNORM;
38503
38504- if (seq->poll_event != atomic_read(&md_event_count))
38505+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
38506 mask |= POLLERR | POLLPRI;
38507 return mask;
38508 }
38509@@ -7155,7 +7155,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
38510 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
38511 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38512 (int)part_stat_read(&disk->part0, sectors[1]) -
38513- atomic_read(&disk->sync_io);
38514+ atomic_read_unchecked(&disk->sync_io);
38515 /* sync IO will cause sync_io to increase before the disk_stats
38516 * as sync_io is counted when a request starts, and
38517 * disk_stats is counted when it completes.
38518diff --git a/drivers/md/md.h b/drivers/md/md.h
38519index d90fb1a..4174a2b 100644
38520--- a/drivers/md/md.h
38521+++ b/drivers/md/md.h
38522@@ -94,13 +94,13 @@ struct md_rdev {
38523 * only maintained for arrays that
38524 * support hot removal
38525 */
38526- atomic_t read_errors; /* number of consecutive read errors that
38527+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
38528 * we have tried to ignore.
38529 */
38530 struct timespec last_read_error; /* monotonic time since our
38531 * last read error
38532 */
38533- atomic_t corrected_errors; /* number of corrected read errors,
38534+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
38535 * for reporting to userspace and storing
38536 * in superblock.
38537 */
38538@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
38539
38540 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
38541 {
38542- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38543+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38544 }
38545
38546 struct md_personality
38547diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
38548index 1cbfc6b..56e1dbb 100644
38549--- a/drivers/md/persistent-data/dm-space-map.h
38550+++ b/drivers/md/persistent-data/dm-space-map.h
38551@@ -60,6 +60,7 @@ struct dm_space_map {
38552 int (*root_size)(struct dm_space_map *sm, size_t *result);
38553 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
38554 };
38555+typedef struct dm_space_map __no_const dm_space_map_no_const;
38556
38557 /*----------------------------------------------------------------*/
38558
38559diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
38560index 7116798..c81390c 100644
38561--- a/drivers/md/raid1.c
38562+++ b/drivers/md/raid1.c
38563@@ -1836,7 +1836,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
38564 if (r1_sync_page_io(rdev, sect, s,
38565 bio->bi_io_vec[idx].bv_page,
38566 READ) != 0)
38567- atomic_add(s, &rdev->corrected_errors);
38568+ atomic_add_unchecked(s, &rdev->corrected_errors);
38569 }
38570 sectors -= s;
38571 sect += s;
38572@@ -2058,7 +2058,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
38573 test_bit(In_sync, &rdev->flags)) {
38574 if (r1_sync_page_io(rdev, sect, s,
38575 conf->tmppage, READ)) {
38576- atomic_add(s, &rdev->corrected_errors);
38577+ atomic_add_unchecked(s, &rdev->corrected_errors);
38578 printk(KERN_INFO
38579 "md/raid1:%s: read error corrected "
38580 "(%d sectors at %llu on %s)\n",
38581diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38582index e4ea992..d234520 100644
38583--- a/drivers/md/raid10.c
38584+++ b/drivers/md/raid10.c
38585@@ -1942,7 +1942,7 @@ static void end_sync_read(struct bio *bio, int error)
38586 /* The write handler will notice the lack of
38587 * R10BIO_Uptodate and record any errors etc
38588 */
38589- atomic_add(r10_bio->sectors,
38590+ atomic_add_unchecked(r10_bio->sectors,
38591 &conf->mirrors[d].rdev->corrected_errors);
38592
38593 /* for reconstruct, we always reschedule after a read.
38594@@ -2291,7 +2291,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38595 {
38596 struct timespec cur_time_mon;
38597 unsigned long hours_since_last;
38598- unsigned int read_errors = atomic_read(&rdev->read_errors);
38599+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38600
38601 ktime_get_ts(&cur_time_mon);
38602
38603@@ -2313,9 +2313,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38604 * overflowing the shift of read_errors by hours_since_last.
38605 */
38606 if (hours_since_last >= 8 * sizeof(read_errors))
38607- atomic_set(&rdev->read_errors, 0);
38608+ atomic_set_unchecked(&rdev->read_errors, 0);
38609 else
38610- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38611+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38612 }
38613
38614 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38615@@ -2369,8 +2369,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38616 return;
38617
38618 check_decay_read_errors(mddev, rdev);
38619- atomic_inc(&rdev->read_errors);
38620- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38621+ atomic_inc_unchecked(&rdev->read_errors);
38622+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38623 char b[BDEVNAME_SIZE];
38624 bdevname(rdev->bdev, b);
38625
38626@@ -2378,7 +2378,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38627 "md/raid10:%s: %s: Raid device exceeded "
38628 "read_error threshold [cur %d:max %d]\n",
38629 mdname(mddev), b,
38630- atomic_read(&rdev->read_errors), max_read_errors);
38631+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38632 printk(KERN_NOTICE
38633 "md/raid10:%s: %s: Failing raid device\n",
38634 mdname(mddev), b);
38635@@ -2533,7 +2533,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38636 sect +
38637 choose_data_offset(r10_bio, rdev)),
38638 bdevname(rdev->bdev, b));
38639- atomic_add(s, &rdev->corrected_errors);
38640+ atomic_add_unchecked(s, &rdev->corrected_errors);
38641 }
38642
38643 rdev_dec_pending(rdev, mddev);
38644diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38645index 251ab64..ed23a18 100644
38646--- a/drivers/md/raid5.c
38647+++ b/drivers/md/raid5.c
38648@@ -1763,21 +1763,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38649 mdname(conf->mddev), STRIPE_SECTORS,
38650 (unsigned long long)s,
38651 bdevname(rdev->bdev, b));
38652- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38653+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38654 clear_bit(R5_ReadError, &sh->dev[i].flags);
38655 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38656 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38657 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38658
38659- if (atomic_read(&rdev->read_errors))
38660- atomic_set(&rdev->read_errors, 0);
38661+ if (atomic_read_unchecked(&rdev->read_errors))
38662+ atomic_set_unchecked(&rdev->read_errors, 0);
38663 } else {
38664 const char *bdn = bdevname(rdev->bdev, b);
38665 int retry = 0;
38666 int set_bad = 0;
38667
38668 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38669- atomic_inc(&rdev->read_errors);
38670+ atomic_inc_unchecked(&rdev->read_errors);
38671 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38672 printk_ratelimited(
38673 KERN_WARNING
38674@@ -1805,7 +1805,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38675 mdname(conf->mddev),
38676 (unsigned long long)s,
38677 bdn);
38678- } else if (atomic_read(&rdev->read_errors)
38679+ } else if (atomic_read_unchecked(&rdev->read_errors)
38680 > conf->max_nr_stripes)
38681 printk(KERN_WARNING
38682 "md/raid:%s: Too many read errors, failing device %s.\n",
38683diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38684index 401ef64..836e563 100644
38685--- a/drivers/media/dvb-core/dvbdev.c
38686+++ b/drivers/media/dvb-core/dvbdev.c
38687@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38688 const struct dvb_device *template, void *priv, int type)
38689 {
38690 struct dvb_device *dvbdev;
38691- struct file_operations *dvbdevfops;
38692+ file_operations_no_const *dvbdevfops;
38693 struct device *clsdev;
38694 int minor;
38695 int id;
38696diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38697index 9b6c3bb..baeb5c7 100644
38698--- a/drivers/media/dvb-frontends/dib3000.h
38699+++ b/drivers/media/dvb-frontends/dib3000.h
38700@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38701 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38702 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38703 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38704-};
38705+} __no_const;
38706
38707 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
38708 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38709diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
38710index bc78354..42c9459 100644
38711--- a/drivers/media/pci/cx88/cx88-video.c
38712+++ b/drivers/media/pci/cx88/cx88-video.c
38713@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
38714
38715 /* ------------------------------------------------------------------ */
38716
38717-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38718-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38719-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38720+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38721+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38722+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38723
38724 module_param_array(video_nr, int, NULL, 0444);
38725 module_param_array(vbi_nr, int, NULL, 0444);
38726diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38727index 96c4a17..1305a79 100644
38728--- a/drivers/media/platform/omap/omap_vout.c
38729+++ b/drivers/media/platform/omap/omap_vout.c
38730@@ -63,7 +63,6 @@ enum omap_vout_channels {
38731 OMAP_VIDEO2,
38732 };
38733
38734-static struct videobuf_queue_ops video_vbq_ops;
38735 /* Variables configurable through module params*/
38736 static u32 video1_numbuffers = 3;
38737 static u32 video2_numbuffers = 3;
38738@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
38739 {
38740 struct videobuf_queue *q;
38741 struct omap_vout_device *vout = NULL;
38742+ static struct videobuf_queue_ops video_vbq_ops = {
38743+ .buf_setup = omap_vout_buffer_setup,
38744+ .buf_prepare = omap_vout_buffer_prepare,
38745+ .buf_release = omap_vout_buffer_release,
38746+ .buf_queue = omap_vout_buffer_queue,
38747+ };
38748
38749 vout = video_drvdata(file);
38750 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38751@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
38752 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38753
38754 q = &vout->vbq;
38755- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38756- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38757- video_vbq_ops.buf_release = omap_vout_buffer_release;
38758- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38759 spin_lock_init(&vout->vbq_lock);
38760
38761 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38762diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38763index 04e6490..2df65bf 100644
38764--- a/drivers/media/platform/s5p-tv/mixer.h
38765+++ b/drivers/media/platform/s5p-tv/mixer.h
38766@@ -156,7 +156,7 @@ struct mxr_layer {
38767 /** layer index (unique identifier) */
38768 int idx;
38769 /** callbacks for layer methods */
38770- struct mxr_layer_ops ops;
38771+ struct mxr_layer_ops *ops;
38772 /** format array */
38773 const struct mxr_format **fmt_array;
38774 /** size of format array */
38775diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38776index b93a21f..2535195 100644
38777--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38778+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38779@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38780 {
38781 struct mxr_layer *layer;
38782 int ret;
38783- struct mxr_layer_ops ops = {
38784+ static struct mxr_layer_ops ops = {
38785 .release = mxr_graph_layer_release,
38786 .buffer_set = mxr_graph_buffer_set,
38787 .stream_set = mxr_graph_stream_set,
38788diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38789index b713403..53cb5ad 100644
38790--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38791+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38792@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38793 layer->update_buf = next;
38794 }
38795
38796- layer->ops.buffer_set(layer, layer->update_buf);
38797+ layer->ops->buffer_set(layer, layer->update_buf);
38798
38799 if (done && done != layer->shadow_buf)
38800 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38801diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38802index 82142a2..6de47e8 100644
38803--- a/drivers/media/platform/s5p-tv/mixer_video.c
38804+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38805@@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38806 layer->geo.src.height = layer->geo.src.full_height;
38807
38808 mxr_geometry_dump(mdev, &layer->geo);
38809- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38810+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38811 mxr_geometry_dump(mdev, &layer->geo);
38812 }
38813
38814@@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38815 layer->geo.dst.full_width = mbus_fmt.width;
38816 layer->geo.dst.full_height = mbus_fmt.height;
38817 layer->geo.dst.field = mbus_fmt.field;
38818- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38819+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38820
38821 mxr_geometry_dump(mdev, &layer->geo);
38822 }
38823@@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38824 /* set source size to highest accepted value */
38825 geo->src.full_width = max(geo->dst.full_width, pix->width);
38826 geo->src.full_height = max(geo->dst.full_height, pix->height);
38827- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38828+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38829 mxr_geometry_dump(mdev, &layer->geo);
38830 /* set cropping to total visible screen */
38831 geo->src.width = pix->width;
38832@@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38833 geo->src.x_offset = 0;
38834 geo->src.y_offset = 0;
38835 /* assure consistency of geometry */
38836- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38837+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38838 mxr_geometry_dump(mdev, &layer->geo);
38839 /* set full size to lowest possible value */
38840 geo->src.full_width = 0;
38841 geo->src.full_height = 0;
38842- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38843+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38844 mxr_geometry_dump(mdev, &layer->geo);
38845
38846 /* returning results */
38847@@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38848 target->width = s->r.width;
38849 target->height = s->r.height;
38850
38851- layer->ops.fix_geometry(layer, stage, s->flags);
38852+ layer->ops->fix_geometry(layer, stage, s->flags);
38853
38854 /* retrieve update selection rectangle */
38855 res.left = target->x_offset;
38856@@ -938,13 +938,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38857 mxr_output_get(mdev);
38858
38859 mxr_layer_update_output(layer);
38860- layer->ops.format_set(layer);
38861+ layer->ops->format_set(layer);
38862 /* enabling layer in hardware */
38863 spin_lock_irqsave(&layer->enq_slock, flags);
38864 layer->state = MXR_LAYER_STREAMING;
38865 spin_unlock_irqrestore(&layer->enq_slock, flags);
38866
38867- layer->ops.stream_set(layer, MXR_ENABLE);
38868+ layer->ops->stream_set(layer, MXR_ENABLE);
38869 mxr_streamer_get(mdev);
38870
38871 return 0;
38872@@ -1014,7 +1014,7 @@ static int stop_streaming(struct vb2_queue *vq)
38873 spin_unlock_irqrestore(&layer->enq_slock, flags);
38874
38875 /* disabling layer in hardware */
38876- layer->ops.stream_set(layer, MXR_DISABLE);
38877+ layer->ops->stream_set(layer, MXR_DISABLE);
38878 /* remove one streamer */
38879 mxr_streamer_put(mdev);
38880 /* allow changes in output configuration */
38881@@ -1053,8 +1053,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
38882
38883 void mxr_layer_release(struct mxr_layer *layer)
38884 {
38885- if (layer->ops.release)
38886- layer->ops.release(layer);
38887+ if (layer->ops->release)
38888+ layer->ops->release(layer);
38889 }
38890
38891 void mxr_base_layer_release(struct mxr_layer *layer)
38892@@ -1080,7 +1080,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
38893
38894 layer->mdev = mdev;
38895 layer->idx = idx;
38896- layer->ops = *ops;
38897+ layer->ops = ops;
38898
38899 spin_lock_init(&layer->enq_slock);
38900 INIT_LIST_HEAD(&layer->enq_list);
38901diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38902index 3d13a63..da31bf1 100644
38903--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38904+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38905@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
38906 {
38907 struct mxr_layer *layer;
38908 int ret;
38909- struct mxr_layer_ops ops = {
38910+ static struct mxr_layer_ops ops = {
38911 .release = mxr_vp_layer_release,
38912 .buffer_set = mxr_vp_buffer_set,
38913 .stream_set = mxr_vp_stream_set,
38914diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
38915index 643d80a..56bb96b 100644
38916--- a/drivers/media/radio/radio-cadet.c
38917+++ b/drivers/media/radio/radio-cadet.c
38918@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38919 unsigned char readbuf[RDS_BUFFER];
38920 int i = 0;
38921
38922+ if (count > RDS_BUFFER)
38923+ return -EFAULT;
38924 mutex_lock(&dev->lock);
38925 if (dev->rdsstat == 0)
38926 cadet_start_rds(dev);
38927@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38928 while (i < count && dev->rdsin != dev->rdsout)
38929 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
38930
38931- if (i && copy_to_user(data, readbuf, i))
38932+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
38933 i = -EFAULT;
38934 unlock:
38935 mutex_unlock(&dev->lock);
38936diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
38937index 3940bb0..fb3952a 100644
38938--- a/drivers/media/usb/dvb-usb/cxusb.c
38939+++ b/drivers/media/usb/dvb-usb/cxusb.c
38940@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
38941
38942 struct dib0700_adapter_state {
38943 int (*set_param_save) (struct dvb_frontend *);
38944-};
38945+} __no_const;
38946
38947 static int dib7070_set_param_override(struct dvb_frontend *fe)
38948 {
38949diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
38950index 9578a67..31aa652 100644
38951--- a/drivers/media/usb/dvb-usb/dw2102.c
38952+++ b/drivers/media/usb/dvb-usb/dw2102.c
38953@@ -115,7 +115,7 @@ struct su3000_state {
38954
38955 struct s6x0_state {
38956 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38957-};
38958+} __no_const;
38959
38960 /* debug */
38961 static int dvb_usb_dw2102_debug;
38962diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
38963index 7157af3..139e91a 100644
38964--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
38965+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
38966@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
38967 __u32 reserved;
38968 };
38969
38970-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
38971+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
38972 enum v4l2_memory memory)
38973 {
38974 void __user *up_pln;
38975@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
38976 return 0;
38977 }
38978
38979-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
38980+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
38981 enum v4l2_memory memory)
38982 {
38983 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
38984@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
38985 put_user(kp->start_block, &up->start_block) ||
38986 put_user(kp->blocks, &up->blocks) ||
38987 put_user(tmp, &up->edid) ||
38988- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
38989+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
38990 return -EFAULT;
38991 return 0;
38992 }
38993diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38994index aa6e7c7..cb5de87 100644
38995--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38996+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38997@@ -236,7 +236,7 @@ static void v4l_print_format(const void *arg, bool write_only)
38998 const struct v4l2_vbi_format *vbi;
38999 const struct v4l2_sliced_vbi_format *sliced;
39000 const struct v4l2_window *win;
39001- const struct v4l2_clip *clip;
39002+ const struct v4l2_clip __user *pclip;
39003 unsigned i;
39004
39005 pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
39006@@ -284,12 +284,16 @@ static void v4l_print_format(const void *arg, bool write_only)
39007 win->w.left, win->w.top,
39008 prt_names(win->field, v4l2_field_names),
39009 win->chromakey, win->bitmap, win->global_alpha);
39010- clip = win->clips;
39011+ pclip = win->clips;
39012 for (i = 0; i < win->clipcount; i++) {
39013+ struct v4l2_clip clip;
39014+
39015+ if (copy_from_user(&clip, pclip, sizeof clip))
39016+ break;
39017 printk(KERN_DEBUG "clip %u: wxh=%dx%d, x,y=%d,%d\n",
39018- i, clip->c.width, clip->c.height,
39019- clip->c.left, clip->c.top);
39020- clip = clip->next;
39021+ i, clip.c.width, clip.c.height,
39022+ clip.c.left, clip.c.top);
39023+ pclip = clip.next;
39024 }
39025 break;
39026 case V4L2_BUF_TYPE_VBI_CAPTURE:
39027@@ -1923,7 +1927,8 @@ struct v4l2_ioctl_info {
39028 struct file *file, void *fh, void *p);
39029 } u;
39030 void (*debug)(const void *arg, bool write_only);
39031-};
39032+} __do_const;
39033+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
39034
39035 /* This control needs a priority check */
39036 #define INFO_FL_PRIO (1 << 0)
39037@@ -2108,7 +2113,7 @@ static long __video_do_ioctl(struct file *file,
39038 struct video_device *vfd = video_devdata(file);
39039 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
39040 bool write_only = false;
39041- struct v4l2_ioctl_info default_info;
39042+ v4l2_ioctl_info_no_const default_info;
39043 const struct v4l2_ioctl_info *info;
39044 void *fh = file->private_data;
39045 struct v4l2_fh *vfh = NULL;
39046@@ -2193,7 +2198,7 @@ done:
39047 }
39048
39049 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39050- void * __user *user_ptr, void ***kernel_ptr)
39051+ void __user **user_ptr, void ***kernel_ptr)
39052 {
39053 int ret = 0;
39054
39055@@ -2209,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39056 ret = -EINVAL;
39057 break;
39058 }
39059- *user_ptr = (void __user *)buf->m.planes;
39060+ *user_ptr = (void __force_user *)buf->m.planes;
39061 *kernel_ptr = (void *)&buf->m.planes;
39062 *array_size = sizeof(struct v4l2_plane) * buf->length;
39063 ret = 1;
39064@@ -2244,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39065 ret = -EINVAL;
39066 break;
39067 }
39068- *user_ptr = (void __user *)ctrls->controls;
39069+ *user_ptr = (void __force_user *)ctrls->controls;
39070 *kernel_ptr = (void *)&ctrls->controls;
39071 *array_size = sizeof(struct v4l2_ext_control)
39072 * ctrls->count;
39073diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
39074index fb69baa..3aeea2e 100644
39075--- a/drivers/message/fusion/mptbase.c
39076+++ b/drivers/message/fusion/mptbase.c
39077@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
39078 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
39079 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
39080
39081+#ifdef CONFIG_GRKERNSEC_HIDESYM
39082+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
39083+#else
39084 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
39085 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
39086+#endif
39087+
39088 /*
39089 * Rounding UP to nearest 4-kB boundary here...
39090 */
39091@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
39092 ioc->facts.GlobalCredits);
39093
39094 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
39095+#ifdef CONFIG_GRKERNSEC_HIDESYM
39096+ NULL, NULL);
39097+#else
39098 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
39099+#endif
39100 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
39101 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
39102 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
39103diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
39104index fa43c39..daeb158 100644
39105--- a/drivers/message/fusion/mptsas.c
39106+++ b/drivers/message/fusion/mptsas.c
39107@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
39108 return 0;
39109 }
39110
39111+static inline void
39112+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39113+{
39114+ if (phy_info->port_details) {
39115+ phy_info->port_details->rphy = rphy;
39116+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39117+ ioc->name, rphy));
39118+ }
39119+
39120+ if (rphy) {
39121+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39122+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39123+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39124+ ioc->name, rphy, rphy->dev.release));
39125+ }
39126+}
39127+
39128 /* no mutex */
39129 static void
39130 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
39131@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
39132 return NULL;
39133 }
39134
39135-static inline void
39136-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39137-{
39138- if (phy_info->port_details) {
39139- phy_info->port_details->rphy = rphy;
39140- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39141- ioc->name, rphy));
39142- }
39143-
39144- if (rphy) {
39145- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39146- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39147- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39148- ioc->name, rphy, rphy->dev.release));
39149- }
39150-}
39151-
39152 static inline struct sas_port *
39153 mptsas_get_port(struct mptsas_phyinfo *phy_info)
39154 {
39155diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
39156index 164afa7..b6b2e74 100644
39157--- a/drivers/message/fusion/mptscsih.c
39158+++ b/drivers/message/fusion/mptscsih.c
39159@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
39160
39161 h = shost_priv(SChost);
39162
39163- if (h) {
39164- if (h->info_kbuf == NULL)
39165- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39166- return h->info_kbuf;
39167- h->info_kbuf[0] = '\0';
39168+ if (!h)
39169+ return NULL;
39170
39171- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39172- h->info_kbuf[size-1] = '\0';
39173- }
39174+ if (h->info_kbuf == NULL)
39175+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39176+ return h->info_kbuf;
39177+ h->info_kbuf[0] = '\0';
39178+
39179+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39180+ h->info_kbuf[size-1] = '\0';
39181
39182 return h->info_kbuf;
39183 }
39184diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
39185index 8001aa6..b137580 100644
39186--- a/drivers/message/i2o/i2o_proc.c
39187+++ b/drivers/message/i2o/i2o_proc.c
39188@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
39189 "Array Controller Device"
39190 };
39191
39192-static char *chtostr(char *tmp, u8 *chars, int n)
39193-{
39194- tmp[0] = 0;
39195- return strncat(tmp, (char *)chars, n);
39196-}
39197-
39198 static int i2o_report_query_status(struct seq_file *seq, int block_status,
39199 char *group)
39200 {
39201@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39202 } *result;
39203
39204 i2o_exec_execute_ddm_table ddm_table;
39205- char tmp[28 + 1];
39206
39207 result = kmalloc(sizeof(*result), GFP_KERNEL);
39208 if (!result)
39209@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39210
39211 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
39212 seq_printf(seq, "%-#8x", ddm_table.module_id);
39213- seq_printf(seq, "%-29s",
39214- chtostr(tmp, ddm_table.module_name_version, 28));
39215+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
39216 seq_printf(seq, "%9d ", ddm_table.data_size);
39217 seq_printf(seq, "%8d", ddm_table.code_size);
39218
39219@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39220
39221 i2o_driver_result_table *result;
39222 i2o_driver_store_table *dst;
39223- char tmp[28 + 1];
39224
39225 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
39226 if (result == NULL)
39227@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39228
39229 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
39230 seq_printf(seq, "%-#8x", dst->module_id);
39231- seq_printf(seq, "%-29s",
39232- chtostr(tmp, dst->module_name_version, 28));
39233- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
39234+ seq_printf(seq, "%-.28s", dst->module_name_version);
39235+ seq_printf(seq, "%-.8s", dst->date);
39236 seq_printf(seq, "%8d ", dst->module_size);
39237 seq_printf(seq, "%8d ", dst->mpb_size);
39238 seq_printf(seq, "0x%04x", dst->module_flags);
39239@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39240 // == (allow) 512d bytes (max)
39241 static u16 *work16 = (u16 *) work32;
39242 int token;
39243- char tmp[16 + 1];
39244
39245 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
39246
39247@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39248 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
39249 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
39250 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
39251- seq_printf(seq, "Vendor info : %s\n",
39252- chtostr(tmp, (u8 *) (work32 + 2), 16));
39253- seq_printf(seq, "Product info : %s\n",
39254- chtostr(tmp, (u8 *) (work32 + 6), 16));
39255- seq_printf(seq, "Description : %s\n",
39256- chtostr(tmp, (u8 *) (work32 + 10), 16));
39257- seq_printf(seq, "Product rev. : %s\n",
39258- chtostr(tmp, (u8 *) (work32 + 14), 8));
39259+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
39260+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
39261+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
39262+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
39263
39264 seq_printf(seq, "Serial number : ");
39265 print_serial_number(seq, (u8 *) (work32 + 16),
39266@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39267 u8 pad[256]; // allow up to 256 byte (max) serial number
39268 } result;
39269
39270- char tmp[24 + 1];
39271-
39272 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
39273
39274 if (token < 0) {
39275@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39276 }
39277
39278 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
39279- seq_printf(seq, "Module name : %s\n",
39280- chtostr(tmp, result.module_name, 24));
39281- seq_printf(seq, "Module revision : %s\n",
39282- chtostr(tmp, result.module_rev, 8));
39283+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
39284+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
39285
39286 seq_printf(seq, "Serial number : ");
39287 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
39288@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39289 u8 instance_number[4];
39290 } result;
39291
39292- char tmp[64 + 1];
39293-
39294 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
39295
39296 if (token < 0) {
39297@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39298 return 0;
39299 }
39300
39301- seq_printf(seq, "Device name : %s\n",
39302- chtostr(tmp, result.device_name, 64));
39303- seq_printf(seq, "Service name : %s\n",
39304- chtostr(tmp, result.service_name, 64));
39305- seq_printf(seq, "Physical name : %s\n",
39306- chtostr(tmp, result.physical_location, 64));
39307- seq_printf(seq, "Instance number : %s\n",
39308- chtostr(tmp, result.instance_number, 4));
39309+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
39310+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
39311+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
39312+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
39313
39314 return 0;
39315 }
39316diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
39317index a8c08f3..155fe3d 100644
39318--- a/drivers/message/i2o/iop.c
39319+++ b/drivers/message/i2o/iop.c
39320@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
39321
39322 spin_lock_irqsave(&c->context_list_lock, flags);
39323
39324- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
39325- atomic_inc(&c->context_list_counter);
39326+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
39327+ atomic_inc_unchecked(&c->context_list_counter);
39328
39329- entry->context = atomic_read(&c->context_list_counter);
39330+ entry->context = atomic_read_unchecked(&c->context_list_counter);
39331
39332 list_add(&entry->list, &c->context_list);
39333
39334@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
39335
39336 #if BITS_PER_LONG == 64
39337 spin_lock_init(&c->context_list_lock);
39338- atomic_set(&c->context_list_counter, 0);
39339+ atomic_set_unchecked(&c->context_list_counter, 0);
39340 INIT_LIST_HEAD(&c->context_list);
39341 #endif
39342
39343diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
39344index 45ece11..8efa218 100644
39345--- a/drivers/mfd/janz-cmodio.c
39346+++ b/drivers/mfd/janz-cmodio.c
39347@@ -13,6 +13,7 @@
39348
39349 #include <linux/kernel.h>
39350 #include <linux/module.h>
39351+#include <linux/slab.h>
39352 #include <linux/init.h>
39353 #include <linux/pci.h>
39354 #include <linux/interrupt.h>
39355diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
39356index a5f9888..1c0ed56 100644
39357--- a/drivers/mfd/twl4030-irq.c
39358+++ b/drivers/mfd/twl4030-irq.c
39359@@ -35,6 +35,7 @@
39360 #include <linux/of.h>
39361 #include <linux/irqdomain.h>
39362 #include <linux/i2c/twl.h>
39363+#include <asm/pgtable.h>
39364
39365 #include "twl-core.h"
39366
39367@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
39368 * Install an irq handler for each of the SIH modules;
39369 * clone dummy irq_chip since PIH can't *do* anything
39370 */
39371- twl4030_irq_chip = dummy_irq_chip;
39372- twl4030_irq_chip.name = "twl4030";
39373+ pax_open_kernel();
39374+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
39375+ *(const char **)&twl4030_irq_chip.name = "twl4030";
39376
39377- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39378+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39379+ pax_close_kernel();
39380
39381 for (i = irq_base; i < irq_end; i++) {
39382 irq_set_chip_and_handler(i, &twl4030_irq_chip,
39383diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
39384index 277a8db..0e0b754 100644
39385--- a/drivers/mfd/twl6030-irq.c
39386+++ b/drivers/mfd/twl6030-irq.c
39387@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
39388 * install an irq handler for each of the modules;
39389 * clone dummy irq_chip since PIH can't *do* anything
39390 */
39391- twl6030_irq_chip = dummy_irq_chip;
39392- twl6030_irq_chip.name = "twl6030";
39393- twl6030_irq_chip.irq_set_type = NULL;
39394- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39395+ pax_open_kernel();
39396+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
39397+ *(const char **)&twl6030_irq_chip.name = "twl6030";
39398+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
39399+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39400+ pax_close_kernel();
39401
39402 for (i = irq_base; i < irq_end; i++) {
39403 irq_set_chip_and_handler(i, &twl6030_irq_chip,
39404diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
39405index f32550a..e3e52a2 100644
39406--- a/drivers/misc/c2port/core.c
39407+++ b/drivers/misc/c2port/core.c
39408@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
39409 mutex_init(&c2dev->mutex);
39410
39411 /* Create binary file */
39412- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39413+ pax_open_kernel();
39414+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39415+ pax_close_kernel();
39416 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
39417 if (unlikely(ret))
39418 goto error_device_create_bin_file;
39419diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
39420index 36f5d52..32311c3 100644
39421--- a/drivers/misc/kgdbts.c
39422+++ b/drivers/misc/kgdbts.c
39423@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
39424 char before[BREAK_INSTR_SIZE];
39425 char after[BREAK_INSTR_SIZE];
39426
39427- probe_kernel_read(before, (char *)kgdbts_break_test,
39428+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
39429 BREAK_INSTR_SIZE);
39430 init_simple_test();
39431 ts.tst = plant_and_detach_test;
39432@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
39433 /* Activate test with initial breakpoint */
39434 if (!is_early)
39435 kgdb_breakpoint();
39436- probe_kernel_read(after, (char *)kgdbts_break_test,
39437+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
39438 BREAK_INSTR_SIZE);
39439 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
39440 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
39441diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
39442index 4a87e5c..76bdf5c 100644
39443--- a/drivers/misc/lis3lv02d/lis3lv02d.c
39444+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
39445@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
39446 * the lid is closed. This leads to interrupts as soon as a little move
39447 * is done.
39448 */
39449- atomic_inc(&lis3->count);
39450+ atomic_inc_unchecked(&lis3->count);
39451
39452 wake_up_interruptible(&lis3->misc_wait);
39453 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
39454@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
39455 if (lis3->pm_dev)
39456 pm_runtime_get_sync(lis3->pm_dev);
39457
39458- atomic_set(&lis3->count, 0);
39459+ atomic_set_unchecked(&lis3->count, 0);
39460 return 0;
39461 }
39462
39463@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
39464 add_wait_queue(&lis3->misc_wait, &wait);
39465 while (true) {
39466 set_current_state(TASK_INTERRUPTIBLE);
39467- data = atomic_xchg(&lis3->count, 0);
39468+ data = atomic_xchg_unchecked(&lis3->count, 0);
39469 if (data)
39470 break;
39471
39472@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
39473 struct lis3lv02d, miscdev);
39474
39475 poll_wait(file, &lis3->misc_wait, wait);
39476- if (atomic_read(&lis3->count))
39477+ if (atomic_read_unchecked(&lis3->count))
39478 return POLLIN | POLLRDNORM;
39479 return 0;
39480 }
39481diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
39482index c439c82..1f20f57 100644
39483--- a/drivers/misc/lis3lv02d/lis3lv02d.h
39484+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
39485@@ -297,7 +297,7 @@ struct lis3lv02d {
39486 struct input_polled_dev *idev; /* input device */
39487 struct platform_device *pdev; /* platform device */
39488 struct regulator_bulk_data regulators[2];
39489- atomic_t count; /* interrupt count after last read */
39490+ atomic_unchecked_t count; /* interrupt count after last read */
39491 union axis_conversion ac; /* hw -> logical axis */
39492 int mapped_btns[3];
39493
39494diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
39495index 2f30bad..c4c13d0 100644
39496--- a/drivers/misc/sgi-gru/gruhandles.c
39497+++ b/drivers/misc/sgi-gru/gruhandles.c
39498@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
39499 unsigned long nsec;
39500
39501 nsec = CLKS2NSEC(clks);
39502- atomic_long_inc(&mcs_op_statistics[op].count);
39503- atomic_long_add(nsec, &mcs_op_statistics[op].total);
39504+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
39505+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
39506 if (mcs_op_statistics[op].max < nsec)
39507 mcs_op_statistics[op].max = nsec;
39508 }
39509diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
39510index 950dbe9..eeef0f8 100644
39511--- a/drivers/misc/sgi-gru/gruprocfs.c
39512+++ b/drivers/misc/sgi-gru/gruprocfs.c
39513@@ -32,9 +32,9 @@
39514
39515 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
39516
39517-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
39518+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
39519 {
39520- unsigned long val = atomic_long_read(v);
39521+ unsigned long val = atomic_long_read_unchecked(v);
39522
39523 seq_printf(s, "%16lu %s\n", val, id);
39524 }
39525@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
39526
39527 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
39528 for (op = 0; op < mcsop_last; op++) {
39529- count = atomic_long_read(&mcs_op_statistics[op].count);
39530- total = atomic_long_read(&mcs_op_statistics[op].total);
39531+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
39532+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
39533 max = mcs_op_statistics[op].max;
39534 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
39535 count ? total / count : 0, max);
39536diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
39537index 5c3ce24..4915ccb 100644
39538--- a/drivers/misc/sgi-gru/grutables.h
39539+++ b/drivers/misc/sgi-gru/grutables.h
39540@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
39541 * GRU statistics.
39542 */
39543 struct gru_stats_s {
39544- atomic_long_t vdata_alloc;
39545- atomic_long_t vdata_free;
39546- atomic_long_t gts_alloc;
39547- atomic_long_t gts_free;
39548- atomic_long_t gms_alloc;
39549- atomic_long_t gms_free;
39550- atomic_long_t gts_double_allocate;
39551- atomic_long_t assign_context;
39552- atomic_long_t assign_context_failed;
39553- atomic_long_t free_context;
39554- atomic_long_t load_user_context;
39555- atomic_long_t load_kernel_context;
39556- atomic_long_t lock_kernel_context;
39557- atomic_long_t unlock_kernel_context;
39558- atomic_long_t steal_user_context;
39559- atomic_long_t steal_kernel_context;
39560- atomic_long_t steal_context_failed;
39561- atomic_long_t nopfn;
39562- atomic_long_t asid_new;
39563- atomic_long_t asid_next;
39564- atomic_long_t asid_wrap;
39565- atomic_long_t asid_reuse;
39566- atomic_long_t intr;
39567- atomic_long_t intr_cbr;
39568- atomic_long_t intr_tfh;
39569- atomic_long_t intr_spurious;
39570- atomic_long_t intr_mm_lock_failed;
39571- atomic_long_t call_os;
39572- atomic_long_t call_os_wait_queue;
39573- atomic_long_t user_flush_tlb;
39574- atomic_long_t user_unload_context;
39575- atomic_long_t user_exception;
39576- atomic_long_t set_context_option;
39577- atomic_long_t check_context_retarget_intr;
39578- atomic_long_t check_context_unload;
39579- atomic_long_t tlb_dropin;
39580- atomic_long_t tlb_preload_page;
39581- atomic_long_t tlb_dropin_fail_no_asid;
39582- atomic_long_t tlb_dropin_fail_upm;
39583- atomic_long_t tlb_dropin_fail_invalid;
39584- atomic_long_t tlb_dropin_fail_range_active;
39585- atomic_long_t tlb_dropin_fail_idle;
39586- atomic_long_t tlb_dropin_fail_fmm;
39587- atomic_long_t tlb_dropin_fail_no_exception;
39588- atomic_long_t tfh_stale_on_fault;
39589- atomic_long_t mmu_invalidate_range;
39590- atomic_long_t mmu_invalidate_page;
39591- atomic_long_t flush_tlb;
39592- atomic_long_t flush_tlb_gru;
39593- atomic_long_t flush_tlb_gru_tgh;
39594- atomic_long_t flush_tlb_gru_zero_asid;
39595+ atomic_long_unchecked_t vdata_alloc;
39596+ atomic_long_unchecked_t vdata_free;
39597+ atomic_long_unchecked_t gts_alloc;
39598+ atomic_long_unchecked_t gts_free;
39599+ atomic_long_unchecked_t gms_alloc;
39600+ atomic_long_unchecked_t gms_free;
39601+ atomic_long_unchecked_t gts_double_allocate;
39602+ atomic_long_unchecked_t assign_context;
39603+ atomic_long_unchecked_t assign_context_failed;
39604+ atomic_long_unchecked_t free_context;
39605+ atomic_long_unchecked_t load_user_context;
39606+ atomic_long_unchecked_t load_kernel_context;
39607+ atomic_long_unchecked_t lock_kernel_context;
39608+ atomic_long_unchecked_t unlock_kernel_context;
39609+ atomic_long_unchecked_t steal_user_context;
39610+ atomic_long_unchecked_t steal_kernel_context;
39611+ atomic_long_unchecked_t steal_context_failed;
39612+ atomic_long_unchecked_t nopfn;
39613+ atomic_long_unchecked_t asid_new;
39614+ atomic_long_unchecked_t asid_next;
39615+ atomic_long_unchecked_t asid_wrap;
39616+ atomic_long_unchecked_t asid_reuse;
39617+ atomic_long_unchecked_t intr;
39618+ atomic_long_unchecked_t intr_cbr;
39619+ atomic_long_unchecked_t intr_tfh;
39620+ atomic_long_unchecked_t intr_spurious;
39621+ atomic_long_unchecked_t intr_mm_lock_failed;
39622+ atomic_long_unchecked_t call_os;
39623+ atomic_long_unchecked_t call_os_wait_queue;
39624+ atomic_long_unchecked_t user_flush_tlb;
39625+ atomic_long_unchecked_t user_unload_context;
39626+ atomic_long_unchecked_t user_exception;
39627+ atomic_long_unchecked_t set_context_option;
39628+ atomic_long_unchecked_t check_context_retarget_intr;
39629+ atomic_long_unchecked_t check_context_unload;
39630+ atomic_long_unchecked_t tlb_dropin;
39631+ atomic_long_unchecked_t tlb_preload_page;
39632+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
39633+ atomic_long_unchecked_t tlb_dropin_fail_upm;
39634+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
39635+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
39636+ atomic_long_unchecked_t tlb_dropin_fail_idle;
39637+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
39638+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
39639+ atomic_long_unchecked_t tfh_stale_on_fault;
39640+ atomic_long_unchecked_t mmu_invalidate_range;
39641+ atomic_long_unchecked_t mmu_invalidate_page;
39642+ atomic_long_unchecked_t flush_tlb;
39643+ atomic_long_unchecked_t flush_tlb_gru;
39644+ atomic_long_unchecked_t flush_tlb_gru_tgh;
39645+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
39646
39647- atomic_long_t copy_gpa;
39648- atomic_long_t read_gpa;
39649+ atomic_long_unchecked_t copy_gpa;
39650+ atomic_long_unchecked_t read_gpa;
39651
39652- atomic_long_t mesq_receive;
39653- atomic_long_t mesq_receive_none;
39654- atomic_long_t mesq_send;
39655- atomic_long_t mesq_send_failed;
39656- atomic_long_t mesq_noop;
39657- atomic_long_t mesq_send_unexpected_error;
39658- atomic_long_t mesq_send_lb_overflow;
39659- atomic_long_t mesq_send_qlimit_reached;
39660- atomic_long_t mesq_send_amo_nacked;
39661- atomic_long_t mesq_send_put_nacked;
39662- atomic_long_t mesq_page_overflow;
39663- atomic_long_t mesq_qf_locked;
39664- atomic_long_t mesq_qf_noop_not_full;
39665- atomic_long_t mesq_qf_switch_head_failed;
39666- atomic_long_t mesq_qf_unexpected_error;
39667- atomic_long_t mesq_noop_unexpected_error;
39668- atomic_long_t mesq_noop_lb_overflow;
39669- atomic_long_t mesq_noop_qlimit_reached;
39670- atomic_long_t mesq_noop_amo_nacked;
39671- atomic_long_t mesq_noop_put_nacked;
39672- atomic_long_t mesq_noop_page_overflow;
39673+ atomic_long_unchecked_t mesq_receive;
39674+ atomic_long_unchecked_t mesq_receive_none;
39675+ atomic_long_unchecked_t mesq_send;
39676+ atomic_long_unchecked_t mesq_send_failed;
39677+ atomic_long_unchecked_t mesq_noop;
39678+ atomic_long_unchecked_t mesq_send_unexpected_error;
39679+ atomic_long_unchecked_t mesq_send_lb_overflow;
39680+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39681+ atomic_long_unchecked_t mesq_send_amo_nacked;
39682+ atomic_long_unchecked_t mesq_send_put_nacked;
39683+ atomic_long_unchecked_t mesq_page_overflow;
39684+ atomic_long_unchecked_t mesq_qf_locked;
39685+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39686+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39687+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39688+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39689+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39690+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39691+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39692+ atomic_long_unchecked_t mesq_noop_put_nacked;
39693+ atomic_long_unchecked_t mesq_noop_page_overflow;
39694
39695 };
39696
39697@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39698 tghop_invalidate, mcsop_last};
39699
39700 struct mcs_op_statistic {
39701- atomic_long_t count;
39702- atomic_long_t total;
39703+ atomic_long_unchecked_t count;
39704+ atomic_long_unchecked_t total;
39705 unsigned long max;
39706 };
39707
39708@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39709
39710 #define STAT(id) do { \
39711 if (gru_options & OPT_STATS) \
39712- atomic_long_inc(&gru_stats.id); \
39713+ atomic_long_inc_unchecked(&gru_stats.id); \
39714 } while (0)
39715
39716 #ifdef CONFIG_SGI_GRU_DEBUG
39717diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39718index c862cd4..0d176fe 100644
39719--- a/drivers/misc/sgi-xp/xp.h
39720+++ b/drivers/misc/sgi-xp/xp.h
39721@@ -288,7 +288,7 @@ struct xpc_interface {
39722 xpc_notify_func, void *);
39723 void (*received) (short, int, void *);
39724 enum xp_retval (*partid_to_nasids) (short, void *);
39725-};
39726+} __no_const;
39727
39728 extern struct xpc_interface xpc_interface;
39729
39730diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39731index b94d5f7..7f494c5 100644
39732--- a/drivers/misc/sgi-xp/xpc.h
39733+++ b/drivers/misc/sgi-xp/xpc.h
39734@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39735 void (*received_payload) (struct xpc_channel *, void *);
39736 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39737 };
39738+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39739
39740 /* struct xpc_partition act_state values (for XPC HB) */
39741
39742@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39743 /* found in xpc_main.c */
39744 extern struct device *xpc_part;
39745 extern struct device *xpc_chan;
39746-extern struct xpc_arch_operations xpc_arch_ops;
39747+extern xpc_arch_operations_no_const xpc_arch_ops;
39748 extern int xpc_disengage_timelimit;
39749 extern int xpc_disengage_timedout;
39750 extern int xpc_activate_IRQ_rcvd;
39751diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39752index d971817..33bdca5 100644
39753--- a/drivers/misc/sgi-xp/xpc_main.c
39754+++ b/drivers/misc/sgi-xp/xpc_main.c
39755@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39756 .notifier_call = xpc_system_die,
39757 };
39758
39759-struct xpc_arch_operations xpc_arch_ops;
39760+xpc_arch_operations_no_const xpc_arch_ops;
39761
39762 /*
39763 * Timer function to enforce the timelimit on the partition disengage.
39764@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39765
39766 if (((die_args->trapnr == X86_TRAP_MF) ||
39767 (die_args->trapnr == X86_TRAP_XF)) &&
39768- !user_mode_vm(die_args->regs))
39769+ !user_mode(die_args->regs))
39770 xpc_die_deactivate();
39771
39772 break;
39773diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39774index 49f04bc..65660c2 100644
39775--- a/drivers/mmc/core/mmc_ops.c
39776+++ b/drivers/mmc/core/mmc_ops.c
39777@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39778 void *data_buf;
39779 int is_on_stack;
39780
39781- is_on_stack = object_is_on_stack(buf);
39782+ is_on_stack = object_starts_on_stack(buf);
39783 if (is_on_stack) {
39784 /*
39785 * dma onto stack is unsafe/nonportable, but callers to this
39786diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39787index 53b8fd9..615b462 100644
39788--- a/drivers/mmc/host/dw_mmc.h
39789+++ b/drivers/mmc/host/dw_mmc.h
39790@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
39791 int (*parse_dt)(struct dw_mci *host);
39792 int (*setup_bus)(struct dw_mci *host,
39793 struct device_node *slot_np, u8 bus_width);
39794-};
39795+} __do_const;
39796 #endif /* _DW_MMC_H_ */
39797diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39798index 7363efe..681558e 100644
39799--- a/drivers/mmc/host/sdhci-s3c.c
39800+++ b/drivers/mmc/host/sdhci-s3c.c
39801@@ -720,9 +720,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39802 * we can use overriding functions instead of default.
39803 */
39804 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39805- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39806- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39807- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39808+ pax_open_kernel();
39809+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39810+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39811+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39812+ pax_close_kernel();
39813 }
39814
39815 /* It supports additional host capabilities if needed */
39816diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
39817index a4eb8b5..8c0628f 100644
39818--- a/drivers/mtd/devices/doc2000.c
39819+++ b/drivers/mtd/devices/doc2000.c
39820@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39821
39822 /* The ECC will not be calculated correctly if less than 512 is written */
39823 /* DBB-
39824- if (len != 0x200 && eccbuf)
39825+ if (len != 0x200)
39826 printk(KERN_WARNING
39827 "ECC needs a full sector write (adr: %lx size %lx)\n",
39828 (long) to, (long) len);
39829diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39830index 0c8bb6b..6f35deb 100644
39831--- a/drivers/mtd/nand/denali.c
39832+++ b/drivers/mtd/nand/denali.c
39833@@ -24,6 +24,7 @@
39834 #include <linux/slab.h>
39835 #include <linux/mtd/mtd.h>
39836 #include <linux/module.h>
39837+#include <linux/slab.h>
39838
39839 #include "denali.h"
39840
39841diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39842index 51b9d6a..52af9a7 100644
39843--- a/drivers/mtd/nftlmount.c
39844+++ b/drivers/mtd/nftlmount.c
39845@@ -24,6 +24,7 @@
39846 #include <asm/errno.h>
39847 #include <linux/delay.h>
39848 #include <linux/slab.h>
39849+#include <linux/sched.h>
39850 #include <linux/mtd/mtd.h>
39851 #include <linux/mtd/nand.h>
39852 #include <linux/mtd/nftl.h>
39853diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39854index 8dd6ba5..419cc1d 100644
39855--- a/drivers/mtd/sm_ftl.c
39856+++ b/drivers/mtd/sm_ftl.c
39857@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39858 #define SM_CIS_VENDOR_OFFSET 0x59
39859 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39860 {
39861- struct attribute_group *attr_group;
39862+ attribute_group_no_const *attr_group;
39863 struct attribute **attributes;
39864 struct sm_sysfs_attribute *vendor_attribute;
39865
39866diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39867index dbbea0e..3f4a0b1 100644
39868--- a/drivers/net/bonding/bond_main.c
39869+++ b/drivers/net/bonding/bond_main.c
39870@@ -4822,7 +4822,7 @@ static unsigned int bond_get_num_tx_queues(void)
39871 return tx_queues;
39872 }
39873
39874-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39875+static struct rtnl_link_ops bond_link_ops = {
39876 .kind = "bond",
39877 .priv_size = sizeof(struct bonding),
39878 .setup = bond_setup,
39879@@ -4947,8 +4947,8 @@ static void __exit bonding_exit(void)
39880
39881 bond_destroy_debugfs();
39882
39883- rtnl_link_unregister(&bond_link_ops);
39884 unregister_pernet_subsys(&bond_net_ops);
39885+ rtnl_link_unregister(&bond_link_ops);
39886
39887 #ifdef CONFIG_NET_POLL_CONTROLLER
39888 /*
39889diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39890index e1d2643..7f4133b 100644
39891--- a/drivers/net/ethernet/8390/ax88796.c
39892+++ b/drivers/net/ethernet/8390/ax88796.c
39893@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39894 if (ax->plat->reg_offsets)
39895 ei_local->reg_offset = ax->plat->reg_offsets;
39896 else {
39897+ resource_size_t _mem_size = mem_size;
39898+ do_div(_mem_size, 0x18);
39899 ei_local->reg_offset = ax->reg_offsets;
39900 for (ret = 0; ret < 0x18; ret++)
39901- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39902+ ax->reg_offsets[ret] = _mem_size * ret;
39903 }
39904
39905 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39906diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39907index aee7671..3ca2651 100644
39908--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39909+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39910@@ -1093,7 +1093,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39911 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39912 {
39913 /* RX_MODE controlling object */
39914- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39915+ bnx2x_init_rx_mode_obj(bp);
39916
39917 /* multicast configuration controlling object */
39918 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39919diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39920index 7306416..5fb7fb5 100644
39921--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39922+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39923@@ -2381,15 +2381,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
39924 return rc;
39925 }
39926
39927-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39928- struct bnx2x_rx_mode_obj *o)
39929+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
39930 {
39931 if (CHIP_IS_E1x(bp)) {
39932- o->wait_comp = bnx2x_empty_rx_mode_wait;
39933- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
39934+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
39935+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
39936 } else {
39937- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
39938- o->config_rx_mode = bnx2x_set_rx_mode_e2;
39939+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
39940+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
39941 }
39942 }
39943
39944diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39945index ff90760..08d8aed 100644
39946--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39947+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39948@@ -1306,8 +1306,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
39949
39950 /********************* RX MODE ****************/
39951
39952-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39953- struct bnx2x_rx_mode_obj *o);
39954+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
39955
39956 /**
39957 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
39958diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
39959index 25309bf..fcfd54c 100644
39960--- a/drivers/net/ethernet/broadcom/tg3.h
39961+++ b/drivers/net/ethernet/broadcom/tg3.h
39962@@ -147,6 +147,7 @@
39963 #define CHIPREV_ID_5750_A0 0x4000
39964 #define CHIPREV_ID_5750_A1 0x4001
39965 #define CHIPREV_ID_5750_A3 0x4003
39966+#define CHIPREV_ID_5750_C1 0x4201
39967 #define CHIPREV_ID_5750_C2 0x4202
39968 #define CHIPREV_ID_5752_A0_HW 0x5000
39969 #define CHIPREV_ID_5752_A0 0x6000
39970diff --git a/drivers/net/ethernet/brocade/bna/bnad_debugfs.c b/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
39971index 6e8bc9d..94d957d 100644
39972--- a/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
39973+++ b/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
39974@@ -244,7 +244,7 @@ bnad_debugfs_lseek(struct file *file, loff_t offset, int orig)
39975 file->f_pos += offset;
39976 break;
39977 case 2:
39978- file->f_pos = debug->buffer_len - offset;
39979+ file->f_pos = debug->buffer_len + offset;
39980 break;
39981 default:
39982 return -EINVAL;
39983diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39984index 8cffcdf..aadf043 100644
39985--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39986+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39987@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39988 */
39989 struct l2t_skb_cb {
39990 arp_failure_handler_func arp_failure_handler;
39991-};
39992+} __no_const;
39993
39994 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39995
39996diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39997index 4c83003..2a2a5b9 100644
39998--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39999+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
40000@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40001 for (i=0; i<ETH_ALEN; i++) {
40002 tmp.addr[i] = dev->dev_addr[i];
40003 }
40004- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
40005+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
40006 break;
40007
40008 case DE4X5_SET_HWADDR: /* Set the hardware address */
40009@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40010 spin_lock_irqsave(&lp->lock, flags);
40011 memcpy(&statbuf, &lp->pktStats, ioc->len);
40012 spin_unlock_irqrestore(&lp->lock, flags);
40013- if (copy_to_user(ioc->data, &statbuf, ioc->len))
40014+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
40015 return -EFAULT;
40016 break;
40017 }
40018diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
40019index 2886c9b..db71673 100644
40020--- a/drivers/net/ethernet/emulex/benet/be_main.c
40021+++ b/drivers/net/ethernet/emulex/benet/be_main.c
40022@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
40023
40024 if (wrapped)
40025 newacc += 65536;
40026- ACCESS_ONCE(*acc) = newacc;
40027+ ACCESS_ONCE_RW(*acc) = newacc;
40028 }
40029
40030 void be_parse_stats(struct be_adapter *adapter)
40031diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
40032index 7c361d1..57e3ff1 100644
40033--- a/drivers/net/ethernet/faraday/ftgmac100.c
40034+++ b/drivers/net/ethernet/faraday/ftgmac100.c
40035@@ -31,6 +31,8 @@
40036 #include <linux/netdevice.h>
40037 #include <linux/phy.h>
40038 #include <linux/platform_device.h>
40039+#include <linux/interrupt.h>
40040+#include <linux/irqreturn.h>
40041 #include <net/ip.h>
40042
40043 #include "ftgmac100.h"
40044diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
40045index b5ea8fb..bd25e9a 100644
40046--- a/drivers/net/ethernet/faraday/ftmac100.c
40047+++ b/drivers/net/ethernet/faraday/ftmac100.c
40048@@ -31,6 +31,8 @@
40049 #include <linux/module.h>
40050 #include <linux/netdevice.h>
40051 #include <linux/platform_device.h>
40052+#include <linux/interrupt.h>
40053+#include <linux/irqreturn.h>
40054
40055 #include "ftmac100.h"
40056
40057diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40058index 331987d..3be1135 100644
40059--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40060+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40061@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
40062 }
40063
40064 /* update the base incval used to calculate frequency adjustment */
40065- ACCESS_ONCE(adapter->base_incval) = incval;
40066+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
40067 smp_mb();
40068
40069 /* need lock to prevent incorrect read while modifying cyclecounter */
40070diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40071index fbe5363..266b4e3 100644
40072--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
40073+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40074@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40075 struct __vxge_hw_fifo *fifo;
40076 struct vxge_hw_fifo_config *config;
40077 u32 txdl_size, txdl_per_memblock;
40078- struct vxge_hw_mempool_cbs fifo_mp_callback;
40079+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
40080+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
40081+ };
40082+
40083 struct __vxge_hw_virtualpath *vpath;
40084
40085 if ((vp == NULL) || (attr == NULL)) {
40086@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40087 goto exit;
40088 }
40089
40090- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
40091-
40092 fifo->mempool =
40093 __vxge_hw_mempool_create(vpath->hldev,
40094 fifo->config->memblock_size,
40095diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40096index 5c033f2..7bbb0d8 100644
40097--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40098+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40099@@ -1894,7 +1894,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
40100 op_mode = QLCRDX(ahw, QLC_83XX_DRV_OP_MODE);
40101
40102 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
40103- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
40104+ pax_open_kernel();
40105+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
40106+ pax_close_kernel();
40107 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40108 } else {
40109 return -EIO;
40110diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40111index b0c3de9..fc5857e 100644
40112--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40113+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40114@@ -200,15 +200,21 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
40115 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
40116 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
40117 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40118- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
40119+ pax_open_kernel();
40120+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
40121+ pax_close_kernel();
40122 } else if (priv_level == QLCNIC_PRIV_FUNC) {
40123 ahw->op_mode = QLCNIC_PRIV_FUNC;
40124 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
40125- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
40126+ pax_open_kernel();
40127+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
40128+ pax_close_kernel();
40129 } else if (priv_level == QLCNIC_MGMT_FUNC) {
40130 ahw->op_mode = QLCNIC_MGMT_FUNC;
40131 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40132- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
40133+ pax_open_kernel();
40134+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
40135+ pax_close_kernel();
40136 } else {
40137 return -EIO;
40138 }
40139diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
40140index 54fd2ef..33c8a4f 100644
40141--- a/drivers/net/ethernet/realtek/r8169.c
40142+++ b/drivers/net/ethernet/realtek/r8169.c
40143@@ -740,22 +740,22 @@ struct rtl8169_private {
40144 struct mdio_ops {
40145 void (*write)(struct rtl8169_private *, int, int);
40146 int (*read)(struct rtl8169_private *, int);
40147- } mdio_ops;
40148+ } __no_const mdio_ops;
40149
40150 struct pll_power_ops {
40151 void (*down)(struct rtl8169_private *);
40152 void (*up)(struct rtl8169_private *);
40153- } pll_power_ops;
40154+ } __no_const pll_power_ops;
40155
40156 struct jumbo_ops {
40157 void (*enable)(struct rtl8169_private *);
40158 void (*disable)(struct rtl8169_private *);
40159- } jumbo_ops;
40160+ } __no_const jumbo_ops;
40161
40162 struct csi_ops {
40163 void (*write)(struct rtl8169_private *, int, int);
40164 u32 (*read)(struct rtl8169_private *, int);
40165- } csi_ops;
40166+ } __no_const csi_ops;
40167
40168 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
40169 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
40170diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
40171index 3f93624..cf01144 100644
40172--- a/drivers/net/ethernet/sfc/ptp.c
40173+++ b/drivers/net/ethernet/sfc/ptp.c
40174@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
40175 (u32)((u64)ptp->start.dma_addr >> 32));
40176
40177 /* Clear flag that signals MC ready */
40178- ACCESS_ONCE(*start) = 0;
40179+ ACCESS_ONCE_RW(*start) = 0;
40180 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
40181 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
40182
40183diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40184index 50617c5..b13724c 100644
40185--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40186+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40187@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
40188
40189 writel(value, ioaddr + MMC_CNTRL);
40190
40191- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40192- MMC_CNTRL, value);
40193+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40194+// MMC_CNTRL, value);
40195 }
40196
40197 /* To mask all all interrupts.*/
40198diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
40199index e6fe0d8..2b7d752 100644
40200--- a/drivers/net/hyperv/hyperv_net.h
40201+++ b/drivers/net/hyperv/hyperv_net.h
40202@@ -101,7 +101,7 @@ struct rndis_device {
40203
40204 enum rndis_device_state state;
40205 bool link_state;
40206- atomic_t new_req_id;
40207+ atomic_unchecked_t new_req_id;
40208
40209 spinlock_t request_lock;
40210 struct list_head req_list;
40211diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
40212index 0775f0a..d4fb316 100644
40213--- a/drivers/net/hyperv/rndis_filter.c
40214+++ b/drivers/net/hyperv/rndis_filter.c
40215@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
40216 * template
40217 */
40218 set = &rndis_msg->msg.set_req;
40219- set->req_id = atomic_inc_return(&dev->new_req_id);
40220+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40221
40222 /* Add to the request list */
40223 spin_lock_irqsave(&dev->request_lock, flags);
40224@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
40225
40226 /* Setup the rndis set */
40227 halt = &request->request_msg.msg.halt_req;
40228- halt->req_id = atomic_inc_return(&dev->new_req_id);
40229+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40230
40231 /* Ignore return since this msg is optional. */
40232 rndis_filter_send_request(dev, request);
40233diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
40234index 8f1c256..a2991d1 100644
40235--- a/drivers/net/ieee802154/fakehard.c
40236+++ b/drivers/net/ieee802154/fakehard.c
40237@@ -385,7 +385,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
40238 phy->transmit_power = 0xbf;
40239
40240 dev->netdev_ops = &fake_ops;
40241- dev->ml_priv = &fake_mlme;
40242+ dev->ml_priv = (void *)&fake_mlme;
40243
40244 priv = netdev_priv(dev);
40245 priv->phy = phy;
40246diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
40247index 011062e..ada88e9 100644
40248--- a/drivers/net/macvlan.c
40249+++ b/drivers/net/macvlan.c
40250@@ -892,13 +892,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
40251 int macvlan_link_register(struct rtnl_link_ops *ops)
40252 {
40253 /* common fields */
40254- ops->priv_size = sizeof(struct macvlan_dev);
40255- ops->validate = macvlan_validate;
40256- ops->maxtype = IFLA_MACVLAN_MAX;
40257- ops->policy = macvlan_policy;
40258- ops->changelink = macvlan_changelink;
40259- ops->get_size = macvlan_get_size;
40260- ops->fill_info = macvlan_fill_info;
40261+ pax_open_kernel();
40262+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
40263+ *(void **)&ops->validate = macvlan_validate;
40264+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
40265+ *(const void **)&ops->policy = macvlan_policy;
40266+ *(void **)&ops->changelink = macvlan_changelink;
40267+ *(void **)&ops->get_size = macvlan_get_size;
40268+ *(void **)&ops->fill_info = macvlan_fill_info;
40269+ pax_close_kernel();
40270
40271 return rtnl_link_register(ops);
40272 };
40273@@ -954,7 +956,7 @@ static int macvlan_device_event(struct notifier_block *unused,
40274 return NOTIFY_DONE;
40275 }
40276
40277-static struct notifier_block macvlan_notifier_block __read_mostly = {
40278+static struct notifier_block macvlan_notifier_block = {
40279 .notifier_call = macvlan_device_event,
40280 };
40281
40282diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
40283index acf6450..8f771b7 100644
40284--- a/drivers/net/macvtap.c
40285+++ b/drivers/net/macvtap.c
40286@@ -525,8 +525,10 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
40287 return -EMSGSIZE;
40288 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
40289 if (num_pages != size) {
40290- for (i = 0; i < num_pages; i++)
40291- put_page(page[i]);
40292+ int j;
40293+
40294+ for (j = 0; j < num_pages; j++)
40295+ put_page(page[i + j]);
40296 return -EFAULT;
40297 }
40298 truesize = size * PAGE_SIZE;
40299@@ -1099,7 +1101,7 @@ static int macvtap_device_event(struct notifier_block *unused,
40300 return NOTIFY_DONE;
40301 }
40302
40303-static struct notifier_block macvtap_notifier_block __read_mostly = {
40304+static struct notifier_block macvtap_notifier_block = {
40305 .notifier_call = macvtap_device_event,
40306 };
40307
40308diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
40309index daec9b0..6428fcb 100644
40310--- a/drivers/net/phy/mdio-bitbang.c
40311+++ b/drivers/net/phy/mdio-bitbang.c
40312@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
40313 struct mdiobb_ctrl *ctrl = bus->priv;
40314
40315 module_put(ctrl->ops->owner);
40316+ mdiobus_unregister(bus);
40317 mdiobus_free(bus);
40318 }
40319 EXPORT_SYMBOL(free_mdio_bitbang);
40320diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
40321index 72ff14b..11d442d 100644
40322--- a/drivers/net/ppp/ppp_generic.c
40323+++ b/drivers/net/ppp/ppp_generic.c
40324@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40325 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
40326 struct ppp_stats stats;
40327 struct ppp_comp_stats cstats;
40328- char *vers;
40329
40330 switch (cmd) {
40331 case SIOCGPPPSTATS:
40332@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40333 break;
40334
40335 case SIOCGPPPVER:
40336- vers = PPP_VERSION;
40337- if (copy_to_user(addr, vers, strlen(vers) + 1))
40338+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
40339 break;
40340 err = 0;
40341 break;
40342diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
40343index 1252d9c..80e660b 100644
40344--- a/drivers/net/slip/slhc.c
40345+++ b/drivers/net/slip/slhc.c
40346@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
40347 register struct tcphdr *thp;
40348 register struct iphdr *ip;
40349 register struct cstate *cs;
40350- int len, hdrlen;
40351+ long len, hdrlen;
40352 unsigned char *cp = icp;
40353
40354 /* We've got a compressed packet; read the change byte */
40355diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
40356index 0017b67..ab8f595 100644
40357--- a/drivers/net/team/team.c
40358+++ b/drivers/net/team/team.c
40359@@ -2668,7 +2668,7 @@ static int team_device_event(struct notifier_block *unused,
40360 return NOTIFY_DONE;
40361 }
40362
40363-static struct notifier_block team_notifier_block __read_mostly = {
40364+static struct notifier_block team_notifier_block = {
40365 .notifier_call = team_device_event,
40366 };
40367
40368diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40369index 8ad822e..eb895f1 100644
40370--- a/drivers/net/tun.c
40371+++ b/drivers/net/tun.c
40372@@ -1013,8 +1013,10 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
40373 return -EMSGSIZE;
40374 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
40375 if (num_pages != size) {
40376- for (i = 0; i < num_pages; i++)
40377- put_page(page[i]);
40378+ int j;
40379+
40380+ for (j = 0; j < num_pages; j++)
40381+ put_page(page[i + j]);
40382 return -EFAULT;
40383 }
40384 truesize = size * PAGE_SIZE;
40385@@ -1859,7 +1861,7 @@ unlock:
40386 }
40387
40388 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40389- unsigned long arg, int ifreq_len)
40390+ unsigned long arg, size_t ifreq_len)
40391 {
40392 struct tun_file *tfile = file->private_data;
40393 struct tun_struct *tun;
40394@@ -1871,6 +1873,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40395 int vnet_hdr_sz;
40396 int ret;
40397
40398+ if (ifreq_len > sizeof ifr)
40399+ return -EFAULT;
40400+
40401 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40402 if (copy_from_user(&ifr, argp, ifreq_len))
40403 return -EFAULT;
40404diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40405index e2dd324..be92fcf 100644
40406--- a/drivers/net/usb/hso.c
40407+++ b/drivers/net/usb/hso.c
40408@@ -71,7 +71,7 @@
40409 #include <asm/byteorder.h>
40410 #include <linux/serial_core.h>
40411 #include <linux/serial.h>
40412-
40413+#include <asm/local.h>
40414
40415 #define MOD_AUTHOR "Option Wireless"
40416 #define MOD_DESCRIPTION "USB High Speed Option driver"
40417@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40418 struct urb *urb;
40419
40420 urb = serial->rx_urb[0];
40421- if (serial->port.count > 0) {
40422+ if (atomic_read(&serial->port.count) > 0) {
40423 count = put_rxbuf_data(urb, serial);
40424 if (count == -1)
40425 return;
40426@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40427 DUMP1(urb->transfer_buffer, urb->actual_length);
40428
40429 /* Anyone listening? */
40430- if (serial->port.count == 0)
40431+ if (atomic_read(&serial->port.count) == 0)
40432 return;
40433
40434 if (status == 0) {
40435@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40436 tty_port_tty_set(&serial->port, tty);
40437
40438 /* check for port already opened, if not set the termios */
40439- serial->port.count++;
40440- if (serial->port.count == 1) {
40441+ if (atomic_inc_return(&serial->port.count) == 1) {
40442 serial->rx_state = RX_IDLE;
40443 /* Force default termio settings */
40444 _hso_serial_set_termios(tty, NULL);
40445@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40446 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40447 if (result) {
40448 hso_stop_serial_device(serial->parent);
40449- serial->port.count--;
40450+ atomic_dec(&serial->port.count);
40451 kref_put(&serial->parent->ref, hso_serial_ref_free);
40452 }
40453 } else {
40454@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40455
40456 /* reset the rts and dtr */
40457 /* do the actual close */
40458- serial->port.count--;
40459+ atomic_dec(&serial->port.count);
40460
40461- if (serial->port.count <= 0) {
40462- serial->port.count = 0;
40463+ if (atomic_read(&serial->port.count) <= 0) {
40464+ atomic_set(&serial->port.count, 0);
40465 tty_port_tty_set(&serial->port, NULL);
40466 if (!usb_gone)
40467 hso_stop_serial_device(serial->parent);
40468@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40469
40470 /* the actual setup */
40471 spin_lock_irqsave(&serial->serial_lock, flags);
40472- if (serial->port.count)
40473+ if (atomic_read(&serial->port.count))
40474 _hso_serial_set_termios(tty, old);
40475 else
40476 tty->termios = *old;
40477@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
40478 D1("Pending read interrupt on port %d\n", i);
40479 spin_lock(&serial->serial_lock);
40480 if (serial->rx_state == RX_IDLE &&
40481- serial->port.count > 0) {
40482+ atomic_read(&serial->port.count) > 0) {
40483 /* Setup and send a ctrl req read on
40484 * port i */
40485 if (!serial->rx_urb_filled[0]) {
40486@@ -3066,7 +3065,7 @@ static int hso_resume(struct usb_interface *iface)
40487 /* Start all serial ports */
40488 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
40489 if (serial_table[i] && (serial_table[i]->interface == iface)) {
40490- if (dev2ser(serial_table[i])->port.count) {
40491+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
40492 result =
40493 hso_start_serial_device(serial_table[i], GFP_NOIO);
40494 hso_kick_transmit(dev2ser(serial_table[i]));
40495diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
40496index a4fe5f1..6c9e77f 100644
40497--- a/drivers/net/vxlan.c
40498+++ b/drivers/net/vxlan.c
40499@@ -1454,7 +1454,7 @@ nla_put_failure:
40500 return -EMSGSIZE;
40501 }
40502
40503-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
40504+static struct rtnl_link_ops vxlan_link_ops = {
40505 .kind = "vxlan",
40506 .maxtype = IFLA_VXLAN_MAX,
40507 .policy = vxlan_policy,
40508diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
40509index 5ac5f7a..5f82012 100644
40510--- a/drivers/net/wireless/at76c50x-usb.c
40511+++ b/drivers/net/wireless/at76c50x-usb.c
40512@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
40513 }
40514
40515 /* Convert timeout from the DFU status to jiffies */
40516-static inline unsigned long at76_get_timeout(struct dfu_status *s)
40517+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
40518 {
40519 return msecs_to_jiffies((s->poll_timeout[2] << 16)
40520 | (s->poll_timeout[1] << 8)
40521diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40522index 8d78253..bebbb68 100644
40523--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40524+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40525@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40526 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
40527 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
40528
40529- ACCESS_ONCE(ads->ds_link) = i->link;
40530- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
40531+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
40532+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
40533
40534 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
40535 ctl6 = SM(i->keytype, AR_EncrType);
40536@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40537
40538 if ((i->is_first || i->is_last) &&
40539 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
40540- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
40541+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
40542 | set11nTries(i->rates, 1)
40543 | set11nTries(i->rates, 2)
40544 | set11nTries(i->rates, 3)
40545 | (i->dur_update ? AR_DurUpdateEna : 0)
40546 | SM(0, AR_BurstDur);
40547
40548- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
40549+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
40550 | set11nRate(i->rates, 1)
40551 | set11nRate(i->rates, 2)
40552 | set11nRate(i->rates, 3);
40553 } else {
40554- ACCESS_ONCE(ads->ds_ctl2) = 0;
40555- ACCESS_ONCE(ads->ds_ctl3) = 0;
40556+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
40557+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
40558 }
40559
40560 if (!i->is_first) {
40561- ACCESS_ONCE(ads->ds_ctl0) = 0;
40562- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40563- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40564+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
40565+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40566+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40567 return;
40568 }
40569
40570@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40571 break;
40572 }
40573
40574- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40575+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40576 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40577 | SM(i->txpower, AR_XmitPower)
40578 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40579@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40580 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
40581 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
40582
40583- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40584- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40585+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40586+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40587
40588 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
40589 return;
40590
40591- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40592+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40593 | set11nPktDurRTSCTS(i->rates, 1);
40594
40595- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40596+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40597 | set11nPktDurRTSCTS(i->rates, 3);
40598
40599- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40600+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40601 | set11nRateFlags(i->rates, 1)
40602 | set11nRateFlags(i->rates, 2)
40603 | set11nRateFlags(i->rates, 3)
40604diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40605index 301bf72..3f5654f 100644
40606--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40607+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40608@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40609 (i->qcu << AR_TxQcuNum_S) | desc_len;
40610
40611 checksum += val;
40612- ACCESS_ONCE(ads->info) = val;
40613+ ACCESS_ONCE_RW(ads->info) = val;
40614
40615 checksum += i->link;
40616- ACCESS_ONCE(ads->link) = i->link;
40617+ ACCESS_ONCE_RW(ads->link) = i->link;
40618
40619 checksum += i->buf_addr[0];
40620- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
40621+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
40622 checksum += i->buf_addr[1];
40623- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
40624+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
40625 checksum += i->buf_addr[2];
40626- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
40627+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
40628 checksum += i->buf_addr[3];
40629- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
40630+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
40631
40632 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
40633- ACCESS_ONCE(ads->ctl3) = val;
40634+ ACCESS_ONCE_RW(ads->ctl3) = val;
40635 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
40636- ACCESS_ONCE(ads->ctl5) = val;
40637+ ACCESS_ONCE_RW(ads->ctl5) = val;
40638 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
40639- ACCESS_ONCE(ads->ctl7) = val;
40640+ ACCESS_ONCE_RW(ads->ctl7) = val;
40641 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
40642- ACCESS_ONCE(ads->ctl9) = val;
40643+ ACCESS_ONCE_RW(ads->ctl9) = val;
40644
40645 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
40646- ACCESS_ONCE(ads->ctl10) = checksum;
40647+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
40648
40649 if (i->is_first || i->is_last) {
40650- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
40651+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
40652 | set11nTries(i->rates, 1)
40653 | set11nTries(i->rates, 2)
40654 | set11nTries(i->rates, 3)
40655 | (i->dur_update ? AR_DurUpdateEna : 0)
40656 | SM(0, AR_BurstDur);
40657
40658- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
40659+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
40660 | set11nRate(i->rates, 1)
40661 | set11nRate(i->rates, 2)
40662 | set11nRate(i->rates, 3);
40663 } else {
40664- ACCESS_ONCE(ads->ctl13) = 0;
40665- ACCESS_ONCE(ads->ctl14) = 0;
40666+ ACCESS_ONCE_RW(ads->ctl13) = 0;
40667+ ACCESS_ONCE_RW(ads->ctl14) = 0;
40668 }
40669
40670 ads->ctl20 = 0;
40671@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40672
40673 ctl17 = SM(i->keytype, AR_EncrType);
40674 if (!i->is_first) {
40675- ACCESS_ONCE(ads->ctl11) = 0;
40676- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40677- ACCESS_ONCE(ads->ctl15) = 0;
40678- ACCESS_ONCE(ads->ctl16) = 0;
40679- ACCESS_ONCE(ads->ctl17) = ctl17;
40680- ACCESS_ONCE(ads->ctl18) = 0;
40681- ACCESS_ONCE(ads->ctl19) = 0;
40682+ ACCESS_ONCE_RW(ads->ctl11) = 0;
40683+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40684+ ACCESS_ONCE_RW(ads->ctl15) = 0;
40685+ ACCESS_ONCE_RW(ads->ctl16) = 0;
40686+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40687+ ACCESS_ONCE_RW(ads->ctl18) = 0;
40688+ ACCESS_ONCE_RW(ads->ctl19) = 0;
40689 return;
40690 }
40691
40692- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40693+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40694 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40695 | SM(i->txpower, AR_XmitPower)
40696 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40697@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40698 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
40699 ctl12 |= SM(val, AR_PAPRDChainMask);
40700
40701- ACCESS_ONCE(ads->ctl12) = ctl12;
40702- ACCESS_ONCE(ads->ctl17) = ctl17;
40703+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
40704+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40705
40706- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40707+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40708 | set11nPktDurRTSCTS(i->rates, 1);
40709
40710- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40711+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40712 | set11nPktDurRTSCTS(i->rates, 3);
40713
40714- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
40715+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
40716 | set11nRateFlags(i->rates, 1)
40717 | set11nRateFlags(i->rates, 2)
40718 | set11nRateFlags(i->rates, 3)
40719 | SM(i->rtscts_rate, AR_RTSCTSRate);
40720
40721- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
40722+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
40723 }
40724
40725 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
40726diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
40727index 784e81c..349e01e 100644
40728--- a/drivers/net/wireless/ath/ath9k/hw.h
40729+++ b/drivers/net/wireless/ath/ath9k/hw.h
40730@@ -653,7 +653,7 @@ struct ath_hw_private_ops {
40731
40732 /* ANI */
40733 void (*ani_cache_ini_regs)(struct ath_hw *ah);
40734-};
40735+} __no_const;
40736
40737 /**
40738 * struct ath_spec_scan - parameters for Atheros spectral scan
40739@@ -722,7 +722,7 @@ struct ath_hw_ops {
40740 struct ath_spec_scan *param);
40741 void (*spectral_scan_trigger)(struct ath_hw *ah);
40742 void (*spectral_scan_wait)(struct ath_hw *ah);
40743-};
40744+} __no_const;
40745
40746 struct ath_nf_limits {
40747 s16 max;
40748diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40749index c353b5f..62aaca2 100644
40750--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40751+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40752@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40753 */
40754 if (il3945_mod_params.disable_hw_scan) {
40755 D_INFO("Disabling hw_scan\n");
40756- il3945_mac_ops.hw_scan = NULL;
40757+ pax_open_kernel();
40758+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40759+ pax_close_kernel();
40760 }
40761
40762 D_INFO("*** LOAD DRIVER ***\n");
40763diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40764index 81d4071..f2071ea 100644
40765--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40766+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40767@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40768 {
40769 struct iwl_priv *priv = file->private_data;
40770 char buf[64];
40771- int buf_size;
40772+ size_t buf_size;
40773 u32 offset, len;
40774
40775 memset(buf, 0, sizeof(buf));
40776@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40777 struct iwl_priv *priv = file->private_data;
40778
40779 char buf[8];
40780- int buf_size;
40781+ size_t buf_size;
40782 u32 reset_flag;
40783
40784 memset(buf, 0, sizeof(buf));
40785@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40786 {
40787 struct iwl_priv *priv = file->private_data;
40788 char buf[8];
40789- int buf_size;
40790+ size_t buf_size;
40791 int ht40;
40792
40793 memset(buf, 0, sizeof(buf));
40794@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40795 {
40796 struct iwl_priv *priv = file->private_data;
40797 char buf[8];
40798- int buf_size;
40799+ size_t buf_size;
40800 int value;
40801
40802 memset(buf, 0, sizeof(buf));
40803@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40804 {
40805 struct iwl_priv *priv = file->private_data;
40806 char buf[8];
40807- int buf_size;
40808+ size_t buf_size;
40809 int clear;
40810
40811 memset(buf, 0, sizeof(buf));
40812@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40813 {
40814 struct iwl_priv *priv = file->private_data;
40815 char buf[8];
40816- int buf_size;
40817+ size_t buf_size;
40818 int trace;
40819
40820 memset(buf, 0, sizeof(buf));
40821@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40822 {
40823 struct iwl_priv *priv = file->private_data;
40824 char buf[8];
40825- int buf_size;
40826+ size_t buf_size;
40827 int missed;
40828
40829 memset(buf, 0, sizeof(buf));
40830@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40831
40832 struct iwl_priv *priv = file->private_data;
40833 char buf[8];
40834- int buf_size;
40835+ size_t buf_size;
40836 int plcp;
40837
40838 memset(buf, 0, sizeof(buf));
40839@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40840
40841 struct iwl_priv *priv = file->private_data;
40842 char buf[8];
40843- int buf_size;
40844+ size_t buf_size;
40845 int flush;
40846
40847 memset(buf, 0, sizeof(buf));
40848@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40849
40850 struct iwl_priv *priv = file->private_data;
40851 char buf[8];
40852- int buf_size;
40853+ size_t buf_size;
40854 int rts;
40855
40856 if (!priv->cfg->ht_params)
40857@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40858 {
40859 struct iwl_priv *priv = file->private_data;
40860 char buf[8];
40861- int buf_size;
40862+ size_t buf_size;
40863
40864 memset(buf, 0, sizeof(buf));
40865 buf_size = min(count, sizeof(buf) - 1);
40866@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40867 struct iwl_priv *priv = file->private_data;
40868 u32 event_log_flag;
40869 char buf[8];
40870- int buf_size;
40871+ size_t buf_size;
40872
40873 /* check that the interface is up */
40874 if (!iwl_is_ready(priv))
40875@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40876 struct iwl_priv *priv = file->private_data;
40877 char buf[8];
40878 u32 calib_disabled;
40879- int buf_size;
40880+ size_t buf_size;
40881
40882 memset(buf, 0, sizeof(buf));
40883 buf_size = min(count, sizeof(buf) - 1);
40884diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40885index 12c4f31..484d948 100644
40886--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40887+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40888@@ -1328,7 +1328,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40889 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40890
40891 char buf[8];
40892- int buf_size;
40893+ size_t buf_size;
40894 u32 reset_flag;
40895
40896 memset(buf, 0, sizeof(buf));
40897@@ -1349,7 +1349,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40898 {
40899 struct iwl_trans *trans = file->private_data;
40900 char buf[8];
40901- int buf_size;
40902+ size_t buf_size;
40903 int csr;
40904
40905 memset(buf, 0, sizeof(buf));
40906diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40907index 2b49f48..14fc244 100644
40908--- a/drivers/net/wireless/mac80211_hwsim.c
40909+++ b/drivers/net/wireless/mac80211_hwsim.c
40910@@ -2143,25 +2143,19 @@ static int __init init_mac80211_hwsim(void)
40911
40912 if (channels > 1) {
40913 hwsim_if_comb.num_different_channels = channels;
40914- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40915- mac80211_hwsim_ops.cancel_hw_scan =
40916- mac80211_hwsim_cancel_hw_scan;
40917- mac80211_hwsim_ops.sw_scan_start = NULL;
40918- mac80211_hwsim_ops.sw_scan_complete = NULL;
40919- mac80211_hwsim_ops.remain_on_channel =
40920- mac80211_hwsim_roc;
40921- mac80211_hwsim_ops.cancel_remain_on_channel =
40922- mac80211_hwsim_croc;
40923- mac80211_hwsim_ops.add_chanctx =
40924- mac80211_hwsim_add_chanctx;
40925- mac80211_hwsim_ops.remove_chanctx =
40926- mac80211_hwsim_remove_chanctx;
40927- mac80211_hwsim_ops.change_chanctx =
40928- mac80211_hwsim_change_chanctx;
40929- mac80211_hwsim_ops.assign_vif_chanctx =
40930- mac80211_hwsim_assign_vif_chanctx;
40931- mac80211_hwsim_ops.unassign_vif_chanctx =
40932- mac80211_hwsim_unassign_vif_chanctx;
40933+ pax_open_kernel();
40934+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40935+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40936+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40937+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40938+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40939+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40940+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40941+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40942+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40943+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40944+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40945+ pax_close_kernel();
40946 }
40947
40948 spin_lock_init(&hwsim_radio_lock);
40949diff --git a/drivers/net/wireless/mwifiex/debugfs.c b/drivers/net/wireless/mwifiex/debugfs.c
40950index 753b568..a5f9875 100644
40951--- a/drivers/net/wireless/mwifiex/debugfs.c
40952+++ b/drivers/net/wireless/mwifiex/debugfs.c
40953@@ -26,10 +26,17 @@
40954 static struct dentry *mwifiex_dfs_dir;
40955
40956 static char *bss_modes[] = {
40957- "Unknown",
40958- "Ad-hoc",
40959- "Managed",
40960- "Auto"
40961+ "UNSPECIFIED",
40962+ "ADHOC",
40963+ "STATION",
40964+ "AP",
40965+ "AP_VLAN",
40966+ "WDS",
40967+ "MONITOR",
40968+ "MESH_POINT",
40969+ "P2P_CLIENT",
40970+ "P2P_GO",
40971+ "P2P_DEVICE",
40972 };
40973
40974 /* size/addr for mwifiex_debug_info */
40975@@ -200,7 +207,12 @@ mwifiex_info_read(struct file *file, char __user *ubuf,
40976 p += sprintf(p, "driver_version = %s", fmt);
40977 p += sprintf(p, "\nverext = %s", priv->version_str);
40978 p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name);
40979- p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
40980+
40981+ if (info.bss_mode >= ARRAY_SIZE(bss_modes))
40982+ p += sprintf(p, "bss_mode=\"%d\"\n", info.bss_mode);
40983+ else
40984+ p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
40985+
40986 p += sprintf(p, "media_state=\"%s\"\n",
40987 (!priv->media_connected ? "Disconnected" : "Connected"));
40988 p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
40989diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40990index 525fd75..6c9f791 100644
40991--- a/drivers/net/wireless/rndis_wlan.c
40992+++ b/drivers/net/wireless/rndis_wlan.c
40993@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40994
40995 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40996
40997- if (rts_threshold < 0 || rts_threshold > 2347)
40998+ if (rts_threshold > 2347)
40999 rts_threshold = 2347;
41000
41001 tmp = cpu_to_le32(rts_threshold);
41002diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
41003index 086abb4..8279c30 100644
41004--- a/drivers/net/wireless/rt2x00/rt2x00.h
41005+++ b/drivers/net/wireless/rt2x00/rt2x00.h
41006@@ -396,7 +396,7 @@ struct rt2x00_intf {
41007 * for hardware which doesn't support hardware
41008 * sequence counting.
41009 */
41010- atomic_t seqno;
41011+ atomic_unchecked_t seqno;
41012 };
41013
41014 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
41015diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
41016index 4d91795..62fccff 100644
41017--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
41018+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
41019@@ -251,9 +251,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
41020 * sequence counter given by mac80211.
41021 */
41022 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
41023- seqno = atomic_add_return(0x10, &intf->seqno);
41024+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
41025 else
41026- seqno = atomic_read(&intf->seqno);
41027+ seqno = atomic_read_unchecked(&intf->seqno);
41028
41029 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
41030 hdr->seq_ctrl |= cpu_to_le16(seqno);
41031diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
41032index e57ee48..541cf6c 100644
41033--- a/drivers/net/wireless/ti/wl1251/sdio.c
41034+++ b/drivers/net/wireless/ti/wl1251/sdio.c
41035@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
41036
41037 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
41038
41039- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41040- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41041+ pax_open_kernel();
41042+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41043+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41044+ pax_close_kernel();
41045
41046 wl1251_info("using dedicated interrupt line");
41047 } else {
41048- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41049- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41050+ pax_open_kernel();
41051+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41052+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41053+ pax_close_kernel();
41054
41055 wl1251_info("using SDIO interrupt");
41056 }
41057diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
41058index 09694e3..24ccec7 100644
41059--- a/drivers/net/wireless/ti/wl12xx/main.c
41060+++ b/drivers/net/wireless/ti/wl12xx/main.c
41061@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41062 sizeof(wl->conf.mem));
41063
41064 /* read data preparation is only needed by wl127x */
41065- wl->ops->prepare_read = wl127x_prepare_read;
41066+ pax_open_kernel();
41067+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41068+ pax_close_kernel();
41069
41070 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
41071 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
41072@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41073 sizeof(wl->conf.mem));
41074
41075 /* read data preparation is only needed by wl127x */
41076- wl->ops->prepare_read = wl127x_prepare_read;
41077+ pax_open_kernel();
41078+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41079+ pax_close_kernel();
41080
41081 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
41082 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
41083diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
41084index da3ef1b..4790b95 100644
41085--- a/drivers/net/wireless/ti/wl18xx/main.c
41086+++ b/drivers/net/wireless/ti/wl18xx/main.c
41087@@ -1664,8 +1664,10 @@ static int wl18xx_setup(struct wl1271 *wl)
41088 }
41089
41090 if (!checksum_param) {
41091- wl18xx_ops.set_rx_csum = NULL;
41092- wl18xx_ops.init_vif = NULL;
41093+ pax_open_kernel();
41094+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
41095+ *(void **)&wl18xx_ops.init_vif = NULL;
41096+ pax_close_kernel();
41097 }
41098
41099 /* Enable 11a Band only if we have 5G antennas */
41100diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
41101index 7ef0b4a..ff65c28 100644
41102--- a/drivers/net/wireless/zd1211rw/zd_usb.c
41103+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
41104@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
41105 {
41106 struct zd_usb *usb = urb->context;
41107 struct zd_usb_interrupt *intr = &usb->intr;
41108- int len;
41109+ unsigned int len;
41110 u16 int_num;
41111
41112 ZD_ASSERT(in_interrupt());
41113diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
41114index d93b2b6..ae50401 100644
41115--- a/drivers/oprofile/buffer_sync.c
41116+++ b/drivers/oprofile/buffer_sync.c
41117@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
41118 if (cookie == NO_COOKIE)
41119 offset = pc;
41120 if (cookie == INVALID_COOKIE) {
41121- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41122+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41123 offset = pc;
41124 }
41125 if (cookie != last_cookie) {
41126@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
41127 /* add userspace sample */
41128
41129 if (!mm) {
41130- atomic_inc(&oprofile_stats.sample_lost_no_mm);
41131+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
41132 return 0;
41133 }
41134
41135 cookie = lookup_dcookie(mm, s->eip, &offset);
41136
41137 if (cookie == INVALID_COOKIE) {
41138- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41139+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41140 return 0;
41141 }
41142
41143@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
41144 /* ignore backtraces if failed to add a sample */
41145 if (state == sb_bt_start) {
41146 state = sb_bt_ignore;
41147- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
41148+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
41149 }
41150 }
41151 release_mm(mm);
41152diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
41153index c0cc4e7..44d4e54 100644
41154--- a/drivers/oprofile/event_buffer.c
41155+++ b/drivers/oprofile/event_buffer.c
41156@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
41157 }
41158
41159 if (buffer_pos == buffer_size) {
41160- atomic_inc(&oprofile_stats.event_lost_overflow);
41161+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
41162 return;
41163 }
41164
41165diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
41166index ed2c3ec..deda85a 100644
41167--- a/drivers/oprofile/oprof.c
41168+++ b/drivers/oprofile/oprof.c
41169@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
41170 if (oprofile_ops.switch_events())
41171 return;
41172
41173- atomic_inc(&oprofile_stats.multiplex_counter);
41174+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
41175 start_switch_worker();
41176 }
41177
41178diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
41179index 84a208d..d61b0a1 100644
41180--- a/drivers/oprofile/oprofile_files.c
41181+++ b/drivers/oprofile/oprofile_files.c
41182@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
41183
41184 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
41185
41186-static ssize_t timeout_read(struct file *file, char __user *buf,
41187+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
41188 size_t count, loff_t *offset)
41189 {
41190 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
41191diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
41192index 917d28e..d62d981 100644
41193--- a/drivers/oprofile/oprofile_stats.c
41194+++ b/drivers/oprofile/oprofile_stats.c
41195@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
41196 cpu_buf->sample_invalid_eip = 0;
41197 }
41198
41199- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
41200- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
41201- atomic_set(&oprofile_stats.event_lost_overflow, 0);
41202- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
41203- atomic_set(&oprofile_stats.multiplex_counter, 0);
41204+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
41205+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
41206+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
41207+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
41208+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
41209 }
41210
41211
41212diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
41213index 38b6fc0..b5cbfce 100644
41214--- a/drivers/oprofile/oprofile_stats.h
41215+++ b/drivers/oprofile/oprofile_stats.h
41216@@ -13,11 +13,11 @@
41217 #include <linux/atomic.h>
41218
41219 struct oprofile_stat_struct {
41220- atomic_t sample_lost_no_mm;
41221- atomic_t sample_lost_no_mapping;
41222- atomic_t bt_lost_no_mapping;
41223- atomic_t event_lost_overflow;
41224- atomic_t multiplex_counter;
41225+ atomic_unchecked_t sample_lost_no_mm;
41226+ atomic_unchecked_t sample_lost_no_mapping;
41227+ atomic_unchecked_t bt_lost_no_mapping;
41228+ atomic_unchecked_t event_lost_overflow;
41229+ atomic_unchecked_t multiplex_counter;
41230 };
41231
41232 extern struct oprofile_stat_struct oprofile_stats;
41233diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
41234index 7c12d9c..558bf3bb 100644
41235--- a/drivers/oprofile/oprofilefs.c
41236+++ b/drivers/oprofile/oprofilefs.c
41237@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
41238
41239
41240 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
41241- char const *name, atomic_t *val)
41242+ char const *name, atomic_unchecked_t *val)
41243 {
41244 return __oprofilefs_create_file(sb, root, name,
41245 &atomic_ro_fops, 0444, val);
41246diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
41247index 93404f7..4a313d8 100644
41248--- a/drivers/oprofile/timer_int.c
41249+++ b/drivers/oprofile/timer_int.c
41250@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
41251 return NOTIFY_OK;
41252 }
41253
41254-static struct notifier_block __refdata oprofile_cpu_notifier = {
41255+static struct notifier_block oprofile_cpu_notifier = {
41256 .notifier_call = oprofile_cpu_notify,
41257 };
41258
41259diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
41260index 3f56bc0..707d642 100644
41261--- a/drivers/parport/procfs.c
41262+++ b/drivers/parport/procfs.c
41263@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
41264
41265 *ppos += len;
41266
41267- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
41268+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
41269 }
41270
41271 #ifdef CONFIG_PARPORT_1284
41272@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
41273
41274 *ppos += len;
41275
41276- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
41277+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
41278 }
41279 #endif /* IEEE1284.3 support. */
41280
41281diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
41282index c35e8ad..fc33beb 100644
41283--- a/drivers/pci/hotplug/acpiphp_ibm.c
41284+++ b/drivers/pci/hotplug/acpiphp_ibm.c
41285@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
41286 goto init_cleanup;
41287 }
41288
41289- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41290+ pax_open_kernel();
41291+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41292+ pax_close_kernel();
41293 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
41294
41295 return retval;
41296diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
41297index a6a71c4..c91097b 100644
41298--- a/drivers/pci/hotplug/cpcihp_generic.c
41299+++ b/drivers/pci/hotplug/cpcihp_generic.c
41300@@ -73,7 +73,6 @@ static u16 port;
41301 static unsigned int enum_bit;
41302 static u8 enum_mask;
41303
41304-static struct cpci_hp_controller_ops generic_hpc_ops;
41305 static struct cpci_hp_controller generic_hpc;
41306
41307 static int __init validate_parameters(void)
41308@@ -139,6 +138,10 @@ static int query_enum(void)
41309 return ((value & enum_mask) == enum_mask);
41310 }
41311
41312+static struct cpci_hp_controller_ops generic_hpc_ops = {
41313+ .query_enum = query_enum,
41314+};
41315+
41316 static int __init cpcihp_generic_init(void)
41317 {
41318 int status;
41319@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
41320 pci_dev_put(dev);
41321
41322 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
41323- generic_hpc_ops.query_enum = query_enum;
41324 generic_hpc.ops = &generic_hpc_ops;
41325
41326 status = cpci_hp_register_controller(&generic_hpc);
41327diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
41328index 449b4bb..257e2e8 100644
41329--- a/drivers/pci/hotplug/cpcihp_zt5550.c
41330+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
41331@@ -59,7 +59,6 @@
41332 /* local variables */
41333 static bool debug;
41334 static bool poll;
41335-static struct cpci_hp_controller_ops zt5550_hpc_ops;
41336 static struct cpci_hp_controller zt5550_hpc;
41337
41338 /* Primary cPCI bus bridge device */
41339@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
41340 return 0;
41341 }
41342
41343+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
41344+ .query_enum = zt5550_hc_query_enum,
41345+};
41346+
41347 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
41348 {
41349 int status;
41350@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
41351 dbg("returned from zt5550_hc_config");
41352
41353 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
41354- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
41355 zt5550_hpc.ops = &zt5550_hpc_ops;
41356 if(!poll) {
41357 zt5550_hpc.irq = hc_dev->irq;
41358 zt5550_hpc.irq_flags = IRQF_SHARED;
41359 zt5550_hpc.dev_id = hc_dev;
41360
41361- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41362- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41363- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41364+ pax_open_kernel();
41365+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41366+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41367+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41368+ pax_open_kernel();
41369 } else {
41370 info("using ENUM# polling mode");
41371 }
41372diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
41373index 76ba8a1..20ca857 100644
41374--- a/drivers/pci/hotplug/cpqphp_nvram.c
41375+++ b/drivers/pci/hotplug/cpqphp_nvram.c
41376@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
41377
41378 void compaq_nvram_init (void __iomem *rom_start)
41379 {
41380+
41381+#ifndef CONFIG_PAX_KERNEXEC
41382 if (rom_start) {
41383 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
41384 }
41385+#endif
41386+
41387 dbg("int15 entry = %p\n", compaq_int15_entry_point);
41388
41389 /* initialize our int15 lock */
41390diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
41391index 202f4a9..8ee47d0 100644
41392--- a/drivers/pci/hotplug/pci_hotplug_core.c
41393+++ b/drivers/pci/hotplug/pci_hotplug_core.c
41394@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
41395 return -EINVAL;
41396 }
41397
41398- slot->ops->owner = owner;
41399- slot->ops->mod_name = mod_name;
41400+ pax_open_kernel();
41401+ *(struct module **)&slot->ops->owner = owner;
41402+ *(const char **)&slot->ops->mod_name = mod_name;
41403+ pax_close_kernel();
41404
41405 mutex_lock(&pci_hp_mutex);
41406 /*
41407diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
41408index 7d72c5e..edce02c 100644
41409--- a/drivers/pci/hotplug/pciehp_core.c
41410+++ b/drivers/pci/hotplug/pciehp_core.c
41411@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41412 struct slot *slot = ctrl->slot;
41413 struct hotplug_slot *hotplug = NULL;
41414 struct hotplug_slot_info *info = NULL;
41415- struct hotplug_slot_ops *ops = NULL;
41416+ hotplug_slot_ops_no_const *ops = NULL;
41417 char name[SLOT_NAME_SIZE];
41418 int retval = -ENOMEM;
41419
41420diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41421index 9c6e9bb..2916736 100644
41422--- a/drivers/pci/pci-sysfs.c
41423+++ b/drivers/pci/pci-sysfs.c
41424@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41425 {
41426 /* allocate attribute structure, piggyback attribute name */
41427 int name_len = write_combine ? 13 : 10;
41428- struct bin_attribute *res_attr;
41429+ bin_attribute_no_const *res_attr;
41430 int retval;
41431
41432 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41433@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41434 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41435 {
41436 int retval;
41437- struct bin_attribute *attr;
41438+ bin_attribute_no_const *attr;
41439
41440 /* If the device has VPD, try to expose it in sysfs. */
41441 if (dev->vpd) {
41442@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41443 {
41444 int retval;
41445 int rom_size = 0;
41446- struct bin_attribute *attr;
41447+ bin_attribute_no_const *attr;
41448
41449 if (!sysfs_initialized)
41450 return -EACCES;
41451diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41452index 7346ee6..41520eb 100644
41453--- a/drivers/pci/pci.h
41454+++ b/drivers/pci/pci.h
41455@@ -93,7 +93,7 @@ struct pci_vpd_ops {
41456 struct pci_vpd {
41457 unsigned int len;
41458 const struct pci_vpd_ops *ops;
41459- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41460+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41461 };
41462
41463 extern int pci_vpd_pci22_init(struct pci_dev *dev);
41464diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41465index d320df6..ca9a8f6 100644
41466--- a/drivers/pci/pcie/aspm.c
41467+++ b/drivers/pci/pcie/aspm.c
41468@@ -27,9 +27,9 @@
41469 #define MODULE_PARAM_PREFIX "pcie_aspm."
41470
41471 /* Note: those are not register definitions */
41472-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41473-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41474-#define ASPM_STATE_L1 (4) /* L1 state */
41475+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41476+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41477+#define ASPM_STATE_L1 (4U) /* L1 state */
41478 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41479 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41480
41481diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41482index 563771f..4e3c368 100644
41483--- a/drivers/pci/probe.c
41484+++ b/drivers/pci/probe.c
41485@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41486 struct pci_bus_region region;
41487 bool bar_too_big = false, bar_disabled = false;
41488
41489- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41490+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41491
41492 /* No printks while decoding is disabled! */
41493 if (!dev->mmio_always_on) {
41494diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41495index 0b00947..64f7c0a 100644
41496--- a/drivers/pci/proc.c
41497+++ b/drivers/pci/proc.c
41498@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41499 static int __init pci_proc_init(void)
41500 {
41501 struct pci_dev *dev = NULL;
41502+
41503+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41504+#ifdef CONFIG_GRKERNSEC_PROC_USER
41505+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41506+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41507+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41508+#endif
41509+#else
41510 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41511+#endif
41512 proc_create("devices", 0, proc_bus_pci_dir,
41513 &proc_bus_pci_dev_operations);
41514 proc_initialized = 1;
41515diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
41516index 3e5b4497..dcdfb70 100644
41517--- a/drivers/platform/x86/chromeos_laptop.c
41518+++ b/drivers/platform/x86/chromeos_laptop.c
41519@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
41520 return 0;
41521 }
41522
41523-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
41524+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
41525 {
41526 .ident = "Samsung Series 5 550 - Touchpad",
41527 .matches = {
41528diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41529index 6b22938..bc9700e 100644
41530--- a/drivers/platform/x86/msi-laptop.c
41531+++ b/drivers/platform/x86/msi-laptop.c
41532@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
41533
41534 if (!quirks->ec_read_only) {
41535 /* allow userland write sysfs file */
41536- dev_attr_bluetooth.store = store_bluetooth;
41537- dev_attr_wlan.store = store_wlan;
41538- dev_attr_threeg.store = store_threeg;
41539- dev_attr_bluetooth.attr.mode |= S_IWUSR;
41540- dev_attr_wlan.attr.mode |= S_IWUSR;
41541- dev_attr_threeg.attr.mode |= S_IWUSR;
41542+ pax_open_kernel();
41543+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
41544+ *(void **)&dev_attr_wlan.store = store_wlan;
41545+ *(void **)&dev_attr_threeg.store = store_threeg;
41546+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
41547+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
41548+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
41549+ pax_close_kernel();
41550 }
41551
41552 /* disable hardware control by fn key */
41553diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
41554index 14d4dce..b129917 100644
41555--- a/drivers/platform/x86/sony-laptop.c
41556+++ b/drivers/platform/x86/sony-laptop.c
41557@@ -2465,7 +2465,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
41558 }
41559
41560 /* High speed charging function */
41561-static struct device_attribute *hsc_handle;
41562+static device_attribute_no_const *hsc_handle;
41563
41564 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
41565 struct device_attribute *attr,
41566diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
41567index edec135..59a24a3 100644
41568--- a/drivers/platform/x86/thinkpad_acpi.c
41569+++ b/drivers/platform/x86/thinkpad_acpi.c
41570@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
41571 return 0;
41572 }
41573
41574-void static hotkey_mask_warn_incomplete_mask(void)
41575+static void hotkey_mask_warn_incomplete_mask(void)
41576 {
41577 /* log only what the user can fix... */
41578 const u32 wantedmask = hotkey_driver_mask &
41579@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
41580 }
41581 }
41582
41583-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41584- struct tp_nvram_state *newn,
41585- const u32 event_mask)
41586-{
41587-
41588 #define TPACPI_COMPARE_KEY(__scancode, __member) \
41589 do { \
41590 if ((event_mask & (1 << __scancode)) && \
41591@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41592 tpacpi_hotkey_send_key(__scancode); \
41593 } while (0)
41594
41595- void issue_volchange(const unsigned int oldvol,
41596- const unsigned int newvol)
41597- {
41598- unsigned int i = oldvol;
41599+static void issue_volchange(const unsigned int oldvol,
41600+ const unsigned int newvol,
41601+ const u32 event_mask)
41602+{
41603+ unsigned int i = oldvol;
41604
41605- while (i > newvol) {
41606- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41607- i--;
41608- }
41609- while (i < newvol) {
41610- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41611- i++;
41612- }
41613+ while (i > newvol) {
41614+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41615+ i--;
41616 }
41617+ while (i < newvol) {
41618+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41619+ i++;
41620+ }
41621+}
41622
41623- void issue_brightnesschange(const unsigned int oldbrt,
41624- const unsigned int newbrt)
41625- {
41626- unsigned int i = oldbrt;
41627+static void issue_brightnesschange(const unsigned int oldbrt,
41628+ const unsigned int newbrt,
41629+ const u32 event_mask)
41630+{
41631+ unsigned int i = oldbrt;
41632
41633- while (i > newbrt) {
41634- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41635- i--;
41636- }
41637- while (i < newbrt) {
41638- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41639- i++;
41640- }
41641+ while (i > newbrt) {
41642+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41643+ i--;
41644+ }
41645+ while (i < newbrt) {
41646+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41647+ i++;
41648 }
41649+}
41650
41651+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41652+ struct tp_nvram_state *newn,
41653+ const u32 event_mask)
41654+{
41655 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
41656 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
41657 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
41658@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41659 oldn->volume_level != newn->volume_level) {
41660 /* recently muted, or repeated mute keypress, or
41661 * multiple presses ending in mute */
41662- issue_volchange(oldn->volume_level, newn->volume_level);
41663+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41664 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
41665 }
41666 } else {
41667@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41668 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41669 }
41670 if (oldn->volume_level != newn->volume_level) {
41671- issue_volchange(oldn->volume_level, newn->volume_level);
41672+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41673 } else if (oldn->volume_toggle != newn->volume_toggle) {
41674 /* repeated vol up/down keypress at end of scale ? */
41675 if (newn->volume_level == 0)
41676@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41677 /* handle brightness */
41678 if (oldn->brightness_level != newn->brightness_level) {
41679 issue_brightnesschange(oldn->brightness_level,
41680- newn->brightness_level);
41681+ newn->brightness_level,
41682+ event_mask);
41683 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
41684 /* repeated key presses that didn't change state */
41685 if (newn->brightness_level == 0)
41686@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41687 && !tp_features.bright_unkfw)
41688 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41689 }
41690+}
41691
41692 #undef TPACPI_COMPARE_KEY
41693 #undef TPACPI_MAY_SEND_KEY
41694-}
41695
41696 /*
41697 * Polling driver
41698diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
41699index 769d265..a3a05ca 100644
41700--- a/drivers/pnp/pnpbios/bioscalls.c
41701+++ b/drivers/pnp/pnpbios/bioscalls.c
41702@@ -58,7 +58,7 @@ do { \
41703 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
41704 } while(0)
41705
41706-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
41707+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
41708 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
41709
41710 /*
41711@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41712
41713 cpu = get_cpu();
41714 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
41715+
41716+ pax_open_kernel();
41717 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
41718+ pax_close_kernel();
41719
41720 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
41721 spin_lock_irqsave(&pnp_bios_lock, flags);
41722@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41723 :"memory");
41724 spin_unlock_irqrestore(&pnp_bios_lock, flags);
41725
41726+ pax_open_kernel();
41727 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
41728+ pax_close_kernel();
41729+
41730 put_cpu();
41731
41732 /* If we get here and this is set then the PnP BIOS faulted on us. */
41733@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
41734 return status;
41735 }
41736
41737-void pnpbios_calls_init(union pnp_bios_install_struct *header)
41738+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
41739 {
41740 int i;
41741
41742@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41743 pnp_bios_callpoint.offset = header->fields.pm16offset;
41744 pnp_bios_callpoint.segment = PNP_CS16;
41745
41746+ pax_open_kernel();
41747+
41748 for_each_possible_cpu(i) {
41749 struct desc_struct *gdt = get_cpu_gdt_table(i);
41750 if (!gdt)
41751@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41752 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
41753 (unsigned long)__va(header->fields.pm16dseg));
41754 }
41755+
41756+ pax_close_kernel();
41757 }
41758diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
41759index 3e6db1c..1fbbdae 100644
41760--- a/drivers/pnp/resource.c
41761+++ b/drivers/pnp/resource.c
41762@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
41763 return 1;
41764
41765 /* check if the resource is valid */
41766- if (*irq < 0 || *irq > 15)
41767+ if (*irq > 15)
41768 return 0;
41769
41770 /* check if the resource is reserved */
41771@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
41772 return 1;
41773
41774 /* check if the resource is valid */
41775- if (*dma < 0 || *dma == 4 || *dma > 7)
41776+ if (*dma == 4 || *dma > 7)
41777 return 0;
41778
41779 /* check if the resource is reserved */
41780diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
41781index 7df7c5f..bd48c47 100644
41782--- a/drivers/power/pda_power.c
41783+++ b/drivers/power/pda_power.c
41784@@ -37,7 +37,11 @@ static int polling;
41785
41786 #ifdef CONFIG_USB_OTG_UTILS
41787 static struct usb_phy *transceiver;
41788-static struct notifier_block otg_nb;
41789+static int otg_handle_notification(struct notifier_block *nb,
41790+ unsigned long event, void *unused);
41791+static struct notifier_block otg_nb = {
41792+ .notifier_call = otg_handle_notification
41793+};
41794 #endif
41795
41796 static struct regulator *ac_draw;
41797@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
41798
41799 #ifdef CONFIG_USB_OTG_UTILS
41800 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41801- otg_nb.notifier_call = otg_handle_notification;
41802 ret = usb_register_notifier(transceiver, &otg_nb);
41803 if (ret) {
41804 dev_err(dev, "failure to register otg notifier\n");
41805diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41806index cc439fd..8fa30df 100644
41807--- a/drivers/power/power_supply.h
41808+++ b/drivers/power/power_supply.h
41809@@ -16,12 +16,12 @@ struct power_supply;
41810
41811 #ifdef CONFIG_SYSFS
41812
41813-extern void power_supply_init_attrs(struct device_type *dev_type);
41814+extern void power_supply_init_attrs(void);
41815 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41816
41817 #else
41818
41819-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41820+static inline void power_supply_init_attrs(void) {}
41821 #define power_supply_uevent NULL
41822
41823 #endif /* CONFIG_SYSFS */
41824diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41825index 5deac43..608c5ff 100644
41826--- a/drivers/power/power_supply_core.c
41827+++ b/drivers/power/power_supply_core.c
41828@@ -24,7 +24,10 @@
41829 struct class *power_supply_class;
41830 EXPORT_SYMBOL_GPL(power_supply_class);
41831
41832-static struct device_type power_supply_dev_type;
41833+extern const struct attribute_group *power_supply_attr_groups[];
41834+static struct device_type power_supply_dev_type = {
41835+ .groups = power_supply_attr_groups,
41836+};
41837
41838 static int __power_supply_changed_work(struct device *dev, void *data)
41839 {
41840@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
41841 return PTR_ERR(power_supply_class);
41842
41843 power_supply_class->dev_uevent = power_supply_uevent;
41844- power_supply_init_attrs(&power_supply_dev_type);
41845+ power_supply_init_attrs();
41846
41847 return 0;
41848 }
41849diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41850index 29178f7..c65f324 100644
41851--- a/drivers/power/power_supply_sysfs.c
41852+++ b/drivers/power/power_supply_sysfs.c
41853@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
41854 .is_visible = power_supply_attr_is_visible,
41855 };
41856
41857-static const struct attribute_group *power_supply_attr_groups[] = {
41858+const struct attribute_group *power_supply_attr_groups[] = {
41859 &power_supply_attr_group,
41860 NULL,
41861 };
41862
41863-void power_supply_init_attrs(struct device_type *dev_type)
41864+void power_supply_init_attrs(void)
41865 {
41866 int i;
41867
41868- dev_type->groups = power_supply_attr_groups;
41869-
41870 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41871 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41872 }
41873diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41874index 4d7c635..9860196 100644
41875--- a/drivers/regulator/max8660.c
41876+++ b/drivers/regulator/max8660.c
41877@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41878 max8660->shadow_regs[MAX8660_OVER1] = 5;
41879 } else {
41880 /* Otherwise devices can be toggled via software */
41881- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41882- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41883+ pax_open_kernel();
41884+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41885+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41886+ pax_close_kernel();
41887 }
41888
41889 /*
41890diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41891index 9a8ea91..c483dd9 100644
41892--- a/drivers/regulator/max8973-regulator.c
41893+++ b/drivers/regulator/max8973-regulator.c
41894@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41895 if (!pdata->enable_ext_control) {
41896 max->desc.enable_reg = MAX8973_VOUT;
41897 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41898- max8973_dcdc_ops.enable = regulator_enable_regmap;
41899- max8973_dcdc_ops.disable = regulator_disable_regmap;
41900- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41901+ pax_open_kernel();
41902+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41903+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41904+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41905+ pax_close_kernel();
41906 }
41907
41908 max->enable_external_control = pdata->enable_ext_control;
41909diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41910index 9891aec..beb3083 100644
41911--- a/drivers/regulator/mc13892-regulator.c
41912+++ b/drivers/regulator/mc13892-regulator.c
41913@@ -583,10 +583,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41914 }
41915 mc13xxx_unlock(mc13892);
41916
41917- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41918+ pax_open_kernel();
41919+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41920 = mc13892_vcam_set_mode;
41921- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41922+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41923 = mc13892_vcam_get_mode;
41924+ pax_close_kernel();
41925
41926 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41927 ARRAY_SIZE(mc13892_regulators),
41928diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41929index cc5bea9..689f7d9 100644
41930--- a/drivers/rtc/rtc-cmos.c
41931+++ b/drivers/rtc/rtc-cmos.c
41932@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41933 hpet_rtc_timer_init();
41934
41935 /* export at least the first block of NVRAM */
41936- nvram.size = address_space - NVRAM_OFFSET;
41937+ pax_open_kernel();
41938+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41939+ pax_close_kernel();
41940 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41941 if (retval < 0) {
41942 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41943diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41944index d049393..bb20be0 100644
41945--- a/drivers/rtc/rtc-dev.c
41946+++ b/drivers/rtc/rtc-dev.c
41947@@ -16,6 +16,7 @@
41948 #include <linux/module.h>
41949 #include <linux/rtc.h>
41950 #include <linux/sched.h>
41951+#include <linux/grsecurity.h>
41952 #include "rtc-core.h"
41953
41954 static dev_t rtc_devt;
41955@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
41956 if (copy_from_user(&tm, uarg, sizeof(tm)))
41957 return -EFAULT;
41958
41959+ gr_log_timechange();
41960+
41961 return rtc_set_time(rtc, &tm);
41962
41963 case RTC_PIE_ON:
41964diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
41965index 970a236..3613169 100644
41966--- a/drivers/rtc/rtc-ds1307.c
41967+++ b/drivers/rtc/rtc-ds1307.c
41968@@ -106,7 +106,7 @@ struct ds1307 {
41969 u8 offset; /* register's offset */
41970 u8 regs[11];
41971 u16 nvram_offset;
41972- struct bin_attribute *nvram;
41973+ bin_attribute_no_const *nvram;
41974 enum ds_type type;
41975 unsigned long flags;
41976 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
41977diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
41978index 130f29a..6179d03 100644
41979--- a/drivers/rtc/rtc-m48t59.c
41980+++ b/drivers/rtc/rtc-m48t59.c
41981@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
41982 goto out;
41983 }
41984
41985- m48t59_nvram_attr.size = pdata->offset;
41986+ pax_open_kernel();
41987+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
41988+ pax_close_kernel();
41989
41990 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
41991 if (ret) {
41992diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41993index e693af6..2e525b6 100644
41994--- a/drivers/scsi/bfa/bfa_fcpim.h
41995+++ b/drivers/scsi/bfa/bfa_fcpim.h
41996@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41997
41998 struct bfa_itn_s {
41999 bfa_isr_func_t isr;
42000-};
42001+} __no_const;
42002
42003 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
42004 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
42005diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
42006index 23a90e7..9cf04ee 100644
42007--- a/drivers/scsi/bfa/bfa_ioc.h
42008+++ b/drivers/scsi/bfa/bfa_ioc.h
42009@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
42010 bfa_ioc_disable_cbfn_t disable_cbfn;
42011 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
42012 bfa_ioc_reset_cbfn_t reset_cbfn;
42013-};
42014+} __no_const;
42015
42016 /*
42017 * IOC event notification mechanism.
42018@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
42019 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
42020 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
42021 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
42022-};
42023+} __no_const;
42024
42025 /*
42026 * Queue element to wait for room in request queue. FIFO order is
42027diff --git a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c
42028index 439c012..b63d534 100644
42029--- a/drivers/scsi/bfa/bfad_debugfs.c
42030+++ b/drivers/scsi/bfa/bfad_debugfs.c
42031@@ -186,7 +186,7 @@ bfad_debugfs_lseek(struct file *file, loff_t offset, int orig)
42032 file->f_pos += offset;
42033 break;
42034 case 2:
42035- file->f_pos = debug->buffer_len - offset;
42036+ file->f_pos = debug->buffer_len + offset;
42037 break;
42038 default:
42039 return -EINVAL;
42040diff --git a/drivers/scsi/fnic/fnic_debugfs.c b/drivers/scsi/fnic/fnic_debugfs.c
42041index adc1f7f..85e1ffd 100644
42042--- a/drivers/scsi/fnic/fnic_debugfs.c
42043+++ b/drivers/scsi/fnic/fnic_debugfs.c
42044@@ -174,7 +174,7 @@ static loff_t fnic_trace_debugfs_lseek(struct file *file,
42045 pos = file->f_pos + offset;
42046 break;
42047 case 2:
42048- pos = fnic_dbg_prt->buffer_len - offset;
42049+ pos = fnic_dbg_prt->buffer_len + offset;
42050 }
42051 return (pos < 0 || pos > fnic_dbg_prt->buffer_len) ?
42052 -EINVAL : (file->f_pos = pos);
42053diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
42054index df0c3c7..b00e1d0 100644
42055--- a/drivers/scsi/hosts.c
42056+++ b/drivers/scsi/hosts.c
42057@@ -42,7 +42,7 @@
42058 #include "scsi_logging.h"
42059
42060
42061-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42062+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42063
42064
42065 static void scsi_host_cls_release(struct device *dev)
42066@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
42067 * subtract one because we increment first then return, but we need to
42068 * know what the next host number was before increment
42069 */
42070- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
42071+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
42072 shost->dma_channel = 0xff;
42073
42074 /* These three are default values which can be overridden */
42075diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
42076index 7f4f790..b75b92a 100644
42077--- a/drivers/scsi/hpsa.c
42078+++ b/drivers/scsi/hpsa.c
42079@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
42080 unsigned long flags;
42081
42082 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
42083- return h->access.command_completed(h, q);
42084+ return h->access->command_completed(h, q);
42085
42086 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
42087 a = rq->head[rq->current_entry];
42088@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
42089 while (!list_empty(&h->reqQ)) {
42090 c = list_entry(h->reqQ.next, struct CommandList, list);
42091 /* can't do anything if fifo is full */
42092- if ((h->access.fifo_full(h))) {
42093+ if ((h->access->fifo_full(h))) {
42094 dev_warn(&h->pdev->dev, "fifo full\n");
42095 break;
42096 }
42097@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
42098
42099 /* Tell the controller execute command */
42100 spin_unlock_irqrestore(&h->lock, flags);
42101- h->access.submit_command(h, c);
42102+ h->access->submit_command(h, c);
42103 spin_lock_irqsave(&h->lock, flags);
42104 }
42105 spin_unlock_irqrestore(&h->lock, flags);
42106@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
42107
42108 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
42109 {
42110- return h->access.command_completed(h, q);
42111+ return h->access->command_completed(h, q);
42112 }
42113
42114 static inline bool interrupt_pending(struct ctlr_info *h)
42115 {
42116- return h->access.intr_pending(h);
42117+ return h->access->intr_pending(h);
42118 }
42119
42120 static inline long interrupt_not_for_us(struct ctlr_info *h)
42121 {
42122- return (h->access.intr_pending(h) == 0) ||
42123+ return (h->access->intr_pending(h) == 0) ||
42124 (h->interrupts_enabled == 0);
42125 }
42126
42127@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
42128 if (prod_index < 0)
42129 return -ENODEV;
42130 h->product_name = products[prod_index].product_name;
42131- h->access = *(products[prod_index].access);
42132+ h->access = products[prod_index].access;
42133
42134 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
42135 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
42136@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
42137
42138 assert_spin_locked(&lockup_detector_lock);
42139 remove_ctlr_from_lockup_detector_list(h);
42140- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42141+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42142 spin_lock_irqsave(&h->lock, flags);
42143 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
42144 spin_unlock_irqrestore(&h->lock, flags);
42145@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
42146 }
42147
42148 /* make sure the board interrupts are off */
42149- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42150+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42151
42152 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
42153 goto clean2;
42154@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
42155 * fake ones to scoop up any residual completions.
42156 */
42157 spin_lock_irqsave(&h->lock, flags);
42158- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42159+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42160 spin_unlock_irqrestore(&h->lock, flags);
42161 free_irqs(h);
42162 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
42163@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
42164 dev_info(&h->pdev->dev, "Board READY.\n");
42165 dev_info(&h->pdev->dev,
42166 "Waiting for stale completions to drain.\n");
42167- h->access.set_intr_mask(h, HPSA_INTR_ON);
42168+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42169 msleep(10000);
42170- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42171+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42172
42173 rc = controller_reset_failed(h->cfgtable);
42174 if (rc)
42175@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
42176 }
42177
42178 /* Turn the interrupts on so we can service requests */
42179- h->access.set_intr_mask(h, HPSA_INTR_ON);
42180+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42181
42182 hpsa_hba_inquiry(h);
42183 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
42184@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
42185 * To write all data in the battery backed cache to disks
42186 */
42187 hpsa_flush_cache(h);
42188- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42189+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42190 hpsa_free_irqs_and_disable_msix(h);
42191 }
42192
42193@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
42194 return;
42195 }
42196 /* Change the access methods to the performant access methods */
42197- h->access = SA5_performant_access;
42198+ h->access = &SA5_performant_access;
42199 h->transMethod = CFGTBL_Trans_Performant;
42200 }
42201
42202diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
42203index 9816479..c5d4e97 100644
42204--- a/drivers/scsi/hpsa.h
42205+++ b/drivers/scsi/hpsa.h
42206@@ -79,7 +79,7 @@ struct ctlr_info {
42207 unsigned int msix_vector;
42208 unsigned int msi_vector;
42209 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
42210- struct access_method access;
42211+ struct access_method *access;
42212
42213 /* queue and queue Info */
42214 struct list_head reqQ;
42215diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
42216index c772d8d..35c362c 100644
42217--- a/drivers/scsi/libfc/fc_exch.c
42218+++ b/drivers/scsi/libfc/fc_exch.c
42219@@ -100,12 +100,12 @@ struct fc_exch_mgr {
42220 u16 pool_max_index;
42221
42222 struct {
42223- atomic_t no_free_exch;
42224- atomic_t no_free_exch_xid;
42225- atomic_t xid_not_found;
42226- atomic_t xid_busy;
42227- atomic_t seq_not_found;
42228- atomic_t non_bls_resp;
42229+ atomic_unchecked_t no_free_exch;
42230+ atomic_unchecked_t no_free_exch_xid;
42231+ atomic_unchecked_t xid_not_found;
42232+ atomic_unchecked_t xid_busy;
42233+ atomic_unchecked_t seq_not_found;
42234+ atomic_unchecked_t non_bls_resp;
42235 } stats;
42236 };
42237
42238@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
42239 /* allocate memory for exchange */
42240 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
42241 if (!ep) {
42242- atomic_inc(&mp->stats.no_free_exch);
42243+ atomic_inc_unchecked(&mp->stats.no_free_exch);
42244 goto out;
42245 }
42246 memset(ep, 0, sizeof(*ep));
42247@@ -786,7 +786,7 @@ out:
42248 return ep;
42249 err:
42250 spin_unlock_bh(&pool->lock);
42251- atomic_inc(&mp->stats.no_free_exch_xid);
42252+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
42253 mempool_free(ep, mp->ep_pool);
42254 return NULL;
42255 }
42256@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42257 xid = ntohs(fh->fh_ox_id); /* we originated exch */
42258 ep = fc_exch_find(mp, xid);
42259 if (!ep) {
42260- atomic_inc(&mp->stats.xid_not_found);
42261+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42262 reject = FC_RJT_OX_ID;
42263 goto out;
42264 }
42265@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42266 ep = fc_exch_find(mp, xid);
42267 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
42268 if (ep) {
42269- atomic_inc(&mp->stats.xid_busy);
42270+ atomic_inc_unchecked(&mp->stats.xid_busy);
42271 reject = FC_RJT_RX_ID;
42272 goto rel;
42273 }
42274@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42275 }
42276 xid = ep->xid; /* get our XID */
42277 } else if (!ep) {
42278- atomic_inc(&mp->stats.xid_not_found);
42279+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42280 reject = FC_RJT_RX_ID; /* XID not found */
42281 goto out;
42282 }
42283@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42284 } else {
42285 sp = &ep->seq;
42286 if (sp->id != fh->fh_seq_id) {
42287- atomic_inc(&mp->stats.seq_not_found);
42288+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42289 if (f_ctl & FC_FC_END_SEQ) {
42290 /*
42291 * Update sequence_id based on incoming last
42292@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42293
42294 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
42295 if (!ep) {
42296- atomic_inc(&mp->stats.xid_not_found);
42297+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42298 goto out;
42299 }
42300 if (ep->esb_stat & ESB_ST_COMPLETE) {
42301- atomic_inc(&mp->stats.xid_not_found);
42302+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42303 goto rel;
42304 }
42305 if (ep->rxid == FC_XID_UNKNOWN)
42306 ep->rxid = ntohs(fh->fh_rx_id);
42307 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
42308- atomic_inc(&mp->stats.xid_not_found);
42309+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42310 goto rel;
42311 }
42312 if (ep->did != ntoh24(fh->fh_s_id) &&
42313 ep->did != FC_FID_FLOGI) {
42314- atomic_inc(&mp->stats.xid_not_found);
42315+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42316 goto rel;
42317 }
42318 sof = fr_sof(fp);
42319@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42320 sp->ssb_stat |= SSB_ST_RESP;
42321 sp->id = fh->fh_seq_id;
42322 } else if (sp->id != fh->fh_seq_id) {
42323- atomic_inc(&mp->stats.seq_not_found);
42324+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42325 goto rel;
42326 }
42327
42328@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42329 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
42330
42331 if (!sp)
42332- atomic_inc(&mp->stats.xid_not_found);
42333+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42334 else
42335- atomic_inc(&mp->stats.non_bls_resp);
42336+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
42337
42338 fc_frame_free(fp);
42339 }
42340@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
42341
42342 list_for_each_entry(ema, &lport->ema_list, ema_list) {
42343 mp = ema->mp;
42344- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
42345+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
42346 st->fc_no_free_exch_xid +=
42347- atomic_read(&mp->stats.no_free_exch_xid);
42348- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
42349- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
42350- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
42351- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
42352+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
42353+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
42354+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
42355+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
42356+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
42357 }
42358 }
42359 EXPORT_SYMBOL(fc_exch_update_stats);
42360diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
42361index bdb81cd..d3c7c2c 100644
42362--- a/drivers/scsi/libsas/sas_ata.c
42363+++ b/drivers/scsi/libsas/sas_ata.c
42364@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
42365 .postreset = ata_std_postreset,
42366 .error_handler = ata_std_error_handler,
42367 .post_internal_cmd = sas_ata_post_internal,
42368- .qc_defer = ata_std_qc_defer,
42369+ .qc_defer = ata_std_qc_defer,
42370 .qc_prep = ata_noop_qc_prep,
42371 .qc_issue = sas_ata_qc_issue,
42372 .qc_fill_rtf = sas_ata_qc_fill_rtf,
42373diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
42374index 7706c99..3b4fc0c 100644
42375--- a/drivers/scsi/lpfc/lpfc.h
42376+++ b/drivers/scsi/lpfc/lpfc.h
42377@@ -424,7 +424,7 @@ struct lpfc_vport {
42378 struct dentry *debug_nodelist;
42379 struct dentry *vport_debugfs_root;
42380 struct lpfc_debugfs_trc *disc_trc;
42381- atomic_t disc_trc_cnt;
42382+ atomic_unchecked_t disc_trc_cnt;
42383 #endif
42384 uint8_t stat_data_enabled;
42385 uint8_t stat_data_blocked;
42386@@ -853,8 +853,8 @@ struct lpfc_hba {
42387 struct timer_list fabric_block_timer;
42388 unsigned long bit_flags;
42389 #define FABRIC_COMANDS_BLOCKED 0
42390- atomic_t num_rsrc_err;
42391- atomic_t num_cmd_success;
42392+ atomic_unchecked_t num_rsrc_err;
42393+ atomic_unchecked_t num_cmd_success;
42394 unsigned long last_rsrc_error_time;
42395 unsigned long last_ramp_down_time;
42396 unsigned long last_ramp_up_time;
42397@@ -890,7 +890,7 @@ struct lpfc_hba {
42398
42399 struct dentry *debug_slow_ring_trc;
42400 struct lpfc_debugfs_trc *slow_ring_trc;
42401- atomic_t slow_ring_trc_cnt;
42402+ atomic_unchecked_t slow_ring_trc_cnt;
42403 /* iDiag debugfs sub-directory */
42404 struct dentry *idiag_root;
42405 struct dentry *idiag_pci_cfg;
42406diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
42407index f63f5ff..32549a4 100644
42408--- a/drivers/scsi/lpfc/lpfc_debugfs.c
42409+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
42410@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
42411
42412 #include <linux/debugfs.h>
42413
42414-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42415+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42416 static unsigned long lpfc_debugfs_start_time = 0L;
42417
42418 /* iDiag */
42419@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
42420 lpfc_debugfs_enable = 0;
42421
42422 len = 0;
42423- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
42424+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
42425 (lpfc_debugfs_max_disc_trc - 1);
42426 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
42427 dtp = vport->disc_trc + i;
42428@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
42429 lpfc_debugfs_enable = 0;
42430
42431 len = 0;
42432- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
42433+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
42434 (lpfc_debugfs_max_slow_ring_trc - 1);
42435 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
42436 dtp = phba->slow_ring_trc + i;
42437@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42438 !vport || !vport->disc_trc)
42439 return;
42440
42441- index = atomic_inc_return(&vport->disc_trc_cnt) &
42442+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42443 (lpfc_debugfs_max_disc_trc - 1);
42444 dtp = vport->disc_trc + index;
42445 dtp->fmt = fmt;
42446 dtp->data1 = data1;
42447 dtp->data2 = data2;
42448 dtp->data3 = data3;
42449- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42450+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42451 dtp->jif = jiffies;
42452 #endif
42453 return;
42454@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42455 !phba || !phba->slow_ring_trc)
42456 return;
42457
42458- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42459+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42460 (lpfc_debugfs_max_slow_ring_trc - 1);
42461 dtp = phba->slow_ring_trc + index;
42462 dtp->fmt = fmt;
42463 dtp->data1 = data1;
42464 dtp->data2 = data2;
42465 dtp->data3 = data3;
42466- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42467+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42468 dtp->jif = jiffies;
42469 #endif
42470 return;
42471@@ -1178,7 +1178,7 @@ lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
42472 pos = file->f_pos + off;
42473 break;
42474 case 2:
42475- pos = debug->len - off;
42476+ pos = debug->len + off;
42477 }
42478 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
42479 }
42480@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42481 "slow_ring buffer\n");
42482 goto debug_failed;
42483 }
42484- atomic_set(&phba->slow_ring_trc_cnt, 0);
42485+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42486 memset(phba->slow_ring_trc, 0,
42487 (sizeof(struct lpfc_debugfs_trc) *
42488 lpfc_debugfs_max_slow_ring_trc));
42489@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42490 "buffer\n");
42491 goto debug_failed;
42492 }
42493- atomic_set(&vport->disc_trc_cnt, 0);
42494+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42495
42496 snprintf(name, sizeof(name), "discovery_trace");
42497 vport->debug_disc_trc =
42498diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42499index 314b4f6..7005d10 100644
42500--- a/drivers/scsi/lpfc/lpfc_init.c
42501+++ b/drivers/scsi/lpfc/lpfc_init.c
42502@@ -10551,8 +10551,10 @@ lpfc_init(void)
42503 "misc_register returned with status %d", error);
42504
42505 if (lpfc_enable_npiv) {
42506- lpfc_transport_functions.vport_create = lpfc_vport_create;
42507- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42508+ pax_open_kernel();
42509+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42510+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42511+ pax_close_kernel();
42512 }
42513 lpfc_transport_template =
42514 fc_attach_transport(&lpfc_transport_functions);
42515diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42516index 98af07c..7625fb5 100644
42517--- a/drivers/scsi/lpfc/lpfc_scsi.c
42518+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42519@@ -325,7 +325,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42520 uint32_t evt_posted;
42521
42522 spin_lock_irqsave(&phba->hbalock, flags);
42523- atomic_inc(&phba->num_rsrc_err);
42524+ atomic_inc_unchecked(&phba->num_rsrc_err);
42525 phba->last_rsrc_error_time = jiffies;
42526
42527 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42528@@ -366,7 +366,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42529 unsigned long flags;
42530 struct lpfc_hba *phba = vport->phba;
42531 uint32_t evt_posted;
42532- atomic_inc(&phba->num_cmd_success);
42533+ atomic_inc_unchecked(&phba->num_cmd_success);
42534
42535 if (vport->cfg_lun_queue_depth <= queue_depth)
42536 return;
42537@@ -410,8 +410,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42538 unsigned long num_rsrc_err, num_cmd_success;
42539 int i;
42540
42541- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42542- num_cmd_success = atomic_read(&phba->num_cmd_success);
42543+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42544+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42545
42546 /*
42547 * The error and success command counters are global per
42548@@ -439,8 +439,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42549 }
42550 }
42551 lpfc_destroy_vport_work_array(phba, vports);
42552- atomic_set(&phba->num_rsrc_err, 0);
42553- atomic_set(&phba->num_cmd_success, 0);
42554+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42555+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42556 }
42557
42558 /**
42559@@ -474,8 +474,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42560 }
42561 }
42562 lpfc_destroy_vport_work_array(phba, vports);
42563- atomic_set(&phba->num_rsrc_err, 0);
42564- atomic_set(&phba->num_cmd_success, 0);
42565+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42566+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42567 }
42568
42569 /**
42570diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
42571index b46f5e9..c4c4ccb 100644
42572--- a/drivers/scsi/pmcraid.c
42573+++ b/drivers/scsi/pmcraid.c
42574@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
42575 res->scsi_dev = scsi_dev;
42576 scsi_dev->hostdata = res;
42577 res->change_detected = 0;
42578- atomic_set(&res->read_failures, 0);
42579- atomic_set(&res->write_failures, 0);
42580+ atomic_set_unchecked(&res->read_failures, 0);
42581+ atomic_set_unchecked(&res->write_failures, 0);
42582 rc = 0;
42583 }
42584 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
42585@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
42586
42587 /* If this was a SCSI read/write command keep count of errors */
42588 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
42589- atomic_inc(&res->read_failures);
42590+ atomic_inc_unchecked(&res->read_failures);
42591 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
42592- atomic_inc(&res->write_failures);
42593+ atomic_inc_unchecked(&res->write_failures);
42594
42595 if (!RES_IS_GSCSI(res->cfg_entry) &&
42596 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
42597@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
42598 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42599 * hrrq_id assigned here in queuecommand
42600 */
42601- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42602+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42603 pinstance->num_hrrq;
42604 cmd->cmd_done = pmcraid_io_done;
42605
42606@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
42607 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42608 * hrrq_id assigned here in queuecommand
42609 */
42610- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42611+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42612 pinstance->num_hrrq;
42613
42614 if (request_size) {
42615@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
42616
42617 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
42618 /* add resources only after host is added into system */
42619- if (!atomic_read(&pinstance->expose_resources))
42620+ if (!atomic_read_unchecked(&pinstance->expose_resources))
42621 return;
42622
42623 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
42624@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
42625 init_waitqueue_head(&pinstance->reset_wait_q);
42626
42627 atomic_set(&pinstance->outstanding_cmds, 0);
42628- atomic_set(&pinstance->last_message_id, 0);
42629- atomic_set(&pinstance->expose_resources, 0);
42630+ atomic_set_unchecked(&pinstance->last_message_id, 0);
42631+ atomic_set_unchecked(&pinstance->expose_resources, 0);
42632
42633 INIT_LIST_HEAD(&pinstance->free_res_q);
42634 INIT_LIST_HEAD(&pinstance->used_res_q);
42635@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
42636 /* Schedule worker thread to handle CCN and take care of adding and
42637 * removing devices to OS
42638 */
42639- atomic_set(&pinstance->expose_resources, 1);
42640+ atomic_set_unchecked(&pinstance->expose_resources, 1);
42641 schedule_work(&pinstance->worker_q);
42642 return rc;
42643
42644diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
42645index e1d150f..6c6df44 100644
42646--- a/drivers/scsi/pmcraid.h
42647+++ b/drivers/scsi/pmcraid.h
42648@@ -748,7 +748,7 @@ struct pmcraid_instance {
42649 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
42650
42651 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
42652- atomic_t last_message_id;
42653+ atomic_unchecked_t last_message_id;
42654
42655 /* configuration table */
42656 struct pmcraid_config_table *cfg_table;
42657@@ -777,7 +777,7 @@ struct pmcraid_instance {
42658 atomic_t outstanding_cmds;
42659
42660 /* should add/delete resources to mid-layer now ?*/
42661- atomic_t expose_resources;
42662+ atomic_unchecked_t expose_resources;
42663
42664
42665
42666@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
42667 struct pmcraid_config_table_entry_ext cfg_entry_ext;
42668 };
42669 struct scsi_device *scsi_dev; /* Link scsi_device structure */
42670- atomic_t read_failures; /* count of failed READ commands */
42671- atomic_t write_failures; /* count of failed WRITE commands */
42672+ atomic_unchecked_t read_failures; /* count of failed READ commands */
42673+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
42674
42675 /* To indicate add/delete/modify during CCN */
42676 u8 change_detected;
42677diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
42678index b3db9dc..c3b1756 100644
42679--- a/drivers/scsi/qla2xxx/qla_attr.c
42680+++ b/drivers/scsi/qla2xxx/qla_attr.c
42681@@ -1971,7 +1971,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
42682 return 0;
42683 }
42684
42685-struct fc_function_template qla2xxx_transport_functions = {
42686+fc_function_template_no_const qla2xxx_transport_functions = {
42687
42688 .show_host_node_name = 1,
42689 .show_host_port_name = 1,
42690@@ -2018,7 +2018,7 @@ struct fc_function_template qla2xxx_transport_functions = {
42691 .bsg_timeout = qla24xx_bsg_timeout,
42692 };
42693
42694-struct fc_function_template qla2xxx_transport_vport_functions = {
42695+fc_function_template_no_const qla2xxx_transport_vport_functions = {
42696
42697 .show_host_node_name = 1,
42698 .show_host_port_name = 1,
42699diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
42700index b310fa9..b9b3944 100644
42701--- a/drivers/scsi/qla2xxx/qla_gbl.h
42702+++ b/drivers/scsi/qla2xxx/qla_gbl.h
42703@@ -523,8 +523,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
42704 struct device_attribute;
42705 extern struct device_attribute *qla2x00_host_attrs[];
42706 struct fc_function_template;
42707-extern struct fc_function_template qla2xxx_transport_functions;
42708-extern struct fc_function_template qla2xxx_transport_vport_functions;
42709+extern fc_function_template_no_const qla2xxx_transport_functions;
42710+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
42711 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
42712 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
42713 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
42714diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
42715index 2c6dd3d..e5ecd82 100644
42716--- a/drivers/scsi/qla2xxx/qla_os.c
42717+++ b/drivers/scsi/qla2xxx/qla_os.c
42718@@ -1554,8 +1554,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
42719 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
42720 /* Ok, a 64bit DMA mask is applicable. */
42721 ha->flags.enable_64bit_addressing = 1;
42722- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42723- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42724+ pax_open_kernel();
42725+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42726+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42727+ pax_close_kernel();
42728 return;
42729 }
42730 }
42731diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
42732index 129f5dd..ade53e8 100644
42733--- a/drivers/scsi/qla4xxx/ql4_def.h
42734+++ b/drivers/scsi/qla4xxx/ql4_def.h
42735@@ -275,7 +275,7 @@ struct ddb_entry {
42736 * (4000 only) */
42737 atomic_t relogin_timer; /* Max Time to wait for
42738 * relogin to complete */
42739- atomic_t relogin_retry_count; /* Num of times relogin has been
42740+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
42741 * retried */
42742 uint32_t default_time2wait; /* Default Min time between
42743 * relogins (+aens) */
42744diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
42745index 6142729..b6a85c9 100644
42746--- a/drivers/scsi/qla4xxx/ql4_os.c
42747+++ b/drivers/scsi/qla4xxx/ql4_os.c
42748@@ -2622,12 +2622,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
42749 */
42750 if (!iscsi_is_session_online(cls_sess)) {
42751 /* Reset retry relogin timer */
42752- atomic_inc(&ddb_entry->relogin_retry_count);
42753+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
42754 DEBUG2(ql4_printk(KERN_INFO, ha,
42755 "%s: index[%d] relogin timed out-retrying"
42756 " relogin (%d), retry (%d)\n", __func__,
42757 ddb_entry->fw_ddb_index,
42758- atomic_read(&ddb_entry->relogin_retry_count),
42759+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
42760 ddb_entry->default_time2wait + 4));
42761 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
42762 atomic_set(&ddb_entry->retry_relogin_timer,
42763@@ -4742,7 +4742,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
42764
42765 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
42766 atomic_set(&ddb_entry->relogin_timer, 0);
42767- atomic_set(&ddb_entry->relogin_retry_count, 0);
42768+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
42769 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
42770 ddb_entry->default_relogin_timeout =
42771 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
42772diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
42773index 2c0d0ec..4e8681a 100644
42774--- a/drivers/scsi/scsi.c
42775+++ b/drivers/scsi/scsi.c
42776@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
42777 unsigned long timeout;
42778 int rtn = 0;
42779
42780- atomic_inc(&cmd->device->iorequest_cnt);
42781+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42782
42783 /* check if the device is still usable */
42784 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
42785diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
42786index c31187d..0ead8c3 100644
42787--- a/drivers/scsi/scsi_lib.c
42788+++ b/drivers/scsi/scsi_lib.c
42789@@ -1459,7 +1459,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
42790 shost = sdev->host;
42791 scsi_init_cmd_errh(cmd);
42792 cmd->result = DID_NO_CONNECT << 16;
42793- atomic_inc(&cmd->device->iorequest_cnt);
42794+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42795
42796 /*
42797 * SCSI request completion path will do scsi_device_unbusy(),
42798@@ -1485,9 +1485,9 @@ static void scsi_softirq_done(struct request *rq)
42799
42800 INIT_LIST_HEAD(&cmd->eh_entry);
42801
42802- atomic_inc(&cmd->device->iodone_cnt);
42803+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
42804 if (cmd->result)
42805- atomic_inc(&cmd->device->ioerr_cnt);
42806+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
42807
42808 disposition = scsi_decide_disposition(cmd);
42809 if (disposition != SUCCESS &&
42810diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
42811index 931a7d9..0c2a754 100644
42812--- a/drivers/scsi/scsi_sysfs.c
42813+++ b/drivers/scsi/scsi_sysfs.c
42814@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
42815 char *buf) \
42816 { \
42817 struct scsi_device *sdev = to_scsi_device(dev); \
42818- unsigned long long count = atomic_read(&sdev->field); \
42819+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
42820 return snprintf(buf, 20, "0x%llx\n", count); \
42821 } \
42822 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
42823diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
42824index 84a1fdf..693b0d6 100644
42825--- a/drivers/scsi/scsi_tgt_lib.c
42826+++ b/drivers/scsi/scsi_tgt_lib.c
42827@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
42828 int err;
42829
42830 dprintk("%lx %u\n", uaddr, len);
42831- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
42832+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
42833 if (err) {
42834 /*
42835 * TODO: need to fixup sg_tablesize, max_segment_size,
42836diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42837index e894ca7..de9d7660 100644
42838--- a/drivers/scsi/scsi_transport_fc.c
42839+++ b/drivers/scsi/scsi_transport_fc.c
42840@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42841 * Netlink Infrastructure
42842 */
42843
42844-static atomic_t fc_event_seq;
42845+static atomic_unchecked_t fc_event_seq;
42846
42847 /**
42848 * fc_get_event_number - Obtain the next sequential FC event number
42849@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
42850 u32
42851 fc_get_event_number(void)
42852 {
42853- return atomic_add_return(1, &fc_event_seq);
42854+ return atomic_add_return_unchecked(1, &fc_event_seq);
42855 }
42856 EXPORT_SYMBOL(fc_get_event_number);
42857
42858@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
42859 {
42860 int error;
42861
42862- atomic_set(&fc_event_seq, 0);
42863+ atomic_set_unchecked(&fc_event_seq, 0);
42864
42865 error = transport_class_register(&fc_host_class);
42866 if (error)
42867@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42868 char *cp;
42869
42870 *val = simple_strtoul(buf, &cp, 0);
42871- if ((*cp && (*cp != '\n')) || (*val < 0))
42872+ if (*cp && (*cp != '\n'))
42873 return -EINVAL;
42874 /*
42875 * Check for overflow; dev_loss_tmo is u32
42876diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42877index 0a74b97..fa8d648 100644
42878--- a/drivers/scsi/scsi_transport_iscsi.c
42879+++ b/drivers/scsi/scsi_transport_iscsi.c
42880@@ -79,7 +79,7 @@ struct iscsi_internal {
42881 struct transport_container session_cont;
42882 };
42883
42884-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42885+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42886 static struct workqueue_struct *iscsi_eh_timer_workq;
42887
42888 static DEFINE_IDA(iscsi_sess_ida);
42889@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42890 int err;
42891
42892 ihost = shost->shost_data;
42893- session->sid = atomic_add_return(1, &iscsi_session_nr);
42894+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42895
42896 if (target_id == ISCSI_MAX_TARGET) {
42897 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42898@@ -2955,7 +2955,7 @@ static __init int iscsi_transport_init(void)
42899 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42900 ISCSI_TRANSPORT_VERSION);
42901
42902- atomic_set(&iscsi_session_nr, 0);
42903+ atomic_set_unchecked(&iscsi_session_nr, 0);
42904
42905 err = class_register(&iscsi_transport_class);
42906 if (err)
42907diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42908index f379c7f..e8fc69c 100644
42909--- a/drivers/scsi/scsi_transport_srp.c
42910+++ b/drivers/scsi/scsi_transport_srp.c
42911@@ -33,7 +33,7 @@
42912 #include "scsi_transport_srp_internal.h"
42913
42914 struct srp_host_attrs {
42915- atomic_t next_port_id;
42916+ atomic_unchecked_t next_port_id;
42917 };
42918 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42919
42920@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42921 struct Scsi_Host *shost = dev_to_shost(dev);
42922 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42923
42924- atomic_set(&srp_host->next_port_id, 0);
42925+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42926 return 0;
42927 }
42928
42929@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42930 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42931 rport->roles = ids->roles;
42932
42933- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42934+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42935 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42936
42937 transport_setup_device(&rport->dev);
42938diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42939index 82910cc..7c350ad 100644
42940--- a/drivers/scsi/sd.c
42941+++ b/drivers/scsi/sd.c
42942@@ -2929,7 +2929,7 @@ static int sd_probe(struct device *dev)
42943 sdkp->disk = gd;
42944 sdkp->index = index;
42945 atomic_set(&sdkp->openers, 0);
42946- atomic_set(&sdkp->device->ioerr_cnt, 0);
42947+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42948
42949 if (!sdp->request_queue->rq_timeout) {
42950 if (sdp->type != TYPE_MOD)
42951diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42952index 9f0c465..47194ee 100644
42953--- a/drivers/scsi/sg.c
42954+++ b/drivers/scsi/sg.c
42955@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42956 sdp->disk->disk_name,
42957 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42958 NULL,
42959- (char *)arg);
42960+ (char __user *)arg);
42961 case BLKTRACESTART:
42962 return blk_trace_startstop(sdp->device->request_queue, 1);
42963 case BLKTRACESTOP:
42964diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42965index 004b10f..7c98d51 100644
42966--- a/drivers/spi/spi.c
42967+++ b/drivers/spi/spi.c
42968@@ -1620,7 +1620,7 @@ int spi_bus_unlock(struct spi_master *master)
42969 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42970
42971 /* portable code must never pass more than 32 bytes */
42972-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42973+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42974
42975 static u8 *buf;
42976
42977diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
42978index 93af756..a4bc5bf 100644
42979--- a/drivers/staging/iio/iio_hwmon.c
42980+++ b/drivers/staging/iio/iio_hwmon.c
42981@@ -67,7 +67,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42982 {
42983 struct device *dev = &pdev->dev;
42984 struct iio_hwmon_state *st;
42985- struct sensor_device_attribute *a;
42986+ sensor_device_attribute_no_const *a;
42987 int ret, i;
42988 int in_i = 1, temp_i = 1, curr_i = 1;
42989 enum iio_chan_type type;
42990diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42991index 34afc16..ffe44dd 100644
42992--- a/drivers/staging/octeon/ethernet-rx.c
42993+++ b/drivers/staging/octeon/ethernet-rx.c
42994@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42995 /* Increment RX stats for virtual ports */
42996 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42997 #ifdef CONFIG_64BIT
42998- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42999- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
43000+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
43001+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
43002 #else
43003- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
43004- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
43005+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
43006+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
43007 #endif
43008 }
43009 netif_receive_skb(skb);
43010@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
43011 dev->name);
43012 */
43013 #ifdef CONFIG_64BIT
43014- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
43015+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
43016 #else
43017- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
43018+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
43019 #endif
43020 dev_kfree_skb_irq(skb);
43021 }
43022diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
43023index c3a90e7..023619a 100644
43024--- a/drivers/staging/octeon/ethernet.c
43025+++ b/drivers/staging/octeon/ethernet.c
43026@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
43027 * since the RX tasklet also increments it.
43028 */
43029 #ifdef CONFIG_64BIT
43030- atomic64_add(rx_status.dropped_packets,
43031- (atomic64_t *)&priv->stats.rx_dropped);
43032+ atomic64_add_unchecked(rx_status.dropped_packets,
43033+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
43034 #else
43035- atomic_add(rx_status.dropped_packets,
43036- (atomic_t *)&priv->stats.rx_dropped);
43037+ atomic_add_unchecked(rx_status.dropped_packets,
43038+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
43039 #endif
43040 }
43041
43042diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
43043index dc23395..cf7e9b1 100644
43044--- a/drivers/staging/rtl8712/rtl871x_io.h
43045+++ b/drivers/staging/rtl8712/rtl871x_io.h
43046@@ -108,7 +108,7 @@ struct _io_ops {
43047 u8 *pmem);
43048 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
43049 u8 *pmem);
43050-};
43051+} __no_const;
43052
43053 struct io_req {
43054 struct list_head list;
43055diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
43056index 1f5088b..0e59820 100644
43057--- a/drivers/staging/sbe-2t3e3/netdev.c
43058+++ b/drivers/staging/sbe-2t3e3/netdev.c
43059@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43060 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
43061
43062 if (rlen)
43063- if (copy_to_user(data, &resp, rlen))
43064+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
43065 return -EFAULT;
43066
43067 return 0;
43068diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
43069index 5dddc4d..34fcb2f 100644
43070--- a/drivers/staging/usbip/vhci.h
43071+++ b/drivers/staging/usbip/vhci.h
43072@@ -83,7 +83,7 @@ struct vhci_hcd {
43073 unsigned resuming:1;
43074 unsigned long re_timeout;
43075
43076- atomic_t seqnum;
43077+ atomic_unchecked_t seqnum;
43078
43079 /*
43080 * NOTE:
43081diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
43082index f1ca084..7b5c0c3 100644
43083--- a/drivers/staging/usbip/vhci_hcd.c
43084+++ b/drivers/staging/usbip/vhci_hcd.c
43085@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
43086
43087 spin_lock(&vdev->priv_lock);
43088
43089- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
43090+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43091 if (priv->seqnum == 0xffff)
43092 dev_info(&urb->dev->dev, "seqnum max\n");
43093
43094@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
43095 return -ENOMEM;
43096 }
43097
43098- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
43099+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43100 if (unlink->seqnum == 0xffff)
43101 pr_info("seqnum max\n");
43102
43103@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
43104 vdev->rhport = rhport;
43105 }
43106
43107- atomic_set(&vhci->seqnum, 0);
43108+ atomic_set_unchecked(&vhci->seqnum, 0);
43109 spin_lock_init(&vhci->lock);
43110
43111 hcd->power_budget = 0; /* no limit */
43112diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
43113index faf8e60..c46f8ab 100644
43114--- a/drivers/staging/usbip/vhci_rx.c
43115+++ b/drivers/staging/usbip/vhci_rx.c
43116@@ -76,7 +76,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
43117 if (!urb) {
43118 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
43119 pr_info("max seqnum %d\n",
43120- atomic_read(&the_controller->seqnum));
43121+ atomic_read_unchecked(&the_controller->seqnum));
43122 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
43123 return;
43124 }
43125diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
43126index 5f13890..36a044b 100644
43127--- a/drivers/staging/vt6655/hostap.c
43128+++ b/drivers/staging/vt6655/hostap.c
43129@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
43130 *
43131 */
43132
43133+static net_device_ops_no_const apdev_netdev_ops;
43134+
43135 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43136 {
43137 PSDevice apdev_priv;
43138 struct net_device *dev = pDevice->dev;
43139 int ret;
43140- const struct net_device_ops apdev_netdev_ops = {
43141- .ndo_start_xmit = pDevice->tx_80211,
43142- };
43143
43144 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43145
43146@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43147 *apdev_priv = *pDevice;
43148 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43149
43150+ /* only half broken now */
43151+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43152 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43153
43154 pDevice->apdev->type = ARPHRD_IEEE80211;
43155diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
43156index a94e66f..31984d0 100644
43157--- a/drivers/staging/vt6656/hostap.c
43158+++ b/drivers/staging/vt6656/hostap.c
43159@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
43160 *
43161 */
43162
43163+static net_device_ops_no_const apdev_netdev_ops;
43164+
43165 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
43166 {
43167 struct vnt_private *apdev_priv;
43168 struct net_device *dev = pDevice->dev;
43169 int ret;
43170- const struct net_device_ops apdev_netdev_ops = {
43171- .ndo_start_xmit = pDevice->tx_80211,
43172- };
43173
43174 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43175
43176@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
43177 *apdev_priv = *pDevice;
43178 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43179
43180+ /* only half broken now */
43181+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43182 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43183
43184 pDevice->apdev->type = ARPHRD_IEEE80211;
43185diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
43186index a2b7e03..9ff4bbd 100644
43187--- a/drivers/staging/zcache/tmem.c
43188+++ b/drivers/staging/zcache/tmem.c
43189@@ -50,7 +50,7 @@
43190 * A tmem host implementation must use this function to register callbacks
43191 * for memory allocation.
43192 */
43193-static struct tmem_hostops tmem_hostops;
43194+static tmem_hostops_no_const tmem_hostops;
43195
43196 static void tmem_objnode_tree_init(void);
43197
43198@@ -64,7 +64,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
43199 * A tmem host implementation must use this function to register
43200 * callbacks for a page-accessible memory (PAM) implementation.
43201 */
43202-static struct tmem_pamops tmem_pamops;
43203+static tmem_pamops_no_const tmem_pamops;
43204
43205 void tmem_register_pamops(struct tmem_pamops *m)
43206 {
43207diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
43208index adbe5a8..d387359 100644
43209--- a/drivers/staging/zcache/tmem.h
43210+++ b/drivers/staging/zcache/tmem.h
43211@@ -226,6 +226,7 @@ struct tmem_pamops {
43212 int (*replace_in_obj)(void *, struct tmem_obj *);
43213 #endif
43214 };
43215+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
43216 extern void tmem_register_pamops(struct tmem_pamops *m);
43217
43218 /* memory allocation methods provided by the host implementation */
43219@@ -235,6 +236,7 @@ struct tmem_hostops {
43220 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
43221 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
43222 };
43223+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
43224 extern void tmem_register_hostops(struct tmem_hostops *m);
43225
43226 /* core tmem accessor functions */
43227diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
43228index 2e4d655..fd72e68 100644
43229--- a/drivers/target/target_core_device.c
43230+++ b/drivers/target/target_core_device.c
43231@@ -1414,7 +1414,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
43232 spin_lock_init(&dev->se_port_lock);
43233 spin_lock_init(&dev->se_tmr_lock);
43234 spin_lock_init(&dev->qf_cmd_lock);
43235- atomic_set(&dev->dev_ordered_id, 0);
43236+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
43237 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
43238 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
43239 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
43240diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
43241index fc9a5a0..1d5975e 100644
43242--- a/drivers/target/target_core_transport.c
43243+++ b/drivers/target/target_core_transport.c
43244@@ -1081,7 +1081,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
43245 * Used to determine when ORDERED commands should go from
43246 * Dormant to Active status.
43247 */
43248- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
43249+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
43250 smp_mb__after_atomic_inc();
43251 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
43252 cmd->se_ordered_id, cmd->sam_task_attr,
43253diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
43254index 345bd0e..61d5375 100644
43255--- a/drivers/tty/cyclades.c
43256+++ b/drivers/tty/cyclades.c
43257@@ -1576,10 +1576,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
43258 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
43259 info->port.count);
43260 #endif
43261- info->port.count++;
43262+ atomic_inc(&info->port.count);
43263 #ifdef CY_DEBUG_COUNT
43264 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
43265- current->pid, info->port.count);
43266+ current->pid, atomic_read(&info->port.count));
43267 #endif
43268
43269 /*
43270@@ -3978,7 +3978,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
43271 for (j = 0; j < cy_card[i].nports; j++) {
43272 info = &cy_card[i].ports[j];
43273
43274- if (info->port.count) {
43275+ if (atomic_read(&info->port.count)) {
43276 /* XXX is the ldisc num worth this? */
43277 struct tty_struct *tty;
43278 struct tty_ldisc *ld;
43279diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
43280index eb255e8..f637a57 100644
43281--- a/drivers/tty/hvc/hvc_console.c
43282+++ b/drivers/tty/hvc/hvc_console.c
43283@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
43284
43285 spin_lock_irqsave(&hp->port.lock, flags);
43286 /* Check and then increment for fast path open. */
43287- if (hp->port.count++ > 0) {
43288+ if (atomic_inc_return(&hp->port.count) > 1) {
43289 spin_unlock_irqrestore(&hp->port.lock, flags);
43290 hvc_kick();
43291 return 0;
43292@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43293
43294 spin_lock_irqsave(&hp->port.lock, flags);
43295
43296- if (--hp->port.count == 0) {
43297+ if (atomic_dec_return(&hp->port.count) == 0) {
43298 spin_unlock_irqrestore(&hp->port.lock, flags);
43299 /* We are done with the tty pointer now. */
43300 tty_port_tty_set(&hp->port, NULL);
43301@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43302 */
43303 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
43304 } else {
43305- if (hp->port.count < 0)
43306+ if (atomic_read(&hp->port.count) < 0)
43307 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
43308- hp->vtermno, hp->port.count);
43309+ hp->vtermno, atomic_read(&hp->port.count));
43310 spin_unlock_irqrestore(&hp->port.lock, flags);
43311 }
43312 }
43313@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
43314 * open->hangup case this can be called after the final close so prevent
43315 * that from happening for now.
43316 */
43317- if (hp->port.count <= 0) {
43318+ if (atomic_read(&hp->port.count) <= 0) {
43319 spin_unlock_irqrestore(&hp->port.lock, flags);
43320 return;
43321 }
43322
43323- hp->port.count = 0;
43324+ atomic_set(&hp->port.count, 0);
43325 spin_unlock_irqrestore(&hp->port.lock, flags);
43326 tty_port_tty_set(&hp->port, NULL);
43327
43328@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
43329 return -EPIPE;
43330
43331 /* FIXME what's this (unprotected) check for? */
43332- if (hp->port.count <= 0)
43333+ if (atomic_read(&hp->port.count) <= 0)
43334 return -EIO;
43335
43336 spin_lock_irqsave(&hp->lock, flags);
43337diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
43338index 81e939e..95ead10 100644
43339--- a/drivers/tty/hvc/hvcs.c
43340+++ b/drivers/tty/hvc/hvcs.c
43341@@ -83,6 +83,7 @@
43342 #include <asm/hvcserver.h>
43343 #include <asm/uaccess.h>
43344 #include <asm/vio.h>
43345+#include <asm/local.h>
43346
43347 /*
43348 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
43349@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
43350
43351 spin_lock_irqsave(&hvcsd->lock, flags);
43352
43353- if (hvcsd->port.count > 0) {
43354+ if (atomic_read(&hvcsd->port.count) > 0) {
43355 spin_unlock_irqrestore(&hvcsd->lock, flags);
43356 printk(KERN_INFO "HVCS: vterm state unchanged. "
43357 "The hvcs device node is still in use.\n");
43358@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
43359 }
43360 }
43361
43362- hvcsd->port.count = 0;
43363+ atomic_set(&hvcsd->port.count, 0);
43364 hvcsd->port.tty = tty;
43365 tty->driver_data = hvcsd;
43366
43367@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
43368 unsigned long flags;
43369
43370 spin_lock_irqsave(&hvcsd->lock, flags);
43371- hvcsd->port.count++;
43372+ atomic_inc(&hvcsd->port.count);
43373 hvcsd->todo_mask |= HVCS_SCHED_READ;
43374 spin_unlock_irqrestore(&hvcsd->lock, flags);
43375
43376@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43377 hvcsd = tty->driver_data;
43378
43379 spin_lock_irqsave(&hvcsd->lock, flags);
43380- if (--hvcsd->port.count == 0) {
43381+ if (atomic_dec_and_test(&hvcsd->port.count)) {
43382
43383 vio_disable_interrupts(hvcsd->vdev);
43384
43385@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43386
43387 free_irq(irq, hvcsd);
43388 return;
43389- } else if (hvcsd->port.count < 0) {
43390+ } else if (atomic_read(&hvcsd->port.count) < 0) {
43391 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
43392 " is missmanaged.\n",
43393- hvcsd->vdev->unit_address, hvcsd->port.count);
43394+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
43395 }
43396
43397 spin_unlock_irqrestore(&hvcsd->lock, flags);
43398@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43399
43400 spin_lock_irqsave(&hvcsd->lock, flags);
43401 /* Preserve this so that we know how many kref refs to put */
43402- temp_open_count = hvcsd->port.count;
43403+ temp_open_count = atomic_read(&hvcsd->port.count);
43404
43405 /*
43406 * Don't kref put inside the spinlock because the destruction
43407@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43408 tty->driver_data = NULL;
43409 hvcsd->port.tty = NULL;
43410
43411- hvcsd->port.count = 0;
43412+ atomic_set(&hvcsd->port.count, 0);
43413
43414 /* This will drop any buffered data on the floor which is OK in a hangup
43415 * scenario. */
43416@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
43417 * the middle of a write operation? This is a crummy place to do this
43418 * but we want to keep it all in the spinlock.
43419 */
43420- if (hvcsd->port.count <= 0) {
43421+ if (atomic_read(&hvcsd->port.count) <= 0) {
43422 spin_unlock_irqrestore(&hvcsd->lock, flags);
43423 return -ENODEV;
43424 }
43425@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
43426 {
43427 struct hvcs_struct *hvcsd = tty->driver_data;
43428
43429- if (!hvcsd || hvcsd->port.count <= 0)
43430+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
43431 return 0;
43432
43433 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
43434diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
43435index 8fd72ff..34a0bed 100644
43436--- a/drivers/tty/ipwireless/tty.c
43437+++ b/drivers/tty/ipwireless/tty.c
43438@@ -29,6 +29,7 @@
43439 #include <linux/tty_driver.h>
43440 #include <linux/tty_flip.h>
43441 #include <linux/uaccess.h>
43442+#include <asm/local.h>
43443
43444 #include "tty.h"
43445 #include "network.h"
43446@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43447 mutex_unlock(&tty->ipw_tty_mutex);
43448 return -ENODEV;
43449 }
43450- if (tty->port.count == 0)
43451+ if (atomic_read(&tty->port.count) == 0)
43452 tty->tx_bytes_queued = 0;
43453
43454- tty->port.count++;
43455+ atomic_inc(&tty->port.count);
43456
43457 tty->port.tty = linux_tty;
43458 linux_tty->driver_data = tty;
43459@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43460
43461 static void do_ipw_close(struct ipw_tty *tty)
43462 {
43463- tty->port.count--;
43464-
43465- if (tty->port.count == 0) {
43466+ if (atomic_dec_return(&tty->port.count) == 0) {
43467 struct tty_struct *linux_tty = tty->port.tty;
43468
43469 if (linux_tty != NULL) {
43470@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
43471 return;
43472
43473 mutex_lock(&tty->ipw_tty_mutex);
43474- if (tty->port.count == 0) {
43475+ if (atomic_read(&tty->port.count) == 0) {
43476 mutex_unlock(&tty->ipw_tty_mutex);
43477 return;
43478 }
43479@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
43480
43481 mutex_lock(&tty->ipw_tty_mutex);
43482
43483- if (!tty->port.count) {
43484+ if (!atomic_read(&tty->port.count)) {
43485 mutex_unlock(&tty->ipw_tty_mutex);
43486 return;
43487 }
43488@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
43489 return -ENODEV;
43490
43491 mutex_lock(&tty->ipw_tty_mutex);
43492- if (!tty->port.count) {
43493+ if (!atomic_read(&tty->port.count)) {
43494 mutex_unlock(&tty->ipw_tty_mutex);
43495 return -EINVAL;
43496 }
43497@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
43498 if (!tty)
43499 return -ENODEV;
43500
43501- if (!tty->port.count)
43502+ if (!atomic_read(&tty->port.count))
43503 return -EINVAL;
43504
43505 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
43506@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
43507 if (!tty)
43508 return 0;
43509
43510- if (!tty->port.count)
43511+ if (!atomic_read(&tty->port.count))
43512 return 0;
43513
43514 return tty->tx_bytes_queued;
43515@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
43516 if (!tty)
43517 return -ENODEV;
43518
43519- if (!tty->port.count)
43520+ if (!atomic_read(&tty->port.count))
43521 return -EINVAL;
43522
43523 return get_control_lines(tty);
43524@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
43525 if (!tty)
43526 return -ENODEV;
43527
43528- if (!tty->port.count)
43529+ if (!atomic_read(&tty->port.count))
43530 return -EINVAL;
43531
43532 return set_control_lines(tty, set, clear);
43533@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
43534 if (!tty)
43535 return -ENODEV;
43536
43537- if (!tty->port.count)
43538+ if (!atomic_read(&tty->port.count))
43539 return -EINVAL;
43540
43541 /* FIXME: Exactly how is the tty object locked here .. */
43542@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
43543 * are gone */
43544 mutex_lock(&ttyj->ipw_tty_mutex);
43545 }
43546- while (ttyj->port.count)
43547+ while (atomic_read(&ttyj->port.count))
43548 do_ipw_close(ttyj);
43549 ipwireless_disassociate_network_ttys(network,
43550 ttyj->channel_idx);
43551diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
43552index adeac25..787a0a1 100644
43553--- a/drivers/tty/moxa.c
43554+++ b/drivers/tty/moxa.c
43555@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
43556 }
43557
43558 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
43559- ch->port.count++;
43560+ atomic_inc(&ch->port.count);
43561 tty->driver_data = ch;
43562 tty_port_tty_set(&ch->port, tty);
43563 mutex_lock(&ch->port.mutex);
43564diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
43565index 4a43ef5d7..aa71f27 100644
43566--- a/drivers/tty/n_gsm.c
43567+++ b/drivers/tty/n_gsm.c
43568@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
43569 spin_lock_init(&dlci->lock);
43570 mutex_init(&dlci->mutex);
43571 dlci->fifo = &dlci->_fifo;
43572- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
43573+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
43574 kfree(dlci);
43575 return NULL;
43576 }
43577@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
43578 struct gsm_dlci *dlci = tty->driver_data;
43579 struct tty_port *port = &dlci->port;
43580
43581- port->count++;
43582+ atomic_inc(&port->count);
43583 dlci_get(dlci);
43584 dlci_get(dlci->gsm->dlci[0]);
43585 mux_get(dlci->gsm);
43586diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
43587index 1f8cba6..47b06c2 100644
43588--- a/drivers/tty/n_tty.c
43589+++ b/drivers/tty/n_tty.c
43590@@ -2205,6 +2205,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
43591 {
43592 *ops = tty_ldisc_N_TTY;
43593 ops->owner = NULL;
43594- ops->refcount = ops->flags = 0;
43595+ atomic_set(&ops->refcount, 0);
43596+ ops->flags = 0;
43597 }
43598 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
43599diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
43600index 74a5e8b..40c36a7 100644
43601--- a/drivers/tty/pty.c
43602+++ b/drivers/tty/pty.c
43603@@ -797,8 +797,10 @@ static void __init unix98_pty_init(void)
43604 panic("Couldn't register Unix98 pts driver");
43605
43606 /* Now create the /dev/ptmx special device */
43607+ pax_open_kernel();
43608 tty_default_fops(&ptmx_fops);
43609- ptmx_fops.open = ptmx_open;
43610+ *(void **)&ptmx_fops.open = ptmx_open;
43611+ pax_close_kernel();
43612
43613 cdev_init(&ptmx_cdev, &ptmx_fops);
43614 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43615diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43616index 1d27003..959f452 100644
43617--- a/drivers/tty/rocket.c
43618+++ b/drivers/tty/rocket.c
43619@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43620 tty->driver_data = info;
43621 tty_port_tty_set(port, tty);
43622
43623- if (port->count++ == 0) {
43624+ if (atomic_inc_return(&port->count) == 1) {
43625 atomic_inc(&rp_num_ports_open);
43626
43627 #ifdef ROCKET_DEBUG_OPEN
43628@@ -932,7 +932,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43629 #endif
43630 }
43631 #ifdef ROCKET_DEBUG_OPEN
43632- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43633+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43634 #endif
43635
43636 /*
43637@@ -1527,7 +1527,7 @@ static void rp_hangup(struct tty_struct *tty)
43638 spin_unlock_irqrestore(&info->port.lock, flags);
43639 return;
43640 }
43641- if (info->port.count)
43642+ if (atomic_read(&info->port.count))
43643 atomic_dec(&rp_num_ports_open);
43644 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43645 spin_unlock_irqrestore(&info->port.lock, flags);
43646diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43647index 1002054..dd644a8 100644
43648--- a/drivers/tty/serial/kgdboc.c
43649+++ b/drivers/tty/serial/kgdboc.c
43650@@ -24,8 +24,9 @@
43651 #define MAX_CONFIG_LEN 40
43652
43653 static struct kgdb_io kgdboc_io_ops;
43654+static struct kgdb_io kgdboc_io_ops_console;
43655
43656-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43657+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43658 static int configured = -1;
43659
43660 static char config[MAX_CONFIG_LEN];
43661@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43662 kgdboc_unregister_kbd();
43663 if (configured == 1)
43664 kgdb_unregister_io_module(&kgdboc_io_ops);
43665+ else if (configured == 2)
43666+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43667 }
43668
43669 static int configure_kgdboc(void)
43670@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43671 int err;
43672 char *cptr = config;
43673 struct console *cons;
43674+ int is_console = 0;
43675
43676 err = kgdboc_option_setup(config);
43677 if (err || !strlen(config) || isspace(config[0]))
43678 goto noconfig;
43679
43680 err = -ENODEV;
43681- kgdboc_io_ops.is_console = 0;
43682 kgdb_tty_driver = NULL;
43683
43684 kgdboc_use_kms = 0;
43685@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43686 int idx;
43687 if (cons->device && cons->device(cons, &idx) == p &&
43688 idx == tty_line) {
43689- kgdboc_io_ops.is_console = 1;
43690+ is_console = 1;
43691 break;
43692 }
43693 cons = cons->next;
43694@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43695 kgdb_tty_line = tty_line;
43696
43697 do_register:
43698- err = kgdb_register_io_module(&kgdboc_io_ops);
43699+ if (is_console) {
43700+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43701+ configured = 2;
43702+ } else {
43703+ err = kgdb_register_io_module(&kgdboc_io_ops);
43704+ configured = 1;
43705+ }
43706 if (err)
43707 goto noconfig;
43708
43709@@ -205,8 +214,6 @@ do_register:
43710 if (err)
43711 goto nmi_con_failed;
43712
43713- configured = 1;
43714-
43715 return 0;
43716
43717 nmi_con_failed:
43718@@ -223,7 +230,7 @@ noconfig:
43719 static int __init init_kgdboc(void)
43720 {
43721 /* Already configured? */
43722- if (configured == 1)
43723+ if (configured >= 1)
43724 return 0;
43725
43726 return configure_kgdboc();
43727@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43728 if (config[len - 1] == '\n')
43729 config[len - 1] = '\0';
43730
43731- if (configured == 1)
43732+ if (configured >= 1)
43733 cleanup_kgdboc();
43734
43735 /* Go and configure with the new params. */
43736@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43737 .post_exception = kgdboc_post_exp_handler,
43738 };
43739
43740+static struct kgdb_io kgdboc_io_ops_console = {
43741+ .name = "kgdboc",
43742+ .read_char = kgdboc_get_char,
43743+ .write_char = kgdboc_put_char,
43744+ .pre_exception = kgdboc_pre_exp_handler,
43745+ .post_exception = kgdboc_post_exp_handler,
43746+ .is_console = 1
43747+};
43748+
43749 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43750 /* This is only available if kgdboc is a built in for early debugging */
43751 static int __init kgdboc_early_init(char *opt)
43752diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43753index 2769a38..f3dbe48 100644
43754--- a/drivers/tty/serial/samsung.c
43755+++ b/drivers/tty/serial/samsung.c
43756@@ -451,11 +451,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43757 }
43758 }
43759
43760+static int s3c64xx_serial_startup(struct uart_port *port);
43761 static int s3c24xx_serial_startup(struct uart_port *port)
43762 {
43763 struct s3c24xx_uart_port *ourport = to_ourport(port);
43764 int ret;
43765
43766+ /* Startup sequence is different for s3c64xx and higher SoC's */
43767+ if (s3c24xx_serial_has_interrupt_mask(port))
43768+ return s3c64xx_serial_startup(port);
43769+
43770 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43771 port->mapbase, port->membase);
43772
43773@@ -1120,10 +1125,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43774 /* setup info for port */
43775 port->dev = &platdev->dev;
43776
43777- /* Startup sequence is different for s3c64xx and higher SoC's */
43778- if (s3c24xx_serial_has_interrupt_mask(port))
43779- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43780-
43781 port->uartclk = 1;
43782
43783 if (cfg->uart_flags & UPF_CONS_FLOW) {
43784diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43785index 8fbb6d2..822a9e6 100644
43786--- a/drivers/tty/serial/serial_core.c
43787+++ b/drivers/tty/serial/serial_core.c
43788@@ -1454,7 +1454,7 @@ static void uart_hangup(struct tty_struct *tty)
43789 uart_flush_buffer(tty);
43790 uart_shutdown(tty, state);
43791 spin_lock_irqsave(&port->lock, flags);
43792- port->count = 0;
43793+ atomic_set(&port->count, 0);
43794 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43795 spin_unlock_irqrestore(&port->lock, flags);
43796 tty_port_tty_set(port, NULL);
43797@@ -1550,7 +1550,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43798 goto end;
43799 }
43800
43801- port->count++;
43802+ atomic_inc(&port->count);
43803 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43804 retval = -ENXIO;
43805 goto err_dec_count;
43806@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43807 /*
43808 * Make sure the device is in D0 state.
43809 */
43810- if (port->count == 1)
43811+ if (atomic_read(&port->count) == 1)
43812 uart_change_pm(state, UART_PM_STATE_ON);
43813
43814 /*
43815@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43816 end:
43817 return retval;
43818 err_dec_count:
43819- port->count--;
43820+ atomic_inc(&port->count);
43821 mutex_unlock(&port->mutex);
43822 goto end;
43823 }
43824diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43825index 8983276..72a4090 100644
43826--- a/drivers/tty/synclink.c
43827+++ b/drivers/tty/synclink.c
43828@@ -3093,7 +3093,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43829
43830 if (debug_level >= DEBUG_LEVEL_INFO)
43831 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43832- __FILE__,__LINE__, info->device_name, info->port.count);
43833+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43834
43835 if (tty_port_close_start(&info->port, tty, filp) == 0)
43836 goto cleanup;
43837@@ -3111,7 +3111,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43838 cleanup:
43839 if (debug_level >= DEBUG_LEVEL_INFO)
43840 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43841- tty->driver->name, info->port.count);
43842+ tty->driver->name, atomic_read(&info->port.count));
43843
43844 } /* end of mgsl_close() */
43845
43846@@ -3210,8 +3210,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43847
43848 mgsl_flush_buffer(tty);
43849 shutdown(info);
43850-
43851- info->port.count = 0;
43852+
43853+ atomic_set(&info->port.count, 0);
43854 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43855 info->port.tty = NULL;
43856
43857@@ -3300,12 +3300,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43858
43859 if (debug_level >= DEBUG_LEVEL_INFO)
43860 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43861- __FILE__,__LINE__, tty->driver->name, port->count );
43862+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43863
43864 spin_lock_irqsave(&info->irq_spinlock, flags);
43865 if (!tty_hung_up_p(filp)) {
43866 extra_count = true;
43867- port->count--;
43868+ atomic_dec(&port->count);
43869 }
43870 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43871 port->blocked_open++;
43872@@ -3334,7 +3334,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43873
43874 if (debug_level >= DEBUG_LEVEL_INFO)
43875 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43876- __FILE__,__LINE__, tty->driver->name, port->count );
43877+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43878
43879 tty_unlock(tty);
43880 schedule();
43881@@ -3346,12 +3346,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43882
43883 /* FIXME: Racy on hangup during close wait */
43884 if (extra_count)
43885- port->count++;
43886+ atomic_inc(&port->count);
43887 port->blocked_open--;
43888
43889 if (debug_level >= DEBUG_LEVEL_INFO)
43890 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43891- __FILE__,__LINE__, tty->driver->name, port->count );
43892+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43893
43894 if (!retval)
43895 port->flags |= ASYNC_NORMAL_ACTIVE;
43896@@ -3403,7 +3403,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43897
43898 if (debug_level >= DEBUG_LEVEL_INFO)
43899 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
43900- __FILE__,__LINE__,tty->driver->name, info->port.count);
43901+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43902
43903 /* If port is closing, signal caller to try again */
43904 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43905@@ -3422,10 +3422,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43906 spin_unlock_irqrestore(&info->netlock, flags);
43907 goto cleanup;
43908 }
43909- info->port.count++;
43910+ atomic_inc(&info->port.count);
43911 spin_unlock_irqrestore(&info->netlock, flags);
43912
43913- if (info->port.count == 1) {
43914+ if (atomic_read(&info->port.count) == 1) {
43915 /* 1st open on this device, init hardware */
43916 retval = startup(info);
43917 if (retval < 0)
43918@@ -3449,8 +3449,8 @@ cleanup:
43919 if (retval) {
43920 if (tty->count == 1)
43921 info->port.tty = NULL; /* tty layer will release tty struct */
43922- if(info->port.count)
43923- info->port.count--;
43924+ if (atomic_read(&info->port.count))
43925+ atomic_dec(&info->port.count);
43926 }
43927
43928 return retval;
43929@@ -7668,7 +7668,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43930 unsigned short new_crctype;
43931
43932 /* return error if TTY interface open */
43933- if (info->port.count)
43934+ if (atomic_read(&info->port.count))
43935 return -EBUSY;
43936
43937 switch (encoding)
43938@@ -7763,7 +7763,7 @@ static int hdlcdev_open(struct net_device *dev)
43939
43940 /* arbitrate between network and tty opens */
43941 spin_lock_irqsave(&info->netlock, flags);
43942- if (info->port.count != 0 || info->netcount != 0) {
43943+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43944 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43945 spin_unlock_irqrestore(&info->netlock, flags);
43946 return -EBUSY;
43947@@ -7849,7 +7849,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43948 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43949
43950 /* return error if TTY interface open */
43951- if (info->port.count)
43952+ if (atomic_read(&info->port.count))
43953 return -EBUSY;
43954
43955 if (cmd != SIOCWANDEV)
43956diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
43957index aa9eece..d8baaec 100644
43958--- a/drivers/tty/synclink_gt.c
43959+++ b/drivers/tty/synclink_gt.c
43960@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43961 tty->driver_data = info;
43962 info->port.tty = tty;
43963
43964- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
43965+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
43966
43967 /* If port is closing, signal caller to try again */
43968 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43969@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43970 mutex_unlock(&info->port.mutex);
43971 goto cleanup;
43972 }
43973- info->port.count++;
43974+ atomic_inc(&info->port.count);
43975 spin_unlock_irqrestore(&info->netlock, flags);
43976
43977- if (info->port.count == 1) {
43978+ if (atomic_read(&info->port.count) == 1) {
43979 /* 1st open on this device, init hardware */
43980 retval = startup(info);
43981 if (retval < 0) {
43982@@ -715,8 +715,8 @@ cleanup:
43983 if (retval) {
43984 if (tty->count == 1)
43985 info->port.tty = NULL; /* tty layer will release tty struct */
43986- if(info->port.count)
43987- info->port.count--;
43988+ if(atomic_read(&info->port.count))
43989+ atomic_dec(&info->port.count);
43990 }
43991
43992 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
43993@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43994
43995 if (sanity_check(info, tty->name, "close"))
43996 return;
43997- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
43998+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
43999
44000 if (tty_port_close_start(&info->port, tty, filp) == 0)
44001 goto cleanup;
44002@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44003 tty_port_close_end(&info->port, tty);
44004 info->port.tty = NULL;
44005 cleanup:
44006- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
44007+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
44008 }
44009
44010 static void hangup(struct tty_struct *tty)
44011@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
44012 shutdown(info);
44013
44014 spin_lock_irqsave(&info->port.lock, flags);
44015- info->port.count = 0;
44016+ atomic_set(&info->port.count, 0);
44017 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44018 info->port.tty = NULL;
44019 spin_unlock_irqrestore(&info->port.lock, flags);
44020@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44021 unsigned short new_crctype;
44022
44023 /* return error if TTY interface open */
44024- if (info->port.count)
44025+ if (atomic_read(&info->port.count))
44026 return -EBUSY;
44027
44028 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
44029@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
44030
44031 /* arbitrate between network and tty opens */
44032 spin_lock_irqsave(&info->netlock, flags);
44033- if (info->port.count != 0 || info->netcount != 0) {
44034+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44035 DBGINFO(("%s hdlc_open busy\n", dev->name));
44036 spin_unlock_irqrestore(&info->netlock, flags);
44037 return -EBUSY;
44038@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44039 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
44040
44041 /* return error if TTY interface open */
44042- if (info->port.count)
44043+ if (atomic_read(&info->port.count))
44044 return -EBUSY;
44045
44046 if (cmd != SIOCWANDEV)
44047@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
44048 if (port == NULL)
44049 continue;
44050 spin_lock(&port->lock);
44051- if ((port->port.count || port->netcount) &&
44052+ if ((atomic_read(&port->port.count) || port->netcount) &&
44053 port->pending_bh && !port->bh_running &&
44054 !port->bh_requested) {
44055 DBGISR(("%s bh queued\n", port->device_name));
44056@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44057 spin_lock_irqsave(&info->lock, flags);
44058 if (!tty_hung_up_p(filp)) {
44059 extra_count = true;
44060- port->count--;
44061+ atomic_dec(&port->count);
44062 }
44063 spin_unlock_irqrestore(&info->lock, flags);
44064 port->blocked_open++;
44065@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44066 remove_wait_queue(&port->open_wait, &wait);
44067
44068 if (extra_count)
44069- port->count++;
44070+ atomic_inc(&port->count);
44071 port->blocked_open--;
44072
44073 if (!retval)
44074diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
44075index 6d5780c..aa4d8cd 100644
44076--- a/drivers/tty/synclinkmp.c
44077+++ b/drivers/tty/synclinkmp.c
44078@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44079
44080 if (debug_level >= DEBUG_LEVEL_INFO)
44081 printk("%s(%d):%s open(), old ref count = %d\n",
44082- __FILE__,__LINE__,tty->driver->name, info->port.count);
44083+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44084
44085 /* If port is closing, signal caller to try again */
44086 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44087@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44088 spin_unlock_irqrestore(&info->netlock, flags);
44089 goto cleanup;
44090 }
44091- info->port.count++;
44092+ atomic_inc(&info->port.count);
44093 spin_unlock_irqrestore(&info->netlock, flags);
44094
44095- if (info->port.count == 1) {
44096+ if (atomic_read(&info->port.count) == 1) {
44097 /* 1st open on this device, init hardware */
44098 retval = startup(info);
44099 if (retval < 0)
44100@@ -796,8 +796,8 @@ cleanup:
44101 if (retval) {
44102 if (tty->count == 1)
44103 info->port.tty = NULL; /* tty layer will release tty struct */
44104- if(info->port.count)
44105- info->port.count--;
44106+ if(atomic_read(&info->port.count))
44107+ atomic_dec(&info->port.count);
44108 }
44109
44110 return retval;
44111@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44112
44113 if (debug_level >= DEBUG_LEVEL_INFO)
44114 printk("%s(%d):%s close() entry, count=%d\n",
44115- __FILE__,__LINE__, info->device_name, info->port.count);
44116+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
44117
44118 if (tty_port_close_start(&info->port, tty, filp) == 0)
44119 goto cleanup;
44120@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44121 cleanup:
44122 if (debug_level >= DEBUG_LEVEL_INFO)
44123 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
44124- tty->driver->name, info->port.count);
44125+ tty->driver->name, atomic_read(&info->port.count));
44126 }
44127
44128 /* Called by tty_hangup() when a hangup is signaled.
44129@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
44130 shutdown(info);
44131
44132 spin_lock_irqsave(&info->port.lock, flags);
44133- info->port.count = 0;
44134+ atomic_set(&info->port.count, 0);
44135 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44136 info->port.tty = NULL;
44137 spin_unlock_irqrestore(&info->port.lock, flags);
44138@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44139 unsigned short new_crctype;
44140
44141 /* return error if TTY interface open */
44142- if (info->port.count)
44143+ if (atomic_read(&info->port.count))
44144 return -EBUSY;
44145
44146 switch (encoding)
44147@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
44148
44149 /* arbitrate between network and tty opens */
44150 spin_lock_irqsave(&info->netlock, flags);
44151- if (info->port.count != 0 || info->netcount != 0) {
44152+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44153 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44154 spin_unlock_irqrestore(&info->netlock, flags);
44155 return -EBUSY;
44156@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44157 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44158
44159 /* return error if TTY interface open */
44160- if (info->port.count)
44161+ if (atomic_read(&info->port.count))
44162 return -EBUSY;
44163
44164 if (cmd != SIOCWANDEV)
44165@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
44166 * do not request bottom half processing if the
44167 * device is not open in a normal mode.
44168 */
44169- if ( port && (port->port.count || port->netcount) &&
44170+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
44171 port->pending_bh && !port->bh_running &&
44172 !port->bh_requested ) {
44173 if ( debug_level >= DEBUG_LEVEL_ISR )
44174@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44175
44176 if (debug_level >= DEBUG_LEVEL_INFO)
44177 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
44178- __FILE__,__LINE__, tty->driver->name, port->count );
44179+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44180
44181 spin_lock_irqsave(&info->lock, flags);
44182 if (!tty_hung_up_p(filp)) {
44183 extra_count = true;
44184- port->count--;
44185+ atomic_dec(&port->count);
44186 }
44187 spin_unlock_irqrestore(&info->lock, flags);
44188 port->blocked_open++;
44189@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44190
44191 if (debug_level >= DEBUG_LEVEL_INFO)
44192 printk("%s(%d):%s block_til_ready() count=%d\n",
44193- __FILE__,__LINE__, tty->driver->name, port->count );
44194+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44195
44196 tty_unlock(tty);
44197 schedule();
44198@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44199 remove_wait_queue(&port->open_wait, &wait);
44200
44201 if (extra_count)
44202- port->count++;
44203+ atomic_inc(&port->count);
44204 port->blocked_open--;
44205
44206 if (debug_level >= DEBUG_LEVEL_INFO)
44207 printk("%s(%d):%s block_til_ready() after, count=%d\n",
44208- __FILE__,__LINE__, tty->driver->name, port->count );
44209+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44210
44211 if (!retval)
44212 port->flags |= ASYNC_NORMAL_ACTIVE;
44213diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
44214index 3687f0c..6b9b808 100644
44215--- a/drivers/tty/sysrq.c
44216+++ b/drivers/tty/sysrq.c
44217@@ -995,7 +995,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
44218 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
44219 size_t count, loff_t *ppos)
44220 {
44221- if (count) {
44222+ if (count && capable(CAP_SYS_ADMIN)) {
44223 char c;
44224
44225 if (get_user(c, buf))
44226diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
44227index a9cd0b9..47b9336 100644
44228--- a/drivers/tty/tty_io.c
44229+++ b/drivers/tty/tty_io.c
44230@@ -3398,7 +3398,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
44231
44232 void tty_default_fops(struct file_operations *fops)
44233 {
44234- *fops = tty_fops;
44235+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
44236 }
44237
44238 /*
44239diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
44240index d794087..e4f49e5 100644
44241--- a/drivers/tty/tty_ldisc.c
44242+++ b/drivers/tty/tty_ldisc.c
44243@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
44244 if (atomic_dec_and_test(&ld->users)) {
44245 struct tty_ldisc_ops *ldo = ld->ops;
44246
44247- ldo->refcount--;
44248+ atomic_dec(&ldo->refcount);
44249 module_put(ldo->owner);
44250 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44251
44252@@ -93,7 +93,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
44253 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44254 tty_ldiscs[disc] = new_ldisc;
44255 new_ldisc->num = disc;
44256- new_ldisc->refcount = 0;
44257+ atomic_set(&new_ldisc->refcount, 0);
44258 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44259
44260 return ret;
44261@@ -121,7 +121,7 @@ int tty_unregister_ldisc(int disc)
44262 return -EINVAL;
44263
44264 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44265- if (tty_ldiscs[disc]->refcount)
44266+ if (atomic_read(&tty_ldiscs[disc]->refcount))
44267 ret = -EBUSY;
44268 else
44269 tty_ldiscs[disc] = NULL;
44270@@ -142,7 +142,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
44271 if (ldops) {
44272 ret = ERR_PTR(-EAGAIN);
44273 if (try_module_get(ldops->owner)) {
44274- ldops->refcount++;
44275+ atomic_inc(&ldops->refcount);
44276 ret = ldops;
44277 }
44278 }
44279@@ -155,7 +155,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
44280 unsigned long flags;
44281
44282 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44283- ldops->refcount--;
44284+ atomic_dec(&ldops->refcount);
44285 module_put(ldops->owner);
44286 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44287 }
44288diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
44289index b7ff59d..7c6105e 100644
44290--- a/drivers/tty/tty_port.c
44291+++ b/drivers/tty/tty_port.c
44292@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
44293 unsigned long flags;
44294
44295 spin_lock_irqsave(&port->lock, flags);
44296- port->count = 0;
44297+ atomic_set(&port->count, 0);
44298 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44299 if (port->tty) {
44300 set_bit(TTY_IO_ERROR, &port->tty->flags);
44301@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44302 /* The port lock protects the port counts */
44303 spin_lock_irqsave(&port->lock, flags);
44304 if (!tty_hung_up_p(filp))
44305- port->count--;
44306+ atomic_dec(&port->count);
44307 port->blocked_open++;
44308 spin_unlock_irqrestore(&port->lock, flags);
44309
44310@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44311 we must not mess that up further */
44312 spin_lock_irqsave(&port->lock, flags);
44313 if (!tty_hung_up_p(filp))
44314- port->count++;
44315+ atomic_inc(&port->count);
44316 port->blocked_open--;
44317 if (retval == 0)
44318 port->flags |= ASYNC_NORMAL_ACTIVE;
44319@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
44320 return 0;
44321 }
44322
44323- if (tty->count == 1 && port->count != 1) {
44324+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
44325 printk(KERN_WARNING
44326 "tty_port_close_start: tty->count = 1 port count = %d.\n",
44327- port->count);
44328- port->count = 1;
44329+ atomic_read(&port->count));
44330+ atomic_set(&port->count, 1);
44331 }
44332- if (--port->count < 0) {
44333+ if (atomic_dec_return(&port->count) < 0) {
44334 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
44335- port->count);
44336- port->count = 0;
44337+ atomic_read(&port->count));
44338+ atomic_set(&port->count, 0);
44339 }
44340
44341- if (port->count) {
44342+ if (atomic_read(&port->count)) {
44343 spin_unlock_irqrestore(&port->lock, flags);
44344 if (port->ops->drop)
44345 port->ops->drop(port);
44346@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
44347 {
44348 spin_lock_irq(&port->lock);
44349 if (!tty_hung_up_p(filp))
44350- ++port->count;
44351+ atomic_inc(&port->count);
44352 spin_unlock_irq(&port->lock);
44353 tty_port_tty_set(port, tty);
44354
44355diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
44356index a9af1b9a..1e08e7f 100644
44357--- a/drivers/tty/vt/keyboard.c
44358+++ b/drivers/tty/vt/keyboard.c
44359@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
44360 kbd->kbdmode == VC_OFF) &&
44361 value != KVAL(K_SAK))
44362 return; /* SAK is allowed even in raw mode */
44363+
44364+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
44365+ {
44366+ void *func = fn_handler[value];
44367+ if (func == fn_show_state || func == fn_show_ptregs ||
44368+ func == fn_show_mem)
44369+ return;
44370+ }
44371+#endif
44372+
44373 fn_handler[value](vc);
44374 }
44375
44376@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44377 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
44378 return -EFAULT;
44379
44380- if (!capable(CAP_SYS_TTY_CONFIG))
44381- perm = 0;
44382-
44383 switch (cmd) {
44384 case KDGKBENT:
44385 /* Ensure another thread doesn't free it under us */
44386@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44387 spin_unlock_irqrestore(&kbd_event_lock, flags);
44388 return put_user(val, &user_kbe->kb_value);
44389 case KDSKBENT:
44390+ if (!capable(CAP_SYS_TTY_CONFIG))
44391+ perm = 0;
44392+
44393 if (!perm)
44394 return -EPERM;
44395 if (!i && v == K_NOSUCHMAP) {
44396@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44397 int i, j, k;
44398 int ret;
44399
44400- if (!capable(CAP_SYS_TTY_CONFIG))
44401- perm = 0;
44402-
44403 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
44404 if (!kbs) {
44405 ret = -ENOMEM;
44406@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44407 kfree(kbs);
44408 return ((p && *p) ? -EOVERFLOW : 0);
44409 case KDSKBSENT:
44410+ if (!capable(CAP_SYS_TTY_CONFIG))
44411+ perm = 0;
44412+
44413 if (!perm) {
44414 ret = -EPERM;
44415 goto reterr;
44416diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
44417index b645c47..a55c182 100644
44418--- a/drivers/uio/uio.c
44419+++ b/drivers/uio/uio.c
44420@@ -25,6 +25,7 @@
44421 #include <linux/kobject.h>
44422 #include <linux/cdev.h>
44423 #include <linux/uio_driver.h>
44424+#include <asm/local.h>
44425
44426 #define UIO_MAX_DEVICES (1U << MINORBITS)
44427
44428@@ -32,10 +33,10 @@ struct uio_device {
44429 struct module *owner;
44430 struct device *dev;
44431 int minor;
44432- atomic_t event;
44433+ atomic_unchecked_t event;
44434 struct fasync_struct *async_queue;
44435 wait_queue_head_t wait;
44436- int vma_count;
44437+ local_t vma_count;
44438 struct uio_info *info;
44439 struct kobject *map_dir;
44440 struct kobject *portio_dir;
44441@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
44442 struct device_attribute *attr, char *buf)
44443 {
44444 struct uio_device *idev = dev_get_drvdata(dev);
44445- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
44446+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
44447 }
44448
44449 static struct device_attribute uio_class_attributes[] = {
44450@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
44451 {
44452 struct uio_device *idev = info->uio_dev;
44453
44454- atomic_inc(&idev->event);
44455+ atomic_inc_unchecked(&idev->event);
44456 wake_up_interruptible(&idev->wait);
44457 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
44458 }
44459@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
44460 }
44461
44462 listener->dev = idev;
44463- listener->event_count = atomic_read(&idev->event);
44464+ listener->event_count = atomic_read_unchecked(&idev->event);
44465 filep->private_data = listener;
44466
44467 if (idev->info->open) {
44468@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
44469 return -EIO;
44470
44471 poll_wait(filep, &idev->wait, wait);
44472- if (listener->event_count != atomic_read(&idev->event))
44473+ if (listener->event_count != atomic_read_unchecked(&idev->event))
44474 return POLLIN | POLLRDNORM;
44475 return 0;
44476 }
44477@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
44478 do {
44479 set_current_state(TASK_INTERRUPTIBLE);
44480
44481- event_count = atomic_read(&idev->event);
44482+ event_count = atomic_read_unchecked(&idev->event);
44483 if (event_count != listener->event_count) {
44484 if (copy_to_user(buf, &event_count, count))
44485 retval = -EFAULT;
44486@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
44487 static void uio_vma_open(struct vm_area_struct *vma)
44488 {
44489 struct uio_device *idev = vma->vm_private_data;
44490- idev->vma_count++;
44491+ local_inc(&idev->vma_count);
44492 }
44493
44494 static void uio_vma_close(struct vm_area_struct *vma)
44495 {
44496 struct uio_device *idev = vma->vm_private_data;
44497- idev->vma_count--;
44498+ local_dec(&idev->vma_count);
44499 }
44500
44501 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
44502@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
44503 idev->owner = owner;
44504 idev->info = info;
44505 init_waitqueue_head(&idev->wait);
44506- atomic_set(&idev->event, 0);
44507+ atomic_set_unchecked(&idev->event, 0);
44508
44509 ret = uio_get_minor(idev);
44510 if (ret)
44511diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
44512index 8a7eb77..c00402f 100644
44513--- a/drivers/usb/atm/cxacru.c
44514+++ b/drivers/usb/atm/cxacru.c
44515@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
44516 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
44517 if (ret < 2)
44518 return -EINVAL;
44519- if (index < 0 || index > 0x7f)
44520+ if (index > 0x7f)
44521 return -EINVAL;
44522 pos += tmp;
44523
44524diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
44525index 35f10bf..6a38a0b 100644
44526--- a/drivers/usb/atm/usbatm.c
44527+++ b/drivers/usb/atm/usbatm.c
44528@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44529 if (printk_ratelimit())
44530 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
44531 __func__, vpi, vci);
44532- atomic_inc(&vcc->stats->rx_err);
44533+ atomic_inc_unchecked(&vcc->stats->rx_err);
44534 return;
44535 }
44536
44537@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44538 if (length > ATM_MAX_AAL5_PDU) {
44539 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
44540 __func__, length, vcc);
44541- atomic_inc(&vcc->stats->rx_err);
44542+ atomic_inc_unchecked(&vcc->stats->rx_err);
44543 goto out;
44544 }
44545
44546@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44547 if (sarb->len < pdu_length) {
44548 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
44549 __func__, pdu_length, sarb->len, vcc);
44550- atomic_inc(&vcc->stats->rx_err);
44551+ atomic_inc_unchecked(&vcc->stats->rx_err);
44552 goto out;
44553 }
44554
44555 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
44556 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
44557 __func__, vcc);
44558- atomic_inc(&vcc->stats->rx_err);
44559+ atomic_inc_unchecked(&vcc->stats->rx_err);
44560 goto out;
44561 }
44562
44563@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44564 if (printk_ratelimit())
44565 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
44566 __func__, length);
44567- atomic_inc(&vcc->stats->rx_drop);
44568+ atomic_inc_unchecked(&vcc->stats->rx_drop);
44569 goto out;
44570 }
44571
44572@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44573
44574 vcc->push(vcc, skb);
44575
44576- atomic_inc(&vcc->stats->rx);
44577+ atomic_inc_unchecked(&vcc->stats->rx);
44578 out:
44579 skb_trim(sarb, 0);
44580 }
44581@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
44582 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
44583
44584 usbatm_pop(vcc, skb);
44585- atomic_inc(&vcc->stats->tx);
44586+ atomic_inc_unchecked(&vcc->stats->tx);
44587
44588 skb = skb_dequeue(&instance->sndqueue);
44589 }
44590@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
44591 if (!left--)
44592 return sprintf(page,
44593 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
44594- atomic_read(&atm_dev->stats.aal5.tx),
44595- atomic_read(&atm_dev->stats.aal5.tx_err),
44596- atomic_read(&atm_dev->stats.aal5.rx),
44597- atomic_read(&atm_dev->stats.aal5.rx_err),
44598- atomic_read(&atm_dev->stats.aal5.rx_drop));
44599+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
44600+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
44601+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
44602+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
44603+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
44604
44605 if (!left--) {
44606 if (instance->disconnected)
44607diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
44608index 2a3bbdf..91d72cf 100644
44609--- a/drivers/usb/core/devices.c
44610+++ b/drivers/usb/core/devices.c
44611@@ -126,7 +126,7 @@ static const char format_endpt[] =
44612 * time it gets called.
44613 */
44614 static struct device_connect_event {
44615- atomic_t count;
44616+ atomic_unchecked_t count;
44617 wait_queue_head_t wait;
44618 } device_event = {
44619 .count = ATOMIC_INIT(1),
44620@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44621
44622 void usbfs_conn_disc_event(void)
44623 {
44624- atomic_add(2, &device_event.count);
44625+ atomic_add_unchecked(2, &device_event.count);
44626 wake_up(&device_event.wait);
44627 }
44628
44629@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
44630
44631 poll_wait(file, &device_event.wait, wait);
44632
44633- event_count = atomic_read(&device_event.count);
44634+ event_count = atomic_read_unchecked(&device_event.count);
44635 if (file->f_version != event_count) {
44636 file->f_version = event_count;
44637 return POLLIN | POLLRDNORM;
44638diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44639index f9ec44c..eb5779f 100644
44640--- a/drivers/usb/core/hcd.c
44641+++ b/drivers/usb/core/hcd.c
44642@@ -1526,7 +1526,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44643 */
44644 usb_get_urb(urb);
44645 atomic_inc(&urb->use_count);
44646- atomic_inc(&urb->dev->urbnum);
44647+ atomic_inc_unchecked(&urb->dev->urbnum);
44648 usbmon_urb_submit(&hcd->self, urb);
44649
44650 /* NOTE requirements on root-hub callers (usbfs and the hub
44651@@ -1553,7 +1553,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44652 urb->hcpriv = NULL;
44653 INIT_LIST_HEAD(&urb->urb_list);
44654 atomic_dec(&urb->use_count);
44655- atomic_dec(&urb->dev->urbnum);
44656+ atomic_dec_unchecked(&urb->dev->urbnum);
44657 if (atomic_read(&urb->reject))
44658 wake_up(&usb_kill_urb_queue);
44659 usb_put_urb(urb);
44660diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44661index 444d30e..f15c850 100644
44662--- a/drivers/usb/core/message.c
44663+++ b/drivers/usb/core/message.c
44664@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44665 * method can wait for it to complete. Since you don't have a handle on the
44666 * URB used, you can't cancel the request.
44667 */
44668-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44669+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44670 __u8 requesttype, __u16 value, __u16 index, void *data,
44671 __u16 size, int timeout)
44672 {
44673diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44674index 3f81a3d..a3aa993 100644
44675--- a/drivers/usb/core/sysfs.c
44676+++ b/drivers/usb/core/sysfs.c
44677@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44678 struct usb_device *udev;
44679
44680 udev = to_usb_device(dev);
44681- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44682+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44683 }
44684 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44685
44686diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44687index f81b925..78d22ec 100644
44688--- a/drivers/usb/core/usb.c
44689+++ b/drivers/usb/core/usb.c
44690@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44691 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44692 dev->state = USB_STATE_ATTACHED;
44693 dev->lpm_disable_count = 1;
44694- atomic_set(&dev->urbnum, 0);
44695+ atomic_set_unchecked(&dev->urbnum, 0);
44696
44697 INIT_LIST_HEAD(&dev->ep0.urb_list);
44698 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44699diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44700index 5e29dde..eca992f 100644
44701--- a/drivers/usb/early/ehci-dbgp.c
44702+++ b/drivers/usb/early/ehci-dbgp.c
44703@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44704
44705 #ifdef CONFIG_KGDB
44706 static struct kgdb_io kgdbdbgp_io_ops;
44707-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44708+static struct kgdb_io kgdbdbgp_io_ops_console;
44709+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44710 #else
44711 #define dbgp_kgdb_mode (0)
44712 #endif
44713@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44714 .write_char = kgdbdbgp_write_char,
44715 };
44716
44717+static struct kgdb_io kgdbdbgp_io_ops_console = {
44718+ .name = "kgdbdbgp",
44719+ .read_char = kgdbdbgp_read_char,
44720+ .write_char = kgdbdbgp_write_char,
44721+ .is_console = 1
44722+};
44723+
44724 static int kgdbdbgp_wait_time;
44725
44726 static int __init kgdbdbgp_parse_config(char *str)
44727@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44728 ptr++;
44729 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44730 }
44731- kgdb_register_io_module(&kgdbdbgp_io_ops);
44732- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44733+ if (early_dbgp_console.index != -1)
44734+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44735+ else
44736+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44737
44738 return 0;
44739 }
44740diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44741index b369292..9f3ba40 100644
44742--- a/drivers/usb/gadget/u_serial.c
44743+++ b/drivers/usb/gadget/u_serial.c
44744@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44745 spin_lock_irq(&port->port_lock);
44746
44747 /* already open? Great. */
44748- if (port->port.count) {
44749+ if (atomic_read(&port->port.count)) {
44750 status = 0;
44751- port->port.count++;
44752+ atomic_inc(&port->port.count);
44753
44754 /* currently opening/closing? wait ... */
44755 } else if (port->openclose) {
44756@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44757 tty->driver_data = port;
44758 port->port.tty = tty;
44759
44760- port->port.count = 1;
44761+ atomic_set(&port->port.count, 1);
44762 port->openclose = false;
44763
44764 /* if connected, start the I/O stream */
44765@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44766
44767 spin_lock_irq(&port->port_lock);
44768
44769- if (port->port.count != 1) {
44770- if (port->port.count == 0)
44771+ if (atomic_read(&port->port.count) != 1) {
44772+ if (atomic_read(&port->port.count) == 0)
44773 WARN_ON(1);
44774 else
44775- --port->port.count;
44776+ atomic_dec(&port->port.count);
44777 goto exit;
44778 }
44779
44780@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44781 * and sleep if necessary
44782 */
44783 port->openclose = true;
44784- port->port.count = 0;
44785+ atomic_set(&port->port.count, 0);
44786
44787 gser = port->port_usb;
44788 if (gser && gser->disconnect)
44789@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
44790 int cond;
44791
44792 spin_lock_irq(&port->port_lock);
44793- cond = (port->port.count == 0) && !port->openclose;
44794+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44795 spin_unlock_irq(&port->port_lock);
44796 return cond;
44797 }
44798@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44799 /* if it's already open, start I/O ... and notify the serial
44800 * protocol about open/close status (connect/disconnect).
44801 */
44802- if (port->port.count) {
44803+ if (atomic_read(&port->port.count)) {
44804 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44805 gs_start_io(port);
44806 if (gser->connect)
44807@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
44808
44809 port->port_usb = NULL;
44810 gser->ioport = NULL;
44811- if (port->port.count > 0 || port->openclose) {
44812+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44813 wake_up_interruptible(&port->drain_wait);
44814 if (port->port.tty)
44815 tty_hangup(port->port.tty);
44816@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
44817
44818 /* finally, free any unused/unusable I/O buffers */
44819 spin_lock_irqsave(&port->port_lock, flags);
44820- if (port->port.count == 0 && !port->openclose)
44821+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44822 gs_buf_free(&port->port_write_buf);
44823 gs_free_requests(gser->out, &port->read_pool, NULL);
44824 gs_free_requests(gser->out, &port->read_queue, NULL);
44825diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44826index 5f3bcd3..bfca43f 100644
44827--- a/drivers/usb/serial/console.c
44828+++ b/drivers/usb/serial/console.c
44829@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44830
44831 info->port = port;
44832
44833- ++port->port.count;
44834+ atomic_inc(&port->port.count);
44835 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44836 if (serial->type->set_termios) {
44837 /*
44838@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44839 }
44840 /* Now that any required fake tty operations are completed restore
44841 * the tty port count */
44842- --port->port.count;
44843+ atomic_dec(&port->port.count);
44844 /* The console is special in terms of closing the device so
44845 * indicate this port is now acting as a system console. */
44846 port->port.console = 1;
44847@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44848 free_tty:
44849 kfree(tty);
44850 reset_open_count:
44851- port->port.count = 0;
44852+ atomic_set(&port->port.count, 0);
44853 usb_autopm_put_interface(serial->interface);
44854 error_get_interface:
44855 usb_serial_put(serial);
44856diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
44857index 6c3586a..a94e621 100644
44858--- a/drivers/usb/storage/realtek_cr.c
44859+++ b/drivers/usb/storage/realtek_cr.c
44860@@ -429,7 +429,7 @@ static int rts51x_read_status(struct us_data *us,
44861
44862 buf = kmalloc(len, GFP_NOIO);
44863 if (buf == NULL)
44864- return USB_STOR_TRANSPORT_ERROR;
44865+ return -ENOMEM;
44866
44867 US_DEBUGP("%s, lun = %d\n", __func__, lun);
44868
44869diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44870index 75f70f0..d467e1a 100644
44871--- a/drivers/usb/storage/usb.h
44872+++ b/drivers/usb/storage/usb.h
44873@@ -63,7 +63,7 @@ struct us_unusual_dev {
44874 __u8 useProtocol;
44875 __u8 useTransport;
44876 int (*initFunction)(struct us_data *);
44877-};
44878+} __do_const;
44879
44880
44881 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44882diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44883index d6bea3e..60b250e 100644
44884--- a/drivers/usb/wusbcore/wa-hc.h
44885+++ b/drivers/usb/wusbcore/wa-hc.h
44886@@ -192,7 +192,7 @@ struct wahc {
44887 struct list_head xfer_delayed_list;
44888 spinlock_t xfer_list_lock;
44889 struct work_struct xfer_work;
44890- atomic_t xfer_id_count;
44891+ atomic_unchecked_t xfer_id_count;
44892 };
44893
44894
44895@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44896 INIT_LIST_HEAD(&wa->xfer_delayed_list);
44897 spin_lock_init(&wa->xfer_list_lock);
44898 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
44899- atomic_set(&wa->xfer_id_count, 1);
44900+ atomic_set_unchecked(&wa->xfer_id_count, 1);
44901 }
44902
44903 /**
44904diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
44905index 6ef94bc..1b41265 100644
44906--- a/drivers/usb/wusbcore/wa-xfer.c
44907+++ b/drivers/usb/wusbcore/wa-xfer.c
44908@@ -296,7 +296,7 @@ out:
44909 */
44910 static void wa_xfer_id_init(struct wa_xfer *xfer)
44911 {
44912- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
44913+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
44914 }
44915
44916 /*
44917diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
44918index 8c55011..eed4ae1a 100644
44919--- a/drivers/video/aty/aty128fb.c
44920+++ b/drivers/video/aty/aty128fb.c
44921@@ -149,7 +149,7 @@ enum {
44922 };
44923
44924 /* Must match above enum */
44925-static char * const r128_family[] = {
44926+static const char * const r128_family[] = {
44927 "AGP",
44928 "PCI",
44929 "PRO AGP",
44930diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
44931index 4f27fdc..d3537e6 100644
44932--- a/drivers/video/aty/atyfb_base.c
44933+++ b/drivers/video/aty/atyfb_base.c
44934@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
44935 par->accel_flags = var->accel_flags; /* hack */
44936
44937 if (var->accel_flags) {
44938- info->fbops->fb_sync = atyfb_sync;
44939+ pax_open_kernel();
44940+ *(void **)&info->fbops->fb_sync = atyfb_sync;
44941+ pax_close_kernel();
44942 info->flags &= ~FBINFO_HWACCEL_DISABLED;
44943 } else {
44944- info->fbops->fb_sync = NULL;
44945+ pax_open_kernel();
44946+ *(void **)&info->fbops->fb_sync = NULL;
44947+ pax_close_kernel();
44948 info->flags |= FBINFO_HWACCEL_DISABLED;
44949 }
44950
44951diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
44952index 95ec042..e6affdd 100644
44953--- a/drivers/video/aty/mach64_cursor.c
44954+++ b/drivers/video/aty/mach64_cursor.c
44955@@ -7,6 +7,7 @@
44956 #include <linux/string.h>
44957
44958 #include <asm/io.h>
44959+#include <asm/pgtable.h>
44960
44961 #ifdef __sparc__
44962 #include <asm/fbio.h>
44963@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
44964 info->sprite.buf_align = 16; /* and 64 lines tall. */
44965 info->sprite.flags = FB_PIXMAP_IO;
44966
44967- info->fbops->fb_cursor = atyfb_cursor;
44968+ pax_open_kernel();
44969+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
44970+ pax_close_kernel();
44971
44972 return 0;
44973 }
44974diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
44975index 6c5ed6b..b727c88 100644
44976--- a/drivers/video/backlight/kb3886_bl.c
44977+++ b/drivers/video/backlight/kb3886_bl.c
44978@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
44979 static unsigned long kb3886bl_flags;
44980 #define KB3886BL_SUSPENDED 0x01
44981
44982-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
44983+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
44984 {
44985 .ident = "Sahara Touch-iT",
44986 .matches = {
44987diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
44988index 900aa4e..6d49418 100644
44989--- a/drivers/video/fb_defio.c
44990+++ b/drivers/video/fb_defio.c
44991@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
44992
44993 BUG_ON(!fbdefio);
44994 mutex_init(&fbdefio->lock);
44995- info->fbops->fb_mmap = fb_deferred_io_mmap;
44996+ pax_open_kernel();
44997+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
44998+ pax_close_kernel();
44999 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
45000 INIT_LIST_HEAD(&fbdefio->pagelist);
45001 if (fbdefio->delay == 0) /* set a default of 1 s */
45002@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
45003 page->mapping = NULL;
45004 }
45005
45006- info->fbops->fb_mmap = NULL;
45007+ *(void **)&info->fbops->fb_mmap = NULL;
45008 mutex_destroy(&fbdefio->lock);
45009 }
45010 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
45011diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
45012index 5c3960d..15cf8fc 100644
45013--- a/drivers/video/fbcmap.c
45014+++ b/drivers/video/fbcmap.c
45015@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
45016 rc = -ENODEV;
45017 goto out;
45018 }
45019- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
45020- !info->fbops->fb_setcmap)) {
45021+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
45022 rc = -EINVAL;
45023 goto out1;
45024 }
45025diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
45026index 86291dc..7cc5962 100644
45027--- a/drivers/video/fbmem.c
45028+++ b/drivers/video/fbmem.c
45029@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45030 image->dx += image->width + 8;
45031 }
45032 } else if (rotate == FB_ROTATE_UD) {
45033- for (x = 0; x < num && image->dx >= 0; x++) {
45034+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
45035 info->fbops->fb_imageblit(info, image);
45036 image->dx -= image->width + 8;
45037 }
45038@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45039 image->dy += image->height + 8;
45040 }
45041 } else if (rotate == FB_ROTATE_CCW) {
45042- for (x = 0; x < num && image->dy >= 0; x++) {
45043+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
45044 info->fbops->fb_imageblit(info, image);
45045 image->dy -= image->height + 8;
45046 }
45047@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
45048 return -EFAULT;
45049 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
45050 return -EINVAL;
45051- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
45052+ if (con2fb.framebuffer >= FB_MAX)
45053 return -EINVAL;
45054 if (!registered_fb[con2fb.framebuffer])
45055 request_module("fb%d", con2fb.framebuffer);
45056diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
45057index 7672d2e..b56437f 100644
45058--- a/drivers/video/i810/i810_accel.c
45059+++ b/drivers/video/i810/i810_accel.c
45060@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
45061 }
45062 }
45063 printk("ringbuffer lockup!!!\n");
45064+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
45065 i810_report_error(mmio);
45066 par->dev_flags |= LOCKUP;
45067 info->pixmap.scan_align = 1;
45068diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
45069index 3c14e43..eafa544 100644
45070--- a/drivers/video/logo/logo_linux_clut224.ppm
45071+++ b/drivers/video/logo/logo_linux_clut224.ppm
45072@@ -1,1604 +1,1123 @@
45073 P3
45074-# Standard 224-color Linux logo
45075 80 80
45076 255
45077- 0 0 0 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 0 0 0
45084- 0 0 0 0 0 0 0 0 0 0 0 0
45085- 0 0 0 0 0 0 0 0 0 0 0 0
45086- 6 6 6 6 6 6 10 10 10 10 10 10
45087- 10 10 10 6 6 6 6 6 6 6 6 6
45088- 0 0 0 0 0 0 0 0 0 0 0 0
45089- 0 0 0 0 0 0 0 0 0 0 0 0
45090- 0 0 0 0 0 0 0 0 0 0 0 0
45091- 0 0 0 0 0 0 0 0 0 0 0 0
45092- 0 0 0 0 0 0 0 0 0 0 0 0
45093- 0 0 0 0 0 0 0 0 0 0 0 0
45094- 0 0 0 0 0 0 0 0 0 0 0 0
45095- 0 0 0 0 0 0 0 0 0 0 0 0
45096- 0 0 0 0 0 0 0 0 0 0 0 0
45097- 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0
45104- 0 0 0 0 0 0 0 0 0 0 0 0
45105- 0 0 0 6 6 6 10 10 10 14 14 14
45106- 22 22 22 26 26 26 30 30 30 34 34 34
45107- 30 30 30 30 30 30 26 26 26 18 18 18
45108- 14 14 14 10 10 10 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 1 0 0 1 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 0 0 0 0 0 0 0 0 0
45124- 0 0 0 0 0 0 0 0 0 0 0 0
45125- 6 6 6 14 14 14 26 26 26 42 42 42
45126- 54 54 54 66 66 66 78 78 78 78 78 78
45127- 78 78 78 74 74 74 66 66 66 54 54 54
45128- 42 42 42 26 26 26 18 18 18 10 10 10
45129- 6 6 6 0 0 0 0 0 0 0 0 0
45130- 0 0 0 0 0 0 0 0 0 0 0 0
45131- 0 0 0 0 0 0 0 0 0 0 0 0
45132- 0 0 0 0 0 0 0 0 0 0 0 0
45133- 0 0 0 0 0 0 0 0 0 0 0 0
45134- 0 0 0 0 0 0 0 0 0 0 0 0
45135- 0 0 0 0 0 0 0 0 0 0 0 0
45136- 0 0 0 0 0 0 0 0 0 0 0 0
45137- 0 0 0 0 0 0 0 0 0 0 0 0
45138- 0 0 1 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- 0 0 0 0 0 0 0 0 0 0 0 0
45144- 0 0 0 0 0 0 0 0 0 10 10 10
45145- 22 22 22 42 42 42 66 66 66 86 86 86
45146- 66 66 66 38 38 38 38 38 38 22 22 22
45147- 26 26 26 34 34 34 54 54 54 66 66 66
45148- 86 86 86 70 70 70 46 46 46 26 26 26
45149- 14 14 14 6 6 6 0 0 0 0 0 0
45150- 0 0 0 0 0 0 0 0 0 0 0 0
45151- 0 0 0 0 0 0 0 0 0 0 0 0
45152- 0 0 0 0 0 0 0 0 0 0 0 0
45153- 0 0 0 0 0 0 0 0 0 0 0 0
45154- 0 0 0 0 0 0 0 0 0 0 0 0
45155- 0 0 0 0 0 0 0 0 0 0 0 0
45156- 0 0 0 0 0 0 0 0 0 0 0 0
45157- 0 0 0 0 0 0 0 0 0 0 0 0
45158- 0 0 1 0 0 1 0 0 1 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- 0 0 0 0 0 0 0 0 0 0 0 0
45164- 0 0 0 0 0 0 10 10 10 26 26 26
45165- 50 50 50 82 82 82 58 58 58 6 6 6
45166- 2 2 6 2 2 6 2 2 6 2 2 6
45167- 2 2 6 2 2 6 2 2 6 2 2 6
45168- 6 6 6 54 54 54 86 86 86 66 66 66
45169- 38 38 38 18 18 18 6 6 6 0 0 0
45170- 0 0 0 0 0 0 0 0 0 0 0 0
45171- 0 0 0 0 0 0 0 0 0 0 0 0
45172- 0 0 0 0 0 0 0 0 0 0 0 0
45173- 0 0 0 0 0 0 0 0 0 0 0 0
45174- 0 0 0 0 0 0 0 0 0 0 0 0
45175- 0 0 0 0 0 0 0 0 0 0 0 0
45176- 0 0 0 0 0 0 0 0 0 0 0 0
45177- 0 0 0 0 0 0 0 0 0 0 0 0
45178- 0 0 0 0 0 0 0 0 0 0 0 0
45179- 0 0 0 0 0 0 0 0 0 0 0 0
45180- 0 0 0 0 0 0 0 0 0 0 0 0
45181- 0 0 0 0 0 0 0 0 0 0 0 0
45182- 0 0 0 0 0 0 0 0 0 0 0 0
45183- 0 0 0 0 0 0 0 0 0 0 0 0
45184- 0 0 0 6 6 6 22 22 22 50 50 50
45185- 78 78 78 34 34 34 2 2 6 2 2 6
45186- 2 2 6 2 2 6 2 2 6 2 2 6
45187- 2 2 6 2 2 6 2 2 6 2 2 6
45188- 2 2 6 2 2 6 6 6 6 70 70 70
45189- 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 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 0 0 0
45203- 0 0 0 0 0 0 0 0 0 0 0 0
45204- 6 6 6 18 18 18 42 42 42 82 82 82
45205- 26 26 26 2 2 6 2 2 6 2 2 6
45206- 2 2 6 2 2 6 2 2 6 2 2 6
45207- 2 2 6 2 2 6 2 2 6 14 14 14
45208- 46 46 46 34 34 34 6 6 6 2 2 6
45209- 42 42 42 78 78 78 42 42 42 18 18 18
45210- 6 6 6 0 0 0 0 0 0 0 0 0
45211- 0 0 0 0 0 0 0 0 0 0 0 0
45212- 0 0 0 0 0 0 0 0 0 0 0 0
45213- 0 0 0 0 0 0 0 0 0 0 0 0
45214- 0 0 0 0 0 0 0 0 0 0 0 0
45215- 0 0 0 0 0 0 0 0 0 0 0 0
45216- 0 0 0 0 0 0 0 0 0 0 0 0
45217- 0 0 0 0 0 0 0 0 0 0 0 0
45218- 0 0 1 0 0 0 0 0 1 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 0 0 0
45223- 0 0 0 0 0 0 0 0 0 0 0 0
45224- 10 10 10 30 30 30 66 66 66 58 58 58
45225- 2 2 6 2 2 6 2 2 6 2 2 6
45226- 2 2 6 2 2 6 2 2 6 2 2 6
45227- 2 2 6 2 2 6 2 2 6 26 26 26
45228- 86 86 86 101 101 101 46 46 46 10 10 10
45229- 2 2 6 58 58 58 70 70 70 34 34 34
45230- 10 10 10 0 0 0 0 0 0 0 0 0
45231- 0 0 0 0 0 0 0 0 0 0 0 0
45232- 0 0 0 0 0 0 0 0 0 0 0 0
45233- 0 0 0 0 0 0 0 0 0 0 0 0
45234- 0 0 0 0 0 0 0 0 0 0 0 0
45235- 0 0 0 0 0 0 0 0 0 0 0 0
45236- 0 0 0 0 0 0 0 0 0 0 0 0
45237- 0 0 0 0 0 0 0 0 0 0 0 0
45238- 0 0 1 0 0 1 0 0 1 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 0 0 0
45243- 0 0 0 0 0 0 0 0 0 0 0 0
45244- 14 14 14 42 42 42 86 86 86 10 10 10
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 30 30 30
45248- 94 94 94 94 94 94 58 58 58 26 26 26
45249- 2 2 6 6 6 6 78 78 78 54 54 54
45250- 22 22 22 6 6 6 0 0 0 0 0 0
45251- 0 0 0 0 0 0 0 0 0 0 0 0
45252- 0 0 0 0 0 0 0 0 0 0 0 0
45253- 0 0 0 0 0 0 0 0 0 0 0 0
45254- 0 0 0 0 0 0 0 0 0 0 0 0
45255- 0 0 0 0 0 0 0 0 0 0 0 0
45256- 0 0 0 0 0 0 0 0 0 0 0 0
45257- 0 0 0 0 0 0 0 0 0 0 0 0
45258- 0 0 0 0 0 0 0 0 0 0 0 0
45259- 0 0 0 0 0 0 0 0 0 0 0 0
45260- 0 0 0 0 0 0 0 0 0 0 0 0
45261- 0 0 0 0 0 0 0 0 0 0 0 0
45262- 0 0 0 0 0 0 0 0 0 0 0 0
45263- 0 0 0 0 0 0 0 0 0 6 6 6
45264- 22 22 22 62 62 62 62 62 62 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 2 2 6
45267- 2 2 6 2 2 6 2 2 6 26 26 26
45268- 54 54 54 38 38 38 18 18 18 10 10 10
45269- 2 2 6 2 2 6 34 34 34 82 82 82
45270- 38 38 38 14 14 14 0 0 0 0 0 0
45271- 0 0 0 0 0 0 0 0 0 0 0 0
45272- 0 0 0 0 0 0 0 0 0 0 0 0
45273- 0 0 0 0 0 0 0 0 0 0 0 0
45274- 0 0 0 0 0 0 0 0 0 0 0 0
45275- 0 0 0 0 0 0 0 0 0 0 0 0
45276- 0 0 0 0 0 0 0 0 0 0 0 0
45277- 0 0 0 0 0 0 0 0 0 0 0 0
45278- 0 0 0 0 0 1 0 0 1 0 0 0
45279- 0 0 0 0 0 0 0 0 0 0 0 0
45280- 0 0 0 0 0 0 0 0 0 0 0 0
45281- 0 0 0 0 0 0 0 0 0 0 0 0
45282- 0 0 0 0 0 0 0 0 0 0 0 0
45283- 0 0 0 0 0 0 0 0 0 6 6 6
45284- 30 30 30 78 78 78 30 30 30 2 2 6
45285- 2 2 6 2 2 6 2 2 6 2 2 6
45286- 2 2 6 2 2 6 2 2 6 2 2 6
45287- 2 2 6 2 2 6 2 2 6 10 10 10
45288- 10 10 10 2 2 6 2 2 6 2 2 6
45289- 2 2 6 2 2 6 2 2 6 78 78 78
45290- 50 50 50 18 18 18 6 6 6 0 0 0
45291- 0 0 0 0 0 0 0 0 0 0 0 0
45292- 0 0 0 0 0 0 0 0 0 0 0 0
45293- 0 0 0 0 0 0 0 0 0 0 0 0
45294- 0 0 0 0 0 0 0 0 0 0 0 0
45295- 0 0 0 0 0 0 0 0 0 0 0 0
45296- 0 0 0 0 0 0 0 0 0 0 0 0
45297- 0 0 0 0 0 0 0 0 0 0 0 0
45298- 0 0 1 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 0 0 0
45303- 0 0 0 0 0 0 0 0 0 10 10 10
45304- 38 38 38 86 86 86 14 14 14 2 2 6
45305- 2 2 6 2 2 6 2 2 6 2 2 6
45306- 2 2 6 2 2 6 2 2 6 2 2 6
45307- 2 2 6 2 2 6 2 2 6 2 2 6
45308- 2 2 6 2 2 6 2 2 6 2 2 6
45309- 2 2 6 2 2 6 2 2 6 54 54 54
45310- 66 66 66 26 26 26 6 6 6 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 1 0 0 1 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 0 0 0
45323- 0 0 0 0 0 0 0 0 0 14 14 14
45324- 42 42 42 82 82 82 2 2 6 2 2 6
45325- 2 2 6 6 6 6 10 10 10 2 2 6
45326- 2 2 6 2 2 6 2 2 6 2 2 6
45327- 2 2 6 2 2 6 2 2 6 6 6 6
45328- 14 14 14 10 10 10 2 2 6 2 2 6
45329- 2 2 6 2 2 6 2 2 6 18 18 18
45330- 82 82 82 34 34 34 10 10 10 0 0 0
45331- 0 0 0 0 0 0 0 0 0 0 0 0
45332- 0 0 0 0 0 0 0 0 0 0 0 0
45333- 0 0 0 0 0 0 0 0 0 0 0 0
45334- 0 0 0 0 0 0 0 0 0 0 0 0
45335- 0 0 0 0 0 0 0 0 0 0 0 0
45336- 0 0 0 0 0 0 0 0 0 0 0 0
45337- 0 0 0 0 0 0 0 0 0 0 0 0
45338- 0 0 1 0 0 0 0 0 0 0 0 0
45339- 0 0 0 0 0 0 0 0 0 0 0 0
45340- 0 0 0 0 0 0 0 0 0 0 0 0
45341- 0 0 0 0 0 0 0 0 0 0 0 0
45342- 0 0 0 0 0 0 0 0 0 0 0 0
45343- 0 0 0 0 0 0 0 0 0 14 14 14
45344- 46 46 46 86 86 86 2 2 6 2 2 6
45345- 6 6 6 6 6 6 22 22 22 34 34 34
45346- 6 6 6 2 2 6 2 2 6 2 2 6
45347- 2 2 6 2 2 6 18 18 18 34 34 34
45348- 10 10 10 50 50 50 22 22 22 2 2 6
45349- 2 2 6 2 2 6 2 2 6 10 10 10
45350- 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 0 0 0
45359- 0 0 0 0 0 0 0 0 0 0 0 0
45360- 0 0 0 0 0 0 0 0 0 0 0 0
45361- 0 0 0 0 0 0 0 0 0 0 0 0
45362- 0 0 0 0 0 0 0 0 0 0 0 0
45363- 0 0 0 0 0 0 0 0 0 14 14 14
45364- 46 46 46 86 86 86 2 2 6 2 2 6
45365- 38 38 38 116 116 116 94 94 94 22 22 22
45366- 22 22 22 2 2 6 2 2 6 2 2 6
45367- 14 14 14 86 86 86 138 138 138 162 162 162
45368-154 154 154 38 38 38 26 26 26 6 6 6
45369- 2 2 6 2 2 6 2 2 6 2 2 6
45370- 86 86 86 46 46 46 14 14 14 0 0 0
45371- 0 0 0 0 0 0 0 0 0 0 0 0
45372- 0 0 0 0 0 0 0 0 0 0 0 0
45373- 0 0 0 0 0 0 0 0 0 0 0 0
45374- 0 0 0 0 0 0 0 0 0 0 0 0
45375- 0 0 0 0 0 0 0 0 0 0 0 0
45376- 0 0 0 0 0 0 0 0 0 0 0 0
45377- 0 0 0 0 0 0 0 0 0 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 0 0 0
45383- 0 0 0 0 0 0 0 0 0 14 14 14
45384- 46 46 46 86 86 86 2 2 6 14 14 14
45385-134 134 134 198 198 198 195 195 195 116 116 116
45386- 10 10 10 2 2 6 2 2 6 6 6 6
45387-101 98 89 187 187 187 210 210 210 218 218 218
45388-214 214 214 134 134 134 14 14 14 6 6 6
45389- 2 2 6 2 2 6 2 2 6 2 2 6
45390- 86 86 86 50 50 50 18 18 18 6 6 6
45391- 0 0 0 0 0 0 0 0 0 0 0 0
45392- 0 0 0 0 0 0 0 0 0 0 0 0
45393- 0 0 0 0 0 0 0 0 0 0 0 0
45394- 0 0 0 0 0 0 0 0 0 0 0 0
45395- 0 0 0 0 0 0 0 0 0 0 0 0
45396- 0 0 0 0 0 0 0 0 0 0 0 0
45397- 0 0 0 0 0 0 0 0 1 0 0 0
45398- 0 0 1 0 0 1 0 0 1 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 0 0 0
45403- 0 0 0 0 0 0 0 0 0 14 14 14
45404- 46 46 46 86 86 86 2 2 6 54 54 54
45405-218 218 218 195 195 195 226 226 226 246 246 246
45406- 58 58 58 2 2 6 2 2 6 30 30 30
45407-210 210 210 253 253 253 174 174 174 123 123 123
45408-221 221 221 234 234 234 74 74 74 2 2 6
45409- 2 2 6 2 2 6 2 2 6 2 2 6
45410- 70 70 70 58 58 58 22 22 22 6 6 6
45411- 0 0 0 0 0 0 0 0 0 0 0 0
45412- 0 0 0 0 0 0 0 0 0 0 0 0
45413- 0 0 0 0 0 0 0 0 0 0 0 0
45414- 0 0 0 0 0 0 0 0 0 0 0 0
45415- 0 0 0 0 0 0 0 0 0 0 0 0
45416- 0 0 0 0 0 0 0 0 0 0 0 0
45417- 0 0 0 0 0 0 0 0 0 0 0 0
45418- 0 0 0 0 0 0 0 0 0 0 0 0
45419- 0 0 0 0 0 0 0 0 0 0 0 0
45420- 0 0 0 0 0 0 0 0 0 0 0 0
45421- 0 0 0 0 0 0 0 0 0 0 0 0
45422- 0 0 0 0 0 0 0 0 0 0 0 0
45423- 0 0 0 0 0 0 0 0 0 14 14 14
45424- 46 46 46 82 82 82 2 2 6 106 106 106
45425-170 170 170 26 26 26 86 86 86 226 226 226
45426-123 123 123 10 10 10 14 14 14 46 46 46
45427-231 231 231 190 190 190 6 6 6 70 70 70
45428- 90 90 90 238 238 238 158 158 158 2 2 6
45429- 2 2 6 2 2 6 2 2 6 2 2 6
45430- 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
45438- 0 0 1 0 0 1 0 0 1 0 0 0
45439- 0 0 0 0 0 0 0 0 0 0 0 0
45440- 0 0 0 0 0 0 0 0 0 0 0 0
45441- 0 0 0 0 0 0 0 0 0 0 0 0
45442- 0 0 0 0 0 0 0 0 0 0 0 0
45443- 0 0 0 0 0 0 0 0 0 14 14 14
45444- 42 42 42 86 86 86 6 6 6 116 116 116
45445-106 106 106 6 6 6 70 70 70 149 149 149
45446-128 128 128 18 18 18 38 38 38 54 54 54
45447-221 221 221 106 106 106 2 2 6 14 14 14
45448- 46 46 46 190 190 190 198 198 198 2 2 6
45449- 2 2 6 2 2 6 2 2 6 2 2 6
45450- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 0
45458- 0 0 1 0 0 0 0 0 1 0 0 0
45459- 0 0 0 0 0 0 0 0 0 0 0 0
45460- 0 0 0 0 0 0 0 0 0 0 0 0
45461- 0 0 0 0 0 0 0 0 0 0 0 0
45462- 0 0 0 0 0 0 0 0 0 0 0 0
45463- 0 0 0 0 0 0 0 0 0 14 14 14
45464- 42 42 42 94 94 94 14 14 14 101 101 101
45465-128 128 128 2 2 6 18 18 18 116 116 116
45466-118 98 46 121 92 8 121 92 8 98 78 10
45467-162 162 162 106 106 106 2 2 6 2 2 6
45468- 2 2 6 195 195 195 195 195 195 6 6 6
45469- 2 2 6 2 2 6 2 2 6 2 2 6
45470- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
45478- 0 0 1 0 0 0 0 0 1 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 0 0 0
45483- 0 0 0 0 0 0 0 0 0 10 10 10
45484- 38 38 38 90 90 90 14 14 14 58 58 58
45485-210 210 210 26 26 26 54 38 6 154 114 10
45486-226 170 11 236 186 11 225 175 15 184 144 12
45487-215 174 15 175 146 61 37 26 9 2 2 6
45488- 70 70 70 246 246 246 138 138 138 2 2 6
45489- 2 2 6 2 2 6 2 2 6 2 2 6
45490- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
45503- 0 0 0 0 0 0 0 0 0 10 10 10
45504- 38 38 38 86 86 86 14 14 14 10 10 10
45505-195 195 195 188 164 115 192 133 9 225 175 15
45506-239 182 13 234 190 10 232 195 16 232 200 30
45507-245 207 45 241 208 19 232 195 16 184 144 12
45508-218 194 134 211 206 186 42 42 42 2 2 6
45509- 2 2 6 2 2 6 2 2 6 2 2 6
45510- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
45523- 0 0 0 0 0 0 0 0 0 10 10 10
45524- 34 34 34 86 86 86 14 14 14 2 2 6
45525-121 87 25 192 133 9 219 162 10 239 182 13
45526-236 186 11 232 195 16 241 208 19 244 214 54
45527-246 218 60 246 218 38 246 215 20 241 208 19
45528-241 208 19 226 184 13 121 87 25 2 2 6
45529- 2 2 6 2 2 6 2 2 6 2 2 6
45530- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
45543- 0 0 0 0 0 0 0 0 0 10 10 10
45544- 34 34 34 82 82 82 30 30 30 61 42 6
45545-180 123 7 206 145 10 230 174 11 239 182 13
45546-234 190 10 238 202 15 241 208 19 246 218 74
45547-246 218 38 246 215 20 246 215 20 246 215 20
45548-226 184 13 215 174 15 184 144 12 6 6 6
45549- 2 2 6 2 2 6 2 2 6 2 2 6
45550- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
45563- 0 0 0 0 0 0 0 0 0 10 10 10
45564- 30 30 30 78 78 78 50 50 50 104 69 6
45565-192 133 9 216 158 10 236 178 12 236 186 11
45566-232 195 16 241 208 19 244 214 54 245 215 43
45567-246 215 20 246 215 20 241 208 19 198 155 10
45568-200 144 11 216 158 10 156 118 10 2 2 6
45569- 2 2 6 2 2 6 2 2 6 2 2 6
45570- 6 6 6 90 90 90 54 54 54 18 18 18
45571- 6 6 6 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 0 0 0 0 0 0
45583- 0 0 0 0 0 0 0 0 0 10 10 10
45584- 30 30 30 78 78 78 46 46 46 22 22 22
45585-137 92 6 210 162 10 239 182 13 238 190 10
45586-238 202 15 241 208 19 246 215 20 246 215 20
45587-241 208 19 203 166 17 185 133 11 210 150 10
45588-216 158 10 210 150 10 102 78 10 2 2 6
45589- 6 6 6 54 54 54 14 14 14 2 2 6
45590- 2 2 6 62 62 62 74 74 74 30 30 30
45591- 10 10 10 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 0 0 0 0 0 0
45603- 0 0 0 0 0 0 0 0 0 10 10 10
45604- 34 34 34 78 78 78 50 50 50 6 6 6
45605- 94 70 30 139 102 15 190 146 13 226 184 13
45606-232 200 30 232 195 16 215 174 15 190 146 13
45607-168 122 10 192 133 9 210 150 10 213 154 11
45608-202 150 34 182 157 106 101 98 89 2 2 6
45609- 2 2 6 78 78 78 116 116 116 58 58 58
45610- 2 2 6 22 22 22 90 90 90 46 46 46
45611- 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
45623- 0 0 0 0 0 0 0 0 0 10 10 10
45624- 38 38 38 86 86 86 50 50 50 6 6 6
45625-128 128 128 174 154 114 156 107 11 168 122 10
45626-198 155 10 184 144 12 197 138 11 200 144 11
45627-206 145 10 206 145 10 197 138 11 188 164 115
45628-195 195 195 198 198 198 174 174 174 14 14 14
45629- 2 2 6 22 22 22 116 116 116 116 116 116
45630- 22 22 22 2 2 6 74 74 74 70 70 70
45631- 30 30 30 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
45643- 0 0 0 0 0 0 6 6 6 18 18 18
45644- 50 50 50 101 101 101 26 26 26 10 10 10
45645-138 138 138 190 190 190 174 154 114 156 107 11
45646-197 138 11 200 144 11 197 138 11 192 133 9
45647-180 123 7 190 142 34 190 178 144 187 187 187
45648-202 202 202 221 221 221 214 214 214 66 66 66
45649- 2 2 6 2 2 6 50 50 50 62 62 62
45650- 6 6 6 2 2 6 10 10 10 90 90 90
45651- 50 50 50 18 18 18 6 6 6 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 0 0 0
45662- 0 0 0 0 0 0 0 0 0 0 0 0
45663- 0 0 0 0 0 0 10 10 10 34 34 34
45664- 74 74 74 74 74 74 2 2 6 6 6 6
45665-144 144 144 198 198 198 190 190 190 178 166 146
45666-154 121 60 156 107 11 156 107 11 168 124 44
45667-174 154 114 187 187 187 190 190 190 210 210 210
45668-246 246 246 253 253 253 253 253 253 182 182 182
45669- 6 6 6 2 2 6 2 2 6 2 2 6
45670- 2 2 6 2 2 6 2 2 6 62 62 62
45671- 74 74 74 34 34 34 14 14 14 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 0 0 0
45682- 0 0 0 0 0 0 0 0 0 0 0 0
45683- 0 0 0 10 10 10 22 22 22 54 54 54
45684- 94 94 94 18 18 18 2 2 6 46 46 46
45685-234 234 234 221 221 221 190 190 190 190 190 190
45686-190 190 190 187 187 187 187 187 187 190 190 190
45687-190 190 190 195 195 195 214 214 214 242 242 242
45688-253 253 253 253 253 253 253 253 253 253 253 253
45689- 82 82 82 2 2 6 2 2 6 2 2 6
45690- 2 2 6 2 2 6 2 2 6 14 14 14
45691- 86 86 86 54 54 54 22 22 22 6 6 6
45692- 0 0 0 0 0 0 0 0 0 0 0 0
45693- 0 0 0 0 0 0 0 0 0 0 0 0
45694- 0 0 0 0 0 0 0 0 0 0 0 0
45695- 0 0 0 0 0 0 0 0 0 0 0 0
45696- 0 0 0 0 0 0 0 0 0 0 0 0
45697- 0 0 0 0 0 0 0 0 0 0 0 0
45698- 0 0 0 0 0 0 0 0 0 0 0 0
45699- 0 0 0 0 0 0 0 0 0 0 0 0
45700- 0 0 0 0 0 0 0 0 0 0 0 0
45701- 0 0 0 0 0 0 0 0 0 0 0 0
45702- 0 0 0 0 0 0 0 0 0 0 0 0
45703- 6 6 6 18 18 18 46 46 46 90 90 90
45704- 46 46 46 18 18 18 6 6 6 182 182 182
45705-253 253 253 246 246 246 206 206 206 190 190 190
45706-190 190 190 190 190 190 190 190 190 190 190 190
45707-206 206 206 231 231 231 250 250 250 253 253 253
45708-253 253 253 253 253 253 253 253 253 253 253 253
45709-202 202 202 14 14 14 2 2 6 2 2 6
45710- 2 2 6 2 2 6 2 2 6 2 2 6
45711- 42 42 42 86 86 86 42 42 42 18 18 18
45712- 6 6 6 0 0 0 0 0 0 0 0 0
45713- 0 0 0 0 0 0 0 0 0 0 0 0
45714- 0 0 0 0 0 0 0 0 0 0 0 0
45715- 0 0 0 0 0 0 0 0 0 0 0 0
45716- 0 0 0 0 0 0 0 0 0 0 0 0
45717- 0 0 0 0 0 0 0 0 0 0 0 0
45718- 0 0 0 0 0 0 0 0 0 0 0 0
45719- 0 0 0 0 0 0 0 0 0 0 0 0
45720- 0 0 0 0 0 0 0 0 0 0 0 0
45721- 0 0 0 0 0 0 0 0 0 0 0 0
45722- 0 0 0 0 0 0 0 0 0 6 6 6
45723- 14 14 14 38 38 38 74 74 74 66 66 66
45724- 2 2 6 6 6 6 90 90 90 250 250 250
45725-253 253 253 253 253 253 238 238 238 198 198 198
45726-190 190 190 190 190 190 195 195 195 221 221 221
45727-246 246 246 253 253 253 253 253 253 253 253 253
45728-253 253 253 253 253 253 253 253 253 253 253 253
45729-253 253 253 82 82 82 2 2 6 2 2 6
45730- 2 2 6 2 2 6 2 2 6 2 2 6
45731- 2 2 6 78 78 78 70 70 70 34 34 34
45732- 14 14 14 6 6 6 0 0 0 0 0 0
45733- 0 0 0 0 0 0 0 0 0 0 0 0
45734- 0 0 0 0 0 0 0 0 0 0 0 0
45735- 0 0 0 0 0 0 0 0 0 0 0 0
45736- 0 0 0 0 0 0 0 0 0 0 0 0
45737- 0 0 0 0 0 0 0 0 0 0 0 0
45738- 0 0 0 0 0 0 0 0 0 0 0 0
45739- 0 0 0 0 0 0 0 0 0 0 0 0
45740- 0 0 0 0 0 0 0 0 0 0 0 0
45741- 0 0 0 0 0 0 0 0 0 0 0 0
45742- 0 0 0 0 0 0 0 0 0 14 14 14
45743- 34 34 34 66 66 66 78 78 78 6 6 6
45744- 2 2 6 18 18 18 218 218 218 253 253 253
45745-253 253 253 253 253 253 253 253 253 246 246 246
45746-226 226 226 231 231 231 246 246 246 253 253 253
45747-253 253 253 253 253 253 253 253 253 253 253 253
45748-253 253 253 253 253 253 253 253 253 253 253 253
45749-253 253 253 178 178 178 2 2 6 2 2 6
45750- 2 2 6 2 2 6 2 2 6 2 2 6
45751- 2 2 6 18 18 18 90 90 90 62 62 62
45752- 30 30 30 10 10 10 0 0 0 0 0 0
45753- 0 0 0 0 0 0 0 0 0 0 0 0
45754- 0 0 0 0 0 0 0 0 0 0 0 0
45755- 0 0 0 0 0 0 0 0 0 0 0 0
45756- 0 0 0 0 0 0 0 0 0 0 0 0
45757- 0 0 0 0 0 0 0 0 0 0 0 0
45758- 0 0 0 0 0 0 0 0 0 0 0 0
45759- 0 0 0 0 0 0 0 0 0 0 0 0
45760- 0 0 0 0 0 0 0 0 0 0 0 0
45761- 0 0 0 0 0 0 0 0 0 0 0 0
45762- 0 0 0 0 0 0 10 10 10 26 26 26
45763- 58 58 58 90 90 90 18 18 18 2 2 6
45764- 2 2 6 110 110 110 253 253 253 253 253 253
45765-253 253 253 253 253 253 253 253 253 253 253 253
45766-250 250 250 253 253 253 253 253 253 253 253 253
45767-253 253 253 253 253 253 253 253 253 253 253 253
45768-253 253 253 253 253 253 253 253 253 253 253 253
45769-253 253 253 231 231 231 18 18 18 2 2 6
45770- 2 2 6 2 2 6 2 2 6 2 2 6
45771- 2 2 6 2 2 6 18 18 18 94 94 94
45772- 54 54 54 26 26 26 10 10 10 0 0 0
45773- 0 0 0 0 0 0 0 0 0 0 0 0
45774- 0 0 0 0 0 0 0 0 0 0 0 0
45775- 0 0 0 0 0 0 0 0 0 0 0 0
45776- 0 0 0 0 0 0 0 0 0 0 0 0
45777- 0 0 0 0 0 0 0 0 0 0 0 0
45778- 0 0 0 0 0 0 0 0 0 0 0 0
45779- 0 0 0 0 0 0 0 0 0 0 0 0
45780- 0 0 0 0 0 0 0 0 0 0 0 0
45781- 0 0 0 0 0 0 0 0 0 0 0 0
45782- 0 0 0 6 6 6 22 22 22 50 50 50
45783- 90 90 90 26 26 26 2 2 6 2 2 6
45784- 14 14 14 195 195 195 250 250 250 253 253 253
45785-253 253 253 253 253 253 253 253 253 253 253 253
45786-253 253 253 253 253 253 253 253 253 253 253 253
45787-253 253 253 253 253 253 253 253 253 253 253 253
45788-253 253 253 253 253 253 253 253 253 253 253 253
45789-250 250 250 242 242 242 54 54 54 2 2 6
45790- 2 2 6 2 2 6 2 2 6 2 2 6
45791- 2 2 6 2 2 6 2 2 6 38 38 38
45792- 86 86 86 50 50 50 22 22 22 6 6 6
45793- 0 0 0 0 0 0 0 0 0 0 0 0
45794- 0 0 0 0 0 0 0 0 0 0 0 0
45795- 0 0 0 0 0 0 0 0 0 0 0 0
45796- 0 0 0 0 0 0 0 0 0 0 0 0
45797- 0 0 0 0 0 0 0 0 0 0 0 0
45798- 0 0 0 0 0 0 0 0 0 0 0 0
45799- 0 0 0 0 0 0 0 0 0 0 0 0
45800- 0 0 0 0 0 0 0 0 0 0 0 0
45801- 0 0 0 0 0 0 0 0 0 0 0 0
45802- 6 6 6 14 14 14 38 38 38 82 82 82
45803- 34 34 34 2 2 6 2 2 6 2 2 6
45804- 42 42 42 195 195 195 246 246 246 253 253 253
45805-253 253 253 253 253 253 253 253 253 250 250 250
45806-242 242 242 242 242 242 250 250 250 253 253 253
45807-253 253 253 253 253 253 253 253 253 253 253 253
45808-253 253 253 250 250 250 246 246 246 238 238 238
45809-226 226 226 231 231 231 101 101 101 6 6 6
45810- 2 2 6 2 2 6 2 2 6 2 2 6
45811- 2 2 6 2 2 6 2 2 6 2 2 6
45812- 38 38 38 82 82 82 42 42 42 14 14 14
45813- 6 6 6 0 0 0 0 0 0 0 0 0
45814- 0 0 0 0 0 0 0 0 0 0 0 0
45815- 0 0 0 0 0 0 0 0 0 0 0 0
45816- 0 0 0 0 0 0 0 0 0 0 0 0
45817- 0 0 0 0 0 0 0 0 0 0 0 0
45818- 0 0 0 0 0 0 0 0 0 0 0 0
45819- 0 0 0 0 0 0 0 0 0 0 0 0
45820- 0 0 0 0 0 0 0 0 0 0 0 0
45821- 0 0 0 0 0 0 0 0 0 0 0 0
45822- 10 10 10 26 26 26 62 62 62 66 66 66
45823- 2 2 6 2 2 6 2 2 6 6 6 6
45824- 70 70 70 170 170 170 206 206 206 234 234 234
45825-246 246 246 250 250 250 250 250 250 238 238 238
45826-226 226 226 231 231 231 238 238 238 250 250 250
45827-250 250 250 250 250 250 246 246 246 231 231 231
45828-214 214 214 206 206 206 202 202 202 202 202 202
45829-198 198 198 202 202 202 182 182 182 18 18 18
45830- 2 2 6 2 2 6 2 2 6 2 2 6
45831- 2 2 6 2 2 6 2 2 6 2 2 6
45832- 2 2 6 62 62 62 66 66 66 30 30 30
45833- 10 10 10 0 0 0 0 0 0 0 0 0
45834- 0 0 0 0 0 0 0 0 0 0 0 0
45835- 0 0 0 0 0 0 0 0 0 0 0 0
45836- 0 0 0 0 0 0 0 0 0 0 0 0
45837- 0 0 0 0 0 0 0 0 0 0 0 0
45838- 0 0 0 0 0 0 0 0 0 0 0 0
45839- 0 0 0 0 0 0 0 0 0 0 0 0
45840- 0 0 0 0 0 0 0 0 0 0 0 0
45841- 0 0 0 0 0 0 0 0 0 0 0 0
45842- 14 14 14 42 42 42 82 82 82 18 18 18
45843- 2 2 6 2 2 6 2 2 6 10 10 10
45844- 94 94 94 182 182 182 218 218 218 242 242 242
45845-250 250 250 253 253 253 253 253 253 250 250 250
45846-234 234 234 253 253 253 253 253 253 253 253 253
45847-253 253 253 253 253 253 253 253 253 246 246 246
45848-238 238 238 226 226 226 210 210 210 202 202 202
45849-195 195 195 195 195 195 210 210 210 158 158 158
45850- 6 6 6 14 14 14 50 50 50 14 14 14
45851- 2 2 6 2 2 6 2 2 6 2 2 6
45852- 2 2 6 6 6 6 86 86 86 46 46 46
45853- 18 18 18 6 6 6 0 0 0 0 0 0
45854- 0 0 0 0 0 0 0 0 0 0 0 0
45855- 0 0 0 0 0 0 0 0 0 0 0 0
45856- 0 0 0 0 0 0 0 0 0 0 0 0
45857- 0 0 0 0 0 0 0 0 0 0 0 0
45858- 0 0 0 0 0 0 0 0 0 0 0 0
45859- 0 0 0 0 0 0 0 0 0 0 0 0
45860- 0 0 0 0 0 0 0 0 0 0 0 0
45861- 0 0 0 0 0 0 0 0 0 6 6 6
45862- 22 22 22 54 54 54 70 70 70 2 2 6
45863- 2 2 6 10 10 10 2 2 6 22 22 22
45864-166 166 166 231 231 231 250 250 250 253 253 253
45865-253 253 253 253 253 253 253 253 253 250 250 250
45866-242 242 242 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 246 246 246
45869-231 231 231 206 206 206 198 198 198 226 226 226
45870- 94 94 94 2 2 6 6 6 6 38 38 38
45871- 30 30 30 2 2 6 2 2 6 2 2 6
45872- 2 2 6 2 2 6 62 62 62 66 66 66
45873- 26 26 26 10 10 10 0 0 0 0 0 0
45874- 0 0 0 0 0 0 0 0 0 0 0 0
45875- 0 0 0 0 0 0 0 0 0 0 0 0
45876- 0 0 0 0 0 0 0 0 0 0 0 0
45877- 0 0 0 0 0 0 0 0 0 0 0 0
45878- 0 0 0 0 0 0 0 0 0 0 0 0
45879- 0 0 0 0 0 0 0 0 0 0 0 0
45880- 0 0 0 0 0 0 0 0 0 0 0 0
45881- 0 0 0 0 0 0 0 0 0 10 10 10
45882- 30 30 30 74 74 74 50 50 50 2 2 6
45883- 26 26 26 26 26 26 2 2 6 106 106 106
45884-238 238 238 253 253 253 253 253 253 253 253 253
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 218 218 218 202 202 202
45890-210 210 210 14 14 14 2 2 6 2 2 6
45891- 30 30 30 22 22 22 2 2 6 2 2 6
45892- 2 2 6 2 2 6 18 18 18 86 86 86
45893- 42 42 42 14 14 14 0 0 0 0 0 0
45894- 0 0 0 0 0 0 0 0 0 0 0 0
45895- 0 0 0 0 0 0 0 0 0 0 0 0
45896- 0 0 0 0 0 0 0 0 0 0 0 0
45897- 0 0 0 0 0 0 0 0 0 0 0 0
45898- 0 0 0 0 0 0 0 0 0 0 0 0
45899- 0 0 0 0 0 0 0 0 0 0 0 0
45900- 0 0 0 0 0 0 0 0 0 0 0 0
45901- 0 0 0 0 0 0 0 0 0 14 14 14
45902- 42 42 42 90 90 90 22 22 22 2 2 6
45903- 42 42 42 2 2 6 18 18 18 218 218 218
45904-253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 221 221 221
45910-218 218 218 101 101 101 2 2 6 14 14 14
45911- 18 18 18 38 38 38 10 10 10 2 2 6
45912- 2 2 6 2 2 6 2 2 6 78 78 78
45913- 58 58 58 22 22 22 6 6 6 0 0 0
45914- 0 0 0 0 0 0 0 0 0 0 0 0
45915- 0 0 0 0 0 0 0 0 0 0 0 0
45916- 0 0 0 0 0 0 0 0 0 0 0 0
45917- 0 0 0 0 0 0 0 0 0 0 0 0
45918- 0 0 0 0 0 0 0 0 0 0 0 0
45919- 0 0 0 0 0 0 0 0 0 0 0 0
45920- 0 0 0 0 0 0 0 0 0 0 0 0
45921- 0 0 0 0 0 0 6 6 6 18 18 18
45922- 54 54 54 82 82 82 2 2 6 26 26 26
45923- 22 22 22 2 2 6 123 123 123 253 253 253
45924-253 253 253 253 253 253 253 253 253 253 253 253
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 253 253 253 250 250 250
45930-238 238 238 198 198 198 6 6 6 38 38 38
45931- 58 58 58 26 26 26 38 38 38 2 2 6
45932- 2 2 6 2 2 6 2 2 6 46 46 46
45933- 78 78 78 30 30 30 10 10 10 0 0 0
45934- 0 0 0 0 0 0 0 0 0 0 0 0
45935- 0 0 0 0 0 0 0 0 0 0 0 0
45936- 0 0 0 0 0 0 0 0 0 0 0 0
45937- 0 0 0 0 0 0 0 0 0 0 0 0
45938- 0 0 0 0 0 0 0 0 0 0 0 0
45939- 0 0 0 0 0 0 0 0 0 0 0 0
45940- 0 0 0 0 0 0 0 0 0 0 0 0
45941- 0 0 0 0 0 0 10 10 10 30 30 30
45942- 74 74 74 58 58 58 2 2 6 42 42 42
45943- 2 2 6 22 22 22 231 231 231 253 253 253
45944-253 253 253 253 253 253 253 253 253 253 253 253
45945-253 253 253 253 253 253 253 253 253 250 250 250
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 253 253 253 253 253 253
45950-253 253 253 246 246 246 46 46 46 38 38 38
45951- 42 42 42 14 14 14 38 38 38 14 14 14
45952- 2 2 6 2 2 6 2 2 6 6 6 6
45953- 86 86 86 46 46 46 14 14 14 0 0 0
45954- 0 0 0 0 0 0 0 0 0 0 0 0
45955- 0 0 0 0 0 0 0 0 0 0 0 0
45956- 0 0 0 0 0 0 0 0 0 0 0 0
45957- 0 0 0 0 0 0 0 0 0 0 0 0
45958- 0 0 0 0 0 0 0 0 0 0 0 0
45959- 0 0 0 0 0 0 0 0 0 0 0 0
45960- 0 0 0 0 0 0 0 0 0 0 0 0
45961- 0 0 0 6 6 6 14 14 14 42 42 42
45962- 90 90 90 18 18 18 18 18 18 26 26 26
45963- 2 2 6 116 116 116 253 253 253 253 253 253
45964-253 253 253 253 253 253 253 253 253 253 253 253
45965-253 253 253 253 253 253 250 250 250 238 238 238
45966-253 253 253 253 253 253 253 253 253 253 253 253
45967-253 253 253 253 253 253 253 253 253 253 253 253
45968-253 253 253 253 253 253 253 253 253 253 253 253
45969-253 253 253 253 253 253 253 253 253 253 253 253
45970-253 253 253 253 253 253 94 94 94 6 6 6
45971- 2 2 6 2 2 6 10 10 10 34 34 34
45972- 2 2 6 2 2 6 2 2 6 2 2 6
45973- 74 74 74 58 58 58 22 22 22 6 6 6
45974- 0 0 0 0 0 0 0 0 0 0 0 0
45975- 0 0 0 0 0 0 0 0 0 0 0 0
45976- 0 0 0 0 0 0 0 0 0 0 0 0
45977- 0 0 0 0 0 0 0 0 0 0 0 0
45978- 0 0 0 0 0 0 0 0 0 0 0 0
45979- 0 0 0 0 0 0 0 0 0 0 0 0
45980- 0 0 0 0 0 0 0 0 0 0 0 0
45981- 0 0 0 10 10 10 26 26 26 66 66 66
45982- 82 82 82 2 2 6 38 38 38 6 6 6
45983- 14 14 14 210 210 210 253 253 253 253 253 253
45984-253 253 253 253 253 253 253 253 253 253 253 253
45985-253 253 253 253 253 253 246 246 246 242 242 242
45986-253 253 253 253 253 253 253 253 253 253 253 253
45987-253 253 253 253 253 253 253 253 253 253 253 253
45988-253 253 253 253 253 253 253 253 253 253 253 253
45989-253 253 253 253 253 253 253 253 253 253 253 253
45990-253 253 253 253 253 253 144 144 144 2 2 6
45991- 2 2 6 2 2 6 2 2 6 46 46 46
45992- 2 2 6 2 2 6 2 2 6 2 2 6
45993- 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0
46000- 0 0 0 0 0 0 0 0 0 0 0 0
46001- 6 6 6 14 14 14 42 42 42 90 90 90
46002- 26 26 26 6 6 6 42 42 42 2 2 6
46003- 74 74 74 250 250 250 253 253 253 253 253 253
46004-253 253 253 253 253 253 253 253 253 253 253 253
46005-253 253 253 253 253 253 242 242 242 242 242 242
46006-253 253 253 253 253 253 253 253 253 253 253 253
46007-253 253 253 253 253 253 253 253 253 253 253 253
46008-253 253 253 253 253 253 253 253 253 253 253 253
46009-253 253 253 253 253 253 253 253 253 253 253 253
46010-253 253 253 253 253 253 182 182 182 2 2 6
46011- 2 2 6 2 2 6 2 2 6 46 46 46
46012- 2 2 6 2 2 6 2 2 6 2 2 6
46013- 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0
46020- 0 0 0 0 0 0 0 0 0 0 0 0
46021- 10 10 10 26 26 26 66 66 66 82 82 82
46022- 2 2 6 22 22 22 18 18 18 2 2 6
46023-149 149 149 253 253 253 253 253 253 253 253 253
46024-253 253 253 253 253 253 253 253 253 253 253 253
46025-253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253
46030-253 253 253 253 253 253 206 206 206 2 2 6
46031- 2 2 6 2 2 6 2 2 6 38 38 38
46032- 2 2 6 2 2 6 2 2 6 2 2 6
46033- 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0 0 0 0
46040- 0 0 0 0 0 0 0 0 0 6 6 6
46041- 18 18 18 46 46 46 86 86 86 18 18 18
46042- 2 2 6 34 34 34 10 10 10 6 6 6
46043-210 210 210 253 253 253 253 253 253 253 253 253
46044-253 253 253 253 253 253 253 253 253 253 253 253
46045-253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253
46050-253 253 253 253 253 253 221 221 221 6 6 6
46051- 2 2 6 2 2 6 6 6 6 30 30 30
46052- 2 2 6 2 2 6 2 2 6 2 2 6
46053- 2 2 6 82 82 82 54 54 54 18 18 18
46054- 6 6 6 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 0 0 0 0 0 0
46060- 0 0 0 0 0 0 0 0 0 10 10 10
46061- 26 26 26 66 66 66 62 62 62 2 2 6
46062- 2 2 6 38 38 38 10 10 10 26 26 26
46063-238 238 238 253 253 253 253 253 253 253 253 253
46064-253 253 253 253 253 253 253 253 253 253 253 253
46065-253 253 253 253 253 253 231 231 231 238 238 238
46066-253 253 253 253 253 253 253 253 253 253 253 253
46067-253 253 253 253 253 253 253 253 253 253 253 253
46068-253 253 253 253 253 253 253 253 253 253 253 253
46069-253 253 253 253 253 253 253 253 253 253 253 253
46070-253 253 253 253 253 253 231 231 231 6 6 6
46071- 2 2 6 2 2 6 10 10 10 30 30 30
46072- 2 2 6 2 2 6 2 2 6 2 2 6
46073- 2 2 6 66 66 66 58 58 58 22 22 22
46074- 6 6 6 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 0 0 0 0 0 0
46080- 0 0 0 0 0 0 0 0 0 10 10 10
46081- 38 38 38 78 78 78 6 6 6 2 2 6
46082- 2 2 6 46 46 46 14 14 14 42 42 42
46083-246 246 246 253 253 253 253 253 253 253 253 253
46084-253 253 253 253 253 253 253 253 253 253 253 253
46085-253 253 253 253 253 253 231 231 231 242 242 242
46086-253 253 253 253 253 253 253 253 253 253 253 253
46087-253 253 253 253 253 253 253 253 253 253 253 253
46088-253 253 253 253 253 253 253 253 253 253 253 253
46089-253 253 253 253 253 253 253 253 253 253 253 253
46090-253 253 253 253 253 253 234 234 234 10 10 10
46091- 2 2 6 2 2 6 22 22 22 14 14 14
46092- 2 2 6 2 2 6 2 2 6 2 2 6
46093- 2 2 6 66 66 66 62 62 62 22 22 22
46094- 6 6 6 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 0 0 0 0 0 0
46100- 0 0 0 0 0 0 6 6 6 18 18 18
46101- 50 50 50 74 74 74 2 2 6 2 2 6
46102- 14 14 14 70 70 70 34 34 34 62 62 62
46103-250 250 250 253 253 253 253 253 253 253 253 253
46104-253 253 253 253 253 253 253 253 253 253 253 253
46105-253 253 253 253 253 253 231 231 231 246 246 246
46106-253 253 253 253 253 253 253 253 253 253 253 253
46107-253 253 253 253 253 253 253 253 253 253 253 253
46108-253 253 253 253 253 253 253 253 253 253 253 253
46109-253 253 253 253 253 253 253 253 253 253 253 253
46110-253 253 253 253 253 253 234 234 234 14 14 14
46111- 2 2 6 2 2 6 30 30 30 2 2 6
46112- 2 2 6 2 2 6 2 2 6 2 2 6
46113- 2 2 6 66 66 66 62 62 62 22 22 22
46114- 6 6 6 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 0 0 0
46119- 0 0 0 0 0 0 0 0 0 0 0 0
46120- 0 0 0 0 0 0 6 6 6 18 18 18
46121- 54 54 54 62 62 62 2 2 6 2 2 6
46122- 2 2 6 30 30 30 46 46 46 70 70 70
46123-250 250 250 253 253 253 253 253 253 253 253 253
46124-253 253 253 253 253 253 253 253 253 253 253 253
46125-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253
46129-253 253 253 253 253 253 253 253 253 253 253 253
46130-253 253 253 253 253 253 226 226 226 10 10 10
46131- 2 2 6 6 6 6 30 30 30 2 2 6
46132- 2 2 6 2 2 6 2 2 6 2 2 6
46133- 2 2 6 66 66 66 58 58 58 22 22 22
46134- 6 6 6 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 0 0 0 0 0 0 0 0 0
46139- 0 0 0 0 0 0 0 0 0 0 0 0
46140- 0 0 0 0 0 0 6 6 6 22 22 22
46141- 58 58 58 62 62 62 2 2 6 2 2 6
46142- 2 2 6 2 2 6 30 30 30 78 78 78
46143-250 250 250 253 253 253 253 253 253 253 253 253
46144-253 253 253 253 253 253 253 253 253 253 253 253
46145-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253
46149-253 253 253 253 253 253 253 253 253 253 253 253
46150-253 253 253 253 253 253 206 206 206 2 2 6
46151- 22 22 22 34 34 34 18 14 6 22 22 22
46152- 26 26 26 18 18 18 6 6 6 2 2 6
46153- 2 2 6 82 82 82 54 54 54 18 18 18
46154- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
46159- 0 0 0 0 0 0 0 0 0 0 0 0
46160- 0 0 0 0 0 0 6 6 6 26 26 26
46161- 62 62 62 106 106 106 74 54 14 185 133 11
46162-210 162 10 121 92 8 6 6 6 62 62 62
46163-238 238 238 253 253 253 253 253 253 253 253 253
46164-253 253 253 253 253 253 253 253 253 253 253 253
46165-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253
46169-253 253 253 253 253 253 253 253 253 253 253 253
46170-253 253 253 253 253 253 158 158 158 18 18 18
46171- 14 14 14 2 2 6 2 2 6 2 2 6
46172- 6 6 6 18 18 18 66 66 66 38 38 38
46173- 6 6 6 94 94 94 50 50 50 18 18 18
46174- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
46179- 0 0 0 0 0 0 0 0 0 6 6 6
46180- 10 10 10 10 10 10 18 18 18 38 38 38
46181- 78 78 78 142 134 106 216 158 10 242 186 14
46182-246 190 14 246 190 14 156 118 10 10 10 10
46183- 90 90 90 238 238 238 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 231 231 231 250 250 250
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 253 253 253 253 253 253 253 253 253
46189-253 253 253 253 253 253 253 253 253 246 230 190
46190-238 204 91 238 204 91 181 142 44 37 26 9
46191- 2 2 6 2 2 6 2 2 6 2 2 6
46192- 2 2 6 2 2 6 38 38 38 46 46 46
46193- 26 26 26 106 106 106 54 54 54 18 18 18
46194- 6 6 6 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 0 0 0
46198- 0 0 0 0 0 0 0 0 0 0 0 0
46199- 0 0 0 6 6 6 14 14 14 22 22 22
46200- 30 30 30 38 38 38 50 50 50 70 70 70
46201-106 106 106 190 142 34 226 170 11 242 186 14
46202-246 190 14 246 190 14 246 190 14 154 114 10
46203- 6 6 6 74 74 74 226 226 226 253 253 253
46204-253 253 253 253 253 253 253 253 253 253 253 253
46205-253 253 253 253 253 253 231 231 231 250 250 250
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 253 253 253 253 253 253 253 253 253
46209-253 253 253 253 253 253 253 253 253 228 184 62
46210-241 196 14 241 208 19 232 195 16 38 30 10
46211- 2 2 6 2 2 6 2 2 6 2 2 6
46212- 2 2 6 6 6 6 30 30 30 26 26 26
46213-203 166 17 154 142 90 66 66 66 26 26 26
46214- 6 6 6 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 0 0 0
46218- 0 0 0 0 0 0 0 0 0 0 0 0
46219- 6 6 6 18 18 18 38 38 38 58 58 58
46220- 78 78 78 86 86 86 101 101 101 123 123 123
46221-175 146 61 210 150 10 234 174 13 246 186 14
46222-246 190 14 246 190 14 246 190 14 238 190 10
46223-102 78 10 2 2 6 46 46 46 198 198 198
46224-253 253 253 253 253 253 253 253 253 253 253 253
46225-253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253 253 253 253
46229-253 253 253 253 253 253 253 253 253 224 178 62
46230-242 186 14 241 196 14 210 166 10 22 18 6
46231- 2 2 6 2 2 6 2 2 6 2 2 6
46232- 2 2 6 2 2 6 6 6 6 121 92 8
46233-238 202 15 232 195 16 82 82 82 34 34 34
46234- 10 10 10 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 0 0 0
46238- 0 0 0 0 0 0 0 0 0 0 0 0
46239- 14 14 14 38 38 38 70 70 70 154 122 46
46240-190 142 34 200 144 11 197 138 11 197 138 11
46241-213 154 11 226 170 11 242 186 14 246 190 14
46242-246 190 14 246 190 14 246 190 14 246 190 14
46243-225 175 15 46 32 6 2 2 6 22 22 22
46244-158 158 158 250 250 250 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-253 253 253 253 253 253 253 253 253 253 253 253
46249-253 253 253 250 250 250 242 242 242 224 178 62
46250-239 182 13 236 186 11 213 154 11 46 32 6
46251- 2 2 6 2 2 6 2 2 6 2 2 6
46252- 2 2 6 2 2 6 61 42 6 225 175 15
46253-238 190 10 236 186 11 112 100 78 42 42 42
46254- 14 14 14 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 0 0 0
46258- 0 0 0 0 0 0 0 0 0 6 6 6
46259- 22 22 22 54 54 54 154 122 46 213 154 11
46260-226 170 11 230 174 11 226 170 11 226 170 11
46261-236 178 12 242 186 14 246 190 14 246 190 14
46262-246 190 14 246 190 14 246 190 14 246 190 14
46263-241 196 14 184 144 12 10 10 10 2 2 6
46264- 6 6 6 116 116 116 242 242 242 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-253 253 253 253 253 253 253 253 253 253 253 253
46269-253 253 253 231 231 231 198 198 198 214 170 54
46270-236 178 12 236 178 12 210 150 10 137 92 6
46271- 18 14 6 2 2 6 2 2 6 2 2 6
46272- 6 6 6 70 47 6 200 144 11 236 178 12
46273-239 182 13 239 182 13 124 112 88 58 58 58
46274- 22 22 22 6 6 6 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 0 0 0
46278- 0 0 0 0 0 0 0 0 0 10 10 10
46279- 30 30 30 70 70 70 180 133 36 226 170 11
46280-239 182 13 242 186 14 242 186 14 246 186 14
46281-246 190 14 246 190 14 246 190 14 246 190 14
46282-246 190 14 246 190 14 246 190 14 246 190 14
46283-246 190 14 232 195 16 98 70 6 2 2 6
46284- 2 2 6 2 2 6 66 66 66 221 221 221
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 253 253 253 253 253 253 253 253 253
46289-253 253 253 206 206 206 198 198 198 214 166 58
46290-230 174 11 230 174 11 216 158 10 192 133 9
46291-163 110 8 116 81 8 102 78 10 116 81 8
46292-167 114 7 197 138 11 226 170 11 239 182 13
46293-242 186 14 242 186 14 162 146 94 78 78 78
46294- 34 34 34 14 14 14 6 6 6 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 0 0 0
46298- 0 0 0 0 0 0 0 0 0 6 6 6
46299- 30 30 30 78 78 78 190 142 34 226 170 11
46300-239 182 13 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 246 190 14
46303-246 190 14 241 196 14 203 166 17 22 18 6
46304- 2 2 6 2 2 6 2 2 6 38 38 38
46305-218 218 218 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 253 253 253 253 253 253 253 253 253
46309-250 250 250 206 206 206 198 198 198 202 162 69
46310-226 170 11 236 178 12 224 166 10 210 150 10
46311-200 144 11 197 138 11 192 133 9 197 138 11
46312-210 150 10 226 170 11 242 186 14 246 190 14
46313-246 190 14 246 186 14 225 175 15 124 112 88
46314- 62 62 62 30 30 30 14 14 14 6 6 6
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 0 0 0
46318- 0 0 0 0 0 0 0 0 0 10 10 10
46319- 30 30 30 78 78 78 174 135 50 224 166 10
46320-239 182 13 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-246 190 14 246 190 14 241 196 14 139 102 15
46324- 2 2 6 2 2 6 2 2 6 2 2 6
46325- 78 78 78 250 250 250 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-253 253 253 253 253 253 253 253 253 253 253 253
46329-250 250 250 214 214 214 198 198 198 190 150 46
46330-219 162 10 236 178 12 234 174 13 224 166 10
46331-216 158 10 213 154 11 213 154 11 216 158 10
46332-226 170 11 239 182 13 246 190 14 246 190 14
46333-246 190 14 246 190 14 242 186 14 206 162 42
46334-101 101 101 58 58 58 30 30 30 14 14 14
46335- 6 6 6 0 0 0 0 0 0 0 0 0
46336- 0 0 0 0 0 0 0 0 0 0 0 0
46337- 0 0 0 0 0 0 0 0 0 0 0 0
46338- 0 0 0 0 0 0 0 0 0 10 10 10
46339- 30 30 30 74 74 74 174 135 50 216 158 10
46340-236 178 12 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-246 190 14 246 190 14 241 196 14 226 184 13
46344- 61 42 6 2 2 6 2 2 6 2 2 6
46345- 22 22 22 238 238 238 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 253 253 253
46348-253 253 253 253 253 253 253 253 253 253 253 253
46349-253 253 253 226 226 226 187 187 187 180 133 36
46350-216 158 10 236 178 12 239 182 13 236 178 12
46351-230 174 11 226 170 11 226 170 11 230 174 11
46352-236 178 12 242 186 14 246 190 14 246 190 14
46353-246 190 14 246 190 14 246 186 14 239 182 13
46354-206 162 42 106 106 106 66 66 66 34 34 34
46355- 14 14 14 6 6 6 0 0 0 0 0 0
46356- 0 0 0 0 0 0 0 0 0 0 0 0
46357- 0 0 0 0 0 0 0 0 0 0 0 0
46358- 0 0 0 0 0 0 0 0 0 6 6 6
46359- 26 26 26 70 70 70 163 133 67 213 154 11
46360-236 178 12 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 246 190 14 246 190 14 241 196 14
46364-190 146 13 18 14 6 2 2 6 2 2 6
46365- 46 46 46 246 246 246 253 253 253 253 253 253
46366-253 253 253 253 253 253 253 253 253 253 253 253
46367-253 253 253 253 253 253 253 253 253 253 253 253
46368-253 253 253 253 253 253 253 253 253 253 253 253
46369-253 253 253 221 221 221 86 86 86 156 107 11
46370-216 158 10 236 178 12 242 186 14 246 186 14
46371-242 186 14 239 182 13 239 182 13 242 186 14
46372-242 186 14 246 186 14 246 190 14 246 190 14
46373-246 190 14 246 190 14 246 190 14 246 190 14
46374-242 186 14 225 175 15 142 122 72 66 66 66
46375- 30 30 30 10 10 10 0 0 0 0 0 0
46376- 0 0 0 0 0 0 0 0 0 0 0 0
46377- 0 0 0 0 0 0 0 0 0 0 0 0
46378- 0 0 0 0 0 0 0 0 0 6 6 6
46379- 26 26 26 70 70 70 163 133 67 210 150 10
46380-236 178 12 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-246 190 14 246 190 14 246 190 14 246 190 14
46384-232 195 16 121 92 8 34 34 34 106 106 106
46385-221 221 221 253 253 253 253 253 253 253 253 253
46386-253 253 253 253 253 253 253 253 253 253 253 253
46387-253 253 253 253 253 253 253 253 253 253 253 253
46388-253 253 253 253 253 253 253 253 253 253 253 253
46389-242 242 242 82 82 82 18 14 6 163 110 8
46390-216 158 10 236 178 12 242 186 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 246 190 14
46393-246 190 14 246 190 14 246 190 14 246 190 14
46394-246 190 14 246 190 14 242 186 14 163 133 67
46395- 46 46 46 18 18 18 6 6 6 0 0 0
46396- 0 0 0 0 0 0 0 0 0 0 0 0
46397- 0 0 0 0 0 0 0 0 0 0 0 0
46398- 0 0 0 0 0 0 0 0 0 10 10 10
46399- 30 30 30 78 78 78 163 133 67 210 150 10
46400-236 178 12 246 186 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 190 14 246 190 14 246 190 14 246 190 14
46404-241 196 14 215 174 15 190 178 144 253 253 253
46405-253 253 253 253 253 253 253 253 253 253 253 253
46406-253 253 253 253 253 253 253 253 253 253 253 253
46407-253 253 253 253 253 253 253 253 253 253 253 253
46408-253 253 253 253 253 253 253 253 253 218 218 218
46409- 58 58 58 2 2 6 22 18 6 167 114 7
46410-216 158 10 236 178 12 246 186 14 246 190 14
46411-246 190 14 246 190 14 246 190 14 246 190 14
46412-246 190 14 246 190 14 246 190 14 246 190 14
46413-246 190 14 246 190 14 246 190 14 246 190 14
46414-246 190 14 246 186 14 242 186 14 190 150 46
46415- 54 54 54 22 22 22 6 6 6 0 0 0
46416- 0 0 0 0 0 0 0 0 0 0 0 0
46417- 0 0 0 0 0 0 0 0 0 0 0 0
46418- 0 0 0 0 0 0 0 0 0 14 14 14
46419- 38 38 38 86 86 86 180 133 36 213 154 11
46420-236 178 12 246 186 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 246 190 14 246 190 14 246 190 14
46424-246 190 14 232 195 16 190 146 13 214 214 214
46425-253 253 253 253 253 253 253 253 253 253 253 253
46426-253 253 253 253 253 253 253 253 253 253 253 253
46427-253 253 253 253 253 253 253 253 253 253 253 253
46428-253 253 253 250 250 250 170 170 170 26 26 26
46429- 2 2 6 2 2 6 37 26 9 163 110 8
46430-219 162 10 239 182 13 246 186 14 246 190 14
46431-246 190 14 246 190 14 246 190 14 246 190 14
46432-246 190 14 246 190 14 246 190 14 246 190 14
46433-246 190 14 246 190 14 246 190 14 246 190 14
46434-246 186 14 236 178 12 224 166 10 142 122 72
46435- 46 46 46 18 18 18 6 6 6 0 0 0
46436- 0 0 0 0 0 0 0 0 0 0 0 0
46437- 0 0 0 0 0 0 0 0 0 0 0 0
46438- 0 0 0 0 0 0 6 6 6 18 18 18
46439- 50 50 50 109 106 95 192 133 9 224 166 10
46440-242 186 14 246 190 14 246 190 14 246 190 14
46441-246 190 14 246 190 14 246 190 14 246 190 14
46442-246 190 14 246 190 14 246 190 14 246 190 14
46443-246 190 14 246 190 14 246 190 14 246 190 14
46444-242 186 14 226 184 13 210 162 10 142 110 46
46445-226 226 226 253 253 253 253 253 253 253 253 253
46446-253 253 253 253 253 253 253 253 253 253 253 253
46447-253 253 253 253 253 253 253 253 253 253 253 253
46448-198 198 198 66 66 66 2 2 6 2 2 6
46449- 2 2 6 2 2 6 50 34 6 156 107 11
46450-219 162 10 239 182 13 246 186 14 246 190 14
46451-246 190 14 246 190 14 246 190 14 246 190 14
46452-246 190 14 246 190 14 246 190 14 246 190 14
46453-246 190 14 246 190 14 246 190 14 242 186 14
46454-234 174 13 213 154 11 154 122 46 66 66 66
46455- 30 30 30 10 10 10 0 0 0 0 0 0
46456- 0 0 0 0 0 0 0 0 0 0 0 0
46457- 0 0 0 0 0 0 0 0 0 0 0 0
46458- 0 0 0 0 0 0 6 6 6 22 22 22
46459- 58 58 58 154 121 60 206 145 10 234 174 13
46460-242 186 14 246 186 14 246 190 14 246 190 14
46461-246 190 14 246 190 14 246 190 14 246 190 14
46462-246 190 14 246 190 14 246 190 14 246 190 14
46463-246 190 14 246 190 14 246 190 14 246 190 14
46464-246 186 14 236 178 12 210 162 10 163 110 8
46465- 61 42 6 138 138 138 218 218 218 250 250 250
46466-253 253 253 253 253 253 253 253 253 250 250 250
46467-242 242 242 210 210 210 144 144 144 66 66 66
46468- 6 6 6 2 2 6 2 2 6 2 2 6
46469- 2 2 6 2 2 6 61 42 6 163 110 8
46470-216 158 10 236 178 12 246 190 14 246 190 14
46471-246 190 14 246 190 14 246 190 14 246 190 14
46472-246 190 14 246 190 14 246 190 14 246 190 14
46473-246 190 14 239 182 13 230 174 11 216 158 10
46474-190 142 34 124 112 88 70 70 70 38 38 38
46475- 18 18 18 6 6 6 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 0 0 0
46478- 0 0 0 0 0 0 6 6 6 22 22 22
46479- 62 62 62 168 124 44 206 145 10 224 166 10
46480-236 178 12 239 182 13 242 186 14 242 186 14
46481-246 186 14 246 190 14 246 190 14 246 190 14
46482-246 190 14 246 190 14 246 190 14 246 190 14
46483-246 190 14 246 190 14 246 190 14 246 190 14
46484-246 190 14 236 178 12 216 158 10 175 118 6
46485- 80 54 7 2 2 6 6 6 6 30 30 30
46486- 54 54 54 62 62 62 50 50 50 38 38 38
46487- 14 14 14 2 2 6 2 2 6 2 2 6
46488- 2 2 6 2 2 6 2 2 6 2 2 6
46489- 2 2 6 6 6 6 80 54 7 167 114 7
46490-213 154 11 236 178 12 246 190 14 246 190 14
46491-246 190 14 246 190 14 246 190 14 246 190 14
46492-246 190 14 242 186 14 239 182 13 239 182 13
46493-230 174 11 210 150 10 174 135 50 124 112 88
46494- 82 82 82 54 54 54 34 34 34 18 18 18
46495- 6 6 6 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- 0 0 0 0 0 0 6 6 6 18 18 18
46499- 50 50 50 158 118 36 192 133 9 200 144 11
46500-216 158 10 219 162 10 224 166 10 226 170 11
46501-230 174 11 236 178 12 239 182 13 239 182 13
46502-242 186 14 246 186 14 246 190 14 246 190 14
46503-246 190 14 246 190 14 246 190 14 246 190 14
46504-246 186 14 230 174 11 210 150 10 163 110 8
46505-104 69 6 10 10 10 2 2 6 2 2 6
46506- 2 2 6 2 2 6 2 2 6 2 2 6
46507- 2 2 6 2 2 6 2 2 6 2 2 6
46508- 2 2 6 2 2 6 2 2 6 2 2 6
46509- 2 2 6 6 6 6 91 60 6 167 114 7
46510-206 145 10 230 174 11 242 186 14 246 190 14
46511-246 190 14 246 190 14 246 186 14 242 186 14
46512-239 182 13 230 174 11 224 166 10 213 154 11
46513-180 133 36 124 112 88 86 86 86 58 58 58
46514- 38 38 38 22 22 22 10 10 10 6 6 6
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 0 0 0 14 14 14
46519- 34 34 34 70 70 70 138 110 50 158 118 36
46520-167 114 7 180 123 7 192 133 9 197 138 11
46521-200 144 11 206 145 10 213 154 11 219 162 10
46522-224 166 10 230 174 11 239 182 13 242 186 14
46523-246 186 14 246 186 14 246 186 14 246 186 14
46524-239 182 13 216 158 10 185 133 11 152 99 6
46525-104 69 6 18 14 6 2 2 6 2 2 6
46526- 2 2 6 2 2 6 2 2 6 2 2 6
46527- 2 2 6 2 2 6 2 2 6 2 2 6
46528- 2 2 6 2 2 6 2 2 6 2 2 6
46529- 2 2 6 6 6 6 80 54 7 152 99 6
46530-192 133 9 219 162 10 236 178 12 239 182 13
46531-246 186 14 242 186 14 239 182 13 236 178 12
46532-224 166 10 206 145 10 192 133 9 154 121 60
46533- 94 94 94 62 62 62 42 42 42 22 22 22
46534- 14 14 14 6 6 6 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 6 6 6
46539- 18 18 18 34 34 34 58 58 58 78 78 78
46540-101 98 89 124 112 88 142 110 46 156 107 11
46541-163 110 8 167 114 7 175 118 6 180 123 7
46542-185 133 11 197 138 11 210 150 10 219 162 10
46543-226 170 11 236 178 12 236 178 12 234 174 13
46544-219 162 10 197 138 11 163 110 8 130 83 6
46545- 91 60 6 10 10 10 2 2 6 2 2 6
46546- 18 18 18 38 38 38 38 38 38 38 38 38
46547- 38 38 38 38 38 38 38 38 38 38 38 38
46548- 38 38 38 38 38 38 26 26 26 2 2 6
46549- 2 2 6 6 6 6 70 47 6 137 92 6
46550-175 118 6 200 144 11 219 162 10 230 174 11
46551-234 174 13 230 174 11 219 162 10 210 150 10
46552-192 133 9 163 110 8 124 112 88 82 82 82
46553- 50 50 50 30 30 30 14 14 14 6 6 6
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- 6 6 6 14 14 14 22 22 22 34 34 34
46560- 42 42 42 58 58 58 74 74 74 86 86 86
46561-101 98 89 122 102 70 130 98 46 121 87 25
46562-137 92 6 152 99 6 163 110 8 180 123 7
46563-185 133 11 197 138 11 206 145 10 200 144 11
46564-180 123 7 156 107 11 130 83 6 104 69 6
46565- 50 34 6 54 54 54 110 110 110 101 98 89
46566- 86 86 86 82 82 82 78 78 78 78 78 78
46567- 78 78 78 78 78 78 78 78 78 78 78 78
46568- 78 78 78 82 82 82 86 86 86 94 94 94
46569-106 106 106 101 101 101 86 66 34 124 80 6
46570-156 107 11 180 123 7 192 133 9 200 144 11
46571-206 145 10 200 144 11 192 133 9 175 118 6
46572-139 102 15 109 106 95 70 70 70 42 42 42
46573- 22 22 22 10 10 10 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 6 6 6 10 10 10
46580- 14 14 14 22 22 22 30 30 30 38 38 38
46581- 50 50 50 62 62 62 74 74 74 90 90 90
46582-101 98 89 112 100 78 121 87 25 124 80 6
46583-137 92 6 152 99 6 152 99 6 152 99 6
46584-138 86 6 124 80 6 98 70 6 86 66 30
46585-101 98 89 82 82 82 58 58 58 46 46 46
46586- 38 38 38 34 34 34 34 34 34 34 34 34
46587- 34 34 34 34 34 34 34 34 34 34 34 34
46588- 34 34 34 34 34 34 38 38 38 42 42 42
46589- 54 54 54 82 82 82 94 86 76 91 60 6
46590-134 86 6 156 107 11 167 114 7 175 118 6
46591-175 118 6 167 114 7 152 99 6 121 87 25
46592-101 98 89 62 62 62 34 34 34 18 18 18
46593- 6 6 6 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 6 6 6 6 6 6 10 10 10
46601- 18 18 18 22 22 22 30 30 30 42 42 42
46602- 50 50 50 66 66 66 86 86 86 101 98 89
46603-106 86 58 98 70 6 104 69 6 104 69 6
46604-104 69 6 91 60 6 82 62 34 90 90 90
46605- 62 62 62 38 38 38 22 22 22 14 14 14
46606- 10 10 10 10 10 10 10 10 10 10 10 10
46607- 10 10 10 10 10 10 6 6 6 10 10 10
46608- 10 10 10 10 10 10 10 10 10 14 14 14
46609- 22 22 22 42 42 42 70 70 70 89 81 66
46610- 80 54 7 104 69 6 124 80 6 137 92 6
46611-134 86 6 116 81 8 100 82 52 86 86 86
46612- 58 58 58 30 30 30 14 14 14 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
46617- 0 0 0 0 0 0 0 0 0 0 0 0
46618- 0 0 0 0 0 0 0 0 0 0 0 0
46619- 0 0 0 0 0 0 0 0 0 0 0 0
46620- 0 0 0 0 0 0 0 0 0 0 0 0
46621- 0 0 0 6 6 6 10 10 10 14 14 14
46622- 18 18 18 26 26 26 38 38 38 54 54 54
46623- 70 70 70 86 86 86 94 86 76 89 81 66
46624- 89 81 66 86 86 86 74 74 74 50 50 50
46625- 30 30 30 14 14 14 6 6 6 0 0 0
46626- 0 0 0 0 0 0 0 0 0 0 0 0
46627- 0 0 0 0 0 0 0 0 0 0 0 0
46628- 0 0 0 0 0 0 0 0 0 0 0 0
46629- 6 6 6 18 18 18 34 34 34 58 58 58
46630- 82 82 82 89 81 66 89 81 66 89 81 66
46631- 94 86 66 94 86 76 74 74 74 50 50 50
46632- 26 26 26 14 14 14 6 6 6 0 0 0
46633- 0 0 0 0 0 0 0 0 0 0 0 0
46634- 0 0 0 0 0 0 0 0 0 0 0 0
46635- 0 0 0 0 0 0 0 0 0 0 0 0
46636- 0 0 0 0 0 0 0 0 0 0 0 0
46637- 0 0 0 0 0 0 0 0 0 0 0 0
46638- 0 0 0 0 0 0 0 0 0 0 0 0
46639- 0 0 0 0 0 0 0 0 0 0 0 0
46640- 0 0 0 0 0 0 0 0 0 0 0 0
46641- 0 0 0 0 0 0 0 0 0 0 0 0
46642- 6 6 6 6 6 6 14 14 14 18 18 18
46643- 30 30 30 38 38 38 46 46 46 54 54 54
46644- 50 50 50 42 42 42 30 30 30 18 18 18
46645- 10 10 10 0 0 0 0 0 0 0 0 0
46646- 0 0 0 0 0 0 0 0 0 0 0 0
46647- 0 0 0 0 0 0 0 0 0 0 0 0
46648- 0 0 0 0 0 0 0 0 0 0 0 0
46649- 0 0 0 6 6 6 14 14 14 26 26 26
46650- 38 38 38 50 50 50 58 58 58 58 58 58
46651- 54 54 54 42 42 42 30 30 30 18 18 18
46652- 10 10 10 0 0 0 0 0 0 0 0 0
46653- 0 0 0 0 0 0 0 0 0 0 0 0
46654- 0 0 0 0 0 0 0 0 0 0 0 0
46655- 0 0 0 0 0 0 0 0 0 0 0 0
46656- 0 0 0 0 0 0 0 0 0 0 0 0
46657- 0 0 0 0 0 0 0 0 0 0 0 0
46658- 0 0 0 0 0 0 0 0 0 0 0 0
46659- 0 0 0 0 0 0 0 0 0 0 0 0
46660- 0 0 0 0 0 0 0 0 0 0 0 0
46661- 0 0 0 0 0 0 0 0 0 0 0 0
46662- 0 0 0 0 0 0 0 0 0 6 6 6
46663- 6 6 6 10 10 10 14 14 14 18 18 18
46664- 18 18 18 14 14 14 10 10 10 6 6 6
46665- 0 0 0 0 0 0 0 0 0 0 0 0
46666- 0 0 0 0 0 0 0 0 0 0 0 0
46667- 0 0 0 0 0 0 0 0 0 0 0 0
46668- 0 0 0 0 0 0 0 0 0 0 0 0
46669- 0 0 0 0 0 0 0 0 0 6 6 6
46670- 14 14 14 18 18 18 22 22 22 22 22 22
46671- 18 18 18 14 14 14 10 10 10 6 6 6
46672- 0 0 0 0 0 0 0 0 0 0 0 0
46673- 0 0 0 0 0 0 0 0 0 0 0 0
46674- 0 0 0 0 0 0 0 0 0 0 0 0
46675- 0 0 0 0 0 0 0 0 0 0 0 0
46676- 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
46705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46706+4 4 4 4 4 4 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 4 4 4 4 4 4
46710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 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
46719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46720+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46727+4 4 4 4 4 4 4 4 4 4 4 4 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+4 4 4 4 4 4
46733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46734+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46741+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46746+4 4 4 4 4 4
46747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
46751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46755+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46760+4 4 4 4 4 4
46761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46765+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46766+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46770+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46771+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46772+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46774+4 4 4 4 4 4
46775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46779+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46780+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46781+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46784+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46785+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46786+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46787+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46788+4 4 4 4 4 4
46789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46793+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46794+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46795+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46798+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46799+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46800+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46801+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46802+4 4 4 4 4 4
46803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46806+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46807+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46808+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46809+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46811+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46812+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46813+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46814+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46815+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46816+4 4 4 4 4 4
46817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46820+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46821+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46822+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46823+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46824+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46825+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46826+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46827+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46828+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46829+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46830+4 4 4 4 4 4
46831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46834+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46835+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46836+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46837+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46838+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46839+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46840+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46841+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46842+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46843+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46844+4 4 4 4 4 4
46845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46847+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46848+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46849+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46850+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46851+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46852+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46853+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46854+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46855+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46856+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46857+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46858+4 4 4 4 4 4
46859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46861+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46862+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46863+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46864+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46865+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46866+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46867+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46868+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46869+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46870+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46871+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46872+4 4 4 4 4 4
46873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46875+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46876+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46877+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46878+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46879+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46880+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46881+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46882+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46883+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46884+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46885+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46886+4 4 4 4 4 4
46887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46889+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46890+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46891+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46892+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46893+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46894+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46895+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46896+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
46897+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
46898+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
46899+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
46900+4 4 4 4 4 4
46901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46902+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
46903+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
46904+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
46905+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
46906+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
46907+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
46908+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
46909+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
46910+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
46911+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
46912+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
46913+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
46914+4 4 4 4 4 4
46915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46916+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
46917+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
46918+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
46919+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46920+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
46921+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
46922+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
46923+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
46924+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
46925+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
46926+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
46927+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
46928+0 0 0 4 4 4
46929+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46930+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
46931+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
46932+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
46933+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
46934+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
46935+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
46936+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
46937+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
46938+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
46939+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
46940+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
46941+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
46942+2 0 0 0 0 0
46943+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
46944+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
46945+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
46946+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
46947+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
46948+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
46949+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
46950+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
46951+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
46952+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
46953+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
46954+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
46955+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
46956+37 38 37 0 0 0
46957+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46958+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
46959+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
46960+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
46961+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
46962+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
46963+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
46964+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
46965+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
46966+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
46967+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
46968+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
46969+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
46970+85 115 134 4 0 0
46971+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
46972+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
46973+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
46974+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
46975+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
46976+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
46977+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
46978+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
46979+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
46980+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
46981+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
46982+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
46983+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
46984+60 73 81 4 0 0
46985+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
46986+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
46987+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
46988+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
46989+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
46990+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
46991+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
46992+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
46993+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
46994+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
46995+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
46996+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
46997+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
46998+16 19 21 4 0 0
46999+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
47000+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
47001+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
47002+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
47003+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
47004+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
47005+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
47006+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
47007+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
47008+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
47009+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
47010+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
47011+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
47012+4 0 0 4 3 3
47013+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
47014+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
47015+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
47016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
47017+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
47018+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
47019+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
47020+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
47021+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
47022+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
47023+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
47024+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
47025+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
47026+3 2 2 4 4 4
47027+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
47028+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
47029+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
47030+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47031+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
47032+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
47033+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
47034+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
47035+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
47036+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
47037+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
47038+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
47039+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
47040+4 4 4 4 4 4
47041+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
47042+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
47043+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
47044+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
47045+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
47046+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
47047+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
47048+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
47049+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
47050+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
47051+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
47052+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
47053+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
47054+4 4 4 4 4 4
47055+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
47056+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
47057+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
47058+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
47059+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
47060+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47061+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
47062+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
47063+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
47064+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
47065+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
47066+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
47067+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
47068+5 5 5 5 5 5
47069+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
47070+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
47071+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
47072+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
47073+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
47074+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47075+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
47076+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
47077+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
47078+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
47079+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
47080+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
47081+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47082+5 5 5 4 4 4
47083+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
47084+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
47085+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
47086+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
47087+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47088+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
47089+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
47090+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
47091+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
47092+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
47093+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
47094+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47096+4 4 4 4 4 4
47097+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
47098+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
47099+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
47100+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
47101+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
47102+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47103+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47104+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
47105+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
47106+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
47107+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
47108+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
47109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47110+4 4 4 4 4 4
47111+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
47112+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
47113+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
47114+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
47115+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47116+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
47117+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
47118+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
47119+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
47120+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
47121+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
47122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47124+4 4 4 4 4 4
47125+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
47126+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
47127+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
47128+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
47129+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47130+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47131+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47132+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
47133+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
47134+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
47135+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
47136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47138+4 4 4 4 4 4
47139+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
47140+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
47141+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
47142+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
47143+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47144+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
47145+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47146+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
47147+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
47148+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
47149+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47152+4 4 4 4 4 4
47153+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
47154+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
47155+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
47156+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
47157+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47158+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
47159+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
47160+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
47161+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
47162+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
47163+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
47164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47166+4 4 4 4 4 4
47167+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
47168+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
47169+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
47170+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
47171+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47172+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
47173+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
47174+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
47175+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
47176+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
47177+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
47178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47180+4 4 4 4 4 4
47181+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
47182+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
47183+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
47184+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47185+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
47186+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
47187+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
47188+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
47189+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
47190+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
47191+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47194+4 4 4 4 4 4
47195+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
47196+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
47197+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
47198+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47199+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47200+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
47201+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
47202+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
47203+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
47204+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
47205+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47208+4 4 4 4 4 4
47209+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
47210+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
47211+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47212+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47213+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47214+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
47215+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
47216+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
47217+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
47218+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
47219+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47222+4 4 4 4 4 4
47223+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
47224+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
47225+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47226+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47227+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47228+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
47229+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
47230+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
47231+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47232+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47233+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47236+4 4 4 4 4 4
47237+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47238+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
47239+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47240+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
47241+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
47242+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
47243+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
47244+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
47245+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47246+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47247+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47250+4 4 4 4 4 4
47251+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47252+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
47253+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47254+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
47255+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47256+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
47257+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
47258+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
47259+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47260+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47261+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47264+4 4 4 4 4 4
47265+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
47266+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
47267+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47268+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
47269+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
47270+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
47271+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
47272+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
47273+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47274+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47275+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47278+4 4 4 4 4 4
47279+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
47280+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
47281+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47282+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
47283+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
47284+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
47285+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
47286+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
47287+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47288+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47289+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47292+4 4 4 4 4 4
47293+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47294+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
47295+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47296+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
47297+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
47298+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
47299+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
47300+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
47301+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47302+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47303+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47306+4 4 4 4 4 4
47307+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
47308+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
47309+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47310+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
47311+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
47312+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
47313+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
47314+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
47315+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
47316+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47317+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47320+4 4 4 4 4 4
47321+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47322+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
47323+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
47324+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
47325+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
47326+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
47327+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
47328+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
47329+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47330+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47331+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47334+4 4 4 4 4 4
47335+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47336+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
47337+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47338+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
47339+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
47340+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
47341+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
47342+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
47343+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47344+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47345+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47348+4 4 4 4 4 4
47349+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47350+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
47351+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
47352+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
47353+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
47354+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
47355+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47356+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
47357+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47358+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47359+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47362+4 4 4 4 4 4
47363+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47364+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
47365+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
47366+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47367+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
47368+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
47369+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47370+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
47371+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47372+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47373+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47376+4 4 4 4 4 4
47377+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47378+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
47379+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
47380+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
47381+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
47382+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
47383+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
47384+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
47385+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
47386+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47387+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47390+4 4 4 4 4 4
47391+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47392+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
47393+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
47394+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
47395+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
47396+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
47397+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
47398+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
47399+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
47400+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47401+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47404+4 4 4 4 4 4
47405+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
47406+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
47407+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
47408+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
47409+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47410+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
47411+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
47412+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
47413+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
47414+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47415+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47418+4 4 4 4 4 4
47419+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47420+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
47421+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
47422+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
47423+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
47424+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
47425+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
47426+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
47427+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
47428+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47429+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47432+4 4 4 4 4 4
47433+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
47434+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
47435+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
47436+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
47437+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
47438+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
47439+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
47440+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
47441+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
47442+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
47443+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47446+4 4 4 4 4 4
47447+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
47448+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47449+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
47450+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
47451+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
47452+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
47453+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
47454+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
47455+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
47456+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
47457+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47460+4 4 4 4 4 4
47461+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
47462+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47463+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
47464+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
47465+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
47466+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
47467+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47468+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
47469+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
47470+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
47471+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47474+4 4 4 4 4 4
47475+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
47476+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
47477+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
47478+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
47479+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
47480+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
47481+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
47482+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
47483+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
47484+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
47485+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47488+4 4 4 4 4 4
47489+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
47490+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
47491+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47492+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
47493+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
47494+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
47495+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
47496+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
47497+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
47498+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
47499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47502+4 4 4 4 4 4
47503+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47504+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
47505+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
47506+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
47507+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
47508+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
47509+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
47510+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
47511+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
47512+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47516+4 4 4 4 4 4
47517+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
47518+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
47519+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
47520+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
47521+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
47522+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
47523+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
47524+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
47525+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
47526+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47530+4 4 4 4 4 4
47531+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
47532+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
47533+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
47534+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
47535+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
47536+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
47537+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
47538+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
47539+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47540+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47544+4 4 4 4 4 4
47545+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
47546+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47547+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
47548+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47549+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
47550+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
47551+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
47552+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
47553+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
47554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47558+4 4 4 4 4 4
47559+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
47560+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
47561+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
47562+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
47563+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
47564+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
47565+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
47566+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
47567+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
47568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47572+4 4 4 4 4 4
47573+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47574+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
47575+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
47576+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
47577+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
47578+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
47579+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
47580+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
47581+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47586+4 4 4 4 4 4
47587+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
47588+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
47589+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47590+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
47591+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
47592+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
47593+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
47594+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
47595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47600+4 4 4 4 4 4
47601+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47602+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
47603+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
47604+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
47605+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
47606+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
47607+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
47608+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47614+4 4 4 4 4 4
47615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47616+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47617+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47618+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47619+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47620+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47621+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47622+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
47623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47628+4 4 4 4 4 4
47629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47630+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47631+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47632+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47633+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47634+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47635+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47636+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
47637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47642+4 4 4 4 4 4
47643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47644+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47645+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47646+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47647+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47648+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47649+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47650+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47656+4 4 4 4 4 4
47657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47659+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47660+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47661+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47662+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47663+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47664+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47668+4 4 4 4 4 4 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 4 4 4
47670+4 4 4 4 4 4
47671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47672+4 4 4 4 4 4 4 4 4 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 5 5 5
47674+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47675+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47676+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47677+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47682+4 4 4 4 4 4 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 4 4 4
47685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47686+4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47689+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47690+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47691+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47696+4 4 4 4 4 4 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 4 4 4
47699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47700+4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
47703+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47704+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47705+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47710+4 4 4 4 4 4 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
47713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5
47717+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47718+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47719+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47724+4 4 4 4 4 4 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
47727+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5
47731+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47732+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47733+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47740+4 4 4 4 4 4
47741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47745+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47746+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47747+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47754+4 4 4 4 4 4
47755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47759+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47760+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47761+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47768+4 4 4 4 4 4
47769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47773+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47774+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47782+4 4 4 4 4 4
47783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47787+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47788+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47796+4 4 4 4 4 4
47797diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47798index fe92eed..106e085 100644
47799--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47800+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47801@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47802 struct mb862xxfb_par *par = info->par;
47803
47804 if (info->var.bits_per_pixel == 32) {
47805- info->fbops->fb_fillrect = cfb_fillrect;
47806- info->fbops->fb_copyarea = cfb_copyarea;
47807- info->fbops->fb_imageblit = cfb_imageblit;
47808+ pax_open_kernel();
47809+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47810+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47811+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47812+ pax_close_kernel();
47813 } else {
47814 outreg(disp, GC_L0EM, 3);
47815- info->fbops->fb_fillrect = mb86290fb_fillrect;
47816- info->fbops->fb_copyarea = mb86290fb_copyarea;
47817- info->fbops->fb_imageblit = mb86290fb_imageblit;
47818+ pax_open_kernel();
47819+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47820+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47821+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47822+ pax_close_kernel();
47823 }
47824 outreg(draw, GDC_REG_DRAW_BASE, 0);
47825 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47826diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47827index ff22871..b129bed 100644
47828--- a/drivers/video/nvidia/nvidia.c
47829+++ b/drivers/video/nvidia/nvidia.c
47830@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47831 info->fix.line_length = (info->var.xres_virtual *
47832 info->var.bits_per_pixel) >> 3;
47833 if (info->var.accel_flags) {
47834- info->fbops->fb_imageblit = nvidiafb_imageblit;
47835- info->fbops->fb_fillrect = nvidiafb_fillrect;
47836- info->fbops->fb_copyarea = nvidiafb_copyarea;
47837- info->fbops->fb_sync = nvidiafb_sync;
47838+ pax_open_kernel();
47839+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47840+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47841+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47842+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47843+ pax_close_kernel();
47844 info->pixmap.scan_align = 4;
47845 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47846 info->flags |= FBINFO_READS_FAST;
47847 NVResetGraphics(info);
47848 } else {
47849- info->fbops->fb_imageblit = cfb_imageblit;
47850- info->fbops->fb_fillrect = cfb_fillrect;
47851- info->fbops->fb_copyarea = cfb_copyarea;
47852- info->fbops->fb_sync = NULL;
47853+ pax_open_kernel();
47854+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47855+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47856+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47857+ *(void **)&info->fbops->fb_sync = NULL;
47858+ pax_close_kernel();
47859 info->pixmap.scan_align = 1;
47860 info->flags |= FBINFO_HWACCEL_DISABLED;
47861 info->flags &= ~FBINFO_READS_FAST;
47862@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47863 info->pixmap.size = 8 * 1024;
47864 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47865
47866- if (!hwcur)
47867- info->fbops->fb_cursor = NULL;
47868+ if (!hwcur) {
47869+ pax_open_kernel();
47870+ *(void **)&info->fbops->fb_cursor = NULL;
47871+ pax_close_kernel();
47872+ }
47873
47874 info->var.accel_flags = (!noaccel);
47875
47876diff --git a/drivers/video/output.c b/drivers/video/output.c
47877index 0d6f2cd..6285b97 100644
47878--- a/drivers/video/output.c
47879+++ b/drivers/video/output.c
47880@@ -97,7 +97,7 @@ struct output_device *video_output_register(const char *name,
47881 new_dev->props = op;
47882 new_dev->dev.class = &video_output_class;
47883 new_dev->dev.parent = dev;
47884- dev_set_name(&new_dev->dev, name);
47885+ dev_set_name(&new_dev->dev, "%s", name);
47886 dev_set_drvdata(&new_dev->dev, devdata);
47887 ret_code = device_register(&new_dev->dev);
47888 if (ret_code) {
47889diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47890index 76d9053..dec2bfd 100644
47891--- a/drivers/video/s1d13xxxfb.c
47892+++ b/drivers/video/s1d13xxxfb.c
47893@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47894
47895 switch(prod_id) {
47896 case S1D13506_PROD_ID: /* activate acceleration */
47897- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47898- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47899+ pax_open_kernel();
47900+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47901+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47902+ pax_close_kernel();
47903 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
47904 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
47905 break;
47906diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
47907index 97bd662..39fab85 100644
47908--- a/drivers/video/smscufx.c
47909+++ b/drivers/video/smscufx.c
47910@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
47911 fb_deferred_io_cleanup(info);
47912 kfree(info->fbdefio);
47913 info->fbdefio = NULL;
47914- info->fbops->fb_mmap = ufx_ops_mmap;
47915+ pax_open_kernel();
47916+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
47917+ pax_close_kernel();
47918 }
47919
47920 pr_debug("released /dev/fb%d user=%d count=%d",
47921diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
47922index 86d449e..8e04dc5 100644
47923--- a/drivers/video/udlfb.c
47924+++ b/drivers/video/udlfb.c
47925@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
47926 dlfb_urb_completion(urb);
47927
47928 error:
47929- atomic_add(bytes_sent, &dev->bytes_sent);
47930- atomic_add(bytes_identical, &dev->bytes_identical);
47931- atomic_add(width*height*2, &dev->bytes_rendered);
47932+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47933+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47934+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
47935 end_cycles = get_cycles();
47936- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47937+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47938 >> 10)), /* Kcycles */
47939 &dev->cpu_kcycles_used);
47940
47941@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
47942 dlfb_urb_completion(urb);
47943
47944 error:
47945- atomic_add(bytes_sent, &dev->bytes_sent);
47946- atomic_add(bytes_identical, &dev->bytes_identical);
47947- atomic_add(bytes_rendered, &dev->bytes_rendered);
47948+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47949+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47950+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
47951 end_cycles = get_cycles();
47952- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47953+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47954 >> 10)), /* Kcycles */
47955 &dev->cpu_kcycles_used);
47956 }
47957@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
47958 fb_deferred_io_cleanup(info);
47959 kfree(info->fbdefio);
47960 info->fbdefio = NULL;
47961- info->fbops->fb_mmap = dlfb_ops_mmap;
47962+ pax_open_kernel();
47963+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
47964+ pax_close_kernel();
47965 }
47966
47967 pr_warn("released /dev/fb%d user=%d count=%d\n",
47968@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
47969 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47970 struct dlfb_data *dev = fb_info->par;
47971 return snprintf(buf, PAGE_SIZE, "%u\n",
47972- atomic_read(&dev->bytes_rendered));
47973+ atomic_read_unchecked(&dev->bytes_rendered));
47974 }
47975
47976 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47977@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47978 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47979 struct dlfb_data *dev = fb_info->par;
47980 return snprintf(buf, PAGE_SIZE, "%u\n",
47981- atomic_read(&dev->bytes_identical));
47982+ atomic_read_unchecked(&dev->bytes_identical));
47983 }
47984
47985 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47986@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47987 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47988 struct dlfb_data *dev = fb_info->par;
47989 return snprintf(buf, PAGE_SIZE, "%u\n",
47990- atomic_read(&dev->bytes_sent));
47991+ atomic_read_unchecked(&dev->bytes_sent));
47992 }
47993
47994 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47995@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47996 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47997 struct dlfb_data *dev = fb_info->par;
47998 return snprintf(buf, PAGE_SIZE, "%u\n",
47999- atomic_read(&dev->cpu_kcycles_used));
48000+ atomic_read_unchecked(&dev->cpu_kcycles_used));
48001 }
48002
48003 static ssize_t edid_show(
48004@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
48005 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48006 struct dlfb_data *dev = fb_info->par;
48007
48008- atomic_set(&dev->bytes_rendered, 0);
48009- atomic_set(&dev->bytes_identical, 0);
48010- atomic_set(&dev->bytes_sent, 0);
48011- atomic_set(&dev->cpu_kcycles_used, 0);
48012+ atomic_set_unchecked(&dev->bytes_rendered, 0);
48013+ atomic_set_unchecked(&dev->bytes_identical, 0);
48014+ atomic_set_unchecked(&dev->bytes_sent, 0);
48015+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
48016
48017 return count;
48018 }
48019diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
48020index d428445..79a78df 100644
48021--- a/drivers/video/uvesafb.c
48022+++ b/drivers/video/uvesafb.c
48023@@ -19,6 +19,7 @@
48024 #include <linux/io.h>
48025 #include <linux/mutex.h>
48026 #include <linux/slab.h>
48027+#include <linux/moduleloader.h>
48028 #include <video/edid.h>
48029 #include <video/uvesafb.h>
48030 #ifdef CONFIG_X86
48031@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
48032 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
48033 par->pmi_setpal = par->ypan = 0;
48034 } else {
48035+
48036+#ifdef CONFIG_PAX_KERNEXEC
48037+#ifdef CONFIG_MODULES
48038+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
48039+#endif
48040+ if (!par->pmi_code) {
48041+ par->pmi_setpal = par->ypan = 0;
48042+ return 0;
48043+ }
48044+#endif
48045+
48046 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
48047 + task->t.regs.edi);
48048+
48049+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48050+ pax_open_kernel();
48051+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
48052+ pax_close_kernel();
48053+
48054+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
48055+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
48056+#else
48057 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
48058 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
48059+#endif
48060+
48061 printk(KERN_INFO "uvesafb: protected mode interface info at "
48062 "%04x:%04x\n",
48063 (u16)task->t.regs.es, (u16)task->t.regs.edi);
48064@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
48065 par->ypan = ypan;
48066
48067 if (par->pmi_setpal || par->ypan) {
48068+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
48069 if (__supported_pte_mask & _PAGE_NX) {
48070 par->pmi_setpal = par->ypan = 0;
48071 printk(KERN_WARNING "uvesafb: NX protection is actively."
48072 "We have better not to use the PMI.\n");
48073- } else {
48074+ } else
48075+#endif
48076 uvesafb_vbe_getpmi(task, par);
48077- }
48078 }
48079 #else
48080 /* The protected mode interface is not available on non-x86. */
48081@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48082 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
48083
48084 /* Disable blanking if the user requested so. */
48085- if (!blank)
48086- info->fbops->fb_blank = NULL;
48087+ if (!blank) {
48088+ pax_open_kernel();
48089+ *(void **)&info->fbops->fb_blank = NULL;
48090+ pax_close_kernel();
48091+ }
48092
48093 /*
48094 * Find out how much IO memory is required for the mode with
48095@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48096 info->flags = FBINFO_FLAG_DEFAULT |
48097 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
48098
48099- if (!par->ypan)
48100- info->fbops->fb_pan_display = NULL;
48101+ if (!par->ypan) {
48102+ pax_open_kernel();
48103+ *(void **)&info->fbops->fb_pan_display = NULL;
48104+ pax_close_kernel();
48105+ }
48106 }
48107
48108 static void uvesafb_init_mtrr(struct fb_info *info)
48109@@ -1836,6 +1866,11 @@ out:
48110 if (par->vbe_modes)
48111 kfree(par->vbe_modes);
48112
48113+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48114+ if (par->pmi_code)
48115+ module_free_exec(NULL, par->pmi_code);
48116+#endif
48117+
48118 framebuffer_release(info);
48119 return err;
48120 }
48121@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
48122 kfree(par->vbe_state_orig);
48123 if (par->vbe_state_saved)
48124 kfree(par->vbe_state_saved);
48125+
48126+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48127+ if (par->pmi_code)
48128+ module_free_exec(NULL, par->pmi_code);
48129+#endif
48130+
48131 }
48132
48133 framebuffer_release(info);
48134diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
48135index 501b340..d80aa17 100644
48136--- a/drivers/video/vesafb.c
48137+++ b/drivers/video/vesafb.c
48138@@ -9,6 +9,7 @@
48139 */
48140
48141 #include <linux/module.h>
48142+#include <linux/moduleloader.h>
48143 #include <linux/kernel.h>
48144 #include <linux/errno.h>
48145 #include <linux/string.h>
48146@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
48147 static int vram_total __initdata; /* Set total amount of memory */
48148 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
48149 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
48150-static void (*pmi_start)(void) __read_mostly;
48151-static void (*pmi_pal) (void) __read_mostly;
48152+static void (*pmi_start)(void) __read_only;
48153+static void (*pmi_pal) (void) __read_only;
48154 static int depth __read_mostly;
48155 static int vga_compat __read_mostly;
48156 /* --------------------------------------------------------------------- */
48157@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
48158 unsigned int size_vmode;
48159 unsigned int size_remap;
48160 unsigned int size_total;
48161+ void *pmi_code = NULL;
48162
48163 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
48164 return -ENODEV;
48165@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
48166 size_remap = size_total;
48167 vesafb_fix.smem_len = size_remap;
48168
48169-#ifndef __i386__
48170- screen_info.vesapm_seg = 0;
48171-#endif
48172-
48173 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
48174 printk(KERN_WARNING
48175 "vesafb: cannot reserve video memory at 0x%lx\n",
48176@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
48177 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
48178 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
48179
48180+#ifdef __i386__
48181+
48182+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48183+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
48184+ if (!pmi_code)
48185+#elif !defined(CONFIG_PAX_KERNEXEC)
48186+ if (0)
48187+#endif
48188+
48189+#endif
48190+ screen_info.vesapm_seg = 0;
48191+
48192 if (screen_info.vesapm_seg) {
48193- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
48194- screen_info.vesapm_seg,screen_info.vesapm_off);
48195+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
48196+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
48197 }
48198
48199 if (screen_info.vesapm_seg < 0xc000)
48200@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
48201
48202 if (ypan || pmi_setpal) {
48203 unsigned short *pmi_base;
48204+
48205 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
48206- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
48207- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
48208+
48209+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48210+ pax_open_kernel();
48211+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
48212+#else
48213+ pmi_code = pmi_base;
48214+#endif
48215+
48216+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
48217+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
48218+
48219+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48220+ pmi_start = ktva_ktla(pmi_start);
48221+ pmi_pal = ktva_ktla(pmi_pal);
48222+ pax_close_kernel();
48223+#endif
48224+
48225 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
48226 if (pmi_base[3]) {
48227 printk(KERN_INFO "vesafb: pmi: ports = ");
48228@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48229 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
48230 (ypan ? FBINFO_HWACCEL_YPAN : 0);
48231
48232- if (!ypan)
48233- info->fbops->fb_pan_display = NULL;
48234+ if (!ypan) {
48235+ pax_open_kernel();
48236+ *(void **)&info->fbops->fb_pan_display = NULL;
48237+ pax_close_kernel();
48238+ }
48239
48240 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
48241 err = -ENOMEM;
48242@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48243 info->node, info->fix.id);
48244 return 0;
48245 err:
48246+
48247+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48248+ module_free_exec(NULL, pmi_code);
48249+#endif
48250+
48251 if (info->screen_base)
48252 iounmap(info->screen_base);
48253 framebuffer_release(info);
48254diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
48255index 88714ae..16c2e11 100644
48256--- a/drivers/video/via/via_clock.h
48257+++ b/drivers/video/via/via_clock.h
48258@@ -56,7 +56,7 @@ struct via_clock {
48259
48260 void (*set_engine_pll_state)(u8 state);
48261 void (*set_engine_pll)(struct via_pll_config config);
48262-};
48263+} __no_const;
48264
48265
48266 static inline u32 get_pll_internal_frequency(u32 ref_freq,
48267diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
48268index fef20db..d28b1ab 100644
48269--- a/drivers/xen/xenfs/xenstored.c
48270+++ b/drivers/xen/xenfs/xenstored.c
48271@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
48272 static int xsd_kva_open(struct inode *inode, struct file *file)
48273 {
48274 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
48275+#ifdef CONFIG_GRKERNSEC_HIDESYM
48276+ NULL);
48277+#else
48278 xen_store_interface);
48279+#endif
48280+
48281 if (!file->private_data)
48282 return -ENOMEM;
48283 return 0;
48284diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
48285index 0ad61c6..f198bd7 100644
48286--- a/fs/9p/vfs_addr.c
48287+++ b/fs/9p/vfs_addr.c
48288@@ -185,7 +185,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
48289
48290 retval = v9fs_file_write_internal(inode,
48291 v9inode->writeback_fid,
48292- (__force const char __user *)buffer,
48293+ (const char __force_user *)buffer,
48294 len, &offset, 0);
48295 if (retval > 0)
48296 retval = 0;
48297diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
48298index d86edc8..40ff2fb 100644
48299--- a/fs/9p/vfs_inode.c
48300+++ b/fs/9p/vfs_inode.c
48301@@ -1314,7 +1314,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48302 void
48303 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48304 {
48305- char *s = nd_get_link(nd);
48306+ const char *s = nd_get_link(nd);
48307
48308 p9_debug(P9_DEBUG_VFS, " %s %s\n",
48309 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
48310diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
48311index 0efd152..b5802ad 100644
48312--- a/fs/Kconfig.binfmt
48313+++ b/fs/Kconfig.binfmt
48314@@ -89,7 +89,7 @@ config HAVE_AOUT
48315
48316 config BINFMT_AOUT
48317 tristate "Kernel support for a.out and ECOFF binaries"
48318- depends on HAVE_AOUT
48319+ depends on HAVE_AOUT && BROKEN
48320 ---help---
48321 A.out (Assembler.OUTput) is a set of formats for libraries and
48322 executables used in the earliest versions of UNIX. Linux used
48323diff --git a/fs/aio.c b/fs/aio.c
48324index 1dc8786..d3b29e8 100644
48325--- a/fs/aio.c
48326+++ b/fs/aio.c
48327@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
48328 size += sizeof(struct io_event) * nr_events;
48329 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
48330
48331- if (nr_pages < 0)
48332+ if (nr_pages <= 0)
48333 return -EINVAL;
48334
48335 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
48336@@ -1375,18 +1375,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
48337 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48338 {
48339 ssize_t ret;
48340+ struct iovec iovstack;
48341
48342 #ifdef CONFIG_COMPAT
48343 if (compat)
48344 ret = compat_rw_copy_check_uvector(type,
48345 (struct compat_iovec __user *)kiocb->ki_buf,
48346- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48347+ kiocb->ki_nbytes, 1, &iovstack,
48348 &kiocb->ki_iovec);
48349 else
48350 #endif
48351 ret = rw_copy_check_uvector(type,
48352 (struct iovec __user *)kiocb->ki_buf,
48353- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48354+ kiocb->ki_nbytes, 1, &iovstack,
48355 &kiocb->ki_iovec);
48356 if (ret < 0)
48357 goto out;
48358@@ -1395,6 +1396,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48359 if (ret < 0)
48360 goto out;
48361
48362+ if (kiocb->ki_iovec == &iovstack) {
48363+ kiocb->ki_inline_vec = iovstack;
48364+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
48365+ }
48366 kiocb->ki_nr_segs = kiocb->ki_nbytes;
48367 kiocb->ki_cur_seg = 0;
48368 /* ki_nbytes/left now reflect bytes instead of segs */
48369diff --git a/fs/attr.c b/fs/attr.c
48370index 1449adb..a2038c2 100644
48371--- a/fs/attr.c
48372+++ b/fs/attr.c
48373@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
48374 unsigned long limit;
48375
48376 limit = rlimit(RLIMIT_FSIZE);
48377+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
48378 if (limit != RLIM_INFINITY && offset > limit)
48379 goto out_sig;
48380 if (offset > inode->i_sb->s_maxbytes)
48381diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
48382index 3db70da..7aeec5b 100644
48383--- a/fs/autofs4/waitq.c
48384+++ b/fs/autofs4/waitq.c
48385@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
48386 {
48387 unsigned long sigpipe, flags;
48388 mm_segment_t fs;
48389- const char *data = (const char *)addr;
48390+ const char __user *data = (const char __force_user *)addr;
48391 ssize_t wr = 0;
48392
48393 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
48394@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
48395 return 1;
48396 }
48397
48398+#ifdef CONFIG_GRKERNSEC_HIDESYM
48399+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
48400+#endif
48401+
48402 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48403 enum autofs_notify notify)
48404 {
48405@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48406
48407 /* If this is a direct mount request create a dummy name */
48408 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
48409+#ifdef CONFIG_GRKERNSEC_HIDESYM
48410+ /* this name does get written to userland via autofs4_write() */
48411+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
48412+#else
48413 qstr.len = sprintf(name, "%p", dentry);
48414+#endif
48415 else {
48416 qstr.len = autofs4_getpath(sbi, dentry, &name);
48417 if (!qstr.len) {
48418diff --git a/fs/befs/endian.h b/fs/befs/endian.h
48419index 2722387..c8dd2a7 100644
48420--- a/fs/befs/endian.h
48421+++ b/fs/befs/endian.h
48422@@ -11,7 +11,7 @@
48423
48424 #include <asm/byteorder.h>
48425
48426-static inline u64
48427+static inline u64 __intentional_overflow(-1)
48428 fs64_to_cpu(const struct super_block *sb, fs64 n)
48429 {
48430 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48431@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
48432 return (__force fs64)cpu_to_be64(n);
48433 }
48434
48435-static inline u32
48436+static inline u32 __intentional_overflow(-1)
48437 fs32_to_cpu(const struct super_block *sb, fs32 n)
48438 {
48439 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48440diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
48441index 8615ee8..388ed68 100644
48442--- a/fs/befs/linuxvfs.c
48443+++ b/fs/befs/linuxvfs.c
48444@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48445 {
48446 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
48447 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
48448- char *link = nd_get_link(nd);
48449+ const char *link = nd_get_link(nd);
48450 if (!IS_ERR(link))
48451 kfree(link);
48452 }
48453diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
48454index bbc8f88..7c7ac97 100644
48455--- a/fs/binfmt_aout.c
48456+++ b/fs/binfmt_aout.c
48457@@ -16,6 +16,7 @@
48458 #include <linux/string.h>
48459 #include <linux/fs.h>
48460 #include <linux/file.h>
48461+#include <linux/security.h>
48462 #include <linux/stat.h>
48463 #include <linux/fcntl.h>
48464 #include <linux/ptrace.h>
48465@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
48466 #endif
48467 # define START_STACK(u) ((void __user *)u.start_stack)
48468
48469+ memset(&dump, 0, sizeof(dump));
48470+
48471 fs = get_fs();
48472 set_fs(KERNEL_DS);
48473 has_dumped = 1;
48474@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
48475
48476 /* If the size of the dump file exceeds the rlimit, then see what would happen
48477 if we wrote the stack, but not the data area. */
48478+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
48479 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
48480 dump.u_dsize = 0;
48481
48482 /* Make sure we have enough room to write the stack and data areas. */
48483+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
48484 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
48485 dump.u_ssize = 0;
48486
48487@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
48488 rlim = rlimit(RLIMIT_DATA);
48489 if (rlim >= RLIM_INFINITY)
48490 rlim = ~0;
48491+
48492+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
48493 if (ex.a_data + ex.a_bss > rlim)
48494 return -ENOMEM;
48495
48496@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
48497
48498 install_exec_creds(bprm);
48499
48500+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48501+ current->mm->pax_flags = 0UL;
48502+#endif
48503+
48504+#ifdef CONFIG_PAX_PAGEEXEC
48505+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
48506+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
48507+
48508+#ifdef CONFIG_PAX_EMUTRAMP
48509+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
48510+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
48511+#endif
48512+
48513+#ifdef CONFIG_PAX_MPROTECT
48514+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
48515+ current->mm->pax_flags |= MF_PAX_MPROTECT;
48516+#endif
48517+
48518+ }
48519+#endif
48520+
48521 if (N_MAGIC(ex) == OMAGIC) {
48522 unsigned long text_addr, map_size;
48523 loff_t pos;
48524@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
48525 }
48526
48527 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
48528- PROT_READ | PROT_WRITE | PROT_EXEC,
48529+ PROT_READ | PROT_WRITE,
48530 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
48531 fd_offset + ex.a_text);
48532 if (error != N_DATADDR(ex)) {
48533diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
48534index 86af964..5d53bf6 100644
48535--- a/fs/binfmt_elf.c
48536+++ b/fs/binfmt_elf.c
48537@@ -34,6 +34,7 @@
48538 #include <linux/utsname.h>
48539 #include <linux/coredump.h>
48540 #include <linux/sched.h>
48541+#include <linux/xattr.h>
48542 #include <asm/uaccess.h>
48543 #include <asm/param.h>
48544 #include <asm/page.h>
48545@@ -60,6 +61,10 @@ static int elf_core_dump(struct coredump_params *cprm);
48546 #define elf_core_dump NULL
48547 #endif
48548
48549+#ifdef CONFIG_PAX_MPROTECT
48550+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
48551+#endif
48552+
48553 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
48554 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
48555 #else
48556@@ -79,6 +84,11 @@ static struct linux_binfmt elf_format = {
48557 .load_binary = load_elf_binary,
48558 .load_shlib = load_elf_library,
48559 .core_dump = elf_core_dump,
48560+
48561+#ifdef CONFIG_PAX_MPROTECT
48562+ .handle_mprotect= elf_handle_mprotect,
48563+#endif
48564+
48565 .min_coredump = ELF_EXEC_PAGESIZE,
48566 };
48567
48568@@ -86,6 +96,8 @@ static struct linux_binfmt elf_format = {
48569
48570 static int set_brk(unsigned long start, unsigned long end)
48571 {
48572+ unsigned long e = end;
48573+
48574 start = ELF_PAGEALIGN(start);
48575 end = ELF_PAGEALIGN(end);
48576 if (end > start) {
48577@@ -94,7 +106,7 @@ static int set_brk(unsigned long start, unsigned long end)
48578 if (BAD_ADDR(addr))
48579 return addr;
48580 }
48581- current->mm->start_brk = current->mm->brk = end;
48582+ current->mm->start_brk = current->mm->brk = e;
48583 return 0;
48584 }
48585
48586@@ -155,12 +167,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48587 elf_addr_t __user *u_rand_bytes;
48588 const char *k_platform = ELF_PLATFORM;
48589 const char *k_base_platform = ELF_BASE_PLATFORM;
48590- unsigned char k_rand_bytes[16];
48591+ u32 k_rand_bytes[4];
48592 int items;
48593 elf_addr_t *elf_info;
48594 int ei_index = 0;
48595 const struct cred *cred = current_cred();
48596 struct vm_area_struct *vma;
48597+ unsigned long saved_auxv[AT_VECTOR_SIZE];
48598
48599 /*
48600 * In some cases (e.g. Hyper-Threading), we want to avoid L1
48601@@ -202,8 +215,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48602 * Generate 16 random bytes for userspace PRNG seeding.
48603 */
48604 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
48605- u_rand_bytes = (elf_addr_t __user *)
48606- STACK_ALLOC(p, sizeof(k_rand_bytes));
48607+ srandom32(k_rand_bytes[0] ^ random32());
48608+ srandom32(k_rand_bytes[1] ^ random32());
48609+ srandom32(k_rand_bytes[2] ^ random32());
48610+ srandom32(k_rand_bytes[3] ^ random32());
48611+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
48612+ u_rand_bytes = (elf_addr_t __user *) p;
48613 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
48614 return -EFAULT;
48615
48616@@ -315,9 +332,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48617 return -EFAULT;
48618 current->mm->env_end = p;
48619
48620+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
48621+
48622 /* Put the elf_info on the stack in the right place. */
48623 sp = (elf_addr_t __user *)envp + 1;
48624- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
48625+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
48626 return -EFAULT;
48627 return 0;
48628 }
48629@@ -385,15 +404,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
48630 an ELF header */
48631
48632 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48633- struct file *interpreter, unsigned long *interp_map_addr,
48634- unsigned long no_base)
48635+ struct file *interpreter, unsigned long no_base)
48636 {
48637 struct elf_phdr *elf_phdata;
48638 struct elf_phdr *eppnt;
48639- unsigned long load_addr = 0;
48640+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48641 int load_addr_set = 0;
48642 unsigned long last_bss = 0, elf_bss = 0;
48643- unsigned long error = ~0UL;
48644+ unsigned long error = -EINVAL;
48645 unsigned long total_size;
48646 int retval, i, size;
48647
48648@@ -439,6 +457,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48649 goto out_close;
48650 }
48651
48652+#ifdef CONFIG_PAX_SEGMEXEC
48653+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48654+ pax_task_size = SEGMEXEC_TASK_SIZE;
48655+#endif
48656+
48657 eppnt = elf_phdata;
48658 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48659 if (eppnt->p_type == PT_LOAD) {
48660@@ -462,8 +485,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48661 map_addr = elf_map(interpreter, load_addr + vaddr,
48662 eppnt, elf_prot, elf_type, total_size);
48663 total_size = 0;
48664- if (!*interp_map_addr)
48665- *interp_map_addr = map_addr;
48666 error = map_addr;
48667 if (BAD_ADDR(map_addr))
48668 goto out_close;
48669@@ -482,8 +503,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48670 k = load_addr + eppnt->p_vaddr;
48671 if (BAD_ADDR(k) ||
48672 eppnt->p_filesz > eppnt->p_memsz ||
48673- eppnt->p_memsz > TASK_SIZE ||
48674- TASK_SIZE - eppnt->p_memsz < k) {
48675+ eppnt->p_memsz > pax_task_size ||
48676+ pax_task_size - eppnt->p_memsz < k) {
48677 error = -ENOMEM;
48678 goto out_close;
48679 }
48680@@ -535,6 +556,315 @@ out:
48681 return error;
48682 }
48683
48684+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48685+#ifdef CONFIG_PAX_SOFTMODE
48686+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48687+{
48688+ unsigned long pax_flags = 0UL;
48689+
48690+#ifdef CONFIG_PAX_PAGEEXEC
48691+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48692+ pax_flags |= MF_PAX_PAGEEXEC;
48693+#endif
48694+
48695+#ifdef CONFIG_PAX_SEGMEXEC
48696+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48697+ pax_flags |= MF_PAX_SEGMEXEC;
48698+#endif
48699+
48700+#ifdef CONFIG_PAX_EMUTRAMP
48701+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48702+ pax_flags |= MF_PAX_EMUTRAMP;
48703+#endif
48704+
48705+#ifdef CONFIG_PAX_MPROTECT
48706+ if (elf_phdata->p_flags & PF_MPROTECT)
48707+ pax_flags |= MF_PAX_MPROTECT;
48708+#endif
48709+
48710+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48711+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48712+ pax_flags |= MF_PAX_RANDMMAP;
48713+#endif
48714+
48715+ return pax_flags;
48716+}
48717+#endif
48718+
48719+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48720+{
48721+ unsigned long pax_flags = 0UL;
48722+
48723+#ifdef CONFIG_PAX_PAGEEXEC
48724+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48725+ pax_flags |= MF_PAX_PAGEEXEC;
48726+#endif
48727+
48728+#ifdef CONFIG_PAX_SEGMEXEC
48729+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48730+ pax_flags |= MF_PAX_SEGMEXEC;
48731+#endif
48732+
48733+#ifdef CONFIG_PAX_EMUTRAMP
48734+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48735+ pax_flags |= MF_PAX_EMUTRAMP;
48736+#endif
48737+
48738+#ifdef CONFIG_PAX_MPROTECT
48739+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48740+ pax_flags |= MF_PAX_MPROTECT;
48741+#endif
48742+
48743+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48744+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48745+ pax_flags |= MF_PAX_RANDMMAP;
48746+#endif
48747+
48748+ return pax_flags;
48749+}
48750+#endif
48751+
48752+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48753+#ifdef CONFIG_PAX_SOFTMODE
48754+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48755+{
48756+ unsigned long pax_flags = 0UL;
48757+
48758+#ifdef CONFIG_PAX_PAGEEXEC
48759+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48760+ pax_flags |= MF_PAX_PAGEEXEC;
48761+#endif
48762+
48763+#ifdef CONFIG_PAX_SEGMEXEC
48764+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48765+ pax_flags |= MF_PAX_SEGMEXEC;
48766+#endif
48767+
48768+#ifdef CONFIG_PAX_EMUTRAMP
48769+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48770+ pax_flags |= MF_PAX_EMUTRAMP;
48771+#endif
48772+
48773+#ifdef CONFIG_PAX_MPROTECT
48774+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48775+ pax_flags |= MF_PAX_MPROTECT;
48776+#endif
48777+
48778+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48779+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48780+ pax_flags |= MF_PAX_RANDMMAP;
48781+#endif
48782+
48783+ return pax_flags;
48784+}
48785+#endif
48786+
48787+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48788+{
48789+ unsigned long pax_flags = 0UL;
48790+
48791+#ifdef CONFIG_PAX_PAGEEXEC
48792+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48793+ pax_flags |= MF_PAX_PAGEEXEC;
48794+#endif
48795+
48796+#ifdef CONFIG_PAX_SEGMEXEC
48797+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48798+ pax_flags |= MF_PAX_SEGMEXEC;
48799+#endif
48800+
48801+#ifdef CONFIG_PAX_EMUTRAMP
48802+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48803+ pax_flags |= MF_PAX_EMUTRAMP;
48804+#endif
48805+
48806+#ifdef CONFIG_PAX_MPROTECT
48807+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48808+ pax_flags |= MF_PAX_MPROTECT;
48809+#endif
48810+
48811+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48812+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48813+ pax_flags |= MF_PAX_RANDMMAP;
48814+#endif
48815+
48816+ return pax_flags;
48817+}
48818+#endif
48819+
48820+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48821+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48822+{
48823+ unsigned long pax_flags = 0UL;
48824+
48825+#ifdef CONFIG_PAX_EI_PAX
48826+
48827+#ifdef CONFIG_PAX_PAGEEXEC
48828+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48829+ pax_flags |= MF_PAX_PAGEEXEC;
48830+#endif
48831+
48832+#ifdef CONFIG_PAX_SEGMEXEC
48833+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48834+ pax_flags |= MF_PAX_SEGMEXEC;
48835+#endif
48836+
48837+#ifdef CONFIG_PAX_EMUTRAMP
48838+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48839+ pax_flags |= MF_PAX_EMUTRAMP;
48840+#endif
48841+
48842+#ifdef CONFIG_PAX_MPROTECT
48843+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48844+ pax_flags |= MF_PAX_MPROTECT;
48845+#endif
48846+
48847+#ifdef CONFIG_PAX_ASLR
48848+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48849+ pax_flags |= MF_PAX_RANDMMAP;
48850+#endif
48851+
48852+#else
48853+
48854+#ifdef CONFIG_PAX_PAGEEXEC
48855+ pax_flags |= MF_PAX_PAGEEXEC;
48856+#endif
48857+
48858+#ifdef CONFIG_PAX_SEGMEXEC
48859+ pax_flags |= MF_PAX_SEGMEXEC;
48860+#endif
48861+
48862+#ifdef CONFIG_PAX_MPROTECT
48863+ pax_flags |= MF_PAX_MPROTECT;
48864+#endif
48865+
48866+#ifdef CONFIG_PAX_RANDMMAP
48867+ if (randomize_va_space)
48868+ pax_flags |= MF_PAX_RANDMMAP;
48869+#endif
48870+
48871+#endif
48872+
48873+ return pax_flags;
48874+}
48875+
48876+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48877+{
48878+
48879+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48880+ unsigned long i;
48881+
48882+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48883+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48884+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48885+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48886+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48887+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48888+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48889+ return ~0UL;
48890+
48891+#ifdef CONFIG_PAX_SOFTMODE
48892+ if (pax_softmode)
48893+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48894+ else
48895+#endif
48896+
48897+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48898+ break;
48899+ }
48900+#endif
48901+
48902+ return ~0UL;
48903+}
48904+
48905+static unsigned long pax_parse_xattr_pax(struct file * const file)
48906+{
48907+
48908+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48909+ ssize_t xattr_size, i;
48910+ unsigned char xattr_value[sizeof("pemrs") - 1];
48911+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
48912+
48913+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
48914+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
48915+ return ~0UL;
48916+
48917+ for (i = 0; i < xattr_size; i++)
48918+ switch (xattr_value[i]) {
48919+ default:
48920+ return ~0UL;
48921+
48922+#define parse_flag(option1, option2, flag) \
48923+ case option1: \
48924+ if (pax_flags_hardmode & MF_PAX_##flag) \
48925+ return ~0UL; \
48926+ pax_flags_hardmode |= MF_PAX_##flag; \
48927+ break; \
48928+ case option2: \
48929+ if (pax_flags_softmode & MF_PAX_##flag) \
48930+ return ~0UL; \
48931+ pax_flags_softmode |= MF_PAX_##flag; \
48932+ break;
48933+
48934+ parse_flag('p', 'P', PAGEEXEC);
48935+ parse_flag('e', 'E', EMUTRAMP);
48936+ parse_flag('m', 'M', MPROTECT);
48937+ parse_flag('r', 'R', RANDMMAP);
48938+ parse_flag('s', 'S', SEGMEXEC);
48939+
48940+#undef parse_flag
48941+ }
48942+
48943+ if (pax_flags_hardmode & pax_flags_softmode)
48944+ return ~0UL;
48945+
48946+#ifdef CONFIG_PAX_SOFTMODE
48947+ if (pax_softmode)
48948+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
48949+ else
48950+#endif
48951+
48952+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
48953+#else
48954+ return ~0UL;
48955+#endif
48956+
48957+}
48958+
48959+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
48960+{
48961+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
48962+
48963+ pax_flags = pax_parse_ei_pax(elf_ex);
48964+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
48965+ xattr_pax_flags = pax_parse_xattr_pax(file);
48966+
48967+ if (pt_pax_flags == ~0UL)
48968+ pt_pax_flags = xattr_pax_flags;
48969+ else if (xattr_pax_flags == ~0UL)
48970+ xattr_pax_flags = pt_pax_flags;
48971+ if (pt_pax_flags != xattr_pax_flags)
48972+ return -EINVAL;
48973+ if (pt_pax_flags != ~0UL)
48974+ pax_flags = pt_pax_flags;
48975+
48976+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
48977+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48978+ if ((__supported_pte_mask & _PAGE_NX))
48979+ pax_flags &= ~MF_PAX_SEGMEXEC;
48980+ else
48981+ pax_flags &= ~MF_PAX_PAGEEXEC;
48982+ }
48983+#endif
48984+
48985+ if (0 > pax_check_flags(&pax_flags))
48986+ return -EINVAL;
48987+
48988+ current->mm->pax_flags = pax_flags;
48989+ return 0;
48990+}
48991+#endif
48992+
48993 /*
48994 * These are the functions used to load ELF style executables and shared
48995 * libraries. There is no binary dependent code anywhere else.
48996@@ -551,6 +881,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
48997 {
48998 unsigned int random_variable = 0;
48999
49000+#ifdef CONFIG_PAX_RANDUSTACK
49001+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
49002+ return stack_top - current->mm->delta_stack;
49003+#endif
49004+
49005 if ((current->flags & PF_RANDOMIZE) &&
49006 !(current->personality & ADDR_NO_RANDOMIZE)) {
49007 random_variable = get_random_int() & STACK_RND_MASK;
49008@@ -569,7 +904,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
49009 unsigned long load_addr = 0, load_bias = 0;
49010 int load_addr_set = 0;
49011 char * elf_interpreter = NULL;
49012- unsigned long error;
49013+ unsigned long error = 0;
49014 struct elf_phdr *elf_ppnt, *elf_phdata;
49015 unsigned long elf_bss, elf_brk;
49016 int retval, i;
49017@@ -579,12 +914,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
49018 unsigned long start_code, end_code, start_data, end_data;
49019 unsigned long reloc_func_desc __maybe_unused = 0;
49020 int executable_stack = EXSTACK_DEFAULT;
49021- unsigned long def_flags = 0;
49022 struct pt_regs *regs = current_pt_regs();
49023 struct {
49024 struct elfhdr elf_ex;
49025 struct elfhdr interp_elf_ex;
49026 } *loc;
49027+ unsigned long pax_task_size = TASK_SIZE;
49028
49029 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
49030 if (!loc) {
49031@@ -720,11 +1055,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
49032 goto out_free_dentry;
49033
49034 /* OK, This is the point of no return */
49035- current->mm->def_flags = def_flags;
49036+
49037+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49038+ current->mm->pax_flags = 0UL;
49039+#endif
49040+
49041+#ifdef CONFIG_PAX_DLRESOLVE
49042+ current->mm->call_dl_resolve = 0UL;
49043+#endif
49044+
49045+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
49046+ current->mm->call_syscall = 0UL;
49047+#endif
49048+
49049+#ifdef CONFIG_PAX_ASLR
49050+ current->mm->delta_mmap = 0UL;
49051+ current->mm->delta_stack = 0UL;
49052+#endif
49053+
49054+ current->mm->def_flags = 0;
49055+
49056+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49057+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
49058+ send_sig(SIGKILL, current, 0);
49059+ goto out_free_dentry;
49060+ }
49061+#endif
49062+
49063+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49064+ pax_set_initial_flags(bprm);
49065+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
49066+ if (pax_set_initial_flags_func)
49067+ (pax_set_initial_flags_func)(bprm);
49068+#endif
49069+
49070+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49071+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
49072+ current->mm->context.user_cs_limit = PAGE_SIZE;
49073+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
49074+ }
49075+#endif
49076+
49077+#ifdef CONFIG_PAX_SEGMEXEC
49078+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
49079+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
49080+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
49081+ pax_task_size = SEGMEXEC_TASK_SIZE;
49082+ current->mm->def_flags |= VM_NOHUGEPAGE;
49083+ }
49084+#endif
49085+
49086+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
49087+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49088+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
49089+ put_cpu();
49090+ }
49091+#endif
49092
49093 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
49094 may depend on the personality. */
49095 SET_PERSONALITY(loc->elf_ex);
49096+
49097+#ifdef CONFIG_PAX_ASLR
49098+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49099+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
49100+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
49101+ }
49102+#endif
49103+
49104+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49105+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49106+ executable_stack = EXSTACK_DISABLE_X;
49107+ current->personality &= ~READ_IMPLIES_EXEC;
49108+ } else
49109+#endif
49110+
49111 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
49112 current->personality |= READ_IMPLIES_EXEC;
49113
49114@@ -815,6 +1220,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
49115 #else
49116 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
49117 #endif
49118+
49119+#ifdef CONFIG_PAX_RANDMMAP
49120+ /* PaX: randomize base address at the default exe base if requested */
49121+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
49122+#ifdef CONFIG_SPARC64
49123+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
49124+#else
49125+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
49126+#endif
49127+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
49128+ elf_flags |= MAP_FIXED;
49129+ }
49130+#endif
49131+
49132 }
49133
49134 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
49135@@ -847,9 +1266,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
49136 * allowed task size. Note that p_filesz must always be
49137 * <= p_memsz so it is only necessary to check p_memsz.
49138 */
49139- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49140- elf_ppnt->p_memsz > TASK_SIZE ||
49141- TASK_SIZE - elf_ppnt->p_memsz < k) {
49142+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49143+ elf_ppnt->p_memsz > pax_task_size ||
49144+ pax_task_size - elf_ppnt->p_memsz < k) {
49145 /* set_brk can never work. Avoid overflows. */
49146 send_sig(SIGKILL, current, 0);
49147 retval = -EINVAL;
49148@@ -888,17 +1307,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
49149 goto out_free_dentry;
49150 }
49151 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
49152- send_sig(SIGSEGV, current, 0);
49153- retval = -EFAULT; /* Nobody gets to see this, but.. */
49154- goto out_free_dentry;
49155+ /*
49156+ * This bss-zeroing can fail if the ELF
49157+ * file specifies odd protections. So
49158+ * we don't check the return value
49159+ */
49160 }
49161
49162+#ifdef CONFIG_PAX_RANDMMAP
49163+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49164+ unsigned long start, size, flags;
49165+ vm_flags_t vm_flags;
49166+
49167+ start = ELF_PAGEALIGN(elf_brk);
49168+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
49169+ flags = MAP_FIXED | MAP_PRIVATE;
49170+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
49171+
49172+ down_write(&current->mm->mmap_sem);
49173+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
49174+ retval = -ENOMEM;
49175+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
49176+// if (current->personality & ADDR_NO_RANDOMIZE)
49177+// vm_flags |= VM_READ | VM_MAYREAD;
49178+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
49179+ retval = IS_ERR_VALUE(start) ? start : 0;
49180+ }
49181+ up_write(&current->mm->mmap_sem);
49182+ if (retval == 0)
49183+ retval = set_brk(start + size, start + size + PAGE_SIZE);
49184+ if (retval < 0) {
49185+ send_sig(SIGKILL, current, 0);
49186+ goto out_free_dentry;
49187+ }
49188+ }
49189+#endif
49190+
49191 if (elf_interpreter) {
49192- unsigned long interp_map_addr = 0;
49193-
49194 elf_entry = load_elf_interp(&loc->interp_elf_ex,
49195 interpreter,
49196- &interp_map_addr,
49197 load_bias);
49198 if (!IS_ERR((void *)elf_entry)) {
49199 /*
49200@@ -1120,7 +1567,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
49201 * Decide what to dump of a segment, part, all or none.
49202 */
49203 static unsigned long vma_dump_size(struct vm_area_struct *vma,
49204- unsigned long mm_flags)
49205+ unsigned long mm_flags, long signr)
49206 {
49207 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
49208
49209@@ -1158,7 +1605,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
49210 if (vma->vm_file == NULL)
49211 return 0;
49212
49213- if (FILTER(MAPPED_PRIVATE))
49214+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
49215 goto whole;
49216
49217 /*
49218@@ -1383,9 +1830,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
49219 {
49220 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
49221 int i = 0;
49222- do
49223+ do {
49224 i += 2;
49225- while (auxv[i - 2] != AT_NULL);
49226+ } while (auxv[i - 2] != AT_NULL);
49227 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
49228 }
49229
49230@@ -1394,7 +1841,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
49231 {
49232 mm_segment_t old_fs = get_fs();
49233 set_fs(KERNEL_DS);
49234- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
49235+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
49236 set_fs(old_fs);
49237 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
49238 }
49239@@ -2015,14 +2462,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
49240 }
49241
49242 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
49243- unsigned long mm_flags)
49244+ struct coredump_params *cprm)
49245 {
49246 struct vm_area_struct *vma;
49247 size_t size = 0;
49248
49249 for (vma = first_vma(current, gate_vma); vma != NULL;
49250 vma = next_vma(vma, gate_vma))
49251- size += vma_dump_size(vma, mm_flags);
49252+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49253 return size;
49254 }
49255
49256@@ -2116,7 +2563,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49257
49258 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
49259
49260- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
49261+ offset += elf_core_vma_data_size(gate_vma, cprm);
49262 offset += elf_core_extra_data_size();
49263 e_shoff = offset;
49264
49265@@ -2130,10 +2577,12 @@ static int elf_core_dump(struct coredump_params *cprm)
49266 offset = dataoff;
49267
49268 size += sizeof(*elf);
49269+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49270 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
49271 goto end_coredump;
49272
49273 size += sizeof(*phdr4note);
49274+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49275 if (size > cprm->limit
49276 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
49277 goto end_coredump;
49278@@ -2147,7 +2596,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49279 phdr.p_offset = offset;
49280 phdr.p_vaddr = vma->vm_start;
49281 phdr.p_paddr = 0;
49282- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
49283+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49284 phdr.p_memsz = vma->vm_end - vma->vm_start;
49285 offset += phdr.p_filesz;
49286 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
49287@@ -2158,6 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49288 phdr.p_align = ELF_EXEC_PAGESIZE;
49289
49290 size += sizeof(phdr);
49291+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49292 if (size > cprm->limit
49293 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
49294 goto end_coredump;
49295@@ -2182,7 +2632,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49296 unsigned long addr;
49297 unsigned long end;
49298
49299- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
49300+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49301
49302 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
49303 struct page *page;
49304@@ -2191,6 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49305 page = get_dump_page(addr);
49306 if (page) {
49307 void *kaddr = kmap(page);
49308+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
49309 stop = ((size += PAGE_SIZE) > cprm->limit) ||
49310 !dump_write(cprm->file, kaddr,
49311 PAGE_SIZE);
49312@@ -2208,6 +2659,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49313
49314 if (e_phnum == PN_XNUM) {
49315 size += sizeof(*shdr4extnum);
49316+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49317 if (size > cprm->limit
49318 || !dump_write(cprm->file, shdr4extnum,
49319 sizeof(*shdr4extnum)))
49320@@ -2228,6 +2680,97 @@ out:
49321
49322 #endif /* CONFIG_ELF_CORE */
49323
49324+#ifdef CONFIG_PAX_MPROTECT
49325+/* PaX: non-PIC ELF libraries need relocations on their executable segments
49326+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
49327+ * we'll remove VM_MAYWRITE for good on RELRO segments.
49328+ *
49329+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
49330+ * basis because we want to allow the common case and not the special ones.
49331+ */
49332+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
49333+{
49334+ struct elfhdr elf_h;
49335+ struct elf_phdr elf_p;
49336+ unsigned long i;
49337+ unsigned long oldflags;
49338+ bool is_textrel_rw, is_textrel_rx, is_relro;
49339+
49340+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
49341+ return;
49342+
49343+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
49344+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
49345+
49346+#ifdef CONFIG_PAX_ELFRELOCS
49347+ /* possible TEXTREL */
49348+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
49349+ 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);
49350+#else
49351+ is_textrel_rw = false;
49352+ is_textrel_rx = false;
49353+#endif
49354+
49355+ /* possible RELRO */
49356+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
49357+
49358+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
49359+ return;
49360+
49361+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49362+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49363+
49364+#ifdef CONFIG_PAX_ETEXECRELOCS
49365+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49366+#else
49367+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
49368+#endif
49369+
49370+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49371+ !elf_check_arch(&elf_h) ||
49372+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49373+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49374+ return;
49375+
49376+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49377+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49378+ return;
49379+ switch (elf_p.p_type) {
49380+ case PT_DYNAMIC:
49381+ if (!is_textrel_rw && !is_textrel_rx)
49382+ continue;
49383+ i = 0UL;
49384+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
49385+ elf_dyn dyn;
49386+
49387+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
49388+ return;
49389+ if (dyn.d_tag == DT_NULL)
49390+ return;
49391+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
49392+ gr_log_textrel(vma);
49393+ if (is_textrel_rw)
49394+ vma->vm_flags |= VM_MAYWRITE;
49395+ else
49396+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
49397+ vma->vm_flags &= ~VM_MAYWRITE;
49398+ return;
49399+ }
49400+ i++;
49401+ }
49402+ return;
49403+
49404+ case PT_GNU_RELRO:
49405+ if (!is_relro)
49406+ continue;
49407+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
49408+ vma->vm_flags &= ~VM_MAYWRITE;
49409+ return;
49410+ }
49411+ }
49412+}
49413+#endif
49414+
49415 static int __init init_elf_binfmt(void)
49416 {
49417 register_binfmt(&elf_format);
49418diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
49419index 2036d21..b0430d0 100644
49420--- a/fs/binfmt_flat.c
49421+++ b/fs/binfmt_flat.c
49422@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
49423 realdatastart = (unsigned long) -ENOMEM;
49424 printk("Unable to allocate RAM for process data, errno %d\n",
49425 (int)-realdatastart);
49426+ down_write(&current->mm->mmap_sem);
49427 vm_munmap(textpos, text_len);
49428+ up_write(&current->mm->mmap_sem);
49429 ret = realdatastart;
49430 goto err;
49431 }
49432@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49433 }
49434 if (IS_ERR_VALUE(result)) {
49435 printk("Unable to read data+bss, errno %d\n", (int)-result);
49436+ down_write(&current->mm->mmap_sem);
49437 vm_munmap(textpos, text_len);
49438 vm_munmap(realdatastart, len);
49439+ up_write(&current->mm->mmap_sem);
49440 ret = result;
49441 goto err;
49442 }
49443@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49444 }
49445 if (IS_ERR_VALUE(result)) {
49446 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
49447+ down_write(&current->mm->mmap_sem);
49448 vm_munmap(textpos, text_len + data_len + extra +
49449 MAX_SHARED_LIBS * sizeof(unsigned long));
49450+ up_write(&current->mm->mmap_sem);
49451 ret = result;
49452 goto err;
49453 }
49454diff --git a/fs/bio.c b/fs/bio.c
49455index b96fc6c..431d628 100644
49456--- a/fs/bio.c
49457+++ b/fs/bio.c
49458@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
49459 /*
49460 * Overflow, abort
49461 */
49462- if (end < start)
49463+ if (end < start || end - start > INT_MAX - nr_pages)
49464 return ERR_PTR(-EINVAL);
49465
49466 nr_pages += end - start;
49467@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
49468 /*
49469 * Overflow, abort
49470 */
49471- if (end < start)
49472+ if (end < start || end - start > INT_MAX - nr_pages)
49473 return ERR_PTR(-EINVAL);
49474
49475 nr_pages += end - start;
49476@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
49477 const int read = bio_data_dir(bio) == READ;
49478 struct bio_map_data *bmd = bio->bi_private;
49479 int i;
49480- char *p = bmd->sgvecs[0].iov_base;
49481+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
49482
49483 __bio_for_each_segment(bvec, bio, i, 0) {
49484 char *addr = page_address(bvec->bv_page);
49485diff --git a/fs/block_dev.c b/fs/block_dev.c
49486index aae187a..fd790ba 100644
49487--- a/fs/block_dev.c
49488+++ b/fs/block_dev.c
49489@@ -652,7 +652,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
49490 else if (bdev->bd_contains == bdev)
49491 return true; /* is a whole device which isn't held */
49492
49493- else if (whole->bd_holder == bd_may_claim)
49494+ else if (whole->bd_holder == (void *)bd_may_claim)
49495 return true; /* is a partition of a device that is being partitioned */
49496 else if (whole->bd_holder != NULL)
49497 return false; /* is a partition of a held device */
49498diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
49499index ca9d8f1..8c0142d 100644
49500--- a/fs/btrfs/ctree.c
49501+++ b/fs/btrfs/ctree.c
49502@@ -1036,9 +1036,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
49503 free_extent_buffer(buf);
49504 add_root_to_dirty_list(root);
49505 } else {
49506- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
49507- parent_start = parent->start;
49508- else
49509+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
49510+ if (parent)
49511+ parent_start = parent->start;
49512+ else
49513+ parent_start = 0;
49514+ } else
49515 parent_start = 0;
49516
49517 WARN_ON(trans->transid != btrfs_header_generation(parent));
49518diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
49519index f49b62f..07834ab 100644
49520--- a/fs/btrfs/ioctl.c
49521+++ b/fs/btrfs/ioctl.c
49522@@ -3077,9 +3077,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49523 for (i = 0; i < num_types; i++) {
49524 struct btrfs_space_info *tmp;
49525
49526+ /* Don't copy in more than we allocated */
49527 if (!slot_count)
49528 break;
49529
49530+ slot_count--;
49531+
49532 info = NULL;
49533 rcu_read_lock();
49534 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
49535@@ -3101,10 +3104,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49536 memcpy(dest, &space, sizeof(space));
49537 dest++;
49538 space_args.total_spaces++;
49539- slot_count--;
49540 }
49541- if (!slot_count)
49542- break;
49543 }
49544 up_read(&info->groups_sem);
49545 }
49546diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
49547index f6b8859..54fe8c5 100644
49548--- a/fs/btrfs/super.c
49549+++ b/fs/btrfs/super.c
49550@@ -266,7 +266,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
49551 function, line, errstr);
49552 return;
49553 }
49554- ACCESS_ONCE(trans->transaction->aborted) = errno;
49555+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
49556 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
49557 }
49558 /*
49559diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
49560index 622f469..e8d2d55 100644
49561--- a/fs/cachefiles/bind.c
49562+++ b/fs/cachefiles/bind.c
49563@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
49564 args);
49565
49566 /* start by checking things over */
49567- ASSERT(cache->fstop_percent >= 0 &&
49568- cache->fstop_percent < cache->fcull_percent &&
49569+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
49570 cache->fcull_percent < cache->frun_percent &&
49571 cache->frun_percent < 100);
49572
49573- ASSERT(cache->bstop_percent >= 0 &&
49574- cache->bstop_percent < cache->bcull_percent &&
49575+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
49576 cache->bcull_percent < cache->brun_percent &&
49577 cache->brun_percent < 100);
49578
49579diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
49580index 0a1467b..6a53245 100644
49581--- a/fs/cachefiles/daemon.c
49582+++ b/fs/cachefiles/daemon.c
49583@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
49584 if (n > buflen)
49585 return -EMSGSIZE;
49586
49587- if (copy_to_user(_buffer, buffer, n) != 0)
49588+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
49589 return -EFAULT;
49590
49591 return n;
49592@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
49593 if (test_bit(CACHEFILES_DEAD, &cache->flags))
49594 return -EIO;
49595
49596- if (datalen < 0 || datalen > PAGE_SIZE - 1)
49597+ if (datalen > PAGE_SIZE - 1)
49598 return -EOPNOTSUPP;
49599
49600 /* drag the command string into the kernel so we can parse it */
49601@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
49602 if (args[0] != '%' || args[1] != '\0')
49603 return -EINVAL;
49604
49605- if (fstop < 0 || fstop >= cache->fcull_percent)
49606+ if (fstop >= cache->fcull_percent)
49607 return cachefiles_daemon_range_error(cache, args);
49608
49609 cache->fstop_percent = fstop;
49610@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49611 if (args[0] != '%' || args[1] != '\0')
49612 return -EINVAL;
49613
49614- if (bstop < 0 || bstop >= cache->bcull_percent)
49615+ if (bstop >= cache->bcull_percent)
49616 return cachefiles_daemon_range_error(cache, args);
49617
49618 cache->bstop_percent = bstop;
49619diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49620index 4938251..7e01445 100644
49621--- a/fs/cachefiles/internal.h
49622+++ b/fs/cachefiles/internal.h
49623@@ -59,7 +59,7 @@ struct cachefiles_cache {
49624 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49625 struct rb_root active_nodes; /* active nodes (can't be culled) */
49626 rwlock_t active_lock; /* lock for active_nodes */
49627- atomic_t gravecounter; /* graveyard uniquifier */
49628+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49629 unsigned frun_percent; /* when to stop culling (% files) */
49630 unsigned fcull_percent; /* when to start culling (% files) */
49631 unsigned fstop_percent; /* when to stop allocating (% files) */
49632@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49633 * proc.c
49634 */
49635 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49636-extern atomic_t cachefiles_lookup_histogram[HZ];
49637-extern atomic_t cachefiles_mkdir_histogram[HZ];
49638-extern atomic_t cachefiles_create_histogram[HZ];
49639+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49640+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49641+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49642
49643 extern int __init cachefiles_proc_init(void);
49644 extern void cachefiles_proc_cleanup(void);
49645 static inline
49646-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49647+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49648 {
49649 unsigned long jif = jiffies - start_jif;
49650 if (jif >= HZ)
49651 jif = HZ - 1;
49652- atomic_inc(&histogram[jif]);
49653+ atomic_inc_unchecked(&histogram[jif]);
49654 }
49655
49656 #else
49657diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49658index 8c01c5fc..15f982e 100644
49659--- a/fs/cachefiles/namei.c
49660+++ b/fs/cachefiles/namei.c
49661@@ -317,7 +317,7 @@ try_again:
49662 /* first step is to make up a grave dentry in the graveyard */
49663 sprintf(nbuffer, "%08x%08x",
49664 (uint32_t) get_seconds(),
49665- (uint32_t) atomic_inc_return(&cache->gravecounter));
49666+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49667
49668 /* do the multiway lock magic */
49669 trap = lock_rename(cache->graveyard, dir);
49670diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49671index eccd339..4c1d995 100644
49672--- a/fs/cachefiles/proc.c
49673+++ b/fs/cachefiles/proc.c
49674@@ -14,9 +14,9 @@
49675 #include <linux/seq_file.h>
49676 #include "internal.h"
49677
49678-atomic_t cachefiles_lookup_histogram[HZ];
49679-atomic_t cachefiles_mkdir_histogram[HZ];
49680-atomic_t cachefiles_create_histogram[HZ];
49681+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49682+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49683+atomic_unchecked_t cachefiles_create_histogram[HZ];
49684
49685 /*
49686 * display the latency histogram
49687@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49688 return 0;
49689 default:
49690 index = (unsigned long) v - 3;
49691- x = atomic_read(&cachefiles_lookup_histogram[index]);
49692- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49693- z = atomic_read(&cachefiles_create_histogram[index]);
49694+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49695+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49696+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49697 if (x == 0 && y == 0 && z == 0)
49698 return 0;
49699
49700diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49701index 4809922..aab2c39 100644
49702--- a/fs/cachefiles/rdwr.c
49703+++ b/fs/cachefiles/rdwr.c
49704@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49705 old_fs = get_fs();
49706 set_fs(KERNEL_DS);
49707 ret = file->f_op->write(
49708- file, (const void __user *) data, len, &pos);
49709+ file, (const void __force_user *) data, len, &pos);
49710 set_fs(old_fs);
49711 kunmap(page);
49712 if (ret != len)
49713diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49714index 6d797f4..0ace2e5 100644
49715--- a/fs/ceph/dir.c
49716+++ b/fs/ceph/dir.c
49717@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49718 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49719 struct ceph_mds_client *mdsc = fsc->mdsc;
49720 unsigned frag = fpos_frag(filp->f_pos);
49721- int off = fpos_off(filp->f_pos);
49722+ unsigned int off = fpos_off(filp->f_pos);
49723 int err;
49724 u32 ftype;
49725 struct ceph_mds_reply_info_parsed *rinfo;
49726diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49727index d9ea6ed..1e6c8ac 100644
49728--- a/fs/cifs/cifs_debug.c
49729+++ b/fs/cifs/cifs_debug.c
49730@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49731
49732 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49733 #ifdef CONFIG_CIFS_STATS2
49734- atomic_set(&totBufAllocCount, 0);
49735- atomic_set(&totSmBufAllocCount, 0);
49736+ atomic_set_unchecked(&totBufAllocCount, 0);
49737+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49738 #endif /* CONFIG_CIFS_STATS2 */
49739 spin_lock(&cifs_tcp_ses_lock);
49740 list_for_each(tmp1, &cifs_tcp_ses_list) {
49741@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49742 tcon = list_entry(tmp3,
49743 struct cifs_tcon,
49744 tcon_list);
49745- atomic_set(&tcon->num_smbs_sent, 0);
49746+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49747 if (server->ops->clear_stats)
49748 server->ops->clear_stats(tcon);
49749 }
49750@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49751 smBufAllocCount.counter, cifs_min_small);
49752 #ifdef CONFIG_CIFS_STATS2
49753 seq_printf(m, "Total Large %d Small %d Allocations\n",
49754- atomic_read(&totBufAllocCount),
49755- atomic_read(&totSmBufAllocCount));
49756+ atomic_read_unchecked(&totBufAllocCount),
49757+ atomic_read_unchecked(&totSmBufAllocCount));
49758 #endif /* CONFIG_CIFS_STATS2 */
49759
49760 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49761@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49762 if (tcon->need_reconnect)
49763 seq_puts(m, "\tDISCONNECTED ");
49764 seq_printf(m, "\nSMBs: %d",
49765- atomic_read(&tcon->num_smbs_sent));
49766+ atomic_read_unchecked(&tcon->num_smbs_sent));
49767 if (server->ops->print_stats)
49768 server->ops->print_stats(m, tcon);
49769 }
49770diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49771index 345fc89..b2acae5 100644
49772--- a/fs/cifs/cifsfs.c
49773+++ b/fs/cifs/cifsfs.c
49774@@ -1033,7 +1033,7 @@ cifs_init_request_bufs(void)
49775 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49776 cifs_req_cachep = kmem_cache_create("cifs_request",
49777 CIFSMaxBufSize + max_hdr_size, 0,
49778- SLAB_HWCACHE_ALIGN, NULL);
49779+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49780 if (cifs_req_cachep == NULL)
49781 return -ENOMEM;
49782
49783@@ -1060,7 +1060,7 @@ cifs_init_request_bufs(void)
49784 efficient to alloc 1 per page off the slab compared to 17K (5page)
49785 alloc of large cifs buffers even when page debugging is on */
49786 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49787- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49788+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49789 NULL);
49790 if (cifs_sm_req_cachep == NULL) {
49791 mempool_destroy(cifs_req_poolp);
49792@@ -1145,8 +1145,8 @@ init_cifs(void)
49793 atomic_set(&bufAllocCount, 0);
49794 atomic_set(&smBufAllocCount, 0);
49795 #ifdef CONFIG_CIFS_STATS2
49796- atomic_set(&totBufAllocCount, 0);
49797- atomic_set(&totSmBufAllocCount, 0);
49798+ atomic_set_unchecked(&totBufAllocCount, 0);
49799+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49800 #endif /* CONFIG_CIFS_STATS2 */
49801
49802 atomic_set(&midCount, 0);
49803diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49804index 4f07f6f..55de8ce 100644
49805--- a/fs/cifs/cifsglob.h
49806+++ b/fs/cifs/cifsglob.h
49807@@ -751,35 +751,35 @@ struct cifs_tcon {
49808 __u16 Flags; /* optional support bits */
49809 enum statusEnum tidStatus;
49810 #ifdef CONFIG_CIFS_STATS
49811- atomic_t num_smbs_sent;
49812+ atomic_unchecked_t num_smbs_sent;
49813 union {
49814 struct {
49815- atomic_t num_writes;
49816- atomic_t num_reads;
49817- atomic_t num_flushes;
49818- atomic_t num_oplock_brks;
49819- atomic_t num_opens;
49820- atomic_t num_closes;
49821- atomic_t num_deletes;
49822- atomic_t num_mkdirs;
49823- atomic_t num_posixopens;
49824- atomic_t num_posixmkdirs;
49825- atomic_t num_rmdirs;
49826- atomic_t num_renames;
49827- atomic_t num_t2renames;
49828- atomic_t num_ffirst;
49829- atomic_t num_fnext;
49830- atomic_t num_fclose;
49831- atomic_t num_hardlinks;
49832- atomic_t num_symlinks;
49833- atomic_t num_locks;
49834- atomic_t num_acl_get;
49835- atomic_t num_acl_set;
49836+ atomic_unchecked_t num_writes;
49837+ atomic_unchecked_t num_reads;
49838+ atomic_unchecked_t num_flushes;
49839+ atomic_unchecked_t num_oplock_brks;
49840+ atomic_unchecked_t num_opens;
49841+ atomic_unchecked_t num_closes;
49842+ atomic_unchecked_t num_deletes;
49843+ atomic_unchecked_t num_mkdirs;
49844+ atomic_unchecked_t num_posixopens;
49845+ atomic_unchecked_t num_posixmkdirs;
49846+ atomic_unchecked_t num_rmdirs;
49847+ atomic_unchecked_t num_renames;
49848+ atomic_unchecked_t num_t2renames;
49849+ atomic_unchecked_t num_ffirst;
49850+ atomic_unchecked_t num_fnext;
49851+ atomic_unchecked_t num_fclose;
49852+ atomic_unchecked_t num_hardlinks;
49853+ atomic_unchecked_t num_symlinks;
49854+ atomic_unchecked_t num_locks;
49855+ atomic_unchecked_t num_acl_get;
49856+ atomic_unchecked_t num_acl_set;
49857 } cifs_stats;
49858 #ifdef CONFIG_CIFS_SMB2
49859 struct {
49860- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49861- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49862+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49863+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49864 } smb2_stats;
49865 #endif /* CONFIG_CIFS_SMB2 */
49866 } stats;
49867@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49868 }
49869
49870 #ifdef CONFIG_CIFS_STATS
49871-#define cifs_stats_inc atomic_inc
49872+#define cifs_stats_inc atomic_inc_unchecked
49873
49874 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49875 unsigned int bytes)
49876@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49877 /* Various Debug counters */
49878 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49879 #ifdef CONFIG_CIFS_STATS2
49880-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49881-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49882+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49883+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49884 #endif
49885 GLOBAL_EXTERN atomic_t smBufAllocCount;
49886 GLOBAL_EXTERN atomic_t midCount;
49887diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49888index 9f6c4c4..8de307a 100644
49889--- a/fs/cifs/link.c
49890+++ b/fs/cifs/link.c
49891@@ -616,7 +616,7 @@ symlink_exit:
49892
49893 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49894 {
49895- char *p = nd_get_link(nd);
49896+ const char *p = nd_get_link(nd);
49897 if (!IS_ERR(p))
49898 kfree(p);
49899 }
49900diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
49901index 1b15bf8..1ce489e 100644
49902--- a/fs/cifs/misc.c
49903+++ b/fs/cifs/misc.c
49904@@ -169,7 +169,7 @@ cifs_buf_get(void)
49905 memset(ret_buf, 0, buf_size + 3);
49906 atomic_inc(&bufAllocCount);
49907 #ifdef CONFIG_CIFS_STATS2
49908- atomic_inc(&totBufAllocCount);
49909+ atomic_inc_unchecked(&totBufAllocCount);
49910 #endif /* CONFIG_CIFS_STATS2 */
49911 }
49912
49913@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
49914 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
49915 atomic_inc(&smBufAllocCount);
49916 #ifdef CONFIG_CIFS_STATS2
49917- atomic_inc(&totSmBufAllocCount);
49918+ atomic_inc_unchecked(&totSmBufAllocCount);
49919 #endif /* CONFIG_CIFS_STATS2 */
49920
49921 }
49922diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
49923index 47bc5a8..10decbe 100644
49924--- a/fs/cifs/smb1ops.c
49925+++ b/fs/cifs/smb1ops.c
49926@@ -586,27 +586,27 @@ static void
49927 cifs_clear_stats(struct cifs_tcon *tcon)
49928 {
49929 #ifdef CONFIG_CIFS_STATS
49930- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
49931- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
49932- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
49933- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49934- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
49935- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
49936- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49937- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
49938- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
49939- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
49940- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
49941- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
49942- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
49943- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
49944- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
49945- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
49946- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
49947- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
49948- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
49949- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
49950- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
49951+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
49952+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
49953+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
49954+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49955+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
49956+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
49957+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49958+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
49959+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
49960+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
49961+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
49962+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
49963+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
49964+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
49965+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
49966+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
49967+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
49968+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
49969+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
49970+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
49971+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
49972 #endif
49973 }
49974
49975@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49976 {
49977 #ifdef CONFIG_CIFS_STATS
49978 seq_printf(m, " Oplocks breaks: %d",
49979- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
49980+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
49981 seq_printf(m, "\nReads: %d Bytes: %llu",
49982- atomic_read(&tcon->stats.cifs_stats.num_reads),
49983+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
49984 (long long)(tcon->bytes_read));
49985 seq_printf(m, "\nWrites: %d Bytes: %llu",
49986- atomic_read(&tcon->stats.cifs_stats.num_writes),
49987+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
49988 (long long)(tcon->bytes_written));
49989 seq_printf(m, "\nFlushes: %d",
49990- atomic_read(&tcon->stats.cifs_stats.num_flushes));
49991+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
49992 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
49993- atomic_read(&tcon->stats.cifs_stats.num_locks),
49994- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
49995- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
49996+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
49997+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
49998+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
49999 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
50000- atomic_read(&tcon->stats.cifs_stats.num_opens),
50001- atomic_read(&tcon->stats.cifs_stats.num_closes),
50002- atomic_read(&tcon->stats.cifs_stats.num_deletes));
50003+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
50004+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
50005+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
50006 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
50007- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
50008- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
50009+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
50010+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
50011 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
50012- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
50013- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
50014+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
50015+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
50016 seq_printf(m, "\nRenames: %d T2 Renames %d",
50017- atomic_read(&tcon->stats.cifs_stats.num_renames),
50018- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
50019+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
50020+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
50021 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
50022- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
50023- atomic_read(&tcon->stats.cifs_stats.num_fnext),
50024- atomic_read(&tcon->stats.cifs_stats.num_fclose));
50025+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
50026+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
50027+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
50028 #endif
50029 }
50030
50031diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
50032index bceffe7..cd1ae59 100644
50033--- a/fs/cifs/smb2ops.c
50034+++ b/fs/cifs/smb2ops.c
50035@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
50036 #ifdef CONFIG_CIFS_STATS
50037 int i;
50038 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
50039- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50040- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50041+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50042+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50043 }
50044 #endif
50045 }
50046@@ -284,66 +284,66 @@ static void
50047 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50048 {
50049 #ifdef CONFIG_CIFS_STATS
50050- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50051- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50052+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50053+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50054 seq_printf(m, "\nNegotiates: %d sent %d failed",
50055- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
50056- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
50057+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
50058+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
50059 seq_printf(m, "\nSessionSetups: %d sent %d failed",
50060- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
50061- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
50062+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
50063+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
50064 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
50065 seq_printf(m, "\nLogoffs: %d sent %d failed",
50066- atomic_read(&sent[SMB2_LOGOFF_HE]),
50067- atomic_read(&failed[SMB2_LOGOFF_HE]));
50068+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
50069+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
50070 seq_printf(m, "\nTreeConnects: %d sent %d failed",
50071- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
50072- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
50073+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
50074+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
50075 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
50076- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
50077- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
50078+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
50079+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
50080 seq_printf(m, "\nCreates: %d sent %d failed",
50081- atomic_read(&sent[SMB2_CREATE_HE]),
50082- atomic_read(&failed[SMB2_CREATE_HE]));
50083+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
50084+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
50085 seq_printf(m, "\nCloses: %d sent %d failed",
50086- atomic_read(&sent[SMB2_CLOSE_HE]),
50087- atomic_read(&failed[SMB2_CLOSE_HE]));
50088+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
50089+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
50090 seq_printf(m, "\nFlushes: %d sent %d failed",
50091- atomic_read(&sent[SMB2_FLUSH_HE]),
50092- atomic_read(&failed[SMB2_FLUSH_HE]));
50093+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
50094+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
50095 seq_printf(m, "\nReads: %d sent %d failed",
50096- atomic_read(&sent[SMB2_READ_HE]),
50097- atomic_read(&failed[SMB2_READ_HE]));
50098+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
50099+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
50100 seq_printf(m, "\nWrites: %d sent %d failed",
50101- atomic_read(&sent[SMB2_WRITE_HE]),
50102- atomic_read(&failed[SMB2_WRITE_HE]));
50103+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
50104+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
50105 seq_printf(m, "\nLocks: %d sent %d failed",
50106- atomic_read(&sent[SMB2_LOCK_HE]),
50107- atomic_read(&failed[SMB2_LOCK_HE]));
50108+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
50109+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
50110 seq_printf(m, "\nIOCTLs: %d sent %d failed",
50111- atomic_read(&sent[SMB2_IOCTL_HE]),
50112- atomic_read(&failed[SMB2_IOCTL_HE]));
50113+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
50114+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
50115 seq_printf(m, "\nCancels: %d sent %d failed",
50116- atomic_read(&sent[SMB2_CANCEL_HE]),
50117- atomic_read(&failed[SMB2_CANCEL_HE]));
50118+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
50119+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
50120 seq_printf(m, "\nEchos: %d sent %d failed",
50121- atomic_read(&sent[SMB2_ECHO_HE]),
50122- atomic_read(&failed[SMB2_ECHO_HE]));
50123+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
50124+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
50125 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
50126- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
50127- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
50128+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
50129+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
50130 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
50131- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
50132- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
50133+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
50134+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
50135 seq_printf(m, "\nQueryInfos: %d sent %d failed",
50136- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
50137- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
50138+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
50139+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
50140 seq_printf(m, "\nSetInfos: %d sent %d failed",
50141- atomic_read(&sent[SMB2_SET_INFO_HE]),
50142- atomic_read(&failed[SMB2_SET_INFO_HE]));
50143+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
50144+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
50145 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
50146- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
50147- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
50148+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
50149+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
50150 #endif
50151 }
50152
50153diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
50154index 41d9d07..dbb4772 100644
50155--- a/fs/cifs/smb2pdu.c
50156+++ b/fs/cifs/smb2pdu.c
50157@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
50158 default:
50159 cERROR(1, "info level %u isn't supported",
50160 srch_inf->info_level);
50161- rc = -EINVAL;
50162- goto qdir_exit;
50163+ return -EINVAL;
50164 }
50165
50166 req->FileIndex = cpu_to_le32(index);
50167diff --git a/fs/coda/cache.c b/fs/coda/cache.c
50168index 1da168c..8bc7ff6 100644
50169--- a/fs/coda/cache.c
50170+++ b/fs/coda/cache.c
50171@@ -24,7 +24,7 @@
50172 #include "coda_linux.h"
50173 #include "coda_cache.h"
50174
50175-static atomic_t permission_epoch = ATOMIC_INIT(0);
50176+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
50177
50178 /* replace or extend an acl cache hit */
50179 void coda_cache_enter(struct inode *inode, int mask)
50180@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
50181 struct coda_inode_info *cii = ITOC(inode);
50182
50183 spin_lock(&cii->c_lock);
50184- cii->c_cached_epoch = atomic_read(&permission_epoch);
50185+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
50186 if (!uid_eq(cii->c_uid, current_fsuid())) {
50187 cii->c_uid = current_fsuid();
50188 cii->c_cached_perm = mask;
50189@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
50190 {
50191 struct coda_inode_info *cii = ITOC(inode);
50192 spin_lock(&cii->c_lock);
50193- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
50194+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
50195 spin_unlock(&cii->c_lock);
50196 }
50197
50198 /* remove all acl caches */
50199 void coda_cache_clear_all(struct super_block *sb)
50200 {
50201- atomic_inc(&permission_epoch);
50202+ atomic_inc_unchecked(&permission_epoch);
50203 }
50204
50205
50206@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
50207 spin_lock(&cii->c_lock);
50208 hit = (mask & cii->c_cached_perm) == mask &&
50209 uid_eq(cii->c_uid, current_fsuid()) &&
50210- cii->c_cached_epoch == atomic_read(&permission_epoch);
50211+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
50212 spin_unlock(&cii->c_lock);
50213
50214 return hit;
50215diff --git a/fs/compat.c b/fs/compat.c
50216index d487985..c9e04b1 100644
50217--- a/fs/compat.c
50218+++ b/fs/compat.c
50219@@ -54,7 +54,7 @@
50220 #include <asm/ioctls.h>
50221 #include "internal.h"
50222
50223-int compat_log = 1;
50224+int compat_log = 0;
50225
50226 int compat_printk(const char *fmt, ...)
50227 {
50228@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
50229
50230 set_fs(KERNEL_DS);
50231 /* The __user pointer cast is valid because of the set_fs() */
50232- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
50233+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
50234 set_fs(oldfs);
50235 /* truncating is ok because it's a user address */
50236 if (!ret)
50237@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
50238 goto out;
50239
50240 ret = -EINVAL;
50241- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
50242+ if (nr_segs > UIO_MAXIOV)
50243 goto out;
50244 if (nr_segs > fast_segs) {
50245 ret = -ENOMEM;
50246@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
50247
50248 struct compat_readdir_callback {
50249 struct compat_old_linux_dirent __user *dirent;
50250+ struct file * file;
50251 int result;
50252 };
50253
50254@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
50255 buf->result = -EOVERFLOW;
50256 return -EOVERFLOW;
50257 }
50258+
50259+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50260+ return 0;
50261+
50262 buf->result++;
50263 dirent = buf->dirent;
50264 if (!access_ok(VERIFY_WRITE, dirent,
50265@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
50266
50267 buf.result = 0;
50268 buf.dirent = dirent;
50269+ buf.file = f.file;
50270
50271 error = vfs_readdir(f.file, compat_fillonedir, &buf);
50272 if (buf.result)
50273@@ -901,6 +907,7 @@ struct compat_linux_dirent {
50274 struct compat_getdents_callback {
50275 struct compat_linux_dirent __user *current_dir;
50276 struct compat_linux_dirent __user *previous;
50277+ struct file * file;
50278 int count;
50279 int error;
50280 };
50281@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
50282 buf->error = -EOVERFLOW;
50283 return -EOVERFLOW;
50284 }
50285+
50286+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50287+ return 0;
50288+
50289 dirent = buf->previous;
50290 if (dirent) {
50291 if (__put_user(offset, &dirent->d_off))
50292@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50293 buf.previous = NULL;
50294 buf.count = count;
50295 buf.error = 0;
50296+ buf.file = f.file;
50297
50298 error = vfs_readdir(f.file, compat_filldir, &buf);
50299 if (error >= 0)
50300@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50301 struct compat_getdents_callback64 {
50302 struct linux_dirent64 __user *current_dir;
50303 struct linux_dirent64 __user *previous;
50304+ struct file * file;
50305 int count;
50306 int error;
50307 };
50308@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
50309 buf->error = -EINVAL; /* only used if we fail.. */
50310 if (reclen > buf->count)
50311 return -EINVAL;
50312+
50313+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50314+ return 0;
50315+
50316 dirent = buf->previous;
50317
50318 if (dirent) {
50319@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
50320 buf.previous = NULL;
50321 buf.count = count;
50322 buf.error = 0;
50323+ buf.file = f.file;
50324
50325 error = vfs_readdir(f.file, compat_filldir64, &buf);
50326 if (error >= 0)
50327 error = buf.error;
50328 lastdirent = buf.previous;
50329 if (lastdirent) {
50330- typeof(lastdirent->d_off) d_off = f.file->f_pos;
50331+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50332 if (__put_user_unaligned(d_off, &lastdirent->d_off))
50333 error = -EFAULT;
50334 else
50335diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
50336index a81147e..20bf2b5 100644
50337--- a/fs/compat_binfmt_elf.c
50338+++ b/fs/compat_binfmt_elf.c
50339@@ -30,11 +30,13 @@
50340 #undef elf_phdr
50341 #undef elf_shdr
50342 #undef elf_note
50343+#undef elf_dyn
50344 #undef elf_addr_t
50345 #define elfhdr elf32_hdr
50346 #define elf_phdr elf32_phdr
50347 #define elf_shdr elf32_shdr
50348 #define elf_note elf32_note
50349+#define elf_dyn Elf32_Dyn
50350 #define elf_addr_t Elf32_Addr
50351
50352 /*
50353diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
50354index 3ced75f..b28d192 100644
50355--- a/fs/compat_ioctl.c
50356+++ b/fs/compat_ioctl.c
50357@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
50358 return -EFAULT;
50359 if (__get_user(udata, &ss32->iomem_base))
50360 return -EFAULT;
50361- ss.iomem_base = compat_ptr(udata);
50362+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
50363 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
50364 __get_user(ss.port_high, &ss32->port_high))
50365 return -EFAULT;
50366@@ -704,8 +704,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
50367 for (i = 0; i < nmsgs; i++) {
50368 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
50369 return -EFAULT;
50370- if (get_user(datap, &umsgs[i].buf) ||
50371- put_user(compat_ptr(datap), &tmsgs[i].buf))
50372+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
50373+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
50374 return -EFAULT;
50375 }
50376 return sys_ioctl(fd, cmd, (unsigned long)tdata);
50377@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
50378 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
50379 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
50380 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
50381- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50382+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50383 return -EFAULT;
50384
50385 return ioctl_preallocate(file, p);
50386@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
50387 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
50388 {
50389 unsigned int a, b;
50390- a = *(unsigned int *)p;
50391- b = *(unsigned int *)q;
50392+ a = *(const unsigned int *)p;
50393+ b = *(const unsigned int *)q;
50394 if (a > b)
50395 return 1;
50396 if (a < b)
50397diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
50398index 7aabc6a..34c1197 100644
50399--- a/fs/configfs/dir.c
50400+++ b/fs/configfs/dir.c
50401@@ -1565,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50402 }
50403 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
50404 struct configfs_dirent *next;
50405- const char * name;
50406+ const unsigned char * name;
50407+ char d_name[sizeof(next->s_dentry->d_iname)];
50408 int len;
50409 struct inode *inode = NULL;
50410
50411@@ -1575,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50412 continue;
50413
50414 name = configfs_get_name(next);
50415- len = strlen(name);
50416+ if (next->s_dentry && name == next->s_dentry->d_iname) {
50417+ len = next->s_dentry->d_name.len;
50418+ memcpy(d_name, name, len);
50419+ name = d_name;
50420+ } else
50421+ len = strlen(name);
50422
50423 /*
50424 * We'll have a dentry and an inode for
50425diff --git a/fs/coredump.c b/fs/coredump.c
50426index c647965..a77bff3 100644
50427--- a/fs/coredump.c
50428+++ b/fs/coredump.c
50429@@ -52,7 +52,7 @@ struct core_name {
50430 char *corename;
50431 int used, size;
50432 };
50433-static atomic_t call_count = ATOMIC_INIT(1);
50434+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
50435
50436 /* The maximal length of core_pattern is also specified in sysctl.c */
50437
50438@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
50439 {
50440 char *old_corename = cn->corename;
50441
50442- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
50443+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
50444 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
50445
50446 if (!cn->corename) {
50447@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
50448 int pid_in_pattern = 0;
50449 int err = 0;
50450
50451- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
50452+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
50453 cn->corename = kmalloc(cn->size, GFP_KERNEL);
50454 cn->used = 0;
50455
50456@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
50457 pipe = file_inode(file)->i_pipe;
50458
50459 pipe_lock(pipe);
50460- pipe->readers++;
50461- pipe->writers--;
50462+ atomic_inc(&pipe->readers);
50463+ atomic_dec(&pipe->writers);
50464
50465- while ((pipe->readers > 1) && (!signal_pending(current))) {
50466+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
50467 wake_up_interruptible_sync(&pipe->wait);
50468 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50469 pipe_wait(pipe);
50470 }
50471
50472- pipe->readers--;
50473- pipe->writers++;
50474+ atomic_dec(&pipe->readers);
50475+ atomic_inc(&pipe->writers);
50476 pipe_unlock(pipe);
50477
50478 }
50479@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
50480 int ispipe;
50481 struct files_struct *displaced;
50482 bool need_nonrelative = false;
50483- static atomic_t core_dump_count = ATOMIC_INIT(0);
50484+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
50485+ long signr = siginfo->si_signo;
50486 struct coredump_params cprm = {
50487 .siginfo = siginfo,
50488 .regs = signal_pt_regs(),
50489@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
50490 .mm_flags = mm->flags,
50491 };
50492
50493- audit_core_dumps(siginfo->si_signo);
50494+ audit_core_dumps(signr);
50495+
50496+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
50497+ gr_handle_brute_attach(cprm.mm_flags);
50498
50499 binfmt = mm->binfmt;
50500 if (!binfmt || !binfmt->core_dump)
50501@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
50502 need_nonrelative = true;
50503 }
50504
50505- retval = coredump_wait(siginfo->si_signo, &core_state);
50506+ retval = coredump_wait(signr, &core_state);
50507 if (retval < 0)
50508 goto fail_creds;
50509
50510@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
50511 }
50512 cprm.limit = RLIM_INFINITY;
50513
50514- dump_count = atomic_inc_return(&core_dump_count);
50515+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
50516 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
50517 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
50518 task_tgid_vnr(current), current->comm);
50519@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
50520 } else {
50521 struct inode *inode;
50522
50523+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
50524+
50525 if (cprm.limit < binfmt->min_coredump)
50526 goto fail_unlock;
50527
50528@@ -640,7 +646,7 @@ close_fail:
50529 filp_close(cprm.file, NULL);
50530 fail_dropcount:
50531 if (ispipe)
50532- atomic_dec(&core_dump_count);
50533+ atomic_dec_unchecked(&core_dump_count);
50534 fail_unlock:
50535 kfree(cn.corename);
50536 fail_corename:
50537@@ -659,7 +665,7 @@ fail:
50538 */
50539 int dump_write(struct file *file, const void *addr, int nr)
50540 {
50541- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
50542+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
50543 }
50544 EXPORT_SYMBOL(dump_write);
50545
50546diff --git a/fs/dcache.c b/fs/dcache.c
50547index e689268..f36956e 100644
50548--- a/fs/dcache.c
50549+++ b/fs/dcache.c
50550@@ -3100,7 +3100,7 @@ void __init vfs_caches_init(unsigned long mempages)
50551 mempages -= reserve;
50552
50553 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50554- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50555+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
50556
50557 dcache_init();
50558 inode_init();
50559diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50560index 4888cb3..e0f7cf8 100644
50561--- a/fs/debugfs/inode.c
50562+++ b/fs/debugfs/inode.c
50563@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50564 */
50565 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50566 {
50567+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50568+ return __create_file(name, S_IFDIR | S_IRWXU,
50569+#else
50570 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50571+#endif
50572 parent, NULL, NULL);
50573 }
50574 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50575diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50576index 5eab400..810a3f5 100644
50577--- a/fs/ecryptfs/inode.c
50578+++ b/fs/ecryptfs/inode.c
50579@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50580 old_fs = get_fs();
50581 set_fs(get_ds());
50582 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50583- (char __user *)lower_buf,
50584+ (char __force_user *)lower_buf,
50585 PATH_MAX);
50586 set_fs(old_fs);
50587 if (rc < 0)
50588@@ -706,7 +706,7 @@ out:
50589 static void
50590 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50591 {
50592- char *buf = nd_get_link(nd);
50593+ const char *buf = nd_get_link(nd);
50594 if (!IS_ERR(buf)) {
50595 /* Free the char* */
50596 kfree(buf);
50597diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50598index e4141f2..d8263e8 100644
50599--- a/fs/ecryptfs/miscdev.c
50600+++ b/fs/ecryptfs/miscdev.c
50601@@ -304,7 +304,7 @@ check_list:
50602 goto out_unlock_msg_ctx;
50603 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50604 if (msg_ctx->msg) {
50605- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50606+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50607 goto out_unlock_msg_ctx;
50608 i += packet_length_size;
50609 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50610diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
50611index 6a16053..2155147 100644
50612--- a/fs/ecryptfs/read_write.c
50613+++ b/fs/ecryptfs/read_write.c
50614@@ -240,7 +240,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
50615 return -EIO;
50616 fs_save = get_fs();
50617 set_fs(get_ds());
50618- rc = vfs_read(lower_file, data, size, &offset);
50619+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
50620 set_fs(fs_save);
50621 return rc;
50622 }
50623diff --git a/fs/exec.c b/fs/exec.c
50624index 0d5c76f..3d4585e 100644
50625--- a/fs/exec.c
50626+++ b/fs/exec.c
50627@@ -55,8 +55,20 @@
50628 #include <linux/pipe_fs_i.h>
50629 #include <linux/oom.h>
50630 #include <linux/compat.h>
50631+#include <linux/random.h>
50632+#include <linux/seq_file.h>
50633+#include <linux/coredump.h>
50634+#include <linux/mman.h>
50635+
50636+#ifdef CONFIG_PAX_REFCOUNT
50637+#include <linux/kallsyms.h>
50638+#include <linux/kdebug.h>
50639+#endif
50640+
50641+#include <trace/events/fs.h>
50642
50643 #include <asm/uaccess.h>
50644+#include <asm/sections.h>
50645 #include <asm/mmu_context.h>
50646 #include <asm/tlb.h>
50647
50648@@ -66,17 +78,32 @@
50649
50650 #include <trace/events/sched.h>
50651
50652+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50653+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50654+{
50655+ 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");
50656+}
50657+#endif
50658+
50659+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50660+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50661+EXPORT_SYMBOL(pax_set_initial_flags_func);
50662+#endif
50663+
50664 int suid_dumpable = 0;
50665
50666 static LIST_HEAD(formats);
50667 static DEFINE_RWLOCK(binfmt_lock);
50668
50669+extern int gr_process_kernel_exec_ban(void);
50670+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
50671+
50672 void __register_binfmt(struct linux_binfmt * fmt, int insert)
50673 {
50674 BUG_ON(!fmt);
50675 write_lock(&binfmt_lock);
50676- insert ? list_add(&fmt->lh, &formats) :
50677- list_add_tail(&fmt->lh, &formats);
50678+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50679+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50680 write_unlock(&binfmt_lock);
50681 }
50682
50683@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
50684 void unregister_binfmt(struct linux_binfmt * fmt)
50685 {
50686 write_lock(&binfmt_lock);
50687- list_del(&fmt->lh);
50688+ pax_list_del((struct list_head *)&fmt->lh);
50689 write_unlock(&binfmt_lock);
50690 }
50691
50692@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50693 int write)
50694 {
50695 struct page *page;
50696- int ret;
50697
50698-#ifdef CONFIG_STACK_GROWSUP
50699- if (write) {
50700- ret = expand_downwards(bprm->vma, pos);
50701- if (ret < 0)
50702- return NULL;
50703- }
50704-#endif
50705- ret = get_user_pages(current, bprm->mm, pos,
50706- 1, write, 1, &page, NULL);
50707- if (ret <= 0)
50708+ if (0 > expand_downwards(bprm->vma, pos))
50709+ return NULL;
50710+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50711 return NULL;
50712
50713 if (write) {
50714@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50715 if (size <= ARG_MAX)
50716 return page;
50717
50718+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50719+ // only allow 512KB for argv+env on suid/sgid binaries
50720+ // to prevent easy ASLR exhaustion
50721+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50722+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50723+ (size > (512 * 1024))) {
50724+ put_page(page);
50725+ return NULL;
50726+ }
50727+#endif
50728+
50729 /*
50730 * Limit to 1/4-th the stack size for the argv+env strings.
50731 * This ensures that:
50732@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50733 vma->vm_end = STACK_TOP_MAX;
50734 vma->vm_start = vma->vm_end - PAGE_SIZE;
50735 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50736+
50737+#ifdef CONFIG_PAX_SEGMEXEC
50738+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50739+#endif
50740+
50741 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50742 INIT_LIST_HEAD(&vma->anon_vma_chain);
50743
50744@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50745 mm->stack_vm = mm->total_vm = 1;
50746 up_write(&mm->mmap_sem);
50747 bprm->p = vma->vm_end - sizeof(void *);
50748+
50749+#ifdef CONFIG_PAX_RANDUSTACK
50750+ if (randomize_va_space)
50751+ bprm->p ^= random32() & ~PAGE_MASK;
50752+#endif
50753+
50754 return 0;
50755 err:
50756 up_write(&mm->mmap_sem);
50757@@ -396,7 +437,7 @@ struct user_arg_ptr {
50758 } ptr;
50759 };
50760
50761-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50762+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50763 {
50764 const char __user *native;
50765
50766@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50767 compat_uptr_t compat;
50768
50769 if (get_user(compat, argv.ptr.compat + nr))
50770- return ERR_PTR(-EFAULT);
50771+ return (const char __force_user *)ERR_PTR(-EFAULT);
50772
50773 return compat_ptr(compat);
50774 }
50775 #endif
50776
50777 if (get_user(native, argv.ptr.native + nr))
50778- return ERR_PTR(-EFAULT);
50779+ return (const char __force_user *)ERR_PTR(-EFAULT);
50780
50781 return native;
50782 }
50783@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
50784 if (!p)
50785 break;
50786
50787- if (IS_ERR(p))
50788+ if (IS_ERR((const char __force_kernel *)p))
50789 return -EFAULT;
50790
50791 if (i >= max)
50792@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50793
50794 ret = -EFAULT;
50795 str = get_user_arg_ptr(argv, argc);
50796- if (IS_ERR(str))
50797+ if (IS_ERR((const char __force_kernel *)str))
50798 goto out;
50799
50800 len = strnlen_user(str, MAX_ARG_STRLEN);
50801@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50802 int r;
50803 mm_segment_t oldfs = get_fs();
50804 struct user_arg_ptr argv = {
50805- .ptr.native = (const char __user *const __user *)__argv,
50806+ .ptr.native = (const char __force_user * const __force_user *)__argv,
50807 };
50808
50809 set_fs(KERNEL_DS);
50810@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50811 unsigned long new_end = old_end - shift;
50812 struct mmu_gather tlb;
50813
50814- BUG_ON(new_start > new_end);
50815+ if (new_start >= new_end || new_start < mmap_min_addr)
50816+ return -ENOMEM;
50817
50818 /*
50819 * ensure there are no vmas between where we want to go
50820@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50821 if (vma != find_vma(mm, new_start))
50822 return -EFAULT;
50823
50824+#ifdef CONFIG_PAX_SEGMEXEC
50825+ BUG_ON(pax_find_mirror_vma(vma));
50826+#endif
50827+
50828 /*
50829 * cover the whole range: [new_start, old_end)
50830 */
50831@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50832 stack_top = arch_align_stack(stack_top);
50833 stack_top = PAGE_ALIGN(stack_top);
50834
50835- if (unlikely(stack_top < mmap_min_addr) ||
50836- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50837- return -ENOMEM;
50838-
50839 stack_shift = vma->vm_end - stack_top;
50840
50841 bprm->p -= stack_shift;
50842@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50843 bprm->exec -= stack_shift;
50844
50845 down_write(&mm->mmap_sem);
50846+
50847+ /* Move stack pages down in memory. */
50848+ if (stack_shift) {
50849+ ret = shift_arg_pages(vma, stack_shift);
50850+ if (ret)
50851+ goto out_unlock;
50852+ }
50853+
50854 vm_flags = VM_STACK_FLAGS;
50855
50856+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50857+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
50858+ vm_flags &= ~VM_EXEC;
50859+
50860+#ifdef CONFIG_PAX_MPROTECT
50861+ if (mm->pax_flags & MF_PAX_MPROTECT)
50862+ vm_flags &= ~VM_MAYEXEC;
50863+#endif
50864+
50865+ }
50866+#endif
50867+
50868 /*
50869 * Adjust stack execute permissions; explicitly enable for
50870 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
50871@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50872 goto out_unlock;
50873 BUG_ON(prev != vma);
50874
50875- /* Move stack pages down in memory. */
50876- if (stack_shift) {
50877- ret = shift_arg_pages(vma, stack_shift);
50878- if (ret)
50879- goto out_unlock;
50880- }
50881-
50882 /* mprotect_fixup is overkill to remove the temporary stack flags */
50883 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
50884
50885@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
50886 #endif
50887 current->mm->start_stack = bprm->p;
50888 ret = expand_stack(vma, stack_base);
50889+
50890+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
50891+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
50892+ unsigned long size;
50893+ vm_flags_t vm_flags;
50894+
50895+ size = STACK_TOP - vma->vm_end;
50896+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
50897+
50898+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
50899+
50900+#ifdef CONFIG_X86
50901+ if (!ret) {
50902+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
50903+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
50904+ }
50905+#endif
50906+
50907+ }
50908+#endif
50909+
50910 if (ret)
50911 ret = -EFAULT;
50912
50913@@ -772,6 +848,8 @@ struct file *open_exec(const char *name)
50914
50915 fsnotify_open(file);
50916
50917+ trace_open_exec(name);
50918+
50919 err = deny_write_access(file);
50920 if (err)
50921 goto exit;
50922@@ -795,7 +873,7 @@ int kernel_read(struct file *file, loff_t offset,
50923 old_fs = get_fs();
50924 set_fs(get_ds());
50925 /* The cast to a user pointer is valid due to the set_fs() */
50926- result = vfs_read(file, (void __user *)addr, count, &pos);
50927+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
50928 set_fs(old_fs);
50929 return result;
50930 }
50931@@ -1252,7 +1330,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
50932 }
50933 rcu_read_unlock();
50934
50935- if (p->fs->users > n_fs) {
50936+ if (atomic_read(&p->fs->users) > n_fs) {
50937 bprm->unsafe |= LSM_UNSAFE_SHARE;
50938 } else {
50939 res = -EAGAIN;
50940@@ -1452,6 +1530,31 @@ int search_binary_handler(struct linux_binprm *bprm)
50941
50942 EXPORT_SYMBOL(search_binary_handler);
50943
50944+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50945+static DEFINE_PER_CPU(u64, exec_counter);
50946+static int __init init_exec_counters(void)
50947+{
50948+ unsigned int cpu;
50949+
50950+ for_each_possible_cpu(cpu) {
50951+ per_cpu(exec_counter, cpu) = (u64)cpu;
50952+ }
50953+
50954+ return 0;
50955+}
50956+early_initcall(init_exec_counters);
50957+static inline void increment_exec_counter(void)
50958+{
50959+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
50960+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
50961+}
50962+#else
50963+static inline void increment_exec_counter(void) {}
50964+#endif
50965+
50966+extern void gr_handle_exec_args(struct linux_binprm *bprm,
50967+ struct user_arg_ptr argv);
50968+
50969 /*
50970 * sys_execve() executes a new program.
50971 */
50972@@ -1459,6 +1562,11 @@ static int do_execve_common(const char *filename,
50973 struct user_arg_ptr argv,
50974 struct user_arg_ptr envp)
50975 {
50976+#ifdef CONFIG_GRKERNSEC
50977+ struct file *old_exec_file;
50978+ struct acl_subject_label *old_acl;
50979+ struct rlimit old_rlim[RLIM_NLIMITS];
50980+#endif
50981 struct linux_binprm *bprm;
50982 struct file *file;
50983 struct files_struct *displaced;
50984@@ -1466,6 +1574,8 @@ static int do_execve_common(const char *filename,
50985 int retval;
50986 const struct cred *cred = current_cred();
50987
50988+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&cred->user->processes), 1);
50989+
50990 /*
50991 * We move the actual failure in case of RLIMIT_NPROC excess from
50992 * set*uid() to execve() because too many poorly written programs
50993@@ -1506,12 +1616,22 @@ static int do_execve_common(const char *filename,
50994 if (IS_ERR(file))
50995 goto out_unmark;
50996
50997+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
50998+ retval = -EPERM;
50999+ goto out_file;
51000+ }
51001+
51002 sched_exec();
51003
51004 bprm->file = file;
51005 bprm->filename = filename;
51006 bprm->interp = filename;
51007
51008+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
51009+ retval = -EACCES;
51010+ goto out_file;
51011+ }
51012+
51013 retval = bprm_mm_init(bprm);
51014 if (retval)
51015 goto out_file;
51016@@ -1528,24 +1648,70 @@ static int do_execve_common(const char *filename,
51017 if (retval < 0)
51018 goto out;
51019
51020+#ifdef CONFIG_GRKERNSEC
51021+ old_acl = current->acl;
51022+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
51023+ old_exec_file = current->exec_file;
51024+ get_file(file);
51025+ current->exec_file = file;
51026+#endif
51027+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51028+ /* limit suid stack to 8MB
51029+ * we saved the old limits above and will restore them if this exec fails
51030+ */
51031+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
51032+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
51033+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
51034+#endif
51035+
51036+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
51037+ retval = -EPERM;
51038+ goto out_fail;
51039+ }
51040+
51041+ if (!gr_tpe_allow(file)) {
51042+ retval = -EACCES;
51043+ goto out_fail;
51044+ }
51045+
51046+ if (gr_check_crash_exec(file)) {
51047+ retval = -EACCES;
51048+ goto out_fail;
51049+ }
51050+
51051+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
51052+ bprm->unsafe);
51053+ if (retval < 0)
51054+ goto out_fail;
51055+
51056 retval = copy_strings_kernel(1, &bprm->filename, bprm);
51057 if (retval < 0)
51058- goto out;
51059+ goto out_fail;
51060
51061 bprm->exec = bprm->p;
51062 retval = copy_strings(bprm->envc, envp, bprm);
51063 if (retval < 0)
51064- goto out;
51065+ goto out_fail;
51066
51067 retval = copy_strings(bprm->argc, argv, bprm);
51068 if (retval < 0)
51069- goto out;
51070+ goto out_fail;
51071+
51072+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
51073+
51074+ gr_handle_exec_args(bprm, argv);
51075
51076 retval = search_binary_handler(bprm);
51077 if (retval < 0)
51078- goto out;
51079+ goto out_fail;
51080+#ifdef CONFIG_GRKERNSEC
51081+ if (old_exec_file)
51082+ fput(old_exec_file);
51083+#endif
51084
51085 /* execve succeeded */
51086+
51087+ increment_exec_counter();
51088 current->fs->in_exec = 0;
51089 current->in_execve = 0;
51090 acct_update_integrals(current);
51091@@ -1554,6 +1720,14 @@ static int do_execve_common(const char *filename,
51092 put_files_struct(displaced);
51093 return retval;
51094
51095+out_fail:
51096+#ifdef CONFIG_GRKERNSEC
51097+ current->acl = old_acl;
51098+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
51099+ fput(current->exec_file);
51100+ current->exec_file = old_exec_file;
51101+#endif
51102+
51103 out:
51104 if (bprm->mm) {
51105 acct_arg_size(bprm, 0);
51106@@ -1702,3 +1876,283 @@ asmlinkage long compat_sys_execve(const char __user * filename,
51107 return error;
51108 }
51109 #endif
51110+
51111+int pax_check_flags(unsigned long *flags)
51112+{
51113+ int retval = 0;
51114+
51115+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
51116+ if (*flags & MF_PAX_SEGMEXEC)
51117+ {
51118+ *flags &= ~MF_PAX_SEGMEXEC;
51119+ retval = -EINVAL;
51120+ }
51121+#endif
51122+
51123+ if ((*flags & MF_PAX_PAGEEXEC)
51124+
51125+#ifdef CONFIG_PAX_PAGEEXEC
51126+ && (*flags & MF_PAX_SEGMEXEC)
51127+#endif
51128+
51129+ )
51130+ {
51131+ *flags &= ~MF_PAX_PAGEEXEC;
51132+ retval = -EINVAL;
51133+ }
51134+
51135+ if ((*flags & MF_PAX_MPROTECT)
51136+
51137+#ifdef CONFIG_PAX_MPROTECT
51138+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51139+#endif
51140+
51141+ )
51142+ {
51143+ *flags &= ~MF_PAX_MPROTECT;
51144+ retval = -EINVAL;
51145+ }
51146+
51147+ if ((*flags & MF_PAX_EMUTRAMP)
51148+
51149+#ifdef CONFIG_PAX_EMUTRAMP
51150+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51151+#endif
51152+
51153+ )
51154+ {
51155+ *flags &= ~MF_PAX_EMUTRAMP;
51156+ retval = -EINVAL;
51157+ }
51158+
51159+ return retval;
51160+}
51161+
51162+EXPORT_SYMBOL(pax_check_flags);
51163+
51164+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51165+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
51166+{
51167+ struct task_struct *tsk = current;
51168+ struct mm_struct *mm = current->mm;
51169+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
51170+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
51171+ char *path_exec = NULL;
51172+ char *path_fault = NULL;
51173+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
51174+ siginfo_t info = { };
51175+
51176+ if (buffer_exec && buffer_fault) {
51177+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
51178+
51179+ down_read(&mm->mmap_sem);
51180+ vma = mm->mmap;
51181+ while (vma && (!vma_exec || !vma_fault)) {
51182+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
51183+ vma_exec = vma;
51184+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
51185+ vma_fault = vma;
51186+ vma = vma->vm_next;
51187+ }
51188+ if (vma_exec) {
51189+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
51190+ if (IS_ERR(path_exec))
51191+ path_exec = "<path too long>";
51192+ else {
51193+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
51194+ if (path_exec) {
51195+ *path_exec = 0;
51196+ path_exec = buffer_exec;
51197+ } else
51198+ path_exec = "<path too long>";
51199+ }
51200+ }
51201+ if (vma_fault) {
51202+ start = vma_fault->vm_start;
51203+ end = vma_fault->vm_end;
51204+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
51205+ if (vma_fault->vm_file) {
51206+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
51207+ if (IS_ERR(path_fault))
51208+ path_fault = "<path too long>";
51209+ else {
51210+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
51211+ if (path_fault) {
51212+ *path_fault = 0;
51213+ path_fault = buffer_fault;
51214+ } else
51215+ path_fault = "<path too long>";
51216+ }
51217+ } else
51218+ path_fault = "<anonymous mapping>";
51219+ }
51220+ up_read(&mm->mmap_sem);
51221+ }
51222+ if (tsk->signal->curr_ip)
51223+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
51224+ else
51225+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
51226+ 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),
51227+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
51228+ free_page((unsigned long)buffer_exec);
51229+ free_page((unsigned long)buffer_fault);
51230+ pax_report_insns(regs, pc, sp);
51231+ info.si_signo = SIGKILL;
51232+ info.si_errno = 0;
51233+ info.si_code = SI_KERNEL;
51234+ info.si_pid = 0;
51235+ info.si_uid = 0;
51236+ do_coredump(&info);
51237+}
51238+#endif
51239+
51240+#ifdef CONFIG_PAX_REFCOUNT
51241+void pax_report_refcount_overflow(struct pt_regs *regs)
51242+{
51243+ if (current->signal->curr_ip)
51244+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
51245+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
51246+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51247+ else
51248+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
51249+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51250+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
51251+ show_regs(regs);
51252+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
51253+}
51254+#endif
51255+
51256+#ifdef CONFIG_PAX_USERCOPY
51257+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
51258+static noinline int check_stack_object(const void *obj, unsigned long len)
51259+{
51260+ const void * const stack = task_stack_page(current);
51261+ const void * const stackend = stack + THREAD_SIZE;
51262+
51263+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51264+ const void *frame = NULL;
51265+ const void *oldframe;
51266+#endif
51267+
51268+ if (obj + len < obj)
51269+ return -1;
51270+
51271+ if (obj + len <= stack || stackend <= obj)
51272+ return 0;
51273+
51274+ if (obj < stack || stackend < obj + len)
51275+ return -1;
51276+
51277+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51278+ oldframe = __builtin_frame_address(1);
51279+ if (oldframe)
51280+ frame = __builtin_frame_address(2);
51281+ /*
51282+ low ----------------------------------------------> high
51283+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
51284+ ^----------------^
51285+ allow copies only within here
51286+ */
51287+ while (stack <= frame && frame < stackend) {
51288+ /* if obj + len extends past the last frame, this
51289+ check won't pass and the next frame will be 0,
51290+ causing us to bail out and correctly report
51291+ the copy as invalid
51292+ */
51293+ if (obj + len <= frame)
51294+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
51295+ oldframe = frame;
51296+ frame = *(const void * const *)frame;
51297+ }
51298+ return -1;
51299+#else
51300+ return 1;
51301+#endif
51302+}
51303+
51304+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
51305+{
51306+ if (current->signal->curr_ip)
51307+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51308+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51309+ else
51310+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51311+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51312+ dump_stack();
51313+ gr_handle_kernel_exploit();
51314+ do_group_exit(SIGKILL);
51315+}
51316+#endif
51317+
51318+#ifdef CONFIG_PAX_USERCOPY
51319+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
51320+{
51321+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
51322+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
51323+#ifdef CONFIG_MODULES
51324+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
51325+#else
51326+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
51327+#endif
51328+
51329+#else
51330+ unsigned long textlow = (unsigned long)_stext;
51331+ unsigned long texthigh = (unsigned long)_etext;
51332+#endif
51333+
51334+ if (high <= textlow || low > texthigh)
51335+ return false;
51336+ else
51337+ return true;
51338+}
51339+#endif
51340+
51341+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
51342+{
51343+
51344+#ifdef CONFIG_PAX_USERCOPY
51345+ const char *type;
51346+
51347+ if (!n)
51348+ return;
51349+
51350+ type = check_heap_object(ptr, n);
51351+ if (!type) {
51352+ int ret = check_stack_object(ptr, n);
51353+ if (ret == 1 || ret == 2)
51354+ return;
51355+ if (ret == 0) {
51356+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
51357+ type = "<kernel text>";
51358+ else
51359+ return;
51360+ } else
51361+ type = "<process stack>";
51362+ }
51363+
51364+ pax_report_usercopy(ptr, n, to_user, type);
51365+#endif
51366+
51367+}
51368+EXPORT_SYMBOL(__check_object_size);
51369+
51370+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
51371+void pax_track_stack(void)
51372+{
51373+ unsigned long sp = (unsigned long)&sp;
51374+ if (sp < current_thread_info()->lowest_stack &&
51375+ sp > (unsigned long)task_stack_page(current))
51376+ current_thread_info()->lowest_stack = sp;
51377+}
51378+EXPORT_SYMBOL(pax_track_stack);
51379+#endif
51380+
51381+#ifdef CONFIG_PAX_SIZE_OVERFLOW
51382+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
51383+{
51384+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
51385+ dump_stack();
51386+ do_group_exit(SIGKILL);
51387+}
51388+EXPORT_SYMBOL(report_size_overflow);
51389+#endif
51390diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
51391index 9f9992b..8b59411 100644
51392--- a/fs/ext2/balloc.c
51393+++ b/fs/ext2/balloc.c
51394@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
51395
51396 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51397 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51398- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51399+ if (free_blocks < root_blocks + 1 &&
51400 !uid_eq(sbi->s_resuid, current_fsuid()) &&
51401 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51402- !in_group_p (sbi->s_resgid))) {
51403+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51404 return 0;
51405 }
51406 return 1;
51407diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
51408index 22548f5..41521d8 100644
51409--- a/fs/ext3/balloc.c
51410+++ b/fs/ext3/balloc.c
51411@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
51412
51413 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51414 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51415- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51416+ if (free_blocks < root_blocks + 1 &&
51417 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
51418 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51419- !in_group_p (sbi->s_resgid))) {
51420+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51421 return 0;
51422 }
51423 return 1;
51424diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
51425index 92e68b3..115d987 100644
51426--- a/fs/ext4/balloc.c
51427+++ b/fs/ext4/balloc.c
51428@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
51429 /* Hm, nope. Are (enough) root reserved clusters available? */
51430 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
51431 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
51432- capable(CAP_SYS_RESOURCE) ||
51433- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
51434+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
51435+ capable_nolog(CAP_SYS_RESOURCE)) {
51436
51437 if (free_clusters >= (nclusters + dirty_clusters))
51438 return 1;
51439diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
51440index 3b83cd6..0f34dcd 100644
51441--- a/fs/ext4/ext4.h
51442+++ b/fs/ext4/ext4.h
51443@@ -1254,19 +1254,19 @@ struct ext4_sb_info {
51444 unsigned long s_mb_last_start;
51445
51446 /* stats for buddy allocator */
51447- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
51448- atomic_t s_bal_success; /* we found long enough chunks */
51449- atomic_t s_bal_allocated; /* in blocks */
51450- atomic_t s_bal_ex_scanned; /* total extents scanned */
51451- atomic_t s_bal_goals; /* goal hits */
51452- atomic_t s_bal_breaks; /* too long searches */
51453- atomic_t s_bal_2orders; /* 2^order hits */
51454+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
51455+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
51456+ atomic_unchecked_t s_bal_allocated; /* in blocks */
51457+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
51458+ atomic_unchecked_t s_bal_goals; /* goal hits */
51459+ atomic_unchecked_t s_bal_breaks; /* too long searches */
51460+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
51461 spinlock_t s_bal_lock;
51462 unsigned long s_mb_buddies_generated;
51463 unsigned long long s_mb_generation_time;
51464- atomic_t s_mb_lost_chunks;
51465- atomic_t s_mb_preallocated;
51466- atomic_t s_mb_discarded;
51467+ atomic_unchecked_t s_mb_lost_chunks;
51468+ atomic_unchecked_t s_mb_preallocated;
51469+ atomic_unchecked_t s_mb_discarded;
51470 atomic_t s_lock_busy;
51471
51472 /* locality groups */
51473diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
51474index f3190ab..84ffb21 100644
51475--- a/fs/ext4/mballoc.c
51476+++ b/fs/ext4/mballoc.c
51477@@ -1754,7 +1754,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
51478 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
51479
51480 if (EXT4_SB(sb)->s_mb_stats)
51481- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
51482+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
51483
51484 break;
51485 }
51486@@ -2059,7 +2059,7 @@ repeat:
51487 ac->ac_status = AC_STATUS_CONTINUE;
51488 ac->ac_flags |= EXT4_MB_HINT_FIRST;
51489 cr = 3;
51490- atomic_inc(&sbi->s_mb_lost_chunks);
51491+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
51492 goto repeat;
51493 }
51494 }
51495@@ -2567,25 +2567,25 @@ int ext4_mb_release(struct super_block *sb)
51496 if (sbi->s_mb_stats) {
51497 ext4_msg(sb, KERN_INFO,
51498 "mballoc: %u blocks %u reqs (%u success)",
51499- atomic_read(&sbi->s_bal_allocated),
51500- atomic_read(&sbi->s_bal_reqs),
51501- atomic_read(&sbi->s_bal_success));
51502+ atomic_read_unchecked(&sbi->s_bal_allocated),
51503+ atomic_read_unchecked(&sbi->s_bal_reqs),
51504+ atomic_read_unchecked(&sbi->s_bal_success));
51505 ext4_msg(sb, KERN_INFO,
51506 "mballoc: %u extents scanned, %u goal hits, "
51507 "%u 2^N hits, %u breaks, %u lost",
51508- atomic_read(&sbi->s_bal_ex_scanned),
51509- atomic_read(&sbi->s_bal_goals),
51510- atomic_read(&sbi->s_bal_2orders),
51511- atomic_read(&sbi->s_bal_breaks),
51512- atomic_read(&sbi->s_mb_lost_chunks));
51513+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
51514+ atomic_read_unchecked(&sbi->s_bal_goals),
51515+ atomic_read_unchecked(&sbi->s_bal_2orders),
51516+ atomic_read_unchecked(&sbi->s_bal_breaks),
51517+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
51518 ext4_msg(sb, KERN_INFO,
51519 "mballoc: %lu generated and it took %Lu",
51520 sbi->s_mb_buddies_generated,
51521 sbi->s_mb_generation_time);
51522 ext4_msg(sb, KERN_INFO,
51523 "mballoc: %u preallocated, %u discarded",
51524- atomic_read(&sbi->s_mb_preallocated),
51525- atomic_read(&sbi->s_mb_discarded));
51526+ atomic_read_unchecked(&sbi->s_mb_preallocated),
51527+ atomic_read_unchecked(&sbi->s_mb_discarded));
51528 }
51529
51530 free_percpu(sbi->s_locality_groups);
51531@@ -3039,16 +3039,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
51532 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
51533
51534 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
51535- atomic_inc(&sbi->s_bal_reqs);
51536- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51537+ atomic_inc_unchecked(&sbi->s_bal_reqs);
51538+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51539 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
51540- atomic_inc(&sbi->s_bal_success);
51541- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
51542+ atomic_inc_unchecked(&sbi->s_bal_success);
51543+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
51544 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
51545 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
51546- atomic_inc(&sbi->s_bal_goals);
51547+ atomic_inc_unchecked(&sbi->s_bal_goals);
51548 if (ac->ac_found > sbi->s_mb_max_to_scan)
51549- atomic_inc(&sbi->s_bal_breaks);
51550+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51551 }
51552
51553 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51554@@ -3448,7 +3448,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51555 trace_ext4_mb_new_inode_pa(ac, pa);
51556
51557 ext4_mb_use_inode_pa(ac, pa);
51558- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51559+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51560
51561 ei = EXT4_I(ac->ac_inode);
51562 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51563@@ -3508,7 +3508,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51564 trace_ext4_mb_new_group_pa(ac, pa);
51565
51566 ext4_mb_use_group_pa(ac, pa);
51567- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51568+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51569
51570 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51571 lg = ac->ac_lg;
51572@@ -3597,7 +3597,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51573 * from the bitmap and continue.
51574 */
51575 }
51576- atomic_add(free, &sbi->s_mb_discarded);
51577+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51578
51579 return err;
51580 }
51581@@ -3615,7 +3615,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51582 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51583 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51584 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51585- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51586+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51587 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51588
51589 return 0;
51590diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
51591index b3b1f7d..cff51d5 100644
51592--- a/fs/ext4/mmp.c
51593+++ b/fs/ext4/mmp.c
51594@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
51595 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
51596 const char *function, unsigned int line, const char *msg)
51597 {
51598- __ext4_warning(sb, function, line, msg);
51599+ __ext4_warning(sb, function, line, "%s", msg);
51600 __ext4_warning(sb, function, line,
51601 "MMP failure info: last update time: %llu, last update "
51602 "node: %s, last update device: %s\n",
51603diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
51604index 3beae6a..8cc5637 100644
51605--- a/fs/ext4/resize.c
51606+++ b/fs/ext4/resize.c
51607@@ -79,12 +79,20 @@ static int verify_group_input(struct super_block *sb,
51608 ext4_fsblk_t end = start + input->blocks_count;
51609 ext4_group_t group = input->group;
51610 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
51611- unsigned overhead = ext4_group_overhead_blocks(sb, group);
51612- ext4_fsblk_t metaend = start + overhead;
51613+ unsigned overhead;
51614+ ext4_fsblk_t metaend;
51615 struct buffer_head *bh = NULL;
51616 ext4_grpblk_t free_blocks_count, offset;
51617 int err = -EINVAL;
51618
51619+ if (group != sbi->s_groups_count) {
51620+ ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51621+ input->group, sbi->s_groups_count);
51622+ return -EINVAL;
51623+ }
51624+
51625+ overhead = ext4_group_overhead_blocks(sb, group);
51626+ metaend = start + overhead;
51627 input->free_blocks_count = free_blocks_count =
51628 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
51629
51630@@ -96,10 +104,7 @@ static int verify_group_input(struct super_block *sb,
51631 free_blocks_count, input->reserved_blocks);
51632
51633 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
51634- if (group != sbi->s_groups_count)
51635- ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51636- input->group, sbi->s_groups_count);
51637- else if (offset != 0)
51638+ if (offset != 0)
51639 ext4_warning(sb, "Last group not full");
51640 else if (input->reserved_blocks > input->blocks_count / 5)
51641 ext4_warning(sb, "Reserved blocks too high (%u)",
51642diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51643index febbe0e..d0cdc02 100644
51644--- a/fs/ext4/super.c
51645+++ b/fs/ext4/super.c
51646@@ -1238,7 +1238,7 @@ static ext4_fsblk_t get_sb_block(void **data)
51647 }
51648
51649 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
51650-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
51651+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
51652 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
51653
51654 #ifdef CONFIG_QUOTA
51655@@ -2380,7 +2380,7 @@ struct ext4_attr {
51656 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51657 const char *, size_t);
51658 int offset;
51659-};
51660+} __do_const;
51661
51662 static int parse_strtoul(const char *buf,
51663 unsigned long max, unsigned long *value)
51664diff --git a/fs/fcntl.c b/fs/fcntl.c
51665index 6599222..e7bf0de 100644
51666--- a/fs/fcntl.c
51667+++ b/fs/fcntl.c
51668@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51669 if (err)
51670 return err;
51671
51672+ if (gr_handle_chroot_fowner(pid, type))
51673+ return -ENOENT;
51674+ if (gr_check_protected_task_fowner(pid, type))
51675+ return -EACCES;
51676+
51677 f_modown(filp, pid, type, force);
51678 return 0;
51679 }
51680diff --git a/fs/fhandle.c b/fs/fhandle.c
51681index 999ff5c..41f4109 100644
51682--- a/fs/fhandle.c
51683+++ b/fs/fhandle.c
51684@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51685 } else
51686 retval = 0;
51687 /* copy the mount id */
51688- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51689- sizeof(*mnt_id)) ||
51690+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51691 copy_to_user(ufh, handle,
51692 sizeof(struct file_handle) + handle_bytes))
51693 retval = -EFAULT;
51694diff --git a/fs/fifo.c b/fs/fifo.c
51695index cf6f434..3d7942c 100644
51696--- a/fs/fifo.c
51697+++ b/fs/fifo.c
51698@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
51699 */
51700 filp->f_op = &read_pipefifo_fops;
51701 pipe->r_counter++;
51702- if (pipe->readers++ == 0)
51703+ if (atomic_inc_return(&pipe->readers) == 1)
51704 wake_up_partner(inode);
51705
51706- if (!pipe->writers) {
51707+ if (!atomic_read(&pipe->writers)) {
51708 if ((filp->f_flags & O_NONBLOCK)) {
51709 /* suppress POLLHUP until we have
51710 * seen a writer */
51711@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
51712 * errno=ENXIO when there is no process reading the FIFO.
51713 */
51714 ret = -ENXIO;
51715- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
51716+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
51717 goto err;
51718
51719 filp->f_op = &write_pipefifo_fops;
51720 pipe->w_counter++;
51721- if (!pipe->writers++)
51722+ if (atomic_inc_return(&pipe->writers) == 1)
51723 wake_up_partner(inode);
51724
51725- if (!pipe->readers) {
51726+ if (!atomic_read(&pipe->readers)) {
51727 if (wait_for_partner(inode, &pipe->r_counter))
51728 goto err_wr;
51729 }
51730@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
51731 */
51732 filp->f_op = &rdwr_pipefifo_fops;
51733
51734- pipe->readers++;
51735- pipe->writers++;
51736+ atomic_inc(&pipe->readers);
51737+ atomic_inc(&pipe->writers);
51738 pipe->r_counter++;
51739 pipe->w_counter++;
51740- if (pipe->readers == 1 || pipe->writers == 1)
51741+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
51742 wake_up_partner(inode);
51743 break;
51744
51745@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
51746 return 0;
51747
51748 err_rd:
51749- if (!--pipe->readers)
51750+ if (atomic_dec_and_test(&pipe->readers))
51751 wake_up_interruptible(&pipe->wait);
51752 ret = -ERESTARTSYS;
51753 goto err;
51754
51755 err_wr:
51756- if (!--pipe->writers)
51757+ if (atomic_dec_and_test(&pipe->writers))
51758 wake_up_interruptible(&pipe->wait);
51759 ret = -ERESTARTSYS;
51760 goto err;
51761
51762 err:
51763- if (!pipe->readers && !pipe->writers)
51764+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
51765 free_pipe_info(inode);
51766
51767 err_nocleanup:
51768diff --git a/fs/file.c b/fs/file.c
51769index 3906d95..5fe379b 100644
51770--- a/fs/file.c
51771+++ b/fs/file.c
51772@@ -16,6 +16,7 @@
51773 #include <linux/slab.h>
51774 #include <linux/vmalloc.h>
51775 #include <linux/file.h>
51776+#include <linux/security.h>
51777 #include <linux/fdtable.h>
51778 #include <linux/bitops.h>
51779 #include <linux/interrupt.h>
51780@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51781 if (!file)
51782 return __close_fd(files, fd);
51783
51784+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51785 if (fd >= rlimit(RLIMIT_NOFILE))
51786 return -EBADF;
51787
51788@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51789 if (unlikely(oldfd == newfd))
51790 return -EINVAL;
51791
51792+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51793 if (newfd >= rlimit(RLIMIT_NOFILE))
51794 return -EBADF;
51795
51796@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51797 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51798 {
51799 int err;
51800+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51801 if (from >= rlimit(RLIMIT_NOFILE))
51802 return -EINVAL;
51803 err = alloc_fd(from, flags);
51804diff --git a/fs/filesystems.c b/fs/filesystems.c
51805index 92567d9..fcd8cbf 100644
51806--- a/fs/filesystems.c
51807+++ b/fs/filesystems.c
51808@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
51809 int len = dot ? dot - name : strlen(name);
51810
51811 fs = __get_fs_type(name, len);
51812+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51813+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
51814+#else
51815 if (!fs && (request_module("fs-%.*s", len, name) == 0))
51816+#endif
51817 fs = __get_fs_type(name, len);
51818
51819 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51820diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51821index d8ac61d..79a36f0 100644
51822--- a/fs/fs_struct.c
51823+++ b/fs/fs_struct.c
51824@@ -4,6 +4,7 @@
51825 #include <linux/path.h>
51826 #include <linux/slab.h>
51827 #include <linux/fs_struct.h>
51828+#include <linux/grsecurity.h>
51829 #include "internal.h"
51830
51831 /*
51832@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
51833 write_seqcount_begin(&fs->seq);
51834 old_root = fs->root;
51835 fs->root = *path;
51836+ gr_set_chroot_entries(current, path);
51837 write_seqcount_end(&fs->seq);
51838 spin_unlock(&fs->lock);
51839 if (old_root.dentry)
51840@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
51841 int hits = 0;
51842 spin_lock(&fs->lock);
51843 write_seqcount_begin(&fs->seq);
51844+ /* this root replacement is only done by pivot_root,
51845+ leave grsec's chroot tagging alone for this task
51846+ so that a pivoted root isn't treated as a chroot
51847+ */
51848 hits += replace_path(&fs->root, old_root, new_root);
51849 hits += replace_path(&fs->pwd, old_root, new_root);
51850 write_seqcount_end(&fs->seq);
51851@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
51852 task_lock(tsk);
51853 spin_lock(&fs->lock);
51854 tsk->fs = NULL;
51855- kill = !--fs->users;
51856+ gr_clear_chroot_entries(tsk);
51857+ kill = !atomic_dec_return(&fs->users);
51858 spin_unlock(&fs->lock);
51859 task_unlock(tsk);
51860 if (kill)
51861@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51862 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51863 /* We don't need to lock fs - think why ;-) */
51864 if (fs) {
51865- fs->users = 1;
51866+ atomic_set(&fs->users, 1);
51867 fs->in_exec = 0;
51868 spin_lock_init(&fs->lock);
51869 seqcount_init(&fs->seq);
51870@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51871 spin_lock(&old->lock);
51872 fs->root = old->root;
51873 path_get(&fs->root);
51874+ /* instead of calling gr_set_chroot_entries here,
51875+ we call it from every caller of this function
51876+ */
51877 fs->pwd = old->pwd;
51878 path_get(&fs->pwd);
51879 spin_unlock(&old->lock);
51880@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
51881
51882 task_lock(current);
51883 spin_lock(&fs->lock);
51884- kill = !--fs->users;
51885+ kill = !atomic_dec_return(&fs->users);
51886 current->fs = new_fs;
51887+ gr_set_chroot_entries(current, &new_fs->root);
51888 spin_unlock(&fs->lock);
51889 task_unlock(current);
51890
51891@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
51892
51893 int current_umask(void)
51894 {
51895- return current->fs->umask;
51896+ return current->fs->umask | gr_acl_umask();
51897 }
51898 EXPORT_SYMBOL(current_umask);
51899
51900 /* to be mentioned only in INIT_TASK */
51901 struct fs_struct init_fs = {
51902- .users = 1,
51903+ .users = ATOMIC_INIT(1),
51904 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
51905 .seq = SEQCNT_ZERO,
51906 .umask = 0022,
51907diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
51908index e2cba1f..17a25bb 100644
51909--- a/fs/fscache/cookie.c
51910+++ b/fs/fscache/cookie.c
51911@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
51912 parent ? (char *) parent->def->name : "<no-parent>",
51913 def->name, netfs_data);
51914
51915- fscache_stat(&fscache_n_acquires);
51916+ fscache_stat_unchecked(&fscache_n_acquires);
51917
51918 /* if there's no parent cookie, then we don't create one here either */
51919 if (!parent) {
51920- fscache_stat(&fscache_n_acquires_null);
51921+ fscache_stat_unchecked(&fscache_n_acquires_null);
51922 _leave(" [no parent]");
51923 return NULL;
51924 }
51925@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
51926 /* allocate and initialise a cookie */
51927 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
51928 if (!cookie) {
51929- fscache_stat(&fscache_n_acquires_oom);
51930+ fscache_stat_unchecked(&fscache_n_acquires_oom);
51931 _leave(" [ENOMEM]");
51932 return NULL;
51933 }
51934@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51935
51936 switch (cookie->def->type) {
51937 case FSCACHE_COOKIE_TYPE_INDEX:
51938- fscache_stat(&fscache_n_cookie_index);
51939+ fscache_stat_unchecked(&fscache_n_cookie_index);
51940 break;
51941 case FSCACHE_COOKIE_TYPE_DATAFILE:
51942- fscache_stat(&fscache_n_cookie_data);
51943+ fscache_stat_unchecked(&fscache_n_cookie_data);
51944 break;
51945 default:
51946- fscache_stat(&fscache_n_cookie_special);
51947+ fscache_stat_unchecked(&fscache_n_cookie_special);
51948 break;
51949 }
51950
51951@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51952 if (fscache_acquire_non_index_cookie(cookie) < 0) {
51953 atomic_dec(&parent->n_children);
51954 __fscache_cookie_put(cookie);
51955- fscache_stat(&fscache_n_acquires_nobufs);
51956+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
51957 _leave(" = NULL");
51958 return NULL;
51959 }
51960 }
51961
51962- fscache_stat(&fscache_n_acquires_ok);
51963+ fscache_stat_unchecked(&fscache_n_acquires_ok);
51964 _leave(" = %p", cookie);
51965 return cookie;
51966 }
51967@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
51968 cache = fscache_select_cache_for_object(cookie->parent);
51969 if (!cache) {
51970 up_read(&fscache_addremove_sem);
51971- fscache_stat(&fscache_n_acquires_no_cache);
51972+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
51973 _leave(" = -ENOMEDIUM [no cache]");
51974 return -ENOMEDIUM;
51975 }
51976@@ -255,12 +255,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
51977 object = cache->ops->alloc_object(cache, cookie);
51978 fscache_stat_d(&fscache_n_cop_alloc_object);
51979 if (IS_ERR(object)) {
51980- fscache_stat(&fscache_n_object_no_alloc);
51981+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
51982 ret = PTR_ERR(object);
51983 goto error;
51984 }
51985
51986- fscache_stat(&fscache_n_object_alloc);
51987+ fscache_stat_unchecked(&fscache_n_object_alloc);
51988
51989 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
51990
51991@@ -376,7 +376,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
51992
51993 _enter("{%s}", cookie->def->name);
51994
51995- fscache_stat(&fscache_n_invalidates);
51996+ fscache_stat_unchecked(&fscache_n_invalidates);
51997
51998 /* Only permit invalidation of data files. Invalidating an index will
51999 * require the caller to release all its attachments to the tree rooted
52000@@ -434,10 +434,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
52001 {
52002 struct fscache_object *object;
52003
52004- fscache_stat(&fscache_n_updates);
52005+ fscache_stat_unchecked(&fscache_n_updates);
52006
52007 if (!cookie) {
52008- fscache_stat(&fscache_n_updates_null);
52009+ fscache_stat_unchecked(&fscache_n_updates_null);
52010 _leave(" [no cookie]");
52011 return;
52012 }
52013@@ -471,12 +471,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52014 struct fscache_object *object;
52015 unsigned long event;
52016
52017- fscache_stat(&fscache_n_relinquishes);
52018+ fscache_stat_unchecked(&fscache_n_relinquishes);
52019 if (retire)
52020- fscache_stat(&fscache_n_relinquishes_retire);
52021+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
52022
52023 if (!cookie) {
52024- fscache_stat(&fscache_n_relinquishes_null);
52025+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
52026 _leave(" [no cookie]");
52027 return;
52028 }
52029@@ -492,7 +492,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52030
52031 /* wait for the cookie to finish being instantiated (or to fail) */
52032 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
52033- fscache_stat(&fscache_n_relinquishes_waitcrt);
52034+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
52035 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
52036 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
52037 }
52038diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
52039index ee38fef..0a326d4 100644
52040--- a/fs/fscache/internal.h
52041+++ b/fs/fscache/internal.h
52042@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
52043 * stats.c
52044 */
52045 #ifdef CONFIG_FSCACHE_STATS
52046-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52047-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52048+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52049+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52050
52051-extern atomic_t fscache_n_op_pend;
52052-extern atomic_t fscache_n_op_run;
52053-extern atomic_t fscache_n_op_enqueue;
52054-extern atomic_t fscache_n_op_deferred_release;
52055-extern atomic_t fscache_n_op_release;
52056-extern atomic_t fscache_n_op_gc;
52057-extern atomic_t fscache_n_op_cancelled;
52058-extern atomic_t fscache_n_op_rejected;
52059+extern atomic_unchecked_t fscache_n_op_pend;
52060+extern atomic_unchecked_t fscache_n_op_run;
52061+extern atomic_unchecked_t fscache_n_op_enqueue;
52062+extern atomic_unchecked_t fscache_n_op_deferred_release;
52063+extern atomic_unchecked_t fscache_n_op_release;
52064+extern atomic_unchecked_t fscache_n_op_gc;
52065+extern atomic_unchecked_t fscache_n_op_cancelled;
52066+extern atomic_unchecked_t fscache_n_op_rejected;
52067
52068-extern atomic_t fscache_n_attr_changed;
52069-extern atomic_t fscache_n_attr_changed_ok;
52070-extern atomic_t fscache_n_attr_changed_nobufs;
52071-extern atomic_t fscache_n_attr_changed_nomem;
52072-extern atomic_t fscache_n_attr_changed_calls;
52073+extern atomic_unchecked_t fscache_n_attr_changed;
52074+extern atomic_unchecked_t fscache_n_attr_changed_ok;
52075+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
52076+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
52077+extern atomic_unchecked_t fscache_n_attr_changed_calls;
52078
52079-extern atomic_t fscache_n_allocs;
52080-extern atomic_t fscache_n_allocs_ok;
52081-extern atomic_t fscache_n_allocs_wait;
52082-extern atomic_t fscache_n_allocs_nobufs;
52083-extern atomic_t fscache_n_allocs_intr;
52084-extern atomic_t fscache_n_allocs_object_dead;
52085-extern atomic_t fscache_n_alloc_ops;
52086-extern atomic_t fscache_n_alloc_op_waits;
52087+extern atomic_unchecked_t fscache_n_allocs;
52088+extern atomic_unchecked_t fscache_n_allocs_ok;
52089+extern atomic_unchecked_t fscache_n_allocs_wait;
52090+extern atomic_unchecked_t fscache_n_allocs_nobufs;
52091+extern atomic_unchecked_t fscache_n_allocs_intr;
52092+extern atomic_unchecked_t fscache_n_allocs_object_dead;
52093+extern atomic_unchecked_t fscache_n_alloc_ops;
52094+extern atomic_unchecked_t fscache_n_alloc_op_waits;
52095
52096-extern atomic_t fscache_n_retrievals;
52097-extern atomic_t fscache_n_retrievals_ok;
52098-extern atomic_t fscache_n_retrievals_wait;
52099-extern atomic_t fscache_n_retrievals_nodata;
52100-extern atomic_t fscache_n_retrievals_nobufs;
52101-extern atomic_t fscache_n_retrievals_intr;
52102-extern atomic_t fscache_n_retrievals_nomem;
52103-extern atomic_t fscache_n_retrievals_object_dead;
52104-extern atomic_t fscache_n_retrieval_ops;
52105-extern atomic_t fscache_n_retrieval_op_waits;
52106+extern atomic_unchecked_t fscache_n_retrievals;
52107+extern atomic_unchecked_t fscache_n_retrievals_ok;
52108+extern atomic_unchecked_t fscache_n_retrievals_wait;
52109+extern atomic_unchecked_t fscache_n_retrievals_nodata;
52110+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
52111+extern atomic_unchecked_t fscache_n_retrievals_intr;
52112+extern atomic_unchecked_t fscache_n_retrievals_nomem;
52113+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
52114+extern atomic_unchecked_t fscache_n_retrieval_ops;
52115+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
52116
52117-extern atomic_t fscache_n_stores;
52118-extern atomic_t fscache_n_stores_ok;
52119-extern atomic_t fscache_n_stores_again;
52120-extern atomic_t fscache_n_stores_nobufs;
52121-extern atomic_t fscache_n_stores_oom;
52122-extern atomic_t fscache_n_store_ops;
52123-extern atomic_t fscache_n_store_calls;
52124-extern atomic_t fscache_n_store_pages;
52125-extern atomic_t fscache_n_store_radix_deletes;
52126-extern atomic_t fscache_n_store_pages_over_limit;
52127+extern atomic_unchecked_t fscache_n_stores;
52128+extern atomic_unchecked_t fscache_n_stores_ok;
52129+extern atomic_unchecked_t fscache_n_stores_again;
52130+extern atomic_unchecked_t fscache_n_stores_nobufs;
52131+extern atomic_unchecked_t fscache_n_stores_oom;
52132+extern atomic_unchecked_t fscache_n_store_ops;
52133+extern atomic_unchecked_t fscache_n_store_calls;
52134+extern atomic_unchecked_t fscache_n_store_pages;
52135+extern atomic_unchecked_t fscache_n_store_radix_deletes;
52136+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
52137
52138-extern atomic_t fscache_n_store_vmscan_not_storing;
52139-extern atomic_t fscache_n_store_vmscan_gone;
52140-extern atomic_t fscache_n_store_vmscan_busy;
52141-extern atomic_t fscache_n_store_vmscan_cancelled;
52142-extern atomic_t fscache_n_store_vmscan_wait;
52143+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52144+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
52145+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
52146+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52147+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
52148
52149-extern atomic_t fscache_n_marks;
52150-extern atomic_t fscache_n_uncaches;
52151+extern atomic_unchecked_t fscache_n_marks;
52152+extern atomic_unchecked_t fscache_n_uncaches;
52153
52154-extern atomic_t fscache_n_acquires;
52155-extern atomic_t fscache_n_acquires_null;
52156-extern atomic_t fscache_n_acquires_no_cache;
52157-extern atomic_t fscache_n_acquires_ok;
52158-extern atomic_t fscache_n_acquires_nobufs;
52159-extern atomic_t fscache_n_acquires_oom;
52160+extern atomic_unchecked_t fscache_n_acquires;
52161+extern atomic_unchecked_t fscache_n_acquires_null;
52162+extern atomic_unchecked_t fscache_n_acquires_no_cache;
52163+extern atomic_unchecked_t fscache_n_acquires_ok;
52164+extern atomic_unchecked_t fscache_n_acquires_nobufs;
52165+extern atomic_unchecked_t fscache_n_acquires_oom;
52166
52167-extern atomic_t fscache_n_invalidates;
52168-extern atomic_t fscache_n_invalidates_run;
52169+extern atomic_unchecked_t fscache_n_invalidates;
52170+extern atomic_unchecked_t fscache_n_invalidates_run;
52171
52172-extern atomic_t fscache_n_updates;
52173-extern atomic_t fscache_n_updates_null;
52174-extern atomic_t fscache_n_updates_run;
52175+extern atomic_unchecked_t fscache_n_updates;
52176+extern atomic_unchecked_t fscache_n_updates_null;
52177+extern atomic_unchecked_t fscache_n_updates_run;
52178
52179-extern atomic_t fscache_n_relinquishes;
52180-extern atomic_t fscache_n_relinquishes_null;
52181-extern atomic_t fscache_n_relinquishes_waitcrt;
52182-extern atomic_t fscache_n_relinquishes_retire;
52183+extern atomic_unchecked_t fscache_n_relinquishes;
52184+extern atomic_unchecked_t fscache_n_relinquishes_null;
52185+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52186+extern atomic_unchecked_t fscache_n_relinquishes_retire;
52187
52188-extern atomic_t fscache_n_cookie_index;
52189-extern atomic_t fscache_n_cookie_data;
52190-extern atomic_t fscache_n_cookie_special;
52191+extern atomic_unchecked_t fscache_n_cookie_index;
52192+extern atomic_unchecked_t fscache_n_cookie_data;
52193+extern atomic_unchecked_t fscache_n_cookie_special;
52194
52195-extern atomic_t fscache_n_object_alloc;
52196-extern atomic_t fscache_n_object_no_alloc;
52197-extern atomic_t fscache_n_object_lookups;
52198-extern atomic_t fscache_n_object_lookups_negative;
52199-extern atomic_t fscache_n_object_lookups_positive;
52200-extern atomic_t fscache_n_object_lookups_timed_out;
52201-extern atomic_t fscache_n_object_created;
52202-extern atomic_t fscache_n_object_avail;
52203-extern atomic_t fscache_n_object_dead;
52204+extern atomic_unchecked_t fscache_n_object_alloc;
52205+extern atomic_unchecked_t fscache_n_object_no_alloc;
52206+extern atomic_unchecked_t fscache_n_object_lookups;
52207+extern atomic_unchecked_t fscache_n_object_lookups_negative;
52208+extern atomic_unchecked_t fscache_n_object_lookups_positive;
52209+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
52210+extern atomic_unchecked_t fscache_n_object_created;
52211+extern atomic_unchecked_t fscache_n_object_avail;
52212+extern atomic_unchecked_t fscache_n_object_dead;
52213
52214-extern atomic_t fscache_n_checkaux_none;
52215-extern atomic_t fscache_n_checkaux_okay;
52216-extern atomic_t fscache_n_checkaux_update;
52217-extern atomic_t fscache_n_checkaux_obsolete;
52218+extern atomic_unchecked_t fscache_n_checkaux_none;
52219+extern atomic_unchecked_t fscache_n_checkaux_okay;
52220+extern atomic_unchecked_t fscache_n_checkaux_update;
52221+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
52222
52223 extern atomic_t fscache_n_cop_alloc_object;
52224 extern atomic_t fscache_n_cop_lookup_object;
52225@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
52226 atomic_inc(stat);
52227 }
52228
52229+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
52230+{
52231+ atomic_inc_unchecked(stat);
52232+}
52233+
52234 static inline void fscache_stat_d(atomic_t *stat)
52235 {
52236 atomic_dec(stat);
52237@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
52238
52239 #define __fscache_stat(stat) (NULL)
52240 #define fscache_stat(stat) do {} while (0)
52241+#define fscache_stat_unchecked(stat) do {} while (0)
52242 #define fscache_stat_d(stat) do {} while (0)
52243 #endif
52244
52245diff --git a/fs/fscache/object.c b/fs/fscache/object.c
52246index 50d41c1..10ee117 100644
52247--- a/fs/fscache/object.c
52248+++ b/fs/fscache/object.c
52249@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52250 /* Invalidate an object on disk */
52251 case FSCACHE_OBJECT_INVALIDATING:
52252 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
52253- fscache_stat(&fscache_n_invalidates_run);
52254+ fscache_stat_unchecked(&fscache_n_invalidates_run);
52255 fscache_stat(&fscache_n_cop_invalidate_object);
52256 fscache_invalidate_object(object);
52257 fscache_stat_d(&fscache_n_cop_invalidate_object);
52258@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52259 /* update the object metadata on disk */
52260 case FSCACHE_OBJECT_UPDATING:
52261 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
52262- fscache_stat(&fscache_n_updates_run);
52263+ fscache_stat_unchecked(&fscache_n_updates_run);
52264 fscache_stat(&fscache_n_cop_update_object);
52265 object->cache->ops->update_object(object);
52266 fscache_stat_d(&fscache_n_cop_update_object);
52267@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52268 spin_lock(&object->lock);
52269 object->state = FSCACHE_OBJECT_DEAD;
52270 spin_unlock(&object->lock);
52271- fscache_stat(&fscache_n_object_dead);
52272+ fscache_stat_unchecked(&fscache_n_object_dead);
52273 goto terminal_transit;
52274
52275 /* handle the parent cache of this object being withdrawn from
52276@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52277 spin_lock(&object->lock);
52278 object->state = FSCACHE_OBJECT_DEAD;
52279 spin_unlock(&object->lock);
52280- fscache_stat(&fscache_n_object_dead);
52281+ fscache_stat_unchecked(&fscache_n_object_dead);
52282 goto terminal_transit;
52283
52284 /* complain about the object being woken up once it is
52285@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52286 parent->cookie->def->name, cookie->def->name,
52287 object->cache->tag->name);
52288
52289- fscache_stat(&fscache_n_object_lookups);
52290+ fscache_stat_unchecked(&fscache_n_object_lookups);
52291 fscache_stat(&fscache_n_cop_lookup_object);
52292 ret = object->cache->ops->lookup_object(object);
52293 fscache_stat_d(&fscache_n_cop_lookup_object);
52294@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52295 if (ret == -ETIMEDOUT) {
52296 /* probably stuck behind another object, so move this one to
52297 * the back of the queue */
52298- fscache_stat(&fscache_n_object_lookups_timed_out);
52299+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
52300 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52301 }
52302
52303@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
52304
52305 spin_lock(&object->lock);
52306 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52307- fscache_stat(&fscache_n_object_lookups_negative);
52308+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
52309
52310 /* transit here to allow write requests to begin stacking up
52311 * and read requests to begin returning ENODATA */
52312@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
52313 * result, in which case there may be data available */
52314 spin_lock(&object->lock);
52315 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52316- fscache_stat(&fscache_n_object_lookups_positive);
52317+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
52318
52319 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
52320
52321@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
52322 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52323 } else {
52324 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
52325- fscache_stat(&fscache_n_object_created);
52326+ fscache_stat_unchecked(&fscache_n_object_created);
52327
52328 object->state = FSCACHE_OBJECT_AVAILABLE;
52329 spin_unlock(&object->lock);
52330@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
52331 fscache_enqueue_dependents(object);
52332
52333 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
52334- fscache_stat(&fscache_n_object_avail);
52335+ fscache_stat_unchecked(&fscache_n_object_avail);
52336
52337 _leave("");
52338 }
52339@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52340 enum fscache_checkaux result;
52341
52342 if (!object->cookie->def->check_aux) {
52343- fscache_stat(&fscache_n_checkaux_none);
52344+ fscache_stat_unchecked(&fscache_n_checkaux_none);
52345 return FSCACHE_CHECKAUX_OKAY;
52346 }
52347
52348@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52349 switch (result) {
52350 /* entry okay as is */
52351 case FSCACHE_CHECKAUX_OKAY:
52352- fscache_stat(&fscache_n_checkaux_okay);
52353+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
52354 break;
52355
52356 /* entry requires update */
52357 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
52358- fscache_stat(&fscache_n_checkaux_update);
52359+ fscache_stat_unchecked(&fscache_n_checkaux_update);
52360 break;
52361
52362 /* entry requires deletion */
52363 case FSCACHE_CHECKAUX_OBSOLETE:
52364- fscache_stat(&fscache_n_checkaux_obsolete);
52365+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
52366 break;
52367
52368 default:
52369diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
52370index 762a9ec..2023284 100644
52371--- a/fs/fscache/operation.c
52372+++ b/fs/fscache/operation.c
52373@@ -17,7 +17,7 @@
52374 #include <linux/slab.h>
52375 #include "internal.h"
52376
52377-atomic_t fscache_op_debug_id;
52378+atomic_unchecked_t fscache_op_debug_id;
52379 EXPORT_SYMBOL(fscache_op_debug_id);
52380
52381 /**
52382@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
52383 ASSERTCMP(atomic_read(&op->usage), >, 0);
52384 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
52385
52386- fscache_stat(&fscache_n_op_enqueue);
52387+ fscache_stat_unchecked(&fscache_n_op_enqueue);
52388 switch (op->flags & FSCACHE_OP_TYPE) {
52389 case FSCACHE_OP_ASYNC:
52390 _debug("queue async");
52391@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
52392 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
52393 if (op->processor)
52394 fscache_enqueue_operation(op);
52395- fscache_stat(&fscache_n_op_run);
52396+ fscache_stat_unchecked(&fscache_n_op_run);
52397 }
52398
52399 /*
52400@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52401 if (object->n_in_progress > 0) {
52402 atomic_inc(&op->usage);
52403 list_add_tail(&op->pend_link, &object->pending_ops);
52404- fscache_stat(&fscache_n_op_pend);
52405+ fscache_stat_unchecked(&fscache_n_op_pend);
52406 } else if (!list_empty(&object->pending_ops)) {
52407 atomic_inc(&op->usage);
52408 list_add_tail(&op->pend_link, &object->pending_ops);
52409- fscache_stat(&fscache_n_op_pend);
52410+ fscache_stat_unchecked(&fscache_n_op_pend);
52411 fscache_start_operations(object);
52412 } else {
52413 ASSERTCMP(object->n_in_progress, ==, 0);
52414@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52415 object->n_exclusive++; /* reads and writes must wait */
52416 atomic_inc(&op->usage);
52417 list_add_tail(&op->pend_link, &object->pending_ops);
52418- fscache_stat(&fscache_n_op_pend);
52419+ fscache_stat_unchecked(&fscache_n_op_pend);
52420 ret = 0;
52421 } else {
52422 /* If we're in any other state, there must have been an I/O
52423@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
52424 if (object->n_exclusive > 0) {
52425 atomic_inc(&op->usage);
52426 list_add_tail(&op->pend_link, &object->pending_ops);
52427- fscache_stat(&fscache_n_op_pend);
52428+ fscache_stat_unchecked(&fscache_n_op_pend);
52429 } else if (!list_empty(&object->pending_ops)) {
52430 atomic_inc(&op->usage);
52431 list_add_tail(&op->pend_link, &object->pending_ops);
52432- fscache_stat(&fscache_n_op_pend);
52433+ fscache_stat_unchecked(&fscache_n_op_pend);
52434 fscache_start_operations(object);
52435 } else {
52436 ASSERTCMP(object->n_exclusive, ==, 0);
52437@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
52438 object->n_ops++;
52439 atomic_inc(&op->usage);
52440 list_add_tail(&op->pend_link, &object->pending_ops);
52441- fscache_stat(&fscache_n_op_pend);
52442+ fscache_stat_unchecked(&fscache_n_op_pend);
52443 ret = 0;
52444 } else if (object->state == FSCACHE_OBJECT_DYING ||
52445 object->state == FSCACHE_OBJECT_LC_DYING ||
52446 object->state == FSCACHE_OBJECT_WITHDRAWING) {
52447- fscache_stat(&fscache_n_op_rejected);
52448+ fscache_stat_unchecked(&fscache_n_op_rejected);
52449 op->state = FSCACHE_OP_ST_CANCELLED;
52450 ret = -ENOBUFS;
52451 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
52452@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
52453 ret = -EBUSY;
52454 if (op->state == FSCACHE_OP_ST_PENDING) {
52455 ASSERT(!list_empty(&op->pend_link));
52456- fscache_stat(&fscache_n_op_cancelled);
52457+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52458 list_del_init(&op->pend_link);
52459 if (do_cancel)
52460 do_cancel(op);
52461@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
52462 while (!list_empty(&object->pending_ops)) {
52463 op = list_entry(object->pending_ops.next,
52464 struct fscache_operation, pend_link);
52465- fscache_stat(&fscache_n_op_cancelled);
52466+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52467 list_del_init(&op->pend_link);
52468
52469 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
52470@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
52471 op->state, ==, FSCACHE_OP_ST_CANCELLED);
52472 op->state = FSCACHE_OP_ST_DEAD;
52473
52474- fscache_stat(&fscache_n_op_release);
52475+ fscache_stat_unchecked(&fscache_n_op_release);
52476
52477 if (op->release) {
52478 op->release(op);
52479@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
52480 * lock, and defer it otherwise */
52481 if (!spin_trylock(&object->lock)) {
52482 _debug("defer put");
52483- fscache_stat(&fscache_n_op_deferred_release);
52484+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
52485
52486 cache = object->cache;
52487 spin_lock(&cache->op_gc_list_lock);
52488@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
52489
52490 _debug("GC DEFERRED REL OBJ%x OP%x",
52491 object->debug_id, op->debug_id);
52492- fscache_stat(&fscache_n_op_gc);
52493+ fscache_stat_unchecked(&fscache_n_op_gc);
52494
52495 ASSERTCMP(atomic_read(&op->usage), ==, 0);
52496 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
52497diff --git a/fs/fscache/page.c b/fs/fscache/page.c
52498index ff000e5..c44ec6d 100644
52499--- a/fs/fscache/page.c
52500+++ b/fs/fscache/page.c
52501@@ -61,7 +61,7 @@ try_again:
52502 val = radix_tree_lookup(&cookie->stores, page->index);
52503 if (!val) {
52504 rcu_read_unlock();
52505- fscache_stat(&fscache_n_store_vmscan_not_storing);
52506+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
52507 __fscache_uncache_page(cookie, page);
52508 return true;
52509 }
52510@@ -91,11 +91,11 @@ try_again:
52511 spin_unlock(&cookie->stores_lock);
52512
52513 if (xpage) {
52514- fscache_stat(&fscache_n_store_vmscan_cancelled);
52515- fscache_stat(&fscache_n_store_radix_deletes);
52516+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
52517+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52518 ASSERTCMP(xpage, ==, page);
52519 } else {
52520- fscache_stat(&fscache_n_store_vmscan_gone);
52521+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
52522 }
52523
52524 wake_up_bit(&cookie->flags, 0);
52525@@ -110,11 +110,11 @@ page_busy:
52526 * sleeping on memory allocation, so we may need to impose a timeout
52527 * too. */
52528 if (!(gfp & __GFP_WAIT)) {
52529- fscache_stat(&fscache_n_store_vmscan_busy);
52530+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
52531 return false;
52532 }
52533
52534- fscache_stat(&fscache_n_store_vmscan_wait);
52535+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
52536 __fscache_wait_on_page_write(cookie, page);
52537 gfp &= ~__GFP_WAIT;
52538 goto try_again;
52539@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
52540 FSCACHE_COOKIE_STORING_TAG);
52541 if (!radix_tree_tag_get(&cookie->stores, page->index,
52542 FSCACHE_COOKIE_PENDING_TAG)) {
52543- fscache_stat(&fscache_n_store_radix_deletes);
52544+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52545 xpage = radix_tree_delete(&cookie->stores, page->index);
52546 }
52547 spin_unlock(&cookie->stores_lock);
52548@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
52549
52550 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
52551
52552- fscache_stat(&fscache_n_attr_changed_calls);
52553+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
52554
52555 if (fscache_object_is_active(object)) {
52556 fscache_stat(&fscache_n_cop_attr_changed);
52557@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52558
52559 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52560
52561- fscache_stat(&fscache_n_attr_changed);
52562+ fscache_stat_unchecked(&fscache_n_attr_changed);
52563
52564 op = kzalloc(sizeof(*op), GFP_KERNEL);
52565 if (!op) {
52566- fscache_stat(&fscache_n_attr_changed_nomem);
52567+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
52568 _leave(" = -ENOMEM");
52569 return -ENOMEM;
52570 }
52571@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52572 if (fscache_submit_exclusive_op(object, op) < 0)
52573 goto nobufs;
52574 spin_unlock(&cookie->lock);
52575- fscache_stat(&fscache_n_attr_changed_ok);
52576+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
52577 fscache_put_operation(op);
52578 _leave(" = 0");
52579 return 0;
52580@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52581 nobufs:
52582 spin_unlock(&cookie->lock);
52583 kfree(op);
52584- fscache_stat(&fscache_n_attr_changed_nobufs);
52585+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
52586 _leave(" = %d", -ENOBUFS);
52587 return -ENOBUFS;
52588 }
52589@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52590 /* allocate a retrieval operation and attempt to submit it */
52591 op = kzalloc(sizeof(*op), GFP_NOIO);
52592 if (!op) {
52593- fscache_stat(&fscache_n_retrievals_nomem);
52594+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52595 return NULL;
52596 }
52597
52598@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52599 return 0;
52600 }
52601
52602- fscache_stat(&fscache_n_retrievals_wait);
52603+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52604
52605 jif = jiffies;
52606 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52607 fscache_wait_bit_interruptible,
52608 TASK_INTERRUPTIBLE) != 0) {
52609- fscache_stat(&fscache_n_retrievals_intr);
52610+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52611 _leave(" = -ERESTARTSYS");
52612 return -ERESTARTSYS;
52613 }
52614@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52615 */
52616 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52617 struct fscache_retrieval *op,
52618- atomic_t *stat_op_waits,
52619- atomic_t *stat_object_dead)
52620+ atomic_unchecked_t *stat_op_waits,
52621+ atomic_unchecked_t *stat_object_dead)
52622 {
52623 int ret;
52624
52625@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52626 goto check_if_dead;
52627
52628 _debug(">>> WT");
52629- fscache_stat(stat_op_waits);
52630+ fscache_stat_unchecked(stat_op_waits);
52631 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52632 fscache_wait_bit_interruptible,
52633 TASK_INTERRUPTIBLE) != 0) {
52634@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52635
52636 check_if_dead:
52637 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52638- fscache_stat(stat_object_dead);
52639+ fscache_stat_unchecked(stat_object_dead);
52640 _leave(" = -ENOBUFS [cancelled]");
52641 return -ENOBUFS;
52642 }
52643 if (unlikely(fscache_object_is_dead(object))) {
52644 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52645 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52646- fscache_stat(stat_object_dead);
52647+ fscache_stat_unchecked(stat_object_dead);
52648 return -ENOBUFS;
52649 }
52650 return 0;
52651@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52652
52653 _enter("%p,%p,,,", cookie, page);
52654
52655- fscache_stat(&fscache_n_retrievals);
52656+ fscache_stat_unchecked(&fscache_n_retrievals);
52657
52658 if (hlist_empty(&cookie->backing_objects))
52659 goto nobufs;
52660@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52661 goto nobufs_unlock_dec;
52662 spin_unlock(&cookie->lock);
52663
52664- fscache_stat(&fscache_n_retrieval_ops);
52665+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52666
52667 /* pin the netfs read context in case we need to do the actual netfs
52668 * read because we've encountered a cache read failure */
52669@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52670
52671 error:
52672 if (ret == -ENOMEM)
52673- fscache_stat(&fscache_n_retrievals_nomem);
52674+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52675 else if (ret == -ERESTARTSYS)
52676- fscache_stat(&fscache_n_retrievals_intr);
52677+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52678 else if (ret == -ENODATA)
52679- fscache_stat(&fscache_n_retrievals_nodata);
52680+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52681 else if (ret < 0)
52682- fscache_stat(&fscache_n_retrievals_nobufs);
52683+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52684 else
52685- fscache_stat(&fscache_n_retrievals_ok);
52686+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52687
52688 fscache_put_retrieval(op);
52689 _leave(" = %d", ret);
52690@@ -467,7 +467,7 @@ nobufs_unlock:
52691 spin_unlock(&cookie->lock);
52692 kfree(op);
52693 nobufs:
52694- fscache_stat(&fscache_n_retrievals_nobufs);
52695+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52696 _leave(" = -ENOBUFS");
52697 return -ENOBUFS;
52698 }
52699@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52700
52701 _enter("%p,,%d,,,", cookie, *nr_pages);
52702
52703- fscache_stat(&fscache_n_retrievals);
52704+ fscache_stat_unchecked(&fscache_n_retrievals);
52705
52706 if (hlist_empty(&cookie->backing_objects))
52707 goto nobufs;
52708@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52709 goto nobufs_unlock_dec;
52710 spin_unlock(&cookie->lock);
52711
52712- fscache_stat(&fscache_n_retrieval_ops);
52713+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52714
52715 /* pin the netfs read context in case we need to do the actual netfs
52716 * read because we've encountered a cache read failure */
52717@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52718
52719 error:
52720 if (ret == -ENOMEM)
52721- fscache_stat(&fscache_n_retrievals_nomem);
52722+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52723 else if (ret == -ERESTARTSYS)
52724- fscache_stat(&fscache_n_retrievals_intr);
52725+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52726 else if (ret == -ENODATA)
52727- fscache_stat(&fscache_n_retrievals_nodata);
52728+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52729 else if (ret < 0)
52730- fscache_stat(&fscache_n_retrievals_nobufs);
52731+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52732 else
52733- fscache_stat(&fscache_n_retrievals_ok);
52734+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52735
52736 fscache_put_retrieval(op);
52737 _leave(" = %d", ret);
52738@@ -591,7 +591,7 @@ nobufs_unlock:
52739 spin_unlock(&cookie->lock);
52740 kfree(op);
52741 nobufs:
52742- fscache_stat(&fscache_n_retrievals_nobufs);
52743+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52744 _leave(" = -ENOBUFS");
52745 return -ENOBUFS;
52746 }
52747@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52748
52749 _enter("%p,%p,,,", cookie, page);
52750
52751- fscache_stat(&fscache_n_allocs);
52752+ fscache_stat_unchecked(&fscache_n_allocs);
52753
52754 if (hlist_empty(&cookie->backing_objects))
52755 goto nobufs;
52756@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52757 goto nobufs_unlock;
52758 spin_unlock(&cookie->lock);
52759
52760- fscache_stat(&fscache_n_alloc_ops);
52761+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52762
52763 ret = fscache_wait_for_retrieval_activation(
52764 object, op,
52765@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52766
52767 error:
52768 if (ret == -ERESTARTSYS)
52769- fscache_stat(&fscache_n_allocs_intr);
52770+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52771 else if (ret < 0)
52772- fscache_stat(&fscache_n_allocs_nobufs);
52773+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52774 else
52775- fscache_stat(&fscache_n_allocs_ok);
52776+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52777
52778 fscache_put_retrieval(op);
52779 _leave(" = %d", ret);
52780@@ -677,7 +677,7 @@ nobufs_unlock:
52781 spin_unlock(&cookie->lock);
52782 kfree(op);
52783 nobufs:
52784- fscache_stat(&fscache_n_allocs_nobufs);
52785+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52786 _leave(" = -ENOBUFS");
52787 return -ENOBUFS;
52788 }
52789@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52790
52791 spin_lock(&cookie->stores_lock);
52792
52793- fscache_stat(&fscache_n_store_calls);
52794+ fscache_stat_unchecked(&fscache_n_store_calls);
52795
52796 /* find a page to store */
52797 page = NULL;
52798@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52799 page = results[0];
52800 _debug("gang %d [%lx]", n, page->index);
52801 if (page->index > op->store_limit) {
52802- fscache_stat(&fscache_n_store_pages_over_limit);
52803+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52804 goto superseded;
52805 }
52806
52807@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52808 spin_unlock(&cookie->stores_lock);
52809 spin_unlock(&object->lock);
52810
52811- fscache_stat(&fscache_n_store_pages);
52812+ fscache_stat_unchecked(&fscache_n_store_pages);
52813 fscache_stat(&fscache_n_cop_write_page);
52814 ret = object->cache->ops->write_page(op, page);
52815 fscache_stat_d(&fscache_n_cop_write_page);
52816@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52817 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52818 ASSERT(PageFsCache(page));
52819
52820- fscache_stat(&fscache_n_stores);
52821+ fscache_stat_unchecked(&fscache_n_stores);
52822
52823 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52824 _leave(" = -ENOBUFS [invalidating]");
52825@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52826 spin_unlock(&cookie->stores_lock);
52827 spin_unlock(&object->lock);
52828
52829- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52830+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52831 op->store_limit = object->store_limit;
52832
52833 if (fscache_submit_op(object, &op->op) < 0)
52834@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52835
52836 spin_unlock(&cookie->lock);
52837 radix_tree_preload_end();
52838- fscache_stat(&fscache_n_store_ops);
52839- fscache_stat(&fscache_n_stores_ok);
52840+ fscache_stat_unchecked(&fscache_n_store_ops);
52841+ fscache_stat_unchecked(&fscache_n_stores_ok);
52842
52843 /* the work queue now carries its own ref on the object */
52844 fscache_put_operation(&op->op);
52845@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52846 return 0;
52847
52848 already_queued:
52849- fscache_stat(&fscache_n_stores_again);
52850+ fscache_stat_unchecked(&fscache_n_stores_again);
52851 already_pending:
52852 spin_unlock(&cookie->stores_lock);
52853 spin_unlock(&object->lock);
52854 spin_unlock(&cookie->lock);
52855 radix_tree_preload_end();
52856 kfree(op);
52857- fscache_stat(&fscache_n_stores_ok);
52858+ fscache_stat_unchecked(&fscache_n_stores_ok);
52859 _leave(" = 0");
52860 return 0;
52861
52862@@ -959,14 +959,14 @@ nobufs:
52863 spin_unlock(&cookie->lock);
52864 radix_tree_preload_end();
52865 kfree(op);
52866- fscache_stat(&fscache_n_stores_nobufs);
52867+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52868 _leave(" = -ENOBUFS");
52869 return -ENOBUFS;
52870
52871 nomem_free:
52872 kfree(op);
52873 nomem:
52874- fscache_stat(&fscache_n_stores_oom);
52875+ fscache_stat_unchecked(&fscache_n_stores_oom);
52876 _leave(" = -ENOMEM");
52877 return -ENOMEM;
52878 }
52879@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52880 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52881 ASSERTCMP(page, !=, NULL);
52882
52883- fscache_stat(&fscache_n_uncaches);
52884+ fscache_stat_unchecked(&fscache_n_uncaches);
52885
52886 /* cache withdrawal may beat us to it */
52887 if (!PageFsCache(page))
52888@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52889 struct fscache_cookie *cookie = op->op.object->cookie;
52890
52891 #ifdef CONFIG_FSCACHE_STATS
52892- atomic_inc(&fscache_n_marks);
52893+ atomic_inc_unchecked(&fscache_n_marks);
52894 #endif
52895
52896 _debug("- mark %p{%lx}", page, page->index);
52897diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
52898index 40d13c7..ddf52b9 100644
52899--- a/fs/fscache/stats.c
52900+++ b/fs/fscache/stats.c
52901@@ -18,99 +18,99 @@
52902 /*
52903 * operation counters
52904 */
52905-atomic_t fscache_n_op_pend;
52906-atomic_t fscache_n_op_run;
52907-atomic_t fscache_n_op_enqueue;
52908-atomic_t fscache_n_op_requeue;
52909-atomic_t fscache_n_op_deferred_release;
52910-atomic_t fscache_n_op_release;
52911-atomic_t fscache_n_op_gc;
52912-atomic_t fscache_n_op_cancelled;
52913-atomic_t fscache_n_op_rejected;
52914+atomic_unchecked_t fscache_n_op_pend;
52915+atomic_unchecked_t fscache_n_op_run;
52916+atomic_unchecked_t fscache_n_op_enqueue;
52917+atomic_unchecked_t fscache_n_op_requeue;
52918+atomic_unchecked_t fscache_n_op_deferred_release;
52919+atomic_unchecked_t fscache_n_op_release;
52920+atomic_unchecked_t fscache_n_op_gc;
52921+atomic_unchecked_t fscache_n_op_cancelled;
52922+atomic_unchecked_t fscache_n_op_rejected;
52923
52924-atomic_t fscache_n_attr_changed;
52925-atomic_t fscache_n_attr_changed_ok;
52926-atomic_t fscache_n_attr_changed_nobufs;
52927-atomic_t fscache_n_attr_changed_nomem;
52928-atomic_t fscache_n_attr_changed_calls;
52929+atomic_unchecked_t fscache_n_attr_changed;
52930+atomic_unchecked_t fscache_n_attr_changed_ok;
52931+atomic_unchecked_t fscache_n_attr_changed_nobufs;
52932+atomic_unchecked_t fscache_n_attr_changed_nomem;
52933+atomic_unchecked_t fscache_n_attr_changed_calls;
52934
52935-atomic_t fscache_n_allocs;
52936-atomic_t fscache_n_allocs_ok;
52937-atomic_t fscache_n_allocs_wait;
52938-atomic_t fscache_n_allocs_nobufs;
52939-atomic_t fscache_n_allocs_intr;
52940-atomic_t fscache_n_allocs_object_dead;
52941-atomic_t fscache_n_alloc_ops;
52942-atomic_t fscache_n_alloc_op_waits;
52943+atomic_unchecked_t fscache_n_allocs;
52944+atomic_unchecked_t fscache_n_allocs_ok;
52945+atomic_unchecked_t fscache_n_allocs_wait;
52946+atomic_unchecked_t fscache_n_allocs_nobufs;
52947+atomic_unchecked_t fscache_n_allocs_intr;
52948+atomic_unchecked_t fscache_n_allocs_object_dead;
52949+atomic_unchecked_t fscache_n_alloc_ops;
52950+atomic_unchecked_t fscache_n_alloc_op_waits;
52951
52952-atomic_t fscache_n_retrievals;
52953-atomic_t fscache_n_retrievals_ok;
52954-atomic_t fscache_n_retrievals_wait;
52955-atomic_t fscache_n_retrievals_nodata;
52956-atomic_t fscache_n_retrievals_nobufs;
52957-atomic_t fscache_n_retrievals_intr;
52958-atomic_t fscache_n_retrievals_nomem;
52959-atomic_t fscache_n_retrievals_object_dead;
52960-atomic_t fscache_n_retrieval_ops;
52961-atomic_t fscache_n_retrieval_op_waits;
52962+atomic_unchecked_t fscache_n_retrievals;
52963+atomic_unchecked_t fscache_n_retrievals_ok;
52964+atomic_unchecked_t fscache_n_retrievals_wait;
52965+atomic_unchecked_t fscache_n_retrievals_nodata;
52966+atomic_unchecked_t fscache_n_retrievals_nobufs;
52967+atomic_unchecked_t fscache_n_retrievals_intr;
52968+atomic_unchecked_t fscache_n_retrievals_nomem;
52969+atomic_unchecked_t fscache_n_retrievals_object_dead;
52970+atomic_unchecked_t fscache_n_retrieval_ops;
52971+atomic_unchecked_t fscache_n_retrieval_op_waits;
52972
52973-atomic_t fscache_n_stores;
52974-atomic_t fscache_n_stores_ok;
52975-atomic_t fscache_n_stores_again;
52976-atomic_t fscache_n_stores_nobufs;
52977-atomic_t fscache_n_stores_oom;
52978-atomic_t fscache_n_store_ops;
52979-atomic_t fscache_n_store_calls;
52980-atomic_t fscache_n_store_pages;
52981-atomic_t fscache_n_store_radix_deletes;
52982-atomic_t fscache_n_store_pages_over_limit;
52983+atomic_unchecked_t fscache_n_stores;
52984+atomic_unchecked_t fscache_n_stores_ok;
52985+atomic_unchecked_t fscache_n_stores_again;
52986+atomic_unchecked_t fscache_n_stores_nobufs;
52987+atomic_unchecked_t fscache_n_stores_oom;
52988+atomic_unchecked_t fscache_n_store_ops;
52989+atomic_unchecked_t fscache_n_store_calls;
52990+atomic_unchecked_t fscache_n_store_pages;
52991+atomic_unchecked_t fscache_n_store_radix_deletes;
52992+atomic_unchecked_t fscache_n_store_pages_over_limit;
52993
52994-atomic_t fscache_n_store_vmscan_not_storing;
52995-atomic_t fscache_n_store_vmscan_gone;
52996-atomic_t fscache_n_store_vmscan_busy;
52997-atomic_t fscache_n_store_vmscan_cancelled;
52998-atomic_t fscache_n_store_vmscan_wait;
52999+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
53000+atomic_unchecked_t fscache_n_store_vmscan_gone;
53001+atomic_unchecked_t fscache_n_store_vmscan_busy;
53002+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
53003+atomic_unchecked_t fscache_n_store_vmscan_wait;
53004
53005-atomic_t fscache_n_marks;
53006-atomic_t fscache_n_uncaches;
53007+atomic_unchecked_t fscache_n_marks;
53008+atomic_unchecked_t fscache_n_uncaches;
53009
53010-atomic_t fscache_n_acquires;
53011-atomic_t fscache_n_acquires_null;
53012-atomic_t fscache_n_acquires_no_cache;
53013-atomic_t fscache_n_acquires_ok;
53014-atomic_t fscache_n_acquires_nobufs;
53015-atomic_t fscache_n_acquires_oom;
53016+atomic_unchecked_t fscache_n_acquires;
53017+atomic_unchecked_t fscache_n_acquires_null;
53018+atomic_unchecked_t fscache_n_acquires_no_cache;
53019+atomic_unchecked_t fscache_n_acquires_ok;
53020+atomic_unchecked_t fscache_n_acquires_nobufs;
53021+atomic_unchecked_t fscache_n_acquires_oom;
53022
53023-atomic_t fscache_n_invalidates;
53024-atomic_t fscache_n_invalidates_run;
53025+atomic_unchecked_t fscache_n_invalidates;
53026+atomic_unchecked_t fscache_n_invalidates_run;
53027
53028-atomic_t fscache_n_updates;
53029-atomic_t fscache_n_updates_null;
53030-atomic_t fscache_n_updates_run;
53031+atomic_unchecked_t fscache_n_updates;
53032+atomic_unchecked_t fscache_n_updates_null;
53033+atomic_unchecked_t fscache_n_updates_run;
53034
53035-atomic_t fscache_n_relinquishes;
53036-atomic_t fscache_n_relinquishes_null;
53037-atomic_t fscache_n_relinquishes_waitcrt;
53038-atomic_t fscache_n_relinquishes_retire;
53039+atomic_unchecked_t fscache_n_relinquishes;
53040+atomic_unchecked_t fscache_n_relinquishes_null;
53041+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
53042+atomic_unchecked_t fscache_n_relinquishes_retire;
53043
53044-atomic_t fscache_n_cookie_index;
53045-atomic_t fscache_n_cookie_data;
53046-atomic_t fscache_n_cookie_special;
53047+atomic_unchecked_t fscache_n_cookie_index;
53048+atomic_unchecked_t fscache_n_cookie_data;
53049+atomic_unchecked_t fscache_n_cookie_special;
53050
53051-atomic_t fscache_n_object_alloc;
53052-atomic_t fscache_n_object_no_alloc;
53053-atomic_t fscache_n_object_lookups;
53054-atomic_t fscache_n_object_lookups_negative;
53055-atomic_t fscache_n_object_lookups_positive;
53056-atomic_t fscache_n_object_lookups_timed_out;
53057-atomic_t fscache_n_object_created;
53058-atomic_t fscache_n_object_avail;
53059-atomic_t fscache_n_object_dead;
53060+atomic_unchecked_t fscache_n_object_alloc;
53061+atomic_unchecked_t fscache_n_object_no_alloc;
53062+atomic_unchecked_t fscache_n_object_lookups;
53063+atomic_unchecked_t fscache_n_object_lookups_negative;
53064+atomic_unchecked_t fscache_n_object_lookups_positive;
53065+atomic_unchecked_t fscache_n_object_lookups_timed_out;
53066+atomic_unchecked_t fscache_n_object_created;
53067+atomic_unchecked_t fscache_n_object_avail;
53068+atomic_unchecked_t fscache_n_object_dead;
53069
53070-atomic_t fscache_n_checkaux_none;
53071-atomic_t fscache_n_checkaux_okay;
53072-atomic_t fscache_n_checkaux_update;
53073-atomic_t fscache_n_checkaux_obsolete;
53074+atomic_unchecked_t fscache_n_checkaux_none;
53075+atomic_unchecked_t fscache_n_checkaux_okay;
53076+atomic_unchecked_t fscache_n_checkaux_update;
53077+atomic_unchecked_t fscache_n_checkaux_obsolete;
53078
53079 atomic_t fscache_n_cop_alloc_object;
53080 atomic_t fscache_n_cop_lookup_object;
53081@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
53082 seq_puts(m, "FS-Cache statistics\n");
53083
53084 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
53085- atomic_read(&fscache_n_cookie_index),
53086- atomic_read(&fscache_n_cookie_data),
53087- atomic_read(&fscache_n_cookie_special));
53088+ atomic_read_unchecked(&fscache_n_cookie_index),
53089+ atomic_read_unchecked(&fscache_n_cookie_data),
53090+ atomic_read_unchecked(&fscache_n_cookie_special));
53091
53092 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
53093- atomic_read(&fscache_n_object_alloc),
53094- atomic_read(&fscache_n_object_no_alloc),
53095- atomic_read(&fscache_n_object_avail),
53096- atomic_read(&fscache_n_object_dead));
53097+ atomic_read_unchecked(&fscache_n_object_alloc),
53098+ atomic_read_unchecked(&fscache_n_object_no_alloc),
53099+ atomic_read_unchecked(&fscache_n_object_avail),
53100+ atomic_read_unchecked(&fscache_n_object_dead));
53101 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
53102- atomic_read(&fscache_n_checkaux_none),
53103- atomic_read(&fscache_n_checkaux_okay),
53104- atomic_read(&fscache_n_checkaux_update),
53105- atomic_read(&fscache_n_checkaux_obsolete));
53106+ atomic_read_unchecked(&fscache_n_checkaux_none),
53107+ atomic_read_unchecked(&fscache_n_checkaux_okay),
53108+ atomic_read_unchecked(&fscache_n_checkaux_update),
53109+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
53110
53111 seq_printf(m, "Pages : mrk=%u unc=%u\n",
53112- atomic_read(&fscache_n_marks),
53113- atomic_read(&fscache_n_uncaches));
53114+ atomic_read_unchecked(&fscache_n_marks),
53115+ atomic_read_unchecked(&fscache_n_uncaches));
53116
53117 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
53118 " oom=%u\n",
53119- atomic_read(&fscache_n_acquires),
53120- atomic_read(&fscache_n_acquires_null),
53121- atomic_read(&fscache_n_acquires_no_cache),
53122- atomic_read(&fscache_n_acquires_ok),
53123- atomic_read(&fscache_n_acquires_nobufs),
53124- atomic_read(&fscache_n_acquires_oom));
53125+ atomic_read_unchecked(&fscache_n_acquires),
53126+ atomic_read_unchecked(&fscache_n_acquires_null),
53127+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
53128+ atomic_read_unchecked(&fscache_n_acquires_ok),
53129+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
53130+ atomic_read_unchecked(&fscache_n_acquires_oom));
53131
53132 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
53133- atomic_read(&fscache_n_object_lookups),
53134- atomic_read(&fscache_n_object_lookups_negative),
53135- atomic_read(&fscache_n_object_lookups_positive),
53136- atomic_read(&fscache_n_object_created),
53137- atomic_read(&fscache_n_object_lookups_timed_out));
53138+ atomic_read_unchecked(&fscache_n_object_lookups),
53139+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
53140+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
53141+ atomic_read_unchecked(&fscache_n_object_created),
53142+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
53143
53144 seq_printf(m, "Invals : n=%u run=%u\n",
53145- atomic_read(&fscache_n_invalidates),
53146- atomic_read(&fscache_n_invalidates_run));
53147+ atomic_read_unchecked(&fscache_n_invalidates),
53148+ atomic_read_unchecked(&fscache_n_invalidates_run));
53149
53150 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
53151- atomic_read(&fscache_n_updates),
53152- atomic_read(&fscache_n_updates_null),
53153- atomic_read(&fscache_n_updates_run));
53154+ atomic_read_unchecked(&fscache_n_updates),
53155+ atomic_read_unchecked(&fscache_n_updates_null),
53156+ atomic_read_unchecked(&fscache_n_updates_run));
53157
53158 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
53159- atomic_read(&fscache_n_relinquishes),
53160- atomic_read(&fscache_n_relinquishes_null),
53161- atomic_read(&fscache_n_relinquishes_waitcrt),
53162- atomic_read(&fscache_n_relinquishes_retire));
53163+ atomic_read_unchecked(&fscache_n_relinquishes),
53164+ atomic_read_unchecked(&fscache_n_relinquishes_null),
53165+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
53166+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
53167
53168 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
53169- atomic_read(&fscache_n_attr_changed),
53170- atomic_read(&fscache_n_attr_changed_ok),
53171- atomic_read(&fscache_n_attr_changed_nobufs),
53172- atomic_read(&fscache_n_attr_changed_nomem),
53173- atomic_read(&fscache_n_attr_changed_calls));
53174+ atomic_read_unchecked(&fscache_n_attr_changed),
53175+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
53176+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
53177+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
53178+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
53179
53180 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
53181- atomic_read(&fscache_n_allocs),
53182- atomic_read(&fscache_n_allocs_ok),
53183- atomic_read(&fscache_n_allocs_wait),
53184- atomic_read(&fscache_n_allocs_nobufs),
53185- atomic_read(&fscache_n_allocs_intr));
53186+ atomic_read_unchecked(&fscache_n_allocs),
53187+ atomic_read_unchecked(&fscache_n_allocs_ok),
53188+ atomic_read_unchecked(&fscache_n_allocs_wait),
53189+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
53190+ atomic_read_unchecked(&fscache_n_allocs_intr));
53191 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
53192- atomic_read(&fscache_n_alloc_ops),
53193- atomic_read(&fscache_n_alloc_op_waits),
53194- atomic_read(&fscache_n_allocs_object_dead));
53195+ atomic_read_unchecked(&fscache_n_alloc_ops),
53196+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
53197+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
53198
53199 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
53200 " int=%u oom=%u\n",
53201- atomic_read(&fscache_n_retrievals),
53202- atomic_read(&fscache_n_retrievals_ok),
53203- atomic_read(&fscache_n_retrievals_wait),
53204- atomic_read(&fscache_n_retrievals_nodata),
53205- atomic_read(&fscache_n_retrievals_nobufs),
53206- atomic_read(&fscache_n_retrievals_intr),
53207- atomic_read(&fscache_n_retrievals_nomem));
53208+ atomic_read_unchecked(&fscache_n_retrievals),
53209+ atomic_read_unchecked(&fscache_n_retrievals_ok),
53210+ atomic_read_unchecked(&fscache_n_retrievals_wait),
53211+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
53212+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
53213+ atomic_read_unchecked(&fscache_n_retrievals_intr),
53214+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
53215 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
53216- atomic_read(&fscache_n_retrieval_ops),
53217- atomic_read(&fscache_n_retrieval_op_waits),
53218- atomic_read(&fscache_n_retrievals_object_dead));
53219+ atomic_read_unchecked(&fscache_n_retrieval_ops),
53220+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
53221+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
53222
53223 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
53224- atomic_read(&fscache_n_stores),
53225- atomic_read(&fscache_n_stores_ok),
53226- atomic_read(&fscache_n_stores_again),
53227- atomic_read(&fscache_n_stores_nobufs),
53228- atomic_read(&fscache_n_stores_oom));
53229+ atomic_read_unchecked(&fscache_n_stores),
53230+ atomic_read_unchecked(&fscache_n_stores_ok),
53231+ atomic_read_unchecked(&fscache_n_stores_again),
53232+ atomic_read_unchecked(&fscache_n_stores_nobufs),
53233+ atomic_read_unchecked(&fscache_n_stores_oom));
53234 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
53235- atomic_read(&fscache_n_store_ops),
53236- atomic_read(&fscache_n_store_calls),
53237- atomic_read(&fscache_n_store_pages),
53238- atomic_read(&fscache_n_store_radix_deletes),
53239- atomic_read(&fscache_n_store_pages_over_limit));
53240+ atomic_read_unchecked(&fscache_n_store_ops),
53241+ atomic_read_unchecked(&fscache_n_store_calls),
53242+ atomic_read_unchecked(&fscache_n_store_pages),
53243+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
53244+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
53245
53246 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
53247- atomic_read(&fscache_n_store_vmscan_not_storing),
53248- atomic_read(&fscache_n_store_vmscan_gone),
53249- atomic_read(&fscache_n_store_vmscan_busy),
53250- atomic_read(&fscache_n_store_vmscan_cancelled),
53251- atomic_read(&fscache_n_store_vmscan_wait));
53252+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
53253+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
53254+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
53255+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
53256+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
53257
53258 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
53259- atomic_read(&fscache_n_op_pend),
53260- atomic_read(&fscache_n_op_run),
53261- atomic_read(&fscache_n_op_enqueue),
53262- atomic_read(&fscache_n_op_cancelled),
53263- atomic_read(&fscache_n_op_rejected));
53264+ atomic_read_unchecked(&fscache_n_op_pend),
53265+ atomic_read_unchecked(&fscache_n_op_run),
53266+ atomic_read_unchecked(&fscache_n_op_enqueue),
53267+ atomic_read_unchecked(&fscache_n_op_cancelled),
53268+ atomic_read_unchecked(&fscache_n_op_rejected));
53269 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
53270- atomic_read(&fscache_n_op_deferred_release),
53271- atomic_read(&fscache_n_op_release),
53272- atomic_read(&fscache_n_op_gc));
53273+ atomic_read_unchecked(&fscache_n_op_deferred_release),
53274+ atomic_read_unchecked(&fscache_n_op_release),
53275+ atomic_read_unchecked(&fscache_n_op_gc));
53276
53277 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
53278 atomic_read(&fscache_n_cop_alloc_object),
53279diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
53280index 6f96a8d..6019bb9 100644
53281--- a/fs/fuse/cuse.c
53282+++ b/fs/fuse/cuse.c
53283@@ -597,10 +597,12 @@ static int __init cuse_init(void)
53284 INIT_LIST_HEAD(&cuse_conntbl[i]);
53285
53286 /* inherit and extend fuse_dev_operations */
53287- cuse_channel_fops = fuse_dev_operations;
53288- cuse_channel_fops.owner = THIS_MODULE;
53289- cuse_channel_fops.open = cuse_channel_open;
53290- cuse_channel_fops.release = cuse_channel_release;
53291+ pax_open_kernel();
53292+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
53293+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
53294+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
53295+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
53296+ pax_close_kernel();
53297
53298 cuse_class = class_create(THIS_MODULE, "cuse");
53299 if (IS_ERR(cuse_class))
53300diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
53301index 11dfa0c..6f64416 100644
53302--- a/fs/fuse/dev.c
53303+++ b/fs/fuse/dev.c
53304@@ -1294,7 +1294,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53305 ret = 0;
53306 pipe_lock(pipe);
53307
53308- if (!pipe->readers) {
53309+ if (!atomic_read(&pipe->readers)) {
53310 send_sig(SIGPIPE, current, 0);
53311 if (!ret)
53312 ret = -EPIPE;
53313diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
53314index 185c479..51b9986 100644
53315--- a/fs/fuse/dir.c
53316+++ b/fs/fuse/dir.c
53317@@ -1415,7 +1415,7 @@ static char *read_link(struct dentry *dentry)
53318 return link;
53319 }
53320
53321-static void free_link(char *link)
53322+static void free_link(const char *link)
53323 {
53324 if (!IS_ERR(link))
53325 free_page((unsigned long) link);
53326diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
53327index cc00bd1..3edb692 100644
53328--- a/fs/gfs2/inode.c
53329+++ b/fs/gfs2/inode.c
53330@@ -1500,7 +1500,7 @@ out:
53331
53332 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53333 {
53334- char *s = nd_get_link(nd);
53335+ const char *s = nd_get_link(nd);
53336 if (!IS_ERR(s))
53337 kfree(s);
53338 }
53339diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
53340index a3f868a..bb308ae 100644
53341--- a/fs/hugetlbfs/inode.c
53342+++ b/fs/hugetlbfs/inode.c
53343@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53344 struct mm_struct *mm = current->mm;
53345 struct vm_area_struct *vma;
53346 struct hstate *h = hstate_file(file);
53347+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
53348 struct vm_unmapped_area_info info;
53349
53350 if (len & ~huge_page_mask(h))
53351@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53352 return addr;
53353 }
53354
53355+#ifdef CONFIG_PAX_RANDMMAP
53356+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53357+#endif
53358+
53359 if (addr) {
53360 addr = ALIGN(addr, huge_page_size(h));
53361 vma = find_vma(mm, addr);
53362- if (TASK_SIZE - len >= addr &&
53363- (!vma || addr + len <= vma->vm_start))
53364+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
53365 return addr;
53366 }
53367
53368 info.flags = 0;
53369 info.length = len;
53370 info.low_limit = TASK_UNMAPPED_BASE;
53371+
53372+#ifdef CONFIG_PAX_RANDMMAP
53373+ if (mm->pax_flags & MF_PAX_RANDMMAP)
53374+ info.low_limit += mm->delta_mmap;
53375+#endif
53376+
53377 info.high_limit = TASK_SIZE;
53378 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
53379 info.align_offset = 0;
53380@@ -898,7 +908,7 @@ static struct file_system_type hugetlbfs_fs_type = {
53381 };
53382 MODULE_ALIAS_FS("hugetlbfs");
53383
53384-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53385+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53386
53387 static int can_do_hugetlb_shm(void)
53388 {
53389diff --git a/fs/inode.c b/fs/inode.c
53390index a898b3d..9b5a214 100644
53391--- a/fs/inode.c
53392+++ b/fs/inode.c
53393@@ -878,8 +878,8 @@ unsigned int get_next_ino(void)
53394
53395 #ifdef CONFIG_SMP
53396 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
53397- static atomic_t shared_last_ino;
53398- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
53399+ static atomic_unchecked_t shared_last_ino;
53400+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
53401
53402 res = next - LAST_INO_BATCH;
53403 }
53404diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
53405index 4a6cf28..d3a29d3 100644
53406--- a/fs/jffs2/erase.c
53407+++ b/fs/jffs2/erase.c
53408@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
53409 struct jffs2_unknown_node marker = {
53410 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
53411 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53412- .totlen = cpu_to_je32(c->cleanmarker_size)
53413+ .totlen = cpu_to_je32(c->cleanmarker_size),
53414+ .hdr_crc = cpu_to_je32(0)
53415 };
53416
53417 jffs2_prealloc_raw_node_refs(c, jeb, 1);
53418diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
53419index a6597d6..41b30ec 100644
53420--- a/fs/jffs2/wbuf.c
53421+++ b/fs/jffs2/wbuf.c
53422@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
53423 {
53424 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
53425 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53426- .totlen = constant_cpu_to_je32(8)
53427+ .totlen = constant_cpu_to_je32(8),
53428+ .hdr_crc = constant_cpu_to_je32(0)
53429 };
53430
53431 /*
53432diff --git a/fs/jfs/super.c b/fs/jfs/super.c
53433index 2003e83..40db287 100644
53434--- a/fs/jfs/super.c
53435+++ b/fs/jfs/super.c
53436@@ -856,7 +856,7 @@ static int __init init_jfs_fs(void)
53437
53438 jfs_inode_cachep =
53439 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
53440- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
53441+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
53442 init_once);
53443 if (jfs_inode_cachep == NULL)
53444 return -ENOMEM;
53445diff --git a/fs/libfs.c b/fs/libfs.c
53446index 916da8c..1588998 100644
53447--- a/fs/libfs.c
53448+++ b/fs/libfs.c
53449@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53450
53451 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
53452 struct dentry *next;
53453+ char d_name[sizeof(next->d_iname)];
53454+ const unsigned char *name;
53455+
53456 next = list_entry(p, struct dentry, d_u.d_child);
53457 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
53458 if (!simple_positive(next)) {
53459@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53460
53461 spin_unlock(&next->d_lock);
53462 spin_unlock(&dentry->d_lock);
53463- if (filldir(dirent, next->d_name.name,
53464+ name = next->d_name.name;
53465+ if (name == next->d_iname) {
53466+ memcpy(d_name, name, next->d_name.len);
53467+ name = d_name;
53468+ }
53469+ if (filldir(dirent, name,
53470 next->d_name.len, filp->f_pos,
53471 next->d_inode->i_ino,
53472 dt_type(next->d_inode)) < 0)
53473diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
53474index 9760ecb..9b838ef 100644
53475--- a/fs/lockd/clntproc.c
53476+++ b/fs/lockd/clntproc.c
53477@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
53478 /*
53479 * Cookie counter for NLM requests
53480 */
53481-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
53482+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
53483
53484 void nlmclnt_next_cookie(struct nlm_cookie *c)
53485 {
53486- u32 cookie = atomic_inc_return(&nlm_cookie);
53487+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
53488
53489 memcpy(c->data, &cookie, 4);
53490 c->len=4;
53491diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
53492index a2aa97d..10d6c41 100644
53493--- a/fs/lockd/svc.c
53494+++ b/fs/lockd/svc.c
53495@@ -305,7 +305,7 @@ static int lockd_start_svc(struct svc_serv *serv)
53496 svc_sock_update_bufs(serv);
53497 serv->sv_maxconn = nlm_max_connections;
53498
53499- nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name);
53500+ nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, "%s", serv->sv_name);
53501 if (IS_ERR(nlmsvc_task)) {
53502 error = PTR_ERR(nlmsvc_task);
53503 printk(KERN_WARNING
53504diff --git a/fs/locks.c b/fs/locks.c
53505index cb424a4..850e4dd 100644
53506--- a/fs/locks.c
53507+++ b/fs/locks.c
53508@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
53509 return;
53510
53511 if (filp->f_op && filp->f_op->flock) {
53512- struct file_lock fl = {
53513+ struct file_lock flock = {
53514 .fl_pid = current->tgid,
53515 .fl_file = filp,
53516 .fl_flags = FL_FLOCK,
53517 .fl_type = F_UNLCK,
53518 .fl_end = OFFSET_MAX,
53519 };
53520- filp->f_op->flock(filp, F_SETLKW, &fl);
53521- if (fl.fl_ops && fl.fl_ops->fl_release_private)
53522- fl.fl_ops->fl_release_private(&fl);
53523+ filp->f_op->flock(filp, F_SETLKW, &flock);
53524+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
53525+ flock.fl_ops->fl_release_private(&flock);
53526 }
53527
53528 lock_flocks();
53529diff --git a/fs/namei.c b/fs/namei.c
53530index 85e40d1..b66744e 100644
53531--- a/fs/namei.c
53532+++ b/fs/namei.c
53533@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
53534 if (ret != -EACCES)
53535 return ret;
53536
53537+#ifdef CONFIG_GRKERNSEC
53538+ /* we'll block if we have to log due to a denied capability use */
53539+ if (mask & MAY_NOT_BLOCK)
53540+ return -ECHILD;
53541+#endif
53542+
53543 if (S_ISDIR(inode->i_mode)) {
53544 /* DACs are overridable for directories */
53545- if (inode_capable(inode, CAP_DAC_OVERRIDE))
53546- return 0;
53547 if (!(mask & MAY_WRITE))
53548- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53549+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53550+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53551 return 0;
53552+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
53553+ return 0;
53554 return -EACCES;
53555 }
53556 /*
53557+ * Searching includes executable on directories, else just read.
53558+ */
53559+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53560+ if (mask == MAY_READ)
53561+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53562+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53563+ return 0;
53564+
53565+ /*
53566 * Read/write DACs are always overridable.
53567 * Executable DACs are overridable when there is
53568 * at least one exec bit set.
53569@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
53570 if (inode_capable(inode, CAP_DAC_OVERRIDE))
53571 return 0;
53572
53573- /*
53574- * Searching includes executable on directories, else just read.
53575- */
53576- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53577- if (mask == MAY_READ)
53578- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53579- return 0;
53580-
53581 return -EACCES;
53582 }
53583
53584@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53585 {
53586 struct dentry *dentry = link->dentry;
53587 int error;
53588- char *s;
53589+ const char *s;
53590
53591 BUG_ON(nd->flags & LOOKUP_RCU);
53592
53593@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53594 if (error)
53595 goto out_put_nd_path;
53596
53597+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53598+ dentry->d_inode, dentry, nd->path.mnt)) {
53599+ error = -EACCES;
53600+ goto out_put_nd_path;
53601+ }
53602+
53603 nd->last_type = LAST_BIND;
53604 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53605 error = PTR_ERR(*p);
53606@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53607 if (res)
53608 break;
53609 res = walk_component(nd, path, LOOKUP_FOLLOW);
53610+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53611+ res = -EACCES;
53612 put_link(nd, &link, cookie);
53613 } while (res > 0);
53614
53615@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
53616 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53617 {
53618 unsigned long a, b, adata, bdata, mask, hash, len;
53619- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53620+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53621
53622 hash = a = 0;
53623 len = -sizeof(unsigned long);
53624@@ -1968,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
53625 if (err)
53626 break;
53627 err = lookup_last(nd, &path);
53628+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53629+ err = -EACCES;
53630 put_link(nd, &link, cookie);
53631 }
53632 }
53633@@ -1975,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
53634 if (!err)
53635 err = complete_walk(nd);
53636
53637+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53638+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53639+ path_put(&nd->path);
53640+ err = -ENOENT;
53641+ }
53642+ }
53643+
53644 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53645 if (!nd->inode->i_op->lookup) {
53646 path_put(&nd->path);
53647@@ -2002,8 +2027,15 @@ static int filename_lookup(int dfd, struct filename *name,
53648 retval = path_lookupat(dfd, name->name,
53649 flags | LOOKUP_REVAL, nd);
53650
53651- if (likely(!retval))
53652+ if (likely(!retval)) {
53653 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53654+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53655+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53656+ path_put(&nd->path);
53657+ return -ENOENT;
53658+ }
53659+ }
53660+ }
53661 return retval;
53662 }
53663
53664@@ -2381,6 +2413,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53665 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53666 return -EPERM;
53667
53668+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53669+ return -EPERM;
53670+ if (gr_handle_rawio(inode))
53671+ return -EPERM;
53672+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53673+ return -EACCES;
53674+
53675 return 0;
53676 }
53677
53678@@ -2602,7 +2641,7 @@ looked_up:
53679 * cleared otherwise prior to returning.
53680 */
53681 static int lookup_open(struct nameidata *nd, struct path *path,
53682- struct file *file,
53683+ struct path *link, struct file *file,
53684 const struct open_flags *op,
53685 bool got_write, int *opened)
53686 {
53687@@ -2637,6 +2676,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53688 /* Negative dentry, just create the file */
53689 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53690 umode_t mode = op->mode;
53691+
53692+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53693+ error = -EACCES;
53694+ goto out_dput;
53695+ }
53696+
53697+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53698+ error = -EACCES;
53699+ goto out_dput;
53700+ }
53701+
53702 if (!IS_POSIXACL(dir->d_inode))
53703 mode &= ~current_umask();
53704 /*
53705@@ -2658,6 +2708,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53706 nd->flags & LOOKUP_EXCL);
53707 if (error)
53708 goto out_dput;
53709+ else
53710+ gr_handle_create(dentry, nd->path.mnt);
53711 }
53712 out_no_open:
53713 path->dentry = dentry;
53714@@ -2672,7 +2724,7 @@ out_dput:
53715 /*
53716 * Handle the last step of open()
53717 */
53718-static int do_last(struct nameidata *nd, struct path *path,
53719+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53720 struct file *file, const struct open_flags *op,
53721 int *opened, struct filename *name)
53722 {
53723@@ -2701,16 +2753,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53724 error = complete_walk(nd);
53725 if (error)
53726 return error;
53727+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53728+ error = -ENOENT;
53729+ goto out;
53730+ }
53731 audit_inode(name, nd->path.dentry, 0);
53732 if (open_flag & O_CREAT) {
53733 error = -EISDIR;
53734 goto out;
53735 }
53736+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53737+ error = -EACCES;
53738+ goto out;
53739+ }
53740 goto finish_open;
53741 case LAST_BIND:
53742 error = complete_walk(nd);
53743 if (error)
53744 return error;
53745+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53746+ error = -ENOENT;
53747+ goto out;
53748+ }
53749+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53750+ error = -EACCES;
53751+ goto out;
53752+ }
53753 audit_inode(name, dir, 0);
53754 goto finish_open;
53755 }
53756@@ -2759,7 +2827,7 @@ retry_lookup:
53757 */
53758 }
53759 mutex_lock(&dir->d_inode->i_mutex);
53760- error = lookup_open(nd, path, file, op, got_write, opened);
53761+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53762 mutex_unlock(&dir->d_inode->i_mutex);
53763
53764 if (error <= 0) {
53765@@ -2783,11 +2851,28 @@ retry_lookup:
53766 goto finish_open_created;
53767 }
53768
53769+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53770+ error = -ENOENT;
53771+ goto exit_dput;
53772+ }
53773+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53774+ error = -EACCES;
53775+ goto exit_dput;
53776+ }
53777+
53778 /*
53779 * create/update audit record if it already exists.
53780 */
53781- if (path->dentry->d_inode)
53782+ if (path->dentry->d_inode) {
53783+ /* only check if O_CREAT is specified, all other checks need to go
53784+ into may_open */
53785+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53786+ error = -EACCES;
53787+ goto exit_dput;
53788+ }
53789+
53790 audit_inode(name, path->dentry, 0);
53791+ }
53792
53793 /*
53794 * If atomic_open() acquired write access it is dropped now due to
53795@@ -2828,6 +2913,11 @@ finish_lookup:
53796 }
53797 }
53798 BUG_ON(inode != path->dentry->d_inode);
53799+ /* if we're resolving a symlink to another symlink */
53800+ if (link && gr_handle_symlink_owner(link, inode)) {
53801+ error = -EACCES;
53802+ goto out;
53803+ }
53804 return 1;
53805 }
53806
53807@@ -2837,7 +2927,6 @@ finish_lookup:
53808 save_parent.dentry = nd->path.dentry;
53809 save_parent.mnt = mntget(path->mnt);
53810 nd->path.dentry = path->dentry;
53811-
53812 }
53813 nd->inode = inode;
53814 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53815@@ -2846,6 +2935,16 @@ finish_lookup:
53816 path_put(&save_parent);
53817 return error;
53818 }
53819+
53820+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53821+ error = -ENOENT;
53822+ goto out;
53823+ }
53824+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53825+ error = -EACCES;
53826+ goto out;
53827+ }
53828+
53829 error = -EISDIR;
53830 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53831 goto out;
53832@@ -2944,7 +3043,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53833 if (unlikely(error))
53834 goto out;
53835
53836- error = do_last(nd, &path, file, op, &opened, pathname);
53837+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53838 while (unlikely(error > 0)) { /* trailing symlink */
53839 struct path link = path;
53840 void *cookie;
53841@@ -2962,7 +3061,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53842 error = follow_link(&link, nd, &cookie);
53843 if (unlikely(error))
53844 break;
53845- error = do_last(nd, &path, file, op, &opened, pathname);
53846+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53847 put_link(nd, &link, cookie);
53848 }
53849 out:
53850@@ -3062,8 +3161,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53851 goto unlock;
53852
53853 error = -EEXIST;
53854- if (dentry->d_inode)
53855+ if (dentry->d_inode) {
53856+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53857+ error = -ENOENT;
53858+ }
53859 goto fail;
53860+ }
53861 /*
53862 * Special case - lookup gave negative, but... we had foo/bar/
53863 * From the vfs_mknod() POV we just have a negative dentry -
53864@@ -3115,6 +3218,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53865 }
53866 EXPORT_SYMBOL(user_path_create);
53867
53868+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53869+{
53870+ struct filename *tmp = getname(pathname);
53871+ struct dentry *res;
53872+ if (IS_ERR(tmp))
53873+ return ERR_CAST(tmp);
53874+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53875+ if (IS_ERR(res))
53876+ putname(tmp);
53877+ else
53878+ *to = tmp;
53879+ return res;
53880+}
53881+
53882 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53883 {
53884 int error = may_create(dir, dentry);
53885@@ -3177,6 +3294,17 @@ retry:
53886
53887 if (!IS_POSIXACL(path.dentry->d_inode))
53888 mode &= ~current_umask();
53889+
53890+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
53891+ error = -EPERM;
53892+ goto out;
53893+ }
53894+
53895+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
53896+ error = -EACCES;
53897+ goto out;
53898+ }
53899+
53900 error = security_path_mknod(&path, dentry, mode, dev);
53901 if (error)
53902 goto out;
53903@@ -3193,6 +3321,8 @@ retry:
53904 break;
53905 }
53906 out:
53907+ if (!error)
53908+ gr_handle_create(dentry, path.mnt);
53909 done_path_create(&path, dentry);
53910 if (retry_estale(error, lookup_flags)) {
53911 lookup_flags |= LOOKUP_REVAL;
53912@@ -3245,9 +3375,16 @@ retry:
53913
53914 if (!IS_POSIXACL(path.dentry->d_inode))
53915 mode &= ~current_umask();
53916+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
53917+ error = -EACCES;
53918+ goto out;
53919+ }
53920 error = security_path_mkdir(&path, dentry, mode);
53921 if (!error)
53922 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
53923+ if (!error)
53924+ gr_handle_create(dentry, path.mnt);
53925+out:
53926 done_path_create(&path, dentry);
53927 if (retry_estale(error, lookup_flags)) {
53928 lookup_flags |= LOOKUP_REVAL;
53929@@ -3328,6 +3465,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
53930 struct filename *name;
53931 struct dentry *dentry;
53932 struct nameidata nd;
53933+ ino_t saved_ino = 0;
53934+ dev_t saved_dev = 0;
53935 unsigned int lookup_flags = 0;
53936 retry:
53937 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53938@@ -3360,10 +3499,21 @@ retry:
53939 error = -ENOENT;
53940 goto exit3;
53941 }
53942+
53943+ saved_ino = dentry->d_inode->i_ino;
53944+ saved_dev = gr_get_dev_from_dentry(dentry);
53945+
53946+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
53947+ error = -EACCES;
53948+ goto exit3;
53949+ }
53950+
53951 error = security_path_rmdir(&nd.path, dentry);
53952 if (error)
53953 goto exit3;
53954 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
53955+ if (!error && (saved_dev || saved_ino))
53956+ gr_handle_delete(saved_ino, saved_dev);
53957 exit3:
53958 dput(dentry);
53959 exit2:
53960@@ -3429,6 +3579,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
53961 struct dentry *dentry;
53962 struct nameidata nd;
53963 struct inode *inode = NULL;
53964+ ino_t saved_ino = 0;
53965+ dev_t saved_dev = 0;
53966 unsigned int lookup_flags = 0;
53967 retry:
53968 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53969@@ -3455,10 +3607,22 @@ retry:
53970 if (!inode)
53971 goto slashes;
53972 ihold(inode);
53973+
53974+ if (inode->i_nlink <= 1) {
53975+ saved_ino = inode->i_ino;
53976+ saved_dev = gr_get_dev_from_dentry(dentry);
53977+ }
53978+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
53979+ error = -EACCES;
53980+ goto exit2;
53981+ }
53982+
53983 error = security_path_unlink(&nd.path, dentry);
53984 if (error)
53985 goto exit2;
53986 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
53987+ if (!error && (saved_ino || saved_dev))
53988+ gr_handle_delete(saved_ino, saved_dev);
53989 exit2:
53990 dput(dentry);
53991 }
53992@@ -3536,9 +3700,17 @@ retry:
53993 if (IS_ERR(dentry))
53994 goto out_putname;
53995
53996+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
53997+ error = -EACCES;
53998+ goto out;
53999+ }
54000+
54001 error = security_path_symlink(&path, dentry, from->name);
54002 if (!error)
54003 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
54004+ if (!error)
54005+ gr_handle_create(dentry, path.mnt);
54006+out:
54007 done_path_create(&path, dentry);
54008 if (retry_estale(error, lookup_flags)) {
54009 lookup_flags |= LOOKUP_REVAL;
54010@@ -3612,6 +3784,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
54011 {
54012 struct dentry *new_dentry;
54013 struct path old_path, new_path;
54014+ struct filename *to = NULL;
54015 int how = 0;
54016 int error;
54017
54018@@ -3635,7 +3808,7 @@ retry:
54019 if (error)
54020 return error;
54021
54022- new_dentry = user_path_create(newdfd, newname, &new_path,
54023+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
54024 (how & LOOKUP_REVAL));
54025 error = PTR_ERR(new_dentry);
54026 if (IS_ERR(new_dentry))
54027@@ -3647,11 +3820,28 @@ retry:
54028 error = may_linkat(&old_path);
54029 if (unlikely(error))
54030 goto out_dput;
54031+
54032+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
54033+ old_path.dentry->d_inode,
54034+ old_path.dentry->d_inode->i_mode, to)) {
54035+ error = -EACCES;
54036+ goto out_dput;
54037+ }
54038+
54039+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
54040+ old_path.dentry, old_path.mnt, to)) {
54041+ error = -EACCES;
54042+ goto out_dput;
54043+ }
54044+
54045 error = security_path_link(old_path.dentry, &new_path, new_dentry);
54046 if (error)
54047 goto out_dput;
54048 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
54049+ if (!error)
54050+ gr_handle_create(new_dentry, new_path.mnt);
54051 out_dput:
54052+ putname(to);
54053 done_path_create(&new_path, new_dentry);
54054 if (retry_estale(error, how)) {
54055 how |= LOOKUP_REVAL;
54056@@ -3897,12 +4087,21 @@ retry:
54057 if (new_dentry == trap)
54058 goto exit5;
54059
54060+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
54061+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
54062+ to);
54063+ if (error)
54064+ goto exit5;
54065+
54066 error = security_path_rename(&oldnd.path, old_dentry,
54067 &newnd.path, new_dentry);
54068 if (error)
54069 goto exit5;
54070 error = vfs_rename(old_dir->d_inode, old_dentry,
54071 new_dir->d_inode, new_dentry);
54072+ if (!error)
54073+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
54074+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
54075 exit5:
54076 dput(new_dentry);
54077 exit4:
54078@@ -3934,6 +4133,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
54079
54080 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
54081 {
54082+ char tmpbuf[64];
54083+ const char *newlink;
54084 int len;
54085
54086 len = PTR_ERR(link);
54087@@ -3943,7 +4144,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
54088 len = strlen(link);
54089 if (len > (unsigned) buflen)
54090 len = buflen;
54091- if (copy_to_user(buffer, link, len))
54092+
54093+ if (len < sizeof(tmpbuf)) {
54094+ memcpy(tmpbuf, link, len);
54095+ newlink = tmpbuf;
54096+ } else
54097+ newlink = link;
54098+
54099+ if (copy_to_user(buffer, newlink, len))
54100 len = -EFAULT;
54101 out:
54102 return len;
54103diff --git a/fs/namespace.c b/fs/namespace.c
54104index e945b81..fc018e2 100644
54105--- a/fs/namespace.c
54106+++ b/fs/namespace.c
54107@@ -1219,6 +1219,9 @@ static int do_umount(struct mount *mnt, int flags)
54108 if (!(sb->s_flags & MS_RDONLY))
54109 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
54110 up_write(&sb->s_umount);
54111+
54112+ gr_log_remount(mnt->mnt_devname, retval);
54113+
54114 return retval;
54115 }
54116
54117@@ -1238,6 +1241,9 @@ static int do_umount(struct mount *mnt, int flags)
54118 br_write_unlock(&vfsmount_lock);
54119 up_write(&namespace_sem);
54120 release_mounts(&umount_list);
54121+
54122+ gr_log_unmount(mnt->mnt_devname, retval);
54123+
54124 return retval;
54125 }
54126
54127@@ -1257,7 +1263,7 @@ static inline bool may_mount(void)
54128 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
54129 */
54130
54131-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
54132+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
54133 {
54134 struct path path;
54135 struct mount *mnt;
54136@@ -1297,7 +1303,7 @@ out:
54137 /*
54138 * The 2.0 compatible umount. No flags.
54139 */
54140-SYSCALL_DEFINE1(oldumount, char __user *, name)
54141+SYSCALL_DEFINE1(oldumount, const char __user *, name)
54142 {
54143 return sys_umount(name, 0);
54144 }
54145@@ -2267,6 +2273,16 @@ long do_mount(const char *dev_name, const char *dir_name,
54146 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
54147 MS_STRICTATIME);
54148
54149+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
54150+ retval = -EPERM;
54151+ goto dput_out;
54152+ }
54153+
54154+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
54155+ retval = -EPERM;
54156+ goto dput_out;
54157+ }
54158+
54159 if (flags & MS_REMOUNT)
54160 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
54161 data_page);
54162@@ -2281,6 +2297,9 @@ long do_mount(const char *dev_name, const char *dir_name,
54163 dev_name, data_page);
54164 dput_out:
54165 path_put(&path);
54166+
54167+ gr_log_mount(dev_name, dir_name, retval);
54168+
54169 return retval;
54170 }
54171
54172@@ -2454,8 +2473,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
54173 }
54174 EXPORT_SYMBOL(mount_subtree);
54175
54176-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
54177- char __user *, type, unsigned long, flags, void __user *, data)
54178+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
54179+ const char __user *, type, unsigned long, flags, void __user *, data)
54180 {
54181 int ret;
54182 char *kernel_type;
54183@@ -2567,6 +2586,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
54184 if (error)
54185 goto out2;
54186
54187+ if (gr_handle_chroot_pivot()) {
54188+ error = -EPERM;
54189+ goto out2;
54190+ }
54191+
54192 get_fs_root(current->fs, &root);
54193 error = lock_mount(&old);
54194 if (error)
54195@@ -2815,7 +2839,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
54196 !nsown_capable(CAP_SYS_ADMIN))
54197 return -EPERM;
54198
54199- if (fs->users != 1)
54200+ if (atomic_read(&fs->users) != 1)
54201 return -EINVAL;
54202
54203 get_mnt_ns(mnt_ns);
54204diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
54205index 5088b57..eabd719 100644
54206--- a/fs/nfs/callback.c
54207+++ b/fs/nfs/callback.c
54208@@ -208,7 +208,6 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
54209 struct svc_rqst *rqstp;
54210 int (*callback_svc)(void *vrqstp);
54211 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
54212- char svc_name[12];
54213 int ret;
54214
54215 nfs_callback_bc_serv(minorversion, xprt, serv);
54216@@ -232,10 +231,9 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
54217
54218 svc_sock_update_bufs(serv);
54219
54220- sprintf(svc_name, "nfsv4.%u-svc", minorversion);
54221 cb_info->serv = serv;
54222 cb_info->rqst = rqstp;
54223- cb_info->task = kthread_run(callback_svc, cb_info->rqst, svc_name);
54224+ cb_info->task = kthread_run(callback_svc, cb_info->rqst, "nfsv4.%u-svc", minorversion);
54225 if (IS_ERR(cb_info->task)) {
54226 ret = PTR_ERR(cb_info->task);
54227 svc_exit_thread(cb_info->rqst);
54228diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
54229index 59461c9..b17c57e 100644
54230--- a/fs/nfs/callback_xdr.c
54231+++ b/fs/nfs/callback_xdr.c
54232@@ -51,7 +51,7 @@ struct callback_op {
54233 callback_decode_arg_t decode_args;
54234 callback_encode_res_t encode_res;
54235 long res_maxsize;
54236-};
54237+} __do_const;
54238
54239 static struct callback_op callback_ops[];
54240
54241diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
54242index 1f94167..79c4ce4 100644
54243--- a/fs/nfs/inode.c
54244+++ b/fs/nfs/inode.c
54245@@ -1041,16 +1041,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
54246 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
54247 }
54248
54249-static atomic_long_t nfs_attr_generation_counter;
54250+static atomic_long_unchecked_t nfs_attr_generation_counter;
54251
54252 static unsigned long nfs_read_attr_generation_counter(void)
54253 {
54254- return atomic_long_read(&nfs_attr_generation_counter);
54255+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
54256 }
54257
54258 unsigned long nfs_inc_attr_generation_counter(void)
54259 {
54260- return atomic_long_inc_return(&nfs_attr_generation_counter);
54261+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
54262 }
54263
54264 void nfs_fattr_init(struct nfs_fattr *fattr)
54265diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
54266index d41a351..7899577 100644
54267--- a/fs/nfs/nfs4state.c
54268+++ b/fs/nfs/nfs4state.c
54269@@ -1182,7 +1182,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp)
54270 snprintf(buf, sizeof(buf), "%s-manager",
54271 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
54272 rcu_read_unlock();
54273- task = kthread_run(nfs4_run_state_manager, clp, buf);
54274+ task = kthread_run(nfs4_run_state_manager, clp, "%s", buf);
54275 if (IS_ERR(task)) {
54276 printk(KERN_ERR "%s: kthread_run: %ld\n",
54277 __func__, PTR_ERR(task));
54278diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
54279index d401d01..10b3e62 100644
54280--- a/fs/nfsd/nfs4proc.c
54281+++ b/fs/nfsd/nfs4proc.c
54282@@ -1109,7 +1109,7 @@ struct nfsd4_operation {
54283 nfsd4op_rsize op_rsize_bop;
54284 stateid_getter op_get_currentstateid;
54285 stateid_setter op_set_currentstateid;
54286-};
54287+} __do_const;
54288
54289 static struct nfsd4_operation nfsd4_ops[];
54290
54291diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
54292index 6eb0dc5..29067a9 100644
54293--- a/fs/nfsd/nfs4xdr.c
54294+++ b/fs/nfsd/nfs4xdr.c
54295@@ -1457,7 +1457,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
54296
54297 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
54298
54299-static nfsd4_dec nfsd4_dec_ops[] = {
54300+static const nfsd4_dec nfsd4_dec_ops[] = {
54301 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54302 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54303 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54304@@ -1497,7 +1497,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
54305 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
54306 };
54307
54308-static nfsd4_dec nfsd41_dec_ops[] = {
54309+static const nfsd4_dec nfsd41_dec_ops[] = {
54310 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54311 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54312 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54313@@ -1559,7 +1559,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
54314 };
54315
54316 struct nfsd4_minorversion_ops {
54317- nfsd4_dec *decoders;
54318+ const nfsd4_dec *decoders;
54319 int nops;
54320 };
54321
54322diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
54323index ca05f6d..b88c3a7 100644
54324--- a/fs/nfsd/nfscache.c
54325+++ b/fs/nfsd/nfscache.c
54326@@ -461,13 +461,16 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
54327 {
54328 struct svc_cacherep *rp = rqstp->rq_cacherep;
54329 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
54330- int len;
54331+ long len;
54332
54333 if (!rp)
54334 return;
54335
54336- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
54337- len >>= 2;
54338+ if (statp) {
54339+ len = (char*)statp - (char*)resv->iov_base;
54340+ len = resv->iov_len - len;
54341+ len >>= 2;
54342+ }
54343
54344 /* Don't cache excessive amounts of data and XDR failures */
54345 if (!statp || len > (256 >> 2)) {
54346diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
54347index 2b2e239..c915b48 100644
54348--- a/fs/nfsd/vfs.c
54349+++ b/fs/nfsd/vfs.c
54350@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54351 } else {
54352 oldfs = get_fs();
54353 set_fs(KERNEL_DS);
54354- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
54355+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
54356 set_fs(oldfs);
54357 }
54358
54359@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54360
54361 /* Write the data. */
54362 oldfs = get_fs(); set_fs(KERNEL_DS);
54363- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
54364+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
54365 set_fs(oldfs);
54366 if (host_err < 0)
54367 goto out_nfserr;
54368@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
54369 */
54370
54371 oldfs = get_fs(); set_fs(KERNEL_DS);
54372- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
54373+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
54374 set_fs(oldfs);
54375
54376 if (host_err < 0)
54377diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
54378index fea6bd5..8ee9d81 100644
54379--- a/fs/nls/nls_base.c
54380+++ b/fs/nls/nls_base.c
54381@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
54382
54383 int register_nls(struct nls_table * nls)
54384 {
54385- struct nls_table ** tmp = &tables;
54386+ struct nls_table *tmp = tables;
54387
54388 if (nls->next)
54389 return -EBUSY;
54390
54391 spin_lock(&nls_lock);
54392- while (*tmp) {
54393- if (nls == *tmp) {
54394+ while (tmp) {
54395+ if (nls == tmp) {
54396 spin_unlock(&nls_lock);
54397 return -EBUSY;
54398 }
54399- tmp = &(*tmp)->next;
54400+ tmp = tmp->next;
54401 }
54402- nls->next = tables;
54403+ pax_open_kernel();
54404+ *(struct nls_table **)&nls->next = tables;
54405+ pax_close_kernel();
54406 tables = nls;
54407 spin_unlock(&nls_lock);
54408 return 0;
54409@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
54410
54411 int unregister_nls(struct nls_table * nls)
54412 {
54413- struct nls_table ** tmp = &tables;
54414+ struct nls_table * const * tmp = &tables;
54415
54416 spin_lock(&nls_lock);
54417 while (*tmp) {
54418 if (nls == *tmp) {
54419- *tmp = nls->next;
54420+ pax_open_kernel();
54421+ *(struct nls_table **)tmp = nls->next;
54422+ pax_close_kernel();
54423 spin_unlock(&nls_lock);
54424 return 0;
54425 }
54426diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
54427index 7424929..35f6be5 100644
54428--- a/fs/nls/nls_euc-jp.c
54429+++ b/fs/nls/nls_euc-jp.c
54430@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
54431 p_nls = load_nls("cp932");
54432
54433 if (p_nls) {
54434- table.charset2upper = p_nls->charset2upper;
54435- table.charset2lower = p_nls->charset2lower;
54436+ pax_open_kernel();
54437+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54438+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54439+ pax_close_kernel();
54440 return register_nls(&table);
54441 }
54442
54443diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
54444index e7bc1d7..06bd4bb 100644
54445--- a/fs/nls/nls_koi8-ru.c
54446+++ b/fs/nls/nls_koi8-ru.c
54447@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
54448 p_nls = load_nls("koi8-u");
54449
54450 if (p_nls) {
54451- table.charset2upper = p_nls->charset2upper;
54452- table.charset2lower = p_nls->charset2lower;
54453+ pax_open_kernel();
54454+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54455+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54456+ pax_close_kernel();
54457 return register_nls(&table);
54458 }
54459
54460diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
54461index 5d84442..2c034ba 100644
54462--- a/fs/notify/fanotify/fanotify_user.c
54463+++ b/fs/notify/fanotify/fanotify_user.c
54464@@ -121,6 +121,7 @@ static int fill_event_metadata(struct fsnotify_group *group,
54465 metadata->event_len = FAN_EVENT_METADATA_LEN;
54466 metadata->metadata_len = FAN_EVENT_METADATA_LEN;
54467 metadata->vers = FANOTIFY_METADATA_VERSION;
54468+ metadata->reserved = 0;
54469 metadata->mask = event->mask & FAN_ALL_OUTGOING_EVENTS;
54470 metadata->pid = pid_vnr(event->tgid);
54471 if (unlikely(event->mask & FAN_Q_OVERFLOW))
54472@@ -251,8 +252,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
54473
54474 fd = fanotify_event_metadata.fd;
54475 ret = -EFAULT;
54476- if (copy_to_user(buf, &fanotify_event_metadata,
54477- fanotify_event_metadata.event_len))
54478+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
54479+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
54480 goto out_close_fd;
54481
54482 ret = prepare_for_access_response(group, event, fd);
54483diff --git a/fs/notify/notification.c b/fs/notify/notification.c
54484index 7b51b05..5ea5ef6 100644
54485--- a/fs/notify/notification.c
54486+++ b/fs/notify/notification.c
54487@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
54488 * get set to 0 so it will never get 'freed'
54489 */
54490 static struct fsnotify_event *q_overflow_event;
54491-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54492+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54493
54494 /**
54495 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
54496@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54497 */
54498 u32 fsnotify_get_cookie(void)
54499 {
54500- return atomic_inc_return(&fsnotify_sync_cookie);
54501+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
54502 }
54503 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
54504
54505diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
54506index aa411c3..c260a84 100644
54507--- a/fs/ntfs/dir.c
54508+++ b/fs/ntfs/dir.c
54509@@ -1329,7 +1329,7 @@ find_next_index_buffer:
54510 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
54511 ~(s64)(ndir->itype.index.block_size - 1)));
54512 /* Bounds checks. */
54513- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54514+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54515 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
54516 "inode 0x%lx or driver bug.", vdir->i_ino);
54517 goto err_out;
54518diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
54519index 5b2d4f0..c6de396 100644
54520--- a/fs/ntfs/file.c
54521+++ b/fs/ntfs/file.c
54522@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
54523 #endif /* NTFS_RW */
54524 };
54525
54526-const struct file_operations ntfs_empty_file_ops = {};
54527+const struct file_operations ntfs_empty_file_ops __read_only;
54528
54529-const struct inode_operations ntfs_empty_inode_ops = {};
54530+const struct inode_operations ntfs_empty_inode_ops __read_only;
54531diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
54532index aebeacd..0dcdd26 100644
54533--- a/fs/ocfs2/localalloc.c
54534+++ b/fs/ocfs2/localalloc.c
54535@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
54536 goto bail;
54537 }
54538
54539- atomic_inc(&osb->alloc_stats.moves);
54540+ atomic_inc_unchecked(&osb->alloc_stats.moves);
54541
54542 bail:
54543 if (handle)
54544diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
54545index d355e6e..578d905 100644
54546--- a/fs/ocfs2/ocfs2.h
54547+++ b/fs/ocfs2/ocfs2.h
54548@@ -235,11 +235,11 @@ enum ocfs2_vol_state
54549
54550 struct ocfs2_alloc_stats
54551 {
54552- atomic_t moves;
54553- atomic_t local_data;
54554- atomic_t bitmap_data;
54555- atomic_t bg_allocs;
54556- atomic_t bg_extends;
54557+ atomic_unchecked_t moves;
54558+ atomic_unchecked_t local_data;
54559+ atomic_unchecked_t bitmap_data;
54560+ atomic_unchecked_t bg_allocs;
54561+ atomic_unchecked_t bg_extends;
54562 };
54563
54564 enum ocfs2_local_alloc_state
54565diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
54566index b7e74b5..19c6536 100644
54567--- a/fs/ocfs2/suballoc.c
54568+++ b/fs/ocfs2/suballoc.c
54569@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
54570 mlog_errno(status);
54571 goto bail;
54572 }
54573- atomic_inc(&osb->alloc_stats.bg_extends);
54574+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
54575
54576 /* You should never ask for this much metadata */
54577 BUG_ON(bits_wanted >
54578@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
54579 mlog_errno(status);
54580 goto bail;
54581 }
54582- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54583+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54584
54585 *suballoc_loc = res.sr_bg_blkno;
54586 *suballoc_bit_start = res.sr_bit_offset;
54587@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
54588 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
54589 res->sr_bits);
54590
54591- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54592+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54593
54594 BUG_ON(res->sr_bits != 1);
54595
54596@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
54597 mlog_errno(status);
54598 goto bail;
54599 }
54600- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54601+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54602
54603 BUG_ON(res.sr_bits != 1);
54604
54605@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54606 cluster_start,
54607 num_clusters);
54608 if (!status)
54609- atomic_inc(&osb->alloc_stats.local_data);
54610+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
54611 } else {
54612 if (min_clusters > (osb->bitmap_cpg - 1)) {
54613 /* The only paths asking for contiguousness
54614@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54615 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
54616 res.sr_bg_blkno,
54617 res.sr_bit_offset);
54618- atomic_inc(&osb->alloc_stats.bitmap_data);
54619+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
54620 *num_clusters = res.sr_bits;
54621 }
54622 }
54623diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
54624index 01b8516..579c4df 100644
54625--- a/fs/ocfs2/super.c
54626+++ b/fs/ocfs2/super.c
54627@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
54628 "%10s => GlobalAllocs: %d LocalAllocs: %d "
54629 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
54630 "Stats",
54631- atomic_read(&osb->alloc_stats.bitmap_data),
54632- atomic_read(&osb->alloc_stats.local_data),
54633- atomic_read(&osb->alloc_stats.bg_allocs),
54634- atomic_read(&osb->alloc_stats.moves),
54635- atomic_read(&osb->alloc_stats.bg_extends));
54636+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
54637+ atomic_read_unchecked(&osb->alloc_stats.local_data),
54638+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
54639+ atomic_read_unchecked(&osb->alloc_stats.moves),
54640+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
54641
54642 out += snprintf(buf + out, len - out,
54643 "%10s => State: %u Descriptor: %llu Size: %u bits "
54644@@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
54645 spin_lock_init(&osb->osb_xattr_lock);
54646 ocfs2_init_steal_slots(osb);
54647
54648- atomic_set(&osb->alloc_stats.moves, 0);
54649- atomic_set(&osb->alloc_stats.local_data, 0);
54650- atomic_set(&osb->alloc_stats.bitmap_data, 0);
54651- atomic_set(&osb->alloc_stats.bg_allocs, 0);
54652- atomic_set(&osb->alloc_stats.bg_extends, 0);
54653+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
54654+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
54655+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
54656+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
54657+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
54658
54659 /* Copy the blockcheck stats from the superblock probe */
54660 osb->osb_ecc_stats = *stats;
54661diff --git a/fs/open.c b/fs/open.c
54662index 6835446..eadf09f 100644
54663--- a/fs/open.c
54664+++ b/fs/open.c
54665@@ -32,6 +32,8 @@
54666 #include <linux/dnotify.h>
54667 #include <linux/compat.h>
54668
54669+#define CREATE_TRACE_POINTS
54670+#include <trace/events/fs.h>
54671 #include "internal.h"
54672
54673 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54674@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
54675 error = locks_verify_truncate(inode, NULL, length);
54676 if (!error)
54677 error = security_path_truncate(path);
54678+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54679+ error = -EACCES;
54680 if (!error)
54681 error = do_truncate(path->dentry, length, 0, NULL);
54682
54683@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54684 error = locks_verify_truncate(inode, f.file, length);
54685 if (!error)
54686 error = security_path_truncate(&f.file->f_path);
54687+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54688+ error = -EACCES;
54689 if (!error)
54690 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54691 sb_end_write(inode->i_sb);
54692@@ -388,6 +394,9 @@ retry:
54693 if (__mnt_is_readonly(path.mnt))
54694 res = -EROFS;
54695
54696+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54697+ res = -EACCES;
54698+
54699 out_path_release:
54700 path_put(&path);
54701 if (retry_estale(res, lookup_flags)) {
54702@@ -419,6 +428,8 @@ retry:
54703 if (error)
54704 goto dput_and_out;
54705
54706+ gr_log_chdir(path.dentry, path.mnt);
54707+
54708 set_fs_pwd(current->fs, &path);
54709
54710 dput_and_out:
54711@@ -448,6 +459,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54712 goto out_putf;
54713
54714 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54715+
54716+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54717+ error = -EPERM;
54718+
54719+ if (!error)
54720+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54721+
54722 if (!error)
54723 set_fs_pwd(current->fs, &f.file->f_path);
54724 out_putf:
54725@@ -477,7 +495,13 @@ retry:
54726 if (error)
54727 goto dput_and_out;
54728
54729+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54730+ goto dput_and_out;
54731+
54732 set_fs_root(current->fs, &path);
54733+
54734+ gr_handle_chroot_chdir(&path);
54735+
54736 error = 0;
54737 dput_and_out:
54738 path_put(&path);
54739@@ -499,6 +523,16 @@ static int chmod_common(struct path *path, umode_t mode)
54740 if (error)
54741 return error;
54742 mutex_lock(&inode->i_mutex);
54743+
54744+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54745+ error = -EACCES;
54746+ goto out_unlock;
54747+ }
54748+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54749+ error = -EACCES;
54750+ goto out_unlock;
54751+ }
54752+
54753 error = security_path_chmod(path, mode);
54754 if (error)
54755 goto out_unlock;
54756@@ -559,6 +593,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54757 uid = make_kuid(current_user_ns(), user);
54758 gid = make_kgid(current_user_ns(), group);
54759
54760+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54761+ return -EACCES;
54762+
54763 newattrs.ia_valid = ATTR_CTIME;
54764 if (user != (uid_t) -1) {
54765 if (!uid_valid(uid))
54766@@ -974,6 +1011,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54767 } else {
54768 fsnotify_open(f);
54769 fd_install(fd, f);
54770+ trace_do_sys_open(tmp->name, flags, mode);
54771 }
54772 }
54773 putname(tmp);
54774diff --git a/fs/pipe.c b/fs/pipe.c
54775index 2234f3f..f9083a1 100644
54776--- a/fs/pipe.c
54777+++ b/fs/pipe.c
54778@@ -438,9 +438,9 @@ redo:
54779 }
54780 if (bufs) /* More to do? */
54781 continue;
54782- if (!pipe->writers)
54783+ if (!atomic_read(&pipe->writers))
54784 break;
54785- if (!pipe->waiting_writers) {
54786+ if (!atomic_read(&pipe->waiting_writers)) {
54787 /* syscall merging: Usually we must not sleep
54788 * if O_NONBLOCK is set, or if we got some data.
54789 * But if a writer sleeps in kernel space, then
54790@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54791 mutex_lock(&inode->i_mutex);
54792 pipe = inode->i_pipe;
54793
54794- if (!pipe->readers) {
54795+ if (!atomic_read(&pipe->readers)) {
54796 send_sig(SIGPIPE, current, 0);
54797 ret = -EPIPE;
54798 goto out;
54799@@ -553,7 +553,7 @@ redo1:
54800 for (;;) {
54801 int bufs;
54802
54803- if (!pipe->readers) {
54804+ if (!atomic_read(&pipe->readers)) {
54805 send_sig(SIGPIPE, current, 0);
54806 if (!ret)
54807 ret = -EPIPE;
54808@@ -644,9 +644,9 @@ redo2:
54809 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54810 do_wakeup = 0;
54811 }
54812- pipe->waiting_writers++;
54813+ atomic_inc(&pipe->waiting_writers);
54814 pipe_wait(pipe);
54815- pipe->waiting_writers--;
54816+ atomic_dec(&pipe->waiting_writers);
54817 }
54818 out:
54819 mutex_unlock(&inode->i_mutex);
54820@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54821 mask = 0;
54822 if (filp->f_mode & FMODE_READ) {
54823 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54824- if (!pipe->writers && filp->f_version != pipe->w_counter)
54825+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54826 mask |= POLLHUP;
54827 }
54828
54829@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54830 * Most Unices do not set POLLERR for FIFOs but on Linux they
54831 * behave exactly like pipes for poll().
54832 */
54833- if (!pipe->readers)
54834+ if (!atomic_read(&pipe->readers))
54835 mask |= POLLERR;
54836 }
54837
54838@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
54839
54840 mutex_lock(&inode->i_mutex);
54841 pipe = inode->i_pipe;
54842- pipe->readers -= decr;
54843- pipe->writers -= decw;
54844+ atomic_sub(decr, &pipe->readers);
54845+ atomic_sub(decw, &pipe->writers);
54846
54847- if (!pipe->readers && !pipe->writers) {
54848+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
54849 free_pipe_info(inode);
54850 } else {
54851 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54852@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
54853
54854 if (inode->i_pipe) {
54855 ret = 0;
54856- inode->i_pipe->readers++;
54857+ atomic_inc(&inode->i_pipe->readers);
54858 }
54859
54860 mutex_unlock(&inode->i_mutex);
54861@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
54862
54863 if (inode->i_pipe) {
54864 ret = 0;
54865- inode->i_pipe->writers++;
54866+ atomic_inc(&inode->i_pipe->writers);
54867 }
54868
54869 mutex_unlock(&inode->i_mutex);
54870@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54871 if (inode->i_pipe) {
54872 ret = 0;
54873 if (filp->f_mode & FMODE_READ)
54874- inode->i_pipe->readers++;
54875+ atomic_inc(&inode->i_pipe->readers);
54876 if (filp->f_mode & FMODE_WRITE)
54877- inode->i_pipe->writers++;
54878+ atomic_inc(&inode->i_pipe->writers);
54879 }
54880
54881 mutex_unlock(&inode->i_mutex);
54882@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54883 inode->i_pipe = NULL;
54884 }
54885
54886-static struct vfsmount *pipe_mnt __read_mostly;
54887+struct vfsmount *pipe_mnt __read_mostly;
54888
54889 /*
54890 * pipefs_dname() is called from d_path().
54891@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54892 goto fail_iput;
54893 inode->i_pipe = pipe;
54894
54895- pipe->readers = pipe->writers = 1;
54896+ atomic_set(&pipe->readers, 1);
54897+ atomic_set(&pipe->writers, 1);
54898 inode->i_fop = &rdwr_pipefifo_fops;
54899
54900 /*
54901diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54902index 15af622..0e9f4467 100644
54903--- a/fs/proc/Kconfig
54904+++ b/fs/proc/Kconfig
54905@@ -30,12 +30,12 @@ config PROC_FS
54906
54907 config PROC_KCORE
54908 bool "/proc/kcore support" if !ARM
54909- depends on PROC_FS && MMU
54910+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
54911
54912 config PROC_VMCORE
54913 bool "/proc/vmcore support"
54914- depends on PROC_FS && CRASH_DUMP
54915- default y
54916+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
54917+ default n
54918 help
54919 Exports the dump image of crashed kernel in ELF format.
54920
54921@@ -59,8 +59,8 @@ config PROC_SYSCTL
54922 limited in memory.
54923
54924 config PROC_PAGE_MONITOR
54925- default y
54926- depends on PROC_FS && MMU
54927+ default n
54928+ depends on PROC_FS && MMU && !GRKERNSEC
54929 bool "Enable /proc page monitoring" if EXPERT
54930 help
54931 Various /proc files exist to monitor process memory utilization:
54932diff --git a/fs/proc/array.c b/fs/proc/array.c
54933index cbd0f1b..adec3f0 100644
54934--- a/fs/proc/array.c
54935+++ b/fs/proc/array.c
54936@@ -60,6 +60,7 @@
54937 #include <linux/tty.h>
54938 #include <linux/string.h>
54939 #include <linux/mman.h>
54940+#include <linux/grsecurity.h>
54941 #include <linux/proc_fs.h>
54942 #include <linux/ioport.h>
54943 #include <linux/uaccess.h>
54944@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
54945 seq_putc(m, '\n');
54946 }
54947
54948+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54949+static inline void task_pax(struct seq_file *m, struct task_struct *p)
54950+{
54951+ if (p->mm)
54952+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
54953+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
54954+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
54955+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
54956+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
54957+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
54958+ else
54959+ seq_printf(m, "PaX:\t-----\n");
54960+}
54961+#endif
54962+
54963 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54964 struct pid *pid, struct task_struct *task)
54965 {
54966@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54967 task_cpus_allowed(m, task);
54968 cpuset_task_status_allowed(m, task);
54969 task_context_switch_counts(m, task);
54970+
54971+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54972+ task_pax(m, task);
54973+#endif
54974+
54975+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
54976+ task_grsec_rbac(m, task);
54977+#endif
54978+
54979 return 0;
54980 }
54981
54982+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54983+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54984+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54985+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54986+#endif
54987+
54988 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54989 struct pid *pid, struct task_struct *task, int whole)
54990 {
54991@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54992 char tcomm[sizeof(task->comm)];
54993 unsigned long flags;
54994
54995+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54996+ if (current->exec_id != m->exec_id) {
54997+ gr_log_badprocpid("stat");
54998+ return 0;
54999+ }
55000+#endif
55001+
55002 state = *get_task_state(task);
55003 vsize = eip = esp = 0;
55004 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55005@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55006 gtime = task_gtime(task);
55007 }
55008
55009+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55010+ if (PAX_RAND_FLAGS(mm)) {
55011+ eip = 0;
55012+ esp = 0;
55013+ wchan = 0;
55014+ }
55015+#endif
55016+#ifdef CONFIG_GRKERNSEC_HIDESYM
55017+ wchan = 0;
55018+ eip =0;
55019+ esp =0;
55020+#endif
55021+
55022 /* scale priority and nice values from timeslices to -20..20 */
55023 /* to make it look like a "normal" Unix priority/nice value */
55024 priority = task_prio(task);
55025@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55026 seq_put_decimal_ull(m, ' ', vsize);
55027 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
55028 seq_put_decimal_ull(m, ' ', rsslim);
55029+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55030+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
55031+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
55032+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
55033+#else
55034 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
55035 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
55036 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
55037+#endif
55038 seq_put_decimal_ull(m, ' ', esp);
55039 seq_put_decimal_ull(m, ' ', eip);
55040 /* The signal information here is obsolete.
55041@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55042 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
55043 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
55044
55045- if (mm && permitted) {
55046+ if (mm && permitted
55047+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55048+ && !PAX_RAND_FLAGS(mm)
55049+#endif
55050+ ) {
55051 seq_put_decimal_ull(m, ' ', mm->start_data);
55052 seq_put_decimal_ull(m, ' ', mm->end_data);
55053 seq_put_decimal_ull(m, ' ', mm->start_brk);
55054@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55055 struct pid *pid, struct task_struct *task)
55056 {
55057 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
55058- struct mm_struct *mm = get_task_mm(task);
55059+ struct mm_struct *mm;
55060
55061+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55062+ if (current->exec_id != m->exec_id) {
55063+ gr_log_badprocpid("statm");
55064+ return 0;
55065+ }
55066+#endif
55067+ mm = get_task_mm(task);
55068 if (mm) {
55069 size = task_statm(mm, &shared, &text, &data, &resident);
55070 mmput(mm);
55071@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55072 return 0;
55073 }
55074
55075+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55076+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
55077+{
55078+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
55079+}
55080+#endif
55081+
55082 #ifdef CONFIG_CHECKPOINT_RESTORE
55083 static struct pid *
55084 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
55085diff --git a/fs/proc/base.c b/fs/proc/base.c
55086index 69078c7..3e12a75 100644
55087--- a/fs/proc/base.c
55088+++ b/fs/proc/base.c
55089@@ -112,6 +112,14 @@ struct pid_entry {
55090 union proc_op op;
55091 };
55092
55093+struct getdents_callback {
55094+ struct linux_dirent __user * current_dir;
55095+ struct linux_dirent __user * previous;
55096+ struct file * file;
55097+ int count;
55098+ int error;
55099+};
55100+
55101 #define NOD(NAME, MODE, IOP, FOP, OP) { \
55102 .name = (NAME), \
55103 .len = sizeof(NAME) - 1, \
55104@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
55105 if (!mm->arg_end)
55106 goto out_mm; /* Shh! No looking before we're done */
55107
55108+ if (gr_acl_handle_procpidmem(task))
55109+ goto out_mm;
55110+
55111 len = mm->arg_end - mm->arg_start;
55112
55113 if (len > PAGE_SIZE)
55114@@ -236,12 +247,28 @@ out:
55115 return res;
55116 }
55117
55118+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55119+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55120+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55121+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55122+#endif
55123+
55124 static int proc_pid_auxv(struct task_struct *task, char *buffer)
55125 {
55126 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
55127 int res = PTR_ERR(mm);
55128 if (mm && !IS_ERR(mm)) {
55129 unsigned int nwords = 0;
55130+
55131+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55132+ /* allow if we're currently ptracing this task */
55133+ if (PAX_RAND_FLAGS(mm) &&
55134+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
55135+ mmput(mm);
55136+ return 0;
55137+ }
55138+#endif
55139+
55140 do {
55141 nwords += 2;
55142 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
55143@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
55144 }
55145
55146
55147-#ifdef CONFIG_KALLSYMS
55148+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55149 /*
55150 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
55151 * Returns the resolved symbol. If that fails, simply return the address.
55152@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
55153 mutex_unlock(&task->signal->cred_guard_mutex);
55154 }
55155
55156-#ifdef CONFIG_STACKTRACE
55157+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55158
55159 #define MAX_STACK_TRACE_DEPTH 64
55160
55161@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
55162 return count;
55163 }
55164
55165-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55166+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55167 static int proc_pid_syscall(struct task_struct *task, char *buffer)
55168 {
55169 long nr;
55170@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
55171 /************************************************************************/
55172
55173 /* permission checks */
55174-static int proc_fd_access_allowed(struct inode *inode)
55175+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
55176 {
55177 struct task_struct *task;
55178 int allowed = 0;
55179@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
55180 */
55181 task = get_proc_task(inode);
55182 if (task) {
55183- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55184+ if (log)
55185+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55186+ else
55187+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55188 put_task_struct(task);
55189 }
55190 return allowed;
55191@@ -556,10 +586,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
55192 struct task_struct *task,
55193 int hide_pid_min)
55194 {
55195+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55196+ return false;
55197+
55198+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55199+ rcu_read_lock();
55200+ {
55201+ const struct cred *tmpcred = current_cred();
55202+ const struct cred *cred = __task_cred(task);
55203+
55204+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
55205+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55206+ || in_group_p(grsec_proc_gid)
55207+#endif
55208+ ) {
55209+ rcu_read_unlock();
55210+ return true;
55211+ }
55212+ }
55213+ rcu_read_unlock();
55214+
55215+ if (!pid->hide_pid)
55216+ return false;
55217+#endif
55218+
55219 if (pid->hide_pid < hide_pid_min)
55220 return true;
55221 if (in_group_p(pid->pid_gid))
55222 return true;
55223+
55224 return ptrace_may_access(task, PTRACE_MODE_READ);
55225 }
55226
55227@@ -577,7 +632,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
55228 put_task_struct(task);
55229
55230 if (!has_perms) {
55231+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55232+ {
55233+#else
55234 if (pid->hide_pid == 2) {
55235+#endif
55236 /*
55237 * Let's make getdents(), stat(), and open()
55238 * consistent with each other. If a process
55239@@ -675,6 +734,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55240 if (!task)
55241 return -ESRCH;
55242
55243+ if (gr_acl_handle_procpidmem(task)) {
55244+ put_task_struct(task);
55245+ return -EPERM;
55246+ }
55247+
55248 mm = mm_access(task, mode);
55249 put_task_struct(task);
55250
55251@@ -690,6 +754,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55252
55253 file->private_data = mm;
55254
55255+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55256+ file->f_version = current->exec_id;
55257+#endif
55258+
55259 return 0;
55260 }
55261
55262@@ -711,6 +779,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55263 ssize_t copied;
55264 char *page;
55265
55266+#ifdef CONFIG_GRKERNSEC
55267+ if (write)
55268+ return -EPERM;
55269+#endif
55270+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55271+ if (file->f_version != current->exec_id) {
55272+ gr_log_badprocpid("mem");
55273+ return 0;
55274+ }
55275+#endif
55276+
55277 if (!mm)
55278 return 0;
55279
55280@@ -723,7 +802,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55281 goto free;
55282
55283 while (count > 0) {
55284- int this_len = min_t(int, count, PAGE_SIZE);
55285+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
55286
55287 if (write && copy_from_user(page, buf, this_len)) {
55288 copied = -EFAULT;
55289@@ -815,6 +894,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55290 if (!mm)
55291 return 0;
55292
55293+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55294+ if (file->f_version != current->exec_id) {
55295+ gr_log_badprocpid("environ");
55296+ return 0;
55297+ }
55298+#endif
55299+
55300 page = (char *)__get_free_page(GFP_TEMPORARY);
55301 if (!page)
55302 return -ENOMEM;
55303@@ -824,7 +910,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55304 goto free;
55305 while (count > 0) {
55306 size_t this_len, max_len;
55307- int retval;
55308+ ssize_t retval;
55309
55310 if (src >= (mm->env_end - mm->env_start))
55311 break;
55312@@ -1430,7 +1516,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
55313 int error = -EACCES;
55314
55315 /* Are we allowed to snoop on the tasks file descriptors? */
55316- if (!proc_fd_access_allowed(inode))
55317+ if (!proc_fd_access_allowed(inode, 0))
55318 goto out;
55319
55320 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55321@@ -1474,8 +1560,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
55322 struct path path;
55323
55324 /* Are we allowed to snoop on the tasks file descriptors? */
55325- if (!proc_fd_access_allowed(inode))
55326- goto out;
55327+ /* logging this is needed for learning on chromium to work properly,
55328+ but we don't want to flood the logs from 'ps' which does a readlink
55329+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
55330+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
55331+ */
55332+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
55333+ if (!proc_fd_access_allowed(inode,0))
55334+ goto out;
55335+ } else {
55336+ if (!proc_fd_access_allowed(inode,1))
55337+ goto out;
55338+ }
55339
55340 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55341 if (error)
55342@@ -1525,7 +1621,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
55343 rcu_read_lock();
55344 cred = __task_cred(task);
55345 inode->i_uid = cred->euid;
55346+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55347+ inode->i_gid = grsec_proc_gid;
55348+#else
55349 inode->i_gid = cred->egid;
55350+#endif
55351 rcu_read_unlock();
55352 }
55353 security_task_to_inode(task, inode);
55354@@ -1561,10 +1661,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55355 return -ENOENT;
55356 }
55357 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55358+#ifdef CONFIG_GRKERNSEC_PROC_USER
55359+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55360+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55361+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55362+#endif
55363 task_dumpable(task)) {
55364 cred = __task_cred(task);
55365 stat->uid = cred->euid;
55366+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55367+ stat->gid = grsec_proc_gid;
55368+#else
55369 stat->gid = cred->egid;
55370+#endif
55371 }
55372 }
55373 rcu_read_unlock();
55374@@ -1602,11 +1711,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
55375
55376 if (task) {
55377 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55378+#ifdef CONFIG_GRKERNSEC_PROC_USER
55379+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55380+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55381+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55382+#endif
55383 task_dumpable(task)) {
55384 rcu_read_lock();
55385 cred = __task_cred(task);
55386 inode->i_uid = cred->euid;
55387+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55388+ inode->i_gid = grsec_proc_gid;
55389+#else
55390 inode->i_gid = cred->egid;
55391+#endif
55392 rcu_read_unlock();
55393 } else {
55394 inode->i_uid = GLOBAL_ROOT_UID;
55395@@ -2059,6 +2177,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
55396 if (!task)
55397 goto out_no_task;
55398
55399+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55400+ goto out;
55401+
55402 /*
55403 * Yes, it does not scale. And it should not. Don't add
55404 * new entries into /proc/<tgid>/ without very good reasons.
55405@@ -2103,6 +2224,9 @@ static int proc_pident_readdir(struct file *filp,
55406 if (!task)
55407 goto out_no_task;
55408
55409+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55410+ goto out;
55411+
55412 ret = 0;
55413 i = filp->f_pos;
55414 switch (i) {
55415@@ -2516,7 +2640,7 @@ static const struct pid_entry tgid_base_stuff[] = {
55416 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
55417 #endif
55418 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55419-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55420+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55421 INF("syscall", S_IRUGO, proc_pid_syscall),
55422 #endif
55423 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55424@@ -2541,10 +2665,10 @@ static const struct pid_entry tgid_base_stuff[] = {
55425 #ifdef CONFIG_SECURITY
55426 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55427 #endif
55428-#ifdef CONFIG_KALLSYMS
55429+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55430 INF("wchan", S_IRUGO, proc_pid_wchan),
55431 #endif
55432-#ifdef CONFIG_STACKTRACE
55433+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55434 ONE("stack", S_IRUGO, proc_pid_stack),
55435 #endif
55436 #ifdef CONFIG_SCHEDSTATS
55437@@ -2578,6 +2702,9 @@ static const struct pid_entry tgid_base_stuff[] = {
55438 #ifdef CONFIG_HARDWALL
55439 INF("hardwall", S_IRUGO, proc_pid_hardwall),
55440 #endif
55441+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55442+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
55443+#endif
55444 #ifdef CONFIG_USER_NS
55445 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
55446 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
55447@@ -2707,7 +2834,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
55448 if (!inode)
55449 goto out;
55450
55451+#ifdef CONFIG_GRKERNSEC_PROC_USER
55452+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
55453+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55454+ inode->i_gid = grsec_proc_gid;
55455+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
55456+#else
55457 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
55458+#endif
55459 inode->i_op = &proc_tgid_base_inode_operations;
55460 inode->i_fop = &proc_tgid_base_operations;
55461 inode->i_flags|=S_IMMUTABLE;
55462@@ -2745,7 +2879,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
55463 if (!task)
55464 goto out;
55465
55466+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55467+ goto out_put_task;
55468+
55469 result = proc_pid_instantiate(dir, dentry, task, NULL);
55470+out_put_task:
55471 put_task_struct(task);
55472 out:
55473 return result;
55474@@ -2808,6 +2946,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
55475 static int fake_filldir(void *buf, const char *name, int namelen,
55476 loff_t offset, u64 ino, unsigned d_type)
55477 {
55478+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
55479+ __buf->error = -EINVAL;
55480 return 0;
55481 }
55482
55483@@ -2859,7 +2999,7 @@ static const struct pid_entry tid_base_stuff[] = {
55484 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
55485 #endif
55486 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55487-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55488+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55489 INF("syscall", S_IRUGO, proc_pid_syscall),
55490 #endif
55491 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55492@@ -2886,10 +3026,10 @@ static const struct pid_entry tid_base_stuff[] = {
55493 #ifdef CONFIG_SECURITY
55494 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55495 #endif
55496-#ifdef CONFIG_KALLSYMS
55497+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55498 INF("wchan", S_IRUGO, proc_pid_wchan),
55499 #endif
55500-#ifdef CONFIG_STACKTRACE
55501+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55502 ONE("stack", S_IRUGO, proc_pid_stack),
55503 #endif
55504 #ifdef CONFIG_SCHEDSTATS
55505diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
55506index 82676e3..5f8518a 100644
55507--- a/fs/proc/cmdline.c
55508+++ b/fs/proc/cmdline.c
55509@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
55510
55511 static int __init proc_cmdline_init(void)
55512 {
55513+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55514+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
55515+#else
55516 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
55517+#endif
55518 return 0;
55519 }
55520 module_init(proc_cmdline_init);
55521diff --git a/fs/proc/devices.c b/fs/proc/devices.c
55522index b143471..bb105e5 100644
55523--- a/fs/proc/devices.c
55524+++ b/fs/proc/devices.c
55525@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
55526
55527 static int __init proc_devices_init(void)
55528 {
55529+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55530+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
55531+#else
55532 proc_create("devices", 0, NULL, &proc_devinfo_operations);
55533+#endif
55534 return 0;
55535 }
55536 module_init(proc_devices_init);
55537diff --git a/fs/proc/fd.c b/fs/proc/fd.c
55538index d7a4a28..0201742 100644
55539--- a/fs/proc/fd.c
55540+++ b/fs/proc/fd.c
55541@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
55542 if (!task)
55543 return -ENOENT;
55544
55545- files = get_files_struct(task);
55546+ if (!gr_acl_handle_procpidmem(task))
55547+ files = get_files_struct(task);
55548 put_task_struct(task);
55549
55550 if (files) {
55551@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
55552 */
55553 int proc_fd_permission(struct inode *inode, int mask)
55554 {
55555+ struct task_struct *task;
55556 int rv = generic_permission(inode, mask);
55557- if (rv == 0)
55558- return 0;
55559+
55560 if (task_pid(current) == proc_pid(inode))
55561 rv = 0;
55562+
55563+ task = get_proc_task(inode);
55564+ if (task == NULL)
55565+ return rv;
55566+
55567+ if (gr_acl_handle_procpidmem(task))
55568+ rv = -EACCES;
55569+
55570+ put_task_struct(task);
55571+
55572 return rv;
55573 }
55574
55575diff --git a/fs/proc/inode.c b/fs/proc/inode.c
55576index 869116c..820cb27 100644
55577--- a/fs/proc/inode.c
55578+++ b/fs/proc/inode.c
55579@@ -22,11 +22,17 @@
55580 #include <linux/seq_file.h>
55581 #include <linux/slab.h>
55582 #include <linux/mount.h>
55583+#include <linux/grsecurity.h>
55584
55585 #include <asm/uaccess.h>
55586
55587 #include "internal.h"
55588
55589+#ifdef CONFIG_PROC_SYSCTL
55590+extern const struct inode_operations proc_sys_inode_operations;
55591+extern const struct inode_operations proc_sys_dir_operations;
55592+#endif
55593+
55594 static void proc_evict_inode(struct inode *inode)
55595 {
55596 struct proc_dir_entry *de;
55597@@ -54,6 +60,13 @@ static void proc_evict_inode(struct inode *inode)
55598 ns = PROC_I(inode)->ns;
55599 if (ns_ops && ns)
55600 ns_ops->put(ns);
55601+
55602+#ifdef CONFIG_PROC_SYSCTL
55603+ if (inode->i_op == &proc_sys_inode_operations ||
55604+ inode->i_op == &proc_sys_dir_operations)
55605+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
55606+#endif
55607+
55608 }
55609
55610 static struct kmem_cache * proc_inode_cachep;
55611@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
55612 if (de->mode) {
55613 inode->i_mode = de->mode;
55614 inode->i_uid = de->uid;
55615+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55616+ inode->i_gid = grsec_proc_gid;
55617+#else
55618 inode->i_gid = de->gid;
55619+#endif
55620 }
55621 if (de->size)
55622 inode->i_size = de->size;
55623diff --git a/fs/proc/internal.h b/fs/proc/internal.h
55624index 85ff3a4..a512bd8 100644
55625--- a/fs/proc/internal.h
55626+++ b/fs/proc/internal.h
55627@@ -56,6 +56,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55628 struct pid *pid, struct task_struct *task);
55629 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55630 struct pid *pid, struct task_struct *task);
55631+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55632+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
55633+#endif
55634 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
55635
55636 extern const struct file_operations proc_tid_children_operations;
55637diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
55638index eda6f01..006ae24 100644
55639--- a/fs/proc/kcore.c
55640+++ b/fs/proc/kcore.c
55641@@ -481,9 +481,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55642 * the addresses in the elf_phdr on our list.
55643 */
55644 start = kc_offset_to_vaddr(*fpos - elf_buflen);
55645- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
55646+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
55647+ if (tsz > buflen)
55648 tsz = buflen;
55649-
55650+
55651 while (buflen) {
55652 struct kcore_list *m;
55653
55654@@ -512,20 +513,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55655 kfree(elf_buf);
55656 } else {
55657 if (kern_addr_valid(start)) {
55658- unsigned long n;
55659+ char *elf_buf;
55660+ mm_segment_t oldfs;
55661
55662- n = copy_to_user(buffer, (char *)start, tsz);
55663- /*
55664- * We cannot distinguish between fault on source
55665- * and fault on destination. When this happens
55666- * we clear too and hope it will trigger the
55667- * EFAULT again.
55668- */
55669- if (n) {
55670- if (clear_user(buffer + tsz - n,
55671- n))
55672+ elf_buf = kmalloc(tsz, GFP_KERNEL);
55673+ if (!elf_buf)
55674+ return -ENOMEM;
55675+ oldfs = get_fs();
55676+ set_fs(KERNEL_DS);
55677+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
55678+ set_fs(oldfs);
55679+ if (copy_to_user(buffer, elf_buf, tsz)) {
55680+ kfree(elf_buf);
55681 return -EFAULT;
55682+ }
55683 }
55684+ set_fs(oldfs);
55685+ kfree(elf_buf);
55686 } else {
55687 if (clear_user(buffer, tsz))
55688 return -EFAULT;
55689@@ -545,6 +549,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55690
55691 static int open_kcore(struct inode *inode, struct file *filp)
55692 {
55693+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55694+ return -EPERM;
55695+#endif
55696 if (!capable(CAP_SYS_RAWIO))
55697 return -EPERM;
55698 if (kcore_need_update)
55699diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55700index 1efaaa1..834e49a 100644
55701--- a/fs/proc/meminfo.c
55702+++ b/fs/proc/meminfo.c
55703@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55704 vmi.used >> 10,
55705 vmi.largest_chunk >> 10
55706 #ifdef CONFIG_MEMORY_FAILURE
55707- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55708+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55709 #endif
55710 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55711 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
55712diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
55713index ccfd99b..1b7e255 100644
55714--- a/fs/proc/nommu.c
55715+++ b/fs/proc/nommu.c
55716@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
55717 if (len < 1)
55718 len = 1;
55719 seq_printf(m, "%*c", len, ' ');
55720- seq_path(m, &file->f_path, "");
55721+ seq_path(m, &file->f_path, "\n\\");
55722 }
55723
55724 seq_putc(m, '\n');
55725diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
55726index b4ac657..0842bd2 100644
55727--- a/fs/proc/proc_net.c
55728+++ b/fs/proc/proc_net.c
55729@@ -23,6 +23,7 @@
55730 #include <linux/nsproxy.h>
55731 #include <net/net_namespace.h>
55732 #include <linux/seq_file.h>
55733+#include <linux/grsecurity.h>
55734
55735 #include "internal.h"
55736
55737@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
55738 struct task_struct *task;
55739 struct nsproxy *ns;
55740 struct net *net = NULL;
55741+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55742+ const struct cred *cred = current_cred();
55743+#endif
55744+
55745+#ifdef CONFIG_GRKERNSEC_PROC_USER
55746+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
55747+ return net;
55748+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55749+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
55750+ return net;
55751+#endif
55752
55753 rcu_read_lock();
55754 task = pid_task(proc_pid(dir), PIDTYPE_PID);
55755diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
55756index ac05f33..1e6dc7e 100644
55757--- a/fs/proc/proc_sysctl.c
55758+++ b/fs/proc/proc_sysctl.c
55759@@ -13,11 +13,15 @@
55760 #include <linux/module.h>
55761 #include "internal.h"
55762
55763+extern int gr_handle_chroot_sysctl(const int op);
55764+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
55765+ const int op);
55766+
55767 static const struct dentry_operations proc_sys_dentry_operations;
55768 static const struct file_operations proc_sys_file_operations;
55769-static const struct inode_operations proc_sys_inode_operations;
55770+const struct inode_operations proc_sys_inode_operations;
55771 static const struct file_operations proc_sys_dir_file_operations;
55772-static const struct inode_operations proc_sys_dir_operations;
55773+const struct inode_operations proc_sys_dir_operations;
55774
55775 void proc_sys_poll_notify(struct ctl_table_poll *poll)
55776 {
55777@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
55778
55779 err = NULL;
55780 d_set_d_op(dentry, &proc_sys_dentry_operations);
55781+
55782+ gr_handle_proc_create(dentry, inode);
55783+
55784 d_add(dentry, inode);
55785
55786 out:
55787@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55788 struct inode *inode = file_inode(filp);
55789 struct ctl_table_header *head = grab_header(inode);
55790 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
55791+ int op = write ? MAY_WRITE : MAY_READ;
55792 ssize_t error;
55793 size_t res;
55794
55795@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55796 * and won't be until we finish.
55797 */
55798 error = -EPERM;
55799- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
55800+ if (sysctl_perm(head, table, op))
55801 goto out;
55802
55803 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55804@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55805 if (!table->proc_handler)
55806 goto out;
55807
55808+#ifdef CONFIG_GRKERNSEC
55809+ error = -EPERM;
55810+ if (gr_handle_chroot_sysctl(op))
55811+ goto out;
55812+ dget(filp->f_path.dentry);
55813+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55814+ dput(filp->f_path.dentry);
55815+ goto out;
55816+ }
55817+ dput(filp->f_path.dentry);
55818+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55819+ goto out;
55820+ if (write && !capable(CAP_SYS_ADMIN))
55821+ goto out;
55822+#endif
55823+
55824 /* careful: calling conventions are nasty here */
55825 res = count;
55826 error = table->proc_handler(table, write, buf, &res, ppos);
55827@@ -598,6 +622,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55828 return -ENOMEM;
55829 } else {
55830 d_set_d_op(child, &proc_sys_dentry_operations);
55831+
55832+ gr_handle_proc_create(child, inode);
55833+
55834 d_add(child, inode);
55835 }
55836 } else {
55837@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55838 if ((*pos)++ < file->f_pos)
55839 return 0;
55840
55841+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55842+ return 0;
55843+
55844 if (unlikely(S_ISLNK(table->mode)))
55845 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55846 else
55847@@ -751,6 +781,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55848 if (IS_ERR(head))
55849 return PTR_ERR(head);
55850
55851+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55852+ return -ENOENT;
55853+
55854 generic_fillattr(inode, stat);
55855 if (table)
55856 stat->mode = (stat->mode & S_IFMT) | table->mode;
55857@@ -773,13 +806,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55858 .llseek = generic_file_llseek,
55859 };
55860
55861-static const struct inode_operations proc_sys_inode_operations = {
55862+const struct inode_operations proc_sys_inode_operations = {
55863 .permission = proc_sys_permission,
55864 .setattr = proc_sys_setattr,
55865 .getattr = proc_sys_getattr,
55866 };
55867
55868-static const struct inode_operations proc_sys_dir_operations = {
55869+const struct inode_operations proc_sys_dir_operations = {
55870 .lookup = proc_sys_lookup,
55871 .permission = proc_sys_permission,
55872 .setattr = proc_sys_setattr,
55873@@ -855,7 +888,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55874 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55875 const char *name, int namelen)
55876 {
55877- struct ctl_table *table;
55878+ ctl_table_no_const *table;
55879 struct ctl_dir *new;
55880 struct ctl_node *node;
55881 char *new_name;
55882@@ -867,7 +900,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55883 return NULL;
55884
55885 node = (struct ctl_node *)(new + 1);
55886- table = (struct ctl_table *)(node + 1);
55887+ table = (ctl_table_no_const *)(node + 1);
55888 new_name = (char *)(table + 2);
55889 memcpy(new_name, name, namelen);
55890 new_name[namelen] = '\0';
55891@@ -1036,7 +1069,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55892 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55893 struct ctl_table_root *link_root)
55894 {
55895- struct ctl_table *link_table, *entry, *link;
55896+ ctl_table_no_const *link_table, *link;
55897+ struct ctl_table *entry;
55898 struct ctl_table_header *links;
55899 struct ctl_node *node;
55900 char *link_name;
55901@@ -1059,7 +1093,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55902 return NULL;
55903
55904 node = (struct ctl_node *)(links + 1);
55905- link_table = (struct ctl_table *)(node + nr_entries);
55906+ link_table = (ctl_table_no_const *)(node + nr_entries);
55907 link_name = (char *)&link_table[nr_entries + 1];
55908
55909 for (link = link_table, entry = table; entry->procname; link++, entry++) {
55910@@ -1307,8 +1341,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55911 struct ctl_table_header ***subheader, struct ctl_table_set *set,
55912 struct ctl_table *table)
55913 {
55914- struct ctl_table *ctl_table_arg = NULL;
55915- struct ctl_table *entry, *files;
55916+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
55917+ struct ctl_table *entry;
55918 int nr_files = 0;
55919 int nr_dirs = 0;
55920 int err = -ENOMEM;
55921@@ -1320,10 +1354,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55922 nr_files++;
55923 }
55924
55925- files = table;
55926 /* If there are mixed files and directories we need a new table */
55927 if (nr_dirs && nr_files) {
55928- struct ctl_table *new;
55929+ ctl_table_no_const *new;
55930 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
55931 GFP_KERNEL);
55932 if (!files)
55933@@ -1341,7 +1374,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55934 /* Register everything except a directory full of subdirectories */
55935 if (nr_files || !nr_dirs) {
55936 struct ctl_table_header *header;
55937- header = __register_sysctl_table(set, path, files);
55938+ header = __register_sysctl_table(set, path, files ? files : table);
55939 if (!header) {
55940 kfree(ctl_table_arg);
55941 goto out;
55942diff --git a/fs/proc/root.c b/fs/proc/root.c
55943index 9c7fab1..ed1c8e0 100644
55944--- a/fs/proc/root.c
55945+++ b/fs/proc/root.c
55946@@ -180,7 +180,15 @@ void __init proc_root_init(void)
55947 #ifdef CONFIG_PROC_DEVICETREE
55948 proc_device_tree_init();
55949 #endif
55950+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55951+#ifdef CONFIG_GRKERNSEC_PROC_USER
55952+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
55953+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55954+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
55955+#endif
55956+#else
55957 proc_mkdir("bus", NULL);
55958+#endif
55959 proc_sys_init();
55960 }
55961
55962diff --git a/fs/proc/self.c b/fs/proc/self.c
55963index aa5cc3b..c91a5d0 100644
55964--- a/fs/proc/self.c
55965+++ b/fs/proc/self.c
55966@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
55967 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
55968 void *cookie)
55969 {
55970- char *s = nd_get_link(nd);
55971+ const char *s = nd_get_link(nd);
55972 if (!IS_ERR(s))
55973 kfree(s);
55974 }
55975diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
55976index 3e636d8..83e3b71 100644
55977--- a/fs/proc/task_mmu.c
55978+++ b/fs/proc/task_mmu.c
55979@@ -11,12 +11,19 @@
55980 #include <linux/rmap.h>
55981 #include <linux/swap.h>
55982 #include <linux/swapops.h>
55983+#include <linux/grsecurity.h>
55984
55985 #include <asm/elf.h>
55986 #include <asm/uaccess.h>
55987 #include <asm/tlbflush.h>
55988 #include "internal.h"
55989
55990+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55991+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55992+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55993+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55994+#endif
55995+
55996 void task_mem(struct seq_file *m, struct mm_struct *mm)
55997 {
55998 unsigned long data, text, lib, swap;
55999@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56000 "VmExe:\t%8lu kB\n"
56001 "VmLib:\t%8lu kB\n"
56002 "VmPTE:\t%8lu kB\n"
56003- "VmSwap:\t%8lu kB\n",
56004- hiwater_vm << (PAGE_SHIFT-10),
56005+ "VmSwap:\t%8lu kB\n"
56006+
56007+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56008+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
56009+#endif
56010+
56011+ ,hiwater_vm << (PAGE_SHIFT-10),
56012 total_vm << (PAGE_SHIFT-10),
56013 mm->locked_vm << (PAGE_SHIFT-10),
56014 mm->pinned_vm << (PAGE_SHIFT-10),
56015@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56016 data << (PAGE_SHIFT-10),
56017 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
56018 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
56019- swap << (PAGE_SHIFT-10));
56020+ swap << (PAGE_SHIFT-10)
56021+
56022+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56023+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56024+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
56025+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
56026+#else
56027+ , mm->context.user_cs_base
56028+ , mm->context.user_cs_limit
56029+#endif
56030+#endif
56031+
56032+ );
56033 }
56034
56035 unsigned long task_vsize(struct mm_struct *mm)
56036@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56037 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
56038 }
56039
56040- /* We don't show the stack guard page in /proc/maps */
56041+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56042+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
56043+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
56044+#else
56045 start = vma->vm_start;
56046- if (stack_guard_page_start(vma, start))
56047- start += PAGE_SIZE;
56048 end = vma->vm_end;
56049- if (stack_guard_page_end(vma, end))
56050- end -= PAGE_SIZE;
56051+#endif
56052
56053 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
56054 start,
56055@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56056 flags & VM_WRITE ? 'w' : '-',
56057 flags & VM_EXEC ? 'x' : '-',
56058 flags & VM_MAYSHARE ? 's' : 'p',
56059+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56060+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
56061+#else
56062 pgoff,
56063+#endif
56064 MAJOR(dev), MINOR(dev), ino, &len);
56065
56066 /*
56067@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56068 */
56069 if (file) {
56070 pad_len_spaces(m, len);
56071- seq_path(m, &file->f_path, "\n");
56072+ seq_path(m, &file->f_path, "\n\\");
56073 goto done;
56074 }
56075
56076@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56077 * Thread stack in /proc/PID/task/TID/maps or
56078 * the main process stack.
56079 */
56080- if (!is_pid || (vma->vm_start <= mm->start_stack &&
56081- vma->vm_end >= mm->start_stack)) {
56082+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
56083+ (vma->vm_start <= mm->start_stack &&
56084+ vma->vm_end >= mm->start_stack)) {
56085 name = "[stack]";
56086 } else {
56087 /* Thread stack in /proc/PID/maps */
56088@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
56089 struct proc_maps_private *priv = m->private;
56090 struct task_struct *task = priv->task;
56091
56092+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56093+ if (current->exec_id != m->exec_id) {
56094+ gr_log_badprocpid("maps");
56095+ return 0;
56096+ }
56097+#endif
56098+
56099 show_map_vma(m, vma, is_pid);
56100
56101 if (m->count < m->size) /* vma is copied successfully */
56102@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56103 .private = &mss,
56104 };
56105
56106+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56107+ if (current->exec_id != m->exec_id) {
56108+ gr_log_badprocpid("smaps");
56109+ return 0;
56110+ }
56111+#endif
56112 memset(&mss, 0, sizeof mss);
56113- mss.vma = vma;
56114- /* mmap_sem is held in m_start */
56115- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56116- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56117-
56118+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56119+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
56120+#endif
56121+ mss.vma = vma;
56122+ /* mmap_sem is held in m_start */
56123+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56124+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56125+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56126+ }
56127+#endif
56128 show_map_vma(m, vma, is_pid);
56129
56130 seq_printf(m,
56131@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56132 "KernelPageSize: %8lu kB\n"
56133 "MMUPageSize: %8lu kB\n"
56134 "Locked: %8lu kB\n",
56135+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56136+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
56137+#else
56138 (vma->vm_end - vma->vm_start) >> 10,
56139+#endif
56140 mss.resident >> 10,
56141 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
56142 mss.shared_clean >> 10,
56143@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56144 int n;
56145 char buffer[50];
56146
56147+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56148+ if (current->exec_id != m->exec_id) {
56149+ gr_log_badprocpid("numa_maps");
56150+ return 0;
56151+ }
56152+#endif
56153+
56154 if (!mm)
56155 return 0;
56156
56157@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56158 mpol_to_str(buffer, sizeof(buffer), pol);
56159 mpol_cond_put(pol);
56160
56161+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56162+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
56163+#else
56164 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
56165+#endif
56166
56167 if (file) {
56168 seq_printf(m, " file=");
56169- seq_path(m, &file->f_path, "\n\t= ");
56170+ seq_path(m, &file->f_path, "\n\t\\= ");
56171 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
56172 seq_printf(m, " heap");
56173 } else {
56174diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
56175index 56123a6..5a2f6ec 100644
56176--- a/fs/proc/task_nommu.c
56177+++ b/fs/proc/task_nommu.c
56178@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56179 else
56180 bytes += kobjsize(mm);
56181
56182- if (current->fs && current->fs->users > 1)
56183+ if (current->fs && atomic_read(&current->fs->users) > 1)
56184 sbytes += kobjsize(current->fs);
56185 else
56186 bytes += kobjsize(current->fs);
56187@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
56188
56189 if (file) {
56190 pad_len_spaces(m, len);
56191- seq_path(m, &file->f_path, "");
56192+ seq_path(m, &file->f_path, "\n\\");
56193 } else if (mm) {
56194 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
56195
56196diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
56197index b870f74..e9048df 100644
56198--- a/fs/proc/vmcore.c
56199+++ b/fs/proc/vmcore.c
56200@@ -98,9 +98,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
56201 nr_bytes = count;
56202
56203 /* If pfn is not ram, return zeros for sparse dump files */
56204- if (pfn_is_ram(pfn) == 0)
56205- memset(buf, 0, nr_bytes);
56206- else {
56207+ if (pfn_is_ram(pfn) == 0) {
56208+ if (userbuf) {
56209+ if (clear_user((char __force_user *)buf, nr_bytes))
56210+ return -EFAULT;
56211+ } else
56212+ memset(buf, 0, nr_bytes);
56213+ } else {
56214 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
56215 offset, userbuf);
56216 if (tmp < 0)
56217@@ -185,7 +189,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
56218 if (tsz > nr_bytes)
56219 tsz = nr_bytes;
56220
56221- tmp = read_from_oldmem(buffer, tsz, &start, 1);
56222+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
56223 if (tmp < 0)
56224 return tmp;
56225 buflen -= tsz;
56226diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
56227index b00fcc9..e0c6381 100644
56228--- a/fs/qnx6/qnx6.h
56229+++ b/fs/qnx6/qnx6.h
56230@@ -74,7 +74,7 @@ enum {
56231 BYTESEX_BE,
56232 };
56233
56234-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56235+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56236 {
56237 if (sbi->s_bytesex == BYTESEX_LE)
56238 return le64_to_cpu((__force __le64)n);
56239@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
56240 return (__force __fs64)cpu_to_be64(n);
56241 }
56242
56243-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56244+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56245 {
56246 if (sbi->s_bytesex == BYTESEX_LE)
56247 return le32_to_cpu((__force __le32)n);
56248diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
56249index 16e8abb..2dcf914 100644
56250--- a/fs/quota/netlink.c
56251+++ b/fs/quota/netlink.c
56252@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
56253 void quota_send_warning(struct kqid qid, dev_t dev,
56254 const char warntype)
56255 {
56256- static atomic_t seq;
56257+ static atomic_unchecked_t seq;
56258 struct sk_buff *skb;
56259 void *msg_head;
56260 int ret;
56261@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
56262 "VFS: Not enough memory to send quota warning.\n");
56263 return;
56264 }
56265- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
56266+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
56267 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
56268 if (!msg_head) {
56269 printk(KERN_ERR
56270diff --git a/fs/read_write.c b/fs/read_write.c
56271index e6ddc8d..9155227 100644
56272--- a/fs/read_write.c
56273+++ b/fs/read_write.c
56274@@ -429,7 +429,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
56275
56276 old_fs = get_fs();
56277 set_fs(get_ds());
56278- p = (__force const char __user *)buf;
56279+ p = (const char __force_user *)buf;
56280 if (count > MAX_RW_COUNT)
56281 count = MAX_RW_COUNT;
56282 if (file->f_op->write)
56283diff --git a/fs/readdir.c b/fs/readdir.c
56284index fee38e0..12fdf47 100644
56285--- a/fs/readdir.c
56286+++ b/fs/readdir.c
56287@@ -17,6 +17,7 @@
56288 #include <linux/security.h>
56289 #include <linux/syscalls.h>
56290 #include <linux/unistd.h>
56291+#include <linux/namei.h>
56292
56293 #include <asm/uaccess.h>
56294
56295@@ -67,6 +68,7 @@ struct old_linux_dirent {
56296
56297 struct readdir_callback {
56298 struct old_linux_dirent __user * dirent;
56299+ struct file * file;
56300 int result;
56301 };
56302
56303@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
56304 buf->result = -EOVERFLOW;
56305 return -EOVERFLOW;
56306 }
56307+
56308+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56309+ return 0;
56310+
56311 buf->result++;
56312 dirent = buf->dirent;
56313 if (!access_ok(VERIFY_WRITE, dirent,
56314@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
56315
56316 buf.result = 0;
56317 buf.dirent = dirent;
56318+ buf.file = f.file;
56319
56320 error = vfs_readdir(f.file, fillonedir, &buf);
56321 if (buf.result)
56322@@ -139,6 +146,7 @@ struct linux_dirent {
56323 struct getdents_callback {
56324 struct linux_dirent __user * current_dir;
56325 struct linux_dirent __user * previous;
56326+ struct file * file;
56327 int count;
56328 int error;
56329 };
56330@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
56331 buf->error = -EOVERFLOW;
56332 return -EOVERFLOW;
56333 }
56334+
56335+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56336+ return 0;
56337+
56338 dirent = buf->previous;
56339 if (dirent) {
56340 if (__put_user(offset, &dirent->d_off))
56341@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56342 buf.previous = NULL;
56343 buf.count = count;
56344 buf.error = 0;
56345+ buf.file = f.file;
56346
56347 error = vfs_readdir(f.file, filldir, &buf);
56348 if (error >= 0)
56349@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56350 struct getdents_callback64 {
56351 struct linux_dirent64 __user * current_dir;
56352 struct linux_dirent64 __user * previous;
56353+ struct file *file;
56354 int count;
56355 int error;
56356 };
56357@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
56358 buf->error = -EINVAL; /* only used if we fail.. */
56359 if (reclen > buf->count)
56360 return -EINVAL;
56361+
56362+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56363+ return 0;
56364+
56365 dirent = buf->previous;
56366 if (dirent) {
56367 if (__put_user(offset, &dirent->d_off))
56368@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56369
56370 buf.current_dir = dirent;
56371 buf.previous = NULL;
56372+ buf.file = f.file;
56373 buf.count = count;
56374 buf.error = 0;
56375
56376@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56377 error = buf.error;
56378 lastdirent = buf.previous;
56379 if (lastdirent) {
56380- typeof(lastdirent->d_off) d_off = f.file->f_pos;
56381+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
56382 if (__put_user(d_off, &lastdirent->d_off))
56383 error = -EFAULT;
56384 else
56385diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
56386index 2b7882b..1c5ef48 100644
56387--- a/fs/reiserfs/do_balan.c
56388+++ b/fs/reiserfs/do_balan.c
56389@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
56390 return;
56391 }
56392
56393- atomic_inc(&(fs_generation(tb->tb_sb)));
56394+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
56395 do_balance_starts(tb);
56396
56397 /* balance leaf returns 0 except if combining L R and S into
56398diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
56399index 9cc0740a..46bf953 100644
56400--- a/fs/reiserfs/procfs.c
56401+++ b/fs/reiserfs/procfs.c
56402@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
56403 "SMALL_TAILS " : "NO_TAILS ",
56404 replay_only(sb) ? "REPLAY_ONLY " : "",
56405 convert_reiserfs(sb) ? "CONV " : "",
56406- atomic_read(&r->s_generation_counter),
56407+ atomic_read_unchecked(&r->s_generation_counter),
56408 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
56409 SF(s_do_balance), SF(s_unneeded_left_neighbor),
56410 SF(s_good_search_by_key_reada), SF(s_bmaps),
56411diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
56412index 157e474..65a6114 100644
56413--- a/fs/reiserfs/reiserfs.h
56414+++ b/fs/reiserfs/reiserfs.h
56415@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
56416 /* Comment? -Hans */
56417 wait_queue_head_t s_wait;
56418 /* To be obsoleted soon by per buffer seals.. -Hans */
56419- atomic_t s_generation_counter; // increased by one every time the
56420+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56421 // tree gets re-balanced
56422 unsigned long s_properties; /* File system properties. Currently holds
56423 on-disk FS format */
56424@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
56425 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56426
56427 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56428-#define get_generation(s) atomic_read (&fs_generation(s))
56429+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56430 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56431 #define __fs_changed(gen,s) (gen != get_generation (s))
56432 #define fs_changed(gen,s) \
56433diff --git a/fs/select.c b/fs/select.c
56434index 8c1c96c..a0f9b6d 100644
56435--- a/fs/select.c
56436+++ b/fs/select.c
56437@@ -20,6 +20,7 @@
56438 #include <linux/export.h>
56439 #include <linux/slab.h>
56440 #include <linux/poll.h>
56441+#include <linux/security.h>
56442 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
56443 #include <linux/file.h>
56444 #include <linux/fdtable.h>
56445@@ -827,6 +828,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
56446 struct poll_list *walk = head;
56447 unsigned long todo = nfds;
56448
56449+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
56450 if (nfds > rlimit(RLIMIT_NOFILE))
56451 return -EINVAL;
56452
56453diff --git a/fs/seq_file.c b/fs/seq_file.c
56454index 38bb59f..a304f9d 100644
56455--- a/fs/seq_file.c
56456+++ b/fs/seq_file.c
56457@@ -10,6 +10,7 @@
56458 #include <linux/seq_file.h>
56459 #include <linux/slab.h>
56460 #include <linux/cred.h>
56461+#include <linux/sched.h>
56462
56463 #include <asm/uaccess.h>
56464 #include <asm/page.h>
56465@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
56466 #ifdef CONFIG_USER_NS
56467 p->user_ns = file->f_cred->user_ns;
56468 #endif
56469+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56470+ p->exec_id = current->exec_id;
56471+#endif
56472
56473 /*
56474 * Wrappers around seq_open(e.g. swaps_open) need to be
56475@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56476 return 0;
56477 }
56478 if (!m->buf) {
56479- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56480+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56481 if (!m->buf)
56482 return -ENOMEM;
56483 }
56484@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56485 Eoverflow:
56486 m->op->stop(m, p);
56487 kfree(m->buf);
56488- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56489+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56490 return !m->buf ? -ENOMEM : -EAGAIN;
56491 }
56492
56493@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56494
56495 /* grab buffer if we didn't have one */
56496 if (!m->buf) {
56497- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56498+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56499 if (!m->buf)
56500 goto Enomem;
56501 }
56502@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56503 goto Fill;
56504 m->op->stop(m, p);
56505 kfree(m->buf);
56506- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56507+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56508 if (!m->buf)
56509 goto Enomem;
56510 m->count = 0;
56511@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
56512 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
56513 void *data)
56514 {
56515- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
56516+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
56517 int res = -ENOMEM;
56518
56519 if (op) {
56520diff --git a/fs/splice.c b/fs/splice.c
56521index 29e394e..b13c247 100644
56522--- a/fs/splice.c
56523+++ b/fs/splice.c
56524@@ -195,7 +195,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56525 pipe_lock(pipe);
56526
56527 for (;;) {
56528- if (!pipe->readers) {
56529+ if (!atomic_read(&pipe->readers)) {
56530 send_sig(SIGPIPE, current, 0);
56531 if (!ret)
56532 ret = -EPIPE;
56533@@ -249,9 +249,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56534 do_wakeup = 0;
56535 }
56536
56537- pipe->waiting_writers++;
56538+ atomic_inc(&pipe->waiting_writers);
56539 pipe_wait(pipe);
56540- pipe->waiting_writers--;
56541+ atomic_dec(&pipe->waiting_writers);
56542 }
56543
56544 pipe_unlock(pipe);
56545@@ -564,7 +564,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
56546 old_fs = get_fs();
56547 set_fs(get_ds());
56548 /* The cast to a user pointer is valid due to the set_fs() */
56549- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
56550+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
56551 set_fs(old_fs);
56552
56553 return res;
56554@@ -579,7 +579,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
56555 old_fs = get_fs();
56556 set_fs(get_ds());
56557 /* The cast to a user pointer is valid due to the set_fs() */
56558- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
56559+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
56560 set_fs(old_fs);
56561
56562 return res;
56563@@ -632,7 +632,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
56564 goto err;
56565
56566 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
56567- vec[i].iov_base = (void __user *) page_address(page);
56568+ vec[i].iov_base = (void __force_user *) page_address(page);
56569 vec[i].iov_len = this_len;
56570 spd.pages[i] = page;
56571 spd.nr_pages++;
56572@@ -853,10 +853,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
56573 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
56574 {
56575 while (!pipe->nrbufs) {
56576- if (!pipe->writers)
56577+ if (!atomic_read(&pipe->writers))
56578 return 0;
56579
56580- if (!pipe->waiting_writers && sd->num_spliced)
56581+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
56582 return 0;
56583
56584 if (sd->flags & SPLICE_F_NONBLOCK)
56585@@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
56586 * out of the pipe right after the splice_to_pipe(). So set
56587 * PIPE_READERS appropriately.
56588 */
56589- pipe->readers = 1;
56590+ atomic_set(&pipe->readers, 1);
56591
56592 current->splice_pipe = pipe;
56593 }
56594@@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56595 ret = -ERESTARTSYS;
56596 break;
56597 }
56598- if (!pipe->writers)
56599+ if (!atomic_read(&pipe->writers))
56600 break;
56601- if (!pipe->waiting_writers) {
56602+ if (!atomic_read(&pipe->waiting_writers)) {
56603 if (flags & SPLICE_F_NONBLOCK) {
56604 ret = -EAGAIN;
56605 break;
56606@@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56607 pipe_lock(pipe);
56608
56609 while (pipe->nrbufs >= pipe->buffers) {
56610- if (!pipe->readers) {
56611+ if (!atomic_read(&pipe->readers)) {
56612 send_sig(SIGPIPE, current, 0);
56613 ret = -EPIPE;
56614 break;
56615@@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56616 ret = -ERESTARTSYS;
56617 break;
56618 }
56619- pipe->waiting_writers++;
56620+ atomic_inc(&pipe->waiting_writers);
56621 pipe_wait(pipe);
56622- pipe->waiting_writers--;
56623+ atomic_dec(&pipe->waiting_writers);
56624 }
56625
56626 pipe_unlock(pipe);
56627@@ -1826,14 +1826,14 @@ retry:
56628 pipe_double_lock(ipipe, opipe);
56629
56630 do {
56631- if (!opipe->readers) {
56632+ if (!atomic_read(&opipe->readers)) {
56633 send_sig(SIGPIPE, current, 0);
56634 if (!ret)
56635 ret = -EPIPE;
56636 break;
56637 }
56638
56639- if (!ipipe->nrbufs && !ipipe->writers)
56640+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
56641 break;
56642
56643 /*
56644@@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56645 pipe_double_lock(ipipe, opipe);
56646
56647 do {
56648- if (!opipe->readers) {
56649+ if (!atomic_read(&opipe->readers)) {
56650 send_sig(SIGPIPE, current, 0);
56651 if (!ret)
56652 ret = -EPIPE;
56653@@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56654 * return EAGAIN if we have the potential of some data in the
56655 * future, otherwise just return 0
56656 */
56657- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
56658+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
56659 ret = -EAGAIN;
56660
56661 pipe_unlock(ipipe);
56662diff --git a/fs/stat.c b/fs/stat.c
56663index 04ce1ac..a13dd1e 100644
56664--- a/fs/stat.c
56665+++ b/fs/stat.c
56666@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
56667 stat->gid = inode->i_gid;
56668 stat->rdev = inode->i_rdev;
56669 stat->size = i_size_read(inode);
56670- stat->atime = inode->i_atime;
56671- stat->mtime = inode->i_mtime;
56672+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56673+ stat->atime = inode->i_ctime;
56674+ stat->mtime = inode->i_ctime;
56675+ } else {
56676+ stat->atime = inode->i_atime;
56677+ stat->mtime = inode->i_mtime;
56678+ }
56679 stat->ctime = inode->i_ctime;
56680 stat->blksize = (1 << inode->i_blkbits);
56681 stat->blocks = inode->i_blocks;
56682@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
56683 if (retval)
56684 return retval;
56685
56686- if (inode->i_op->getattr)
56687- return inode->i_op->getattr(path->mnt, path->dentry, stat);
56688+ if (inode->i_op->getattr) {
56689+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
56690+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56691+ stat->atime = stat->ctime;
56692+ stat->mtime = stat->ctime;
56693+ }
56694+ return retval;
56695+ }
56696
56697 generic_fillattr(inode, stat);
56698 return 0;
56699diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
56700index 15c68f9..36a8b3e 100644
56701--- a/fs/sysfs/bin.c
56702+++ b/fs/sysfs/bin.c
56703@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
56704 return ret;
56705 }
56706
56707-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
56708- void *buf, int len, int write)
56709+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
56710+ void *buf, size_t len, int write)
56711 {
56712 struct file *file = vma->vm_file;
56713 struct bin_buffer *bb = file->private_data;
56714 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
56715- int ret;
56716+ ssize_t ret;
56717
56718 if (!bb->vm_ops)
56719 return -EINVAL;
56720diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
56721index 6f31590..3c87c8a 100644
56722--- a/fs/sysfs/dir.c
56723+++ b/fs/sysfs/dir.c
56724@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
56725 *
56726 * Returns 31 bit hash of ns + name (so it fits in an off_t )
56727 */
56728-static unsigned int sysfs_name_hash(const void *ns, const char *name)
56729+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
56730 {
56731 unsigned long hash = init_name_hash();
56732 unsigned int len = strlen(name);
56733@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
56734 struct sysfs_dirent *sd;
56735 int rc;
56736
56737+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
56738+ const char *parent_name = parent_sd->s_name;
56739+
56740+ mode = S_IFDIR | S_IRWXU;
56741+
56742+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
56743+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
56744+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
56745+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
56746+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
56747+#endif
56748+
56749 /* allocate */
56750 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
56751 if (!sd)
56752diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
56753index 602f56d..6853db8 100644
56754--- a/fs/sysfs/file.c
56755+++ b/fs/sysfs/file.c
56756@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
56757
56758 struct sysfs_open_dirent {
56759 atomic_t refcnt;
56760- atomic_t event;
56761+ atomic_unchecked_t event;
56762 wait_queue_head_t poll;
56763 struct list_head buffers; /* goes through sysfs_buffer.list */
56764 };
56765@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
56766 if (!sysfs_get_active(attr_sd))
56767 return -ENODEV;
56768
56769- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
56770+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
56771 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
56772
56773 sysfs_put_active(attr_sd);
56774@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
56775 return -ENOMEM;
56776
56777 atomic_set(&new_od->refcnt, 0);
56778- atomic_set(&new_od->event, 1);
56779+ atomic_set_unchecked(&new_od->event, 1);
56780 init_waitqueue_head(&new_od->poll);
56781 INIT_LIST_HEAD(&new_od->buffers);
56782 goto retry;
56783@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
56784
56785 sysfs_put_active(attr_sd);
56786
56787- if (buffer->event != atomic_read(&od->event))
56788+ if (buffer->event != atomic_read_unchecked(&od->event))
56789 goto trigger;
56790
56791 return DEFAULT_POLLMASK;
56792@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
56793
56794 od = sd->s_attr.open;
56795 if (od) {
56796- atomic_inc(&od->event);
56797+ atomic_inc_unchecked(&od->event);
56798 wake_up_interruptible(&od->poll);
56799 }
56800
56801diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
56802index 8c940df..25b733e 100644
56803--- a/fs/sysfs/symlink.c
56804+++ b/fs/sysfs/symlink.c
56805@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56806
56807 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
56808 {
56809- char *page = nd_get_link(nd);
56810+ const char *page = nd_get_link(nd);
56811 if (!IS_ERR(page))
56812 free_page((unsigned long)page);
56813 }
56814diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
56815index 69d4889..a810bd4 100644
56816--- a/fs/sysv/sysv.h
56817+++ b/fs/sysv/sysv.h
56818@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
56819 #endif
56820 }
56821
56822-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56823+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56824 {
56825 if (sbi->s_bytesex == BYTESEX_PDP)
56826 return PDP_swab((__force __u32)n);
56827diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
56828index e18b988..f1d4ad0f 100644
56829--- a/fs/ubifs/io.c
56830+++ b/fs/ubifs/io.c
56831@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
56832 return err;
56833 }
56834
56835-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56836+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56837 {
56838 int err;
56839
56840diff --git a/fs/udf/misc.c b/fs/udf/misc.c
56841index c175b4d..8f36a16 100644
56842--- a/fs/udf/misc.c
56843+++ b/fs/udf/misc.c
56844@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
56845
56846 u8 udf_tag_checksum(const struct tag *t)
56847 {
56848- u8 *data = (u8 *)t;
56849+ const u8 *data = (const u8 *)t;
56850 u8 checksum = 0;
56851 int i;
56852 for (i = 0; i < sizeof(struct tag); ++i)
56853diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
56854index 8d974c4..b82f6ec 100644
56855--- a/fs/ufs/swab.h
56856+++ b/fs/ufs/swab.h
56857@@ -22,7 +22,7 @@ enum {
56858 BYTESEX_BE
56859 };
56860
56861-static inline u64
56862+static inline u64 __intentional_overflow(-1)
56863 fs64_to_cpu(struct super_block *sbp, __fs64 n)
56864 {
56865 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56866@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
56867 return (__force __fs64)cpu_to_be64(n);
56868 }
56869
56870-static inline u32
56871+static inline u32 __intentional_overflow(-1)
56872 fs32_to_cpu(struct super_block *sbp, __fs32 n)
56873 {
56874 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56875diff --git a/fs/utimes.c b/fs/utimes.c
56876index f4fb7ec..3fe03c0 100644
56877--- a/fs/utimes.c
56878+++ b/fs/utimes.c
56879@@ -1,6 +1,7 @@
56880 #include <linux/compiler.h>
56881 #include <linux/file.h>
56882 #include <linux/fs.h>
56883+#include <linux/security.h>
56884 #include <linux/linkage.h>
56885 #include <linux/mount.h>
56886 #include <linux/namei.h>
56887@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
56888 goto mnt_drop_write_and_out;
56889 }
56890 }
56891+
56892+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
56893+ error = -EACCES;
56894+ goto mnt_drop_write_and_out;
56895+ }
56896+
56897 mutex_lock(&inode->i_mutex);
56898 error = notify_change(path->dentry, &newattrs);
56899 mutex_unlock(&inode->i_mutex);
56900diff --git a/fs/xattr.c b/fs/xattr.c
56901index 3377dff..4d074d9 100644
56902--- a/fs/xattr.c
56903+++ b/fs/xattr.c
56904@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
56905 return rc;
56906 }
56907
56908+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56909+ssize_t
56910+pax_getxattr(struct dentry *dentry, void *value, size_t size)
56911+{
56912+ struct inode *inode = dentry->d_inode;
56913+ ssize_t error;
56914+
56915+ error = inode_permission(inode, MAY_EXEC);
56916+ if (error)
56917+ return error;
56918+
56919+ if (inode->i_op->getxattr)
56920+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
56921+ else
56922+ error = -EOPNOTSUPP;
56923+
56924+ return error;
56925+}
56926+EXPORT_SYMBOL(pax_getxattr);
56927+#endif
56928+
56929 ssize_t
56930 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
56931 {
56932@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
56933 * Extended attribute SET operations
56934 */
56935 static long
56936-setxattr(struct dentry *d, const char __user *name, const void __user *value,
56937+setxattr(struct path *path, const char __user *name, const void __user *value,
56938 size_t size, int flags)
56939 {
56940 int error;
56941@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
56942 posix_acl_fix_xattr_from_user(kvalue, size);
56943 }
56944
56945- error = vfs_setxattr(d, kname, kvalue, size, flags);
56946+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
56947+ error = -EACCES;
56948+ goto out;
56949+ }
56950+
56951+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
56952 out:
56953 if (vvalue)
56954 vfree(vvalue);
56955@@ -377,7 +403,7 @@ retry:
56956 return error;
56957 error = mnt_want_write(path.mnt);
56958 if (!error) {
56959- error = setxattr(path.dentry, name, value, size, flags);
56960+ error = setxattr(&path, name, value, size, flags);
56961 mnt_drop_write(path.mnt);
56962 }
56963 path_put(&path);
56964@@ -401,7 +427,7 @@ retry:
56965 return error;
56966 error = mnt_want_write(path.mnt);
56967 if (!error) {
56968- error = setxattr(path.dentry, name, value, size, flags);
56969+ error = setxattr(&path, name, value, size, flags);
56970 mnt_drop_write(path.mnt);
56971 }
56972 path_put(&path);
56973@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
56974 const void __user *,value, size_t, size, int, flags)
56975 {
56976 struct fd f = fdget(fd);
56977- struct dentry *dentry;
56978 int error = -EBADF;
56979
56980 if (!f.file)
56981 return error;
56982- dentry = f.file->f_path.dentry;
56983- audit_inode(NULL, dentry, 0);
56984+ audit_inode(NULL, f.file->f_path.dentry, 0);
56985 error = mnt_want_write_file(f.file);
56986 if (!error) {
56987- error = setxattr(dentry, name, value, size, flags);
56988+ error = setxattr(&f.file->f_path, name, value, size, flags);
56989 mnt_drop_write_file(f.file);
56990 }
56991 fdput(f);
56992diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
56993index 9fbea87..6b19972 100644
56994--- a/fs/xattr_acl.c
56995+++ b/fs/xattr_acl.c
56996@@ -76,8 +76,8 @@ struct posix_acl *
56997 posix_acl_from_xattr(struct user_namespace *user_ns,
56998 const void *value, size_t size)
56999 {
57000- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
57001- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
57002+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
57003+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
57004 int count;
57005 struct posix_acl *acl;
57006 struct posix_acl_entry *acl_e;
57007diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
57008index b44af92..06073da 100644
57009--- a/fs/xfs/xfs_bmap.c
57010+++ b/fs/xfs/xfs_bmap.c
57011@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
57012 int nmap,
57013 int ret_nmap);
57014 #else
57015-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
57016+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
57017 #endif /* DEBUG */
57018
57019 STATIC int
57020diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
57021index 1b9fc3e..e1bdde0 100644
57022--- a/fs/xfs/xfs_dir2_sf.c
57023+++ b/fs/xfs/xfs_dir2_sf.c
57024@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
57025 }
57026
57027 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
57028- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57029+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
57030+ char name[sfep->namelen];
57031+ memcpy(name, sfep->name, sfep->namelen);
57032+ if (filldir(dirent, name, sfep->namelen,
57033+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
57034+ *offset = off & 0x7fffffff;
57035+ return 0;
57036+ }
57037+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57038 off & 0x7fffffff, ino, DT_UNKNOWN)) {
57039 *offset = off & 0x7fffffff;
57040 return 0;
57041diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
57042index d681e34..2a3f5ab 100644
57043--- a/fs/xfs/xfs_ioctl.c
57044+++ b/fs/xfs/xfs_ioctl.c
57045@@ -127,7 +127,7 @@ xfs_find_handle(
57046 }
57047
57048 error = -EFAULT;
57049- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
57050+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
57051 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
57052 goto out_put;
57053
57054diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
57055index ca9ecaa..60100c7 100644
57056--- a/fs/xfs/xfs_iops.c
57057+++ b/fs/xfs/xfs_iops.c
57058@@ -395,7 +395,7 @@ xfs_vn_put_link(
57059 struct nameidata *nd,
57060 void *p)
57061 {
57062- char *s = nd_get_link(nd);
57063+ const char *s = nd_get_link(nd);
57064
57065 if (!IS_ERR(s))
57066 kfree(s);
57067diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
57068new file mode 100644
57069index 0000000..c9c4ac3
57070--- /dev/null
57071+++ b/grsecurity/Kconfig
57072@@ -0,0 +1,1054 @@
57073+#
57074+# grecurity configuration
57075+#
57076+menu "Memory Protections"
57077+depends on GRKERNSEC
57078+
57079+config GRKERNSEC_KMEM
57080+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
57081+ default y if GRKERNSEC_CONFIG_AUTO
57082+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
57083+ help
57084+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
57085+ be written to or read from to modify or leak the contents of the running
57086+ kernel. /dev/port will also not be allowed to be opened and support
57087+ for /dev/cpu/*/msr will be removed. If you have module
57088+ support disabled, enabling this will close up five ways that are
57089+ currently used to insert malicious code into the running kernel.
57090+
57091+ Even with all these features enabled, we still highly recommend that
57092+ you use the RBAC system, as it is still possible for an attacker to
57093+ modify the running kernel through privileged I/O granted by ioperm/iopl.
57094+
57095+ If you are not using XFree86, you may be able to stop this additional
57096+ case by enabling the 'Disable privileged I/O' option. Though nothing
57097+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
57098+ but only to video memory, which is the only writing we allow in this
57099+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
57100+ not be allowed to mprotect it with PROT_WRITE later.
57101+ Enabling this feature will prevent the "cpupower" and "powertop" tools
57102+ from working.
57103+
57104+ It is highly recommended that you say Y here if you meet all the
57105+ conditions above.
57106+
57107+config GRKERNSEC_VM86
57108+ bool "Restrict VM86 mode"
57109+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57110+ depends on X86_32
57111+
57112+ help
57113+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
57114+ make use of a special execution mode on 32bit x86 processors called
57115+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
57116+ video cards and will still work with this option enabled. The purpose
57117+ of the option is to prevent exploitation of emulation errors in
57118+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
57119+ Nearly all users should be able to enable this option.
57120+
57121+config GRKERNSEC_IO
57122+ bool "Disable privileged I/O"
57123+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57124+ depends on X86
57125+ select RTC_CLASS
57126+ select RTC_INTF_DEV
57127+ select RTC_DRV_CMOS
57128+
57129+ help
57130+ If you say Y here, all ioperm and iopl calls will return an error.
57131+ Ioperm and iopl can be used to modify the running kernel.
57132+ Unfortunately, some programs need this access to operate properly,
57133+ the most notable of which are XFree86 and hwclock. hwclock can be
57134+ remedied by having RTC support in the kernel, so real-time
57135+ clock support is enabled if this option is enabled, to ensure
57136+ that hwclock operates correctly. XFree86 still will not
57137+ operate correctly with this option enabled, so DO NOT CHOOSE Y
57138+ IF YOU USE XFree86. If you use XFree86 and you still want to
57139+ protect your kernel against modification, use the RBAC system.
57140+
57141+config GRKERNSEC_JIT_HARDEN
57142+ bool "Harden BPF JIT against spray attacks"
57143+ default y if GRKERNSEC_CONFIG_AUTO
57144+ depends on BPF_JIT
57145+ help
57146+ If you say Y here, the native code generated by the kernel's Berkeley
57147+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
57148+ attacks that attempt to fit attacker-beneficial instructions in
57149+ 32bit immediate fields of JIT-generated native instructions. The
57150+ attacker will generally aim to cause an unintended instruction sequence
57151+ of JIT-generated native code to execute by jumping into the middle of
57152+ a generated instruction. This feature effectively randomizes the 32bit
57153+ immediate constants present in the generated code to thwart such attacks.
57154+
57155+ If you're using KERNEXEC, it's recommended that you enable this option
57156+ to supplement the hardening of the kernel.
57157+
57158+config GRKERNSEC_PERF_HARDEN
57159+ bool "Disable unprivileged PERF_EVENTS usage by default"
57160+ default y if GRKERNSEC_CONFIG_AUTO
57161+ depends on PERF_EVENTS
57162+ help
57163+ If you say Y here, the range of acceptable values for the
57164+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
57165+ default to a new value: 3. When the sysctl is set to this value, no
57166+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
57167+
57168+ Though PERF_EVENTS can be used legitimately for performance monitoring
57169+ and low-level application profiling, it is forced on regardless of
57170+ configuration, has been at fault for several vulnerabilities, and
57171+ creates new opportunities for side channels and other information leaks.
57172+
57173+ This feature puts PERF_EVENTS into a secure default state and permits
57174+ the administrator to change out of it temporarily if unprivileged
57175+ application profiling is needed.
57176+
57177+config GRKERNSEC_RAND_THREADSTACK
57178+ bool "Insert random gaps between thread stacks"
57179+ default y if GRKERNSEC_CONFIG_AUTO
57180+ depends on PAX_RANDMMAP && !PPC
57181+ help
57182+ If you say Y here, a random-sized gap will be enforced between allocated
57183+ thread stacks. Glibc's NPTL and other threading libraries that
57184+ pass MAP_STACK to the kernel for thread stack allocation are supported.
57185+ The implementation currently provides 8 bits of entropy for the gap.
57186+
57187+ Many distributions do not compile threaded remote services with the
57188+ -fstack-check argument to GCC, causing the variable-sized stack-based
57189+ allocator, alloca(), to not probe the stack on allocation. This
57190+ permits an unbounded alloca() to skip over any guard page and potentially
57191+ modify another thread's stack reliably. An enforced random gap
57192+ reduces the reliability of such an attack and increases the chance
57193+ that such a read/write to another thread's stack instead lands in
57194+ an unmapped area, causing a crash and triggering grsecurity's
57195+ anti-bruteforcing logic.
57196+
57197+config GRKERNSEC_PROC_MEMMAP
57198+ bool "Harden ASLR against information leaks and entropy reduction"
57199+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
57200+ depends on PAX_NOEXEC || PAX_ASLR
57201+ help
57202+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
57203+ give no information about the addresses of its mappings if
57204+ PaX features that rely on random addresses are enabled on the task.
57205+ In addition to sanitizing this information and disabling other
57206+ dangerous sources of information, this option causes reads of sensitive
57207+ /proc/<pid> entries where the file descriptor was opened in a different
57208+ task than the one performing the read. Such attempts are logged.
57209+ This option also limits argv/env strings for suid/sgid binaries
57210+ to 512KB to prevent a complete exhaustion of the stack entropy provided
57211+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
57212+ binaries to prevent alternative mmap layouts from being abused.
57213+
57214+ If you use PaX it is essential that you say Y here as it closes up
57215+ several holes that make full ASLR useless locally.
57216+
57217+config GRKERNSEC_BRUTE
57218+ bool "Deter exploit bruteforcing"
57219+ default y if GRKERNSEC_CONFIG_AUTO
57220+ help
57221+ If you say Y here, attempts to bruteforce exploits against forking
57222+ daemons such as apache or sshd, as well as against suid/sgid binaries
57223+ will be deterred. When a child of a forking daemon is killed by PaX
57224+ or crashes due to an illegal instruction or other suspicious signal,
57225+ the parent process will be delayed 30 seconds upon every subsequent
57226+ fork until the administrator is able to assess the situation and
57227+ restart the daemon.
57228+ In the suid/sgid case, the attempt is logged, the user has all their
57229+ existing instances of the suid/sgid binary terminated and will
57230+ be unable to execute any suid/sgid binaries for 15 minutes.
57231+
57232+ It is recommended that you also enable signal logging in the auditing
57233+ section so that logs are generated when a process triggers a suspicious
57234+ signal.
57235+ If the sysctl option is enabled, a sysctl option with name
57236+ "deter_bruteforce" is created.
57237+
57238+
57239+config GRKERNSEC_MODHARDEN
57240+ bool "Harden module auto-loading"
57241+ default y if GRKERNSEC_CONFIG_AUTO
57242+ depends on MODULES
57243+ help
57244+ If you say Y here, module auto-loading in response to use of some
57245+ feature implemented by an unloaded module will be restricted to
57246+ root users. Enabling this option helps defend against attacks
57247+ by unprivileged users who abuse the auto-loading behavior to
57248+ cause a vulnerable module to load that is then exploited.
57249+
57250+ If this option prevents a legitimate use of auto-loading for a
57251+ non-root user, the administrator can execute modprobe manually
57252+ with the exact name of the module mentioned in the alert log.
57253+ Alternatively, the administrator can add the module to the list
57254+ of modules loaded at boot by modifying init scripts.
57255+
57256+ Modification of init scripts will most likely be needed on
57257+ Ubuntu servers with encrypted home directory support enabled,
57258+ as the first non-root user logging in will cause the ecb(aes),
57259+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
57260+
57261+config GRKERNSEC_HIDESYM
57262+ bool "Hide kernel symbols"
57263+ default y if GRKERNSEC_CONFIG_AUTO
57264+ select PAX_USERCOPY_SLABS
57265+ help
57266+ If you say Y here, getting information on loaded modules, and
57267+ displaying all kernel symbols through a syscall will be restricted
57268+ to users with CAP_SYS_MODULE. For software compatibility reasons,
57269+ /proc/kallsyms will be restricted to the root user. The RBAC
57270+ system can hide that entry even from root.
57271+
57272+ This option also prevents leaking of kernel addresses through
57273+ several /proc entries.
57274+
57275+ Note that this option is only effective provided the following
57276+ conditions are met:
57277+ 1) The kernel using grsecurity is not precompiled by some distribution
57278+ 2) You have also enabled GRKERNSEC_DMESG
57279+ 3) You are using the RBAC system and hiding other files such as your
57280+ kernel image and System.map. Alternatively, enabling this option
57281+ causes the permissions on /boot, /lib/modules, and the kernel
57282+ source directory to change at compile time to prevent
57283+ reading by non-root users.
57284+ If the above conditions are met, this option will aid in providing a
57285+ useful protection against local kernel exploitation of overflows
57286+ and arbitrary read/write vulnerabilities.
57287+
57288+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
57289+ in addition to this feature.
57290+
57291+config GRKERNSEC_KERN_LOCKOUT
57292+ bool "Active kernel exploit response"
57293+ default y if GRKERNSEC_CONFIG_AUTO
57294+ depends on X86 || ARM || PPC || SPARC
57295+ help
57296+ If you say Y here, when a PaX alert is triggered due to suspicious
57297+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
57298+ or an OOPS occurs due to bad memory accesses, instead of just
57299+ terminating the offending process (and potentially allowing
57300+ a subsequent exploit from the same user), we will take one of two
57301+ actions:
57302+ If the user was root, we will panic the system
57303+ If the user was non-root, we will log the attempt, terminate
57304+ all processes owned by the user, then prevent them from creating
57305+ any new processes until the system is restarted
57306+ This deters repeated kernel exploitation/bruteforcing attempts
57307+ and is useful for later forensics.
57308+
57309+endmenu
57310+menu "Role Based Access Control Options"
57311+depends on GRKERNSEC
57312+
57313+config GRKERNSEC_RBAC_DEBUG
57314+ bool
57315+
57316+config GRKERNSEC_NO_RBAC
57317+ bool "Disable RBAC system"
57318+ help
57319+ If you say Y here, the /dev/grsec device will be removed from the kernel,
57320+ preventing the RBAC system from being enabled. You should only say Y
57321+ here if you have no intention of using the RBAC system, so as to prevent
57322+ an attacker with root access from misusing the RBAC system to hide files
57323+ and processes when loadable module support and /dev/[k]mem have been
57324+ locked down.
57325+
57326+config GRKERNSEC_ACL_HIDEKERN
57327+ bool "Hide kernel processes"
57328+ help
57329+ If you say Y here, all kernel threads will be hidden to all
57330+ processes but those whose subject has the "view hidden processes"
57331+ flag.
57332+
57333+config GRKERNSEC_ACL_MAXTRIES
57334+ int "Maximum tries before password lockout"
57335+ default 3
57336+ help
57337+ This option enforces the maximum number of times a user can attempt
57338+ to authorize themselves with the grsecurity RBAC system before being
57339+ denied the ability to attempt authorization again for a specified time.
57340+ The lower the number, the harder it will be to brute-force a password.
57341+
57342+config GRKERNSEC_ACL_TIMEOUT
57343+ int "Time to wait after max password tries, in seconds"
57344+ default 30
57345+ help
57346+ This option specifies the time the user must wait after attempting to
57347+ authorize to the RBAC system with the maximum number of invalid
57348+ passwords. The higher the number, the harder it will be to brute-force
57349+ a password.
57350+
57351+endmenu
57352+menu "Filesystem Protections"
57353+depends on GRKERNSEC
57354+
57355+config GRKERNSEC_PROC
57356+ bool "Proc restrictions"
57357+ default y if GRKERNSEC_CONFIG_AUTO
57358+ help
57359+ If you say Y here, the permissions of the /proc filesystem
57360+ will be altered to enhance system security and privacy. You MUST
57361+ choose either a user only restriction or a user and group restriction.
57362+ Depending upon the option you choose, you can either restrict users to
57363+ see only the processes they themselves run, or choose a group that can
57364+ view all processes and files normally restricted to root if you choose
57365+ the "restrict to user only" option. NOTE: If you're running identd or
57366+ ntpd as a non-root user, you will have to run it as the group you
57367+ specify here.
57368+
57369+config GRKERNSEC_PROC_USER
57370+ bool "Restrict /proc to user only"
57371+ depends on GRKERNSEC_PROC
57372+ help
57373+ If you say Y here, non-root users will only be able to view their own
57374+ processes, and restricts them from viewing network-related information,
57375+ and viewing kernel symbol and module information.
57376+
57377+config GRKERNSEC_PROC_USERGROUP
57378+ bool "Allow special group"
57379+ default y if GRKERNSEC_CONFIG_AUTO
57380+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
57381+ help
57382+ If you say Y here, you will be able to select a group that will be
57383+ able to view all processes and network-related information. If you've
57384+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
57385+ remain hidden. This option is useful if you want to run identd as
57386+ a non-root user. The group you select may also be chosen at boot time
57387+ via "grsec_proc_gid=" on the kernel commandline.
57388+
57389+config GRKERNSEC_PROC_GID
57390+ int "GID for special group"
57391+ depends on GRKERNSEC_PROC_USERGROUP
57392+ default 1001
57393+
57394+config GRKERNSEC_PROC_ADD
57395+ bool "Additional restrictions"
57396+ default y if GRKERNSEC_CONFIG_AUTO
57397+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
57398+ help
57399+ If you say Y here, additional restrictions will be placed on
57400+ /proc that keep normal users from viewing device information and
57401+ slabinfo information that could be useful for exploits.
57402+
57403+config GRKERNSEC_LINK
57404+ bool "Linking restrictions"
57405+ default y if GRKERNSEC_CONFIG_AUTO
57406+ help
57407+ If you say Y here, /tmp race exploits will be prevented, since users
57408+ will no longer be able to follow symlinks owned by other users in
57409+ world-writable +t directories (e.g. /tmp), unless the owner of the
57410+ symlink is the owner of the directory. users will also not be
57411+ able to hardlink to files they do not own. If the sysctl option is
57412+ enabled, a sysctl option with name "linking_restrictions" is created.
57413+
57414+config GRKERNSEC_SYMLINKOWN
57415+ bool "Kernel-enforced SymlinksIfOwnerMatch"
57416+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57417+ help
57418+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
57419+ that prevents it from being used as a security feature. As Apache
57420+ verifies the symlink by performing a stat() against the target of
57421+ the symlink before it is followed, an attacker can setup a symlink
57422+ to point to a same-owned file, then replace the symlink with one
57423+ that targets another user's file just after Apache "validates" the
57424+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
57425+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
57426+ will be in place for the group you specify. If the sysctl option
57427+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
57428+ created.
57429+
57430+config GRKERNSEC_SYMLINKOWN_GID
57431+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
57432+ depends on GRKERNSEC_SYMLINKOWN
57433+ default 1006
57434+ help
57435+ Setting this GID determines what group kernel-enforced
57436+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
57437+ is enabled, a sysctl option with name "symlinkown_gid" is created.
57438+
57439+config GRKERNSEC_FIFO
57440+ bool "FIFO restrictions"
57441+ default y if GRKERNSEC_CONFIG_AUTO
57442+ help
57443+ If you say Y here, users will not be able to write to FIFOs they don't
57444+ own in world-writable +t directories (e.g. /tmp), unless the owner of
57445+ the FIFO is the same owner of the directory it's held in. If the sysctl
57446+ option is enabled, a sysctl option with name "fifo_restrictions" is
57447+ created.
57448+
57449+config GRKERNSEC_SYSFS_RESTRICT
57450+ bool "Sysfs/debugfs restriction"
57451+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57452+ depends on SYSFS
57453+ help
57454+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
57455+ any filesystem normally mounted under it (e.g. debugfs) will be
57456+ mostly accessible only by root. These filesystems generally provide access
57457+ to hardware and debug information that isn't appropriate for unprivileged
57458+ users of the system. Sysfs and debugfs have also become a large source
57459+ of new vulnerabilities, ranging from infoleaks to local compromise.
57460+ There has been very little oversight with an eye toward security involved
57461+ in adding new exporters of information to these filesystems, so their
57462+ use is discouraged.
57463+ For reasons of compatibility, a few directories have been whitelisted
57464+ for access by non-root users:
57465+ /sys/fs/selinux
57466+ /sys/fs/fuse
57467+ /sys/devices/system/cpu
57468+
57469+config GRKERNSEC_ROFS
57470+ bool "Runtime read-only mount protection"
57471+ help
57472+ If you say Y here, a sysctl option with name "romount_protect" will
57473+ be created. By setting this option to 1 at runtime, filesystems
57474+ will be protected in the following ways:
57475+ * No new writable mounts will be allowed
57476+ * Existing read-only mounts won't be able to be remounted read/write
57477+ * Write operations will be denied on all block devices
57478+ This option acts independently of grsec_lock: once it is set to 1,
57479+ it cannot be turned off. Therefore, please be mindful of the resulting
57480+ behavior if this option is enabled in an init script on a read-only
57481+ filesystem. This feature is mainly intended for secure embedded systems.
57482+
57483+config GRKERNSEC_DEVICE_SIDECHANNEL
57484+ bool "Eliminate stat/notify-based device sidechannels"
57485+ default y if GRKERNSEC_CONFIG_AUTO
57486+ help
57487+ If you say Y here, timing analyses on block or character
57488+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
57489+ will be thwarted for unprivileged users. If a process without
57490+ CAP_MKNOD stats such a device, the last access and last modify times
57491+ will match the device's create time. No access or modify events
57492+ will be triggered through inotify/dnotify/fanotify for such devices.
57493+ This feature will prevent attacks that may at a minimum
57494+ allow an attacker to determine the administrator's password length.
57495+
57496+config GRKERNSEC_CHROOT
57497+ bool "Chroot jail restrictions"
57498+ default y if GRKERNSEC_CONFIG_AUTO
57499+ help
57500+ If you say Y here, you will be able to choose several options that will
57501+ make breaking out of a chrooted jail much more difficult. If you
57502+ encounter no software incompatibilities with the following options, it
57503+ is recommended that you enable each one.
57504+
57505+config GRKERNSEC_CHROOT_MOUNT
57506+ bool "Deny mounts"
57507+ default y if GRKERNSEC_CONFIG_AUTO
57508+ depends on GRKERNSEC_CHROOT
57509+ help
57510+ If you say Y here, processes inside a chroot will not be able to
57511+ mount or remount filesystems. If the sysctl option is enabled, a
57512+ sysctl option with name "chroot_deny_mount" is created.
57513+
57514+config GRKERNSEC_CHROOT_DOUBLE
57515+ bool "Deny double-chroots"
57516+ default y if GRKERNSEC_CONFIG_AUTO
57517+ depends on GRKERNSEC_CHROOT
57518+ help
57519+ If you say Y here, processes inside a chroot will not be able to chroot
57520+ again outside the chroot. This is a widely used method of breaking
57521+ out of a chroot jail and should not be allowed. If the sysctl
57522+ option is enabled, a sysctl option with name
57523+ "chroot_deny_chroot" is created.
57524+
57525+config GRKERNSEC_CHROOT_PIVOT
57526+ bool "Deny pivot_root in chroot"
57527+ default y if GRKERNSEC_CONFIG_AUTO
57528+ depends on GRKERNSEC_CHROOT
57529+ help
57530+ If you say Y here, processes inside a chroot will not be able to use
57531+ a function called pivot_root() that was introduced in Linux 2.3.41. It
57532+ works similar to chroot in that it changes the root filesystem. This
57533+ function could be misused in a chrooted process to attempt to break out
57534+ of the chroot, and therefore should not be allowed. If the sysctl
57535+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
57536+ created.
57537+
57538+config GRKERNSEC_CHROOT_CHDIR
57539+ bool "Enforce chdir(\"/\") on all chroots"
57540+ default y if GRKERNSEC_CONFIG_AUTO
57541+ depends on GRKERNSEC_CHROOT
57542+ help
57543+ If you say Y here, the current working directory of all newly-chrooted
57544+ applications will be set to the the root directory of the chroot.
57545+ The man page on chroot(2) states:
57546+ Note that this call does not change the current working
57547+ directory, so that `.' can be outside the tree rooted at
57548+ `/'. In particular, the super-user can escape from a
57549+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
57550+
57551+ It is recommended that you say Y here, since it's not known to break
57552+ any software. If the sysctl option is enabled, a sysctl option with
57553+ name "chroot_enforce_chdir" is created.
57554+
57555+config GRKERNSEC_CHROOT_CHMOD
57556+ bool "Deny (f)chmod +s"
57557+ default y if GRKERNSEC_CONFIG_AUTO
57558+ depends on GRKERNSEC_CHROOT
57559+ help
57560+ If you say Y here, processes inside a chroot will not be able to chmod
57561+ or fchmod files to make them have suid or sgid bits. This protects
57562+ against another published method of breaking a chroot. If the sysctl
57563+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
57564+ created.
57565+
57566+config GRKERNSEC_CHROOT_FCHDIR
57567+ bool "Deny fchdir out of chroot"
57568+ default y if GRKERNSEC_CONFIG_AUTO
57569+ depends on GRKERNSEC_CHROOT
57570+ help
57571+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
57572+ to a file descriptor of the chrooting process that points to a directory
57573+ outside the filesystem will be stopped. If the sysctl option
57574+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
57575+
57576+config GRKERNSEC_CHROOT_MKNOD
57577+ bool "Deny mknod"
57578+ default y if GRKERNSEC_CONFIG_AUTO
57579+ depends on GRKERNSEC_CHROOT
57580+ help
57581+ If you say Y here, processes inside a chroot will not be allowed to
57582+ mknod. The problem with using mknod inside a chroot is that it
57583+ would allow an attacker to create a device entry that is the same
57584+ as one on the physical root of your system, which could range from
57585+ anything from the console device to a device for your harddrive (which
57586+ they could then use to wipe the drive or steal data). It is recommended
57587+ that you say Y here, unless you run into software incompatibilities.
57588+ If the sysctl option is enabled, a sysctl option with name
57589+ "chroot_deny_mknod" is created.
57590+
57591+config GRKERNSEC_CHROOT_SHMAT
57592+ bool "Deny shmat() out of chroot"
57593+ default y if GRKERNSEC_CONFIG_AUTO
57594+ depends on GRKERNSEC_CHROOT
57595+ help
57596+ If you say Y here, processes inside a chroot will not be able to attach
57597+ to shared memory segments that were created outside of the chroot jail.
57598+ It is recommended that you say Y here. If the sysctl option is enabled,
57599+ a sysctl option with name "chroot_deny_shmat" is created.
57600+
57601+config GRKERNSEC_CHROOT_UNIX
57602+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
57603+ default y if GRKERNSEC_CONFIG_AUTO
57604+ depends on GRKERNSEC_CHROOT
57605+ help
57606+ If you say Y here, processes inside a chroot will not be able to
57607+ connect to abstract (meaning not belonging to a filesystem) Unix
57608+ domain sockets that were bound outside of a chroot. It is recommended
57609+ that you say Y here. If the sysctl option is enabled, a sysctl option
57610+ with name "chroot_deny_unix" is created.
57611+
57612+config GRKERNSEC_CHROOT_FINDTASK
57613+ bool "Protect outside processes"
57614+ default y if GRKERNSEC_CONFIG_AUTO
57615+ depends on GRKERNSEC_CHROOT
57616+ help
57617+ If you say Y here, processes inside a chroot will not be able to
57618+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
57619+ getsid, or view any process outside of the chroot. If the sysctl
57620+ option is enabled, a sysctl option with name "chroot_findtask" is
57621+ created.
57622+
57623+config GRKERNSEC_CHROOT_NICE
57624+ bool "Restrict priority changes"
57625+ default y if GRKERNSEC_CONFIG_AUTO
57626+ depends on GRKERNSEC_CHROOT
57627+ help
57628+ If you say Y here, processes inside a chroot will not be able to raise
57629+ the priority of processes in the chroot, or alter the priority of
57630+ processes outside the chroot. This provides more security than simply
57631+ removing CAP_SYS_NICE from the process' capability set. If the
57632+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
57633+ is created.
57634+
57635+config GRKERNSEC_CHROOT_SYSCTL
57636+ bool "Deny sysctl writes"
57637+ default y if GRKERNSEC_CONFIG_AUTO
57638+ depends on GRKERNSEC_CHROOT
57639+ help
57640+ If you say Y here, an attacker in a chroot will not be able to
57641+ write to sysctl entries, either by sysctl(2) or through a /proc
57642+ interface. It is strongly recommended that you say Y here. If the
57643+ sysctl option is enabled, a sysctl option with name
57644+ "chroot_deny_sysctl" is created.
57645+
57646+config GRKERNSEC_CHROOT_CAPS
57647+ bool "Capability restrictions"
57648+ default y if GRKERNSEC_CONFIG_AUTO
57649+ depends on GRKERNSEC_CHROOT
57650+ help
57651+ If you say Y here, the capabilities on all processes within a
57652+ chroot jail will be lowered to stop module insertion, raw i/o,
57653+ system and net admin tasks, rebooting the system, modifying immutable
57654+ files, modifying IPC owned by another, and changing the system time.
57655+ This is left an option because it can break some apps. Disable this
57656+ if your chrooted apps are having problems performing those kinds of
57657+ tasks. If the sysctl option is enabled, a sysctl option with
57658+ name "chroot_caps" is created.
57659+
57660+config GRKERNSEC_CHROOT_INITRD
57661+ bool "Exempt initrd tasks from restrictions"
57662+ default y if GRKERNSEC_CONFIG_AUTO
57663+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
57664+ help
57665+ If you say Y here, tasks started prior to init will be exempted from
57666+ grsecurity's chroot restrictions. This option is mainly meant to
57667+ resolve Plymouth's performing privileged operations unnecessarily
57668+ in a chroot.
57669+
57670+endmenu
57671+menu "Kernel Auditing"
57672+depends on GRKERNSEC
57673+
57674+config GRKERNSEC_AUDIT_GROUP
57675+ bool "Single group for auditing"
57676+ help
57677+ If you say Y here, the exec and chdir logging features will only operate
57678+ on a group you specify. This option is recommended if you only want to
57679+ watch certain users instead of having a large amount of logs from the
57680+ entire system. If the sysctl option is enabled, a sysctl option with
57681+ name "audit_group" is created.
57682+
57683+config GRKERNSEC_AUDIT_GID
57684+ int "GID for auditing"
57685+ depends on GRKERNSEC_AUDIT_GROUP
57686+ default 1007
57687+
57688+config GRKERNSEC_EXECLOG
57689+ bool "Exec logging"
57690+ help
57691+ If you say Y here, all execve() calls will be logged (since the
57692+ other exec*() calls are frontends to execve(), all execution
57693+ will be logged). Useful for shell-servers that like to keep track
57694+ of their users. If the sysctl option is enabled, a sysctl option with
57695+ name "exec_logging" is created.
57696+ WARNING: This option when enabled will produce a LOT of logs, especially
57697+ on an active system.
57698+
57699+config GRKERNSEC_RESLOG
57700+ bool "Resource logging"
57701+ default y if GRKERNSEC_CONFIG_AUTO
57702+ help
57703+ If you say Y here, all attempts to overstep resource limits will
57704+ be logged with the resource name, the requested size, and the current
57705+ limit. It is highly recommended that you say Y here. If the sysctl
57706+ option is enabled, a sysctl option with name "resource_logging" is
57707+ created. If the RBAC system is enabled, the sysctl value is ignored.
57708+
57709+config GRKERNSEC_CHROOT_EXECLOG
57710+ bool "Log execs within chroot"
57711+ help
57712+ If you say Y here, all executions inside a chroot jail will be logged
57713+ to syslog. This can cause a large amount of logs if certain
57714+ applications (eg. djb's daemontools) are installed on the system, and
57715+ is therefore left as an option. If the sysctl option is enabled, a
57716+ sysctl option with name "chroot_execlog" is created.
57717+
57718+config GRKERNSEC_AUDIT_PTRACE
57719+ bool "Ptrace logging"
57720+ help
57721+ If you say Y here, all attempts to attach to a process via ptrace
57722+ will be logged. If the sysctl option is enabled, a sysctl option
57723+ with name "audit_ptrace" is created.
57724+
57725+config GRKERNSEC_AUDIT_CHDIR
57726+ bool "Chdir logging"
57727+ help
57728+ If you say Y here, all chdir() calls will be logged. If the sysctl
57729+ option is enabled, a sysctl option with name "audit_chdir" is created.
57730+
57731+config GRKERNSEC_AUDIT_MOUNT
57732+ bool "(Un)Mount logging"
57733+ help
57734+ If you say Y here, all mounts and unmounts will be logged. If the
57735+ sysctl option is enabled, a sysctl option with name "audit_mount" is
57736+ created.
57737+
57738+config GRKERNSEC_SIGNAL
57739+ bool "Signal logging"
57740+ default y if GRKERNSEC_CONFIG_AUTO
57741+ help
57742+ If you say Y here, certain important signals will be logged, such as
57743+ SIGSEGV, which will as a result inform you of when a error in a program
57744+ occurred, which in some cases could mean a possible exploit attempt.
57745+ If the sysctl option is enabled, a sysctl option with name
57746+ "signal_logging" is created.
57747+
57748+config GRKERNSEC_FORKFAIL
57749+ bool "Fork failure logging"
57750+ help
57751+ If you say Y here, all failed fork() attempts will be logged.
57752+ This could suggest a fork bomb, or someone attempting to overstep
57753+ their process limit. If the sysctl option is enabled, a sysctl option
57754+ with name "forkfail_logging" is created.
57755+
57756+config GRKERNSEC_TIME
57757+ bool "Time change logging"
57758+ default y if GRKERNSEC_CONFIG_AUTO
57759+ help
57760+ If you say Y here, any changes of the system clock will be logged.
57761+ If the sysctl option is enabled, a sysctl option with name
57762+ "timechange_logging" is created.
57763+
57764+config GRKERNSEC_PROC_IPADDR
57765+ bool "/proc/<pid>/ipaddr support"
57766+ default y if GRKERNSEC_CONFIG_AUTO
57767+ help
57768+ If you say Y here, a new entry will be added to each /proc/<pid>
57769+ directory that contains the IP address of the person using the task.
57770+ The IP is carried across local TCP and AF_UNIX stream sockets.
57771+ This information can be useful for IDS/IPSes to perform remote response
57772+ to a local attack. The entry is readable by only the owner of the
57773+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
57774+ the RBAC system), and thus does not create privacy concerns.
57775+
57776+config GRKERNSEC_RWXMAP_LOG
57777+ bool 'Denied RWX mmap/mprotect logging'
57778+ default y if GRKERNSEC_CONFIG_AUTO
57779+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
57780+ help
57781+ If you say Y here, calls to mmap() and mprotect() with explicit
57782+ usage of PROT_WRITE and PROT_EXEC together will be logged when
57783+ denied by the PAX_MPROTECT feature. If the sysctl option is
57784+ enabled, a sysctl option with name "rwxmap_logging" is created.
57785+
57786+config GRKERNSEC_AUDIT_TEXTREL
57787+ bool 'ELF text relocations logging (READ HELP)'
57788+ depends on PAX_MPROTECT
57789+ help
57790+ If you say Y here, text relocations will be logged with the filename
57791+ of the offending library or binary. The purpose of the feature is
57792+ to help Linux distribution developers get rid of libraries and
57793+ binaries that need text relocations which hinder the future progress
57794+ of PaX. Only Linux distribution developers should say Y here, and
57795+ never on a production machine, as this option creates an information
57796+ leak that could aid an attacker in defeating the randomization of
57797+ a single memory region. If the sysctl option is enabled, a sysctl
57798+ option with name "audit_textrel" is created.
57799+
57800+endmenu
57801+
57802+menu "Executable Protections"
57803+depends on GRKERNSEC
57804+
57805+config GRKERNSEC_DMESG
57806+ bool "Dmesg(8) restriction"
57807+ default y if GRKERNSEC_CONFIG_AUTO
57808+ help
57809+ If you say Y here, non-root users will not be able to use dmesg(8)
57810+ to view the contents of the kernel's circular log buffer.
57811+ The kernel's log buffer often contains kernel addresses and other
57812+ identifying information useful to an attacker in fingerprinting a
57813+ system for a targeted exploit.
57814+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
57815+ created.
57816+
57817+config GRKERNSEC_HARDEN_PTRACE
57818+ bool "Deter ptrace-based process snooping"
57819+ default y if GRKERNSEC_CONFIG_AUTO
57820+ help
57821+ If you say Y here, TTY sniffers and other malicious monitoring
57822+ programs implemented through ptrace will be defeated. If you
57823+ have been using the RBAC system, this option has already been
57824+ enabled for several years for all users, with the ability to make
57825+ fine-grained exceptions.
57826+
57827+ This option only affects the ability of non-root users to ptrace
57828+ processes that are not a descendent of the ptracing process.
57829+ This means that strace ./binary and gdb ./binary will still work,
57830+ but attaching to arbitrary processes will not. If the sysctl
57831+ option is enabled, a sysctl option with name "harden_ptrace" is
57832+ created.
57833+
57834+config GRKERNSEC_PTRACE_READEXEC
57835+ bool "Require read access to ptrace sensitive binaries"
57836+ default y if GRKERNSEC_CONFIG_AUTO
57837+ help
57838+ If you say Y here, unprivileged users will not be able to ptrace unreadable
57839+ binaries. This option is useful in environments that
57840+ remove the read bits (e.g. file mode 4711) from suid binaries to
57841+ prevent infoleaking of their contents. This option adds
57842+ consistency to the use of that file mode, as the binary could normally
57843+ be read out when run without privileges while ptracing.
57844+
57845+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
57846+ is created.
57847+
57848+config GRKERNSEC_SETXID
57849+ bool "Enforce consistent multithreaded privileges"
57850+ default y if GRKERNSEC_CONFIG_AUTO
57851+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
57852+ help
57853+ If you say Y here, a change from a root uid to a non-root uid
57854+ in a multithreaded application will cause the resulting uids,
57855+ gids, supplementary groups, and capabilities in that thread
57856+ to be propagated to the other threads of the process. In most
57857+ cases this is unnecessary, as glibc will emulate this behavior
57858+ on behalf of the application. Other libcs do not act in the
57859+ same way, allowing the other threads of the process to continue
57860+ running with root privileges. If the sysctl option is enabled,
57861+ a sysctl option with name "consistent_setxid" is created.
57862+
57863+config GRKERNSEC_TPE
57864+ bool "Trusted Path Execution (TPE)"
57865+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57866+ help
57867+ If you say Y here, you will be able to choose a gid to add to the
57868+ supplementary groups of users you want to mark as "untrusted."
57869+ These users will not be able to execute any files that are not in
57870+ root-owned directories writable only by root. If the sysctl option
57871+ is enabled, a sysctl option with name "tpe" is created.
57872+
57873+config GRKERNSEC_TPE_ALL
57874+ bool "Partially restrict all non-root users"
57875+ depends on GRKERNSEC_TPE
57876+ help
57877+ If you say Y here, all non-root users will be covered under
57878+ a weaker TPE restriction. This is separate from, and in addition to,
57879+ the main TPE options that you have selected elsewhere. Thus, if a
57880+ "trusted" GID is chosen, this restriction applies to even that GID.
57881+ Under this restriction, all non-root users will only be allowed to
57882+ execute files in directories they own that are not group or
57883+ world-writable, or in directories owned by root and writable only by
57884+ root. If the sysctl option is enabled, a sysctl option with name
57885+ "tpe_restrict_all" is created.
57886+
57887+config GRKERNSEC_TPE_INVERT
57888+ bool "Invert GID option"
57889+ depends on GRKERNSEC_TPE
57890+ help
57891+ If you say Y here, the group you specify in the TPE configuration will
57892+ decide what group TPE restrictions will be *disabled* for. This
57893+ option is useful if you want TPE restrictions to be applied to most
57894+ users on the system. If the sysctl option is enabled, a sysctl option
57895+ with name "tpe_invert" is created. Unlike other sysctl options, this
57896+ entry will default to on for backward-compatibility.
57897+
57898+config GRKERNSEC_TPE_GID
57899+ int
57900+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
57901+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
57902+
57903+config GRKERNSEC_TPE_UNTRUSTED_GID
57904+ int "GID for TPE-untrusted users"
57905+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
57906+ default 1005
57907+ help
57908+ Setting this GID determines what group TPE restrictions will be
57909+ *enabled* for. If the sysctl option is enabled, a sysctl option
57910+ with name "tpe_gid" is created.
57911+
57912+config GRKERNSEC_TPE_TRUSTED_GID
57913+ int "GID for TPE-trusted users"
57914+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
57915+ default 1005
57916+ help
57917+ Setting this GID determines what group TPE restrictions will be
57918+ *disabled* for. If the sysctl option is enabled, a sysctl option
57919+ with name "tpe_gid" is created.
57920+
57921+endmenu
57922+menu "Network Protections"
57923+depends on GRKERNSEC
57924+
57925+config GRKERNSEC_RANDNET
57926+ bool "Larger entropy pools"
57927+ default y if GRKERNSEC_CONFIG_AUTO
57928+ help
57929+ If you say Y here, the entropy pools used for many features of Linux
57930+ and grsecurity will be doubled in size. Since several grsecurity
57931+ features use additional randomness, it is recommended that you say Y
57932+ here. Saying Y here has a similar effect as modifying
57933+ /proc/sys/kernel/random/poolsize.
57934+
57935+config GRKERNSEC_BLACKHOLE
57936+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
57937+ default y if GRKERNSEC_CONFIG_AUTO
57938+ depends on NET
57939+ help
57940+ If you say Y here, neither TCP resets nor ICMP
57941+ destination-unreachable packets will be sent in response to packets
57942+ sent to ports for which no associated listening process exists.
57943+ This feature supports both IPV4 and IPV6 and exempts the
57944+ loopback interface from blackholing. Enabling this feature
57945+ makes a host more resilient to DoS attacks and reduces network
57946+ visibility against scanners.
57947+
57948+ The blackhole feature as-implemented is equivalent to the FreeBSD
57949+ blackhole feature, as it prevents RST responses to all packets, not
57950+ just SYNs. Under most application behavior this causes no
57951+ problems, but applications (like haproxy) may not close certain
57952+ connections in a way that cleanly terminates them on the remote
57953+ end, leaving the remote host in LAST_ACK state. Because of this
57954+ side-effect and to prevent intentional LAST_ACK DoSes, this
57955+ feature also adds automatic mitigation against such attacks.
57956+ The mitigation drastically reduces the amount of time a socket
57957+ can spend in LAST_ACK state. If you're using haproxy and not
57958+ all servers it connects to have this option enabled, consider
57959+ disabling this feature on the haproxy host.
57960+
57961+ If the sysctl option is enabled, two sysctl options with names
57962+ "ip_blackhole" and "lastack_retries" will be created.
57963+ While "ip_blackhole" takes the standard zero/non-zero on/off
57964+ toggle, "lastack_retries" uses the same kinds of values as
57965+ "tcp_retries1" and "tcp_retries2". The default value of 4
57966+ prevents a socket from lasting more than 45 seconds in LAST_ACK
57967+ state.
57968+
57969+config GRKERNSEC_NO_SIMULT_CONNECT
57970+ bool "Disable TCP Simultaneous Connect"
57971+ default y if GRKERNSEC_CONFIG_AUTO
57972+ depends on NET
57973+ help
57974+ If you say Y here, a feature by Willy Tarreau will be enabled that
57975+ removes a weakness in Linux's strict implementation of TCP that
57976+ allows two clients to connect to each other without either entering
57977+ a listening state. The weakness allows an attacker to easily prevent
57978+ a client from connecting to a known server provided the source port
57979+ for the connection is guessed correctly.
57980+
57981+ As the weakness could be used to prevent an antivirus or IPS from
57982+ fetching updates, or prevent an SSL gateway from fetching a CRL,
57983+ it should be eliminated by enabling this option. Though Linux is
57984+ one of few operating systems supporting simultaneous connect, it
57985+ has no legitimate use in practice and is rarely supported by firewalls.
57986+
57987+config GRKERNSEC_SOCKET
57988+ bool "Socket restrictions"
57989+ depends on NET
57990+ help
57991+ If you say Y here, you will be able to choose from several options.
57992+ If you assign a GID on your system and add it to the supplementary
57993+ groups of users you want to restrict socket access to, this patch
57994+ will perform up to three things, based on the option(s) you choose.
57995+
57996+config GRKERNSEC_SOCKET_ALL
57997+ bool "Deny any sockets to group"
57998+ depends on GRKERNSEC_SOCKET
57999+ help
58000+ If you say Y here, you will be able to choose a GID of whose users will
58001+ be unable to connect to other hosts from your machine or run server
58002+ applications from your machine. If the sysctl option is enabled, a
58003+ sysctl option with name "socket_all" is created.
58004+
58005+config GRKERNSEC_SOCKET_ALL_GID
58006+ int "GID to deny all sockets for"
58007+ depends on GRKERNSEC_SOCKET_ALL
58008+ default 1004
58009+ help
58010+ Here you can choose the GID to disable socket access for. Remember to
58011+ add the users you want socket access disabled for to the GID
58012+ specified here. If the sysctl option is enabled, a sysctl option
58013+ with name "socket_all_gid" is created.
58014+
58015+config GRKERNSEC_SOCKET_CLIENT
58016+ bool "Deny client sockets to group"
58017+ depends on GRKERNSEC_SOCKET
58018+ help
58019+ If you say Y here, you will be able to choose a GID of whose users will
58020+ be unable to connect to other hosts from your machine, but will be
58021+ able to run servers. If this option is enabled, all users in the group
58022+ you specify will have to use passive mode when initiating ftp transfers
58023+ from the shell on your machine. If the sysctl option is enabled, a
58024+ sysctl option with name "socket_client" is created.
58025+
58026+config GRKERNSEC_SOCKET_CLIENT_GID
58027+ int "GID to deny client sockets for"
58028+ depends on GRKERNSEC_SOCKET_CLIENT
58029+ default 1003
58030+ help
58031+ Here you can choose the GID to disable client socket access for.
58032+ Remember to add the users you want client socket access disabled for to
58033+ the GID specified here. If the sysctl option is enabled, a sysctl
58034+ option with name "socket_client_gid" is created.
58035+
58036+config GRKERNSEC_SOCKET_SERVER
58037+ bool "Deny server sockets to group"
58038+ depends on GRKERNSEC_SOCKET
58039+ help
58040+ If you say Y here, you will be able to choose a GID of whose users will
58041+ be unable to run server applications from your machine. If the sysctl
58042+ option is enabled, a sysctl option with name "socket_server" is created.
58043+
58044+config GRKERNSEC_SOCKET_SERVER_GID
58045+ int "GID to deny server sockets for"
58046+ depends on GRKERNSEC_SOCKET_SERVER
58047+ default 1002
58048+ help
58049+ Here you can choose the GID to disable server socket access for.
58050+ Remember to add the users you want server socket access disabled for to
58051+ the GID specified here. If the sysctl option is enabled, a sysctl
58052+ option with name "socket_server_gid" is created.
58053+
58054+endmenu
58055+menu "Sysctl Support"
58056+depends on GRKERNSEC && SYSCTL
58057+
58058+config GRKERNSEC_SYSCTL
58059+ bool "Sysctl support"
58060+ default y if GRKERNSEC_CONFIG_AUTO
58061+ help
58062+ If you say Y here, you will be able to change the options that
58063+ grsecurity runs with at bootup, without having to recompile your
58064+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
58065+ to enable (1) or disable (0) various features. All the sysctl entries
58066+ are mutable until the "grsec_lock" entry is set to a non-zero value.
58067+ All features enabled in the kernel configuration are disabled at boot
58068+ if you do not say Y to the "Turn on features by default" option.
58069+ All options should be set at startup, and the grsec_lock entry should
58070+ be set to a non-zero value after all the options are set.
58071+ *THIS IS EXTREMELY IMPORTANT*
58072+
58073+config GRKERNSEC_SYSCTL_DISTRO
58074+ bool "Extra sysctl support for distro makers (READ HELP)"
58075+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
58076+ help
58077+ If you say Y here, additional sysctl options will be created
58078+ for features that affect processes running as root. Therefore,
58079+ it is critical when using this option that the grsec_lock entry be
58080+ enabled after boot. Only distros with prebuilt kernel packages
58081+ with this option enabled that can ensure grsec_lock is enabled
58082+ after boot should use this option.
58083+ *Failure to set grsec_lock after boot makes all grsec features
58084+ this option covers useless*
58085+
58086+ Currently this option creates the following sysctl entries:
58087+ "Disable Privileged I/O": "disable_priv_io"
58088+
58089+config GRKERNSEC_SYSCTL_ON
58090+ bool "Turn on features by default"
58091+ default y if GRKERNSEC_CONFIG_AUTO
58092+ depends on GRKERNSEC_SYSCTL
58093+ help
58094+ If you say Y here, instead of having all features enabled in the
58095+ kernel configuration disabled at boot time, the features will be
58096+ enabled at boot time. It is recommended you say Y here unless
58097+ there is some reason you would want all sysctl-tunable features to
58098+ be disabled by default. As mentioned elsewhere, it is important
58099+ to enable the grsec_lock entry once you have finished modifying
58100+ the sysctl entries.
58101+
58102+endmenu
58103+menu "Logging Options"
58104+depends on GRKERNSEC
58105+
58106+config GRKERNSEC_FLOODTIME
58107+ int "Seconds in between log messages (minimum)"
58108+ default 10
58109+ help
58110+ This option allows you to enforce the number of seconds between
58111+ grsecurity log messages. The default should be suitable for most
58112+ people, however, if you choose to change it, choose a value small enough
58113+ to allow informative logs to be produced, but large enough to
58114+ prevent flooding.
58115+
58116+config GRKERNSEC_FLOODBURST
58117+ int "Number of messages in a burst (maximum)"
58118+ default 6
58119+ help
58120+ This option allows you to choose the maximum number of messages allowed
58121+ within the flood time interval you chose in a separate option. The
58122+ default should be suitable for most people, however if you find that
58123+ many of your logs are being interpreted as flooding, you may want to
58124+ raise this value.
58125+
58126+endmenu
58127diff --git a/grsecurity/Makefile b/grsecurity/Makefile
58128new file mode 100644
58129index 0000000..1b9afa9
58130--- /dev/null
58131+++ b/grsecurity/Makefile
58132@@ -0,0 +1,38 @@
58133+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
58134+# during 2001-2009 it has been completely redesigned by Brad Spengler
58135+# into an RBAC system
58136+#
58137+# All code in this directory and various hooks inserted throughout the kernel
58138+# are copyright Brad Spengler - Open Source Security, Inc., and released
58139+# under the GPL v2 or higher
58140+
58141+KBUILD_CFLAGS += -Werror
58142+
58143+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
58144+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
58145+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
58146+
58147+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
58148+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
58149+ gracl_learn.o grsec_log.o
58150+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
58151+
58152+ifdef CONFIG_NET
58153+obj-y += grsec_sock.o
58154+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
58155+endif
58156+
58157+ifndef CONFIG_GRKERNSEC
58158+obj-y += grsec_disabled.o
58159+endif
58160+
58161+ifdef CONFIG_GRKERNSEC_HIDESYM
58162+extra-y := grsec_hidesym.o
58163+$(obj)/grsec_hidesym.o:
58164+ @-chmod -f 500 /boot
58165+ @-chmod -f 500 /lib/modules
58166+ @-chmod -f 500 /lib64/modules
58167+ @-chmod -f 500 /lib32/modules
58168+ @-chmod -f 700 .
58169+ @echo ' grsec: protected kernel image paths'
58170+endif
58171diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
58172new file mode 100644
58173index 0000000..0d5c602
58174--- /dev/null
58175+++ b/grsecurity/gracl.c
58176@@ -0,0 +1,4073 @@
58177+#include <linux/kernel.h>
58178+#include <linux/module.h>
58179+#include <linux/sched.h>
58180+#include <linux/mm.h>
58181+#include <linux/file.h>
58182+#include <linux/fs.h>
58183+#include <linux/namei.h>
58184+#include <linux/mount.h>
58185+#include <linux/tty.h>
58186+#include <linux/proc_fs.h>
58187+#include <linux/lglock.h>
58188+#include <linux/slab.h>
58189+#include <linux/vmalloc.h>
58190+#include <linux/types.h>
58191+#include <linux/sysctl.h>
58192+#include <linux/netdevice.h>
58193+#include <linux/ptrace.h>
58194+#include <linux/gracl.h>
58195+#include <linux/gralloc.h>
58196+#include <linux/security.h>
58197+#include <linux/grinternal.h>
58198+#include <linux/pid_namespace.h>
58199+#include <linux/stop_machine.h>
58200+#include <linux/fdtable.h>
58201+#include <linux/percpu.h>
58202+#include <linux/lglock.h>
58203+#include <linux/hugetlb.h>
58204+#include <linux/posix-timers.h>
58205+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58206+#include <linux/magic.h>
58207+#include <linux/pagemap.h>
58208+#include "../fs/btrfs/async-thread.h"
58209+#include "../fs/btrfs/ctree.h"
58210+#include "../fs/btrfs/btrfs_inode.h"
58211+#endif
58212+#include "../fs/mount.h"
58213+
58214+#include <asm/uaccess.h>
58215+#include <asm/errno.h>
58216+#include <asm/mman.h>
58217+
58218+extern struct lglock vfsmount_lock;
58219+
58220+static struct acl_role_db acl_role_set;
58221+static struct name_db name_set;
58222+static struct inodev_db inodev_set;
58223+
58224+/* for keeping track of userspace pointers used for subjects, so we
58225+ can share references in the kernel as well
58226+*/
58227+
58228+static struct path real_root;
58229+
58230+static struct acl_subj_map_db subj_map_set;
58231+
58232+static struct acl_role_label *default_role;
58233+
58234+static struct acl_role_label *role_list;
58235+
58236+static u16 acl_sp_role_value;
58237+
58238+extern char *gr_shared_page[4];
58239+static DEFINE_MUTEX(gr_dev_mutex);
58240+DEFINE_RWLOCK(gr_inode_lock);
58241+
58242+struct gr_arg *gr_usermode;
58243+
58244+static unsigned int gr_status __read_only = GR_STATUS_INIT;
58245+
58246+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
58247+extern void gr_clear_learn_entries(void);
58248+
58249+unsigned char *gr_system_salt;
58250+unsigned char *gr_system_sum;
58251+
58252+static struct sprole_pw **acl_special_roles = NULL;
58253+static __u16 num_sprole_pws = 0;
58254+
58255+static struct acl_role_label *kernel_role = NULL;
58256+
58257+static unsigned int gr_auth_attempts = 0;
58258+static unsigned long gr_auth_expires = 0UL;
58259+
58260+#ifdef CONFIG_NET
58261+extern struct vfsmount *sock_mnt;
58262+#endif
58263+
58264+extern struct vfsmount *pipe_mnt;
58265+extern struct vfsmount *shm_mnt;
58266+
58267+#ifdef CONFIG_HUGETLBFS
58268+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58269+#endif
58270+
58271+static struct acl_object_label *fakefs_obj_rw;
58272+static struct acl_object_label *fakefs_obj_rwx;
58273+
58274+extern int gr_init_uidset(void);
58275+extern void gr_free_uidset(void);
58276+extern void gr_remove_uid(uid_t uid);
58277+extern int gr_find_uid(uid_t uid);
58278+
58279+__inline__ int
58280+gr_acl_is_enabled(void)
58281+{
58282+ return (gr_status & GR_READY);
58283+}
58284+
58285+static inline dev_t __get_dev(const struct dentry *dentry)
58286+{
58287+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58288+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
58289+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
58290+ else
58291+#endif
58292+ return dentry->d_sb->s_dev;
58293+}
58294+
58295+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58296+{
58297+ return __get_dev(dentry);
58298+}
58299+
58300+static char gr_task_roletype_to_char(struct task_struct *task)
58301+{
58302+ switch (task->role->roletype &
58303+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
58304+ GR_ROLE_SPECIAL)) {
58305+ case GR_ROLE_DEFAULT:
58306+ return 'D';
58307+ case GR_ROLE_USER:
58308+ return 'U';
58309+ case GR_ROLE_GROUP:
58310+ return 'G';
58311+ case GR_ROLE_SPECIAL:
58312+ return 'S';
58313+ }
58314+
58315+ return 'X';
58316+}
58317+
58318+char gr_roletype_to_char(void)
58319+{
58320+ return gr_task_roletype_to_char(current);
58321+}
58322+
58323+__inline__ int
58324+gr_acl_tpe_check(void)
58325+{
58326+ if (unlikely(!(gr_status & GR_READY)))
58327+ return 0;
58328+ if (current->role->roletype & GR_ROLE_TPE)
58329+ return 1;
58330+ else
58331+ return 0;
58332+}
58333+
58334+int
58335+gr_handle_rawio(const struct inode *inode)
58336+{
58337+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58338+ if (inode && S_ISBLK(inode->i_mode) &&
58339+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58340+ !capable(CAP_SYS_RAWIO))
58341+ return 1;
58342+#endif
58343+ return 0;
58344+}
58345+
58346+static int
58347+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
58348+{
58349+ if (likely(lena != lenb))
58350+ return 0;
58351+
58352+ return !memcmp(a, b, lena);
58353+}
58354+
58355+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
58356+{
58357+ *buflen -= namelen;
58358+ if (*buflen < 0)
58359+ return -ENAMETOOLONG;
58360+ *buffer -= namelen;
58361+ memcpy(*buffer, str, namelen);
58362+ return 0;
58363+}
58364+
58365+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
58366+{
58367+ return prepend(buffer, buflen, name->name, name->len);
58368+}
58369+
58370+static int prepend_path(const struct path *path, struct path *root,
58371+ char **buffer, int *buflen)
58372+{
58373+ struct dentry *dentry = path->dentry;
58374+ struct vfsmount *vfsmnt = path->mnt;
58375+ struct mount *mnt = real_mount(vfsmnt);
58376+ bool slash = false;
58377+ int error = 0;
58378+
58379+ while (dentry != root->dentry || vfsmnt != root->mnt) {
58380+ struct dentry * parent;
58381+
58382+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
58383+ /* Global root? */
58384+ if (!mnt_has_parent(mnt)) {
58385+ goto out;
58386+ }
58387+ dentry = mnt->mnt_mountpoint;
58388+ mnt = mnt->mnt_parent;
58389+ vfsmnt = &mnt->mnt;
58390+ continue;
58391+ }
58392+ parent = dentry->d_parent;
58393+ prefetch(parent);
58394+ spin_lock(&dentry->d_lock);
58395+ error = prepend_name(buffer, buflen, &dentry->d_name);
58396+ spin_unlock(&dentry->d_lock);
58397+ if (!error)
58398+ error = prepend(buffer, buflen, "/", 1);
58399+ if (error)
58400+ break;
58401+
58402+ slash = true;
58403+ dentry = parent;
58404+ }
58405+
58406+out:
58407+ if (!error && !slash)
58408+ error = prepend(buffer, buflen, "/", 1);
58409+
58410+ return error;
58411+}
58412+
58413+/* this must be called with vfsmount_lock and rename_lock held */
58414+
58415+static char *__our_d_path(const struct path *path, struct path *root,
58416+ char *buf, int buflen)
58417+{
58418+ char *res = buf + buflen;
58419+ int error;
58420+
58421+ prepend(&res, &buflen, "\0", 1);
58422+ error = prepend_path(path, root, &res, &buflen);
58423+ if (error)
58424+ return ERR_PTR(error);
58425+
58426+ return res;
58427+}
58428+
58429+static char *
58430+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
58431+{
58432+ char *retval;
58433+
58434+ retval = __our_d_path(path, root, buf, buflen);
58435+ if (unlikely(IS_ERR(retval)))
58436+ retval = strcpy(buf, "<path too long>");
58437+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
58438+ retval[1] = '\0';
58439+
58440+ return retval;
58441+}
58442+
58443+static char *
58444+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58445+ char *buf, int buflen)
58446+{
58447+ struct path path;
58448+ char *res;
58449+
58450+ path.dentry = (struct dentry *)dentry;
58451+ path.mnt = (struct vfsmount *)vfsmnt;
58452+
58453+ /* we can use real_root.dentry, real_root.mnt, because this is only called
58454+ by the RBAC system */
58455+ res = gen_full_path(&path, &real_root, buf, buflen);
58456+
58457+ return res;
58458+}
58459+
58460+static char *
58461+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58462+ char *buf, int buflen)
58463+{
58464+ char *res;
58465+ struct path path;
58466+ struct path root;
58467+ struct task_struct *reaper = init_pid_ns.child_reaper;
58468+
58469+ path.dentry = (struct dentry *)dentry;
58470+ path.mnt = (struct vfsmount *)vfsmnt;
58471+
58472+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
58473+ get_fs_root(reaper->fs, &root);
58474+
58475+ br_read_lock(&vfsmount_lock);
58476+ write_seqlock(&rename_lock);
58477+ res = gen_full_path(&path, &root, buf, buflen);
58478+ write_sequnlock(&rename_lock);
58479+ br_read_unlock(&vfsmount_lock);
58480+
58481+ path_put(&root);
58482+ return res;
58483+}
58484+
58485+static char *
58486+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58487+{
58488+ char *ret;
58489+ br_read_lock(&vfsmount_lock);
58490+ write_seqlock(&rename_lock);
58491+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58492+ PAGE_SIZE);
58493+ write_sequnlock(&rename_lock);
58494+ br_read_unlock(&vfsmount_lock);
58495+ return ret;
58496+}
58497+
58498+static char *
58499+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58500+{
58501+ char *ret;
58502+ char *buf;
58503+ int buflen;
58504+
58505+ br_read_lock(&vfsmount_lock);
58506+ write_seqlock(&rename_lock);
58507+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
58508+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
58509+ buflen = (int)(ret - buf);
58510+ if (buflen >= 5)
58511+ prepend(&ret, &buflen, "/proc", 5);
58512+ else
58513+ ret = strcpy(buf, "<path too long>");
58514+ write_sequnlock(&rename_lock);
58515+ br_read_unlock(&vfsmount_lock);
58516+ return ret;
58517+}
58518+
58519+char *
58520+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
58521+{
58522+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58523+ PAGE_SIZE);
58524+}
58525+
58526+char *
58527+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
58528+{
58529+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58530+ PAGE_SIZE);
58531+}
58532+
58533+char *
58534+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
58535+{
58536+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
58537+ PAGE_SIZE);
58538+}
58539+
58540+char *
58541+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
58542+{
58543+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
58544+ PAGE_SIZE);
58545+}
58546+
58547+char *
58548+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
58549+{
58550+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
58551+ PAGE_SIZE);
58552+}
58553+
58554+__inline__ __u32
58555+to_gr_audit(const __u32 reqmode)
58556+{
58557+ /* masks off auditable permission flags, then shifts them to create
58558+ auditing flags, and adds the special case of append auditing if
58559+ we're requesting write */
58560+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
58561+}
58562+
58563+struct acl_subject_label *
58564+lookup_subject_map(const struct acl_subject_label *userp)
58565+{
58566+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
58567+ struct subject_map *match;
58568+
58569+ match = subj_map_set.s_hash[index];
58570+
58571+ while (match && match->user != userp)
58572+ match = match->next;
58573+
58574+ if (match != NULL)
58575+ return match->kernel;
58576+ else
58577+ return NULL;
58578+}
58579+
58580+static void
58581+insert_subj_map_entry(struct subject_map *subjmap)
58582+{
58583+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
58584+ struct subject_map **curr;
58585+
58586+ subjmap->prev = NULL;
58587+
58588+ curr = &subj_map_set.s_hash[index];
58589+ if (*curr != NULL)
58590+ (*curr)->prev = subjmap;
58591+
58592+ subjmap->next = *curr;
58593+ *curr = subjmap;
58594+
58595+ return;
58596+}
58597+
58598+static struct acl_role_label *
58599+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
58600+ const gid_t gid)
58601+{
58602+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
58603+ struct acl_role_label *match;
58604+ struct role_allowed_ip *ipp;
58605+ unsigned int x;
58606+ u32 curr_ip = task->signal->curr_ip;
58607+
58608+ task->signal->saved_ip = curr_ip;
58609+
58610+ match = acl_role_set.r_hash[index];
58611+
58612+ while (match) {
58613+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
58614+ for (x = 0; x < match->domain_child_num; x++) {
58615+ if (match->domain_children[x] == uid)
58616+ goto found;
58617+ }
58618+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
58619+ break;
58620+ match = match->next;
58621+ }
58622+found:
58623+ if (match == NULL) {
58624+ try_group:
58625+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
58626+ match = acl_role_set.r_hash[index];
58627+
58628+ while (match) {
58629+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
58630+ for (x = 0; x < match->domain_child_num; x++) {
58631+ if (match->domain_children[x] == gid)
58632+ goto found2;
58633+ }
58634+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
58635+ break;
58636+ match = match->next;
58637+ }
58638+found2:
58639+ if (match == NULL)
58640+ match = default_role;
58641+ if (match->allowed_ips == NULL)
58642+ return match;
58643+ else {
58644+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58645+ if (likely
58646+ ((ntohl(curr_ip) & ipp->netmask) ==
58647+ (ntohl(ipp->addr) & ipp->netmask)))
58648+ return match;
58649+ }
58650+ match = default_role;
58651+ }
58652+ } else if (match->allowed_ips == NULL) {
58653+ return match;
58654+ } else {
58655+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58656+ if (likely
58657+ ((ntohl(curr_ip) & ipp->netmask) ==
58658+ (ntohl(ipp->addr) & ipp->netmask)))
58659+ return match;
58660+ }
58661+ goto try_group;
58662+ }
58663+
58664+ return match;
58665+}
58666+
58667+struct acl_subject_label *
58668+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
58669+ const struct acl_role_label *role)
58670+{
58671+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58672+ struct acl_subject_label *match;
58673+
58674+ match = role->subj_hash[index];
58675+
58676+ while (match && (match->inode != ino || match->device != dev ||
58677+ (match->mode & GR_DELETED))) {
58678+ match = match->next;
58679+ }
58680+
58681+ if (match && !(match->mode & GR_DELETED))
58682+ return match;
58683+ else
58684+ return NULL;
58685+}
58686+
58687+struct acl_subject_label *
58688+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
58689+ const struct acl_role_label *role)
58690+{
58691+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58692+ struct acl_subject_label *match;
58693+
58694+ match = role->subj_hash[index];
58695+
58696+ while (match && (match->inode != ino || match->device != dev ||
58697+ !(match->mode & GR_DELETED))) {
58698+ match = match->next;
58699+ }
58700+
58701+ if (match && (match->mode & GR_DELETED))
58702+ return match;
58703+ else
58704+ return NULL;
58705+}
58706+
58707+static struct acl_object_label *
58708+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
58709+ const struct acl_subject_label *subj)
58710+{
58711+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58712+ struct acl_object_label *match;
58713+
58714+ match = subj->obj_hash[index];
58715+
58716+ while (match && (match->inode != ino || match->device != dev ||
58717+ (match->mode & GR_DELETED))) {
58718+ match = match->next;
58719+ }
58720+
58721+ if (match && !(match->mode & GR_DELETED))
58722+ return match;
58723+ else
58724+ return NULL;
58725+}
58726+
58727+static struct acl_object_label *
58728+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
58729+ const struct acl_subject_label *subj)
58730+{
58731+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58732+ struct acl_object_label *match;
58733+
58734+ match = subj->obj_hash[index];
58735+
58736+ while (match && (match->inode != ino || match->device != dev ||
58737+ !(match->mode & GR_DELETED))) {
58738+ match = match->next;
58739+ }
58740+
58741+ if (match && (match->mode & GR_DELETED))
58742+ return match;
58743+
58744+ match = subj->obj_hash[index];
58745+
58746+ while (match && (match->inode != ino || match->device != dev ||
58747+ (match->mode & GR_DELETED))) {
58748+ match = match->next;
58749+ }
58750+
58751+ if (match && !(match->mode & GR_DELETED))
58752+ return match;
58753+ else
58754+ return NULL;
58755+}
58756+
58757+static struct name_entry *
58758+lookup_name_entry(const char *name)
58759+{
58760+ unsigned int len = strlen(name);
58761+ unsigned int key = full_name_hash(name, len);
58762+ unsigned int index = key % name_set.n_size;
58763+ struct name_entry *match;
58764+
58765+ match = name_set.n_hash[index];
58766+
58767+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
58768+ match = match->next;
58769+
58770+ return match;
58771+}
58772+
58773+static struct name_entry *
58774+lookup_name_entry_create(const char *name)
58775+{
58776+ unsigned int len = strlen(name);
58777+ unsigned int key = full_name_hash(name, len);
58778+ unsigned int index = key % name_set.n_size;
58779+ struct name_entry *match;
58780+
58781+ match = name_set.n_hash[index];
58782+
58783+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58784+ !match->deleted))
58785+ match = match->next;
58786+
58787+ if (match && match->deleted)
58788+ return match;
58789+
58790+ match = name_set.n_hash[index];
58791+
58792+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58793+ match->deleted))
58794+ match = match->next;
58795+
58796+ if (match && !match->deleted)
58797+ return match;
58798+ else
58799+ return NULL;
58800+}
58801+
58802+static struct inodev_entry *
58803+lookup_inodev_entry(const ino_t ino, const dev_t dev)
58804+{
58805+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
58806+ struct inodev_entry *match;
58807+
58808+ match = inodev_set.i_hash[index];
58809+
58810+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
58811+ match = match->next;
58812+
58813+ return match;
58814+}
58815+
58816+static void
58817+insert_inodev_entry(struct inodev_entry *entry)
58818+{
58819+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
58820+ inodev_set.i_size);
58821+ struct inodev_entry **curr;
58822+
58823+ entry->prev = NULL;
58824+
58825+ curr = &inodev_set.i_hash[index];
58826+ if (*curr != NULL)
58827+ (*curr)->prev = entry;
58828+
58829+ entry->next = *curr;
58830+ *curr = entry;
58831+
58832+ return;
58833+}
58834+
58835+static void
58836+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
58837+{
58838+ unsigned int index =
58839+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
58840+ struct acl_role_label **curr;
58841+ struct acl_role_label *tmp, *tmp2;
58842+
58843+ curr = &acl_role_set.r_hash[index];
58844+
58845+ /* simple case, slot is empty, just set it to our role */
58846+ if (*curr == NULL) {
58847+ *curr = role;
58848+ } else {
58849+ /* example:
58850+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
58851+ 2 -> 3
58852+ */
58853+ /* first check to see if we can already be reached via this slot */
58854+ tmp = *curr;
58855+ while (tmp && tmp != role)
58856+ tmp = tmp->next;
58857+ if (tmp == role) {
58858+ /* we don't need to add ourselves to this slot's chain */
58859+ return;
58860+ }
58861+ /* we need to add ourselves to this chain, two cases */
58862+ if (role->next == NULL) {
58863+ /* simple case, append the current chain to our role */
58864+ role->next = *curr;
58865+ *curr = role;
58866+ } else {
58867+ /* 1 -> 2 -> 3 -> 4
58868+ 2 -> 3 -> 4
58869+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
58870+ */
58871+ /* trickier case: walk our role's chain until we find
58872+ the role for the start of the current slot's chain */
58873+ tmp = role;
58874+ tmp2 = *curr;
58875+ while (tmp->next && tmp->next != tmp2)
58876+ tmp = tmp->next;
58877+ if (tmp->next == tmp2) {
58878+ /* from example above, we found 3, so just
58879+ replace this slot's chain with ours */
58880+ *curr = role;
58881+ } else {
58882+ /* we didn't find a subset of our role's chain
58883+ in the current slot's chain, so append their
58884+ chain to ours, and set us as the first role in
58885+ the slot's chain
58886+
58887+ we could fold this case with the case above,
58888+ but making it explicit for clarity
58889+ */
58890+ tmp->next = tmp2;
58891+ *curr = role;
58892+ }
58893+ }
58894+ }
58895+
58896+ return;
58897+}
58898+
58899+static void
58900+insert_acl_role_label(struct acl_role_label *role)
58901+{
58902+ int i;
58903+
58904+ if (role_list == NULL) {
58905+ role_list = role;
58906+ role->prev = NULL;
58907+ } else {
58908+ role->prev = role_list;
58909+ role_list = role;
58910+ }
58911+
58912+ /* used for hash chains */
58913+ role->next = NULL;
58914+
58915+ if (role->roletype & GR_ROLE_DOMAIN) {
58916+ for (i = 0; i < role->domain_child_num; i++)
58917+ __insert_acl_role_label(role, role->domain_children[i]);
58918+ } else
58919+ __insert_acl_role_label(role, role->uidgid);
58920+}
58921+
58922+static int
58923+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
58924+{
58925+ struct name_entry **curr, *nentry;
58926+ struct inodev_entry *ientry;
58927+ unsigned int len = strlen(name);
58928+ unsigned int key = full_name_hash(name, len);
58929+ unsigned int index = key % name_set.n_size;
58930+
58931+ curr = &name_set.n_hash[index];
58932+
58933+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
58934+ curr = &((*curr)->next);
58935+
58936+ if (*curr != NULL)
58937+ return 1;
58938+
58939+ nentry = acl_alloc(sizeof (struct name_entry));
58940+ if (nentry == NULL)
58941+ return 0;
58942+ ientry = acl_alloc(sizeof (struct inodev_entry));
58943+ if (ientry == NULL)
58944+ return 0;
58945+ ientry->nentry = nentry;
58946+
58947+ nentry->key = key;
58948+ nentry->name = name;
58949+ nentry->inode = inode;
58950+ nentry->device = device;
58951+ nentry->len = len;
58952+ nentry->deleted = deleted;
58953+
58954+ nentry->prev = NULL;
58955+ curr = &name_set.n_hash[index];
58956+ if (*curr != NULL)
58957+ (*curr)->prev = nentry;
58958+ nentry->next = *curr;
58959+ *curr = nentry;
58960+
58961+ /* insert us into the table searchable by inode/dev */
58962+ insert_inodev_entry(ientry);
58963+
58964+ return 1;
58965+}
58966+
58967+static void
58968+insert_acl_obj_label(struct acl_object_label *obj,
58969+ struct acl_subject_label *subj)
58970+{
58971+ unsigned int index =
58972+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
58973+ struct acl_object_label **curr;
58974+
58975+
58976+ obj->prev = NULL;
58977+
58978+ curr = &subj->obj_hash[index];
58979+ if (*curr != NULL)
58980+ (*curr)->prev = obj;
58981+
58982+ obj->next = *curr;
58983+ *curr = obj;
58984+
58985+ return;
58986+}
58987+
58988+static void
58989+insert_acl_subj_label(struct acl_subject_label *obj,
58990+ struct acl_role_label *role)
58991+{
58992+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
58993+ struct acl_subject_label **curr;
58994+
58995+ obj->prev = NULL;
58996+
58997+ curr = &role->subj_hash[index];
58998+ if (*curr != NULL)
58999+ (*curr)->prev = obj;
59000+
59001+ obj->next = *curr;
59002+ *curr = obj;
59003+
59004+ return;
59005+}
59006+
59007+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
59008+
59009+static void *
59010+create_table(__u32 * len, int elementsize)
59011+{
59012+ unsigned int table_sizes[] = {
59013+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
59014+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
59015+ 4194301, 8388593, 16777213, 33554393, 67108859
59016+ };
59017+ void *newtable = NULL;
59018+ unsigned int pwr = 0;
59019+
59020+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
59021+ table_sizes[pwr] <= *len)
59022+ pwr++;
59023+
59024+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
59025+ return newtable;
59026+
59027+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
59028+ newtable =
59029+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
59030+ else
59031+ newtable = vmalloc(table_sizes[pwr] * elementsize);
59032+
59033+ *len = table_sizes[pwr];
59034+
59035+ return newtable;
59036+}
59037+
59038+static int
59039+init_variables(const struct gr_arg *arg)
59040+{
59041+ struct task_struct *reaper = init_pid_ns.child_reaper;
59042+ unsigned int stacksize;
59043+
59044+ subj_map_set.s_size = arg->role_db.num_subjects;
59045+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
59046+ name_set.n_size = arg->role_db.num_objects;
59047+ inodev_set.i_size = arg->role_db.num_objects;
59048+
59049+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
59050+ !name_set.n_size || !inodev_set.i_size)
59051+ return 1;
59052+
59053+ if (!gr_init_uidset())
59054+ return 1;
59055+
59056+ /* set up the stack that holds allocation info */
59057+
59058+ stacksize = arg->role_db.num_pointers + 5;
59059+
59060+ if (!acl_alloc_stack_init(stacksize))
59061+ return 1;
59062+
59063+ /* grab reference for the real root dentry and vfsmount */
59064+ get_fs_root(reaper->fs, &real_root);
59065+
59066+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59067+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
59068+#endif
59069+
59070+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
59071+ if (fakefs_obj_rw == NULL)
59072+ return 1;
59073+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
59074+
59075+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
59076+ if (fakefs_obj_rwx == NULL)
59077+ return 1;
59078+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
59079+
59080+ subj_map_set.s_hash =
59081+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
59082+ acl_role_set.r_hash =
59083+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
59084+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
59085+ inodev_set.i_hash =
59086+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
59087+
59088+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
59089+ !name_set.n_hash || !inodev_set.i_hash)
59090+ return 1;
59091+
59092+ memset(subj_map_set.s_hash, 0,
59093+ sizeof(struct subject_map *) * subj_map_set.s_size);
59094+ memset(acl_role_set.r_hash, 0,
59095+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
59096+ memset(name_set.n_hash, 0,
59097+ sizeof (struct name_entry *) * name_set.n_size);
59098+ memset(inodev_set.i_hash, 0,
59099+ sizeof (struct inodev_entry *) * inodev_set.i_size);
59100+
59101+ return 0;
59102+}
59103+
59104+/* free information not needed after startup
59105+ currently contains user->kernel pointer mappings for subjects
59106+*/
59107+
59108+static void
59109+free_init_variables(void)
59110+{
59111+ __u32 i;
59112+
59113+ if (subj_map_set.s_hash) {
59114+ for (i = 0; i < subj_map_set.s_size; i++) {
59115+ if (subj_map_set.s_hash[i]) {
59116+ kfree(subj_map_set.s_hash[i]);
59117+ subj_map_set.s_hash[i] = NULL;
59118+ }
59119+ }
59120+
59121+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
59122+ PAGE_SIZE)
59123+ kfree(subj_map_set.s_hash);
59124+ else
59125+ vfree(subj_map_set.s_hash);
59126+ }
59127+
59128+ return;
59129+}
59130+
59131+static void
59132+free_variables(void)
59133+{
59134+ struct acl_subject_label *s;
59135+ struct acl_role_label *r;
59136+ struct task_struct *task, *task2;
59137+ unsigned int x;
59138+
59139+ gr_clear_learn_entries();
59140+
59141+ read_lock(&tasklist_lock);
59142+ do_each_thread(task2, task) {
59143+ task->acl_sp_role = 0;
59144+ task->acl_role_id = 0;
59145+ task->acl = NULL;
59146+ task->role = NULL;
59147+ } while_each_thread(task2, task);
59148+ read_unlock(&tasklist_lock);
59149+
59150+ /* release the reference to the real root dentry and vfsmount */
59151+ path_put(&real_root);
59152+ memset(&real_root, 0, sizeof(real_root));
59153+
59154+ /* free all object hash tables */
59155+
59156+ FOR_EACH_ROLE_START(r)
59157+ if (r->subj_hash == NULL)
59158+ goto next_role;
59159+ FOR_EACH_SUBJECT_START(r, s, x)
59160+ if (s->obj_hash == NULL)
59161+ break;
59162+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59163+ kfree(s->obj_hash);
59164+ else
59165+ vfree(s->obj_hash);
59166+ FOR_EACH_SUBJECT_END(s, x)
59167+ FOR_EACH_NESTED_SUBJECT_START(r, s)
59168+ if (s->obj_hash == NULL)
59169+ break;
59170+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59171+ kfree(s->obj_hash);
59172+ else
59173+ vfree(s->obj_hash);
59174+ FOR_EACH_NESTED_SUBJECT_END(s)
59175+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
59176+ kfree(r->subj_hash);
59177+ else
59178+ vfree(r->subj_hash);
59179+ r->subj_hash = NULL;
59180+next_role:
59181+ FOR_EACH_ROLE_END(r)
59182+
59183+ acl_free_all();
59184+
59185+ if (acl_role_set.r_hash) {
59186+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
59187+ PAGE_SIZE)
59188+ kfree(acl_role_set.r_hash);
59189+ else
59190+ vfree(acl_role_set.r_hash);
59191+ }
59192+ if (name_set.n_hash) {
59193+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
59194+ PAGE_SIZE)
59195+ kfree(name_set.n_hash);
59196+ else
59197+ vfree(name_set.n_hash);
59198+ }
59199+
59200+ if (inodev_set.i_hash) {
59201+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
59202+ PAGE_SIZE)
59203+ kfree(inodev_set.i_hash);
59204+ else
59205+ vfree(inodev_set.i_hash);
59206+ }
59207+
59208+ gr_free_uidset();
59209+
59210+ memset(&name_set, 0, sizeof (struct name_db));
59211+ memset(&inodev_set, 0, sizeof (struct inodev_db));
59212+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
59213+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
59214+
59215+ default_role = NULL;
59216+ kernel_role = NULL;
59217+ role_list = NULL;
59218+
59219+ return;
59220+}
59221+
59222+static __u32
59223+count_user_objs(struct acl_object_label *userp)
59224+{
59225+ struct acl_object_label o_tmp;
59226+ __u32 num = 0;
59227+
59228+ while (userp) {
59229+ if (copy_from_user(&o_tmp, userp,
59230+ sizeof (struct acl_object_label)))
59231+ break;
59232+
59233+ userp = o_tmp.prev;
59234+ num++;
59235+ }
59236+
59237+ return num;
59238+}
59239+
59240+static struct acl_subject_label *
59241+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
59242+
59243+static int
59244+copy_user_glob(struct acl_object_label *obj)
59245+{
59246+ struct acl_object_label *g_tmp, **guser;
59247+ unsigned int len;
59248+ char *tmp;
59249+
59250+ if (obj->globbed == NULL)
59251+ return 0;
59252+
59253+ guser = &obj->globbed;
59254+ while (*guser) {
59255+ g_tmp = (struct acl_object_label *)
59256+ acl_alloc(sizeof (struct acl_object_label));
59257+ if (g_tmp == NULL)
59258+ return -ENOMEM;
59259+
59260+ if (copy_from_user(g_tmp, *guser,
59261+ sizeof (struct acl_object_label)))
59262+ return -EFAULT;
59263+
59264+ len = strnlen_user(g_tmp->filename, PATH_MAX);
59265+
59266+ if (!len || len >= PATH_MAX)
59267+ return -EINVAL;
59268+
59269+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59270+ return -ENOMEM;
59271+
59272+ if (copy_from_user(tmp, g_tmp->filename, len))
59273+ return -EFAULT;
59274+ tmp[len-1] = '\0';
59275+ g_tmp->filename = tmp;
59276+
59277+ *guser = g_tmp;
59278+ guser = &(g_tmp->next);
59279+ }
59280+
59281+ return 0;
59282+}
59283+
59284+static int
59285+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
59286+ struct acl_role_label *role)
59287+{
59288+ struct acl_object_label *o_tmp;
59289+ unsigned int len;
59290+ int ret;
59291+ char *tmp;
59292+
59293+ while (userp) {
59294+ if ((o_tmp = (struct acl_object_label *)
59295+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
59296+ return -ENOMEM;
59297+
59298+ if (copy_from_user(o_tmp, userp,
59299+ sizeof (struct acl_object_label)))
59300+ return -EFAULT;
59301+
59302+ userp = o_tmp->prev;
59303+
59304+ len = strnlen_user(o_tmp->filename, PATH_MAX);
59305+
59306+ if (!len || len >= PATH_MAX)
59307+ return -EINVAL;
59308+
59309+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59310+ return -ENOMEM;
59311+
59312+ if (copy_from_user(tmp, o_tmp->filename, len))
59313+ return -EFAULT;
59314+ tmp[len-1] = '\0';
59315+ o_tmp->filename = tmp;
59316+
59317+ insert_acl_obj_label(o_tmp, subj);
59318+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
59319+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
59320+ return -ENOMEM;
59321+
59322+ ret = copy_user_glob(o_tmp);
59323+ if (ret)
59324+ return ret;
59325+
59326+ if (o_tmp->nested) {
59327+ int already_copied;
59328+
59329+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
59330+ if (IS_ERR(o_tmp->nested))
59331+ return PTR_ERR(o_tmp->nested);
59332+
59333+ /* insert into nested subject list if we haven't copied this one yet
59334+ to prevent duplicate entries */
59335+ if (!already_copied) {
59336+ o_tmp->nested->next = role->hash->first;
59337+ role->hash->first = o_tmp->nested;
59338+ }
59339+ }
59340+ }
59341+
59342+ return 0;
59343+}
59344+
59345+static __u32
59346+count_user_subjs(struct acl_subject_label *userp)
59347+{
59348+ struct acl_subject_label s_tmp;
59349+ __u32 num = 0;
59350+
59351+ while (userp) {
59352+ if (copy_from_user(&s_tmp, userp,
59353+ sizeof (struct acl_subject_label)))
59354+ break;
59355+
59356+ userp = s_tmp.prev;
59357+ }
59358+
59359+ return num;
59360+}
59361+
59362+static int
59363+copy_user_allowedips(struct acl_role_label *rolep)
59364+{
59365+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
59366+
59367+ ruserip = rolep->allowed_ips;
59368+
59369+ while (ruserip) {
59370+ rlast = rtmp;
59371+
59372+ if ((rtmp = (struct role_allowed_ip *)
59373+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
59374+ return -ENOMEM;
59375+
59376+ if (copy_from_user(rtmp, ruserip,
59377+ sizeof (struct role_allowed_ip)))
59378+ return -EFAULT;
59379+
59380+ ruserip = rtmp->prev;
59381+
59382+ if (!rlast) {
59383+ rtmp->prev = NULL;
59384+ rolep->allowed_ips = rtmp;
59385+ } else {
59386+ rlast->next = rtmp;
59387+ rtmp->prev = rlast;
59388+ }
59389+
59390+ if (!ruserip)
59391+ rtmp->next = NULL;
59392+ }
59393+
59394+ return 0;
59395+}
59396+
59397+static int
59398+copy_user_transitions(struct acl_role_label *rolep)
59399+{
59400+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
59401+
59402+ unsigned int len;
59403+ char *tmp;
59404+
59405+ rusertp = rolep->transitions;
59406+
59407+ while (rusertp) {
59408+ rlast = rtmp;
59409+
59410+ if ((rtmp = (struct role_transition *)
59411+ acl_alloc(sizeof (struct role_transition))) == NULL)
59412+ return -ENOMEM;
59413+
59414+ if (copy_from_user(rtmp, rusertp,
59415+ sizeof (struct role_transition)))
59416+ return -EFAULT;
59417+
59418+ rusertp = rtmp->prev;
59419+
59420+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
59421+
59422+ if (!len || len >= GR_SPROLE_LEN)
59423+ return -EINVAL;
59424+
59425+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59426+ return -ENOMEM;
59427+
59428+ if (copy_from_user(tmp, rtmp->rolename, len))
59429+ return -EFAULT;
59430+ tmp[len-1] = '\0';
59431+ rtmp->rolename = tmp;
59432+
59433+ if (!rlast) {
59434+ rtmp->prev = NULL;
59435+ rolep->transitions = rtmp;
59436+ } else {
59437+ rlast->next = rtmp;
59438+ rtmp->prev = rlast;
59439+ }
59440+
59441+ if (!rusertp)
59442+ rtmp->next = NULL;
59443+ }
59444+
59445+ return 0;
59446+}
59447+
59448+static struct acl_subject_label *
59449+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
59450+{
59451+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
59452+ unsigned int len;
59453+ char *tmp;
59454+ __u32 num_objs;
59455+ struct acl_ip_label **i_tmp, *i_utmp2;
59456+ struct gr_hash_struct ghash;
59457+ struct subject_map *subjmap;
59458+ unsigned int i_num;
59459+ int err;
59460+
59461+ if (already_copied != NULL)
59462+ *already_copied = 0;
59463+
59464+ s_tmp = lookup_subject_map(userp);
59465+
59466+ /* we've already copied this subject into the kernel, just return
59467+ the reference to it, and don't copy it over again
59468+ */
59469+ if (s_tmp) {
59470+ if (already_copied != NULL)
59471+ *already_copied = 1;
59472+ return(s_tmp);
59473+ }
59474+
59475+ if ((s_tmp = (struct acl_subject_label *)
59476+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
59477+ return ERR_PTR(-ENOMEM);
59478+
59479+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
59480+ if (subjmap == NULL)
59481+ return ERR_PTR(-ENOMEM);
59482+
59483+ subjmap->user = userp;
59484+ subjmap->kernel = s_tmp;
59485+ insert_subj_map_entry(subjmap);
59486+
59487+ if (copy_from_user(s_tmp, userp,
59488+ sizeof (struct acl_subject_label)))
59489+ return ERR_PTR(-EFAULT);
59490+
59491+ len = strnlen_user(s_tmp->filename, PATH_MAX);
59492+
59493+ if (!len || len >= PATH_MAX)
59494+ return ERR_PTR(-EINVAL);
59495+
59496+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59497+ return ERR_PTR(-ENOMEM);
59498+
59499+ if (copy_from_user(tmp, s_tmp->filename, len))
59500+ return ERR_PTR(-EFAULT);
59501+ tmp[len-1] = '\0';
59502+ s_tmp->filename = tmp;
59503+
59504+ if (!strcmp(s_tmp->filename, "/"))
59505+ role->root_label = s_tmp;
59506+
59507+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
59508+ return ERR_PTR(-EFAULT);
59509+
59510+ /* copy user and group transition tables */
59511+
59512+ if (s_tmp->user_trans_num) {
59513+ uid_t *uidlist;
59514+
59515+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
59516+ if (uidlist == NULL)
59517+ return ERR_PTR(-ENOMEM);
59518+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
59519+ return ERR_PTR(-EFAULT);
59520+
59521+ s_tmp->user_transitions = uidlist;
59522+ }
59523+
59524+ if (s_tmp->group_trans_num) {
59525+ gid_t *gidlist;
59526+
59527+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
59528+ if (gidlist == NULL)
59529+ return ERR_PTR(-ENOMEM);
59530+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
59531+ return ERR_PTR(-EFAULT);
59532+
59533+ s_tmp->group_transitions = gidlist;
59534+ }
59535+
59536+ /* set up object hash table */
59537+ num_objs = count_user_objs(ghash.first);
59538+
59539+ s_tmp->obj_hash_size = num_objs;
59540+ s_tmp->obj_hash =
59541+ (struct acl_object_label **)
59542+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
59543+
59544+ if (!s_tmp->obj_hash)
59545+ return ERR_PTR(-ENOMEM);
59546+
59547+ memset(s_tmp->obj_hash, 0,
59548+ s_tmp->obj_hash_size *
59549+ sizeof (struct acl_object_label *));
59550+
59551+ /* add in objects */
59552+ err = copy_user_objs(ghash.first, s_tmp, role);
59553+
59554+ if (err)
59555+ return ERR_PTR(err);
59556+
59557+ /* set pointer for parent subject */
59558+ if (s_tmp->parent_subject) {
59559+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
59560+
59561+ if (IS_ERR(s_tmp2))
59562+ return s_tmp2;
59563+
59564+ s_tmp->parent_subject = s_tmp2;
59565+ }
59566+
59567+ /* add in ip acls */
59568+
59569+ if (!s_tmp->ip_num) {
59570+ s_tmp->ips = NULL;
59571+ goto insert;
59572+ }
59573+
59574+ i_tmp =
59575+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
59576+ sizeof (struct acl_ip_label *));
59577+
59578+ if (!i_tmp)
59579+ return ERR_PTR(-ENOMEM);
59580+
59581+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
59582+ *(i_tmp + i_num) =
59583+ (struct acl_ip_label *)
59584+ acl_alloc(sizeof (struct acl_ip_label));
59585+ if (!*(i_tmp + i_num))
59586+ return ERR_PTR(-ENOMEM);
59587+
59588+ if (copy_from_user
59589+ (&i_utmp2, s_tmp->ips + i_num,
59590+ sizeof (struct acl_ip_label *)))
59591+ return ERR_PTR(-EFAULT);
59592+
59593+ if (copy_from_user
59594+ (*(i_tmp + i_num), i_utmp2,
59595+ sizeof (struct acl_ip_label)))
59596+ return ERR_PTR(-EFAULT);
59597+
59598+ if ((*(i_tmp + i_num))->iface == NULL)
59599+ continue;
59600+
59601+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
59602+ if (!len || len >= IFNAMSIZ)
59603+ return ERR_PTR(-EINVAL);
59604+ tmp = acl_alloc(len);
59605+ if (tmp == NULL)
59606+ return ERR_PTR(-ENOMEM);
59607+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
59608+ return ERR_PTR(-EFAULT);
59609+ (*(i_tmp + i_num))->iface = tmp;
59610+ }
59611+
59612+ s_tmp->ips = i_tmp;
59613+
59614+insert:
59615+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
59616+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
59617+ return ERR_PTR(-ENOMEM);
59618+
59619+ return s_tmp;
59620+}
59621+
59622+static int
59623+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
59624+{
59625+ struct acl_subject_label s_pre;
59626+ struct acl_subject_label * ret;
59627+ int err;
59628+
59629+ while (userp) {
59630+ if (copy_from_user(&s_pre, userp,
59631+ sizeof (struct acl_subject_label)))
59632+ return -EFAULT;
59633+
59634+ ret = do_copy_user_subj(userp, role, NULL);
59635+
59636+ err = PTR_ERR(ret);
59637+ if (IS_ERR(ret))
59638+ return err;
59639+
59640+ insert_acl_subj_label(ret, role);
59641+
59642+ userp = s_pre.prev;
59643+ }
59644+
59645+ return 0;
59646+}
59647+
59648+static int
59649+copy_user_acl(struct gr_arg *arg)
59650+{
59651+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
59652+ struct acl_subject_label *subj_list;
59653+ struct sprole_pw *sptmp;
59654+ struct gr_hash_struct *ghash;
59655+ uid_t *domainlist;
59656+ unsigned int r_num;
59657+ unsigned int len;
59658+ char *tmp;
59659+ int err = 0;
59660+ __u16 i;
59661+ __u32 num_subjs;
59662+
59663+ /* we need a default and kernel role */
59664+ if (arg->role_db.num_roles < 2)
59665+ return -EINVAL;
59666+
59667+ /* copy special role authentication info from userspace */
59668+
59669+ num_sprole_pws = arg->num_sprole_pws;
59670+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
59671+
59672+ if (!acl_special_roles && num_sprole_pws)
59673+ return -ENOMEM;
59674+
59675+ for (i = 0; i < num_sprole_pws; i++) {
59676+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
59677+ if (!sptmp)
59678+ return -ENOMEM;
59679+ if (copy_from_user(sptmp, arg->sprole_pws + i,
59680+ sizeof (struct sprole_pw)))
59681+ return -EFAULT;
59682+
59683+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
59684+
59685+ if (!len || len >= GR_SPROLE_LEN)
59686+ return -EINVAL;
59687+
59688+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59689+ return -ENOMEM;
59690+
59691+ if (copy_from_user(tmp, sptmp->rolename, len))
59692+ return -EFAULT;
59693+
59694+ tmp[len-1] = '\0';
59695+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59696+ printk(KERN_ALERT "Copying special role %s\n", tmp);
59697+#endif
59698+ sptmp->rolename = tmp;
59699+ acl_special_roles[i] = sptmp;
59700+ }
59701+
59702+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
59703+
59704+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
59705+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
59706+
59707+ if (!r_tmp)
59708+ return -ENOMEM;
59709+
59710+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
59711+ sizeof (struct acl_role_label *)))
59712+ return -EFAULT;
59713+
59714+ if (copy_from_user(r_tmp, r_utmp2,
59715+ sizeof (struct acl_role_label)))
59716+ return -EFAULT;
59717+
59718+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
59719+
59720+ if (!len || len >= PATH_MAX)
59721+ return -EINVAL;
59722+
59723+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59724+ return -ENOMEM;
59725+
59726+ if (copy_from_user(tmp, r_tmp->rolename, len))
59727+ return -EFAULT;
59728+
59729+ tmp[len-1] = '\0';
59730+ r_tmp->rolename = tmp;
59731+
59732+ if (!strcmp(r_tmp->rolename, "default")
59733+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
59734+ default_role = r_tmp;
59735+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
59736+ kernel_role = r_tmp;
59737+ }
59738+
59739+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
59740+ return -ENOMEM;
59741+
59742+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
59743+ return -EFAULT;
59744+
59745+ r_tmp->hash = ghash;
59746+
59747+ num_subjs = count_user_subjs(r_tmp->hash->first);
59748+
59749+ r_tmp->subj_hash_size = num_subjs;
59750+ r_tmp->subj_hash =
59751+ (struct acl_subject_label **)
59752+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
59753+
59754+ if (!r_tmp->subj_hash)
59755+ return -ENOMEM;
59756+
59757+ err = copy_user_allowedips(r_tmp);
59758+ if (err)
59759+ return err;
59760+
59761+ /* copy domain info */
59762+ if (r_tmp->domain_children != NULL) {
59763+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
59764+ if (domainlist == NULL)
59765+ return -ENOMEM;
59766+
59767+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
59768+ return -EFAULT;
59769+
59770+ r_tmp->domain_children = domainlist;
59771+ }
59772+
59773+ err = copy_user_transitions(r_tmp);
59774+ if (err)
59775+ return err;
59776+
59777+ memset(r_tmp->subj_hash, 0,
59778+ r_tmp->subj_hash_size *
59779+ sizeof (struct acl_subject_label *));
59780+
59781+ /* acquire the list of subjects, then NULL out
59782+ the list prior to parsing the subjects for this role,
59783+ as during this parsing the list is replaced with a list
59784+ of *nested* subjects for the role
59785+ */
59786+ subj_list = r_tmp->hash->first;
59787+
59788+ /* set nested subject list to null */
59789+ r_tmp->hash->first = NULL;
59790+
59791+ err = copy_user_subjs(subj_list, r_tmp);
59792+
59793+ if (err)
59794+ return err;
59795+
59796+ insert_acl_role_label(r_tmp);
59797+ }
59798+
59799+ if (default_role == NULL || kernel_role == NULL)
59800+ return -EINVAL;
59801+
59802+ return err;
59803+}
59804+
59805+static int
59806+gracl_init(struct gr_arg *args)
59807+{
59808+ int error = 0;
59809+
59810+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
59811+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
59812+
59813+ if (init_variables(args)) {
59814+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
59815+ error = -ENOMEM;
59816+ free_variables();
59817+ goto out;
59818+ }
59819+
59820+ error = copy_user_acl(args);
59821+ free_init_variables();
59822+ if (error) {
59823+ free_variables();
59824+ goto out;
59825+ }
59826+
59827+ if ((error = gr_set_acls(0))) {
59828+ free_variables();
59829+ goto out;
59830+ }
59831+
59832+ pax_open_kernel();
59833+ gr_status |= GR_READY;
59834+ pax_close_kernel();
59835+
59836+ out:
59837+ return error;
59838+}
59839+
59840+/* derived from glibc fnmatch() 0: match, 1: no match*/
59841+
59842+static int
59843+glob_match(const char *p, const char *n)
59844+{
59845+ char c;
59846+
59847+ while ((c = *p++) != '\0') {
59848+ switch (c) {
59849+ case '?':
59850+ if (*n == '\0')
59851+ return 1;
59852+ else if (*n == '/')
59853+ return 1;
59854+ break;
59855+ case '\\':
59856+ if (*n != c)
59857+ return 1;
59858+ break;
59859+ case '*':
59860+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
59861+ if (*n == '/')
59862+ return 1;
59863+ else if (c == '?') {
59864+ if (*n == '\0')
59865+ return 1;
59866+ else
59867+ ++n;
59868+ }
59869+ }
59870+ if (c == '\0') {
59871+ return 0;
59872+ } else {
59873+ const char *endp;
59874+
59875+ if ((endp = strchr(n, '/')) == NULL)
59876+ endp = n + strlen(n);
59877+
59878+ if (c == '[') {
59879+ for (--p; n < endp; ++n)
59880+ if (!glob_match(p, n))
59881+ return 0;
59882+ } else if (c == '/') {
59883+ while (*n != '\0' && *n != '/')
59884+ ++n;
59885+ if (*n == '/' && !glob_match(p, n + 1))
59886+ return 0;
59887+ } else {
59888+ for (--p; n < endp; ++n)
59889+ if (*n == c && !glob_match(p, n))
59890+ return 0;
59891+ }
59892+
59893+ return 1;
59894+ }
59895+ case '[':
59896+ {
59897+ int not;
59898+ char cold;
59899+
59900+ if (*n == '\0' || *n == '/')
59901+ return 1;
59902+
59903+ not = (*p == '!' || *p == '^');
59904+ if (not)
59905+ ++p;
59906+
59907+ c = *p++;
59908+ for (;;) {
59909+ unsigned char fn = (unsigned char)*n;
59910+
59911+ if (c == '\0')
59912+ return 1;
59913+ else {
59914+ if (c == fn)
59915+ goto matched;
59916+ cold = c;
59917+ c = *p++;
59918+
59919+ if (c == '-' && *p != ']') {
59920+ unsigned char cend = *p++;
59921+
59922+ if (cend == '\0')
59923+ return 1;
59924+
59925+ if (cold <= fn && fn <= cend)
59926+ goto matched;
59927+
59928+ c = *p++;
59929+ }
59930+ }
59931+
59932+ if (c == ']')
59933+ break;
59934+ }
59935+ if (!not)
59936+ return 1;
59937+ break;
59938+ matched:
59939+ while (c != ']') {
59940+ if (c == '\0')
59941+ return 1;
59942+
59943+ c = *p++;
59944+ }
59945+ if (not)
59946+ return 1;
59947+ }
59948+ break;
59949+ default:
59950+ if (c != *n)
59951+ return 1;
59952+ }
59953+
59954+ ++n;
59955+ }
59956+
59957+ if (*n == '\0')
59958+ return 0;
59959+
59960+ if (*n == '/')
59961+ return 0;
59962+
59963+ return 1;
59964+}
59965+
59966+static struct acl_object_label *
59967+chk_glob_label(struct acl_object_label *globbed,
59968+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
59969+{
59970+ struct acl_object_label *tmp;
59971+
59972+ if (*path == NULL)
59973+ *path = gr_to_filename_nolock(dentry, mnt);
59974+
59975+ tmp = globbed;
59976+
59977+ while (tmp) {
59978+ if (!glob_match(tmp->filename, *path))
59979+ return tmp;
59980+ tmp = tmp->next;
59981+ }
59982+
59983+ return NULL;
59984+}
59985+
59986+static struct acl_object_label *
59987+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59988+ const ino_t curr_ino, const dev_t curr_dev,
59989+ const struct acl_subject_label *subj, char **path, const int checkglob)
59990+{
59991+ struct acl_subject_label *tmpsubj;
59992+ struct acl_object_label *retval;
59993+ struct acl_object_label *retval2;
59994+
59995+ tmpsubj = (struct acl_subject_label *) subj;
59996+ read_lock(&gr_inode_lock);
59997+ do {
59998+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
59999+ if (retval) {
60000+ if (checkglob && retval->globbed) {
60001+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
60002+ if (retval2)
60003+ retval = retval2;
60004+ }
60005+ break;
60006+ }
60007+ } while ((tmpsubj = tmpsubj->parent_subject));
60008+ read_unlock(&gr_inode_lock);
60009+
60010+ return retval;
60011+}
60012+
60013+static __inline__ struct acl_object_label *
60014+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60015+ struct dentry *curr_dentry,
60016+ const struct acl_subject_label *subj, char **path, const int checkglob)
60017+{
60018+ int newglob = checkglob;
60019+ ino_t inode;
60020+ dev_t device;
60021+
60022+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
60023+ as we don't want a / * rule to match instead of the / object
60024+ don't do this for create lookups that call this function though, since they're looking up
60025+ on the parent and thus need globbing checks on all paths
60026+ */
60027+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
60028+ newglob = GR_NO_GLOB;
60029+
60030+ spin_lock(&curr_dentry->d_lock);
60031+ inode = curr_dentry->d_inode->i_ino;
60032+ device = __get_dev(curr_dentry);
60033+ spin_unlock(&curr_dentry->d_lock);
60034+
60035+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
60036+}
60037+
60038+#ifdef CONFIG_HUGETLBFS
60039+static inline bool
60040+is_hugetlbfs_mnt(const struct vfsmount *mnt)
60041+{
60042+ int i;
60043+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
60044+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
60045+ return true;
60046+ }
60047+
60048+ return false;
60049+}
60050+#endif
60051+
60052+static struct acl_object_label *
60053+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60054+ const struct acl_subject_label *subj, char *path, const int checkglob)
60055+{
60056+ struct dentry *dentry = (struct dentry *) l_dentry;
60057+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60058+ struct mount *real_mnt = real_mount(mnt);
60059+ struct acl_object_label *retval;
60060+ struct dentry *parent;
60061+
60062+ br_read_lock(&vfsmount_lock);
60063+ write_seqlock(&rename_lock);
60064+
60065+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
60066+#ifdef CONFIG_NET
60067+ mnt == sock_mnt ||
60068+#endif
60069+#ifdef CONFIG_HUGETLBFS
60070+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
60071+#endif
60072+ /* ignore Eric Biederman */
60073+ IS_PRIVATE(l_dentry->d_inode))) {
60074+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
60075+ goto out;
60076+ }
60077+
60078+ for (;;) {
60079+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60080+ break;
60081+
60082+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60083+ if (!mnt_has_parent(real_mnt))
60084+ break;
60085+
60086+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60087+ if (retval != NULL)
60088+ goto out;
60089+
60090+ dentry = real_mnt->mnt_mountpoint;
60091+ real_mnt = real_mnt->mnt_parent;
60092+ mnt = &real_mnt->mnt;
60093+ continue;
60094+ }
60095+
60096+ parent = dentry->d_parent;
60097+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60098+ if (retval != NULL)
60099+ goto out;
60100+
60101+ dentry = parent;
60102+ }
60103+
60104+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60105+
60106+ /* real_root is pinned so we don't have to hold a reference */
60107+ if (retval == NULL)
60108+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
60109+out:
60110+ write_sequnlock(&rename_lock);
60111+ br_read_unlock(&vfsmount_lock);
60112+
60113+ BUG_ON(retval == NULL);
60114+
60115+ return retval;
60116+}
60117+
60118+static __inline__ struct acl_object_label *
60119+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60120+ const struct acl_subject_label *subj)
60121+{
60122+ char *path = NULL;
60123+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
60124+}
60125+
60126+static __inline__ struct acl_object_label *
60127+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60128+ const struct acl_subject_label *subj)
60129+{
60130+ char *path = NULL;
60131+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
60132+}
60133+
60134+static __inline__ struct acl_object_label *
60135+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60136+ const struct acl_subject_label *subj, char *path)
60137+{
60138+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
60139+}
60140+
60141+static struct acl_subject_label *
60142+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60143+ const struct acl_role_label *role)
60144+{
60145+ struct dentry *dentry = (struct dentry *) l_dentry;
60146+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60147+ struct mount *real_mnt = real_mount(mnt);
60148+ struct acl_subject_label *retval;
60149+ struct dentry *parent;
60150+
60151+ br_read_lock(&vfsmount_lock);
60152+ write_seqlock(&rename_lock);
60153+
60154+ for (;;) {
60155+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60156+ break;
60157+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60158+ if (!mnt_has_parent(real_mnt))
60159+ break;
60160+
60161+ spin_lock(&dentry->d_lock);
60162+ read_lock(&gr_inode_lock);
60163+ retval =
60164+ lookup_acl_subj_label(dentry->d_inode->i_ino,
60165+ __get_dev(dentry), role);
60166+ read_unlock(&gr_inode_lock);
60167+ spin_unlock(&dentry->d_lock);
60168+ if (retval != NULL)
60169+ goto out;
60170+
60171+ dentry = real_mnt->mnt_mountpoint;
60172+ real_mnt = real_mnt->mnt_parent;
60173+ mnt = &real_mnt->mnt;
60174+ continue;
60175+ }
60176+
60177+ spin_lock(&dentry->d_lock);
60178+ read_lock(&gr_inode_lock);
60179+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60180+ __get_dev(dentry), role);
60181+ read_unlock(&gr_inode_lock);
60182+ parent = dentry->d_parent;
60183+ spin_unlock(&dentry->d_lock);
60184+
60185+ if (retval != NULL)
60186+ goto out;
60187+
60188+ dentry = parent;
60189+ }
60190+
60191+ spin_lock(&dentry->d_lock);
60192+ read_lock(&gr_inode_lock);
60193+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60194+ __get_dev(dentry), role);
60195+ read_unlock(&gr_inode_lock);
60196+ spin_unlock(&dentry->d_lock);
60197+
60198+ if (unlikely(retval == NULL)) {
60199+ /* real_root is pinned, we don't need to hold a reference */
60200+ read_lock(&gr_inode_lock);
60201+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
60202+ __get_dev(real_root.dentry), role);
60203+ read_unlock(&gr_inode_lock);
60204+ }
60205+out:
60206+ write_sequnlock(&rename_lock);
60207+ br_read_unlock(&vfsmount_lock);
60208+
60209+ BUG_ON(retval == NULL);
60210+
60211+ return retval;
60212+}
60213+
60214+static void
60215+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
60216+{
60217+ struct task_struct *task = current;
60218+ const struct cred *cred = current_cred();
60219+
60220+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
60221+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60222+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60223+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
60224+
60225+ return;
60226+}
60227+
60228+static void
60229+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
60230+{
60231+ struct task_struct *task = current;
60232+ const struct cred *cred = current_cred();
60233+
60234+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60235+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60236+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60237+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
60238+
60239+ return;
60240+}
60241+
60242+static void
60243+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
60244+{
60245+ struct task_struct *task = current;
60246+ const struct cred *cred = current_cred();
60247+
60248+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60249+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60250+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60251+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
60252+
60253+ return;
60254+}
60255+
60256+__u32
60257+gr_search_file(const struct dentry * dentry, const __u32 mode,
60258+ const struct vfsmount * mnt)
60259+{
60260+ __u32 retval = mode;
60261+ struct acl_subject_label *curracl;
60262+ struct acl_object_label *currobj;
60263+
60264+ if (unlikely(!(gr_status & GR_READY)))
60265+ return (mode & ~GR_AUDITS);
60266+
60267+ curracl = current->acl;
60268+
60269+ currobj = chk_obj_label(dentry, mnt, curracl);
60270+ retval = currobj->mode & mode;
60271+
60272+ /* if we're opening a specified transfer file for writing
60273+ (e.g. /dev/initctl), then transfer our role to init
60274+ */
60275+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
60276+ current->role->roletype & GR_ROLE_PERSIST)) {
60277+ struct task_struct *task = init_pid_ns.child_reaper;
60278+
60279+ if (task->role != current->role) {
60280+ task->acl_sp_role = 0;
60281+ task->acl_role_id = current->acl_role_id;
60282+ task->role = current->role;
60283+ rcu_read_lock();
60284+ read_lock(&grsec_exec_file_lock);
60285+ gr_apply_subject_to_task(task);
60286+ read_unlock(&grsec_exec_file_lock);
60287+ rcu_read_unlock();
60288+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
60289+ }
60290+ }
60291+
60292+ if (unlikely
60293+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
60294+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
60295+ __u32 new_mode = mode;
60296+
60297+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60298+
60299+ retval = new_mode;
60300+
60301+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
60302+ new_mode |= GR_INHERIT;
60303+
60304+ if (!(mode & GR_NOLEARN))
60305+ gr_log_learn(dentry, mnt, new_mode);
60306+ }
60307+
60308+ return retval;
60309+}
60310+
60311+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
60312+ const struct dentry *parent,
60313+ const struct vfsmount *mnt)
60314+{
60315+ struct name_entry *match;
60316+ struct acl_object_label *matchpo;
60317+ struct acl_subject_label *curracl;
60318+ char *path;
60319+
60320+ if (unlikely(!(gr_status & GR_READY)))
60321+ return NULL;
60322+
60323+ preempt_disable();
60324+ path = gr_to_filename_rbac(new_dentry, mnt);
60325+ match = lookup_name_entry_create(path);
60326+
60327+ curracl = current->acl;
60328+
60329+ if (match) {
60330+ read_lock(&gr_inode_lock);
60331+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
60332+ read_unlock(&gr_inode_lock);
60333+
60334+ if (matchpo) {
60335+ preempt_enable();
60336+ return matchpo;
60337+ }
60338+ }
60339+
60340+ // lookup parent
60341+
60342+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
60343+
60344+ preempt_enable();
60345+ return matchpo;
60346+}
60347+
60348+__u32
60349+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
60350+ const struct vfsmount * mnt, const __u32 mode)
60351+{
60352+ struct acl_object_label *matchpo;
60353+ __u32 retval;
60354+
60355+ if (unlikely(!(gr_status & GR_READY)))
60356+ return (mode & ~GR_AUDITS);
60357+
60358+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
60359+
60360+ retval = matchpo->mode & mode;
60361+
60362+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
60363+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60364+ __u32 new_mode = mode;
60365+
60366+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60367+
60368+ gr_log_learn(new_dentry, mnt, new_mode);
60369+ return new_mode;
60370+ }
60371+
60372+ return retval;
60373+}
60374+
60375+__u32
60376+gr_check_link(const struct dentry * new_dentry,
60377+ const struct dentry * parent_dentry,
60378+ const struct vfsmount * parent_mnt,
60379+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
60380+{
60381+ struct acl_object_label *obj;
60382+ __u32 oldmode, newmode;
60383+ __u32 needmode;
60384+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
60385+ GR_DELETE | GR_INHERIT;
60386+
60387+ if (unlikely(!(gr_status & GR_READY)))
60388+ return (GR_CREATE | GR_LINK);
60389+
60390+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
60391+ oldmode = obj->mode;
60392+
60393+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
60394+ newmode = obj->mode;
60395+
60396+ needmode = newmode & checkmodes;
60397+
60398+ // old name for hardlink must have at least the permissions of the new name
60399+ if ((oldmode & needmode) != needmode)
60400+ goto bad;
60401+
60402+ // if old name had restrictions/auditing, make sure the new name does as well
60403+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
60404+
60405+ // don't allow hardlinking of suid/sgid/fcapped files without permission
60406+ if (is_privileged_binary(old_dentry))
60407+ needmode |= GR_SETID;
60408+
60409+ if ((newmode & needmode) != needmode)
60410+ goto bad;
60411+
60412+ // enforce minimum permissions
60413+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
60414+ return newmode;
60415+bad:
60416+ needmode = oldmode;
60417+ if (is_privileged_binary(old_dentry))
60418+ needmode |= GR_SETID;
60419+
60420+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
60421+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
60422+ return (GR_CREATE | GR_LINK);
60423+ } else if (newmode & GR_SUPPRESS)
60424+ return GR_SUPPRESS;
60425+ else
60426+ return 0;
60427+}
60428+
60429+int
60430+gr_check_hidden_task(const struct task_struct *task)
60431+{
60432+ if (unlikely(!(gr_status & GR_READY)))
60433+ return 0;
60434+
60435+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
60436+ return 1;
60437+
60438+ return 0;
60439+}
60440+
60441+int
60442+gr_check_protected_task(const struct task_struct *task)
60443+{
60444+ if (unlikely(!(gr_status & GR_READY) || !task))
60445+ return 0;
60446+
60447+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60448+ task->acl != current->acl)
60449+ return 1;
60450+
60451+ return 0;
60452+}
60453+
60454+int
60455+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60456+{
60457+ struct task_struct *p;
60458+ int ret = 0;
60459+
60460+ if (unlikely(!(gr_status & GR_READY) || !pid))
60461+ return ret;
60462+
60463+ read_lock(&tasklist_lock);
60464+ do_each_pid_task(pid, type, p) {
60465+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60466+ p->acl != current->acl) {
60467+ ret = 1;
60468+ goto out;
60469+ }
60470+ } while_each_pid_task(pid, type, p);
60471+out:
60472+ read_unlock(&tasklist_lock);
60473+
60474+ return ret;
60475+}
60476+
60477+void
60478+gr_copy_label(struct task_struct *tsk)
60479+{
60480+ tsk->signal->used_accept = 0;
60481+ tsk->acl_sp_role = 0;
60482+ tsk->acl_role_id = current->acl_role_id;
60483+ tsk->acl = current->acl;
60484+ tsk->role = current->role;
60485+ tsk->signal->curr_ip = current->signal->curr_ip;
60486+ tsk->signal->saved_ip = current->signal->saved_ip;
60487+ if (current->exec_file)
60488+ get_file(current->exec_file);
60489+ tsk->exec_file = current->exec_file;
60490+ tsk->is_writable = current->is_writable;
60491+ if (unlikely(current->signal->used_accept)) {
60492+ current->signal->curr_ip = 0;
60493+ current->signal->saved_ip = 0;
60494+ }
60495+
60496+ return;
60497+}
60498+
60499+static void
60500+gr_set_proc_res(struct task_struct *task)
60501+{
60502+ struct acl_subject_label *proc;
60503+ unsigned short i;
60504+
60505+ proc = task->acl;
60506+
60507+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
60508+ return;
60509+
60510+ for (i = 0; i < RLIM_NLIMITS; i++) {
60511+ if (!(proc->resmask & (1U << i)))
60512+ continue;
60513+
60514+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
60515+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
60516+
60517+ if (i == RLIMIT_CPU)
60518+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
60519+ }
60520+
60521+ return;
60522+}
60523+
60524+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
60525+
60526+int
60527+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
60528+{
60529+ unsigned int i;
60530+ __u16 num;
60531+ uid_t *uidlist;
60532+ uid_t curuid;
60533+ int realok = 0;
60534+ int effectiveok = 0;
60535+ int fsok = 0;
60536+ uid_t globalreal, globaleffective, globalfs;
60537+
60538+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
60539+ struct user_struct *user;
60540+
60541+ if (!uid_valid(real))
60542+ goto skipit;
60543+
60544+ /* find user based on global namespace */
60545+
60546+ globalreal = GR_GLOBAL_UID(real);
60547+
60548+ user = find_user(make_kuid(&init_user_ns, globalreal));
60549+ if (user == NULL)
60550+ goto skipit;
60551+
60552+ if (gr_process_kernel_setuid_ban(user)) {
60553+ /* for find_user */
60554+ free_uid(user);
60555+ return 1;
60556+ }
60557+
60558+ /* for find_user */
60559+ free_uid(user);
60560+
60561+skipit:
60562+#endif
60563+
60564+ if (unlikely(!(gr_status & GR_READY)))
60565+ return 0;
60566+
60567+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60568+ gr_log_learn_uid_change(real, effective, fs);
60569+
60570+ num = current->acl->user_trans_num;
60571+ uidlist = current->acl->user_transitions;
60572+
60573+ if (uidlist == NULL)
60574+ return 0;
60575+
60576+ if (!uid_valid(real)) {
60577+ realok = 1;
60578+ globalreal = (uid_t)-1;
60579+ } else {
60580+ globalreal = GR_GLOBAL_UID(real);
60581+ }
60582+ if (!uid_valid(effective)) {
60583+ effectiveok = 1;
60584+ globaleffective = (uid_t)-1;
60585+ } else {
60586+ globaleffective = GR_GLOBAL_UID(effective);
60587+ }
60588+ if (!uid_valid(fs)) {
60589+ fsok = 1;
60590+ globalfs = (uid_t)-1;
60591+ } else {
60592+ globalfs = GR_GLOBAL_UID(fs);
60593+ }
60594+
60595+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
60596+ for (i = 0; i < num; i++) {
60597+ curuid = uidlist[i];
60598+ if (globalreal == curuid)
60599+ realok = 1;
60600+ if (globaleffective == curuid)
60601+ effectiveok = 1;
60602+ if (globalfs == curuid)
60603+ fsok = 1;
60604+ }
60605+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
60606+ for (i = 0; i < num; i++) {
60607+ curuid = uidlist[i];
60608+ if (globalreal == curuid)
60609+ break;
60610+ if (globaleffective == curuid)
60611+ break;
60612+ if (globalfs == curuid)
60613+ break;
60614+ }
60615+ /* not in deny list */
60616+ if (i == num) {
60617+ realok = 1;
60618+ effectiveok = 1;
60619+ fsok = 1;
60620+ }
60621+ }
60622+
60623+ if (realok && effectiveok && fsok)
60624+ return 0;
60625+ else {
60626+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60627+ return 1;
60628+ }
60629+}
60630+
60631+int
60632+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
60633+{
60634+ unsigned int i;
60635+ __u16 num;
60636+ gid_t *gidlist;
60637+ gid_t curgid;
60638+ int realok = 0;
60639+ int effectiveok = 0;
60640+ int fsok = 0;
60641+ gid_t globalreal, globaleffective, globalfs;
60642+
60643+ if (unlikely(!(gr_status & GR_READY)))
60644+ return 0;
60645+
60646+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60647+ gr_log_learn_gid_change(real, effective, fs);
60648+
60649+ num = current->acl->group_trans_num;
60650+ gidlist = current->acl->group_transitions;
60651+
60652+ if (gidlist == NULL)
60653+ return 0;
60654+
60655+ if (!gid_valid(real)) {
60656+ realok = 1;
60657+ globalreal = (gid_t)-1;
60658+ } else {
60659+ globalreal = GR_GLOBAL_GID(real);
60660+ }
60661+ if (!gid_valid(effective)) {
60662+ effectiveok = 1;
60663+ globaleffective = (gid_t)-1;
60664+ } else {
60665+ globaleffective = GR_GLOBAL_GID(effective);
60666+ }
60667+ if (!gid_valid(fs)) {
60668+ fsok = 1;
60669+ globalfs = (gid_t)-1;
60670+ } else {
60671+ globalfs = GR_GLOBAL_GID(fs);
60672+ }
60673+
60674+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
60675+ for (i = 0; i < num; i++) {
60676+ curgid = gidlist[i];
60677+ if (globalreal == curgid)
60678+ realok = 1;
60679+ if (globaleffective == curgid)
60680+ effectiveok = 1;
60681+ if (globalfs == curgid)
60682+ fsok = 1;
60683+ }
60684+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
60685+ for (i = 0; i < num; i++) {
60686+ curgid = gidlist[i];
60687+ if (globalreal == curgid)
60688+ break;
60689+ if (globaleffective == curgid)
60690+ break;
60691+ if (globalfs == curgid)
60692+ break;
60693+ }
60694+ /* not in deny list */
60695+ if (i == num) {
60696+ realok = 1;
60697+ effectiveok = 1;
60698+ fsok = 1;
60699+ }
60700+ }
60701+
60702+ if (realok && effectiveok && fsok)
60703+ return 0;
60704+ else {
60705+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60706+ return 1;
60707+ }
60708+}
60709+
60710+extern int gr_acl_is_capable(const int cap);
60711+
60712+void
60713+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
60714+{
60715+ struct acl_role_label *role = task->role;
60716+ struct acl_subject_label *subj = NULL;
60717+ struct acl_object_label *obj;
60718+ struct file *filp;
60719+ uid_t uid;
60720+ gid_t gid;
60721+
60722+ if (unlikely(!(gr_status & GR_READY)))
60723+ return;
60724+
60725+ uid = GR_GLOBAL_UID(kuid);
60726+ gid = GR_GLOBAL_GID(kgid);
60727+
60728+ filp = task->exec_file;
60729+
60730+ /* kernel process, we'll give them the kernel role */
60731+ if (unlikely(!filp)) {
60732+ task->role = kernel_role;
60733+ task->acl = kernel_role->root_label;
60734+ return;
60735+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
60736+ role = lookup_acl_role_label(task, uid, gid);
60737+
60738+ /* don't change the role if we're not a privileged process */
60739+ if (role && task->role != role &&
60740+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
60741+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
60742+ return;
60743+
60744+ /* perform subject lookup in possibly new role
60745+ we can use this result below in the case where role == task->role
60746+ */
60747+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
60748+
60749+ /* if we changed uid/gid, but result in the same role
60750+ and are using inheritance, don't lose the inherited subject
60751+ if current subject is other than what normal lookup
60752+ would result in, we arrived via inheritance, don't
60753+ lose subject
60754+ */
60755+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
60756+ (subj == task->acl)))
60757+ task->acl = subj;
60758+
60759+ task->role = role;
60760+
60761+ task->is_writable = 0;
60762+
60763+ /* ignore additional mmap checks for processes that are writable
60764+ by the default ACL */
60765+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60766+ if (unlikely(obj->mode & GR_WRITE))
60767+ task->is_writable = 1;
60768+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60769+ if (unlikely(obj->mode & GR_WRITE))
60770+ task->is_writable = 1;
60771+
60772+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60773+ 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);
60774+#endif
60775+
60776+ gr_set_proc_res(task);
60777+
60778+ return;
60779+}
60780+
60781+int
60782+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60783+ const int unsafe_flags)
60784+{
60785+ struct task_struct *task = current;
60786+ struct acl_subject_label *newacl;
60787+ struct acl_object_label *obj;
60788+ __u32 retmode;
60789+
60790+ if (unlikely(!(gr_status & GR_READY)))
60791+ return 0;
60792+
60793+ newacl = chk_subj_label(dentry, mnt, task->role);
60794+
60795+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
60796+ did an exec
60797+ */
60798+ rcu_read_lock();
60799+ read_lock(&tasklist_lock);
60800+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
60801+ (task->parent->acl->mode & GR_POVERRIDE))) {
60802+ read_unlock(&tasklist_lock);
60803+ rcu_read_unlock();
60804+ goto skip_check;
60805+ }
60806+ read_unlock(&tasklist_lock);
60807+ rcu_read_unlock();
60808+
60809+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
60810+ !(task->role->roletype & GR_ROLE_GOD) &&
60811+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
60812+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60813+ if (unsafe_flags & LSM_UNSAFE_SHARE)
60814+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
60815+ else
60816+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
60817+ return -EACCES;
60818+ }
60819+
60820+skip_check:
60821+
60822+ obj = chk_obj_label(dentry, mnt, task->acl);
60823+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
60824+
60825+ if (!(task->acl->mode & GR_INHERITLEARN) &&
60826+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
60827+ if (obj->nested)
60828+ task->acl = obj->nested;
60829+ else
60830+ task->acl = newacl;
60831+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
60832+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
60833+
60834+ task->is_writable = 0;
60835+
60836+ /* ignore additional mmap checks for processes that are writable
60837+ by the default ACL */
60838+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
60839+ if (unlikely(obj->mode & GR_WRITE))
60840+ task->is_writable = 1;
60841+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
60842+ if (unlikely(obj->mode & GR_WRITE))
60843+ task->is_writable = 1;
60844+
60845+ gr_set_proc_res(task);
60846+
60847+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60848+ 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);
60849+#endif
60850+ return 0;
60851+}
60852+
60853+/* always called with valid inodev ptr */
60854+static void
60855+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
60856+{
60857+ struct acl_object_label *matchpo;
60858+ struct acl_subject_label *matchps;
60859+ struct acl_subject_label *subj;
60860+ struct acl_role_label *role;
60861+ unsigned int x;
60862+
60863+ FOR_EACH_ROLE_START(role)
60864+ FOR_EACH_SUBJECT_START(role, subj, x)
60865+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60866+ matchpo->mode |= GR_DELETED;
60867+ FOR_EACH_SUBJECT_END(subj,x)
60868+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60869+ /* nested subjects aren't in the role's subj_hash table */
60870+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60871+ matchpo->mode |= GR_DELETED;
60872+ FOR_EACH_NESTED_SUBJECT_END(subj)
60873+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
60874+ matchps->mode |= GR_DELETED;
60875+ FOR_EACH_ROLE_END(role)
60876+
60877+ inodev->nentry->deleted = 1;
60878+
60879+ return;
60880+}
60881+
60882+void
60883+gr_handle_delete(const ino_t ino, const dev_t dev)
60884+{
60885+ struct inodev_entry *inodev;
60886+
60887+ if (unlikely(!(gr_status & GR_READY)))
60888+ return;
60889+
60890+ write_lock(&gr_inode_lock);
60891+ inodev = lookup_inodev_entry(ino, dev);
60892+ if (inodev != NULL)
60893+ do_handle_delete(inodev, ino, dev);
60894+ write_unlock(&gr_inode_lock);
60895+
60896+ return;
60897+}
60898+
60899+static void
60900+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
60901+ const ino_t newinode, const dev_t newdevice,
60902+ struct acl_subject_label *subj)
60903+{
60904+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
60905+ struct acl_object_label *match;
60906+
60907+ match = subj->obj_hash[index];
60908+
60909+ while (match && (match->inode != oldinode ||
60910+ match->device != olddevice ||
60911+ !(match->mode & GR_DELETED)))
60912+ match = match->next;
60913+
60914+ if (match && (match->inode == oldinode)
60915+ && (match->device == olddevice)
60916+ && (match->mode & GR_DELETED)) {
60917+ if (match->prev == NULL) {
60918+ subj->obj_hash[index] = match->next;
60919+ if (match->next != NULL)
60920+ match->next->prev = NULL;
60921+ } else {
60922+ match->prev->next = match->next;
60923+ if (match->next != NULL)
60924+ match->next->prev = match->prev;
60925+ }
60926+ match->prev = NULL;
60927+ match->next = NULL;
60928+ match->inode = newinode;
60929+ match->device = newdevice;
60930+ match->mode &= ~GR_DELETED;
60931+
60932+ insert_acl_obj_label(match, subj);
60933+ }
60934+
60935+ return;
60936+}
60937+
60938+static void
60939+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
60940+ const ino_t newinode, const dev_t newdevice,
60941+ struct acl_role_label *role)
60942+{
60943+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
60944+ struct acl_subject_label *match;
60945+
60946+ match = role->subj_hash[index];
60947+
60948+ while (match && (match->inode != oldinode ||
60949+ match->device != olddevice ||
60950+ !(match->mode & GR_DELETED)))
60951+ match = match->next;
60952+
60953+ if (match && (match->inode == oldinode)
60954+ && (match->device == olddevice)
60955+ && (match->mode & GR_DELETED)) {
60956+ if (match->prev == NULL) {
60957+ role->subj_hash[index] = match->next;
60958+ if (match->next != NULL)
60959+ match->next->prev = NULL;
60960+ } else {
60961+ match->prev->next = match->next;
60962+ if (match->next != NULL)
60963+ match->next->prev = match->prev;
60964+ }
60965+ match->prev = NULL;
60966+ match->next = NULL;
60967+ match->inode = newinode;
60968+ match->device = newdevice;
60969+ match->mode &= ~GR_DELETED;
60970+
60971+ insert_acl_subj_label(match, role);
60972+ }
60973+
60974+ return;
60975+}
60976+
60977+static void
60978+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
60979+ const ino_t newinode, const dev_t newdevice)
60980+{
60981+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
60982+ struct inodev_entry *match;
60983+
60984+ match = inodev_set.i_hash[index];
60985+
60986+ while (match && (match->nentry->inode != oldinode ||
60987+ match->nentry->device != olddevice || !match->nentry->deleted))
60988+ match = match->next;
60989+
60990+ if (match && (match->nentry->inode == oldinode)
60991+ && (match->nentry->device == olddevice) &&
60992+ match->nentry->deleted) {
60993+ if (match->prev == NULL) {
60994+ inodev_set.i_hash[index] = match->next;
60995+ if (match->next != NULL)
60996+ match->next->prev = NULL;
60997+ } else {
60998+ match->prev->next = match->next;
60999+ if (match->next != NULL)
61000+ match->next->prev = match->prev;
61001+ }
61002+ match->prev = NULL;
61003+ match->next = NULL;
61004+ match->nentry->inode = newinode;
61005+ match->nentry->device = newdevice;
61006+ match->nentry->deleted = 0;
61007+
61008+ insert_inodev_entry(match);
61009+ }
61010+
61011+ return;
61012+}
61013+
61014+static void
61015+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
61016+{
61017+ struct acl_subject_label *subj;
61018+ struct acl_role_label *role;
61019+ unsigned int x;
61020+
61021+ FOR_EACH_ROLE_START(role)
61022+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
61023+
61024+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61025+ if ((subj->inode == ino) && (subj->device == dev)) {
61026+ subj->inode = ino;
61027+ subj->device = dev;
61028+ }
61029+ /* nested subjects aren't in the role's subj_hash table */
61030+ update_acl_obj_label(matchn->inode, matchn->device,
61031+ ino, dev, subj);
61032+ FOR_EACH_NESTED_SUBJECT_END(subj)
61033+ FOR_EACH_SUBJECT_START(role, subj, x)
61034+ update_acl_obj_label(matchn->inode, matchn->device,
61035+ ino, dev, subj);
61036+ FOR_EACH_SUBJECT_END(subj,x)
61037+ FOR_EACH_ROLE_END(role)
61038+
61039+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
61040+
61041+ return;
61042+}
61043+
61044+static void
61045+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
61046+ const struct vfsmount *mnt)
61047+{
61048+ ino_t ino = dentry->d_inode->i_ino;
61049+ dev_t dev = __get_dev(dentry);
61050+
61051+ __do_handle_create(matchn, ino, dev);
61052+
61053+ return;
61054+}
61055+
61056+void
61057+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61058+{
61059+ struct name_entry *matchn;
61060+
61061+ if (unlikely(!(gr_status & GR_READY)))
61062+ return;
61063+
61064+ preempt_disable();
61065+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
61066+
61067+ if (unlikely((unsigned long)matchn)) {
61068+ write_lock(&gr_inode_lock);
61069+ do_handle_create(matchn, dentry, mnt);
61070+ write_unlock(&gr_inode_lock);
61071+ }
61072+ preempt_enable();
61073+
61074+ return;
61075+}
61076+
61077+void
61078+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61079+{
61080+ struct name_entry *matchn;
61081+
61082+ if (unlikely(!(gr_status & GR_READY)))
61083+ return;
61084+
61085+ preempt_disable();
61086+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
61087+
61088+ if (unlikely((unsigned long)matchn)) {
61089+ write_lock(&gr_inode_lock);
61090+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
61091+ write_unlock(&gr_inode_lock);
61092+ }
61093+ preempt_enable();
61094+
61095+ return;
61096+}
61097+
61098+void
61099+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61100+ struct dentry *old_dentry,
61101+ struct dentry *new_dentry,
61102+ struct vfsmount *mnt, const __u8 replace)
61103+{
61104+ struct name_entry *matchn;
61105+ struct inodev_entry *inodev;
61106+ struct inode *inode = new_dentry->d_inode;
61107+ ino_t old_ino = old_dentry->d_inode->i_ino;
61108+ dev_t old_dev = __get_dev(old_dentry);
61109+
61110+ /* vfs_rename swaps the name and parent link for old_dentry and
61111+ new_dentry
61112+ at this point, old_dentry has the new name, parent link, and inode
61113+ for the renamed file
61114+ if a file is being replaced by a rename, new_dentry has the inode
61115+ and name for the replaced file
61116+ */
61117+
61118+ if (unlikely(!(gr_status & GR_READY)))
61119+ return;
61120+
61121+ preempt_disable();
61122+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
61123+
61124+ /* we wouldn't have to check d_inode if it weren't for
61125+ NFS silly-renaming
61126+ */
61127+
61128+ write_lock(&gr_inode_lock);
61129+ if (unlikely(replace && inode)) {
61130+ ino_t new_ino = inode->i_ino;
61131+ dev_t new_dev = __get_dev(new_dentry);
61132+
61133+ inodev = lookup_inodev_entry(new_ino, new_dev);
61134+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
61135+ do_handle_delete(inodev, new_ino, new_dev);
61136+ }
61137+
61138+ inodev = lookup_inodev_entry(old_ino, old_dev);
61139+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
61140+ do_handle_delete(inodev, old_ino, old_dev);
61141+
61142+ if (unlikely((unsigned long)matchn))
61143+ do_handle_create(matchn, old_dentry, mnt);
61144+
61145+ write_unlock(&gr_inode_lock);
61146+ preempt_enable();
61147+
61148+ return;
61149+}
61150+
61151+static int
61152+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
61153+ unsigned char **sum)
61154+{
61155+ struct acl_role_label *r;
61156+ struct role_allowed_ip *ipp;
61157+ struct role_transition *trans;
61158+ unsigned int i;
61159+ int found = 0;
61160+ u32 curr_ip = current->signal->curr_ip;
61161+
61162+ current->signal->saved_ip = curr_ip;
61163+
61164+ /* check transition table */
61165+
61166+ for (trans = current->role->transitions; trans; trans = trans->next) {
61167+ if (!strcmp(rolename, trans->rolename)) {
61168+ found = 1;
61169+ break;
61170+ }
61171+ }
61172+
61173+ if (!found)
61174+ return 0;
61175+
61176+ /* handle special roles that do not require authentication
61177+ and check ip */
61178+
61179+ FOR_EACH_ROLE_START(r)
61180+ if (!strcmp(rolename, r->rolename) &&
61181+ (r->roletype & GR_ROLE_SPECIAL)) {
61182+ found = 0;
61183+ if (r->allowed_ips != NULL) {
61184+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
61185+ if ((ntohl(curr_ip) & ipp->netmask) ==
61186+ (ntohl(ipp->addr) & ipp->netmask))
61187+ found = 1;
61188+ }
61189+ } else
61190+ found = 2;
61191+ if (!found)
61192+ return 0;
61193+
61194+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
61195+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
61196+ *salt = NULL;
61197+ *sum = NULL;
61198+ return 1;
61199+ }
61200+ }
61201+ FOR_EACH_ROLE_END(r)
61202+
61203+ for (i = 0; i < num_sprole_pws; i++) {
61204+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
61205+ *salt = acl_special_roles[i]->salt;
61206+ *sum = acl_special_roles[i]->sum;
61207+ return 1;
61208+ }
61209+ }
61210+
61211+ return 0;
61212+}
61213+
61214+static void
61215+assign_special_role(char *rolename)
61216+{
61217+ struct acl_object_label *obj;
61218+ struct acl_role_label *r;
61219+ struct acl_role_label *assigned = NULL;
61220+ struct task_struct *tsk;
61221+ struct file *filp;
61222+
61223+ FOR_EACH_ROLE_START(r)
61224+ if (!strcmp(rolename, r->rolename) &&
61225+ (r->roletype & GR_ROLE_SPECIAL)) {
61226+ assigned = r;
61227+ break;
61228+ }
61229+ FOR_EACH_ROLE_END(r)
61230+
61231+ if (!assigned)
61232+ return;
61233+
61234+ read_lock(&tasklist_lock);
61235+ read_lock(&grsec_exec_file_lock);
61236+
61237+ tsk = current->real_parent;
61238+ if (tsk == NULL)
61239+ goto out_unlock;
61240+
61241+ filp = tsk->exec_file;
61242+ if (filp == NULL)
61243+ goto out_unlock;
61244+
61245+ tsk->is_writable = 0;
61246+
61247+ tsk->acl_sp_role = 1;
61248+ tsk->acl_role_id = ++acl_sp_role_value;
61249+ tsk->role = assigned;
61250+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
61251+
61252+ /* ignore additional mmap checks for processes that are writable
61253+ by the default ACL */
61254+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61255+ if (unlikely(obj->mode & GR_WRITE))
61256+ tsk->is_writable = 1;
61257+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
61258+ if (unlikely(obj->mode & GR_WRITE))
61259+ tsk->is_writable = 1;
61260+
61261+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61262+ 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));
61263+#endif
61264+
61265+out_unlock:
61266+ read_unlock(&grsec_exec_file_lock);
61267+ read_unlock(&tasklist_lock);
61268+ return;
61269+}
61270+
61271+int gr_check_secure_terminal(struct task_struct *task)
61272+{
61273+ struct task_struct *p, *p2, *p3;
61274+ struct files_struct *files;
61275+ struct fdtable *fdt;
61276+ struct file *our_file = NULL, *file;
61277+ int i;
61278+
61279+ if (task->signal->tty == NULL)
61280+ return 1;
61281+
61282+ files = get_files_struct(task);
61283+ if (files != NULL) {
61284+ rcu_read_lock();
61285+ fdt = files_fdtable(files);
61286+ for (i=0; i < fdt->max_fds; i++) {
61287+ file = fcheck_files(files, i);
61288+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
61289+ get_file(file);
61290+ our_file = file;
61291+ }
61292+ }
61293+ rcu_read_unlock();
61294+ put_files_struct(files);
61295+ }
61296+
61297+ if (our_file == NULL)
61298+ return 1;
61299+
61300+ read_lock(&tasklist_lock);
61301+ do_each_thread(p2, p) {
61302+ files = get_files_struct(p);
61303+ if (files == NULL ||
61304+ (p->signal && p->signal->tty == task->signal->tty)) {
61305+ if (files != NULL)
61306+ put_files_struct(files);
61307+ continue;
61308+ }
61309+ rcu_read_lock();
61310+ fdt = files_fdtable(files);
61311+ for (i=0; i < fdt->max_fds; i++) {
61312+ file = fcheck_files(files, i);
61313+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
61314+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
61315+ p3 = task;
61316+ while (task_pid_nr(p3) > 0) {
61317+ if (p3 == p)
61318+ break;
61319+ p3 = p3->real_parent;
61320+ }
61321+ if (p3 == p)
61322+ break;
61323+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
61324+ gr_handle_alertkill(p);
61325+ rcu_read_unlock();
61326+ put_files_struct(files);
61327+ read_unlock(&tasklist_lock);
61328+ fput(our_file);
61329+ return 0;
61330+ }
61331+ }
61332+ rcu_read_unlock();
61333+ put_files_struct(files);
61334+ } while_each_thread(p2, p);
61335+ read_unlock(&tasklist_lock);
61336+
61337+ fput(our_file);
61338+ return 1;
61339+}
61340+
61341+static int gr_rbac_disable(void *unused)
61342+{
61343+ pax_open_kernel();
61344+ gr_status &= ~GR_READY;
61345+ pax_close_kernel();
61346+
61347+ return 0;
61348+}
61349+
61350+ssize_t
61351+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
61352+{
61353+ struct gr_arg_wrapper uwrap;
61354+ unsigned char *sprole_salt = NULL;
61355+ unsigned char *sprole_sum = NULL;
61356+ int error = sizeof (struct gr_arg_wrapper);
61357+ int error2 = 0;
61358+
61359+ mutex_lock(&gr_dev_mutex);
61360+
61361+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
61362+ error = -EPERM;
61363+ goto out;
61364+ }
61365+
61366+ if (count != sizeof (struct gr_arg_wrapper)) {
61367+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
61368+ error = -EINVAL;
61369+ goto out;
61370+ }
61371+
61372+
61373+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
61374+ gr_auth_expires = 0;
61375+ gr_auth_attempts = 0;
61376+ }
61377+
61378+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
61379+ error = -EFAULT;
61380+ goto out;
61381+ }
61382+
61383+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
61384+ error = -EINVAL;
61385+ goto out;
61386+ }
61387+
61388+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
61389+ error = -EFAULT;
61390+ goto out;
61391+ }
61392+
61393+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61394+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61395+ time_after(gr_auth_expires, get_seconds())) {
61396+ error = -EBUSY;
61397+ goto out;
61398+ }
61399+
61400+ /* if non-root trying to do anything other than use a special role,
61401+ do not attempt authentication, do not count towards authentication
61402+ locking
61403+ */
61404+
61405+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
61406+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61407+ gr_is_global_nonroot(current_uid())) {
61408+ error = -EPERM;
61409+ goto out;
61410+ }
61411+
61412+ /* ensure pw and special role name are null terminated */
61413+
61414+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
61415+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
61416+
61417+ /* Okay.
61418+ * We have our enough of the argument structure..(we have yet
61419+ * to copy_from_user the tables themselves) . Copy the tables
61420+ * only if we need them, i.e. for loading operations. */
61421+
61422+ switch (gr_usermode->mode) {
61423+ case GR_STATUS:
61424+ if (gr_status & GR_READY) {
61425+ error = 1;
61426+ if (!gr_check_secure_terminal(current))
61427+ error = 3;
61428+ } else
61429+ error = 2;
61430+ goto out;
61431+ case GR_SHUTDOWN:
61432+ if ((gr_status & GR_READY)
61433+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61434+ stop_machine(gr_rbac_disable, NULL, NULL);
61435+ free_variables();
61436+ memset(gr_usermode, 0, sizeof (struct gr_arg));
61437+ memset(gr_system_salt, 0, GR_SALT_LEN);
61438+ memset(gr_system_sum, 0, GR_SHA_LEN);
61439+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
61440+ } else if (gr_status & GR_READY) {
61441+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
61442+ error = -EPERM;
61443+ } else {
61444+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
61445+ error = -EAGAIN;
61446+ }
61447+ break;
61448+ case GR_ENABLE:
61449+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
61450+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
61451+ else {
61452+ if (gr_status & GR_READY)
61453+ error = -EAGAIN;
61454+ else
61455+ error = error2;
61456+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
61457+ }
61458+ break;
61459+ case GR_RELOAD:
61460+ if (!(gr_status & GR_READY)) {
61461+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
61462+ error = -EAGAIN;
61463+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61464+ stop_machine(gr_rbac_disable, NULL, NULL);
61465+ free_variables();
61466+ error2 = gracl_init(gr_usermode);
61467+ if (!error2)
61468+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
61469+ else {
61470+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61471+ error = error2;
61472+ }
61473+ } else {
61474+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61475+ error = -EPERM;
61476+ }
61477+ break;
61478+ case GR_SEGVMOD:
61479+ if (unlikely(!(gr_status & GR_READY))) {
61480+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
61481+ error = -EAGAIN;
61482+ break;
61483+ }
61484+
61485+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61486+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
61487+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
61488+ struct acl_subject_label *segvacl;
61489+ segvacl =
61490+ lookup_acl_subj_label(gr_usermode->segv_inode,
61491+ gr_usermode->segv_device,
61492+ current->role);
61493+ if (segvacl) {
61494+ segvacl->crashes = 0;
61495+ segvacl->expires = 0;
61496+ }
61497+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
61498+ gr_remove_uid(gr_usermode->segv_uid);
61499+ }
61500+ } else {
61501+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
61502+ error = -EPERM;
61503+ }
61504+ break;
61505+ case GR_SPROLE:
61506+ case GR_SPROLEPAM:
61507+ if (unlikely(!(gr_status & GR_READY))) {
61508+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
61509+ error = -EAGAIN;
61510+ break;
61511+ }
61512+
61513+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
61514+ current->role->expires = 0;
61515+ current->role->auth_attempts = 0;
61516+ }
61517+
61518+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61519+ time_after(current->role->expires, get_seconds())) {
61520+ error = -EBUSY;
61521+ goto out;
61522+ }
61523+
61524+ if (lookup_special_role_auth
61525+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
61526+ && ((!sprole_salt && !sprole_sum)
61527+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
61528+ char *p = "";
61529+ assign_special_role(gr_usermode->sp_role);
61530+ read_lock(&tasklist_lock);
61531+ if (current->real_parent)
61532+ p = current->real_parent->role->rolename;
61533+ read_unlock(&tasklist_lock);
61534+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
61535+ p, acl_sp_role_value);
61536+ } else {
61537+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
61538+ error = -EPERM;
61539+ if(!(current->role->auth_attempts++))
61540+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61541+
61542+ goto out;
61543+ }
61544+ break;
61545+ case GR_UNSPROLE:
61546+ if (unlikely(!(gr_status & GR_READY))) {
61547+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
61548+ error = -EAGAIN;
61549+ break;
61550+ }
61551+
61552+ if (current->role->roletype & GR_ROLE_SPECIAL) {
61553+ char *p = "";
61554+ int i = 0;
61555+
61556+ read_lock(&tasklist_lock);
61557+ if (current->real_parent) {
61558+ p = current->real_parent->role->rolename;
61559+ i = current->real_parent->acl_role_id;
61560+ }
61561+ read_unlock(&tasklist_lock);
61562+
61563+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
61564+ gr_set_acls(1);
61565+ } else {
61566+ error = -EPERM;
61567+ goto out;
61568+ }
61569+ break;
61570+ default:
61571+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
61572+ error = -EINVAL;
61573+ break;
61574+ }
61575+
61576+ if (error != -EPERM)
61577+ goto out;
61578+
61579+ if(!(gr_auth_attempts++))
61580+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61581+
61582+ out:
61583+ mutex_unlock(&gr_dev_mutex);
61584+ return error;
61585+}
61586+
61587+/* must be called with
61588+ rcu_read_lock();
61589+ read_lock(&tasklist_lock);
61590+ read_lock(&grsec_exec_file_lock);
61591+*/
61592+int gr_apply_subject_to_task(struct task_struct *task)
61593+{
61594+ struct acl_object_label *obj;
61595+ char *tmpname;
61596+ struct acl_subject_label *tmpsubj;
61597+ struct file *filp;
61598+ struct name_entry *nmatch;
61599+
61600+ filp = task->exec_file;
61601+ if (filp == NULL)
61602+ return 0;
61603+
61604+ /* the following is to apply the correct subject
61605+ on binaries running when the RBAC system
61606+ is enabled, when the binaries have been
61607+ replaced or deleted since their execution
61608+ -----
61609+ when the RBAC system starts, the inode/dev
61610+ from exec_file will be one the RBAC system
61611+ is unaware of. It only knows the inode/dev
61612+ of the present file on disk, or the absence
61613+ of it.
61614+ */
61615+ preempt_disable();
61616+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
61617+
61618+ nmatch = lookup_name_entry(tmpname);
61619+ preempt_enable();
61620+ tmpsubj = NULL;
61621+ if (nmatch) {
61622+ if (nmatch->deleted)
61623+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
61624+ else
61625+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
61626+ if (tmpsubj != NULL)
61627+ task->acl = tmpsubj;
61628+ }
61629+ if (tmpsubj == NULL)
61630+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
61631+ task->role);
61632+ if (task->acl) {
61633+ task->is_writable = 0;
61634+ /* ignore additional mmap checks for processes that are writable
61635+ by the default ACL */
61636+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61637+ if (unlikely(obj->mode & GR_WRITE))
61638+ task->is_writable = 1;
61639+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61640+ if (unlikely(obj->mode & GR_WRITE))
61641+ task->is_writable = 1;
61642+
61643+ gr_set_proc_res(task);
61644+
61645+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61646+ 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);
61647+#endif
61648+ } else {
61649+ return 1;
61650+ }
61651+
61652+ return 0;
61653+}
61654+
61655+int
61656+gr_set_acls(const int type)
61657+{
61658+ struct task_struct *task, *task2;
61659+ struct acl_role_label *role = current->role;
61660+ __u16 acl_role_id = current->acl_role_id;
61661+ const struct cred *cred;
61662+ int ret;
61663+
61664+ rcu_read_lock();
61665+ read_lock(&tasklist_lock);
61666+ read_lock(&grsec_exec_file_lock);
61667+ do_each_thread(task2, task) {
61668+ /* check to see if we're called from the exit handler,
61669+ if so, only replace ACLs that have inherited the admin
61670+ ACL */
61671+
61672+ if (type && (task->role != role ||
61673+ task->acl_role_id != acl_role_id))
61674+ continue;
61675+
61676+ task->acl_role_id = 0;
61677+ task->acl_sp_role = 0;
61678+
61679+ if (task->exec_file) {
61680+ cred = __task_cred(task);
61681+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
61682+ ret = gr_apply_subject_to_task(task);
61683+ if (ret) {
61684+ read_unlock(&grsec_exec_file_lock);
61685+ read_unlock(&tasklist_lock);
61686+ rcu_read_unlock();
61687+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
61688+ return ret;
61689+ }
61690+ } else {
61691+ // it's a kernel process
61692+ task->role = kernel_role;
61693+ task->acl = kernel_role->root_label;
61694+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
61695+ task->acl->mode &= ~GR_PROCFIND;
61696+#endif
61697+ }
61698+ } while_each_thread(task2, task);
61699+ read_unlock(&grsec_exec_file_lock);
61700+ read_unlock(&tasklist_lock);
61701+ rcu_read_unlock();
61702+
61703+ return 0;
61704+}
61705+
61706+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
61707+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
61708+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
61709+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
61710+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
61711+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
61712+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
61713+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
61714+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
61715+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
61716+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
61717+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
61718+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
61719+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
61720+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
61721+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
61722+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
61723+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
61724+};
61725+
61726+void
61727+gr_learn_resource(const struct task_struct *task,
61728+ const int res, const unsigned long wanted, const int gt)
61729+{
61730+ struct acl_subject_label *acl;
61731+ const struct cred *cred;
61732+
61733+ if (unlikely((gr_status & GR_READY) &&
61734+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
61735+ goto skip_reslog;
61736+
61737+ gr_log_resource(task, res, wanted, gt);
61738+skip_reslog:
61739+
61740+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
61741+ return;
61742+
61743+ acl = task->acl;
61744+
61745+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
61746+ !(acl->resmask & (1U << (unsigned short) res))))
61747+ return;
61748+
61749+ if (wanted >= acl->res[res].rlim_cur) {
61750+ unsigned long res_add;
61751+
61752+ res_add = wanted + res_learn_bumps[res];
61753+
61754+ acl->res[res].rlim_cur = res_add;
61755+
61756+ if (wanted > acl->res[res].rlim_max)
61757+ acl->res[res].rlim_max = res_add;
61758+
61759+ /* only log the subject filename, since resource logging is supported for
61760+ single-subject learning only */
61761+ rcu_read_lock();
61762+ cred = __task_cred(task);
61763+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61764+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
61765+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
61766+ "", (unsigned long) res, &task->signal->saved_ip);
61767+ rcu_read_unlock();
61768+ }
61769+
61770+ return;
61771+}
61772+EXPORT_SYMBOL(gr_learn_resource);
61773+#endif
61774+
61775+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
61776+void
61777+pax_set_initial_flags(struct linux_binprm *bprm)
61778+{
61779+ struct task_struct *task = current;
61780+ struct acl_subject_label *proc;
61781+ unsigned long flags;
61782+
61783+ if (unlikely(!(gr_status & GR_READY)))
61784+ return;
61785+
61786+ flags = pax_get_flags(task);
61787+
61788+ proc = task->acl;
61789+
61790+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
61791+ flags &= ~MF_PAX_PAGEEXEC;
61792+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
61793+ flags &= ~MF_PAX_SEGMEXEC;
61794+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
61795+ flags &= ~MF_PAX_RANDMMAP;
61796+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
61797+ flags &= ~MF_PAX_EMUTRAMP;
61798+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
61799+ flags &= ~MF_PAX_MPROTECT;
61800+
61801+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
61802+ flags |= MF_PAX_PAGEEXEC;
61803+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
61804+ flags |= MF_PAX_SEGMEXEC;
61805+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
61806+ flags |= MF_PAX_RANDMMAP;
61807+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
61808+ flags |= MF_PAX_EMUTRAMP;
61809+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
61810+ flags |= MF_PAX_MPROTECT;
61811+
61812+ pax_set_flags(task, flags);
61813+
61814+ return;
61815+}
61816+#endif
61817+
61818+int
61819+gr_handle_proc_ptrace(struct task_struct *task)
61820+{
61821+ struct file *filp;
61822+ struct task_struct *tmp = task;
61823+ struct task_struct *curtemp = current;
61824+ __u32 retmode;
61825+
61826+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61827+ if (unlikely(!(gr_status & GR_READY)))
61828+ return 0;
61829+#endif
61830+
61831+ read_lock(&tasklist_lock);
61832+ read_lock(&grsec_exec_file_lock);
61833+ filp = task->exec_file;
61834+
61835+ while (task_pid_nr(tmp) > 0) {
61836+ if (tmp == curtemp)
61837+ break;
61838+ tmp = tmp->real_parent;
61839+ }
61840+
61841+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61842+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
61843+ read_unlock(&grsec_exec_file_lock);
61844+ read_unlock(&tasklist_lock);
61845+ return 1;
61846+ }
61847+
61848+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61849+ if (!(gr_status & GR_READY)) {
61850+ read_unlock(&grsec_exec_file_lock);
61851+ read_unlock(&tasklist_lock);
61852+ return 0;
61853+ }
61854+#endif
61855+
61856+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
61857+ read_unlock(&grsec_exec_file_lock);
61858+ read_unlock(&tasklist_lock);
61859+
61860+ if (retmode & GR_NOPTRACE)
61861+ return 1;
61862+
61863+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
61864+ && (current->acl != task->acl || (current->acl != current->role->root_label
61865+ && task_pid_nr(current) != task_pid_nr(task))))
61866+ return 1;
61867+
61868+ return 0;
61869+}
61870+
61871+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
61872+{
61873+ if (unlikely(!(gr_status & GR_READY)))
61874+ return;
61875+
61876+ if (!(current->role->roletype & GR_ROLE_GOD))
61877+ return;
61878+
61879+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
61880+ p->role->rolename, gr_task_roletype_to_char(p),
61881+ p->acl->filename);
61882+}
61883+
61884+int
61885+gr_handle_ptrace(struct task_struct *task, const long request)
61886+{
61887+ struct task_struct *tmp = task;
61888+ struct task_struct *curtemp = current;
61889+ __u32 retmode;
61890+
61891+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61892+ if (unlikely(!(gr_status & GR_READY)))
61893+ return 0;
61894+#endif
61895+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
61896+ read_lock(&tasklist_lock);
61897+ while (task_pid_nr(tmp) > 0) {
61898+ if (tmp == curtemp)
61899+ break;
61900+ tmp = tmp->real_parent;
61901+ }
61902+
61903+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61904+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
61905+ read_unlock(&tasklist_lock);
61906+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61907+ return 1;
61908+ }
61909+ read_unlock(&tasklist_lock);
61910+ }
61911+
61912+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61913+ if (!(gr_status & GR_READY))
61914+ return 0;
61915+#endif
61916+
61917+ read_lock(&grsec_exec_file_lock);
61918+ if (unlikely(!task->exec_file)) {
61919+ read_unlock(&grsec_exec_file_lock);
61920+ return 0;
61921+ }
61922+
61923+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
61924+ read_unlock(&grsec_exec_file_lock);
61925+
61926+ if (retmode & GR_NOPTRACE) {
61927+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61928+ return 1;
61929+ }
61930+
61931+ if (retmode & GR_PTRACERD) {
61932+ switch (request) {
61933+ case PTRACE_SEIZE:
61934+ case PTRACE_POKETEXT:
61935+ case PTRACE_POKEDATA:
61936+ case PTRACE_POKEUSR:
61937+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
61938+ case PTRACE_SETREGS:
61939+ case PTRACE_SETFPREGS:
61940+#endif
61941+#ifdef CONFIG_X86
61942+ case PTRACE_SETFPXREGS:
61943+#endif
61944+#ifdef CONFIG_ALTIVEC
61945+ case PTRACE_SETVRREGS:
61946+#endif
61947+ return 1;
61948+ default:
61949+ return 0;
61950+ }
61951+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
61952+ !(current->role->roletype & GR_ROLE_GOD) &&
61953+ (current->acl != task->acl)) {
61954+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61955+ return 1;
61956+ }
61957+
61958+ return 0;
61959+}
61960+
61961+static int is_writable_mmap(const struct file *filp)
61962+{
61963+ struct task_struct *task = current;
61964+ struct acl_object_label *obj, *obj2;
61965+
61966+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
61967+ !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))) {
61968+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61969+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
61970+ task->role->root_label);
61971+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
61972+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
61973+ return 1;
61974+ }
61975+ }
61976+ return 0;
61977+}
61978+
61979+int
61980+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
61981+{
61982+ __u32 mode;
61983+
61984+ if (unlikely(!file || !(prot & PROT_EXEC)))
61985+ return 1;
61986+
61987+ if (is_writable_mmap(file))
61988+ return 0;
61989+
61990+ mode =
61991+ gr_search_file(file->f_path.dentry,
61992+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61993+ file->f_path.mnt);
61994+
61995+ if (!gr_tpe_allow(file))
61996+ return 0;
61997+
61998+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61999+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62000+ return 0;
62001+ } else if (unlikely(!(mode & GR_EXEC))) {
62002+ return 0;
62003+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62004+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62005+ return 1;
62006+ }
62007+
62008+ return 1;
62009+}
62010+
62011+int
62012+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62013+{
62014+ __u32 mode;
62015+
62016+ if (unlikely(!file || !(prot & PROT_EXEC)))
62017+ return 1;
62018+
62019+ if (is_writable_mmap(file))
62020+ return 0;
62021+
62022+ mode =
62023+ gr_search_file(file->f_path.dentry,
62024+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62025+ file->f_path.mnt);
62026+
62027+ if (!gr_tpe_allow(file))
62028+ return 0;
62029+
62030+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62031+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62032+ return 0;
62033+ } else if (unlikely(!(mode & GR_EXEC))) {
62034+ return 0;
62035+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62036+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62037+ return 1;
62038+ }
62039+
62040+ return 1;
62041+}
62042+
62043+void
62044+gr_acl_handle_psacct(struct task_struct *task, const long code)
62045+{
62046+ unsigned long runtime;
62047+ unsigned long cputime;
62048+ unsigned int wday, cday;
62049+ __u8 whr, chr;
62050+ __u8 wmin, cmin;
62051+ __u8 wsec, csec;
62052+ struct timespec timeval;
62053+
62054+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
62055+ !(task->acl->mode & GR_PROCACCT)))
62056+ return;
62057+
62058+ do_posix_clock_monotonic_gettime(&timeval);
62059+ runtime = timeval.tv_sec - task->start_time.tv_sec;
62060+ wday = runtime / (3600 * 24);
62061+ runtime -= wday * (3600 * 24);
62062+ whr = runtime / 3600;
62063+ runtime -= whr * 3600;
62064+ wmin = runtime / 60;
62065+ runtime -= wmin * 60;
62066+ wsec = runtime;
62067+
62068+ cputime = (task->utime + task->stime) / HZ;
62069+ cday = cputime / (3600 * 24);
62070+ cputime -= cday * (3600 * 24);
62071+ chr = cputime / 3600;
62072+ cputime -= chr * 3600;
62073+ cmin = cputime / 60;
62074+ cputime -= cmin * 60;
62075+ csec = cputime;
62076+
62077+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
62078+
62079+ return;
62080+}
62081+
62082+void gr_set_kernel_label(struct task_struct *task)
62083+{
62084+ if (gr_status & GR_READY) {
62085+ task->role = kernel_role;
62086+ task->acl = kernel_role->root_label;
62087+ }
62088+ return;
62089+}
62090+
62091+#ifdef CONFIG_TASKSTATS
62092+int gr_is_taskstats_denied(int pid)
62093+{
62094+ struct task_struct *task;
62095+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62096+ const struct cred *cred;
62097+#endif
62098+ int ret = 0;
62099+
62100+ /* restrict taskstats viewing to un-chrooted root users
62101+ who have the 'view' subject flag if the RBAC system is enabled
62102+ */
62103+
62104+ rcu_read_lock();
62105+ read_lock(&tasklist_lock);
62106+ task = find_task_by_vpid(pid);
62107+ if (task) {
62108+#ifdef CONFIG_GRKERNSEC_CHROOT
62109+ if (proc_is_chrooted(task))
62110+ ret = -EACCES;
62111+#endif
62112+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62113+ cred = __task_cred(task);
62114+#ifdef CONFIG_GRKERNSEC_PROC_USER
62115+ if (gr_is_global_nonroot(cred->uid))
62116+ ret = -EACCES;
62117+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62118+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
62119+ ret = -EACCES;
62120+#endif
62121+#endif
62122+ if (gr_status & GR_READY) {
62123+ if (!(task->acl->mode & GR_VIEW))
62124+ ret = -EACCES;
62125+ }
62126+ } else
62127+ ret = -ENOENT;
62128+
62129+ read_unlock(&tasklist_lock);
62130+ rcu_read_unlock();
62131+
62132+ return ret;
62133+}
62134+#endif
62135+
62136+/* AUXV entries are filled via a descendant of search_binary_handler
62137+ after we've already applied the subject for the target
62138+*/
62139+int gr_acl_enable_at_secure(void)
62140+{
62141+ if (unlikely(!(gr_status & GR_READY)))
62142+ return 0;
62143+
62144+ if (current->acl->mode & GR_ATSECURE)
62145+ return 1;
62146+
62147+ return 0;
62148+}
62149+
62150+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
62151+{
62152+ struct task_struct *task = current;
62153+ struct dentry *dentry = file->f_path.dentry;
62154+ struct vfsmount *mnt = file->f_path.mnt;
62155+ struct acl_object_label *obj, *tmp;
62156+ struct acl_subject_label *subj;
62157+ unsigned int bufsize;
62158+ int is_not_root;
62159+ char *path;
62160+ dev_t dev = __get_dev(dentry);
62161+
62162+ if (unlikely(!(gr_status & GR_READY)))
62163+ return 1;
62164+
62165+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
62166+ return 1;
62167+
62168+ /* ignore Eric Biederman */
62169+ if (IS_PRIVATE(dentry->d_inode))
62170+ return 1;
62171+
62172+ subj = task->acl;
62173+ read_lock(&gr_inode_lock);
62174+ do {
62175+ obj = lookup_acl_obj_label(ino, dev, subj);
62176+ if (obj != NULL) {
62177+ read_unlock(&gr_inode_lock);
62178+ return (obj->mode & GR_FIND) ? 1 : 0;
62179+ }
62180+ } while ((subj = subj->parent_subject));
62181+ read_unlock(&gr_inode_lock);
62182+
62183+ /* this is purely an optimization since we're looking for an object
62184+ for the directory we're doing a readdir on
62185+ if it's possible for any globbed object to match the entry we're
62186+ filling into the directory, then the object we find here will be
62187+ an anchor point with attached globbed objects
62188+ */
62189+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
62190+ if (obj->globbed == NULL)
62191+ return (obj->mode & GR_FIND) ? 1 : 0;
62192+
62193+ is_not_root = ((obj->filename[0] == '/') &&
62194+ (obj->filename[1] == '\0')) ? 0 : 1;
62195+ bufsize = PAGE_SIZE - namelen - is_not_root;
62196+
62197+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
62198+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
62199+ return 1;
62200+
62201+ preempt_disable();
62202+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62203+ bufsize);
62204+
62205+ bufsize = strlen(path);
62206+
62207+ /* if base is "/", don't append an additional slash */
62208+ if (is_not_root)
62209+ *(path + bufsize) = '/';
62210+ memcpy(path + bufsize + is_not_root, name, namelen);
62211+ *(path + bufsize + namelen + is_not_root) = '\0';
62212+
62213+ tmp = obj->globbed;
62214+ while (tmp) {
62215+ if (!glob_match(tmp->filename, path)) {
62216+ preempt_enable();
62217+ return (tmp->mode & GR_FIND) ? 1 : 0;
62218+ }
62219+ tmp = tmp->next;
62220+ }
62221+ preempt_enable();
62222+ return (obj->mode & GR_FIND) ? 1 : 0;
62223+}
62224+
62225+void gr_put_exec_file(struct task_struct *task)
62226+{
62227+ struct file *filp;
62228+
62229+ write_lock(&grsec_exec_file_lock);
62230+ filp = task->exec_file;
62231+ task->exec_file = NULL;
62232+ write_unlock(&grsec_exec_file_lock);
62233+
62234+ if (filp)
62235+ fput(filp);
62236+
62237+ return;
62238+}
62239+
62240+
62241+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
62242+EXPORT_SYMBOL(gr_acl_is_enabled);
62243+#endif
62244+EXPORT_SYMBOL(gr_set_kernel_label);
62245+#ifdef CONFIG_SECURITY
62246+EXPORT_SYMBOL(gr_check_user_change);
62247+EXPORT_SYMBOL(gr_check_group_change);
62248+#endif
62249+
62250diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
62251new file mode 100644
62252index 0000000..34fefda
62253--- /dev/null
62254+++ b/grsecurity/gracl_alloc.c
62255@@ -0,0 +1,105 @@
62256+#include <linux/kernel.h>
62257+#include <linux/mm.h>
62258+#include <linux/slab.h>
62259+#include <linux/vmalloc.h>
62260+#include <linux/gracl.h>
62261+#include <linux/grsecurity.h>
62262+
62263+static unsigned long alloc_stack_next = 1;
62264+static unsigned long alloc_stack_size = 1;
62265+static void **alloc_stack;
62266+
62267+static __inline__ int
62268+alloc_pop(void)
62269+{
62270+ if (alloc_stack_next == 1)
62271+ return 0;
62272+
62273+ kfree(alloc_stack[alloc_stack_next - 2]);
62274+
62275+ alloc_stack_next--;
62276+
62277+ return 1;
62278+}
62279+
62280+static __inline__ int
62281+alloc_push(void *buf)
62282+{
62283+ if (alloc_stack_next >= alloc_stack_size)
62284+ return 1;
62285+
62286+ alloc_stack[alloc_stack_next - 1] = buf;
62287+
62288+ alloc_stack_next++;
62289+
62290+ return 0;
62291+}
62292+
62293+void *
62294+acl_alloc(unsigned long len)
62295+{
62296+ void *ret = NULL;
62297+
62298+ if (!len || len > PAGE_SIZE)
62299+ goto out;
62300+
62301+ ret = kmalloc(len, GFP_KERNEL);
62302+
62303+ if (ret) {
62304+ if (alloc_push(ret)) {
62305+ kfree(ret);
62306+ ret = NULL;
62307+ }
62308+ }
62309+
62310+out:
62311+ return ret;
62312+}
62313+
62314+void *
62315+acl_alloc_num(unsigned long num, unsigned long len)
62316+{
62317+ if (!len || (num > (PAGE_SIZE / len)))
62318+ return NULL;
62319+
62320+ return acl_alloc(num * len);
62321+}
62322+
62323+void
62324+acl_free_all(void)
62325+{
62326+ if (gr_acl_is_enabled() || !alloc_stack)
62327+ return;
62328+
62329+ while (alloc_pop()) ;
62330+
62331+ if (alloc_stack) {
62332+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
62333+ kfree(alloc_stack);
62334+ else
62335+ vfree(alloc_stack);
62336+ }
62337+
62338+ alloc_stack = NULL;
62339+ alloc_stack_size = 1;
62340+ alloc_stack_next = 1;
62341+
62342+ return;
62343+}
62344+
62345+int
62346+acl_alloc_stack_init(unsigned long size)
62347+{
62348+ if ((size * sizeof (void *)) <= PAGE_SIZE)
62349+ alloc_stack =
62350+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
62351+ else
62352+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
62353+
62354+ alloc_stack_size = size;
62355+
62356+ if (!alloc_stack)
62357+ return 0;
62358+ else
62359+ return 1;
62360+}
62361diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
62362new file mode 100644
62363index 0000000..bdd51ea
62364--- /dev/null
62365+++ b/grsecurity/gracl_cap.c
62366@@ -0,0 +1,110 @@
62367+#include <linux/kernel.h>
62368+#include <linux/module.h>
62369+#include <linux/sched.h>
62370+#include <linux/gracl.h>
62371+#include <linux/grsecurity.h>
62372+#include <linux/grinternal.h>
62373+
62374+extern const char *captab_log[];
62375+extern int captab_log_entries;
62376+
62377+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62378+{
62379+ struct acl_subject_label *curracl;
62380+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62381+ kernel_cap_t cap_audit = __cap_empty_set;
62382+
62383+ if (!gr_acl_is_enabled())
62384+ return 1;
62385+
62386+ curracl = task->acl;
62387+
62388+ cap_drop = curracl->cap_lower;
62389+ cap_mask = curracl->cap_mask;
62390+ cap_audit = curracl->cap_invert_audit;
62391+
62392+ while ((curracl = curracl->parent_subject)) {
62393+ /* if the cap isn't specified in the current computed mask but is specified in the
62394+ current level subject, and is lowered in the current level subject, then add
62395+ it to the set of dropped capabilities
62396+ otherwise, add the current level subject's mask to the current computed mask
62397+ */
62398+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62399+ cap_raise(cap_mask, cap);
62400+ if (cap_raised(curracl->cap_lower, cap))
62401+ cap_raise(cap_drop, cap);
62402+ if (cap_raised(curracl->cap_invert_audit, cap))
62403+ cap_raise(cap_audit, cap);
62404+ }
62405+ }
62406+
62407+ if (!cap_raised(cap_drop, cap)) {
62408+ if (cap_raised(cap_audit, cap))
62409+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
62410+ return 1;
62411+ }
62412+
62413+ curracl = task->acl;
62414+
62415+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
62416+ && cap_raised(cred->cap_effective, cap)) {
62417+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62418+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
62419+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
62420+ gr_to_filename(task->exec_file->f_path.dentry,
62421+ task->exec_file->f_path.mnt) : curracl->filename,
62422+ curracl->filename, 0UL,
62423+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
62424+ return 1;
62425+ }
62426+
62427+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
62428+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
62429+
62430+ return 0;
62431+}
62432+
62433+int
62434+gr_acl_is_capable(const int cap)
62435+{
62436+ return gr_task_acl_is_capable(current, current_cred(), cap);
62437+}
62438+
62439+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
62440+{
62441+ struct acl_subject_label *curracl;
62442+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62443+
62444+ if (!gr_acl_is_enabled())
62445+ return 1;
62446+
62447+ curracl = task->acl;
62448+
62449+ cap_drop = curracl->cap_lower;
62450+ cap_mask = curracl->cap_mask;
62451+
62452+ while ((curracl = curracl->parent_subject)) {
62453+ /* if the cap isn't specified in the current computed mask but is specified in the
62454+ current level subject, and is lowered in the current level subject, then add
62455+ it to the set of dropped capabilities
62456+ otherwise, add the current level subject's mask to the current computed mask
62457+ */
62458+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62459+ cap_raise(cap_mask, cap);
62460+ if (cap_raised(curracl->cap_lower, cap))
62461+ cap_raise(cap_drop, cap);
62462+ }
62463+ }
62464+
62465+ if (!cap_raised(cap_drop, cap))
62466+ return 1;
62467+
62468+ return 0;
62469+}
62470+
62471+int
62472+gr_acl_is_capable_nolog(const int cap)
62473+{
62474+ return gr_task_acl_is_capable_nolog(current, cap);
62475+}
62476+
62477diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
62478new file mode 100644
62479index 0000000..a340c17
62480--- /dev/null
62481+++ b/grsecurity/gracl_fs.c
62482@@ -0,0 +1,431 @@
62483+#include <linux/kernel.h>
62484+#include <linux/sched.h>
62485+#include <linux/types.h>
62486+#include <linux/fs.h>
62487+#include <linux/file.h>
62488+#include <linux/stat.h>
62489+#include <linux/grsecurity.h>
62490+#include <linux/grinternal.h>
62491+#include <linux/gracl.h>
62492+
62493+umode_t
62494+gr_acl_umask(void)
62495+{
62496+ if (unlikely(!gr_acl_is_enabled()))
62497+ return 0;
62498+
62499+ return current->role->umask;
62500+}
62501+
62502+__u32
62503+gr_acl_handle_hidden_file(const struct dentry * dentry,
62504+ const struct vfsmount * mnt)
62505+{
62506+ __u32 mode;
62507+
62508+ if (unlikely(!dentry->d_inode))
62509+ return GR_FIND;
62510+
62511+ mode =
62512+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
62513+
62514+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
62515+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62516+ return mode;
62517+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
62518+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62519+ return 0;
62520+ } else if (unlikely(!(mode & GR_FIND)))
62521+ return 0;
62522+
62523+ return GR_FIND;
62524+}
62525+
62526+__u32
62527+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62528+ int acc_mode)
62529+{
62530+ __u32 reqmode = GR_FIND;
62531+ __u32 mode;
62532+
62533+ if (unlikely(!dentry->d_inode))
62534+ return reqmode;
62535+
62536+ if (acc_mode & MAY_APPEND)
62537+ reqmode |= GR_APPEND;
62538+ else if (acc_mode & MAY_WRITE)
62539+ reqmode |= GR_WRITE;
62540+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
62541+ reqmode |= GR_READ;
62542+
62543+ mode =
62544+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62545+ mnt);
62546+
62547+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62548+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62549+ reqmode & GR_READ ? " reading" : "",
62550+ reqmode & GR_WRITE ? " writing" : reqmode &
62551+ GR_APPEND ? " appending" : "");
62552+ return reqmode;
62553+ } else
62554+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62555+ {
62556+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62557+ reqmode & GR_READ ? " reading" : "",
62558+ reqmode & GR_WRITE ? " writing" : reqmode &
62559+ GR_APPEND ? " appending" : "");
62560+ return 0;
62561+ } else if (unlikely((mode & reqmode) != reqmode))
62562+ return 0;
62563+
62564+ return reqmode;
62565+}
62566+
62567+__u32
62568+gr_acl_handle_creat(const struct dentry * dentry,
62569+ const struct dentry * p_dentry,
62570+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
62571+ const int imode)
62572+{
62573+ __u32 reqmode = GR_WRITE | GR_CREATE;
62574+ __u32 mode;
62575+
62576+ if (acc_mode & MAY_APPEND)
62577+ reqmode |= GR_APPEND;
62578+ // if a directory was required or the directory already exists, then
62579+ // don't count this open as a read
62580+ if ((acc_mode & MAY_READ) &&
62581+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
62582+ reqmode |= GR_READ;
62583+ if ((open_flags & O_CREAT) &&
62584+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62585+ reqmode |= GR_SETID;
62586+
62587+ mode =
62588+ gr_check_create(dentry, p_dentry, p_mnt,
62589+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62590+
62591+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62592+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62593+ reqmode & GR_READ ? " reading" : "",
62594+ reqmode & GR_WRITE ? " writing" : reqmode &
62595+ GR_APPEND ? " appending" : "");
62596+ return reqmode;
62597+ } else
62598+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62599+ {
62600+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62601+ reqmode & GR_READ ? " reading" : "",
62602+ reqmode & GR_WRITE ? " writing" : reqmode &
62603+ GR_APPEND ? " appending" : "");
62604+ return 0;
62605+ } else if (unlikely((mode & reqmode) != reqmode))
62606+ return 0;
62607+
62608+ return reqmode;
62609+}
62610+
62611+__u32
62612+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
62613+ const int fmode)
62614+{
62615+ __u32 mode, reqmode = GR_FIND;
62616+
62617+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
62618+ reqmode |= GR_EXEC;
62619+ if (fmode & S_IWOTH)
62620+ reqmode |= GR_WRITE;
62621+ if (fmode & S_IROTH)
62622+ reqmode |= GR_READ;
62623+
62624+ mode =
62625+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62626+ mnt);
62627+
62628+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62629+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62630+ reqmode & GR_READ ? " reading" : "",
62631+ reqmode & GR_WRITE ? " writing" : "",
62632+ reqmode & GR_EXEC ? " executing" : "");
62633+ return reqmode;
62634+ } else
62635+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62636+ {
62637+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62638+ reqmode & GR_READ ? " reading" : "",
62639+ reqmode & GR_WRITE ? " writing" : "",
62640+ reqmode & GR_EXEC ? " executing" : "");
62641+ return 0;
62642+ } else if (unlikely((mode & reqmode) != reqmode))
62643+ return 0;
62644+
62645+ return reqmode;
62646+}
62647+
62648+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
62649+{
62650+ __u32 mode;
62651+
62652+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
62653+
62654+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62655+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
62656+ return mode;
62657+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62658+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
62659+ return 0;
62660+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62661+ return 0;
62662+
62663+ return (reqmode);
62664+}
62665+
62666+__u32
62667+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62668+{
62669+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
62670+}
62671+
62672+__u32
62673+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
62674+{
62675+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
62676+}
62677+
62678+__u32
62679+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
62680+{
62681+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
62682+}
62683+
62684+__u32
62685+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
62686+{
62687+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
62688+}
62689+
62690+__u32
62691+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
62692+ umode_t *modeptr)
62693+{
62694+ umode_t mode;
62695+
62696+ *modeptr &= ~gr_acl_umask();
62697+ mode = *modeptr;
62698+
62699+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
62700+ return 1;
62701+
62702+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
62703+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
62704+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
62705+ GR_CHMOD_ACL_MSG);
62706+ } else {
62707+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
62708+ }
62709+}
62710+
62711+__u32
62712+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
62713+{
62714+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
62715+}
62716+
62717+__u32
62718+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
62719+{
62720+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
62721+}
62722+
62723+__u32
62724+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
62725+{
62726+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
62727+}
62728+
62729+__u32
62730+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
62731+{
62732+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
62733+ GR_UNIXCONNECT_ACL_MSG);
62734+}
62735+
62736+/* hardlinks require at minimum create and link permission,
62737+ any additional privilege required is based on the
62738+ privilege of the file being linked to
62739+*/
62740+__u32
62741+gr_acl_handle_link(const struct dentry * new_dentry,
62742+ const struct dentry * parent_dentry,
62743+ const struct vfsmount * parent_mnt,
62744+ const struct dentry * old_dentry,
62745+ const struct vfsmount * old_mnt, const struct filename *to)
62746+{
62747+ __u32 mode;
62748+ __u32 needmode = GR_CREATE | GR_LINK;
62749+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
62750+
62751+ mode =
62752+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
62753+ old_mnt);
62754+
62755+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
62756+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62757+ return mode;
62758+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62759+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62760+ return 0;
62761+ } else if (unlikely((mode & needmode) != needmode))
62762+ return 0;
62763+
62764+ return 1;
62765+}
62766+
62767+__u32
62768+gr_acl_handle_symlink(const struct dentry * new_dentry,
62769+ const struct dentry * parent_dentry,
62770+ const struct vfsmount * parent_mnt, const struct filename *from)
62771+{
62772+ __u32 needmode = GR_WRITE | GR_CREATE;
62773+ __u32 mode;
62774+
62775+ mode =
62776+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
62777+ GR_CREATE | GR_AUDIT_CREATE |
62778+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
62779+
62780+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
62781+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62782+ return mode;
62783+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62784+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62785+ return 0;
62786+ } else if (unlikely((mode & needmode) != needmode))
62787+ return 0;
62788+
62789+ return (GR_WRITE | GR_CREATE);
62790+}
62791+
62792+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)
62793+{
62794+ __u32 mode;
62795+
62796+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62797+
62798+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62799+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
62800+ return mode;
62801+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62802+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
62803+ return 0;
62804+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62805+ return 0;
62806+
62807+ return (reqmode);
62808+}
62809+
62810+__u32
62811+gr_acl_handle_mknod(const struct dentry * new_dentry,
62812+ const struct dentry * parent_dentry,
62813+ const struct vfsmount * parent_mnt,
62814+ const int mode)
62815+{
62816+ __u32 reqmode = GR_WRITE | GR_CREATE;
62817+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62818+ reqmode |= GR_SETID;
62819+
62820+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62821+ reqmode, GR_MKNOD_ACL_MSG);
62822+}
62823+
62824+__u32
62825+gr_acl_handle_mkdir(const struct dentry *new_dentry,
62826+ const struct dentry *parent_dentry,
62827+ const struct vfsmount *parent_mnt)
62828+{
62829+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62830+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
62831+}
62832+
62833+#define RENAME_CHECK_SUCCESS(old, new) \
62834+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
62835+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
62836+
62837+int
62838+gr_acl_handle_rename(struct dentry *new_dentry,
62839+ struct dentry *parent_dentry,
62840+ const struct vfsmount *parent_mnt,
62841+ struct dentry *old_dentry,
62842+ struct inode *old_parent_inode,
62843+ struct vfsmount *old_mnt, const struct filename *newname)
62844+{
62845+ __u32 comp1, comp2;
62846+ int error = 0;
62847+
62848+ if (unlikely(!gr_acl_is_enabled()))
62849+ return 0;
62850+
62851+ if (!new_dentry->d_inode) {
62852+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
62853+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
62854+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
62855+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
62856+ GR_DELETE | GR_AUDIT_DELETE |
62857+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62858+ GR_SUPPRESS, old_mnt);
62859+ } else {
62860+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
62861+ GR_CREATE | GR_DELETE |
62862+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
62863+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62864+ GR_SUPPRESS, parent_mnt);
62865+ comp2 =
62866+ gr_search_file(old_dentry,
62867+ GR_READ | GR_WRITE | GR_AUDIT_READ |
62868+ GR_DELETE | GR_AUDIT_DELETE |
62869+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
62870+ }
62871+
62872+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
62873+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
62874+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62875+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
62876+ && !(comp2 & GR_SUPPRESS)) {
62877+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62878+ error = -EACCES;
62879+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
62880+ error = -EACCES;
62881+
62882+ return error;
62883+}
62884+
62885+void
62886+gr_acl_handle_exit(void)
62887+{
62888+ u16 id;
62889+ char *rolename;
62890+
62891+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
62892+ !(current->role->roletype & GR_ROLE_PERSIST))) {
62893+ id = current->acl_role_id;
62894+ rolename = current->role->rolename;
62895+ gr_set_acls(1);
62896+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
62897+ }
62898+
62899+ gr_put_exec_file(current);
62900+ return;
62901+}
62902+
62903+int
62904+gr_acl_handle_procpidmem(const struct task_struct *task)
62905+{
62906+ if (unlikely(!gr_acl_is_enabled()))
62907+ return 0;
62908+
62909+ if (task != current && task->acl->mode & GR_PROTPROCFD)
62910+ return -EACCES;
62911+
62912+ return 0;
62913+}
62914diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
62915new file mode 100644
62916index 0000000..8132048
62917--- /dev/null
62918+++ b/grsecurity/gracl_ip.c
62919@@ -0,0 +1,387 @@
62920+#include <linux/kernel.h>
62921+#include <asm/uaccess.h>
62922+#include <asm/errno.h>
62923+#include <net/sock.h>
62924+#include <linux/file.h>
62925+#include <linux/fs.h>
62926+#include <linux/net.h>
62927+#include <linux/in.h>
62928+#include <linux/skbuff.h>
62929+#include <linux/ip.h>
62930+#include <linux/udp.h>
62931+#include <linux/types.h>
62932+#include <linux/sched.h>
62933+#include <linux/netdevice.h>
62934+#include <linux/inetdevice.h>
62935+#include <linux/gracl.h>
62936+#include <linux/grsecurity.h>
62937+#include <linux/grinternal.h>
62938+
62939+#define GR_BIND 0x01
62940+#define GR_CONNECT 0x02
62941+#define GR_INVERT 0x04
62942+#define GR_BINDOVERRIDE 0x08
62943+#define GR_CONNECTOVERRIDE 0x10
62944+#define GR_SOCK_FAMILY 0x20
62945+
62946+static const char * gr_protocols[IPPROTO_MAX] = {
62947+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
62948+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
62949+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
62950+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
62951+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
62952+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
62953+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
62954+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
62955+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
62956+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
62957+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
62958+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
62959+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
62960+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
62961+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
62962+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
62963+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
62964+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
62965+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
62966+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
62967+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
62968+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
62969+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
62970+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
62971+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
62972+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
62973+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
62974+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
62975+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
62976+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
62977+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
62978+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
62979+ };
62980+
62981+static const char * gr_socktypes[SOCK_MAX] = {
62982+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
62983+ "unknown:7", "unknown:8", "unknown:9", "packet"
62984+ };
62985+
62986+static const char * gr_sockfamilies[AF_MAX+1] = {
62987+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
62988+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
62989+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
62990+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
62991+ };
62992+
62993+const char *
62994+gr_proto_to_name(unsigned char proto)
62995+{
62996+ return gr_protocols[proto];
62997+}
62998+
62999+const char *
63000+gr_socktype_to_name(unsigned char type)
63001+{
63002+ return gr_socktypes[type];
63003+}
63004+
63005+const char *
63006+gr_sockfamily_to_name(unsigned char family)
63007+{
63008+ return gr_sockfamilies[family];
63009+}
63010+
63011+int
63012+gr_search_socket(const int domain, const int type, const int protocol)
63013+{
63014+ struct acl_subject_label *curr;
63015+ const struct cred *cred = current_cred();
63016+
63017+ if (unlikely(!gr_acl_is_enabled()))
63018+ goto exit;
63019+
63020+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
63021+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
63022+ goto exit; // let the kernel handle it
63023+
63024+ curr = current->acl;
63025+
63026+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
63027+ /* the family is allowed, if this is PF_INET allow it only if
63028+ the extra sock type/protocol checks pass */
63029+ if (domain == PF_INET)
63030+ goto inet_check;
63031+ goto exit;
63032+ } else {
63033+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63034+ __u32 fakeip = 0;
63035+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63036+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63037+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63038+ gr_to_filename(current->exec_file->f_path.dentry,
63039+ current->exec_file->f_path.mnt) :
63040+ curr->filename, curr->filename,
63041+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
63042+ &current->signal->saved_ip);
63043+ goto exit;
63044+ }
63045+ goto exit_fail;
63046+ }
63047+
63048+inet_check:
63049+ /* the rest of this checking is for IPv4 only */
63050+ if (!curr->ips)
63051+ goto exit;
63052+
63053+ if ((curr->ip_type & (1U << type)) &&
63054+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
63055+ goto exit;
63056+
63057+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63058+ /* we don't place acls on raw sockets , and sometimes
63059+ dgram/ip sockets are opened for ioctl and not
63060+ bind/connect, so we'll fake a bind learn log */
63061+ if (type == SOCK_RAW || type == SOCK_PACKET) {
63062+ __u32 fakeip = 0;
63063+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63064+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63065+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63066+ gr_to_filename(current->exec_file->f_path.dentry,
63067+ current->exec_file->f_path.mnt) :
63068+ curr->filename, curr->filename,
63069+ &fakeip, 0, type,
63070+ protocol, GR_CONNECT, &current->signal->saved_ip);
63071+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
63072+ __u32 fakeip = 0;
63073+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63074+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63075+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63076+ gr_to_filename(current->exec_file->f_path.dentry,
63077+ current->exec_file->f_path.mnt) :
63078+ curr->filename, curr->filename,
63079+ &fakeip, 0, type,
63080+ protocol, GR_BIND, &current->signal->saved_ip);
63081+ }
63082+ /* we'll log when they use connect or bind */
63083+ goto exit;
63084+ }
63085+
63086+exit_fail:
63087+ if (domain == PF_INET)
63088+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
63089+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
63090+ else
63091+#ifndef CONFIG_IPV6
63092+ if (domain != PF_INET6)
63093+#endif
63094+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
63095+ gr_socktype_to_name(type), protocol);
63096+
63097+ return 0;
63098+exit:
63099+ return 1;
63100+}
63101+
63102+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)
63103+{
63104+ if ((ip->mode & mode) &&
63105+ (ip_port >= ip->low) &&
63106+ (ip_port <= ip->high) &&
63107+ ((ntohl(ip_addr) & our_netmask) ==
63108+ (ntohl(our_addr) & our_netmask))
63109+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
63110+ && (ip->type & (1U << type))) {
63111+ if (ip->mode & GR_INVERT)
63112+ return 2; // specifically denied
63113+ else
63114+ return 1; // allowed
63115+ }
63116+
63117+ return 0; // not specifically allowed, may continue parsing
63118+}
63119+
63120+static int
63121+gr_search_connectbind(const int full_mode, struct sock *sk,
63122+ struct sockaddr_in *addr, const int type)
63123+{
63124+ char iface[IFNAMSIZ] = {0};
63125+ struct acl_subject_label *curr;
63126+ struct acl_ip_label *ip;
63127+ struct inet_sock *isk;
63128+ struct net_device *dev;
63129+ struct in_device *idev;
63130+ unsigned long i;
63131+ int ret;
63132+ int mode = full_mode & (GR_BIND | GR_CONNECT);
63133+ __u32 ip_addr = 0;
63134+ __u32 our_addr;
63135+ __u32 our_netmask;
63136+ char *p;
63137+ __u16 ip_port = 0;
63138+ const struct cred *cred = current_cred();
63139+
63140+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
63141+ return 0;
63142+
63143+ curr = current->acl;
63144+ isk = inet_sk(sk);
63145+
63146+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
63147+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
63148+ addr->sin_addr.s_addr = curr->inaddr_any_override;
63149+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
63150+ struct sockaddr_in saddr;
63151+ int err;
63152+
63153+ saddr.sin_family = AF_INET;
63154+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
63155+ saddr.sin_port = isk->inet_sport;
63156+
63157+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63158+ if (err)
63159+ return err;
63160+
63161+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63162+ if (err)
63163+ return err;
63164+ }
63165+
63166+ if (!curr->ips)
63167+ return 0;
63168+
63169+ ip_addr = addr->sin_addr.s_addr;
63170+ ip_port = ntohs(addr->sin_port);
63171+
63172+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63173+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63174+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63175+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63176+ gr_to_filename(current->exec_file->f_path.dentry,
63177+ current->exec_file->f_path.mnt) :
63178+ curr->filename, curr->filename,
63179+ &ip_addr, ip_port, type,
63180+ sk->sk_protocol, mode, &current->signal->saved_ip);
63181+ return 0;
63182+ }
63183+
63184+ for (i = 0; i < curr->ip_num; i++) {
63185+ ip = *(curr->ips + i);
63186+ if (ip->iface != NULL) {
63187+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
63188+ p = strchr(iface, ':');
63189+ if (p != NULL)
63190+ *p = '\0';
63191+ dev = dev_get_by_name(sock_net(sk), iface);
63192+ if (dev == NULL)
63193+ continue;
63194+ idev = in_dev_get(dev);
63195+ if (idev == NULL) {
63196+ dev_put(dev);
63197+ continue;
63198+ }
63199+ rcu_read_lock();
63200+ for_ifa(idev) {
63201+ if (!strcmp(ip->iface, ifa->ifa_label)) {
63202+ our_addr = ifa->ifa_address;
63203+ our_netmask = 0xffffffff;
63204+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63205+ if (ret == 1) {
63206+ rcu_read_unlock();
63207+ in_dev_put(idev);
63208+ dev_put(dev);
63209+ return 0;
63210+ } else if (ret == 2) {
63211+ rcu_read_unlock();
63212+ in_dev_put(idev);
63213+ dev_put(dev);
63214+ goto denied;
63215+ }
63216+ }
63217+ } endfor_ifa(idev);
63218+ rcu_read_unlock();
63219+ in_dev_put(idev);
63220+ dev_put(dev);
63221+ } else {
63222+ our_addr = ip->addr;
63223+ our_netmask = ip->netmask;
63224+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63225+ if (ret == 1)
63226+ return 0;
63227+ else if (ret == 2)
63228+ goto denied;
63229+ }
63230+ }
63231+
63232+denied:
63233+ if (mode == GR_BIND)
63234+ 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));
63235+ else if (mode == GR_CONNECT)
63236+ 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));
63237+
63238+ return -EACCES;
63239+}
63240+
63241+int
63242+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
63243+{
63244+ /* always allow disconnection of dgram sockets with connect */
63245+ if (addr->sin_family == AF_UNSPEC)
63246+ return 0;
63247+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
63248+}
63249+
63250+int
63251+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
63252+{
63253+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
63254+}
63255+
63256+int gr_search_listen(struct socket *sock)
63257+{
63258+ struct sock *sk = sock->sk;
63259+ struct sockaddr_in addr;
63260+
63261+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63262+ addr.sin_port = inet_sk(sk)->inet_sport;
63263+
63264+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63265+}
63266+
63267+int gr_search_accept(struct socket *sock)
63268+{
63269+ struct sock *sk = sock->sk;
63270+ struct sockaddr_in addr;
63271+
63272+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63273+ addr.sin_port = inet_sk(sk)->inet_sport;
63274+
63275+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63276+}
63277+
63278+int
63279+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
63280+{
63281+ if (addr)
63282+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
63283+ else {
63284+ struct sockaddr_in sin;
63285+ const struct inet_sock *inet = inet_sk(sk);
63286+
63287+ sin.sin_addr.s_addr = inet->inet_daddr;
63288+ sin.sin_port = inet->inet_dport;
63289+
63290+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63291+ }
63292+}
63293+
63294+int
63295+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
63296+{
63297+ struct sockaddr_in sin;
63298+
63299+ if (unlikely(skb->len < sizeof (struct udphdr)))
63300+ return 0; // skip this packet
63301+
63302+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
63303+ sin.sin_port = udp_hdr(skb)->source;
63304+
63305+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63306+}
63307diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
63308new file mode 100644
63309index 0000000..25f54ef
63310--- /dev/null
63311+++ b/grsecurity/gracl_learn.c
63312@@ -0,0 +1,207 @@
63313+#include <linux/kernel.h>
63314+#include <linux/mm.h>
63315+#include <linux/sched.h>
63316+#include <linux/poll.h>
63317+#include <linux/string.h>
63318+#include <linux/file.h>
63319+#include <linux/types.h>
63320+#include <linux/vmalloc.h>
63321+#include <linux/grinternal.h>
63322+
63323+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
63324+ size_t count, loff_t *ppos);
63325+extern int gr_acl_is_enabled(void);
63326+
63327+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
63328+static int gr_learn_attached;
63329+
63330+/* use a 512k buffer */
63331+#define LEARN_BUFFER_SIZE (512 * 1024)
63332+
63333+static DEFINE_SPINLOCK(gr_learn_lock);
63334+static DEFINE_MUTEX(gr_learn_user_mutex);
63335+
63336+/* we need to maintain two buffers, so that the kernel context of grlearn
63337+ uses a semaphore around the userspace copying, and the other kernel contexts
63338+ use a spinlock when copying into the buffer, since they cannot sleep
63339+*/
63340+static char *learn_buffer;
63341+static char *learn_buffer_user;
63342+static int learn_buffer_len;
63343+static int learn_buffer_user_len;
63344+
63345+static ssize_t
63346+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
63347+{
63348+ DECLARE_WAITQUEUE(wait, current);
63349+ ssize_t retval = 0;
63350+
63351+ add_wait_queue(&learn_wait, &wait);
63352+ set_current_state(TASK_INTERRUPTIBLE);
63353+ do {
63354+ mutex_lock(&gr_learn_user_mutex);
63355+ spin_lock(&gr_learn_lock);
63356+ if (learn_buffer_len)
63357+ break;
63358+ spin_unlock(&gr_learn_lock);
63359+ mutex_unlock(&gr_learn_user_mutex);
63360+ if (file->f_flags & O_NONBLOCK) {
63361+ retval = -EAGAIN;
63362+ goto out;
63363+ }
63364+ if (signal_pending(current)) {
63365+ retval = -ERESTARTSYS;
63366+ goto out;
63367+ }
63368+
63369+ schedule();
63370+ } while (1);
63371+
63372+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
63373+ learn_buffer_user_len = learn_buffer_len;
63374+ retval = learn_buffer_len;
63375+ learn_buffer_len = 0;
63376+
63377+ spin_unlock(&gr_learn_lock);
63378+
63379+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
63380+ retval = -EFAULT;
63381+
63382+ mutex_unlock(&gr_learn_user_mutex);
63383+out:
63384+ set_current_state(TASK_RUNNING);
63385+ remove_wait_queue(&learn_wait, &wait);
63386+ return retval;
63387+}
63388+
63389+static unsigned int
63390+poll_learn(struct file * file, poll_table * wait)
63391+{
63392+ poll_wait(file, &learn_wait, wait);
63393+
63394+ if (learn_buffer_len)
63395+ return (POLLIN | POLLRDNORM);
63396+
63397+ return 0;
63398+}
63399+
63400+void
63401+gr_clear_learn_entries(void)
63402+{
63403+ char *tmp;
63404+
63405+ mutex_lock(&gr_learn_user_mutex);
63406+ spin_lock(&gr_learn_lock);
63407+ tmp = learn_buffer;
63408+ learn_buffer = NULL;
63409+ spin_unlock(&gr_learn_lock);
63410+ if (tmp)
63411+ vfree(tmp);
63412+ if (learn_buffer_user != NULL) {
63413+ vfree(learn_buffer_user);
63414+ learn_buffer_user = NULL;
63415+ }
63416+ learn_buffer_len = 0;
63417+ mutex_unlock(&gr_learn_user_mutex);
63418+
63419+ return;
63420+}
63421+
63422+void
63423+gr_add_learn_entry(const char *fmt, ...)
63424+{
63425+ va_list args;
63426+ unsigned int len;
63427+
63428+ if (!gr_learn_attached)
63429+ return;
63430+
63431+ spin_lock(&gr_learn_lock);
63432+
63433+ /* leave a gap at the end so we know when it's "full" but don't have to
63434+ compute the exact length of the string we're trying to append
63435+ */
63436+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
63437+ spin_unlock(&gr_learn_lock);
63438+ wake_up_interruptible(&learn_wait);
63439+ return;
63440+ }
63441+ if (learn_buffer == NULL) {
63442+ spin_unlock(&gr_learn_lock);
63443+ return;
63444+ }
63445+
63446+ va_start(args, fmt);
63447+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
63448+ va_end(args);
63449+
63450+ learn_buffer_len += len + 1;
63451+
63452+ spin_unlock(&gr_learn_lock);
63453+ wake_up_interruptible(&learn_wait);
63454+
63455+ return;
63456+}
63457+
63458+static int
63459+open_learn(struct inode *inode, struct file *file)
63460+{
63461+ if (file->f_mode & FMODE_READ && gr_learn_attached)
63462+ return -EBUSY;
63463+ if (file->f_mode & FMODE_READ) {
63464+ int retval = 0;
63465+ mutex_lock(&gr_learn_user_mutex);
63466+ if (learn_buffer == NULL)
63467+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
63468+ if (learn_buffer_user == NULL)
63469+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
63470+ if (learn_buffer == NULL) {
63471+ retval = -ENOMEM;
63472+ goto out_error;
63473+ }
63474+ if (learn_buffer_user == NULL) {
63475+ retval = -ENOMEM;
63476+ goto out_error;
63477+ }
63478+ learn_buffer_len = 0;
63479+ learn_buffer_user_len = 0;
63480+ gr_learn_attached = 1;
63481+out_error:
63482+ mutex_unlock(&gr_learn_user_mutex);
63483+ return retval;
63484+ }
63485+ return 0;
63486+}
63487+
63488+static int
63489+close_learn(struct inode *inode, struct file *file)
63490+{
63491+ if (file->f_mode & FMODE_READ) {
63492+ char *tmp = NULL;
63493+ mutex_lock(&gr_learn_user_mutex);
63494+ spin_lock(&gr_learn_lock);
63495+ tmp = learn_buffer;
63496+ learn_buffer = NULL;
63497+ spin_unlock(&gr_learn_lock);
63498+ if (tmp)
63499+ vfree(tmp);
63500+ if (learn_buffer_user != NULL) {
63501+ vfree(learn_buffer_user);
63502+ learn_buffer_user = NULL;
63503+ }
63504+ learn_buffer_len = 0;
63505+ learn_buffer_user_len = 0;
63506+ gr_learn_attached = 0;
63507+ mutex_unlock(&gr_learn_user_mutex);
63508+ }
63509+
63510+ return 0;
63511+}
63512+
63513+const struct file_operations grsec_fops = {
63514+ .read = read_learn,
63515+ .write = write_grsec_handler,
63516+ .open = open_learn,
63517+ .release = close_learn,
63518+ .poll = poll_learn,
63519+};
63520diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
63521new file mode 100644
63522index 0000000..39645c9
63523--- /dev/null
63524+++ b/grsecurity/gracl_res.c
63525@@ -0,0 +1,68 @@
63526+#include <linux/kernel.h>
63527+#include <linux/sched.h>
63528+#include <linux/gracl.h>
63529+#include <linux/grinternal.h>
63530+
63531+static const char *restab_log[] = {
63532+ [RLIMIT_CPU] = "RLIMIT_CPU",
63533+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
63534+ [RLIMIT_DATA] = "RLIMIT_DATA",
63535+ [RLIMIT_STACK] = "RLIMIT_STACK",
63536+ [RLIMIT_CORE] = "RLIMIT_CORE",
63537+ [RLIMIT_RSS] = "RLIMIT_RSS",
63538+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
63539+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
63540+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
63541+ [RLIMIT_AS] = "RLIMIT_AS",
63542+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
63543+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
63544+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
63545+ [RLIMIT_NICE] = "RLIMIT_NICE",
63546+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
63547+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
63548+ [GR_CRASH_RES] = "RLIMIT_CRASH"
63549+};
63550+
63551+void
63552+gr_log_resource(const struct task_struct *task,
63553+ const int res, const unsigned long wanted, const int gt)
63554+{
63555+ const struct cred *cred;
63556+ unsigned long rlim;
63557+
63558+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
63559+ return;
63560+
63561+ // not yet supported resource
63562+ if (unlikely(!restab_log[res]))
63563+ return;
63564+
63565+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
63566+ rlim = task_rlimit_max(task, res);
63567+ else
63568+ rlim = task_rlimit(task, res);
63569+
63570+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
63571+ return;
63572+
63573+ rcu_read_lock();
63574+ cred = __task_cred(task);
63575+
63576+ if (res == RLIMIT_NPROC &&
63577+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
63578+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
63579+ goto out_rcu_unlock;
63580+ else if (res == RLIMIT_MEMLOCK &&
63581+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
63582+ goto out_rcu_unlock;
63583+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
63584+ goto out_rcu_unlock;
63585+ rcu_read_unlock();
63586+
63587+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
63588+
63589+ return;
63590+out_rcu_unlock:
63591+ rcu_read_unlock();
63592+ return;
63593+}
63594diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
63595new file mode 100644
63596index 0000000..3c38bfe
63597--- /dev/null
63598+++ b/grsecurity/gracl_segv.c
63599@@ -0,0 +1,305 @@
63600+#include <linux/kernel.h>
63601+#include <linux/mm.h>
63602+#include <asm/uaccess.h>
63603+#include <asm/errno.h>
63604+#include <asm/mman.h>
63605+#include <net/sock.h>
63606+#include <linux/file.h>
63607+#include <linux/fs.h>
63608+#include <linux/net.h>
63609+#include <linux/in.h>
63610+#include <linux/slab.h>
63611+#include <linux/types.h>
63612+#include <linux/sched.h>
63613+#include <linux/timer.h>
63614+#include <linux/gracl.h>
63615+#include <linux/grsecurity.h>
63616+#include <linux/grinternal.h>
63617+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63618+#include <linux/magic.h>
63619+#include <linux/pagemap.h>
63620+#include "../fs/btrfs/async-thread.h"
63621+#include "../fs/btrfs/ctree.h"
63622+#include "../fs/btrfs/btrfs_inode.h"
63623+#endif
63624+
63625+static struct crash_uid *uid_set;
63626+static unsigned short uid_used;
63627+static DEFINE_SPINLOCK(gr_uid_lock);
63628+extern rwlock_t gr_inode_lock;
63629+extern struct acl_subject_label *
63630+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
63631+ struct acl_role_label *role);
63632+
63633+static inline dev_t __get_dev(const struct dentry *dentry)
63634+{
63635+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63636+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
63637+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
63638+ else
63639+#endif
63640+ return dentry->d_sb->s_dev;
63641+}
63642+
63643+int
63644+gr_init_uidset(void)
63645+{
63646+ uid_set =
63647+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
63648+ uid_used = 0;
63649+
63650+ return uid_set ? 1 : 0;
63651+}
63652+
63653+void
63654+gr_free_uidset(void)
63655+{
63656+ if (uid_set)
63657+ kfree(uid_set);
63658+
63659+ return;
63660+}
63661+
63662+int
63663+gr_find_uid(const uid_t uid)
63664+{
63665+ struct crash_uid *tmp = uid_set;
63666+ uid_t buid;
63667+ int low = 0, high = uid_used - 1, mid;
63668+
63669+ while (high >= low) {
63670+ mid = (low + high) >> 1;
63671+ buid = tmp[mid].uid;
63672+ if (buid == uid)
63673+ return mid;
63674+ if (buid > uid)
63675+ high = mid - 1;
63676+ if (buid < uid)
63677+ low = mid + 1;
63678+ }
63679+
63680+ return -1;
63681+}
63682+
63683+static __inline__ void
63684+gr_insertsort(void)
63685+{
63686+ unsigned short i, j;
63687+ struct crash_uid index;
63688+
63689+ for (i = 1; i < uid_used; i++) {
63690+ index = uid_set[i];
63691+ j = i;
63692+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
63693+ uid_set[j] = uid_set[j - 1];
63694+ j--;
63695+ }
63696+ uid_set[j] = index;
63697+ }
63698+
63699+ return;
63700+}
63701+
63702+static __inline__ void
63703+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
63704+{
63705+ int loc;
63706+ uid_t uid = GR_GLOBAL_UID(kuid);
63707+
63708+ if (uid_used == GR_UIDTABLE_MAX)
63709+ return;
63710+
63711+ loc = gr_find_uid(uid);
63712+
63713+ if (loc >= 0) {
63714+ uid_set[loc].expires = expires;
63715+ return;
63716+ }
63717+
63718+ uid_set[uid_used].uid = uid;
63719+ uid_set[uid_used].expires = expires;
63720+ uid_used++;
63721+
63722+ gr_insertsort();
63723+
63724+ return;
63725+}
63726+
63727+void
63728+gr_remove_uid(const unsigned short loc)
63729+{
63730+ unsigned short i;
63731+
63732+ for (i = loc + 1; i < uid_used; i++)
63733+ uid_set[i - 1] = uid_set[i];
63734+
63735+ uid_used--;
63736+
63737+ return;
63738+}
63739+
63740+int
63741+gr_check_crash_uid(const kuid_t kuid)
63742+{
63743+ int loc;
63744+ int ret = 0;
63745+ uid_t uid;
63746+
63747+ if (unlikely(!gr_acl_is_enabled()))
63748+ return 0;
63749+
63750+ uid = GR_GLOBAL_UID(kuid);
63751+
63752+ spin_lock(&gr_uid_lock);
63753+ loc = gr_find_uid(uid);
63754+
63755+ if (loc < 0)
63756+ goto out_unlock;
63757+
63758+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
63759+ gr_remove_uid(loc);
63760+ else
63761+ ret = 1;
63762+
63763+out_unlock:
63764+ spin_unlock(&gr_uid_lock);
63765+ return ret;
63766+}
63767+
63768+static __inline__ int
63769+proc_is_setxid(const struct cred *cred)
63770+{
63771+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
63772+ !uid_eq(cred->uid, cred->fsuid))
63773+ return 1;
63774+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
63775+ !gid_eq(cred->gid, cred->fsgid))
63776+ return 1;
63777+
63778+ return 0;
63779+}
63780+
63781+extern int gr_fake_force_sig(int sig, struct task_struct *t);
63782+
63783+void
63784+gr_handle_crash(struct task_struct *task, const int sig)
63785+{
63786+ struct acl_subject_label *curr;
63787+ struct task_struct *tsk, *tsk2;
63788+ const struct cred *cred;
63789+ const struct cred *cred2;
63790+
63791+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
63792+ return;
63793+
63794+ if (unlikely(!gr_acl_is_enabled()))
63795+ return;
63796+
63797+ curr = task->acl;
63798+
63799+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
63800+ return;
63801+
63802+ if (time_before_eq(curr->expires, get_seconds())) {
63803+ curr->expires = 0;
63804+ curr->crashes = 0;
63805+ }
63806+
63807+ curr->crashes++;
63808+
63809+ if (!curr->expires)
63810+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
63811+
63812+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63813+ time_after(curr->expires, get_seconds())) {
63814+ rcu_read_lock();
63815+ cred = __task_cred(task);
63816+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
63817+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63818+ spin_lock(&gr_uid_lock);
63819+ gr_insert_uid(cred->uid, curr->expires);
63820+ spin_unlock(&gr_uid_lock);
63821+ curr->expires = 0;
63822+ curr->crashes = 0;
63823+ read_lock(&tasklist_lock);
63824+ do_each_thread(tsk2, tsk) {
63825+ cred2 = __task_cred(tsk);
63826+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
63827+ gr_fake_force_sig(SIGKILL, tsk);
63828+ } while_each_thread(tsk2, tsk);
63829+ read_unlock(&tasklist_lock);
63830+ } else {
63831+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63832+ read_lock(&tasklist_lock);
63833+ read_lock(&grsec_exec_file_lock);
63834+ do_each_thread(tsk2, tsk) {
63835+ if (likely(tsk != task)) {
63836+ // if this thread has the same subject as the one that triggered
63837+ // RES_CRASH and it's the same binary, kill it
63838+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
63839+ gr_fake_force_sig(SIGKILL, tsk);
63840+ }
63841+ } while_each_thread(tsk2, tsk);
63842+ read_unlock(&grsec_exec_file_lock);
63843+ read_unlock(&tasklist_lock);
63844+ }
63845+ rcu_read_unlock();
63846+ }
63847+
63848+ return;
63849+}
63850+
63851+int
63852+gr_check_crash_exec(const struct file *filp)
63853+{
63854+ struct acl_subject_label *curr;
63855+
63856+ if (unlikely(!gr_acl_is_enabled()))
63857+ return 0;
63858+
63859+ read_lock(&gr_inode_lock);
63860+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
63861+ __get_dev(filp->f_path.dentry),
63862+ current->role);
63863+ read_unlock(&gr_inode_lock);
63864+
63865+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
63866+ (!curr->crashes && !curr->expires))
63867+ return 0;
63868+
63869+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63870+ time_after(curr->expires, get_seconds()))
63871+ return 1;
63872+ else if (time_before_eq(curr->expires, get_seconds())) {
63873+ curr->crashes = 0;
63874+ curr->expires = 0;
63875+ }
63876+
63877+ return 0;
63878+}
63879+
63880+void
63881+gr_handle_alertkill(struct task_struct *task)
63882+{
63883+ struct acl_subject_label *curracl;
63884+ __u32 curr_ip;
63885+ struct task_struct *p, *p2;
63886+
63887+ if (unlikely(!gr_acl_is_enabled()))
63888+ return;
63889+
63890+ curracl = task->acl;
63891+ curr_ip = task->signal->curr_ip;
63892+
63893+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
63894+ read_lock(&tasklist_lock);
63895+ do_each_thread(p2, p) {
63896+ if (p->signal->curr_ip == curr_ip)
63897+ gr_fake_force_sig(SIGKILL, p);
63898+ } while_each_thread(p2, p);
63899+ read_unlock(&tasklist_lock);
63900+ } else if (curracl->mode & GR_KILLPROC)
63901+ gr_fake_force_sig(SIGKILL, task);
63902+
63903+ return;
63904+}
63905diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
63906new file mode 100644
63907index 0000000..98011b0
63908--- /dev/null
63909+++ b/grsecurity/gracl_shm.c
63910@@ -0,0 +1,40 @@
63911+#include <linux/kernel.h>
63912+#include <linux/mm.h>
63913+#include <linux/sched.h>
63914+#include <linux/file.h>
63915+#include <linux/ipc.h>
63916+#include <linux/gracl.h>
63917+#include <linux/grsecurity.h>
63918+#include <linux/grinternal.h>
63919+
63920+int
63921+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63922+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63923+{
63924+ struct task_struct *task;
63925+
63926+ if (!gr_acl_is_enabled())
63927+ return 1;
63928+
63929+ rcu_read_lock();
63930+ read_lock(&tasklist_lock);
63931+
63932+ task = find_task_by_vpid(shm_cprid);
63933+
63934+ if (unlikely(!task))
63935+ task = find_task_by_vpid(shm_lapid);
63936+
63937+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
63938+ (task_pid_nr(task) == shm_lapid)) &&
63939+ (task->acl->mode & GR_PROTSHM) &&
63940+ (task->acl != current->acl))) {
63941+ read_unlock(&tasklist_lock);
63942+ rcu_read_unlock();
63943+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
63944+ return 0;
63945+ }
63946+ read_unlock(&tasklist_lock);
63947+ rcu_read_unlock();
63948+
63949+ return 1;
63950+}
63951diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
63952new file mode 100644
63953index 0000000..bc0be01
63954--- /dev/null
63955+++ b/grsecurity/grsec_chdir.c
63956@@ -0,0 +1,19 @@
63957+#include <linux/kernel.h>
63958+#include <linux/sched.h>
63959+#include <linux/fs.h>
63960+#include <linux/file.h>
63961+#include <linux/grsecurity.h>
63962+#include <linux/grinternal.h>
63963+
63964+void
63965+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
63966+{
63967+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63968+ if ((grsec_enable_chdir && grsec_enable_group &&
63969+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
63970+ !grsec_enable_group)) {
63971+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
63972+ }
63973+#endif
63974+ return;
63975+}
63976diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
63977new file mode 100644
63978index 0000000..bd6e105
63979--- /dev/null
63980+++ b/grsecurity/grsec_chroot.c
63981@@ -0,0 +1,370 @@
63982+#include <linux/kernel.h>
63983+#include <linux/module.h>
63984+#include <linux/sched.h>
63985+#include <linux/file.h>
63986+#include <linux/fs.h>
63987+#include <linux/mount.h>
63988+#include <linux/types.h>
63989+#include "../fs/mount.h"
63990+#include <linux/grsecurity.h>
63991+#include <linux/grinternal.h>
63992+
63993+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
63994+static int gr_init_ran;
63995+#endif
63996+
63997+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
63998+{
63999+#ifdef CONFIG_GRKERNSEC
64000+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
64001+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
64002+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64003+ && gr_init_ran
64004+#endif
64005+ )
64006+ task->gr_is_chrooted = 1;
64007+ else {
64008+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64009+ if (task_pid_nr(task) == 1 && !gr_init_ran)
64010+ gr_init_ran = 1;
64011+#endif
64012+ task->gr_is_chrooted = 0;
64013+ }
64014+
64015+ task->gr_chroot_dentry = path->dentry;
64016+#endif
64017+ return;
64018+}
64019+
64020+void gr_clear_chroot_entries(struct task_struct *task)
64021+{
64022+#ifdef CONFIG_GRKERNSEC
64023+ task->gr_is_chrooted = 0;
64024+ task->gr_chroot_dentry = NULL;
64025+#endif
64026+ return;
64027+}
64028+
64029+int
64030+gr_handle_chroot_unix(const pid_t pid)
64031+{
64032+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64033+ struct task_struct *p;
64034+
64035+ if (unlikely(!grsec_enable_chroot_unix))
64036+ return 1;
64037+
64038+ if (likely(!proc_is_chrooted(current)))
64039+ return 1;
64040+
64041+ rcu_read_lock();
64042+ read_lock(&tasklist_lock);
64043+ p = find_task_by_vpid_unrestricted(pid);
64044+ if (unlikely(p && !have_same_root(current, p))) {
64045+ read_unlock(&tasklist_lock);
64046+ rcu_read_unlock();
64047+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
64048+ return 0;
64049+ }
64050+ read_unlock(&tasklist_lock);
64051+ rcu_read_unlock();
64052+#endif
64053+ return 1;
64054+}
64055+
64056+int
64057+gr_handle_chroot_nice(void)
64058+{
64059+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64060+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
64061+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
64062+ return -EPERM;
64063+ }
64064+#endif
64065+ return 0;
64066+}
64067+
64068+int
64069+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
64070+{
64071+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64072+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
64073+ && proc_is_chrooted(current)) {
64074+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
64075+ return -EACCES;
64076+ }
64077+#endif
64078+ return 0;
64079+}
64080+
64081+int
64082+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
64083+{
64084+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64085+ struct task_struct *p;
64086+ int ret = 0;
64087+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
64088+ return ret;
64089+
64090+ read_lock(&tasklist_lock);
64091+ do_each_pid_task(pid, type, p) {
64092+ if (!have_same_root(current, p)) {
64093+ ret = 1;
64094+ goto out;
64095+ }
64096+ } while_each_pid_task(pid, type, p);
64097+out:
64098+ read_unlock(&tasklist_lock);
64099+ return ret;
64100+#endif
64101+ return 0;
64102+}
64103+
64104+int
64105+gr_pid_is_chrooted(struct task_struct *p)
64106+{
64107+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64108+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
64109+ return 0;
64110+
64111+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
64112+ !have_same_root(current, p)) {
64113+ return 1;
64114+ }
64115+#endif
64116+ return 0;
64117+}
64118+
64119+EXPORT_SYMBOL(gr_pid_is_chrooted);
64120+
64121+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
64122+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
64123+{
64124+ struct path path, currentroot;
64125+ int ret = 0;
64126+
64127+ path.dentry = (struct dentry *)u_dentry;
64128+ path.mnt = (struct vfsmount *)u_mnt;
64129+ get_fs_root(current->fs, &currentroot);
64130+ if (path_is_under(&path, &currentroot))
64131+ ret = 1;
64132+ path_put(&currentroot);
64133+
64134+ return ret;
64135+}
64136+#endif
64137+
64138+int
64139+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
64140+{
64141+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64142+ if (!grsec_enable_chroot_fchdir)
64143+ return 1;
64144+
64145+ if (!proc_is_chrooted(current))
64146+ return 1;
64147+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
64148+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
64149+ return 0;
64150+ }
64151+#endif
64152+ return 1;
64153+}
64154+
64155+int
64156+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64157+ const time_t shm_createtime)
64158+{
64159+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64160+ struct task_struct *p;
64161+ time_t starttime;
64162+
64163+ if (unlikely(!grsec_enable_chroot_shmat))
64164+ return 1;
64165+
64166+ if (likely(!proc_is_chrooted(current)))
64167+ return 1;
64168+
64169+ rcu_read_lock();
64170+ read_lock(&tasklist_lock);
64171+
64172+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
64173+ starttime = p->start_time.tv_sec;
64174+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
64175+ if (have_same_root(current, p)) {
64176+ goto allow;
64177+ } else {
64178+ read_unlock(&tasklist_lock);
64179+ rcu_read_unlock();
64180+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64181+ return 0;
64182+ }
64183+ }
64184+ /* creator exited, pid reuse, fall through to next check */
64185+ }
64186+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
64187+ if (unlikely(!have_same_root(current, p))) {
64188+ read_unlock(&tasklist_lock);
64189+ rcu_read_unlock();
64190+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64191+ return 0;
64192+ }
64193+ }
64194+
64195+allow:
64196+ read_unlock(&tasklist_lock);
64197+ rcu_read_unlock();
64198+#endif
64199+ return 1;
64200+}
64201+
64202+void
64203+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
64204+{
64205+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64206+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
64207+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
64208+#endif
64209+ return;
64210+}
64211+
64212+int
64213+gr_handle_chroot_mknod(const struct dentry *dentry,
64214+ const struct vfsmount *mnt, const int mode)
64215+{
64216+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64217+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
64218+ proc_is_chrooted(current)) {
64219+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
64220+ return -EPERM;
64221+ }
64222+#endif
64223+ return 0;
64224+}
64225+
64226+int
64227+gr_handle_chroot_mount(const struct dentry *dentry,
64228+ const struct vfsmount *mnt, const char *dev_name)
64229+{
64230+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64231+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
64232+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
64233+ return -EPERM;
64234+ }
64235+#endif
64236+ return 0;
64237+}
64238+
64239+int
64240+gr_handle_chroot_pivot(void)
64241+{
64242+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64243+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
64244+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
64245+ return -EPERM;
64246+ }
64247+#endif
64248+ return 0;
64249+}
64250+
64251+int
64252+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
64253+{
64254+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64255+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
64256+ !gr_is_outside_chroot(dentry, mnt)) {
64257+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
64258+ return -EPERM;
64259+ }
64260+#endif
64261+ return 0;
64262+}
64263+
64264+extern const char *captab_log[];
64265+extern int captab_log_entries;
64266+
64267+int
64268+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64269+{
64270+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64271+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64272+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64273+ if (cap_raised(chroot_caps, cap)) {
64274+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
64275+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
64276+ }
64277+ return 0;
64278+ }
64279+ }
64280+#endif
64281+ return 1;
64282+}
64283+
64284+int
64285+gr_chroot_is_capable(const int cap)
64286+{
64287+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64288+ return gr_task_chroot_is_capable(current, current_cred(), cap);
64289+#endif
64290+ return 1;
64291+}
64292+
64293+int
64294+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
64295+{
64296+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64297+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64298+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64299+ if (cap_raised(chroot_caps, cap)) {
64300+ return 0;
64301+ }
64302+ }
64303+#endif
64304+ return 1;
64305+}
64306+
64307+int
64308+gr_chroot_is_capable_nolog(const int cap)
64309+{
64310+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64311+ return gr_task_chroot_is_capable_nolog(current, cap);
64312+#endif
64313+ return 1;
64314+}
64315+
64316+int
64317+gr_handle_chroot_sysctl(const int op)
64318+{
64319+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64320+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
64321+ proc_is_chrooted(current))
64322+ return -EACCES;
64323+#endif
64324+ return 0;
64325+}
64326+
64327+void
64328+gr_handle_chroot_chdir(const struct path *path)
64329+{
64330+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64331+ if (grsec_enable_chroot_chdir)
64332+ set_fs_pwd(current->fs, path);
64333+#endif
64334+ return;
64335+}
64336+
64337+int
64338+gr_handle_chroot_chmod(const struct dentry *dentry,
64339+ const struct vfsmount *mnt, const int mode)
64340+{
64341+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64342+ /* allow chmod +s on directories, but not files */
64343+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
64344+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
64345+ proc_is_chrooted(current)) {
64346+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
64347+ return -EPERM;
64348+ }
64349+#endif
64350+ return 0;
64351+}
64352diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
64353new file mode 100644
64354index 0000000..ce65ceb
64355--- /dev/null
64356+++ b/grsecurity/grsec_disabled.c
64357@@ -0,0 +1,434 @@
64358+#include <linux/kernel.h>
64359+#include <linux/module.h>
64360+#include <linux/sched.h>
64361+#include <linux/file.h>
64362+#include <linux/fs.h>
64363+#include <linux/kdev_t.h>
64364+#include <linux/net.h>
64365+#include <linux/in.h>
64366+#include <linux/ip.h>
64367+#include <linux/skbuff.h>
64368+#include <linux/sysctl.h>
64369+
64370+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64371+void
64372+pax_set_initial_flags(struct linux_binprm *bprm)
64373+{
64374+ return;
64375+}
64376+#endif
64377+
64378+#ifdef CONFIG_SYSCTL
64379+__u32
64380+gr_handle_sysctl(const struct ctl_table * table, const int op)
64381+{
64382+ return 0;
64383+}
64384+#endif
64385+
64386+#ifdef CONFIG_TASKSTATS
64387+int gr_is_taskstats_denied(int pid)
64388+{
64389+ return 0;
64390+}
64391+#endif
64392+
64393+int
64394+gr_acl_is_enabled(void)
64395+{
64396+ return 0;
64397+}
64398+
64399+void
64400+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64401+{
64402+ return;
64403+}
64404+
64405+int
64406+gr_handle_rawio(const struct inode *inode)
64407+{
64408+ return 0;
64409+}
64410+
64411+void
64412+gr_acl_handle_psacct(struct task_struct *task, const long code)
64413+{
64414+ return;
64415+}
64416+
64417+int
64418+gr_handle_ptrace(struct task_struct *task, const long request)
64419+{
64420+ return 0;
64421+}
64422+
64423+int
64424+gr_handle_proc_ptrace(struct task_struct *task)
64425+{
64426+ return 0;
64427+}
64428+
64429+int
64430+gr_set_acls(const int type)
64431+{
64432+ return 0;
64433+}
64434+
64435+int
64436+gr_check_hidden_task(const struct task_struct *tsk)
64437+{
64438+ return 0;
64439+}
64440+
64441+int
64442+gr_check_protected_task(const struct task_struct *task)
64443+{
64444+ return 0;
64445+}
64446+
64447+int
64448+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64449+{
64450+ return 0;
64451+}
64452+
64453+void
64454+gr_copy_label(struct task_struct *tsk)
64455+{
64456+ return;
64457+}
64458+
64459+void
64460+gr_set_pax_flags(struct task_struct *task)
64461+{
64462+ return;
64463+}
64464+
64465+int
64466+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64467+ const int unsafe_share)
64468+{
64469+ return 0;
64470+}
64471+
64472+void
64473+gr_handle_delete(const ino_t ino, const dev_t dev)
64474+{
64475+ return;
64476+}
64477+
64478+void
64479+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64480+{
64481+ return;
64482+}
64483+
64484+void
64485+gr_handle_crash(struct task_struct *task, const int sig)
64486+{
64487+ return;
64488+}
64489+
64490+int
64491+gr_check_crash_exec(const struct file *filp)
64492+{
64493+ return 0;
64494+}
64495+
64496+int
64497+gr_check_crash_uid(const kuid_t uid)
64498+{
64499+ return 0;
64500+}
64501+
64502+void
64503+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64504+ struct dentry *old_dentry,
64505+ struct dentry *new_dentry,
64506+ struct vfsmount *mnt, const __u8 replace)
64507+{
64508+ return;
64509+}
64510+
64511+int
64512+gr_search_socket(const int family, const int type, const int protocol)
64513+{
64514+ return 1;
64515+}
64516+
64517+int
64518+gr_search_connectbind(const int mode, const struct socket *sock,
64519+ const struct sockaddr_in *addr)
64520+{
64521+ return 0;
64522+}
64523+
64524+void
64525+gr_handle_alertkill(struct task_struct *task)
64526+{
64527+ return;
64528+}
64529+
64530+__u32
64531+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
64532+{
64533+ return 1;
64534+}
64535+
64536+__u32
64537+gr_acl_handle_hidden_file(const struct dentry * dentry,
64538+ const struct vfsmount * mnt)
64539+{
64540+ return 1;
64541+}
64542+
64543+__u32
64544+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
64545+ int acc_mode)
64546+{
64547+ return 1;
64548+}
64549+
64550+__u32
64551+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
64552+{
64553+ return 1;
64554+}
64555+
64556+__u32
64557+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
64558+{
64559+ return 1;
64560+}
64561+
64562+int
64563+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
64564+ unsigned int *vm_flags)
64565+{
64566+ return 1;
64567+}
64568+
64569+__u32
64570+gr_acl_handle_truncate(const struct dentry * dentry,
64571+ const struct vfsmount * mnt)
64572+{
64573+ return 1;
64574+}
64575+
64576+__u32
64577+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
64578+{
64579+ return 1;
64580+}
64581+
64582+__u32
64583+gr_acl_handle_access(const struct dentry * dentry,
64584+ const struct vfsmount * mnt, const int fmode)
64585+{
64586+ return 1;
64587+}
64588+
64589+__u32
64590+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
64591+ umode_t *mode)
64592+{
64593+ return 1;
64594+}
64595+
64596+__u32
64597+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
64598+{
64599+ return 1;
64600+}
64601+
64602+__u32
64603+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
64604+{
64605+ return 1;
64606+}
64607+
64608+void
64609+grsecurity_init(void)
64610+{
64611+ return;
64612+}
64613+
64614+umode_t gr_acl_umask(void)
64615+{
64616+ return 0;
64617+}
64618+
64619+__u32
64620+gr_acl_handle_mknod(const struct dentry * new_dentry,
64621+ const struct dentry * parent_dentry,
64622+ const struct vfsmount * parent_mnt,
64623+ const int mode)
64624+{
64625+ return 1;
64626+}
64627+
64628+__u32
64629+gr_acl_handle_mkdir(const struct dentry * new_dentry,
64630+ const struct dentry * parent_dentry,
64631+ const struct vfsmount * parent_mnt)
64632+{
64633+ return 1;
64634+}
64635+
64636+__u32
64637+gr_acl_handle_symlink(const struct dentry * new_dentry,
64638+ const struct dentry * parent_dentry,
64639+ const struct vfsmount * parent_mnt, const struct filename *from)
64640+{
64641+ return 1;
64642+}
64643+
64644+__u32
64645+gr_acl_handle_link(const struct dentry * new_dentry,
64646+ const struct dentry * parent_dentry,
64647+ const struct vfsmount * parent_mnt,
64648+ const struct dentry * old_dentry,
64649+ const struct vfsmount * old_mnt, const struct filename *to)
64650+{
64651+ return 1;
64652+}
64653+
64654+int
64655+gr_acl_handle_rename(const struct dentry *new_dentry,
64656+ const struct dentry *parent_dentry,
64657+ const struct vfsmount *parent_mnt,
64658+ const struct dentry *old_dentry,
64659+ const struct inode *old_parent_inode,
64660+ const struct vfsmount *old_mnt, const struct filename *newname)
64661+{
64662+ return 0;
64663+}
64664+
64665+int
64666+gr_acl_handle_filldir(const struct file *file, const char *name,
64667+ const int namelen, const ino_t ino)
64668+{
64669+ return 1;
64670+}
64671+
64672+int
64673+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64674+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64675+{
64676+ return 1;
64677+}
64678+
64679+int
64680+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
64681+{
64682+ return 0;
64683+}
64684+
64685+int
64686+gr_search_accept(const struct socket *sock)
64687+{
64688+ return 0;
64689+}
64690+
64691+int
64692+gr_search_listen(const struct socket *sock)
64693+{
64694+ return 0;
64695+}
64696+
64697+int
64698+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
64699+{
64700+ return 0;
64701+}
64702+
64703+__u32
64704+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
64705+{
64706+ return 1;
64707+}
64708+
64709+__u32
64710+gr_acl_handle_creat(const struct dentry * dentry,
64711+ const struct dentry * p_dentry,
64712+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
64713+ const int imode)
64714+{
64715+ return 1;
64716+}
64717+
64718+void
64719+gr_acl_handle_exit(void)
64720+{
64721+ return;
64722+}
64723+
64724+int
64725+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
64726+{
64727+ return 1;
64728+}
64729+
64730+void
64731+gr_set_role_label(const kuid_t uid, const kgid_t gid)
64732+{
64733+ return;
64734+}
64735+
64736+int
64737+gr_acl_handle_procpidmem(const struct task_struct *task)
64738+{
64739+ return 0;
64740+}
64741+
64742+int
64743+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
64744+{
64745+ return 0;
64746+}
64747+
64748+int
64749+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
64750+{
64751+ return 0;
64752+}
64753+
64754+void
64755+gr_set_kernel_label(struct task_struct *task)
64756+{
64757+ return;
64758+}
64759+
64760+int
64761+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64762+{
64763+ return 0;
64764+}
64765+
64766+int
64767+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64768+{
64769+ return 0;
64770+}
64771+
64772+int gr_acl_enable_at_secure(void)
64773+{
64774+ return 0;
64775+}
64776+
64777+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
64778+{
64779+ return dentry->d_sb->s_dev;
64780+}
64781+
64782+void gr_put_exec_file(struct task_struct *task)
64783+{
64784+ return;
64785+}
64786+
64787+EXPORT_SYMBOL(gr_set_kernel_label);
64788+#ifdef CONFIG_SECURITY
64789+EXPORT_SYMBOL(gr_check_user_change);
64790+EXPORT_SYMBOL(gr_check_group_change);
64791+#endif
64792diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
64793new file mode 100644
64794index 0000000..387032b
64795--- /dev/null
64796+++ b/grsecurity/grsec_exec.c
64797@@ -0,0 +1,187 @@
64798+#include <linux/kernel.h>
64799+#include <linux/sched.h>
64800+#include <linux/file.h>
64801+#include <linux/binfmts.h>
64802+#include <linux/fs.h>
64803+#include <linux/types.h>
64804+#include <linux/grdefs.h>
64805+#include <linux/grsecurity.h>
64806+#include <linux/grinternal.h>
64807+#include <linux/capability.h>
64808+#include <linux/module.h>
64809+#include <linux/compat.h>
64810+
64811+#include <asm/uaccess.h>
64812+
64813+#ifdef CONFIG_GRKERNSEC_EXECLOG
64814+static char gr_exec_arg_buf[132];
64815+static DEFINE_MUTEX(gr_exec_arg_mutex);
64816+#endif
64817+
64818+struct user_arg_ptr {
64819+#ifdef CONFIG_COMPAT
64820+ bool is_compat;
64821+#endif
64822+ union {
64823+ const char __user *const __user *native;
64824+#ifdef CONFIG_COMPAT
64825+ const compat_uptr_t __user *compat;
64826+#endif
64827+ } ptr;
64828+};
64829+
64830+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
64831+
64832+void
64833+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
64834+{
64835+#ifdef CONFIG_GRKERNSEC_EXECLOG
64836+ char *grarg = gr_exec_arg_buf;
64837+ unsigned int i, x, execlen = 0;
64838+ char c;
64839+
64840+ if (!((grsec_enable_execlog && grsec_enable_group &&
64841+ in_group_p(grsec_audit_gid))
64842+ || (grsec_enable_execlog && !grsec_enable_group)))
64843+ return;
64844+
64845+ mutex_lock(&gr_exec_arg_mutex);
64846+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
64847+
64848+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
64849+ const char __user *p;
64850+ unsigned int len;
64851+
64852+ p = get_user_arg_ptr(argv, i);
64853+ if (IS_ERR(p))
64854+ goto log;
64855+
64856+ len = strnlen_user(p, 128 - execlen);
64857+ if (len > 128 - execlen)
64858+ len = 128 - execlen;
64859+ else if (len > 0)
64860+ len--;
64861+ if (copy_from_user(grarg + execlen, p, len))
64862+ goto log;
64863+
64864+ /* rewrite unprintable characters */
64865+ for (x = 0; x < len; x++) {
64866+ c = *(grarg + execlen + x);
64867+ if (c < 32 || c > 126)
64868+ *(grarg + execlen + x) = ' ';
64869+ }
64870+
64871+ execlen += len;
64872+ *(grarg + execlen) = ' ';
64873+ *(grarg + execlen + 1) = '\0';
64874+ execlen++;
64875+ }
64876+
64877+ log:
64878+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
64879+ bprm->file->f_path.mnt, grarg);
64880+ mutex_unlock(&gr_exec_arg_mutex);
64881+#endif
64882+ return;
64883+}
64884+
64885+#ifdef CONFIG_GRKERNSEC
64886+extern int gr_acl_is_capable(const int cap);
64887+extern int gr_acl_is_capable_nolog(const int cap);
64888+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64889+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
64890+extern int gr_chroot_is_capable(const int cap);
64891+extern int gr_chroot_is_capable_nolog(const int cap);
64892+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64893+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
64894+#endif
64895+
64896+const char *captab_log[] = {
64897+ "CAP_CHOWN",
64898+ "CAP_DAC_OVERRIDE",
64899+ "CAP_DAC_READ_SEARCH",
64900+ "CAP_FOWNER",
64901+ "CAP_FSETID",
64902+ "CAP_KILL",
64903+ "CAP_SETGID",
64904+ "CAP_SETUID",
64905+ "CAP_SETPCAP",
64906+ "CAP_LINUX_IMMUTABLE",
64907+ "CAP_NET_BIND_SERVICE",
64908+ "CAP_NET_BROADCAST",
64909+ "CAP_NET_ADMIN",
64910+ "CAP_NET_RAW",
64911+ "CAP_IPC_LOCK",
64912+ "CAP_IPC_OWNER",
64913+ "CAP_SYS_MODULE",
64914+ "CAP_SYS_RAWIO",
64915+ "CAP_SYS_CHROOT",
64916+ "CAP_SYS_PTRACE",
64917+ "CAP_SYS_PACCT",
64918+ "CAP_SYS_ADMIN",
64919+ "CAP_SYS_BOOT",
64920+ "CAP_SYS_NICE",
64921+ "CAP_SYS_RESOURCE",
64922+ "CAP_SYS_TIME",
64923+ "CAP_SYS_TTY_CONFIG",
64924+ "CAP_MKNOD",
64925+ "CAP_LEASE",
64926+ "CAP_AUDIT_WRITE",
64927+ "CAP_AUDIT_CONTROL",
64928+ "CAP_SETFCAP",
64929+ "CAP_MAC_OVERRIDE",
64930+ "CAP_MAC_ADMIN",
64931+ "CAP_SYSLOG",
64932+ "CAP_WAKE_ALARM"
64933+};
64934+
64935+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
64936+
64937+int gr_is_capable(const int cap)
64938+{
64939+#ifdef CONFIG_GRKERNSEC
64940+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
64941+ return 1;
64942+ return 0;
64943+#else
64944+ return 1;
64945+#endif
64946+}
64947+
64948+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64949+{
64950+#ifdef CONFIG_GRKERNSEC
64951+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
64952+ return 1;
64953+ return 0;
64954+#else
64955+ return 1;
64956+#endif
64957+}
64958+
64959+int gr_is_capable_nolog(const int cap)
64960+{
64961+#ifdef CONFIG_GRKERNSEC
64962+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
64963+ return 1;
64964+ return 0;
64965+#else
64966+ return 1;
64967+#endif
64968+}
64969+
64970+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
64971+{
64972+#ifdef CONFIG_GRKERNSEC
64973+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
64974+ return 1;
64975+ return 0;
64976+#else
64977+ return 1;
64978+#endif
64979+}
64980+
64981+EXPORT_SYMBOL(gr_is_capable);
64982+EXPORT_SYMBOL(gr_is_capable_nolog);
64983+EXPORT_SYMBOL(gr_task_is_capable);
64984+EXPORT_SYMBOL(gr_task_is_capable_nolog);
64985diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
64986new file mode 100644
64987index 0000000..06cc6ea
64988--- /dev/null
64989+++ b/grsecurity/grsec_fifo.c
64990@@ -0,0 +1,24 @@
64991+#include <linux/kernel.h>
64992+#include <linux/sched.h>
64993+#include <linux/fs.h>
64994+#include <linux/file.h>
64995+#include <linux/grinternal.h>
64996+
64997+int
64998+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
64999+ const struct dentry *dir, const int flag, const int acc_mode)
65000+{
65001+#ifdef CONFIG_GRKERNSEC_FIFO
65002+ const struct cred *cred = current_cred();
65003+
65004+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
65005+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
65006+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
65007+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
65008+ if (!inode_permission(dentry->d_inode, acc_mode))
65009+ 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));
65010+ return -EACCES;
65011+ }
65012+#endif
65013+ return 0;
65014+}
65015diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
65016new file mode 100644
65017index 0000000..8ca18bf
65018--- /dev/null
65019+++ b/grsecurity/grsec_fork.c
65020@@ -0,0 +1,23 @@
65021+#include <linux/kernel.h>
65022+#include <linux/sched.h>
65023+#include <linux/grsecurity.h>
65024+#include <linux/grinternal.h>
65025+#include <linux/errno.h>
65026+
65027+void
65028+gr_log_forkfail(const int retval)
65029+{
65030+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65031+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
65032+ switch (retval) {
65033+ case -EAGAIN:
65034+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
65035+ break;
65036+ case -ENOMEM:
65037+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
65038+ break;
65039+ }
65040+ }
65041+#endif
65042+ return;
65043+}
65044diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
65045new file mode 100644
65046index 0000000..a862e9f
65047--- /dev/null
65048+++ b/grsecurity/grsec_init.c
65049@@ -0,0 +1,283 @@
65050+#include <linux/kernel.h>
65051+#include <linux/sched.h>
65052+#include <linux/mm.h>
65053+#include <linux/gracl.h>
65054+#include <linux/slab.h>
65055+#include <linux/vmalloc.h>
65056+#include <linux/percpu.h>
65057+#include <linux/module.h>
65058+
65059+int grsec_enable_ptrace_readexec;
65060+int grsec_enable_setxid;
65061+int grsec_enable_symlinkown;
65062+kgid_t grsec_symlinkown_gid;
65063+int grsec_enable_brute;
65064+int grsec_enable_link;
65065+int grsec_enable_dmesg;
65066+int grsec_enable_harden_ptrace;
65067+int grsec_enable_fifo;
65068+int grsec_enable_execlog;
65069+int grsec_enable_signal;
65070+int grsec_enable_forkfail;
65071+int grsec_enable_audit_ptrace;
65072+int grsec_enable_time;
65073+int grsec_enable_audit_textrel;
65074+int grsec_enable_group;
65075+kgid_t grsec_audit_gid;
65076+int grsec_enable_chdir;
65077+int grsec_enable_mount;
65078+int grsec_enable_rofs;
65079+int grsec_enable_chroot_findtask;
65080+int grsec_enable_chroot_mount;
65081+int grsec_enable_chroot_shmat;
65082+int grsec_enable_chroot_fchdir;
65083+int grsec_enable_chroot_double;
65084+int grsec_enable_chroot_pivot;
65085+int grsec_enable_chroot_chdir;
65086+int grsec_enable_chroot_chmod;
65087+int grsec_enable_chroot_mknod;
65088+int grsec_enable_chroot_nice;
65089+int grsec_enable_chroot_execlog;
65090+int grsec_enable_chroot_caps;
65091+int grsec_enable_chroot_sysctl;
65092+int grsec_enable_chroot_unix;
65093+int grsec_enable_tpe;
65094+kgid_t grsec_tpe_gid;
65095+int grsec_enable_blackhole;
65096+#ifdef CONFIG_IPV6_MODULE
65097+EXPORT_SYMBOL(grsec_enable_blackhole);
65098+#endif
65099+int grsec_lastack_retries;
65100+int grsec_enable_tpe_all;
65101+int grsec_enable_tpe_invert;
65102+int grsec_enable_socket_all;
65103+kgid_t grsec_socket_all_gid;
65104+int grsec_enable_socket_client;
65105+kgid_t grsec_socket_client_gid;
65106+int grsec_enable_socket_server;
65107+kgid_t grsec_socket_server_gid;
65108+int grsec_resource_logging;
65109+int grsec_disable_privio;
65110+int grsec_enable_log_rwxmaps;
65111+int grsec_lock;
65112+
65113+DEFINE_SPINLOCK(grsec_alert_lock);
65114+unsigned long grsec_alert_wtime = 0;
65115+unsigned long grsec_alert_fyet = 0;
65116+
65117+DEFINE_SPINLOCK(grsec_audit_lock);
65118+
65119+DEFINE_RWLOCK(grsec_exec_file_lock);
65120+
65121+char *gr_shared_page[4];
65122+
65123+char *gr_alert_log_fmt;
65124+char *gr_audit_log_fmt;
65125+char *gr_alert_log_buf;
65126+char *gr_audit_log_buf;
65127+
65128+extern struct gr_arg *gr_usermode;
65129+extern unsigned char *gr_system_salt;
65130+extern unsigned char *gr_system_sum;
65131+
65132+void __init
65133+grsecurity_init(void)
65134+{
65135+ int j;
65136+ /* create the per-cpu shared pages */
65137+
65138+#ifdef CONFIG_X86
65139+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
65140+#endif
65141+
65142+ for (j = 0; j < 4; j++) {
65143+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
65144+ if (gr_shared_page[j] == NULL) {
65145+ panic("Unable to allocate grsecurity shared page");
65146+ return;
65147+ }
65148+ }
65149+
65150+ /* allocate log buffers */
65151+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
65152+ if (!gr_alert_log_fmt) {
65153+ panic("Unable to allocate grsecurity alert log format buffer");
65154+ return;
65155+ }
65156+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
65157+ if (!gr_audit_log_fmt) {
65158+ panic("Unable to allocate grsecurity audit log format buffer");
65159+ return;
65160+ }
65161+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65162+ if (!gr_alert_log_buf) {
65163+ panic("Unable to allocate grsecurity alert log buffer");
65164+ return;
65165+ }
65166+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65167+ if (!gr_audit_log_buf) {
65168+ panic("Unable to allocate grsecurity audit log buffer");
65169+ return;
65170+ }
65171+
65172+ /* allocate memory for authentication structure */
65173+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
65174+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
65175+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
65176+
65177+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
65178+ panic("Unable to allocate grsecurity authentication structure");
65179+ return;
65180+ }
65181+
65182+
65183+#ifdef CONFIG_GRKERNSEC_IO
65184+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
65185+ grsec_disable_privio = 1;
65186+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65187+ grsec_disable_privio = 1;
65188+#else
65189+ grsec_disable_privio = 0;
65190+#endif
65191+#endif
65192+
65193+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65194+ /* for backward compatibility, tpe_invert always defaults to on if
65195+ enabled in the kernel
65196+ */
65197+ grsec_enable_tpe_invert = 1;
65198+#endif
65199+
65200+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65201+#ifndef CONFIG_GRKERNSEC_SYSCTL
65202+ grsec_lock = 1;
65203+#endif
65204+
65205+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65206+ grsec_enable_audit_textrel = 1;
65207+#endif
65208+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65209+ grsec_enable_log_rwxmaps = 1;
65210+#endif
65211+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65212+ grsec_enable_group = 1;
65213+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
65214+#endif
65215+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65216+ grsec_enable_ptrace_readexec = 1;
65217+#endif
65218+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65219+ grsec_enable_chdir = 1;
65220+#endif
65221+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65222+ grsec_enable_harden_ptrace = 1;
65223+#endif
65224+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65225+ grsec_enable_mount = 1;
65226+#endif
65227+#ifdef CONFIG_GRKERNSEC_LINK
65228+ grsec_enable_link = 1;
65229+#endif
65230+#ifdef CONFIG_GRKERNSEC_BRUTE
65231+ grsec_enable_brute = 1;
65232+#endif
65233+#ifdef CONFIG_GRKERNSEC_DMESG
65234+ grsec_enable_dmesg = 1;
65235+#endif
65236+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65237+ grsec_enable_blackhole = 1;
65238+ grsec_lastack_retries = 4;
65239+#endif
65240+#ifdef CONFIG_GRKERNSEC_FIFO
65241+ grsec_enable_fifo = 1;
65242+#endif
65243+#ifdef CONFIG_GRKERNSEC_EXECLOG
65244+ grsec_enable_execlog = 1;
65245+#endif
65246+#ifdef CONFIG_GRKERNSEC_SETXID
65247+ grsec_enable_setxid = 1;
65248+#endif
65249+#ifdef CONFIG_GRKERNSEC_SIGNAL
65250+ grsec_enable_signal = 1;
65251+#endif
65252+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65253+ grsec_enable_forkfail = 1;
65254+#endif
65255+#ifdef CONFIG_GRKERNSEC_TIME
65256+ grsec_enable_time = 1;
65257+#endif
65258+#ifdef CONFIG_GRKERNSEC_RESLOG
65259+ grsec_resource_logging = 1;
65260+#endif
65261+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65262+ grsec_enable_chroot_findtask = 1;
65263+#endif
65264+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65265+ grsec_enable_chroot_unix = 1;
65266+#endif
65267+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65268+ grsec_enable_chroot_mount = 1;
65269+#endif
65270+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65271+ grsec_enable_chroot_fchdir = 1;
65272+#endif
65273+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65274+ grsec_enable_chroot_shmat = 1;
65275+#endif
65276+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65277+ grsec_enable_audit_ptrace = 1;
65278+#endif
65279+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65280+ grsec_enable_chroot_double = 1;
65281+#endif
65282+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65283+ grsec_enable_chroot_pivot = 1;
65284+#endif
65285+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65286+ grsec_enable_chroot_chdir = 1;
65287+#endif
65288+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65289+ grsec_enable_chroot_chmod = 1;
65290+#endif
65291+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65292+ grsec_enable_chroot_mknod = 1;
65293+#endif
65294+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65295+ grsec_enable_chroot_nice = 1;
65296+#endif
65297+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65298+ grsec_enable_chroot_execlog = 1;
65299+#endif
65300+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65301+ grsec_enable_chroot_caps = 1;
65302+#endif
65303+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65304+ grsec_enable_chroot_sysctl = 1;
65305+#endif
65306+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65307+ grsec_enable_symlinkown = 1;
65308+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
65309+#endif
65310+#ifdef CONFIG_GRKERNSEC_TPE
65311+ grsec_enable_tpe = 1;
65312+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
65313+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65314+ grsec_enable_tpe_all = 1;
65315+#endif
65316+#endif
65317+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65318+ grsec_enable_socket_all = 1;
65319+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
65320+#endif
65321+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65322+ grsec_enable_socket_client = 1;
65323+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
65324+#endif
65325+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65326+ grsec_enable_socket_server = 1;
65327+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
65328+#endif
65329+#endif
65330+
65331+ return;
65332+}
65333diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
65334new file mode 100644
65335index 0000000..5e05e20
65336--- /dev/null
65337+++ b/grsecurity/grsec_link.c
65338@@ -0,0 +1,58 @@
65339+#include <linux/kernel.h>
65340+#include <linux/sched.h>
65341+#include <linux/fs.h>
65342+#include <linux/file.h>
65343+#include <linux/grinternal.h>
65344+
65345+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
65346+{
65347+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65348+ const struct inode *link_inode = link->dentry->d_inode;
65349+
65350+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
65351+ /* ignore root-owned links, e.g. /proc/self */
65352+ gr_is_global_nonroot(link_inode->i_uid) && target &&
65353+ !uid_eq(link_inode->i_uid, target->i_uid)) {
65354+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
65355+ return 1;
65356+ }
65357+#endif
65358+ return 0;
65359+}
65360+
65361+int
65362+gr_handle_follow_link(const struct inode *parent,
65363+ const struct inode *inode,
65364+ const struct dentry *dentry, const struct vfsmount *mnt)
65365+{
65366+#ifdef CONFIG_GRKERNSEC_LINK
65367+ const struct cred *cred = current_cred();
65368+
65369+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
65370+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
65371+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
65372+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
65373+ return -EACCES;
65374+ }
65375+#endif
65376+ return 0;
65377+}
65378+
65379+int
65380+gr_handle_hardlink(const struct dentry *dentry,
65381+ const struct vfsmount *mnt,
65382+ struct inode *inode, const int mode, const struct filename *to)
65383+{
65384+#ifdef CONFIG_GRKERNSEC_LINK
65385+ const struct cred *cred = current_cred();
65386+
65387+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
65388+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
65389+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
65390+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
65391+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
65392+ return -EPERM;
65393+ }
65394+#endif
65395+ return 0;
65396+}
65397diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
65398new file mode 100644
65399index 0000000..7c06085
65400--- /dev/null
65401+++ b/grsecurity/grsec_log.c
65402@@ -0,0 +1,326 @@
65403+#include <linux/kernel.h>
65404+#include <linux/sched.h>
65405+#include <linux/file.h>
65406+#include <linux/tty.h>
65407+#include <linux/fs.h>
65408+#include <linux/grinternal.h>
65409+
65410+#ifdef CONFIG_TREE_PREEMPT_RCU
65411+#define DISABLE_PREEMPT() preempt_disable()
65412+#define ENABLE_PREEMPT() preempt_enable()
65413+#else
65414+#define DISABLE_PREEMPT()
65415+#define ENABLE_PREEMPT()
65416+#endif
65417+
65418+#define BEGIN_LOCKS(x) \
65419+ DISABLE_PREEMPT(); \
65420+ rcu_read_lock(); \
65421+ read_lock(&tasklist_lock); \
65422+ read_lock(&grsec_exec_file_lock); \
65423+ if (x != GR_DO_AUDIT) \
65424+ spin_lock(&grsec_alert_lock); \
65425+ else \
65426+ spin_lock(&grsec_audit_lock)
65427+
65428+#define END_LOCKS(x) \
65429+ if (x != GR_DO_AUDIT) \
65430+ spin_unlock(&grsec_alert_lock); \
65431+ else \
65432+ spin_unlock(&grsec_audit_lock); \
65433+ read_unlock(&grsec_exec_file_lock); \
65434+ read_unlock(&tasklist_lock); \
65435+ rcu_read_unlock(); \
65436+ ENABLE_PREEMPT(); \
65437+ if (x == GR_DONT_AUDIT) \
65438+ gr_handle_alertkill(current)
65439+
65440+enum {
65441+ FLOODING,
65442+ NO_FLOODING
65443+};
65444+
65445+extern char *gr_alert_log_fmt;
65446+extern char *gr_audit_log_fmt;
65447+extern char *gr_alert_log_buf;
65448+extern char *gr_audit_log_buf;
65449+
65450+static int gr_log_start(int audit)
65451+{
65452+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
65453+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
65454+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65455+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
65456+ unsigned long curr_secs = get_seconds();
65457+
65458+ if (audit == GR_DO_AUDIT)
65459+ goto set_fmt;
65460+
65461+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
65462+ grsec_alert_wtime = curr_secs;
65463+ grsec_alert_fyet = 0;
65464+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
65465+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
65466+ grsec_alert_fyet++;
65467+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
65468+ grsec_alert_wtime = curr_secs;
65469+ grsec_alert_fyet++;
65470+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
65471+ return FLOODING;
65472+ }
65473+ else return FLOODING;
65474+
65475+set_fmt:
65476+#endif
65477+ memset(buf, 0, PAGE_SIZE);
65478+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
65479+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
65480+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65481+ } else if (current->signal->curr_ip) {
65482+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
65483+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
65484+ } else if (gr_acl_is_enabled()) {
65485+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
65486+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65487+ } else {
65488+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
65489+ strcpy(buf, fmt);
65490+ }
65491+
65492+ return NO_FLOODING;
65493+}
65494+
65495+static void gr_log_middle(int audit, const char *msg, va_list ap)
65496+ __attribute__ ((format (printf, 2, 0)));
65497+
65498+static void gr_log_middle(int audit, const char *msg, va_list ap)
65499+{
65500+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65501+ unsigned int len = strlen(buf);
65502+
65503+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65504+
65505+ return;
65506+}
65507+
65508+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65509+ __attribute__ ((format (printf, 2, 3)));
65510+
65511+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65512+{
65513+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65514+ unsigned int len = strlen(buf);
65515+ va_list ap;
65516+
65517+ va_start(ap, msg);
65518+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65519+ va_end(ap);
65520+
65521+ return;
65522+}
65523+
65524+static void gr_log_end(int audit, int append_default)
65525+{
65526+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65527+ if (append_default) {
65528+ struct task_struct *task = current;
65529+ struct task_struct *parent = task->real_parent;
65530+ const struct cred *cred = __task_cred(task);
65531+ const struct cred *pcred = __task_cred(parent);
65532+ unsigned int len = strlen(buf);
65533+
65534+ 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));
65535+ }
65536+
65537+ printk("%s\n", buf);
65538+
65539+ return;
65540+}
65541+
65542+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
65543+{
65544+ int logtype;
65545+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
65546+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
65547+ void *voidptr = NULL;
65548+ int num1 = 0, num2 = 0;
65549+ unsigned long ulong1 = 0, ulong2 = 0;
65550+ struct dentry *dentry = NULL;
65551+ struct vfsmount *mnt = NULL;
65552+ struct file *file = NULL;
65553+ struct task_struct *task = NULL;
65554+ const struct cred *cred, *pcred;
65555+ va_list ap;
65556+
65557+ BEGIN_LOCKS(audit);
65558+ logtype = gr_log_start(audit);
65559+ if (logtype == FLOODING) {
65560+ END_LOCKS(audit);
65561+ return;
65562+ }
65563+ va_start(ap, argtypes);
65564+ switch (argtypes) {
65565+ case GR_TTYSNIFF:
65566+ task = va_arg(ap, struct task_struct *);
65567+ 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));
65568+ break;
65569+ case GR_SYSCTL_HIDDEN:
65570+ str1 = va_arg(ap, char *);
65571+ gr_log_middle_varargs(audit, msg, result, str1);
65572+ break;
65573+ case GR_RBAC:
65574+ dentry = va_arg(ap, struct dentry *);
65575+ mnt = va_arg(ap, struct vfsmount *);
65576+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
65577+ break;
65578+ case GR_RBAC_STR:
65579+ dentry = va_arg(ap, struct dentry *);
65580+ mnt = va_arg(ap, struct vfsmount *);
65581+ str1 = va_arg(ap, char *);
65582+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
65583+ break;
65584+ case GR_STR_RBAC:
65585+ str1 = va_arg(ap, char *);
65586+ dentry = va_arg(ap, struct dentry *);
65587+ mnt = va_arg(ap, struct vfsmount *);
65588+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
65589+ break;
65590+ case GR_RBAC_MODE2:
65591+ dentry = va_arg(ap, struct dentry *);
65592+ mnt = va_arg(ap, struct vfsmount *);
65593+ str1 = va_arg(ap, char *);
65594+ str2 = va_arg(ap, char *);
65595+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
65596+ break;
65597+ case GR_RBAC_MODE3:
65598+ dentry = va_arg(ap, struct dentry *);
65599+ mnt = va_arg(ap, struct vfsmount *);
65600+ str1 = va_arg(ap, char *);
65601+ str2 = va_arg(ap, char *);
65602+ str3 = va_arg(ap, char *);
65603+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
65604+ break;
65605+ case GR_FILENAME:
65606+ dentry = va_arg(ap, struct dentry *);
65607+ mnt = va_arg(ap, struct vfsmount *);
65608+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
65609+ break;
65610+ case GR_STR_FILENAME:
65611+ str1 = va_arg(ap, char *);
65612+ dentry = va_arg(ap, struct dentry *);
65613+ mnt = va_arg(ap, struct vfsmount *);
65614+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
65615+ break;
65616+ case GR_FILENAME_STR:
65617+ dentry = va_arg(ap, struct dentry *);
65618+ mnt = va_arg(ap, struct vfsmount *);
65619+ str1 = va_arg(ap, char *);
65620+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
65621+ break;
65622+ case GR_FILENAME_TWO_INT:
65623+ dentry = va_arg(ap, struct dentry *);
65624+ mnt = va_arg(ap, struct vfsmount *);
65625+ num1 = va_arg(ap, int);
65626+ num2 = va_arg(ap, int);
65627+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
65628+ break;
65629+ case GR_FILENAME_TWO_INT_STR:
65630+ dentry = va_arg(ap, struct dentry *);
65631+ mnt = va_arg(ap, struct vfsmount *);
65632+ num1 = va_arg(ap, int);
65633+ num2 = va_arg(ap, int);
65634+ str1 = va_arg(ap, char *);
65635+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
65636+ break;
65637+ case GR_TEXTREL:
65638+ file = va_arg(ap, struct file *);
65639+ ulong1 = va_arg(ap, unsigned long);
65640+ ulong2 = va_arg(ap, unsigned long);
65641+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
65642+ break;
65643+ case GR_PTRACE:
65644+ task = va_arg(ap, struct task_struct *);
65645+ 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));
65646+ break;
65647+ case GR_RESOURCE:
65648+ task = va_arg(ap, struct task_struct *);
65649+ cred = __task_cred(task);
65650+ pcred = __task_cred(task->real_parent);
65651+ ulong1 = va_arg(ap, unsigned long);
65652+ str1 = va_arg(ap, char *);
65653+ ulong2 = va_arg(ap, unsigned long);
65654+ 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));
65655+ break;
65656+ case GR_CAP:
65657+ task = va_arg(ap, struct task_struct *);
65658+ cred = __task_cred(task);
65659+ pcred = __task_cred(task->real_parent);
65660+ str1 = va_arg(ap, char *);
65661+ 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));
65662+ break;
65663+ case GR_SIG:
65664+ str1 = va_arg(ap, char *);
65665+ voidptr = va_arg(ap, void *);
65666+ gr_log_middle_varargs(audit, msg, str1, voidptr);
65667+ break;
65668+ case GR_SIG2:
65669+ task = va_arg(ap, struct task_struct *);
65670+ cred = __task_cred(task);
65671+ pcred = __task_cred(task->real_parent);
65672+ num1 = va_arg(ap, int);
65673+ 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));
65674+ break;
65675+ case GR_CRASH1:
65676+ task = va_arg(ap, struct task_struct *);
65677+ cred = __task_cred(task);
65678+ pcred = __task_cred(task->real_parent);
65679+ ulong1 = va_arg(ap, unsigned long);
65680+ 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);
65681+ break;
65682+ case GR_CRASH2:
65683+ task = va_arg(ap, struct task_struct *);
65684+ cred = __task_cred(task);
65685+ pcred = __task_cred(task->real_parent);
65686+ ulong1 = va_arg(ap, unsigned long);
65687+ 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);
65688+ break;
65689+ case GR_RWXMAP:
65690+ file = va_arg(ap, struct file *);
65691+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
65692+ break;
65693+ case GR_PSACCT:
65694+ {
65695+ unsigned int wday, cday;
65696+ __u8 whr, chr;
65697+ __u8 wmin, cmin;
65698+ __u8 wsec, csec;
65699+ char cur_tty[64] = { 0 };
65700+ char parent_tty[64] = { 0 };
65701+
65702+ task = va_arg(ap, struct task_struct *);
65703+ wday = va_arg(ap, unsigned int);
65704+ cday = va_arg(ap, unsigned int);
65705+ whr = va_arg(ap, int);
65706+ chr = va_arg(ap, int);
65707+ wmin = va_arg(ap, int);
65708+ cmin = va_arg(ap, int);
65709+ wsec = va_arg(ap, int);
65710+ csec = va_arg(ap, int);
65711+ ulong1 = va_arg(ap, unsigned long);
65712+ cred = __task_cred(task);
65713+ pcred = __task_cred(task->real_parent);
65714+
65715+ 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));
65716+ }
65717+ break;
65718+ default:
65719+ gr_log_middle(audit, msg, ap);
65720+ }
65721+ va_end(ap);
65722+ // these don't need DEFAULTSECARGS printed on the end
65723+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
65724+ gr_log_end(audit, 0);
65725+ else
65726+ gr_log_end(audit, 1);
65727+ END_LOCKS(audit);
65728+}
65729diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
65730new file mode 100644
65731index 0000000..f536303
65732--- /dev/null
65733+++ b/grsecurity/grsec_mem.c
65734@@ -0,0 +1,40 @@
65735+#include <linux/kernel.h>
65736+#include <linux/sched.h>
65737+#include <linux/mm.h>
65738+#include <linux/mman.h>
65739+#include <linux/grinternal.h>
65740+
65741+void
65742+gr_handle_ioperm(void)
65743+{
65744+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
65745+ return;
65746+}
65747+
65748+void
65749+gr_handle_iopl(void)
65750+{
65751+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
65752+ return;
65753+}
65754+
65755+void
65756+gr_handle_mem_readwrite(u64 from, u64 to)
65757+{
65758+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
65759+ return;
65760+}
65761+
65762+void
65763+gr_handle_vm86(void)
65764+{
65765+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
65766+ return;
65767+}
65768+
65769+void
65770+gr_log_badprocpid(const char *entry)
65771+{
65772+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
65773+ return;
65774+}
65775diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
65776new file mode 100644
65777index 0000000..2131422
65778--- /dev/null
65779+++ b/grsecurity/grsec_mount.c
65780@@ -0,0 +1,62 @@
65781+#include <linux/kernel.h>
65782+#include <linux/sched.h>
65783+#include <linux/mount.h>
65784+#include <linux/grsecurity.h>
65785+#include <linux/grinternal.h>
65786+
65787+void
65788+gr_log_remount(const char *devname, const int retval)
65789+{
65790+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65791+ if (grsec_enable_mount && (retval >= 0))
65792+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
65793+#endif
65794+ return;
65795+}
65796+
65797+void
65798+gr_log_unmount(const char *devname, const int retval)
65799+{
65800+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65801+ if (grsec_enable_mount && (retval >= 0))
65802+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
65803+#endif
65804+ return;
65805+}
65806+
65807+void
65808+gr_log_mount(const char *from, const char *to, const int retval)
65809+{
65810+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65811+ if (grsec_enable_mount && (retval >= 0))
65812+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
65813+#endif
65814+ return;
65815+}
65816+
65817+int
65818+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
65819+{
65820+#ifdef CONFIG_GRKERNSEC_ROFS
65821+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
65822+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
65823+ return -EPERM;
65824+ } else
65825+ return 0;
65826+#endif
65827+ return 0;
65828+}
65829+
65830+int
65831+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
65832+{
65833+#ifdef CONFIG_GRKERNSEC_ROFS
65834+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
65835+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
65836+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
65837+ return -EPERM;
65838+ } else
65839+ return 0;
65840+#endif
65841+ return 0;
65842+}
65843diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
65844new file mode 100644
65845index 0000000..a3b12a0
65846--- /dev/null
65847+++ b/grsecurity/grsec_pax.c
65848@@ -0,0 +1,36 @@
65849+#include <linux/kernel.h>
65850+#include <linux/sched.h>
65851+#include <linux/mm.h>
65852+#include <linux/file.h>
65853+#include <linux/grinternal.h>
65854+#include <linux/grsecurity.h>
65855+
65856+void
65857+gr_log_textrel(struct vm_area_struct * vma)
65858+{
65859+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65860+ if (grsec_enable_audit_textrel)
65861+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
65862+#endif
65863+ return;
65864+}
65865+
65866+void
65867+gr_log_rwxmmap(struct file *file)
65868+{
65869+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65870+ if (grsec_enable_log_rwxmaps)
65871+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
65872+#endif
65873+ return;
65874+}
65875+
65876+void
65877+gr_log_rwxmprotect(struct file *file)
65878+{
65879+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65880+ if (grsec_enable_log_rwxmaps)
65881+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
65882+#endif
65883+ return;
65884+}
65885diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
65886new file mode 100644
65887index 0000000..f7f29aa
65888--- /dev/null
65889+++ b/grsecurity/grsec_ptrace.c
65890@@ -0,0 +1,30 @@
65891+#include <linux/kernel.h>
65892+#include <linux/sched.h>
65893+#include <linux/grinternal.h>
65894+#include <linux/security.h>
65895+
65896+void
65897+gr_audit_ptrace(struct task_struct *task)
65898+{
65899+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65900+ if (grsec_enable_audit_ptrace)
65901+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
65902+#endif
65903+ return;
65904+}
65905+
65906+int
65907+gr_ptrace_readexec(struct file *file, int unsafe_flags)
65908+{
65909+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65910+ const struct dentry *dentry = file->f_path.dentry;
65911+ const struct vfsmount *mnt = file->f_path.mnt;
65912+
65913+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
65914+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
65915+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
65916+ return -EACCES;
65917+ }
65918+#endif
65919+ return 0;
65920+}
65921diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
65922new file mode 100644
65923index 0000000..4e29cc7
65924--- /dev/null
65925+++ b/grsecurity/grsec_sig.c
65926@@ -0,0 +1,246 @@
65927+#include <linux/kernel.h>
65928+#include <linux/sched.h>
65929+#include <linux/fs.h>
65930+#include <linux/delay.h>
65931+#include <linux/grsecurity.h>
65932+#include <linux/grinternal.h>
65933+#include <linux/hardirq.h>
65934+
65935+char *signames[] = {
65936+ [SIGSEGV] = "Segmentation fault",
65937+ [SIGILL] = "Illegal instruction",
65938+ [SIGABRT] = "Abort",
65939+ [SIGBUS] = "Invalid alignment/Bus error"
65940+};
65941+
65942+void
65943+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
65944+{
65945+#ifdef CONFIG_GRKERNSEC_SIGNAL
65946+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
65947+ (sig == SIGABRT) || (sig == SIGBUS))) {
65948+ if (task_pid_nr(t) == task_pid_nr(current)) {
65949+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
65950+ } else {
65951+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
65952+ }
65953+ }
65954+#endif
65955+ return;
65956+}
65957+
65958+int
65959+gr_handle_signal(const struct task_struct *p, const int sig)
65960+{
65961+#ifdef CONFIG_GRKERNSEC
65962+ /* ignore the 0 signal for protected task checks */
65963+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
65964+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
65965+ return -EPERM;
65966+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
65967+ return -EPERM;
65968+ }
65969+#endif
65970+ return 0;
65971+}
65972+
65973+#ifdef CONFIG_GRKERNSEC
65974+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
65975+
65976+int gr_fake_force_sig(int sig, struct task_struct *t)
65977+{
65978+ unsigned long int flags;
65979+ int ret, blocked, ignored;
65980+ struct k_sigaction *action;
65981+
65982+ spin_lock_irqsave(&t->sighand->siglock, flags);
65983+ action = &t->sighand->action[sig-1];
65984+ ignored = action->sa.sa_handler == SIG_IGN;
65985+ blocked = sigismember(&t->blocked, sig);
65986+ if (blocked || ignored) {
65987+ action->sa.sa_handler = SIG_DFL;
65988+ if (blocked) {
65989+ sigdelset(&t->blocked, sig);
65990+ recalc_sigpending_and_wake(t);
65991+ }
65992+ }
65993+ if (action->sa.sa_handler == SIG_DFL)
65994+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
65995+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
65996+
65997+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
65998+
65999+ return ret;
66000+}
66001+#endif
66002+
66003+#ifdef CONFIG_GRKERNSEC_BRUTE
66004+#define GR_USER_BAN_TIME (15 * 60)
66005+#define GR_DAEMON_BRUTE_TIME (30 * 60)
66006+
66007+static int __get_dumpable(unsigned long mm_flags)
66008+{
66009+ int ret;
66010+
66011+ ret = mm_flags & MMF_DUMPABLE_MASK;
66012+ return (ret >= 2) ? 2 : ret;
66013+}
66014+#endif
66015+
66016+void gr_handle_brute_attach(unsigned long mm_flags)
66017+{
66018+#ifdef CONFIG_GRKERNSEC_BRUTE
66019+ struct task_struct *p = current;
66020+ kuid_t uid = GLOBAL_ROOT_UID;
66021+ int daemon = 0;
66022+
66023+ if (!grsec_enable_brute)
66024+ return;
66025+
66026+ rcu_read_lock();
66027+ read_lock(&tasklist_lock);
66028+ read_lock(&grsec_exec_file_lock);
66029+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
66030+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
66031+ p->real_parent->brute = 1;
66032+ daemon = 1;
66033+ } else {
66034+ const struct cred *cred = __task_cred(p), *cred2;
66035+ struct task_struct *tsk, *tsk2;
66036+
66037+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
66038+ struct user_struct *user;
66039+
66040+ uid = cred->uid;
66041+
66042+ /* this is put upon execution past expiration */
66043+ user = find_user(uid);
66044+ if (user == NULL)
66045+ goto unlock;
66046+ user->suid_banned = 1;
66047+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
66048+ if (user->suid_ban_expires == ~0UL)
66049+ user->suid_ban_expires--;
66050+
66051+ /* only kill other threads of the same binary, from the same user */
66052+ do_each_thread(tsk2, tsk) {
66053+ cred2 = __task_cred(tsk);
66054+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
66055+ gr_fake_force_sig(SIGKILL, tsk);
66056+ } while_each_thread(tsk2, tsk);
66057+ }
66058+ }
66059+unlock:
66060+ read_unlock(&grsec_exec_file_lock);
66061+ read_unlock(&tasklist_lock);
66062+ rcu_read_unlock();
66063+
66064+ if (gr_is_global_nonroot(uid))
66065+ gr_log_fs_int2(GR_DONT_AUDIT, GR_BRUTE_SUID_MSG, p->exec_file->f_path.dentry, p->exec_file->f_path.mnt, GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
66066+ else if (daemon)
66067+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
66068+
66069+#endif
66070+ return;
66071+}
66072+
66073+void gr_handle_brute_check(void)
66074+{
66075+#ifdef CONFIG_GRKERNSEC_BRUTE
66076+ struct task_struct *p = current;
66077+
66078+ if (unlikely(p->brute)) {
66079+ if (!grsec_enable_brute)
66080+ p->brute = 0;
66081+ else if (time_before(get_seconds(), p->brute_expires))
66082+ msleep(30 * 1000);
66083+ }
66084+#endif
66085+ return;
66086+}
66087+
66088+void gr_handle_kernel_exploit(void)
66089+{
66090+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66091+ const struct cred *cred;
66092+ struct task_struct *tsk, *tsk2;
66093+ struct user_struct *user;
66094+ kuid_t uid;
66095+
66096+ if (in_irq() || in_serving_softirq() || in_nmi())
66097+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
66098+
66099+ uid = current_uid();
66100+
66101+ if (gr_is_global_root(uid))
66102+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
66103+ else {
66104+ /* kill all the processes of this user, hold a reference
66105+ to their creds struct, and prevent them from creating
66106+ another process until system reset
66107+ */
66108+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
66109+ GR_GLOBAL_UID(uid));
66110+ /* we intentionally leak this ref */
66111+ user = get_uid(current->cred->user);
66112+ if (user)
66113+ user->kernel_banned = 1;
66114+
66115+ /* kill all processes of this user */
66116+ read_lock(&tasklist_lock);
66117+ do_each_thread(tsk2, tsk) {
66118+ cred = __task_cred(tsk);
66119+ if (uid_eq(cred->uid, uid))
66120+ gr_fake_force_sig(SIGKILL, tsk);
66121+ } while_each_thread(tsk2, tsk);
66122+ read_unlock(&tasklist_lock);
66123+ }
66124+#endif
66125+}
66126+
66127+#ifdef CONFIG_GRKERNSEC_BRUTE
66128+static bool suid_ban_expired(struct user_struct *user)
66129+{
66130+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
66131+ user->suid_banned = 0;
66132+ user->suid_ban_expires = 0;
66133+ free_uid(user);
66134+ return true;
66135+ }
66136+
66137+ return false;
66138+}
66139+#endif
66140+
66141+int gr_process_kernel_exec_ban(void)
66142+{
66143+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66144+ if (unlikely(current->cred->user->kernel_banned))
66145+ return -EPERM;
66146+#endif
66147+ return 0;
66148+}
66149+
66150+int gr_process_kernel_setuid_ban(struct user_struct *user)
66151+{
66152+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66153+ if (unlikely(user->kernel_banned))
66154+ gr_fake_force_sig(SIGKILL, current);
66155+#endif
66156+ return 0;
66157+}
66158+
66159+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
66160+{
66161+#ifdef CONFIG_GRKERNSEC_BRUTE
66162+ struct user_struct *user = current->cred->user;
66163+ if (unlikely(user->suid_banned)) {
66164+ if (suid_ban_expired(user))
66165+ return 0;
66166+ /* disallow execution of suid binaries only */
66167+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
66168+ return -EPERM;
66169+ }
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..12994b5
69205--- /dev/null
69206+++ b/include/linux/grinternal.h
69207@@ -0,0 +1,227 @@
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+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
69322+{
69323+ if (file1 && file2) {
69324+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
69325+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
69326+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
69327+ return true;
69328+ }
69329+
69330+ return false;
69331+}
69332+
69333+#define GR_CHROOT_CAPS {{ \
69334+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
69335+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
69336+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
69337+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
69338+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
69339+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
69340+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
69341+
69342+#define security_learn(normal_msg,args...) \
69343+({ \
69344+ read_lock(&grsec_exec_file_lock); \
69345+ gr_add_learn_entry(normal_msg "\n", ## args); \
69346+ read_unlock(&grsec_exec_file_lock); \
69347+})
69348+
69349+enum {
69350+ GR_DO_AUDIT,
69351+ GR_DONT_AUDIT,
69352+ /* used for non-audit messages that we shouldn't kill the task on */
69353+ GR_DONT_AUDIT_GOOD
69354+};
69355+
69356+enum {
69357+ GR_TTYSNIFF,
69358+ GR_RBAC,
69359+ GR_RBAC_STR,
69360+ GR_STR_RBAC,
69361+ GR_RBAC_MODE2,
69362+ GR_RBAC_MODE3,
69363+ GR_FILENAME,
69364+ GR_SYSCTL_HIDDEN,
69365+ GR_NOARGS,
69366+ GR_ONE_INT,
69367+ GR_ONE_INT_TWO_STR,
69368+ GR_ONE_STR,
69369+ GR_STR_INT,
69370+ GR_TWO_STR_INT,
69371+ GR_TWO_INT,
69372+ GR_TWO_U64,
69373+ GR_THREE_INT,
69374+ GR_FIVE_INT_TWO_STR,
69375+ GR_TWO_STR,
69376+ GR_THREE_STR,
69377+ GR_FOUR_STR,
69378+ GR_STR_FILENAME,
69379+ GR_FILENAME_STR,
69380+ GR_FILENAME_TWO_INT,
69381+ GR_FILENAME_TWO_INT_STR,
69382+ GR_TEXTREL,
69383+ GR_PTRACE,
69384+ GR_RESOURCE,
69385+ GR_CAP,
69386+ GR_SIG,
69387+ GR_SIG2,
69388+ GR_CRASH1,
69389+ GR_CRASH2,
69390+ GR_PSACCT,
69391+ GR_RWXMAP
69392+};
69393+
69394+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
69395+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
69396+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
69397+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
69398+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
69399+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
69400+#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)
69401+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
69402+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
69403+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
69404+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
69405+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
69406+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
69407+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
69408+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
69409+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
69410+#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)
69411+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
69412+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
69413+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
69414+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
69415+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
69416+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
69417+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
69418+#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)
69419+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
69420+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
69421+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
69422+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
69423+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
69424+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
69425+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
69426+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
69427+#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)
69428+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
69429+
69430+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
69431+
69432+#endif
69433+
69434+#endif
69435diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
69436new file mode 100644
69437index 0000000..2f159b5
69438--- /dev/null
69439+++ b/include/linux/grmsg.h
69440@@ -0,0 +1,112 @@
69441+#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"
69442+#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"
69443+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
69444+#define GR_STOPMOD_MSG "denied modification of module state by "
69445+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
69446+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
69447+#define GR_IOPERM_MSG "denied use of ioperm() by "
69448+#define GR_IOPL_MSG "denied use of iopl() by "
69449+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
69450+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
69451+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
69452+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
69453+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
69454+#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"
69455+#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"
69456+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
69457+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
69458+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
69459+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
69460+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
69461+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
69462+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
69463+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
69464+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
69465+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
69466+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
69467+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
69468+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
69469+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
69470+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
69471+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
69472+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
69473+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
69474+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
69475+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
69476+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
69477+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
69478+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
69479+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
69480+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
69481+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
69482+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
69483+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
69484+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
69485+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
69486+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
69487+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
69488+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
69489+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
69490+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
69491+#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"
69492+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
69493+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
69494+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
69495+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
69496+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
69497+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
69498+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
69499+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
69500+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
69501+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
69502+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
69503+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
69504+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
69505+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
69506+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
69507+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
69508+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
69509+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
69510+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
69511+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
69512+#define GR_FAILFORK_MSG "failed fork with errno %s by "
69513+#define GR_NICE_CHROOT_MSG "denied priority change by "
69514+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
69515+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
69516+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
69517+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
69518+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
69519+#define GR_TIME_MSG "time set by "
69520+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
69521+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
69522+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
69523+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
69524+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
69525+#define GR_BIND_MSG "denied bind() by "
69526+#define GR_CONNECT_MSG "denied connect() by "
69527+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
69528+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
69529+#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"
69530+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
69531+#define GR_CAP_ACL_MSG "use of %s denied for "
69532+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
69533+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
69534+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
69535+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
69536+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
69537+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
69538+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
69539+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
69540+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
69541+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
69542+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
69543+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
69544+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
69545+#define GR_VM86_MSG "denied use of vm86 by "
69546+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
69547+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
69548+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
69549+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
69550+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
69551+#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 "
69552+#define GR_BRUTE_SUID_MSG "bruteforce prevention initiated due to crash of %.950s against uid %u, banning suid/sgid execs for %u minutes. Please investigate the crash report for "
69553diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
69554new file mode 100644
69555index 0000000..d957f6d
69556--- /dev/null
69557+++ b/include/linux/grsecurity.h
69558@@ -0,0 +1,241 @@
69559+#ifndef GR_SECURITY_H
69560+#define GR_SECURITY_H
69561+#include <linux/fs.h>
69562+#include <linux/fs_struct.h>
69563+#include <linux/binfmts.h>
69564+#include <linux/gracl.h>
69565+
69566+/* notify of brain-dead configs */
69567+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69568+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
69569+#endif
69570+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
69571+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
69572+#endif
69573+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
69574+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
69575+#endif
69576+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
69577+#error "CONFIG_PAX enabled, but no PaX options are enabled."
69578+#endif
69579+
69580+void gr_handle_brute_attach(unsigned long mm_flags);
69581+void gr_handle_brute_check(void);
69582+void gr_handle_kernel_exploit(void);
69583+
69584+char gr_roletype_to_char(void);
69585+
69586+int gr_acl_enable_at_secure(void);
69587+
69588+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
69589+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
69590+
69591+void gr_del_task_from_ip_table(struct task_struct *p);
69592+
69593+int gr_pid_is_chrooted(struct task_struct *p);
69594+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
69595+int gr_handle_chroot_nice(void);
69596+int gr_handle_chroot_sysctl(const int op);
69597+int gr_handle_chroot_setpriority(struct task_struct *p,
69598+ const int niceval);
69599+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
69600+int gr_handle_chroot_chroot(const struct dentry *dentry,
69601+ const struct vfsmount *mnt);
69602+void gr_handle_chroot_chdir(const struct path *path);
69603+int gr_handle_chroot_chmod(const struct dentry *dentry,
69604+ const struct vfsmount *mnt, const int mode);
69605+int gr_handle_chroot_mknod(const struct dentry *dentry,
69606+ const struct vfsmount *mnt, const int mode);
69607+int gr_handle_chroot_mount(const struct dentry *dentry,
69608+ const struct vfsmount *mnt,
69609+ const char *dev_name);
69610+int gr_handle_chroot_pivot(void);
69611+int gr_handle_chroot_unix(const pid_t pid);
69612+
69613+int gr_handle_rawio(const struct inode *inode);
69614+
69615+void gr_handle_ioperm(void);
69616+void gr_handle_iopl(void);
69617+
69618+umode_t gr_acl_umask(void);
69619+
69620+int gr_tpe_allow(const struct file *file);
69621+
69622+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
69623+void gr_clear_chroot_entries(struct task_struct *task);
69624+
69625+void gr_log_forkfail(const int retval);
69626+void gr_log_timechange(void);
69627+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
69628+void gr_log_chdir(const struct dentry *dentry,
69629+ const struct vfsmount *mnt);
69630+void gr_log_chroot_exec(const struct dentry *dentry,
69631+ const struct vfsmount *mnt);
69632+void gr_log_remount(const char *devname, const int retval);
69633+void gr_log_unmount(const char *devname, const int retval);
69634+void gr_log_mount(const char *from, const char *to, const int retval);
69635+void gr_log_textrel(struct vm_area_struct *vma);
69636+void gr_log_rwxmmap(struct file *file);
69637+void gr_log_rwxmprotect(struct file *file);
69638+
69639+int gr_handle_follow_link(const struct inode *parent,
69640+ const struct inode *inode,
69641+ const struct dentry *dentry,
69642+ const struct vfsmount *mnt);
69643+int gr_handle_fifo(const struct dentry *dentry,
69644+ const struct vfsmount *mnt,
69645+ const struct dentry *dir, const int flag,
69646+ const int acc_mode);
69647+int gr_handle_hardlink(const struct dentry *dentry,
69648+ const struct vfsmount *mnt,
69649+ struct inode *inode,
69650+ const int mode, const struct filename *to);
69651+
69652+int gr_is_capable(const int cap);
69653+int gr_is_capable_nolog(const int cap);
69654+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69655+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
69656+
69657+void gr_copy_label(struct task_struct *tsk);
69658+void gr_handle_crash(struct task_struct *task, const int sig);
69659+int gr_handle_signal(const struct task_struct *p, const int sig);
69660+int gr_check_crash_uid(const kuid_t uid);
69661+int gr_check_protected_task(const struct task_struct *task);
69662+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
69663+int gr_acl_handle_mmap(const struct file *file,
69664+ const unsigned long prot);
69665+int gr_acl_handle_mprotect(const struct file *file,
69666+ const unsigned long prot);
69667+int gr_check_hidden_task(const struct task_struct *tsk);
69668+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
69669+ const struct vfsmount *mnt);
69670+__u32 gr_acl_handle_utime(const struct dentry *dentry,
69671+ const struct vfsmount *mnt);
69672+__u32 gr_acl_handle_access(const struct dentry *dentry,
69673+ const struct vfsmount *mnt, const int fmode);
69674+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
69675+ const struct vfsmount *mnt, umode_t *mode);
69676+__u32 gr_acl_handle_chown(const struct dentry *dentry,
69677+ const struct vfsmount *mnt);
69678+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
69679+ const struct vfsmount *mnt);
69680+int gr_handle_ptrace(struct task_struct *task, const long request);
69681+int gr_handle_proc_ptrace(struct task_struct *task);
69682+__u32 gr_acl_handle_execve(const struct dentry *dentry,
69683+ const struct vfsmount *mnt);
69684+int gr_check_crash_exec(const struct file *filp);
69685+int gr_acl_is_enabled(void);
69686+void gr_set_kernel_label(struct task_struct *task);
69687+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
69688+ const kgid_t gid);
69689+int gr_set_proc_label(const struct dentry *dentry,
69690+ const struct vfsmount *mnt,
69691+ const int unsafe_flags);
69692+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
69693+ const struct vfsmount *mnt);
69694+__u32 gr_acl_handle_open(const struct dentry *dentry,
69695+ const struct vfsmount *mnt, int acc_mode);
69696+__u32 gr_acl_handle_creat(const struct dentry *dentry,
69697+ const struct dentry *p_dentry,
69698+ const struct vfsmount *p_mnt,
69699+ int open_flags, int acc_mode, const int imode);
69700+void gr_handle_create(const struct dentry *dentry,
69701+ const struct vfsmount *mnt);
69702+void gr_handle_proc_create(const struct dentry *dentry,
69703+ const struct inode *inode);
69704+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
69705+ const struct dentry *parent_dentry,
69706+ const struct vfsmount *parent_mnt,
69707+ const int mode);
69708+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
69709+ const struct dentry *parent_dentry,
69710+ const struct vfsmount *parent_mnt);
69711+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
69712+ const struct vfsmount *mnt);
69713+void gr_handle_delete(const ino_t ino, const dev_t dev);
69714+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
69715+ const struct vfsmount *mnt);
69716+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
69717+ const struct dentry *parent_dentry,
69718+ const struct vfsmount *parent_mnt,
69719+ const struct filename *from);
69720+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
69721+ const struct dentry *parent_dentry,
69722+ const struct vfsmount *parent_mnt,
69723+ const struct dentry *old_dentry,
69724+ const struct vfsmount *old_mnt, const struct filename *to);
69725+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
69726+int gr_acl_handle_rename(struct dentry *new_dentry,
69727+ struct dentry *parent_dentry,
69728+ const struct vfsmount *parent_mnt,
69729+ struct dentry *old_dentry,
69730+ struct inode *old_parent_inode,
69731+ struct vfsmount *old_mnt, const struct filename *newname);
69732+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69733+ struct dentry *old_dentry,
69734+ struct dentry *new_dentry,
69735+ struct vfsmount *mnt, const __u8 replace);
69736+__u32 gr_check_link(const struct dentry *new_dentry,
69737+ const struct dentry *parent_dentry,
69738+ const struct vfsmount *parent_mnt,
69739+ const struct dentry *old_dentry,
69740+ const struct vfsmount *old_mnt);
69741+int gr_acl_handle_filldir(const struct file *file, const char *name,
69742+ const unsigned int namelen, const ino_t ino);
69743+
69744+__u32 gr_acl_handle_unix(const struct dentry *dentry,
69745+ const struct vfsmount *mnt);
69746+void gr_acl_handle_exit(void);
69747+void gr_acl_handle_psacct(struct task_struct *task, const long code);
69748+int gr_acl_handle_procpidmem(const struct task_struct *task);
69749+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
69750+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
69751+void gr_audit_ptrace(struct task_struct *task);
69752+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
69753+void gr_put_exec_file(struct task_struct *task);
69754+
69755+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
69756+
69757+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
69758+extern void gr_learn_resource(const struct task_struct *task, const int res,
69759+ const unsigned long wanted, const int gt);
69760+#else
69761+static inline void gr_learn_resource(const struct task_struct *task, const int res,
69762+ const unsigned long wanted, const int gt)
69763+{
69764+}
69765+#endif
69766+
69767+#ifdef CONFIG_GRKERNSEC_RESLOG
69768+extern void gr_log_resource(const struct task_struct *task, const int res,
69769+ const unsigned long wanted, const int gt);
69770+#else
69771+static inline void gr_log_resource(const struct task_struct *task, const int res,
69772+ const unsigned long wanted, const int gt)
69773+{
69774+}
69775+#endif
69776+
69777+#ifdef CONFIG_GRKERNSEC
69778+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
69779+void gr_handle_vm86(void);
69780+void gr_handle_mem_readwrite(u64 from, u64 to);
69781+
69782+void gr_log_badprocpid(const char *entry);
69783+
69784+extern int grsec_enable_dmesg;
69785+extern int grsec_disable_privio;
69786+
69787+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69788+extern kgid_t grsec_proc_gid;
69789+#endif
69790+
69791+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69792+extern int grsec_enable_chroot_findtask;
69793+#endif
69794+#ifdef CONFIG_GRKERNSEC_SETXID
69795+extern int grsec_enable_setxid;
69796+#endif
69797+#endif
69798+
69799+#endif
69800diff --git a/include/linux/grsock.h b/include/linux/grsock.h
69801new file mode 100644
69802index 0000000..e7ffaaf
69803--- /dev/null
69804+++ b/include/linux/grsock.h
69805@@ -0,0 +1,19 @@
69806+#ifndef __GRSOCK_H
69807+#define __GRSOCK_H
69808+
69809+extern void gr_attach_curr_ip(const struct sock *sk);
69810+extern int gr_handle_sock_all(const int family, const int type,
69811+ const int protocol);
69812+extern int gr_handle_sock_server(const struct sockaddr *sck);
69813+extern int gr_handle_sock_server_other(const struct sock *sck);
69814+extern int gr_handle_sock_client(const struct sockaddr *sck);
69815+extern int gr_search_connect(struct socket * sock,
69816+ struct sockaddr_in * addr);
69817+extern int gr_search_bind(struct socket * sock,
69818+ struct sockaddr_in * addr);
69819+extern int gr_search_listen(struct socket * sock);
69820+extern int gr_search_accept(struct socket * sock);
69821+extern int gr_search_socket(const int domain, const int type,
69822+ const int protocol);
69823+
69824+#endif
69825diff --git a/include/linux/highmem.h b/include/linux/highmem.h
69826index 7fb31da..08b5114 100644
69827--- a/include/linux/highmem.h
69828+++ b/include/linux/highmem.h
69829@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
69830 kunmap_atomic(kaddr);
69831 }
69832
69833+static inline void sanitize_highpage(struct page *page)
69834+{
69835+ void *kaddr;
69836+ unsigned long flags;
69837+
69838+ local_irq_save(flags);
69839+ kaddr = kmap_atomic(page);
69840+ clear_page(kaddr);
69841+ kunmap_atomic(kaddr);
69842+ local_irq_restore(flags);
69843+}
69844+
69845 static inline void zero_user_segments(struct page *page,
69846 unsigned start1, unsigned end1,
69847 unsigned start2, unsigned end2)
69848diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
69849index 1c7b89a..7f52502 100644
69850--- a/include/linux/hwmon-sysfs.h
69851+++ b/include/linux/hwmon-sysfs.h
69852@@ -25,7 +25,8 @@
69853 struct sensor_device_attribute{
69854 struct device_attribute dev_attr;
69855 int index;
69856-};
69857+} __do_const;
69858+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
69859 #define to_sensor_dev_attr(_dev_attr) \
69860 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
69861
69862@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
69863 struct device_attribute dev_attr;
69864 u8 index;
69865 u8 nr;
69866-};
69867+} __do_const;
69868 #define to_sensor_dev_attr_2(_dev_attr) \
69869 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
69870
69871diff --git a/include/linux/i2c.h b/include/linux/i2c.h
69872index d0c4db7..61b3577 100644
69873--- a/include/linux/i2c.h
69874+++ b/include/linux/i2c.h
69875@@ -369,6 +369,7 @@ struct i2c_algorithm {
69876 /* To determine what the adapter supports */
69877 u32 (*functionality) (struct i2c_adapter *);
69878 };
69879+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
69880
69881 /*
69882 * i2c_adapter is the structure used to identify a physical i2c bus along
69883diff --git a/include/linux/i2o.h b/include/linux/i2o.h
69884index d23c3c2..eb63c81 100644
69885--- a/include/linux/i2o.h
69886+++ b/include/linux/i2o.h
69887@@ -565,7 +565,7 @@ struct i2o_controller {
69888 struct i2o_device *exec; /* Executive */
69889 #if BITS_PER_LONG == 64
69890 spinlock_t context_list_lock; /* lock for context_list */
69891- atomic_t context_list_counter; /* needed for unique contexts */
69892+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
69893 struct list_head context_list; /* list of context id's
69894 and pointers */
69895 #endif
69896diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
69897index aff7ad8..3942bbd 100644
69898--- a/include/linux/if_pppox.h
69899+++ b/include/linux/if_pppox.h
69900@@ -76,7 +76,7 @@ struct pppox_proto {
69901 int (*ioctl)(struct socket *sock, unsigned int cmd,
69902 unsigned long arg);
69903 struct module *owner;
69904-};
69905+} __do_const;
69906
69907 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
69908 extern void unregister_pppox_proto(int proto_num);
69909diff --git a/include/linux/init.h b/include/linux/init.h
69910index 8618147..0821126 100644
69911--- a/include/linux/init.h
69912+++ b/include/linux/init.h
69913@@ -39,9 +39,36 @@
69914 * Also note, that this data cannot be "const".
69915 */
69916
69917+#ifdef MODULE
69918+#define add_init_latent_entropy
69919+#define add_devinit_latent_entropy
69920+#define add_cpuinit_latent_entropy
69921+#define add_meminit_latent_entropy
69922+#else
69923+#define add_init_latent_entropy __latent_entropy
69924+
69925+#ifdef CONFIG_HOTPLUG
69926+#define add_devinit_latent_entropy
69927+#else
69928+#define add_devinit_latent_entropy __latent_entropy
69929+#endif
69930+
69931+#ifdef CONFIG_HOTPLUG_CPU
69932+#define add_cpuinit_latent_entropy
69933+#else
69934+#define add_cpuinit_latent_entropy __latent_entropy
69935+#endif
69936+
69937+#ifdef CONFIG_MEMORY_HOTPLUG
69938+#define add_meminit_latent_entropy
69939+#else
69940+#define add_meminit_latent_entropy __latent_entropy
69941+#endif
69942+#endif
69943+
69944 /* These are for everybody (although not all archs will actually
69945 discard it in modules) */
69946-#define __init __section(.init.text) __cold notrace
69947+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
69948 #define __initdata __section(.init.data)
69949 #define __initconst __constsection(.init.rodata)
69950 #define __exitdata __section(.exit.data)
69951@@ -94,7 +121,7 @@
69952 #define __exit __section(.exit.text) __exitused __cold notrace
69953
69954 /* Used for HOTPLUG_CPU */
69955-#define __cpuinit __section(.cpuinit.text) __cold notrace
69956+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
69957 #define __cpuinitdata __section(.cpuinit.data)
69958 #define __cpuinitconst __constsection(.cpuinit.rodata)
69959 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
69960@@ -102,7 +129,7 @@
69961 #define __cpuexitconst __constsection(.cpuexit.rodata)
69962
69963 /* Used for MEMORY_HOTPLUG */
69964-#define __meminit __section(.meminit.text) __cold notrace
69965+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
69966 #define __meminitdata __section(.meminit.data)
69967 #define __meminitconst __constsection(.meminit.rodata)
69968 #define __memexit __section(.memexit.text) __exitused __cold notrace
69969diff --git a/include/linux/init_task.h b/include/linux/init_task.h
69970index 5cd0f09..c9f67cc 100644
69971--- a/include/linux/init_task.h
69972+++ b/include/linux/init_task.h
69973@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
69974
69975 #define INIT_TASK_COMM "swapper"
69976
69977+#ifdef CONFIG_X86
69978+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
69979+#else
69980+#define INIT_TASK_THREAD_INFO
69981+#endif
69982+
69983 /*
69984 * INIT_TASK is used to set up the first task table, touch at
69985 * your own risk!. Base=0, limit=0x1fffff (=2MB)
69986@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
69987 RCU_POINTER_INITIALIZER(cred, &init_cred), \
69988 .comm = INIT_TASK_COMM, \
69989 .thread = INIT_THREAD, \
69990+ INIT_TASK_THREAD_INFO \
69991 .fs = &init_fs, \
69992 .files = &init_files, \
69993 .signal = &init_signals, \
69994diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
69995index 5fa5afe..ac55b25 100644
69996--- a/include/linux/interrupt.h
69997+++ b/include/linux/interrupt.h
69998@@ -430,7 +430,7 @@ enum
69999 /* map softirq index to softirq name. update 'softirq_to_name' in
70000 * kernel/softirq.c when adding a new softirq.
70001 */
70002-extern char *softirq_to_name[NR_SOFTIRQS];
70003+extern const char * const softirq_to_name[NR_SOFTIRQS];
70004
70005 /* softirq mask and active fields moved to irq_cpustat_t in
70006 * asm/hardirq.h to get better cache usage. KAO
70007@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
70008
70009 struct softirq_action
70010 {
70011- void (*action)(struct softirq_action *);
70012-};
70013+ void (*action)(void);
70014+} __no_const;
70015
70016 asmlinkage void do_softirq(void);
70017 asmlinkage void __do_softirq(void);
70018-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
70019+extern void open_softirq(int nr, void (*action)(void));
70020 extern void softirq_init(void);
70021 extern void __raise_softirq_irqoff(unsigned int nr);
70022
70023diff --git a/include/linux/iommu.h b/include/linux/iommu.h
70024index ba3b8a9..7e14ed8 100644
70025--- a/include/linux/iommu.h
70026+++ b/include/linux/iommu.h
70027@@ -113,7 +113,7 @@ struct iommu_ops {
70028 u32 (*domain_get_windows)(struct iommu_domain *domain);
70029
70030 unsigned long pgsize_bitmap;
70031-};
70032+} __do_const;
70033
70034 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
70035 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
70036diff --git a/include/linux/ioport.h b/include/linux/ioport.h
70037index 85ac9b9b..e5759ab 100644
70038--- a/include/linux/ioport.h
70039+++ b/include/linux/ioport.h
70040@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
70041 int adjust_resource(struct resource *res, resource_size_t start,
70042 resource_size_t size);
70043 resource_size_t resource_alignment(struct resource *res);
70044-static inline resource_size_t resource_size(const struct resource *res)
70045+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
70046 {
70047 return res->end - res->start + 1;
70048 }
70049diff --git a/include/linux/irq.h b/include/linux/irq.h
70050index bc4e066..50468a9 100644
70051--- a/include/linux/irq.h
70052+++ b/include/linux/irq.h
70053@@ -328,7 +328,8 @@ struct irq_chip {
70054 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
70055
70056 unsigned long flags;
70057-};
70058+} __do_const;
70059+typedef struct irq_chip __no_const irq_chip_no_const;
70060
70061 /*
70062 * irq_chip specific flags
70063diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
70064index 3fd8e42..a73e966 100644
70065--- a/include/linux/irqchip/arm-gic.h
70066+++ b/include/linux/irqchip/arm-gic.h
70067@@ -59,9 +59,11 @@
70068
70069 #ifndef __ASSEMBLY__
70070
70071+#include <linux/irq.h>
70072+
70073 struct device_node;
70074
70075-extern struct irq_chip gic_arch_extn;
70076+extern irq_chip_no_const gic_arch_extn;
70077
70078 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
70079 u32 offset, struct device_node *);
70080diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
70081index 6883e19..06992b1 100644
70082--- a/include/linux/kallsyms.h
70083+++ b/include/linux/kallsyms.h
70084@@ -15,7 +15,8 @@
70085
70086 struct module;
70087
70088-#ifdef CONFIG_KALLSYMS
70089+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
70090+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70091 /* Lookup the address for a symbol. Returns 0 if not found. */
70092 unsigned long kallsyms_lookup_name(const char *name);
70093
70094@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
70095 /* Stupid that this does nothing, but I didn't create this mess. */
70096 #define __print_symbol(fmt, addr)
70097 #endif /*CONFIG_KALLSYMS*/
70098+#else /* when included by kallsyms.c, vsnprintf.c, or
70099+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
70100+extern void __print_symbol(const char *fmt, unsigned long address);
70101+extern int sprint_backtrace(char *buffer, unsigned long address);
70102+extern int sprint_symbol(char *buffer, unsigned long address);
70103+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
70104+const char *kallsyms_lookup(unsigned long addr,
70105+ unsigned long *symbolsize,
70106+ unsigned long *offset,
70107+ char **modname, char *namebuf);
70108+#endif
70109
70110 /* This macro allows us to keep printk typechecking */
70111 static __printf(1, 2)
70112diff --git a/include/linux/key-type.h b/include/linux/key-type.h
70113index 518a53a..5e28358 100644
70114--- a/include/linux/key-type.h
70115+++ b/include/linux/key-type.h
70116@@ -125,7 +125,7 @@ struct key_type {
70117 /* internal fields */
70118 struct list_head link; /* link in types list */
70119 struct lock_class_key lock_class; /* key->sem lock class */
70120-};
70121+} __do_const;
70122
70123 extern struct key_type key_type_keyring;
70124
70125diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
70126index c6e091b..a940adf 100644
70127--- a/include/linux/kgdb.h
70128+++ b/include/linux/kgdb.h
70129@@ -52,7 +52,7 @@ extern int kgdb_connected;
70130 extern int kgdb_io_module_registered;
70131
70132 extern atomic_t kgdb_setting_breakpoint;
70133-extern atomic_t kgdb_cpu_doing_single_step;
70134+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
70135
70136 extern struct task_struct *kgdb_usethread;
70137 extern struct task_struct *kgdb_contthread;
70138@@ -254,7 +254,7 @@ struct kgdb_arch {
70139 void (*correct_hw_break)(void);
70140
70141 void (*enable_nmi)(bool on);
70142-};
70143+} __do_const;
70144
70145 /**
70146 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
70147@@ -279,7 +279,7 @@ struct kgdb_io {
70148 void (*pre_exception) (void);
70149 void (*post_exception) (void);
70150 int is_console;
70151-};
70152+} __do_const;
70153
70154 extern struct kgdb_arch arch_kgdb_ops;
70155
70156diff --git a/include/linux/kmod.h b/include/linux/kmod.h
70157index 5398d58..5883a34 100644
70158--- a/include/linux/kmod.h
70159+++ b/include/linux/kmod.h
70160@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
70161 * usually useless though. */
70162 extern __printf(2, 3)
70163 int __request_module(bool wait, const char *name, ...);
70164+extern __printf(3, 4)
70165+int ___request_module(bool wait, char *param_name, const char *name, ...);
70166 #define request_module(mod...) __request_module(true, mod)
70167 #define request_module_nowait(mod...) __request_module(false, mod)
70168 #define try_then_request_module(x, mod...) \
70169diff --git a/include/linux/kobject.h b/include/linux/kobject.h
70170index 939b112..ed6ed51 100644
70171--- a/include/linux/kobject.h
70172+++ b/include/linux/kobject.h
70173@@ -111,7 +111,7 @@ struct kobj_type {
70174 struct attribute **default_attrs;
70175 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
70176 const void *(*namespace)(struct kobject *kobj);
70177-};
70178+} __do_const;
70179
70180 struct kobj_uevent_env {
70181 char *envp[UEVENT_NUM_ENVP];
70182@@ -134,6 +134,7 @@ struct kobj_attribute {
70183 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
70184 const char *buf, size_t count);
70185 };
70186+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
70187
70188 extern const struct sysfs_ops kobj_sysfs_ops;
70189
70190diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
70191index f66b065..c2c29b4 100644
70192--- a/include/linux/kobject_ns.h
70193+++ b/include/linux/kobject_ns.h
70194@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
70195 const void *(*netlink_ns)(struct sock *sk);
70196 const void *(*initial_ns)(void);
70197 void (*drop_ns)(void *);
70198-};
70199+} __do_const;
70200
70201 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
70202 int kobj_ns_type_registered(enum kobj_ns_type type);
70203diff --git a/include/linux/kref.h b/include/linux/kref.h
70204index 7419c02..aa2f02d 100644
70205--- a/include/linux/kref.h
70206+++ b/include/linux/kref.h
70207@@ -65,7 +65,7 @@ static inline void kref_get(struct kref *kref)
70208 static inline int kref_sub(struct kref *kref, unsigned int count,
70209 void (*release)(struct kref *kref))
70210 {
70211- WARN_ON(release == NULL);
70212+ BUG_ON(release == NULL);
70213
70214 if (atomic_sub_and_test((int) count, &kref->refcount)) {
70215 release(kref);
70216diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
70217index c139582..0b5b102 100644
70218--- a/include/linux/kvm_host.h
70219+++ b/include/linux/kvm_host.h
70220@@ -424,7 +424,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
70221 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
70222 void vcpu_put(struct kvm_vcpu *vcpu);
70223
70224-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70225+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70226 struct module *module);
70227 void kvm_exit(void);
70228
70229@@ -582,7 +582,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
70230 struct kvm_guest_debug *dbg);
70231 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
70232
70233-int kvm_arch_init(void *opaque);
70234+int kvm_arch_init(const void *opaque);
70235 void kvm_arch_exit(void);
70236
70237 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
70238diff --git a/include/linux/libata.h b/include/linux/libata.h
70239index eae7a05..2cdd875 100644
70240--- a/include/linux/libata.h
70241+++ b/include/linux/libata.h
70242@@ -919,7 +919,7 @@ struct ata_port_operations {
70243 * fields must be pointers.
70244 */
70245 const struct ata_port_operations *inherits;
70246-};
70247+} __do_const;
70248
70249 struct ata_port_info {
70250 unsigned long flags;
70251diff --git a/include/linux/list.h b/include/linux/list.h
70252index 6a1f8df..eaec1ff 100644
70253--- a/include/linux/list.h
70254+++ b/include/linux/list.h
70255@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
70256 extern void list_del(struct list_head *entry);
70257 #endif
70258
70259+extern void __pax_list_add(struct list_head *new,
70260+ struct list_head *prev,
70261+ struct list_head *next);
70262+static inline void pax_list_add(struct list_head *new, struct list_head *head)
70263+{
70264+ __pax_list_add(new, head, head->next);
70265+}
70266+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
70267+{
70268+ __pax_list_add(new, head->prev, head);
70269+}
70270+extern void pax_list_del(struct list_head *entry);
70271+
70272 /**
70273 * list_replace - replace old entry by new one
70274 * @old : the element to be replaced
70275@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
70276 INIT_LIST_HEAD(entry);
70277 }
70278
70279+extern void pax_list_del_init(struct list_head *entry);
70280+
70281 /**
70282 * list_move - delete from one list and add as another's head
70283 * @list: the entry to move
70284diff --git a/include/linux/math64.h b/include/linux/math64.h
70285index b8ba855..0148090 100644
70286--- a/include/linux/math64.h
70287+++ b/include/linux/math64.h
70288@@ -14,7 +14,7 @@
70289 * This is commonly provided by 32bit archs to provide an optimized 64bit
70290 * divide.
70291 */
70292-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70293+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70294 {
70295 *remainder = dividend % divisor;
70296 return dividend / divisor;
70297@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
70298 #define div64_long(x,y) div_s64((x),(y))
70299
70300 #ifndef div_u64_rem
70301-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70302+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70303 {
70304 *remainder = do_div(dividend, divisor);
70305 return dividend;
70306@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
70307 * divide.
70308 */
70309 #ifndef div_u64
70310-static inline u64 div_u64(u64 dividend, u32 divisor)
70311+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
70312 {
70313 u32 remainder;
70314 return div_u64_rem(dividend, divisor, &remainder);
70315diff --git a/include/linux/mm.h b/include/linux/mm.h
70316index e2091b8..3c7b38c 100644
70317--- a/include/linux/mm.h
70318+++ b/include/linux/mm.h
70319@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
70320 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
70321 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
70322 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
70323+
70324+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70325+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
70326+#endif
70327+
70328 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
70329
70330 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
70331@@ -202,8 +207,8 @@ struct vm_operations_struct {
70332 /* called by access_process_vm when get_user_pages() fails, typically
70333 * for use by special VMAs that can switch between memory and hardware
70334 */
70335- int (*access)(struct vm_area_struct *vma, unsigned long addr,
70336- void *buf, int len, int write);
70337+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
70338+ void *buf, size_t len, int write);
70339 #ifdef CONFIG_NUMA
70340 /*
70341 * set_policy() op must add a reference to any non-NULL @new mempolicy
70342@@ -233,6 +238,7 @@ struct vm_operations_struct {
70343 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
70344 unsigned long size, pgoff_t pgoff);
70345 };
70346+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
70347
70348 struct mmu_gather;
70349 struct inode;
70350@@ -970,8 +976,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
70351 unsigned long *pfn);
70352 int follow_phys(struct vm_area_struct *vma, unsigned long address,
70353 unsigned int flags, unsigned long *prot, resource_size_t *phys);
70354-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70355- void *buf, int len, int write);
70356+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70357+ void *buf, size_t len, int write);
70358
70359 static inline void unmap_shared_mapping_range(struct address_space *mapping,
70360 loff_t const holebegin, loff_t const holelen)
70361@@ -1010,9 +1016,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
70362 }
70363 #endif
70364
70365-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
70366-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
70367- void *buf, int len, int write);
70368+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
70369+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
70370+ void *buf, size_t len, int write);
70371
70372 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70373 unsigned long start, unsigned long nr_pages,
70374@@ -1043,34 +1049,6 @@ int set_page_dirty(struct page *page);
70375 int set_page_dirty_lock(struct page *page);
70376 int clear_page_dirty_for_io(struct page *page);
70377
70378-/* Is the vma a continuation of the stack vma above it? */
70379-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
70380-{
70381- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
70382-}
70383-
70384-static inline int stack_guard_page_start(struct vm_area_struct *vma,
70385- unsigned long addr)
70386-{
70387- return (vma->vm_flags & VM_GROWSDOWN) &&
70388- (vma->vm_start == addr) &&
70389- !vma_growsdown(vma->vm_prev, addr);
70390-}
70391-
70392-/* Is the vma a continuation of the stack vma below it? */
70393-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
70394-{
70395- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
70396-}
70397-
70398-static inline int stack_guard_page_end(struct vm_area_struct *vma,
70399- unsigned long addr)
70400-{
70401- return (vma->vm_flags & VM_GROWSUP) &&
70402- (vma->vm_end == addr) &&
70403- !vma_growsup(vma->vm_next, addr);
70404-}
70405-
70406 extern pid_t
70407 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
70408
70409@@ -1173,6 +1151,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
70410 }
70411 #endif
70412
70413+#ifdef CONFIG_MMU
70414+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
70415+#else
70416+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70417+{
70418+ return __pgprot(0);
70419+}
70420+#endif
70421+
70422 int vma_wants_writenotify(struct vm_area_struct *vma);
70423
70424 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
70425@@ -1191,8 +1178,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
70426 {
70427 return 0;
70428 }
70429+
70430+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
70431+ unsigned long address)
70432+{
70433+ return 0;
70434+}
70435 #else
70436 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70437+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70438 #endif
70439
70440 #ifdef __PAGETABLE_PMD_FOLDED
70441@@ -1201,8 +1195,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
70442 {
70443 return 0;
70444 }
70445+
70446+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
70447+ unsigned long address)
70448+{
70449+ return 0;
70450+}
70451 #else
70452 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
70453+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
70454 #endif
70455
70456 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
70457@@ -1220,11 +1221,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
70458 NULL: pud_offset(pgd, address);
70459 }
70460
70461+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70462+{
70463+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
70464+ NULL: pud_offset(pgd, address);
70465+}
70466+
70467 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70468 {
70469 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
70470 NULL: pmd_offset(pud, address);
70471 }
70472+
70473+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70474+{
70475+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
70476+ NULL: pmd_offset(pud, address);
70477+}
70478 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
70479
70480 #if USE_SPLIT_PTLOCKS
70481@@ -1455,6 +1468,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70482 unsigned long len, unsigned long prot, unsigned long flags,
70483 unsigned long pgoff, unsigned long *populate);
70484 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
70485+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
70486
70487 #ifdef CONFIG_MMU
70488 extern int __mm_populate(unsigned long addr, unsigned long len,
70489@@ -1483,10 +1497,11 @@ struct vm_unmapped_area_info {
70490 unsigned long high_limit;
70491 unsigned long align_mask;
70492 unsigned long align_offset;
70493+ unsigned long threadstack_offset;
70494 };
70495
70496-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
70497-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
70498+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
70499+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
70500
70501 /*
70502 * Search for an unmapped address range.
70503@@ -1498,7 +1513,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
70504 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
70505 */
70506 static inline unsigned long
70507-vm_unmapped_area(struct vm_unmapped_area_info *info)
70508+vm_unmapped_area(const struct vm_unmapped_area_info *info)
70509 {
70510 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
70511 return unmapped_area(info);
70512@@ -1561,6 +1576,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
70513 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
70514 struct vm_area_struct **pprev);
70515
70516+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
70517+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
70518+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
70519+
70520 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
70521 NULL if none. Assume start_addr < end_addr. */
70522 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
70523@@ -1589,15 +1608,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
70524 return vma;
70525 }
70526
70527-#ifdef CONFIG_MMU
70528-pgprot_t vm_get_page_prot(unsigned long vm_flags);
70529-#else
70530-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
70531-{
70532- return __pgprot(0);
70533-}
70534-#endif
70535-
70536 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
70537 unsigned long change_prot_numa(struct vm_area_struct *vma,
70538 unsigned long start, unsigned long end);
70539@@ -1649,6 +1659,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
70540 static inline void vm_stat_account(struct mm_struct *mm,
70541 unsigned long flags, struct file *file, long pages)
70542 {
70543+
70544+#ifdef CONFIG_PAX_RANDMMAP
70545+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
70546+#endif
70547+
70548 mm->total_vm += pages;
70549 }
70550 #endif /* CONFIG_PROC_FS */
70551@@ -1725,7 +1740,7 @@ extern int unpoison_memory(unsigned long pfn);
70552 extern int sysctl_memory_failure_early_kill;
70553 extern int sysctl_memory_failure_recovery;
70554 extern void shake_page(struct page *p, int access);
70555-extern atomic_long_t num_poisoned_pages;
70556+extern atomic_long_unchecked_t num_poisoned_pages;
70557 extern int soft_offline_page(struct page *page, int flags);
70558
70559 extern void dump_page(struct page *page);
70560@@ -1756,5 +1771,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
70561 static inline bool page_is_guard(struct page *page) { return false; }
70562 #endif /* CONFIG_DEBUG_PAGEALLOC */
70563
70564+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70565+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
70566+#else
70567+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
70568+#endif
70569+
70570 #endif /* __KERNEL__ */
70571 #endif /* _LINUX_MM_H */
70572diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
70573index ace9a5f..81bdb59 100644
70574--- a/include/linux/mm_types.h
70575+++ b/include/linux/mm_types.h
70576@@ -289,6 +289,8 @@ struct vm_area_struct {
70577 #ifdef CONFIG_NUMA
70578 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
70579 #endif
70580+
70581+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
70582 };
70583
70584 struct core_thread {
70585@@ -437,6 +439,24 @@ struct mm_struct {
70586 int first_nid;
70587 #endif
70588 struct uprobes_state uprobes_state;
70589+
70590+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70591+ unsigned long pax_flags;
70592+#endif
70593+
70594+#ifdef CONFIG_PAX_DLRESOLVE
70595+ unsigned long call_dl_resolve;
70596+#endif
70597+
70598+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
70599+ unsigned long call_syscall;
70600+#endif
70601+
70602+#ifdef CONFIG_PAX_ASLR
70603+ unsigned long delta_mmap; /* randomized offset */
70604+ unsigned long delta_stack; /* randomized offset */
70605+#endif
70606+
70607 };
70608
70609 /* first nid will either be a valid NID or one of these values */
70610diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
70611index c5d5278..f0b68c8 100644
70612--- a/include/linux/mmiotrace.h
70613+++ b/include/linux/mmiotrace.h
70614@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
70615 /* Called from ioremap.c */
70616 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
70617 void __iomem *addr);
70618-extern void mmiotrace_iounmap(volatile void __iomem *addr);
70619+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
70620
70621 /* For anyone to insert markers. Remember trailing newline. */
70622 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
70623@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
70624 {
70625 }
70626
70627-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
70628+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
70629 {
70630 }
70631
70632diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
70633index c74092e..b663967 100644
70634--- a/include/linux/mmzone.h
70635+++ b/include/linux/mmzone.h
70636@@ -396,7 +396,7 @@ struct zone {
70637 unsigned long flags; /* zone flags, see below */
70638
70639 /* Zone statistics */
70640- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70641+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70642
70643 /*
70644 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
70645diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
70646index 779cf7c..e6768240 100644
70647--- a/include/linux/mod_devicetable.h
70648+++ b/include/linux/mod_devicetable.h
70649@@ -12,7 +12,7 @@
70650 typedef unsigned long kernel_ulong_t;
70651 #endif
70652
70653-#define PCI_ANY_ID (~0)
70654+#define PCI_ANY_ID ((__u16)~0)
70655
70656 struct pci_device_id {
70657 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
70658@@ -138,7 +138,7 @@ struct usb_device_id {
70659 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
70660 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
70661
70662-#define HID_ANY_ID (~0)
70663+#define HID_ANY_ID (~0U)
70664 #define HID_BUS_ANY 0xffff
70665 #define HID_GROUP_ANY 0x0000
70666
70667@@ -464,7 +464,7 @@ struct dmi_system_id {
70668 const char *ident;
70669 struct dmi_strmatch matches[4];
70670 void *driver_data;
70671-};
70672+} __do_const;
70673 /*
70674 * struct dmi_device_id appears during expansion of
70675 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
70676diff --git a/include/linux/module.h b/include/linux/module.h
70677index ead1b57..81a3b6c 100644
70678--- a/include/linux/module.h
70679+++ b/include/linux/module.h
70680@@ -17,9 +17,11 @@
70681 #include <linux/moduleparam.h>
70682 #include <linux/tracepoint.h>
70683 #include <linux/export.h>
70684+#include <linux/fs.h>
70685
70686 #include <linux/percpu.h>
70687 #include <asm/module.h>
70688+#include <asm/pgtable.h>
70689
70690 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
70691 #define MODULE_SIG_STRING "~Module signature appended~\n"
70692@@ -54,12 +56,13 @@ struct module_attribute {
70693 int (*test)(struct module *);
70694 void (*free)(struct module *);
70695 };
70696+typedef struct module_attribute __no_const module_attribute_no_const;
70697
70698 struct module_version_attribute {
70699 struct module_attribute mattr;
70700 const char *module_name;
70701 const char *version;
70702-} __attribute__ ((__aligned__(sizeof(void *))));
70703+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
70704
70705 extern ssize_t __modver_version_show(struct module_attribute *,
70706 struct module_kobject *, char *);
70707@@ -232,7 +235,7 @@ struct module
70708
70709 /* Sysfs stuff. */
70710 struct module_kobject mkobj;
70711- struct module_attribute *modinfo_attrs;
70712+ module_attribute_no_const *modinfo_attrs;
70713 const char *version;
70714 const char *srcversion;
70715 struct kobject *holders_dir;
70716@@ -281,19 +284,16 @@ struct module
70717 int (*init)(void);
70718
70719 /* If this is non-NULL, vfree after init() returns */
70720- void *module_init;
70721+ void *module_init_rx, *module_init_rw;
70722
70723 /* Here is the actual code + data, vfree'd on unload. */
70724- void *module_core;
70725+ void *module_core_rx, *module_core_rw;
70726
70727 /* Here are the sizes of the init and core sections */
70728- unsigned int init_size, core_size;
70729+ unsigned int init_size_rw, core_size_rw;
70730
70731 /* The size of the executable code in each section. */
70732- unsigned int init_text_size, core_text_size;
70733-
70734- /* Size of RO sections of the module (text+rodata) */
70735- unsigned int init_ro_size, core_ro_size;
70736+ unsigned int init_size_rx, core_size_rx;
70737
70738 /* Arch-specific module values */
70739 struct mod_arch_specific arch;
70740@@ -349,6 +349,10 @@ struct module
70741 #ifdef CONFIG_EVENT_TRACING
70742 struct ftrace_event_call **trace_events;
70743 unsigned int num_trace_events;
70744+ struct file_operations trace_id;
70745+ struct file_operations trace_enable;
70746+ struct file_operations trace_format;
70747+ struct file_operations trace_filter;
70748 #endif
70749 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
70750 unsigned int num_ftrace_callsites;
70751@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
70752 bool is_module_percpu_address(unsigned long addr);
70753 bool is_module_text_address(unsigned long addr);
70754
70755+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
70756+{
70757+
70758+#ifdef CONFIG_PAX_KERNEXEC
70759+ if (ktla_ktva(addr) >= (unsigned long)start &&
70760+ ktla_ktva(addr) < (unsigned long)start + size)
70761+ return 1;
70762+#endif
70763+
70764+ return ((void *)addr >= start && (void *)addr < start + size);
70765+}
70766+
70767+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
70768+{
70769+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
70770+}
70771+
70772+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
70773+{
70774+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
70775+}
70776+
70777+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
70778+{
70779+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
70780+}
70781+
70782+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
70783+{
70784+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
70785+}
70786+
70787 static inline int within_module_core(unsigned long addr, const struct module *mod)
70788 {
70789- return (unsigned long)mod->module_core <= addr &&
70790- addr < (unsigned long)mod->module_core + mod->core_size;
70791+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
70792 }
70793
70794 static inline int within_module_init(unsigned long addr, const struct module *mod)
70795 {
70796- return (unsigned long)mod->module_init <= addr &&
70797- addr < (unsigned long)mod->module_init + mod->init_size;
70798+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
70799 }
70800
70801 /* Search for module by name: must hold module_mutex. */
70802diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
70803index 560ca53..ef621ef 100644
70804--- a/include/linux/moduleloader.h
70805+++ b/include/linux/moduleloader.h
70806@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
70807 sections. Returns NULL on failure. */
70808 void *module_alloc(unsigned long size);
70809
70810+#ifdef CONFIG_PAX_KERNEXEC
70811+void *module_alloc_exec(unsigned long size);
70812+#else
70813+#define module_alloc_exec(x) module_alloc(x)
70814+#endif
70815+
70816 /* Free memory returned from module_alloc. */
70817 void module_free(struct module *mod, void *module_region);
70818
70819+#ifdef CONFIG_PAX_KERNEXEC
70820+void module_free_exec(struct module *mod, void *module_region);
70821+#else
70822+#define module_free_exec(x, y) module_free((x), (y))
70823+#endif
70824+
70825 /*
70826 * Apply the given relocation to the (simplified) ELF. Return -error
70827 * or 0.
70828@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
70829 unsigned int relsec,
70830 struct module *me)
70831 {
70832+#ifdef CONFIG_MODULES
70833 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70834+#endif
70835 return -ENOEXEC;
70836 }
70837 #endif
70838@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
70839 unsigned int relsec,
70840 struct module *me)
70841 {
70842+#ifdef CONFIG_MODULES
70843 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70844+#endif
70845 return -ENOEXEC;
70846 }
70847 #endif
70848diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
70849index 137b419..fe663ec 100644
70850--- a/include/linux/moduleparam.h
70851+++ b/include/linux/moduleparam.h
70852@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
70853 * @len is usually just sizeof(string).
70854 */
70855 #define module_param_string(name, string, len, perm) \
70856- static const struct kparam_string __param_string_##name \
70857+ static const struct kparam_string __param_string_##name __used \
70858 = { len, string }; \
70859 __module_param_call(MODULE_PARAM_PREFIX, name, \
70860 &param_ops_string, \
70861@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
70862 */
70863 #define module_param_array_named(name, array, type, nump, perm) \
70864 param_check_##type(name, &(array)[0]); \
70865- static const struct kparam_array __param_arr_##name \
70866+ static const struct kparam_array __param_arr_##name __used \
70867 = { .max = ARRAY_SIZE(array), .num = nump, \
70868 .ops = &param_ops_##type, \
70869 .elemsize = sizeof(array[0]), .elem = array }; \
70870diff --git a/include/linux/namei.h b/include/linux/namei.h
70871index 5a5ff57..5ae5070 100644
70872--- a/include/linux/namei.h
70873+++ b/include/linux/namei.h
70874@@ -19,7 +19,7 @@ struct nameidata {
70875 unsigned seq;
70876 int last_type;
70877 unsigned depth;
70878- char *saved_names[MAX_NESTED_LINKS + 1];
70879+ const char *saved_names[MAX_NESTED_LINKS + 1];
70880 };
70881
70882 /*
70883@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
70884
70885 extern void nd_jump_link(struct nameidata *nd, struct path *path);
70886
70887-static inline void nd_set_link(struct nameidata *nd, char *path)
70888+static inline void nd_set_link(struct nameidata *nd, const char *path)
70889 {
70890 nd->saved_names[nd->depth] = path;
70891 }
70892
70893-static inline char *nd_get_link(struct nameidata *nd)
70894+static inline const char *nd_get_link(const struct nameidata *nd)
70895 {
70896 return nd->saved_names[nd->depth];
70897 }
70898diff --git a/include/linux/net.h b/include/linux/net.h
70899index aa16731..514b875 100644
70900--- a/include/linux/net.h
70901+++ b/include/linux/net.h
70902@@ -183,7 +183,7 @@ struct net_proto_family {
70903 int (*create)(struct net *net, struct socket *sock,
70904 int protocol, int kern);
70905 struct module *owner;
70906-};
70907+} __do_const;
70908
70909 struct iovec;
70910 struct kvec;
70911diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
70912index 6151e90..2e0afb0 100644
70913--- a/include/linux/netdevice.h
70914+++ b/include/linux/netdevice.h
70915@@ -1028,6 +1028,7 @@ struct net_device_ops {
70916 int (*ndo_change_carrier)(struct net_device *dev,
70917 bool new_carrier);
70918 };
70919+typedef struct net_device_ops __no_const net_device_ops_no_const;
70920
70921 /*
70922 * The DEVICE structure.
70923@@ -1094,7 +1095,7 @@ struct net_device {
70924 int iflink;
70925
70926 struct net_device_stats stats;
70927- atomic_long_t rx_dropped; /* dropped packets by core network
70928+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
70929 * Do not use this in drivers.
70930 */
70931
70932diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
70933index ee14284..bc65d63 100644
70934--- a/include/linux/netfilter.h
70935+++ b/include/linux/netfilter.h
70936@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
70937 #endif
70938 /* Use the module struct to lock set/get code in place */
70939 struct module *owner;
70940-};
70941+} __do_const;
70942
70943 /* Function to register/unregister hook points. */
70944 int nf_register_hook(struct nf_hook_ops *reg);
70945diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
70946index 7958e84..ed74d7a 100644
70947--- a/include/linux/netfilter/ipset/ip_set.h
70948+++ b/include/linux/netfilter/ipset/ip_set.h
70949@@ -98,7 +98,7 @@ struct ip_set_type_variant {
70950 /* Return true if "b" set is the same as "a"
70951 * according to the create set parameters */
70952 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
70953-};
70954+} __do_const;
70955
70956 /* The core set type structure */
70957 struct ip_set_type {
70958diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
70959index ecbb8e4..8a1c4e1 100644
70960--- a/include/linux/netfilter/nfnetlink.h
70961+++ b/include/linux/netfilter/nfnetlink.h
70962@@ -16,7 +16,7 @@ struct nfnl_callback {
70963 const struct nlattr * const cda[]);
70964 const struct nla_policy *policy; /* netlink attribute policy */
70965 const u_int16_t attr_count; /* number of nlattr's */
70966-};
70967+} __do_const;
70968
70969 struct nfnetlink_subsystem {
70970 const char *name;
70971diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
70972new file mode 100644
70973index 0000000..33f4af8
70974--- /dev/null
70975+++ b/include/linux/netfilter/xt_gradm.h
70976@@ -0,0 +1,9 @@
70977+#ifndef _LINUX_NETFILTER_XT_GRADM_H
70978+#define _LINUX_NETFILTER_XT_GRADM_H 1
70979+
70980+struct xt_gradm_mtinfo {
70981+ __u16 flags;
70982+ __u16 invflags;
70983+};
70984+
70985+#endif
70986diff --git a/include/linux/nls.h b/include/linux/nls.h
70987index 5dc635f..35f5e11 100644
70988--- a/include/linux/nls.h
70989+++ b/include/linux/nls.h
70990@@ -31,7 +31,7 @@ struct nls_table {
70991 const unsigned char *charset2upper;
70992 struct module *owner;
70993 struct nls_table *next;
70994-};
70995+} __do_const;
70996
70997 /* this value hold the maximum octet of charset */
70998 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
70999diff --git a/include/linux/notifier.h b/include/linux/notifier.h
71000index d65746e..62e72c2 100644
71001--- a/include/linux/notifier.h
71002+++ b/include/linux/notifier.h
71003@@ -51,7 +51,8 @@ struct notifier_block {
71004 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
71005 struct notifier_block __rcu *next;
71006 int priority;
71007-};
71008+} __do_const;
71009+typedef struct notifier_block __no_const notifier_block_no_const;
71010
71011 struct atomic_notifier_head {
71012 spinlock_t lock;
71013diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
71014index a4c5624..79d6d88 100644
71015--- a/include/linux/oprofile.h
71016+++ b/include/linux/oprofile.h
71017@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
71018 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
71019 char const * name, ulong * val);
71020
71021-/** Create a file for read-only access to an atomic_t. */
71022+/** Create a file for read-only access to an atomic_unchecked_t. */
71023 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
71024- char const * name, atomic_t * val);
71025+ char const * name, atomic_unchecked_t * val);
71026
71027 /** create a directory */
71028 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
71029diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
71030index 45fc162..01a4068 100644
71031--- a/include/linux/pci_hotplug.h
71032+++ b/include/linux/pci_hotplug.h
71033@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
71034 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
71035 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
71036 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
71037-};
71038+} __do_const;
71039+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
71040
71041 /**
71042 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
71043diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
71044index 2f522a3..494e45f 100644
71045--- a/include/linux/perf_event.h
71046+++ b/include/linux/perf_event.h
71047@@ -333,8 +333,8 @@ struct perf_event {
71048
71049 enum perf_event_active_state state;
71050 unsigned int attach_state;
71051- local64_t count;
71052- atomic64_t child_count;
71053+ local64_t count; /* PaX: fix it one day */
71054+ atomic64_unchecked_t child_count;
71055
71056 /*
71057 * These are the total time in nanoseconds that the event
71058@@ -385,8 +385,8 @@ struct perf_event {
71059 * These accumulate total time (in nanoseconds) that children
71060 * events have been enabled and running, respectively.
71061 */
71062- atomic64_t child_total_time_enabled;
71063- atomic64_t child_total_time_running;
71064+ atomic64_unchecked_t child_total_time_enabled;
71065+ atomic64_unchecked_t child_total_time_running;
71066
71067 /*
71068 * Protect attach/detach and child_list:
71069@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
71070 entry->ip[entry->nr++] = ip;
71071 }
71072
71073-extern int sysctl_perf_event_paranoid;
71074+extern int sysctl_perf_event_legitimately_concerned;
71075 extern int sysctl_perf_event_mlock;
71076 extern int sysctl_perf_event_sample_rate;
71077
71078@@ -711,19 +711,24 @@ extern int perf_proc_update_handler(struct ctl_table *table, int write,
71079 void __user *buffer, size_t *lenp,
71080 loff_t *ppos);
71081
71082+static inline bool perf_paranoid_any(void)
71083+{
71084+ return sysctl_perf_event_legitimately_concerned > 2;
71085+}
71086+
71087 static inline bool perf_paranoid_tracepoint_raw(void)
71088 {
71089- return sysctl_perf_event_paranoid > -1;
71090+ return sysctl_perf_event_legitimately_concerned > -1;
71091 }
71092
71093 static inline bool perf_paranoid_cpu(void)
71094 {
71095- return sysctl_perf_event_paranoid > 0;
71096+ return sysctl_perf_event_legitimately_concerned > 0;
71097 }
71098
71099 static inline bool perf_paranoid_kernel(void)
71100 {
71101- return sysctl_perf_event_paranoid > 1;
71102+ return sysctl_perf_event_legitimately_concerned > 1;
71103 }
71104
71105 extern void perf_event_init(void);
71106@@ -811,7 +816,7 @@ static inline void perf_restore_debug_store(void) { }
71107 */
71108 #define perf_cpu_notifier(fn) \
71109 do { \
71110- static struct notifier_block fn##_nb __cpuinitdata = \
71111+ static struct notifier_block fn##_nb = \
71112 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
71113 unsigned long cpu = smp_processor_id(); \
71114 unsigned long flags; \
71115@@ -830,7 +835,7 @@ do { \
71116 struct perf_pmu_events_attr {
71117 struct device_attribute attr;
71118 u64 id;
71119-};
71120+} __do_const;
71121
71122 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
71123 static struct perf_pmu_events_attr _var = { \
71124diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
71125index ad1a427..6419649 100644
71126--- a/include/linux/pipe_fs_i.h
71127+++ b/include/linux/pipe_fs_i.h
71128@@ -45,9 +45,9 @@ struct pipe_buffer {
71129 struct pipe_inode_info {
71130 wait_queue_head_t wait;
71131 unsigned int nrbufs, curbuf, buffers;
71132- unsigned int readers;
71133- unsigned int writers;
71134- unsigned int waiting_writers;
71135+ atomic_t readers;
71136+ atomic_t writers;
71137+ atomic_t waiting_writers;
71138 unsigned int r_counter;
71139 unsigned int w_counter;
71140 struct page *tmp_page;
71141diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
71142index 5f28cae..3d23723 100644
71143--- a/include/linux/platform_data/usb-ehci-s5p.h
71144+++ b/include/linux/platform_data/usb-ehci-s5p.h
71145@@ -14,7 +14,7 @@
71146 struct s5p_ehci_platdata {
71147 int (*phy_init)(struct platform_device *pdev, int type);
71148 int (*phy_exit)(struct platform_device *pdev, int type);
71149-};
71150+} __no_const;
71151
71152 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
71153
71154diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
71155index c256c59..8ea94c7 100644
71156--- a/include/linux/platform_data/usb-exynos.h
71157+++ b/include/linux/platform_data/usb-exynos.h
71158@@ -14,7 +14,7 @@
71159 struct exynos4_ohci_platdata {
71160 int (*phy_init)(struct platform_device *pdev, int type);
71161 int (*phy_exit)(struct platform_device *pdev, int type);
71162-};
71163+} __no_const;
71164
71165 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
71166
71167diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
71168index 7c1d252..c5c773e 100644
71169--- a/include/linux/pm_domain.h
71170+++ b/include/linux/pm_domain.h
71171@@ -48,7 +48,7 @@ struct gpd_dev_ops {
71172
71173 struct gpd_cpu_data {
71174 unsigned int saved_exit_latency;
71175- struct cpuidle_state *idle_state;
71176+ cpuidle_state_no_const *idle_state;
71177 };
71178
71179 struct generic_pm_domain {
71180diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
71181index 7d7e09e..8671ef8 100644
71182--- a/include/linux/pm_runtime.h
71183+++ b/include/linux/pm_runtime.h
71184@@ -104,7 +104,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
71185
71186 static inline void pm_runtime_mark_last_busy(struct device *dev)
71187 {
71188- ACCESS_ONCE(dev->power.last_busy) = jiffies;
71189+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
71190 }
71191
71192 #else /* !CONFIG_PM_RUNTIME */
71193diff --git a/include/linux/pnp.h b/include/linux/pnp.h
71194index 195aafc..49a7bc2 100644
71195--- a/include/linux/pnp.h
71196+++ b/include/linux/pnp.h
71197@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
71198 struct pnp_fixup {
71199 char id[7];
71200 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
71201-};
71202+} __do_const;
71203
71204 /* config parameters */
71205 #define PNP_CONFIG_NORMAL 0x0001
71206diff --git a/include/linux/poison.h b/include/linux/poison.h
71207index 2110a81..13a11bb 100644
71208--- a/include/linux/poison.h
71209+++ b/include/linux/poison.h
71210@@ -19,8 +19,8 @@
71211 * under normal circumstances, used to verify that nobody uses
71212 * non-initialized list entries.
71213 */
71214-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
71215-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
71216+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
71217+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
71218
71219 /********** include/linux/timer.h **********/
71220 /*
71221diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
71222index c0f44c2..1572583 100644
71223--- a/include/linux/power/smartreflex.h
71224+++ b/include/linux/power/smartreflex.h
71225@@ -238,7 +238,7 @@ struct omap_sr_class_data {
71226 int (*notify)(struct omap_sr *sr, u32 status);
71227 u8 notify_flags;
71228 u8 class_type;
71229-};
71230+} __do_const;
71231
71232 /**
71233 * struct omap_sr_nvalue_table - Smartreflex n-target value info
71234diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
71235index 4ea1d37..80f4b33 100644
71236--- a/include/linux/ppp-comp.h
71237+++ b/include/linux/ppp-comp.h
71238@@ -84,7 +84,7 @@ struct compressor {
71239 struct module *owner;
71240 /* Extra skb space needed by the compressor algorithm */
71241 unsigned int comp_extra;
71242-};
71243+} __do_const;
71244
71245 /*
71246 * The return value from decompress routine is the length of the
71247diff --git a/include/linux/printk.h b/include/linux/printk.h
71248index 822171f..12b30e8 100644
71249--- a/include/linux/printk.h
71250+++ b/include/linux/printk.h
71251@@ -98,6 +98,8 @@ int no_printk(const char *fmt, ...)
71252 extern asmlinkage __printf(1, 2)
71253 void early_printk(const char *fmt, ...);
71254
71255+extern int kptr_restrict;
71256+
71257 #ifdef CONFIG_PRINTK
71258 asmlinkage __printf(5, 0)
71259 int vprintk_emit(int facility, int level,
71260@@ -132,7 +134,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
71261
71262 extern int printk_delay_msec;
71263 extern int dmesg_restrict;
71264-extern int kptr_restrict;
71265
71266 extern void wake_up_klogd(void);
71267
71268diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
71269index 94dfb2a..88b9d3b 100644
71270--- a/include/linux/proc_fs.h
71271+++ b/include/linux/proc_fs.h
71272@@ -165,6 +165,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
71273 return proc_create_data(name, mode, parent, proc_fops, NULL);
71274 }
71275
71276+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
71277+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
71278+{
71279+#ifdef CONFIG_GRKERNSEC_PROC_USER
71280+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
71281+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71282+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
71283+#else
71284+ return proc_create_data(name, mode, parent, proc_fops, NULL);
71285+#endif
71286+}
71287+
71288 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
71289 umode_t mode, struct proc_dir_entry *base,
71290 read_proc_t *read_proc, void * data)
71291@@ -266,7 +278,7 @@ struct proc_ns_operations {
71292 void (*put)(void *ns);
71293 int (*install)(struct nsproxy *nsproxy, void *ns);
71294 unsigned int (*inum)(void *ns);
71295-};
71296+} __do_const;
71297 extern const struct proc_ns_operations netns_operations;
71298 extern const struct proc_ns_operations utsns_operations;
71299 extern const struct proc_ns_operations ipcns_operations;
71300diff --git a/include/linux/random.h b/include/linux/random.h
71301index 347ce55..880f97c 100644
71302--- a/include/linux/random.h
71303+++ b/include/linux/random.h
71304@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
71305 u32 prandom_u32_state(struct rnd_state *);
71306 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
71307
71308+static inline unsigned long pax_get_random_long(void)
71309+{
71310+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
71311+}
71312+
71313 /*
71314 * Handle minimum values for seeds
71315 */
71316diff --git a/include/linux/rculist.h b/include/linux/rculist.h
71317index 8089e35..3a0d59a 100644
71318--- a/include/linux/rculist.h
71319+++ b/include/linux/rculist.h
71320@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
71321 struct list_head *prev, struct list_head *next);
71322 #endif
71323
71324+extern void __pax_list_add_rcu(struct list_head *new,
71325+ struct list_head *prev, struct list_head *next);
71326+
71327 /**
71328 * list_add_rcu - add a new entry to rcu-protected list
71329 * @new: new entry to be added
71330@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
71331 __list_add_rcu(new, head, head->next);
71332 }
71333
71334+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
71335+{
71336+ __pax_list_add_rcu(new, head, head->next);
71337+}
71338+
71339 /**
71340 * list_add_tail_rcu - add a new entry to rcu-protected list
71341 * @new: new entry to be added
71342@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
71343 __list_add_rcu(new, head->prev, head);
71344 }
71345
71346+static inline void pax_list_add_tail_rcu(struct list_head *new,
71347+ struct list_head *head)
71348+{
71349+ __pax_list_add_rcu(new, head->prev, head);
71350+}
71351+
71352 /**
71353 * list_del_rcu - deletes entry from list without re-initialization
71354 * @entry: the element to delete from the list.
71355@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
71356 entry->prev = LIST_POISON2;
71357 }
71358
71359+extern void pax_list_del_rcu(struct list_head *entry);
71360+
71361 /**
71362 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
71363 * @n: the element to delete from the hash list.
71364diff --git a/include/linux/reboot.h b/include/linux/reboot.h
71365index 23b3630..e1bc12b 100644
71366--- a/include/linux/reboot.h
71367+++ b/include/linux/reboot.h
71368@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
71369 * Architecture-specific implementations of sys_reboot commands.
71370 */
71371
71372-extern void machine_restart(char *cmd);
71373-extern void machine_halt(void);
71374-extern void machine_power_off(void);
71375+extern void machine_restart(char *cmd) __noreturn;
71376+extern void machine_halt(void) __noreturn;
71377+extern void machine_power_off(void) __noreturn;
71378
71379 extern void machine_shutdown(void);
71380 struct pt_regs;
71381@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
71382 */
71383
71384 extern void kernel_restart_prepare(char *cmd);
71385-extern void kernel_restart(char *cmd);
71386-extern void kernel_halt(void);
71387-extern void kernel_power_off(void);
71388+extern void kernel_restart(char *cmd) __noreturn;
71389+extern void kernel_halt(void) __noreturn;
71390+extern void kernel_power_off(void) __noreturn;
71391
71392 extern int C_A_D; /* for sysctl */
71393 void ctrl_alt_del(void);
71394@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
71395 * Emergency restart, callable from an interrupt handler.
71396 */
71397
71398-extern void emergency_restart(void);
71399+extern void emergency_restart(void) __noreturn;
71400 #include <asm/emergency-restart.h>
71401
71402 #endif /* _LINUX_REBOOT_H */
71403diff --git a/include/linux/regset.h b/include/linux/regset.h
71404index 8e0c9fe..ac4d221 100644
71405--- a/include/linux/regset.h
71406+++ b/include/linux/regset.h
71407@@ -161,7 +161,8 @@ struct user_regset {
71408 unsigned int align;
71409 unsigned int bias;
71410 unsigned int core_note_type;
71411-};
71412+} __do_const;
71413+typedef struct user_regset __no_const user_regset_no_const;
71414
71415 /**
71416 * struct user_regset_view - available regsets
71417diff --git a/include/linux/relay.h b/include/linux/relay.h
71418index 91cacc3..b55ff74 100644
71419--- a/include/linux/relay.h
71420+++ b/include/linux/relay.h
71421@@ -160,7 +160,7 @@ struct rchan_callbacks
71422 * The callback should return 0 if successful, negative if not.
71423 */
71424 int (*remove_buf_file)(struct dentry *dentry);
71425-};
71426+} __no_const;
71427
71428 /*
71429 * CONFIG_RELAY kernel API, kernel/relay.c
71430diff --git a/include/linux/rio.h b/include/linux/rio.h
71431index a3e7842..d973ca6 100644
71432--- a/include/linux/rio.h
71433+++ b/include/linux/rio.h
71434@@ -339,7 +339,7 @@ struct rio_ops {
71435 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
71436 u64 rstart, u32 size, u32 flags);
71437 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
71438-};
71439+} __no_const;
71440
71441 #define RIO_RESOURCE_MEM 0x00000100
71442 #define RIO_RESOURCE_DOORBELL 0x00000200
71443diff --git a/include/linux/rmap.h b/include/linux/rmap.h
71444index 6dacb93..6174423 100644
71445--- a/include/linux/rmap.h
71446+++ b/include/linux/rmap.h
71447@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
71448 void anon_vma_init(void); /* create anon_vma_cachep */
71449 int anon_vma_prepare(struct vm_area_struct *);
71450 void unlink_anon_vmas(struct vm_area_struct *);
71451-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
71452-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
71453+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
71454+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
71455
71456 static inline void anon_vma_merge(struct vm_area_struct *vma,
71457 struct vm_area_struct *next)
71458diff --git a/include/linux/sched.h b/include/linux/sched.h
71459index be4e742..01f1387 100644
71460--- a/include/linux/sched.h
71461+++ b/include/linux/sched.h
71462@@ -62,6 +62,7 @@ struct bio_list;
71463 struct fs_struct;
71464 struct perf_event_context;
71465 struct blk_plug;
71466+struct linux_binprm;
71467
71468 /*
71469 * List of flags we want to share for kernel threads,
71470@@ -315,7 +316,7 @@ extern char __sched_text_start[], __sched_text_end[];
71471 extern int in_sched_functions(unsigned long addr);
71472
71473 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
71474-extern signed long schedule_timeout(signed long timeout);
71475+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
71476 extern signed long schedule_timeout_interruptible(signed long timeout);
71477 extern signed long schedule_timeout_killable(signed long timeout);
71478 extern signed long schedule_timeout_uninterruptible(signed long timeout);
71479@@ -329,6 +330,18 @@ struct user_namespace;
71480 #include <linux/aio.h>
71481
71482 #ifdef CONFIG_MMU
71483+
71484+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
71485+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
71486+#else
71487+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
71488+{
71489+ return 0;
71490+}
71491+#endif
71492+
71493+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
71494+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
71495 extern void arch_pick_mmap_layout(struct mm_struct *mm);
71496 extern unsigned long
71497 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
71498@@ -605,6 +618,17 @@ struct signal_struct {
71499 #ifdef CONFIG_TASKSTATS
71500 struct taskstats *stats;
71501 #endif
71502+
71503+#ifdef CONFIG_GRKERNSEC
71504+ u32 curr_ip;
71505+ u32 saved_ip;
71506+ u32 gr_saddr;
71507+ u32 gr_daddr;
71508+ u16 gr_sport;
71509+ u16 gr_dport;
71510+ u8 used_accept:1;
71511+#endif
71512+
71513 #ifdef CONFIG_AUDIT
71514 unsigned audit_tty;
71515 struct tty_audit_buf *tty_audit_buf;
71516@@ -683,6 +707,14 @@ struct user_struct {
71517 struct key *session_keyring; /* UID's default session keyring */
71518 #endif
71519
71520+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71521+ unsigned char kernel_banned;
71522+#endif
71523+#ifdef CONFIG_GRKERNSEC_BRUTE
71524+ unsigned char suid_banned;
71525+ unsigned long suid_ban_expires;
71526+#endif
71527+
71528 /* Hash table maintenance information */
71529 struct hlist_node uidhash_node;
71530 kuid_t uid;
71531@@ -1082,7 +1114,7 @@ struct sched_class {
71532 #ifdef CONFIG_FAIR_GROUP_SCHED
71533 void (*task_move_group) (struct task_struct *p, int on_rq);
71534 #endif
71535-};
71536+} __do_const;
71537
71538 struct load_weight {
71539 unsigned long weight, inv_weight;
71540@@ -1323,8 +1355,8 @@ struct task_struct {
71541 struct list_head thread_group;
71542
71543 struct completion *vfork_done; /* for vfork() */
71544- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
71545- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71546+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
71547+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71548
71549 cputime_t utime, stime, utimescaled, stimescaled;
71550 cputime_t gtime;
71551@@ -1349,11 +1381,6 @@ struct task_struct {
71552 struct task_cputime cputime_expires;
71553 struct list_head cpu_timers[3];
71554
71555-/* process credentials */
71556- const struct cred __rcu *real_cred; /* objective and real subjective task
71557- * credentials (COW) */
71558- const struct cred __rcu *cred; /* effective (overridable) subjective task
71559- * credentials (COW) */
71560 char comm[TASK_COMM_LEN]; /* executable name excluding path
71561 - access with [gs]et_task_comm (which lock
71562 it with task_lock())
71563@@ -1370,6 +1397,10 @@ struct task_struct {
71564 #endif
71565 /* CPU-specific state of this task */
71566 struct thread_struct thread;
71567+/* thread_info moved to task_struct */
71568+#ifdef CONFIG_X86
71569+ struct thread_info tinfo;
71570+#endif
71571 /* filesystem information */
71572 struct fs_struct *fs;
71573 /* open file information */
71574@@ -1443,6 +1474,10 @@ struct task_struct {
71575 gfp_t lockdep_reclaim_gfp;
71576 #endif
71577
71578+/* process credentials */
71579+ const struct cred __rcu *real_cred; /* objective and real subjective task
71580+ * credentials (COW) */
71581+
71582 /* journalling filesystem info */
71583 void *journal_info;
71584
71585@@ -1481,6 +1516,10 @@ struct task_struct {
71586 /* cg_list protected by css_set_lock and tsk->alloc_lock */
71587 struct list_head cg_list;
71588 #endif
71589+
71590+ const struct cred __rcu *cred; /* effective (overridable) subjective task
71591+ * credentials (COW) */
71592+
71593 #ifdef CONFIG_FUTEX
71594 struct robust_list_head __user *robust_list;
71595 #ifdef CONFIG_COMPAT
71596@@ -1577,8 +1616,74 @@ struct task_struct {
71597 #ifdef CONFIG_UPROBES
71598 struct uprobe_task *utask;
71599 #endif
71600+
71601+#ifdef CONFIG_GRKERNSEC
71602+ /* grsecurity */
71603+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71604+ u64 exec_id;
71605+#endif
71606+#ifdef CONFIG_GRKERNSEC_SETXID
71607+ const struct cred *delayed_cred;
71608+#endif
71609+ struct dentry *gr_chroot_dentry;
71610+ struct acl_subject_label *acl;
71611+ struct acl_role_label *role;
71612+ struct file *exec_file;
71613+ unsigned long brute_expires;
71614+ u16 acl_role_id;
71615+ /* is this the task that authenticated to the special role */
71616+ u8 acl_sp_role;
71617+ u8 is_writable;
71618+ u8 brute;
71619+ u8 gr_is_chrooted;
71620+#endif
71621+
71622 };
71623
71624+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
71625+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
71626+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
71627+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
71628+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
71629+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
71630+
71631+#ifdef CONFIG_PAX_SOFTMODE
71632+extern int pax_softmode;
71633+#endif
71634+
71635+extern int pax_check_flags(unsigned long *);
71636+
71637+/* if tsk != current then task_lock must be held on it */
71638+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
71639+static inline unsigned long pax_get_flags(struct task_struct *tsk)
71640+{
71641+ if (likely(tsk->mm))
71642+ return tsk->mm->pax_flags;
71643+ else
71644+ return 0UL;
71645+}
71646+
71647+/* if tsk != current then task_lock must be held on it */
71648+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
71649+{
71650+ if (likely(tsk->mm)) {
71651+ tsk->mm->pax_flags = flags;
71652+ return 0;
71653+ }
71654+ return -EINVAL;
71655+}
71656+#endif
71657+
71658+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
71659+extern void pax_set_initial_flags(struct linux_binprm *bprm);
71660+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
71661+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
71662+#endif
71663+
71664+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
71665+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
71666+extern void pax_report_refcount_overflow(struct pt_regs *regs);
71667+
71668 /* Future-safe accessor for struct task_struct's cpus_allowed. */
71669 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
71670
71671@@ -1637,7 +1742,7 @@ struct pid_namespace;
71672 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
71673 struct pid_namespace *ns);
71674
71675-static inline pid_t task_pid_nr(struct task_struct *tsk)
71676+static inline pid_t task_pid_nr(const struct task_struct *tsk)
71677 {
71678 return tsk->pid;
71679 }
71680@@ -2073,7 +2178,9 @@ void yield(void);
71681 extern struct exec_domain default_exec_domain;
71682
71683 union thread_union {
71684+#ifndef CONFIG_X86
71685 struct thread_info thread_info;
71686+#endif
71687 unsigned long stack[THREAD_SIZE/sizeof(long)];
71688 };
71689
71690@@ -2106,6 +2213,7 @@ extern struct pid_namespace init_pid_ns;
71691 */
71692
71693 extern struct task_struct *find_task_by_vpid(pid_t nr);
71694+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
71695 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
71696 struct pid_namespace *ns);
71697
71698@@ -2272,7 +2380,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
71699 extern void exit_itimers(struct signal_struct *);
71700 extern void flush_itimer_signals(void);
71701
71702-extern void do_group_exit(int);
71703+extern __noreturn void do_group_exit(int);
71704
71705 extern int allow_signal(int);
71706 extern int disallow_signal(int);
71707@@ -2463,9 +2571,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
71708
71709 #endif
71710
71711-static inline int object_is_on_stack(void *obj)
71712+static inline int object_starts_on_stack(void *obj)
71713 {
71714- void *stack = task_stack_page(current);
71715+ const void *stack = task_stack_page(current);
71716
71717 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
71718 }
71719diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
71720index bf8086b..962b035 100644
71721--- a/include/linux/sched/sysctl.h
71722+++ b/include/linux/sched/sysctl.h
71723@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
71724 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
71725
71726 extern int sysctl_max_map_count;
71727+extern unsigned long sysctl_heap_stack_gap;
71728
71729 extern unsigned int sysctl_sched_latency;
71730 extern unsigned int sysctl_sched_min_granularity;
71731diff --git a/include/linux/security.h b/include/linux/security.h
71732index 032c366..2c1c2dc2 100644
71733--- a/include/linux/security.h
71734+++ b/include/linux/security.h
71735@@ -26,6 +26,7 @@
71736 #include <linux/capability.h>
71737 #include <linux/slab.h>
71738 #include <linux/err.h>
71739+#include <linux/grsecurity.h>
71740
71741 struct linux_binprm;
71742 struct cred;
71743diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
71744index 68a04a3..866e6a1 100644
71745--- a/include/linux/seq_file.h
71746+++ b/include/linux/seq_file.h
71747@@ -26,6 +26,9 @@ struct seq_file {
71748 struct mutex lock;
71749 const struct seq_operations *op;
71750 int poll_event;
71751+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71752+ u64 exec_id;
71753+#endif
71754 #ifdef CONFIG_USER_NS
71755 struct user_namespace *user_ns;
71756 #endif
71757@@ -38,6 +41,7 @@ struct seq_operations {
71758 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
71759 int (*show) (struct seq_file *m, void *v);
71760 };
71761+typedef struct seq_operations __no_const seq_operations_no_const;
71762
71763 #define SEQ_SKIP 1
71764
71765diff --git a/include/linux/shm.h b/include/linux/shm.h
71766index 429c199..4d42e38 100644
71767--- a/include/linux/shm.h
71768+++ b/include/linux/shm.h
71769@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
71770
71771 /* The task created the shm object. NULL if the task is dead. */
71772 struct task_struct *shm_creator;
71773+#ifdef CONFIG_GRKERNSEC
71774+ time_t shm_createtime;
71775+ pid_t shm_lapid;
71776+#endif
71777 };
71778
71779 /* shm_mode upper byte flags */
71780diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
71781index 1f2803c..4858a3d 100644
71782--- a/include/linux/skbuff.h
71783+++ b/include/linux/skbuff.h
71784@@ -599,7 +599,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
71785 extern struct sk_buff *__alloc_skb(unsigned int size,
71786 gfp_t priority, int flags, int node);
71787 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
71788-static inline struct sk_buff *alloc_skb(unsigned int size,
71789+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
71790 gfp_t priority)
71791 {
71792 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
71793@@ -709,7 +709,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
71794 */
71795 static inline int skb_queue_empty(const struct sk_buff_head *list)
71796 {
71797- return list->next == (struct sk_buff *)list;
71798+ return list->next == (const struct sk_buff *)list;
71799 }
71800
71801 /**
71802@@ -722,7 +722,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
71803 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71804 const struct sk_buff *skb)
71805 {
71806- return skb->next == (struct sk_buff *)list;
71807+ return skb->next == (const struct sk_buff *)list;
71808 }
71809
71810 /**
71811@@ -735,7 +735,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71812 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
71813 const struct sk_buff *skb)
71814 {
71815- return skb->prev == (struct sk_buff *)list;
71816+ return skb->prev == (const struct sk_buff *)list;
71817 }
71818
71819 /**
71820@@ -1756,7 +1756,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
71821 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
71822 */
71823 #ifndef NET_SKB_PAD
71824-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
71825+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
71826 #endif
71827
71828 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
71829@@ -2351,7 +2351,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
71830 int noblock, int *err);
71831 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
71832 struct poll_table_struct *wait);
71833-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
71834+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
71835 int offset, struct iovec *to,
71836 int size);
71837 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
71838@@ -2641,6 +2641,9 @@ static inline void nf_reset(struct sk_buff *skb)
71839 nf_bridge_put(skb->nf_bridge);
71840 skb->nf_bridge = NULL;
71841 #endif
71842+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
71843+ skb->nf_trace = 0;
71844+#endif
71845 }
71846
71847 static inline void nf_reset_trace(struct sk_buff *skb)
71848diff --git a/include/linux/slab.h b/include/linux/slab.h
71849index 5d168d7..720bff3 100644
71850--- a/include/linux/slab.h
71851+++ b/include/linux/slab.h
71852@@ -12,13 +12,20 @@
71853 #include <linux/gfp.h>
71854 #include <linux/types.h>
71855 #include <linux/workqueue.h>
71856-
71857+#include <linux/err.h>
71858
71859 /*
71860 * Flags to pass to kmem_cache_create().
71861 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
71862 */
71863 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
71864+
71865+#ifdef CONFIG_PAX_USERCOPY_SLABS
71866+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
71867+#else
71868+#define SLAB_USERCOPY 0x00000000UL
71869+#endif
71870+
71871 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
71872 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
71873 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
71874@@ -89,10 +96,13 @@
71875 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
71876 * Both make kfree a no-op.
71877 */
71878-#define ZERO_SIZE_PTR ((void *)16)
71879+#define ZERO_SIZE_PTR \
71880+({ \
71881+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
71882+ (void *)(-MAX_ERRNO-1L); \
71883+})
71884
71885-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
71886- (unsigned long)ZERO_SIZE_PTR)
71887+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
71888
71889 /*
71890 * Common fields provided in kmem_cache by all slab allocators
71891@@ -112,7 +122,7 @@ struct kmem_cache {
71892 unsigned int align; /* Alignment as calculated */
71893 unsigned long flags; /* Active flags on the slab */
71894 const char *name; /* Slab name for sysfs */
71895- int refcount; /* Use counter */
71896+ atomic_t refcount; /* Use counter */
71897 void (*ctor)(void *); /* Called on object slot creation */
71898 struct list_head list; /* List of all slab caches on the system */
71899 };
71900@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
71901 void kfree(const void *);
71902 void kzfree(const void *);
71903 size_t ksize(const void *);
71904+const char *check_heap_object(const void *ptr, unsigned long n);
71905+bool is_usercopy_object(const void *ptr);
71906
71907 /*
71908 * Allocator specific definitions. These are mainly used to establish optimized
71909@@ -311,6 +323,7 @@ size_t ksize(const void *);
71910 * for general use, and so are not documented here. For a full list of
71911 * potential flags, always refer to linux/gfp.h.
71912 */
71913+
71914 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
71915 {
71916 if (size != 0 && n > SIZE_MAX / size)
71917@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
71918 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71919 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71920 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71921-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71922+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
71923 #define kmalloc_track_caller(size, flags) \
71924 __kmalloc_track_caller(size, flags, _RET_IP_)
71925 #else
71926@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71927 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71928 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71929 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71930-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
71931+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
71932 #define kmalloc_node_track_caller(size, flags, node) \
71933 __kmalloc_node_track_caller(size, flags, node, \
71934 _RET_IP_)
71935diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
71936index 8bb6e0e..8eb0dbe 100644
71937--- a/include/linux/slab_def.h
71938+++ b/include/linux/slab_def.h
71939@@ -52,7 +52,7 @@ struct kmem_cache {
71940 /* 4) cache creation/removal */
71941 const char *name;
71942 struct list_head list;
71943- int refcount;
71944+ atomic_t refcount;
71945 int object_size;
71946 int align;
71947
71948@@ -68,10 +68,10 @@ struct kmem_cache {
71949 unsigned long node_allocs;
71950 unsigned long node_frees;
71951 unsigned long node_overflow;
71952- atomic_t allochit;
71953- atomic_t allocmiss;
71954- atomic_t freehit;
71955- atomic_t freemiss;
71956+ atomic_unchecked_t allochit;
71957+ atomic_unchecked_t allocmiss;
71958+ atomic_unchecked_t freehit;
71959+ atomic_unchecked_t freemiss;
71960
71961 /*
71962 * If debugging is enabled, then the allocator can add additional
71963@@ -111,11 +111,16 @@ struct cache_sizes {
71964 #ifdef CONFIG_ZONE_DMA
71965 struct kmem_cache *cs_dmacachep;
71966 #endif
71967+
71968+#ifdef CONFIG_PAX_USERCOPY_SLABS
71969+ struct kmem_cache *cs_usercopycachep;
71970+#endif
71971+
71972 };
71973 extern struct cache_sizes malloc_sizes[];
71974
71975 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71976-void *__kmalloc(size_t size, gfp_t flags);
71977+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
71978
71979 #ifdef CONFIG_TRACING
71980 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
71981@@ -152,6 +157,13 @@ found:
71982 cachep = malloc_sizes[i].cs_dmacachep;
71983 else
71984 #endif
71985+
71986+#ifdef CONFIG_PAX_USERCOPY_SLABS
71987+ if (flags & GFP_USERCOPY)
71988+ cachep = malloc_sizes[i].cs_usercopycachep;
71989+ else
71990+#endif
71991+
71992 cachep = malloc_sizes[i].cs_cachep;
71993
71994 ret = kmem_cache_alloc_trace(cachep, flags, size);
71995@@ -162,7 +174,7 @@ found:
71996 }
71997
71998 #ifdef CONFIG_NUMA
71999-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
72000+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72001 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72002
72003 #ifdef CONFIG_TRACING
72004@@ -205,6 +217,13 @@ found:
72005 cachep = malloc_sizes[i].cs_dmacachep;
72006 else
72007 #endif
72008+
72009+#ifdef CONFIG_PAX_USERCOPY_SLABS
72010+ if (flags & GFP_USERCOPY)
72011+ cachep = malloc_sizes[i].cs_usercopycachep;
72012+ else
72013+#endif
72014+
72015 cachep = malloc_sizes[i].cs_cachep;
72016
72017 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
72018diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
72019index f28e14a..7831211 100644
72020--- a/include/linux/slob_def.h
72021+++ b/include/linux/slob_def.h
72022@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
72023 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
72024 }
72025
72026-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72027+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72028
72029 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
72030 {
72031@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72032 return __kmalloc_node(size, flags, NUMA_NO_NODE);
72033 }
72034
72035-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
72036+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
72037 {
72038 return kmalloc(size, flags);
72039 }
72040diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
72041index 9db4825..ed42fb5 100644
72042--- a/include/linux/slub_def.h
72043+++ b/include/linux/slub_def.h
72044@@ -91,7 +91,7 @@ struct kmem_cache {
72045 struct kmem_cache_order_objects max;
72046 struct kmem_cache_order_objects min;
72047 gfp_t allocflags; /* gfp flags to use on each alloc */
72048- int refcount; /* Refcount for slab cache destroy */
72049+ atomic_t refcount; /* Refcount for slab cache destroy */
72050 void (*ctor)(void *);
72051 int inuse; /* Offset to metadata */
72052 int align; /* Alignment */
72053@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
72054 * Sorry that the following has to be that ugly but some versions of GCC
72055 * have trouble with constant propagation and loops.
72056 */
72057-static __always_inline int kmalloc_index(size_t size)
72058+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
72059 {
72060 if (!size)
72061 return 0;
72062@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
72063 }
72064
72065 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
72066-void *__kmalloc(size_t size, gfp_t flags);
72067+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
72068
72069 static __always_inline void *
72070 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
72071@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
72072 }
72073 #endif
72074
72075-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
72076+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
72077 {
72078 unsigned int order = get_order(size);
72079 return kmalloc_order_trace(size, flags, order);
72080@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72081 }
72082
72083 #ifdef CONFIG_NUMA
72084-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72085+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72086 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72087
72088 #ifdef CONFIG_TRACING
72089diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
72090index e8d702e..0a56eb4 100644
72091--- a/include/linux/sock_diag.h
72092+++ b/include/linux/sock_diag.h
72093@@ -10,7 +10,7 @@ struct sock;
72094 struct sock_diag_handler {
72095 __u8 family;
72096 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
72097-};
72098+} __do_const;
72099
72100 int sock_diag_register(const struct sock_diag_handler *h);
72101 void sock_diag_unregister(const struct sock_diag_handler *h);
72102diff --git a/include/linux/sonet.h b/include/linux/sonet.h
72103index 680f9a3..f13aeb0 100644
72104--- a/include/linux/sonet.h
72105+++ b/include/linux/sonet.h
72106@@ -7,7 +7,7 @@
72107 #include <uapi/linux/sonet.h>
72108
72109 struct k_sonet_stats {
72110-#define __HANDLE_ITEM(i) atomic_t i
72111+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72112 __SONET_ITEMS
72113 #undef __HANDLE_ITEM
72114 };
72115diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
72116index 07d8e53..dc934c9 100644
72117--- a/include/linux/sunrpc/addr.h
72118+++ b/include/linux/sunrpc/addr.h
72119@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
72120 {
72121 switch (sap->sa_family) {
72122 case AF_INET:
72123- return ntohs(((struct sockaddr_in *)sap)->sin_port);
72124+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
72125 case AF_INET6:
72126- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
72127+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
72128 }
72129 return 0;
72130 }
72131@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
72132 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
72133 const struct sockaddr *src)
72134 {
72135- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
72136+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
72137 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
72138
72139 dsin->sin_family = ssin->sin_family;
72140@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
72141 if (sa->sa_family != AF_INET6)
72142 return 0;
72143
72144- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
72145+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
72146 }
72147
72148 #endif /* _LINUX_SUNRPC_ADDR_H */
72149diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
72150index 2cf4ffa..470d140 100644
72151--- a/include/linux/sunrpc/clnt.h
72152+++ b/include/linux/sunrpc/clnt.h
72153@@ -96,7 +96,7 @@ struct rpc_procinfo {
72154 unsigned int p_timer; /* Which RTT timer to use */
72155 u32 p_statidx; /* Which procedure to account */
72156 const char * p_name; /* name of procedure */
72157-};
72158+} __do_const;
72159
72160 #ifdef __KERNEL__
72161
72162diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
72163index 1f0216b..6a4fa50 100644
72164--- a/include/linux/sunrpc/svc.h
72165+++ b/include/linux/sunrpc/svc.h
72166@@ -411,7 +411,7 @@ struct svc_procedure {
72167 unsigned int pc_count; /* call count */
72168 unsigned int pc_cachetype; /* cache info (NFS) */
72169 unsigned int pc_xdrressize; /* maximum size of XDR reply */
72170-};
72171+} __do_const;
72172
72173 /*
72174 * Function prototypes.
72175diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
72176index 0b8e3e6..33e0a01 100644
72177--- a/include/linux/sunrpc/svc_rdma.h
72178+++ b/include/linux/sunrpc/svc_rdma.h
72179@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
72180 extern unsigned int svcrdma_max_requests;
72181 extern unsigned int svcrdma_max_req_size;
72182
72183-extern atomic_t rdma_stat_recv;
72184-extern atomic_t rdma_stat_read;
72185-extern atomic_t rdma_stat_write;
72186-extern atomic_t rdma_stat_sq_starve;
72187-extern atomic_t rdma_stat_rq_starve;
72188-extern atomic_t rdma_stat_rq_poll;
72189-extern atomic_t rdma_stat_rq_prod;
72190-extern atomic_t rdma_stat_sq_poll;
72191-extern atomic_t rdma_stat_sq_prod;
72192+extern atomic_unchecked_t rdma_stat_recv;
72193+extern atomic_unchecked_t rdma_stat_read;
72194+extern atomic_unchecked_t rdma_stat_write;
72195+extern atomic_unchecked_t rdma_stat_sq_starve;
72196+extern atomic_unchecked_t rdma_stat_rq_starve;
72197+extern atomic_unchecked_t rdma_stat_rq_poll;
72198+extern atomic_unchecked_t rdma_stat_rq_prod;
72199+extern atomic_unchecked_t rdma_stat_sq_poll;
72200+extern atomic_unchecked_t rdma_stat_sq_prod;
72201
72202 #define RPCRDMA_VERSION 1
72203
72204diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
72205index ff374ab..7fd2ecb 100644
72206--- a/include/linux/sunrpc/svcauth.h
72207+++ b/include/linux/sunrpc/svcauth.h
72208@@ -109,7 +109,7 @@ struct auth_ops {
72209 int (*release)(struct svc_rqst *rq);
72210 void (*domain_release)(struct auth_domain *);
72211 int (*set_client)(struct svc_rqst *rq);
72212-};
72213+} __do_const;
72214
72215 #define SVC_GARBAGE 1
72216 #define SVC_SYSERR 2
72217diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
72218index a5ffd32..0935dea 100644
72219--- a/include/linux/swiotlb.h
72220+++ b/include/linux/swiotlb.h
72221@@ -60,7 +60,8 @@ extern void
72222
72223 extern void
72224 swiotlb_free_coherent(struct device *hwdev, size_t size,
72225- void *vaddr, dma_addr_t dma_handle);
72226+ void *vaddr, dma_addr_t dma_handle,
72227+ struct dma_attrs *attrs);
72228
72229 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
72230 unsigned long offset, size_t size,
72231diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
72232index 313a8e0..6b273a9 100644
72233--- a/include/linux/syscalls.h
72234+++ b/include/linux/syscalls.h
72235@@ -418,11 +418,11 @@ asmlinkage long sys_sync(void);
72236 asmlinkage long sys_fsync(unsigned int fd);
72237 asmlinkage long sys_fdatasync(unsigned int fd);
72238 asmlinkage long sys_bdflush(int func, long data);
72239-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
72240- char __user *type, unsigned long flags,
72241+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
72242+ const char __user *type, unsigned long flags,
72243 void __user *data);
72244-asmlinkage long sys_umount(char __user *name, int flags);
72245-asmlinkage long sys_oldumount(char __user *name);
72246+asmlinkage long sys_umount(const char __user *name, int flags);
72247+asmlinkage long sys_oldumount(const char __user *name);
72248 asmlinkage long sys_truncate(const char __user *path, long length);
72249 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
72250 asmlinkage long sys_stat(const char __user *filename,
72251@@ -634,7 +634,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
72252 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
72253 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
72254 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
72255- struct sockaddr __user *, int);
72256+ struct sockaddr __user *, int) __intentional_overflow(0);
72257 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
72258 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
72259 unsigned int vlen, unsigned flags);
72260diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
72261index 27b3b0b..e093dd9 100644
72262--- a/include/linux/syscore_ops.h
72263+++ b/include/linux/syscore_ops.h
72264@@ -16,7 +16,7 @@ struct syscore_ops {
72265 int (*suspend)(void);
72266 void (*resume)(void);
72267 void (*shutdown)(void);
72268-};
72269+} __do_const;
72270
72271 extern void register_syscore_ops(struct syscore_ops *ops);
72272 extern void unregister_syscore_ops(struct syscore_ops *ops);
72273diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
72274index 14a8ff2..af52bad 100644
72275--- a/include/linux/sysctl.h
72276+++ b/include/linux/sysctl.h
72277@@ -34,13 +34,13 @@ struct ctl_table_root;
72278 struct ctl_table_header;
72279 struct ctl_dir;
72280
72281-typedef struct ctl_table ctl_table;
72282-
72283 typedef int proc_handler (struct ctl_table *ctl, int write,
72284 void __user *buffer, size_t *lenp, loff_t *ppos);
72285
72286 extern int proc_dostring(struct ctl_table *, int,
72287 void __user *, size_t *, loff_t *);
72288+extern int proc_dostring_modpriv(struct ctl_table *, int,
72289+ void __user *, size_t *, loff_t *);
72290 extern int proc_dointvec(struct ctl_table *, int,
72291 void __user *, size_t *, loff_t *);
72292 extern int proc_dointvec_minmax(struct ctl_table *, int,
72293@@ -115,7 +115,9 @@ struct ctl_table
72294 struct ctl_table_poll *poll;
72295 void *extra1;
72296 void *extra2;
72297-};
72298+} __do_const;
72299+typedef struct ctl_table __no_const ctl_table_no_const;
72300+typedef struct ctl_table ctl_table;
72301
72302 struct ctl_node {
72303 struct rb_node node;
72304diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
72305index e2cee22..3ddb921 100644
72306--- a/include/linux/sysfs.h
72307+++ b/include/linux/sysfs.h
72308@@ -31,7 +31,8 @@ struct attribute {
72309 struct lock_class_key *key;
72310 struct lock_class_key skey;
72311 #endif
72312-};
72313+} __do_const;
72314+typedef struct attribute __no_const attribute_no_const;
72315
72316 /**
72317 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
72318@@ -59,8 +60,8 @@ struct attribute_group {
72319 umode_t (*is_visible)(struct kobject *,
72320 struct attribute *, int);
72321 struct attribute **attrs;
72322-};
72323-
72324+} __do_const;
72325+typedef struct attribute_group __no_const attribute_group_no_const;
72326
72327
72328 /**
72329@@ -107,7 +108,8 @@ struct bin_attribute {
72330 char *, loff_t, size_t);
72331 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
72332 struct vm_area_struct *vma);
72333-};
72334+} __do_const;
72335+typedef struct bin_attribute __no_const bin_attribute_no_const;
72336
72337 /**
72338 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
72339diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
72340index 7faf933..9b85a0c 100644
72341--- a/include/linux/sysrq.h
72342+++ b/include/linux/sysrq.h
72343@@ -16,6 +16,7 @@
72344
72345 #include <linux/errno.h>
72346 #include <linux/types.h>
72347+#include <linux/compiler.h>
72348
72349 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
72350 #define SYSRQ_DEFAULT_ENABLE 1
72351@@ -36,7 +37,7 @@ struct sysrq_key_op {
72352 char *help_msg;
72353 char *action_msg;
72354 int enable_mask;
72355-};
72356+} __do_const;
72357
72358 #ifdef CONFIG_MAGIC_SYSRQ
72359
72360diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
72361index e7e0473..7989295 100644
72362--- a/include/linux/thread_info.h
72363+++ b/include/linux/thread_info.h
72364@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
72365 #error "no set_restore_sigmask() provided and default one won't work"
72366 #endif
72367
72368+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
72369+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
72370+{
72371+#ifndef CONFIG_PAX_USERCOPY_DEBUG
72372+ if (!__builtin_constant_p(n))
72373+#endif
72374+ __check_object_size(ptr, n, to_user);
72375+}
72376+
72377 #endif /* __KERNEL__ */
72378
72379 #endif /* _LINUX_THREAD_INFO_H */
72380diff --git a/include/linux/tty.h b/include/linux/tty.h
72381index c75d886..04cb148 100644
72382--- a/include/linux/tty.h
72383+++ b/include/linux/tty.h
72384@@ -194,7 +194,7 @@ struct tty_port {
72385 const struct tty_port_operations *ops; /* Port operations */
72386 spinlock_t lock; /* Lock protecting tty field */
72387 int blocked_open; /* Waiting to open */
72388- int count; /* Usage count */
72389+ atomic_t count; /* Usage count */
72390 wait_queue_head_t open_wait; /* Open waiters */
72391 wait_queue_head_t close_wait; /* Close waiters */
72392 wait_queue_head_t delta_msr_wait; /* Modem status change */
72393@@ -515,7 +515,7 @@ extern int tty_port_open(struct tty_port *port,
72394 struct tty_struct *tty, struct file *filp);
72395 static inline int tty_port_users(struct tty_port *port)
72396 {
72397- return port->count + port->blocked_open;
72398+ return atomic_read(&port->count) + port->blocked_open;
72399 }
72400
72401 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
72402diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
72403index 756a609..b302dd6 100644
72404--- a/include/linux/tty_driver.h
72405+++ b/include/linux/tty_driver.h
72406@@ -285,7 +285,7 @@ struct tty_operations {
72407 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
72408 #endif
72409 const struct file_operations *proc_fops;
72410-};
72411+} __do_const;
72412
72413 struct tty_driver {
72414 int magic; /* magic number for this structure */
72415diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
72416index 455a0d7..bf97ff5 100644
72417--- a/include/linux/tty_ldisc.h
72418+++ b/include/linux/tty_ldisc.h
72419@@ -146,7 +146,7 @@ struct tty_ldisc_ops {
72420
72421 struct module *owner;
72422
72423- int refcount;
72424+ atomic_t refcount;
72425 };
72426
72427 struct tty_ldisc {
72428diff --git a/include/linux/types.h b/include/linux/types.h
72429index 4d118ba..c3ee9bf 100644
72430--- a/include/linux/types.h
72431+++ b/include/linux/types.h
72432@@ -176,10 +176,26 @@ typedef struct {
72433 int counter;
72434 } atomic_t;
72435
72436+#ifdef CONFIG_PAX_REFCOUNT
72437+typedef struct {
72438+ int counter;
72439+} atomic_unchecked_t;
72440+#else
72441+typedef atomic_t atomic_unchecked_t;
72442+#endif
72443+
72444 #ifdef CONFIG_64BIT
72445 typedef struct {
72446 long counter;
72447 } atomic64_t;
72448+
72449+#ifdef CONFIG_PAX_REFCOUNT
72450+typedef struct {
72451+ long counter;
72452+} atomic64_unchecked_t;
72453+#else
72454+typedef atomic64_t atomic64_unchecked_t;
72455+#endif
72456 #endif
72457
72458 struct list_head {
72459diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
72460index 5ca0951..ab496a5 100644
72461--- a/include/linux/uaccess.h
72462+++ b/include/linux/uaccess.h
72463@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
72464 long ret; \
72465 mm_segment_t old_fs = get_fs(); \
72466 \
72467- set_fs(KERNEL_DS); \
72468 pagefault_disable(); \
72469- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
72470- pagefault_enable(); \
72471+ set_fs(KERNEL_DS); \
72472+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
72473 set_fs(old_fs); \
72474+ pagefault_enable(); \
72475 ret; \
72476 })
72477
72478diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
72479index 8e522cbc..aa8572d 100644
72480--- a/include/linux/uidgid.h
72481+++ b/include/linux/uidgid.h
72482@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
72483
72484 #endif /* CONFIG_USER_NS */
72485
72486+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
72487+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
72488+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
72489+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
72490+
72491 #endif /* _LINUX_UIDGID_H */
72492diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
72493index 99c1b4d..562e6f3 100644
72494--- a/include/linux/unaligned/access_ok.h
72495+++ b/include/linux/unaligned/access_ok.h
72496@@ -4,34 +4,34 @@
72497 #include <linux/kernel.h>
72498 #include <asm/byteorder.h>
72499
72500-static inline u16 get_unaligned_le16(const void *p)
72501+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
72502 {
72503- return le16_to_cpup((__le16 *)p);
72504+ return le16_to_cpup((const __le16 *)p);
72505 }
72506
72507-static inline u32 get_unaligned_le32(const void *p)
72508+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
72509 {
72510- return le32_to_cpup((__le32 *)p);
72511+ return le32_to_cpup((const __le32 *)p);
72512 }
72513
72514-static inline u64 get_unaligned_le64(const void *p)
72515+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
72516 {
72517- return le64_to_cpup((__le64 *)p);
72518+ return le64_to_cpup((const __le64 *)p);
72519 }
72520
72521-static inline u16 get_unaligned_be16(const void *p)
72522+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
72523 {
72524- return be16_to_cpup((__be16 *)p);
72525+ return be16_to_cpup((const __be16 *)p);
72526 }
72527
72528-static inline u32 get_unaligned_be32(const void *p)
72529+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
72530 {
72531- return be32_to_cpup((__be32 *)p);
72532+ return be32_to_cpup((const __be32 *)p);
72533 }
72534
72535-static inline u64 get_unaligned_be64(const void *p)
72536+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
72537 {
72538- return be64_to_cpup((__be64 *)p);
72539+ return be64_to_cpup((const __be64 *)p);
72540 }
72541
72542 static inline void put_unaligned_le16(u16 val, void *p)
72543diff --git a/include/linux/usb.h b/include/linux/usb.h
72544index 4d22d0f..8d0e8f8 100644
72545--- a/include/linux/usb.h
72546+++ b/include/linux/usb.h
72547@@ -554,7 +554,7 @@ struct usb_device {
72548 int maxchild;
72549
72550 u32 quirks;
72551- atomic_t urbnum;
72552+ atomic_unchecked_t urbnum;
72553
72554 unsigned long active_duration;
72555
72556@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
72557
72558 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
72559 __u8 request, __u8 requesttype, __u16 value, __u16 index,
72560- void *data, __u16 size, int timeout);
72561+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
72562 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
72563 void *data, int len, int *actual_length, int timeout);
72564 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
72565diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
72566index c5d36c6..108f4f9 100644
72567--- a/include/linux/usb/renesas_usbhs.h
72568+++ b/include/linux/usb/renesas_usbhs.h
72569@@ -39,7 +39,7 @@ enum {
72570 */
72571 struct renesas_usbhs_driver_callback {
72572 int (*notify_hotplug)(struct platform_device *pdev);
72573-};
72574+} __no_const;
72575
72576 /*
72577 * callback functions for platform
72578diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
72579index 6f8fbcf..8259001 100644
72580--- a/include/linux/vermagic.h
72581+++ b/include/linux/vermagic.h
72582@@ -25,9 +25,35 @@
72583 #define MODULE_ARCH_VERMAGIC ""
72584 #endif
72585
72586+#ifdef CONFIG_PAX_REFCOUNT
72587+#define MODULE_PAX_REFCOUNT "REFCOUNT "
72588+#else
72589+#define MODULE_PAX_REFCOUNT ""
72590+#endif
72591+
72592+#ifdef CONSTIFY_PLUGIN
72593+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
72594+#else
72595+#define MODULE_CONSTIFY_PLUGIN ""
72596+#endif
72597+
72598+#ifdef STACKLEAK_PLUGIN
72599+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
72600+#else
72601+#define MODULE_STACKLEAK_PLUGIN ""
72602+#endif
72603+
72604+#ifdef CONFIG_GRKERNSEC
72605+#define MODULE_GRSEC "GRSEC "
72606+#else
72607+#define MODULE_GRSEC ""
72608+#endif
72609+
72610 #define VERMAGIC_STRING \
72611 UTS_RELEASE " " \
72612 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
72613 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
72614- MODULE_ARCH_VERMAGIC
72615+ MODULE_ARCH_VERMAGIC \
72616+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
72617+ MODULE_GRSEC
72618
72619diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
72620index 6071e91..4c73b47 100644
72621--- a/include/linux/vmalloc.h
72622+++ b/include/linux/vmalloc.h
72623@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
72624 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
72625 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
72626 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
72627+
72628+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72629+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
72630+#endif
72631+
72632 /* bits [20..32] reserved for arch specific ioremap internals */
72633
72634 /*
72635@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
72636 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
72637 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
72638 unsigned long start, unsigned long end, gfp_t gfp_mask,
72639- pgprot_t prot, int node, const void *caller);
72640+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
72641 extern void vfree(const void *addr);
72642
72643 extern void *vmap(struct page **pages, unsigned int count,
72644@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
72645 extern void free_vm_area(struct vm_struct *area);
72646
72647 /* for /dev/kmem */
72648-extern long vread(char *buf, char *addr, unsigned long count);
72649-extern long vwrite(char *buf, char *addr, unsigned long count);
72650+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
72651+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
72652
72653 /*
72654 * Internals. Dont't use..
72655diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
72656index 5fd71a7..e5ef9a9 100644
72657--- a/include/linux/vmstat.h
72658+++ b/include/linux/vmstat.h
72659@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
72660 /*
72661 * Zone based page accounting with per cpu differentials.
72662 */
72663-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72664+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72665
72666 static inline void zone_page_state_add(long x, struct zone *zone,
72667 enum zone_stat_item item)
72668 {
72669- atomic_long_add(x, &zone->vm_stat[item]);
72670- atomic_long_add(x, &vm_stat[item]);
72671+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
72672+ atomic_long_add_unchecked(x, &vm_stat[item]);
72673 }
72674
72675 static inline unsigned long global_page_state(enum zone_stat_item item)
72676 {
72677- long x = atomic_long_read(&vm_stat[item]);
72678+ long x = atomic_long_read_unchecked(&vm_stat[item]);
72679 #ifdef CONFIG_SMP
72680 if (x < 0)
72681 x = 0;
72682@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
72683 static inline unsigned long zone_page_state(struct zone *zone,
72684 enum zone_stat_item item)
72685 {
72686- long x = atomic_long_read(&zone->vm_stat[item]);
72687+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72688 #ifdef CONFIG_SMP
72689 if (x < 0)
72690 x = 0;
72691@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
72692 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
72693 enum zone_stat_item item)
72694 {
72695- long x = atomic_long_read(&zone->vm_stat[item]);
72696+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72697
72698 #ifdef CONFIG_SMP
72699 int cpu;
72700@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
72701
72702 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
72703 {
72704- atomic_long_inc(&zone->vm_stat[item]);
72705- atomic_long_inc(&vm_stat[item]);
72706+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
72707+ atomic_long_inc_unchecked(&vm_stat[item]);
72708 }
72709
72710 static inline void __inc_zone_page_state(struct page *page,
72711@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
72712
72713 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
72714 {
72715- atomic_long_dec(&zone->vm_stat[item]);
72716- atomic_long_dec(&vm_stat[item]);
72717+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
72718+ atomic_long_dec_unchecked(&vm_stat[item]);
72719 }
72720
72721 static inline void __dec_zone_page_state(struct page *page,
72722diff --git a/include/linux/xattr.h b/include/linux/xattr.h
72723index fdbafc6..49dfe4f 100644
72724--- a/include/linux/xattr.h
72725+++ b/include/linux/xattr.h
72726@@ -28,7 +28,7 @@ struct xattr_handler {
72727 size_t size, int handler_flags);
72728 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
72729 size_t size, int flags, int handler_flags);
72730-};
72731+} __do_const;
72732
72733 struct xattr {
72734 char *name;
72735@@ -37,6 +37,9 @@ struct xattr {
72736 };
72737
72738 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
72739+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
72740+ssize_t pax_getxattr(struct dentry *, void *, size_t);
72741+#endif
72742 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
72743 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
72744 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
72745diff --git a/include/linux/zlib.h b/include/linux/zlib.h
72746index 9c5a6b4..09c9438 100644
72747--- a/include/linux/zlib.h
72748+++ b/include/linux/zlib.h
72749@@ -31,6 +31,7 @@
72750 #define _ZLIB_H
72751
72752 #include <linux/zconf.h>
72753+#include <linux/compiler.h>
72754
72755 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
72756 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
72757@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
72758
72759 /* basic functions */
72760
72761-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
72762+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
72763 /*
72764 Returns the number of bytes that needs to be allocated for a per-
72765 stream workspace with the specified parameters. A pointer to this
72766diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
72767index 95d1c91..6798cca 100644
72768--- a/include/media/v4l2-dev.h
72769+++ b/include/media/v4l2-dev.h
72770@@ -76,7 +76,7 @@ struct v4l2_file_operations {
72771 int (*mmap) (struct file *, struct vm_area_struct *);
72772 int (*open) (struct file *);
72773 int (*release) (struct file *);
72774-};
72775+} __do_const;
72776
72777 /*
72778 * Newer version of video_device, handled by videodev2.c
72779diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
72780index 4118ad1..cb7e25f 100644
72781--- a/include/media/v4l2-ioctl.h
72782+++ b/include/media/v4l2-ioctl.h
72783@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
72784 bool valid_prio, int cmd, void *arg);
72785 };
72786
72787-
72788 /* v4l debugging and diagnostics */
72789
72790 /* Debug bitmask flags to be used on V4L2 */
72791diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
72792index adcbb20..62c2559 100644
72793--- a/include/net/9p/transport.h
72794+++ b/include/net/9p/transport.h
72795@@ -57,7 +57,7 @@ struct p9_trans_module {
72796 int (*cancel) (struct p9_client *, struct p9_req_t *req);
72797 int (*zc_request)(struct p9_client *, struct p9_req_t *,
72798 char *, char *, int , int, int, int);
72799-};
72800+} __do_const;
72801
72802 void v9fs_register_trans(struct p9_trans_module *m);
72803 void v9fs_unregister_trans(struct p9_trans_module *m);
72804diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
72805index cdd3302..76f8ede 100644
72806--- a/include/net/bluetooth/l2cap.h
72807+++ b/include/net/bluetooth/l2cap.h
72808@@ -551,7 +551,7 @@ struct l2cap_ops {
72809 void (*defer) (struct l2cap_chan *chan);
72810 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
72811 unsigned long len, int nb);
72812-};
72813+} __do_const;
72814
72815 struct l2cap_conn {
72816 struct hci_conn *hcon;
72817diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
72818index 9e5425b..8136ffc 100644
72819--- a/include/net/caif/cfctrl.h
72820+++ b/include/net/caif/cfctrl.h
72821@@ -52,7 +52,7 @@ struct cfctrl_rsp {
72822 void (*radioset_rsp)(void);
72823 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
72824 struct cflayer *client_layer);
72825-};
72826+} __no_const;
72827
72828 /* Link Setup Parameters for CAIF-Links. */
72829 struct cfctrl_link_param {
72830@@ -101,8 +101,8 @@ struct cfctrl_request_info {
72831 struct cfctrl {
72832 struct cfsrvl serv;
72833 struct cfctrl_rsp res;
72834- atomic_t req_seq_no;
72835- atomic_t rsp_seq_no;
72836+ atomic_unchecked_t req_seq_no;
72837+ atomic_unchecked_t rsp_seq_no;
72838 struct list_head list;
72839 /* Protects from simultaneous access to first_req list */
72840 spinlock_t info_list_lock;
72841diff --git a/include/net/flow.h b/include/net/flow.h
72842index 628e11b..4c475df 100644
72843--- a/include/net/flow.h
72844+++ b/include/net/flow.h
72845@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
72846
72847 extern void flow_cache_flush(void);
72848 extern void flow_cache_flush_deferred(void);
72849-extern atomic_t flow_cache_genid;
72850+extern atomic_unchecked_t flow_cache_genid;
72851
72852 #endif
72853diff --git a/include/net/genetlink.h b/include/net/genetlink.h
72854index bdfbe68..4402ebe 100644
72855--- a/include/net/genetlink.h
72856+++ b/include/net/genetlink.h
72857@@ -118,7 +118,7 @@ struct genl_ops {
72858 struct netlink_callback *cb);
72859 int (*done)(struct netlink_callback *cb);
72860 struct list_head ops_list;
72861-};
72862+} __do_const;
72863
72864 extern int genl_register_family(struct genl_family *family);
72865 extern int genl_register_family_with_ops(struct genl_family *family,
72866diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
72867index 734d9b5..48a9a4b 100644
72868--- a/include/net/gro_cells.h
72869+++ b/include/net/gro_cells.h
72870@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
72871 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
72872
72873 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
72874- atomic_long_inc(&dev->rx_dropped);
72875+ atomic_long_inc_unchecked(&dev->rx_dropped);
72876 kfree_skb(skb);
72877 return;
72878 }
72879diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
72880index 1832927..ce39aea 100644
72881--- a/include/net/inet_connection_sock.h
72882+++ b/include/net/inet_connection_sock.h
72883@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
72884 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
72885 int (*bind_conflict)(const struct sock *sk,
72886 const struct inet_bind_bucket *tb, bool relax);
72887-};
72888+} __do_const;
72889
72890 /** inet_connection_sock - INET connection oriented sock
72891 *
72892diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
72893index 53f464d..ba76aaa 100644
72894--- a/include/net/inetpeer.h
72895+++ b/include/net/inetpeer.h
72896@@ -47,8 +47,8 @@ struct inet_peer {
72897 */
72898 union {
72899 struct {
72900- atomic_t rid; /* Frag reception counter */
72901- atomic_t ip_id_count; /* IP ID for the next packet */
72902+ atomic_unchecked_t rid; /* Frag reception counter */
72903+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
72904 };
72905 struct rcu_head rcu;
72906 struct inet_peer *gc_next;
72907@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
72908 more++;
72909 inet_peer_refcheck(p);
72910 do {
72911- old = atomic_read(&p->ip_id_count);
72912+ old = atomic_read_unchecked(&p->ip_id_count);
72913 new = old + more;
72914 if (!new)
72915 new = 1;
72916- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
72917+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
72918 return new;
72919 }
72920
72921diff --git a/include/net/ip.h b/include/net/ip.h
72922index a68f838..74518ab 100644
72923--- a/include/net/ip.h
72924+++ b/include/net/ip.h
72925@@ -202,7 +202,7 @@ extern struct local_ports {
72926 } sysctl_local_ports;
72927 extern void inet_get_local_port_range(int *low, int *high);
72928
72929-extern unsigned long *sysctl_local_reserved_ports;
72930+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
72931 static inline int inet_is_reserved_local_port(int port)
72932 {
72933 return test_bit(port, sysctl_local_reserved_ports);
72934diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
72935index e49db91..76a81de 100644
72936--- a/include/net/ip_fib.h
72937+++ b/include/net/ip_fib.h
72938@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
72939
72940 #define FIB_RES_SADDR(net, res) \
72941 ((FIB_RES_NH(res).nh_saddr_genid == \
72942- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
72943+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
72944 FIB_RES_NH(res).nh_saddr : \
72945 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
72946 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
72947diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
72948index fce8e6b..3ca4916 100644
72949--- a/include/net/ip_vs.h
72950+++ b/include/net/ip_vs.h
72951@@ -599,7 +599,7 @@ struct ip_vs_conn {
72952 struct ip_vs_conn *control; /* Master control connection */
72953 atomic_t n_control; /* Number of controlled ones */
72954 struct ip_vs_dest *dest; /* real server */
72955- atomic_t in_pkts; /* incoming packet counter */
72956+ atomic_unchecked_t in_pkts; /* incoming packet counter */
72957
72958 /* packet transmitter for different forwarding methods. If it
72959 mangles the packet, it must return NF_DROP or better NF_STOLEN,
72960@@ -737,7 +737,7 @@ struct ip_vs_dest {
72961 __be16 port; /* port number of the server */
72962 union nf_inet_addr addr; /* IP address of the server */
72963 volatile unsigned int flags; /* dest status flags */
72964- atomic_t conn_flags; /* flags to copy to conn */
72965+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
72966 atomic_t weight; /* server weight */
72967
72968 atomic_t refcnt; /* reference counter */
72969@@ -981,11 +981,11 @@ struct netns_ipvs {
72970 /* ip_vs_lblc */
72971 int sysctl_lblc_expiration;
72972 struct ctl_table_header *lblc_ctl_header;
72973- struct ctl_table *lblc_ctl_table;
72974+ ctl_table_no_const *lblc_ctl_table;
72975 /* ip_vs_lblcr */
72976 int sysctl_lblcr_expiration;
72977 struct ctl_table_header *lblcr_ctl_header;
72978- struct ctl_table *lblcr_ctl_table;
72979+ ctl_table_no_const *lblcr_ctl_table;
72980 /* ip_vs_est */
72981 struct list_head est_list; /* estimator list */
72982 spinlock_t est_lock;
72983diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
72984index 80ffde3..968b0f4 100644
72985--- a/include/net/irda/ircomm_tty.h
72986+++ b/include/net/irda/ircomm_tty.h
72987@@ -35,6 +35,7 @@
72988 #include <linux/termios.h>
72989 #include <linux/timer.h>
72990 #include <linux/tty.h> /* struct tty_struct */
72991+#include <asm/local.h>
72992
72993 #include <net/irda/irias_object.h>
72994 #include <net/irda/ircomm_core.h>
72995diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
72996index 714cc9a..ea05f3e 100644
72997--- a/include/net/iucv/af_iucv.h
72998+++ b/include/net/iucv/af_iucv.h
72999@@ -149,7 +149,7 @@ struct iucv_skb_cb {
73000 struct iucv_sock_list {
73001 struct hlist_head head;
73002 rwlock_t lock;
73003- atomic_t autobind_name;
73004+ atomic_unchecked_t autobind_name;
73005 };
73006
73007 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
73008diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
73009index df83f69..9b640b8 100644
73010--- a/include/net/llc_c_ac.h
73011+++ b/include/net/llc_c_ac.h
73012@@ -87,7 +87,7 @@
73013 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
73014 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
73015
73016-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73017+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73018
73019 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
73020 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
73021diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
73022index 6ca3113..f8026dd 100644
73023--- a/include/net/llc_c_ev.h
73024+++ b/include/net/llc_c_ev.h
73025@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
73026 return (struct llc_conn_state_ev *)skb->cb;
73027 }
73028
73029-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73030-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73031+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73032+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73033
73034 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
73035 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
73036diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
73037index 0e79cfb..f46db31 100644
73038--- a/include/net/llc_c_st.h
73039+++ b/include/net/llc_c_st.h
73040@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
73041 u8 next_state;
73042 llc_conn_ev_qfyr_t *ev_qualifiers;
73043 llc_conn_action_t *ev_actions;
73044-};
73045+} __do_const;
73046
73047 struct llc_conn_state {
73048 u8 current_state;
73049diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
73050index 37a3bbd..55a4241 100644
73051--- a/include/net/llc_s_ac.h
73052+++ b/include/net/llc_s_ac.h
73053@@ -23,7 +23,7 @@
73054 #define SAP_ACT_TEST_IND 9
73055
73056 /* All action functions must look like this */
73057-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73058+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73059
73060 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
73061 struct sk_buff *skb);
73062diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
73063index 567c681..cd73ac0 100644
73064--- a/include/net/llc_s_st.h
73065+++ b/include/net/llc_s_st.h
73066@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
73067 llc_sap_ev_t ev;
73068 u8 next_state;
73069 llc_sap_action_t *ev_actions;
73070-};
73071+} __do_const;
73072
73073 struct llc_sap_state {
73074 u8 curr_state;
73075diff --git a/include/net/mac80211.h b/include/net/mac80211.h
73076index f7eba13..91ed983 100644
73077--- a/include/net/mac80211.h
73078+++ b/include/net/mac80211.h
73079@@ -4119,7 +4119,7 @@ struct rate_control_ops {
73080 void (*add_sta_debugfs)(void *priv, void *priv_sta,
73081 struct dentry *dir);
73082 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
73083-};
73084+} __do_const;
73085
73086 static inline int rate_supported(struct ieee80211_sta *sta,
73087 enum ieee80211_band band,
73088diff --git a/include/net/neighbour.h b/include/net/neighbour.h
73089index 7e748ad..5c6229b 100644
73090--- a/include/net/neighbour.h
73091+++ b/include/net/neighbour.h
73092@@ -123,7 +123,7 @@ struct neigh_ops {
73093 void (*error_report)(struct neighbour *, struct sk_buff *);
73094 int (*output)(struct neighbour *, struct sk_buff *);
73095 int (*connected_output)(struct neighbour *, struct sk_buff *);
73096-};
73097+} __do_const;
73098
73099 struct pneigh_entry {
73100 struct pneigh_entry *next;
73101diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
73102index de644bc..dfbcc4c 100644
73103--- a/include/net/net_namespace.h
73104+++ b/include/net/net_namespace.h
73105@@ -115,7 +115,7 @@ struct net {
73106 #endif
73107 struct netns_ipvs *ipvs;
73108 struct sock *diag_nlsk;
73109- atomic_t rt_genid;
73110+ atomic_unchecked_t rt_genid;
73111 };
73112
73113 /*
73114@@ -272,7 +272,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
73115 #define __net_init __init
73116 #define __net_exit __exit_refok
73117 #define __net_initdata __initdata
73118+#ifdef CONSTIFY_PLUGIN
73119 #define __net_initconst __initconst
73120+#else
73121+#define __net_initconst __initdata
73122+#endif
73123 #endif
73124
73125 struct pernet_operations {
73126@@ -282,7 +286,7 @@ struct pernet_operations {
73127 void (*exit_batch)(struct list_head *net_exit_list);
73128 int *id;
73129 size_t size;
73130-};
73131+} __do_const;
73132
73133 /*
73134 * Use these carefully. If you implement a network device and it
73135@@ -330,12 +334,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
73136
73137 static inline int rt_genid(struct net *net)
73138 {
73139- return atomic_read(&net->rt_genid);
73140+ return atomic_read_unchecked(&net->rt_genid);
73141 }
73142
73143 static inline void rt_genid_bump(struct net *net)
73144 {
73145- atomic_inc(&net->rt_genid);
73146+ atomic_inc_unchecked(&net->rt_genid);
73147 }
73148
73149 #endif /* __NET_NET_NAMESPACE_H */
73150diff --git a/include/net/netdma.h b/include/net/netdma.h
73151index 8ba8ce2..99b7fff 100644
73152--- a/include/net/netdma.h
73153+++ b/include/net/netdma.h
73154@@ -24,7 +24,7 @@
73155 #include <linux/dmaengine.h>
73156 #include <linux/skbuff.h>
73157
73158-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73159+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73160 struct sk_buff *skb, int offset, struct iovec *to,
73161 size_t len, struct dma_pinned_list *pinned_list);
73162
73163diff --git a/include/net/netlink.h b/include/net/netlink.h
73164index 9690b0f..87aded7 100644
73165--- a/include/net/netlink.h
73166+++ b/include/net/netlink.h
73167@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
73168 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
73169 {
73170 if (mark)
73171- skb_trim(skb, (unsigned char *) mark - skb->data);
73172+ skb_trim(skb, (const unsigned char *) mark - skb->data);
73173 }
73174
73175 /**
73176diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
73177index c9c0c53..53f24c3 100644
73178--- a/include/net/netns/conntrack.h
73179+++ b/include/net/netns/conntrack.h
73180@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
73181 struct nf_proto_net {
73182 #ifdef CONFIG_SYSCTL
73183 struct ctl_table_header *ctl_table_header;
73184- struct ctl_table *ctl_table;
73185+ ctl_table_no_const *ctl_table;
73186 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
73187 struct ctl_table_header *ctl_compat_header;
73188- struct ctl_table *ctl_compat_table;
73189+ ctl_table_no_const *ctl_compat_table;
73190 #endif
73191 #endif
73192 unsigned int users;
73193@@ -58,7 +58,7 @@ struct nf_ip_net {
73194 struct nf_icmp_net icmpv6;
73195 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
73196 struct ctl_table_header *ctl_table_header;
73197- struct ctl_table *ctl_table;
73198+ ctl_table_no_const *ctl_table;
73199 #endif
73200 };
73201
73202diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
73203index 2ba9de8..47bd6c7 100644
73204--- a/include/net/netns/ipv4.h
73205+++ b/include/net/netns/ipv4.h
73206@@ -67,7 +67,7 @@ struct netns_ipv4 {
73207 kgid_t sysctl_ping_group_range[2];
73208 long sysctl_tcp_mem[3];
73209
73210- atomic_t dev_addr_genid;
73211+ atomic_unchecked_t dev_addr_genid;
73212
73213 #ifdef CONFIG_IP_MROUTE
73214 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
73215diff --git a/include/net/protocol.h b/include/net/protocol.h
73216index 047c047..b9dad15 100644
73217--- a/include/net/protocol.h
73218+++ b/include/net/protocol.h
73219@@ -44,7 +44,7 @@ struct net_protocol {
73220 void (*err_handler)(struct sk_buff *skb, u32 info);
73221 unsigned int no_policy:1,
73222 netns_ok:1;
73223-};
73224+} __do_const;
73225
73226 #if IS_ENABLED(CONFIG_IPV6)
73227 struct inet6_protocol {
73228@@ -57,7 +57,7 @@ struct inet6_protocol {
73229 u8 type, u8 code, int offset,
73230 __be32 info);
73231 unsigned int flags; /* INET6_PROTO_xxx */
73232-};
73233+} __do_const;
73234
73235 #define INET6_PROTO_NOPOLICY 0x1
73236 #define INET6_PROTO_FINAL 0x2
73237diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
73238index 5a15fab..d799ea7 100644
73239--- a/include/net/rtnetlink.h
73240+++ b/include/net/rtnetlink.h
73241@@ -81,7 +81,7 @@ struct rtnl_link_ops {
73242 const struct net_device *dev);
73243 unsigned int (*get_num_tx_queues)(void);
73244 unsigned int (*get_num_rx_queues)(void);
73245-};
73246+} __do_const;
73247
73248 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
73249 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
73250diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
73251index df85a0c..19ac300 100644
73252--- a/include/net/sctp/sctp.h
73253+++ b/include/net/sctp/sctp.h
73254@@ -330,9 +330,9 @@ do { \
73255
73256 #else /* SCTP_DEBUG */
73257
73258-#define SCTP_DEBUG_PRINTK(whatever...)
73259-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
73260-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
73261+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
73262+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
73263+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
73264 #define SCTP_ENABLE_DEBUG
73265 #define SCTP_DISABLE_DEBUG
73266 #define SCTP_ASSERT(expr, str, func)
73267diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
73268index 2a82d13..62a31c2 100644
73269--- a/include/net/sctp/sm.h
73270+++ b/include/net/sctp/sm.h
73271@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
73272 typedef struct {
73273 sctp_state_fn_t *fn;
73274 const char *name;
73275-} sctp_sm_table_entry_t;
73276+} __do_const sctp_sm_table_entry_t;
73277
73278 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
73279 * currently in use.
73280@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
73281 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
73282
73283 /* Extern declarations for major data structures. */
73284-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73285+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73286
73287
73288 /* Get the size of a DATA chunk payload. */
73289diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
73290index 0e0f9d2..cd05ebb 100644
73291--- a/include/net/sctp/structs.h
73292+++ b/include/net/sctp/structs.h
73293@@ -517,7 +517,7 @@ struct sctp_pf {
73294 struct sctp_association *asoc);
73295 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
73296 struct sctp_af *af;
73297-};
73298+} __do_const;
73299
73300
73301 /* Structure to track chunk fragments that have been acked, but peer
73302diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h
73303index c2e542b..6ca975b 100644
73304--- a/include/net/secure_seq.h
73305+++ b/include/net/secure_seq.h
73306@@ -3,6 +3,7 @@
73307
73308 #include <linux/types.h>
73309
73310+extern void net_secret_init(void);
73311 extern __u32 secure_ip_id(__be32 daddr);
73312 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
73313 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
73314diff --git a/include/net/sock.h b/include/net/sock.h
73315index 0be480a..586232f 100644
73316--- a/include/net/sock.h
73317+++ b/include/net/sock.h
73318@@ -325,7 +325,7 @@ struct sock {
73319 #ifdef CONFIG_RPS
73320 __u32 sk_rxhash;
73321 #endif
73322- atomic_t sk_drops;
73323+ atomic_unchecked_t sk_drops;
73324 int sk_rcvbuf;
73325
73326 struct sk_filter __rcu *sk_filter;
73327@@ -1796,7 +1796,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
73328 }
73329
73330 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
73331- char __user *from, char *to,
73332+ char __user *from, unsigned char *to,
73333 int copy, int offset)
73334 {
73335 if (skb->ip_summed == CHECKSUM_NONE) {
73336@@ -2055,7 +2055,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
73337 }
73338 }
73339
73340-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73341+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73342
73343 /**
73344 * sk_page_frag - return an appropriate page_frag
73345diff --git a/include/net/tcp.h b/include/net/tcp.h
73346index a345480..3c65cf4 100644
73347--- a/include/net/tcp.h
73348+++ b/include/net/tcp.h
73349@@ -529,7 +529,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
73350 extern void tcp_xmit_retransmit_queue(struct sock *);
73351 extern void tcp_simple_retransmit(struct sock *);
73352 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
73353-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73354+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73355
73356 extern void tcp_send_probe0(struct sock *);
73357 extern void tcp_send_partial(struct sock *);
73358@@ -700,8 +700,8 @@ struct tcp_skb_cb {
73359 struct inet6_skb_parm h6;
73360 #endif
73361 } header; /* For incoming frames */
73362- __u32 seq; /* Starting sequence number */
73363- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
73364+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
73365+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
73366 __u32 when; /* used to compute rtt's */
73367 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
73368
73369@@ -715,7 +715,7 @@ struct tcp_skb_cb {
73370
73371 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
73372 /* 1 byte hole */
73373- __u32 ack_seq; /* Sequence number ACK'd */
73374+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
73375 };
73376
73377 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
73378diff --git a/include/net/xfrm.h b/include/net/xfrm.h
73379index 24c8886..e6fb816 100644
73380--- a/include/net/xfrm.h
73381+++ b/include/net/xfrm.h
73382@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
73383 struct net_device *dev,
73384 const struct flowi *fl);
73385 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
73386-};
73387+} __do_const;
73388
73389 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
73390 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
73391@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
73392 struct sk_buff *skb);
73393 int (*transport_finish)(struct sk_buff *skb,
73394 int async);
73395-};
73396+} __do_const;
73397
73398 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
73399 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
73400@@ -423,7 +423,7 @@ struct xfrm_mode {
73401 struct module *owner;
73402 unsigned int encap;
73403 int flags;
73404-};
73405+} __do_const;
73406
73407 /* Flags for xfrm_mode. */
73408 enum {
73409@@ -520,7 +520,7 @@ struct xfrm_policy {
73410 struct timer_list timer;
73411
73412 struct flow_cache_object flo;
73413- atomic_t genid;
73414+ atomic_unchecked_t genid;
73415 u32 priority;
73416 u32 index;
73417 struct xfrm_mark mark;
73418diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
73419index 1a046b1..ee0bef0 100644
73420--- a/include/rdma/iw_cm.h
73421+++ b/include/rdma/iw_cm.h
73422@@ -122,7 +122,7 @@ struct iw_cm_verbs {
73423 int backlog);
73424
73425 int (*destroy_listen)(struct iw_cm_id *cm_id);
73426-};
73427+} __no_const;
73428
73429 /**
73430 * iw_create_cm_id - Create an IW CM identifier.
73431diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
73432index e1379b4..67eafbe 100644
73433--- a/include/scsi/libfc.h
73434+++ b/include/scsi/libfc.h
73435@@ -762,6 +762,7 @@ struct libfc_function_template {
73436 */
73437 void (*disc_stop_final) (struct fc_lport *);
73438 };
73439+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
73440
73441 /**
73442 * struct fc_disc - Discovery context
73443@@ -866,7 +867,7 @@ struct fc_lport {
73444 struct fc_vport *vport;
73445
73446 /* Operational Information */
73447- struct libfc_function_template tt;
73448+ libfc_function_template_no_const tt;
73449 u8 link_up;
73450 u8 qfull;
73451 enum fc_lport_state state;
73452diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
73453index a7f9cba..b1f44d0 100644
73454--- a/include/scsi/scsi_device.h
73455+++ b/include/scsi/scsi_device.h
73456@@ -171,9 +171,9 @@ struct scsi_device {
73457 unsigned int max_device_blocked; /* what device_blocked counts down from */
73458 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
73459
73460- atomic_t iorequest_cnt;
73461- atomic_t iodone_cnt;
73462- atomic_t ioerr_cnt;
73463+ atomic_unchecked_t iorequest_cnt;
73464+ atomic_unchecked_t iodone_cnt;
73465+ atomic_unchecked_t ioerr_cnt;
73466
73467 struct device sdev_gendev,
73468 sdev_dev;
73469diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
73470index b797e8f..8e2c3aa 100644
73471--- a/include/scsi/scsi_transport_fc.h
73472+++ b/include/scsi/scsi_transport_fc.h
73473@@ -751,7 +751,8 @@ struct fc_function_template {
73474 unsigned long show_host_system_hostname:1;
73475
73476 unsigned long disable_target_scan:1;
73477-};
73478+} __do_const;
73479+typedef struct fc_function_template __no_const fc_function_template_no_const;
73480
73481
73482 /**
73483diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
73484index ff6c741..393815f 100644
73485--- a/include/sound/compress_driver.h
73486+++ b/include/sound/compress_driver.h
73487@@ -130,7 +130,7 @@ struct snd_compr_ops {
73488 struct snd_compr_caps *caps);
73489 int (*get_codec_caps) (struct snd_compr_stream *stream,
73490 struct snd_compr_codec_caps *codec);
73491-};
73492+} __no_const;
73493
73494 /**
73495 * struct snd_compr: Compressed device
73496diff --git a/include/sound/soc.h b/include/sound/soc.h
73497index a6a059c..2243336 100644
73498--- a/include/sound/soc.h
73499+++ b/include/sound/soc.h
73500@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
73501 /* probe ordering - for components with runtime dependencies */
73502 int probe_order;
73503 int remove_order;
73504-};
73505+} __do_const;
73506
73507 /* SoC platform interface */
73508 struct snd_soc_platform_driver {
73509@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
73510 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
73511 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
73512 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
73513-};
73514+} __do_const;
73515
73516 struct snd_soc_platform {
73517 const char *name;
73518diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
73519index f8640f3..b72d113 100644
73520--- a/include/target/target_core_base.h
73521+++ b/include/target/target_core_base.h
73522@@ -658,7 +658,7 @@ struct se_device {
73523 spinlock_t stats_lock;
73524 /* Active commands on this virtual SE device */
73525 atomic_t simple_cmds;
73526- atomic_t dev_ordered_id;
73527+ atomic_unchecked_t dev_ordered_id;
73528 atomic_t dev_ordered_sync;
73529 atomic_t dev_qf_count;
73530 int export_count;
73531diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
73532new file mode 100644
73533index 0000000..fb634b7
73534--- /dev/null
73535+++ b/include/trace/events/fs.h
73536@@ -0,0 +1,53 @@
73537+#undef TRACE_SYSTEM
73538+#define TRACE_SYSTEM fs
73539+
73540+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
73541+#define _TRACE_FS_H
73542+
73543+#include <linux/fs.h>
73544+#include <linux/tracepoint.h>
73545+
73546+TRACE_EVENT(do_sys_open,
73547+
73548+ TP_PROTO(const char *filename, int flags, int mode),
73549+
73550+ TP_ARGS(filename, flags, mode),
73551+
73552+ TP_STRUCT__entry(
73553+ __string( filename, filename )
73554+ __field( int, flags )
73555+ __field( int, mode )
73556+ ),
73557+
73558+ TP_fast_assign(
73559+ __assign_str(filename, filename);
73560+ __entry->flags = flags;
73561+ __entry->mode = mode;
73562+ ),
73563+
73564+ TP_printk("\"%s\" %x %o",
73565+ __get_str(filename), __entry->flags, __entry->mode)
73566+);
73567+
73568+TRACE_EVENT(open_exec,
73569+
73570+ TP_PROTO(const char *filename),
73571+
73572+ TP_ARGS(filename),
73573+
73574+ TP_STRUCT__entry(
73575+ __string( filename, filename )
73576+ ),
73577+
73578+ TP_fast_assign(
73579+ __assign_str(filename, filename);
73580+ ),
73581+
73582+ TP_printk("\"%s\"",
73583+ __get_str(filename))
73584+);
73585+
73586+#endif /* _TRACE_FS_H */
73587+
73588+/* This part must be outside protection */
73589+#include <trace/define_trace.h>
73590diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
73591index 1c09820..7f5ec79 100644
73592--- a/include/trace/events/irq.h
73593+++ b/include/trace/events/irq.h
73594@@ -36,7 +36,7 @@ struct softirq_action;
73595 */
73596 TRACE_EVENT(irq_handler_entry,
73597
73598- TP_PROTO(int irq, struct irqaction *action),
73599+ TP_PROTO(int irq, const struct irqaction *action),
73600
73601 TP_ARGS(irq, action),
73602
73603@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
73604 */
73605 TRACE_EVENT(irq_handler_exit,
73606
73607- TP_PROTO(int irq, struct irqaction *action, int ret),
73608+ TP_PROTO(int irq, const struct irqaction *action, int ret),
73609
73610 TP_ARGS(irq, action, ret),
73611
73612diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
73613index 7caf44c..23c6f27 100644
73614--- a/include/uapi/linux/a.out.h
73615+++ b/include/uapi/linux/a.out.h
73616@@ -39,6 +39,14 @@ enum machine_type {
73617 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
73618 };
73619
73620+/* Constants for the N_FLAGS field */
73621+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73622+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
73623+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
73624+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
73625+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73626+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73627+
73628 #if !defined (N_MAGIC)
73629 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
73630 #endif
73631diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
73632index d876736..ccce5c0 100644
73633--- a/include/uapi/linux/byteorder/little_endian.h
73634+++ b/include/uapi/linux/byteorder/little_endian.h
73635@@ -42,51 +42,51 @@
73636
73637 static inline __le64 __cpu_to_le64p(const __u64 *p)
73638 {
73639- return (__force __le64)*p;
73640+ return (__force const __le64)*p;
73641 }
73642-static inline __u64 __le64_to_cpup(const __le64 *p)
73643+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
73644 {
73645- return (__force __u64)*p;
73646+ return (__force const __u64)*p;
73647 }
73648 static inline __le32 __cpu_to_le32p(const __u32 *p)
73649 {
73650- return (__force __le32)*p;
73651+ return (__force const __le32)*p;
73652 }
73653 static inline __u32 __le32_to_cpup(const __le32 *p)
73654 {
73655- return (__force __u32)*p;
73656+ return (__force const __u32)*p;
73657 }
73658 static inline __le16 __cpu_to_le16p(const __u16 *p)
73659 {
73660- return (__force __le16)*p;
73661+ return (__force const __le16)*p;
73662 }
73663 static inline __u16 __le16_to_cpup(const __le16 *p)
73664 {
73665- return (__force __u16)*p;
73666+ return (__force const __u16)*p;
73667 }
73668 static inline __be64 __cpu_to_be64p(const __u64 *p)
73669 {
73670- return (__force __be64)__swab64p(p);
73671+ return (__force const __be64)__swab64p(p);
73672 }
73673 static inline __u64 __be64_to_cpup(const __be64 *p)
73674 {
73675- return __swab64p((__u64 *)p);
73676+ return __swab64p((const __u64 *)p);
73677 }
73678 static inline __be32 __cpu_to_be32p(const __u32 *p)
73679 {
73680- return (__force __be32)__swab32p(p);
73681+ return (__force const __be32)__swab32p(p);
73682 }
73683-static inline __u32 __be32_to_cpup(const __be32 *p)
73684+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
73685 {
73686- return __swab32p((__u32 *)p);
73687+ return __swab32p((const __u32 *)p);
73688 }
73689 static inline __be16 __cpu_to_be16p(const __u16 *p)
73690 {
73691- return (__force __be16)__swab16p(p);
73692+ return (__force const __be16)__swab16p(p);
73693 }
73694 static inline __u16 __be16_to_cpup(const __be16 *p)
73695 {
73696- return __swab16p((__u16 *)p);
73697+ return __swab16p((const __u16 *)p);
73698 }
73699 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
73700 #define __le64_to_cpus(x) do { (void)(x); } while (0)
73701diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
73702index 8072d35..e77aeb8 100644
73703--- a/include/uapi/linux/elf.h
73704+++ b/include/uapi/linux/elf.h
73705@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
73706 #define PT_GNU_EH_FRAME 0x6474e550
73707
73708 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
73709+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
73710+
73711+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
73712+
73713+/* Constants for the e_flags field */
73714+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73715+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
73716+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
73717+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
73718+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73719+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73720
73721 /*
73722 * Extended Numbering
73723@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
73724 #define DT_DEBUG 21
73725 #define DT_TEXTREL 22
73726 #define DT_JMPREL 23
73727+#define DT_FLAGS 30
73728+ #define DF_TEXTREL 0x00000004
73729 #define DT_ENCODING 32
73730 #define OLD_DT_LOOS 0x60000000
73731 #define DT_LOOS 0x6000000d
73732@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
73733 #define PF_W 0x2
73734 #define PF_X 0x1
73735
73736+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
73737+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
73738+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
73739+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
73740+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
73741+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
73742+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
73743+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
73744+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
73745+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
73746+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
73747+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
73748+
73749 typedef struct elf32_phdr{
73750 Elf32_Word p_type;
73751 Elf32_Off p_offset;
73752@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
73753 #define EI_OSABI 7
73754 #define EI_PAD 8
73755
73756+#define EI_PAX 14
73757+
73758 #define ELFMAG0 0x7f /* EI_MAG */
73759 #define ELFMAG1 'E'
73760 #define ELFMAG2 'L'
73761diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
73762index aa169c4..6a2771d 100644
73763--- a/include/uapi/linux/personality.h
73764+++ b/include/uapi/linux/personality.h
73765@@ -30,6 +30,7 @@ enum {
73766 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
73767 ADDR_NO_RANDOMIZE | \
73768 ADDR_COMPAT_LAYOUT | \
73769+ ADDR_LIMIT_3GB | \
73770 MMAP_PAGE_ZERO)
73771
73772 /*
73773diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
73774index 7530e74..e714828 100644
73775--- a/include/uapi/linux/screen_info.h
73776+++ b/include/uapi/linux/screen_info.h
73777@@ -43,7 +43,8 @@ struct screen_info {
73778 __u16 pages; /* 0x32 */
73779 __u16 vesa_attributes; /* 0x34 */
73780 __u32 capabilities; /* 0x36 */
73781- __u8 _reserved[6]; /* 0x3a */
73782+ __u16 vesapm_size; /* 0x3a */
73783+ __u8 _reserved[4]; /* 0x3c */
73784 } __attribute__((packed));
73785
73786 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
73787diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
73788index 0e011eb..82681b1 100644
73789--- a/include/uapi/linux/swab.h
73790+++ b/include/uapi/linux/swab.h
73791@@ -43,7 +43,7 @@
73792 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
73793 */
73794
73795-static inline __attribute_const__ __u16 __fswab16(__u16 val)
73796+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
73797 {
73798 #ifdef __HAVE_BUILTIN_BSWAP16__
73799 return __builtin_bswap16(val);
73800@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
73801 #endif
73802 }
73803
73804-static inline __attribute_const__ __u32 __fswab32(__u32 val)
73805+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
73806 {
73807 #ifdef __HAVE_BUILTIN_BSWAP32__
73808 return __builtin_bswap32(val);
73809@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
73810 #endif
73811 }
73812
73813-static inline __attribute_const__ __u64 __fswab64(__u64 val)
73814+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
73815 {
73816 #ifdef __HAVE_BUILTIN_BSWAP64__
73817 return __builtin_bswap64(val);
73818diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
73819index 6d67213..8dab561 100644
73820--- a/include/uapi/linux/sysctl.h
73821+++ b/include/uapi/linux/sysctl.h
73822@@ -155,7 +155,11 @@ enum
73823 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
73824 };
73825
73826-
73827+#ifdef CONFIG_PAX_SOFTMODE
73828+enum {
73829+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
73830+};
73831+#endif
73832
73833 /* CTL_VM names: */
73834 enum
73835diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
73836index e4629b9..6958086 100644
73837--- a/include/uapi/linux/xattr.h
73838+++ b/include/uapi/linux/xattr.h
73839@@ -63,5 +63,9 @@
73840 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
73841 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
73842
73843+/* User namespace */
73844+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
73845+#define XATTR_PAX_FLAGS_SUFFIX "flags"
73846+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
73847
73848 #endif /* _UAPI_LINUX_XATTR_H */
73849diff --git a/include/video/udlfb.h b/include/video/udlfb.h
73850index f9466fa..f4e2b81 100644
73851--- a/include/video/udlfb.h
73852+++ b/include/video/udlfb.h
73853@@ -53,10 +53,10 @@ struct dlfb_data {
73854 u32 pseudo_palette[256];
73855 int blank_mode; /*one of FB_BLANK_ */
73856 /* blit-only rendering path metrics, exposed through sysfs */
73857- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73858- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
73859- atomic_t bytes_sent; /* to usb, after compression including overhead */
73860- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
73861+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73862+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
73863+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
73864+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
73865 };
73866
73867 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
73868diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
73869index 1a91850..28573f8 100644
73870--- a/include/video/uvesafb.h
73871+++ b/include/video/uvesafb.h
73872@@ -122,6 +122,7 @@ struct uvesafb_par {
73873 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
73874 u8 pmi_setpal; /* PMI for palette changes */
73875 u16 *pmi_base; /* protected mode interface location */
73876+ u8 *pmi_code; /* protected mode code location */
73877 void *pmi_start;
73878 void *pmi_pal;
73879 u8 *vbe_state_orig; /*
73880diff --git a/init/Kconfig b/init/Kconfig
73881index 5341d72..153f24f 100644
73882--- a/init/Kconfig
73883+++ b/init/Kconfig
73884@@ -984,6 +984,7 @@ endif # CGROUPS
73885
73886 config CHECKPOINT_RESTORE
73887 bool "Checkpoint/restore support" if EXPERT
73888+ depends on !GRKERNSEC
73889 default n
73890 help
73891 Enables additional kernel features in a sake of checkpoint/restore.
73892@@ -1471,7 +1472,7 @@ config SLUB_DEBUG
73893
73894 config COMPAT_BRK
73895 bool "Disable heap randomization"
73896- default y
73897+ default n
73898 help
73899 Randomizing heap placement makes heap exploits harder, but it
73900 also breaks ancient binaries (including anything libc5 based).
73901@@ -1734,7 +1735,7 @@ config INIT_ALL_POSSIBLE
73902 config STOP_MACHINE
73903 bool
73904 default y
73905- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
73906+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
73907 help
73908 Need stop_machine() primitive.
73909
73910diff --git a/init/Makefile b/init/Makefile
73911index 7bc47ee..6da2dc7 100644
73912--- a/init/Makefile
73913+++ b/init/Makefile
73914@@ -2,6 +2,9 @@
73915 # Makefile for the linux kernel.
73916 #
73917
73918+ccflags-y := $(GCC_PLUGINS_CFLAGS)
73919+asflags-y := $(GCC_PLUGINS_AFLAGS)
73920+
73921 obj-y := main.o version.o mounts.o
73922 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
73923 obj-y += noinitramfs.o
73924diff --git a/init/do_mounts.c b/init/do_mounts.c
73925index a2b49f2..03a0e17c 100644
73926--- a/init/do_mounts.c
73927+++ b/init/do_mounts.c
73928@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
73929 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
73930 {
73931 struct super_block *s;
73932- int err = sys_mount(name, "/root", fs, flags, data);
73933+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
73934 if (err)
73935 return err;
73936
73937- sys_chdir("/root");
73938+ sys_chdir((const char __force_user *)"/root");
73939 s = current->fs->pwd.dentry->d_sb;
73940 ROOT_DEV = s->s_dev;
73941 printk(KERN_INFO
73942@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
73943 va_start(args, fmt);
73944 vsprintf(buf, fmt, args);
73945 va_end(args);
73946- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
73947+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
73948 if (fd >= 0) {
73949 sys_ioctl(fd, FDEJECT, 0);
73950 sys_close(fd);
73951 }
73952 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
73953- fd = sys_open("/dev/console", O_RDWR, 0);
73954+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
73955 if (fd >= 0) {
73956 sys_ioctl(fd, TCGETS, (long)&termios);
73957 termios.c_lflag &= ~ICANON;
73958 sys_ioctl(fd, TCSETSF, (long)&termios);
73959- sys_read(fd, &c, 1);
73960+ sys_read(fd, (char __user *)&c, 1);
73961 termios.c_lflag |= ICANON;
73962 sys_ioctl(fd, TCSETSF, (long)&termios);
73963 sys_close(fd);
73964@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
73965 mount_root();
73966 out:
73967 devtmpfs_mount("dev");
73968- sys_mount(".", "/", NULL, MS_MOVE, NULL);
73969- sys_chroot(".");
73970+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
73971+ sys_chroot((const char __force_user *)".");
73972 }
73973diff --git a/init/do_mounts.h b/init/do_mounts.h
73974index f5b978a..69dbfe8 100644
73975--- a/init/do_mounts.h
73976+++ b/init/do_mounts.h
73977@@ -15,15 +15,15 @@ extern int root_mountflags;
73978
73979 static inline int create_dev(char *name, dev_t dev)
73980 {
73981- sys_unlink(name);
73982- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
73983+ sys_unlink((char __force_user *)name);
73984+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
73985 }
73986
73987 #if BITS_PER_LONG == 32
73988 static inline u32 bstat(char *name)
73989 {
73990 struct stat64 stat;
73991- if (sys_stat64(name, &stat) != 0)
73992+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
73993 return 0;
73994 if (!S_ISBLK(stat.st_mode))
73995 return 0;
73996@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
73997 static inline u32 bstat(char *name)
73998 {
73999 struct stat stat;
74000- if (sys_newstat(name, &stat) != 0)
74001+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
74002 return 0;
74003 if (!S_ISBLK(stat.st_mode))
74004 return 0;
74005diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
74006index a32ec1c..60a6659 100644
74007--- a/init/do_mounts_initrd.c
74008+++ b/init/do_mounts_initrd.c
74009@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
74010 {
74011 sys_unshare(CLONE_FS | CLONE_FILES);
74012 /* stdin/stdout/stderr for /linuxrc */
74013- sys_open("/dev/console", O_RDWR, 0);
74014+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
74015 sys_dup(0);
74016 sys_dup(0);
74017 /* move initrd over / and chdir/chroot in initrd root */
74018- sys_chdir("/root");
74019- sys_mount(".", "/", NULL, MS_MOVE, NULL);
74020- sys_chroot(".");
74021+ sys_chdir((const char __force_user *)"/root");
74022+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
74023+ sys_chroot((const char __force_user *)".");
74024 sys_setsid();
74025 return 0;
74026 }
74027@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
74028 create_dev("/dev/root.old", Root_RAM0);
74029 /* mount initrd on rootfs' /root */
74030 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
74031- sys_mkdir("/old", 0700);
74032- sys_chdir("/old");
74033+ sys_mkdir((const char __force_user *)"/old", 0700);
74034+ sys_chdir((const char __force_user *)"/old");
74035
74036 /* try loading default modules from initrd */
74037 load_default_modules();
74038@@ -76,31 +76,31 @@ static void __init handle_initrd(void)
74039 current->flags &= ~PF_FREEZER_SKIP;
74040
74041 /* move initrd to rootfs' /old */
74042- sys_mount("..", ".", NULL, MS_MOVE, NULL);
74043+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
74044 /* switch root and cwd back to / of rootfs */
74045- sys_chroot("..");
74046+ sys_chroot((const char __force_user *)"..");
74047
74048 if (new_decode_dev(real_root_dev) == Root_RAM0) {
74049- sys_chdir("/old");
74050+ sys_chdir((const char __force_user *)"/old");
74051 return;
74052 }
74053
74054- sys_chdir("/");
74055+ sys_chdir((const char __force_user *)"/");
74056 ROOT_DEV = new_decode_dev(real_root_dev);
74057 mount_root();
74058
74059 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
74060- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
74061+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
74062 if (!error)
74063 printk("okay\n");
74064 else {
74065- int fd = sys_open("/dev/root.old", O_RDWR, 0);
74066+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
74067 if (error == -ENOENT)
74068 printk("/initrd does not exist. Ignored.\n");
74069 else
74070 printk("failed\n");
74071 printk(KERN_NOTICE "Unmounting old root\n");
74072- sys_umount("/old", MNT_DETACH);
74073+ sys_umount((char __force_user *)"/old", MNT_DETACH);
74074 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
74075 if (fd < 0) {
74076 error = fd;
74077@@ -123,11 +123,11 @@ int __init initrd_load(void)
74078 * mounted in the normal path.
74079 */
74080 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
74081- sys_unlink("/initrd.image");
74082+ sys_unlink((const char __force_user *)"/initrd.image");
74083 handle_initrd();
74084 return 1;
74085 }
74086 }
74087- sys_unlink("/initrd.image");
74088+ sys_unlink((const char __force_user *)"/initrd.image");
74089 return 0;
74090 }
74091diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
74092index 8cb6db5..d729f50 100644
74093--- a/init/do_mounts_md.c
74094+++ b/init/do_mounts_md.c
74095@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
74096 partitioned ? "_d" : "", minor,
74097 md_setup_args[ent].device_names);
74098
74099- fd = sys_open(name, 0, 0);
74100+ fd = sys_open((char __force_user *)name, 0, 0);
74101 if (fd < 0) {
74102 printk(KERN_ERR "md: open failed - cannot start "
74103 "array %s\n", name);
74104@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
74105 * array without it
74106 */
74107 sys_close(fd);
74108- fd = sys_open(name, 0, 0);
74109+ fd = sys_open((char __force_user *)name, 0, 0);
74110 sys_ioctl(fd, BLKRRPART, 0);
74111 }
74112 sys_close(fd);
74113@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
74114
74115 wait_for_device_probe();
74116
74117- fd = sys_open("/dev/md0", 0, 0);
74118+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
74119 if (fd >= 0) {
74120 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
74121 sys_close(fd);
74122diff --git a/init/init_task.c b/init/init_task.c
74123index ba0a7f36..2bcf1d5 100644
74124--- a/init/init_task.c
74125+++ b/init/init_task.c
74126@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
74127 * Initial thread structure. Alignment of this is handled by a special
74128 * linker map entry.
74129 */
74130+#ifdef CONFIG_X86
74131+union thread_union init_thread_union __init_task_data;
74132+#else
74133 union thread_union init_thread_union __init_task_data =
74134 { INIT_THREAD_INFO(init_task) };
74135+#endif
74136diff --git a/init/initramfs.c b/init/initramfs.c
74137index a67ef9d..2d17ed9 100644
74138--- a/init/initramfs.c
74139+++ b/init/initramfs.c
74140@@ -84,7 +84,7 @@ static void __init free_hash(void)
74141 }
74142 }
74143
74144-static long __init do_utime(char *filename, time_t mtime)
74145+static long __init do_utime(char __force_user *filename, time_t mtime)
74146 {
74147 struct timespec t[2];
74148
74149@@ -119,7 +119,7 @@ static void __init dir_utime(void)
74150 struct dir_entry *de, *tmp;
74151 list_for_each_entry_safe(de, tmp, &dir_list, list) {
74152 list_del(&de->list);
74153- do_utime(de->name, de->mtime);
74154+ do_utime((char __force_user *)de->name, de->mtime);
74155 kfree(de->name);
74156 kfree(de);
74157 }
74158@@ -281,7 +281,7 @@ static int __init maybe_link(void)
74159 if (nlink >= 2) {
74160 char *old = find_link(major, minor, ino, mode, collected);
74161 if (old)
74162- return (sys_link(old, collected) < 0) ? -1 : 1;
74163+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
74164 }
74165 return 0;
74166 }
74167@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
74168 {
74169 struct stat st;
74170
74171- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
74172+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
74173 if (S_ISDIR(st.st_mode))
74174- sys_rmdir(path);
74175+ sys_rmdir((char __force_user *)path);
74176 else
74177- sys_unlink(path);
74178+ sys_unlink((char __force_user *)path);
74179 }
74180 }
74181
74182@@ -315,7 +315,7 @@ static int __init do_name(void)
74183 int openflags = O_WRONLY|O_CREAT;
74184 if (ml != 1)
74185 openflags |= O_TRUNC;
74186- wfd = sys_open(collected, openflags, mode);
74187+ wfd = sys_open((char __force_user *)collected, openflags, mode);
74188
74189 if (wfd >= 0) {
74190 sys_fchown(wfd, uid, gid);
74191@@ -327,17 +327,17 @@ static int __init do_name(void)
74192 }
74193 }
74194 } else if (S_ISDIR(mode)) {
74195- sys_mkdir(collected, mode);
74196- sys_chown(collected, uid, gid);
74197- sys_chmod(collected, mode);
74198+ sys_mkdir((char __force_user *)collected, mode);
74199+ sys_chown((char __force_user *)collected, uid, gid);
74200+ sys_chmod((char __force_user *)collected, mode);
74201 dir_add(collected, mtime);
74202 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
74203 S_ISFIFO(mode) || S_ISSOCK(mode)) {
74204 if (maybe_link() == 0) {
74205- sys_mknod(collected, mode, rdev);
74206- sys_chown(collected, uid, gid);
74207- sys_chmod(collected, mode);
74208- do_utime(collected, mtime);
74209+ sys_mknod((char __force_user *)collected, mode, rdev);
74210+ sys_chown((char __force_user *)collected, uid, gid);
74211+ sys_chmod((char __force_user *)collected, mode);
74212+ do_utime((char __force_user *)collected, mtime);
74213 }
74214 }
74215 return 0;
74216@@ -346,15 +346,15 @@ static int __init do_name(void)
74217 static int __init do_copy(void)
74218 {
74219 if (count >= body_len) {
74220- sys_write(wfd, victim, body_len);
74221+ sys_write(wfd, (char __force_user *)victim, body_len);
74222 sys_close(wfd);
74223- do_utime(vcollected, mtime);
74224+ do_utime((char __force_user *)vcollected, mtime);
74225 kfree(vcollected);
74226 eat(body_len);
74227 state = SkipIt;
74228 return 0;
74229 } else {
74230- sys_write(wfd, victim, count);
74231+ sys_write(wfd, (char __force_user *)victim, count);
74232 body_len -= count;
74233 eat(count);
74234 return 1;
74235@@ -365,9 +365,9 @@ static int __init do_symlink(void)
74236 {
74237 collected[N_ALIGN(name_len) + body_len] = '\0';
74238 clean_path(collected, 0);
74239- sys_symlink(collected + N_ALIGN(name_len), collected);
74240- sys_lchown(collected, uid, gid);
74241- do_utime(collected, mtime);
74242+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
74243+ sys_lchown((char __force_user *)collected, uid, gid);
74244+ do_utime((char __force_user *)collected, mtime);
74245 state = SkipIt;
74246 next_state = Reset;
74247 return 0;
74248@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
74249 {
74250 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
74251 if (err)
74252- panic(err); /* Failed to decompress INTERNAL initramfs */
74253+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
74254 if (initrd_start) {
74255 #ifdef CONFIG_BLK_DEV_RAM
74256 int fd;
74257diff --git a/init/main.c b/init/main.c
74258index 63534a1..85feae2 100644
74259--- a/init/main.c
74260+++ b/init/main.c
74261@@ -98,6 +98,8 @@ static inline void mark_rodata_ro(void) { }
74262 extern void tc_init(void);
74263 #endif
74264
74265+extern void grsecurity_init(void);
74266+
74267 /*
74268 * Debug helper: via this flag we know that we are in 'early bootup code'
74269 * where only the boot processor is running with IRQ disabled. This means
74270@@ -151,6 +153,64 @@ static int __init set_reset_devices(char *str)
74271
74272 __setup("reset_devices", set_reset_devices);
74273
74274+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74275+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
74276+static int __init setup_grsec_proc_gid(char *str)
74277+{
74278+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
74279+ return 1;
74280+}
74281+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
74282+#endif
74283+
74284+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
74285+unsigned long pax_user_shadow_base __read_only = 1UL << TASK_SIZE_MAX_SHIFT;
74286+EXPORT_SYMBOL(pax_user_shadow_base);
74287+extern char pax_enter_kernel_user[];
74288+extern char pax_exit_kernel_user[];
74289+extern pgdval_t clone_pgd_mask;
74290+#endif
74291+
74292+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
74293+static int __init setup_pax_nouderef(char *str)
74294+{
74295+#ifdef CONFIG_X86_32
74296+ unsigned int cpu;
74297+ struct desc_struct *gdt;
74298+
74299+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
74300+ gdt = get_cpu_gdt_table(cpu);
74301+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
74302+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
74303+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
74304+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
74305+ }
74306+ loadsegment(ds, __KERNEL_DS);
74307+ loadsegment(es, __KERNEL_DS);
74308+ loadsegment(ss, __KERNEL_DS);
74309+#else
74310+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
74311+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
74312+ clone_pgd_mask = ~(pgdval_t)0UL;
74313+ pax_user_shadow_base = 0UL;
74314+#endif
74315+
74316+ return 0;
74317+}
74318+early_param("pax_nouderef", setup_pax_nouderef);
74319+#endif
74320+
74321+#ifdef CONFIG_PAX_SOFTMODE
74322+int pax_softmode;
74323+
74324+static int __init setup_pax_softmode(char *str)
74325+{
74326+ get_option(&str, &pax_softmode);
74327+ return 1;
74328+}
74329+__setup("pax_softmode=", setup_pax_softmode);
74330+#endif
74331+
74332 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
74333 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
74334 static const char *panic_later, *panic_param;
74335@@ -683,6 +743,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
74336 {
74337 int count = preempt_count();
74338 int ret;
74339+ const char *msg1 = "", *msg2 = "";
74340
74341 if (initcall_debug)
74342 ret = do_one_initcall_debug(fn);
74343@@ -695,15 +756,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
74344 sprintf(msgbuf, "error code %d ", ret);
74345
74346 if (preempt_count() != count) {
74347- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
74348+ msg1 = " preemption imbalance";
74349 preempt_count() = count;
74350 }
74351 if (irqs_disabled()) {
74352- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
74353+ msg2 = " disabled interrupts";
74354 local_irq_enable();
74355 }
74356- if (msgbuf[0]) {
74357- printk("initcall %pF returned with %s\n", fn, msgbuf);
74358+ if (msgbuf[0] || *msg1 || *msg2) {
74359+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
74360 }
74361
74362 return ret;
74363@@ -757,8 +818,14 @@ static void __init do_initcall_level(int level)
74364 level, level,
74365 &repair_env_string);
74366
74367- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
74368+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
74369 do_one_initcall(*fn);
74370+
74371+#ifdef LATENT_ENTROPY_PLUGIN
74372+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74373+#endif
74374+
74375+ }
74376 }
74377
74378 static void __init do_initcalls(void)
74379@@ -792,8 +859,14 @@ static void __init do_pre_smp_initcalls(void)
74380 {
74381 initcall_t *fn;
74382
74383- for (fn = __initcall_start; fn < __initcall0_start; fn++)
74384+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
74385 do_one_initcall(*fn);
74386+
74387+#ifdef LATENT_ENTROPY_PLUGIN
74388+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74389+#endif
74390+
74391+ }
74392 }
74393
74394 /*
74395@@ -811,8 +884,8 @@ static int run_init_process(const char *init_filename)
74396 {
74397 argv_init[0] = init_filename;
74398 return do_execve(init_filename,
74399- (const char __user *const __user *)argv_init,
74400- (const char __user *const __user *)envp_init);
74401+ (const char __user *const __force_user *)argv_init,
74402+ (const char __user *const __force_user *)envp_init);
74403 }
74404
74405 static noinline void __init kernel_init_freeable(void);
74406@@ -890,7 +963,7 @@ static noinline void __init kernel_init_freeable(void)
74407 do_basic_setup();
74408
74409 /* Open the /dev/console on the rootfs, this should never fail */
74410- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
74411+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
74412 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
74413
74414 (void) sys_dup(0);
74415@@ -903,11 +976,13 @@ static noinline void __init kernel_init_freeable(void)
74416 if (!ramdisk_execute_command)
74417 ramdisk_execute_command = "/init";
74418
74419- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
74420+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
74421 ramdisk_execute_command = NULL;
74422 prepare_namespace();
74423 }
74424
74425+ grsecurity_init();
74426+
74427 /*
74428 * Ok, we have completed the initial bootup, and
74429 * we're essentially up and running. Get rid of the
74430diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
74431index 130dfec..cc88451 100644
74432--- a/ipc/ipc_sysctl.c
74433+++ b/ipc/ipc_sysctl.c
74434@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
74435 static int proc_ipc_dointvec(ctl_table *table, int write,
74436 void __user *buffer, size_t *lenp, loff_t *ppos)
74437 {
74438- struct ctl_table ipc_table;
74439+ ctl_table_no_const ipc_table;
74440
74441 memcpy(&ipc_table, table, sizeof(ipc_table));
74442 ipc_table.data = get_ipc(table);
74443@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
74444 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
74445 void __user *buffer, size_t *lenp, loff_t *ppos)
74446 {
74447- struct ctl_table ipc_table;
74448+ ctl_table_no_const ipc_table;
74449
74450 memcpy(&ipc_table, table, sizeof(ipc_table));
74451 ipc_table.data = get_ipc(table);
74452@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
74453 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74454 void __user *buffer, size_t *lenp, loff_t *ppos)
74455 {
74456- struct ctl_table ipc_table;
74457+ ctl_table_no_const ipc_table;
74458 size_t lenp_bef = *lenp;
74459 int rc;
74460
74461@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74462 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
74463 void __user *buffer, size_t *lenp, loff_t *ppos)
74464 {
74465- struct ctl_table ipc_table;
74466+ ctl_table_no_const ipc_table;
74467 memcpy(&ipc_table, table, sizeof(ipc_table));
74468 ipc_table.data = get_ipc(table);
74469
74470@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
74471 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
74472 void __user *buffer, size_t *lenp, loff_t *ppos)
74473 {
74474- struct ctl_table ipc_table;
74475+ ctl_table_no_const ipc_table;
74476 size_t lenp_bef = *lenp;
74477 int oldval;
74478 int rc;
74479diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
74480index 383d638..943fdbb 100644
74481--- a/ipc/mq_sysctl.c
74482+++ b/ipc/mq_sysctl.c
74483@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
74484 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
74485 void __user *buffer, size_t *lenp, loff_t *ppos)
74486 {
74487- struct ctl_table mq_table;
74488+ ctl_table_no_const mq_table;
74489 memcpy(&mq_table, table, sizeof(mq_table));
74490 mq_table.data = get_mq(table);
74491
74492diff --git a/ipc/mqueue.c b/ipc/mqueue.c
74493index e4e47f6..a85e0ad 100644
74494--- a/ipc/mqueue.c
74495+++ b/ipc/mqueue.c
74496@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
74497 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
74498 info->attr.mq_msgsize);
74499
74500+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
74501 spin_lock(&mq_lock);
74502 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
74503 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
74504diff --git a/ipc/msg.c b/ipc/msg.c
74505index fede1d0..9778e0f8 100644
74506--- a/ipc/msg.c
74507+++ b/ipc/msg.c
74508@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
74509 return security_msg_queue_associate(msq, msgflg);
74510 }
74511
74512+static struct ipc_ops msg_ops = {
74513+ .getnew = newque,
74514+ .associate = msg_security,
74515+ .more_checks = NULL
74516+};
74517+
74518 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
74519 {
74520 struct ipc_namespace *ns;
74521- struct ipc_ops msg_ops;
74522 struct ipc_params msg_params;
74523
74524 ns = current->nsproxy->ipc_ns;
74525
74526- msg_ops.getnew = newque;
74527- msg_ops.associate = msg_security;
74528- msg_ops.more_checks = NULL;
74529-
74530 msg_params.key = key;
74531 msg_params.flg = msgflg;
74532
74533diff --git a/ipc/sem.c b/ipc/sem.c
74534index 58d31f1..cce7a55 100644
74535--- a/ipc/sem.c
74536+++ b/ipc/sem.c
74537@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
74538 return 0;
74539 }
74540
74541+static struct ipc_ops sem_ops = {
74542+ .getnew = newary,
74543+ .associate = sem_security,
74544+ .more_checks = sem_more_checks
74545+};
74546+
74547 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74548 {
74549 struct ipc_namespace *ns;
74550- struct ipc_ops sem_ops;
74551 struct ipc_params sem_params;
74552
74553 ns = current->nsproxy->ipc_ns;
74554@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74555 if (nsems < 0 || nsems > ns->sc_semmsl)
74556 return -EINVAL;
74557
74558- sem_ops.getnew = newary;
74559- sem_ops.associate = sem_security;
74560- sem_ops.more_checks = sem_more_checks;
74561-
74562 sem_params.key = key;
74563 sem_params.flg = semflg;
74564 sem_params.u.nsems = nsems;
74565diff --git a/ipc/shm.c b/ipc/shm.c
74566index 7e199fa..180a1ca 100644
74567--- a/ipc/shm.c
74568+++ b/ipc/shm.c
74569@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
74570 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
74571 #endif
74572
74573+#ifdef CONFIG_GRKERNSEC
74574+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74575+ const time_t shm_createtime, const kuid_t cuid,
74576+ const int shmid);
74577+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74578+ const time_t shm_createtime);
74579+#endif
74580+
74581 void shm_init_ns(struct ipc_namespace *ns)
74582 {
74583 ns->shm_ctlmax = SHMMAX;
74584@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
74585 shp->shm_lprid = 0;
74586 shp->shm_atim = shp->shm_dtim = 0;
74587 shp->shm_ctim = get_seconds();
74588+#ifdef CONFIG_GRKERNSEC
74589+ {
74590+ struct timespec timeval;
74591+ do_posix_clock_monotonic_gettime(&timeval);
74592+
74593+ shp->shm_createtime = timeval.tv_sec;
74594+ }
74595+#endif
74596 shp->shm_segsz = size;
74597 shp->shm_nattch = 0;
74598 shp->shm_file = file;
74599@@ -582,18 +598,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
74600 return 0;
74601 }
74602
74603+static struct ipc_ops shm_ops = {
74604+ .getnew = newseg,
74605+ .associate = shm_security,
74606+ .more_checks = shm_more_checks
74607+};
74608+
74609 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
74610 {
74611 struct ipc_namespace *ns;
74612- struct ipc_ops shm_ops;
74613 struct ipc_params shm_params;
74614
74615 ns = current->nsproxy->ipc_ns;
74616
74617- shm_ops.getnew = newseg;
74618- shm_ops.associate = shm_security;
74619- shm_ops.more_checks = shm_more_checks;
74620-
74621 shm_params.key = key;
74622 shm_params.flg = shmflg;
74623 shm_params.u.size = size;
74624@@ -1014,6 +1031,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74625 f_mode = FMODE_READ | FMODE_WRITE;
74626 }
74627 if (shmflg & SHM_EXEC) {
74628+
74629+#ifdef CONFIG_PAX_MPROTECT
74630+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
74631+ goto out;
74632+#endif
74633+
74634 prot |= PROT_EXEC;
74635 acc_mode |= S_IXUGO;
74636 }
74637@@ -1037,9 +1060,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74638 if (err)
74639 goto out_unlock;
74640
74641+#ifdef CONFIG_GRKERNSEC
74642+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
74643+ shp->shm_perm.cuid, shmid) ||
74644+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
74645+ err = -EACCES;
74646+ goto out_unlock;
74647+ }
74648+#endif
74649+
74650 path = shp->shm_file->f_path;
74651 path_get(&path);
74652 shp->shm_nattch++;
74653+#ifdef CONFIG_GRKERNSEC
74654+ shp->shm_lapid = current->pid;
74655+#endif
74656 size = i_size_read(path.dentry->d_inode);
74657 shm_unlock(shp);
74658
74659diff --git a/kernel/acct.c b/kernel/acct.c
74660index b9bd7f0..1762b4a 100644
74661--- a/kernel/acct.c
74662+++ b/kernel/acct.c
74663@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
74664 */
74665 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
74666 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
74667- file->f_op->write(file, (char *)&ac,
74668+ file->f_op->write(file, (char __force_user *)&ac,
74669 sizeof(acct_t), &file->f_pos);
74670 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
74671 set_fs(fs);
74672diff --git a/kernel/audit.c b/kernel/audit.c
74673index 8a667f10..7375e3f 100644
74674--- a/kernel/audit.c
74675+++ b/kernel/audit.c
74676@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
74677 3) suppressed due to audit_rate_limit
74678 4) suppressed due to audit_backlog_limit
74679 */
74680-static atomic_t audit_lost = ATOMIC_INIT(0);
74681+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
74682
74683 /* The netlink socket. */
74684 static struct sock *audit_sock;
74685@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
74686 unsigned long now;
74687 int print;
74688
74689- atomic_inc(&audit_lost);
74690+ atomic_inc_unchecked(&audit_lost);
74691
74692 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
74693
74694@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
74695 printk(KERN_WARNING
74696 "audit: audit_lost=%d audit_rate_limit=%d "
74697 "audit_backlog_limit=%d\n",
74698- atomic_read(&audit_lost),
74699+ atomic_read_unchecked(&audit_lost),
74700 audit_rate_limit,
74701 audit_backlog_limit);
74702 audit_panic(message);
74703@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
74704 status_set.pid = audit_pid;
74705 status_set.rate_limit = audit_rate_limit;
74706 status_set.backlog_limit = audit_backlog_limit;
74707- status_set.lost = atomic_read(&audit_lost);
74708+ status_set.lost = atomic_read_unchecked(&audit_lost);
74709 status_set.backlog = skb_queue_len(&audit_skb_queue);
74710 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
74711 &status_set, sizeof(status_set));
74712diff --git a/kernel/auditsc.c b/kernel/auditsc.c
74713index c4b72b0..8654c4e 100644
74714--- a/kernel/auditsc.c
74715+++ b/kernel/auditsc.c
74716@@ -2295,7 +2295,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
74717 }
74718
74719 /* global counter which is incremented every time something logs in */
74720-static atomic_t session_id = ATOMIC_INIT(0);
74721+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
74722
74723 /**
74724 * audit_set_loginuid - set current task's audit_context loginuid
74725@@ -2319,7 +2319,7 @@ int audit_set_loginuid(kuid_t loginuid)
74726 return -EPERM;
74727 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
74728
74729- sessionid = atomic_inc_return(&session_id);
74730+ sessionid = atomic_inc_return_unchecked(&session_id);
74731 if (context && context->in_syscall) {
74732 struct audit_buffer *ab;
74733
74734diff --git a/kernel/capability.c b/kernel/capability.c
74735index f6c2ce5..982c0f9 100644
74736--- a/kernel/capability.c
74737+++ b/kernel/capability.c
74738@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
74739 * before modification is attempted and the application
74740 * fails.
74741 */
74742+ if (tocopy > ARRAY_SIZE(kdata))
74743+ return -EFAULT;
74744+
74745 if (copy_to_user(dataptr, kdata, tocopy
74746 * sizeof(struct __user_cap_data_struct))) {
74747 return -EFAULT;
74748@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
74749 int ret;
74750
74751 rcu_read_lock();
74752- ret = security_capable(__task_cred(t), ns, cap);
74753+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
74754+ gr_task_is_capable(t, __task_cred(t), cap);
74755 rcu_read_unlock();
74756
74757- return (ret == 0);
74758+ return ret;
74759 }
74760
74761 /**
74762@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
74763 int ret;
74764
74765 rcu_read_lock();
74766- ret = security_capable_noaudit(__task_cred(t), ns, cap);
74767+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
74768 rcu_read_unlock();
74769
74770- return (ret == 0);
74771+ return ret;
74772 }
74773
74774 /**
74775@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
74776 BUG();
74777 }
74778
74779- if (security_capable(current_cred(), ns, cap) == 0) {
74780+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
74781 current->flags |= PF_SUPERPRIV;
74782 return true;
74783 }
74784@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
74785 }
74786 EXPORT_SYMBOL(ns_capable);
74787
74788+bool ns_capable_nolog(struct user_namespace *ns, int cap)
74789+{
74790+ if (unlikely(!cap_valid(cap))) {
74791+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
74792+ BUG();
74793+ }
74794+
74795+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
74796+ current->flags |= PF_SUPERPRIV;
74797+ return true;
74798+ }
74799+ return false;
74800+}
74801+EXPORT_SYMBOL(ns_capable_nolog);
74802+
74803 /**
74804 * file_ns_capable - Determine if the file's opener had a capability in effect
74805 * @file: The file we want to check
74806@@ -432,6 +451,12 @@ bool capable(int cap)
74807 }
74808 EXPORT_SYMBOL(capable);
74809
74810+bool capable_nolog(int cap)
74811+{
74812+ return ns_capable_nolog(&init_user_ns, cap);
74813+}
74814+EXPORT_SYMBOL(capable_nolog);
74815+
74816 /**
74817 * nsown_capable - Check superior capability to one's own user_ns
74818 * @cap: The capability in question
74819@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
74820
74821 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74822 }
74823+
74824+bool inode_capable_nolog(const struct inode *inode, int cap)
74825+{
74826+ struct user_namespace *ns = current_user_ns();
74827+
74828+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74829+}
74830diff --git a/kernel/cgroup.c b/kernel/cgroup.c
74831index a48de6a..df24bfe 100644
74832--- a/kernel/cgroup.c
74833+++ b/kernel/cgroup.c
74834@@ -5567,7 +5567,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
74835 struct css_set *cg = link->cg;
74836 struct task_struct *task;
74837 int count = 0;
74838- seq_printf(seq, "css_set %p\n", cg);
74839+ seq_printf(seq, "css_set %pK\n", cg);
74840 list_for_each_entry(task, &cg->tasks, cg_list) {
74841 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
74842 seq_puts(seq, " ...\n");
74843diff --git a/kernel/compat.c b/kernel/compat.c
74844index 19971d8..02fe2df 100644
74845--- a/kernel/compat.c
74846+++ b/kernel/compat.c
74847@@ -13,6 +13,7 @@
74848
74849 #include <linux/linkage.h>
74850 #include <linux/compat.h>
74851+#include <linux/module.h>
74852 #include <linux/errno.h>
74853 #include <linux/time.h>
74854 #include <linux/signal.h>
74855@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
74856 mm_segment_t oldfs;
74857 long ret;
74858
74859- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
74860+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
74861 oldfs = get_fs();
74862 set_fs(KERNEL_DS);
74863 ret = hrtimer_nanosleep_restart(restart);
74864@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
74865 oldfs = get_fs();
74866 set_fs(KERNEL_DS);
74867 ret = hrtimer_nanosleep(&tu,
74868- rmtp ? (struct timespec __user *)&rmt : NULL,
74869+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
74870 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
74871 set_fs(oldfs);
74872
74873@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
74874 mm_segment_t old_fs = get_fs();
74875
74876 set_fs(KERNEL_DS);
74877- ret = sys_sigpending((old_sigset_t __user *) &s);
74878+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
74879 set_fs(old_fs);
74880 if (ret == 0)
74881 ret = put_user(s, set);
74882@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
74883 mm_segment_t old_fs = get_fs();
74884
74885 set_fs(KERNEL_DS);
74886- ret = sys_old_getrlimit(resource, &r);
74887+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
74888 set_fs(old_fs);
74889
74890 if (!ret) {
74891@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
74892 mm_segment_t old_fs = get_fs();
74893
74894 set_fs(KERNEL_DS);
74895- ret = sys_getrusage(who, (struct rusage __user *) &r);
74896+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
74897 set_fs(old_fs);
74898
74899 if (ret)
74900@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
74901 set_fs (KERNEL_DS);
74902 ret = sys_wait4(pid,
74903 (stat_addr ?
74904- (unsigned int __user *) &status : NULL),
74905- options, (struct rusage __user *) &r);
74906+ (unsigned int __force_user *) &status : NULL),
74907+ options, (struct rusage __force_user *) &r);
74908 set_fs (old_fs);
74909
74910 if (ret > 0) {
74911@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
74912 memset(&info, 0, sizeof(info));
74913
74914 set_fs(KERNEL_DS);
74915- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
74916- uru ? (struct rusage __user *)&ru : NULL);
74917+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
74918+ uru ? (struct rusage __force_user *)&ru : NULL);
74919 set_fs(old_fs);
74920
74921 if ((ret < 0) || (info.si_signo == 0))
74922@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
74923 oldfs = get_fs();
74924 set_fs(KERNEL_DS);
74925 err = sys_timer_settime(timer_id, flags,
74926- (struct itimerspec __user *) &newts,
74927- (struct itimerspec __user *) &oldts);
74928+ (struct itimerspec __force_user *) &newts,
74929+ (struct itimerspec __force_user *) &oldts);
74930 set_fs(oldfs);
74931 if (!err && old && put_compat_itimerspec(old, &oldts))
74932 return -EFAULT;
74933@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
74934 oldfs = get_fs();
74935 set_fs(KERNEL_DS);
74936 err = sys_timer_gettime(timer_id,
74937- (struct itimerspec __user *) &ts);
74938+ (struct itimerspec __force_user *) &ts);
74939 set_fs(oldfs);
74940 if (!err && put_compat_itimerspec(setting, &ts))
74941 return -EFAULT;
74942@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
74943 oldfs = get_fs();
74944 set_fs(KERNEL_DS);
74945 err = sys_clock_settime(which_clock,
74946- (struct timespec __user *) &ts);
74947+ (struct timespec __force_user *) &ts);
74948 set_fs(oldfs);
74949 return err;
74950 }
74951@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
74952 oldfs = get_fs();
74953 set_fs(KERNEL_DS);
74954 err = sys_clock_gettime(which_clock,
74955- (struct timespec __user *) &ts);
74956+ (struct timespec __force_user *) &ts);
74957 set_fs(oldfs);
74958 if (!err && put_compat_timespec(&ts, tp))
74959 return -EFAULT;
74960@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
74961
74962 oldfs = get_fs();
74963 set_fs(KERNEL_DS);
74964- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
74965+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
74966 set_fs(oldfs);
74967
74968 err = compat_put_timex(utp, &txc);
74969@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
74970 oldfs = get_fs();
74971 set_fs(KERNEL_DS);
74972 err = sys_clock_getres(which_clock,
74973- (struct timespec __user *) &ts);
74974+ (struct timespec __force_user *) &ts);
74975 set_fs(oldfs);
74976 if (!err && tp && put_compat_timespec(&ts, tp))
74977 return -EFAULT;
74978@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
74979 long err;
74980 mm_segment_t oldfs;
74981 struct timespec tu;
74982- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
74983+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
74984
74985- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
74986+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
74987 oldfs = get_fs();
74988 set_fs(KERNEL_DS);
74989 err = clock_nanosleep_restart(restart);
74990@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
74991 oldfs = get_fs();
74992 set_fs(KERNEL_DS);
74993 err = sys_clock_nanosleep(which_clock, flags,
74994- (struct timespec __user *) &in,
74995- (struct timespec __user *) &out);
74996+ (struct timespec __force_user *) &in,
74997+ (struct timespec __force_user *) &out);
74998 set_fs(oldfs);
74999
75000 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
75001diff --git a/kernel/configs.c b/kernel/configs.c
75002index 42e8fa0..9e7406b 100644
75003--- a/kernel/configs.c
75004+++ b/kernel/configs.c
75005@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
75006 struct proc_dir_entry *entry;
75007
75008 /* create the current config file */
75009+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
75010+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
75011+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
75012+ &ikconfig_file_ops);
75013+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75014+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
75015+ &ikconfig_file_ops);
75016+#endif
75017+#else
75018 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
75019 &ikconfig_file_ops);
75020+#endif
75021+
75022 if (!entry)
75023 return -ENOMEM;
75024
75025diff --git a/kernel/cred.c b/kernel/cred.c
75026index e0573a4..3874e41 100644
75027--- a/kernel/cred.c
75028+++ b/kernel/cred.c
75029@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
75030 validate_creds(cred);
75031 alter_cred_subscribers(cred, -1);
75032 put_cred(cred);
75033+
75034+#ifdef CONFIG_GRKERNSEC_SETXID
75035+ cred = (struct cred *) tsk->delayed_cred;
75036+ if (cred != NULL) {
75037+ tsk->delayed_cred = NULL;
75038+ validate_creds(cred);
75039+ alter_cred_subscribers(cred, -1);
75040+ put_cred(cred);
75041+ }
75042+#endif
75043 }
75044
75045 /**
75046@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
75047 * Always returns 0 thus allowing this function to be tail-called at the end
75048 * of, say, sys_setgid().
75049 */
75050-int commit_creds(struct cred *new)
75051+static int __commit_creds(struct cred *new)
75052 {
75053 struct task_struct *task = current;
75054 const struct cred *old = task->real_cred;
75055@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
75056
75057 get_cred(new); /* we will require a ref for the subj creds too */
75058
75059+ gr_set_role_label(task, new->uid, new->gid);
75060+
75061 /* dumpability changes */
75062 if (!uid_eq(old->euid, new->euid) ||
75063 !gid_eq(old->egid, new->egid) ||
75064@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
75065 put_cred(old);
75066 return 0;
75067 }
75068+#ifdef CONFIG_GRKERNSEC_SETXID
75069+extern int set_user(struct cred *new);
75070+
75071+void gr_delayed_cred_worker(void)
75072+{
75073+ const struct cred *new = current->delayed_cred;
75074+ struct cred *ncred;
75075+
75076+ current->delayed_cred = NULL;
75077+
75078+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
75079+ // from doing get_cred on it when queueing this
75080+ put_cred(new);
75081+ return;
75082+ } else if (new == NULL)
75083+ return;
75084+
75085+ ncred = prepare_creds();
75086+ if (!ncred)
75087+ goto die;
75088+ // uids
75089+ ncred->uid = new->uid;
75090+ ncred->euid = new->euid;
75091+ ncred->suid = new->suid;
75092+ ncred->fsuid = new->fsuid;
75093+ // gids
75094+ ncred->gid = new->gid;
75095+ ncred->egid = new->egid;
75096+ ncred->sgid = new->sgid;
75097+ ncred->fsgid = new->fsgid;
75098+ // groups
75099+ if (set_groups(ncred, new->group_info) < 0) {
75100+ abort_creds(ncred);
75101+ goto die;
75102+ }
75103+ // caps
75104+ ncred->securebits = new->securebits;
75105+ ncred->cap_inheritable = new->cap_inheritable;
75106+ ncred->cap_permitted = new->cap_permitted;
75107+ ncred->cap_effective = new->cap_effective;
75108+ ncred->cap_bset = new->cap_bset;
75109+
75110+ if (set_user(ncred)) {
75111+ abort_creds(ncred);
75112+ goto die;
75113+ }
75114+
75115+ // from doing get_cred on it when queueing this
75116+ put_cred(new);
75117+
75118+ __commit_creds(ncred);
75119+ return;
75120+die:
75121+ // from doing get_cred on it when queueing this
75122+ put_cred(new);
75123+ do_group_exit(SIGKILL);
75124+}
75125+#endif
75126+
75127+int commit_creds(struct cred *new)
75128+{
75129+#ifdef CONFIG_GRKERNSEC_SETXID
75130+ int ret;
75131+ int schedule_it = 0;
75132+ struct task_struct *t;
75133+
75134+ /* we won't get called with tasklist_lock held for writing
75135+ and interrupts disabled as the cred struct in that case is
75136+ init_cred
75137+ */
75138+ if (grsec_enable_setxid && !current_is_single_threaded() &&
75139+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
75140+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
75141+ schedule_it = 1;
75142+ }
75143+ ret = __commit_creds(new);
75144+ if (schedule_it) {
75145+ rcu_read_lock();
75146+ read_lock(&tasklist_lock);
75147+ for (t = next_thread(current); t != current;
75148+ t = next_thread(t)) {
75149+ if (t->delayed_cred == NULL) {
75150+ t->delayed_cred = get_cred(new);
75151+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
75152+ set_tsk_need_resched(t);
75153+ }
75154+ }
75155+ read_unlock(&tasklist_lock);
75156+ rcu_read_unlock();
75157+ }
75158+ return ret;
75159+#else
75160+ return __commit_creds(new);
75161+#endif
75162+}
75163+
75164 EXPORT_SYMBOL(commit_creds);
75165
75166 /**
75167diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
75168index c26278f..e323fb8 100644
75169--- a/kernel/debug/debug_core.c
75170+++ b/kernel/debug/debug_core.c
75171@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
75172 */
75173 static atomic_t masters_in_kgdb;
75174 static atomic_t slaves_in_kgdb;
75175-static atomic_t kgdb_break_tasklet_var;
75176+static atomic_unchecked_t kgdb_break_tasklet_var;
75177 atomic_t kgdb_setting_breakpoint;
75178
75179 struct task_struct *kgdb_usethread;
75180@@ -133,7 +133,7 @@ int kgdb_single_step;
75181 static pid_t kgdb_sstep_pid;
75182
75183 /* to keep track of the CPU which is doing the single stepping*/
75184-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75185+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75186
75187 /*
75188 * If you are debugging a problem where roundup (the collection of
75189@@ -541,7 +541,7 @@ return_normal:
75190 * kernel will only try for the value of sstep_tries before
75191 * giving up and continuing on.
75192 */
75193- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
75194+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
75195 (kgdb_info[cpu].task &&
75196 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
75197 atomic_set(&kgdb_active, -1);
75198@@ -635,8 +635,8 @@ cpu_master_loop:
75199 }
75200
75201 kgdb_restore:
75202- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
75203- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
75204+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
75205+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
75206 if (kgdb_info[sstep_cpu].task)
75207 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
75208 else
75209@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
75210 static void kgdb_tasklet_bpt(unsigned long ing)
75211 {
75212 kgdb_breakpoint();
75213- atomic_set(&kgdb_break_tasklet_var, 0);
75214+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
75215 }
75216
75217 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
75218
75219 void kgdb_schedule_breakpoint(void)
75220 {
75221- if (atomic_read(&kgdb_break_tasklet_var) ||
75222+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
75223 atomic_read(&kgdb_active) != -1 ||
75224 atomic_read(&kgdb_setting_breakpoint))
75225 return;
75226- atomic_inc(&kgdb_break_tasklet_var);
75227+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
75228 tasklet_schedule(&kgdb_tasklet_breakpoint);
75229 }
75230 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
75231diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
75232index 00eb8f7..d7e3244 100644
75233--- a/kernel/debug/kdb/kdb_main.c
75234+++ b/kernel/debug/kdb/kdb_main.c
75235@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
75236 continue;
75237
75238 kdb_printf("%-20s%8u 0x%p ", mod->name,
75239- mod->core_size, (void *)mod);
75240+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
75241 #ifdef CONFIG_MODULE_UNLOAD
75242 kdb_printf("%4ld ", module_refcount(mod));
75243 #endif
75244@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
75245 kdb_printf(" (Loading)");
75246 else
75247 kdb_printf(" (Live)");
75248- kdb_printf(" 0x%p", mod->module_core);
75249+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
75250
75251 #ifdef CONFIG_MODULE_UNLOAD
75252 {
75253diff --git a/kernel/events/core.c b/kernel/events/core.c
75254index f8ddcfb..77c06ec 100644
75255--- a/kernel/events/core.c
75256+++ b/kernel/events/core.c
75257@@ -154,8 +154,15 @@ static struct srcu_struct pmus_srcu;
75258 * 0 - disallow raw tracepoint access for unpriv
75259 * 1 - disallow cpu events for unpriv
75260 * 2 - disallow kernel profiling for unpriv
75261+ * 3 - disallow all unpriv perf event use
75262 */
75263-int sysctl_perf_event_paranoid __read_mostly = 1;
75264+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
75265+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
75266+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
75267+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
75268+#else
75269+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
75270+#endif
75271
75272 /* Minimum for 512 kiB + 1 user control page */
75273 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
75274@@ -182,7 +189,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
75275 return 0;
75276 }
75277
75278-static atomic64_t perf_event_id;
75279+static atomic64_unchecked_t perf_event_id;
75280
75281 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
75282 enum event_type_t event_type);
75283@@ -2674,7 +2681,7 @@ static void __perf_event_read(void *info)
75284
75285 static inline u64 perf_event_count(struct perf_event *event)
75286 {
75287- return local64_read(&event->count) + atomic64_read(&event->child_count);
75288+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
75289 }
75290
75291 static u64 perf_event_read(struct perf_event *event)
75292@@ -3020,9 +3027,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
75293 mutex_lock(&event->child_mutex);
75294 total += perf_event_read(event);
75295 *enabled += event->total_time_enabled +
75296- atomic64_read(&event->child_total_time_enabled);
75297+ atomic64_read_unchecked(&event->child_total_time_enabled);
75298 *running += event->total_time_running +
75299- atomic64_read(&event->child_total_time_running);
75300+ atomic64_read_unchecked(&event->child_total_time_running);
75301
75302 list_for_each_entry(child, &event->child_list, child_list) {
75303 total += perf_event_read(child);
75304@@ -3408,10 +3415,10 @@ void perf_event_update_userpage(struct perf_event *event)
75305 userpg->offset -= local64_read(&event->hw.prev_count);
75306
75307 userpg->time_enabled = enabled +
75308- atomic64_read(&event->child_total_time_enabled);
75309+ atomic64_read_unchecked(&event->child_total_time_enabled);
75310
75311 userpg->time_running = running +
75312- atomic64_read(&event->child_total_time_running);
75313+ atomic64_read_unchecked(&event->child_total_time_running);
75314
75315 arch_perf_update_userpage(userpg, now);
75316
75317@@ -3961,7 +3968,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
75318
75319 /* Data. */
75320 sp = perf_user_stack_pointer(regs);
75321- rem = __output_copy_user(handle, (void *) sp, dump_size);
75322+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
75323 dyn_size = dump_size - rem;
75324
75325 perf_output_skip(handle, rem);
75326@@ -4049,11 +4056,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
75327 values[n++] = perf_event_count(event);
75328 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
75329 values[n++] = enabled +
75330- atomic64_read(&event->child_total_time_enabled);
75331+ atomic64_read_unchecked(&event->child_total_time_enabled);
75332 }
75333 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
75334 values[n++] = running +
75335- atomic64_read(&event->child_total_time_running);
75336+ atomic64_read_unchecked(&event->child_total_time_running);
75337 }
75338 if (read_format & PERF_FORMAT_ID)
75339 values[n++] = primary_event_id(event);
75340@@ -4801,12 +4808,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
75341 * need to add enough zero bytes after the string to handle
75342 * the 64bit alignment we do later.
75343 */
75344- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
75345+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
75346 if (!buf) {
75347 name = strncpy(tmp, "//enomem", sizeof(tmp));
75348 goto got_name;
75349 }
75350- name = d_path(&file->f_path, buf, PATH_MAX);
75351+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
75352 if (IS_ERR(name)) {
75353 name = strncpy(tmp, "//toolong", sizeof(tmp));
75354 goto got_name;
75355@@ -6242,7 +6249,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
75356 event->parent = parent_event;
75357
75358 event->ns = get_pid_ns(task_active_pid_ns(current));
75359- event->id = atomic64_inc_return(&perf_event_id);
75360+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
75361
75362 event->state = PERF_EVENT_STATE_INACTIVE;
75363
75364@@ -6552,6 +6559,11 @@ SYSCALL_DEFINE5(perf_event_open,
75365 if (flags & ~PERF_FLAG_ALL)
75366 return -EINVAL;
75367
75368+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
75369+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
75370+ return -EACCES;
75371+#endif
75372+
75373 err = perf_copy_attr(attr_uptr, &attr);
75374 if (err)
75375 return err;
75376@@ -6884,10 +6896,10 @@ static void sync_child_event(struct perf_event *child_event,
75377 /*
75378 * Add back the child's count to the parent's count:
75379 */
75380- atomic64_add(child_val, &parent_event->child_count);
75381- atomic64_add(child_event->total_time_enabled,
75382+ atomic64_add_unchecked(child_val, &parent_event->child_count);
75383+ atomic64_add_unchecked(child_event->total_time_enabled,
75384 &parent_event->child_total_time_enabled);
75385- atomic64_add(child_event->total_time_running,
75386+ atomic64_add_unchecked(child_event->total_time_running,
75387 &parent_event->child_total_time_running);
75388
75389 /*
75390diff --git a/kernel/events/internal.h b/kernel/events/internal.h
75391index ca65997..cc8cee4 100644
75392--- a/kernel/events/internal.h
75393+++ b/kernel/events/internal.h
75394@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
75395 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
75396 }
75397
75398-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
75399+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
75400 static inline unsigned int \
75401 func_name(struct perf_output_handle *handle, \
75402- const void *buf, unsigned int len) \
75403+ const void user *buf, unsigned int len) \
75404 { \
75405 unsigned long size, written; \
75406 \
75407@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
75408 return n;
75409 }
75410
75411-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
75412+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
75413
75414 #define MEMCPY_SKIP(dst, src, n) (n)
75415
75416-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
75417+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
75418
75419 #ifndef arch_perf_out_copy_user
75420 #define arch_perf_out_copy_user __copy_from_user_inatomic
75421 #endif
75422
75423-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
75424+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
75425
75426 /* Callchain handling */
75427 extern struct perf_callchain_entry *
75428diff --git a/kernel/exit.c b/kernel/exit.c
75429index 60bc027..ca6d727 100644
75430--- a/kernel/exit.c
75431+++ b/kernel/exit.c
75432@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
75433 struct task_struct *leader;
75434 int zap_leader;
75435 repeat:
75436+#ifdef CONFIG_NET
75437+ gr_del_task_from_ip_table(p);
75438+#endif
75439+
75440 /* don't need to get the RCU readlock here - the process is dead and
75441 * can't be modifying its own credentials. But shut RCU-lockdep up */
75442 rcu_read_lock();
75443@@ -340,7 +344,7 @@ int allow_signal(int sig)
75444 * know it'll be handled, so that they don't get converted to
75445 * SIGKILL or just silently dropped.
75446 */
75447- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
75448+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
75449 recalc_sigpending();
75450 spin_unlock_irq(&current->sighand->siglock);
75451 return 0;
75452@@ -710,6 +714,8 @@ void do_exit(long code)
75453 struct task_struct *tsk = current;
75454 int group_dead;
75455
75456+ set_fs(USER_DS);
75457+
75458 profile_task_exit(tsk);
75459
75460 WARN_ON(blk_needs_flush_plug(tsk));
75461@@ -726,7 +732,6 @@ void do_exit(long code)
75462 * mm_release()->clear_child_tid() from writing to a user-controlled
75463 * kernel address.
75464 */
75465- set_fs(USER_DS);
75466
75467 ptrace_event(PTRACE_EVENT_EXIT, code);
75468
75469@@ -785,6 +790,9 @@ void do_exit(long code)
75470 tsk->exit_code = code;
75471 taskstats_exit(tsk, group_dead);
75472
75473+ gr_acl_handle_psacct(tsk, code);
75474+ gr_acl_handle_exit();
75475+
75476 exit_mm(tsk);
75477
75478 if (group_dead)
75479@@ -905,7 +913,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
75480 * Take down every thread in the group. This is called by fatal signals
75481 * as well as by sys_exit_group (below).
75482 */
75483-void
75484+__noreturn void
75485 do_group_exit(int exit_code)
75486 {
75487 struct signal_struct *sig = current->signal;
75488diff --git a/kernel/fork.c b/kernel/fork.c
75489index 1766d32..c0e44e2 100644
75490--- a/kernel/fork.c
75491+++ b/kernel/fork.c
75492@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
75493 *stackend = STACK_END_MAGIC; /* for overflow detection */
75494
75495 #ifdef CONFIG_CC_STACKPROTECTOR
75496- tsk->stack_canary = get_random_int();
75497+ tsk->stack_canary = pax_get_random_long();
75498 #endif
75499
75500 /*
75501@@ -344,13 +344,81 @@ free_tsk:
75502 }
75503
75504 #ifdef CONFIG_MMU
75505+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
75506+{
75507+ struct vm_area_struct *tmp;
75508+ unsigned long charge;
75509+ struct mempolicy *pol;
75510+ struct file *file;
75511+
75512+ charge = 0;
75513+ if (mpnt->vm_flags & VM_ACCOUNT) {
75514+ unsigned long len = vma_pages(mpnt);
75515+
75516+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75517+ goto fail_nomem;
75518+ charge = len;
75519+ }
75520+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75521+ if (!tmp)
75522+ goto fail_nomem;
75523+ *tmp = *mpnt;
75524+ tmp->vm_mm = mm;
75525+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
75526+ pol = mpol_dup(vma_policy(mpnt));
75527+ if (IS_ERR(pol))
75528+ goto fail_nomem_policy;
75529+ vma_set_policy(tmp, pol);
75530+ if (anon_vma_fork(tmp, mpnt))
75531+ goto fail_nomem_anon_vma_fork;
75532+ tmp->vm_flags &= ~VM_LOCKED;
75533+ tmp->vm_next = tmp->vm_prev = NULL;
75534+ tmp->vm_mirror = NULL;
75535+ file = tmp->vm_file;
75536+ if (file) {
75537+ struct inode *inode = file_inode(file);
75538+ struct address_space *mapping = file->f_mapping;
75539+
75540+ get_file(file);
75541+ if (tmp->vm_flags & VM_DENYWRITE)
75542+ atomic_dec(&inode->i_writecount);
75543+ mutex_lock(&mapping->i_mmap_mutex);
75544+ if (tmp->vm_flags & VM_SHARED)
75545+ mapping->i_mmap_writable++;
75546+ flush_dcache_mmap_lock(mapping);
75547+ /* insert tmp into the share list, just after mpnt */
75548+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75549+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
75550+ else
75551+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
75552+ flush_dcache_mmap_unlock(mapping);
75553+ mutex_unlock(&mapping->i_mmap_mutex);
75554+ }
75555+
75556+ /*
75557+ * Clear hugetlb-related page reserves for children. This only
75558+ * affects MAP_PRIVATE mappings. Faults generated by the child
75559+ * are not guaranteed to succeed, even if read-only
75560+ */
75561+ if (is_vm_hugetlb_page(tmp))
75562+ reset_vma_resv_huge_pages(tmp);
75563+
75564+ return tmp;
75565+
75566+fail_nomem_anon_vma_fork:
75567+ mpol_put(pol);
75568+fail_nomem_policy:
75569+ kmem_cache_free(vm_area_cachep, tmp);
75570+fail_nomem:
75571+ vm_unacct_memory(charge);
75572+ return NULL;
75573+}
75574+
75575 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75576 {
75577 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
75578 struct rb_node **rb_link, *rb_parent;
75579 int retval;
75580- unsigned long charge;
75581- struct mempolicy *pol;
75582
75583 uprobe_start_dup_mmap();
75584 down_write(&oldmm->mmap_sem);
75585@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75586 mm->locked_vm = 0;
75587 mm->mmap = NULL;
75588 mm->mmap_cache = NULL;
75589- mm->free_area_cache = oldmm->mmap_base;
75590- mm->cached_hole_size = ~0UL;
75591+ mm->free_area_cache = oldmm->free_area_cache;
75592+ mm->cached_hole_size = oldmm->cached_hole_size;
75593 mm->map_count = 0;
75594 cpumask_clear(mm_cpumask(mm));
75595 mm->mm_rb = RB_ROOT;
75596@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75597
75598 prev = NULL;
75599 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
75600- struct file *file;
75601-
75602 if (mpnt->vm_flags & VM_DONTCOPY) {
75603 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
75604 -vma_pages(mpnt));
75605 continue;
75606 }
75607- charge = 0;
75608- if (mpnt->vm_flags & VM_ACCOUNT) {
75609- unsigned long len = vma_pages(mpnt);
75610-
75611- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75612- goto fail_nomem;
75613- charge = len;
75614- }
75615- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75616- if (!tmp)
75617- goto fail_nomem;
75618- *tmp = *mpnt;
75619- INIT_LIST_HEAD(&tmp->anon_vma_chain);
75620- pol = mpol_dup(vma_policy(mpnt));
75621- retval = PTR_ERR(pol);
75622- if (IS_ERR(pol))
75623- goto fail_nomem_policy;
75624- vma_set_policy(tmp, pol);
75625- tmp->vm_mm = mm;
75626- if (anon_vma_fork(tmp, mpnt))
75627- goto fail_nomem_anon_vma_fork;
75628- tmp->vm_flags &= ~VM_LOCKED;
75629- tmp->vm_next = tmp->vm_prev = NULL;
75630- file = tmp->vm_file;
75631- if (file) {
75632- struct inode *inode = file_inode(file);
75633- struct address_space *mapping = file->f_mapping;
75634-
75635- get_file(file);
75636- if (tmp->vm_flags & VM_DENYWRITE)
75637- atomic_dec(&inode->i_writecount);
75638- mutex_lock(&mapping->i_mmap_mutex);
75639- if (tmp->vm_flags & VM_SHARED)
75640- mapping->i_mmap_writable++;
75641- flush_dcache_mmap_lock(mapping);
75642- /* insert tmp into the share list, just after mpnt */
75643- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75644- vma_nonlinear_insert(tmp,
75645- &mapping->i_mmap_nonlinear);
75646- else
75647- vma_interval_tree_insert_after(tmp, mpnt,
75648- &mapping->i_mmap);
75649- flush_dcache_mmap_unlock(mapping);
75650- mutex_unlock(&mapping->i_mmap_mutex);
75651+ tmp = dup_vma(mm, oldmm, mpnt);
75652+ if (!tmp) {
75653+ retval = -ENOMEM;
75654+ goto out;
75655 }
75656
75657 /*
75658@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75659 if (retval)
75660 goto out;
75661 }
75662+
75663+#ifdef CONFIG_PAX_SEGMEXEC
75664+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
75665+ struct vm_area_struct *mpnt_m;
75666+
75667+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
75668+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
75669+
75670+ if (!mpnt->vm_mirror)
75671+ continue;
75672+
75673+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
75674+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
75675+ mpnt->vm_mirror = mpnt_m;
75676+ } else {
75677+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
75678+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
75679+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
75680+ mpnt->vm_mirror->vm_mirror = mpnt;
75681+ }
75682+ }
75683+ BUG_ON(mpnt_m);
75684+ }
75685+#endif
75686+
75687 /* a new mm has just been created */
75688 arch_dup_mmap(oldmm, mm);
75689 retval = 0;
75690@@ -472,14 +523,6 @@ out:
75691 up_write(&oldmm->mmap_sem);
75692 uprobe_end_dup_mmap();
75693 return retval;
75694-fail_nomem_anon_vma_fork:
75695- mpol_put(pol);
75696-fail_nomem_policy:
75697- kmem_cache_free(vm_area_cachep, tmp);
75698-fail_nomem:
75699- retval = -ENOMEM;
75700- vm_unacct_memory(charge);
75701- goto out;
75702 }
75703
75704 static inline int mm_alloc_pgd(struct mm_struct *mm)
75705@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
75706 return ERR_PTR(err);
75707
75708 mm = get_task_mm(task);
75709- if (mm && mm != current->mm &&
75710- !ptrace_may_access(task, mode)) {
75711+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
75712+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
75713 mmput(mm);
75714 mm = ERR_PTR(-EACCES);
75715 }
75716@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
75717 spin_unlock(&fs->lock);
75718 return -EAGAIN;
75719 }
75720- fs->users++;
75721+ atomic_inc(&fs->users);
75722 spin_unlock(&fs->lock);
75723 return 0;
75724 }
75725 tsk->fs = copy_fs_struct(fs);
75726 if (!tsk->fs)
75727 return -ENOMEM;
75728+ /* Carry through gr_chroot_dentry and is_chrooted instead
75729+ of recomputing it here. Already copied when the task struct
75730+ is duplicated. This allows pivot_root to not be treated as
75731+ a chroot
75732+ */
75733+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
75734+
75735 return 0;
75736 }
75737
75738@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75739 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
75740 #endif
75741 retval = -EAGAIN;
75742+
75743+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
75744+
75745 if (atomic_read(&p->real_cred->user->processes) >=
75746 task_rlimit(p, RLIMIT_NPROC)) {
75747 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
75748@@ -1441,6 +1494,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75749 goto bad_fork_free_pid;
75750 }
75751
75752+ /* synchronizes with gr_set_acls()
75753+ we need to call this past the point of no return for fork()
75754+ */
75755+ gr_copy_label(p);
75756+
75757 if (clone_flags & CLONE_THREAD) {
75758 current->signal->nr_threads++;
75759 atomic_inc(&current->signal->live);
75760@@ -1524,6 +1582,8 @@ bad_fork_cleanup_count:
75761 bad_fork_free:
75762 free_task(p);
75763 fork_out:
75764+ gr_log_forkfail(retval);
75765+
75766 return ERR_PTR(retval);
75767 }
75768
75769@@ -1574,6 +1634,23 @@ long do_fork(unsigned long clone_flags,
75770 return -EINVAL;
75771 }
75772
75773+#ifdef CONFIG_GRKERNSEC
75774+ if (clone_flags & CLONE_NEWUSER) {
75775+ /*
75776+ * This doesn't really inspire confidence:
75777+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
75778+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
75779+ * Increases kernel attack surface in areas developers
75780+ * previously cared little about ("low importance due
75781+ * to requiring "root" capability")
75782+ * To be removed when this code receives *proper* review
75783+ */
75784+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
75785+ !capable(CAP_SETGID))
75786+ return -EPERM;
75787+ }
75788+#endif
75789+
75790 /*
75791 * Determine whether and which event to report to ptracer. When
75792 * called from kernel_thread or CLONE_UNTRACED is explicitly
75793@@ -1608,6 +1685,8 @@ long do_fork(unsigned long clone_flags,
75794 if (clone_flags & CLONE_PARENT_SETTID)
75795 put_user(nr, parent_tidptr);
75796
75797+ gr_handle_brute_check();
75798+
75799 if (clone_flags & CLONE_VFORK) {
75800 p->vfork_done = &vfork;
75801 init_completion(&vfork);
75802@@ -1761,7 +1840,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
75803 return 0;
75804
75805 /* don't need lock here; in the worst case we'll do useless copy */
75806- if (fs->users == 1)
75807+ if (atomic_read(&fs->users) == 1)
75808 return 0;
75809
75810 *new_fsp = copy_fs_struct(fs);
75811@@ -1873,7 +1952,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
75812 fs = current->fs;
75813 spin_lock(&fs->lock);
75814 current->fs = new_fs;
75815- if (--fs->users)
75816+ gr_set_chroot_entries(current, &current->fs->root);
75817+ if (atomic_dec_return(&fs->users))
75818 new_fs = NULL;
75819 else
75820 new_fs = fs;
75821diff --git a/kernel/futex.c b/kernel/futex.c
75822index b26dcfc..39e266a 100644
75823--- a/kernel/futex.c
75824+++ b/kernel/futex.c
75825@@ -54,6 +54,7 @@
75826 #include <linux/mount.h>
75827 #include <linux/pagemap.h>
75828 #include <linux/syscalls.h>
75829+#include <linux/ptrace.h>
75830 #include <linux/signal.h>
75831 #include <linux/export.h>
75832 #include <linux/magic.h>
75833@@ -241,6 +242,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
75834 struct page *page, *page_head;
75835 int err, ro = 0;
75836
75837+#ifdef CONFIG_PAX_SEGMEXEC
75838+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
75839+ return -EFAULT;
75840+#endif
75841+
75842 /*
75843 * The futex address must be "naturally" aligned.
75844 */
75845@@ -2732,6 +2738,7 @@ static int __init futex_init(void)
75846 {
75847 u32 curval;
75848 int i;
75849+ mm_segment_t oldfs;
75850
75851 /*
75852 * This will fail and we want it. Some arch implementations do
75853@@ -2743,8 +2750,11 @@ static int __init futex_init(void)
75854 * implementation, the non-functional ones will return
75855 * -ENOSYS.
75856 */
75857+ oldfs = get_fs();
75858+ set_fs(USER_DS);
75859 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
75860 futex_cmpxchg_enabled = 1;
75861+ set_fs(oldfs);
75862
75863 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
75864 plist_head_init(&futex_queues[i].chain);
75865diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
75866index f9f44fd..29885e4 100644
75867--- a/kernel/futex_compat.c
75868+++ b/kernel/futex_compat.c
75869@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
75870 return 0;
75871 }
75872
75873-static void __user *futex_uaddr(struct robust_list __user *entry,
75874+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
75875 compat_long_t futex_offset)
75876 {
75877 compat_uptr_t base = ptr_to_compat(entry);
75878diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
75879index 9b22d03..6295b62 100644
75880--- a/kernel/gcov/base.c
75881+++ b/kernel/gcov/base.c
75882@@ -102,11 +102,6 @@ void gcov_enable_events(void)
75883 }
75884
75885 #ifdef CONFIG_MODULES
75886-static inline int within(void *addr, void *start, unsigned long size)
75887-{
75888- return ((addr >= start) && (addr < start + size));
75889-}
75890-
75891 /* Update list and generate events when modules are unloaded. */
75892 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75893 void *data)
75894@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75895 prev = NULL;
75896 /* Remove entries located in module from linked list. */
75897 for (info = gcov_info_head; info; info = info->next) {
75898- if (within(info, mod->module_core, mod->core_size)) {
75899+ if (within_module_core_rw((unsigned long)info, mod)) {
75900 if (prev)
75901 prev->next = info->next;
75902 else
75903diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
75904index 7ef5556..8247f11 100644
75905--- a/kernel/hrtimer.c
75906+++ b/kernel/hrtimer.c
75907@@ -1416,7 +1416,7 @@ void hrtimer_peek_ahead_timers(void)
75908 local_irq_restore(flags);
75909 }
75910
75911-static void run_hrtimer_softirq(struct softirq_action *h)
75912+static void run_hrtimer_softirq(void)
75913 {
75914 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
75915
75916@@ -1758,7 +1758,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
75917 return NOTIFY_OK;
75918 }
75919
75920-static struct notifier_block __cpuinitdata hrtimers_nb = {
75921+static struct notifier_block hrtimers_nb = {
75922 .notifier_call = hrtimer_cpu_notify,
75923 };
75924
75925diff --git a/kernel/irq_work.c b/kernel/irq_work.c
75926index 55fcce6..0e4cf34 100644
75927--- a/kernel/irq_work.c
75928+++ b/kernel/irq_work.c
75929@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
75930 return NOTIFY_OK;
75931 }
75932
75933-static struct notifier_block cpu_notify;
75934+static struct notifier_block cpu_notify = {
75935+ .notifier_call = irq_work_cpu_notify,
75936+ .priority = 0,
75937+};
75938
75939 static __init int irq_work_init_cpu_notifier(void)
75940 {
75941- cpu_notify.notifier_call = irq_work_cpu_notify;
75942- cpu_notify.priority = 0;
75943 register_cpu_notifier(&cpu_notify);
75944 return 0;
75945 }
75946diff --git a/kernel/jump_label.c b/kernel/jump_label.c
75947index 60f48fa..7f3a770 100644
75948--- a/kernel/jump_label.c
75949+++ b/kernel/jump_label.c
75950@@ -13,6 +13,7 @@
75951 #include <linux/sort.h>
75952 #include <linux/err.h>
75953 #include <linux/static_key.h>
75954+#include <linux/mm.h>
75955
75956 #ifdef HAVE_JUMP_LABEL
75957
75958@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
75959
75960 size = (((unsigned long)stop - (unsigned long)start)
75961 / sizeof(struct jump_entry));
75962+ pax_open_kernel();
75963 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
75964+ pax_close_kernel();
75965 }
75966
75967 static void jump_label_update(struct static_key *key, int enable);
75968@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
75969 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
75970 struct jump_entry *iter;
75971
75972+ pax_open_kernel();
75973 for (iter = iter_start; iter < iter_stop; iter++) {
75974 if (within_module_init(iter->code, mod))
75975 iter->code = 0;
75976 }
75977+ pax_close_kernel();
75978 }
75979
75980 static int
75981diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
75982index 2169fee..706ccca 100644
75983--- a/kernel/kallsyms.c
75984+++ b/kernel/kallsyms.c
75985@@ -11,6 +11,9 @@
75986 * Changed the compression method from stem compression to "table lookup"
75987 * compression (see scripts/kallsyms.c for a more complete description)
75988 */
75989+#ifdef CONFIG_GRKERNSEC_HIDESYM
75990+#define __INCLUDED_BY_HIDESYM 1
75991+#endif
75992 #include <linux/kallsyms.h>
75993 #include <linux/module.h>
75994 #include <linux/init.h>
75995@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
75996
75997 static inline int is_kernel_inittext(unsigned long addr)
75998 {
75999+ if (system_state != SYSTEM_BOOTING)
76000+ return 0;
76001+
76002 if (addr >= (unsigned long)_sinittext
76003 && addr <= (unsigned long)_einittext)
76004 return 1;
76005 return 0;
76006 }
76007
76008+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76009+#ifdef CONFIG_MODULES
76010+static inline int is_module_text(unsigned long addr)
76011+{
76012+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
76013+ return 1;
76014+
76015+ addr = ktla_ktva(addr);
76016+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
76017+}
76018+#else
76019+static inline int is_module_text(unsigned long addr)
76020+{
76021+ return 0;
76022+}
76023+#endif
76024+#endif
76025+
76026 static inline int is_kernel_text(unsigned long addr)
76027 {
76028 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
76029@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
76030
76031 static inline int is_kernel(unsigned long addr)
76032 {
76033+
76034+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76035+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
76036+ return 1;
76037+
76038+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
76039+#else
76040 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
76041+#endif
76042+
76043 return 1;
76044 return in_gate_area_no_mm(addr);
76045 }
76046
76047 static int is_ksym_addr(unsigned long addr)
76048 {
76049+
76050+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76051+ if (is_module_text(addr))
76052+ return 0;
76053+#endif
76054+
76055 if (all_var)
76056 return is_kernel(addr);
76057
76058@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
76059
76060 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
76061 {
76062- iter->name[0] = '\0';
76063 iter->nameoff = get_symbol_offset(new_pos);
76064 iter->pos = new_pos;
76065 }
76066@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
76067 {
76068 struct kallsym_iter *iter = m->private;
76069
76070+#ifdef CONFIG_GRKERNSEC_HIDESYM
76071+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
76072+ return 0;
76073+#endif
76074+
76075 /* Some debugging symbols have no name. Ignore them. */
76076 if (!iter->name[0])
76077 return 0;
76078@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
76079 */
76080 type = iter->exported ? toupper(iter->type) :
76081 tolower(iter->type);
76082+
76083 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
76084 type, iter->name, iter->module_name);
76085 } else
76086@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
76087 struct kallsym_iter *iter;
76088 int ret;
76089
76090- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
76091+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
76092 if (!iter)
76093 return -ENOMEM;
76094 reset_iter(iter, 0);
76095diff --git a/kernel/kcmp.c b/kernel/kcmp.c
76096index e30ac0f..3528cac 100644
76097--- a/kernel/kcmp.c
76098+++ b/kernel/kcmp.c
76099@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
76100 struct task_struct *task1, *task2;
76101 int ret;
76102
76103+#ifdef CONFIG_GRKERNSEC
76104+ return -ENOSYS;
76105+#endif
76106+
76107 rcu_read_lock();
76108
76109 /*
76110diff --git a/kernel/kexec.c b/kernel/kexec.c
76111index ffd4e11..c3ff6bf 100644
76112--- a/kernel/kexec.c
76113+++ b/kernel/kexec.c
76114@@ -1048,7 +1048,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
76115 unsigned long flags)
76116 {
76117 struct compat_kexec_segment in;
76118- struct kexec_segment out, __user *ksegments;
76119+ struct kexec_segment out;
76120+ struct kexec_segment __user *ksegments;
76121 unsigned long i, result;
76122
76123 /* Don't allow clients that don't understand the native
76124diff --git a/kernel/kmod.c b/kernel/kmod.c
76125index 8985c87..f539dbe 100644
76126--- a/kernel/kmod.c
76127+++ b/kernel/kmod.c
76128@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
76129 kfree(info->argv);
76130 }
76131
76132-static int call_modprobe(char *module_name, int wait)
76133+static int call_modprobe(char *module_name, char *module_param, int wait)
76134 {
76135 static char *envp[] = {
76136 "HOME=/",
76137@@ -84,7 +84,7 @@ static int call_modprobe(char *module_name, int wait)
76138 NULL
76139 };
76140
76141- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
76142+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
76143 if (!argv)
76144 goto out;
76145
76146@@ -96,7 +96,8 @@ static int call_modprobe(char *module_name, int wait)
76147 argv[1] = "-q";
76148 argv[2] = "--";
76149 argv[3] = module_name; /* check free_modprobe_argv() */
76150- argv[4] = NULL;
76151+ argv[4] = module_param;
76152+ argv[5] = NULL;
76153
76154 return call_usermodehelper_fns(modprobe_path, argv, envp,
76155 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
76156@@ -121,9 +122,8 @@ out:
76157 * If module auto-loading support is disabled then this function
76158 * becomes a no-operation.
76159 */
76160-int __request_module(bool wait, const char *fmt, ...)
76161+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
76162 {
76163- va_list args;
76164 char module_name[MODULE_NAME_LEN];
76165 unsigned int max_modprobes;
76166 int ret;
76167@@ -139,9 +139,7 @@ int __request_module(bool wait, const char *fmt, ...)
76168 */
76169 WARN_ON_ONCE(wait && current_is_async());
76170
76171- va_start(args, fmt);
76172- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
76173- va_end(args);
76174+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
76175 if (ret >= MODULE_NAME_LEN)
76176 return -ENAMETOOLONG;
76177
76178@@ -149,6 +147,20 @@ int __request_module(bool wait, const char *fmt, ...)
76179 if (ret)
76180 return ret;
76181
76182+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76183+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
76184+ /* hack to workaround consolekit/udisks stupidity */
76185+ read_lock(&tasklist_lock);
76186+ if (!strcmp(current->comm, "mount") &&
76187+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
76188+ read_unlock(&tasklist_lock);
76189+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
76190+ return -EPERM;
76191+ }
76192+ read_unlock(&tasklist_lock);
76193+ }
76194+#endif
76195+
76196 /* If modprobe needs a service that is in a module, we get a recursive
76197 * loop. Limit the number of running kmod threads to max_threads/2 or
76198 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
76199@@ -177,11 +189,52 @@ int __request_module(bool wait, const char *fmt, ...)
76200
76201 trace_module_request(module_name, wait, _RET_IP_);
76202
76203- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
76204+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
76205
76206 atomic_dec(&kmod_concurrent);
76207 return ret;
76208 }
76209+
76210+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
76211+{
76212+ va_list args;
76213+ int ret;
76214+
76215+ va_start(args, fmt);
76216+ ret = ____request_module(wait, module_param, fmt, args);
76217+ va_end(args);
76218+
76219+ return ret;
76220+}
76221+
76222+int __request_module(bool wait, const char *fmt, ...)
76223+{
76224+ va_list args;
76225+ int ret;
76226+
76227+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76228+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
76229+ char module_param[MODULE_NAME_LEN];
76230+
76231+ memset(module_param, 0, sizeof(module_param));
76232+
76233+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
76234+
76235+ va_start(args, fmt);
76236+ ret = ____request_module(wait, module_param, fmt, args);
76237+ va_end(args);
76238+
76239+ return ret;
76240+ }
76241+#endif
76242+
76243+ va_start(args, fmt);
76244+ ret = ____request_module(wait, NULL, fmt, args);
76245+ va_end(args);
76246+
76247+ return ret;
76248+}
76249+
76250 EXPORT_SYMBOL(__request_module);
76251 #endif /* CONFIG_MODULES */
76252
76253@@ -292,7 +345,7 @@ static int wait_for_helper(void *data)
76254 *
76255 * Thus the __user pointer cast is valid here.
76256 */
76257- sys_wait4(pid, (int __user *)&ret, 0, NULL);
76258+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
76259
76260 /*
76261 * If ret is 0, either ____call_usermodehelper failed and the
76262@@ -649,7 +702,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
76263 static int proc_cap_handler(struct ctl_table *table, int write,
76264 void __user *buffer, size_t *lenp, loff_t *ppos)
76265 {
76266- struct ctl_table t;
76267+ ctl_table_no_const t;
76268 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
76269 kernel_cap_t new_cap;
76270 int err, i;
76271diff --git a/kernel/kprobes.c b/kernel/kprobes.c
76272index 3fed7f0..a3f95ed 100644
76273--- a/kernel/kprobes.c
76274+++ b/kernel/kprobes.c
76275@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
76276 * kernel image and loaded module images reside. This is required
76277 * so x86_64 can correctly handle the %rip-relative fixups.
76278 */
76279- kip->insns = module_alloc(PAGE_SIZE);
76280+ kip->insns = module_alloc_exec(PAGE_SIZE);
76281 if (!kip->insns) {
76282 kfree(kip);
76283 return NULL;
76284@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
76285 */
76286 if (!list_is_singular(&kip->list)) {
76287 list_del(&kip->list);
76288- module_free(NULL, kip->insns);
76289+ module_free_exec(NULL, kip->insns);
76290 kfree(kip);
76291 }
76292 return 1;
76293@@ -2073,7 +2073,7 @@ static int __init init_kprobes(void)
76294 {
76295 int i, err = 0;
76296 unsigned long offset = 0, size = 0;
76297- char *modname, namebuf[128];
76298+ char *modname, namebuf[KSYM_NAME_LEN];
76299 const char *symbol_name;
76300 void *addr;
76301 struct kprobe_blackpoint *kb;
76302@@ -2158,11 +2158,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
76303 kprobe_type = "k";
76304
76305 if (sym)
76306- seq_printf(pi, "%p %s %s+0x%x %s ",
76307+ seq_printf(pi, "%pK %s %s+0x%x %s ",
76308 p->addr, kprobe_type, sym, offset,
76309 (modname ? modname : " "));
76310 else
76311- seq_printf(pi, "%p %s %p ",
76312+ seq_printf(pi, "%pK %s %pK ",
76313 p->addr, kprobe_type, p->addr);
76314
76315 if (!pp)
76316@@ -2199,7 +2199,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
76317 const char *sym = NULL;
76318 unsigned int i = *(loff_t *) v;
76319 unsigned long offset = 0;
76320- char *modname, namebuf[128];
76321+ char *modname, namebuf[KSYM_NAME_LEN];
76322
76323 head = &kprobe_table[i];
76324 preempt_disable();
76325diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
76326index 6ada93c..dce7d5d 100644
76327--- a/kernel/ksysfs.c
76328+++ b/kernel/ksysfs.c
76329@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
76330 {
76331 if (count+1 > UEVENT_HELPER_PATH_LEN)
76332 return -ENOENT;
76333+ if (!capable(CAP_SYS_ADMIN))
76334+ return -EPERM;
76335 memcpy(uevent_helper, buf, count);
76336 uevent_helper[count] = '\0';
76337 if (count && uevent_helper[count-1] == '\n')
76338@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
76339 return count;
76340 }
76341
76342-static struct bin_attribute notes_attr = {
76343+static bin_attribute_no_const notes_attr __read_only = {
76344 .attr = {
76345 .name = "notes",
76346 .mode = S_IRUGO,
76347diff --git a/kernel/lockdep.c b/kernel/lockdep.c
76348index 8a0efac..56f1e2d 100644
76349--- a/kernel/lockdep.c
76350+++ b/kernel/lockdep.c
76351@@ -590,6 +590,10 @@ static int static_obj(void *obj)
76352 end = (unsigned long) &_end,
76353 addr = (unsigned long) obj;
76354
76355+#ifdef CONFIG_PAX_KERNEXEC
76356+ start = ktla_ktva(start);
76357+#endif
76358+
76359 /*
76360 * static variable?
76361 */
76362@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
76363 if (!static_obj(lock->key)) {
76364 debug_locks_off();
76365 printk("INFO: trying to register non-static key.\n");
76366+ printk("lock:%pS key:%pS.\n", lock, lock->key);
76367 printk("the code is fine but needs lockdep annotation.\n");
76368 printk("turning off the locking correctness validator.\n");
76369 dump_stack();
76370@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
76371 if (!class)
76372 return 0;
76373 }
76374- atomic_inc((atomic_t *)&class->ops);
76375+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
76376 if (very_verbose(class)) {
76377 printk("\nacquire class [%p] %s", class->key, class->name);
76378 if (class->name_version > 1)
76379diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
76380index b2c71c5..7b88d63 100644
76381--- a/kernel/lockdep_proc.c
76382+++ b/kernel/lockdep_proc.c
76383@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
76384 return 0;
76385 }
76386
76387- seq_printf(m, "%p", class->key);
76388+ seq_printf(m, "%pK", class->key);
76389 #ifdef CONFIG_DEBUG_LOCKDEP
76390 seq_printf(m, " OPS:%8ld", class->ops);
76391 #endif
76392@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
76393
76394 list_for_each_entry(entry, &class->locks_after, entry) {
76395 if (entry->distance == 1) {
76396- seq_printf(m, " -> [%p] ", entry->class->key);
76397+ seq_printf(m, " -> [%pK] ", entry->class->key);
76398 print_name(m, entry->class);
76399 seq_puts(m, "\n");
76400 }
76401@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
76402 if (!class->key)
76403 continue;
76404
76405- seq_printf(m, "[%p] ", class->key);
76406+ seq_printf(m, "[%pK] ", class->key);
76407 print_name(m, class);
76408 seq_puts(m, "\n");
76409 }
76410@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76411 if (!i)
76412 seq_line(m, '-', 40-namelen, namelen);
76413
76414- snprintf(ip, sizeof(ip), "[<%p>]",
76415+ snprintf(ip, sizeof(ip), "[<%pK>]",
76416 (void *)class->contention_point[i]);
76417 seq_printf(m, "%40s %14lu %29s %pS\n",
76418 name, stats->contention_point[i],
76419@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76420 if (!i)
76421 seq_line(m, '-', 40-namelen, namelen);
76422
76423- snprintf(ip, sizeof(ip), "[<%p>]",
76424+ snprintf(ip, sizeof(ip), "[<%pK>]",
76425 (void *)class->contending_point[i]);
76426 seq_printf(m, "%40s %14lu %29s %pS\n",
76427 name, stats->contending_point[i],
76428diff --git a/kernel/module.c b/kernel/module.c
76429index 97f202c..109575f 100644
76430--- a/kernel/module.c
76431+++ b/kernel/module.c
76432@@ -61,6 +61,7 @@
76433 #include <linux/pfn.h>
76434 #include <linux/bsearch.h>
76435 #include <linux/fips.h>
76436+#include <linux/grsecurity.h>
76437 #include <uapi/linux/module.h>
76438 #include "module-internal.h"
76439
76440@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
76441
76442 /* Bounds of module allocation, for speeding __module_address.
76443 * Protected by module_mutex. */
76444-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
76445+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
76446+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
76447
76448 int register_module_notifier(struct notifier_block * nb)
76449 {
76450@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76451 return true;
76452
76453 list_for_each_entry_rcu(mod, &modules, list) {
76454- struct symsearch arr[] = {
76455+ struct symsearch modarr[] = {
76456 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
76457 NOT_GPL_ONLY, false },
76458 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
76459@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76460 if (mod->state == MODULE_STATE_UNFORMED)
76461 continue;
76462
76463- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
76464+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
76465 return true;
76466 }
76467 return false;
76468@@ -485,7 +487,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
76469 static int percpu_modalloc(struct module *mod,
76470 unsigned long size, unsigned long align)
76471 {
76472- if (align > PAGE_SIZE) {
76473+ if (align-1 >= PAGE_SIZE) {
76474 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
76475 mod->name, align, PAGE_SIZE);
76476 align = PAGE_SIZE;
76477@@ -1089,7 +1091,7 @@ struct module_attribute module_uevent =
76478 static ssize_t show_coresize(struct module_attribute *mattr,
76479 struct module_kobject *mk, char *buffer)
76480 {
76481- return sprintf(buffer, "%u\n", mk->mod->core_size);
76482+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
76483 }
76484
76485 static struct module_attribute modinfo_coresize =
76486@@ -1098,7 +1100,7 @@ static struct module_attribute modinfo_coresize =
76487 static ssize_t show_initsize(struct module_attribute *mattr,
76488 struct module_kobject *mk, char *buffer)
76489 {
76490- return sprintf(buffer, "%u\n", mk->mod->init_size);
76491+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
76492 }
76493
76494 static struct module_attribute modinfo_initsize =
76495@@ -1312,7 +1314,7 @@ resolve_symbol_wait(struct module *mod,
76496 */
76497 #ifdef CONFIG_SYSFS
76498
76499-#ifdef CONFIG_KALLSYMS
76500+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76501 static inline bool sect_empty(const Elf_Shdr *sect)
76502 {
76503 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
76504@@ -1452,7 +1454,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
76505 {
76506 unsigned int notes, loaded, i;
76507 struct module_notes_attrs *notes_attrs;
76508- struct bin_attribute *nattr;
76509+ bin_attribute_no_const *nattr;
76510
76511 /* failed to create section attributes, so can't create notes */
76512 if (!mod->sect_attrs)
76513@@ -1564,7 +1566,7 @@ static void del_usage_links(struct module *mod)
76514 static int module_add_modinfo_attrs(struct module *mod)
76515 {
76516 struct module_attribute *attr;
76517- struct module_attribute *temp_attr;
76518+ module_attribute_no_const *temp_attr;
76519 int error = 0;
76520 int i;
76521
76522@@ -1778,21 +1780,21 @@ static void set_section_ro_nx(void *base,
76523
76524 static void unset_module_core_ro_nx(struct module *mod)
76525 {
76526- set_page_attributes(mod->module_core + mod->core_text_size,
76527- mod->module_core + mod->core_size,
76528+ set_page_attributes(mod->module_core_rw,
76529+ mod->module_core_rw + mod->core_size_rw,
76530 set_memory_x);
76531- set_page_attributes(mod->module_core,
76532- mod->module_core + mod->core_ro_size,
76533+ set_page_attributes(mod->module_core_rx,
76534+ mod->module_core_rx + mod->core_size_rx,
76535 set_memory_rw);
76536 }
76537
76538 static void unset_module_init_ro_nx(struct module *mod)
76539 {
76540- set_page_attributes(mod->module_init + mod->init_text_size,
76541- mod->module_init + mod->init_size,
76542+ set_page_attributes(mod->module_init_rw,
76543+ mod->module_init_rw + mod->init_size_rw,
76544 set_memory_x);
76545- set_page_attributes(mod->module_init,
76546- mod->module_init + mod->init_ro_size,
76547+ set_page_attributes(mod->module_init_rx,
76548+ mod->module_init_rx + mod->init_size_rx,
76549 set_memory_rw);
76550 }
76551
76552@@ -1805,14 +1807,14 @@ void set_all_modules_text_rw(void)
76553 list_for_each_entry_rcu(mod, &modules, list) {
76554 if (mod->state == MODULE_STATE_UNFORMED)
76555 continue;
76556- if ((mod->module_core) && (mod->core_text_size)) {
76557- set_page_attributes(mod->module_core,
76558- mod->module_core + mod->core_text_size,
76559+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76560+ set_page_attributes(mod->module_core_rx,
76561+ mod->module_core_rx + mod->core_size_rx,
76562 set_memory_rw);
76563 }
76564- if ((mod->module_init) && (mod->init_text_size)) {
76565- set_page_attributes(mod->module_init,
76566- mod->module_init + mod->init_text_size,
76567+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76568+ set_page_attributes(mod->module_init_rx,
76569+ mod->module_init_rx + mod->init_size_rx,
76570 set_memory_rw);
76571 }
76572 }
76573@@ -1828,14 +1830,14 @@ void set_all_modules_text_ro(void)
76574 list_for_each_entry_rcu(mod, &modules, list) {
76575 if (mod->state == MODULE_STATE_UNFORMED)
76576 continue;
76577- if ((mod->module_core) && (mod->core_text_size)) {
76578- set_page_attributes(mod->module_core,
76579- mod->module_core + mod->core_text_size,
76580+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76581+ set_page_attributes(mod->module_core_rx,
76582+ mod->module_core_rx + mod->core_size_rx,
76583 set_memory_ro);
76584 }
76585- if ((mod->module_init) && (mod->init_text_size)) {
76586- set_page_attributes(mod->module_init,
76587- mod->module_init + mod->init_text_size,
76588+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76589+ set_page_attributes(mod->module_init_rx,
76590+ mod->module_init_rx + mod->init_size_rx,
76591 set_memory_ro);
76592 }
76593 }
76594@@ -1886,16 +1888,19 @@ static void free_module(struct module *mod)
76595
76596 /* This may be NULL, but that's OK */
76597 unset_module_init_ro_nx(mod);
76598- module_free(mod, mod->module_init);
76599+ module_free(mod, mod->module_init_rw);
76600+ module_free_exec(mod, mod->module_init_rx);
76601 kfree(mod->args);
76602 percpu_modfree(mod);
76603
76604 /* Free lock-classes: */
76605- lockdep_free_key_range(mod->module_core, mod->core_size);
76606+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
76607+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
76608
76609 /* Finally, free the core (containing the module structure) */
76610 unset_module_core_ro_nx(mod);
76611- module_free(mod, mod->module_core);
76612+ module_free_exec(mod, mod->module_core_rx);
76613+ module_free(mod, mod->module_core_rw);
76614
76615 #ifdef CONFIG_MPU
76616 update_protections(current->mm);
76617@@ -1965,9 +1970,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76618 int ret = 0;
76619 const struct kernel_symbol *ksym;
76620
76621+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76622+ int is_fs_load = 0;
76623+ int register_filesystem_found = 0;
76624+ char *p;
76625+
76626+ p = strstr(mod->args, "grsec_modharden_fs");
76627+ if (p) {
76628+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
76629+ /* copy \0 as well */
76630+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
76631+ is_fs_load = 1;
76632+ }
76633+#endif
76634+
76635 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
76636 const char *name = info->strtab + sym[i].st_name;
76637
76638+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76639+ /* it's a real shame this will never get ripped and copied
76640+ upstream! ;(
76641+ */
76642+ if (is_fs_load && !strcmp(name, "register_filesystem"))
76643+ register_filesystem_found = 1;
76644+#endif
76645+
76646 switch (sym[i].st_shndx) {
76647 case SHN_COMMON:
76648 /* We compiled with -fno-common. These are not
76649@@ -1988,7 +2015,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76650 ksym = resolve_symbol_wait(mod, info, name);
76651 /* Ok if resolved. */
76652 if (ksym && !IS_ERR(ksym)) {
76653+ pax_open_kernel();
76654 sym[i].st_value = ksym->value;
76655+ pax_close_kernel();
76656 break;
76657 }
76658
76659@@ -2007,11 +2036,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76660 secbase = (unsigned long)mod_percpu(mod);
76661 else
76662 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
76663+ pax_open_kernel();
76664 sym[i].st_value += secbase;
76665+ pax_close_kernel();
76666 break;
76667 }
76668 }
76669
76670+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76671+ if (is_fs_load && !register_filesystem_found) {
76672+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
76673+ ret = -EPERM;
76674+ }
76675+#endif
76676+
76677 return ret;
76678 }
76679
76680@@ -2095,22 +2133,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
76681 || s->sh_entsize != ~0UL
76682 || strstarts(sname, ".init"))
76683 continue;
76684- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
76685+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76686+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
76687+ else
76688+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
76689 pr_debug("\t%s\n", sname);
76690 }
76691- switch (m) {
76692- case 0: /* executable */
76693- mod->core_size = debug_align(mod->core_size);
76694- mod->core_text_size = mod->core_size;
76695- break;
76696- case 1: /* RO: text and ro-data */
76697- mod->core_size = debug_align(mod->core_size);
76698- mod->core_ro_size = mod->core_size;
76699- break;
76700- case 3: /* whole core */
76701- mod->core_size = debug_align(mod->core_size);
76702- break;
76703- }
76704 }
76705
76706 pr_debug("Init section allocation order:\n");
76707@@ -2124,23 +2152,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
76708 || s->sh_entsize != ~0UL
76709 || !strstarts(sname, ".init"))
76710 continue;
76711- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
76712- | INIT_OFFSET_MASK);
76713+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76714+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
76715+ else
76716+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
76717+ s->sh_entsize |= INIT_OFFSET_MASK;
76718 pr_debug("\t%s\n", sname);
76719 }
76720- switch (m) {
76721- case 0: /* executable */
76722- mod->init_size = debug_align(mod->init_size);
76723- mod->init_text_size = mod->init_size;
76724- break;
76725- case 1: /* RO: text and ro-data */
76726- mod->init_size = debug_align(mod->init_size);
76727- mod->init_ro_size = mod->init_size;
76728- break;
76729- case 3: /* whole init */
76730- mod->init_size = debug_align(mod->init_size);
76731- break;
76732- }
76733 }
76734 }
76735
76736@@ -2313,7 +2331,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76737
76738 /* Put symbol section at end of init part of module. */
76739 symsect->sh_flags |= SHF_ALLOC;
76740- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
76741+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
76742 info->index.sym) | INIT_OFFSET_MASK;
76743 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
76744
76745@@ -2330,13 +2348,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76746 }
76747
76748 /* Append room for core symbols at end of core part. */
76749- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
76750- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
76751- mod->core_size += strtab_size;
76752+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
76753+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
76754+ mod->core_size_rx += strtab_size;
76755
76756 /* Put string table section at end of init part of module. */
76757 strsect->sh_flags |= SHF_ALLOC;
76758- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
76759+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
76760 info->index.str) | INIT_OFFSET_MASK;
76761 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
76762 }
76763@@ -2354,12 +2372,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76764 /* Make sure we get permanent strtab: don't use info->strtab. */
76765 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
76766
76767+ pax_open_kernel();
76768+
76769 /* Set types up while we still have access to sections. */
76770 for (i = 0; i < mod->num_symtab; i++)
76771 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
76772
76773- mod->core_symtab = dst = mod->module_core + info->symoffs;
76774- mod->core_strtab = s = mod->module_core + info->stroffs;
76775+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
76776+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
76777 src = mod->symtab;
76778 for (ndst = i = 0; i < mod->num_symtab; i++) {
76779 if (i == 0 ||
76780@@ -2371,6 +2391,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76781 }
76782 }
76783 mod->core_num_syms = ndst;
76784+
76785+ pax_close_kernel();
76786 }
76787 #else
76788 static inline void layout_symtab(struct module *mod, struct load_info *info)
76789@@ -2404,17 +2426,33 @@ void * __weak module_alloc(unsigned long size)
76790 return vmalloc_exec(size);
76791 }
76792
76793-static void *module_alloc_update_bounds(unsigned long size)
76794+static void *module_alloc_update_bounds_rw(unsigned long size)
76795 {
76796 void *ret = module_alloc(size);
76797
76798 if (ret) {
76799 mutex_lock(&module_mutex);
76800 /* Update module bounds. */
76801- if ((unsigned long)ret < module_addr_min)
76802- module_addr_min = (unsigned long)ret;
76803- if ((unsigned long)ret + size > module_addr_max)
76804- module_addr_max = (unsigned long)ret + size;
76805+ if ((unsigned long)ret < module_addr_min_rw)
76806+ module_addr_min_rw = (unsigned long)ret;
76807+ if ((unsigned long)ret + size > module_addr_max_rw)
76808+ module_addr_max_rw = (unsigned long)ret + size;
76809+ mutex_unlock(&module_mutex);
76810+ }
76811+ return ret;
76812+}
76813+
76814+static void *module_alloc_update_bounds_rx(unsigned long size)
76815+{
76816+ void *ret = module_alloc_exec(size);
76817+
76818+ if (ret) {
76819+ mutex_lock(&module_mutex);
76820+ /* Update module bounds. */
76821+ if ((unsigned long)ret < module_addr_min_rx)
76822+ module_addr_min_rx = (unsigned long)ret;
76823+ if ((unsigned long)ret + size > module_addr_max_rx)
76824+ module_addr_max_rx = (unsigned long)ret + size;
76825 mutex_unlock(&module_mutex);
76826 }
76827 return ret;
76828@@ -2690,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
76829 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76830 {
76831 const char *modmagic = get_modinfo(info, "vermagic");
76832+ const char *license = get_modinfo(info, "license");
76833 int err;
76834
76835+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
76836+ if (!license || !license_is_gpl_compatible(license))
76837+ return -ENOEXEC;
76838+#endif
76839+
76840 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
76841 modmagic = NULL;
76842
76843@@ -2717,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76844 }
76845
76846 /* Set up license info based on the info section */
76847- set_license(mod, get_modinfo(info, "license"));
76848+ set_license(mod, license);
76849
76850 return 0;
76851 }
76852@@ -2811,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
76853 void *ptr;
76854
76855 /* Do the allocs. */
76856- ptr = module_alloc_update_bounds(mod->core_size);
76857+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
76858 /*
76859 * The pointer to this block is stored in the module structure
76860 * which is inside the block. Just mark it as not being a
76861@@ -2821,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
76862 if (!ptr)
76863 return -ENOMEM;
76864
76865- memset(ptr, 0, mod->core_size);
76866- mod->module_core = ptr;
76867+ memset(ptr, 0, mod->core_size_rw);
76868+ mod->module_core_rw = ptr;
76869
76870- if (mod->init_size) {
76871- ptr = module_alloc_update_bounds(mod->init_size);
76872+ if (mod->init_size_rw) {
76873+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
76874 /*
76875 * The pointer to this block is stored in the module structure
76876 * which is inside the block. This block doesn't need to be
76877@@ -2834,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
76878 */
76879 kmemleak_ignore(ptr);
76880 if (!ptr) {
76881- module_free(mod, mod->module_core);
76882+ module_free(mod, mod->module_core_rw);
76883 return -ENOMEM;
76884 }
76885- memset(ptr, 0, mod->init_size);
76886- mod->module_init = ptr;
76887+ memset(ptr, 0, mod->init_size_rw);
76888+ mod->module_init_rw = ptr;
76889 } else
76890- mod->module_init = NULL;
76891+ mod->module_init_rw = NULL;
76892+
76893+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
76894+ kmemleak_not_leak(ptr);
76895+ if (!ptr) {
76896+ if (mod->module_init_rw)
76897+ module_free(mod, mod->module_init_rw);
76898+ module_free(mod, mod->module_core_rw);
76899+ return -ENOMEM;
76900+ }
76901+
76902+ pax_open_kernel();
76903+ memset(ptr, 0, mod->core_size_rx);
76904+ pax_close_kernel();
76905+ mod->module_core_rx = ptr;
76906+
76907+ if (mod->init_size_rx) {
76908+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
76909+ kmemleak_ignore(ptr);
76910+ if (!ptr && mod->init_size_rx) {
76911+ module_free_exec(mod, mod->module_core_rx);
76912+ if (mod->module_init_rw)
76913+ module_free(mod, mod->module_init_rw);
76914+ module_free(mod, mod->module_core_rw);
76915+ return -ENOMEM;
76916+ }
76917+
76918+ pax_open_kernel();
76919+ memset(ptr, 0, mod->init_size_rx);
76920+ pax_close_kernel();
76921+ mod->module_init_rx = ptr;
76922+ } else
76923+ mod->module_init_rx = NULL;
76924
76925 /* Transfer each section which specifies SHF_ALLOC */
76926 pr_debug("final section addresses:\n");
76927@@ -2851,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
76928 if (!(shdr->sh_flags & SHF_ALLOC))
76929 continue;
76930
76931- if (shdr->sh_entsize & INIT_OFFSET_MASK)
76932- dest = mod->module_init
76933- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76934- else
76935- dest = mod->module_core + shdr->sh_entsize;
76936+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
76937+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76938+ dest = mod->module_init_rw
76939+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76940+ else
76941+ dest = mod->module_init_rx
76942+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76943+ } else {
76944+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76945+ dest = mod->module_core_rw + shdr->sh_entsize;
76946+ else
76947+ dest = mod->module_core_rx + shdr->sh_entsize;
76948+ }
76949+
76950+ if (shdr->sh_type != SHT_NOBITS) {
76951+
76952+#ifdef CONFIG_PAX_KERNEXEC
76953+#ifdef CONFIG_X86_64
76954+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
76955+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
76956+#endif
76957+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
76958+ pax_open_kernel();
76959+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76960+ pax_close_kernel();
76961+ } else
76962+#endif
76963
76964- if (shdr->sh_type != SHT_NOBITS)
76965 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76966+ }
76967 /* Update sh_addr to point to copy in image. */
76968- shdr->sh_addr = (unsigned long)dest;
76969+
76970+#ifdef CONFIG_PAX_KERNEXEC
76971+ if (shdr->sh_flags & SHF_EXECINSTR)
76972+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
76973+ else
76974+#endif
76975+
76976+ shdr->sh_addr = (unsigned long)dest;
76977 pr_debug("\t0x%lx %s\n",
76978 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
76979 }
76980@@ -2917,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
76981 * Do it before processing of module parameters, so the module
76982 * can provide parameter accessor functions of its own.
76983 */
76984- if (mod->module_init)
76985- flush_icache_range((unsigned long)mod->module_init,
76986- (unsigned long)mod->module_init
76987- + mod->init_size);
76988- flush_icache_range((unsigned long)mod->module_core,
76989- (unsigned long)mod->module_core + mod->core_size);
76990+ if (mod->module_init_rx)
76991+ flush_icache_range((unsigned long)mod->module_init_rx,
76992+ (unsigned long)mod->module_init_rx
76993+ + mod->init_size_rx);
76994+ flush_icache_range((unsigned long)mod->module_core_rx,
76995+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
76996
76997 set_fs(old_fs);
76998 }
76999@@ -2992,8 +3097,10 @@ out:
77000 static void module_deallocate(struct module *mod, struct load_info *info)
77001 {
77002 percpu_modfree(mod);
77003- module_free(mod, mod->module_init);
77004- module_free(mod, mod->module_core);
77005+ module_free_exec(mod, mod->module_init_rx);
77006+ module_free_exec(mod, mod->module_core_rx);
77007+ module_free(mod, mod->module_init_rw);
77008+ module_free(mod, mod->module_core_rw);
77009 }
77010
77011 int __weak module_finalize(const Elf_Ehdr *hdr,
77012@@ -3006,7 +3113,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
77013 static int post_relocation(struct module *mod, const struct load_info *info)
77014 {
77015 /* Sort exception table now relocations are done. */
77016+ pax_open_kernel();
77017 sort_extable(mod->extable, mod->extable + mod->num_exentries);
77018+ pax_close_kernel();
77019
77020 /* Copy relocated percpu area over. */
77021 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
77022@@ -3060,16 +3169,16 @@ static int do_init_module(struct module *mod)
77023 MODULE_STATE_COMING, mod);
77024
77025 /* Set RO and NX regions for core */
77026- set_section_ro_nx(mod->module_core,
77027- mod->core_text_size,
77028- mod->core_ro_size,
77029- mod->core_size);
77030+ set_section_ro_nx(mod->module_core_rx,
77031+ mod->core_size_rx,
77032+ mod->core_size_rx,
77033+ mod->core_size_rx);
77034
77035 /* Set RO and NX regions for init */
77036- set_section_ro_nx(mod->module_init,
77037- mod->init_text_size,
77038- mod->init_ro_size,
77039- mod->init_size);
77040+ set_section_ro_nx(mod->module_init_rx,
77041+ mod->init_size_rx,
77042+ mod->init_size_rx,
77043+ mod->init_size_rx);
77044
77045 do_mod_ctors(mod);
77046 /* Start the module */
77047@@ -3131,11 +3240,12 @@ static int do_init_module(struct module *mod)
77048 mod->strtab = mod->core_strtab;
77049 #endif
77050 unset_module_init_ro_nx(mod);
77051- module_free(mod, mod->module_init);
77052- mod->module_init = NULL;
77053- mod->init_size = 0;
77054- mod->init_ro_size = 0;
77055- mod->init_text_size = 0;
77056+ module_free(mod, mod->module_init_rw);
77057+ module_free_exec(mod, mod->module_init_rx);
77058+ mod->module_init_rw = NULL;
77059+ mod->module_init_rx = NULL;
77060+ mod->init_size_rw = 0;
77061+ mod->init_size_rx = 0;
77062 mutex_unlock(&module_mutex);
77063 wake_up_all(&module_wq);
77064
77065@@ -3262,9 +3372,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
77066 if (err)
77067 goto free_unload;
77068
77069+ /* Now copy in args */
77070+ mod->args = strndup_user(uargs, ~0UL >> 1);
77071+ if (IS_ERR(mod->args)) {
77072+ err = PTR_ERR(mod->args);
77073+ goto free_unload;
77074+ }
77075+
77076 /* Set up MODINFO_ATTR fields */
77077 setup_modinfo(mod, info);
77078
77079+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77080+ {
77081+ char *p, *p2;
77082+
77083+ if (strstr(mod->args, "grsec_modharden_netdev")) {
77084+ 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);
77085+ err = -EPERM;
77086+ goto free_modinfo;
77087+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
77088+ p += sizeof("grsec_modharden_normal") - 1;
77089+ p2 = strstr(p, "_");
77090+ if (p2) {
77091+ *p2 = '\0';
77092+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
77093+ *p2 = '_';
77094+ }
77095+ err = -EPERM;
77096+ goto free_modinfo;
77097+ }
77098+ }
77099+#endif
77100+
77101 /* Fix up syms, so that st_value is a pointer to location. */
77102 err = simplify_symbols(mod, info);
77103 if (err < 0)
77104@@ -3280,13 +3419,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
77105
77106 flush_module_icache(mod);
77107
77108- /* Now copy in args */
77109- mod->args = strndup_user(uargs, ~0UL >> 1);
77110- if (IS_ERR(mod->args)) {
77111- err = PTR_ERR(mod->args);
77112- goto free_arch_cleanup;
77113- }
77114-
77115 dynamic_debug_setup(info->debug, info->num_debug);
77116
77117 /* Finally it's fully formed, ready to start executing. */
77118@@ -3321,11 +3453,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
77119 ddebug_cleanup:
77120 dynamic_debug_remove(info->debug);
77121 synchronize_sched();
77122- kfree(mod->args);
77123- free_arch_cleanup:
77124 module_arch_cleanup(mod);
77125 free_modinfo:
77126 free_modinfo(mod);
77127+ kfree(mod->args);
77128 free_unload:
77129 module_unload_free(mod);
77130 unlink_mod:
77131@@ -3408,10 +3539,16 @@ static const char *get_ksymbol(struct module *mod,
77132 unsigned long nextval;
77133
77134 /* At worse, next value is at end of module */
77135- if (within_module_init(addr, mod))
77136- nextval = (unsigned long)mod->module_init+mod->init_text_size;
77137+ if (within_module_init_rx(addr, mod))
77138+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
77139+ else if (within_module_init_rw(addr, mod))
77140+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
77141+ else if (within_module_core_rx(addr, mod))
77142+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
77143+ else if (within_module_core_rw(addr, mod))
77144+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
77145 else
77146- nextval = (unsigned long)mod->module_core+mod->core_text_size;
77147+ return NULL;
77148
77149 /* Scan for closest preceding symbol, and next symbol. (ELF
77150 starts real symbols at 1). */
77151@@ -3664,7 +3801,7 @@ static int m_show(struct seq_file *m, void *p)
77152 return 0;
77153
77154 seq_printf(m, "%s %u",
77155- mod->name, mod->init_size + mod->core_size);
77156+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
77157 print_unload_info(m, mod);
77158
77159 /* Informative for users. */
77160@@ -3673,7 +3810,7 @@ static int m_show(struct seq_file *m, void *p)
77161 mod->state == MODULE_STATE_COMING ? "Loading":
77162 "Live");
77163 /* Used by oprofile and other similar tools. */
77164- seq_printf(m, " 0x%pK", mod->module_core);
77165+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
77166
77167 /* Taints info */
77168 if (mod->taints)
77169@@ -3709,7 +3846,17 @@ static const struct file_operations proc_modules_operations = {
77170
77171 static int __init proc_modules_init(void)
77172 {
77173+#ifndef CONFIG_GRKERNSEC_HIDESYM
77174+#ifdef CONFIG_GRKERNSEC_PROC_USER
77175+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
77176+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77177+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
77178+#else
77179 proc_create("modules", 0, NULL, &proc_modules_operations);
77180+#endif
77181+#else
77182+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
77183+#endif
77184 return 0;
77185 }
77186 module_init(proc_modules_init);
77187@@ -3770,14 +3917,14 @@ struct module *__module_address(unsigned long addr)
77188 {
77189 struct module *mod;
77190
77191- if (addr < module_addr_min || addr > module_addr_max)
77192+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
77193+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
77194 return NULL;
77195
77196 list_for_each_entry_rcu(mod, &modules, list) {
77197 if (mod->state == MODULE_STATE_UNFORMED)
77198 continue;
77199- if (within_module_core(addr, mod)
77200- || within_module_init(addr, mod))
77201+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
77202 return mod;
77203 }
77204 return NULL;
77205@@ -3812,11 +3959,20 @@ bool is_module_text_address(unsigned long addr)
77206 */
77207 struct module *__module_text_address(unsigned long addr)
77208 {
77209- struct module *mod = __module_address(addr);
77210+ struct module *mod;
77211+
77212+#ifdef CONFIG_X86_32
77213+ addr = ktla_ktva(addr);
77214+#endif
77215+
77216+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
77217+ return NULL;
77218+
77219+ mod = __module_address(addr);
77220+
77221 if (mod) {
77222 /* Make sure it's within the text section. */
77223- if (!within(addr, mod->module_init, mod->init_text_size)
77224- && !within(addr, mod->module_core, mod->core_text_size))
77225+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
77226 mod = NULL;
77227 }
77228 return mod;
77229diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
77230index 7e3443f..b2a1e6b 100644
77231--- a/kernel/mutex-debug.c
77232+++ b/kernel/mutex-debug.c
77233@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
77234 }
77235
77236 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77237- struct thread_info *ti)
77238+ struct task_struct *task)
77239 {
77240 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
77241
77242 /* Mark the current thread as blocked on the lock: */
77243- ti->task->blocked_on = waiter;
77244+ task->blocked_on = waiter;
77245 }
77246
77247 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77248- struct thread_info *ti)
77249+ struct task_struct *task)
77250 {
77251 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
77252- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
77253- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
77254- ti->task->blocked_on = NULL;
77255+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
77256+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
77257+ task->blocked_on = NULL;
77258
77259 list_del_init(&waiter->list);
77260 waiter->task = NULL;
77261diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
77262index 0799fd3..d06ae3b 100644
77263--- a/kernel/mutex-debug.h
77264+++ b/kernel/mutex-debug.h
77265@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
77266 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
77267 extern void debug_mutex_add_waiter(struct mutex *lock,
77268 struct mutex_waiter *waiter,
77269- struct thread_info *ti);
77270+ struct task_struct *task);
77271 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77272- struct thread_info *ti);
77273+ struct task_struct *task);
77274 extern void debug_mutex_unlock(struct mutex *lock);
77275 extern void debug_mutex_init(struct mutex *lock, const char *name,
77276 struct lock_class_key *key);
77277diff --git a/kernel/mutex.c b/kernel/mutex.c
77278index 52f2301..73f7528 100644
77279--- a/kernel/mutex.c
77280+++ b/kernel/mutex.c
77281@@ -199,7 +199,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77282 spin_lock_mutex(&lock->wait_lock, flags);
77283
77284 debug_mutex_lock_common(lock, &waiter);
77285- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
77286+ debug_mutex_add_waiter(lock, &waiter, task);
77287
77288 /* add waiting tasks to the end of the waitqueue (FIFO): */
77289 list_add_tail(&waiter.list, &lock->wait_list);
77290@@ -228,8 +228,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77291 * TASK_UNINTERRUPTIBLE case.)
77292 */
77293 if (unlikely(signal_pending_state(state, task))) {
77294- mutex_remove_waiter(lock, &waiter,
77295- task_thread_info(task));
77296+ mutex_remove_waiter(lock, &waiter, task);
77297 mutex_release(&lock->dep_map, 1, ip);
77298 spin_unlock_mutex(&lock->wait_lock, flags);
77299
77300@@ -248,7 +247,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77301 done:
77302 lock_acquired(&lock->dep_map, ip);
77303 /* got the lock - rejoice! */
77304- mutex_remove_waiter(lock, &waiter, current_thread_info());
77305+ mutex_remove_waiter(lock, &waiter, task);
77306 mutex_set_owner(lock);
77307
77308 /* set it to 0 if there are no waiters left: */
77309diff --git a/kernel/notifier.c b/kernel/notifier.c
77310index 2d5cc4c..d9ea600 100644
77311--- a/kernel/notifier.c
77312+++ b/kernel/notifier.c
77313@@ -5,6 +5,7 @@
77314 #include <linux/rcupdate.h>
77315 #include <linux/vmalloc.h>
77316 #include <linux/reboot.h>
77317+#include <linux/mm.h>
77318
77319 /*
77320 * Notifier list for kernel code which wants to be called
77321@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
77322 while ((*nl) != NULL) {
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@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
77337 return 0;
77338 if (n->priority > (*nl)->priority)
77339 break;
77340- nl = &((*nl)->next);
77341+ nl = (struct notifier_block **)&((*nl)->next);
77342 }
77343- n->next = *nl;
77344+ pax_open_kernel();
77345+ *(const void **)&n->next = *nl;
77346 rcu_assign_pointer(*nl, n);
77347+ pax_close_kernel();
77348 return 0;
77349 }
77350
77351@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
77352 {
77353 while ((*nl) != NULL) {
77354 if ((*nl) == n) {
77355+ pax_open_kernel();
77356 rcu_assign_pointer(*nl, n->next);
77357+ pax_close_kernel();
77358 return 0;
77359 }
77360- nl = &((*nl)->next);
77361+ nl = (struct notifier_block **)&((*nl)->next);
77362 }
77363 return -ENOENT;
77364 }
77365diff --git a/kernel/panic.c b/kernel/panic.c
77366index 7c57cc9..28f1b3f 100644
77367--- a/kernel/panic.c
77368+++ b/kernel/panic.c
77369@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
77370 const char *board;
77371
77372 printk(KERN_WARNING "------------[ cut here ]------------\n");
77373- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
77374+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
77375 board = dmi_get_system_info(DMI_PRODUCT_NAME);
77376 if (board)
77377 printk(KERN_WARNING "Hardware name: %s\n", board);
77378@@ -459,7 +459,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
77379 */
77380 void __stack_chk_fail(void)
77381 {
77382- panic("stack-protector: Kernel stack is corrupted in: %p\n",
77383+ dump_stack();
77384+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
77385 __builtin_return_address(0));
77386 }
77387 EXPORT_SYMBOL(__stack_chk_fail);
77388diff --git a/kernel/pid.c b/kernel/pid.c
77389index 047dc62..418d74b 100644
77390--- a/kernel/pid.c
77391+++ b/kernel/pid.c
77392@@ -33,6 +33,7 @@
77393 #include <linux/rculist.h>
77394 #include <linux/bootmem.h>
77395 #include <linux/hash.h>
77396+#include <linux/security.h>
77397 #include <linux/pid_namespace.h>
77398 #include <linux/init_task.h>
77399 #include <linux/syscalls.h>
77400@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
77401
77402 int pid_max = PID_MAX_DEFAULT;
77403
77404-#define RESERVED_PIDS 300
77405+#define RESERVED_PIDS 500
77406
77407 int pid_max_min = RESERVED_PIDS + 1;
77408 int pid_max_max = PID_MAX_LIMIT;
77409@@ -440,10 +441,18 @@ EXPORT_SYMBOL(pid_task);
77410 */
77411 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
77412 {
77413+ struct task_struct *task;
77414+
77415 rcu_lockdep_assert(rcu_read_lock_held(),
77416 "find_task_by_pid_ns() needs rcu_read_lock()"
77417 " protection");
77418- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77419+
77420+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77421+
77422+ if (gr_pid_is_chrooted(task))
77423+ return NULL;
77424+
77425+ return task;
77426 }
77427
77428 struct task_struct *find_task_by_vpid(pid_t vnr)
77429@@ -451,6 +460,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
77430 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
77431 }
77432
77433+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
77434+{
77435+ rcu_lockdep_assert(rcu_read_lock_held(),
77436+ "find_task_by_pid_ns() needs rcu_read_lock()"
77437+ " protection");
77438+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
77439+}
77440+
77441 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
77442 {
77443 struct pid *pid;
77444diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
77445index bea15bd..789f3d0 100644
77446--- a/kernel/pid_namespace.c
77447+++ b/kernel/pid_namespace.c
77448@@ -249,7 +249,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
77449 void __user *buffer, size_t *lenp, loff_t *ppos)
77450 {
77451 struct pid_namespace *pid_ns = task_active_pid_ns(current);
77452- struct ctl_table tmp = *table;
77453+ ctl_table_no_const tmp = *table;
77454
77455 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
77456 return -EPERM;
77457diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
77458index 8fd709c..542bf4b 100644
77459--- a/kernel/posix-cpu-timers.c
77460+++ b/kernel/posix-cpu-timers.c
77461@@ -1592,14 +1592,14 @@ struct k_clock clock_posix_cpu = {
77462
77463 static __init int init_posix_cpu_timers(void)
77464 {
77465- struct k_clock process = {
77466+ static struct k_clock process = {
77467 .clock_getres = process_cpu_clock_getres,
77468 .clock_get = process_cpu_clock_get,
77469 .timer_create = process_cpu_timer_create,
77470 .nsleep = process_cpu_nsleep,
77471 .nsleep_restart = process_cpu_nsleep_restart,
77472 };
77473- struct k_clock thread = {
77474+ static struct k_clock thread = {
77475 .clock_getres = thread_cpu_clock_getres,
77476 .clock_get = thread_cpu_clock_get,
77477 .timer_create = thread_cpu_timer_create,
77478diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
77479index 6edbb2c..334f085 100644
77480--- a/kernel/posix-timers.c
77481+++ b/kernel/posix-timers.c
77482@@ -43,6 +43,7 @@
77483 #include <linux/idr.h>
77484 #include <linux/posix-clock.h>
77485 #include <linux/posix-timers.h>
77486+#include <linux/grsecurity.h>
77487 #include <linux/syscalls.h>
77488 #include <linux/wait.h>
77489 #include <linux/workqueue.h>
77490@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
77491 * which we beg off on and pass to do_sys_settimeofday().
77492 */
77493
77494-static struct k_clock posix_clocks[MAX_CLOCKS];
77495+static struct k_clock *posix_clocks[MAX_CLOCKS];
77496
77497 /*
77498 * These ones are defined below.
77499@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
77500 */
77501 static __init int init_posix_timers(void)
77502 {
77503- struct k_clock clock_realtime = {
77504+ static struct k_clock clock_realtime = {
77505 .clock_getres = hrtimer_get_res,
77506 .clock_get = posix_clock_realtime_get,
77507 .clock_set = posix_clock_realtime_set,
77508@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
77509 .timer_get = common_timer_get,
77510 .timer_del = common_timer_del,
77511 };
77512- struct k_clock clock_monotonic = {
77513+ static struct k_clock clock_monotonic = {
77514 .clock_getres = hrtimer_get_res,
77515 .clock_get = posix_ktime_get_ts,
77516 .nsleep = common_nsleep,
77517@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
77518 .timer_get = common_timer_get,
77519 .timer_del = common_timer_del,
77520 };
77521- struct k_clock clock_monotonic_raw = {
77522+ static struct k_clock clock_monotonic_raw = {
77523 .clock_getres = hrtimer_get_res,
77524 .clock_get = posix_get_monotonic_raw,
77525 };
77526- struct k_clock clock_realtime_coarse = {
77527+ static struct k_clock clock_realtime_coarse = {
77528 .clock_getres = posix_get_coarse_res,
77529 .clock_get = posix_get_realtime_coarse,
77530 };
77531- struct k_clock clock_monotonic_coarse = {
77532+ static struct k_clock clock_monotonic_coarse = {
77533 .clock_getres = posix_get_coarse_res,
77534 .clock_get = posix_get_monotonic_coarse,
77535 };
77536- struct k_clock clock_boottime = {
77537+ static struct k_clock clock_boottime = {
77538 .clock_getres = hrtimer_get_res,
77539 .clock_get = posix_get_boottime,
77540 .nsleep = common_nsleep,
77541@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
77542 return;
77543 }
77544
77545- posix_clocks[clock_id] = *new_clock;
77546+ posix_clocks[clock_id] = new_clock;
77547 }
77548 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
77549
77550@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
77551 return (id & CLOCKFD_MASK) == CLOCKFD ?
77552 &clock_posix_dynamic : &clock_posix_cpu;
77553
77554- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
77555+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
77556 return NULL;
77557- return &posix_clocks[id];
77558+ return posix_clocks[id];
77559 }
77560
77561 static int common_timer_create(struct k_itimer *new_timer)
77562@@ -964,6 +965,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
77563 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
77564 return -EFAULT;
77565
77566+ /* only the CLOCK_REALTIME clock can be set, all other clocks
77567+ have their clock_set fptr set to a nosettime dummy function
77568+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
77569+ call common_clock_set, which calls do_sys_settimeofday, which
77570+ we hook
77571+ */
77572+
77573 return kc->clock_set(which_clock, &new_tp);
77574 }
77575
77576diff --git a/kernel/power/process.c b/kernel/power/process.c
77577index 98088e0..aaf95c0 100644
77578--- a/kernel/power/process.c
77579+++ b/kernel/power/process.c
77580@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
77581 u64 elapsed_csecs64;
77582 unsigned int elapsed_csecs;
77583 bool wakeup = false;
77584+ bool timedout = false;
77585
77586 do_gettimeofday(&start);
77587
77588@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
77589
77590 while (true) {
77591 todo = 0;
77592+ if (time_after(jiffies, end_time))
77593+ timedout = true;
77594 read_lock(&tasklist_lock);
77595 do_each_thread(g, p) {
77596 if (p == current || !freeze_task(p))
77597 continue;
77598
77599- if (!freezer_should_skip(p))
77600+ if (!freezer_should_skip(p)) {
77601 todo++;
77602+ if (timedout) {
77603+ printk(KERN_ERR "Task refusing to freeze:\n");
77604+ sched_show_task(p);
77605+ }
77606+ }
77607 } while_each_thread(g, p);
77608 read_unlock(&tasklist_lock);
77609
77610@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
77611 todo += wq_busy;
77612 }
77613
77614- if (!todo || time_after(jiffies, end_time))
77615+ if (!todo || timedout)
77616 break;
77617
77618 if (pm_wakeup_pending()) {
77619diff --git a/kernel/printk.c b/kernel/printk.c
77620index 0e4eba6a..d58ebf0 100644
77621--- a/kernel/printk.c
77622+++ b/kernel/printk.c
77623@@ -395,6 +395,11 @@ static int check_syslog_permissions(int type, bool from_file)
77624 if (from_file && type != SYSLOG_ACTION_OPEN)
77625 return 0;
77626
77627+#ifdef CONFIG_GRKERNSEC_DMESG
77628+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
77629+ return -EPERM;
77630+#endif
77631+
77632 if (syslog_action_restricted(type)) {
77633 if (capable(CAP_SYSLOG))
77634 return 0;
77635diff --git a/kernel/profile.c b/kernel/profile.c
77636index dc3384e..0de5b49 100644
77637--- a/kernel/profile.c
77638+++ b/kernel/profile.c
77639@@ -37,7 +37,7 @@ struct profile_hit {
77640 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
77641 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
77642
77643-static atomic_t *prof_buffer;
77644+static atomic_unchecked_t *prof_buffer;
77645 static unsigned long prof_len, prof_shift;
77646
77647 int prof_on __read_mostly;
77648@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
77649 hits[i].pc = 0;
77650 continue;
77651 }
77652- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77653+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77654 hits[i].hits = hits[i].pc = 0;
77655 }
77656 }
77657@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77658 * Add the current hit(s) and flush the write-queue out
77659 * to the global buffer:
77660 */
77661- atomic_add(nr_hits, &prof_buffer[pc]);
77662+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
77663 for (i = 0; i < NR_PROFILE_HIT; ++i) {
77664- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77665+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77666 hits[i].pc = hits[i].hits = 0;
77667 }
77668 out:
77669@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77670 {
77671 unsigned long pc;
77672 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
77673- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77674+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77675 }
77676 #endif /* !CONFIG_SMP */
77677
77678@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
77679 return -EFAULT;
77680 buf++; p++; count--; read++;
77681 }
77682- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
77683+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
77684 if (copy_to_user(buf, (void *)pnt, count))
77685 return -EFAULT;
77686 read += count;
77687@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
77688 }
77689 #endif
77690 profile_discard_flip_buffers();
77691- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
77692+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
77693 return count;
77694 }
77695
77696diff --git a/kernel/ptrace.c b/kernel/ptrace.c
77697index acbd284..00bb0c9 100644
77698--- a/kernel/ptrace.c
77699+++ b/kernel/ptrace.c
77700@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
77701 if (seize)
77702 flags |= PT_SEIZED;
77703 rcu_read_lock();
77704- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77705+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77706 flags |= PT_PTRACE_CAP;
77707 rcu_read_unlock();
77708 task->ptrace = flags;
77709@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
77710 break;
77711 return -EIO;
77712 }
77713- if (copy_to_user(dst, buf, retval))
77714+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
77715 return -EFAULT;
77716 copied += retval;
77717 src += retval;
77718@@ -726,7 +726,7 @@ int ptrace_request(struct task_struct *child, long request,
77719 bool seized = child->ptrace & PT_SEIZED;
77720 int ret = -EIO;
77721 siginfo_t siginfo, *si;
77722- void __user *datavp = (void __user *) data;
77723+ void __user *datavp = (__force void __user *) data;
77724 unsigned long __user *datalp = datavp;
77725 unsigned long flags;
77726
77727@@ -928,14 +928,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
77728 goto out;
77729 }
77730
77731+ if (gr_handle_ptrace(child, request)) {
77732+ ret = -EPERM;
77733+ goto out_put_task_struct;
77734+ }
77735+
77736 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77737 ret = ptrace_attach(child, request, addr, data);
77738 /*
77739 * Some architectures need to do book-keeping after
77740 * a ptrace attach.
77741 */
77742- if (!ret)
77743+ if (!ret) {
77744 arch_ptrace_attach(child);
77745+ gr_audit_ptrace(child);
77746+ }
77747 goto out_put_task_struct;
77748 }
77749
77750@@ -963,7 +970,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
77751 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
77752 if (copied != sizeof(tmp))
77753 return -EIO;
77754- return put_user(tmp, (unsigned long __user *)data);
77755+ return put_user(tmp, (__force unsigned long __user *)data);
77756 }
77757
77758 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
77759@@ -1057,7 +1064,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
77760 }
77761
77762 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77763- compat_long_t addr, compat_long_t data)
77764+ compat_ulong_t addr, compat_ulong_t data)
77765 {
77766 struct task_struct *child;
77767 long ret;
77768@@ -1073,14 +1080,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77769 goto out;
77770 }
77771
77772+ if (gr_handle_ptrace(child, request)) {
77773+ ret = -EPERM;
77774+ goto out_put_task_struct;
77775+ }
77776+
77777 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77778 ret = ptrace_attach(child, request, addr, data);
77779 /*
77780 * Some architectures need to do book-keeping after
77781 * a ptrace attach.
77782 */
77783- if (!ret)
77784+ if (!ret) {
77785 arch_ptrace_attach(child);
77786+ gr_audit_ptrace(child);
77787+ }
77788 goto out_put_task_struct;
77789 }
77790
77791diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
77792index 48ab703..07561d4 100644
77793--- a/kernel/rcupdate.c
77794+++ b/kernel/rcupdate.c
77795@@ -439,10 +439,10 @@ int rcu_jiffies_till_stall_check(void)
77796 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
77797 */
77798 if (till_stall_check < 3) {
77799- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
77800+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
77801 till_stall_check = 3;
77802 } else if (till_stall_check > 300) {
77803- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
77804+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
77805 till_stall_check = 300;
77806 }
77807 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
77808diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
77809index a0714a5..2ab5e34 100644
77810--- a/kernel/rcutiny.c
77811+++ b/kernel/rcutiny.c
77812@@ -46,7 +46,7 @@
77813 struct rcu_ctrlblk;
77814 static void invoke_rcu_callbacks(void);
77815 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
77816-static void rcu_process_callbacks(struct softirq_action *unused);
77817+static void rcu_process_callbacks(void);
77818 static void __call_rcu(struct rcu_head *head,
77819 void (*func)(struct rcu_head *rcu),
77820 struct rcu_ctrlblk *rcp);
77821@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
77822 rcu_is_callbacks_kthread()));
77823 }
77824
77825-static void rcu_process_callbacks(struct softirq_action *unused)
77826+static void rcu_process_callbacks(void)
77827 {
77828 __rcu_process_callbacks(&rcu_sched_ctrlblk);
77829 __rcu_process_callbacks(&rcu_bh_ctrlblk);
77830diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
77831index 8a23300..4255818 100644
77832--- a/kernel/rcutiny_plugin.h
77833+++ b/kernel/rcutiny_plugin.h
77834@@ -945,7 +945,7 @@ static int rcu_kthread(void *arg)
77835 have_rcu_kthread_work = morework;
77836 local_irq_restore(flags);
77837 if (work)
77838- rcu_process_callbacks(NULL);
77839+ rcu_process_callbacks();
77840 schedule_timeout_interruptible(1); /* Leave CPU for others. */
77841 }
77842
77843diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
77844index e1f3a8c..42c94a2 100644
77845--- a/kernel/rcutorture.c
77846+++ b/kernel/rcutorture.c
77847@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
77848 { 0 };
77849 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
77850 { 0 };
77851-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77852-static atomic_t n_rcu_torture_alloc;
77853-static atomic_t n_rcu_torture_alloc_fail;
77854-static atomic_t n_rcu_torture_free;
77855-static atomic_t n_rcu_torture_mberror;
77856-static atomic_t n_rcu_torture_error;
77857+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77858+static atomic_unchecked_t n_rcu_torture_alloc;
77859+static atomic_unchecked_t n_rcu_torture_alloc_fail;
77860+static atomic_unchecked_t n_rcu_torture_free;
77861+static atomic_unchecked_t n_rcu_torture_mberror;
77862+static atomic_unchecked_t n_rcu_torture_error;
77863 static long n_rcu_torture_barrier_error;
77864 static long n_rcu_torture_boost_ktrerror;
77865 static long n_rcu_torture_boost_rterror;
77866@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
77867
77868 spin_lock_bh(&rcu_torture_lock);
77869 if (list_empty(&rcu_torture_freelist)) {
77870- atomic_inc(&n_rcu_torture_alloc_fail);
77871+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
77872 spin_unlock_bh(&rcu_torture_lock);
77873 return NULL;
77874 }
77875- atomic_inc(&n_rcu_torture_alloc);
77876+ atomic_inc_unchecked(&n_rcu_torture_alloc);
77877 p = rcu_torture_freelist.next;
77878 list_del_init(p);
77879 spin_unlock_bh(&rcu_torture_lock);
77880@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
77881 static void
77882 rcu_torture_free(struct rcu_torture *p)
77883 {
77884- atomic_inc(&n_rcu_torture_free);
77885+ atomic_inc_unchecked(&n_rcu_torture_free);
77886 spin_lock_bh(&rcu_torture_lock);
77887 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
77888 spin_unlock_bh(&rcu_torture_lock);
77889@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
77890 i = rp->rtort_pipe_count;
77891 if (i > RCU_TORTURE_PIPE_LEN)
77892 i = RCU_TORTURE_PIPE_LEN;
77893- atomic_inc(&rcu_torture_wcount[i]);
77894+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77895 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77896 rp->rtort_mbtest = 0;
77897 rcu_torture_free(rp);
77898@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
77899 i = rp->rtort_pipe_count;
77900 if (i > RCU_TORTURE_PIPE_LEN)
77901 i = RCU_TORTURE_PIPE_LEN;
77902- atomic_inc(&rcu_torture_wcount[i]);
77903+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77904 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77905 rp->rtort_mbtest = 0;
77906 list_del(&rp->rtort_free);
77907@@ -990,7 +990,7 @@ rcu_torture_writer(void *arg)
77908 i = old_rp->rtort_pipe_count;
77909 if (i > RCU_TORTURE_PIPE_LEN)
77910 i = RCU_TORTURE_PIPE_LEN;
77911- atomic_inc(&rcu_torture_wcount[i]);
77912+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77913 old_rp->rtort_pipe_count++;
77914 cur_ops->deferred_free(old_rp);
77915 }
77916@@ -1076,7 +1076,7 @@ static void rcu_torture_timer(unsigned long unused)
77917 return;
77918 }
77919 if (p->rtort_mbtest == 0)
77920- atomic_inc(&n_rcu_torture_mberror);
77921+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77922 spin_lock(&rand_lock);
77923 cur_ops->read_delay(&rand);
77924 n_rcu_torture_timers++;
77925@@ -1146,7 +1146,7 @@ rcu_torture_reader(void *arg)
77926 continue;
77927 }
77928 if (p->rtort_mbtest == 0)
77929- atomic_inc(&n_rcu_torture_mberror);
77930+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77931 cur_ops->read_delay(&rand);
77932 preempt_disable();
77933 pipe_count = p->rtort_pipe_count;
77934@@ -1209,11 +1209,11 @@ rcu_torture_printk(char *page)
77935 rcu_torture_current,
77936 rcu_torture_current_version,
77937 list_empty(&rcu_torture_freelist),
77938- atomic_read(&n_rcu_torture_alloc),
77939- atomic_read(&n_rcu_torture_alloc_fail),
77940- atomic_read(&n_rcu_torture_free));
77941+ atomic_read_unchecked(&n_rcu_torture_alloc),
77942+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
77943+ atomic_read_unchecked(&n_rcu_torture_free));
77944 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
77945- atomic_read(&n_rcu_torture_mberror),
77946+ atomic_read_unchecked(&n_rcu_torture_mberror),
77947 n_rcu_torture_boost_ktrerror,
77948 n_rcu_torture_boost_rterror);
77949 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
77950@@ -1232,14 +1232,14 @@ rcu_torture_printk(char *page)
77951 n_barrier_attempts,
77952 n_rcu_torture_barrier_error);
77953 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
77954- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
77955+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
77956 n_rcu_torture_barrier_error != 0 ||
77957 n_rcu_torture_boost_ktrerror != 0 ||
77958 n_rcu_torture_boost_rterror != 0 ||
77959 n_rcu_torture_boost_failure != 0 ||
77960 i > 1) {
77961 cnt += sprintf(&page[cnt], "!!! ");
77962- atomic_inc(&n_rcu_torture_error);
77963+ atomic_inc_unchecked(&n_rcu_torture_error);
77964 WARN_ON_ONCE(1);
77965 }
77966 cnt += sprintf(&page[cnt], "Reader Pipe: ");
77967@@ -1253,7 +1253,7 @@ rcu_torture_printk(char *page)
77968 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
77969 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77970 cnt += sprintf(&page[cnt], " %d",
77971- atomic_read(&rcu_torture_wcount[i]));
77972+ atomic_read_unchecked(&rcu_torture_wcount[i]));
77973 }
77974 cnt += sprintf(&page[cnt], "\n");
77975 if (cur_ops->stats)
77976@@ -1962,7 +1962,7 @@ rcu_torture_cleanup(void)
77977
77978 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
77979
77980- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77981+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77982 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
77983 else if (n_online_successes != n_online_attempts ||
77984 n_offline_successes != n_offline_attempts)
77985@@ -2031,18 +2031,18 @@ rcu_torture_init(void)
77986
77987 rcu_torture_current = NULL;
77988 rcu_torture_current_version = 0;
77989- atomic_set(&n_rcu_torture_alloc, 0);
77990- atomic_set(&n_rcu_torture_alloc_fail, 0);
77991- atomic_set(&n_rcu_torture_free, 0);
77992- atomic_set(&n_rcu_torture_mberror, 0);
77993- atomic_set(&n_rcu_torture_error, 0);
77994+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
77995+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
77996+ atomic_set_unchecked(&n_rcu_torture_free, 0);
77997+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
77998+ atomic_set_unchecked(&n_rcu_torture_error, 0);
77999 n_rcu_torture_barrier_error = 0;
78000 n_rcu_torture_boost_ktrerror = 0;
78001 n_rcu_torture_boost_rterror = 0;
78002 n_rcu_torture_boost_failure = 0;
78003 n_rcu_torture_boosts = 0;
78004 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
78005- atomic_set(&rcu_torture_wcount[i], 0);
78006+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
78007 for_each_possible_cpu(cpu) {
78008 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
78009 per_cpu(rcu_torture_count, cpu)[i] = 0;
78010diff --git a/kernel/rcutree.c b/kernel/rcutree.c
78011index 5b8ad82..59e1f64 100644
78012--- a/kernel/rcutree.c
78013+++ b/kernel/rcutree.c
78014@@ -353,9 +353,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
78015 rcu_prepare_for_idle(smp_processor_id());
78016 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78017 smp_mb__before_atomic_inc(); /* See above. */
78018- atomic_inc(&rdtp->dynticks);
78019+ atomic_inc_unchecked(&rdtp->dynticks);
78020 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
78021- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78022+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78023
78024 /*
78025 * It is illegal to enter an extended quiescent state while
78026@@ -491,10 +491,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
78027 int user)
78028 {
78029 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
78030- atomic_inc(&rdtp->dynticks);
78031+ atomic_inc_unchecked(&rdtp->dynticks);
78032 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78033 smp_mb__after_atomic_inc(); /* See above. */
78034- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78035+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78036 rcu_cleanup_after_idle(smp_processor_id());
78037 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
78038 if (!user && !is_idle_task(current)) {
78039@@ -633,14 +633,14 @@ void rcu_nmi_enter(void)
78040 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
78041
78042 if (rdtp->dynticks_nmi_nesting == 0 &&
78043- (atomic_read(&rdtp->dynticks) & 0x1))
78044+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
78045 return;
78046 rdtp->dynticks_nmi_nesting++;
78047 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
78048- atomic_inc(&rdtp->dynticks);
78049+ atomic_inc_unchecked(&rdtp->dynticks);
78050 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78051 smp_mb__after_atomic_inc(); /* See above. */
78052- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78053+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78054 }
78055
78056 /**
78057@@ -659,9 +659,9 @@ void rcu_nmi_exit(void)
78058 return;
78059 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78060 smp_mb__before_atomic_inc(); /* See above. */
78061- atomic_inc(&rdtp->dynticks);
78062+ atomic_inc_unchecked(&rdtp->dynticks);
78063 smp_mb__after_atomic_inc(); /* Force delay to next write. */
78064- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78065+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78066 }
78067
78068 /**
78069@@ -675,7 +675,7 @@ int rcu_is_cpu_idle(void)
78070 int ret;
78071
78072 preempt_disable();
78073- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78074+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78075 preempt_enable();
78076 return ret;
78077 }
78078@@ -743,7 +743,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
78079 */
78080 static int dyntick_save_progress_counter(struct rcu_data *rdp)
78081 {
78082- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
78083+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78084 return (rdp->dynticks_snap & 0x1) == 0;
78085 }
78086
78087@@ -758,7 +758,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
78088 unsigned int curr;
78089 unsigned int snap;
78090
78091- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
78092+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78093 snap = (unsigned int)rdp->dynticks_snap;
78094
78095 /*
78096@@ -1698,7 +1698,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
78097 rsp->qlen += rdp->qlen;
78098 rdp->n_cbs_orphaned += rdp->qlen;
78099 rdp->qlen_lazy = 0;
78100- ACCESS_ONCE(rdp->qlen) = 0;
78101+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78102 }
78103
78104 /*
78105@@ -1944,7 +1944,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
78106 }
78107 smp_mb(); /* List handling before counting for rcu_barrier(). */
78108 rdp->qlen_lazy -= count_lazy;
78109- ACCESS_ONCE(rdp->qlen) -= count;
78110+ ACCESS_ONCE_RW(rdp->qlen) -= count;
78111 rdp->n_cbs_invoked += count;
78112
78113 /* Reinstate batch limit if we have worked down the excess. */
78114@@ -2137,7 +2137,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
78115 /*
78116 * Do RCU core processing for the current CPU.
78117 */
78118-static void rcu_process_callbacks(struct softirq_action *unused)
78119+static void rcu_process_callbacks(void)
78120 {
78121 struct rcu_state *rsp;
78122
78123@@ -2260,7 +2260,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
78124 local_irq_restore(flags);
78125 return;
78126 }
78127- ACCESS_ONCE(rdp->qlen)++;
78128+ ACCESS_ONCE_RW(rdp->qlen)++;
78129 if (lazy)
78130 rdp->qlen_lazy++;
78131 else
78132@@ -2469,11 +2469,11 @@ void synchronize_sched_expedited(void)
78133 * counter wrap on a 32-bit system. Quite a few more CPUs would of
78134 * course be required on a 64-bit system.
78135 */
78136- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
78137+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
78138 (ulong)atomic_long_read(&rsp->expedited_done) +
78139 ULONG_MAX / 8)) {
78140 synchronize_sched();
78141- atomic_long_inc(&rsp->expedited_wrap);
78142+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
78143 return;
78144 }
78145
78146@@ -2481,7 +2481,7 @@ void synchronize_sched_expedited(void)
78147 * Take a ticket. Note that atomic_inc_return() implies a
78148 * full memory barrier.
78149 */
78150- snap = atomic_long_inc_return(&rsp->expedited_start);
78151+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
78152 firstsnap = snap;
78153 get_online_cpus();
78154 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
78155@@ -2494,14 +2494,14 @@ void synchronize_sched_expedited(void)
78156 synchronize_sched_expedited_cpu_stop,
78157 NULL) == -EAGAIN) {
78158 put_online_cpus();
78159- atomic_long_inc(&rsp->expedited_tryfail);
78160+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
78161
78162 /* Check to see if someone else did our work for us. */
78163 s = atomic_long_read(&rsp->expedited_done);
78164 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
78165 /* ensure test happens before caller kfree */
78166 smp_mb__before_atomic_inc(); /* ^^^ */
78167- atomic_long_inc(&rsp->expedited_workdone1);
78168+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
78169 return;
78170 }
78171
78172@@ -2510,7 +2510,7 @@ void synchronize_sched_expedited(void)
78173 udelay(trycount * num_online_cpus());
78174 } else {
78175 wait_rcu_gp(call_rcu_sched);
78176- atomic_long_inc(&rsp->expedited_normal);
78177+ atomic_long_inc_unchecked(&rsp->expedited_normal);
78178 return;
78179 }
78180
78181@@ -2519,7 +2519,7 @@ void synchronize_sched_expedited(void)
78182 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
78183 /* ensure test happens before caller kfree */
78184 smp_mb__before_atomic_inc(); /* ^^^ */
78185- atomic_long_inc(&rsp->expedited_workdone2);
78186+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
78187 return;
78188 }
78189
78190@@ -2531,10 +2531,10 @@ void synchronize_sched_expedited(void)
78191 * period works for us.
78192 */
78193 get_online_cpus();
78194- snap = atomic_long_read(&rsp->expedited_start);
78195+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
78196 smp_mb(); /* ensure read is before try_stop_cpus(). */
78197 }
78198- atomic_long_inc(&rsp->expedited_stoppedcpus);
78199+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
78200
78201 /*
78202 * Everyone up to our most recent fetch is covered by our grace
78203@@ -2543,16 +2543,16 @@ void synchronize_sched_expedited(void)
78204 * than we did already did their update.
78205 */
78206 do {
78207- atomic_long_inc(&rsp->expedited_done_tries);
78208+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
78209 s = atomic_long_read(&rsp->expedited_done);
78210 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
78211 /* ensure test happens before caller kfree */
78212 smp_mb__before_atomic_inc(); /* ^^^ */
78213- atomic_long_inc(&rsp->expedited_done_lost);
78214+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
78215 break;
78216 }
78217 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
78218- atomic_long_inc(&rsp->expedited_done_exit);
78219+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
78220
78221 put_online_cpus();
78222 }
78223@@ -2726,7 +2726,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78224 * ACCESS_ONCE() to prevent the compiler from speculating
78225 * the increment to precede the early-exit check.
78226 */
78227- ACCESS_ONCE(rsp->n_barrier_done)++;
78228+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78229 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
78230 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
78231 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
78232@@ -2776,7 +2776,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78233
78234 /* Increment ->n_barrier_done to prevent duplicate work. */
78235 smp_mb(); /* Keep increment after above mechanism. */
78236- ACCESS_ONCE(rsp->n_barrier_done)++;
78237+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78238 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
78239 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
78240 smp_mb(); /* Keep increment before caller's subsequent code. */
78241@@ -2821,10 +2821,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
78242 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
78243 init_callback_list(rdp);
78244 rdp->qlen_lazy = 0;
78245- ACCESS_ONCE(rdp->qlen) = 0;
78246+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78247 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
78248 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
78249- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
78250+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
78251 rdp->cpu = cpu;
78252 rdp->rsp = rsp;
78253 rcu_boot_init_nocb_percpu_data(rdp);
78254@@ -2857,8 +2857,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
78255 rdp->blimit = blimit;
78256 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
78257 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
78258- atomic_set(&rdp->dynticks->dynticks,
78259- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
78260+ atomic_set_unchecked(&rdp->dynticks->dynticks,
78261+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
78262 rcu_prepare_for_idle_init(cpu);
78263 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
78264
78265@@ -2964,7 +2964,7 @@ static int __init rcu_spawn_gp_kthread(void)
78266 struct task_struct *t;
78267
78268 for_each_rcu_flavor(rsp) {
78269- t = kthread_run(rcu_gp_kthread, rsp, rsp->name);
78270+ t = kthread_run(rcu_gp_kthread, rsp, "%s", rsp->name);
78271 BUG_ON(IS_ERR(t));
78272 rnp = rcu_get_root(rsp);
78273 raw_spin_lock_irqsave(&rnp->lock, flags);
78274diff --git a/kernel/rcutree.h b/kernel/rcutree.h
78275index c896b50..c357252 100644
78276--- a/kernel/rcutree.h
78277+++ b/kernel/rcutree.h
78278@@ -86,7 +86,7 @@ struct rcu_dynticks {
78279 long long dynticks_nesting; /* Track irq/process nesting level. */
78280 /* Process level is worth LLONG_MAX/2. */
78281 int dynticks_nmi_nesting; /* Track NMI nesting level. */
78282- atomic_t dynticks; /* Even value for idle, else odd. */
78283+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
78284 #ifdef CONFIG_RCU_FAST_NO_HZ
78285 int dyntick_drain; /* Prepare-for-idle state variable. */
78286 unsigned long dyntick_holdoff;
78287@@ -416,17 +416,17 @@ struct rcu_state {
78288 /* _rcu_barrier(). */
78289 /* End of fields guarded by barrier_mutex. */
78290
78291- atomic_long_t expedited_start; /* Starting ticket. */
78292- atomic_long_t expedited_done; /* Done ticket. */
78293- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
78294- atomic_long_t expedited_tryfail; /* # acquisition failures. */
78295- atomic_long_t expedited_workdone1; /* # done by others #1. */
78296- atomic_long_t expedited_workdone2; /* # done by others #2. */
78297- atomic_long_t expedited_normal; /* # fallbacks to normal. */
78298- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
78299- atomic_long_t expedited_done_tries; /* # tries to update _done. */
78300- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
78301- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
78302+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
78303+ atomic_long_t expedited_done; /* Done ticket. */
78304+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
78305+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
78306+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
78307+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
78308+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
78309+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
78310+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
78311+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
78312+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
78313
78314 unsigned long jiffies_force_qs; /* Time at which to invoke */
78315 /* force_quiescent_state(). */
78316diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
78317index c1cc7e1..f62e436 100644
78318--- a/kernel/rcutree_plugin.h
78319+++ b/kernel/rcutree_plugin.h
78320@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
78321
78322 /* Clean up and exit. */
78323 smp_mb(); /* ensure expedited GP seen before counter increment. */
78324- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
78325+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
78326 unlock_mb_ret:
78327 mutex_unlock(&sync_rcu_preempt_exp_mutex);
78328 mb_ret:
78329@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
78330 free_cpumask_var(cm);
78331 }
78332
78333-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
78334+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
78335 .store = &rcu_cpu_kthread_task,
78336 .thread_should_run = rcu_cpu_kthread_should_run,
78337 .thread_fn = rcu_cpu_kthread,
78338@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
78339 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
78340 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
78341 cpu, ticks_value, ticks_title,
78342- atomic_read(&rdtp->dynticks) & 0xfff,
78343+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
78344 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
78345 fast_no_hz);
78346 }
78347@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
78348
78349 /* Enqueue the callback on the nocb list and update counts. */
78350 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
78351- ACCESS_ONCE(*old_rhpp) = rhp;
78352+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
78353 atomic_long_add(rhcount, &rdp->nocb_q_count);
78354 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
78355
78356@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
78357 * Extract queued callbacks, update counts, and wait
78358 * for a grace period to elapse.
78359 */
78360- ACCESS_ONCE(rdp->nocb_head) = NULL;
78361+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
78362 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
78363 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
78364 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
78365- ACCESS_ONCE(rdp->nocb_p_count) += c;
78366- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
78367+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
78368+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
78369 wait_rcu_gp(rdp->rsp->call_remote);
78370
78371 /* Each pass through the following loop invokes a callback. */
78372@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
78373 list = next;
78374 }
78375 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
78376- ACCESS_ONCE(rdp->nocb_p_count) -= c;
78377- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
78378+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
78379+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
78380 rdp->n_nocbs_invoked += c;
78381 }
78382 return 0;
78383@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
78384 rdp = per_cpu_ptr(rsp->rda, cpu);
78385 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
78386 BUG_ON(IS_ERR(t));
78387- ACCESS_ONCE(rdp->nocb_kthread) = t;
78388+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
78389 }
78390 }
78391
78392diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
78393index 93f8e8f..cf812ae 100644
78394--- a/kernel/rcutree_trace.c
78395+++ b/kernel/rcutree_trace.c
78396@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
78397 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
78398 rdp->passed_quiesce, rdp->qs_pending);
78399 seq_printf(m, " dt=%d/%llx/%d df=%lu",
78400- atomic_read(&rdp->dynticks->dynticks),
78401+ atomic_read_unchecked(&rdp->dynticks->dynticks),
78402 rdp->dynticks->dynticks_nesting,
78403 rdp->dynticks->dynticks_nmi_nesting,
78404 rdp->dynticks_fqs);
78405@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
78406 struct rcu_state *rsp = (struct rcu_state *)m->private;
78407
78408 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",
78409- atomic_long_read(&rsp->expedited_start),
78410+ atomic_long_read_unchecked(&rsp->expedited_start),
78411 atomic_long_read(&rsp->expedited_done),
78412- atomic_long_read(&rsp->expedited_wrap),
78413- atomic_long_read(&rsp->expedited_tryfail),
78414- atomic_long_read(&rsp->expedited_workdone1),
78415- atomic_long_read(&rsp->expedited_workdone2),
78416- atomic_long_read(&rsp->expedited_normal),
78417- atomic_long_read(&rsp->expedited_stoppedcpus),
78418- atomic_long_read(&rsp->expedited_done_tries),
78419- atomic_long_read(&rsp->expedited_done_lost),
78420- atomic_long_read(&rsp->expedited_done_exit));
78421+ atomic_long_read_unchecked(&rsp->expedited_wrap),
78422+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
78423+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
78424+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
78425+ atomic_long_read_unchecked(&rsp->expedited_normal),
78426+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
78427+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
78428+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
78429+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
78430 return 0;
78431 }
78432
78433diff --git a/kernel/resource.c b/kernel/resource.c
78434index 73f35d4..4684fc4 100644
78435--- a/kernel/resource.c
78436+++ b/kernel/resource.c
78437@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
78438
78439 static int __init ioresources_init(void)
78440 {
78441+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78442+#ifdef CONFIG_GRKERNSEC_PROC_USER
78443+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
78444+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
78445+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78446+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
78447+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
78448+#endif
78449+#else
78450 proc_create("ioports", 0, NULL, &proc_ioports_operations);
78451 proc_create("iomem", 0, NULL, &proc_iomem_operations);
78452+#endif
78453 return 0;
78454 }
78455 __initcall(ioresources_init);
78456diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
78457index 7890b10..8b68605f 100644
78458--- a/kernel/rtmutex-tester.c
78459+++ b/kernel/rtmutex-tester.c
78460@@ -21,7 +21,7 @@
78461 #define MAX_RT_TEST_MUTEXES 8
78462
78463 static spinlock_t rttest_lock;
78464-static atomic_t rttest_event;
78465+static atomic_unchecked_t rttest_event;
78466
78467 struct test_thread_data {
78468 int opcode;
78469@@ -62,7 +62,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78470
78471 case RTTEST_LOCKCONT:
78472 td->mutexes[td->opdata] = 1;
78473- td->event = atomic_add_return(1, &rttest_event);
78474+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78475 return 0;
78476
78477 case RTTEST_RESET:
78478@@ -75,7 +75,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78479 return 0;
78480
78481 case RTTEST_RESETEVENT:
78482- atomic_set(&rttest_event, 0);
78483+ atomic_set_unchecked(&rttest_event, 0);
78484 return 0;
78485
78486 default:
78487@@ -92,9 +92,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78488 return ret;
78489
78490 td->mutexes[id] = 1;
78491- td->event = atomic_add_return(1, &rttest_event);
78492+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78493 rt_mutex_lock(&mutexes[id]);
78494- td->event = atomic_add_return(1, &rttest_event);
78495+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78496 td->mutexes[id] = 4;
78497 return 0;
78498
78499@@ -105,9 +105,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78500 return ret;
78501
78502 td->mutexes[id] = 1;
78503- td->event = atomic_add_return(1, &rttest_event);
78504+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78505 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
78506- td->event = atomic_add_return(1, &rttest_event);
78507+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78508 td->mutexes[id] = ret ? 0 : 4;
78509 return ret ? -EINTR : 0;
78510
78511@@ -116,9 +116,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78512 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
78513 return ret;
78514
78515- td->event = atomic_add_return(1, &rttest_event);
78516+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78517 rt_mutex_unlock(&mutexes[id]);
78518- td->event = atomic_add_return(1, &rttest_event);
78519+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78520 td->mutexes[id] = 0;
78521 return 0;
78522
78523@@ -165,7 +165,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78524 break;
78525
78526 td->mutexes[dat] = 2;
78527- td->event = atomic_add_return(1, &rttest_event);
78528+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78529 break;
78530
78531 default:
78532@@ -185,7 +185,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78533 return;
78534
78535 td->mutexes[dat] = 3;
78536- td->event = atomic_add_return(1, &rttest_event);
78537+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78538 break;
78539
78540 case RTTEST_LOCKNOWAIT:
78541@@ -197,7 +197,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78542 return;
78543
78544 td->mutexes[dat] = 1;
78545- td->event = atomic_add_return(1, &rttest_event);
78546+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78547 return;
78548
78549 default:
78550diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
78551index 64de5f8..7735e12 100644
78552--- a/kernel/sched/auto_group.c
78553+++ b/kernel/sched/auto_group.c
78554@@ -11,7 +11,7 @@
78555
78556 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
78557 static struct autogroup autogroup_default;
78558-static atomic_t autogroup_seq_nr;
78559+static atomic_unchecked_t autogroup_seq_nr;
78560
78561 void __init autogroup_init(struct task_struct *init_task)
78562 {
78563@@ -81,7 +81,7 @@ static inline struct autogroup *autogroup_create(void)
78564
78565 kref_init(&ag->kref);
78566 init_rwsem(&ag->lock);
78567- ag->id = atomic_inc_return(&autogroup_seq_nr);
78568+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
78569 ag->tg = tg;
78570 #ifdef CONFIG_RT_GROUP_SCHED
78571 /*
78572diff --git a/kernel/sched/core.c b/kernel/sched/core.c
78573index 67d0465..4cf9361 100644
78574--- a/kernel/sched/core.c
78575+++ b/kernel/sched/core.c
78576@@ -3406,7 +3406,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
78577 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78578 * positive (at least 1, or number of jiffies left till timeout) if completed.
78579 */
78580-long __sched
78581+long __sched __intentional_overflow(-1)
78582 wait_for_completion_interruptible_timeout(struct completion *x,
78583 unsigned long timeout)
78584 {
78585@@ -3423,7 +3423,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
78586 *
78587 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
78588 */
78589-int __sched wait_for_completion_killable(struct completion *x)
78590+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
78591 {
78592 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
78593 if (t == -ERESTARTSYS)
78594@@ -3444,7 +3444,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
78595 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78596 * positive (at least 1, or number of jiffies left till timeout) if completed.
78597 */
78598-long __sched
78599+long __sched __intentional_overflow(-1)
78600 wait_for_completion_killable_timeout(struct completion *x,
78601 unsigned long timeout)
78602 {
78603@@ -3670,6 +3670,8 @@ int can_nice(const struct task_struct *p, const int nice)
78604 /* convert nice value [19,-20] to rlimit style value [1,40] */
78605 int nice_rlim = 20 - nice;
78606
78607+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
78608+
78609 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
78610 capable(CAP_SYS_NICE));
78611 }
78612@@ -3703,7 +3705,8 @@ SYSCALL_DEFINE1(nice, int, increment)
78613 if (nice > 19)
78614 nice = 19;
78615
78616- if (increment < 0 && !can_nice(current, nice))
78617+ if (increment < 0 && (!can_nice(current, nice) ||
78618+ gr_handle_chroot_nice()))
78619 return -EPERM;
78620
78621 retval = security_task_setnice(current, nice);
78622@@ -3857,6 +3860,7 @@ recheck:
78623 unsigned long rlim_rtprio =
78624 task_rlimit(p, RLIMIT_RTPRIO);
78625
78626+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
78627 /* can't set/change the rt policy */
78628 if (policy != p->policy && !rlim_rtprio)
78629 return -EPERM;
78630@@ -4954,7 +4958,7 @@ static void migrate_tasks(unsigned int dead_cpu)
78631
78632 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
78633
78634-static struct ctl_table sd_ctl_dir[] = {
78635+static ctl_table_no_const sd_ctl_dir[] __read_only = {
78636 {
78637 .procname = "sched_domain",
78638 .mode = 0555,
78639@@ -4971,17 +4975,17 @@ static struct ctl_table sd_ctl_root[] = {
78640 {}
78641 };
78642
78643-static struct ctl_table *sd_alloc_ctl_entry(int n)
78644+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
78645 {
78646- struct ctl_table *entry =
78647+ ctl_table_no_const *entry =
78648 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
78649
78650 return entry;
78651 }
78652
78653-static void sd_free_ctl_entry(struct ctl_table **tablep)
78654+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
78655 {
78656- struct ctl_table *entry;
78657+ ctl_table_no_const *entry;
78658
78659 /*
78660 * In the intermediate directories, both the child directory and
78661@@ -4989,22 +4993,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
78662 * will always be set. In the lowest directory the names are
78663 * static strings and all have proc handlers.
78664 */
78665- for (entry = *tablep; entry->mode; entry++) {
78666- if (entry->child)
78667- sd_free_ctl_entry(&entry->child);
78668+ for (entry = tablep; entry->mode; entry++) {
78669+ if (entry->child) {
78670+ sd_free_ctl_entry(entry->child);
78671+ pax_open_kernel();
78672+ entry->child = NULL;
78673+ pax_close_kernel();
78674+ }
78675 if (entry->proc_handler == NULL)
78676 kfree(entry->procname);
78677 }
78678
78679- kfree(*tablep);
78680- *tablep = NULL;
78681+ kfree(tablep);
78682 }
78683
78684 static int min_load_idx = 0;
78685 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
78686
78687 static void
78688-set_table_entry(struct ctl_table *entry,
78689+set_table_entry(ctl_table_no_const *entry,
78690 const char *procname, void *data, int maxlen,
78691 umode_t mode, proc_handler *proc_handler,
78692 bool load_idx)
78693@@ -5024,7 +5031,7 @@ set_table_entry(struct ctl_table *entry,
78694 static struct ctl_table *
78695 sd_alloc_ctl_domain_table(struct sched_domain *sd)
78696 {
78697- struct ctl_table *table = sd_alloc_ctl_entry(13);
78698+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
78699
78700 if (table == NULL)
78701 return NULL;
78702@@ -5059,9 +5066,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
78703 return table;
78704 }
78705
78706-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
78707+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
78708 {
78709- struct ctl_table *entry, *table;
78710+ ctl_table_no_const *entry, *table;
78711 struct sched_domain *sd;
78712 int domain_num = 0, i;
78713 char buf[32];
78714@@ -5088,11 +5095,13 @@ static struct ctl_table_header *sd_sysctl_header;
78715 static void register_sched_domain_sysctl(void)
78716 {
78717 int i, cpu_num = num_possible_cpus();
78718- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
78719+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
78720 char buf[32];
78721
78722 WARN_ON(sd_ctl_dir[0].child);
78723+ pax_open_kernel();
78724 sd_ctl_dir[0].child = entry;
78725+ pax_close_kernel();
78726
78727 if (entry == NULL)
78728 return;
78729@@ -5115,8 +5124,12 @@ static void unregister_sched_domain_sysctl(void)
78730 if (sd_sysctl_header)
78731 unregister_sysctl_table(sd_sysctl_header);
78732 sd_sysctl_header = NULL;
78733- if (sd_ctl_dir[0].child)
78734- sd_free_ctl_entry(&sd_ctl_dir[0].child);
78735+ if (sd_ctl_dir[0].child) {
78736+ sd_free_ctl_entry(sd_ctl_dir[0].child);
78737+ pax_open_kernel();
78738+ sd_ctl_dir[0].child = NULL;
78739+ pax_close_kernel();
78740+ }
78741 }
78742 #else
78743 static void register_sched_domain_sysctl(void)
78744@@ -5215,7 +5228,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
78745 * happens before everything else. This has to be lower priority than
78746 * the notifier in the perf_event subsystem, though.
78747 */
78748-static struct notifier_block __cpuinitdata migration_notifier = {
78749+static struct notifier_block migration_notifier = {
78750 .notifier_call = migration_call,
78751 .priority = CPU_PRI_MIGRATION,
78752 };
78753diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
78754index 7a33e59..2f7730c 100644
78755--- a/kernel/sched/fair.c
78756+++ b/kernel/sched/fair.c
78757@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
78758
78759 static void reset_ptenuma_scan(struct task_struct *p)
78760 {
78761- ACCESS_ONCE(p->mm->numa_scan_seq)++;
78762+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
78763 p->mm->numa_scan_offset = 0;
78764 }
78765
78766@@ -5654,7 +5654,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
78767 * run_rebalance_domains is triggered when needed from the scheduler tick.
78768 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
78769 */
78770-static void run_rebalance_domains(struct softirq_action *h)
78771+static void run_rebalance_domains(void)
78772 {
78773 int this_cpu = smp_processor_id();
78774 struct rq *this_rq = cpu_rq(this_cpu);
78775diff --git a/kernel/signal.c b/kernel/signal.c
78776index 598dc06..471310a 100644
78777--- a/kernel/signal.c
78778+++ b/kernel/signal.c
78779@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
78780
78781 int print_fatal_signals __read_mostly;
78782
78783-static void __user *sig_handler(struct task_struct *t, int sig)
78784+static __sighandler_t sig_handler(struct task_struct *t, int sig)
78785 {
78786 return t->sighand->action[sig - 1].sa.sa_handler;
78787 }
78788
78789-static int sig_handler_ignored(void __user *handler, int sig)
78790+static int sig_handler_ignored(__sighandler_t handler, int sig)
78791 {
78792 /* Is it explicitly or implicitly ignored? */
78793 return handler == SIG_IGN ||
78794@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
78795
78796 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
78797 {
78798- void __user *handler;
78799+ __sighandler_t handler;
78800
78801 handler = sig_handler(t, sig);
78802
78803@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
78804 atomic_inc(&user->sigpending);
78805 rcu_read_unlock();
78806
78807+ if (!override_rlimit)
78808+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
78809+
78810 if (override_rlimit ||
78811 atomic_read(&user->sigpending) <=
78812 task_rlimit(t, RLIMIT_SIGPENDING)) {
78813@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
78814
78815 int unhandled_signal(struct task_struct *tsk, int sig)
78816 {
78817- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
78818+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
78819 if (is_global_init(tsk))
78820 return 1;
78821 if (handler != SIG_IGN && handler != SIG_DFL)
78822@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
78823 }
78824 }
78825
78826+ /* allow glibc communication via tgkill to other threads in our
78827+ thread group */
78828+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
78829+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
78830+ && gr_handle_signal(t, sig))
78831+ return -EPERM;
78832+
78833 return security_task_kill(t, info, sig, 0);
78834 }
78835
78836@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78837 return send_signal(sig, info, p, 1);
78838 }
78839
78840-static int
78841+int
78842 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78843 {
78844 return send_signal(sig, info, t, 0);
78845@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78846 unsigned long int flags;
78847 int ret, blocked, ignored;
78848 struct k_sigaction *action;
78849+ int is_unhandled = 0;
78850
78851 spin_lock_irqsave(&t->sighand->siglock, flags);
78852 action = &t->sighand->action[sig-1];
78853@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78854 }
78855 if (action->sa.sa_handler == SIG_DFL)
78856 t->signal->flags &= ~SIGNAL_UNKILLABLE;
78857+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
78858+ is_unhandled = 1;
78859 ret = specific_send_sig_info(sig, info, t);
78860 spin_unlock_irqrestore(&t->sighand->siglock, flags);
78861
78862+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
78863+ normal operation */
78864+ if (is_unhandled) {
78865+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
78866+ gr_handle_crash(t, sig);
78867+ }
78868+
78869 return ret;
78870 }
78871
78872@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78873 ret = check_kill_permission(sig, info, p);
78874 rcu_read_unlock();
78875
78876- if (!ret && sig)
78877+ if (!ret && sig) {
78878 ret = do_send_sig_info(sig, info, p, true);
78879+ if (!ret)
78880+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
78881+ }
78882
78883 return ret;
78884 }
78885@@ -2923,7 +2946,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
78886 int error = -ESRCH;
78887
78888 rcu_read_lock();
78889- p = find_task_by_vpid(pid);
78890+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78891+ /* allow glibc communication via tgkill to other threads in our
78892+ thread group */
78893+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
78894+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
78895+ p = find_task_by_vpid_unrestricted(pid);
78896+ else
78897+#endif
78898+ p = find_task_by_vpid(pid);
78899 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
78900 error = check_kill_permission(sig, info, p);
78901 /*
78902@@ -3237,8 +3268,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
78903 }
78904 seg = get_fs();
78905 set_fs(KERNEL_DS);
78906- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
78907- (stack_t __force __user *) &uoss,
78908+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
78909+ (stack_t __force_user *) &uoss,
78910 compat_user_stack_pointer());
78911 set_fs(seg);
78912 if (ret >= 0 && uoss_ptr) {
78913diff --git a/kernel/smp.c b/kernel/smp.c
78914index 8e451f3..8322029 100644
78915--- a/kernel/smp.c
78916+++ b/kernel/smp.c
78917@@ -73,7 +73,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
78918 return NOTIFY_OK;
78919 }
78920
78921-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
78922+static struct notifier_block hotplug_cfd_notifier = {
78923 .notifier_call = hotplug_cfd,
78924 };
78925
78926diff --git a/kernel/smpboot.c b/kernel/smpboot.c
78927index 02fc5c9..e54c335 100644
78928--- a/kernel/smpboot.c
78929+++ b/kernel/smpboot.c
78930@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
78931 }
78932 smpboot_unpark_thread(plug_thread, cpu);
78933 }
78934- list_add(&plug_thread->list, &hotplug_threads);
78935+ pax_list_add(&plug_thread->list, &hotplug_threads);
78936 out:
78937 mutex_unlock(&smpboot_threads_lock);
78938 return ret;
78939@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
78940 {
78941 get_online_cpus();
78942 mutex_lock(&smpboot_threads_lock);
78943- list_del(&plug_thread->list);
78944+ pax_list_del(&plug_thread->list);
78945 smpboot_destroy_threads(plug_thread);
78946 mutex_unlock(&smpboot_threads_lock);
78947 put_online_cpus();
78948diff --git a/kernel/softirq.c b/kernel/softirq.c
78949index d93dcb1..1cd8a71 100644
78950--- a/kernel/softirq.c
78951+++ b/kernel/softirq.c
78952@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
78953 EXPORT_SYMBOL(irq_stat);
78954 #endif
78955
78956-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
78957+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
78958
78959 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
78960
78961-char *softirq_to_name[NR_SOFTIRQS] = {
78962+const char * const softirq_to_name[NR_SOFTIRQS] = {
78963 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
78964 "TASKLET", "SCHED", "HRTIMER", "RCU"
78965 };
78966@@ -250,7 +250,7 @@ restart:
78967 kstat_incr_softirqs_this_cpu(vec_nr);
78968
78969 trace_softirq_entry(vec_nr);
78970- h->action(h);
78971+ h->action();
78972 trace_softirq_exit(vec_nr);
78973 if (unlikely(prev_count != preempt_count())) {
78974 printk(KERN_ERR "huh, entered softirq %u %s %p"
78975@@ -396,7 +396,7 @@ void __raise_softirq_irqoff(unsigned int nr)
78976 or_softirq_pending(1UL << nr);
78977 }
78978
78979-void open_softirq(int nr, void (*action)(struct softirq_action *))
78980+void __init open_softirq(int nr, void (*action)(void))
78981 {
78982 softirq_vec[nr].action = action;
78983 }
78984@@ -452,7 +452,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
78985
78986 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
78987
78988-static void tasklet_action(struct softirq_action *a)
78989+static void tasklet_action(void)
78990 {
78991 struct tasklet_struct *list;
78992
78993@@ -487,7 +487,7 @@ static void tasklet_action(struct softirq_action *a)
78994 }
78995 }
78996
78997-static void tasklet_hi_action(struct softirq_action *a)
78998+static void tasklet_hi_action(void)
78999 {
79000 struct tasklet_struct *list;
79001
79002@@ -723,7 +723,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
79003 return NOTIFY_OK;
79004 }
79005
79006-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
79007+static struct notifier_block remote_softirq_cpu_notifier = {
79008 .notifier_call = remote_softirq_cpu_notify,
79009 };
79010
79011@@ -840,11 +840,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
79012 return NOTIFY_OK;
79013 }
79014
79015-static struct notifier_block __cpuinitdata cpu_nfb = {
79016+static struct notifier_block cpu_nfb = {
79017 .notifier_call = cpu_callback
79018 };
79019
79020-static struct smp_hotplug_thread softirq_threads = {
79021+static struct smp_hotplug_thread softirq_threads __read_only = {
79022 .store = &ksoftirqd,
79023 .thread_should_run = ksoftirqd_should_run,
79024 .thread_fn = run_ksoftirqd,
79025diff --git a/kernel/srcu.c b/kernel/srcu.c
79026index 01d5ccb..cdcbee6 100644
79027--- a/kernel/srcu.c
79028+++ b/kernel/srcu.c
79029@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
79030
79031 idx = ACCESS_ONCE(sp->completed) & 0x1;
79032 preempt_disable();
79033- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79034+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79035 smp_mb(); /* B */ /* Avoid leaking the critical section. */
79036- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79037+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79038 preempt_enable();
79039 return idx;
79040 }
79041diff --git a/kernel/sys.c b/kernel/sys.c
79042index e5f0aca..8d58b1f 100644
79043--- a/kernel/sys.c
79044+++ b/kernel/sys.c
79045@@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
79046 error = -EACCES;
79047 goto out;
79048 }
79049+
79050+ if (gr_handle_chroot_setpriority(p, niceval)) {
79051+ error = -EACCES;
79052+ goto out;
79053+ }
79054+
79055 no_nice = security_task_setnice(p, niceval);
79056 if (no_nice) {
79057 error = no_nice;
79058@@ -621,6 +627,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
79059 goto error;
79060 }
79061
79062+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
79063+ goto error;
79064+
79065 if (rgid != (gid_t) -1 ||
79066 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
79067 new->sgid = new->egid;
79068@@ -656,6 +665,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
79069 old = current_cred();
79070
79071 retval = -EPERM;
79072+
79073+ if (gr_check_group_change(kgid, kgid, kgid))
79074+ goto error;
79075+
79076 if (nsown_capable(CAP_SETGID))
79077 new->gid = new->egid = new->sgid = new->fsgid = kgid;
79078 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
79079@@ -673,7 +686,7 @@ error:
79080 /*
79081 * change the user struct in a credentials set to match the new UID
79082 */
79083-static int set_user(struct cred *new)
79084+int set_user(struct cred *new)
79085 {
79086 struct user_struct *new_user;
79087
79088@@ -753,6 +766,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
79089 goto error;
79090 }
79091
79092+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
79093+ goto error;
79094+
79095 if (!uid_eq(new->uid, old->uid)) {
79096 retval = set_user(new);
79097 if (retval < 0)
79098@@ -803,6 +819,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
79099 old = current_cred();
79100
79101 retval = -EPERM;
79102+
79103+ if (gr_check_crash_uid(kuid))
79104+ goto error;
79105+ if (gr_check_user_change(kuid, kuid, kuid))
79106+ goto error;
79107+
79108 if (nsown_capable(CAP_SETUID)) {
79109 new->suid = new->uid = kuid;
79110 if (!uid_eq(kuid, old->uid)) {
79111@@ -872,6 +894,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
79112 goto error;
79113 }
79114
79115+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
79116+ goto error;
79117+
79118 if (ruid != (uid_t) -1) {
79119 new->uid = kruid;
79120 if (!uid_eq(kruid, old->uid)) {
79121@@ -954,6 +979,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
79122 goto error;
79123 }
79124
79125+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
79126+ goto error;
79127+
79128 if (rgid != (gid_t) -1)
79129 new->gid = krgid;
79130 if (egid != (gid_t) -1)
79131@@ -1015,12 +1043,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
79132 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
79133 nsown_capable(CAP_SETUID)) {
79134 if (!uid_eq(kuid, old->fsuid)) {
79135+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
79136+ goto error;
79137+
79138 new->fsuid = kuid;
79139 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
79140 goto change_okay;
79141 }
79142 }
79143
79144+error:
79145 abort_creds(new);
79146 return old_fsuid;
79147
79148@@ -1053,12 +1085,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
79149 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
79150 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
79151 nsown_capable(CAP_SETGID)) {
79152+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
79153+ goto error;
79154+
79155 if (!gid_eq(kgid, old->fsgid)) {
79156 new->fsgid = kgid;
79157 goto change_okay;
79158 }
79159 }
79160
79161+error:
79162 abort_creds(new);
79163 return old_fsgid;
79164
79165@@ -1366,19 +1402,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
79166 return -EFAULT;
79167
79168 down_read(&uts_sem);
79169- error = __copy_to_user(&name->sysname, &utsname()->sysname,
79170+ error = __copy_to_user(name->sysname, &utsname()->sysname,
79171 __OLD_UTS_LEN);
79172 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
79173- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
79174+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
79175 __OLD_UTS_LEN);
79176 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
79177- error |= __copy_to_user(&name->release, &utsname()->release,
79178+ error |= __copy_to_user(name->release, &utsname()->release,
79179 __OLD_UTS_LEN);
79180 error |= __put_user(0, name->release + __OLD_UTS_LEN);
79181- error |= __copy_to_user(&name->version, &utsname()->version,
79182+ error |= __copy_to_user(name->version, &utsname()->version,
79183 __OLD_UTS_LEN);
79184 error |= __put_user(0, name->version + __OLD_UTS_LEN);
79185- error |= __copy_to_user(&name->machine, &utsname()->machine,
79186+ error |= __copy_to_user(name->machine, &utsname()->machine,
79187 __OLD_UTS_LEN);
79188 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
79189 up_read(&uts_sem);
79190@@ -1580,6 +1616,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
79191 */
79192 new_rlim->rlim_cur = 1;
79193 }
79194+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
79195+ is changed to a lower value. Since tasks can be created by the same
79196+ user in between this limit change and an execve by this task, force
79197+ a recheck only for this task by setting PF_NPROC_EXCEEDED
79198+ */
79199+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
79200+ tsk->flags |= PF_NPROC_EXCEEDED;
79201 }
79202 if (!retval) {
79203 if (old_rlim)
79204diff --git a/kernel/sysctl.c b/kernel/sysctl.c
79205index afc1dc6..f6cf355 100644
79206--- a/kernel/sysctl.c
79207+++ b/kernel/sysctl.c
79208@@ -93,7 +93,6 @@
79209
79210
79211 #if defined(CONFIG_SYSCTL)
79212-
79213 /* External variables not in a header file. */
79214 extern int sysctl_overcommit_memory;
79215 extern int sysctl_overcommit_ratio;
79216@@ -120,18 +119,18 @@ extern int blk_iopoll_enabled;
79217
79218 /* Constants used for minimum and maximum */
79219 #ifdef CONFIG_LOCKUP_DETECTOR
79220-static int sixty = 60;
79221-static int neg_one = -1;
79222+static int sixty __read_only = 60;
79223 #endif
79224
79225-static int zero;
79226-static int __maybe_unused one = 1;
79227-static int __maybe_unused two = 2;
79228-static int __maybe_unused three = 3;
79229-static unsigned long one_ul = 1;
79230-static int one_hundred = 100;
79231+static int neg_one __read_only = -1;
79232+static int zero __read_only = 0;
79233+static int __maybe_unused one __read_only = 1;
79234+static int __maybe_unused two __read_only = 2;
79235+static int __maybe_unused three __read_only = 3;
79236+static unsigned long one_ul __read_only = 1;
79237+static int one_hundred __read_only = 100;
79238 #ifdef CONFIG_PRINTK
79239-static int ten_thousand = 10000;
79240+static int ten_thousand __read_only = 10000;
79241 #endif
79242
79243 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
79244@@ -178,10 +177,8 @@ static int proc_taint(struct ctl_table *table, int write,
79245 void __user *buffer, size_t *lenp, loff_t *ppos);
79246 #endif
79247
79248-#ifdef CONFIG_PRINTK
79249 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79250 void __user *buffer, size_t *lenp, loff_t *ppos);
79251-#endif
79252
79253 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
79254 void __user *buffer, size_t *lenp, loff_t *ppos);
79255@@ -212,6 +209,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
79256
79257 #endif
79258
79259+extern struct ctl_table grsecurity_table[];
79260+
79261 static struct ctl_table kern_table[];
79262 static struct ctl_table vm_table[];
79263 static struct ctl_table fs_table[];
79264@@ -226,6 +225,20 @@ extern struct ctl_table epoll_table[];
79265 int sysctl_legacy_va_layout;
79266 #endif
79267
79268+#ifdef CONFIG_PAX_SOFTMODE
79269+static ctl_table pax_table[] = {
79270+ {
79271+ .procname = "softmode",
79272+ .data = &pax_softmode,
79273+ .maxlen = sizeof(unsigned int),
79274+ .mode = 0600,
79275+ .proc_handler = &proc_dointvec,
79276+ },
79277+
79278+ { }
79279+};
79280+#endif
79281+
79282 /* The default sysctl tables: */
79283
79284 static struct ctl_table sysctl_base_table[] = {
79285@@ -274,6 +287,22 @@ static int max_extfrag_threshold = 1000;
79286 #endif
79287
79288 static struct ctl_table kern_table[] = {
79289+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
79290+ {
79291+ .procname = "grsecurity",
79292+ .mode = 0500,
79293+ .child = grsecurity_table,
79294+ },
79295+#endif
79296+
79297+#ifdef CONFIG_PAX_SOFTMODE
79298+ {
79299+ .procname = "pax",
79300+ .mode = 0500,
79301+ .child = pax_table,
79302+ },
79303+#endif
79304+
79305 {
79306 .procname = "sched_child_runs_first",
79307 .data = &sysctl_sched_child_runs_first,
79308@@ -608,7 +637,7 @@ static struct ctl_table kern_table[] = {
79309 .data = &modprobe_path,
79310 .maxlen = KMOD_PATH_LEN,
79311 .mode = 0644,
79312- .proc_handler = proc_dostring,
79313+ .proc_handler = proc_dostring_modpriv,
79314 },
79315 {
79316 .procname = "modules_disabled",
79317@@ -775,16 +804,20 @@ static struct ctl_table kern_table[] = {
79318 .extra1 = &zero,
79319 .extra2 = &one,
79320 },
79321+#endif
79322 {
79323 .procname = "kptr_restrict",
79324 .data = &kptr_restrict,
79325 .maxlen = sizeof(int),
79326 .mode = 0644,
79327 .proc_handler = proc_dointvec_minmax_sysadmin,
79328+#ifdef CONFIG_GRKERNSEC_HIDESYM
79329+ .extra1 = &two,
79330+#else
79331 .extra1 = &zero,
79332+#endif
79333 .extra2 = &two,
79334 },
79335-#endif
79336 {
79337 .procname = "ngroups_max",
79338 .data = &ngroups_max,
79339@@ -1026,10 +1059,17 @@ static struct ctl_table kern_table[] = {
79340 */
79341 {
79342 .procname = "perf_event_paranoid",
79343- .data = &sysctl_perf_event_paranoid,
79344- .maxlen = sizeof(sysctl_perf_event_paranoid),
79345+ .data = &sysctl_perf_event_legitimately_concerned,
79346+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
79347 .mode = 0644,
79348- .proc_handler = proc_dointvec,
79349+ /* go ahead, be a hero */
79350+ .proc_handler = proc_dointvec_minmax_sysadmin,
79351+ .extra1 = &neg_one,
79352+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
79353+ .extra2 = &three,
79354+#else
79355+ .extra2 = &two,
79356+#endif
79357 },
79358 {
79359 .procname = "perf_event_mlock_kb",
79360@@ -1283,6 +1323,13 @@ static struct ctl_table vm_table[] = {
79361 .proc_handler = proc_dointvec_minmax,
79362 .extra1 = &zero,
79363 },
79364+ {
79365+ .procname = "heap_stack_gap",
79366+ .data = &sysctl_heap_stack_gap,
79367+ .maxlen = sizeof(sysctl_heap_stack_gap),
79368+ .mode = 0644,
79369+ .proc_handler = proc_doulongvec_minmax,
79370+ },
79371 #else
79372 {
79373 .procname = "nr_trim_pages",
79374@@ -1733,6 +1780,16 @@ int proc_dostring(struct ctl_table *table, int write,
79375 buffer, lenp, ppos);
79376 }
79377
79378+int proc_dostring_modpriv(struct ctl_table *table, int write,
79379+ void __user *buffer, size_t *lenp, loff_t *ppos)
79380+{
79381+ if (write && !capable(CAP_SYS_MODULE))
79382+ return -EPERM;
79383+
79384+ return _proc_do_string(table->data, table->maxlen, write,
79385+ buffer, lenp, ppos);
79386+}
79387+
79388 static size_t proc_skip_spaces(char **buf)
79389 {
79390 size_t ret;
79391@@ -1838,6 +1895,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
79392 len = strlen(tmp);
79393 if (len > *size)
79394 len = *size;
79395+ if (len > sizeof(tmp))
79396+ len = sizeof(tmp);
79397 if (copy_to_user(*buf, tmp, len))
79398 return -EFAULT;
79399 *size -= len;
79400@@ -2002,7 +2061,7 @@ int proc_dointvec(struct ctl_table *table, int write,
79401 static int proc_taint(struct ctl_table *table, int write,
79402 void __user *buffer, size_t *lenp, loff_t *ppos)
79403 {
79404- struct ctl_table t;
79405+ ctl_table_no_const t;
79406 unsigned long tmptaint = get_taint();
79407 int err;
79408
79409@@ -2030,7 +2089,6 @@ static int proc_taint(struct ctl_table *table, int write,
79410 return err;
79411 }
79412
79413-#ifdef CONFIG_PRINTK
79414 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79415 void __user *buffer, size_t *lenp, loff_t *ppos)
79416 {
79417@@ -2039,7 +2097,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79418
79419 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
79420 }
79421-#endif
79422
79423 struct do_proc_dointvec_minmax_conv_param {
79424 int *min;
79425@@ -2186,8 +2243,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
79426 *i = val;
79427 } else {
79428 val = convdiv * (*i) / convmul;
79429- if (!first)
79430+ if (!first) {
79431 err = proc_put_char(&buffer, &left, '\t');
79432+ if (err)
79433+ break;
79434+ }
79435 err = proc_put_long(&buffer, &left, val, false);
79436 if (err)
79437 break;
79438@@ -2579,6 +2639,12 @@ int proc_dostring(struct ctl_table *table, int write,
79439 return -ENOSYS;
79440 }
79441
79442+int proc_dostring_modpriv(struct ctl_table *table, int write,
79443+ void __user *buffer, size_t *lenp, loff_t *ppos)
79444+{
79445+ return -ENOSYS;
79446+}
79447+
79448 int proc_dointvec(struct ctl_table *table, int write,
79449 void __user *buffer, size_t *lenp, loff_t *ppos)
79450 {
79451@@ -2635,5 +2701,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
79452 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
79453 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
79454 EXPORT_SYMBOL(proc_dostring);
79455+EXPORT_SYMBOL(proc_dostring_modpriv);
79456 EXPORT_SYMBOL(proc_doulongvec_minmax);
79457 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
79458diff --git a/kernel/taskstats.c b/kernel/taskstats.c
79459index 145bb4d..b2aa969 100644
79460--- a/kernel/taskstats.c
79461+++ b/kernel/taskstats.c
79462@@ -28,9 +28,12 @@
79463 #include <linux/fs.h>
79464 #include <linux/file.h>
79465 #include <linux/pid_namespace.h>
79466+#include <linux/grsecurity.h>
79467 #include <net/genetlink.h>
79468 #include <linux/atomic.h>
79469
79470+extern int gr_is_taskstats_denied(int pid);
79471+
79472 /*
79473 * Maximum length of a cpumask that can be specified in
79474 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
79475@@ -570,6 +573,9 @@ err:
79476
79477 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
79478 {
79479+ if (gr_is_taskstats_denied(current->pid))
79480+ return -EACCES;
79481+
79482 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
79483 return cmd_attr_register_cpumask(info);
79484 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
79485diff --git a/kernel/time.c b/kernel/time.c
79486index f8342a4..288f13b 100644
79487--- a/kernel/time.c
79488+++ b/kernel/time.c
79489@@ -171,6 +171,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
79490 return error;
79491
79492 if (tz) {
79493+ /* we log in do_settimeofday called below, so don't log twice
79494+ */
79495+ if (!tv)
79496+ gr_log_timechange();
79497+
79498 sys_tz = *tz;
79499 update_vsyscall_tz();
79500 if (firsttime) {
79501@@ -501,7 +506,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
79502 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
79503 * value to a scaled second value.
79504 */
79505-unsigned long
79506+unsigned long __intentional_overflow(-1)
79507 timespec_to_jiffies(const struct timespec *value)
79508 {
79509 unsigned long sec = value->tv_sec;
79510diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
79511index f11d83b..d016d91 100644
79512--- a/kernel/time/alarmtimer.c
79513+++ b/kernel/time/alarmtimer.c
79514@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
79515 struct platform_device *pdev;
79516 int error = 0;
79517 int i;
79518- struct k_clock alarm_clock = {
79519+ static struct k_clock alarm_clock = {
79520 .clock_getres = alarm_clock_getres,
79521 .clock_get = alarm_clock_get,
79522 .timer_create = alarm_timer_create,
79523diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
79524index 90ad470..1814e9a 100644
79525--- a/kernel/time/tick-broadcast.c
79526+++ b/kernel/time/tick-broadcast.c
79527@@ -138,7 +138,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
79528 * then clear the broadcast bit.
79529 */
79530 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
79531- int cpu = smp_processor_id();
79532+ cpu = smp_processor_id();
79533 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
79534 tick_broadcast_clear_oneshot(cpu);
79535 } else {
79536diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
79537index 183df62..59b1442 100644
79538--- a/kernel/time/timekeeping.c
79539+++ b/kernel/time/timekeeping.c
79540@@ -15,6 +15,7 @@
79541 #include <linux/init.h>
79542 #include <linux/mm.h>
79543 #include <linux/sched.h>
79544+#include <linux/grsecurity.h>
79545 #include <linux/syscore_ops.h>
79546 #include <linux/clocksource.h>
79547 #include <linux/jiffies.h>
79548@@ -448,6 +449,8 @@ int do_settimeofday(const struct timespec *tv)
79549 if (!timespec_valid_strict(tv))
79550 return -EINVAL;
79551
79552+ gr_log_timechange();
79553+
79554 write_seqlock_irqsave(&tk->lock, flags);
79555
79556 timekeeping_forward_now(tk);
79557diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
79558index af5a7e9..715611a 100644
79559--- a/kernel/time/timer_list.c
79560+++ b/kernel/time/timer_list.c
79561@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
79562
79563 static void print_name_offset(struct seq_file *m, void *sym)
79564 {
79565+#ifdef CONFIG_GRKERNSEC_HIDESYM
79566+ SEQ_printf(m, "<%p>", NULL);
79567+#else
79568 char symname[KSYM_NAME_LEN];
79569
79570 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
79571 SEQ_printf(m, "<%pK>", sym);
79572 else
79573 SEQ_printf(m, "%s", symname);
79574+#endif
79575 }
79576
79577 static void
79578@@ -112,7 +116,11 @@ next_one:
79579 static void
79580 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
79581 {
79582+#ifdef CONFIG_GRKERNSEC_HIDESYM
79583+ SEQ_printf(m, " .base: %p\n", NULL);
79584+#else
79585 SEQ_printf(m, " .base: %pK\n", base);
79586+#endif
79587 SEQ_printf(m, " .index: %d\n",
79588 base->index);
79589 SEQ_printf(m, " .resolution: %Lu nsecs\n",
79590@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
79591 {
79592 struct proc_dir_entry *pe;
79593
79594+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79595+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
79596+#else
79597 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
79598+#endif
79599 if (!pe)
79600 return -ENOMEM;
79601 return 0;
79602diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
79603index 0b537f2..40d6c20 100644
79604--- a/kernel/time/timer_stats.c
79605+++ b/kernel/time/timer_stats.c
79606@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
79607 static unsigned long nr_entries;
79608 static struct entry entries[MAX_ENTRIES];
79609
79610-static atomic_t overflow_count;
79611+static atomic_unchecked_t overflow_count;
79612
79613 /*
79614 * The entries are in a hash-table, for fast lookup:
79615@@ -140,7 +140,7 @@ static void reset_entries(void)
79616 nr_entries = 0;
79617 memset(entries, 0, sizeof(entries));
79618 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
79619- atomic_set(&overflow_count, 0);
79620+ atomic_set_unchecked(&overflow_count, 0);
79621 }
79622
79623 static struct entry *alloc_entry(void)
79624@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79625 if (likely(entry))
79626 entry->count++;
79627 else
79628- atomic_inc(&overflow_count);
79629+ atomic_inc_unchecked(&overflow_count);
79630
79631 out_unlock:
79632 raw_spin_unlock_irqrestore(lock, flags);
79633@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79634
79635 static void print_name_offset(struct seq_file *m, unsigned long addr)
79636 {
79637+#ifdef CONFIG_GRKERNSEC_HIDESYM
79638+ seq_printf(m, "<%p>", NULL);
79639+#else
79640 char symname[KSYM_NAME_LEN];
79641
79642 if (lookup_symbol_name(addr, symname) < 0)
79643- seq_printf(m, "<%p>", (void *)addr);
79644+ seq_printf(m, "<%pK>", (void *)addr);
79645 else
79646 seq_printf(m, "%s", symname);
79647+#endif
79648 }
79649
79650 static int tstats_show(struct seq_file *m, void *v)
79651@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
79652
79653 seq_puts(m, "Timer Stats Version: v0.2\n");
79654 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
79655- if (atomic_read(&overflow_count))
79656+ if (atomic_read_unchecked(&overflow_count))
79657 seq_printf(m, "Overflow: %d entries\n",
79658- atomic_read(&overflow_count));
79659+ atomic_read_unchecked(&overflow_count));
79660
79661 for (i = 0; i < nr_entries; i++) {
79662 entry = entries + i;
79663@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
79664 {
79665 struct proc_dir_entry *pe;
79666
79667+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79668+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
79669+#else
79670 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
79671+#endif
79672 if (!pe)
79673 return -ENOMEM;
79674 return 0;
79675diff --git a/kernel/timer.c b/kernel/timer.c
79676index 1b399c8..90e1849 100644
79677--- a/kernel/timer.c
79678+++ b/kernel/timer.c
79679@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
79680 /*
79681 * This function runs timers and the timer-tq in bottom half context.
79682 */
79683-static void run_timer_softirq(struct softirq_action *h)
79684+static void run_timer_softirq(void)
79685 {
79686 struct tvec_base *base = __this_cpu_read(tvec_bases);
79687
79688@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
79689 *
79690 * In all cases the return value is guaranteed to be non-negative.
79691 */
79692-signed long __sched schedule_timeout(signed long timeout)
79693+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
79694 {
79695 struct timer_list timer;
79696 unsigned long expire;
79697@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
79698 return NOTIFY_OK;
79699 }
79700
79701-static struct notifier_block __cpuinitdata timers_nb = {
79702+static struct notifier_block timers_nb = {
79703 .notifier_call = timer_cpu_notify,
79704 };
79705
79706diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
79707index 5a0f781..1497f95 100644
79708--- a/kernel/trace/blktrace.c
79709+++ b/kernel/trace/blktrace.c
79710@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
79711 struct blk_trace *bt = filp->private_data;
79712 char buf[16];
79713
79714- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
79715+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
79716
79717 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
79718 }
79719@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
79720 return 1;
79721
79722 bt = buf->chan->private_data;
79723- atomic_inc(&bt->dropped);
79724+ atomic_inc_unchecked(&bt->dropped);
79725 return 0;
79726 }
79727
79728@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
79729
79730 bt->dir = dir;
79731 bt->dev = dev;
79732- atomic_set(&bt->dropped, 0);
79733+ atomic_set_unchecked(&bt->dropped, 0);
79734
79735 ret = -EIO;
79736 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
79737diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
79738index 0a0e2a6..943495e 100644
79739--- a/kernel/trace/ftrace.c
79740+++ b/kernel/trace/ftrace.c
79741@@ -1909,12 +1909,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
79742 if (unlikely(ftrace_disabled))
79743 return 0;
79744
79745+ ret = ftrace_arch_code_modify_prepare();
79746+ FTRACE_WARN_ON(ret);
79747+ if (ret)
79748+ return 0;
79749+
79750 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
79751+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
79752 if (ret) {
79753 ftrace_bug(ret, ip);
79754- return 0;
79755 }
79756- return 1;
79757+ return ret ? 0 : 1;
79758 }
79759
79760 /*
79761@@ -2986,7 +2991,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
79762
79763 int
79764 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
79765- void *data)
79766+ void *data)
79767 {
79768 struct ftrace_func_probe *entry;
79769 struct ftrace_page *pg;
79770@@ -3854,8 +3859,10 @@ static int ftrace_process_locs(struct module *mod,
79771 if (!count)
79772 return 0;
79773
79774+ pax_open_kernel();
79775 sort(start, count, sizeof(*start),
79776 ftrace_cmp_ips, ftrace_swap_ips);
79777+ pax_close_kernel();
79778
79779 start_pg = ftrace_allocate_pages(count);
79780 if (!start_pg)
79781@@ -4574,8 +4581,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
79782 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
79783
79784 static int ftrace_graph_active;
79785-static struct notifier_block ftrace_suspend_notifier;
79786-
79787 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
79788 {
79789 return 0;
79790@@ -4719,6 +4724,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
79791 return NOTIFY_DONE;
79792 }
79793
79794+static struct notifier_block ftrace_suspend_notifier = {
79795+ .notifier_call = ftrace_suspend_notifier_call
79796+};
79797+
79798 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79799 trace_func_graph_ent_t entryfunc)
79800 {
79801@@ -4732,7 +4741,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79802 goto out;
79803 }
79804
79805- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
79806 register_pm_notifier(&ftrace_suspend_notifier);
79807
79808 ftrace_graph_active++;
79809diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
79810index 6989df2..c2265cf 100644
79811--- a/kernel/trace/ring_buffer.c
79812+++ b/kernel/trace/ring_buffer.c
79813@@ -349,9 +349,9 @@ struct buffer_data_page {
79814 */
79815 struct buffer_page {
79816 struct list_head list; /* list of buffer pages */
79817- local_t write; /* index for next write */
79818+ local_unchecked_t write; /* index for next write */
79819 unsigned read; /* index for next read */
79820- local_t entries; /* entries on this page */
79821+ local_unchecked_t entries; /* entries on this page */
79822 unsigned long real_end; /* real end of data */
79823 struct buffer_data_page *page; /* Actual data page */
79824 };
79825@@ -464,8 +464,8 @@ struct ring_buffer_per_cpu {
79826 unsigned long last_overrun;
79827 local_t entries_bytes;
79828 local_t entries;
79829- local_t overrun;
79830- local_t commit_overrun;
79831+ local_unchecked_t overrun;
79832+ local_unchecked_t commit_overrun;
79833 local_t dropped_events;
79834 local_t committing;
79835 local_t commits;
79836@@ -864,8 +864,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79837 *
79838 * We add a counter to the write field to denote this.
79839 */
79840- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
79841- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
79842+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
79843+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
79844
79845 /*
79846 * Just make sure we have seen our old_write and synchronize
79847@@ -893,8 +893,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79848 * cmpxchg to only update if an interrupt did not already
79849 * do it for us. If the cmpxchg fails, we don't care.
79850 */
79851- (void)local_cmpxchg(&next_page->write, old_write, val);
79852- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
79853+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
79854+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
79855
79856 /*
79857 * No need to worry about races with clearing out the commit.
79858@@ -1253,12 +1253,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
79859
79860 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
79861 {
79862- return local_read(&bpage->entries) & RB_WRITE_MASK;
79863+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
79864 }
79865
79866 static inline unsigned long rb_page_write(struct buffer_page *bpage)
79867 {
79868- return local_read(&bpage->write) & RB_WRITE_MASK;
79869+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
79870 }
79871
79872 static int
79873@@ -1353,7 +1353,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
79874 * bytes consumed in ring buffer from here.
79875 * Increment overrun to account for the lost events.
79876 */
79877- local_add(page_entries, &cpu_buffer->overrun);
79878+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
79879 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79880 }
79881
79882@@ -1909,7 +1909,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
79883 * it is our responsibility to update
79884 * the counters.
79885 */
79886- local_add(entries, &cpu_buffer->overrun);
79887+ local_add_unchecked(entries, &cpu_buffer->overrun);
79888 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79889
79890 /*
79891@@ -2059,7 +2059,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79892 if (tail == BUF_PAGE_SIZE)
79893 tail_page->real_end = 0;
79894
79895- local_sub(length, &tail_page->write);
79896+ local_sub_unchecked(length, &tail_page->write);
79897 return;
79898 }
79899
79900@@ -2094,7 +2094,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79901 rb_event_set_padding(event);
79902
79903 /* Set the write back to the previous setting */
79904- local_sub(length, &tail_page->write);
79905+ local_sub_unchecked(length, &tail_page->write);
79906 return;
79907 }
79908
79909@@ -2106,7 +2106,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79910
79911 /* Set write to end of buffer */
79912 length = (tail + length) - BUF_PAGE_SIZE;
79913- local_sub(length, &tail_page->write);
79914+ local_sub_unchecked(length, &tail_page->write);
79915 }
79916
79917 /*
79918@@ -2132,7 +2132,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79919 * about it.
79920 */
79921 if (unlikely(next_page == commit_page)) {
79922- local_inc(&cpu_buffer->commit_overrun);
79923+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79924 goto out_reset;
79925 }
79926
79927@@ -2188,7 +2188,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79928 cpu_buffer->tail_page) &&
79929 (cpu_buffer->commit_page ==
79930 cpu_buffer->reader_page))) {
79931- local_inc(&cpu_buffer->commit_overrun);
79932+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79933 goto out_reset;
79934 }
79935 }
79936@@ -2236,7 +2236,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79937 length += RB_LEN_TIME_EXTEND;
79938
79939 tail_page = cpu_buffer->tail_page;
79940- write = local_add_return(length, &tail_page->write);
79941+ write = local_add_return_unchecked(length, &tail_page->write);
79942
79943 /* set write to only the index of the write */
79944 write &= RB_WRITE_MASK;
79945@@ -2253,7 +2253,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79946 kmemcheck_annotate_bitfield(event, bitfield);
79947 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
79948
79949- local_inc(&tail_page->entries);
79950+ local_inc_unchecked(&tail_page->entries);
79951
79952 /*
79953 * If this is the first commit on the page, then update
79954@@ -2286,7 +2286,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79955
79956 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
79957 unsigned long write_mask =
79958- local_read(&bpage->write) & ~RB_WRITE_MASK;
79959+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
79960 unsigned long event_length = rb_event_length(event);
79961 /*
79962 * This is on the tail page. It is possible that
79963@@ -2296,7 +2296,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79964 */
79965 old_index += write_mask;
79966 new_index += write_mask;
79967- index = local_cmpxchg(&bpage->write, old_index, new_index);
79968+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
79969 if (index == old_index) {
79970 /* update counters */
79971 local_sub(event_length, &cpu_buffer->entries_bytes);
79972@@ -2670,7 +2670,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79973
79974 /* Do the likely case first */
79975 if (likely(bpage->page == (void *)addr)) {
79976- local_dec(&bpage->entries);
79977+ local_dec_unchecked(&bpage->entries);
79978 return;
79979 }
79980
79981@@ -2682,7 +2682,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79982 start = bpage;
79983 do {
79984 if (bpage->page == (void *)addr) {
79985- local_dec(&bpage->entries);
79986+ local_dec_unchecked(&bpage->entries);
79987 return;
79988 }
79989 rb_inc_page(cpu_buffer, &bpage);
79990@@ -2964,7 +2964,7 @@ static inline unsigned long
79991 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
79992 {
79993 return local_read(&cpu_buffer->entries) -
79994- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
79995+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
79996 }
79997
79998 /**
79999@@ -3053,7 +3053,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
80000 return 0;
80001
80002 cpu_buffer = buffer->buffers[cpu];
80003- ret = local_read(&cpu_buffer->overrun);
80004+ ret = local_read_unchecked(&cpu_buffer->overrun);
80005
80006 return ret;
80007 }
80008@@ -3076,7 +3076,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
80009 return 0;
80010
80011 cpu_buffer = buffer->buffers[cpu];
80012- ret = local_read(&cpu_buffer->commit_overrun);
80013+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
80014
80015 return ret;
80016 }
80017@@ -3161,7 +3161,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
80018 /* if you care about this being correct, lock the buffer */
80019 for_each_buffer_cpu(buffer, cpu) {
80020 cpu_buffer = buffer->buffers[cpu];
80021- overruns += local_read(&cpu_buffer->overrun);
80022+ overruns += local_read_unchecked(&cpu_buffer->overrun);
80023 }
80024
80025 return overruns;
80026@@ -3337,8 +3337,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80027 /*
80028 * Reset the reader page to size zero.
80029 */
80030- local_set(&cpu_buffer->reader_page->write, 0);
80031- local_set(&cpu_buffer->reader_page->entries, 0);
80032+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80033+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80034 local_set(&cpu_buffer->reader_page->page->commit, 0);
80035 cpu_buffer->reader_page->real_end = 0;
80036
80037@@ -3372,7 +3372,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80038 * want to compare with the last_overrun.
80039 */
80040 smp_mb();
80041- overwrite = local_read(&(cpu_buffer->overrun));
80042+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
80043
80044 /*
80045 * Here's the tricky part.
80046@@ -3942,8 +3942,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80047
80048 cpu_buffer->head_page
80049 = list_entry(cpu_buffer->pages, struct buffer_page, list);
80050- local_set(&cpu_buffer->head_page->write, 0);
80051- local_set(&cpu_buffer->head_page->entries, 0);
80052+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
80053+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
80054 local_set(&cpu_buffer->head_page->page->commit, 0);
80055
80056 cpu_buffer->head_page->read = 0;
80057@@ -3953,14 +3953,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80058
80059 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
80060 INIT_LIST_HEAD(&cpu_buffer->new_pages);
80061- local_set(&cpu_buffer->reader_page->write, 0);
80062- local_set(&cpu_buffer->reader_page->entries, 0);
80063+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80064+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80065 local_set(&cpu_buffer->reader_page->page->commit, 0);
80066 cpu_buffer->reader_page->read = 0;
80067
80068 local_set(&cpu_buffer->entries_bytes, 0);
80069- local_set(&cpu_buffer->overrun, 0);
80070- local_set(&cpu_buffer->commit_overrun, 0);
80071+ local_set_unchecked(&cpu_buffer->overrun, 0);
80072+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
80073 local_set(&cpu_buffer->dropped_events, 0);
80074 local_set(&cpu_buffer->entries, 0);
80075 local_set(&cpu_buffer->committing, 0);
80076@@ -4364,8 +4364,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
80077 rb_init_page(bpage);
80078 bpage = reader->page;
80079 reader->page = *data_page;
80080- local_set(&reader->write, 0);
80081- local_set(&reader->entries, 0);
80082+ local_set_unchecked(&reader->write, 0);
80083+ local_set_unchecked(&reader->entries, 0);
80084 reader->read = 0;
80085 *data_page = bpage;
80086
80087diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
80088index 3f28192..a29e8b0 100644
80089--- a/kernel/trace/trace.c
80090+++ b/kernel/trace/trace.c
80091@@ -2893,7 +2893,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
80092 return 0;
80093 }
80094
80095-int set_tracer_flag(unsigned int mask, int enabled)
80096+int set_tracer_flag(unsigned long mask, int enabled)
80097 {
80098 /* do nothing if flag is already set */
80099 if (!!(trace_flags & mask) == !!enabled)
80100@@ -4637,10 +4637,9 @@ static const struct file_operations tracing_dyn_info_fops = {
80101 };
80102 #endif
80103
80104-static struct dentry *d_tracer;
80105-
80106 struct dentry *tracing_init_dentry(void)
80107 {
80108+ static struct dentry *d_tracer;
80109 static int once;
80110
80111 if (d_tracer)
80112@@ -4660,10 +4659,9 @@ struct dentry *tracing_init_dentry(void)
80113 return d_tracer;
80114 }
80115
80116-static struct dentry *d_percpu;
80117-
80118 static struct dentry *tracing_dentry_percpu(void)
80119 {
80120+ static struct dentry *d_percpu;
80121 static int once;
80122 struct dentry *d_tracer;
80123
80124diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
80125index 2081971..09f861e 100644
80126--- a/kernel/trace/trace.h
80127+++ b/kernel/trace/trace.h
80128@@ -948,7 +948,7 @@ extern const char *__stop___trace_bprintk_fmt[];
80129 void trace_printk_init_buffers(void);
80130 void trace_printk_start_comm(void);
80131 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
80132-int set_tracer_flag(unsigned int mask, int enabled);
80133+int set_tracer_flag(unsigned long mask, int enabled);
80134
80135 #undef FTRACE_ENTRY
80136 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
80137diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
80138index 57e9b28..eebe41c 100644
80139--- a/kernel/trace/trace_events.c
80140+++ b/kernel/trace/trace_events.c
80141@@ -1329,10 +1329,6 @@ static LIST_HEAD(ftrace_module_file_list);
80142 struct ftrace_module_file_ops {
80143 struct list_head list;
80144 struct module *mod;
80145- struct file_operations id;
80146- struct file_operations enable;
80147- struct file_operations format;
80148- struct file_operations filter;
80149 };
80150
80151 static struct ftrace_module_file_ops *
80152@@ -1353,17 +1349,12 @@ trace_create_file_ops(struct module *mod)
80153
80154 file_ops->mod = mod;
80155
80156- file_ops->id = ftrace_event_id_fops;
80157- file_ops->id.owner = mod;
80158-
80159- file_ops->enable = ftrace_enable_fops;
80160- file_ops->enable.owner = mod;
80161-
80162- file_ops->filter = ftrace_event_filter_fops;
80163- file_ops->filter.owner = mod;
80164-
80165- file_ops->format = ftrace_event_format_fops;
80166- file_ops->format.owner = mod;
80167+ pax_open_kernel();
80168+ mod->trace_id.owner = mod;
80169+ mod->trace_enable.owner = mod;
80170+ mod->trace_filter.owner = mod;
80171+ mod->trace_format.owner = mod;
80172+ pax_close_kernel();
80173
80174 list_add(&file_ops->list, &ftrace_module_file_list);
80175
80176@@ -1387,8 +1378,8 @@ static void trace_module_add_events(struct module *mod)
80177
80178 for_each_event(call, start, end) {
80179 __trace_add_event_call(*call, mod,
80180- &file_ops->id, &file_ops->enable,
80181- &file_ops->filter, &file_ops->format);
80182+ &mod->trace_id, &mod->trace_enable,
80183+ &mod->trace_filter, &mod->trace_format);
80184 }
80185 }
80186
80187diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
80188index fd3c8aa..5f324a6 100644
80189--- a/kernel/trace/trace_mmiotrace.c
80190+++ b/kernel/trace/trace_mmiotrace.c
80191@@ -24,7 +24,7 @@ struct header_iter {
80192 static struct trace_array *mmio_trace_array;
80193 static bool overrun_detected;
80194 static unsigned long prev_overruns;
80195-static atomic_t dropped_count;
80196+static atomic_unchecked_t dropped_count;
80197
80198 static void mmio_reset_data(struct trace_array *tr)
80199 {
80200@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
80201
80202 static unsigned long count_overruns(struct trace_iterator *iter)
80203 {
80204- unsigned long cnt = atomic_xchg(&dropped_count, 0);
80205+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
80206 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
80207
80208 if (over > prev_overruns)
80209@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
80210 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
80211 sizeof(*entry), 0, pc);
80212 if (!event) {
80213- atomic_inc(&dropped_count);
80214+ atomic_inc_unchecked(&dropped_count);
80215 return;
80216 }
80217 entry = ring_buffer_event_data(event);
80218@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
80219 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
80220 sizeof(*entry), 0, pc);
80221 if (!event) {
80222- atomic_inc(&dropped_count);
80223+ atomic_inc_unchecked(&dropped_count);
80224 return;
80225 }
80226 entry = ring_buffer_event_data(event);
80227diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
80228index 697e88d..1a79993 100644
80229--- a/kernel/trace/trace_output.c
80230+++ b/kernel/trace/trace_output.c
80231@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
80232
80233 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
80234 if (!IS_ERR(p)) {
80235- p = mangle_path(s->buffer + s->len, p, "\n");
80236+ p = mangle_path(s->buffer + s->len, p, "\n\\");
80237 if (p) {
80238 s->len = p - s->buffer;
80239 return 1;
80240@@ -851,14 +851,16 @@ int register_ftrace_event(struct trace_event *event)
80241 goto out;
80242 }
80243
80244+ pax_open_kernel();
80245 if (event->funcs->trace == NULL)
80246- event->funcs->trace = trace_nop_print;
80247+ *(void **)&event->funcs->trace = trace_nop_print;
80248 if (event->funcs->raw == NULL)
80249- event->funcs->raw = trace_nop_print;
80250+ *(void **)&event->funcs->raw = trace_nop_print;
80251 if (event->funcs->hex == NULL)
80252- event->funcs->hex = trace_nop_print;
80253+ *(void **)&event->funcs->hex = trace_nop_print;
80254 if (event->funcs->binary == NULL)
80255- event->funcs->binary = trace_nop_print;
80256+ *(void **)&event->funcs->binary = trace_nop_print;
80257+ pax_close_kernel();
80258
80259 key = event->type & (EVENT_HASHSIZE - 1);
80260
80261diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
80262index b20428c..4845a10 100644
80263--- a/kernel/trace/trace_stack.c
80264+++ b/kernel/trace/trace_stack.c
80265@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
80266 return;
80267
80268 /* we do not handle interrupt stacks yet */
80269- if (!object_is_on_stack(stack))
80270+ if (!object_starts_on_stack(stack))
80271 return;
80272
80273 local_irq_save(flags);
80274diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
80275index e134d8f..a018cdd 100644
80276--- a/kernel/user_namespace.c
80277+++ b/kernel/user_namespace.c
80278@@ -853,7 +853,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
80279 if (atomic_read(&current->mm->mm_users) > 1)
80280 return -EINVAL;
80281
80282- if (current->fs->users != 1)
80283+ if (atomic_read(&current->fs->users) != 1)
80284 return -EINVAL;
80285
80286 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
80287diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
80288index 4f69f9a..7c6f8f8 100644
80289--- a/kernel/utsname_sysctl.c
80290+++ b/kernel/utsname_sysctl.c
80291@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
80292 static int proc_do_uts_string(ctl_table *table, int write,
80293 void __user *buffer, size_t *lenp, loff_t *ppos)
80294 {
80295- struct ctl_table uts_table;
80296+ ctl_table_no_const uts_table;
80297 int r;
80298 memcpy(&uts_table, table, sizeof(uts_table));
80299 uts_table.data = get_uts(table, write);
80300diff --git a/kernel/watchdog.c b/kernel/watchdog.c
80301index 4a94467..80a6f9c 100644
80302--- a/kernel/watchdog.c
80303+++ b/kernel/watchdog.c
80304@@ -526,7 +526,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
80305 }
80306 #endif /* CONFIG_SYSCTL */
80307
80308-static struct smp_hotplug_thread watchdog_threads = {
80309+static struct smp_hotplug_thread watchdog_threads __read_only = {
80310 .store = &softlockup_watchdog,
80311 .thread_should_run = watchdog_should_run,
80312 .thread_fn = watchdog,
80313diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
80314index 28be08c..47bab92 100644
80315--- a/lib/Kconfig.debug
80316+++ b/lib/Kconfig.debug
80317@@ -549,7 +549,7 @@ config DEBUG_MUTEXES
80318
80319 config DEBUG_LOCK_ALLOC
80320 bool "Lock debugging: detect incorrect freeing of live locks"
80321- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80322+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80323 select DEBUG_SPINLOCK
80324 select DEBUG_MUTEXES
80325 select LOCKDEP
80326@@ -563,7 +563,7 @@ config DEBUG_LOCK_ALLOC
80327
80328 config PROVE_LOCKING
80329 bool "Lock debugging: prove locking correctness"
80330- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80331+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80332 select LOCKDEP
80333 select DEBUG_SPINLOCK
80334 select DEBUG_MUTEXES
80335@@ -614,7 +614,7 @@ config LOCKDEP
80336
80337 config LOCK_STAT
80338 bool "Lock usage statistics"
80339- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80340+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80341 select LOCKDEP
80342 select DEBUG_SPINLOCK
80343 select DEBUG_MUTEXES
80344@@ -1282,6 +1282,7 @@ config LATENCYTOP
80345 depends on DEBUG_KERNEL
80346 depends on STACKTRACE_SUPPORT
80347 depends on PROC_FS
80348+ depends on !GRKERNSEC_HIDESYM
80349 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
80350 select KALLSYMS
80351 select KALLSYMS_ALL
80352@@ -1310,7 +1311,7 @@ config INTERVAL_TREE_TEST
80353
80354 config PROVIDE_OHCI1394_DMA_INIT
80355 bool "Remote debugging over FireWire early on boot"
80356- depends on PCI && X86
80357+ depends on PCI && X86 && !GRKERNSEC
80358 help
80359 If you want to debug problems which hang or crash the kernel early
80360 on boot and the crashing machine has a FireWire port, you can use
80361@@ -1339,7 +1340,7 @@ config PROVIDE_OHCI1394_DMA_INIT
80362
80363 config FIREWIRE_OHCI_REMOTE_DMA
80364 bool "Remote debugging over FireWire with firewire-ohci"
80365- depends on FIREWIRE_OHCI
80366+ depends on FIREWIRE_OHCI && !GRKERNSEC
80367 help
80368 This option lets you use the FireWire bus for remote debugging
80369 with help of the firewire-ohci driver. It enables unfiltered
80370diff --git a/lib/Makefile b/lib/Makefile
80371index 6e2cc56..9b13738 100644
80372--- a/lib/Makefile
80373+++ b/lib/Makefile
80374@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
80375
80376 obj-$(CONFIG_BTREE) += btree.o
80377 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
80378-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
80379+obj-y += list_debug.o
80380 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
80381
80382 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
80383diff --git a/lib/bitmap.c b/lib/bitmap.c
80384index 06f7e4f..f3cf2b0 100644
80385--- a/lib/bitmap.c
80386+++ b/lib/bitmap.c
80387@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
80388 {
80389 int c, old_c, totaldigits, ndigits, nchunks, nbits;
80390 u32 chunk;
80391- const char __user __force *ubuf = (const char __user __force *)buf;
80392+ const char __user *ubuf = (const char __force_user *)buf;
80393
80394 bitmap_zero(maskp, nmaskbits);
80395
80396@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
80397 {
80398 if (!access_ok(VERIFY_READ, ubuf, ulen))
80399 return -EFAULT;
80400- return __bitmap_parse((const char __force *)ubuf,
80401+ return __bitmap_parse((const char __force_kernel *)ubuf,
80402 ulen, 1, maskp, nmaskbits);
80403
80404 }
80405@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
80406 {
80407 unsigned a, b;
80408 int c, old_c, totaldigits;
80409- const char __user __force *ubuf = (const char __user __force *)buf;
80410+ const char __user *ubuf = (const char __force_user *)buf;
80411 int exp_digit, in_range;
80412
80413 totaldigits = c = 0;
80414@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
80415 {
80416 if (!access_ok(VERIFY_READ, ubuf, ulen))
80417 return -EFAULT;
80418- return __bitmap_parselist((const char __force *)ubuf,
80419+ return __bitmap_parselist((const char __force_kernel *)ubuf,
80420 ulen, 1, maskp, nmaskbits);
80421 }
80422 EXPORT_SYMBOL(bitmap_parselist_user);
80423diff --git a/lib/bug.c b/lib/bug.c
80424index 1686034..a9c00c8 100644
80425--- a/lib/bug.c
80426+++ b/lib/bug.c
80427@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
80428 return BUG_TRAP_TYPE_NONE;
80429
80430 bug = find_bug(bugaddr);
80431+ if (!bug)
80432+ return BUG_TRAP_TYPE_NONE;
80433
80434 file = NULL;
80435 line = 0;
80436diff --git a/lib/debugobjects.c b/lib/debugobjects.c
80437index 37061ed..da83f48 100644
80438--- a/lib/debugobjects.c
80439+++ b/lib/debugobjects.c
80440@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
80441 if (limit > 4)
80442 return;
80443
80444- is_on_stack = object_is_on_stack(addr);
80445+ is_on_stack = object_starts_on_stack(addr);
80446 if (is_on_stack == onstack)
80447 return;
80448
80449diff --git a/lib/devres.c b/lib/devres.c
80450index 8235331..5881053 100644
80451--- a/lib/devres.c
80452+++ b/lib/devres.c
80453@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
80454 void devm_iounmap(struct device *dev, void __iomem *addr)
80455 {
80456 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
80457- (void *)addr));
80458+ (void __force *)addr));
80459 iounmap(addr);
80460 }
80461 EXPORT_SYMBOL(devm_iounmap);
80462@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
80463 {
80464 ioport_unmap(addr);
80465 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
80466- devm_ioport_map_match, (void *)addr));
80467+ devm_ioport_map_match, (void __force *)addr));
80468 }
80469 EXPORT_SYMBOL(devm_ioport_unmap);
80470 #endif /* CONFIG_HAS_IOPORT */
80471diff --git a/lib/div64.c b/lib/div64.c
80472index a163b6c..9618fa5 100644
80473--- a/lib/div64.c
80474+++ b/lib/div64.c
80475@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
80476 EXPORT_SYMBOL(__div64_32);
80477
80478 #ifndef div_s64_rem
80479-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80480+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80481 {
80482 u64 quotient;
80483
80484@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
80485 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
80486 */
80487 #ifndef div64_u64
80488-u64 div64_u64(u64 dividend, u64 divisor)
80489+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80490 {
80491 u32 high = divisor >> 32;
80492 u64 quot;
80493diff --git a/lib/dma-debug.c b/lib/dma-debug.c
80494index d87a17a..ac0d79a 100644
80495--- a/lib/dma-debug.c
80496+++ b/lib/dma-debug.c
80497@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
80498
80499 void dma_debug_add_bus(struct bus_type *bus)
80500 {
80501- struct notifier_block *nb;
80502+ notifier_block_no_const *nb;
80503
80504 if (global_disable)
80505 return;
80506@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
80507
80508 static void check_for_stack(struct device *dev, void *addr)
80509 {
80510- if (object_is_on_stack(addr))
80511+ if (object_starts_on_stack(addr))
80512 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
80513 "stack [addr=%p]\n", addr);
80514 }
80515diff --git a/lib/inflate.c b/lib/inflate.c
80516index 013a761..c28f3fc 100644
80517--- a/lib/inflate.c
80518+++ b/lib/inflate.c
80519@@ -269,7 +269,7 @@ static void free(void *where)
80520 malloc_ptr = free_mem_ptr;
80521 }
80522 #else
80523-#define malloc(a) kmalloc(a, GFP_KERNEL)
80524+#define malloc(a) kmalloc((a), GFP_KERNEL)
80525 #define free(a) kfree(a)
80526 #endif
80527
80528diff --git a/lib/ioremap.c b/lib/ioremap.c
80529index 0c9216c..863bd89 100644
80530--- a/lib/ioremap.c
80531+++ b/lib/ioremap.c
80532@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
80533 unsigned long next;
80534
80535 phys_addr -= addr;
80536- pmd = pmd_alloc(&init_mm, pud, addr);
80537+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
80538 if (!pmd)
80539 return -ENOMEM;
80540 do {
80541@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
80542 unsigned long next;
80543
80544 phys_addr -= addr;
80545- pud = pud_alloc(&init_mm, pgd, addr);
80546+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
80547 if (!pud)
80548 return -ENOMEM;
80549 do {
80550diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
80551index bd2bea9..6b3c95e 100644
80552--- a/lib/is_single_threaded.c
80553+++ b/lib/is_single_threaded.c
80554@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
80555 struct task_struct *p, *t;
80556 bool ret;
80557
80558+ if (!mm)
80559+ return true;
80560+
80561 if (atomic_read(&task->signal->live) != 1)
80562 return false;
80563
80564diff --git a/lib/kobject.c b/lib/kobject.c
80565index a654866..d8bb115 100644
80566--- a/lib/kobject.c
80567+++ b/lib/kobject.c
80568@@ -805,7 +805,7 @@ static struct kset *kset_create(const char *name,
80569 kset = kzalloc(sizeof(*kset), GFP_KERNEL);
80570 if (!kset)
80571 return NULL;
80572- retval = kobject_set_name(&kset->kobj, name);
80573+ retval = kobject_set_name(&kset->kobj, "%s", name);
80574 if (retval) {
80575 kfree(kset);
80576 return NULL;
80577@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
80578
80579
80580 static DEFINE_SPINLOCK(kobj_ns_type_lock);
80581-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
80582+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
80583
80584-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80585+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80586 {
80587 enum kobj_ns_type type = ops->type;
80588 int error;
80589diff --git a/lib/list_debug.c b/lib/list_debug.c
80590index c24c2f7..06e070b 100644
80591--- a/lib/list_debug.c
80592+++ b/lib/list_debug.c
80593@@ -11,7 +11,9 @@
80594 #include <linux/bug.h>
80595 #include <linux/kernel.h>
80596 #include <linux/rculist.h>
80597+#include <linux/mm.h>
80598
80599+#ifdef CONFIG_DEBUG_LIST
80600 /*
80601 * Insert a new entry between two known consecutive entries.
80602 *
80603@@ -19,21 +21,32 @@
80604 * the prev/next entries already!
80605 */
80606
80607-void __list_add(struct list_head *new,
80608- struct list_head *prev,
80609- struct list_head *next)
80610+static bool __list_add_debug(struct list_head *new,
80611+ struct list_head *prev,
80612+ struct list_head *next)
80613 {
80614- WARN(next->prev != prev,
80615+ if (WARN(next->prev != prev,
80616 "list_add corruption. next->prev should be "
80617 "prev (%p), but was %p. (next=%p).\n",
80618- prev, next->prev, next);
80619- WARN(prev->next != next,
80620+ prev, next->prev, next) ||
80621+ WARN(prev->next != next,
80622 "list_add corruption. prev->next should be "
80623 "next (%p), but was %p. (prev=%p).\n",
80624- next, prev->next, prev);
80625- WARN(new == prev || new == next,
80626- "list_add double add: new=%p, prev=%p, next=%p.\n",
80627- new, prev, next);
80628+ next, prev->next, prev) ||
80629+ WARN(new == prev || new == next,
80630+ "list_add double add: new=%p, prev=%p, next=%p.\n",
80631+ new, prev, next))
80632+ return false;
80633+ return true;
80634+}
80635+
80636+void __list_add(struct list_head *new,
80637+ struct list_head *prev,
80638+ struct list_head *next)
80639+{
80640+ if (!__list_add_debug(new, prev, next))
80641+ return;
80642+
80643 next->prev = new;
80644 new->next = next;
80645 new->prev = prev;
80646@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
80647 }
80648 EXPORT_SYMBOL(__list_add);
80649
80650-void __list_del_entry(struct list_head *entry)
80651+static bool __list_del_entry_debug(struct list_head *entry)
80652 {
80653 struct list_head *prev, *next;
80654
80655@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
80656 WARN(next->prev != entry,
80657 "list_del corruption. next->prev should be %p, "
80658 "but was %p\n", entry, next->prev))
80659+ return false;
80660+ return true;
80661+}
80662+
80663+void __list_del_entry(struct list_head *entry)
80664+{
80665+ if (!__list_del_entry_debug(entry))
80666 return;
80667
80668- __list_del(prev, next);
80669+ __list_del(entry->prev, entry->next);
80670 }
80671 EXPORT_SYMBOL(__list_del_entry);
80672
80673@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
80674 void __list_add_rcu(struct list_head *new,
80675 struct list_head *prev, struct list_head *next)
80676 {
80677- WARN(next->prev != prev,
80678- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
80679- prev, next->prev, next);
80680- WARN(prev->next != next,
80681- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
80682- next, prev->next, prev);
80683+ if (!__list_add_debug(new, prev, next))
80684+ return;
80685+
80686 new->next = next;
80687 new->prev = prev;
80688 rcu_assign_pointer(list_next_rcu(prev), new);
80689 next->prev = new;
80690 }
80691 EXPORT_SYMBOL(__list_add_rcu);
80692+#endif
80693+
80694+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
80695+{
80696+#ifdef CONFIG_DEBUG_LIST
80697+ if (!__list_add_debug(new, prev, next))
80698+ return;
80699+#endif
80700+
80701+ pax_open_kernel();
80702+ next->prev = new;
80703+ new->next = next;
80704+ new->prev = prev;
80705+ prev->next = new;
80706+ pax_close_kernel();
80707+}
80708+EXPORT_SYMBOL(__pax_list_add);
80709+
80710+void pax_list_del(struct list_head *entry)
80711+{
80712+#ifdef CONFIG_DEBUG_LIST
80713+ if (!__list_del_entry_debug(entry))
80714+ return;
80715+#endif
80716+
80717+ pax_open_kernel();
80718+ __list_del(entry->prev, entry->next);
80719+ entry->next = LIST_POISON1;
80720+ entry->prev = LIST_POISON2;
80721+ pax_close_kernel();
80722+}
80723+EXPORT_SYMBOL(pax_list_del);
80724+
80725+void pax_list_del_init(struct list_head *entry)
80726+{
80727+ pax_open_kernel();
80728+ __list_del(entry->prev, entry->next);
80729+ INIT_LIST_HEAD(entry);
80730+ pax_close_kernel();
80731+}
80732+EXPORT_SYMBOL(pax_list_del_init);
80733+
80734+void __pax_list_add_rcu(struct list_head *new,
80735+ struct list_head *prev, struct list_head *next)
80736+{
80737+#ifdef CONFIG_DEBUG_LIST
80738+ if (!__list_add_debug(new, prev, next))
80739+ return;
80740+#endif
80741+
80742+ pax_open_kernel();
80743+ new->next = next;
80744+ new->prev = prev;
80745+ rcu_assign_pointer(list_next_rcu(prev), new);
80746+ next->prev = new;
80747+ pax_close_kernel();
80748+}
80749+EXPORT_SYMBOL(__pax_list_add_rcu);
80750+
80751+void pax_list_del_rcu(struct list_head *entry)
80752+{
80753+#ifdef CONFIG_DEBUG_LIST
80754+ if (!__list_del_entry_debug(entry))
80755+ return;
80756+#endif
80757+
80758+ pax_open_kernel();
80759+ __list_del(entry->prev, entry->next);
80760+ entry->next = LIST_POISON1;
80761+ entry->prev = LIST_POISON2;
80762+ pax_close_kernel();
80763+}
80764+EXPORT_SYMBOL(pax_list_del_rcu);
80765diff --git a/lib/radix-tree.c b/lib/radix-tree.c
80766index e796429..6e38f9f 100644
80767--- a/lib/radix-tree.c
80768+++ b/lib/radix-tree.c
80769@@ -92,7 +92,7 @@ struct radix_tree_preload {
80770 int nr;
80771 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
80772 };
80773-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
80774+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
80775
80776 static inline void *ptr_to_indirect(void *ptr)
80777 {
80778diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
80779index bb2b201..46abaf9 100644
80780--- a/lib/strncpy_from_user.c
80781+++ b/lib/strncpy_from_user.c
80782@@ -21,7 +21,7 @@
80783 */
80784 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
80785 {
80786- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80787+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80788 long res = 0;
80789
80790 /*
80791diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
80792index a28df52..3d55877 100644
80793--- a/lib/strnlen_user.c
80794+++ b/lib/strnlen_user.c
80795@@ -26,7 +26,7 @@
80796 */
80797 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
80798 {
80799- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80800+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80801 long align, res = 0;
80802 unsigned long c;
80803
80804diff --git a/lib/swiotlb.c b/lib/swiotlb.c
80805index d23762e..e21eab2 100644
80806--- a/lib/swiotlb.c
80807+++ b/lib/swiotlb.c
80808@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
80809
80810 void
80811 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
80812- dma_addr_t dev_addr)
80813+ dma_addr_t dev_addr, struct dma_attrs *attrs)
80814 {
80815 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
80816
80817diff --git a/lib/vsprintf.c b/lib/vsprintf.c
80818index 0d62fd7..b7bc911 100644
80819--- a/lib/vsprintf.c
80820+++ b/lib/vsprintf.c
80821@@ -16,6 +16,9 @@
80822 * - scnprintf and vscnprintf
80823 */
80824
80825+#ifdef CONFIG_GRKERNSEC_HIDESYM
80826+#define __INCLUDED_BY_HIDESYM 1
80827+#endif
80828 #include <stdarg.h>
80829 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
80830 #include <linux/types.h>
80831@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
80832 return number(buf, end, *(const netdev_features_t *)addr, spec);
80833 }
80834
80835+#ifdef CONFIG_GRKERNSEC_HIDESYM
80836+int kptr_restrict __read_mostly = 2;
80837+#else
80838 int kptr_restrict __read_mostly;
80839+#endif
80840
80841 /*
80842 * Show a '%p' thing. A kernel extension is that the '%p' is followed
80843@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
80844 * - 'S' For symbolic direct pointers with offset
80845 * - 's' For symbolic direct pointers without offset
80846 * - 'B' For backtraced symbolic direct pointers with offset
80847+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
80848+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
80849 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
80850 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
80851 * - 'M' For a 6-byte MAC address, it prints the address in the
80852@@ -1044,12 +1053,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80853
80854 if (!ptr && *fmt != 'K') {
80855 /*
80856- * Print (null) with the same width as a pointer so it makes
80857+ * Print (nil) with the same width as a pointer so it makes
80858 * tabular output look nice.
80859 */
80860 if (spec.field_width == -1)
80861 spec.field_width = default_width;
80862- return string(buf, end, "(null)", spec);
80863+ return string(buf, end, "(nil)", spec);
80864 }
80865
80866 switch (*fmt) {
80867@@ -1059,6 +1068,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80868 /* Fallthrough */
80869 case 'S':
80870 case 's':
80871+#ifdef CONFIG_GRKERNSEC_HIDESYM
80872+ break;
80873+#else
80874+ return symbol_string(buf, end, ptr, spec, *fmt);
80875+#endif
80876+ case 'A':
80877 case 'B':
80878 return symbol_string(buf, end, ptr, spec, *fmt);
80879 case 'R':
80880@@ -1099,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80881 va_end(va);
80882 return buf;
80883 }
80884+ case 'P':
80885+ break;
80886 case 'K':
80887 /*
80888 * %pK cannot be used in IRQ context because its test
80889@@ -1128,6 +1145,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80890 return number(buf, end,
80891 (unsigned long long) *((phys_addr_t *)ptr), spec);
80892 }
80893+
80894+#ifdef CONFIG_GRKERNSEC_HIDESYM
80895+ /* 'P' = approved pointers to copy to userland,
80896+ as in the /proc/kallsyms case, as we make it display nothing
80897+ for non-root users, and the real contents for root users
80898+ Also ignore 'K' pointers, since we force their NULLing for non-root users
80899+ above
80900+ */
80901+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
80902+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
80903+ dump_stack();
80904+ ptr = NULL;
80905+ }
80906+#endif
80907+
80908 spec.flags |= SMALL;
80909 if (spec.field_width == -1) {
80910 spec.field_width = default_width;
80911@@ -1849,11 +1881,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80912 typeof(type) value; \
80913 if (sizeof(type) == 8) { \
80914 args = PTR_ALIGN(args, sizeof(u32)); \
80915- *(u32 *)&value = *(u32 *)args; \
80916- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
80917+ *(u32 *)&value = *(const u32 *)args; \
80918+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
80919 } else { \
80920 args = PTR_ALIGN(args, sizeof(type)); \
80921- value = *(typeof(type) *)args; \
80922+ value = *(const typeof(type) *)args; \
80923 } \
80924 args += sizeof(type); \
80925 value; \
80926@@ -1916,7 +1948,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80927 case FORMAT_TYPE_STR: {
80928 const char *str_arg = args;
80929 args += strlen(str_arg) + 1;
80930- str = string(str, end, (char *)str_arg, spec);
80931+ str = string(str, end, str_arg, spec);
80932 break;
80933 }
80934
80935diff --git a/localversion-grsec b/localversion-grsec
80936new file mode 100644
80937index 0000000..7cd6065
80938--- /dev/null
80939+++ b/localversion-grsec
80940@@ -0,0 +1 @@
80941+-grsec
80942diff --git a/mm/Kconfig b/mm/Kconfig
80943index 3bea74f..e821c99 100644
80944--- a/mm/Kconfig
80945+++ b/mm/Kconfig
80946@@ -311,10 +311,10 @@ config KSM
80947 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
80948
80949 config DEFAULT_MMAP_MIN_ADDR
80950- int "Low address space to protect from user allocation"
80951+ int "Low address space to protect from user allocation"
80952 depends on MMU
80953- default 4096
80954- help
80955+ default 65536
80956+ help
80957 This is the portion of low virtual memory which should be protected
80958 from userspace allocation. Keeping a user from writing to low pages
80959 can help reduce the impact of kernel NULL pointer bugs.
80960@@ -345,7 +345,7 @@ config MEMORY_FAILURE
80961
80962 config HWPOISON_INJECT
80963 tristate "HWPoison pages injector"
80964- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
80965+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
80966 select PROC_PAGE_MONITOR
80967
80968 config NOMMU_INITIAL_TRIM_EXCESS
80969diff --git a/mm/backing-dev.c b/mm/backing-dev.c
80970index 41733c5..d80d7a9 100644
80971--- a/mm/backing-dev.c
80972+++ b/mm/backing-dev.c
80973@@ -716,7 +716,6 @@ EXPORT_SYMBOL(bdi_destroy);
80974 int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
80975 unsigned int cap)
80976 {
80977- char tmp[32];
80978 int err;
80979
80980 bdi->name = name;
80981@@ -725,8 +724,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
80982 if (err)
80983 return err;
80984
80985- sprintf(tmp, "%.28s%s", name, "-%d");
80986- err = bdi_register(bdi, NULL, tmp, atomic_long_inc_return(&bdi_seq));
80987+ err = bdi_register(bdi, NULL, "%.28s-%ld", name, atomic_long_inc_return(&bdi_seq));
80988 if (err) {
80989 bdi_destroy(bdi);
80990 return err;
80991diff --git a/mm/filemap.c b/mm/filemap.c
80992index e1979fd..dda5120 100644
80993--- a/mm/filemap.c
80994+++ b/mm/filemap.c
80995@@ -1748,7 +1748,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
80996 struct address_space *mapping = file->f_mapping;
80997
80998 if (!mapping->a_ops->readpage)
80999- return -ENOEXEC;
81000+ return -ENODEV;
81001 file_accessed(file);
81002 vma->vm_ops = &generic_file_vm_ops;
81003 return 0;
81004@@ -2088,6 +2088,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
81005 *pos = i_size_read(inode);
81006
81007 if (limit != RLIM_INFINITY) {
81008+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
81009 if (*pos >= limit) {
81010 send_sig(SIGXFSZ, current, 0);
81011 return -EFBIG;
81012diff --git a/mm/fremap.c b/mm/fremap.c
81013index 87da359..3f41cb1 100644
81014--- a/mm/fremap.c
81015+++ b/mm/fremap.c
81016@@ -158,6 +158,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
81017 retry:
81018 vma = find_vma(mm, start);
81019
81020+#ifdef CONFIG_PAX_SEGMEXEC
81021+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
81022+ goto out;
81023+#endif
81024+
81025 /*
81026 * Make sure the vma is shared, that it supports prefaulting,
81027 * and that the remapped range is valid and fully within
81028diff --git a/mm/highmem.c b/mm/highmem.c
81029index b32b70c..e512eb0 100644
81030--- a/mm/highmem.c
81031+++ b/mm/highmem.c
81032@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
81033 * So no dangers, even with speculative execution.
81034 */
81035 page = pte_page(pkmap_page_table[i]);
81036+ pax_open_kernel();
81037 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
81038-
81039+ pax_close_kernel();
81040 set_page_address(page, NULL);
81041 need_flush = 1;
81042 }
81043@@ -198,9 +199,11 @@ start:
81044 }
81045 }
81046 vaddr = PKMAP_ADDR(last_pkmap_nr);
81047+
81048+ pax_open_kernel();
81049 set_pte_at(&init_mm, vaddr,
81050 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
81051-
81052+ pax_close_kernel();
81053 pkmap_count[last_pkmap_nr] = 1;
81054 set_page_address(page, (void *)vaddr);
81055
81056diff --git a/mm/hugetlb.c b/mm/hugetlb.c
81057index ce4cb19..93899ef 100644
81058--- a/mm/hugetlb.c
81059+++ b/mm/hugetlb.c
81060@@ -2005,15 +2005,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
81061 struct hstate *h = &default_hstate;
81062 unsigned long tmp;
81063 int ret;
81064+ ctl_table_no_const hugetlb_table;
81065
81066 tmp = h->max_huge_pages;
81067
81068 if (write && h->order >= MAX_ORDER)
81069 return -EINVAL;
81070
81071- table->data = &tmp;
81072- table->maxlen = sizeof(unsigned long);
81073- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
81074+ hugetlb_table = *table;
81075+ hugetlb_table.data = &tmp;
81076+ hugetlb_table.maxlen = sizeof(unsigned long);
81077+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
81078 if (ret)
81079 goto out;
81080
81081@@ -2070,15 +2072,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
81082 struct hstate *h = &default_hstate;
81083 unsigned long tmp;
81084 int ret;
81085+ ctl_table_no_const hugetlb_table;
81086
81087 tmp = h->nr_overcommit_huge_pages;
81088
81089 if (write && h->order >= MAX_ORDER)
81090 return -EINVAL;
81091
81092- table->data = &tmp;
81093- table->maxlen = sizeof(unsigned long);
81094- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
81095+ hugetlb_table = *table;
81096+ hugetlb_table.data = &tmp;
81097+ hugetlb_table.maxlen = sizeof(unsigned long);
81098+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
81099 if (ret)
81100 goto out;
81101
81102@@ -2512,6 +2516,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
81103 return 1;
81104 }
81105
81106+#ifdef CONFIG_PAX_SEGMEXEC
81107+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
81108+{
81109+ struct mm_struct *mm = vma->vm_mm;
81110+ struct vm_area_struct *vma_m;
81111+ unsigned long address_m;
81112+ pte_t *ptep_m;
81113+
81114+ vma_m = pax_find_mirror_vma(vma);
81115+ if (!vma_m)
81116+ return;
81117+
81118+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81119+ address_m = address + SEGMEXEC_TASK_SIZE;
81120+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
81121+ get_page(page_m);
81122+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
81123+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
81124+}
81125+#endif
81126+
81127 /*
81128 * Hugetlb_cow() should be called with page lock of the original hugepage held.
81129 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
81130@@ -2630,6 +2655,11 @@ retry_avoidcopy:
81131 make_huge_pte(vma, new_page, 1));
81132 page_remove_rmap(old_page);
81133 hugepage_add_new_anon_rmap(new_page, vma, address);
81134+
81135+#ifdef CONFIG_PAX_SEGMEXEC
81136+ pax_mirror_huge_pte(vma, address, new_page);
81137+#endif
81138+
81139 /* Make the old page be freed below */
81140 new_page = old_page;
81141 }
81142@@ -2788,6 +2818,10 @@ retry:
81143 && (vma->vm_flags & VM_SHARED)));
81144 set_huge_pte_at(mm, address, ptep, new_pte);
81145
81146+#ifdef CONFIG_PAX_SEGMEXEC
81147+ pax_mirror_huge_pte(vma, address, page);
81148+#endif
81149+
81150 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
81151 /* Optimization, do the COW without a second fault */
81152 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
81153@@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81154 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
81155 struct hstate *h = hstate_vma(vma);
81156
81157+#ifdef CONFIG_PAX_SEGMEXEC
81158+ struct vm_area_struct *vma_m;
81159+#endif
81160+
81161 address &= huge_page_mask(h);
81162
81163 ptep = huge_pte_offset(mm, address);
81164@@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81165 VM_FAULT_SET_HINDEX(hstate_index(h));
81166 }
81167
81168+#ifdef CONFIG_PAX_SEGMEXEC
81169+ vma_m = pax_find_mirror_vma(vma);
81170+ if (vma_m) {
81171+ unsigned long address_m;
81172+
81173+ if (vma->vm_start > vma_m->vm_start) {
81174+ address_m = address;
81175+ address -= SEGMEXEC_TASK_SIZE;
81176+ vma = vma_m;
81177+ h = hstate_vma(vma);
81178+ } else
81179+ address_m = address + SEGMEXEC_TASK_SIZE;
81180+
81181+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
81182+ return VM_FAULT_OOM;
81183+ address_m &= HPAGE_MASK;
81184+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
81185+ }
81186+#endif
81187+
81188 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
81189 if (!ptep)
81190 return VM_FAULT_OOM;
81191diff --git a/mm/internal.h b/mm/internal.h
81192index 8562de0..7fdfe92 100644
81193--- a/mm/internal.h
81194+++ b/mm/internal.h
81195@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
81196 * in mm/page_alloc.c
81197 */
81198 extern void __free_pages_bootmem(struct page *page, unsigned int order);
81199+extern void free_compound_page(struct page *page);
81200 extern void prep_compound_page(struct page *page, unsigned long order);
81201 #ifdef CONFIG_MEMORY_FAILURE
81202 extern bool is_free_buddy_page(struct page *page);
81203diff --git a/mm/kmemleak.c b/mm/kmemleak.c
81204index c8d7f31..2dbeffd 100644
81205--- a/mm/kmemleak.c
81206+++ b/mm/kmemleak.c
81207@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
81208
81209 for (i = 0; i < object->trace_len; i++) {
81210 void *ptr = (void *)object->trace[i];
81211- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
81212+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
81213 }
81214 }
81215
81216@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
81217 return -ENOMEM;
81218 }
81219
81220- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
81221+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
81222 &kmemleak_fops);
81223 if (!dentry)
81224 pr_warning("Failed to create the debugfs kmemleak file\n");
81225diff --git a/mm/maccess.c b/mm/maccess.c
81226index d53adf9..03a24bf 100644
81227--- a/mm/maccess.c
81228+++ b/mm/maccess.c
81229@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
81230 set_fs(KERNEL_DS);
81231 pagefault_disable();
81232 ret = __copy_from_user_inatomic(dst,
81233- (__force const void __user *)src, size);
81234+ (const void __force_user *)src, size);
81235 pagefault_enable();
81236 set_fs(old_fs);
81237
81238@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
81239
81240 set_fs(KERNEL_DS);
81241 pagefault_disable();
81242- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
81243+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
81244 pagefault_enable();
81245 set_fs(old_fs);
81246
81247diff --git a/mm/madvise.c b/mm/madvise.c
81248index c58c94b..86ec14e 100644
81249--- a/mm/madvise.c
81250+++ b/mm/madvise.c
81251@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
81252 pgoff_t pgoff;
81253 unsigned long new_flags = vma->vm_flags;
81254
81255+#ifdef CONFIG_PAX_SEGMEXEC
81256+ struct vm_area_struct *vma_m;
81257+#endif
81258+
81259 switch (behavior) {
81260 case MADV_NORMAL:
81261 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
81262@@ -126,6 +130,13 @@ success:
81263 /*
81264 * vm_flags is protected by the mmap_sem held in write mode.
81265 */
81266+
81267+#ifdef CONFIG_PAX_SEGMEXEC
81268+ vma_m = pax_find_mirror_vma(vma);
81269+ if (vma_m)
81270+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
81271+#endif
81272+
81273 vma->vm_flags = new_flags;
81274
81275 out:
81276@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81277 struct vm_area_struct ** prev,
81278 unsigned long start, unsigned long end)
81279 {
81280+
81281+#ifdef CONFIG_PAX_SEGMEXEC
81282+ struct vm_area_struct *vma_m;
81283+#endif
81284+
81285 *prev = vma;
81286 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
81287 return -EINVAL;
81288@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81289 zap_page_range(vma, start, end - start, &details);
81290 } else
81291 zap_page_range(vma, start, end - start, NULL);
81292+
81293+#ifdef CONFIG_PAX_SEGMEXEC
81294+ vma_m = pax_find_mirror_vma(vma);
81295+ if (vma_m) {
81296+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
81297+ struct zap_details details = {
81298+ .nonlinear_vma = vma_m,
81299+ .last_index = ULONG_MAX,
81300+ };
81301+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
81302+ } else
81303+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
81304+ }
81305+#endif
81306+
81307 return 0;
81308 }
81309
81310@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
81311 if (end < start)
81312 goto out;
81313
81314+#ifdef CONFIG_PAX_SEGMEXEC
81315+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81316+ if (end > SEGMEXEC_TASK_SIZE)
81317+ goto out;
81318+ } else
81319+#endif
81320+
81321+ if (end > TASK_SIZE)
81322+ goto out;
81323+
81324 error = 0;
81325 if (end == start)
81326 goto out;
81327diff --git a/mm/memory-failure.c b/mm/memory-failure.c
81328index df0694c..bc95539 100644
81329--- a/mm/memory-failure.c
81330+++ b/mm/memory-failure.c
81331@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
81332
81333 int sysctl_memory_failure_recovery __read_mostly = 1;
81334
81335-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
81336+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
81337
81338 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
81339
81340@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
81341 pfn, t->comm, t->pid);
81342 si.si_signo = SIGBUS;
81343 si.si_errno = 0;
81344- si.si_addr = (void *)addr;
81345+ si.si_addr = (void __user *)addr;
81346 #ifdef __ARCH_SI_TRAPNO
81347 si.si_trapno = trapno;
81348 #endif
81349@@ -760,7 +760,7 @@ static struct page_state {
81350 unsigned long res;
81351 char *msg;
81352 int (*action)(struct page *p, unsigned long pfn);
81353-} error_states[] = {
81354+} __do_const error_states[] = {
81355 { reserved, reserved, "reserved kernel", me_kernel },
81356 /*
81357 * free pages are specially detected outside this table:
81358@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81359 nr_pages = 1 << compound_order(hpage);
81360 else /* normal page or thp */
81361 nr_pages = 1;
81362- atomic_long_add(nr_pages, &num_poisoned_pages);
81363+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
81364
81365 /*
81366 * We need/can do nothing about count=0 pages.
81367@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81368 if (!PageHWPoison(hpage)
81369 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
81370 || (p != hpage && TestSetPageHWPoison(hpage))) {
81371- atomic_long_sub(nr_pages, &num_poisoned_pages);
81372+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81373 return 0;
81374 }
81375 set_page_hwpoison_huge_page(hpage);
81376@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81377 }
81378 if (hwpoison_filter(p)) {
81379 if (TestClearPageHWPoison(p))
81380- atomic_long_sub(nr_pages, &num_poisoned_pages);
81381+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81382 unlock_page(hpage);
81383 put_page(hpage);
81384 return 0;
81385@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
81386 return 0;
81387 }
81388 if (TestClearPageHWPoison(p))
81389- atomic_long_sub(nr_pages, &num_poisoned_pages);
81390+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81391 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
81392 return 0;
81393 }
81394@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
81395 */
81396 if (TestClearPageHWPoison(page)) {
81397 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
81398- atomic_long_sub(nr_pages, &num_poisoned_pages);
81399+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81400 freeit = 1;
81401 if (PageHuge(page))
81402 clear_page_hwpoison_huge_page(page);
81403@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
81404 } else {
81405 set_page_hwpoison_huge_page(hpage);
81406 dequeue_hwpoisoned_huge_page(hpage);
81407- atomic_long_add(1 << compound_trans_order(hpage),
81408+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81409 &num_poisoned_pages);
81410 }
81411 /* keep elevated page count for bad page */
81412@@ -1552,11 +1552,11 @@ int soft_offline_page(struct page *page, int flags)
81413 if (PageHuge(page)) {
81414 set_page_hwpoison_huge_page(hpage);
81415 dequeue_hwpoisoned_huge_page(hpage);
81416- atomic_long_add(1 << compound_trans_order(hpage),
81417+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81418 &num_poisoned_pages);
81419 } else {
81420 SetPageHWPoison(page);
81421- atomic_long_inc(&num_poisoned_pages);
81422+ atomic_long_inc_unchecked(&num_poisoned_pages);
81423 }
81424 }
81425 /* keep elevated page count for bad page */
81426@@ -1596,7 +1596,7 @@ static int __soft_offline_page(struct page *page, int flags)
81427 put_page(page);
81428 pr_info("soft_offline: %#lx: invalidated\n", pfn);
81429 SetPageHWPoison(page);
81430- atomic_long_inc(&num_poisoned_pages);
81431+ atomic_long_inc_unchecked(&num_poisoned_pages);
81432 return 0;
81433 }
81434
81435@@ -1626,7 +1626,7 @@ static int __soft_offline_page(struct page *page, int flags)
81436 ret = -EIO;
81437 } else {
81438 SetPageHWPoison(page);
81439- atomic_long_inc(&num_poisoned_pages);
81440+ atomic_long_inc_unchecked(&num_poisoned_pages);
81441 }
81442 } else {
81443 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
81444diff --git a/mm/memory.c b/mm/memory.c
81445index ba94dec..08ffe0d 100644
81446--- a/mm/memory.c
81447+++ b/mm/memory.c
81448@@ -438,6 +438,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81449 free_pte_range(tlb, pmd, addr);
81450 } while (pmd++, addr = next, addr != end);
81451
81452+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
81453 start &= PUD_MASK;
81454 if (start < floor)
81455 return;
81456@@ -452,6 +453,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81457 pmd = pmd_offset(pud, start);
81458 pud_clear(pud);
81459 pmd_free_tlb(tlb, pmd, start);
81460+#endif
81461+
81462 }
81463
81464 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81465@@ -471,6 +474,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81466 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
81467 } while (pud++, addr = next, addr != end);
81468
81469+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
81470 start &= PGDIR_MASK;
81471 if (start < floor)
81472 return;
81473@@ -485,6 +489,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81474 pud = pud_offset(pgd, start);
81475 pgd_clear(pgd);
81476 pud_free_tlb(tlb, pud, start);
81477+#endif
81478+
81479 }
81480
81481 /*
81482@@ -1644,12 +1650,6 @@ no_page_table:
81483 return page;
81484 }
81485
81486-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
81487-{
81488- return stack_guard_page_start(vma, addr) ||
81489- stack_guard_page_end(vma, addr+PAGE_SIZE);
81490-}
81491-
81492 /**
81493 * __get_user_pages() - pin user pages in memory
81494 * @tsk: task_struct of target task
81495@@ -1736,10 +1736,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81496
81497 i = 0;
81498
81499- do {
81500+ while (nr_pages) {
81501 struct vm_area_struct *vma;
81502
81503- vma = find_extend_vma(mm, start);
81504+ vma = find_vma(mm, start);
81505 if (!vma && in_gate_area(mm, start)) {
81506 unsigned long pg = start & PAGE_MASK;
81507 pgd_t *pgd;
81508@@ -1788,7 +1788,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81509 goto next_page;
81510 }
81511
81512- if (!vma ||
81513+ if (!vma || start < vma->vm_start ||
81514 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
81515 !(vm_flags & vma->vm_flags))
81516 return i ? : -EFAULT;
81517@@ -1817,11 +1817,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81518 int ret;
81519 unsigned int fault_flags = 0;
81520
81521- /* For mlock, just skip the stack guard page. */
81522- if (foll_flags & FOLL_MLOCK) {
81523- if (stack_guard_page(vma, start))
81524- goto next_page;
81525- }
81526 if (foll_flags & FOLL_WRITE)
81527 fault_flags |= FAULT_FLAG_WRITE;
81528 if (nonblocking)
81529@@ -1901,7 +1896,7 @@ next_page:
81530 start += page_increm * PAGE_SIZE;
81531 nr_pages -= page_increm;
81532 } while (nr_pages && start < vma->vm_end);
81533- } while (nr_pages);
81534+ }
81535 return i;
81536 }
81537 EXPORT_SYMBOL(__get_user_pages);
81538@@ -2108,6 +2103,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
81539 page_add_file_rmap(page);
81540 set_pte_at(mm, addr, pte, mk_pte(page, prot));
81541
81542+#ifdef CONFIG_PAX_SEGMEXEC
81543+ pax_mirror_file_pte(vma, addr, page, ptl);
81544+#endif
81545+
81546 retval = 0;
81547 pte_unmap_unlock(pte, ptl);
81548 return retval;
81549@@ -2152,9 +2151,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
81550 if (!page_count(page))
81551 return -EINVAL;
81552 if (!(vma->vm_flags & VM_MIXEDMAP)) {
81553+
81554+#ifdef CONFIG_PAX_SEGMEXEC
81555+ struct vm_area_struct *vma_m;
81556+#endif
81557+
81558 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
81559 BUG_ON(vma->vm_flags & VM_PFNMAP);
81560 vma->vm_flags |= VM_MIXEDMAP;
81561+
81562+#ifdef CONFIG_PAX_SEGMEXEC
81563+ vma_m = pax_find_mirror_vma(vma);
81564+ if (vma_m)
81565+ vma_m->vm_flags |= VM_MIXEDMAP;
81566+#endif
81567+
81568 }
81569 return insert_page(vma, addr, page, vma->vm_page_prot);
81570 }
81571@@ -2237,6 +2248,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
81572 unsigned long pfn)
81573 {
81574 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
81575+ BUG_ON(vma->vm_mirror);
81576
81577 if (addr < vma->vm_start || addr >= vma->vm_end)
81578 return -EFAULT;
81579@@ -2484,7 +2496,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
81580
81581 BUG_ON(pud_huge(*pud));
81582
81583- pmd = pmd_alloc(mm, pud, addr);
81584+ pmd = (mm == &init_mm) ?
81585+ pmd_alloc_kernel(mm, pud, addr) :
81586+ pmd_alloc(mm, pud, addr);
81587 if (!pmd)
81588 return -ENOMEM;
81589 do {
81590@@ -2504,7 +2518,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
81591 unsigned long next;
81592 int err;
81593
81594- pud = pud_alloc(mm, pgd, addr);
81595+ pud = (mm == &init_mm) ?
81596+ pud_alloc_kernel(mm, pgd, addr) :
81597+ pud_alloc(mm, pgd, addr);
81598 if (!pud)
81599 return -ENOMEM;
81600 do {
81601@@ -2592,6 +2608,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
81602 copy_user_highpage(dst, src, va, vma);
81603 }
81604
81605+#ifdef CONFIG_PAX_SEGMEXEC
81606+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
81607+{
81608+ struct mm_struct *mm = vma->vm_mm;
81609+ spinlock_t *ptl;
81610+ pte_t *pte, entry;
81611+
81612+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
81613+ entry = *pte;
81614+ if (!pte_present(entry)) {
81615+ if (!pte_none(entry)) {
81616+ BUG_ON(pte_file(entry));
81617+ free_swap_and_cache(pte_to_swp_entry(entry));
81618+ pte_clear_not_present_full(mm, address, pte, 0);
81619+ }
81620+ } else {
81621+ struct page *page;
81622+
81623+ flush_cache_page(vma, address, pte_pfn(entry));
81624+ entry = ptep_clear_flush(vma, address, pte);
81625+ BUG_ON(pte_dirty(entry));
81626+ page = vm_normal_page(vma, address, entry);
81627+ if (page) {
81628+ update_hiwater_rss(mm);
81629+ if (PageAnon(page))
81630+ dec_mm_counter_fast(mm, MM_ANONPAGES);
81631+ else
81632+ dec_mm_counter_fast(mm, MM_FILEPAGES);
81633+ page_remove_rmap(page);
81634+ page_cache_release(page);
81635+ }
81636+ }
81637+ pte_unmap_unlock(pte, ptl);
81638+}
81639+
81640+/* PaX: if vma is mirrored, synchronize the mirror's PTE
81641+ *
81642+ * the ptl of the lower mapped page is held on entry and is not released on exit
81643+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
81644+ */
81645+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81646+{
81647+ struct mm_struct *mm = vma->vm_mm;
81648+ unsigned long address_m;
81649+ spinlock_t *ptl_m;
81650+ struct vm_area_struct *vma_m;
81651+ pmd_t *pmd_m;
81652+ pte_t *pte_m, entry_m;
81653+
81654+ BUG_ON(!page_m || !PageAnon(page_m));
81655+
81656+ vma_m = pax_find_mirror_vma(vma);
81657+ if (!vma_m)
81658+ return;
81659+
81660+ BUG_ON(!PageLocked(page_m));
81661+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81662+ address_m = address + SEGMEXEC_TASK_SIZE;
81663+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81664+ pte_m = pte_offset_map(pmd_m, address_m);
81665+ ptl_m = pte_lockptr(mm, pmd_m);
81666+ if (ptl != ptl_m) {
81667+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81668+ if (!pte_none(*pte_m))
81669+ goto out;
81670+ }
81671+
81672+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81673+ page_cache_get(page_m);
81674+ page_add_anon_rmap(page_m, vma_m, address_m);
81675+ inc_mm_counter_fast(mm, MM_ANONPAGES);
81676+ set_pte_at(mm, address_m, pte_m, entry_m);
81677+ update_mmu_cache(vma_m, address_m, pte_m);
81678+out:
81679+ if (ptl != ptl_m)
81680+ spin_unlock(ptl_m);
81681+ pte_unmap(pte_m);
81682+ unlock_page(page_m);
81683+}
81684+
81685+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81686+{
81687+ struct mm_struct *mm = vma->vm_mm;
81688+ unsigned long address_m;
81689+ spinlock_t *ptl_m;
81690+ struct vm_area_struct *vma_m;
81691+ pmd_t *pmd_m;
81692+ pte_t *pte_m, entry_m;
81693+
81694+ BUG_ON(!page_m || PageAnon(page_m));
81695+
81696+ vma_m = pax_find_mirror_vma(vma);
81697+ if (!vma_m)
81698+ return;
81699+
81700+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81701+ address_m = address + SEGMEXEC_TASK_SIZE;
81702+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81703+ pte_m = pte_offset_map(pmd_m, address_m);
81704+ ptl_m = pte_lockptr(mm, pmd_m);
81705+ if (ptl != ptl_m) {
81706+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81707+ if (!pte_none(*pte_m))
81708+ goto out;
81709+ }
81710+
81711+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81712+ page_cache_get(page_m);
81713+ page_add_file_rmap(page_m);
81714+ inc_mm_counter_fast(mm, MM_FILEPAGES);
81715+ set_pte_at(mm, address_m, pte_m, entry_m);
81716+ update_mmu_cache(vma_m, address_m, pte_m);
81717+out:
81718+ if (ptl != ptl_m)
81719+ spin_unlock(ptl_m);
81720+ pte_unmap(pte_m);
81721+}
81722+
81723+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
81724+{
81725+ struct mm_struct *mm = vma->vm_mm;
81726+ unsigned long address_m;
81727+ spinlock_t *ptl_m;
81728+ struct vm_area_struct *vma_m;
81729+ pmd_t *pmd_m;
81730+ pte_t *pte_m, entry_m;
81731+
81732+ vma_m = pax_find_mirror_vma(vma);
81733+ if (!vma_m)
81734+ return;
81735+
81736+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81737+ address_m = address + SEGMEXEC_TASK_SIZE;
81738+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81739+ pte_m = pte_offset_map(pmd_m, address_m);
81740+ ptl_m = pte_lockptr(mm, pmd_m);
81741+ if (ptl != ptl_m) {
81742+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81743+ if (!pte_none(*pte_m))
81744+ goto out;
81745+ }
81746+
81747+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
81748+ set_pte_at(mm, address_m, pte_m, entry_m);
81749+out:
81750+ if (ptl != ptl_m)
81751+ spin_unlock(ptl_m);
81752+ pte_unmap(pte_m);
81753+}
81754+
81755+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
81756+{
81757+ struct page *page_m;
81758+ pte_t entry;
81759+
81760+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
81761+ goto out;
81762+
81763+ entry = *pte;
81764+ page_m = vm_normal_page(vma, address, entry);
81765+ if (!page_m)
81766+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
81767+ else if (PageAnon(page_m)) {
81768+ if (pax_find_mirror_vma(vma)) {
81769+ pte_unmap_unlock(pte, ptl);
81770+ lock_page(page_m);
81771+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
81772+ if (pte_same(entry, *pte))
81773+ pax_mirror_anon_pte(vma, address, page_m, ptl);
81774+ else
81775+ unlock_page(page_m);
81776+ }
81777+ } else
81778+ pax_mirror_file_pte(vma, address, page_m, ptl);
81779+
81780+out:
81781+ pte_unmap_unlock(pte, ptl);
81782+}
81783+#endif
81784+
81785 /*
81786 * This routine handles present pages, when users try to write
81787 * to a shared page. It is done by copying the page to a new address
81788@@ -2808,6 +3004,12 @@ gotten:
81789 */
81790 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81791 if (likely(pte_same(*page_table, orig_pte))) {
81792+
81793+#ifdef CONFIG_PAX_SEGMEXEC
81794+ if (pax_find_mirror_vma(vma))
81795+ BUG_ON(!trylock_page(new_page));
81796+#endif
81797+
81798 if (old_page) {
81799 if (!PageAnon(old_page)) {
81800 dec_mm_counter_fast(mm, MM_FILEPAGES);
81801@@ -2859,6 +3061,10 @@ gotten:
81802 page_remove_rmap(old_page);
81803 }
81804
81805+#ifdef CONFIG_PAX_SEGMEXEC
81806+ pax_mirror_anon_pte(vma, address, new_page, ptl);
81807+#endif
81808+
81809 /* Free the old page.. */
81810 new_page = old_page;
81811 ret |= VM_FAULT_WRITE;
81812@@ -3134,6 +3340,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81813 swap_free(entry);
81814 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
81815 try_to_free_swap(page);
81816+
81817+#ifdef CONFIG_PAX_SEGMEXEC
81818+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
81819+#endif
81820+
81821 unlock_page(page);
81822 if (page != swapcache) {
81823 /*
81824@@ -3157,6 +3368,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81825
81826 /* No need to invalidate - it was non-present before */
81827 update_mmu_cache(vma, address, page_table);
81828+
81829+#ifdef CONFIG_PAX_SEGMEXEC
81830+ pax_mirror_anon_pte(vma, address, page, ptl);
81831+#endif
81832+
81833 unlock:
81834 pte_unmap_unlock(page_table, ptl);
81835 out:
81836@@ -3176,40 +3392,6 @@ out_release:
81837 }
81838
81839 /*
81840- * This is like a special single-page "expand_{down|up}wards()",
81841- * except we must first make sure that 'address{-|+}PAGE_SIZE'
81842- * doesn't hit another vma.
81843- */
81844-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
81845-{
81846- address &= PAGE_MASK;
81847- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
81848- struct vm_area_struct *prev = vma->vm_prev;
81849-
81850- /*
81851- * Is there a mapping abutting this one below?
81852- *
81853- * That's only ok if it's the same stack mapping
81854- * that has gotten split..
81855- */
81856- if (prev && prev->vm_end == address)
81857- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
81858-
81859- expand_downwards(vma, address - PAGE_SIZE);
81860- }
81861- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
81862- struct vm_area_struct *next = vma->vm_next;
81863-
81864- /* As VM_GROWSDOWN but s/below/above/ */
81865- if (next && next->vm_start == address + PAGE_SIZE)
81866- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
81867-
81868- expand_upwards(vma, address + PAGE_SIZE);
81869- }
81870- return 0;
81871-}
81872-
81873-/*
81874 * We enter with non-exclusive mmap_sem (to exclude vma changes,
81875 * but allow concurrent faults), and pte mapped but not yet locked.
81876 * We return with mmap_sem still held, but pte unmapped and unlocked.
81877@@ -3218,27 +3400,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81878 unsigned long address, pte_t *page_table, pmd_t *pmd,
81879 unsigned int flags)
81880 {
81881- struct page *page;
81882+ struct page *page = NULL;
81883 spinlock_t *ptl;
81884 pte_t entry;
81885
81886- pte_unmap(page_table);
81887-
81888- /* Check if we need to add a guard page to the stack */
81889- if (check_stack_guard_page(vma, address) < 0)
81890- return VM_FAULT_SIGBUS;
81891-
81892- /* Use the zero-page for reads */
81893 if (!(flags & FAULT_FLAG_WRITE)) {
81894 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
81895 vma->vm_page_prot));
81896- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81897+ ptl = pte_lockptr(mm, pmd);
81898+ spin_lock(ptl);
81899 if (!pte_none(*page_table))
81900 goto unlock;
81901 goto setpte;
81902 }
81903
81904 /* Allocate our own private page. */
81905+ pte_unmap(page_table);
81906+
81907 if (unlikely(anon_vma_prepare(vma)))
81908 goto oom;
81909 page = alloc_zeroed_user_highpage_movable(vma, address);
81910@@ -3257,6 +3435,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81911 if (!pte_none(*page_table))
81912 goto release;
81913
81914+#ifdef CONFIG_PAX_SEGMEXEC
81915+ if (pax_find_mirror_vma(vma))
81916+ BUG_ON(!trylock_page(page));
81917+#endif
81918+
81919 inc_mm_counter_fast(mm, MM_ANONPAGES);
81920 page_add_new_anon_rmap(page, vma, address);
81921 setpte:
81922@@ -3264,6 +3447,12 @@ setpte:
81923
81924 /* No need to invalidate - it was non-present before */
81925 update_mmu_cache(vma, address, page_table);
81926+
81927+#ifdef CONFIG_PAX_SEGMEXEC
81928+ if (page)
81929+ pax_mirror_anon_pte(vma, address, page, ptl);
81930+#endif
81931+
81932 unlock:
81933 pte_unmap_unlock(page_table, ptl);
81934 return 0;
81935@@ -3407,6 +3596,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81936 */
81937 /* Only go through if we didn't race with anybody else... */
81938 if (likely(pte_same(*page_table, orig_pte))) {
81939+
81940+#ifdef CONFIG_PAX_SEGMEXEC
81941+ if (anon && pax_find_mirror_vma(vma))
81942+ BUG_ON(!trylock_page(page));
81943+#endif
81944+
81945 flush_icache_page(vma, page);
81946 entry = mk_pte(page, vma->vm_page_prot);
81947 if (flags & FAULT_FLAG_WRITE)
81948@@ -3426,6 +3621,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81949
81950 /* no need to invalidate: a not-present page won't be cached */
81951 update_mmu_cache(vma, address, page_table);
81952+
81953+#ifdef CONFIG_PAX_SEGMEXEC
81954+ if (anon)
81955+ pax_mirror_anon_pte(vma, address, page, ptl);
81956+ else
81957+ pax_mirror_file_pte(vma, address, page, ptl);
81958+#endif
81959+
81960 } else {
81961 if (cow_page)
81962 mem_cgroup_uncharge_page(cow_page);
81963@@ -3747,6 +3950,12 @@ int handle_pte_fault(struct mm_struct *mm,
81964 if (flags & FAULT_FLAG_WRITE)
81965 flush_tlb_fix_spurious_fault(vma, address);
81966 }
81967+
81968+#ifdef CONFIG_PAX_SEGMEXEC
81969+ pax_mirror_pte(vma, address, pte, pmd, ptl);
81970+ return 0;
81971+#endif
81972+
81973 unlock:
81974 pte_unmap_unlock(pte, ptl);
81975 return 0;
81976@@ -3763,6 +3972,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81977 pmd_t *pmd;
81978 pte_t *pte;
81979
81980+#ifdef CONFIG_PAX_SEGMEXEC
81981+ struct vm_area_struct *vma_m;
81982+#endif
81983+
81984 __set_current_state(TASK_RUNNING);
81985
81986 count_vm_event(PGFAULT);
81987@@ -3774,6 +3987,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81988 if (unlikely(is_vm_hugetlb_page(vma)))
81989 return hugetlb_fault(mm, vma, address, flags);
81990
81991+#ifdef CONFIG_PAX_SEGMEXEC
81992+ vma_m = pax_find_mirror_vma(vma);
81993+ if (vma_m) {
81994+ unsigned long address_m;
81995+ pgd_t *pgd_m;
81996+ pud_t *pud_m;
81997+ pmd_t *pmd_m;
81998+
81999+ if (vma->vm_start > vma_m->vm_start) {
82000+ address_m = address;
82001+ address -= SEGMEXEC_TASK_SIZE;
82002+ vma = vma_m;
82003+ } else
82004+ address_m = address + SEGMEXEC_TASK_SIZE;
82005+
82006+ pgd_m = pgd_offset(mm, address_m);
82007+ pud_m = pud_alloc(mm, pgd_m, address_m);
82008+ if (!pud_m)
82009+ return VM_FAULT_OOM;
82010+ pmd_m = pmd_alloc(mm, pud_m, address_m);
82011+ if (!pmd_m)
82012+ return VM_FAULT_OOM;
82013+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
82014+ return VM_FAULT_OOM;
82015+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
82016+ }
82017+#endif
82018+
82019 retry:
82020 pgd = pgd_offset(mm, address);
82021 pud = pud_alloc(mm, pgd, address);
82022@@ -3872,6 +4113,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82023 spin_unlock(&mm->page_table_lock);
82024 return 0;
82025 }
82026+
82027+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82028+{
82029+ pud_t *new = pud_alloc_one(mm, address);
82030+ if (!new)
82031+ return -ENOMEM;
82032+
82033+ smp_wmb(); /* See comment in __pte_alloc */
82034+
82035+ spin_lock(&mm->page_table_lock);
82036+ if (pgd_present(*pgd)) /* Another has populated it */
82037+ pud_free(mm, new);
82038+ else
82039+ pgd_populate_kernel(mm, pgd, new);
82040+ spin_unlock(&mm->page_table_lock);
82041+ return 0;
82042+}
82043 #endif /* __PAGETABLE_PUD_FOLDED */
82044
82045 #ifndef __PAGETABLE_PMD_FOLDED
82046@@ -3902,6 +4160,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
82047 spin_unlock(&mm->page_table_lock);
82048 return 0;
82049 }
82050+
82051+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
82052+{
82053+ pmd_t *new = pmd_alloc_one(mm, address);
82054+ if (!new)
82055+ return -ENOMEM;
82056+
82057+ smp_wmb(); /* See comment in __pte_alloc */
82058+
82059+ spin_lock(&mm->page_table_lock);
82060+#ifndef __ARCH_HAS_4LEVEL_HACK
82061+ if (pud_present(*pud)) /* Another has populated it */
82062+ pmd_free(mm, new);
82063+ else
82064+ pud_populate_kernel(mm, pud, new);
82065+#else
82066+ if (pgd_present(*pud)) /* Another has populated it */
82067+ pmd_free(mm, new);
82068+ else
82069+ pgd_populate_kernel(mm, pud, new);
82070+#endif /* __ARCH_HAS_4LEVEL_HACK */
82071+ spin_unlock(&mm->page_table_lock);
82072+ return 0;
82073+}
82074 #endif /* __PAGETABLE_PMD_FOLDED */
82075
82076 #if !defined(__HAVE_ARCH_GATE_AREA)
82077@@ -3915,7 +4197,7 @@ static int __init gate_vma_init(void)
82078 gate_vma.vm_start = FIXADDR_USER_START;
82079 gate_vma.vm_end = FIXADDR_USER_END;
82080 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
82081- gate_vma.vm_page_prot = __P101;
82082+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
82083
82084 return 0;
82085 }
82086@@ -4049,8 +4331,8 @@ out:
82087 return ret;
82088 }
82089
82090-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82091- void *buf, int len, int write)
82092+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82093+ void *buf, size_t len, int write)
82094 {
82095 resource_size_t phys_addr;
82096 unsigned long prot = 0;
82097@@ -4075,8 +4357,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82098 * Access another process' address space as given in mm. If non-NULL, use the
82099 * given task for page fault accounting.
82100 */
82101-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82102- unsigned long addr, void *buf, int len, int write)
82103+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82104+ unsigned long addr, void *buf, size_t len, int write)
82105 {
82106 struct vm_area_struct *vma;
82107 void *old_buf = buf;
82108@@ -4084,7 +4366,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82109 down_read(&mm->mmap_sem);
82110 /* ignore errors, just check how much was successfully transferred */
82111 while (len) {
82112- int bytes, ret, offset;
82113+ ssize_t bytes, ret, offset;
82114 void *maddr;
82115 struct page *page = NULL;
82116
82117@@ -4143,8 +4425,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82118 *
82119 * The caller must hold a reference on @mm.
82120 */
82121-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82122- void *buf, int len, int write)
82123+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
82124+ void *buf, size_t len, int write)
82125 {
82126 return __access_remote_vm(NULL, mm, addr, buf, len, write);
82127 }
82128@@ -4154,11 +4436,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82129 * Source/target buffer must be kernel space,
82130 * Do not walk the page table directly, use get_user_pages
82131 */
82132-int access_process_vm(struct task_struct *tsk, unsigned long addr,
82133- void *buf, int len, int write)
82134+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
82135+ void *buf, size_t len, int write)
82136 {
82137 struct mm_struct *mm;
82138- int ret;
82139+ ssize_t ret;
82140
82141 mm = get_task_mm(tsk);
82142 if (!mm)
82143diff --git a/mm/mempolicy.c b/mm/mempolicy.c
82144index 7431001..0f8344e 100644
82145--- a/mm/mempolicy.c
82146+++ b/mm/mempolicy.c
82147@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82148 unsigned long vmstart;
82149 unsigned long vmend;
82150
82151+#ifdef CONFIG_PAX_SEGMEXEC
82152+ struct vm_area_struct *vma_m;
82153+#endif
82154+
82155 vma = find_vma(mm, start);
82156 if (!vma || vma->vm_start > start)
82157 return -EFAULT;
82158@@ -744,9 +748,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82159 if (err)
82160 goto out;
82161 }
82162+
82163 err = vma_replace_policy(vma, new_pol);
82164 if (err)
82165 goto out;
82166+
82167+#ifdef CONFIG_PAX_SEGMEXEC
82168+ vma_m = pax_find_mirror_vma(vma);
82169+ if (vma_m) {
82170+ err = vma_replace_policy(vma_m, new_pol);
82171+ if (err)
82172+ goto out;
82173+ }
82174+#endif
82175+
82176 }
82177
82178 out:
82179@@ -1202,6 +1217,17 @@ static long do_mbind(unsigned long start, unsigned long len,
82180
82181 if (end < start)
82182 return -EINVAL;
82183+
82184+#ifdef CONFIG_PAX_SEGMEXEC
82185+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82186+ if (end > SEGMEXEC_TASK_SIZE)
82187+ return -EINVAL;
82188+ } else
82189+#endif
82190+
82191+ if (end > TASK_SIZE)
82192+ return -EINVAL;
82193+
82194 if (end == start)
82195 return 0;
82196
82197@@ -1430,8 +1456,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82198 */
82199 tcred = __task_cred(task);
82200 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82201- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82202- !capable(CAP_SYS_NICE)) {
82203+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82204 rcu_read_unlock();
82205 err = -EPERM;
82206 goto out_put;
82207@@ -1462,6 +1487,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82208 goto out;
82209 }
82210
82211+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82212+ if (mm != current->mm &&
82213+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
82214+ mmput(mm);
82215+ err = -EPERM;
82216+ goto out;
82217+ }
82218+#endif
82219+
82220 err = do_migrate_pages(mm, old, new,
82221 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
82222
82223diff --git a/mm/migrate.c b/mm/migrate.c
82224index c04d9af..0b41805 100644
82225--- a/mm/migrate.c
82226+++ b/mm/migrate.c
82227@@ -1395,8 +1395,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
82228 */
82229 tcred = __task_cred(task);
82230 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82231- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82232- !capable(CAP_SYS_NICE)) {
82233+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82234 rcu_read_unlock();
82235 err = -EPERM;
82236 goto out;
82237diff --git a/mm/mlock.c b/mm/mlock.c
82238index 79b7cf7..9944291 100644
82239--- a/mm/mlock.c
82240+++ b/mm/mlock.c
82241@@ -13,6 +13,7 @@
82242 #include <linux/pagemap.h>
82243 #include <linux/mempolicy.h>
82244 #include <linux/syscalls.h>
82245+#include <linux/security.h>
82246 #include <linux/sched.h>
82247 #include <linux/export.h>
82248 #include <linux/rmap.h>
82249@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
82250 {
82251 unsigned long nstart, end, tmp;
82252 struct vm_area_struct * vma, * prev;
82253- int error;
82254+ int error = 0;
82255
82256 VM_BUG_ON(start & ~PAGE_MASK);
82257 VM_BUG_ON(len != PAGE_ALIGN(len));
82258@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
82259 return -EINVAL;
82260 if (end == start)
82261 return 0;
82262+ if (end > TASK_SIZE)
82263+ return -EINVAL;
82264+
82265 vma = find_vma(current->mm, start);
82266 if (!vma || vma->vm_start > start)
82267 return -ENOMEM;
82268@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
82269 for (nstart = start ; ; ) {
82270 vm_flags_t newflags;
82271
82272+#ifdef CONFIG_PAX_SEGMEXEC
82273+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82274+ break;
82275+#endif
82276+
82277 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
82278
82279 newflags = vma->vm_flags & ~VM_LOCKED;
82280@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
82281 lock_limit >>= PAGE_SHIFT;
82282
82283 /* check against resource limits */
82284+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
82285 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
82286 error = do_mlock(start, len, 1);
82287 up_write(&current->mm->mmap_sem);
82288@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
82289 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
82290 vm_flags_t newflags;
82291
82292+#ifdef CONFIG_PAX_SEGMEXEC
82293+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82294+ break;
82295+#endif
82296+
82297 newflags = vma->vm_flags & ~VM_LOCKED;
82298 if (flags & MCL_CURRENT)
82299 newflags |= VM_LOCKED;
82300@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
82301 lock_limit >>= PAGE_SHIFT;
82302
82303 ret = -ENOMEM;
82304+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
82305 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
82306 capable(CAP_IPC_LOCK))
82307 ret = do_mlockall(flags);
82308diff --git a/mm/mmap.c b/mm/mmap.c
82309index 0dceed8..a559c2e 100644
82310--- a/mm/mmap.c
82311+++ b/mm/mmap.c
82312@@ -33,6 +33,7 @@
82313 #include <linux/uprobes.h>
82314 #include <linux/rbtree_augmented.h>
82315 #include <linux/sched/sysctl.h>
82316+#include <linux/random.h>
82317
82318 #include <asm/uaccess.h>
82319 #include <asm/cacheflush.h>
82320@@ -49,6 +50,16 @@
82321 #define arch_rebalance_pgtables(addr, len) (addr)
82322 #endif
82323
82324+static inline void verify_mm_writelocked(struct mm_struct *mm)
82325+{
82326+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
82327+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82328+ up_read(&mm->mmap_sem);
82329+ BUG();
82330+ }
82331+#endif
82332+}
82333+
82334 static void unmap_region(struct mm_struct *mm,
82335 struct vm_area_struct *vma, struct vm_area_struct *prev,
82336 unsigned long start, unsigned long end);
82337@@ -68,22 +79,32 @@ static void unmap_region(struct mm_struct *mm,
82338 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
82339 *
82340 */
82341-pgprot_t protection_map[16] = {
82342+pgprot_t protection_map[16] __read_only = {
82343 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
82344 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
82345 };
82346
82347-pgprot_t vm_get_page_prot(unsigned long vm_flags)
82348+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
82349 {
82350- return __pgprot(pgprot_val(protection_map[vm_flags &
82351+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
82352 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
82353 pgprot_val(arch_vm_get_page_prot(vm_flags)));
82354+
82355+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82356+ if (!(__supported_pte_mask & _PAGE_NX) &&
82357+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
82358+ (vm_flags & (VM_READ | VM_WRITE)))
82359+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
82360+#endif
82361+
82362+ return prot;
82363 }
82364 EXPORT_SYMBOL(vm_get_page_prot);
82365
82366 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
82367 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
82368 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
82369+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
82370 /*
82371 * Make sure vm_committed_as in one cacheline and not cacheline shared with
82372 * other variables. It can be updated by several CPUs frequently.
82373@@ -239,6 +260,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
82374 struct vm_area_struct *next = vma->vm_next;
82375
82376 might_sleep();
82377+ BUG_ON(vma->vm_mirror);
82378 if (vma->vm_ops && vma->vm_ops->close)
82379 vma->vm_ops->close(vma);
82380 if (vma->vm_file)
82381@@ -283,6 +305,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
82382 * not page aligned -Ram Gupta
82383 */
82384 rlim = rlimit(RLIMIT_DATA);
82385+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
82386 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
82387 (mm->end_data - mm->start_data) > rlim)
82388 goto out;
82389@@ -897,6 +920,12 @@ static int
82390 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
82391 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82392 {
82393+
82394+#ifdef CONFIG_PAX_SEGMEXEC
82395+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
82396+ return 0;
82397+#endif
82398+
82399 if (is_mergeable_vma(vma, file, vm_flags) &&
82400 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82401 if (vma->vm_pgoff == vm_pgoff)
82402@@ -916,6 +945,12 @@ static int
82403 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82404 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82405 {
82406+
82407+#ifdef CONFIG_PAX_SEGMEXEC
82408+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
82409+ return 0;
82410+#endif
82411+
82412 if (is_mergeable_vma(vma, file, vm_flags) &&
82413 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82414 pgoff_t vm_pglen;
82415@@ -958,13 +993,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82416 struct vm_area_struct *vma_merge(struct mm_struct *mm,
82417 struct vm_area_struct *prev, unsigned long addr,
82418 unsigned long end, unsigned long vm_flags,
82419- struct anon_vma *anon_vma, struct file *file,
82420+ struct anon_vma *anon_vma, struct file *file,
82421 pgoff_t pgoff, struct mempolicy *policy)
82422 {
82423 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
82424 struct vm_area_struct *area, *next;
82425 int err;
82426
82427+#ifdef CONFIG_PAX_SEGMEXEC
82428+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
82429+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
82430+
82431+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
82432+#endif
82433+
82434 /*
82435 * We later require that vma->vm_flags == vm_flags,
82436 * so this tests vma->vm_flags & VM_SPECIAL, too.
82437@@ -980,6 +1022,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82438 if (next && next->vm_end == end) /* cases 6, 7, 8 */
82439 next = next->vm_next;
82440
82441+#ifdef CONFIG_PAX_SEGMEXEC
82442+ if (prev)
82443+ prev_m = pax_find_mirror_vma(prev);
82444+ if (area)
82445+ area_m = pax_find_mirror_vma(area);
82446+ if (next)
82447+ next_m = pax_find_mirror_vma(next);
82448+#endif
82449+
82450 /*
82451 * Can it merge with the predecessor?
82452 */
82453@@ -999,9 +1050,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82454 /* cases 1, 6 */
82455 err = vma_adjust(prev, prev->vm_start,
82456 next->vm_end, prev->vm_pgoff, NULL);
82457- } else /* cases 2, 5, 7 */
82458+
82459+#ifdef CONFIG_PAX_SEGMEXEC
82460+ if (!err && prev_m)
82461+ err = vma_adjust(prev_m, prev_m->vm_start,
82462+ next_m->vm_end, prev_m->vm_pgoff, NULL);
82463+#endif
82464+
82465+ } else { /* cases 2, 5, 7 */
82466 err = vma_adjust(prev, prev->vm_start,
82467 end, prev->vm_pgoff, NULL);
82468+
82469+#ifdef CONFIG_PAX_SEGMEXEC
82470+ if (!err && prev_m)
82471+ err = vma_adjust(prev_m, prev_m->vm_start,
82472+ end_m, prev_m->vm_pgoff, NULL);
82473+#endif
82474+
82475+ }
82476 if (err)
82477 return NULL;
82478 khugepaged_enter_vma_merge(prev);
82479@@ -1015,12 +1081,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82480 mpol_equal(policy, vma_policy(next)) &&
82481 can_vma_merge_before(next, vm_flags,
82482 anon_vma, file, pgoff+pglen)) {
82483- if (prev && addr < prev->vm_end) /* case 4 */
82484+ if (prev && addr < prev->vm_end) { /* case 4 */
82485 err = vma_adjust(prev, prev->vm_start,
82486 addr, prev->vm_pgoff, NULL);
82487- else /* cases 3, 8 */
82488+
82489+#ifdef CONFIG_PAX_SEGMEXEC
82490+ if (!err && prev_m)
82491+ err = vma_adjust(prev_m, prev_m->vm_start,
82492+ addr_m, prev_m->vm_pgoff, NULL);
82493+#endif
82494+
82495+ } else { /* cases 3, 8 */
82496 err = vma_adjust(area, addr, next->vm_end,
82497 next->vm_pgoff - pglen, NULL);
82498+
82499+#ifdef CONFIG_PAX_SEGMEXEC
82500+ if (!err && area_m)
82501+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
82502+ next_m->vm_pgoff - pglen, NULL);
82503+#endif
82504+
82505+ }
82506 if (err)
82507 return NULL;
82508 khugepaged_enter_vma_merge(area);
82509@@ -1129,8 +1210,10 @@ none:
82510 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82511 struct file *file, long pages)
82512 {
82513- const unsigned long stack_flags
82514- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
82515+
82516+#ifdef CONFIG_PAX_RANDMMAP
82517+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82518+#endif
82519
82520 mm->total_vm += pages;
82521
82522@@ -1138,7 +1221,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82523 mm->shared_vm += pages;
82524 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
82525 mm->exec_vm += pages;
82526- } else if (flags & stack_flags)
82527+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
82528 mm->stack_vm += pages;
82529 }
82530 #endif /* CONFIG_PROC_FS */
82531@@ -1177,7 +1260,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82532 * (the exception is when the underlying filesystem is noexec
82533 * mounted, in which case we dont add PROT_EXEC.)
82534 */
82535- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82536+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82537 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
82538 prot |= PROT_EXEC;
82539
82540@@ -1203,7 +1286,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82541 /* Obtain the address to map to. we verify (or select) it and ensure
82542 * that it represents a valid section of the address space.
82543 */
82544- addr = get_unmapped_area(file, addr, len, pgoff, flags);
82545+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
82546 if (addr & ~PAGE_MASK)
82547 return addr;
82548
82549@@ -1214,6 +1297,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82550 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
82551 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
82552
82553+#ifdef CONFIG_PAX_MPROTECT
82554+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82555+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82556+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
82557+ gr_log_rwxmmap(file);
82558+
82559+#ifdef CONFIG_PAX_EMUPLT
82560+ vm_flags &= ~VM_EXEC;
82561+#else
82562+ return -EPERM;
82563+#endif
82564+
82565+ }
82566+
82567+ if (!(vm_flags & VM_EXEC))
82568+ vm_flags &= ~VM_MAYEXEC;
82569+#else
82570+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82571+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82572+#endif
82573+ else
82574+ vm_flags &= ~VM_MAYWRITE;
82575+ }
82576+#endif
82577+
82578+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82579+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
82580+ vm_flags &= ~VM_PAGEEXEC;
82581+#endif
82582+
82583 if (flags & MAP_LOCKED)
82584 if (!can_do_mlock())
82585 return -EPERM;
82586@@ -1225,6 +1338,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82587 locked += mm->locked_vm;
82588 lock_limit = rlimit(RLIMIT_MEMLOCK);
82589 lock_limit >>= PAGE_SHIFT;
82590+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82591 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
82592 return -EAGAIN;
82593 }
82594@@ -1305,6 +1419,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82595 vm_flags |= VM_NORESERVE;
82596 }
82597
82598+ if (!gr_acl_handle_mmap(file, prot))
82599+ return -EACCES;
82600+
82601 addr = mmap_region(file, addr, len, vm_flags, pgoff);
82602 if (!IS_ERR_VALUE(addr) &&
82603 ((vm_flags & VM_LOCKED) ||
82604@@ -1396,7 +1513,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
82605 vm_flags_t vm_flags = vma->vm_flags;
82606
82607 /* If it was private or non-writable, the write bit is already clear */
82608- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
82609+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
82610 return 0;
82611
82612 /* The backer wishes to know when pages are first written to? */
82613@@ -1444,16 +1561,30 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82614 unsigned long charged = 0;
82615 struct inode *inode = file ? file_inode(file) : NULL;
82616
82617+#ifdef CONFIG_PAX_SEGMEXEC
82618+ struct vm_area_struct *vma_m = NULL;
82619+#endif
82620+
82621+ /*
82622+ * mm->mmap_sem is required to protect against another thread
82623+ * changing the mappings in case we sleep.
82624+ */
82625+ verify_mm_writelocked(mm);
82626+
82627 /* Clear old maps */
82628 error = -ENOMEM;
82629-munmap_back:
82630 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82631 if (do_munmap(mm, addr, len))
82632 return -ENOMEM;
82633- goto munmap_back;
82634+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82635 }
82636
82637 /* Check against address space limit. */
82638+
82639+#ifdef CONFIG_PAX_RANDMMAP
82640+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82641+#endif
82642+
82643 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82644 return -ENOMEM;
82645
82646@@ -1485,6 +1616,16 @@ munmap_back:
82647 goto unacct_error;
82648 }
82649
82650+#ifdef CONFIG_PAX_SEGMEXEC
82651+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
82652+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82653+ if (!vma_m) {
82654+ error = -ENOMEM;
82655+ goto free_vma;
82656+ }
82657+ }
82658+#endif
82659+
82660 vma->vm_mm = mm;
82661 vma->vm_start = addr;
82662 vma->vm_end = addr + len;
82663@@ -1509,6 +1650,13 @@ munmap_back:
82664 if (error)
82665 goto unmap_and_free_vma;
82666
82667+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82668+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
82669+ vma->vm_flags |= VM_PAGEEXEC;
82670+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82671+ }
82672+#endif
82673+
82674 /* Can addr have changed??
82675 *
82676 * Answer: Yes, several device drivers can do it in their
82677@@ -1547,6 +1695,11 @@ munmap_back:
82678 vma_link(mm, vma, prev, rb_link, rb_parent);
82679 file = vma->vm_file;
82680
82681+#ifdef CONFIG_PAX_SEGMEXEC
82682+ if (vma_m)
82683+ BUG_ON(pax_mirror_vma(vma_m, vma));
82684+#endif
82685+
82686 /* Once vma denies write, undo our temporary denial count */
82687 if (correct_wcount)
82688 atomic_inc(&inode->i_writecount);
82689@@ -1554,6 +1707,7 @@ out:
82690 perf_event_mmap(vma);
82691
82692 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
82693+ track_exec_limit(mm, addr, addr + len, vm_flags);
82694 if (vm_flags & VM_LOCKED) {
82695 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
82696 vma == get_gate_vma(current->mm)))
82697@@ -1577,6 +1731,12 @@ unmap_and_free_vma:
82698 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
82699 charged = 0;
82700 free_vma:
82701+
82702+#ifdef CONFIG_PAX_SEGMEXEC
82703+ if (vma_m)
82704+ kmem_cache_free(vm_area_cachep, vma_m);
82705+#endif
82706+
82707 kmem_cache_free(vm_area_cachep, vma);
82708 unacct_error:
82709 if (charged)
82710@@ -1584,7 +1744,63 @@ unacct_error:
82711 return error;
82712 }
82713
82714-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82715+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82716+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82717+{
82718+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
82719+ return ((random32() & 0xFF) + 1) << PAGE_SHIFT;
82720+
82721+ return 0;
82722+}
82723+#endif
82724+
82725+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
82726+{
82727+ if (!vma) {
82728+#ifdef CONFIG_STACK_GROWSUP
82729+ if (addr > sysctl_heap_stack_gap)
82730+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
82731+ else
82732+ vma = find_vma(current->mm, 0);
82733+ if (vma && (vma->vm_flags & VM_GROWSUP))
82734+ return false;
82735+#endif
82736+ return true;
82737+ }
82738+
82739+ if (addr + len > vma->vm_start)
82740+ return false;
82741+
82742+ if (vma->vm_flags & VM_GROWSDOWN)
82743+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
82744+#ifdef CONFIG_STACK_GROWSUP
82745+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
82746+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
82747+#endif
82748+ else if (offset)
82749+ return offset <= vma->vm_start - addr - len;
82750+
82751+ return true;
82752+}
82753+
82754+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
82755+{
82756+ if (vma->vm_start < len)
82757+ return -ENOMEM;
82758+
82759+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
82760+ if (offset <= vma->vm_start - len)
82761+ return vma->vm_start - len - offset;
82762+ else
82763+ return -ENOMEM;
82764+ }
82765+
82766+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
82767+ return vma->vm_start - len - sysctl_heap_stack_gap;
82768+ return -ENOMEM;
82769+}
82770+
82771+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
82772 {
82773 /*
82774 * We implement the search by looking for an rbtree node that
82775@@ -1632,11 +1848,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82776 }
82777 }
82778
82779- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
82780+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
82781 check_current:
82782 /* Check if current node has a suitable gap */
82783 if (gap_start > high_limit)
82784 return -ENOMEM;
82785+
82786+ if (gap_end - gap_start > info->threadstack_offset)
82787+ gap_start += info->threadstack_offset;
82788+ else
82789+ gap_start = gap_end;
82790+
82791+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
82792+ if (gap_end - gap_start > sysctl_heap_stack_gap)
82793+ gap_start += sysctl_heap_stack_gap;
82794+ else
82795+ gap_start = gap_end;
82796+ }
82797+ if (vma->vm_flags & VM_GROWSDOWN) {
82798+ if (gap_end - gap_start > sysctl_heap_stack_gap)
82799+ gap_end -= sysctl_heap_stack_gap;
82800+ else
82801+ gap_end = gap_start;
82802+ }
82803 if (gap_end >= low_limit && gap_end - gap_start >= length)
82804 goto found;
82805
82806@@ -1686,7 +1920,7 @@ found:
82807 return gap_start;
82808 }
82809
82810-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
82811+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
82812 {
82813 struct mm_struct *mm = current->mm;
82814 struct vm_area_struct *vma;
82815@@ -1740,6 +1974,24 @@ check_current:
82816 gap_end = vma->vm_start;
82817 if (gap_end < low_limit)
82818 return -ENOMEM;
82819+
82820+ if (gap_end - gap_start > info->threadstack_offset)
82821+ gap_end -= info->threadstack_offset;
82822+ else
82823+ gap_end = gap_start;
82824+
82825+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
82826+ if (gap_end - gap_start > sysctl_heap_stack_gap)
82827+ gap_start += sysctl_heap_stack_gap;
82828+ else
82829+ gap_start = gap_end;
82830+ }
82831+ if (vma->vm_flags & VM_GROWSDOWN) {
82832+ if (gap_end - gap_start > sysctl_heap_stack_gap)
82833+ gap_end -= sysctl_heap_stack_gap;
82834+ else
82835+ gap_end = gap_start;
82836+ }
82837 if (gap_start <= high_limit && gap_end - gap_start >= length)
82838 goto found;
82839
82840@@ -1803,6 +2055,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82841 struct mm_struct *mm = current->mm;
82842 struct vm_area_struct *vma;
82843 struct vm_unmapped_area_info info;
82844+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82845
82846 if (len > TASK_SIZE)
82847 return -ENOMEM;
82848@@ -1810,29 +2063,45 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82849 if (flags & MAP_FIXED)
82850 return addr;
82851
82852+#ifdef CONFIG_PAX_RANDMMAP
82853+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82854+#endif
82855+
82856 if (addr) {
82857 addr = PAGE_ALIGN(addr);
82858 vma = find_vma(mm, addr);
82859- if (TASK_SIZE - len >= addr &&
82860- (!vma || addr + len <= vma->vm_start))
82861+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82862 return addr;
82863 }
82864
82865 info.flags = 0;
82866 info.length = len;
82867 info.low_limit = TASK_UNMAPPED_BASE;
82868+
82869+#ifdef CONFIG_PAX_RANDMMAP
82870+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82871+ info.low_limit += mm->delta_mmap;
82872+#endif
82873+
82874 info.high_limit = TASK_SIZE;
82875 info.align_mask = 0;
82876+ info.threadstack_offset = offset;
82877 return vm_unmapped_area(&info);
82878 }
82879 #endif
82880
82881 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
82882 {
82883+
82884+#ifdef CONFIG_PAX_SEGMEXEC
82885+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82886+ return;
82887+#endif
82888+
82889 /*
82890 * Is this a new hole at the lowest possible address?
82891 */
82892- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
82893+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
82894 mm->free_area_cache = addr;
82895 }
82896
82897@@ -1850,6 +2119,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82898 struct mm_struct *mm = current->mm;
82899 unsigned long addr = addr0;
82900 struct vm_unmapped_area_info info;
82901+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82902
82903 /* requested length too big for entire address space */
82904 if (len > TASK_SIZE)
82905@@ -1858,12 +2128,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82906 if (flags & MAP_FIXED)
82907 return addr;
82908
82909+#ifdef CONFIG_PAX_RANDMMAP
82910+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82911+#endif
82912+
82913 /* requesting a specific address */
82914 if (addr) {
82915 addr = PAGE_ALIGN(addr);
82916 vma = find_vma(mm, addr);
82917- if (TASK_SIZE - len >= addr &&
82918- (!vma || addr + len <= vma->vm_start))
82919+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82920 return addr;
82921 }
82922
82923@@ -1872,6 +2145,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82924 info.low_limit = PAGE_SIZE;
82925 info.high_limit = mm->mmap_base;
82926 info.align_mask = 0;
82927+ info.threadstack_offset = offset;
82928 addr = vm_unmapped_area(&info);
82929
82930 /*
82931@@ -1884,6 +2158,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82932 VM_BUG_ON(addr != -ENOMEM);
82933 info.flags = 0;
82934 info.low_limit = TASK_UNMAPPED_BASE;
82935+
82936+#ifdef CONFIG_PAX_RANDMMAP
82937+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82938+ info.low_limit += mm->delta_mmap;
82939+#endif
82940+
82941 info.high_limit = TASK_SIZE;
82942 addr = vm_unmapped_area(&info);
82943 }
82944@@ -1894,6 +2174,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82945
82946 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82947 {
82948+
82949+#ifdef CONFIG_PAX_SEGMEXEC
82950+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82951+ return;
82952+#endif
82953+
82954 /*
82955 * Is this a new hole at the highest possible address?
82956 */
82957@@ -1901,8 +2187,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82958 mm->free_area_cache = addr;
82959
82960 /* dont allow allocations above current base */
82961- if (mm->free_area_cache > mm->mmap_base)
82962+ if (mm->free_area_cache > mm->mmap_base) {
82963 mm->free_area_cache = mm->mmap_base;
82964+ mm->cached_hole_size = ~0UL;
82965+ }
82966 }
82967
82968 unsigned long
82969@@ -2001,6 +2289,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
82970 return vma;
82971 }
82972
82973+#ifdef CONFIG_PAX_SEGMEXEC
82974+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
82975+{
82976+ struct vm_area_struct *vma_m;
82977+
82978+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
82979+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
82980+ BUG_ON(vma->vm_mirror);
82981+ return NULL;
82982+ }
82983+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
82984+ vma_m = vma->vm_mirror;
82985+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
82986+ BUG_ON(vma->vm_file != vma_m->vm_file);
82987+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
82988+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
82989+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
82990+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
82991+ return vma_m;
82992+}
82993+#endif
82994+
82995 /*
82996 * Verify that the stack growth is acceptable and
82997 * update accounting. This is shared with both the
82998@@ -2017,6 +2327,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82999 return -ENOMEM;
83000
83001 /* Stack limit test */
83002+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
83003 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
83004 return -ENOMEM;
83005
83006@@ -2027,6 +2338,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83007 locked = mm->locked_vm + grow;
83008 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
83009 limit >>= PAGE_SHIFT;
83010+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
83011 if (locked > limit && !capable(CAP_IPC_LOCK))
83012 return -ENOMEM;
83013 }
83014@@ -2056,37 +2368,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83015 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
83016 * vma is the last one with address > vma->vm_end. Have to extend vma.
83017 */
83018+#ifndef CONFIG_IA64
83019+static
83020+#endif
83021 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83022 {
83023 int error;
83024+ bool locknext;
83025
83026 if (!(vma->vm_flags & VM_GROWSUP))
83027 return -EFAULT;
83028
83029+ /* Also guard against wrapping around to address 0. */
83030+ if (address < PAGE_ALIGN(address+1))
83031+ address = PAGE_ALIGN(address+1);
83032+ else
83033+ return -ENOMEM;
83034+
83035 /*
83036 * We must make sure the anon_vma is allocated
83037 * so that the anon_vma locking is not a noop.
83038 */
83039 if (unlikely(anon_vma_prepare(vma)))
83040 return -ENOMEM;
83041+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
83042+ if (locknext && anon_vma_prepare(vma->vm_next))
83043+ return -ENOMEM;
83044 vma_lock_anon_vma(vma);
83045+ if (locknext)
83046+ vma_lock_anon_vma(vma->vm_next);
83047
83048 /*
83049 * vma->vm_start/vm_end cannot change under us because the caller
83050 * is required to hold the mmap_sem in read mode. We need the
83051- * anon_vma lock to serialize against concurrent expand_stacks.
83052- * Also guard against wrapping around to address 0.
83053+ * anon_vma locks to serialize against concurrent expand_stacks
83054+ * and expand_upwards.
83055 */
83056- if (address < PAGE_ALIGN(address+4))
83057- address = PAGE_ALIGN(address+4);
83058- else {
83059- vma_unlock_anon_vma(vma);
83060- return -ENOMEM;
83061- }
83062 error = 0;
83063
83064 /* Somebody else might have raced and expanded it already */
83065- if (address > vma->vm_end) {
83066+ 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)
83067+ error = -ENOMEM;
83068+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
83069 unsigned long size, grow;
83070
83071 size = address - vma->vm_start;
83072@@ -2121,6 +2444,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83073 }
83074 }
83075 }
83076+ if (locknext)
83077+ vma_unlock_anon_vma(vma->vm_next);
83078 vma_unlock_anon_vma(vma);
83079 khugepaged_enter_vma_merge(vma);
83080 validate_mm(vma->vm_mm);
83081@@ -2135,6 +2460,8 @@ int expand_downwards(struct vm_area_struct *vma,
83082 unsigned long address)
83083 {
83084 int error;
83085+ bool lockprev = false;
83086+ struct vm_area_struct *prev;
83087
83088 /*
83089 * We must make sure the anon_vma is allocated
83090@@ -2148,6 +2475,15 @@ int expand_downwards(struct vm_area_struct *vma,
83091 if (error)
83092 return error;
83093
83094+ prev = vma->vm_prev;
83095+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
83096+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
83097+#endif
83098+ if (lockprev && anon_vma_prepare(prev))
83099+ return -ENOMEM;
83100+ if (lockprev)
83101+ vma_lock_anon_vma(prev);
83102+
83103 vma_lock_anon_vma(vma);
83104
83105 /*
83106@@ -2157,9 +2493,17 @@ int expand_downwards(struct vm_area_struct *vma,
83107 */
83108
83109 /* Somebody else might have raced and expanded it already */
83110- if (address < vma->vm_start) {
83111+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
83112+ error = -ENOMEM;
83113+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
83114 unsigned long size, grow;
83115
83116+#ifdef CONFIG_PAX_SEGMEXEC
83117+ struct vm_area_struct *vma_m;
83118+
83119+ vma_m = pax_find_mirror_vma(vma);
83120+#endif
83121+
83122 size = vma->vm_end - address;
83123 grow = (vma->vm_start - address) >> PAGE_SHIFT;
83124
83125@@ -2184,13 +2528,27 @@ int expand_downwards(struct vm_area_struct *vma,
83126 vma->vm_pgoff -= grow;
83127 anon_vma_interval_tree_post_update_vma(vma);
83128 vma_gap_update(vma);
83129+
83130+#ifdef CONFIG_PAX_SEGMEXEC
83131+ if (vma_m) {
83132+ anon_vma_interval_tree_pre_update_vma(vma_m);
83133+ vma_m->vm_start -= grow << PAGE_SHIFT;
83134+ vma_m->vm_pgoff -= grow;
83135+ anon_vma_interval_tree_post_update_vma(vma_m);
83136+ vma_gap_update(vma_m);
83137+ }
83138+#endif
83139+
83140 spin_unlock(&vma->vm_mm->page_table_lock);
83141
83142+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
83143 perf_event_mmap(vma);
83144 }
83145 }
83146 }
83147 vma_unlock_anon_vma(vma);
83148+ if (lockprev)
83149+ vma_unlock_anon_vma(prev);
83150 khugepaged_enter_vma_merge(vma);
83151 validate_mm(vma->vm_mm);
83152 return error;
83153@@ -2288,6 +2646,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
83154 do {
83155 long nrpages = vma_pages(vma);
83156
83157+#ifdef CONFIG_PAX_SEGMEXEC
83158+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
83159+ vma = remove_vma(vma);
83160+ continue;
83161+ }
83162+#endif
83163+
83164 if (vma->vm_flags & VM_ACCOUNT)
83165 nr_accounted += nrpages;
83166 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
83167@@ -2333,6 +2698,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
83168 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
83169 vma->vm_prev = NULL;
83170 do {
83171+
83172+#ifdef CONFIG_PAX_SEGMEXEC
83173+ if (vma->vm_mirror) {
83174+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
83175+ vma->vm_mirror->vm_mirror = NULL;
83176+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
83177+ vma->vm_mirror = NULL;
83178+ }
83179+#endif
83180+
83181 vma_rb_erase(vma, &mm->mm_rb);
83182 mm->map_count--;
83183 tail_vma = vma;
83184@@ -2364,14 +2739,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83185 struct vm_area_struct *new;
83186 int err = -ENOMEM;
83187
83188+#ifdef CONFIG_PAX_SEGMEXEC
83189+ struct vm_area_struct *vma_m, *new_m = NULL;
83190+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
83191+#endif
83192+
83193 if (is_vm_hugetlb_page(vma) && (addr &
83194 ~(huge_page_mask(hstate_vma(vma)))))
83195 return -EINVAL;
83196
83197+#ifdef CONFIG_PAX_SEGMEXEC
83198+ vma_m = pax_find_mirror_vma(vma);
83199+#endif
83200+
83201 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
83202 if (!new)
83203 goto out_err;
83204
83205+#ifdef CONFIG_PAX_SEGMEXEC
83206+ if (vma_m) {
83207+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
83208+ if (!new_m) {
83209+ kmem_cache_free(vm_area_cachep, new);
83210+ goto out_err;
83211+ }
83212+ }
83213+#endif
83214+
83215 /* most fields are the same, copy all, and then fixup */
83216 *new = *vma;
83217
83218@@ -2384,6 +2778,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83219 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
83220 }
83221
83222+#ifdef CONFIG_PAX_SEGMEXEC
83223+ if (vma_m) {
83224+ *new_m = *vma_m;
83225+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
83226+ new_m->vm_mirror = new;
83227+ new->vm_mirror = new_m;
83228+
83229+ if (new_below)
83230+ new_m->vm_end = addr_m;
83231+ else {
83232+ new_m->vm_start = addr_m;
83233+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
83234+ }
83235+ }
83236+#endif
83237+
83238 pol = mpol_dup(vma_policy(vma));
83239 if (IS_ERR(pol)) {
83240 err = PTR_ERR(pol);
83241@@ -2406,6 +2816,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83242 else
83243 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
83244
83245+#ifdef CONFIG_PAX_SEGMEXEC
83246+ if (!err && vma_m) {
83247+ if (anon_vma_clone(new_m, vma_m))
83248+ goto out_free_mpol;
83249+
83250+ mpol_get(pol);
83251+ vma_set_policy(new_m, pol);
83252+
83253+ if (new_m->vm_file)
83254+ get_file(new_m->vm_file);
83255+
83256+ if (new_m->vm_ops && new_m->vm_ops->open)
83257+ new_m->vm_ops->open(new_m);
83258+
83259+ if (new_below)
83260+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
83261+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
83262+ else
83263+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
83264+
83265+ if (err) {
83266+ if (new_m->vm_ops && new_m->vm_ops->close)
83267+ new_m->vm_ops->close(new_m);
83268+ if (new_m->vm_file)
83269+ fput(new_m->vm_file);
83270+ mpol_put(pol);
83271+ }
83272+ }
83273+#endif
83274+
83275 /* Success. */
83276 if (!err)
83277 return 0;
83278@@ -2415,10 +2855,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83279 new->vm_ops->close(new);
83280 if (new->vm_file)
83281 fput(new->vm_file);
83282- unlink_anon_vmas(new);
83283 out_free_mpol:
83284 mpol_put(pol);
83285 out_free_vma:
83286+
83287+#ifdef CONFIG_PAX_SEGMEXEC
83288+ if (new_m) {
83289+ unlink_anon_vmas(new_m);
83290+ kmem_cache_free(vm_area_cachep, new_m);
83291+ }
83292+#endif
83293+
83294+ unlink_anon_vmas(new);
83295 kmem_cache_free(vm_area_cachep, new);
83296 out_err:
83297 return err;
83298@@ -2431,6 +2879,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83299 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83300 unsigned long addr, int new_below)
83301 {
83302+
83303+#ifdef CONFIG_PAX_SEGMEXEC
83304+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
83305+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
83306+ if (mm->map_count >= sysctl_max_map_count-1)
83307+ return -ENOMEM;
83308+ } else
83309+#endif
83310+
83311 if (mm->map_count >= sysctl_max_map_count)
83312 return -ENOMEM;
83313
83314@@ -2442,11 +2899,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83315 * work. This now handles partial unmappings.
83316 * Jeremy Fitzhardinge <jeremy@goop.org>
83317 */
83318+#ifdef CONFIG_PAX_SEGMEXEC
83319 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83320 {
83321+ int ret = __do_munmap(mm, start, len);
83322+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
83323+ return ret;
83324+
83325+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
83326+}
83327+
83328+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83329+#else
83330+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83331+#endif
83332+{
83333 unsigned long end;
83334 struct vm_area_struct *vma, *prev, *last;
83335
83336+ /*
83337+ * mm->mmap_sem is required to protect against another thread
83338+ * changing the mappings in case we sleep.
83339+ */
83340+ verify_mm_writelocked(mm);
83341+
83342 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
83343 return -EINVAL;
83344
83345@@ -2521,6 +2997,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83346 /* Fix up all other VM information */
83347 remove_vma_list(mm, vma);
83348
83349+ track_exec_limit(mm, start, end, 0UL);
83350+
83351 return 0;
83352 }
83353
83354@@ -2529,6 +3007,13 @@ int vm_munmap(unsigned long start, size_t len)
83355 int ret;
83356 struct mm_struct *mm = current->mm;
83357
83358+
83359+#ifdef CONFIG_PAX_SEGMEXEC
83360+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
83361+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
83362+ return -EINVAL;
83363+#endif
83364+
83365 down_write(&mm->mmap_sem);
83366 ret = do_munmap(mm, start, len);
83367 up_write(&mm->mmap_sem);
83368@@ -2542,16 +3027,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
83369 return vm_munmap(addr, len);
83370 }
83371
83372-static inline void verify_mm_writelocked(struct mm_struct *mm)
83373-{
83374-#ifdef CONFIG_DEBUG_VM
83375- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
83376- WARN_ON(1);
83377- up_read(&mm->mmap_sem);
83378- }
83379-#endif
83380-}
83381-
83382 /*
83383 * this is really a simplified "do_mmap". it only handles
83384 * anonymous maps. eventually we may be able to do some
83385@@ -2565,6 +3040,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83386 struct rb_node ** rb_link, * rb_parent;
83387 pgoff_t pgoff = addr >> PAGE_SHIFT;
83388 int error;
83389+ unsigned long charged;
83390
83391 len = PAGE_ALIGN(len);
83392 if (!len)
83393@@ -2572,16 +3048,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83394
83395 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
83396
83397+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
83398+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
83399+ flags &= ~VM_EXEC;
83400+
83401+#ifdef CONFIG_PAX_MPROTECT
83402+ if (mm->pax_flags & MF_PAX_MPROTECT)
83403+ flags &= ~VM_MAYEXEC;
83404+#endif
83405+
83406+ }
83407+#endif
83408+
83409 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
83410 if (error & ~PAGE_MASK)
83411 return error;
83412
83413+ charged = len >> PAGE_SHIFT;
83414+
83415 /*
83416 * mlock MCL_FUTURE?
83417 */
83418 if (mm->def_flags & VM_LOCKED) {
83419 unsigned long locked, lock_limit;
83420- locked = len >> PAGE_SHIFT;
83421+ locked = charged;
83422 locked += mm->locked_vm;
83423 lock_limit = rlimit(RLIMIT_MEMLOCK);
83424 lock_limit >>= PAGE_SHIFT;
83425@@ -2598,21 +3088,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83426 /*
83427 * Clear old maps. this also does some error checking for us
83428 */
83429- munmap_back:
83430 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
83431 if (do_munmap(mm, addr, len))
83432 return -ENOMEM;
83433- goto munmap_back;
83434+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
83435 }
83436
83437 /* Check against address space limits *after* clearing old maps... */
83438- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
83439+ if (!may_expand_vm(mm, charged))
83440 return -ENOMEM;
83441
83442 if (mm->map_count > sysctl_max_map_count)
83443 return -ENOMEM;
83444
83445- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
83446+ if (security_vm_enough_memory_mm(mm, charged))
83447 return -ENOMEM;
83448
83449 /* Can we just expand an old private anonymous mapping? */
83450@@ -2626,7 +3115,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83451 */
83452 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83453 if (!vma) {
83454- vm_unacct_memory(len >> PAGE_SHIFT);
83455+ vm_unacct_memory(charged);
83456 return -ENOMEM;
83457 }
83458
83459@@ -2640,9 +3129,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83460 vma_link(mm, vma, prev, rb_link, rb_parent);
83461 out:
83462 perf_event_mmap(vma);
83463- mm->total_vm += len >> PAGE_SHIFT;
83464+ mm->total_vm += charged;
83465 if (flags & VM_LOCKED)
83466- mm->locked_vm += (len >> PAGE_SHIFT);
83467+ mm->locked_vm += charged;
83468+ track_exec_limit(mm, addr, addr + len, flags);
83469 return addr;
83470 }
83471
83472@@ -2704,6 +3194,7 @@ void exit_mmap(struct mm_struct *mm)
83473 while (vma) {
83474 if (vma->vm_flags & VM_ACCOUNT)
83475 nr_accounted += vma_pages(vma);
83476+ vma->vm_mirror = NULL;
83477 vma = remove_vma(vma);
83478 }
83479 vm_unacct_memory(nr_accounted);
83480@@ -2720,6 +3211,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83481 struct vm_area_struct *prev;
83482 struct rb_node **rb_link, *rb_parent;
83483
83484+#ifdef CONFIG_PAX_SEGMEXEC
83485+ struct vm_area_struct *vma_m = NULL;
83486+#endif
83487+
83488+ if (security_mmap_addr(vma->vm_start))
83489+ return -EPERM;
83490+
83491 /*
83492 * The vm_pgoff of a purely anonymous vma should be irrelevant
83493 * until its first write fault, when page's anon_vma and index
83494@@ -2743,7 +3241,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83495 security_vm_enough_memory_mm(mm, vma_pages(vma)))
83496 return -ENOMEM;
83497
83498+#ifdef CONFIG_PAX_SEGMEXEC
83499+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
83500+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83501+ if (!vma_m)
83502+ return -ENOMEM;
83503+ }
83504+#endif
83505+
83506 vma_link(mm, vma, prev, rb_link, rb_parent);
83507+
83508+#ifdef CONFIG_PAX_SEGMEXEC
83509+ if (vma_m)
83510+ BUG_ON(pax_mirror_vma(vma_m, vma));
83511+#endif
83512+
83513 return 0;
83514 }
83515
83516@@ -2763,6 +3275,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83517 struct mempolicy *pol;
83518 bool faulted_in_anon_vma = true;
83519
83520+ BUG_ON(vma->vm_mirror);
83521+
83522 /*
83523 * If anonymous vma has not yet been faulted, update new pgoff
83524 * to match new location, to increase its chance of merging.
83525@@ -2829,6 +3343,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83526 return NULL;
83527 }
83528
83529+#ifdef CONFIG_PAX_SEGMEXEC
83530+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
83531+{
83532+ struct vm_area_struct *prev_m;
83533+ struct rb_node **rb_link_m, *rb_parent_m;
83534+ struct mempolicy *pol_m;
83535+
83536+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
83537+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
83538+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
83539+ *vma_m = *vma;
83540+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
83541+ if (anon_vma_clone(vma_m, vma))
83542+ return -ENOMEM;
83543+ pol_m = vma_policy(vma_m);
83544+ mpol_get(pol_m);
83545+ vma_set_policy(vma_m, pol_m);
83546+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
83547+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
83548+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
83549+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
83550+ if (vma_m->vm_file)
83551+ get_file(vma_m->vm_file);
83552+ if (vma_m->vm_ops && vma_m->vm_ops->open)
83553+ vma_m->vm_ops->open(vma_m);
83554+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
83555+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
83556+ vma_m->vm_mirror = vma;
83557+ vma->vm_mirror = vma_m;
83558+ return 0;
83559+}
83560+#endif
83561+
83562 /*
83563 * Return true if the calling process may expand its vm space by the passed
83564 * number of pages
83565@@ -2840,6 +3387,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
83566
83567 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
83568
83569+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
83570 if (cur + npages > lim)
83571 return 0;
83572 return 1;
83573@@ -2910,6 +3458,22 @@ int install_special_mapping(struct mm_struct *mm,
83574 vma->vm_start = addr;
83575 vma->vm_end = addr + len;
83576
83577+#ifdef CONFIG_PAX_MPROTECT
83578+ if (mm->pax_flags & MF_PAX_MPROTECT) {
83579+#ifndef CONFIG_PAX_MPROTECT_COMPAT
83580+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
83581+ return -EPERM;
83582+ if (!(vm_flags & VM_EXEC))
83583+ vm_flags &= ~VM_MAYEXEC;
83584+#else
83585+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
83586+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
83587+#endif
83588+ else
83589+ vm_flags &= ~VM_MAYWRITE;
83590+ }
83591+#endif
83592+
83593 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
83594 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
83595
83596diff --git a/mm/mprotect.c b/mm/mprotect.c
83597index 94722a4..07d9926 100644
83598--- a/mm/mprotect.c
83599+++ b/mm/mprotect.c
83600@@ -23,10 +23,18 @@
83601 #include <linux/mmu_notifier.h>
83602 #include <linux/migrate.h>
83603 #include <linux/perf_event.h>
83604+#include <linux/sched/sysctl.h>
83605+
83606+#ifdef CONFIG_PAX_MPROTECT
83607+#include <linux/elf.h>
83608+#include <linux/binfmts.h>
83609+#endif
83610+
83611 #include <asm/uaccess.h>
83612 #include <asm/pgtable.h>
83613 #include <asm/cacheflush.h>
83614 #include <asm/tlbflush.h>
83615+#include <asm/mmu_context.h>
83616
83617 #ifndef pgprot_modify
83618 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
83619@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
83620 return pages;
83621 }
83622
83623+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83624+/* called while holding the mmap semaphor for writing except stack expansion */
83625+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
83626+{
83627+ unsigned long oldlimit, newlimit = 0UL;
83628+
83629+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
83630+ return;
83631+
83632+ spin_lock(&mm->page_table_lock);
83633+ oldlimit = mm->context.user_cs_limit;
83634+ if ((prot & VM_EXEC) && oldlimit < end)
83635+ /* USER_CS limit moved up */
83636+ newlimit = end;
83637+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
83638+ /* USER_CS limit moved down */
83639+ newlimit = start;
83640+
83641+ if (newlimit) {
83642+ mm->context.user_cs_limit = newlimit;
83643+
83644+#ifdef CONFIG_SMP
83645+ wmb();
83646+ cpus_clear(mm->context.cpu_user_cs_mask);
83647+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
83648+#endif
83649+
83650+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
83651+ }
83652+ spin_unlock(&mm->page_table_lock);
83653+ if (newlimit == end) {
83654+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
83655+
83656+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
83657+ if (is_vm_hugetlb_page(vma))
83658+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
83659+ else
83660+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
83661+ }
83662+}
83663+#endif
83664+
83665 int
83666 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83667 unsigned long start, unsigned long end, unsigned long newflags)
83668@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83669 int error;
83670 int dirty_accountable = 0;
83671
83672+#ifdef CONFIG_PAX_SEGMEXEC
83673+ struct vm_area_struct *vma_m = NULL;
83674+ unsigned long start_m, end_m;
83675+
83676+ start_m = start + SEGMEXEC_TASK_SIZE;
83677+ end_m = end + SEGMEXEC_TASK_SIZE;
83678+#endif
83679+
83680 if (newflags == oldflags) {
83681 *pprev = vma;
83682 return 0;
83683 }
83684
83685+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
83686+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
83687+
83688+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
83689+ return -ENOMEM;
83690+
83691+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
83692+ return -ENOMEM;
83693+ }
83694+
83695 /*
83696 * If we make a private mapping writable we increase our commit;
83697 * but (without finer accounting) cannot reduce our commit if we
83698@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83699 }
83700 }
83701
83702+#ifdef CONFIG_PAX_SEGMEXEC
83703+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
83704+ if (start != vma->vm_start) {
83705+ error = split_vma(mm, vma, start, 1);
83706+ if (error)
83707+ goto fail;
83708+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
83709+ *pprev = (*pprev)->vm_next;
83710+ }
83711+
83712+ if (end != vma->vm_end) {
83713+ error = split_vma(mm, vma, end, 0);
83714+ if (error)
83715+ goto fail;
83716+ }
83717+
83718+ if (pax_find_mirror_vma(vma)) {
83719+ error = __do_munmap(mm, start_m, end_m - start_m);
83720+ if (error)
83721+ goto fail;
83722+ } else {
83723+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83724+ if (!vma_m) {
83725+ error = -ENOMEM;
83726+ goto fail;
83727+ }
83728+ vma->vm_flags = newflags;
83729+ error = pax_mirror_vma(vma_m, vma);
83730+ if (error) {
83731+ vma->vm_flags = oldflags;
83732+ goto fail;
83733+ }
83734+ }
83735+ }
83736+#endif
83737+
83738 /*
83739 * First try to merge with previous and/or next vma.
83740 */
83741@@ -296,9 +400,21 @@ success:
83742 * vm_flags and vm_page_prot are protected by the mmap_sem
83743 * held in write mode.
83744 */
83745+
83746+#ifdef CONFIG_PAX_SEGMEXEC
83747+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
83748+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
83749+#endif
83750+
83751 vma->vm_flags = newflags;
83752+
83753+#ifdef CONFIG_PAX_MPROTECT
83754+ if (mm->binfmt && mm->binfmt->handle_mprotect)
83755+ mm->binfmt->handle_mprotect(vma, newflags);
83756+#endif
83757+
83758 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
83759- vm_get_page_prot(newflags));
83760+ vm_get_page_prot(vma->vm_flags));
83761
83762 if (vma_wants_writenotify(vma)) {
83763 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
83764@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83765 end = start + len;
83766 if (end <= start)
83767 return -ENOMEM;
83768+
83769+#ifdef CONFIG_PAX_SEGMEXEC
83770+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
83771+ if (end > SEGMEXEC_TASK_SIZE)
83772+ return -EINVAL;
83773+ } else
83774+#endif
83775+
83776+ if (end > TASK_SIZE)
83777+ return -EINVAL;
83778+
83779 if (!arch_validate_prot(prot))
83780 return -EINVAL;
83781
83782@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83783 /*
83784 * Does the application expect PROT_READ to imply PROT_EXEC:
83785 */
83786- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
83787+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
83788 prot |= PROT_EXEC;
83789
83790 vm_flags = calc_vm_prot_bits(prot);
83791@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83792 if (start > vma->vm_start)
83793 prev = vma;
83794
83795+#ifdef CONFIG_PAX_MPROTECT
83796+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
83797+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
83798+#endif
83799+
83800 for (nstart = start ; ; ) {
83801 unsigned long newflags;
83802
83803@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83804
83805 /* newflags >> 4 shift VM_MAY% in place of VM_% */
83806 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
83807+ if (prot & (PROT_WRITE | PROT_EXEC))
83808+ gr_log_rwxmprotect(vma->vm_file);
83809+
83810+ error = -EACCES;
83811+ goto out;
83812+ }
83813+
83814+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
83815 error = -EACCES;
83816 goto out;
83817 }
83818@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83819 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
83820 if (error)
83821 goto out;
83822+
83823+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
83824+
83825 nstart = tmp;
83826
83827 if (nstart < prev->vm_end)
83828diff --git a/mm/mremap.c b/mm/mremap.c
83829index 463a257..c0c7a92 100644
83830--- a/mm/mremap.c
83831+++ b/mm/mremap.c
83832@@ -126,6 +126,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
83833 continue;
83834 pte = ptep_get_and_clear(mm, old_addr, old_pte);
83835 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
83836+
83837+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83838+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
83839+ pte = pte_exprotect(pte);
83840+#endif
83841+
83842 set_pte_at(mm, new_addr, new_pte, pte);
83843 }
83844
83845@@ -318,6 +324,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
83846 if (is_vm_hugetlb_page(vma))
83847 goto Einval;
83848
83849+#ifdef CONFIG_PAX_SEGMEXEC
83850+ if (pax_find_mirror_vma(vma))
83851+ goto Einval;
83852+#endif
83853+
83854 /* We can't remap across vm area boundaries */
83855 if (old_len > vma->vm_end - addr)
83856 goto Efault;
83857@@ -373,20 +384,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
83858 unsigned long ret = -EINVAL;
83859 unsigned long charged = 0;
83860 unsigned long map_flags;
83861+ unsigned long pax_task_size = TASK_SIZE;
83862
83863 if (new_addr & ~PAGE_MASK)
83864 goto out;
83865
83866- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
83867+#ifdef CONFIG_PAX_SEGMEXEC
83868+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83869+ pax_task_size = SEGMEXEC_TASK_SIZE;
83870+#endif
83871+
83872+ pax_task_size -= PAGE_SIZE;
83873+
83874+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
83875 goto out;
83876
83877 /* Check if the location we're moving into overlaps the
83878 * old location at all, and fail if it does.
83879 */
83880- if ((new_addr <= addr) && (new_addr+new_len) > addr)
83881- goto out;
83882-
83883- if ((addr <= new_addr) && (addr+old_len) > new_addr)
83884+ if (addr + old_len > new_addr && new_addr + new_len > addr)
83885 goto out;
83886
83887 ret = do_munmap(mm, new_addr, new_len);
83888@@ -455,6 +471,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83889 unsigned long ret = -EINVAL;
83890 unsigned long charged = 0;
83891 bool locked = false;
83892+ unsigned long pax_task_size = TASK_SIZE;
83893
83894 down_write(&current->mm->mmap_sem);
83895
83896@@ -475,6 +492,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83897 if (!new_len)
83898 goto out;
83899
83900+#ifdef CONFIG_PAX_SEGMEXEC
83901+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83902+ pax_task_size = SEGMEXEC_TASK_SIZE;
83903+#endif
83904+
83905+ pax_task_size -= PAGE_SIZE;
83906+
83907+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
83908+ old_len > pax_task_size || addr > pax_task_size-old_len)
83909+ goto out;
83910+
83911 if (flags & MREMAP_FIXED) {
83912 if (flags & MREMAP_MAYMOVE)
83913 ret = mremap_to(addr, old_len, new_addr, new_len,
83914@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83915 new_addr = addr;
83916 }
83917 ret = addr;
83918+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
83919 goto out;
83920 }
83921 }
83922@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83923 goto out;
83924 }
83925
83926+ map_flags = vma->vm_flags;
83927 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
83928+ if (!(ret & ~PAGE_MASK)) {
83929+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
83930+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
83931+ }
83932 }
83933 out:
83934 if (ret & ~PAGE_MASK)
83935diff --git a/mm/nommu.c b/mm/nommu.c
83936index e001768..9b52b30 100644
83937--- a/mm/nommu.c
83938+++ b/mm/nommu.c
83939@@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
83940 int sysctl_overcommit_ratio = 50; /* default is 50% */
83941 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
83942 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
83943-int heap_stack_gap = 0;
83944
83945 atomic_long_t mmap_pages_allocated;
83946
83947@@ -841,15 +840,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
83948 EXPORT_SYMBOL(find_vma);
83949
83950 /*
83951- * find a VMA
83952- * - we don't extend stack VMAs under NOMMU conditions
83953- */
83954-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
83955-{
83956- return find_vma(mm, addr);
83957-}
83958-
83959-/*
83960 * expand a stack to a given address
83961 * - not supported under NOMMU conditions
83962 */
83963@@ -1560,6 +1550,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83964
83965 /* most fields are the same, copy all, and then fixup */
83966 *new = *vma;
83967+ INIT_LIST_HEAD(&new->anon_vma_chain);
83968 *region = *vma->vm_region;
83969 new->vm_region = region;
83970
83971@@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
83972 }
83973 EXPORT_SYMBOL(generic_file_remap_pages);
83974
83975-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83976- unsigned long addr, void *buf, int len, int write)
83977+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83978+ unsigned long addr, void *buf, size_t len, int write)
83979 {
83980 struct vm_area_struct *vma;
83981
83982@@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83983 *
83984 * The caller must hold a reference on @mm.
83985 */
83986-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83987- void *buf, int len, int write)
83988+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83989+ void *buf, size_t len, int write)
83990 {
83991 return __access_remote_vm(NULL, mm, addr, buf, len, write);
83992 }
83993@@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83994 * Access another process' address space.
83995 * - source/target buffer must be kernel space
83996 */
83997-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
83998+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
83999 {
84000 struct mm_struct *mm;
84001
84002diff --git a/mm/page-writeback.c b/mm/page-writeback.c
84003index efe6814..64b4701 100644
84004--- a/mm/page-writeback.c
84005+++ b/mm/page-writeback.c
84006@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
84007 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
84008 * - the bdi dirty thresh drops quickly due to change of JBOD workload
84009 */
84010-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
84011+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
84012 unsigned long thresh,
84013 unsigned long bg_thresh,
84014 unsigned long dirty,
84015@@ -1634,7 +1634,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
84016 }
84017 }
84018
84019-static struct notifier_block __cpuinitdata ratelimit_nb = {
84020+static struct notifier_block ratelimit_nb = {
84021 .notifier_call = ratelimit_handler,
84022 .next = NULL,
84023 };
84024diff --git a/mm/page_alloc.c b/mm/page_alloc.c
84025index 0d4fef2..8870335 100644
84026--- a/mm/page_alloc.c
84027+++ b/mm/page_alloc.c
84028@@ -59,6 +59,7 @@
84029 #include <linux/migrate.h>
84030 #include <linux/page-debug-flags.h>
84031 #include <linux/sched/rt.h>
84032+#include <linux/random.h>
84033
84034 #include <asm/tlbflush.h>
84035 #include <asm/div64.h>
84036@@ -344,7 +345,7 @@ out:
84037 * This usage means that zero-order pages may not be compound.
84038 */
84039
84040-static void free_compound_page(struct page *page)
84041+void free_compound_page(struct page *page)
84042 {
84043 __free_pages_ok(page, compound_order(page));
84044 }
84045@@ -701,6 +702,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
84046 int i;
84047 int bad = 0;
84048
84049+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84050+ unsigned long index = 1UL << order;
84051+#endif
84052+
84053 trace_mm_page_free(page, order);
84054 kmemcheck_free_shadow(page, order);
84055
84056@@ -716,6 +721,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
84057 debug_check_no_obj_freed(page_address(page),
84058 PAGE_SIZE << order);
84059 }
84060+
84061+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84062+ for (; index; --index)
84063+ sanitize_highpage(page + index - 1);
84064+#endif
84065+
84066 arch_free_page(page, order);
84067 kernel_map_pages(page, 1 << order, 0);
84068
84069@@ -738,6 +749,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
84070 local_irq_restore(flags);
84071 }
84072
84073+#ifdef CONFIG_PAX_LATENT_ENTROPY
84074+bool __meminitdata extra_latent_entropy;
84075+
84076+static int __init setup_pax_extra_latent_entropy(char *str)
84077+{
84078+ extra_latent_entropy = true;
84079+ return 0;
84080+}
84081+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
84082+
84083+volatile u64 latent_entropy;
84084+#endif
84085+
84086 /*
84087 * Read access to zone->managed_pages is safe because it's unsigned long,
84088 * but we still need to serialize writers. Currently all callers of
84089@@ -760,6 +784,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
84090 set_page_count(p, 0);
84091 }
84092
84093+#ifdef CONFIG_PAX_LATENT_ENTROPY
84094+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
84095+ u64 hash = 0;
84096+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
84097+ const u64 *data = lowmem_page_address(page);
84098+
84099+ for (index = 0; index < end; index++)
84100+ hash ^= hash + data[index];
84101+ latent_entropy ^= hash;
84102+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84103+ }
84104+#endif
84105+
84106 page_zone(page)->managed_pages += 1 << order;
84107 set_page_refcounted(page);
84108 __free_pages(page, order);
84109@@ -869,8 +906,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
84110 arch_alloc_page(page, order);
84111 kernel_map_pages(page, 1 << order, 1);
84112
84113+#ifndef CONFIG_PAX_MEMORY_SANITIZE
84114 if (gfp_flags & __GFP_ZERO)
84115 prep_zero_page(page, order, gfp_flags);
84116+#endif
84117
84118 if (order && (gfp_flags & __GFP_COMP))
84119 prep_compound_page(page, order);
84120diff --git a/mm/page_io.c b/mm/page_io.c
84121index 6182870..4bba6a2 100644
84122--- a/mm/page_io.c
84123+++ b/mm/page_io.c
84124@@ -205,7 +205,7 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
84125 struct file *swap_file = sis->swap_file;
84126 struct address_space *mapping = swap_file->f_mapping;
84127 struct iovec iov = {
84128- .iov_base = kmap(page),
84129+ .iov_base = (void __force_user *)kmap(page),
84130 .iov_len = PAGE_SIZE,
84131 };
84132
84133diff --git a/mm/percpu.c b/mm/percpu.c
84134index 8c8e08f..73a5cda 100644
84135--- a/mm/percpu.c
84136+++ b/mm/percpu.c
84137@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
84138 static unsigned int pcpu_high_unit_cpu __read_mostly;
84139
84140 /* the address of the first chunk which starts with the kernel static area */
84141-void *pcpu_base_addr __read_mostly;
84142+void *pcpu_base_addr __read_only;
84143 EXPORT_SYMBOL_GPL(pcpu_base_addr);
84144
84145 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
84146diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
84147index fd26d04..0cea1b0 100644
84148--- a/mm/process_vm_access.c
84149+++ b/mm/process_vm_access.c
84150@@ -13,6 +13,7 @@
84151 #include <linux/uio.h>
84152 #include <linux/sched.h>
84153 #include <linux/highmem.h>
84154+#include <linux/security.h>
84155 #include <linux/ptrace.h>
84156 #include <linux/slab.h>
84157 #include <linux/syscalls.h>
84158@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
84159 size_t iov_l_curr_offset = 0;
84160 ssize_t iov_len;
84161
84162+ return -ENOSYS; // PaX: until properly audited
84163+
84164 /*
84165 * Work out how many pages of struct pages we're going to need
84166 * when eventually calling get_user_pages
84167 */
84168 for (i = 0; i < riovcnt; i++) {
84169 iov_len = rvec[i].iov_len;
84170- if (iov_len > 0) {
84171- nr_pages_iov = ((unsigned long)rvec[i].iov_base
84172- + iov_len)
84173- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
84174- / PAGE_SIZE + 1;
84175- nr_pages = max(nr_pages, nr_pages_iov);
84176- }
84177+ if (iov_len <= 0)
84178+ continue;
84179+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
84180+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
84181+ nr_pages = max(nr_pages, nr_pages_iov);
84182 }
84183
84184 if (nr_pages == 0)
84185@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
84186 goto free_proc_pages;
84187 }
84188
84189+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
84190+ rc = -EPERM;
84191+ goto put_task_struct;
84192+ }
84193+
84194 mm = mm_access(task, PTRACE_MODE_ATTACH);
84195 if (!mm || IS_ERR(mm)) {
84196 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
84197diff --git a/mm/rmap.c b/mm/rmap.c
84198index 807c96b..0e05279 100644
84199--- a/mm/rmap.c
84200+++ b/mm/rmap.c
84201@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84202 struct anon_vma *anon_vma = vma->anon_vma;
84203 struct anon_vma_chain *avc;
84204
84205+#ifdef CONFIG_PAX_SEGMEXEC
84206+ struct anon_vma_chain *avc_m = NULL;
84207+#endif
84208+
84209 might_sleep();
84210 if (unlikely(!anon_vma)) {
84211 struct mm_struct *mm = vma->vm_mm;
84212@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84213 if (!avc)
84214 goto out_enomem;
84215
84216+#ifdef CONFIG_PAX_SEGMEXEC
84217+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
84218+ if (!avc_m)
84219+ goto out_enomem_free_avc;
84220+#endif
84221+
84222 anon_vma = find_mergeable_anon_vma(vma);
84223 allocated = NULL;
84224 if (!anon_vma) {
84225@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84226 /* page_table_lock to protect against threads */
84227 spin_lock(&mm->page_table_lock);
84228 if (likely(!vma->anon_vma)) {
84229+
84230+#ifdef CONFIG_PAX_SEGMEXEC
84231+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
84232+
84233+ if (vma_m) {
84234+ BUG_ON(vma_m->anon_vma);
84235+ vma_m->anon_vma = anon_vma;
84236+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
84237+ avc_m = NULL;
84238+ }
84239+#endif
84240+
84241 vma->anon_vma = anon_vma;
84242 anon_vma_chain_link(vma, avc, anon_vma);
84243 allocated = NULL;
84244@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84245
84246 if (unlikely(allocated))
84247 put_anon_vma(allocated);
84248+
84249+#ifdef CONFIG_PAX_SEGMEXEC
84250+ if (unlikely(avc_m))
84251+ anon_vma_chain_free(avc_m);
84252+#endif
84253+
84254 if (unlikely(avc))
84255 anon_vma_chain_free(avc);
84256 }
84257 return 0;
84258
84259 out_enomem_free_avc:
84260+
84261+#ifdef CONFIG_PAX_SEGMEXEC
84262+ if (avc_m)
84263+ anon_vma_chain_free(avc_m);
84264+#endif
84265+
84266 anon_vma_chain_free(avc);
84267 out_enomem:
84268 return -ENOMEM;
84269@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
84270 * Attach the anon_vmas from src to dst.
84271 * Returns 0 on success, -ENOMEM on failure.
84272 */
84273-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84274+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
84275 {
84276 struct anon_vma_chain *avc, *pavc;
84277 struct anon_vma *root = NULL;
84278@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84279 * the corresponding VMA in the parent process is attached to.
84280 * Returns 0 on success, non-zero on failure.
84281 */
84282-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
84283+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
84284 {
84285 struct anon_vma_chain *avc;
84286 struct anon_vma *anon_vma;
84287diff --git a/mm/shmem.c b/mm/shmem.c
84288index 1c44af7..cefe9a6 100644
84289--- a/mm/shmem.c
84290+++ b/mm/shmem.c
84291@@ -31,7 +31,7 @@
84292 #include <linux/export.h>
84293 #include <linux/swap.h>
84294
84295-static struct vfsmount *shm_mnt;
84296+struct vfsmount *shm_mnt;
84297
84298 #ifdef CONFIG_SHMEM
84299 /*
84300@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
84301 #define BOGO_DIRENT_SIZE 20
84302
84303 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
84304-#define SHORT_SYMLINK_LEN 128
84305+#define SHORT_SYMLINK_LEN 64
84306
84307 /*
84308 * shmem_fallocate and shmem_writepage communicate via inode->i_private
84309@@ -2201,6 +2201,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
84310 static int shmem_xattr_validate(const char *name)
84311 {
84312 struct { const char *prefix; size_t len; } arr[] = {
84313+
84314+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84315+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
84316+#endif
84317+
84318 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
84319 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
84320 };
84321@@ -2256,6 +2261,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
84322 if (err)
84323 return err;
84324
84325+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84326+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
84327+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
84328+ return -EOPNOTSUPP;
84329+ if (size > 8)
84330+ return -EINVAL;
84331+ }
84332+#endif
84333+
84334 return simple_xattr_set(&info->xattrs, name, value, size, flags);
84335 }
84336
84337@@ -2568,8 +2582,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
84338 int err = -ENOMEM;
84339
84340 /* Round up to L1_CACHE_BYTES to resist false sharing */
84341- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
84342- L1_CACHE_BYTES), GFP_KERNEL);
84343+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
84344 if (!sbinfo)
84345 return -ENOMEM;
84346
84347diff --git a/mm/slab.c b/mm/slab.c
84348index 856e4a1..fafb820 100644
84349--- a/mm/slab.c
84350+++ b/mm/slab.c
84351@@ -306,7 +306,7 @@ struct kmem_list3 {
84352 * Need this for bootstrapping a per node allocator.
84353 */
84354 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
84355-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
84356+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
84357 #define CACHE_CACHE 0
84358 #define SIZE_AC MAX_NUMNODES
84359 #define SIZE_L3 (2 * MAX_NUMNODES)
84360@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
84361 if ((x)->max_freeable < i) \
84362 (x)->max_freeable = i; \
84363 } while (0)
84364-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
84365-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
84366-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
84367-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
84368+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
84369+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
84370+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
84371+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
84372 #else
84373 #define STATS_INC_ACTIVE(x) do { } while (0)
84374 #define STATS_DEC_ACTIVE(x) do { } while (0)
84375@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
84376 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
84377 */
84378 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
84379- const struct slab *slab, void *obj)
84380+ const struct slab *slab, const void *obj)
84381 {
84382 u32 offset = (obj - slab->s_mem);
84383 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
84384@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
84385 struct cache_names {
84386 char *name;
84387 char *name_dma;
84388+ char *name_usercopy;
84389 };
84390
84391 static struct cache_names __initdata cache_names[] = {
84392-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
84393+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
84394 #include <linux/kmalloc_sizes.h>
84395- {NULL,}
84396+ {NULL}
84397 #undef CACHE
84398 };
84399
84400@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
84401 if (unlikely(gfpflags & GFP_DMA))
84402 return csizep->cs_dmacachep;
84403 #endif
84404+
84405+#ifdef CONFIG_PAX_USERCOPY_SLABS
84406+ if (unlikely(gfpflags & GFP_USERCOPY))
84407+ return csizep->cs_usercopycachep;
84408+#endif
84409+
84410 return csizep->cs_cachep;
84411 }
84412
84413@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
84414 return notifier_from_errno(err);
84415 }
84416
84417-static struct notifier_block __cpuinitdata cpucache_notifier = {
84418+static struct notifier_block cpucache_notifier = {
84419 &cpuup_callback, NULL, 0
84420 };
84421
84422@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
84423 */
84424
84425 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
84426- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
84427+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84428
84429 if (INDEX_AC != INDEX_L3)
84430 sizes[INDEX_L3].cs_cachep =
84431 create_kmalloc_cache(names[INDEX_L3].name,
84432- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
84433+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84434
84435 slab_early_init = 0;
84436
84437@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
84438 */
84439 if (!sizes->cs_cachep)
84440 sizes->cs_cachep = create_kmalloc_cache(names->name,
84441- sizes->cs_size, ARCH_KMALLOC_FLAGS);
84442+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84443
84444 #ifdef CONFIG_ZONE_DMA
84445 sizes->cs_dmacachep = create_kmalloc_cache(
84446 names->name_dma, sizes->cs_size,
84447 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
84448 #endif
84449+
84450+#ifdef CONFIG_PAX_USERCOPY_SLABS
84451+ sizes->cs_usercopycachep = create_kmalloc_cache(
84452+ names->name_usercopy, sizes->cs_size,
84453+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84454+#endif
84455+
84456 sizes++;
84457 names++;
84458 }
84459@@ -3924,6 +3938,7 @@ void kfree(const void *objp)
84460
84461 if (unlikely(ZERO_OR_NULL_PTR(objp)))
84462 return;
84463+ VM_BUG_ON(!virt_addr_valid(objp));
84464 local_irq_save(flags);
84465 kfree_debugcheck(objp);
84466 c = virt_to_cache(objp);
84467@@ -4365,10 +4380,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
84468 }
84469 /* cpu stats */
84470 {
84471- unsigned long allochit = atomic_read(&cachep->allochit);
84472- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
84473- unsigned long freehit = atomic_read(&cachep->freehit);
84474- unsigned long freemiss = atomic_read(&cachep->freemiss);
84475+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
84476+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
84477+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
84478+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
84479
84480 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
84481 allochit, allocmiss, freehit, freemiss);
84482@@ -4600,13 +4615,71 @@ static const struct file_operations proc_slabstats_operations = {
84483 static int __init slab_proc_init(void)
84484 {
84485 #ifdef CONFIG_DEBUG_SLAB_LEAK
84486- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
84487+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
84488 #endif
84489 return 0;
84490 }
84491 module_init(slab_proc_init);
84492 #endif
84493
84494+bool is_usercopy_object(const void *ptr)
84495+{
84496+ struct page *page;
84497+ struct kmem_cache *cachep;
84498+
84499+ if (ZERO_OR_NULL_PTR(ptr))
84500+ return false;
84501+
84502+ if (!slab_is_available())
84503+ return false;
84504+
84505+ if (!virt_addr_valid(ptr))
84506+ return false;
84507+
84508+ page = virt_to_head_page(ptr);
84509+
84510+ if (!PageSlab(page))
84511+ return false;
84512+
84513+ cachep = page->slab_cache;
84514+ return cachep->flags & SLAB_USERCOPY;
84515+}
84516+
84517+#ifdef CONFIG_PAX_USERCOPY
84518+const char *check_heap_object(const void *ptr, unsigned long n)
84519+{
84520+ struct page *page;
84521+ struct kmem_cache *cachep;
84522+ struct slab *slabp;
84523+ unsigned int objnr;
84524+ unsigned long offset;
84525+
84526+ if (ZERO_OR_NULL_PTR(ptr))
84527+ return "<null>";
84528+
84529+ if (!virt_addr_valid(ptr))
84530+ return NULL;
84531+
84532+ page = virt_to_head_page(ptr);
84533+
84534+ if (!PageSlab(page))
84535+ return NULL;
84536+
84537+ cachep = page->slab_cache;
84538+ if (!(cachep->flags & SLAB_USERCOPY))
84539+ return cachep->name;
84540+
84541+ slabp = page->slab_page;
84542+ objnr = obj_to_index(cachep, slabp, ptr);
84543+ BUG_ON(objnr >= cachep->num);
84544+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
84545+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
84546+ return NULL;
84547+
84548+ return cachep->name;
84549+}
84550+#endif
84551+
84552 /**
84553 * ksize - get the actual amount of memory allocated for a given object
84554 * @objp: Pointer to the object
84555diff --git a/mm/slab.h b/mm/slab.h
84556index 34a98d6..73633d1 100644
84557--- a/mm/slab.h
84558+++ b/mm/slab.h
84559@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84560
84561 /* Legal flag mask for kmem_cache_create(), for various configurations */
84562 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
84563- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
84564+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
84565
84566 #if defined(CONFIG_DEBUG_SLAB)
84567 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
84568@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
84569 return s;
84570
84571 page = virt_to_head_page(x);
84572+
84573+ BUG_ON(!PageSlab(page));
84574+
84575 cachep = page->slab_cache;
84576 if (slab_equal_or_root(cachep, s))
84577 return cachep;
84578diff --git a/mm/slab_common.c b/mm/slab_common.c
84579index 3f3cd97..93b0236 100644
84580--- a/mm/slab_common.c
84581+++ b/mm/slab_common.c
84582@@ -22,7 +22,7 @@
84583
84584 #include "slab.h"
84585
84586-enum slab_state slab_state;
84587+enum slab_state slab_state __read_only;
84588 LIST_HEAD(slab_caches);
84589 DEFINE_MUTEX(slab_mutex);
84590 struct kmem_cache *kmem_cache;
84591@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
84592
84593 err = __kmem_cache_create(s, flags);
84594 if (!err) {
84595- s->refcount = 1;
84596+ atomic_set(&s->refcount, 1);
84597 list_add(&s->list, &slab_caches);
84598 memcg_cache_list_add(memcg, s);
84599 } else {
84600@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
84601
84602 get_online_cpus();
84603 mutex_lock(&slab_mutex);
84604- s->refcount--;
84605- if (!s->refcount) {
84606+ if (atomic_dec_and_test(&s->refcount)) {
84607 list_del(&s->list);
84608
84609 if (!__kmem_cache_shutdown(s)) {
84610@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
84611 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
84612 name, size, err);
84613
84614- s->refcount = -1; /* Exempt from merging for now */
84615+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
84616 }
84617
84618 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84619@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84620
84621 create_boot_cache(s, name, size, flags);
84622 list_add(&s->list, &slab_caches);
84623- s->refcount = 1;
84624+ atomic_set(&s->refcount, 1);
84625 return s;
84626 }
84627
84628diff --git a/mm/slob.c b/mm/slob.c
84629index eeed4a0..6ee34ec 100644
84630--- a/mm/slob.c
84631+++ b/mm/slob.c
84632@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
84633 /*
84634 * Return the size of a slob block.
84635 */
84636-static slobidx_t slob_units(slob_t *s)
84637+static slobidx_t slob_units(const slob_t *s)
84638 {
84639 if (s->units > 0)
84640 return s->units;
84641@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
84642 /*
84643 * Return the next free slob block pointer after this one.
84644 */
84645-static slob_t *slob_next(slob_t *s)
84646+static slob_t *slob_next(const slob_t *s)
84647 {
84648 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
84649 slobidx_t next;
84650@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
84651 /*
84652 * Returns true if s is the last free block in its page.
84653 */
84654-static int slob_last(slob_t *s)
84655+static int slob_last(const slob_t *s)
84656 {
84657 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
84658 }
84659
84660-static void *slob_new_pages(gfp_t gfp, int order, int node)
84661+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
84662 {
84663- void *page;
84664+ struct page *page;
84665
84666 #ifdef CONFIG_NUMA
84667 if (node != NUMA_NO_NODE)
84668@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
84669 if (!page)
84670 return NULL;
84671
84672- return page_address(page);
84673+ __SetPageSlab(page);
84674+ return page;
84675 }
84676
84677-static void slob_free_pages(void *b, int order)
84678+static void slob_free_pages(struct page *sp, int order)
84679 {
84680 if (current->reclaim_state)
84681 current->reclaim_state->reclaimed_slab += 1 << order;
84682- free_pages((unsigned long)b, order);
84683+ __ClearPageSlab(sp);
84684+ reset_page_mapcount(sp);
84685+ sp->private = 0;
84686+ __free_pages(sp, order);
84687 }
84688
84689 /*
84690@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
84691
84692 /* Not enough space: must allocate a new page */
84693 if (!b) {
84694- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84695- if (!b)
84696+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84697+ if (!sp)
84698 return NULL;
84699- sp = virt_to_page(b);
84700- __SetPageSlab(sp);
84701+ b = page_address(sp);
84702
84703 spin_lock_irqsave(&slob_lock, flags);
84704 sp->units = SLOB_UNITS(PAGE_SIZE);
84705 sp->freelist = b;
84706+ sp->private = 0;
84707 INIT_LIST_HEAD(&sp->list);
84708 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
84709 set_slob_page_free(sp, slob_list);
84710@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
84711 if (slob_page_free(sp))
84712 clear_slob_page_free(sp);
84713 spin_unlock_irqrestore(&slob_lock, flags);
84714- __ClearPageSlab(sp);
84715- page_mapcount_reset(sp);
84716- slob_free_pages(b, 0);
84717+ slob_free_pages(sp, 0);
84718 return;
84719 }
84720
84721@@ -424,11 +426,10 @@ out:
84722 */
84723
84724 static __always_inline void *
84725-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84726+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
84727 {
84728- unsigned int *m;
84729- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84730- void *ret;
84731+ slob_t *m;
84732+ void *ret = NULL;
84733
84734 gfp &= gfp_allowed_mask;
84735
84736@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84737
84738 if (!m)
84739 return NULL;
84740- *m = size;
84741+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
84742+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
84743+ m[0].units = size;
84744+ m[1].units = align;
84745 ret = (void *)m + align;
84746
84747 trace_kmalloc_node(caller, ret,
84748 size, size + align, gfp, node);
84749 } else {
84750 unsigned int order = get_order(size);
84751+ struct page *page;
84752
84753 if (likely(order))
84754 gfp |= __GFP_COMP;
84755- ret = slob_new_pages(gfp, order, node);
84756+ page = slob_new_pages(gfp, order, node);
84757+ if (page) {
84758+ ret = page_address(page);
84759+ page->private = size;
84760+ }
84761
84762 trace_kmalloc_node(caller, ret,
84763 size, PAGE_SIZE << order, gfp, node);
84764 }
84765
84766- kmemleak_alloc(ret, size, 1, gfp);
84767+ return ret;
84768+}
84769+
84770+static __always_inline void *
84771+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84772+{
84773+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84774+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
84775+
84776+ if (!ZERO_OR_NULL_PTR(ret))
84777+ kmemleak_alloc(ret, size, 1, gfp);
84778 return ret;
84779 }
84780
84781@@ -493,34 +512,112 @@ void kfree(const void *block)
84782 return;
84783 kmemleak_free(block);
84784
84785+ VM_BUG_ON(!virt_addr_valid(block));
84786 sp = virt_to_page(block);
84787- if (PageSlab(sp)) {
84788+ VM_BUG_ON(!PageSlab(sp));
84789+ if (!sp->private) {
84790 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84791- unsigned int *m = (unsigned int *)(block - align);
84792- slob_free(m, *m + align);
84793- } else
84794+ slob_t *m = (slob_t *)(block - align);
84795+ slob_free(m, m[0].units + align);
84796+ } else {
84797+ __ClearPageSlab(sp);
84798+ reset_page_mapcount(sp);
84799+ sp->private = 0;
84800 __free_pages(sp, compound_order(sp));
84801+ }
84802 }
84803 EXPORT_SYMBOL(kfree);
84804
84805+bool is_usercopy_object(const void *ptr)
84806+{
84807+ if (!slab_is_available())
84808+ return false;
84809+
84810+ // PAX: TODO
84811+
84812+ return false;
84813+}
84814+
84815+#ifdef CONFIG_PAX_USERCOPY
84816+const char *check_heap_object(const void *ptr, unsigned long n)
84817+{
84818+ struct page *page;
84819+ const slob_t *free;
84820+ const void *base;
84821+ unsigned long flags;
84822+
84823+ if (ZERO_OR_NULL_PTR(ptr))
84824+ return "<null>";
84825+
84826+ if (!virt_addr_valid(ptr))
84827+ return NULL;
84828+
84829+ page = virt_to_head_page(ptr);
84830+ if (!PageSlab(page))
84831+ return NULL;
84832+
84833+ if (page->private) {
84834+ base = page;
84835+ if (base <= ptr && n <= page->private - (ptr - base))
84836+ return NULL;
84837+ return "<slob>";
84838+ }
84839+
84840+ /* some tricky double walking to find the chunk */
84841+ spin_lock_irqsave(&slob_lock, flags);
84842+ base = (void *)((unsigned long)ptr & PAGE_MASK);
84843+ free = page->freelist;
84844+
84845+ while (!slob_last(free) && (void *)free <= ptr) {
84846+ base = free + slob_units(free);
84847+ free = slob_next(free);
84848+ }
84849+
84850+ while (base < (void *)free) {
84851+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
84852+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
84853+ int offset;
84854+
84855+ if (ptr < base + align)
84856+ break;
84857+
84858+ offset = ptr - base - align;
84859+ if (offset >= m) {
84860+ base += size;
84861+ continue;
84862+ }
84863+
84864+ if (n > m - offset)
84865+ break;
84866+
84867+ spin_unlock_irqrestore(&slob_lock, flags);
84868+ return NULL;
84869+ }
84870+
84871+ spin_unlock_irqrestore(&slob_lock, flags);
84872+ return "<slob>";
84873+}
84874+#endif
84875+
84876 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
84877 size_t ksize(const void *block)
84878 {
84879 struct page *sp;
84880 int align;
84881- unsigned int *m;
84882+ slob_t *m;
84883
84884 BUG_ON(!block);
84885 if (unlikely(block == ZERO_SIZE_PTR))
84886 return 0;
84887
84888 sp = virt_to_page(block);
84889- if (unlikely(!PageSlab(sp)))
84890- return PAGE_SIZE << compound_order(sp);
84891+ VM_BUG_ON(!PageSlab(sp));
84892+ if (sp->private)
84893+ return sp->private;
84894
84895 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84896- m = (unsigned int *)(block - align);
84897- return SLOB_UNITS(*m) * SLOB_UNIT;
84898+ m = (slob_t *)(block - align);
84899+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
84900 }
84901 EXPORT_SYMBOL(ksize);
84902
84903@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
84904
84905 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
84906 {
84907- void *b;
84908+ void *b = NULL;
84909
84910 flags &= gfp_allowed_mask;
84911
84912 lockdep_trace_alloc(flags);
84913
84914+#ifdef CONFIG_PAX_USERCOPY_SLABS
84915+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
84916+#else
84917 if (c->size < PAGE_SIZE) {
84918 b = slob_alloc(c->size, flags, c->align, node);
84919 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84920 SLOB_UNITS(c->size) * SLOB_UNIT,
84921 flags, node);
84922 } else {
84923- b = slob_new_pages(flags, get_order(c->size), node);
84924+ struct page *sp;
84925+
84926+ sp = slob_new_pages(flags, get_order(c->size), node);
84927+ if (sp) {
84928+ b = page_address(sp);
84929+ sp->private = c->size;
84930+ }
84931 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84932 PAGE_SIZE << get_order(c->size),
84933 flags, node);
84934 }
84935+#endif
84936
84937 if (c->ctor)
84938 c->ctor(b);
84939@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
84940
84941 static void __kmem_cache_free(void *b, int size)
84942 {
84943- if (size < PAGE_SIZE)
84944+ struct page *sp;
84945+
84946+ sp = virt_to_page(b);
84947+ BUG_ON(!PageSlab(sp));
84948+ if (!sp->private)
84949 slob_free(b, size);
84950 else
84951- slob_free_pages(b, get_order(size));
84952+ slob_free_pages(sp, get_order(size));
84953 }
84954
84955 static void kmem_rcu_free(struct rcu_head *head)
84956@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
84957
84958 void kmem_cache_free(struct kmem_cache *c, void *b)
84959 {
84960+ int size = c->size;
84961+
84962+#ifdef CONFIG_PAX_USERCOPY_SLABS
84963+ if (size + c->align < PAGE_SIZE) {
84964+ size += c->align;
84965+ b -= c->align;
84966+ }
84967+#endif
84968+
84969 kmemleak_free_recursive(b, c->flags);
84970 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
84971 struct slob_rcu *slob_rcu;
84972- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
84973- slob_rcu->size = c->size;
84974+ slob_rcu = b + (size - sizeof(struct slob_rcu));
84975+ slob_rcu->size = size;
84976 call_rcu(&slob_rcu->head, kmem_rcu_free);
84977 } else {
84978- __kmem_cache_free(b, c->size);
84979+ __kmem_cache_free(b, size);
84980 }
84981
84982+#ifdef CONFIG_PAX_USERCOPY_SLABS
84983+ trace_kfree(_RET_IP_, b);
84984+#else
84985 trace_kmem_cache_free(_RET_IP_, b);
84986+#endif
84987+
84988 }
84989 EXPORT_SYMBOL(kmem_cache_free);
84990
84991diff --git a/mm/slub.c b/mm/slub.c
84992index 4aec537..8043df1 100644
84993--- a/mm/slub.c
84994+++ b/mm/slub.c
84995@@ -197,7 +197,7 @@ struct track {
84996
84997 enum track_item { TRACK_ALLOC, TRACK_FREE };
84998
84999-#ifdef CONFIG_SYSFS
85000+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85001 static int sysfs_slab_add(struct kmem_cache *);
85002 static int sysfs_slab_alias(struct kmem_cache *, const char *);
85003 static void sysfs_slab_remove(struct kmem_cache *);
85004@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
85005 if (!t->addr)
85006 return;
85007
85008- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
85009+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
85010 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
85011 #ifdef CONFIG_STACKTRACE
85012 {
85013@@ -2653,7 +2653,7 @@ static int slub_min_objects;
85014 * Merge control. If this is set then no merging of slab caches will occur.
85015 * (Could be removed. This was introduced to pacify the merge skeptics.)
85016 */
85017-static int slub_nomerge;
85018+static int slub_nomerge = 1;
85019
85020 /*
85021 * Calculate the order of allocation given an slab object size.
85022@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
85023 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
85024 #endif
85025
85026+#ifdef CONFIG_PAX_USERCOPY_SLABS
85027+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
85028+#endif
85029+
85030 static int __init setup_slub_min_order(char *str)
85031 {
85032 get_option(&str, &slub_min_order);
85033@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
85034 return kmalloc_dma_caches[index];
85035
85036 #endif
85037+
85038+#ifdef CONFIG_PAX_USERCOPY_SLABS
85039+ if (flags & SLAB_USERCOPY)
85040+ return kmalloc_usercopy_caches[index];
85041+
85042+#endif
85043+
85044 return kmalloc_caches[index];
85045 }
85046
85047@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
85048 EXPORT_SYMBOL(__kmalloc_node);
85049 #endif
85050
85051+bool is_usercopy_object(const void *ptr)
85052+{
85053+ struct page *page;
85054+ struct kmem_cache *s;
85055+
85056+ if (ZERO_OR_NULL_PTR(ptr))
85057+ return false;
85058+
85059+ if (!slab_is_available())
85060+ return false;
85061+
85062+ if (!virt_addr_valid(ptr))
85063+ return false;
85064+
85065+ page = virt_to_head_page(ptr);
85066+
85067+ if (!PageSlab(page))
85068+ return false;
85069+
85070+ s = page->slab_cache;
85071+ return s->flags & SLAB_USERCOPY;
85072+}
85073+
85074+#ifdef CONFIG_PAX_USERCOPY
85075+const char *check_heap_object(const void *ptr, unsigned long n)
85076+{
85077+ struct page *page;
85078+ struct kmem_cache *s;
85079+ unsigned long offset;
85080+
85081+ if (ZERO_OR_NULL_PTR(ptr))
85082+ return "<null>";
85083+
85084+ if (!virt_addr_valid(ptr))
85085+ return NULL;
85086+
85087+ page = virt_to_head_page(ptr);
85088+
85089+ if (!PageSlab(page))
85090+ return NULL;
85091+
85092+ s = page->slab_cache;
85093+ if (!(s->flags & SLAB_USERCOPY))
85094+ return s->name;
85095+
85096+ offset = (ptr - page_address(page)) % s->size;
85097+ if (offset <= s->object_size && n <= s->object_size - offset)
85098+ return NULL;
85099+
85100+ return s->name;
85101+}
85102+#endif
85103+
85104 size_t ksize(const void *object)
85105 {
85106 struct page *page;
85107@@ -3404,6 +3468,7 @@ void kfree(const void *x)
85108 if (unlikely(ZERO_OR_NULL_PTR(x)))
85109 return;
85110
85111+ VM_BUG_ON(!virt_addr_valid(x));
85112 page = virt_to_head_page(x);
85113 if (unlikely(!PageSlab(page))) {
85114 BUG_ON(!PageCompound(page));
85115@@ -3712,17 +3777,17 @@ void __init kmem_cache_init(void)
85116
85117 /* Caches that are not of the two-to-the-power-of size */
85118 if (KMALLOC_MIN_SIZE <= 32) {
85119- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
85120+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
85121 caches++;
85122 }
85123
85124 if (KMALLOC_MIN_SIZE <= 64) {
85125- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
85126+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
85127 caches++;
85128 }
85129
85130 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
85131- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
85132+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
85133 caches++;
85134 }
85135
85136@@ -3764,6 +3829,22 @@ void __init kmem_cache_init(void)
85137 }
85138 }
85139 #endif
85140+
85141+#ifdef CONFIG_PAX_USERCOPY_SLABS
85142+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
85143+ struct kmem_cache *s = kmalloc_caches[i];
85144+
85145+ if (s && s->size) {
85146+ char *name = kasprintf(GFP_NOWAIT,
85147+ "usercopy-kmalloc-%d", s->object_size);
85148+
85149+ BUG_ON(!name);
85150+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
85151+ s->object_size, SLAB_USERCOPY);
85152+ }
85153+ }
85154+#endif
85155+
85156 printk(KERN_INFO
85157 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
85158 " CPUs=%d, Nodes=%d\n",
85159@@ -3790,7 +3871,7 @@ static int slab_unmergeable(struct kmem_cache *s)
85160 /*
85161 * We may have set a slab to be unmergeable during bootstrap.
85162 */
85163- if (s->refcount < 0)
85164+ if (atomic_read(&s->refcount) < 0)
85165 return 1;
85166
85167 return 0;
85168@@ -3848,7 +3929,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85169
85170 s = find_mergeable(memcg, size, align, flags, name, ctor);
85171 if (s) {
85172- s->refcount++;
85173+ atomic_inc(&s->refcount);
85174 /*
85175 * Adjust the object sizes so that we clear
85176 * the complete object on kzalloc.
85177@@ -3857,7 +3938,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85178 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
85179
85180 if (sysfs_slab_alias(s, name)) {
85181- s->refcount--;
85182+ atomic_dec(&s->refcount);
85183 s = NULL;
85184 }
85185 }
85186@@ -3919,7 +4000,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
85187 return NOTIFY_OK;
85188 }
85189
85190-static struct notifier_block __cpuinitdata slab_notifier = {
85191+static struct notifier_block slab_notifier = {
85192 .notifier_call = slab_cpuup_callback
85193 };
85194
85195@@ -3977,7 +4058,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
85196 }
85197 #endif
85198
85199-#ifdef CONFIG_SYSFS
85200+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85201 static int count_inuse(struct page *page)
85202 {
85203 return page->inuse;
85204@@ -4364,12 +4445,12 @@ static void resiliency_test(void)
85205 validate_slab_cache(kmalloc_caches[9]);
85206 }
85207 #else
85208-#ifdef CONFIG_SYSFS
85209+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85210 static void resiliency_test(void) {};
85211 #endif
85212 #endif
85213
85214-#ifdef CONFIG_SYSFS
85215+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85216 enum slab_stat_type {
85217 SL_ALL, /* All slabs */
85218 SL_PARTIAL, /* Only partially allocated slabs */
85219@@ -4613,7 +4694,7 @@ SLAB_ATTR_RO(ctor);
85220
85221 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
85222 {
85223- return sprintf(buf, "%d\n", s->refcount - 1);
85224+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
85225 }
85226 SLAB_ATTR_RO(aliases);
85227
85228@@ -5266,6 +5347,7 @@ static char *create_unique_id(struct kmem_cache *s)
85229 return name;
85230 }
85231
85232+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85233 static int sysfs_slab_add(struct kmem_cache *s)
85234 {
85235 int err;
85236@@ -5289,7 +5371,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
85237 }
85238
85239 s->kobj.kset = slab_kset;
85240- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
85241+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
85242 if (err) {
85243 kobject_put(&s->kobj);
85244 return err;
85245@@ -5323,6 +5405,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
85246 kobject_del(&s->kobj);
85247 kobject_put(&s->kobj);
85248 }
85249+#endif
85250
85251 /*
85252 * Need to buffer aliases during bootup until sysfs becomes
85253@@ -5336,6 +5419,7 @@ struct saved_alias {
85254
85255 static struct saved_alias *alias_list;
85256
85257+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85258 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85259 {
85260 struct saved_alias *al;
85261@@ -5358,6 +5442,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85262 alias_list = al;
85263 return 0;
85264 }
85265+#endif
85266
85267 static int __init slab_sysfs_init(void)
85268 {
85269diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
85270index 1b7e22a..3fcd4f3 100644
85271--- a/mm/sparse-vmemmap.c
85272+++ b/mm/sparse-vmemmap.c
85273@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
85274 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85275 if (!p)
85276 return NULL;
85277- pud_populate(&init_mm, pud, p);
85278+ pud_populate_kernel(&init_mm, pud, p);
85279 }
85280 return pud;
85281 }
85282@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
85283 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85284 if (!p)
85285 return NULL;
85286- pgd_populate(&init_mm, pgd, p);
85287+ pgd_populate_kernel(&init_mm, pgd, p);
85288 }
85289 return pgd;
85290 }
85291diff --git a/mm/sparse.c b/mm/sparse.c
85292index 7ca6dc8..6472aa1 100644
85293--- a/mm/sparse.c
85294+++ b/mm/sparse.c
85295@@ -783,7 +783,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
85296
85297 for (i = 0; i < PAGES_PER_SECTION; i++) {
85298 if (PageHWPoison(&memmap[i])) {
85299- atomic_long_sub(1, &num_poisoned_pages);
85300+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
85301 ClearPageHWPoison(&memmap[i]);
85302 }
85303 }
85304diff --git a/mm/swap.c b/mm/swap.c
85305index 8a529a0..154ef26 100644
85306--- a/mm/swap.c
85307+++ b/mm/swap.c
85308@@ -30,6 +30,7 @@
85309 #include <linux/backing-dev.h>
85310 #include <linux/memcontrol.h>
85311 #include <linux/gfp.h>
85312+#include <linux/hugetlb.h>
85313
85314 #include "internal.h"
85315
85316@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
85317
85318 __page_cache_release(page);
85319 dtor = get_compound_page_dtor(page);
85320+ if (!PageHuge(page))
85321+ BUG_ON(dtor != free_compound_page);
85322 (*dtor)(page);
85323 }
85324
85325diff --git a/mm/swapfile.c b/mm/swapfile.c
85326index a1f7772..9e982ac 100644
85327--- a/mm/swapfile.c
85328+++ b/mm/swapfile.c
85329@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
85330
85331 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
85332 /* Activity counter to indicate that a swapon or swapoff has occurred */
85333-static atomic_t proc_poll_event = ATOMIC_INIT(0);
85334+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
85335
85336 static inline unsigned char swap_count(unsigned char ent)
85337 {
85338@@ -1683,7 +1683,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
85339 }
85340 filp_close(swap_file, NULL);
85341 err = 0;
85342- atomic_inc(&proc_poll_event);
85343+ atomic_inc_unchecked(&proc_poll_event);
85344 wake_up_interruptible(&proc_poll_wait);
85345
85346 out_dput:
85347@@ -1700,8 +1700,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
85348
85349 poll_wait(file, &proc_poll_wait, wait);
85350
85351- if (seq->poll_event != atomic_read(&proc_poll_event)) {
85352- seq->poll_event = atomic_read(&proc_poll_event);
85353+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
85354+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85355 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
85356 }
85357
85358@@ -1799,7 +1799,7 @@ static int swaps_open(struct inode *inode, struct file *file)
85359 return ret;
85360
85361 seq = file->private_data;
85362- seq->poll_event = atomic_read(&proc_poll_event);
85363+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85364 return 0;
85365 }
85366
85367@@ -2142,7 +2142,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
85368 (frontswap_map) ? "FS" : "");
85369
85370 mutex_unlock(&swapon_mutex);
85371- atomic_inc(&proc_poll_event);
85372+ atomic_inc_unchecked(&proc_poll_event);
85373 wake_up_interruptible(&proc_poll_wait);
85374
85375 if (S_ISREG(inode->i_mode))
85376diff --git a/mm/util.c b/mm/util.c
85377index ab1424d..7c5bd5a 100644
85378--- a/mm/util.c
85379+++ b/mm/util.c
85380@@ -294,6 +294,12 @@ done:
85381 void arch_pick_mmap_layout(struct mm_struct *mm)
85382 {
85383 mm->mmap_base = TASK_UNMAPPED_BASE;
85384+
85385+#ifdef CONFIG_PAX_RANDMMAP
85386+ if (mm->pax_flags & MF_PAX_RANDMMAP)
85387+ mm->mmap_base += mm->delta_mmap;
85388+#endif
85389+
85390 mm->get_unmapped_area = arch_get_unmapped_area;
85391 mm->unmap_area = arch_unmap_area;
85392 }
85393diff --git a/mm/vmalloc.c b/mm/vmalloc.c
85394index 0f751f2..2bc3bd1 100644
85395--- a/mm/vmalloc.c
85396+++ b/mm/vmalloc.c
85397@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
85398
85399 pte = pte_offset_kernel(pmd, addr);
85400 do {
85401- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85402- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85403+
85404+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85405+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
85406+ BUG_ON(!pte_exec(*pte));
85407+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
85408+ continue;
85409+ }
85410+#endif
85411+
85412+ {
85413+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85414+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85415+ }
85416 } while (pte++, addr += PAGE_SIZE, addr != end);
85417 }
85418
85419@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
85420 pte = pte_alloc_kernel(pmd, addr);
85421 if (!pte)
85422 return -ENOMEM;
85423+
85424+ pax_open_kernel();
85425 do {
85426 struct page *page = pages[*nr];
85427
85428- if (WARN_ON(!pte_none(*pte)))
85429+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85430+ if (pgprot_val(prot) & _PAGE_NX)
85431+#endif
85432+
85433+ if (!pte_none(*pte)) {
85434+ pax_close_kernel();
85435+ WARN_ON(1);
85436 return -EBUSY;
85437- if (WARN_ON(!page))
85438+ }
85439+ if (!page) {
85440+ pax_close_kernel();
85441+ WARN_ON(1);
85442 return -ENOMEM;
85443+ }
85444 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
85445 (*nr)++;
85446 } while (pte++, addr += PAGE_SIZE, addr != end);
85447+ pax_close_kernel();
85448 return 0;
85449 }
85450
85451@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
85452 pmd_t *pmd;
85453 unsigned long next;
85454
85455- pmd = pmd_alloc(&init_mm, pud, addr);
85456+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85457 if (!pmd)
85458 return -ENOMEM;
85459 do {
85460@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
85461 pud_t *pud;
85462 unsigned long next;
85463
85464- pud = pud_alloc(&init_mm, pgd, addr);
85465+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85466 if (!pud)
85467 return -ENOMEM;
85468 do {
85469@@ -196,6 +220,12 @@ int is_vmalloc_or_module_addr(const void *x)
85470 if (addr >= MODULES_VADDR && addr < MODULES_END)
85471 return 1;
85472 #endif
85473+
85474+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85475+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
85476+ return 1;
85477+#endif
85478+
85479 return is_vmalloc_addr(x);
85480 }
85481
85482@@ -216,8 +246,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
85483
85484 if (!pgd_none(*pgd)) {
85485 pud_t *pud = pud_offset(pgd, addr);
85486+#ifdef CONFIG_X86
85487+ if (!pud_large(*pud))
85488+#endif
85489 if (!pud_none(*pud)) {
85490 pmd_t *pmd = pmd_offset(pud, addr);
85491+#ifdef CONFIG_X86
85492+ if (!pmd_large(*pmd))
85493+#endif
85494 if (!pmd_none(*pmd)) {
85495 pte_t *ptep, pte;
85496
85497@@ -329,7 +365,7 @@ static void purge_vmap_area_lazy(void);
85498 * Allocate a region of KVA of the specified size and alignment, within the
85499 * vstart and vend.
85500 */
85501-static struct vmap_area *alloc_vmap_area(unsigned long size,
85502+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
85503 unsigned long align,
85504 unsigned long vstart, unsigned long vend,
85505 int node, gfp_t gfp_mask)
85506@@ -1328,6 +1364,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
85507 struct vm_struct *area;
85508
85509 BUG_ON(in_interrupt());
85510+
85511+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85512+ if (flags & VM_KERNEXEC) {
85513+ if (start != VMALLOC_START || end != VMALLOC_END)
85514+ return NULL;
85515+ start = (unsigned long)MODULES_EXEC_VADDR;
85516+ end = (unsigned long)MODULES_EXEC_END;
85517+ }
85518+#endif
85519+
85520 if (flags & VM_IOREMAP) {
85521 int bit = fls(size);
85522
85523@@ -1569,6 +1615,11 @@ void *vmap(struct page **pages, unsigned int count,
85524 if (count > totalram_pages)
85525 return NULL;
85526
85527+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85528+ if (!(pgprot_val(prot) & _PAGE_NX))
85529+ flags |= VM_KERNEXEC;
85530+#endif
85531+
85532 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
85533 __builtin_return_address(0));
85534 if (!area)
85535@@ -1670,6 +1721,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
85536 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
85537 goto fail;
85538
85539+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85540+ if (!(pgprot_val(prot) & _PAGE_NX))
85541+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
85542+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
85543+ else
85544+#endif
85545+
85546 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
85547 start, end, node, gfp_mask, caller);
85548 if (!area)
85549@@ -1845,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
85550 * For tight control over page level allocator and protection flags
85551 * use __vmalloc() instead.
85552 */
85553-
85554 void *vmalloc_exec(unsigned long size)
85555 {
85556- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
85557+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
85558 NUMA_NO_NODE, __builtin_return_address(0));
85559 }
85560
85561@@ -2139,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
85562 unsigned long uaddr = vma->vm_start;
85563 unsigned long usize = vma->vm_end - vma->vm_start;
85564
85565+ BUG_ON(vma->vm_mirror);
85566+
85567 if ((PAGE_SIZE-1) & (unsigned long)addr)
85568 return -EINVAL;
85569
85570@@ -2578,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
85571 v->addr, v->addr + v->size, v->size);
85572
85573 if (v->caller)
85574+#ifdef CONFIG_GRKERNSEC_HIDESYM
85575+ seq_printf(m, " %pK", v->caller);
85576+#else
85577 seq_printf(m, " %pS", v->caller);
85578+#endif
85579
85580 if (v->nr_pages)
85581 seq_printf(m, " pages=%d", v->nr_pages);
85582diff --git a/mm/vmstat.c b/mm/vmstat.c
85583index e1d8ed1..253fa3c 100644
85584--- a/mm/vmstat.c
85585+++ b/mm/vmstat.c
85586@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
85587 *
85588 * vm_stat contains the global counters
85589 */
85590-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85591+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85592 EXPORT_SYMBOL(vm_stat);
85593
85594 #ifdef CONFIG_SMP
85595@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
85596 v = p->vm_stat_diff[i];
85597 p->vm_stat_diff[i] = 0;
85598 local_irq_restore(flags);
85599- atomic_long_add(v, &zone->vm_stat[i]);
85600+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85601 global_diff[i] += v;
85602 #ifdef CONFIG_NUMA
85603 /* 3 seconds idle till flush */
85604@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
85605
85606 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
85607 if (global_diff[i])
85608- atomic_long_add(global_diff[i], &vm_stat[i]);
85609+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
85610 }
85611
85612 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85613@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85614 if (pset->vm_stat_diff[i]) {
85615 int v = pset->vm_stat_diff[i];
85616 pset->vm_stat_diff[i] = 0;
85617- atomic_long_add(v, &zone->vm_stat[i]);
85618- atomic_long_add(v, &vm_stat[i]);
85619+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85620+ atomic_long_add_unchecked(v, &vm_stat[i]);
85621 }
85622 }
85623 #endif
85624@@ -1224,7 +1224,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
85625 return NOTIFY_OK;
85626 }
85627
85628-static struct notifier_block __cpuinitdata vmstat_notifier =
85629+static struct notifier_block vmstat_notifier =
85630 { &vmstat_cpuup_callback, NULL, 0 };
85631 #endif
85632
85633@@ -1239,10 +1239,20 @@ static int __init setup_vmstat(void)
85634 start_cpu_timer(cpu);
85635 #endif
85636 #ifdef CONFIG_PROC_FS
85637- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
85638- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
85639- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
85640- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
85641+ {
85642+ mode_t gr_mode = S_IRUGO;
85643+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85644+ gr_mode = S_IRUSR;
85645+#endif
85646+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
85647+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
85648+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85649+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
85650+#else
85651+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
85652+#endif
85653+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
85654+ }
85655 #endif
85656 return 0;
85657 }
85658diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
85659index 85addcd..c429a13 100644
85660--- a/net/8021q/vlan.c
85661+++ b/net/8021q/vlan.c
85662@@ -114,6 +114,13 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
85663 if (vlan_id)
85664 vlan_vid_del(real_dev, vlan_id);
85665
85666+ /* Take it out of our own structures, but be sure to interlock with
85667+ * HW accelerating devices or SW vlan input packet processing if
85668+ * VLAN is not 0 (leave it there for 802.1p).
85669+ */
85670+ if (vlan_id)
85671+ vlan_vid_del(real_dev, vlan_id);
85672+
85673 /* Get rid of the vlan's reference to real_dev */
85674 dev_put(real_dev);
85675 }
85676@@ -496,7 +503,7 @@ out:
85677 return NOTIFY_DONE;
85678 }
85679
85680-static struct notifier_block vlan_notifier_block __read_mostly = {
85681+static struct notifier_block vlan_notifier_block = {
85682 .notifier_call = vlan_device_event,
85683 };
85684
85685@@ -571,8 +578,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
85686 err = -EPERM;
85687 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
85688 break;
85689- if ((args.u.name_type >= 0) &&
85690- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
85691+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
85692 struct vlan_net *vn;
85693
85694 vn = net_generic(net, vlan_net_id);
85695diff --git a/net/9p/mod.c b/net/9p/mod.c
85696index 6ab36ae..6f1841b 100644
85697--- a/net/9p/mod.c
85698+++ b/net/9p/mod.c
85699@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
85700 void v9fs_register_trans(struct p9_trans_module *m)
85701 {
85702 spin_lock(&v9fs_trans_lock);
85703- list_add_tail(&m->list, &v9fs_trans_list);
85704+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
85705 spin_unlock(&v9fs_trans_lock);
85706 }
85707 EXPORT_SYMBOL(v9fs_register_trans);
85708@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
85709 void v9fs_unregister_trans(struct p9_trans_module *m)
85710 {
85711 spin_lock(&v9fs_trans_lock);
85712- list_del_init(&m->list);
85713+ pax_list_del_init((struct list_head *)&m->list);
85714 spin_unlock(&v9fs_trans_lock);
85715 }
85716 EXPORT_SYMBOL(v9fs_unregister_trans);
85717diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
85718index 02efb25..41541a9 100644
85719--- a/net/9p/trans_fd.c
85720+++ b/net/9p/trans_fd.c
85721@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
85722 oldfs = get_fs();
85723 set_fs(get_ds());
85724 /* The cast to a user pointer is valid due to the set_fs() */
85725- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
85726+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
85727 set_fs(oldfs);
85728
85729 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
85730diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
85731index 876fbe8..8bbea9f 100644
85732--- a/net/atm/atm_misc.c
85733+++ b/net/atm/atm_misc.c
85734@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
85735 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
85736 return 1;
85737 atm_return(vcc, truesize);
85738- atomic_inc(&vcc->stats->rx_drop);
85739+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85740 return 0;
85741 }
85742 EXPORT_SYMBOL(atm_charge);
85743@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
85744 }
85745 }
85746 atm_return(vcc, guess);
85747- atomic_inc(&vcc->stats->rx_drop);
85748+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85749 return NULL;
85750 }
85751 EXPORT_SYMBOL(atm_alloc_charge);
85752@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
85753
85754 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85755 {
85756-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85757+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85758 __SONET_ITEMS
85759 #undef __HANDLE_ITEM
85760 }
85761@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
85762
85763 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85764 {
85765-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85766+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
85767 __SONET_ITEMS
85768 #undef __HANDLE_ITEM
85769 }
85770diff --git a/net/atm/lec.h b/net/atm/lec.h
85771index a86aff9..3a0d6f6 100644
85772--- a/net/atm/lec.h
85773+++ b/net/atm/lec.h
85774@@ -48,7 +48,7 @@ struct lane2_ops {
85775 const u8 *tlvs, u32 sizeoftlvs);
85776 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
85777 const u8 *tlvs, u32 sizeoftlvs);
85778-};
85779+} __no_const;
85780
85781 /*
85782 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
85783diff --git a/net/atm/proc.c b/net/atm/proc.c
85784index 6ac35ff..ac0e136 100644
85785--- a/net/atm/proc.c
85786+++ b/net/atm/proc.c
85787@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
85788 const struct k_atm_aal_stats *stats)
85789 {
85790 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
85791- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
85792- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
85793- atomic_read(&stats->rx_drop));
85794+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
85795+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
85796+ atomic_read_unchecked(&stats->rx_drop));
85797 }
85798
85799 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
85800diff --git a/net/atm/resources.c b/net/atm/resources.c
85801index 0447d5d..3cf4728 100644
85802--- a/net/atm/resources.c
85803+++ b/net/atm/resources.c
85804@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
85805 static void copy_aal_stats(struct k_atm_aal_stats *from,
85806 struct atm_aal_stats *to)
85807 {
85808-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85809+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85810 __AAL_STAT_ITEMS
85811 #undef __HANDLE_ITEM
85812 }
85813@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
85814 static void subtract_aal_stats(struct k_atm_aal_stats *from,
85815 struct atm_aal_stats *to)
85816 {
85817-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85818+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
85819 __AAL_STAT_ITEMS
85820 #undef __HANDLE_ITEM
85821 }
85822diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
85823index d5744b7..506bae3 100644
85824--- a/net/ax25/sysctl_net_ax25.c
85825+++ b/net/ax25/sysctl_net_ax25.c
85826@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
85827 {
85828 char path[sizeof("net/ax25/") + IFNAMSIZ];
85829 int k;
85830- struct ctl_table *table;
85831+ ctl_table_no_const *table;
85832
85833 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
85834 if (!table)
85835diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
85836index a5bb0a7..e1d8b97 100644
85837--- a/net/batman-adv/bat_iv_ogm.c
85838+++ b/net/batman-adv/bat_iv_ogm.c
85839@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
85840
85841 /* randomize initial seqno to avoid collision */
85842 get_random_bytes(&random_seqno, sizeof(random_seqno));
85843- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85844+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85845
85846 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
85847 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
85848@@ -611,9 +611,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
85849 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
85850
85851 /* change sequence number to network order */
85852- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
85853+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
85854 batadv_ogm_packet->seqno = htonl(seqno);
85855- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
85856+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
85857
85858 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
85859 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
85860@@ -1013,7 +1013,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
85861 return;
85862
85863 /* could be changed by schedule_own_packet() */
85864- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
85865+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
85866
85867 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
85868 has_directlink_flag = 1;
85869diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
85870index 368219e..53f56f9 100644
85871--- a/net/batman-adv/hard-interface.c
85872+++ b/net/batman-adv/hard-interface.c
85873@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
85874 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
85875 dev_add_pack(&hard_iface->batman_adv_ptype);
85876
85877- atomic_set(&hard_iface->frag_seqno, 1);
85878+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
85879 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
85880 hard_iface->net_dev->name);
85881
85882@@ -514,7 +514,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
85883 /* This can't be called via a bat_priv callback because
85884 * we have no bat_priv yet.
85885 */
85886- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
85887+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
85888 hard_iface->bat_iv.ogm_buff = NULL;
85889
85890 return hard_iface;
85891diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
85892index 2711e87..4ca48fa 100644
85893--- a/net/batman-adv/soft-interface.c
85894+++ b/net/batman-adv/soft-interface.c
85895@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
85896 primary_if->net_dev->dev_addr, ETH_ALEN);
85897
85898 /* set broadcast sequence number */
85899- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
85900+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
85901 bcast_packet->seqno = htonl(seqno);
85902
85903 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
85904@@ -527,7 +527,7 @@ struct net_device *batadv_softif_create(const char *name)
85905 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
85906
85907 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
85908- atomic_set(&bat_priv->bcast_seqno, 1);
85909+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
85910 atomic_set(&bat_priv->tt.vn, 0);
85911 atomic_set(&bat_priv->tt.local_changes, 0);
85912 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
85913diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
85914index 4cd87a0..348e705 100644
85915--- a/net/batman-adv/types.h
85916+++ b/net/batman-adv/types.h
85917@@ -51,7 +51,7 @@
85918 struct batadv_hard_iface_bat_iv {
85919 unsigned char *ogm_buff;
85920 int ogm_buff_len;
85921- atomic_t ogm_seqno;
85922+ atomic_unchecked_t ogm_seqno;
85923 };
85924
85925 /**
85926@@ -75,7 +75,7 @@ struct batadv_hard_iface {
85927 int16_t if_num;
85928 char if_status;
85929 struct net_device *net_dev;
85930- atomic_t frag_seqno;
85931+ atomic_unchecked_t frag_seqno;
85932 struct kobject *hardif_obj;
85933 atomic_t refcount;
85934 struct packet_type batman_adv_ptype;
85935@@ -495,7 +495,7 @@ struct batadv_priv {
85936 #ifdef CONFIG_BATMAN_ADV_DEBUG
85937 atomic_t log_level;
85938 #endif
85939- atomic_t bcast_seqno;
85940+ atomic_unchecked_t bcast_seqno;
85941 atomic_t bcast_queue_left;
85942 atomic_t batman_queue_left;
85943 char num_ifaces;
85944diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
85945index 50e079f..49ce2d2 100644
85946--- a/net/batman-adv/unicast.c
85947+++ b/net/batman-adv/unicast.c
85948@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
85949 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
85950 frag2->flags = large_tail;
85951
85952- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
85953+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
85954 frag1->seqno = htons(seqno - 1);
85955 frag2->seqno = htons(seqno);
85956
85957diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
85958index b88605f..958e3e2 100644
85959--- a/net/bluetooth/hci_core.c
85960+++ b/net/bluetooth/hci_core.c
85961@@ -1793,16 +1793,16 @@ int hci_register_dev(struct hci_dev *hdev)
85962 list_add(&hdev->list, &hci_dev_list);
85963 write_unlock(&hci_dev_list_lock);
85964
85965- hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND |
85966- WQ_MEM_RECLAIM, 1);
85967+ hdev->workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
85968+ WQ_MEM_RECLAIM, 1, hdev->name);
85969 if (!hdev->workqueue) {
85970 error = -ENOMEM;
85971 goto err;
85972 }
85973
85974- hdev->req_workqueue = alloc_workqueue(hdev->name,
85975+ hdev->req_workqueue = alloc_workqueue("%s",
85976 WQ_HIGHPRI | WQ_UNBOUND |
85977- WQ_MEM_RECLAIM, 1);
85978+ WQ_MEM_RECLAIM, 1, hdev->name);
85979 if (!hdev->req_workqueue) {
85980 destroy_workqueue(hdev->workqueue);
85981 error = -ENOMEM;
85982diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
85983index 6a93614..1415549 100644
85984--- a/net/bluetooth/hci_sock.c
85985+++ b/net/bluetooth/hci_sock.c
85986@@ -929,7 +929,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
85987 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
85988 }
85989
85990- len = min_t(unsigned int, len, sizeof(uf));
85991+ len = min((size_t)len, sizeof(uf));
85992 if (copy_from_user(&uf, optval, len)) {
85993 err = -EFAULT;
85994 break;
85995diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
85996index 04b32e1..dfc8ec1 100644
85997--- a/net/bluetooth/l2cap_core.c
85998+++ b/net/bluetooth/l2cap_core.c
85999@@ -3398,8 +3398,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
86000 break;
86001
86002 case L2CAP_CONF_RFC:
86003- if (olen == sizeof(rfc))
86004- memcpy(&rfc, (void *)val, olen);
86005+ if (olen != sizeof(rfc))
86006+ break;
86007+
86008+ memcpy(&rfc, (void *)val, olen);
86009
86010 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
86011 rfc.mode != chan->mode)
86012diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
86013index 1bcfb84..dad9f98 100644
86014--- a/net/bluetooth/l2cap_sock.c
86015+++ b/net/bluetooth/l2cap_sock.c
86016@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
86017 struct sock *sk = sock->sk;
86018 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
86019 struct l2cap_options opts;
86020- int len, err = 0;
86021+ int err = 0;
86022+ size_t len = optlen;
86023 u32 opt;
86024
86025 BT_DBG("sk %p", sk);
86026@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
86027 opts.max_tx = chan->max_tx;
86028 opts.txwin_size = chan->tx_win;
86029
86030- len = min_t(unsigned int, sizeof(opts), optlen);
86031+ len = min(sizeof(opts), len);
86032 if (copy_from_user((char *) &opts, optval, len)) {
86033 err = -EFAULT;
86034 break;
86035@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86036 struct bt_security sec;
86037 struct bt_power pwr;
86038 struct l2cap_conn *conn;
86039- int len, err = 0;
86040+ int err = 0;
86041+ size_t len = optlen;
86042 u32 opt;
86043
86044 BT_DBG("sk %p", sk);
86045@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86046
86047 sec.level = BT_SECURITY_LOW;
86048
86049- len = min_t(unsigned int, sizeof(sec), optlen);
86050+ len = min(sizeof(sec), len);
86051 if (copy_from_user((char *) &sec, optval, len)) {
86052 err = -EFAULT;
86053 break;
86054@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86055
86056 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
86057
86058- len = min_t(unsigned int, sizeof(pwr), optlen);
86059+ len = min(sizeof(pwr), len);
86060 if (copy_from_user((char *) &pwr, optval, len)) {
86061 err = -EFAULT;
86062 break;
86063diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
86064index 7c9224b..381009e 100644
86065--- a/net/bluetooth/rfcomm/sock.c
86066+++ b/net/bluetooth/rfcomm/sock.c
86067@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
86068 struct sock *sk = sock->sk;
86069 struct bt_security sec;
86070 int err = 0;
86071- size_t len;
86072+ size_t len = optlen;
86073 u32 opt;
86074
86075 BT_DBG("sk %p", sk);
86076@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
86077
86078 sec.level = BT_SECURITY_LOW;
86079
86080- len = min_t(unsigned int, sizeof(sec), optlen);
86081+ len = min(sizeof(sec), len);
86082 if (copy_from_user((char *) &sec, optval, len)) {
86083 err = -EFAULT;
86084 break;
86085diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
86086index b6e44ad..5b0d514 100644
86087--- a/net/bluetooth/rfcomm/tty.c
86088+++ b/net/bluetooth/rfcomm/tty.c
86089@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
86090 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
86091
86092 spin_lock_irqsave(&dev->port.lock, flags);
86093- if (dev->port.count > 0) {
86094+ if (atomic_read(&dev->port.count) > 0) {
86095 spin_unlock_irqrestore(&dev->port.lock, flags);
86096 return;
86097 }
86098@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
86099 return -ENODEV;
86100
86101 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
86102- dev->channel, dev->port.count);
86103+ dev->channel, atomic_read(&dev->port.count));
86104
86105 spin_lock_irqsave(&dev->port.lock, flags);
86106- if (++dev->port.count > 1) {
86107+ if (atomic_inc_return(&dev->port.count) > 1) {
86108 spin_unlock_irqrestore(&dev->port.lock, flags);
86109 return 0;
86110 }
86111@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
86112 return;
86113
86114 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
86115- dev->port.count);
86116+ atomic_read(&dev->port.count));
86117
86118 spin_lock_irqsave(&dev->port.lock, flags);
86119- if (!--dev->port.count) {
86120+ if (!atomic_dec_return(&dev->port.count)) {
86121 spin_unlock_irqrestore(&dev->port.lock, flags);
86122 if (dev->tty_dev->parent)
86123 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
86124diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
86125index 8d493c9..3849e49 100644
86126--- a/net/bridge/netfilter/ebtables.c
86127+++ b/net/bridge/netfilter/ebtables.c
86128@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86129 tmp.valid_hooks = t->table->valid_hooks;
86130 }
86131 mutex_unlock(&ebt_mutex);
86132- if (copy_to_user(user, &tmp, *len) != 0){
86133+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
86134 BUGPRINT("c2u Didn't work\n");
86135 ret = -EFAULT;
86136 break;
86137@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
86138 goto out;
86139 tmp.valid_hooks = t->valid_hooks;
86140
86141- if (copy_to_user(user, &tmp, *len) != 0) {
86142+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
86143 ret = -EFAULT;
86144 break;
86145 }
86146@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
86147 tmp.entries_size = t->table->entries_size;
86148 tmp.valid_hooks = t->table->valid_hooks;
86149
86150- if (copy_to_user(user, &tmp, *len) != 0) {
86151+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
86152 ret = -EFAULT;
86153 break;
86154 }
86155diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
86156index a376ec1..1fbd6be 100644
86157--- a/net/caif/cfctrl.c
86158+++ b/net/caif/cfctrl.c
86159@@ -10,6 +10,7 @@
86160 #include <linux/spinlock.h>
86161 #include <linux/slab.h>
86162 #include <linux/pkt_sched.h>
86163+#include <linux/sched.h>
86164 #include <net/caif/caif_layer.h>
86165 #include <net/caif/cfpkt.h>
86166 #include <net/caif/cfctrl.h>
86167@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
86168 memset(&dev_info, 0, sizeof(dev_info));
86169 dev_info.id = 0xff;
86170 cfsrvl_init(&this->serv, 0, &dev_info, false);
86171- atomic_set(&this->req_seq_no, 1);
86172- atomic_set(&this->rsp_seq_no, 1);
86173+ atomic_set_unchecked(&this->req_seq_no, 1);
86174+ atomic_set_unchecked(&this->rsp_seq_no, 1);
86175 this->serv.layer.receive = cfctrl_recv;
86176 sprintf(this->serv.layer.name, "ctrl");
86177 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
86178@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
86179 struct cfctrl_request_info *req)
86180 {
86181 spin_lock_bh(&ctrl->info_list_lock);
86182- atomic_inc(&ctrl->req_seq_no);
86183- req->sequence_no = atomic_read(&ctrl->req_seq_no);
86184+ atomic_inc_unchecked(&ctrl->req_seq_no);
86185+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
86186 list_add_tail(&req->list, &ctrl->list);
86187 spin_unlock_bh(&ctrl->info_list_lock);
86188 }
86189@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
86190 if (p != first)
86191 pr_warn("Requests are not received in order\n");
86192
86193- atomic_set(&ctrl->rsp_seq_no,
86194+ atomic_set_unchecked(&ctrl->rsp_seq_no,
86195 p->sequence_no);
86196 list_del(&p->list);
86197 goto out;
86198diff --git a/net/can/af_can.c b/net/can/af_can.c
86199index c48e522..1223690 100644
86200--- a/net/can/af_can.c
86201+++ b/net/can/af_can.c
86202@@ -870,7 +870,7 @@ static const struct net_proto_family can_family_ops = {
86203 };
86204
86205 /* notifier block for netdevice event */
86206-static struct notifier_block can_netdev_notifier __read_mostly = {
86207+static struct notifier_block can_netdev_notifier = {
86208 .notifier_call = can_notifier,
86209 };
86210
86211diff --git a/net/can/gw.c b/net/can/gw.c
86212index 117814a..ad4fb73 100644
86213--- a/net/can/gw.c
86214+++ b/net/can/gw.c
86215@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
86216 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
86217
86218 static HLIST_HEAD(cgw_list);
86219-static struct notifier_block notifier;
86220
86221 static struct kmem_cache *cgw_cache __read_mostly;
86222
86223@@ -928,6 +927,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
86224 return err;
86225 }
86226
86227+static struct notifier_block notifier = {
86228+ .notifier_call = cgw_notifier
86229+};
86230+
86231 static __init int cgw_module_init(void)
86232 {
86233 /* sanitize given module parameter */
86234@@ -943,7 +946,6 @@ static __init int cgw_module_init(void)
86235 return -ENOMEM;
86236
86237 /* set notifier */
86238- notifier.notifier_call = cgw_notifier;
86239 register_netdevice_notifier(&notifier);
86240
86241 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
86242diff --git a/net/compat.c b/net/compat.c
86243index f0a1ba6..0541331 100644
86244--- a/net/compat.c
86245+++ b/net/compat.c
86246@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
86247 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
86248 __get_user(kmsg->msg_flags, &umsg->msg_flags))
86249 return -EFAULT;
86250- kmsg->msg_name = compat_ptr(tmp1);
86251- kmsg->msg_iov = compat_ptr(tmp2);
86252- kmsg->msg_control = compat_ptr(tmp3);
86253+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
86254+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
86255+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
86256 return 0;
86257 }
86258
86259@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86260
86261 if (kern_msg->msg_namelen) {
86262 if (mode == VERIFY_READ) {
86263- int err = move_addr_to_kernel(kern_msg->msg_name,
86264+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
86265 kern_msg->msg_namelen,
86266 kern_address);
86267 if (err < 0)
86268@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86269 kern_msg->msg_name = NULL;
86270
86271 tot_len = iov_from_user_compat_to_kern(kern_iov,
86272- (struct compat_iovec __user *)kern_msg->msg_iov,
86273+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
86274 kern_msg->msg_iovlen);
86275 if (tot_len >= 0)
86276 kern_msg->msg_iov = kern_iov;
86277@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86278
86279 #define CMSG_COMPAT_FIRSTHDR(msg) \
86280 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
86281- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
86282+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
86283 (struct compat_cmsghdr __user *)NULL)
86284
86285 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
86286 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
86287 (ucmlen) <= (unsigned long) \
86288 ((mhdr)->msg_controllen - \
86289- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
86290+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
86291
86292 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
86293 struct compat_cmsghdr __user *cmsg, int cmsg_len)
86294 {
86295 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
86296- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
86297+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
86298 msg->msg_controllen)
86299 return NULL;
86300 return (struct compat_cmsghdr __user *)ptr;
86301@@ -219,7 +219,7 @@ Efault:
86302
86303 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
86304 {
86305- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86306+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86307 struct compat_cmsghdr cmhdr;
86308 struct compat_timeval ctv;
86309 struct compat_timespec cts[3];
86310@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
86311
86312 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
86313 {
86314- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86315+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86316 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
86317 int fdnum = scm->fp->count;
86318 struct file **fp = scm->fp->fp;
86319@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
86320 return -EFAULT;
86321 old_fs = get_fs();
86322 set_fs(KERNEL_DS);
86323- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
86324+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
86325 set_fs(old_fs);
86326
86327 return err;
86328@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
86329 len = sizeof(ktime);
86330 old_fs = get_fs();
86331 set_fs(KERNEL_DS);
86332- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
86333+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
86334 set_fs(old_fs);
86335
86336 if (!err) {
86337@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86338 case MCAST_JOIN_GROUP:
86339 case MCAST_LEAVE_GROUP:
86340 {
86341- struct compat_group_req __user *gr32 = (void *)optval;
86342+ struct compat_group_req __user *gr32 = (void __user *)optval;
86343 struct group_req __user *kgr =
86344 compat_alloc_user_space(sizeof(struct group_req));
86345 u32 interface;
86346@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86347 case MCAST_BLOCK_SOURCE:
86348 case MCAST_UNBLOCK_SOURCE:
86349 {
86350- struct compat_group_source_req __user *gsr32 = (void *)optval;
86351+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
86352 struct group_source_req __user *kgsr = compat_alloc_user_space(
86353 sizeof(struct group_source_req));
86354 u32 interface;
86355@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86356 }
86357 case MCAST_MSFILTER:
86358 {
86359- struct compat_group_filter __user *gf32 = (void *)optval;
86360+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86361 struct group_filter __user *kgf;
86362 u32 interface, fmode, numsrc;
86363
86364@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
86365 char __user *optval, int __user *optlen,
86366 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
86367 {
86368- struct compat_group_filter __user *gf32 = (void *)optval;
86369+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86370 struct group_filter __user *kgf;
86371 int __user *koptlen;
86372 u32 interface, fmode, numsrc;
86373@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
86374
86375 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
86376 return -EINVAL;
86377- if (copy_from_user(a, args, nas[call]))
86378+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
86379 return -EFAULT;
86380 a0 = a[0];
86381 a1 = a[1];
86382diff --git a/net/core/datagram.c b/net/core/datagram.c
86383index 368f9c3..f82d4a3 100644
86384--- a/net/core/datagram.c
86385+++ b/net/core/datagram.c
86386@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
86387 }
86388
86389 kfree_skb(skb);
86390- atomic_inc(&sk->sk_drops);
86391+ atomic_inc_unchecked(&sk->sk_drops);
86392 sk_mem_reclaim_partial(sk);
86393
86394 return err;
86395diff --git a/net/core/dev.c b/net/core/dev.c
86396index c9eb9e6..922c789 100644
86397--- a/net/core/dev.c
86398+++ b/net/core/dev.c
86399@@ -1617,7 +1617,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86400 {
86401 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
86402 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
86403- atomic_long_inc(&dev->rx_dropped);
86404+ atomic_long_inc_unchecked(&dev->rx_dropped);
86405 kfree_skb(skb);
86406 return NET_RX_DROP;
86407 }
86408@@ -1626,7 +1626,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86409 skb_orphan(skb);
86410
86411 if (unlikely(!is_skb_forwardable(dev, skb))) {
86412- atomic_long_inc(&dev->rx_dropped);
86413+ atomic_long_inc_unchecked(&dev->rx_dropped);
86414 kfree_skb(skb);
86415 return NET_RX_DROP;
86416 }
86417@@ -2351,7 +2351,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
86418
86419 struct dev_gso_cb {
86420 void (*destructor)(struct sk_buff *skb);
86421-};
86422+} __no_const;
86423
86424 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
86425
86426@@ -3099,7 +3099,7 @@ enqueue:
86427
86428 local_irq_restore(flags);
86429
86430- atomic_long_inc(&skb->dev->rx_dropped);
86431+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86432 kfree_skb(skb);
86433 return NET_RX_DROP;
86434 }
86435@@ -3171,7 +3171,7 @@ int netif_rx_ni(struct sk_buff *skb)
86436 }
86437 EXPORT_SYMBOL(netif_rx_ni);
86438
86439-static void net_tx_action(struct softirq_action *h)
86440+static void net_tx_action(void)
86441 {
86442 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86443
86444@@ -3496,7 +3496,7 @@ ncls:
86445 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
86446 } else {
86447 drop:
86448- atomic_long_inc(&skb->dev->rx_dropped);
86449+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86450 kfree_skb(skb);
86451 /* Jamal, now you will not able to escape explaining
86452 * me how you were going to use this. :-)
86453@@ -4101,7 +4101,7 @@ void netif_napi_del(struct napi_struct *napi)
86454 }
86455 EXPORT_SYMBOL(netif_napi_del);
86456
86457-static void net_rx_action(struct softirq_action *h)
86458+static void net_rx_action(void)
86459 {
86460 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86461 unsigned long time_limit = jiffies + 2;
86462@@ -5528,7 +5528,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
86463 } else {
86464 netdev_stats_to_stats64(storage, &dev->stats);
86465 }
86466- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
86467+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
86468 return storage;
86469 }
86470 EXPORT_SYMBOL(dev_get_stats);
86471diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
86472index 6cc0481..59cfb00 100644
86473--- a/net/core/dev_ioctl.c
86474+++ b/net/core/dev_ioctl.c
86475@@ -376,9 +376,13 @@ void dev_load(struct net *net, const char *name)
86476 if (no_module && capable(CAP_NET_ADMIN))
86477 no_module = request_module("netdev-%s", name);
86478 if (no_module && capable(CAP_SYS_MODULE)) {
86479+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86480+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
86481+#else
86482 if (!request_module("%s", name))
86483 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
86484 name);
86485+#endif
86486 }
86487 }
86488 EXPORT_SYMBOL(dev_load);
86489diff --git a/net/core/flow.c b/net/core/flow.c
86490index 2bfd081..53c6058 100644
86491--- a/net/core/flow.c
86492+++ b/net/core/flow.c
86493@@ -61,7 +61,7 @@ struct flow_cache {
86494 struct timer_list rnd_timer;
86495 };
86496
86497-atomic_t flow_cache_genid = ATOMIC_INIT(0);
86498+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
86499 EXPORT_SYMBOL(flow_cache_genid);
86500 static struct flow_cache flow_cache_global;
86501 static struct kmem_cache *flow_cachep __read_mostly;
86502@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
86503
86504 static int flow_entry_valid(struct flow_cache_entry *fle)
86505 {
86506- if (atomic_read(&flow_cache_genid) != fle->genid)
86507+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
86508 return 0;
86509 if (fle->object && !fle->object->ops->check(fle->object))
86510 return 0;
86511@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
86512 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
86513 fcp->hash_count++;
86514 }
86515- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
86516+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
86517 flo = fle->object;
86518 if (!flo)
86519 goto ret_object;
86520@@ -279,7 +279,7 @@ nocache:
86521 }
86522 flo = resolver(net, key, family, dir, flo, ctx);
86523 if (fle) {
86524- fle->genid = atomic_read(&flow_cache_genid);
86525+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
86526 if (!IS_ERR(flo))
86527 fle->object = flo;
86528 else
86529diff --git a/net/core/iovec.c b/net/core/iovec.c
86530index 7e7aeb0..2a998cb 100644
86531--- a/net/core/iovec.c
86532+++ b/net/core/iovec.c
86533@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86534 if (m->msg_namelen) {
86535 if (mode == VERIFY_READ) {
86536 void __user *namep;
86537- namep = (void __user __force *) m->msg_name;
86538+ namep = (void __force_user *) m->msg_name;
86539 err = move_addr_to_kernel(namep, m->msg_namelen,
86540 address);
86541 if (err < 0)
86542@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86543 }
86544
86545 size = m->msg_iovlen * sizeof(struct iovec);
86546- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
86547+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
86548 return -EFAULT;
86549
86550 m->msg_iov = iov;
86551diff --git a/net/core/neighbour.c b/net/core/neighbour.c
86552index 3863b8f..85c99a6 100644
86553--- a/net/core/neighbour.c
86554+++ b/net/core/neighbour.c
86555@@ -2778,7 +2778,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
86556 size_t *lenp, loff_t *ppos)
86557 {
86558 int size, ret;
86559- ctl_table tmp = *ctl;
86560+ ctl_table_no_const tmp = *ctl;
86561
86562 tmp.extra1 = &zero;
86563 tmp.extra2 = &unres_qlen_max;
86564diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
86565index 3174f19..5810985 100644
86566--- a/net/core/net-procfs.c
86567+++ b/net/core/net-procfs.c
86568@@ -271,8 +271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
86569 else
86570 seq_printf(seq, "%04x", ntohs(pt->type));
86571
86572+#ifdef CONFIG_GRKERNSEC_HIDESYM
86573+ seq_printf(seq, " %-8s %pF\n",
86574+ pt->dev ? pt->dev->name : "", NULL);
86575+#else
86576 seq_printf(seq, " %-8s %pF\n",
86577 pt->dev ? pt->dev->name : "", pt->func);
86578+#endif
86579 }
86580
86581 return 0;
86582diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
86583index 7427ab5..389f411 100644
86584--- a/net/core/net-sysfs.c
86585+++ b/net/core/net-sysfs.c
86586@@ -1321,7 +1321,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
86587 }
86588 EXPORT_SYMBOL(netdev_class_remove_file);
86589
86590-int netdev_kobject_init(void)
86591+int __init netdev_kobject_init(void)
86592 {
86593 kobj_ns_type_register(&net_ns_type_operations);
86594 return class_register(&net_class);
86595diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
86596index 80e271d..2980cc2 100644
86597--- a/net/core/net_namespace.c
86598+++ b/net/core/net_namespace.c
86599@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
86600 int error;
86601 LIST_HEAD(net_exit_list);
86602
86603- list_add_tail(&ops->list, list);
86604+ pax_list_add_tail((struct list_head *)&ops->list, list);
86605 if (ops->init || (ops->id && ops->size)) {
86606 for_each_net(net) {
86607 error = ops_init(ops, net);
86608@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
86609
86610 out_undo:
86611 /* If I have an error cleanup all namespaces I initialized */
86612- list_del(&ops->list);
86613+ pax_list_del((struct list_head *)&ops->list);
86614 ops_exit_list(ops, &net_exit_list);
86615 ops_free_list(ops, &net_exit_list);
86616 return error;
86617@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
86618 struct net *net;
86619 LIST_HEAD(net_exit_list);
86620
86621- list_del(&ops->list);
86622+ pax_list_del((struct list_head *)&ops->list);
86623 for_each_net(net)
86624 list_add_tail(&net->exit_list, &net_exit_list);
86625 ops_exit_list(ops, &net_exit_list);
86626@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
86627 mutex_lock(&net_mutex);
86628 error = register_pernet_operations(&pernet_list, ops);
86629 if (!error && (first_device == &pernet_list))
86630- first_device = &ops->list;
86631+ first_device = (struct list_head *)&ops->list;
86632 mutex_unlock(&net_mutex);
86633 return error;
86634 }
86635diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
86636index 23854b5..ff4fda4 100644
86637--- a/net/core/rtnetlink.c
86638+++ b/net/core/rtnetlink.c
86639@@ -58,7 +58,7 @@ struct rtnl_link {
86640 rtnl_doit_func doit;
86641 rtnl_dumpit_func dumpit;
86642 rtnl_calcit_func calcit;
86643-};
86644+} __no_const;
86645
86646 static DEFINE_MUTEX(rtnl_mutex);
86647
86648@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
86649 if (rtnl_link_ops_get(ops->kind))
86650 return -EEXIST;
86651
86652- if (!ops->dellink)
86653- ops->dellink = unregister_netdevice_queue;
86654+ if (!ops->dellink) {
86655+ pax_open_kernel();
86656+ *(void **)&ops->dellink = unregister_netdevice_queue;
86657+ pax_close_kernel();
86658+ }
86659
86660- list_add_tail(&ops->list, &link_ops);
86661+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
86662 return 0;
86663 }
86664 EXPORT_SYMBOL_GPL(__rtnl_link_register);
86665@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
86666 for_each_net(net) {
86667 __rtnl_kill_links(net, ops);
86668 }
86669- list_del(&ops->list);
86670+ pax_list_del((struct list_head *)&ops->list);
86671 }
86672 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
86673
86674diff --git a/net/core/scm.c b/net/core/scm.c
86675index 2dc6cda..2159524 100644
86676--- a/net/core/scm.c
86677+++ b/net/core/scm.c
86678@@ -226,7 +226,7 @@ EXPORT_SYMBOL(__scm_send);
86679 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86680 {
86681 struct cmsghdr __user *cm
86682- = (__force struct cmsghdr __user *)msg->msg_control;
86683+ = (struct cmsghdr __force_user *)msg->msg_control;
86684 struct cmsghdr cmhdr;
86685 int cmlen = CMSG_LEN(len);
86686 int err;
86687@@ -249,7 +249,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86688 err = -EFAULT;
86689 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
86690 goto out;
86691- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
86692+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
86693 goto out;
86694 cmlen = CMSG_SPACE(len);
86695 if (msg->msg_controllen < cmlen)
86696@@ -265,7 +265,7 @@ EXPORT_SYMBOL(put_cmsg);
86697 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86698 {
86699 struct cmsghdr __user *cm
86700- = (__force struct cmsghdr __user*)msg->msg_control;
86701+ = (struct cmsghdr __force_user *)msg->msg_control;
86702
86703 int fdmax = 0;
86704 int fdnum = scm->fp->count;
86705@@ -285,7 +285,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86706 if (fdnum < fdmax)
86707 fdmax = fdnum;
86708
86709- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
86710+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
86711 i++, cmfptr++)
86712 {
86713 struct socket *sock;
86714diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
86715index e61a8bb..6a2f13c 100644
86716--- a/net/core/secure_seq.c
86717+++ b/net/core/secure_seq.c
86718@@ -12,12 +12,10 @@
86719
86720 static u32 net_secret[MD5_MESSAGE_BYTES / 4] ____cacheline_aligned;
86721
86722-static int __init net_secret_init(void)
86723+void net_secret_init(void)
86724 {
86725 get_random_bytes(net_secret, sizeof(net_secret));
86726- return 0;
86727 }
86728-late_initcall(net_secret_init);
86729
86730 #ifdef CONFIG_INET
86731 static u32 seq_scale(u32 seq)
86732diff --git a/net/core/sock.c b/net/core/sock.c
86733index 684c37d..b541900 100644
86734--- a/net/core/sock.c
86735+++ b/net/core/sock.c
86736@@ -390,7 +390,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86737 struct sk_buff_head *list = &sk->sk_receive_queue;
86738
86739 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
86740- atomic_inc(&sk->sk_drops);
86741+ atomic_inc_unchecked(&sk->sk_drops);
86742 trace_sock_rcvqueue_full(sk, skb);
86743 return -ENOMEM;
86744 }
86745@@ -400,7 +400,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86746 return err;
86747
86748 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
86749- atomic_inc(&sk->sk_drops);
86750+ atomic_inc_unchecked(&sk->sk_drops);
86751 return -ENOBUFS;
86752 }
86753
86754@@ -420,7 +420,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86755 skb_dst_force(skb);
86756
86757 spin_lock_irqsave(&list->lock, flags);
86758- skb->dropcount = atomic_read(&sk->sk_drops);
86759+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86760 __skb_queue_tail(list, skb);
86761 spin_unlock_irqrestore(&list->lock, flags);
86762
86763@@ -440,7 +440,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86764 skb->dev = NULL;
86765
86766 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
86767- atomic_inc(&sk->sk_drops);
86768+ atomic_inc_unchecked(&sk->sk_drops);
86769 goto discard_and_relse;
86770 }
86771 if (nested)
86772@@ -458,7 +458,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86773 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
86774 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
86775 bh_unlock_sock(sk);
86776- atomic_inc(&sk->sk_drops);
86777+ atomic_inc_unchecked(&sk->sk_drops);
86778 goto discard_and_relse;
86779 }
86780
86781@@ -942,12 +942,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86782 struct timeval tm;
86783 } v;
86784
86785- int lv = sizeof(int);
86786- int len;
86787+ unsigned int lv = sizeof(int);
86788+ unsigned int len;
86789
86790 if (get_user(len, optlen))
86791 return -EFAULT;
86792- if (len < 0)
86793+ if (len > INT_MAX)
86794 return -EINVAL;
86795
86796 memset(&v, 0, sizeof(v));
86797@@ -1099,11 +1099,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86798
86799 case SO_PEERNAME:
86800 {
86801- char address[128];
86802+ char address[_K_SS_MAXSIZE];
86803
86804 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
86805 return -ENOTCONN;
86806- if (lv < len)
86807+ if (lv < len || sizeof address < len)
86808 return -EINVAL;
86809 if (copy_to_user(optval, address, len))
86810 return -EFAULT;
86811@@ -1166,7 +1166,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86812
86813 if (len > lv)
86814 len = lv;
86815- if (copy_to_user(optval, &v, len))
86816+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
86817 return -EFAULT;
86818 lenout:
86819 if (put_user(len, optlen))
86820@@ -2284,7 +2284,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
86821 */
86822 smp_wmb();
86823 atomic_set(&sk->sk_refcnt, 1);
86824- atomic_set(&sk->sk_drops, 0);
86825+ atomic_set_unchecked(&sk->sk_drops, 0);
86826 }
86827 EXPORT_SYMBOL(sock_init_data);
86828
86829diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
86830index a29e90c..922399c 100644
86831--- a/net/core/sock_diag.c
86832+++ b/net/core/sock_diag.c
86833@@ -9,26 +9,33 @@
86834 #include <linux/inet_diag.h>
86835 #include <linux/sock_diag.h>
86836
86837-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
86838+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
86839 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
86840 static DEFINE_MUTEX(sock_diag_table_mutex);
86841
86842 int sock_diag_check_cookie(void *sk, __u32 *cookie)
86843 {
86844+#ifndef CONFIG_GRKERNSEC_HIDESYM
86845 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
86846 cookie[1] != INET_DIAG_NOCOOKIE) &&
86847 ((u32)(unsigned long)sk != cookie[0] ||
86848 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
86849 return -ESTALE;
86850 else
86851+#endif
86852 return 0;
86853 }
86854 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
86855
86856 void sock_diag_save_cookie(void *sk, __u32 *cookie)
86857 {
86858+#ifdef CONFIG_GRKERNSEC_HIDESYM
86859+ cookie[0] = 0;
86860+ cookie[1] = 0;
86861+#else
86862 cookie[0] = (u32)(unsigned long)sk;
86863 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
86864+#endif
86865 }
86866 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
86867
86868@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
86869 mutex_lock(&sock_diag_table_mutex);
86870 if (sock_diag_handlers[hndl->family])
86871 err = -EBUSY;
86872- else
86873+ else {
86874+ pax_open_kernel();
86875 sock_diag_handlers[hndl->family] = hndl;
86876+ pax_close_kernel();
86877+ }
86878 mutex_unlock(&sock_diag_table_mutex);
86879
86880 return err;
86881@@ -92,7 +102,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
86882
86883 mutex_lock(&sock_diag_table_mutex);
86884 BUG_ON(sock_diag_handlers[family] != hnld);
86885+ pax_open_kernel();
86886 sock_diag_handlers[family] = NULL;
86887+ pax_close_kernel();
86888 mutex_unlock(&sock_diag_table_mutex);
86889 }
86890 EXPORT_SYMBOL_GPL(sock_diag_unregister);
86891diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
86892index cfdb46a..cef55e1 100644
86893--- a/net/core/sysctl_net_core.c
86894+++ b/net/core/sysctl_net_core.c
86895@@ -28,7 +28,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
86896 {
86897 unsigned int orig_size, size;
86898 int ret, i;
86899- ctl_table tmp = {
86900+ ctl_table_no_const tmp = {
86901 .data = &size,
86902 .maxlen = sizeof(size),
86903 .mode = table->mode
86904@@ -211,13 +211,12 @@ static struct ctl_table netns_core_table[] = {
86905
86906 static __net_init int sysctl_core_net_init(struct net *net)
86907 {
86908- struct ctl_table *tbl;
86909+ ctl_table_no_const *tbl = NULL;
86910
86911 net->core.sysctl_somaxconn = SOMAXCONN;
86912
86913- tbl = netns_core_table;
86914 if (!net_eq(net, &init_net)) {
86915- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
86916+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
86917 if (tbl == NULL)
86918 goto err_dup;
86919
86920@@ -227,17 +226,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
86921 if (net->user_ns != &init_user_ns) {
86922 tbl[0].procname = NULL;
86923 }
86924- }
86925-
86926- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86927+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86928+ } else
86929+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
86930 if (net->core.sysctl_hdr == NULL)
86931 goto err_reg;
86932
86933 return 0;
86934
86935 err_reg:
86936- if (tbl != netns_core_table)
86937- kfree(tbl);
86938+ kfree(tbl);
86939 err_dup:
86940 return -ENOMEM;
86941 }
86942@@ -252,7 +250,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
86943 kfree(tbl);
86944 }
86945
86946-static __net_initdata struct pernet_operations sysctl_core_ops = {
86947+static __net_initconst struct pernet_operations sysctl_core_ops = {
86948 .init = sysctl_core_net_init,
86949 .exit = sysctl_core_net_exit,
86950 };
86951diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
86952index c21f200..bc4565b 100644
86953--- a/net/decnet/af_decnet.c
86954+++ b/net/decnet/af_decnet.c
86955@@ -465,6 +465,7 @@ static struct proto dn_proto = {
86956 .sysctl_rmem = sysctl_decnet_rmem,
86957 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
86958 .obj_size = sizeof(struct dn_sock),
86959+ .slab_flags = SLAB_USERCOPY,
86960 };
86961
86962 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
86963diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
86964index a55eecc..dd8428c 100644
86965--- a/net/decnet/sysctl_net_decnet.c
86966+++ b/net/decnet/sysctl_net_decnet.c
86967@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
86968
86969 if (len > *lenp) len = *lenp;
86970
86971- if (copy_to_user(buffer, addr, len))
86972+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
86973 return -EFAULT;
86974
86975 *lenp = len;
86976@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
86977
86978 if (len > *lenp) len = *lenp;
86979
86980- if (copy_to_user(buffer, devname, len))
86981+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
86982 return -EFAULT;
86983
86984 *lenp = len;
86985diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
86986index c929d9c..df10cde 100644
86987--- a/net/ipv4/af_inet.c
86988+++ b/net/ipv4/af_inet.c
86989@@ -115,6 +115,7 @@
86990 #include <net/inet_common.h>
86991 #include <net/xfrm.h>
86992 #include <net/net_namespace.h>
86993+#include <net/secure_seq.h>
86994 #ifdef CONFIG_IP_MROUTE
86995 #include <linux/mroute.h>
86996 #endif
86997@@ -263,8 +264,10 @@ void build_ehash_secret(void)
86998 get_random_bytes(&rnd, sizeof(rnd));
86999 } while (rnd == 0);
87000
87001- if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0)
87002+ if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0) {
87003 get_random_bytes(&ipv6_hash_secret, sizeof(ipv6_hash_secret));
87004+ net_secret_init();
87005+ }
87006 }
87007 EXPORT_SYMBOL(build_ehash_secret);
87008
87009@@ -1699,13 +1702,9 @@ static int __init inet_init(void)
87010
87011 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
87012
87013- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
87014- if (!sysctl_local_reserved_ports)
87015- goto out;
87016-
87017 rc = proto_register(&tcp_prot, 1);
87018 if (rc)
87019- goto out_free_reserved_ports;
87020+ goto out;
87021
87022 rc = proto_register(&udp_prot, 1);
87023 if (rc)
87024@@ -1814,8 +1813,6 @@ out_unregister_udp_proto:
87025 proto_unregister(&udp_prot);
87026 out_unregister_tcp_proto:
87027 proto_unregister(&tcp_prot);
87028-out_free_reserved_ports:
87029- kfree(sysctl_local_reserved_ports);
87030 goto out;
87031 }
87032
87033diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
87034index 2e7f194..0fa4d6d 100644
87035--- a/net/ipv4/ah4.c
87036+++ b/net/ipv4/ah4.c
87037@@ -420,7 +420,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
87038 return;
87039
87040 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87041- atomic_inc(&flow_cache_genid);
87042+ atomic_inc_unchecked(&flow_cache_genid);
87043 rt_genid_bump(net);
87044
87045 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
87046diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
87047index c6287cd..e9bc96a 100644
87048--- a/net/ipv4/devinet.c
87049+++ b/net/ipv4/devinet.c
87050@@ -1992,7 +1992,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
87051 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
87052 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
87053
87054-static struct devinet_sysctl_table {
87055+static const struct devinet_sysctl_table {
87056 struct ctl_table_header *sysctl_header;
87057 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
87058 } devinet_sysctl = {
87059@@ -2110,7 +2110,7 @@ static __net_init int devinet_init_net(struct net *net)
87060 int err;
87061 struct ipv4_devconf *all, *dflt;
87062 #ifdef CONFIG_SYSCTL
87063- struct ctl_table *tbl = ctl_forward_entry;
87064+ ctl_table_no_const *tbl = NULL;
87065 struct ctl_table_header *forw_hdr;
87066 #endif
87067
87068@@ -2128,7 +2128,7 @@ static __net_init int devinet_init_net(struct net *net)
87069 goto err_alloc_dflt;
87070
87071 #ifdef CONFIG_SYSCTL
87072- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
87073+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
87074 if (tbl == NULL)
87075 goto err_alloc_ctl;
87076
87077@@ -2148,7 +2148,10 @@ static __net_init int devinet_init_net(struct net *net)
87078 goto err_reg_dflt;
87079
87080 err = -ENOMEM;
87081- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
87082+ if (!net_eq(net, &init_net))
87083+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
87084+ else
87085+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
87086 if (forw_hdr == NULL)
87087 goto err_reg_ctl;
87088 net->ipv4.forw_hdr = forw_hdr;
87089@@ -2164,8 +2167,7 @@ err_reg_ctl:
87090 err_reg_dflt:
87091 __devinet_sysctl_unregister(all);
87092 err_reg_all:
87093- if (tbl != ctl_forward_entry)
87094- kfree(tbl);
87095+ kfree(tbl);
87096 err_alloc_ctl:
87097 #endif
87098 if (dflt != &ipv4_devconf_dflt)
87099diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
87100index 4cfe34d..a6ba66e 100644
87101--- a/net/ipv4/esp4.c
87102+++ b/net/ipv4/esp4.c
87103@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
87104 return;
87105
87106 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87107- atomic_inc(&flow_cache_genid);
87108+ atomic_inc_unchecked(&flow_cache_genid);
87109 rt_genid_bump(net);
87110
87111 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
87112diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
87113index eb4bb12..ee4ec7d 100644
87114--- a/net/ipv4/fib_frontend.c
87115+++ b/net/ipv4/fib_frontend.c
87116@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
87117 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87118 fib_sync_up(dev);
87119 #endif
87120- atomic_inc(&net->ipv4.dev_addr_genid);
87121+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87122 rt_cache_flush(dev_net(dev));
87123 break;
87124 case NETDEV_DOWN:
87125 fib_del_ifaddr(ifa, NULL);
87126- atomic_inc(&net->ipv4.dev_addr_genid);
87127+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87128 if (ifa->ifa_dev->ifa_list == NULL) {
87129 /* Last address was deleted from this interface.
87130 * Disable IP.
87131@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
87132 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87133 fib_sync_up(dev);
87134 #endif
87135- atomic_inc(&net->ipv4.dev_addr_genid);
87136+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87137 rt_cache_flush(net);
87138 break;
87139 case NETDEV_DOWN:
87140diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
87141index 8f6cb7a..34507f9 100644
87142--- a/net/ipv4/fib_semantics.c
87143+++ b/net/ipv4/fib_semantics.c
87144@@ -765,7 +765,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
87145 nh->nh_saddr = inet_select_addr(nh->nh_dev,
87146 nh->nh_gw,
87147 nh->nh_parent->fib_scope);
87148- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
87149+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
87150
87151 return nh->nh_saddr;
87152 }
87153diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
87154index 786d97a..1889c0d 100644
87155--- a/net/ipv4/inet_connection_sock.c
87156+++ b/net/ipv4/inet_connection_sock.c
87157@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
87158 .range = { 32768, 61000 },
87159 };
87160
87161-unsigned long *sysctl_local_reserved_ports;
87162+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
87163 EXPORT_SYMBOL(sysctl_local_reserved_ports);
87164
87165 void inet_get_local_port_range(int *low, int *high)
87166diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
87167index 6af375a..c493c74 100644
87168--- a/net/ipv4/inet_hashtables.c
87169+++ b/net/ipv4/inet_hashtables.c
87170@@ -18,12 +18,15 @@
87171 #include <linux/sched.h>
87172 #include <linux/slab.h>
87173 #include <linux/wait.h>
87174+#include <linux/security.h>
87175
87176 #include <net/inet_connection_sock.h>
87177 #include <net/inet_hashtables.h>
87178 #include <net/secure_seq.h>
87179 #include <net/ip.h>
87180
87181+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
87182+
87183 /*
87184 * Allocate and initialize a new local port bind bucket.
87185 * The bindhash mutex for snum's hash chain must be held here.
87186@@ -554,6 +557,8 @@ ok:
87187 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
87188 spin_unlock(&head->lock);
87189
87190+ gr_update_task_in_ip_table(current, inet_sk(sk));
87191+
87192 if (tw) {
87193 inet_twsk_deschedule(tw, death_row);
87194 while (twrefcnt) {
87195diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
87196index 000e3d2..5472da3 100644
87197--- a/net/ipv4/inetpeer.c
87198+++ b/net/ipv4/inetpeer.c
87199@@ -503,8 +503,8 @@ relookup:
87200 if (p) {
87201 p->daddr = *daddr;
87202 atomic_set(&p->refcnt, 1);
87203- atomic_set(&p->rid, 0);
87204- atomic_set(&p->ip_id_count,
87205+ atomic_set_unchecked(&p->rid, 0);
87206+ atomic_set_unchecked(&p->ip_id_count,
87207 (daddr->family == AF_INET) ?
87208 secure_ip_id(daddr->addr.a4) :
87209 secure_ipv6_id(daddr->addr.a6));
87210diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
87211index 52c273e..579060b 100644
87212--- a/net/ipv4/ip_fragment.c
87213+++ b/net/ipv4/ip_fragment.c
87214@@ -311,7 +311,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
87215 return 0;
87216
87217 start = qp->rid;
87218- end = atomic_inc_return(&peer->rid);
87219+ end = atomic_inc_return_unchecked(&peer->rid);
87220 qp->rid = end;
87221
87222 rc = qp->q.fragments && (end - start) > max;
87223@@ -788,12 +788,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
87224
87225 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87226 {
87227- struct ctl_table *table;
87228+ ctl_table_no_const *table = NULL;
87229 struct ctl_table_header *hdr;
87230
87231- table = ip4_frags_ns_ctl_table;
87232 if (!net_eq(net, &init_net)) {
87233- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87234+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87235 if (table == NULL)
87236 goto err_alloc;
87237
87238@@ -804,9 +803,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87239 /* Don't export sysctls to unprivileged users */
87240 if (net->user_ns != &init_user_ns)
87241 table[0].procname = NULL;
87242- }
87243+ hdr = register_net_sysctl(net, "net/ipv4", table);
87244+ } else
87245+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
87246
87247- hdr = register_net_sysctl(net, "net/ipv4", table);
87248 if (hdr == NULL)
87249 goto err_reg;
87250
87251@@ -814,8 +814,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87252 return 0;
87253
87254 err_reg:
87255- if (!net_eq(net, &init_net))
87256- kfree(table);
87257+ kfree(table);
87258 err_alloc:
87259 return -ENOMEM;
87260 }
87261diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
87262index c7e8c04..56cb4c1 100644
87263--- a/net/ipv4/ip_gre.c
87264+++ b/net/ipv4/ip_gre.c
87265@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
87266 module_param(log_ecn_error, bool, 0644);
87267 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87268
87269-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
87270+static struct rtnl_link_ops ipgre_link_ops;
87271 static int ipgre_tunnel_init(struct net_device *dev);
87272 static void ipgre_tunnel_setup(struct net_device *dev);
87273 static int ipgre_tunnel_bind_dev(struct net_device *dev);
87274@@ -1823,7 +1823,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
87275 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
87276 };
87277
87278-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87279+static struct rtnl_link_ops ipgre_link_ops = {
87280 .kind = "gre",
87281 .maxtype = IFLA_GRE_MAX,
87282 .policy = ipgre_policy,
87283@@ -1836,7 +1836,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87284 .fill_info = ipgre_fill_info,
87285 };
87286
87287-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
87288+static struct rtnl_link_ops ipgre_tap_ops = {
87289 .kind = "gretap",
87290 .maxtype = IFLA_GRE_MAX,
87291 .policy = ipgre_policy,
87292diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
87293index d9c4f11..02b82dbc 100644
87294--- a/net/ipv4/ip_sockglue.c
87295+++ b/net/ipv4/ip_sockglue.c
87296@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87297 len = min_t(unsigned int, len, opt->optlen);
87298 if (put_user(len, optlen))
87299 return -EFAULT;
87300- if (copy_to_user(optval, opt->__data, len))
87301+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
87302+ copy_to_user(optval, opt->__data, len))
87303 return -EFAULT;
87304 return 0;
87305 }
87306@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87307 if (sk->sk_type != SOCK_STREAM)
87308 return -ENOPROTOOPT;
87309
87310- msg.msg_control = optval;
87311+ msg.msg_control = (void __force_kernel *)optval;
87312 msg.msg_controllen = len;
87313 msg.msg_flags = flags;
87314
87315diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
87316index c3a4233..7df5626 100644
87317--- a/net/ipv4/ip_vti.c
87318+++ b/net/ipv4/ip_vti.c
87319@@ -47,7 +47,7 @@
87320 #define HASH_SIZE 16
87321 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
87322
87323-static struct rtnl_link_ops vti_link_ops __read_mostly;
87324+static struct rtnl_link_ops vti_link_ops;
87325
87326 static int vti_net_id __read_mostly;
87327 struct vti_net {
87328@@ -399,8 +399,7 @@ static netdev_tx_t vti_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
87329 tunnel->err_count = 0;
87330 }
87331
87332- IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
87333- IPSKB_REROUTED);
87334+ memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
87335 skb_dst_drop(skb);
87336 skb_dst_set(skb, &rt->dst);
87337 nf_reset(skb);
87338@@ -886,7 +885,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
87339 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
87340 };
87341
87342-static struct rtnl_link_ops vti_link_ops __read_mostly = {
87343+static struct rtnl_link_ops vti_link_ops = {
87344 .kind = "vti",
87345 .maxtype = IFLA_VTI_MAX,
87346 .policy = vti_policy,
87347diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
87348index f01d1b1..8fe03ad 100644
87349--- a/net/ipv4/ipcomp.c
87350+++ b/net/ipv4/ipcomp.c
87351@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
87352 return;
87353
87354 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87355- atomic_inc(&flow_cache_genid);
87356+ atomic_inc_unchecked(&flow_cache_genid);
87357 rt_genid_bump(net);
87358
87359 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
87360diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
87361index bf6c5cf..ab2e9c6 100644
87362--- a/net/ipv4/ipconfig.c
87363+++ b/net/ipv4/ipconfig.c
87364@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
87365
87366 mm_segment_t oldfs = get_fs();
87367 set_fs(get_ds());
87368- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87369+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87370 set_fs(oldfs);
87371 return res;
87372 }
87373@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
87374
87375 mm_segment_t oldfs = get_fs();
87376 set_fs(get_ds());
87377- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87378+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87379 set_fs(oldfs);
87380 return res;
87381 }
87382@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
87383
87384 mm_segment_t oldfs = get_fs();
87385 set_fs(get_ds());
87386- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
87387+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
87388 set_fs(oldfs);
87389 return res;
87390 }
87391diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
87392index 7533846..d2361d1 100644
87393--- a/net/ipv4/ipip.c
87394+++ b/net/ipv4/ipip.c
87395@@ -138,7 +138,7 @@ struct ipip_net {
87396 static int ipip_tunnel_init(struct net_device *dev);
87397 static void ipip_tunnel_setup(struct net_device *dev);
87398 static void ipip_dev_free(struct net_device *dev);
87399-static struct rtnl_link_ops ipip_link_ops __read_mostly;
87400+static struct rtnl_link_ops ipip_link_ops;
87401
87402 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
87403 struct rtnl_link_stats64 *tot)
87404@@ -974,7 +974,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
87405 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
87406 };
87407
87408-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
87409+static struct rtnl_link_ops ipip_link_ops = {
87410 .kind = "ipip",
87411 .maxtype = IFLA_IPTUN_MAX,
87412 .policy = ipip_policy,
87413diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
87414index 7dc6a97..229c61b 100644
87415--- a/net/ipv4/netfilter/arp_tables.c
87416+++ b/net/ipv4/netfilter/arp_tables.c
87417@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
87418 #endif
87419
87420 static int get_info(struct net *net, void __user *user,
87421- const int *len, int compat)
87422+ int len, int compat)
87423 {
87424 char name[XT_TABLE_MAXNAMELEN];
87425 struct xt_table *t;
87426 int ret;
87427
87428- if (*len != sizeof(struct arpt_getinfo)) {
87429- duprintf("length %u != %Zu\n", *len,
87430+ if (len != sizeof(struct arpt_getinfo)) {
87431+ duprintf("length %u != %Zu\n", len,
87432 sizeof(struct arpt_getinfo));
87433 return -EINVAL;
87434 }
87435@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
87436 info.size = private->size;
87437 strcpy(info.name, name);
87438
87439- if (copy_to_user(user, &info, *len) != 0)
87440+ if (copy_to_user(user, &info, len) != 0)
87441 ret = -EFAULT;
87442 else
87443 ret = 0;
87444@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
87445
87446 switch (cmd) {
87447 case ARPT_SO_GET_INFO:
87448- ret = get_info(sock_net(sk), user, len, 1);
87449+ ret = get_info(sock_net(sk), user, *len, 1);
87450 break;
87451 case ARPT_SO_GET_ENTRIES:
87452 ret = compat_get_entries(sock_net(sk), user, len);
87453@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
87454
87455 switch (cmd) {
87456 case ARPT_SO_GET_INFO:
87457- ret = get_info(sock_net(sk), user, len, 0);
87458+ ret = get_info(sock_net(sk), user, *len, 0);
87459 break;
87460
87461 case ARPT_SO_GET_ENTRIES:
87462diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
87463index 3efcf87..5247916 100644
87464--- a/net/ipv4/netfilter/ip_tables.c
87465+++ b/net/ipv4/netfilter/ip_tables.c
87466@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
87467 #endif
87468
87469 static int get_info(struct net *net, void __user *user,
87470- const int *len, int compat)
87471+ int len, int compat)
87472 {
87473 char name[XT_TABLE_MAXNAMELEN];
87474 struct xt_table *t;
87475 int ret;
87476
87477- if (*len != sizeof(struct ipt_getinfo)) {
87478- duprintf("length %u != %zu\n", *len,
87479+ if (len != sizeof(struct ipt_getinfo)) {
87480+ duprintf("length %u != %zu\n", len,
87481 sizeof(struct ipt_getinfo));
87482 return -EINVAL;
87483 }
87484@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
87485 info.size = private->size;
87486 strcpy(info.name, name);
87487
87488- if (copy_to_user(user, &info, *len) != 0)
87489+ if (copy_to_user(user, &info, len) != 0)
87490 ret = -EFAULT;
87491 else
87492 ret = 0;
87493@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87494
87495 switch (cmd) {
87496 case IPT_SO_GET_INFO:
87497- ret = get_info(sock_net(sk), user, len, 1);
87498+ ret = get_info(sock_net(sk), user, *len, 1);
87499 break;
87500 case IPT_SO_GET_ENTRIES:
87501 ret = compat_get_entries(sock_net(sk), user, len);
87502@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87503
87504 switch (cmd) {
87505 case IPT_SO_GET_INFO:
87506- ret = get_info(sock_net(sk), user, len, 0);
87507+ ret = get_info(sock_net(sk), user, *len, 0);
87508 break;
87509
87510 case IPT_SO_GET_ENTRIES:
87511diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
87512index 2e91006..f084394 100644
87513--- a/net/ipv4/ping.c
87514+++ b/net/ipv4/ping.c
87515@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
87516 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87517 0, sock_i_ino(sp),
87518 atomic_read(&sp->sk_refcnt), sp,
87519- atomic_read(&sp->sk_drops), len);
87520+ atomic_read_unchecked(&sp->sk_drops), len);
87521 }
87522
87523 static int ping_seq_show(struct seq_file *seq, void *v)
87524diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
87525index dd44e0a..06dcca4 100644
87526--- a/net/ipv4/raw.c
87527+++ b/net/ipv4/raw.c
87528@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
87529 int raw_rcv(struct sock *sk, struct sk_buff *skb)
87530 {
87531 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
87532- atomic_inc(&sk->sk_drops);
87533+ atomic_inc_unchecked(&sk->sk_drops);
87534 kfree_skb(skb);
87535 return NET_RX_DROP;
87536 }
87537@@ -745,16 +745,20 @@ static int raw_init(struct sock *sk)
87538
87539 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
87540 {
87541+ struct icmp_filter filter;
87542+
87543 if (optlen > sizeof(struct icmp_filter))
87544 optlen = sizeof(struct icmp_filter);
87545- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
87546+ if (copy_from_user(&filter, optval, optlen))
87547 return -EFAULT;
87548+ raw_sk(sk)->filter = filter;
87549 return 0;
87550 }
87551
87552 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
87553 {
87554 int len, ret = -EFAULT;
87555+ struct icmp_filter filter;
87556
87557 if (get_user(len, optlen))
87558 goto out;
87559@@ -764,8 +768,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
87560 if (len > sizeof(struct icmp_filter))
87561 len = sizeof(struct icmp_filter);
87562 ret = -EFAULT;
87563- if (put_user(len, optlen) ||
87564- copy_to_user(optval, &raw_sk(sk)->filter, len))
87565+ filter = raw_sk(sk)->filter;
87566+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
87567 goto out;
87568 ret = 0;
87569 out: return ret;
87570@@ -994,7 +998,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87571 0, 0L, 0,
87572 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87573 0, sock_i_ino(sp),
87574- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87575+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87576 }
87577
87578 static int raw_seq_show(struct seq_file *seq, void *v)
87579diff --git a/net/ipv4/route.c b/net/ipv4/route.c
87580index cfede9a..22248f9 100644
87581--- a/net/ipv4/route.c
87582+++ b/net/ipv4/route.c
87583@@ -2558,34 +2558,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
87584 .maxlen = sizeof(int),
87585 .mode = 0200,
87586 .proc_handler = ipv4_sysctl_rtcache_flush,
87587+ .extra1 = &init_net,
87588 },
87589 { },
87590 };
87591
87592 static __net_init int sysctl_route_net_init(struct net *net)
87593 {
87594- struct ctl_table *tbl;
87595+ ctl_table_no_const *tbl = NULL;
87596
87597- tbl = ipv4_route_flush_table;
87598 if (!net_eq(net, &init_net)) {
87599- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87600+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87601 if (tbl == NULL)
87602 goto err_dup;
87603
87604 /* Don't export sysctls to unprivileged users */
87605 if (net->user_ns != &init_user_ns)
87606 tbl[0].procname = NULL;
87607- }
87608- tbl[0].extra1 = net;
87609+ tbl[0].extra1 = net;
87610+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87611+ } else
87612+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
87613
87614- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87615 if (net->ipv4.route_hdr == NULL)
87616 goto err_reg;
87617 return 0;
87618
87619 err_reg:
87620- if (tbl != ipv4_route_flush_table)
87621- kfree(tbl);
87622+ kfree(tbl);
87623 err_dup:
87624 return -ENOMEM;
87625 }
87626@@ -2608,7 +2608,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
87627
87628 static __net_init int rt_genid_init(struct net *net)
87629 {
87630- atomic_set(&net->rt_genid, 0);
87631+ atomic_set_unchecked(&net->rt_genid, 0);
87632 get_random_bytes(&net->ipv4.dev_addr_genid,
87633 sizeof(net->ipv4.dev_addr_genid));
87634 return 0;
87635diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
87636index 960fd29..d55bf64 100644
87637--- a/net/ipv4/sysctl_net_ipv4.c
87638+++ b/net/ipv4/sysctl_net_ipv4.c
87639@@ -55,7 +55,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
87640 {
87641 int ret;
87642 int range[2];
87643- ctl_table tmp = {
87644+ ctl_table_no_const tmp = {
87645 .data = &range,
87646 .maxlen = sizeof(range),
87647 .mode = table->mode,
87648@@ -108,7 +108,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
87649 int ret;
87650 gid_t urange[2];
87651 kgid_t low, high;
87652- ctl_table tmp = {
87653+ ctl_table_no_const tmp = {
87654 .data = &urange,
87655 .maxlen = sizeof(urange),
87656 .mode = table->mode,
87657@@ -139,7 +139,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
87658 void __user *buffer, size_t *lenp, loff_t *ppos)
87659 {
87660 char val[TCP_CA_NAME_MAX];
87661- ctl_table tbl = {
87662+ ctl_table_no_const tbl = {
87663 .data = val,
87664 .maxlen = TCP_CA_NAME_MAX,
87665 };
87666@@ -158,7 +158,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
87667 void __user *buffer, size_t *lenp,
87668 loff_t *ppos)
87669 {
87670- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
87671+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
87672 int ret;
87673
87674 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87675@@ -175,7 +175,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
87676 void __user *buffer, size_t *lenp,
87677 loff_t *ppos)
87678 {
87679- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
87680+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
87681 int ret;
87682
87683 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87684@@ -201,15 +201,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87685 struct mem_cgroup *memcg;
87686 #endif
87687
87688- ctl_table tmp = {
87689+ ctl_table_no_const tmp = {
87690 .data = &vec,
87691 .maxlen = sizeof(vec),
87692 .mode = ctl->mode,
87693 };
87694
87695 if (!write) {
87696- ctl->data = &net->ipv4.sysctl_tcp_mem;
87697- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
87698+ ctl_table_no_const tcp_mem = *ctl;
87699+
87700+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
87701+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
87702 }
87703
87704 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
87705@@ -236,7 +238,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87706 static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
87707 size_t *lenp, loff_t *ppos)
87708 {
87709- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87710+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87711 struct tcp_fastopen_context *ctxt;
87712 int ret;
87713 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
87714@@ -477,7 +479,7 @@ static struct ctl_table ipv4_table[] = {
87715 },
87716 {
87717 .procname = "ip_local_reserved_ports",
87718- .data = NULL, /* initialized in sysctl_ipv4_init */
87719+ .data = sysctl_local_reserved_ports,
87720 .maxlen = 65536,
87721 .mode = 0644,
87722 .proc_handler = proc_do_large_bitmap,
87723@@ -856,11 +858,10 @@ static struct ctl_table ipv4_net_table[] = {
87724
87725 static __net_init int ipv4_sysctl_init_net(struct net *net)
87726 {
87727- struct ctl_table *table;
87728+ ctl_table_no_const *table = NULL;
87729
87730- table = ipv4_net_table;
87731 if (!net_eq(net, &init_net)) {
87732- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
87733+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
87734 if (table == NULL)
87735 goto err_alloc;
87736
87737@@ -895,15 +896,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
87738
87739 tcp_init_mem(net);
87740
87741- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87742+ if (!net_eq(net, &init_net))
87743+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87744+ else
87745+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
87746 if (net->ipv4.ipv4_hdr == NULL)
87747 goto err_reg;
87748
87749 return 0;
87750
87751 err_reg:
87752- if (!net_eq(net, &init_net))
87753- kfree(table);
87754+ kfree(table);
87755 err_alloc:
87756 return -ENOMEM;
87757 }
87758@@ -925,16 +928,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
87759 static __init int sysctl_ipv4_init(void)
87760 {
87761 struct ctl_table_header *hdr;
87762- struct ctl_table *i;
87763-
87764- for (i = ipv4_table; i->procname; i++) {
87765- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
87766- i->data = sysctl_local_reserved_ports;
87767- break;
87768- }
87769- }
87770- if (!i->procname)
87771- return -EINVAL;
87772
87773 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
87774 if (hdr == NULL)
87775diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
87776index 59163c8..8277c51 100644
87777--- a/net/ipv4/tcp_input.c
87778+++ b/net/ipv4/tcp_input.c
87779@@ -4727,7 +4727,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
87780 * simplifies code)
87781 */
87782 static void
87783-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87784+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87785 struct sk_buff *head, struct sk_buff *tail,
87786 u32 start, u32 end)
87787 {
87788@@ -5841,6 +5841,7 @@ discard:
87789 tcp_paws_reject(&tp->rx_opt, 0))
87790 goto discard_and_undo;
87791
87792+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
87793 if (th->syn) {
87794 /* We see SYN without ACK. It is attempt of
87795 * simultaneous connect with crossed SYNs.
87796@@ -5891,6 +5892,7 @@ discard:
87797 goto discard;
87798 #endif
87799 }
87800+#endif
87801 /* "fifth, if neither of the SYN or RST bits is set then
87802 * drop the segment and return."
87803 */
87804@@ -5935,7 +5937,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
87805 goto discard;
87806
87807 if (th->syn) {
87808- if (th->fin)
87809+ if (th->fin || th->urg || th->psh)
87810 goto discard;
87811 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
87812 return 1;
87813diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
87814index d09203c..fd5cc91 100644
87815--- a/net/ipv4/tcp_ipv4.c
87816+++ b/net/ipv4/tcp_ipv4.c
87817@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
87818 EXPORT_SYMBOL(sysctl_tcp_low_latency);
87819
87820
87821+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87822+extern int grsec_enable_blackhole;
87823+#endif
87824+
87825 #ifdef CONFIG_TCP_MD5SIG
87826 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
87827 __be32 daddr, __be32 saddr, const struct tcphdr *th);
87828@@ -1897,6 +1901,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
87829 return 0;
87830
87831 reset:
87832+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87833+ if (!grsec_enable_blackhole)
87834+#endif
87835 tcp_v4_send_reset(rsk, skb);
87836 discard:
87837 kfree_skb(skb);
87838@@ -1996,12 +2003,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
87839 TCP_SKB_CB(skb)->sacked = 0;
87840
87841 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
87842- if (!sk)
87843+ if (!sk) {
87844+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87845+ ret = 1;
87846+#endif
87847 goto no_tcp_socket;
87848-
87849+ }
87850 process:
87851- if (sk->sk_state == TCP_TIME_WAIT)
87852+ if (sk->sk_state == TCP_TIME_WAIT) {
87853+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87854+ ret = 2;
87855+#endif
87856 goto do_time_wait;
87857+ }
87858
87859 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
87860 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
87861@@ -2052,6 +2066,10 @@ no_tcp_socket:
87862 bad_packet:
87863 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
87864 } else {
87865+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87866+ if (!grsec_enable_blackhole || (ret == 1 &&
87867+ (skb->dev->flags & IFF_LOOPBACK)))
87868+#endif
87869 tcp_v4_send_reset(NULL, skb);
87870 }
87871
87872diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
87873index 2f672e7..b8895e9 100644
87874--- a/net/ipv4/tcp_minisocks.c
87875+++ b/net/ipv4/tcp_minisocks.c
87876@@ -27,6 +27,10 @@
87877 #include <net/inet_common.h>
87878 #include <net/xfrm.h>
87879
87880+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87881+extern int grsec_enable_blackhole;
87882+#endif
87883+
87884 int sysctl_tcp_syncookies __read_mostly = 1;
87885 EXPORT_SYMBOL(sysctl_tcp_syncookies);
87886
87887@@ -749,7 +753,10 @@ embryonic_reset:
87888 * avoid becoming vulnerable to outside attack aiming at
87889 * resetting legit local connections.
87890 */
87891- req->rsk_ops->send_reset(sk, skb);
87892+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87893+ if (!grsec_enable_blackhole)
87894+#endif
87895+ req->rsk_ops->send_reset(sk, skb);
87896 } else if (fastopen) { /* received a valid RST pkt */
87897 reqsk_fastopen_remove(sk, req, true);
87898 tcp_reset(sk);
87899diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
87900index d4943f6..e7a74a5 100644
87901--- a/net/ipv4/tcp_probe.c
87902+++ b/net/ipv4/tcp_probe.c
87903@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
87904 if (cnt + width >= len)
87905 break;
87906
87907- if (copy_to_user(buf + cnt, tbuf, width))
87908+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
87909 return -EFAULT;
87910 cnt += width;
87911 }
87912diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
87913index b78aac3..e18230b 100644
87914--- a/net/ipv4/tcp_timer.c
87915+++ b/net/ipv4/tcp_timer.c
87916@@ -22,6 +22,10 @@
87917 #include <linux/gfp.h>
87918 #include <net/tcp.h>
87919
87920+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87921+extern int grsec_lastack_retries;
87922+#endif
87923+
87924 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
87925 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
87926 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
87927@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
87928 }
87929 }
87930
87931+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87932+ if ((sk->sk_state == TCP_LAST_ACK) &&
87933+ (grsec_lastack_retries > 0) &&
87934+ (grsec_lastack_retries < retry_until))
87935+ retry_until = grsec_lastack_retries;
87936+#endif
87937+
87938 if (retransmits_timed_out(sk, retry_until,
87939 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
87940 /* Has it gone just too far? */
87941diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
87942index 0a073a2..ddf6279 100644
87943--- a/net/ipv4/udp.c
87944+++ b/net/ipv4/udp.c
87945@@ -87,6 +87,7 @@
87946 #include <linux/types.h>
87947 #include <linux/fcntl.h>
87948 #include <linux/module.h>
87949+#include <linux/security.h>
87950 #include <linux/socket.h>
87951 #include <linux/sockios.h>
87952 #include <linux/igmp.h>
87953@@ -111,6 +112,10 @@
87954 #include <trace/events/skb.h>
87955 #include "udp_impl.h"
87956
87957+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87958+extern int grsec_enable_blackhole;
87959+#endif
87960+
87961 struct udp_table udp_table __read_mostly;
87962 EXPORT_SYMBOL(udp_table);
87963
87964@@ -594,6 +599,9 @@ found:
87965 return s;
87966 }
87967
87968+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
87969+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
87970+
87971 /*
87972 * This routine is called by the ICMP module when it gets some
87973 * sort of error condition. If err < 0 then the socket should
87974@@ -889,9 +897,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
87975 dport = usin->sin_port;
87976 if (dport == 0)
87977 return -EINVAL;
87978+
87979+ err = gr_search_udp_sendmsg(sk, usin);
87980+ if (err)
87981+ return err;
87982 } else {
87983 if (sk->sk_state != TCP_ESTABLISHED)
87984 return -EDESTADDRREQ;
87985+
87986+ err = gr_search_udp_sendmsg(sk, NULL);
87987+ if (err)
87988+ return err;
87989+
87990 daddr = inet->inet_daddr;
87991 dport = inet->inet_dport;
87992 /* Open fast path for connected socket.
87993@@ -1133,7 +1150,7 @@ static unsigned int first_packet_length(struct sock *sk)
87994 udp_lib_checksum_complete(skb)) {
87995 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87996 IS_UDPLITE(sk));
87997- atomic_inc(&sk->sk_drops);
87998+ atomic_inc_unchecked(&sk->sk_drops);
87999 __skb_unlink(skb, rcvq);
88000 __skb_queue_tail(&list_kill, skb);
88001 }
88002@@ -1219,6 +1236,10 @@ try_again:
88003 if (!skb)
88004 goto out;
88005
88006+ err = gr_search_udp_recvmsg(sk, skb);
88007+ if (err)
88008+ goto out_free;
88009+
88010 ulen = skb->len - sizeof(struct udphdr);
88011 copied = len;
88012 if (copied > ulen)
88013@@ -1252,7 +1273,7 @@ try_again:
88014 if (unlikely(err)) {
88015 trace_kfree_skb(skb, udp_recvmsg);
88016 if (!peeked) {
88017- atomic_inc(&sk->sk_drops);
88018+ atomic_inc_unchecked(&sk->sk_drops);
88019 UDP_INC_STATS_USER(sock_net(sk),
88020 UDP_MIB_INERRORS, is_udplite);
88021 }
88022@@ -1535,7 +1556,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
88023
88024 drop:
88025 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88026- atomic_inc(&sk->sk_drops);
88027+ atomic_inc_unchecked(&sk->sk_drops);
88028 kfree_skb(skb);
88029 return -1;
88030 }
88031@@ -1554,7 +1575,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88032 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88033
88034 if (!skb1) {
88035- atomic_inc(&sk->sk_drops);
88036+ atomic_inc_unchecked(&sk->sk_drops);
88037 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88038 IS_UDPLITE(sk));
88039 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88040@@ -1723,6 +1744,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88041 goto csum_error;
88042
88043 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88044+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88045+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88046+#endif
88047 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
88048
88049 /*
88050@@ -2152,7 +2176,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
88051 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
88052 0, sock_i_ino(sp),
88053 atomic_read(&sp->sk_refcnt), sp,
88054- atomic_read(&sp->sk_drops), len);
88055+ atomic_read_unchecked(&sp->sk_drops), len);
88056 }
88057
88058 int udp4_seq_show(struct seq_file *seq, void *v)
88059diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
88060index 9a459be..086b866 100644
88061--- a/net/ipv4/xfrm4_policy.c
88062+++ b/net/ipv4/xfrm4_policy.c
88063@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
88064
88065 static int __net_init xfrm4_net_init(struct net *net)
88066 {
88067- struct ctl_table *table;
88068+ ctl_table_no_const *table = NULL;
88069 struct ctl_table_header *hdr;
88070
88071- table = xfrm4_policy_table;
88072 if (!net_eq(net, &init_net)) {
88073- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
88074+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
88075 if (!table)
88076 goto err_alloc;
88077
88078 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
88079- }
88080-
88081- hdr = register_net_sysctl(net, "net/ipv4", table);
88082+ hdr = register_net_sysctl(net, "net/ipv4", table);
88083+ } else
88084+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
88085 if (!hdr)
88086 goto err_reg;
88087
88088@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
88089 return 0;
88090
88091 err_reg:
88092- if (!net_eq(net, &init_net))
88093- kfree(table);
88094+ kfree(table);
88095 err_alloc:
88096 return -ENOMEM;
88097 }
88098diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
88099index 50a4c7c..50a27e6 100644
88100--- a/net/ipv6/addrconf.c
88101+++ b/net/ipv6/addrconf.c
88102@@ -2274,7 +2274,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
88103 p.iph.ihl = 5;
88104 p.iph.protocol = IPPROTO_IPV6;
88105 p.iph.ttl = 64;
88106- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
88107+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
88108
88109 if (ops->ndo_do_ioctl) {
88110 mm_segment_t oldfs = get_fs();
88111@@ -4412,7 +4412,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
88112 int *valp = ctl->data;
88113 int val = *valp;
88114 loff_t pos = *ppos;
88115- ctl_table lctl;
88116+ ctl_table_no_const lctl;
88117 int ret;
88118
88119 /*
88120@@ -4494,7 +4494,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
88121 int *valp = ctl->data;
88122 int val = *valp;
88123 loff_t pos = *ppos;
88124- ctl_table lctl;
88125+ ctl_table_no_const lctl;
88126 int ret;
88127
88128 /*
88129diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
88130index fff5bdd..15194fb 100644
88131--- a/net/ipv6/icmp.c
88132+++ b/net/ipv6/icmp.c
88133@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
88134
88135 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
88136 {
88137- struct ctl_table *table;
88138+ ctl_table_no_const *table;
88139
88140 table = kmemdup(ipv6_icmp_table_template,
88141 sizeof(ipv6_icmp_table_template),
88142diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
88143index 95d13c7..791fe2f 100644
88144--- a/net/ipv6/ip6_gre.c
88145+++ b/net/ipv6/ip6_gre.c
88146@@ -73,7 +73,7 @@ struct ip6gre_net {
88147 struct net_device *fb_tunnel_dev;
88148 };
88149
88150-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
88151+static struct rtnl_link_ops ip6gre_link_ops;
88152 static int ip6gre_tunnel_init(struct net_device *dev);
88153 static void ip6gre_tunnel_setup(struct net_device *dev);
88154 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
88155@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
88156 }
88157
88158
88159-static struct inet6_protocol ip6gre_protocol __read_mostly = {
88160+static struct inet6_protocol ip6gre_protocol = {
88161 .handler = ip6gre_rcv,
88162 .err_handler = ip6gre_err,
88163 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
88164@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
88165 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
88166 };
88167
88168-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
88169+static struct rtnl_link_ops ip6gre_link_ops = {
88170 .kind = "ip6gre",
88171 .maxtype = IFLA_GRE_MAX,
88172 .policy = ip6gre_policy,
88173@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
88174 .fill_info = ip6gre_fill_info,
88175 };
88176
88177-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
88178+static struct rtnl_link_ops ip6gre_tap_ops = {
88179 .kind = "ip6gretap",
88180 .maxtype = IFLA_GRE_MAX,
88181 .policy = ip6gre_policy,
88182diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
88183index 851fdae..9d4d1fd 100644
88184--- a/net/ipv6/ip6_output.c
88185+++ b/net/ipv6/ip6_output.c
88186@@ -822,11 +822,17 @@ static struct dst_entry *ip6_sk_dst_check(struct sock *sk,
88187 const struct flowi6 *fl6)
88188 {
88189 struct ipv6_pinfo *np = inet6_sk(sk);
88190- struct rt6_info *rt = (struct rt6_info *)dst;
88191+ struct rt6_info *rt;
88192
88193 if (!dst)
88194 goto out;
88195
88196+ if (dst->ops->family != AF_INET6) {
88197+ dst_release(dst);
88198+ return NULL;
88199+ }
88200+
88201+ rt = (struct rt6_info *)dst;
88202 /* Yes, checking route validity in not connected
88203 * case is not very simple. Take into account,
88204 * that we do not support routing by source, TOS,
88205diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
88206index fff83cb..82d49dd 100644
88207--- a/net/ipv6/ip6_tunnel.c
88208+++ b/net/ipv6/ip6_tunnel.c
88209@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
88210
88211 static int ip6_tnl_dev_init(struct net_device *dev);
88212 static void ip6_tnl_dev_setup(struct net_device *dev);
88213-static struct rtnl_link_ops ip6_link_ops __read_mostly;
88214+static struct rtnl_link_ops ip6_link_ops;
88215
88216 static int ip6_tnl_net_id __read_mostly;
88217 struct ip6_tnl_net {
88218@@ -1684,7 +1684,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
88219 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
88220 };
88221
88222-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
88223+static struct rtnl_link_ops ip6_link_ops = {
88224 .kind = "ip6tnl",
88225 .maxtype = IFLA_IPTUN_MAX,
88226 .policy = ip6_tnl_policy,
88227diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
88228index d1e2e8e..51c19ae 100644
88229--- a/net/ipv6/ipv6_sockglue.c
88230+++ b/net/ipv6/ipv6_sockglue.c
88231@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
88232 if (sk->sk_type != SOCK_STREAM)
88233 return -ENOPROTOOPT;
88234
88235- msg.msg_control = optval;
88236+ msg.msg_control = (void __force_kernel *)optval;
88237 msg.msg_controllen = len;
88238 msg.msg_flags = flags;
88239
88240diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
88241index 341b54a..591e8ed 100644
88242--- a/net/ipv6/netfilter/ip6_tables.c
88243+++ b/net/ipv6/netfilter/ip6_tables.c
88244@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
88245 #endif
88246
88247 static int get_info(struct net *net, void __user *user,
88248- const int *len, int compat)
88249+ int len, int compat)
88250 {
88251 char name[XT_TABLE_MAXNAMELEN];
88252 struct xt_table *t;
88253 int ret;
88254
88255- if (*len != sizeof(struct ip6t_getinfo)) {
88256- duprintf("length %u != %zu\n", *len,
88257+ if (len != sizeof(struct ip6t_getinfo)) {
88258+ duprintf("length %u != %zu\n", len,
88259 sizeof(struct ip6t_getinfo));
88260 return -EINVAL;
88261 }
88262@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
88263 info.size = private->size;
88264 strcpy(info.name, name);
88265
88266- if (copy_to_user(user, &info, *len) != 0)
88267+ if (copy_to_user(user, &info, len) != 0)
88268 ret = -EFAULT;
88269 else
88270 ret = 0;
88271@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88272
88273 switch (cmd) {
88274 case IP6T_SO_GET_INFO:
88275- ret = get_info(sock_net(sk), user, len, 1);
88276+ ret = get_info(sock_net(sk), user, *len, 1);
88277 break;
88278 case IP6T_SO_GET_ENTRIES:
88279 ret = compat_get_entries(sock_net(sk), user, len);
88280@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88281
88282 switch (cmd) {
88283 case IP6T_SO_GET_INFO:
88284- ret = get_info(sock_net(sk), user, len, 0);
88285+ ret = get_info(sock_net(sk), user, *len, 0);
88286 break;
88287
88288 case IP6T_SO_GET_ENTRIES:
88289diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
88290index 6700069..1e50f42 100644
88291--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
88292+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
88293@@ -89,12 +89,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
88294
88295 static int nf_ct_frag6_sysctl_register(struct net *net)
88296 {
88297- struct ctl_table *table;
88298+ ctl_table_no_const *table = NULL;
88299 struct ctl_table_header *hdr;
88300
88301- table = nf_ct_frag6_sysctl_table;
88302 if (!net_eq(net, &init_net)) {
88303- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
88304+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
88305 GFP_KERNEL);
88306 if (table == NULL)
88307 goto err_alloc;
88308@@ -102,9 +101,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88309 table[0].data = &net->nf_frag.frags.timeout;
88310 table[1].data = &net->nf_frag.frags.low_thresh;
88311 table[2].data = &net->nf_frag.frags.high_thresh;
88312- }
88313-
88314- hdr = register_net_sysctl(net, "net/netfilter", table);
88315+ hdr = register_net_sysctl(net, "net/netfilter", table);
88316+ } else
88317+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
88318 if (hdr == NULL)
88319 goto err_reg;
88320
88321@@ -112,8 +111,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88322 return 0;
88323
88324 err_reg:
88325- if (!net_eq(net, &init_net))
88326- kfree(table);
88327+ kfree(table);
88328 err_alloc:
88329 return -ENOMEM;
88330 }
88331diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
88332index 330b5e7..796fbf1 100644
88333--- a/net/ipv6/raw.c
88334+++ b/net/ipv6/raw.c
88335@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
88336 {
88337 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
88338 skb_checksum_complete(skb)) {
88339- atomic_inc(&sk->sk_drops);
88340+ atomic_inc_unchecked(&sk->sk_drops);
88341 kfree_skb(skb);
88342 return NET_RX_DROP;
88343 }
88344@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88345 struct raw6_sock *rp = raw6_sk(sk);
88346
88347 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
88348- atomic_inc(&sk->sk_drops);
88349+ atomic_inc_unchecked(&sk->sk_drops);
88350 kfree_skb(skb);
88351 return NET_RX_DROP;
88352 }
88353@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88354
88355 if (inet->hdrincl) {
88356 if (skb_checksum_complete(skb)) {
88357- atomic_inc(&sk->sk_drops);
88358+ atomic_inc_unchecked(&sk->sk_drops);
88359 kfree_skb(skb);
88360 return NET_RX_DROP;
88361 }
88362@@ -603,7 +603,7 @@ out:
88363 return err;
88364 }
88365
88366-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
88367+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
88368 struct flowi6 *fl6, struct dst_entry **dstp,
88369 unsigned int flags)
88370 {
88371@@ -915,12 +915,15 @@ do_confirm:
88372 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
88373 char __user *optval, int optlen)
88374 {
88375+ struct icmp6_filter filter;
88376+
88377 switch (optname) {
88378 case ICMPV6_FILTER:
88379 if (optlen > sizeof(struct icmp6_filter))
88380 optlen = sizeof(struct icmp6_filter);
88381- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
88382+ if (copy_from_user(&filter, optval, optlen))
88383 return -EFAULT;
88384+ raw6_sk(sk)->filter = filter;
88385 return 0;
88386 default:
88387 return -ENOPROTOOPT;
88388@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88389 char __user *optval, int __user *optlen)
88390 {
88391 int len;
88392+ struct icmp6_filter filter;
88393
88394 switch (optname) {
88395 case ICMPV6_FILTER:
88396@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88397 len = sizeof(struct icmp6_filter);
88398 if (put_user(len, optlen))
88399 return -EFAULT;
88400- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
88401+ filter = raw6_sk(sk)->filter;
88402+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
88403 return -EFAULT;
88404 return 0;
88405 default:
88406@@ -1252,7 +1257,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
88407 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
88408 0,
88409 sock_i_ino(sp),
88410- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
88411+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
88412 }
88413
88414 static int raw6_seq_show(struct seq_file *seq, void *v)
88415diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
88416index 0ba10e5..c14a4f6 100644
88417--- a/net/ipv6/reassembly.c
88418+++ b/net/ipv6/reassembly.c
88419@@ -602,12 +602,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
88420
88421 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88422 {
88423- struct ctl_table *table;
88424+ ctl_table_no_const *table = NULL;
88425 struct ctl_table_header *hdr;
88426
88427- table = ip6_frags_ns_ctl_table;
88428 if (!net_eq(net, &init_net)) {
88429- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88430+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88431 if (table == NULL)
88432 goto err_alloc;
88433
88434@@ -618,9 +617,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88435 /* Don't export sysctls to unprivileged users */
88436 if (net->user_ns != &init_user_ns)
88437 table[0].procname = NULL;
88438- }
88439+ hdr = register_net_sysctl(net, "net/ipv6", table);
88440+ } else
88441+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
88442
88443- hdr = register_net_sysctl(net, "net/ipv6", table);
88444 if (hdr == NULL)
88445 goto err_reg;
88446
88447@@ -628,8 +628,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88448 return 0;
88449
88450 err_reg:
88451- if (!net_eq(net, &init_net))
88452- kfree(table);
88453+ kfree(table);
88454 err_alloc:
88455 return -ENOMEM;
88456 }
88457diff --git a/net/ipv6/route.c b/net/ipv6/route.c
88458index e5fe004..9fe3e8e 100644
88459--- a/net/ipv6/route.c
88460+++ b/net/ipv6/route.c
88461@@ -2881,7 +2881,7 @@ ctl_table ipv6_route_table_template[] = {
88462
88463 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
88464 {
88465- struct ctl_table *table;
88466+ ctl_table_no_const *table;
88467
88468 table = kmemdup(ipv6_route_table_template,
88469 sizeof(ipv6_route_table_template),
88470diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
88471index 02f96dc..4a5a6e5 100644
88472--- a/net/ipv6/sit.c
88473+++ b/net/ipv6/sit.c
88474@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
88475 static void ipip6_dev_free(struct net_device *dev);
88476 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
88477 __be32 *v4dst);
88478-static struct rtnl_link_ops sit_link_ops __read_mostly;
88479+static struct rtnl_link_ops sit_link_ops;
88480
88481 static int sit_net_id __read_mostly;
88482 struct sit_net {
88483@@ -1486,7 +1486,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
88484 #endif
88485 };
88486
88487-static struct rtnl_link_ops sit_link_ops __read_mostly = {
88488+static struct rtnl_link_ops sit_link_ops = {
88489 .kind = "sit",
88490 .maxtype = IFLA_IPTUN_MAX,
88491 .policy = ipip6_policy,
88492diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
88493index e85c48b..b8268d3 100644
88494--- a/net/ipv6/sysctl_net_ipv6.c
88495+++ b/net/ipv6/sysctl_net_ipv6.c
88496@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
88497
88498 static int __net_init ipv6_sysctl_net_init(struct net *net)
88499 {
88500- struct ctl_table *ipv6_table;
88501+ ctl_table_no_const *ipv6_table;
88502 struct ctl_table *ipv6_route_table;
88503 struct ctl_table *ipv6_icmp_table;
88504 int err;
88505diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
88506index 0fce928..c52a518 100644
88507--- a/net/ipv6/tcp_ipv6.c
88508+++ b/net/ipv6/tcp_ipv6.c
88509@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
88510 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
88511 }
88512
88513+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88514+extern int grsec_enable_blackhole;
88515+#endif
88516+
88517 static void tcp_v6_hash(struct sock *sk)
88518 {
88519 if (sk->sk_state != TCP_CLOSE) {
88520@@ -1446,6 +1450,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
88521 return 0;
88522
88523 reset:
88524+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88525+ if (!grsec_enable_blackhole)
88526+#endif
88527 tcp_v6_send_reset(sk, skb);
88528 discard:
88529 if (opt_skb)
88530@@ -1527,12 +1534,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
88531 TCP_SKB_CB(skb)->sacked = 0;
88532
88533 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88534- if (!sk)
88535+ if (!sk) {
88536+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88537+ ret = 1;
88538+#endif
88539 goto no_tcp_socket;
88540+ }
88541
88542 process:
88543- if (sk->sk_state == TCP_TIME_WAIT)
88544+ if (sk->sk_state == TCP_TIME_WAIT) {
88545+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88546+ ret = 2;
88547+#endif
88548 goto do_time_wait;
88549+ }
88550
88551 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
88552 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88553@@ -1581,6 +1596,10 @@ no_tcp_socket:
88554 bad_packet:
88555 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88556 } else {
88557+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88558+ if (!grsec_enable_blackhole || (ret == 1 &&
88559+ (skb->dev->flags & IFF_LOOPBACK)))
88560+#endif
88561 tcp_v6_send_reset(NULL, skb);
88562 }
88563
88564diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
88565index 27f0f8e..949e7ee 100644
88566--- a/net/ipv6/udp.c
88567+++ b/net/ipv6/udp.c
88568@@ -52,6 +52,10 @@
88569 #include <trace/events/skb.h>
88570 #include "udp_impl.h"
88571
88572+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88573+extern int grsec_enable_blackhole;
88574+#endif
88575+
88576 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
88577 {
88578 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
88579@@ -419,7 +423,7 @@ try_again:
88580 if (unlikely(err)) {
88581 trace_kfree_skb(skb, udpv6_recvmsg);
88582 if (!peeked) {
88583- atomic_inc(&sk->sk_drops);
88584+ atomic_inc_unchecked(&sk->sk_drops);
88585 if (is_udp4)
88586 UDP_INC_STATS_USER(sock_net(sk),
88587 UDP_MIB_INERRORS,
88588@@ -657,7 +661,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
88589 return rc;
88590 drop:
88591 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88592- atomic_inc(&sk->sk_drops);
88593+ atomic_inc_unchecked(&sk->sk_drops);
88594 kfree_skb(skb);
88595 return -1;
88596 }
88597@@ -715,7 +719,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88598 if (likely(skb1 == NULL))
88599 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88600 if (!skb1) {
88601- atomic_inc(&sk->sk_drops);
88602+ atomic_inc_unchecked(&sk->sk_drops);
88603 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88604 IS_UDPLITE(sk));
88605 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88606@@ -852,6 +856,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88607 goto discard;
88608
88609 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88610+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88611+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88612+#endif
88613 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
88614
88615 kfree_skb(skb);
88616@@ -1377,7 +1384,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
88617 0,
88618 sock_i_ino(sp),
88619 atomic_read(&sp->sk_refcnt), sp,
88620- atomic_read(&sp->sk_drops));
88621+ atomic_read_unchecked(&sp->sk_drops));
88622 }
88623
88624 int udp6_seq_show(struct seq_file *seq, void *v)
88625diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
88626index 23ed03d..465a71d 100644
88627--- a/net/ipv6/xfrm6_policy.c
88628+++ b/net/ipv6/xfrm6_policy.c
88629@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
88630
88631 static int __net_init xfrm6_net_init(struct net *net)
88632 {
88633- struct ctl_table *table;
88634+ ctl_table_no_const *table = NULL;
88635 struct ctl_table_header *hdr;
88636
88637- table = xfrm6_policy_table;
88638 if (!net_eq(net, &init_net)) {
88639- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
88640+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
88641 if (!table)
88642 goto err_alloc;
88643
88644 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
88645- }
88646+ hdr = register_net_sysctl(net, "net/ipv6", table);
88647+ } else
88648+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
88649
88650- hdr = register_net_sysctl(net, "net/ipv6", table);
88651 if (!hdr)
88652 goto err_reg;
88653
88654@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
88655 return 0;
88656
88657 err_reg:
88658- if (!net_eq(net, &init_net))
88659- kfree(table);
88660+ kfree(table);
88661 err_alloc:
88662 return -ENOMEM;
88663 }
88664diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
88665index 362ba47..66196f4 100644
88666--- a/net/irda/ircomm/ircomm_tty.c
88667+++ b/net/irda/ircomm/ircomm_tty.c
88668@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88669 add_wait_queue(&port->open_wait, &wait);
88670
88671 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
88672- __FILE__, __LINE__, tty->driver->name, port->count);
88673+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88674
88675 spin_lock_irqsave(&port->lock, flags);
88676 if (!tty_hung_up_p(filp))
88677- port->count--;
88678+ atomic_dec(&port->count);
88679 port->blocked_open++;
88680 spin_unlock_irqrestore(&port->lock, flags);
88681
88682@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88683 }
88684
88685 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
88686- __FILE__, __LINE__, tty->driver->name, port->count);
88687+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88688
88689 schedule();
88690 }
88691@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88692
88693 spin_lock_irqsave(&port->lock, flags);
88694 if (!tty_hung_up_p(filp))
88695- port->count++;
88696+ atomic_inc(&port->count);
88697 port->blocked_open--;
88698 spin_unlock_irqrestore(&port->lock, flags);
88699
88700 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
88701- __FILE__, __LINE__, tty->driver->name, port->count);
88702+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88703
88704 if (!retval)
88705 port->flags |= ASYNC_NORMAL_ACTIVE;
88706@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
88707
88708 /* ++ is not atomic, so this should be protected - Jean II */
88709 spin_lock_irqsave(&self->port.lock, flags);
88710- self->port.count++;
88711+ atomic_inc(&self->port.count);
88712 spin_unlock_irqrestore(&self->port.lock, flags);
88713 tty_port_tty_set(&self->port, tty);
88714
88715 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
88716- self->line, self->port.count);
88717+ self->line, atomic_read(&self->port.count));
88718
88719 /* Not really used by us, but lets do it anyway */
88720 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
88721@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
88722 tty_kref_put(port->tty);
88723 }
88724 port->tty = NULL;
88725- port->count = 0;
88726+ atomic_set(&port->count, 0);
88727 spin_unlock_irqrestore(&port->lock, flags);
88728
88729 wake_up_interruptible(&port->open_wait);
88730@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
88731 seq_putc(m, '\n');
88732
88733 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
88734- seq_printf(m, "Open count: %d\n", self->port.count);
88735+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
88736 seq_printf(m, "Max data size: %d\n", self->max_data_size);
88737 seq_printf(m, "Max header size: %d\n", self->max_header_size);
88738
88739diff --git a/net/irda/irlap_frame.c b/net/irda/irlap_frame.c
88740index 8c00416..9ea0c93 100644
88741--- a/net/irda/irlap_frame.c
88742+++ b/net/irda/irlap_frame.c
88743@@ -544,7 +544,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
88744 /*
88745 * We now have some discovery info to deliver!
88746 */
88747- discovery = kmalloc(sizeof(discovery_t), GFP_ATOMIC);
88748+ discovery = kzalloc(sizeof(discovery_t), GFP_ATOMIC);
88749 if (!discovery) {
88750 IRDA_WARNING("%s: unable to malloc!\n", __func__);
88751 return;
88752diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
88753index 206ce6d..cfb27cd 100644
88754--- a/net/iucv/af_iucv.c
88755+++ b/net/iucv/af_iucv.c
88756@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
88757
88758 write_lock_bh(&iucv_sk_list.lock);
88759
88760- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
88761+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88762 while (__iucv_get_sock_by_name(name)) {
88763 sprintf(name, "%08x",
88764- atomic_inc_return(&iucv_sk_list.autobind_name));
88765+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88766 }
88767
88768 write_unlock_bh(&iucv_sk_list.lock);
88769diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
88770index 4fe76ff..426a904 100644
88771--- a/net/iucv/iucv.c
88772+++ b/net/iucv/iucv.c
88773@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
88774 return NOTIFY_OK;
88775 }
88776
88777-static struct notifier_block __refdata iucv_cpu_notifier = {
88778+static struct notifier_block iucv_cpu_notifier = {
88779 .notifier_call = iucv_cpu_notify,
88780 };
88781
88782diff --git a/net/key/af_key.c b/net/key/af_key.c
88783index 5b1e5af..1b929e7 100644
88784--- a/net/key/af_key.c
88785+++ b/net/key/af_key.c
88786@@ -1710,6 +1710,7 @@ static int key_notify_sa_flush(const struct km_event *c)
88787 hdr->sadb_msg_version = PF_KEY_V2;
88788 hdr->sadb_msg_errno = (uint8_t) 0;
88789 hdr->sadb_msg_len = (sizeof(struct sadb_msg) / sizeof(uint64_t));
88790+ hdr->sadb_msg_reserved = 0;
88791
88792 pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_ALL, NULL, c->net);
88793
88794@@ -2695,6 +2696,7 @@ static int key_notify_policy_flush(const struct km_event *c)
88795 hdr->sadb_msg_errno = (uint8_t) 0;
88796 hdr->sadb_msg_satype = SADB_SATYPE_UNSPEC;
88797 hdr->sadb_msg_len = (sizeof(struct sadb_msg) / sizeof(uint64_t));
88798+ hdr->sadb_msg_reserved = 0;
88799 pfkey_broadcast(skb_out, GFP_ATOMIC, BROADCAST_ALL, NULL, c->net);
88800 return 0;
88801
88802@@ -3041,10 +3043,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
88803 static u32 get_acqseq(void)
88804 {
88805 u32 res;
88806- static atomic_t acqseq;
88807+ static atomic_unchecked_t acqseq;
88808
88809 do {
88810- res = atomic_inc_return(&acqseq);
88811+ res = atomic_inc_return_unchecked(&acqseq);
88812 } while (!res);
88813 return res;
88814 }
88815diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
88816index 843d8c4..cb04fa1 100644
88817--- a/net/mac80211/cfg.c
88818+++ b/net/mac80211/cfg.c
88819@@ -799,7 +799,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
88820 ret = ieee80211_vif_use_channel(sdata, chandef,
88821 IEEE80211_CHANCTX_EXCLUSIVE);
88822 }
88823- } else if (local->open_count == local->monitors) {
88824+ } else if (local_read(&local->open_count) == local->monitors) {
88825 local->_oper_channel = chandef->chan;
88826 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
88827 ieee80211_hw_config(local, 0);
88828@@ -2834,7 +2834,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
88829 else
88830 local->probe_req_reg--;
88831
88832- if (!local->open_count)
88833+ if (!local_read(&local->open_count))
88834 break;
88835
88836 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
88837@@ -3297,8 +3297,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
88838 if (chanctx_conf) {
88839 *chandef = chanctx_conf->def;
88840 ret = 0;
88841- } else if (local->open_count > 0 &&
88842- local->open_count == local->monitors &&
88843+ } else if (local_read(&local->open_count) > 0 &&
88844+ local_read(&local->open_count) == local->monitors &&
88845 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
88846 if (local->use_chanctx)
88847 *chandef = local->monitor_chandef;
88848diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
88849index 4e74cd6..963b8a1 100644
88850--- a/net/mac80211/ieee80211_i.h
88851+++ b/net/mac80211/ieee80211_i.h
88852@@ -28,6 +28,7 @@
88853 #include <net/ieee80211_radiotap.h>
88854 #include <net/cfg80211.h>
88855 #include <net/mac80211.h>
88856+#include <asm/local.h>
88857 #include "key.h"
88858 #include "sta_info.h"
88859 #include "debug.h"
88860@@ -897,7 +898,7 @@ struct ieee80211_local {
88861 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
88862 spinlock_t queue_stop_reason_lock;
88863
88864- int open_count;
88865+ local_t open_count;
88866 int monitors, cooked_mntrs;
88867 /* number of interfaces with corresponding FIF_ flags */
88868 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
88869diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
88870index 9cbebc2..14879bb 100644
88871--- a/net/mac80211/iface.c
88872+++ b/net/mac80211/iface.c
88873@@ -495,7 +495,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88874 break;
88875 }
88876
88877- if (local->open_count == 0) {
88878+ if (local_read(&local->open_count) == 0) {
88879 res = drv_start(local);
88880 if (res)
88881 goto err_del_bss;
88882@@ -540,7 +540,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88883 break;
88884 }
88885
88886- if (local->monitors == 0 && local->open_count == 0) {
88887+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
88888 res = ieee80211_add_virtual_monitor(local);
88889 if (res)
88890 goto err_stop;
88891@@ -649,7 +649,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88892 atomic_inc(&local->iff_promiscs);
88893
88894 if (coming_up)
88895- local->open_count++;
88896+ local_inc(&local->open_count);
88897
88898 if (hw_reconf_flags)
88899 ieee80211_hw_config(local, hw_reconf_flags);
88900@@ -663,7 +663,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88901 err_del_interface:
88902 drv_remove_interface(local, sdata);
88903 err_stop:
88904- if (!local->open_count)
88905+ if (!local_read(&local->open_count))
88906 drv_stop(local);
88907 err_del_bss:
88908 sdata->bss = NULL;
88909@@ -806,7 +806,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88910 }
88911
88912 if (going_down)
88913- local->open_count--;
88914+ local_dec(&local->open_count);
88915
88916 switch (sdata->vif.type) {
88917 case NL80211_IFTYPE_AP_VLAN:
88918@@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88919
88920 ieee80211_recalc_ps(local, -1);
88921
88922- if (local->open_count == 0) {
88923+ if (local_read(&local->open_count) == 0) {
88924 if (local->ops->napi_poll)
88925 napi_disable(&local->napi);
88926 ieee80211_clear_tx_pending(local);
88927@@ -897,7 +897,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88928 }
88929 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
88930
88931- if (local->monitors == local->open_count && local->monitors > 0)
88932+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
88933 ieee80211_add_virtual_monitor(local);
88934 }
88935
88936diff --git a/net/mac80211/main.c b/net/mac80211/main.c
88937index 1a8591b..ef5db54 100644
88938--- a/net/mac80211/main.c
88939+++ b/net/mac80211/main.c
88940@@ -180,7 +180,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
88941 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
88942 IEEE80211_CONF_CHANGE_POWER);
88943
88944- if (changed && local->open_count) {
88945+ if (changed && local_read(&local->open_count)) {
88946 ret = drv_config(local, changed);
88947 /*
88948 * Goal:
88949diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
88950index 835584c..be46e67 100644
88951--- a/net/mac80211/pm.c
88952+++ b/net/mac80211/pm.c
88953@@ -33,7 +33,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88954 struct sta_info *sta;
88955 struct ieee80211_chanctx *ctx;
88956
88957- if (!local->open_count)
88958+ if (!local_read(&local->open_count))
88959 goto suspend;
88960
88961 ieee80211_scan_cancel(local);
88962@@ -75,7 +75,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88963 cancel_work_sync(&local->dynamic_ps_enable_work);
88964 del_timer_sync(&local->dynamic_ps_timer);
88965
88966- local->wowlan = wowlan && local->open_count;
88967+ local->wowlan = wowlan && local_read(&local->open_count);
88968 if (local->wowlan) {
88969 int err = drv_suspend(local, wowlan);
88970 if (err < 0) {
88971@@ -214,7 +214,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88972 mutex_unlock(&local->chanctx_mtx);
88973
88974 /* stop hardware - this must stop RX */
88975- if (local->open_count)
88976+ if (local_read(&local->open_count))
88977 ieee80211_stop_device(local);
88978
88979 suspend:
88980diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
88981index dd88381..eef4dd6 100644
88982--- a/net/mac80211/rate.c
88983+++ b/net/mac80211/rate.c
88984@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
88985
88986 ASSERT_RTNL();
88987
88988- if (local->open_count)
88989+ if (local_read(&local->open_count))
88990 return -EBUSY;
88991
88992 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
88993diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
88994index c97a065..ff61928 100644
88995--- a/net/mac80211/rc80211_pid_debugfs.c
88996+++ b/net/mac80211/rc80211_pid_debugfs.c
88997@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
88998
88999 spin_unlock_irqrestore(&events->lock, status);
89000
89001- if (copy_to_user(buf, pb, p))
89002+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
89003 return -EFAULT;
89004
89005 return p;
89006diff --git a/net/mac80211/util.c b/net/mac80211/util.c
89007index 1f4b908..c4def45 100644
89008--- a/net/mac80211/util.c
89009+++ b/net/mac80211/util.c
89010@@ -1388,7 +1388,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
89011 }
89012 #endif
89013 /* everything else happens only if HW was up & running */
89014- if (!local->open_count)
89015+ if (!local_read(&local->open_count))
89016 goto wake_up;
89017
89018 /*
89019diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
89020index 56d22ca..87c778f 100644
89021--- a/net/netfilter/Kconfig
89022+++ b/net/netfilter/Kconfig
89023@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
89024
89025 To compile it as a module, choose M here. If unsure, say N.
89026
89027+config NETFILTER_XT_MATCH_GRADM
89028+ tristate '"gradm" match support'
89029+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
89030+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
89031+ ---help---
89032+ The gradm match allows to match on grsecurity RBAC being enabled.
89033+ It is useful when iptables rules are applied early on bootup to
89034+ prevent connections to the machine (except from a trusted host)
89035+ while the RBAC system is disabled.
89036+
89037 config NETFILTER_XT_MATCH_HASHLIMIT
89038 tristate '"hashlimit" match support'
89039 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
89040diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
89041index a1abf87..dbcb7ee 100644
89042--- a/net/netfilter/Makefile
89043+++ b/net/netfilter/Makefile
89044@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
89045 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
89046 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
89047 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
89048+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
89049 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
89050 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
89051 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
89052diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
89053index 1ba9dbc..e39f4ca 100644
89054--- a/net/netfilter/ipset/ip_set_core.c
89055+++ b/net/netfilter/ipset/ip_set_core.c
89056@@ -1801,7 +1801,7 @@ done:
89057 return ret;
89058 }
89059
89060-static struct nf_sockopt_ops so_set __read_mostly = {
89061+static struct nf_sockopt_ops so_set = {
89062 .pf = PF_INET,
89063 .get_optmin = SO_IP_SET,
89064 .get_optmax = SO_IP_SET + 1,
89065diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
89066index 704e514..d644cc2 100644
89067--- a/net/netfilter/ipvs/ip_vs_conn.c
89068+++ b/net/netfilter/ipvs/ip_vs_conn.c
89069@@ -551,7 +551,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
89070 /* Increase the refcnt counter of the dest */
89071 atomic_inc(&dest->refcnt);
89072
89073- conn_flags = atomic_read(&dest->conn_flags);
89074+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
89075 if (cp->protocol != IPPROTO_UDP)
89076 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
89077 flags = cp->flags;
89078@@ -895,7 +895,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
89079 atomic_set(&cp->refcnt, 1);
89080
89081 atomic_set(&cp->n_control, 0);
89082- atomic_set(&cp->in_pkts, 0);
89083+ atomic_set_unchecked(&cp->in_pkts, 0);
89084
89085 atomic_inc(&ipvs->conn_count);
89086 if (flags & IP_VS_CONN_F_NO_CPORT)
89087@@ -1174,7 +1174,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
89088
89089 /* Don't drop the entry if its number of incoming packets is not
89090 located in [0, 8] */
89091- i = atomic_read(&cp->in_pkts);
89092+ i = atomic_read_unchecked(&cp->in_pkts);
89093 if (i > 8 || i < 0) return 0;
89094
89095 if (!todrop_rate[i]) return 0;
89096diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
89097index 61f49d2..6c8c5bc 100644
89098--- a/net/netfilter/ipvs/ip_vs_core.c
89099+++ b/net/netfilter/ipvs/ip_vs_core.c
89100@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
89101 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
89102 /* do not touch skb anymore */
89103
89104- atomic_inc(&cp->in_pkts);
89105+ atomic_inc_unchecked(&cp->in_pkts);
89106 ip_vs_conn_put(cp);
89107 return ret;
89108 }
89109@@ -1689,7 +1689,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
89110 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
89111 pkts = sysctl_sync_threshold(ipvs);
89112 else
89113- pkts = atomic_add_return(1, &cp->in_pkts);
89114+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89115
89116 if (ipvs->sync_state & IP_VS_STATE_MASTER)
89117 ip_vs_sync_conn(net, cp, pkts);
89118diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
89119index 9e2d1cc..6ed0748 100644
89120--- a/net/netfilter/ipvs/ip_vs_ctl.c
89121+++ b/net/netfilter/ipvs/ip_vs_ctl.c
89122@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
89123 ip_vs_rs_hash(ipvs, dest);
89124 write_unlock_bh(&ipvs->rs_lock);
89125 }
89126- atomic_set(&dest->conn_flags, conn_flags);
89127+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
89128
89129 /* bind the service */
89130 if (!dest->svc) {
89131@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
89132 * align with netns init in ip_vs_control_net_init()
89133 */
89134
89135-static struct ctl_table vs_vars[] = {
89136+static ctl_table_no_const vs_vars[] __read_only = {
89137 {
89138 .procname = "amemthresh",
89139 .maxlen = sizeof(int),
89140@@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
89141 " %-7s %-6d %-10d %-10d\n",
89142 &dest->addr.in6,
89143 ntohs(dest->port),
89144- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
89145+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
89146 atomic_read(&dest->weight),
89147 atomic_read(&dest->activeconns),
89148 atomic_read(&dest->inactconns));
89149@@ -2098,7 +2098,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
89150 "%-7s %-6d %-10d %-10d\n",
89151 ntohl(dest->addr.ip),
89152 ntohs(dest->port),
89153- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
89154+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
89155 atomic_read(&dest->weight),
89156 atomic_read(&dest->activeconns),
89157 atomic_read(&dest->inactconns));
89158@@ -2562,13 +2562,14 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
89159 struct ip_vs_dest *dest;
89160 struct ip_vs_dest_entry entry;
89161
89162+ memset(&entry, 0, sizeof(entry));
89163 list_for_each_entry(dest, &svc->destinations, n_list) {
89164 if (count >= get->num_dests)
89165 break;
89166
89167 entry.addr = dest->addr.ip;
89168 entry.port = dest->port;
89169- entry.conn_flags = atomic_read(&dest->conn_flags);
89170+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
89171 entry.weight = atomic_read(&dest->weight);
89172 entry.u_threshold = dest->u_threshold;
89173 entry.l_threshold = dest->l_threshold;
89174@@ -3104,7 +3105,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
89175 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
89176 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
89177 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
89178- (atomic_read(&dest->conn_flags) &
89179+ (atomic_read_unchecked(&dest->conn_flags) &
89180 IP_VS_CONN_F_FWD_MASK)) ||
89181 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
89182 atomic_read(&dest->weight)) ||
89183@@ -3694,7 +3695,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
89184 {
89185 int idx;
89186 struct netns_ipvs *ipvs = net_ipvs(net);
89187- struct ctl_table *tbl;
89188+ ctl_table_no_const *tbl;
89189
89190 atomic_set(&ipvs->dropentry, 0);
89191 spin_lock_init(&ipvs->dropentry_lock);
89192diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
89193index fdd89b9..bd96aa9 100644
89194--- a/net/netfilter/ipvs/ip_vs_lblc.c
89195+++ b/net/netfilter/ipvs/ip_vs_lblc.c
89196@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
89197 * IPVS LBLC sysctl table
89198 */
89199 #ifdef CONFIG_SYSCTL
89200-static ctl_table vs_vars_table[] = {
89201+static ctl_table_no_const vs_vars_table[] __read_only = {
89202 {
89203 .procname = "lblc_expiration",
89204 .data = NULL,
89205diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
89206index c03b6a3..8ce3681 100644
89207--- a/net/netfilter/ipvs/ip_vs_lblcr.c
89208+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
89209@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
89210 * IPVS LBLCR sysctl table
89211 */
89212
89213-static ctl_table vs_vars_table[] = {
89214+static ctl_table_no_const vs_vars_table[] __read_only = {
89215 {
89216 .procname = "lblcr_expiration",
89217 .data = NULL,
89218diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
89219index 44fd10c..2a163b3 100644
89220--- a/net/netfilter/ipvs/ip_vs_sync.c
89221+++ b/net/netfilter/ipvs/ip_vs_sync.c
89222@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
89223 cp = cp->control;
89224 if (cp) {
89225 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
89226- pkts = atomic_add_return(1, &cp->in_pkts);
89227+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89228 else
89229 pkts = sysctl_sync_threshold(ipvs);
89230 ip_vs_sync_conn(net, cp->control, pkts);
89231@@ -758,7 +758,7 @@ control:
89232 if (!cp)
89233 return;
89234 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
89235- pkts = atomic_add_return(1, &cp->in_pkts);
89236+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89237 else
89238 pkts = sysctl_sync_threshold(ipvs);
89239 goto sloop;
89240@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
89241
89242 if (opt)
89243 memcpy(&cp->in_seq, opt, sizeof(*opt));
89244- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
89245+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
89246 cp->state = state;
89247 cp->old_state = cp->state;
89248 /*
89249diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
89250index ee6b7a9..f9a89f6 100644
89251--- a/net/netfilter/ipvs/ip_vs_xmit.c
89252+++ b/net/netfilter/ipvs/ip_vs_xmit.c
89253@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
89254 else
89255 rc = NF_ACCEPT;
89256 /* do not touch skb anymore */
89257- atomic_inc(&cp->in_pkts);
89258+ atomic_inc_unchecked(&cp->in_pkts);
89259 goto out;
89260 }
89261
89262@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
89263 else
89264 rc = NF_ACCEPT;
89265 /* do not touch skb anymore */
89266- atomic_inc(&cp->in_pkts);
89267+ atomic_inc_unchecked(&cp->in_pkts);
89268 goto out;
89269 }
89270
89271diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
89272index 2d3030a..7ba1c0a 100644
89273--- a/net/netfilter/nf_conntrack_acct.c
89274+++ b/net/netfilter/nf_conntrack_acct.c
89275@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
89276 #ifdef CONFIG_SYSCTL
89277 static int nf_conntrack_acct_init_sysctl(struct net *net)
89278 {
89279- struct ctl_table *table;
89280+ ctl_table_no_const *table;
89281
89282 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
89283 GFP_KERNEL);
89284diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
89285index c8e001a..f842a8b 100644
89286--- a/net/netfilter/nf_conntrack_core.c
89287+++ b/net/netfilter/nf_conntrack_core.c
89288@@ -1594,6 +1594,10 @@ void nf_conntrack_init_end(void)
89289 #define DYING_NULLS_VAL ((1<<30)+1)
89290 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
89291
89292+#ifdef CONFIG_GRKERNSEC_HIDESYM
89293+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
89294+#endif
89295+
89296 int nf_conntrack_init_net(struct net *net)
89297 {
89298 int ret;
89299@@ -1608,7 +1612,11 @@ int nf_conntrack_init_net(struct net *net)
89300 goto err_stat;
89301 }
89302
89303+#ifdef CONFIG_GRKERNSEC_HIDESYM
89304+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
89305+#else
89306 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
89307+#endif
89308 if (!net->ct.slabname) {
89309 ret = -ENOMEM;
89310 goto err_slabname;
89311diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
89312index b5d2eb8..61ef19a 100644
89313--- a/net/netfilter/nf_conntrack_ecache.c
89314+++ b/net/netfilter/nf_conntrack_ecache.c
89315@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
89316 #ifdef CONFIG_SYSCTL
89317 static int nf_conntrack_event_init_sysctl(struct net *net)
89318 {
89319- struct ctl_table *table;
89320+ ctl_table_no_const *table;
89321
89322 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
89323 GFP_KERNEL);
89324diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
89325index 94b4b98..97cf0ad 100644
89326--- a/net/netfilter/nf_conntrack_helper.c
89327+++ b/net/netfilter/nf_conntrack_helper.c
89328@@ -56,7 +56,7 @@ static struct ctl_table helper_sysctl_table[] = {
89329
89330 static int nf_conntrack_helper_init_sysctl(struct net *net)
89331 {
89332- struct ctl_table *table;
89333+ ctl_table_no_const *table;
89334
89335 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
89336 GFP_KERNEL);
89337diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
89338index 58ab405..50eb8d3 100644
89339--- a/net/netfilter/nf_conntrack_proto.c
89340+++ b/net/netfilter/nf_conntrack_proto.c
89341@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
89342
89343 static void
89344 nf_ct_unregister_sysctl(struct ctl_table_header **header,
89345- struct ctl_table **table,
89346+ ctl_table_no_const **table,
89347 unsigned int users)
89348 {
89349 if (users > 0)
89350diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
89351index ba65b20..2a4d937 100644
89352--- a/net/netfilter/nf_conntrack_proto_dccp.c
89353+++ b/net/netfilter/nf_conntrack_proto_dccp.c
89354@@ -456,7 +456,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
89355
89356 out_invalid:
89357 if (LOG_INVALID(net, IPPROTO_DCCP))
89358- nf_log_packet(nf_ct_l3num(ct), 0, skb, NULL, NULL, NULL, msg);
89359+ nf_log_packet(nf_ct_l3num(ct), 0, skb, NULL, NULL, NULL, "%s", msg);
89360 return false;
89361 }
89362
89363@@ -613,7 +613,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
89364
89365 out_invalid:
89366 if (LOG_INVALID(net, IPPROTO_DCCP))
89367- nf_log_packet(pf, 0, skb, NULL, NULL, NULL, msg);
89368+ nf_log_packet(pf, 0, skb, NULL, NULL, NULL, "%s", msg);
89369 return -NF_ACCEPT;
89370 }
89371
89372diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
89373index fedee39..d62a93d 100644
89374--- a/net/netfilter/nf_conntrack_standalone.c
89375+++ b/net/netfilter/nf_conntrack_standalone.c
89376@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
89377
89378 static int nf_conntrack_standalone_init_sysctl(struct net *net)
89379 {
89380- struct ctl_table *table;
89381+ ctl_table_no_const *table;
89382
89383 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
89384 GFP_KERNEL);
89385diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
89386index 902fb0a..87f7fdb 100644
89387--- a/net/netfilter/nf_conntrack_timestamp.c
89388+++ b/net/netfilter/nf_conntrack_timestamp.c
89389@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
89390 #ifdef CONFIG_SYSCTL
89391 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
89392 {
89393- struct ctl_table *table;
89394+ ctl_table_no_const *table;
89395
89396 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
89397 GFP_KERNEL);
89398diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
89399index 9e31269..bc4c1b7 100644
89400--- a/net/netfilter/nf_log.c
89401+++ b/net/netfilter/nf_log.c
89402@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
89403
89404 #ifdef CONFIG_SYSCTL
89405 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
89406-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
89407+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
89408 static struct ctl_table_header *nf_log_dir_header;
89409
89410 static int nf_log_proc_dostring(ctl_table *table, int write,
89411@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
89412 rcu_assign_pointer(nf_loggers[tindex], logger);
89413 mutex_unlock(&nf_log_mutex);
89414 } else {
89415+ ctl_table_no_const nf_log_table = *table;
89416+
89417 mutex_lock(&nf_log_mutex);
89418 logger = rcu_dereference_protected(nf_loggers[tindex],
89419 lockdep_is_held(&nf_log_mutex));
89420 if (!logger)
89421- table->data = "NONE";
89422+ nf_log_table.data = "NONE";
89423 else
89424- table->data = logger->name;
89425- r = proc_dostring(table, write, buffer, lenp, ppos);
89426+ nf_log_table.data = logger->name;
89427+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
89428 mutex_unlock(&nf_log_mutex);
89429 }
89430
89431diff --git a/net/netfilter/nf_nat_sip.c b/net/netfilter/nf_nat_sip.c
89432index 96ccdf7..dac11f7 100644
89433--- a/net/netfilter/nf_nat_sip.c
89434+++ b/net/netfilter/nf_nat_sip.c
89435@@ -230,9 +230,10 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff,
89436 &ct->tuplehash[!dir].tuple.src.u3,
89437 false);
89438 if (!mangle_packet(skb, protoff, dataoff, dptr, datalen,
89439- poff, plen, buffer, buflen))
89440+ poff, plen, buffer, buflen)) {
89441 nf_ct_helper_log(skb, ct, "cannot mangle received");
89442 return NF_DROP;
89443+ }
89444 }
89445
89446 /* The rport= parameter (RFC 3581) contains the port number
89447diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
89448index f042ae5..30ea486 100644
89449--- a/net/netfilter/nf_sockopt.c
89450+++ b/net/netfilter/nf_sockopt.c
89451@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
89452 }
89453 }
89454
89455- list_add(&reg->list, &nf_sockopts);
89456+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
89457 out:
89458 mutex_unlock(&nf_sockopt_mutex);
89459 return ret;
89460@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
89461 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
89462 {
89463 mutex_lock(&nf_sockopt_mutex);
89464- list_del(&reg->list);
89465+ pax_list_del((struct list_head *)&reg->list);
89466 mutex_unlock(&nf_sockopt_mutex);
89467 }
89468 EXPORT_SYMBOL(nf_unregister_sockopt);
89469diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
89470index f248db5..3778ad9 100644
89471--- a/net/netfilter/nfnetlink_log.c
89472+++ b/net/netfilter/nfnetlink_log.c
89473@@ -72,7 +72,7 @@ struct nfulnl_instance {
89474 };
89475
89476 static DEFINE_SPINLOCK(instances_lock);
89477-static atomic_t global_seq;
89478+static atomic_unchecked_t global_seq;
89479
89480 #define INSTANCE_BUCKETS 16
89481 static struct hlist_head instance_table[INSTANCE_BUCKETS];
89482@@ -536,7 +536,7 @@ __build_packet_message(struct nfulnl_instance *inst,
89483 /* global sequence number */
89484 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
89485 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
89486- htonl(atomic_inc_return(&global_seq))))
89487+ htonl(atomic_inc_return_unchecked(&global_seq))))
89488 goto nla_put_failure;
89489
89490 if (data_len) {
89491diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
89492new file mode 100644
89493index 0000000..c566332
89494--- /dev/null
89495+++ b/net/netfilter/xt_gradm.c
89496@@ -0,0 +1,51 @@
89497+/*
89498+ * gradm match for netfilter
89499