]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.10.1-201307132058.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.10.1-201307132058.patch
CommitLineData
855cb065
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..79768fb 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29+*.vim
30 *.xml
31 *.xz
32 *_MODULES
33+*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38-.*
39+.[^g]*
40+.gen*
41 .*.d
42 .mm
43 53c700_d.h
44@@ -69,9 +75,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52+TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56@@ -80,6 +88,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60+ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64@@ -92,19 +101,24 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68+builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74+clut_vga16.c
75+common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82+config.c
83 config.mak
84 config.mak.autogen
85+config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89@@ -115,9 +129,11 @@ devlist.h*
90 dnotify_test
91 docproc
92 dslm
93+dtc-lexer.lex.c
94 elf2ecoff
95 elfconfig.h*
96 evergreen_reg_safe.h
97+exception_policy.conf
98 fixdep
99 flask.h
100 fore200e_mkfirm
101@@ -125,12 +141,15 @@ fore200e_pca_fw.c*
102 gconf
103 gconf.glade.h
104 gen-devlist
105+gen-kdb_cmds.c
106 gen_crc32table
107 gen_init_cpio
108 generated
109 genheaders
110 genksyms
111 *_gray256.c
112+hash
113+hid-example
114 hpet_example
115 hugepage-mmap
116 hugepage-shm
117@@ -145,14 +164,14 @@ int32.c
118 int4.c
119 int8.c
120 kallsyms
121-kconfig
122+kern_constants.h
123 keywords.c
124 ksym.c*
125 ksym.h*
126 kxgettext
127 lex.c
128 lex.*.c
129-linux
130+lib1funcs.S
131 logo_*.c
132 logo_*_clut224.c
133 logo_*_mono.c
134@@ -162,14 +181,15 @@ mach-types.h
135 machtypes.h
136 map
137 map_hugetlb
138-media
139 mconf
140+mdp
141 miboot*
142 mk_elfconfig
143 mkboot
144 mkbugboot
145 mkcpustr
146 mkdep
147+mkpiggy
148 mkprep
149 mkregtable
150 mktables
151@@ -185,6 +205,8 @@ oui.c*
152 page-types
153 parse.c
154 parse.h
155+parse-events*
156+pasyms.h
157 patches*
158 pca200e.bin
159 pca200e_ecd.bin2
160@@ -194,6 +216,7 @@ perf-archive
161 piggyback
162 piggy.gzip
163 piggy.S
164+pmu-*
165 pnmtologo
166 ppc_defs.h*
167 pss_boot.h
168@@ -203,7 +226,10 @@ r200_reg_safe.h
169 r300_reg_safe.h
170 r420_reg_safe.h
171 r600_reg_safe.h
172+realmode.lds
173+realmode.relocs
174 recordmcount
175+regdb.c
176 relocs
177 rlim_names.h
178 rn50_reg_safe.h
179@@ -213,8 +239,12 @@ series
180 setup
181 setup.bin
182 setup.elf
183+signing_key*
184+size_overflow_hash.h
185 sImage
186+slabinfo
187 sm_tbl*
188+sortextable
189 split-include
190 syscalltab.h
191 tables.c
192@@ -224,6 +254,7 @@ tftpboot.img
193 timeconst.h
194 times.h*
195 trix_boot.h
196+user_constants.h
197 utsrelease.h*
198 vdso-syms.lds
199 vdso.lds
200@@ -235,13 +266,17 @@ vdso32.lds
201 vdso32.so.dbg
202 vdso64.lds
203 vdso64.so.dbg
204+vdsox32.lds
205+vdsox32-syms.lds
206 version.h*
207 vmImage
208 vmlinux
209 vmlinux-*
210 vmlinux.aout
211 vmlinux.bin.all
212+vmlinux.bin.bz2
213 vmlinux.lds
214+vmlinux.relocs
215 vmlinuz
216 voffset.h
217 vsyscall.lds
218@@ -249,9 +284,12 @@ vsyscall_32.lds
219 wanxlfw.inc
220 uImage
221 unifdef
222+utsrelease.h
223 wakeup.bin
224 wakeup.elf
225 wakeup.lds
226+x509*
227 zImage*
228 zconf.hash.c
229+zconf.lex.c
230 zoffset.h
231diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
232index 2fe6e76..3dd8184 100644
233--- a/Documentation/kernel-parameters.txt
234+++ b/Documentation/kernel-parameters.txt
235@@ -976,6 +976,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
236 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
237 Default: 1024
238
239+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
240+ ignore grsecurity's /proc restrictions
241+
242+
243 hashdist= [KNL,NUMA] Large hashes allocated during boot
244 are distributed across NUMA nodes. Defaults on
245 for 64-bit NUMA, off otherwise.
246@@ -2195,6 +2199,18 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
247 the specified number of seconds. This is to be used if
248 your oopses keep scrolling off the screen.
249
250+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
251+ virtualization environments that don't cope well with the
252+ expand down segment used by UDEREF on X86-32 or the frequent
253+ page table updates on X86-64.
254+
255+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
256+
257+ pax_extra_latent_entropy
258+ Enable a very simple form of latent entropy extraction
259+ from the first 4GB of memory as the bootmem allocator
260+ passes the memory pages to the buddy allocator.
261+
262 pcbit= [HW,ISDN]
263
264 pcd. [PARIDE]
265diff --git a/Makefile b/Makefile
266index b75cc30..6abd111 100644
267--- a/Makefile
268+++ b/Makefile
269@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
270
271 HOSTCC = gcc
272 HOSTCXX = g++
273-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
274-HOSTCXXFLAGS = -O2
275+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
276+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
277+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
278
279 # Decide whether to build built-in, modular, or both.
280 # Normally, just do built-in.
281@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
282 # Rules shared between *config targets and build targets
283
284 # Basic helpers built in scripts/
285-PHONY += scripts_basic
286-scripts_basic:
287+PHONY += scripts_basic gcc-plugins
288+scripts_basic: gcc-plugins
289 $(Q)$(MAKE) $(build)=scripts/basic
290 $(Q)rm -f .tmp_quiet_recordmcount
291
292@@ -576,6 +577,65 @@ else
293 KBUILD_CFLAGS += -O2
294 endif
295
296+ifndef DISABLE_PAX_PLUGINS
297+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
298+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
299+else
300+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
301+endif
302+ifneq ($(PLUGINCC),)
303+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
304+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
305+endif
306+ifdef CONFIG_PAX_MEMORY_STACKLEAK
307+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
308+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
309+endif
310+ifdef CONFIG_KALLOCSTAT_PLUGIN
311+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
312+endif
313+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
314+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
315+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
316+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
317+endif
318+ifdef CONFIG_CHECKER_PLUGIN
319+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
320+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
321+endif
322+endif
323+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
324+ifdef CONFIG_PAX_SIZE_OVERFLOW
325+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
326+endif
327+ifdef CONFIG_PAX_LATENT_ENTROPY
328+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
329+endif
330+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
331+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
332+endif
333+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
334+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
335+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
336+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
337+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
338+ifeq ($(KBUILD_EXTMOD),)
339+gcc-plugins:
340+ $(Q)$(MAKE) $(build)=tools/gcc
341+else
342+gcc-plugins: ;
343+endif
344+else
345+gcc-plugins:
346+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
347+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
348+else
349+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
350+endif
351+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
352+endif
353+endif
354+
355 include $(srctree)/arch/$(SRCARCH)/Makefile
356
357 ifdef CONFIG_READABLE_ASM
358@@ -733,7 +793,7 @@ export mod_sign_cmd
359
360
361 ifeq ($(KBUILD_EXTMOD),)
362-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
363+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
364
365 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
366 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
367@@ -782,6 +842,8 @@ endif
368
369 # The actual objects are generated when descending,
370 # make sure no implicit rule kicks in
371+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
372+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
373 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
374
375 # Handle descending into subdirectories listed in $(vmlinux-dirs)
376@@ -791,7 +853,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
377 # Error messages still appears in the original language
378
379 PHONY += $(vmlinux-dirs)
380-$(vmlinux-dirs): prepare scripts
381+$(vmlinux-dirs): gcc-plugins prepare scripts
382 $(Q)$(MAKE) $(build)=$@
383
384 # Store (new) KERNELRELASE string in include/config/kernel.release
385@@ -835,6 +897,7 @@ prepare0: archprepare FORCE
386 $(Q)$(MAKE) $(build)=.
387
388 # All the preparing..
389+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
390 prepare: prepare0
391
392 # Generate some files
393@@ -942,6 +1005,8 @@ all: modules
394 # using awk while concatenating to the final file.
395
396 PHONY += modules
397+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
398+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
399 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
400 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
401 @$(kecho) ' Building modules, stage 2.';
402@@ -957,7 +1022,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
403
404 # Target to prepare building external modules
405 PHONY += modules_prepare
406-modules_prepare: prepare scripts
407+modules_prepare: gcc-plugins prepare scripts
408
409 # Target to install modules
410 PHONY += modules_install
411@@ -1023,7 +1088,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
412 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
413 signing_key.priv signing_key.x509 x509.genkey \
414 extra_certificates signing_key.x509.keyid \
415- signing_key.x509.signer
416+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
417
418 # clean - Delete most, but leave enough to build external modules
419 #
420@@ -1063,6 +1128,7 @@ distclean: mrproper
421 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
422 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
423 -o -name '.*.rej' \
424+ -o -name '.*.rej' -o -name '*.so' \
425 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
426 -type f -print | xargs rm -f
427
428@@ -1223,6 +1289,8 @@ PHONY += $(module-dirs) modules
429 $(module-dirs): crmodverdir $(objtree)/Module.symvers
430 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
431
432+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 modules: $(module-dirs)
435 @$(kecho) ' Building modules, stage 2.';
436 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
437@@ -1359,17 +1427,21 @@ else
438 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
439 endif
440
441-%.s: %.c prepare scripts FORCE
442+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
443+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
444+%.s: %.c gcc-plugins prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 %.i: %.c prepare scripts FORCE
447 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
448-%.o: %.c prepare scripts FORCE
449+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
450+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
451+%.o: %.c gcc-plugins prepare scripts FORCE
452 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
453 %.lst: %.c prepare scripts FORCE
454 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
455-%.s: %.S prepare scripts FORCE
456+%.s: %.S gcc-plugins prepare scripts FORCE
457 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
458-%.o: %.S prepare scripts FORCE
459+%.o: %.S gcc-plugins prepare scripts FORCE
460 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
461 %.symtypes: %.c prepare scripts FORCE
462 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
463@@ -1379,11 +1451,15 @@ endif
464 $(cmd_crmodverdir)
465 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
466 $(build)=$(build-dir)
467-%/: prepare scripts FORCE
468+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
469+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
470+%/: gcc-plugins prepare scripts FORCE
471 $(cmd_crmodverdir)
472 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
473 $(build)=$(build-dir)
474-%.ko: prepare scripts FORCE
475+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
476+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
477+%.ko: gcc-plugins prepare scripts FORCE
478 $(cmd_crmodverdir)
479 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
480 $(build)=$(build-dir) $(@:.ko=.o)
481diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
482index c2cbe4f..f7264b4 100644
483--- a/arch/alpha/include/asm/atomic.h
484+++ b/arch/alpha/include/asm/atomic.h
485@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
486 #define atomic_dec(v) atomic_sub(1,(v))
487 #define atomic64_dec(v) atomic64_sub(1,(v))
488
489+#define atomic64_read_unchecked(v) atomic64_read(v)
490+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
491+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
492+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
493+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
494+#define atomic64_inc_unchecked(v) atomic64_inc(v)
495+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
496+#define atomic64_dec_unchecked(v) atomic64_dec(v)
497+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
498+
499 #define smp_mb__before_atomic_dec() smp_mb()
500 #define smp_mb__after_atomic_dec() smp_mb()
501 #define smp_mb__before_atomic_inc() smp_mb()
502diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
503index ad368a9..fbe0f25 100644
504--- a/arch/alpha/include/asm/cache.h
505+++ b/arch/alpha/include/asm/cache.h
506@@ -4,19 +4,19 @@
507 #ifndef __ARCH_ALPHA_CACHE_H
508 #define __ARCH_ALPHA_CACHE_H
509
510+#include <linux/const.h>
511
512 /* Bytes per L1 (data) cache line. */
513 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
514-# define L1_CACHE_BYTES 64
515 # define L1_CACHE_SHIFT 6
516 #else
517 /* Both EV4 and EV5 are write-through, read-allocate,
518 direct-mapped, physical.
519 */
520-# define L1_CACHE_BYTES 32
521 # define L1_CACHE_SHIFT 5
522 #endif
523
524+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
525 #define SMP_CACHE_BYTES L1_CACHE_BYTES
526
527 #endif
528diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
529index 968d999..d36b2df 100644
530--- a/arch/alpha/include/asm/elf.h
531+++ b/arch/alpha/include/asm/elf.h
532@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
533
534 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
535
536+#ifdef CONFIG_PAX_ASLR
537+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
538+
539+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
540+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
541+#endif
542+
543 /* $0 is set by ld.so to a pointer to a function which might be
544 registered using atexit. This provides a mean for the dynamic
545 linker to call DT_FINI functions for shared libraries that have
546diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
547index bc2a0da..8ad11ee 100644
548--- a/arch/alpha/include/asm/pgalloc.h
549+++ b/arch/alpha/include/asm/pgalloc.h
550@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
551 pgd_set(pgd, pmd);
552 }
553
554+static inline void
555+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
556+{
557+ pgd_populate(mm, pgd, pmd);
558+}
559+
560 extern pgd_t *pgd_alloc(struct mm_struct *mm);
561
562 static inline void
563diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
564index 81a4342..348b927 100644
565--- a/arch/alpha/include/asm/pgtable.h
566+++ b/arch/alpha/include/asm/pgtable.h
567@@ -102,6 +102,17 @@ struct vm_area_struct;
568 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
569 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
570 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
571+
572+#ifdef CONFIG_PAX_PAGEEXEC
573+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
574+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
575+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
576+#else
577+# define PAGE_SHARED_NOEXEC PAGE_SHARED
578+# define PAGE_COPY_NOEXEC PAGE_COPY
579+# define PAGE_READONLY_NOEXEC PAGE_READONLY
580+#endif
581+
582 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
583
584 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
585diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
586index 2fd00b7..cfd5069 100644
587--- a/arch/alpha/kernel/module.c
588+++ b/arch/alpha/kernel/module.c
589@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
590
591 /* The small sections were sorted to the end of the segment.
592 The following should definitely cover them. */
593- gp = (u64)me->module_core + me->core_size - 0x8000;
594+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
595 got = sechdrs[me->arch.gotsecindex].sh_addr;
596
597 for (i = 0; i < n; i++) {
598diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
599index b9e37ad..44c24e7 100644
600--- a/arch/alpha/kernel/osf_sys.c
601+++ b/arch/alpha/kernel/osf_sys.c
602@@ -1297,10 +1297,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
603 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
604
605 static unsigned long
606-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
607- unsigned long limit)
608+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
609+ unsigned long limit, unsigned long flags)
610 {
611 struct vm_unmapped_area_info info;
612+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
613
614 info.flags = 0;
615 info.length = len;
616@@ -1308,6 +1309,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
617 info.high_limit = limit;
618 info.align_mask = 0;
619 info.align_offset = 0;
620+ info.threadstack_offset = offset;
621 return vm_unmapped_area(&info);
622 }
623
624@@ -1340,20 +1342,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
625 merely specific addresses, but regions of memory -- perhaps
626 this feature should be incorporated into all ports? */
627
628+#ifdef CONFIG_PAX_RANDMMAP
629+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
630+#endif
631+
632 if (addr) {
633- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
634+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
635 if (addr != (unsigned long) -ENOMEM)
636 return addr;
637 }
638
639 /* Next, try allocating at TASK_UNMAPPED_BASE. */
640- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
641- len, limit);
642+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
643+
644 if (addr != (unsigned long) -ENOMEM)
645 return addr;
646
647 /* Finally, try allocating in low memory. */
648- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
649+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
650
651 return addr;
652 }
653diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
654index 0c4132d..88f0d53 100644
655--- a/arch/alpha/mm/fault.c
656+++ b/arch/alpha/mm/fault.c
657@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
658 __reload_thread(pcb);
659 }
660
661+#ifdef CONFIG_PAX_PAGEEXEC
662+/*
663+ * PaX: decide what to do with offenders (regs->pc = fault address)
664+ *
665+ * returns 1 when task should be killed
666+ * 2 when patched PLT trampoline was detected
667+ * 3 when unpatched PLT trampoline was detected
668+ */
669+static int pax_handle_fetch_fault(struct pt_regs *regs)
670+{
671+
672+#ifdef CONFIG_PAX_EMUPLT
673+ int err;
674+
675+ do { /* PaX: patched PLT emulation #1 */
676+ unsigned int ldah, ldq, jmp;
677+
678+ err = get_user(ldah, (unsigned int *)regs->pc);
679+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
680+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
681+
682+ if (err)
683+ break;
684+
685+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
686+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
687+ jmp == 0x6BFB0000U)
688+ {
689+ unsigned long r27, addr;
690+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
691+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
692+
693+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
694+ err = get_user(r27, (unsigned long *)addr);
695+ if (err)
696+ break;
697+
698+ regs->r27 = r27;
699+ regs->pc = r27;
700+ return 2;
701+ }
702+ } while (0);
703+
704+ do { /* PaX: patched PLT emulation #2 */
705+ unsigned int ldah, lda, br;
706+
707+ err = get_user(ldah, (unsigned int *)regs->pc);
708+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
709+ err |= get_user(br, (unsigned int *)(regs->pc+8));
710+
711+ if (err)
712+ break;
713+
714+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
715+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
716+ (br & 0xFFE00000U) == 0xC3E00000U)
717+ {
718+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
719+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
720+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
721+
722+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
723+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
724+ return 2;
725+ }
726+ } while (0);
727+
728+ do { /* PaX: unpatched PLT emulation */
729+ unsigned int br;
730+
731+ err = get_user(br, (unsigned int *)regs->pc);
732+
733+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
734+ unsigned int br2, ldq, nop, jmp;
735+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
736+
737+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
738+ err = get_user(br2, (unsigned int *)addr);
739+ err |= get_user(ldq, (unsigned int *)(addr+4));
740+ err |= get_user(nop, (unsigned int *)(addr+8));
741+ err |= get_user(jmp, (unsigned int *)(addr+12));
742+ err |= get_user(resolver, (unsigned long *)(addr+16));
743+
744+ if (err)
745+ break;
746+
747+ if (br2 == 0xC3600000U &&
748+ ldq == 0xA77B000CU &&
749+ nop == 0x47FF041FU &&
750+ jmp == 0x6B7B0000U)
751+ {
752+ regs->r28 = regs->pc+4;
753+ regs->r27 = addr+16;
754+ regs->pc = resolver;
755+ return 3;
756+ }
757+ }
758+ } while (0);
759+#endif
760+
761+ return 1;
762+}
763+
764+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
765+{
766+ unsigned long i;
767+
768+ printk(KERN_ERR "PAX: bytes at PC: ");
769+ for (i = 0; i < 5; i++) {
770+ unsigned int c;
771+ if (get_user(c, (unsigned int *)pc+i))
772+ printk(KERN_CONT "???????? ");
773+ else
774+ printk(KERN_CONT "%08x ", c);
775+ }
776+ printk("\n");
777+}
778+#endif
779
780 /*
781 * This routine handles page faults. It determines the address,
782@@ -133,8 +251,29 @@ retry:
783 good_area:
784 si_code = SEGV_ACCERR;
785 if (cause < 0) {
786- if (!(vma->vm_flags & VM_EXEC))
787+ if (!(vma->vm_flags & VM_EXEC)) {
788+
789+#ifdef CONFIG_PAX_PAGEEXEC
790+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
791+ goto bad_area;
792+
793+ up_read(&mm->mmap_sem);
794+ switch (pax_handle_fetch_fault(regs)) {
795+
796+#ifdef CONFIG_PAX_EMUPLT
797+ case 2:
798+ case 3:
799+ return;
800+#endif
801+
802+ }
803+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
804+ do_group_exit(SIGKILL);
805+#else
806 goto bad_area;
807+#endif
808+
809+ }
810 } else if (!cause) {
811 /* Allow reads even for write-only mappings */
812 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
813diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
814index 136f263..f471277 100644
815--- a/arch/arm/Kconfig
816+++ b/arch/arm/Kconfig
817@@ -1766,7 +1766,7 @@ config ALIGNMENT_TRAP
818
819 config UACCESS_WITH_MEMCPY
820 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
821- depends on MMU
822+ depends on MMU && !PAX_MEMORY_UDEREF
823 default y if CPU_FEROCEON
824 help
825 Implement faster copy_to_user and clear_user methods for CPU
826diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
827index da1c77d..2ee6056 100644
828--- a/arch/arm/include/asm/atomic.h
829+++ b/arch/arm/include/asm/atomic.h
830@@ -17,17 +17,35 @@
831 #include <asm/barrier.h>
832 #include <asm/cmpxchg.h>
833
834+#ifdef CONFIG_GENERIC_ATOMIC64
835+#include <asm-generic/atomic64.h>
836+#endif
837+
838 #define ATOMIC_INIT(i) { (i) }
839
840 #ifdef __KERNEL__
841
842+#define _ASM_EXTABLE(from, to) \
843+" .pushsection __ex_table,\"a\"\n"\
844+" .align 3\n" \
845+" .long " #from ", " #to"\n" \
846+" .popsection"
847+
848 /*
849 * On ARM, ordinary assignment (str instruction) doesn't clear the local
850 * strex/ldrex monitor on some implementations. The reason we can use it for
851 * atomic_set() is the clrex or dummy strex done on every exception return.
852 */
853 #define atomic_read(v) (*(volatile int *)&(v)->counter)
854+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
855+{
856+ return v->counter;
857+}
858 #define atomic_set(v,i) (((v)->counter) = (i))
859+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
860+{
861+ v->counter = i;
862+}
863
864 #if __LINUX_ARM_ARCH__ >= 6
865
866@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
867 int result;
868
869 __asm__ __volatile__("@ atomic_add\n"
870+"1: ldrex %1, [%3]\n"
871+" adds %0, %1, %4\n"
872+
873+#ifdef CONFIG_PAX_REFCOUNT
874+" bvc 3f\n"
875+"2: bkpt 0xf103\n"
876+"3:\n"
877+#endif
878+
879+" strex %1, %0, [%3]\n"
880+" teq %1, #0\n"
881+" bne 1b"
882+
883+#ifdef CONFIG_PAX_REFCOUNT
884+"\n4:\n"
885+ _ASM_EXTABLE(2b, 4b)
886+#endif
887+
888+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
889+ : "r" (&v->counter), "Ir" (i)
890+ : "cc");
891+}
892+
893+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
894+{
895+ unsigned long tmp;
896+ int result;
897+
898+ __asm__ __volatile__("@ atomic_add_unchecked\n"
899 "1: ldrex %0, [%3]\n"
900 " add %0, %0, %4\n"
901 " strex %1, %0, [%3]\n"
902@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
903 smp_mb();
904
905 __asm__ __volatile__("@ atomic_add_return\n"
906+"1: ldrex %1, [%3]\n"
907+" adds %0, %1, %4\n"
908+
909+#ifdef CONFIG_PAX_REFCOUNT
910+" bvc 3f\n"
911+" mov %0, %1\n"
912+"2: bkpt 0xf103\n"
913+"3:\n"
914+#endif
915+
916+" strex %1, %0, [%3]\n"
917+" teq %1, #0\n"
918+" bne 1b"
919+
920+#ifdef CONFIG_PAX_REFCOUNT
921+"\n4:\n"
922+ _ASM_EXTABLE(2b, 4b)
923+#endif
924+
925+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
926+ : "r" (&v->counter), "Ir" (i)
927+ : "cc");
928+
929+ smp_mb();
930+
931+ return result;
932+}
933+
934+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
935+{
936+ unsigned long tmp;
937+ int result;
938+
939+ smp_mb();
940+
941+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
942 "1: ldrex %0, [%3]\n"
943 " add %0, %0, %4\n"
944 " strex %1, %0, [%3]\n"
945@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
946 int result;
947
948 __asm__ __volatile__("@ atomic_sub\n"
949+"1: ldrex %1, [%3]\n"
950+" subs %0, %1, %4\n"
951+
952+#ifdef CONFIG_PAX_REFCOUNT
953+" bvc 3f\n"
954+"2: bkpt 0xf103\n"
955+"3:\n"
956+#endif
957+
958+" strex %1, %0, [%3]\n"
959+" teq %1, #0\n"
960+" bne 1b"
961+
962+#ifdef CONFIG_PAX_REFCOUNT
963+"\n4:\n"
964+ _ASM_EXTABLE(2b, 4b)
965+#endif
966+
967+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
968+ : "r" (&v->counter), "Ir" (i)
969+ : "cc");
970+}
971+
972+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
973+{
974+ unsigned long tmp;
975+ int result;
976+
977+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
978 "1: ldrex %0, [%3]\n"
979 " sub %0, %0, %4\n"
980 " strex %1, %0, [%3]\n"
981@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
982 smp_mb();
983
984 __asm__ __volatile__("@ atomic_sub_return\n"
985-"1: ldrex %0, [%3]\n"
986-" sub %0, %0, %4\n"
987+"1: ldrex %1, [%3]\n"
988+" subs %0, %1, %4\n"
989+
990+#ifdef CONFIG_PAX_REFCOUNT
991+" bvc 3f\n"
992+" mov %0, %1\n"
993+"2: bkpt 0xf103\n"
994+"3:\n"
995+#endif
996+
997 " strex %1, %0, [%3]\n"
998 " teq %1, #0\n"
999 " bne 1b"
1000+
1001+#ifdef CONFIG_PAX_REFCOUNT
1002+"\n4:\n"
1003+ _ASM_EXTABLE(2b, 4b)
1004+#endif
1005+
1006 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1007 : "r" (&v->counter), "Ir" (i)
1008 : "cc");
1009@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1010 return oldval;
1011 }
1012
1013+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1014+{
1015+ unsigned long oldval, res;
1016+
1017+ smp_mb();
1018+
1019+ do {
1020+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1021+ "ldrex %1, [%3]\n"
1022+ "mov %0, #0\n"
1023+ "teq %1, %4\n"
1024+ "strexeq %0, %5, [%3]\n"
1025+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1026+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1027+ : "cc");
1028+ } while (res);
1029+
1030+ smp_mb();
1031+
1032+ return oldval;
1033+}
1034+
1035 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1036 {
1037 unsigned long tmp, tmp2;
1038@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1039
1040 return val;
1041 }
1042+
1043+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1044+{
1045+ return atomic_add_return(i, v);
1046+}
1047+
1048 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1049+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1050+{
1051+ (void) atomic_add_return(i, v);
1052+}
1053
1054 static inline int atomic_sub_return(int i, atomic_t *v)
1055 {
1056@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1057 return val;
1058 }
1059 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1060+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1061+{
1062+ (void) atomic_sub_return(i, v);
1063+}
1064
1065 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1066 {
1067@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1068 return ret;
1069 }
1070
1071+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1072+{
1073+ return atomic_cmpxchg(v, old, new);
1074+}
1075+
1076 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1077 {
1078 unsigned long flags;
1079@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1080 #endif /* __LINUX_ARM_ARCH__ */
1081
1082 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1083+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1084+{
1085+ return xchg(&v->counter, new);
1086+}
1087
1088 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1089 {
1090@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1091 }
1092
1093 #define atomic_inc(v) atomic_add(1, v)
1094+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1095+{
1096+ atomic_add_unchecked(1, v);
1097+}
1098 #define atomic_dec(v) atomic_sub(1, v)
1099+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1100+{
1101+ atomic_sub_unchecked(1, v);
1102+}
1103
1104 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1105+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1106+{
1107+ return atomic_add_return_unchecked(1, v) == 0;
1108+}
1109 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1110 #define atomic_inc_return(v) (atomic_add_return(1, v))
1111+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1112+{
1113+ return atomic_add_return_unchecked(1, v);
1114+}
1115 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1116 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1117
1118@@ -241,6 +428,14 @@ typedef struct {
1119 u64 __aligned(8) counter;
1120 } atomic64_t;
1121
1122+#ifdef CONFIG_PAX_REFCOUNT
1123+typedef struct {
1124+ u64 __aligned(8) counter;
1125+} atomic64_unchecked_t;
1126+#else
1127+typedef atomic64_t atomic64_unchecked_t;
1128+#endif
1129+
1130 #define ATOMIC64_INIT(i) { (i) }
1131
1132 #ifdef CONFIG_ARM_LPAE
1133@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1134 return result;
1135 }
1136
1137+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1138+{
1139+ u64 result;
1140+
1141+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1142+" ldrd %0, %H0, [%1]"
1143+ : "=&r" (result)
1144+ : "r" (&v->counter), "Qo" (v->counter)
1145+ );
1146+
1147+ return result;
1148+}
1149+
1150 static inline void atomic64_set(atomic64_t *v, u64 i)
1151 {
1152 __asm__ __volatile__("@ atomic64_set\n"
1153@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1154 : "r" (&v->counter), "r" (i)
1155 );
1156 }
1157+
1158+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1159+{
1160+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1161+" strd %2, %H2, [%1]"
1162+ : "=Qo" (v->counter)
1163+ : "r" (&v->counter), "r" (i)
1164+ );
1165+}
1166 #else
1167 static inline u64 atomic64_read(const atomic64_t *v)
1168 {
1169@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1170 return result;
1171 }
1172
1173+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1174+{
1175+ u64 result;
1176+
1177+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1178+" ldrexd %0, %H0, [%1]"
1179+ : "=&r" (result)
1180+ : "r" (&v->counter), "Qo" (v->counter)
1181+ );
1182+
1183+ return result;
1184+}
1185+
1186 static inline void atomic64_set(atomic64_t *v, u64 i)
1187 {
1188 u64 tmp;
1189@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1190 : "r" (&v->counter), "r" (i)
1191 : "cc");
1192 }
1193+
1194+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1195+{
1196+ u64 tmp;
1197+
1198+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1199+"1: ldrexd %0, %H0, [%2]\n"
1200+" strexd %0, %3, %H3, [%2]\n"
1201+" teq %0, #0\n"
1202+" bne 1b"
1203+ : "=&r" (tmp), "=Qo" (v->counter)
1204+ : "r" (&v->counter), "r" (i)
1205+ : "cc");
1206+}
1207+
1208 #endif
1209
1210 static inline void atomic64_add(u64 i, atomic64_t *v)
1211@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1212 __asm__ __volatile__("@ atomic64_add\n"
1213 "1: ldrexd %0, %H0, [%3]\n"
1214 " adds %0, %0, %4\n"
1215+" adcs %H0, %H0, %H4\n"
1216+
1217+#ifdef CONFIG_PAX_REFCOUNT
1218+" bvc 3f\n"
1219+"2: bkpt 0xf103\n"
1220+"3:\n"
1221+#endif
1222+
1223+" strexd %1, %0, %H0, [%3]\n"
1224+" teq %1, #0\n"
1225+" bne 1b"
1226+
1227+#ifdef CONFIG_PAX_REFCOUNT
1228+"\n4:\n"
1229+ _ASM_EXTABLE(2b, 4b)
1230+#endif
1231+
1232+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1233+ : "r" (&v->counter), "r" (i)
1234+ : "cc");
1235+}
1236+
1237+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1238+{
1239+ u64 result;
1240+ unsigned long tmp;
1241+
1242+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1243+"1: ldrexd %0, %H0, [%3]\n"
1244+" adds %0, %0, %4\n"
1245 " adc %H0, %H0, %H4\n"
1246 " strexd %1, %0, %H0, [%3]\n"
1247 " teq %1, #0\n"
1248@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1249
1250 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1251 {
1252- u64 result;
1253- unsigned long tmp;
1254+ u64 result, tmp;
1255
1256 smp_mb();
1257
1258 __asm__ __volatile__("@ atomic64_add_return\n"
1259+"1: ldrexd %1, %H1, [%3]\n"
1260+" adds %0, %1, %4\n"
1261+" adcs %H0, %H1, %H4\n"
1262+
1263+#ifdef CONFIG_PAX_REFCOUNT
1264+" bvc 3f\n"
1265+" mov %0, %1\n"
1266+" mov %H0, %H1\n"
1267+"2: bkpt 0xf103\n"
1268+"3:\n"
1269+#endif
1270+
1271+" strexd %1, %0, %H0, [%3]\n"
1272+" teq %1, #0\n"
1273+" bne 1b"
1274+
1275+#ifdef CONFIG_PAX_REFCOUNT
1276+"\n4:\n"
1277+ _ASM_EXTABLE(2b, 4b)
1278+#endif
1279+
1280+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1281+ : "r" (&v->counter), "r" (i)
1282+ : "cc");
1283+
1284+ smp_mb();
1285+
1286+ return result;
1287+}
1288+
1289+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1290+{
1291+ u64 result;
1292+ unsigned long tmp;
1293+
1294+ smp_mb();
1295+
1296+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1297 "1: ldrexd %0, %H0, [%3]\n"
1298 " adds %0, %0, %4\n"
1299 " adc %H0, %H0, %H4\n"
1300@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1301 __asm__ __volatile__("@ atomic64_sub\n"
1302 "1: ldrexd %0, %H0, [%3]\n"
1303 " subs %0, %0, %4\n"
1304+" sbcs %H0, %H0, %H4\n"
1305+
1306+#ifdef CONFIG_PAX_REFCOUNT
1307+" bvc 3f\n"
1308+"2: bkpt 0xf103\n"
1309+"3:\n"
1310+#endif
1311+
1312+" strexd %1, %0, %H0, [%3]\n"
1313+" teq %1, #0\n"
1314+" bne 1b"
1315+
1316+#ifdef CONFIG_PAX_REFCOUNT
1317+"\n4:\n"
1318+ _ASM_EXTABLE(2b, 4b)
1319+#endif
1320+
1321+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1322+ : "r" (&v->counter), "r" (i)
1323+ : "cc");
1324+}
1325+
1326+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1327+{
1328+ u64 result;
1329+ unsigned long tmp;
1330+
1331+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1332+"1: ldrexd %0, %H0, [%3]\n"
1333+" subs %0, %0, %4\n"
1334 " sbc %H0, %H0, %H4\n"
1335 " strexd %1, %0, %H0, [%3]\n"
1336 " teq %1, #0\n"
1337@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1338
1339 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1340 {
1341- u64 result;
1342- unsigned long tmp;
1343+ u64 result, tmp;
1344
1345 smp_mb();
1346
1347 __asm__ __volatile__("@ atomic64_sub_return\n"
1348-"1: ldrexd %0, %H0, [%3]\n"
1349-" subs %0, %0, %4\n"
1350-" sbc %H0, %H0, %H4\n"
1351+"1: ldrexd %1, %H1, [%3]\n"
1352+" subs %0, %1, %4\n"
1353+" sbcs %H0, %H1, %H4\n"
1354+
1355+#ifdef CONFIG_PAX_REFCOUNT
1356+" bvc 3f\n"
1357+" mov %0, %1\n"
1358+" mov %H0, %H1\n"
1359+"2: bkpt 0xf103\n"
1360+"3:\n"
1361+#endif
1362+
1363 " strexd %1, %0, %H0, [%3]\n"
1364 " teq %1, #0\n"
1365 " bne 1b"
1366+
1367+#ifdef CONFIG_PAX_REFCOUNT
1368+"\n4:\n"
1369+ _ASM_EXTABLE(2b, 4b)
1370+#endif
1371+
1372 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1373 : "r" (&v->counter), "r" (i)
1374 : "cc");
1375@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1376 return oldval;
1377 }
1378
1379+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1380+{
1381+ u64 oldval;
1382+ unsigned long res;
1383+
1384+ smp_mb();
1385+
1386+ do {
1387+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1388+ "ldrexd %1, %H1, [%3]\n"
1389+ "mov %0, #0\n"
1390+ "teq %1, %4\n"
1391+ "teqeq %H1, %H4\n"
1392+ "strexdeq %0, %5, %H5, [%3]"
1393+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1394+ : "r" (&ptr->counter), "r" (old), "r" (new)
1395+ : "cc");
1396+ } while (res);
1397+
1398+ smp_mb();
1399+
1400+ return oldval;
1401+}
1402+
1403 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1404 {
1405 u64 result;
1406@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1407
1408 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1409 {
1410- u64 result;
1411- unsigned long tmp;
1412+ u64 result, tmp;
1413
1414 smp_mb();
1415
1416 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1417-"1: ldrexd %0, %H0, [%3]\n"
1418-" subs %0, %0, #1\n"
1419-" sbc %H0, %H0, #0\n"
1420+"1: ldrexd %1, %H1, [%3]\n"
1421+" subs %0, %1, #1\n"
1422+" sbcs %H0, %H1, #0\n"
1423+
1424+#ifdef CONFIG_PAX_REFCOUNT
1425+" bvc 3f\n"
1426+" mov %0, %1\n"
1427+" mov %H0, %H1\n"
1428+"2: bkpt 0xf103\n"
1429+"3:\n"
1430+#endif
1431+
1432 " teq %H0, #0\n"
1433-" bmi 2f\n"
1434+" bmi 4f\n"
1435 " strexd %1, %0, %H0, [%3]\n"
1436 " teq %1, #0\n"
1437 " bne 1b\n"
1438-"2:"
1439+"4:\n"
1440+
1441+#ifdef CONFIG_PAX_REFCOUNT
1442+ _ASM_EXTABLE(2b, 4b)
1443+#endif
1444+
1445 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1446 : "r" (&v->counter)
1447 : "cc");
1448@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1449 " teq %0, %5\n"
1450 " teqeq %H0, %H5\n"
1451 " moveq %1, #0\n"
1452-" beq 2f\n"
1453+" beq 4f\n"
1454 " adds %0, %0, %6\n"
1455-" adc %H0, %H0, %H6\n"
1456+" adcs %H0, %H0, %H6\n"
1457+
1458+#ifdef CONFIG_PAX_REFCOUNT
1459+" bvc 3f\n"
1460+"2: bkpt 0xf103\n"
1461+"3:\n"
1462+#endif
1463+
1464 " strexd %2, %0, %H0, [%4]\n"
1465 " teq %2, #0\n"
1466 " bne 1b\n"
1467-"2:"
1468+"4:\n"
1469+
1470+#ifdef CONFIG_PAX_REFCOUNT
1471+ _ASM_EXTABLE(2b, 4b)
1472+#endif
1473+
1474 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1475 : "r" (&v->counter), "r" (u), "r" (a)
1476 : "cc");
1477@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1478
1479 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1480 #define atomic64_inc(v) atomic64_add(1LL, (v))
1481+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1482 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1483+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1484 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1485 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1486 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1487+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1488 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1489 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1490 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1491diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1492index 75fe66b..ba3dee4 100644
1493--- a/arch/arm/include/asm/cache.h
1494+++ b/arch/arm/include/asm/cache.h
1495@@ -4,8 +4,10 @@
1496 #ifndef __ASMARM_CACHE_H
1497 #define __ASMARM_CACHE_H
1498
1499+#include <linux/const.h>
1500+
1501 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1502-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1503+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1504
1505 /*
1506 * Memory returned by kmalloc() may be used for DMA, so we must make
1507@@ -24,5 +26,6 @@
1508 #endif
1509
1510 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1511+#define __read_only __attribute__ ((__section__(".data..read_only")))
1512
1513 #endif
1514diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1515index 17d0ae8..014e350 100644
1516--- a/arch/arm/include/asm/cacheflush.h
1517+++ b/arch/arm/include/asm/cacheflush.h
1518@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1519 void (*dma_unmap_area)(const void *, size_t, int);
1520
1521 void (*dma_flush_range)(const void *, const void *);
1522-};
1523+} __no_const;
1524
1525 /*
1526 * Select the calling method
1527diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1528index 6dcc164..b14d917 100644
1529--- a/arch/arm/include/asm/checksum.h
1530+++ b/arch/arm/include/asm/checksum.h
1531@@ -37,7 +37,19 @@ __wsum
1532 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1533
1534 __wsum
1535-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1536+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1537+
1538+static inline __wsum
1539+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1540+{
1541+ __wsum ret;
1542+ pax_open_userland();
1543+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1544+ pax_close_userland();
1545+ return ret;
1546+}
1547+
1548+
1549
1550 /*
1551 * Fold a partial checksum without adding pseudo headers
1552diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1553index 4f009c1..466c59b 100644
1554--- a/arch/arm/include/asm/cmpxchg.h
1555+++ b/arch/arm/include/asm/cmpxchg.h
1556@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1557
1558 #define xchg(ptr,x) \
1559 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1560+#define xchg_unchecked(ptr,x) \
1561+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1562
1563 #include <asm-generic/cmpxchg-local.h>
1564
1565diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1566index 6ddbe44..b5e38b1 100644
1567--- a/arch/arm/include/asm/domain.h
1568+++ b/arch/arm/include/asm/domain.h
1569@@ -48,18 +48,37 @@
1570 * Domain types
1571 */
1572 #define DOMAIN_NOACCESS 0
1573-#define DOMAIN_CLIENT 1
1574 #ifdef CONFIG_CPU_USE_DOMAINS
1575+#define DOMAIN_USERCLIENT 1
1576+#define DOMAIN_KERNELCLIENT 1
1577 #define DOMAIN_MANAGER 3
1578+#define DOMAIN_VECTORS DOMAIN_USER
1579 #else
1580+
1581+#ifdef CONFIG_PAX_KERNEXEC
1582 #define DOMAIN_MANAGER 1
1583+#define DOMAIN_KERNEXEC 3
1584+#else
1585+#define DOMAIN_MANAGER 1
1586+#endif
1587+
1588+#ifdef CONFIG_PAX_MEMORY_UDEREF
1589+#define DOMAIN_USERCLIENT 0
1590+#define DOMAIN_UDEREF 1
1591+#define DOMAIN_VECTORS DOMAIN_KERNEL
1592+#else
1593+#define DOMAIN_USERCLIENT 1
1594+#define DOMAIN_VECTORS DOMAIN_USER
1595+#endif
1596+#define DOMAIN_KERNELCLIENT 1
1597+
1598 #endif
1599
1600 #define domain_val(dom,type) ((type) << (2*(dom)))
1601
1602 #ifndef __ASSEMBLY__
1603
1604-#ifdef CONFIG_CPU_USE_DOMAINS
1605+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1606 static inline void set_domain(unsigned val)
1607 {
1608 asm volatile(
1609@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1610 isb();
1611 }
1612
1613-#define modify_domain(dom,type) \
1614- do { \
1615- struct thread_info *thread = current_thread_info(); \
1616- unsigned int domain = thread->cpu_domain; \
1617- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1618- thread->cpu_domain = domain | domain_val(dom, type); \
1619- set_domain(thread->cpu_domain); \
1620- } while (0)
1621-
1622+extern void modify_domain(unsigned int dom, unsigned int type);
1623 #else
1624 static inline void set_domain(unsigned val) { }
1625 static inline void modify_domain(unsigned dom, unsigned type) { }
1626diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1627index 38050b1..9d90e8b 100644
1628--- a/arch/arm/include/asm/elf.h
1629+++ b/arch/arm/include/asm/elf.h
1630@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1631 the loader. We need to make sure that it is out of the way of the program
1632 that it will "exec", and that there is sufficient room for the brk. */
1633
1634-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1635+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1636+
1637+#ifdef CONFIG_PAX_ASLR
1638+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1639+
1640+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1641+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1642+#endif
1643
1644 /* When the program starts, a1 contains a pointer to a function to be
1645 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1646@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1647 extern void elf_set_personality(const struct elf32_hdr *);
1648 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1649
1650-struct mm_struct;
1651-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1652-#define arch_randomize_brk arch_randomize_brk
1653-
1654 #endif
1655diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1656index de53547..52b9a28 100644
1657--- a/arch/arm/include/asm/fncpy.h
1658+++ b/arch/arm/include/asm/fncpy.h
1659@@ -81,7 +81,9 @@
1660 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1661 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1662 \
1663+ pax_open_kernel(); \
1664 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1665+ pax_close_kernel(); \
1666 flush_icache_range((unsigned long)(dest_buf), \
1667 (unsigned long)(dest_buf) + (size)); \
1668 \
1669diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1670index e42cf59..7b94b8f 100644
1671--- a/arch/arm/include/asm/futex.h
1672+++ b/arch/arm/include/asm/futex.h
1673@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1674 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1675 return -EFAULT;
1676
1677+ pax_open_userland();
1678+
1679 smp_mb();
1680 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1681 "1: ldrex %1, [%4]\n"
1682@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1683 : "cc", "memory");
1684 smp_mb();
1685
1686+ pax_close_userland();
1687+
1688 *uval = val;
1689 return ret;
1690 }
1691@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1692 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1693 return -EFAULT;
1694
1695+ pax_open_userland();
1696+
1697 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1698 "1: " TUSER(ldr) " %1, [%4]\n"
1699 " teq %1, %2\n"
1700@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1701 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1702 : "cc", "memory");
1703
1704+ pax_close_userland();
1705+
1706 *uval = val;
1707 return ret;
1708 }
1709@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1710 return -EFAULT;
1711
1712 pagefault_disable(); /* implies preempt_disable() */
1713+ pax_open_userland();
1714
1715 switch (op) {
1716 case FUTEX_OP_SET:
1717@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1718 ret = -ENOSYS;
1719 }
1720
1721+ pax_close_userland();
1722 pagefault_enable(); /* subsumes preempt_enable() */
1723
1724 if (!ret) {
1725diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1726index 83eb2f7..ed77159 100644
1727--- a/arch/arm/include/asm/kmap_types.h
1728+++ b/arch/arm/include/asm/kmap_types.h
1729@@ -4,6 +4,6 @@
1730 /*
1731 * This is the "bare minimum". AIO seems to require this.
1732 */
1733-#define KM_TYPE_NR 16
1734+#define KM_TYPE_NR 17
1735
1736 #endif
1737diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1738index 9e614a1..3302cca 100644
1739--- a/arch/arm/include/asm/mach/dma.h
1740+++ b/arch/arm/include/asm/mach/dma.h
1741@@ -22,7 +22,7 @@ struct dma_ops {
1742 int (*residue)(unsigned int, dma_t *); /* optional */
1743 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1744 const char *type;
1745-};
1746+} __do_const;
1747
1748 struct dma_struct {
1749 void *addr; /* single DMA address */
1750diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1751index 2fe141f..192dc01 100644
1752--- a/arch/arm/include/asm/mach/map.h
1753+++ b/arch/arm/include/asm/mach/map.h
1754@@ -27,13 +27,16 @@ struct map_desc {
1755 #define MT_MINICLEAN 6
1756 #define MT_LOW_VECTORS 7
1757 #define MT_HIGH_VECTORS 8
1758-#define MT_MEMORY 9
1759+#define MT_MEMORY_RWX 9
1760 #define MT_ROM 10
1761-#define MT_MEMORY_NONCACHED 11
1762+#define MT_MEMORY_NONCACHED_RX 11
1763 #define MT_MEMORY_DTCM 12
1764 #define MT_MEMORY_ITCM 13
1765 #define MT_MEMORY_SO 14
1766 #define MT_MEMORY_DMA_READY 15
1767+#define MT_MEMORY_RW 16
1768+#define MT_MEMORY_RX 17
1769+#define MT_MEMORY_NONCACHED_RW 18
1770
1771 #ifdef CONFIG_MMU
1772 extern void iotable_init(struct map_desc *, int);
1773diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1774index 12f71a1..04e063c 100644
1775--- a/arch/arm/include/asm/outercache.h
1776+++ b/arch/arm/include/asm/outercache.h
1777@@ -35,7 +35,7 @@ struct outer_cache_fns {
1778 #endif
1779 void (*set_debug)(unsigned long);
1780 void (*resume)(void);
1781-};
1782+} __no_const;
1783
1784 #ifdef CONFIG_OUTER_CACHE
1785
1786diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1787index 812a494..71fc0b6 100644
1788--- a/arch/arm/include/asm/page.h
1789+++ b/arch/arm/include/asm/page.h
1790@@ -114,7 +114,7 @@ struct cpu_user_fns {
1791 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1792 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1793 unsigned long vaddr, struct vm_area_struct *vma);
1794-};
1795+} __no_const;
1796
1797 #ifdef MULTI_USER
1798 extern struct cpu_user_fns cpu_user;
1799diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1800index 943504f..c37a730 100644
1801--- a/arch/arm/include/asm/pgalloc.h
1802+++ b/arch/arm/include/asm/pgalloc.h
1803@@ -17,6 +17,7 @@
1804 #include <asm/processor.h>
1805 #include <asm/cacheflush.h>
1806 #include <asm/tlbflush.h>
1807+#include <asm/system_info.h>
1808
1809 #define check_pgt_cache() do { } while (0)
1810
1811@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1812 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1813 }
1814
1815+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1816+{
1817+ pud_populate(mm, pud, pmd);
1818+}
1819+
1820 #else /* !CONFIG_ARM_LPAE */
1821
1822 /*
1823@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1824 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1825 #define pmd_free(mm, pmd) do { } while (0)
1826 #define pud_populate(mm,pmd,pte) BUG()
1827+#define pud_populate_kernel(mm,pmd,pte) BUG()
1828
1829 #endif /* CONFIG_ARM_LPAE */
1830
1831@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1832 __free_page(pte);
1833 }
1834
1835+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1836+{
1837+#ifdef CONFIG_ARM_LPAE
1838+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1839+#else
1840+ if (addr & SECTION_SIZE)
1841+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1842+ else
1843+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1844+#endif
1845+ flush_pmd_entry(pmdp);
1846+}
1847+
1848 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1849 pmdval_t prot)
1850 {
1851@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1852 static inline void
1853 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1854 {
1855- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1856+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1857 }
1858 #define pmd_pgtable(pmd) pmd_page(pmd)
1859
1860diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1861index 5cfba15..f415e1a 100644
1862--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1863+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1864@@ -20,12 +20,15 @@
1865 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1866 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1867 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1868+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1869 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1870 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1871 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1872+
1873 /*
1874 * - section
1875 */
1876+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1877 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1878 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1879 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1880@@ -37,6 +40,7 @@
1881 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1882 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1883 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1884+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1885
1886 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1887 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1888@@ -66,6 +70,7 @@
1889 * - extended small page/tiny page
1890 */
1891 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1892+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1893 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1894 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1895 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1896diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1897index f97ee02..07f1be5 100644
1898--- a/arch/arm/include/asm/pgtable-2level.h
1899+++ b/arch/arm/include/asm/pgtable-2level.h
1900@@ -125,6 +125,7 @@
1901 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1902 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1903 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1904+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1905
1906 /*
1907 * These are the memory types, defined to be compatible with
1908diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1909index 18f5cef..25b8f43 100644
1910--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1911+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1912@@ -41,6 +41,7 @@
1913 */
1914 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1915 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1916+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1917 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1918 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1919 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1920@@ -71,6 +72,7 @@
1921 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1922 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1923 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1924+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1925 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1926
1927 /*
1928diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1929index 86b8fe3..e25f975 100644
1930--- a/arch/arm/include/asm/pgtable-3level.h
1931+++ b/arch/arm/include/asm/pgtable-3level.h
1932@@ -74,6 +74,7 @@
1933 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1934 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1935 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1936+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1937 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1938 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1939 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1940@@ -82,6 +83,7 @@
1941 /*
1942 * To be used in assembly code with the upper page attributes.
1943 */
1944+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1945 #define L_PTE_XN_HIGH (1 << (54 - 32))
1946 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1947
1948diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1949index 9bcd262..fba731c 100644
1950--- a/arch/arm/include/asm/pgtable.h
1951+++ b/arch/arm/include/asm/pgtable.h
1952@@ -30,6 +30,9 @@
1953 #include <asm/pgtable-2level.h>
1954 #endif
1955
1956+#define ktla_ktva(addr) (addr)
1957+#define ktva_ktla(addr) (addr)
1958+
1959 /*
1960 * Just any arbitrary offset to the start of the vmalloc VM area: the
1961 * current 8MB value just means that there will be a 8MB "hole" after the
1962@@ -45,6 +48,9 @@
1963 #define LIBRARY_TEXT_START 0x0c000000
1964
1965 #ifndef __ASSEMBLY__
1966+extern pteval_t __supported_pte_mask;
1967+extern pmdval_t __supported_pmd_mask;
1968+
1969 extern void __pte_error(const char *file, int line, pte_t);
1970 extern void __pmd_error(const char *file, int line, pmd_t);
1971 extern void __pgd_error(const char *file, int line, pgd_t);
1972@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1973 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1974 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1975
1976+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1977+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1978+
1979+#ifdef CONFIG_PAX_KERNEXEC
1980+#include <asm/domain.h>
1981+#include <linux/thread_info.h>
1982+#include <linux/preempt.h>
1983+#endif
1984+
1985+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1986+static inline int test_domain(int domain, int domaintype)
1987+{
1988+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
1989+}
1990+#endif
1991+
1992+#ifdef CONFIG_PAX_KERNEXEC
1993+static inline unsigned long pax_open_kernel(void) {
1994+#ifdef CONFIG_ARM_LPAE
1995+ /* TODO */
1996+#else
1997+ preempt_disable();
1998+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
1999+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2000+#endif
2001+ return 0;
2002+}
2003+
2004+static inline unsigned long pax_close_kernel(void) {
2005+#ifdef CONFIG_ARM_LPAE
2006+ /* TODO */
2007+#else
2008+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2009+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2010+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2011+ preempt_enable_no_resched();
2012+#endif
2013+ return 0;
2014+}
2015+#else
2016+static inline unsigned long pax_open_kernel(void) { return 0; }
2017+static inline unsigned long pax_close_kernel(void) { return 0; }
2018+#endif
2019+
2020 /*
2021 * This is the lowest virtual address we can permit any user space
2022 * mapping to be mapped at. This is particularly important for
2023@@ -72,8 +122,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2024 /*
2025 * The pgprot_* and protection_map entries will be fixed up in runtime
2026 * to include the cachable and bufferable bits based on memory policy,
2027- * as well as any architecture dependent bits like global/ASID and SMP
2028- * shared mapping bits.
2029+ * as well as any architecture dependent bits like global/ASID, PXN,
2030+ * and SMP shared mapping bits.
2031 */
2032 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2033
2034@@ -257,7 +307,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2035 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2036 {
2037 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2038- L_PTE_NONE | L_PTE_VALID;
2039+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2040 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2041 return pte;
2042 }
2043diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2044index f3628fb..a0672dd 100644
2045--- a/arch/arm/include/asm/proc-fns.h
2046+++ b/arch/arm/include/asm/proc-fns.h
2047@@ -75,7 +75,7 @@ extern struct processor {
2048 unsigned int suspend_size;
2049 void (*do_suspend)(void *);
2050 void (*do_resume)(void *);
2051-} processor;
2052+} __do_const processor;
2053
2054 #ifndef MULTI_CPU
2055 extern void cpu_proc_init(void);
2056diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2057index 06e7d50..8a8e251 100644
2058--- a/arch/arm/include/asm/processor.h
2059+++ b/arch/arm/include/asm/processor.h
2060@@ -65,9 +65,8 @@ struct thread_struct {
2061 regs->ARM_cpsr |= PSR_ENDSTATE; \
2062 regs->ARM_pc = pc & ~1; /* pc */ \
2063 regs->ARM_sp = sp; /* sp */ \
2064- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2065- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2066- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2067+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2068+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2069 nommu_start_thread(regs); \
2070 })
2071
2072diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2073index ce0dbe7..c085b6f 100644
2074--- a/arch/arm/include/asm/psci.h
2075+++ b/arch/arm/include/asm/psci.h
2076@@ -29,7 +29,7 @@ struct psci_operations {
2077 int (*cpu_off)(struct psci_power_state state);
2078 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2079 int (*migrate)(unsigned long cpuid);
2080-};
2081+} __no_const;
2082
2083 extern struct psci_operations psci_ops;
2084
2085diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2086index d3a22be..3a69ad5 100644
2087--- a/arch/arm/include/asm/smp.h
2088+++ b/arch/arm/include/asm/smp.h
2089@@ -107,7 +107,7 @@ struct smp_operations {
2090 int (*cpu_disable)(unsigned int cpu);
2091 #endif
2092 #endif
2093-};
2094+} __no_const;
2095
2096 /*
2097 * set platform specific SMP operations
2098diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2099index 1995d1a..76693a2 100644
2100--- a/arch/arm/include/asm/thread_info.h
2101+++ b/arch/arm/include/asm/thread_info.h
2102@@ -77,9 +77,9 @@ struct thread_info {
2103 .flags = 0, \
2104 .preempt_count = INIT_PREEMPT_COUNT, \
2105 .addr_limit = KERNEL_DS, \
2106- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2107- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2108- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2109+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2110+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2111+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2112 .restart_block = { \
2113 .fn = do_no_restart_syscall, \
2114 }, \
2115@@ -152,7 +152,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2116 #define TIF_SYSCALL_AUDIT 9
2117 #define TIF_SYSCALL_TRACEPOINT 10
2118 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2119-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2120+/* within 8 bits of TIF_SYSCALL_TRACE
2121+ * to meet flexible second operand requirements
2122+ */
2123+#define TIF_GRSEC_SETXID 12
2124+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2125 #define TIF_USING_IWMMXT 17
2126 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2127 #define TIF_RESTORE_SIGMASK 20
2128@@ -166,10 +170,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2129 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2130 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2131 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2132+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2133
2134 /* Checks for any syscall work in entry-common.S */
2135 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2136- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2137+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2138
2139 /*
2140 * Change these and you break ASM code in entry-common.S
2141diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2142index 7e1f760..510061e 100644
2143--- a/arch/arm/include/asm/uaccess.h
2144+++ b/arch/arm/include/asm/uaccess.h
2145@@ -18,6 +18,7 @@
2146 #include <asm/domain.h>
2147 #include <asm/unified.h>
2148 #include <asm/compiler.h>
2149+#include <asm/pgtable.h>
2150
2151 #define VERIFY_READ 0
2152 #define VERIFY_WRITE 1
2153@@ -63,11 +64,35 @@ extern int __put_user_bad(void);
2154 static inline void set_fs(mm_segment_t fs)
2155 {
2156 current_thread_info()->addr_limit = fs;
2157- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2158+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2159 }
2160
2161 #define segment_eq(a,b) ((a) == (b))
2162
2163+static inline void pax_open_userland(void)
2164+{
2165+
2166+#ifdef CONFIG_PAX_MEMORY_UDEREF
2167+ if (segment_eq(get_fs(), USER_DS) {
2168+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2169+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2170+ }
2171+#endif
2172+
2173+}
2174+
2175+static inline void pax_close_userland(void)
2176+{
2177+
2178+#ifdef CONFIG_PAX_MEMORY_UDEREF
2179+ if (segment_eq(get_fs(), USER_DS) {
2180+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2181+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2182+ }
2183+#endif
2184+
2185+}
2186+
2187 #define __addr_ok(addr) ({ \
2188 unsigned long flag; \
2189 __asm__("cmp %2, %0; movlo %0, #0" \
2190@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2191
2192 #define get_user(x,p) \
2193 ({ \
2194+ int __e; \
2195 might_fault(); \
2196- __get_user_check(x,p); \
2197+ pax_open_userland(); \
2198+ __e = __get_user_check(x,p); \
2199+ pax_close_userland(); \
2200+ __e; \
2201 })
2202
2203 extern int __put_user_1(void *, unsigned int);
2204@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2205
2206 #define put_user(x,p) \
2207 ({ \
2208+ int __e; \
2209 might_fault(); \
2210- __put_user_check(x,p); \
2211+ pax_open_userland(); \
2212+ __e = __put_user_check(x,p); \
2213+ pax_close_userland(); \
2214+ __e; \
2215 })
2216
2217 #else /* CONFIG_MMU */
2218@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2219 #define __get_user(x,ptr) \
2220 ({ \
2221 long __gu_err = 0; \
2222+ pax_open_userland(); \
2223 __get_user_err((x),(ptr),__gu_err); \
2224+ pax_close_userland(); \
2225 __gu_err; \
2226 })
2227
2228 #define __get_user_error(x,ptr,err) \
2229 ({ \
2230+ pax_open_userland(); \
2231 __get_user_err((x),(ptr),err); \
2232+ pax_close_userland(); \
2233 (void) 0; \
2234 })
2235
2236@@ -312,13 +349,17 @@ do { \
2237 #define __put_user(x,ptr) \
2238 ({ \
2239 long __pu_err = 0; \
2240+ pax_open_userland(); \
2241 __put_user_err((x),(ptr),__pu_err); \
2242+ pax_close_userland(); \
2243 __pu_err; \
2244 })
2245
2246 #define __put_user_error(x,ptr,err) \
2247 ({ \
2248+ pax_open_userland(); \
2249 __put_user_err((x),(ptr),err); \
2250+ pax_close_userland(); \
2251 (void) 0; \
2252 })
2253
2254@@ -418,11 +459,44 @@ do { \
2255
2256
2257 #ifdef CONFIG_MMU
2258-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2259-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2260+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2261+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2262+
2263+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2264+{
2265+ unsigned long ret;
2266+
2267+ check_object_size(to, n, false);
2268+ pax_open_userland();
2269+ ret = ___copy_from_user(to, from, n);
2270+ pax_close_userland();
2271+ return ret;
2272+}
2273+
2274+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2275+{
2276+ unsigned long ret;
2277+
2278+ check_object_size(from, n, true);
2279+ pax_open_userland();
2280+ ret = ___copy_to_user(to, from, n);
2281+ pax_close_userland();
2282+ return ret;
2283+}
2284+
2285 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2286-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2287+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2288 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2289+
2290+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2291+{
2292+ unsigned long ret;
2293+ pax_open_userland();
2294+ ret = ___clear_user(addr, n);
2295+ pax_close_userland();
2296+ return ret;
2297+}
2298+
2299 #else
2300 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2301 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2302@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2303
2304 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2305 {
2306+ if ((long)n < 0)
2307+ return n;
2308+
2309 if (access_ok(VERIFY_READ, from, n))
2310 n = __copy_from_user(to, from, n);
2311 else /* security hole - plug it */
2312@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2313
2314 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2315 {
2316+ if ((long)n < 0)
2317+ return n;
2318+
2319 if (access_ok(VERIFY_WRITE, to, n))
2320 n = __copy_to_user(to, from, n);
2321 return n;
2322diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2323index 96ee092..37f1844 100644
2324--- a/arch/arm/include/uapi/asm/ptrace.h
2325+++ b/arch/arm/include/uapi/asm/ptrace.h
2326@@ -73,7 +73,7 @@
2327 * ARMv7 groups of PSR bits
2328 */
2329 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2330-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2331+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2332 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2333 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2334
2335diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2336index 60d3b73..e5a0f22 100644
2337--- a/arch/arm/kernel/armksyms.c
2338+++ b/arch/arm/kernel/armksyms.c
2339@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2340
2341 /* networking */
2342 EXPORT_SYMBOL(csum_partial);
2343-EXPORT_SYMBOL(csum_partial_copy_from_user);
2344+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2345 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2346 EXPORT_SYMBOL(__csum_ipv6_magic);
2347
2348@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2349 #ifdef CONFIG_MMU
2350 EXPORT_SYMBOL(copy_page);
2351
2352-EXPORT_SYMBOL(__copy_from_user);
2353-EXPORT_SYMBOL(__copy_to_user);
2354-EXPORT_SYMBOL(__clear_user);
2355+EXPORT_SYMBOL(___copy_from_user);
2356+EXPORT_SYMBOL(___copy_to_user);
2357+EXPORT_SYMBOL(___clear_user);
2358
2359 EXPORT_SYMBOL(__get_user_1);
2360 EXPORT_SYMBOL(__get_user_2);
2361diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2362index 582b405..50351b7 100644
2363--- a/arch/arm/kernel/entry-armv.S
2364+++ b/arch/arm/kernel/entry-armv.S
2365@@ -47,6 +47,87 @@
2366 9997:
2367 .endm
2368
2369+ .macro pax_enter_kernel
2370+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2371+ @ make aligned space for saved DACR
2372+ sub sp, sp, #8
2373+ @ save regs
2374+ stmdb sp!, {r1, r2}
2375+ @ read DACR from cpu_domain into r1
2376+ mov r2, sp
2377+ @ assume 8K pages, since we have to split the immediate in two
2378+ bic r2, r2, #(0x1fc0)
2379+ bic r2, r2, #(0x3f)
2380+ ldr r1, [r2, #TI_CPU_DOMAIN]
2381+ @ store old DACR on stack
2382+ str r1, [sp, #8]
2383+#ifdef CONFIG_PAX_KERNEXEC
2384+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2385+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2386+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2387+#endif
2388+#ifdef CONFIG_PAX_MEMORY_UDEREF
2389+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2390+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2391+#endif
2392+ @ write r1 to current_thread_info()->cpu_domain
2393+ str r1, [r2, #TI_CPU_DOMAIN]
2394+ @ write r1 to DACR
2395+ mcr p15, 0, r1, c3, c0, 0
2396+ @ instruction sync
2397+ instr_sync
2398+ @ restore regs
2399+ ldmia sp!, {r1, r2}
2400+#endif
2401+ .endm
2402+
2403+ .macro pax_open_userland
2404+#ifdef CONFIG_PAX_MEMORY_UDEREF
2405+ @ save regs
2406+ stmdb sp!, {r0, r1}
2407+ @ read DACR from cpu_domain into r1
2408+ mov r0, sp
2409+ @ assume 8K pages, since we have to split the immediate in two
2410+ bic r0, r0, #(0x1fc0)
2411+ bic r0, r0, #(0x3f)
2412+ ldr r1, [r0, #TI_CPU_DOMAIN]
2413+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2414+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2415+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2416+ @ write r1 to current_thread_info()->cpu_domain
2417+ str r1, [r0, #TI_CPU_DOMAIN]
2418+ @ write r1 to DACR
2419+ mcr p15, 0, r1, c3, c0, 0
2420+ @ instruction sync
2421+ instr_sync
2422+ @ restore regs
2423+ ldmia sp!, {r0, r1}
2424+#endif
2425+ .endm
2426+
2427+ .macro pax_close_userland
2428+#ifdef CONFIG_PAX_MEMORY_UDEREF
2429+ @ save regs
2430+ stmdb sp!, {r0, r1}
2431+ @ read DACR from cpu_domain into r1
2432+ mov r0, sp
2433+ @ assume 8K pages, since we have to split the immediate in two
2434+ bic r0, r0, #(0x1fc0)
2435+ bic r0, r0, #(0x3f)
2436+ ldr r1, [r0, #TI_CPU_DOMAIN]
2437+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2438+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2439+ @ write r1 to current_thread_info()->cpu_domain
2440+ str r1, [r0, #TI_CPU_DOMAIN]
2441+ @ write r1 to DACR
2442+ mcr p15, 0, r1, c3, c0, 0
2443+ @ instruction sync
2444+ instr_sync
2445+ @ restore regs
2446+ ldmia sp!, {r0, r1}
2447+#endif
2448+ .endm
2449+
2450 .macro pabt_helper
2451 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2452 #ifdef MULTI_PABORT
2453@@ -89,11 +170,15 @@
2454 * Invalid mode handlers
2455 */
2456 .macro inv_entry, reason
2457+
2458+ pax_enter_kernel
2459+
2460 sub sp, sp, #S_FRAME_SIZE
2461 ARM( stmib sp, {r1 - lr} )
2462 THUMB( stmia sp, {r0 - r12} )
2463 THUMB( str sp, [sp, #S_SP] )
2464 THUMB( str lr, [sp, #S_LR] )
2465+
2466 mov r1, #\reason
2467 .endm
2468
2469@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2470 .macro svc_entry, stack_hole=0
2471 UNWIND(.fnstart )
2472 UNWIND(.save {r0 - pc} )
2473+
2474+ pax_enter_kernel
2475+
2476 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2477+
2478 #ifdef CONFIG_THUMB2_KERNEL
2479 SPFIX( str r0, [sp] ) @ temporarily saved
2480 SPFIX( mov r0, sp )
2481@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2482 ldmia r0, {r3 - r5}
2483 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2484 mov r6, #-1 @ "" "" "" ""
2485+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2486+ @ offset sp by 8 as done in pax_enter_kernel
2487+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2488+#else
2489 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2490+#endif
2491 SPFIX( addeq r2, r2, #4 )
2492 str r3, [sp, #-4]! @ save the "real" r0 copied
2493 @ from the exception stack
2494@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2495 .macro usr_entry
2496 UNWIND(.fnstart )
2497 UNWIND(.cantunwind ) @ don't unwind the user space
2498+
2499+ pax_enter_kernel_user
2500+
2501 sub sp, sp, #S_FRAME_SIZE
2502 ARM( stmib sp, {r1 - r12} )
2503 THUMB( stmia sp, {r0 - r12} )
2504@@ -414,7 +511,9 @@ __und_usr:
2505 tst r3, #PSR_T_BIT @ Thumb mode?
2506 bne __und_usr_thumb
2507 sub r4, r2, #4 @ ARM instr at LR - 4
2508+ pax_open_userland
2509 1: ldrt r0, [r4]
2510+ pax_close_userland
2511 #ifdef CONFIG_CPU_ENDIAN_BE8
2512 rev r0, r0 @ little endian instruction
2513 #endif
2514@@ -449,10 +548,14 @@ __und_usr_thumb:
2515 */
2516 .arch armv6t2
2517 #endif
2518+ pax_open_userland
2519 2: ldrht r5, [r4]
2520+ pax_close_userland
2521 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2522 blo __und_usr_fault_16 @ 16bit undefined instruction
2523+ pax_open_userland
2524 3: ldrht r0, [r2]
2525+ pax_close_userland
2526 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2527 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2528 orr r0, r0, r5, lsl #16
2529@@ -690,7 +793,7 @@ ENTRY(__switch_to)
2530 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2531 THUMB( str sp, [ip], #4 )
2532 THUMB( str lr, [ip], #4 )
2533-#ifdef CONFIG_CPU_USE_DOMAINS
2534+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2535 ldr r6, [r2, #TI_CPU_DOMAIN]
2536 #endif
2537 set_tls r3, r4, r5
2538@@ -699,7 +802,7 @@ ENTRY(__switch_to)
2539 ldr r8, =__stack_chk_guard
2540 ldr r7, [r7, #TSK_STACK_CANARY]
2541 #endif
2542-#ifdef CONFIG_CPU_USE_DOMAINS
2543+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2544 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2545 #endif
2546 mov r5, r0
2547diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2548index bc5bc0a..d0998ca 100644
2549--- a/arch/arm/kernel/entry-common.S
2550+++ b/arch/arm/kernel/entry-common.S
2551@@ -10,18 +10,46 @@
2552
2553 #include <asm/unistd.h>
2554 #include <asm/ftrace.h>
2555+#include <asm/domain.h>
2556 #include <asm/unwind.h>
2557
2558+#include "entry-header.S"
2559+
2560 #ifdef CONFIG_NEED_RET_TO_USER
2561 #include <mach/entry-macro.S>
2562 #else
2563 .macro arch_ret_to_user, tmp1, tmp2
2564+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2565+ @ save regs
2566+ stmdb sp!, {r1, r2}
2567+ @ read DACR from cpu_domain into r1
2568+ mov r2, sp
2569+ @ assume 8K pages, since we have to split the immediate in two
2570+ bic r2, r2, #(0x1fc0)
2571+ bic r2, r2, #(0x3f)
2572+ ldr r1, [r2, #TI_CPU_DOMAIN]
2573+#ifdef CONFIG_PAX_KERNEXEC
2574+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2575+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2576+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2577+#endif
2578+#ifdef CONFIG_PAX_MEMORY_UDEREF
2579+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2580+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2581+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2582+#endif
2583+ @ write r1 to current_thread_info()->cpu_domain
2584+ str r1, [r2, #TI_CPU_DOMAIN]
2585+ @ write r1 to DACR
2586+ mcr p15, 0, r1, c3, c0, 0
2587+ @ instruction sync
2588+ instr_sync
2589+ @ restore regs
2590+ ldmia sp!, {r1, r2}
2591+#endif
2592 .endm
2593 #endif
2594
2595-#include "entry-header.S"
2596-
2597-
2598 .align 5
2599 /*
2600 * This is the fast syscall return path. We do as little as
2601@@ -350,6 +378,7 @@ ENDPROC(ftrace_stub)
2602
2603 .align 5
2604 ENTRY(vector_swi)
2605+
2606 sub sp, sp, #S_FRAME_SIZE
2607 stmia sp, {r0 - r12} @ Calling r0 - r12
2608 ARM( add r8, sp, #S_PC )
2609@@ -399,6 +428,12 @@ ENTRY(vector_swi)
2610 ldr scno, [lr, #-4] @ get SWI instruction
2611 #endif
2612
2613+ /*
2614+ * do this here to avoid a performance hit of wrapping the code above
2615+ * that directly dereferences userland to parse the SWI instruction
2616+ */
2617+ pax_enter_kernel_user
2618+
2619 #ifdef CONFIG_ALIGNMENT_TRAP
2620 ldr ip, __cr_alignment
2621 ldr ip, [ip]
2622diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2623index 160f337..db67ee4 100644
2624--- a/arch/arm/kernel/entry-header.S
2625+++ b/arch/arm/kernel/entry-header.S
2626@@ -73,6 +73,60 @@
2627 msr cpsr_c, \rtemp @ switch back to the SVC mode
2628 .endm
2629
2630+ .macro pax_enter_kernel_user
2631+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2632+ @ save regs
2633+ stmdb sp!, {r0, r1}
2634+ @ read DACR from cpu_domain into r1
2635+ mov r0, sp
2636+ @ assume 8K pages, since we have to split the immediate in two
2637+ bic r0, r0, #(0x1fc0)
2638+ bic r0, r0, #(0x3f)
2639+ ldr r1, [r0, #TI_CPU_DOMAIN]
2640+#ifdef CONFIG_PAX_MEMORY_UDEREF
2641+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2642+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2643+#endif
2644+#ifdef CONFIG_PAX_KERNEXEC
2645+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2646+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2647+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2648+#endif
2649+ @ write r1 to current_thread_info()->cpu_domain
2650+ str r1, [r0, #TI_CPU_DOMAIN]
2651+ @ write r1 to DACR
2652+ mcr p15, 0, r1, c3, c0, 0
2653+ @ instruction sync
2654+ instr_sync
2655+ @ restore regs
2656+ ldmia sp!, {r0, r1}
2657+#endif
2658+ .endm
2659+
2660+ .macro pax_exit_kernel
2661+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2662+ @ save regs
2663+ stmdb sp!, {r0, r1}
2664+ @ read old DACR from stack into r1
2665+ ldr r1, [sp, #(8 + S_SP)]
2666+ sub r1, r1, #8
2667+ ldr r1, [r1]
2668+
2669+ @ write r1 to current_thread_info()->cpu_domain
2670+ mov r0, sp
2671+ @ assume 8K pages, since we have to split the immediate in two
2672+ bic r0, r0, #(0x1fc0)
2673+ bic r0, r0, #(0x3f)
2674+ str r1, [r0, #TI_CPU_DOMAIN]
2675+ @ write r1 to DACR
2676+ mcr p15, 0, r1, c3, c0, 0
2677+ @ instruction sync
2678+ instr_sync
2679+ @ restore regs
2680+ ldmia sp!, {r0, r1}
2681+#endif
2682+ .endm
2683+
2684 #ifndef CONFIG_THUMB2_KERNEL
2685 .macro svc_exit, rpsr, irq = 0
2686 .if \irq != 0
2687@@ -92,6 +146,9 @@
2688 blne trace_hardirqs_off
2689 #endif
2690 .endif
2691+
2692+ pax_exit_kernel
2693+
2694 msr spsr_cxsf, \rpsr
2695 #if defined(CONFIG_CPU_V6)
2696 ldr r0, [sp]
2697@@ -155,6 +212,9 @@
2698 blne trace_hardirqs_off
2699 #endif
2700 .endif
2701+
2702+ pax_exit_kernel
2703+
2704 ldr lr, [sp, #S_SP] @ top of the stack
2705 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2706 clrex @ clear the exclusive monitor
2707diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2708index 2adda11..7fbe958 100644
2709--- a/arch/arm/kernel/fiq.c
2710+++ b/arch/arm/kernel/fiq.c
2711@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2712 #if defined(CONFIG_CPU_USE_DOMAINS)
2713 memcpy((void *)0xffff001c, start, length);
2714 #else
2715+ pax_open_kernel();
2716 memcpy(vectors_page + 0x1c, start, length);
2717+ pax_close_kernel();
2718 #endif
2719 flush_icache_range(0xffff001c, 0xffff001c + length);
2720 if (!vectors_high())
2721diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2722index 8bac553..caee108 100644
2723--- a/arch/arm/kernel/head.S
2724+++ b/arch/arm/kernel/head.S
2725@@ -52,7 +52,9 @@
2726 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2727
2728 .macro pgtbl, rd, phys
2729- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2730+ mov \rd, #TEXT_OFFSET
2731+ sub \rd, #PG_DIR_SIZE
2732+ add \rd, \rd, \phys
2733 .endm
2734
2735 /*
2736@@ -434,7 +436,7 @@ __enable_mmu:
2737 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2738 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2739 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2740- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2741+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2742 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2743 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2744 #endif
2745diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2746index 1fd749e..47adb08 100644
2747--- a/arch/arm/kernel/hw_breakpoint.c
2748+++ b/arch/arm/kernel/hw_breakpoint.c
2749@@ -1029,7 +1029,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2750 return NOTIFY_OK;
2751 }
2752
2753-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2754+static struct notifier_block dbg_reset_nb = {
2755 .notifier_call = dbg_reset_notify,
2756 };
2757
2758diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2759index 1e9be5d..03edbc2 100644
2760--- a/arch/arm/kernel/module.c
2761+++ b/arch/arm/kernel/module.c
2762@@ -37,12 +37,37 @@
2763 #endif
2764
2765 #ifdef CONFIG_MMU
2766-void *module_alloc(unsigned long size)
2767+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2768 {
2769+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2770+ return NULL;
2771 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2772- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2773+ GFP_KERNEL, prot, -1,
2774 __builtin_return_address(0));
2775 }
2776+
2777+void *module_alloc(unsigned long size)
2778+{
2779+
2780+#ifdef CONFIG_PAX_KERNEXEC
2781+ return __module_alloc(size, PAGE_KERNEL);
2782+#else
2783+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2784+#endif
2785+
2786+}
2787+
2788+#ifdef CONFIG_PAX_KERNEXEC
2789+void module_free_exec(struct module *mod, void *module_region)
2790+{
2791+ module_free(mod, module_region);
2792+}
2793+
2794+void *module_alloc_exec(unsigned long size)
2795+{
2796+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2797+}
2798+#endif
2799 #endif
2800
2801 int
2802diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2803index 07314af..c46655c 100644
2804--- a/arch/arm/kernel/patch.c
2805+++ b/arch/arm/kernel/patch.c
2806@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2807 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2808 int size;
2809
2810+ pax_open_kernel();
2811 if (thumb2 && __opcode_is_thumb16(insn)) {
2812 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2813 size = sizeof(u16);
2814@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2815 *(u32 *)addr = insn;
2816 size = sizeof(u32);
2817 }
2818+ pax_close_kernel();
2819
2820 flush_icache_range((uintptr_t)(addr),
2821 (uintptr_t)(addr) + size);
2822diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2823index 1f2740e..b36e225 100644
2824--- a/arch/arm/kernel/perf_event_cpu.c
2825+++ b/arch/arm/kernel/perf_event_cpu.c
2826@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2827 return NOTIFY_OK;
2828 }
2829
2830-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2831+static struct notifier_block cpu_pmu_hotplug_notifier = {
2832 .notifier_call = cpu_pmu_notify,
2833 };
2834
2835diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2836index 6e8931c..82ec6a5 100644
2837--- a/arch/arm/kernel/process.c
2838+++ b/arch/arm/kernel/process.c
2839@@ -28,7 +28,6 @@
2840 #include <linux/tick.h>
2841 #include <linux/utsname.h>
2842 #include <linux/uaccess.h>
2843-#include <linux/random.h>
2844 #include <linux/hw_breakpoint.h>
2845 #include <linux/cpuidle.h>
2846 #include <linux/leds.h>
2847@@ -223,6 +222,7 @@ void machine_power_off(void)
2848
2849 if (pm_power_off)
2850 pm_power_off();
2851+ BUG();
2852 }
2853
2854 /*
2855@@ -236,7 +236,7 @@ void machine_power_off(void)
2856 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2857 * to use. Implementing such co-ordination would be essentially impossible.
2858 */
2859-void machine_restart(char *cmd)
2860+__noreturn void machine_restart(char *cmd)
2861 {
2862 smp_send_stop();
2863
2864@@ -258,8 +258,8 @@ void __show_regs(struct pt_regs *regs)
2865
2866 show_regs_print_info(KERN_DEFAULT);
2867
2868- print_symbol("PC is at %s\n", instruction_pointer(regs));
2869- print_symbol("LR is at %s\n", regs->ARM_lr);
2870+ printk("PC is at %pA\n", instruction_pointer(regs));
2871+ printk("LR is at %pA\n", regs->ARM_lr);
2872 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2873 "sp : %08lx ip : %08lx fp : %08lx\n",
2874 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2875@@ -426,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2876 return 0;
2877 }
2878
2879-unsigned long arch_randomize_brk(struct mm_struct *mm)
2880-{
2881- unsigned long range_end = mm->brk + 0x02000000;
2882- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2883-}
2884-
2885 #ifdef CONFIG_MMU
2886 /*
2887 * The vectors page is always readable from user space for the
2888@@ -441,12 +435,12 @@ unsigned long arch_randomize_brk(struct mm_struct *mm)
2889 static struct vm_area_struct gate_vma = {
2890 .vm_start = 0xffff0000,
2891 .vm_end = 0xffff0000 + PAGE_SIZE,
2892- .vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC,
2893+ .vm_flags = VM_NONE,
2894 };
2895
2896 static int __init gate_vma_init(void)
2897 {
2898- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2899+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2900 return 0;
2901 }
2902 arch_initcall(gate_vma_init);
2903diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2904index 3653164..d83e55d 100644
2905--- a/arch/arm/kernel/psci.c
2906+++ b/arch/arm/kernel/psci.c
2907@@ -24,7 +24,7 @@
2908 #include <asm/opcodes-virt.h>
2909 #include <asm/psci.h>
2910
2911-struct psci_operations psci_ops;
2912+struct psci_operations psci_ops __read_only;
2913
2914 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2915
2916diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2917index 03deeff..741ce88 100644
2918--- a/arch/arm/kernel/ptrace.c
2919+++ b/arch/arm/kernel/ptrace.c
2920@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2921 return current_thread_info()->syscall;
2922 }
2923
2924+#ifdef CONFIG_GRKERNSEC_SETXID
2925+extern void gr_delayed_cred_worker(void);
2926+#endif
2927+
2928 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2929 {
2930 current_thread_info()->syscall = scno;
2931
2932+#ifdef CONFIG_GRKERNSEC_SETXID
2933+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2934+ gr_delayed_cred_worker();
2935+#endif
2936+
2937 /* Do the secure computing check first; failures should be fast. */
2938 if (secure_computing(scno) == -1)
2939 return -1;
2940diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2941index b4b1d39..efdc9be 100644
2942--- a/arch/arm/kernel/setup.c
2943+++ b/arch/arm/kernel/setup.c
2944@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2945 unsigned int elf_hwcap __read_mostly;
2946 EXPORT_SYMBOL(elf_hwcap);
2947
2948+pteval_t __supported_pte_mask __read_only;
2949+pmdval_t __supported_pmd_mask __read_only;
2950
2951 #ifdef MULTI_CPU
2952-struct processor processor __read_mostly;
2953+struct processor processor;
2954 #endif
2955 #ifdef MULTI_TLB
2956-struct cpu_tlb_fns cpu_tlb __read_mostly;
2957+struct cpu_tlb_fns cpu_tlb __read_only;
2958 #endif
2959 #ifdef MULTI_USER
2960-struct cpu_user_fns cpu_user __read_mostly;
2961+struct cpu_user_fns cpu_user __read_only;
2962 #endif
2963 #ifdef MULTI_CACHE
2964-struct cpu_cache_fns cpu_cache __read_mostly;
2965+struct cpu_cache_fns cpu_cache __read_only;
2966 #endif
2967 #ifdef CONFIG_OUTER_CACHE
2968-struct outer_cache_fns outer_cache __read_mostly;
2969+struct outer_cache_fns outer_cache __read_only;
2970 EXPORT_SYMBOL(outer_cache);
2971 #endif
2972
2973@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2974 asm("mrc p15, 0, %0, c0, c1, 4"
2975 : "=r" (mmfr0));
2976 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2977- (mmfr0 & 0x000000f0) >= 0x00000030)
2978+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2979 cpu_arch = CPU_ARCH_ARMv7;
2980- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2981+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2982+ __supported_pte_mask |= L_PTE_PXN;
2983+ __supported_pmd_mask |= PMD_PXNTABLE;
2984+ }
2985+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2986 (mmfr0 & 0x000000f0) == 0x00000020)
2987 cpu_arch = CPU_ARCH_ARMv6;
2988 else
2989@@ -479,7 +485,7 @@ static void __init setup_processor(void)
2990 __cpu_architecture = __get_cpu_architecture();
2991
2992 #ifdef MULTI_CPU
2993- processor = *list->proc;
2994+ memcpy((void *)&processor, list->proc, sizeof processor);
2995 #endif
2996 #ifdef MULTI_TLB
2997 cpu_tlb = *list->tlb;
2998diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
2999index 296786b..a8d4dd5 100644
3000--- a/arch/arm/kernel/signal.c
3001+++ b/arch/arm/kernel/signal.c
3002@@ -396,22 +396,14 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3003 __put_user(sigreturn_codes[idx+1], rc+1))
3004 return 1;
3005
3006- if (cpsr & MODE32_BIT) {
3007- /*
3008- * 32-bit code can use the new high-page
3009- * signal return code support.
3010- */
3011- retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
3012- } else {
3013- /*
3014- * Ensure that the instruction cache sees
3015- * the return code written onto the stack.
3016- */
3017- flush_icache_range((unsigned long)rc,
3018- (unsigned long)(rc + 2));
3019+ /*
3020+ * Ensure that the instruction cache sees
3021+ * the return code written onto the stack.
3022+ */
3023+ flush_icache_range((unsigned long)rc,
3024+ (unsigned long)(rc + 2));
3025
3026- retcode = ((unsigned long)rc) + thumb;
3027- }
3028+ retcode = ((unsigned long)rc) + thumb;
3029 }
3030
3031 regs->ARM_r0 = map_sig(ksig->sig);
3032diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3033index 5919eb4..b5d6dfe 100644
3034--- a/arch/arm/kernel/smp.c
3035+++ b/arch/arm/kernel/smp.c
3036@@ -70,7 +70,7 @@ enum ipi_msg_type {
3037
3038 static DECLARE_COMPLETION(cpu_running);
3039
3040-static struct smp_operations smp_ops;
3041+static struct smp_operations smp_ops __read_only;
3042
3043 void __init smp_set_ops(struct smp_operations *ops)
3044 {
3045diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3046index 18b32e8..b0c8dca 100644
3047--- a/arch/arm/kernel/traps.c
3048+++ b/arch/arm/kernel/traps.c
3049@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3050 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3051 {
3052 #ifdef CONFIG_KALLSYMS
3053- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3054+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3055 #else
3056 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3057 #endif
3058@@ -259,6 +259,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3059 static int die_owner = -1;
3060 static unsigned int die_nest_count;
3061
3062+extern void gr_handle_kernel_exploit(void);
3063+
3064 static unsigned long oops_begin(void)
3065 {
3066 int cpu;
3067@@ -301,6 +303,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3068 panic("Fatal exception in interrupt");
3069 if (panic_on_oops)
3070 panic("Fatal exception");
3071+
3072+ gr_handle_kernel_exploit();
3073+
3074 if (signr)
3075 do_exit(signr);
3076 }
3077@@ -594,7 +599,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3078 * The user helper at 0xffff0fe0 must be used instead.
3079 * (see entry-armv.S for details)
3080 */
3081+ pax_open_kernel();
3082 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3083+ pax_close_kernel();
3084 }
3085 return 0;
3086
3087@@ -834,13 +841,10 @@ void __init early_trap_init(void *vectors_base)
3088 */
3089 kuser_get_tls_init(vectors);
3090
3091- /*
3092- * Copy signal return handlers into the vector page, and
3093- * set sigreturn to be a pointer to these.
3094- */
3095- memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE),
3096- sigreturn_codes, sizeof(sigreturn_codes));
3097-
3098 flush_icache_range(vectors, vectors + PAGE_SIZE);
3099- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3100+
3101+#ifndef CONFIG_PAX_MEMORY_UDEREF
3102+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3103+#endif
3104+
3105 }
3106diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3107index a871b8e..123b00a 100644
3108--- a/arch/arm/kernel/vmlinux.lds.S
3109+++ b/arch/arm/kernel/vmlinux.lds.S
3110@@ -8,7 +8,11 @@
3111 #include <asm/thread_info.h>
3112 #include <asm/memory.h>
3113 #include <asm/page.h>
3114-
3115+
3116+#ifdef CONFIG_PAX_KERNEXEC
3117+#include <asm/pgtable.h>
3118+#endif
3119+
3120 #define PROC_INFO \
3121 . = ALIGN(4); \
3122 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3123@@ -94,6 +98,11 @@ SECTIONS
3124 _text = .;
3125 HEAD_TEXT
3126 }
3127+
3128+#ifdef CONFIG_PAX_KERNEXEC
3129+ . = ALIGN(1<<SECTION_SHIFT);
3130+#endif
3131+
3132 .text : { /* Real text segment */
3133 _stext = .; /* Text and read-only data */
3134 __exception_text_start = .;
3135@@ -116,6 +125,8 @@ SECTIONS
3136 ARM_CPU_KEEP(PROC_INFO)
3137 }
3138
3139+ _etext = .; /* End of text section */
3140+
3141 RO_DATA(PAGE_SIZE)
3142
3143 . = ALIGN(4);
3144@@ -146,7 +157,9 @@ SECTIONS
3145
3146 NOTES
3147
3148- _etext = .; /* End of text and rodata section */
3149+#ifdef CONFIG_PAX_KERNEXEC
3150+ . = ALIGN(1<<SECTION_SHIFT);
3151+#endif
3152
3153 #ifndef CONFIG_XIP_KERNEL
3154 . = ALIGN(PAGE_SIZE);
3155@@ -207,6 +220,11 @@ SECTIONS
3156 . = PAGE_OFFSET + TEXT_OFFSET;
3157 #else
3158 __init_end = .;
3159+
3160+#ifdef CONFIG_PAX_KERNEXEC
3161+ . = ALIGN(1<<SECTION_SHIFT);
3162+#endif
3163+
3164 . = ALIGN(THREAD_SIZE);
3165 __data_loc = .;
3166 #endif
3167diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3168index 14a0d98..7771a7d 100644
3169--- a/arch/arm/lib/clear_user.S
3170+++ b/arch/arm/lib/clear_user.S
3171@@ -12,14 +12,14 @@
3172
3173 .text
3174
3175-/* Prototype: int __clear_user(void *addr, size_t sz)
3176+/* Prototype: int ___clear_user(void *addr, size_t sz)
3177 * Purpose : clear some user memory
3178 * Params : addr - user memory address to clear
3179 * : sz - number of bytes to clear
3180 * Returns : number of bytes NOT cleared
3181 */
3182 ENTRY(__clear_user_std)
3183-WEAK(__clear_user)
3184+WEAK(___clear_user)
3185 stmfd sp!, {r1, lr}
3186 mov r2, #0
3187 cmp r1, #4
3188@@ -44,7 +44,7 @@ WEAK(__clear_user)
3189 USER( strnebt r2, [r0])
3190 mov r0, #0
3191 ldmfd sp!, {r1, pc}
3192-ENDPROC(__clear_user)
3193+ENDPROC(___clear_user)
3194 ENDPROC(__clear_user_std)
3195
3196 .pushsection .fixup,"ax"
3197diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3198index 66a477a..bee61d3 100644
3199--- a/arch/arm/lib/copy_from_user.S
3200+++ b/arch/arm/lib/copy_from_user.S
3201@@ -16,7 +16,7 @@
3202 /*
3203 * Prototype:
3204 *
3205- * size_t __copy_from_user(void *to, const void *from, size_t n)
3206+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3207 *
3208 * Purpose:
3209 *
3210@@ -84,11 +84,11 @@
3211
3212 .text
3213
3214-ENTRY(__copy_from_user)
3215+ENTRY(___copy_from_user)
3216
3217 #include "copy_template.S"
3218
3219-ENDPROC(__copy_from_user)
3220+ENDPROC(___copy_from_user)
3221
3222 .pushsection .fixup,"ax"
3223 .align 0
3224diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3225index 6ee2f67..d1cce76 100644
3226--- a/arch/arm/lib/copy_page.S
3227+++ b/arch/arm/lib/copy_page.S
3228@@ -10,6 +10,7 @@
3229 * ASM optimised string functions
3230 */
3231 #include <linux/linkage.h>
3232+#include <linux/const.h>
3233 #include <asm/assembler.h>
3234 #include <asm/asm-offsets.h>
3235 #include <asm/cache.h>
3236diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3237index d066df6..df28194 100644
3238--- a/arch/arm/lib/copy_to_user.S
3239+++ b/arch/arm/lib/copy_to_user.S
3240@@ -16,7 +16,7 @@
3241 /*
3242 * Prototype:
3243 *
3244- * size_t __copy_to_user(void *to, const void *from, size_t n)
3245+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3246 *
3247 * Purpose:
3248 *
3249@@ -88,11 +88,11 @@
3250 .text
3251
3252 ENTRY(__copy_to_user_std)
3253-WEAK(__copy_to_user)
3254+WEAK(___copy_to_user)
3255
3256 #include "copy_template.S"
3257
3258-ENDPROC(__copy_to_user)
3259+ENDPROC(___copy_to_user)
3260 ENDPROC(__copy_to_user_std)
3261
3262 .pushsection .fixup,"ax"
3263diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3264index 7d08b43..f7ca7ea 100644
3265--- a/arch/arm/lib/csumpartialcopyuser.S
3266+++ b/arch/arm/lib/csumpartialcopyuser.S
3267@@ -57,8 +57,8 @@
3268 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3269 */
3270
3271-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3272-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3273+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3274+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3275
3276 #include "csumpartialcopygeneric.S"
3277
3278diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3279index 64dbfa5..84a3fd9 100644
3280--- a/arch/arm/lib/delay.c
3281+++ b/arch/arm/lib/delay.c
3282@@ -28,7 +28,7 @@
3283 /*
3284 * Default to the loop-based delay implementation.
3285 */
3286-struct arm_delay_ops arm_delay_ops = {
3287+struct arm_delay_ops arm_delay_ops __read_only = {
3288 .delay = __loop_delay,
3289 .const_udelay = __loop_const_udelay,
3290 .udelay = __loop_udelay,
3291diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3292index 025f742..8432b08 100644
3293--- a/arch/arm/lib/uaccess_with_memcpy.c
3294+++ b/arch/arm/lib/uaccess_with_memcpy.c
3295@@ -104,7 +104,7 @@ out:
3296 }
3297
3298 unsigned long
3299-__copy_to_user(void __user *to, const void *from, unsigned long n)
3300+___copy_to_user(void __user *to, const void *from, unsigned long n)
3301 {
3302 /*
3303 * This test is stubbed out of the main function above to keep
3304diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3305index f389228..592ef66 100644
3306--- a/arch/arm/mach-kirkwood/common.c
3307+++ b/arch/arm/mach-kirkwood/common.c
3308@@ -149,7 +149,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3309 clk_gate_ops.disable(hw);
3310 }
3311
3312-static struct clk_ops clk_gate_fn_ops;
3313+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3314+{
3315+ return clk_gate_ops.is_enabled(hw);
3316+}
3317+
3318+static struct clk_ops clk_gate_fn_ops = {
3319+ .enable = clk_gate_fn_enable,
3320+ .disable = clk_gate_fn_disable,
3321+ .is_enabled = clk_gate_fn_is_enabled,
3322+};
3323
3324 static struct clk __init *clk_register_gate_fn(struct device *dev,
3325 const char *name,
3326@@ -183,14 +192,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3327 gate_fn->fn_en = fn_en;
3328 gate_fn->fn_dis = fn_dis;
3329
3330- /* ops is the gate ops, but with our enable/disable functions */
3331- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3332- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3333- clk_gate_fn_ops = clk_gate_ops;
3334- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3335- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3336- }
3337-
3338 clk = clk_register(dev, &gate_fn->gate.hw);
3339
3340 if (IS_ERR(clk))
3341diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3342index f6eeb87..cc90868 100644
3343--- a/arch/arm/mach-omap2/board-n8x0.c
3344+++ b/arch/arm/mach-omap2/board-n8x0.c
3345@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3346 }
3347 #endif
3348
3349-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3350+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3351 .late_init = n8x0_menelaus_late_init,
3352 };
3353
3354diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3355index 6c4da12..d9ca72d 100644
3356--- a/arch/arm/mach-omap2/gpmc.c
3357+++ b/arch/arm/mach-omap2/gpmc.c
3358@@ -147,7 +147,6 @@ struct omap3_gpmc_regs {
3359 };
3360
3361 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3362-static struct irq_chip gpmc_irq_chip;
3363 static unsigned gpmc_irq_start;
3364
3365 static struct resource gpmc_mem_root;
3366@@ -711,6 +710,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3367
3368 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3369
3370+static struct irq_chip gpmc_irq_chip = {
3371+ .name = "gpmc",
3372+ .irq_startup = gpmc_irq_noop_ret,
3373+ .irq_enable = gpmc_irq_enable,
3374+ .irq_disable = gpmc_irq_disable,
3375+ .irq_shutdown = gpmc_irq_noop,
3376+ .irq_ack = gpmc_irq_noop,
3377+ .irq_mask = gpmc_irq_noop,
3378+ .irq_unmask = gpmc_irq_noop,
3379+
3380+};
3381+
3382 static int gpmc_setup_irq(void)
3383 {
3384 int i;
3385@@ -725,15 +736,6 @@ static int gpmc_setup_irq(void)
3386 return gpmc_irq_start;
3387 }
3388
3389- gpmc_irq_chip.name = "gpmc";
3390- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3391- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3392- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3393- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3394- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3395- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3396- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3397-
3398 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3399 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3400
3401diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3402index f8bb3b9..831e7b8 100644
3403--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3404+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3405@@ -339,7 +339,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3406 return NOTIFY_OK;
3407 }
3408
3409-static struct notifier_block __refdata irq_hotplug_notifier = {
3410+static struct notifier_block irq_hotplug_notifier = {
3411 .notifier_call = irq_cpu_hotplug_notify,
3412 };
3413
3414diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3415index e6d2307..d057195 100644
3416--- a/arch/arm/mach-omap2/omap_device.c
3417+++ b/arch/arm/mach-omap2/omap_device.c
3418@@ -499,7 +499,7 @@ void omap_device_delete(struct omap_device *od)
3419 struct platform_device __init *omap_device_build(const char *pdev_name,
3420 int pdev_id,
3421 struct omap_hwmod *oh,
3422- void *pdata, int pdata_len)
3423+ const void *pdata, int pdata_len)
3424 {
3425 struct omap_hwmod *ohs[] = { oh };
3426
3427@@ -527,7 +527,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3428 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3429 int pdev_id,
3430 struct omap_hwmod **ohs,
3431- int oh_cnt, void *pdata,
3432+ int oh_cnt, const void *pdata,
3433 int pdata_len)
3434 {
3435 int ret = -ENOMEM;
3436diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3437index 044c31d..2ee0861 100644
3438--- a/arch/arm/mach-omap2/omap_device.h
3439+++ b/arch/arm/mach-omap2/omap_device.h
3440@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3441 /* Core code interface */
3442
3443 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3444- struct omap_hwmod *oh, void *pdata,
3445+ struct omap_hwmod *oh, const void *pdata,
3446 int pdata_len);
3447
3448 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3449 struct omap_hwmod **oh, int oh_cnt,
3450- void *pdata, int pdata_len);
3451+ const void *pdata, int pdata_len);
3452
3453 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3454 struct omap_hwmod **ohs, int oh_cnt);
3455diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3456index 7341eff..fd75e34 100644
3457--- a/arch/arm/mach-omap2/omap_hwmod.c
3458+++ b/arch/arm/mach-omap2/omap_hwmod.c
3459@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3460 int (*init_clkdm)(struct omap_hwmod *oh);
3461 void (*update_context_lost)(struct omap_hwmod *oh);
3462 int (*get_context_lost)(struct omap_hwmod *oh);
3463-};
3464+} __no_const;
3465
3466 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3467-static struct omap_hwmod_soc_ops soc_ops;
3468+static struct omap_hwmod_soc_ops soc_ops __read_only;
3469
3470 /* omap_hwmod_list contains all registered struct omap_hwmods */
3471 static LIST_HEAD(omap_hwmod_list);
3472diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3473index d15c7bb..b2d1f0c 100644
3474--- a/arch/arm/mach-omap2/wd_timer.c
3475+++ b/arch/arm/mach-omap2/wd_timer.c
3476@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3477 struct omap_hwmod *oh;
3478 char *oh_name = "wd_timer2";
3479 char *dev_name = "omap_wdt";
3480- struct omap_wd_timer_platform_data pdata;
3481+ static struct omap_wd_timer_platform_data pdata = {
3482+ .read_reset_sources = prm_read_reset_sources
3483+ };
3484
3485 if (!cpu_class_is_omap2() || of_have_populated_dt())
3486 return 0;
3487@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3488 return -EINVAL;
3489 }
3490
3491- pdata.read_reset_sources = prm_read_reset_sources;
3492-
3493 pdev = omap_device_build(dev_name, id, oh, &pdata,
3494 sizeof(struct omap_wd_timer_platform_data));
3495 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3496diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3497index 0cdba8d..297993e 100644
3498--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3499+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3500@@ -181,7 +181,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3501 bool entered_lp2 = false;
3502
3503 if (tegra_pending_sgi())
3504- ACCESS_ONCE(abort_flag) = true;
3505+ ACCESS_ONCE_RW(abort_flag) = true;
3506
3507 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3508
3509diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3510index cad3ca86..1d79e0f 100644
3511--- a/arch/arm/mach-ux500/setup.h
3512+++ b/arch/arm/mach-ux500/setup.h
3513@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3514 .type = MT_DEVICE, \
3515 }
3516
3517-#define __MEM_DEV_DESC(x, sz) { \
3518- .virtual = IO_ADDRESS(x), \
3519- .pfn = __phys_to_pfn(x), \
3520- .length = sz, \
3521- .type = MT_MEMORY, \
3522-}
3523-
3524 extern struct smp_operations ux500_smp_ops;
3525 extern void ux500_cpu_die(unsigned int cpu);
3526
3527diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3528index 35955b5..b475042 100644
3529--- a/arch/arm/mm/Kconfig
3530+++ b/arch/arm/mm/Kconfig
3531@@ -432,7 +432,7 @@ config CPU_32v5
3532
3533 config CPU_32v6
3534 bool
3535- select CPU_USE_DOMAINS if CPU_V6 && MMU
3536+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3537 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3538
3539 config CPU_32v6K
3540@@ -581,6 +581,7 @@ config CPU_CP15_MPU
3541
3542 config CPU_USE_DOMAINS
3543 bool
3544+ depends on !ARM_LPAE && !PAX_KERNEXEC
3545 help
3546 This option enables or disables the use of domain switching
3547 via the set_fs() function.
3548diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3549index 6f4585b..7b6f52b 100644
3550--- a/arch/arm/mm/alignment.c
3551+++ b/arch/arm/mm/alignment.c
3552@@ -211,10 +211,12 @@ union offset_union {
3553 #define __get16_unaligned_check(ins,val,addr) \
3554 do { \
3555 unsigned int err = 0, v, a = addr; \
3556+ pax_open_userland(); \
3557 __get8_unaligned_check(ins,v,a,err); \
3558 val = v << ((BE) ? 8 : 0); \
3559 __get8_unaligned_check(ins,v,a,err); \
3560 val |= v << ((BE) ? 0 : 8); \
3561+ pax_close_userland(); \
3562 if (err) \
3563 goto fault; \
3564 } while (0)
3565@@ -228,6 +230,7 @@ union offset_union {
3566 #define __get32_unaligned_check(ins,val,addr) \
3567 do { \
3568 unsigned int err = 0, v, a = addr; \
3569+ pax_open_userland(); \
3570 __get8_unaligned_check(ins,v,a,err); \
3571 val = v << ((BE) ? 24 : 0); \
3572 __get8_unaligned_check(ins,v,a,err); \
3573@@ -236,6 +239,7 @@ union offset_union {
3574 val |= v << ((BE) ? 8 : 16); \
3575 __get8_unaligned_check(ins,v,a,err); \
3576 val |= v << ((BE) ? 0 : 24); \
3577+ pax_close_userland(); \
3578 if (err) \
3579 goto fault; \
3580 } while (0)
3581@@ -249,6 +253,7 @@ union offset_union {
3582 #define __put16_unaligned_check(ins,val,addr) \
3583 do { \
3584 unsigned int err = 0, v = val, a = addr; \
3585+ pax_open_userland(); \
3586 __asm__( FIRST_BYTE_16 \
3587 ARM( "1: "ins" %1, [%2], #1\n" ) \
3588 THUMB( "1: "ins" %1, [%2]\n" ) \
3589@@ -268,6 +273,7 @@ union offset_union {
3590 " .popsection\n" \
3591 : "=r" (err), "=&r" (v), "=&r" (a) \
3592 : "0" (err), "1" (v), "2" (a)); \
3593+ pax_close_userland(); \
3594 if (err) \
3595 goto fault; \
3596 } while (0)
3597@@ -281,6 +287,7 @@ union offset_union {
3598 #define __put32_unaligned_check(ins,val,addr) \
3599 do { \
3600 unsigned int err = 0, v = val, a = addr; \
3601+ pax_open_userland(); \
3602 __asm__( FIRST_BYTE_32 \
3603 ARM( "1: "ins" %1, [%2], #1\n" ) \
3604 THUMB( "1: "ins" %1, [%2]\n" ) \
3605@@ -310,6 +317,7 @@ union offset_union {
3606 " .popsection\n" \
3607 : "=r" (err), "=&r" (v), "=&r" (a) \
3608 : "0" (err), "1" (v), "2" (a)); \
3609+ pax_close_userland(); \
3610 if (err) \
3611 goto fault; \
3612 } while (0)
3613diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3614index 5dbf13f..1a60561 100644
3615--- a/arch/arm/mm/fault.c
3616+++ b/arch/arm/mm/fault.c
3617@@ -25,6 +25,7 @@
3618 #include <asm/system_misc.h>
3619 #include <asm/system_info.h>
3620 #include <asm/tlbflush.h>
3621+#include <asm/sections.h>
3622
3623 #include "fault.h"
3624
3625@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3626 if (fixup_exception(regs))
3627 return;
3628
3629+#ifdef CONFIG_PAX_KERNEXEC
3630+ if ((fsr & FSR_WRITE) &&
3631+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3632+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3633+ {
3634+ if (current->signal->curr_ip)
3635+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3636+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3637+ else
3638+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3639+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3640+ }
3641+#endif
3642+
3643 /*
3644 * No handler, we'll have to terminate things with extreme prejudice.
3645 */
3646@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3647 }
3648 #endif
3649
3650+#ifdef CONFIG_PAX_PAGEEXEC
3651+ if (fsr & FSR_LNX_PF) {
3652+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3653+ do_group_exit(SIGKILL);
3654+ }
3655+#endif
3656+
3657 tsk->thread.address = addr;
3658 tsk->thread.error_code = fsr;
3659 tsk->thread.trap_no = 14;
3660@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3661 }
3662 #endif /* CONFIG_MMU */
3663
3664+#ifdef CONFIG_PAX_PAGEEXEC
3665+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3666+{
3667+ long i;
3668+
3669+ printk(KERN_ERR "PAX: bytes at PC: ");
3670+ for (i = 0; i < 20; i++) {
3671+ unsigned char c;
3672+ if (get_user(c, (__force unsigned char __user *)pc+i))
3673+ printk(KERN_CONT "?? ");
3674+ else
3675+ printk(KERN_CONT "%02x ", c);
3676+ }
3677+ printk("\n");
3678+
3679+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3680+ for (i = -1; i < 20; i++) {
3681+ unsigned long c;
3682+ if (get_user(c, (__force unsigned long __user *)sp+i))
3683+ printk(KERN_CONT "???????? ");
3684+ else
3685+ printk(KERN_CONT "%08lx ", c);
3686+ }
3687+ printk("\n");
3688+}
3689+#endif
3690+
3691 /*
3692 * First Level Translation Fault Handler
3693 *
3694@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3695 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3696 struct siginfo info;
3697
3698+#ifdef CONFIG_PAX_MEMORY_UDEREF
3699+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3700+ if (current->signal->curr_ip)
3701+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3702+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3703+ else
3704+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3705+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3706+ goto die;
3707+ }
3708+#endif
3709+
3710 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3711 return;
3712
3713+die:
3714 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3715 inf->name, fsr, addr);
3716
3717@@ -575,9 +637,49 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3718 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3719 struct siginfo info;
3720
3721+ if (user_mode(regs)) {
3722+ if (addr == 0xffff0fe0UL) {
3723+ /*
3724+ * PaX: __kuser_get_tls emulation
3725+ */
3726+ regs->ARM_r0 = current_thread_info()->tp_value;
3727+ regs->ARM_pc = regs->ARM_lr;
3728+ return;
3729+ }
3730+ }
3731+
3732+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3733+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3734+ if (current->signal->curr_ip)
3735+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3736+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3737+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3738+ else
3739+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3740+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3741+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3742+ goto die;
3743+ }
3744+#endif
3745+
3746+#ifdef CONFIG_PAX_REFCOUNT
3747+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3748+ unsigned int bkpt;
3749+
3750+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3751+ current->thread.error_code = ifsr;
3752+ current->thread.trap_no = 0;
3753+ pax_report_refcount_overflow(regs);
3754+ fixup_exception(regs);
3755+ return;
3756+ }
3757+ }
3758+#endif
3759+
3760 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3761 return;
3762
3763+die:
3764 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3765 inf->name, ifsr, addr);
3766
3767diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3768index cf08bdf..772656c 100644
3769--- a/arch/arm/mm/fault.h
3770+++ b/arch/arm/mm/fault.h
3771@@ -3,6 +3,7 @@
3772
3773 /*
3774 * Fault status register encodings. We steal bit 31 for our own purposes.
3775+ * Set when the FSR value is from an instruction fault.
3776 */
3777 #define FSR_LNX_PF (1 << 31)
3778 #define FSR_WRITE (1 << 11)
3779@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3780 }
3781 #endif
3782
3783+/* valid for LPAE and !LPAE */
3784+static inline int is_xn_fault(unsigned int fsr)
3785+{
3786+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3787+}
3788+
3789+static inline int is_domain_fault(unsigned int fsr)
3790+{
3791+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3792+}
3793+
3794 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3795 unsigned long search_exception_table(unsigned long addr);
3796
3797diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3798index 9a5cdc0..a1182cf 100644
3799--- a/arch/arm/mm/init.c
3800+++ b/arch/arm/mm/init.c
3801@@ -30,6 +30,8 @@
3802 #include <asm/setup.h>
3803 #include <asm/tlb.h>
3804 #include <asm/fixmap.h>
3805+#include <asm/system_info.h>
3806+#include <asm/cp15.h>
3807
3808 #include <asm/mach/arch.h>
3809 #include <asm/mach/map.h>
3810@@ -726,7 +728,46 @@ void free_initmem(void)
3811 {
3812 #ifdef CONFIG_HAVE_TCM
3813 extern char __tcm_start, __tcm_end;
3814+#endif
3815
3816+#ifdef CONFIG_PAX_KERNEXEC
3817+ unsigned long addr;
3818+ pgd_t *pgd;
3819+ pud_t *pud;
3820+ pmd_t *pmd;
3821+ int cpu_arch = cpu_architecture();
3822+ unsigned int cr = get_cr();
3823+
3824+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3825+ /* make pages tables, etc before .text NX */
3826+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3827+ pgd = pgd_offset_k(addr);
3828+ pud = pud_offset(pgd, addr);
3829+ pmd = pmd_offset(pud, addr);
3830+ __section_update(pmd, addr, PMD_SECT_XN);
3831+ }
3832+ /* make init NX */
3833+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3834+ pgd = pgd_offset_k(addr);
3835+ pud = pud_offset(pgd, addr);
3836+ pmd = pmd_offset(pud, addr);
3837+ __section_update(pmd, addr, PMD_SECT_XN);
3838+ }
3839+ /* make kernel code/rodata RX */
3840+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3841+ pgd = pgd_offset_k(addr);
3842+ pud = pud_offset(pgd, addr);
3843+ pmd = pmd_offset(pud, addr);
3844+#ifdef CONFIG_ARM_LPAE
3845+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3846+#else
3847+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3848+#endif
3849+ }
3850+ }
3851+#endif
3852+
3853+#ifdef CONFIG_HAVE_TCM
3854 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3855 free_reserved_area(&__tcm_start, &__tcm_end, 0, "TCM link");
3856 #endif
3857diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3858index 04d9006..c547d85 100644
3859--- a/arch/arm/mm/ioremap.c
3860+++ b/arch/arm/mm/ioremap.c
3861@@ -392,9 +392,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3862 unsigned int mtype;
3863
3864 if (cached)
3865- mtype = MT_MEMORY;
3866+ mtype = MT_MEMORY_RX;
3867 else
3868- mtype = MT_MEMORY_NONCACHED;
3869+ mtype = MT_MEMORY_NONCACHED_RX;
3870
3871 return __arm_ioremap_caller(phys_addr, size, mtype,
3872 __builtin_return_address(0));
3873diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3874index 10062ce..8695745 100644
3875--- a/arch/arm/mm/mmap.c
3876+++ b/arch/arm/mm/mmap.c
3877@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3878 struct vm_area_struct *vma;
3879 int do_align = 0;
3880 int aliasing = cache_is_vipt_aliasing();
3881+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3882 struct vm_unmapped_area_info info;
3883
3884 /*
3885@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3886 if (len > TASK_SIZE)
3887 return -ENOMEM;
3888
3889+#ifdef CONFIG_PAX_RANDMMAP
3890+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3891+#endif
3892+
3893 if (addr) {
3894 if (do_align)
3895 addr = COLOUR_ALIGN(addr, pgoff);
3896@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3897 addr = PAGE_ALIGN(addr);
3898
3899 vma = find_vma(mm, addr);
3900- if (TASK_SIZE - len >= addr &&
3901- (!vma || addr + len <= vma->vm_start))
3902+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3903 return addr;
3904 }
3905
3906@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3907 info.high_limit = TASK_SIZE;
3908 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3909 info.align_offset = pgoff << PAGE_SHIFT;
3910+ info.threadstack_offset = offset;
3911 return vm_unmapped_area(&info);
3912 }
3913
3914@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3915 unsigned long addr = addr0;
3916 int do_align = 0;
3917 int aliasing = cache_is_vipt_aliasing();
3918+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3919 struct vm_unmapped_area_info info;
3920
3921 /*
3922@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3923 return addr;
3924 }
3925
3926+#ifdef CONFIG_PAX_RANDMMAP
3927+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3928+#endif
3929+
3930 /* requesting a specific address */
3931 if (addr) {
3932 if (do_align)
3933@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3934 else
3935 addr = PAGE_ALIGN(addr);
3936 vma = find_vma(mm, addr);
3937- if (TASK_SIZE - len >= addr &&
3938- (!vma || addr + len <= vma->vm_start))
3939+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3940 return addr;
3941 }
3942
3943@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3944 info.high_limit = mm->mmap_base;
3945 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3946 info.align_offset = pgoff << PAGE_SHIFT;
3947+ info.threadstack_offset = offset;
3948 addr = vm_unmapped_area(&info);
3949
3950 /*
3951@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3952 {
3953 unsigned long random_factor = 0UL;
3954
3955+#ifdef CONFIG_PAX_RANDMMAP
3956+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3957+#endif
3958+
3959 /* 8 bits of randomness in 20 address space bits */
3960 if ((current->flags & PF_RANDOMIZE) &&
3961 !(current->personality & ADDR_NO_RANDOMIZE))
3962@@ -180,10 +194,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3963
3964 if (mmap_is_legacy()) {
3965 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3966+
3967+#ifdef CONFIG_PAX_RANDMMAP
3968+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3969+ mm->mmap_base += mm->delta_mmap;
3970+#endif
3971+
3972 mm->get_unmapped_area = arch_get_unmapped_area;
3973 mm->unmap_area = arch_unmap_area;
3974 } else {
3975 mm->mmap_base = mmap_base(random_factor);
3976+
3977+#ifdef CONFIG_PAX_RANDMMAP
3978+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3979+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3980+#endif
3981+
3982 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3983 mm->unmap_area = arch_unmap_area_topdown;
3984 }
3985diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3986index 4d409e6..0193da8 100644
3987--- a/arch/arm/mm/mmu.c
3988+++ b/arch/arm/mm/mmu.c
3989@@ -36,6 +36,22 @@
3990 #include "mm.h"
3991 #include "tcm.h"
3992
3993+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3994+void modify_domain(unsigned int dom, unsigned int type)
3995+{
3996+ struct thread_info *thread = current_thread_info();
3997+ unsigned int domain = thread->cpu_domain;
3998+ /*
3999+ * DOMAIN_MANAGER might be defined to some other value,
4000+ * use the arch-defined constant
4001+ */
4002+ domain &= ~domain_val(dom, 3);
4003+ thread->cpu_domain = domain | domain_val(dom, type);
4004+ set_domain(thread->cpu_domain);
4005+}
4006+EXPORT_SYMBOL(modify_domain);
4007+#endif
4008+
4009 /*
4010 * empty_zero_page is a special page that is used for
4011 * zero-initialized data and COW.
4012@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4013
4014 #endif /* ifdef CONFIG_CPU_CP15 / else */
4015
4016-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4017+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4018 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4019
4020-static struct mem_type mem_types[] = {
4021+#ifdef CONFIG_PAX_KERNEXEC
4022+#define L_PTE_KERNEXEC L_PTE_RDONLY
4023+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4024+#else
4025+#define L_PTE_KERNEXEC L_PTE_DIRTY
4026+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4027+#endif
4028+
4029+static struct mem_type mem_types[] __read_only = {
4030 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4031 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4032 L_PTE_SHARED,
4033@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4034 [MT_UNCACHED] = {
4035 .prot_pte = PROT_PTE_DEVICE,
4036 .prot_l1 = PMD_TYPE_TABLE,
4037- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4038+ .prot_sect = PROT_SECT_DEVICE,
4039 .domain = DOMAIN_IO,
4040 },
4041 [MT_CACHECLEAN] = {
4042- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4043+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4044 .domain = DOMAIN_KERNEL,
4045 },
4046 #ifndef CONFIG_ARM_LPAE
4047 [MT_MINICLEAN] = {
4048- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4049+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4050 .domain = DOMAIN_KERNEL,
4051 },
4052 #endif
4053@@ -277,36 +301,62 @@ static struct mem_type mem_types[] = {
4054 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4055 L_PTE_RDONLY,
4056 .prot_l1 = PMD_TYPE_TABLE,
4057- .domain = DOMAIN_USER,
4058+ .domain = DOMAIN_VECTORS,
4059 },
4060 [MT_HIGH_VECTORS] = {
4061- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4062- L_PTE_USER | L_PTE_RDONLY,
4063+ /* we always want the vector page to be noaccess for userland
4064+ therefore, when kernexec is disabled, instead of L_PTE_USER | L_PTE_RDONLY
4065+ which turns into supervisor rwx, userland rx, we instead omit that entirely,
4066+ leaving it as supervisor rwx only
4067+ */
4068+#ifdef CONFIG_PAX_KERNEXEC
4069+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_RDONLY,
4070+#else
4071+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4072+#endif
4073 .prot_l1 = PMD_TYPE_TABLE,
4074- .domain = DOMAIN_USER,
4075+ .domain = DOMAIN_VECTORS,
4076 },
4077- [MT_MEMORY] = {
4078+ [MT_MEMORY_RWX] = {
4079 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4080 .prot_l1 = PMD_TYPE_TABLE,
4081 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4082 .domain = DOMAIN_KERNEL,
4083 },
4084+ [MT_MEMORY_RW] = {
4085+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4086+ .prot_l1 = PMD_TYPE_TABLE,
4087+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4088+ .domain = DOMAIN_KERNEL,
4089+ },
4090+ [MT_MEMORY_RX] = {
4091+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4092+ .prot_l1 = PMD_TYPE_TABLE,
4093+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4094+ .domain = DOMAIN_KERNEL,
4095+ },
4096 [MT_ROM] = {
4097- .prot_sect = PMD_TYPE_SECT,
4098+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4099 .domain = DOMAIN_KERNEL,
4100 },
4101- [MT_MEMORY_NONCACHED] = {
4102+ [MT_MEMORY_NONCACHED_RW] = {
4103 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4104 L_PTE_MT_BUFFERABLE,
4105 .prot_l1 = PMD_TYPE_TABLE,
4106 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4107 .domain = DOMAIN_KERNEL,
4108 },
4109+ [MT_MEMORY_NONCACHED_RX] = {
4110+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4111+ L_PTE_MT_BUFFERABLE,
4112+ .prot_l1 = PMD_TYPE_TABLE,
4113+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4114+ .domain = DOMAIN_KERNEL,
4115+ },
4116 [MT_MEMORY_DTCM] = {
4117- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4118- L_PTE_XN,
4119+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4120 .prot_l1 = PMD_TYPE_TABLE,
4121- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4122+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4123 .domain = DOMAIN_KERNEL,
4124 },
4125 [MT_MEMORY_ITCM] = {
4126@@ -316,10 +366,10 @@ static struct mem_type mem_types[] = {
4127 },
4128 [MT_MEMORY_SO] = {
4129 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4130- L_PTE_MT_UNCACHED | L_PTE_XN,
4131+ L_PTE_MT_UNCACHED,
4132 .prot_l1 = PMD_TYPE_TABLE,
4133 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4134- PMD_SECT_UNCACHED | PMD_SECT_XN,
4135+ PMD_SECT_UNCACHED,
4136 .domain = DOMAIN_KERNEL,
4137 },
4138 [MT_MEMORY_DMA_READY] = {
4139@@ -405,9 +455,35 @@ static void __init build_mem_type_table(void)
4140 * to prevent speculative instruction fetches.
4141 */
4142 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4143+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4144 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4145+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4146 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4147+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4148 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4149+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4150+
4151+ /* Mark other regions on ARMv6+ as execute-never */
4152+
4153+#ifdef CONFIG_PAX_KERNEXEC
4154+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4155+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4156+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4157+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4158+#ifndef CONFIG_ARM_LPAE
4159+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4160+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4161+#endif
4162+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4163+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4164+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4165+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4166+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4167+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4168+#endif
4169+
4170+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4171+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4172 }
4173 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4174 /*
4175@@ -468,6 +544,9 @@ static void __init build_mem_type_table(void)
4176 * from SVC mode and no access from userspace.
4177 */
4178 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4179+#ifdef CONFIG_PAX_KERNEXEC
4180+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4181+#endif
4182 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4183 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4184 #endif
4185@@ -485,11 +564,17 @@ static void __init build_mem_type_table(void)
4186 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4187 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4188 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4189- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4190- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4191+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4192+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4193+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4194+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4195+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4196+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4197 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4198- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4199- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4200+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4201+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4202+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4203+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4204 }
4205 }
4206
4207@@ -500,15 +585,20 @@ static void __init build_mem_type_table(void)
4208 if (cpu_arch >= CPU_ARCH_ARMv6) {
4209 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4210 /* Non-cacheable Normal is XCB = 001 */
4211- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4212+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4213+ PMD_SECT_BUFFERED;
4214+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4215 PMD_SECT_BUFFERED;
4216 } else {
4217 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4218- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4219+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4220+ PMD_SECT_TEX(1);
4221+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4222 PMD_SECT_TEX(1);
4223 }
4224 } else {
4225- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4226+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4227+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4228 }
4229
4230 #ifdef CONFIG_ARM_LPAE
4231@@ -524,6 +614,8 @@ static void __init build_mem_type_table(void)
4232 vecs_pgprot |= PTE_EXT_AF;
4233 #endif
4234
4235+ user_pgprot |= __supported_pte_mask;
4236+
4237 for (i = 0; i < 16; i++) {
4238 pteval_t v = pgprot_val(protection_map[i]);
4239 protection_map[i] = __pgprot(v | user_pgprot);
4240@@ -541,10 +633,15 @@ static void __init build_mem_type_table(void)
4241
4242 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4243 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4244- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4245- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4246+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4247+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4248+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4249+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4250+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4251+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4252 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4253- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4254+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4255+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4256 mem_types[MT_ROM].prot_sect |= cp->pmd;
4257
4258 switch (cp->pmd) {
4259@@ -1166,18 +1263,15 @@ void __init arm_mm_memblock_reserve(void)
4260 * called function. This means you can't use any function or debugging
4261 * method which may touch any device, otherwise the kernel _will_ crash.
4262 */
4263+
4264+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4265+
4266 static void __init devicemaps_init(struct machine_desc *mdesc)
4267 {
4268 struct map_desc map;
4269 unsigned long addr;
4270- void *vectors;
4271
4272- /*
4273- * Allocate the vector page early.
4274- */
4275- vectors = early_alloc(PAGE_SIZE);
4276-
4277- early_trap_init(vectors);
4278+ early_trap_init(&vectors);
4279
4280 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4281 pmd_clear(pmd_off_k(addr));
4282@@ -1217,7 +1311,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4283 * location (0xffff0000). If we aren't using high-vectors, also
4284 * create a mapping at the low-vectors virtual address.
4285 */
4286- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4287+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4288 map.virtual = 0xffff0000;
4289 map.length = PAGE_SIZE;
4290 map.type = MT_HIGH_VECTORS;
4291@@ -1275,8 +1369,39 @@ static void __init map_lowmem(void)
4292 map.pfn = __phys_to_pfn(start);
4293 map.virtual = __phys_to_virt(start);
4294 map.length = end - start;
4295- map.type = MT_MEMORY;
4296
4297+#ifdef CONFIG_PAX_KERNEXEC
4298+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4299+ struct map_desc kernel;
4300+ struct map_desc initmap;
4301+
4302+ /* when freeing initmem we will make this RW */
4303+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4304+ initmap.virtual = (unsigned long)__init_begin;
4305+ initmap.length = _sdata - __init_begin;
4306+ initmap.type = MT_MEMORY_RWX;
4307+ create_mapping(&initmap);
4308+
4309+ /* when freeing initmem we will make this RX */
4310+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4311+ kernel.virtual = (unsigned long)_stext;
4312+ kernel.length = __init_begin - _stext;
4313+ kernel.type = MT_MEMORY_RWX;
4314+ create_mapping(&kernel);
4315+
4316+ if (map.virtual < (unsigned long)_stext) {
4317+ map.length = (unsigned long)_stext - map.virtual;
4318+ map.type = MT_MEMORY_RWX;
4319+ create_mapping(&map);
4320+ }
4321+
4322+ map.pfn = __phys_to_pfn(__pa(_sdata));
4323+ map.virtual = (unsigned long)_sdata;
4324+ map.length = end - __pa(_sdata);
4325+ }
4326+#endif
4327+
4328+ map.type = MT_MEMORY_RW;
4329 create_mapping(&map);
4330 }
4331 }
4332diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4333index 9704097..3e36dde 100644
4334--- a/arch/arm/mm/proc-v7-2level.S
4335+++ b/arch/arm/mm/proc-v7-2level.S
4336@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4337 tst r1, #L_PTE_XN
4338 orrne r3, r3, #PTE_EXT_XN
4339
4340+ tst r1, #L_PTE_PXN
4341+ orrne r3, r3, #PTE_EXT_PXN
4342+
4343 tst r1, #L_PTE_YOUNG
4344 tstne r1, #L_PTE_VALID
4345 #ifndef CONFIG_CPU_USE_DOMAINS
4346diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4347index a5bc92d..0bb4730 100644
4348--- a/arch/arm/plat-omap/sram.c
4349+++ b/arch/arm/plat-omap/sram.c
4350@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4351 * Looks like we need to preserve some bootloader code at the
4352 * beginning of SRAM for jumping to flash for reboot to work...
4353 */
4354+ pax_open_kernel();
4355 memset_io(omap_sram_base + omap_sram_skip, 0,
4356 omap_sram_size - omap_sram_skip);
4357+ pax_close_kernel();
4358 }
4359diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4360index ce6d763..cfea917 100644
4361--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4362+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4363@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4364 int (*started)(unsigned ch);
4365 int (*flush)(unsigned ch);
4366 int (*stop)(unsigned ch);
4367-};
4368+} __no_const;
4369
4370 extern void *samsung_dmadev_get_ops(void);
4371 extern void *s3c_dma_get_ops(void);
4372diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4373index f4726dc..39ed646 100644
4374--- a/arch/arm64/kernel/debug-monitors.c
4375+++ b/arch/arm64/kernel/debug-monitors.c
4376@@ -149,7 +149,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4377 return NOTIFY_OK;
4378 }
4379
4380-static struct notifier_block __cpuinitdata os_lock_nb = {
4381+static struct notifier_block os_lock_nb = {
4382 .notifier_call = os_lock_notify,
4383 };
4384
4385diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4386index 5ab825c..96aaec8 100644
4387--- a/arch/arm64/kernel/hw_breakpoint.c
4388+++ b/arch/arm64/kernel/hw_breakpoint.c
4389@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4390 return NOTIFY_OK;
4391 }
4392
4393-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4394+static struct notifier_block hw_breakpoint_reset_nb = {
4395 .notifier_call = hw_breakpoint_reset_notify,
4396 };
4397
4398diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4399index c3a58a1..78fbf54 100644
4400--- a/arch/avr32/include/asm/cache.h
4401+++ b/arch/avr32/include/asm/cache.h
4402@@ -1,8 +1,10 @@
4403 #ifndef __ASM_AVR32_CACHE_H
4404 #define __ASM_AVR32_CACHE_H
4405
4406+#include <linux/const.h>
4407+
4408 #define L1_CACHE_SHIFT 5
4409-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4410+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4411
4412 /*
4413 * Memory returned by kmalloc() may be used for DMA, so we must make
4414diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4415index d232888..87c8df1 100644
4416--- a/arch/avr32/include/asm/elf.h
4417+++ b/arch/avr32/include/asm/elf.h
4418@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4419 the loader. We need to make sure that it is out of the way of the program
4420 that it will "exec", and that there is sufficient room for the brk. */
4421
4422-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4423+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4424
4425+#ifdef CONFIG_PAX_ASLR
4426+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4427+
4428+#define PAX_DELTA_MMAP_LEN 15
4429+#define PAX_DELTA_STACK_LEN 15
4430+#endif
4431
4432 /* This yields a mask that user programs can use to figure out what
4433 instruction set this CPU supports. This could be done in user space,
4434diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4435index 479330b..53717a8 100644
4436--- a/arch/avr32/include/asm/kmap_types.h
4437+++ b/arch/avr32/include/asm/kmap_types.h
4438@@ -2,9 +2,9 @@
4439 #define __ASM_AVR32_KMAP_TYPES_H
4440
4441 #ifdef CONFIG_DEBUG_HIGHMEM
4442-# define KM_TYPE_NR 29
4443+# define KM_TYPE_NR 30
4444 #else
4445-# define KM_TYPE_NR 14
4446+# define KM_TYPE_NR 15
4447 #endif
4448
4449 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4450diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4451index b2f2d2d..d1c85cb 100644
4452--- a/arch/avr32/mm/fault.c
4453+++ b/arch/avr32/mm/fault.c
4454@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4455
4456 int exception_trace = 1;
4457
4458+#ifdef CONFIG_PAX_PAGEEXEC
4459+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4460+{
4461+ unsigned long i;
4462+
4463+ printk(KERN_ERR "PAX: bytes at PC: ");
4464+ for (i = 0; i < 20; i++) {
4465+ unsigned char c;
4466+ if (get_user(c, (unsigned char *)pc+i))
4467+ printk(KERN_CONT "???????? ");
4468+ else
4469+ printk(KERN_CONT "%02x ", c);
4470+ }
4471+ printk("\n");
4472+}
4473+#endif
4474+
4475 /*
4476 * This routine handles page faults. It determines the address and the
4477 * problem, and then passes it off to one of the appropriate routines.
4478@@ -174,6 +191,16 @@ bad_area:
4479 up_read(&mm->mmap_sem);
4480
4481 if (user_mode(regs)) {
4482+
4483+#ifdef CONFIG_PAX_PAGEEXEC
4484+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4485+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4486+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4487+ do_group_exit(SIGKILL);
4488+ }
4489+ }
4490+#endif
4491+
4492 if (exception_trace && printk_ratelimit())
4493 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4494 "sp %08lx ecr %lu\n",
4495diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4496index 568885a..f8008df 100644
4497--- a/arch/blackfin/include/asm/cache.h
4498+++ b/arch/blackfin/include/asm/cache.h
4499@@ -7,6 +7,7 @@
4500 #ifndef __ARCH_BLACKFIN_CACHE_H
4501 #define __ARCH_BLACKFIN_CACHE_H
4502
4503+#include <linux/const.h>
4504 #include <linux/linkage.h> /* for asmlinkage */
4505
4506 /*
4507@@ -14,7 +15,7 @@
4508 * Blackfin loads 32 bytes for cache
4509 */
4510 #define L1_CACHE_SHIFT 5
4511-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4512+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4513 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4514
4515 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4516diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4517index aea2718..3639a60 100644
4518--- a/arch/cris/include/arch-v10/arch/cache.h
4519+++ b/arch/cris/include/arch-v10/arch/cache.h
4520@@ -1,8 +1,9 @@
4521 #ifndef _ASM_ARCH_CACHE_H
4522 #define _ASM_ARCH_CACHE_H
4523
4524+#include <linux/const.h>
4525 /* Etrax 100LX have 32-byte cache-lines. */
4526-#define L1_CACHE_BYTES 32
4527 #define L1_CACHE_SHIFT 5
4528+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4529
4530 #endif /* _ASM_ARCH_CACHE_H */
4531diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4532index 7caf25d..ee65ac5 100644
4533--- a/arch/cris/include/arch-v32/arch/cache.h
4534+++ b/arch/cris/include/arch-v32/arch/cache.h
4535@@ -1,11 +1,12 @@
4536 #ifndef _ASM_CRIS_ARCH_CACHE_H
4537 #define _ASM_CRIS_ARCH_CACHE_H
4538
4539+#include <linux/const.h>
4540 #include <arch/hwregs/dma.h>
4541
4542 /* A cache-line is 32 bytes. */
4543-#define L1_CACHE_BYTES 32
4544 #define L1_CACHE_SHIFT 5
4545+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4546
4547 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4548
4549diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4550index b86329d..6709906 100644
4551--- a/arch/frv/include/asm/atomic.h
4552+++ b/arch/frv/include/asm/atomic.h
4553@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4554 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4555 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4556
4557+#define atomic64_read_unchecked(v) atomic64_read(v)
4558+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4559+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4560+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4561+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4562+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4563+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4564+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4565+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4566+
4567 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4568 {
4569 int c, old;
4570diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4571index 2797163..c2a401d 100644
4572--- a/arch/frv/include/asm/cache.h
4573+++ b/arch/frv/include/asm/cache.h
4574@@ -12,10 +12,11 @@
4575 #ifndef __ASM_CACHE_H
4576 #define __ASM_CACHE_H
4577
4578+#include <linux/const.h>
4579
4580 /* bytes per L1 cache line */
4581 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4582-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4583+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4584
4585 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4586 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4587diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4588index 43901f2..0d8b865 100644
4589--- a/arch/frv/include/asm/kmap_types.h
4590+++ b/arch/frv/include/asm/kmap_types.h
4591@@ -2,6 +2,6 @@
4592 #ifndef _ASM_KMAP_TYPES_H
4593 #define _ASM_KMAP_TYPES_H
4594
4595-#define KM_TYPE_NR 17
4596+#define KM_TYPE_NR 18
4597
4598 #endif
4599diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4600index 836f147..4cf23f5 100644
4601--- a/arch/frv/mm/elf-fdpic.c
4602+++ b/arch/frv/mm/elf-fdpic.c
4603@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4604 {
4605 struct vm_area_struct *vma;
4606 struct vm_unmapped_area_info info;
4607+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4608
4609 if (len > TASK_SIZE)
4610 return -ENOMEM;
4611@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4612 if (addr) {
4613 addr = PAGE_ALIGN(addr);
4614 vma = find_vma(current->mm, addr);
4615- if (TASK_SIZE - len >= addr &&
4616- (!vma || addr + len <= vma->vm_start))
4617+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4618 goto success;
4619 }
4620
4621@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4622 info.high_limit = (current->mm->start_stack - 0x00200000);
4623 info.align_mask = 0;
4624 info.align_offset = 0;
4625+ info.threadstack_offset = offset;
4626 addr = vm_unmapped_area(&info);
4627 if (!(addr & ~PAGE_MASK))
4628 goto success;
4629diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4630index f4ca594..adc72fd6 100644
4631--- a/arch/hexagon/include/asm/cache.h
4632+++ b/arch/hexagon/include/asm/cache.h
4633@@ -21,9 +21,11 @@
4634 #ifndef __ASM_CACHE_H
4635 #define __ASM_CACHE_H
4636
4637+#include <linux/const.h>
4638+
4639 /* Bytes per L1 cache line */
4640-#define L1_CACHE_SHIFT (5)
4641-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4642+#define L1_CACHE_SHIFT 5
4643+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4644
4645 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4646 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4647diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4648index 6e6fe18..a6ae668 100644
4649--- a/arch/ia64/include/asm/atomic.h
4650+++ b/arch/ia64/include/asm/atomic.h
4651@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4652 #define atomic64_inc(v) atomic64_add(1, (v))
4653 #define atomic64_dec(v) atomic64_sub(1, (v))
4654
4655+#define atomic64_read_unchecked(v) atomic64_read(v)
4656+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4657+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4658+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4659+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4660+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4661+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4662+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4663+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4664+
4665 /* Atomic operations are already serializing */
4666 #define smp_mb__before_atomic_dec() barrier()
4667 #define smp_mb__after_atomic_dec() barrier()
4668diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4669index 988254a..e1ee885 100644
4670--- a/arch/ia64/include/asm/cache.h
4671+++ b/arch/ia64/include/asm/cache.h
4672@@ -1,6 +1,7 @@
4673 #ifndef _ASM_IA64_CACHE_H
4674 #define _ASM_IA64_CACHE_H
4675
4676+#include <linux/const.h>
4677
4678 /*
4679 * Copyright (C) 1998-2000 Hewlett-Packard Co
4680@@ -9,7 +10,7 @@
4681
4682 /* Bytes per L1 (data) cache line. */
4683 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4684-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4685+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4686
4687 #ifdef CONFIG_SMP
4688 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4689diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4690index 5a83c5c..4d7f553 100644
4691--- a/arch/ia64/include/asm/elf.h
4692+++ b/arch/ia64/include/asm/elf.h
4693@@ -42,6 +42,13 @@
4694 */
4695 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4696
4697+#ifdef CONFIG_PAX_ASLR
4698+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4699+
4700+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4701+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4702+#endif
4703+
4704 #define PT_IA_64_UNWIND 0x70000001
4705
4706 /* IA-64 relocations: */
4707diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4708index 96a8d92..617a1cf 100644
4709--- a/arch/ia64/include/asm/pgalloc.h
4710+++ b/arch/ia64/include/asm/pgalloc.h
4711@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4712 pgd_val(*pgd_entry) = __pa(pud);
4713 }
4714
4715+static inline void
4716+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4717+{
4718+ pgd_populate(mm, pgd_entry, pud);
4719+}
4720+
4721 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4722 {
4723 return quicklist_alloc(0, GFP_KERNEL, NULL);
4724@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4725 pud_val(*pud_entry) = __pa(pmd);
4726 }
4727
4728+static inline void
4729+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4730+{
4731+ pud_populate(mm, pud_entry, pmd);
4732+}
4733+
4734 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4735 {
4736 return quicklist_alloc(0, GFP_KERNEL, NULL);
4737diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4738index 815810c..d60bd4c 100644
4739--- a/arch/ia64/include/asm/pgtable.h
4740+++ b/arch/ia64/include/asm/pgtable.h
4741@@ -12,7 +12,7 @@
4742 * David Mosberger-Tang <davidm@hpl.hp.com>
4743 */
4744
4745-
4746+#include <linux/const.h>
4747 #include <asm/mman.h>
4748 #include <asm/page.h>
4749 #include <asm/processor.h>
4750@@ -142,6 +142,17 @@
4751 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4752 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4753 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4754+
4755+#ifdef CONFIG_PAX_PAGEEXEC
4756+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4757+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4758+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4759+#else
4760+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4761+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4762+# define PAGE_COPY_NOEXEC PAGE_COPY
4763+#endif
4764+
4765 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4766 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4767 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4768diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4769index 54ff557..70c88b7 100644
4770--- a/arch/ia64/include/asm/spinlock.h
4771+++ b/arch/ia64/include/asm/spinlock.h
4772@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4773 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4774
4775 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4776- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4777+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4778 }
4779
4780 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4781diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4782index 449c8c0..18965fb 100644
4783--- a/arch/ia64/include/asm/uaccess.h
4784+++ b/arch/ia64/include/asm/uaccess.h
4785@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4786 static inline unsigned long
4787 __copy_to_user (void __user *to, const void *from, unsigned long count)
4788 {
4789+ if (count > INT_MAX)
4790+ return count;
4791+
4792+ if (!__builtin_constant_p(count))
4793+ check_object_size(from, count, true);
4794+
4795 return __copy_user(to, (__force void __user *) from, count);
4796 }
4797
4798 static inline unsigned long
4799 __copy_from_user (void *to, const void __user *from, unsigned long count)
4800 {
4801+ if (count > INT_MAX)
4802+ return count;
4803+
4804+ if (!__builtin_constant_p(count))
4805+ check_object_size(to, count, false);
4806+
4807 return __copy_user((__force void __user *) to, from, count);
4808 }
4809
4810@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4811 ({ \
4812 void __user *__cu_to = (to); \
4813 const void *__cu_from = (from); \
4814- long __cu_len = (n); \
4815+ unsigned long __cu_len = (n); \
4816 \
4817- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4818+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4819+ if (!__builtin_constant_p(n)) \
4820+ check_object_size(__cu_from, __cu_len, true); \
4821 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4822+ } \
4823 __cu_len; \
4824 })
4825
4826@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4827 ({ \
4828 void *__cu_to = (to); \
4829 const void __user *__cu_from = (from); \
4830- long __cu_len = (n); \
4831+ unsigned long __cu_len = (n); \
4832 \
4833 __chk_user_ptr(__cu_from); \
4834- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4835+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4836+ if (!__builtin_constant_p(n)) \
4837+ check_object_size(__cu_to, __cu_len, false); \
4838 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4839+ } \
4840 __cu_len; \
4841 })
4842
4843diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4844index 2d67317..07d8bfa 100644
4845--- a/arch/ia64/kernel/err_inject.c
4846+++ b/arch/ia64/kernel/err_inject.c
4847@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4848 return NOTIFY_OK;
4849 }
4850
4851-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4852+static struct notifier_block err_inject_cpu_notifier =
4853 {
4854 .notifier_call = err_inject_cpu_callback,
4855 };
4856diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4857index d7396db..b33e873 100644
4858--- a/arch/ia64/kernel/mca.c
4859+++ b/arch/ia64/kernel/mca.c
4860@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4861 return NOTIFY_OK;
4862 }
4863
4864-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4865+static struct notifier_block mca_cpu_notifier = {
4866 .notifier_call = mca_cpu_callback
4867 };
4868
4869diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4870index 24603be..948052d 100644
4871--- a/arch/ia64/kernel/module.c
4872+++ b/arch/ia64/kernel/module.c
4873@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4874 void
4875 module_free (struct module *mod, void *module_region)
4876 {
4877- if (mod && mod->arch.init_unw_table &&
4878- module_region == mod->module_init) {
4879+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4880 unw_remove_unwind_table(mod->arch.init_unw_table);
4881 mod->arch.init_unw_table = NULL;
4882 }
4883@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4884 }
4885
4886 static inline int
4887+in_init_rx (const struct module *mod, uint64_t addr)
4888+{
4889+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4890+}
4891+
4892+static inline int
4893+in_init_rw (const struct module *mod, uint64_t addr)
4894+{
4895+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4896+}
4897+
4898+static inline int
4899 in_init (const struct module *mod, uint64_t addr)
4900 {
4901- return addr - (uint64_t) mod->module_init < mod->init_size;
4902+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4903+}
4904+
4905+static inline int
4906+in_core_rx (const struct module *mod, uint64_t addr)
4907+{
4908+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4909+}
4910+
4911+static inline int
4912+in_core_rw (const struct module *mod, uint64_t addr)
4913+{
4914+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4915 }
4916
4917 static inline int
4918 in_core (const struct module *mod, uint64_t addr)
4919 {
4920- return addr - (uint64_t) mod->module_core < mod->core_size;
4921+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4922 }
4923
4924 static inline int
4925@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4926 break;
4927
4928 case RV_BDREL:
4929- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4930+ if (in_init_rx(mod, val))
4931+ val -= (uint64_t) mod->module_init_rx;
4932+ else if (in_init_rw(mod, val))
4933+ val -= (uint64_t) mod->module_init_rw;
4934+ else if (in_core_rx(mod, val))
4935+ val -= (uint64_t) mod->module_core_rx;
4936+ else if (in_core_rw(mod, val))
4937+ val -= (uint64_t) mod->module_core_rw;
4938 break;
4939
4940 case RV_LTV:
4941@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4942 * addresses have been selected...
4943 */
4944 uint64_t gp;
4945- if (mod->core_size > MAX_LTOFF)
4946+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4947 /*
4948 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4949 * at the end of the module.
4950 */
4951- gp = mod->core_size - MAX_LTOFF / 2;
4952+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4953 else
4954- gp = mod->core_size / 2;
4955- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4956+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4957+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4958 mod->arch.gp = gp;
4959 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4960 }
4961diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4962index 2b3c2d7..a318d84 100644
4963--- a/arch/ia64/kernel/palinfo.c
4964+++ b/arch/ia64/kernel/palinfo.c
4965@@ -980,7 +980,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4966 return NOTIFY_OK;
4967 }
4968
4969-static struct notifier_block __refdata palinfo_cpu_notifier =
4970+static struct notifier_block palinfo_cpu_notifier =
4971 {
4972 .notifier_call = palinfo_cpu_callback,
4973 .priority = 0,
4974diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4975index 4bc580a..7767f24 100644
4976--- a/arch/ia64/kernel/salinfo.c
4977+++ b/arch/ia64/kernel/salinfo.c
4978@@ -609,7 +609,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4979 return NOTIFY_OK;
4980 }
4981
4982-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4983+static struct notifier_block salinfo_cpu_notifier =
4984 {
4985 .notifier_call = salinfo_cpu_callback,
4986 .priority = 0,
4987diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4988index 41e33f8..65180b2 100644
4989--- a/arch/ia64/kernel/sys_ia64.c
4990+++ b/arch/ia64/kernel/sys_ia64.c
4991@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4992 unsigned long align_mask = 0;
4993 struct mm_struct *mm = current->mm;
4994 struct vm_unmapped_area_info info;
4995+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4996
4997 if (len > RGN_MAP_LIMIT)
4998 return -ENOMEM;
4999@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5000 if (REGION_NUMBER(addr) == RGN_HPAGE)
5001 addr = 0;
5002 #endif
5003+
5004+#ifdef CONFIG_PAX_RANDMMAP
5005+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5006+ addr = mm->free_area_cache;
5007+ else
5008+#endif
5009+
5010 if (!addr)
5011 addr = TASK_UNMAPPED_BASE;
5012
5013@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5014 info.high_limit = TASK_SIZE;
5015 info.align_mask = align_mask;
5016 info.align_offset = 0;
5017+ info.threadstack_offset = offset;
5018 return vm_unmapped_area(&info);
5019 }
5020
5021diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
5022index dc00b2c..cce53c2 100644
5023--- a/arch/ia64/kernel/topology.c
5024+++ b/arch/ia64/kernel/topology.c
5025@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
5026 return NOTIFY_OK;
5027 }
5028
5029-static struct notifier_block __cpuinitdata cache_cpu_notifier =
5030+static struct notifier_block cache_cpu_notifier =
5031 {
5032 .notifier_call = cache_cpu_callback
5033 };
5034diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5035index 0ccb28f..8992469 100644
5036--- a/arch/ia64/kernel/vmlinux.lds.S
5037+++ b/arch/ia64/kernel/vmlinux.lds.S
5038@@ -198,7 +198,7 @@ SECTIONS {
5039 /* Per-cpu data: */
5040 . = ALIGN(PERCPU_PAGE_SIZE);
5041 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5042- __phys_per_cpu_start = __per_cpu_load;
5043+ __phys_per_cpu_start = per_cpu_load;
5044 /*
5045 * ensure percpu data fits
5046 * into percpu page size
5047diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5048index 6cf0341..d352594 100644
5049--- a/arch/ia64/mm/fault.c
5050+++ b/arch/ia64/mm/fault.c
5051@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5052 return pte_present(pte);
5053 }
5054
5055+#ifdef CONFIG_PAX_PAGEEXEC
5056+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5057+{
5058+ unsigned long i;
5059+
5060+ printk(KERN_ERR "PAX: bytes at PC: ");
5061+ for (i = 0; i < 8; i++) {
5062+ unsigned int c;
5063+ if (get_user(c, (unsigned int *)pc+i))
5064+ printk(KERN_CONT "???????? ");
5065+ else
5066+ printk(KERN_CONT "%08x ", c);
5067+ }
5068+ printk("\n");
5069+}
5070+#endif
5071+
5072 # define VM_READ_BIT 0
5073 # define VM_WRITE_BIT 1
5074 # define VM_EXEC_BIT 2
5075@@ -149,8 +166,21 @@ retry:
5076 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5077 goto bad_area;
5078
5079- if ((vma->vm_flags & mask) != mask)
5080+ if ((vma->vm_flags & mask) != mask) {
5081+
5082+#ifdef CONFIG_PAX_PAGEEXEC
5083+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5084+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5085+ goto bad_area;
5086+
5087+ up_read(&mm->mmap_sem);
5088+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5089+ do_group_exit(SIGKILL);
5090+ }
5091+#endif
5092+
5093 goto bad_area;
5094+ }
5095
5096 /*
5097 * If for any reason at all we couldn't handle the fault, make
5098diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5099index 76069c1..c2aa816 100644
5100--- a/arch/ia64/mm/hugetlbpage.c
5101+++ b/arch/ia64/mm/hugetlbpage.c
5102@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5103 unsigned long pgoff, unsigned long flags)
5104 {
5105 struct vm_unmapped_area_info info;
5106+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5107
5108 if (len > RGN_MAP_LIMIT)
5109 return -ENOMEM;
5110@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5111 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5112 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5113 info.align_offset = 0;
5114+ info.threadstack_offset = offset;
5115 return vm_unmapped_area(&info);
5116 }
5117
5118diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5119index d1fe4b4..2628f37 100644
5120--- a/arch/ia64/mm/init.c
5121+++ b/arch/ia64/mm/init.c
5122@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5123 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5124 vma->vm_end = vma->vm_start + PAGE_SIZE;
5125 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5126+
5127+#ifdef CONFIG_PAX_PAGEEXEC
5128+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5129+ vma->vm_flags &= ~VM_EXEC;
5130+
5131+#ifdef CONFIG_PAX_MPROTECT
5132+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5133+ vma->vm_flags &= ~VM_MAYEXEC;
5134+#endif
5135+
5136+ }
5137+#endif
5138+
5139 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5140 down_write(&current->mm->mmap_sem);
5141 if (insert_vm_struct(current->mm, vma)) {
5142diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5143index 40b3ee9..8c2c112 100644
5144--- a/arch/m32r/include/asm/cache.h
5145+++ b/arch/m32r/include/asm/cache.h
5146@@ -1,8 +1,10 @@
5147 #ifndef _ASM_M32R_CACHE_H
5148 #define _ASM_M32R_CACHE_H
5149
5150+#include <linux/const.h>
5151+
5152 /* L1 cache line size */
5153 #define L1_CACHE_SHIFT 4
5154-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5155+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5156
5157 #endif /* _ASM_M32R_CACHE_H */
5158diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5159index 82abd15..d95ae5d 100644
5160--- a/arch/m32r/lib/usercopy.c
5161+++ b/arch/m32r/lib/usercopy.c
5162@@ -14,6 +14,9 @@
5163 unsigned long
5164 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5165 {
5166+ if ((long)n < 0)
5167+ return n;
5168+
5169 prefetch(from);
5170 if (access_ok(VERIFY_WRITE, to, n))
5171 __copy_user(to,from,n);
5172@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5173 unsigned long
5174 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5175 {
5176+ if ((long)n < 0)
5177+ return n;
5178+
5179 prefetchw(to);
5180 if (access_ok(VERIFY_READ, from, n))
5181 __copy_user_zeroing(to,from,n);
5182diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5183index 0395c51..5f26031 100644
5184--- a/arch/m68k/include/asm/cache.h
5185+++ b/arch/m68k/include/asm/cache.h
5186@@ -4,9 +4,11 @@
5187 #ifndef __ARCH_M68K_CACHE_H
5188 #define __ARCH_M68K_CACHE_H
5189
5190+#include <linux/const.h>
5191+
5192 /* bytes per L1 cache line */
5193 #define L1_CACHE_SHIFT 4
5194-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5195+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5196
5197 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5198
5199diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5200index 3c52fa6..11b2ad8 100644
5201--- a/arch/metag/mm/hugetlbpage.c
5202+++ b/arch/metag/mm/hugetlbpage.c
5203@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5204 info.high_limit = TASK_SIZE;
5205 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5206 info.align_offset = 0;
5207+ info.threadstack_offset = 0;
5208 return vm_unmapped_area(&info);
5209 }
5210
5211diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5212index 4efe96a..60e8699 100644
5213--- a/arch/microblaze/include/asm/cache.h
5214+++ b/arch/microblaze/include/asm/cache.h
5215@@ -13,11 +13,12 @@
5216 #ifndef _ASM_MICROBLAZE_CACHE_H
5217 #define _ASM_MICROBLAZE_CACHE_H
5218
5219+#include <linux/const.h>
5220 #include <asm/registers.h>
5221
5222 #define L1_CACHE_SHIFT 5
5223 /* word-granular cache in microblaze */
5224-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5225+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5226
5227 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5228
5229diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5230index 08b6079..eb272cf 100644
5231--- a/arch/mips/include/asm/atomic.h
5232+++ b/arch/mips/include/asm/atomic.h
5233@@ -21,6 +21,10 @@
5234 #include <asm/cmpxchg.h>
5235 #include <asm/war.h>
5236
5237+#ifdef CONFIG_GENERIC_ATOMIC64
5238+#include <asm-generic/atomic64.h>
5239+#endif
5240+
5241 #define ATOMIC_INIT(i) { (i) }
5242
5243 /*
5244@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5245 */
5246 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5247
5248+#define atomic64_read_unchecked(v) atomic64_read(v)
5249+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5250+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5251+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5252+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5253+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5254+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5255+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5256+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5257+
5258 #endif /* CONFIG_64BIT */
5259
5260 /*
5261diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5262index b4db69f..8f3b093 100644
5263--- a/arch/mips/include/asm/cache.h
5264+++ b/arch/mips/include/asm/cache.h
5265@@ -9,10 +9,11 @@
5266 #ifndef _ASM_CACHE_H
5267 #define _ASM_CACHE_H
5268
5269+#include <linux/const.h>
5270 #include <kmalloc.h>
5271
5272 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5273-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5274+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5275
5276 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5277 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5278diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5279index cf3ae24..238d22f 100644
5280--- a/arch/mips/include/asm/elf.h
5281+++ b/arch/mips/include/asm/elf.h
5282@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5283 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5284 #endif
5285
5286+#ifdef CONFIG_PAX_ASLR
5287+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5288+
5289+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5290+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5291+#endif
5292+
5293 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5294 struct linux_binprm;
5295 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5296 int uses_interp);
5297
5298-struct mm_struct;
5299-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5300-#define arch_randomize_brk arch_randomize_brk
5301-
5302 #endif /* _ASM_ELF_H */
5303diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5304index c1f6afa..38cc6e9 100644
5305--- a/arch/mips/include/asm/exec.h
5306+++ b/arch/mips/include/asm/exec.h
5307@@ -12,6 +12,6 @@
5308 #ifndef _ASM_EXEC_H
5309 #define _ASM_EXEC_H
5310
5311-extern unsigned long arch_align_stack(unsigned long sp);
5312+#define arch_align_stack(x) ((x) & ~0xfUL)
5313
5314 #endif /* _ASM_EXEC_H */
5315diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5316index f59552f..3abe9b9 100644
5317--- a/arch/mips/include/asm/page.h
5318+++ b/arch/mips/include/asm/page.h
5319@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5320 #ifdef CONFIG_CPU_MIPS32
5321 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5322 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5323- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5324+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5325 #else
5326 typedef struct { unsigned long long pte; } pte_t;
5327 #define pte_val(x) ((x).pte)
5328diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5329index 881d18b..cea38bc 100644
5330--- a/arch/mips/include/asm/pgalloc.h
5331+++ b/arch/mips/include/asm/pgalloc.h
5332@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5333 {
5334 set_pud(pud, __pud((unsigned long)pmd));
5335 }
5336+
5337+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5338+{
5339+ pud_populate(mm, pud, pmd);
5340+}
5341 #endif
5342
5343 /*
5344diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5345index 895320e..bf63e10 100644
5346--- a/arch/mips/include/asm/thread_info.h
5347+++ b/arch/mips/include/asm/thread_info.h
5348@@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
5349 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5350 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5351 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5352+/* li takes a 32bit immediate */
5353+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5354 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5355
5356 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5357@@ -130,15 +132,18 @@ static inline struct thread_info *current_thread_info(void)
5358 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5359 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5360 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5361+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5362+
5363+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5364
5365 /* work to do in syscall_trace_leave() */
5366-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5367+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5368
5369 /* work to do on interrupt/exception return */
5370 #define _TIF_WORK_MASK \
5371 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5372 /* work to do on any return to u-space */
5373-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5374+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5375
5376 #endif /* __KERNEL__ */
5377
5378diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5379index 1188e00..41cf144 100644
5380--- a/arch/mips/kernel/binfmt_elfn32.c
5381+++ b/arch/mips/kernel/binfmt_elfn32.c
5382@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5383 #undef ELF_ET_DYN_BASE
5384 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5385
5386+#ifdef CONFIG_PAX_ASLR
5387+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5388+
5389+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5390+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5391+#endif
5392+
5393 #include <asm/processor.h>
5394 #include <linux/module.h>
5395 #include <linux/elfcore.h>
5396diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5397index 202e581..689ca79 100644
5398--- a/arch/mips/kernel/binfmt_elfo32.c
5399+++ b/arch/mips/kernel/binfmt_elfo32.c
5400@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5401 #undef ELF_ET_DYN_BASE
5402 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5403
5404+#ifdef CONFIG_PAX_ASLR
5405+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5406+
5407+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5408+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5409+#endif
5410+
5411 #include <asm/processor.h>
5412
5413 /*
5414diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5415index c6a041d..b3e7318 100644
5416--- a/arch/mips/kernel/process.c
5417+++ b/arch/mips/kernel/process.c
5418@@ -563,15 +563,3 @@ unsigned long get_wchan(struct task_struct *task)
5419 out:
5420 return pc;
5421 }
5422-
5423-/*
5424- * Don't forget that the stack pointer must be aligned on a 8 bytes
5425- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5426- */
5427-unsigned long arch_align_stack(unsigned long sp)
5428-{
5429- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5430- sp -= get_random_int() & ~PAGE_MASK;
5431-
5432- return sp & ALMASK;
5433-}
5434diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5435index 9c6299c..2fb4c22 100644
5436--- a/arch/mips/kernel/ptrace.c
5437+++ b/arch/mips/kernel/ptrace.c
5438@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5439 return arch;
5440 }
5441
5442+#ifdef CONFIG_GRKERNSEC_SETXID
5443+extern void gr_delayed_cred_worker(void);
5444+#endif
5445+
5446 /*
5447 * Notification of system call entry/exit
5448 * - triggered by current->work.syscall_trace
5449@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5450 /* do the secure computing check first */
5451 secure_computing_strict(regs->regs[2]);
5452
5453+#ifdef CONFIG_GRKERNSEC_SETXID
5454+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5455+ gr_delayed_cred_worker();
5456+#endif
5457+
5458 if (!(current->ptrace & PT_PTRACED))
5459 goto out;
5460
5461diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5462index 9b36424..e7f4154 100644
5463--- a/arch/mips/kernel/scall32-o32.S
5464+++ b/arch/mips/kernel/scall32-o32.S
5465@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5466
5467 stack_done:
5468 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5469- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5470+ li t1, _TIF_SYSCALL_WORK
5471 and t0, t1
5472 bnez t0, syscall_trace_entry # -> yes
5473
5474diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5475index 97a5909..59622f8 100644
5476--- a/arch/mips/kernel/scall64-64.S
5477+++ b/arch/mips/kernel/scall64-64.S
5478@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5479
5480 sd a3, PT_R26(sp) # save a3 for syscall restarting
5481
5482- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5483+ li t1, _TIF_SYSCALL_WORK
5484 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5485 and t0, t1, t0
5486 bnez t0, syscall_trace_entry
5487diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5488index edcb659..fb2ab09 100644
5489--- a/arch/mips/kernel/scall64-n32.S
5490+++ b/arch/mips/kernel/scall64-n32.S
5491@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5492
5493 sd a3, PT_R26(sp) # save a3 for syscall restarting
5494
5495- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5496+ li t1, _TIF_SYSCALL_WORK
5497 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5498 and t0, t1, t0
5499 bnez t0, n32_syscall_trace_entry
5500diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5501index 74f485d..47d2c38 100644
5502--- a/arch/mips/kernel/scall64-o32.S
5503+++ b/arch/mips/kernel/scall64-o32.S
5504@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5505 PTR 4b, bad_stack
5506 .previous
5507
5508- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5509+ li t1, _TIF_SYSCALL_WORK
5510 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5511 and t0, t1, t0
5512 bnez t0, trace_a_syscall
5513diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5514index 0fead53..a2c0fb5 100644
5515--- a/arch/mips/mm/fault.c
5516+++ b/arch/mips/mm/fault.c
5517@@ -27,6 +27,23 @@
5518 #include <asm/highmem.h> /* For VMALLOC_END */
5519 #include <linux/kdebug.h>
5520
5521+#ifdef CONFIG_PAX_PAGEEXEC
5522+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5523+{
5524+ unsigned long i;
5525+
5526+ printk(KERN_ERR "PAX: bytes at PC: ");
5527+ for (i = 0; i < 5; i++) {
5528+ unsigned int c;
5529+ if (get_user(c, (unsigned int *)pc+i))
5530+ printk(KERN_CONT "???????? ");
5531+ else
5532+ printk(KERN_CONT "%08x ", c);
5533+ }
5534+ printk("\n");
5535+}
5536+#endif
5537+
5538 /*
5539 * This routine handles page faults. It determines the address,
5540 * and the problem, and then passes it off to one of the appropriate
5541diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5542index 7e5fe27..9656513 100644
5543--- a/arch/mips/mm/mmap.c
5544+++ b/arch/mips/mm/mmap.c
5545@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5546 struct vm_area_struct *vma;
5547 unsigned long addr = addr0;
5548 int do_color_align;
5549+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5550 struct vm_unmapped_area_info info;
5551
5552 if (unlikely(len > TASK_SIZE))
5553@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5554 do_color_align = 1;
5555
5556 /* requesting a specific address */
5557+
5558+#ifdef CONFIG_PAX_RANDMMAP
5559+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5560+#endif
5561+
5562 if (addr) {
5563 if (do_color_align)
5564 addr = COLOUR_ALIGN(addr, pgoff);
5565@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5566 addr = PAGE_ALIGN(addr);
5567
5568 vma = find_vma(mm, addr);
5569- if (TASK_SIZE - len >= addr &&
5570- (!vma || addr + len <= vma->vm_start))
5571+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5572 return addr;
5573 }
5574
5575 info.length = len;
5576 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
5577 info.align_offset = pgoff << PAGE_SHIFT;
5578+ info.threadstack_offset = offset;
5579
5580 if (dir == DOWN) {
5581 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
5582@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5583 {
5584 unsigned long random_factor = 0UL;
5585
5586+#ifdef CONFIG_PAX_RANDMMAP
5587+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5588+#endif
5589+
5590 if (current->flags & PF_RANDOMIZE) {
5591 random_factor = get_random_int();
5592 random_factor = random_factor << PAGE_SHIFT;
5593@@ -157,42 +167,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5594
5595 if (mmap_is_legacy()) {
5596 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5597+
5598+#ifdef CONFIG_PAX_RANDMMAP
5599+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5600+ mm->mmap_base += mm->delta_mmap;
5601+#endif
5602+
5603 mm->get_unmapped_area = arch_get_unmapped_area;
5604 mm->unmap_area = arch_unmap_area;
5605 } else {
5606 mm->mmap_base = mmap_base(random_factor);
5607+
5608+#ifdef CONFIG_PAX_RANDMMAP
5609+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5610+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5611+#endif
5612+
5613 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5614 mm->unmap_area = arch_unmap_area_topdown;
5615 }
5616 }
5617
5618-static inline unsigned long brk_rnd(void)
5619-{
5620- unsigned long rnd = get_random_int();
5621-
5622- rnd = rnd << PAGE_SHIFT;
5623- /* 8MB for 32bit, 256MB for 64bit */
5624- if (TASK_IS_32BIT_ADDR)
5625- rnd = rnd & 0x7ffffful;
5626- else
5627- rnd = rnd & 0xffffffful;
5628-
5629- return rnd;
5630-}
5631-
5632-unsigned long arch_randomize_brk(struct mm_struct *mm)
5633-{
5634- unsigned long base = mm->brk;
5635- unsigned long ret;
5636-
5637- ret = PAGE_ALIGN(base + brk_rnd());
5638-
5639- if (ret < mm->brk)
5640- return mm->brk;
5641-
5642- return ret;
5643-}
5644-
5645 int __virt_addr_valid(const volatile void *kaddr)
5646 {
5647 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5648diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5649index 967d144..db12197 100644
5650--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5651+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5652@@ -11,12 +11,14 @@
5653 #ifndef _ASM_PROC_CACHE_H
5654 #define _ASM_PROC_CACHE_H
5655
5656+#include <linux/const.h>
5657+
5658 /* L1 cache */
5659
5660 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5661 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5662-#define L1_CACHE_BYTES 16 /* bytes per entry */
5663 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5664+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5665 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5666
5667 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5668diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5669index bcb5df2..84fabd2 100644
5670--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5671+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5672@@ -16,13 +16,15 @@
5673 #ifndef _ASM_PROC_CACHE_H
5674 #define _ASM_PROC_CACHE_H
5675
5676+#include <linux/const.h>
5677+
5678 /*
5679 * L1 cache
5680 */
5681 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5682 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5683-#define L1_CACHE_BYTES 32 /* bytes per entry */
5684 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5685+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5686 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5687
5688 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5689diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5690index 4ce7a01..449202a 100644
5691--- a/arch/openrisc/include/asm/cache.h
5692+++ b/arch/openrisc/include/asm/cache.h
5693@@ -19,11 +19,13 @@
5694 #ifndef __ASM_OPENRISC_CACHE_H
5695 #define __ASM_OPENRISC_CACHE_H
5696
5697+#include <linux/const.h>
5698+
5699 /* FIXME: How can we replace these with values from the CPU...
5700 * they shouldn't be hard-coded!
5701 */
5702
5703-#define L1_CACHE_BYTES 16
5704 #define L1_CACHE_SHIFT 4
5705+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5706
5707 #endif /* __ASM_OPENRISC_CACHE_H */
5708diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5709index 472886c..00e7df9 100644
5710--- a/arch/parisc/include/asm/atomic.h
5711+++ b/arch/parisc/include/asm/atomic.h
5712@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
5713 return dec;
5714 }
5715
5716+#define atomic64_read_unchecked(v) atomic64_read(v)
5717+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5718+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5719+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5720+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5721+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5722+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5723+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5724+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5725+
5726 #endif /* !CONFIG_64BIT */
5727
5728
5729diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5730index 47f11c7..3420df2 100644
5731--- a/arch/parisc/include/asm/cache.h
5732+++ b/arch/parisc/include/asm/cache.h
5733@@ -5,6 +5,7 @@
5734 #ifndef __ARCH_PARISC_CACHE_H
5735 #define __ARCH_PARISC_CACHE_H
5736
5737+#include <linux/const.h>
5738
5739 /*
5740 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5741@@ -15,13 +16,13 @@
5742 * just ruin performance.
5743 */
5744 #ifdef CONFIG_PA20
5745-#define L1_CACHE_BYTES 64
5746 #define L1_CACHE_SHIFT 6
5747 #else
5748-#define L1_CACHE_BYTES 32
5749 #define L1_CACHE_SHIFT 5
5750 #endif
5751
5752+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5753+
5754 #ifndef __ASSEMBLY__
5755
5756 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5757diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5758index ad2b503..bdf1651 100644
5759--- a/arch/parisc/include/asm/elf.h
5760+++ b/arch/parisc/include/asm/elf.h
5761@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5762
5763 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5764
5765+#ifdef CONFIG_PAX_ASLR
5766+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5767+
5768+#define PAX_DELTA_MMAP_LEN 16
5769+#define PAX_DELTA_STACK_LEN 16
5770+#endif
5771+
5772 /* This yields a mask that user programs can use to figure out what
5773 instruction set this CPU supports. This could be done in user space,
5774 but it's not easy, and we've already done it here. */
5775diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5776index fc987a1..6e068ef 100644
5777--- a/arch/parisc/include/asm/pgalloc.h
5778+++ b/arch/parisc/include/asm/pgalloc.h
5779@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5780 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5781 }
5782
5783+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5784+{
5785+ pgd_populate(mm, pgd, pmd);
5786+}
5787+
5788 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5789 {
5790 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5791@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5792 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5793 #define pmd_free(mm, x) do { } while (0)
5794 #define pgd_populate(mm, pmd, pte) BUG()
5795+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5796
5797 #endif
5798
5799diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5800index 1e40d7f..a3eb445 100644
5801--- a/arch/parisc/include/asm/pgtable.h
5802+++ b/arch/parisc/include/asm/pgtable.h
5803@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5804 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5805 #define PAGE_COPY PAGE_EXECREAD
5806 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5807+
5808+#ifdef CONFIG_PAX_PAGEEXEC
5809+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5810+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5811+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5812+#else
5813+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5814+# define PAGE_COPY_NOEXEC PAGE_COPY
5815+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5816+#endif
5817+
5818 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5819 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5820 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5821diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5822index e0a8235..ce2f1e1 100644
5823--- a/arch/parisc/include/asm/uaccess.h
5824+++ b/arch/parisc/include/asm/uaccess.h
5825@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5826 const void __user *from,
5827 unsigned long n)
5828 {
5829- int sz = __compiletime_object_size(to);
5830+ size_t sz = __compiletime_object_size(to);
5831 int ret = -EFAULT;
5832
5833- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5834+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5835 ret = __copy_from_user(to, from, n);
5836 else
5837 copy_from_user_overflow();
5838diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5839index 2a625fb..9908930 100644
5840--- a/arch/parisc/kernel/module.c
5841+++ b/arch/parisc/kernel/module.c
5842@@ -98,16 +98,38 @@
5843
5844 /* three functions to determine where in the module core
5845 * or init pieces the location is */
5846+static inline int in_init_rx(struct module *me, void *loc)
5847+{
5848+ return (loc >= me->module_init_rx &&
5849+ loc < (me->module_init_rx + me->init_size_rx));
5850+}
5851+
5852+static inline int in_init_rw(struct module *me, void *loc)
5853+{
5854+ return (loc >= me->module_init_rw &&
5855+ loc < (me->module_init_rw + me->init_size_rw));
5856+}
5857+
5858 static inline int in_init(struct module *me, void *loc)
5859 {
5860- return (loc >= me->module_init &&
5861- loc <= (me->module_init + me->init_size));
5862+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5863+}
5864+
5865+static inline int in_core_rx(struct module *me, void *loc)
5866+{
5867+ return (loc >= me->module_core_rx &&
5868+ loc < (me->module_core_rx + me->core_size_rx));
5869+}
5870+
5871+static inline int in_core_rw(struct module *me, void *loc)
5872+{
5873+ return (loc >= me->module_core_rw &&
5874+ loc < (me->module_core_rw + me->core_size_rw));
5875 }
5876
5877 static inline int in_core(struct module *me, void *loc)
5878 {
5879- return (loc >= me->module_core &&
5880- loc <= (me->module_core + me->core_size));
5881+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5882 }
5883
5884 static inline int in_local(struct module *me, void *loc)
5885@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5886 }
5887
5888 /* align things a bit */
5889- me->core_size = ALIGN(me->core_size, 16);
5890- me->arch.got_offset = me->core_size;
5891- me->core_size += gots * sizeof(struct got_entry);
5892+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5893+ me->arch.got_offset = me->core_size_rw;
5894+ me->core_size_rw += gots * sizeof(struct got_entry);
5895
5896- me->core_size = ALIGN(me->core_size, 16);
5897- me->arch.fdesc_offset = me->core_size;
5898- me->core_size += fdescs * sizeof(Elf_Fdesc);
5899+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5900+ me->arch.fdesc_offset = me->core_size_rw;
5901+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5902
5903 me->arch.got_max = gots;
5904 me->arch.fdesc_max = fdescs;
5905@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5906
5907 BUG_ON(value == 0);
5908
5909- got = me->module_core + me->arch.got_offset;
5910+ got = me->module_core_rw + me->arch.got_offset;
5911 for (i = 0; got[i].addr; i++)
5912 if (got[i].addr == value)
5913 goto out;
5914@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5915 #ifdef CONFIG_64BIT
5916 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5917 {
5918- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5919+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5920
5921 if (!value) {
5922 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5923@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5924
5925 /* Create new one */
5926 fdesc->addr = value;
5927- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5928+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5929 return (Elf_Addr)fdesc;
5930 }
5931 #endif /* CONFIG_64BIT */
5932@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5933
5934 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5935 end = table + sechdrs[me->arch.unwind_section].sh_size;
5936- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5937+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5938
5939 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5940 me->arch.unwind_section, table, end, gp);
5941diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5942index 5dfd248..64914ac 100644
5943--- a/arch/parisc/kernel/sys_parisc.c
5944+++ b/arch/parisc/kernel/sys_parisc.c
5945@@ -33,9 +33,11 @@
5946 #include <linux/utsname.h>
5947 #include <linux/personality.h>
5948
5949-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5950+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5951+ unsigned long flags)
5952 {
5953 struct vm_unmapped_area_info info;
5954+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5955
5956 info.flags = 0;
5957 info.length = len;
5958@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5959 info.high_limit = TASK_SIZE;
5960 info.align_mask = 0;
5961 info.align_offset = 0;
5962+ info.threadstack_offset = offset;
5963 return vm_unmapped_area(&info);
5964 }
5965
5966@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
5967 return (unsigned long) mapping >> 8;
5968 }
5969
5970-static unsigned long get_shared_area(struct address_space *mapping,
5971- unsigned long addr, unsigned long len, unsigned long pgoff)
5972+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5973+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5974 {
5975 struct vm_unmapped_area_info info;
5976+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5977
5978 info.flags = 0;
5979 info.length = len;
5980@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5981 info.high_limit = TASK_SIZE;
5982 info.align_mask = PAGE_MASK & (SHMLBA - 1);
5983 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
5984+ info.threadstack_offset = offset;
5985 return vm_unmapped_area(&info);
5986 }
5987
5988@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5989 return -EINVAL;
5990 return addr;
5991 }
5992- if (!addr)
5993+ if (!addr) {
5994 addr = TASK_UNMAPPED_BASE;
5995
5996+#ifdef CONFIG_PAX_RANDMMAP
5997+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
5998+ addr += current->mm->delta_mmap;
5999+#endif
6000+
6001+ }
6002+
6003 if (filp) {
6004- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
6005+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
6006 } else if(flags & MAP_SHARED) {
6007- addr = get_shared_area(NULL, addr, len, pgoff);
6008+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
6009 } else {
6010- addr = get_unshared_area(addr, len);
6011+ addr = get_unshared_area(filp, addr, len, flags);
6012 }
6013 return addr;
6014 }
6015diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
6016index 04e47c6..7a8faf6 100644
6017--- a/arch/parisc/kernel/traps.c
6018+++ b/arch/parisc/kernel/traps.c
6019@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
6020
6021 down_read(&current->mm->mmap_sem);
6022 vma = find_vma(current->mm,regs->iaoq[0]);
6023- if (vma && (regs->iaoq[0] >= vma->vm_start)
6024- && (vma->vm_flags & VM_EXEC)) {
6025-
6026+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
6027 fault_address = regs->iaoq[0];
6028 fault_space = regs->iasq[0];
6029
6030diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
6031index f247a34..dc0f219 100644
6032--- a/arch/parisc/mm/fault.c
6033+++ b/arch/parisc/mm/fault.c
6034@@ -15,6 +15,7 @@
6035 #include <linux/sched.h>
6036 #include <linux/interrupt.h>
6037 #include <linux/module.h>
6038+#include <linux/unistd.h>
6039
6040 #include <asm/uaccess.h>
6041 #include <asm/traps.h>
6042@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
6043 static unsigned long
6044 parisc_acctyp(unsigned long code, unsigned int inst)
6045 {
6046- if (code == 6 || code == 16)
6047+ if (code == 6 || code == 7 || code == 16)
6048 return VM_EXEC;
6049
6050 switch (inst & 0xf0000000) {
6051@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
6052 }
6053 #endif
6054
6055+#ifdef CONFIG_PAX_PAGEEXEC
6056+/*
6057+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
6058+ *
6059+ * returns 1 when task should be killed
6060+ * 2 when rt_sigreturn trampoline was detected
6061+ * 3 when unpatched PLT trampoline was detected
6062+ */
6063+static int pax_handle_fetch_fault(struct pt_regs *regs)
6064+{
6065+
6066+#ifdef CONFIG_PAX_EMUPLT
6067+ int err;
6068+
6069+ do { /* PaX: unpatched PLT emulation */
6070+ unsigned int bl, depwi;
6071+
6072+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6073+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6074+
6075+ if (err)
6076+ break;
6077+
6078+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6079+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6080+
6081+ err = get_user(ldw, (unsigned int *)addr);
6082+ err |= get_user(bv, (unsigned int *)(addr+4));
6083+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6084+
6085+ if (err)
6086+ break;
6087+
6088+ if (ldw == 0x0E801096U &&
6089+ bv == 0xEAC0C000U &&
6090+ ldw2 == 0x0E881095U)
6091+ {
6092+ unsigned int resolver, map;
6093+
6094+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6095+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6096+ if (err)
6097+ break;
6098+
6099+ regs->gr[20] = instruction_pointer(regs)+8;
6100+ regs->gr[21] = map;
6101+ regs->gr[22] = resolver;
6102+ regs->iaoq[0] = resolver | 3UL;
6103+ regs->iaoq[1] = regs->iaoq[0] + 4;
6104+ return 3;
6105+ }
6106+ }
6107+ } while (0);
6108+#endif
6109+
6110+#ifdef CONFIG_PAX_EMUTRAMP
6111+
6112+#ifndef CONFIG_PAX_EMUSIGRT
6113+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6114+ return 1;
6115+#endif
6116+
6117+ do { /* PaX: rt_sigreturn emulation */
6118+ unsigned int ldi1, ldi2, bel, nop;
6119+
6120+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6121+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6122+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6123+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6124+
6125+ if (err)
6126+ break;
6127+
6128+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6129+ ldi2 == 0x3414015AU &&
6130+ bel == 0xE4008200U &&
6131+ nop == 0x08000240U)
6132+ {
6133+ regs->gr[25] = (ldi1 & 2) >> 1;
6134+ regs->gr[20] = __NR_rt_sigreturn;
6135+ regs->gr[31] = regs->iaoq[1] + 16;
6136+ regs->sr[0] = regs->iasq[1];
6137+ regs->iaoq[0] = 0x100UL;
6138+ regs->iaoq[1] = regs->iaoq[0] + 4;
6139+ regs->iasq[0] = regs->sr[2];
6140+ regs->iasq[1] = regs->sr[2];
6141+ return 2;
6142+ }
6143+ } while (0);
6144+#endif
6145+
6146+ return 1;
6147+}
6148+
6149+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6150+{
6151+ unsigned long i;
6152+
6153+ printk(KERN_ERR "PAX: bytes at PC: ");
6154+ for (i = 0; i < 5; i++) {
6155+ unsigned int c;
6156+ if (get_user(c, (unsigned int *)pc+i))
6157+ printk(KERN_CONT "???????? ");
6158+ else
6159+ printk(KERN_CONT "%08x ", c);
6160+ }
6161+ printk("\n");
6162+}
6163+#endif
6164+
6165 int fixup_exception(struct pt_regs *regs)
6166 {
6167 const struct exception_table_entry *fix;
6168@@ -194,8 +305,33 @@ good_area:
6169
6170 acc_type = parisc_acctyp(code,regs->iir);
6171
6172- if ((vma->vm_flags & acc_type) != acc_type)
6173+ if ((vma->vm_flags & acc_type) != acc_type) {
6174+
6175+#ifdef CONFIG_PAX_PAGEEXEC
6176+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6177+ (address & ~3UL) == instruction_pointer(regs))
6178+ {
6179+ up_read(&mm->mmap_sem);
6180+ switch (pax_handle_fetch_fault(regs)) {
6181+
6182+#ifdef CONFIG_PAX_EMUPLT
6183+ case 3:
6184+ return;
6185+#endif
6186+
6187+#ifdef CONFIG_PAX_EMUTRAMP
6188+ case 2:
6189+ return;
6190+#endif
6191+
6192+ }
6193+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6194+ do_group_exit(SIGKILL);
6195+ }
6196+#endif
6197+
6198 goto bad_area;
6199+ }
6200
6201 /*
6202 * If for any reason at all we couldn't handle the fault, make
6203diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6204index e3b1d41..8e81edf 100644
6205--- a/arch/powerpc/include/asm/atomic.h
6206+++ b/arch/powerpc/include/asm/atomic.h
6207@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6208 return t1;
6209 }
6210
6211+#define atomic64_read_unchecked(v) atomic64_read(v)
6212+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6213+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6214+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6215+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6216+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6217+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6218+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6219+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6220+
6221 #endif /* __powerpc64__ */
6222
6223 #endif /* __KERNEL__ */
6224diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6225index 9e495c9..b6878e5 100644
6226--- a/arch/powerpc/include/asm/cache.h
6227+++ b/arch/powerpc/include/asm/cache.h
6228@@ -3,6 +3,7 @@
6229
6230 #ifdef __KERNEL__
6231
6232+#include <linux/const.h>
6233
6234 /* bytes per L1 cache line */
6235 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6236@@ -22,7 +23,7 @@
6237 #define L1_CACHE_SHIFT 7
6238 #endif
6239
6240-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6241+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6242
6243 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6244
6245diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6246index cc0655a..13eac2e 100644
6247--- a/arch/powerpc/include/asm/elf.h
6248+++ b/arch/powerpc/include/asm/elf.h
6249@@ -28,8 +28,19 @@
6250 the loader. We need to make sure that it is out of the way of the program
6251 that it will "exec", and that there is sufficient room for the brk. */
6252
6253-extern unsigned long randomize_et_dyn(unsigned long base);
6254-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6255+#define ELF_ET_DYN_BASE (0x20000000)
6256+
6257+#ifdef CONFIG_PAX_ASLR
6258+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6259+
6260+#ifdef __powerpc64__
6261+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6262+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6263+#else
6264+#define PAX_DELTA_MMAP_LEN 15
6265+#define PAX_DELTA_STACK_LEN 15
6266+#endif
6267+#endif
6268
6269 /*
6270 * Our registers are always unsigned longs, whether we're a 32 bit
6271@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6272 (0x7ff >> (PAGE_SHIFT - 12)) : \
6273 (0x3ffff >> (PAGE_SHIFT - 12)))
6274
6275-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6276-#define arch_randomize_brk arch_randomize_brk
6277-
6278-
6279 #ifdef CONFIG_SPU_BASE
6280 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6281 #define NT_SPU 1
6282diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6283index 8196e9c..d83a9f3 100644
6284--- a/arch/powerpc/include/asm/exec.h
6285+++ b/arch/powerpc/include/asm/exec.h
6286@@ -4,6 +4,6 @@
6287 #ifndef _ASM_POWERPC_EXEC_H
6288 #define _ASM_POWERPC_EXEC_H
6289
6290-extern unsigned long arch_align_stack(unsigned long sp);
6291+#define arch_align_stack(x) ((x) & ~0xfUL)
6292
6293 #endif /* _ASM_POWERPC_EXEC_H */
6294diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6295index 5acabbd..7ea14fa 100644
6296--- a/arch/powerpc/include/asm/kmap_types.h
6297+++ b/arch/powerpc/include/asm/kmap_types.h
6298@@ -10,7 +10,7 @@
6299 * 2 of the License, or (at your option) any later version.
6300 */
6301
6302-#define KM_TYPE_NR 16
6303+#define KM_TYPE_NR 17
6304
6305 #endif /* __KERNEL__ */
6306 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6307diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6308index 8565c25..2865190 100644
6309--- a/arch/powerpc/include/asm/mman.h
6310+++ b/arch/powerpc/include/asm/mman.h
6311@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6312 }
6313 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6314
6315-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6316+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6317 {
6318 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6319 }
6320diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6321index 988c812..63c7d70 100644
6322--- a/arch/powerpc/include/asm/page.h
6323+++ b/arch/powerpc/include/asm/page.h
6324@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6325 * and needs to be executable. This means the whole heap ends
6326 * up being executable.
6327 */
6328-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6329- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6330+#define VM_DATA_DEFAULT_FLAGS32 \
6331+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6332+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6333
6334 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6335 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6336@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6337 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6338 #endif
6339
6340+#define ktla_ktva(addr) (addr)
6341+#define ktva_ktla(addr) (addr)
6342+
6343 #ifndef CONFIG_PPC_BOOK3S_64
6344 /*
6345 * Use the top bit of the higher-level page table entries to indicate whether
6346diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6347index 88693ce..ac6f9ab 100644
6348--- a/arch/powerpc/include/asm/page_64.h
6349+++ b/arch/powerpc/include/asm/page_64.h
6350@@ -153,15 +153,18 @@ do { \
6351 * stack by default, so in the absence of a PT_GNU_STACK program header
6352 * we turn execute permission off.
6353 */
6354-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6355- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6356+#define VM_STACK_DEFAULT_FLAGS32 \
6357+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6358+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6359
6360 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6361 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6362
6363+#ifndef CONFIG_PAX_PAGEEXEC
6364 #define VM_STACK_DEFAULT_FLAGS \
6365 (is_32bit_task() ? \
6366 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6367+#endif
6368
6369 #include <asm-generic/getorder.h>
6370
6371diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6372index b66ae72..4a378cd 100644
6373--- a/arch/powerpc/include/asm/pgalloc-64.h
6374+++ b/arch/powerpc/include/asm/pgalloc-64.h
6375@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6376 #ifndef CONFIG_PPC_64K_PAGES
6377
6378 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6379+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6380
6381 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6382 {
6383@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6384 pud_set(pud, (unsigned long)pmd);
6385 }
6386
6387+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6388+{
6389+ pud_populate(mm, pud, pmd);
6390+}
6391+
6392 #define pmd_populate(mm, pmd, pte_page) \
6393 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6394 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6395@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
6396 #endif
6397
6398 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6399+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6400
6401 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6402 pte_t *pte)
6403diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6404index 7aeb955..19f748e 100644
6405--- a/arch/powerpc/include/asm/pgtable.h
6406+++ b/arch/powerpc/include/asm/pgtable.h
6407@@ -2,6 +2,7 @@
6408 #define _ASM_POWERPC_PGTABLE_H
6409 #ifdef __KERNEL__
6410
6411+#include <linux/const.h>
6412 #ifndef __ASSEMBLY__
6413 #include <asm/processor.h> /* For TASK_SIZE */
6414 #include <asm/mmu.h>
6415diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6416index 4aad413..85d86bf 100644
6417--- a/arch/powerpc/include/asm/pte-hash32.h
6418+++ b/arch/powerpc/include/asm/pte-hash32.h
6419@@ -21,6 +21,7 @@
6420 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6421 #define _PAGE_USER 0x004 /* usermode access allowed */
6422 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6423+#define _PAGE_EXEC _PAGE_GUARDED
6424 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6425 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6426 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6427diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6428index 4a9e408..724aa59 100644
6429--- a/arch/powerpc/include/asm/reg.h
6430+++ b/arch/powerpc/include/asm/reg.h
6431@@ -234,6 +234,7 @@
6432 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6433 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6434 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6435+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6436 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6437 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6438 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6439diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
6440index ffbaabe..eabe843 100644
6441--- a/arch/powerpc/include/asm/smp.h
6442+++ b/arch/powerpc/include/asm/smp.h
6443@@ -50,7 +50,7 @@ struct smp_ops_t {
6444 int (*cpu_disable)(void);
6445 void (*cpu_die)(unsigned int nr);
6446 int (*cpu_bootable)(unsigned int nr);
6447-};
6448+} __no_const;
6449
6450 extern void smp_send_debugger_break(void);
6451 extern void start_secondary_resume(void);
6452diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6453index ba7b197..d292e26 100644
6454--- a/arch/powerpc/include/asm/thread_info.h
6455+++ b/arch/powerpc/include/asm/thread_info.h
6456@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
6457 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
6458 TIF_NEED_RESCHED */
6459 #define TIF_32BIT 4 /* 32 bit binary */
6460-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
6461 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6462 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6463 #define TIF_SINGLESTEP 8 /* singlestepping active */
6464@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
6465 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6466 for stack store? */
6467 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6468+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
6469+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6470+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
6471
6472 /* as above, but as bit values */
6473 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6474@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
6475 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6476 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6477 #define _TIF_NOHZ (1<<TIF_NOHZ)
6478+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6479 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6480 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6481- _TIF_NOHZ)
6482+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
6483
6484 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6485 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6486diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6487index 4db4959..aba5c41 100644
6488--- a/arch/powerpc/include/asm/uaccess.h
6489+++ b/arch/powerpc/include/asm/uaccess.h
6490@@ -318,52 +318,6 @@ do { \
6491 extern unsigned long __copy_tofrom_user(void __user *to,
6492 const void __user *from, unsigned long size);
6493
6494-#ifndef __powerpc64__
6495-
6496-static inline unsigned long copy_from_user(void *to,
6497- const void __user *from, unsigned long n)
6498-{
6499- unsigned long over;
6500-
6501- if (access_ok(VERIFY_READ, from, n))
6502- return __copy_tofrom_user((__force void __user *)to, from, n);
6503- if ((unsigned long)from < TASK_SIZE) {
6504- over = (unsigned long)from + n - TASK_SIZE;
6505- return __copy_tofrom_user((__force void __user *)to, from,
6506- n - over) + over;
6507- }
6508- return n;
6509-}
6510-
6511-static inline unsigned long copy_to_user(void __user *to,
6512- const void *from, unsigned long n)
6513-{
6514- unsigned long over;
6515-
6516- if (access_ok(VERIFY_WRITE, to, n))
6517- return __copy_tofrom_user(to, (__force void __user *)from, n);
6518- if ((unsigned long)to < TASK_SIZE) {
6519- over = (unsigned long)to + n - TASK_SIZE;
6520- return __copy_tofrom_user(to, (__force void __user *)from,
6521- n - over) + over;
6522- }
6523- return n;
6524-}
6525-
6526-#else /* __powerpc64__ */
6527-
6528-#define __copy_in_user(to, from, size) \
6529- __copy_tofrom_user((to), (from), (size))
6530-
6531-extern unsigned long copy_from_user(void *to, const void __user *from,
6532- unsigned long n);
6533-extern unsigned long copy_to_user(void __user *to, const void *from,
6534- unsigned long n);
6535-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6536- unsigned long n);
6537-
6538-#endif /* __powerpc64__ */
6539-
6540 static inline unsigned long __copy_from_user_inatomic(void *to,
6541 const void __user *from, unsigned long n)
6542 {
6543@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6544 if (ret == 0)
6545 return 0;
6546 }
6547+
6548+ if (!__builtin_constant_p(n))
6549+ check_object_size(to, n, false);
6550+
6551 return __copy_tofrom_user((__force void __user *)to, from, n);
6552 }
6553
6554@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6555 if (ret == 0)
6556 return 0;
6557 }
6558+
6559+ if (!__builtin_constant_p(n))
6560+ check_object_size(from, n, true);
6561+
6562 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6563 }
6564
6565@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6566 return __copy_to_user_inatomic(to, from, size);
6567 }
6568
6569+#ifndef __powerpc64__
6570+
6571+static inline unsigned long __must_check copy_from_user(void *to,
6572+ const void __user *from, unsigned long n)
6573+{
6574+ unsigned long over;
6575+
6576+ if ((long)n < 0)
6577+ return n;
6578+
6579+ if (access_ok(VERIFY_READ, from, n)) {
6580+ if (!__builtin_constant_p(n))
6581+ check_object_size(to, n, false);
6582+ return __copy_tofrom_user((__force void __user *)to, from, n);
6583+ }
6584+ if ((unsigned long)from < TASK_SIZE) {
6585+ over = (unsigned long)from + n - TASK_SIZE;
6586+ if (!__builtin_constant_p(n - over))
6587+ check_object_size(to, n - over, false);
6588+ return __copy_tofrom_user((__force void __user *)to, from,
6589+ n - over) + over;
6590+ }
6591+ return n;
6592+}
6593+
6594+static inline unsigned long __must_check copy_to_user(void __user *to,
6595+ const void *from, unsigned long n)
6596+{
6597+ unsigned long over;
6598+
6599+ if ((long)n < 0)
6600+ return n;
6601+
6602+ if (access_ok(VERIFY_WRITE, to, n)) {
6603+ if (!__builtin_constant_p(n))
6604+ check_object_size(from, n, true);
6605+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6606+ }
6607+ if ((unsigned long)to < TASK_SIZE) {
6608+ over = (unsigned long)to + n - TASK_SIZE;
6609+ if (!__builtin_constant_p(n))
6610+ check_object_size(from, n - over, true);
6611+ return __copy_tofrom_user(to, (__force void __user *)from,
6612+ n - over) + over;
6613+ }
6614+ return n;
6615+}
6616+
6617+#else /* __powerpc64__ */
6618+
6619+#define __copy_in_user(to, from, size) \
6620+ __copy_tofrom_user((to), (from), (size))
6621+
6622+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6623+{
6624+ if ((long)n < 0 || n > INT_MAX)
6625+ return n;
6626+
6627+ if (!__builtin_constant_p(n))
6628+ check_object_size(to, n, false);
6629+
6630+ if (likely(access_ok(VERIFY_READ, from, n)))
6631+ n = __copy_from_user(to, from, n);
6632+ else
6633+ memset(to, 0, n);
6634+ return n;
6635+}
6636+
6637+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6638+{
6639+ if ((long)n < 0 || n > INT_MAX)
6640+ return n;
6641+
6642+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6643+ if (!__builtin_constant_p(n))
6644+ check_object_size(from, n, true);
6645+ n = __copy_to_user(to, from, n);
6646+ }
6647+ return n;
6648+}
6649+
6650+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6651+ unsigned long n);
6652+
6653+#endif /* __powerpc64__ */
6654+
6655 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6656
6657 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6658diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6659index 645170a..6cf0271 100644
6660--- a/arch/powerpc/kernel/exceptions-64e.S
6661+++ b/arch/powerpc/kernel/exceptions-64e.S
6662@@ -757,6 +757,7 @@ storage_fault_common:
6663 std r14,_DAR(r1)
6664 std r15,_DSISR(r1)
6665 addi r3,r1,STACK_FRAME_OVERHEAD
6666+ bl .save_nvgprs
6667 mr r4,r14
6668 mr r5,r15
6669 ld r14,PACA_EXGEN+EX_R14(r13)
6670@@ -765,8 +766,7 @@ storage_fault_common:
6671 cmpdi r3,0
6672 bne- 1f
6673 b .ret_from_except_lite
6674-1: bl .save_nvgprs
6675- mr r5,r3
6676+1: mr r5,r3
6677 addi r3,r1,STACK_FRAME_OVERHEAD
6678 ld r4,_DAR(r1)
6679 bl .bad_page_fault
6680diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6681index 40e4a17..5a84b37 100644
6682--- a/arch/powerpc/kernel/exceptions-64s.S
6683+++ b/arch/powerpc/kernel/exceptions-64s.S
6684@@ -1362,10 +1362,10 @@ handle_page_fault:
6685 11: ld r4,_DAR(r1)
6686 ld r5,_DSISR(r1)
6687 addi r3,r1,STACK_FRAME_OVERHEAD
6688+ bl .save_nvgprs
6689 bl .do_page_fault
6690 cmpdi r3,0
6691 beq+ 12f
6692- bl .save_nvgprs
6693 mr r5,r3
6694 addi r3,r1,STACK_FRAME_OVERHEAD
6695 lwz r4,_DAR(r1)
6696diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6697index 2e3200c..72095ce 100644
6698--- a/arch/powerpc/kernel/module_32.c
6699+++ b/arch/powerpc/kernel/module_32.c
6700@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6701 me->arch.core_plt_section = i;
6702 }
6703 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6704- printk("Module doesn't contain .plt or .init.plt sections.\n");
6705+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6706 return -ENOEXEC;
6707 }
6708
6709@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6710
6711 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6712 /* Init, or core PLT? */
6713- if (location >= mod->module_core
6714- && location < mod->module_core + mod->core_size)
6715+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6716+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6717 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6718- else
6719+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6720+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6721 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6722+ else {
6723+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6724+ return ~0UL;
6725+ }
6726
6727 /* Find this entry, or if that fails, the next avail. entry */
6728 while (entry->jump[0]) {
6729diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6730index 076d124..6cb2cbf 100644
6731--- a/arch/powerpc/kernel/process.c
6732+++ b/arch/powerpc/kernel/process.c
6733@@ -874,8 +874,8 @@ void show_regs(struct pt_regs * regs)
6734 * Lookup NIP late so we have the best change of getting the
6735 * above info out without failing
6736 */
6737- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6738- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6739+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6740+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6741 #endif
6742 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
6743 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
6744@@ -1335,10 +1335,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6745 newsp = stack[0];
6746 ip = stack[STACK_FRAME_LR_SAVE];
6747 if (!firstframe || ip != lr) {
6748- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6749+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6750 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6751 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6752- printk(" (%pS)",
6753+ printk(" (%pA)",
6754 (void *)current->ret_stack[curr_frame].ret);
6755 curr_frame--;
6756 }
6757@@ -1358,7 +1358,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6758 struct pt_regs *regs = (struct pt_regs *)
6759 (sp + STACK_FRAME_OVERHEAD);
6760 lr = regs->link;
6761- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6762+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6763 regs->trap, (void *)regs->nip, (void *)lr);
6764 firstframe = 1;
6765 }
6766@@ -1394,58 +1394,3 @@ void notrace __ppc64_runlatch_off(void)
6767 mtspr(SPRN_CTRLT, ctrl);
6768 }
6769 #endif /* CONFIG_PPC64 */
6770-
6771-unsigned long arch_align_stack(unsigned long sp)
6772-{
6773- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6774- sp -= get_random_int() & ~PAGE_MASK;
6775- return sp & ~0xf;
6776-}
6777-
6778-static inline unsigned long brk_rnd(void)
6779-{
6780- unsigned long rnd = 0;
6781-
6782- /* 8MB for 32bit, 1GB for 64bit */
6783- if (is_32bit_task())
6784- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6785- else
6786- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6787-
6788- return rnd << PAGE_SHIFT;
6789-}
6790-
6791-unsigned long arch_randomize_brk(struct mm_struct *mm)
6792-{
6793- unsigned long base = mm->brk;
6794- unsigned long ret;
6795-
6796-#ifdef CONFIG_PPC_STD_MMU_64
6797- /*
6798- * If we are using 1TB segments and we are allowed to randomise
6799- * the heap, we can put it above 1TB so it is backed by a 1TB
6800- * segment. Otherwise the heap will be in the bottom 1TB
6801- * which always uses 256MB segments and this may result in a
6802- * performance penalty.
6803- */
6804- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6805- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6806-#endif
6807-
6808- ret = PAGE_ALIGN(base + brk_rnd());
6809-
6810- if (ret < mm->brk)
6811- return mm->brk;
6812-
6813- return ret;
6814-}
6815-
6816-unsigned long randomize_et_dyn(unsigned long base)
6817-{
6818- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6819-
6820- if (ret < base)
6821- return base;
6822-
6823- return ret;
6824-}
6825diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6826index 98c2fc1..b73a4ca 100644
6827--- a/arch/powerpc/kernel/ptrace.c
6828+++ b/arch/powerpc/kernel/ptrace.c
6829@@ -1781,6 +1781,10 @@ long arch_ptrace(struct task_struct *child, long request,
6830 return ret;
6831 }
6832
6833+#ifdef CONFIG_GRKERNSEC_SETXID
6834+extern void gr_delayed_cred_worker(void);
6835+#endif
6836+
6837 /*
6838 * We must return the syscall number to actually look up in the table.
6839 * This can be -1L to skip running any syscall at all.
6840@@ -1793,6 +1797,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6841
6842 secure_computing_strict(regs->gpr[0]);
6843
6844+#ifdef CONFIG_GRKERNSEC_SETXID
6845+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6846+ gr_delayed_cred_worker();
6847+#endif
6848+
6849 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6850 tracehook_report_syscall_entry(regs))
6851 /*
6852@@ -1827,6 +1836,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6853 {
6854 int step;
6855
6856+#ifdef CONFIG_GRKERNSEC_SETXID
6857+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6858+ gr_delayed_cred_worker();
6859+#endif
6860+
6861 audit_syscall_exit(regs);
6862
6863 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6864diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6865index 201385c..0f01828 100644
6866--- a/arch/powerpc/kernel/signal_32.c
6867+++ b/arch/powerpc/kernel/signal_32.c
6868@@ -976,7 +976,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6869 /* Save user registers on the stack */
6870 frame = &rt_sf->uc.uc_mcontext;
6871 addr = frame;
6872- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6873+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6874 sigret = 0;
6875 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6876 } else {
6877diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6878index 3459473..2d40783 100644
6879--- a/arch/powerpc/kernel/signal_64.c
6880+++ b/arch/powerpc/kernel/signal_64.c
6881@@ -749,7 +749,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6882 #endif
6883
6884 /* Set up to return from userspace. */
6885- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6886+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6887 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6888 } else {
6889 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6890diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6891index e68a845..8b140e6 100644
6892--- a/arch/powerpc/kernel/sysfs.c
6893+++ b/arch/powerpc/kernel/sysfs.c
6894@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6895 return NOTIFY_OK;
6896 }
6897
6898-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6899+static struct notifier_block sysfs_cpu_nb = {
6900 .notifier_call = sysfs_cpu_notify,
6901 };
6902
6903diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6904index c0e5caf..68e8305 100644
6905--- a/arch/powerpc/kernel/traps.c
6906+++ b/arch/powerpc/kernel/traps.c
6907@@ -143,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6908 return flags;
6909 }
6910
6911+extern void gr_handle_kernel_exploit(void);
6912+
6913 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6914 int signr)
6915 {
6916@@ -192,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6917 panic("Fatal exception in interrupt");
6918 if (panic_on_oops)
6919 panic("Fatal exception");
6920+
6921+ gr_handle_kernel_exploit();
6922+
6923 do_exit(signr);
6924 }
6925
6926diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6927index d4f463a..8fb7431 100644
6928--- a/arch/powerpc/kernel/vdso.c
6929+++ b/arch/powerpc/kernel/vdso.c
6930@@ -34,6 +34,7 @@
6931 #include <asm/firmware.h>
6932 #include <asm/vdso.h>
6933 #include <asm/vdso_datapage.h>
6934+#include <asm/mman.h>
6935
6936 #include "setup.h"
6937
6938@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6939 vdso_base = VDSO32_MBASE;
6940 #endif
6941
6942- current->mm->context.vdso_base = 0;
6943+ current->mm->context.vdso_base = ~0UL;
6944
6945 /* vDSO has a problem and was disabled, just don't "enable" it for the
6946 * process
6947@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6948 vdso_base = get_unmapped_area(NULL, vdso_base,
6949 (vdso_pages << PAGE_SHIFT) +
6950 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6951- 0, 0);
6952+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6953 if (IS_ERR_VALUE(vdso_base)) {
6954 rc = vdso_base;
6955 goto fail_mmapsem;
6956diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6957index 5eea6f3..5d10396 100644
6958--- a/arch/powerpc/lib/usercopy_64.c
6959+++ b/arch/powerpc/lib/usercopy_64.c
6960@@ -9,22 +9,6 @@
6961 #include <linux/module.h>
6962 #include <asm/uaccess.h>
6963
6964-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6965-{
6966- if (likely(access_ok(VERIFY_READ, from, n)))
6967- n = __copy_from_user(to, from, n);
6968- else
6969- memset(to, 0, n);
6970- return n;
6971-}
6972-
6973-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6974-{
6975- if (likely(access_ok(VERIFY_WRITE, to, n)))
6976- n = __copy_to_user(to, from, n);
6977- return n;
6978-}
6979-
6980 unsigned long copy_in_user(void __user *to, const void __user *from,
6981 unsigned long n)
6982 {
6983@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6984 return n;
6985 }
6986
6987-EXPORT_SYMBOL(copy_from_user);
6988-EXPORT_SYMBOL(copy_to_user);
6989 EXPORT_SYMBOL(copy_in_user);
6990
6991diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6992index 8726779..a33c512 100644
6993--- a/arch/powerpc/mm/fault.c
6994+++ b/arch/powerpc/mm/fault.c
6995@@ -33,6 +33,10 @@
6996 #include <linux/magic.h>
6997 #include <linux/ratelimit.h>
6998 #include <linux/context_tracking.h>
6999+#include <linux/slab.h>
7000+#include <linux/pagemap.h>
7001+#include <linux/compiler.h>
7002+#include <linux/unistd.h>
7003
7004 #include <asm/firmware.h>
7005 #include <asm/page.h>
7006@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
7007 }
7008 #endif
7009
7010+#ifdef CONFIG_PAX_PAGEEXEC
7011+/*
7012+ * PaX: decide what to do with offenders (regs->nip = fault address)
7013+ *
7014+ * returns 1 when task should be killed
7015+ */
7016+static int pax_handle_fetch_fault(struct pt_regs *regs)
7017+{
7018+ return 1;
7019+}
7020+
7021+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7022+{
7023+ unsigned long i;
7024+
7025+ printk(KERN_ERR "PAX: bytes at PC: ");
7026+ for (i = 0; i < 5; i++) {
7027+ unsigned int c;
7028+ if (get_user(c, (unsigned int __user *)pc+i))
7029+ printk(KERN_CONT "???????? ");
7030+ else
7031+ printk(KERN_CONT "%08x ", c);
7032+ }
7033+ printk("\n");
7034+}
7035+#endif
7036+
7037 /*
7038 * Check whether the instruction at regs->nip is a store using
7039 * an update addressing form which will update r1.
7040@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
7041 * indicate errors in DSISR but can validly be set in SRR1.
7042 */
7043 if (trap == 0x400)
7044- error_code &= 0x48200000;
7045+ error_code &= 0x58200000;
7046 else
7047 is_write = error_code & DSISR_ISSTORE;
7048 #else
7049@@ -371,7 +402,7 @@ good_area:
7050 * "undefined". Of those that can be set, this is the only
7051 * one which seems bad.
7052 */
7053- if (error_code & 0x10000000)
7054+ if (error_code & DSISR_GUARDED)
7055 /* Guarded storage error. */
7056 goto bad_area;
7057 #endif /* CONFIG_8xx */
7058@@ -386,7 +417,7 @@ good_area:
7059 * processors use the same I/D cache coherency mechanism
7060 * as embedded.
7061 */
7062- if (error_code & DSISR_PROTFAULT)
7063+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
7064 goto bad_area;
7065 #endif /* CONFIG_PPC_STD_MMU */
7066
7067@@ -471,6 +502,23 @@ bad_area:
7068 bad_area_nosemaphore:
7069 /* User mode accesses cause a SIGSEGV */
7070 if (user_mode(regs)) {
7071+
7072+#ifdef CONFIG_PAX_PAGEEXEC
7073+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7074+#ifdef CONFIG_PPC_STD_MMU
7075+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7076+#else
7077+ if (is_exec && regs->nip == address) {
7078+#endif
7079+ switch (pax_handle_fetch_fault(regs)) {
7080+ }
7081+
7082+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7083+ do_group_exit(SIGKILL);
7084+ }
7085+ }
7086+#endif
7087+
7088 _exception(SIGSEGV, regs, code, address);
7089 goto bail;
7090 }
7091diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7092index 67a42ed..cd463e0 100644
7093--- a/arch/powerpc/mm/mmap_64.c
7094+++ b/arch/powerpc/mm/mmap_64.c
7095@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7096 {
7097 unsigned long rnd = 0;
7098
7099+#ifdef CONFIG_PAX_RANDMMAP
7100+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7101+#endif
7102+
7103 if (current->flags & PF_RANDOMIZE) {
7104 /* 8MB for 32bit, 1GB for 64bit */
7105 if (is_32bit_task())
7106@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7107 */
7108 if (mmap_is_legacy()) {
7109 mm->mmap_base = TASK_UNMAPPED_BASE;
7110+
7111+#ifdef CONFIG_PAX_RANDMMAP
7112+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7113+ mm->mmap_base += mm->delta_mmap;
7114+#endif
7115+
7116 mm->get_unmapped_area = arch_get_unmapped_area;
7117 mm->unmap_area = arch_unmap_area;
7118 } else {
7119 mm->mmap_base = mmap_base();
7120+
7121+#ifdef CONFIG_PAX_RANDMMAP
7122+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7123+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7124+#endif
7125+
7126 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7127 mm->unmap_area = arch_unmap_area_topdown;
7128 }
7129diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7130index e779642..e5bb889 100644
7131--- a/arch/powerpc/mm/mmu_context_nohash.c
7132+++ b/arch/powerpc/mm/mmu_context_nohash.c
7133@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7134 return NOTIFY_OK;
7135 }
7136
7137-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7138+static struct notifier_block mmu_context_cpu_nb = {
7139 .notifier_call = mmu_context_cpu_notify,
7140 };
7141
7142diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7143index 88c0425..717feb8 100644
7144--- a/arch/powerpc/mm/numa.c
7145+++ b/arch/powerpc/mm/numa.c
7146@@ -919,7 +919,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7147 return ret;
7148 }
7149
7150-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7151+static struct notifier_block ppc64_numa_nb = {
7152 .notifier_call = cpu_numa_callback,
7153 .priority = 1 /* Must run before sched domains notifier. */
7154 };
7155diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7156index 3e99c14..f00953c 100644
7157--- a/arch/powerpc/mm/slice.c
7158+++ b/arch/powerpc/mm/slice.c
7159@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7160 if ((mm->task_size - len) < addr)
7161 return 0;
7162 vma = find_vma(mm, addr);
7163- return (!vma || (addr + len) <= vma->vm_start);
7164+ return check_heap_stack_gap(vma, addr, len, 0);
7165 }
7166
7167 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7168@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
7169 info.align_offset = 0;
7170
7171 addr = TASK_UNMAPPED_BASE;
7172+
7173+#ifdef CONFIG_PAX_RANDMMAP
7174+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7175+ addr += mm->delta_mmap;
7176+#endif
7177+
7178 while (addr < TASK_SIZE) {
7179 info.low_limit = addr;
7180 if (!slice_scan_available(addr, available, 1, &addr))
7181@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7182 if (fixed && addr > (mm->task_size - len))
7183 return -EINVAL;
7184
7185+#ifdef CONFIG_PAX_RANDMMAP
7186+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7187+ addr = 0;
7188+#endif
7189+
7190 /* If hint, make sure it matches our alignment restrictions */
7191 if (!fixed && addr) {
7192 addr = _ALIGN_UP(addr, 1ul << pshift);
7193diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
7194index 9098692..3d54cd1 100644
7195--- a/arch/powerpc/platforms/cell/spufs/file.c
7196+++ b/arch/powerpc/platforms/cell/spufs/file.c
7197@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7198 return VM_FAULT_NOPAGE;
7199 }
7200
7201-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
7202+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
7203 unsigned long address,
7204- void *buf, int len, int write)
7205+ void *buf, size_t len, int write)
7206 {
7207 struct spu_context *ctx = vma->vm_file->private_data;
7208 unsigned long offset = address - vma->vm_start;
7209diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7210index bdb738a..49c9f95 100644
7211--- a/arch/powerpc/platforms/powermac/smp.c
7212+++ b/arch/powerpc/platforms/powermac/smp.c
7213@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7214 return NOTIFY_OK;
7215 }
7216
7217-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7218+static struct notifier_block smp_core99_cpu_nb = {
7219 .notifier_call = smp_core99_cpu_notify,
7220 };
7221 #endif /* CONFIG_HOTPLUG_CPU */
7222diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7223index c797832..ce575c8 100644
7224--- a/arch/s390/include/asm/atomic.h
7225+++ b/arch/s390/include/asm/atomic.h
7226@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7227 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7228 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7229
7230+#define atomic64_read_unchecked(v) atomic64_read(v)
7231+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7232+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7233+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7234+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7235+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7236+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7237+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7238+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7239+
7240 #define smp_mb__before_atomic_dec() smp_mb()
7241 #define smp_mb__after_atomic_dec() smp_mb()
7242 #define smp_mb__before_atomic_inc() smp_mb()
7243diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7244index 4d7ccac..d03d0ad 100644
7245--- a/arch/s390/include/asm/cache.h
7246+++ b/arch/s390/include/asm/cache.h
7247@@ -9,8 +9,10 @@
7248 #ifndef __ARCH_S390_CACHE_H
7249 #define __ARCH_S390_CACHE_H
7250
7251-#define L1_CACHE_BYTES 256
7252+#include <linux/const.h>
7253+
7254 #define L1_CACHE_SHIFT 8
7255+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7256 #define NET_SKB_PAD 32
7257
7258 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7259diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7260index 78f4f87..598ce39 100644
7261--- a/arch/s390/include/asm/elf.h
7262+++ b/arch/s390/include/asm/elf.h
7263@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
7264 the loader. We need to make sure that it is out of the way of the program
7265 that it will "exec", and that there is sufficient room for the brk. */
7266
7267-extern unsigned long randomize_et_dyn(unsigned long base);
7268-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7269+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7270+
7271+#ifdef CONFIG_PAX_ASLR
7272+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7273+
7274+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7275+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7276+#endif
7277
7278 /* This yields a mask that user programs can use to figure out what
7279 instruction set this CPU supports. */
7280@@ -222,9 +228,6 @@ struct linux_binprm;
7281 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7282 int arch_setup_additional_pages(struct linux_binprm *, int);
7283
7284-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7285-#define arch_randomize_brk arch_randomize_brk
7286-
7287 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7288
7289 #endif
7290diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7291index c4a93d6..4d2a9b4 100644
7292--- a/arch/s390/include/asm/exec.h
7293+++ b/arch/s390/include/asm/exec.h
7294@@ -7,6 +7,6 @@
7295 #ifndef __ASM_EXEC_H
7296 #define __ASM_EXEC_H
7297
7298-extern unsigned long arch_align_stack(unsigned long sp);
7299+#define arch_align_stack(x) ((x) & ~0xfUL)
7300
7301 #endif /* __ASM_EXEC_H */
7302diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7303index 9c33ed4..e40cbef 100644
7304--- a/arch/s390/include/asm/uaccess.h
7305+++ b/arch/s390/include/asm/uaccess.h
7306@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7307 copy_to_user(void __user *to, const void *from, unsigned long n)
7308 {
7309 might_fault();
7310+
7311+ if ((long)n < 0)
7312+ return n;
7313+
7314 return __copy_to_user(to, from, n);
7315 }
7316
7317@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7318 static inline unsigned long __must_check
7319 __copy_from_user(void *to, const void __user *from, unsigned long n)
7320 {
7321+ if ((long)n < 0)
7322+ return n;
7323+
7324 if (__builtin_constant_p(n) && (n <= 256))
7325 return uaccess.copy_from_user_small(n, from, to);
7326 else
7327@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7328 static inline unsigned long __must_check
7329 copy_from_user(void *to, const void __user *from, unsigned long n)
7330 {
7331- unsigned int sz = __compiletime_object_size(to);
7332+ size_t sz = __compiletime_object_size(to);
7333
7334 might_fault();
7335- if (unlikely(sz != -1 && sz < n)) {
7336+
7337+ if ((long)n < 0)
7338+ return n;
7339+
7340+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7341 copy_from_user_overflow();
7342 return n;
7343 }
7344diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7345index 7845e15..59c4353 100644
7346--- a/arch/s390/kernel/module.c
7347+++ b/arch/s390/kernel/module.c
7348@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7349
7350 /* Increase core size by size of got & plt and set start
7351 offsets for got and plt. */
7352- me->core_size = ALIGN(me->core_size, 4);
7353- me->arch.got_offset = me->core_size;
7354- me->core_size += me->arch.got_size;
7355- me->arch.plt_offset = me->core_size;
7356- me->core_size += me->arch.plt_size;
7357+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7358+ me->arch.got_offset = me->core_size_rw;
7359+ me->core_size_rw += me->arch.got_size;
7360+ me->arch.plt_offset = me->core_size_rx;
7361+ me->core_size_rx += me->arch.plt_size;
7362 return 0;
7363 }
7364
7365@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7366 if (info->got_initialized == 0) {
7367 Elf_Addr *gotent;
7368
7369- gotent = me->module_core + me->arch.got_offset +
7370+ gotent = me->module_core_rw + me->arch.got_offset +
7371 info->got_offset;
7372 *gotent = val;
7373 info->got_initialized = 1;
7374@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7375 rc = apply_rela_bits(loc, val, 0, 64, 0);
7376 else if (r_type == R_390_GOTENT ||
7377 r_type == R_390_GOTPLTENT) {
7378- val += (Elf_Addr) me->module_core - loc;
7379+ val += (Elf_Addr) me->module_core_rw - loc;
7380 rc = apply_rela_bits(loc, val, 1, 32, 1);
7381 }
7382 break;
7383@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7384 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7385 if (info->plt_initialized == 0) {
7386 unsigned int *ip;
7387- ip = me->module_core + me->arch.plt_offset +
7388+ ip = me->module_core_rx + me->arch.plt_offset +
7389 info->plt_offset;
7390 #ifndef CONFIG_64BIT
7391 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7392@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7393 val - loc + 0xffffUL < 0x1ffffeUL) ||
7394 (r_type == R_390_PLT32DBL &&
7395 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7396- val = (Elf_Addr) me->module_core +
7397+ val = (Elf_Addr) me->module_core_rx +
7398 me->arch.plt_offset +
7399 info->plt_offset;
7400 val += rela->r_addend - loc;
7401@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7402 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7403 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7404 val = val + rela->r_addend -
7405- ((Elf_Addr) me->module_core + me->arch.got_offset);
7406+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7407 if (r_type == R_390_GOTOFF16)
7408 rc = apply_rela_bits(loc, val, 0, 16, 0);
7409 else if (r_type == R_390_GOTOFF32)
7410@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7411 break;
7412 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7413 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7414- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7415+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7416 rela->r_addend - loc;
7417 if (r_type == R_390_GOTPC)
7418 rc = apply_rela_bits(loc, val, 1, 32, 0);
7419diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7420index 2bc3edd..ab9d598 100644
7421--- a/arch/s390/kernel/process.c
7422+++ b/arch/s390/kernel/process.c
7423@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
7424 }
7425 return 0;
7426 }
7427-
7428-unsigned long arch_align_stack(unsigned long sp)
7429-{
7430- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7431- sp -= get_random_int() & ~PAGE_MASK;
7432- return sp & ~0xf;
7433-}
7434-
7435-static inline unsigned long brk_rnd(void)
7436-{
7437- /* 8MB for 32bit, 1GB for 64bit */
7438- if (is_32bit_task())
7439- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7440- else
7441- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7442-}
7443-
7444-unsigned long arch_randomize_brk(struct mm_struct *mm)
7445-{
7446- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7447-
7448- if (ret < mm->brk)
7449- return mm->brk;
7450- return ret;
7451-}
7452-
7453-unsigned long randomize_et_dyn(unsigned long base)
7454-{
7455- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7456-
7457- if (!(current->flags & PF_RANDOMIZE))
7458- return base;
7459- if (ret < base)
7460- return base;
7461- return ret;
7462-}
7463diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7464index 06bafec..2bca531 100644
7465--- a/arch/s390/mm/mmap.c
7466+++ b/arch/s390/mm/mmap.c
7467@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7468 */
7469 if (mmap_is_legacy()) {
7470 mm->mmap_base = TASK_UNMAPPED_BASE;
7471+
7472+#ifdef CONFIG_PAX_RANDMMAP
7473+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7474+ mm->mmap_base += mm->delta_mmap;
7475+#endif
7476+
7477 mm->get_unmapped_area = arch_get_unmapped_area;
7478 mm->unmap_area = arch_unmap_area;
7479 } else {
7480 mm->mmap_base = mmap_base();
7481+
7482+#ifdef CONFIG_PAX_RANDMMAP
7483+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7484+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7485+#endif
7486+
7487 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7488 mm->unmap_area = arch_unmap_area_topdown;
7489 }
7490@@ -175,10 +187,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7491 */
7492 if (mmap_is_legacy()) {
7493 mm->mmap_base = TASK_UNMAPPED_BASE;
7494+
7495+#ifdef CONFIG_PAX_RANDMMAP
7496+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7497+ mm->mmap_base += mm->delta_mmap;
7498+#endif
7499+
7500 mm->get_unmapped_area = s390_get_unmapped_area;
7501 mm->unmap_area = arch_unmap_area;
7502 } else {
7503 mm->mmap_base = mmap_base();
7504+
7505+#ifdef CONFIG_PAX_RANDMMAP
7506+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7507+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7508+#endif
7509+
7510 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7511 mm->unmap_area = arch_unmap_area_topdown;
7512 }
7513diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7514index ae3d59f..f65f075 100644
7515--- a/arch/score/include/asm/cache.h
7516+++ b/arch/score/include/asm/cache.h
7517@@ -1,7 +1,9 @@
7518 #ifndef _ASM_SCORE_CACHE_H
7519 #define _ASM_SCORE_CACHE_H
7520
7521+#include <linux/const.h>
7522+
7523 #define L1_CACHE_SHIFT 4
7524-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7525+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7526
7527 #endif /* _ASM_SCORE_CACHE_H */
7528diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7529index f9f3cd5..58ff438 100644
7530--- a/arch/score/include/asm/exec.h
7531+++ b/arch/score/include/asm/exec.h
7532@@ -1,6 +1,6 @@
7533 #ifndef _ASM_SCORE_EXEC_H
7534 #define _ASM_SCORE_EXEC_H
7535
7536-extern unsigned long arch_align_stack(unsigned long sp);
7537+#define arch_align_stack(x) (x)
7538
7539 #endif /* _ASM_SCORE_EXEC_H */
7540diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7541index f4c6d02..e9355c3 100644
7542--- a/arch/score/kernel/process.c
7543+++ b/arch/score/kernel/process.c
7544@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
7545
7546 return task_pt_regs(task)->cp0_epc;
7547 }
7548-
7549-unsigned long arch_align_stack(unsigned long sp)
7550-{
7551- return sp;
7552-}
7553diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7554index ef9e555..331bd29 100644
7555--- a/arch/sh/include/asm/cache.h
7556+++ b/arch/sh/include/asm/cache.h
7557@@ -9,10 +9,11 @@
7558 #define __ASM_SH_CACHE_H
7559 #ifdef __KERNEL__
7560
7561+#include <linux/const.h>
7562 #include <linux/init.h>
7563 #include <cpu/cache.h>
7564
7565-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7566+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7567
7568 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7569
7570diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7571index 03f2b55..b0270327 100644
7572--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7573+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7574@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7575 return NOTIFY_OK;
7576 }
7577
7578-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7579+static struct notifier_block shx3_cpu_notifier = {
7580 .notifier_call = shx3_cpu_callback,
7581 };
7582
7583diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7584index 6777177..cb5e44f 100644
7585--- a/arch/sh/mm/mmap.c
7586+++ b/arch/sh/mm/mmap.c
7587@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7588 struct mm_struct *mm = current->mm;
7589 struct vm_area_struct *vma;
7590 int do_colour_align;
7591+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7592 struct vm_unmapped_area_info info;
7593
7594 if (flags & MAP_FIXED) {
7595@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7596 if (filp || (flags & MAP_SHARED))
7597 do_colour_align = 1;
7598
7599+#ifdef CONFIG_PAX_RANDMMAP
7600+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7601+#endif
7602+
7603 if (addr) {
7604 if (do_colour_align)
7605 addr = COLOUR_ALIGN(addr, pgoff);
7606@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7607 addr = PAGE_ALIGN(addr);
7608
7609 vma = find_vma(mm, addr);
7610- if (TASK_SIZE - len >= addr &&
7611- (!vma || addr + len <= vma->vm_start))
7612+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7613 return addr;
7614 }
7615
7616 info.flags = 0;
7617 info.length = len;
7618- info.low_limit = TASK_UNMAPPED_BASE;
7619+ info.low_limit = mm->mmap_base;
7620 info.high_limit = TASK_SIZE;
7621 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7622 info.align_offset = pgoff << PAGE_SHIFT;
7623@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7624 struct mm_struct *mm = current->mm;
7625 unsigned long addr = addr0;
7626 int do_colour_align;
7627+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7628 struct vm_unmapped_area_info info;
7629
7630 if (flags & MAP_FIXED) {
7631@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7632 if (filp || (flags & MAP_SHARED))
7633 do_colour_align = 1;
7634
7635+#ifdef CONFIG_PAX_RANDMMAP
7636+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7637+#endif
7638+
7639 /* requesting a specific address */
7640 if (addr) {
7641 if (do_colour_align)
7642@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7643 addr = PAGE_ALIGN(addr);
7644
7645 vma = find_vma(mm, addr);
7646- if (TASK_SIZE - len >= addr &&
7647- (!vma || addr + len <= vma->vm_start))
7648+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7649 return addr;
7650 }
7651
7652@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7653 VM_BUG_ON(addr != -ENOMEM);
7654 info.flags = 0;
7655 info.low_limit = TASK_UNMAPPED_BASE;
7656+
7657+#ifdef CONFIG_PAX_RANDMMAP
7658+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7659+ info.low_limit += mm->delta_mmap;
7660+#endif
7661+
7662 info.high_limit = TASK_SIZE;
7663 addr = vm_unmapped_area(&info);
7664 }
7665diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7666index be56a24..443328f 100644
7667--- a/arch/sparc/include/asm/atomic_64.h
7668+++ b/arch/sparc/include/asm/atomic_64.h
7669@@ -14,18 +14,40 @@
7670 #define ATOMIC64_INIT(i) { (i) }
7671
7672 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7673+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7674+{
7675+ return v->counter;
7676+}
7677 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7678+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7679+{
7680+ return v->counter;
7681+}
7682
7683 #define atomic_set(v, i) (((v)->counter) = i)
7684+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7685+{
7686+ v->counter = i;
7687+}
7688 #define atomic64_set(v, i) (((v)->counter) = i)
7689+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7690+{
7691+ v->counter = i;
7692+}
7693
7694 extern void atomic_add(int, atomic_t *);
7695+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7696 extern void atomic64_add(long, atomic64_t *);
7697+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7698 extern void atomic_sub(int, atomic_t *);
7699+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7700 extern void atomic64_sub(long, atomic64_t *);
7701+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7702
7703 extern int atomic_add_ret(int, atomic_t *);
7704+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7705 extern long atomic64_add_ret(long, atomic64_t *);
7706+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7707 extern int atomic_sub_ret(int, atomic_t *);
7708 extern long atomic64_sub_ret(long, atomic64_t *);
7709
7710@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7711 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7712
7713 #define atomic_inc_return(v) atomic_add_ret(1, v)
7714+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7715+{
7716+ return atomic_add_ret_unchecked(1, v);
7717+}
7718 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7719+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7720+{
7721+ return atomic64_add_ret_unchecked(1, v);
7722+}
7723
7724 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7725 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7726
7727 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7728+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7729+{
7730+ return atomic_add_ret_unchecked(i, v);
7731+}
7732 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7733+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7734+{
7735+ return atomic64_add_ret_unchecked(i, v);
7736+}
7737
7738 /*
7739 * atomic_inc_and_test - increment and test
7740@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7741 * other cases.
7742 */
7743 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7744+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7745+{
7746+ return atomic_inc_return_unchecked(v) == 0;
7747+}
7748 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7749
7750 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7751@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7752 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7753
7754 #define atomic_inc(v) atomic_add(1, v)
7755+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7756+{
7757+ atomic_add_unchecked(1, v);
7758+}
7759 #define atomic64_inc(v) atomic64_add(1, v)
7760+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7761+{
7762+ atomic64_add_unchecked(1, v);
7763+}
7764
7765 #define atomic_dec(v) atomic_sub(1, v)
7766+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7767+{
7768+ atomic_sub_unchecked(1, v);
7769+}
7770 #define atomic64_dec(v) atomic64_sub(1, v)
7771+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7772+{
7773+ atomic64_sub_unchecked(1, v);
7774+}
7775
7776 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7777 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7778
7779 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7780+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7781+{
7782+ return cmpxchg(&v->counter, old, new);
7783+}
7784 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7785+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7786+{
7787+ return xchg(&v->counter, new);
7788+}
7789
7790 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7791 {
7792- int c, old;
7793+ int c, old, new;
7794 c = atomic_read(v);
7795 for (;;) {
7796- if (unlikely(c == (u)))
7797+ if (unlikely(c == u))
7798 break;
7799- old = atomic_cmpxchg((v), c, c + (a));
7800+
7801+ asm volatile("addcc %2, %0, %0\n"
7802+
7803+#ifdef CONFIG_PAX_REFCOUNT
7804+ "tvs %%icc, 6\n"
7805+#endif
7806+
7807+ : "=r" (new)
7808+ : "0" (c), "ir" (a)
7809+ : "cc");
7810+
7811+ old = atomic_cmpxchg(v, c, new);
7812 if (likely(old == c))
7813 break;
7814 c = old;
7815@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7816 #define atomic64_cmpxchg(v, o, n) \
7817 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7818 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7819+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7820+{
7821+ return xchg(&v->counter, new);
7822+}
7823
7824 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7825 {
7826- long c, old;
7827+ long c, old, new;
7828 c = atomic64_read(v);
7829 for (;;) {
7830- if (unlikely(c == (u)))
7831+ if (unlikely(c == u))
7832 break;
7833- old = atomic64_cmpxchg((v), c, c + (a));
7834+
7835+ asm volatile("addcc %2, %0, %0\n"
7836+
7837+#ifdef CONFIG_PAX_REFCOUNT
7838+ "tvs %%xcc, 6\n"
7839+#endif
7840+
7841+ : "=r" (new)
7842+ : "0" (c), "ir" (a)
7843+ : "cc");
7844+
7845+ old = atomic64_cmpxchg(v, c, new);
7846 if (likely(old == c))
7847 break;
7848 c = old;
7849 }
7850- return c != (u);
7851+ return c != u;
7852 }
7853
7854 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7855diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7856index 5bb6991..5c2132e 100644
7857--- a/arch/sparc/include/asm/cache.h
7858+++ b/arch/sparc/include/asm/cache.h
7859@@ -7,10 +7,12 @@
7860 #ifndef _SPARC_CACHE_H
7861 #define _SPARC_CACHE_H
7862
7863+#include <linux/const.h>
7864+
7865 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7866
7867 #define L1_CACHE_SHIFT 5
7868-#define L1_CACHE_BYTES 32
7869+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7870
7871 #ifdef CONFIG_SPARC32
7872 #define SMP_CACHE_BYTES_SHIFT 5
7873diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7874index a24e41f..47677ff 100644
7875--- a/arch/sparc/include/asm/elf_32.h
7876+++ b/arch/sparc/include/asm/elf_32.h
7877@@ -114,6 +114,13 @@ typedef struct {
7878
7879 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7880
7881+#ifdef CONFIG_PAX_ASLR
7882+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7883+
7884+#define PAX_DELTA_MMAP_LEN 16
7885+#define PAX_DELTA_STACK_LEN 16
7886+#endif
7887+
7888 /* This yields a mask that user programs can use to figure out what
7889 instruction set this cpu supports. This can NOT be done in userspace
7890 on Sparc. */
7891diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7892index 370ca1e..d4f4a98 100644
7893--- a/arch/sparc/include/asm/elf_64.h
7894+++ b/arch/sparc/include/asm/elf_64.h
7895@@ -189,6 +189,13 @@ typedef struct {
7896 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7897 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7898
7899+#ifdef CONFIG_PAX_ASLR
7900+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7901+
7902+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7903+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7904+#endif
7905+
7906 extern unsigned long sparc64_elf_hwcap;
7907 #define ELF_HWCAP sparc64_elf_hwcap
7908
7909diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7910index 9b1c36d..209298b 100644
7911--- a/arch/sparc/include/asm/pgalloc_32.h
7912+++ b/arch/sparc/include/asm/pgalloc_32.h
7913@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7914 }
7915
7916 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7917+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7918
7919 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7920 unsigned long address)
7921diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7922index bcfe063..b333142 100644
7923--- a/arch/sparc/include/asm/pgalloc_64.h
7924+++ b/arch/sparc/include/asm/pgalloc_64.h
7925@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7926 }
7927
7928 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7929+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7930
7931 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7932 {
7933diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7934index 6fc1348..390c50a 100644
7935--- a/arch/sparc/include/asm/pgtable_32.h
7936+++ b/arch/sparc/include/asm/pgtable_32.h
7937@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7938 #define PAGE_SHARED SRMMU_PAGE_SHARED
7939 #define PAGE_COPY SRMMU_PAGE_COPY
7940 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7941+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7942+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7943+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7944 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7945
7946 /* Top-level page directory - dummy used by init-mm.
7947@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7948
7949 /* xwr */
7950 #define __P000 PAGE_NONE
7951-#define __P001 PAGE_READONLY
7952-#define __P010 PAGE_COPY
7953-#define __P011 PAGE_COPY
7954+#define __P001 PAGE_READONLY_NOEXEC
7955+#define __P010 PAGE_COPY_NOEXEC
7956+#define __P011 PAGE_COPY_NOEXEC
7957 #define __P100 PAGE_READONLY
7958 #define __P101 PAGE_READONLY
7959 #define __P110 PAGE_COPY
7960 #define __P111 PAGE_COPY
7961
7962 #define __S000 PAGE_NONE
7963-#define __S001 PAGE_READONLY
7964-#define __S010 PAGE_SHARED
7965-#define __S011 PAGE_SHARED
7966+#define __S001 PAGE_READONLY_NOEXEC
7967+#define __S010 PAGE_SHARED_NOEXEC
7968+#define __S011 PAGE_SHARED_NOEXEC
7969 #define __S100 PAGE_READONLY
7970 #define __S101 PAGE_READONLY
7971 #define __S110 PAGE_SHARED
7972diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7973index 79da178..c2eede8 100644
7974--- a/arch/sparc/include/asm/pgtsrmmu.h
7975+++ b/arch/sparc/include/asm/pgtsrmmu.h
7976@@ -115,6 +115,11 @@
7977 SRMMU_EXEC | SRMMU_REF)
7978 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7979 SRMMU_EXEC | SRMMU_REF)
7980+
7981+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7982+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7983+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7984+
7985 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7986 SRMMU_DIRTY | SRMMU_REF)
7987
7988diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7989index 9689176..63c18ea 100644
7990--- a/arch/sparc/include/asm/spinlock_64.h
7991+++ b/arch/sparc/include/asm/spinlock_64.h
7992@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7993
7994 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7995
7996-static void inline arch_read_lock(arch_rwlock_t *lock)
7997+static inline void arch_read_lock(arch_rwlock_t *lock)
7998 {
7999 unsigned long tmp1, tmp2;
8000
8001 __asm__ __volatile__ (
8002 "1: ldsw [%2], %0\n"
8003 " brlz,pn %0, 2f\n"
8004-"4: add %0, 1, %1\n"
8005+"4: addcc %0, 1, %1\n"
8006+
8007+#ifdef CONFIG_PAX_REFCOUNT
8008+" tvs %%icc, 6\n"
8009+#endif
8010+
8011 " cas [%2], %0, %1\n"
8012 " cmp %0, %1\n"
8013 " bne,pn %%icc, 1b\n"
8014@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8015 " .previous"
8016 : "=&r" (tmp1), "=&r" (tmp2)
8017 : "r" (lock)
8018- : "memory");
8019+ : "memory", "cc");
8020 }
8021
8022-static int inline arch_read_trylock(arch_rwlock_t *lock)
8023+static inline int arch_read_trylock(arch_rwlock_t *lock)
8024 {
8025 int tmp1, tmp2;
8026
8027@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8028 "1: ldsw [%2], %0\n"
8029 " brlz,a,pn %0, 2f\n"
8030 " mov 0, %0\n"
8031-" add %0, 1, %1\n"
8032+" addcc %0, 1, %1\n"
8033+
8034+#ifdef CONFIG_PAX_REFCOUNT
8035+" tvs %%icc, 6\n"
8036+#endif
8037+
8038 " cas [%2], %0, %1\n"
8039 " cmp %0, %1\n"
8040 " bne,pn %%icc, 1b\n"
8041@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8042 return tmp1;
8043 }
8044
8045-static void inline arch_read_unlock(arch_rwlock_t *lock)
8046+static inline void arch_read_unlock(arch_rwlock_t *lock)
8047 {
8048 unsigned long tmp1, tmp2;
8049
8050 __asm__ __volatile__(
8051 "1: lduw [%2], %0\n"
8052-" sub %0, 1, %1\n"
8053+" subcc %0, 1, %1\n"
8054+
8055+#ifdef CONFIG_PAX_REFCOUNT
8056+" tvs %%icc, 6\n"
8057+#endif
8058+
8059 " cas [%2], %0, %1\n"
8060 " cmp %0, %1\n"
8061 " bne,pn %%xcc, 1b\n"
8062@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8063 : "memory");
8064 }
8065
8066-static void inline arch_write_lock(arch_rwlock_t *lock)
8067+static inline void arch_write_lock(arch_rwlock_t *lock)
8068 {
8069 unsigned long mask, tmp1, tmp2;
8070
8071@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8072 : "memory");
8073 }
8074
8075-static void inline arch_write_unlock(arch_rwlock_t *lock)
8076+static inline void arch_write_unlock(arch_rwlock_t *lock)
8077 {
8078 __asm__ __volatile__(
8079 " stw %%g0, [%0]"
8080@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8081 : "memory");
8082 }
8083
8084-static int inline arch_write_trylock(arch_rwlock_t *lock)
8085+static inline int arch_write_trylock(arch_rwlock_t *lock)
8086 {
8087 unsigned long mask, tmp1, tmp2, result;
8088
8089diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8090index dd38075..e7cac83 100644
8091--- a/arch/sparc/include/asm/thread_info_32.h
8092+++ b/arch/sparc/include/asm/thread_info_32.h
8093@@ -49,6 +49,8 @@ struct thread_info {
8094 unsigned long w_saved;
8095
8096 struct restart_block restart_block;
8097+
8098+ unsigned long lowest_stack;
8099 };
8100
8101 /*
8102diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8103index d5e5042..9bfee76 100644
8104--- a/arch/sparc/include/asm/thread_info_64.h
8105+++ b/arch/sparc/include/asm/thread_info_64.h
8106@@ -63,6 +63,8 @@ struct thread_info {
8107 struct pt_regs *kern_una_regs;
8108 unsigned int kern_una_insn;
8109
8110+ unsigned long lowest_stack;
8111+
8112 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8113 };
8114
8115@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8116 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8117 /* flag bit 6 is available */
8118 #define TIF_32BIT 7 /* 32-bit binary */
8119-/* flag bit 8 is available */
8120+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8121 #define TIF_SECCOMP 9 /* secure computing */
8122 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8123 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8124+
8125 /* NOTE: Thread flags >= 12 should be ones we have no interest
8126 * in using in assembly, else we can't use the mask as
8127 * an immediate value in instructions such as andcc.
8128@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8129 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8130 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8131 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8132+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8133
8134 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8135 _TIF_DO_NOTIFY_RESUME_MASK | \
8136 _TIF_NEED_RESCHED)
8137 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8138
8139+#define _TIF_WORK_SYSCALL \
8140+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8141+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8142+
8143+
8144 /*
8145 * Thread-synchronous status.
8146 *
8147diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8148index 0167d26..767bb0c 100644
8149--- a/arch/sparc/include/asm/uaccess.h
8150+++ b/arch/sparc/include/asm/uaccess.h
8151@@ -1,5 +1,6 @@
8152 #ifndef ___ASM_SPARC_UACCESS_H
8153 #define ___ASM_SPARC_UACCESS_H
8154+
8155 #if defined(__sparc__) && defined(__arch64__)
8156 #include <asm/uaccess_64.h>
8157 #else
8158diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8159index 53a28dd..50c38c3 100644
8160--- a/arch/sparc/include/asm/uaccess_32.h
8161+++ b/arch/sparc/include/asm/uaccess_32.h
8162@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8163
8164 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8165 {
8166- if (n && __access_ok((unsigned long) to, n))
8167+ if ((long)n < 0)
8168+ return n;
8169+
8170+ if (n && __access_ok((unsigned long) to, n)) {
8171+ if (!__builtin_constant_p(n))
8172+ check_object_size(from, n, true);
8173 return __copy_user(to, (__force void __user *) from, n);
8174- else
8175+ } else
8176 return n;
8177 }
8178
8179 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8180 {
8181+ if ((long)n < 0)
8182+ return n;
8183+
8184+ if (!__builtin_constant_p(n))
8185+ check_object_size(from, n, true);
8186+
8187 return __copy_user(to, (__force void __user *) from, n);
8188 }
8189
8190 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8191 {
8192- if (n && __access_ok((unsigned long) from, n))
8193+ if ((long)n < 0)
8194+ return n;
8195+
8196+ if (n && __access_ok((unsigned long) from, n)) {
8197+ if (!__builtin_constant_p(n))
8198+ check_object_size(to, n, false);
8199 return __copy_user((__force void __user *) to, from, n);
8200- else
8201+ } else
8202 return n;
8203 }
8204
8205 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8206 {
8207+ if ((long)n < 0)
8208+ return n;
8209+
8210 return __copy_user((__force void __user *) to, from, n);
8211 }
8212
8213diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8214index e562d3c..191f176 100644
8215--- a/arch/sparc/include/asm/uaccess_64.h
8216+++ b/arch/sparc/include/asm/uaccess_64.h
8217@@ -10,6 +10,7 @@
8218 #include <linux/compiler.h>
8219 #include <linux/string.h>
8220 #include <linux/thread_info.h>
8221+#include <linux/kernel.h>
8222 #include <asm/asi.h>
8223 #include <asm/spitfire.h>
8224 #include <asm-generic/uaccess-unaligned.h>
8225@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8226 static inline unsigned long __must_check
8227 copy_from_user(void *to, const void __user *from, unsigned long size)
8228 {
8229- unsigned long ret = ___copy_from_user(to, from, size);
8230+ unsigned long ret;
8231
8232+ if ((long)size < 0 || size > INT_MAX)
8233+ return size;
8234+
8235+ if (!__builtin_constant_p(size))
8236+ check_object_size(to, size, false);
8237+
8238+ ret = ___copy_from_user(to, from, size);
8239 if (unlikely(ret))
8240 ret = copy_from_user_fixup(to, from, size);
8241
8242@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8243 static inline unsigned long __must_check
8244 copy_to_user(void __user *to, const void *from, unsigned long size)
8245 {
8246- unsigned long ret = ___copy_to_user(to, from, size);
8247+ unsigned long ret;
8248
8249+ if ((long)size < 0 || size > INT_MAX)
8250+ return size;
8251+
8252+ if (!__builtin_constant_p(size))
8253+ check_object_size(from, size, true);
8254+
8255+ ret = ___copy_to_user(to, from, size);
8256 if (unlikely(ret))
8257 ret = copy_to_user_fixup(to, from, size);
8258 return ret;
8259diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8260index d432fb2..6056af1 100644
8261--- a/arch/sparc/kernel/Makefile
8262+++ b/arch/sparc/kernel/Makefile
8263@@ -3,7 +3,7 @@
8264 #
8265
8266 asflags-y := -ansi
8267-ccflags-y := -Werror
8268+#ccflags-y := -Werror
8269
8270 extra-y := head_$(BITS).o
8271
8272diff --git a/arch/sparc/kernel/ds.c b/arch/sparc/kernel/ds.c
8273index 5ef48da..11d460f 100644
8274--- a/arch/sparc/kernel/ds.c
8275+++ b/arch/sparc/kernel/ds.c
8276@@ -783,6 +783,16 @@ void ldom_set_var(const char *var, const char *value)
8277 char *base, *p;
8278 int msg_len, loops;
8279
8280+ if (strlen(var) + strlen(value) + 2 >
8281+ sizeof(pkt) - sizeof(pkt.header)) {
8282+ printk(KERN_ERR PFX
8283+ "contents length: %zu, which more than max: %lu,"
8284+ "so could not set (%s) variable to (%s).\n",
8285+ strlen(var) + strlen(value) + 2,
8286+ sizeof(pkt) - sizeof(pkt.header), var, value);
8287+ return;
8288+ }
8289+
8290 memset(&pkt, 0, sizeof(pkt));
8291 pkt.header.data.tag.type = DS_DATA;
8292 pkt.header.data.handle = cp->handle;
8293diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8294index fdd819d..5af08c8 100644
8295--- a/arch/sparc/kernel/process_32.c
8296+++ b/arch/sparc/kernel/process_32.c
8297@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
8298
8299 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8300 r->psr, r->pc, r->npc, r->y, print_tainted());
8301- printk("PC: <%pS>\n", (void *) r->pc);
8302+ printk("PC: <%pA>\n", (void *) r->pc);
8303 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8304 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8305 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8306 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8307 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8308 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8309- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8310+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8311
8312 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8313 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8314@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8315 rw = (struct reg_window32 *) fp;
8316 pc = rw->ins[7];
8317 printk("[%08lx : ", pc);
8318- printk("%pS ] ", (void *) pc);
8319+ printk("%pA ] ", (void *) pc);
8320 fp = rw->ins[6];
8321 } while (++count < 16);
8322 printk("\n");
8323diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8324index baebab2..9cd13b1 100644
8325--- a/arch/sparc/kernel/process_64.c
8326+++ b/arch/sparc/kernel/process_64.c
8327@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
8328 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8329 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8330 if (regs->tstate & TSTATE_PRIV)
8331- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8332+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8333 }
8334
8335 void show_regs(struct pt_regs *regs)
8336@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
8337
8338 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8339 regs->tpc, regs->tnpc, regs->y, print_tainted());
8340- printk("TPC: <%pS>\n", (void *) regs->tpc);
8341+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8342 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8343 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8344 regs->u_regs[3]);
8345@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
8346 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8347 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8348 regs->u_regs[15]);
8349- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8350+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8351 show_regwindow(regs);
8352 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8353 }
8354@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
8355 ((tp && tp->task) ? tp->task->pid : -1));
8356
8357 if (gp->tstate & TSTATE_PRIV) {
8358- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8359+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8360 (void *) gp->tpc,
8361 (void *) gp->o7,
8362 (void *) gp->i7,
8363diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
8364index 79cc0d1..ec62734 100644
8365--- a/arch/sparc/kernel/prom_common.c
8366+++ b/arch/sparc/kernel/prom_common.c
8367@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
8368
8369 unsigned int prom_early_allocated __initdata;
8370
8371-static struct of_pdt_ops prom_sparc_ops __initdata = {
8372+static struct of_pdt_ops prom_sparc_ops __initconst = {
8373 .nextprop = prom_common_nextprop,
8374 .getproplen = prom_getproplen,
8375 .getproperty = prom_getproperty,
8376diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8377index 7ff45e4..a58f271 100644
8378--- a/arch/sparc/kernel/ptrace_64.c
8379+++ b/arch/sparc/kernel/ptrace_64.c
8380@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8381 return ret;
8382 }
8383
8384+#ifdef CONFIG_GRKERNSEC_SETXID
8385+extern void gr_delayed_cred_worker(void);
8386+#endif
8387+
8388 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8389 {
8390 int ret = 0;
8391@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8392 /* do the secure computing check first */
8393 secure_computing_strict(regs->u_regs[UREG_G1]);
8394
8395+#ifdef CONFIG_GRKERNSEC_SETXID
8396+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8397+ gr_delayed_cred_worker();
8398+#endif
8399+
8400 if (test_thread_flag(TIF_SYSCALL_TRACE))
8401 ret = tracehook_report_syscall_entry(regs);
8402
8403@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8404
8405 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8406 {
8407+#ifdef CONFIG_GRKERNSEC_SETXID
8408+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8409+ gr_delayed_cred_worker();
8410+#endif
8411+
8412 audit_syscall_exit(regs);
8413
8414 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8415diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8416index 3a8d184..49498a8 100644
8417--- a/arch/sparc/kernel/sys_sparc_32.c
8418+++ b/arch/sparc/kernel/sys_sparc_32.c
8419@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8420 if (len > TASK_SIZE - PAGE_SIZE)
8421 return -ENOMEM;
8422 if (!addr)
8423- addr = TASK_UNMAPPED_BASE;
8424+ addr = current->mm->mmap_base;
8425
8426 info.flags = 0;
8427 info.length = len;
8428diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8429index 2daaaa6..d29bb82 100644
8430--- a/arch/sparc/kernel/sys_sparc_64.c
8431+++ b/arch/sparc/kernel/sys_sparc_64.c
8432@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8433 struct vm_area_struct * vma;
8434 unsigned long task_size = TASK_SIZE;
8435 int do_color_align;
8436+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8437 struct vm_unmapped_area_info info;
8438
8439 if (flags & MAP_FIXED) {
8440 /* We do not accept a shared mapping if it would violate
8441 * cache aliasing constraints.
8442 */
8443- if ((flags & MAP_SHARED) &&
8444+ if ((filp || (flags & MAP_SHARED)) &&
8445 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8446 return -EINVAL;
8447 return addr;
8448@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8449 if (filp || (flags & MAP_SHARED))
8450 do_color_align = 1;
8451
8452+#ifdef CONFIG_PAX_RANDMMAP
8453+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8454+#endif
8455+
8456 if (addr) {
8457 if (do_color_align)
8458 addr = COLOR_ALIGN(addr, pgoff);
8459@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8460 addr = PAGE_ALIGN(addr);
8461
8462 vma = find_vma(mm, addr);
8463- if (task_size - len >= addr &&
8464- (!vma || addr + len <= vma->vm_start))
8465+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8466 return addr;
8467 }
8468
8469 info.flags = 0;
8470 info.length = len;
8471- info.low_limit = TASK_UNMAPPED_BASE;
8472+ info.low_limit = mm->mmap_base;
8473 info.high_limit = min(task_size, VA_EXCLUDE_START);
8474 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8475 info.align_offset = pgoff << PAGE_SHIFT;
8476+ info.threadstack_offset = offset;
8477 addr = vm_unmapped_area(&info);
8478
8479 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8480 VM_BUG_ON(addr != -ENOMEM);
8481 info.low_limit = VA_EXCLUDE_END;
8482+
8483+#ifdef CONFIG_PAX_RANDMMAP
8484+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8485+ info.low_limit += mm->delta_mmap;
8486+#endif
8487+
8488 info.high_limit = task_size;
8489 addr = vm_unmapped_area(&info);
8490 }
8491@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8492 unsigned long task_size = STACK_TOP32;
8493 unsigned long addr = addr0;
8494 int do_color_align;
8495+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8496 struct vm_unmapped_area_info info;
8497
8498 /* This should only ever run for 32-bit processes. */
8499@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8500 /* We do not accept a shared mapping if it would violate
8501 * cache aliasing constraints.
8502 */
8503- if ((flags & MAP_SHARED) &&
8504+ if ((filp || (flags & MAP_SHARED)) &&
8505 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8506 return -EINVAL;
8507 return addr;
8508@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8509 if (filp || (flags & MAP_SHARED))
8510 do_color_align = 1;
8511
8512+#ifdef CONFIG_PAX_RANDMMAP
8513+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8514+#endif
8515+
8516 /* requesting a specific address */
8517 if (addr) {
8518 if (do_color_align)
8519@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8520 addr = PAGE_ALIGN(addr);
8521
8522 vma = find_vma(mm, addr);
8523- if (task_size - len >= addr &&
8524- (!vma || addr + len <= vma->vm_start))
8525+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8526 return addr;
8527 }
8528
8529@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8530 info.high_limit = mm->mmap_base;
8531 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8532 info.align_offset = pgoff << PAGE_SHIFT;
8533+ info.threadstack_offset = offset;
8534 addr = vm_unmapped_area(&info);
8535
8536 /*
8537@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8538 VM_BUG_ON(addr != -ENOMEM);
8539 info.flags = 0;
8540 info.low_limit = TASK_UNMAPPED_BASE;
8541+
8542+#ifdef CONFIG_PAX_RANDMMAP
8543+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8544+ info.low_limit += mm->delta_mmap;
8545+#endif
8546+
8547 info.high_limit = STACK_TOP32;
8548 addr = vm_unmapped_area(&info);
8549 }
8550@@ -264,6 +286,10 @@ static unsigned long mmap_rnd(void)
8551 {
8552 unsigned long rnd = 0UL;
8553
8554+#ifdef CONFIG_PAX_RANDMMAP
8555+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8556+#endif
8557+
8558 if (current->flags & PF_RANDOMIZE) {
8559 unsigned long val = get_random_int();
8560 if (test_thread_flag(TIF_32BIT))
8561@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8562 gap == RLIM_INFINITY ||
8563 sysctl_legacy_va_layout) {
8564 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8565+
8566+#ifdef CONFIG_PAX_RANDMMAP
8567+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8568+ mm->mmap_base += mm->delta_mmap;
8569+#endif
8570+
8571 mm->get_unmapped_area = arch_get_unmapped_area;
8572 mm->unmap_area = arch_unmap_area;
8573 } else {
8574@@ -301,6 +333,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8575 gap = (task_size / 6 * 5);
8576
8577 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8578+
8579+#ifdef CONFIG_PAX_RANDMMAP
8580+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8581+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8582+#endif
8583+
8584 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8585 mm->unmap_area = arch_unmap_area_topdown;
8586 }
8587diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8588index 22a1098..6255eb9 100644
8589--- a/arch/sparc/kernel/syscalls.S
8590+++ b/arch/sparc/kernel/syscalls.S
8591@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
8592 #endif
8593 .align 32
8594 1: ldx [%g6 + TI_FLAGS], %l5
8595- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8596+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8597 be,pt %icc, rtrap
8598 nop
8599 call syscall_trace_leave
8600@@ -184,7 +184,7 @@ linux_sparc_syscall32:
8601
8602 srl %i5, 0, %o5 ! IEU1
8603 srl %i2, 0, %o2 ! IEU0 Group
8604- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8605+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8606 bne,pn %icc, linux_syscall_trace32 ! CTI
8607 mov %i0, %l5 ! IEU1
8608 call %l7 ! CTI Group brk forced
8609@@ -207,7 +207,7 @@ linux_sparc_syscall:
8610
8611 mov %i3, %o3 ! IEU1
8612 mov %i4, %o4 ! IEU0 Group
8613- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8614+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8615 bne,pn %icc, linux_syscall_trace ! CTI Group
8616 mov %i0, %l5 ! IEU0
8617 2: call %l7 ! CTI Group brk forced
8618@@ -223,7 +223,7 @@ ret_sys_call:
8619
8620 cmp %o0, -ERESTART_RESTARTBLOCK
8621 bgeu,pn %xcc, 1f
8622- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8623+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8624 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8625
8626 2:
8627diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8628index 654e8aa..45f431b 100644
8629--- a/arch/sparc/kernel/sysfs.c
8630+++ b/arch/sparc/kernel/sysfs.c
8631@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8632 return NOTIFY_OK;
8633 }
8634
8635-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8636+static struct notifier_block sysfs_cpu_nb = {
8637 .notifier_call = sysfs_cpu_notify,
8638 };
8639
8640diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8641index 6629829..036032d 100644
8642--- a/arch/sparc/kernel/traps_32.c
8643+++ b/arch/sparc/kernel/traps_32.c
8644@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8645 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8646 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8647
8648+extern void gr_handle_kernel_exploit(void);
8649+
8650 void die_if_kernel(char *str, struct pt_regs *regs)
8651 {
8652 static int die_counter;
8653@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8654 count++ < 30 &&
8655 (((unsigned long) rw) >= PAGE_OFFSET) &&
8656 !(((unsigned long) rw) & 0x7)) {
8657- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8658+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8659 (void *) rw->ins[7]);
8660 rw = (struct reg_window32 *)rw->ins[6];
8661 }
8662 }
8663 printk("Instruction DUMP:");
8664 instruction_dump ((unsigned long *) regs->pc);
8665- if(regs->psr & PSR_PS)
8666+ if(regs->psr & PSR_PS) {
8667+ gr_handle_kernel_exploit();
8668 do_exit(SIGKILL);
8669+ }
8670 do_exit(SIGSEGV);
8671 }
8672
8673diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8674index b3f833a..ac74b2d 100644
8675--- a/arch/sparc/kernel/traps_64.c
8676+++ b/arch/sparc/kernel/traps_64.c
8677@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8678 i + 1,
8679 p->trapstack[i].tstate, p->trapstack[i].tpc,
8680 p->trapstack[i].tnpc, p->trapstack[i].tt);
8681- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8682+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8683 }
8684 }
8685
8686@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8687
8688 lvl -= 0x100;
8689 if (regs->tstate & TSTATE_PRIV) {
8690+
8691+#ifdef CONFIG_PAX_REFCOUNT
8692+ if (lvl == 6)
8693+ pax_report_refcount_overflow(regs);
8694+#endif
8695+
8696 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8697 die_if_kernel(buffer, regs);
8698 }
8699@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8700 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8701 {
8702 char buffer[32];
8703-
8704+
8705 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8706 0, lvl, SIGTRAP) == NOTIFY_STOP)
8707 return;
8708
8709+#ifdef CONFIG_PAX_REFCOUNT
8710+ if (lvl == 6)
8711+ pax_report_refcount_overflow(regs);
8712+#endif
8713+
8714 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8715
8716 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8717@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8718 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8719 printk("%s" "ERROR(%d): ",
8720 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8721- printk("TPC<%pS>\n", (void *) regs->tpc);
8722+ printk("TPC<%pA>\n", (void *) regs->tpc);
8723 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8724 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8725 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8726@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8727 smp_processor_id(),
8728 (type & 0x1) ? 'I' : 'D',
8729 regs->tpc);
8730- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8731+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8732 panic("Irrecoverable Cheetah+ parity error.");
8733 }
8734
8735@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8736 smp_processor_id(),
8737 (type & 0x1) ? 'I' : 'D',
8738 regs->tpc);
8739- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8740+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8741 }
8742
8743 struct sun4v_error_entry {
8744@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8745
8746 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8747 regs->tpc, tl);
8748- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8749+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8750 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8751- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8752+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8753 (void *) regs->u_regs[UREG_I7]);
8754 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8755 "pte[%lx] error[%lx]\n",
8756@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8757
8758 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8759 regs->tpc, tl);
8760- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8761+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8762 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8763- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8764+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8765 (void *) regs->u_regs[UREG_I7]);
8766 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8767 "pte[%lx] error[%lx]\n",
8768@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8769 fp = (unsigned long)sf->fp + STACK_BIAS;
8770 }
8771
8772- printk(" [%016lx] %pS\n", pc, (void *) pc);
8773+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8774 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8775 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8776 int index = tsk->curr_ret_stack;
8777 if (tsk->ret_stack && index >= graph) {
8778 pc = tsk->ret_stack[index - graph].ret;
8779- printk(" [%016lx] %pS\n", pc, (void *) pc);
8780+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8781 graph++;
8782 }
8783 }
8784@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8785 return (struct reg_window *) (fp + STACK_BIAS);
8786 }
8787
8788+extern void gr_handle_kernel_exploit(void);
8789+
8790 void die_if_kernel(char *str, struct pt_regs *regs)
8791 {
8792 static int die_counter;
8793@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8794 while (rw &&
8795 count++ < 30 &&
8796 kstack_valid(tp, (unsigned long) rw)) {
8797- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8798+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8799 (void *) rw->ins[7]);
8800
8801 rw = kernel_stack_up(rw);
8802@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8803 }
8804 user_instruction_dump ((unsigned int __user *) regs->tpc);
8805 }
8806- if (regs->tstate & TSTATE_PRIV)
8807+ if (regs->tstate & TSTATE_PRIV) {
8808+ gr_handle_kernel_exploit();
8809 do_exit(SIGKILL);
8810+ }
8811 do_exit(SIGSEGV);
8812 }
8813 EXPORT_SYMBOL(die_if_kernel);
8814diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8815index 8201c25e..072a2a7 100644
8816--- a/arch/sparc/kernel/unaligned_64.c
8817+++ b/arch/sparc/kernel/unaligned_64.c
8818@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8819 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8820
8821 if (__ratelimit(&ratelimit)) {
8822- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8823+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8824 regs->tpc, (void *) regs->tpc);
8825 }
8826 }
8827diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8828index dbe119b..089c7c1 100644
8829--- a/arch/sparc/lib/Makefile
8830+++ b/arch/sparc/lib/Makefile
8831@@ -2,7 +2,7 @@
8832 #
8833
8834 asflags-y := -ansi -DST_DIV0=0x02
8835-ccflags-y := -Werror
8836+#ccflags-y := -Werror
8837
8838 lib-$(CONFIG_SPARC32) += ashrdi3.o
8839 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8840diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8841index 85c233d..68500e0 100644
8842--- a/arch/sparc/lib/atomic_64.S
8843+++ b/arch/sparc/lib/atomic_64.S
8844@@ -17,7 +17,12 @@
8845 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8846 BACKOFF_SETUP(%o2)
8847 1: lduw [%o1], %g1
8848- add %g1, %o0, %g7
8849+ addcc %g1, %o0, %g7
8850+
8851+#ifdef CONFIG_PAX_REFCOUNT
8852+ tvs %icc, 6
8853+#endif
8854+
8855 cas [%o1], %g1, %g7
8856 cmp %g1, %g7
8857 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8858@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8859 2: BACKOFF_SPIN(%o2, %o3, 1b)
8860 ENDPROC(atomic_add)
8861
8862+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8863+ BACKOFF_SETUP(%o2)
8864+1: lduw [%o1], %g1
8865+ add %g1, %o0, %g7
8866+ cas [%o1], %g1, %g7
8867+ cmp %g1, %g7
8868+ bne,pn %icc, 2f
8869+ nop
8870+ retl
8871+ nop
8872+2: BACKOFF_SPIN(%o2, %o3, 1b)
8873+ENDPROC(atomic_add_unchecked)
8874+
8875 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8876 BACKOFF_SETUP(%o2)
8877 1: lduw [%o1], %g1
8878- sub %g1, %o0, %g7
8879+ subcc %g1, %o0, %g7
8880+
8881+#ifdef CONFIG_PAX_REFCOUNT
8882+ tvs %icc, 6
8883+#endif
8884+
8885 cas [%o1], %g1, %g7
8886 cmp %g1, %g7
8887 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8888@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8889 2: BACKOFF_SPIN(%o2, %o3, 1b)
8890 ENDPROC(atomic_sub)
8891
8892+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8893+ BACKOFF_SETUP(%o2)
8894+1: lduw [%o1], %g1
8895+ sub %g1, %o0, %g7
8896+ cas [%o1], %g1, %g7
8897+ cmp %g1, %g7
8898+ bne,pn %icc, 2f
8899+ nop
8900+ retl
8901+ nop
8902+2: BACKOFF_SPIN(%o2, %o3, 1b)
8903+ENDPROC(atomic_sub_unchecked)
8904+
8905 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8906 BACKOFF_SETUP(%o2)
8907 1: lduw [%o1], %g1
8908- add %g1, %o0, %g7
8909+ addcc %g1, %o0, %g7
8910+
8911+#ifdef CONFIG_PAX_REFCOUNT
8912+ tvs %icc, 6
8913+#endif
8914+
8915 cas [%o1], %g1, %g7
8916 cmp %g1, %g7
8917 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8918@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8919 2: BACKOFF_SPIN(%o2, %o3, 1b)
8920 ENDPROC(atomic_add_ret)
8921
8922+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8923+ BACKOFF_SETUP(%o2)
8924+1: lduw [%o1], %g1
8925+ addcc %g1, %o0, %g7
8926+ cas [%o1], %g1, %g7
8927+ cmp %g1, %g7
8928+ bne,pn %icc, 2f
8929+ add %g7, %o0, %g7
8930+ sra %g7, 0, %o0
8931+ retl
8932+ nop
8933+2: BACKOFF_SPIN(%o2, %o3, 1b)
8934+ENDPROC(atomic_add_ret_unchecked)
8935+
8936 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8937 BACKOFF_SETUP(%o2)
8938 1: lduw [%o1], %g1
8939- sub %g1, %o0, %g7
8940+ subcc %g1, %o0, %g7
8941+
8942+#ifdef CONFIG_PAX_REFCOUNT
8943+ tvs %icc, 6
8944+#endif
8945+
8946 cas [%o1], %g1, %g7
8947 cmp %g1, %g7
8948 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8949@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8950 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8951 BACKOFF_SETUP(%o2)
8952 1: ldx [%o1], %g1
8953- add %g1, %o0, %g7
8954+ addcc %g1, %o0, %g7
8955+
8956+#ifdef CONFIG_PAX_REFCOUNT
8957+ tvs %xcc, 6
8958+#endif
8959+
8960 casx [%o1], %g1, %g7
8961 cmp %g1, %g7
8962 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8963@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8964 2: BACKOFF_SPIN(%o2, %o3, 1b)
8965 ENDPROC(atomic64_add)
8966
8967+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8968+ BACKOFF_SETUP(%o2)
8969+1: ldx [%o1], %g1
8970+ addcc %g1, %o0, %g7
8971+ casx [%o1], %g1, %g7
8972+ cmp %g1, %g7
8973+ bne,pn %xcc, 2f
8974+ nop
8975+ retl
8976+ nop
8977+2: BACKOFF_SPIN(%o2, %o3, 1b)
8978+ENDPROC(atomic64_add_unchecked)
8979+
8980 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8981 BACKOFF_SETUP(%o2)
8982 1: ldx [%o1], %g1
8983- sub %g1, %o0, %g7
8984+ subcc %g1, %o0, %g7
8985+
8986+#ifdef CONFIG_PAX_REFCOUNT
8987+ tvs %xcc, 6
8988+#endif
8989+
8990 casx [%o1], %g1, %g7
8991 cmp %g1, %g7
8992 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8993@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8994 2: BACKOFF_SPIN(%o2, %o3, 1b)
8995 ENDPROC(atomic64_sub)
8996
8997+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8998+ BACKOFF_SETUP(%o2)
8999+1: ldx [%o1], %g1
9000+ subcc %g1, %o0, %g7
9001+ casx [%o1], %g1, %g7
9002+ cmp %g1, %g7
9003+ bne,pn %xcc, 2f
9004+ nop
9005+ retl
9006+ nop
9007+2: BACKOFF_SPIN(%o2, %o3, 1b)
9008+ENDPROC(atomic64_sub_unchecked)
9009+
9010 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9011 BACKOFF_SETUP(%o2)
9012 1: ldx [%o1], %g1
9013- add %g1, %o0, %g7
9014+ addcc %g1, %o0, %g7
9015+
9016+#ifdef CONFIG_PAX_REFCOUNT
9017+ tvs %xcc, 6
9018+#endif
9019+
9020 casx [%o1], %g1, %g7
9021 cmp %g1, %g7
9022 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9023@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9024 2: BACKOFF_SPIN(%o2, %o3, 1b)
9025 ENDPROC(atomic64_add_ret)
9026
9027+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9028+ BACKOFF_SETUP(%o2)
9029+1: ldx [%o1], %g1
9030+ addcc %g1, %o0, %g7
9031+ casx [%o1], %g1, %g7
9032+ cmp %g1, %g7
9033+ bne,pn %xcc, 2f
9034+ add %g7, %o0, %g7
9035+ mov %g7, %o0
9036+ retl
9037+ nop
9038+2: BACKOFF_SPIN(%o2, %o3, 1b)
9039+ENDPROC(atomic64_add_ret_unchecked)
9040+
9041 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9042 BACKOFF_SETUP(%o2)
9043 1: ldx [%o1], %g1
9044- sub %g1, %o0, %g7
9045+ subcc %g1, %o0, %g7
9046+
9047+#ifdef CONFIG_PAX_REFCOUNT
9048+ tvs %xcc, 6
9049+#endif
9050+
9051 casx [%o1], %g1, %g7
9052 cmp %g1, %g7
9053 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9054diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9055index 0c4e35e..745d3e4 100644
9056--- a/arch/sparc/lib/ksyms.c
9057+++ b/arch/sparc/lib/ksyms.c
9058@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9059
9060 /* Atomic counter implementation. */
9061 EXPORT_SYMBOL(atomic_add);
9062+EXPORT_SYMBOL(atomic_add_unchecked);
9063 EXPORT_SYMBOL(atomic_add_ret);
9064+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9065 EXPORT_SYMBOL(atomic_sub);
9066+EXPORT_SYMBOL(atomic_sub_unchecked);
9067 EXPORT_SYMBOL(atomic_sub_ret);
9068 EXPORT_SYMBOL(atomic64_add);
9069+EXPORT_SYMBOL(atomic64_add_unchecked);
9070 EXPORT_SYMBOL(atomic64_add_ret);
9071+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9072 EXPORT_SYMBOL(atomic64_sub);
9073+EXPORT_SYMBOL(atomic64_sub_unchecked);
9074 EXPORT_SYMBOL(atomic64_sub_ret);
9075 EXPORT_SYMBOL(atomic64_dec_if_positive);
9076
9077diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9078index 30c3ecc..736f015 100644
9079--- a/arch/sparc/mm/Makefile
9080+++ b/arch/sparc/mm/Makefile
9081@@ -2,7 +2,7 @@
9082 #
9083
9084 asflags-y := -ansi
9085-ccflags-y := -Werror
9086+#ccflags-y := -Werror
9087
9088 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9089 obj-y += fault_$(BITS).o
9090diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9091index e98bfda..ea8d221 100644
9092--- a/arch/sparc/mm/fault_32.c
9093+++ b/arch/sparc/mm/fault_32.c
9094@@ -21,6 +21,9 @@
9095 #include <linux/perf_event.h>
9096 #include <linux/interrupt.h>
9097 #include <linux/kdebug.h>
9098+#include <linux/slab.h>
9099+#include <linux/pagemap.h>
9100+#include <linux/compiler.h>
9101
9102 #include <asm/page.h>
9103 #include <asm/pgtable.h>
9104@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9105 return safe_compute_effective_address(regs, insn);
9106 }
9107
9108+#ifdef CONFIG_PAX_PAGEEXEC
9109+#ifdef CONFIG_PAX_DLRESOLVE
9110+static void pax_emuplt_close(struct vm_area_struct *vma)
9111+{
9112+ vma->vm_mm->call_dl_resolve = 0UL;
9113+}
9114+
9115+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9116+{
9117+ unsigned int *kaddr;
9118+
9119+ vmf->page = alloc_page(GFP_HIGHUSER);
9120+ if (!vmf->page)
9121+ return VM_FAULT_OOM;
9122+
9123+ kaddr = kmap(vmf->page);
9124+ memset(kaddr, 0, PAGE_SIZE);
9125+ kaddr[0] = 0x9DE3BFA8U; /* save */
9126+ flush_dcache_page(vmf->page);
9127+ kunmap(vmf->page);
9128+ return VM_FAULT_MAJOR;
9129+}
9130+
9131+static const struct vm_operations_struct pax_vm_ops = {
9132+ .close = pax_emuplt_close,
9133+ .fault = pax_emuplt_fault
9134+};
9135+
9136+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9137+{
9138+ int ret;
9139+
9140+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9141+ vma->vm_mm = current->mm;
9142+ vma->vm_start = addr;
9143+ vma->vm_end = addr + PAGE_SIZE;
9144+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9145+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9146+ vma->vm_ops = &pax_vm_ops;
9147+
9148+ ret = insert_vm_struct(current->mm, vma);
9149+ if (ret)
9150+ return ret;
9151+
9152+ ++current->mm->total_vm;
9153+ return 0;
9154+}
9155+#endif
9156+
9157+/*
9158+ * PaX: decide what to do with offenders (regs->pc = fault address)
9159+ *
9160+ * returns 1 when task should be killed
9161+ * 2 when patched PLT trampoline was detected
9162+ * 3 when unpatched PLT trampoline was detected
9163+ */
9164+static int pax_handle_fetch_fault(struct pt_regs *regs)
9165+{
9166+
9167+#ifdef CONFIG_PAX_EMUPLT
9168+ int err;
9169+
9170+ do { /* PaX: patched PLT emulation #1 */
9171+ unsigned int sethi1, sethi2, jmpl;
9172+
9173+ err = get_user(sethi1, (unsigned int *)regs->pc);
9174+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9175+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9176+
9177+ if (err)
9178+ break;
9179+
9180+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9181+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9182+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9183+ {
9184+ unsigned int addr;
9185+
9186+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9187+ addr = regs->u_regs[UREG_G1];
9188+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9189+ regs->pc = addr;
9190+ regs->npc = addr+4;
9191+ return 2;
9192+ }
9193+ } while (0);
9194+
9195+ do { /* PaX: patched PLT emulation #2 */
9196+ unsigned int ba;
9197+
9198+ err = get_user(ba, (unsigned int *)regs->pc);
9199+
9200+ if (err)
9201+ break;
9202+
9203+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9204+ unsigned int addr;
9205+
9206+ if ((ba & 0xFFC00000U) == 0x30800000U)
9207+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9208+ else
9209+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9210+ regs->pc = addr;
9211+ regs->npc = addr+4;
9212+ return 2;
9213+ }
9214+ } while (0);
9215+
9216+ do { /* PaX: patched PLT emulation #3 */
9217+ unsigned int sethi, bajmpl, nop;
9218+
9219+ err = get_user(sethi, (unsigned int *)regs->pc);
9220+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9221+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9222+
9223+ if (err)
9224+ break;
9225+
9226+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9227+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9228+ nop == 0x01000000U)
9229+ {
9230+ unsigned int addr;
9231+
9232+ addr = (sethi & 0x003FFFFFU) << 10;
9233+ regs->u_regs[UREG_G1] = addr;
9234+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9235+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9236+ else
9237+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9238+ regs->pc = addr;
9239+ regs->npc = addr+4;
9240+ return 2;
9241+ }
9242+ } while (0);
9243+
9244+ do { /* PaX: unpatched PLT emulation step 1 */
9245+ unsigned int sethi, ba, nop;
9246+
9247+ err = get_user(sethi, (unsigned int *)regs->pc);
9248+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9249+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9250+
9251+ if (err)
9252+ break;
9253+
9254+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9255+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9256+ nop == 0x01000000U)
9257+ {
9258+ unsigned int addr, save, call;
9259+
9260+ if ((ba & 0xFFC00000U) == 0x30800000U)
9261+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9262+ else
9263+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9264+
9265+ err = get_user(save, (unsigned int *)addr);
9266+ err |= get_user(call, (unsigned int *)(addr+4));
9267+ err |= get_user(nop, (unsigned int *)(addr+8));
9268+ if (err)
9269+ break;
9270+
9271+#ifdef CONFIG_PAX_DLRESOLVE
9272+ if (save == 0x9DE3BFA8U &&
9273+ (call & 0xC0000000U) == 0x40000000U &&
9274+ nop == 0x01000000U)
9275+ {
9276+ struct vm_area_struct *vma;
9277+ unsigned long call_dl_resolve;
9278+
9279+ down_read(&current->mm->mmap_sem);
9280+ call_dl_resolve = current->mm->call_dl_resolve;
9281+ up_read(&current->mm->mmap_sem);
9282+ if (likely(call_dl_resolve))
9283+ goto emulate;
9284+
9285+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9286+
9287+ down_write(&current->mm->mmap_sem);
9288+ if (current->mm->call_dl_resolve) {
9289+ call_dl_resolve = current->mm->call_dl_resolve;
9290+ up_write(&current->mm->mmap_sem);
9291+ if (vma)
9292+ kmem_cache_free(vm_area_cachep, vma);
9293+ goto emulate;
9294+ }
9295+
9296+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9297+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9298+ up_write(&current->mm->mmap_sem);
9299+ if (vma)
9300+ kmem_cache_free(vm_area_cachep, vma);
9301+ return 1;
9302+ }
9303+
9304+ if (pax_insert_vma(vma, call_dl_resolve)) {
9305+ up_write(&current->mm->mmap_sem);
9306+ kmem_cache_free(vm_area_cachep, vma);
9307+ return 1;
9308+ }
9309+
9310+ current->mm->call_dl_resolve = call_dl_resolve;
9311+ up_write(&current->mm->mmap_sem);
9312+
9313+emulate:
9314+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9315+ regs->pc = call_dl_resolve;
9316+ regs->npc = addr+4;
9317+ return 3;
9318+ }
9319+#endif
9320+
9321+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9322+ if ((save & 0xFFC00000U) == 0x05000000U &&
9323+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9324+ nop == 0x01000000U)
9325+ {
9326+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9327+ regs->u_regs[UREG_G2] = addr + 4;
9328+ addr = (save & 0x003FFFFFU) << 10;
9329+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9330+ regs->pc = addr;
9331+ regs->npc = addr+4;
9332+ return 3;
9333+ }
9334+ }
9335+ } while (0);
9336+
9337+ do { /* PaX: unpatched PLT emulation step 2 */
9338+ unsigned int save, call, nop;
9339+
9340+ err = get_user(save, (unsigned int *)(regs->pc-4));
9341+ err |= get_user(call, (unsigned int *)regs->pc);
9342+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9343+ if (err)
9344+ break;
9345+
9346+ if (save == 0x9DE3BFA8U &&
9347+ (call & 0xC0000000U) == 0x40000000U &&
9348+ nop == 0x01000000U)
9349+ {
9350+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9351+
9352+ regs->u_regs[UREG_RETPC] = regs->pc;
9353+ regs->pc = dl_resolve;
9354+ regs->npc = dl_resolve+4;
9355+ return 3;
9356+ }
9357+ } while (0);
9358+#endif
9359+
9360+ return 1;
9361+}
9362+
9363+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9364+{
9365+ unsigned long i;
9366+
9367+ printk(KERN_ERR "PAX: bytes at PC: ");
9368+ for (i = 0; i < 8; i++) {
9369+ unsigned int c;
9370+ if (get_user(c, (unsigned int *)pc+i))
9371+ printk(KERN_CONT "???????? ");
9372+ else
9373+ printk(KERN_CONT "%08x ", c);
9374+ }
9375+ printk("\n");
9376+}
9377+#endif
9378+
9379 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9380 int text_fault)
9381 {
9382@@ -230,6 +504,24 @@ good_area:
9383 if (!(vma->vm_flags & VM_WRITE))
9384 goto bad_area;
9385 } else {
9386+
9387+#ifdef CONFIG_PAX_PAGEEXEC
9388+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9389+ up_read(&mm->mmap_sem);
9390+ switch (pax_handle_fetch_fault(regs)) {
9391+
9392+#ifdef CONFIG_PAX_EMUPLT
9393+ case 2:
9394+ case 3:
9395+ return;
9396+#endif
9397+
9398+ }
9399+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9400+ do_group_exit(SIGKILL);
9401+ }
9402+#endif
9403+
9404 /* Allow reads even for write-only mappings */
9405 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9406 goto bad_area;
9407diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9408index 5062ff3..e0b75f3 100644
9409--- a/arch/sparc/mm/fault_64.c
9410+++ b/arch/sparc/mm/fault_64.c
9411@@ -21,6 +21,9 @@
9412 #include <linux/kprobes.h>
9413 #include <linux/kdebug.h>
9414 #include <linux/percpu.h>
9415+#include <linux/slab.h>
9416+#include <linux/pagemap.h>
9417+#include <linux/compiler.h>
9418
9419 #include <asm/page.h>
9420 #include <asm/pgtable.h>
9421@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9422 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9423 regs->tpc);
9424 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9425- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9426+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9427 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9428 dump_stack();
9429 unhandled_fault(regs->tpc, current, regs);
9430@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9431 show_regs(regs);
9432 }
9433
9434+#ifdef CONFIG_PAX_PAGEEXEC
9435+#ifdef CONFIG_PAX_DLRESOLVE
9436+static void pax_emuplt_close(struct vm_area_struct *vma)
9437+{
9438+ vma->vm_mm->call_dl_resolve = 0UL;
9439+}
9440+
9441+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9442+{
9443+ unsigned int *kaddr;
9444+
9445+ vmf->page = alloc_page(GFP_HIGHUSER);
9446+ if (!vmf->page)
9447+ return VM_FAULT_OOM;
9448+
9449+ kaddr = kmap(vmf->page);
9450+ memset(kaddr, 0, PAGE_SIZE);
9451+ kaddr[0] = 0x9DE3BFA8U; /* save */
9452+ flush_dcache_page(vmf->page);
9453+ kunmap(vmf->page);
9454+ return VM_FAULT_MAJOR;
9455+}
9456+
9457+static const struct vm_operations_struct pax_vm_ops = {
9458+ .close = pax_emuplt_close,
9459+ .fault = pax_emuplt_fault
9460+};
9461+
9462+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9463+{
9464+ int ret;
9465+
9466+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9467+ vma->vm_mm = current->mm;
9468+ vma->vm_start = addr;
9469+ vma->vm_end = addr + PAGE_SIZE;
9470+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9471+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9472+ vma->vm_ops = &pax_vm_ops;
9473+
9474+ ret = insert_vm_struct(current->mm, vma);
9475+ if (ret)
9476+ return ret;
9477+
9478+ ++current->mm->total_vm;
9479+ return 0;
9480+}
9481+#endif
9482+
9483+/*
9484+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9485+ *
9486+ * returns 1 when task should be killed
9487+ * 2 when patched PLT trampoline was detected
9488+ * 3 when unpatched PLT trampoline was detected
9489+ */
9490+static int pax_handle_fetch_fault(struct pt_regs *regs)
9491+{
9492+
9493+#ifdef CONFIG_PAX_EMUPLT
9494+ int err;
9495+
9496+ do { /* PaX: patched PLT emulation #1 */
9497+ unsigned int sethi1, sethi2, jmpl;
9498+
9499+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9500+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9501+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9502+
9503+ if (err)
9504+ break;
9505+
9506+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9507+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9508+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9509+ {
9510+ unsigned long addr;
9511+
9512+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9513+ addr = regs->u_regs[UREG_G1];
9514+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9515+
9516+ if (test_thread_flag(TIF_32BIT))
9517+ addr &= 0xFFFFFFFFUL;
9518+
9519+ regs->tpc = addr;
9520+ regs->tnpc = addr+4;
9521+ return 2;
9522+ }
9523+ } while (0);
9524+
9525+ do { /* PaX: patched PLT emulation #2 */
9526+ unsigned int ba;
9527+
9528+ err = get_user(ba, (unsigned int *)regs->tpc);
9529+
9530+ if (err)
9531+ break;
9532+
9533+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9534+ unsigned long addr;
9535+
9536+ if ((ba & 0xFFC00000U) == 0x30800000U)
9537+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9538+ else
9539+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9540+
9541+ if (test_thread_flag(TIF_32BIT))
9542+ addr &= 0xFFFFFFFFUL;
9543+
9544+ regs->tpc = addr;
9545+ regs->tnpc = addr+4;
9546+ return 2;
9547+ }
9548+ } while (0);
9549+
9550+ do { /* PaX: patched PLT emulation #3 */
9551+ unsigned int sethi, bajmpl, nop;
9552+
9553+ err = get_user(sethi, (unsigned int *)regs->tpc);
9554+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9555+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9556+
9557+ if (err)
9558+ break;
9559+
9560+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9561+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9562+ nop == 0x01000000U)
9563+ {
9564+ unsigned long addr;
9565+
9566+ addr = (sethi & 0x003FFFFFU) << 10;
9567+ regs->u_regs[UREG_G1] = addr;
9568+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9569+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9570+ else
9571+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9572+
9573+ if (test_thread_flag(TIF_32BIT))
9574+ addr &= 0xFFFFFFFFUL;
9575+
9576+ regs->tpc = addr;
9577+ regs->tnpc = addr+4;
9578+ return 2;
9579+ }
9580+ } while (0);
9581+
9582+ do { /* PaX: patched PLT emulation #4 */
9583+ unsigned int sethi, mov1, call, mov2;
9584+
9585+ err = get_user(sethi, (unsigned int *)regs->tpc);
9586+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9587+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9588+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9589+
9590+ if (err)
9591+ break;
9592+
9593+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9594+ mov1 == 0x8210000FU &&
9595+ (call & 0xC0000000U) == 0x40000000U &&
9596+ mov2 == 0x9E100001U)
9597+ {
9598+ unsigned long addr;
9599+
9600+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9601+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9602+
9603+ if (test_thread_flag(TIF_32BIT))
9604+ addr &= 0xFFFFFFFFUL;
9605+
9606+ regs->tpc = addr;
9607+ regs->tnpc = addr+4;
9608+ return 2;
9609+ }
9610+ } while (0);
9611+
9612+ do { /* PaX: patched PLT emulation #5 */
9613+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9614+
9615+ err = get_user(sethi, (unsigned int *)regs->tpc);
9616+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9617+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9618+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9619+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9620+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9621+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9622+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9623+
9624+ if (err)
9625+ break;
9626+
9627+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9628+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9629+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9630+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9631+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9632+ sllx == 0x83287020U &&
9633+ jmpl == 0x81C04005U &&
9634+ nop == 0x01000000U)
9635+ {
9636+ unsigned long addr;
9637+
9638+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9639+ regs->u_regs[UREG_G1] <<= 32;
9640+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9641+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9642+ regs->tpc = addr;
9643+ regs->tnpc = addr+4;
9644+ return 2;
9645+ }
9646+ } while (0);
9647+
9648+ do { /* PaX: patched PLT emulation #6 */
9649+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9650+
9651+ err = get_user(sethi, (unsigned int *)regs->tpc);
9652+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9653+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9654+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9655+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9656+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9657+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9658+
9659+ if (err)
9660+ break;
9661+
9662+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9663+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9664+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9665+ sllx == 0x83287020U &&
9666+ (or & 0xFFFFE000U) == 0x8A116000U &&
9667+ jmpl == 0x81C04005U &&
9668+ nop == 0x01000000U)
9669+ {
9670+ unsigned long addr;
9671+
9672+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9673+ regs->u_regs[UREG_G1] <<= 32;
9674+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9675+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9676+ regs->tpc = addr;
9677+ regs->tnpc = addr+4;
9678+ return 2;
9679+ }
9680+ } while (0);
9681+
9682+ do { /* PaX: unpatched PLT emulation step 1 */
9683+ unsigned int sethi, ba, nop;
9684+
9685+ err = get_user(sethi, (unsigned int *)regs->tpc);
9686+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9687+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9688+
9689+ if (err)
9690+ break;
9691+
9692+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9693+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9694+ nop == 0x01000000U)
9695+ {
9696+ unsigned long addr;
9697+ unsigned int save, call;
9698+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9699+
9700+ if ((ba & 0xFFC00000U) == 0x30800000U)
9701+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9702+ else
9703+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9704+
9705+ if (test_thread_flag(TIF_32BIT))
9706+ addr &= 0xFFFFFFFFUL;
9707+
9708+ err = get_user(save, (unsigned int *)addr);
9709+ err |= get_user(call, (unsigned int *)(addr+4));
9710+ err |= get_user(nop, (unsigned int *)(addr+8));
9711+ if (err)
9712+ break;
9713+
9714+#ifdef CONFIG_PAX_DLRESOLVE
9715+ if (save == 0x9DE3BFA8U &&
9716+ (call & 0xC0000000U) == 0x40000000U &&
9717+ nop == 0x01000000U)
9718+ {
9719+ struct vm_area_struct *vma;
9720+ unsigned long call_dl_resolve;
9721+
9722+ down_read(&current->mm->mmap_sem);
9723+ call_dl_resolve = current->mm->call_dl_resolve;
9724+ up_read(&current->mm->mmap_sem);
9725+ if (likely(call_dl_resolve))
9726+ goto emulate;
9727+
9728+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9729+
9730+ down_write(&current->mm->mmap_sem);
9731+ if (current->mm->call_dl_resolve) {
9732+ call_dl_resolve = current->mm->call_dl_resolve;
9733+ up_write(&current->mm->mmap_sem);
9734+ if (vma)
9735+ kmem_cache_free(vm_area_cachep, vma);
9736+ goto emulate;
9737+ }
9738+
9739+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9740+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9741+ up_write(&current->mm->mmap_sem);
9742+ if (vma)
9743+ kmem_cache_free(vm_area_cachep, vma);
9744+ return 1;
9745+ }
9746+
9747+ if (pax_insert_vma(vma, call_dl_resolve)) {
9748+ up_write(&current->mm->mmap_sem);
9749+ kmem_cache_free(vm_area_cachep, vma);
9750+ return 1;
9751+ }
9752+
9753+ current->mm->call_dl_resolve = call_dl_resolve;
9754+ up_write(&current->mm->mmap_sem);
9755+
9756+emulate:
9757+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9758+ regs->tpc = call_dl_resolve;
9759+ regs->tnpc = addr+4;
9760+ return 3;
9761+ }
9762+#endif
9763+
9764+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9765+ if ((save & 0xFFC00000U) == 0x05000000U &&
9766+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9767+ nop == 0x01000000U)
9768+ {
9769+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9770+ regs->u_regs[UREG_G2] = addr + 4;
9771+ addr = (save & 0x003FFFFFU) << 10;
9772+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9773+
9774+ if (test_thread_flag(TIF_32BIT))
9775+ addr &= 0xFFFFFFFFUL;
9776+
9777+ regs->tpc = addr;
9778+ regs->tnpc = addr+4;
9779+ return 3;
9780+ }
9781+
9782+ /* PaX: 64-bit PLT stub */
9783+ err = get_user(sethi1, (unsigned int *)addr);
9784+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9785+ err |= get_user(or1, (unsigned int *)(addr+8));
9786+ err |= get_user(or2, (unsigned int *)(addr+12));
9787+ err |= get_user(sllx, (unsigned int *)(addr+16));
9788+ err |= get_user(add, (unsigned int *)(addr+20));
9789+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9790+ err |= get_user(nop, (unsigned int *)(addr+28));
9791+ if (err)
9792+ break;
9793+
9794+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9795+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9796+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9797+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9798+ sllx == 0x89293020U &&
9799+ add == 0x8A010005U &&
9800+ jmpl == 0x89C14000U &&
9801+ nop == 0x01000000U)
9802+ {
9803+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9804+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9805+ regs->u_regs[UREG_G4] <<= 32;
9806+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9807+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9808+ regs->u_regs[UREG_G4] = addr + 24;
9809+ addr = regs->u_regs[UREG_G5];
9810+ regs->tpc = addr;
9811+ regs->tnpc = addr+4;
9812+ return 3;
9813+ }
9814+ }
9815+ } while (0);
9816+
9817+#ifdef CONFIG_PAX_DLRESOLVE
9818+ do { /* PaX: unpatched PLT emulation step 2 */
9819+ unsigned int save, call, nop;
9820+
9821+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9822+ err |= get_user(call, (unsigned int *)regs->tpc);
9823+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9824+ if (err)
9825+ break;
9826+
9827+ if (save == 0x9DE3BFA8U &&
9828+ (call & 0xC0000000U) == 0x40000000U &&
9829+ nop == 0x01000000U)
9830+ {
9831+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9832+
9833+ if (test_thread_flag(TIF_32BIT))
9834+ dl_resolve &= 0xFFFFFFFFUL;
9835+
9836+ regs->u_regs[UREG_RETPC] = regs->tpc;
9837+ regs->tpc = dl_resolve;
9838+ regs->tnpc = dl_resolve+4;
9839+ return 3;
9840+ }
9841+ } while (0);
9842+#endif
9843+
9844+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9845+ unsigned int sethi, ba, nop;
9846+
9847+ err = get_user(sethi, (unsigned int *)regs->tpc);
9848+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9849+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9850+
9851+ if (err)
9852+ break;
9853+
9854+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9855+ (ba & 0xFFF00000U) == 0x30600000U &&
9856+ nop == 0x01000000U)
9857+ {
9858+ unsigned long addr;
9859+
9860+ addr = (sethi & 0x003FFFFFU) << 10;
9861+ regs->u_regs[UREG_G1] = addr;
9862+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9863+
9864+ if (test_thread_flag(TIF_32BIT))
9865+ addr &= 0xFFFFFFFFUL;
9866+
9867+ regs->tpc = addr;
9868+ regs->tnpc = addr+4;
9869+ return 2;
9870+ }
9871+ } while (0);
9872+
9873+#endif
9874+
9875+ return 1;
9876+}
9877+
9878+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9879+{
9880+ unsigned long i;
9881+
9882+ printk(KERN_ERR "PAX: bytes at PC: ");
9883+ for (i = 0; i < 8; i++) {
9884+ unsigned int c;
9885+ if (get_user(c, (unsigned int *)pc+i))
9886+ printk(KERN_CONT "???????? ");
9887+ else
9888+ printk(KERN_CONT "%08x ", c);
9889+ }
9890+ printk("\n");
9891+}
9892+#endif
9893+
9894 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9895 {
9896 struct mm_struct *mm = current->mm;
9897@@ -341,6 +804,29 @@ retry:
9898 if (!vma)
9899 goto bad_area;
9900
9901+#ifdef CONFIG_PAX_PAGEEXEC
9902+ /* PaX: detect ITLB misses on non-exec pages */
9903+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9904+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9905+ {
9906+ if (address != regs->tpc)
9907+ goto good_area;
9908+
9909+ up_read(&mm->mmap_sem);
9910+ switch (pax_handle_fetch_fault(regs)) {
9911+
9912+#ifdef CONFIG_PAX_EMUPLT
9913+ case 2:
9914+ case 3:
9915+ return;
9916+#endif
9917+
9918+ }
9919+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9920+ do_group_exit(SIGKILL);
9921+ }
9922+#endif
9923+
9924 /* Pure DTLB misses do not tell us whether the fault causing
9925 * load/store/atomic was a write or not, it only says that there
9926 * was no match. So in such a case we (carefully) read the
9927diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9928index d2b5944..bd813f2 100644
9929--- a/arch/sparc/mm/hugetlbpage.c
9930+++ b/arch/sparc/mm/hugetlbpage.c
9931@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9932
9933 info.flags = 0;
9934 info.length = len;
9935- info.low_limit = TASK_UNMAPPED_BASE;
9936+ info.low_limit = mm->mmap_base;
9937 info.high_limit = min(task_size, VA_EXCLUDE_START);
9938 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9939 info.align_offset = 0;
9940@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9941 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9942 VM_BUG_ON(addr != -ENOMEM);
9943 info.low_limit = VA_EXCLUDE_END;
9944+
9945+#ifdef CONFIG_PAX_RANDMMAP
9946+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9947+ info.low_limit += mm->delta_mmap;
9948+#endif
9949+
9950 info.high_limit = task_size;
9951 addr = vm_unmapped_area(&info);
9952 }
9953@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9954 VM_BUG_ON(addr != -ENOMEM);
9955 info.flags = 0;
9956 info.low_limit = TASK_UNMAPPED_BASE;
9957+
9958+#ifdef CONFIG_PAX_RANDMMAP
9959+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9960+ info.low_limit += mm->delta_mmap;
9961+#endif
9962+
9963 info.high_limit = STACK_TOP32;
9964 addr = vm_unmapped_area(&info);
9965 }
9966@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9967 struct mm_struct *mm = current->mm;
9968 struct vm_area_struct *vma;
9969 unsigned long task_size = TASK_SIZE;
9970+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9971
9972 if (test_thread_flag(TIF_32BIT))
9973 task_size = STACK_TOP32;
9974@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9975 return addr;
9976 }
9977
9978+#ifdef CONFIG_PAX_RANDMMAP
9979+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9980+#endif
9981+
9982 if (addr) {
9983 addr = ALIGN(addr, HPAGE_SIZE);
9984 vma = find_vma(mm, addr);
9985- if (task_size - len >= addr &&
9986- (!vma || addr + len <= vma->vm_start))
9987+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9988 return addr;
9989 }
9990 if (mm->get_unmapped_area == arch_get_unmapped_area)
9991diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9992index f4500c6..889656c 100644
9993--- a/arch/tile/include/asm/atomic_64.h
9994+++ b/arch/tile/include/asm/atomic_64.h
9995@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9996
9997 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9998
9999+#define atomic64_read_unchecked(v) atomic64_read(v)
10000+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10001+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10002+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10003+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10004+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10005+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10006+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10007+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10008+
10009 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
10010 #define smp_mb__before_atomic_dec() smp_mb()
10011 #define smp_mb__after_atomic_dec() smp_mb()
10012diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
10013index a9a5299..0fce79e 100644
10014--- a/arch/tile/include/asm/cache.h
10015+++ b/arch/tile/include/asm/cache.h
10016@@ -15,11 +15,12 @@
10017 #ifndef _ASM_TILE_CACHE_H
10018 #define _ASM_TILE_CACHE_H
10019
10020+#include <linux/const.h>
10021 #include <arch/chip.h>
10022
10023 /* bytes per L1 data cache line */
10024 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10025-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10026+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10027
10028 /* bytes per L2 cache line */
10029 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10030diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10031index 8a082bc..7a6bf87 100644
10032--- a/arch/tile/include/asm/uaccess.h
10033+++ b/arch/tile/include/asm/uaccess.h
10034@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10035 const void __user *from,
10036 unsigned long n)
10037 {
10038- int sz = __compiletime_object_size(to);
10039+ size_t sz = __compiletime_object_size(to);
10040
10041- if (likely(sz == -1 || sz >= n))
10042+ if (likely(sz == (size_t)-1 || sz >= n))
10043 n = _copy_from_user(to, from, n);
10044 else
10045 copy_from_user_overflow();
10046diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
10047index 650ccff..45fe2d6 100644
10048--- a/arch/tile/mm/hugetlbpage.c
10049+++ b/arch/tile/mm/hugetlbpage.c
10050@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
10051 info.high_limit = TASK_SIZE;
10052 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10053 info.align_offset = 0;
10054+ info.threadstack_offset = 0;
10055 return vm_unmapped_area(&info);
10056 }
10057
10058@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
10059 info.high_limit = current->mm->mmap_base;
10060 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10061 info.align_offset = 0;
10062+ info.threadstack_offset = 0;
10063 addr = vm_unmapped_area(&info);
10064
10065 /*
10066diff --git a/arch/um/Makefile b/arch/um/Makefile
10067index 133f7de..1d6f2f1 100644
10068--- a/arch/um/Makefile
10069+++ b/arch/um/Makefile
10070@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10071 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10072 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10073
10074+ifdef CONSTIFY_PLUGIN
10075+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10076+endif
10077+
10078 #This will adjust *FLAGS accordingly to the platform.
10079 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10080
10081diff --git a/arch/um/defconfig b/arch/um/defconfig
10082index 08107a7..ab22afe 100644
10083--- a/arch/um/defconfig
10084+++ b/arch/um/defconfig
10085@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
10086 CONFIG_X86_L1_CACHE_SHIFT=5
10087 CONFIG_X86_XADD=y
10088 CONFIG_X86_PPRO_FENCE=y
10089-CONFIG_X86_WP_WORKS_OK=y
10090 CONFIG_X86_INVLPG=y
10091 CONFIG_X86_BSWAP=y
10092 CONFIG_X86_POPAD_OK=y
10093diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10094index 19e1bdd..3665b77 100644
10095--- a/arch/um/include/asm/cache.h
10096+++ b/arch/um/include/asm/cache.h
10097@@ -1,6 +1,7 @@
10098 #ifndef __UM_CACHE_H
10099 #define __UM_CACHE_H
10100
10101+#include <linux/const.h>
10102
10103 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10104 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10105@@ -12,6 +13,6 @@
10106 # define L1_CACHE_SHIFT 5
10107 #endif
10108
10109-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10110+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10111
10112 #endif
10113diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10114index 2e0a6b1..a64d0f5 100644
10115--- a/arch/um/include/asm/kmap_types.h
10116+++ b/arch/um/include/asm/kmap_types.h
10117@@ -8,6 +8,6 @@
10118
10119 /* No more #include "asm/arch/kmap_types.h" ! */
10120
10121-#define KM_TYPE_NR 14
10122+#define KM_TYPE_NR 15
10123
10124 #endif
10125diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10126index 5ff53d9..5850cdf 100644
10127--- a/arch/um/include/asm/page.h
10128+++ b/arch/um/include/asm/page.h
10129@@ -14,6 +14,9 @@
10130 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10131 #define PAGE_MASK (~(PAGE_SIZE-1))
10132
10133+#define ktla_ktva(addr) (addr)
10134+#define ktva_ktla(addr) (addr)
10135+
10136 #ifndef __ASSEMBLY__
10137
10138 struct page;
10139diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10140index 0032f92..cd151e0 100644
10141--- a/arch/um/include/asm/pgtable-3level.h
10142+++ b/arch/um/include/asm/pgtable-3level.h
10143@@ -58,6 +58,7 @@
10144 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10145 #define pud_populate(mm, pud, pmd) \
10146 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10147+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10148
10149 #ifdef CONFIG_64BIT
10150 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10151diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10152index bbcef52..6a2a483 100644
10153--- a/arch/um/kernel/process.c
10154+++ b/arch/um/kernel/process.c
10155@@ -367,22 +367,6 @@ int singlestepping(void * t)
10156 return 2;
10157 }
10158
10159-/*
10160- * Only x86 and x86_64 have an arch_align_stack().
10161- * All other arches have "#define arch_align_stack(x) (x)"
10162- * in their asm/system.h
10163- * As this is included in UML from asm-um/system-generic.h,
10164- * we can use it to behave as the subarch does.
10165- */
10166-#ifndef arch_align_stack
10167-unsigned long arch_align_stack(unsigned long sp)
10168-{
10169- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10170- sp -= get_random_int() % 8192;
10171- return sp & ~0xf;
10172-}
10173-#endif
10174-
10175 unsigned long get_wchan(struct task_struct *p)
10176 {
10177 unsigned long stack_page, sp, ip;
10178diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10179index ad8f795..2c7eec6 100644
10180--- a/arch/unicore32/include/asm/cache.h
10181+++ b/arch/unicore32/include/asm/cache.h
10182@@ -12,8 +12,10 @@
10183 #ifndef __UNICORE_CACHE_H__
10184 #define __UNICORE_CACHE_H__
10185
10186-#define L1_CACHE_SHIFT (5)
10187-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10188+#include <linux/const.h>
10189+
10190+#define L1_CACHE_SHIFT 5
10191+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10192
10193 /*
10194 * Memory returned by kmalloc() may be used for DMA, so we must make
10195diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10196index fe120da..24177f7 100644
10197--- a/arch/x86/Kconfig
10198+++ b/arch/x86/Kconfig
10199@@ -239,7 +239,7 @@ config X86_HT
10200
10201 config X86_32_LAZY_GS
10202 def_bool y
10203- depends on X86_32 && !CC_STACKPROTECTOR
10204+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10205
10206 config ARCH_HWEIGHT_CFLAGS
10207 string
10208@@ -1073,6 +1073,7 @@ config MICROCODE_EARLY
10209
10210 config X86_MSR
10211 tristate "/dev/cpu/*/msr - Model-specific register support"
10212+ depends on !GRKERNSEC_KMEM
10213 ---help---
10214 This device gives privileged processes access to the x86
10215 Model-Specific Registers (MSRs). It is a character device with
10216@@ -1096,7 +1097,7 @@ choice
10217
10218 config NOHIGHMEM
10219 bool "off"
10220- depends on !X86_NUMAQ
10221+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10222 ---help---
10223 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10224 However, the address space of 32-bit x86 processors is only 4
10225@@ -1133,7 +1134,7 @@ config NOHIGHMEM
10226
10227 config HIGHMEM4G
10228 bool "4GB"
10229- depends on !X86_NUMAQ
10230+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10231 ---help---
10232 Select this if you have a 32-bit processor and between 1 and 4
10233 gigabytes of physical RAM.
10234@@ -1186,7 +1187,7 @@ config PAGE_OFFSET
10235 hex
10236 default 0xB0000000 if VMSPLIT_3G_OPT
10237 default 0x80000000 if VMSPLIT_2G
10238- default 0x78000000 if VMSPLIT_2G_OPT
10239+ default 0x70000000 if VMSPLIT_2G_OPT
10240 default 0x40000000 if VMSPLIT_1G
10241 default 0xC0000000
10242 depends on X86_32
10243@@ -1584,6 +1585,7 @@ config SECCOMP
10244
10245 config CC_STACKPROTECTOR
10246 bool "Enable -fstack-protector buffer overflow detection"
10247+ depends on X86_64 || !PAX_MEMORY_UDEREF
10248 ---help---
10249 This option turns on the -fstack-protector GCC feature. This
10250 feature puts, at the beginning of functions, a canary value on
10251@@ -1703,6 +1705,8 @@ config X86_NEED_RELOCS
10252 config PHYSICAL_ALIGN
10253 hex "Alignment value to which kernel should be aligned" if X86_32
10254 default "0x1000000"
10255+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
10256+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
10257 range 0x2000 0x1000000
10258 ---help---
10259 This value puts the alignment restrictions on physical address
10260@@ -1778,9 +1782,10 @@ config DEBUG_HOTPLUG_CPU0
10261 If unsure, say N.
10262
10263 config COMPAT_VDSO
10264- def_bool y
10265+ def_bool n
10266 prompt "Compat VDSO support"
10267 depends on X86_32 || IA32_EMULATION
10268+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10269 ---help---
10270 Map the 32-bit VDSO to the predictable old-style address too.
10271
10272diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10273index c026cca..14657ae 100644
10274--- a/arch/x86/Kconfig.cpu
10275+++ b/arch/x86/Kconfig.cpu
10276@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10277
10278 config X86_F00F_BUG
10279 def_bool y
10280- depends on M586MMX || M586TSC || M586 || M486
10281+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10282
10283 config X86_INVD_BUG
10284 def_bool y
10285@@ -327,7 +327,7 @@ config X86_INVD_BUG
10286
10287 config X86_ALIGNMENT_16
10288 def_bool y
10289- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10290+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10291
10292 config X86_INTEL_USERCOPY
10293 def_bool y
10294@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10295 # generates cmov.
10296 config X86_CMOV
10297 def_bool y
10298- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10299+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10300
10301 config X86_MINIMUM_CPU_FAMILY
10302 int
10303diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10304index c198b7e..63eea60 100644
10305--- a/arch/x86/Kconfig.debug
10306+++ b/arch/x86/Kconfig.debug
10307@@ -84,7 +84,7 @@ config X86_PTDUMP
10308 config DEBUG_RODATA
10309 bool "Write protect kernel read-only data structures"
10310 default y
10311- depends on DEBUG_KERNEL
10312+ depends on DEBUG_KERNEL && BROKEN
10313 ---help---
10314 Mark the kernel read-only data as write-protected in the pagetables,
10315 in order to catch accidental (and incorrect) writes to such const
10316@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10317
10318 config DEBUG_SET_MODULE_RONX
10319 bool "Set loadable kernel module data as NX and text as RO"
10320- depends on MODULES
10321+ depends on MODULES && BROKEN
10322 ---help---
10323 This option helps catch unintended modifications to loadable
10324 kernel module's text and read-only data. It also prevents execution
10325diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10326index 5c47726..8c4fa67 100644
10327--- a/arch/x86/Makefile
10328+++ b/arch/x86/Makefile
10329@@ -54,6 +54,7 @@ else
10330 UTS_MACHINE := x86_64
10331 CHECKFLAGS += -D__x86_64__ -m64
10332
10333+ biarch := $(call cc-option,-m64)
10334 KBUILD_AFLAGS += -m64
10335 KBUILD_CFLAGS += -m64
10336
10337@@ -234,3 +235,12 @@ define archhelp
10338 echo ' FDARGS="..." arguments for the booted kernel'
10339 echo ' FDINITRD=file initrd for the booted kernel'
10340 endef
10341+
10342+define OLD_LD
10343+
10344+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10345+*** Please upgrade your binutils to 2.18 or newer
10346+endef
10347+
10348+archprepare:
10349+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10350diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10351index 379814b..add62ce 100644
10352--- a/arch/x86/boot/Makefile
10353+++ b/arch/x86/boot/Makefile
10354@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10355 $(call cc-option, -fno-stack-protector) \
10356 $(call cc-option, -mpreferred-stack-boundary=2)
10357 KBUILD_CFLAGS += $(call cc-option, -m32)
10358+ifdef CONSTIFY_PLUGIN
10359+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10360+endif
10361 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10362 GCOV_PROFILE := n
10363
10364diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10365index 878e4b9..20537ab 100644
10366--- a/arch/x86/boot/bitops.h
10367+++ b/arch/x86/boot/bitops.h
10368@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10369 u8 v;
10370 const u32 *p = (const u32 *)addr;
10371
10372- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10373+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10374 return v;
10375 }
10376
10377@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10378
10379 static inline void set_bit(int nr, void *addr)
10380 {
10381- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10382+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10383 }
10384
10385 #endif /* BOOT_BITOPS_H */
10386diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10387index 5b75319..331a4ca 100644
10388--- a/arch/x86/boot/boot.h
10389+++ b/arch/x86/boot/boot.h
10390@@ -85,7 +85,7 @@ static inline void io_delay(void)
10391 static inline u16 ds(void)
10392 {
10393 u16 seg;
10394- asm("movw %%ds,%0" : "=rm" (seg));
10395+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10396 return seg;
10397 }
10398
10399@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10400 static inline int memcmp(const void *s1, const void *s2, size_t len)
10401 {
10402 u8 diff;
10403- asm("repe; cmpsb; setnz %0"
10404+ asm volatile("repe; cmpsb; setnz %0"
10405 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10406 return diff;
10407 }
10408diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10409index 5ef205c..342191d 100644
10410--- a/arch/x86/boot/compressed/Makefile
10411+++ b/arch/x86/boot/compressed/Makefile
10412@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10413 KBUILD_CFLAGS += $(cflags-y)
10414 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10415 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10416+ifdef CONSTIFY_PLUGIN
10417+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10418+endif
10419
10420 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10421 GCOV_PROFILE := n
10422diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10423index c205035..5853587 100644
10424--- a/arch/x86/boot/compressed/eboot.c
10425+++ b/arch/x86/boot/compressed/eboot.c
10426@@ -150,7 +150,6 @@ again:
10427 *addr = max_addr;
10428 }
10429
10430-free_pool:
10431 efi_call_phys1(sys_table->boottime->free_pool, map);
10432
10433 fail:
10434@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10435 if (i == map_size / desc_size)
10436 status = EFI_NOT_FOUND;
10437
10438-free_pool:
10439 efi_call_phys1(sys_table->boottime->free_pool, map);
10440 fail:
10441 return status;
10442diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
10443index a53440e..c3dbf1e 100644
10444--- a/arch/x86/boot/compressed/efi_stub_32.S
10445+++ b/arch/x86/boot/compressed/efi_stub_32.S
10446@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
10447 * parameter 2, ..., param n. To make things easy, we save the return
10448 * address of efi_call_phys in a global variable.
10449 */
10450- popl %ecx
10451- movl %ecx, saved_return_addr(%edx)
10452- /* get the function pointer into ECX*/
10453- popl %ecx
10454- movl %ecx, efi_rt_function_ptr(%edx)
10455+ popl saved_return_addr(%edx)
10456+ popl efi_rt_function_ptr(%edx)
10457
10458 /*
10459 * 3. Call the physical function.
10460 */
10461- call *%ecx
10462+ call *efi_rt_function_ptr(%edx)
10463
10464 /*
10465 * 4. Balance the stack. And because EAX contain the return value,
10466@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
10467 1: popl %edx
10468 subl $1b, %edx
10469
10470- movl efi_rt_function_ptr(%edx), %ecx
10471- pushl %ecx
10472+ pushl efi_rt_function_ptr(%edx)
10473
10474 /*
10475 * 10. Push the saved return address onto the stack and return.
10476 */
10477- movl saved_return_addr(%edx), %ecx
10478- pushl %ecx
10479- ret
10480+ jmpl *saved_return_addr(%edx)
10481 ENDPROC(efi_call_phys)
10482 .previous
10483
10484diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10485index 1e3184f..0d11e2e 100644
10486--- a/arch/x86/boot/compressed/head_32.S
10487+++ b/arch/x86/boot/compressed/head_32.S
10488@@ -118,7 +118,7 @@ preferred_addr:
10489 notl %eax
10490 andl %eax, %ebx
10491 #else
10492- movl $LOAD_PHYSICAL_ADDR, %ebx
10493+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10494 #endif
10495
10496 /* Target address to relocate to for decompression */
10497@@ -204,7 +204,7 @@ relocated:
10498 * and where it was actually loaded.
10499 */
10500 movl %ebp, %ebx
10501- subl $LOAD_PHYSICAL_ADDR, %ebx
10502+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10503 jz 2f /* Nothing to be done if loaded at compiled addr. */
10504 /*
10505 * Process relocations.
10506@@ -212,8 +212,7 @@ relocated:
10507
10508 1: subl $4, %edi
10509 movl (%edi), %ecx
10510- testl %ecx, %ecx
10511- jz 2f
10512+ jecxz 2f
10513 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10514 jmp 1b
10515 2:
10516diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10517index 16f24e6..47491a3 100644
10518--- a/arch/x86/boot/compressed/head_64.S
10519+++ b/arch/x86/boot/compressed/head_64.S
10520@@ -97,7 +97,7 @@ ENTRY(startup_32)
10521 notl %eax
10522 andl %eax, %ebx
10523 #else
10524- movl $LOAD_PHYSICAL_ADDR, %ebx
10525+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10526 #endif
10527
10528 /* Target address to relocate to for decompression */
10529@@ -272,7 +272,7 @@ preferred_addr:
10530 notq %rax
10531 andq %rax, %rbp
10532 #else
10533- movq $LOAD_PHYSICAL_ADDR, %rbp
10534+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10535 #endif
10536
10537 /* Target address to relocate to for decompression */
10538@@ -363,8 +363,8 @@ gdt:
10539 .long gdt
10540 .word 0
10541 .quad 0x0000000000000000 /* NULL descriptor */
10542- .quad 0x00af9a000000ffff /* __KERNEL_CS */
10543- .quad 0x00cf92000000ffff /* __KERNEL_DS */
10544+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
10545+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
10546 .quad 0x0080890000000000 /* TS descriptor */
10547 .quad 0x0000000000000000 /* TS continued */
10548 gdt_end:
10549diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10550index 7cb56c6..d382d84 100644
10551--- a/arch/x86/boot/compressed/misc.c
10552+++ b/arch/x86/boot/compressed/misc.c
10553@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10554 case PT_LOAD:
10555 #ifdef CONFIG_RELOCATABLE
10556 dest = output;
10557- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10558+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10559 #else
10560 dest = (void *)(phdr->p_paddr);
10561 #endif
10562@@ -354,7 +354,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10563 error("Destination address too large");
10564 #endif
10565 #ifndef CONFIG_RELOCATABLE
10566- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10567+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10568 error("Wrong destination address");
10569 #endif
10570
10571diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10572index 4d3ff03..e4972ff 100644
10573--- a/arch/x86/boot/cpucheck.c
10574+++ b/arch/x86/boot/cpucheck.c
10575@@ -74,7 +74,7 @@ static int has_fpu(void)
10576 u16 fcw = -1, fsw = -1;
10577 u32 cr0;
10578
10579- asm("movl %%cr0,%0" : "=r" (cr0));
10580+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10581 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10582 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10583 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10584@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10585 {
10586 u32 f0, f1;
10587
10588- asm("pushfl ; "
10589+ asm volatile("pushfl ; "
10590 "pushfl ; "
10591 "popl %0 ; "
10592 "movl %0,%1 ; "
10593@@ -115,7 +115,7 @@ static void get_flags(void)
10594 set_bit(X86_FEATURE_FPU, cpu.flags);
10595
10596 if (has_eflag(X86_EFLAGS_ID)) {
10597- asm("cpuid"
10598+ asm volatile("cpuid"
10599 : "=a" (max_intel_level),
10600 "=b" (cpu_vendor[0]),
10601 "=d" (cpu_vendor[1]),
10602@@ -124,7 +124,7 @@ static void get_flags(void)
10603
10604 if (max_intel_level >= 0x00000001 &&
10605 max_intel_level <= 0x0000ffff) {
10606- asm("cpuid"
10607+ asm volatile("cpuid"
10608 : "=a" (tfms),
10609 "=c" (cpu.flags[4]),
10610 "=d" (cpu.flags[0])
10611@@ -136,7 +136,7 @@ static void get_flags(void)
10612 cpu.model += ((tfms >> 16) & 0xf) << 4;
10613 }
10614
10615- asm("cpuid"
10616+ asm volatile("cpuid"
10617 : "=a" (max_amd_level)
10618 : "a" (0x80000000)
10619 : "ebx", "ecx", "edx");
10620@@ -144,7 +144,7 @@ static void get_flags(void)
10621 if (max_amd_level >= 0x80000001 &&
10622 max_amd_level <= 0x8000ffff) {
10623 u32 eax = 0x80000001;
10624- asm("cpuid"
10625+ asm volatile("cpuid"
10626 : "+a" (eax),
10627 "=c" (cpu.flags[6]),
10628 "=d" (cpu.flags[1])
10629@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10630 u32 ecx = MSR_K7_HWCR;
10631 u32 eax, edx;
10632
10633- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10634+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10635 eax &= ~(1 << 15);
10636- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10637+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10638
10639 get_flags(); /* Make sure it really did something */
10640 err = check_flags();
10641@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10642 u32 ecx = MSR_VIA_FCR;
10643 u32 eax, edx;
10644
10645- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10646+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10647 eax |= (1<<1)|(1<<7);
10648- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10649+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10650
10651 set_bit(X86_FEATURE_CX8, cpu.flags);
10652 err = check_flags();
10653@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10654 u32 eax, edx;
10655 u32 level = 1;
10656
10657- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10658- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10659- asm("cpuid"
10660+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10661+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10662+ asm volatile("cpuid"
10663 : "+a" (level), "=d" (cpu.flags[0])
10664 : : "ecx", "ebx");
10665- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10666+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10667
10668 err = check_flags();
10669 }
10670diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10671index 9ec06a1..2c25e79 100644
10672--- a/arch/x86/boot/header.S
10673+++ b/arch/x86/boot/header.S
10674@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10675 # single linked list of
10676 # struct setup_data
10677
10678-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10679+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10680
10681 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10682+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10683+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10684+#else
10685 #define VO_INIT_SIZE (VO__end - VO__text)
10686+#endif
10687 #if ZO_INIT_SIZE > VO_INIT_SIZE
10688 #define INIT_SIZE ZO_INIT_SIZE
10689 #else
10690diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10691index db75d07..8e6d0af 100644
10692--- a/arch/x86/boot/memory.c
10693+++ b/arch/x86/boot/memory.c
10694@@ -19,7 +19,7 @@
10695
10696 static int detect_memory_e820(void)
10697 {
10698- int count = 0;
10699+ unsigned int count = 0;
10700 struct biosregs ireg, oreg;
10701 struct e820entry *desc = boot_params.e820_map;
10702 static struct e820entry buf; /* static so it is zeroed */
10703diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10704index 11e8c6e..fdbb1ed 100644
10705--- a/arch/x86/boot/video-vesa.c
10706+++ b/arch/x86/boot/video-vesa.c
10707@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10708
10709 boot_params.screen_info.vesapm_seg = oreg.es;
10710 boot_params.screen_info.vesapm_off = oreg.di;
10711+ boot_params.screen_info.vesapm_size = oreg.cx;
10712 }
10713
10714 /*
10715diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10716index 43eda28..5ab5fdb 100644
10717--- a/arch/x86/boot/video.c
10718+++ b/arch/x86/boot/video.c
10719@@ -96,7 +96,7 @@ static void store_mode_params(void)
10720 static unsigned int get_entry(void)
10721 {
10722 char entry_buf[4];
10723- int i, len = 0;
10724+ unsigned int i, len = 0;
10725 int key;
10726 unsigned int v;
10727
10728diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10729index 9105655..5e37f27 100644
10730--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10731+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10732@@ -8,6 +8,8 @@
10733 * including this sentence is retained in full.
10734 */
10735
10736+#include <asm/alternative-asm.h>
10737+
10738 .extern crypto_ft_tab
10739 .extern crypto_it_tab
10740 .extern crypto_fl_tab
10741@@ -70,6 +72,8 @@
10742 je B192; \
10743 leaq 32(r9),r9;
10744
10745+#define ret pax_force_retaddr 0, 1; ret
10746+
10747 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10748 movq r1,r2; \
10749 movq r3,r4; \
10750diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10751index 477e9d7..3ab339f 100644
10752--- a/arch/x86/crypto/aesni-intel_asm.S
10753+++ b/arch/x86/crypto/aesni-intel_asm.S
10754@@ -31,6 +31,7 @@
10755
10756 #include <linux/linkage.h>
10757 #include <asm/inst.h>
10758+#include <asm/alternative-asm.h>
10759
10760 #ifdef __x86_64__
10761 .data
10762@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
10763 pop %r14
10764 pop %r13
10765 pop %r12
10766+ pax_force_retaddr 0, 1
10767 ret
10768 ENDPROC(aesni_gcm_dec)
10769
10770@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
10771 pop %r14
10772 pop %r13
10773 pop %r12
10774+ pax_force_retaddr 0, 1
10775 ret
10776 ENDPROC(aesni_gcm_enc)
10777
10778@@ -1722,6 +1725,7 @@ _key_expansion_256a:
10779 pxor %xmm1, %xmm0
10780 movaps %xmm0, (TKEYP)
10781 add $0x10, TKEYP
10782+ pax_force_retaddr_bts
10783 ret
10784 ENDPROC(_key_expansion_128)
10785 ENDPROC(_key_expansion_256a)
10786@@ -1748,6 +1752,7 @@ _key_expansion_192a:
10787 shufps $0b01001110, %xmm2, %xmm1
10788 movaps %xmm1, 0x10(TKEYP)
10789 add $0x20, TKEYP
10790+ pax_force_retaddr_bts
10791 ret
10792 ENDPROC(_key_expansion_192a)
10793
10794@@ -1768,6 +1773,7 @@ _key_expansion_192b:
10795
10796 movaps %xmm0, (TKEYP)
10797 add $0x10, TKEYP
10798+ pax_force_retaddr_bts
10799 ret
10800 ENDPROC(_key_expansion_192b)
10801
10802@@ -1781,6 +1787,7 @@ _key_expansion_256b:
10803 pxor %xmm1, %xmm2
10804 movaps %xmm2, (TKEYP)
10805 add $0x10, TKEYP
10806+ pax_force_retaddr_bts
10807 ret
10808 ENDPROC(_key_expansion_256b)
10809
10810@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
10811 #ifndef __x86_64__
10812 popl KEYP
10813 #endif
10814+ pax_force_retaddr 0, 1
10815 ret
10816 ENDPROC(aesni_set_key)
10817
10818@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
10819 popl KLEN
10820 popl KEYP
10821 #endif
10822+ pax_force_retaddr 0, 1
10823 ret
10824 ENDPROC(aesni_enc)
10825
10826@@ -1974,6 +1983,7 @@ _aesni_enc1:
10827 AESENC KEY STATE
10828 movaps 0x70(TKEYP), KEY
10829 AESENCLAST KEY STATE
10830+ pax_force_retaddr_bts
10831 ret
10832 ENDPROC(_aesni_enc1)
10833
10834@@ -2083,6 +2093,7 @@ _aesni_enc4:
10835 AESENCLAST KEY STATE2
10836 AESENCLAST KEY STATE3
10837 AESENCLAST KEY STATE4
10838+ pax_force_retaddr_bts
10839 ret
10840 ENDPROC(_aesni_enc4)
10841
10842@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
10843 popl KLEN
10844 popl KEYP
10845 #endif
10846+ pax_force_retaddr 0, 1
10847 ret
10848 ENDPROC(aesni_dec)
10849
10850@@ -2164,6 +2176,7 @@ _aesni_dec1:
10851 AESDEC KEY STATE
10852 movaps 0x70(TKEYP), KEY
10853 AESDECLAST KEY STATE
10854+ pax_force_retaddr_bts
10855 ret
10856 ENDPROC(_aesni_dec1)
10857
10858@@ -2273,6 +2286,7 @@ _aesni_dec4:
10859 AESDECLAST KEY STATE2
10860 AESDECLAST KEY STATE3
10861 AESDECLAST KEY STATE4
10862+ pax_force_retaddr_bts
10863 ret
10864 ENDPROC(_aesni_dec4)
10865
10866@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
10867 popl KEYP
10868 popl LEN
10869 #endif
10870+ pax_force_retaddr 0, 1
10871 ret
10872 ENDPROC(aesni_ecb_enc)
10873
10874@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
10875 popl KEYP
10876 popl LEN
10877 #endif
10878+ pax_force_retaddr 0, 1
10879 ret
10880 ENDPROC(aesni_ecb_dec)
10881
10882@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
10883 popl LEN
10884 popl IVP
10885 #endif
10886+ pax_force_retaddr 0, 1
10887 ret
10888 ENDPROC(aesni_cbc_enc)
10889
10890@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
10891 popl LEN
10892 popl IVP
10893 #endif
10894+ pax_force_retaddr 0, 1
10895 ret
10896 ENDPROC(aesni_cbc_dec)
10897
10898@@ -2550,6 +2568,7 @@ _aesni_inc_init:
10899 mov $1, TCTR_LOW
10900 MOVQ_R64_XMM TCTR_LOW INC
10901 MOVQ_R64_XMM CTR TCTR_LOW
10902+ pax_force_retaddr_bts
10903 ret
10904 ENDPROC(_aesni_inc_init)
10905
10906@@ -2579,6 +2598,7 @@ _aesni_inc:
10907 .Linc_low:
10908 movaps CTR, IV
10909 PSHUFB_XMM BSWAP_MASK IV
10910+ pax_force_retaddr_bts
10911 ret
10912 ENDPROC(_aesni_inc)
10913
10914@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
10915 .Lctr_enc_ret:
10916 movups IV, (IVP)
10917 .Lctr_enc_just_ret:
10918+ pax_force_retaddr 0, 1
10919 ret
10920 ENDPROC(aesni_ctr_enc)
10921
10922@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
10923 pxor INC, STATE4
10924 movdqu STATE4, 0x70(OUTP)
10925
10926+ pax_force_retaddr 0, 1
10927 ret
10928 ENDPROC(aesni_xts_crypt8)
10929
10930diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10931index 246c670..4d1ed00 100644
10932--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10933+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10934@@ -21,6 +21,7 @@
10935 */
10936
10937 #include <linux/linkage.h>
10938+#include <asm/alternative-asm.h>
10939
10940 .file "blowfish-x86_64-asm.S"
10941 .text
10942@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
10943 jnz .L__enc_xor;
10944
10945 write_block();
10946+ pax_force_retaddr 0, 1
10947 ret;
10948 .L__enc_xor:
10949 xor_block();
10950+ pax_force_retaddr 0, 1
10951 ret;
10952 ENDPROC(__blowfish_enc_blk)
10953
10954@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
10955
10956 movq %r11, %rbp;
10957
10958+ pax_force_retaddr 0, 1
10959 ret;
10960 ENDPROC(blowfish_dec_blk)
10961
10962@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
10963
10964 popq %rbx;
10965 popq %rbp;
10966+ pax_force_retaddr 0, 1
10967 ret;
10968
10969 .L__enc_xor4:
10970@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
10971
10972 popq %rbx;
10973 popq %rbp;
10974+ pax_force_retaddr 0, 1
10975 ret;
10976 ENDPROC(__blowfish_enc_blk_4way)
10977
10978@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
10979 popq %rbx;
10980 popq %rbp;
10981
10982+ pax_force_retaddr 0, 1
10983 ret;
10984 ENDPROC(blowfish_dec_blk_4way)
10985diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10986index 310319c..ce174a4 100644
10987--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10988+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10989@@ -21,6 +21,7 @@
10990 */
10991
10992 #include <linux/linkage.h>
10993+#include <asm/alternative-asm.h>
10994
10995 .file "camellia-x86_64-asm_64.S"
10996 .text
10997@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
10998 enc_outunpack(mov, RT1);
10999
11000 movq RRBP, %rbp;
11001+ pax_force_retaddr 0, 1
11002 ret;
11003
11004 .L__enc_xor:
11005 enc_outunpack(xor, RT1);
11006
11007 movq RRBP, %rbp;
11008+ pax_force_retaddr 0, 1
11009 ret;
11010 ENDPROC(__camellia_enc_blk)
11011
11012@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
11013 dec_outunpack();
11014
11015 movq RRBP, %rbp;
11016+ pax_force_retaddr 0, 1
11017 ret;
11018 ENDPROC(camellia_dec_blk)
11019
11020@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
11021
11022 movq RRBP, %rbp;
11023 popq %rbx;
11024+ pax_force_retaddr 0, 1
11025 ret;
11026
11027 .L__enc2_xor:
11028@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
11029
11030 movq RRBP, %rbp;
11031 popq %rbx;
11032+ pax_force_retaddr 0, 1
11033 ret;
11034 ENDPROC(__camellia_enc_blk_2way)
11035
11036@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
11037
11038 movq RRBP, %rbp;
11039 movq RXOR, %rbx;
11040+ pax_force_retaddr 0, 1
11041 ret;
11042 ENDPROC(camellia_dec_blk_2way)
11043diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11044index c35fd5d..c1ee236 100644
11045--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11046+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11047@@ -24,6 +24,7 @@
11048 */
11049
11050 #include <linux/linkage.h>
11051+#include <asm/alternative-asm.h>
11052
11053 .file "cast5-avx-x86_64-asm_64.S"
11054
11055@@ -281,6 +282,7 @@ __cast5_enc_blk16:
11056 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11057 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11058
11059+ pax_force_retaddr 0, 1
11060 ret;
11061 ENDPROC(__cast5_enc_blk16)
11062
11063@@ -352,6 +354,7 @@ __cast5_dec_blk16:
11064 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11065 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11066
11067+ pax_force_retaddr 0, 1
11068 ret;
11069
11070 .L__skip_dec:
11071@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
11072 vmovdqu RR4, (6*4*4)(%r11);
11073 vmovdqu RL4, (7*4*4)(%r11);
11074
11075+ pax_force_retaddr
11076 ret;
11077 ENDPROC(cast5_ecb_enc_16way)
11078
11079@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
11080 vmovdqu RR4, (6*4*4)(%r11);
11081 vmovdqu RL4, (7*4*4)(%r11);
11082
11083+ pax_force_retaddr
11084 ret;
11085 ENDPROC(cast5_ecb_dec_16way)
11086
11087@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
11088
11089 popq %r12;
11090
11091+ pax_force_retaddr
11092 ret;
11093 ENDPROC(cast5_cbc_dec_16way)
11094
11095@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
11096
11097 popq %r12;
11098
11099+ pax_force_retaddr
11100 ret;
11101 ENDPROC(cast5_ctr_16way)
11102diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11103index e3531f8..18ded3a 100644
11104--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11105+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11106@@ -24,6 +24,7 @@
11107 */
11108
11109 #include <linux/linkage.h>
11110+#include <asm/alternative-asm.h>
11111 #include "glue_helper-asm-avx.S"
11112
11113 .file "cast6-avx-x86_64-asm_64.S"
11114@@ -295,6 +296,7 @@ __cast6_enc_blk8:
11115 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11116 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11117
11118+ pax_force_retaddr 0, 1
11119 ret;
11120 ENDPROC(__cast6_enc_blk8)
11121
11122@@ -340,6 +342,7 @@ __cast6_dec_blk8:
11123 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11124 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11125
11126+ pax_force_retaddr 0, 1
11127 ret;
11128 ENDPROC(__cast6_dec_blk8)
11129
11130@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
11131
11132 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11133
11134+ pax_force_retaddr
11135 ret;
11136 ENDPROC(cast6_ecb_enc_8way)
11137
11138@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
11139
11140 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11141
11142+ pax_force_retaddr
11143 ret;
11144 ENDPROC(cast6_ecb_dec_8way)
11145
11146@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
11147
11148 popq %r12;
11149
11150+ pax_force_retaddr
11151 ret;
11152 ENDPROC(cast6_cbc_dec_8way)
11153
11154@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
11155
11156 popq %r12;
11157
11158+ pax_force_retaddr
11159 ret;
11160 ENDPROC(cast6_ctr_8way)
11161
11162@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
11163 /* dst <= regs xor IVs(in dst) */
11164 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11165
11166+ pax_force_retaddr
11167 ret;
11168 ENDPROC(cast6_xts_enc_8way)
11169
11170@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
11171 /* dst <= regs xor IVs(in dst) */
11172 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11173
11174+ pax_force_retaddr
11175 ret;
11176 ENDPROC(cast6_xts_dec_8way)
11177diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11178index 9279e0b..9270820 100644
11179--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11180+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11181@@ -1,4 +1,5 @@
11182 #include <linux/linkage.h>
11183+#include <asm/alternative-asm.h>
11184
11185 # enter salsa20_encrypt_bytes
11186 ENTRY(salsa20_encrypt_bytes)
11187@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
11188 add %r11,%rsp
11189 mov %rdi,%rax
11190 mov %rsi,%rdx
11191+ pax_force_retaddr 0, 1
11192 ret
11193 # bytesatleast65:
11194 ._bytesatleast65:
11195@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
11196 add %r11,%rsp
11197 mov %rdi,%rax
11198 mov %rsi,%rdx
11199+ pax_force_retaddr
11200 ret
11201 ENDPROC(salsa20_keysetup)
11202
11203@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
11204 add %r11,%rsp
11205 mov %rdi,%rax
11206 mov %rsi,%rdx
11207+ pax_force_retaddr
11208 ret
11209 ENDPROC(salsa20_ivsetup)
11210diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11211index 2f202f4..d9164d6 100644
11212--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11213+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11214@@ -24,6 +24,7 @@
11215 */
11216
11217 #include <linux/linkage.h>
11218+#include <asm/alternative-asm.h>
11219 #include "glue_helper-asm-avx.S"
11220
11221 .file "serpent-avx-x86_64-asm_64.S"
11222@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
11223 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11224 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11225
11226+ pax_force_retaddr
11227 ret;
11228 ENDPROC(__serpent_enc_blk8_avx)
11229
11230@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
11231 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11232 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11233
11234+ pax_force_retaddr
11235 ret;
11236 ENDPROC(__serpent_dec_blk8_avx)
11237
11238@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
11239
11240 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11241
11242+ pax_force_retaddr
11243 ret;
11244 ENDPROC(serpent_ecb_enc_8way_avx)
11245
11246@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
11247
11248 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11249
11250+ pax_force_retaddr
11251 ret;
11252 ENDPROC(serpent_ecb_dec_8way_avx)
11253
11254@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
11255
11256 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11257
11258+ pax_force_retaddr
11259 ret;
11260 ENDPROC(serpent_cbc_dec_8way_avx)
11261
11262@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
11263
11264 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11265
11266+ pax_force_retaddr
11267 ret;
11268 ENDPROC(serpent_ctr_8way_avx)
11269
11270@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
11271 /* dst <= regs xor IVs(in dst) */
11272 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11273
11274+ pax_force_retaddr
11275 ret;
11276 ENDPROC(serpent_xts_enc_8way_avx)
11277
11278@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
11279 /* dst <= regs xor IVs(in dst) */
11280 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11281
11282+ pax_force_retaddr
11283 ret;
11284 ENDPROC(serpent_xts_dec_8way_avx)
11285diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11286index acc066c..1559cc4 100644
11287--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11288+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11289@@ -25,6 +25,7 @@
11290 */
11291
11292 #include <linux/linkage.h>
11293+#include <asm/alternative-asm.h>
11294
11295 .file "serpent-sse2-x86_64-asm_64.S"
11296 .text
11297@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
11298 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11299 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11300
11301+ pax_force_retaddr
11302 ret;
11303
11304 .L__enc_xor8:
11305 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11306 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11307
11308+ pax_force_retaddr
11309 ret;
11310 ENDPROC(__serpent_enc_blk_8way)
11311
11312@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
11313 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11314 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11315
11316+ pax_force_retaddr
11317 ret;
11318 ENDPROC(serpent_dec_blk_8way)
11319diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11320index a410950..3356d42 100644
11321--- a/arch/x86/crypto/sha1_ssse3_asm.S
11322+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11323@@ -29,6 +29,7 @@
11324 */
11325
11326 #include <linux/linkage.h>
11327+#include <asm/alternative-asm.h>
11328
11329 #define CTX %rdi // arg1
11330 #define BUF %rsi // arg2
11331@@ -104,6 +105,7 @@
11332 pop %r12
11333 pop %rbp
11334 pop %rbx
11335+ pax_force_retaddr 0, 1
11336 ret
11337
11338 ENDPROC(\name)
11339diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11340index 0505813..63b1d00 100644
11341--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11342+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11343@@ -24,6 +24,7 @@
11344 */
11345
11346 #include <linux/linkage.h>
11347+#include <asm/alternative-asm.h>
11348 #include "glue_helper-asm-avx.S"
11349
11350 .file "twofish-avx-x86_64-asm_64.S"
11351@@ -284,6 +285,7 @@ __twofish_enc_blk8:
11352 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11353 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11354
11355+ pax_force_retaddr 0, 1
11356 ret;
11357 ENDPROC(__twofish_enc_blk8)
11358
11359@@ -324,6 +326,7 @@ __twofish_dec_blk8:
11360 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11361 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11362
11363+ pax_force_retaddr 0, 1
11364 ret;
11365 ENDPROC(__twofish_dec_blk8)
11366
11367@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
11368
11369 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11370
11371+ pax_force_retaddr 0, 1
11372 ret;
11373 ENDPROC(twofish_ecb_enc_8way)
11374
11375@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
11376
11377 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11378
11379+ pax_force_retaddr 0, 1
11380 ret;
11381 ENDPROC(twofish_ecb_dec_8way)
11382
11383@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
11384
11385 popq %r12;
11386
11387+ pax_force_retaddr 0, 1
11388 ret;
11389 ENDPROC(twofish_cbc_dec_8way)
11390
11391@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
11392
11393 popq %r12;
11394
11395+ pax_force_retaddr 0, 1
11396 ret;
11397 ENDPROC(twofish_ctr_8way)
11398
11399@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
11400 /* dst <= regs xor IVs(in dst) */
11401 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11402
11403+ pax_force_retaddr 0, 1
11404 ret;
11405 ENDPROC(twofish_xts_enc_8way)
11406
11407@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
11408 /* dst <= regs xor IVs(in dst) */
11409 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11410
11411+ pax_force_retaddr 0, 1
11412 ret;
11413 ENDPROC(twofish_xts_dec_8way)
11414diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11415index 1c3b7ce..b365c5e 100644
11416--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11417+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11418@@ -21,6 +21,7 @@
11419 */
11420
11421 #include <linux/linkage.h>
11422+#include <asm/alternative-asm.h>
11423
11424 .file "twofish-x86_64-asm-3way.S"
11425 .text
11426@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
11427 popq %r13;
11428 popq %r14;
11429 popq %r15;
11430+ pax_force_retaddr 0, 1
11431 ret;
11432
11433 .L__enc_xor3:
11434@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
11435 popq %r13;
11436 popq %r14;
11437 popq %r15;
11438+ pax_force_retaddr 0, 1
11439 ret;
11440 ENDPROC(__twofish_enc_blk_3way)
11441
11442@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
11443 popq %r13;
11444 popq %r14;
11445 popq %r15;
11446+ pax_force_retaddr 0, 1
11447 ret;
11448 ENDPROC(twofish_dec_blk_3way)
11449diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11450index a039d21..29e7615 100644
11451--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11452+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11453@@ -22,6 +22,7 @@
11454
11455 #include <linux/linkage.h>
11456 #include <asm/asm-offsets.h>
11457+#include <asm/alternative-asm.h>
11458
11459 #define a_offset 0
11460 #define b_offset 4
11461@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
11462
11463 popq R1
11464 movq $1,%rax
11465+ pax_force_retaddr 0, 1
11466 ret
11467 ENDPROC(twofish_enc_blk)
11468
11469@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
11470
11471 popq R1
11472 movq $1,%rax
11473+ pax_force_retaddr 0, 1
11474 ret
11475 ENDPROC(twofish_dec_blk)
11476diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11477index 52ff81c..98af645 100644
11478--- a/arch/x86/ia32/ia32_aout.c
11479+++ b/arch/x86/ia32/ia32_aout.c
11480@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11481 unsigned long dump_start, dump_size;
11482 struct user32 dump;
11483
11484+ memset(&dump, 0, sizeof(dump));
11485+
11486 fs = get_fs();
11487 set_fs(KERNEL_DS);
11488 has_dumped = 1;
11489diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11490index cf1a471..3bc4cf8 100644
11491--- a/arch/x86/ia32/ia32_signal.c
11492+++ b/arch/x86/ia32/ia32_signal.c
11493@@ -340,7 +340,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
11494 sp -= frame_size;
11495 /* Align the stack pointer according to the i386 ABI,
11496 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11497- sp = ((sp + 4) & -16ul) - 4;
11498+ sp = ((sp - 12) & -16ul) - 4;
11499 return (void __user *) sp;
11500 }
11501
11502@@ -398,7 +398,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
11503 * These are actually not used anymore, but left because some
11504 * gdb versions depend on them as a marker.
11505 */
11506- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11507+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11508 } put_user_catch(err);
11509
11510 if (err)
11511@@ -440,7 +440,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11512 0xb8,
11513 __NR_ia32_rt_sigreturn,
11514 0x80cd,
11515- 0,
11516+ 0
11517 };
11518
11519 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
11520@@ -463,16 +463,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11521
11522 if (ksig->ka.sa.sa_flags & SA_RESTORER)
11523 restorer = ksig->ka.sa.sa_restorer;
11524+ else if (current->mm->context.vdso)
11525+ /* Return stub is in 32bit vsyscall page */
11526+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11527 else
11528- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11529- rt_sigreturn);
11530+ restorer = &frame->retcode;
11531 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11532
11533 /*
11534 * Not actually used anymore, but left because some gdb
11535 * versions need it.
11536 */
11537- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11538+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11539 } put_user_catch(err);
11540
11541 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
11542diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11543index 474dc1b..24aaa3e 100644
11544--- a/arch/x86/ia32/ia32entry.S
11545+++ b/arch/x86/ia32/ia32entry.S
11546@@ -15,8 +15,10 @@
11547 #include <asm/irqflags.h>
11548 #include <asm/asm.h>
11549 #include <asm/smap.h>
11550+#include <asm/pgtable.h>
11551 #include <linux/linkage.h>
11552 #include <linux/err.h>
11553+#include <asm/alternative-asm.h>
11554
11555 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11556 #include <linux/elf-em.h>
11557@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11558 ENDPROC(native_irq_enable_sysexit)
11559 #endif
11560
11561+ .macro pax_enter_kernel_user
11562+ pax_set_fptr_mask
11563+#ifdef CONFIG_PAX_MEMORY_UDEREF
11564+ call pax_enter_kernel_user
11565+#endif
11566+ .endm
11567+
11568+ .macro pax_exit_kernel_user
11569+#ifdef CONFIG_PAX_MEMORY_UDEREF
11570+ call pax_exit_kernel_user
11571+#endif
11572+#ifdef CONFIG_PAX_RANDKSTACK
11573+ pushq %rax
11574+ pushq %r11
11575+ call pax_randomize_kstack
11576+ popq %r11
11577+ popq %rax
11578+#endif
11579+ .endm
11580+
11581+ .macro pax_erase_kstack
11582+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11583+ call pax_erase_kstack
11584+#endif
11585+ .endm
11586+
11587 /*
11588 * 32bit SYSENTER instruction entry.
11589 *
11590@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11591 CFI_REGISTER rsp,rbp
11592 SWAPGS_UNSAFE_STACK
11593 movq PER_CPU_VAR(kernel_stack), %rsp
11594- addq $(KERNEL_STACK_OFFSET),%rsp
11595- /*
11596- * No need to follow this irqs on/off section: the syscall
11597- * disabled irqs, here we enable it straight after entry:
11598- */
11599- ENABLE_INTERRUPTS(CLBR_NONE)
11600 movl %ebp,%ebp /* zero extension */
11601 pushq_cfi $__USER32_DS
11602 /*CFI_REL_OFFSET ss,0*/
11603@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11604 CFI_REL_OFFSET rsp,0
11605 pushfq_cfi
11606 /*CFI_REL_OFFSET rflags,0*/
11607- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11608- CFI_REGISTER rip,r10
11609+ orl $X86_EFLAGS_IF,(%rsp)
11610+ GET_THREAD_INFO(%r11)
11611+ movl TI_sysenter_return(%r11), %r11d
11612+ CFI_REGISTER rip,r11
11613 pushq_cfi $__USER32_CS
11614 /*CFI_REL_OFFSET cs,0*/
11615 movl %eax, %eax
11616- pushq_cfi %r10
11617+ pushq_cfi %r11
11618 CFI_REL_OFFSET rip,0
11619 pushq_cfi %rax
11620 cld
11621 SAVE_ARGS 0,1,0
11622+ pax_enter_kernel_user
11623+
11624+#ifdef CONFIG_PAX_RANDKSTACK
11625+ pax_erase_kstack
11626+#endif
11627+
11628+ /*
11629+ * No need to follow this irqs on/off section: the syscall
11630+ * disabled irqs, here we enable it straight after entry:
11631+ */
11632+ ENABLE_INTERRUPTS(CLBR_NONE)
11633 /* no need to do an access_ok check here because rbp has been
11634 32bit zero extended */
11635+
11636+#ifdef CONFIG_PAX_MEMORY_UDEREF
11637+ mov pax_user_shadow_base,%r11
11638+ add %r11,%rbp
11639+#endif
11640+
11641 ASM_STAC
11642 1: movl (%rbp),%ebp
11643 _ASM_EXTABLE(1b,ia32_badarg)
11644 ASM_CLAC
11645- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11646- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11647+ GET_THREAD_INFO(%r11)
11648+ orl $TS_COMPAT,TI_status(%r11)
11649+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11650 CFI_REMEMBER_STATE
11651 jnz sysenter_tracesys
11652 cmpq $(IA32_NR_syscalls-1),%rax
11653@@ -162,12 +204,15 @@ sysenter_do_call:
11654 sysenter_dispatch:
11655 call *ia32_sys_call_table(,%rax,8)
11656 movq %rax,RAX-ARGOFFSET(%rsp)
11657+ GET_THREAD_INFO(%r11)
11658 DISABLE_INTERRUPTS(CLBR_NONE)
11659 TRACE_IRQS_OFF
11660- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11661+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11662 jnz sysexit_audit
11663 sysexit_from_sys_call:
11664- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11665+ pax_exit_kernel_user
11666+ pax_erase_kstack
11667+ andl $~TS_COMPAT,TI_status(%r11)
11668 /* clear IF, that popfq doesn't enable interrupts early */
11669 andl $~0x200,EFLAGS-R11(%rsp)
11670 movl RIP-R11(%rsp),%edx /* User %eip */
11671@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11672 movl %eax,%esi /* 2nd arg: syscall number */
11673 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11674 call __audit_syscall_entry
11675+
11676+ pax_erase_kstack
11677+
11678 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11679 cmpq $(IA32_NR_syscalls-1),%rax
11680 ja ia32_badsys
11681@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11682 .endm
11683
11684 .macro auditsys_exit exit
11685- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11686+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11687 jnz ia32_ret_from_sys_call
11688 TRACE_IRQS_ON
11689 ENABLE_INTERRUPTS(CLBR_NONE)
11690@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11691 1: setbe %al /* 1 if error, 0 if not */
11692 movzbl %al,%edi /* zero-extend that into %edi */
11693 call __audit_syscall_exit
11694+ GET_THREAD_INFO(%r11)
11695 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11696 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11697 DISABLE_INTERRUPTS(CLBR_NONE)
11698 TRACE_IRQS_OFF
11699- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11700+ testl %edi,TI_flags(%r11)
11701 jz \exit
11702 CLEAR_RREGS -ARGOFFSET
11703 jmp int_with_check
11704@@ -237,7 +286,7 @@ sysexit_audit:
11705
11706 sysenter_tracesys:
11707 #ifdef CONFIG_AUDITSYSCALL
11708- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11709+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11710 jz sysenter_auditsys
11711 #endif
11712 SAVE_REST
11713@@ -249,6 +298,9 @@ sysenter_tracesys:
11714 RESTORE_REST
11715 cmpq $(IA32_NR_syscalls-1),%rax
11716 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11717+
11718+ pax_erase_kstack
11719+
11720 jmp sysenter_do_call
11721 CFI_ENDPROC
11722 ENDPROC(ia32_sysenter_target)
11723@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11724 ENTRY(ia32_cstar_target)
11725 CFI_STARTPROC32 simple
11726 CFI_SIGNAL_FRAME
11727- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11728+ CFI_DEF_CFA rsp,0
11729 CFI_REGISTER rip,rcx
11730 /*CFI_REGISTER rflags,r11*/
11731 SWAPGS_UNSAFE_STACK
11732 movl %esp,%r8d
11733 CFI_REGISTER rsp,r8
11734 movq PER_CPU_VAR(kernel_stack),%rsp
11735+ SAVE_ARGS 8*6,0,0
11736+ pax_enter_kernel_user
11737+
11738+#ifdef CONFIG_PAX_RANDKSTACK
11739+ pax_erase_kstack
11740+#endif
11741+
11742 /*
11743 * No need to follow this irqs on/off section: the syscall
11744 * disabled irqs and here we enable it straight after entry:
11745 */
11746 ENABLE_INTERRUPTS(CLBR_NONE)
11747- SAVE_ARGS 8,0,0
11748 movl %eax,%eax /* zero extension */
11749 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11750 movq %rcx,RIP-ARGOFFSET(%rsp)
11751@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11752 /* no need to do an access_ok check here because r8 has been
11753 32bit zero extended */
11754 /* hardware stack frame is complete now */
11755+
11756+#ifdef CONFIG_PAX_MEMORY_UDEREF
11757+ mov pax_user_shadow_base,%r11
11758+ add %r11,%r8
11759+#endif
11760+
11761 ASM_STAC
11762 1: movl (%r8),%r9d
11763 _ASM_EXTABLE(1b,ia32_badarg)
11764 ASM_CLAC
11765- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11766- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11767+ GET_THREAD_INFO(%r11)
11768+ orl $TS_COMPAT,TI_status(%r11)
11769+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11770 CFI_REMEMBER_STATE
11771 jnz cstar_tracesys
11772 cmpq $IA32_NR_syscalls-1,%rax
11773@@ -319,12 +384,15 @@ cstar_do_call:
11774 cstar_dispatch:
11775 call *ia32_sys_call_table(,%rax,8)
11776 movq %rax,RAX-ARGOFFSET(%rsp)
11777+ GET_THREAD_INFO(%r11)
11778 DISABLE_INTERRUPTS(CLBR_NONE)
11779 TRACE_IRQS_OFF
11780- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11781+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11782 jnz sysretl_audit
11783 sysretl_from_sys_call:
11784- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11785+ pax_exit_kernel_user
11786+ pax_erase_kstack
11787+ andl $~TS_COMPAT,TI_status(%r11)
11788 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11789 movl RIP-ARGOFFSET(%rsp),%ecx
11790 CFI_REGISTER rip,rcx
11791@@ -352,7 +420,7 @@ sysretl_audit:
11792
11793 cstar_tracesys:
11794 #ifdef CONFIG_AUDITSYSCALL
11795- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11796+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11797 jz cstar_auditsys
11798 #endif
11799 xchgl %r9d,%ebp
11800@@ -366,6 +434,9 @@ cstar_tracesys:
11801 xchgl %ebp,%r9d
11802 cmpq $(IA32_NR_syscalls-1),%rax
11803 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11804+
11805+ pax_erase_kstack
11806+
11807 jmp cstar_do_call
11808 END(ia32_cstar_target)
11809
11810@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11811 CFI_REL_OFFSET rip,RIP-RIP
11812 PARAVIRT_ADJUST_EXCEPTION_FRAME
11813 SWAPGS
11814- /*
11815- * No need to follow this irqs on/off section: the syscall
11816- * disabled irqs and here we enable it straight after entry:
11817- */
11818- ENABLE_INTERRUPTS(CLBR_NONE)
11819 movl %eax,%eax
11820 pushq_cfi %rax
11821 cld
11822 /* note the registers are not zero extended to the sf.
11823 this could be a problem. */
11824 SAVE_ARGS 0,1,0
11825- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11826- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11827+ pax_enter_kernel_user
11828+
11829+#ifdef CONFIG_PAX_RANDKSTACK
11830+ pax_erase_kstack
11831+#endif
11832+
11833+ /*
11834+ * No need to follow this irqs on/off section: the syscall
11835+ * disabled irqs and here we enable it straight after entry:
11836+ */
11837+ ENABLE_INTERRUPTS(CLBR_NONE)
11838+ GET_THREAD_INFO(%r11)
11839+ orl $TS_COMPAT,TI_status(%r11)
11840+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11841 jnz ia32_tracesys
11842 cmpq $(IA32_NR_syscalls-1),%rax
11843 ja ia32_badsys
11844@@ -442,6 +520,9 @@ ia32_tracesys:
11845 RESTORE_REST
11846 cmpq $(IA32_NR_syscalls-1),%rax
11847 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11848+
11849+ pax_erase_kstack
11850+
11851 jmp ia32_do_call
11852 END(ia32_syscall)
11853
11854diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11855index 8e0ceec..af13504 100644
11856--- a/arch/x86/ia32/sys_ia32.c
11857+++ b/arch/x86/ia32/sys_ia32.c
11858@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11859 */
11860 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11861 {
11862- typeof(ubuf->st_uid) uid = 0;
11863- typeof(ubuf->st_gid) gid = 0;
11864+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11865+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11866 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11867 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11868 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11869diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11870index 372231c..a5aa1a1 100644
11871--- a/arch/x86/include/asm/alternative-asm.h
11872+++ b/arch/x86/include/asm/alternative-asm.h
11873@@ -18,6 +18,45 @@
11874 .endm
11875 #endif
11876
11877+#ifdef KERNEXEC_PLUGIN
11878+ .macro pax_force_retaddr_bts rip=0
11879+ btsq $63,\rip(%rsp)
11880+ .endm
11881+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11882+ .macro pax_force_retaddr rip=0, reload=0
11883+ btsq $63,\rip(%rsp)
11884+ .endm
11885+ .macro pax_force_fptr ptr
11886+ btsq $63,\ptr
11887+ .endm
11888+ .macro pax_set_fptr_mask
11889+ .endm
11890+#endif
11891+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11892+ .macro pax_force_retaddr rip=0, reload=0
11893+ .if \reload
11894+ pax_set_fptr_mask
11895+ .endif
11896+ orq %r10,\rip(%rsp)
11897+ .endm
11898+ .macro pax_force_fptr ptr
11899+ orq %r10,\ptr
11900+ .endm
11901+ .macro pax_set_fptr_mask
11902+ movabs $0x8000000000000000,%r10
11903+ .endm
11904+#endif
11905+#else
11906+ .macro pax_force_retaddr rip=0, reload=0
11907+ .endm
11908+ .macro pax_force_fptr ptr
11909+ .endm
11910+ .macro pax_force_retaddr_bts rip=0
11911+ .endm
11912+ .macro pax_set_fptr_mask
11913+ .endm
11914+#endif
11915+
11916 .macro altinstruction_entry orig alt feature orig_len alt_len
11917 .long \orig - .
11918 .long \alt - .
11919diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11920index 58ed6d9..f1cbe58 100644
11921--- a/arch/x86/include/asm/alternative.h
11922+++ b/arch/x86/include/asm/alternative.h
11923@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11924 ".pushsection .discard,\"aw\",@progbits\n" \
11925 DISCARD_ENTRY(1) \
11926 ".popsection\n" \
11927- ".pushsection .altinstr_replacement, \"ax\"\n" \
11928+ ".pushsection .altinstr_replacement, \"a\"\n" \
11929 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11930 ".popsection"
11931
11932@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11933 DISCARD_ENTRY(1) \
11934 DISCARD_ENTRY(2) \
11935 ".popsection\n" \
11936- ".pushsection .altinstr_replacement, \"ax\"\n" \
11937+ ".pushsection .altinstr_replacement, \"a\"\n" \
11938 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11939 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11940 ".popsection"
11941diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11942index 3388034..050f0b9 100644
11943--- a/arch/x86/include/asm/apic.h
11944+++ b/arch/x86/include/asm/apic.h
11945@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11946
11947 #ifdef CONFIG_X86_LOCAL_APIC
11948
11949-extern unsigned int apic_verbosity;
11950+extern int apic_verbosity;
11951 extern int local_apic_timer_c2_ok;
11952
11953 extern int disable_apic;
11954diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11955index 20370c6..a2eb9b0 100644
11956--- a/arch/x86/include/asm/apm.h
11957+++ b/arch/x86/include/asm/apm.h
11958@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11959 __asm__ __volatile__(APM_DO_ZERO_SEGS
11960 "pushl %%edi\n\t"
11961 "pushl %%ebp\n\t"
11962- "lcall *%%cs:apm_bios_entry\n\t"
11963+ "lcall *%%ss:apm_bios_entry\n\t"
11964 "setc %%al\n\t"
11965 "popl %%ebp\n\t"
11966 "popl %%edi\n\t"
11967@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11968 __asm__ __volatile__(APM_DO_ZERO_SEGS
11969 "pushl %%edi\n\t"
11970 "pushl %%ebp\n\t"
11971- "lcall *%%cs:apm_bios_entry\n\t"
11972+ "lcall *%%ss:apm_bios_entry\n\t"
11973 "setc %%bl\n\t"
11974 "popl %%ebp\n\t"
11975 "popl %%edi\n\t"
11976diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11977index 722aa3b..3a0bb27 100644
11978--- a/arch/x86/include/asm/atomic.h
11979+++ b/arch/x86/include/asm/atomic.h
11980@@ -22,7 +22,18 @@
11981 */
11982 static inline int atomic_read(const atomic_t *v)
11983 {
11984- return (*(volatile int *)&(v)->counter);
11985+ return (*(volatile const int *)&(v)->counter);
11986+}
11987+
11988+/**
11989+ * atomic_read_unchecked - read atomic variable
11990+ * @v: pointer of type atomic_unchecked_t
11991+ *
11992+ * Atomically reads the value of @v.
11993+ */
11994+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11995+{
11996+ return (*(volatile const int *)&(v)->counter);
11997 }
11998
11999 /**
12000@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
12001 }
12002
12003 /**
12004+ * atomic_set_unchecked - set atomic variable
12005+ * @v: pointer of type atomic_unchecked_t
12006+ * @i: required value
12007+ *
12008+ * Atomically sets the value of @v to @i.
12009+ */
12010+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
12011+{
12012+ v->counter = i;
12013+}
12014+
12015+/**
12016 * atomic_add - add integer to atomic variable
12017 * @i: integer value to add
12018 * @v: pointer of type atomic_t
12019@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
12020 */
12021 static inline void atomic_add(int i, atomic_t *v)
12022 {
12023- asm volatile(LOCK_PREFIX "addl %1,%0"
12024+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12025+
12026+#ifdef CONFIG_PAX_REFCOUNT
12027+ "jno 0f\n"
12028+ LOCK_PREFIX "subl %1,%0\n"
12029+ "int $4\n0:\n"
12030+ _ASM_EXTABLE(0b, 0b)
12031+#endif
12032+
12033+ : "+m" (v->counter)
12034+ : "ir" (i));
12035+}
12036+
12037+/**
12038+ * atomic_add_unchecked - add integer to atomic variable
12039+ * @i: integer value to add
12040+ * @v: pointer of type atomic_unchecked_t
12041+ *
12042+ * Atomically adds @i to @v.
12043+ */
12044+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
12045+{
12046+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12047 : "+m" (v->counter)
12048 : "ir" (i));
12049 }
12050@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
12051 */
12052 static inline void atomic_sub(int i, atomic_t *v)
12053 {
12054- asm volatile(LOCK_PREFIX "subl %1,%0"
12055+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12056+
12057+#ifdef CONFIG_PAX_REFCOUNT
12058+ "jno 0f\n"
12059+ LOCK_PREFIX "addl %1,%0\n"
12060+ "int $4\n0:\n"
12061+ _ASM_EXTABLE(0b, 0b)
12062+#endif
12063+
12064+ : "+m" (v->counter)
12065+ : "ir" (i));
12066+}
12067+
12068+/**
12069+ * atomic_sub_unchecked - subtract integer from atomic variable
12070+ * @i: integer value to subtract
12071+ * @v: pointer of type atomic_unchecked_t
12072+ *
12073+ * Atomically subtracts @i from @v.
12074+ */
12075+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
12076+{
12077+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12078 : "+m" (v->counter)
12079 : "ir" (i));
12080 }
12081@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12082 {
12083 unsigned char c;
12084
12085- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
12086+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
12087+
12088+#ifdef CONFIG_PAX_REFCOUNT
12089+ "jno 0f\n"
12090+ LOCK_PREFIX "addl %2,%0\n"
12091+ "int $4\n0:\n"
12092+ _ASM_EXTABLE(0b, 0b)
12093+#endif
12094+
12095+ "sete %1\n"
12096 : "+m" (v->counter), "=qm" (c)
12097 : "ir" (i) : "memory");
12098 return c;
12099@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12100 */
12101 static inline void atomic_inc(atomic_t *v)
12102 {
12103- asm volatile(LOCK_PREFIX "incl %0"
12104+ asm volatile(LOCK_PREFIX "incl %0\n"
12105+
12106+#ifdef CONFIG_PAX_REFCOUNT
12107+ "jno 0f\n"
12108+ LOCK_PREFIX "decl %0\n"
12109+ "int $4\n0:\n"
12110+ _ASM_EXTABLE(0b, 0b)
12111+#endif
12112+
12113+ : "+m" (v->counter));
12114+}
12115+
12116+/**
12117+ * atomic_inc_unchecked - increment atomic variable
12118+ * @v: pointer of type atomic_unchecked_t
12119+ *
12120+ * Atomically increments @v by 1.
12121+ */
12122+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12123+{
12124+ asm volatile(LOCK_PREFIX "incl %0\n"
12125 : "+m" (v->counter));
12126 }
12127
12128@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12129 */
12130 static inline void atomic_dec(atomic_t *v)
12131 {
12132- asm volatile(LOCK_PREFIX "decl %0"
12133+ asm volatile(LOCK_PREFIX "decl %0\n"
12134+
12135+#ifdef CONFIG_PAX_REFCOUNT
12136+ "jno 0f\n"
12137+ LOCK_PREFIX "incl %0\n"
12138+ "int $4\n0:\n"
12139+ _ASM_EXTABLE(0b, 0b)
12140+#endif
12141+
12142+ : "+m" (v->counter));
12143+}
12144+
12145+/**
12146+ * atomic_dec_unchecked - decrement atomic variable
12147+ * @v: pointer of type atomic_unchecked_t
12148+ *
12149+ * Atomically decrements @v by 1.
12150+ */
12151+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12152+{
12153+ asm volatile(LOCK_PREFIX "decl %0\n"
12154 : "+m" (v->counter));
12155 }
12156
12157@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12158 {
12159 unsigned char c;
12160
12161- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12162+ asm volatile(LOCK_PREFIX "decl %0\n"
12163+
12164+#ifdef CONFIG_PAX_REFCOUNT
12165+ "jno 0f\n"
12166+ LOCK_PREFIX "incl %0\n"
12167+ "int $4\n0:\n"
12168+ _ASM_EXTABLE(0b, 0b)
12169+#endif
12170+
12171+ "sete %1\n"
12172 : "+m" (v->counter), "=qm" (c)
12173 : : "memory");
12174 return c != 0;
12175@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12176 {
12177 unsigned char c;
12178
12179- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12180+ asm volatile(LOCK_PREFIX "incl %0\n"
12181+
12182+#ifdef CONFIG_PAX_REFCOUNT
12183+ "jno 0f\n"
12184+ LOCK_PREFIX "decl %0\n"
12185+ "int $4\n0:\n"
12186+ _ASM_EXTABLE(0b, 0b)
12187+#endif
12188+
12189+ "sete %1\n"
12190+ : "+m" (v->counter), "=qm" (c)
12191+ : : "memory");
12192+ return c != 0;
12193+}
12194+
12195+/**
12196+ * atomic_inc_and_test_unchecked - increment and test
12197+ * @v: pointer of type atomic_unchecked_t
12198+ *
12199+ * Atomically increments @v by 1
12200+ * and returns true if the result is zero, or false for all
12201+ * other cases.
12202+ */
12203+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12204+{
12205+ unsigned char c;
12206+
12207+ asm volatile(LOCK_PREFIX "incl %0\n"
12208+ "sete %1\n"
12209 : "+m" (v->counter), "=qm" (c)
12210 : : "memory");
12211 return c != 0;
12212@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12213 {
12214 unsigned char c;
12215
12216- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12217+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12218+
12219+#ifdef CONFIG_PAX_REFCOUNT
12220+ "jno 0f\n"
12221+ LOCK_PREFIX "subl %2,%0\n"
12222+ "int $4\n0:\n"
12223+ _ASM_EXTABLE(0b, 0b)
12224+#endif
12225+
12226+ "sets %1\n"
12227 : "+m" (v->counter), "=qm" (c)
12228 : "ir" (i) : "memory");
12229 return c;
12230@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12231 */
12232 static inline int atomic_add_return(int i, atomic_t *v)
12233 {
12234+ return i + xadd_check_overflow(&v->counter, i);
12235+}
12236+
12237+/**
12238+ * atomic_add_return_unchecked - add integer and return
12239+ * @i: integer value to add
12240+ * @v: pointer of type atomic_unchecked_t
12241+ *
12242+ * Atomically adds @i to @v and returns @i + @v
12243+ */
12244+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12245+{
12246 return i + xadd(&v->counter, i);
12247 }
12248
12249@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12250 }
12251
12252 #define atomic_inc_return(v) (atomic_add_return(1, v))
12253+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12254+{
12255+ return atomic_add_return_unchecked(1, v);
12256+}
12257 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12258
12259 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12260@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12261 return cmpxchg(&v->counter, old, new);
12262 }
12263
12264+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12265+{
12266+ return cmpxchg(&v->counter, old, new);
12267+}
12268+
12269 static inline int atomic_xchg(atomic_t *v, int new)
12270 {
12271 return xchg(&v->counter, new);
12272 }
12273
12274+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12275+{
12276+ return xchg(&v->counter, new);
12277+}
12278+
12279 /**
12280 * __atomic_add_unless - add unless the number is already a given value
12281 * @v: pointer of type atomic_t
12282@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12283 */
12284 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12285 {
12286- int c, old;
12287+ int c, old, new;
12288 c = atomic_read(v);
12289 for (;;) {
12290- if (unlikely(c == (u)))
12291+ if (unlikely(c == u))
12292 break;
12293- old = atomic_cmpxchg((v), c, c + (a));
12294+
12295+ asm volatile("addl %2,%0\n"
12296+
12297+#ifdef CONFIG_PAX_REFCOUNT
12298+ "jno 0f\n"
12299+ "subl %2,%0\n"
12300+ "int $4\n0:\n"
12301+ _ASM_EXTABLE(0b, 0b)
12302+#endif
12303+
12304+ : "=r" (new)
12305+ : "0" (c), "ir" (a));
12306+
12307+ old = atomic_cmpxchg(v, c, new);
12308 if (likely(old == c))
12309 break;
12310 c = old;
12311@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12312 }
12313
12314 /**
12315+ * atomic_inc_not_zero_hint - increment if not null
12316+ * @v: pointer of type atomic_t
12317+ * @hint: probable value of the atomic before the increment
12318+ *
12319+ * This version of atomic_inc_not_zero() gives a hint of probable
12320+ * value of the atomic. This helps processor to not read the memory
12321+ * before doing the atomic read/modify/write cycle, lowering
12322+ * number of bus transactions on some arches.
12323+ *
12324+ * Returns: 0 if increment was not done, 1 otherwise.
12325+ */
12326+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12327+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12328+{
12329+ int val, c = hint, new;
12330+
12331+ /* sanity test, should be removed by compiler if hint is a constant */
12332+ if (!hint)
12333+ return __atomic_add_unless(v, 1, 0);
12334+
12335+ do {
12336+ asm volatile("incl %0\n"
12337+
12338+#ifdef CONFIG_PAX_REFCOUNT
12339+ "jno 0f\n"
12340+ "decl %0\n"
12341+ "int $4\n0:\n"
12342+ _ASM_EXTABLE(0b, 0b)
12343+#endif
12344+
12345+ : "=r" (new)
12346+ : "0" (c));
12347+
12348+ val = atomic_cmpxchg(v, c, new);
12349+ if (val == c)
12350+ return 1;
12351+ c = val;
12352+ } while (c);
12353+
12354+ return 0;
12355+}
12356+
12357+/**
12358 * atomic_inc_short - increment of a short integer
12359 * @v: pointer to type int
12360 *
12361@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12362 #endif
12363
12364 /* These are x86-specific, used by some header files */
12365-#define atomic_clear_mask(mask, addr) \
12366- asm volatile(LOCK_PREFIX "andl %0,%1" \
12367- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12368+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12369+{
12370+ asm volatile(LOCK_PREFIX "andl %1,%0"
12371+ : "+m" (v->counter)
12372+ : "r" (~(mask))
12373+ : "memory");
12374+}
12375
12376-#define atomic_set_mask(mask, addr) \
12377- asm volatile(LOCK_PREFIX "orl %0,%1" \
12378- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12379- : "memory")
12380+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12381+{
12382+ asm volatile(LOCK_PREFIX "andl %1,%0"
12383+ : "+m" (v->counter)
12384+ : "r" (~(mask))
12385+ : "memory");
12386+}
12387+
12388+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12389+{
12390+ asm volatile(LOCK_PREFIX "orl %1,%0"
12391+ : "+m" (v->counter)
12392+ : "r" (mask)
12393+ : "memory");
12394+}
12395+
12396+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12397+{
12398+ asm volatile(LOCK_PREFIX "orl %1,%0"
12399+ : "+m" (v->counter)
12400+ : "r" (mask)
12401+ : "memory");
12402+}
12403
12404 /* Atomic operations are already serializing on x86 */
12405 #define smp_mb__before_atomic_dec() barrier()
12406diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12407index b154de7..aadebd8 100644
12408--- a/arch/x86/include/asm/atomic64_32.h
12409+++ b/arch/x86/include/asm/atomic64_32.h
12410@@ -12,6 +12,14 @@ typedef struct {
12411 u64 __aligned(8) counter;
12412 } atomic64_t;
12413
12414+#ifdef CONFIG_PAX_REFCOUNT
12415+typedef struct {
12416+ u64 __aligned(8) counter;
12417+} atomic64_unchecked_t;
12418+#else
12419+typedef atomic64_t atomic64_unchecked_t;
12420+#endif
12421+
12422 #define ATOMIC64_INIT(val) { (val) }
12423
12424 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12425@@ -37,21 +45,31 @@ typedef struct {
12426 ATOMIC64_DECL_ONE(sym##_386)
12427
12428 ATOMIC64_DECL_ONE(add_386);
12429+ATOMIC64_DECL_ONE(add_unchecked_386);
12430 ATOMIC64_DECL_ONE(sub_386);
12431+ATOMIC64_DECL_ONE(sub_unchecked_386);
12432 ATOMIC64_DECL_ONE(inc_386);
12433+ATOMIC64_DECL_ONE(inc_unchecked_386);
12434 ATOMIC64_DECL_ONE(dec_386);
12435+ATOMIC64_DECL_ONE(dec_unchecked_386);
12436 #endif
12437
12438 #define alternative_atomic64(f, out, in...) \
12439 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12440
12441 ATOMIC64_DECL(read);
12442+ATOMIC64_DECL(read_unchecked);
12443 ATOMIC64_DECL(set);
12444+ATOMIC64_DECL(set_unchecked);
12445 ATOMIC64_DECL(xchg);
12446 ATOMIC64_DECL(add_return);
12447+ATOMIC64_DECL(add_return_unchecked);
12448 ATOMIC64_DECL(sub_return);
12449+ATOMIC64_DECL(sub_return_unchecked);
12450 ATOMIC64_DECL(inc_return);
12451+ATOMIC64_DECL(inc_return_unchecked);
12452 ATOMIC64_DECL(dec_return);
12453+ATOMIC64_DECL(dec_return_unchecked);
12454 ATOMIC64_DECL(dec_if_positive);
12455 ATOMIC64_DECL(inc_not_zero);
12456 ATOMIC64_DECL(add_unless);
12457@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12458 }
12459
12460 /**
12461+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12462+ * @p: pointer to type atomic64_unchecked_t
12463+ * @o: expected value
12464+ * @n: new value
12465+ *
12466+ * Atomically sets @v to @n if it was equal to @o and returns
12467+ * the old value.
12468+ */
12469+
12470+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12471+{
12472+ return cmpxchg64(&v->counter, o, n);
12473+}
12474+
12475+/**
12476 * atomic64_xchg - xchg atomic64 variable
12477 * @v: pointer to type atomic64_t
12478 * @n: value to assign
12479@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12480 }
12481
12482 /**
12483+ * atomic64_set_unchecked - set atomic64 variable
12484+ * @v: pointer to type atomic64_unchecked_t
12485+ * @n: value to assign
12486+ *
12487+ * Atomically sets the value of @v to @n.
12488+ */
12489+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12490+{
12491+ unsigned high = (unsigned)(i >> 32);
12492+ unsigned low = (unsigned)i;
12493+ alternative_atomic64(set, /* no output */,
12494+ "S" (v), "b" (low), "c" (high)
12495+ : "eax", "edx", "memory");
12496+}
12497+
12498+/**
12499 * atomic64_read - read atomic64 variable
12500 * @v: pointer to type atomic64_t
12501 *
12502@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12503 }
12504
12505 /**
12506+ * atomic64_read_unchecked - read atomic64 variable
12507+ * @v: pointer to type atomic64_unchecked_t
12508+ *
12509+ * Atomically reads the value of @v and returns it.
12510+ */
12511+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12512+{
12513+ long long r;
12514+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12515+ return r;
12516+ }
12517+
12518+/**
12519 * atomic64_add_return - add and return
12520 * @i: integer value to add
12521 * @v: pointer to type atomic64_t
12522@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12523 return i;
12524 }
12525
12526+/**
12527+ * atomic64_add_return_unchecked - add and return
12528+ * @i: integer value to add
12529+ * @v: pointer to type atomic64_unchecked_t
12530+ *
12531+ * Atomically adds @i to @v and returns @i + *@v
12532+ */
12533+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12534+{
12535+ alternative_atomic64(add_return_unchecked,
12536+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12537+ ASM_NO_INPUT_CLOBBER("memory"));
12538+ return i;
12539+}
12540+
12541 /*
12542 * Other variants with different arithmetic operators:
12543 */
12544@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12545 return a;
12546 }
12547
12548+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12549+{
12550+ long long a;
12551+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12552+ "S" (v) : "memory", "ecx");
12553+ return a;
12554+}
12555+
12556 static inline long long atomic64_dec_return(atomic64_t *v)
12557 {
12558 long long a;
12559@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12560 }
12561
12562 /**
12563+ * atomic64_add_unchecked - add integer to atomic64 variable
12564+ * @i: integer value to add
12565+ * @v: pointer to type atomic64_unchecked_t
12566+ *
12567+ * Atomically adds @i to @v.
12568+ */
12569+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12570+{
12571+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12572+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12573+ ASM_NO_INPUT_CLOBBER("memory"));
12574+ return i;
12575+}
12576+
12577+/**
12578 * atomic64_sub - subtract the atomic64 variable
12579 * @i: integer value to subtract
12580 * @v: pointer to type atomic64_t
12581diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12582index 0e1cbfc..5623683 100644
12583--- a/arch/x86/include/asm/atomic64_64.h
12584+++ b/arch/x86/include/asm/atomic64_64.h
12585@@ -18,7 +18,19 @@
12586 */
12587 static inline long atomic64_read(const atomic64_t *v)
12588 {
12589- return (*(volatile long *)&(v)->counter);
12590+ return (*(volatile const long *)&(v)->counter);
12591+}
12592+
12593+/**
12594+ * atomic64_read_unchecked - read atomic64 variable
12595+ * @v: pointer of type atomic64_unchecked_t
12596+ *
12597+ * Atomically reads the value of @v.
12598+ * Doesn't imply a read memory barrier.
12599+ */
12600+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12601+{
12602+ return (*(volatile const long *)&(v)->counter);
12603 }
12604
12605 /**
12606@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12607 }
12608
12609 /**
12610+ * atomic64_set_unchecked - set atomic64 variable
12611+ * @v: pointer to type atomic64_unchecked_t
12612+ * @i: required value
12613+ *
12614+ * Atomically sets the value of @v to @i.
12615+ */
12616+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12617+{
12618+ v->counter = i;
12619+}
12620+
12621+/**
12622 * atomic64_add - add integer to atomic64 variable
12623 * @i: integer value to add
12624 * @v: pointer to type atomic64_t
12625@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12626 */
12627 static inline void atomic64_add(long i, atomic64_t *v)
12628 {
12629+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12630+
12631+#ifdef CONFIG_PAX_REFCOUNT
12632+ "jno 0f\n"
12633+ LOCK_PREFIX "subq %1,%0\n"
12634+ "int $4\n0:\n"
12635+ _ASM_EXTABLE(0b, 0b)
12636+#endif
12637+
12638+ : "=m" (v->counter)
12639+ : "er" (i), "m" (v->counter));
12640+}
12641+
12642+/**
12643+ * atomic64_add_unchecked - add integer to atomic64 variable
12644+ * @i: integer value to add
12645+ * @v: pointer to type atomic64_unchecked_t
12646+ *
12647+ * Atomically adds @i to @v.
12648+ */
12649+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12650+{
12651 asm volatile(LOCK_PREFIX "addq %1,%0"
12652 : "=m" (v->counter)
12653 : "er" (i), "m" (v->counter));
12654@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12655 */
12656 static inline void atomic64_sub(long i, atomic64_t *v)
12657 {
12658- asm volatile(LOCK_PREFIX "subq %1,%0"
12659+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12660+
12661+#ifdef CONFIG_PAX_REFCOUNT
12662+ "jno 0f\n"
12663+ LOCK_PREFIX "addq %1,%0\n"
12664+ "int $4\n0:\n"
12665+ _ASM_EXTABLE(0b, 0b)
12666+#endif
12667+
12668+ : "=m" (v->counter)
12669+ : "er" (i), "m" (v->counter));
12670+}
12671+
12672+/**
12673+ * atomic64_sub_unchecked - subtract the atomic64 variable
12674+ * @i: integer value to subtract
12675+ * @v: pointer to type atomic64_unchecked_t
12676+ *
12677+ * Atomically subtracts @i from @v.
12678+ */
12679+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12680+{
12681+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12682 : "=m" (v->counter)
12683 : "er" (i), "m" (v->counter));
12684 }
12685@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12686 {
12687 unsigned char c;
12688
12689- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12690+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12691+
12692+#ifdef CONFIG_PAX_REFCOUNT
12693+ "jno 0f\n"
12694+ LOCK_PREFIX "addq %2,%0\n"
12695+ "int $4\n0:\n"
12696+ _ASM_EXTABLE(0b, 0b)
12697+#endif
12698+
12699+ "sete %1\n"
12700 : "=m" (v->counter), "=qm" (c)
12701 : "er" (i), "m" (v->counter) : "memory");
12702 return c;
12703@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12704 */
12705 static inline void atomic64_inc(atomic64_t *v)
12706 {
12707+ asm volatile(LOCK_PREFIX "incq %0\n"
12708+
12709+#ifdef CONFIG_PAX_REFCOUNT
12710+ "jno 0f\n"
12711+ LOCK_PREFIX "decq %0\n"
12712+ "int $4\n0:\n"
12713+ _ASM_EXTABLE(0b, 0b)
12714+#endif
12715+
12716+ : "=m" (v->counter)
12717+ : "m" (v->counter));
12718+}
12719+
12720+/**
12721+ * atomic64_inc_unchecked - increment atomic64 variable
12722+ * @v: pointer to type atomic64_unchecked_t
12723+ *
12724+ * Atomically increments @v by 1.
12725+ */
12726+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12727+{
12728 asm volatile(LOCK_PREFIX "incq %0"
12729 : "=m" (v->counter)
12730 : "m" (v->counter));
12731@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12732 */
12733 static inline void atomic64_dec(atomic64_t *v)
12734 {
12735- asm volatile(LOCK_PREFIX "decq %0"
12736+ asm volatile(LOCK_PREFIX "decq %0\n"
12737+
12738+#ifdef CONFIG_PAX_REFCOUNT
12739+ "jno 0f\n"
12740+ LOCK_PREFIX "incq %0\n"
12741+ "int $4\n0:\n"
12742+ _ASM_EXTABLE(0b, 0b)
12743+#endif
12744+
12745+ : "=m" (v->counter)
12746+ : "m" (v->counter));
12747+}
12748+
12749+/**
12750+ * atomic64_dec_unchecked - decrement atomic64 variable
12751+ * @v: pointer to type atomic64_t
12752+ *
12753+ * Atomically decrements @v by 1.
12754+ */
12755+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12756+{
12757+ asm volatile(LOCK_PREFIX "decq %0\n"
12758 : "=m" (v->counter)
12759 : "m" (v->counter));
12760 }
12761@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12762 {
12763 unsigned char c;
12764
12765- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12766+ asm volatile(LOCK_PREFIX "decq %0\n"
12767+
12768+#ifdef CONFIG_PAX_REFCOUNT
12769+ "jno 0f\n"
12770+ LOCK_PREFIX "incq %0\n"
12771+ "int $4\n0:\n"
12772+ _ASM_EXTABLE(0b, 0b)
12773+#endif
12774+
12775+ "sete %1\n"
12776 : "=m" (v->counter), "=qm" (c)
12777 : "m" (v->counter) : "memory");
12778 return c != 0;
12779@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12780 {
12781 unsigned char c;
12782
12783- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12784+ asm volatile(LOCK_PREFIX "incq %0\n"
12785+
12786+#ifdef CONFIG_PAX_REFCOUNT
12787+ "jno 0f\n"
12788+ LOCK_PREFIX "decq %0\n"
12789+ "int $4\n0:\n"
12790+ _ASM_EXTABLE(0b, 0b)
12791+#endif
12792+
12793+ "sete %1\n"
12794 : "=m" (v->counter), "=qm" (c)
12795 : "m" (v->counter) : "memory");
12796 return c != 0;
12797@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12798 {
12799 unsigned char c;
12800
12801- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12802+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12803+
12804+#ifdef CONFIG_PAX_REFCOUNT
12805+ "jno 0f\n"
12806+ LOCK_PREFIX "subq %2,%0\n"
12807+ "int $4\n0:\n"
12808+ _ASM_EXTABLE(0b, 0b)
12809+#endif
12810+
12811+ "sets %1\n"
12812 : "=m" (v->counter), "=qm" (c)
12813 : "er" (i), "m" (v->counter) : "memory");
12814 return c;
12815@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12816 */
12817 static inline long atomic64_add_return(long i, atomic64_t *v)
12818 {
12819+ return i + xadd_check_overflow(&v->counter, i);
12820+}
12821+
12822+/**
12823+ * atomic64_add_return_unchecked - add and return
12824+ * @i: integer value to add
12825+ * @v: pointer to type atomic64_unchecked_t
12826+ *
12827+ * Atomically adds @i to @v and returns @i + @v
12828+ */
12829+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12830+{
12831 return i + xadd(&v->counter, i);
12832 }
12833
12834@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12835 }
12836
12837 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12838+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12839+{
12840+ return atomic64_add_return_unchecked(1, v);
12841+}
12842 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12843
12844 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12845@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12846 return cmpxchg(&v->counter, old, new);
12847 }
12848
12849+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12850+{
12851+ return cmpxchg(&v->counter, old, new);
12852+}
12853+
12854 static inline long atomic64_xchg(atomic64_t *v, long new)
12855 {
12856 return xchg(&v->counter, new);
12857@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12858 */
12859 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12860 {
12861- long c, old;
12862+ long c, old, new;
12863 c = atomic64_read(v);
12864 for (;;) {
12865- if (unlikely(c == (u)))
12866+ if (unlikely(c == u))
12867 break;
12868- old = atomic64_cmpxchg((v), c, c + (a));
12869+
12870+ asm volatile("add %2,%0\n"
12871+
12872+#ifdef CONFIG_PAX_REFCOUNT
12873+ "jno 0f\n"
12874+ "sub %2,%0\n"
12875+ "int $4\n0:\n"
12876+ _ASM_EXTABLE(0b, 0b)
12877+#endif
12878+
12879+ : "=r" (new)
12880+ : "0" (c), "ir" (a));
12881+
12882+ old = atomic64_cmpxchg(v, c, new);
12883 if (likely(old == c))
12884 break;
12885 c = old;
12886 }
12887- return c != (u);
12888+ return c != u;
12889 }
12890
12891 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12892diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12893index 6dfd019..28e188d 100644
12894--- a/arch/x86/include/asm/bitops.h
12895+++ b/arch/x86/include/asm/bitops.h
12896@@ -40,7 +40,7 @@
12897 * a mask operation on a byte.
12898 */
12899 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12900-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12901+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12902 #define CONST_MASK(nr) (1 << ((nr) & 7))
12903
12904 /**
12905@@ -486,7 +486,7 @@ static inline int fls(int x)
12906 * at position 64.
12907 */
12908 #ifdef CONFIG_X86_64
12909-static __always_inline int fls64(__u64 x)
12910+static __always_inline long fls64(__u64 x)
12911 {
12912 int bitpos = -1;
12913 /*
12914diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12915index 4fa687a..60f2d39 100644
12916--- a/arch/x86/include/asm/boot.h
12917+++ b/arch/x86/include/asm/boot.h
12918@@ -6,10 +6,15 @@
12919 #include <uapi/asm/boot.h>
12920
12921 /* Physical address where kernel should be loaded. */
12922-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12923+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12924 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12925 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12926
12927+#ifndef __ASSEMBLY__
12928+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12929+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12930+#endif
12931+
12932 /* Minimum kernel alignment, as a power of two */
12933 #ifdef CONFIG_X86_64
12934 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12935diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12936index 48f99f1..d78ebf9 100644
12937--- a/arch/x86/include/asm/cache.h
12938+++ b/arch/x86/include/asm/cache.h
12939@@ -5,12 +5,13 @@
12940
12941 /* L1 cache line size */
12942 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12943-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12944+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12945
12946 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12947+#define __read_only __attribute__((__section__(".data..read_only")))
12948
12949 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12950-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12951+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12952
12953 #ifdef CONFIG_X86_VSMP
12954 #ifdef CONFIG_SMP
12955diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12956index 9863ee3..4a1f8e1 100644
12957--- a/arch/x86/include/asm/cacheflush.h
12958+++ b/arch/x86/include/asm/cacheflush.h
12959@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12960 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12961
12962 if (pg_flags == _PGMT_DEFAULT)
12963- return -1;
12964+ return ~0UL;
12965 else if (pg_flags == _PGMT_WC)
12966 return _PAGE_CACHE_WC;
12967 else if (pg_flags == _PGMT_UC_MINUS)
12968diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12969index 46fc474..b02b0f9 100644
12970--- a/arch/x86/include/asm/checksum_32.h
12971+++ b/arch/x86/include/asm/checksum_32.h
12972@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12973 int len, __wsum sum,
12974 int *src_err_ptr, int *dst_err_ptr);
12975
12976+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12977+ int len, __wsum sum,
12978+ int *src_err_ptr, int *dst_err_ptr);
12979+
12980+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12981+ int len, __wsum sum,
12982+ int *src_err_ptr, int *dst_err_ptr);
12983+
12984 /*
12985 * Note: when you get a NULL pointer exception here this means someone
12986 * passed in an incorrect kernel address to one of these functions.
12987@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12988 int *err_ptr)
12989 {
12990 might_sleep();
12991- return csum_partial_copy_generic((__force void *)src, dst,
12992+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
12993 len, sum, err_ptr, NULL);
12994 }
12995
12996@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12997 {
12998 might_sleep();
12999 if (access_ok(VERIFY_WRITE, dst, len))
13000- return csum_partial_copy_generic(src, (__force void *)dst,
13001+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
13002 len, sum, NULL, err_ptr);
13003
13004 if (len)
13005diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
13006index d47786a..ce1b05d 100644
13007--- a/arch/x86/include/asm/cmpxchg.h
13008+++ b/arch/x86/include/asm/cmpxchg.h
13009@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
13010 __compiletime_error("Bad argument size for cmpxchg");
13011 extern void __xadd_wrong_size(void)
13012 __compiletime_error("Bad argument size for xadd");
13013+extern void __xadd_check_overflow_wrong_size(void)
13014+ __compiletime_error("Bad argument size for xadd_check_overflow");
13015 extern void __add_wrong_size(void)
13016 __compiletime_error("Bad argument size for add");
13017+extern void __add_check_overflow_wrong_size(void)
13018+ __compiletime_error("Bad argument size for add_check_overflow");
13019
13020 /*
13021 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
13022@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
13023 __ret; \
13024 })
13025
13026+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
13027+ ({ \
13028+ __typeof__ (*(ptr)) __ret = (arg); \
13029+ switch (sizeof(*(ptr))) { \
13030+ case __X86_CASE_L: \
13031+ asm volatile (lock #op "l %0, %1\n" \
13032+ "jno 0f\n" \
13033+ "mov %0,%1\n" \
13034+ "int $4\n0:\n" \
13035+ _ASM_EXTABLE(0b, 0b) \
13036+ : "+r" (__ret), "+m" (*(ptr)) \
13037+ : : "memory", "cc"); \
13038+ break; \
13039+ case __X86_CASE_Q: \
13040+ asm volatile (lock #op "q %q0, %1\n" \
13041+ "jno 0f\n" \
13042+ "mov %0,%1\n" \
13043+ "int $4\n0:\n" \
13044+ _ASM_EXTABLE(0b, 0b) \
13045+ : "+r" (__ret), "+m" (*(ptr)) \
13046+ : : "memory", "cc"); \
13047+ break; \
13048+ default: \
13049+ __ ## op ## _check_overflow_wrong_size(); \
13050+ } \
13051+ __ret; \
13052+ })
13053+
13054 /*
13055 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
13056 * Since this is generally used to protect other memory information, we
13057@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
13058 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
13059 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
13060
13061+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
13062+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
13063+
13064 #define __add(ptr, inc, lock) \
13065 ({ \
13066 __typeof__ (*(ptr)) __ret = (inc); \
13067diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
13068index 59c6c40..5e0b22c 100644
13069--- a/arch/x86/include/asm/compat.h
13070+++ b/arch/x86/include/asm/compat.h
13071@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
13072 typedef u32 compat_uint_t;
13073 typedef u32 compat_ulong_t;
13074 typedef u64 __attribute__((aligned(4))) compat_u64;
13075-typedef u32 compat_uptr_t;
13076+typedef u32 __user compat_uptr_t;
13077
13078 struct compat_timespec {
13079 compat_time_t tv_sec;
13080diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
13081index e99ac27..e89e28c 100644
13082--- a/arch/x86/include/asm/cpufeature.h
13083+++ b/arch/x86/include/asm/cpufeature.h
13084@@ -211,7 +211,7 @@
13085 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
13086 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
13087 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
13088-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
13089+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
13090 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
13091 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
13092 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
13093@@ -394,7 +394,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
13094 ".section .discard,\"aw\",@progbits\n"
13095 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
13096 ".previous\n"
13097- ".section .altinstr_replacement,\"ax\"\n"
13098+ ".section .altinstr_replacement,\"a\"\n"
13099 "3: movb $1,%0\n"
13100 "4:\n"
13101 ".previous\n"
13102diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
13103index 8bf1c06..b6ae785 100644
13104--- a/arch/x86/include/asm/desc.h
13105+++ b/arch/x86/include/asm/desc.h
13106@@ -4,6 +4,7 @@
13107 #include <asm/desc_defs.h>
13108 #include <asm/ldt.h>
13109 #include <asm/mmu.h>
13110+#include <asm/pgtable.h>
13111
13112 #include <linux/smp.h>
13113 #include <linux/percpu.h>
13114@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13115
13116 desc->type = (info->read_exec_only ^ 1) << 1;
13117 desc->type |= info->contents << 2;
13118+ desc->type |= info->seg_not_present ^ 1;
13119
13120 desc->s = 1;
13121 desc->dpl = 0x3;
13122@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13123 }
13124
13125 extern struct desc_ptr idt_descr;
13126-extern gate_desc idt_table[];
13127 extern struct desc_ptr nmi_idt_descr;
13128-extern gate_desc nmi_idt_table[];
13129-
13130-struct gdt_page {
13131- struct desc_struct gdt[GDT_ENTRIES];
13132-} __attribute__((aligned(PAGE_SIZE)));
13133-
13134-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13135+extern gate_desc idt_table[256];
13136+extern gate_desc nmi_idt_table[256];
13137
13138+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13139 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13140 {
13141- return per_cpu(gdt_page, cpu).gdt;
13142+ return cpu_gdt_table[cpu];
13143 }
13144
13145 #ifdef CONFIG_X86_64
13146@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13147 unsigned long base, unsigned dpl, unsigned flags,
13148 unsigned short seg)
13149 {
13150- gate->a = (seg << 16) | (base & 0xffff);
13151- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13152+ gate->gate.offset_low = base;
13153+ gate->gate.seg = seg;
13154+ gate->gate.reserved = 0;
13155+ gate->gate.type = type;
13156+ gate->gate.s = 0;
13157+ gate->gate.dpl = dpl;
13158+ gate->gate.p = 1;
13159+ gate->gate.offset_high = base >> 16;
13160 }
13161
13162 #endif
13163@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13164
13165 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13166 {
13167+ pax_open_kernel();
13168 memcpy(&idt[entry], gate, sizeof(*gate));
13169+ pax_close_kernel();
13170 }
13171
13172 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13173 {
13174+ pax_open_kernel();
13175 memcpy(&ldt[entry], desc, 8);
13176+ pax_close_kernel();
13177 }
13178
13179 static inline void
13180@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13181 default: size = sizeof(*gdt); break;
13182 }
13183
13184+ pax_open_kernel();
13185 memcpy(&gdt[entry], desc, size);
13186+ pax_close_kernel();
13187 }
13188
13189 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13190@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13191
13192 static inline void native_load_tr_desc(void)
13193 {
13194+ pax_open_kernel();
13195 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13196+ pax_close_kernel();
13197 }
13198
13199 static inline void native_load_gdt(const struct desc_ptr *dtr)
13200@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13201 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13202 unsigned int i;
13203
13204+ pax_open_kernel();
13205 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13206 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13207+ pax_close_kernel();
13208 }
13209
13210 #define _LDT_empty(info) \
13211@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13212 preempt_enable();
13213 }
13214
13215-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13216+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13217 {
13218 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13219 }
13220@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13221 }
13222
13223 #ifdef CONFIG_X86_64
13224-static inline void set_nmi_gate(int gate, void *addr)
13225+static inline void set_nmi_gate(int gate, const void *addr)
13226 {
13227 gate_desc s;
13228
13229@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13230 }
13231 #endif
13232
13233-static inline void _set_gate(int gate, unsigned type, void *addr,
13234+static inline void _set_gate(int gate, unsigned type, const void *addr,
13235 unsigned dpl, unsigned ist, unsigned seg)
13236 {
13237 gate_desc s;
13238@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13239 * Pentium F0 0F bugfix can have resulted in the mapped
13240 * IDT being write-protected.
13241 */
13242-static inline void set_intr_gate(unsigned int n, void *addr)
13243+static inline void set_intr_gate(unsigned int n, const void *addr)
13244 {
13245 BUG_ON((unsigned)n > 0xFF);
13246 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13247@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13248 /*
13249 * This routine sets up an interrupt gate at directory privilege level 3.
13250 */
13251-static inline void set_system_intr_gate(unsigned int n, void *addr)
13252+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13253 {
13254 BUG_ON((unsigned)n > 0xFF);
13255 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13256 }
13257
13258-static inline void set_system_trap_gate(unsigned int n, void *addr)
13259+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13260 {
13261 BUG_ON((unsigned)n > 0xFF);
13262 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13263 }
13264
13265-static inline void set_trap_gate(unsigned int n, void *addr)
13266+static inline void set_trap_gate(unsigned int n, const void *addr)
13267 {
13268 BUG_ON((unsigned)n > 0xFF);
13269 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13270@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13271 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13272 {
13273 BUG_ON((unsigned)n > 0xFF);
13274- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13275+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13276 }
13277
13278-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13279+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13280 {
13281 BUG_ON((unsigned)n > 0xFF);
13282 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13283 }
13284
13285-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13286+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13287 {
13288 BUG_ON((unsigned)n > 0xFF);
13289 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13290 }
13291
13292+#ifdef CONFIG_X86_32
13293+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13294+{
13295+ struct desc_struct d;
13296+
13297+ if (likely(limit))
13298+ limit = (limit - 1UL) >> PAGE_SHIFT;
13299+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13300+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13301+}
13302+#endif
13303+
13304 #endif /* _ASM_X86_DESC_H */
13305diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13306index 278441f..b95a174 100644
13307--- a/arch/x86/include/asm/desc_defs.h
13308+++ b/arch/x86/include/asm/desc_defs.h
13309@@ -31,6 +31,12 @@ struct desc_struct {
13310 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13311 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13312 };
13313+ struct {
13314+ u16 offset_low;
13315+ u16 seg;
13316+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13317+ unsigned offset_high: 16;
13318+ } gate;
13319 };
13320 } __attribute__((packed));
13321
13322diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13323index ced283a..ffe04cc 100644
13324--- a/arch/x86/include/asm/div64.h
13325+++ b/arch/x86/include/asm/div64.h
13326@@ -39,7 +39,7 @@
13327 __mod; \
13328 })
13329
13330-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13331+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13332 {
13333 union {
13334 u64 v64;
13335diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13336index 9c999c1..3860cb8 100644
13337--- a/arch/x86/include/asm/elf.h
13338+++ b/arch/x86/include/asm/elf.h
13339@@ -243,7 +243,25 @@ extern int force_personality32;
13340 the loader. We need to make sure that it is out of the way of the program
13341 that it will "exec", and that there is sufficient room for the brk. */
13342
13343+#ifdef CONFIG_PAX_SEGMEXEC
13344+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13345+#else
13346 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13347+#endif
13348+
13349+#ifdef CONFIG_PAX_ASLR
13350+#ifdef CONFIG_X86_32
13351+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13352+
13353+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13354+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13355+#else
13356+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13357+
13358+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13359+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13360+#endif
13361+#endif
13362
13363 /* This yields a mask that user programs can use to figure out what
13364 instruction set this CPU supports. This could be done in user space,
13365@@ -296,16 +314,12 @@ do { \
13366
13367 #define ARCH_DLINFO \
13368 do { \
13369- if (vdso_enabled) \
13370- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13371- (unsigned long)current->mm->context.vdso); \
13372+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13373 } while (0)
13374
13375 #define ARCH_DLINFO_X32 \
13376 do { \
13377- if (vdso_enabled) \
13378- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13379- (unsigned long)current->mm->context.vdso); \
13380+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13381 } while (0)
13382
13383 #define AT_SYSINFO 32
13384@@ -320,7 +334,7 @@ else \
13385
13386 #endif /* !CONFIG_X86_32 */
13387
13388-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13389+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13390
13391 #define VDSO_ENTRY \
13392 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13393@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13394 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13395 #define compat_arch_setup_additional_pages syscall32_setup_pages
13396
13397-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13398-#define arch_randomize_brk arch_randomize_brk
13399-
13400 /*
13401 * True on X86_32 or when emulating IA32 on X86_64
13402 */
13403diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13404index 75ce3f4..882e801 100644
13405--- a/arch/x86/include/asm/emergency-restart.h
13406+++ b/arch/x86/include/asm/emergency-restart.h
13407@@ -13,6 +13,6 @@ enum reboot_type {
13408
13409 extern enum reboot_type reboot_type;
13410
13411-extern void machine_emergency_restart(void);
13412+extern void machine_emergency_restart(void) __noreturn;
13413
13414 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13415diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13416index e25cc33..425d099 100644
13417--- a/arch/x86/include/asm/fpu-internal.h
13418+++ b/arch/x86/include/asm/fpu-internal.h
13419@@ -127,7 +127,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13420 ({ \
13421 int err; \
13422 asm volatile(ASM_STAC "\n" \
13423- "1:" #insn "\n\t" \
13424+ "1:" \
13425+ __copyuser_seg \
13426+ #insn "\n\t" \
13427 "2: " ASM_CLAC "\n" \
13428 ".section .fixup,\"ax\"\n" \
13429 "3: movl $-1,%[err]\n" \
13430@@ -300,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13431 "emms\n\t" /* clear stack tags */
13432 "fildl %P[addr]", /* set F?P to defined value */
13433 X86_FEATURE_FXSAVE_LEAK,
13434- [addr] "m" (tsk->thread.fpu.has_fpu));
13435+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13436
13437 return fpu_restore_checking(&tsk->thread.fpu);
13438 }
13439diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13440index be27ba1..8f13ff9 100644
13441--- a/arch/x86/include/asm/futex.h
13442+++ b/arch/x86/include/asm/futex.h
13443@@ -12,6 +12,7 @@
13444 #include <asm/smap.h>
13445
13446 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13447+ typecheck(u32 __user *, uaddr); \
13448 asm volatile("\t" ASM_STAC "\n" \
13449 "1:\t" insn "\n" \
13450 "2:\t" ASM_CLAC "\n" \
13451@@ -20,15 +21,16 @@
13452 "\tjmp\t2b\n" \
13453 "\t.previous\n" \
13454 _ASM_EXTABLE(1b, 3b) \
13455- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13456+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13457 : "i" (-EFAULT), "0" (oparg), "1" (0))
13458
13459 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13460+ typecheck(u32 __user *, uaddr); \
13461 asm volatile("\t" ASM_STAC "\n" \
13462 "1:\tmovl %2, %0\n" \
13463 "\tmovl\t%0, %3\n" \
13464 "\t" insn "\n" \
13465- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13466+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13467 "\tjnz\t1b\n" \
13468 "3:\t" ASM_CLAC "\n" \
13469 "\t.section .fixup,\"ax\"\n" \
13470@@ -38,7 +40,7 @@
13471 _ASM_EXTABLE(1b, 4b) \
13472 _ASM_EXTABLE(2b, 4b) \
13473 : "=&a" (oldval), "=&r" (ret), \
13474- "+m" (*uaddr), "=&r" (tem) \
13475+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13476 : "r" (oparg), "i" (-EFAULT), "1" (0))
13477
13478 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13479@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13480
13481 switch (op) {
13482 case FUTEX_OP_SET:
13483- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13484+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13485 break;
13486 case FUTEX_OP_ADD:
13487- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13488+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13489 uaddr, oparg);
13490 break;
13491 case FUTEX_OP_OR:
13492@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13493 return -EFAULT;
13494
13495 asm volatile("\t" ASM_STAC "\n"
13496- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13497+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13498 "2:\t" ASM_CLAC "\n"
13499 "\t.section .fixup, \"ax\"\n"
13500 "3:\tmov %3, %0\n"
13501 "\tjmp 2b\n"
13502 "\t.previous\n"
13503 _ASM_EXTABLE(1b, 3b)
13504- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13505+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13506 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13507 : "memory"
13508 );
13509diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13510index 1da97ef..9c2ebff 100644
13511--- a/arch/x86/include/asm/hw_irq.h
13512+++ b/arch/x86/include/asm/hw_irq.h
13513@@ -148,8 +148,8 @@ extern void setup_ioapic_dest(void);
13514 extern void enable_IO_APIC(void);
13515
13516 /* Statistics */
13517-extern atomic_t irq_err_count;
13518-extern atomic_t irq_mis_count;
13519+extern atomic_unchecked_t irq_err_count;
13520+extern atomic_unchecked_t irq_mis_count;
13521
13522 /* EISA */
13523 extern void eisa_set_level_irq(unsigned int irq);
13524diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13525index a203659..9889f1c 100644
13526--- a/arch/x86/include/asm/i8259.h
13527+++ b/arch/x86/include/asm/i8259.h
13528@@ -62,7 +62,7 @@ struct legacy_pic {
13529 void (*init)(int auto_eoi);
13530 int (*irq_pending)(unsigned int irq);
13531 void (*make_irq)(unsigned int irq);
13532-};
13533+} __do_const;
13534
13535 extern struct legacy_pic *legacy_pic;
13536 extern struct legacy_pic null_legacy_pic;
13537diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13538index d8e8eef..1765f78 100644
13539--- a/arch/x86/include/asm/io.h
13540+++ b/arch/x86/include/asm/io.h
13541@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13542 "m" (*(volatile type __force *)addr) barrier); }
13543
13544 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13545-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13546-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13547+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13548+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13549
13550 build_mmio_read(__readb, "b", unsigned char, "=q", )
13551-build_mmio_read(__readw, "w", unsigned short, "=r", )
13552-build_mmio_read(__readl, "l", unsigned int, "=r", )
13553+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13554+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13555
13556 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13557 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13558@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13559 return ioremap_nocache(offset, size);
13560 }
13561
13562-extern void iounmap(volatile void __iomem *addr);
13563+extern void iounmap(const volatile void __iomem *addr);
13564
13565 extern void set_iounmap_nonlazy(void);
13566
13567@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13568
13569 #include <linux/vmalloc.h>
13570
13571+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13572+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13573+{
13574+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13575+}
13576+
13577+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13578+{
13579+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13580+}
13581+
13582 /*
13583 * Convert a virtual cached pointer to an uncached pointer
13584 */
13585diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13586index bba3cf8..06bc8da 100644
13587--- a/arch/x86/include/asm/irqflags.h
13588+++ b/arch/x86/include/asm/irqflags.h
13589@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13590 sti; \
13591 sysexit
13592
13593+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13594+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13595+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13596+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13597+
13598 #else
13599 #define INTERRUPT_RETURN iret
13600 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13601diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13602index 5a6d287..f815789 100644
13603--- a/arch/x86/include/asm/kprobes.h
13604+++ b/arch/x86/include/asm/kprobes.h
13605@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13606 #define RELATIVEJUMP_SIZE 5
13607 #define RELATIVECALL_OPCODE 0xe8
13608 #define RELATIVE_ADDR_SIZE 4
13609-#define MAX_STACK_SIZE 64
13610-#define MIN_STACK_SIZE(ADDR) \
13611- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13612- THREAD_SIZE - (unsigned long)(ADDR))) \
13613- ? (MAX_STACK_SIZE) \
13614- : (((unsigned long)current_thread_info()) + \
13615- THREAD_SIZE - (unsigned long)(ADDR)))
13616+#define MAX_STACK_SIZE 64UL
13617+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13618
13619 #define flush_insn_slot(p) do { } while (0)
13620
13621diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13622index 2d89e39..baee879 100644
13623--- a/arch/x86/include/asm/local.h
13624+++ b/arch/x86/include/asm/local.h
13625@@ -10,33 +10,97 @@ typedef struct {
13626 atomic_long_t a;
13627 } local_t;
13628
13629+typedef struct {
13630+ atomic_long_unchecked_t a;
13631+} local_unchecked_t;
13632+
13633 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13634
13635 #define local_read(l) atomic_long_read(&(l)->a)
13636+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13637 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13638+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13639
13640 static inline void local_inc(local_t *l)
13641 {
13642- asm volatile(_ASM_INC "%0"
13643+ asm volatile(_ASM_INC "%0\n"
13644+
13645+#ifdef CONFIG_PAX_REFCOUNT
13646+ "jno 0f\n"
13647+ _ASM_DEC "%0\n"
13648+ "int $4\n0:\n"
13649+ _ASM_EXTABLE(0b, 0b)
13650+#endif
13651+
13652+ : "+m" (l->a.counter));
13653+}
13654+
13655+static inline void local_inc_unchecked(local_unchecked_t *l)
13656+{
13657+ asm volatile(_ASM_INC "%0\n"
13658 : "+m" (l->a.counter));
13659 }
13660
13661 static inline void local_dec(local_t *l)
13662 {
13663- asm volatile(_ASM_DEC "%0"
13664+ asm volatile(_ASM_DEC "%0\n"
13665+
13666+#ifdef CONFIG_PAX_REFCOUNT
13667+ "jno 0f\n"
13668+ _ASM_INC "%0\n"
13669+ "int $4\n0:\n"
13670+ _ASM_EXTABLE(0b, 0b)
13671+#endif
13672+
13673+ : "+m" (l->a.counter));
13674+}
13675+
13676+static inline void local_dec_unchecked(local_unchecked_t *l)
13677+{
13678+ asm volatile(_ASM_DEC "%0\n"
13679 : "+m" (l->a.counter));
13680 }
13681
13682 static inline void local_add(long i, local_t *l)
13683 {
13684- asm volatile(_ASM_ADD "%1,%0"
13685+ asm volatile(_ASM_ADD "%1,%0\n"
13686+
13687+#ifdef CONFIG_PAX_REFCOUNT
13688+ "jno 0f\n"
13689+ _ASM_SUB "%1,%0\n"
13690+ "int $4\n0:\n"
13691+ _ASM_EXTABLE(0b, 0b)
13692+#endif
13693+
13694+ : "+m" (l->a.counter)
13695+ : "ir" (i));
13696+}
13697+
13698+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13699+{
13700+ asm volatile(_ASM_ADD "%1,%0\n"
13701 : "+m" (l->a.counter)
13702 : "ir" (i));
13703 }
13704
13705 static inline void local_sub(long i, local_t *l)
13706 {
13707- asm volatile(_ASM_SUB "%1,%0"
13708+ asm volatile(_ASM_SUB "%1,%0\n"
13709+
13710+#ifdef CONFIG_PAX_REFCOUNT
13711+ "jno 0f\n"
13712+ _ASM_ADD "%1,%0\n"
13713+ "int $4\n0:\n"
13714+ _ASM_EXTABLE(0b, 0b)
13715+#endif
13716+
13717+ : "+m" (l->a.counter)
13718+ : "ir" (i));
13719+}
13720+
13721+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13722+{
13723+ asm volatile(_ASM_SUB "%1,%0\n"
13724 : "+m" (l->a.counter)
13725 : "ir" (i));
13726 }
13727@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13728 {
13729 unsigned char c;
13730
13731- asm volatile(_ASM_SUB "%2,%0; sete %1"
13732+ asm volatile(_ASM_SUB "%2,%0\n"
13733+
13734+#ifdef CONFIG_PAX_REFCOUNT
13735+ "jno 0f\n"
13736+ _ASM_ADD "%2,%0\n"
13737+ "int $4\n0:\n"
13738+ _ASM_EXTABLE(0b, 0b)
13739+#endif
13740+
13741+ "sete %1\n"
13742 : "+m" (l->a.counter), "=qm" (c)
13743 : "ir" (i) : "memory");
13744 return c;
13745@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13746 {
13747 unsigned char c;
13748
13749- asm volatile(_ASM_DEC "%0; sete %1"
13750+ asm volatile(_ASM_DEC "%0\n"
13751+
13752+#ifdef CONFIG_PAX_REFCOUNT
13753+ "jno 0f\n"
13754+ _ASM_INC "%0\n"
13755+ "int $4\n0:\n"
13756+ _ASM_EXTABLE(0b, 0b)
13757+#endif
13758+
13759+ "sete %1\n"
13760 : "+m" (l->a.counter), "=qm" (c)
13761 : : "memory");
13762 return c != 0;
13763@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13764 {
13765 unsigned char c;
13766
13767- asm volatile(_ASM_INC "%0; sete %1"
13768+ asm volatile(_ASM_INC "%0\n"
13769+
13770+#ifdef CONFIG_PAX_REFCOUNT
13771+ "jno 0f\n"
13772+ _ASM_DEC "%0\n"
13773+ "int $4\n0:\n"
13774+ _ASM_EXTABLE(0b, 0b)
13775+#endif
13776+
13777+ "sete %1\n"
13778 : "+m" (l->a.counter), "=qm" (c)
13779 : : "memory");
13780 return c != 0;
13781@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13782 {
13783 unsigned char c;
13784
13785- asm volatile(_ASM_ADD "%2,%0; sets %1"
13786+ asm volatile(_ASM_ADD "%2,%0\n"
13787+
13788+#ifdef CONFIG_PAX_REFCOUNT
13789+ "jno 0f\n"
13790+ _ASM_SUB "%2,%0\n"
13791+ "int $4\n0:\n"
13792+ _ASM_EXTABLE(0b, 0b)
13793+#endif
13794+
13795+ "sets %1\n"
13796 : "+m" (l->a.counter), "=qm" (c)
13797 : "ir" (i) : "memory");
13798 return c;
13799@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13800 static inline long local_add_return(long i, local_t *l)
13801 {
13802 long __i = i;
13803+ asm volatile(_ASM_XADD "%0, %1\n"
13804+
13805+#ifdef CONFIG_PAX_REFCOUNT
13806+ "jno 0f\n"
13807+ _ASM_MOV "%0,%1\n"
13808+ "int $4\n0:\n"
13809+ _ASM_EXTABLE(0b, 0b)
13810+#endif
13811+
13812+ : "+r" (i), "+m" (l->a.counter)
13813+ : : "memory");
13814+ return i + __i;
13815+}
13816+
13817+/**
13818+ * local_add_return_unchecked - add and return
13819+ * @i: integer value to add
13820+ * @l: pointer to type local_unchecked_t
13821+ *
13822+ * Atomically adds @i to @l and returns @i + @l
13823+ */
13824+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13825+{
13826+ long __i = i;
13827 asm volatile(_ASM_XADD "%0, %1;"
13828 : "+r" (i), "+m" (l->a.counter)
13829 : : "memory");
13830@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13831
13832 #define local_cmpxchg(l, o, n) \
13833 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13834+#define local_cmpxchg_unchecked(l, o, n) \
13835+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13836 /* Always has a lock prefix */
13837 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13838
13839diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13840new file mode 100644
13841index 0000000..2bfd3ba
13842--- /dev/null
13843+++ b/arch/x86/include/asm/mman.h
13844@@ -0,0 +1,15 @@
13845+#ifndef _X86_MMAN_H
13846+#define _X86_MMAN_H
13847+
13848+#include <uapi/asm/mman.h>
13849+
13850+#ifdef __KERNEL__
13851+#ifndef __ASSEMBLY__
13852+#ifdef CONFIG_X86_32
13853+#define arch_mmap_check i386_mmap_check
13854+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13855+#endif
13856+#endif
13857+#endif
13858+
13859+#endif /* X86_MMAN_H */
13860diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13861index 5f55e69..e20bfb1 100644
13862--- a/arch/x86/include/asm/mmu.h
13863+++ b/arch/x86/include/asm/mmu.h
13864@@ -9,7 +9,7 @@
13865 * we put the segment information here.
13866 */
13867 typedef struct {
13868- void *ldt;
13869+ struct desc_struct *ldt;
13870 int size;
13871
13872 #ifdef CONFIG_X86_64
13873@@ -18,7 +18,19 @@ typedef struct {
13874 #endif
13875
13876 struct mutex lock;
13877- void *vdso;
13878+ unsigned long vdso;
13879+
13880+#ifdef CONFIG_X86_32
13881+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13882+ unsigned long user_cs_base;
13883+ unsigned long user_cs_limit;
13884+
13885+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13886+ cpumask_t cpu_user_cs_mask;
13887+#endif
13888+
13889+#endif
13890+#endif
13891 } mm_context_t;
13892
13893 #ifdef CONFIG_SMP
13894diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13895index cdbf367..adb37ac 100644
13896--- a/arch/x86/include/asm/mmu_context.h
13897+++ b/arch/x86/include/asm/mmu_context.h
13898@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13899
13900 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13901 {
13902+
13903+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13904+ unsigned int i;
13905+ pgd_t *pgd;
13906+
13907+ pax_open_kernel();
13908+ pgd = get_cpu_pgd(smp_processor_id());
13909+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13910+ set_pgd_batched(pgd+i, native_make_pgd(0));
13911+ pax_close_kernel();
13912+#endif
13913+
13914 #ifdef CONFIG_SMP
13915 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13916 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13917@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13918 struct task_struct *tsk)
13919 {
13920 unsigned cpu = smp_processor_id();
13921+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13922+ int tlbstate = TLBSTATE_OK;
13923+#endif
13924
13925 if (likely(prev != next)) {
13926 #ifdef CONFIG_SMP
13927+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13928+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13929+#endif
13930 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13931 this_cpu_write(cpu_tlbstate.active_mm, next);
13932 #endif
13933 cpumask_set_cpu(cpu, mm_cpumask(next));
13934
13935 /* Re-load page tables */
13936+#ifdef CONFIG_PAX_PER_CPU_PGD
13937+ pax_open_kernel();
13938+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13939+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13940+ pax_close_kernel();
13941+ load_cr3(get_cpu_pgd(cpu));
13942+#else
13943 load_cr3(next->pgd);
13944+#endif
13945
13946 /* stop flush ipis for the previous mm */
13947 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13948@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13949 */
13950 if (unlikely(prev->context.ldt != next->context.ldt))
13951 load_LDT_nolock(&next->context);
13952- }
13953+
13954+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13955+ if (!(__supported_pte_mask & _PAGE_NX)) {
13956+ smp_mb__before_clear_bit();
13957+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13958+ smp_mb__after_clear_bit();
13959+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13960+ }
13961+#endif
13962+
13963+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13964+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13965+ prev->context.user_cs_limit != next->context.user_cs_limit))
13966+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13967 #ifdef CONFIG_SMP
13968+ else if (unlikely(tlbstate != TLBSTATE_OK))
13969+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13970+#endif
13971+#endif
13972+
13973+ }
13974 else {
13975+
13976+#ifdef CONFIG_PAX_PER_CPU_PGD
13977+ pax_open_kernel();
13978+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13979+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13980+ pax_close_kernel();
13981+ load_cr3(get_cpu_pgd(cpu));
13982+#endif
13983+
13984+#ifdef CONFIG_SMP
13985 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13986 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13987
13988@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13989 * tlb flush IPI delivery. We must reload CR3
13990 * to make sure to use no freed page tables.
13991 */
13992+
13993+#ifndef CONFIG_PAX_PER_CPU_PGD
13994 load_cr3(next->pgd);
13995+#endif
13996+
13997 load_LDT_nolock(&next->context);
13998+
13999+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14000+ if (!(__supported_pte_mask & _PAGE_NX))
14001+ cpu_set(cpu, next->context.cpu_user_cs_mask);
14002+#endif
14003+
14004+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14005+#ifdef CONFIG_PAX_PAGEEXEC
14006+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
14007+#endif
14008+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14009+#endif
14010+
14011 }
14012+#endif
14013 }
14014-#endif
14015 }
14016
14017 #define activate_mm(prev, next) \
14018diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
14019index e3b7819..b257c64 100644
14020--- a/arch/x86/include/asm/module.h
14021+++ b/arch/x86/include/asm/module.h
14022@@ -5,6 +5,7 @@
14023
14024 #ifdef CONFIG_X86_64
14025 /* X86_64 does not define MODULE_PROC_FAMILY */
14026+#define MODULE_PROC_FAMILY ""
14027 #elif defined CONFIG_M486
14028 #define MODULE_PROC_FAMILY "486 "
14029 #elif defined CONFIG_M586
14030@@ -57,8 +58,20 @@
14031 #error unknown processor family
14032 #endif
14033
14034-#ifdef CONFIG_X86_32
14035-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
14036+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14037+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
14038+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
14039+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
14040+#else
14041+#define MODULE_PAX_KERNEXEC ""
14042 #endif
14043
14044+#ifdef CONFIG_PAX_MEMORY_UDEREF
14045+#define MODULE_PAX_UDEREF "UDEREF "
14046+#else
14047+#define MODULE_PAX_UDEREF ""
14048+#endif
14049+
14050+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
14051+
14052 #endif /* _ASM_X86_MODULE_H */
14053diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
14054index 86f9301..b365cda 100644
14055--- a/arch/x86/include/asm/nmi.h
14056+++ b/arch/x86/include/asm/nmi.h
14057@@ -40,11 +40,11 @@ struct nmiaction {
14058 nmi_handler_t handler;
14059 unsigned long flags;
14060 const char *name;
14061-};
14062+} __do_const;
14063
14064 #define register_nmi_handler(t, fn, fg, n, init...) \
14065 ({ \
14066- static struct nmiaction init fn##_na = { \
14067+ static const struct nmiaction init fn##_na = { \
14068 .handler = (fn), \
14069 .name = (n), \
14070 .flags = (fg), \
14071@@ -52,7 +52,7 @@ struct nmiaction {
14072 __register_nmi_handler((t), &fn##_na); \
14073 })
14074
14075-int __register_nmi_handler(unsigned int, struct nmiaction *);
14076+int __register_nmi_handler(unsigned int, const struct nmiaction *);
14077
14078 void unregister_nmi_handler(unsigned int, const char *);
14079
14080diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
14081index c878924..21f4889 100644
14082--- a/arch/x86/include/asm/page.h
14083+++ b/arch/x86/include/asm/page.h
14084@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
14085 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
14086
14087 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
14088+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
14089
14090 #define __boot_va(x) __va(x)
14091 #define __boot_pa(x) __pa(x)
14092diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
14093index 0f1ddee..e2fc3d1 100644
14094--- a/arch/x86/include/asm/page_64.h
14095+++ b/arch/x86/include/asm/page_64.h
14096@@ -7,9 +7,9 @@
14097
14098 /* duplicated to the one in bootmem.h */
14099 extern unsigned long max_pfn;
14100-extern unsigned long phys_base;
14101+extern const unsigned long phys_base;
14102
14103-static inline unsigned long __phys_addr_nodebug(unsigned long x)
14104+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
14105 {
14106 unsigned long y = x - __START_KERNEL_map;
14107
14108diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
14109index cfdc9ee..3f7b5d6 100644
14110--- a/arch/x86/include/asm/paravirt.h
14111+++ b/arch/x86/include/asm/paravirt.h
14112@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
14113 return (pmd_t) { ret };
14114 }
14115
14116-static inline pmdval_t pmd_val(pmd_t pmd)
14117+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14118 {
14119 pmdval_t ret;
14120
14121@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14122 val);
14123 }
14124
14125+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14126+{
14127+ pgdval_t val = native_pgd_val(pgd);
14128+
14129+ if (sizeof(pgdval_t) > sizeof(long))
14130+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14131+ val, (u64)val >> 32);
14132+ else
14133+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14134+ val);
14135+}
14136+
14137 static inline void pgd_clear(pgd_t *pgdp)
14138 {
14139 set_pgd(pgdp, __pgd(0));
14140@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14141 pv_mmu_ops.set_fixmap(idx, phys, flags);
14142 }
14143
14144+#ifdef CONFIG_PAX_KERNEXEC
14145+static inline unsigned long pax_open_kernel(void)
14146+{
14147+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14148+}
14149+
14150+static inline unsigned long pax_close_kernel(void)
14151+{
14152+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14153+}
14154+#else
14155+static inline unsigned long pax_open_kernel(void) { return 0; }
14156+static inline unsigned long pax_close_kernel(void) { return 0; }
14157+#endif
14158+
14159 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14160
14161 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14162@@ -926,7 +953,7 @@ extern void default_banner(void);
14163
14164 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14165 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14166-#define PARA_INDIRECT(addr) *%cs:addr
14167+#define PARA_INDIRECT(addr) *%ss:addr
14168 #endif
14169
14170 #define INTERRUPT_RETURN \
14171@@ -1001,6 +1028,21 @@ extern void default_banner(void);
14172 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14173 CLBR_NONE, \
14174 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14175+
14176+#define GET_CR0_INTO_RDI \
14177+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14178+ mov %rax,%rdi
14179+
14180+#define SET_RDI_INTO_CR0 \
14181+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14182+
14183+#define GET_CR3_INTO_RDI \
14184+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14185+ mov %rax,%rdi
14186+
14187+#define SET_RDI_INTO_CR3 \
14188+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14189+
14190 #endif /* CONFIG_X86_32 */
14191
14192 #endif /* __ASSEMBLY__ */
14193diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14194index 0db1fca..52310cc 100644
14195--- a/arch/x86/include/asm/paravirt_types.h
14196+++ b/arch/x86/include/asm/paravirt_types.h
14197@@ -84,7 +84,7 @@ struct pv_init_ops {
14198 */
14199 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14200 unsigned long addr, unsigned len);
14201-};
14202+} __no_const;
14203
14204
14205 struct pv_lazy_ops {
14206@@ -98,7 +98,7 @@ struct pv_time_ops {
14207 unsigned long long (*sched_clock)(void);
14208 unsigned long long (*steal_clock)(int cpu);
14209 unsigned long (*get_tsc_khz)(void);
14210-};
14211+} __no_const;
14212
14213 struct pv_cpu_ops {
14214 /* hooks for various privileged instructions */
14215@@ -192,7 +192,7 @@ struct pv_cpu_ops {
14216
14217 void (*start_context_switch)(struct task_struct *prev);
14218 void (*end_context_switch)(struct task_struct *next);
14219-};
14220+} __no_const;
14221
14222 struct pv_irq_ops {
14223 /*
14224@@ -223,7 +223,7 @@ struct pv_apic_ops {
14225 unsigned long start_eip,
14226 unsigned long start_esp);
14227 #endif
14228-};
14229+} __no_const;
14230
14231 struct pv_mmu_ops {
14232 unsigned long (*read_cr2)(void);
14233@@ -313,6 +313,7 @@ struct pv_mmu_ops {
14234 struct paravirt_callee_save make_pud;
14235
14236 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14237+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14238 #endif /* PAGETABLE_LEVELS == 4 */
14239 #endif /* PAGETABLE_LEVELS >= 3 */
14240
14241@@ -324,6 +325,12 @@ struct pv_mmu_ops {
14242 an mfn. We can tell which is which from the index. */
14243 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14244 phys_addr_t phys, pgprot_t flags);
14245+
14246+#ifdef CONFIG_PAX_KERNEXEC
14247+ unsigned long (*pax_open_kernel)(void);
14248+ unsigned long (*pax_close_kernel)(void);
14249+#endif
14250+
14251 };
14252
14253 struct arch_spinlock;
14254@@ -334,7 +341,7 @@ struct pv_lock_ops {
14255 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14256 int (*spin_trylock)(struct arch_spinlock *lock);
14257 void (*spin_unlock)(struct arch_spinlock *lock);
14258-};
14259+} __no_const;
14260
14261 /* This contains all the paravirt structures: we get a convenient
14262 * number for each function using the offset which we use to indicate
14263diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14264index b4389a4..7024269 100644
14265--- a/arch/x86/include/asm/pgalloc.h
14266+++ b/arch/x86/include/asm/pgalloc.h
14267@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14268 pmd_t *pmd, pte_t *pte)
14269 {
14270 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14271+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14272+}
14273+
14274+static inline void pmd_populate_user(struct mm_struct *mm,
14275+ pmd_t *pmd, pte_t *pte)
14276+{
14277+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14278 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14279 }
14280
14281@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14282
14283 #ifdef CONFIG_X86_PAE
14284 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14285+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14286+{
14287+ pud_populate(mm, pudp, pmd);
14288+}
14289 #else /* !CONFIG_X86_PAE */
14290 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14291 {
14292 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14293 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14294 }
14295+
14296+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14297+{
14298+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14299+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14300+}
14301 #endif /* CONFIG_X86_PAE */
14302
14303 #if PAGETABLE_LEVELS > 3
14304@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14305 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14306 }
14307
14308+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14309+{
14310+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14311+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14312+}
14313+
14314 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14315 {
14316 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14317diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14318index f2b489c..4f7e2e5 100644
14319--- a/arch/x86/include/asm/pgtable-2level.h
14320+++ b/arch/x86/include/asm/pgtable-2level.h
14321@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14322
14323 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14324 {
14325+ pax_open_kernel();
14326 *pmdp = pmd;
14327+ pax_close_kernel();
14328 }
14329
14330 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14331diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14332index 4cc9f2b..5fd9226 100644
14333--- a/arch/x86/include/asm/pgtable-3level.h
14334+++ b/arch/x86/include/asm/pgtable-3level.h
14335@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14336
14337 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14338 {
14339+ pax_open_kernel();
14340 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14341+ pax_close_kernel();
14342 }
14343
14344 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14345 {
14346+ pax_open_kernel();
14347 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14348+ pax_close_kernel();
14349 }
14350
14351 /*
14352diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14353index 1e67223..dd6e7ea 100644
14354--- a/arch/x86/include/asm/pgtable.h
14355+++ b/arch/x86/include/asm/pgtable.h
14356@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14357
14358 #ifndef __PAGETABLE_PUD_FOLDED
14359 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14360+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14361 #define pgd_clear(pgd) native_pgd_clear(pgd)
14362 #endif
14363
14364@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14365
14366 #define arch_end_context_switch(prev) do {} while(0)
14367
14368+#define pax_open_kernel() native_pax_open_kernel()
14369+#define pax_close_kernel() native_pax_close_kernel()
14370 #endif /* CONFIG_PARAVIRT */
14371
14372+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14373+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14374+
14375+#ifdef CONFIG_PAX_KERNEXEC
14376+static inline unsigned long native_pax_open_kernel(void)
14377+{
14378+ unsigned long cr0;
14379+
14380+ preempt_disable();
14381+ barrier();
14382+ cr0 = read_cr0() ^ X86_CR0_WP;
14383+ BUG_ON(cr0 & X86_CR0_WP);
14384+ write_cr0(cr0);
14385+ return cr0 ^ X86_CR0_WP;
14386+}
14387+
14388+static inline unsigned long native_pax_close_kernel(void)
14389+{
14390+ unsigned long cr0;
14391+
14392+ cr0 = read_cr0() ^ X86_CR0_WP;
14393+ BUG_ON(!(cr0 & X86_CR0_WP));
14394+ write_cr0(cr0);
14395+ barrier();
14396+ preempt_enable_no_resched();
14397+ return cr0 ^ X86_CR0_WP;
14398+}
14399+#else
14400+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14401+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14402+#endif
14403+
14404 /*
14405 * The following only work if pte_present() is true.
14406 * Undefined behaviour if not..
14407 */
14408+static inline int pte_user(pte_t pte)
14409+{
14410+ return pte_val(pte) & _PAGE_USER;
14411+}
14412+
14413 static inline int pte_dirty(pte_t pte)
14414 {
14415 return pte_flags(pte) & _PAGE_DIRTY;
14416@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
14417 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
14418 }
14419
14420+static inline unsigned long pgd_pfn(pgd_t pgd)
14421+{
14422+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
14423+}
14424+
14425 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
14426
14427 static inline int pmd_large(pmd_t pte)
14428@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14429 return pte_clear_flags(pte, _PAGE_RW);
14430 }
14431
14432+static inline pte_t pte_mkread(pte_t pte)
14433+{
14434+ return __pte(pte_val(pte) | _PAGE_USER);
14435+}
14436+
14437 static inline pte_t pte_mkexec(pte_t pte)
14438 {
14439- return pte_clear_flags(pte, _PAGE_NX);
14440+#ifdef CONFIG_X86_PAE
14441+ if (__supported_pte_mask & _PAGE_NX)
14442+ return pte_clear_flags(pte, _PAGE_NX);
14443+ else
14444+#endif
14445+ return pte_set_flags(pte, _PAGE_USER);
14446+}
14447+
14448+static inline pte_t pte_exprotect(pte_t pte)
14449+{
14450+#ifdef CONFIG_X86_PAE
14451+ if (__supported_pte_mask & _PAGE_NX)
14452+ return pte_set_flags(pte, _PAGE_NX);
14453+ else
14454+#endif
14455+ return pte_clear_flags(pte, _PAGE_USER);
14456 }
14457
14458 static inline pte_t pte_mkdirty(pte_t pte)
14459@@ -394,6 +459,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14460 #endif
14461
14462 #ifndef __ASSEMBLY__
14463+
14464+#ifdef CONFIG_PAX_PER_CPU_PGD
14465+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14466+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14467+{
14468+ return cpu_pgd[cpu];
14469+}
14470+#endif
14471+
14472 #include <linux/mm_types.h>
14473 #include <linux/log2.h>
14474
14475@@ -529,7 +603,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
14476 * Currently stuck as a macro due to indirect forward reference to
14477 * linux/mmzone.h's __section_mem_map_addr() definition:
14478 */
14479-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
14480+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
14481
14482 /* Find an entry in the second-level page table.. */
14483 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
14484@@ -569,7 +643,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
14485 * Currently stuck as a macro due to indirect forward reference to
14486 * linux/mmzone.h's __section_mem_map_addr() definition:
14487 */
14488-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
14489+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
14490
14491 /* to find an entry in a page-table-directory. */
14492 static inline unsigned long pud_index(unsigned long address)
14493@@ -584,7 +658,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14494
14495 static inline int pgd_bad(pgd_t pgd)
14496 {
14497- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14498+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14499 }
14500
14501 static inline int pgd_none(pgd_t pgd)
14502@@ -607,7 +681,12 @@ static inline int pgd_none(pgd_t pgd)
14503 * pgd_offset() returns a (pgd_t *)
14504 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14505 */
14506-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14507+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14508+
14509+#ifdef CONFIG_PAX_PER_CPU_PGD
14510+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14511+#endif
14512+
14513 /*
14514 * a shortcut which implies the use of the kernel's pgd, instead
14515 * of a process's
14516@@ -618,6 +697,22 @@ static inline int pgd_none(pgd_t pgd)
14517 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14518 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14519
14520+#ifdef CONFIG_X86_32
14521+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14522+#else
14523+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14524+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14525+
14526+#ifdef CONFIG_PAX_MEMORY_UDEREF
14527+#ifdef __ASSEMBLY__
14528+#define pax_user_shadow_base pax_user_shadow_base(%rip)
14529+#else
14530+extern unsigned long pax_user_shadow_base;
14531+#endif
14532+#endif
14533+
14534+#endif
14535+
14536 #ifndef __ASSEMBLY__
14537
14538 extern int direct_gbpages;
14539@@ -784,11 +879,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14540 * dst and src can be on the same page, but the range must not overlap,
14541 * and must not cross a page boundary.
14542 */
14543-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14544+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14545 {
14546- memcpy(dst, src, count * sizeof(pgd_t));
14547+ pax_open_kernel();
14548+ while (count--)
14549+ *dst++ = *src++;
14550+ pax_close_kernel();
14551 }
14552
14553+#ifdef CONFIG_PAX_PER_CPU_PGD
14554+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14555+#endif
14556+
14557+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14558+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14559+#else
14560+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14561+#endif
14562+
14563 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
14564 static inline int page_level_shift(enum pg_level level)
14565 {
14566diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14567index 9ee3221..b979c6b 100644
14568--- a/arch/x86/include/asm/pgtable_32.h
14569+++ b/arch/x86/include/asm/pgtable_32.h
14570@@ -25,9 +25,6 @@
14571 struct mm_struct;
14572 struct vm_area_struct;
14573
14574-extern pgd_t swapper_pg_dir[1024];
14575-extern pgd_t initial_page_table[1024];
14576-
14577 static inline void pgtable_cache_init(void) { }
14578 static inline void check_pgt_cache(void) { }
14579 void paging_init(void);
14580@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14581 # include <asm/pgtable-2level.h>
14582 #endif
14583
14584+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14585+extern pgd_t initial_page_table[PTRS_PER_PGD];
14586+#ifdef CONFIG_X86_PAE
14587+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14588+#endif
14589+
14590 #if defined(CONFIG_HIGHPTE)
14591 #define pte_offset_map(dir, address) \
14592 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14593@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14594 /* Clear a kernel PTE and flush it from the TLB */
14595 #define kpte_clear_flush(ptep, vaddr) \
14596 do { \
14597+ pax_open_kernel(); \
14598 pte_clear(&init_mm, (vaddr), (ptep)); \
14599+ pax_close_kernel(); \
14600 __flush_tlb_one((vaddr)); \
14601 } while (0)
14602
14603 #endif /* !__ASSEMBLY__ */
14604
14605+#define HAVE_ARCH_UNMAPPED_AREA
14606+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14607+
14608 /*
14609 * kern_addr_valid() is (1) for FLATMEM and (0) for
14610 * SPARSEMEM and DISCONTIGMEM
14611diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14612index ed5903b..c7fe163 100644
14613--- a/arch/x86/include/asm/pgtable_32_types.h
14614+++ b/arch/x86/include/asm/pgtable_32_types.h
14615@@ -8,7 +8,7 @@
14616 */
14617 #ifdef CONFIG_X86_PAE
14618 # include <asm/pgtable-3level_types.h>
14619-# define PMD_SIZE (1UL << PMD_SHIFT)
14620+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14621 # define PMD_MASK (~(PMD_SIZE - 1))
14622 #else
14623 # include <asm/pgtable-2level_types.h>
14624@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14625 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14626 #endif
14627
14628+#ifdef CONFIG_PAX_KERNEXEC
14629+#ifndef __ASSEMBLY__
14630+extern unsigned char MODULES_EXEC_VADDR[];
14631+extern unsigned char MODULES_EXEC_END[];
14632+#endif
14633+#include <asm/boot.h>
14634+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14635+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14636+#else
14637+#define ktla_ktva(addr) (addr)
14638+#define ktva_ktla(addr) (addr)
14639+#endif
14640+
14641 #define MODULES_VADDR VMALLOC_START
14642 #define MODULES_END VMALLOC_END
14643 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14644diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14645index e22c1db..23a625a 100644
14646--- a/arch/x86/include/asm/pgtable_64.h
14647+++ b/arch/x86/include/asm/pgtable_64.h
14648@@ -16,10 +16,14 @@
14649
14650 extern pud_t level3_kernel_pgt[512];
14651 extern pud_t level3_ident_pgt[512];
14652+extern pud_t level3_vmalloc_start_pgt[512];
14653+extern pud_t level3_vmalloc_end_pgt[512];
14654+extern pud_t level3_vmemmap_pgt[512];
14655+extern pud_t level2_vmemmap_pgt[512];
14656 extern pmd_t level2_kernel_pgt[512];
14657 extern pmd_t level2_fixmap_pgt[512];
14658-extern pmd_t level2_ident_pgt[512];
14659-extern pgd_t init_level4_pgt[];
14660+extern pmd_t level2_ident_pgt[512*2];
14661+extern pgd_t init_level4_pgt[512];
14662
14663 #define swapper_pg_dir init_level4_pgt
14664
14665@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14666
14667 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14668 {
14669+ pax_open_kernel();
14670 *pmdp = pmd;
14671+ pax_close_kernel();
14672 }
14673
14674 static inline void native_pmd_clear(pmd_t *pmd)
14675@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14676
14677 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14678 {
14679+ pax_open_kernel();
14680 *pudp = pud;
14681+ pax_close_kernel();
14682 }
14683
14684 static inline void native_pud_clear(pud_t *pud)
14685@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14686
14687 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14688 {
14689+ pax_open_kernel();
14690+ *pgdp = pgd;
14691+ pax_close_kernel();
14692+}
14693+
14694+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14695+{
14696 *pgdp = pgd;
14697 }
14698
14699diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14700index 2d88344..4679fc3 100644
14701--- a/arch/x86/include/asm/pgtable_64_types.h
14702+++ b/arch/x86/include/asm/pgtable_64_types.h
14703@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
14704 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14705 #define MODULES_END _AC(0xffffffffff000000, UL)
14706 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14707+#define MODULES_EXEC_VADDR MODULES_VADDR
14708+#define MODULES_EXEC_END MODULES_END
14709+
14710+#define ktla_ktva(addr) (addr)
14711+#define ktva_ktla(addr) (addr)
14712
14713 #define EARLY_DYNAMIC_PAGE_TABLES 64
14714
14715diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14716index e642300..0ef8f31 100644
14717--- a/arch/x86/include/asm/pgtable_types.h
14718+++ b/arch/x86/include/asm/pgtable_types.h
14719@@ -16,13 +16,12 @@
14720 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14721 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14722 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14723-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14724+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14725 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14726 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14727 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14728-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14729-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14730-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14731+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14732+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14733 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14734
14735 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14736@@ -40,7 +39,6 @@
14737 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14738 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14739 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14740-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14741 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14742 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14743 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14744@@ -57,8 +55,10 @@
14745
14746 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14747 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14748-#else
14749+#elif defined(CONFIG_KMEMCHECK)
14750 #define _PAGE_NX (_AT(pteval_t, 0))
14751+#else
14752+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14753 #endif
14754
14755 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14756@@ -116,6 +116,9 @@
14757 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14758 _PAGE_ACCESSED)
14759
14760+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14761+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14762+
14763 #define __PAGE_KERNEL_EXEC \
14764 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14765 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14766@@ -126,7 +129,7 @@
14767 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14768 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14769 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14770-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14771+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14772 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14773 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14774 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14775@@ -188,8 +191,8 @@
14776 * bits are combined, this will alow user to access the high address mapped
14777 * VDSO in the presence of CONFIG_COMPAT_VDSO
14778 */
14779-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14780-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14781+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14782+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14783 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14784 #endif
14785
14786@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14787 {
14788 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14789 }
14790+#endif
14791
14792+#if PAGETABLE_LEVELS == 3
14793+#include <asm-generic/pgtable-nopud.h>
14794+#endif
14795+
14796+#if PAGETABLE_LEVELS == 2
14797+#include <asm-generic/pgtable-nopmd.h>
14798+#endif
14799+
14800+#ifndef __ASSEMBLY__
14801 #if PAGETABLE_LEVELS > 3
14802 typedef struct { pudval_t pud; } pud_t;
14803
14804@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14805 return pud.pud;
14806 }
14807 #else
14808-#include <asm-generic/pgtable-nopud.h>
14809-
14810 static inline pudval_t native_pud_val(pud_t pud)
14811 {
14812 return native_pgd_val(pud.pgd);
14813@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14814 return pmd.pmd;
14815 }
14816 #else
14817-#include <asm-generic/pgtable-nopmd.h>
14818-
14819 static inline pmdval_t native_pmd_val(pmd_t pmd)
14820 {
14821 return native_pgd_val(pmd.pud.pgd);
14822@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14823
14824 extern pteval_t __supported_pte_mask;
14825 extern void set_nx(void);
14826-extern int nx_enabled;
14827
14828 #define pgprot_writecombine pgprot_writecombine
14829 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14830diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14831index 22224b3..4080dab 100644
14832--- a/arch/x86/include/asm/processor.h
14833+++ b/arch/x86/include/asm/processor.h
14834@@ -282,7 +282,7 @@ struct tss_struct {
14835
14836 } ____cacheline_aligned;
14837
14838-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14839+extern struct tss_struct init_tss[NR_CPUS];
14840
14841 /*
14842 * Save the original ist values for checking stack pointers during debugging
14843@@ -823,11 +823,18 @@ static inline void spin_lock_prefetch(const void *x)
14844 */
14845 #define TASK_SIZE PAGE_OFFSET
14846 #define TASK_SIZE_MAX TASK_SIZE
14847+
14848+#ifdef CONFIG_PAX_SEGMEXEC
14849+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14850+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14851+#else
14852 #define STACK_TOP TASK_SIZE
14853-#define STACK_TOP_MAX STACK_TOP
14854+#endif
14855+
14856+#define STACK_TOP_MAX TASK_SIZE
14857
14858 #define INIT_THREAD { \
14859- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14860+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14861 .vm86_info = NULL, \
14862 .sysenter_cs = __KERNEL_CS, \
14863 .io_bitmap_ptr = NULL, \
14864@@ -841,7 +848,7 @@ static inline void spin_lock_prefetch(const void *x)
14865 */
14866 #define INIT_TSS { \
14867 .x86_tss = { \
14868- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14869+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14870 .ss0 = __KERNEL_DS, \
14871 .ss1 = __KERNEL_CS, \
14872 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14873@@ -852,11 +859,7 @@ static inline void spin_lock_prefetch(const void *x)
14874 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14875
14876 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14877-#define KSTK_TOP(info) \
14878-({ \
14879- unsigned long *__ptr = (unsigned long *)(info); \
14880- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14881-})
14882+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14883
14884 /*
14885 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14886@@ -871,7 +874,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14887 #define task_pt_regs(task) \
14888 ({ \
14889 struct pt_regs *__regs__; \
14890- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14891+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14892 __regs__ - 1; \
14893 })
14894
14895@@ -881,13 +884,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14896 /*
14897 * User space process size. 47bits minus one guard page.
14898 */
14899-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14900+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14901
14902 /* This decides where the kernel will search for a free chunk of vm
14903 * space during mmap's.
14904 */
14905 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14906- 0xc0000000 : 0xFFFFe000)
14907+ 0xc0000000 : 0xFFFFf000)
14908
14909 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14910 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14911@@ -898,11 +901,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14912 #define STACK_TOP_MAX TASK_SIZE_MAX
14913
14914 #define INIT_THREAD { \
14915- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14916+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14917 }
14918
14919 #define INIT_TSS { \
14920- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14921+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14922 }
14923
14924 /*
14925@@ -930,6 +933,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14926 */
14927 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14928
14929+#ifdef CONFIG_PAX_SEGMEXEC
14930+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14931+#endif
14932+
14933 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14934
14935 /* Get/set a process' ability to use the timestamp counter instruction */
14936@@ -970,7 +977,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
14937 return ratio;
14938 }
14939
14940-extern unsigned long arch_align_stack(unsigned long sp);
14941+#define arch_align_stack(x) ((x) & ~0xfUL)
14942 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14943
14944 void default_idle(void);
14945@@ -980,6 +987,6 @@ bool xen_set_default_idle(void);
14946 #define xen_set_default_idle 0
14947 #endif
14948
14949-void stop_this_cpu(void *dummy);
14950+void stop_this_cpu(void *dummy) __noreturn;
14951
14952 #endif /* _ASM_X86_PROCESSOR_H */
14953diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14954index 942a086..6c26446 100644
14955--- a/arch/x86/include/asm/ptrace.h
14956+++ b/arch/x86/include/asm/ptrace.h
14957@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14958 }
14959
14960 /*
14961- * user_mode_vm(regs) determines whether a register set came from user mode.
14962+ * user_mode(regs) determines whether a register set came from user mode.
14963 * This is true if V8086 mode was enabled OR if the register set was from
14964 * protected mode with RPL-3 CS value. This tricky test checks that with
14965 * one comparison. Many places in the kernel can bypass this full check
14966- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14967+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14968+ * be used.
14969 */
14970-static inline int user_mode(struct pt_regs *regs)
14971+static inline int user_mode_novm(struct pt_regs *regs)
14972 {
14973 #ifdef CONFIG_X86_32
14974 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14975 #else
14976- return !!(regs->cs & 3);
14977+ return !!(regs->cs & SEGMENT_RPL_MASK);
14978 #endif
14979 }
14980
14981-static inline int user_mode_vm(struct pt_regs *regs)
14982+static inline int user_mode(struct pt_regs *regs)
14983 {
14984 #ifdef CONFIG_X86_32
14985 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14986 USER_RPL;
14987 #else
14988- return user_mode(regs);
14989+ return user_mode_novm(regs);
14990 #endif
14991 }
14992
14993@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14994 #ifdef CONFIG_X86_64
14995 static inline bool user_64bit_mode(struct pt_regs *regs)
14996 {
14997+ unsigned long cs = regs->cs & 0xffff;
14998 #ifndef CONFIG_PARAVIRT
14999 /*
15000 * On non-paravirt systems, this is the only long mode CPL 3
15001 * selector. We do not allow long mode selectors in the LDT.
15002 */
15003- return regs->cs == __USER_CS;
15004+ return cs == __USER_CS;
15005 #else
15006 /* Headers are too twisted for this to go in paravirt.h. */
15007- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
15008+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
15009 #endif
15010 }
15011
15012@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
15013 * Traps from the kernel do not save sp and ss.
15014 * Use the helper function to retrieve sp.
15015 */
15016- if (offset == offsetof(struct pt_regs, sp) &&
15017- regs->cs == __KERNEL_CS)
15018- return kernel_stack_pointer(regs);
15019+ if (offset == offsetof(struct pt_regs, sp)) {
15020+ unsigned long cs = regs->cs & 0xffff;
15021+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
15022+ return kernel_stack_pointer(regs);
15023+ }
15024 #endif
15025 return *(unsigned long *)((unsigned long)regs + offset);
15026 }
15027diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
15028index 9c6b890..5305f53 100644
15029--- a/arch/x86/include/asm/realmode.h
15030+++ b/arch/x86/include/asm/realmode.h
15031@@ -22,16 +22,14 @@ struct real_mode_header {
15032 #endif
15033 /* APM/BIOS reboot */
15034 u32 machine_real_restart_asm;
15035-#ifdef CONFIG_X86_64
15036 u32 machine_real_restart_seg;
15037-#endif
15038 };
15039
15040 /* This must match data at trampoline_32/64.S */
15041 struct trampoline_header {
15042 #ifdef CONFIG_X86_32
15043 u32 start;
15044- u16 gdt_pad;
15045+ u16 boot_cs;
15046 u16 gdt_limit;
15047 u32 gdt_base;
15048 #else
15049diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
15050index a82c4f1..ac45053 100644
15051--- a/arch/x86/include/asm/reboot.h
15052+++ b/arch/x86/include/asm/reboot.h
15053@@ -6,13 +6,13 @@
15054 struct pt_regs;
15055
15056 struct machine_ops {
15057- void (*restart)(char *cmd);
15058- void (*halt)(void);
15059- void (*power_off)(void);
15060+ void (* __noreturn restart)(char *cmd);
15061+ void (* __noreturn halt)(void);
15062+ void (* __noreturn power_off)(void);
15063 void (*shutdown)(void);
15064 void (*crash_shutdown)(struct pt_regs *);
15065- void (*emergency_restart)(void);
15066-};
15067+ void (* __noreturn emergency_restart)(void);
15068+} __no_const;
15069
15070 extern struct machine_ops machine_ops;
15071
15072diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
15073index cad82c9..2e5c5c1 100644
15074--- a/arch/x86/include/asm/rwsem.h
15075+++ b/arch/x86/include/asm/rwsem.h
15076@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
15077 {
15078 asm volatile("# beginning down_read\n\t"
15079 LOCK_PREFIX _ASM_INC "(%1)\n\t"
15080+
15081+#ifdef CONFIG_PAX_REFCOUNT
15082+ "jno 0f\n"
15083+ LOCK_PREFIX _ASM_DEC "(%1)\n"
15084+ "int $4\n0:\n"
15085+ _ASM_EXTABLE(0b, 0b)
15086+#endif
15087+
15088 /* adds 0x00000001 */
15089 " jns 1f\n"
15090 " call call_rwsem_down_read_failed\n"
15091@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
15092 "1:\n\t"
15093 " mov %1,%2\n\t"
15094 " add %3,%2\n\t"
15095+
15096+#ifdef CONFIG_PAX_REFCOUNT
15097+ "jno 0f\n"
15098+ "sub %3,%2\n"
15099+ "int $4\n0:\n"
15100+ _ASM_EXTABLE(0b, 0b)
15101+#endif
15102+
15103 " jle 2f\n\t"
15104 LOCK_PREFIX " cmpxchg %2,%0\n\t"
15105 " jnz 1b\n\t"
15106@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
15107 long tmp;
15108 asm volatile("# beginning down_write\n\t"
15109 LOCK_PREFIX " xadd %1,(%2)\n\t"
15110+
15111+#ifdef CONFIG_PAX_REFCOUNT
15112+ "jno 0f\n"
15113+ "mov %1,(%2)\n"
15114+ "int $4\n0:\n"
15115+ _ASM_EXTABLE(0b, 0b)
15116+#endif
15117+
15118 /* adds 0xffff0001, returns the old value */
15119 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
15120 /* was the active mask 0 before? */
15121@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
15122 long tmp;
15123 asm volatile("# beginning __up_read\n\t"
15124 LOCK_PREFIX " xadd %1,(%2)\n\t"
15125+
15126+#ifdef CONFIG_PAX_REFCOUNT
15127+ "jno 0f\n"
15128+ "mov %1,(%2)\n"
15129+ "int $4\n0:\n"
15130+ _ASM_EXTABLE(0b, 0b)
15131+#endif
15132+
15133 /* subtracts 1, returns the old value */
15134 " jns 1f\n\t"
15135 " call call_rwsem_wake\n" /* expects old value in %edx */
15136@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
15137 long tmp;
15138 asm volatile("# beginning __up_write\n\t"
15139 LOCK_PREFIX " xadd %1,(%2)\n\t"
15140+
15141+#ifdef CONFIG_PAX_REFCOUNT
15142+ "jno 0f\n"
15143+ "mov %1,(%2)\n"
15144+ "int $4\n0:\n"
15145+ _ASM_EXTABLE(0b, 0b)
15146+#endif
15147+
15148 /* subtracts 0xffff0001, returns the old value */
15149 " jns 1f\n\t"
15150 " call call_rwsem_wake\n" /* expects old value in %edx */
15151@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15152 {
15153 asm volatile("# beginning __downgrade_write\n\t"
15154 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15155+
15156+#ifdef CONFIG_PAX_REFCOUNT
15157+ "jno 0f\n"
15158+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15159+ "int $4\n0:\n"
15160+ _ASM_EXTABLE(0b, 0b)
15161+#endif
15162+
15163 /*
15164 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15165 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15166@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15167 */
15168 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15169 {
15170- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15171+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15172+
15173+#ifdef CONFIG_PAX_REFCOUNT
15174+ "jno 0f\n"
15175+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15176+ "int $4\n0:\n"
15177+ _ASM_EXTABLE(0b, 0b)
15178+#endif
15179+
15180 : "+m" (sem->count)
15181 : "er" (delta));
15182 }
15183@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15184 */
15185 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15186 {
15187- return delta + xadd(&sem->count, delta);
15188+ return delta + xadd_check_overflow(&sem->count, delta);
15189 }
15190
15191 #endif /* __KERNEL__ */
15192diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15193index c48a950..c6d7468 100644
15194--- a/arch/x86/include/asm/segment.h
15195+++ b/arch/x86/include/asm/segment.h
15196@@ -64,10 +64,15 @@
15197 * 26 - ESPFIX small SS
15198 * 27 - per-cpu [ offset to per-cpu data area ]
15199 * 28 - stack_canary-20 [ for stack protector ]
15200- * 29 - unused
15201- * 30 - unused
15202+ * 29 - PCI BIOS CS
15203+ * 30 - PCI BIOS DS
15204 * 31 - TSS for double fault handler
15205 */
15206+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15207+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15208+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15209+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15210+
15211 #define GDT_ENTRY_TLS_MIN 6
15212 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15213
15214@@ -79,6 +84,8 @@
15215
15216 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15217
15218+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15219+
15220 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15221
15222 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15223@@ -104,6 +111,12 @@
15224 #define __KERNEL_STACK_CANARY 0
15225 #endif
15226
15227+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15228+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15229+
15230+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15231+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15232+
15233 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15234
15235 /*
15236@@ -141,7 +154,7 @@
15237 */
15238
15239 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15240-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15241+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15242
15243
15244 #else
15245@@ -165,6 +178,8 @@
15246 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15247 #define __USER32_DS __USER_DS
15248
15249+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15250+
15251 #define GDT_ENTRY_TSS 8 /* needs two entries */
15252 #define GDT_ENTRY_LDT 10 /* needs two entries */
15253 #define GDT_ENTRY_TLS_MIN 12
15254@@ -185,6 +200,7 @@
15255 #endif
15256
15257 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15258+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15259 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15260 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15261 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15262@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15263 {
15264 unsigned long __limit;
15265 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15266- return __limit + 1;
15267+ return __limit;
15268 }
15269
15270 #endif /* !__ASSEMBLY__ */
15271diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15272index b073aae..39f9bdd 100644
15273--- a/arch/x86/include/asm/smp.h
15274+++ b/arch/x86/include/asm/smp.h
15275@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15276 /* cpus sharing the last level cache: */
15277 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15278 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15279-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15280+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15281
15282 static inline struct cpumask *cpu_sibling_mask(int cpu)
15283 {
15284@@ -79,7 +79,7 @@ struct smp_ops {
15285
15286 void (*send_call_func_ipi)(const struct cpumask *mask);
15287 void (*send_call_func_single_ipi)(int cpu);
15288-};
15289+} __no_const;
15290
15291 /* Globals due to paravirt */
15292 extern void set_cpu_sibling_map(int cpu);
15293@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15294 extern int safe_smp_processor_id(void);
15295
15296 #elif defined(CONFIG_X86_64_SMP)
15297-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15298-
15299-#define stack_smp_processor_id() \
15300-({ \
15301- struct thread_info *ti; \
15302- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15303- ti->cpu; \
15304-})
15305+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15306+#define stack_smp_processor_id() raw_smp_processor_id()
15307 #define safe_smp_processor_id() smp_processor_id()
15308
15309 #endif
15310diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15311index 33692ea..350a534 100644
15312--- a/arch/x86/include/asm/spinlock.h
15313+++ b/arch/x86/include/asm/spinlock.h
15314@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15315 static inline void arch_read_lock(arch_rwlock_t *rw)
15316 {
15317 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15318+
15319+#ifdef CONFIG_PAX_REFCOUNT
15320+ "jno 0f\n"
15321+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15322+ "int $4\n0:\n"
15323+ _ASM_EXTABLE(0b, 0b)
15324+#endif
15325+
15326 "jns 1f\n"
15327 "call __read_lock_failed\n\t"
15328 "1:\n"
15329@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15330 static inline void arch_write_lock(arch_rwlock_t *rw)
15331 {
15332 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15333+
15334+#ifdef CONFIG_PAX_REFCOUNT
15335+ "jno 0f\n"
15336+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15337+ "int $4\n0:\n"
15338+ _ASM_EXTABLE(0b, 0b)
15339+#endif
15340+
15341 "jz 1f\n"
15342 "call __write_lock_failed\n\t"
15343 "1:\n"
15344@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15345
15346 static inline void arch_read_unlock(arch_rwlock_t *rw)
15347 {
15348- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15349+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15350+
15351+#ifdef CONFIG_PAX_REFCOUNT
15352+ "jno 0f\n"
15353+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15354+ "int $4\n0:\n"
15355+ _ASM_EXTABLE(0b, 0b)
15356+#endif
15357+
15358 :"+m" (rw->lock) : : "memory");
15359 }
15360
15361 static inline void arch_write_unlock(arch_rwlock_t *rw)
15362 {
15363- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15364+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15365+
15366+#ifdef CONFIG_PAX_REFCOUNT
15367+ "jno 0f\n"
15368+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15369+ "int $4\n0:\n"
15370+ _ASM_EXTABLE(0b, 0b)
15371+#endif
15372+
15373 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15374 }
15375
15376diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15377index 6a99859..03cb807 100644
15378--- a/arch/x86/include/asm/stackprotector.h
15379+++ b/arch/x86/include/asm/stackprotector.h
15380@@ -47,7 +47,7 @@
15381 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15382 */
15383 #define GDT_STACK_CANARY_INIT \
15384- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15385+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15386
15387 /*
15388 * Initialize the stackprotector canary value.
15389@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15390
15391 static inline void load_stack_canary_segment(void)
15392 {
15393-#ifdef CONFIG_X86_32
15394+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15395 asm volatile ("mov %0, %%gs" : : "r" (0));
15396 #endif
15397 }
15398diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15399index 70bbe39..4ae2bd4 100644
15400--- a/arch/x86/include/asm/stacktrace.h
15401+++ b/arch/x86/include/asm/stacktrace.h
15402@@ -11,28 +11,20 @@
15403
15404 extern int kstack_depth_to_print;
15405
15406-struct thread_info;
15407+struct task_struct;
15408 struct stacktrace_ops;
15409
15410-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15411- unsigned long *stack,
15412- unsigned long bp,
15413- const struct stacktrace_ops *ops,
15414- void *data,
15415- unsigned long *end,
15416- int *graph);
15417+typedef unsigned long walk_stack_t(struct task_struct *task,
15418+ void *stack_start,
15419+ unsigned long *stack,
15420+ unsigned long bp,
15421+ const struct stacktrace_ops *ops,
15422+ void *data,
15423+ unsigned long *end,
15424+ int *graph);
15425
15426-extern unsigned long
15427-print_context_stack(struct thread_info *tinfo,
15428- unsigned long *stack, unsigned long bp,
15429- const struct stacktrace_ops *ops, void *data,
15430- unsigned long *end, int *graph);
15431-
15432-extern unsigned long
15433-print_context_stack_bp(struct thread_info *tinfo,
15434- unsigned long *stack, unsigned long bp,
15435- const struct stacktrace_ops *ops, void *data,
15436- unsigned long *end, int *graph);
15437+extern walk_stack_t print_context_stack;
15438+extern walk_stack_t print_context_stack_bp;
15439
15440 /* Generic stack tracer with callbacks */
15441
15442@@ -40,7 +32,7 @@ struct stacktrace_ops {
15443 void (*address)(void *data, unsigned long address, int reliable);
15444 /* On negative return stop dumping */
15445 int (*stack)(void *data, char *name);
15446- walk_stack_t walk_stack;
15447+ walk_stack_t *walk_stack;
15448 };
15449
15450 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15451diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15452index 4ec45b3..a4f0a8a 100644
15453--- a/arch/x86/include/asm/switch_to.h
15454+++ b/arch/x86/include/asm/switch_to.h
15455@@ -108,7 +108,7 @@ do { \
15456 "call __switch_to\n\t" \
15457 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15458 __switch_canary \
15459- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15460+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15461 "movq %%rax,%%rdi\n\t" \
15462 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15463 "jnz ret_from_fork\n\t" \
15464@@ -119,7 +119,7 @@ do { \
15465 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15466 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15467 [_tif_fork] "i" (_TIF_FORK), \
15468- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15469+ [thread_info] "m" (current_tinfo), \
15470 [current_task] "m" (current_task) \
15471 __switch_canary_iparam \
15472 : "memory", "cc" __EXTRA_CLOBBER)
15473diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15474index a1df6e8..e002940 100644
15475--- a/arch/x86/include/asm/thread_info.h
15476+++ b/arch/x86/include/asm/thread_info.h
15477@@ -10,6 +10,7 @@
15478 #include <linux/compiler.h>
15479 #include <asm/page.h>
15480 #include <asm/types.h>
15481+#include <asm/percpu.h>
15482
15483 /*
15484 * low level task data that entry.S needs immediate access to
15485@@ -23,7 +24,6 @@ struct exec_domain;
15486 #include <linux/atomic.h>
15487
15488 struct thread_info {
15489- struct task_struct *task; /* main task structure */
15490 struct exec_domain *exec_domain; /* execution domain */
15491 __u32 flags; /* low level flags */
15492 __u32 status; /* thread synchronous flags */
15493@@ -33,19 +33,13 @@ struct thread_info {
15494 mm_segment_t addr_limit;
15495 struct restart_block restart_block;
15496 void __user *sysenter_return;
15497-#ifdef CONFIG_X86_32
15498- unsigned long previous_esp; /* ESP of the previous stack in
15499- case of nested (IRQ) stacks
15500- */
15501- __u8 supervisor_stack[0];
15502-#endif
15503+ unsigned long lowest_stack;
15504 unsigned int sig_on_uaccess_error:1;
15505 unsigned int uaccess_err:1; /* uaccess failed */
15506 };
15507
15508-#define INIT_THREAD_INFO(tsk) \
15509+#define INIT_THREAD_INFO \
15510 { \
15511- .task = &tsk, \
15512 .exec_domain = &default_exec_domain, \
15513 .flags = 0, \
15514 .cpu = 0, \
15515@@ -56,7 +50,7 @@ struct thread_info {
15516 }, \
15517 }
15518
15519-#define init_thread_info (init_thread_union.thread_info)
15520+#define init_thread_info (init_thread_union.stack)
15521 #define init_stack (init_thread_union.stack)
15522
15523 #else /* !__ASSEMBLY__ */
15524@@ -97,6 +91,7 @@ struct thread_info {
15525 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15526 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15527 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15528+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15529
15530 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15531 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15532@@ -121,17 +116,18 @@ struct thread_info {
15533 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15534 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15535 #define _TIF_X32 (1 << TIF_X32)
15536+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15537
15538 /* work to do in syscall_trace_enter() */
15539 #define _TIF_WORK_SYSCALL_ENTRY \
15540 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15541 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15542- _TIF_NOHZ)
15543+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15544
15545 /* work to do in syscall_trace_leave() */
15546 #define _TIF_WORK_SYSCALL_EXIT \
15547 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15548- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15549+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15550
15551 /* work to do on interrupt/exception return */
15552 #define _TIF_WORK_MASK \
15553@@ -142,7 +138,7 @@ struct thread_info {
15554 /* work to do on any return to user space */
15555 #define _TIF_ALLWORK_MASK \
15556 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15557- _TIF_NOHZ)
15558+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15559
15560 /* Only used for 64 bit */
15561 #define _TIF_DO_NOTIFY_MASK \
15562@@ -158,45 +154,40 @@ struct thread_info {
15563
15564 #define PREEMPT_ACTIVE 0x10000000
15565
15566-#ifdef CONFIG_X86_32
15567-
15568-#define STACK_WARN (THREAD_SIZE/8)
15569-/*
15570- * macros/functions for gaining access to the thread information structure
15571- *
15572- * preempt_count needs to be 1 initially, until the scheduler is functional.
15573- */
15574-#ifndef __ASSEMBLY__
15575-
15576-
15577-/* how to get the current stack pointer from C */
15578-register unsigned long current_stack_pointer asm("esp") __used;
15579-
15580-/* how to get the thread information struct from C */
15581-static inline struct thread_info *current_thread_info(void)
15582-{
15583- return (struct thread_info *)
15584- (current_stack_pointer & ~(THREAD_SIZE - 1));
15585-}
15586-
15587-#else /* !__ASSEMBLY__ */
15588-
15589+#ifdef __ASSEMBLY__
15590 /* how to get the thread information struct from ASM */
15591 #define GET_THREAD_INFO(reg) \
15592- movl $-THREAD_SIZE, reg; \
15593- andl %esp, reg
15594+ mov PER_CPU_VAR(current_tinfo), reg
15595
15596 /* use this one if reg already contains %esp */
15597-#define GET_THREAD_INFO_WITH_ESP(reg) \
15598- andl $-THREAD_SIZE, reg
15599+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15600+#else
15601+/* how to get the thread information struct from C */
15602+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15603+
15604+static __always_inline struct thread_info *current_thread_info(void)
15605+{
15606+ return this_cpu_read_stable(current_tinfo);
15607+}
15608+#endif
15609+
15610+#ifdef CONFIG_X86_32
15611+
15612+#define STACK_WARN (THREAD_SIZE/8)
15613+/*
15614+ * macros/functions for gaining access to the thread information structure
15615+ *
15616+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15617+ */
15618+#ifndef __ASSEMBLY__
15619+
15620+/* how to get the current stack pointer from C */
15621+register unsigned long current_stack_pointer asm("esp") __used;
15622
15623 #endif
15624
15625 #else /* X86_32 */
15626
15627-#include <asm/percpu.h>
15628-#define KERNEL_STACK_OFFSET (5*8)
15629-
15630 /*
15631 * macros/functions for gaining access to the thread information structure
15632 * preempt_count needs to be 1 initially, until the scheduler is functional.
15633@@ -204,27 +195,8 @@ static inline struct thread_info *current_thread_info(void)
15634 #ifndef __ASSEMBLY__
15635 DECLARE_PER_CPU(unsigned long, kernel_stack);
15636
15637-static inline struct thread_info *current_thread_info(void)
15638-{
15639- struct thread_info *ti;
15640- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15641- KERNEL_STACK_OFFSET - THREAD_SIZE);
15642- return ti;
15643-}
15644-
15645-#else /* !__ASSEMBLY__ */
15646-
15647-/* how to get the thread information struct from ASM */
15648-#define GET_THREAD_INFO(reg) \
15649- movq PER_CPU_VAR(kernel_stack),reg ; \
15650- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15651-
15652-/*
15653- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15654- * a certain register (to be used in assembler memory operands).
15655- */
15656-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15657-
15658+/* how to get the current stack pointer from C */
15659+register unsigned long current_stack_pointer asm("rsp") __used;
15660 #endif
15661
15662 #endif /* !X86_32 */
15663@@ -283,5 +255,12 @@ static inline bool is_ia32_task(void)
15664 extern void arch_task_cache_init(void);
15665 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15666 extern void arch_release_task_struct(struct task_struct *tsk);
15667+
15668+#define __HAVE_THREAD_FUNCTIONS
15669+#define task_thread_info(task) (&(task)->tinfo)
15670+#define task_stack_page(task) ((task)->stack)
15671+#define setup_thread_stack(p, org) do {} while (0)
15672+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15673+
15674 #endif
15675 #endif /* _ASM_X86_THREAD_INFO_H */
15676diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15677index 5ee2687..70d5895 100644
15678--- a/arch/x86/include/asm/uaccess.h
15679+++ b/arch/x86/include/asm/uaccess.h
15680@@ -7,6 +7,7 @@
15681 #include <linux/compiler.h>
15682 #include <linux/thread_info.h>
15683 #include <linux/string.h>
15684+#include <linux/sched.h>
15685 #include <asm/asm.h>
15686 #include <asm/page.h>
15687 #include <asm/smap.h>
15688@@ -29,7 +30,12 @@
15689
15690 #define get_ds() (KERNEL_DS)
15691 #define get_fs() (current_thread_info()->addr_limit)
15692+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15693+void __set_fs(mm_segment_t x);
15694+void set_fs(mm_segment_t x);
15695+#else
15696 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15697+#endif
15698
15699 #define segment_eq(a, b) ((a).seg == (b).seg)
15700
15701@@ -77,8 +83,33 @@
15702 * checks that the pointer is in the user space range - after calling
15703 * this function, memory access functions may still return -EFAULT.
15704 */
15705-#define access_ok(type, addr, size) \
15706- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15707+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15708+#define access_ok(type, addr, size) \
15709+({ \
15710+ long __size = size; \
15711+ unsigned long __addr = (unsigned long)addr; \
15712+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15713+ unsigned long __end_ao = __addr + __size - 1; \
15714+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15715+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15716+ while(__addr_ao <= __end_ao) { \
15717+ char __c_ao; \
15718+ __addr_ao += PAGE_SIZE; \
15719+ if (__size > PAGE_SIZE) \
15720+ cond_resched(); \
15721+ if (__get_user(__c_ao, (char __user *)__addr)) \
15722+ break; \
15723+ if (type != VERIFY_WRITE) { \
15724+ __addr = __addr_ao; \
15725+ continue; \
15726+ } \
15727+ if (__put_user(__c_ao, (char __user *)__addr)) \
15728+ break; \
15729+ __addr = __addr_ao; \
15730+ } \
15731+ } \
15732+ __ret_ao; \
15733+})
15734
15735 /*
15736 * The exception table consists of pairs of addresses relative to the
15737@@ -176,13 +207,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15738 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15739 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15740
15741-
15742+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15743+#define __copyuser_seg "gs;"
15744+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15745+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15746+#else
15747+#define __copyuser_seg
15748+#define __COPYUSER_SET_ES
15749+#define __COPYUSER_RESTORE_ES
15750+#endif
15751
15752 #ifdef CONFIG_X86_32
15753 #define __put_user_asm_u64(x, addr, err, errret) \
15754 asm volatile(ASM_STAC "\n" \
15755- "1: movl %%eax,0(%2)\n" \
15756- "2: movl %%edx,4(%2)\n" \
15757+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15758+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15759 "3: " ASM_CLAC "\n" \
15760 ".section .fixup,\"ax\"\n" \
15761 "4: movl %3,%0\n" \
15762@@ -195,8 +234,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15763
15764 #define __put_user_asm_ex_u64(x, addr) \
15765 asm volatile(ASM_STAC "\n" \
15766- "1: movl %%eax,0(%1)\n" \
15767- "2: movl %%edx,4(%1)\n" \
15768+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15769+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15770 "3: " ASM_CLAC "\n" \
15771 _ASM_EXTABLE_EX(1b, 2b) \
15772 _ASM_EXTABLE_EX(2b, 3b) \
15773@@ -246,7 +285,7 @@ extern void __put_user_8(void);
15774 __typeof__(*(ptr)) __pu_val; \
15775 __chk_user_ptr(ptr); \
15776 might_fault(); \
15777- __pu_val = x; \
15778+ __pu_val = (x); \
15779 switch (sizeof(*(ptr))) { \
15780 case 1: \
15781 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15782@@ -345,7 +384,7 @@ do { \
15783
15784 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15785 asm volatile(ASM_STAC "\n" \
15786- "1: mov"itype" %2,%"rtype"1\n" \
15787+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15788 "2: " ASM_CLAC "\n" \
15789 ".section .fixup,\"ax\"\n" \
15790 "3: mov %3,%0\n" \
15791@@ -353,7 +392,7 @@ do { \
15792 " jmp 2b\n" \
15793 ".previous\n" \
15794 _ASM_EXTABLE(1b, 3b) \
15795- : "=r" (err), ltype(x) \
15796+ : "=r" (err), ltype (x) \
15797 : "m" (__m(addr)), "i" (errret), "0" (err))
15798
15799 #define __get_user_size_ex(x, ptr, size) \
15800@@ -378,7 +417,7 @@ do { \
15801 } while (0)
15802
15803 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15804- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15805+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15806 "2:\n" \
15807 _ASM_EXTABLE_EX(1b, 2b) \
15808 : ltype(x) : "m" (__m(addr)))
15809@@ -395,13 +434,24 @@ do { \
15810 int __gu_err; \
15811 unsigned long __gu_val; \
15812 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15813- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15814+ (x) = (__typeof__(*(ptr)))__gu_val; \
15815 __gu_err; \
15816 })
15817
15818 /* FIXME: this hack is definitely wrong -AK */
15819 struct __large_struct { unsigned long buf[100]; };
15820-#define __m(x) (*(struct __large_struct __user *)(x))
15821+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15822+#define ____m(x) \
15823+({ \
15824+ unsigned long ____x = (unsigned long)(x); \
15825+ if (____x < pax_user_shadow_base) \
15826+ ____x += pax_user_shadow_base; \
15827+ (typeof(x))____x; \
15828+})
15829+#else
15830+#define ____m(x) (x)
15831+#endif
15832+#define __m(x) (*(struct __large_struct __user *)____m(x))
15833
15834 /*
15835 * Tell gcc we read from memory instead of writing: this is because
15836@@ -410,7 +460,7 @@ struct __large_struct { unsigned long buf[100]; };
15837 */
15838 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15839 asm volatile(ASM_STAC "\n" \
15840- "1: mov"itype" %"rtype"1,%2\n" \
15841+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15842 "2: " ASM_CLAC "\n" \
15843 ".section .fixup,\"ax\"\n" \
15844 "3: mov %3,%0\n" \
15845@@ -418,10 +468,10 @@ struct __large_struct { unsigned long buf[100]; };
15846 ".previous\n" \
15847 _ASM_EXTABLE(1b, 3b) \
15848 : "=r"(err) \
15849- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15850+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15851
15852 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15853- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15854+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15855 "2:\n" \
15856 _ASM_EXTABLE_EX(1b, 2b) \
15857 : : ltype(x), "m" (__m(addr)))
15858@@ -460,8 +510,12 @@ struct __large_struct { unsigned long buf[100]; };
15859 * On error, the variable @x is set to zero.
15860 */
15861
15862+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15863+#define __get_user(x, ptr) get_user((x), (ptr))
15864+#else
15865 #define __get_user(x, ptr) \
15866 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15867+#endif
15868
15869 /**
15870 * __put_user: - Write a simple value into user space, with less checking.
15871@@ -483,8 +537,12 @@ struct __large_struct { unsigned long buf[100]; };
15872 * Returns zero on success, or -EFAULT on error.
15873 */
15874
15875+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15876+#define __put_user(x, ptr) put_user((x), (ptr))
15877+#else
15878 #define __put_user(x, ptr) \
15879 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15880+#endif
15881
15882 #define __get_user_unaligned __get_user
15883 #define __put_user_unaligned __put_user
15884@@ -502,7 +560,7 @@ struct __large_struct { unsigned long buf[100]; };
15885 #define get_user_ex(x, ptr) do { \
15886 unsigned long __gue_val; \
15887 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15888- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15889+ (x) = (__typeof__(*(ptr)))__gue_val; \
15890 } while (0)
15891
15892 #define put_user_try uaccess_try
15893@@ -519,8 +577,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15894 extern __must_check long strlen_user(const char __user *str);
15895 extern __must_check long strnlen_user(const char __user *str, long n);
15896
15897-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15898-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15899+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15900+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15901
15902 /*
15903 * movsl can be slow when source and dest are not both 8-byte aligned
15904diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15905index 7f760a9..04b1c65 100644
15906--- a/arch/x86/include/asm/uaccess_32.h
15907+++ b/arch/x86/include/asm/uaccess_32.h
15908@@ -11,15 +11,15 @@
15909 #include <asm/page.h>
15910
15911 unsigned long __must_check __copy_to_user_ll
15912- (void __user *to, const void *from, unsigned long n);
15913+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15914 unsigned long __must_check __copy_from_user_ll
15915- (void *to, const void __user *from, unsigned long n);
15916+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15917 unsigned long __must_check __copy_from_user_ll_nozero
15918- (void *to, const void __user *from, unsigned long n);
15919+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15920 unsigned long __must_check __copy_from_user_ll_nocache
15921- (void *to, const void __user *from, unsigned long n);
15922+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15923 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15924- (void *to, const void __user *from, unsigned long n);
15925+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15926
15927 /**
15928 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15929@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15930 static __always_inline unsigned long __must_check
15931 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15932 {
15933+ if ((long)n < 0)
15934+ return n;
15935+
15936+ check_object_size(from, n, true);
15937+
15938 if (__builtin_constant_p(n)) {
15939 unsigned long ret;
15940
15941@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15942 __copy_to_user(void __user *to, const void *from, unsigned long n)
15943 {
15944 might_fault();
15945+
15946 return __copy_to_user_inatomic(to, from, n);
15947 }
15948
15949 static __always_inline unsigned long
15950 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15951 {
15952+ if ((long)n < 0)
15953+ return n;
15954+
15955 /* Avoid zeroing the tail if the copy fails..
15956 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15957 * but as the zeroing behaviour is only significant when n is not
15958@@ -137,6 +146,12 @@ static __always_inline unsigned long
15959 __copy_from_user(void *to, const void __user *from, unsigned long n)
15960 {
15961 might_fault();
15962+
15963+ if ((long)n < 0)
15964+ return n;
15965+
15966+ check_object_size(to, n, false);
15967+
15968 if (__builtin_constant_p(n)) {
15969 unsigned long ret;
15970
15971@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15972 const void __user *from, unsigned long n)
15973 {
15974 might_fault();
15975+
15976+ if ((long)n < 0)
15977+ return n;
15978+
15979 if (__builtin_constant_p(n)) {
15980 unsigned long ret;
15981
15982@@ -181,15 +200,19 @@ static __always_inline unsigned long
15983 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15984 unsigned long n)
15985 {
15986- return __copy_from_user_ll_nocache_nozero(to, from, n);
15987+ if ((long)n < 0)
15988+ return n;
15989+
15990+ return __copy_from_user_ll_nocache_nozero(to, from, n);
15991 }
15992
15993-unsigned long __must_check copy_to_user(void __user *to,
15994- const void *from, unsigned long n);
15995-unsigned long __must_check _copy_from_user(void *to,
15996- const void __user *from,
15997- unsigned long n);
15998-
15999+extern void copy_to_user_overflow(void)
16000+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16001+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16002+#else
16003+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16004+#endif
16005+;
16006
16007 extern void copy_from_user_overflow(void)
16008 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16009@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
16010 #endif
16011 ;
16012
16013-static inline unsigned long __must_check copy_from_user(void *to,
16014- const void __user *from,
16015- unsigned long n)
16016+/**
16017+ * copy_to_user: - Copy a block of data into user space.
16018+ * @to: Destination address, in user space.
16019+ * @from: Source address, in kernel space.
16020+ * @n: Number of bytes to copy.
16021+ *
16022+ * Context: User context only. This function may sleep.
16023+ *
16024+ * Copy data from kernel space to user space.
16025+ *
16026+ * Returns number of bytes that could not be copied.
16027+ * On success, this will be zero.
16028+ */
16029+static inline unsigned long __must_check
16030+copy_to_user(void __user *to, const void *from, unsigned long n)
16031 {
16032- int sz = __compiletime_object_size(to);
16033+ size_t sz = __compiletime_object_size(from);
16034
16035- if (likely(sz == -1 || sz >= n))
16036- n = _copy_from_user(to, from, n);
16037- else
16038+ if (unlikely(sz != (size_t)-1 && sz < n))
16039+ copy_to_user_overflow();
16040+ else if (access_ok(VERIFY_WRITE, to, n))
16041+ n = __copy_to_user(to, from, n);
16042+ return n;
16043+}
16044+
16045+/**
16046+ * copy_from_user: - Copy a block of data from user space.
16047+ * @to: Destination address, in kernel space.
16048+ * @from: Source address, in user space.
16049+ * @n: Number of bytes to copy.
16050+ *
16051+ * Context: User context only. This function may sleep.
16052+ *
16053+ * Copy data from user space to kernel space.
16054+ *
16055+ * Returns number of bytes that could not be copied.
16056+ * On success, this will be zero.
16057+ *
16058+ * If some data could not be copied, this function will pad the copied
16059+ * data to the requested size using zero bytes.
16060+ */
16061+static inline unsigned long __must_check
16062+copy_from_user(void *to, const void __user *from, unsigned long n)
16063+{
16064+ size_t sz = __compiletime_object_size(to);
16065+
16066+ check_object_size(to, n, false);
16067+
16068+ if (unlikely(sz != (size_t)-1 && sz < n))
16069 copy_from_user_overflow();
16070-
16071+ else if (access_ok(VERIFY_READ, from, n))
16072+ n = __copy_from_user(to, from, n);
16073+ else if ((long)n > 0)
16074+ memset(to, 0, n);
16075 return n;
16076 }
16077
16078diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
16079index 142810c..1f2a0a7 100644
16080--- a/arch/x86/include/asm/uaccess_64.h
16081+++ b/arch/x86/include/asm/uaccess_64.h
16082@@ -10,6 +10,9 @@
16083 #include <asm/alternative.h>
16084 #include <asm/cpufeature.h>
16085 #include <asm/page.h>
16086+#include <asm/pgtable.h>
16087+
16088+#define set_fs(x) (current_thread_info()->addr_limit = (x))
16089
16090 /*
16091 * Copy To/From Userspace
16092@@ -17,13 +20,13 @@
16093
16094 /* Handles exceptions in both to and from, but doesn't do access_ok */
16095 __must_check unsigned long
16096-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
16097+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
16098 __must_check unsigned long
16099-copy_user_generic_string(void *to, const void *from, unsigned len);
16100+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
16101 __must_check unsigned long
16102-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
16103+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
16104
16105-static __always_inline __must_check unsigned long
16106+static __always_inline __must_check __size_overflow(3) unsigned long
16107 copy_user_generic(void *to, const void *from, unsigned len)
16108 {
16109 unsigned ret;
16110@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
16111 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
16112 "=d" (len)),
16113 "1" (to), "2" (from), "3" (len)
16114- : "memory", "rcx", "r8", "r9", "r10", "r11");
16115+ : "memory", "rcx", "r8", "r9", "r11");
16116 return ret;
16117 }
16118
16119+static __always_inline __must_check unsigned long
16120+__copy_to_user(void __user *to, const void *from, unsigned long len);
16121+static __always_inline __must_check unsigned long
16122+__copy_from_user(void *to, const void __user *from, unsigned long len);
16123 __must_check unsigned long
16124-_copy_to_user(void __user *to, const void *from, unsigned len);
16125-__must_check unsigned long
16126-_copy_from_user(void *to, const void __user *from, unsigned len);
16127-__must_check unsigned long
16128-copy_in_user(void __user *to, const void __user *from, unsigned len);
16129+copy_in_user(void __user *to, const void __user *from, unsigned long len);
16130+
16131+extern void copy_to_user_overflow(void)
16132+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16133+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16134+#else
16135+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16136+#endif
16137+;
16138+
16139+extern void copy_from_user_overflow(void)
16140+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16141+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16142+#else
16143+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16144+#endif
16145+;
16146
16147 static inline unsigned long __must_check copy_from_user(void *to,
16148 const void __user *from,
16149 unsigned long n)
16150 {
16151- int sz = __compiletime_object_size(to);
16152-
16153 might_fault();
16154- if (likely(sz == -1 || sz >= n))
16155- n = _copy_from_user(to, from, n);
16156-#ifdef CONFIG_DEBUG_VM
16157- else
16158- WARN(1, "Buffer overflow detected!\n");
16159-#endif
16160+
16161+ check_object_size(to, n, false);
16162+
16163+ if (access_ok(VERIFY_READ, from, n))
16164+ n = __copy_from_user(to, from, n);
16165+ else if (n < INT_MAX)
16166+ memset(to, 0, n);
16167 return n;
16168 }
16169
16170 static __always_inline __must_check
16171-int copy_to_user(void __user *dst, const void *src, unsigned size)
16172+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16173 {
16174 might_fault();
16175
16176- return _copy_to_user(dst, src, size);
16177+ if (access_ok(VERIFY_WRITE, dst, size))
16178+ size = __copy_to_user(dst, src, size);
16179+ return size;
16180 }
16181
16182 static __always_inline __must_check
16183-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16184+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16185 {
16186- int ret = 0;
16187+ size_t sz = __compiletime_object_size(dst);
16188+ unsigned ret = 0;
16189
16190 might_fault();
16191+
16192+ if (size > INT_MAX)
16193+ return size;
16194+
16195+ check_object_size(dst, size, false);
16196+
16197+#ifdef CONFIG_PAX_MEMORY_UDEREF
16198+ if (!__access_ok(VERIFY_READ, src, size))
16199+ return size;
16200+#endif
16201+
16202+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16203+ copy_from_user_overflow();
16204+ return size;
16205+ }
16206+
16207 if (!__builtin_constant_p(size))
16208- return copy_user_generic(dst, (__force void *)src, size);
16209+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16210 switch (size) {
16211- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16212+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16213 ret, "b", "b", "=q", 1);
16214 return ret;
16215- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16216+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16217 ret, "w", "w", "=r", 2);
16218 return ret;
16219- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16220+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16221 ret, "l", "k", "=r", 4);
16222 return ret;
16223- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16224+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16225 ret, "q", "", "=r", 8);
16226 return ret;
16227 case 10:
16228- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16229+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16230 ret, "q", "", "=r", 10);
16231 if (unlikely(ret))
16232 return ret;
16233 __get_user_asm(*(u16 *)(8 + (char *)dst),
16234- (u16 __user *)(8 + (char __user *)src),
16235+ (const u16 __user *)(8 + (const char __user *)src),
16236 ret, "w", "w", "=r", 2);
16237 return ret;
16238 case 16:
16239- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16240+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16241 ret, "q", "", "=r", 16);
16242 if (unlikely(ret))
16243 return ret;
16244 __get_user_asm(*(u64 *)(8 + (char *)dst),
16245- (u64 __user *)(8 + (char __user *)src),
16246+ (const u64 __user *)(8 + (const char __user *)src),
16247 ret, "q", "", "=r", 8);
16248 return ret;
16249 default:
16250- return copy_user_generic(dst, (__force void *)src, size);
16251+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16252 }
16253 }
16254
16255 static __always_inline __must_check
16256-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16257+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16258 {
16259- int ret = 0;
16260+ size_t sz = __compiletime_object_size(src);
16261+ unsigned ret = 0;
16262
16263 might_fault();
16264+
16265+ if (size > INT_MAX)
16266+ return size;
16267+
16268+ check_object_size(src, size, true);
16269+
16270+#ifdef CONFIG_PAX_MEMORY_UDEREF
16271+ if (!__access_ok(VERIFY_WRITE, dst, size))
16272+ return size;
16273+#endif
16274+
16275+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16276+ copy_to_user_overflow();
16277+ return size;
16278+ }
16279+
16280 if (!__builtin_constant_p(size))
16281- return copy_user_generic((__force void *)dst, src, size);
16282+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16283 switch (size) {
16284- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16285+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16286 ret, "b", "b", "iq", 1);
16287 return ret;
16288- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16289+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16290 ret, "w", "w", "ir", 2);
16291 return ret;
16292- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16293+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16294 ret, "l", "k", "ir", 4);
16295 return ret;
16296- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16297+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16298 ret, "q", "", "er", 8);
16299 return ret;
16300 case 10:
16301- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16302+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16303 ret, "q", "", "er", 10);
16304 if (unlikely(ret))
16305 return ret;
16306 asm("":::"memory");
16307- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16308+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16309 ret, "w", "w", "ir", 2);
16310 return ret;
16311 case 16:
16312- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16313+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16314 ret, "q", "", "er", 16);
16315 if (unlikely(ret))
16316 return ret;
16317 asm("":::"memory");
16318- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16319+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16320 ret, "q", "", "er", 8);
16321 return ret;
16322 default:
16323- return copy_user_generic((__force void *)dst, src, size);
16324+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16325 }
16326 }
16327
16328 static __always_inline __must_check
16329-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16330+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16331 {
16332- int ret = 0;
16333+ unsigned ret = 0;
16334
16335 might_fault();
16336+
16337+ if (size > INT_MAX)
16338+ return size;
16339+
16340+#ifdef CONFIG_PAX_MEMORY_UDEREF
16341+ if (!__access_ok(VERIFY_READ, src, size))
16342+ return size;
16343+ if (!__access_ok(VERIFY_WRITE, dst, size))
16344+ return size;
16345+#endif
16346+
16347 if (!__builtin_constant_p(size))
16348- return copy_user_generic((__force void *)dst,
16349- (__force void *)src, size);
16350+ return copy_user_generic((__force_kernel void *)____m(dst),
16351+ (__force_kernel const void *)____m(src), size);
16352 switch (size) {
16353 case 1: {
16354 u8 tmp;
16355- __get_user_asm(tmp, (u8 __user *)src,
16356+ __get_user_asm(tmp, (const u8 __user *)src,
16357 ret, "b", "b", "=q", 1);
16358 if (likely(!ret))
16359 __put_user_asm(tmp, (u8 __user *)dst,
16360@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16361 }
16362 case 2: {
16363 u16 tmp;
16364- __get_user_asm(tmp, (u16 __user *)src,
16365+ __get_user_asm(tmp, (const u16 __user *)src,
16366 ret, "w", "w", "=r", 2);
16367 if (likely(!ret))
16368 __put_user_asm(tmp, (u16 __user *)dst,
16369@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16370
16371 case 4: {
16372 u32 tmp;
16373- __get_user_asm(tmp, (u32 __user *)src,
16374+ __get_user_asm(tmp, (const u32 __user *)src,
16375 ret, "l", "k", "=r", 4);
16376 if (likely(!ret))
16377 __put_user_asm(tmp, (u32 __user *)dst,
16378@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16379 }
16380 case 8: {
16381 u64 tmp;
16382- __get_user_asm(tmp, (u64 __user *)src,
16383+ __get_user_asm(tmp, (const u64 __user *)src,
16384 ret, "q", "", "=r", 8);
16385 if (likely(!ret))
16386 __put_user_asm(tmp, (u64 __user *)dst,
16387@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16388 return ret;
16389 }
16390 default:
16391- return copy_user_generic((__force void *)dst,
16392- (__force void *)src, size);
16393+ return copy_user_generic((__force_kernel void *)____m(dst),
16394+ (__force_kernel const void *)____m(src), size);
16395 }
16396 }
16397
16398 static __must_check __always_inline int
16399-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16400+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16401 {
16402- return copy_user_generic(dst, (__force const void *)src, size);
16403+ if (size > INT_MAX)
16404+ return size;
16405+
16406+#ifdef CONFIG_PAX_MEMORY_UDEREF
16407+ if (!__access_ok(VERIFY_READ, src, size))
16408+ return size;
16409+#endif
16410+
16411+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16412 }
16413
16414-static __must_check __always_inline int
16415-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16416+static __must_check __always_inline unsigned long
16417+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16418 {
16419- return copy_user_generic((__force void *)dst, src, size);
16420+ if (size > INT_MAX)
16421+ return size;
16422+
16423+#ifdef CONFIG_PAX_MEMORY_UDEREF
16424+ if (!__access_ok(VERIFY_WRITE, dst, size))
16425+ return size;
16426+#endif
16427+
16428+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16429 }
16430
16431-extern long __copy_user_nocache(void *dst, const void __user *src,
16432- unsigned size, int zerorest);
16433+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16434+ unsigned long size, int zerorest) __size_overflow(3);
16435
16436-static inline int
16437-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16438+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16439 {
16440 might_sleep();
16441+
16442+ if (size > INT_MAX)
16443+ return size;
16444+
16445+#ifdef CONFIG_PAX_MEMORY_UDEREF
16446+ if (!__access_ok(VERIFY_READ, src, size))
16447+ return size;
16448+#endif
16449+
16450 return __copy_user_nocache(dst, src, size, 1);
16451 }
16452
16453-static inline int
16454-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16455- unsigned size)
16456+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16457+ unsigned long size)
16458 {
16459+ if (size > INT_MAX)
16460+ return size;
16461+
16462+#ifdef CONFIG_PAX_MEMORY_UDEREF
16463+ if (!__access_ok(VERIFY_READ, src, size))
16464+ return size;
16465+#endif
16466+
16467 return __copy_user_nocache(dst, src, size, 0);
16468 }
16469
16470-unsigned long
16471-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16472+extern unsigned long
16473+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16474
16475 #endif /* _ASM_X86_UACCESS_64_H */
16476diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16477index 5b238981..77fdd78 100644
16478--- a/arch/x86/include/asm/word-at-a-time.h
16479+++ b/arch/x86/include/asm/word-at-a-time.h
16480@@ -11,7 +11,7 @@
16481 * and shift, for example.
16482 */
16483 struct word_at_a_time {
16484- const unsigned long one_bits, high_bits;
16485+ unsigned long one_bits, high_bits;
16486 };
16487
16488 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16489diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16490index d8d9922..bf6cecb 100644
16491--- a/arch/x86/include/asm/x86_init.h
16492+++ b/arch/x86/include/asm/x86_init.h
16493@@ -129,7 +129,7 @@ struct x86_init_ops {
16494 struct x86_init_timers timers;
16495 struct x86_init_iommu iommu;
16496 struct x86_init_pci pci;
16497-};
16498+} __no_const;
16499
16500 /**
16501 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16502@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
16503 void (*setup_percpu_clockev)(void);
16504 void (*early_percpu_clock_init)(void);
16505 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16506-};
16507+} __no_const;
16508
16509 /**
16510 * struct x86_platform_ops - platform specific runtime functions
16511@@ -166,7 +166,7 @@ struct x86_platform_ops {
16512 void (*save_sched_clock_state)(void);
16513 void (*restore_sched_clock_state)(void);
16514 void (*apic_post_init)(void);
16515-};
16516+} __no_const;
16517
16518 struct pci_dev;
16519 struct msi_msg;
16520@@ -180,7 +180,7 @@ struct x86_msi_ops {
16521 void (*teardown_msi_irqs)(struct pci_dev *dev);
16522 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16523 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
16524-};
16525+} __no_const;
16526
16527 struct IO_APIC_route_entry;
16528 struct io_apic_irq_attr;
16529@@ -201,7 +201,7 @@ struct x86_io_apic_ops {
16530 unsigned int destination, int vector,
16531 struct io_apic_irq_attr *attr);
16532 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
16533-};
16534+} __no_const;
16535
16536 extern struct x86_init_ops x86_init;
16537 extern struct x86_cpuinit_ops x86_cpuinit;
16538diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16539index 0415cda..b43d877 100644
16540--- a/arch/x86/include/asm/xsave.h
16541+++ b/arch/x86/include/asm/xsave.h
16542@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16543 return -EFAULT;
16544
16545 __asm__ __volatile__(ASM_STAC "\n"
16546- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16547+ "1:"
16548+ __copyuser_seg
16549+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16550 "2: " ASM_CLAC "\n"
16551 ".section .fixup,\"ax\"\n"
16552 "3: movl $-1,%[err]\n"
16553@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16554 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16555 {
16556 int err;
16557- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16558+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16559 u32 lmask = mask;
16560 u32 hmask = mask >> 32;
16561
16562 __asm__ __volatile__(ASM_STAC "\n"
16563- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16564+ "1:"
16565+ __copyuser_seg
16566+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16567 "2: " ASM_CLAC "\n"
16568 ".section .fixup,\"ax\"\n"
16569 "3: movl $-1,%[err]\n"
16570diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16571index bbae024..e1528f9 100644
16572--- a/arch/x86/include/uapi/asm/e820.h
16573+++ b/arch/x86/include/uapi/asm/e820.h
16574@@ -63,7 +63,7 @@ struct e820map {
16575 #define ISA_START_ADDRESS 0xa0000
16576 #define ISA_END_ADDRESS 0x100000
16577
16578-#define BIOS_BEGIN 0x000a0000
16579+#define BIOS_BEGIN 0x000c0000
16580 #define BIOS_END 0x00100000
16581
16582 #define BIOS_ROM_BASE 0xffe00000
16583diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16584index 7bd3bd3..5dac791 100644
16585--- a/arch/x86/kernel/Makefile
16586+++ b/arch/x86/kernel/Makefile
16587@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16588 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16589 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16590 obj-y += probe_roms.o
16591-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16592+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16593 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16594 obj-y += syscall_$(BITS).o
16595 obj-$(CONFIG_X86_64) += vsyscall_64.o
16596diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16597index 230c8ea..f915130 100644
16598--- a/arch/x86/kernel/acpi/boot.c
16599+++ b/arch/x86/kernel/acpi/boot.c
16600@@ -1361,7 +1361,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16601 * If your system is blacklisted here, but you find that acpi=force
16602 * works for you, please contact linux-acpi@vger.kernel.org
16603 */
16604-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16605+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16606 /*
16607 * Boxes that need ACPI disabled
16608 */
16609@@ -1436,7 +1436,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16610 };
16611
16612 /* second table for DMI checks that should run after early-quirks */
16613-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16614+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16615 /*
16616 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16617 * which includes some code which overrides all temperature
16618diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16619index b44577b..27d8443 100644
16620--- a/arch/x86/kernel/acpi/sleep.c
16621+++ b/arch/x86/kernel/acpi/sleep.c
16622@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16623 #else /* CONFIG_64BIT */
16624 #ifdef CONFIG_SMP
16625 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16626+
16627+ pax_open_kernel();
16628 early_gdt_descr.address =
16629 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16630+ pax_close_kernel();
16631+
16632 initial_gs = per_cpu_offset(smp_processor_id());
16633 #endif
16634 initial_code = (unsigned long)wakeup_long64;
16635diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16636index d1daa66..59fecba 100644
16637--- a/arch/x86/kernel/acpi/wakeup_32.S
16638+++ b/arch/x86/kernel/acpi/wakeup_32.S
16639@@ -29,13 +29,11 @@ wakeup_pmode_return:
16640 # and restore the stack ... but you need gdt for this to work
16641 movl saved_context_esp, %esp
16642
16643- movl %cs:saved_magic, %eax
16644- cmpl $0x12345678, %eax
16645+ cmpl $0x12345678, saved_magic
16646 jne bogus_magic
16647
16648 # jump to place where we left off
16649- movl saved_eip, %eax
16650- jmp *%eax
16651+ jmp *(saved_eip)
16652
16653 bogus_magic:
16654 jmp bogus_magic
16655diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16656index c15cf9a..0e63558 100644
16657--- a/arch/x86/kernel/alternative.c
16658+++ b/arch/x86/kernel/alternative.c
16659@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16660 */
16661 for (a = start; a < end; a++) {
16662 instr = (u8 *)&a->instr_offset + a->instr_offset;
16663+
16664+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16665+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16666+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16667+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16668+#endif
16669+
16670 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16671 BUG_ON(a->replacementlen > a->instrlen);
16672 BUG_ON(a->instrlen > sizeof(insnbuf));
16673@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16674 for (poff = start; poff < end; poff++) {
16675 u8 *ptr = (u8 *)poff + *poff;
16676
16677+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16678+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16679+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16680+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16681+#endif
16682+
16683 if (!*poff || ptr < text || ptr >= text_end)
16684 continue;
16685 /* turn DS segment override prefix into lock prefix */
16686- if (*ptr == 0x3e)
16687+ if (*ktla_ktva(ptr) == 0x3e)
16688 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16689 }
16690 mutex_unlock(&text_mutex);
16691@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16692 for (poff = start; poff < end; poff++) {
16693 u8 *ptr = (u8 *)poff + *poff;
16694
16695+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16696+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16697+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16698+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16699+#endif
16700+
16701 if (!*poff || ptr < text || ptr >= text_end)
16702 continue;
16703 /* turn lock prefix into DS segment override prefix */
16704- if (*ptr == 0xf0)
16705+ if (*ktla_ktva(ptr) == 0xf0)
16706 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16707 }
16708 mutex_unlock(&text_mutex);
16709@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16710
16711 BUG_ON(p->len > MAX_PATCH_LEN);
16712 /* prep the buffer with the original instructions */
16713- memcpy(insnbuf, p->instr, p->len);
16714+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16715 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16716 (unsigned long)p->instr, p->len);
16717
16718@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16719 if (!uniproc_patched || num_possible_cpus() == 1)
16720 free_init_pages("SMP alternatives",
16721 (unsigned long)__smp_locks,
16722- (unsigned long)__smp_locks_end);
16723+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16724 #endif
16725
16726 apply_paravirt(__parainstructions, __parainstructions_end);
16727@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16728 * instructions. And on the local CPU you need to be protected again NMI or MCE
16729 * handlers seeing an inconsistent instruction while you patch.
16730 */
16731-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16732+void *__kprobes text_poke_early(void *addr, const void *opcode,
16733 size_t len)
16734 {
16735 unsigned long flags;
16736 local_irq_save(flags);
16737- memcpy(addr, opcode, len);
16738+
16739+ pax_open_kernel();
16740+ memcpy(ktla_ktva(addr), opcode, len);
16741 sync_core();
16742+ pax_close_kernel();
16743+
16744 local_irq_restore(flags);
16745 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16746 that causes hangs on some VIA CPUs. */
16747@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16748 */
16749 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16750 {
16751- unsigned long flags;
16752- char *vaddr;
16753+ unsigned char *vaddr = ktla_ktva(addr);
16754 struct page *pages[2];
16755- int i;
16756+ size_t i;
16757
16758 if (!core_kernel_text((unsigned long)addr)) {
16759- pages[0] = vmalloc_to_page(addr);
16760- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16761+ pages[0] = vmalloc_to_page(vaddr);
16762+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16763 } else {
16764- pages[0] = virt_to_page(addr);
16765+ pages[0] = virt_to_page(vaddr);
16766 WARN_ON(!PageReserved(pages[0]));
16767- pages[1] = virt_to_page(addr + PAGE_SIZE);
16768+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16769 }
16770 BUG_ON(!pages[0]);
16771- local_irq_save(flags);
16772- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16773- if (pages[1])
16774- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16775- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16776- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16777- clear_fixmap(FIX_TEXT_POKE0);
16778- if (pages[1])
16779- clear_fixmap(FIX_TEXT_POKE1);
16780- local_flush_tlb();
16781- sync_core();
16782- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16783- that causes hangs on some VIA CPUs. */
16784+ text_poke_early(addr, opcode, len);
16785 for (i = 0; i < len; i++)
16786- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16787- local_irq_restore(flags);
16788+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16789 return addr;
16790 }
16791
16792diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16793index 904611b..004dde6 100644
16794--- a/arch/x86/kernel/apic/apic.c
16795+++ b/arch/x86/kernel/apic/apic.c
16796@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16797 /*
16798 * Debug level, exported for io_apic.c
16799 */
16800-unsigned int apic_verbosity;
16801+int apic_verbosity;
16802
16803 int pic_mode;
16804
16805@@ -1955,7 +1955,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16806 apic_write(APIC_ESR, 0);
16807 v1 = apic_read(APIC_ESR);
16808 ack_APIC_irq();
16809- atomic_inc(&irq_err_count);
16810+ atomic_inc_unchecked(&irq_err_count);
16811
16812 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16813 smp_processor_id(), v0 , v1);
16814diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16815index 00c77cf..2dc6a2d 100644
16816--- a/arch/x86/kernel/apic/apic_flat_64.c
16817+++ b/arch/x86/kernel/apic/apic_flat_64.c
16818@@ -157,7 +157,7 @@ static int flat_probe(void)
16819 return 1;
16820 }
16821
16822-static struct apic apic_flat = {
16823+static struct apic apic_flat __read_only = {
16824 .name = "flat",
16825 .probe = flat_probe,
16826 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16827@@ -271,7 +271,7 @@ static int physflat_probe(void)
16828 return 0;
16829 }
16830
16831-static struct apic apic_physflat = {
16832+static struct apic apic_physflat __read_only = {
16833
16834 .name = "physical flat",
16835 .probe = physflat_probe,
16836diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16837index e145f28..2752888 100644
16838--- a/arch/x86/kernel/apic/apic_noop.c
16839+++ b/arch/x86/kernel/apic/apic_noop.c
16840@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16841 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16842 }
16843
16844-struct apic apic_noop = {
16845+struct apic apic_noop __read_only = {
16846 .name = "noop",
16847 .probe = noop_probe,
16848 .acpi_madt_oem_check = NULL,
16849diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16850index d50e364..543bee3 100644
16851--- a/arch/x86/kernel/apic/bigsmp_32.c
16852+++ b/arch/x86/kernel/apic/bigsmp_32.c
16853@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16854 return dmi_bigsmp;
16855 }
16856
16857-static struct apic apic_bigsmp = {
16858+static struct apic apic_bigsmp __read_only = {
16859
16860 .name = "bigsmp",
16861 .probe = probe_bigsmp,
16862diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16863index 0874799..a7a7892 100644
16864--- a/arch/x86/kernel/apic/es7000_32.c
16865+++ b/arch/x86/kernel/apic/es7000_32.c
16866@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16867 return ret && es7000_apic_is_cluster();
16868 }
16869
16870-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16871-static struct apic __refdata apic_es7000_cluster = {
16872+static struct apic apic_es7000_cluster __read_only = {
16873
16874 .name = "es7000",
16875 .probe = probe_es7000,
16876@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16877 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16878 };
16879
16880-static struct apic __refdata apic_es7000 = {
16881+static struct apic apic_es7000 __read_only = {
16882
16883 .name = "es7000",
16884 .probe = probe_es7000,
16885diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16886index 9ed796c..e930fe4 100644
16887--- a/arch/x86/kernel/apic/io_apic.c
16888+++ b/arch/x86/kernel/apic/io_apic.c
16889@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16890 }
16891 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16892
16893-void lock_vector_lock(void)
16894+void lock_vector_lock(void) __acquires(vector_lock)
16895 {
16896 /* Used to the online set of cpus does not change
16897 * during assign_irq_vector.
16898@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
16899 raw_spin_lock(&vector_lock);
16900 }
16901
16902-void unlock_vector_lock(void)
16903+void unlock_vector_lock(void) __releases(vector_lock)
16904 {
16905 raw_spin_unlock(&vector_lock);
16906 }
16907@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
16908 ack_APIC_irq();
16909 }
16910
16911-atomic_t irq_mis_count;
16912+atomic_unchecked_t irq_mis_count;
16913
16914 #ifdef CONFIG_GENERIC_PENDING_IRQ
16915 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16916@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
16917 * at the cpu.
16918 */
16919 if (!(v & (1 << (i & 0x1f)))) {
16920- atomic_inc(&irq_mis_count);
16921+ atomic_inc_unchecked(&irq_mis_count);
16922
16923 eoi_ioapic_irq(irq, cfg);
16924 }
16925diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16926index d661ee9..791fd33 100644
16927--- a/arch/x86/kernel/apic/numaq_32.c
16928+++ b/arch/x86/kernel/apic/numaq_32.c
16929@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16930 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16931 }
16932
16933-/* Use __refdata to keep false positive warning calm. */
16934-static struct apic __refdata apic_numaq = {
16935+static struct apic apic_numaq __read_only = {
16936
16937 .name = "NUMAQ",
16938 .probe = probe_numaq,
16939diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16940index eb35ef9..f184a21 100644
16941--- a/arch/x86/kernel/apic/probe_32.c
16942+++ b/arch/x86/kernel/apic/probe_32.c
16943@@ -72,7 +72,7 @@ static int probe_default(void)
16944 return 1;
16945 }
16946
16947-static struct apic apic_default = {
16948+static struct apic apic_default __read_only = {
16949
16950 .name = "default",
16951 .probe = probe_default,
16952diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16953index 77c95c0..434f8a4 100644
16954--- a/arch/x86/kernel/apic/summit_32.c
16955+++ b/arch/x86/kernel/apic/summit_32.c
16956@@ -486,7 +486,7 @@ void setup_summit(void)
16957 }
16958 #endif
16959
16960-static struct apic apic_summit = {
16961+static struct apic apic_summit __read_only = {
16962
16963 .name = "summit",
16964 .probe = probe_summit,
16965diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16966index c88baa4..757aee1 100644
16967--- a/arch/x86/kernel/apic/x2apic_cluster.c
16968+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16969@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16970 return notifier_from_errno(err);
16971 }
16972
16973-static struct notifier_block __refdata x2apic_cpu_notifier = {
16974+static struct notifier_block x2apic_cpu_notifier = {
16975 .notifier_call = update_clusterinfo,
16976 };
16977
16978@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16979 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16980 }
16981
16982-static struct apic apic_x2apic_cluster = {
16983+static struct apic apic_x2apic_cluster __read_only = {
16984
16985 .name = "cluster x2apic",
16986 .probe = x2apic_cluster_probe,
16987diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16988index 562a76d..a003c0f 100644
16989--- a/arch/x86/kernel/apic/x2apic_phys.c
16990+++ b/arch/x86/kernel/apic/x2apic_phys.c
16991@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16992 return apic == &apic_x2apic_phys;
16993 }
16994
16995-static struct apic apic_x2apic_phys = {
16996+static struct apic apic_x2apic_phys __read_only = {
16997
16998 .name = "physical x2apic",
16999 .probe = x2apic_phys_probe,
17000diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
17001index 794f6eb..67e1db2 100644
17002--- a/arch/x86/kernel/apic/x2apic_uv_x.c
17003+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
17004@@ -342,7 +342,7 @@ static int uv_probe(void)
17005 return apic == &apic_x2apic_uv_x;
17006 }
17007
17008-static struct apic __refdata apic_x2apic_uv_x = {
17009+static struct apic apic_x2apic_uv_x __read_only = {
17010
17011 .name = "UV large system",
17012 .probe = uv_probe,
17013diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
17014index 53a4e27..038760a 100644
17015--- a/arch/x86/kernel/apm_32.c
17016+++ b/arch/x86/kernel/apm_32.c
17017@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
17018 * This is for buggy BIOS's that refer to (real mode) segment 0x40
17019 * even though they are called in protected mode.
17020 */
17021-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
17022+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
17023 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
17024
17025 static const char driver_version[] = "1.16ac"; /* no spaces */
17026@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
17027 BUG_ON(cpu != 0);
17028 gdt = get_cpu_gdt_table(cpu);
17029 save_desc_40 = gdt[0x40 / 8];
17030+
17031+ pax_open_kernel();
17032 gdt[0x40 / 8] = bad_bios_desc;
17033+ pax_close_kernel();
17034
17035 apm_irq_save(flags);
17036 APM_DO_SAVE_SEGS;
17037@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
17038 &call->esi);
17039 APM_DO_RESTORE_SEGS;
17040 apm_irq_restore(flags);
17041+
17042+ pax_open_kernel();
17043 gdt[0x40 / 8] = save_desc_40;
17044+ pax_close_kernel();
17045+
17046 put_cpu();
17047
17048 return call->eax & 0xff;
17049@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
17050 BUG_ON(cpu != 0);
17051 gdt = get_cpu_gdt_table(cpu);
17052 save_desc_40 = gdt[0x40 / 8];
17053+
17054+ pax_open_kernel();
17055 gdt[0x40 / 8] = bad_bios_desc;
17056+ pax_close_kernel();
17057
17058 apm_irq_save(flags);
17059 APM_DO_SAVE_SEGS;
17060@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
17061 &call->eax);
17062 APM_DO_RESTORE_SEGS;
17063 apm_irq_restore(flags);
17064+
17065+ pax_open_kernel();
17066 gdt[0x40 / 8] = save_desc_40;
17067+ pax_close_kernel();
17068+
17069 put_cpu();
17070 return error;
17071 }
17072@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
17073 * code to that CPU.
17074 */
17075 gdt = get_cpu_gdt_table(0);
17076+
17077+ pax_open_kernel();
17078 set_desc_base(&gdt[APM_CS >> 3],
17079 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
17080 set_desc_base(&gdt[APM_CS_16 >> 3],
17081 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
17082 set_desc_base(&gdt[APM_DS >> 3],
17083 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
17084+ pax_close_kernel();
17085
17086 proc_create("apm", 0, NULL, &apm_file_ops);
17087
17088diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
17089index 2861082..6d4718e 100644
17090--- a/arch/x86/kernel/asm-offsets.c
17091+++ b/arch/x86/kernel/asm-offsets.c
17092@@ -33,6 +33,8 @@ void common(void) {
17093 OFFSET(TI_status, thread_info, status);
17094 OFFSET(TI_addr_limit, thread_info, addr_limit);
17095 OFFSET(TI_preempt_count, thread_info, preempt_count);
17096+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
17097+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
17098
17099 BLANK();
17100 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
17101@@ -53,8 +55,26 @@ void common(void) {
17102 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
17103 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
17104 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
17105+
17106+#ifdef CONFIG_PAX_KERNEXEC
17107+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
17108 #endif
17109
17110+#ifdef CONFIG_PAX_MEMORY_UDEREF
17111+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
17112+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
17113+#ifdef CONFIG_X86_64
17114+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
17115+#endif
17116+#endif
17117+
17118+#endif
17119+
17120+ BLANK();
17121+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
17122+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
17123+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
17124+
17125 #ifdef CONFIG_XEN
17126 BLANK();
17127 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17128diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17129index e7c798b..2b2019b 100644
17130--- a/arch/x86/kernel/asm-offsets_64.c
17131+++ b/arch/x86/kernel/asm-offsets_64.c
17132@@ -77,6 +77,7 @@ int main(void)
17133 BLANK();
17134 #undef ENTRY
17135
17136+ DEFINE(TSS_size, sizeof(struct tss_struct));
17137 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17138 BLANK();
17139
17140diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17141index b0684e4..22ccfd7 100644
17142--- a/arch/x86/kernel/cpu/Makefile
17143+++ b/arch/x86/kernel/cpu/Makefile
17144@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17145 CFLAGS_REMOVE_perf_event.o = -pg
17146 endif
17147
17148-# Make sure load_percpu_segment has no stackprotector
17149-nostackp := $(call cc-option, -fno-stack-protector)
17150-CFLAGS_common.o := $(nostackp)
17151-
17152 obj-y := intel_cacheinfo.o scattered.o topology.o
17153 obj-y += proc.o capflags.o powerflags.o common.o
17154 obj-y += rdrand.o
17155diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17156index 5013a48..0782c53 100644
17157--- a/arch/x86/kernel/cpu/amd.c
17158+++ b/arch/x86/kernel/cpu/amd.c
17159@@ -744,7 +744,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17160 unsigned int size)
17161 {
17162 /* AMD errata T13 (order #21922) */
17163- if ((c->x86 == 6)) {
17164+ if (c->x86 == 6) {
17165 /* Duron Rev A0 */
17166 if (c->x86_model == 3 && c->x86_mask == 0)
17167 size = 64;
17168diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17169index 22018f7..bc6f5e3 100644
17170--- a/arch/x86/kernel/cpu/common.c
17171+++ b/arch/x86/kernel/cpu/common.c
17172@@ -88,60 +88,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17173
17174 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17175
17176-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17177-#ifdef CONFIG_X86_64
17178- /*
17179- * We need valid kernel segments for data and code in long mode too
17180- * IRET will check the segment types kkeil 2000/10/28
17181- * Also sysret mandates a special GDT layout
17182- *
17183- * TLS descriptors are currently at a different place compared to i386.
17184- * Hopefully nobody expects them at a fixed place (Wine?)
17185- */
17186- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17187- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17188- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17189- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17190- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17191- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17192-#else
17193- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17194- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17195- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17196- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17197- /*
17198- * Segments used for calling PnP BIOS have byte granularity.
17199- * They code segments and data segments have fixed 64k limits,
17200- * the transfer segment sizes are set at run time.
17201- */
17202- /* 32-bit code */
17203- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17204- /* 16-bit code */
17205- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17206- /* 16-bit data */
17207- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17208- /* 16-bit data */
17209- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17210- /* 16-bit data */
17211- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17212- /*
17213- * The APM segments have byte granularity and their bases
17214- * are set at run time. All have 64k limits.
17215- */
17216- /* 32-bit code */
17217- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17218- /* 16-bit code */
17219- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17220- /* data */
17221- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17222-
17223- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17224- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17225- GDT_STACK_CANARY_INIT
17226-#endif
17227-} };
17228-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17229-
17230 static int __init x86_xsave_setup(char *s)
17231 {
17232 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17233@@ -386,7 +332,7 @@ void switch_to_new_gdt(int cpu)
17234 {
17235 struct desc_ptr gdt_descr;
17236
17237- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17238+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17239 gdt_descr.size = GDT_SIZE - 1;
17240 load_gdt(&gdt_descr);
17241 /* Reload the per-cpu base */
17242@@ -882,6 +828,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17243 /* Filter out anything that depends on CPUID levels we don't have */
17244 filter_cpuid_features(c, true);
17245
17246+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17247+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17248+#endif
17249+
17250 /* If the model name is still unset, do table lookup. */
17251 if (!c->x86_model_id[0]) {
17252 const char *p;
17253@@ -1069,10 +1019,12 @@ static __init int setup_disablecpuid(char *arg)
17254 }
17255 __setup("clearcpuid=", setup_disablecpuid);
17256
17257+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17258+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17259+
17260 #ifdef CONFIG_X86_64
17261 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17262-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17263- (unsigned long) nmi_idt_table };
17264+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17265
17266 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17267 irq_stack_union) __aligned(PAGE_SIZE);
17268@@ -1086,7 +1038,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17269 EXPORT_PER_CPU_SYMBOL(current_task);
17270
17271 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17272- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17273+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17274 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17275
17276 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17277@@ -1231,7 +1183,7 @@ void __cpuinit cpu_init(void)
17278 load_ucode_ap();
17279
17280 cpu = stack_smp_processor_id();
17281- t = &per_cpu(init_tss, cpu);
17282+ t = init_tss + cpu;
17283 oist = &per_cpu(orig_ist, cpu);
17284
17285 #ifdef CONFIG_NUMA
17286@@ -1257,7 +1209,7 @@ void __cpuinit cpu_init(void)
17287 switch_to_new_gdt(cpu);
17288 loadsegment(fs, 0);
17289
17290- load_idt((const struct desc_ptr *)&idt_descr);
17291+ load_idt(&idt_descr);
17292
17293 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17294 syscall_init();
17295@@ -1266,7 +1218,6 @@ void __cpuinit cpu_init(void)
17296 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17297 barrier();
17298
17299- x86_configure_nx();
17300 enable_x2apic();
17301
17302 /*
17303@@ -1318,7 +1269,7 @@ void __cpuinit cpu_init(void)
17304 {
17305 int cpu = smp_processor_id();
17306 struct task_struct *curr = current;
17307- struct tss_struct *t = &per_cpu(init_tss, cpu);
17308+ struct tss_struct *t = init_tss + cpu;
17309 struct thread_struct *thread = &curr->thread;
17310
17311 show_ucode_info_early();
17312diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17313index 7c6f7d5..8cac382 100644
17314--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17315+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17316@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17317 };
17318
17319 #ifdef CONFIG_AMD_NB
17320+static struct attribute *default_attrs_amd_nb[] = {
17321+ &type.attr,
17322+ &level.attr,
17323+ &coherency_line_size.attr,
17324+ &physical_line_partition.attr,
17325+ &ways_of_associativity.attr,
17326+ &number_of_sets.attr,
17327+ &size.attr,
17328+ &shared_cpu_map.attr,
17329+ &shared_cpu_list.attr,
17330+ NULL,
17331+ NULL,
17332+ NULL,
17333+ NULL
17334+};
17335+
17336 static struct attribute ** __cpuinit amd_l3_attrs(void)
17337 {
17338 static struct attribute **attrs;
17339@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17340
17341 n = ARRAY_SIZE(default_attrs);
17342
17343- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17344- n += 2;
17345-
17346- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17347- n += 1;
17348-
17349- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17350- if (attrs == NULL)
17351- return attrs = default_attrs;
17352-
17353- for (n = 0; default_attrs[n]; n++)
17354- attrs[n] = default_attrs[n];
17355+ attrs = default_attrs_amd_nb;
17356
17357 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17358 attrs[n++] = &cache_disable_0.attr;
17359@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17360 .default_attrs = default_attrs,
17361 };
17362
17363+#ifdef CONFIG_AMD_NB
17364+static struct kobj_type ktype_cache_amd_nb = {
17365+ .sysfs_ops = &sysfs_ops,
17366+ .default_attrs = default_attrs_amd_nb,
17367+};
17368+#endif
17369+
17370 static struct kobj_type ktype_percpu_entry = {
17371 .sysfs_ops = &sysfs_ops,
17372 };
17373@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17374 return retval;
17375 }
17376
17377+#ifdef CONFIG_AMD_NB
17378+ amd_l3_attrs();
17379+#endif
17380+
17381 for (i = 0; i < num_cache_leaves; i++) {
17382+ struct kobj_type *ktype;
17383+
17384 this_object = INDEX_KOBJECT_PTR(cpu, i);
17385 this_object->cpu = cpu;
17386 this_object->index = i;
17387
17388 this_leaf = CPUID4_INFO_IDX(cpu, i);
17389
17390- ktype_cache.default_attrs = default_attrs;
17391+ ktype = &ktype_cache;
17392 #ifdef CONFIG_AMD_NB
17393 if (this_leaf->base.nb)
17394- ktype_cache.default_attrs = amd_l3_attrs();
17395+ ktype = &ktype_cache_amd_nb;
17396 #endif
17397 retval = kobject_init_and_add(&(this_object->kobj),
17398- &ktype_cache,
17399+ ktype,
17400 per_cpu(ici_cache_kobject, cpu),
17401 "index%1lu", i);
17402 if (unlikely(retval)) {
17403@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17404 return NOTIFY_OK;
17405 }
17406
17407-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17408+static struct notifier_block cacheinfo_cpu_notifier = {
17409 .notifier_call = cacheinfo_cpu_callback,
17410 };
17411
17412diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17413index 9239504..b2471ce 100644
17414--- a/arch/x86/kernel/cpu/mcheck/mce.c
17415+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17416@@ -45,6 +45,7 @@
17417 #include <asm/processor.h>
17418 #include <asm/mce.h>
17419 #include <asm/msr.h>
17420+#include <asm/local.h>
17421
17422 #include "mce-internal.h"
17423
17424@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17425 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17426 m->cs, m->ip);
17427
17428- if (m->cs == __KERNEL_CS)
17429+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17430 print_symbol("{%s}", m->ip);
17431 pr_cont("\n");
17432 }
17433@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17434
17435 #define PANIC_TIMEOUT 5 /* 5 seconds */
17436
17437-static atomic_t mce_paniced;
17438+static atomic_unchecked_t mce_paniced;
17439
17440 static int fake_panic;
17441-static atomic_t mce_fake_paniced;
17442+static atomic_unchecked_t mce_fake_paniced;
17443
17444 /* Panic in progress. Enable interrupts and wait for final IPI */
17445 static void wait_for_panic(void)
17446@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17447 /*
17448 * Make sure only one CPU runs in machine check panic
17449 */
17450- if (atomic_inc_return(&mce_paniced) > 1)
17451+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17452 wait_for_panic();
17453 barrier();
17454
17455@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17456 console_verbose();
17457 } else {
17458 /* Don't log too much for fake panic */
17459- if (atomic_inc_return(&mce_fake_paniced) > 1)
17460+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17461 return;
17462 }
17463 /* First print corrected ones that are still unlogged */
17464@@ -353,7 +354,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17465 if (!fake_panic) {
17466 if (panic_timeout == 0)
17467 panic_timeout = mca_cfg.panic_timeout;
17468- panic(msg);
17469+ panic("%s", msg);
17470 } else
17471 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
17472 }
17473@@ -683,7 +684,7 @@ static int mce_timed_out(u64 *t)
17474 * might have been modified by someone else.
17475 */
17476 rmb();
17477- if (atomic_read(&mce_paniced))
17478+ if (atomic_read_unchecked(&mce_paniced))
17479 wait_for_panic();
17480 if (!mca_cfg.monarch_timeout)
17481 goto out;
17482@@ -1654,7 +1655,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17483 }
17484
17485 /* Call the installed machine check handler for this CPU setup. */
17486-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17487+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17488 unexpected_machine_check;
17489
17490 /*
17491@@ -1677,7 +1678,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17492 return;
17493 }
17494
17495+ pax_open_kernel();
17496 machine_check_vector = do_machine_check;
17497+ pax_close_kernel();
17498
17499 __mcheck_cpu_init_generic();
17500 __mcheck_cpu_init_vendor(c);
17501@@ -1691,7 +1694,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17502 */
17503
17504 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17505-static int mce_chrdev_open_count; /* #times opened */
17506+static local_t mce_chrdev_open_count; /* #times opened */
17507 static int mce_chrdev_open_exclu; /* already open exclusive? */
17508
17509 static int mce_chrdev_open(struct inode *inode, struct file *file)
17510@@ -1699,7 +1702,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17511 spin_lock(&mce_chrdev_state_lock);
17512
17513 if (mce_chrdev_open_exclu ||
17514- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17515+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17516 spin_unlock(&mce_chrdev_state_lock);
17517
17518 return -EBUSY;
17519@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17520
17521 if (file->f_flags & O_EXCL)
17522 mce_chrdev_open_exclu = 1;
17523- mce_chrdev_open_count++;
17524+ local_inc(&mce_chrdev_open_count);
17525
17526 spin_unlock(&mce_chrdev_state_lock);
17527
17528@@ -1718,7 +1721,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17529 {
17530 spin_lock(&mce_chrdev_state_lock);
17531
17532- mce_chrdev_open_count--;
17533+ local_dec(&mce_chrdev_open_count);
17534 mce_chrdev_open_exclu = 0;
17535
17536 spin_unlock(&mce_chrdev_state_lock);
17537@@ -2364,7 +2367,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17538 return NOTIFY_OK;
17539 }
17540
17541-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17542+static struct notifier_block mce_cpu_notifier = {
17543 .notifier_call = mce_cpu_callback,
17544 };
17545
17546@@ -2374,7 +2377,7 @@ static __init void mce_init_banks(void)
17547
17548 for (i = 0; i < mca_cfg.banks; i++) {
17549 struct mce_bank *b = &mce_banks[i];
17550- struct device_attribute *a = &b->attr;
17551+ device_attribute_no_const *a = &b->attr;
17552
17553 sysfs_attr_init(&a->attr);
17554 a->attr.name = b->attrname;
17555@@ -2442,7 +2445,7 @@ struct dentry *mce_get_debugfs_dir(void)
17556 static void mce_reset(void)
17557 {
17558 cpu_missing = 0;
17559- atomic_set(&mce_fake_paniced, 0);
17560+ atomic_set_unchecked(&mce_fake_paniced, 0);
17561 atomic_set(&mce_executing, 0);
17562 atomic_set(&mce_callin, 0);
17563 atomic_set(&global_nwo, 0);
17564diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17565index 1c044b1..37a2a43 100644
17566--- a/arch/x86/kernel/cpu/mcheck/p5.c
17567+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17568@@ -11,6 +11,7 @@
17569 #include <asm/processor.h>
17570 #include <asm/mce.h>
17571 #include <asm/msr.h>
17572+#include <asm/pgtable.h>
17573
17574 /* By default disabled */
17575 int mce_p5_enabled __read_mostly;
17576@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17577 if (!cpu_has(c, X86_FEATURE_MCE))
17578 return;
17579
17580+ pax_open_kernel();
17581 machine_check_vector = pentium_machine_check;
17582+ pax_close_kernel();
17583 /* Make sure the vector pointer is visible before we enable MCEs: */
17584 wmb();
17585
17586diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17587index 47a1870..8c019a7 100644
17588--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17589+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17590@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17591 return notifier_from_errno(err);
17592 }
17593
17594-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17595+static struct notifier_block thermal_throttle_cpu_notifier =
17596 {
17597 .notifier_call = thermal_throttle_cpu_callback,
17598 };
17599diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17600index e9a701a..35317d6 100644
17601--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17602+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17603@@ -10,6 +10,7 @@
17604 #include <asm/processor.h>
17605 #include <asm/mce.h>
17606 #include <asm/msr.h>
17607+#include <asm/pgtable.h>
17608
17609 /* Machine check handler for WinChip C6: */
17610 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17611@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17612 {
17613 u32 lo, hi;
17614
17615+ pax_open_kernel();
17616 machine_check_vector = winchip_machine_check;
17617+ pax_close_kernel();
17618 /* Make sure the vector pointer is visible before we enable MCEs: */
17619 wmb();
17620
17621diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17622index 726bf96..81f0526 100644
17623--- a/arch/x86/kernel/cpu/mtrr/main.c
17624+++ b/arch/x86/kernel/cpu/mtrr/main.c
17625@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17626 u64 size_or_mask, size_and_mask;
17627 static bool mtrr_aps_delayed_init;
17628
17629-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17630+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17631
17632 const struct mtrr_ops *mtrr_if;
17633
17634diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17635index df5e41f..816c719 100644
17636--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17637+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17638@@ -25,7 +25,7 @@ struct mtrr_ops {
17639 int (*validate_add_page)(unsigned long base, unsigned long size,
17640 unsigned int type);
17641 int (*have_wrcomb)(void);
17642-};
17643+} __do_const;
17644
17645 extern int generic_get_free_region(unsigned long base, unsigned long size,
17646 int replace_reg);
17647diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17648index 1025f3c..824f677 100644
17649--- a/arch/x86/kernel/cpu/perf_event.c
17650+++ b/arch/x86/kernel/cpu/perf_event.c
17651@@ -1311,7 +1311,7 @@ static void __init pmu_check_apic(void)
17652 pr_info("no hardware sampling interrupt available.\n");
17653 }
17654
17655-static struct attribute_group x86_pmu_format_group = {
17656+static attribute_group_no_const x86_pmu_format_group = {
17657 .name = "format",
17658 .attrs = NULL,
17659 };
17660@@ -1410,7 +1410,7 @@ static struct attribute *events_attr[] = {
17661 NULL,
17662 };
17663
17664-static struct attribute_group x86_pmu_events_group = {
17665+static attribute_group_no_const x86_pmu_events_group = {
17666 .name = "events",
17667 .attrs = events_attr,
17668 };
17669@@ -1920,7 +1920,7 @@ static unsigned long get_segment_base(unsigned int segment)
17670 if (idx > GDT_ENTRIES)
17671 return 0;
17672
17673- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17674+ desc = get_cpu_gdt_table(smp_processor_id());
17675 }
17676
17677 return get_desc_base(desc + idx);
17678@@ -2010,7 +2010,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17679 break;
17680
17681 perf_callchain_store(entry, frame.return_address);
17682- fp = frame.next_frame;
17683+ fp = (const void __force_user *)frame.next_frame;
17684 }
17685 }
17686
17687diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17688index a9e2207..d70c83a 100644
17689--- a/arch/x86/kernel/cpu/perf_event_intel.c
17690+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17691@@ -2022,10 +2022,10 @@ __init int intel_pmu_init(void)
17692 * v2 and above have a perf capabilities MSR
17693 */
17694 if (version > 1) {
17695- u64 capabilities;
17696+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17697
17698- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17699- x86_pmu.intel_cap.capabilities = capabilities;
17700+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17701+ x86_pmu.intel_cap.capabilities = capabilities;
17702 }
17703
17704 intel_ds_init();
17705diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17706index 52441a2..f94fae8 100644
17707--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17708+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17709@@ -3093,7 +3093,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17710 static int __init uncore_type_init(struct intel_uncore_type *type)
17711 {
17712 struct intel_uncore_pmu *pmus;
17713- struct attribute_group *attr_group;
17714+ attribute_group_no_const *attr_group;
17715 struct attribute **attrs;
17716 int i, j;
17717
17718@@ -3518,7 +3518,7 @@ static int
17719 return NOTIFY_OK;
17720 }
17721
17722-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17723+static struct notifier_block uncore_cpu_nb = {
17724 .notifier_call = uncore_cpu_notifier,
17725 /*
17726 * to migrate uncore events, our notifier should be executed
17727diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17728index f952891..4722ad4 100644
17729--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17730+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17731@@ -488,7 +488,7 @@ struct intel_uncore_box {
17732 struct uncore_event_desc {
17733 struct kobj_attribute attr;
17734 const char *config;
17735-};
17736+} __do_const;
17737
17738 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17739 { \
17740diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17741index 1e4dbcf..b9a34c2 100644
17742--- a/arch/x86/kernel/cpuid.c
17743+++ b/arch/x86/kernel/cpuid.c
17744@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17745 return notifier_from_errno(err);
17746 }
17747
17748-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17749+static struct notifier_block cpuid_class_cpu_notifier =
17750 {
17751 .notifier_call = cpuid_class_cpu_callback,
17752 };
17753diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17754index 74467fe..18793d5 100644
17755--- a/arch/x86/kernel/crash.c
17756+++ b/arch/x86/kernel/crash.c
17757@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17758 {
17759 #ifdef CONFIG_X86_32
17760 struct pt_regs fixed_regs;
17761-#endif
17762
17763-#ifdef CONFIG_X86_32
17764- if (!user_mode_vm(regs)) {
17765+ if (!user_mode(regs)) {
17766 crash_fixup_ss_esp(&fixed_regs, regs);
17767 regs = &fixed_regs;
17768 }
17769diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
17770index afa64ad..dce67dd 100644
17771--- a/arch/x86/kernel/crash_dump_64.c
17772+++ b/arch/x86/kernel/crash_dump_64.c
17773@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
17774 return -ENOMEM;
17775
17776 if (userbuf) {
17777- if (copy_to_user(buf, vaddr + offset, csize)) {
17778+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
17779 iounmap(vaddr);
17780 return -EFAULT;
17781 }
17782diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17783index 155a13f..1672b9b 100644
17784--- a/arch/x86/kernel/doublefault_32.c
17785+++ b/arch/x86/kernel/doublefault_32.c
17786@@ -11,7 +11,7 @@
17787
17788 #define DOUBLEFAULT_STACKSIZE (1024)
17789 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17790-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17791+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17792
17793 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17794
17795@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17796 unsigned long gdt, tss;
17797
17798 native_store_gdt(&gdt_desc);
17799- gdt = gdt_desc.address;
17800+ gdt = (unsigned long)gdt_desc.address;
17801
17802 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17803
17804@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17805 /* 0x2 bit is always set */
17806 .flags = X86_EFLAGS_SF | 0x2,
17807 .sp = STACK_START,
17808- .es = __USER_DS,
17809+ .es = __KERNEL_DS,
17810 .cs = __KERNEL_CS,
17811 .ss = __KERNEL_DS,
17812- .ds = __USER_DS,
17813+ .ds = __KERNEL_DS,
17814 .fs = __KERNEL_PERCPU,
17815
17816 .__cr3 = __pa_nodebug(swapper_pg_dir),
17817diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17818index deb6421..622e0ed 100644
17819--- a/arch/x86/kernel/dumpstack.c
17820+++ b/arch/x86/kernel/dumpstack.c
17821@@ -2,6 +2,9 @@
17822 * Copyright (C) 1991, 1992 Linus Torvalds
17823 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17824 */
17825+#ifdef CONFIG_GRKERNSEC_HIDESYM
17826+#define __INCLUDED_BY_HIDESYM 1
17827+#endif
17828 #include <linux/kallsyms.h>
17829 #include <linux/kprobes.h>
17830 #include <linux/uaccess.h>
17831@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17832 static void
17833 print_ftrace_graph_addr(unsigned long addr, void *data,
17834 const struct stacktrace_ops *ops,
17835- struct thread_info *tinfo, int *graph)
17836+ struct task_struct *task, int *graph)
17837 {
17838- struct task_struct *task;
17839 unsigned long ret_addr;
17840 int index;
17841
17842 if (addr != (unsigned long)return_to_handler)
17843 return;
17844
17845- task = tinfo->task;
17846 index = task->curr_ret_stack;
17847
17848 if (!task->ret_stack || index < *graph)
17849@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17850 static inline void
17851 print_ftrace_graph_addr(unsigned long addr, void *data,
17852 const struct stacktrace_ops *ops,
17853- struct thread_info *tinfo, int *graph)
17854+ struct task_struct *task, int *graph)
17855 { }
17856 #endif
17857
17858@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17859 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17860 */
17861
17862-static inline int valid_stack_ptr(struct thread_info *tinfo,
17863- void *p, unsigned int size, void *end)
17864+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17865 {
17866- void *t = tinfo;
17867 if (end) {
17868 if (p < end && p >= (end-THREAD_SIZE))
17869 return 1;
17870@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17871 }
17872
17873 unsigned long
17874-print_context_stack(struct thread_info *tinfo,
17875+print_context_stack(struct task_struct *task, void *stack_start,
17876 unsigned long *stack, unsigned long bp,
17877 const struct stacktrace_ops *ops, void *data,
17878 unsigned long *end, int *graph)
17879 {
17880 struct stack_frame *frame = (struct stack_frame *)bp;
17881
17882- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17883+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17884 unsigned long addr;
17885
17886 addr = *stack;
17887@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17888 } else {
17889 ops->address(data, addr, 0);
17890 }
17891- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17892+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17893 }
17894 stack++;
17895 }
17896@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17897 EXPORT_SYMBOL_GPL(print_context_stack);
17898
17899 unsigned long
17900-print_context_stack_bp(struct thread_info *tinfo,
17901+print_context_stack_bp(struct task_struct *task, void *stack_start,
17902 unsigned long *stack, unsigned long bp,
17903 const struct stacktrace_ops *ops, void *data,
17904 unsigned long *end, int *graph)
17905@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17906 struct stack_frame *frame = (struct stack_frame *)bp;
17907 unsigned long *ret_addr = &frame->return_address;
17908
17909- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17910+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17911 unsigned long addr = *ret_addr;
17912
17913 if (!__kernel_text_address(addr))
17914@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17915 ops->address(data, addr, 1);
17916 frame = frame->next_frame;
17917 ret_addr = &frame->return_address;
17918- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17919+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17920 }
17921
17922 return (unsigned long)frame;
17923@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
17924 }
17925 EXPORT_SYMBOL_GPL(oops_begin);
17926
17927+extern void gr_handle_kernel_exploit(void);
17928+
17929 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17930 {
17931 if (regs && kexec_should_crash(current))
17932@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17933 panic("Fatal exception in interrupt");
17934 if (panic_on_oops)
17935 panic("Fatal exception");
17936- do_exit(signr);
17937+
17938+ gr_handle_kernel_exploit();
17939+
17940+ do_group_exit(signr);
17941 }
17942
17943 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17944@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17945 print_modules();
17946 show_regs(regs);
17947 #ifdef CONFIG_X86_32
17948- if (user_mode_vm(regs)) {
17949+ if (user_mode(regs)) {
17950 sp = regs->sp;
17951 ss = regs->ss & 0xffff;
17952 } else {
17953@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17954 unsigned long flags = oops_begin();
17955 int sig = SIGSEGV;
17956
17957- if (!user_mode_vm(regs))
17958+ if (!user_mode(regs))
17959 report_bug(regs->ip, regs);
17960
17961 if (__die(str, regs, err))
17962diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17963index f2a1770..540657f 100644
17964--- a/arch/x86/kernel/dumpstack_32.c
17965+++ b/arch/x86/kernel/dumpstack_32.c
17966@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17967 bp = stack_frame(task, regs);
17968
17969 for (;;) {
17970- struct thread_info *context;
17971+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17972
17973- context = (struct thread_info *)
17974- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17975- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17976+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17977
17978- stack = (unsigned long *)context->previous_esp;
17979- if (!stack)
17980+ if (stack_start == task_stack_page(task))
17981 break;
17982+ stack = *(unsigned long **)stack_start;
17983 if (ops->stack(data, "IRQ") < 0)
17984 break;
17985 touch_nmi_watchdog();
17986@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
17987 int i;
17988
17989 show_regs_print_info(KERN_EMERG);
17990- __show_regs(regs, !user_mode_vm(regs));
17991+ __show_regs(regs, !user_mode(regs));
17992
17993 /*
17994 * When in-kernel, we also print out the stack and code at the
17995 * time of the fault..
17996 */
17997- if (!user_mode_vm(regs)) {
17998+ if (!user_mode(regs)) {
17999 unsigned int code_prologue = code_bytes * 43 / 64;
18000 unsigned int code_len = code_bytes;
18001 unsigned char c;
18002 u8 *ip;
18003+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
18004
18005 pr_emerg("Stack:\n");
18006 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
18007
18008 pr_emerg("Code:");
18009
18010- ip = (u8 *)regs->ip - code_prologue;
18011+ ip = (u8 *)regs->ip - code_prologue + cs_base;
18012 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
18013 /* try starting at IP */
18014- ip = (u8 *)regs->ip;
18015+ ip = (u8 *)regs->ip + cs_base;
18016 code_len = code_len - code_prologue + 1;
18017 }
18018 for (i = 0; i < code_len; i++, ip++) {
18019@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
18020 pr_cont(" Bad EIP value.");
18021 break;
18022 }
18023- if (ip == (u8 *)regs->ip)
18024+ if (ip == (u8 *)regs->ip + cs_base)
18025 pr_cont(" <%02x>", c);
18026 else
18027 pr_cont(" %02x", c);
18028@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
18029 {
18030 unsigned short ud2;
18031
18032+ ip = ktla_ktva(ip);
18033 if (ip < PAGE_OFFSET)
18034 return 0;
18035 if (probe_kernel_address((unsigned short *)ip, ud2))
18036@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
18037
18038 return ud2 == 0x0b0f;
18039 }
18040+
18041+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18042+void pax_check_alloca(unsigned long size)
18043+{
18044+ unsigned long sp = (unsigned long)&sp, stack_left;
18045+
18046+ /* all kernel stacks are of the same size */
18047+ stack_left = sp & (THREAD_SIZE - 1);
18048+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18049+}
18050+EXPORT_SYMBOL(pax_check_alloca);
18051+#endif
18052diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
18053index addb207..99635fa 100644
18054--- a/arch/x86/kernel/dumpstack_64.c
18055+++ b/arch/x86/kernel/dumpstack_64.c
18056@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18057 unsigned long *irq_stack_end =
18058 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
18059 unsigned used = 0;
18060- struct thread_info *tinfo;
18061 int graph = 0;
18062 unsigned long dummy;
18063+ void *stack_start;
18064
18065 if (!task)
18066 task = current;
18067@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18068 * current stack address. If the stacks consist of nested
18069 * exceptions
18070 */
18071- tinfo = task_thread_info(task);
18072 for (;;) {
18073 char *id;
18074 unsigned long *estack_end;
18075+
18076 estack_end = in_exception_stack(cpu, (unsigned long)stack,
18077 &used, &id);
18078
18079@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18080 if (ops->stack(data, id) < 0)
18081 break;
18082
18083- bp = ops->walk_stack(tinfo, stack, bp, ops,
18084+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
18085 data, estack_end, &graph);
18086 ops->stack(data, "<EOE>");
18087 /*
18088@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18089 * second-to-last pointer (index -2 to end) in the
18090 * exception stack:
18091 */
18092+ if ((u16)estack_end[-1] != __KERNEL_DS)
18093+ goto out;
18094 stack = (unsigned long *) estack_end[-2];
18095 continue;
18096 }
18097@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18098 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18099 if (ops->stack(data, "IRQ") < 0)
18100 break;
18101- bp = ops->walk_stack(tinfo, stack, bp,
18102+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18103 ops, data, irq_stack_end, &graph);
18104 /*
18105 * We link to the next stack (which would be
18106@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18107 /*
18108 * This handles the process stack:
18109 */
18110- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18111+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18112+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18113+out:
18114 put_cpu();
18115 }
18116 EXPORT_SYMBOL(dump_trace);
18117@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
18118
18119 return ud2 == 0x0b0f;
18120 }
18121+
18122+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18123+void pax_check_alloca(unsigned long size)
18124+{
18125+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18126+ unsigned cpu, used;
18127+ char *id;
18128+
18129+ /* check the process stack first */
18130+ stack_start = (unsigned long)task_stack_page(current);
18131+ stack_end = stack_start + THREAD_SIZE;
18132+ if (likely(stack_start <= sp && sp < stack_end)) {
18133+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18134+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18135+ return;
18136+ }
18137+
18138+ cpu = get_cpu();
18139+
18140+ /* check the irq stacks */
18141+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18142+ stack_start = stack_end - IRQ_STACK_SIZE;
18143+ if (stack_start <= sp && sp < stack_end) {
18144+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18145+ put_cpu();
18146+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18147+ return;
18148+ }
18149+
18150+ /* check the exception stacks */
18151+ used = 0;
18152+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18153+ stack_start = stack_end - EXCEPTION_STKSZ;
18154+ if (stack_end && stack_start <= sp && sp < stack_end) {
18155+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18156+ put_cpu();
18157+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18158+ return;
18159+ }
18160+
18161+ put_cpu();
18162+
18163+ /* unknown stack */
18164+ BUG();
18165+}
18166+EXPORT_SYMBOL(pax_check_alloca);
18167+#endif
18168diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
18169index d32abea..74daf4f 100644
18170--- a/arch/x86/kernel/e820.c
18171+++ b/arch/x86/kernel/e820.c
18172@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
18173
18174 static void early_panic(char *msg)
18175 {
18176- early_printk(msg);
18177- panic(msg);
18178+ early_printk("%s", msg);
18179+ panic("%s", msg);
18180 }
18181
18182 static int userdef __initdata;
18183diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18184index d15f575..d692043 100644
18185--- a/arch/x86/kernel/early_printk.c
18186+++ b/arch/x86/kernel/early_printk.c
18187@@ -7,6 +7,7 @@
18188 #include <linux/pci_regs.h>
18189 #include <linux/pci_ids.h>
18190 #include <linux/errno.h>
18191+#include <linux/sched.h>
18192 #include <asm/io.h>
18193 #include <asm/processor.h>
18194 #include <asm/fcntl.h>
18195diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18196index 8f3e2de..caecc4e 100644
18197--- a/arch/x86/kernel/entry_32.S
18198+++ b/arch/x86/kernel/entry_32.S
18199@@ -177,13 +177,153 @@
18200 /*CFI_REL_OFFSET gs, PT_GS*/
18201 .endm
18202 .macro SET_KERNEL_GS reg
18203+
18204+#ifdef CONFIG_CC_STACKPROTECTOR
18205 movl $(__KERNEL_STACK_CANARY), \reg
18206+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18207+ movl $(__USER_DS), \reg
18208+#else
18209+ xorl \reg, \reg
18210+#endif
18211+
18212 movl \reg, %gs
18213 .endm
18214
18215 #endif /* CONFIG_X86_32_LAZY_GS */
18216
18217-.macro SAVE_ALL
18218+.macro pax_enter_kernel
18219+#ifdef CONFIG_PAX_KERNEXEC
18220+ call pax_enter_kernel
18221+#endif
18222+.endm
18223+
18224+.macro pax_exit_kernel
18225+#ifdef CONFIG_PAX_KERNEXEC
18226+ call pax_exit_kernel
18227+#endif
18228+.endm
18229+
18230+#ifdef CONFIG_PAX_KERNEXEC
18231+ENTRY(pax_enter_kernel)
18232+#ifdef CONFIG_PARAVIRT
18233+ pushl %eax
18234+ pushl %ecx
18235+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18236+ mov %eax, %esi
18237+#else
18238+ mov %cr0, %esi
18239+#endif
18240+ bts $16, %esi
18241+ jnc 1f
18242+ mov %cs, %esi
18243+ cmp $__KERNEL_CS, %esi
18244+ jz 3f
18245+ ljmp $__KERNEL_CS, $3f
18246+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18247+2:
18248+#ifdef CONFIG_PARAVIRT
18249+ mov %esi, %eax
18250+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18251+#else
18252+ mov %esi, %cr0
18253+#endif
18254+3:
18255+#ifdef CONFIG_PARAVIRT
18256+ popl %ecx
18257+ popl %eax
18258+#endif
18259+ ret
18260+ENDPROC(pax_enter_kernel)
18261+
18262+ENTRY(pax_exit_kernel)
18263+#ifdef CONFIG_PARAVIRT
18264+ pushl %eax
18265+ pushl %ecx
18266+#endif
18267+ mov %cs, %esi
18268+ cmp $__KERNEXEC_KERNEL_CS, %esi
18269+ jnz 2f
18270+#ifdef CONFIG_PARAVIRT
18271+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18272+ mov %eax, %esi
18273+#else
18274+ mov %cr0, %esi
18275+#endif
18276+ btr $16, %esi
18277+ ljmp $__KERNEL_CS, $1f
18278+1:
18279+#ifdef CONFIG_PARAVIRT
18280+ mov %esi, %eax
18281+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18282+#else
18283+ mov %esi, %cr0
18284+#endif
18285+2:
18286+#ifdef CONFIG_PARAVIRT
18287+ popl %ecx
18288+ popl %eax
18289+#endif
18290+ ret
18291+ENDPROC(pax_exit_kernel)
18292+#endif
18293+
18294+ .macro pax_erase_kstack
18295+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18296+ call pax_erase_kstack
18297+#endif
18298+ .endm
18299+
18300+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18301+/*
18302+ * ebp: thread_info
18303+ */
18304+ENTRY(pax_erase_kstack)
18305+ pushl %edi
18306+ pushl %ecx
18307+ pushl %eax
18308+
18309+ mov TI_lowest_stack(%ebp), %edi
18310+ mov $-0xBEEF, %eax
18311+ std
18312+
18313+1: mov %edi, %ecx
18314+ and $THREAD_SIZE_asm - 1, %ecx
18315+ shr $2, %ecx
18316+ repne scasl
18317+ jecxz 2f
18318+
18319+ cmp $2*16, %ecx
18320+ jc 2f
18321+
18322+ mov $2*16, %ecx
18323+ repe scasl
18324+ jecxz 2f
18325+ jne 1b
18326+
18327+2: cld
18328+ mov %esp, %ecx
18329+ sub %edi, %ecx
18330+
18331+ cmp $THREAD_SIZE_asm, %ecx
18332+ jb 3f
18333+ ud2
18334+3:
18335+
18336+ shr $2, %ecx
18337+ rep stosl
18338+
18339+ mov TI_task_thread_sp0(%ebp), %edi
18340+ sub $128, %edi
18341+ mov %edi, TI_lowest_stack(%ebp)
18342+
18343+ popl %eax
18344+ popl %ecx
18345+ popl %edi
18346+ ret
18347+ENDPROC(pax_erase_kstack)
18348+#endif
18349+
18350+.macro __SAVE_ALL _DS
18351 cld
18352 PUSH_GS
18353 pushl_cfi %fs
18354@@ -206,7 +346,7 @@
18355 CFI_REL_OFFSET ecx, 0
18356 pushl_cfi %ebx
18357 CFI_REL_OFFSET ebx, 0
18358- movl $(__USER_DS), %edx
18359+ movl $\_DS, %edx
18360 movl %edx, %ds
18361 movl %edx, %es
18362 movl $(__KERNEL_PERCPU), %edx
18363@@ -214,6 +354,15 @@
18364 SET_KERNEL_GS %edx
18365 .endm
18366
18367+.macro SAVE_ALL
18368+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18369+ __SAVE_ALL __KERNEL_DS
18370+ pax_enter_kernel
18371+#else
18372+ __SAVE_ALL __USER_DS
18373+#endif
18374+.endm
18375+
18376 .macro RESTORE_INT_REGS
18377 popl_cfi %ebx
18378 CFI_RESTORE ebx
18379@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18380 popfl_cfi
18381 jmp syscall_exit
18382 CFI_ENDPROC
18383-END(ret_from_fork)
18384+ENDPROC(ret_from_fork)
18385
18386 ENTRY(ret_from_kernel_thread)
18387 CFI_STARTPROC
18388@@ -344,7 +493,15 @@ ret_from_intr:
18389 andl $SEGMENT_RPL_MASK, %eax
18390 #endif
18391 cmpl $USER_RPL, %eax
18392+
18393+#ifdef CONFIG_PAX_KERNEXEC
18394+ jae resume_userspace
18395+
18396+ pax_exit_kernel
18397+ jmp resume_kernel
18398+#else
18399 jb resume_kernel # not returning to v8086 or userspace
18400+#endif
18401
18402 ENTRY(resume_userspace)
18403 LOCKDEP_SYS_EXIT
18404@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18405 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18406 # int/exception return?
18407 jne work_pending
18408- jmp restore_all
18409-END(ret_from_exception)
18410+ jmp restore_all_pax
18411+ENDPROC(ret_from_exception)
18412
18413 #ifdef CONFIG_PREEMPT
18414 ENTRY(resume_kernel)
18415@@ -372,7 +529,7 @@ need_resched:
18416 jz restore_all
18417 call preempt_schedule_irq
18418 jmp need_resched
18419-END(resume_kernel)
18420+ENDPROC(resume_kernel)
18421 #endif
18422 CFI_ENDPROC
18423 /*
18424@@ -406,30 +563,45 @@ sysenter_past_esp:
18425 /*CFI_REL_OFFSET cs, 0*/
18426 /*
18427 * Push current_thread_info()->sysenter_return to the stack.
18428- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18429- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18430 */
18431- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18432+ pushl_cfi $0
18433 CFI_REL_OFFSET eip, 0
18434
18435 pushl_cfi %eax
18436 SAVE_ALL
18437+ GET_THREAD_INFO(%ebp)
18438+ movl TI_sysenter_return(%ebp),%ebp
18439+ movl %ebp,PT_EIP(%esp)
18440 ENABLE_INTERRUPTS(CLBR_NONE)
18441
18442 /*
18443 * Load the potential sixth argument from user stack.
18444 * Careful about security.
18445 */
18446+ movl PT_OLDESP(%esp),%ebp
18447+
18448+#ifdef CONFIG_PAX_MEMORY_UDEREF
18449+ mov PT_OLDSS(%esp),%ds
18450+1: movl %ds:(%ebp),%ebp
18451+ push %ss
18452+ pop %ds
18453+#else
18454 cmpl $__PAGE_OFFSET-3,%ebp
18455 jae syscall_fault
18456 ASM_STAC
18457 1: movl (%ebp),%ebp
18458 ASM_CLAC
18459+#endif
18460+
18461 movl %ebp,PT_EBP(%esp)
18462 _ASM_EXTABLE(1b,syscall_fault)
18463
18464 GET_THREAD_INFO(%ebp)
18465
18466+#ifdef CONFIG_PAX_RANDKSTACK
18467+ pax_erase_kstack
18468+#endif
18469+
18470 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18471 jnz sysenter_audit
18472 sysenter_do_call:
18473@@ -444,12 +616,24 @@ sysenter_do_call:
18474 testl $_TIF_ALLWORK_MASK, %ecx
18475 jne sysexit_audit
18476 sysenter_exit:
18477+
18478+#ifdef CONFIG_PAX_RANDKSTACK
18479+ pushl_cfi %eax
18480+ movl %esp, %eax
18481+ call pax_randomize_kstack
18482+ popl_cfi %eax
18483+#endif
18484+
18485+ pax_erase_kstack
18486+
18487 /* if something modifies registers it must also disable sysexit */
18488 movl PT_EIP(%esp), %edx
18489 movl PT_OLDESP(%esp), %ecx
18490 xorl %ebp,%ebp
18491 TRACE_IRQS_ON
18492 1: mov PT_FS(%esp), %fs
18493+2: mov PT_DS(%esp), %ds
18494+3: mov PT_ES(%esp), %es
18495 PTGS_TO_GS
18496 ENABLE_INTERRUPTS_SYSEXIT
18497
18498@@ -466,6 +650,9 @@ sysenter_audit:
18499 movl %eax,%edx /* 2nd arg: syscall number */
18500 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18501 call __audit_syscall_entry
18502+
18503+ pax_erase_kstack
18504+
18505 pushl_cfi %ebx
18506 movl PT_EAX(%esp),%eax /* reload syscall number */
18507 jmp sysenter_do_call
18508@@ -491,10 +678,16 @@ sysexit_audit:
18509
18510 CFI_ENDPROC
18511 .pushsection .fixup,"ax"
18512-2: movl $0,PT_FS(%esp)
18513+4: movl $0,PT_FS(%esp)
18514+ jmp 1b
18515+5: movl $0,PT_DS(%esp)
18516+ jmp 1b
18517+6: movl $0,PT_ES(%esp)
18518 jmp 1b
18519 .popsection
18520- _ASM_EXTABLE(1b,2b)
18521+ _ASM_EXTABLE(1b,4b)
18522+ _ASM_EXTABLE(2b,5b)
18523+ _ASM_EXTABLE(3b,6b)
18524 PTGS_TO_GS_EX
18525 ENDPROC(ia32_sysenter_target)
18526
18527@@ -509,6 +702,11 @@ ENTRY(system_call)
18528 pushl_cfi %eax # save orig_eax
18529 SAVE_ALL
18530 GET_THREAD_INFO(%ebp)
18531+
18532+#ifdef CONFIG_PAX_RANDKSTACK
18533+ pax_erase_kstack
18534+#endif
18535+
18536 # system call tracing in operation / emulation
18537 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18538 jnz syscall_trace_entry
18539@@ -527,6 +725,15 @@ syscall_exit:
18540 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18541 jne syscall_exit_work
18542
18543+restore_all_pax:
18544+
18545+#ifdef CONFIG_PAX_RANDKSTACK
18546+ movl %esp, %eax
18547+ call pax_randomize_kstack
18548+#endif
18549+
18550+ pax_erase_kstack
18551+
18552 restore_all:
18553 TRACE_IRQS_IRET
18554 restore_all_notrace:
18555@@ -583,14 +790,34 @@ ldt_ss:
18556 * compensating for the offset by changing to the ESPFIX segment with
18557 * a base address that matches for the difference.
18558 */
18559-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18560+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18561 mov %esp, %edx /* load kernel esp */
18562 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18563 mov %dx, %ax /* eax: new kernel esp */
18564 sub %eax, %edx /* offset (low word is 0) */
18565+#ifdef CONFIG_SMP
18566+ movl PER_CPU_VAR(cpu_number), %ebx
18567+ shll $PAGE_SHIFT_asm, %ebx
18568+ addl $cpu_gdt_table, %ebx
18569+#else
18570+ movl $cpu_gdt_table, %ebx
18571+#endif
18572 shr $16, %edx
18573- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18574- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18575+
18576+#ifdef CONFIG_PAX_KERNEXEC
18577+ mov %cr0, %esi
18578+ btr $16, %esi
18579+ mov %esi, %cr0
18580+#endif
18581+
18582+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18583+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18584+
18585+#ifdef CONFIG_PAX_KERNEXEC
18586+ bts $16, %esi
18587+ mov %esi, %cr0
18588+#endif
18589+
18590 pushl_cfi $__ESPFIX_SS
18591 pushl_cfi %eax /* new kernel esp */
18592 /* Disable interrupts, but do not irqtrace this section: we
18593@@ -619,20 +846,18 @@ work_resched:
18594 movl TI_flags(%ebp), %ecx
18595 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18596 # than syscall tracing?
18597- jz restore_all
18598+ jz restore_all_pax
18599 testb $_TIF_NEED_RESCHED, %cl
18600 jnz work_resched
18601
18602 work_notifysig: # deal with pending signals and
18603 # notify-resume requests
18604+ movl %esp, %eax
18605 #ifdef CONFIG_VM86
18606 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18607- movl %esp, %eax
18608 jne work_notifysig_v86 # returning to kernel-space or
18609 # vm86-space
18610 1:
18611-#else
18612- movl %esp, %eax
18613 #endif
18614 TRACE_IRQS_ON
18615 ENABLE_INTERRUPTS(CLBR_NONE)
18616@@ -653,7 +878,7 @@ work_notifysig_v86:
18617 movl %eax, %esp
18618 jmp 1b
18619 #endif
18620-END(work_pending)
18621+ENDPROC(work_pending)
18622
18623 # perform syscall exit tracing
18624 ALIGN
18625@@ -661,11 +886,14 @@ syscall_trace_entry:
18626 movl $-ENOSYS,PT_EAX(%esp)
18627 movl %esp, %eax
18628 call syscall_trace_enter
18629+
18630+ pax_erase_kstack
18631+
18632 /* What it returned is what we'll actually use. */
18633 cmpl $(NR_syscalls), %eax
18634 jnae syscall_call
18635 jmp syscall_exit
18636-END(syscall_trace_entry)
18637+ENDPROC(syscall_trace_entry)
18638
18639 # perform syscall exit tracing
18640 ALIGN
18641@@ -678,21 +906,25 @@ syscall_exit_work:
18642 movl %esp, %eax
18643 call syscall_trace_leave
18644 jmp resume_userspace
18645-END(syscall_exit_work)
18646+ENDPROC(syscall_exit_work)
18647 CFI_ENDPROC
18648
18649 RING0_INT_FRAME # can't unwind into user space anyway
18650 syscall_fault:
18651+#ifdef CONFIG_PAX_MEMORY_UDEREF
18652+ push %ss
18653+ pop %ds
18654+#endif
18655 ASM_CLAC
18656 GET_THREAD_INFO(%ebp)
18657 movl $-EFAULT,PT_EAX(%esp)
18658 jmp resume_userspace
18659-END(syscall_fault)
18660+ENDPROC(syscall_fault)
18661
18662 syscall_badsys:
18663 movl $-ENOSYS,PT_EAX(%esp)
18664 jmp resume_userspace
18665-END(syscall_badsys)
18666+ENDPROC(syscall_badsys)
18667 CFI_ENDPROC
18668 /*
18669 * End of kprobes section
18670@@ -708,8 +940,15 @@ END(syscall_badsys)
18671 * normal stack and adjusts ESP with the matching offset.
18672 */
18673 /* fixup the stack */
18674- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18675- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18676+#ifdef CONFIG_SMP
18677+ movl PER_CPU_VAR(cpu_number), %ebx
18678+ shll $PAGE_SHIFT_asm, %ebx
18679+ addl $cpu_gdt_table, %ebx
18680+#else
18681+ movl $cpu_gdt_table, %ebx
18682+#endif
18683+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18684+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18685 shl $16, %eax
18686 addl %esp, %eax /* the adjusted stack pointer */
18687 pushl_cfi $__KERNEL_DS
18688@@ -762,7 +1001,7 @@ vector=vector+1
18689 .endr
18690 2: jmp common_interrupt
18691 .endr
18692-END(irq_entries_start)
18693+ENDPROC(irq_entries_start)
18694
18695 .previous
18696 END(interrupt)
18697@@ -813,7 +1052,7 @@ ENTRY(coprocessor_error)
18698 pushl_cfi $do_coprocessor_error
18699 jmp error_code
18700 CFI_ENDPROC
18701-END(coprocessor_error)
18702+ENDPROC(coprocessor_error)
18703
18704 ENTRY(simd_coprocessor_error)
18705 RING0_INT_FRAME
18706@@ -835,7 +1074,7 @@ ENTRY(simd_coprocessor_error)
18707 #endif
18708 jmp error_code
18709 CFI_ENDPROC
18710-END(simd_coprocessor_error)
18711+ENDPROC(simd_coprocessor_error)
18712
18713 ENTRY(device_not_available)
18714 RING0_INT_FRAME
18715@@ -844,18 +1083,18 @@ ENTRY(device_not_available)
18716 pushl_cfi $do_device_not_available
18717 jmp error_code
18718 CFI_ENDPROC
18719-END(device_not_available)
18720+ENDPROC(device_not_available)
18721
18722 #ifdef CONFIG_PARAVIRT
18723 ENTRY(native_iret)
18724 iret
18725 _ASM_EXTABLE(native_iret, iret_exc)
18726-END(native_iret)
18727+ENDPROC(native_iret)
18728
18729 ENTRY(native_irq_enable_sysexit)
18730 sti
18731 sysexit
18732-END(native_irq_enable_sysexit)
18733+ENDPROC(native_irq_enable_sysexit)
18734 #endif
18735
18736 ENTRY(overflow)
18737@@ -865,7 +1104,7 @@ ENTRY(overflow)
18738 pushl_cfi $do_overflow
18739 jmp error_code
18740 CFI_ENDPROC
18741-END(overflow)
18742+ENDPROC(overflow)
18743
18744 ENTRY(bounds)
18745 RING0_INT_FRAME
18746@@ -874,7 +1113,7 @@ ENTRY(bounds)
18747 pushl_cfi $do_bounds
18748 jmp error_code
18749 CFI_ENDPROC
18750-END(bounds)
18751+ENDPROC(bounds)
18752
18753 ENTRY(invalid_op)
18754 RING0_INT_FRAME
18755@@ -883,7 +1122,7 @@ ENTRY(invalid_op)
18756 pushl_cfi $do_invalid_op
18757 jmp error_code
18758 CFI_ENDPROC
18759-END(invalid_op)
18760+ENDPROC(invalid_op)
18761
18762 ENTRY(coprocessor_segment_overrun)
18763 RING0_INT_FRAME
18764@@ -892,7 +1131,7 @@ ENTRY(coprocessor_segment_overrun)
18765 pushl_cfi $do_coprocessor_segment_overrun
18766 jmp error_code
18767 CFI_ENDPROC
18768-END(coprocessor_segment_overrun)
18769+ENDPROC(coprocessor_segment_overrun)
18770
18771 ENTRY(invalid_TSS)
18772 RING0_EC_FRAME
18773@@ -900,7 +1139,7 @@ ENTRY(invalid_TSS)
18774 pushl_cfi $do_invalid_TSS
18775 jmp error_code
18776 CFI_ENDPROC
18777-END(invalid_TSS)
18778+ENDPROC(invalid_TSS)
18779
18780 ENTRY(segment_not_present)
18781 RING0_EC_FRAME
18782@@ -908,7 +1147,7 @@ ENTRY(segment_not_present)
18783 pushl_cfi $do_segment_not_present
18784 jmp error_code
18785 CFI_ENDPROC
18786-END(segment_not_present)
18787+ENDPROC(segment_not_present)
18788
18789 ENTRY(stack_segment)
18790 RING0_EC_FRAME
18791@@ -916,7 +1155,7 @@ ENTRY(stack_segment)
18792 pushl_cfi $do_stack_segment
18793 jmp error_code
18794 CFI_ENDPROC
18795-END(stack_segment)
18796+ENDPROC(stack_segment)
18797
18798 ENTRY(alignment_check)
18799 RING0_EC_FRAME
18800@@ -924,7 +1163,7 @@ ENTRY(alignment_check)
18801 pushl_cfi $do_alignment_check
18802 jmp error_code
18803 CFI_ENDPROC
18804-END(alignment_check)
18805+ENDPROC(alignment_check)
18806
18807 ENTRY(divide_error)
18808 RING0_INT_FRAME
18809@@ -933,7 +1172,7 @@ ENTRY(divide_error)
18810 pushl_cfi $do_divide_error
18811 jmp error_code
18812 CFI_ENDPROC
18813-END(divide_error)
18814+ENDPROC(divide_error)
18815
18816 #ifdef CONFIG_X86_MCE
18817 ENTRY(machine_check)
18818@@ -943,7 +1182,7 @@ ENTRY(machine_check)
18819 pushl_cfi machine_check_vector
18820 jmp error_code
18821 CFI_ENDPROC
18822-END(machine_check)
18823+ENDPROC(machine_check)
18824 #endif
18825
18826 ENTRY(spurious_interrupt_bug)
18827@@ -953,7 +1192,7 @@ ENTRY(spurious_interrupt_bug)
18828 pushl_cfi $do_spurious_interrupt_bug
18829 jmp error_code
18830 CFI_ENDPROC
18831-END(spurious_interrupt_bug)
18832+ENDPROC(spurious_interrupt_bug)
18833 /*
18834 * End of kprobes section
18835 */
18836@@ -1063,7 +1302,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
18837
18838 ENTRY(mcount)
18839 ret
18840-END(mcount)
18841+ENDPROC(mcount)
18842
18843 ENTRY(ftrace_caller)
18844 cmpl $0, function_trace_stop
18845@@ -1096,7 +1335,7 @@ ftrace_graph_call:
18846 .globl ftrace_stub
18847 ftrace_stub:
18848 ret
18849-END(ftrace_caller)
18850+ENDPROC(ftrace_caller)
18851
18852 ENTRY(ftrace_regs_caller)
18853 pushf /* push flags before compare (in cs location) */
18854@@ -1197,7 +1436,7 @@ trace:
18855 popl %ecx
18856 popl %eax
18857 jmp ftrace_stub
18858-END(mcount)
18859+ENDPROC(mcount)
18860 #endif /* CONFIG_DYNAMIC_FTRACE */
18861 #endif /* CONFIG_FUNCTION_TRACER */
18862
18863@@ -1215,7 +1454,7 @@ ENTRY(ftrace_graph_caller)
18864 popl %ecx
18865 popl %eax
18866 ret
18867-END(ftrace_graph_caller)
18868+ENDPROC(ftrace_graph_caller)
18869
18870 .globl return_to_handler
18871 return_to_handler:
18872@@ -1271,15 +1510,18 @@ error_code:
18873 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18874 REG_TO_PTGS %ecx
18875 SET_KERNEL_GS %ecx
18876- movl $(__USER_DS), %ecx
18877+ movl $(__KERNEL_DS), %ecx
18878 movl %ecx, %ds
18879 movl %ecx, %es
18880+
18881+ pax_enter_kernel
18882+
18883 TRACE_IRQS_OFF
18884 movl %esp,%eax # pt_regs pointer
18885 call *%edi
18886 jmp ret_from_exception
18887 CFI_ENDPROC
18888-END(page_fault)
18889+ENDPROC(page_fault)
18890
18891 /*
18892 * Debug traps and NMI can happen at the one SYSENTER instruction
18893@@ -1322,7 +1564,7 @@ debug_stack_correct:
18894 call do_debug
18895 jmp ret_from_exception
18896 CFI_ENDPROC
18897-END(debug)
18898+ENDPROC(debug)
18899
18900 /*
18901 * NMI is doubly nasty. It can happen _while_ we're handling
18902@@ -1360,6 +1602,9 @@ nmi_stack_correct:
18903 xorl %edx,%edx # zero error code
18904 movl %esp,%eax # pt_regs pointer
18905 call do_nmi
18906+
18907+ pax_exit_kernel
18908+
18909 jmp restore_all_notrace
18910 CFI_ENDPROC
18911
18912@@ -1396,12 +1641,15 @@ nmi_espfix_stack:
18913 FIXUP_ESPFIX_STACK # %eax == %esp
18914 xorl %edx,%edx # zero error code
18915 call do_nmi
18916+
18917+ pax_exit_kernel
18918+
18919 RESTORE_REGS
18920 lss 12+4(%esp), %esp # back to espfix stack
18921 CFI_ADJUST_CFA_OFFSET -24
18922 jmp irq_return
18923 CFI_ENDPROC
18924-END(nmi)
18925+ENDPROC(nmi)
18926
18927 ENTRY(int3)
18928 RING0_INT_FRAME
18929@@ -1414,14 +1662,14 @@ ENTRY(int3)
18930 call do_int3
18931 jmp ret_from_exception
18932 CFI_ENDPROC
18933-END(int3)
18934+ENDPROC(int3)
18935
18936 ENTRY(general_protection)
18937 RING0_EC_FRAME
18938 pushl_cfi $do_general_protection
18939 jmp error_code
18940 CFI_ENDPROC
18941-END(general_protection)
18942+ENDPROC(general_protection)
18943
18944 #ifdef CONFIG_KVM_GUEST
18945 ENTRY(async_page_fault)
18946@@ -1430,7 +1678,7 @@ ENTRY(async_page_fault)
18947 pushl_cfi $do_async_page_fault
18948 jmp error_code
18949 CFI_ENDPROC
18950-END(async_page_fault)
18951+ENDPROC(async_page_fault)
18952 #endif
18953
18954 /*
18955diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18956index 7272089..6204f9c5 100644
18957--- a/arch/x86/kernel/entry_64.S
18958+++ b/arch/x86/kernel/entry_64.S
18959@@ -59,6 +59,8 @@
18960 #include <asm/context_tracking.h>
18961 #include <asm/smap.h>
18962 #include <linux/err.h>
18963+#include <asm/pgtable.h>
18964+#include <asm/alternative-asm.h>
18965
18966 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18967 #include <linux/elf-em.h>
18968@@ -80,8 +82,9 @@
18969 #ifdef CONFIG_DYNAMIC_FTRACE
18970
18971 ENTRY(function_hook)
18972+ pax_force_retaddr
18973 retq
18974-END(function_hook)
18975+ENDPROC(function_hook)
18976
18977 /* skip is set if stack has been adjusted */
18978 .macro ftrace_caller_setup skip=0
18979@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18980 #endif
18981
18982 GLOBAL(ftrace_stub)
18983+ pax_force_retaddr
18984 retq
18985-END(ftrace_caller)
18986+ENDPROC(ftrace_caller)
18987
18988 ENTRY(ftrace_regs_caller)
18989 /* Save the current flags before compare (in SS location)*/
18990@@ -191,7 +195,7 @@ ftrace_restore_flags:
18991 popfq
18992 jmp ftrace_stub
18993
18994-END(ftrace_regs_caller)
18995+ENDPROC(ftrace_regs_caller)
18996
18997
18998 #else /* ! CONFIG_DYNAMIC_FTRACE */
18999@@ -212,6 +216,7 @@ ENTRY(function_hook)
19000 #endif
19001
19002 GLOBAL(ftrace_stub)
19003+ pax_force_retaddr
19004 retq
19005
19006 trace:
19007@@ -225,12 +230,13 @@ trace:
19008 #endif
19009 subq $MCOUNT_INSN_SIZE, %rdi
19010
19011+ pax_force_fptr ftrace_trace_function
19012 call *ftrace_trace_function
19013
19014 MCOUNT_RESTORE_FRAME
19015
19016 jmp ftrace_stub
19017-END(function_hook)
19018+ENDPROC(function_hook)
19019 #endif /* CONFIG_DYNAMIC_FTRACE */
19020 #endif /* CONFIG_FUNCTION_TRACER */
19021
19022@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
19023
19024 MCOUNT_RESTORE_FRAME
19025
19026+ pax_force_retaddr
19027 retq
19028-END(ftrace_graph_caller)
19029+ENDPROC(ftrace_graph_caller)
19030
19031 GLOBAL(return_to_handler)
19032 subq $24, %rsp
19033@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
19034 movq 8(%rsp), %rdx
19035 movq (%rsp), %rax
19036 addq $24, %rsp
19037+ pax_force_fptr %rdi
19038 jmp *%rdi
19039+ENDPROC(return_to_handler)
19040 #endif
19041
19042
19043@@ -284,6 +293,309 @@ ENTRY(native_usergs_sysret64)
19044 ENDPROC(native_usergs_sysret64)
19045 #endif /* CONFIG_PARAVIRT */
19046
19047+ .macro ljmpq sel, off
19048+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
19049+ .byte 0x48; ljmp *1234f(%rip)
19050+ .pushsection .rodata
19051+ .align 16
19052+ 1234: .quad \off; .word \sel
19053+ .popsection
19054+#else
19055+ pushq $\sel
19056+ pushq $\off
19057+ lretq
19058+#endif
19059+ .endm
19060+
19061+ .macro pax_enter_kernel
19062+ pax_set_fptr_mask
19063+#ifdef CONFIG_PAX_KERNEXEC
19064+ call pax_enter_kernel
19065+#endif
19066+ .endm
19067+
19068+ .macro pax_exit_kernel
19069+#ifdef CONFIG_PAX_KERNEXEC
19070+ call pax_exit_kernel
19071+#endif
19072+ .endm
19073+
19074+#ifdef CONFIG_PAX_KERNEXEC
19075+ENTRY(pax_enter_kernel)
19076+ pushq %rdi
19077+
19078+#ifdef CONFIG_PARAVIRT
19079+ PV_SAVE_REGS(CLBR_RDI)
19080+#endif
19081+
19082+ GET_CR0_INTO_RDI
19083+ bts $16,%rdi
19084+ jnc 3f
19085+ mov %cs,%edi
19086+ cmp $__KERNEL_CS,%edi
19087+ jnz 2f
19088+1:
19089+
19090+#ifdef CONFIG_PARAVIRT
19091+ PV_RESTORE_REGS(CLBR_RDI)
19092+#endif
19093+
19094+ popq %rdi
19095+ pax_force_retaddr
19096+ retq
19097+
19098+2: ljmpq __KERNEL_CS,1b
19099+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19100+4: SET_RDI_INTO_CR0
19101+ jmp 1b
19102+ENDPROC(pax_enter_kernel)
19103+
19104+ENTRY(pax_exit_kernel)
19105+ pushq %rdi
19106+
19107+#ifdef CONFIG_PARAVIRT
19108+ PV_SAVE_REGS(CLBR_RDI)
19109+#endif
19110+
19111+ mov %cs,%rdi
19112+ cmp $__KERNEXEC_KERNEL_CS,%edi
19113+ jz 2f
19114+ GET_CR0_INTO_RDI
19115+ bts $16,%rdi
19116+ jnc 4f
19117+1:
19118+
19119+#ifdef CONFIG_PARAVIRT
19120+ PV_RESTORE_REGS(CLBR_RDI);
19121+#endif
19122+
19123+ popq %rdi
19124+ pax_force_retaddr
19125+ retq
19126+
19127+2: GET_CR0_INTO_RDI
19128+ btr $16,%rdi
19129+ jnc 4f
19130+ ljmpq __KERNEL_CS,3f
19131+3: SET_RDI_INTO_CR0
19132+ jmp 1b
19133+4: ud2
19134+ jmp 4b
19135+ENDPROC(pax_exit_kernel)
19136+#endif
19137+
19138+ .macro pax_enter_kernel_user
19139+ pax_set_fptr_mask
19140+#ifdef CONFIG_PAX_MEMORY_UDEREF
19141+ call pax_enter_kernel_user
19142+#endif
19143+ .endm
19144+
19145+ .macro pax_exit_kernel_user
19146+#ifdef CONFIG_PAX_MEMORY_UDEREF
19147+ call pax_exit_kernel_user
19148+#endif
19149+#ifdef CONFIG_PAX_RANDKSTACK
19150+ pushq %rax
19151+ pushq %r11
19152+ call pax_randomize_kstack
19153+ popq %r11
19154+ popq %rax
19155+#endif
19156+ .endm
19157+
19158+#ifdef CONFIG_PAX_MEMORY_UDEREF
19159+ENTRY(pax_enter_kernel_user)
19160+ pushq %rdi
19161+ pushq %rbx
19162+
19163+#ifdef CONFIG_PARAVIRT
19164+ PV_SAVE_REGS(CLBR_RDI)
19165+#endif
19166+
19167+ GET_CR3_INTO_RDI
19168+ mov %rdi,%rbx
19169+ add $__START_KERNEL_map,%rbx
19170+ sub phys_base(%rip),%rbx
19171+
19172+#ifdef CONFIG_PARAVIRT
19173+ cmpl $0, pv_info+PARAVIRT_enabled
19174+ jz 1f
19175+ pushq %rdi
19176+ i = 0
19177+ .rept USER_PGD_PTRS
19178+ mov i*8(%rbx),%rsi
19179+ mov $0,%sil
19180+ lea i*8(%rbx),%rdi
19181+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19182+ i = i + 1
19183+ .endr
19184+ popq %rdi
19185+ jmp 2f
19186+1:
19187+#endif
19188+
19189+ i = 0
19190+ .rept USER_PGD_PTRS
19191+ movb $0,i*8(%rbx)
19192+ i = i + 1
19193+ .endr
19194+
19195+#ifdef CONFIG_PARAVIRT
19196+2:
19197+#endif
19198+ SET_RDI_INTO_CR3
19199+
19200+#ifdef CONFIG_PAX_KERNEXEC
19201+ GET_CR0_INTO_RDI
19202+ bts $16,%rdi
19203+ SET_RDI_INTO_CR0
19204+#endif
19205+
19206+#ifdef CONFIG_PARAVIRT
19207+ PV_RESTORE_REGS(CLBR_RDI)
19208+#endif
19209+
19210+ popq %rbx
19211+ popq %rdi
19212+ pax_force_retaddr
19213+ retq
19214+ENDPROC(pax_enter_kernel_user)
19215+
19216+ENTRY(pax_exit_kernel_user)
19217+ pushq %rdi
19218+ pushq %rbx
19219+
19220+#ifdef CONFIG_PARAVIRT
19221+ PV_SAVE_REGS(CLBR_RDI)
19222+#endif
19223+
19224+#ifdef CONFIG_PAX_KERNEXEC
19225+ GET_CR0_INTO_RDI
19226+ btr $16,%rdi
19227+ jnc 3f
19228+ SET_RDI_INTO_CR0
19229+#endif
19230+
19231+ GET_CR3_INTO_RDI
19232+ mov %rdi,%rbx
19233+ add $__START_KERNEL_map,%rbx
19234+ sub phys_base(%rip),%rbx
19235+
19236+#ifdef CONFIG_PARAVIRT
19237+ cmpl $0, pv_info+PARAVIRT_enabled
19238+ jz 1f
19239+ i = 0
19240+ .rept USER_PGD_PTRS
19241+ mov i*8(%rbx),%rsi
19242+ mov $0x67,%sil
19243+ lea i*8(%rbx),%rdi
19244+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19245+ i = i + 1
19246+ .endr
19247+ jmp 2f
19248+1:
19249+#endif
19250+
19251+ i = 0
19252+ .rept USER_PGD_PTRS
19253+ movb $0x67,i*8(%rbx)
19254+ i = i + 1
19255+ .endr
19256+
19257+#ifdef CONFIG_PARAVIRT
19258+2: PV_RESTORE_REGS(CLBR_RDI)
19259+#endif
19260+
19261+ popq %rbx
19262+ popq %rdi
19263+ pax_force_retaddr
19264+ retq
19265+3: ud2
19266+ jmp 3b
19267+ENDPROC(pax_exit_kernel_user)
19268+#endif
19269+
19270+ .macro pax_enter_kernel_nmi
19271+ pax_set_fptr_mask
19272+
19273+#ifdef CONFIG_PAX_KERNEXEC
19274+ GET_CR0_INTO_RDI
19275+ bts $16,%rdi
19276+ jc 110f
19277+ SET_RDI_INTO_CR0
19278+ or $2,%ebx
19279+110:
19280+#endif
19281+ .endm
19282+
19283+ .macro pax_exit_kernel_nmi
19284+#ifdef CONFIG_PAX_KERNEXEC
19285+ btr $1,%ebx
19286+ jnc 110f
19287+ GET_CR0_INTO_RDI
19288+ btr $16,%rdi
19289+ SET_RDI_INTO_CR0
19290+110:
19291+#endif
19292+ .endm
19293+
19294+ .macro pax_erase_kstack
19295+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19296+ call pax_erase_kstack
19297+#endif
19298+ .endm
19299+
19300+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19301+ENTRY(pax_erase_kstack)
19302+ pushq %rdi
19303+ pushq %rcx
19304+ pushq %rax
19305+ pushq %r11
19306+
19307+ GET_THREAD_INFO(%r11)
19308+ mov TI_lowest_stack(%r11), %rdi
19309+ mov $-0xBEEF, %rax
19310+ std
19311+
19312+1: mov %edi, %ecx
19313+ and $THREAD_SIZE_asm - 1, %ecx
19314+ shr $3, %ecx
19315+ repne scasq
19316+ jecxz 2f
19317+
19318+ cmp $2*8, %ecx
19319+ jc 2f
19320+
19321+ mov $2*8, %ecx
19322+ repe scasq
19323+ jecxz 2f
19324+ jne 1b
19325+
19326+2: cld
19327+ mov %esp, %ecx
19328+ sub %edi, %ecx
19329+
19330+ cmp $THREAD_SIZE_asm, %rcx
19331+ jb 3f
19332+ ud2
19333+3:
19334+
19335+ shr $3, %ecx
19336+ rep stosq
19337+
19338+ mov TI_task_thread_sp0(%r11), %rdi
19339+ sub $256, %rdi
19340+ mov %rdi, TI_lowest_stack(%r11)
19341+
19342+ popq %r11
19343+ popq %rax
19344+ popq %rcx
19345+ popq %rdi
19346+ pax_force_retaddr
19347+ ret
19348+ENDPROC(pax_erase_kstack)
19349+#endif
19350
19351 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19352 #ifdef CONFIG_TRACE_IRQFLAGS
19353@@ -375,8 +687,8 @@ ENDPROC(native_usergs_sysret64)
19354 .endm
19355
19356 .macro UNFAKE_STACK_FRAME
19357- addq $8*6, %rsp
19358- CFI_ADJUST_CFA_OFFSET -(6*8)
19359+ addq $8*6 + ARG_SKIP, %rsp
19360+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19361 .endm
19362
19363 /*
19364@@ -463,7 +775,7 @@ ENDPROC(native_usergs_sysret64)
19365 movq %rsp, %rsi
19366
19367 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19368- testl $3, CS-RBP(%rsi)
19369+ testb $3, CS-RBP(%rsi)
19370 je 1f
19371 SWAPGS
19372 /*
19373@@ -498,9 +810,10 @@ ENTRY(save_rest)
19374 movq_cfi r15, R15+16
19375 movq %r11, 8(%rsp) /* return address */
19376 FIXUP_TOP_OF_STACK %r11, 16
19377+ pax_force_retaddr
19378 ret
19379 CFI_ENDPROC
19380-END(save_rest)
19381+ENDPROC(save_rest)
19382
19383 /* save complete stack frame */
19384 .pushsection .kprobes.text, "ax"
19385@@ -529,9 +842,10 @@ ENTRY(save_paranoid)
19386 js 1f /* negative -> in kernel */
19387 SWAPGS
19388 xorl %ebx,%ebx
19389-1: ret
19390+1: pax_force_retaddr_bts
19391+ ret
19392 CFI_ENDPROC
19393-END(save_paranoid)
19394+ENDPROC(save_paranoid)
19395 .popsection
19396
19397 /*
19398@@ -553,7 +867,7 @@ ENTRY(ret_from_fork)
19399
19400 RESTORE_REST
19401
19402- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19403+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19404 jz 1f
19405
19406 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19407@@ -571,7 +885,7 @@ ENTRY(ret_from_fork)
19408 RESTORE_REST
19409 jmp int_ret_from_sys_call
19410 CFI_ENDPROC
19411-END(ret_from_fork)
19412+ENDPROC(ret_from_fork)
19413
19414 /*
19415 * System call entry. Up to 6 arguments in registers are supported.
19416@@ -608,7 +922,7 @@ END(ret_from_fork)
19417 ENTRY(system_call)
19418 CFI_STARTPROC simple
19419 CFI_SIGNAL_FRAME
19420- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19421+ CFI_DEF_CFA rsp,0
19422 CFI_REGISTER rip,rcx
19423 /*CFI_REGISTER rflags,r11*/
19424 SWAPGS_UNSAFE_STACK
19425@@ -621,16 +935,23 @@ GLOBAL(system_call_after_swapgs)
19426
19427 movq %rsp,PER_CPU_VAR(old_rsp)
19428 movq PER_CPU_VAR(kernel_stack),%rsp
19429+ SAVE_ARGS 8*6,0
19430+ pax_enter_kernel_user
19431+
19432+#ifdef CONFIG_PAX_RANDKSTACK
19433+ pax_erase_kstack
19434+#endif
19435+
19436 /*
19437 * No need to follow this irqs off/on section - it's straight
19438 * and short:
19439 */
19440 ENABLE_INTERRUPTS(CLBR_NONE)
19441- SAVE_ARGS 8,0
19442 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19443 movq %rcx,RIP-ARGOFFSET(%rsp)
19444 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19445- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19446+ GET_THREAD_INFO(%rcx)
19447+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19448 jnz tracesys
19449 system_call_fastpath:
19450 #if __SYSCALL_MASK == ~0
19451@@ -640,7 +961,7 @@ system_call_fastpath:
19452 cmpl $__NR_syscall_max,%eax
19453 #endif
19454 ja badsys
19455- movq %r10,%rcx
19456+ movq R10-ARGOFFSET(%rsp),%rcx
19457 call *sys_call_table(,%rax,8) # XXX: rip relative
19458 movq %rax,RAX-ARGOFFSET(%rsp)
19459 /*
19460@@ -654,10 +975,13 @@ sysret_check:
19461 LOCKDEP_SYS_EXIT
19462 DISABLE_INTERRUPTS(CLBR_NONE)
19463 TRACE_IRQS_OFF
19464- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19465+ GET_THREAD_INFO(%rcx)
19466+ movl TI_flags(%rcx),%edx
19467 andl %edi,%edx
19468 jnz sysret_careful
19469 CFI_REMEMBER_STATE
19470+ pax_exit_kernel_user
19471+ pax_erase_kstack
19472 /*
19473 * sysretq will re-enable interrupts:
19474 */
19475@@ -709,14 +1033,18 @@ badsys:
19476 * jump back to the normal fast path.
19477 */
19478 auditsys:
19479- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19480+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19481 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19482 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19483 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19484 movq %rax,%rsi /* 2nd arg: syscall number */
19485 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19486 call __audit_syscall_entry
19487+
19488+ pax_erase_kstack
19489+
19490 LOAD_ARGS 0 /* reload call-clobbered registers */
19491+ pax_set_fptr_mask
19492 jmp system_call_fastpath
19493
19494 /*
19495@@ -737,7 +1065,7 @@ sysret_audit:
19496 /* Do syscall tracing */
19497 tracesys:
19498 #ifdef CONFIG_AUDITSYSCALL
19499- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19500+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19501 jz auditsys
19502 #endif
19503 SAVE_REST
19504@@ -745,12 +1073,16 @@ tracesys:
19505 FIXUP_TOP_OF_STACK %rdi
19506 movq %rsp,%rdi
19507 call syscall_trace_enter
19508+
19509+ pax_erase_kstack
19510+
19511 /*
19512 * Reload arg registers from stack in case ptrace changed them.
19513 * We don't reload %rax because syscall_trace_enter() returned
19514 * the value it wants us to use in the table lookup.
19515 */
19516 LOAD_ARGS ARGOFFSET, 1
19517+ pax_set_fptr_mask
19518 RESTORE_REST
19519 #if __SYSCALL_MASK == ~0
19520 cmpq $__NR_syscall_max,%rax
19521@@ -759,7 +1091,7 @@ tracesys:
19522 cmpl $__NR_syscall_max,%eax
19523 #endif
19524 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19525- movq %r10,%rcx /* fixup for C */
19526+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19527 call *sys_call_table(,%rax,8)
19528 movq %rax,RAX-ARGOFFSET(%rsp)
19529 /* Use IRET because user could have changed frame */
19530@@ -780,7 +1112,9 @@ GLOBAL(int_with_check)
19531 andl %edi,%edx
19532 jnz int_careful
19533 andl $~TS_COMPAT,TI_status(%rcx)
19534- jmp retint_swapgs
19535+ pax_exit_kernel_user
19536+ pax_erase_kstack
19537+ jmp retint_swapgs_pax
19538
19539 /* Either reschedule or signal or syscall exit tracking needed. */
19540 /* First do a reschedule test. */
19541@@ -826,7 +1160,7 @@ int_restore_rest:
19542 TRACE_IRQS_OFF
19543 jmp int_with_check
19544 CFI_ENDPROC
19545-END(system_call)
19546+ENDPROC(system_call)
19547
19548 .macro FORK_LIKE func
19549 ENTRY(stub_\func)
19550@@ -839,9 +1173,10 @@ ENTRY(stub_\func)
19551 DEFAULT_FRAME 0 8 /* offset 8: return address */
19552 call sys_\func
19553 RESTORE_TOP_OF_STACK %r11, 8
19554+ pax_force_retaddr
19555 ret $REST_SKIP /* pop extended registers */
19556 CFI_ENDPROC
19557-END(stub_\func)
19558+ENDPROC(stub_\func)
19559 .endm
19560
19561 .macro FIXED_FRAME label,func
19562@@ -851,9 +1186,10 @@ ENTRY(\label)
19563 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
19564 call \func
19565 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
19566+ pax_force_retaddr
19567 ret
19568 CFI_ENDPROC
19569-END(\label)
19570+ENDPROC(\label)
19571 .endm
19572
19573 FORK_LIKE clone
19574@@ -870,9 +1206,10 @@ ENTRY(ptregscall_common)
19575 movq_cfi_restore R12+8, r12
19576 movq_cfi_restore RBP+8, rbp
19577 movq_cfi_restore RBX+8, rbx
19578+ pax_force_retaddr
19579 ret $REST_SKIP /* pop extended registers */
19580 CFI_ENDPROC
19581-END(ptregscall_common)
19582+ENDPROC(ptregscall_common)
19583
19584 ENTRY(stub_execve)
19585 CFI_STARTPROC
19586@@ -885,7 +1222,7 @@ ENTRY(stub_execve)
19587 RESTORE_REST
19588 jmp int_ret_from_sys_call
19589 CFI_ENDPROC
19590-END(stub_execve)
19591+ENDPROC(stub_execve)
19592
19593 /*
19594 * sigreturn is special because it needs to restore all registers on return.
19595@@ -902,7 +1239,7 @@ ENTRY(stub_rt_sigreturn)
19596 RESTORE_REST
19597 jmp int_ret_from_sys_call
19598 CFI_ENDPROC
19599-END(stub_rt_sigreturn)
19600+ENDPROC(stub_rt_sigreturn)
19601
19602 #ifdef CONFIG_X86_X32_ABI
19603 ENTRY(stub_x32_rt_sigreturn)
19604@@ -916,7 +1253,7 @@ ENTRY(stub_x32_rt_sigreturn)
19605 RESTORE_REST
19606 jmp int_ret_from_sys_call
19607 CFI_ENDPROC
19608-END(stub_x32_rt_sigreturn)
19609+ENDPROC(stub_x32_rt_sigreturn)
19610
19611 ENTRY(stub_x32_execve)
19612 CFI_STARTPROC
19613@@ -930,7 +1267,7 @@ ENTRY(stub_x32_execve)
19614 RESTORE_REST
19615 jmp int_ret_from_sys_call
19616 CFI_ENDPROC
19617-END(stub_x32_execve)
19618+ENDPROC(stub_x32_execve)
19619
19620 #endif
19621
19622@@ -967,7 +1304,7 @@ vector=vector+1
19623 2: jmp common_interrupt
19624 .endr
19625 CFI_ENDPROC
19626-END(irq_entries_start)
19627+ENDPROC(irq_entries_start)
19628
19629 .previous
19630 END(interrupt)
19631@@ -987,6 +1324,16 @@ END(interrupt)
19632 subq $ORIG_RAX-RBP, %rsp
19633 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19634 SAVE_ARGS_IRQ
19635+#ifdef CONFIG_PAX_MEMORY_UDEREF
19636+ testb $3, CS(%rdi)
19637+ jnz 1f
19638+ pax_enter_kernel
19639+ jmp 2f
19640+1: pax_enter_kernel_user
19641+2:
19642+#else
19643+ pax_enter_kernel
19644+#endif
19645 call \func
19646 .endm
19647
19648@@ -1019,7 +1366,7 @@ ret_from_intr:
19649
19650 exit_intr:
19651 GET_THREAD_INFO(%rcx)
19652- testl $3,CS-ARGOFFSET(%rsp)
19653+ testb $3,CS-ARGOFFSET(%rsp)
19654 je retint_kernel
19655
19656 /* Interrupt came from user space */
19657@@ -1041,12 +1388,16 @@ retint_swapgs: /* return to user-space */
19658 * The iretq could re-enable interrupts:
19659 */
19660 DISABLE_INTERRUPTS(CLBR_ANY)
19661+ pax_exit_kernel_user
19662+retint_swapgs_pax:
19663 TRACE_IRQS_IRETQ
19664 SWAPGS
19665 jmp restore_args
19666
19667 retint_restore_args: /* return to kernel space */
19668 DISABLE_INTERRUPTS(CLBR_ANY)
19669+ pax_exit_kernel
19670+ pax_force_retaddr (RIP-ARGOFFSET)
19671 /*
19672 * The iretq could re-enable interrupts:
19673 */
19674@@ -1129,7 +1480,7 @@ ENTRY(retint_kernel)
19675 #endif
19676
19677 CFI_ENDPROC
19678-END(common_interrupt)
19679+ENDPROC(common_interrupt)
19680 /*
19681 * End of kprobes section
19682 */
19683@@ -1147,7 +1498,7 @@ ENTRY(\sym)
19684 interrupt \do_sym
19685 jmp ret_from_intr
19686 CFI_ENDPROC
19687-END(\sym)
19688+ENDPROC(\sym)
19689 .endm
19690
19691 #ifdef CONFIG_SMP
19692@@ -1208,12 +1559,22 @@ ENTRY(\sym)
19693 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19694 call error_entry
19695 DEFAULT_FRAME 0
19696+#ifdef CONFIG_PAX_MEMORY_UDEREF
19697+ testb $3, CS(%rsp)
19698+ jnz 1f
19699+ pax_enter_kernel
19700+ jmp 2f
19701+1: pax_enter_kernel_user
19702+2:
19703+#else
19704+ pax_enter_kernel
19705+#endif
19706 movq %rsp,%rdi /* pt_regs pointer */
19707 xorl %esi,%esi /* no error code */
19708 call \do_sym
19709 jmp error_exit /* %ebx: no swapgs flag */
19710 CFI_ENDPROC
19711-END(\sym)
19712+ENDPROC(\sym)
19713 .endm
19714
19715 .macro paranoidzeroentry sym do_sym
19716@@ -1226,15 +1587,25 @@ ENTRY(\sym)
19717 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19718 call save_paranoid
19719 TRACE_IRQS_OFF
19720+#ifdef CONFIG_PAX_MEMORY_UDEREF
19721+ testb $3, CS(%rsp)
19722+ jnz 1f
19723+ pax_enter_kernel
19724+ jmp 2f
19725+1: pax_enter_kernel_user
19726+2:
19727+#else
19728+ pax_enter_kernel
19729+#endif
19730 movq %rsp,%rdi /* pt_regs pointer */
19731 xorl %esi,%esi /* no error code */
19732 call \do_sym
19733 jmp paranoid_exit /* %ebx: no swapgs flag */
19734 CFI_ENDPROC
19735-END(\sym)
19736+ENDPROC(\sym)
19737 .endm
19738
19739-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19740+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19741 .macro paranoidzeroentry_ist sym do_sym ist
19742 ENTRY(\sym)
19743 INTR_FRAME
19744@@ -1245,14 +1616,30 @@ ENTRY(\sym)
19745 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19746 call save_paranoid
19747 TRACE_IRQS_OFF_DEBUG
19748+#ifdef CONFIG_PAX_MEMORY_UDEREF
19749+ testb $3, CS(%rsp)
19750+ jnz 1f
19751+ pax_enter_kernel
19752+ jmp 2f
19753+1: pax_enter_kernel_user
19754+2:
19755+#else
19756+ pax_enter_kernel
19757+#endif
19758 movq %rsp,%rdi /* pt_regs pointer */
19759 xorl %esi,%esi /* no error code */
19760+#ifdef CONFIG_SMP
19761+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19762+ lea init_tss(%r12), %r12
19763+#else
19764+ lea init_tss(%rip), %r12
19765+#endif
19766 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19767 call \do_sym
19768 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19769 jmp paranoid_exit /* %ebx: no swapgs flag */
19770 CFI_ENDPROC
19771-END(\sym)
19772+ENDPROC(\sym)
19773 .endm
19774
19775 .macro errorentry sym do_sym
19776@@ -1264,13 +1651,23 @@ ENTRY(\sym)
19777 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19778 call error_entry
19779 DEFAULT_FRAME 0
19780+#ifdef CONFIG_PAX_MEMORY_UDEREF
19781+ testb $3, CS(%rsp)
19782+ jnz 1f
19783+ pax_enter_kernel
19784+ jmp 2f
19785+1: pax_enter_kernel_user
19786+2:
19787+#else
19788+ pax_enter_kernel
19789+#endif
19790 movq %rsp,%rdi /* pt_regs pointer */
19791 movq ORIG_RAX(%rsp),%rsi /* get error code */
19792 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19793 call \do_sym
19794 jmp error_exit /* %ebx: no swapgs flag */
19795 CFI_ENDPROC
19796-END(\sym)
19797+ENDPROC(\sym)
19798 .endm
19799
19800 /* error code is on the stack already */
19801@@ -1284,13 +1681,23 @@ ENTRY(\sym)
19802 call save_paranoid
19803 DEFAULT_FRAME 0
19804 TRACE_IRQS_OFF
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 movq ORIG_RAX(%rsp),%rsi /* get error code */
19817 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19818 call \do_sym
19819 jmp paranoid_exit /* %ebx: no swapgs flag */
19820 CFI_ENDPROC
19821-END(\sym)
19822+ENDPROC(\sym)
19823 .endm
19824
19825 zeroentry divide_error do_divide_error
19826@@ -1320,9 +1727,10 @@ gs_change:
19827 2: mfence /* workaround */
19828 SWAPGS
19829 popfq_cfi
19830+ pax_force_retaddr
19831 ret
19832 CFI_ENDPROC
19833-END(native_load_gs_index)
19834+ENDPROC(native_load_gs_index)
19835
19836 _ASM_EXTABLE(gs_change,bad_gs)
19837 .section .fixup,"ax"
19838@@ -1350,9 +1758,10 @@ ENTRY(call_softirq)
19839 CFI_DEF_CFA_REGISTER rsp
19840 CFI_ADJUST_CFA_OFFSET -8
19841 decl PER_CPU_VAR(irq_count)
19842+ pax_force_retaddr
19843 ret
19844 CFI_ENDPROC
19845-END(call_softirq)
19846+ENDPROC(call_softirq)
19847
19848 #ifdef CONFIG_XEN
19849 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19850@@ -1390,7 +1799,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19851 decl PER_CPU_VAR(irq_count)
19852 jmp error_exit
19853 CFI_ENDPROC
19854-END(xen_do_hypervisor_callback)
19855+ENDPROC(xen_do_hypervisor_callback)
19856
19857 /*
19858 * Hypervisor uses this for application faults while it executes.
19859@@ -1449,7 +1858,7 @@ ENTRY(xen_failsafe_callback)
19860 SAVE_ALL
19861 jmp error_exit
19862 CFI_ENDPROC
19863-END(xen_failsafe_callback)
19864+ENDPROC(xen_failsafe_callback)
19865
19866 apicinterrupt HYPERVISOR_CALLBACK_VECTOR \
19867 xen_hvm_callback_vector xen_evtchn_do_upcall
19868@@ -1501,18 +1910,33 @@ ENTRY(paranoid_exit)
19869 DEFAULT_FRAME
19870 DISABLE_INTERRUPTS(CLBR_NONE)
19871 TRACE_IRQS_OFF_DEBUG
19872- testl %ebx,%ebx /* swapgs needed? */
19873+ testl $1,%ebx /* swapgs needed? */
19874 jnz paranoid_restore
19875- testl $3,CS(%rsp)
19876+ testb $3,CS(%rsp)
19877 jnz paranoid_userspace
19878+#ifdef CONFIG_PAX_MEMORY_UDEREF
19879+ pax_exit_kernel
19880+ TRACE_IRQS_IRETQ 0
19881+ SWAPGS_UNSAFE_STACK
19882+ RESTORE_ALL 8
19883+ pax_force_retaddr_bts
19884+ jmp irq_return
19885+#endif
19886 paranoid_swapgs:
19887+#ifdef CONFIG_PAX_MEMORY_UDEREF
19888+ pax_exit_kernel_user
19889+#else
19890+ pax_exit_kernel
19891+#endif
19892 TRACE_IRQS_IRETQ 0
19893 SWAPGS_UNSAFE_STACK
19894 RESTORE_ALL 8
19895 jmp irq_return
19896 paranoid_restore:
19897+ pax_exit_kernel
19898 TRACE_IRQS_IRETQ_DEBUG 0
19899 RESTORE_ALL 8
19900+ pax_force_retaddr_bts
19901 jmp irq_return
19902 paranoid_userspace:
19903 GET_THREAD_INFO(%rcx)
19904@@ -1541,7 +1965,7 @@ paranoid_schedule:
19905 TRACE_IRQS_OFF
19906 jmp paranoid_userspace
19907 CFI_ENDPROC
19908-END(paranoid_exit)
19909+ENDPROC(paranoid_exit)
19910
19911 /*
19912 * Exception entry point. This expects an error code/orig_rax on the stack.
19913@@ -1568,12 +1992,13 @@ ENTRY(error_entry)
19914 movq_cfi r14, R14+8
19915 movq_cfi r15, R15+8
19916 xorl %ebx,%ebx
19917- testl $3,CS+8(%rsp)
19918+ testb $3,CS+8(%rsp)
19919 je error_kernelspace
19920 error_swapgs:
19921 SWAPGS
19922 error_sti:
19923 TRACE_IRQS_OFF
19924+ pax_force_retaddr_bts
19925 ret
19926
19927 /*
19928@@ -1600,7 +2025,7 @@ bstep_iret:
19929 movq %rcx,RIP+8(%rsp)
19930 jmp error_swapgs
19931 CFI_ENDPROC
19932-END(error_entry)
19933+ENDPROC(error_entry)
19934
19935
19936 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19937@@ -1611,7 +2036,7 @@ ENTRY(error_exit)
19938 DISABLE_INTERRUPTS(CLBR_NONE)
19939 TRACE_IRQS_OFF
19940 GET_THREAD_INFO(%rcx)
19941- testl %eax,%eax
19942+ testl $1,%eax
19943 jne retint_kernel
19944 LOCKDEP_SYS_EXIT_IRQ
19945 movl TI_flags(%rcx),%edx
19946@@ -1620,7 +2045,7 @@ ENTRY(error_exit)
19947 jnz retint_careful
19948 jmp retint_swapgs
19949 CFI_ENDPROC
19950-END(error_exit)
19951+ENDPROC(error_exit)
19952
19953 /*
19954 * Test if a given stack is an NMI stack or not.
19955@@ -1678,9 +2103,11 @@ ENTRY(nmi)
19956 * If %cs was not the kernel segment, then the NMI triggered in user
19957 * space, which means it is definitely not nested.
19958 */
19959+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19960+ je 1f
19961 cmpl $__KERNEL_CS, 16(%rsp)
19962 jne first_nmi
19963-
19964+1:
19965 /*
19966 * Check the special variable on the stack to see if NMIs are
19967 * executing.
19968@@ -1714,8 +2141,7 @@ nested_nmi:
19969
19970 1:
19971 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
19972- leaq -1*8(%rsp), %rdx
19973- movq %rdx, %rsp
19974+ subq $8, %rsp
19975 CFI_ADJUST_CFA_OFFSET 1*8
19976 leaq -10*8(%rsp), %rdx
19977 pushq_cfi $__KERNEL_DS
19978@@ -1733,6 +2159,7 @@ nested_nmi_out:
19979 CFI_RESTORE rdx
19980
19981 /* No need to check faults here */
19982+# pax_force_retaddr_bts
19983 INTERRUPT_RETURN
19984
19985 CFI_RESTORE_STATE
19986@@ -1849,6 +2276,8 @@ end_repeat_nmi:
19987 */
19988 movq %cr2, %r12
19989
19990+ pax_enter_kernel_nmi
19991+
19992 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19993 movq %rsp,%rdi
19994 movq $-1,%rsi
19995@@ -1861,26 +2290,31 @@ end_repeat_nmi:
19996 movq %r12, %cr2
19997 1:
19998
19999- testl %ebx,%ebx /* swapgs needed? */
20000+ testl $1,%ebx /* swapgs needed? */
20001 jnz nmi_restore
20002 nmi_swapgs:
20003 SWAPGS_UNSAFE_STACK
20004 nmi_restore:
20005+ pax_exit_kernel_nmi
20006 /* Pop the extra iret frame at once */
20007 RESTORE_ALL 6*8
20008+ testb $3, 8(%rsp)
20009+ jnz 1f
20010+ pax_force_retaddr_bts
20011+1:
20012
20013 /* Clear the NMI executing stack variable */
20014 movq $0, 5*8(%rsp)
20015 jmp irq_return
20016 CFI_ENDPROC
20017-END(nmi)
20018+ENDPROC(nmi)
20019
20020 ENTRY(ignore_sysret)
20021 CFI_STARTPROC
20022 mov $-ENOSYS,%eax
20023 sysret
20024 CFI_ENDPROC
20025-END(ignore_sysret)
20026+ENDPROC(ignore_sysret)
20027
20028 /*
20029 * End of kprobes section
20030diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
20031index 42a392a..fbbd930 100644
20032--- a/arch/x86/kernel/ftrace.c
20033+++ b/arch/x86/kernel/ftrace.c
20034@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
20035 {
20036 unsigned char replaced[MCOUNT_INSN_SIZE];
20037
20038+ ip = ktla_ktva(ip);
20039+
20040 /*
20041 * Note: Due to modules and __init, code can
20042 * disappear and change, we need to protect against faulting
20043@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20044 unsigned char old[MCOUNT_INSN_SIZE], *new;
20045 int ret;
20046
20047- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
20048+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
20049 new = ftrace_call_replace(ip, (unsigned long)func);
20050
20051 /* See comment above by declaration of modifying_ftrace_code */
20052@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20053 /* Also update the regs callback function */
20054 if (!ret) {
20055 ip = (unsigned long)(&ftrace_regs_call);
20056- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
20057+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
20058 new = ftrace_call_replace(ip, (unsigned long)func);
20059 ret = ftrace_modify_code(ip, old, new);
20060 }
20061@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
20062 * kernel identity mapping to modify code.
20063 */
20064 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
20065- ip = (unsigned long)__va(__pa_symbol(ip));
20066+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
20067
20068 return probe_kernel_write((void *)ip, val, size);
20069 }
20070@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
20071 unsigned char replaced[MCOUNT_INSN_SIZE];
20072 unsigned char brk = BREAKPOINT_INSTRUCTION;
20073
20074- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
20075+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
20076 return -EFAULT;
20077
20078 /* Make sure it is what we expect it to be */
20079@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
20080 return ret;
20081
20082 fail_update:
20083- probe_kernel_write((void *)ip, &old_code[0], 1);
20084+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
20085 goto out;
20086 }
20087
20088@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
20089 {
20090 unsigned char code[MCOUNT_INSN_SIZE];
20091
20092+ ip = ktla_ktva(ip);
20093+
20094 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
20095 return -EFAULT;
20096
20097diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
20098index 55b6761..a6456fc 100644
20099--- a/arch/x86/kernel/head64.c
20100+++ b/arch/x86/kernel/head64.c
20101@@ -67,12 +67,12 @@ again:
20102 pgd = *pgd_p;
20103
20104 /*
20105- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
20106- * critical -- __PAGE_OFFSET would point us back into the dynamic
20107+ * The use of __early_va rather than __va here is critical:
20108+ * __va would point us back into the dynamic
20109 * range and we might end up looping forever...
20110 */
20111 if (pgd)
20112- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
20113+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
20114 else {
20115 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
20116 reset_early_page_tables();
20117@@ -82,13 +82,13 @@ again:
20118 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
20119 for (i = 0; i < PTRS_PER_PUD; i++)
20120 pud_p[i] = 0;
20121- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
20122+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
20123 }
20124 pud_p += pud_index(address);
20125 pud = *pud_p;
20126
20127 if (pud)
20128- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
20129+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
20130 else {
20131 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
20132 reset_early_page_tables();
20133@@ -98,7 +98,7 @@ again:
20134 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
20135 for (i = 0; i < PTRS_PER_PMD; i++)
20136 pmd_p[i] = 0;
20137- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
20138+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
20139 }
20140 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
20141 pmd_p[pmd_index(address)] = pmd;
20142@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
20143 if (console_loglevel == 10)
20144 early_printk("Kernel alive\n");
20145
20146- clear_page(init_level4_pgt);
20147 /* set init_level4_pgt kernel high mapping*/
20148 init_level4_pgt[511] = early_level4_pgt[511];
20149
20150diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
20151index 73afd11..d1670f5 100644
20152--- a/arch/x86/kernel/head_32.S
20153+++ b/arch/x86/kernel/head_32.S
20154@@ -26,6 +26,12 @@
20155 /* Physical address */
20156 #define pa(X) ((X) - __PAGE_OFFSET)
20157
20158+#ifdef CONFIG_PAX_KERNEXEC
20159+#define ta(X) (X)
20160+#else
20161+#define ta(X) ((X) - __PAGE_OFFSET)
20162+#endif
20163+
20164 /*
20165 * References to members of the new_cpu_data structure.
20166 */
20167@@ -55,11 +61,7 @@
20168 * and small than max_low_pfn, otherwise will waste some page table entries
20169 */
20170
20171-#if PTRS_PER_PMD > 1
20172-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
20173-#else
20174-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
20175-#endif
20176+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
20177
20178 /* Number of possible pages in the lowmem region */
20179 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
20180@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
20181 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20182
20183 /*
20184+ * Real beginning of normal "text" segment
20185+ */
20186+ENTRY(stext)
20187+ENTRY(_stext)
20188+
20189+/*
20190 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
20191 * %esi points to the real-mode code as a 32-bit pointer.
20192 * CS and DS must be 4 GB flat segments, but we don't depend on
20193@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20194 * can.
20195 */
20196 __HEAD
20197+
20198+#ifdef CONFIG_PAX_KERNEXEC
20199+ jmp startup_32
20200+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20201+.fill PAGE_SIZE-5,1,0xcc
20202+#endif
20203+
20204 ENTRY(startup_32)
20205 movl pa(stack_start),%ecx
20206
20207@@ -106,6 +121,59 @@ ENTRY(startup_32)
20208 2:
20209 leal -__PAGE_OFFSET(%ecx),%esp
20210
20211+#ifdef CONFIG_SMP
20212+ movl $pa(cpu_gdt_table),%edi
20213+ movl $__per_cpu_load,%eax
20214+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20215+ rorl $16,%eax
20216+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20217+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20218+ movl $__per_cpu_end - 1,%eax
20219+ subl $__per_cpu_start,%eax
20220+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20221+#endif
20222+
20223+#ifdef CONFIG_PAX_MEMORY_UDEREF
20224+ movl $NR_CPUS,%ecx
20225+ movl $pa(cpu_gdt_table),%edi
20226+1:
20227+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20228+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20229+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20230+ addl $PAGE_SIZE_asm,%edi
20231+ loop 1b
20232+#endif
20233+
20234+#ifdef CONFIG_PAX_KERNEXEC
20235+ movl $pa(boot_gdt),%edi
20236+ movl $__LOAD_PHYSICAL_ADDR,%eax
20237+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20238+ rorl $16,%eax
20239+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20240+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20241+ rorl $16,%eax
20242+
20243+ ljmp $(__BOOT_CS),$1f
20244+1:
20245+
20246+ movl $NR_CPUS,%ecx
20247+ movl $pa(cpu_gdt_table),%edi
20248+ addl $__PAGE_OFFSET,%eax
20249+1:
20250+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20251+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20252+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20253+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20254+ rorl $16,%eax
20255+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20256+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20257+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20258+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20259+ rorl $16,%eax
20260+ addl $PAGE_SIZE_asm,%edi
20261+ loop 1b
20262+#endif
20263+
20264 /*
20265 * Clear BSS first so that there are no surprises...
20266 */
20267@@ -201,8 +269,11 @@ ENTRY(startup_32)
20268 movl %eax, pa(max_pfn_mapped)
20269
20270 /* Do early initialization of the fixmap area */
20271- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20272- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20273+#ifdef CONFIG_COMPAT_VDSO
20274+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20275+#else
20276+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20277+#endif
20278 #else /* Not PAE */
20279
20280 page_pde_offset = (__PAGE_OFFSET >> 20);
20281@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20282 movl %eax, pa(max_pfn_mapped)
20283
20284 /* Do early initialization of the fixmap area */
20285- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20286- movl %eax,pa(initial_page_table+0xffc)
20287+#ifdef CONFIG_COMPAT_VDSO
20288+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20289+#else
20290+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20291+#endif
20292 #endif
20293
20294 #ifdef CONFIG_PARAVIRT
20295@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20296 cmpl $num_subarch_entries, %eax
20297 jae bad_subarch
20298
20299- movl pa(subarch_entries)(,%eax,4), %eax
20300- subl $__PAGE_OFFSET, %eax
20301- jmp *%eax
20302+ jmp *pa(subarch_entries)(,%eax,4)
20303
20304 bad_subarch:
20305 WEAK(lguest_entry)
20306@@ -261,10 +333,10 @@ WEAK(xen_entry)
20307 __INITDATA
20308
20309 subarch_entries:
20310- .long default_entry /* normal x86/PC */
20311- .long lguest_entry /* lguest hypervisor */
20312- .long xen_entry /* Xen hypervisor */
20313- .long default_entry /* Moorestown MID */
20314+ .long ta(default_entry) /* normal x86/PC */
20315+ .long ta(lguest_entry) /* lguest hypervisor */
20316+ .long ta(xen_entry) /* Xen hypervisor */
20317+ .long ta(default_entry) /* Moorestown MID */
20318 num_subarch_entries = (. - subarch_entries) / 4
20319 .previous
20320 #else
20321@@ -355,6 +427,7 @@ default_entry:
20322 movl pa(mmu_cr4_features),%eax
20323 movl %eax,%cr4
20324
20325+#ifdef CONFIG_X86_PAE
20326 testb $X86_CR4_PAE, %al # check if PAE is enabled
20327 jz enable_paging
20328
20329@@ -383,6 +456,9 @@ default_entry:
20330 /* Make changes effective */
20331 wrmsr
20332
20333+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20334+#endif
20335+
20336 enable_paging:
20337
20338 /*
20339@@ -451,14 +527,20 @@ is486:
20340 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20341 movl %eax,%ss # after changing gdt.
20342
20343- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20344+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20345 movl %eax,%ds
20346 movl %eax,%es
20347
20348 movl $(__KERNEL_PERCPU), %eax
20349 movl %eax,%fs # set this cpu's percpu
20350
20351+#ifdef CONFIG_CC_STACKPROTECTOR
20352 movl $(__KERNEL_STACK_CANARY),%eax
20353+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20354+ movl $(__USER_DS),%eax
20355+#else
20356+ xorl %eax,%eax
20357+#endif
20358 movl %eax,%gs
20359
20360 xorl %eax,%eax # Clear LDT
20361@@ -534,8 +616,11 @@ setup_once:
20362 * relocation. Manually set base address in stack canary
20363 * segment descriptor.
20364 */
20365- movl $gdt_page,%eax
20366+ movl $cpu_gdt_table,%eax
20367 movl $stack_canary,%ecx
20368+#ifdef CONFIG_SMP
20369+ addl $__per_cpu_load,%ecx
20370+#endif
20371 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20372 shrl $16, %ecx
20373 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20374@@ -566,7 +651,7 @@ ENDPROC(early_idt_handlers)
20375 /* This is global to keep gas from relaxing the jumps */
20376 ENTRY(early_idt_handler)
20377 cld
20378- cmpl $2,%ss:early_recursion_flag
20379+ cmpl $1,%ss:early_recursion_flag
20380 je hlt_loop
20381 incl %ss:early_recursion_flag
20382
20383@@ -604,8 +689,8 @@ ENTRY(early_idt_handler)
20384 pushl (20+6*4)(%esp) /* trapno */
20385 pushl $fault_msg
20386 call printk
20387-#endif
20388 call dump_stack
20389+#endif
20390 hlt_loop:
20391 hlt
20392 jmp hlt_loop
20393@@ -624,8 +709,11 @@ ENDPROC(early_idt_handler)
20394 /* This is the default interrupt "handler" :-) */
20395 ALIGN
20396 ignore_int:
20397- cld
20398 #ifdef CONFIG_PRINTK
20399+ cmpl $2,%ss:early_recursion_flag
20400+ je hlt_loop
20401+ incl %ss:early_recursion_flag
20402+ cld
20403 pushl %eax
20404 pushl %ecx
20405 pushl %edx
20406@@ -634,9 +722,6 @@ ignore_int:
20407 movl $(__KERNEL_DS),%eax
20408 movl %eax,%ds
20409 movl %eax,%es
20410- cmpl $2,early_recursion_flag
20411- je hlt_loop
20412- incl early_recursion_flag
20413 pushl 16(%esp)
20414 pushl 24(%esp)
20415 pushl 32(%esp)
20416@@ -670,29 +755,43 @@ ENTRY(setup_once_ref)
20417 /*
20418 * BSS section
20419 */
20420-__PAGE_ALIGNED_BSS
20421- .align PAGE_SIZE
20422 #ifdef CONFIG_X86_PAE
20423+.section .initial_pg_pmd,"a",@progbits
20424 initial_pg_pmd:
20425 .fill 1024*KPMDS,4,0
20426 #else
20427+.section .initial_page_table,"a",@progbits
20428 ENTRY(initial_page_table)
20429 .fill 1024,4,0
20430 #endif
20431+.section .initial_pg_fixmap,"a",@progbits
20432 initial_pg_fixmap:
20433 .fill 1024,4,0
20434+.section .empty_zero_page,"a",@progbits
20435 ENTRY(empty_zero_page)
20436 .fill 4096,1,0
20437+.section .swapper_pg_dir,"a",@progbits
20438 ENTRY(swapper_pg_dir)
20439+#ifdef CONFIG_X86_PAE
20440+ .fill 4,8,0
20441+#else
20442 .fill 1024,4,0
20443+#endif
20444+
20445+/*
20446+ * The IDT has to be page-aligned to simplify the Pentium
20447+ * F0 0F bug workaround.. We have a special link segment
20448+ * for this.
20449+ */
20450+.section .idt,"a",@progbits
20451+ENTRY(idt_table)
20452+ .fill 256,8,0
20453
20454 /*
20455 * This starts the data section.
20456 */
20457 #ifdef CONFIG_X86_PAE
20458-__PAGE_ALIGNED_DATA
20459- /* Page-aligned for the benefit of paravirt? */
20460- .align PAGE_SIZE
20461+.section .initial_page_table,"a",@progbits
20462 ENTRY(initial_page_table)
20463 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20464 # if KPMDS == 3
20465@@ -711,12 +810,20 @@ ENTRY(initial_page_table)
20466 # error "Kernel PMDs should be 1, 2 or 3"
20467 # endif
20468 .align PAGE_SIZE /* needs to be page-sized too */
20469+
20470+#ifdef CONFIG_PAX_PER_CPU_PGD
20471+ENTRY(cpu_pgd)
20472+ .rept NR_CPUS
20473+ .fill 4,8,0
20474+ .endr
20475+#endif
20476+
20477 #endif
20478
20479 .data
20480 .balign 4
20481 ENTRY(stack_start)
20482- .long init_thread_union+THREAD_SIZE
20483+ .long init_thread_union+THREAD_SIZE-8
20484
20485 __INITRODATA
20486 int_msg:
20487@@ -744,7 +851,7 @@ fault_msg:
20488 * segment size, and 32-bit linear address value:
20489 */
20490
20491- .data
20492+.section .rodata,"a",@progbits
20493 .globl boot_gdt_descr
20494 .globl idt_descr
20495
20496@@ -753,7 +860,7 @@ fault_msg:
20497 .word 0 # 32 bit align gdt_desc.address
20498 boot_gdt_descr:
20499 .word __BOOT_DS+7
20500- .long boot_gdt - __PAGE_OFFSET
20501+ .long pa(boot_gdt)
20502
20503 .word 0 # 32-bit align idt_desc.address
20504 idt_descr:
20505@@ -764,7 +871,7 @@ idt_descr:
20506 .word 0 # 32 bit align gdt_desc.address
20507 ENTRY(early_gdt_descr)
20508 .word GDT_ENTRIES*8-1
20509- .long gdt_page /* Overwritten for secondary CPUs */
20510+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20511
20512 /*
20513 * The boot_gdt must mirror the equivalent in setup.S and is
20514@@ -773,5 +880,65 @@ ENTRY(early_gdt_descr)
20515 .align L1_CACHE_BYTES
20516 ENTRY(boot_gdt)
20517 .fill GDT_ENTRY_BOOT_CS,8,0
20518- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20519- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20520+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20521+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20522+
20523+ .align PAGE_SIZE_asm
20524+ENTRY(cpu_gdt_table)
20525+ .rept NR_CPUS
20526+ .quad 0x0000000000000000 /* NULL descriptor */
20527+ .quad 0x0000000000000000 /* 0x0b reserved */
20528+ .quad 0x0000000000000000 /* 0x13 reserved */
20529+ .quad 0x0000000000000000 /* 0x1b reserved */
20530+
20531+#ifdef CONFIG_PAX_KERNEXEC
20532+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20533+#else
20534+ .quad 0x0000000000000000 /* 0x20 unused */
20535+#endif
20536+
20537+ .quad 0x0000000000000000 /* 0x28 unused */
20538+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20539+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20540+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20541+ .quad 0x0000000000000000 /* 0x4b reserved */
20542+ .quad 0x0000000000000000 /* 0x53 reserved */
20543+ .quad 0x0000000000000000 /* 0x5b reserved */
20544+
20545+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20546+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20547+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20548+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20549+
20550+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20551+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20552+
20553+ /*
20554+ * Segments used for calling PnP BIOS have byte granularity.
20555+ * The code segments and data segments have fixed 64k limits,
20556+ * the transfer segment sizes are set at run time.
20557+ */
20558+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20559+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20560+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20561+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20562+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20563+
20564+ /*
20565+ * The APM segments have byte granularity and their bases
20566+ * are set at run time. All have 64k limits.
20567+ */
20568+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20569+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20570+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20571+
20572+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20573+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20574+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20575+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20576+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20577+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20578+
20579+ /* Be sure this is zeroed to avoid false validations in Xen */
20580+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20581+ .endr
20582diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20583index 321d65e..863089b 100644
20584--- a/arch/x86/kernel/head_64.S
20585+++ b/arch/x86/kernel/head_64.S
20586@@ -20,6 +20,8 @@
20587 #include <asm/processor-flags.h>
20588 #include <asm/percpu.h>
20589 #include <asm/nops.h>
20590+#include <asm/cpufeature.h>
20591+#include <asm/alternative-asm.h>
20592
20593 #ifdef CONFIG_PARAVIRT
20594 #include <asm/asm-offsets.h>
20595@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20596 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20597 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20598 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20599+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20600+L3_VMALLOC_START = pud_index(VMALLOC_START)
20601+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20602+L3_VMALLOC_END = pud_index(VMALLOC_END)
20603+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20604+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20605
20606 .text
20607 __HEAD
20608@@ -89,11 +97,23 @@ startup_64:
20609 * Fixup the physical addresses in the page table
20610 */
20611 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
20612+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20613+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20614+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20615+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20616+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20617
20618- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20619- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20620+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
20621+#ifndef CONFIG_XEN
20622+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
20623+#endif
20624
20625- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20626+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20627+
20628+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20629+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
20630+
20631+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20632
20633 /*
20634 * Set up the identity mapping for the switchover. These
20635@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
20636 movq $(init_level4_pgt - __START_KERNEL_map), %rax
20637 1:
20638
20639- /* Enable PAE mode and PGE */
20640- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
20641+ /* Enable PAE mode and PSE/PGE */
20642+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
20643 movq %rcx, %cr4
20644
20645 /* Setup early boot stage 4 level pagetables. */
20646@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
20647 movl $MSR_EFER, %ecx
20648 rdmsr
20649 btsl $_EFER_SCE, %eax /* Enable System Call */
20650- btl $20,%edi /* No Execute supported? */
20651+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20652 jnc 1f
20653 btsl $_EFER_NX, %eax
20654 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
20655+ leaq init_level4_pgt(%rip), %rdi
20656+#ifndef CONFIG_EFI
20657+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20658+#endif
20659+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20660+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20661+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20662+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20663 1: wrmsr /* Make changes effective */
20664
20665 /* Setup cr0 */
20666@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
20667 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
20668 * address given in m16:64.
20669 */
20670+ pax_set_fptr_mask
20671 movq initial_code(%rip),%rax
20672 pushq $0 # fake return address to stop unwinder
20673 pushq $__KERNEL_CS # set correct cs
20674@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
20675 call dump_stack
20676 #ifdef CONFIG_KALLSYMS
20677 leaq early_idt_ripmsg(%rip),%rdi
20678- movq 40(%rsp),%rsi # %rip again
20679+ movq 88(%rsp),%rsi # %rip again
20680 call __print_symbol
20681 #endif
20682 #endif /* EARLY_PRINTK */
20683@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
20684 early_recursion_flag:
20685 .long 0
20686
20687+ .section .rodata,"a",@progbits
20688 #ifdef CONFIG_EARLY_PRINTK
20689 early_idt_msg:
20690 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20691@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
20692 NEXT_PAGE(early_dynamic_pgts)
20693 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
20694
20695- .data
20696+ .section .rodata,"a",@progbits
20697
20698-#ifndef CONFIG_XEN
20699 NEXT_PAGE(init_level4_pgt)
20700- .fill 512,8,0
20701-#else
20702-NEXT_PAGE(init_level4_pgt)
20703- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20704 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20705 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20706+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20707+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20708+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20709+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20710+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20711+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20712 .org init_level4_pgt + L4_START_KERNEL*8, 0
20713 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20714 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20715
20716+#ifdef CONFIG_PAX_PER_CPU_PGD
20717+NEXT_PAGE(cpu_pgd)
20718+ .rept NR_CPUS
20719+ .fill 512,8,0
20720+ .endr
20721+#endif
20722+
20723 NEXT_PAGE(level3_ident_pgt)
20724 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20725+#ifdef CONFIG_XEN
20726 .fill 511, 8, 0
20727+#else
20728+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20729+ .fill 510,8,0
20730+#endif
20731+
20732+NEXT_PAGE(level3_vmalloc_start_pgt)
20733+ .fill 512,8,0
20734+
20735+NEXT_PAGE(level3_vmalloc_end_pgt)
20736+ .fill 512,8,0
20737+
20738+NEXT_PAGE(level3_vmemmap_pgt)
20739+ .fill L3_VMEMMAP_START,8,0
20740+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20741+
20742 NEXT_PAGE(level2_ident_pgt)
20743- /* Since I easily can, map the first 1G.
20744+ /* Since I easily can, map the first 2G.
20745 * Don't set NX because code runs from these pages.
20746 */
20747- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20748-#endif
20749+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20750
20751 NEXT_PAGE(level3_kernel_pgt)
20752 .fill L3_START_KERNEL,8,0
20753@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
20754 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20755 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20756
20757+NEXT_PAGE(level2_vmemmap_pgt)
20758+ .fill 512,8,0
20759+
20760 NEXT_PAGE(level2_kernel_pgt)
20761 /*
20762 * 512 MB kernel mapping. We spend a full page on this pagetable
20763@@ -488,39 +544,64 @@ NEXT_PAGE(level2_kernel_pgt)
20764 KERNEL_IMAGE_SIZE/PMD_SIZE)
20765
20766 NEXT_PAGE(level2_fixmap_pgt)
20767- .fill 506,8,0
20768- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20769- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20770- .fill 5,8,0
20771+ .fill 507,8,0
20772+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20773+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20774+ .fill 4,8,0
20775
20776-NEXT_PAGE(level1_fixmap_pgt)
20777+NEXT_PAGE(level1_vsyscall_pgt)
20778 .fill 512,8,0
20779
20780 #undef PMDS
20781
20782- .data
20783+ .align PAGE_SIZE
20784+ENTRY(cpu_gdt_table)
20785+ .rept NR_CPUS
20786+ .quad 0x0000000000000000 /* NULL descriptor */
20787+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20788+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20789+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20790+ .quad 0x00cffb000000ffff /* __USER32_CS */
20791+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20792+ .quad 0x00affb000000ffff /* __USER_CS */
20793+
20794+#ifdef CONFIG_PAX_KERNEXEC
20795+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20796+#else
20797+ .quad 0x0 /* unused */
20798+#endif
20799+
20800+ .quad 0,0 /* TSS */
20801+ .quad 0,0 /* LDT */
20802+ .quad 0,0,0 /* three TLS descriptors */
20803+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20804+ /* asm/segment.h:GDT_ENTRIES must match this */
20805+
20806+ /* zero the remaining page */
20807+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20808+ .endr
20809+
20810 .align 16
20811 .globl early_gdt_descr
20812 early_gdt_descr:
20813 .word GDT_ENTRIES*8-1
20814 early_gdt_descr_base:
20815- .quad INIT_PER_CPU_VAR(gdt_page)
20816+ .quad cpu_gdt_table
20817
20818 ENTRY(phys_base)
20819 /* This must match the first entry in level2_kernel_pgt */
20820 .quad 0x0000000000000000
20821
20822 #include "../../x86/xen/xen-head.S"
20823-
20824- .section .bss, "aw", @nobits
20825- .align L1_CACHE_BYTES
20826-ENTRY(idt_table)
20827- .skip IDT_ENTRIES * 16
20828
20829- .align L1_CACHE_BYTES
20830-ENTRY(nmi_idt_table)
20831- .skip IDT_ENTRIES * 16
20832-
20833- __PAGE_ALIGNED_BSS
20834+ .section .rodata,"a",@progbits
20835 NEXT_PAGE(empty_zero_page)
20836 .skip PAGE_SIZE
20837+
20838+ .align L1_CACHE_BYTES
20839+ENTRY(idt_table)
20840+ .fill 512,8,0
20841+
20842+ .align L1_CACHE_BYTES
20843+ENTRY(nmi_idt_table)
20844+ .fill 512,8,0
20845diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20846index 0fa6912..37fce70 100644
20847--- a/arch/x86/kernel/i386_ksyms_32.c
20848+++ b/arch/x86/kernel/i386_ksyms_32.c
20849@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20850 EXPORT_SYMBOL(cmpxchg8b_emu);
20851 #endif
20852
20853+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20854+
20855 /* Networking helper routines. */
20856 EXPORT_SYMBOL(csum_partial_copy_generic);
20857+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20858+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20859
20860 EXPORT_SYMBOL(__get_user_1);
20861 EXPORT_SYMBOL(__get_user_2);
20862@@ -37,3 +41,7 @@ EXPORT_SYMBOL(strstr);
20863
20864 EXPORT_SYMBOL(csum_partial);
20865 EXPORT_SYMBOL(empty_zero_page);
20866+
20867+#ifdef CONFIG_PAX_KERNEXEC
20868+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20869+#endif
20870diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20871index cb33909..1163b40 100644
20872--- a/arch/x86/kernel/i387.c
20873+++ b/arch/x86/kernel/i387.c
20874@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20875 static inline bool interrupted_user_mode(void)
20876 {
20877 struct pt_regs *regs = get_irq_regs();
20878- return regs && user_mode_vm(regs);
20879+ return regs && user_mode(regs);
20880 }
20881
20882 /*
20883diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20884index 9a5c460..84868423 100644
20885--- a/arch/x86/kernel/i8259.c
20886+++ b/arch/x86/kernel/i8259.c
20887@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
20888 static void make_8259A_irq(unsigned int irq)
20889 {
20890 disable_irq_nosync(irq);
20891- io_apic_irqs &= ~(1<<irq);
20892+ io_apic_irqs &= ~(1UL<<irq);
20893 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
20894 i8259A_chip.name);
20895 enable_irq(irq);
20896@@ -209,7 +209,7 @@ spurious_8259A_irq:
20897 "spurious 8259A interrupt: IRQ%d.\n", irq);
20898 spurious_irq_mask |= irqmask;
20899 }
20900- atomic_inc(&irq_err_count);
20901+ atomic_inc_unchecked(&irq_err_count);
20902 /*
20903 * Theoretically we do not have to handle this IRQ,
20904 * but in Linux this does not cause problems and is
20905@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20906 /* (slave's support for AEOI in flat mode is to be investigated) */
20907 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20908
20909+ pax_open_kernel();
20910 if (auto_eoi)
20911 /*
20912 * In AEOI mode we just have to mask the interrupt
20913 * when acking.
20914 */
20915- i8259A_chip.irq_mask_ack = disable_8259A_irq;
20916+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20917 else
20918- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20919+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20920+ pax_close_kernel();
20921
20922 udelay(100); /* wait for 8259A to initialize */
20923
20924diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20925index a979b5b..1d6db75 100644
20926--- a/arch/x86/kernel/io_delay.c
20927+++ b/arch/x86/kernel/io_delay.c
20928@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20929 * Quirk table for systems that misbehave (lock up, etc.) if port
20930 * 0x80 is used:
20931 */
20932-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20933+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20934 {
20935 .callback = dmi_io_delay_0xed_port,
20936 .ident = "Compaq Presario V6000",
20937diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20938index 4ddaf66..6292f4e 100644
20939--- a/arch/x86/kernel/ioport.c
20940+++ b/arch/x86/kernel/ioport.c
20941@@ -6,6 +6,7 @@
20942 #include <linux/sched.h>
20943 #include <linux/kernel.h>
20944 #include <linux/capability.h>
20945+#include <linux/security.h>
20946 #include <linux/errno.h>
20947 #include <linux/types.h>
20948 #include <linux/ioport.h>
20949@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20950
20951 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20952 return -EINVAL;
20953+#ifdef CONFIG_GRKERNSEC_IO
20954+ if (turn_on && grsec_disable_privio) {
20955+ gr_handle_ioperm();
20956+ return -EPERM;
20957+ }
20958+#endif
20959 if (turn_on && !capable(CAP_SYS_RAWIO))
20960 return -EPERM;
20961
20962@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20963 * because the ->io_bitmap_max value must match the bitmap
20964 * contents:
20965 */
20966- tss = &per_cpu(init_tss, get_cpu());
20967+ tss = init_tss + get_cpu();
20968
20969 if (turn_on)
20970 bitmap_clear(t->io_bitmap_ptr, from, num);
20971@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
20972 return -EINVAL;
20973 /* Trying to gain more privileges? */
20974 if (level > old) {
20975+#ifdef CONFIG_GRKERNSEC_IO
20976+ if (grsec_disable_privio) {
20977+ gr_handle_iopl();
20978+ return -EPERM;
20979+ }
20980+#endif
20981 if (!capable(CAP_SYS_RAWIO))
20982 return -EPERM;
20983 }
20984diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20985index ac0631d..ff7cb62 100644
20986--- a/arch/x86/kernel/irq.c
20987+++ b/arch/x86/kernel/irq.c
20988@@ -18,7 +18,7 @@
20989 #include <asm/mce.h>
20990 #include <asm/hw_irq.h>
20991
20992-atomic_t irq_err_count;
20993+atomic_unchecked_t irq_err_count;
20994
20995 /* Function pointer for generic interrupt vector handling */
20996 void (*x86_platform_ipi_callback)(void) = NULL;
20997@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20998 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20999 seq_printf(p, " Machine check polls\n");
21000 #endif
21001- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
21002+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
21003 #if defined(CONFIG_X86_IO_APIC)
21004- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
21005+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
21006 #endif
21007 return 0;
21008 }
21009@@ -164,7 +164,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
21010
21011 u64 arch_irq_stat(void)
21012 {
21013- u64 sum = atomic_read(&irq_err_count);
21014+ u64 sum = atomic_read_unchecked(&irq_err_count);
21015 return sum;
21016 }
21017
21018diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
21019index 344faf8..355f60d 100644
21020--- a/arch/x86/kernel/irq_32.c
21021+++ b/arch/x86/kernel/irq_32.c
21022@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
21023 __asm__ __volatile__("andl %%esp,%0" :
21024 "=r" (sp) : "0" (THREAD_SIZE - 1));
21025
21026- return sp < (sizeof(struct thread_info) + STACK_WARN);
21027+ return sp < STACK_WARN;
21028 }
21029
21030 static void print_stack_overflow(void)
21031@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
21032 * per-CPU IRQ handling contexts (thread information and stack)
21033 */
21034 union irq_ctx {
21035- struct thread_info tinfo;
21036- u32 stack[THREAD_SIZE/sizeof(u32)];
21037+ unsigned long previous_esp;
21038+ u32 stack[THREAD_SIZE/sizeof(u32)];
21039 } __attribute__((aligned(THREAD_SIZE)));
21040
21041 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
21042@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
21043 static inline int
21044 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21045 {
21046- union irq_ctx *curctx, *irqctx;
21047+ union irq_ctx *irqctx;
21048 u32 *isp, arg1, arg2;
21049
21050- curctx = (union irq_ctx *) current_thread_info();
21051 irqctx = __this_cpu_read(hardirq_ctx);
21052
21053 /*
21054@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21055 * handler) we can't do that and just have to keep using the
21056 * current stack (which is the irq stack already after all)
21057 */
21058- if (unlikely(curctx == irqctx))
21059+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
21060 return 0;
21061
21062 /* build the stack frame on the IRQ stack */
21063- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21064- irqctx->tinfo.task = curctx->tinfo.task;
21065- irqctx->tinfo.previous_esp = current_stack_pointer;
21066+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21067+ irqctx->previous_esp = current_stack_pointer;
21068
21069- /* Copy the preempt_count so that the [soft]irq checks work. */
21070- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
21071+#ifdef CONFIG_PAX_MEMORY_UDEREF
21072+ __set_fs(MAKE_MM_SEG(0));
21073+#endif
21074
21075 if (unlikely(overflow))
21076 call_on_stack(print_stack_overflow, isp);
21077@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21078 : "0" (irq), "1" (desc), "2" (isp),
21079 "D" (desc->handle_irq)
21080 : "memory", "cc", "ecx");
21081+
21082+#ifdef CONFIG_PAX_MEMORY_UDEREF
21083+ __set_fs(current_thread_info()->addr_limit);
21084+#endif
21085+
21086 return 1;
21087 }
21088
21089@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21090 */
21091 void __cpuinit irq_ctx_init(int cpu)
21092 {
21093- union irq_ctx *irqctx;
21094-
21095 if (per_cpu(hardirq_ctx, cpu))
21096 return;
21097
21098- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21099- THREADINFO_GFP,
21100- THREAD_SIZE_ORDER));
21101- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21102- irqctx->tinfo.cpu = cpu;
21103- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
21104- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21105-
21106- per_cpu(hardirq_ctx, cpu) = irqctx;
21107-
21108- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21109- THREADINFO_GFP,
21110- THREAD_SIZE_ORDER));
21111- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21112- irqctx->tinfo.cpu = cpu;
21113- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21114-
21115- per_cpu(softirq_ctx, cpu) = irqctx;
21116+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21117+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21118+
21119+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21120+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21121
21122 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21123 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21124@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
21125 asmlinkage void do_softirq(void)
21126 {
21127 unsigned long flags;
21128- struct thread_info *curctx;
21129 union irq_ctx *irqctx;
21130 u32 *isp;
21131
21132@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
21133 local_irq_save(flags);
21134
21135 if (local_softirq_pending()) {
21136- curctx = current_thread_info();
21137 irqctx = __this_cpu_read(softirq_ctx);
21138- irqctx->tinfo.task = curctx->task;
21139- irqctx->tinfo.previous_esp = current_stack_pointer;
21140+ irqctx->previous_esp = current_stack_pointer;
21141
21142 /* build the stack frame on the softirq stack */
21143- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21144+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21145+
21146+#ifdef CONFIG_PAX_MEMORY_UDEREF
21147+ __set_fs(MAKE_MM_SEG(0));
21148+#endif
21149
21150 call_on_stack(__do_softirq, isp);
21151+
21152+#ifdef CONFIG_PAX_MEMORY_UDEREF
21153+ __set_fs(current_thread_info()->addr_limit);
21154+#endif
21155+
21156 /*
21157 * Shouldn't happen, we returned above if in_interrupt():
21158 */
21159@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21160 if (unlikely(!desc))
21161 return false;
21162
21163- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21164+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21165 if (unlikely(overflow))
21166 print_stack_overflow();
21167 desc->handle_irq(irq, desc);
21168diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21169index d04d3ec..ea4b374 100644
21170--- a/arch/x86/kernel/irq_64.c
21171+++ b/arch/x86/kernel/irq_64.c
21172@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21173 u64 estack_top, estack_bottom;
21174 u64 curbase = (u64)task_stack_page(current);
21175
21176- if (user_mode_vm(regs))
21177+ if (user_mode(regs))
21178 return;
21179
21180 if (regs->sp >= curbase + sizeof(struct thread_info) +
21181diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21182index dc1404b..bbc43e7 100644
21183--- a/arch/x86/kernel/kdebugfs.c
21184+++ b/arch/x86/kernel/kdebugfs.c
21185@@ -27,7 +27,7 @@ struct setup_data_node {
21186 u32 len;
21187 };
21188
21189-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21190+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21191 size_t count, loff_t *ppos)
21192 {
21193 struct setup_data_node *node = file->private_data;
21194diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21195index 836f832..a8bda67 100644
21196--- a/arch/x86/kernel/kgdb.c
21197+++ b/arch/x86/kernel/kgdb.c
21198@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21199 #ifdef CONFIG_X86_32
21200 switch (regno) {
21201 case GDB_SS:
21202- if (!user_mode_vm(regs))
21203+ if (!user_mode(regs))
21204 *(unsigned long *)mem = __KERNEL_DS;
21205 break;
21206 case GDB_SP:
21207- if (!user_mode_vm(regs))
21208+ if (!user_mode(regs))
21209 *(unsigned long *)mem = kernel_stack_pointer(regs);
21210 break;
21211 case GDB_GS:
21212@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21213 bp->attr.bp_addr = breakinfo[breakno].addr;
21214 bp->attr.bp_len = breakinfo[breakno].len;
21215 bp->attr.bp_type = breakinfo[breakno].type;
21216- info->address = breakinfo[breakno].addr;
21217+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21218+ info->address = ktla_ktva(breakinfo[breakno].addr);
21219+ else
21220+ info->address = breakinfo[breakno].addr;
21221 info->len = breakinfo[breakno].len;
21222 info->type = breakinfo[breakno].type;
21223 val = arch_install_hw_breakpoint(bp);
21224@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21225 case 'k':
21226 /* clear the trace bit */
21227 linux_regs->flags &= ~X86_EFLAGS_TF;
21228- atomic_set(&kgdb_cpu_doing_single_step, -1);
21229+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21230
21231 /* set the trace bit if we're stepping */
21232 if (remcomInBuffer[0] == 's') {
21233 linux_regs->flags |= X86_EFLAGS_TF;
21234- atomic_set(&kgdb_cpu_doing_single_step,
21235+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21236 raw_smp_processor_id());
21237 }
21238
21239@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21240
21241 switch (cmd) {
21242 case DIE_DEBUG:
21243- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21244+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21245 if (user_mode(regs))
21246 return single_step_cont(regs, args);
21247 break;
21248@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21249 #endif /* CONFIG_DEBUG_RODATA */
21250
21251 bpt->type = BP_BREAKPOINT;
21252- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21253+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21254 BREAK_INSTR_SIZE);
21255 if (err)
21256 return err;
21257- err = probe_kernel_write((char *)bpt->bpt_addr,
21258+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21259 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21260 #ifdef CONFIG_DEBUG_RODATA
21261 if (!err)
21262@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21263 return -EBUSY;
21264 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21265 BREAK_INSTR_SIZE);
21266- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21267+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21268 if (err)
21269 return err;
21270 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21271@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21272 if (mutex_is_locked(&text_mutex))
21273 goto knl_write;
21274 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21275- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21276+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21277 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21278 goto knl_write;
21279 return err;
21280 knl_write:
21281 #endif /* CONFIG_DEBUG_RODATA */
21282- return probe_kernel_write((char *)bpt->bpt_addr,
21283+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21284 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21285 }
21286
21287diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
21288index 211bce4..6e2580a 100644
21289--- a/arch/x86/kernel/kprobes/core.c
21290+++ b/arch/x86/kernel/kprobes/core.c
21291@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21292 s32 raddr;
21293 } __packed *insn;
21294
21295- insn = (struct __arch_relative_insn *)from;
21296+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21297+
21298+ pax_open_kernel();
21299 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21300 insn->op = op;
21301+ pax_close_kernel();
21302 }
21303
21304 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21305@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21306 kprobe_opcode_t opcode;
21307 kprobe_opcode_t *orig_opcodes = opcodes;
21308
21309- if (search_exception_tables((unsigned long)opcodes))
21310+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21311 return 0; /* Page fault may occur on this address. */
21312
21313 retry:
21314@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21315 * for the first byte, we can recover the original instruction
21316 * from it and kp->opcode.
21317 */
21318- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21319+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21320 buf[0] = kp->opcode;
21321- return (unsigned long)buf;
21322+ return ktva_ktla((unsigned long)buf);
21323 }
21324
21325 /*
21326@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21327 /* Another subsystem puts a breakpoint, failed to recover */
21328 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21329 return 0;
21330+ pax_open_kernel();
21331 memcpy(dest, insn.kaddr, insn.length);
21332+ pax_close_kernel();
21333
21334 #ifdef CONFIG_X86_64
21335 if (insn_rip_relative(&insn)) {
21336@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21337 return 0;
21338 }
21339 disp = (u8 *) dest + insn_offset_displacement(&insn);
21340+ pax_open_kernel();
21341 *(s32 *) disp = (s32) newdisp;
21342+ pax_close_kernel();
21343 }
21344 #endif
21345 return insn.length;
21346@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21347 * nor set current_kprobe, because it doesn't use single
21348 * stepping.
21349 */
21350- regs->ip = (unsigned long)p->ainsn.insn;
21351+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21352 preempt_enable_no_resched();
21353 return;
21354 }
21355@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21356 regs->flags &= ~X86_EFLAGS_IF;
21357 /* single step inline if the instruction is an int3 */
21358 if (p->opcode == BREAKPOINT_INSTRUCTION)
21359- regs->ip = (unsigned long)p->addr;
21360+ regs->ip = ktla_ktva((unsigned long)p->addr);
21361 else
21362- regs->ip = (unsigned long)p->ainsn.insn;
21363+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21364 }
21365
21366 /*
21367@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21368 setup_singlestep(p, regs, kcb, 0);
21369 return 1;
21370 }
21371- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21372+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21373 /*
21374 * The breakpoint instruction was removed right
21375 * after we hit it. Another cpu has removed
21376@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21377 " movq %rax, 152(%rsp)\n"
21378 RESTORE_REGS_STRING
21379 " popfq\n"
21380+#ifdef KERNEXEC_PLUGIN
21381+ " btsq $63,(%rsp)\n"
21382+#endif
21383 #else
21384 " pushf\n"
21385 SAVE_REGS_STRING
21386@@ -779,7 +789,7 @@ static void __kprobes
21387 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21388 {
21389 unsigned long *tos = stack_addr(regs);
21390- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21391+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21392 unsigned long orig_ip = (unsigned long)p->addr;
21393 kprobe_opcode_t *insn = p->ainsn.insn;
21394
21395@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21396 struct die_args *args = data;
21397 int ret = NOTIFY_DONE;
21398
21399- if (args->regs && user_mode_vm(args->regs))
21400+ if (args->regs && user_mode(args->regs))
21401 return ret;
21402
21403 switch (val) {
21404diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
21405index 76dc6f0..66bdfc3 100644
21406--- a/arch/x86/kernel/kprobes/opt.c
21407+++ b/arch/x86/kernel/kprobes/opt.c
21408@@ -79,6 +79,7 @@ found:
21409 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
21410 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
21411 {
21412+ pax_open_kernel();
21413 #ifdef CONFIG_X86_64
21414 *addr++ = 0x48;
21415 *addr++ = 0xbf;
21416@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
21417 *addr++ = 0xb8;
21418 #endif
21419 *(unsigned long *)addr = val;
21420+ pax_close_kernel();
21421 }
21422
21423 static void __used __kprobes kprobes_optinsn_template_holder(void)
21424@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21425 * Verify if the address gap is in 2GB range, because this uses
21426 * a relative jump.
21427 */
21428- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21429+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21430 if (abs(rel) > 0x7fffffff)
21431 return -ERANGE;
21432
21433@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21434 op->optinsn.size = ret;
21435
21436 /* Copy arch-dep-instance from template */
21437- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21438+ pax_open_kernel();
21439+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21440+ pax_close_kernel();
21441
21442 /* Set probe information */
21443 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21444
21445 /* Set probe function call */
21446- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21447+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21448
21449 /* Set returning jmp instruction at the tail of out-of-line buffer */
21450- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21451+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21452 (u8 *)op->kp.addr + op->optinsn.size);
21453
21454 flush_icache_range((unsigned long) buf,
21455@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21456 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21457
21458 /* Backup instructions which will be replaced by jump address */
21459- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21460+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21461 RELATIVE_ADDR_SIZE);
21462
21463 insn_buf[0] = RELATIVEJUMP_OPCODE;
21464@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21465 /* This kprobe is really able to run optimized path. */
21466 op = container_of(p, struct optimized_kprobe, kp);
21467 /* Detour through copied instructions */
21468- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21469+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21470 if (!reenter)
21471 reset_current_kprobe();
21472 preempt_enable_no_resched();
21473diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21474index cd6d9a5..16245a4 100644
21475--- a/arch/x86/kernel/kvm.c
21476+++ b/arch/x86/kernel/kvm.c
21477@@ -455,7 +455,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21478 return NOTIFY_OK;
21479 }
21480
21481-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21482+static struct notifier_block kvm_cpu_notifier = {
21483 .notifier_call = kvm_cpu_notify,
21484 };
21485 #endif
21486diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21487index ebc9873..1b9724b 100644
21488--- a/arch/x86/kernel/ldt.c
21489+++ b/arch/x86/kernel/ldt.c
21490@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21491 if (reload) {
21492 #ifdef CONFIG_SMP
21493 preempt_disable();
21494- load_LDT(pc);
21495+ load_LDT_nolock(pc);
21496 if (!cpumask_equal(mm_cpumask(current->mm),
21497 cpumask_of(smp_processor_id())))
21498 smp_call_function(flush_ldt, current->mm, 1);
21499 preempt_enable();
21500 #else
21501- load_LDT(pc);
21502+ load_LDT_nolock(pc);
21503 #endif
21504 }
21505 if (oldsize) {
21506@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21507 return err;
21508
21509 for (i = 0; i < old->size; i++)
21510- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21511+ write_ldt_entry(new->ldt, i, old->ldt + i);
21512 return 0;
21513 }
21514
21515@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21516 retval = copy_ldt(&mm->context, &old_mm->context);
21517 mutex_unlock(&old_mm->context.lock);
21518 }
21519+
21520+ if (tsk == current) {
21521+ mm->context.vdso = 0;
21522+
21523+#ifdef CONFIG_X86_32
21524+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21525+ mm->context.user_cs_base = 0UL;
21526+ mm->context.user_cs_limit = ~0UL;
21527+
21528+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21529+ cpus_clear(mm->context.cpu_user_cs_mask);
21530+#endif
21531+
21532+#endif
21533+#endif
21534+
21535+ }
21536+
21537 return retval;
21538 }
21539
21540@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21541 }
21542 }
21543
21544+#ifdef CONFIG_PAX_SEGMEXEC
21545+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21546+ error = -EINVAL;
21547+ goto out_unlock;
21548+ }
21549+#endif
21550+
21551 fill_ldt(&ldt, &ldt_info);
21552 if (oldmode)
21553 ldt.avl = 0;
21554diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21555index 5b19e4d..6476a76 100644
21556--- a/arch/x86/kernel/machine_kexec_32.c
21557+++ b/arch/x86/kernel/machine_kexec_32.c
21558@@ -26,7 +26,7 @@
21559 #include <asm/cacheflush.h>
21560 #include <asm/debugreg.h>
21561
21562-static void set_idt(void *newidt, __u16 limit)
21563+static void set_idt(struct desc_struct *newidt, __u16 limit)
21564 {
21565 struct desc_ptr curidt;
21566
21567@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21568 }
21569
21570
21571-static void set_gdt(void *newgdt, __u16 limit)
21572+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21573 {
21574 struct desc_ptr curgdt;
21575
21576@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21577 }
21578
21579 control_page = page_address(image->control_code_page);
21580- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21581+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21582
21583 relocate_kernel_ptr = control_page;
21584 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21585diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21586index 22db92b..d546bec 100644
21587--- a/arch/x86/kernel/microcode_core.c
21588+++ b/arch/x86/kernel/microcode_core.c
21589@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21590 return NOTIFY_OK;
21591 }
21592
21593-static struct notifier_block __refdata mc_cpu_notifier = {
21594+static struct notifier_block mc_cpu_notifier = {
21595 .notifier_call = mc_cpu_callback,
21596 };
21597
21598diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21599index 5fb2ceb..3ae90bb 100644
21600--- a/arch/x86/kernel/microcode_intel.c
21601+++ b/arch/x86/kernel/microcode_intel.c
21602@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21603
21604 static int get_ucode_user(void *to, const void *from, size_t n)
21605 {
21606- return copy_from_user(to, from, n);
21607+ return copy_from_user(to, (const void __force_user *)from, n);
21608 }
21609
21610 static enum ucode_state
21611 request_microcode_user(int cpu, const void __user *buf, size_t size)
21612 {
21613- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21614+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21615 }
21616
21617 static void microcode_fini_cpu(int cpu)
21618diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21619index 216a4d7..228255a 100644
21620--- a/arch/x86/kernel/module.c
21621+++ b/arch/x86/kernel/module.c
21622@@ -43,15 +43,60 @@ do { \
21623 } while (0)
21624 #endif
21625
21626-void *module_alloc(unsigned long size)
21627+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21628 {
21629- if (PAGE_ALIGN(size) > MODULES_LEN)
21630+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21631 return NULL;
21632 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21633- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21634+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21635 -1, __builtin_return_address(0));
21636 }
21637
21638+void *module_alloc(unsigned long size)
21639+{
21640+
21641+#ifdef CONFIG_PAX_KERNEXEC
21642+ return __module_alloc(size, PAGE_KERNEL);
21643+#else
21644+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21645+#endif
21646+
21647+}
21648+
21649+#ifdef CONFIG_PAX_KERNEXEC
21650+#ifdef CONFIG_X86_32
21651+void *module_alloc_exec(unsigned long size)
21652+{
21653+ struct vm_struct *area;
21654+
21655+ if (size == 0)
21656+ return NULL;
21657+
21658+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21659+ return area ? area->addr : NULL;
21660+}
21661+EXPORT_SYMBOL(module_alloc_exec);
21662+
21663+void module_free_exec(struct module *mod, void *module_region)
21664+{
21665+ vunmap(module_region);
21666+}
21667+EXPORT_SYMBOL(module_free_exec);
21668+#else
21669+void module_free_exec(struct module *mod, void *module_region)
21670+{
21671+ module_free(mod, module_region);
21672+}
21673+EXPORT_SYMBOL(module_free_exec);
21674+
21675+void *module_alloc_exec(unsigned long size)
21676+{
21677+ return __module_alloc(size, PAGE_KERNEL_RX);
21678+}
21679+EXPORT_SYMBOL(module_alloc_exec);
21680+#endif
21681+#endif
21682+
21683 #ifdef CONFIG_X86_32
21684 int apply_relocate(Elf32_Shdr *sechdrs,
21685 const char *strtab,
21686@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21687 unsigned int i;
21688 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21689 Elf32_Sym *sym;
21690- uint32_t *location;
21691+ uint32_t *plocation, location;
21692
21693 DEBUGP("Applying relocate section %u to %u\n",
21694 relsec, sechdrs[relsec].sh_info);
21695 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21696 /* This is where to make the change */
21697- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21698- + rel[i].r_offset;
21699+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21700+ location = (uint32_t)plocation;
21701+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21702+ plocation = ktla_ktva((void *)plocation);
21703 /* This is the symbol it is referring to. Note that all
21704 undefined symbols have been resolved. */
21705 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21706@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21707 switch (ELF32_R_TYPE(rel[i].r_info)) {
21708 case R_386_32:
21709 /* We add the value into the location given */
21710- *location += sym->st_value;
21711+ pax_open_kernel();
21712+ *plocation += sym->st_value;
21713+ pax_close_kernel();
21714 break;
21715 case R_386_PC32:
21716 /* Add the value, subtract its position */
21717- *location += sym->st_value - (uint32_t)location;
21718+ pax_open_kernel();
21719+ *plocation += sym->st_value - location;
21720+ pax_close_kernel();
21721 break;
21722 default:
21723 pr_err("%s: Unknown relocation: %u\n",
21724@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21725 case R_X86_64_NONE:
21726 break;
21727 case R_X86_64_64:
21728+ pax_open_kernel();
21729 *(u64 *)loc = val;
21730+ pax_close_kernel();
21731 break;
21732 case R_X86_64_32:
21733+ pax_open_kernel();
21734 *(u32 *)loc = val;
21735+ pax_close_kernel();
21736 if (val != *(u32 *)loc)
21737 goto overflow;
21738 break;
21739 case R_X86_64_32S:
21740+ pax_open_kernel();
21741 *(s32 *)loc = val;
21742+ pax_close_kernel();
21743 if ((s64)val != *(s32 *)loc)
21744 goto overflow;
21745 break;
21746 case R_X86_64_PC32:
21747 val -= (u64)loc;
21748+ pax_open_kernel();
21749 *(u32 *)loc = val;
21750+ pax_close_kernel();
21751+
21752 #if 0
21753 if ((s64)val != *(s32 *)loc)
21754 goto overflow;
21755diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21756index ce13049..e2e9c3c 100644
21757--- a/arch/x86/kernel/msr.c
21758+++ b/arch/x86/kernel/msr.c
21759@@ -233,7 +233,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21760 return notifier_from_errno(err);
21761 }
21762
21763-static struct notifier_block __refdata msr_class_cpu_notifier = {
21764+static struct notifier_block msr_class_cpu_notifier = {
21765 .notifier_call = msr_class_cpu_callback,
21766 };
21767
21768diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21769index 6030805..2d33f21 100644
21770--- a/arch/x86/kernel/nmi.c
21771+++ b/arch/x86/kernel/nmi.c
21772@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21773 return handled;
21774 }
21775
21776-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21777+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21778 {
21779 struct nmi_desc *desc = nmi_to_desc(type);
21780 unsigned long flags;
21781@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21782 * event confuses some handlers (kdump uses this flag)
21783 */
21784 if (action->flags & NMI_FLAG_FIRST)
21785- list_add_rcu(&action->list, &desc->head);
21786+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21787 else
21788- list_add_tail_rcu(&action->list, &desc->head);
21789+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21790
21791 spin_unlock_irqrestore(&desc->lock, flags);
21792 return 0;
21793@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21794 if (!strcmp(n->name, name)) {
21795 WARN(in_nmi(),
21796 "Trying to free NMI (%s) from NMI context!\n", n->name);
21797- list_del_rcu(&n->list);
21798+ pax_list_del_rcu((struct list_head *)&n->list);
21799 break;
21800 }
21801 }
21802@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21803 dotraplinkage notrace __kprobes void
21804 do_nmi(struct pt_regs *regs, long error_code)
21805 {
21806+
21807+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21808+ if (!user_mode(regs)) {
21809+ unsigned long cs = regs->cs & 0xFFFF;
21810+ unsigned long ip = ktva_ktla(regs->ip);
21811+
21812+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21813+ regs->ip = ip;
21814+ }
21815+#endif
21816+
21817 nmi_nesting_preprocess(regs);
21818
21819 nmi_enter();
21820diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21821index 6d9582e..f746287 100644
21822--- a/arch/x86/kernel/nmi_selftest.c
21823+++ b/arch/x86/kernel/nmi_selftest.c
21824@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21825 {
21826 /* trap all the unknown NMIs we may generate */
21827 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21828- __initdata);
21829+ __initconst);
21830 }
21831
21832 static void __init cleanup_nmi_testsuite(void)
21833@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21834 unsigned long timeout;
21835
21836 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21837- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21838+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21839 nmi_fail = FAILURE;
21840 return;
21841 }
21842diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21843index 676b8c7..870ba04 100644
21844--- a/arch/x86/kernel/paravirt-spinlocks.c
21845+++ b/arch/x86/kernel/paravirt-spinlocks.c
21846@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21847 arch_spin_lock(lock);
21848 }
21849
21850-struct pv_lock_ops pv_lock_ops = {
21851+struct pv_lock_ops pv_lock_ops __read_only = {
21852 #ifdef CONFIG_SMP
21853 .spin_is_locked = __ticket_spin_is_locked,
21854 .spin_is_contended = __ticket_spin_is_contended,
21855diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21856index cd6de64..27c6af0 100644
21857--- a/arch/x86/kernel/paravirt.c
21858+++ b/arch/x86/kernel/paravirt.c
21859@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21860 {
21861 return x;
21862 }
21863+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21864+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21865+#endif
21866
21867 void __init default_banner(void)
21868 {
21869@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21870 if (opfunc == NULL)
21871 /* If there's no function, patch it with a ud2a (BUG) */
21872 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21873- else if (opfunc == _paravirt_nop)
21874+ else if (opfunc == (void *)_paravirt_nop)
21875 /* If the operation is a nop, then nop the callsite */
21876 ret = paravirt_patch_nop();
21877
21878 /* identity functions just return their single argument */
21879- else if (opfunc == _paravirt_ident_32)
21880+ else if (opfunc == (void *)_paravirt_ident_32)
21881 ret = paravirt_patch_ident_32(insnbuf, len);
21882- else if (opfunc == _paravirt_ident_64)
21883+ else if (opfunc == (void *)_paravirt_ident_64)
21884 ret = paravirt_patch_ident_64(insnbuf, len);
21885+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21886+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21887+ ret = paravirt_patch_ident_64(insnbuf, len);
21888+#endif
21889
21890 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21891 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21892@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21893 if (insn_len > len || start == NULL)
21894 insn_len = len;
21895 else
21896- memcpy(insnbuf, start, insn_len);
21897+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21898
21899 return insn_len;
21900 }
21901@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
21902 return this_cpu_read(paravirt_lazy_mode);
21903 }
21904
21905-struct pv_info pv_info = {
21906+struct pv_info pv_info __read_only = {
21907 .name = "bare hardware",
21908 .paravirt_enabled = 0,
21909 .kernel_rpl = 0,
21910@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21911 #endif
21912 };
21913
21914-struct pv_init_ops pv_init_ops = {
21915+struct pv_init_ops pv_init_ops __read_only = {
21916 .patch = native_patch,
21917 };
21918
21919-struct pv_time_ops pv_time_ops = {
21920+struct pv_time_ops pv_time_ops __read_only = {
21921 .sched_clock = native_sched_clock,
21922 .steal_clock = native_steal_clock,
21923 };
21924
21925-struct pv_irq_ops pv_irq_ops = {
21926+struct pv_irq_ops pv_irq_ops __read_only = {
21927 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21928 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21929 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21930@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21931 #endif
21932 };
21933
21934-struct pv_cpu_ops pv_cpu_ops = {
21935+struct pv_cpu_ops pv_cpu_ops __read_only = {
21936 .cpuid = native_cpuid,
21937 .get_debugreg = native_get_debugreg,
21938 .set_debugreg = native_set_debugreg,
21939@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21940 .end_context_switch = paravirt_nop,
21941 };
21942
21943-struct pv_apic_ops pv_apic_ops = {
21944+struct pv_apic_ops pv_apic_ops __read_only= {
21945 #ifdef CONFIG_X86_LOCAL_APIC
21946 .startup_ipi_hook = paravirt_nop,
21947 #endif
21948 };
21949
21950-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21951+#ifdef CONFIG_X86_32
21952+#ifdef CONFIG_X86_PAE
21953+/* 64-bit pagetable entries */
21954+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21955+#else
21956 /* 32-bit pagetable entries */
21957 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21958+#endif
21959 #else
21960 /* 64-bit pagetable entries */
21961 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21962 #endif
21963
21964-struct pv_mmu_ops pv_mmu_ops = {
21965+struct pv_mmu_ops pv_mmu_ops __read_only = {
21966
21967 .read_cr2 = native_read_cr2,
21968 .write_cr2 = native_write_cr2,
21969@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21970 .make_pud = PTE_IDENT,
21971
21972 .set_pgd = native_set_pgd,
21973+ .set_pgd_batched = native_set_pgd_batched,
21974 #endif
21975 #endif /* PAGETABLE_LEVELS >= 3 */
21976
21977@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21978 },
21979
21980 .set_fixmap = native_set_fixmap,
21981+
21982+#ifdef CONFIG_PAX_KERNEXEC
21983+ .pax_open_kernel = native_pax_open_kernel,
21984+ .pax_close_kernel = native_pax_close_kernel,
21985+#endif
21986+
21987 };
21988
21989 EXPORT_SYMBOL_GPL(pv_time_ops);
21990diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
21991index 299d493..2ccb0ee 100644
21992--- a/arch/x86/kernel/pci-calgary_64.c
21993+++ b/arch/x86/kernel/pci-calgary_64.c
21994@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
21995 tce_space = be64_to_cpu(readq(target));
21996 tce_space = tce_space & TAR_SW_BITS;
21997
21998- tce_space = tce_space & (~specified_table_size);
21999+ tce_space = tce_space & (~(unsigned long)specified_table_size);
22000 info->tce_space = (u64 *)__va(tce_space);
22001 }
22002 }
22003diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
22004index 35ccf75..7a15747 100644
22005--- a/arch/x86/kernel/pci-iommu_table.c
22006+++ b/arch/x86/kernel/pci-iommu_table.c
22007@@ -2,7 +2,7 @@
22008 #include <asm/iommu_table.h>
22009 #include <linux/string.h>
22010 #include <linux/kallsyms.h>
22011-
22012+#include <linux/sched.h>
22013
22014 #define DEBUG 1
22015
22016diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
22017index 6c483ba..d10ce2f 100644
22018--- a/arch/x86/kernel/pci-swiotlb.c
22019+++ b/arch/x86/kernel/pci-swiotlb.c
22020@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
22021 void *vaddr, dma_addr_t dma_addr,
22022 struct dma_attrs *attrs)
22023 {
22024- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
22025+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
22026 }
22027
22028 static struct dma_map_ops swiotlb_dma_ops = {
22029diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
22030index 81a5f5e..20f8b58 100644
22031--- a/arch/x86/kernel/process.c
22032+++ b/arch/x86/kernel/process.c
22033@@ -36,7 +36,8 @@
22034 * section. Since TSS's are completely CPU-local, we want them
22035 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
22036 */
22037-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
22038+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
22039+EXPORT_SYMBOL(init_tss);
22040
22041 #ifdef CONFIG_X86_64
22042 static DEFINE_PER_CPU(unsigned char, is_idle);
22043@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
22044 task_xstate_cachep =
22045 kmem_cache_create("task_xstate", xstate_size,
22046 __alignof__(union thread_xstate),
22047- SLAB_PANIC | SLAB_NOTRACK, NULL);
22048+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
22049 }
22050
22051 /*
22052@@ -105,7 +106,7 @@ void exit_thread(void)
22053 unsigned long *bp = t->io_bitmap_ptr;
22054
22055 if (bp) {
22056- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
22057+ struct tss_struct *tss = init_tss + get_cpu();
22058
22059 t->io_bitmap_ptr = NULL;
22060 clear_thread_flag(TIF_IO_BITMAP);
22061@@ -125,6 +126,9 @@ void flush_thread(void)
22062 {
22063 struct task_struct *tsk = current;
22064
22065+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
22066+ loadsegment(gs, 0);
22067+#endif
22068 flush_ptrace_hw_breakpoint(tsk);
22069 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
22070 drop_init_fpu(tsk);
22071@@ -271,7 +275,7 @@ static void __exit_idle(void)
22072 void exit_idle(void)
22073 {
22074 /* idle loop has pid 0 */
22075- if (current->pid)
22076+ if (task_pid_nr(current))
22077 return;
22078 __exit_idle();
22079 }
22080@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
22081 return ret;
22082 }
22083 #endif
22084-void stop_this_cpu(void *dummy)
22085+__noreturn void stop_this_cpu(void *dummy)
22086 {
22087 local_irq_disable();
22088 /*
22089@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
22090 }
22091 early_param("idle", idle_setup);
22092
22093-unsigned long arch_align_stack(unsigned long sp)
22094+#ifdef CONFIG_PAX_RANDKSTACK
22095+void pax_randomize_kstack(struct pt_regs *regs)
22096 {
22097- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
22098- sp -= get_random_int() % 8192;
22099- return sp & ~0xf;
22100-}
22101+ struct thread_struct *thread = &current->thread;
22102+ unsigned long time;
22103
22104-unsigned long arch_randomize_brk(struct mm_struct *mm)
22105-{
22106- unsigned long range_end = mm->brk + 0x02000000;
22107- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
22108-}
22109+ if (!randomize_va_space)
22110+ return;
22111+
22112+ if (v8086_mode(regs))
22113+ return;
22114
22115+ rdtscl(time);
22116+
22117+ /* P4 seems to return a 0 LSB, ignore it */
22118+#ifdef CONFIG_MPENTIUM4
22119+ time &= 0x3EUL;
22120+ time <<= 2;
22121+#elif defined(CONFIG_X86_64)
22122+ time &= 0xFUL;
22123+ time <<= 4;
22124+#else
22125+ time &= 0x1FUL;
22126+ time <<= 3;
22127+#endif
22128+
22129+ thread->sp0 ^= time;
22130+ load_sp0(init_tss + smp_processor_id(), thread);
22131+
22132+#ifdef CONFIG_X86_64
22133+ this_cpu_write(kernel_stack, thread->sp0);
22134+#endif
22135+}
22136+#endif
22137diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
22138index 7305f7d..22f73d6 100644
22139--- a/arch/x86/kernel/process_32.c
22140+++ b/arch/x86/kernel/process_32.c
22141@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
22142 unsigned long thread_saved_pc(struct task_struct *tsk)
22143 {
22144 return ((unsigned long *)tsk->thread.sp)[3];
22145+//XXX return tsk->thread.eip;
22146 }
22147
22148 void __show_regs(struct pt_regs *regs, int all)
22149@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
22150 unsigned long sp;
22151 unsigned short ss, gs;
22152
22153- if (user_mode_vm(regs)) {
22154+ if (user_mode(regs)) {
22155 sp = regs->sp;
22156 ss = regs->ss & 0xffff;
22157- gs = get_user_gs(regs);
22158 } else {
22159 sp = kernel_stack_pointer(regs);
22160 savesegment(ss, ss);
22161- savesegment(gs, gs);
22162 }
22163+ gs = get_user_gs(regs);
22164
22165 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
22166 (u16)regs->cs, regs->ip, regs->flags,
22167- smp_processor_id());
22168+ raw_smp_processor_id());
22169 print_symbol("EIP is at %s\n", regs->ip);
22170
22171 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22172@@ -128,20 +128,21 @@ void release_thread(struct task_struct *dead_task)
22173 int copy_thread(unsigned long clone_flags, unsigned long sp,
22174 unsigned long arg, struct task_struct *p)
22175 {
22176- struct pt_regs *childregs = task_pt_regs(p);
22177+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22178 struct task_struct *tsk;
22179 int err;
22180
22181 p->thread.sp = (unsigned long) childregs;
22182 p->thread.sp0 = (unsigned long) (childregs+1);
22183+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22184
22185 if (unlikely(p->flags & PF_KTHREAD)) {
22186 /* kernel thread */
22187 memset(childregs, 0, sizeof(struct pt_regs));
22188 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22189- task_user_gs(p) = __KERNEL_STACK_CANARY;
22190- childregs->ds = __USER_DS;
22191- childregs->es = __USER_DS;
22192+ savesegment(gs, childregs->gs);
22193+ childregs->ds = __KERNEL_DS;
22194+ childregs->es = __KERNEL_DS;
22195 childregs->fs = __KERNEL_PERCPU;
22196 childregs->bx = sp; /* function */
22197 childregs->bp = arg;
22198@@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22199 struct thread_struct *prev = &prev_p->thread,
22200 *next = &next_p->thread;
22201 int cpu = smp_processor_id();
22202- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22203+ struct tss_struct *tss = init_tss + cpu;
22204 fpu_switch_t fpu;
22205
22206 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22207@@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22208 */
22209 lazy_save_gs(prev->gs);
22210
22211+#ifdef CONFIG_PAX_MEMORY_UDEREF
22212+ __set_fs(task_thread_info(next_p)->addr_limit);
22213+#endif
22214+
22215 /*
22216 * Load the per-thread Thread-Local Storage descriptor.
22217 */
22218@@ -302,6 +307,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22219 */
22220 arch_end_context_switch(next_p);
22221
22222+ this_cpu_write(current_task, next_p);
22223+ this_cpu_write(current_tinfo, &next_p->tinfo);
22224+
22225 /*
22226 * Restore %gs if needed (which is common)
22227 */
22228@@ -310,8 +318,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22229
22230 switch_fpu_finish(next_p, fpu);
22231
22232- this_cpu_write(current_task, next_p);
22233-
22234 return prev_p;
22235 }
22236
22237@@ -341,4 +347,3 @@ unsigned long get_wchan(struct task_struct *p)
22238 } while (count++ < 16);
22239 return 0;
22240 }
22241-
22242diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22243index 355ae06..4530766 100644
22244--- a/arch/x86/kernel/process_64.c
22245+++ b/arch/x86/kernel/process_64.c
22246@@ -151,10 +151,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22247 struct pt_regs *childregs;
22248 struct task_struct *me = current;
22249
22250- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22251+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22252 childregs = task_pt_regs(p);
22253 p->thread.sp = (unsigned long) childregs;
22254 p->thread.usersp = me->thread.usersp;
22255+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22256 set_tsk_thread_flag(p, TIF_FORK);
22257 p->fpu_counter = 0;
22258 p->thread.io_bitmap_ptr = NULL;
22259@@ -273,7 +274,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22260 struct thread_struct *prev = &prev_p->thread;
22261 struct thread_struct *next = &next_p->thread;
22262 int cpu = smp_processor_id();
22263- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22264+ struct tss_struct *tss = init_tss + cpu;
22265 unsigned fsindex, gsindex;
22266 fpu_switch_t fpu;
22267
22268@@ -355,10 +356,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22269 prev->usersp = this_cpu_read(old_rsp);
22270 this_cpu_write(old_rsp, next->usersp);
22271 this_cpu_write(current_task, next_p);
22272+ this_cpu_write(current_tinfo, &next_p->tinfo);
22273
22274- this_cpu_write(kernel_stack,
22275- (unsigned long)task_stack_page(next_p) +
22276- THREAD_SIZE - KERNEL_STACK_OFFSET);
22277+ this_cpu_write(kernel_stack, next->sp0);
22278
22279 /*
22280 * Now maybe reload the debug registers and handle I/O bitmaps
22281@@ -427,12 +427,11 @@ unsigned long get_wchan(struct task_struct *p)
22282 if (!p || p == current || p->state == TASK_RUNNING)
22283 return 0;
22284 stack = (unsigned long)task_stack_page(p);
22285- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22286+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22287 return 0;
22288 fp = *(u64 *)(p->thread.sp);
22289 do {
22290- if (fp < (unsigned long)stack ||
22291- fp >= (unsigned long)stack+THREAD_SIZE)
22292+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22293 return 0;
22294 ip = *(u64 *)(fp+8);
22295 if (!in_sched_functions(ip))
22296diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22297index 29a8120..a50b5ee 100644
22298--- a/arch/x86/kernel/ptrace.c
22299+++ b/arch/x86/kernel/ptrace.c
22300@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22301 {
22302 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22303 unsigned long sp = (unsigned long)&regs->sp;
22304- struct thread_info *tinfo;
22305
22306- if (context == (sp & ~(THREAD_SIZE - 1)))
22307+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22308 return sp;
22309
22310- tinfo = (struct thread_info *)context;
22311- if (tinfo->previous_esp)
22312- return tinfo->previous_esp;
22313+ sp = *(unsigned long *)context;
22314+ if (sp)
22315+ return sp;
22316
22317 return (unsigned long)regs;
22318 }
22319@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22320 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22321 {
22322 int i;
22323- int dr7 = 0;
22324+ unsigned long dr7 = 0;
22325 struct arch_hw_breakpoint *info;
22326
22327 for (i = 0; i < HBP_NUM; i++) {
22328@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22329 unsigned long addr, unsigned long data)
22330 {
22331 int ret;
22332- unsigned long __user *datap = (unsigned long __user *)data;
22333+ unsigned long __user *datap = (__force unsigned long __user *)data;
22334
22335 switch (request) {
22336 /* read the word at location addr in the USER area. */
22337@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22338 if ((int) addr < 0)
22339 return -EIO;
22340 ret = do_get_thread_area(child, addr,
22341- (struct user_desc __user *)data);
22342+ (__force struct user_desc __user *) data);
22343 break;
22344
22345 case PTRACE_SET_THREAD_AREA:
22346 if ((int) addr < 0)
22347 return -EIO;
22348 ret = do_set_thread_area(child, addr,
22349- (struct user_desc __user *)data, 0);
22350+ (__force struct user_desc __user *) data, 0);
22351 break;
22352 #endif
22353
22354@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22355
22356 #ifdef CONFIG_X86_64
22357
22358-static struct user_regset x86_64_regsets[] __read_mostly = {
22359+static user_regset_no_const x86_64_regsets[] __read_only = {
22360 [REGSET_GENERAL] = {
22361 .core_note_type = NT_PRSTATUS,
22362 .n = sizeof(struct user_regs_struct) / sizeof(long),
22363@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22364 #endif /* CONFIG_X86_64 */
22365
22366 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22367-static struct user_regset x86_32_regsets[] __read_mostly = {
22368+static user_regset_no_const x86_32_regsets[] __read_only = {
22369 [REGSET_GENERAL] = {
22370 .core_note_type = NT_PRSTATUS,
22371 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22372@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22373 */
22374 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22375
22376-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22377+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22378 {
22379 #ifdef CONFIG_X86_64
22380 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22381@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22382 memset(info, 0, sizeof(*info));
22383 info->si_signo = SIGTRAP;
22384 info->si_code = si_code;
22385- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22386+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22387 }
22388
22389 void user_single_step_siginfo(struct task_struct *tsk,
22390@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22391 # define IS_IA32 0
22392 #endif
22393
22394+#ifdef CONFIG_GRKERNSEC_SETXID
22395+extern void gr_delayed_cred_worker(void);
22396+#endif
22397+
22398 /*
22399 * We must return the syscall number to actually look up in the table.
22400 * This can be -1L to skip running any syscall at all.
22401@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22402
22403 user_exit();
22404
22405+#ifdef CONFIG_GRKERNSEC_SETXID
22406+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22407+ gr_delayed_cred_worker();
22408+#endif
22409+
22410 /*
22411 * If we stepped into a sysenter/syscall insn, it trapped in
22412 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22413@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22414 */
22415 user_exit();
22416
22417+#ifdef CONFIG_GRKERNSEC_SETXID
22418+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22419+ gr_delayed_cred_worker();
22420+#endif
22421+
22422 audit_syscall_exit(regs);
22423
22424 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22425diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22426index 2cb9470..ff1fd80 100644
22427--- a/arch/x86/kernel/pvclock.c
22428+++ b/arch/x86/kernel/pvclock.c
22429@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22430 return pv_tsc_khz;
22431 }
22432
22433-static atomic64_t last_value = ATOMIC64_INIT(0);
22434+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22435
22436 void pvclock_resume(void)
22437 {
22438- atomic64_set(&last_value, 0);
22439+ atomic64_set_unchecked(&last_value, 0);
22440 }
22441
22442 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22443@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22444 * updating at the same time, and one of them could be slightly behind,
22445 * making the assumption that last_value always go forward fail to hold.
22446 */
22447- last = atomic64_read(&last_value);
22448+ last = atomic64_read_unchecked(&last_value);
22449 do {
22450 if (ret < last)
22451 return last;
22452- last = atomic64_cmpxchg(&last_value, last, ret);
22453+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22454 } while (unlikely(last != ret));
22455
22456 return ret;
22457diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22458index 76fa1e9..abf09ea 100644
22459--- a/arch/x86/kernel/reboot.c
22460+++ b/arch/x86/kernel/reboot.c
22461@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22462 EXPORT_SYMBOL(pm_power_off);
22463
22464 static const struct desc_ptr no_idt = {};
22465-static int reboot_mode;
22466+static unsigned short reboot_mode;
22467 enum reboot_type reboot_type = BOOT_ACPI;
22468 int reboot_force;
22469
22470@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22471
22472 void __noreturn machine_real_restart(unsigned int type)
22473 {
22474+
22475+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22476+ struct desc_struct *gdt;
22477+#endif
22478+
22479 local_irq_disable();
22480
22481 /*
22482@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22483
22484 /* Jump to the identity-mapped low memory code */
22485 #ifdef CONFIG_X86_32
22486- asm volatile("jmpl *%0" : :
22487+
22488+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22489+ gdt = get_cpu_gdt_table(smp_processor_id());
22490+ pax_open_kernel();
22491+#ifdef CONFIG_PAX_MEMORY_UDEREF
22492+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22493+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22494+ loadsegment(ds, __KERNEL_DS);
22495+ loadsegment(es, __KERNEL_DS);
22496+ loadsegment(ss, __KERNEL_DS);
22497+#endif
22498+#ifdef CONFIG_PAX_KERNEXEC
22499+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22500+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22501+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22502+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22503+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22504+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22505+#endif
22506+ pax_close_kernel();
22507+#endif
22508+
22509+ asm volatile("ljmpl *%0" : :
22510 "rm" (real_mode_header->machine_real_restart_asm),
22511 "a" (type));
22512 #else
22513@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22514 * try to force a triple fault and then cycle between hitting the keyboard
22515 * controller and doing that
22516 */
22517-static void native_machine_emergency_restart(void)
22518+static void __noreturn native_machine_emergency_restart(void)
22519 {
22520 int i;
22521 int attempt = 0;
22522@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22523 #endif
22524 }
22525
22526-static void __machine_emergency_restart(int emergency)
22527+static void __noreturn __machine_emergency_restart(int emergency)
22528 {
22529 reboot_emergency = emergency;
22530 machine_ops.emergency_restart();
22531 }
22532
22533-static void native_machine_restart(char *__unused)
22534+static void __noreturn native_machine_restart(char *__unused)
22535 {
22536 pr_notice("machine restart\n");
22537
22538@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22539 __machine_emergency_restart(0);
22540 }
22541
22542-static void native_machine_halt(void)
22543+static void __noreturn native_machine_halt(void)
22544 {
22545 /* Stop other cpus and apics */
22546 machine_shutdown();
22547@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22548 stop_this_cpu(NULL);
22549 }
22550
22551-static void native_machine_power_off(void)
22552+static void __noreturn native_machine_power_off(void)
22553 {
22554 if (pm_power_off) {
22555 if (!reboot_force)
22556@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22557 }
22558 /* A fallback in case there is no PM info available */
22559 tboot_shutdown(TB_SHUTDOWN_HALT);
22560+ unreachable();
22561 }
22562
22563-struct machine_ops machine_ops = {
22564+struct machine_ops machine_ops __read_only = {
22565 .power_off = native_machine_power_off,
22566 .shutdown = native_machine_shutdown,
22567 .emergency_restart = native_machine_emergency_restart,
22568diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22569index f2bb9c9..bed145d7 100644
22570--- a/arch/x86/kernel/relocate_kernel_64.S
22571+++ b/arch/x86/kernel/relocate_kernel_64.S
22572@@ -11,6 +11,7 @@
22573 #include <asm/kexec.h>
22574 #include <asm/processor-flags.h>
22575 #include <asm/pgtable_types.h>
22576+#include <asm/alternative-asm.h>
22577
22578 /*
22579 * Must be relocatable PIC code callable as a C function
22580@@ -167,6 +168,7 @@ identity_mapped:
22581 xorq %r14, %r14
22582 xorq %r15, %r15
22583
22584+ pax_force_retaddr 0, 1
22585 ret
22586
22587 1:
22588diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22589index 56f7fcf..fa229f4 100644
22590--- a/arch/x86/kernel/setup.c
22591+++ b/arch/x86/kernel/setup.c
22592@@ -110,6 +110,7 @@
22593 #include <asm/mce.h>
22594 #include <asm/alternative.h>
22595 #include <asm/prom.h>
22596+#include <asm/boot.h>
22597
22598 /*
22599 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
22600@@ -444,7 +445,7 @@ static void __init parse_setup_data(void)
22601
22602 switch (data->type) {
22603 case SETUP_E820_EXT:
22604- parse_e820_ext(data);
22605+ parse_e820_ext((struct setup_data __force_kernel *)data);
22606 break;
22607 case SETUP_DTB:
22608 add_dtb(pa_data);
22609@@ -771,7 +772,7 @@ static void __init trim_bios_range(void)
22610 * area (640->1Mb) as ram even though it is not.
22611 * take them out.
22612 */
22613- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22614+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22615
22616 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22617 }
22618@@ -779,7 +780,7 @@ static void __init trim_bios_range(void)
22619 /* called before trim_bios_range() to spare extra sanitize */
22620 static void __init e820_add_kernel_range(void)
22621 {
22622- u64 start = __pa_symbol(_text);
22623+ u64 start = __pa_symbol(ktla_ktva(_text));
22624 u64 size = __pa_symbol(_end) - start;
22625
22626 /*
22627@@ -841,8 +842,12 @@ static void __init trim_low_memory_range(void)
22628
22629 void __init setup_arch(char **cmdline_p)
22630 {
22631+#ifdef CONFIG_X86_32
22632+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
22633+#else
22634 memblock_reserve(__pa_symbol(_text),
22635 (unsigned long)__bss_stop - (unsigned long)_text);
22636+#endif
22637
22638 early_reserve_initrd();
22639
22640@@ -934,14 +939,14 @@ void __init setup_arch(char **cmdline_p)
22641
22642 if (!boot_params.hdr.root_flags)
22643 root_mountflags &= ~MS_RDONLY;
22644- init_mm.start_code = (unsigned long) _text;
22645- init_mm.end_code = (unsigned long) _etext;
22646+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22647+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22648 init_mm.end_data = (unsigned long) _edata;
22649 init_mm.brk = _brk_end;
22650
22651- code_resource.start = __pa_symbol(_text);
22652- code_resource.end = __pa_symbol(_etext)-1;
22653- data_resource.start = __pa_symbol(_etext);
22654+ code_resource.start = __pa_symbol(ktla_ktva(_text));
22655+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
22656+ data_resource.start = __pa_symbol(_sdata);
22657 data_resource.end = __pa_symbol(_edata)-1;
22658 bss_resource.start = __pa_symbol(__bss_start);
22659 bss_resource.end = __pa_symbol(__bss_stop)-1;
22660diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22661index 5cdff03..80fa283 100644
22662--- a/arch/x86/kernel/setup_percpu.c
22663+++ b/arch/x86/kernel/setup_percpu.c
22664@@ -21,19 +21,17 @@
22665 #include <asm/cpu.h>
22666 #include <asm/stackprotector.h>
22667
22668-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22669+#ifdef CONFIG_SMP
22670+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22671 EXPORT_PER_CPU_SYMBOL(cpu_number);
22672+#endif
22673
22674-#ifdef CONFIG_X86_64
22675 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22676-#else
22677-#define BOOT_PERCPU_OFFSET 0
22678-#endif
22679
22680 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22681 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22682
22683-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22684+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22685 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22686 };
22687 EXPORT_SYMBOL(__per_cpu_offset);
22688@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22689 {
22690 #ifdef CONFIG_NEED_MULTIPLE_NODES
22691 pg_data_t *last = NULL;
22692- unsigned int cpu;
22693+ int cpu;
22694
22695 for_each_possible_cpu(cpu) {
22696 int node = early_cpu_to_node(cpu);
22697@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22698 {
22699 #ifdef CONFIG_X86_32
22700 struct desc_struct gdt;
22701+ unsigned long base = per_cpu_offset(cpu);
22702
22703- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22704- 0x2 | DESCTYPE_S, 0x8);
22705- gdt.s = 1;
22706+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22707+ 0x83 | DESCTYPE_S, 0xC);
22708 write_gdt_entry(get_cpu_gdt_table(cpu),
22709 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22710 #endif
22711@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22712 /* alrighty, percpu areas up and running */
22713 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22714 for_each_possible_cpu(cpu) {
22715+#ifdef CONFIG_CC_STACKPROTECTOR
22716+#ifdef CONFIG_X86_32
22717+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22718+#endif
22719+#endif
22720 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22721 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22722 per_cpu(cpu_number, cpu) = cpu;
22723@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22724 */
22725 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22726 #endif
22727+#ifdef CONFIG_CC_STACKPROTECTOR
22728+#ifdef CONFIG_X86_32
22729+ if (!cpu)
22730+ per_cpu(stack_canary.canary, cpu) = canary;
22731+#endif
22732+#endif
22733 /*
22734 * Up to this point, the boot CPU has been using .init.data
22735 * area. Reload any changed state for the boot CPU.
22736diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22737index 6956299..f20beae 100644
22738--- a/arch/x86/kernel/signal.c
22739+++ b/arch/x86/kernel/signal.c
22740@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22741 * Align the stack pointer according to the i386 ABI,
22742 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22743 */
22744- sp = ((sp + 4) & -16ul) - 4;
22745+ sp = ((sp - 12) & -16ul) - 4;
22746 #else /* !CONFIG_X86_32 */
22747 sp = round_down(sp, 16) - 8;
22748 #endif
22749@@ -304,9 +304,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22750 }
22751
22752 if (current->mm->context.vdso)
22753- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22754+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22755 else
22756- restorer = &frame->retcode;
22757+ restorer = (void __user *)&frame->retcode;
22758 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22759 restorer = ksig->ka.sa.sa_restorer;
22760
22761@@ -320,7 +320,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22762 * reasons and because gdb uses it as a signature to notice
22763 * signal handler stack frames.
22764 */
22765- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22766+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22767
22768 if (err)
22769 return -EFAULT;
22770@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22771 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22772
22773 /* Set up to return from userspace. */
22774- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22775+ if (current->mm->context.vdso)
22776+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22777+ else
22778+ restorer = (void __user *)&frame->retcode;
22779 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22780 restorer = ksig->ka.sa.sa_restorer;
22781 put_user_ex(restorer, &frame->pretcode);
22782@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22783 * reasons and because gdb uses it as a signature to notice
22784 * signal handler stack frames.
22785 */
22786- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22787+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22788 } put_user_catch(err);
22789
22790 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
22791@@ -615,7 +618,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22792 {
22793 int usig = signr_convert(ksig->sig);
22794 sigset_t *set = sigmask_to_save();
22795- compat_sigset_t *cset = (compat_sigset_t *) set;
22796+ sigset_t sigcopy;
22797+ compat_sigset_t *cset;
22798+
22799+ sigcopy = *set;
22800+
22801+ cset = (compat_sigset_t *) &sigcopy;
22802
22803 /* Set up the stack frame */
22804 if (is_ia32_frame()) {
22805@@ -626,7 +634,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22806 } else if (is_x32_frame()) {
22807 return x32_setup_rt_frame(ksig, cset, regs);
22808 } else {
22809- return __setup_rt_frame(ksig->sig, ksig, set, regs);
22810+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
22811 }
22812 }
22813
22814diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22815index 48d2b7d..90d328a 100644
22816--- a/arch/x86/kernel/smp.c
22817+++ b/arch/x86/kernel/smp.c
22818@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22819
22820 __setup("nonmi_ipi", nonmi_ipi_setup);
22821
22822-struct smp_ops smp_ops = {
22823+struct smp_ops smp_ops __read_only = {
22824 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22825 .smp_prepare_cpus = native_smp_prepare_cpus,
22826 .smp_cpus_done = native_smp_cpus_done,
22827diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22828index bfd348e..4816ad8 100644
22829--- a/arch/x86/kernel/smpboot.c
22830+++ b/arch/x86/kernel/smpboot.c
22831@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22832 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22833 (THREAD_SIZE + task_stack_page(idle))) - 1);
22834 per_cpu(current_task, cpu) = idle;
22835+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22836
22837 #ifdef CONFIG_X86_32
22838 /* Stack for startup_32 can be just as for start_secondary onwards */
22839@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22840 #else
22841 clear_tsk_thread_flag(idle, TIF_FORK);
22842 initial_gs = per_cpu_offset(cpu);
22843- per_cpu(kernel_stack, cpu) =
22844- (unsigned long)task_stack_page(idle) -
22845- KERNEL_STACK_OFFSET + THREAD_SIZE;
22846+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22847 #endif
22848+
22849+ pax_open_kernel();
22850 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22851+ pax_close_kernel();
22852+
22853 initial_code = (unsigned long)start_secondary;
22854 stack_start = idle->thread.sp;
22855
22856@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22857 /* the FPU context is blank, nobody can own it */
22858 __cpu_disable_lazy_restore(cpu);
22859
22860+#ifdef CONFIG_PAX_PER_CPU_PGD
22861+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22862+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22863+ KERNEL_PGD_PTRS);
22864+#endif
22865+
22866+ /* the FPU context is blank, nobody can own it */
22867+ __cpu_disable_lazy_restore(cpu);
22868+
22869 err = do_boot_cpu(apicid, cpu, tidle);
22870 if (err) {
22871 pr_debug("do_boot_cpu failed %d\n", err);
22872diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22873index 9b4d51d..5d28b58 100644
22874--- a/arch/x86/kernel/step.c
22875+++ b/arch/x86/kernel/step.c
22876@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22877 struct desc_struct *desc;
22878 unsigned long base;
22879
22880- seg &= ~7UL;
22881+ seg >>= 3;
22882
22883 mutex_lock(&child->mm->context.lock);
22884- if (unlikely((seg >> 3) >= child->mm->context.size))
22885+ if (unlikely(seg >= child->mm->context.size))
22886 addr = -1L; /* bogus selector, access would fault */
22887 else {
22888 desc = child->mm->context.ldt + seg;
22889@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22890 addr += base;
22891 }
22892 mutex_unlock(&child->mm->context.lock);
22893- }
22894+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22895+ addr = ktla_ktva(addr);
22896
22897 return addr;
22898 }
22899@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22900 unsigned char opcode[15];
22901 unsigned long addr = convert_ip_to_linear(child, regs);
22902
22903+ if (addr == -EINVAL)
22904+ return 0;
22905+
22906 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22907 for (i = 0; i < copied; i++) {
22908 switch (opcode[i]) {
22909diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22910new file mode 100644
22911index 0000000..5877189
22912--- /dev/null
22913+++ b/arch/x86/kernel/sys_i386_32.c
22914@@ -0,0 +1,189 @@
22915+/*
22916+ * This file contains various random system calls that
22917+ * have a non-standard calling sequence on the Linux/i386
22918+ * platform.
22919+ */
22920+
22921+#include <linux/errno.h>
22922+#include <linux/sched.h>
22923+#include <linux/mm.h>
22924+#include <linux/fs.h>
22925+#include <linux/smp.h>
22926+#include <linux/sem.h>
22927+#include <linux/msg.h>
22928+#include <linux/shm.h>
22929+#include <linux/stat.h>
22930+#include <linux/syscalls.h>
22931+#include <linux/mman.h>
22932+#include <linux/file.h>
22933+#include <linux/utsname.h>
22934+#include <linux/ipc.h>
22935+#include <linux/elf.h>
22936+
22937+#include <linux/uaccess.h>
22938+#include <linux/unistd.h>
22939+
22940+#include <asm/syscalls.h>
22941+
22942+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22943+{
22944+ unsigned long pax_task_size = TASK_SIZE;
22945+
22946+#ifdef CONFIG_PAX_SEGMEXEC
22947+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22948+ pax_task_size = SEGMEXEC_TASK_SIZE;
22949+#endif
22950+
22951+ if (flags & MAP_FIXED)
22952+ if (len > pax_task_size || addr > pax_task_size - len)
22953+ return -EINVAL;
22954+
22955+ return 0;
22956+}
22957+
22958+/*
22959+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
22960+ */
22961+static unsigned long get_align_mask(void)
22962+{
22963+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
22964+ return 0;
22965+
22966+ if (!(current->flags & PF_RANDOMIZE))
22967+ return 0;
22968+
22969+ return va_align.mask;
22970+}
22971+
22972+unsigned long
22973+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22974+ unsigned long len, unsigned long pgoff, unsigned long flags)
22975+{
22976+ struct mm_struct *mm = current->mm;
22977+ struct vm_area_struct *vma;
22978+ unsigned long pax_task_size = TASK_SIZE;
22979+ struct vm_unmapped_area_info info;
22980+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22981+
22982+#ifdef CONFIG_PAX_SEGMEXEC
22983+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22984+ pax_task_size = SEGMEXEC_TASK_SIZE;
22985+#endif
22986+
22987+ pax_task_size -= PAGE_SIZE;
22988+
22989+ if (len > pax_task_size)
22990+ return -ENOMEM;
22991+
22992+ if (flags & MAP_FIXED)
22993+ return addr;
22994+
22995+#ifdef CONFIG_PAX_RANDMMAP
22996+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22997+#endif
22998+
22999+ if (addr) {
23000+ addr = PAGE_ALIGN(addr);
23001+ if (pax_task_size - len >= addr) {
23002+ vma = find_vma(mm, addr);
23003+ if (check_heap_stack_gap(vma, addr, len, offset))
23004+ return addr;
23005+ }
23006+ }
23007+
23008+ info.flags = 0;
23009+ info.length = len;
23010+ info.align_mask = filp ? get_align_mask() : 0;
23011+ info.align_offset = pgoff << PAGE_SHIFT;
23012+ info.threadstack_offset = offset;
23013+
23014+#ifdef CONFIG_PAX_PAGEEXEC
23015+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
23016+ info.low_limit = 0x00110000UL;
23017+ info.high_limit = mm->start_code;
23018+
23019+#ifdef CONFIG_PAX_RANDMMAP
23020+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23021+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
23022+#endif
23023+
23024+ if (info.low_limit < info.high_limit) {
23025+ addr = vm_unmapped_area(&info);
23026+ if (!IS_ERR_VALUE(addr))
23027+ return addr;
23028+ }
23029+ } else
23030+#endif
23031+
23032+ info.low_limit = mm->mmap_base;
23033+ info.high_limit = pax_task_size;
23034+
23035+ return vm_unmapped_area(&info);
23036+}
23037+
23038+unsigned long
23039+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23040+ const unsigned long len, const unsigned long pgoff,
23041+ const unsigned long flags)
23042+{
23043+ struct vm_area_struct *vma;
23044+ struct mm_struct *mm = current->mm;
23045+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
23046+ struct vm_unmapped_area_info info;
23047+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23048+
23049+#ifdef CONFIG_PAX_SEGMEXEC
23050+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23051+ pax_task_size = SEGMEXEC_TASK_SIZE;
23052+#endif
23053+
23054+ pax_task_size -= PAGE_SIZE;
23055+
23056+ /* requested length too big for entire address space */
23057+ if (len > pax_task_size)
23058+ return -ENOMEM;
23059+
23060+ if (flags & MAP_FIXED)
23061+ return addr;
23062+
23063+#ifdef CONFIG_PAX_PAGEEXEC
23064+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
23065+ goto bottomup;
23066+#endif
23067+
23068+#ifdef CONFIG_PAX_RANDMMAP
23069+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23070+#endif
23071+
23072+ /* requesting a specific address */
23073+ if (addr) {
23074+ addr = PAGE_ALIGN(addr);
23075+ if (pax_task_size - len >= addr) {
23076+ vma = find_vma(mm, addr);
23077+ if (check_heap_stack_gap(vma, addr, len, offset))
23078+ return addr;
23079+ }
23080+ }
23081+
23082+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
23083+ info.length = len;
23084+ info.low_limit = PAGE_SIZE;
23085+ info.high_limit = mm->mmap_base;
23086+ info.align_mask = filp ? get_align_mask() : 0;
23087+ info.align_offset = pgoff << PAGE_SHIFT;
23088+ info.threadstack_offset = offset;
23089+
23090+ addr = vm_unmapped_area(&info);
23091+ if (!(addr & ~PAGE_MASK))
23092+ return addr;
23093+ VM_BUG_ON(addr != -ENOMEM);
23094+
23095+bottomup:
23096+ /*
23097+ * A failed mmap() very likely causes application failure,
23098+ * so fall back to the bottom-up function here. This scenario
23099+ * can happen with large stack limits and large mmap()
23100+ * allocations.
23101+ */
23102+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
23103+}
23104diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
23105index dbded5a..ace2781 100644
23106--- a/arch/x86/kernel/sys_x86_64.c
23107+++ b/arch/x86/kernel/sys_x86_64.c
23108@@ -81,8 +81,8 @@ out:
23109 return error;
23110 }
23111
23112-static void find_start_end(unsigned long flags, unsigned long *begin,
23113- unsigned long *end)
23114+static void find_start_end(struct mm_struct *mm, unsigned long flags,
23115+ unsigned long *begin, unsigned long *end)
23116 {
23117 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
23118 unsigned long new_begin;
23119@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
23120 *begin = new_begin;
23121 }
23122 } else {
23123- *begin = TASK_UNMAPPED_BASE;
23124+ *begin = mm->mmap_base;
23125 *end = TASK_SIZE;
23126 }
23127 }
23128@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23129 struct vm_area_struct *vma;
23130 struct vm_unmapped_area_info info;
23131 unsigned long begin, end;
23132+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23133
23134 if (flags & MAP_FIXED)
23135 return addr;
23136
23137- find_start_end(flags, &begin, &end);
23138+ find_start_end(mm, flags, &begin, &end);
23139
23140 if (len > end)
23141 return -ENOMEM;
23142
23143+#ifdef CONFIG_PAX_RANDMMAP
23144+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23145+#endif
23146+
23147 if (addr) {
23148 addr = PAGE_ALIGN(addr);
23149 vma = find_vma(mm, addr);
23150- if (end - len >= addr &&
23151- (!vma || addr + len <= vma->vm_start))
23152+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23153 return addr;
23154 }
23155
23156@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23157 info.high_limit = end;
23158 info.align_mask = filp ? get_align_mask() : 0;
23159 info.align_offset = pgoff << PAGE_SHIFT;
23160+ info.threadstack_offset = offset;
23161 return vm_unmapped_area(&info);
23162 }
23163
23164@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23165 struct mm_struct *mm = current->mm;
23166 unsigned long addr = addr0;
23167 struct vm_unmapped_area_info info;
23168+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23169
23170 /* requested length too big for entire address space */
23171 if (len > TASK_SIZE)
23172@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23173 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23174 goto bottomup;
23175
23176+#ifdef CONFIG_PAX_RANDMMAP
23177+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23178+#endif
23179+
23180 /* requesting a specific address */
23181 if (addr) {
23182 addr = PAGE_ALIGN(addr);
23183 vma = find_vma(mm, addr);
23184- if (TASK_SIZE - len >= addr &&
23185- (!vma || addr + len <= vma->vm_start))
23186+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23187 return addr;
23188 }
23189
23190@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23191 info.high_limit = mm->mmap_base;
23192 info.align_mask = filp ? get_align_mask() : 0;
23193 info.align_offset = pgoff << PAGE_SHIFT;
23194+ info.threadstack_offset = offset;
23195 addr = vm_unmapped_area(&info);
23196 if (!(addr & ~PAGE_MASK))
23197 return addr;
23198diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23199index f84fe00..f41d9f1 100644
23200--- a/arch/x86/kernel/tboot.c
23201+++ b/arch/x86/kernel/tboot.c
23202@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23203
23204 void tboot_shutdown(u32 shutdown_type)
23205 {
23206- void (*shutdown)(void);
23207+ void (* __noreturn shutdown)(void);
23208
23209 if (!tboot_enabled())
23210 return;
23211@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23212
23213 switch_to_tboot_pt();
23214
23215- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23216+ shutdown = (void *)tboot->shutdown_entry;
23217 shutdown();
23218
23219 /* should not reach here */
23220@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23221 return 0;
23222 }
23223
23224-static atomic_t ap_wfs_count;
23225+static atomic_unchecked_t ap_wfs_count;
23226
23227 static int tboot_wait_for_aps(int num_aps)
23228 {
23229@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23230 {
23231 switch (action) {
23232 case CPU_DYING:
23233- atomic_inc(&ap_wfs_count);
23234+ atomic_inc_unchecked(&ap_wfs_count);
23235 if (num_online_cpus() == 1)
23236- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23237+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23238 return NOTIFY_BAD;
23239 break;
23240 }
23241 return NOTIFY_OK;
23242 }
23243
23244-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23245+static struct notifier_block tboot_cpu_notifier =
23246 {
23247 .notifier_call = tboot_cpu_callback,
23248 };
23249@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23250
23251 tboot_create_trampoline();
23252
23253- atomic_set(&ap_wfs_count, 0);
23254+ atomic_set_unchecked(&ap_wfs_count, 0);
23255 register_hotcpu_notifier(&tboot_cpu_notifier);
23256
23257 acpi_os_set_prepare_sleep(&tboot_sleep);
23258diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23259index 24d3c91..d06b473 100644
23260--- a/arch/x86/kernel/time.c
23261+++ b/arch/x86/kernel/time.c
23262@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23263 {
23264 unsigned long pc = instruction_pointer(regs);
23265
23266- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23267+ if (!user_mode(regs) && in_lock_functions(pc)) {
23268 #ifdef CONFIG_FRAME_POINTER
23269- return *(unsigned long *)(regs->bp + sizeof(long));
23270+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23271 #else
23272 unsigned long *sp =
23273 (unsigned long *)kernel_stack_pointer(regs);
23274@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23275 * or above a saved flags. Eflags has bits 22-31 zero,
23276 * kernel addresses don't.
23277 */
23278+
23279+#ifdef CONFIG_PAX_KERNEXEC
23280+ return ktla_ktva(sp[0]);
23281+#else
23282 if (sp[0] >> 22)
23283 return sp[0];
23284 if (sp[1] >> 22)
23285 return sp[1];
23286 #endif
23287+
23288+#endif
23289 }
23290 return pc;
23291 }
23292diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23293index f7fec09..9991981 100644
23294--- a/arch/x86/kernel/tls.c
23295+++ b/arch/x86/kernel/tls.c
23296@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23297 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23298 return -EINVAL;
23299
23300+#ifdef CONFIG_PAX_SEGMEXEC
23301+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23302+ return -EINVAL;
23303+#endif
23304+
23305 set_tls_desc(p, idx, &info, 1);
23306
23307 return 0;
23308@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23309
23310 if (kbuf)
23311 info = kbuf;
23312- else if (__copy_from_user(infobuf, ubuf, count))
23313+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23314 return -EFAULT;
23315 else
23316 info = infobuf;
23317diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23318index 772e2a8..bad5bf6 100644
23319--- a/arch/x86/kernel/traps.c
23320+++ b/arch/x86/kernel/traps.c
23321@@ -68,12 +68,6 @@
23322 #include <asm/setup.h>
23323
23324 asmlinkage int system_call(void);
23325-
23326-/*
23327- * The IDT has to be page-aligned to simplify the Pentium
23328- * F0 0F bug workaround.
23329- */
23330-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23331 #endif
23332
23333 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23334@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23335 }
23336
23337 static int __kprobes
23338-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23339+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23340 struct pt_regs *regs, long error_code)
23341 {
23342 #ifdef CONFIG_X86_32
23343- if (regs->flags & X86_VM_MASK) {
23344+ if (v8086_mode(regs)) {
23345 /*
23346 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23347 * On nmi (interrupt 2), do_trap should not be called.
23348@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23349 return -1;
23350 }
23351 #endif
23352- if (!user_mode(regs)) {
23353+ if (!user_mode_novm(regs)) {
23354 if (!fixup_exception(regs)) {
23355 tsk->thread.error_code = error_code;
23356 tsk->thread.trap_nr = trapnr;
23357+
23358+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23359+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23360+ str = "PAX: suspicious stack segment fault";
23361+#endif
23362+
23363 die(str, regs, error_code);
23364 }
23365+
23366+#ifdef CONFIG_PAX_REFCOUNT
23367+ if (trapnr == 4)
23368+ pax_report_refcount_overflow(regs);
23369+#endif
23370+
23371 return 0;
23372 }
23373
23374@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23375 }
23376
23377 static void __kprobes
23378-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23379+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23380 long error_code, siginfo_t *info)
23381 {
23382 struct task_struct *tsk = current;
23383@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23384 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23385 printk_ratelimit()) {
23386 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23387- tsk->comm, tsk->pid, str,
23388+ tsk->comm, task_pid_nr(tsk), str,
23389 regs->ip, regs->sp, error_code);
23390 print_vma_addr(" in ", regs->ip);
23391 pr_cont("\n");
23392@@ -273,7 +279,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23393 conditional_sti(regs);
23394
23395 #ifdef CONFIG_X86_32
23396- if (regs->flags & X86_VM_MASK) {
23397+ if (v8086_mode(regs)) {
23398 local_irq_enable();
23399 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23400 goto exit;
23401@@ -281,18 +287,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23402 #endif
23403
23404 tsk = current;
23405- if (!user_mode(regs)) {
23406+ if (!user_mode_novm(regs)) {
23407 if (fixup_exception(regs))
23408 goto exit;
23409
23410 tsk->thread.error_code = error_code;
23411 tsk->thread.trap_nr = X86_TRAP_GP;
23412 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23413- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23414+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23415+
23416+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23417+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23418+ die("PAX: suspicious general protection fault", regs, error_code);
23419+ else
23420+#endif
23421+
23422 die("general protection fault", regs, error_code);
23423+ }
23424 goto exit;
23425 }
23426
23427+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23428+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23429+ struct mm_struct *mm = tsk->mm;
23430+ unsigned long limit;
23431+
23432+ down_write(&mm->mmap_sem);
23433+ limit = mm->context.user_cs_limit;
23434+ if (limit < TASK_SIZE) {
23435+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23436+ up_write(&mm->mmap_sem);
23437+ return;
23438+ }
23439+ up_write(&mm->mmap_sem);
23440+ }
23441+#endif
23442+
23443 tsk->thread.error_code = error_code;
23444 tsk->thread.trap_nr = X86_TRAP_GP;
23445
23446@@ -450,7 +480,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23447 /* It's safe to allow irq's after DR6 has been saved */
23448 preempt_conditional_sti(regs);
23449
23450- if (regs->flags & X86_VM_MASK) {
23451+ if (v8086_mode(regs)) {
23452 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23453 X86_TRAP_DB);
23454 preempt_conditional_cli(regs);
23455@@ -465,7 +495,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23456 * We already checked v86 mode above, so we can check for kernel mode
23457 * by just checking the CPL of CS.
23458 */
23459- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23460+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23461 tsk->thread.debugreg6 &= ~DR_STEP;
23462 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23463 regs->flags &= ~X86_EFLAGS_TF;
23464@@ -497,7 +527,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23465 return;
23466 conditional_sti(regs);
23467
23468- if (!user_mode_vm(regs))
23469+ if (!user_mode(regs))
23470 {
23471 if (!fixup_exception(regs)) {
23472 task->thread.error_code = error_code;
23473diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23474index 2ed8459..7cf329f 100644
23475--- a/arch/x86/kernel/uprobes.c
23476+++ b/arch/x86/kernel/uprobes.c
23477@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23478 int ret = NOTIFY_DONE;
23479
23480 /* We are only interested in userspace traps */
23481- if (regs && !user_mode_vm(regs))
23482+ if (regs && !user_mode(regs))
23483 return NOTIFY_DONE;
23484
23485 switch (val) {
23486@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
23487
23488 if (ncopied != rasize) {
23489 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
23490- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
23491+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
23492
23493 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
23494 }
23495diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23496index b9242ba..50c5edd 100644
23497--- a/arch/x86/kernel/verify_cpu.S
23498+++ b/arch/x86/kernel/verify_cpu.S
23499@@ -20,6 +20,7 @@
23500 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23501 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23502 * arch/x86/kernel/head_32.S: processor startup
23503+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23504 *
23505 * verify_cpu, returns the status of longmode and SSE in register %eax.
23506 * 0: Success 1: Failure
23507diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23508index e8edcf5..27f9344 100644
23509--- a/arch/x86/kernel/vm86_32.c
23510+++ b/arch/x86/kernel/vm86_32.c
23511@@ -44,6 +44,7 @@
23512 #include <linux/ptrace.h>
23513 #include <linux/audit.h>
23514 #include <linux/stddef.h>
23515+#include <linux/grsecurity.h>
23516
23517 #include <asm/uaccess.h>
23518 #include <asm/io.h>
23519@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23520 do_exit(SIGSEGV);
23521 }
23522
23523- tss = &per_cpu(init_tss, get_cpu());
23524+ tss = init_tss + get_cpu();
23525 current->thread.sp0 = current->thread.saved_sp0;
23526 current->thread.sysenter_cs = __KERNEL_CS;
23527 load_sp0(tss, &current->thread);
23528@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
23529
23530 if (tsk->thread.saved_sp0)
23531 return -EPERM;
23532+
23533+#ifdef CONFIG_GRKERNSEC_VM86
23534+ if (!capable(CAP_SYS_RAWIO)) {
23535+ gr_handle_vm86();
23536+ return -EPERM;
23537+ }
23538+#endif
23539+
23540 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
23541 offsetof(struct kernel_vm86_struct, vm86plus) -
23542 sizeof(info.regs));
23543@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
23544 int tmp;
23545 struct vm86plus_struct __user *v86;
23546
23547+#ifdef CONFIG_GRKERNSEC_VM86
23548+ if (!capable(CAP_SYS_RAWIO)) {
23549+ gr_handle_vm86();
23550+ return -EPERM;
23551+ }
23552+#endif
23553+
23554 tsk = current;
23555 switch (cmd) {
23556 case VM86_REQUEST_IRQ:
23557@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23558 tsk->thread.saved_fs = info->regs32->fs;
23559 tsk->thread.saved_gs = get_user_gs(info->regs32);
23560
23561- tss = &per_cpu(init_tss, get_cpu());
23562+ tss = init_tss + get_cpu();
23563 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23564 if (cpu_has_sep)
23565 tsk->thread.sysenter_cs = 0;
23566@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23567 goto cannot_handle;
23568 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23569 goto cannot_handle;
23570- intr_ptr = (unsigned long __user *) (i << 2);
23571+ intr_ptr = (__force unsigned long __user *) (i << 2);
23572 if (get_user(segoffs, intr_ptr))
23573 goto cannot_handle;
23574 if ((segoffs >> 16) == BIOSSEG)
23575diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23576index 10c4f30..57377c2 100644
23577--- a/arch/x86/kernel/vmlinux.lds.S
23578+++ b/arch/x86/kernel/vmlinux.lds.S
23579@@ -26,6 +26,13 @@
23580 #include <asm/page_types.h>
23581 #include <asm/cache.h>
23582 #include <asm/boot.h>
23583+#include <asm/segment.h>
23584+
23585+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23586+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23587+#else
23588+#define __KERNEL_TEXT_OFFSET 0
23589+#endif
23590
23591 #undef i386 /* in case the preprocessor is a 32bit one */
23592
23593@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23594
23595 PHDRS {
23596 text PT_LOAD FLAGS(5); /* R_E */
23597+#ifdef CONFIG_X86_32
23598+ module PT_LOAD FLAGS(5); /* R_E */
23599+#endif
23600+#ifdef CONFIG_XEN
23601+ rodata PT_LOAD FLAGS(5); /* R_E */
23602+#else
23603+ rodata PT_LOAD FLAGS(4); /* R__ */
23604+#endif
23605 data PT_LOAD FLAGS(6); /* RW_ */
23606-#ifdef CONFIG_X86_64
23607+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23608 #ifdef CONFIG_SMP
23609 percpu PT_LOAD FLAGS(6); /* RW_ */
23610 #endif
23611+ text.init PT_LOAD FLAGS(5); /* R_E */
23612+ text.exit PT_LOAD FLAGS(5); /* R_E */
23613 init PT_LOAD FLAGS(7); /* RWE */
23614-#endif
23615 note PT_NOTE FLAGS(0); /* ___ */
23616 }
23617
23618 SECTIONS
23619 {
23620 #ifdef CONFIG_X86_32
23621- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23622- phys_startup_32 = startup_32 - LOAD_OFFSET;
23623+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23624 #else
23625- . = __START_KERNEL;
23626- phys_startup_64 = startup_64 - LOAD_OFFSET;
23627+ . = __START_KERNEL;
23628 #endif
23629
23630 /* Text and read-only data */
23631- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23632- _text = .;
23633+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23634 /* bootstrapping code */
23635+#ifdef CONFIG_X86_32
23636+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23637+#else
23638+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23639+#endif
23640+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23641+ _text = .;
23642 HEAD_TEXT
23643 . = ALIGN(8);
23644 _stext = .;
23645@@ -104,13 +124,48 @@ SECTIONS
23646 IRQENTRY_TEXT
23647 *(.fixup)
23648 *(.gnu.warning)
23649- /* End of text section */
23650- _etext = .;
23651 } :text = 0x9090
23652
23653- NOTES :text :note
23654+ . += __KERNEL_TEXT_OFFSET;
23655
23656- EXCEPTION_TABLE(16) :text = 0x9090
23657+#ifdef CONFIG_X86_32
23658+ . = ALIGN(PAGE_SIZE);
23659+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23660+
23661+#ifdef CONFIG_PAX_KERNEXEC
23662+ MODULES_EXEC_VADDR = .;
23663+ BYTE(0)
23664+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23665+ . = ALIGN(HPAGE_SIZE) - 1;
23666+ MODULES_EXEC_END = .;
23667+#endif
23668+
23669+ } :module
23670+#endif
23671+
23672+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23673+ /* End of text section */
23674+ BYTE(0)
23675+ _etext = . - __KERNEL_TEXT_OFFSET;
23676+ }
23677+
23678+#ifdef CONFIG_X86_32
23679+ . = ALIGN(PAGE_SIZE);
23680+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23681+ *(.idt)
23682+ . = ALIGN(PAGE_SIZE);
23683+ *(.empty_zero_page)
23684+ *(.initial_pg_fixmap)
23685+ *(.initial_pg_pmd)
23686+ *(.initial_page_table)
23687+ *(.swapper_pg_dir)
23688+ } :rodata
23689+#endif
23690+
23691+ . = ALIGN(PAGE_SIZE);
23692+ NOTES :rodata :note
23693+
23694+ EXCEPTION_TABLE(16) :rodata
23695
23696 #if defined(CONFIG_DEBUG_RODATA)
23697 /* .text should occupy whole number of pages */
23698@@ -122,16 +177,20 @@ SECTIONS
23699
23700 /* Data */
23701 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23702+
23703+#ifdef CONFIG_PAX_KERNEXEC
23704+ . = ALIGN(HPAGE_SIZE);
23705+#else
23706+ . = ALIGN(PAGE_SIZE);
23707+#endif
23708+
23709 /* Start of data section */
23710 _sdata = .;
23711
23712 /* init_task */
23713 INIT_TASK_DATA(THREAD_SIZE)
23714
23715-#ifdef CONFIG_X86_32
23716- /* 32 bit has nosave before _edata */
23717 NOSAVE_DATA
23718-#endif
23719
23720 PAGE_ALIGNED_DATA(PAGE_SIZE)
23721
23722@@ -172,12 +231,19 @@ SECTIONS
23723 #endif /* CONFIG_X86_64 */
23724
23725 /* Init code and data - will be freed after init */
23726- . = ALIGN(PAGE_SIZE);
23727 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23728+ BYTE(0)
23729+
23730+#ifdef CONFIG_PAX_KERNEXEC
23731+ . = ALIGN(HPAGE_SIZE);
23732+#else
23733+ . = ALIGN(PAGE_SIZE);
23734+#endif
23735+
23736 __init_begin = .; /* paired with __init_end */
23737- }
23738+ } :init.begin
23739
23740-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23741+#ifdef CONFIG_SMP
23742 /*
23743 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23744 * output PHDR, so the next output section - .init.text - should
23745@@ -186,12 +252,27 @@ SECTIONS
23746 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23747 #endif
23748
23749- INIT_TEXT_SECTION(PAGE_SIZE)
23750-#ifdef CONFIG_X86_64
23751- :init
23752-#endif
23753+ . = ALIGN(PAGE_SIZE);
23754+ init_begin = .;
23755+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23756+ VMLINUX_SYMBOL(_sinittext) = .;
23757+ INIT_TEXT
23758+ VMLINUX_SYMBOL(_einittext) = .;
23759+ . = ALIGN(PAGE_SIZE);
23760+ } :text.init
23761
23762- INIT_DATA_SECTION(16)
23763+ /*
23764+ * .exit.text is discard at runtime, not link time, to deal with
23765+ * references from .altinstructions and .eh_frame
23766+ */
23767+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23768+ EXIT_TEXT
23769+ . = ALIGN(16);
23770+ } :text.exit
23771+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23772+
23773+ . = ALIGN(PAGE_SIZE);
23774+ INIT_DATA_SECTION(16) :init
23775
23776 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23777 __x86_cpu_dev_start = .;
23778@@ -253,19 +334,12 @@ SECTIONS
23779 }
23780
23781 . = ALIGN(8);
23782- /*
23783- * .exit.text is discard at runtime, not link time, to deal with
23784- * references from .altinstructions and .eh_frame
23785- */
23786- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23787- EXIT_TEXT
23788- }
23789
23790 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23791 EXIT_DATA
23792 }
23793
23794-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23795+#ifndef CONFIG_SMP
23796 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23797 #endif
23798
23799@@ -284,16 +358,10 @@ SECTIONS
23800 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23801 __smp_locks = .;
23802 *(.smp_locks)
23803- . = ALIGN(PAGE_SIZE);
23804 __smp_locks_end = .;
23805+ . = ALIGN(PAGE_SIZE);
23806 }
23807
23808-#ifdef CONFIG_X86_64
23809- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23810- NOSAVE_DATA
23811- }
23812-#endif
23813-
23814 /* BSS */
23815 . = ALIGN(PAGE_SIZE);
23816 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23817@@ -309,6 +377,7 @@ SECTIONS
23818 __brk_base = .;
23819 . += 64 * 1024; /* 64k alignment slop space */
23820 *(.brk_reservation) /* areas brk users have reserved */
23821+ . = ALIGN(HPAGE_SIZE);
23822 __brk_limit = .;
23823 }
23824
23825@@ -335,13 +404,12 @@ SECTIONS
23826 * for the boot processor.
23827 */
23828 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23829-INIT_PER_CPU(gdt_page);
23830 INIT_PER_CPU(irq_stack_union);
23831
23832 /*
23833 * Build-time check on the image size:
23834 */
23835-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23836+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23837 "kernel image bigger than KERNEL_IMAGE_SIZE");
23838
23839 #ifdef CONFIG_SMP
23840diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23841index 9a907a6..f83f921 100644
23842--- a/arch/x86/kernel/vsyscall_64.c
23843+++ b/arch/x86/kernel/vsyscall_64.c
23844@@ -56,15 +56,13 @@
23845 DEFINE_VVAR(int, vgetcpu_mode);
23846 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23847
23848-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23849+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23850
23851 static int __init vsyscall_setup(char *str)
23852 {
23853 if (str) {
23854 if (!strcmp("emulate", str))
23855 vsyscall_mode = EMULATE;
23856- else if (!strcmp("native", str))
23857- vsyscall_mode = NATIVE;
23858 else if (!strcmp("none", str))
23859 vsyscall_mode = NONE;
23860 else
23861@@ -323,8 +321,7 @@ do_ret:
23862 return true;
23863
23864 sigsegv:
23865- force_sig(SIGSEGV, current);
23866- return true;
23867+ do_group_exit(SIGKILL);
23868 }
23869
23870 /*
23871@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23872 extern char __vvar_page;
23873 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23874
23875- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23876- vsyscall_mode == NATIVE
23877- ? PAGE_KERNEL_VSYSCALL
23878- : PAGE_KERNEL_VVAR);
23879+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23880 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23881 (unsigned long)VSYSCALL_START);
23882
23883diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23884index b014d94..6d6ca7b 100644
23885--- a/arch/x86/kernel/x8664_ksyms_64.c
23886+++ b/arch/x86/kernel/x8664_ksyms_64.c
23887@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23888 EXPORT_SYMBOL(copy_user_generic_unrolled);
23889 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23890 EXPORT_SYMBOL(__copy_user_nocache);
23891-EXPORT_SYMBOL(_copy_from_user);
23892-EXPORT_SYMBOL(_copy_to_user);
23893
23894 EXPORT_SYMBOL(copy_page);
23895 EXPORT_SYMBOL(clear_page);
23896diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23897index 45a14db..075bb9b 100644
23898--- a/arch/x86/kernel/x86_init.c
23899+++ b/arch/x86/kernel/x86_init.c
23900@@ -85,7 +85,7 @@ struct x86_init_ops x86_init __initdata = {
23901 },
23902 };
23903
23904-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23905+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23906 .early_percpu_clock_init = x86_init_noop,
23907 .setup_percpu_clockev = setup_secondary_APIC_clock,
23908 };
23909@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23910 static void default_nmi_init(void) { };
23911 static int default_i8042_detect(void) { return 1; };
23912
23913-struct x86_platform_ops x86_platform = {
23914+struct x86_platform_ops x86_platform __read_only = {
23915 .calibrate_tsc = native_calibrate_tsc,
23916 .get_wallclock = mach_get_cmos_time,
23917 .set_wallclock = mach_set_rtc_mmss,
23918@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
23919 };
23920
23921 EXPORT_SYMBOL_GPL(x86_platform);
23922-struct x86_msi_ops x86_msi = {
23923+struct x86_msi_ops x86_msi __read_only = {
23924 .setup_msi_irqs = native_setup_msi_irqs,
23925 .compose_msi_msg = native_compose_msi_msg,
23926 .teardown_msi_irq = native_teardown_msi_irq,
23927@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
23928 .setup_hpet_msi = default_setup_hpet_msi,
23929 };
23930
23931-struct x86_io_apic_ops x86_io_apic_ops = {
23932+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23933 .init = native_io_apic_init_mappings,
23934 .read = native_io_apic_read,
23935 .write = native_io_apic_write,
23936diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23937index ada87a3..afea76d 100644
23938--- a/arch/x86/kernel/xsave.c
23939+++ b/arch/x86/kernel/xsave.c
23940@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23941 {
23942 int err;
23943
23944+ buf = (struct xsave_struct __user *)____m(buf);
23945 if (use_xsave())
23946 err = xsave_user(buf);
23947 else if (use_fxsr())
23948@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23949 */
23950 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23951 {
23952+ buf = (void __user *)____m(buf);
23953 if (use_xsave()) {
23954 if ((unsigned long)buf % 64 || fx_only) {
23955 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23956diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23957index a20ecb5..d0e2194 100644
23958--- a/arch/x86/kvm/cpuid.c
23959+++ b/arch/x86/kvm/cpuid.c
23960@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23961 struct kvm_cpuid2 *cpuid,
23962 struct kvm_cpuid_entry2 __user *entries)
23963 {
23964- int r;
23965+ int r, i;
23966
23967 r = -E2BIG;
23968 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23969 goto out;
23970 r = -EFAULT;
23971- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23972- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23973+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23974 goto out;
23975+ for (i = 0; i < cpuid->nent; ++i) {
23976+ struct kvm_cpuid_entry2 cpuid_entry;
23977+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23978+ goto out;
23979+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23980+ }
23981 vcpu->arch.cpuid_nent = cpuid->nent;
23982 kvm_apic_set_version(vcpu);
23983 kvm_x86_ops->cpuid_update(vcpu);
23984@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23985 struct kvm_cpuid2 *cpuid,
23986 struct kvm_cpuid_entry2 __user *entries)
23987 {
23988- int r;
23989+ int r, i;
23990
23991 r = -E2BIG;
23992 if (cpuid->nent < vcpu->arch.cpuid_nent)
23993 goto out;
23994 r = -EFAULT;
23995- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23996- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23997+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23998 goto out;
23999+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
24000+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
24001+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
24002+ goto out;
24003+ }
24004 return 0;
24005
24006 out:
24007diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
24008index 5953dce..f11a7d2 100644
24009--- a/arch/x86/kvm/emulate.c
24010+++ b/arch/x86/kvm/emulate.c
24011@@ -329,6 +329,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24012
24013 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
24014 do { \
24015+ unsigned long _tmp; \
24016 __asm__ __volatile__ ( \
24017 _PRE_EFLAGS("0", "4", "2") \
24018 _op _suffix " %"_x"3,%1; " \
24019@@ -343,8 +344,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24020 /* Raw emulation: instruction has two explicit operands. */
24021 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
24022 do { \
24023- unsigned long _tmp; \
24024- \
24025 switch ((ctxt)->dst.bytes) { \
24026 case 2: \
24027 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
24028@@ -360,7 +359,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24029
24030 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
24031 do { \
24032- unsigned long _tmp; \
24033 switch ((ctxt)->dst.bytes) { \
24034 case 1: \
24035 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
24036diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
24037index 0eee2c8..94a32c3 100644
24038--- a/arch/x86/kvm/lapic.c
24039+++ b/arch/x86/kvm/lapic.c
24040@@ -55,7 +55,7 @@
24041 #define APIC_BUS_CYCLE_NS 1
24042
24043 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
24044-#define apic_debug(fmt, arg...)
24045+#define apic_debug(fmt, arg...) do {} while (0)
24046
24047 #define APIC_LVT_NUM 6
24048 /* 14 is the version for Xeon and Pentium 8.4.8*/
24049diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
24050index da20860..d19fdf5 100644
24051--- a/arch/x86/kvm/paging_tmpl.h
24052+++ b/arch/x86/kvm/paging_tmpl.h
24053@@ -208,7 +208,7 @@ retry_walk:
24054 if (unlikely(kvm_is_error_hva(host_addr)))
24055 goto error;
24056
24057- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
24058+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
24059 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
24060 goto error;
24061 walker->ptep_user[walker->level - 1] = ptep_user;
24062diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
24063index a14a6ea..dc86cf0 100644
24064--- a/arch/x86/kvm/svm.c
24065+++ b/arch/x86/kvm/svm.c
24066@@ -3493,7 +3493,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
24067 int cpu = raw_smp_processor_id();
24068
24069 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
24070+
24071+ pax_open_kernel();
24072 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
24073+ pax_close_kernel();
24074+
24075 load_TR_desc();
24076 }
24077
24078@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
24079 #endif
24080 #endif
24081
24082+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24083+ __set_fs(current_thread_info()->addr_limit);
24084+#endif
24085+
24086 reload_tss(vcpu);
24087
24088 local_irq_disable();
24089diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
24090index 5402c94..c3bdeee 100644
24091--- a/arch/x86/kvm/vmx.c
24092+++ b/arch/x86/kvm/vmx.c
24093@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
24094 #endif
24095 }
24096
24097-static void vmcs_clear_bits(unsigned long field, u32 mask)
24098+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
24099 {
24100 vmcs_writel(field, vmcs_readl(field) & ~mask);
24101 }
24102
24103-static void vmcs_set_bits(unsigned long field, u32 mask)
24104+static void vmcs_set_bits(unsigned long field, unsigned long mask)
24105 {
24106 vmcs_writel(field, vmcs_readl(field) | mask);
24107 }
24108@@ -1517,7 +1517,11 @@ static void reload_tss(void)
24109 struct desc_struct *descs;
24110
24111 descs = (void *)gdt->address;
24112+
24113+ pax_open_kernel();
24114 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
24115+ pax_close_kernel();
24116+
24117 load_TR_desc();
24118 }
24119
24120@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
24121 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
24122 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
24123
24124+#ifdef CONFIG_PAX_PER_CPU_PGD
24125+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24126+#endif
24127+
24128 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
24129 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
24130 vmx->loaded_vmcs->cpu = cpu;
24131@@ -2935,8 +2943,11 @@ static __init int hardware_setup(void)
24132 if (!cpu_has_vmx_flexpriority())
24133 flexpriority_enabled = 0;
24134
24135- if (!cpu_has_vmx_tpr_shadow())
24136- kvm_x86_ops->update_cr8_intercept = NULL;
24137+ if (!cpu_has_vmx_tpr_shadow()) {
24138+ pax_open_kernel();
24139+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24140+ pax_close_kernel();
24141+ }
24142
24143 if (enable_ept && !cpu_has_vmx_ept_2m_page())
24144 kvm_disable_largepages();
24145@@ -2947,13 +2958,15 @@ static __init int hardware_setup(void)
24146 if (!cpu_has_vmx_apicv())
24147 enable_apicv = 0;
24148
24149+ pax_open_kernel();
24150 if (enable_apicv)
24151- kvm_x86_ops->update_cr8_intercept = NULL;
24152+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24153 else {
24154- kvm_x86_ops->hwapic_irr_update = NULL;
24155- kvm_x86_ops->deliver_posted_interrupt = NULL;
24156- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
24157+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
24158+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
24159+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
24160 }
24161+ pax_close_kernel();
24162
24163 if (nested)
24164 nested_vmx_setup_ctls_msrs();
24165@@ -4076,7 +4089,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
24166
24167 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
24168 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
24169+
24170+#ifndef CONFIG_PAX_PER_CPU_PGD
24171 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24172+#endif
24173
24174 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
24175 #ifdef CONFIG_X86_64
24176@@ -4098,7 +4114,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
24177 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
24178 vmx->host_idt_base = dt.address;
24179
24180- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
24181+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
24182
24183 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
24184 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
24185@@ -7030,6 +7046,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24186 "jmp 2f \n\t"
24187 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
24188 "2: "
24189+
24190+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24191+ "ljmp %[cs],$3f\n\t"
24192+ "3: "
24193+#endif
24194+
24195 /* Save guest registers, load host registers, keep flags */
24196 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
24197 "pop %0 \n\t"
24198@@ -7082,6 +7104,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24199 #endif
24200 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
24201 [wordsize]"i"(sizeof(ulong))
24202+
24203+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24204+ ,[cs]"i"(__KERNEL_CS)
24205+#endif
24206+
24207 : "cc", "memory"
24208 #ifdef CONFIG_X86_64
24209 , "rax", "rbx", "rdi", "rsi"
24210@@ -7095,7 +7122,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24211 if (debugctlmsr)
24212 update_debugctlmsr(debugctlmsr);
24213
24214-#ifndef CONFIG_X86_64
24215+#ifdef CONFIG_X86_32
24216 /*
24217 * The sysexit path does not restore ds/es, so we must set them to
24218 * a reasonable value ourselves.
24219@@ -7104,8 +7131,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24220 * may be executed in interrupt context, which saves and restore segments
24221 * around it, nullifying its effect.
24222 */
24223- loadsegment(ds, __USER_DS);
24224- loadsegment(es, __USER_DS);
24225+ loadsegment(ds, __KERNEL_DS);
24226+ loadsegment(es, __KERNEL_DS);
24227+ loadsegment(ss, __KERNEL_DS);
24228+
24229+#ifdef CONFIG_PAX_KERNEXEC
24230+ loadsegment(fs, __KERNEL_PERCPU);
24231+#endif
24232+
24233+#ifdef CONFIG_PAX_MEMORY_UDEREF
24234+ __set_fs(current_thread_info()->addr_limit);
24235+#endif
24236+
24237 #endif
24238
24239 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24240diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24241index e8ba99c..ee9d7d9 100644
24242--- a/arch/x86/kvm/x86.c
24243+++ b/arch/x86/kvm/x86.c
24244@@ -1725,8 +1725,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24245 {
24246 struct kvm *kvm = vcpu->kvm;
24247 int lm = is_long_mode(vcpu);
24248- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24249- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24250+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24251+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24252 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24253 : kvm->arch.xen_hvm_config.blob_size_32;
24254 u32 page_num = data & ~PAGE_MASK;
24255@@ -2609,6 +2609,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24256 if (n < msr_list.nmsrs)
24257 goto out;
24258 r = -EFAULT;
24259+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24260+ goto out;
24261 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24262 num_msrs_to_save * sizeof(u32)))
24263 goto out;
24264@@ -5297,7 +5299,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24265 };
24266 #endif
24267
24268-int kvm_arch_init(void *opaque)
24269+int kvm_arch_init(const void *opaque)
24270 {
24271 int r;
24272 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24273diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24274index 7114c63..a1018fc 100644
24275--- a/arch/x86/lguest/boot.c
24276+++ b/arch/x86/lguest/boot.c
24277@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24278 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24279 * Launcher to reboot us.
24280 */
24281-static void lguest_restart(char *reason)
24282+static __noreturn void lguest_restart(char *reason)
24283 {
24284 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24285+ BUG();
24286 }
24287
24288 /*G:050
24289diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24290index 00933d5..3a64af9 100644
24291--- a/arch/x86/lib/atomic64_386_32.S
24292+++ b/arch/x86/lib/atomic64_386_32.S
24293@@ -48,6 +48,10 @@ BEGIN(read)
24294 movl (v), %eax
24295 movl 4(v), %edx
24296 RET_ENDP
24297+BEGIN(read_unchecked)
24298+ movl (v), %eax
24299+ movl 4(v), %edx
24300+RET_ENDP
24301 #undef v
24302
24303 #define v %esi
24304@@ -55,6 +59,10 @@ BEGIN(set)
24305 movl %ebx, (v)
24306 movl %ecx, 4(v)
24307 RET_ENDP
24308+BEGIN(set_unchecked)
24309+ movl %ebx, (v)
24310+ movl %ecx, 4(v)
24311+RET_ENDP
24312 #undef v
24313
24314 #define v %esi
24315@@ -70,6 +78,20 @@ RET_ENDP
24316 BEGIN(add)
24317 addl %eax, (v)
24318 adcl %edx, 4(v)
24319+
24320+#ifdef CONFIG_PAX_REFCOUNT
24321+ jno 0f
24322+ subl %eax, (v)
24323+ sbbl %edx, 4(v)
24324+ int $4
24325+0:
24326+ _ASM_EXTABLE(0b, 0b)
24327+#endif
24328+
24329+RET_ENDP
24330+BEGIN(add_unchecked)
24331+ addl %eax, (v)
24332+ adcl %edx, 4(v)
24333 RET_ENDP
24334 #undef v
24335
24336@@ -77,6 +99,24 @@ RET_ENDP
24337 BEGIN(add_return)
24338 addl (v), %eax
24339 adcl 4(v), %edx
24340+
24341+#ifdef CONFIG_PAX_REFCOUNT
24342+ into
24343+1234:
24344+ _ASM_EXTABLE(1234b, 2f)
24345+#endif
24346+
24347+ movl %eax, (v)
24348+ movl %edx, 4(v)
24349+
24350+#ifdef CONFIG_PAX_REFCOUNT
24351+2:
24352+#endif
24353+
24354+RET_ENDP
24355+BEGIN(add_return_unchecked)
24356+ addl (v), %eax
24357+ adcl 4(v), %edx
24358 movl %eax, (v)
24359 movl %edx, 4(v)
24360 RET_ENDP
24361@@ -86,6 +126,20 @@ RET_ENDP
24362 BEGIN(sub)
24363 subl %eax, (v)
24364 sbbl %edx, 4(v)
24365+
24366+#ifdef CONFIG_PAX_REFCOUNT
24367+ jno 0f
24368+ addl %eax, (v)
24369+ adcl %edx, 4(v)
24370+ int $4
24371+0:
24372+ _ASM_EXTABLE(0b, 0b)
24373+#endif
24374+
24375+RET_ENDP
24376+BEGIN(sub_unchecked)
24377+ subl %eax, (v)
24378+ sbbl %edx, 4(v)
24379 RET_ENDP
24380 #undef v
24381
24382@@ -96,6 +150,27 @@ BEGIN(sub_return)
24383 sbbl $0, %edx
24384 addl (v), %eax
24385 adcl 4(v), %edx
24386+
24387+#ifdef CONFIG_PAX_REFCOUNT
24388+ into
24389+1234:
24390+ _ASM_EXTABLE(1234b, 2f)
24391+#endif
24392+
24393+ movl %eax, (v)
24394+ movl %edx, 4(v)
24395+
24396+#ifdef CONFIG_PAX_REFCOUNT
24397+2:
24398+#endif
24399+
24400+RET_ENDP
24401+BEGIN(sub_return_unchecked)
24402+ negl %edx
24403+ negl %eax
24404+ sbbl $0, %edx
24405+ addl (v), %eax
24406+ adcl 4(v), %edx
24407 movl %eax, (v)
24408 movl %edx, 4(v)
24409 RET_ENDP
24410@@ -105,6 +180,20 @@ RET_ENDP
24411 BEGIN(inc)
24412 addl $1, (v)
24413 adcl $0, 4(v)
24414+
24415+#ifdef CONFIG_PAX_REFCOUNT
24416+ jno 0f
24417+ subl $1, (v)
24418+ sbbl $0, 4(v)
24419+ int $4
24420+0:
24421+ _ASM_EXTABLE(0b, 0b)
24422+#endif
24423+
24424+RET_ENDP
24425+BEGIN(inc_unchecked)
24426+ addl $1, (v)
24427+ adcl $0, 4(v)
24428 RET_ENDP
24429 #undef v
24430
24431@@ -114,6 +203,26 @@ BEGIN(inc_return)
24432 movl 4(v), %edx
24433 addl $1, %eax
24434 adcl $0, %edx
24435+
24436+#ifdef CONFIG_PAX_REFCOUNT
24437+ into
24438+1234:
24439+ _ASM_EXTABLE(1234b, 2f)
24440+#endif
24441+
24442+ movl %eax, (v)
24443+ movl %edx, 4(v)
24444+
24445+#ifdef CONFIG_PAX_REFCOUNT
24446+2:
24447+#endif
24448+
24449+RET_ENDP
24450+BEGIN(inc_return_unchecked)
24451+ movl (v), %eax
24452+ movl 4(v), %edx
24453+ addl $1, %eax
24454+ adcl $0, %edx
24455 movl %eax, (v)
24456 movl %edx, 4(v)
24457 RET_ENDP
24458@@ -123,6 +232,20 @@ RET_ENDP
24459 BEGIN(dec)
24460 subl $1, (v)
24461 sbbl $0, 4(v)
24462+
24463+#ifdef CONFIG_PAX_REFCOUNT
24464+ jno 0f
24465+ addl $1, (v)
24466+ adcl $0, 4(v)
24467+ int $4
24468+0:
24469+ _ASM_EXTABLE(0b, 0b)
24470+#endif
24471+
24472+RET_ENDP
24473+BEGIN(dec_unchecked)
24474+ subl $1, (v)
24475+ sbbl $0, 4(v)
24476 RET_ENDP
24477 #undef v
24478
24479@@ -132,6 +255,26 @@ BEGIN(dec_return)
24480 movl 4(v), %edx
24481 subl $1, %eax
24482 sbbl $0, %edx
24483+
24484+#ifdef CONFIG_PAX_REFCOUNT
24485+ into
24486+1234:
24487+ _ASM_EXTABLE(1234b, 2f)
24488+#endif
24489+
24490+ movl %eax, (v)
24491+ movl %edx, 4(v)
24492+
24493+#ifdef CONFIG_PAX_REFCOUNT
24494+2:
24495+#endif
24496+
24497+RET_ENDP
24498+BEGIN(dec_return_unchecked)
24499+ movl (v), %eax
24500+ movl 4(v), %edx
24501+ subl $1, %eax
24502+ sbbl $0, %edx
24503 movl %eax, (v)
24504 movl %edx, 4(v)
24505 RET_ENDP
24506@@ -143,6 +286,13 @@ BEGIN(add_unless)
24507 adcl %edx, %edi
24508 addl (v), %eax
24509 adcl 4(v), %edx
24510+
24511+#ifdef CONFIG_PAX_REFCOUNT
24512+ into
24513+1234:
24514+ _ASM_EXTABLE(1234b, 2f)
24515+#endif
24516+
24517 cmpl %eax, %ecx
24518 je 3f
24519 1:
24520@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24521 1:
24522 addl $1, %eax
24523 adcl $0, %edx
24524+
24525+#ifdef CONFIG_PAX_REFCOUNT
24526+ into
24527+1234:
24528+ _ASM_EXTABLE(1234b, 2f)
24529+#endif
24530+
24531 movl %eax, (v)
24532 movl %edx, 4(v)
24533 movl $1, %eax
24534@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24535 movl 4(v), %edx
24536 subl $1, %eax
24537 sbbl $0, %edx
24538+
24539+#ifdef CONFIG_PAX_REFCOUNT
24540+ into
24541+1234:
24542+ _ASM_EXTABLE(1234b, 1f)
24543+#endif
24544+
24545 js 1f
24546 movl %eax, (v)
24547 movl %edx, 4(v)
24548diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24549index f5cc9eb..51fa319 100644
24550--- a/arch/x86/lib/atomic64_cx8_32.S
24551+++ b/arch/x86/lib/atomic64_cx8_32.S
24552@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24553 CFI_STARTPROC
24554
24555 read64 %ecx
24556+ pax_force_retaddr
24557 ret
24558 CFI_ENDPROC
24559 ENDPROC(atomic64_read_cx8)
24560
24561+ENTRY(atomic64_read_unchecked_cx8)
24562+ CFI_STARTPROC
24563+
24564+ read64 %ecx
24565+ pax_force_retaddr
24566+ ret
24567+ CFI_ENDPROC
24568+ENDPROC(atomic64_read_unchecked_cx8)
24569+
24570 ENTRY(atomic64_set_cx8)
24571 CFI_STARTPROC
24572
24573@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24574 cmpxchg8b (%esi)
24575 jne 1b
24576
24577+ pax_force_retaddr
24578 ret
24579 CFI_ENDPROC
24580 ENDPROC(atomic64_set_cx8)
24581
24582+ENTRY(atomic64_set_unchecked_cx8)
24583+ CFI_STARTPROC
24584+
24585+1:
24586+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24587+ * are atomic on 586 and newer */
24588+ cmpxchg8b (%esi)
24589+ jne 1b
24590+
24591+ pax_force_retaddr
24592+ ret
24593+ CFI_ENDPROC
24594+ENDPROC(atomic64_set_unchecked_cx8)
24595+
24596 ENTRY(atomic64_xchg_cx8)
24597 CFI_STARTPROC
24598
24599@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24600 cmpxchg8b (%esi)
24601 jne 1b
24602
24603+ pax_force_retaddr
24604 ret
24605 CFI_ENDPROC
24606 ENDPROC(atomic64_xchg_cx8)
24607
24608-.macro addsub_return func ins insc
24609-ENTRY(atomic64_\func\()_return_cx8)
24610+.macro addsub_return func ins insc unchecked=""
24611+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24612 CFI_STARTPROC
24613 SAVE ebp
24614 SAVE ebx
24615@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24616 movl %edx, %ecx
24617 \ins\()l %esi, %ebx
24618 \insc\()l %edi, %ecx
24619+
24620+.ifb \unchecked
24621+#ifdef CONFIG_PAX_REFCOUNT
24622+ into
24623+2:
24624+ _ASM_EXTABLE(2b, 3f)
24625+#endif
24626+.endif
24627+
24628 LOCK_PREFIX
24629 cmpxchg8b (%ebp)
24630 jne 1b
24631-
24632-10:
24633 movl %ebx, %eax
24634 movl %ecx, %edx
24635+
24636+.ifb \unchecked
24637+#ifdef CONFIG_PAX_REFCOUNT
24638+3:
24639+#endif
24640+.endif
24641+
24642 RESTORE edi
24643 RESTORE esi
24644 RESTORE ebx
24645 RESTORE ebp
24646+ pax_force_retaddr
24647 ret
24648 CFI_ENDPROC
24649-ENDPROC(atomic64_\func\()_return_cx8)
24650+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24651 .endm
24652
24653 addsub_return add add adc
24654 addsub_return sub sub sbb
24655+addsub_return add add adc _unchecked
24656+addsub_return sub sub sbb _unchecked
24657
24658-.macro incdec_return func ins insc
24659-ENTRY(atomic64_\func\()_return_cx8)
24660+.macro incdec_return func ins insc unchecked=""
24661+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24662 CFI_STARTPROC
24663 SAVE ebx
24664
24665@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24666 movl %edx, %ecx
24667 \ins\()l $1, %ebx
24668 \insc\()l $0, %ecx
24669+
24670+.ifb \unchecked
24671+#ifdef CONFIG_PAX_REFCOUNT
24672+ into
24673+2:
24674+ _ASM_EXTABLE(2b, 3f)
24675+#endif
24676+.endif
24677+
24678 LOCK_PREFIX
24679 cmpxchg8b (%esi)
24680 jne 1b
24681
24682-10:
24683 movl %ebx, %eax
24684 movl %ecx, %edx
24685+
24686+.ifb \unchecked
24687+#ifdef CONFIG_PAX_REFCOUNT
24688+3:
24689+#endif
24690+.endif
24691+
24692 RESTORE ebx
24693+ pax_force_retaddr
24694 ret
24695 CFI_ENDPROC
24696-ENDPROC(atomic64_\func\()_return_cx8)
24697+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24698 .endm
24699
24700 incdec_return inc add adc
24701 incdec_return dec sub sbb
24702+incdec_return inc add adc _unchecked
24703+incdec_return dec sub sbb _unchecked
24704
24705 ENTRY(atomic64_dec_if_positive_cx8)
24706 CFI_STARTPROC
24707@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24708 movl %edx, %ecx
24709 subl $1, %ebx
24710 sbb $0, %ecx
24711+
24712+#ifdef CONFIG_PAX_REFCOUNT
24713+ into
24714+1234:
24715+ _ASM_EXTABLE(1234b, 2f)
24716+#endif
24717+
24718 js 2f
24719 LOCK_PREFIX
24720 cmpxchg8b (%esi)
24721@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24722 movl %ebx, %eax
24723 movl %ecx, %edx
24724 RESTORE ebx
24725+ pax_force_retaddr
24726 ret
24727 CFI_ENDPROC
24728 ENDPROC(atomic64_dec_if_positive_cx8)
24729@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24730 movl %edx, %ecx
24731 addl %ebp, %ebx
24732 adcl %edi, %ecx
24733+
24734+#ifdef CONFIG_PAX_REFCOUNT
24735+ into
24736+1234:
24737+ _ASM_EXTABLE(1234b, 3f)
24738+#endif
24739+
24740 LOCK_PREFIX
24741 cmpxchg8b (%esi)
24742 jne 1b
24743@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24744 CFI_ADJUST_CFA_OFFSET -8
24745 RESTORE ebx
24746 RESTORE ebp
24747+ pax_force_retaddr
24748 ret
24749 4:
24750 cmpl %edx, 4(%esp)
24751@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24752 xorl %ecx, %ecx
24753 addl $1, %ebx
24754 adcl %edx, %ecx
24755+
24756+#ifdef CONFIG_PAX_REFCOUNT
24757+ into
24758+1234:
24759+ _ASM_EXTABLE(1234b, 3f)
24760+#endif
24761+
24762 LOCK_PREFIX
24763 cmpxchg8b (%esi)
24764 jne 1b
24765@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24766 movl $1, %eax
24767 3:
24768 RESTORE ebx
24769+ pax_force_retaddr
24770 ret
24771 CFI_ENDPROC
24772 ENDPROC(atomic64_inc_not_zero_cx8)
24773diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24774index e78b8ee..7e173a8 100644
24775--- a/arch/x86/lib/checksum_32.S
24776+++ b/arch/x86/lib/checksum_32.S
24777@@ -29,7 +29,8 @@
24778 #include <asm/dwarf2.h>
24779 #include <asm/errno.h>
24780 #include <asm/asm.h>
24781-
24782+#include <asm/segment.h>
24783+
24784 /*
24785 * computes a partial checksum, e.g. for TCP/UDP fragments
24786 */
24787@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24788
24789 #define ARGBASE 16
24790 #define FP 12
24791-
24792-ENTRY(csum_partial_copy_generic)
24793+
24794+ENTRY(csum_partial_copy_generic_to_user)
24795 CFI_STARTPROC
24796+
24797+#ifdef CONFIG_PAX_MEMORY_UDEREF
24798+ pushl_cfi %gs
24799+ popl_cfi %es
24800+ jmp csum_partial_copy_generic
24801+#endif
24802+
24803+ENTRY(csum_partial_copy_generic_from_user)
24804+
24805+#ifdef CONFIG_PAX_MEMORY_UDEREF
24806+ pushl_cfi %gs
24807+ popl_cfi %ds
24808+#endif
24809+
24810+ENTRY(csum_partial_copy_generic)
24811 subl $4,%esp
24812 CFI_ADJUST_CFA_OFFSET 4
24813 pushl_cfi %edi
24814@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24815 jmp 4f
24816 SRC(1: movw (%esi), %bx )
24817 addl $2, %esi
24818-DST( movw %bx, (%edi) )
24819+DST( movw %bx, %es:(%edi) )
24820 addl $2, %edi
24821 addw %bx, %ax
24822 adcl $0, %eax
24823@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24824 SRC(1: movl (%esi), %ebx )
24825 SRC( movl 4(%esi), %edx )
24826 adcl %ebx, %eax
24827-DST( movl %ebx, (%edi) )
24828+DST( movl %ebx, %es:(%edi) )
24829 adcl %edx, %eax
24830-DST( movl %edx, 4(%edi) )
24831+DST( movl %edx, %es:4(%edi) )
24832
24833 SRC( movl 8(%esi), %ebx )
24834 SRC( movl 12(%esi), %edx )
24835 adcl %ebx, %eax
24836-DST( movl %ebx, 8(%edi) )
24837+DST( movl %ebx, %es:8(%edi) )
24838 adcl %edx, %eax
24839-DST( movl %edx, 12(%edi) )
24840+DST( movl %edx, %es:12(%edi) )
24841
24842 SRC( movl 16(%esi), %ebx )
24843 SRC( movl 20(%esi), %edx )
24844 adcl %ebx, %eax
24845-DST( movl %ebx, 16(%edi) )
24846+DST( movl %ebx, %es:16(%edi) )
24847 adcl %edx, %eax
24848-DST( movl %edx, 20(%edi) )
24849+DST( movl %edx, %es:20(%edi) )
24850
24851 SRC( movl 24(%esi), %ebx )
24852 SRC( movl 28(%esi), %edx )
24853 adcl %ebx, %eax
24854-DST( movl %ebx, 24(%edi) )
24855+DST( movl %ebx, %es:24(%edi) )
24856 adcl %edx, %eax
24857-DST( movl %edx, 28(%edi) )
24858+DST( movl %edx, %es:28(%edi) )
24859
24860 lea 32(%esi), %esi
24861 lea 32(%edi), %edi
24862@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24863 shrl $2, %edx # This clears CF
24864 SRC(3: movl (%esi), %ebx )
24865 adcl %ebx, %eax
24866-DST( movl %ebx, (%edi) )
24867+DST( movl %ebx, %es:(%edi) )
24868 lea 4(%esi), %esi
24869 lea 4(%edi), %edi
24870 dec %edx
24871@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24872 jb 5f
24873 SRC( movw (%esi), %cx )
24874 leal 2(%esi), %esi
24875-DST( movw %cx, (%edi) )
24876+DST( movw %cx, %es:(%edi) )
24877 leal 2(%edi), %edi
24878 je 6f
24879 shll $16,%ecx
24880 SRC(5: movb (%esi), %cl )
24881-DST( movb %cl, (%edi) )
24882+DST( movb %cl, %es:(%edi) )
24883 6: addl %ecx, %eax
24884 adcl $0, %eax
24885 7:
24886@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24887
24888 6001:
24889 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24890- movl $-EFAULT, (%ebx)
24891+ movl $-EFAULT, %ss:(%ebx)
24892
24893 # zero the complete destination - computing the rest
24894 # is too much work
24895@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24896
24897 6002:
24898 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24899- movl $-EFAULT,(%ebx)
24900+ movl $-EFAULT,%ss:(%ebx)
24901 jmp 5000b
24902
24903 .previous
24904
24905+ pushl_cfi %ss
24906+ popl_cfi %ds
24907+ pushl_cfi %ss
24908+ popl_cfi %es
24909 popl_cfi %ebx
24910 CFI_RESTORE ebx
24911 popl_cfi %esi
24912@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24913 popl_cfi %ecx # equivalent to addl $4,%esp
24914 ret
24915 CFI_ENDPROC
24916-ENDPROC(csum_partial_copy_generic)
24917+ENDPROC(csum_partial_copy_generic_to_user)
24918
24919 #else
24920
24921 /* Version for PentiumII/PPro */
24922
24923 #define ROUND1(x) \
24924+ nop; nop; nop; \
24925 SRC(movl x(%esi), %ebx ) ; \
24926 addl %ebx, %eax ; \
24927- DST(movl %ebx, x(%edi) ) ;
24928+ DST(movl %ebx, %es:x(%edi)) ;
24929
24930 #define ROUND(x) \
24931+ nop; nop; nop; \
24932 SRC(movl x(%esi), %ebx ) ; \
24933 adcl %ebx, %eax ; \
24934- DST(movl %ebx, x(%edi) ) ;
24935+ DST(movl %ebx, %es:x(%edi)) ;
24936
24937 #define ARGBASE 12
24938-
24939-ENTRY(csum_partial_copy_generic)
24940+
24941+ENTRY(csum_partial_copy_generic_to_user)
24942 CFI_STARTPROC
24943+
24944+#ifdef CONFIG_PAX_MEMORY_UDEREF
24945+ pushl_cfi %gs
24946+ popl_cfi %es
24947+ jmp csum_partial_copy_generic
24948+#endif
24949+
24950+ENTRY(csum_partial_copy_generic_from_user)
24951+
24952+#ifdef CONFIG_PAX_MEMORY_UDEREF
24953+ pushl_cfi %gs
24954+ popl_cfi %ds
24955+#endif
24956+
24957+ENTRY(csum_partial_copy_generic)
24958 pushl_cfi %ebx
24959 CFI_REL_OFFSET ebx, 0
24960 pushl_cfi %edi
24961@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24962 subl %ebx, %edi
24963 lea -1(%esi),%edx
24964 andl $-32,%edx
24965- lea 3f(%ebx,%ebx), %ebx
24966+ lea 3f(%ebx,%ebx,2), %ebx
24967 testl %esi, %esi
24968 jmp *%ebx
24969 1: addl $64,%esi
24970@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24971 jb 5f
24972 SRC( movw (%esi), %dx )
24973 leal 2(%esi), %esi
24974-DST( movw %dx, (%edi) )
24975+DST( movw %dx, %es:(%edi) )
24976 leal 2(%edi), %edi
24977 je 6f
24978 shll $16,%edx
24979 5:
24980 SRC( movb (%esi), %dl )
24981-DST( movb %dl, (%edi) )
24982+DST( movb %dl, %es:(%edi) )
24983 6: addl %edx, %eax
24984 adcl $0, %eax
24985 7:
24986 .section .fixup, "ax"
24987 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24988- movl $-EFAULT, (%ebx)
24989+ movl $-EFAULT, %ss:(%ebx)
24990 # zero the complete destination (computing the rest is too much work)
24991 movl ARGBASE+8(%esp),%edi # dst
24992 movl ARGBASE+12(%esp),%ecx # len
24993@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24994 rep; stosb
24995 jmp 7b
24996 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24997- movl $-EFAULT, (%ebx)
24998+ movl $-EFAULT, %ss:(%ebx)
24999 jmp 7b
25000 .previous
25001
25002+#ifdef CONFIG_PAX_MEMORY_UDEREF
25003+ pushl_cfi %ss
25004+ popl_cfi %ds
25005+ pushl_cfi %ss
25006+ popl_cfi %es
25007+#endif
25008+
25009 popl_cfi %esi
25010 CFI_RESTORE esi
25011 popl_cfi %edi
25012@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
25013 CFI_RESTORE ebx
25014 ret
25015 CFI_ENDPROC
25016-ENDPROC(csum_partial_copy_generic)
25017+ENDPROC(csum_partial_copy_generic_to_user)
25018
25019 #undef ROUND
25020 #undef ROUND1
25021diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
25022index f2145cf..cea889d 100644
25023--- a/arch/x86/lib/clear_page_64.S
25024+++ b/arch/x86/lib/clear_page_64.S
25025@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
25026 movl $4096/8,%ecx
25027 xorl %eax,%eax
25028 rep stosq
25029+ pax_force_retaddr
25030 ret
25031 CFI_ENDPROC
25032 ENDPROC(clear_page_c)
25033@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
25034 movl $4096,%ecx
25035 xorl %eax,%eax
25036 rep stosb
25037+ pax_force_retaddr
25038 ret
25039 CFI_ENDPROC
25040 ENDPROC(clear_page_c_e)
25041@@ -43,6 +45,7 @@ ENTRY(clear_page)
25042 leaq 64(%rdi),%rdi
25043 jnz .Lloop
25044 nop
25045+ pax_force_retaddr
25046 ret
25047 CFI_ENDPROC
25048 .Lclear_page_end:
25049@@ -58,7 +61,7 @@ ENDPROC(clear_page)
25050
25051 #include <asm/cpufeature.h>
25052
25053- .section .altinstr_replacement,"ax"
25054+ .section .altinstr_replacement,"a"
25055 1: .byte 0xeb /* jmp <disp8> */
25056 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
25057 2: .byte 0xeb /* jmp <disp8> */
25058diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
25059index 1e572c5..2a162cd 100644
25060--- a/arch/x86/lib/cmpxchg16b_emu.S
25061+++ b/arch/x86/lib/cmpxchg16b_emu.S
25062@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
25063
25064 popf
25065 mov $1, %al
25066+ pax_force_retaddr
25067 ret
25068
25069 not_same:
25070 popf
25071 xor %al,%al
25072+ pax_force_retaddr
25073 ret
25074
25075 CFI_ENDPROC
25076diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
25077index 176cca6..1166c50 100644
25078--- a/arch/x86/lib/copy_page_64.S
25079+++ b/arch/x86/lib/copy_page_64.S
25080@@ -9,6 +9,7 @@ copy_page_rep:
25081 CFI_STARTPROC
25082 movl $4096/8, %ecx
25083 rep movsq
25084+ pax_force_retaddr
25085 ret
25086 CFI_ENDPROC
25087 ENDPROC(copy_page_rep)
25088@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
25089
25090 ENTRY(copy_page)
25091 CFI_STARTPROC
25092- subq $2*8, %rsp
25093- CFI_ADJUST_CFA_OFFSET 2*8
25094+ subq $3*8, %rsp
25095+ CFI_ADJUST_CFA_OFFSET 3*8
25096 movq %rbx, (%rsp)
25097 CFI_REL_OFFSET rbx, 0
25098 movq %r12, 1*8(%rsp)
25099 CFI_REL_OFFSET r12, 1*8
25100+ movq %r13, 2*8(%rsp)
25101+ CFI_REL_OFFSET r13, 2*8
25102
25103 movl $(4096/64)-5, %ecx
25104 .p2align 4
25105@@ -36,7 +39,7 @@ ENTRY(copy_page)
25106 movq 0x8*2(%rsi), %rdx
25107 movq 0x8*3(%rsi), %r8
25108 movq 0x8*4(%rsi), %r9
25109- movq 0x8*5(%rsi), %r10
25110+ movq 0x8*5(%rsi), %r13
25111 movq 0x8*6(%rsi), %r11
25112 movq 0x8*7(%rsi), %r12
25113
25114@@ -47,7 +50,7 @@ ENTRY(copy_page)
25115 movq %rdx, 0x8*2(%rdi)
25116 movq %r8, 0x8*3(%rdi)
25117 movq %r9, 0x8*4(%rdi)
25118- movq %r10, 0x8*5(%rdi)
25119+ movq %r13, 0x8*5(%rdi)
25120 movq %r11, 0x8*6(%rdi)
25121 movq %r12, 0x8*7(%rdi)
25122
25123@@ -66,7 +69,7 @@ ENTRY(copy_page)
25124 movq 0x8*2(%rsi), %rdx
25125 movq 0x8*3(%rsi), %r8
25126 movq 0x8*4(%rsi), %r9
25127- movq 0x8*5(%rsi), %r10
25128+ movq 0x8*5(%rsi), %r13
25129 movq 0x8*6(%rsi), %r11
25130 movq 0x8*7(%rsi), %r12
25131
25132@@ -75,7 +78,7 @@ ENTRY(copy_page)
25133 movq %rdx, 0x8*2(%rdi)
25134 movq %r8, 0x8*3(%rdi)
25135 movq %r9, 0x8*4(%rdi)
25136- movq %r10, 0x8*5(%rdi)
25137+ movq %r13, 0x8*5(%rdi)
25138 movq %r11, 0x8*6(%rdi)
25139 movq %r12, 0x8*7(%rdi)
25140
25141@@ -87,8 +90,11 @@ ENTRY(copy_page)
25142 CFI_RESTORE rbx
25143 movq 1*8(%rsp), %r12
25144 CFI_RESTORE r12
25145- addq $2*8, %rsp
25146- CFI_ADJUST_CFA_OFFSET -2*8
25147+ movq 2*8(%rsp), %r13
25148+ CFI_RESTORE r13
25149+ addq $3*8, %rsp
25150+ CFI_ADJUST_CFA_OFFSET -3*8
25151+ pax_force_retaddr
25152 ret
25153 .Lcopy_page_end:
25154 CFI_ENDPROC
25155@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25156
25157 #include <asm/cpufeature.h>
25158
25159- .section .altinstr_replacement,"ax"
25160+ .section .altinstr_replacement,"a"
25161 1: .byte 0xeb /* jmp <disp8> */
25162 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25163 2:
25164diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25165index a30ca15..d25fab6 100644
25166--- a/arch/x86/lib/copy_user_64.S
25167+++ b/arch/x86/lib/copy_user_64.S
25168@@ -18,6 +18,7 @@
25169 #include <asm/alternative-asm.h>
25170 #include <asm/asm.h>
25171 #include <asm/smap.h>
25172+#include <asm/pgtable.h>
25173
25174 /*
25175 * By placing feature2 after feature1 in altinstructions section, we logically
25176@@ -31,7 +32,7 @@
25177 .byte 0xe9 /* 32bit jump */
25178 .long \orig-1f /* by default jump to orig */
25179 1:
25180- .section .altinstr_replacement,"ax"
25181+ .section .altinstr_replacement,"a"
25182 2: .byte 0xe9 /* near jump with 32bit immediate */
25183 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25184 3: .byte 0xe9 /* near jump with 32bit immediate */
25185@@ -70,47 +71,20 @@
25186 #endif
25187 .endm
25188
25189-/* Standard copy_to_user with segment limit checking */
25190-ENTRY(_copy_to_user)
25191- CFI_STARTPROC
25192- GET_THREAD_INFO(%rax)
25193- movq %rdi,%rcx
25194- addq %rdx,%rcx
25195- jc bad_to_user
25196- cmpq TI_addr_limit(%rax),%rcx
25197- ja bad_to_user
25198- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25199- copy_user_generic_unrolled,copy_user_generic_string, \
25200- copy_user_enhanced_fast_string
25201- CFI_ENDPROC
25202-ENDPROC(_copy_to_user)
25203-
25204-/* Standard copy_from_user with segment limit checking */
25205-ENTRY(_copy_from_user)
25206- CFI_STARTPROC
25207- GET_THREAD_INFO(%rax)
25208- movq %rsi,%rcx
25209- addq %rdx,%rcx
25210- jc bad_from_user
25211- cmpq TI_addr_limit(%rax),%rcx
25212- ja bad_from_user
25213- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25214- copy_user_generic_unrolled,copy_user_generic_string, \
25215- copy_user_enhanced_fast_string
25216- CFI_ENDPROC
25217-ENDPROC(_copy_from_user)
25218-
25219 .section .fixup,"ax"
25220 /* must zero dest */
25221 ENTRY(bad_from_user)
25222 bad_from_user:
25223 CFI_STARTPROC
25224+ testl %edx,%edx
25225+ js bad_to_user
25226 movl %edx,%ecx
25227 xorl %eax,%eax
25228 rep
25229 stosb
25230 bad_to_user:
25231 movl %edx,%eax
25232+ pax_force_retaddr
25233 ret
25234 CFI_ENDPROC
25235 ENDPROC(bad_from_user)
25236@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25237 jz 17f
25238 1: movq (%rsi),%r8
25239 2: movq 1*8(%rsi),%r9
25240-3: movq 2*8(%rsi),%r10
25241+3: movq 2*8(%rsi),%rax
25242 4: movq 3*8(%rsi),%r11
25243 5: movq %r8,(%rdi)
25244 6: movq %r9,1*8(%rdi)
25245-7: movq %r10,2*8(%rdi)
25246+7: movq %rax,2*8(%rdi)
25247 8: movq %r11,3*8(%rdi)
25248 9: movq 4*8(%rsi),%r8
25249 10: movq 5*8(%rsi),%r9
25250-11: movq 6*8(%rsi),%r10
25251+11: movq 6*8(%rsi),%rax
25252 12: movq 7*8(%rsi),%r11
25253 13: movq %r8,4*8(%rdi)
25254 14: movq %r9,5*8(%rdi)
25255-15: movq %r10,6*8(%rdi)
25256+15: movq %rax,6*8(%rdi)
25257 16: movq %r11,7*8(%rdi)
25258 leaq 64(%rsi),%rsi
25259 leaq 64(%rdi),%rdi
25260@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25261 jnz 21b
25262 23: xor %eax,%eax
25263 ASM_CLAC
25264+ pax_force_retaddr
25265 ret
25266
25267 .section .fixup,"ax"
25268@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25269 movsb
25270 4: xorl %eax,%eax
25271 ASM_CLAC
25272+ pax_force_retaddr
25273 ret
25274
25275 .section .fixup,"ax"
25276@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25277 movsb
25278 2: xorl %eax,%eax
25279 ASM_CLAC
25280+ pax_force_retaddr
25281 ret
25282
25283 .section .fixup,"ax"
25284diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25285index 6a4f43c..f08b4a2 100644
25286--- a/arch/x86/lib/copy_user_nocache_64.S
25287+++ b/arch/x86/lib/copy_user_nocache_64.S
25288@@ -8,6 +8,7 @@
25289
25290 #include <linux/linkage.h>
25291 #include <asm/dwarf2.h>
25292+#include <asm/alternative-asm.h>
25293
25294 #define FIX_ALIGNMENT 1
25295
25296@@ -16,6 +17,7 @@
25297 #include <asm/thread_info.h>
25298 #include <asm/asm.h>
25299 #include <asm/smap.h>
25300+#include <asm/pgtable.h>
25301
25302 .macro ALIGN_DESTINATION
25303 #ifdef FIX_ALIGNMENT
25304@@ -49,6 +51,15 @@
25305 */
25306 ENTRY(__copy_user_nocache)
25307 CFI_STARTPROC
25308+
25309+#ifdef CONFIG_PAX_MEMORY_UDEREF
25310+ mov pax_user_shadow_base,%rcx
25311+ cmp %rcx,%rsi
25312+ jae 1f
25313+ add %rcx,%rsi
25314+1:
25315+#endif
25316+
25317 ASM_STAC
25318 cmpl $8,%edx
25319 jb 20f /* less then 8 bytes, go to byte copy loop */
25320@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25321 jz 17f
25322 1: movq (%rsi),%r8
25323 2: movq 1*8(%rsi),%r9
25324-3: movq 2*8(%rsi),%r10
25325+3: movq 2*8(%rsi),%rax
25326 4: movq 3*8(%rsi),%r11
25327 5: movnti %r8,(%rdi)
25328 6: movnti %r9,1*8(%rdi)
25329-7: movnti %r10,2*8(%rdi)
25330+7: movnti %rax,2*8(%rdi)
25331 8: movnti %r11,3*8(%rdi)
25332 9: movq 4*8(%rsi),%r8
25333 10: movq 5*8(%rsi),%r9
25334-11: movq 6*8(%rsi),%r10
25335+11: movq 6*8(%rsi),%rax
25336 12: movq 7*8(%rsi),%r11
25337 13: movnti %r8,4*8(%rdi)
25338 14: movnti %r9,5*8(%rdi)
25339-15: movnti %r10,6*8(%rdi)
25340+15: movnti %rax,6*8(%rdi)
25341 16: movnti %r11,7*8(%rdi)
25342 leaq 64(%rsi),%rsi
25343 leaq 64(%rdi),%rdi
25344@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25345 23: xorl %eax,%eax
25346 ASM_CLAC
25347 sfence
25348+ pax_force_retaddr
25349 ret
25350
25351 .section .fixup,"ax"
25352diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25353index 2419d5f..953ee51 100644
25354--- a/arch/x86/lib/csum-copy_64.S
25355+++ b/arch/x86/lib/csum-copy_64.S
25356@@ -9,6 +9,7 @@
25357 #include <asm/dwarf2.h>
25358 #include <asm/errno.h>
25359 #include <asm/asm.h>
25360+#include <asm/alternative-asm.h>
25361
25362 /*
25363 * Checksum copy with exception handling.
25364@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25365 CFI_RESTORE rbp
25366 addq $7*8, %rsp
25367 CFI_ADJUST_CFA_OFFSET -7*8
25368+ pax_force_retaddr 0, 1
25369 ret
25370 CFI_RESTORE_STATE
25371
25372diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25373index 25b7ae8..169fafc 100644
25374--- a/arch/x86/lib/csum-wrappers_64.c
25375+++ b/arch/x86/lib/csum-wrappers_64.c
25376@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25377 len -= 2;
25378 }
25379 }
25380- isum = csum_partial_copy_generic((__force const void *)src,
25381+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25382 dst, len, isum, errp, NULL);
25383 if (unlikely(*errp))
25384 goto out_err;
25385@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25386 }
25387
25388 *errp = 0;
25389- return csum_partial_copy_generic(src, (void __force *)dst,
25390+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25391 len, isum, NULL, errp);
25392 }
25393 EXPORT_SYMBOL(csum_partial_copy_to_user);
25394diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25395index a451235..79fb5cf 100644
25396--- a/arch/x86/lib/getuser.S
25397+++ b/arch/x86/lib/getuser.S
25398@@ -33,17 +33,40 @@
25399 #include <asm/thread_info.h>
25400 #include <asm/asm.h>
25401 #include <asm/smap.h>
25402+#include <asm/segment.h>
25403+#include <asm/pgtable.h>
25404+#include <asm/alternative-asm.h>
25405+
25406+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25407+#define __copyuser_seg gs;
25408+#else
25409+#define __copyuser_seg
25410+#endif
25411
25412 .text
25413 ENTRY(__get_user_1)
25414 CFI_STARTPROC
25415+
25416+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25417 GET_THREAD_INFO(%_ASM_DX)
25418 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25419 jae bad_get_user
25420 ASM_STAC
25421-1: movzbl (%_ASM_AX),%edx
25422+
25423+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25424+ mov pax_user_shadow_base,%_ASM_DX
25425+ cmp %_ASM_DX,%_ASM_AX
25426+ jae 1234f
25427+ add %_ASM_DX,%_ASM_AX
25428+1234:
25429+#endif
25430+
25431+#endif
25432+
25433+1: __copyuser_seg movzbl (%_ASM_AX),%edx
25434 xor %eax,%eax
25435 ASM_CLAC
25436+ pax_force_retaddr
25437 ret
25438 CFI_ENDPROC
25439 ENDPROC(__get_user_1)
25440@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
25441 ENTRY(__get_user_2)
25442 CFI_STARTPROC
25443 add $1,%_ASM_AX
25444+
25445+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25446 jc bad_get_user
25447 GET_THREAD_INFO(%_ASM_DX)
25448 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25449 jae bad_get_user
25450 ASM_STAC
25451-2: movzwl -1(%_ASM_AX),%edx
25452+
25453+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25454+ mov pax_user_shadow_base,%_ASM_DX
25455+ cmp %_ASM_DX,%_ASM_AX
25456+ jae 1234f
25457+ add %_ASM_DX,%_ASM_AX
25458+1234:
25459+#endif
25460+
25461+#endif
25462+
25463+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25464 xor %eax,%eax
25465 ASM_CLAC
25466+ pax_force_retaddr
25467 ret
25468 CFI_ENDPROC
25469 ENDPROC(__get_user_2)
25470@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
25471 ENTRY(__get_user_4)
25472 CFI_STARTPROC
25473 add $3,%_ASM_AX
25474+
25475+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25476 jc bad_get_user
25477 GET_THREAD_INFO(%_ASM_DX)
25478 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25479 jae bad_get_user
25480 ASM_STAC
25481-3: movl -3(%_ASM_AX),%edx
25482+
25483+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25484+ mov pax_user_shadow_base,%_ASM_DX
25485+ cmp %_ASM_DX,%_ASM_AX
25486+ jae 1234f
25487+ add %_ASM_DX,%_ASM_AX
25488+1234:
25489+#endif
25490+
25491+#endif
25492+
25493+3: __copyuser_seg movl -3(%_ASM_AX),%edx
25494 xor %eax,%eax
25495 ASM_CLAC
25496+ pax_force_retaddr
25497 ret
25498 CFI_ENDPROC
25499 ENDPROC(__get_user_4)
25500@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
25501 GET_THREAD_INFO(%_ASM_DX)
25502 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25503 jae bad_get_user
25504+
25505+#ifdef CONFIG_PAX_MEMORY_UDEREF
25506+ mov pax_user_shadow_base,%_ASM_DX
25507+ cmp %_ASM_DX,%_ASM_AX
25508+ jae 1234f
25509+ add %_ASM_DX,%_ASM_AX
25510+1234:
25511+#endif
25512+
25513 ASM_STAC
25514 4: movq -7(%_ASM_AX),%rdx
25515 xor %eax,%eax
25516 ASM_CLAC
25517+ pax_force_retaddr
25518 ret
25519 #else
25520 add $7,%_ASM_AX
25521@@ -102,6 +163,7 @@ ENTRY(__get_user_8)
25522 5: movl -3(%_ASM_AX),%ecx
25523 xor %eax,%eax
25524 ASM_CLAC
25525+ pax_force_retaddr
25526 ret
25527 #endif
25528 CFI_ENDPROC
25529@@ -113,6 +175,7 @@ bad_get_user:
25530 xor %edx,%edx
25531 mov $(-EFAULT),%_ASM_AX
25532 ASM_CLAC
25533+ pax_force_retaddr
25534 ret
25535 CFI_ENDPROC
25536 END(bad_get_user)
25537@@ -124,6 +187,7 @@ bad_get_user_8:
25538 xor %ecx,%ecx
25539 mov $(-EFAULT),%_ASM_AX
25540 ASM_CLAC
25541+ pax_force_retaddr
25542 ret
25543 CFI_ENDPROC
25544 END(bad_get_user_8)
25545diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25546index 54fcffe..7be149e 100644
25547--- a/arch/x86/lib/insn.c
25548+++ b/arch/x86/lib/insn.c
25549@@ -20,8 +20,10 @@
25550
25551 #ifdef __KERNEL__
25552 #include <linux/string.h>
25553+#include <asm/pgtable_types.h>
25554 #else
25555 #include <string.h>
25556+#define ktla_ktva(addr) addr
25557 #endif
25558 #include <asm/inat.h>
25559 #include <asm/insn.h>
25560@@ -53,8 +55,8 @@
25561 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25562 {
25563 memset(insn, 0, sizeof(*insn));
25564- insn->kaddr = kaddr;
25565- insn->next_byte = kaddr;
25566+ insn->kaddr = ktla_ktva(kaddr);
25567+ insn->next_byte = ktla_ktva(kaddr);
25568 insn->x86_64 = x86_64 ? 1 : 0;
25569 insn->opnd_bytes = 4;
25570 if (x86_64)
25571diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25572index 05a95e7..326f2fa 100644
25573--- a/arch/x86/lib/iomap_copy_64.S
25574+++ b/arch/x86/lib/iomap_copy_64.S
25575@@ -17,6 +17,7 @@
25576
25577 #include <linux/linkage.h>
25578 #include <asm/dwarf2.h>
25579+#include <asm/alternative-asm.h>
25580
25581 /*
25582 * override generic version in lib/iomap_copy.c
25583@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25584 CFI_STARTPROC
25585 movl %edx,%ecx
25586 rep movsd
25587+ pax_force_retaddr
25588 ret
25589 CFI_ENDPROC
25590 ENDPROC(__iowrite32_copy)
25591diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25592index 56313a3..aa84a79 100644
25593--- a/arch/x86/lib/memcpy_64.S
25594+++ b/arch/x86/lib/memcpy_64.S
25595@@ -33,6 +33,7 @@
25596 rep movsq
25597 movl %edx, %ecx
25598 rep movsb
25599+ pax_force_retaddr
25600 ret
25601 .Lmemcpy_e:
25602 .previous
25603@@ -49,6 +50,7 @@
25604 movq %rdi, %rax
25605 movq %rdx, %rcx
25606 rep movsb
25607+ pax_force_retaddr
25608 ret
25609 .Lmemcpy_e_e:
25610 .previous
25611@@ -76,13 +78,13 @@ ENTRY(memcpy)
25612 */
25613 movq 0*8(%rsi), %r8
25614 movq 1*8(%rsi), %r9
25615- movq 2*8(%rsi), %r10
25616+ movq 2*8(%rsi), %rcx
25617 movq 3*8(%rsi), %r11
25618 leaq 4*8(%rsi), %rsi
25619
25620 movq %r8, 0*8(%rdi)
25621 movq %r9, 1*8(%rdi)
25622- movq %r10, 2*8(%rdi)
25623+ movq %rcx, 2*8(%rdi)
25624 movq %r11, 3*8(%rdi)
25625 leaq 4*8(%rdi), %rdi
25626 jae .Lcopy_forward_loop
25627@@ -105,12 +107,12 @@ ENTRY(memcpy)
25628 subq $0x20, %rdx
25629 movq -1*8(%rsi), %r8
25630 movq -2*8(%rsi), %r9
25631- movq -3*8(%rsi), %r10
25632+ movq -3*8(%rsi), %rcx
25633 movq -4*8(%rsi), %r11
25634 leaq -4*8(%rsi), %rsi
25635 movq %r8, -1*8(%rdi)
25636 movq %r9, -2*8(%rdi)
25637- movq %r10, -3*8(%rdi)
25638+ movq %rcx, -3*8(%rdi)
25639 movq %r11, -4*8(%rdi)
25640 leaq -4*8(%rdi), %rdi
25641 jae .Lcopy_backward_loop
25642@@ -130,12 +132,13 @@ ENTRY(memcpy)
25643 */
25644 movq 0*8(%rsi), %r8
25645 movq 1*8(%rsi), %r9
25646- movq -2*8(%rsi, %rdx), %r10
25647+ movq -2*8(%rsi, %rdx), %rcx
25648 movq -1*8(%rsi, %rdx), %r11
25649 movq %r8, 0*8(%rdi)
25650 movq %r9, 1*8(%rdi)
25651- movq %r10, -2*8(%rdi, %rdx)
25652+ movq %rcx, -2*8(%rdi, %rdx)
25653 movq %r11, -1*8(%rdi, %rdx)
25654+ pax_force_retaddr
25655 retq
25656 .p2align 4
25657 .Lless_16bytes:
25658@@ -148,6 +151,7 @@ ENTRY(memcpy)
25659 movq -1*8(%rsi, %rdx), %r9
25660 movq %r8, 0*8(%rdi)
25661 movq %r9, -1*8(%rdi, %rdx)
25662+ pax_force_retaddr
25663 retq
25664 .p2align 4
25665 .Lless_8bytes:
25666@@ -161,6 +165,7 @@ ENTRY(memcpy)
25667 movl -4(%rsi, %rdx), %r8d
25668 movl %ecx, (%rdi)
25669 movl %r8d, -4(%rdi, %rdx)
25670+ pax_force_retaddr
25671 retq
25672 .p2align 4
25673 .Lless_3bytes:
25674@@ -179,6 +184,7 @@ ENTRY(memcpy)
25675 movb %cl, (%rdi)
25676
25677 .Lend:
25678+ pax_force_retaddr
25679 retq
25680 CFI_ENDPROC
25681 ENDPROC(memcpy)
25682diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25683index 65268a6..c9518d1 100644
25684--- a/arch/x86/lib/memmove_64.S
25685+++ b/arch/x86/lib/memmove_64.S
25686@@ -61,13 +61,13 @@ ENTRY(memmove)
25687 5:
25688 sub $0x20, %rdx
25689 movq 0*8(%rsi), %r11
25690- movq 1*8(%rsi), %r10
25691+ movq 1*8(%rsi), %rcx
25692 movq 2*8(%rsi), %r9
25693 movq 3*8(%rsi), %r8
25694 leaq 4*8(%rsi), %rsi
25695
25696 movq %r11, 0*8(%rdi)
25697- movq %r10, 1*8(%rdi)
25698+ movq %rcx, 1*8(%rdi)
25699 movq %r9, 2*8(%rdi)
25700 movq %r8, 3*8(%rdi)
25701 leaq 4*8(%rdi), %rdi
25702@@ -81,10 +81,10 @@ ENTRY(memmove)
25703 4:
25704 movq %rdx, %rcx
25705 movq -8(%rsi, %rdx), %r11
25706- lea -8(%rdi, %rdx), %r10
25707+ lea -8(%rdi, %rdx), %r9
25708 shrq $3, %rcx
25709 rep movsq
25710- movq %r11, (%r10)
25711+ movq %r11, (%r9)
25712 jmp 13f
25713 .Lmemmove_end_forward:
25714
25715@@ -95,14 +95,14 @@ ENTRY(memmove)
25716 7:
25717 movq %rdx, %rcx
25718 movq (%rsi), %r11
25719- movq %rdi, %r10
25720+ movq %rdi, %r9
25721 leaq -8(%rsi, %rdx), %rsi
25722 leaq -8(%rdi, %rdx), %rdi
25723 shrq $3, %rcx
25724 std
25725 rep movsq
25726 cld
25727- movq %r11, (%r10)
25728+ movq %r11, (%r9)
25729 jmp 13f
25730
25731 /*
25732@@ -127,13 +127,13 @@ ENTRY(memmove)
25733 8:
25734 subq $0x20, %rdx
25735 movq -1*8(%rsi), %r11
25736- movq -2*8(%rsi), %r10
25737+ movq -2*8(%rsi), %rcx
25738 movq -3*8(%rsi), %r9
25739 movq -4*8(%rsi), %r8
25740 leaq -4*8(%rsi), %rsi
25741
25742 movq %r11, -1*8(%rdi)
25743- movq %r10, -2*8(%rdi)
25744+ movq %rcx, -2*8(%rdi)
25745 movq %r9, -3*8(%rdi)
25746 movq %r8, -4*8(%rdi)
25747 leaq -4*8(%rdi), %rdi
25748@@ -151,11 +151,11 @@ ENTRY(memmove)
25749 * Move data from 16 bytes to 31 bytes.
25750 */
25751 movq 0*8(%rsi), %r11
25752- movq 1*8(%rsi), %r10
25753+ movq 1*8(%rsi), %rcx
25754 movq -2*8(%rsi, %rdx), %r9
25755 movq -1*8(%rsi, %rdx), %r8
25756 movq %r11, 0*8(%rdi)
25757- movq %r10, 1*8(%rdi)
25758+ movq %rcx, 1*8(%rdi)
25759 movq %r9, -2*8(%rdi, %rdx)
25760 movq %r8, -1*8(%rdi, %rdx)
25761 jmp 13f
25762@@ -167,9 +167,9 @@ ENTRY(memmove)
25763 * Move data from 8 bytes to 15 bytes.
25764 */
25765 movq 0*8(%rsi), %r11
25766- movq -1*8(%rsi, %rdx), %r10
25767+ movq -1*8(%rsi, %rdx), %r9
25768 movq %r11, 0*8(%rdi)
25769- movq %r10, -1*8(%rdi, %rdx)
25770+ movq %r9, -1*8(%rdi, %rdx)
25771 jmp 13f
25772 10:
25773 cmpq $4, %rdx
25774@@ -178,9 +178,9 @@ ENTRY(memmove)
25775 * Move data from 4 bytes to 7 bytes.
25776 */
25777 movl (%rsi), %r11d
25778- movl -4(%rsi, %rdx), %r10d
25779+ movl -4(%rsi, %rdx), %r9d
25780 movl %r11d, (%rdi)
25781- movl %r10d, -4(%rdi, %rdx)
25782+ movl %r9d, -4(%rdi, %rdx)
25783 jmp 13f
25784 11:
25785 cmp $2, %rdx
25786@@ -189,9 +189,9 @@ ENTRY(memmove)
25787 * Move data from 2 bytes to 3 bytes.
25788 */
25789 movw (%rsi), %r11w
25790- movw -2(%rsi, %rdx), %r10w
25791+ movw -2(%rsi, %rdx), %r9w
25792 movw %r11w, (%rdi)
25793- movw %r10w, -2(%rdi, %rdx)
25794+ movw %r9w, -2(%rdi, %rdx)
25795 jmp 13f
25796 12:
25797 cmp $1, %rdx
25798@@ -202,6 +202,7 @@ ENTRY(memmove)
25799 movb (%rsi), %r11b
25800 movb %r11b, (%rdi)
25801 13:
25802+ pax_force_retaddr
25803 retq
25804 CFI_ENDPROC
25805
25806@@ -210,6 +211,7 @@ ENTRY(memmove)
25807 /* Forward moving data. */
25808 movq %rdx, %rcx
25809 rep movsb
25810+ pax_force_retaddr
25811 retq
25812 .Lmemmove_end_forward_efs:
25813 .previous
25814diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25815index 2dcb380..963660a 100644
25816--- a/arch/x86/lib/memset_64.S
25817+++ b/arch/x86/lib/memset_64.S
25818@@ -30,6 +30,7 @@
25819 movl %edx,%ecx
25820 rep stosb
25821 movq %r9,%rax
25822+ pax_force_retaddr
25823 ret
25824 .Lmemset_e:
25825 .previous
25826@@ -52,6 +53,7 @@
25827 movq %rdx,%rcx
25828 rep stosb
25829 movq %r9,%rax
25830+ pax_force_retaddr
25831 ret
25832 .Lmemset_e_e:
25833 .previous
25834@@ -59,7 +61,7 @@
25835 ENTRY(memset)
25836 ENTRY(__memset)
25837 CFI_STARTPROC
25838- movq %rdi,%r10
25839+ movq %rdi,%r11
25840
25841 /* expand byte value */
25842 movzbl %sil,%ecx
25843@@ -117,7 +119,8 @@ ENTRY(__memset)
25844 jnz .Lloop_1
25845
25846 .Lende:
25847- movq %r10,%rax
25848+ movq %r11,%rax
25849+ pax_force_retaddr
25850 ret
25851
25852 CFI_RESTORE_STATE
25853diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25854index c9f2d9b..e7fd2c0 100644
25855--- a/arch/x86/lib/mmx_32.c
25856+++ b/arch/x86/lib/mmx_32.c
25857@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25858 {
25859 void *p;
25860 int i;
25861+ unsigned long cr0;
25862
25863 if (unlikely(in_interrupt()))
25864 return __memcpy(to, from, len);
25865@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25866 kernel_fpu_begin();
25867
25868 __asm__ __volatile__ (
25869- "1: prefetch (%0)\n" /* This set is 28 bytes */
25870- " prefetch 64(%0)\n"
25871- " prefetch 128(%0)\n"
25872- " prefetch 192(%0)\n"
25873- " prefetch 256(%0)\n"
25874+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25875+ " prefetch 64(%1)\n"
25876+ " prefetch 128(%1)\n"
25877+ " prefetch 192(%1)\n"
25878+ " prefetch 256(%1)\n"
25879 "2: \n"
25880 ".section .fixup, \"ax\"\n"
25881- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25882+ "3: \n"
25883+
25884+#ifdef CONFIG_PAX_KERNEXEC
25885+ " movl %%cr0, %0\n"
25886+ " movl %0, %%eax\n"
25887+ " andl $0xFFFEFFFF, %%eax\n"
25888+ " movl %%eax, %%cr0\n"
25889+#endif
25890+
25891+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25892+
25893+#ifdef CONFIG_PAX_KERNEXEC
25894+ " movl %0, %%cr0\n"
25895+#endif
25896+
25897 " jmp 2b\n"
25898 ".previous\n"
25899 _ASM_EXTABLE(1b, 3b)
25900- : : "r" (from));
25901+ : "=&r" (cr0) : "r" (from) : "ax");
25902
25903 for ( ; i > 5; i--) {
25904 __asm__ __volatile__ (
25905- "1: prefetch 320(%0)\n"
25906- "2: movq (%0), %%mm0\n"
25907- " movq 8(%0), %%mm1\n"
25908- " movq 16(%0), %%mm2\n"
25909- " movq 24(%0), %%mm3\n"
25910- " movq %%mm0, (%1)\n"
25911- " movq %%mm1, 8(%1)\n"
25912- " movq %%mm2, 16(%1)\n"
25913- " movq %%mm3, 24(%1)\n"
25914- " movq 32(%0), %%mm0\n"
25915- " movq 40(%0), %%mm1\n"
25916- " movq 48(%0), %%mm2\n"
25917- " movq 56(%0), %%mm3\n"
25918- " movq %%mm0, 32(%1)\n"
25919- " movq %%mm1, 40(%1)\n"
25920- " movq %%mm2, 48(%1)\n"
25921- " movq %%mm3, 56(%1)\n"
25922+ "1: prefetch 320(%1)\n"
25923+ "2: movq (%1), %%mm0\n"
25924+ " movq 8(%1), %%mm1\n"
25925+ " movq 16(%1), %%mm2\n"
25926+ " movq 24(%1), %%mm3\n"
25927+ " movq %%mm0, (%2)\n"
25928+ " movq %%mm1, 8(%2)\n"
25929+ " movq %%mm2, 16(%2)\n"
25930+ " movq %%mm3, 24(%2)\n"
25931+ " movq 32(%1), %%mm0\n"
25932+ " movq 40(%1), %%mm1\n"
25933+ " movq 48(%1), %%mm2\n"
25934+ " movq 56(%1), %%mm3\n"
25935+ " movq %%mm0, 32(%2)\n"
25936+ " movq %%mm1, 40(%2)\n"
25937+ " movq %%mm2, 48(%2)\n"
25938+ " movq %%mm3, 56(%2)\n"
25939 ".section .fixup, \"ax\"\n"
25940- "3: movw $0x05EB, 1b\n" /* jmp on 5 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 $0x05EB, 1b\n" /* jmp on 5 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), "r" (to) : "memory");
25960+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25961
25962 from += 64;
25963 to += 64;
25964@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25965 static void fast_copy_page(void *to, void *from)
25966 {
25967 int i;
25968+ unsigned long cr0;
25969
25970 kernel_fpu_begin();
25971
25972@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25973 * but that is for later. -AV
25974 */
25975 __asm__ __volatile__(
25976- "1: prefetch (%0)\n"
25977- " prefetch 64(%0)\n"
25978- " prefetch 128(%0)\n"
25979- " prefetch 192(%0)\n"
25980- " prefetch 256(%0)\n"
25981+ "1: prefetch (%1)\n"
25982+ " prefetch 64(%1)\n"
25983+ " prefetch 128(%1)\n"
25984+ " prefetch 192(%1)\n"
25985+ " prefetch 256(%1)\n"
25986 "2: \n"
25987 ".section .fixup, \"ax\"\n"
25988- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25989+ "3: \n"
25990+
25991+#ifdef CONFIG_PAX_KERNEXEC
25992+ " movl %%cr0, %0\n"
25993+ " movl %0, %%eax\n"
25994+ " andl $0xFFFEFFFF, %%eax\n"
25995+ " movl %%eax, %%cr0\n"
25996+#endif
25997+
25998+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25999+
26000+#ifdef CONFIG_PAX_KERNEXEC
26001+ " movl %0, %%cr0\n"
26002+#endif
26003+
26004 " jmp 2b\n"
26005 ".previous\n"
26006- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26007+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26008
26009 for (i = 0; i < (4096-320)/64; i++) {
26010 __asm__ __volatile__ (
26011- "1: prefetch 320(%0)\n"
26012- "2: movq (%0), %%mm0\n"
26013- " movntq %%mm0, (%1)\n"
26014- " movq 8(%0), %%mm1\n"
26015- " movntq %%mm1, 8(%1)\n"
26016- " movq 16(%0), %%mm2\n"
26017- " movntq %%mm2, 16(%1)\n"
26018- " movq 24(%0), %%mm3\n"
26019- " movntq %%mm3, 24(%1)\n"
26020- " movq 32(%0), %%mm4\n"
26021- " movntq %%mm4, 32(%1)\n"
26022- " movq 40(%0), %%mm5\n"
26023- " movntq %%mm5, 40(%1)\n"
26024- " movq 48(%0), %%mm6\n"
26025- " movntq %%mm6, 48(%1)\n"
26026- " movq 56(%0), %%mm7\n"
26027- " movntq %%mm7, 56(%1)\n"
26028+ "1: prefetch 320(%1)\n"
26029+ "2: movq (%1), %%mm0\n"
26030+ " movntq %%mm0, (%2)\n"
26031+ " movq 8(%1), %%mm1\n"
26032+ " movntq %%mm1, 8(%2)\n"
26033+ " movq 16(%1), %%mm2\n"
26034+ " movntq %%mm2, 16(%2)\n"
26035+ " movq 24(%1), %%mm3\n"
26036+ " movntq %%mm3, 24(%2)\n"
26037+ " movq 32(%1), %%mm4\n"
26038+ " movntq %%mm4, 32(%2)\n"
26039+ " movq 40(%1), %%mm5\n"
26040+ " movntq %%mm5, 40(%2)\n"
26041+ " movq 48(%1), %%mm6\n"
26042+ " movntq %%mm6, 48(%2)\n"
26043+ " movq 56(%1), %%mm7\n"
26044+ " movntq %%mm7, 56(%2)\n"
26045 ".section .fixup, \"ax\"\n"
26046- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26047+ "3:\n"
26048+
26049+#ifdef CONFIG_PAX_KERNEXEC
26050+ " movl %%cr0, %0\n"
26051+ " movl %0, %%eax\n"
26052+ " andl $0xFFFEFFFF, %%eax\n"
26053+ " movl %%eax, %%cr0\n"
26054+#endif
26055+
26056+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26057+
26058+#ifdef CONFIG_PAX_KERNEXEC
26059+ " movl %0, %%cr0\n"
26060+#endif
26061+
26062 " jmp 2b\n"
26063 ".previous\n"
26064- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
26065+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26066
26067 from += 64;
26068 to += 64;
26069@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
26070 static void fast_copy_page(void *to, void *from)
26071 {
26072 int i;
26073+ unsigned long cr0;
26074
26075 kernel_fpu_begin();
26076
26077 __asm__ __volatile__ (
26078- "1: prefetch (%0)\n"
26079- " prefetch 64(%0)\n"
26080- " prefetch 128(%0)\n"
26081- " prefetch 192(%0)\n"
26082- " prefetch 256(%0)\n"
26083+ "1: prefetch (%1)\n"
26084+ " prefetch 64(%1)\n"
26085+ " prefetch 128(%1)\n"
26086+ " prefetch 192(%1)\n"
26087+ " prefetch 256(%1)\n"
26088 "2: \n"
26089 ".section .fixup, \"ax\"\n"
26090- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26091+ "3: \n"
26092+
26093+#ifdef CONFIG_PAX_KERNEXEC
26094+ " movl %%cr0, %0\n"
26095+ " movl %0, %%eax\n"
26096+ " andl $0xFFFEFFFF, %%eax\n"
26097+ " movl %%eax, %%cr0\n"
26098+#endif
26099+
26100+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26101+
26102+#ifdef CONFIG_PAX_KERNEXEC
26103+ " movl %0, %%cr0\n"
26104+#endif
26105+
26106 " jmp 2b\n"
26107 ".previous\n"
26108- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26109+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26110
26111 for (i = 0; i < 4096/64; i++) {
26112 __asm__ __volatile__ (
26113- "1: prefetch 320(%0)\n"
26114- "2: movq (%0), %%mm0\n"
26115- " movq 8(%0), %%mm1\n"
26116- " movq 16(%0), %%mm2\n"
26117- " movq 24(%0), %%mm3\n"
26118- " movq %%mm0, (%1)\n"
26119- " movq %%mm1, 8(%1)\n"
26120- " movq %%mm2, 16(%1)\n"
26121- " movq %%mm3, 24(%1)\n"
26122- " movq 32(%0), %%mm0\n"
26123- " movq 40(%0), %%mm1\n"
26124- " movq 48(%0), %%mm2\n"
26125- " movq 56(%0), %%mm3\n"
26126- " movq %%mm0, 32(%1)\n"
26127- " movq %%mm1, 40(%1)\n"
26128- " movq %%mm2, 48(%1)\n"
26129- " movq %%mm3, 56(%1)\n"
26130+ "1: prefetch 320(%1)\n"
26131+ "2: movq (%1), %%mm0\n"
26132+ " movq 8(%1), %%mm1\n"
26133+ " movq 16(%1), %%mm2\n"
26134+ " movq 24(%1), %%mm3\n"
26135+ " movq %%mm0, (%2)\n"
26136+ " movq %%mm1, 8(%2)\n"
26137+ " movq %%mm2, 16(%2)\n"
26138+ " movq %%mm3, 24(%2)\n"
26139+ " movq 32(%1), %%mm0\n"
26140+ " movq 40(%1), %%mm1\n"
26141+ " movq 48(%1), %%mm2\n"
26142+ " movq 56(%1), %%mm3\n"
26143+ " movq %%mm0, 32(%2)\n"
26144+ " movq %%mm1, 40(%2)\n"
26145+ " movq %%mm2, 48(%2)\n"
26146+ " movq %%mm3, 56(%2)\n"
26147 ".section .fixup, \"ax\"\n"
26148- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26149+ "3:\n"
26150+
26151+#ifdef CONFIG_PAX_KERNEXEC
26152+ " movl %%cr0, %0\n"
26153+ " movl %0, %%eax\n"
26154+ " andl $0xFFFEFFFF, %%eax\n"
26155+ " movl %%eax, %%cr0\n"
26156+#endif
26157+
26158+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26159+
26160+#ifdef CONFIG_PAX_KERNEXEC
26161+ " movl %0, %%cr0\n"
26162+#endif
26163+
26164 " jmp 2b\n"
26165 ".previous\n"
26166 _ASM_EXTABLE(1b, 3b)
26167- : : "r" (from), "r" (to) : "memory");
26168+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26169
26170 from += 64;
26171 to += 64;
26172diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26173index f6d13ee..aca5f0b 100644
26174--- a/arch/x86/lib/msr-reg.S
26175+++ b/arch/x86/lib/msr-reg.S
26176@@ -3,6 +3,7 @@
26177 #include <asm/dwarf2.h>
26178 #include <asm/asm.h>
26179 #include <asm/msr.h>
26180+#include <asm/alternative-asm.h>
26181
26182 #ifdef CONFIG_X86_64
26183 /*
26184@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26185 CFI_STARTPROC
26186 pushq_cfi %rbx
26187 pushq_cfi %rbp
26188- movq %rdi, %r10 /* Save pointer */
26189+ movq %rdi, %r9 /* Save pointer */
26190 xorl %r11d, %r11d /* Return value */
26191 movl (%rdi), %eax
26192 movl 4(%rdi), %ecx
26193@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26194 movl 28(%rdi), %edi
26195 CFI_REMEMBER_STATE
26196 1: \op
26197-2: movl %eax, (%r10)
26198+2: movl %eax, (%r9)
26199 movl %r11d, %eax /* Return value */
26200- movl %ecx, 4(%r10)
26201- movl %edx, 8(%r10)
26202- movl %ebx, 12(%r10)
26203- movl %ebp, 20(%r10)
26204- movl %esi, 24(%r10)
26205- movl %edi, 28(%r10)
26206+ movl %ecx, 4(%r9)
26207+ movl %edx, 8(%r9)
26208+ movl %ebx, 12(%r9)
26209+ movl %ebp, 20(%r9)
26210+ movl %esi, 24(%r9)
26211+ movl %edi, 28(%r9)
26212 popq_cfi %rbp
26213 popq_cfi %rbx
26214+ pax_force_retaddr
26215 ret
26216 3:
26217 CFI_RESTORE_STATE
26218diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26219index fc6ba17..d4d989d 100644
26220--- a/arch/x86/lib/putuser.S
26221+++ b/arch/x86/lib/putuser.S
26222@@ -16,7 +16,9 @@
26223 #include <asm/errno.h>
26224 #include <asm/asm.h>
26225 #include <asm/smap.h>
26226-
26227+#include <asm/segment.h>
26228+#include <asm/pgtable.h>
26229+#include <asm/alternative-asm.h>
26230
26231 /*
26232 * __put_user_X
26233@@ -30,57 +32,125 @@
26234 * as they get called from within inline assembly.
26235 */
26236
26237-#define ENTER CFI_STARTPROC ; \
26238- GET_THREAD_INFO(%_ASM_BX)
26239-#define EXIT ASM_CLAC ; \
26240- ret ; \
26241+#define ENTER CFI_STARTPROC
26242+#define EXIT ASM_CLAC ; \
26243+ pax_force_retaddr ; \
26244+ ret ; \
26245 CFI_ENDPROC
26246
26247+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26248+#define _DEST %_ASM_CX,%_ASM_BX
26249+#else
26250+#define _DEST %_ASM_CX
26251+#endif
26252+
26253+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26254+#define __copyuser_seg gs;
26255+#else
26256+#define __copyuser_seg
26257+#endif
26258+
26259 .text
26260 ENTRY(__put_user_1)
26261 ENTER
26262+
26263+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26264+ GET_THREAD_INFO(%_ASM_BX)
26265 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26266 jae bad_put_user
26267 ASM_STAC
26268-1: movb %al,(%_ASM_CX)
26269+
26270+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26271+ mov pax_user_shadow_base,%_ASM_BX
26272+ cmp %_ASM_BX,%_ASM_CX
26273+ jb 1234f
26274+ xor %ebx,%ebx
26275+1234:
26276+#endif
26277+
26278+#endif
26279+
26280+1: __copyuser_seg movb %al,(_DEST)
26281 xor %eax,%eax
26282 EXIT
26283 ENDPROC(__put_user_1)
26284
26285 ENTRY(__put_user_2)
26286 ENTER
26287+
26288+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26289+ GET_THREAD_INFO(%_ASM_BX)
26290 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26291 sub $1,%_ASM_BX
26292 cmp %_ASM_BX,%_ASM_CX
26293 jae bad_put_user
26294 ASM_STAC
26295-2: movw %ax,(%_ASM_CX)
26296+
26297+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26298+ mov pax_user_shadow_base,%_ASM_BX
26299+ cmp %_ASM_BX,%_ASM_CX
26300+ jb 1234f
26301+ xor %ebx,%ebx
26302+1234:
26303+#endif
26304+
26305+#endif
26306+
26307+2: __copyuser_seg movw %ax,(_DEST)
26308 xor %eax,%eax
26309 EXIT
26310 ENDPROC(__put_user_2)
26311
26312 ENTRY(__put_user_4)
26313 ENTER
26314+
26315+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26316+ GET_THREAD_INFO(%_ASM_BX)
26317 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26318 sub $3,%_ASM_BX
26319 cmp %_ASM_BX,%_ASM_CX
26320 jae bad_put_user
26321 ASM_STAC
26322-3: movl %eax,(%_ASM_CX)
26323+
26324+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26325+ mov pax_user_shadow_base,%_ASM_BX
26326+ cmp %_ASM_BX,%_ASM_CX
26327+ jb 1234f
26328+ xor %ebx,%ebx
26329+1234:
26330+#endif
26331+
26332+#endif
26333+
26334+3: __copyuser_seg movl %eax,(_DEST)
26335 xor %eax,%eax
26336 EXIT
26337 ENDPROC(__put_user_4)
26338
26339 ENTRY(__put_user_8)
26340 ENTER
26341+
26342+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26343+ GET_THREAD_INFO(%_ASM_BX)
26344 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26345 sub $7,%_ASM_BX
26346 cmp %_ASM_BX,%_ASM_CX
26347 jae bad_put_user
26348 ASM_STAC
26349-4: mov %_ASM_AX,(%_ASM_CX)
26350+
26351+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26352+ mov pax_user_shadow_base,%_ASM_BX
26353+ cmp %_ASM_BX,%_ASM_CX
26354+ jb 1234f
26355+ xor %ebx,%ebx
26356+1234:
26357+#endif
26358+
26359+#endif
26360+
26361+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26362 #ifdef CONFIG_X86_32
26363-5: movl %edx,4(%_ASM_CX)
26364+5: __copyuser_seg movl %edx,4(_DEST)
26365 #endif
26366 xor %eax,%eax
26367 EXIT
26368diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26369index 1cad221..de671ee 100644
26370--- a/arch/x86/lib/rwlock.S
26371+++ b/arch/x86/lib/rwlock.S
26372@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26373 FRAME
26374 0: LOCK_PREFIX
26375 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26376+
26377+#ifdef CONFIG_PAX_REFCOUNT
26378+ jno 1234f
26379+ LOCK_PREFIX
26380+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26381+ int $4
26382+1234:
26383+ _ASM_EXTABLE(1234b, 1234b)
26384+#endif
26385+
26386 1: rep; nop
26387 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26388 jne 1b
26389 LOCK_PREFIX
26390 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26391+
26392+#ifdef CONFIG_PAX_REFCOUNT
26393+ jno 1234f
26394+ LOCK_PREFIX
26395+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26396+ int $4
26397+1234:
26398+ _ASM_EXTABLE(1234b, 1234b)
26399+#endif
26400+
26401 jnz 0b
26402 ENDFRAME
26403+ pax_force_retaddr
26404 ret
26405 CFI_ENDPROC
26406 END(__write_lock_failed)
26407@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26408 FRAME
26409 0: LOCK_PREFIX
26410 READ_LOCK_SIZE(inc) (%__lock_ptr)
26411+
26412+#ifdef CONFIG_PAX_REFCOUNT
26413+ jno 1234f
26414+ LOCK_PREFIX
26415+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26416+ int $4
26417+1234:
26418+ _ASM_EXTABLE(1234b, 1234b)
26419+#endif
26420+
26421 1: rep; nop
26422 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26423 js 1b
26424 LOCK_PREFIX
26425 READ_LOCK_SIZE(dec) (%__lock_ptr)
26426+
26427+#ifdef CONFIG_PAX_REFCOUNT
26428+ jno 1234f
26429+ LOCK_PREFIX
26430+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26431+ int $4
26432+1234:
26433+ _ASM_EXTABLE(1234b, 1234b)
26434+#endif
26435+
26436 js 0b
26437 ENDFRAME
26438+ pax_force_retaddr
26439 ret
26440 CFI_ENDPROC
26441 END(__read_lock_failed)
26442diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26443index 5dff5f0..cadebf4 100644
26444--- a/arch/x86/lib/rwsem.S
26445+++ b/arch/x86/lib/rwsem.S
26446@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26447 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26448 CFI_RESTORE __ASM_REG(dx)
26449 restore_common_regs
26450+ pax_force_retaddr
26451 ret
26452 CFI_ENDPROC
26453 ENDPROC(call_rwsem_down_read_failed)
26454@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26455 movq %rax,%rdi
26456 call rwsem_down_write_failed
26457 restore_common_regs
26458+ pax_force_retaddr
26459 ret
26460 CFI_ENDPROC
26461 ENDPROC(call_rwsem_down_write_failed)
26462@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26463 movq %rax,%rdi
26464 call rwsem_wake
26465 restore_common_regs
26466-1: ret
26467+1: pax_force_retaddr
26468+ ret
26469 CFI_ENDPROC
26470 ENDPROC(call_rwsem_wake)
26471
26472@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26473 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26474 CFI_RESTORE __ASM_REG(dx)
26475 restore_common_regs
26476+ pax_force_retaddr
26477 ret
26478 CFI_ENDPROC
26479 ENDPROC(call_rwsem_downgrade_wake)
26480diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26481index a63efd6..ccecad8 100644
26482--- a/arch/x86/lib/thunk_64.S
26483+++ b/arch/x86/lib/thunk_64.S
26484@@ -8,6 +8,7 @@
26485 #include <linux/linkage.h>
26486 #include <asm/dwarf2.h>
26487 #include <asm/calling.h>
26488+#include <asm/alternative-asm.h>
26489
26490 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26491 .macro THUNK name, func, put_ret_addr_in_rdi=0
26492@@ -41,5 +42,6 @@
26493 SAVE_ARGS
26494 restore:
26495 RESTORE_ARGS
26496+ pax_force_retaddr
26497 ret
26498 CFI_ENDPROC
26499diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26500index 3eb18ac..6890bc3 100644
26501--- a/arch/x86/lib/usercopy_32.c
26502+++ b/arch/x86/lib/usercopy_32.c
26503@@ -42,11 +42,13 @@ do { \
26504 int __d0; \
26505 might_fault(); \
26506 __asm__ __volatile__( \
26507+ __COPYUSER_SET_ES \
26508 ASM_STAC "\n" \
26509 "0: rep; stosl\n" \
26510 " movl %2,%0\n" \
26511 "1: rep; stosb\n" \
26512 "2: " ASM_CLAC "\n" \
26513+ __COPYUSER_RESTORE_ES \
26514 ".section .fixup,\"ax\"\n" \
26515 "3: lea 0(%2,%0,4),%0\n" \
26516 " jmp 2b\n" \
26517@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26518
26519 #ifdef CONFIG_X86_INTEL_USERCOPY
26520 static unsigned long
26521-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26522+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26523 {
26524 int d0, d1;
26525 __asm__ __volatile__(
26526@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26527 " .align 2,0x90\n"
26528 "3: movl 0(%4), %%eax\n"
26529 "4: movl 4(%4), %%edx\n"
26530- "5: movl %%eax, 0(%3)\n"
26531- "6: movl %%edx, 4(%3)\n"
26532+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26533+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26534 "7: movl 8(%4), %%eax\n"
26535 "8: movl 12(%4),%%edx\n"
26536- "9: movl %%eax, 8(%3)\n"
26537- "10: movl %%edx, 12(%3)\n"
26538+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26539+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26540 "11: movl 16(%4), %%eax\n"
26541 "12: movl 20(%4), %%edx\n"
26542- "13: movl %%eax, 16(%3)\n"
26543- "14: movl %%edx, 20(%3)\n"
26544+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26545+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26546 "15: movl 24(%4), %%eax\n"
26547 "16: movl 28(%4), %%edx\n"
26548- "17: movl %%eax, 24(%3)\n"
26549- "18: movl %%edx, 28(%3)\n"
26550+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26551+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26552 "19: movl 32(%4), %%eax\n"
26553 "20: movl 36(%4), %%edx\n"
26554- "21: movl %%eax, 32(%3)\n"
26555- "22: movl %%edx, 36(%3)\n"
26556+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26557+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26558 "23: movl 40(%4), %%eax\n"
26559 "24: movl 44(%4), %%edx\n"
26560- "25: movl %%eax, 40(%3)\n"
26561- "26: movl %%edx, 44(%3)\n"
26562+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26563+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26564 "27: movl 48(%4), %%eax\n"
26565 "28: movl 52(%4), %%edx\n"
26566- "29: movl %%eax, 48(%3)\n"
26567- "30: movl %%edx, 52(%3)\n"
26568+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26569+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26570 "31: movl 56(%4), %%eax\n"
26571 "32: movl 60(%4), %%edx\n"
26572- "33: movl %%eax, 56(%3)\n"
26573- "34: movl %%edx, 60(%3)\n"
26574+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26575+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26576 " addl $-64, %0\n"
26577 " addl $64, %4\n"
26578 " addl $64, %3\n"
26579@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26580 " shrl $2, %0\n"
26581 " andl $3, %%eax\n"
26582 " cld\n"
26583+ __COPYUSER_SET_ES
26584 "99: rep; movsl\n"
26585 "36: movl %%eax, %0\n"
26586 "37: rep; movsb\n"
26587 "100:\n"
26588+ __COPYUSER_RESTORE_ES
26589 ".section .fixup,\"ax\"\n"
26590 "101: lea 0(%%eax,%0,4),%0\n"
26591 " jmp 100b\n"
26592@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26593 }
26594
26595 static unsigned long
26596+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26597+{
26598+ int d0, d1;
26599+ __asm__ __volatile__(
26600+ " .align 2,0x90\n"
26601+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26602+ " cmpl $67, %0\n"
26603+ " jbe 3f\n"
26604+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26605+ " .align 2,0x90\n"
26606+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26607+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26608+ "5: movl %%eax, 0(%3)\n"
26609+ "6: movl %%edx, 4(%3)\n"
26610+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26611+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26612+ "9: movl %%eax, 8(%3)\n"
26613+ "10: movl %%edx, 12(%3)\n"
26614+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26615+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26616+ "13: movl %%eax, 16(%3)\n"
26617+ "14: movl %%edx, 20(%3)\n"
26618+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26619+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26620+ "17: movl %%eax, 24(%3)\n"
26621+ "18: movl %%edx, 28(%3)\n"
26622+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26623+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26624+ "21: movl %%eax, 32(%3)\n"
26625+ "22: movl %%edx, 36(%3)\n"
26626+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26627+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26628+ "25: movl %%eax, 40(%3)\n"
26629+ "26: movl %%edx, 44(%3)\n"
26630+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26631+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26632+ "29: movl %%eax, 48(%3)\n"
26633+ "30: movl %%edx, 52(%3)\n"
26634+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26635+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26636+ "33: movl %%eax, 56(%3)\n"
26637+ "34: movl %%edx, 60(%3)\n"
26638+ " addl $-64, %0\n"
26639+ " addl $64, %4\n"
26640+ " addl $64, %3\n"
26641+ " cmpl $63, %0\n"
26642+ " ja 1b\n"
26643+ "35: movl %0, %%eax\n"
26644+ " shrl $2, %0\n"
26645+ " andl $3, %%eax\n"
26646+ " cld\n"
26647+ "99: rep; "__copyuser_seg" movsl\n"
26648+ "36: movl %%eax, %0\n"
26649+ "37: rep; "__copyuser_seg" movsb\n"
26650+ "100:\n"
26651+ ".section .fixup,\"ax\"\n"
26652+ "101: lea 0(%%eax,%0,4),%0\n"
26653+ " jmp 100b\n"
26654+ ".previous\n"
26655+ _ASM_EXTABLE(1b,100b)
26656+ _ASM_EXTABLE(2b,100b)
26657+ _ASM_EXTABLE(3b,100b)
26658+ _ASM_EXTABLE(4b,100b)
26659+ _ASM_EXTABLE(5b,100b)
26660+ _ASM_EXTABLE(6b,100b)
26661+ _ASM_EXTABLE(7b,100b)
26662+ _ASM_EXTABLE(8b,100b)
26663+ _ASM_EXTABLE(9b,100b)
26664+ _ASM_EXTABLE(10b,100b)
26665+ _ASM_EXTABLE(11b,100b)
26666+ _ASM_EXTABLE(12b,100b)
26667+ _ASM_EXTABLE(13b,100b)
26668+ _ASM_EXTABLE(14b,100b)
26669+ _ASM_EXTABLE(15b,100b)
26670+ _ASM_EXTABLE(16b,100b)
26671+ _ASM_EXTABLE(17b,100b)
26672+ _ASM_EXTABLE(18b,100b)
26673+ _ASM_EXTABLE(19b,100b)
26674+ _ASM_EXTABLE(20b,100b)
26675+ _ASM_EXTABLE(21b,100b)
26676+ _ASM_EXTABLE(22b,100b)
26677+ _ASM_EXTABLE(23b,100b)
26678+ _ASM_EXTABLE(24b,100b)
26679+ _ASM_EXTABLE(25b,100b)
26680+ _ASM_EXTABLE(26b,100b)
26681+ _ASM_EXTABLE(27b,100b)
26682+ _ASM_EXTABLE(28b,100b)
26683+ _ASM_EXTABLE(29b,100b)
26684+ _ASM_EXTABLE(30b,100b)
26685+ _ASM_EXTABLE(31b,100b)
26686+ _ASM_EXTABLE(32b,100b)
26687+ _ASM_EXTABLE(33b,100b)
26688+ _ASM_EXTABLE(34b,100b)
26689+ _ASM_EXTABLE(35b,100b)
26690+ _ASM_EXTABLE(36b,100b)
26691+ _ASM_EXTABLE(37b,100b)
26692+ _ASM_EXTABLE(99b,101b)
26693+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26694+ : "1"(to), "2"(from), "0"(size)
26695+ : "eax", "edx", "memory");
26696+ return size;
26697+}
26698+
26699+static unsigned long __size_overflow(3)
26700 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26701 {
26702 int d0, d1;
26703 __asm__ __volatile__(
26704 " .align 2,0x90\n"
26705- "0: movl 32(%4), %%eax\n"
26706+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26707 " cmpl $67, %0\n"
26708 " jbe 2f\n"
26709- "1: movl 64(%4), %%eax\n"
26710+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26711 " .align 2,0x90\n"
26712- "2: movl 0(%4), %%eax\n"
26713- "21: movl 4(%4), %%edx\n"
26714+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26715+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26716 " movl %%eax, 0(%3)\n"
26717 " movl %%edx, 4(%3)\n"
26718- "3: movl 8(%4), %%eax\n"
26719- "31: movl 12(%4),%%edx\n"
26720+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26721+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26722 " movl %%eax, 8(%3)\n"
26723 " movl %%edx, 12(%3)\n"
26724- "4: movl 16(%4), %%eax\n"
26725- "41: movl 20(%4), %%edx\n"
26726+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26727+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26728 " movl %%eax, 16(%3)\n"
26729 " movl %%edx, 20(%3)\n"
26730- "10: movl 24(%4), %%eax\n"
26731- "51: movl 28(%4), %%edx\n"
26732+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26733+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26734 " movl %%eax, 24(%3)\n"
26735 " movl %%edx, 28(%3)\n"
26736- "11: movl 32(%4), %%eax\n"
26737- "61: movl 36(%4), %%edx\n"
26738+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26739+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26740 " movl %%eax, 32(%3)\n"
26741 " movl %%edx, 36(%3)\n"
26742- "12: movl 40(%4), %%eax\n"
26743- "71: movl 44(%4), %%edx\n"
26744+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26745+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26746 " movl %%eax, 40(%3)\n"
26747 " movl %%edx, 44(%3)\n"
26748- "13: movl 48(%4), %%eax\n"
26749- "81: movl 52(%4), %%edx\n"
26750+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26751+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26752 " movl %%eax, 48(%3)\n"
26753 " movl %%edx, 52(%3)\n"
26754- "14: movl 56(%4), %%eax\n"
26755- "91: movl 60(%4), %%edx\n"
26756+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26757+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26758 " movl %%eax, 56(%3)\n"
26759 " movl %%edx, 60(%3)\n"
26760 " addl $-64, %0\n"
26761@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26762 " shrl $2, %0\n"
26763 " andl $3, %%eax\n"
26764 " cld\n"
26765- "6: rep; movsl\n"
26766+ "6: rep; "__copyuser_seg" movsl\n"
26767 " movl %%eax,%0\n"
26768- "7: rep; movsb\n"
26769+ "7: rep; "__copyuser_seg" movsb\n"
26770 "8:\n"
26771 ".section .fixup,\"ax\"\n"
26772 "9: lea 0(%%eax,%0,4),%0\n"
26773@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26774 * hyoshiok@miraclelinux.com
26775 */
26776
26777-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26778+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26779 const void __user *from, unsigned long size)
26780 {
26781 int d0, d1;
26782
26783 __asm__ __volatile__(
26784 " .align 2,0x90\n"
26785- "0: movl 32(%4), %%eax\n"
26786+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26787 " cmpl $67, %0\n"
26788 " jbe 2f\n"
26789- "1: movl 64(%4), %%eax\n"
26790+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26791 " .align 2,0x90\n"
26792- "2: movl 0(%4), %%eax\n"
26793- "21: movl 4(%4), %%edx\n"
26794+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26795+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26796 " movnti %%eax, 0(%3)\n"
26797 " movnti %%edx, 4(%3)\n"
26798- "3: movl 8(%4), %%eax\n"
26799- "31: movl 12(%4),%%edx\n"
26800+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26801+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26802 " movnti %%eax, 8(%3)\n"
26803 " movnti %%edx, 12(%3)\n"
26804- "4: movl 16(%4), %%eax\n"
26805- "41: movl 20(%4), %%edx\n"
26806+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26807+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26808 " movnti %%eax, 16(%3)\n"
26809 " movnti %%edx, 20(%3)\n"
26810- "10: movl 24(%4), %%eax\n"
26811- "51: movl 28(%4), %%edx\n"
26812+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26813+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26814 " movnti %%eax, 24(%3)\n"
26815 " movnti %%edx, 28(%3)\n"
26816- "11: movl 32(%4), %%eax\n"
26817- "61: movl 36(%4), %%edx\n"
26818+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26819+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26820 " movnti %%eax, 32(%3)\n"
26821 " movnti %%edx, 36(%3)\n"
26822- "12: movl 40(%4), %%eax\n"
26823- "71: movl 44(%4), %%edx\n"
26824+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26825+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26826 " movnti %%eax, 40(%3)\n"
26827 " movnti %%edx, 44(%3)\n"
26828- "13: movl 48(%4), %%eax\n"
26829- "81: movl 52(%4), %%edx\n"
26830+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26831+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26832 " movnti %%eax, 48(%3)\n"
26833 " movnti %%edx, 52(%3)\n"
26834- "14: movl 56(%4), %%eax\n"
26835- "91: movl 60(%4), %%edx\n"
26836+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26837+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26838 " movnti %%eax, 56(%3)\n"
26839 " movnti %%edx, 60(%3)\n"
26840 " addl $-64, %0\n"
26841@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26842 " shrl $2, %0\n"
26843 " andl $3, %%eax\n"
26844 " cld\n"
26845- "6: rep; movsl\n"
26846+ "6: rep; "__copyuser_seg" movsl\n"
26847 " movl %%eax,%0\n"
26848- "7: rep; movsb\n"
26849+ "7: rep; "__copyuser_seg" movsb\n"
26850 "8:\n"
26851 ".section .fixup,\"ax\"\n"
26852 "9: lea 0(%%eax,%0,4),%0\n"
26853@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26854 return size;
26855 }
26856
26857-static unsigned long __copy_user_intel_nocache(void *to,
26858+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26859 const void __user *from, unsigned long size)
26860 {
26861 int d0, d1;
26862
26863 __asm__ __volatile__(
26864 " .align 2,0x90\n"
26865- "0: movl 32(%4), %%eax\n"
26866+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26867 " cmpl $67, %0\n"
26868 " jbe 2f\n"
26869- "1: movl 64(%4), %%eax\n"
26870+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26871 " .align 2,0x90\n"
26872- "2: movl 0(%4), %%eax\n"
26873- "21: movl 4(%4), %%edx\n"
26874+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26875+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26876 " movnti %%eax, 0(%3)\n"
26877 " movnti %%edx, 4(%3)\n"
26878- "3: movl 8(%4), %%eax\n"
26879- "31: movl 12(%4),%%edx\n"
26880+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26881+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26882 " movnti %%eax, 8(%3)\n"
26883 " movnti %%edx, 12(%3)\n"
26884- "4: movl 16(%4), %%eax\n"
26885- "41: movl 20(%4), %%edx\n"
26886+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26887+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26888 " movnti %%eax, 16(%3)\n"
26889 " movnti %%edx, 20(%3)\n"
26890- "10: movl 24(%4), %%eax\n"
26891- "51: movl 28(%4), %%edx\n"
26892+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26893+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26894 " movnti %%eax, 24(%3)\n"
26895 " movnti %%edx, 28(%3)\n"
26896- "11: movl 32(%4), %%eax\n"
26897- "61: movl 36(%4), %%edx\n"
26898+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26899+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26900 " movnti %%eax, 32(%3)\n"
26901 " movnti %%edx, 36(%3)\n"
26902- "12: movl 40(%4), %%eax\n"
26903- "71: movl 44(%4), %%edx\n"
26904+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26905+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26906 " movnti %%eax, 40(%3)\n"
26907 " movnti %%edx, 44(%3)\n"
26908- "13: movl 48(%4), %%eax\n"
26909- "81: movl 52(%4), %%edx\n"
26910+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26911+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26912 " movnti %%eax, 48(%3)\n"
26913 " movnti %%edx, 52(%3)\n"
26914- "14: movl 56(%4), %%eax\n"
26915- "91: movl 60(%4), %%edx\n"
26916+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26917+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26918 " movnti %%eax, 56(%3)\n"
26919 " movnti %%edx, 60(%3)\n"
26920 " addl $-64, %0\n"
26921@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26922 " shrl $2, %0\n"
26923 " andl $3, %%eax\n"
26924 " cld\n"
26925- "6: rep; movsl\n"
26926+ "6: rep; "__copyuser_seg" movsl\n"
26927 " movl %%eax,%0\n"
26928- "7: rep; movsb\n"
26929+ "7: rep; "__copyuser_seg" movsb\n"
26930 "8:\n"
26931 ".section .fixup,\"ax\"\n"
26932 "9: lea 0(%%eax,%0,4),%0\n"
26933@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26934 */
26935 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26936 unsigned long size);
26937-unsigned long __copy_user_intel(void __user *to, const void *from,
26938+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26939+ unsigned long size);
26940+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26941 unsigned long size);
26942 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26943 const void __user *from, unsigned long size);
26944 #endif /* CONFIG_X86_INTEL_USERCOPY */
26945
26946 /* Generic arbitrary sized copy. */
26947-#define __copy_user(to, from, size) \
26948+#define __copy_user(to, from, size, prefix, set, restore) \
26949 do { \
26950 int __d0, __d1, __d2; \
26951 __asm__ __volatile__( \
26952+ set \
26953 " cmp $7,%0\n" \
26954 " jbe 1f\n" \
26955 " movl %1,%0\n" \
26956 " negl %0\n" \
26957 " andl $7,%0\n" \
26958 " subl %0,%3\n" \
26959- "4: rep; movsb\n" \
26960+ "4: rep; "prefix"movsb\n" \
26961 " movl %3,%0\n" \
26962 " shrl $2,%0\n" \
26963 " andl $3,%3\n" \
26964 " .align 2,0x90\n" \
26965- "0: rep; movsl\n" \
26966+ "0: rep; "prefix"movsl\n" \
26967 " movl %3,%0\n" \
26968- "1: rep; movsb\n" \
26969+ "1: rep; "prefix"movsb\n" \
26970 "2:\n" \
26971+ restore \
26972 ".section .fixup,\"ax\"\n" \
26973 "5: addl %3,%0\n" \
26974 " jmp 2b\n" \
26975@@ -538,14 +650,14 @@ do { \
26976 " negl %0\n" \
26977 " andl $7,%0\n" \
26978 " subl %0,%3\n" \
26979- "4: rep; movsb\n" \
26980+ "4: rep; "__copyuser_seg"movsb\n" \
26981 " movl %3,%0\n" \
26982 " shrl $2,%0\n" \
26983 " andl $3,%3\n" \
26984 " .align 2,0x90\n" \
26985- "0: rep; movsl\n" \
26986+ "0: rep; "__copyuser_seg"movsl\n" \
26987 " movl %3,%0\n" \
26988- "1: rep; movsb\n" \
26989+ "1: rep; "__copyuser_seg"movsb\n" \
26990 "2:\n" \
26991 ".section .fixup,\"ax\"\n" \
26992 "5: addl %3,%0\n" \
26993@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26994 {
26995 stac();
26996 if (movsl_is_ok(to, from, n))
26997- __copy_user(to, from, n);
26998+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26999 else
27000- n = __copy_user_intel(to, from, n);
27001+ n = __generic_copy_to_user_intel(to, from, n);
27002 clac();
27003 return n;
27004 }
27005@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
27006 {
27007 stac();
27008 if (movsl_is_ok(to, from, n))
27009- __copy_user(to, from, n);
27010+ __copy_user(to, from, n, __copyuser_seg, "", "");
27011 else
27012- n = __copy_user_intel((void __user *)to,
27013- (const void *)from, n);
27014+ n = __generic_copy_from_user_intel(to, from, n);
27015 clac();
27016 return n;
27017 }
27018@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
27019 if (n > 64 && cpu_has_xmm2)
27020 n = __copy_user_intel_nocache(to, from, n);
27021 else
27022- __copy_user(to, from, n);
27023+ __copy_user(to, from, n, __copyuser_seg, "", "");
27024 #else
27025- __copy_user(to, from, n);
27026+ __copy_user(to, from, n, __copyuser_seg, "", "");
27027 #endif
27028 clac();
27029 return n;
27030 }
27031 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
27032
27033-/**
27034- * copy_to_user: - Copy a block of data into user space.
27035- * @to: Destination address, in user space.
27036- * @from: Source address, in kernel space.
27037- * @n: Number of bytes to copy.
27038- *
27039- * Context: User context only. This function may sleep.
27040- *
27041- * Copy data from kernel space to user space.
27042- *
27043- * Returns number of bytes that could not be copied.
27044- * On success, this will be zero.
27045- */
27046-unsigned long
27047-copy_to_user(void __user *to, const void *from, unsigned long n)
27048+#ifdef CONFIG_PAX_MEMORY_UDEREF
27049+void __set_fs(mm_segment_t x)
27050 {
27051- if (access_ok(VERIFY_WRITE, to, n))
27052- n = __copy_to_user(to, from, n);
27053- return n;
27054+ switch (x.seg) {
27055+ case 0:
27056+ loadsegment(gs, 0);
27057+ break;
27058+ case TASK_SIZE_MAX:
27059+ loadsegment(gs, __USER_DS);
27060+ break;
27061+ case -1UL:
27062+ loadsegment(gs, __KERNEL_DS);
27063+ break;
27064+ default:
27065+ BUG();
27066+ }
27067 }
27068-EXPORT_SYMBOL(copy_to_user);
27069+EXPORT_SYMBOL(__set_fs);
27070
27071-/**
27072- * copy_from_user: - Copy a block of data from user space.
27073- * @to: Destination address, in kernel space.
27074- * @from: Source address, in user space.
27075- * @n: Number of bytes to copy.
27076- *
27077- * Context: User context only. This function may sleep.
27078- *
27079- * Copy data from user space to kernel space.
27080- *
27081- * Returns number of bytes that could not be copied.
27082- * On success, this will be zero.
27083- *
27084- * If some data could not be copied, this function will pad the copied
27085- * data to the requested size using zero bytes.
27086- */
27087-unsigned long
27088-_copy_from_user(void *to, const void __user *from, unsigned long n)
27089+void set_fs(mm_segment_t x)
27090 {
27091- if (access_ok(VERIFY_READ, from, n))
27092- n = __copy_from_user(to, from, n);
27093- else
27094- memset(to, 0, n);
27095- return n;
27096+ current_thread_info()->addr_limit = x;
27097+ __set_fs(x);
27098 }
27099-EXPORT_SYMBOL(_copy_from_user);
27100+EXPORT_SYMBOL(set_fs);
27101+#endif
27102diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27103index 906fea3..5646695 100644
27104--- a/arch/x86/lib/usercopy_64.c
27105+++ b/arch/x86/lib/usercopy_64.c
27106@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27107 _ASM_EXTABLE(0b,3b)
27108 _ASM_EXTABLE(1b,2b)
27109 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27110- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27111+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27112 [zero] "r" (0UL), [eight] "r" (8UL));
27113 clac();
27114 return size;
27115@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27116 }
27117 EXPORT_SYMBOL(clear_user);
27118
27119-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27120+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27121 {
27122- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27123- return copy_user_generic((__force void *)to, (__force void *)from, len);
27124- }
27125- return len;
27126+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27127+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27128+ return len;
27129 }
27130 EXPORT_SYMBOL(copy_in_user);
27131
27132@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27133 * it is not necessary to optimize tail handling.
27134 */
27135 unsigned long
27136-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27137+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27138 {
27139 char c;
27140 unsigned zero_len;
27141diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27142index 903ec1e..c4166b2 100644
27143--- a/arch/x86/mm/extable.c
27144+++ b/arch/x86/mm/extable.c
27145@@ -6,12 +6,24 @@
27146 static inline unsigned long
27147 ex_insn_addr(const struct exception_table_entry *x)
27148 {
27149- return (unsigned long)&x->insn + x->insn;
27150+ unsigned long reloc = 0;
27151+
27152+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27153+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27154+#endif
27155+
27156+ return (unsigned long)&x->insn + x->insn + reloc;
27157 }
27158 static inline unsigned long
27159 ex_fixup_addr(const struct exception_table_entry *x)
27160 {
27161- return (unsigned long)&x->fixup + x->fixup;
27162+ unsigned long reloc = 0;
27163+
27164+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27165+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27166+#endif
27167+
27168+ return (unsigned long)&x->fixup + x->fixup + reloc;
27169 }
27170
27171 int fixup_exception(struct pt_regs *regs)
27172@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27173 unsigned long new_ip;
27174
27175 #ifdef CONFIG_PNPBIOS
27176- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27177+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27178 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27179 extern u32 pnp_bios_is_utter_crap;
27180 pnp_bios_is_utter_crap = 1;
27181@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27182 i += 4;
27183 p->fixup -= i;
27184 i += 4;
27185+
27186+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27187+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27188+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27189+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27190+#endif
27191+
27192 }
27193 }
27194
27195diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27196index 654be4a..d36985f 100644
27197--- a/arch/x86/mm/fault.c
27198+++ b/arch/x86/mm/fault.c
27199@@ -14,11 +14,18 @@
27200 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27201 #include <linux/prefetch.h> /* prefetchw */
27202 #include <linux/context_tracking.h> /* exception_enter(), ... */
27203+#include <linux/unistd.h>
27204+#include <linux/compiler.h>
27205
27206 #include <asm/traps.h> /* dotraplinkage, ... */
27207 #include <asm/pgalloc.h> /* pgd_*(), ... */
27208 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27209 #include <asm/fixmap.h> /* VSYSCALL_START */
27210+#include <asm/tlbflush.h>
27211+
27212+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27213+#include <asm/stacktrace.h>
27214+#endif
27215
27216 /*
27217 * Page fault error code bits:
27218@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27219 int ret = 0;
27220
27221 /* kprobe_running() needs smp_processor_id() */
27222- if (kprobes_built_in() && !user_mode_vm(regs)) {
27223+ if (kprobes_built_in() && !user_mode(regs)) {
27224 preempt_disable();
27225 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27226 ret = 1;
27227@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27228 return !instr_lo || (instr_lo>>1) == 1;
27229 case 0x00:
27230 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27231- if (probe_kernel_address(instr, opcode))
27232+ if (user_mode(regs)) {
27233+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27234+ return 0;
27235+ } else if (probe_kernel_address(instr, opcode))
27236 return 0;
27237
27238 *prefetch = (instr_lo == 0xF) &&
27239@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27240 while (instr < max_instr) {
27241 unsigned char opcode;
27242
27243- if (probe_kernel_address(instr, opcode))
27244+ if (user_mode(regs)) {
27245+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27246+ break;
27247+ } else if (probe_kernel_address(instr, opcode))
27248 break;
27249
27250 instr++;
27251@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27252 force_sig_info(si_signo, &info, tsk);
27253 }
27254
27255+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27256+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27257+#endif
27258+
27259+#ifdef CONFIG_PAX_EMUTRAMP
27260+static int pax_handle_fetch_fault(struct pt_regs *regs);
27261+#endif
27262+
27263+#ifdef CONFIG_PAX_PAGEEXEC
27264+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27265+{
27266+ pgd_t *pgd;
27267+ pud_t *pud;
27268+ pmd_t *pmd;
27269+
27270+ pgd = pgd_offset(mm, address);
27271+ if (!pgd_present(*pgd))
27272+ return NULL;
27273+ pud = pud_offset(pgd, address);
27274+ if (!pud_present(*pud))
27275+ return NULL;
27276+ pmd = pmd_offset(pud, address);
27277+ if (!pmd_present(*pmd))
27278+ return NULL;
27279+ return pmd;
27280+}
27281+#endif
27282+
27283 DEFINE_SPINLOCK(pgd_lock);
27284 LIST_HEAD(pgd_list);
27285
27286@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27287 for (address = VMALLOC_START & PMD_MASK;
27288 address >= TASK_SIZE && address < FIXADDR_TOP;
27289 address += PMD_SIZE) {
27290+
27291+#ifdef CONFIG_PAX_PER_CPU_PGD
27292+ unsigned long cpu;
27293+#else
27294 struct page *page;
27295+#endif
27296
27297 spin_lock(&pgd_lock);
27298+
27299+#ifdef CONFIG_PAX_PER_CPU_PGD
27300+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27301+ pgd_t *pgd = get_cpu_pgd(cpu);
27302+ pmd_t *ret;
27303+#else
27304 list_for_each_entry(page, &pgd_list, lru) {
27305+ pgd_t *pgd;
27306 spinlock_t *pgt_lock;
27307 pmd_t *ret;
27308
27309@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
27310 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27311
27312 spin_lock(pgt_lock);
27313- ret = vmalloc_sync_one(page_address(page), address);
27314+ pgd = page_address(page);
27315+#endif
27316+
27317+ ret = vmalloc_sync_one(pgd, address);
27318+
27319+#ifndef CONFIG_PAX_PER_CPU_PGD
27320 spin_unlock(pgt_lock);
27321+#endif
27322
27323 if (!ret)
27324 break;
27325@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27326 * an interrupt in the middle of a task switch..
27327 */
27328 pgd_paddr = read_cr3();
27329+
27330+#ifdef CONFIG_PAX_PER_CPU_PGD
27331+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27332+#endif
27333+
27334 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27335 if (!pmd_k)
27336 return -1;
27337@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27338 * happen within a race in page table update. In the later
27339 * case just flush:
27340 */
27341+
27342+#ifdef CONFIG_PAX_PER_CPU_PGD
27343+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27344+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27345+#else
27346 pgd = pgd_offset(current->active_mm, address);
27347+#endif
27348+
27349 pgd_ref = pgd_offset_k(address);
27350 if (pgd_none(*pgd_ref))
27351 return -1;
27352@@ -543,7 +614,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27353 static int is_errata100(struct pt_regs *regs, unsigned long address)
27354 {
27355 #ifdef CONFIG_X86_64
27356- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27357+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27358 return 1;
27359 #endif
27360 return 0;
27361@@ -570,7 +641,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27362 }
27363
27364 static const char nx_warning[] = KERN_CRIT
27365-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27366+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27367
27368 static void
27369 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27370@@ -579,15 +650,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27371 if (!oops_may_print())
27372 return;
27373
27374- if (error_code & PF_INSTR) {
27375+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27376 unsigned int level;
27377
27378 pte_t *pte = lookup_address(address, &level);
27379
27380 if (pte && pte_present(*pte) && !pte_exec(*pte))
27381- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27382+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27383 }
27384
27385+#ifdef CONFIG_PAX_KERNEXEC
27386+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27387+ if (current->signal->curr_ip)
27388+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27389+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27390+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27391+ else
27392+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27393+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27394+ }
27395+#endif
27396+
27397 printk(KERN_ALERT "BUG: unable to handle kernel ");
27398 if (address < PAGE_SIZE)
27399 printk(KERN_CONT "NULL pointer dereference");
27400@@ -750,6 +833,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27401 return;
27402 }
27403 #endif
27404+
27405+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27406+ if (pax_is_fetch_fault(regs, error_code, address)) {
27407+
27408+#ifdef CONFIG_PAX_EMUTRAMP
27409+ switch (pax_handle_fetch_fault(regs)) {
27410+ case 2:
27411+ return;
27412+ }
27413+#endif
27414+
27415+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27416+ do_group_exit(SIGKILL);
27417+ }
27418+#endif
27419+
27420 /* Kernel addresses are always protection faults: */
27421 if (address >= TASK_SIZE)
27422 error_code |= PF_PROT;
27423@@ -835,7 +934,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27424 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27425 printk(KERN_ERR
27426 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27427- tsk->comm, tsk->pid, address);
27428+ tsk->comm, task_pid_nr(tsk), address);
27429 code = BUS_MCEERR_AR;
27430 }
27431 #endif
27432@@ -898,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27433 return 1;
27434 }
27435
27436+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27437+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27438+{
27439+ pte_t *pte;
27440+ pmd_t *pmd;
27441+ spinlock_t *ptl;
27442+ unsigned char pte_mask;
27443+
27444+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27445+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27446+ return 0;
27447+
27448+ /* PaX: it's our fault, let's handle it if we can */
27449+
27450+ /* PaX: take a look at read faults before acquiring any locks */
27451+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27452+ /* instruction fetch attempt from a protected page in user mode */
27453+ up_read(&mm->mmap_sem);
27454+
27455+#ifdef CONFIG_PAX_EMUTRAMP
27456+ switch (pax_handle_fetch_fault(regs)) {
27457+ case 2:
27458+ return 1;
27459+ }
27460+#endif
27461+
27462+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27463+ do_group_exit(SIGKILL);
27464+ }
27465+
27466+ pmd = pax_get_pmd(mm, address);
27467+ if (unlikely(!pmd))
27468+ return 0;
27469+
27470+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27471+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27472+ pte_unmap_unlock(pte, ptl);
27473+ return 0;
27474+ }
27475+
27476+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27477+ /* write attempt to a protected page in user mode */
27478+ pte_unmap_unlock(pte, ptl);
27479+ return 0;
27480+ }
27481+
27482+#ifdef CONFIG_SMP
27483+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27484+#else
27485+ if (likely(address > get_limit(regs->cs)))
27486+#endif
27487+ {
27488+ set_pte(pte, pte_mkread(*pte));
27489+ __flush_tlb_one(address);
27490+ pte_unmap_unlock(pte, ptl);
27491+ up_read(&mm->mmap_sem);
27492+ return 1;
27493+ }
27494+
27495+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27496+
27497+ /*
27498+ * PaX: fill DTLB with user rights and retry
27499+ */
27500+ __asm__ __volatile__ (
27501+ "orb %2,(%1)\n"
27502+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27503+/*
27504+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27505+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27506+ * page fault when examined during a TLB load attempt. this is true not only
27507+ * for PTEs holding a non-present entry but also present entries that will
27508+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27509+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27510+ * for our target pages since their PTEs are simply not in the TLBs at all.
27511+
27512+ * the best thing in omitting it is that we gain around 15-20% speed in the
27513+ * fast path of the page fault handler and can get rid of tracing since we
27514+ * can no longer flush unintended entries.
27515+ */
27516+ "invlpg (%0)\n"
27517+#endif
27518+ __copyuser_seg"testb $0,(%0)\n"
27519+ "xorb %3,(%1)\n"
27520+ :
27521+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27522+ : "memory", "cc");
27523+ pte_unmap_unlock(pte, ptl);
27524+ up_read(&mm->mmap_sem);
27525+ return 1;
27526+}
27527+#endif
27528+
27529 /*
27530 * Handle a spurious fault caused by a stale TLB entry.
27531 *
27532@@ -964,6 +1156,9 @@ int show_unhandled_signals = 1;
27533 static inline int
27534 access_error(unsigned long error_code, struct vm_area_struct *vma)
27535 {
27536+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27537+ return 1;
27538+
27539 if (error_code & PF_WRITE) {
27540 /* write, present and write, not present: */
27541 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27542@@ -992,7 +1187,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27543 if (error_code & PF_USER)
27544 return false;
27545
27546- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27547+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27548 return false;
27549
27550 return true;
27551@@ -1008,18 +1203,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27552 {
27553 struct vm_area_struct *vma;
27554 struct task_struct *tsk;
27555- unsigned long address;
27556 struct mm_struct *mm;
27557 int fault;
27558 int write = error_code & PF_WRITE;
27559 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27560 (write ? FAULT_FLAG_WRITE : 0);
27561
27562- tsk = current;
27563- mm = tsk->mm;
27564-
27565 /* Get the faulting address: */
27566- address = read_cr2();
27567+ unsigned long address = read_cr2();
27568+
27569+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27570+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
27571+ if (!search_exception_tables(regs->ip)) {
27572+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27573+ bad_area_nosemaphore(regs, error_code, address);
27574+ return;
27575+ }
27576+ if (address < pax_user_shadow_base) {
27577+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27578+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27579+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27580+ } else
27581+ address -= pax_user_shadow_base;
27582+ }
27583+#endif
27584+
27585+ tsk = current;
27586+ mm = tsk->mm;
27587
27588 /*
27589 * Detect and handle instructions that would cause a page fault for
27590@@ -1080,7 +1290,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27591 * User-mode registers count as a user access even for any
27592 * potential system fault or CPU buglet:
27593 */
27594- if (user_mode_vm(regs)) {
27595+ if (user_mode(regs)) {
27596 local_irq_enable();
27597 error_code |= PF_USER;
27598 } else {
27599@@ -1142,6 +1352,11 @@ retry:
27600 might_sleep();
27601 }
27602
27603+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27604+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27605+ return;
27606+#endif
27607+
27608 vma = find_vma(mm, address);
27609 if (unlikely(!vma)) {
27610 bad_area(regs, error_code, address);
27611@@ -1153,18 +1368,24 @@ retry:
27612 bad_area(regs, error_code, address);
27613 return;
27614 }
27615- if (error_code & PF_USER) {
27616- /*
27617- * Accessing the stack below %sp is always a bug.
27618- * The large cushion allows instructions like enter
27619- * and pusha to work. ("enter $65535, $31" pushes
27620- * 32 pointers and then decrements %sp by 65535.)
27621- */
27622- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27623- bad_area(regs, error_code, address);
27624- return;
27625- }
27626+ /*
27627+ * Accessing the stack below %sp is always a bug.
27628+ * The large cushion allows instructions like enter
27629+ * and pusha to work. ("enter $65535, $31" pushes
27630+ * 32 pointers and then decrements %sp by 65535.)
27631+ */
27632+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27633+ bad_area(regs, error_code, address);
27634+ return;
27635 }
27636+
27637+#ifdef CONFIG_PAX_SEGMEXEC
27638+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27639+ bad_area(regs, error_code, address);
27640+ return;
27641+ }
27642+#endif
27643+
27644 if (unlikely(expand_stack(vma, address))) {
27645 bad_area(regs, error_code, address);
27646 return;
27647@@ -1230,3 +1451,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27648 __do_page_fault(regs, error_code);
27649 exception_exit(prev_state);
27650 }
27651+
27652+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27653+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27654+{
27655+ struct mm_struct *mm = current->mm;
27656+ unsigned long ip = regs->ip;
27657+
27658+ if (v8086_mode(regs))
27659+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27660+
27661+#ifdef CONFIG_PAX_PAGEEXEC
27662+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27663+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27664+ return true;
27665+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27666+ return true;
27667+ return false;
27668+ }
27669+#endif
27670+
27671+#ifdef CONFIG_PAX_SEGMEXEC
27672+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27673+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27674+ return true;
27675+ return false;
27676+ }
27677+#endif
27678+
27679+ return false;
27680+}
27681+#endif
27682+
27683+#ifdef CONFIG_PAX_EMUTRAMP
27684+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27685+{
27686+ int err;
27687+
27688+ do { /* PaX: libffi trampoline emulation */
27689+ unsigned char mov, jmp;
27690+ unsigned int addr1, addr2;
27691+
27692+#ifdef CONFIG_X86_64
27693+ if ((regs->ip + 9) >> 32)
27694+ break;
27695+#endif
27696+
27697+ err = get_user(mov, (unsigned char __user *)regs->ip);
27698+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27699+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27700+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27701+
27702+ if (err)
27703+ break;
27704+
27705+ if (mov == 0xB8 && jmp == 0xE9) {
27706+ regs->ax = addr1;
27707+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27708+ return 2;
27709+ }
27710+ } while (0);
27711+
27712+ do { /* PaX: gcc trampoline emulation #1 */
27713+ unsigned char mov1, mov2;
27714+ unsigned short jmp;
27715+ unsigned int addr1, addr2;
27716+
27717+#ifdef CONFIG_X86_64
27718+ if ((regs->ip + 11) >> 32)
27719+ break;
27720+#endif
27721+
27722+ err = get_user(mov1, (unsigned char __user *)regs->ip);
27723+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27724+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27725+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27726+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27727+
27728+ if (err)
27729+ break;
27730+
27731+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27732+ regs->cx = addr1;
27733+ regs->ax = addr2;
27734+ regs->ip = addr2;
27735+ return 2;
27736+ }
27737+ } while (0);
27738+
27739+ do { /* PaX: gcc trampoline emulation #2 */
27740+ unsigned char mov, jmp;
27741+ unsigned int addr1, addr2;
27742+
27743+#ifdef CONFIG_X86_64
27744+ if ((regs->ip + 9) >> 32)
27745+ break;
27746+#endif
27747+
27748+ err = get_user(mov, (unsigned char __user *)regs->ip);
27749+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27750+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27751+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27752+
27753+ if (err)
27754+ break;
27755+
27756+ if (mov == 0xB9 && jmp == 0xE9) {
27757+ regs->cx = addr1;
27758+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27759+ return 2;
27760+ }
27761+ } while (0);
27762+
27763+ return 1; /* PaX in action */
27764+}
27765+
27766+#ifdef CONFIG_X86_64
27767+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27768+{
27769+ int err;
27770+
27771+ do { /* PaX: libffi trampoline emulation */
27772+ unsigned short mov1, mov2, jmp1;
27773+ unsigned char stcclc, jmp2;
27774+ unsigned long addr1, addr2;
27775+
27776+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27777+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27778+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27779+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27780+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27781+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27782+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27783+
27784+ if (err)
27785+ break;
27786+
27787+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27788+ regs->r11 = addr1;
27789+ regs->r10 = addr2;
27790+ if (stcclc == 0xF8)
27791+ regs->flags &= ~X86_EFLAGS_CF;
27792+ else
27793+ regs->flags |= X86_EFLAGS_CF;
27794+ regs->ip = addr1;
27795+ return 2;
27796+ }
27797+ } while (0);
27798+
27799+ do { /* PaX: gcc trampoline emulation #1 */
27800+ unsigned short mov1, mov2, jmp1;
27801+ unsigned char jmp2;
27802+ unsigned int addr1;
27803+ unsigned long addr2;
27804+
27805+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27806+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27807+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27808+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27809+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27810+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27811+
27812+ if (err)
27813+ break;
27814+
27815+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27816+ regs->r11 = addr1;
27817+ regs->r10 = addr2;
27818+ regs->ip = addr1;
27819+ return 2;
27820+ }
27821+ } while (0);
27822+
27823+ do { /* PaX: gcc trampoline emulation #2 */
27824+ unsigned short mov1, mov2, jmp1;
27825+ unsigned char jmp2;
27826+ unsigned long addr1, addr2;
27827+
27828+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27829+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27830+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27831+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27832+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27833+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27834+
27835+ if (err)
27836+ break;
27837+
27838+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27839+ regs->r11 = addr1;
27840+ regs->r10 = addr2;
27841+ regs->ip = addr1;
27842+ return 2;
27843+ }
27844+ } while (0);
27845+
27846+ return 1; /* PaX in action */
27847+}
27848+#endif
27849+
27850+/*
27851+ * PaX: decide what to do with offenders (regs->ip = fault address)
27852+ *
27853+ * returns 1 when task should be killed
27854+ * 2 when gcc trampoline was detected
27855+ */
27856+static int pax_handle_fetch_fault(struct pt_regs *regs)
27857+{
27858+ if (v8086_mode(regs))
27859+ return 1;
27860+
27861+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27862+ return 1;
27863+
27864+#ifdef CONFIG_X86_32
27865+ return pax_handle_fetch_fault_32(regs);
27866+#else
27867+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27868+ return pax_handle_fetch_fault_32(regs);
27869+ else
27870+ return pax_handle_fetch_fault_64(regs);
27871+#endif
27872+}
27873+#endif
27874+
27875+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27876+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27877+{
27878+ long i;
27879+
27880+ printk(KERN_ERR "PAX: bytes at PC: ");
27881+ for (i = 0; i < 20; i++) {
27882+ unsigned char c;
27883+ if (get_user(c, (unsigned char __force_user *)pc+i))
27884+ printk(KERN_CONT "?? ");
27885+ else
27886+ printk(KERN_CONT "%02x ", c);
27887+ }
27888+ printk("\n");
27889+
27890+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27891+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27892+ unsigned long c;
27893+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27894+#ifdef CONFIG_X86_32
27895+ printk(KERN_CONT "???????? ");
27896+#else
27897+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27898+ printk(KERN_CONT "???????? ???????? ");
27899+ else
27900+ printk(KERN_CONT "???????????????? ");
27901+#endif
27902+ } else {
27903+#ifdef CONFIG_X86_64
27904+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27905+ printk(KERN_CONT "%08x ", (unsigned int)c);
27906+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27907+ } else
27908+#endif
27909+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27910+ }
27911+ }
27912+ printk("\n");
27913+}
27914+#endif
27915+
27916+/**
27917+ * probe_kernel_write(): safely attempt to write to a location
27918+ * @dst: address to write to
27919+ * @src: pointer to the data that shall be written
27920+ * @size: size of the data chunk
27921+ *
27922+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27923+ * happens, handle that and return -EFAULT.
27924+ */
27925+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27926+{
27927+ long ret;
27928+ mm_segment_t old_fs = get_fs();
27929+
27930+ set_fs(KERNEL_DS);
27931+ pagefault_disable();
27932+ pax_open_kernel();
27933+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27934+ pax_close_kernel();
27935+ pagefault_enable();
27936+ set_fs(old_fs);
27937+
27938+ return ret ? -EFAULT : 0;
27939+}
27940diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27941index dd74e46..7d26398 100644
27942--- a/arch/x86/mm/gup.c
27943+++ b/arch/x86/mm/gup.c
27944@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27945 addr = start;
27946 len = (unsigned long) nr_pages << PAGE_SHIFT;
27947 end = start + len;
27948- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27949+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27950 (void __user *)start, len)))
27951 return 0;
27952
27953diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27954index 252b8f5..4dcfdc1 100644
27955--- a/arch/x86/mm/highmem_32.c
27956+++ b/arch/x86/mm/highmem_32.c
27957@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27958 idx = type + KM_TYPE_NR*smp_processor_id();
27959 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27960 BUG_ON(!pte_none(*(kmap_pte-idx)));
27961+
27962+ pax_open_kernel();
27963 set_pte(kmap_pte-idx, mk_pte(page, prot));
27964+ pax_close_kernel();
27965+
27966 arch_flush_lazy_mmu_mode();
27967
27968 return (void *)vaddr;
27969diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27970index ae1aa71..d9bea75 100644
27971--- a/arch/x86/mm/hugetlbpage.c
27972+++ b/arch/x86/mm/hugetlbpage.c
27973@@ -271,23 +271,30 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
27974 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
27975 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27976 unsigned long addr, unsigned long len,
27977- unsigned long pgoff, unsigned long flags)
27978+ unsigned long pgoff, unsigned long flags, unsigned long offset)
27979 {
27980 struct hstate *h = hstate_file(file);
27981 struct vm_unmapped_area_info info;
27982-
27983+
27984 info.flags = 0;
27985 info.length = len;
27986 info.low_limit = TASK_UNMAPPED_BASE;
27987+
27988+#ifdef CONFIG_PAX_RANDMMAP
27989+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27990+ info.low_limit += current->mm->delta_mmap;
27991+#endif
27992+
27993 info.high_limit = TASK_SIZE;
27994 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27995 info.align_offset = 0;
27996+ info.threadstack_offset = offset;
27997 return vm_unmapped_area(&info);
27998 }
27999
28000 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28001 unsigned long addr0, unsigned long len,
28002- unsigned long pgoff, unsigned long flags)
28003+ unsigned long pgoff, unsigned long flags, unsigned long offset)
28004 {
28005 struct hstate *h = hstate_file(file);
28006 struct vm_unmapped_area_info info;
28007@@ -299,6 +306,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28008 info.high_limit = current->mm->mmap_base;
28009 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28010 info.align_offset = 0;
28011+ info.threadstack_offset = offset;
28012 addr = vm_unmapped_area(&info);
28013
28014 /*
28015@@ -311,6 +319,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28016 VM_BUG_ON(addr != -ENOMEM);
28017 info.flags = 0;
28018 info.low_limit = TASK_UNMAPPED_BASE;
28019+
28020+#ifdef CONFIG_PAX_RANDMMAP
28021+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28022+ info.low_limit += current->mm->delta_mmap;
28023+#endif
28024+
28025 info.high_limit = TASK_SIZE;
28026 addr = vm_unmapped_area(&info);
28027 }
28028@@ -325,10 +339,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28029 struct hstate *h = hstate_file(file);
28030 struct mm_struct *mm = current->mm;
28031 struct vm_area_struct *vma;
28032+ unsigned long pax_task_size = TASK_SIZE;
28033+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
28034
28035 if (len & ~huge_page_mask(h))
28036 return -EINVAL;
28037- if (len > TASK_SIZE)
28038+
28039+#ifdef CONFIG_PAX_SEGMEXEC
28040+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28041+ pax_task_size = SEGMEXEC_TASK_SIZE;
28042+#endif
28043+
28044+ pax_task_size -= PAGE_SIZE;
28045+
28046+ if (len > pax_task_size)
28047 return -ENOMEM;
28048
28049 if (flags & MAP_FIXED) {
28050@@ -337,19 +361,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28051 return addr;
28052 }
28053
28054+#ifdef CONFIG_PAX_RANDMMAP
28055+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28056+#endif
28057+
28058 if (addr) {
28059 addr = ALIGN(addr, huge_page_size(h));
28060 vma = find_vma(mm, addr);
28061- if (TASK_SIZE - len >= addr &&
28062- (!vma || addr + len <= vma->vm_start))
28063+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28064 return addr;
28065 }
28066 if (mm->get_unmapped_area == arch_get_unmapped_area)
28067 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
28068- pgoff, flags);
28069+ pgoff, flags, offset);
28070 else
28071 return hugetlb_get_unmapped_area_topdown(file, addr, len,
28072- pgoff, flags);
28073+ pgoff, flags, offset);
28074 }
28075
28076 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
28077diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
28078index 1f34e92..d252637 100644
28079--- a/arch/x86/mm/init.c
28080+++ b/arch/x86/mm/init.c
28081@@ -4,6 +4,7 @@
28082 #include <linux/swap.h>
28083 #include <linux/memblock.h>
28084 #include <linux/bootmem.h> /* for max_low_pfn */
28085+#include <linux/tboot.h>
28086
28087 #include <asm/cacheflush.h>
28088 #include <asm/e820.h>
28089@@ -17,6 +18,8 @@
28090 #include <asm/proto.h>
28091 #include <asm/dma.h> /* for MAX_DMA_PFN */
28092 #include <asm/microcode.h>
28093+#include <asm/desc.h>
28094+#include <asm/bios_ebda.h>
28095
28096 #include "mm_internal.h"
28097
28098@@ -465,7 +468,15 @@ void __init init_mem_mapping(void)
28099 early_ioremap_page_table_range_init();
28100 #endif
28101
28102+#ifdef CONFIG_PAX_PER_CPU_PGD
28103+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28104+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28105+ KERNEL_PGD_PTRS);
28106+ load_cr3(get_cpu_pgd(0));
28107+#else
28108 load_cr3(swapper_pg_dir);
28109+#endif
28110+
28111 __flush_tlb_all();
28112
28113 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
28114@@ -481,10 +492,40 @@ void __init init_mem_mapping(void)
28115 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
28116 * mmio resources as well as potential bios/acpi data regions.
28117 */
28118+
28119+#ifdef CONFIG_GRKERNSEC_KMEM
28120+static unsigned int ebda_start __read_only;
28121+static unsigned int ebda_end __read_only;
28122+#endif
28123+
28124 int devmem_is_allowed(unsigned long pagenr)
28125 {
28126- if (pagenr < 256)
28127+#ifdef CONFIG_GRKERNSEC_KMEM
28128+ /* allow BDA */
28129+ if (!pagenr)
28130 return 1;
28131+ /* allow EBDA */
28132+ if (pagenr >= ebda_start && pagenr < ebda_end)
28133+ return 1;
28134+ /* if tboot is in use, allow access to its hardcoded serial log range */
28135+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28136+ return 1;
28137+#else
28138+ if (!pagenr)
28139+ return 1;
28140+#ifdef CONFIG_VM86
28141+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28142+ return 1;
28143+#endif
28144+#endif
28145+
28146+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28147+ return 1;
28148+#ifdef CONFIG_GRKERNSEC_KMEM
28149+ /* throw out everything else below 1MB */
28150+ if (pagenr <= 256)
28151+ return 0;
28152+#endif
28153 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28154 return 0;
28155 if (!page_is_ram(pagenr))
28156@@ -538,8 +579,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28157 #endif
28158 }
28159
28160+#ifdef CONFIG_GRKERNSEC_KMEM
28161+static inline void gr_init_ebda(void)
28162+{
28163+ unsigned int ebda_addr;
28164+ unsigned int ebda_size = 0;
28165+
28166+ ebda_addr = get_bios_ebda();
28167+ if (ebda_addr) {
28168+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28169+ ebda_size <<= 10;
28170+ }
28171+ if (ebda_addr && ebda_size) {
28172+ ebda_start = ebda_addr >> PAGE_SHIFT;
28173+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28174+ } else {
28175+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28176+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28177+ }
28178+}
28179+#else
28180+static inline void gr_init_ebda(void) { }
28181+#endif
28182+
28183 void free_initmem(void)
28184 {
28185+#ifdef CONFIG_PAX_KERNEXEC
28186+#ifdef CONFIG_X86_32
28187+ /* PaX: limit KERNEL_CS to actual size */
28188+ unsigned long addr, limit;
28189+ struct desc_struct d;
28190+ int cpu;
28191+#else
28192+ pgd_t *pgd;
28193+ pud_t *pud;
28194+ pmd_t *pmd;
28195+ unsigned long addr, end;
28196+#endif
28197+#endif
28198+
28199+ gr_init_ebda();
28200+
28201+#ifdef CONFIG_PAX_KERNEXEC
28202+#ifdef CONFIG_X86_32
28203+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28204+ limit = (limit - 1UL) >> PAGE_SHIFT;
28205+
28206+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28207+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28208+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28209+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28210+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28211+ }
28212+
28213+ /* PaX: make KERNEL_CS read-only */
28214+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28215+ if (!paravirt_enabled())
28216+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28217+/*
28218+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28219+ pgd = pgd_offset_k(addr);
28220+ pud = pud_offset(pgd, addr);
28221+ pmd = pmd_offset(pud, addr);
28222+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28223+ }
28224+*/
28225+#ifdef CONFIG_X86_PAE
28226+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28227+/*
28228+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28229+ pgd = pgd_offset_k(addr);
28230+ pud = pud_offset(pgd, addr);
28231+ pmd = pmd_offset(pud, addr);
28232+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28233+ }
28234+*/
28235+#endif
28236+
28237+#ifdef CONFIG_MODULES
28238+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28239+#endif
28240+
28241+#else
28242+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28243+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28244+ pgd = pgd_offset_k(addr);
28245+ pud = pud_offset(pgd, addr);
28246+ pmd = pmd_offset(pud, addr);
28247+ if (!pmd_present(*pmd))
28248+ continue;
28249+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28250+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28251+ else
28252+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28253+ }
28254+
28255+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28256+ end = addr + KERNEL_IMAGE_SIZE;
28257+ for (; addr < end; addr += PMD_SIZE) {
28258+ pgd = pgd_offset_k(addr);
28259+ pud = pud_offset(pgd, addr);
28260+ pmd = pmd_offset(pud, addr);
28261+ if (!pmd_present(*pmd))
28262+ continue;
28263+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28264+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28265+ }
28266+#endif
28267+
28268+ flush_tlb_all();
28269+#endif
28270+
28271 free_init_pages("unused kernel memory",
28272 (unsigned long)(&__init_begin),
28273 (unsigned long)(&__init_end));
28274diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28275index 3ac7e31..89611b7 100644
28276--- a/arch/x86/mm/init_32.c
28277+++ b/arch/x86/mm/init_32.c
28278@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
28279 bool __read_mostly __vmalloc_start_set = false;
28280
28281 /*
28282- * Creates a middle page table and puts a pointer to it in the
28283- * given global directory entry. This only returns the gd entry
28284- * in non-PAE compilation mode, since the middle layer is folded.
28285- */
28286-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28287-{
28288- pud_t *pud;
28289- pmd_t *pmd_table;
28290-
28291-#ifdef CONFIG_X86_PAE
28292- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28293- pmd_table = (pmd_t *)alloc_low_page();
28294- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28295- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28296- pud = pud_offset(pgd, 0);
28297- BUG_ON(pmd_table != pmd_offset(pud, 0));
28298-
28299- return pmd_table;
28300- }
28301-#endif
28302- pud = pud_offset(pgd, 0);
28303- pmd_table = pmd_offset(pud, 0);
28304-
28305- return pmd_table;
28306-}
28307-
28308-/*
28309 * Create a page table and place a pointer to it in a middle page
28310 * directory entry:
28311 */
28312@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28313 pte_t *page_table = (pte_t *)alloc_low_page();
28314
28315 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28316+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28317+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28318+#else
28319 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28320+#endif
28321 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28322 }
28323
28324 return pte_offset_kernel(pmd, 0);
28325 }
28326
28327+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28328+{
28329+ pud_t *pud;
28330+ pmd_t *pmd_table;
28331+
28332+ pud = pud_offset(pgd, 0);
28333+ pmd_table = pmd_offset(pud, 0);
28334+
28335+ return pmd_table;
28336+}
28337+
28338 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28339 {
28340 int pgd_idx = pgd_index(vaddr);
28341@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28342 int pgd_idx, pmd_idx;
28343 unsigned long vaddr;
28344 pgd_t *pgd;
28345+ pud_t *pud;
28346 pmd_t *pmd;
28347 pte_t *pte = NULL;
28348 unsigned long count = page_table_range_init_count(start, end);
28349@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28350 pgd = pgd_base + pgd_idx;
28351
28352 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28353- pmd = one_md_table_init(pgd);
28354- pmd = pmd + pmd_index(vaddr);
28355+ pud = pud_offset(pgd, vaddr);
28356+ pmd = pmd_offset(pud, vaddr);
28357+
28358+#ifdef CONFIG_X86_PAE
28359+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28360+#endif
28361+
28362 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28363 pmd++, pmd_idx++) {
28364 pte = page_table_kmap_check(one_page_table_init(pmd),
28365@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28366 }
28367 }
28368
28369-static inline int is_kernel_text(unsigned long addr)
28370+static inline int is_kernel_text(unsigned long start, unsigned long end)
28371 {
28372- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28373- return 1;
28374- return 0;
28375+ if ((start > ktla_ktva((unsigned long)_etext) ||
28376+ end <= ktla_ktva((unsigned long)_stext)) &&
28377+ (start > ktla_ktva((unsigned long)_einittext) ||
28378+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28379+
28380+#ifdef CONFIG_ACPI_SLEEP
28381+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28382+#endif
28383+
28384+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28385+ return 0;
28386+ return 1;
28387 }
28388
28389 /*
28390@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
28391 unsigned long last_map_addr = end;
28392 unsigned long start_pfn, end_pfn;
28393 pgd_t *pgd_base = swapper_pg_dir;
28394- int pgd_idx, pmd_idx, pte_ofs;
28395+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28396 unsigned long pfn;
28397 pgd_t *pgd;
28398+ pud_t *pud;
28399 pmd_t *pmd;
28400 pte_t *pte;
28401 unsigned pages_2m, pages_4k;
28402@@ -291,8 +295,13 @@ repeat:
28403 pfn = start_pfn;
28404 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28405 pgd = pgd_base + pgd_idx;
28406- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28407- pmd = one_md_table_init(pgd);
28408+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28409+ pud = pud_offset(pgd, 0);
28410+ pmd = pmd_offset(pud, 0);
28411+
28412+#ifdef CONFIG_X86_PAE
28413+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28414+#endif
28415
28416 if (pfn >= end_pfn)
28417 continue;
28418@@ -304,14 +313,13 @@ repeat:
28419 #endif
28420 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28421 pmd++, pmd_idx++) {
28422- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28423+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28424
28425 /*
28426 * Map with big pages if possible, otherwise
28427 * create normal page tables:
28428 */
28429 if (use_pse) {
28430- unsigned int addr2;
28431 pgprot_t prot = PAGE_KERNEL_LARGE;
28432 /*
28433 * first pass will use the same initial
28434@@ -322,11 +330,7 @@ repeat:
28435 _PAGE_PSE);
28436
28437 pfn &= PMD_MASK >> PAGE_SHIFT;
28438- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28439- PAGE_OFFSET + PAGE_SIZE-1;
28440-
28441- if (is_kernel_text(addr) ||
28442- is_kernel_text(addr2))
28443+ if (is_kernel_text(address, address + PMD_SIZE))
28444 prot = PAGE_KERNEL_LARGE_EXEC;
28445
28446 pages_2m++;
28447@@ -343,7 +347,7 @@ repeat:
28448 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28449 pte += pte_ofs;
28450 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28451- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28452+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28453 pgprot_t prot = PAGE_KERNEL;
28454 /*
28455 * first pass will use the same initial
28456@@ -351,7 +355,7 @@ repeat:
28457 */
28458 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28459
28460- if (is_kernel_text(addr))
28461+ if (is_kernel_text(address, address + PAGE_SIZE))
28462 prot = PAGE_KERNEL_EXEC;
28463
28464 pages_4k++;
28465@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
28466
28467 pud = pud_offset(pgd, va);
28468 pmd = pmd_offset(pud, va);
28469- if (!pmd_present(*pmd))
28470+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
28471 break;
28472
28473 /* should not be large page here */
28474@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
28475
28476 static void __init pagetable_init(void)
28477 {
28478- pgd_t *pgd_base = swapper_pg_dir;
28479-
28480- permanent_kmaps_init(pgd_base);
28481+ permanent_kmaps_init(swapper_pg_dir);
28482 }
28483
28484-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28485+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28486 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28487
28488 /* user-defined highmem size */
28489@@ -772,7 +774,7 @@ void __init mem_init(void)
28490 after_bootmem = 1;
28491
28492 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28493- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28494+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28495 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28496
28497 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28498@@ -813,10 +815,10 @@ void __init mem_init(void)
28499 ((unsigned long)&__init_end -
28500 (unsigned long)&__init_begin) >> 10,
28501
28502- (unsigned long)&_etext, (unsigned long)&_edata,
28503- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28504+ (unsigned long)&_sdata, (unsigned long)&_edata,
28505+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28506
28507- (unsigned long)&_text, (unsigned long)&_etext,
28508+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28509 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28510
28511 /*
28512@@ -906,6 +908,7 @@ void set_kernel_text_rw(void)
28513 if (!kernel_set_to_readonly)
28514 return;
28515
28516+ start = ktla_ktva(start);
28517 pr_debug("Set kernel text: %lx - %lx for read write\n",
28518 start, start+size);
28519
28520@@ -920,6 +923,7 @@ void set_kernel_text_ro(void)
28521 if (!kernel_set_to_readonly)
28522 return;
28523
28524+ start = ktla_ktva(start);
28525 pr_debug("Set kernel text: %lx - %lx for read only\n",
28526 start, start+size);
28527
28528@@ -948,6 +952,7 @@ void mark_rodata_ro(void)
28529 unsigned long start = PFN_ALIGN(_text);
28530 unsigned long size = PFN_ALIGN(_etext) - start;
28531
28532+ start = ktla_ktva(start);
28533 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28534 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28535 size >> 10);
28536diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28537index bb00c46..f31d2f0 100644
28538--- a/arch/x86/mm/init_64.c
28539+++ b/arch/x86/mm/init_64.c
28540@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28541 * around without checking the pgd every time.
28542 */
28543
28544-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28545+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28546 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28547
28548 int force_personality32;
28549@@ -184,12 +184,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28550
28551 for (address = start; address <= end; address += PGDIR_SIZE) {
28552 const pgd_t *pgd_ref = pgd_offset_k(address);
28553+
28554+#ifdef CONFIG_PAX_PER_CPU_PGD
28555+ unsigned long cpu;
28556+#else
28557 struct page *page;
28558+#endif
28559
28560 if (pgd_none(*pgd_ref))
28561 continue;
28562
28563 spin_lock(&pgd_lock);
28564+
28565+#ifdef CONFIG_PAX_PER_CPU_PGD
28566+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28567+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28568+#else
28569 list_for_each_entry(page, &pgd_list, lru) {
28570 pgd_t *pgd;
28571 spinlock_t *pgt_lock;
28572@@ -198,6 +208,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28573 /* the pgt_lock only for Xen */
28574 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28575 spin_lock(pgt_lock);
28576+#endif
28577
28578 if (pgd_none(*pgd))
28579 set_pgd(pgd, *pgd_ref);
28580@@ -205,7 +216,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28581 BUG_ON(pgd_page_vaddr(*pgd)
28582 != pgd_page_vaddr(*pgd_ref));
28583
28584+#ifndef CONFIG_PAX_PER_CPU_PGD
28585 spin_unlock(pgt_lock);
28586+#endif
28587+
28588 }
28589 spin_unlock(&pgd_lock);
28590 }
28591@@ -238,7 +252,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28592 {
28593 if (pgd_none(*pgd)) {
28594 pud_t *pud = (pud_t *)spp_getpage();
28595- pgd_populate(&init_mm, pgd, pud);
28596+ pgd_populate_kernel(&init_mm, pgd, pud);
28597 if (pud != pud_offset(pgd, 0))
28598 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28599 pud, pud_offset(pgd, 0));
28600@@ -250,7 +264,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28601 {
28602 if (pud_none(*pud)) {
28603 pmd_t *pmd = (pmd_t *) spp_getpage();
28604- pud_populate(&init_mm, pud, pmd);
28605+ pud_populate_kernel(&init_mm, pud, pmd);
28606 if (pmd != pmd_offset(pud, 0))
28607 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28608 pmd, pmd_offset(pud, 0));
28609@@ -279,7 +293,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28610 pmd = fill_pmd(pud, vaddr);
28611 pte = fill_pte(pmd, vaddr);
28612
28613+ pax_open_kernel();
28614 set_pte(pte, new_pte);
28615+ pax_close_kernel();
28616
28617 /*
28618 * It's enough to flush this one mapping.
28619@@ -338,14 +354,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28620 pgd = pgd_offset_k((unsigned long)__va(phys));
28621 if (pgd_none(*pgd)) {
28622 pud = (pud_t *) spp_getpage();
28623- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28624- _PAGE_USER));
28625+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28626 }
28627 pud = pud_offset(pgd, (unsigned long)__va(phys));
28628 if (pud_none(*pud)) {
28629 pmd = (pmd_t *) spp_getpage();
28630- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28631- _PAGE_USER));
28632+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28633 }
28634 pmd = pmd_offset(pud, phys);
28635 BUG_ON(!pmd_none(*pmd));
28636@@ -586,7 +600,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28637 prot);
28638
28639 spin_lock(&init_mm.page_table_lock);
28640- pud_populate(&init_mm, pud, pmd);
28641+ pud_populate_kernel(&init_mm, pud, pmd);
28642 spin_unlock(&init_mm.page_table_lock);
28643 }
28644 __flush_tlb_all();
28645@@ -627,7 +641,7 @@ kernel_physical_mapping_init(unsigned long start,
28646 page_size_mask);
28647
28648 spin_lock(&init_mm.page_table_lock);
28649- pgd_populate(&init_mm, pgd, pud);
28650+ pgd_populate_kernel(&init_mm, pgd, pud);
28651 spin_unlock(&init_mm.page_table_lock);
28652 pgd_changed = true;
28653 }
28654@@ -1221,8 +1235,8 @@ int kern_addr_valid(unsigned long addr)
28655 static struct vm_area_struct gate_vma = {
28656 .vm_start = VSYSCALL_START,
28657 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28658- .vm_page_prot = PAGE_READONLY_EXEC,
28659- .vm_flags = VM_READ | VM_EXEC
28660+ .vm_page_prot = PAGE_READONLY,
28661+ .vm_flags = VM_READ
28662 };
28663
28664 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28665@@ -1256,7 +1270,7 @@ int in_gate_area_no_mm(unsigned long addr)
28666
28667 const char *arch_vma_name(struct vm_area_struct *vma)
28668 {
28669- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28670+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28671 return "[vdso]";
28672 if (vma == &gate_vma)
28673 return "[vsyscall]";
28674diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28675index 7b179b4..6bd17777 100644
28676--- a/arch/x86/mm/iomap_32.c
28677+++ b/arch/x86/mm/iomap_32.c
28678@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28679 type = kmap_atomic_idx_push();
28680 idx = type + KM_TYPE_NR * smp_processor_id();
28681 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28682+
28683+ pax_open_kernel();
28684 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28685+ pax_close_kernel();
28686+
28687 arch_flush_lazy_mmu_mode();
28688
28689 return (void *)vaddr;
28690diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28691index 9a1e658..da003f3 100644
28692--- a/arch/x86/mm/ioremap.c
28693+++ b/arch/x86/mm/ioremap.c
28694@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28695 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28696 int is_ram = page_is_ram(pfn);
28697
28698- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28699+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28700 return NULL;
28701 WARN_ON_ONCE(is_ram);
28702 }
28703@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28704 *
28705 * Caller must ensure there is only one unmapping for the same pointer.
28706 */
28707-void iounmap(volatile void __iomem *addr)
28708+void iounmap(const volatile void __iomem *addr)
28709 {
28710 struct vm_struct *p, *o;
28711
28712@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28713
28714 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28715 if (page_is_ram(start >> PAGE_SHIFT))
28716+#ifdef CONFIG_HIGHMEM
28717+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28718+#endif
28719 return __va(phys);
28720
28721 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28722@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28723 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
28724 {
28725 if (page_is_ram(phys >> PAGE_SHIFT))
28726+#ifdef CONFIG_HIGHMEM
28727+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
28728+#endif
28729 return;
28730
28731 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
28732@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
28733 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28734
28735 static __initdata int after_paging_init;
28736-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28737+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28738
28739 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28740 {
28741@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
28742 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28743
28744 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28745- memset(bm_pte, 0, sizeof(bm_pte));
28746- pmd_populate_kernel(&init_mm, pmd, bm_pte);
28747+ pmd_populate_user(&init_mm, pmd, bm_pte);
28748
28749 /*
28750 * The boot-ioremap range spans multiple pmds, for which
28751diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28752index d87dd6d..bf3fa66 100644
28753--- a/arch/x86/mm/kmemcheck/kmemcheck.c
28754+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28755@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28756 * memory (e.g. tracked pages)? For now, we need this to avoid
28757 * invoking kmemcheck for PnP BIOS calls.
28758 */
28759- if (regs->flags & X86_VM_MASK)
28760+ if (v8086_mode(regs))
28761 return false;
28762- if (regs->cs != __KERNEL_CS)
28763+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28764 return false;
28765
28766 pte = kmemcheck_pte_lookup(address);
28767diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28768index 845df68..1d8d29f 100644
28769--- a/arch/x86/mm/mmap.c
28770+++ b/arch/x86/mm/mmap.c
28771@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28772 * Leave an at least ~128 MB hole with possible stack randomization.
28773 */
28774 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28775-#define MAX_GAP (TASK_SIZE/6*5)
28776+#define MAX_GAP (pax_task_size/6*5)
28777
28778 static int mmap_is_legacy(void)
28779 {
28780@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28781 return rnd << PAGE_SHIFT;
28782 }
28783
28784-static unsigned long mmap_base(void)
28785+static unsigned long mmap_base(struct mm_struct *mm)
28786 {
28787 unsigned long gap = rlimit(RLIMIT_STACK);
28788+ unsigned long pax_task_size = TASK_SIZE;
28789+
28790+#ifdef CONFIG_PAX_SEGMEXEC
28791+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28792+ pax_task_size = SEGMEXEC_TASK_SIZE;
28793+#endif
28794
28795 if (gap < MIN_GAP)
28796 gap = MIN_GAP;
28797 else if (gap > MAX_GAP)
28798 gap = MAX_GAP;
28799
28800- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28801+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28802 }
28803
28804 /*
28805 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28806 * does, but not when emulating X86_32
28807 */
28808-static unsigned long mmap_legacy_base(void)
28809+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28810 {
28811- if (mmap_is_ia32())
28812+ if (mmap_is_ia32()) {
28813+
28814+#ifdef CONFIG_PAX_SEGMEXEC
28815+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28816+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28817+ else
28818+#endif
28819+
28820 return TASK_UNMAPPED_BASE;
28821- else
28822+ } else
28823 return TASK_UNMAPPED_BASE + mmap_rnd();
28824 }
28825
28826@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28827 void arch_pick_mmap_layout(struct mm_struct *mm)
28828 {
28829 if (mmap_is_legacy()) {
28830- mm->mmap_base = mmap_legacy_base();
28831+ mm->mmap_base = mmap_legacy_base(mm);
28832+
28833+#ifdef CONFIG_PAX_RANDMMAP
28834+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28835+ mm->mmap_base += mm->delta_mmap;
28836+#endif
28837+
28838 mm->get_unmapped_area = arch_get_unmapped_area;
28839 mm->unmap_area = arch_unmap_area;
28840 } else {
28841- mm->mmap_base = mmap_base();
28842+ mm->mmap_base = mmap_base(mm);
28843+
28844+#ifdef CONFIG_PAX_RANDMMAP
28845+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28846+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28847+#endif
28848+
28849 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28850 mm->unmap_area = arch_unmap_area_topdown;
28851 }
28852diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28853index dc0b727..f612039 100644
28854--- a/arch/x86/mm/mmio-mod.c
28855+++ b/arch/x86/mm/mmio-mod.c
28856@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28857 break;
28858 default:
28859 {
28860- unsigned char *ip = (unsigned char *)instptr;
28861+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28862 my_trace->opcode = MMIO_UNKNOWN_OP;
28863 my_trace->width = 0;
28864 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28865@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28866 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28867 void __iomem *addr)
28868 {
28869- static atomic_t next_id;
28870+ static atomic_unchecked_t next_id;
28871 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28872 /* These are page-unaligned. */
28873 struct mmiotrace_map map = {
28874@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28875 .private = trace
28876 },
28877 .phys = offset,
28878- .id = atomic_inc_return(&next_id)
28879+ .id = atomic_inc_return_unchecked(&next_id)
28880 };
28881 map.map_id = trace->id;
28882
28883@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28884 ioremap_trace_core(offset, size, addr);
28885 }
28886
28887-static void iounmap_trace_core(volatile void __iomem *addr)
28888+static void iounmap_trace_core(const volatile void __iomem *addr)
28889 {
28890 struct mmiotrace_map map = {
28891 .phys = 0,
28892@@ -328,7 +328,7 @@ not_enabled:
28893 }
28894 }
28895
28896-void mmiotrace_iounmap(volatile void __iomem *addr)
28897+void mmiotrace_iounmap(const volatile void __iomem *addr)
28898 {
28899 might_sleep();
28900 if (is_enabled()) /* recheck and proper locking in *_core() */
28901diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
28902index a71c4e2..301ae44 100644
28903--- a/arch/x86/mm/numa.c
28904+++ b/arch/x86/mm/numa.c
28905@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
28906 return true;
28907 }
28908
28909-static int __init numa_register_memblks(struct numa_meminfo *mi)
28910+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
28911 {
28912 unsigned long uninitialized_var(pfn_align);
28913 int i, nid;
28914diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28915index d0b1773..4c3327c 100644
28916--- a/arch/x86/mm/pageattr-test.c
28917+++ b/arch/x86/mm/pageattr-test.c
28918@@ -36,7 +36,7 @@ enum {
28919
28920 static int pte_testbit(pte_t pte)
28921 {
28922- return pte_flags(pte) & _PAGE_UNUSED1;
28923+ return pte_flags(pte) & _PAGE_CPA_TEST;
28924 }
28925
28926 struct split_state {
28927diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28928index bb32480..aef8278 100644
28929--- a/arch/x86/mm/pageattr.c
28930+++ b/arch/x86/mm/pageattr.c
28931@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28932 */
28933 #ifdef CONFIG_PCI_BIOS
28934 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28935- pgprot_val(forbidden) |= _PAGE_NX;
28936+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28937 #endif
28938
28939 /*
28940@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28941 * Does not cover __inittext since that is gone later on. On
28942 * 64bit we do not enforce !NX on the low mapping
28943 */
28944- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28945- pgprot_val(forbidden) |= _PAGE_NX;
28946+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28947+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28948
28949+#ifdef CONFIG_DEBUG_RODATA
28950 /*
28951 * The .rodata section needs to be read-only. Using the pfn
28952 * catches all aliases.
28953@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28954 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
28955 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
28956 pgprot_val(forbidden) |= _PAGE_RW;
28957+#endif
28958
28959 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28960 /*
28961@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28962 }
28963 #endif
28964
28965+#ifdef CONFIG_PAX_KERNEXEC
28966+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28967+ pgprot_val(forbidden) |= _PAGE_RW;
28968+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28969+ }
28970+#endif
28971+
28972 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28973
28974 return prot;
28975@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
28976 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28977 {
28978 /* change init_mm */
28979+ pax_open_kernel();
28980 set_pte_atomic(kpte, pte);
28981+
28982 #ifdef CONFIG_X86_32
28983 if (!SHARED_KERNEL_PMD) {
28984+
28985+#ifdef CONFIG_PAX_PER_CPU_PGD
28986+ unsigned long cpu;
28987+#else
28988 struct page *page;
28989+#endif
28990
28991+#ifdef CONFIG_PAX_PER_CPU_PGD
28992+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28993+ pgd_t *pgd = get_cpu_pgd(cpu);
28994+#else
28995 list_for_each_entry(page, &pgd_list, lru) {
28996- pgd_t *pgd;
28997+ pgd_t *pgd = (pgd_t *)page_address(page);
28998+#endif
28999+
29000 pud_t *pud;
29001 pmd_t *pmd;
29002
29003- pgd = (pgd_t *)page_address(page) + pgd_index(address);
29004+ pgd += pgd_index(address);
29005 pud = pud_offset(pgd, address);
29006 pmd = pmd_offset(pud, address);
29007 set_pte_atomic((pte_t *)pmd, pte);
29008 }
29009 }
29010 #endif
29011+ pax_close_kernel();
29012 }
29013
29014 static int
29015diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
29016index 6574388..87e9bef 100644
29017--- a/arch/x86/mm/pat.c
29018+++ b/arch/x86/mm/pat.c
29019@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
29020
29021 if (!entry) {
29022 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
29023- current->comm, current->pid, start, end - 1);
29024+ current->comm, task_pid_nr(current), start, end - 1);
29025 return -EINVAL;
29026 }
29027
29028@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29029
29030 while (cursor < to) {
29031 if (!devmem_is_allowed(pfn)) {
29032- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
29033- current->comm, from, to - 1);
29034+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
29035+ current->comm, from, to - 1, cursor);
29036 return 0;
29037 }
29038 cursor += PAGE_SIZE;
29039@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
29040 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
29041 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
29042 "for [mem %#010Lx-%#010Lx]\n",
29043- current->comm, current->pid,
29044+ current->comm, task_pid_nr(current),
29045 cattr_name(flags),
29046 base, (unsigned long long)(base + size-1));
29047 return -EINVAL;
29048@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29049 flags = lookup_memtype(paddr);
29050 if (want_flags != flags) {
29051 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
29052- current->comm, current->pid,
29053+ current->comm, task_pid_nr(current),
29054 cattr_name(want_flags),
29055 (unsigned long long)paddr,
29056 (unsigned long long)(paddr + size - 1),
29057@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29058 free_memtype(paddr, paddr + size);
29059 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
29060 " for [mem %#010Lx-%#010Lx], got %s\n",
29061- current->comm, current->pid,
29062+ current->comm, task_pid_nr(current),
29063 cattr_name(want_flags),
29064 (unsigned long long)paddr,
29065 (unsigned long long)(paddr + size - 1),
29066diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
29067index 415f6c4..d319983 100644
29068--- a/arch/x86/mm/pat_rbtree.c
29069+++ b/arch/x86/mm/pat_rbtree.c
29070@@ -160,7 +160,7 @@ success:
29071
29072 failure:
29073 printk(KERN_INFO "%s:%d conflicting memory types "
29074- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
29075+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
29076 end, cattr_name(found_type), cattr_name(match->type));
29077 return -EBUSY;
29078 }
29079diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
29080index 9f0614d..92ae64a 100644
29081--- a/arch/x86/mm/pf_in.c
29082+++ b/arch/x86/mm/pf_in.c
29083@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
29084 int i;
29085 enum reason_type rv = OTHERS;
29086
29087- p = (unsigned char *)ins_addr;
29088+ p = (unsigned char *)ktla_ktva(ins_addr);
29089 p += skip_prefix(p, &prf);
29090 p += get_opcode(p, &opcode);
29091
29092@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
29093 struct prefix_bits prf;
29094 int i;
29095
29096- p = (unsigned char *)ins_addr;
29097+ p = (unsigned char *)ktla_ktva(ins_addr);
29098 p += skip_prefix(p, &prf);
29099 p += get_opcode(p, &opcode);
29100
29101@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29102 struct prefix_bits prf;
29103 int i;
29104
29105- p = (unsigned char *)ins_addr;
29106+ p = (unsigned char *)ktla_ktva(ins_addr);
29107 p += skip_prefix(p, &prf);
29108 p += get_opcode(p, &opcode);
29109
29110@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29111 struct prefix_bits prf;
29112 int i;
29113
29114- p = (unsigned char *)ins_addr;
29115+ p = (unsigned char *)ktla_ktva(ins_addr);
29116 p += skip_prefix(p, &prf);
29117 p += get_opcode(p, &opcode);
29118 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29119@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29120 struct prefix_bits prf;
29121 int i;
29122
29123- p = (unsigned char *)ins_addr;
29124+ p = (unsigned char *)ktla_ktva(ins_addr);
29125 p += skip_prefix(p, &prf);
29126 p += get_opcode(p, &opcode);
29127 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29128diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29129index 17fda6a..489c74a 100644
29130--- a/arch/x86/mm/pgtable.c
29131+++ b/arch/x86/mm/pgtable.c
29132@@ -91,10 +91,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29133 list_del(&page->lru);
29134 }
29135
29136-#define UNSHARED_PTRS_PER_PGD \
29137- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29138+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29139+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29140
29141+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29142+{
29143+ unsigned int count = USER_PGD_PTRS;
29144
29145+ while (count--)
29146+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29147+}
29148+#endif
29149+
29150+#ifdef CONFIG_PAX_PER_CPU_PGD
29151+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29152+{
29153+ unsigned int count = USER_PGD_PTRS;
29154+
29155+ while (count--) {
29156+ pgd_t pgd;
29157+
29158+#ifdef CONFIG_X86_64
29159+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29160+#else
29161+ pgd = *src++;
29162+#endif
29163+
29164+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29165+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29166+#endif
29167+
29168+ *dst++ = pgd;
29169+ }
29170+
29171+}
29172+#endif
29173+
29174+#ifdef CONFIG_X86_64
29175+#define pxd_t pud_t
29176+#define pyd_t pgd_t
29177+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29178+#define pxd_free(mm, pud) pud_free((mm), (pud))
29179+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29180+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29181+#define PYD_SIZE PGDIR_SIZE
29182+#else
29183+#define pxd_t pmd_t
29184+#define pyd_t pud_t
29185+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29186+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29187+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29188+#define pyd_offset(mm, address) pud_offset((mm), (address))
29189+#define PYD_SIZE PUD_SIZE
29190+#endif
29191+
29192+#ifdef CONFIG_PAX_PER_CPU_PGD
29193+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29194+static inline void pgd_dtor(pgd_t *pgd) {}
29195+#else
29196 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29197 {
29198 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29199@@ -135,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd)
29200 pgd_list_del(pgd);
29201 spin_unlock(&pgd_lock);
29202 }
29203+#endif
29204
29205 /*
29206 * List of all pgd's needed for non-PAE so it can invalidate entries
29207@@ -147,7 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
29208 * -- nyc
29209 */
29210
29211-#ifdef CONFIG_X86_PAE
29212+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29213 /*
29214 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29215 * updating the top-level pagetable entries to guarantee the
29216@@ -159,7 +214,7 @@ static void pgd_dtor(pgd_t *pgd)
29217 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29218 * and initialize the kernel pmds here.
29219 */
29220-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29221+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29222
29223 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29224 {
29225@@ -177,36 +232,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29226 */
29227 flush_tlb_mm(mm);
29228 }
29229+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29230+#define PREALLOCATED_PXDS USER_PGD_PTRS
29231 #else /* !CONFIG_X86_PAE */
29232
29233 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29234-#define PREALLOCATED_PMDS 0
29235+#define PREALLOCATED_PXDS 0
29236
29237 #endif /* CONFIG_X86_PAE */
29238
29239-static void free_pmds(pmd_t *pmds[])
29240+static void free_pxds(pxd_t *pxds[])
29241 {
29242 int i;
29243
29244- for(i = 0; i < PREALLOCATED_PMDS; i++)
29245- if (pmds[i])
29246- free_page((unsigned long)pmds[i]);
29247+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29248+ if (pxds[i])
29249+ free_page((unsigned long)pxds[i]);
29250 }
29251
29252-static int preallocate_pmds(pmd_t *pmds[])
29253+static int preallocate_pxds(pxd_t *pxds[])
29254 {
29255 int i;
29256 bool failed = false;
29257
29258- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29259- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29260- if (pmd == NULL)
29261+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29262+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29263+ if (pxd == NULL)
29264 failed = true;
29265- pmds[i] = pmd;
29266+ pxds[i] = pxd;
29267 }
29268
29269 if (failed) {
29270- free_pmds(pmds);
29271+ free_pxds(pxds);
29272 return -ENOMEM;
29273 }
29274
29275@@ -219,51 +276,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29276 * preallocate which never got a corresponding vma will need to be
29277 * freed manually.
29278 */
29279-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29280+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29281 {
29282 int i;
29283
29284- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29285+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29286 pgd_t pgd = pgdp[i];
29287
29288 if (pgd_val(pgd) != 0) {
29289- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29290+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29291
29292- pgdp[i] = native_make_pgd(0);
29293+ set_pgd(pgdp + i, native_make_pgd(0));
29294
29295- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29296- pmd_free(mm, pmd);
29297+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29298+ pxd_free(mm, pxd);
29299 }
29300 }
29301 }
29302
29303-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29304+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29305 {
29306- pud_t *pud;
29307+ pyd_t *pyd;
29308 unsigned long addr;
29309 int i;
29310
29311- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29312+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29313 return;
29314
29315- pud = pud_offset(pgd, 0);
29316+#ifdef CONFIG_X86_64
29317+ pyd = pyd_offset(mm, 0L);
29318+#else
29319+ pyd = pyd_offset(pgd, 0L);
29320+#endif
29321
29322- for (addr = i = 0; i < PREALLOCATED_PMDS;
29323- i++, pud++, addr += PUD_SIZE) {
29324- pmd_t *pmd = pmds[i];
29325+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29326+ i++, pyd++, addr += PYD_SIZE) {
29327+ pxd_t *pxd = pxds[i];
29328
29329 if (i >= KERNEL_PGD_BOUNDARY)
29330- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29331- sizeof(pmd_t) * PTRS_PER_PMD);
29332+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29333+ sizeof(pxd_t) * PTRS_PER_PMD);
29334
29335- pud_populate(mm, pud, pmd);
29336+ pyd_populate(mm, pyd, pxd);
29337 }
29338 }
29339
29340 pgd_t *pgd_alloc(struct mm_struct *mm)
29341 {
29342 pgd_t *pgd;
29343- pmd_t *pmds[PREALLOCATED_PMDS];
29344+ pxd_t *pxds[PREALLOCATED_PXDS];
29345
29346 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29347
29348@@ -272,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29349
29350 mm->pgd = pgd;
29351
29352- if (preallocate_pmds(pmds) != 0)
29353+ if (preallocate_pxds(pxds) != 0)
29354 goto out_free_pgd;
29355
29356 if (paravirt_pgd_alloc(mm) != 0)
29357- goto out_free_pmds;
29358+ goto out_free_pxds;
29359
29360 /*
29361 * Make sure that pre-populating the pmds is atomic with
29362@@ -286,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29363 spin_lock(&pgd_lock);
29364
29365 pgd_ctor(mm, pgd);
29366- pgd_prepopulate_pmd(mm, pgd, pmds);
29367+ pgd_prepopulate_pxd(mm, pgd, pxds);
29368
29369 spin_unlock(&pgd_lock);
29370
29371 return pgd;
29372
29373-out_free_pmds:
29374- free_pmds(pmds);
29375+out_free_pxds:
29376+ free_pxds(pxds);
29377 out_free_pgd:
29378 free_page((unsigned long)pgd);
29379 out:
29380@@ -302,7 +363,7 @@ out:
29381
29382 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29383 {
29384- pgd_mop_up_pmds(mm, pgd);
29385+ pgd_mop_up_pxds(mm, pgd);
29386 pgd_dtor(pgd);
29387 paravirt_pgd_free(mm, pgd);
29388 free_page((unsigned long)pgd);
29389diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29390index a69bcb8..19068ab 100644
29391--- a/arch/x86/mm/pgtable_32.c
29392+++ b/arch/x86/mm/pgtable_32.c
29393@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29394 return;
29395 }
29396 pte = pte_offset_kernel(pmd, vaddr);
29397+
29398+ pax_open_kernel();
29399 if (pte_val(pteval))
29400 set_pte_at(&init_mm, vaddr, pte, pteval);
29401 else
29402 pte_clear(&init_mm, vaddr, pte);
29403+ pax_close_kernel();
29404
29405 /*
29406 * It's enough to flush this one mapping.
29407diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29408index e666cbb..61788c45 100644
29409--- a/arch/x86/mm/physaddr.c
29410+++ b/arch/x86/mm/physaddr.c
29411@@ -10,7 +10,7 @@
29412 #ifdef CONFIG_X86_64
29413
29414 #ifdef CONFIG_DEBUG_VIRTUAL
29415-unsigned long __phys_addr(unsigned long x)
29416+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29417 {
29418 unsigned long y = x - __START_KERNEL_map;
29419
29420@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29421 #else
29422
29423 #ifdef CONFIG_DEBUG_VIRTUAL
29424-unsigned long __phys_addr(unsigned long x)
29425+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29426 {
29427 unsigned long phys_addr = x - PAGE_OFFSET;
29428 /* VMALLOC_* aren't constants */
29429diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29430index 410531d..0f16030 100644
29431--- a/arch/x86/mm/setup_nx.c
29432+++ b/arch/x86/mm/setup_nx.c
29433@@ -5,8 +5,10 @@
29434 #include <asm/pgtable.h>
29435 #include <asm/proto.h>
29436
29437+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29438 static int disable_nx __cpuinitdata;
29439
29440+#ifndef CONFIG_PAX_PAGEEXEC
29441 /*
29442 * noexec = on|off
29443 *
29444@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29445 return 0;
29446 }
29447 early_param("noexec", noexec_setup);
29448+#endif
29449+
29450+#endif
29451
29452 void __cpuinit x86_configure_nx(void)
29453 {
29454+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29455 if (cpu_has_nx && !disable_nx)
29456 __supported_pte_mask |= _PAGE_NX;
29457 else
29458+#endif
29459 __supported_pte_mask &= ~_PAGE_NX;
29460 }
29461
29462diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29463index 282375f..e03a98f 100644
29464--- a/arch/x86/mm/tlb.c
29465+++ b/arch/x86/mm/tlb.c
29466@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29467 BUG();
29468 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29469 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29470+
29471+#ifndef CONFIG_PAX_PER_CPU_PGD
29472 load_cr3(swapper_pg_dir);
29473+#endif
29474+
29475 }
29476 }
29477 EXPORT_SYMBOL_GPL(leave_mm);
29478diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29479index 877b9a1..a8ecf42 100644
29480--- a/arch/x86/net/bpf_jit.S
29481+++ b/arch/x86/net/bpf_jit.S
29482@@ -9,6 +9,7 @@
29483 */
29484 #include <linux/linkage.h>
29485 #include <asm/dwarf2.h>
29486+#include <asm/alternative-asm.h>
29487
29488 /*
29489 * Calling convention :
29490@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29491 jle bpf_slow_path_word
29492 mov (SKBDATA,%rsi),%eax
29493 bswap %eax /* ntohl() */
29494+ pax_force_retaddr
29495 ret
29496
29497 sk_load_half:
29498@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29499 jle bpf_slow_path_half
29500 movzwl (SKBDATA,%rsi),%eax
29501 rol $8,%ax # ntohs()
29502+ pax_force_retaddr
29503 ret
29504
29505 sk_load_byte:
29506@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29507 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29508 jle bpf_slow_path_byte
29509 movzbl (SKBDATA,%rsi),%eax
29510+ pax_force_retaddr
29511 ret
29512
29513 /**
29514@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29515 movzbl (SKBDATA,%rsi),%ebx
29516 and $15,%bl
29517 shl $2,%bl
29518+ pax_force_retaddr
29519 ret
29520
29521 /* rsi contains offset and can be scratched */
29522@@ -109,6 +114,7 @@ bpf_slow_path_word:
29523 js bpf_error
29524 mov -12(%rbp),%eax
29525 bswap %eax
29526+ pax_force_retaddr
29527 ret
29528
29529 bpf_slow_path_half:
29530@@ -117,12 +123,14 @@ bpf_slow_path_half:
29531 mov -12(%rbp),%ax
29532 rol $8,%ax
29533 movzwl %ax,%eax
29534+ pax_force_retaddr
29535 ret
29536
29537 bpf_slow_path_byte:
29538 bpf_slow_path_common(1)
29539 js bpf_error
29540 movzbl -12(%rbp),%eax
29541+ pax_force_retaddr
29542 ret
29543
29544 bpf_slow_path_byte_msh:
29545@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29546 and $15,%al
29547 shl $2,%al
29548 xchg %eax,%ebx
29549+ pax_force_retaddr
29550 ret
29551
29552 #define sk_negative_common(SIZE) \
29553@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29554 sk_negative_common(4)
29555 mov (%rax), %eax
29556 bswap %eax
29557+ pax_force_retaddr
29558 ret
29559
29560 bpf_slow_path_half_neg:
29561@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29562 mov (%rax),%ax
29563 rol $8,%ax
29564 movzwl %ax,%eax
29565+ pax_force_retaddr
29566 ret
29567
29568 bpf_slow_path_byte_neg:
29569@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29570 .globl sk_load_byte_negative_offset
29571 sk_negative_common(1)
29572 movzbl (%rax), %eax
29573+ pax_force_retaddr
29574 ret
29575
29576 bpf_slow_path_byte_msh_neg:
29577@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29578 and $15,%al
29579 shl $2,%al
29580 xchg %eax,%ebx
29581+ pax_force_retaddr
29582 ret
29583
29584 bpf_error:
29585@@ -197,4 +210,5 @@ bpf_error:
29586 xor %eax,%eax
29587 mov -8(%rbp),%rbx
29588 leaveq
29589+ pax_force_retaddr
29590 ret
29591diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29592index f66b540..3e88dfb 100644
29593--- a/arch/x86/net/bpf_jit_comp.c
29594+++ b/arch/x86/net/bpf_jit_comp.c
29595@@ -12,6 +12,7 @@
29596 #include <linux/netdevice.h>
29597 #include <linux/filter.h>
29598 #include <linux/if_vlan.h>
29599+#include <linux/random.h>
29600
29601 /*
29602 * Conventions :
29603@@ -49,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29604 return ptr + len;
29605 }
29606
29607+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29608+#define MAX_INSTR_CODE_SIZE 96
29609+#else
29610+#define MAX_INSTR_CODE_SIZE 64
29611+#endif
29612+
29613 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29614
29615 #define EMIT1(b1) EMIT(b1, 1)
29616 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29617 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29618 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29619+
29620+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29621+/* original constant will appear in ecx */
29622+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29623+do { \
29624+ /* mov ecx, randkey */ \
29625+ EMIT1(0xb9); \
29626+ EMIT(_key, 4); \
29627+ /* xor ecx, randkey ^ off */ \
29628+ EMIT2(0x81, 0xf1); \
29629+ EMIT((_key) ^ (_off), 4); \
29630+} while (0)
29631+
29632+#define EMIT1_off32(b1, _off) \
29633+do { \
29634+ switch (b1) { \
29635+ case 0x05: /* add eax, imm32 */ \
29636+ case 0x2d: /* sub eax, imm32 */ \
29637+ case 0x25: /* and eax, imm32 */ \
29638+ case 0x0d: /* or eax, imm32 */ \
29639+ case 0xb8: /* mov eax, imm32 */ \
29640+ case 0x35: /* xor eax, imm32 */ \
29641+ case 0x3d: /* cmp eax, imm32 */ \
29642+ case 0xa9: /* test eax, imm32 */ \
29643+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29644+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29645+ break; \
29646+ case 0xbb: /* mov ebx, imm32 */ \
29647+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29648+ /* mov ebx, ecx */ \
29649+ EMIT2(0x89, 0xcb); \
29650+ break; \
29651+ case 0xbe: /* mov esi, imm32 */ \
29652+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29653+ /* mov esi, ecx */ \
29654+ EMIT2(0x89, 0xce); \
29655+ break; \
29656+ case 0xe8: /* call rel imm32, always to known funcs */ \
29657+ EMIT1(b1); \
29658+ EMIT(_off, 4); \
29659+ break; \
29660+ case 0xe9: /* jmp rel imm32 */ \
29661+ EMIT1(b1); \
29662+ EMIT(_off, 4); \
29663+ /* prevent fall-through, we're not called if off = 0 */ \
29664+ EMIT(0xcccccccc, 4); \
29665+ EMIT(0xcccccccc, 4); \
29666+ break; \
29667+ default: \
29668+ BUILD_BUG(); \
29669+ } \
29670+} while (0)
29671+
29672+#define EMIT2_off32(b1, b2, _off) \
29673+do { \
29674+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29675+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29676+ EMIT(randkey, 4); \
29677+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29678+ EMIT((_off) - randkey, 4); \
29679+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29680+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29681+ /* imul eax, ecx */ \
29682+ EMIT3(0x0f, 0xaf, 0xc1); \
29683+ } else { \
29684+ BUILD_BUG(); \
29685+ } \
29686+} while (0)
29687+#else
29688 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29689+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29690+#endif
29691
29692 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29693 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29694@@ -90,6 +168,24 @@ do { \
29695 #define X86_JBE 0x76
29696 #define X86_JA 0x77
29697
29698+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29699+#define APPEND_FLOW_VERIFY() \
29700+do { \
29701+ /* mov ecx, randkey */ \
29702+ EMIT1(0xb9); \
29703+ EMIT(randkey, 4); \
29704+ /* cmp ecx, randkey */ \
29705+ EMIT2(0x81, 0xf9); \
29706+ EMIT(randkey, 4); \
29707+ /* jz after 8 int 3s */ \
29708+ EMIT2(0x74, 0x08); \
29709+ EMIT(0xcccccccc, 4); \
29710+ EMIT(0xcccccccc, 4); \
29711+} while (0)
29712+#else
29713+#define APPEND_FLOW_VERIFY() do { } while (0)
29714+#endif
29715+
29716 #define EMIT_COND_JMP(op, offset) \
29717 do { \
29718 if (is_near(offset)) \
29719@@ -97,6 +193,7 @@ do { \
29720 else { \
29721 EMIT2(0x0f, op + 0x10); \
29722 EMIT(offset, 4); /* jxx .+off32 */ \
29723+ APPEND_FLOW_VERIFY(); \
29724 } \
29725 } while (0)
29726
29727@@ -121,6 +218,11 @@ static inline void bpf_flush_icache(void *start, void *end)
29728 set_fs(old_fs);
29729 }
29730
29731+struct bpf_jit_work {
29732+ struct work_struct work;
29733+ void *image;
29734+};
29735+
29736 #define CHOOSE_LOAD_FUNC(K, func) \
29737 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29738
29739@@ -146,7 +248,7 @@ static int pkt_type_offset(void)
29740
29741 void bpf_jit_compile(struct sk_filter *fp)
29742 {
29743- u8 temp[64];
29744+ u8 temp[MAX_INSTR_CODE_SIZE];
29745 u8 *prog;
29746 unsigned int proglen, oldproglen = 0;
29747 int ilen, i;
29748@@ -159,6 +261,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29749 unsigned int *addrs;
29750 const struct sock_filter *filter = fp->insns;
29751 int flen = fp->len;
29752+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29753+ unsigned int randkey;
29754+#endif
29755
29756 if (!bpf_jit_enable)
29757 return;
29758@@ -167,11 +272,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29759 if (addrs == NULL)
29760 return;
29761
29762+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29763+ if (!fp->work)
29764+ goto out;
29765+
29766+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29767+ randkey = get_random_int();
29768+#endif
29769+
29770 /* Before first pass, make a rough estimation of addrs[]
29771- * each bpf instruction is translated to less than 64 bytes
29772+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29773 */
29774 for (proglen = 0, i = 0; i < flen; i++) {
29775- proglen += 64;
29776+ proglen += MAX_INSTR_CODE_SIZE;
29777 addrs[i] = proglen;
29778 }
29779 cleanup_addr = proglen; /* epilogue address */
29780@@ -282,10 +395,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29781 case BPF_S_ALU_MUL_K: /* A *= K */
29782 if (is_imm8(K))
29783 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29784- else {
29785- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29786- EMIT(K, 4);
29787- }
29788+ else
29789+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29790 break;
29791 case BPF_S_ALU_DIV_X: /* A /= X; */
29792 seen |= SEEN_XREG;
29793@@ -325,13 +436,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29794 break;
29795 case BPF_S_ALU_MOD_K: /* A %= K; */
29796 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29797+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29798+ DILUTE_CONST_SEQUENCE(K, randkey);
29799+#else
29800 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29801+#endif
29802 EMIT2(0xf7, 0xf1); /* div %ecx */
29803 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29804 break;
29805 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29806+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29807+ DILUTE_CONST_SEQUENCE(K, randkey);
29808+ // imul rax, rcx
29809+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29810+#else
29811 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29812 EMIT(K, 4);
29813+#endif
29814 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29815 break;
29816 case BPF_S_ALU_AND_X:
29817@@ -602,8 +723,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29818 if (is_imm8(K)) {
29819 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29820 } else {
29821- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29822- EMIT(K, 4);
29823+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29824 }
29825 } else {
29826 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29827@@ -686,17 +806,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29828 break;
29829 default:
29830 /* hmm, too complex filter, give up with jit compiler */
29831- goto out;
29832+ goto error;
29833 }
29834 ilen = prog - temp;
29835 if (image) {
29836 if (unlikely(proglen + ilen > oldproglen)) {
29837 pr_err("bpb_jit_compile fatal error\n");
29838- kfree(addrs);
29839- module_free(NULL, image);
29840- return;
29841+ module_free_exec(NULL, image);
29842+ goto error;
29843 }
29844+ pax_open_kernel();
29845 memcpy(image + proglen, temp, ilen);
29846+ pax_close_kernel();
29847 }
29848 proglen += ilen;
29849 addrs[i] = proglen;
29850@@ -717,11 +838,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29851 break;
29852 }
29853 if (proglen == oldproglen) {
29854- image = module_alloc(max_t(unsigned int,
29855- proglen,
29856- sizeof(struct work_struct)));
29857+ image = module_alloc_exec(proglen);
29858 if (!image)
29859- goto out;
29860+ goto error;
29861 }
29862 oldproglen = proglen;
29863 }
29864@@ -732,7 +851,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29865 if (image) {
29866 bpf_flush_icache(image, image + proglen);
29867 fp->bpf_func = (void *)image;
29868- }
29869+ } else
29870+error:
29871+ kfree(fp->work);
29872+
29873 out:
29874 kfree(addrs);
29875 return;
29876@@ -740,18 +862,20 @@ out:
29877
29878 static void jit_free_defer(struct work_struct *arg)
29879 {
29880- module_free(NULL, arg);
29881+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29882+ kfree(arg);
29883 }
29884
29885 /* run from softirq, we must use a work_struct to call
29886- * module_free() from process context
29887+ * module_free_exec() from process context
29888 */
29889 void bpf_jit_free(struct sk_filter *fp)
29890 {
29891 if (fp->bpf_func != sk_run_filter) {
29892- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29893+ struct work_struct *work = &fp->work->work;
29894
29895 INIT_WORK(work, jit_free_defer);
29896+ fp->work->image = fp->bpf_func;
29897 schedule_work(work);
29898 }
29899 }
29900diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29901index d6aa6e8..266395a 100644
29902--- a/arch/x86/oprofile/backtrace.c
29903+++ b/arch/x86/oprofile/backtrace.c
29904@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29905 struct stack_frame_ia32 *fp;
29906 unsigned long bytes;
29907
29908- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29909+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29910 if (bytes != sizeof(bufhead))
29911 return NULL;
29912
29913- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29914+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29915
29916 oprofile_add_trace(bufhead[0].return_address);
29917
29918@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29919 struct stack_frame bufhead[2];
29920 unsigned long bytes;
29921
29922- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29923+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29924 if (bytes != sizeof(bufhead))
29925 return NULL;
29926
29927@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29928 {
29929 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29930
29931- if (!user_mode_vm(regs)) {
29932+ if (!user_mode(regs)) {
29933 unsigned long stack = kernel_stack_pointer(regs);
29934 if (depth)
29935 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29936diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29937index 48768df..ba9143c 100644
29938--- a/arch/x86/oprofile/nmi_int.c
29939+++ b/arch/x86/oprofile/nmi_int.c
29940@@ -23,6 +23,7 @@
29941 #include <asm/nmi.h>
29942 #include <asm/msr.h>
29943 #include <asm/apic.h>
29944+#include <asm/pgtable.h>
29945
29946 #include "op_counter.h"
29947 #include "op_x86_model.h"
29948@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29949 if (ret)
29950 return ret;
29951
29952- if (!model->num_virt_counters)
29953- model->num_virt_counters = model->num_counters;
29954+ if (!model->num_virt_counters) {
29955+ pax_open_kernel();
29956+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
29957+ pax_close_kernel();
29958+ }
29959
29960 mux_init(ops);
29961
29962diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29963index b2b9443..be58856 100644
29964--- a/arch/x86/oprofile/op_model_amd.c
29965+++ b/arch/x86/oprofile/op_model_amd.c
29966@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29967 num_counters = AMD64_NUM_COUNTERS;
29968 }
29969
29970- op_amd_spec.num_counters = num_counters;
29971- op_amd_spec.num_controls = num_counters;
29972- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29973+ pax_open_kernel();
29974+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29975+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29976+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29977+ pax_close_kernel();
29978
29979 return 0;
29980 }
29981diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29982index d90528e..0127e2b 100644
29983--- a/arch/x86/oprofile/op_model_ppro.c
29984+++ b/arch/x86/oprofile/op_model_ppro.c
29985@@ -19,6 +19,7 @@
29986 #include <asm/msr.h>
29987 #include <asm/apic.h>
29988 #include <asm/nmi.h>
29989+#include <asm/pgtable.h>
29990
29991 #include "op_x86_model.h"
29992 #include "op_counter.h"
29993@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
29994
29995 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
29996
29997- op_arch_perfmon_spec.num_counters = num_counters;
29998- op_arch_perfmon_spec.num_controls = num_counters;
29999+ pax_open_kernel();
30000+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
30001+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
30002+ pax_close_kernel();
30003 }
30004
30005 static int arch_perfmon_init(struct oprofile_operations *ignore)
30006diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
30007index 71e8a67..6a313bb 100644
30008--- a/arch/x86/oprofile/op_x86_model.h
30009+++ b/arch/x86/oprofile/op_x86_model.h
30010@@ -52,7 +52,7 @@ struct op_x86_model_spec {
30011 void (*switch_ctrl)(struct op_x86_model_spec const *model,
30012 struct op_msrs const * const msrs);
30013 #endif
30014-};
30015+} __do_const;
30016
30017 struct op_counter_config;
30018
30019diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
30020index e9e6ed5..e47ae67 100644
30021--- a/arch/x86/pci/amd_bus.c
30022+++ b/arch/x86/pci/amd_bus.c
30023@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
30024 return NOTIFY_OK;
30025 }
30026
30027-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
30028+static struct notifier_block amd_cpu_notifier = {
30029 .notifier_call = amd_cpu_notify,
30030 };
30031
30032diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
30033index 372e9b8..e775a6c 100644
30034--- a/arch/x86/pci/irq.c
30035+++ b/arch/x86/pci/irq.c
30036@@ -50,7 +50,7 @@ struct irq_router {
30037 struct irq_router_handler {
30038 u16 vendor;
30039 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
30040-};
30041+} __do_const;
30042
30043 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
30044 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
30045@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
30046 return 0;
30047 }
30048
30049-static __initdata struct irq_router_handler pirq_routers[] = {
30050+static __initconst const struct irq_router_handler pirq_routers[] = {
30051 { PCI_VENDOR_ID_INTEL, intel_router_probe },
30052 { PCI_VENDOR_ID_AL, ali_router_probe },
30053 { PCI_VENDOR_ID_ITE, ite_router_probe },
30054@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
30055 static void __init pirq_find_router(struct irq_router *r)
30056 {
30057 struct irq_routing_table *rt = pirq_table;
30058- struct irq_router_handler *h;
30059+ const struct irq_router_handler *h;
30060
30061 #ifdef CONFIG_PCI_BIOS
30062 if (!rt->signature) {
30063@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
30064 return 0;
30065 }
30066
30067-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
30068+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
30069 {
30070 .callback = fix_broken_hp_bios_irq9,
30071 .ident = "HP Pavilion N5400 Series Laptop",
30072diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
30073index 6eb18c4..20d83de 100644
30074--- a/arch/x86/pci/mrst.c
30075+++ b/arch/x86/pci/mrst.c
30076@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
30077 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
30078 pci_mmcfg_late_init();
30079 pcibios_enable_irq = mrst_pci_irq_enable;
30080- pci_root_ops = pci_mrst_ops;
30081+ pax_open_kernel();
30082+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
30083+ pax_close_kernel();
30084 pci_soc_mode = 1;
30085 /* Continue with standard init */
30086 return 1;
30087diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
30088index c77b24a..c979855 100644
30089--- a/arch/x86/pci/pcbios.c
30090+++ b/arch/x86/pci/pcbios.c
30091@@ -79,7 +79,7 @@ union bios32 {
30092 static struct {
30093 unsigned long address;
30094 unsigned short segment;
30095-} bios32_indirect = { 0, __KERNEL_CS };
30096+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
30097
30098 /*
30099 * Returns the entry point for the given service, NULL on error
30100@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30101 unsigned long length; /* %ecx */
30102 unsigned long entry; /* %edx */
30103 unsigned long flags;
30104+ struct desc_struct d, *gdt;
30105
30106 local_irq_save(flags);
30107- __asm__("lcall *(%%edi); cld"
30108+
30109+ gdt = get_cpu_gdt_table(smp_processor_id());
30110+
30111+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30112+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30113+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30114+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30115+
30116+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30117 : "=a" (return_code),
30118 "=b" (address),
30119 "=c" (length),
30120 "=d" (entry)
30121 : "0" (service),
30122 "1" (0),
30123- "D" (&bios32_indirect));
30124+ "D" (&bios32_indirect),
30125+ "r"(__PCIBIOS_DS)
30126+ : "memory");
30127+
30128+ pax_open_kernel();
30129+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30130+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30131+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30132+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30133+ pax_close_kernel();
30134+
30135 local_irq_restore(flags);
30136
30137 switch (return_code) {
30138- case 0:
30139- return address + entry;
30140- case 0x80: /* Not present */
30141- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30142- return 0;
30143- default: /* Shouldn't happen */
30144- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30145- service, return_code);
30146+ case 0: {
30147+ int cpu;
30148+ unsigned char flags;
30149+
30150+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30151+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30152+ printk(KERN_WARNING "bios32_service: not valid\n");
30153 return 0;
30154+ }
30155+ address = address + PAGE_OFFSET;
30156+ length += 16UL; /* some BIOSs underreport this... */
30157+ flags = 4;
30158+ if (length >= 64*1024*1024) {
30159+ length >>= PAGE_SHIFT;
30160+ flags |= 8;
30161+ }
30162+
30163+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30164+ gdt = get_cpu_gdt_table(cpu);
30165+ pack_descriptor(&d, address, length, 0x9b, flags);
30166+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30167+ pack_descriptor(&d, address, length, 0x93, flags);
30168+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30169+ }
30170+ return entry;
30171+ }
30172+ case 0x80: /* Not present */
30173+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30174+ return 0;
30175+ default: /* Shouldn't happen */
30176+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30177+ service, return_code);
30178+ return 0;
30179 }
30180 }
30181
30182 static struct {
30183 unsigned long address;
30184 unsigned short segment;
30185-} pci_indirect = { 0, __KERNEL_CS };
30186+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30187
30188-static int pci_bios_present;
30189+static int pci_bios_present __read_only;
30190
30191 static int check_pcibios(void)
30192 {
30193@@ -131,11 +174,13 @@ static int check_pcibios(void)
30194 unsigned long flags, pcibios_entry;
30195
30196 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30197- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30198+ pci_indirect.address = pcibios_entry;
30199
30200 local_irq_save(flags);
30201- __asm__(
30202- "lcall *(%%edi); cld\n\t"
30203+ __asm__("movw %w6, %%ds\n\t"
30204+ "lcall *%%ss:(%%edi); cld\n\t"
30205+ "push %%ss\n\t"
30206+ "pop %%ds\n\t"
30207 "jc 1f\n\t"
30208 "xor %%ah, %%ah\n"
30209 "1:"
30210@@ -144,7 +189,8 @@ static int check_pcibios(void)
30211 "=b" (ebx),
30212 "=c" (ecx)
30213 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30214- "D" (&pci_indirect)
30215+ "D" (&pci_indirect),
30216+ "r" (__PCIBIOS_DS)
30217 : "memory");
30218 local_irq_restore(flags);
30219
30220@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30221
30222 switch (len) {
30223 case 1:
30224- __asm__("lcall *(%%esi); cld\n\t"
30225+ __asm__("movw %w6, %%ds\n\t"
30226+ "lcall *%%ss:(%%esi); cld\n\t"
30227+ "push %%ss\n\t"
30228+ "pop %%ds\n\t"
30229 "jc 1f\n\t"
30230 "xor %%ah, %%ah\n"
30231 "1:"
30232@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30233 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30234 "b" (bx),
30235 "D" ((long)reg),
30236- "S" (&pci_indirect));
30237+ "S" (&pci_indirect),
30238+ "r" (__PCIBIOS_DS));
30239 /*
30240 * Zero-extend the result beyond 8 bits, do not trust the
30241 * BIOS having done it:
30242@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30243 *value &= 0xff;
30244 break;
30245 case 2:
30246- __asm__("lcall *(%%esi); cld\n\t"
30247+ __asm__("movw %w6, %%ds\n\t"
30248+ "lcall *%%ss:(%%esi); cld\n\t"
30249+ "push %%ss\n\t"
30250+ "pop %%ds\n\t"
30251 "jc 1f\n\t"
30252 "xor %%ah, %%ah\n"
30253 "1:"
30254@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30255 : "1" (PCIBIOS_READ_CONFIG_WORD),
30256 "b" (bx),
30257 "D" ((long)reg),
30258- "S" (&pci_indirect));
30259+ "S" (&pci_indirect),
30260+ "r" (__PCIBIOS_DS));
30261 /*
30262 * Zero-extend the result beyond 16 bits, do not trust the
30263 * BIOS having done it:
30264@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30265 *value &= 0xffff;
30266 break;
30267 case 4:
30268- __asm__("lcall *(%%esi); cld\n\t"
30269+ __asm__("movw %w6, %%ds\n\t"
30270+ "lcall *%%ss:(%%esi); cld\n\t"
30271+ "push %%ss\n\t"
30272+ "pop %%ds\n\t"
30273 "jc 1f\n\t"
30274 "xor %%ah, %%ah\n"
30275 "1:"
30276@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30277 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30278 "b" (bx),
30279 "D" ((long)reg),
30280- "S" (&pci_indirect));
30281+ "S" (&pci_indirect),
30282+ "r" (__PCIBIOS_DS));
30283 break;
30284 }
30285
30286@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30287
30288 switch (len) {
30289 case 1:
30290- __asm__("lcall *(%%esi); cld\n\t"
30291+ __asm__("movw %w6, %%ds\n\t"
30292+ "lcall *%%ss:(%%esi); cld\n\t"
30293+ "push %%ss\n\t"
30294+ "pop %%ds\n\t"
30295 "jc 1f\n\t"
30296 "xor %%ah, %%ah\n"
30297 "1:"
30298@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30299 "c" (value),
30300 "b" (bx),
30301 "D" ((long)reg),
30302- "S" (&pci_indirect));
30303+ "S" (&pci_indirect),
30304+ "r" (__PCIBIOS_DS));
30305 break;
30306 case 2:
30307- __asm__("lcall *(%%esi); cld\n\t"
30308+ __asm__("movw %w6, %%ds\n\t"
30309+ "lcall *%%ss:(%%esi); cld\n\t"
30310+ "push %%ss\n\t"
30311+ "pop %%ds\n\t"
30312 "jc 1f\n\t"
30313 "xor %%ah, %%ah\n"
30314 "1:"
30315@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30316 "c" (value),
30317 "b" (bx),
30318 "D" ((long)reg),
30319- "S" (&pci_indirect));
30320+ "S" (&pci_indirect),
30321+ "r" (__PCIBIOS_DS));
30322 break;
30323 case 4:
30324- __asm__("lcall *(%%esi); cld\n\t"
30325+ __asm__("movw %w6, %%ds\n\t"
30326+ "lcall *%%ss:(%%esi); cld\n\t"
30327+ "push %%ss\n\t"
30328+ "pop %%ds\n\t"
30329 "jc 1f\n\t"
30330 "xor %%ah, %%ah\n"
30331 "1:"
30332@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30333 "c" (value),
30334 "b" (bx),
30335 "D" ((long)reg),
30336- "S" (&pci_indirect));
30337+ "S" (&pci_indirect),
30338+ "r" (__PCIBIOS_DS));
30339 break;
30340 }
30341
30342@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30343
30344 DBG("PCI: Fetching IRQ routing table... ");
30345 __asm__("push %%es\n\t"
30346+ "movw %w8, %%ds\n\t"
30347 "push %%ds\n\t"
30348 "pop %%es\n\t"
30349- "lcall *(%%esi); cld\n\t"
30350+ "lcall *%%ss:(%%esi); cld\n\t"
30351 "pop %%es\n\t"
30352+ "push %%ss\n\t"
30353+ "pop %%ds\n"
30354 "jc 1f\n\t"
30355 "xor %%ah, %%ah\n"
30356 "1:"
30357@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30358 "1" (0),
30359 "D" ((long) &opt),
30360 "S" (&pci_indirect),
30361- "m" (opt)
30362+ "m" (opt),
30363+ "r" (__PCIBIOS_DS)
30364 : "memory");
30365 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30366 if (ret & 0xff00)
30367@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30368 {
30369 int ret;
30370
30371- __asm__("lcall *(%%esi); cld\n\t"
30372+ __asm__("movw %w5, %%ds\n\t"
30373+ "lcall *%%ss:(%%esi); cld\n\t"
30374+ "push %%ss\n\t"
30375+ "pop %%ds\n"
30376 "jc 1f\n\t"
30377 "xor %%ah, %%ah\n"
30378 "1:"
30379@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30380 : "0" (PCIBIOS_SET_PCI_HW_INT),
30381 "b" ((dev->bus->number << 8) | dev->devfn),
30382 "c" ((irq << 8) | (pin + 10)),
30383- "S" (&pci_indirect));
30384+ "S" (&pci_indirect),
30385+ "r" (__PCIBIOS_DS));
30386 return !(ret & 0xff00);
30387 }
30388 EXPORT_SYMBOL(pcibios_set_irq_routing);
30389diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30390index 40e4469..0592924 100644
30391--- a/arch/x86/platform/efi/efi_32.c
30392+++ b/arch/x86/platform/efi/efi_32.c
30393@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30394 {
30395 struct desc_ptr gdt_descr;
30396
30397+#ifdef CONFIG_PAX_KERNEXEC
30398+ struct desc_struct d;
30399+#endif
30400+
30401 local_irq_save(efi_rt_eflags);
30402
30403 load_cr3(initial_page_table);
30404 __flush_tlb_all();
30405
30406+#ifdef CONFIG_PAX_KERNEXEC
30407+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30408+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30409+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30410+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30411+#endif
30412+
30413 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30414 gdt_descr.size = GDT_SIZE - 1;
30415 load_gdt(&gdt_descr);
30416@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
30417 {
30418 struct desc_ptr gdt_descr;
30419
30420+#ifdef CONFIG_PAX_KERNEXEC
30421+ struct desc_struct d;
30422+
30423+ memset(&d, 0, sizeof d);
30424+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30425+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30426+#endif
30427+
30428 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30429 gdt_descr.size = GDT_SIZE - 1;
30430 load_gdt(&gdt_descr);
30431
30432+#ifdef CONFIG_PAX_PER_CPU_PGD
30433+ load_cr3(get_cpu_pgd(smp_processor_id()));
30434+#else
30435 load_cr3(swapper_pg_dir);
30436+#endif
30437+
30438 __flush_tlb_all();
30439
30440 local_irq_restore(efi_rt_eflags);
30441diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
30442index 39a0e7f1..ecc2f1e 100644
30443--- a/arch/x86/platform/efi/efi_64.c
30444+++ b/arch/x86/platform/efi/efi_64.c
30445@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
30446 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
30447 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
30448 }
30449+
30450+#ifdef CONFIG_PAX_PER_CPU_PGD
30451+ load_cr3(swapper_pg_dir);
30452+#endif
30453+
30454 __flush_tlb_all();
30455 }
30456
30457@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
30458 for (pgd = 0; pgd < n_pgds; pgd++)
30459 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
30460 kfree(save_pgd);
30461+
30462+#ifdef CONFIG_PAX_PER_CPU_PGD
30463+ load_cr3(get_cpu_pgd(smp_processor_id()));
30464+#endif
30465+
30466 __flush_tlb_all();
30467 local_irq_restore(efi_flags);
30468 early_code_mapping_set_exec(0);
30469diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30470index fbe66e6..eae5e38 100644
30471--- a/arch/x86/platform/efi/efi_stub_32.S
30472+++ b/arch/x86/platform/efi/efi_stub_32.S
30473@@ -6,7 +6,9 @@
30474 */
30475
30476 #include <linux/linkage.h>
30477+#include <linux/init.h>
30478 #include <asm/page_types.h>
30479+#include <asm/segment.h>
30480
30481 /*
30482 * efi_call_phys(void *, ...) is a function with variable parameters.
30483@@ -20,7 +22,7 @@
30484 * service functions will comply with gcc calling convention, too.
30485 */
30486
30487-.text
30488+__INIT
30489 ENTRY(efi_call_phys)
30490 /*
30491 * 0. The function can only be called in Linux kernel. So CS has been
30492@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30493 * The mapping of lower virtual memory has been created in prelog and
30494 * epilog.
30495 */
30496- movl $1f, %edx
30497- subl $__PAGE_OFFSET, %edx
30498- jmp *%edx
30499+#ifdef CONFIG_PAX_KERNEXEC
30500+ movl $(__KERNEXEC_EFI_DS), %edx
30501+ mov %edx, %ds
30502+ mov %edx, %es
30503+ mov %edx, %ss
30504+ addl $2f,(1f)
30505+ ljmp *(1f)
30506+
30507+__INITDATA
30508+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30509+.previous
30510+
30511+2:
30512+ subl $2b,(1b)
30513+#else
30514+ jmp 1f-__PAGE_OFFSET
30515 1:
30516+#endif
30517
30518 /*
30519 * 2. Now on the top of stack is the return
30520@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30521 * parameter 2, ..., param n. To make things easy, we save the return
30522 * address of efi_call_phys in a global variable.
30523 */
30524- popl %edx
30525- movl %edx, saved_return_addr
30526- /* get the function pointer into ECX*/
30527- popl %ecx
30528- movl %ecx, efi_rt_function_ptr
30529- movl $2f, %edx
30530- subl $__PAGE_OFFSET, %edx
30531- pushl %edx
30532+ popl (saved_return_addr)
30533+ popl (efi_rt_function_ptr)
30534
30535 /*
30536 * 3. Clear PG bit in %CR0.
30537@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30538 /*
30539 * 5. Call the physical function.
30540 */
30541- jmp *%ecx
30542+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30543
30544-2:
30545 /*
30546 * 6. After EFI runtime service returns, control will return to
30547 * following instruction. We'd better readjust stack pointer first.
30548@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30549 movl %cr0, %edx
30550 orl $0x80000000, %edx
30551 movl %edx, %cr0
30552- jmp 1f
30553-1:
30554+
30555 /*
30556 * 8. Now restore the virtual mode from flat mode by
30557 * adding EIP with PAGE_OFFSET.
30558 */
30559- movl $1f, %edx
30560- jmp *%edx
30561+#ifdef CONFIG_PAX_KERNEXEC
30562+ movl $(__KERNEL_DS), %edx
30563+ mov %edx, %ds
30564+ mov %edx, %es
30565+ mov %edx, %ss
30566+ ljmp $(__KERNEL_CS),$1f
30567+#else
30568+ jmp 1f+__PAGE_OFFSET
30569+#endif
30570 1:
30571
30572 /*
30573 * 9. Balance the stack. And because EAX contain the return value,
30574 * we'd better not clobber it.
30575 */
30576- leal efi_rt_function_ptr, %edx
30577- movl (%edx), %ecx
30578- pushl %ecx
30579+ pushl (efi_rt_function_ptr)
30580
30581 /*
30582- * 10. Push the saved return address onto the stack and return.
30583+ * 10. Return to the saved return address.
30584 */
30585- leal saved_return_addr, %edx
30586- movl (%edx), %ecx
30587- pushl %ecx
30588- ret
30589+ jmpl *(saved_return_addr)
30590 ENDPROC(efi_call_phys)
30591 .previous
30592
30593-.data
30594+__INITDATA
30595 saved_return_addr:
30596 .long 0
30597 efi_rt_function_ptr:
30598diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30599index 4c07cca..2c8427d 100644
30600--- a/arch/x86/platform/efi/efi_stub_64.S
30601+++ b/arch/x86/platform/efi/efi_stub_64.S
30602@@ -7,6 +7,7 @@
30603 */
30604
30605 #include <linux/linkage.h>
30606+#include <asm/alternative-asm.h>
30607
30608 #define SAVE_XMM \
30609 mov %rsp, %rax; \
30610@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30611 call *%rdi
30612 addq $32, %rsp
30613 RESTORE_XMM
30614+ pax_force_retaddr 0, 1
30615 ret
30616 ENDPROC(efi_call0)
30617
30618@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30619 call *%rdi
30620 addq $32, %rsp
30621 RESTORE_XMM
30622+ pax_force_retaddr 0, 1
30623 ret
30624 ENDPROC(efi_call1)
30625
30626@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30627 call *%rdi
30628 addq $32, %rsp
30629 RESTORE_XMM
30630+ pax_force_retaddr 0, 1
30631 ret
30632 ENDPROC(efi_call2)
30633
30634@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30635 call *%rdi
30636 addq $32, %rsp
30637 RESTORE_XMM
30638+ pax_force_retaddr 0, 1
30639 ret
30640 ENDPROC(efi_call3)
30641
30642@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30643 call *%rdi
30644 addq $32, %rsp
30645 RESTORE_XMM
30646+ pax_force_retaddr 0, 1
30647 ret
30648 ENDPROC(efi_call4)
30649
30650@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30651 call *%rdi
30652 addq $48, %rsp
30653 RESTORE_XMM
30654+ pax_force_retaddr 0, 1
30655 ret
30656 ENDPROC(efi_call5)
30657
30658@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30659 call *%rdi
30660 addq $48, %rsp
30661 RESTORE_XMM
30662+ pax_force_retaddr 0, 1
30663 ret
30664 ENDPROC(efi_call6)
30665diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30666index a0a0a43..a48e233 100644
30667--- a/arch/x86/platform/mrst/mrst.c
30668+++ b/arch/x86/platform/mrst/mrst.c
30669@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30670 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30671 int sfi_mrtc_num;
30672
30673-static void mrst_power_off(void)
30674+static __noreturn void mrst_power_off(void)
30675 {
30676+ BUG();
30677 }
30678
30679-static void mrst_reboot(void)
30680+static __noreturn void mrst_reboot(void)
30681 {
30682 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30683+ BUG();
30684 }
30685
30686 /* parse all the mtimer info to a static mtimer array */
30687diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30688index d6ee929..3637cb5 100644
30689--- a/arch/x86/platform/olpc/olpc_dt.c
30690+++ b/arch/x86/platform/olpc/olpc_dt.c
30691@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30692 return res;
30693 }
30694
30695-static struct of_pdt_ops prom_olpc_ops __initdata = {
30696+static struct of_pdt_ops prom_olpc_ops __initconst = {
30697 .nextprop = olpc_dt_nextprop,
30698 .getproplen = olpc_dt_getproplen,
30699 .getproperty = olpc_dt_getproperty,
30700diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30701index 1cf5b30..fd45732 100644
30702--- a/arch/x86/power/cpu.c
30703+++ b/arch/x86/power/cpu.c
30704@@ -137,11 +137,8 @@ static void do_fpu_end(void)
30705 static void fix_processor_context(void)
30706 {
30707 int cpu = smp_processor_id();
30708- struct tss_struct *t = &per_cpu(init_tss, cpu);
30709-#ifdef CONFIG_X86_64
30710- struct desc_struct *desc = get_cpu_gdt_table(cpu);
30711- tss_desc tss;
30712-#endif
30713+ struct tss_struct *t = init_tss + cpu;
30714+
30715 set_tss_desc(cpu, t); /*
30716 * This just modifies memory; should not be
30717 * necessary. But... This is necessary, because
30718@@ -150,10 +147,6 @@ static void fix_processor_context(void)
30719 */
30720
30721 #ifdef CONFIG_X86_64
30722- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
30723- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
30724- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
30725-
30726 syscall_init(); /* This sets MSR_*STAR and related */
30727 #endif
30728 load_TR_desc(); /* This does ltr */
30729diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30730index a44f457..9140171 100644
30731--- a/arch/x86/realmode/init.c
30732+++ b/arch/x86/realmode/init.c
30733@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
30734 __va(real_mode_header->trampoline_header);
30735
30736 #ifdef CONFIG_X86_32
30737- trampoline_header->start = __pa_symbol(startup_32_smp);
30738+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
30739+
30740+#ifdef CONFIG_PAX_KERNEXEC
30741+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30742+#endif
30743+
30744+ trampoline_header->boot_cs = __BOOT_CS;
30745 trampoline_header->gdt_limit = __BOOT_DS + 7;
30746 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
30747 #else
30748@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
30749 *trampoline_cr4_features = read_cr4();
30750
30751 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
30752- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
30753+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
30754 trampoline_pgd[511] = init_level4_pgt[511].pgd;
30755 #endif
30756 }
30757diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30758index 8869287..d577672 100644
30759--- a/arch/x86/realmode/rm/Makefile
30760+++ b/arch/x86/realmode/rm/Makefile
30761@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30762 $(call cc-option, -fno-unit-at-a-time)) \
30763 $(call cc-option, -fno-stack-protector) \
30764 $(call cc-option, -mpreferred-stack-boundary=2)
30765+ifdef CONSTIFY_PLUGIN
30766+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30767+endif
30768 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30769 GCOV_PROFILE := n
30770diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30771index a28221d..93c40f1 100644
30772--- a/arch/x86/realmode/rm/header.S
30773+++ b/arch/x86/realmode/rm/header.S
30774@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30775 #endif
30776 /* APM/BIOS reboot */
30777 .long pa_machine_real_restart_asm
30778-#ifdef CONFIG_X86_64
30779+#ifdef CONFIG_X86_32
30780+ .long __KERNEL_CS
30781+#else
30782 .long __KERNEL32_CS
30783 #endif
30784 END(real_mode_header)
30785diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30786index c1b2791..f9e31c7 100644
30787--- a/arch/x86/realmode/rm/trampoline_32.S
30788+++ b/arch/x86/realmode/rm/trampoline_32.S
30789@@ -25,6 +25,12 @@
30790 #include <asm/page_types.h>
30791 #include "realmode.h"
30792
30793+#ifdef CONFIG_PAX_KERNEXEC
30794+#define ta(X) (X)
30795+#else
30796+#define ta(X) (pa_ ## X)
30797+#endif
30798+
30799 .text
30800 .code16
30801
30802@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30803
30804 cli # We should be safe anyway
30805
30806- movl tr_start, %eax # where we need to go
30807-
30808 movl $0xA5A5A5A5, trampoline_status
30809 # write marker for master knows we're running
30810
30811@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30812 movw $1, %dx # protected mode (PE) bit
30813 lmsw %dx # into protected mode
30814
30815- ljmpl $__BOOT_CS, $pa_startup_32
30816+ ljmpl *(trampoline_header)
30817
30818 .section ".text32","ax"
30819 .code32
30820@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30821 .balign 8
30822 GLOBAL(trampoline_header)
30823 tr_start: .space 4
30824- tr_gdt_pad: .space 2
30825+ tr_boot_cs: .space 2
30826 tr_gdt: .space 6
30827 END(trampoline_header)
30828
30829diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30830index bb360dc..3e5945f 100644
30831--- a/arch/x86/realmode/rm/trampoline_64.S
30832+++ b/arch/x86/realmode/rm/trampoline_64.S
30833@@ -107,7 +107,7 @@ ENTRY(startup_32)
30834 wrmsr
30835
30836 # Enable paging and in turn activate Long Mode
30837- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30838+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
30839 movl %eax, %cr0
30840
30841 /*
30842diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
30843index e812034..c747134 100644
30844--- a/arch/x86/tools/Makefile
30845+++ b/arch/x86/tools/Makefile
30846@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
30847
30848 $(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c
30849
30850-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
30851+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
30852 hostprogs-y += relocs
30853 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
30854 relocs: $(obj)/relocs
30855diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30856index f7bab68..b6d9886 100644
30857--- a/arch/x86/tools/relocs.c
30858+++ b/arch/x86/tools/relocs.c
30859@@ -1,5 +1,7 @@
30860 /* This is included from relocs_32/64.c */
30861
30862+#include "../../../include/generated/autoconf.h"
30863+
30864 #define ElfW(type) _ElfW(ELF_BITS, type)
30865 #define _ElfW(bits, type) __ElfW(bits, type)
30866 #define __ElfW(bits, type) Elf##bits##_##type
30867@@ -11,6 +13,7 @@
30868 #define Elf_Sym ElfW(Sym)
30869
30870 static Elf_Ehdr ehdr;
30871+static Elf_Phdr *phdr;
30872
30873 struct relocs {
30874 uint32_t *offset;
30875@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
30876 }
30877 }
30878
30879+static void read_phdrs(FILE *fp)
30880+{
30881+ unsigned int i;
30882+
30883+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
30884+ if (!phdr) {
30885+ die("Unable to allocate %d program headers\n",
30886+ ehdr.e_phnum);
30887+ }
30888+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30889+ die("Seek to %d failed: %s\n",
30890+ ehdr.e_phoff, strerror(errno));
30891+ }
30892+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30893+ die("Cannot read ELF program headers: %s\n",
30894+ strerror(errno));
30895+ }
30896+ for(i = 0; i < ehdr.e_phnum; i++) {
30897+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
30898+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
30899+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
30900+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
30901+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
30902+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
30903+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
30904+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
30905+ }
30906+
30907+}
30908+
30909 static void read_shdrs(FILE *fp)
30910 {
30911- int i;
30912+ unsigned int i;
30913 Elf_Shdr shdr;
30914
30915 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30916@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
30917
30918 static void read_strtabs(FILE *fp)
30919 {
30920- int i;
30921+ unsigned int i;
30922 for (i = 0; i < ehdr.e_shnum; i++) {
30923 struct section *sec = &secs[i];
30924 if (sec->shdr.sh_type != SHT_STRTAB) {
30925@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
30926
30927 static void read_symtabs(FILE *fp)
30928 {
30929- int i,j;
30930+ unsigned int i,j;
30931 for (i = 0; i < ehdr.e_shnum; i++) {
30932 struct section *sec = &secs[i];
30933 if (sec->shdr.sh_type != SHT_SYMTAB) {
30934@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
30935 }
30936
30937
30938-static void read_relocs(FILE *fp)
30939+static void read_relocs(FILE *fp, int use_real_mode)
30940 {
30941- int i,j;
30942+ unsigned int i,j;
30943+ uint32_t base;
30944+
30945 for (i = 0; i < ehdr.e_shnum; i++) {
30946 struct section *sec = &secs[i];
30947 if (sec->shdr.sh_type != SHT_REL_TYPE) {
30948@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
30949 die("Cannot read symbol table: %s\n",
30950 strerror(errno));
30951 }
30952+ base = 0;
30953+
30954+#ifdef CONFIG_X86_32
30955+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30956+ if (phdr[j].p_type != PT_LOAD )
30957+ continue;
30958+ 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)
30959+ continue;
30960+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30961+ break;
30962+ }
30963+#endif
30964+
30965 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
30966 Elf_Rel *rel = &sec->reltab[j];
30967- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
30968+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
30969 rel->r_info = elf_xword_to_cpu(rel->r_info);
30970 #if (SHT_REL_TYPE == SHT_RELA)
30971 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
30972@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
30973
30974 static void print_absolute_symbols(void)
30975 {
30976- int i;
30977+ unsigned int i;
30978 const char *format;
30979
30980 if (ELF_BITS == 64)
30981@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
30982 for (i = 0; i < ehdr.e_shnum; i++) {
30983 struct section *sec = &secs[i];
30984 char *sym_strtab;
30985- int j;
30986+ unsigned int j;
30987
30988 if (sec->shdr.sh_type != SHT_SYMTAB) {
30989 continue;
30990@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
30991
30992 static void print_absolute_relocs(void)
30993 {
30994- int i, printed = 0;
30995+ unsigned int i, printed = 0;
30996 const char *format;
30997
30998 if (ELF_BITS == 64)
30999@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
31000 struct section *sec_applies, *sec_symtab;
31001 char *sym_strtab;
31002 Elf_Sym *sh_symtab;
31003- int j;
31004+ unsigned int j;
31005 if (sec->shdr.sh_type != SHT_REL_TYPE) {
31006 continue;
31007 }
31008@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
31009 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
31010 Elf_Sym *sym, const char *symname))
31011 {
31012- int i;
31013+ unsigned int i;
31014 /* Walk through the relocations */
31015 for (i = 0; i < ehdr.e_shnum; i++) {
31016 char *sym_strtab;
31017 Elf_Sym *sh_symtab;
31018 struct section *sec_applies, *sec_symtab;
31019- int j;
31020+ unsigned int j;
31021 struct section *sec = &secs[i];
31022
31023 if (sec->shdr.sh_type != SHT_REL_TYPE) {
31024@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
31025 {
31026 unsigned r_type = ELF32_R_TYPE(rel->r_info);
31027 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
31028+ char *sym_strtab = sec->link->link->strtab;
31029+
31030+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
31031+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
31032+ return 0;
31033+
31034+#ifdef CONFIG_PAX_KERNEXEC
31035+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
31036+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
31037+ return 0;
31038+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
31039+ return 0;
31040+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
31041+ return 0;
31042+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
31043+ return 0;
31044+#endif
31045
31046 switch (r_type) {
31047 case R_386_NONE:
31048@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
31049
31050 static void emit_relocs(int as_text, int use_real_mode)
31051 {
31052- int i;
31053+ unsigned int i;
31054 int (*write_reloc)(uint32_t, FILE *) = write32;
31055 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
31056 const char *symname);
31057@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
31058 {
31059 regex_init(use_real_mode);
31060 read_ehdr(fp);
31061+ read_phdrs(fp);
31062 read_shdrs(fp);
31063 read_strtabs(fp);
31064 read_symtabs(fp);
31065- read_relocs(fp);
31066+ read_relocs(fp, use_real_mode);
31067 if (ELF_BITS == 64)
31068 percpu_init();
31069 if (show_absolute_syms) {
31070diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
31071index 80ffa5b..a33bd15 100644
31072--- a/arch/x86/um/tls_32.c
31073+++ b/arch/x86/um/tls_32.c
31074@@ -260,7 +260,7 @@ out:
31075 if (unlikely(task == current &&
31076 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
31077 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
31078- "without flushed TLS.", current->pid);
31079+ "without flushed TLS.", task_pid_nr(current));
31080 }
31081
31082 return 0;
31083diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
31084index fd14be1..e3c79c0 100644
31085--- a/arch/x86/vdso/Makefile
31086+++ b/arch/x86/vdso/Makefile
31087@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
31088 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
31089 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
31090
31091-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31092+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31093 GCOV_PROFILE := n
31094
31095 #
31096diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
31097index 0faad64..39ef157 100644
31098--- a/arch/x86/vdso/vdso32-setup.c
31099+++ b/arch/x86/vdso/vdso32-setup.c
31100@@ -25,6 +25,7 @@
31101 #include <asm/tlbflush.h>
31102 #include <asm/vdso.h>
31103 #include <asm/proto.h>
31104+#include <asm/mman.h>
31105
31106 enum {
31107 VDSO_DISABLED = 0,
31108@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
31109 void enable_sep_cpu(void)
31110 {
31111 int cpu = get_cpu();
31112- struct tss_struct *tss = &per_cpu(init_tss, cpu);
31113+ struct tss_struct *tss = init_tss + cpu;
31114
31115 if (!boot_cpu_has(X86_FEATURE_SEP)) {
31116 put_cpu();
31117@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
31118 gate_vma.vm_start = FIXADDR_USER_START;
31119 gate_vma.vm_end = FIXADDR_USER_END;
31120 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
31121- gate_vma.vm_page_prot = __P101;
31122+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
31123
31124 return 0;
31125 }
31126@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31127 if (compat)
31128 addr = VDSO_HIGH_BASE;
31129 else {
31130- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
31131+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
31132 if (IS_ERR_VALUE(addr)) {
31133 ret = addr;
31134 goto up_fail;
31135 }
31136 }
31137
31138- current->mm->context.vdso = (void *)addr;
31139+ current->mm->context.vdso = addr;
31140
31141 if (compat_uses_vma || !compat) {
31142 /*
31143@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31144 }
31145
31146 current_thread_info()->sysenter_return =
31147- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31148+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31149
31150 up_fail:
31151 if (ret)
31152- current->mm->context.vdso = NULL;
31153+ current->mm->context.vdso = 0;
31154
31155 up_write(&mm->mmap_sem);
31156
31157@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
31158
31159 const char *arch_vma_name(struct vm_area_struct *vma)
31160 {
31161- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31162+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31163 return "[vdso]";
31164+
31165+#ifdef CONFIG_PAX_SEGMEXEC
31166+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
31167+ return "[vdso]";
31168+#endif
31169+
31170 return NULL;
31171 }
31172
31173@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31174 * Check to see if the corresponding task was created in compat vdso
31175 * mode.
31176 */
31177- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
31178+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
31179 return &gate_vma;
31180 return NULL;
31181 }
31182diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
31183index 431e875..cbb23f3 100644
31184--- a/arch/x86/vdso/vma.c
31185+++ b/arch/x86/vdso/vma.c
31186@@ -16,8 +16,6 @@
31187 #include <asm/vdso.h>
31188 #include <asm/page.h>
31189
31190-unsigned int __read_mostly vdso_enabled = 1;
31191-
31192 extern char vdso_start[], vdso_end[];
31193 extern unsigned short vdso_sync_cpuid;
31194
31195@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31196 * unaligned here as a result of stack start randomization.
31197 */
31198 addr = PAGE_ALIGN(addr);
31199- addr = align_vdso_addr(addr);
31200
31201 return addr;
31202 }
31203@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31204 unsigned size)
31205 {
31206 struct mm_struct *mm = current->mm;
31207- unsigned long addr;
31208+ unsigned long addr = 0;
31209 int ret;
31210
31211- if (!vdso_enabled)
31212- return 0;
31213-
31214 down_write(&mm->mmap_sem);
31215+
31216+#ifdef CONFIG_PAX_RANDMMAP
31217+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31218+#endif
31219+
31220 addr = vdso_addr(mm->start_stack, size);
31221+ addr = align_vdso_addr(addr);
31222 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31223 if (IS_ERR_VALUE(addr)) {
31224 ret = addr;
31225 goto up_fail;
31226 }
31227
31228- current->mm->context.vdso = (void *)addr;
31229+ mm->context.vdso = addr;
31230
31231 ret = install_special_mapping(mm, addr, size,
31232 VM_READ|VM_EXEC|
31233 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31234 pages);
31235- if (ret) {
31236- current->mm->context.vdso = NULL;
31237- goto up_fail;
31238- }
31239+ if (ret)
31240+ mm->context.vdso = 0;
31241
31242 up_fail:
31243 up_write(&mm->mmap_sem);
31244@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31245 vdsox32_size);
31246 }
31247 #endif
31248-
31249-static __init int vdso_setup(char *s)
31250-{
31251- vdso_enabled = simple_strtoul(s, NULL, 0);
31252- return 0;
31253-}
31254-__setup("vdso=", vdso_setup);
31255diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31256index a492be2..08678da 100644
31257--- a/arch/x86/xen/enlighten.c
31258+++ b/arch/x86/xen/enlighten.c
31259@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31260
31261 struct shared_info xen_dummy_shared_info;
31262
31263-void *xen_initial_gdt;
31264-
31265 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31266 __read_mostly int xen_have_vector_callback;
31267 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31268@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31269 {
31270 unsigned long va = dtr->address;
31271 unsigned int size = dtr->size + 1;
31272- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31273- unsigned long frames[pages];
31274+ unsigned long frames[65536 / PAGE_SIZE];
31275 int f;
31276
31277 /*
31278@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31279 {
31280 unsigned long va = dtr->address;
31281 unsigned int size = dtr->size + 1;
31282- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31283- unsigned long frames[pages];
31284+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
31285 int f;
31286
31287 /*
31288@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31289 * 8-byte entries, or 16 4k pages..
31290 */
31291
31292- BUG_ON(size > 65536);
31293+ BUG_ON(size > GDT_SIZE);
31294 BUG_ON(va & ~PAGE_MASK);
31295
31296 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
31297@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31298 return 0;
31299 }
31300
31301-static void set_xen_basic_apic_ops(void)
31302+static void __init set_xen_basic_apic_ops(void)
31303 {
31304 apic->read = xen_apic_read;
31305 apic->write = xen_apic_write;
31306@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31307 #endif
31308 };
31309
31310-static void xen_reboot(int reason)
31311+static __noreturn void xen_reboot(int reason)
31312 {
31313 struct sched_shutdown r = { .reason = reason };
31314
31315- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31316- BUG();
31317+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31318+ BUG();
31319 }
31320
31321-static void xen_restart(char *msg)
31322+static __noreturn void xen_restart(char *msg)
31323 {
31324 xen_reboot(SHUTDOWN_reboot);
31325 }
31326
31327-static void xen_emergency_restart(void)
31328+static __noreturn void xen_emergency_restart(void)
31329 {
31330 xen_reboot(SHUTDOWN_reboot);
31331 }
31332
31333-static void xen_machine_halt(void)
31334+static __noreturn void xen_machine_halt(void)
31335 {
31336 xen_reboot(SHUTDOWN_poweroff);
31337 }
31338
31339-static void xen_machine_power_off(void)
31340+static __noreturn void xen_machine_power_off(void)
31341 {
31342 if (pm_power_off)
31343 pm_power_off();
31344@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
31345 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31346
31347 /* Work out if we support NX */
31348- x86_configure_nx();
31349+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31350+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31351+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31352+ unsigned l, h;
31353+
31354+ __supported_pte_mask |= _PAGE_NX;
31355+ rdmsr(MSR_EFER, l, h);
31356+ l |= EFER_NX;
31357+ wrmsr(MSR_EFER, l, h);
31358+ }
31359+#endif
31360
31361 xen_setup_features();
31362
31363@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
31364
31365 machine_ops = xen_machine_ops;
31366
31367- /*
31368- * The only reliable way to retain the initial address of the
31369- * percpu gdt_page is to remember it here, so we can go and
31370- * mark it RW later, when the initial percpu area is freed.
31371- */
31372- xen_initial_gdt = &per_cpu(gdt_page, 0);
31373-
31374 xen_smp_init();
31375
31376 #ifdef CONFIG_ACPI_NUMA
31377@@ -1700,7 +1699,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31378 return NOTIFY_OK;
31379 }
31380
31381-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31382+static struct notifier_block xen_hvm_cpu_notifier = {
31383 .notifier_call = xen_hvm_cpu_notify,
31384 };
31385
31386diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31387index fdc3ba2..3daee39 100644
31388--- a/arch/x86/xen/mmu.c
31389+++ b/arch/x86/xen/mmu.c
31390@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31391 /* L3_k[510] -> level2_kernel_pgt
31392 * L3_i[511] -> level2_fixmap_pgt */
31393 convert_pfn_mfn(level3_kernel_pgt);
31394+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31395+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31396+ convert_pfn_mfn(level3_vmemmap_pgt);
31397
31398 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31399 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31400@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31401 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31402 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31403 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31404+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31405+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31406+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31407 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31408 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31409+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31410 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31411 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31412
31413@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
31414 pv_mmu_ops.set_pud = xen_set_pud;
31415 #if PAGETABLE_LEVELS == 4
31416 pv_mmu_ops.set_pgd = xen_set_pgd;
31417+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31418 #endif
31419
31420 /* This will work as long as patching hasn't happened yet
31421@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31422 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31423 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31424 .set_pgd = xen_set_pgd_hyper,
31425+ .set_pgd_batched = xen_set_pgd_hyper,
31426
31427 .alloc_pud = xen_alloc_pmd_init,
31428 .release_pud = xen_release_pmd_init,
31429diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31430index d99cae8..18401e1 100644
31431--- a/arch/x86/xen/smp.c
31432+++ b/arch/x86/xen/smp.c
31433@@ -240,11 +240,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31434 {
31435 BUG_ON(smp_processor_id() != 0);
31436 native_smp_prepare_boot_cpu();
31437-
31438- /* We've switched to the "real" per-cpu gdt, so make sure the
31439- old memory can be recycled */
31440- make_lowmem_page_readwrite(xen_initial_gdt);
31441-
31442 xen_filter_cpu_maps();
31443 xen_setup_vcpu_info_placement();
31444 }
31445@@ -314,7 +309,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31446 ctxt->user_regs.ss = __KERNEL_DS;
31447 #ifdef CONFIG_X86_32
31448 ctxt->user_regs.fs = __KERNEL_PERCPU;
31449- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31450+ savesegment(gs, ctxt->user_regs.gs);
31451 #else
31452 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31453 #endif
31454@@ -324,8 +319,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31455
31456 {
31457 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
31458- ctxt->user_regs.ds = __USER_DS;
31459- ctxt->user_regs.es = __USER_DS;
31460+ ctxt->user_regs.ds = __KERNEL_DS;
31461+ ctxt->user_regs.es = __KERNEL_DS;
31462
31463 xen_copy_trap_info(ctxt->trap_ctxt);
31464
31465@@ -370,13 +365,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31466 int rc;
31467
31468 per_cpu(current_task, cpu) = idle;
31469+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31470 #ifdef CONFIG_X86_32
31471 irq_ctx_init(cpu);
31472 #else
31473 clear_tsk_thread_flag(idle, TIF_FORK);
31474- per_cpu(kernel_stack, cpu) =
31475- (unsigned long)task_stack_page(idle) -
31476- KERNEL_STACK_OFFSET + THREAD_SIZE;
31477+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31478 #endif
31479 xen_setup_runstate_info(cpu);
31480 xen_setup_timer(cpu);
31481@@ -651,7 +645,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31482
31483 void __init xen_smp_init(void)
31484 {
31485- smp_ops = xen_smp_ops;
31486+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31487 xen_fill_possible_map();
31488 xen_init_spinlocks();
31489 }
31490diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31491index 33ca6e4..0ded929 100644
31492--- a/arch/x86/xen/xen-asm_32.S
31493+++ b/arch/x86/xen/xen-asm_32.S
31494@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31495 ESP_OFFSET=4 # bytes pushed onto stack
31496
31497 /*
31498- * Store vcpu_info pointer for easy access. Do it this way to
31499- * avoid having to reload %fs
31500+ * Store vcpu_info pointer for easy access.
31501 */
31502 #ifdef CONFIG_SMP
31503- GET_THREAD_INFO(%eax)
31504- movl %ss:TI_cpu(%eax), %eax
31505- movl %ss:__per_cpu_offset(,%eax,4), %eax
31506- mov %ss:xen_vcpu(%eax), %eax
31507+ push %fs
31508+ mov $(__KERNEL_PERCPU), %eax
31509+ mov %eax, %fs
31510+ mov PER_CPU_VAR(xen_vcpu), %eax
31511+ pop %fs
31512 #else
31513 movl %ss:xen_vcpu, %eax
31514 #endif
31515diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31516index 7faed58..ba4427c 100644
31517--- a/arch/x86/xen/xen-head.S
31518+++ b/arch/x86/xen/xen-head.S
31519@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31520 #ifdef CONFIG_X86_32
31521 mov %esi,xen_start_info
31522 mov $init_thread_union+THREAD_SIZE,%esp
31523+#ifdef CONFIG_SMP
31524+ movl $cpu_gdt_table,%edi
31525+ movl $__per_cpu_load,%eax
31526+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31527+ rorl $16,%eax
31528+ movb %al,__KERNEL_PERCPU + 4(%edi)
31529+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31530+ movl $__per_cpu_end - 1,%eax
31531+ subl $__per_cpu_start,%eax
31532+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31533+#endif
31534 #else
31535 mov %rsi,xen_start_info
31536 mov $init_thread_union+THREAD_SIZE,%rsp
31537diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31538index a95b417..b6dbd0b 100644
31539--- a/arch/x86/xen/xen-ops.h
31540+++ b/arch/x86/xen/xen-ops.h
31541@@ -10,8 +10,6 @@
31542 extern const char xen_hypervisor_callback[];
31543 extern const char xen_failsafe_callback[];
31544
31545-extern void *xen_initial_gdt;
31546-
31547 struct trap_info;
31548 void xen_copy_trap_info(struct trap_info *traps);
31549
31550diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31551index 525bd3d..ef888b1 100644
31552--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31553+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31554@@ -119,9 +119,9 @@
31555 ----------------------------------------------------------------------*/
31556
31557 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31558-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31559 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31560 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31561+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31562
31563 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31564 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31565diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31566index 2f33760..835e50a 100644
31567--- a/arch/xtensa/variants/fsf/include/variant/core.h
31568+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31569@@ -11,6 +11,7 @@
31570 #ifndef _XTENSA_CORE_H
31571 #define _XTENSA_CORE_H
31572
31573+#include <linux/const.h>
31574
31575 /****************************************************************************
31576 Parameters Useful for Any Code, USER or PRIVILEGED
31577@@ -112,9 +113,9 @@
31578 ----------------------------------------------------------------------*/
31579
31580 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31581-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31582 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31583 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31584+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31585
31586 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31587 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31588diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31589index af00795..2bb8105 100644
31590--- a/arch/xtensa/variants/s6000/include/variant/core.h
31591+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31592@@ -11,6 +11,7 @@
31593 #ifndef _XTENSA_CORE_CONFIGURATION_H
31594 #define _XTENSA_CORE_CONFIGURATION_H
31595
31596+#include <linux/const.h>
31597
31598 /****************************************************************************
31599 Parameters Useful for Any Code, USER or PRIVILEGED
31600@@ -118,9 +119,9 @@
31601 ----------------------------------------------------------------------*/
31602
31603 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31604-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31605 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31606 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31607+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31608
31609 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31610 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31611diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31612index 58916af..eb9dbcf6 100644
31613--- a/block/blk-iopoll.c
31614+++ b/block/blk-iopoll.c
31615@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31616 }
31617 EXPORT_SYMBOL(blk_iopoll_complete);
31618
31619-static void blk_iopoll_softirq(struct softirq_action *h)
31620+static void blk_iopoll_softirq(void)
31621 {
31622 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31623 int rearm = 0, budget = blk_iopoll_budget;
31624@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31625 return NOTIFY_OK;
31626 }
31627
31628-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31629+static struct notifier_block blk_iopoll_cpu_notifier = {
31630 .notifier_call = blk_iopoll_cpu_notify,
31631 };
31632
31633diff --git a/block/blk-map.c b/block/blk-map.c
31634index 623e1cd..ca1e109 100644
31635--- a/block/blk-map.c
31636+++ b/block/blk-map.c
31637@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31638 if (!len || !kbuf)
31639 return -EINVAL;
31640
31641- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31642+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31643 if (do_copy)
31644 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31645 else
31646diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31647index 467c8de..f3628c5 100644
31648--- a/block/blk-softirq.c
31649+++ b/block/blk-softirq.c
31650@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31651 * Softirq action handler - move entries to local list and loop over them
31652 * while passing them to the queue registered handler.
31653 */
31654-static void blk_done_softirq(struct softirq_action *h)
31655+static void blk_done_softirq(void)
31656 {
31657 struct list_head *cpu_list, local_list;
31658
31659@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31660 return NOTIFY_OK;
31661 }
31662
31663-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31664+static struct notifier_block blk_cpu_notifier = {
31665 .notifier_call = blk_cpu_notify,
31666 };
31667
31668diff --git a/block/bsg.c b/block/bsg.c
31669index 420a5a9..23834aa 100644
31670--- a/block/bsg.c
31671+++ b/block/bsg.c
31672@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31673 struct sg_io_v4 *hdr, struct bsg_device *bd,
31674 fmode_t has_write_perm)
31675 {
31676+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31677+ unsigned char *cmdptr;
31678+
31679 if (hdr->request_len > BLK_MAX_CDB) {
31680 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31681 if (!rq->cmd)
31682 return -ENOMEM;
31683- }
31684+ cmdptr = rq->cmd;
31685+ } else
31686+ cmdptr = tmpcmd;
31687
31688- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31689+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31690 hdr->request_len))
31691 return -EFAULT;
31692
31693+ if (cmdptr != rq->cmd)
31694+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31695+
31696 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31697 if (blk_verify_command(rq->cmd, has_write_perm))
31698 return -EPERM;
31699diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31700index 7c668c8..db3521c 100644
31701--- a/block/compat_ioctl.c
31702+++ b/block/compat_ioctl.c
31703@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31704 err |= __get_user(f->spec1, &uf->spec1);
31705 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31706 err |= __get_user(name, &uf->name);
31707- f->name = compat_ptr(name);
31708+ f->name = (void __force_kernel *)compat_ptr(name);
31709 if (err) {
31710 err = -EFAULT;
31711 goto out;
31712diff --git a/block/genhd.c b/block/genhd.c
31713index cdeb527..10aa34d 100644
31714--- a/block/genhd.c
31715+++ b/block/genhd.c
31716@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
31717
31718 /*
31719 * Register device numbers dev..(dev+range-1)
31720- * range must be nonzero
31721+ * Noop if @range is zero.
31722 * The hash chain is sorted on range, so that subranges can override.
31723 */
31724 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
31725 struct kobject *(*probe)(dev_t, int *, void *),
31726 int (*lock)(dev_t, void *), void *data)
31727 {
31728- kobj_map(bdev_map, devt, range, module, probe, lock, data);
31729+ if (range)
31730+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
31731 }
31732
31733 EXPORT_SYMBOL(blk_register_region);
31734
31735+/* undo blk_register_region(), noop if @range is zero */
31736 void blk_unregister_region(dev_t devt, unsigned long range)
31737 {
31738- kobj_unmap(bdev_map, devt, range);
31739+ if (range)
31740+ kobj_unmap(bdev_map, devt, range);
31741 }
31742
31743 EXPORT_SYMBOL(blk_unregister_region);
31744diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31745index c85fc89..51e690b 100644
31746--- a/block/partitions/efi.c
31747+++ b/block/partitions/efi.c
31748@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31749 if (!gpt)
31750 return NULL;
31751
31752+ if (!le32_to_cpu(gpt->num_partition_entries))
31753+ return NULL;
31754+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31755+ if (!pte)
31756+ return NULL;
31757+
31758 count = le32_to_cpu(gpt->num_partition_entries) *
31759 le32_to_cpu(gpt->sizeof_partition_entry);
31760- if (!count)
31761- return NULL;
31762- pte = kmalloc(count, GFP_KERNEL);
31763- if (!pte)
31764- return NULL;
31765-
31766 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31767 (u8 *) pte,
31768 count) < count) {
31769diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31770index a5ffcc9..3cedc9c 100644
31771--- a/block/scsi_ioctl.c
31772+++ b/block/scsi_ioctl.c
31773@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
31774 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31775 struct sg_io_hdr *hdr, fmode_t mode)
31776 {
31777- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31778+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31779+ unsigned char *cmdptr;
31780+
31781+ if (rq->cmd != rq->__cmd)
31782+ cmdptr = rq->cmd;
31783+ else
31784+ cmdptr = tmpcmd;
31785+
31786+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31787 return -EFAULT;
31788+
31789+ if (cmdptr != rq->cmd)
31790+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31791+
31792 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31793 return -EPERM;
31794
31795@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31796 int err;
31797 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31798 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31799+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31800+ unsigned char *cmdptr;
31801
31802 if (!sic)
31803 return -EINVAL;
31804@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31805 */
31806 err = -EFAULT;
31807 rq->cmd_len = cmdlen;
31808- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31809+
31810+ if (rq->cmd != rq->__cmd)
31811+ cmdptr = rq->cmd;
31812+ else
31813+ cmdptr = tmpcmd;
31814+
31815+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31816 goto error;
31817
31818+ if (rq->cmd != cmdptr)
31819+ memcpy(rq->cmd, cmdptr, cmdlen);
31820+
31821 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31822 goto error;
31823
31824diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31825index 7bdd61b..afec999 100644
31826--- a/crypto/cryptd.c
31827+++ b/crypto/cryptd.c
31828@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31829
31830 struct cryptd_blkcipher_request_ctx {
31831 crypto_completion_t complete;
31832-};
31833+} __no_const;
31834
31835 struct cryptd_hash_ctx {
31836 struct crypto_shash *child;
31837@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31838
31839 struct cryptd_aead_request_ctx {
31840 crypto_completion_t complete;
31841-};
31842+} __no_const;
31843
31844 static void cryptd_queue_worker(struct work_struct *work);
31845
31846diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
31847index b2c99dc..476c9fb 100644
31848--- a/crypto/pcrypt.c
31849+++ b/crypto/pcrypt.c
31850@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
31851 int ret;
31852
31853 pinst->kobj.kset = pcrypt_kset;
31854- ret = kobject_add(&pinst->kobj, NULL, name);
31855+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
31856 if (!ret)
31857 kobject_uevent(&pinst->kobj, KOBJ_ADD);
31858
31859@@ -455,8 +455,8 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
31860
31861 get_online_cpus();
31862
31863- pcrypt->wq = alloc_workqueue(name,
31864- WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
31865+ pcrypt->wq = alloc_workqueue("%s",
31866+ WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1, name);
31867 if (!pcrypt->wq)
31868 goto err;
31869
31870diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31871index f220d64..d359ad6 100644
31872--- a/drivers/acpi/apei/apei-internal.h
31873+++ b/drivers/acpi/apei/apei-internal.h
31874@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31875 struct apei_exec_ins_type {
31876 u32 flags;
31877 apei_exec_ins_func_t run;
31878-};
31879+} __do_const;
31880
31881 struct apei_exec_context {
31882 u32 ip;
31883diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31884index 33dc6a0..4b24b47 100644
31885--- a/drivers/acpi/apei/cper.c
31886+++ b/drivers/acpi/apei/cper.c
31887@@ -39,12 +39,12 @@
31888 */
31889 u64 cper_next_record_id(void)
31890 {
31891- static atomic64_t seq;
31892+ static atomic64_unchecked_t seq;
31893
31894- if (!atomic64_read(&seq))
31895- atomic64_set(&seq, ((u64)get_seconds()) << 32);
31896+ if (!atomic64_read_unchecked(&seq))
31897+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31898
31899- return atomic64_inc_return(&seq);
31900+ return atomic64_inc_return_unchecked(&seq);
31901 }
31902 EXPORT_SYMBOL_GPL(cper_next_record_id);
31903
31904diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31905index be60399..778b33e8 100644
31906--- a/drivers/acpi/bgrt.c
31907+++ b/drivers/acpi/bgrt.c
31908@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31909 return -ENODEV;
31910
31911 sysfs_bin_attr_init(&image_attr);
31912- image_attr.private = bgrt_image;
31913- image_attr.size = bgrt_image_size;
31914+ pax_open_kernel();
31915+ *(void **)&image_attr.private = bgrt_image;
31916+ *(size_t *)&image_attr.size = bgrt_image_size;
31917+ pax_close_kernel();
31918
31919 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31920 if (!bgrt_kobj)
31921diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31922index cb96296..b81293b 100644
31923--- a/drivers/acpi/blacklist.c
31924+++ b/drivers/acpi/blacklist.c
31925@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31926 u32 is_critical_error;
31927 };
31928
31929-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31930+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31931
31932 /*
31933 * POLICY: If *anything* doesn't work, put it on the blacklist.
31934@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31935 return 0;
31936 }
31937
31938-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31939+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31940 {
31941 .callback = dmi_disable_osi_vista,
31942 .ident = "Fujitsu Siemens",
31943diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31944index 7586544..636a2f0 100644
31945--- a/drivers/acpi/ec_sys.c
31946+++ b/drivers/acpi/ec_sys.c
31947@@ -12,6 +12,7 @@
31948 #include <linux/acpi.h>
31949 #include <linux/debugfs.h>
31950 #include <linux/module.h>
31951+#include <linux/uaccess.h>
31952 #include "internal.h"
31953
31954 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31955@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31956 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31957 */
31958 unsigned int size = EC_SPACE_SIZE;
31959- u8 *data = (u8 *) buf;
31960+ u8 data;
31961 loff_t init_off = *off;
31962 int err = 0;
31963
31964@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31965 size = count;
31966
31967 while (size) {
31968- err = ec_read(*off, &data[*off - init_off]);
31969+ err = ec_read(*off, &data);
31970 if (err)
31971 return err;
31972+ if (put_user(data, &buf[*off - init_off]))
31973+ return -EFAULT;
31974 *off += 1;
31975 size--;
31976 }
31977@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31978
31979 unsigned int size = count;
31980 loff_t init_off = *off;
31981- u8 *data = (u8 *) buf;
31982 int err = 0;
31983
31984 if (*off >= EC_SPACE_SIZE)
31985@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31986 }
31987
31988 while (size) {
31989- u8 byte_write = data[*off - init_off];
31990+ u8 byte_write;
31991+ if (get_user(byte_write, &buf[*off - init_off]))
31992+ return -EFAULT;
31993 err = ec_write(*off, byte_write);
31994 if (err)
31995 return err;
31996diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
31997index eb133c7..f571552 100644
31998--- a/drivers/acpi/processor_idle.c
31999+++ b/drivers/acpi/processor_idle.c
32000@@ -994,7 +994,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
32001 {
32002 int i, count = CPUIDLE_DRIVER_STATE_START;
32003 struct acpi_processor_cx *cx;
32004- struct cpuidle_state *state;
32005+ cpuidle_state_no_const *state;
32006 struct cpuidle_driver *drv = &acpi_idle_driver;
32007
32008 if (!pr->flags.power_setup_done)
32009diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
32010index fcae5fa..e9f71ea 100644
32011--- a/drivers/acpi/sysfs.c
32012+++ b/drivers/acpi/sysfs.c
32013@@ -423,11 +423,11 @@ static u32 num_counters;
32014 static struct attribute **all_attrs;
32015 static u32 acpi_gpe_count;
32016
32017-static struct attribute_group interrupt_stats_attr_group = {
32018+static attribute_group_no_const interrupt_stats_attr_group = {
32019 .name = "interrupts",
32020 };
32021
32022-static struct kobj_attribute *counter_attrs;
32023+static kobj_attribute_no_const *counter_attrs;
32024
32025 static void delete_gpe_attr_array(void)
32026 {
32027diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
32028index a70ff15..f1ff44e 100644
32029--- a/drivers/ata/libahci.c
32030+++ b/drivers/ata/libahci.c
32031@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
32032 }
32033 EXPORT_SYMBOL_GPL(ahci_kick_engine);
32034
32035-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32036+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32037 struct ata_taskfile *tf, int is_cmd, u16 flags,
32038 unsigned long timeout_msec)
32039 {
32040diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
32041index adf002a..39bb8f9 100644
32042--- a/drivers/ata/libata-core.c
32043+++ b/drivers/ata/libata-core.c
32044@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
32045 struct ata_port *ap;
32046 unsigned int tag;
32047
32048- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32049+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32050 ap = qc->ap;
32051
32052 qc->flags = 0;
32053@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
32054 struct ata_port *ap;
32055 struct ata_link *link;
32056
32057- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32058+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32059 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
32060 ap = qc->ap;
32061 link = qc->dev->link;
32062@@ -5926,6 +5926,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32063 return;
32064
32065 spin_lock(&lock);
32066+ pax_open_kernel();
32067
32068 for (cur = ops->inherits; cur; cur = cur->inherits) {
32069 void **inherit = (void **)cur;
32070@@ -5939,8 +5940,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32071 if (IS_ERR(*pp))
32072 *pp = NULL;
32073
32074- ops->inherits = NULL;
32075+ *(struct ata_port_operations **)&ops->inherits = NULL;
32076
32077+ pax_close_kernel();
32078 spin_unlock(&lock);
32079 }
32080
32081diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
32082index 7638121..357a965 100644
32083--- a/drivers/ata/pata_arasan_cf.c
32084+++ b/drivers/ata/pata_arasan_cf.c
32085@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
32086 /* Handle platform specific quirks */
32087 if (quirk) {
32088 if (quirk & CF_BROKEN_PIO) {
32089- ap->ops->set_piomode = NULL;
32090+ pax_open_kernel();
32091+ *(void **)&ap->ops->set_piomode = NULL;
32092+ pax_close_kernel();
32093 ap->pio_mask = 0;
32094 }
32095 if (quirk & CF_BROKEN_MWDMA)
32096diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
32097index f9b983a..887b9d8 100644
32098--- a/drivers/atm/adummy.c
32099+++ b/drivers/atm/adummy.c
32100@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
32101 vcc->pop(vcc, skb);
32102 else
32103 dev_kfree_skb_any(skb);
32104- atomic_inc(&vcc->stats->tx);
32105+ atomic_inc_unchecked(&vcc->stats->tx);
32106
32107 return 0;
32108 }
32109diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
32110index 77a7480d..05cde58 100644
32111--- a/drivers/atm/ambassador.c
32112+++ b/drivers/atm/ambassador.c
32113@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
32114 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
32115
32116 // VC layer stats
32117- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32118+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32119
32120 // free the descriptor
32121 kfree (tx_descr);
32122@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32123 dump_skb ("<<<", vc, skb);
32124
32125 // VC layer stats
32126- atomic_inc(&atm_vcc->stats->rx);
32127+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32128 __net_timestamp(skb);
32129 // end of our responsibility
32130 atm_vcc->push (atm_vcc, skb);
32131@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32132 } else {
32133 PRINTK (KERN_INFO, "dropped over-size frame");
32134 // should we count this?
32135- atomic_inc(&atm_vcc->stats->rx_drop);
32136+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32137 }
32138
32139 } else {
32140@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
32141 }
32142
32143 if (check_area (skb->data, skb->len)) {
32144- atomic_inc(&atm_vcc->stats->tx_err);
32145+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
32146 return -ENOMEM; // ?
32147 }
32148
32149diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
32150index 0e3f8f9..765a7a5 100644
32151--- a/drivers/atm/atmtcp.c
32152+++ b/drivers/atm/atmtcp.c
32153@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32154 if (vcc->pop) vcc->pop(vcc,skb);
32155 else dev_kfree_skb(skb);
32156 if (dev_data) return 0;
32157- atomic_inc(&vcc->stats->tx_err);
32158+ atomic_inc_unchecked(&vcc->stats->tx_err);
32159 return -ENOLINK;
32160 }
32161 size = skb->len+sizeof(struct atmtcp_hdr);
32162@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32163 if (!new_skb) {
32164 if (vcc->pop) vcc->pop(vcc,skb);
32165 else dev_kfree_skb(skb);
32166- atomic_inc(&vcc->stats->tx_err);
32167+ atomic_inc_unchecked(&vcc->stats->tx_err);
32168 return -ENOBUFS;
32169 }
32170 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
32171@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32172 if (vcc->pop) vcc->pop(vcc,skb);
32173 else dev_kfree_skb(skb);
32174 out_vcc->push(out_vcc,new_skb);
32175- atomic_inc(&vcc->stats->tx);
32176- atomic_inc(&out_vcc->stats->rx);
32177+ atomic_inc_unchecked(&vcc->stats->tx);
32178+ atomic_inc_unchecked(&out_vcc->stats->rx);
32179 return 0;
32180 }
32181
32182@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32183 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32184 read_unlock(&vcc_sklist_lock);
32185 if (!out_vcc) {
32186- atomic_inc(&vcc->stats->tx_err);
32187+ atomic_inc_unchecked(&vcc->stats->tx_err);
32188 goto done;
32189 }
32190 skb_pull(skb,sizeof(struct atmtcp_hdr));
32191@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32192 __net_timestamp(new_skb);
32193 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32194 out_vcc->push(out_vcc,new_skb);
32195- atomic_inc(&vcc->stats->tx);
32196- atomic_inc(&out_vcc->stats->rx);
32197+ atomic_inc_unchecked(&vcc->stats->tx);
32198+ atomic_inc_unchecked(&out_vcc->stats->rx);
32199 done:
32200 if (vcc->pop) vcc->pop(vcc,skb);
32201 else dev_kfree_skb(skb);
32202diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
32203index b1955ba..b179940 100644
32204--- a/drivers/atm/eni.c
32205+++ b/drivers/atm/eni.c
32206@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
32207 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
32208 vcc->dev->number);
32209 length = 0;
32210- atomic_inc(&vcc->stats->rx_err);
32211+ atomic_inc_unchecked(&vcc->stats->rx_err);
32212 }
32213 else {
32214 length = ATM_CELL_SIZE-1; /* no HEC */
32215@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32216 size);
32217 }
32218 eff = length = 0;
32219- atomic_inc(&vcc->stats->rx_err);
32220+ atomic_inc_unchecked(&vcc->stats->rx_err);
32221 }
32222 else {
32223 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32224@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32225 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32226 vcc->dev->number,vcc->vci,length,size << 2,descr);
32227 length = eff = 0;
32228- atomic_inc(&vcc->stats->rx_err);
32229+ atomic_inc_unchecked(&vcc->stats->rx_err);
32230 }
32231 }
32232 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32233@@ -767,7 +767,7 @@ rx_dequeued++;
32234 vcc->push(vcc,skb);
32235 pushed++;
32236 }
32237- atomic_inc(&vcc->stats->rx);
32238+ atomic_inc_unchecked(&vcc->stats->rx);
32239 }
32240 wake_up(&eni_dev->rx_wait);
32241 }
32242@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32243 PCI_DMA_TODEVICE);
32244 if (vcc->pop) vcc->pop(vcc,skb);
32245 else dev_kfree_skb_irq(skb);
32246- atomic_inc(&vcc->stats->tx);
32247+ atomic_inc_unchecked(&vcc->stats->tx);
32248 wake_up(&eni_dev->tx_wait);
32249 dma_complete++;
32250 }
32251diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32252index b41c948..a002b17 100644
32253--- a/drivers/atm/firestream.c
32254+++ b/drivers/atm/firestream.c
32255@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32256 }
32257 }
32258
32259- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32260+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32261
32262 fs_dprintk (FS_DEBUG_TXMEM, "i");
32263 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32264@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32265 #endif
32266 skb_put (skb, qe->p1 & 0xffff);
32267 ATM_SKB(skb)->vcc = atm_vcc;
32268- atomic_inc(&atm_vcc->stats->rx);
32269+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32270 __net_timestamp(skb);
32271 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32272 atm_vcc->push (atm_vcc, skb);
32273@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32274 kfree (pe);
32275 }
32276 if (atm_vcc)
32277- atomic_inc(&atm_vcc->stats->rx_drop);
32278+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32279 break;
32280 case 0x1f: /* Reassembly abort: no buffers. */
32281 /* Silently increment error counter. */
32282 if (atm_vcc)
32283- atomic_inc(&atm_vcc->stats->rx_drop);
32284+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32285 break;
32286 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32287 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32288diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32289index 204814e..cede831 100644
32290--- a/drivers/atm/fore200e.c
32291+++ b/drivers/atm/fore200e.c
32292@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32293 #endif
32294 /* check error condition */
32295 if (*entry->status & STATUS_ERROR)
32296- atomic_inc(&vcc->stats->tx_err);
32297+ atomic_inc_unchecked(&vcc->stats->tx_err);
32298 else
32299- atomic_inc(&vcc->stats->tx);
32300+ atomic_inc_unchecked(&vcc->stats->tx);
32301 }
32302 }
32303
32304@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32305 if (skb == NULL) {
32306 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32307
32308- atomic_inc(&vcc->stats->rx_drop);
32309+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32310 return -ENOMEM;
32311 }
32312
32313@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32314
32315 dev_kfree_skb_any(skb);
32316
32317- atomic_inc(&vcc->stats->rx_drop);
32318+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32319 return -ENOMEM;
32320 }
32321
32322 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32323
32324 vcc->push(vcc, skb);
32325- atomic_inc(&vcc->stats->rx);
32326+ atomic_inc_unchecked(&vcc->stats->rx);
32327
32328 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32329
32330@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32331 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32332 fore200e->atm_dev->number,
32333 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32334- atomic_inc(&vcc->stats->rx_err);
32335+ atomic_inc_unchecked(&vcc->stats->rx_err);
32336 }
32337 }
32338
32339@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32340 goto retry_here;
32341 }
32342
32343- atomic_inc(&vcc->stats->tx_err);
32344+ atomic_inc_unchecked(&vcc->stats->tx_err);
32345
32346 fore200e->tx_sat++;
32347 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32348diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32349index 507362a..a845e57 100644
32350--- a/drivers/atm/he.c
32351+++ b/drivers/atm/he.c
32352@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32353
32354 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32355 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32356- atomic_inc(&vcc->stats->rx_drop);
32357+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32358 goto return_host_buffers;
32359 }
32360
32361@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32362 RBRQ_LEN_ERR(he_dev->rbrq_head)
32363 ? "LEN_ERR" : "",
32364 vcc->vpi, vcc->vci);
32365- atomic_inc(&vcc->stats->rx_err);
32366+ atomic_inc_unchecked(&vcc->stats->rx_err);
32367 goto return_host_buffers;
32368 }
32369
32370@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32371 vcc->push(vcc, skb);
32372 spin_lock(&he_dev->global_lock);
32373
32374- atomic_inc(&vcc->stats->rx);
32375+ atomic_inc_unchecked(&vcc->stats->rx);
32376
32377 return_host_buffers:
32378 ++pdus_assembled;
32379@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32380 tpd->vcc->pop(tpd->vcc, tpd->skb);
32381 else
32382 dev_kfree_skb_any(tpd->skb);
32383- atomic_inc(&tpd->vcc->stats->tx_err);
32384+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32385 }
32386 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32387 return;
32388@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32389 vcc->pop(vcc, skb);
32390 else
32391 dev_kfree_skb_any(skb);
32392- atomic_inc(&vcc->stats->tx_err);
32393+ atomic_inc_unchecked(&vcc->stats->tx_err);
32394 return -EINVAL;
32395 }
32396
32397@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32398 vcc->pop(vcc, skb);
32399 else
32400 dev_kfree_skb_any(skb);
32401- atomic_inc(&vcc->stats->tx_err);
32402+ atomic_inc_unchecked(&vcc->stats->tx_err);
32403 return -EINVAL;
32404 }
32405 #endif
32406@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32407 vcc->pop(vcc, skb);
32408 else
32409 dev_kfree_skb_any(skb);
32410- atomic_inc(&vcc->stats->tx_err);
32411+ atomic_inc_unchecked(&vcc->stats->tx_err);
32412 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32413 return -ENOMEM;
32414 }
32415@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32416 vcc->pop(vcc, skb);
32417 else
32418 dev_kfree_skb_any(skb);
32419- atomic_inc(&vcc->stats->tx_err);
32420+ atomic_inc_unchecked(&vcc->stats->tx_err);
32421 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32422 return -ENOMEM;
32423 }
32424@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32425 __enqueue_tpd(he_dev, tpd, cid);
32426 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32427
32428- atomic_inc(&vcc->stats->tx);
32429+ atomic_inc_unchecked(&vcc->stats->tx);
32430
32431 return 0;
32432 }
32433diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32434index 1dc0519..1aadaf7 100644
32435--- a/drivers/atm/horizon.c
32436+++ b/drivers/atm/horizon.c
32437@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32438 {
32439 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32440 // VC layer stats
32441- atomic_inc(&vcc->stats->rx);
32442+ atomic_inc_unchecked(&vcc->stats->rx);
32443 __net_timestamp(skb);
32444 // end of our responsibility
32445 vcc->push (vcc, skb);
32446@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32447 dev->tx_iovec = NULL;
32448
32449 // VC layer stats
32450- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32451+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32452
32453 // free the skb
32454 hrz_kfree_skb (skb);
32455diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32456index 272f009..a18ba55 100644
32457--- a/drivers/atm/idt77252.c
32458+++ b/drivers/atm/idt77252.c
32459@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32460 else
32461 dev_kfree_skb(skb);
32462
32463- atomic_inc(&vcc->stats->tx);
32464+ atomic_inc_unchecked(&vcc->stats->tx);
32465 }
32466
32467 atomic_dec(&scq->used);
32468@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32469 if ((sb = dev_alloc_skb(64)) == NULL) {
32470 printk("%s: Can't allocate buffers for aal0.\n",
32471 card->name);
32472- atomic_add(i, &vcc->stats->rx_drop);
32473+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32474 break;
32475 }
32476 if (!atm_charge(vcc, sb->truesize)) {
32477 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32478 card->name);
32479- atomic_add(i - 1, &vcc->stats->rx_drop);
32480+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32481 dev_kfree_skb(sb);
32482 break;
32483 }
32484@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32485 ATM_SKB(sb)->vcc = vcc;
32486 __net_timestamp(sb);
32487 vcc->push(vcc, sb);
32488- atomic_inc(&vcc->stats->rx);
32489+ atomic_inc_unchecked(&vcc->stats->rx);
32490
32491 cell += ATM_CELL_PAYLOAD;
32492 }
32493@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32494 "(CDC: %08x)\n",
32495 card->name, len, rpp->len, readl(SAR_REG_CDC));
32496 recycle_rx_pool_skb(card, rpp);
32497- atomic_inc(&vcc->stats->rx_err);
32498+ atomic_inc_unchecked(&vcc->stats->rx_err);
32499 return;
32500 }
32501 if (stat & SAR_RSQE_CRC) {
32502 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32503 recycle_rx_pool_skb(card, rpp);
32504- atomic_inc(&vcc->stats->rx_err);
32505+ atomic_inc_unchecked(&vcc->stats->rx_err);
32506 return;
32507 }
32508 if (skb_queue_len(&rpp->queue) > 1) {
32509@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32510 RXPRINTK("%s: Can't alloc RX skb.\n",
32511 card->name);
32512 recycle_rx_pool_skb(card, rpp);
32513- atomic_inc(&vcc->stats->rx_err);
32514+ atomic_inc_unchecked(&vcc->stats->rx_err);
32515 return;
32516 }
32517 if (!atm_charge(vcc, skb->truesize)) {
32518@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32519 __net_timestamp(skb);
32520
32521 vcc->push(vcc, skb);
32522- atomic_inc(&vcc->stats->rx);
32523+ atomic_inc_unchecked(&vcc->stats->rx);
32524
32525 return;
32526 }
32527@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32528 __net_timestamp(skb);
32529
32530 vcc->push(vcc, skb);
32531- atomic_inc(&vcc->stats->rx);
32532+ atomic_inc_unchecked(&vcc->stats->rx);
32533
32534 if (skb->truesize > SAR_FB_SIZE_3)
32535 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32536@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32537 if (vcc->qos.aal != ATM_AAL0) {
32538 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32539 card->name, vpi, vci);
32540- atomic_inc(&vcc->stats->rx_drop);
32541+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32542 goto drop;
32543 }
32544
32545 if ((sb = dev_alloc_skb(64)) == NULL) {
32546 printk("%s: Can't allocate buffers for AAL0.\n",
32547 card->name);
32548- atomic_inc(&vcc->stats->rx_err);
32549+ atomic_inc_unchecked(&vcc->stats->rx_err);
32550 goto drop;
32551 }
32552
32553@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32554 ATM_SKB(sb)->vcc = vcc;
32555 __net_timestamp(sb);
32556 vcc->push(vcc, sb);
32557- atomic_inc(&vcc->stats->rx);
32558+ atomic_inc_unchecked(&vcc->stats->rx);
32559
32560 drop:
32561 skb_pull(queue, 64);
32562@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32563
32564 if (vc == NULL) {
32565 printk("%s: NULL connection in send().\n", card->name);
32566- atomic_inc(&vcc->stats->tx_err);
32567+ atomic_inc_unchecked(&vcc->stats->tx_err);
32568 dev_kfree_skb(skb);
32569 return -EINVAL;
32570 }
32571 if (!test_bit(VCF_TX, &vc->flags)) {
32572 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32573- atomic_inc(&vcc->stats->tx_err);
32574+ atomic_inc_unchecked(&vcc->stats->tx_err);
32575 dev_kfree_skb(skb);
32576 return -EINVAL;
32577 }
32578@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32579 break;
32580 default:
32581 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32582- atomic_inc(&vcc->stats->tx_err);
32583+ atomic_inc_unchecked(&vcc->stats->tx_err);
32584 dev_kfree_skb(skb);
32585 return -EINVAL;
32586 }
32587
32588 if (skb_shinfo(skb)->nr_frags != 0) {
32589 printk("%s: No scatter-gather yet.\n", card->name);
32590- atomic_inc(&vcc->stats->tx_err);
32591+ atomic_inc_unchecked(&vcc->stats->tx_err);
32592 dev_kfree_skb(skb);
32593 return -EINVAL;
32594 }
32595@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32596
32597 err = queue_skb(card, vc, skb, oam);
32598 if (err) {
32599- atomic_inc(&vcc->stats->tx_err);
32600+ atomic_inc_unchecked(&vcc->stats->tx_err);
32601 dev_kfree_skb(skb);
32602 return err;
32603 }
32604@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32605 skb = dev_alloc_skb(64);
32606 if (!skb) {
32607 printk("%s: Out of memory in send_oam().\n", card->name);
32608- atomic_inc(&vcc->stats->tx_err);
32609+ atomic_inc_unchecked(&vcc->stats->tx_err);
32610 return -ENOMEM;
32611 }
32612 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32613diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32614index 4217f29..88f547a 100644
32615--- a/drivers/atm/iphase.c
32616+++ b/drivers/atm/iphase.c
32617@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32618 status = (u_short) (buf_desc_ptr->desc_mode);
32619 if (status & (RX_CER | RX_PTE | RX_OFL))
32620 {
32621- atomic_inc(&vcc->stats->rx_err);
32622+ atomic_inc_unchecked(&vcc->stats->rx_err);
32623 IF_ERR(printk("IA: bad packet, dropping it");)
32624 if (status & RX_CER) {
32625 IF_ERR(printk(" cause: packet CRC error\n");)
32626@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32627 len = dma_addr - buf_addr;
32628 if (len > iadev->rx_buf_sz) {
32629 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32630- atomic_inc(&vcc->stats->rx_err);
32631+ atomic_inc_unchecked(&vcc->stats->rx_err);
32632 goto out_free_desc;
32633 }
32634
32635@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32636 ia_vcc = INPH_IA_VCC(vcc);
32637 if (ia_vcc == NULL)
32638 {
32639- atomic_inc(&vcc->stats->rx_err);
32640+ atomic_inc_unchecked(&vcc->stats->rx_err);
32641 atm_return(vcc, skb->truesize);
32642 dev_kfree_skb_any(skb);
32643 goto INCR_DLE;
32644@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32645 if ((length > iadev->rx_buf_sz) || (length >
32646 (skb->len - sizeof(struct cpcs_trailer))))
32647 {
32648- atomic_inc(&vcc->stats->rx_err);
32649+ atomic_inc_unchecked(&vcc->stats->rx_err);
32650 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32651 length, skb->len);)
32652 atm_return(vcc, skb->truesize);
32653@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32654
32655 IF_RX(printk("rx_dle_intr: skb push");)
32656 vcc->push(vcc,skb);
32657- atomic_inc(&vcc->stats->rx);
32658+ atomic_inc_unchecked(&vcc->stats->rx);
32659 iadev->rx_pkt_cnt++;
32660 }
32661 INCR_DLE:
32662@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32663 {
32664 struct k_sonet_stats *stats;
32665 stats = &PRIV(_ia_dev[board])->sonet_stats;
32666- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32667- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32668- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32669- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32670- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32671- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32672- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32673- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32674- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32675+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32676+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32677+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32678+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32679+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32680+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32681+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32682+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32683+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32684 }
32685 ia_cmds.status = 0;
32686 break;
32687@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32688 if ((desc == 0) || (desc > iadev->num_tx_desc))
32689 {
32690 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32691- atomic_inc(&vcc->stats->tx);
32692+ atomic_inc_unchecked(&vcc->stats->tx);
32693 if (vcc->pop)
32694 vcc->pop(vcc, skb);
32695 else
32696@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32697 ATM_DESC(skb) = vcc->vci;
32698 skb_queue_tail(&iadev->tx_dma_q, skb);
32699
32700- atomic_inc(&vcc->stats->tx);
32701+ atomic_inc_unchecked(&vcc->stats->tx);
32702 iadev->tx_pkt_cnt++;
32703 /* Increment transaction counter */
32704 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32705
32706 #if 0
32707 /* add flow control logic */
32708- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32709+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32710 if (iavcc->vc_desc_cnt > 10) {
32711 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32712 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32713diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32714index fa7d701..1e404c7 100644
32715--- a/drivers/atm/lanai.c
32716+++ b/drivers/atm/lanai.c
32717@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32718 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32719 lanai_endtx(lanai, lvcc);
32720 lanai_free_skb(lvcc->tx.atmvcc, skb);
32721- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32722+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32723 }
32724
32725 /* Try to fill the buffer - don't call unless there is backlog */
32726@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32727 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32728 __net_timestamp(skb);
32729 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32730- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32731+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32732 out:
32733 lvcc->rx.buf.ptr = end;
32734 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32735@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32736 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32737 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32738 lanai->stats.service_rxnotaal5++;
32739- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32740+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32741 return 0;
32742 }
32743 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32744@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32745 int bytes;
32746 read_unlock(&vcc_sklist_lock);
32747 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32748- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32749+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32750 lvcc->stats.x.aal5.service_trash++;
32751 bytes = (SERVICE_GET_END(s) * 16) -
32752 (((unsigned long) lvcc->rx.buf.ptr) -
32753@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32754 }
32755 if (s & SERVICE_STREAM) {
32756 read_unlock(&vcc_sklist_lock);
32757- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32758+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32759 lvcc->stats.x.aal5.service_stream++;
32760 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32761 "PDU on VCI %d!\n", lanai->number, vci);
32762@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32763 return 0;
32764 }
32765 DPRINTK("got rx crc error on vci %d\n", vci);
32766- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32767+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32768 lvcc->stats.x.aal5.service_rxcrc++;
32769 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32770 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32771diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32772index 6587dc2..149833d 100644
32773--- a/drivers/atm/nicstar.c
32774+++ b/drivers/atm/nicstar.c
32775@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32776 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32777 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32778 card->index);
32779- atomic_inc(&vcc->stats->tx_err);
32780+ atomic_inc_unchecked(&vcc->stats->tx_err);
32781 dev_kfree_skb_any(skb);
32782 return -EINVAL;
32783 }
32784@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32785 if (!vc->tx) {
32786 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32787 card->index);
32788- atomic_inc(&vcc->stats->tx_err);
32789+ atomic_inc_unchecked(&vcc->stats->tx_err);
32790 dev_kfree_skb_any(skb);
32791 return -EINVAL;
32792 }
32793@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32794 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32795 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32796 card->index);
32797- atomic_inc(&vcc->stats->tx_err);
32798+ atomic_inc_unchecked(&vcc->stats->tx_err);
32799 dev_kfree_skb_any(skb);
32800 return -EINVAL;
32801 }
32802
32803 if (skb_shinfo(skb)->nr_frags != 0) {
32804 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32805- atomic_inc(&vcc->stats->tx_err);
32806+ atomic_inc_unchecked(&vcc->stats->tx_err);
32807 dev_kfree_skb_any(skb);
32808 return -EINVAL;
32809 }
32810@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32811 }
32812
32813 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32814- atomic_inc(&vcc->stats->tx_err);
32815+ atomic_inc_unchecked(&vcc->stats->tx_err);
32816 dev_kfree_skb_any(skb);
32817 return -EIO;
32818 }
32819- atomic_inc(&vcc->stats->tx);
32820+ atomic_inc_unchecked(&vcc->stats->tx);
32821
32822 return 0;
32823 }
32824@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32825 printk
32826 ("nicstar%d: Can't allocate buffers for aal0.\n",
32827 card->index);
32828- atomic_add(i, &vcc->stats->rx_drop);
32829+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32830 break;
32831 }
32832 if (!atm_charge(vcc, sb->truesize)) {
32833 RXPRINTK
32834 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32835 card->index);
32836- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32837+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32838 dev_kfree_skb_any(sb);
32839 break;
32840 }
32841@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32842 ATM_SKB(sb)->vcc = vcc;
32843 __net_timestamp(sb);
32844 vcc->push(vcc, sb);
32845- atomic_inc(&vcc->stats->rx);
32846+ atomic_inc_unchecked(&vcc->stats->rx);
32847 cell += ATM_CELL_PAYLOAD;
32848 }
32849
32850@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32851 if (iovb == NULL) {
32852 printk("nicstar%d: Out of iovec buffers.\n",
32853 card->index);
32854- atomic_inc(&vcc->stats->rx_drop);
32855+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32856 recycle_rx_buf(card, skb);
32857 return;
32858 }
32859@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32860 small or large buffer itself. */
32861 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32862 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32863- atomic_inc(&vcc->stats->rx_err);
32864+ atomic_inc_unchecked(&vcc->stats->rx_err);
32865 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32866 NS_MAX_IOVECS);
32867 NS_PRV_IOVCNT(iovb) = 0;
32868@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32869 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32870 card->index);
32871 which_list(card, skb);
32872- atomic_inc(&vcc->stats->rx_err);
32873+ atomic_inc_unchecked(&vcc->stats->rx_err);
32874 recycle_rx_buf(card, skb);
32875 vc->rx_iov = NULL;
32876 recycle_iov_buf(card, iovb);
32877@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32878 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32879 card->index);
32880 which_list(card, skb);
32881- atomic_inc(&vcc->stats->rx_err);
32882+ atomic_inc_unchecked(&vcc->stats->rx_err);
32883 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32884 NS_PRV_IOVCNT(iovb));
32885 vc->rx_iov = NULL;
32886@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32887 printk(" - PDU size mismatch.\n");
32888 else
32889 printk(".\n");
32890- atomic_inc(&vcc->stats->rx_err);
32891+ atomic_inc_unchecked(&vcc->stats->rx_err);
32892 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32893 NS_PRV_IOVCNT(iovb));
32894 vc->rx_iov = NULL;
32895@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32896 /* skb points to a small buffer */
32897 if (!atm_charge(vcc, skb->truesize)) {
32898 push_rxbufs(card, skb);
32899- atomic_inc(&vcc->stats->rx_drop);
32900+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32901 } else {
32902 skb_put(skb, len);
32903 dequeue_sm_buf(card, skb);
32904@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32905 ATM_SKB(skb)->vcc = vcc;
32906 __net_timestamp(skb);
32907 vcc->push(vcc, skb);
32908- atomic_inc(&vcc->stats->rx);
32909+ atomic_inc_unchecked(&vcc->stats->rx);
32910 }
32911 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32912 struct sk_buff *sb;
32913@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32914 if (len <= NS_SMBUFSIZE) {
32915 if (!atm_charge(vcc, sb->truesize)) {
32916 push_rxbufs(card, sb);
32917- atomic_inc(&vcc->stats->rx_drop);
32918+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32919 } else {
32920 skb_put(sb, len);
32921 dequeue_sm_buf(card, sb);
32922@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32923 ATM_SKB(sb)->vcc = vcc;
32924 __net_timestamp(sb);
32925 vcc->push(vcc, sb);
32926- atomic_inc(&vcc->stats->rx);
32927+ atomic_inc_unchecked(&vcc->stats->rx);
32928 }
32929
32930 push_rxbufs(card, skb);
32931@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32932
32933 if (!atm_charge(vcc, skb->truesize)) {
32934 push_rxbufs(card, skb);
32935- atomic_inc(&vcc->stats->rx_drop);
32936+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32937 } else {
32938 dequeue_lg_buf(card, skb);
32939 #ifdef NS_USE_DESTRUCTORS
32940@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32941 ATM_SKB(skb)->vcc = vcc;
32942 __net_timestamp(skb);
32943 vcc->push(vcc, skb);
32944- atomic_inc(&vcc->stats->rx);
32945+ atomic_inc_unchecked(&vcc->stats->rx);
32946 }
32947
32948 push_rxbufs(card, sb);
32949@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32950 printk
32951 ("nicstar%d: Out of huge buffers.\n",
32952 card->index);
32953- atomic_inc(&vcc->stats->rx_drop);
32954+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32955 recycle_iovec_rx_bufs(card,
32956 (struct iovec *)
32957 iovb->data,
32958@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32959 card->hbpool.count++;
32960 } else
32961 dev_kfree_skb_any(hb);
32962- atomic_inc(&vcc->stats->rx_drop);
32963+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32964 } else {
32965 /* Copy the small buffer to the huge buffer */
32966 sb = (struct sk_buff *)iov->iov_base;
32967@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32968 #endif /* NS_USE_DESTRUCTORS */
32969 __net_timestamp(hb);
32970 vcc->push(vcc, hb);
32971- atomic_inc(&vcc->stats->rx);
32972+ atomic_inc_unchecked(&vcc->stats->rx);
32973 }
32974 }
32975
32976diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32977index 32784d1..4a8434a 100644
32978--- a/drivers/atm/solos-pci.c
32979+++ b/drivers/atm/solos-pci.c
32980@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32981 }
32982 atm_charge(vcc, skb->truesize);
32983 vcc->push(vcc, skb);
32984- atomic_inc(&vcc->stats->rx);
32985+ atomic_inc_unchecked(&vcc->stats->rx);
32986 break;
32987
32988 case PKT_STATUS:
32989@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
32990 vcc = SKB_CB(oldskb)->vcc;
32991
32992 if (vcc) {
32993- atomic_inc(&vcc->stats->tx);
32994+ atomic_inc_unchecked(&vcc->stats->tx);
32995 solos_pop(vcc, oldskb);
32996 } else {
32997 dev_kfree_skb_irq(oldskb);
32998diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
32999index 0215934..ce9f5b1 100644
33000--- a/drivers/atm/suni.c
33001+++ b/drivers/atm/suni.c
33002@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
33003
33004
33005 #define ADD_LIMITED(s,v) \
33006- atomic_add((v),&stats->s); \
33007- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
33008+ atomic_add_unchecked((v),&stats->s); \
33009+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
33010
33011
33012 static void suni_hz(unsigned long from_timer)
33013diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
33014index 5120a96..e2572bd 100644
33015--- a/drivers/atm/uPD98402.c
33016+++ b/drivers/atm/uPD98402.c
33017@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
33018 struct sonet_stats tmp;
33019 int error = 0;
33020
33021- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33022+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33023 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
33024 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
33025 if (zero && !error) {
33026@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
33027
33028
33029 #define ADD_LIMITED(s,v) \
33030- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
33031- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
33032- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33033+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
33034+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
33035+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33036
33037
33038 static void stat_event(struct atm_dev *dev)
33039@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
33040 if (reason & uPD98402_INT_PFM) stat_event(dev);
33041 if (reason & uPD98402_INT_PCO) {
33042 (void) GET(PCOCR); /* clear interrupt cause */
33043- atomic_add(GET(HECCT),
33044+ atomic_add_unchecked(GET(HECCT),
33045 &PRIV(dev)->sonet_stats.uncorr_hcs);
33046 }
33047 if ((reason & uPD98402_INT_RFO) &&
33048@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
33049 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
33050 uPD98402_INT_LOS),PIMR); /* enable them */
33051 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
33052- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33053- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
33054- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
33055+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33056+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
33057+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
33058 return 0;
33059 }
33060
33061diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
33062index 969c3c2..9b72956 100644
33063--- a/drivers/atm/zatm.c
33064+++ b/drivers/atm/zatm.c
33065@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33066 }
33067 if (!size) {
33068 dev_kfree_skb_irq(skb);
33069- if (vcc) atomic_inc(&vcc->stats->rx_err);
33070+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
33071 continue;
33072 }
33073 if (!atm_charge(vcc,skb->truesize)) {
33074@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33075 skb->len = size;
33076 ATM_SKB(skb)->vcc = vcc;
33077 vcc->push(vcc,skb);
33078- atomic_inc(&vcc->stats->rx);
33079+ atomic_inc_unchecked(&vcc->stats->rx);
33080 }
33081 zout(pos & 0xffff,MTA(mbx));
33082 #if 0 /* probably a stupid idea */
33083@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
33084 skb_queue_head(&zatm_vcc->backlog,skb);
33085 break;
33086 }
33087- atomic_inc(&vcc->stats->tx);
33088+ atomic_inc_unchecked(&vcc->stats->tx);
33089 wake_up(&zatm_vcc->tx_wait);
33090 }
33091
33092diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
33093index d78b204..ecc1929 100644
33094--- a/drivers/base/attribute_container.c
33095+++ b/drivers/base/attribute_container.c
33096@@ -167,7 +167,7 @@ attribute_container_add_device(struct device *dev,
33097 ic->classdev.parent = get_device(dev);
33098 ic->classdev.class = cont->class;
33099 cont->class->dev_release = attribute_container_release;
33100- dev_set_name(&ic->classdev, dev_name(dev));
33101+ dev_set_name(&ic->classdev, "%s", dev_name(dev));
33102 if (fn)
33103 fn(cont, dev, &ic->classdev);
33104 else
33105diff --git a/drivers/base/bus.c b/drivers/base/bus.c
33106index d414331..b4dd4ba 100644
33107--- a/drivers/base/bus.c
33108+++ b/drivers/base/bus.c
33109@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
33110 return -EINVAL;
33111
33112 mutex_lock(&subsys->p->mutex);
33113- list_add_tail(&sif->node, &subsys->p->interfaces);
33114+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
33115 if (sif->add_dev) {
33116 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33117 while ((dev = subsys_dev_iter_next(&iter)))
33118@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
33119 subsys = sif->subsys;
33120
33121 mutex_lock(&subsys->p->mutex);
33122- list_del_init(&sif->node);
33123+ pax_list_del_init((struct list_head *)&sif->node);
33124 if (sif->remove_dev) {
33125 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33126 while ((dev = subsys_dev_iter_next(&iter)))
33127diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
33128index 7413d06..79155fa 100644
33129--- a/drivers/base/devtmpfs.c
33130+++ b/drivers/base/devtmpfs.c
33131@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
33132 if (!thread)
33133 return 0;
33134
33135- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
33136+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
33137 if (err)
33138 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
33139 else
33140@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
33141 *err = sys_unshare(CLONE_NEWNS);
33142 if (*err)
33143 goto out;
33144- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
33145+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
33146 if (*err)
33147 goto out;
33148- sys_chdir("/.."); /* will traverse into overmounted root */
33149- sys_chroot(".");
33150+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
33151+ sys_chroot((char __force_user *)".");
33152 complete(&setup_done);
33153 while (1) {
33154 spin_lock(&req_lock);
33155diff --git a/drivers/base/node.c b/drivers/base/node.c
33156index 7616a77c..8f57f51 100644
33157--- a/drivers/base/node.c
33158+++ b/drivers/base/node.c
33159@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
33160 struct node_attr {
33161 struct device_attribute attr;
33162 enum node_states state;
33163-};
33164+} __do_const;
33165
33166 static ssize_t show_node_state(struct device *dev,
33167 struct device_attribute *attr, char *buf)
33168diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
33169index 7072404..76dcebd 100644
33170--- a/drivers/base/power/domain.c
33171+++ b/drivers/base/power/domain.c
33172@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
33173 {
33174 struct cpuidle_driver *cpuidle_drv;
33175 struct gpd_cpu_data *cpu_data;
33176- struct cpuidle_state *idle_state;
33177+ cpuidle_state_no_const *idle_state;
33178 int ret = 0;
33179
33180 if (IS_ERR_OR_NULL(genpd) || state < 0)
33181@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
33182 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
33183 {
33184 struct gpd_cpu_data *cpu_data;
33185- struct cpuidle_state *idle_state;
33186+ cpuidle_state_no_const *idle_state;
33187 int ret = 0;
33188
33189 if (IS_ERR_OR_NULL(genpd))
33190diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
33191index a53ebd2..8f73eeb 100644
33192--- a/drivers/base/power/sysfs.c
33193+++ b/drivers/base/power/sysfs.c
33194@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
33195 return -EIO;
33196 }
33197 }
33198- return sprintf(buf, p);
33199+ return sprintf(buf, "%s", p);
33200 }
33201
33202 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
33203diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
33204index 79715e7..df06b3b 100644
33205--- a/drivers/base/power/wakeup.c
33206+++ b/drivers/base/power/wakeup.c
33207@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
33208 * They need to be modified together atomically, so it's better to use one
33209 * atomic variable to hold them both.
33210 */
33211-static atomic_t combined_event_count = ATOMIC_INIT(0);
33212+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
33213
33214 #define IN_PROGRESS_BITS (sizeof(int) * 4)
33215 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
33216
33217 static void split_counters(unsigned int *cnt, unsigned int *inpr)
33218 {
33219- unsigned int comb = atomic_read(&combined_event_count);
33220+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
33221
33222 *cnt = (comb >> IN_PROGRESS_BITS);
33223 *inpr = comb & MAX_IN_PROGRESS;
33224@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33225 ws->start_prevent_time = ws->last_time;
33226
33227 /* Increment the counter of events in progress. */
33228- cec = atomic_inc_return(&combined_event_count);
33229+ cec = atomic_inc_return_unchecked(&combined_event_count);
33230
33231 trace_wakeup_source_activate(ws->name, cec);
33232 }
33233@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33234 * Increment the counter of registered wakeup events and decrement the
33235 * couter of wakeup events in progress simultaneously.
33236 */
33237- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33238+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33239 trace_wakeup_source_deactivate(ws->name, cec);
33240
33241 split_counters(&cnt, &inpr);
33242diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
33243index e8d11b6..7b1b36f 100644
33244--- a/drivers/base/syscore.c
33245+++ b/drivers/base/syscore.c
33246@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
33247 void register_syscore_ops(struct syscore_ops *ops)
33248 {
33249 mutex_lock(&syscore_ops_lock);
33250- list_add_tail(&ops->node, &syscore_ops_list);
33251+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33252 mutex_unlock(&syscore_ops_lock);
33253 }
33254 EXPORT_SYMBOL_GPL(register_syscore_ops);
33255@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33256 void unregister_syscore_ops(struct syscore_ops *ops)
33257 {
33258 mutex_lock(&syscore_ops_lock);
33259- list_del(&ops->node);
33260+ pax_list_del((struct list_head *)&ops->node);
33261 mutex_unlock(&syscore_ops_lock);
33262 }
33263 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33264diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33265index 62b6c2c..4a11354 100644
33266--- a/drivers/block/cciss.c
33267+++ b/drivers/block/cciss.c
33268@@ -1189,6 +1189,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33269 int err;
33270 u32 cp;
33271
33272+ memset(&arg64, 0, sizeof(arg64));
33273+
33274 err = 0;
33275 err |=
33276 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33277@@ -3010,7 +3012,7 @@ static void start_io(ctlr_info_t *h)
33278 while (!list_empty(&h->reqQ)) {
33279 c = list_entry(h->reqQ.next, CommandList_struct, list);
33280 /* can't do anything if fifo is full */
33281- if ((h->access.fifo_full(h))) {
33282+ if ((h->access->fifo_full(h))) {
33283 dev_warn(&h->pdev->dev, "fifo full\n");
33284 break;
33285 }
33286@@ -3020,7 +3022,7 @@ static void start_io(ctlr_info_t *h)
33287 h->Qdepth--;
33288
33289 /* Tell the controller execute command */
33290- h->access.submit_command(h, c);
33291+ h->access->submit_command(h, c);
33292
33293 /* Put job onto the completed Q */
33294 addQ(&h->cmpQ, c);
33295@@ -3446,17 +3448,17 @@ startio:
33296
33297 static inline unsigned long get_next_completion(ctlr_info_t *h)
33298 {
33299- return h->access.command_completed(h);
33300+ return h->access->command_completed(h);
33301 }
33302
33303 static inline int interrupt_pending(ctlr_info_t *h)
33304 {
33305- return h->access.intr_pending(h);
33306+ return h->access->intr_pending(h);
33307 }
33308
33309 static inline long interrupt_not_for_us(ctlr_info_t *h)
33310 {
33311- return ((h->access.intr_pending(h) == 0) ||
33312+ return ((h->access->intr_pending(h) == 0) ||
33313 (h->interrupts_enabled == 0));
33314 }
33315
33316@@ -3489,7 +3491,7 @@ static inline u32 next_command(ctlr_info_t *h)
33317 u32 a;
33318
33319 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33320- return h->access.command_completed(h);
33321+ return h->access->command_completed(h);
33322
33323 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33324 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33325@@ -4046,7 +4048,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33326 trans_support & CFGTBL_Trans_use_short_tags);
33327
33328 /* Change the access methods to the performant access methods */
33329- h->access = SA5_performant_access;
33330+ h->access = &SA5_performant_access;
33331 h->transMethod = CFGTBL_Trans_Performant;
33332
33333 return;
33334@@ -4319,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33335 if (prod_index < 0)
33336 return -ENODEV;
33337 h->product_name = products[prod_index].product_name;
33338- h->access = *(products[prod_index].access);
33339+ h->access = products[prod_index].access;
33340
33341 if (cciss_board_disabled(h)) {
33342 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33343@@ -5051,7 +5053,7 @@ reinit_after_soft_reset:
33344 }
33345
33346 /* make sure the board interrupts are off */
33347- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33348+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33349 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33350 if (rc)
33351 goto clean2;
33352@@ -5101,7 +5103,7 @@ reinit_after_soft_reset:
33353 * fake ones to scoop up any residual completions.
33354 */
33355 spin_lock_irqsave(&h->lock, flags);
33356- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33357+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33358 spin_unlock_irqrestore(&h->lock, flags);
33359 free_irq(h->intr[h->intr_mode], h);
33360 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33361@@ -5121,9 +5123,9 @@ reinit_after_soft_reset:
33362 dev_info(&h->pdev->dev, "Board READY.\n");
33363 dev_info(&h->pdev->dev,
33364 "Waiting for stale completions to drain.\n");
33365- h->access.set_intr_mask(h, CCISS_INTR_ON);
33366+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33367 msleep(10000);
33368- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33369+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33370
33371 rc = controller_reset_failed(h->cfgtable);
33372 if (rc)
33373@@ -5146,7 +5148,7 @@ reinit_after_soft_reset:
33374 cciss_scsi_setup(h);
33375
33376 /* Turn the interrupts on so we can service requests */
33377- h->access.set_intr_mask(h, CCISS_INTR_ON);
33378+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33379
33380 /* Get the firmware version */
33381 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33382@@ -5218,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33383 kfree(flush_buf);
33384 if (return_code != IO_OK)
33385 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33386- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33387+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33388 free_irq(h->intr[h->intr_mode], h);
33389 }
33390
33391diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33392index 7fda30e..eb5dfe0 100644
33393--- a/drivers/block/cciss.h
33394+++ b/drivers/block/cciss.h
33395@@ -101,7 +101,7 @@ struct ctlr_info
33396 /* information about each logical volume */
33397 drive_info_struct *drv[CISS_MAX_LUN];
33398
33399- struct access_method access;
33400+ struct access_method *access;
33401
33402 /* queue and queue Info */
33403 struct list_head reqQ;
33404diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33405index 639d26b..fd6ad1f 100644
33406--- a/drivers/block/cpqarray.c
33407+++ b/drivers/block/cpqarray.c
33408@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33409 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33410 goto Enomem4;
33411 }
33412- hba[i]->access.set_intr_mask(hba[i], 0);
33413+ hba[i]->access->set_intr_mask(hba[i], 0);
33414 if (request_irq(hba[i]->intr, do_ida_intr,
33415 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33416 {
33417@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33418 add_timer(&hba[i]->timer);
33419
33420 /* Enable IRQ now that spinlock and rate limit timer are set up */
33421- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33422+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33423
33424 for(j=0; j<NWD; j++) {
33425 struct gendisk *disk = ida_gendisk[i][j];
33426@@ -694,7 +694,7 @@ DBGINFO(
33427 for(i=0; i<NR_PRODUCTS; i++) {
33428 if (board_id == products[i].board_id) {
33429 c->product_name = products[i].product_name;
33430- c->access = *(products[i].access);
33431+ c->access = products[i].access;
33432 break;
33433 }
33434 }
33435@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33436 hba[ctlr]->intr = intr;
33437 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33438 hba[ctlr]->product_name = products[j].product_name;
33439- hba[ctlr]->access = *(products[j].access);
33440+ hba[ctlr]->access = products[j].access;
33441 hba[ctlr]->ctlr = ctlr;
33442 hba[ctlr]->board_id = board_id;
33443 hba[ctlr]->pci_dev = NULL; /* not PCI */
33444@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
33445
33446 while((c = h->reqQ) != NULL) {
33447 /* Can't do anything if we're busy */
33448- if (h->access.fifo_full(h) == 0)
33449+ if (h->access->fifo_full(h) == 0)
33450 return;
33451
33452 /* Get the first entry from the request Q */
33453@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
33454 h->Qdepth--;
33455
33456 /* Tell the controller to do our bidding */
33457- h->access.submit_command(h, c);
33458+ h->access->submit_command(h, c);
33459
33460 /* Get onto the completion Q */
33461 addQ(&h->cmpQ, c);
33462@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33463 unsigned long flags;
33464 __u32 a,a1;
33465
33466- istat = h->access.intr_pending(h);
33467+ istat = h->access->intr_pending(h);
33468 /* Is this interrupt for us? */
33469 if (istat == 0)
33470 return IRQ_NONE;
33471@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33472 */
33473 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33474 if (istat & FIFO_NOT_EMPTY) {
33475- while((a = h->access.command_completed(h))) {
33476+ while((a = h->access->command_completed(h))) {
33477 a1 = a; a &= ~3;
33478 if ((c = h->cmpQ) == NULL)
33479 {
33480@@ -1193,6 +1193,7 @@ out_passthru:
33481 ida_pci_info_struct pciinfo;
33482
33483 if (!arg) return -EINVAL;
33484+ memset(&pciinfo, 0, sizeof(pciinfo));
33485 pciinfo.bus = host->pci_dev->bus->number;
33486 pciinfo.dev_fn = host->pci_dev->devfn;
33487 pciinfo.board_id = host->board_id;
33488@@ -1447,11 +1448,11 @@ static int sendcmd(
33489 /*
33490 * Disable interrupt
33491 */
33492- info_p->access.set_intr_mask(info_p, 0);
33493+ info_p->access->set_intr_mask(info_p, 0);
33494 /* Make sure there is room in the command FIFO */
33495 /* Actually it should be completely empty at this time. */
33496 for (i = 200000; i > 0; i--) {
33497- temp = info_p->access.fifo_full(info_p);
33498+ temp = info_p->access->fifo_full(info_p);
33499 if (temp != 0) {
33500 break;
33501 }
33502@@ -1464,7 +1465,7 @@ DBG(
33503 /*
33504 * Send the cmd
33505 */
33506- info_p->access.submit_command(info_p, c);
33507+ info_p->access->submit_command(info_p, c);
33508 complete = pollcomplete(ctlr);
33509
33510 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33511@@ -1547,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33512 * we check the new geometry. Then turn interrupts back on when
33513 * we're done.
33514 */
33515- host->access.set_intr_mask(host, 0);
33516+ host->access->set_intr_mask(host, 0);
33517 getgeometry(ctlr);
33518- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33519+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33520
33521 for(i=0; i<NWD; i++) {
33522 struct gendisk *disk = ida_gendisk[ctlr][i];
33523@@ -1589,7 +1590,7 @@ static int pollcomplete(int ctlr)
33524 /* Wait (up to 2 seconds) for a command to complete */
33525
33526 for (i = 200000; i > 0; i--) {
33527- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33528+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33529 if (done == 0) {
33530 udelay(10); /* a short fixed delay */
33531 } else
33532diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33533index be73e9d..7fbf140 100644
33534--- a/drivers/block/cpqarray.h
33535+++ b/drivers/block/cpqarray.h
33536@@ -99,7 +99,7 @@ struct ctlr_info {
33537 drv_info_t drv[NWD];
33538 struct proc_dir_entry *proc;
33539
33540- struct access_method access;
33541+ struct access_method *access;
33542
33543 cmdlist_t *reqQ;
33544 cmdlist_t *cmpQ;
33545diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33546index f943aac..99bfd19 100644
33547--- a/drivers/block/drbd/drbd_int.h
33548+++ b/drivers/block/drbd/drbd_int.h
33549@@ -582,7 +582,7 @@ struct drbd_epoch {
33550 struct drbd_tconn *tconn;
33551 struct list_head list;
33552 unsigned int barrier_nr;
33553- atomic_t epoch_size; /* increased on every request added. */
33554+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33555 atomic_t active; /* increased on every req. added, and dec on every finished. */
33556 unsigned long flags;
33557 };
33558@@ -1021,7 +1021,7 @@ struct drbd_conf {
33559 unsigned int al_tr_number;
33560 int al_tr_cycle;
33561 wait_queue_head_t seq_wait;
33562- atomic_t packet_seq;
33563+ atomic_unchecked_t packet_seq;
33564 unsigned int peer_seq;
33565 spinlock_t peer_seq_lock;
33566 unsigned int minor;
33567@@ -1562,7 +1562,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33568 char __user *uoptval;
33569 int err;
33570
33571- uoptval = (char __user __force *)optval;
33572+ uoptval = (char __force_user *)optval;
33573
33574 set_fs(KERNEL_DS);
33575 if (level == SOL_SOCKET)
33576diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33577index a5dca6a..bb27967 100644
33578--- a/drivers/block/drbd/drbd_main.c
33579+++ b/drivers/block/drbd/drbd_main.c
33580@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33581 p->sector = sector;
33582 p->block_id = block_id;
33583 p->blksize = blksize;
33584- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33585+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33586 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33587 }
33588
33589@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33590 return -EIO;
33591 p->sector = cpu_to_be64(req->i.sector);
33592 p->block_id = (unsigned long)req;
33593- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33594+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33595 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33596 if (mdev->state.conn >= C_SYNC_SOURCE &&
33597 mdev->state.conn <= C_PAUSED_SYNC_T)
33598@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33599 {
33600 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33601
33602- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33603- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33604+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33605+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33606 kfree(tconn->current_epoch);
33607
33608 idr_destroy(&tconn->volumes);
33609diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33610index 4222aff..1f79506 100644
33611--- a/drivers/block/drbd/drbd_receiver.c
33612+++ b/drivers/block/drbd/drbd_receiver.c
33613@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
33614 {
33615 int err;
33616
33617- atomic_set(&mdev->packet_seq, 0);
33618+ atomic_set_unchecked(&mdev->packet_seq, 0);
33619 mdev->peer_seq = 0;
33620
33621 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33622@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33623 do {
33624 next_epoch = NULL;
33625
33626- epoch_size = atomic_read(&epoch->epoch_size);
33627+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33628
33629 switch (ev & ~EV_CLEANUP) {
33630 case EV_PUT:
33631@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33632 rv = FE_DESTROYED;
33633 } else {
33634 epoch->flags = 0;
33635- atomic_set(&epoch->epoch_size, 0);
33636+ atomic_set_unchecked(&epoch->epoch_size, 0);
33637 /* atomic_set(&epoch->active, 0); is already zero */
33638 if (rv == FE_STILL_LIVE)
33639 rv = FE_RECYCLED;
33640@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33641 conn_wait_active_ee_empty(tconn);
33642 drbd_flush(tconn);
33643
33644- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33645+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33646 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33647 if (epoch)
33648 break;
33649@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33650 }
33651
33652 epoch->flags = 0;
33653- atomic_set(&epoch->epoch_size, 0);
33654+ atomic_set_unchecked(&epoch->epoch_size, 0);
33655 atomic_set(&epoch->active, 0);
33656
33657 spin_lock(&tconn->epoch_lock);
33658- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33659+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33660 list_add(&epoch->list, &tconn->current_epoch->list);
33661 tconn->current_epoch = epoch;
33662 tconn->epochs++;
33663@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33664
33665 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33666 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33667- atomic_inc(&tconn->current_epoch->epoch_size);
33668+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33669 err2 = drbd_drain_block(mdev, pi->size);
33670 if (!err)
33671 err = err2;
33672@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33673
33674 spin_lock(&tconn->epoch_lock);
33675 peer_req->epoch = tconn->current_epoch;
33676- atomic_inc(&peer_req->epoch->epoch_size);
33677+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33678 atomic_inc(&peer_req->epoch->active);
33679 spin_unlock(&tconn->epoch_lock);
33680
33681@@ -4347,7 +4347,7 @@ struct data_cmd {
33682 int expect_payload;
33683 size_t pkt_size;
33684 int (*fn)(struct drbd_tconn *, struct packet_info *);
33685-};
33686+} __do_const;
33687
33688 static struct data_cmd drbd_cmd_handler[] = {
33689 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33690@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33691 if (!list_empty(&tconn->current_epoch->list))
33692 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33693 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33694- atomic_set(&tconn->current_epoch->epoch_size, 0);
33695+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33696 tconn->send.seen_any_write_yet = false;
33697
33698 conn_info(tconn, "Connection closed\n");
33699@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33700 struct asender_cmd {
33701 size_t pkt_size;
33702 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33703-};
33704+} __do_const;
33705
33706 static struct asender_cmd asender_tbl[] = {
33707 [P_PING] = { 0, got_Ping },
33708diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33709index d92d50f..a7e9d97 100644
33710--- a/drivers/block/loop.c
33711+++ b/drivers/block/loop.c
33712@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
33713
33714 file_start_write(file);
33715 set_fs(get_ds());
33716- bw = file->f_op->write(file, buf, len, &pos);
33717+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33718 set_fs(old_fs);
33719 file_end_write(file);
33720 if (likely(bw == len))
33721diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
33722index f5d0ea1..c62380a 100644
33723--- a/drivers/block/pktcdvd.c
33724+++ b/drivers/block/pktcdvd.c
33725@@ -84,7 +84,7 @@
33726 #define MAX_SPEED 0xffff
33727
33728 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
33729- ~(sector_t)((pd)->settings.size - 1))
33730+ ~(sector_t)((pd)->settings.size - 1UL))
33731
33732 static DEFINE_MUTEX(pktcdvd_mutex);
33733 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
33734diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33735index 8a3aff7..d7538c2 100644
33736--- a/drivers/cdrom/cdrom.c
33737+++ b/drivers/cdrom/cdrom.c
33738@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33739 ENSURE(reset, CDC_RESET);
33740 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33741 cdi->mc_flags = 0;
33742- cdo->n_minors = 0;
33743 cdi->options = CDO_USE_FFLAGS;
33744
33745 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33746@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33747 else
33748 cdi->cdda_method = CDDA_OLD;
33749
33750- if (!cdo->generic_packet)
33751- cdo->generic_packet = cdrom_dummy_generic_packet;
33752+ if (!cdo->generic_packet) {
33753+ pax_open_kernel();
33754+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33755+ pax_close_kernel();
33756+ }
33757
33758 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33759 mutex_lock(&cdrom_mutex);
33760@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33761 if (cdi->exit)
33762 cdi->exit(cdi);
33763
33764- cdi->ops->n_minors--;
33765 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33766 }
33767
33768@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
33769 */
33770 nr = nframes;
33771 do {
33772- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33773+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33774 if (cgc.buffer)
33775 break;
33776
33777@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
33778 struct cdrom_device_info *cdi;
33779 int ret;
33780
33781- ret = scnprintf(info + *pos, max_size - *pos, header);
33782+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
33783 if (!ret)
33784 return 1;
33785
33786diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33787index 4afcb65..a68a32d 100644
33788--- a/drivers/cdrom/gdrom.c
33789+++ b/drivers/cdrom/gdrom.c
33790@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33791 .audio_ioctl = gdrom_audio_ioctl,
33792 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33793 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33794- .n_minors = 1,
33795 };
33796
33797 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33798diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33799index 3bb6fa3..34013fb 100644
33800--- a/drivers/char/Kconfig
33801+++ b/drivers/char/Kconfig
33802@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33803
33804 config DEVKMEM
33805 bool "/dev/kmem virtual device support"
33806- default y
33807+ default n
33808+ depends on !GRKERNSEC_KMEM
33809 help
33810 Say Y here if you want to support the /dev/kmem device. The
33811 /dev/kmem device is rarely used, but can be used for certain
33812@@ -582,6 +583,7 @@ config DEVPORT
33813 bool
33814 depends on !M68K
33815 depends on ISA || PCI
33816+ depends on !GRKERNSEC_KMEM
33817 default y
33818
33819 source "drivers/s390/char/Kconfig"
33820diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
33821index a48e05b..6bac831 100644
33822--- a/drivers/char/agp/compat_ioctl.c
33823+++ b/drivers/char/agp/compat_ioctl.c
33824@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
33825 return -ENOMEM;
33826 }
33827
33828- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
33829+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
33830 sizeof(*usegment) * ureserve.seg_count)) {
33831 kfree(usegment);
33832 kfree(ksegment);
33833diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33834index 2e04433..771f2cc 100644
33835--- a/drivers/char/agp/frontend.c
33836+++ b/drivers/char/agp/frontend.c
33837@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33838 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33839 return -EFAULT;
33840
33841- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33842+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33843 return -EFAULT;
33844
33845 client = agp_find_client_by_pid(reserve.pid);
33846@@ -847,7 +847,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33847 if (segment == NULL)
33848 return -ENOMEM;
33849
33850- if (copy_from_user(segment, (void __user *) reserve.seg_list,
33851+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
33852 sizeof(struct agp_segment) * reserve.seg_count)) {
33853 kfree(segment);
33854 return -EFAULT;
33855diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33856index 4f94375..413694e 100644
33857--- a/drivers/char/genrtc.c
33858+++ b/drivers/char/genrtc.c
33859@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
33860 switch (cmd) {
33861
33862 case RTC_PLL_GET:
33863+ memset(&pll, 0, sizeof(pll));
33864 if (get_rtc_pll(&pll))
33865 return -EINVAL;
33866 else
33867diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33868index d784650..e8bfd69 100644
33869--- a/drivers/char/hpet.c
33870+++ b/drivers/char/hpet.c
33871@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33872 }
33873
33874 static int
33875-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33876+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33877 struct hpet_info *info)
33878 {
33879 struct hpet_timer __iomem *timer;
33880diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
33881index 86fe45c..c0ea948 100644
33882--- a/drivers/char/hw_random/intel-rng.c
33883+++ b/drivers/char/hw_random/intel-rng.c
33884@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
33885
33886 if (no_fwh_detect)
33887 return -ENODEV;
33888- printk(warning);
33889+ printk("%s", warning);
33890 return -EBUSY;
33891 }
33892
33893diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33894index 4445fa1..7c6de37 100644
33895--- a/drivers/char/ipmi/ipmi_msghandler.c
33896+++ b/drivers/char/ipmi/ipmi_msghandler.c
33897@@ -420,7 +420,7 @@ struct ipmi_smi {
33898 struct proc_dir_entry *proc_dir;
33899 char proc_dir_name[10];
33900
33901- atomic_t stats[IPMI_NUM_STATS];
33902+ atomic_unchecked_t stats[IPMI_NUM_STATS];
33903
33904 /*
33905 * run_to_completion duplicate of smb_info, smi_info
33906@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33907
33908
33909 #define ipmi_inc_stat(intf, stat) \
33910- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33911+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33912 #define ipmi_get_stat(intf, stat) \
33913- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33914+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33915
33916 static int is_lan_addr(struct ipmi_addr *addr)
33917 {
33918@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33919 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33920 init_waitqueue_head(&intf->waitq);
33921 for (i = 0; i < IPMI_NUM_STATS; i++)
33922- atomic_set(&intf->stats[i], 0);
33923+ atomic_set_unchecked(&intf->stats[i], 0);
33924
33925 intf->proc_dir = NULL;
33926
33927diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33928index af4b23f..79806fc 100644
33929--- a/drivers/char/ipmi/ipmi_si_intf.c
33930+++ b/drivers/char/ipmi/ipmi_si_intf.c
33931@@ -275,7 +275,7 @@ struct smi_info {
33932 unsigned char slave_addr;
33933
33934 /* Counters and things for the proc filesystem. */
33935- atomic_t stats[SI_NUM_STATS];
33936+ atomic_unchecked_t stats[SI_NUM_STATS];
33937
33938 struct task_struct *thread;
33939
33940@@ -284,9 +284,9 @@ struct smi_info {
33941 };
33942
33943 #define smi_inc_stat(smi, stat) \
33944- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33945+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33946 #define smi_get_stat(smi, stat) \
33947- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33948+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33949
33950 #define SI_MAX_PARMS 4
33951
33952@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
33953 atomic_set(&new_smi->req_events, 0);
33954 new_smi->run_to_completion = 0;
33955 for (i = 0; i < SI_NUM_STATS; i++)
33956- atomic_set(&new_smi->stats[i], 0);
33957+ atomic_set_unchecked(&new_smi->stats[i], 0);
33958
33959 new_smi->interrupt_disabled = 1;
33960 atomic_set(&new_smi->stop_operation, 0);
33961diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33962index 1ccbe94..6ad651a 100644
33963--- a/drivers/char/mem.c
33964+++ b/drivers/char/mem.c
33965@@ -18,6 +18,7 @@
33966 #include <linux/raw.h>
33967 #include <linux/tty.h>
33968 #include <linux/capability.h>
33969+#include <linux/security.h>
33970 #include <linux/ptrace.h>
33971 #include <linux/device.h>
33972 #include <linux/highmem.h>
33973@@ -38,6 +39,10 @@
33974
33975 #define DEVPORT_MINOR 4
33976
33977+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33978+extern const struct file_operations grsec_fops;
33979+#endif
33980+
33981 static inline unsigned long size_inside_page(unsigned long start,
33982 unsigned long size)
33983 {
33984@@ -69,9 +74,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33985
33986 while (cursor < to) {
33987 if (!devmem_is_allowed(pfn)) {
33988+#ifdef CONFIG_GRKERNSEC_KMEM
33989+ gr_handle_mem_readwrite(from, to);
33990+#else
33991 printk(KERN_INFO
33992 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
33993 current->comm, from, to);
33994+#endif
33995 return 0;
33996 }
33997 cursor += PAGE_SIZE;
33998@@ -79,6 +88,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33999 }
34000 return 1;
34001 }
34002+#elif defined(CONFIG_GRKERNSEC_KMEM)
34003+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34004+{
34005+ return 0;
34006+}
34007 #else
34008 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34009 {
34010@@ -121,6 +135,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34011
34012 while (count > 0) {
34013 unsigned long remaining;
34014+ char *temp;
34015
34016 sz = size_inside_page(p, count);
34017
34018@@ -136,7 +151,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34019 if (!ptr)
34020 return -EFAULT;
34021
34022- remaining = copy_to_user(buf, ptr, sz);
34023+#ifdef CONFIG_PAX_USERCOPY
34024+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34025+ if (!temp) {
34026+ unxlate_dev_mem_ptr(p, ptr);
34027+ return -ENOMEM;
34028+ }
34029+ memcpy(temp, ptr, sz);
34030+#else
34031+ temp = ptr;
34032+#endif
34033+
34034+ remaining = copy_to_user(buf, temp, sz);
34035+
34036+#ifdef CONFIG_PAX_USERCOPY
34037+ kfree(temp);
34038+#endif
34039+
34040 unxlate_dev_mem_ptr(p, ptr);
34041 if (remaining)
34042 return -EFAULT;
34043@@ -379,7 +410,7 @@ static ssize_t read_oldmem(struct file *file, char __user *buf,
34044 else
34045 csize = count;
34046
34047- rc = copy_oldmem_page(pfn, buf, csize, offset, 1);
34048+ rc = copy_oldmem_page(pfn, (char __force_kernel *)buf, csize, offset, 1);
34049 if (rc < 0)
34050 return rc;
34051 buf += csize;
34052@@ -399,9 +430,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34053 size_t count, loff_t *ppos)
34054 {
34055 unsigned long p = *ppos;
34056- ssize_t low_count, read, sz;
34057+ ssize_t low_count, read, sz, err = 0;
34058 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
34059- int err = 0;
34060
34061 read = 0;
34062 if (p < (unsigned long) high_memory) {
34063@@ -423,6 +453,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34064 }
34065 #endif
34066 while (low_count > 0) {
34067+ char *temp;
34068+
34069 sz = size_inside_page(p, low_count);
34070
34071 /*
34072@@ -432,7 +464,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34073 */
34074 kbuf = xlate_dev_kmem_ptr((char *)p);
34075
34076- if (copy_to_user(buf, kbuf, sz))
34077+#ifdef CONFIG_PAX_USERCOPY
34078+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34079+ if (!temp)
34080+ return -ENOMEM;
34081+ memcpy(temp, kbuf, sz);
34082+#else
34083+ temp = kbuf;
34084+#endif
34085+
34086+ err = copy_to_user(buf, temp, sz);
34087+
34088+#ifdef CONFIG_PAX_USERCOPY
34089+ kfree(temp);
34090+#endif
34091+
34092+ if (err)
34093 return -EFAULT;
34094 buf += sz;
34095 p += sz;
34096@@ -869,6 +916,9 @@ static const struct memdev {
34097 #ifdef CONFIG_CRASH_DUMP
34098 [12] = { "oldmem", 0, &oldmem_fops, NULL },
34099 #endif
34100+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34101+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
34102+#endif
34103 };
34104
34105 static int memory_open(struct inode *inode, struct file *filp)
34106@@ -940,7 +990,7 @@ static int __init chr_dev_init(void)
34107 continue;
34108
34109 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
34110- NULL, devlist[minor].name);
34111+ NULL, "%s", devlist[minor].name);
34112 }
34113
34114 return tty_init();
34115diff --git a/drivers/char/mwave/tp3780i.c b/drivers/char/mwave/tp3780i.c
34116index c689697..04e6d6a2 100644
34117--- a/drivers/char/mwave/tp3780i.c
34118+++ b/drivers/char/mwave/tp3780i.c
34119@@ -479,6 +479,7 @@ int tp3780I_QueryAbilities(THINKPAD_BD_DATA * pBDData, MW_ABILITIES * pAbilities
34120 PRINTK_2(TRACE_TP3780I,
34121 "tp3780i::tp3780I_QueryAbilities entry pBDData %p\n", pBDData);
34122
34123+ memset(pAbilities, 0, sizeof(*pAbilities));
34124 /* fill out standard constant fields */
34125 pAbilities->instr_per_sec = pBDData->rDspSettings.uIps;
34126 pAbilities->data_size = pBDData->rDspSettings.uDStoreSize;
34127diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
34128index 9df78e2..01ba9ae 100644
34129--- a/drivers/char/nvram.c
34130+++ b/drivers/char/nvram.c
34131@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
34132
34133 spin_unlock_irq(&rtc_lock);
34134
34135- if (copy_to_user(buf, contents, tmp - contents))
34136+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
34137 return -EFAULT;
34138
34139 *ppos = i;
34140diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
34141index 5c5cc00..ac9edb7 100644
34142--- a/drivers/char/pcmcia/synclink_cs.c
34143+++ b/drivers/char/pcmcia/synclink_cs.c
34144@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34145
34146 if (debug_level >= DEBUG_LEVEL_INFO)
34147 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
34148- __FILE__, __LINE__, info->device_name, port->count);
34149+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
34150
34151- WARN_ON(!port->count);
34152+ WARN_ON(!atomic_read(&port->count));
34153
34154 if (tty_port_close_start(port, tty, filp) == 0)
34155 goto cleanup;
34156@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34157 cleanup:
34158 if (debug_level >= DEBUG_LEVEL_INFO)
34159 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
34160- tty->driver->name, port->count);
34161+ tty->driver->name, atomic_read(&port->count));
34162 }
34163
34164 /* Wait until the transmitter is empty.
34165@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34166
34167 if (debug_level >= DEBUG_LEVEL_INFO)
34168 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
34169- __FILE__, __LINE__, tty->driver->name, port->count);
34170+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
34171
34172 /* If port is closing, signal caller to try again */
34173 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
34174@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34175 goto cleanup;
34176 }
34177 spin_lock(&port->lock);
34178- port->count++;
34179+ atomic_inc(&port->count);
34180 spin_unlock(&port->lock);
34181 spin_unlock_irqrestore(&info->netlock, flags);
34182
34183- if (port->count == 1) {
34184+ if (atomic_read(&port->count) == 1) {
34185 /* 1st open on this device, init hardware */
34186 retval = startup(info, tty);
34187 if (retval < 0)
34188@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
34189 unsigned short new_crctype;
34190
34191 /* return error if TTY interface open */
34192- if (info->port.count)
34193+ if (atomic_read(&info->port.count))
34194 return -EBUSY;
34195
34196 switch (encoding)
34197@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
34198
34199 /* arbitrate between network and tty opens */
34200 spin_lock_irqsave(&info->netlock, flags);
34201- if (info->port.count != 0 || info->netcount != 0) {
34202+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
34203 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
34204 spin_unlock_irqrestore(&info->netlock, flags);
34205 return -EBUSY;
34206@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34207 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
34208
34209 /* return error if TTY interface open */
34210- if (info->port.count)
34211+ if (atomic_read(&info->port.count))
34212 return -EBUSY;
34213
34214 if (cmd != SIOCWANDEV)
34215diff --git a/drivers/char/random.c b/drivers/char/random.c
34216index 35487e8..dac8bd1 100644
34217--- a/drivers/char/random.c
34218+++ b/drivers/char/random.c
34219@@ -272,8 +272,13 @@
34220 /*
34221 * Configuration information
34222 */
34223+#ifdef CONFIG_GRKERNSEC_RANDNET
34224+#define INPUT_POOL_WORDS 512
34225+#define OUTPUT_POOL_WORDS 128
34226+#else
34227 #define INPUT_POOL_WORDS 128
34228 #define OUTPUT_POOL_WORDS 32
34229+#endif
34230 #define SEC_XFER_SIZE 512
34231 #define EXTRACT_SIZE 10
34232
34233@@ -313,10 +318,17 @@ static struct poolinfo {
34234 int poolwords;
34235 int tap1, tap2, tap3, tap4, tap5;
34236 } poolinfo_table[] = {
34237+#ifdef CONFIG_GRKERNSEC_RANDNET
34238+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
34239+ { 512, 411, 308, 208, 104, 1 },
34240+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
34241+ { 128, 103, 76, 51, 25, 1 },
34242+#else
34243 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
34244 { 128, 103, 76, 51, 25, 1 },
34245 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
34246 { 32, 26, 20, 14, 7, 1 },
34247+#endif
34248 #if 0
34249 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
34250 { 2048, 1638, 1231, 819, 411, 1 },
34251@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
34252 input_rotate += i ? 7 : 14;
34253 }
34254
34255- ACCESS_ONCE(r->input_rotate) = input_rotate;
34256- ACCESS_ONCE(r->add_ptr) = i;
34257+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
34258+ ACCESS_ONCE_RW(r->add_ptr) = i;
34259 smp_wmb();
34260
34261 if (out)
34262@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
34263
34264 extract_buf(r, tmp);
34265 i = min_t(int, nbytes, EXTRACT_SIZE);
34266- if (copy_to_user(buf, tmp, i)) {
34267+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
34268 ret = -EFAULT;
34269 break;
34270 }
34271@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
34272 #include <linux/sysctl.h>
34273
34274 static int min_read_thresh = 8, min_write_thresh;
34275-static int max_read_thresh = INPUT_POOL_WORDS * 32;
34276+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
34277 static int max_write_thresh = INPUT_POOL_WORDS * 32;
34278 static char sysctl_bootid[16];
34279
34280@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
34281 static int proc_do_uuid(ctl_table *table, int write,
34282 void __user *buffer, size_t *lenp, loff_t *ppos)
34283 {
34284- ctl_table fake_table;
34285+ ctl_table_no_const fake_table;
34286 unsigned char buf[64], tmp_uuid[16], *uuid;
34287
34288 uuid = table->data;
34289diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
34290index bf2349db..5456d53 100644
34291--- a/drivers/char/sonypi.c
34292+++ b/drivers/char/sonypi.c
34293@@ -54,6 +54,7 @@
34294
34295 #include <asm/uaccess.h>
34296 #include <asm/io.h>
34297+#include <asm/local.h>
34298
34299 #include <linux/sonypi.h>
34300
34301@@ -490,7 +491,7 @@ static struct sonypi_device {
34302 spinlock_t fifo_lock;
34303 wait_queue_head_t fifo_proc_list;
34304 struct fasync_struct *fifo_async;
34305- int open_count;
34306+ local_t open_count;
34307 int model;
34308 struct input_dev *input_jog_dev;
34309 struct input_dev *input_key_dev;
34310@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
34311 static int sonypi_misc_release(struct inode *inode, struct file *file)
34312 {
34313 mutex_lock(&sonypi_device.lock);
34314- sonypi_device.open_count--;
34315+ local_dec(&sonypi_device.open_count);
34316 mutex_unlock(&sonypi_device.lock);
34317 return 0;
34318 }
34319@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
34320 {
34321 mutex_lock(&sonypi_device.lock);
34322 /* Flush input queue on first open */
34323- if (!sonypi_device.open_count)
34324+ if (!local_read(&sonypi_device.open_count))
34325 kfifo_reset(&sonypi_device.fifo);
34326- sonypi_device.open_count++;
34327+ local_inc(&sonypi_device.open_count);
34328 mutex_unlock(&sonypi_device.lock);
34329
34330 return 0;
34331diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
34332index 64420b3..5c40b56 100644
34333--- a/drivers/char/tpm/tpm_acpi.c
34334+++ b/drivers/char/tpm/tpm_acpi.c
34335@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
34336 virt = acpi_os_map_memory(start, len);
34337 if (!virt) {
34338 kfree(log->bios_event_log);
34339+ log->bios_event_log = NULL;
34340 printk("%s: ERROR - Unable to map memory\n", __func__);
34341 return -EIO;
34342 }
34343
34344- memcpy_fromio(log->bios_event_log, virt, len);
34345+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34346
34347 acpi_os_unmap_memory(virt, len);
34348 return 0;
34349diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34350index 84ddc55..1d32f1e 100644
34351--- a/drivers/char/tpm/tpm_eventlog.c
34352+++ b/drivers/char/tpm/tpm_eventlog.c
34353@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34354 event = addr;
34355
34356 if ((event->event_type == 0 && event->event_size == 0) ||
34357- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34358+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34359 return NULL;
34360
34361 return addr;
34362@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34363 return NULL;
34364
34365 if ((event->event_type == 0 && event->event_size == 0) ||
34366- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34367+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34368 return NULL;
34369
34370 (*pos)++;
34371@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34372 int i;
34373
34374 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34375- seq_putc(m, data[i]);
34376+ if (!seq_putc(m, data[i]))
34377+ return -EFAULT;
34378
34379 return 0;
34380 }
34381diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34382index 1b456fe..2510242 100644
34383--- a/drivers/char/virtio_console.c
34384+++ b/drivers/char/virtio_console.c
34385@@ -679,7 +679,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34386 if (to_user) {
34387 ssize_t ret;
34388
34389- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34390+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34391 if (ret)
34392 return -EFAULT;
34393 } else {
34394@@ -778,7 +778,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34395 if (!port_has_data(port) && !port->host_connected)
34396 return 0;
34397
34398- return fill_readbuf(port, ubuf, count, true);
34399+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34400 }
34401
34402 static int wait_port_writable(struct port *port, bool nonblock)
34403diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
34404index a33f46f..a720eed 100644
34405--- a/drivers/clk/clk-composite.c
34406+++ b/drivers/clk/clk-composite.c
34407@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
34408 struct clk *clk;
34409 struct clk_init_data init;
34410 struct clk_composite *composite;
34411- struct clk_ops *clk_composite_ops;
34412+ clk_ops_no_const *clk_composite_ops;
34413
34414 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
34415 if (!composite) {
34416diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
34417index a2b2541..bc1e7ff 100644
34418--- a/drivers/clocksource/arm_arch_timer.c
34419+++ b/drivers/clocksource/arm_arch_timer.c
34420@@ -264,7 +264,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34421 return NOTIFY_OK;
34422 }
34423
34424-static struct notifier_block arch_timer_cpu_nb __cpuinitdata = {
34425+static struct notifier_block arch_timer_cpu_nb = {
34426 .notifier_call = arch_timer_cpu_notify,
34427 };
34428
34429diff --git a/drivers/clocksource/metag_generic.c b/drivers/clocksource/metag_generic.c
34430index ade7513..069445f 100644
34431--- a/drivers/clocksource/metag_generic.c
34432+++ b/drivers/clocksource/metag_generic.c
34433@@ -169,7 +169,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34434 return NOTIFY_OK;
34435 }
34436
34437-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34438+static struct notifier_block arch_timer_cpu_nb = {
34439 .notifier_call = arch_timer_cpu_notify,
34440 };
34441
34442diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34443index edc089e..bc7c0bc 100644
34444--- a/drivers/cpufreq/acpi-cpufreq.c
34445+++ b/drivers/cpufreq/acpi-cpufreq.c
34446@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34447 return sprintf(buf, "%u\n", boost_enabled);
34448 }
34449
34450-static struct global_attr global_boost = __ATTR(boost, 0644,
34451+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34452 show_global_boost,
34453 store_global_boost);
34454
34455@@ -705,8 +705,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34456 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34457 per_cpu(acfreq_data, cpu) = data;
34458
34459- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34460- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34461+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34462+ pax_open_kernel();
34463+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34464+ pax_close_kernel();
34465+ }
34466
34467 result = acpi_processor_register_performance(data->acpi_data, cpu);
34468 if (result)
34469@@ -832,7 +835,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34470 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34471 break;
34472 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34473- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34474+ pax_open_kernel();
34475+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34476+ pax_close_kernel();
34477 policy->cur = get_cur_freq_on_cpu(cpu);
34478 break;
34479 default:
34480@@ -843,8 +848,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34481 acpi_processor_notify_smm(THIS_MODULE);
34482
34483 /* Check for APERF/MPERF support in hardware */
34484- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34485- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34486+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34487+ pax_open_kernel();
34488+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34489+ pax_close_kernel();
34490+ }
34491
34492 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34493 for (i = 0; i < perf->state_count; i++)
34494diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34495index 2d53f47..eb3803e 100644
34496--- a/drivers/cpufreq/cpufreq.c
34497+++ b/drivers/cpufreq/cpufreq.c
34498@@ -1851,7 +1851,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34499 return NOTIFY_OK;
34500 }
34501
34502-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34503+static struct notifier_block cpufreq_cpu_notifier = {
34504 .notifier_call = cpufreq_cpu_callback,
34505 };
34506
34507@@ -1883,8 +1883,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34508
34509 pr_debug("trying to register driver %s\n", driver_data->name);
34510
34511- if (driver_data->setpolicy)
34512- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34513+ if (driver_data->setpolicy) {
34514+ pax_open_kernel();
34515+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34516+ pax_close_kernel();
34517+ }
34518
34519 write_lock_irqsave(&cpufreq_driver_lock, flags);
34520 if (cpufreq_driver) {
34521diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34522index dc9b72e..11c0302 100644
34523--- a/drivers/cpufreq/cpufreq_governor.c
34524+++ b/drivers/cpufreq/cpufreq_governor.c
34525@@ -238,7 +238,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
34526 struct dbs_data *dbs_data;
34527 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
34528 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
34529- struct od_ops *od_ops = NULL;
34530+ const struct od_ops *od_ops = NULL;
34531 struct od_dbs_tuners *od_tuners = NULL;
34532 struct cs_dbs_tuners *cs_tuners = NULL;
34533 struct cpu_dbs_common_info *cpu_cdbs;
34534@@ -301,7 +301,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
34535
34536 if ((cdata->governor == GOV_CONSERVATIVE) &&
34537 (!policy->governor->initialized)) {
34538- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34539+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34540
34541 cpufreq_register_notifier(cs_ops->notifier_block,
34542 CPUFREQ_TRANSITION_NOTIFIER);
34543@@ -318,7 +318,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
34544
34545 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
34546 (policy->governor->initialized == 1)) {
34547- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34548+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34549
34550 cpufreq_unregister_notifier(cs_ops->notifier_block,
34551 CPUFREQ_TRANSITION_NOTIFIER);
34552diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34553index e16a961..0e68927 100644
34554--- a/drivers/cpufreq/cpufreq_governor.h
34555+++ b/drivers/cpufreq/cpufreq_governor.h
34556@@ -204,7 +204,7 @@ struct common_dbs_data {
34557 void (*exit)(struct dbs_data *dbs_data);
34558
34559 /* Governor specific ops, see below */
34560- void *gov_ops;
34561+ const void *gov_ops;
34562 };
34563
34564 /* Governer Per policy data */
34565diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
34566index 93eb5cb..f8ab572 100644
34567--- a/drivers/cpufreq/cpufreq_ondemand.c
34568+++ b/drivers/cpufreq/cpufreq_ondemand.c
34569@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
34570 (struct cpufreq_policy *, unsigned int, unsigned int),
34571 unsigned int powersave_bias)
34572 {
34573- od_ops.powersave_bias_target = f;
34574+ pax_open_kernel();
34575+ *(void **)&od_ops.powersave_bias_target = f;
34576+ pax_close_kernel();
34577 od_set_powersave_bias(powersave_bias);
34578 }
34579 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
34580
34581 void od_unregister_powersave_bias_handler(void)
34582 {
34583- od_ops.powersave_bias_target = generic_powersave_bias_target;
34584+ pax_open_kernel();
34585+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
34586+ pax_close_kernel();
34587 od_set_powersave_bias(0);
34588 }
34589 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
34590diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34591index 591b6fb..2a01183 100644
34592--- a/drivers/cpufreq/cpufreq_stats.c
34593+++ b/drivers/cpufreq/cpufreq_stats.c
34594@@ -367,7 +367,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34595 }
34596
34597 /* priority=1 so this will get called before cpufreq_remove_dev */
34598-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34599+static struct notifier_block cpufreq_stat_cpu_notifier = {
34600 .notifier_call = cpufreq_stat_cpu_callback,
34601 .priority = 1,
34602 };
34603diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34604index 421ef37..e708530c 100644
34605--- a/drivers/cpufreq/p4-clockmod.c
34606+++ b/drivers/cpufreq/p4-clockmod.c
34607@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34608 case 0x0F: /* Core Duo */
34609 case 0x16: /* Celeron Core */
34610 case 0x1C: /* Atom */
34611- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34612+ pax_open_kernel();
34613+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34614+ pax_close_kernel();
34615 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34616 case 0x0D: /* Pentium M (Dothan) */
34617- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34618+ pax_open_kernel();
34619+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34620+ pax_close_kernel();
34621 /* fall through */
34622 case 0x09: /* Pentium M (Banias) */
34623 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34624@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34625
34626 /* on P-4s, the TSC runs with constant frequency independent whether
34627 * throttling is active or not. */
34628- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34629+ pax_open_kernel();
34630+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34631+ pax_close_kernel();
34632
34633 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34634 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34635diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
34636index c71ee14..7c2e183 100644
34637--- a/drivers/cpufreq/sparc-us3-cpufreq.c
34638+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
34639@@ -18,14 +18,12 @@
34640 #include <asm/head.h>
34641 #include <asm/timer.h>
34642
34643-static struct cpufreq_driver *cpufreq_us3_driver;
34644-
34645 struct us3_freq_percpu_info {
34646 struct cpufreq_frequency_table table[4];
34647 };
34648
34649 /* Indexed by cpu number. */
34650-static struct us3_freq_percpu_info *us3_freq_table;
34651+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
34652
34653 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
34654 * in the Safari config register.
34655@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
34656
34657 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
34658 {
34659- if (cpufreq_us3_driver)
34660- us3_set_cpu_divider_index(policy, 0);
34661+ us3_set_cpu_divider_index(policy->cpu, 0);
34662
34663 return 0;
34664 }
34665
34666+static int __init us3_freq_init(void);
34667+static void __exit us3_freq_exit(void);
34668+
34669+static struct cpufreq_driver cpufreq_us3_driver = {
34670+ .init = us3_freq_cpu_init,
34671+ .verify = us3_freq_verify,
34672+ .target = us3_freq_target,
34673+ .get = us3_freq_get,
34674+ .exit = us3_freq_cpu_exit,
34675+ .owner = THIS_MODULE,
34676+ .name = "UltraSPARC-III",
34677+
34678+};
34679+
34680 static int __init us3_freq_init(void)
34681 {
34682 unsigned long manuf, impl, ver;
34683@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
34684 (impl == CHEETAH_IMPL ||
34685 impl == CHEETAH_PLUS_IMPL ||
34686 impl == JAGUAR_IMPL ||
34687- impl == PANTHER_IMPL)) {
34688- struct cpufreq_driver *driver;
34689-
34690- ret = -ENOMEM;
34691- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
34692- if (!driver)
34693- goto err_out;
34694-
34695- us3_freq_table = kzalloc(
34696- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
34697- GFP_KERNEL);
34698- if (!us3_freq_table)
34699- goto err_out;
34700-
34701- driver->init = us3_freq_cpu_init;
34702- driver->verify = us3_freq_verify;
34703- driver->target = us3_freq_target;
34704- driver->get = us3_freq_get;
34705- driver->exit = us3_freq_cpu_exit;
34706- driver->owner = THIS_MODULE,
34707- strcpy(driver->name, "UltraSPARC-III");
34708-
34709- cpufreq_us3_driver = driver;
34710- ret = cpufreq_register_driver(driver);
34711- if (ret)
34712- goto err_out;
34713-
34714- return 0;
34715-
34716-err_out:
34717- if (driver) {
34718- kfree(driver);
34719- cpufreq_us3_driver = NULL;
34720- }
34721- kfree(us3_freq_table);
34722- us3_freq_table = NULL;
34723- return ret;
34724- }
34725+ impl == PANTHER_IMPL))
34726+ return cpufreq_register_driver(&cpufreq_us3_driver);
34727
34728 return -ENODEV;
34729 }
34730
34731 static void __exit us3_freq_exit(void)
34732 {
34733- if (cpufreq_us3_driver) {
34734- cpufreq_unregister_driver(cpufreq_us3_driver);
34735- kfree(cpufreq_us3_driver);
34736- cpufreq_us3_driver = NULL;
34737- kfree(us3_freq_table);
34738- us3_freq_table = NULL;
34739- }
34740+ cpufreq_unregister_driver(&cpufreq_us3_driver);
34741 }
34742
34743 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
34744diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34745index 618e6f4..e89d915 100644
34746--- a/drivers/cpufreq/speedstep-centrino.c
34747+++ b/drivers/cpufreq/speedstep-centrino.c
34748@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34749 !cpu_has(cpu, X86_FEATURE_EST))
34750 return -ENODEV;
34751
34752- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34753- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34754+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34755+ pax_open_kernel();
34756+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34757+ pax_close_kernel();
34758+ }
34759
34760 if (policy->cpu != 0)
34761 return -ENODEV;
34762diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34763index c3a93fe..e808f24 100644
34764--- a/drivers/cpuidle/cpuidle.c
34765+++ b/drivers/cpuidle/cpuidle.c
34766@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
34767
34768 static void poll_idle_init(struct cpuidle_driver *drv)
34769 {
34770- struct cpuidle_state *state = &drv->states[0];
34771+ cpuidle_state_no_const *state = &drv->states[0];
34772
34773 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34774 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34775diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34776index ea2f8e7..70ac501 100644
34777--- a/drivers/cpuidle/governor.c
34778+++ b/drivers/cpuidle/governor.c
34779@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34780 mutex_lock(&cpuidle_lock);
34781 if (__cpuidle_find_governor(gov->name) == NULL) {
34782 ret = 0;
34783- list_add_tail(&gov->governor_list, &cpuidle_governors);
34784+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34785 if (!cpuidle_curr_governor ||
34786 cpuidle_curr_governor->rating < gov->rating)
34787 cpuidle_switch_governor(gov);
34788@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34789 new_gov = cpuidle_replace_governor(gov->rating);
34790 cpuidle_switch_governor(new_gov);
34791 }
34792- list_del(&gov->governor_list);
34793+ pax_list_del((struct list_head *)&gov->governor_list);
34794 mutex_unlock(&cpuidle_lock);
34795 }
34796
34797diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34798index 428754a..8bdf9cc 100644
34799--- a/drivers/cpuidle/sysfs.c
34800+++ b/drivers/cpuidle/sysfs.c
34801@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34802 NULL
34803 };
34804
34805-static struct attribute_group cpuidle_attr_group = {
34806+static attribute_group_no_const cpuidle_attr_group = {
34807 .attrs = cpuidle_default_attrs,
34808 .name = "cpuidle",
34809 };
34810diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34811index 3b36797..db0b0c0 100644
34812--- a/drivers/devfreq/devfreq.c
34813+++ b/drivers/devfreq/devfreq.c
34814@@ -477,7 +477,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
34815 GFP_KERNEL);
34816 devfreq->last_stat_updated = jiffies;
34817
34818- dev_set_name(&devfreq->dev, dev_name(dev));
34819+ dev_set_name(&devfreq->dev, "%s", dev_name(dev));
34820 err = device_register(&devfreq->dev);
34821 if (err) {
34822 put_device(&devfreq->dev);
34823@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34824 goto err_out;
34825 }
34826
34827- list_add(&governor->node, &devfreq_governor_list);
34828+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34829
34830 list_for_each_entry(devfreq, &devfreq_list, node) {
34831 int ret = 0;
34832@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34833 }
34834 }
34835
34836- list_del(&governor->node);
34837+ pax_list_del((struct list_head *)&governor->node);
34838 err_out:
34839 mutex_unlock(&devfreq_list_lock);
34840
34841diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34842index b70709b..1d8d02a 100644
34843--- a/drivers/dma/sh/shdma.c
34844+++ b/drivers/dma/sh/shdma.c
34845@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34846 return ret;
34847 }
34848
34849-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34850+static struct notifier_block sh_dmae_nmi_notifier = {
34851 .notifier_call = sh_dmae_nmi_handler,
34852
34853 /* Run before NMI debug handler and KGDB */
34854diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34855index 67610a6..30f8a11 100644
34856--- a/drivers/edac/edac_mc_sysfs.c
34857+++ b/drivers/edac/edac_mc_sysfs.c
34858@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
34859 struct dev_ch_attribute {
34860 struct device_attribute attr;
34861 int channel;
34862-};
34863+} __do_const;
34864
34865 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34866 struct dev_ch_attribute dev_attr_legacy_##_name = \
34867@@ -1003,14 +1003,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
34868 }
34869
34870 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
34871+ pax_open_kernel();
34872 if (mci->get_sdram_scrub_rate) {
34873- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34874- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34875+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34876+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34877 }
34878 if (mci->set_sdram_scrub_rate) {
34879- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34880- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34881+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34882+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34883 }
34884+ pax_close_kernel();
34885 err = device_create_file(&mci->dev,
34886 &dev_attr_sdram_scrub_rate);
34887 if (err) {
34888diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34889index e8658e4..22746d6 100644
34890--- a/drivers/edac/edac_pci_sysfs.c
34891+++ b/drivers/edac/edac_pci_sysfs.c
34892@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34893 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34894 static int edac_pci_poll_msec = 1000; /* one second workq period */
34895
34896-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34897-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34898+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34899+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34900
34901 static struct kobject *edac_pci_top_main_kobj;
34902 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34903@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34904 void *value;
34905 ssize_t(*show) (void *, char *);
34906 ssize_t(*store) (void *, const char *, size_t);
34907-};
34908+} __do_const;
34909
34910 /* Set of show/store abstract level functions for PCI Parity object */
34911 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34912@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34913 edac_printk(KERN_CRIT, EDAC_PCI,
34914 "Signaled System Error on %s\n",
34915 pci_name(dev));
34916- atomic_inc(&pci_nonparity_count);
34917+ atomic_inc_unchecked(&pci_nonparity_count);
34918 }
34919
34920 if (status & (PCI_STATUS_PARITY)) {
34921@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34922 "Master Data Parity Error on %s\n",
34923 pci_name(dev));
34924
34925- atomic_inc(&pci_parity_count);
34926+ atomic_inc_unchecked(&pci_parity_count);
34927 }
34928
34929 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34930@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34931 "Detected Parity Error on %s\n",
34932 pci_name(dev));
34933
34934- atomic_inc(&pci_parity_count);
34935+ atomic_inc_unchecked(&pci_parity_count);
34936 }
34937 }
34938
34939@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34940 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34941 "Signaled System Error on %s\n",
34942 pci_name(dev));
34943- atomic_inc(&pci_nonparity_count);
34944+ atomic_inc_unchecked(&pci_nonparity_count);
34945 }
34946
34947 if (status & (PCI_STATUS_PARITY)) {
34948@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34949 "Master Data Parity Error on "
34950 "%s\n", pci_name(dev));
34951
34952- atomic_inc(&pci_parity_count);
34953+ atomic_inc_unchecked(&pci_parity_count);
34954 }
34955
34956 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34957@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34958 "Detected Parity Error on %s\n",
34959 pci_name(dev));
34960
34961- atomic_inc(&pci_parity_count);
34962+ atomic_inc_unchecked(&pci_parity_count);
34963 }
34964 }
34965 }
34966@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34967 if (!check_pci_errors)
34968 return;
34969
34970- before_count = atomic_read(&pci_parity_count);
34971+ before_count = atomic_read_unchecked(&pci_parity_count);
34972
34973 /* scan all PCI devices looking for a Parity Error on devices and
34974 * bridges.
34975@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34976 /* Only if operator has selected panic on PCI Error */
34977 if (edac_pci_get_panic_on_pe()) {
34978 /* If the count is different 'after' from 'before' */
34979- if (before_count != atomic_read(&pci_parity_count))
34980+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34981 panic("EDAC: PCI Parity Error");
34982 }
34983 }
34984diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34985index 51b7e3a..aa8a3e8 100644
34986--- a/drivers/edac/mce_amd.h
34987+++ b/drivers/edac/mce_amd.h
34988@@ -77,7 +77,7 @@ struct amd_decoder_ops {
34989 bool (*mc0_mce)(u16, u8);
34990 bool (*mc1_mce)(u16, u8);
34991 bool (*mc2_mce)(u16, u8);
34992-};
34993+} __no_const;
34994
34995 void amd_report_gart_errors(bool);
34996 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34997diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34998index 57ea7f4..789e3c3 100644
34999--- a/drivers/firewire/core-card.c
35000+++ b/drivers/firewire/core-card.c
35001@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
35002
35003 void fw_core_remove_card(struct fw_card *card)
35004 {
35005- struct fw_card_driver dummy_driver = dummy_driver_template;
35006+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
35007
35008 card->driver->update_phy_reg(card, 4,
35009 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
35010diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
35011index 664a6ff..af13580 100644
35012--- a/drivers/firewire/core-device.c
35013+++ b/drivers/firewire/core-device.c
35014@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
35015 struct config_rom_attribute {
35016 struct device_attribute attr;
35017 u32 key;
35018-};
35019+} __do_const;
35020
35021 static ssize_t show_immediate(struct device *dev,
35022 struct device_attribute *dattr, char *buf)
35023diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
35024index 28a94c7..58da63a 100644
35025--- a/drivers/firewire/core-transaction.c
35026+++ b/drivers/firewire/core-transaction.c
35027@@ -38,6 +38,7 @@
35028 #include <linux/timer.h>
35029 #include <linux/types.h>
35030 #include <linux/workqueue.h>
35031+#include <linux/sched.h>
35032
35033 #include <asm/byteorder.h>
35034
35035diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
35036index 515a42c..5ecf3ba 100644
35037--- a/drivers/firewire/core.h
35038+++ b/drivers/firewire/core.h
35039@@ -111,6 +111,7 @@ struct fw_card_driver {
35040
35041 int (*stop_iso)(struct fw_iso_context *ctx);
35042 };
35043+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
35044
35045 void fw_card_initialize(struct fw_card *card,
35046 const struct fw_card_driver *driver, struct device *device);
35047diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
35048index 94a58a0..f5eba42 100644
35049--- a/drivers/firmware/dmi-id.c
35050+++ b/drivers/firmware/dmi-id.c
35051@@ -16,7 +16,7 @@
35052 struct dmi_device_attribute{
35053 struct device_attribute dev_attr;
35054 int field;
35055-};
35056+} __do_const;
35057 #define to_dmi_dev_attr(_dev_attr) \
35058 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
35059
35060diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
35061index b95159b..841ae55 100644
35062--- a/drivers/firmware/dmi_scan.c
35063+++ b/drivers/firmware/dmi_scan.c
35064@@ -497,11 +497,6 @@ void __init dmi_scan_machine(void)
35065 }
35066 }
35067 else {
35068- /*
35069- * no iounmap() for that ioremap(); it would be a no-op, but
35070- * it's so early in setup that sucker gets confused into doing
35071- * what it shouldn't if we actually call it.
35072- */
35073 p = dmi_ioremap(0xF0000, 0x10000);
35074 if (p == NULL)
35075 goto error;
35076@@ -786,7 +781,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
35077 if (buf == NULL)
35078 return -1;
35079
35080- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
35081+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
35082
35083 iounmap(buf);
35084 return 0;
35085diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
35086index 5145fa3..0d3babd 100644
35087--- a/drivers/firmware/efi/efi.c
35088+++ b/drivers/firmware/efi/efi.c
35089@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
35090 };
35091
35092 static struct efivars generic_efivars;
35093-static struct efivar_operations generic_ops;
35094+static efivar_operations_no_const generic_ops __read_only;
35095
35096 static int generic_ops_register(void)
35097 {
35098- generic_ops.get_variable = efi.get_variable;
35099- generic_ops.set_variable = efi.set_variable;
35100- generic_ops.get_next_variable = efi.get_next_variable;
35101- generic_ops.query_variable_store = efi_query_variable_store;
35102+ pax_open_kernel();
35103+ *(void **)&generic_ops.get_variable = efi.get_variable;
35104+ *(void **)&generic_ops.set_variable = efi.set_variable;
35105+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
35106+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
35107+ pax_close_kernel();
35108
35109 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
35110 }
35111diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
35112index 8bd1bb6..c48b0c6 100644
35113--- a/drivers/firmware/efi/efivars.c
35114+++ b/drivers/firmware/efi/efivars.c
35115@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
35116 static int
35117 create_efivars_bin_attributes(void)
35118 {
35119- struct bin_attribute *attr;
35120+ bin_attribute_no_const *attr;
35121 int error;
35122
35123 /* new_var */
35124diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
35125index 2a90ba6..07f3733 100644
35126--- a/drivers/firmware/google/memconsole.c
35127+++ b/drivers/firmware/google/memconsole.c
35128@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
35129 if (!found_memconsole())
35130 return -ENODEV;
35131
35132- memconsole_bin_attr.size = memconsole_length;
35133+ pax_open_kernel();
35134+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
35135+ pax_close_kernel();
35136
35137 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
35138
35139diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
35140index e16d932..f0206ef 100644
35141--- a/drivers/gpio/gpio-ich.c
35142+++ b/drivers/gpio/gpio-ich.c
35143@@ -69,7 +69,7 @@ struct ichx_desc {
35144 /* Some chipsets have quirks, let these use their own request/get */
35145 int (*request)(struct gpio_chip *chip, unsigned offset);
35146 int (*get)(struct gpio_chip *chip, unsigned offset);
35147-};
35148+} __do_const;
35149
35150 static struct {
35151 spinlock_t lock;
35152diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
35153index 9902732..64b62dd 100644
35154--- a/drivers/gpio/gpio-vr41xx.c
35155+++ b/drivers/gpio/gpio-vr41xx.c
35156@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
35157 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
35158 maskl, pendl, maskh, pendh);
35159
35160- atomic_inc(&irq_err_count);
35161+ atomic_inc_unchecked(&irq_err_count);
35162
35163 return -EINVAL;
35164 }
35165diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
35166index ed1334e..ee0dd42 100644
35167--- a/drivers/gpu/drm/drm_crtc_helper.c
35168+++ b/drivers/gpu/drm/drm_crtc_helper.c
35169@@ -321,7 +321,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
35170 struct drm_crtc *tmp;
35171 int crtc_mask = 1;
35172
35173- WARN(!crtc, "checking null crtc?\n");
35174+ BUG_ON(!crtc);
35175
35176 dev = crtc->dev;
35177
35178diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
35179index 9cc247f..36aa285 100644
35180--- a/drivers/gpu/drm/drm_drv.c
35181+++ b/drivers/gpu/drm/drm_drv.c
35182@@ -306,7 +306,7 @@ module_exit(drm_core_exit);
35183 /**
35184 * Copy and IOCTL return string to user space
35185 */
35186-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
35187+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
35188 {
35189 int len;
35190
35191@@ -376,7 +376,7 @@ long drm_ioctl(struct file *filp,
35192 struct drm_file *file_priv = filp->private_data;
35193 struct drm_device *dev;
35194 const struct drm_ioctl_desc *ioctl = NULL;
35195- drm_ioctl_t *func;
35196+ drm_ioctl_no_const_t func;
35197 unsigned int nr = DRM_IOCTL_NR(cmd);
35198 int retcode = -EINVAL;
35199 char stack_kdata[128];
35200@@ -389,7 +389,7 @@ long drm_ioctl(struct file *filp,
35201 return -ENODEV;
35202
35203 atomic_inc(&dev->ioctl_count);
35204- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
35205+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
35206 ++file_priv->ioctl_count;
35207
35208 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
35209diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
35210index 429e07d..e681a2c 100644
35211--- a/drivers/gpu/drm/drm_fops.c
35212+++ b/drivers/gpu/drm/drm_fops.c
35213@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
35214 }
35215
35216 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
35217- atomic_set(&dev->counts[i], 0);
35218+ atomic_set_unchecked(&dev->counts[i], 0);
35219
35220 dev->sigdata.lock = NULL;
35221
35222@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
35223 if (drm_device_is_unplugged(dev))
35224 return -ENODEV;
35225
35226- if (!dev->open_count++)
35227+ if (local_inc_return(&dev->open_count) == 1)
35228 need_setup = 1;
35229 mutex_lock(&dev->struct_mutex);
35230 old_imapping = inode->i_mapping;
35231@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
35232 retcode = drm_open_helper(inode, filp, dev);
35233 if (retcode)
35234 goto err_undo;
35235- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
35236+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
35237 if (need_setup) {
35238 retcode = drm_setup(dev);
35239 if (retcode)
35240@@ -166,7 +166,7 @@ err_undo:
35241 iput(container_of(dev->dev_mapping, struct inode, i_data));
35242 dev->dev_mapping = old_mapping;
35243 mutex_unlock(&dev->struct_mutex);
35244- dev->open_count--;
35245+ local_dec(&dev->open_count);
35246 return retcode;
35247 }
35248 EXPORT_SYMBOL(drm_open);
35249@@ -441,7 +441,7 @@ int drm_release(struct inode *inode, struct file *filp)
35250
35251 mutex_lock(&drm_global_mutex);
35252
35253- DRM_DEBUG("open_count = %d\n", dev->open_count);
35254+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
35255
35256 if (dev->driver->preclose)
35257 dev->driver->preclose(dev, file_priv);
35258@@ -450,10 +450,10 @@ int drm_release(struct inode *inode, struct file *filp)
35259 * Begin inline drm_release
35260 */
35261
35262- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
35263+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
35264 task_pid_nr(current),
35265 (long)old_encode_dev(file_priv->minor->device),
35266- dev->open_count);
35267+ local_read(&dev->open_count));
35268
35269 /* Release any auth tokens that might point to this file_priv,
35270 (do that under the drm_global_mutex) */
35271@@ -550,8 +550,8 @@ int drm_release(struct inode *inode, struct file *filp)
35272 * End inline drm_release
35273 */
35274
35275- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
35276- if (!--dev->open_count) {
35277+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
35278+ if (local_dec_and_test(&dev->open_count)) {
35279 if (atomic_read(&dev->ioctl_count)) {
35280 DRM_ERROR("Device busy: %d\n",
35281 atomic_read(&dev->ioctl_count));
35282diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
35283index f731116..629842c 100644
35284--- a/drivers/gpu/drm/drm_global.c
35285+++ b/drivers/gpu/drm/drm_global.c
35286@@ -36,7 +36,7 @@
35287 struct drm_global_item {
35288 struct mutex mutex;
35289 void *object;
35290- int refcount;
35291+ atomic_t refcount;
35292 };
35293
35294 static struct drm_global_item glob[DRM_GLOBAL_NUM];
35295@@ -49,7 +49,7 @@ void drm_global_init(void)
35296 struct drm_global_item *item = &glob[i];
35297 mutex_init(&item->mutex);
35298 item->object = NULL;
35299- item->refcount = 0;
35300+ atomic_set(&item->refcount, 0);
35301 }
35302 }
35303
35304@@ -59,7 +59,7 @@ void drm_global_release(void)
35305 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
35306 struct drm_global_item *item = &glob[i];
35307 BUG_ON(item->object != NULL);
35308- BUG_ON(item->refcount != 0);
35309+ BUG_ON(atomic_read(&item->refcount) != 0);
35310 }
35311 }
35312
35313@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35314 void *object;
35315
35316 mutex_lock(&item->mutex);
35317- if (item->refcount == 0) {
35318+ if (atomic_read(&item->refcount) == 0) {
35319 item->object = kzalloc(ref->size, GFP_KERNEL);
35320 if (unlikely(item->object == NULL)) {
35321 ret = -ENOMEM;
35322@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35323 goto out_err;
35324
35325 }
35326- ++item->refcount;
35327+ atomic_inc(&item->refcount);
35328 ref->object = item->object;
35329 object = item->object;
35330 mutex_unlock(&item->mutex);
35331@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
35332 struct drm_global_item *item = &glob[ref->global_type];
35333
35334 mutex_lock(&item->mutex);
35335- BUG_ON(item->refcount == 0);
35336+ BUG_ON(atomic_read(&item->refcount) == 0);
35337 BUG_ON(ref->object != item->object);
35338- if (--item->refcount == 0) {
35339+ if (atomic_dec_and_test(&item->refcount)) {
35340 ref->release(ref);
35341 item->object = NULL;
35342 }
35343diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
35344index d4b20ce..77a8d41 100644
35345--- a/drivers/gpu/drm/drm_info.c
35346+++ b/drivers/gpu/drm/drm_info.c
35347@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
35348 struct drm_local_map *map;
35349 struct drm_map_list *r_list;
35350
35351- /* Hardcoded from _DRM_FRAME_BUFFER,
35352- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
35353- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
35354- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
35355+ static const char * const types[] = {
35356+ [_DRM_FRAME_BUFFER] = "FB",
35357+ [_DRM_REGISTERS] = "REG",
35358+ [_DRM_SHM] = "SHM",
35359+ [_DRM_AGP] = "AGP",
35360+ [_DRM_SCATTER_GATHER] = "SG",
35361+ [_DRM_CONSISTENT] = "PCI",
35362+ [_DRM_GEM] = "GEM" };
35363 const char *type;
35364 int i;
35365
35366@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
35367 map = r_list->map;
35368 if (!map)
35369 continue;
35370- if (map->type < 0 || map->type > 5)
35371+ if (map->type >= ARRAY_SIZE(types))
35372 type = "??";
35373 else
35374 type = types[map->type];
35375@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
35376 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
35377 vma->vm_flags & VM_LOCKED ? 'l' : '-',
35378 vma->vm_flags & VM_IO ? 'i' : '-',
35379+#ifdef CONFIG_GRKERNSEC_HIDESYM
35380+ 0);
35381+#else
35382 vma->vm_pgoff);
35383+#endif
35384
35385 #if defined(__i386__)
35386 pgprot = pgprot_val(vma->vm_page_prot);
35387diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
35388index 2f4c434..dd12cd2 100644
35389--- a/drivers/gpu/drm/drm_ioc32.c
35390+++ b/drivers/gpu/drm/drm_ioc32.c
35391@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
35392 request = compat_alloc_user_space(nbytes);
35393 if (!access_ok(VERIFY_WRITE, request, nbytes))
35394 return -EFAULT;
35395- list = (struct drm_buf_desc *) (request + 1);
35396+ list = (struct drm_buf_desc __user *) (request + 1);
35397
35398 if (__put_user(count, &request->count)
35399 || __put_user(list, &request->list))
35400@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
35401 request = compat_alloc_user_space(nbytes);
35402 if (!access_ok(VERIFY_WRITE, request, nbytes))
35403 return -EFAULT;
35404- list = (struct drm_buf_pub *) (request + 1);
35405+ list = (struct drm_buf_pub __user *) (request + 1);
35406
35407 if (__put_user(count, &request->count)
35408 || __put_user(list, &request->list))
35409@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
35410 return 0;
35411 }
35412
35413-drm_ioctl_compat_t *drm_compat_ioctls[] = {
35414+drm_ioctl_compat_t drm_compat_ioctls[] = {
35415 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
35416 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
35417 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
35418@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
35419 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35420 {
35421 unsigned int nr = DRM_IOCTL_NR(cmd);
35422- drm_ioctl_compat_t *fn;
35423 int ret;
35424
35425 /* Assume that ioctls without an explicit compat routine will just
35426@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35427 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
35428 return drm_ioctl(filp, cmd, arg);
35429
35430- fn = drm_compat_ioctls[nr];
35431-
35432- if (fn != NULL)
35433- ret = (*fn) (filp, cmd, arg);
35434+ if (drm_compat_ioctls[nr] != NULL)
35435+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
35436 else
35437 ret = drm_ioctl(filp, cmd, arg);
35438
35439diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
35440index e77bd8b..1571b85 100644
35441--- a/drivers/gpu/drm/drm_ioctl.c
35442+++ b/drivers/gpu/drm/drm_ioctl.c
35443@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
35444 stats->data[i].value =
35445 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
35446 else
35447- stats->data[i].value = atomic_read(&dev->counts[i]);
35448+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
35449 stats->data[i].type = dev->types[i];
35450 }
35451
35452diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
35453index d752c96..fe08455 100644
35454--- a/drivers/gpu/drm/drm_lock.c
35455+++ b/drivers/gpu/drm/drm_lock.c
35456@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35457 if (drm_lock_take(&master->lock, lock->context)) {
35458 master->lock.file_priv = file_priv;
35459 master->lock.lock_time = jiffies;
35460- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
35461+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
35462 break; /* Got lock */
35463 }
35464
35465@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35466 return -EINVAL;
35467 }
35468
35469- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
35470+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
35471
35472 if (drm_lock_free(&master->lock, lock->context)) {
35473 /* FIXME: Should really bail out here. */
35474diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
35475index 16f3ec5..b28f9ca 100644
35476--- a/drivers/gpu/drm/drm_stub.c
35477+++ b/drivers/gpu/drm/drm_stub.c
35478@@ -501,7 +501,7 @@ void drm_unplug_dev(struct drm_device *dev)
35479
35480 drm_device_set_unplugged(dev);
35481
35482- if (dev->open_count == 0) {
35483+ if (local_read(&dev->open_count) == 0) {
35484 drm_put_dev(dev);
35485 }
35486 mutex_unlock(&drm_global_mutex);
35487diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
35488index 0229665..f61329c 100644
35489--- a/drivers/gpu/drm/drm_sysfs.c
35490+++ b/drivers/gpu/drm/drm_sysfs.c
35491@@ -499,7 +499,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
35492 int drm_sysfs_device_add(struct drm_minor *minor)
35493 {
35494 int err;
35495- char *minor_str;
35496+ const char *minor_str;
35497
35498 minor->kdev.parent = minor->dev->dev;
35499
35500diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
35501index 004ecdf..db1f6e0 100644
35502--- a/drivers/gpu/drm/i810/i810_dma.c
35503+++ b/drivers/gpu/drm/i810/i810_dma.c
35504@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
35505 dma->buflist[vertex->idx],
35506 vertex->discard, vertex->used);
35507
35508- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35509- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35510+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35511+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35512 sarea_priv->last_enqueue = dev_priv->counter - 1;
35513 sarea_priv->last_dispatch = (int)hw_status[5];
35514
35515@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35516 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35517 mc->last_render);
35518
35519- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35520- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35521+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35522+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35523 sarea_priv->last_enqueue = dev_priv->counter - 1;
35524 sarea_priv->last_dispatch = (int)hw_status[5];
35525
35526diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35527index 6e0acad..93c8289 100644
35528--- a/drivers/gpu/drm/i810/i810_drv.h
35529+++ b/drivers/gpu/drm/i810/i810_drv.h
35530@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
35531 int page_flipping;
35532
35533 wait_queue_head_t irq_queue;
35534- atomic_t irq_received;
35535- atomic_t irq_emitted;
35536+ atomic_unchecked_t irq_received;
35537+ atomic_unchecked_t irq_emitted;
35538
35539 int front_offset;
35540 } drm_i810_private_t;
35541diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35542index e913d32..4d9b351 100644
35543--- a/drivers/gpu/drm/i915/i915_debugfs.c
35544+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35545@@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35546 I915_READ(GTIMR));
35547 }
35548 seq_printf(m, "Interrupts received: %d\n",
35549- atomic_read(&dev_priv->irq_received));
35550+ atomic_read_unchecked(&dev_priv->irq_received));
35551 for_each_ring(ring, dev_priv, i) {
35552 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35553 seq_printf(m,
35554diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35555index 3b315ba..aac280f 100644
35556--- a/drivers/gpu/drm/i915/i915_dma.c
35557+++ b/drivers/gpu/drm/i915/i915_dma.c
35558@@ -1259,7 +1259,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35559 bool can_switch;
35560
35561 spin_lock(&dev->count_lock);
35562- can_switch = (dev->open_count == 0);
35563+ can_switch = (local_read(&dev->open_count) == 0);
35564 spin_unlock(&dev->count_lock);
35565 return can_switch;
35566 }
35567diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35568index 9669a0b..bb65176 100644
35569--- a/drivers/gpu/drm/i915/i915_drv.h
35570+++ b/drivers/gpu/drm/i915/i915_drv.h
35571@@ -915,7 +915,7 @@ typedef struct drm_i915_private {
35572 drm_dma_handle_t *status_page_dmah;
35573 struct resource mch_res;
35574
35575- atomic_t irq_received;
35576+ atomic_unchecked_t irq_received;
35577
35578 /* protects the irq masks */
35579 spinlock_t irq_lock;
35580@@ -1811,7 +1811,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35581 struct drm_i915_private *dev_priv, unsigned port);
35582 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35583 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35584-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35585+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35586 {
35587 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35588 }
35589diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35590index 117ce38..eefd237 100644
35591--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35592+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35593@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35594
35595 static int
35596 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35597- int count)
35598+ unsigned int count)
35599 {
35600- int i;
35601+ unsigned int i;
35602 int relocs_total = 0;
35603 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35604
35605diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35606index 3c59584..500f2e9 100644
35607--- a/drivers/gpu/drm/i915/i915_ioc32.c
35608+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35609@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35610 (unsigned long)request);
35611 }
35612
35613-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35614+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35615 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35616 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35617 [DRM_I915_GETPARAM] = compat_i915_getparam,
35618@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35619 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35620 {
35621 unsigned int nr = DRM_IOCTL_NR(cmd);
35622- drm_ioctl_compat_t *fn = NULL;
35623 int ret;
35624
35625 if (nr < DRM_COMMAND_BASE)
35626 return drm_compat_ioctl(filp, cmd, arg);
35627
35628- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35629- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35630-
35631- if (fn != NULL)
35632+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35633+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35634 ret = (*fn) (filp, cmd, arg);
35635- else
35636+ } else
35637 ret = drm_ioctl(filp, cmd, arg);
35638
35639 return ret;
35640diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35641index 0aa2ef0..77c03d0 100644
35642--- a/drivers/gpu/drm/i915/i915_irq.c
35643+++ b/drivers/gpu/drm/i915/i915_irq.c
35644@@ -679,7 +679,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35645 int pipe;
35646 u32 pipe_stats[I915_MAX_PIPES];
35647
35648- atomic_inc(&dev_priv->irq_received);
35649+ atomic_inc_unchecked(&dev_priv->irq_received);
35650
35651 while (true) {
35652 iir = I915_READ(VLV_IIR);
35653@@ -844,7 +844,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35654 irqreturn_t ret = IRQ_NONE;
35655 int i;
35656
35657- atomic_inc(&dev_priv->irq_received);
35658+ atomic_inc_unchecked(&dev_priv->irq_received);
35659
35660 /* disable master interrupt before clearing iir */
35661 de_ier = I915_READ(DEIER);
35662@@ -934,7 +934,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35663 int ret = IRQ_NONE;
35664 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
35665
35666- atomic_inc(&dev_priv->irq_received);
35667+ atomic_inc_unchecked(&dev_priv->irq_received);
35668
35669 /* disable master interrupt before clearing iir */
35670 de_ier = I915_READ(DEIER);
35671@@ -2098,7 +2098,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35672 {
35673 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35674
35675- atomic_set(&dev_priv->irq_received, 0);
35676+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35677
35678 I915_WRITE(HWSTAM, 0xeffe);
35679
35680@@ -2133,7 +2133,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35681 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35682 int pipe;
35683
35684- atomic_set(&dev_priv->irq_received, 0);
35685+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35686
35687 /* VLV magic */
35688 I915_WRITE(VLV_IMR, 0);
35689@@ -2420,7 +2420,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35690 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35691 int pipe;
35692
35693- atomic_set(&dev_priv->irq_received, 0);
35694+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35695
35696 for_each_pipe(pipe)
35697 I915_WRITE(PIPESTAT(pipe), 0);
35698@@ -2499,7 +2499,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35699 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35700 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35701
35702- atomic_inc(&dev_priv->irq_received);
35703+ atomic_inc_unchecked(&dev_priv->irq_received);
35704
35705 iir = I915_READ16(IIR);
35706 if (iir == 0)
35707@@ -2574,7 +2574,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35708 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35709 int pipe;
35710
35711- atomic_set(&dev_priv->irq_received, 0);
35712+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35713
35714 if (I915_HAS_HOTPLUG(dev)) {
35715 I915_WRITE(PORT_HOTPLUG_EN, 0);
35716@@ -2673,7 +2673,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35717 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35718 int pipe, ret = IRQ_NONE;
35719
35720- atomic_inc(&dev_priv->irq_received);
35721+ atomic_inc_unchecked(&dev_priv->irq_received);
35722
35723 iir = I915_READ(IIR);
35724 do {
35725@@ -2800,7 +2800,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35726 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35727 int pipe;
35728
35729- atomic_set(&dev_priv->irq_received, 0);
35730+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35731
35732 I915_WRITE(PORT_HOTPLUG_EN, 0);
35733 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35734@@ -2907,7 +2907,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35735 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35736 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35737
35738- atomic_inc(&dev_priv->irq_received);
35739+ atomic_inc_unchecked(&dev_priv->irq_received);
35740
35741 iir = I915_READ(IIR);
35742
35743diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35744index 56746dc..b5a214f 100644
35745--- a/drivers/gpu/drm/i915/intel_display.c
35746+++ b/drivers/gpu/drm/i915/intel_display.c
35747@@ -8919,13 +8919,13 @@ struct intel_quirk {
35748 int subsystem_vendor;
35749 int subsystem_device;
35750 void (*hook)(struct drm_device *dev);
35751-};
35752+} __do_const;
35753
35754 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35755 struct intel_dmi_quirk {
35756 void (*hook)(struct drm_device *dev);
35757 const struct dmi_system_id (*dmi_id_list)[];
35758-};
35759+} __do_const;
35760
35761 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35762 {
35763@@ -8933,18 +8933,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35764 return 1;
35765 }
35766
35767-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35768+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35769 {
35770- .dmi_id_list = &(const struct dmi_system_id[]) {
35771- {
35772- .callback = intel_dmi_reverse_brightness,
35773- .ident = "NCR Corporation",
35774- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35775- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35776- },
35777- },
35778- { } /* terminating entry */
35779+ .callback = intel_dmi_reverse_brightness,
35780+ .ident = "NCR Corporation",
35781+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35782+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35783 },
35784+ },
35785+ { } /* terminating entry */
35786+};
35787+
35788+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35789+ {
35790+ .dmi_id_list = &intel_dmi_quirks_table,
35791 .hook = quirk_invert_brightness,
35792 },
35793 };
35794diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35795index 54558a0..2d97005 100644
35796--- a/drivers/gpu/drm/mga/mga_drv.h
35797+++ b/drivers/gpu/drm/mga/mga_drv.h
35798@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35799 u32 clear_cmd;
35800 u32 maccess;
35801
35802- atomic_t vbl_received; /**< Number of vblanks received. */
35803+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35804 wait_queue_head_t fence_queue;
35805- atomic_t last_fence_retired;
35806+ atomic_unchecked_t last_fence_retired;
35807 u32 next_fence_to_post;
35808
35809 unsigned int fb_cpp;
35810diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35811index 709e90d..89a1c0d 100644
35812--- a/drivers/gpu/drm/mga/mga_ioc32.c
35813+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35814@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35815 return 0;
35816 }
35817
35818-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35819+drm_ioctl_compat_t mga_compat_ioctls[] = {
35820 [DRM_MGA_INIT] = compat_mga_init,
35821 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35822 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35823@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35824 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35825 {
35826 unsigned int nr = DRM_IOCTL_NR(cmd);
35827- drm_ioctl_compat_t *fn = NULL;
35828 int ret;
35829
35830 if (nr < DRM_COMMAND_BASE)
35831 return drm_compat_ioctl(filp, cmd, arg);
35832
35833- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35834- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35835-
35836- if (fn != NULL)
35837+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35838+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35839 ret = (*fn) (filp, cmd, arg);
35840- else
35841+ } else
35842 ret = drm_ioctl(filp, cmd, arg);
35843
35844 return ret;
35845diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35846index 598c281..60d590e 100644
35847--- a/drivers/gpu/drm/mga/mga_irq.c
35848+++ b/drivers/gpu/drm/mga/mga_irq.c
35849@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35850 if (crtc != 0)
35851 return 0;
35852
35853- return atomic_read(&dev_priv->vbl_received);
35854+ return atomic_read_unchecked(&dev_priv->vbl_received);
35855 }
35856
35857
35858@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35859 /* VBLANK interrupt */
35860 if (status & MGA_VLINEPEN) {
35861 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35862- atomic_inc(&dev_priv->vbl_received);
35863+ atomic_inc_unchecked(&dev_priv->vbl_received);
35864 drm_handle_vblank(dev, 0);
35865 handled = 1;
35866 }
35867@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35868 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35869 MGA_WRITE(MGA_PRIMEND, prim_end);
35870
35871- atomic_inc(&dev_priv->last_fence_retired);
35872+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35873 DRM_WAKEUP(&dev_priv->fence_queue);
35874 handled = 1;
35875 }
35876@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35877 * using fences.
35878 */
35879 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35880- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35881+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35882 - *sequence) <= (1 << 23)));
35883
35884 *sequence = cur_fence;
35885diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35886index 6aa2137..fe8dc55 100644
35887--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35888+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35889@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35890 struct bit_table {
35891 const char id;
35892 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35893-};
35894+} __no_const;
35895
35896 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35897
35898diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35899index f2b30f8..d0f9a95 100644
35900--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35901+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35902@@ -92,7 +92,7 @@ struct nouveau_drm {
35903 struct drm_global_reference mem_global_ref;
35904 struct ttm_bo_global_ref bo_global_ref;
35905 struct ttm_bo_device bdev;
35906- atomic_t validate_sequence;
35907+ atomic_unchecked_t validate_sequence;
35908 int (*move)(struct nouveau_channel *,
35909 struct ttm_buffer_object *,
35910 struct ttm_mem_reg *, struct ttm_mem_reg *);
35911diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35912index b4b4d0c..b7edc15 100644
35913--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35914+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35915@@ -322,7 +322,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35916 int ret, i;
35917 struct nouveau_bo *res_bo = NULL;
35918
35919- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35920+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35921 retry:
35922 if (++trycnt > 100000) {
35923 NV_ERROR(cli, "%s failed and gave up.\n", __func__);
35924@@ -359,7 +359,7 @@ retry:
35925 if (ret) {
35926 validate_fini(op, NULL);
35927 if (unlikely(ret == -EAGAIN)) {
35928- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35929+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35930 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
35931 sequence);
35932 if (!ret)
35933diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35934index 08214bc..9208577 100644
35935--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35936+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35937@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35938 unsigned long arg)
35939 {
35940 unsigned int nr = DRM_IOCTL_NR(cmd);
35941- drm_ioctl_compat_t *fn = NULL;
35942+ drm_ioctl_compat_t fn = NULL;
35943 int ret;
35944
35945 if (nr < DRM_COMMAND_BASE)
35946diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35947index 25d3495..d81aaf6 100644
35948--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35949+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35950@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35951 bool can_switch;
35952
35953 spin_lock(&dev->count_lock);
35954- can_switch = (dev->open_count == 0);
35955+ can_switch = (local_read(&dev->open_count) == 0);
35956 spin_unlock(&dev->count_lock);
35957 return can_switch;
35958 }
35959diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
35960index 489cb8c..0b8d0d3 100644
35961--- a/drivers/gpu/drm/qxl/qxl_ttm.c
35962+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
35963@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
35964 }
35965 }
35966
35967-static struct vm_operations_struct qxl_ttm_vm_ops;
35968+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
35969 static const struct vm_operations_struct *ttm_vm_ops;
35970
35971 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
35972@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
35973 return r;
35974 if (unlikely(ttm_vm_ops == NULL)) {
35975 ttm_vm_ops = vma->vm_ops;
35976+ pax_open_kernel();
35977 qxl_ttm_vm_ops = *ttm_vm_ops;
35978 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
35979+ pax_close_kernel();
35980 }
35981 vma->vm_ops = &qxl_ttm_vm_ops;
35982 return 0;
35983@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
35984 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
35985 {
35986 #if defined(CONFIG_DEBUG_FS)
35987- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
35988- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
35989- unsigned i;
35990+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
35991+ {
35992+ .name = "qxl_mem_mm",
35993+ .show = &qxl_mm_dump_table,
35994+ },
35995+ {
35996+ .name = "qxl_surf_mm",
35997+ .show = &qxl_mm_dump_table,
35998+ }
35999+ };
36000
36001- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
36002- if (i == 0)
36003- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
36004- else
36005- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
36006- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
36007- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
36008- qxl_mem_types_list[i].driver_features = 0;
36009- if (i == 0)
36010- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
36011- else
36012- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
36013+ pax_open_kernel();
36014+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
36015+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
36016+ pax_close_kernel();
36017
36018- }
36019- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
36020+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
36021 #else
36022 return 0;
36023 #endif
36024diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
36025index d4660cf..70dbe65 100644
36026--- a/drivers/gpu/drm/r128/r128_cce.c
36027+++ b/drivers/gpu/drm/r128/r128_cce.c
36028@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
36029
36030 /* GH: Simple idle check.
36031 */
36032- atomic_set(&dev_priv->idle_count, 0);
36033+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36034
36035 /* We don't support anything other than bus-mastering ring mode,
36036 * but the ring can be in either AGP or PCI space for the ring
36037diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
36038index 930c71b..499aded 100644
36039--- a/drivers/gpu/drm/r128/r128_drv.h
36040+++ b/drivers/gpu/drm/r128/r128_drv.h
36041@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
36042 int is_pci;
36043 unsigned long cce_buffers_offset;
36044
36045- atomic_t idle_count;
36046+ atomic_unchecked_t idle_count;
36047
36048 int page_flipping;
36049 int current_page;
36050 u32 crtc_offset;
36051 u32 crtc_offset_cntl;
36052
36053- atomic_t vbl_received;
36054+ atomic_unchecked_t vbl_received;
36055
36056 u32 color_fmt;
36057 unsigned int front_offset;
36058diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
36059index a954c54..9cc595c 100644
36060--- a/drivers/gpu/drm/r128/r128_ioc32.c
36061+++ b/drivers/gpu/drm/r128/r128_ioc32.c
36062@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
36063 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
36064 }
36065
36066-drm_ioctl_compat_t *r128_compat_ioctls[] = {
36067+drm_ioctl_compat_t r128_compat_ioctls[] = {
36068 [DRM_R128_INIT] = compat_r128_init,
36069 [DRM_R128_DEPTH] = compat_r128_depth,
36070 [DRM_R128_STIPPLE] = compat_r128_stipple,
36071@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
36072 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36073 {
36074 unsigned int nr = DRM_IOCTL_NR(cmd);
36075- drm_ioctl_compat_t *fn = NULL;
36076 int ret;
36077
36078 if (nr < DRM_COMMAND_BASE)
36079 return drm_compat_ioctl(filp, cmd, arg);
36080
36081- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
36082- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36083-
36084- if (fn != NULL)
36085+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
36086+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36087 ret = (*fn) (filp, cmd, arg);
36088- else
36089+ } else
36090 ret = drm_ioctl(filp, cmd, arg);
36091
36092 return ret;
36093diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
36094index 2ea4f09..d391371 100644
36095--- a/drivers/gpu/drm/r128/r128_irq.c
36096+++ b/drivers/gpu/drm/r128/r128_irq.c
36097@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
36098 if (crtc != 0)
36099 return 0;
36100
36101- return atomic_read(&dev_priv->vbl_received);
36102+ return atomic_read_unchecked(&dev_priv->vbl_received);
36103 }
36104
36105 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36106@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36107 /* VBLANK interrupt */
36108 if (status & R128_CRTC_VBLANK_INT) {
36109 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
36110- atomic_inc(&dev_priv->vbl_received);
36111+ atomic_inc_unchecked(&dev_priv->vbl_received);
36112 drm_handle_vblank(dev, 0);
36113 return IRQ_HANDLED;
36114 }
36115diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
36116index 19bb7e6..de7e2a2 100644
36117--- a/drivers/gpu/drm/r128/r128_state.c
36118+++ b/drivers/gpu/drm/r128/r128_state.c
36119@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
36120
36121 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
36122 {
36123- if (atomic_read(&dev_priv->idle_count) == 0)
36124+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
36125 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
36126 else
36127- atomic_set(&dev_priv->idle_count, 0);
36128+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36129 }
36130
36131 #endif
36132diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
36133index 5a82b6b..9e69c73 100644
36134--- a/drivers/gpu/drm/radeon/mkregtable.c
36135+++ b/drivers/gpu/drm/radeon/mkregtable.c
36136@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
36137 regex_t mask_rex;
36138 regmatch_t match[4];
36139 char buf[1024];
36140- size_t end;
36141+ long end;
36142 int len;
36143 int done = 0;
36144 int r;
36145 unsigned o;
36146 struct offset *offset;
36147 char last_reg_s[10];
36148- int last_reg;
36149+ unsigned long last_reg;
36150
36151 if (regcomp
36152 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
36153diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
36154index b0dc0b6..a9bfe9c 100644
36155--- a/drivers/gpu/drm/radeon/radeon_device.c
36156+++ b/drivers/gpu/drm/radeon/radeon_device.c
36157@@ -1014,7 +1014,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
36158 bool can_switch;
36159
36160 spin_lock(&dev->count_lock);
36161- can_switch = (dev->open_count == 0);
36162+ can_switch = (local_read(&dev->open_count) == 0);
36163 spin_unlock(&dev->count_lock);
36164 return can_switch;
36165 }
36166diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
36167index b369d42..8dd04eb 100644
36168--- a/drivers/gpu/drm/radeon/radeon_drv.h
36169+++ b/drivers/gpu/drm/radeon/radeon_drv.h
36170@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
36171
36172 /* SW interrupt */
36173 wait_queue_head_t swi_queue;
36174- atomic_t swi_emitted;
36175+ atomic_unchecked_t swi_emitted;
36176 int vblank_crtc;
36177 uint32_t irq_enable_reg;
36178 uint32_t r500_disp_irq_reg;
36179diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
36180index c180df8..5fd8186 100644
36181--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
36182+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
36183@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36184 request = compat_alloc_user_space(sizeof(*request));
36185 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
36186 || __put_user(req32.param, &request->param)
36187- || __put_user((void __user *)(unsigned long)req32.value,
36188+ || __put_user((unsigned long)req32.value,
36189 &request->value))
36190 return -EFAULT;
36191
36192@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36193 #define compat_radeon_cp_setparam NULL
36194 #endif /* X86_64 || IA64 */
36195
36196-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36197+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
36198 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
36199 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
36200 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
36201@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36202 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36203 {
36204 unsigned int nr = DRM_IOCTL_NR(cmd);
36205- drm_ioctl_compat_t *fn = NULL;
36206 int ret;
36207
36208 if (nr < DRM_COMMAND_BASE)
36209 return drm_compat_ioctl(filp, cmd, arg);
36210
36211- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
36212- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36213-
36214- if (fn != NULL)
36215+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
36216+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36217 ret = (*fn) (filp, cmd, arg);
36218- else
36219+ } else
36220 ret = drm_ioctl(filp, cmd, arg);
36221
36222 return ret;
36223diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
36224index 8d68e97..9dcfed8 100644
36225--- a/drivers/gpu/drm/radeon/radeon_irq.c
36226+++ b/drivers/gpu/drm/radeon/radeon_irq.c
36227@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
36228 unsigned int ret;
36229 RING_LOCALS;
36230
36231- atomic_inc(&dev_priv->swi_emitted);
36232- ret = atomic_read(&dev_priv->swi_emitted);
36233+ atomic_inc_unchecked(&dev_priv->swi_emitted);
36234+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
36235
36236 BEGIN_RING(4);
36237 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
36238@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
36239 drm_radeon_private_t *dev_priv =
36240 (drm_radeon_private_t *) dev->dev_private;
36241
36242- atomic_set(&dev_priv->swi_emitted, 0);
36243+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
36244 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
36245
36246 dev->max_vblank_count = 0x001fffff;
36247diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
36248index 4d20910..6726b6d 100644
36249--- a/drivers/gpu/drm/radeon/radeon_state.c
36250+++ b/drivers/gpu/drm/radeon/radeon_state.c
36251@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
36252 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
36253 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
36254
36255- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36256+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36257 sarea_priv->nbox * sizeof(depth_boxes[0])))
36258 return -EFAULT;
36259
36260@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
36261 {
36262 drm_radeon_private_t *dev_priv = dev->dev_private;
36263 drm_radeon_getparam_t *param = data;
36264- int value;
36265+ int value = 0;
36266
36267 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
36268
36269diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
36270index 6c0ce89..57a2529 100644
36271--- a/drivers/gpu/drm/radeon/radeon_ttm.c
36272+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
36273@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
36274 man->size = size >> PAGE_SHIFT;
36275 }
36276
36277-static struct vm_operations_struct radeon_ttm_vm_ops;
36278+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
36279 static const struct vm_operations_struct *ttm_vm_ops = NULL;
36280
36281 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36282@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
36283 }
36284 if (unlikely(ttm_vm_ops == NULL)) {
36285 ttm_vm_ops = vma->vm_ops;
36286+ pax_open_kernel();
36287 radeon_ttm_vm_ops = *ttm_vm_ops;
36288 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
36289+ pax_close_kernel();
36290 }
36291 vma->vm_ops = &radeon_ttm_vm_ops;
36292 return 0;
36293@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
36294 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
36295 {
36296 #if defined(CONFIG_DEBUG_FS)
36297- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
36298- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
36299+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
36300+ {
36301+ .name = "radeon_vram_mm",
36302+ .show = &radeon_mm_dump_table,
36303+ },
36304+ {
36305+ .name = "radeon_gtt_mm",
36306+ .show = &radeon_mm_dump_table,
36307+ },
36308+ {
36309+ .name = "ttm_page_pool",
36310+ .show = &ttm_page_alloc_debugfs,
36311+ },
36312+ {
36313+ .name = "ttm_dma_page_pool",
36314+ .show = &ttm_dma_page_alloc_debugfs,
36315+ },
36316+ };
36317 unsigned i;
36318
36319- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
36320- if (i == 0)
36321- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
36322- else
36323- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
36324- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36325- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36326- radeon_mem_types_list[i].driver_features = 0;
36327- if (i == 0)
36328- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36329- else
36330- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36331-
36332- }
36333- /* Add ttm page pool to debugfs */
36334- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
36335- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36336- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36337- radeon_mem_types_list[i].driver_features = 0;
36338- radeon_mem_types_list[i++].data = NULL;
36339+ pax_open_kernel();
36340+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36341+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36342+ pax_close_kernel();
36343 #ifdef CONFIG_SWIOTLB
36344- if (swiotlb_nr_tbl()) {
36345- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
36346- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36347- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36348- radeon_mem_types_list[i].driver_features = 0;
36349- radeon_mem_types_list[i++].data = NULL;
36350- }
36351+ if (swiotlb_nr_tbl())
36352+ i++;
36353 #endif
36354 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
36355
36356diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
36357index 55880d5..9e95342 100644
36358--- a/drivers/gpu/drm/radeon/rs690.c
36359+++ b/drivers/gpu/drm/radeon/rs690.c
36360@@ -327,9 +327,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
36361 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
36362 rdev->pm.sideport_bandwidth.full)
36363 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
36364- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
36365+ read_delay_latency.full = dfixed_const(800 * 1000);
36366 read_delay_latency.full = dfixed_div(read_delay_latency,
36367 rdev->pm.igp_sideport_mclk);
36368+ a.full = dfixed_const(370);
36369+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
36370 } else {
36371 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
36372 rdev->pm.k8_bandwidth.full)
36373diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
36374index dbc2def..0a9f710 100644
36375--- a/drivers/gpu/drm/ttm/ttm_memory.c
36376+++ b/drivers/gpu/drm/ttm/ttm_memory.c
36377@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
36378 zone->glob = glob;
36379 glob->zone_kernel = zone;
36380 ret = kobject_init_and_add(
36381- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
36382+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
36383 if (unlikely(ret != 0)) {
36384 kobject_put(&zone->kobj);
36385 return ret;
36386@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
36387 zone->glob = glob;
36388 glob->zone_dma32 = zone;
36389 ret = kobject_init_and_add(
36390- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
36391+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
36392 if (unlikely(ret != 0)) {
36393 kobject_put(&zone->kobj);
36394 return ret;
36395diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36396index bd2a3b4..122d9ad 100644
36397--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
36398+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36399@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
36400 static int ttm_pool_mm_shrink(struct shrinker *shrink,
36401 struct shrink_control *sc)
36402 {
36403- static atomic_t start_pool = ATOMIC_INIT(0);
36404+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
36405 unsigned i;
36406- unsigned pool_offset = atomic_add_return(1, &start_pool);
36407+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
36408 struct ttm_page_pool *pool;
36409 int shrink_pages = sc->nr_to_scan;
36410
36411diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
36412index dc0c065..58a0782 100644
36413--- a/drivers/gpu/drm/udl/udl_fb.c
36414+++ b/drivers/gpu/drm/udl/udl_fb.c
36415@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
36416 fb_deferred_io_cleanup(info);
36417 kfree(info->fbdefio);
36418 info->fbdefio = NULL;
36419- info->fbops->fb_mmap = udl_fb_mmap;
36420 }
36421
36422 pr_warn("released /dev/fb%d user=%d count=%d\n",
36423diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
36424index 893a650..6190d3b 100644
36425--- a/drivers/gpu/drm/via/via_drv.h
36426+++ b/drivers/gpu/drm/via/via_drv.h
36427@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
36428 typedef uint32_t maskarray_t[5];
36429
36430 typedef struct drm_via_irq {
36431- atomic_t irq_received;
36432+ atomic_unchecked_t irq_received;
36433 uint32_t pending_mask;
36434 uint32_t enable_mask;
36435 wait_queue_head_t irq_queue;
36436@@ -75,7 +75,7 @@ typedef struct drm_via_private {
36437 struct timeval last_vblank;
36438 int last_vblank_valid;
36439 unsigned usec_per_vblank;
36440- atomic_t vbl_received;
36441+ atomic_unchecked_t vbl_received;
36442 drm_via_state_t hc_state;
36443 char pci_buf[VIA_PCI_BUF_SIZE];
36444 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
36445diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
36446index ac98964..5dbf512 100644
36447--- a/drivers/gpu/drm/via/via_irq.c
36448+++ b/drivers/gpu/drm/via/via_irq.c
36449@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
36450 if (crtc != 0)
36451 return 0;
36452
36453- return atomic_read(&dev_priv->vbl_received);
36454+ return atomic_read_unchecked(&dev_priv->vbl_received);
36455 }
36456
36457 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36458@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36459
36460 status = VIA_READ(VIA_REG_INTERRUPT);
36461 if (status & VIA_IRQ_VBLANK_PENDING) {
36462- atomic_inc(&dev_priv->vbl_received);
36463- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
36464+ atomic_inc_unchecked(&dev_priv->vbl_received);
36465+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
36466 do_gettimeofday(&cur_vblank);
36467 if (dev_priv->last_vblank_valid) {
36468 dev_priv->usec_per_vblank =
36469@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36470 dev_priv->last_vblank = cur_vblank;
36471 dev_priv->last_vblank_valid = 1;
36472 }
36473- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
36474+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
36475 DRM_DEBUG("US per vblank is: %u\n",
36476 dev_priv->usec_per_vblank);
36477 }
36478@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36479
36480 for (i = 0; i < dev_priv->num_irqs; ++i) {
36481 if (status & cur_irq->pending_mask) {
36482- atomic_inc(&cur_irq->irq_received);
36483+ atomic_inc_unchecked(&cur_irq->irq_received);
36484 DRM_WAKEUP(&cur_irq->irq_queue);
36485 handled = 1;
36486 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
36487@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
36488 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36489 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
36490 masks[irq][4]));
36491- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
36492+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
36493 } else {
36494 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36495 (((cur_irq_sequence =
36496- atomic_read(&cur_irq->irq_received)) -
36497+ atomic_read_unchecked(&cur_irq->irq_received)) -
36498 *sequence) <= (1 << 23)));
36499 }
36500 *sequence = cur_irq_sequence;
36501@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
36502 }
36503
36504 for (i = 0; i < dev_priv->num_irqs; ++i) {
36505- atomic_set(&cur_irq->irq_received, 0);
36506+ atomic_set_unchecked(&cur_irq->irq_received, 0);
36507 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
36508 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
36509 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
36510@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
36511 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
36512 case VIA_IRQ_RELATIVE:
36513 irqwait->request.sequence +=
36514- atomic_read(&cur_irq->irq_received);
36515+ atomic_read_unchecked(&cur_irq->irq_received);
36516 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
36517 case VIA_IRQ_ABSOLUTE:
36518 break;
36519diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36520index 13aeda7..4a952d1 100644
36521--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36522+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36523@@ -290,7 +290,7 @@ struct vmw_private {
36524 * Fencing and IRQs.
36525 */
36526
36527- atomic_t marker_seq;
36528+ atomic_unchecked_t marker_seq;
36529 wait_queue_head_t fence_queue;
36530 wait_queue_head_t fifo_queue;
36531 int fence_queue_waiters; /* Protected by hw_mutex */
36532diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36533index 3eb1486..0a47ee9 100644
36534--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36535+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36536@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
36537 (unsigned int) min,
36538 (unsigned int) fifo->capabilities);
36539
36540- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36541+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36542 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
36543 vmw_marker_queue_init(&fifo->marker_queue);
36544 return vmw_fifo_send_fence(dev_priv, &dummy);
36545@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
36546 if (reserveable)
36547 iowrite32(bytes, fifo_mem +
36548 SVGA_FIFO_RESERVED);
36549- return fifo_mem + (next_cmd >> 2);
36550+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36551 } else {
36552 need_bounce = true;
36553 }
36554@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36555
36556 fm = vmw_fifo_reserve(dev_priv, bytes);
36557 if (unlikely(fm == NULL)) {
36558- *seqno = atomic_read(&dev_priv->marker_seq);
36559+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36560 ret = -ENOMEM;
36561 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36562 false, 3*HZ);
36563@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36564 }
36565
36566 do {
36567- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36568+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36569 } while (*seqno == 0);
36570
36571 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36572diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36573index c509d40..3b640c3 100644
36574--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36575+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36576@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
36577 int ret;
36578
36579 num_clips = arg->num_clips;
36580- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36581+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36582
36583 if (unlikely(num_clips == 0))
36584 return 0;
36585@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
36586 int ret;
36587
36588 num_clips = arg->num_clips;
36589- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36590+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36591
36592 if (unlikely(num_clips == 0))
36593 return 0;
36594diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36595index 4640adb..e1384ed 100644
36596--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36597+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36598@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36599 * emitted. Then the fence is stale and signaled.
36600 */
36601
36602- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36603+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36604 > VMW_FENCE_WRAP);
36605
36606 return ret;
36607@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36608
36609 if (fifo_idle)
36610 down_read(&fifo_state->rwsem);
36611- signal_seq = atomic_read(&dev_priv->marker_seq);
36612+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36613 ret = 0;
36614
36615 for (;;) {
36616diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36617index 8a8725c2..afed796 100644
36618--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36619+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36620@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36621 while (!vmw_lag_lt(queue, us)) {
36622 spin_lock(&queue->lock);
36623 if (list_empty(&queue->head))
36624- seqno = atomic_read(&dev_priv->marker_seq);
36625+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36626 else {
36627 marker = list_first_entry(&queue->head,
36628 struct vmw_marker, head);
36629diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36630index 264f550..f92dd8c 100644
36631--- a/drivers/hid/hid-core.c
36632+++ b/drivers/hid/hid-core.c
36633@@ -2269,7 +2269,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36634
36635 int hid_add_device(struct hid_device *hdev)
36636 {
36637- static atomic_t id = ATOMIC_INIT(0);
36638+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36639 int ret;
36640
36641 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36642@@ -2303,7 +2303,7 @@ int hid_add_device(struct hid_device *hdev)
36643 /* XXX hack, any other cleaner solution after the driver core
36644 * is converted to allow more than 20 bytes as the device name? */
36645 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36646- hdev->vendor, hdev->product, atomic_inc_return(&id));
36647+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36648
36649 hid_debug_register(hdev, dev_name(&hdev->dev));
36650 ret = device_add(&hdev->dev);
36651diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36652index 90124ff..3761764 100644
36653--- a/drivers/hid/hid-wiimote-debug.c
36654+++ b/drivers/hid/hid-wiimote-debug.c
36655@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36656 else if (size == 0)
36657 return -EIO;
36658
36659- if (copy_to_user(u, buf, size))
36660+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36661 return -EFAULT;
36662
36663 *off += size;
36664diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36665index 0b122f8..b1d8160 100644
36666--- a/drivers/hv/channel.c
36667+++ b/drivers/hv/channel.c
36668@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36669 int ret = 0;
36670 int t;
36671
36672- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36673- atomic_inc(&vmbus_connection.next_gpadl_handle);
36674+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36675+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36676
36677 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36678 if (ret)
36679diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36680index ae49237..380d4c9 100644
36681--- a/drivers/hv/hv.c
36682+++ b/drivers/hv/hv.c
36683@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36684 u64 output_address = (output) ? virt_to_phys(output) : 0;
36685 u32 output_address_hi = output_address >> 32;
36686 u32 output_address_lo = output_address & 0xFFFFFFFF;
36687- void *hypercall_page = hv_context.hypercall_page;
36688+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36689
36690 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36691 "=a"(hv_status_lo) : "d" (control_hi),
36692diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36693index 12f2f9e..679603c 100644
36694--- a/drivers/hv/hyperv_vmbus.h
36695+++ b/drivers/hv/hyperv_vmbus.h
36696@@ -591,7 +591,7 @@ enum vmbus_connect_state {
36697 struct vmbus_connection {
36698 enum vmbus_connect_state conn_state;
36699
36700- atomic_t next_gpadl_handle;
36701+ atomic_unchecked_t next_gpadl_handle;
36702
36703 /*
36704 * Represents channel interrupts. Each bit position represents a
36705diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36706index bf421e0..ce2c897 100644
36707--- a/drivers/hv/vmbus_drv.c
36708+++ b/drivers/hv/vmbus_drv.c
36709@@ -668,10 +668,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36710 {
36711 int ret = 0;
36712
36713- static atomic_t device_num = ATOMIC_INIT(0);
36714+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36715
36716 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36717- atomic_inc_return(&device_num));
36718+ atomic_inc_return_unchecked(&device_num));
36719
36720 child_device_obj->device.bus = &hv_bus;
36721 child_device_obj->device.parent = &hv_acpi_dev->dev;
36722diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36723index 6351aba..dc4aaf4 100644
36724--- a/drivers/hwmon/acpi_power_meter.c
36725+++ b/drivers/hwmon/acpi_power_meter.c
36726@@ -117,7 +117,7 @@ struct sensor_template {
36727 struct device_attribute *devattr,
36728 const char *buf, size_t count);
36729 int index;
36730-};
36731+} __do_const;
36732
36733 /* Averaging interval */
36734 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36735@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36736 struct sensor_template *attrs)
36737 {
36738 struct device *dev = &resource->acpi_dev->dev;
36739- struct sensor_device_attribute *sensors =
36740+ sensor_device_attribute_no_const *sensors =
36741 &resource->sensors[resource->num_sensors];
36742 int res = 0;
36743
36744diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36745index 62c2e32..8f2859a 100644
36746--- a/drivers/hwmon/applesmc.c
36747+++ b/drivers/hwmon/applesmc.c
36748@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36749 {
36750 struct applesmc_node_group *grp;
36751 struct applesmc_dev_attr *node;
36752- struct attribute *attr;
36753+ attribute_no_const *attr;
36754 int ret, i;
36755
36756 for (grp = groups; grp->format; grp++) {
36757diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36758index b25c643..a13460d 100644
36759--- a/drivers/hwmon/asus_atk0110.c
36760+++ b/drivers/hwmon/asus_atk0110.c
36761@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36762 struct atk_sensor_data {
36763 struct list_head list;
36764 struct atk_data *data;
36765- struct device_attribute label_attr;
36766- struct device_attribute input_attr;
36767- struct device_attribute limit1_attr;
36768- struct device_attribute limit2_attr;
36769+ device_attribute_no_const label_attr;
36770+ device_attribute_no_const input_attr;
36771+ device_attribute_no_const limit1_attr;
36772+ device_attribute_no_const limit2_attr;
36773 char label_attr_name[ATTR_NAME_SIZE];
36774 char input_attr_name[ATTR_NAME_SIZE];
36775 char limit1_attr_name[ATTR_NAME_SIZE];
36776@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36777 static struct device_attribute atk_name_attr =
36778 __ATTR(name, 0444, atk_name_show, NULL);
36779
36780-static void atk_init_attribute(struct device_attribute *attr, char *name,
36781+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36782 sysfs_show_func show)
36783 {
36784 sysfs_attr_init(&attr->attr);
36785diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36786index 658ce3a..0d0c2f3 100644
36787--- a/drivers/hwmon/coretemp.c
36788+++ b/drivers/hwmon/coretemp.c
36789@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36790 return NOTIFY_OK;
36791 }
36792
36793-static struct notifier_block coretemp_cpu_notifier __refdata = {
36794+static struct notifier_block coretemp_cpu_notifier = {
36795 .notifier_call = coretemp_cpu_callback,
36796 };
36797
36798diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36799index 1429f6e..ee03d59 100644
36800--- a/drivers/hwmon/ibmaem.c
36801+++ b/drivers/hwmon/ibmaem.c
36802@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
36803 struct aem_rw_sensor_template *rw)
36804 {
36805 struct device *dev = &data->pdev->dev;
36806- struct sensor_device_attribute *sensors = data->sensors;
36807+ sensor_device_attribute_no_const *sensors = data->sensors;
36808 int err;
36809
36810 /* Set up read-only sensors */
36811diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
36812index 52b77af..aed1ddf 100644
36813--- a/drivers/hwmon/iio_hwmon.c
36814+++ b/drivers/hwmon/iio_hwmon.c
36815@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
36816 {
36817 struct device *dev = &pdev->dev;
36818 struct iio_hwmon_state *st;
36819- struct sensor_device_attribute *a;
36820+ sensor_device_attribute_no_const *a;
36821 int ret, i;
36822 int in_i = 1, temp_i = 1, curr_i = 1;
36823 enum iio_chan_type type;
36824diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36825index 9add6092..ee7ba3f 100644
36826--- a/drivers/hwmon/pmbus/pmbus_core.c
36827+++ b/drivers/hwmon/pmbus/pmbus_core.c
36828@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
36829 return 0;
36830 }
36831
36832-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36833+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
36834 const char *name,
36835 umode_t mode,
36836 ssize_t (*show)(struct device *dev,
36837@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36838 dev_attr->store = store;
36839 }
36840
36841-static void pmbus_attr_init(struct sensor_device_attribute *a,
36842+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
36843 const char *name,
36844 umode_t mode,
36845 ssize_t (*show)(struct device *dev,
36846@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
36847 u16 reg, u8 mask)
36848 {
36849 struct pmbus_boolean *boolean;
36850- struct sensor_device_attribute *a;
36851+ sensor_device_attribute_no_const *a;
36852
36853 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
36854 if (!boolean)
36855@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
36856 bool update, bool readonly)
36857 {
36858 struct pmbus_sensor *sensor;
36859- struct device_attribute *a;
36860+ device_attribute_no_const *a;
36861
36862 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
36863 if (!sensor)
36864@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
36865 const char *lstring, int index)
36866 {
36867 struct pmbus_label *label;
36868- struct device_attribute *a;
36869+ device_attribute_no_const *a;
36870
36871 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
36872 if (!label)
36873diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36874index 2507f90..1645765 100644
36875--- a/drivers/hwmon/sht15.c
36876+++ b/drivers/hwmon/sht15.c
36877@@ -169,7 +169,7 @@ struct sht15_data {
36878 int supply_uv;
36879 bool supply_uv_valid;
36880 struct work_struct update_supply_work;
36881- atomic_t interrupt_handled;
36882+ atomic_unchecked_t interrupt_handled;
36883 };
36884
36885 /**
36886@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
36887 ret = gpio_direction_input(data->pdata->gpio_data);
36888 if (ret)
36889 return ret;
36890- atomic_set(&data->interrupt_handled, 0);
36891+ atomic_set_unchecked(&data->interrupt_handled, 0);
36892
36893 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36894 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36895 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36896 /* Only relevant if the interrupt hasn't occurred. */
36897- if (!atomic_read(&data->interrupt_handled))
36898+ if (!atomic_read_unchecked(&data->interrupt_handled))
36899 schedule_work(&data->read_work);
36900 }
36901 ret = wait_event_timeout(data->wait_queue,
36902@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36903
36904 /* First disable the interrupt */
36905 disable_irq_nosync(irq);
36906- atomic_inc(&data->interrupt_handled);
36907+ atomic_inc_unchecked(&data->interrupt_handled);
36908 /* Then schedule a reading work struct */
36909 if (data->state != SHT15_READING_NOTHING)
36910 schedule_work(&data->read_work);
36911@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36912 * If not, then start the interrupt again - care here as could
36913 * have gone low in meantime so verify it hasn't!
36914 */
36915- atomic_set(&data->interrupt_handled, 0);
36916+ atomic_set_unchecked(&data->interrupt_handled, 0);
36917 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36918 /* If still not occurred or another handler was scheduled */
36919 if (gpio_get_value(data->pdata->gpio_data)
36920- || atomic_read(&data->interrupt_handled))
36921+ || atomic_read_unchecked(&data->interrupt_handled))
36922 return;
36923 }
36924
36925diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36926index 76f157b..9c0db1b 100644
36927--- a/drivers/hwmon/via-cputemp.c
36928+++ b/drivers/hwmon/via-cputemp.c
36929@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36930 return NOTIFY_OK;
36931 }
36932
36933-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36934+static struct notifier_block via_cputemp_cpu_notifier = {
36935 .notifier_call = via_cputemp_cpu_callback,
36936 };
36937
36938diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36939index 07f01ac..d79ad3d 100644
36940--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36941+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36942@@ -43,7 +43,7 @@
36943 extern struct i2c_adapter amd756_smbus;
36944
36945 static struct i2c_adapter *s4882_adapter;
36946-static struct i2c_algorithm *s4882_algo;
36947+static i2c_algorithm_no_const *s4882_algo;
36948
36949 /* Wrapper access functions for multiplexed SMBus */
36950 static DEFINE_MUTEX(amd756_lock);
36951diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36952index 2ca268d..c6acbdf 100644
36953--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36954+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36955@@ -41,7 +41,7 @@
36956 extern struct i2c_adapter *nforce2_smbus;
36957
36958 static struct i2c_adapter *s4985_adapter;
36959-static struct i2c_algorithm *s4985_algo;
36960+static i2c_algorithm_no_const *s4985_algo;
36961
36962 /* Wrapper access functions for multiplexed SMBus */
36963 static DEFINE_MUTEX(nforce2_lock);
36964diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
36965index c3ccdea..5b3dc1a 100644
36966--- a/drivers/i2c/i2c-dev.c
36967+++ b/drivers/i2c/i2c-dev.c
36968@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
36969 break;
36970 }
36971
36972- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
36973+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
36974 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
36975 if (IS_ERR(rdwr_pa[i].buf)) {
36976 res = PTR_ERR(rdwr_pa[i].buf);
36977diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36978index 2ff6204..218c16e 100644
36979--- a/drivers/ide/ide-cd.c
36980+++ b/drivers/ide/ide-cd.c
36981@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36982 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36983 if ((unsigned long)buf & alignment
36984 || blk_rq_bytes(rq) & q->dma_pad_mask
36985- || object_is_on_stack(buf))
36986+ || object_starts_on_stack(buf))
36987 drive->dma = 0;
36988 }
36989 }
36990diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36991index e145931..08bfc59 100644
36992--- a/drivers/iio/industrialio-core.c
36993+++ b/drivers/iio/industrialio-core.c
36994@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36995 }
36996
36997 static
36998-int __iio_device_attr_init(struct device_attribute *dev_attr,
36999+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
37000 const char *postfix,
37001 struct iio_chan_spec const *chan,
37002 ssize_t (*readfunc)(struct device *dev,
37003diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
37004index 784b97c..c9ceadf 100644
37005--- a/drivers/infiniband/core/cm.c
37006+++ b/drivers/infiniband/core/cm.c
37007@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
37008
37009 struct cm_counter_group {
37010 struct kobject obj;
37011- atomic_long_t counter[CM_ATTR_COUNT];
37012+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
37013 };
37014
37015 struct cm_counter_attribute {
37016@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
37017 struct ib_mad_send_buf *msg = NULL;
37018 int ret;
37019
37020- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37021+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37022 counter[CM_REQ_COUNTER]);
37023
37024 /* Quick state check to discard duplicate REQs. */
37025@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
37026 if (!cm_id_priv)
37027 return;
37028
37029- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37030+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37031 counter[CM_REP_COUNTER]);
37032 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
37033 if (ret)
37034@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
37035 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
37036 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
37037 spin_unlock_irq(&cm_id_priv->lock);
37038- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37039+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37040 counter[CM_RTU_COUNTER]);
37041 goto out;
37042 }
37043@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
37044 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
37045 dreq_msg->local_comm_id);
37046 if (!cm_id_priv) {
37047- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37048+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37049 counter[CM_DREQ_COUNTER]);
37050 cm_issue_drep(work->port, work->mad_recv_wc);
37051 return -EINVAL;
37052@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
37053 case IB_CM_MRA_REP_RCVD:
37054 break;
37055 case IB_CM_TIMEWAIT:
37056- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37057+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37058 counter[CM_DREQ_COUNTER]);
37059 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
37060 goto unlock;
37061@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
37062 cm_free_msg(msg);
37063 goto deref;
37064 case IB_CM_DREQ_RCVD:
37065- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37066+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37067 counter[CM_DREQ_COUNTER]);
37068 goto unlock;
37069 default:
37070@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
37071 ib_modify_mad(cm_id_priv->av.port->mad_agent,
37072 cm_id_priv->msg, timeout)) {
37073 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
37074- atomic_long_inc(&work->port->
37075+ atomic_long_inc_unchecked(&work->port->
37076 counter_group[CM_RECV_DUPLICATES].
37077 counter[CM_MRA_COUNTER]);
37078 goto out;
37079@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
37080 break;
37081 case IB_CM_MRA_REQ_RCVD:
37082 case IB_CM_MRA_REP_RCVD:
37083- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37084+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37085 counter[CM_MRA_COUNTER]);
37086 /* fall through */
37087 default:
37088@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
37089 case IB_CM_LAP_IDLE:
37090 break;
37091 case IB_CM_MRA_LAP_SENT:
37092- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37093+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37094 counter[CM_LAP_COUNTER]);
37095 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
37096 goto unlock;
37097@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
37098 cm_free_msg(msg);
37099 goto deref;
37100 case IB_CM_LAP_RCVD:
37101- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37102+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37103 counter[CM_LAP_COUNTER]);
37104 goto unlock;
37105 default:
37106@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
37107 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
37108 if (cur_cm_id_priv) {
37109 spin_unlock_irq(&cm.lock);
37110- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37111+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37112 counter[CM_SIDR_REQ_COUNTER]);
37113 goto out; /* Duplicate message. */
37114 }
37115@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
37116 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
37117 msg->retries = 1;
37118
37119- atomic_long_add(1 + msg->retries,
37120+ atomic_long_add_unchecked(1 + msg->retries,
37121 &port->counter_group[CM_XMIT].counter[attr_index]);
37122 if (msg->retries)
37123- atomic_long_add(msg->retries,
37124+ atomic_long_add_unchecked(msg->retries,
37125 &port->counter_group[CM_XMIT_RETRIES].
37126 counter[attr_index]);
37127
37128@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
37129 }
37130
37131 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
37132- atomic_long_inc(&port->counter_group[CM_RECV].
37133+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
37134 counter[attr_id - CM_ATTR_ID_OFFSET]);
37135
37136 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
37137@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
37138 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
37139
37140 return sprintf(buf, "%ld\n",
37141- atomic_long_read(&group->counter[cm_attr->index]));
37142+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
37143 }
37144
37145 static const struct sysfs_ops cm_counter_ops = {
37146diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
37147index 9f5ad7c..588cd84 100644
37148--- a/drivers/infiniband/core/fmr_pool.c
37149+++ b/drivers/infiniband/core/fmr_pool.c
37150@@ -98,8 +98,8 @@ struct ib_fmr_pool {
37151
37152 struct task_struct *thread;
37153
37154- atomic_t req_ser;
37155- atomic_t flush_ser;
37156+ atomic_unchecked_t req_ser;
37157+ atomic_unchecked_t flush_ser;
37158
37159 wait_queue_head_t force_wait;
37160 };
37161@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37162 struct ib_fmr_pool *pool = pool_ptr;
37163
37164 do {
37165- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
37166+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
37167 ib_fmr_batch_release(pool);
37168
37169- atomic_inc(&pool->flush_ser);
37170+ atomic_inc_unchecked(&pool->flush_ser);
37171 wake_up_interruptible(&pool->force_wait);
37172
37173 if (pool->flush_function)
37174@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37175 }
37176
37177 set_current_state(TASK_INTERRUPTIBLE);
37178- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
37179+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
37180 !kthread_should_stop())
37181 schedule();
37182 __set_current_state(TASK_RUNNING);
37183@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
37184 pool->dirty_watermark = params->dirty_watermark;
37185 pool->dirty_len = 0;
37186 spin_lock_init(&pool->pool_lock);
37187- atomic_set(&pool->req_ser, 0);
37188- atomic_set(&pool->flush_ser, 0);
37189+ atomic_set_unchecked(&pool->req_ser, 0);
37190+ atomic_set_unchecked(&pool->flush_ser, 0);
37191 init_waitqueue_head(&pool->force_wait);
37192
37193 pool->thread = kthread_run(ib_fmr_cleanup_thread,
37194@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
37195 }
37196 spin_unlock_irq(&pool->pool_lock);
37197
37198- serial = atomic_inc_return(&pool->req_ser);
37199+ serial = atomic_inc_return_unchecked(&pool->req_ser);
37200 wake_up_process(pool->thread);
37201
37202 if (wait_event_interruptible(pool->force_wait,
37203- atomic_read(&pool->flush_ser) - serial >= 0))
37204+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
37205 return -EINTR;
37206
37207 return 0;
37208@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
37209 } else {
37210 list_add_tail(&fmr->list, &pool->dirty_list);
37211 if (++pool->dirty_len >= pool->dirty_watermark) {
37212- atomic_inc(&pool->req_ser);
37213+ atomic_inc_unchecked(&pool->req_ser);
37214 wake_up_process(pool->thread);
37215 }
37216 }
37217diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
37218index 4cb8eb2..146bf60 100644
37219--- a/drivers/infiniband/hw/cxgb4/mem.c
37220+++ b/drivers/infiniband/hw/cxgb4/mem.c
37221@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37222 int err;
37223 struct fw_ri_tpte tpt;
37224 u32 stag_idx;
37225- static atomic_t key;
37226+ static atomic_unchecked_t key;
37227
37228 if (c4iw_fatal_error(rdev))
37229 return -EIO;
37230@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37231 if (rdev->stats.stag.cur > rdev->stats.stag.max)
37232 rdev->stats.stag.max = rdev->stats.stag.cur;
37233 mutex_unlock(&rdev->stats.lock);
37234- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
37235+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
37236 }
37237 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
37238 __func__, stag_state, type, pdid, stag_idx);
37239diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
37240index 79b3dbc..96e5fcc 100644
37241--- a/drivers/infiniband/hw/ipath/ipath_rc.c
37242+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
37243@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37244 struct ib_atomic_eth *ateth;
37245 struct ipath_ack_entry *e;
37246 u64 vaddr;
37247- atomic64_t *maddr;
37248+ atomic64_unchecked_t *maddr;
37249 u64 sdata;
37250 u32 rkey;
37251 u8 next;
37252@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37253 IB_ACCESS_REMOTE_ATOMIC)))
37254 goto nack_acc_unlck;
37255 /* Perform atomic OP and save result. */
37256- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37257+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37258 sdata = be64_to_cpu(ateth->swap_data);
37259 e = &qp->s_ack_queue[qp->r_head_ack_queue];
37260 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
37261- (u64) atomic64_add_return(sdata, maddr) - sdata :
37262+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37263 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37264 be64_to_cpu(ateth->compare_data),
37265 sdata);
37266diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
37267index 1f95bba..9530f87 100644
37268--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
37269+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
37270@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
37271 unsigned long flags;
37272 struct ib_wc wc;
37273 u64 sdata;
37274- atomic64_t *maddr;
37275+ atomic64_unchecked_t *maddr;
37276 enum ib_wc_status send_status;
37277
37278 /*
37279@@ -382,11 +382,11 @@ again:
37280 IB_ACCESS_REMOTE_ATOMIC)))
37281 goto acc_err;
37282 /* Perform atomic OP and save result. */
37283- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37284+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37285 sdata = wqe->wr.wr.atomic.compare_add;
37286 *(u64 *) sqp->s_sge.sge.vaddr =
37287 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
37288- (u64) atomic64_add_return(sdata, maddr) - sdata :
37289+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37290 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37291 sdata, wqe->wr.wr.atomic.swap);
37292 goto send_comp;
37293diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
37294index 9d3e5c1..d9afe4a 100644
37295--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
37296+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
37297@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
37298 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
37299 }
37300
37301-int mthca_QUERY_FW(struct mthca_dev *dev)
37302+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
37303 {
37304 struct mthca_mailbox *mailbox;
37305 u32 *outbox;
37306diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
37307index ed9a989..e0c5871 100644
37308--- a/drivers/infiniband/hw/mthca/mthca_mr.c
37309+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
37310@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
37311 return key;
37312 }
37313
37314-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37315+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37316 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
37317 {
37318 struct mthca_mailbox *mailbox;
37319diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
37320index 4291410..d2ab1fb 100644
37321--- a/drivers/infiniband/hw/nes/nes.c
37322+++ b/drivers/infiniband/hw/nes/nes.c
37323@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
37324 LIST_HEAD(nes_adapter_list);
37325 static LIST_HEAD(nes_dev_list);
37326
37327-atomic_t qps_destroyed;
37328+atomic_unchecked_t qps_destroyed;
37329
37330 static unsigned int ee_flsh_adapter;
37331 static unsigned int sysfs_nonidx_addr;
37332@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
37333 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
37334 struct nes_adapter *nesadapter = nesdev->nesadapter;
37335
37336- atomic_inc(&qps_destroyed);
37337+ atomic_inc_unchecked(&qps_destroyed);
37338
37339 /* Free the control structures */
37340
37341diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
37342index 33cc589..3bd6538 100644
37343--- a/drivers/infiniband/hw/nes/nes.h
37344+++ b/drivers/infiniband/hw/nes/nes.h
37345@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
37346 extern unsigned int wqm_quanta;
37347 extern struct list_head nes_adapter_list;
37348
37349-extern atomic_t cm_connects;
37350-extern atomic_t cm_accepts;
37351-extern atomic_t cm_disconnects;
37352-extern atomic_t cm_closes;
37353-extern atomic_t cm_connecteds;
37354-extern atomic_t cm_connect_reqs;
37355-extern atomic_t cm_rejects;
37356-extern atomic_t mod_qp_timouts;
37357-extern atomic_t qps_created;
37358-extern atomic_t qps_destroyed;
37359-extern atomic_t sw_qps_destroyed;
37360+extern atomic_unchecked_t cm_connects;
37361+extern atomic_unchecked_t cm_accepts;
37362+extern atomic_unchecked_t cm_disconnects;
37363+extern atomic_unchecked_t cm_closes;
37364+extern atomic_unchecked_t cm_connecteds;
37365+extern atomic_unchecked_t cm_connect_reqs;
37366+extern atomic_unchecked_t cm_rejects;
37367+extern atomic_unchecked_t mod_qp_timouts;
37368+extern atomic_unchecked_t qps_created;
37369+extern atomic_unchecked_t qps_destroyed;
37370+extern atomic_unchecked_t sw_qps_destroyed;
37371 extern u32 mh_detected;
37372 extern u32 mh_pauses_sent;
37373 extern u32 cm_packets_sent;
37374@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
37375 extern u32 cm_packets_received;
37376 extern u32 cm_packets_dropped;
37377 extern u32 cm_packets_retrans;
37378-extern atomic_t cm_listens_created;
37379-extern atomic_t cm_listens_destroyed;
37380+extern atomic_unchecked_t cm_listens_created;
37381+extern atomic_unchecked_t cm_listens_destroyed;
37382 extern u32 cm_backlog_drops;
37383-extern atomic_t cm_loopbacks;
37384-extern atomic_t cm_nodes_created;
37385-extern atomic_t cm_nodes_destroyed;
37386-extern atomic_t cm_accel_dropped_pkts;
37387-extern atomic_t cm_resets_recvd;
37388-extern atomic_t pau_qps_created;
37389-extern atomic_t pau_qps_destroyed;
37390+extern atomic_unchecked_t cm_loopbacks;
37391+extern atomic_unchecked_t cm_nodes_created;
37392+extern atomic_unchecked_t cm_nodes_destroyed;
37393+extern atomic_unchecked_t cm_accel_dropped_pkts;
37394+extern atomic_unchecked_t cm_resets_recvd;
37395+extern atomic_unchecked_t pau_qps_created;
37396+extern atomic_unchecked_t pau_qps_destroyed;
37397
37398 extern u32 int_mod_timer_init;
37399 extern u32 int_mod_cq_depth_256;
37400diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
37401index 24b9f1a..00fd004 100644
37402--- a/drivers/infiniband/hw/nes/nes_cm.c
37403+++ b/drivers/infiniband/hw/nes/nes_cm.c
37404@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
37405 u32 cm_packets_retrans;
37406 u32 cm_packets_created;
37407 u32 cm_packets_received;
37408-atomic_t cm_listens_created;
37409-atomic_t cm_listens_destroyed;
37410+atomic_unchecked_t cm_listens_created;
37411+atomic_unchecked_t cm_listens_destroyed;
37412 u32 cm_backlog_drops;
37413-atomic_t cm_loopbacks;
37414-atomic_t cm_nodes_created;
37415-atomic_t cm_nodes_destroyed;
37416-atomic_t cm_accel_dropped_pkts;
37417-atomic_t cm_resets_recvd;
37418+atomic_unchecked_t cm_loopbacks;
37419+atomic_unchecked_t cm_nodes_created;
37420+atomic_unchecked_t cm_nodes_destroyed;
37421+atomic_unchecked_t cm_accel_dropped_pkts;
37422+atomic_unchecked_t cm_resets_recvd;
37423
37424 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
37425 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
37426@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
37427
37428 static struct nes_cm_core *g_cm_core;
37429
37430-atomic_t cm_connects;
37431-atomic_t cm_accepts;
37432-atomic_t cm_disconnects;
37433-atomic_t cm_closes;
37434-atomic_t cm_connecteds;
37435-atomic_t cm_connect_reqs;
37436-atomic_t cm_rejects;
37437+atomic_unchecked_t cm_connects;
37438+atomic_unchecked_t cm_accepts;
37439+atomic_unchecked_t cm_disconnects;
37440+atomic_unchecked_t cm_closes;
37441+atomic_unchecked_t cm_connecteds;
37442+atomic_unchecked_t cm_connect_reqs;
37443+atomic_unchecked_t cm_rejects;
37444
37445 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
37446 {
37447@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
37448 kfree(listener);
37449 listener = NULL;
37450 ret = 0;
37451- atomic_inc(&cm_listens_destroyed);
37452+ atomic_inc_unchecked(&cm_listens_destroyed);
37453 } else {
37454 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
37455 }
37456@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
37457 cm_node->rem_mac);
37458
37459 add_hte_node(cm_core, cm_node);
37460- atomic_inc(&cm_nodes_created);
37461+ atomic_inc_unchecked(&cm_nodes_created);
37462
37463 return cm_node;
37464 }
37465@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
37466 }
37467
37468 atomic_dec(&cm_core->node_cnt);
37469- atomic_inc(&cm_nodes_destroyed);
37470+ atomic_inc_unchecked(&cm_nodes_destroyed);
37471 nesqp = cm_node->nesqp;
37472 if (nesqp) {
37473 nesqp->cm_node = NULL;
37474@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
37475
37476 static void drop_packet(struct sk_buff *skb)
37477 {
37478- atomic_inc(&cm_accel_dropped_pkts);
37479+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37480 dev_kfree_skb_any(skb);
37481 }
37482
37483@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
37484 {
37485
37486 int reset = 0; /* whether to send reset in case of err.. */
37487- atomic_inc(&cm_resets_recvd);
37488+ atomic_inc_unchecked(&cm_resets_recvd);
37489 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
37490 " refcnt=%d\n", cm_node, cm_node->state,
37491 atomic_read(&cm_node->ref_count));
37492@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
37493 rem_ref_cm_node(cm_node->cm_core, cm_node);
37494 return NULL;
37495 }
37496- atomic_inc(&cm_loopbacks);
37497+ atomic_inc_unchecked(&cm_loopbacks);
37498 loopbackremotenode->loopbackpartner = cm_node;
37499 loopbackremotenode->tcp_cntxt.rcv_wscale =
37500 NES_CM_DEFAULT_RCV_WND_SCALE;
37501@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
37502 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
37503 else {
37504 rem_ref_cm_node(cm_core, cm_node);
37505- atomic_inc(&cm_accel_dropped_pkts);
37506+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37507 dev_kfree_skb_any(skb);
37508 }
37509 break;
37510@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37511
37512 if ((cm_id) && (cm_id->event_handler)) {
37513 if (issue_disconn) {
37514- atomic_inc(&cm_disconnects);
37515+ atomic_inc_unchecked(&cm_disconnects);
37516 cm_event.event = IW_CM_EVENT_DISCONNECT;
37517 cm_event.status = disconn_status;
37518 cm_event.local_addr = cm_id->local_addr;
37519@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37520 }
37521
37522 if (issue_close) {
37523- atomic_inc(&cm_closes);
37524+ atomic_inc_unchecked(&cm_closes);
37525 nes_disconnect(nesqp, 1);
37526
37527 cm_id->provider_data = nesqp;
37528@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37529
37530 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
37531 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
37532- atomic_inc(&cm_accepts);
37533+ atomic_inc_unchecked(&cm_accepts);
37534
37535 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
37536 netdev_refcnt_read(nesvnic->netdev));
37537@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
37538 struct nes_cm_core *cm_core;
37539 u8 *start_buff;
37540
37541- atomic_inc(&cm_rejects);
37542+ atomic_inc_unchecked(&cm_rejects);
37543 cm_node = (struct nes_cm_node *)cm_id->provider_data;
37544 loopback = cm_node->loopbackpartner;
37545 cm_core = cm_node->cm_core;
37546@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37547 ntohl(cm_id->local_addr.sin_addr.s_addr),
37548 ntohs(cm_id->local_addr.sin_port));
37549
37550- atomic_inc(&cm_connects);
37551+ atomic_inc_unchecked(&cm_connects);
37552 nesqp->active_conn = 1;
37553
37554 /* cache the cm_id in the qp */
37555@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
37556 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
37557 return err;
37558 }
37559- atomic_inc(&cm_listens_created);
37560+ atomic_inc_unchecked(&cm_listens_created);
37561 }
37562
37563 cm_id->add_ref(cm_id);
37564@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
37565
37566 if (nesqp->destroyed)
37567 return;
37568- atomic_inc(&cm_connecteds);
37569+ atomic_inc_unchecked(&cm_connecteds);
37570 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
37571 " local port 0x%04X. jiffies = %lu.\n",
37572 nesqp->hwqp.qp_id,
37573@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
37574
37575 cm_id->add_ref(cm_id);
37576 ret = cm_id->event_handler(cm_id, &cm_event);
37577- atomic_inc(&cm_closes);
37578+ atomic_inc_unchecked(&cm_closes);
37579 cm_event.event = IW_CM_EVENT_CLOSE;
37580 cm_event.status = 0;
37581 cm_event.provider_data = cm_id->provider_data;
37582@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
37583 return;
37584 cm_id = cm_node->cm_id;
37585
37586- atomic_inc(&cm_connect_reqs);
37587+ atomic_inc_unchecked(&cm_connect_reqs);
37588 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37589 cm_node, cm_id, jiffies);
37590
37591@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
37592 return;
37593 cm_id = cm_node->cm_id;
37594
37595- atomic_inc(&cm_connect_reqs);
37596+ atomic_inc_unchecked(&cm_connect_reqs);
37597 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37598 cm_node, cm_id, jiffies);
37599
37600diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
37601index 4166452..fc952c3 100644
37602--- a/drivers/infiniband/hw/nes/nes_mgt.c
37603+++ b/drivers/infiniband/hw/nes/nes_mgt.c
37604@@ -40,8 +40,8 @@
37605 #include "nes.h"
37606 #include "nes_mgt.h"
37607
37608-atomic_t pau_qps_created;
37609-atomic_t pau_qps_destroyed;
37610+atomic_unchecked_t pau_qps_created;
37611+atomic_unchecked_t pau_qps_destroyed;
37612
37613 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
37614 {
37615@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
37616 {
37617 struct sk_buff *skb;
37618 unsigned long flags;
37619- atomic_inc(&pau_qps_destroyed);
37620+ atomic_inc_unchecked(&pau_qps_destroyed);
37621
37622 /* Free packets that have not yet been forwarded */
37623 /* Lock is acquired by skb_dequeue when removing the skb */
37624@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
37625 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
37626 skb_queue_head_init(&nesqp->pau_list);
37627 spin_lock_init(&nesqp->pau_lock);
37628- atomic_inc(&pau_qps_created);
37629+ atomic_inc_unchecked(&pau_qps_created);
37630 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37631 }
37632
37633diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37634index 49eb511..a774366 100644
37635--- a/drivers/infiniband/hw/nes/nes_nic.c
37636+++ b/drivers/infiniband/hw/nes/nes_nic.c
37637@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37638 target_stat_values[++index] = mh_detected;
37639 target_stat_values[++index] = mh_pauses_sent;
37640 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37641- target_stat_values[++index] = atomic_read(&cm_connects);
37642- target_stat_values[++index] = atomic_read(&cm_accepts);
37643- target_stat_values[++index] = atomic_read(&cm_disconnects);
37644- target_stat_values[++index] = atomic_read(&cm_connecteds);
37645- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37646- target_stat_values[++index] = atomic_read(&cm_rejects);
37647- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37648- target_stat_values[++index] = atomic_read(&qps_created);
37649- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37650- target_stat_values[++index] = atomic_read(&qps_destroyed);
37651- target_stat_values[++index] = atomic_read(&cm_closes);
37652+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37653+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37654+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37655+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37656+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37657+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37658+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37659+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37660+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37661+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37662+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37663 target_stat_values[++index] = cm_packets_sent;
37664 target_stat_values[++index] = cm_packets_bounced;
37665 target_stat_values[++index] = cm_packets_created;
37666 target_stat_values[++index] = cm_packets_received;
37667 target_stat_values[++index] = cm_packets_dropped;
37668 target_stat_values[++index] = cm_packets_retrans;
37669- target_stat_values[++index] = atomic_read(&cm_listens_created);
37670- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37671+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37672+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37673 target_stat_values[++index] = cm_backlog_drops;
37674- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37675- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37676- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37677- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37678- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37679+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37680+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37681+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37682+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37683+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37684 target_stat_values[++index] = nesadapter->free_4kpbl;
37685 target_stat_values[++index] = nesadapter->free_256pbl;
37686 target_stat_values[++index] = int_mod_timer_init;
37687 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37688 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37689 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37690- target_stat_values[++index] = atomic_read(&pau_qps_created);
37691- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37692+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37693+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37694 }
37695
37696 /**
37697diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37698index 8f67fe2..8960859 100644
37699--- a/drivers/infiniband/hw/nes/nes_verbs.c
37700+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37701@@ -46,9 +46,9 @@
37702
37703 #include <rdma/ib_umem.h>
37704
37705-atomic_t mod_qp_timouts;
37706-atomic_t qps_created;
37707-atomic_t sw_qps_destroyed;
37708+atomic_unchecked_t mod_qp_timouts;
37709+atomic_unchecked_t qps_created;
37710+atomic_unchecked_t sw_qps_destroyed;
37711
37712 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37713
37714@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37715 if (init_attr->create_flags)
37716 return ERR_PTR(-EINVAL);
37717
37718- atomic_inc(&qps_created);
37719+ atomic_inc_unchecked(&qps_created);
37720 switch (init_attr->qp_type) {
37721 case IB_QPT_RC:
37722 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37723@@ -1465,7 +1465,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37724 struct iw_cm_event cm_event;
37725 int ret = 0;
37726
37727- atomic_inc(&sw_qps_destroyed);
37728+ atomic_inc_unchecked(&sw_qps_destroyed);
37729 nesqp->destroyed = 1;
37730
37731 /* Blow away the connection if it exists. */
37732diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37733index 4d11575..3e890e5 100644
37734--- a/drivers/infiniband/hw/qib/qib.h
37735+++ b/drivers/infiniband/hw/qib/qib.h
37736@@ -51,6 +51,7 @@
37737 #include <linux/completion.h>
37738 #include <linux/kref.h>
37739 #include <linux/sched.h>
37740+#include <linux/slab.h>
37741
37742 #include "qib_common.h"
37743 #include "qib_verbs.h"
37744diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37745index da739d9..da1c7f4 100644
37746--- a/drivers/input/gameport/gameport.c
37747+++ b/drivers/input/gameport/gameport.c
37748@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37749 */
37750 static void gameport_init_port(struct gameport *gameport)
37751 {
37752- static atomic_t gameport_no = ATOMIC_INIT(0);
37753+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37754
37755 __module_get(THIS_MODULE);
37756
37757 mutex_init(&gameport->drv_mutex);
37758 device_initialize(&gameport->dev);
37759 dev_set_name(&gameport->dev, "gameport%lu",
37760- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37761+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37762 gameport->dev.bus = &gameport_bus;
37763 gameport->dev.release = gameport_release_port;
37764 if (gameport->parent)
37765diff --git a/drivers/input/input.c b/drivers/input/input.c
37766index c044699..174d71a 100644
37767--- a/drivers/input/input.c
37768+++ b/drivers/input/input.c
37769@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37770 */
37771 int input_register_device(struct input_dev *dev)
37772 {
37773- static atomic_t input_no = ATOMIC_INIT(0);
37774+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37775 struct input_devres *devres = NULL;
37776 struct input_handler *handler;
37777 unsigned int packet_size;
37778@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37779 dev->setkeycode = input_default_setkeycode;
37780
37781 dev_set_name(&dev->dev, "input%ld",
37782- (unsigned long) atomic_inc_return(&input_no) - 1);
37783+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37784
37785 error = device_add(&dev->dev);
37786 if (error)
37787diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37788index 04c69af..5f92d00 100644
37789--- a/drivers/input/joystick/sidewinder.c
37790+++ b/drivers/input/joystick/sidewinder.c
37791@@ -30,6 +30,7 @@
37792 #include <linux/kernel.h>
37793 #include <linux/module.h>
37794 #include <linux/slab.h>
37795+#include <linux/sched.h>
37796 #include <linux/init.h>
37797 #include <linux/input.h>
37798 #include <linux/gameport.h>
37799diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37800index fa061d4..4a6957c 100644
37801--- a/drivers/input/joystick/xpad.c
37802+++ b/drivers/input/joystick/xpad.c
37803@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37804
37805 static int xpad_led_probe(struct usb_xpad *xpad)
37806 {
37807- static atomic_t led_seq = ATOMIC_INIT(0);
37808+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37809 long led_no;
37810 struct xpad_led *led;
37811 struct led_classdev *led_cdev;
37812@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37813 if (!led)
37814 return -ENOMEM;
37815
37816- led_no = (long)atomic_inc_return(&led_seq) - 1;
37817+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37818
37819 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37820 led->xpad = xpad;
37821diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37822index 2f0b39d..7370f13 100644
37823--- a/drivers/input/mouse/psmouse.h
37824+++ b/drivers/input/mouse/psmouse.h
37825@@ -116,7 +116,7 @@ struct psmouse_attribute {
37826 ssize_t (*set)(struct psmouse *psmouse, void *data,
37827 const char *buf, size_t count);
37828 bool protect;
37829-};
37830+} __do_const;
37831 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37832
37833 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37834diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37835index 4c842c3..590b0bf 100644
37836--- a/drivers/input/mousedev.c
37837+++ b/drivers/input/mousedev.c
37838@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37839
37840 spin_unlock_irq(&client->packet_lock);
37841
37842- if (copy_to_user(buffer, data, count))
37843+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37844 return -EFAULT;
37845
37846 return count;
37847diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37848index 25fc597..558bf3b3 100644
37849--- a/drivers/input/serio/serio.c
37850+++ b/drivers/input/serio/serio.c
37851@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37852 */
37853 static void serio_init_port(struct serio *serio)
37854 {
37855- static atomic_t serio_no = ATOMIC_INIT(0);
37856+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37857
37858 __module_get(THIS_MODULE);
37859
37860@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37861 mutex_init(&serio->drv_mutex);
37862 device_initialize(&serio->dev);
37863 dev_set_name(&serio->dev, "serio%ld",
37864- (long)atomic_inc_return(&serio_no) - 1);
37865+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37866 serio->dev.bus = &serio_bus;
37867 serio->dev.release = serio_release_port;
37868 serio->dev.groups = serio_device_attr_groups;
37869diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37870index d8f98b1..f62a640 100644
37871--- a/drivers/iommu/iommu.c
37872+++ b/drivers/iommu/iommu.c
37873@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
37874 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37875 {
37876 bus_register_notifier(bus, &iommu_bus_nb);
37877- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37878+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37879 }
37880
37881 /**
37882diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
37883index dcfea4e..f4226b2 100644
37884--- a/drivers/iommu/irq_remapping.c
37885+++ b/drivers/iommu/irq_remapping.c
37886@@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
37887 void panic_if_irq_remap(const char *msg)
37888 {
37889 if (irq_remapping_enabled)
37890- panic(msg);
37891+ panic("%s", msg);
37892 }
37893
37894 static void ir_ack_apic_edge(struct irq_data *data)
37895@@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
37896
37897 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
37898 {
37899- chip->irq_print_chip = ir_print_prefix;
37900- chip->irq_ack = ir_ack_apic_edge;
37901- chip->irq_eoi = ir_ack_apic_level;
37902- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37903+ pax_open_kernel();
37904+ *(void **)&chip->irq_print_chip = ir_print_prefix;
37905+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
37906+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
37907+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37908+ pax_close_kernel();
37909 }
37910
37911 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
37912diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
37913index 19ceaa6..3625818 100644
37914--- a/drivers/irqchip/irq-gic.c
37915+++ b/drivers/irqchip/irq-gic.c
37916@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
37917 * Supported arch specific GIC irq extension.
37918 * Default make them NULL.
37919 */
37920-struct irq_chip gic_arch_extn = {
37921+irq_chip_no_const gic_arch_extn = {
37922 .irq_eoi = NULL,
37923 .irq_mask = NULL,
37924 .irq_unmask = NULL,
37925@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
37926 chained_irq_exit(chip, desc);
37927 }
37928
37929-static struct irq_chip gic_chip = {
37930+static irq_chip_no_const gic_chip __read_only = {
37931 .name = "GIC",
37932 .irq_mask = gic_mask_irq,
37933 .irq_unmask = gic_unmask_irq,
37934diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37935index ac6f72b..81150f2 100644
37936--- a/drivers/isdn/capi/capi.c
37937+++ b/drivers/isdn/capi/capi.c
37938@@ -81,8 +81,8 @@ struct capiminor {
37939
37940 struct capi20_appl *ap;
37941 u32 ncci;
37942- atomic_t datahandle;
37943- atomic_t msgid;
37944+ atomic_unchecked_t datahandle;
37945+ atomic_unchecked_t msgid;
37946
37947 struct tty_port port;
37948 int ttyinstop;
37949@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37950 capimsg_setu16(s, 2, mp->ap->applid);
37951 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37952 capimsg_setu8 (s, 5, CAPI_RESP);
37953- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37954+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37955 capimsg_setu32(s, 8, mp->ncci);
37956 capimsg_setu16(s, 12, datahandle);
37957 }
37958@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37959 mp->outbytes -= len;
37960 spin_unlock_bh(&mp->outlock);
37961
37962- datahandle = atomic_inc_return(&mp->datahandle);
37963+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37964 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37965 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37966 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37967 capimsg_setu16(skb->data, 2, mp->ap->applid);
37968 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37969 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37970- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37971+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37972 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37973 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37974 capimsg_setu16(skb->data, 16, len); /* Data length */
37975diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37976index 600c79b..3752bab 100644
37977--- a/drivers/isdn/gigaset/interface.c
37978+++ b/drivers/isdn/gigaset/interface.c
37979@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37980 }
37981 tty->driver_data = cs;
37982
37983- ++cs->port.count;
37984+ atomic_inc(&cs->port.count);
37985
37986- if (cs->port.count == 1) {
37987+ if (atomic_read(&cs->port.count) == 1) {
37988 tty_port_tty_set(&cs->port, tty);
37989 cs->port.low_latency = 1;
37990 }
37991@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37992
37993 if (!cs->connected)
37994 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37995- else if (!cs->port.count)
37996+ else if (!atomic_read(&cs->port.count))
37997 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37998- else if (!--cs->port.count)
37999+ else if (!atomic_dec_return(&cs->port.count))
38000 tty_port_tty_set(&cs->port, NULL);
38001
38002 mutex_unlock(&cs->mutex);
38003diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
38004index 4d9b195..455075c 100644
38005--- a/drivers/isdn/hardware/avm/b1.c
38006+++ b/drivers/isdn/hardware/avm/b1.c
38007@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
38008 }
38009 if (left) {
38010 if (t4file->user) {
38011- if (copy_from_user(buf, dp, left))
38012+ if (left > sizeof buf || copy_from_user(buf, dp, left))
38013 return -EFAULT;
38014 } else {
38015 memcpy(buf, dp, left);
38016@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
38017 }
38018 if (left) {
38019 if (config->user) {
38020- if (copy_from_user(buf, dp, left))
38021+ if (left > sizeof buf || copy_from_user(buf, dp, left))
38022 return -EFAULT;
38023 } else {
38024 memcpy(buf, dp, left);
38025diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
38026index 3c5f249..5fac4d0 100644
38027--- a/drivers/isdn/i4l/isdn_tty.c
38028+++ b/drivers/isdn/i4l/isdn_tty.c
38029@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
38030
38031 #ifdef ISDN_DEBUG_MODEM_OPEN
38032 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
38033- port->count);
38034+ atomic_read(&port->count));
38035 #endif
38036- port->count++;
38037+ atomic_inc(&port->count);
38038 port->tty = tty;
38039 /*
38040 * Start up serial port
38041@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
38042 #endif
38043 return;
38044 }
38045- if ((tty->count == 1) && (port->count != 1)) {
38046+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
38047 /*
38048 * Uh, oh. tty->count is 1, which means that the tty
38049 * structure will be freed. Info->count should always
38050@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
38051 * serial port won't be shutdown.
38052 */
38053 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
38054- "info->count is %d\n", port->count);
38055- port->count = 1;
38056+ "info->count is %d\n", atomic_read(&port->count));
38057+ atomic_set(&port->count, 1);
38058 }
38059- if (--port->count < 0) {
38060+ if (atomic_dec_return(&port->count) < 0) {
38061 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
38062- info->line, port->count);
38063- port->count = 0;
38064+ info->line, atomic_read(&port->count));
38065+ atomic_set(&port->count, 0);
38066 }
38067- if (port->count) {
38068+ if (atomic_read(&port->count)) {
38069 #ifdef ISDN_DEBUG_MODEM_OPEN
38070 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
38071 #endif
38072@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
38073 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
38074 return;
38075 isdn_tty_shutdown(info);
38076- port->count = 0;
38077+ atomic_set(&port->count, 0);
38078 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38079 port->tty = NULL;
38080 wake_up_interruptible(&port->open_wait);
38081@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
38082 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
38083 modem_info *info = &dev->mdm.info[i];
38084
38085- if (info->port.count == 0)
38086+ if (atomic_read(&info->port.count) == 0)
38087 continue;
38088 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
38089 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
38090diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
38091index e74df7c..03a03ba 100644
38092--- a/drivers/isdn/icn/icn.c
38093+++ b/drivers/isdn/icn/icn.c
38094@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
38095 if (count > len)
38096 count = len;
38097 if (user) {
38098- if (copy_from_user(msg, buf, count))
38099+ if (count > sizeof msg || copy_from_user(msg, buf, count))
38100 return -EFAULT;
38101 } else
38102 memcpy(msg, buf, count);
38103diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
38104index 6a8405d..0bd1c7e 100644
38105--- a/drivers/leds/leds-clevo-mail.c
38106+++ b/drivers/leds/leds-clevo-mail.c
38107@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
38108 * detected as working, but in reality it is not) as low as
38109 * possible.
38110 */
38111-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
38112+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
38113 {
38114 .callback = clevo_mail_led_dmi_callback,
38115 .ident = "Clevo D410J",
38116diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
38117index 64e204e..c6bf189 100644
38118--- a/drivers/leds/leds-ss4200.c
38119+++ b/drivers/leds/leds-ss4200.c
38120@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
38121 * detected as working, but in reality it is not) as low as
38122 * possible.
38123 */
38124-static struct dmi_system_id __initdata nas_led_whitelist[] = {
38125+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
38126 {
38127 .callback = ss4200_led_dmi_callback,
38128 .ident = "Intel SS4200-E",
38129diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
38130index 0bf1e4e..b4bf44e 100644
38131--- a/drivers/lguest/core.c
38132+++ b/drivers/lguest/core.c
38133@@ -97,9 +97,17 @@ static __init int map_switcher(void)
38134 * The end address needs +1 because __get_vm_area allocates an
38135 * extra guard page, so we need space for that.
38136 */
38137+
38138+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
38139+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
38140+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
38141+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
38142+#else
38143 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
38144 VM_ALLOC, switcher_addr, switcher_addr
38145 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
38146+#endif
38147+
38148 if (!switcher_vma) {
38149 err = -ENOMEM;
38150 printk("lguest: could not map switcher pages high\n");
38151@@ -124,7 +132,7 @@ static __init int map_switcher(void)
38152 * Now the Switcher is mapped at the right address, we can't fail!
38153 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
38154 */
38155- memcpy(switcher_vma->addr, start_switcher_text,
38156+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
38157 end_switcher_text - start_switcher_text);
38158
38159 printk(KERN_INFO "lguest: mapped switcher at %p\n",
38160diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
38161index 5b9ac32..2ef4f26 100644
38162--- a/drivers/lguest/page_tables.c
38163+++ b/drivers/lguest/page_tables.c
38164@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
38165 /*:*/
38166
38167 #ifdef CONFIG_X86_PAE
38168-static void release_pmd(pmd_t *spmd)
38169+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
38170 {
38171 /* If the entry's not present, there's nothing to release. */
38172 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
38173diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
38174index f0a3347..f6608b2 100644
38175--- a/drivers/lguest/x86/core.c
38176+++ b/drivers/lguest/x86/core.c
38177@@ -59,7 +59,7 @@ static struct {
38178 /* Offset from where switcher.S was compiled to where we've copied it */
38179 static unsigned long switcher_offset(void)
38180 {
38181- return switcher_addr - (unsigned long)start_switcher_text;
38182+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
38183 }
38184
38185 /* This cpu's struct lguest_pages (after the Switcher text page) */
38186@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
38187 * These copies are pretty cheap, so we do them unconditionally: */
38188 /* Save the current Host top-level page directory.
38189 */
38190+
38191+#ifdef CONFIG_PAX_PER_CPU_PGD
38192+ pages->state.host_cr3 = read_cr3();
38193+#else
38194 pages->state.host_cr3 = __pa(current->mm->pgd);
38195+#endif
38196+
38197 /*
38198 * Set up the Guest's page tables to see this CPU's pages (and no
38199 * other CPU's pages).
38200@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
38201 * compiled-in switcher code and the high-mapped copy we just made.
38202 */
38203 for (i = 0; i < IDT_ENTRIES; i++)
38204- default_idt_entries[i] += switcher_offset();
38205+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
38206
38207 /*
38208 * Set up the Switcher's per-cpu areas.
38209@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
38210 * it will be undisturbed when we switch. To change %cs and jump we
38211 * need this structure to feed to Intel's "lcall" instruction.
38212 */
38213- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
38214+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
38215 lguest_entry.segment = LGUEST_CS;
38216
38217 /*
38218diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
38219index 40634b0..4f5855e 100644
38220--- a/drivers/lguest/x86/switcher_32.S
38221+++ b/drivers/lguest/x86/switcher_32.S
38222@@ -87,6 +87,7 @@
38223 #include <asm/page.h>
38224 #include <asm/segment.h>
38225 #include <asm/lguest.h>
38226+#include <asm/processor-flags.h>
38227
38228 // We mark the start of the code to copy
38229 // It's placed in .text tho it's never run here
38230@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
38231 // Changes type when we load it: damn Intel!
38232 // For after we switch over our page tables
38233 // That entry will be read-only: we'd crash.
38234+
38235+#ifdef CONFIG_PAX_KERNEXEC
38236+ mov %cr0, %edx
38237+ xor $X86_CR0_WP, %edx
38238+ mov %edx, %cr0
38239+#endif
38240+
38241 movl $(GDT_ENTRY_TSS*8), %edx
38242 ltr %dx
38243
38244@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
38245 // Let's clear it again for our return.
38246 // The GDT descriptor of the Host
38247 // Points to the table after two "size" bytes
38248- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
38249+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
38250 // Clear "used" from type field (byte 5, bit 2)
38251- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
38252+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
38253+
38254+#ifdef CONFIG_PAX_KERNEXEC
38255+ mov %cr0, %eax
38256+ xor $X86_CR0_WP, %eax
38257+ mov %eax, %cr0
38258+#endif
38259
38260 // Once our page table's switched, the Guest is live!
38261 // The Host fades as we run this final step.
38262@@ -295,13 +309,12 @@ deliver_to_host:
38263 // I consulted gcc, and it gave
38264 // These instructions, which I gladly credit:
38265 leal (%edx,%ebx,8), %eax
38266- movzwl (%eax),%edx
38267- movl 4(%eax), %eax
38268- xorw %ax, %ax
38269- orl %eax, %edx
38270+ movl 4(%eax), %edx
38271+ movw (%eax), %dx
38272 // Now the address of the handler's in %edx
38273 // We call it now: its "iret" drops us home.
38274- jmp *%edx
38275+ ljmp $__KERNEL_CS, $1f
38276+1: jmp *%edx
38277
38278 // Every interrupt can come to us here
38279 // But we must truly tell each apart.
38280diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
38281index 0003992..854bbce 100644
38282--- a/drivers/md/bcache/closure.h
38283+++ b/drivers/md/bcache/closure.h
38284@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
38285 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
38286 struct workqueue_struct *wq)
38287 {
38288- BUG_ON(object_is_on_stack(cl));
38289+ BUG_ON(object_starts_on_stack(cl));
38290 closure_set_ip(cl);
38291 cl->fn = fn;
38292 cl->wq = wq;
38293diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
38294index 5a2c754..0fa55db 100644
38295--- a/drivers/md/bitmap.c
38296+++ b/drivers/md/bitmap.c
38297@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
38298 chunk_kb ? "KB" : "B");
38299 if (bitmap->storage.file) {
38300 seq_printf(seq, ", file: ");
38301- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
38302+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
38303 }
38304
38305 seq_printf(seq, "\n");
38306diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
38307index aa04f02..2a1309e 100644
38308--- a/drivers/md/dm-ioctl.c
38309+++ b/drivers/md/dm-ioctl.c
38310@@ -1694,7 +1694,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
38311 cmd == DM_LIST_VERSIONS_CMD)
38312 return 0;
38313
38314- if ((cmd == DM_DEV_CREATE_CMD)) {
38315+ if (cmd == DM_DEV_CREATE_CMD) {
38316 if (!*param->name) {
38317 DMWARN("name not supplied when creating device");
38318 return -EINVAL;
38319diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
38320index 699b5be..eac0a15 100644
38321--- a/drivers/md/dm-raid1.c
38322+++ b/drivers/md/dm-raid1.c
38323@@ -40,7 +40,7 @@ enum dm_raid1_error {
38324
38325 struct mirror {
38326 struct mirror_set *ms;
38327- atomic_t error_count;
38328+ atomic_unchecked_t error_count;
38329 unsigned long error_type;
38330 struct dm_dev *dev;
38331 sector_t offset;
38332@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
38333 struct mirror *m;
38334
38335 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
38336- if (!atomic_read(&m->error_count))
38337+ if (!atomic_read_unchecked(&m->error_count))
38338 return m;
38339
38340 return NULL;
38341@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
38342 * simple way to tell if a device has encountered
38343 * errors.
38344 */
38345- atomic_inc(&m->error_count);
38346+ atomic_inc_unchecked(&m->error_count);
38347
38348 if (test_and_set_bit(error_type, &m->error_type))
38349 return;
38350@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
38351 struct mirror *m = get_default_mirror(ms);
38352
38353 do {
38354- if (likely(!atomic_read(&m->error_count)))
38355+ if (likely(!atomic_read_unchecked(&m->error_count)))
38356 return m;
38357
38358 if (m-- == ms->mirror)
38359@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
38360 {
38361 struct mirror *default_mirror = get_default_mirror(m->ms);
38362
38363- return !atomic_read(&default_mirror->error_count);
38364+ return !atomic_read_unchecked(&default_mirror->error_count);
38365 }
38366
38367 static int mirror_available(struct mirror_set *ms, struct bio *bio)
38368@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
38369 */
38370 if (likely(region_in_sync(ms, region, 1)))
38371 m = choose_mirror(ms, bio->bi_sector);
38372- else if (m && atomic_read(&m->error_count))
38373+ else if (m && atomic_read_unchecked(&m->error_count))
38374 m = NULL;
38375
38376 if (likely(m))
38377@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
38378 }
38379
38380 ms->mirror[mirror].ms = ms;
38381- atomic_set(&(ms->mirror[mirror].error_count), 0);
38382+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
38383 ms->mirror[mirror].error_type = 0;
38384 ms->mirror[mirror].offset = offset;
38385
38386@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
38387 */
38388 static char device_status_char(struct mirror *m)
38389 {
38390- if (!atomic_read(&(m->error_count)))
38391+ if (!atomic_read_unchecked(&(m->error_count)))
38392 return 'A';
38393
38394 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
38395diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
38396index d907ca6..cfb8384 100644
38397--- a/drivers/md/dm-stripe.c
38398+++ b/drivers/md/dm-stripe.c
38399@@ -20,7 +20,7 @@ struct stripe {
38400 struct dm_dev *dev;
38401 sector_t physical_start;
38402
38403- atomic_t error_count;
38404+ atomic_unchecked_t error_count;
38405 };
38406
38407 struct stripe_c {
38408@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
38409 kfree(sc);
38410 return r;
38411 }
38412- atomic_set(&(sc->stripe[i].error_count), 0);
38413+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
38414 }
38415
38416 ti->private = sc;
38417@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
38418 DMEMIT("%d ", sc->stripes);
38419 for (i = 0; i < sc->stripes; i++) {
38420 DMEMIT("%s ", sc->stripe[i].dev->name);
38421- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
38422+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
38423 'D' : 'A';
38424 }
38425 buffer[i] = '\0';
38426@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
38427 */
38428 for (i = 0; i < sc->stripes; i++)
38429 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
38430- atomic_inc(&(sc->stripe[i].error_count));
38431- if (atomic_read(&(sc->stripe[i].error_count)) <
38432+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
38433+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
38434 DM_IO_ERROR_THRESHOLD)
38435 schedule_work(&sc->trigger_event);
38436 }
38437diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
38438index 1ff252a..ee384c1 100644
38439--- a/drivers/md/dm-table.c
38440+++ b/drivers/md/dm-table.c
38441@@ -389,7 +389,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
38442 if (!dev_size)
38443 return 0;
38444
38445- if ((start >= dev_size) || (start + len > dev_size)) {
38446+ if ((start >= dev_size) || (len > dev_size - start)) {
38447 DMWARN("%s: %s too small for target: "
38448 "start=%llu, len=%llu, dev_size=%llu",
38449 dm_device_name(ti->table->md), bdevname(bdev, b),
38450diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
38451index 60bce43..9b997d0 100644
38452--- a/drivers/md/dm-thin-metadata.c
38453+++ b/drivers/md/dm-thin-metadata.c
38454@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38455 {
38456 pmd->info.tm = pmd->tm;
38457 pmd->info.levels = 2;
38458- pmd->info.value_type.context = pmd->data_sm;
38459+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38460 pmd->info.value_type.size = sizeof(__le64);
38461 pmd->info.value_type.inc = data_block_inc;
38462 pmd->info.value_type.dec = data_block_dec;
38463@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38464
38465 pmd->bl_info.tm = pmd->tm;
38466 pmd->bl_info.levels = 1;
38467- pmd->bl_info.value_type.context = pmd->data_sm;
38468+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38469 pmd->bl_info.value_type.size = sizeof(__le64);
38470 pmd->bl_info.value_type.inc = data_block_inc;
38471 pmd->bl_info.value_type.dec = data_block_dec;
38472diff --git a/drivers/md/dm.c b/drivers/md/dm.c
38473index d5370a9..8761bbc 100644
38474--- a/drivers/md/dm.c
38475+++ b/drivers/md/dm.c
38476@@ -169,9 +169,9 @@ struct mapped_device {
38477 /*
38478 * Event handling.
38479 */
38480- atomic_t event_nr;
38481+ atomic_unchecked_t event_nr;
38482 wait_queue_head_t eventq;
38483- atomic_t uevent_seq;
38484+ atomic_unchecked_t uevent_seq;
38485 struct list_head uevent_list;
38486 spinlock_t uevent_lock; /* Protect access to uevent_list */
38487
38488@@ -1877,8 +1877,8 @@ static struct mapped_device *alloc_dev(int minor)
38489 rwlock_init(&md->map_lock);
38490 atomic_set(&md->holders, 1);
38491 atomic_set(&md->open_count, 0);
38492- atomic_set(&md->event_nr, 0);
38493- atomic_set(&md->uevent_seq, 0);
38494+ atomic_set_unchecked(&md->event_nr, 0);
38495+ atomic_set_unchecked(&md->uevent_seq, 0);
38496 INIT_LIST_HEAD(&md->uevent_list);
38497 spin_lock_init(&md->uevent_lock);
38498
38499@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
38500
38501 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
38502
38503- atomic_inc(&md->event_nr);
38504+ atomic_inc_unchecked(&md->event_nr);
38505 wake_up(&md->eventq);
38506 }
38507
38508@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
38509
38510 uint32_t dm_next_uevent_seq(struct mapped_device *md)
38511 {
38512- return atomic_add_return(1, &md->uevent_seq);
38513+ return atomic_add_return_unchecked(1, &md->uevent_seq);
38514 }
38515
38516 uint32_t dm_get_event_nr(struct mapped_device *md)
38517 {
38518- return atomic_read(&md->event_nr);
38519+ return atomic_read_unchecked(&md->event_nr);
38520 }
38521
38522 int dm_wait_event(struct mapped_device *md, int event_nr)
38523 {
38524 return wait_event_interruptible(md->eventq,
38525- (event_nr != atomic_read(&md->event_nr)));
38526+ (event_nr != atomic_read_unchecked(&md->event_nr)));
38527 }
38528
38529 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
38530diff --git a/drivers/md/md.c b/drivers/md/md.c
38531index 9b82377..6b6922d 100644
38532--- a/drivers/md/md.c
38533+++ b/drivers/md/md.c
38534@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
38535 * start build, activate spare
38536 */
38537 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
38538-static atomic_t md_event_count;
38539+static atomic_unchecked_t md_event_count;
38540 void md_new_event(struct mddev *mddev)
38541 {
38542- atomic_inc(&md_event_count);
38543+ atomic_inc_unchecked(&md_event_count);
38544 wake_up(&md_event_waiters);
38545 }
38546 EXPORT_SYMBOL_GPL(md_new_event);
38547@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
38548 */
38549 static void md_new_event_inintr(struct mddev *mddev)
38550 {
38551- atomic_inc(&md_event_count);
38552+ atomic_inc_unchecked(&md_event_count);
38553 wake_up(&md_event_waiters);
38554 }
38555
38556@@ -1501,7 +1501,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
38557 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
38558 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
38559 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
38560- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38561+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38562
38563 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
38564 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
38565@@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
38566 else
38567 sb->resync_offset = cpu_to_le64(0);
38568
38569- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
38570+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
38571
38572 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
38573 sb->size = cpu_to_le64(mddev->dev_sectors);
38574@@ -2750,7 +2750,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
38575 static ssize_t
38576 errors_show(struct md_rdev *rdev, char *page)
38577 {
38578- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
38579+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
38580 }
38581
38582 static ssize_t
38583@@ -2759,7 +2759,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
38584 char *e;
38585 unsigned long n = simple_strtoul(buf, &e, 10);
38586 if (*buf && (*e == 0 || *e == '\n')) {
38587- atomic_set(&rdev->corrected_errors, n);
38588+ atomic_set_unchecked(&rdev->corrected_errors, n);
38589 return len;
38590 }
38591 return -EINVAL;
38592@@ -3207,8 +3207,8 @@ int md_rdev_init(struct md_rdev *rdev)
38593 rdev->sb_loaded = 0;
38594 rdev->bb_page = NULL;
38595 atomic_set(&rdev->nr_pending, 0);
38596- atomic_set(&rdev->read_errors, 0);
38597- atomic_set(&rdev->corrected_errors, 0);
38598+ atomic_set_unchecked(&rdev->read_errors, 0);
38599+ atomic_set_unchecked(&rdev->corrected_errors, 0);
38600
38601 INIT_LIST_HEAD(&rdev->same_set);
38602 init_waitqueue_head(&rdev->blocked_wait);
38603@@ -7009,7 +7009,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
38604
38605 spin_unlock(&pers_lock);
38606 seq_printf(seq, "\n");
38607- seq->poll_event = atomic_read(&md_event_count);
38608+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38609 return 0;
38610 }
38611 if (v == (void*)2) {
38612@@ -7112,7 +7112,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
38613 return error;
38614
38615 seq = file->private_data;
38616- seq->poll_event = atomic_read(&md_event_count);
38617+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38618 return error;
38619 }
38620
38621@@ -7126,7 +7126,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
38622 /* always allow read */
38623 mask = POLLIN | POLLRDNORM;
38624
38625- if (seq->poll_event != atomic_read(&md_event_count))
38626+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
38627 mask |= POLLERR | POLLPRI;
38628 return mask;
38629 }
38630@@ -7170,7 +7170,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
38631 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
38632 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38633 (int)part_stat_read(&disk->part0, sectors[1]) -
38634- atomic_read(&disk->sync_io);
38635+ atomic_read_unchecked(&disk->sync_io);
38636 /* sync IO will cause sync_io to increase before the disk_stats
38637 * as sync_io is counted when a request starts, and
38638 * disk_stats is counted when it completes.
38639diff --git a/drivers/md/md.h b/drivers/md/md.h
38640index 653f992b6..6af6c40 100644
38641--- a/drivers/md/md.h
38642+++ b/drivers/md/md.h
38643@@ -94,13 +94,13 @@ struct md_rdev {
38644 * only maintained for arrays that
38645 * support hot removal
38646 */
38647- atomic_t read_errors; /* number of consecutive read errors that
38648+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
38649 * we have tried to ignore.
38650 */
38651 struct timespec last_read_error; /* monotonic time since our
38652 * last read error
38653 */
38654- atomic_t corrected_errors; /* number of corrected read errors,
38655+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
38656 * for reporting to userspace and storing
38657 * in superblock.
38658 */
38659@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
38660
38661 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
38662 {
38663- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38664+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38665 }
38666
38667 struct md_personality
38668diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
38669index 3e6d115..ffecdeb 100644
38670--- a/drivers/md/persistent-data/dm-space-map.h
38671+++ b/drivers/md/persistent-data/dm-space-map.h
38672@@ -71,6 +71,7 @@ struct dm_space_map {
38673 dm_sm_threshold_fn fn,
38674 void *context);
38675 };
38676+typedef struct dm_space_map __no_const dm_space_map_no_const;
38677
38678 /*----------------------------------------------------------------*/
38679
38680diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
38681index 6e17f81..140f717 100644
38682--- a/drivers/md/raid1.c
38683+++ b/drivers/md/raid1.c
38684@@ -1822,7 +1822,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
38685 if (r1_sync_page_io(rdev, sect, s,
38686 bio->bi_io_vec[idx].bv_page,
38687 READ) != 0)
38688- atomic_add(s, &rdev->corrected_errors);
38689+ atomic_add_unchecked(s, &rdev->corrected_errors);
38690 }
38691 sectors -= s;
38692 sect += s;
38693@@ -2042,7 +2042,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
38694 test_bit(In_sync, &rdev->flags)) {
38695 if (r1_sync_page_io(rdev, sect, s,
38696 conf->tmppage, READ)) {
38697- atomic_add(s, &rdev->corrected_errors);
38698+ atomic_add_unchecked(s, &rdev->corrected_errors);
38699 printk(KERN_INFO
38700 "md/raid1:%s: read error corrected "
38701 "(%d sectors at %llu on %s)\n",
38702diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38703index 6ddae25..514caa9 100644
38704--- a/drivers/md/raid10.c
38705+++ b/drivers/md/raid10.c
38706@@ -1940,7 +1940,7 @@ static void end_sync_read(struct bio *bio, int error)
38707 /* The write handler will notice the lack of
38708 * R10BIO_Uptodate and record any errors etc
38709 */
38710- atomic_add(r10_bio->sectors,
38711+ atomic_add_unchecked(r10_bio->sectors,
38712 &conf->mirrors[d].rdev->corrected_errors);
38713
38714 /* for reconstruct, we always reschedule after a read.
38715@@ -2286,7 +2286,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38716 {
38717 struct timespec cur_time_mon;
38718 unsigned long hours_since_last;
38719- unsigned int read_errors = atomic_read(&rdev->read_errors);
38720+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38721
38722 ktime_get_ts(&cur_time_mon);
38723
38724@@ -2308,9 +2308,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38725 * overflowing the shift of read_errors by hours_since_last.
38726 */
38727 if (hours_since_last >= 8 * sizeof(read_errors))
38728- atomic_set(&rdev->read_errors, 0);
38729+ atomic_set_unchecked(&rdev->read_errors, 0);
38730 else
38731- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38732+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38733 }
38734
38735 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38736@@ -2364,8 +2364,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38737 return;
38738
38739 check_decay_read_errors(mddev, rdev);
38740- atomic_inc(&rdev->read_errors);
38741- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38742+ atomic_inc_unchecked(&rdev->read_errors);
38743+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38744 char b[BDEVNAME_SIZE];
38745 bdevname(rdev->bdev, b);
38746
38747@@ -2373,7 +2373,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38748 "md/raid10:%s: %s: Raid device exceeded "
38749 "read_error threshold [cur %d:max %d]\n",
38750 mdname(mddev), b,
38751- atomic_read(&rdev->read_errors), max_read_errors);
38752+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38753 printk(KERN_NOTICE
38754 "md/raid10:%s: %s: Failing raid device\n",
38755 mdname(mddev), b);
38756@@ -2528,7 +2528,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38757 sect +
38758 choose_data_offset(r10_bio, rdev)),
38759 bdevname(rdev->bdev, b));
38760- atomic_add(s, &rdev->corrected_errors);
38761+ atomic_add_unchecked(s, &rdev->corrected_errors);
38762 }
38763
38764 rdev_dec_pending(rdev, mddev);
38765diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38766index 05e4a10..48fbe37 100644
38767--- a/drivers/md/raid5.c
38768+++ b/drivers/md/raid5.c
38769@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38770 mdname(conf->mddev), STRIPE_SECTORS,
38771 (unsigned long long)s,
38772 bdevname(rdev->bdev, b));
38773- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38774+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38775 clear_bit(R5_ReadError, &sh->dev[i].flags);
38776 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38777 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38778 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38779
38780- if (atomic_read(&rdev->read_errors))
38781- atomic_set(&rdev->read_errors, 0);
38782+ if (atomic_read_unchecked(&rdev->read_errors))
38783+ atomic_set_unchecked(&rdev->read_errors, 0);
38784 } else {
38785 const char *bdn = bdevname(rdev->bdev, b);
38786 int retry = 0;
38787 int set_bad = 0;
38788
38789 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38790- atomic_inc(&rdev->read_errors);
38791+ atomic_inc_unchecked(&rdev->read_errors);
38792 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38793 printk_ratelimited(
38794 KERN_WARNING
38795@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38796 mdname(conf->mddev),
38797 (unsigned long long)s,
38798 bdn);
38799- } else if (atomic_read(&rdev->read_errors)
38800+ } else if (atomic_read_unchecked(&rdev->read_errors)
38801 > conf->max_nr_stripes)
38802 printk(KERN_WARNING
38803 "md/raid:%s: Too many read errors, failing device %s.\n",
38804diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38805index 401ef64..836e563 100644
38806--- a/drivers/media/dvb-core/dvbdev.c
38807+++ b/drivers/media/dvb-core/dvbdev.c
38808@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38809 const struct dvb_device *template, void *priv, int type)
38810 {
38811 struct dvb_device *dvbdev;
38812- struct file_operations *dvbdevfops;
38813+ file_operations_no_const *dvbdevfops;
38814 struct device *clsdev;
38815 int minor;
38816 int id;
38817diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38818index 9b6c3bb..baeb5c7 100644
38819--- a/drivers/media/dvb-frontends/dib3000.h
38820+++ b/drivers/media/dvb-frontends/dib3000.h
38821@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38822 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38823 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38824 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38825-};
38826+} __no_const;
38827
38828 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
38829 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38830diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
38831index c7a9be1..683f6f8 100644
38832--- a/drivers/media/pci/cx88/cx88-video.c
38833+++ b/drivers/media/pci/cx88/cx88-video.c
38834@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
38835
38836 /* ------------------------------------------------------------------ */
38837
38838-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38839-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38840-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38841+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38842+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38843+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38844
38845 module_param_array(video_nr, int, NULL, 0444);
38846 module_param_array(vbi_nr, int, NULL, 0444);
38847diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38848index d338b19..aae4f9e 100644
38849--- a/drivers/media/platform/omap/omap_vout.c
38850+++ b/drivers/media/platform/omap/omap_vout.c
38851@@ -63,7 +63,6 @@ enum omap_vout_channels {
38852 OMAP_VIDEO2,
38853 };
38854
38855-static struct videobuf_queue_ops video_vbq_ops;
38856 /* Variables configurable through module params*/
38857 static u32 video1_numbuffers = 3;
38858 static u32 video2_numbuffers = 3;
38859@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
38860 {
38861 struct videobuf_queue *q;
38862 struct omap_vout_device *vout = NULL;
38863+ static struct videobuf_queue_ops video_vbq_ops = {
38864+ .buf_setup = omap_vout_buffer_setup,
38865+ .buf_prepare = omap_vout_buffer_prepare,
38866+ .buf_release = omap_vout_buffer_release,
38867+ .buf_queue = omap_vout_buffer_queue,
38868+ };
38869
38870 vout = video_drvdata(file);
38871 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38872@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
38873 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38874
38875 q = &vout->vbq;
38876- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38877- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38878- video_vbq_ops.buf_release = omap_vout_buffer_release;
38879- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38880 spin_lock_init(&vout->vbq_lock);
38881
38882 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38883diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38884index 04e6490..2df65bf 100644
38885--- a/drivers/media/platform/s5p-tv/mixer.h
38886+++ b/drivers/media/platform/s5p-tv/mixer.h
38887@@ -156,7 +156,7 @@ struct mxr_layer {
38888 /** layer index (unique identifier) */
38889 int idx;
38890 /** callbacks for layer methods */
38891- struct mxr_layer_ops ops;
38892+ struct mxr_layer_ops *ops;
38893 /** format array */
38894 const struct mxr_format **fmt_array;
38895 /** size of format array */
38896diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38897index b93a21f..2535195 100644
38898--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38899+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38900@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38901 {
38902 struct mxr_layer *layer;
38903 int ret;
38904- struct mxr_layer_ops ops = {
38905+ static struct mxr_layer_ops ops = {
38906 .release = mxr_graph_layer_release,
38907 .buffer_set = mxr_graph_buffer_set,
38908 .stream_set = mxr_graph_stream_set,
38909diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38910index b713403..53cb5ad 100644
38911--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38912+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38913@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38914 layer->update_buf = next;
38915 }
38916
38917- layer->ops.buffer_set(layer, layer->update_buf);
38918+ layer->ops->buffer_set(layer, layer->update_buf);
38919
38920 if (done && done != layer->shadow_buf)
38921 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38922diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38923index ef0efdf..8c78eb6 100644
38924--- a/drivers/media/platform/s5p-tv/mixer_video.c
38925+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38926@@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38927 layer->geo.src.height = layer->geo.src.full_height;
38928
38929 mxr_geometry_dump(mdev, &layer->geo);
38930- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38931+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38932 mxr_geometry_dump(mdev, &layer->geo);
38933 }
38934
38935@@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38936 layer->geo.dst.full_width = mbus_fmt.width;
38937 layer->geo.dst.full_height = mbus_fmt.height;
38938 layer->geo.dst.field = mbus_fmt.field;
38939- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38940+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38941
38942 mxr_geometry_dump(mdev, &layer->geo);
38943 }
38944@@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38945 /* set source size to highest accepted value */
38946 geo->src.full_width = max(geo->dst.full_width, pix->width);
38947 geo->src.full_height = max(geo->dst.full_height, pix->height);
38948- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38949+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38950 mxr_geometry_dump(mdev, &layer->geo);
38951 /* set cropping to total visible screen */
38952 geo->src.width = pix->width;
38953@@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38954 geo->src.x_offset = 0;
38955 geo->src.y_offset = 0;
38956 /* assure consistency of geometry */
38957- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38958+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38959 mxr_geometry_dump(mdev, &layer->geo);
38960 /* set full size to lowest possible value */
38961 geo->src.full_width = 0;
38962 geo->src.full_height = 0;
38963- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38964+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38965 mxr_geometry_dump(mdev, &layer->geo);
38966
38967 /* returning results */
38968@@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38969 target->width = s->r.width;
38970 target->height = s->r.height;
38971
38972- layer->ops.fix_geometry(layer, stage, s->flags);
38973+ layer->ops->fix_geometry(layer, stage, s->flags);
38974
38975 /* retrieve update selection rectangle */
38976 res.left = target->x_offset;
38977@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38978 mxr_output_get(mdev);
38979
38980 mxr_layer_update_output(layer);
38981- layer->ops.format_set(layer);
38982+ layer->ops->format_set(layer);
38983 /* enabling layer in hardware */
38984 spin_lock_irqsave(&layer->enq_slock, flags);
38985 layer->state = MXR_LAYER_STREAMING;
38986 spin_unlock_irqrestore(&layer->enq_slock, flags);
38987
38988- layer->ops.stream_set(layer, MXR_ENABLE);
38989+ layer->ops->stream_set(layer, MXR_ENABLE);
38990 mxr_streamer_get(mdev);
38991
38992 return 0;
38993@@ -1030,7 +1030,7 @@ static int stop_streaming(struct vb2_queue *vq)
38994 spin_unlock_irqrestore(&layer->enq_slock, flags);
38995
38996 /* disabling layer in hardware */
38997- layer->ops.stream_set(layer, MXR_DISABLE);
38998+ layer->ops->stream_set(layer, MXR_DISABLE);
38999 /* remove one streamer */
39000 mxr_streamer_put(mdev);
39001 /* allow changes in output configuration */
39002@@ -1069,8 +1069,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
39003
39004 void mxr_layer_release(struct mxr_layer *layer)
39005 {
39006- if (layer->ops.release)
39007- layer->ops.release(layer);
39008+ if (layer->ops->release)
39009+ layer->ops->release(layer);
39010 }
39011
39012 void mxr_base_layer_release(struct mxr_layer *layer)
39013@@ -1096,7 +1096,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
39014
39015 layer->mdev = mdev;
39016 layer->idx = idx;
39017- layer->ops = *ops;
39018+ layer->ops = ops;
39019
39020 spin_lock_init(&layer->enq_slock);
39021 INIT_LIST_HEAD(&layer->enq_list);
39022diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39023index 3d13a63..da31bf1 100644
39024--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39025+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39026@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
39027 {
39028 struct mxr_layer *layer;
39029 int ret;
39030- struct mxr_layer_ops ops = {
39031+ static struct mxr_layer_ops ops = {
39032 .release = mxr_vp_layer_release,
39033 .buffer_set = mxr_vp_buffer_set,
39034 .stream_set = mxr_vp_stream_set,
39035diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
39036index 545c04c..a14bded 100644
39037--- a/drivers/media/radio/radio-cadet.c
39038+++ b/drivers/media/radio/radio-cadet.c
39039@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
39040 unsigned char readbuf[RDS_BUFFER];
39041 int i = 0;
39042
39043+ if (count > RDS_BUFFER)
39044+ return -EFAULT;
39045 mutex_lock(&dev->lock);
39046 if (dev->rdsstat == 0)
39047 cadet_start_rds(dev);
39048@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
39049 while (i < count && dev->rdsin != dev->rdsout)
39050 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
39051
39052- if (i && copy_to_user(data, readbuf, i))
39053+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
39054 i = -EFAULT;
39055 unlock:
39056 mutex_unlock(&dev->lock);
39057diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
39058index 3940bb0..fb3952a 100644
39059--- a/drivers/media/usb/dvb-usb/cxusb.c
39060+++ b/drivers/media/usb/dvb-usb/cxusb.c
39061@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
39062
39063 struct dib0700_adapter_state {
39064 int (*set_param_save) (struct dvb_frontend *);
39065-};
39066+} __no_const;
39067
39068 static int dib7070_set_param_override(struct dvb_frontend *fe)
39069 {
39070diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
39071index 6e237b6..dc25556 100644
39072--- a/drivers/media/usb/dvb-usb/dw2102.c
39073+++ b/drivers/media/usb/dvb-usb/dw2102.c
39074@@ -118,7 +118,7 @@ struct su3000_state {
39075
39076 struct s6x0_state {
39077 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
39078-};
39079+} __no_const;
39080
39081 /* debug */
39082 static int dvb_usb_dw2102_debug;
39083diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
39084index f129551..ecf6514 100644
39085--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
39086+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
39087@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
39088 __u32 reserved;
39089 };
39090
39091-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
39092+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
39093 enum v4l2_memory memory)
39094 {
39095 void __user *up_pln;
39096@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
39097 return 0;
39098 }
39099
39100-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
39101+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
39102 enum v4l2_memory memory)
39103 {
39104 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
39105@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
39106 put_user(kp->start_block, &up->start_block) ||
39107 put_user(kp->blocks, &up->blocks) ||
39108 put_user(tmp, &up->edid) ||
39109- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
39110+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
39111 return -EFAULT;
39112 return 0;
39113 }
39114diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
39115index 7658586..1079260 100644
39116--- a/drivers/media/v4l2-core/v4l2-ioctl.c
39117+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
39118@@ -1995,7 +1995,8 @@ struct v4l2_ioctl_info {
39119 struct file *file, void *fh, void *p);
39120 } u;
39121 void (*debug)(const void *arg, bool write_only);
39122-};
39123+} __do_const;
39124+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
39125
39126 /* This control needs a priority check */
39127 #define INFO_FL_PRIO (1 << 0)
39128@@ -2177,7 +2178,7 @@ static long __video_do_ioctl(struct file *file,
39129 struct video_device *vfd = video_devdata(file);
39130 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
39131 bool write_only = false;
39132- struct v4l2_ioctl_info default_info;
39133+ v4l2_ioctl_info_no_const default_info;
39134 const struct v4l2_ioctl_info *info;
39135 void *fh = file->private_data;
39136 struct v4l2_fh *vfh = NULL;
39137@@ -2251,7 +2252,7 @@ done:
39138 }
39139
39140 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39141- void * __user *user_ptr, void ***kernel_ptr)
39142+ void __user **user_ptr, void ***kernel_ptr)
39143 {
39144 int ret = 0;
39145
39146@@ -2267,7 +2268,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39147 ret = -EINVAL;
39148 break;
39149 }
39150- *user_ptr = (void __user *)buf->m.planes;
39151+ *user_ptr = (void __force_user *)buf->m.planes;
39152 *kernel_ptr = (void *)&buf->m.planes;
39153 *array_size = sizeof(struct v4l2_plane) * buf->length;
39154 ret = 1;
39155@@ -2302,7 +2303,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39156 ret = -EINVAL;
39157 break;
39158 }
39159- *user_ptr = (void __user *)ctrls->controls;
39160+ *user_ptr = (void __force_user *)ctrls->controls;
39161 *kernel_ptr = (void *)&ctrls->controls;
39162 *array_size = sizeof(struct v4l2_ext_control)
39163 * ctrls->count;
39164diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
39165index 767ff4d..c69d259 100644
39166--- a/drivers/message/fusion/mptbase.c
39167+++ b/drivers/message/fusion/mptbase.c
39168@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
39169 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
39170 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
39171
39172+#ifdef CONFIG_GRKERNSEC_HIDESYM
39173+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
39174+#else
39175 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
39176 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
39177+#endif
39178+
39179 /*
39180 * Rounding UP to nearest 4-kB boundary here...
39181 */
39182@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
39183 ioc->facts.GlobalCredits);
39184
39185 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
39186+#ifdef CONFIG_GRKERNSEC_HIDESYM
39187+ NULL, NULL);
39188+#else
39189 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
39190+#endif
39191 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
39192 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
39193 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
39194diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
39195index dd239bd..689c4f7 100644
39196--- a/drivers/message/fusion/mptsas.c
39197+++ b/drivers/message/fusion/mptsas.c
39198@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
39199 return 0;
39200 }
39201
39202+static inline void
39203+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39204+{
39205+ if (phy_info->port_details) {
39206+ phy_info->port_details->rphy = rphy;
39207+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39208+ ioc->name, rphy));
39209+ }
39210+
39211+ if (rphy) {
39212+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39213+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39214+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39215+ ioc->name, rphy, rphy->dev.release));
39216+ }
39217+}
39218+
39219 /* no mutex */
39220 static void
39221 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
39222@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
39223 return NULL;
39224 }
39225
39226-static inline void
39227-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39228-{
39229- if (phy_info->port_details) {
39230- phy_info->port_details->rphy = rphy;
39231- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39232- ioc->name, rphy));
39233- }
39234-
39235- if (rphy) {
39236- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39237- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39238- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39239- ioc->name, rphy, rphy->dev.release));
39240- }
39241-}
39242-
39243 static inline struct sas_port *
39244 mptsas_get_port(struct mptsas_phyinfo *phy_info)
39245 {
39246diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
39247index 727819c..ad74694 100644
39248--- a/drivers/message/fusion/mptscsih.c
39249+++ b/drivers/message/fusion/mptscsih.c
39250@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
39251
39252 h = shost_priv(SChost);
39253
39254- if (h) {
39255- if (h->info_kbuf == NULL)
39256- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39257- return h->info_kbuf;
39258- h->info_kbuf[0] = '\0';
39259+ if (!h)
39260+ return NULL;
39261
39262- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39263- h->info_kbuf[size-1] = '\0';
39264- }
39265+ if (h->info_kbuf == NULL)
39266+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39267+ return h->info_kbuf;
39268+ h->info_kbuf[0] = '\0';
39269+
39270+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39271+ h->info_kbuf[size-1] = '\0';
39272
39273 return h->info_kbuf;
39274 }
39275diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
39276index b7d87cd..9890039 100644
39277--- a/drivers/message/i2o/i2o_proc.c
39278+++ b/drivers/message/i2o/i2o_proc.c
39279@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
39280 "Array Controller Device"
39281 };
39282
39283-static char *chtostr(char *tmp, u8 *chars, int n)
39284-{
39285- tmp[0] = 0;
39286- return strncat(tmp, (char *)chars, n);
39287-}
39288-
39289 static int i2o_report_query_status(struct seq_file *seq, int block_status,
39290 char *group)
39291 {
39292@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39293 } *result;
39294
39295 i2o_exec_execute_ddm_table ddm_table;
39296- char tmp[28 + 1];
39297
39298 result = kmalloc(sizeof(*result), GFP_KERNEL);
39299 if (!result)
39300@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39301
39302 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
39303 seq_printf(seq, "%-#8x", ddm_table.module_id);
39304- seq_printf(seq, "%-29s",
39305- chtostr(tmp, ddm_table.module_name_version, 28));
39306+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
39307 seq_printf(seq, "%9d ", ddm_table.data_size);
39308 seq_printf(seq, "%8d", ddm_table.code_size);
39309
39310@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39311
39312 i2o_driver_result_table *result;
39313 i2o_driver_store_table *dst;
39314- char tmp[28 + 1];
39315
39316 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
39317 if (result == NULL)
39318@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39319
39320 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
39321 seq_printf(seq, "%-#8x", dst->module_id);
39322- seq_printf(seq, "%-29s",
39323- chtostr(tmp, dst->module_name_version, 28));
39324- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
39325+ seq_printf(seq, "%-.28s", dst->module_name_version);
39326+ seq_printf(seq, "%-.8s", dst->date);
39327 seq_printf(seq, "%8d ", dst->module_size);
39328 seq_printf(seq, "%8d ", dst->mpb_size);
39329 seq_printf(seq, "0x%04x", dst->module_flags);
39330@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39331 // == (allow) 512d bytes (max)
39332 static u16 *work16 = (u16 *) work32;
39333 int token;
39334- char tmp[16 + 1];
39335
39336 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
39337
39338@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39339 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
39340 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
39341 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
39342- seq_printf(seq, "Vendor info : %s\n",
39343- chtostr(tmp, (u8 *) (work32 + 2), 16));
39344- seq_printf(seq, "Product info : %s\n",
39345- chtostr(tmp, (u8 *) (work32 + 6), 16));
39346- seq_printf(seq, "Description : %s\n",
39347- chtostr(tmp, (u8 *) (work32 + 10), 16));
39348- seq_printf(seq, "Product rev. : %s\n",
39349- chtostr(tmp, (u8 *) (work32 + 14), 8));
39350+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
39351+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
39352+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
39353+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
39354
39355 seq_printf(seq, "Serial number : ");
39356 print_serial_number(seq, (u8 *) (work32 + 16),
39357@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39358 u8 pad[256]; // allow up to 256 byte (max) serial number
39359 } result;
39360
39361- char tmp[24 + 1];
39362-
39363 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
39364
39365 if (token < 0) {
39366@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39367 }
39368
39369 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
39370- seq_printf(seq, "Module name : %s\n",
39371- chtostr(tmp, result.module_name, 24));
39372- seq_printf(seq, "Module revision : %s\n",
39373- chtostr(tmp, result.module_rev, 8));
39374+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
39375+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
39376
39377 seq_printf(seq, "Serial number : ");
39378 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
39379@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39380 u8 instance_number[4];
39381 } result;
39382
39383- char tmp[64 + 1];
39384-
39385 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
39386
39387 if (token < 0) {
39388@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39389 return 0;
39390 }
39391
39392- seq_printf(seq, "Device name : %s\n",
39393- chtostr(tmp, result.device_name, 64));
39394- seq_printf(seq, "Service name : %s\n",
39395- chtostr(tmp, result.service_name, 64));
39396- seq_printf(seq, "Physical name : %s\n",
39397- chtostr(tmp, result.physical_location, 64));
39398- seq_printf(seq, "Instance number : %s\n",
39399- chtostr(tmp, result.instance_number, 4));
39400+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
39401+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
39402+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
39403+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
39404
39405 return 0;
39406 }
39407diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
39408index a8c08f3..155fe3d 100644
39409--- a/drivers/message/i2o/iop.c
39410+++ b/drivers/message/i2o/iop.c
39411@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
39412
39413 spin_lock_irqsave(&c->context_list_lock, flags);
39414
39415- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
39416- atomic_inc(&c->context_list_counter);
39417+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
39418+ atomic_inc_unchecked(&c->context_list_counter);
39419
39420- entry->context = atomic_read(&c->context_list_counter);
39421+ entry->context = atomic_read_unchecked(&c->context_list_counter);
39422
39423 list_add(&entry->list, &c->context_list);
39424
39425@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
39426
39427 #if BITS_PER_LONG == 64
39428 spin_lock_init(&c->context_list_lock);
39429- atomic_set(&c->context_list_counter, 0);
39430+ atomic_set_unchecked(&c->context_list_counter, 0);
39431 INIT_LIST_HEAD(&c->context_list);
39432 #endif
39433
39434diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
39435index 45ece11..8efa218 100644
39436--- a/drivers/mfd/janz-cmodio.c
39437+++ b/drivers/mfd/janz-cmodio.c
39438@@ -13,6 +13,7 @@
39439
39440 #include <linux/kernel.h>
39441 #include <linux/module.h>
39442+#include <linux/slab.h>
39443 #include <linux/init.h>
39444 #include <linux/pci.h>
39445 #include <linux/interrupt.h>
39446diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
39447index a5f9888..1c0ed56 100644
39448--- a/drivers/mfd/twl4030-irq.c
39449+++ b/drivers/mfd/twl4030-irq.c
39450@@ -35,6 +35,7 @@
39451 #include <linux/of.h>
39452 #include <linux/irqdomain.h>
39453 #include <linux/i2c/twl.h>
39454+#include <asm/pgtable.h>
39455
39456 #include "twl-core.h"
39457
39458@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
39459 * Install an irq handler for each of the SIH modules;
39460 * clone dummy irq_chip since PIH can't *do* anything
39461 */
39462- twl4030_irq_chip = dummy_irq_chip;
39463- twl4030_irq_chip.name = "twl4030";
39464+ pax_open_kernel();
39465+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
39466+ *(const char **)&twl4030_irq_chip.name = "twl4030";
39467
39468- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39469+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39470+ pax_close_kernel();
39471
39472 for (i = irq_base; i < irq_end; i++) {
39473 irq_set_chip_and_handler(i, &twl4030_irq_chip,
39474diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
39475index 277a8db..0e0b754 100644
39476--- a/drivers/mfd/twl6030-irq.c
39477+++ b/drivers/mfd/twl6030-irq.c
39478@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
39479 * install an irq handler for each of the modules;
39480 * clone dummy irq_chip since PIH can't *do* anything
39481 */
39482- twl6030_irq_chip = dummy_irq_chip;
39483- twl6030_irq_chip.name = "twl6030";
39484- twl6030_irq_chip.irq_set_type = NULL;
39485- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39486+ pax_open_kernel();
39487+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
39488+ *(const char **)&twl6030_irq_chip.name = "twl6030";
39489+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
39490+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39491+ pax_close_kernel();
39492
39493 for (i = irq_base; i < irq_end; i++) {
39494 irq_set_chip_and_handler(i, &twl6030_irq_chip,
39495diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
39496index f32550a..e3e52a2 100644
39497--- a/drivers/misc/c2port/core.c
39498+++ b/drivers/misc/c2port/core.c
39499@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
39500 mutex_init(&c2dev->mutex);
39501
39502 /* Create binary file */
39503- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39504+ pax_open_kernel();
39505+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39506+ pax_close_kernel();
39507 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
39508 if (unlikely(ret))
39509 goto error_device_create_bin_file;
39510diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
39511index 36f5d52..32311c3 100644
39512--- a/drivers/misc/kgdbts.c
39513+++ b/drivers/misc/kgdbts.c
39514@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
39515 char before[BREAK_INSTR_SIZE];
39516 char after[BREAK_INSTR_SIZE];
39517
39518- probe_kernel_read(before, (char *)kgdbts_break_test,
39519+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
39520 BREAK_INSTR_SIZE);
39521 init_simple_test();
39522 ts.tst = plant_and_detach_test;
39523@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
39524 /* Activate test with initial breakpoint */
39525 if (!is_early)
39526 kgdb_breakpoint();
39527- probe_kernel_read(after, (char *)kgdbts_break_test,
39528+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
39529 BREAK_INSTR_SIZE);
39530 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
39531 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
39532diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
39533index 4cd4a3d..b48cbc7 100644
39534--- a/drivers/misc/lis3lv02d/lis3lv02d.c
39535+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
39536@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
39537 * the lid is closed. This leads to interrupts as soon as a little move
39538 * is done.
39539 */
39540- atomic_inc(&lis3->count);
39541+ atomic_inc_unchecked(&lis3->count);
39542
39543 wake_up_interruptible(&lis3->misc_wait);
39544 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
39545@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
39546 if (lis3->pm_dev)
39547 pm_runtime_get_sync(lis3->pm_dev);
39548
39549- atomic_set(&lis3->count, 0);
39550+ atomic_set_unchecked(&lis3->count, 0);
39551 return 0;
39552 }
39553
39554@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
39555 add_wait_queue(&lis3->misc_wait, &wait);
39556 while (true) {
39557 set_current_state(TASK_INTERRUPTIBLE);
39558- data = atomic_xchg(&lis3->count, 0);
39559+ data = atomic_xchg_unchecked(&lis3->count, 0);
39560 if (data)
39561 break;
39562
39563@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
39564 struct lis3lv02d, miscdev);
39565
39566 poll_wait(file, &lis3->misc_wait, wait);
39567- if (atomic_read(&lis3->count))
39568+ if (atomic_read_unchecked(&lis3->count))
39569 return POLLIN | POLLRDNORM;
39570 return 0;
39571 }
39572diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
39573index c439c82..1f20f57 100644
39574--- a/drivers/misc/lis3lv02d/lis3lv02d.h
39575+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
39576@@ -297,7 +297,7 @@ struct lis3lv02d {
39577 struct input_polled_dev *idev; /* input device */
39578 struct platform_device *pdev; /* platform device */
39579 struct regulator_bulk_data regulators[2];
39580- atomic_t count; /* interrupt count after last read */
39581+ atomic_unchecked_t count; /* interrupt count after last read */
39582 union axis_conversion ac; /* hw -> logical axis */
39583 int mapped_btns[3];
39584
39585diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
39586index 2f30bad..c4c13d0 100644
39587--- a/drivers/misc/sgi-gru/gruhandles.c
39588+++ b/drivers/misc/sgi-gru/gruhandles.c
39589@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
39590 unsigned long nsec;
39591
39592 nsec = CLKS2NSEC(clks);
39593- atomic_long_inc(&mcs_op_statistics[op].count);
39594- atomic_long_add(nsec, &mcs_op_statistics[op].total);
39595+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
39596+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
39597 if (mcs_op_statistics[op].max < nsec)
39598 mcs_op_statistics[op].max = nsec;
39599 }
39600diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
39601index 797d796..ae8f01e 100644
39602--- a/drivers/misc/sgi-gru/gruprocfs.c
39603+++ b/drivers/misc/sgi-gru/gruprocfs.c
39604@@ -32,9 +32,9 @@
39605
39606 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
39607
39608-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
39609+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
39610 {
39611- unsigned long val = atomic_long_read(v);
39612+ unsigned long val = atomic_long_read_unchecked(v);
39613
39614 seq_printf(s, "%16lu %s\n", val, id);
39615 }
39616@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
39617
39618 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
39619 for (op = 0; op < mcsop_last; op++) {
39620- count = atomic_long_read(&mcs_op_statistics[op].count);
39621- total = atomic_long_read(&mcs_op_statistics[op].total);
39622+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
39623+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
39624 max = mcs_op_statistics[op].max;
39625 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
39626 count ? total / count : 0, max);
39627diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
39628index 5c3ce24..4915ccb 100644
39629--- a/drivers/misc/sgi-gru/grutables.h
39630+++ b/drivers/misc/sgi-gru/grutables.h
39631@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
39632 * GRU statistics.
39633 */
39634 struct gru_stats_s {
39635- atomic_long_t vdata_alloc;
39636- atomic_long_t vdata_free;
39637- atomic_long_t gts_alloc;
39638- atomic_long_t gts_free;
39639- atomic_long_t gms_alloc;
39640- atomic_long_t gms_free;
39641- atomic_long_t gts_double_allocate;
39642- atomic_long_t assign_context;
39643- atomic_long_t assign_context_failed;
39644- atomic_long_t free_context;
39645- atomic_long_t load_user_context;
39646- atomic_long_t load_kernel_context;
39647- atomic_long_t lock_kernel_context;
39648- atomic_long_t unlock_kernel_context;
39649- atomic_long_t steal_user_context;
39650- atomic_long_t steal_kernel_context;
39651- atomic_long_t steal_context_failed;
39652- atomic_long_t nopfn;
39653- atomic_long_t asid_new;
39654- atomic_long_t asid_next;
39655- atomic_long_t asid_wrap;
39656- atomic_long_t asid_reuse;
39657- atomic_long_t intr;
39658- atomic_long_t intr_cbr;
39659- atomic_long_t intr_tfh;
39660- atomic_long_t intr_spurious;
39661- atomic_long_t intr_mm_lock_failed;
39662- atomic_long_t call_os;
39663- atomic_long_t call_os_wait_queue;
39664- atomic_long_t user_flush_tlb;
39665- atomic_long_t user_unload_context;
39666- atomic_long_t user_exception;
39667- atomic_long_t set_context_option;
39668- atomic_long_t check_context_retarget_intr;
39669- atomic_long_t check_context_unload;
39670- atomic_long_t tlb_dropin;
39671- atomic_long_t tlb_preload_page;
39672- atomic_long_t tlb_dropin_fail_no_asid;
39673- atomic_long_t tlb_dropin_fail_upm;
39674- atomic_long_t tlb_dropin_fail_invalid;
39675- atomic_long_t tlb_dropin_fail_range_active;
39676- atomic_long_t tlb_dropin_fail_idle;
39677- atomic_long_t tlb_dropin_fail_fmm;
39678- atomic_long_t tlb_dropin_fail_no_exception;
39679- atomic_long_t tfh_stale_on_fault;
39680- atomic_long_t mmu_invalidate_range;
39681- atomic_long_t mmu_invalidate_page;
39682- atomic_long_t flush_tlb;
39683- atomic_long_t flush_tlb_gru;
39684- atomic_long_t flush_tlb_gru_tgh;
39685- atomic_long_t flush_tlb_gru_zero_asid;
39686+ atomic_long_unchecked_t vdata_alloc;
39687+ atomic_long_unchecked_t vdata_free;
39688+ atomic_long_unchecked_t gts_alloc;
39689+ atomic_long_unchecked_t gts_free;
39690+ atomic_long_unchecked_t gms_alloc;
39691+ atomic_long_unchecked_t gms_free;
39692+ atomic_long_unchecked_t gts_double_allocate;
39693+ atomic_long_unchecked_t assign_context;
39694+ atomic_long_unchecked_t assign_context_failed;
39695+ atomic_long_unchecked_t free_context;
39696+ atomic_long_unchecked_t load_user_context;
39697+ atomic_long_unchecked_t load_kernel_context;
39698+ atomic_long_unchecked_t lock_kernel_context;
39699+ atomic_long_unchecked_t unlock_kernel_context;
39700+ atomic_long_unchecked_t steal_user_context;
39701+ atomic_long_unchecked_t steal_kernel_context;
39702+ atomic_long_unchecked_t steal_context_failed;
39703+ atomic_long_unchecked_t nopfn;
39704+ atomic_long_unchecked_t asid_new;
39705+ atomic_long_unchecked_t asid_next;
39706+ atomic_long_unchecked_t asid_wrap;
39707+ atomic_long_unchecked_t asid_reuse;
39708+ atomic_long_unchecked_t intr;
39709+ atomic_long_unchecked_t intr_cbr;
39710+ atomic_long_unchecked_t intr_tfh;
39711+ atomic_long_unchecked_t intr_spurious;
39712+ atomic_long_unchecked_t intr_mm_lock_failed;
39713+ atomic_long_unchecked_t call_os;
39714+ atomic_long_unchecked_t call_os_wait_queue;
39715+ atomic_long_unchecked_t user_flush_tlb;
39716+ atomic_long_unchecked_t user_unload_context;
39717+ atomic_long_unchecked_t user_exception;
39718+ atomic_long_unchecked_t set_context_option;
39719+ atomic_long_unchecked_t check_context_retarget_intr;
39720+ atomic_long_unchecked_t check_context_unload;
39721+ atomic_long_unchecked_t tlb_dropin;
39722+ atomic_long_unchecked_t tlb_preload_page;
39723+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
39724+ atomic_long_unchecked_t tlb_dropin_fail_upm;
39725+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
39726+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
39727+ atomic_long_unchecked_t tlb_dropin_fail_idle;
39728+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
39729+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
39730+ atomic_long_unchecked_t tfh_stale_on_fault;
39731+ atomic_long_unchecked_t mmu_invalidate_range;
39732+ atomic_long_unchecked_t mmu_invalidate_page;
39733+ atomic_long_unchecked_t flush_tlb;
39734+ atomic_long_unchecked_t flush_tlb_gru;
39735+ atomic_long_unchecked_t flush_tlb_gru_tgh;
39736+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
39737
39738- atomic_long_t copy_gpa;
39739- atomic_long_t read_gpa;
39740+ atomic_long_unchecked_t copy_gpa;
39741+ atomic_long_unchecked_t read_gpa;
39742
39743- atomic_long_t mesq_receive;
39744- atomic_long_t mesq_receive_none;
39745- atomic_long_t mesq_send;
39746- atomic_long_t mesq_send_failed;
39747- atomic_long_t mesq_noop;
39748- atomic_long_t mesq_send_unexpected_error;
39749- atomic_long_t mesq_send_lb_overflow;
39750- atomic_long_t mesq_send_qlimit_reached;
39751- atomic_long_t mesq_send_amo_nacked;
39752- atomic_long_t mesq_send_put_nacked;
39753- atomic_long_t mesq_page_overflow;
39754- atomic_long_t mesq_qf_locked;
39755- atomic_long_t mesq_qf_noop_not_full;
39756- atomic_long_t mesq_qf_switch_head_failed;
39757- atomic_long_t mesq_qf_unexpected_error;
39758- atomic_long_t mesq_noop_unexpected_error;
39759- atomic_long_t mesq_noop_lb_overflow;
39760- atomic_long_t mesq_noop_qlimit_reached;
39761- atomic_long_t mesq_noop_amo_nacked;
39762- atomic_long_t mesq_noop_put_nacked;
39763- atomic_long_t mesq_noop_page_overflow;
39764+ atomic_long_unchecked_t mesq_receive;
39765+ atomic_long_unchecked_t mesq_receive_none;
39766+ atomic_long_unchecked_t mesq_send;
39767+ atomic_long_unchecked_t mesq_send_failed;
39768+ atomic_long_unchecked_t mesq_noop;
39769+ atomic_long_unchecked_t mesq_send_unexpected_error;
39770+ atomic_long_unchecked_t mesq_send_lb_overflow;
39771+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39772+ atomic_long_unchecked_t mesq_send_amo_nacked;
39773+ atomic_long_unchecked_t mesq_send_put_nacked;
39774+ atomic_long_unchecked_t mesq_page_overflow;
39775+ atomic_long_unchecked_t mesq_qf_locked;
39776+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39777+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39778+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39779+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39780+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39781+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39782+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39783+ atomic_long_unchecked_t mesq_noop_put_nacked;
39784+ atomic_long_unchecked_t mesq_noop_page_overflow;
39785
39786 };
39787
39788@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39789 tghop_invalidate, mcsop_last};
39790
39791 struct mcs_op_statistic {
39792- atomic_long_t count;
39793- atomic_long_t total;
39794+ atomic_long_unchecked_t count;
39795+ atomic_long_unchecked_t total;
39796 unsigned long max;
39797 };
39798
39799@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39800
39801 #define STAT(id) do { \
39802 if (gru_options & OPT_STATS) \
39803- atomic_long_inc(&gru_stats.id); \
39804+ atomic_long_inc_unchecked(&gru_stats.id); \
39805 } while (0)
39806
39807 #ifdef CONFIG_SGI_GRU_DEBUG
39808diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39809index c862cd4..0d176fe 100644
39810--- a/drivers/misc/sgi-xp/xp.h
39811+++ b/drivers/misc/sgi-xp/xp.h
39812@@ -288,7 +288,7 @@ struct xpc_interface {
39813 xpc_notify_func, void *);
39814 void (*received) (short, int, void *);
39815 enum xp_retval (*partid_to_nasids) (short, void *);
39816-};
39817+} __no_const;
39818
39819 extern struct xpc_interface xpc_interface;
39820
39821diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39822index b94d5f7..7f494c5 100644
39823--- a/drivers/misc/sgi-xp/xpc.h
39824+++ b/drivers/misc/sgi-xp/xpc.h
39825@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39826 void (*received_payload) (struct xpc_channel *, void *);
39827 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39828 };
39829+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39830
39831 /* struct xpc_partition act_state values (for XPC HB) */
39832
39833@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39834 /* found in xpc_main.c */
39835 extern struct device *xpc_part;
39836 extern struct device *xpc_chan;
39837-extern struct xpc_arch_operations xpc_arch_ops;
39838+extern xpc_arch_operations_no_const xpc_arch_ops;
39839 extern int xpc_disengage_timelimit;
39840 extern int xpc_disengage_timedout;
39841 extern int xpc_activate_IRQ_rcvd;
39842diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39843index d971817..33bdca5 100644
39844--- a/drivers/misc/sgi-xp/xpc_main.c
39845+++ b/drivers/misc/sgi-xp/xpc_main.c
39846@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39847 .notifier_call = xpc_system_die,
39848 };
39849
39850-struct xpc_arch_operations xpc_arch_ops;
39851+xpc_arch_operations_no_const xpc_arch_ops;
39852
39853 /*
39854 * Timer function to enforce the timelimit on the partition disengage.
39855@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39856
39857 if (((die_args->trapnr == X86_TRAP_MF) ||
39858 (die_args->trapnr == X86_TRAP_XF)) &&
39859- !user_mode_vm(die_args->regs))
39860+ !user_mode(die_args->regs))
39861 xpc_die_deactivate();
39862
39863 break;
39864diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39865index 49f04bc..65660c2 100644
39866--- a/drivers/mmc/core/mmc_ops.c
39867+++ b/drivers/mmc/core/mmc_ops.c
39868@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39869 void *data_buf;
39870 int is_on_stack;
39871
39872- is_on_stack = object_is_on_stack(buf);
39873+ is_on_stack = object_starts_on_stack(buf);
39874 if (is_on_stack) {
39875 /*
39876 * dma onto stack is unsafe/nonportable, but callers to this
39877diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39878index 0b74189..818358f 100644
39879--- a/drivers/mmc/host/dw_mmc.h
39880+++ b/drivers/mmc/host/dw_mmc.h
39881@@ -202,5 +202,5 @@ struct dw_mci_drv_data {
39882 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
39883 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
39884 int (*parse_dt)(struct dw_mci *host);
39885-};
39886+} __do_const;
39887 #endif /* _DW_MMC_H_ */
39888diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39889index c6f6246..60760a8 100644
39890--- a/drivers/mmc/host/sdhci-s3c.c
39891+++ b/drivers/mmc/host/sdhci-s3c.c
39892@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39893 * we can use overriding functions instead of default.
39894 */
39895 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39896- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39897- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39898- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39899+ pax_open_kernel();
39900+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39901+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39902+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39903+ pax_close_kernel();
39904 }
39905
39906 /* It supports additional host capabilities if needed */
39907diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39908index 0c8bb6b..6f35deb 100644
39909--- a/drivers/mtd/nand/denali.c
39910+++ b/drivers/mtd/nand/denali.c
39911@@ -24,6 +24,7 @@
39912 #include <linux/slab.h>
39913 #include <linux/mtd/mtd.h>
39914 #include <linux/module.h>
39915+#include <linux/slab.h>
39916
39917 #include "denali.h"
39918
39919diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39920index 51b9d6a..52af9a7 100644
39921--- a/drivers/mtd/nftlmount.c
39922+++ b/drivers/mtd/nftlmount.c
39923@@ -24,6 +24,7 @@
39924 #include <asm/errno.h>
39925 #include <linux/delay.h>
39926 #include <linux/slab.h>
39927+#include <linux/sched.h>
39928 #include <linux/mtd/mtd.h>
39929 #include <linux/mtd/nand.h>
39930 #include <linux/mtd/nftl.h>
39931diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39932index f9d5615..99dd95f 100644
39933--- a/drivers/mtd/sm_ftl.c
39934+++ b/drivers/mtd/sm_ftl.c
39935@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39936 #define SM_CIS_VENDOR_OFFSET 0x59
39937 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39938 {
39939- struct attribute_group *attr_group;
39940+ attribute_group_no_const *attr_group;
39941 struct attribute **attributes;
39942 struct sm_sysfs_attribute *vendor_attribute;
39943
39944diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39945index f975696..4597e21 100644
39946--- a/drivers/net/bonding/bond_main.c
39947+++ b/drivers/net/bonding/bond_main.c
39948@@ -4870,7 +4870,7 @@ static unsigned int bond_get_num_tx_queues(void)
39949 return tx_queues;
39950 }
39951
39952-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39953+static struct rtnl_link_ops bond_link_ops = {
39954 .kind = "bond",
39955 .priv_size = sizeof(struct bonding),
39956 .setup = bond_setup,
39957@@ -4995,8 +4995,8 @@ static void __exit bonding_exit(void)
39958
39959 bond_destroy_debugfs();
39960
39961- rtnl_link_unregister(&bond_link_ops);
39962 unregister_pernet_subsys(&bond_net_ops);
39963+ rtnl_link_unregister(&bond_link_ops);
39964
39965 #ifdef CONFIG_NET_POLL_CONTROLLER
39966 /*
39967diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39968index e1d2643..7f4133b 100644
39969--- a/drivers/net/ethernet/8390/ax88796.c
39970+++ b/drivers/net/ethernet/8390/ax88796.c
39971@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39972 if (ax->plat->reg_offsets)
39973 ei_local->reg_offset = ax->plat->reg_offsets;
39974 else {
39975+ resource_size_t _mem_size = mem_size;
39976+ do_div(_mem_size, 0x18);
39977 ei_local->reg_offset = ax->reg_offsets;
39978 for (ret = 0; ret < 0x18; ret++)
39979- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39980+ ax->reg_offsets[ret] = _mem_size * ret;
39981 }
39982
39983 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39984diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39985index 151675d..0139a9d 100644
39986--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39987+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39988@@ -1112,7 +1112,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39989 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39990 {
39991 /* RX_MODE controlling object */
39992- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39993+ bnx2x_init_rx_mode_obj(bp);
39994
39995 /* multicast configuration controlling object */
39996 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39997diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
39998index ce1a916..10b52b0 100644
39999--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
40000+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
40001@@ -960,6 +960,9 @@ static int bnx2x_set_dump(struct net_device *dev, struct ethtool_dump *val)
40002 struct bnx2x *bp = netdev_priv(dev);
40003
40004 /* Use the ethtool_dump "flag" field as the dump preset index */
40005+ if (val->flag < 1 || val->flag > DUMP_MAX_PRESETS)
40006+ return -EINVAL;
40007+
40008 bp->dump_preset_idx = val->flag;
40009 return 0;
40010 }
40011@@ -986,8 +989,6 @@ static int bnx2x_get_dump_data(struct net_device *dev,
40012 struct bnx2x *bp = netdev_priv(dev);
40013 struct dump_header dump_hdr = {0};
40014
40015- memset(p, 0, dump->len);
40016-
40017 /* Disable parity attentions as long as following dump may
40018 * cause false alarms by reading never written registers. We
40019 * will re-enable parity attentions right after the dump.
40020diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40021index b4c9dea..2a9927f 100644
40022--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40023+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40024@@ -11497,6 +11497,8 @@ static int bnx2x_init_bp(struct bnx2x *bp)
40025 bp->min_msix_vec_cnt = 2;
40026 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
40027
40028+ bp->dump_preset_idx = 1;
40029+
40030 return rc;
40031 }
40032
40033diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40034index 32a9609..0b1c53a 100644
40035--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40036+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40037@@ -2387,15 +2387,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
40038 return rc;
40039 }
40040
40041-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
40042- struct bnx2x_rx_mode_obj *o)
40043+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
40044 {
40045 if (CHIP_IS_E1x(bp)) {
40046- o->wait_comp = bnx2x_empty_rx_mode_wait;
40047- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
40048+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
40049+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
40050 } else {
40051- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
40052- o->config_rx_mode = bnx2x_set_rx_mode_e2;
40053+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
40054+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
40055 }
40056 }
40057
40058diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40059index 43c00bc..dd1d03d 100644
40060--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40061+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40062@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
40063
40064 /********************* RX MODE ****************/
40065
40066-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
40067- struct bnx2x_rx_mode_obj *o);
40068+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
40069
40070 /**
40071 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
40072diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
40073index ff6e30e..87e8452 100644
40074--- a/drivers/net/ethernet/broadcom/tg3.h
40075+++ b/drivers/net/ethernet/broadcom/tg3.h
40076@@ -147,6 +147,7 @@
40077 #define CHIPREV_ID_5750_A0 0x4000
40078 #define CHIPREV_ID_5750_A1 0x4001
40079 #define CHIPREV_ID_5750_A3 0x4003
40080+#define CHIPREV_ID_5750_C1 0x4201
40081 #define CHIPREV_ID_5750_C2 0x4202
40082 #define CHIPREV_ID_5752_A0_HW 0x5000
40083 #define CHIPREV_ID_5752_A0 0x6000
40084diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
40085index 71497e8..b650951 100644
40086--- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
40087+++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
40088@@ -3037,7 +3037,9 @@ static void t3_io_resume(struct pci_dev *pdev)
40089 CH_ALERT(adapter, "adapter recovering, PEX ERR 0x%x\n",
40090 t3_read_reg(adapter, A_PCIE_PEX_ERR));
40091
40092+ rtnl_lock();
40093 t3_resume_ports(adapter);
40094+ rtnl_unlock();
40095 }
40096
40097 static const struct pci_error_handlers t3_err_handler = {
40098diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40099index 8cffcdf..aadf043 100644
40100--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40101+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40102@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
40103 */
40104 struct l2t_skb_cb {
40105 arp_failure_handler_func arp_failure_handler;
40106-};
40107+} __no_const;
40108
40109 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
40110
40111diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
40112index 4c83003..2a2a5b9 100644
40113--- a/drivers/net/ethernet/dec/tulip/de4x5.c
40114+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
40115@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40116 for (i=0; i<ETH_ALEN; i++) {
40117 tmp.addr[i] = dev->dev_addr[i];
40118 }
40119- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
40120+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
40121 break;
40122
40123 case DE4X5_SET_HWADDR: /* Set the hardware address */
40124@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40125 spin_lock_irqsave(&lp->lock, flags);
40126 memcpy(&statbuf, &lp->pktStats, ioc->len);
40127 spin_unlock_irqrestore(&lp->lock, flags);
40128- if (copy_to_user(ioc->data, &statbuf, ioc->len))
40129+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
40130 return -EFAULT;
40131 break;
40132 }
40133diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
40134index a0b4be5..d8cb082 100644
40135--- a/drivers/net/ethernet/emulex/benet/be_main.c
40136+++ b/drivers/net/ethernet/emulex/benet/be_main.c
40137@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
40138
40139 if (wrapped)
40140 newacc += 65536;
40141- ACCESS_ONCE(*acc) = newacc;
40142+ ACCESS_ONCE_RW(*acc) = newacc;
40143 }
40144
40145 void populate_erx_stats(struct be_adapter *adapter,
40146diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
40147index 21b85fb..b49e5fc 100644
40148--- a/drivers/net/ethernet/faraday/ftgmac100.c
40149+++ b/drivers/net/ethernet/faraday/ftgmac100.c
40150@@ -31,6 +31,8 @@
40151 #include <linux/netdevice.h>
40152 #include <linux/phy.h>
40153 #include <linux/platform_device.h>
40154+#include <linux/interrupt.h>
40155+#include <linux/irqreturn.h>
40156 #include <net/ip.h>
40157
40158 #include "ftgmac100.h"
40159diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
40160index a6eda8d..935d273 100644
40161--- a/drivers/net/ethernet/faraday/ftmac100.c
40162+++ b/drivers/net/ethernet/faraday/ftmac100.c
40163@@ -31,6 +31,8 @@
40164 #include <linux/module.h>
40165 #include <linux/netdevice.h>
40166 #include <linux/platform_device.h>
40167+#include <linux/interrupt.h>
40168+#include <linux/irqreturn.h>
40169
40170 #include "ftmac100.h"
40171
40172diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40173index 331987d..3be1135 100644
40174--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40175+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40176@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
40177 }
40178
40179 /* update the base incval used to calculate frequency adjustment */
40180- ACCESS_ONCE(adapter->base_incval) = incval;
40181+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
40182 smp_mb();
40183
40184 /* need lock to prevent incorrect read while modifying cyclecounter */
40185diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40186index fbe5363..266b4e3 100644
40187--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
40188+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40189@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40190 struct __vxge_hw_fifo *fifo;
40191 struct vxge_hw_fifo_config *config;
40192 u32 txdl_size, txdl_per_memblock;
40193- struct vxge_hw_mempool_cbs fifo_mp_callback;
40194+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
40195+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
40196+ };
40197+
40198 struct __vxge_hw_virtualpath *vpath;
40199
40200 if ((vp == NULL) || (attr == NULL)) {
40201@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40202 goto exit;
40203 }
40204
40205- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
40206-
40207 fifo->mempool =
40208 __vxge_hw_mempool_create(vpath->hldev,
40209 fifo->config->memblock_size,
40210diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40211index 5e7fb1d..f8d1810 100644
40212--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40213+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40214@@ -1948,7 +1948,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
40215 op_mode = QLC_83XX_DEFAULT_OPMODE;
40216
40217 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
40218- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
40219+ pax_open_kernel();
40220+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
40221+ pax_close_kernel();
40222 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40223 } else {
40224 return -EIO;
40225diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40226index b0c3de9..fc5857e 100644
40227--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40228+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40229@@ -200,15 +200,21 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
40230 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
40231 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
40232 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40233- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
40234+ pax_open_kernel();
40235+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
40236+ pax_close_kernel();
40237 } else if (priv_level == QLCNIC_PRIV_FUNC) {
40238 ahw->op_mode = QLCNIC_PRIV_FUNC;
40239 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
40240- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
40241+ pax_open_kernel();
40242+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
40243+ pax_close_kernel();
40244 } else if (priv_level == QLCNIC_MGMT_FUNC) {
40245 ahw->op_mode = QLCNIC_MGMT_FUNC;
40246 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40247- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
40248+ pax_open_kernel();
40249+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
40250+ pax_close_kernel();
40251 } else {
40252 return -EIO;
40253 }
40254diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
40255index 393f961..d343034 100644
40256--- a/drivers/net/ethernet/realtek/r8169.c
40257+++ b/drivers/net/ethernet/realtek/r8169.c
40258@@ -753,22 +753,22 @@ struct rtl8169_private {
40259 struct mdio_ops {
40260 void (*write)(struct rtl8169_private *, int, int);
40261 int (*read)(struct rtl8169_private *, int);
40262- } mdio_ops;
40263+ } __no_const mdio_ops;
40264
40265 struct pll_power_ops {
40266 void (*down)(struct rtl8169_private *);
40267 void (*up)(struct rtl8169_private *);
40268- } pll_power_ops;
40269+ } __no_const pll_power_ops;
40270
40271 struct jumbo_ops {
40272 void (*enable)(struct rtl8169_private *);
40273 void (*disable)(struct rtl8169_private *);
40274- } jumbo_ops;
40275+ } __no_const jumbo_ops;
40276
40277 struct csi_ops {
40278 void (*write)(struct rtl8169_private *, int, int);
40279 u32 (*read)(struct rtl8169_private *, int);
40280- } csi_ops;
40281+ } __no_const csi_ops;
40282
40283 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
40284 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
40285diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
40286index 9a95abf..36df7f9 100644
40287--- a/drivers/net/ethernet/sfc/ptp.c
40288+++ b/drivers/net/ethernet/sfc/ptp.c
40289@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
40290 (u32)((u64)ptp->start.dma_addr >> 32));
40291
40292 /* Clear flag that signals MC ready */
40293- ACCESS_ONCE(*start) = 0;
40294+ ACCESS_ONCE_RW(*start) = 0;
40295 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
40296 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
40297
40298diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40299index 50617c5..b13724c 100644
40300--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40301+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40302@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
40303
40304 writel(value, ioaddr + MMC_CNTRL);
40305
40306- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40307- MMC_CNTRL, value);
40308+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40309+// MMC_CNTRL, value);
40310 }
40311
40312 /* To mask all all interrupts.*/
40313diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
40314index e6fe0d8..2b7d752 100644
40315--- a/drivers/net/hyperv/hyperv_net.h
40316+++ b/drivers/net/hyperv/hyperv_net.h
40317@@ -101,7 +101,7 @@ struct rndis_device {
40318
40319 enum rndis_device_state state;
40320 bool link_state;
40321- atomic_t new_req_id;
40322+ atomic_unchecked_t new_req_id;
40323
40324 spinlock_t request_lock;
40325 struct list_head req_list;
40326diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
40327index 0775f0a..d4fb316 100644
40328--- a/drivers/net/hyperv/rndis_filter.c
40329+++ b/drivers/net/hyperv/rndis_filter.c
40330@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
40331 * template
40332 */
40333 set = &rndis_msg->msg.set_req;
40334- set->req_id = atomic_inc_return(&dev->new_req_id);
40335+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40336
40337 /* Add to the request list */
40338 spin_lock_irqsave(&dev->request_lock, flags);
40339@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
40340
40341 /* Setup the rndis set */
40342 halt = &request->request_msg.msg.halt_req;
40343- halt->req_id = atomic_inc_return(&dev->new_req_id);
40344+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40345
40346 /* Ignore return since this msg is optional. */
40347 rndis_filter_send_request(dev, request);
40348diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
40349index bf0d55e..82bcfbd1 100644
40350--- a/drivers/net/ieee802154/fakehard.c
40351+++ b/drivers/net/ieee802154/fakehard.c
40352@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
40353 phy->transmit_power = 0xbf;
40354
40355 dev->netdev_ops = &fake_ops;
40356- dev->ml_priv = &fake_mlme;
40357+ dev->ml_priv = (void *)&fake_mlme;
40358
40359 priv = netdev_priv(dev);
40360 priv->phy = phy;
40361diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
40362index 6e91931..2b0ebe7 100644
40363--- a/drivers/net/macvlan.c
40364+++ b/drivers/net/macvlan.c
40365@@ -905,13 +905,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
40366 int macvlan_link_register(struct rtnl_link_ops *ops)
40367 {
40368 /* common fields */
40369- ops->priv_size = sizeof(struct macvlan_dev);
40370- ops->validate = macvlan_validate;
40371- ops->maxtype = IFLA_MACVLAN_MAX;
40372- ops->policy = macvlan_policy;
40373- ops->changelink = macvlan_changelink;
40374- ops->get_size = macvlan_get_size;
40375- ops->fill_info = macvlan_fill_info;
40376+ pax_open_kernel();
40377+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
40378+ *(void **)&ops->validate = macvlan_validate;
40379+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
40380+ *(const void **)&ops->policy = macvlan_policy;
40381+ *(void **)&ops->changelink = macvlan_changelink;
40382+ *(void **)&ops->get_size = macvlan_get_size;
40383+ *(void **)&ops->fill_info = macvlan_fill_info;
40384+ pax_close_kernel();
40385
40386 return rtnl_link_register(ops);
40387 };
40388@@ -967,7 +969,7 @@ static int macvlan_device_event(struct notifier_block *unused,
40389 return NOTIFY_DONE;
40390 }
40391
40392-static struct notifier_block macvlan_notifier_block __read_mostly = {
40393+static struct notifier_block macvlan_notifier_block = {
40394 .notifier_call = macvlan_device_event,
40395 };
40396
40397diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
40398index b6dd6a7..5c38a02 100644
40399--- a/drivers/net/macvtap.c
40400+++ b/drivers/net/macvtap.c
40401@@ -1094,7 +1094,7 @@ static int macvtap_device_event(struct notifier_block *unused,
40402 return NOTIFY_DONE;
40403 }
40404
40405-static struct notifier_block macvtap_notifier_block __read_mostly = {
40406+static struct notifier_block macvtap_notifier_block = {
40407 .notifier_call = macvtap_device_event,
40408 };
40409
40410diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
40411index daec9b0..6428fcb 100644
40412--- a/drivers/net/phy/mdio-bitbang.c
40413+++ b/drivers/net/phy/mdio-bitbang.c
40414@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
40415 struct mdiobb_ctrl *ctrl = bus->priv;
40416
40417 module_put(ctrl->ops->owner);
40418+ mdiobus_unregister(bus);
40419 mdiobus_free(bus);
40420 }
40421 EXPORT_SYMBOL(free_mdio_bitbang);
40422diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
40423index 72ff14b..11d442d 100644
40424--- a/drivers/net/ppp/ppp_generic.c
40425+++ b/drivers/net/ppp/ppp_generic.c
40426@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40427 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
40428 struct ppp_stats stats;
40429 struct ppp_comp_stats cstats;
40430- char *vers;
40431
40432 switch (cmd) {
40433 case SIOCGPPPSTATS:
40434@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40435 break;
40436
40437 case SIOCGPPPVER:
40438- vers = PPP_VERSION;
40439- if (copy_to_user(addr, vers, strlen(vers) + 1))
40440+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
40441 break;
40442 err = 0;
40443 break;
40444diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
40445index 1252d9c..80e660b 100644
40446--- a/drivers/net/slip/slhc.c
40447+++ b/drivers/net/slip/slhc.c
40448@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
40449 register struct tcphdr *thp;
40450 register struct iphdr *ip;
40451 register struct cstate *cs;
40452- int len, hdrlen;
40453+ long len, hdrlen;
40454 unsigned char *cp = icp;
40455
40456 /* We've got a compressed packet; read the change byte */
40457diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
40458index b305105..8ead6df 100644
40459--- a/drivers/net/team/team.c
40460+++ b/drivers/net/team/team.c
40461@@ -2682,7 +2682,7 @@ static int team_device_event(struct notifier_block *unused,
40462 return NOTIFY_DONE;
40463 }
40464
40465-static struct notifier_block team_notifier_block __read_mostly = {
40466+static struct notifier_block team_notifier_block = {
40467 .notifier_call = team_device_event,
40468 };
40469
40470diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40471index 9c61f87..213609e 100644
40472--- a/drivers/net/tun.c
40473+++ b/drivers/net/tun.c
40474@@ -1852,7 +1852,7 @@ unlock:
40475 }
40476
40477 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40478- unsigned long arg, int ifreq_len)
40479+ unsigned long arg, size_t ifreq_len)
40480 {
40481 struct tun_file *tfile = file->private_data;
40482 struct tun_struct *tun;
40483@@ -1864,6 +1864,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40484 int vnet_hdr_sz;
40485 int ret;
40486
40487+ if (ifreq_len > sizeof ifr)
40488+ return -EFAULT;
40489+
40490 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40491 if (copy_from_user(&ifr, argp, ifreq_len))
40492 return -EFAULT;
40493diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40494index cba1d46..f703766 100644
40495--- a/drivers/net/usb/hso.c
40496+++ b/drivers/net/usb/hso.c
40497@@ -71,7 +71,7 @@
40498 #include <asm/byteorder.h>
40499 #include <linux/serial_core.h>
40500 #include <linux/serial.h>
40501-
40502+#include <asm/local.h>
40503
40504 #define MOD_AUTHOR "Option Wireless"
40505 #define MOD_DESCRIPTION "USB High Speed Option driver"
40506@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40507 struct urb *urb;
40508
40509 urb = serial->rx_urb[0];
40510- if (serial->port.count > 0) {
40511+ if (atomic_read(&serial->port.count) > 0) {
40512 count = put_rxbuf_data(urb, serial);
40513 if (count == -1)
40514 return;
40515@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40516 DUMP1(urb->transfer_buffer, urb->actual_length);
40517
40518 /* Anyone listening? */
40519- if (serial->port.count == 0)
40520+ if (atomic_read(&serial->port.count) == 0)
40521 return;
40522
40523 if (status == 0) {
40524@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40525 tty_port_tty_set(&serial->port, tty);
40526
40527 /* check for port already opened, if not set the termios */
40528- serial->port.count++;
40529- if (serial->port.count == 1) {
40530+ if (atomic_inc_return(&serial->port.count) == 1) {
40531 serial->rx_state = RX_IDLE;
40532 /* Force default termio settings */
40533 _hso_serial_set_termios(tty, NULL);
40534@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40535 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40536 if (result) {
40537 hso_stop_serial_device(serial->parent);
40538- serial->port.count--;
40539+ atomic_dec(&serial->port.count);
40540 kref_put(&serial->parent->ref, hso_serial_ref_free);
40541 }
40542 } else {
40543@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40544
40545 /* reset the rts and dtr */
40546 /* do the actual close */
40547- serial->port.count--;
40548+ atomic_dec(&serial->port.count);
40549
40550- if (serial->port.count <= 0) {
40551- serial->port.count = 0;
40552+ if (atomic_read(&serial->port.count) <= 0) {
40553+ atomic_set(&serial->port.count, 0);
40554 tty_port_tty_set(&serial->port, NULL);
40555 if (!usb_gone)
40556 hso_stop_serial_device(serial->parent);
40557@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40558
40559 /* the actual setup */
40560 spin_lock_irqsave(&serial->serial_lock, flags);
40561- if (serial->port.count)
40562+ if (atomic_read(&serial->port.count))
40563 _hso_serial_set_termios(tty, old);
40564 else
40565 tty->termios = *old;
40566@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
40567 D1("Pending read interrupt on port %d\n", i);
40568 spin_lock(&serial->serial_lock);
40569 if (serial->rx_state == RX_IDLE &&
40570- serial->port.count > 0) {
40571+ atomic_read(&serial->port.count) > 0) {
40572 /* Setup and send a ctrl req read on
40573 * port i */
40574 if (!serial->rx_urb_filled[0]) {
40575@@ -3057,7 +3056,7 @@ static int hso_resume(struct usb_interface *iface)
40576 /* Start all serial ports */
40577 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
40578 if (serial_table[i] && (serial_table[i]->interface == iface)) {
40579- if (dev2ser(serial_table[i])->port.count) {
40580+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
40581 result =
40582 hso_start_serial_device(serial_table[i], GFP_NOIO);
40583 hso_kick_transmit(dev2ser(serial_table[i]));
40584diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
40585index 57325f3..36b181f 100644
40586--- a/drivers/net/vxlan.c
40587+++ b/drivers/net/vxlan.c
40588@@ -1579,7 +1579,7 @@ nla_put_failure:
40589 return -EMSGSIZE;
40590 }
40591
40592-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
40593+static struct rtnl_link_ops vxlan_link_ops = {
40594 .kind = "vxlan",
40595 .maxtype = IFLA_VXLAN_MAX,
40596 .policy = vxlan_policy,
40597diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
40598index 34c8a33..3261fdc 100644
40599--- a/drivers/net/wireless/at76c50x-usb.c
40600+++ b/drivers/net/wireless/at76c50x-usb.c
40601@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
40602 }
40603
40604 /* Convert timeout from the DFU status to jiffies */
40605-static inline unsigned long at76_get_timeout(struct dfu_status *s)
40606+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
40607 {
40608 return msecs_to_jiffies((s->poll_timeout[2] << 16)
40609 | (s->poll_timeout[1] << 8)
40610diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40611index 8d78253..bebbb68 100644
40612--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40613+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40614@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40615 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
40616 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
40617
40618- ACCESS_ONCE(ads->ds_link) = i->link;
40619- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
40620+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
40621+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
40622
40623 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
40624 ctl6 = SM(i->keytype, AR_EncrType);
40625@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40626
40627 if ((i->is_first || i->is_last) &&
40628 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
40629- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
40630+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
40631 | set11nTries(i->rates, 1)
40632 | set11nTries(i->rates, 2)
40633 | set11nTries(i->rates, 3)
40634 | (i->dur_update ? AR_DurUpdateEna : 0)
40635 | SM(0, AR_BurstDur);
40636
40637- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
40638+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
40639 | set11nRate(i->rates, 1)
40640 | set11nRate(i->rates, 2)
40641 | set11nRate(i->rates, 3);
40642 } else {
40643- ACCESS_ONCE(ads->ds_ctl2) = 0;
40644- ACCESS_ONCE(ads->ds_ctl3) = 0;
40645+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
40646+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
40647 }
40648
40649 if (!i->is_first) {
40650- ACCESS_ONCE(ads->ds_ctl0) = 0;
40651- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40652- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40653+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
40654+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40655+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40656 return;
40657 }
40658
40659@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40660 break;
40661 }
40662
40663- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40664+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40665 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40666 | SM(i->txpower, AR_XmitPower)
40667 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40668@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40669 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
40670 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
40671
40672- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40673- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40674+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40675+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40676
40677 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
40678 return;
40679
40680- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40681+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40682 | set11nPktDurRTSCTS(i->rates, 1);
40683
40684- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40685+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40686 | set11nPktDurRTSCTS(i->rates, 3);
40687
40688- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40689+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40690 | set11nRateFlags(i->rates, 1)
40691 | set11nRateFlags(i->rates, 2)
40692 | set11nRateFlags(i->rates, 3)
40693diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40694index 301bf72..3f5654f 100644
40695--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40696+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40697@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40698 (i->qcu << AR_TxQcuNum_S) | desc_len;
40699
40700 checksum += val;
40701- ACCESS_ONCE(ads->info) = val;
40702+ ACCESS_ONCE_RW(ads->info) = val;
40703
40704 checksum += i->link;
40705- ACCESS_ONCE(ads->link) = i->link;
40706+ ACCESS_ONCE_RW(ads->link) = i->link;
40707
40708 checksum += i->buf_addr[0];
40709- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
40710+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
40711 checksum += i->buf_addr[1];
40712- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
40713+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
40714 checksum += i->buf_addr[2];
40715- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
40716+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
40717 checksum += i->buf_addr[3];
40718- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
40719+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
40720
40721 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
40722- ACCESS_ONCE(ads->ctl3) = val;
40723+ ACCESS_ONCE_RW(ads->ctl3) = val;
40724 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
40725- ACCESS_ONCE(ads->ctl5) = val;
40726+ ACCESS_ONCE_RW(ads->ctl5) = val;
40727 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
40728- ACCESS_ONCE(ads->ctl7) = val;
40729+ ACCESS_ONCE_RW(ads->ctl7) = val;
40730 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
40731- ACCESS_ONCE(ads->ctl9) = val;
40732+ ACCESS_ONCE_RW(ads->ctl9) = val;
40733
40734 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
40735- ACCESS_ONCE(ads->ctl10) = checksum;
40736+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
40737
40738 if (i->is_first || i->is_last) {
40739- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
40740+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
40741 | set11nTries(i->rates, 1)
40742 | set11nTries(i->rates, 2)
40743 | set11nTries(i->rates, 3)
40744 | (i->dur_update ? AR_DurUpdateEna : 0)
40745 | SM(0, AR_BurstDur);
40746
40747- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
40748+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
40749 | set11nRate(i->rates, 1)
40750 | set11nRate(i->rates, 2)
40751 | set11nRate(i->rates, 3);
40752 } else {
40753- ACCESS_ONCE(ads->ctl13) = 0;
40754- ACCESS_ONCE(ads->ctl14) = 0;
40755+ ACCESS_ONCE_RW(ads->ctl13) = 0;
40756+ ACCESS_ONCE_RW(ads->ctl14) = 0;
40757 }
40758
40759 ads->ctl20 = 0;
40760@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40761
40762 ctl17 = SM(i->keytype, AR_EncrType);
40763 if (!i->is_first) {
40764- ACCESS_ONCE(ads->ctl11) = 0;
40765- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40766- ACCESS_ONCE(ads->ctl15) = 0;
40767- ACCESS_ONCE(ads->ctl16) = 0;
40768- ACCESS_ONCE(ads->ctl17) = ctl17;
40769- ACCESS_ONCE(ads->ctl18) = 0;
40770- ACCESS_ONCE(ads->ctl19) = 0;
40771+ ACCESS_ONCE_RW(ads->ctl11) = 0;
40772+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40773+ ACCESS_ONCE_RW(ads->ctl15) = 0;
40774+ ACCESS_ONCE_RW(ads->ctl16) = 0;
40775+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40776+ ACCESS_ONCE_RW(ads->ctl18) = 0;
40777+ ACCESS_ONCE_RW(ads->ctl19) = 0;
40778 return;
40779 }
40780
40781- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40782+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40783 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40784 | SM(i->txpower, AR_XmitPower)
40785 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40786@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40787 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
40788 ctl12 |= SM(val, AR_PAPRDChainMask);
40789
40790- ACCESS_ONCE(ads->ctl12) = ctl12;
40791- ACCESS_ONCE(ads->ctl17) = ctl17;
40792+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
40793+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40794
40795- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40796+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40797 | set11nPktDurRTSCTS(i->rates, 1);
40798
40799- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40800+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40801 | set11nPktDurRTSCTS(i->rates, 3);
40802
40803- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
40804+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
40805 | set11nRateFlags(i->rates, 1)
40806 | set11nRateFlags(i->rates, 2)
40807 | set11nRateFlags(i->rates, 3)
40808 | SM(i->rtscts_rate, AR_RTSCTSRate);
40809
40810- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
40811+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
40812 }
40813
40814 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
40815diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
40816index ae30343..a117806 100644
40817--- a/drivers/net/wireless/ath/ath9k/hw.h
40818+++ b/drivers/net/wireless/ath/ath9k/hw.h
40819@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
40820
40821 /* ANI */
40822 void (*ani_cache_ini_regs)(struct ath_hw *ah);
40823-};
40824+} __no_const;
40825
40826 /**
40827 * struct ath_spec_scan - parameters for Atheros spectral scan
40828@@ -721,7 +721,7 @@ struct ath_hw_ops {
40829 struct ath_spec_scan *param);
40830 void (*spectral_scan_trigger)(struct ath_hw *ah);
40831 void (*spectral_scan_wait)(struct ath_hw *ah);
40832-};
40833+} __no_const;
40834
40835 struct ath_nf_limits {
40836 s16 max;
40837diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40838index b37a582..680835d 100644
40839--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40840+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40841@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40842 */
40843 if (il3945_mod_params.disable_hw_scan) {
40844 D_INFO("Disabling hw_scan\n");
40845- il3945_mac_ops.hw_scan = NULL;
40846+ pax_open_kernel();
40847+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40848+ pax_close_kernel();
40849 }
40850
40851 D_INFO("*** LOAD DRIVER ***\n");
40852diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40853index d532948..a1cb592 100644
40854--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40855+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40856@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40857 {
40858 struct iwl_priv *priv = file->private_data;
40859 char buf[64];
40860- int buf_size;
40861+ size_t buf_size;
40862 u32 offset, len;
40863
40864 memset(buf, 0, sizeof(buf));
40865@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40866 struct iwl_priv *priv = file->private_data;
40867
40868 char buf[8];
40869- int buf_size;
40870+ size_t buf_size;
40871 u32 reset_flag;
40872
40873 memset(buf, 0, sizeof(buf));
40874@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40875 {
40876 struct iwl_priv *priv = file->private_data;
40877 char buf[8];
40878- int buf_size;
40879+ size_t buf_size;
40880 int ht40;
40881
40882 memset(buf, 0, sizeof(buf));
40883@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40884 {
40885 struct iwl_priv *priv = file->private_data;
40886 char buf[8];
40887- int buf_size;
40888+ size_t buf_size;
40889 int value;
40890
40891 memset(buf, 0, sizeof(buf));
40892@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40893 {
40894 struct iwl_priv *priv = file->private_data;
40895 char buf[8];
40896- int buf_size;
40897+ size_t buf_size;
40898 int clear;
40899
40900 memset(buf, 0, sizeof(buf));
40901@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40902 {
40903 struct iwl_priv *priv = file->private_data;
40904 char buf[8];
40905- int buf_size;
40906+ size_t buf_size;
40907 int trace;
40908
40909 memset(buf, 0, sizeof(buf));
40910@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40911 {
40912 struct iwl_priv *priv = file->private_data;
40913 char buf[8];
40914- int buf_size;
40915+ size_t buf_size;
40916 int missed;
40917
40918 memset(buf, 0, sizeof(buf));
40919@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40920
40921 struct iwl_priv *priv = file->private_data;
40922 char buf[8];
40923- int buf_size;
40924+ size_t buf_size;
40925 int plcp;
40926
40927 memset(buf, 0, sizeof(buf));
40928@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40929
40930 struct iwl_priv *priv = file->private_data;
40931 char buf[8];
40932- int buf_size;
40933+ size_t buf_size;
40934 int flush;
40935
40936 memset(buf, 0, sizeof(buf));
40937@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40938
40939 struct iwl_priv *priv = file->private_data;
40940 char buf[8];
40941- int buf_size;
40942+ size_t buf_size;
40943 int rts;
40944
40945 if (!priv->cfg->ht_params)
40946@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40947 {
40948 struct iwl_priv *priv = file->private_data;
40949 char buf[8];
40950- int buf_size;
40951+ size_t buf_size;
40952
40953 memset(buf, 0, sizeof(buf));
40954 buf_size = min(count, sizeof(buf) - 1);
40955@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40956 struct iwl_priv *priv = file->private_data;
40957 u32 event_log_flag;
40958 char buf[8];
40959- int buf_size;
40960+ size_t buf_size;
40961
40962 /* check that the interface is up */
40963 if (!iwl_is_ready(priv))
40964@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40965 struct iwl_priv *priv = file->private_data;
40966 char buf[8];
40967 u32 calib_disabled;
40968- int buf_size;
40969+ size_t buf_size;
40970
40971 memset(buf, 0, sizeof(buf));
40972 buf_size = min(count, sizeof(buf) - 1);
40973diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40974index 50ba0a4..29424e7 100644
40975--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40976+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40977@@ -1329,7 +1329,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40978 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40979
40980 char buf[8];
40981- int buf_size;
40982+ size_t buf_size;
40983 u32 reset_flag;
40984
40985 memset(buf, 0, sizeof(buf));
40986@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40987 {
40988 struct iwl_trans *trans = file->private_data;
40989 char buf[8];
40990- int buf_size;
40991+ size_t buf_size;
40992 int csr;
40993
40994 memset(buf, 0, sizeof(buf));
40995diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40996index cb34c78..9fec0dc 100644
40997--- a/drivers/net/wireless/mac80211_hwsim.c
40998+++ b/drivers/net/wireless/mac80211_hwsim.c
40999@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
41000
41001 if (channels > 1) {
41002 hwsim_if_comb.num_different_channels = channels;
41003- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
41004- mac80211_hwsim_ops.cancel_hw_scan =
41005- mac80211_hwsim_cancel_hw_scan;
41006- mac80211_hwsim_ops.sw_scan_start = NULL;
41007- mac80211_hwsim_ops.sw_scan_complete = NULL;
41008- mac80211_hwsim_ops.remain_on_channel =
41009- mac80211_hwsim_roc;
41010- mac80211_hwsim_ops.cancel_remain_on_channel =
41011- mac80211_hwsim_croc;
41012- mac80211_hwsim_ops.add_chanctx =
41013- mac80211_hwsim_add_chanctx;
41014- mac80211_hwsim_ops.remove_chanctx =
41015- mac80211_hwsim_remove_chanctx;
41016- mac80211_hwsim_ops.change_chanctx =
41017- mac80211_hwsim_change_chanctx;
41018- mac80211_hwsim_ops.assign_vif_chanctx =
41019- mac80211_hwsim_assign_vif_chanctx;
41020- mac80211_hwsim_ops.unassign_vif_chanctx =
41021- mac80211_hwsim_unassign_vif_chanctx;
41022+ pax_open_kernel();
41023+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
41024+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
41025+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
41026+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
41027+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
41028+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
41029+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
41030+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
41031+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
41032+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
41033+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
41034+ pax_close_kernel();
41035 }
41036
41037 spin_lock_init(&hwsim_radio_lock);
41038diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
41039index 8169a85..7fa3b47 100644
41040--- a/drivers/net/wireless/rndis_wlan.c
41041+++ b/drivers/net/wireless/rndis_wlan.c
41042@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
41043
41044 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
41045
41046- if (rts_threshold < 0 || rts_threshold > 2347)
41047+ if (rts_threshold > 2347)
41048 rts_threshold = 2347;
41049
41050 tmp = cpu_to_le32(rts_threshold);
41051diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
41052index 7510723..5ba37f5 100644
41053--- a/drivers/net/wireless/rt2x00/rt2x00.h
41054+++ b/drivers/net/wireless/rt2x00/rt2x00.h
41055@@ -386,7 +386,7 @@ struct rt2x00_intf {
41056 * for hardware which doesn't support hardware
41057 * sequence counting.
41058 */
41059- atomic_t seqno;
41060+ atomic_unchecked_t seqno;
41061 };
41062
41063 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
41064diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
41065index 2c12311..7b77f24 100644
41066--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
41067+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
41068@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
41069 * sequence counter given by mac80211.
41070 */
41071 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
41072- seqno = atomic_add_return(0x10, &intf->seqno);
41073+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
41074 else
41075- seqno = atomic_read(&intf->seqno);
41076+ seqno = atomic_read_unchecked(&intf->seqno);
41077
41078 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
41079 hdr->seq_ctrl |= cpu_to_le16(seqno);
41080diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
41081index e2b3d9c..67a5184 100644
41082--- a/drivers/net/wireless/ti/wl1251/sdio.c
41083+++ b/drivers/net/wireless/ti/wl1251/sdio.c
41084@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
41085
41086 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
41087
41088- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41089- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41090+ pax_open_kernel();
41091+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41092+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41093+ pax_close_kernel();
41094
41095 wl1251_info("using dedicated interrupt line");
41096 } else {
41097- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41098- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41099+ pax_open_kernel();
41100+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41101+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41102+ pax_close_kernel();
41103
41104 wl1251_info("using SDIO interrupt");
41105 }
41106diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
41107index 1c627da..69f7d17 100644
41108--- a/drivers/net/wireless/ti/wl12xx/main.c
41109+++ b/drivers/net/wireless/ti/wl12xx/main.c
41110@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41111 sizeof(wl->conf.mem));
41112
41113 /* read data preparation is only needed by wl127x */
41114- wl->ops->prepare_read = wl127x_prepare_read;
41115+ pax_open_kernel();
41116+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41117+ pax_close_kernel();
41118
41119 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
41120 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
41121@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41122 sizeof(wl->conf.mem));
41123
41124 /* read data preparation is only needed by wl127x */
41125- wl->ops->prepare_read = wl127x_prepare_read;
41126+ pax_open_kernel();
41127+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41128+ pax_close_kernel();
41129
41130 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
41131 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
41132diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
41133index 9fa692d..b31fee0 100644
41134--- a/drivers/net/wireless/ti/wl18xx/main.c
41135+++ b/drivers/net/wireless/ti/wl18xx/main.c
41136@@ -1687,8 +1687,10 @@ static int wl18xx_setup(struct wl1271 *wl)
41137 }
41138
41139 if (!checksum_param) {
41140- wl18xx_ops.set_rx_csum = NULL;
41141- wl18xx_ops.init_vif = NULL;
41142+ pax_open_kernel();
41143+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
41144+ *(void **)&wl18xx_ops.init_vif = NULL;
41145+ pax_close_kernel();
41146 }
41147
41148 /* Enable 11a Band only if we have 5G antennas */
41149diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
41150index 7ef0b4a..ff65c28 100644
41151--- a/drivers/net/wireless/zd1211rw/zd_usb.c
41152+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
41153@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
41154 {
41155 struct zd_usb *usb = urb->context;
41156 struct zd_usb_interrupt *intr = &usb->intr;
41157- int len;
41158+ unsigned int len;
41159 u16 int_num;
41160
41161 ZD_ASSERT(in_interrupt());
41162diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
41163index d93b2b6..ae50401 100644
41164--- a/drivers/oprofile/buffer_sync.c
41165+++ b/drivers/oprofile/buffer_sync.c
41166@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
41167 if (cookie == NO_COOKIE)
41168 offset = pc;
41169 if (cookie == INVALID_COOKIE) {
41170- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41171+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41172 offset = pc;
41173 }
41174 if (cookie != last_cookie) {
41175@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
41176 /* add userspace sample */
41177
41178 if (!mm) {
41179- atomic_inc(&oprofile_stats.sample_lost_no_mm);
41180+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
41181 return 0;
41182 }
41183
41184 cookie = lookup_dcookie(mm, s->eip, &offset);
41185
41186 if (cookie == INVALID_COOKIE) {
41187- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41188+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41189 return 0;
41190 }
41191
41192@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
41193 /* ignore backtraces if failed to add a sample */
41194 if (state == sb_bt_start) {
41195 state = sb_bt_ignore;
41196- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
41197+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
41198 }
41199 }
41200 release_mm(mm);
41201diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
41202index c0cc4e7..44d4e54 100644
41203--- a/drivers/oprofile/event_buffer.c
41204+++ b/drivers/oprofile/event_buffer.c
41205@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
41206 }
41207
41208 if (buffer_pos == buffer_size) {
41209- atomic_inc(&oprofile_stats.event_lost_overflow);
41210+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
41211 return;
41212 }
41213
41214diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
41215index ed2c3ec..deda85a 100644
41216--- a/drivers/oprofile/oprof.c
41217+++ b/drivers/oprofile/oprof.c
41218@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
41219 if (oprofile_ops.switch_events())
41220 return;
41221
41222- atomic_inc(&oprofile_stats.multiplex_counter);
41223+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
41224 start_switch_worker();
41225 }
41226
41227diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
41228index 84a208d..d61b0a1 100644
41229--- a/drivers/oprofile/oprofile_files.c
41230+++ b/drivers/oprofile/oprofile_files.c
41231@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
41232
41233 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
41234
41235-static ssize_t timeout_read(struct file *file, char __user *buf,
41236+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
41237 size_t count, loff_t *offset)
41238 {
41239 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
41240diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
41241index 917d28e..d62d981 100644
41242--- a/drivers/oprofile/oprofile_stats.c
41243+++ b/drivers/oprofile/oprofile_stats.c
41244@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
41245 cpu_buf->sample_invalid_eip = 0;
41246 }
41247
41248- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
41249- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
41250- atomic_set(&oprofile_stats.event_lost_overflow, 0);
41251- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
41252- atomic_set(&oprofile_stats.multiplex_counter, 0);
41253+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
41254+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
41255+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
41256+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
41257+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
41258 }
41259
41260
41261diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
41262index 38b6fc0..b5cbfce 100644
41263--- a/drivers/oprofile/oprofile_stats.h
41264+++ b/drivers/oprofile/oprofile_stats.h
41265@@ -13,11 +13,11 @@
41266 #include <linux/atomic.h>
41267
41268 struct oprofile_stat_struct {
41269- atomic_t sample_lost_no_mm;
41270- atomic_t sample_lost_no_mapping;
41271- atomic_t bt_lost_no_mapping;
41272- atomic_t event_lost_overflow;
41273- atomic_t multiplex_counter;
41274+ atomic_unchecked_t sample_lost_no_mm;
41275+ atomic_unchecked_t sample_lost_no_mapping;
41276+ atomic_unchecked_t bt_lost_no_mapping;
41277+ atomic_unchecked_t event_lost_overflow;
41278+ atomic_unchecked_t multiplex_counter;
41279 };
41280
41281 extern struct oprofile_stat_struct oprofile_stats;
41282diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
41283index 7c12d9c..558bf3bb 100644
41284--- a/drivers/oprofile/oprofilefs.c
41285+++ b/drivers/oprofile/oprofilefs.c
41286@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
41287
41288
41289 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
41290- char const *name, atomic_t *val)
41291+ char const *name, atomic_unchecked_t *val)
41292 {
41293 return __oprofilefs_create_file(sb, root, name,
41294 &atomic_ro_fops, 0444, val);
41295diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
41296index 93404f7..4a313d8 100644
41297--- a/drivers/oprofile/timer_int.c
41298+++ b/drivers/oprofile/timer_int.c
41299@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
41300 return NOTIFY_OK;
41301 }
41302
41303-static struct notifier_block __refdata oprofile_cpu_notifier = {
41304+static struct notifier_block oprofile_cpu_notifier = {
41305 .notifier_call = oprofile_cpu_notify,
41306 };
41307
41308diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
41309index 92ed045..62d39bd7 100644
41310--- a/drivers/parport/procfs.c
41311+++ b/drivers/parport/procfs.c
41312@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
41313
41314 *ppos += len;
41315
41316- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
41317+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
41318 }
41319
41320 #ifdef CONFIG_PARPORT_1284
41321@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
41322
41323 *ppos += len;
41324
41325- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
41326+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
41327 }
41328 #endif /* IEEE1284.3 support. */
41329
41330diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
41331index c35e8ad..fc33beb 100644
41332--- a/drivers/pci/hotplug/acpiphp_ibm.c
41333+++ b/drivers/pci/hotplug/acpiphp_ibm.c
41334@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
41335 goto init_cleanup;
41336 }
41337
41338- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41339+ pax_open_kernel();
41340+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41341+ pax_close_kernel();
41342 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
41343
41344 return retval;
41345diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
41346index a6a71c4..c91097b 100644
41347--- a/drivers/pci/hotplug/cpcihp_generic.c
41348+++ b/drivers/pci/hotplug/cpcihp_generic.c
41349@@ -73,7 +73,6 @@ static u16 port;
41350 static unsigned int enum_bit;
41351 static u8 enum_mask;
41352
41353-static struct cpci_hp_controller_ops generic_hpc_ops;
41354 static struct cpci_hp_controller generic_hpc;
41355
41356 static int __init validate_parameters(void)
41357@@ -139,6 +138,10 @@ static int query_enum(void)
41358 return ((value & enum_mask) == enum_mask);
41359 }
41360
41361+static struct cpci_hp_controller_ops generic_hpc_ops = {
41362+ .query_enum = query_enum,
41363+};
41364+
41365 static int __init cpcihp_generic_init(void)
41366 {
41367 int status;
41368@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
41369 pci_dev_put(dev);
41370
41371 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
41372- generic_hpc_ops.query_enum = query_enum;
41373 generic_hpc.ops = &generic_hpc_ops;
41374
41375 status = cpci_hp_register_controller(&generic_hpc);
41376diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
41377index 449b4bb..257e2e8 100644
41378--- a/drivers/pci/hotplug/cpcihp_zt5550.c
41379+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
41380@@ -59,7 +59,6 @@
41381 /* local variables */
41382 static bool debug;
41383 static bool poll;
41384-static struct cpci_hp_controller_ops zt5550_hpc_ops;
41385 static struct cpci_hp_controller zt5550_hpc;
41386
41387 /* Primary cPCI bus bridge device */
41388@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
41389 return 0;
41390 }
41391
41392+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
41393+ .query_enum = zt5550_hc_query_enum,
41394+};
41395+
41396 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
41397 {
41398 int status;
41399@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
41400 dbg("returned from zt5550_hc_config");
41401
41402 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
41403- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
41404 zt5550_hpc.ops = &zt5550_hpc_ops;
41405 if(!poll) {
41406 zt5550_hpc.irq = hc_dev->irq;
41407 zt5550_hpc.irq_flags = IRQF_SHARED;
41408 zt5550_hpc.dev_id = hc_dev;
41409
41410- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41411- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41412- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41413+ pax_open_kernel();
41414+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41415+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41416+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41417+ pax_open_kernel();
41418 } else {
41419 info("using ENUM# polling mode");
41420 }
41421diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
41422index 76ba8a1..20ca857 100644
41423--- a/drivers/pci/hotplug/cpqphp_nvram.c
41424+++ b/drivers/pci/hotplug/cpqphp_nvram.c
41425@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
41426
41427 void compaq_nvram_init (void __iomem *rom_start)
41428 {
41429+
41430+#ifndef CONFIG_PAX_KERNEXEC
41431 if (rom_start) {
41432 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
41433 }
41434+#endif
41435+
41436 dbg("int15 entry = %p\n", compaq_int15_entry_point);
41437
41438 /* initialize our int15 lock */
41439diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
41440index ec20f74..c1d961e 100644
41441--- a/drivers/pci/hotplug/pci_hotplug_core.c
41442+++ b/drivers/pci/hotplug/pci_hotplug_core.c
41443@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
41444 return -EINVAL;
41445 }
41446
41447- slot->ops->owner = owner;
41448- slot->ops->mod_name = mod_name;
41449+ pax_open_kernel();
41450+ *(struct module **)&slot->ops->owner = owner;
41451+ *(const char **)&slot->ops->mod_name = mod_name;
41452+ pax_close_kernel();
41453
41454 mutex_lock(&pci_hp_mutex);
41455 /*
41456diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
41457index 7d72c5e..edce02c 100644
41458--- a/drivers/pci/hotplug/pciehp_core.c
41459+++ b/drivers/pci/hotplug/pciehp_core.c
41460@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41461 struct slot *slot = ctrl->slot;
41462 struct hotplug_slot *hotplug = NULL;
41463 struct hotplug_slot_info *info = NULL;
41464- struct hotplug_slot_ops *ops = NULL;
41465+ hotplug_slot_ops_no_const *ops = NULL;
41466 char name[SLOT_NAME_SIZE];
41467 int retval = -ENOMEM;
41468
41469diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41470index 5b4a9d9..cd5ac1f 100644
41471--- a/drivers/pci/pci-sysfs.c
41472+++ b/drivers/pci/pci-sysfs.c
41473@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41474 {
41475 /* allocate attribute structure, piggyback attribute name */
41476 int name_len = write_combine ? 13 : 10;
41477- struct bin_attribute *res_attr;
41478+ bin_attribute_no_const *res_attr;
41479 int retval;
41480
41481 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41482@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41483 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41484 {
41485 int retval;
41486- struct bin_attribute *attr;
41487+ bin_attribute_no_const *attr;
41488
41489 /* If the device has VPD, try to expose it in sysfs. */
41490 if (dev->vpd) {
41491@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41492 {
41493 int retval;
41494 int rom_size = 0;
41495- struct bin_attribute *attr;
41496+ bin_attribute_no_const *attr;
41497
41498 if (!sysfs_initialized)
41499 return -EACCES;
41500diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41501index d1182c4..2a138ec 100644
41502--- a/drivers/pci/pci.h
41503+++ b/drivers/pci/pci.h
41504@@ -92,7 +92,7 @@ struct pci_vpd_ops {
41505 struct pci_vpd {
41506 unsigned int len;
41507 const struct pci_vpd_ops *ops;
41508- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41509+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41510 };
41511
41512 int pci_vpd_pci22_init(struct pci_dev *dev);
41513diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41514index d320df6..ca9a8f6 100644
41515--- a/drivers/pci/pcie/aspm.c
41516+++ b/drivers/pci/pcie/aspm.c
41517@@ -27,9 +27,9 @@
41518 #define MODULE_PARAM_PREFIX "pcie_aspm."
41519
41520 /* Note: those are not register definitions */
41521-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41522-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41523-#define ASPM_STATE_L1 (4) /* L1 state */
41524+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41525+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41526+#define ASPM_STATE_L1 (4U) /* L1 state */
41527 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41528 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41529
41530diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41531index 70f10fa..cb5e917 100644
41532--- a/drivers/pci/probe.c
41533+++ b/drivers/pci/probe.c
41534@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41535 struct pci_bus_region region;
41536 bool bar_too_big = false, bar_disabled = false;
41537
41538- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41539+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41540
41541 /* No printks while decoding is disabled! */
41542 if (!dev->mmio_always_on) {
41543diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41544index 0812608..b04018c4 100644
41545--- a/drivers/pci/proc.c
41546+++ b/drivers/pci/proc.c
41547@@ -453,7 +453,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41548 static int __init pci_proc_init(void)
41549 {
41550 struct pci_dev *dev = NULL;
41551+
41552+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41553+#ifdef CONFIG_GRKERNSEC_PROC_USER
41554+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41555+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41556+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41557+#endif
41558+#else
41559 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41560+#endif
41561 proc_create("devices", 0, proc_bus_pci_dir,
41562 &proc_bus_pci_dev_operations);
41563 proc_initialized = 1;
41564diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
41565index 3e5b4497..dcdfb70 100644
41566--- a/drivers/platform/x86/chromeos_laptop.c
41567+++ b/drivers/platform/x86/chromeos_laptop.c
41568@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
41569 return 0;
41570 }
41571
41572-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
41573+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
41574 {
41575 .ident = "Samsung Series 5 550 - Touchpad",
41576 .matches = {
41577diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41578index 6b22938..bc9700e 100644
41579--- a/drivers/platform/x86/msi-laptop.c
41580+++ b/drivers/platform/x86/msi-laptop.c
41581@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
41582
41583 if (!quirks->ec_read_only) {
41584 /* allow userland write sysfs file */
41585- dev_attr_bluetooth.store = store_bluetooth;
41586- dev_attr_wlan.store = store_wlan;
41587- dev_attr_threeg.store = store_threeg;
41588- dev_attr_bluetooth.attr.mode |= S_IWUSR;
41589- dev_attr_wlan.attr.mode |= S_IWUSR;
41590- dev_attr_threeg.attr.mode |= S_IWUSR;
41591+ pax_open_kernel();
41592+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
41593+ *(void **)&dev_attr_wlan.store = store_wlan;
41594+ *(void **)&dev_attr_threeg.store = store_threeg;
41595+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
41596+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
41597+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
41598+ pax_close_kernel();
41599 }
41600
41601 /* disable hardware control by fn key */
41602diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
41603index 2ac045f..39c443d 100644
41604--- a/drivers/platform/x86/sony-laptop.c
41605+++ b/drivers/platform/x86/sony-laptop.c
41606@@ -2483,7 +2483,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
41607 }
41608
41609 /* High speed charging function */
41610-static struct device_attribute *hsc_handle;
41611+static device_attribute_no_const *hsc_handle;
41612
41613 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
41614 struct device_attribute *attr,
41615diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
41616index 54d31c0..3f896d3 100644
41617--- a/drivers/platform/x86/thinkpad_acpi.c
41618+++ b/drivers/platform/x86/thinkpad_acpi.c
41619@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
41620 return 0;
41621 }
41622
41623-void static hotkey_mask_warn_incomplete_mask(void)
41624+static void hotkey_mask_warn_incomplete_mask(void)
41625 {
41626 /* log only what the user can fix... */
41627 const u32 wantedmask = hotkey_driver_mask &
41628@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
41629 }
41630 }
41631
41632-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41633- struct tp_nvram_state *newn,
41634- const u32 event_mask)
41635-{
41636-
41637 #define TPACPI_COMPARE_KEY(__scancode, __member) \
41638 do { \
41639 if ((event_mask & (1 << __scancode)) && \
41640@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41641 tpacpi_hotkey_send_key(__scancode); \
41642 } while (0)
41643
41644- void issue_volchange(const unsigned int oldvol,
41645- const unsigned int newvol)
41646- {
41647- unsigned int i = oldvol;
41648+static void issue_volchange(const unsigned int oldvol,
41649+ const unsigned int newvol,
41650+ const u32 event_mask)
41651+{
41652+ unsigned int i = oldvol;
41653
41654- while (i > newvol) {
41655- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41656- i--;
41657- }
41658- while (i < newvol) {
41659- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41660- i++;
41661- }
41662+ while (i > newvol) {
41663+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41664+ i--;
41665 }
41666+ while (i < newvol) {
41667+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41668+ i++;
41669+ }
41670+}
41671
41672- void issue_brightnesschange(const unsigned int oldbrt,
41673- const unsigned int newbrt)
41674- {
41675- unsigned int i = oldbrt;
41676+static void issue_brightnesschange(const unsigned int oldbrt,
41677+ const unsigned int newbrt,
41678+ const u32 event_mask)
41679+{
41680+ unsigned int i = oldbrt;
41681
41682- while (i > newbrt) {
41683- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41684- i--;
41685- }
41686- while (i < newbrt) {
41687- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41688- i++;
41689- }
41690+ while (i > newbrt) {
41691+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41692+ i--;
41693+ }
41694+ while (i < newbrt) {
41695+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41696+ i++;
41697 }
41698+}
41699
41700+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41701+ struct tp_nvram_state *newn,
41702+ const u32 event_mask)
41703+{
41704 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
41705 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
41706 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
41707@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41708 oldn->volume_level != newn->volume_level) {
41709 /* recently muted, or repeated mute keypress, or
41710 * multiple presses ending in mute */
41711- issue_volchange(oldn->volume_level, newn->volume_level);
41712+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41713 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
41714 }
41715 } else {
41716@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41717 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41718 }
41719 if (oldn->volume_level != newn->volume_level) {
41720- issue_volchange(oldn->volume_level, newn->volume_level);
41721+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41722 } else if (oldn->volume_toggle != newn->volume_toggle) {
41723 /* repeated vol up/down keypress at end of scale ? */
41724 if (newn->volume_level == 0)
41725@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41726 /* handle brightness */
41727 if (oldn->brightness_level != newn->brightness_level) {
41728 issue_brightnesschange(oldn->brightness_level,
41729- newn->brightness_level);
41730+ newn->brightness_level,
41731+ event_mask);
41732 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
41733 /* repeated key presses that didn't change state */
41734 if (newn->brightness_level == 0)
41735@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41736 && !tp_features.bright_unkfw)
41737 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41738 }
41739+}
41740
41741 #undef TPACPI_COMPARE_KEY
41742 #undef TPACPI_MAY_SEND_KEY
41743-}
41744
41745 /*
41746 * Polling driver
41747diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
41748index 769d265..a3a05ca 100644
41749--- a/drivers/pnp/pnpbios/bioscalls.c
41750+++ b/drivers/pnp/pnpbios/bioscalls.c
41751@@ -58,7 +58,7 @@ do { \
41752 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
41753 } while(0)
41754
41755-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
41756+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
41757 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
41758
41759 /*
41760@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41761
41762 cpu = get_cpu();
41763 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
41764+
41765+ pax_open_kernel();
41766 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
41767+ pax_close_kernel();
41768
41769 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
41770 spin_lock_irqsave(&pnp_bios_lock, flags);
41771@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41772 :"memory");
41773 spin_unlock_irqrestore(&pnp_bios_lock, flags);
41774
41775+ pax_open_kernel();
41776 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
41777+ pax_close_kernel();
41778+
41779 put_cpu();
41780
41781 /* If we get here and this is set then the PnP BIOS faulted on us. */
41782@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
41783 return status;
41784 }
41785
41786-void pnpbios_calls_init(union pnp_bios_install_struct *header)
41787+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
41788 {
41789 int i;
41790
41791@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41792 pnp_bios_callpoint.offset = header->fields.pm16offset;
41793 pnp_bios_callpoint.segment = PNP_CS16;
41794
41795+ pax_open_kernel();
41796+
41797 for_each_possible_cpu(i) {
41798 struct desc_struct *gdt = get_cpu_gdt_table(i);
41799 if (!gdt)
41800@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41801 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
41802 (unsigned long)__va(header->fields.pm16dseg));
41803 }
41804+
41805+ pax_close_kernel();
41806 }
41807diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
41808index 3e6db1c..1fbbdae 100644
41809--- a/drivers/pnp/resource.c
41810+++ b/drivers/pnp/resource.c
41811@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
41812 return 1;
41813
41814 /* check if the resource is valid */
41815- if (*irq < 0 || *irq > 15)
41816+ if (*irq > 15)
41817 return 0;
41818
41819 /* check if the resource is reserved */
41820@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
41821 return 1;
41822
41823 /* check if the resource is valid */
41824- if (*dma < 0 || *dma == 4 || *dma > 7)
41825+ if (*dma == 4 || *dma > 7)
41826 return 0;
41827
41828 /* check if the resource is reserved */
41829diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
41830index 0c52e2a..3421ab7 100644
41831--- a/drivers/power/pda_power.c
41832+++ b/drivers/power/pda_power.c
41833@@ -37,7 +37,11 @@ static int polling;
41834
41835 #if IS_ENABLED(CONFIG_USB_PHY)
41836 static struct usb_phy *transceiver;
41837-static struct notifier_block otg_nb;
41838+static int otg_handle_notification(struct notifier_block *nb,
41839+ unsigned long event, void *unused);
41840+static struct notifier_block otg_nb = {
41841+ .notifier_call = otg_handle_notification
41842+};
41843 #endif
41844
41845 static struct regulator *ac_draw;
41846@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
41847
41848 #if IS_ENABLED(CONFIG_USB_PHY)
41849 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41850- otg_nb.notifier_call = otg_handle_notification;
41851 ret = usb_register_notifier(transceiver, &otg_nb);
41852 if (ret) {
41853 dev_err(dev, "failure to register otg notifier\n");
41854diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41855index cc439fd..8fa30df 100644
41856--- a/drivers/power/power_supply.h
41857+++ b/drivers/power/power_supply.h
41858@@ -16,12 +16,12 @@ struct power_supply;
41859
41860 #ifdef CONFIG_SYSFS
41861
41862-extern void power_supply_init_attrs(struct device_type *dev_type);
41863+extern void power_supply_init_attrs(void);
41864 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41865
41866 #else
41867
41868-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41869+static inline void power_supply_init_attrs(void) {}
41870 #define power_supply_uevent NULL
41871
41872 #endif /* CONFIG_SYSFS */
41873diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41874index 1c517c3..ffa2f17 100644
41875--- a/drivers/power/power_supply_core.c
41876+++ b/drivers/power/power_supply_core.c
41877@@ -24,7 +24,10 @@
41878 struct class *power_supply_class;
41879 EXPORT_SYMBOL_GPL(power_supply_class);
41880
41881-static struct device_type power_supply_dev_type;
41882+extern const struct attribute_group *power_supply_attr_groups[];
41883+static struct device_type power_supply_dev_type = {
41884+ .groups = power_supply_attr_groups,
41885+};
41886
41887 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
41888 struct power_supply *supply)
41889@@ -554,7 +557,7 @@ static int __init power_supply_class_init(void)
41890 return PTR_ERR(power_supply_class);
41891
41892 power_supply_class->dev_uevent = power_supply_uevent;
41893- power_supply_init_attrs(&power_supply_dev_type);
41894+ power_supply_init_attrs();
41895
41896 return 0;
41897 }
41898diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41899index 29178f7..c65f324 100644
41900--- a/drivers/power/power_supply_sysfs.c
41901+++ b/drivers/power/power_supply_sysfs.c
41902@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
41903 .is_visible = power_supply_attr_is_visible,
41904 };
41905
41906-static const struct attribute_group *power_supply_attr_groups[] = {
41907+const struct attribute_group *power_supply_attr_groups[] = {
41908 &power_supply_attr_group,
41909 NULL,
41910 };
41911
41912-void power_supply_init_attrs(struct device_type *dev_type)
41913+void power_supply_init_attrs(void)
41914 {
41915 int i;
41916
41917- dev_type->groups = power_supply_attr_groups;
41918-
41919 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41920 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41921 }
41922diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41923index d428ef9..fdc0357 100644
41924--- a/drivers/regulator/max8660.c
41925+++ b/drivers/regulator/max8660.c
41926@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41927 max8660->shadow_regs[MAX8660_OVER1] = 5;
41928 } else {
41929 /* Otherwise devices can be toggled via software */
41930- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41931- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41932+ pax_open_kernel();
41933+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41934+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41935+ pax_close_kernel();
41936 }
41937
41938 /*
41939diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41940index adb1414..c13e0ce 100644
41941--- a/drivers/regulator/max8973-regulator.c
41942+++ b/drivers/regulator/max8973-regulator.c
41943@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41944 if (!pdata->enable_ext_control) {
41945 max->desc.enable_reg = MAX8973_VOUT;
41946 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41947- max8973_dcdc_ops.enable = regulator_enable_regmap;
41948- max8973_dcdc_ops.disable = regulator_disable_regmap;
41949- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41950+ pax_open_kernel();
41951+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41952+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41953+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41954+ pax_close_kernel();
41955 }
41956
41957 max->enable_external_control = pdata->enable_ext_control;
41958diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41959index b716283..3cc4349 100644
41960--- a/drivers/regulator/mc13892-regulator.c
41961+++ b/drivers/regulator/mc13892-regulator.c
41962@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41963 }
41964 mc13xxx_unlock(mc13892);
41965
41966- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41967+ pax_open_kernel();
41968+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41969 = mc13892_vcam_set_mode;
41970- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41971+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41972 = mc13892_vcam_get_mode;
41973+ pax_close_kernel();
41974
41975 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41976 ARRAY_SIZE(mc13892_regulators));
41977diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41978index f1cb706..4c7832a 100644
41979--- a/drivers/rtc/rtc-cmos.c
41980+++ b/drivers/rtc/rtc-cmos.c
41981@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41982 hpet_rtc_timer_init();
41983
41984 /* export at least the first block of NVRAM */
41985- nvram.size = address_space - NVRAM_OFFSET;
41986+ pax_open_kernel();
41987+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41988+ pax_close_kernel();
41989 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41990 if (retval < 0) {
41991 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41992diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41993index d049393..bb20be0 100644
41994--- a/drivers/rtc/rtc-dev.c
41995+++ b/drivers/rtc/rtc-dev.c
41996@@ -16,6 +16,7 @@
41997 #include <linux/module.h>
41998 #include <linux/rtc.h>
41999 #include <linux/sched.h>
42000+#include <linux/grsecurity.h>
42001 #include "rtc-core.h"
42002
42003 static dev_t rtc_devt;
42004@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
42005 if (copy_from_user(&tm, uarg, sizeof(tm)))
42006 return -EFAULT;
42007
42008+ gr_log_timechange();
42009+
42010 return rtc_set_time(rtc, &tm);
42011
42012 case RTC_PIE_ON:
42013diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
42014index b53992a..776df84 100644
42015--- a/drivers/rtc/rtc-ds1307.c
42016+++ b/drivers/rtc/rtc-ds1307.c
42017@@ -107,7 +107,7 @@ struct ds1307 {
42018 u8 offset; /* register's offset */
42019 u8 regs[11];
42020 u16 nvram_offset;
42021- struct bin_attribute *nvram;
42022+ bin_attribute_no_const *nvram;
42023 enum ds_type type;
42024 unsigned long flags;
42025 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
42026diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
42027index 130f29a..6179d03 100644
42028--- a/drivers/rtc/rtc-m48t59.c
42029+++ b/drivers/rtc/rtc-m48t59.c
42030@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
42031 goto out;
42032 }
42033
42034- m48t59_nvram_attr.size = pdata->offset;
42035+ pax_open_kernel();
42036+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
42037+ pax_close_kernel();
42038
42039 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
42040 if (ret) {
42041diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
42042index e693af6..2e525b6 100644
42043--- a/drivers/scsi/bfa/bfa_fcpim.h
42044+++ b/drivers/scsi/bfa/bfa_fcpim.h
42045@@ -36,7 +36,7 @@ struct bfa_iotag_s {
42046
42047 struct bfa_itn_s {
42048 bfa_isr_func_t isr;
42049-};
42050+} __no_const;
42051
42052 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
42053 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
42054diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
42055index 23a90e7..9cf04ee 100644
42056--- a/drivers/scsi/bfa/bfa_ioc.h
42057+++ b/drivers/scsi/bfa/bfa_ioc.h
42058@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
42059 bfa_ioc_disable_cbfn_t disable_cbfn;
42060 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
42061 bfa_ioc_reset_cbfn_t reset_cbfn;
42062-};
42063+} __no_const;
42064
42065 /*
42066 * IOC event notification mechanism.
42067@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
42068 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
42069 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
42070 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
42071-};
42072+} __no_const;
42073
42074 /*
42075 * Queue element to wait for room in request queue. FIFO order is
42076diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
42077index df0c3c7..b00e1d0 100644
42078--- a/drivers/scsi/hosts.c
42079+++ b/drivers/scsi/hosts.c
42080@@ -42,7 +42,7 @@
42081 #include "scsi_logging.h"
42082
42083
42084-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42085+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42086
42087
42088 static void scsi_host_cls_release(struct device *dev)
42089@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
42090 * subtract one because we increment first then return, but we need to
42091 * know what the next host number was before increment
42092 */
42093- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
42094+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
42095 shost->dma_channel = 0xff;
42096
42097 /* These three are default values which can be overridden */
42098diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
42099index 7f4f790..b75b92a 100644
42100--- a/drivers/scsi/hpsa.c
42101+++ b/drivers/scsi/hpsa.c
42102@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
42103 unsigned long flags;
42104
42105 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
42106- return h->access.command_completed(h, q);
42107+ return h->access->command_completed(h, q);
42108
42109 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
42110 a = rq->head[rq->current_entry];
42111@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
42112 while (!list_empty(&h->reqQ)) {
42113 c = list_entry(h->reqQ.next, struct CommandList, list);
42114 /* can't do anything if fifo is full */
42115- if ((h->access.fifo_full(h))) {
42116+ if ((h->access->fifo_full(h))) {
42117 dev_warn(&h->pdev->dev, "fifo full\n");
42118 break;
42119 }
42120@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
42121
42122 /* Tell the controller execute command */
42123 spin_unlock_irqrestore(&h->lock, flags);
42124- h->access.submit_command(h, c);
42125+ h->access->submit_command(h, c);
42126 spin_lock_irqsave(&h->lock, flags);
42127 }
42128 spin_unlock_irqrestore(&h->lock, flags);
42129@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
42130
42131 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
42132 {
42133- return h->access.command_completed(h, q);
42134+ return h->access->command_completed(h, q);
42135 }
42136
42137 static inline bool interrupt_pending(struct ctlr_info *h)
42138 {
42139- return h->access.intr_pending(h);
42140+ return h->access->intr_pending(h);
42141 }
42142
42143 static inline long interrupt_not_for_us(struct ctlr_info *h)
42144 {
42145- return (h->access.intr_pending(h) == 0) ||
42146+ return (h->access->intr_pending(h) == 0) ||
42147 (h->interrupts_enabled == 0);
42148 }
42149
42150@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
42151 if (prod_index < 0)
42152 return -ENODEV;
42153 h->product_name = products[prod_index].product_name;
42154- h->access = *(products[prod_index].access);
42155+ h->access = products[prod_index].access;
42156
42157 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
42158 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
42159@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
42160
42161 assert_spin_locked(&lockup_detector_lock);
42162 remove_ctlr_from_lockup_detector_list(h);
42163- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42164+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42165 spin_lock_irqsave(&h->lock, flags);
42166 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
42167 spin_unlock_irqrestore(&h->lock, flags);
42168@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
42169 }
42170
42171 /* make sure the board interrupts are off */
42172- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42173+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42174
42175 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
42176 goto clean2;
42177@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
42178 * fake ones to scoop up any residual completions.
42179 */
42180 spin_lock_irqsave(&h->lock, flags);
42181- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42182+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42183 spin_unlock_irqrestore(&h->lock, flags);
42184 free_irqs(h);
42185 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
42186@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
42187 dev_info(&h->pdev->dev, "Board READY.\n");
42188 dev_info(&h->pdev->dev,
42189 "Waiting for stale completions to drain.\n");
42190- h->access.set_intr_mask(h, HPSA_INTR_ON);
42191+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42192 msleep(10000);
42193- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42194+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42195
42196 rc = controller_reset_failed(h->cfgtable);
42197 if (rc)
42198@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
42199 }
42200
42201 /* Turn the interrupts on so we can service requests */
42202- h->access.set_intr_mask(h, HPSA_INTR_ON);
42203+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42204
42205 hpsa_hba_inquiry(h);
42206 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
42207@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
42208 * To write all data in the battery backed cache to disks
42209 */
42210 hpsa_flush_cache(h);
42211- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42212+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42213 hpsa_free_irqs_and_disable_msix(h);
42214 }
42215
42216@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
42217 return;
42218 }
42219 /* Change the access methods to the performant access methods */
42220- h->access = SA5_performant_access;
42221+ h->access = &SA5_performant_access;
42222 h->transMethod = CFGTBL_Trans_Performant;
42223 }
42224
42225diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
42226index 9816479..c5d4e97 100644
42227--- a/drivers/scsi/hpsa.h
42228+++ b/drivers/scsi/hpsa.h
42229@@ -79,7 +79,7 @@ struct ctlr_info {
42230 unsigned int msix_vector;
42231 unsigned int msi_vector;
42232 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
42233- struct access_method access;
42234+ struct access_method *access;
42235
42236 /* queue and queue Info */
42237 struct list_head reqQ;
42238diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
42239index 8b928c6..9c76300 100644
42240--- a/drivers/scsi/libfc/fc_exch.c
42241+++ b/drivers/scsi/libfc/fc_exch.c
42242@@ -100,12 +100,12 @@ struct fc_exch_mgr {
42243 u16 pool_max_index;
42244
42245 struct {
42246- atomic_t no_free_exch;
42247- atomic_t no_free_exch_xid;
42248- atomic_t xid_not_found;
42249- atomic_t xid_busy;
42250- atomic_t seq_not_found;
42251- atomic_t non_bls_resp;
42252+ atomic_unchecked_t no_free_exch;
42253+ atomic_unchecked_t no_free_exch_xid;
42254+ atomic_unchecked_t xid_not_found;
42255+ atomic_unchecked_t xid_busy;
42256+ atomic_unchecked_t seq_not_found;
42257+ atomic_unchecked_t non_bls_resp;
42258 } stats;
42259 };
42260
42261@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
42262 /* allocate memory for exchange */
42263 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
42264 if (!ep) {
42265- atomic_inc(&mp->stats.no_free_exch);
42266+ atomic_inc_unchecked(&mp->stats.no_free_exch);
42267 goto out;
42268 }
42269 memset(ep, 0, sizeof(*ep));
42270@@ -797,7 +797,7 @@ out:
42271 return ep;
42272 err:
42273 spin_unlock_bh(&pool->lock);
42274- atomic_inc(&mp->stats.no_free_exch_xid);
42275+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
42276 mempool_free(ep, mp->ep_pool);
42277 return NULL;
42278 }
42279@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42280 xid = ntohs(fh->fh_ox_id); /* we originated exch */
42281 ep = fc_exch_find(mp, xid);
42282 if (!ep) {
42283- atomic_inc(&mp->stats.xid_not_found);
42284+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42285 reject = FC_RJT_OX_ID;
42286 goto out;
42287 }
42288@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42289 ep = fc_exch_find(mp, xid);
42290 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
42291 if (ep) {
42292- atomic_inc(&mp->stats.xid_busy);
42293+ atomic_inc_unchecked(&mp->stats.xid_busy);
42294 reject = FC_RJT_RX_ID;
42295 goto rel;
42296 }
42297@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42298 }
42299 xid = ep->xid; /* get our XID */
42300 } else if (!ep) {
42301- atomic_inc(&mp->stats.xid_not_found);
42302+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42303 reject = FC_RJT_RX_ID; /* XID not found */
42304 goto out;
42305 }
42306@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42307 } else {
42308 sp = &ep->seq;
42309 if (sp->id != fh->fh_seq_id) {
42310- atomic_inc(&mp->stats.seq_not_found);
42311+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42312 if (f_ctl & FC_FC_END_SEQ) {
42313 /*
42314 * Update sequence_id based on incoming last
42315@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42316
42317 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
42318 if (!ep) {
42319- atomic_inc(&mp->stats.xid_not_found);
42320+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42321 goto out;
42322 }
42323 if (ep->esb_stat & ESB_ST_COMPLETE) {
42324- atomic_inc(&mp->stats.xid_not_found);
42325+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42326 goto rel;
42327 }
42328 if (ep->rxid == FC_XID_UNKNOWN)
42329 ep->rxid = ntohs(fh->fh_rx_id);
42330 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
42331- atomic_inc(&mp->stats.xid_not_found);
42332+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42333 goto rel;
42334 }
42335 if (ep->did != ntoh24(fh->fh_s_id) &&
42336 ep->did != FC_FID_FLOGI) {
42337- atomic_inc(&mp->stats.xid_not_found);
42338+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42339 goto rel;
42340 }
42341 sof = fr_sof(fp);
42342@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42343 sp->ssb_stat |= SSB_ST_RESP;
42344 sp->id = fh->fh_seq_id;
42345 } else if (sp->id != fh->fh_seq_id) {
42346- atomic_inc(&mp->stats.seq_not_found);
42347+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42348 goto rel;
42349 }
42350
42351@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42352 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
42353
42354 if (!sp)
42355- atomic_inc(&mp->stats.xid_not_found);
42356+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42357 else
42358- atomic_inc(&mp->stats.non_bls_resp);
42359+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
42360
42361 fc_frame_free(fp);
42362 }
42363@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
42364
42365 list_for_each_entry(ema, &lport->ema_list, ema_list) {
42366 mp = ema->mp;
42367- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
42368+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
42369 st->fc_no_free_exch_xid +=
42370- atomic_read(&mp->stats.no_free_exch_xid);
42371- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
42372- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
42373- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
42374- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
42375+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
42376+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
42377+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
42378+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
42379+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
42380 }
42381 }
42382 EXPORT_SYMBOL(fc_exch_update_stats);
42383diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
42384index 161c98e..6d563b3 100644
42385--- a/drivers/scsi/libsas/sas_ata.c
42386+++ b/drivers/scsi/libsas/sas_ata.c
42387@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
42388 .postreset = ata_std_postreset,
42389 .error_handler = ata_std_error_handler,
42390 .post_internal_cmd = sas_ata_post_internal,
42391- .qc_defer = ata_std_qc_defer,
42392+ .qc_defer = ata_std_qc_defer,
42393 .qc_prep = ata_noop_qc_prep,
42394 .qc_issue = sas_ata_qc_issue,
42395 .qc_fill_rtf = sas_ata_qc_fill_rtf,
42396diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
42397index bcc56ca..6f4174a 100644
42398--- a/drivers/scsi/lpfc/lpfc.h
42399+++ b/drivers/scsi/lpfc/lpfc.h
42400@@ -431,7 +431,7 @@ struct lpfc_vport {
42401 struct dentry *debug_nodelist;
42402 struct dentry *vport_debugfs_root;
42403 struct lpfc_debugfs_trc *disc_trc;
42404- atomic_t disc_trc_cnt;
42405+ atomic_unchecked_t disc_trc_cnt;
42406 #endif
42407 uint8_t stat_data_enabled;
42408 uint8_t stat_data_blocked;
42409@@ -865,8 +865,8 @@ struct lpfc_hba {
42410 struct timer_list fabric_block_timer;
42411 unsigned long bit_flags;
42412 #define FABRIC_COMANDS_BLOCKED 0
42413- atomic_t num_rsrc_err;
42414- atomic_t num_cmd_success;
42415+ atomic_unchecked_t num_rsrc_err;
42416+ atomic_unchecked_t num_cmd_success;
42417 unsigned long last_rsrc_error_time;
42418 unsigned long last_ramp_down_time;
42419 unsigned long last_ramp_up_time;
42420@@ -902,7 +902,7 @@ struct lpfc_hba {
42421
42422 struct dentry *debug_slow_ring_trc;
42423 struct lpfc_debugfs_trc *slow_ring_trc;
42424- atomic_t slow_ring_trc_cnt;
42425+ atomic_unchecked_t slow_ring_trc_cnt;
42426 /* iDiag debugfs sub-directory */
42427 struct dentry *idiag_root;
42428 struct dentry *idiag_pci_cfg;
42429diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
42430index f525ecb..32549a4 100644
42431--- a/drivers/scsi/lpfc/lpfc_debugfs.c
42432+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
42433@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
42434
42435 #include <linux/debugfs.h>
42436
42437-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42438+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42439 static unsigned long lpfc_debugfs_start_time = 0L;
42440
42441 /* iDiag */
42442@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
42443 lpfc_debugfs_enable = 0;
42444
42445 len = 0;
42446- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
42447+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
42448 (lpfc_debugfs_max_disc_trc - 1);
42449 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
42450 dtp = vport->disc_trc + i;
42451@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
42452 lpfc_debugfs_enable = 0;
42453
42454 len = 0;
42455- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
42456+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
42457 (lpfc_debugfs_max_slow_ring_trc - 1);
42458 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
42459 dtp = phba->slow_ring_trc + i;
42460@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42461 !vport || !vport->disc_trc)
42462 return;
42463
42464- index = atomic_inc_return(&vport->disc_trc_cnt) &
42465+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42466 (lpfc_debugfs_max_disc_trc - 1);
42467 dtp = vport->disc_trc + index;
42468 dtp->fmt = fmt;
42469 dtp->data1 = data1;
42470 dtp->data2 = data2;
42471 dtp->data3 = data3;
42472- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42473+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42474 dtp->jif = jiffies;
42475 #endif
42476 return;
42477@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42478 !phba || !phba->slow_ring_trc)
42479 return;
42480
42481- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42482+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42483 (lpfc_debugfs_max_slow_ring_trc - 1);
42484 dtp = phba->slow_ring_trc + index;
42485 dtp->fmt = fmt;
42486 dtp->data1 = data1;
42487 dtp->data2 = data2;
42488 dtp->data3 = data3;
42489- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42490+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42491 dtp->jif = jiffies;
42492 #endif
42493 return;
42494@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42495 "slow_ring buffer\n");
42496 goto debug_failed;
42497 }
42498- atomic_set(&phba->slow_ring_trc_cnt, 0);
42499+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42500 memset(phba->slow_ring_trc, 0,
42501 (sizeof(struct lpfc_debugfs_trc) *
42502 lpfc_debugfs_max_slow_ring_trc));
42503@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42504 "buffer\n");
42505 goto debug_failed;
42506 }
42507- atomic_set(&vport->disc_trc_cnt, 0);
42508+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42509
42510 snprintf(name, sizeof(name), "discovery_trace");
42511 vport->debug_disc_trc =
42512diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42513index cb465b2..2e7b25f 100644
42514--- a/drivers/scsi/lpfc/lpfc_init.c
42515+++ b/drivers/scsi/lpfc/lpfc_init.c
42516@@ -10950,8 +10950,10 @@ lpfc_init(void)
42517 "misc_register returned with status %d", error);
42518
42519 if (lpfc_enable_npiv) {
42520- lpfc_transport_functions.vport_create = lpfc_vport_create;
42521- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42522+ pax_open_kernel();
42523+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42524+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42525+ pax_close_kernel();
42526 }
42527 lpfc_transport_template =
42528 fc_attach_transport(&lpfc_transport_functions);
42529diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42530index 8523b278e..ce1d812 100644
42531--- a/drivers/scsi/lpfc/lpfc_scsi.c
42532+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42533@@ -331,7 +331,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42534 uint32_t evt_posted;
42535
42536 spin_lock_irqsave(&phba->hbalock, flags);
42537- atomic_inc(&phba->num_rsrc_err);
42538+ atomic_inc_unchecked(&phba->num_rsrc_err);
42539 phba->last_rsrc_error_time = jiffies;
42540
42541 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42542@@ -372,7 +372,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42543 unsigned long flags;
42544 struct lpfc_hba *phba = vport->phba;
42545 uint32_t evt_posted;
42546- atomic_inc(&phba->num_cmd_success);
42547+ atomic_inc_unchecked(&phba->num_cmd_success);
42548
42549 if (vport->cfg_lun_queue_depth <= queue_depth)
42550 return;
42551@@ -416,8 +416,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42552 unsigned long num_rsrc_err, num_cmd_success;
42553 int i;
42554
42555- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42556- num_cmd_success = atomic_read(&phba->num_cmd_success);
42557+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42558+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42559
42560 /*
42561 * The error and success command counters are global per
42562@@ -445,8 +445,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42563 }
42564 }
42565 lpfc_destroy_vport_work_array(phba, vports);
42566- atomic_set(&phba->num_rsrc_err, 0);
42567- atomic_set(&phba->num_cmd_success, 0);
42568+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42569+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42570 }
42571
42572 /**
42573@@ -480,8 +480,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42574 }
42575 }
42576 lpfc_destroy_vport_work_array(phba, vports);
42577- atomic_set(&phba->num_rsrc_err, 0);
42578- atomic_set(&phba->num_cmd_success, 0);
42579+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42580+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42581 }
42582
42583 /**
42584diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
42585index 8e1b737..50ff510 100644
42586--- a/drivers/scsi/pmcraid.c
42587+++ b/drivers/scsi/pmcraid.c
42588@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
42589 res->scsi_dev = scsi_dev;
42590 scsi_dev->hostdata = res;
42591 res->change_detected = 0;
42592- atomic_set(&res->read_failures, 0);
42593- atomic_set(&res->write_failures, 0);
42594+ atomic_set_unchecked(&res->read_failures, 0);
42595+ atomic_set_unchecked(&res->write_failures, 0);
42596 rc = 0;
42597 }
42598 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
42599@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
42600
42601 /* If this was a SCSI read/write command keep count of errors */
42602 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
42603- atomic_inc(&res->read_failures);
42604+ atomic_inc_unchecked(&res->read_failures);
42605 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
42606- atomic_inc(&res->write_failures);
42607+ atomic_inc_unchecked(&res->write_failures);
42608
42609 if (!RES_IS_GSCSI(res->cfg_entry) &&
42610 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
42611@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
42612 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42613 * hrrq_id assigned here in queuecommand
42614 */
42615- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42616+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42617 pinstance->num_hrrq;
42618 cmd->cmd_done = pmcraid_io_done;
42619
42620@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
42621 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42622 * hrrq_id assigned here in queuecommand
42623 */
42624- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42625+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42626 pinstance->num_hrrq;
42627
42628 if (request_size) {
42629@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
42630
42631 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
42632 /* add resources only after host is added into system */
42633- if (!atomic_read(&pinstance->expose_resources))
42634+ if (!atomic_read_unchecked(&pinstance->expose_resources))
42635 return;
42636
42637 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
42638@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
42639 init_waitqueue_head(&pinstance->reset_wait_q);
42640
42641 atomic_set(&pinstance->outstanding_cmds, 0);
42642- atomic_set(&pinstance->last_message_id, 0);
42643- atomic_set(&pinstance->expose_resources, 0);
42644+ atomic_set_unchecked(&pinstance->last_message_id, 0);
42645+ atomic_set_unchecked(&pinstance->expose_resources, 0);
42646
42647 INIT_LIST_HEAD(&pinstance->free_res_q);
42648 INIT_LIST_HEAD(&pinstance->used_res_q);
42649@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
42650 /* Schedule worker thread to handle CCN and take care of adding and
42651 * removing devices to OS
42652 */
42653- atomic_set(&pinstance->expose_resources, 1);
42654+ atomic_set_unchecked(&pinstance->expose_resources, 1);
42655 schedule_work(&pinstance->worker_q);
42656 return rc;
42657
42658diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
42659index e1d150f..6c6df44 100644
42660--- a/drivers/scsi/pmcraid.h
42661+++ b/drivers/scsi/pmcraid.h
42662@@ -748,7 +748,7 @@ struct pmcraid_instance {
42663 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
42664
42665 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
42666- atomic_t last_message_id;
42667+ atomic_unchecked_t last_message_id;
42668
42669 /* configuration table */
42670 struct pmcraid_config_table *cfg_table;
42671@@ -777,7 +777,7 @@ struct pmcraid_instance {
42672 atomic_t outstanding_cmds;
42673
42674 /* should add/delete resources to mid-layer now ?*/
42675- atomic_t expose_resources;
42676+ atomic_unchecked_t expose_resources;
42677
42678
42679
42680@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
42681 struct pmcraid_config_table_entry_ext cfg_entry_ext;
42682 };
42683 struct scsi_device *scsi_dev; /* Link scsi_device structure */
42684- atomic_t read_failures; /* count of failed READ commands */
42685- atomic_t write_failures; /* count of failed WRITE commands */
42686+ atomic_unchecked_t read_failures; /* count of failed READ commands */
42687+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
42688
42689 /* To indicate add/delete/modify during CCN */
42690 u8 change_detected;
42691diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
42692index bf60c63..74d4dce 100644
42693--- a/drivers/scsi/qla2xxx/qla_attr.c
42694+++ b/drivers/scsi/qla2xxx/qla_attr.c
42695@@ -2001,7 +2001,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
42696 return 0;
42697 }
42698
42699-struct fc_function_template qla2xxx_transport_functions = {
42700+fc_function_template_no_const qla2xxx_transport_functions = {
42701
42702 .show_host_node_name = 1,
42703 .show_host_port_name = 1,
42704@@ -2048,7 +2048,7 @@ struct fc_function_template qla2xxx_transport_functions = {
42705 .bsg_timeout = qla24xx_bsg_timeout,
42706 };
42707
42708-struct fc_function_template qla2xxx_transport_vport_functions = {
42709+fc_function_template_no_const qla2xxx_transport_vport_functions = {
42710
42711 .show_host_node_name = 1,
42712 .show_host_port_name = 1,
42713diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
42714index 026bfde..90c4018 100644
42715--- a/drivers/scsi/qla2xxx/qla_gbl.h
42716+++ b/drivers/scsi/qla2xxx/qla_gbl.h
42717@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
42718 struct device_attribute;
42719 extern struct device_attribute *qla2x00_host_attrs[];
42720 struct fc_function_template;
42721-extern struct fc_function_template qla2xxx_transport_functions;
42722-extern struct fc_function_template qla2xxx_transport_vport_functions;
42723+extern fc_function_template_no_const qla2xxx_transport_functions;
42724+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
42725 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
42726 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
42727 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
42728diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
42729index ad72c1d..afc9a98 100644
42730--- a/drivers/scsi/qla2xxx/qla_os.c
42731+++ b/drivers/scsi/qla2xxx/qla_os.c
42732@@ -1571,8 +1571,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
42733 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
42734 /* Ok, a 64bit DMA mask is applicable. */
42735 ha->flags.enable_64bit_addressing = 1;
42736- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42737- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42738+ pax_open_kernel();
42739+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42740+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42741+ pax_close_kernel();
42742 return;
42743 }
42744 }
42745diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
42746index ddf16a8..80f4dd0 100644
42747--- a/drivers/scsi/qla4xxx/ql4_def.h
42748+++ b/drivers/scsi/qla4xxx/ql4_def.h
42749@@ -291,7 +291,7 @@ struct ddb_entry {
42750 * (4000 only) */
42751 atomic_t relogin_timer; /* Max Time to wait for
42752 * relogin to complete */
42753- atomic_t relogin_retry_count; /* Num of times relogin has been
42754+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
42755 * retried */
42756 uint32_t default_time2wait; /* Default Min time between
42757 * relogins (+aens) */
42758diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
42759index 4d231c1..2892c37 100644
42760--- a/drivers/scsi/qla4xxx/ql4_os.c
42761+++ b/drivers/scsi/qla4xxx/ql4_os.c
42762@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
42763 */
42764 if (!iscsi_is_session_online(cls_sess)) {
42765 /* Reset retry relogin timer */
42766- atomic_inc(&ddb_entry->relogin_retry_count);
42767+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
42768 DEBUG2(ql4_printk(KERN_INFO, ha,
42769 "%s: index[%d] relogin timed out-retrying"
42770 " relogin (%d), retry (%d)\n", __func__,
42771 ddb_entry->fw_ddb_index,
42772- atomic_read(&ddb_entry->relogin_retry_count),
42773+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
42774 ddb_entry->default_time2wait + 4));
42775 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
42776 atomic_set(&ddb_entry->retry_relogin_timer,
42777@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
42778
42779 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
42780 atomic_set(&ddb_entry->relogin_timer, 0);
42781- atomic_set(&ddb_entry->relogin_retry_count, 0);
42782+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
42783 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
42784 ddb_entry->default_relogin_timeout =
42785 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
42786diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
42787index 2c0d0ec..4e8681a 100644
42788--- a/drivers/scsi/scsi.c
42789+++ b/drivers/scsi/scsi.c
42790@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
42791 unsigned long timeout;
42792 int rtn = 0;
42793
42794- atomic_inc(&cmd->device->iorequest_cnt);
42795+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42796
42797 /* check if the device is still usable */
42798 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
42799diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
42800index 86d5220..f22c51a 100644
42801--- a/drivers/scsi/scsi_lib.c
42802+++ b/drivers/scsi/scsi_lib.c
42803@@ -1458,7 +1458,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
42804 shost = sdev->host;
42805 scsi_init_cmd_errh(cmd);
42806 cmd->result = DID_NO_CONNECT << 16;
42807- atomic_inc(&cmd->device->iorequest_cnt);
42808+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42809
42810 /*
42811 * SCSI request completion path will do scsi_device_unbusy(),
42812@@ -1484,9 +1484,9 @@ static void scsi_softirq_done(struct request *rq)
42813
42814 INIT_LIST_HEAD(&cmd->eh_entry);
42815
42816- atomic_inc(&cmd->device->iodone_cnt);
42817+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
42818 if (cmd->result)
42819- atomic_inc(&cmd->device->ioerr_cnt);
42820+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
42821
42822 disposition = scsi_decide_disposition(cmd);
42823 if (disposition != SUCCESS &&
42824diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
42825index 931a7d9..0c2a754 100644
42826--- a/drivers/scsi/scsi_sysfs.c
42827+++ b/drivers/scsi/scsi_sysfs.c
42828@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
42829 char *buf) \
42830 { \
42831 struct scsi_device *sdev = to_scsi_device(dev); \
42832- unsigned long long count = atomic_read(&sdev->field); \
42833+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
42834 return snprintf(buf, 20, "0x%llx\n", count); \
42835 } \
42836 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
42837diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
42838index 84a1fdf..693b0d6 100644
42839--- a/drivers/scsi/scsi_tgt_lib.c
42840+++ b/drivers/scsi/scsi_tgt_lib.c
42841@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
42842 int err;
42843
42844 dprintk("%lx %u\n", uaddr, len);
42845- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
42846+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
42847 if (err) {
42848 /*
42849 * TODO: need to fixup sg_tablesize, max_segment_size,
42850diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42851index e106c27..11a380e 100644
42852--- a/drivers/scsi/scsi_transport_fc.c
42853+++ b/drivers/scsi/scsi_transport_fc.c
42854@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42855 * Netlink Infrastructure
42856 */
42857
42858-static atomic_t fc_event_seq;
42859+static atomic_unchecked_t fc_event_seq;
42860
42861 /**
42862 * fc_get_event_number - Obtain the next sequential FC event number
42863@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
42864 u32
42865 fc_get_event_number(void)
42866 {
42867- return atomic_add_return(1, &fc_event_seq);
42868+ return atomic_add_return_unchecked(1, &fc_event_seq);
42869 }
42870 EXPORT_SYMBOL(fc_get_event_number);
42871
42872@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
42873 {
42874 int error;
42875
42876- atomic_set(&fc_event_seq, 0);
42877+ atomic_set_unchecked(&fc_event_seq, 0);
42878
42879 error = transport_class_register(&fc_host_class);
42880 if (error)
42881@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42882 char *cp;
42883
42884 *val = simple_strtoul(buf, &cp, 0);
42885- if ((*cp && (*cp != '\n')) || (*val < 0))
42886+ if (*cp && (*cp != '\n'))
42887 return -EINVAL;
42888 /*
42889 * Check for overflow; dev_loss_tmo is u32
42890diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42891index 133926b..903000d 100644
42892--- a/drivers/scsi/scsi_transport_iscsi.c
42893+++ b/drivers/scsi/scsi_transport_iscsi.c
42894@@ -80,7 +80,7 @@ struct iscsi_internal {
42895 struct transport_container session_cont;
42896 };
42897
42898-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42899+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42900 static struct workqueue_struct *iscsi_eh_timer_workq;
42901
42902 static DEFINE_IDA(iscsi_sess_ida);
42903@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42904 int err;
42905
42906 ihost = shost->shost_data;
42907- session->sid = atomic_add_return(1, &iscsi_session_nr);
42908+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42909
42910 if (target_id == ISCSI_MAX_TARGET) {
42911 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42912@@ -3944,7 +3944,7 @@ static __init int iscsi_transport_init(void)
42913 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42914 ISCSI_TRANSPORT_VERSION);
42915
42916- atomic_set(&iscsi_session_nr, 0);
42917+ atomic_set_unchecked(&iscsi_session_nr, 0);
42918
42919 err = class_register(&iscsi_transport_class);
42920 if (err)
42921diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42922index f379c7f..e8fc69c 100644
42923--- a/drivers/scsi/scsi_transport_srp.c
42924+++ b/drivers/scsi/scsi_transport_srp.c
42925@@ -33,7 +33,7 @@
42926 #include "scsi_transport_srp_internal.h"
42927
42928 struct srp_host_attrs {
42929- atomic_t next_port_id;
42930+ atomic_unchecked_t next_port_id;
42931 };
42932 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42933
42934@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42935 struct Scsi_Host *shost = dev_to_shost(dev);
42936 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42937
42938- atomic_set(&srp_host->next_port_id, 0);
42939+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42940 return 0;
42941 }
42942
42943@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42944 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42945 rport->roles = ids->roles;
42946
42947- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42948+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42949 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42950
42951 transport_setup_device(&rport->dev);
42952diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42953index 6f6a1b4..80704a9 100644
42954--- a/drivers/scsi/sd.c
42955+++ b/drivers/scsi/sd.c
42956@@ -2918,7 +2918,7 @@ static int sd_probe(struct device *dev)
42957 sdkp->disk = gd;
42958 sdkp->index = index;
42959 atomic_set(&sdkp->openers, 0);
42960- atomic_set(&sdkp->device->ioerr_cnt, 0);
42961+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42962
42963 if (!sdp->request_queue->rq_timeout) {
42964 if (sdp->type != TYPE_MOD)
42965diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42966index df5e961..df6b97f 100644
42967--- a/drivers/scsi/sg.c
42968+++ b/drivers/scsi/sg.c
42969@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42970 sdp->disk->disk_name,
42971 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42972 NULL,
42973- (char *)arg);
42974+ (char __user *)arg);
42975 case BLKTRACESTART:
42976 return blk_trace_startstop(sdp->device->request_queue, 1);
42977 case BLKTRACESTOP:
42978diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42979index 32b7bb1..2f1c4bd 100644
42980--- a/drivers/spi/spi.c
42981+++ b/drivers/spi/spi.c
42982@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
42983 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42984
42985 /* portable code must never pass more than 32 bytes */
42986-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42987+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42988
42989 static u8 *buf;
42990
42991diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
42992index 3675020..e80d92c 100644
42993--- a/drivers/staging/media/solo6x10/solo6x10-core.c
42994+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
42995@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
42996
42997 static int solo_sysfs_init(struct solo_dev *solo_dev)
42998 {
42999- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
43000+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
43001 struct device *dev = &solo_dev->dev;
43002 const char *driver;
43003 int i;
43004diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
43005index 34afc16..ffe44dd 100644
43006--- a/drivers/staging/octeon/ethernet-rx.c
43007+++ b/drivers/staging/octeon/ethernet-rx.c
43008@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
43009 /* Increment RX stats for virtual ports */
43010 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
43011 #ifdef CONFIG_64BIT
43012- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
43013- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
43014+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
43015+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
43016 #else
43017- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
43018- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
43019+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
43020+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
43021 #endif
43022 }
43023 netif_receive_skb(skb);
43024@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
43025 dev->name);
43026 */
43027 #ifdef CONFIG_64BIT
43028- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
43029+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
43030 #else
43031- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
43032+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
43033 #endif
43034 dev_kfree_skb_irq(skb);
43035 }
43036diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
43037index c3a90e7..023619a 100644
43038--- a/drivers/staging/octeon/ethernet.c
43039+++ b/drivers/staging/octeon/ethernet.c
43040@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
43041 * since the RX tasklet also increments it.
43042 */
43043 #ifdef CONFIG_64BIT
43044- atomic64_add(rx_status.dropped_packets,
43045- (atomic64_t *)&priv->stats.rx_dropped);
43046+ atomic64_add_unchecked(rx_status.dropped_packets,
43047+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
43048 #else
43049- atomic_add(rx_status.dropped_packets,
43050- (atomic_t *)&priv->stats.rx_dropped);
43051+ atomic_add_unchecked(rx_status.dropped_packets,
43052+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
43053 #endif
43054 }
43055
43056diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
43057index dc23395..cf7e9b1 100644
43058--- a/drivers/staging/rtl8712/rtl871x_io.h
43059+++ b/drivers/staging/rtl8712/rtl871x_io.h
43060@@ -108,7 +108,7 @@ struct _io_ops {
43061 u8 *pmem);
43062 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
43063 u8 *pmem);
43064-};
43065+} __no_const;
43066
43067 struct io_req {
43068 struct list_head list;
43069diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
43070index 1f5088b..0e59820 100644
43071--- a/drivers/staging/sbe-2t3e3/netdev.c
43072+++ b/drivers/staging/sbe-2t3e3/netdev.c
43073@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43074 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
43075
43076 if (rlen)
43077- if (copy_to_user(data, &resp, rlen))
43078+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
43079 return -EFAULT;
43080
43081 return 0;
43082diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
43083index a863a98..d272795 100644
43084--- a/drivers/staging/usbip/vhci.h
43085+++ b/drivers/staging/usbip/vhci.h
43086@@ -83,7 +83,7 @@ struct vhci_hcd {
43087 unsigned resuming:1;
43088 unsigned long re_timeout;
43089
43090- atomic_t seqnum;
43091+ atomic_unchecked_t seqnum;
43092
43093 /*
43094 * NOTE:
43095diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
43096index d7974cb..d78076b 100644
43097--- a/drivers/staging/usbip/vhci_hcd.c
43098+++ b/drivers/staging/usbip/vhci_hcd.c
43099@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
43100
43101 spin_lock(&vdev->priv_lock);
43102
43103- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
43104+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43105 if (priv->seqnum == 0xffff)
43106 dev_info(&urb->dev->dev, "seqnum max\n");
43107
43108@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
43109 return -ENOMEM;
43110 }
43111
43112- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
43113+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43114 if (unlink->seqnum == 0xffff)
43115 pr_info("seqnum max\n");
43116
43117@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
43118 vdev->rhport = rhport;
43119 }
43120
43121- atomic_set(&vhci->seqnum, 0);
43122+ atomic_set_unchecked(&vhci->seqnum, 0);
43123 spin_lock_init(&vhci->lock);
43124
43125 hcd->power_budget = 0; /* no limit */
43126diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
43127index d07fcb5..358e1e1 100644
43128--- a/drivers/staging/usbip/vhci_rx.c
43129+++ b/drivers/staging/usbip/vhci_rx.c
43130@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
43131 if (!urb) {
43132 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
43133 pr_info("max seqnum %d\n",
43134- atomic_read(&the_controller->seqnum));
43135+ atomic_read_unchecked(&the_controller->seqnum));
43136 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
43137 return;
43138 }
43139diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
43140index 8417c2f..ef5ebd6 100644
43141--- a/drivers/staging/vt6655/hostap.c
43142+++ b/drivers/staging/vt6655/hostap.c
43143@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
43144 *
43145 */
43146
43147+static net_device_ops_no_const apdev_netdev_ops;
43148+
43149 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43150 {
43151 PSDevice apdev_priv;
43152 struct net_device *dev = pDevice->dev;
43153 int ret;
43154- const struct net_device_ops apdev_netdev_ops = {
43155- .ndo_start_xmit = pDevice->tx_80211,
43156- };
43157
43158 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43159
43160@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43161 *apdev_priv = *pDevice;
43162 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43163
43164+ /* only half broken now */
43165+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43166 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43167
43168 pDevice->apdev->type = ARPHRD_IEEE80211;
43169diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
43170index c699a30..b90a5fd 100644
43171--- a/drivers/staging/vt6656/hostap.c
43172+++ b/drivers/staging/vt6656/hostap.c
43173@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
43174 *
43175 */
43176
43177+static net_device_ops_no_const apdev_netdev_ops;
43178+
43179 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
43180 {
43181 struct vnt_private *apdev_priv;
43182 struct net_device *dev = pDevice->dev;
43183 int ret;
43184- const struct net_device_ops apdev_netdev_ops = {
43185- .ndo_start_xmit = pDevice->tx_80211,
43186- };
43187
43188 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43189
43190@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
43191 *apdev_priv = *pDevice;
43192 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43193
43194+ /* only half broken now */
43195+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43196 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43197
43198 pDevice->apdev->type = ARPHRD_IEEE80211;
43199diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
43200index d7e51e4..d07eaab 100644
43201--- a/drivers/staging/zcache/tmem.c
43202+++ b/drivers/staging/zcache/tmem.c
43203@@ -51,7 +51,7 @@
43204 * A tmem host implementation must use this function to register callbacks
43205 * for memory allocation.
43206 */
43207-static struct tmem_hostops tmem_hostops;
43208+static tmem_hostops_no_const tmem_hostops;
43209
43210 static void tmem_objnode_tree_init(void);
43211
43212@@ -65,7 +65,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
43213 * A tmem host implementation must use this function to register
43214 * callbacks for a page-accessible memory (PAM) implementation.
43215 */
43216-static struct tmem_pamops tmem_pamops;
43217+static tmem_pamops_no_const tmem_pamops;
43218
43219 void tmem_register_pamops(struct tmem_pamops *m)
43220 {
43221diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
43222index d128ce2..a43980c 100644
43223--- a/drivers/staging/zcache/tmem.h
43224+++ b/drivers/staging/zcache/tmem.h
43225@@ -226,6 +226,7 @@ struct tmem_pamops {
43226 int (*replace_in_obj)(void *, struct tmem_obj *);
43227 #endif
43228 };
43229+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
43230 extern void tmem_register_pamops(struct tmem_pamops *m);
43231
43232 /* memory allocation methods provided by the host implementation */
43233@@ -235,6 +236,7 @@ struct tmem_hostops {
43234 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
43235 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
43236 };
43237+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
43238 extern void tmem_register_hostops(struct tmem_hostops *m);
43239
43240 /* core tmem accessor functions */
43241diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
43242index 4630481..c26782a 100644
43243--- a/drivers/target/target_core_device.c
43244+++ b/drivers/target/target_core_device.c
43245@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
43246 spin_lock_init(&dev->se_port_lock);
43247 spin_lock_init(&dev->se_tmr_lock);
43248 spin_lock_init(&dev->qf_cmd_lock);
43249- atomic_set(&dev->dev_ordered_id, 0);
43250+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
43251 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
43252 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
43253 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
43254diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
43255index 21e3158..43c6004 100644
43256--- a/drivers/target/target_core_transport.c
43257+++ b/drivers/target/target_core_transport.c
43258@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
43259 * Used to determine when ORDERED commands should go from
43260 * Dormant to Active status.
43261 */
43262- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
43263+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
43264 smp_mb__after_atomic_inc();
43265 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
43266 cmd->se_ordered_id, cmd->sam_task_attr,
43267diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
43268index 33f83fe..d80f8e1 100644
43269--- a/drivers/tty/cyclades.c
43270+++ b/drivers/tty/cyclades.c
43271@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
43272 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
43273 info->port.count);
43274 #endif
43275- info->port.count++;
43276+ atomic_inc(&info->port.count);
43277 #ifdef CY_DEBUG_COUNT
43278 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
43279- current->pid, info->port.count);
43280+ current->pid, atomic_read(&info->port.count));
43281 #endif
43282
43283 /*
43284@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
43285 for (j = 0; j < cy_card[i].nports; j++) {
43286 info = &cy_card[i].ports[j];
43287
43288- if (info->port.count) {
43289+ if (atomic_read(&info->port.count)) {
43290 /* XXX is the ldisc num worth this? */
43291 struct tty_struct *tty;
43292 struct tty_ldisc *ld;
43293diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
43294index eb255e8..f637a57 100644
43295--- a/drivers/tty/hvc/hvc_console.c
43296+++ b/drivers/tty/hvc/hvc_console.c
43297@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
43298
43299 spin_lock_irqsave(&hp->port.lock, flags);
43300 /* Check and then increment for fast path open. */
43301- if (hp->port.count++ > 0) {
43302+ if (atomic_inc_return(&hp->port.count) > 1) {
43303 spin_unlock_irqrestore(&hp->port.lock, flags);
43304 hvc_kick();
43305 return 0;
43306@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43307
43308 spin_lock_irqsave(&hp->port.lock, flags);
43309
43310- if (--hp->port.count == 0) {
43311+ if (atomic_dec_return(&hp->port.count) == 0) {
43312 spin_unlock_irqrestore(&hp->port.lock, flags);
43313 /* We are done with the tty pointer now. */
43314 tty_port_tty_set(&hp->port, NULL);
43315@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43316 */
43317 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
43318 } else {
43319- if (hp->port.count < 0)
43320+ if (atomic_read(&hp->port.count) < 0)
43321 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
43322- hp->vtermno, hp->port.count);
43323+ hp->vtermno, atomic_read(&hp->port.count));
43324 spin_unlock_irqrestore(&hp->port.lock, flags);
43325 }
43326 }
43327@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
43328 * open->hangup case this can be called after the final close so prevent
43329 * that from happening for now.
43330 */
43331- if (hp->port.count <= 0) {
43332+ if (atomic_read(&hp->port.count) <= 0) {
43333 spin_unlock_irqrestore(&hp->port.lock, flags);
43334 return;
43335 }
43336
43337- hp->port.count = 0;
43338+ atomic_set(&hp->port.count, 0);
43339 spin_unlock_irqrestore(&hp->port.lock, flags);
43340 tty_port_tty_set(&hp->port, NULL);
43341
43342@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
43343 return -EPIPE;
43344
43345 /* FIXME what's this (unprotected) check for? */
43346- if (hp->port.count <= 0)
43347+ if (atomic_read(&hp->port.count) <= 0)
43348 return -EIO;
43349
43350 spin_lock_irqsave(&hp->lock, flags);
43351diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
43352index 81e939e..95ead10 100644
43353--- a/drivers/tty/hvc/hvcs.c
43354+++ b/drivers/tty/hvc/hvcs.c
43355@@ -83,6 +83,7 @@
43356 #include <asm/hvcserver.h>
43357 #include <asm/uaccess.h>
43358 #include <asm/vio.h>
43359+#include <asm/local.h>
43360
43361 /*
43362 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
43363@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
43364
43365 spin_lock_irqsave(&hvcsd->lock, flags);
43366
43367- if (hvcsd->port.count > 0) {
43368+ if (atomic_read(&hvcsd->port.count) > 0) {
43369 spin_unlock_irqrestore(&hvcsd->lock, flags);
43370 printk(KERN_INFO "HVCS: vterm state unchanged. "
43371 "The hvcs device node is still in use.\n");
43372@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
43373 }
43374 }
43375
43376- hvcsd->port.count = 0;
43377+ atomic_set(&hvcsd->port.count, 0);
43378 hvcsd->port.tty = tty;
43379 tty->driver_data = hvcsd;
43380
43381@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
43382 unsigned long flags;
43383
43384 spin_lock_irqsave(&hvcsd->lock, flags);
43385- hvcsd->port.count++;
43386+ atomic_inc(&hvcsd->port.count);
43387 hvcsd->todo_mask |= HVCS_SCHED_READ;
43388 spin_unlock_irqrestore(&hvcsd->lock, flags);
43389
43390@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43391 hvcsd = tty->driver_data;
43392
43393 spin_lock_irqsave(&hvcsd->lock, flags);
43394- if (--hvcsd->port.count == 0) {
43395+ if (atomic_dec_and_test(&hvcsd->port.count)) {
43396
43397 vio_disable_interrupts(hvcsd->vdev);
43398
43399@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43400
43401 free_irq(irq, hvcsd);
43402 return;
43403- } else if (hvcsd->port.count < 0) {
43404+ } else if (atomic_read(&hvcsd->port.count) < 0) {
43405 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
43406 " is missmanaged.\n",
43407- hvcsd->vdev->unit_address, hvcsd->port.count);
43408+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
43409 }
43410
43411 spin_unlock_irqrestore(&hvcsd->lock, flags);
43412@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43413
43414 spin_lock_irqsave(&hvcsd->lock, flags);
43415 /* Preserve this so that we know how many kref refs to put */
43416- temp_open_count = hvcsd->port.count;
43417+ temp_open_count = atomic_read(&hvcsd->port.count);
43418
43419 /*
43420 * Don't kref put inside the spinlock because the destruction
43421@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43422 tty->driver_data = NULL;
43423 hvcsd->port.tty = NULL;
43424
43425- hvcsd->port.count = 0;
43426+ atomic_set(&hvcsd->port.count, 0);
43427
43428 /* This will drop any buffered data on the floor which is OK in a hangup
43429 * scenario. */
43430@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
43431 * the middle of a write operation? This is a crummy place to do this
43432 * but we want to keep it all in the spinlock.
43433 */
43434- if (hvcsd->port.count <= 0) {
43435+ if (atomic_read(&hvcsd->port.count) <= 0) {
43436 spin_unlock_irqrestore(&hvcsd->lock, flags);
43437 return -ENODEV;
43438 }
43439@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
43440 {
43441 struct hvcs_struct *hvcsd = tty->driver_data;
43442
43443- if (!hvcsd || hvcsd->port.count <= 0)
43444+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
43445 return 0;
43446
43447 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
43448diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
43449index 8fd72ff..34a0bed 100644
43450--- a/drivers/tty/ipwireless/tty.c
43451+++ b/drivers/tty/ipwireless/tty.c
43452@@ -29,6 +29,7 @@
43453 #include <linux/tty_driver.h>
43454 #include <linux/tty_flip.h>
43455 #include <linux/uaccess.h>
43456+#include <asm/local.h>
43457
43458 #include "tty.h"
43459 #include "network.h"
43460@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43461 mutex_unlock(&tty->ipw_tty_mutex);
43462 return -ENODEV;
43463 }
43464- if (tty->port.count == 0)
43465+ if (atomic_read(&tty->port.count) == 0)
43466 tty->tx_bytes_queued = 0;
43467
43468- tty->port.count++;
43469+ atomic_inc(&tty->port.count);
43470
43471 tty->port.tty = linux_tty;
43472 linux_tty->driver_data = tty;
43473@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43474
43475 static void do_ipw_close(struct ipw_tty *tty)
43476 {
43477- tty->port.count--;
43478-
43479- if (tty->port.count == 0) {
43480+ if (atomic_dec_return(&tty->port.count) == 0) {
43481 struct tty_struct *linux_tty = tty->port.tty;
43482
43483 if (linux_tty != NULL) {
43484@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
43485 return;
43486
43487 mutex_lock(&tty->ipw_tty_mutex);
43488- if (tty->port.count == 0) {
43489+ if (atomic_read(&tty->port.count) == 0) {
43490 mutex_unlock(&tty->ipw_tty_mutex);
43491 return;
43492 }
43493@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
43494
43495 mutex_lock(&tty->ipw_tty_mutex);
43496
43497- if (!tty->port.count) {
43498+ if (!atomic_read(&tty->port.count)) {
43499 mutex_unlock(&tty->ipw_tty_mutex);
43500 return;
43501 }
43502@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
43503 return -ENODEV;
43504
43505 mutex_lock(&tty->ipw_tty_mutex);
43506- if (!tty->port.count) {
43507+ if (!atomic_read(&tty->port.count)) {
43508 mutex_unlock(&tty->ipw_tty_mutex);
43509 return -EINVAL;
43510 }
43511@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
43512 if (!tty)
43513 return -ENODEV;
43514
43515- if (!tty->port.count)
43516+ if (!atomic_read(&tty->port.count))
43517 return -EINVAL;
43518
43519 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
43520@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
43521 if (!tty)
43522 return 0;
43523
43524- if (!tty->port.count)
43525+ if (!atomic_read(&tty->port.count))
43526 return 0;
43527
43528 return tty->tx_bytes_queued;
43529@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
43530 if (!tty)
43531 return -ENODEV;
43532
43533- if (!tty->port.count)
43534+ if (!atomic_read(&tty->port.count))
43535 return -EINVAL;
43536
43537 return get_control_lines(tty);
43538@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
43539 if (!tty)
43540 return -ENODEV;
43541
43542- if (!tty->port.count)
43543+ if (!atomic_read(&tty->port.count))
43544 return -EINVAL;
43545
43546 return set_control_lines(tty, set, clear);
43547@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
43548 if (!tty)
43549 return -ENODEV;
43550
43551- if (!tty->port.count)
43552+ if (!atomic_read(&tty->port.count))
43553 return -EINVAL;
43554
43555 /* FIXME: Exactly how is the tty object locked here .. */
43556@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
43557 * are gone */
43558 mutex_lock(&ttyj->ipw_tty_mutex);
43559 }
43560- while (ttyj->port.count)
43561+ while (atomic_read(&ttyj->port.count))
43562 do_ipw_close(ttyj);
43563 ipwireless_disassociate_network_ttys(network,
43564 ttyj->channel_idx);
43565diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
43566index 1deaca4..c8582d4 100644
43567--- a/drivers/tty/moxa.c
43568+++ b/drivers/tty/moxa.c
43569@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
43570 }
43571
43572 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
43573- ch->port.count++;
43574+ atomic_inc(&ch->port.count);
43575 tty->driver_data = ch;
43576 tty_port_tty_set(&ch->port, tty);
43577 mutex_lock(&ch->port.mutex);
43578diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
43579index 6422390..49003ac8 100644
43580--- a/drivers/tty/n_gsm.c
43581+++ b/drivers/tty/n_gsm.c
43582@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
43583 spin_lock_init(&dlci->lock);
43584 mutex_init(&dlci->mutex);
43585 dlci->fifo = &dlci->_fifo;
43586- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
43587+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
43588 kfree(dlci);
43589 return NULL;
43590 }
43591@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
43592 struct gsm_dlci *dlci = tty->driver_data;
43593 struct tty_port *port = &dlci->port;
43594
43595- port->count++;
43596+ atomic_inc(&port->count);
43597 dlci_get(dlci);
43598 dlci_get(dlci->gsm->dlci[0]);
43599 mux_get(dlci->gsm);
43600diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
43601index 6c7fe90..9241dab 100644
43602--- a/drivers/tty/n_tty.c
43603+++ b/drivers/tty/n_tty.c
43604@@ -2203,6 +2203,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
43605 {
43606 *ops = tty_ldisc_N_TTY;
43607 ops->owner = NULL;
43608- ops->refcount = ops->flags = 0;
43609+ atomic_set(&ops->refcount, 0);
43610+ ops->flags = 0;
43611 }
43612 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
43613diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
43614index abfd990..5ab5da9 100644
43615--- a/drivers/tty/pty.c
43616+++ b/drivers/tty/pty.c
43617@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
43618 panic("Couldn't register Unix98 pts driver");
43619
43620 /* Now create the /dev/ptmx special device */
43621+ pax_open_kernel();
43622 tty_default_fops(&ptmx_fops);
43623- ptmx_fops.open = ptmx_open;
43624+ *(void **)&ptmx_fops.open = ptmx_open;
43625+ pax_close_kernel();
43626
43627 cdev_init(&ptmx_cdev, &ptmx_fops);
43628 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43629diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43630index 354564e..fe50d9a 100644
43631--- a/drivers/tty/rocket.c
43632+++ b/drivers/tty/rocket.c
43633@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43634 tty->driver_data = info;
43635 tty_port_tty_set(port, tty);
43636
43637- if (port->count++ == 0) {
43638+ if (atomic_inc_return(&port->count) == 1) {
43639 atomic_inc(&rp_num_ports_open);
43640
43641 #ifdef ROCKET_DEBUG_OPEN
43642@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43643 #endif
43644 }
43645 #ifdef ROCKET_DEBUG_OPEN
43646- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43647+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43648 #endif
43649
43650 /*
43651@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
43652 spin_unlock_irqrestore(&info->port.lock, flags);
43653 return;
43654 }
43655- if (info->port.count)
43656+ if (atomic_read(&info->port.count))
43657 atomic_dec(&rp_num_ports_open);
43658 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43659 spin_unlock_irqrestore(&info->port.lock, flags);
43660diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43661index 1002054..dd644a8 100644
43662--- a/drivers/tty/serial/kgdboc.c
43663+++ b/drivers/tty/serial/kgdboc.c
43664@@ -24,8 +24,9 @@
43665 #define MAX_CONFIG_LEN 40
43666
43667 static struct kgdb_io kgdboc_io_ops;
43668+static struct kgdb_io kgdboc_io_ops_console;
43669
43670-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43671+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43672 static int configured = -1;
43673
43674 static char config[MAX_CONFIG_LEN];
43675@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43676 kgdboc_unregister_kbd();
43677 if (configured == 1)
43678 kgdb_unregister_io_module(&kgdboc_io_ops);
43679+ else if (configured == 2)
43680+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43681 }
43682
43683 static int configure_kgdboc(void)
43684@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43685 int err;
43686 char *cptr = config;
43687 struct console *cons;
43688+ int is_console = 0;
43689
43690 err = kgdboc_option_setup(config);
43691 if (err || !strlen(config) || isspace(config[0]))
43692 goto noconfig;
43693
43694 err = -ENODEV;
43695- kgdboc_io_ops.is_console = 0;
43696 kgdb_tty_driver = NULL;
43697
43698 kgdboc_use_kms = 0;
43699@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43700 int idx;
43701 if (cons->device && cons->device(cons, &idx) == p &&
43702 idx == tty_line) {
43703- kgdboc_io_ops.is_console = 1;
43704+ is_console = 1;
43705 break;
43706 }
43707 cons = cons->next;
43708@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43709 kgdb_tty_line = tty_line;
43710
43711 do_register:
43712- err = kgdb_register_io_module(&kgdboc_io_ops);
43713+ if (is_console) {
43714+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43715+ configured = 2;
43716+ } else {
43717+ err = kgdb_register_io_module(&kgdboc_io_ops);
43718+ configured = 1;
43719+ }
43720 if (err)
43721 goto noconfig;
43722
43723@@ -205,8 +214,6 @@ do_register:
43724 if (err)
43725 goto nmi_con_failed;
43726
43727- configured = 1;
43728-
43729 return 0;
43730
43731 nmi_con_failed:
43732@@ -223,7 +230,7 @@ noconfig:
43733 static int __init init_kgdboc(void)
43734 {
43735 /* Already configured? */
43736- if (configured == 1)
43737+ if (configured >= 1)
43738 return 0;
43739
43740 return configure_kgdboc();
43741@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43742 if (config[len - 1] == '\n')
43743 config[len - 1] = '\0';
43744
43745- if (configured == 1)
43746+ if (configured >= 1)
43747 cleanup_kgdboc();
43748
43749 /* Go and configure with the new params. */
43750@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43751 .post_exception = kgdboc_post_exp_handler,
43752 };
43753
43754+static struct kgdb_io kgdboc_io_ops_console = {
43755+ .name = "kgdboc",
43756+ .read_char = kgdboc_get_char,
43757+ .write_char = kgdboc_put_char,
43758+ .pre_exception = kgdboc_pre_exp_handler,
43759+ .post_exception = kgdboc_post_exp_handler,
43760+ .is_console = 1
43761+};
43762+
43763 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43764 /* This is only available if kgdboc is a built in for early debugging */
43765 static int __init kgdboc_early_init(char *opt)
43766diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43767index 0c8a9fa..234a95f 100644
43768--- a/drivers/tty/serial/samsung.c
43769+++ b/drivers/tty/serial/samsung.c
43770@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43771 }
43772 }
43773
43774+static int s3c64xx_serial_startup(struct uart_port *port);
43775 static int s3c24xx_serial_startup(struct uart_port *port)
43776 {
43777 struct s3c24xx_uart_port *ourport = to_ourport(port);
43778 int ret;
43779
43780+ /* Startup sequence is different for s3c64xx and higher SoC's */
43781+ if (s3c24xx_serial_has_interrupt_mask(port))
43782+ return s3c64xx_serial_startup(port);
43783+
43784 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43785 port->mapbase, port->membase);
43786
43787@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43788 /* setup info for port */
43789 port->dev = &platdev->dev;
43790
43791- /* Startup sequence is different for s3c64xx and higher SoC's */
43792- if (s3c24xx_serial_has_interrupt_mask(port))
43793- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43794-
43795 port->uartclk = 1;
43796
43797 if (cfg->uart_flags & UPF_CONS_FLOW) {
43798diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43799index f87dbfd..42ad4b1 100644
43800--- a/drivers/tty/serial/serial_core.c
43801+++ b/drivers/tty/serial/serial_core.c
43802@@ -1454,7 +1454,7 @@ static void uart_hangup(struct tty_struct *tty)
43803 uart_flush_buffer(tty);
43804 uart_shutdown(tty, state);
43805 spin_lock_irqsave(&port->lock, flags);
43806- port->count = 0;
43807+ atomic_set(&port->count, 0);
43808 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43809 spin_unlock_irqrestore(&port->lock, flags);
43810 tty_port_tty_set(port, NULL);
43811@@ -1550,7 +1550,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43812 goto end;
43813 }
43814
43815- port->count++;
43816+ atomic_inc(&port->count);
43817 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43818 retval = -ENXIO;
43819 goto err_dec_count;
43820@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43821 /*
43822 * Make sure the device is in D0 state.
43823 */
43824- if (port->count == 1)
43825+ if (atomic_read(&port->count) == 1)
43826 uart_change_pm(state, UART_PM_STATE_ON);
43827
43828 /*
43829@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43830 end:
43831 return retval;
43832 err_dec_count:
43833- port->count--;
43834+ atomic_inc(&port->count);
43835 mutex_unlock(&port->mutex);
43836 goto end;
43837 }
43838diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43839index 8eaf1ab..85c030d 100644
43840--- a/drivers/tty/synclink.c
43841+++ b/drivers/tty/synclink.c
43842@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43843
43844 if (debug_level >= DEBUG_LEVEL_INFO)
43845 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43846- __FILE__,__LINE__, info->device_name, info->port.count);
43847+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43848
43849 if (tty_port_close_start(&info->port, tty, filp) == 0)
43850 goto cleanup;
43851@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43852 cleanup:
43853 if (debug_level >= DEBUG_LEVEL_INFO)
43854 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43855- tty->driver->name, info->port.count);
43856+ tty->driver->name, atomic_read(&info->port.count));
43857
43858 } /* end of mgsl_close() */
43859
43860@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43861
43862 mgsl_flush_buffer(tty);
43863 shutdown(info);
43864-
43865- info->port.count = 0;
43866+
43867+ atomic_set(&info->port.count, 0);
43868 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43869 info->port.tty = NULL;
43870
43871@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43872
43873 if (debug_level >= DEBUG_LEVEL_INFO)
43874 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43875- __FILE__,__LINE__, tty->driver->name, port->count );
43876+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43877
43878 spin_lock_irqsave(&info->irq_spinlock, flags);
43879 if (!tty_hung_up_p(filp)) {
43880 extra_count = true;
43881- port->count--;
43882+ atomic_dec(&port->count);
43883 }
43884 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43885 port->blocked_open++;
43886@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43887
43888 if (debug_level >= DEBUG_LEVEL_INFO)
43889 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43890- __FILE__,__LINE__, tty->driver->name, port->count );
43891+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43892
43893 tty_unlock(tty);
43894 schedule();
43895@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43896
43897 /* FIXME: Racy on hangup during close wait */
43898 if (extra_count)
43899- port->count++;
43900+ atomic_inc(&port->count);
43901 port->blocked_open--;
43902
43903 if (debug_level >= DEBUG_LEVEL_INFO)
43904 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43905- __FILE__,__LINE__, tty->driver->name, port->count );
43906+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43907
43908 if (!retval)
43909 port->flags |= ASYNC_NORMAL_ACTIVE;
43910@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43911
43912 if (debug_level >= DEBUG_LEVEL_INFO)
43913 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
43914- __FILE__,__LINE__,tty->driver->name, info->port.count);
43915+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43916
43917 /* If port is closing, signal caller to try again */
43918 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43919@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43920 spin_unlock_irqrestore(&info->netlock, flags);
43921 goto cleanup;
43922 }
43923- info->port.count++;
43924+ atomic_inc(&info->port.count);
43925 spin_unlock_irqrestore(&info->netlock, flags);
43926
43927- if (info->port.count == 1) {
43928+ if (atomic_read(&info->port.count) == 1) {
43929 /* 1st open on this device, init hardware */
43930 retval = startup(info);
43931 if (retval < 0)
43932@@ -3446,8 +3446,8 @@ cleanup:
43933 if (retval) {
43934 if (tty->count == 1)
43935 info->port.tty = NULL; /* tty layer will release tty struct */
43936- if(info->port.count)
43937- info->port.count--;
43938+ if (atomic_read(&info->port.count))
43939+ atomic_dec(&info->port.count);
43940 }
43941
43942 return retval;
43943@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43944 unsigned short new_crctype;
43945
43946 /* return error if TTY interface open */
43947- if (info->port.count)
43948+ if (atomic_read(&info->port.count))
43949 return -EBUSY;
43950
43951 switch (encoding)
43952@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
43953
43954 /* arbitrate between network and tty opens */
43955 spin_lock_irqsave(&info->netlock, flags);
43956- if (info->port.count != 0 || info->netcount != 0) {
43957+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43958 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43959 spin_unlock_irqrestore(&info->netlock, flags);
43960 return -EBUSY;
43961@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43962 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43963
43964 /* return error if TTY interface open */
43965- if (info->port.count)
43966+ if (atomic_read(&info->port.count))
43967 return -EBUSY;
43968
43969 if (cmd != SIOCWANDEV)
43970diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
43971index 1abf946..1ee34fc 100644
43972--- a/drivers/tty/synclink_gt.c
43973+++ b/drivers/tty/synclink_gt.c
43974@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43975 tty->driver_data = info;
43976 info->port.tty = tty;
43977
43978- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
43979+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
43980
43981 /* If port is closing, signal caller to try again */
43982 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43983@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43984 mutex_unlock(&info->port.mutex);
43985 goto cleanup;
43986 }
43987- info->port.count++;
43988+ atomic_inc(&info->port.count);
43989 spin_unlock_irqrestore(&info->netlock, flags);
43990
43991- if (info->port.count == 1) {
43992+ if (atomic_read(&info->port.count) == 1) {
43993 /* 1st open on this device, init hardware */
43994 retval = startup(info);
43995 if (retval < 0) {
43996@@ -715,8 +715,8 @@ cleanup:
43997 if (retval) {
43998 if (tty->count == 1)
43999 info->port.tty = NULL; /* tty layer will release tty struct */
44000- if(info->port.count)
44001- info->port.count--;
44002+ if(atomic_read(&info->port.count))
44003+ atomic_dec(&info->port.count);
44004 }
44005
44006 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
44007@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44008
44009 if (sanity_check(info, tty->name, "close"))
44010 return;
44011- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
44012+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
44013
44014 if (tty_port_close_start(&info->port, tty, filp) == 0)
44015 goto cleanup;
44016@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44017 tty_port_close_end(&info->port, tty);
44018 info->port.tty = NULL;
44019 cleanup:
44020- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
44021+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
44022 }
44023
44024 static void hangup(struct tty_struct *tty)
44025@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
44026 shutdown(info);
44027
44028 spin_lock_irqsave(&info->port.lock, flags);
44029- info->port.count = 0;
44030+ atomic_set(&info->port.count, 0);
44031 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44032 info->port.tty = NULL;
44033 spin_unlock_irqrestore(&info->port.lock, flags);
44034@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44035 unsigned short new_crctype;
44036
44037 /* return error if TTY interface open */
44038- if (info->port.count)
44039+ if (atomic_read(&info->port.count))
44040 return -EBUSY;
44041
44042 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
44043@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
44044
44045 /* arbitrate between network and tty opens */
44046 spin_lock_irqsave(&info->netlock, flags);
44047- if (info->port.count != 0 || info->netcount != 0) {
44048+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44049 DBGINFO(("%s hdlc_open busy\n", dev->name));
44050 spin_unlock_irqrestore(&info->netlock, flags);
44051 return -EBUSY;
44052@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44053 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
44054
44055 /* return error if TTY interface open */
44056- if (info->port.count)
44057+ if (atomic_read(&info->port.count))
44058 return -EBUSY;
44059
44060 if (cmd != SIOCWANDEV)
44061@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
44062 if (port == NULL)
44063 continue;
44064 spin_lock(&port->lock);
44065- if ((port->port.count || port->netcount) &&
44066+ if ((atomic_read(&port->port.count) || port->netcount) &&
44067 port->pending_bh && !port->bh_running &&
44068 !port->bh_requested) {
44069 DBGISR(("%s bh queued\n", port->device_name));
44070@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44071 spin_lock_irqsave(&info->lock, flags);
44072 if (!tty_hung_up_p(filp)) {
44073 extra_count = true;
44074- port->count--;
44075+ atomic_dec(&port->count);
44076 }
44077 spin_unlock_irqrestore(&info->lock, flags);
44078 port->blocked_open++;
44079@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44080 remove_wait_queue(&port->open_wait, &wait);
44081
44082 if (extra_count)
44083- port->count++;
44084+ atomic_inc(&port->count);
44085 port->blocked_open--;
44086
44087 if (!retval)
44088diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
44089index ff17138..e38b41e 100644
44090--- a/drivers/tty/synclinkmp.c
44091+++ b/drivers/tty/synclinkmp.c
44092@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44093
44094 if (debug_level >= DEBUG_LEVEL_INFO)
44095 printk("%s(%d):%s open(), old ref count = %d\n",
44096- __FILE__,__LINE__,tty->driver->name, info->port.count);
44097+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44098
44099 /* If port is closing, signal caller to try again */
44100 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44101@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44102 spin_unlock_irqrestore(&info->netlock, flags);
44103 goto cleanup;
44104 }
44105- info->port.count++;
44106+ atomic_inc(&info->port.count);
44107 spin_unlock_irqrestore(&info->netlock, flags);
44108
44109- if (info->port.count == 1) {
44110+ if (atomic_read(&info->port.count) == 1) {
44111 /* 1st open on this device, init hardware */
44112 retval = startup(info);
44113 if (retval < 0)
44114@@ -796,8 +796,8 @@ cleanup:
44115 if (retval) {
44116 if (tty->count == 1)
44117 info->port.tty = NULL; /* tty layer will release tty struct */
44118- if(info->port.count)
44119- info->port.count--;
44120+ if(atomic_read(&info->port.count))
44121+ atomic_dec(&info->port.count);
44122 }
44123
44124 return retval;
44125@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44126
44127 if (debug_level >= DEBUG_LEVEL_INFO)
44128 printk("%s(%d):%s close() entry, count=%d\n",
44129- __FILE__,__LINE__, info->device_name, info->port.count);
44130+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
44131
44132 if (tty_port_close_start(&info->port, tty, filp) == 0)
44133 goto cleanup;
44134@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44135 cleanup:
44136 if (debug_level >= DEBUG_LEVEL_INFO)
44137 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
44138- tty->driver->name, info->port.count);
44139+ tty->driver->name, atomic_read(&info->port.count));
44140 }
44141
44142 /* Called by tty_hangup() when a hangup is signaled.
44143@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
44144 shutdown(info);
44145
44146 spin_lock_irqsave(&info->port.lock, flags);
44147- info->port.count = 0;
44148+ atomic_set(&info->port.count, 0);
44149 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44150 info->port.tty = NULL;
44151 spin_unlock_irqrestore(&info->port.lock, flags);
44152@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44153 unsigned short new_crctype;
44154
44155 /* return error if TTY interface open */
44156- if (info->port.count)
44157+ if (atomic_read(&info->port.count))
44158 return -EBUSY;
44159
44160 switch (encoding)
44161@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
44162
44163 /* arbitrate between network and tty opens */
44164 spin_lock_irqsave(&info->netlock, flags);
44165- if (info->port.count != 0 || info->netcount != 0) {
44166+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44167 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44168 spin_unlock_irqrestore(&info->netlock, flags);
44169 return -EBUSY;
44170@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44171 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44172
44173 /* return error if TTY interface open */
44174- if (info->port.count)
44175+ if (atomic_read(&info->port.count))
44176 return -EBUSY;
44177
44178 if (cmd != SIOCWANDEV)
44179@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
44180 * do not request bottom half processing if the
44181 * device is not open in a normal mode.
44182 */
44183- if ( port && (port->port.count || port->netcount) &&
44184+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
44185 port->pending_bh && !port->bh_running &&
44186 !port->bh_requested ) {
44187 if ( debug_level >= DEBUG_LEVEL_ISR )
44188@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44189
44190 if (debug_level >= DEBUG_LEVEL_INFO)
44191 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
44192- __FILE__,__LINE__, tty->driver->name, port->count );
44193+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44194
44195 spin_lock_irqsave(&info->lock, flags);
44196 if (!tty_hung_up_p(filp)) {
44197 extra_count = true;
44198- port->count--;
44199+ atomic_dec(&port->count);
44200 }
44201 spin_unlock_irqrestore(&info->lock, flags);
44202 port->blocked_open++;
44203@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44204
44205 if (debug_level >= DEBUG_LEVEL_INFO)
44206 printk("%s(%d):%s block_til_ready() count=%d\n",
44207- __FILE__,__LINE__, tty->driver->name, port->count );
44208+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44209
44210 tty_unlock(tty);
44211 schedule();
44212@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44213 remove_wait_queue(&port->open_wait, &wait);
44214
44215 if (extra_count)
44216- port->count++;
44217+ atomic_inc(&port->count);
44218 port->blocked_open--;
44219
44220 if (debug_level >= DEBUG_LEVEL_INFO)
44221 printk("%s(%d):%s block_til_ready() after, count=%d\n",
44222- __FILE__,__LINE__, tty->driver->name, port->count );
44223+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44224
44225 if (!retval)
44226 port->flags |= ASYNC_NORMAL_ACTIVE;
44227diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
44228index b51c154..17d55d1 100644
44229--- a/drivers/tty/sysrq.c
44230+++ b/drivers/tty/sysrq.c
44231@@ -1022,7 +1022,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
44232 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
44233 size_t count, loff_t *ppos)
44234 {
44235- if (count) {
44236+ if (count && capable(CAP_SYS_ADMIN)) {
44237 char c;
44238
44239 if (get_user(c, buf))
44240diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
44241index 4476682..d77e748 100644
44242--- a/drivers/tty/tty_io.c
44243+++ b/drivers/tty/tty_io.c
44244@@ -3466,7 +3466,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
44245
44246 void tty_default_fops(struct file_operations *fops)
44247 {
44248- *fops = tty_fops;
44249+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
44250 }
44251
44252 /*
44253diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
44254index 1afe192..73d2c20 100644
44255--- a/drivers/tty/tty_ldisc.c
44256+++ b/drivers/tty/tty_ldisc.c
44257@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
44258 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44259 tty_ldiscs[disc] = new_ldisc;
44260 new_ldisc->num = disc;
44261- new_ldisc->refcount = 0;
44262+ atomic_set(&new_ldisc->refcount, 0);
44263 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44264
44265 return ret;
44266@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
44267 return -EINVAL;
44268
44269 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44270- if (tty_ldiscs[disc]->refcount)
44271+ if (atomic_read(&tty_ldiscs[disc]->refcount))
44272 ret = -EBUSY;
44273 else
44274 tty_ldiscs[disc] = NULL;
44275@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
44276 if (ldops) {
44277 ret = ERR_PTR(-EAGAIN);
44278 if (try_module_get(ldops->owner)) {
44279- ldops->refcount++;
44280+ atomic_inc(&ldops->refcount);
44281 ret = ldops;
44282 }
44283 }
44284@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
44285 unsigned long flags;
44286
44287 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44288- ldops->refcount--;
44289+ atomic_dec(&ldops->refcount);
44290 module_put(ldops->owner);
44291 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44292 }
44293@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
44294 /* unreleased reader reference(s) will cause this WARN */
44295 WARN_ON(!atomic_dec_and_test(&ld->users));
44296
44297- ld->ops->refcount--;
44298+ atomic_dec(&ld->ops->refcount);
44299 module_put(ld->ops->owner);
44300 kfree(ld);
44301 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44302diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
44303index 121aeb9..0d2c4b9 100644
44304--- a/drivers/tty/tty_port.c
44305+++ b/drivers/tty/tty_port.c
44306@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
44307 unsigned long flags;
44308
44309 spin_lock_irqsave(&port->lock, flags);
44310- port->count = 0;
44311+ atomic_set(&port->count, 0);
44312 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44313 tty = port->tty;
44314 if (tty)
44315@@ -391,7 +391,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44316 /* The port lock protects the port counts */
44317 spin_lock_irqsave(&port->lock, flags);
44318 if (!tty_hung_up_p(filp))
44319- port->count--;
44320+ atomic_dec(&port->count);
44321 port->blocked_open++;
44322 spin_unlock_irqrestore(&port->lock, flags);
44323
44324@@ -433,7 +433,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44325 we must not mess that up further */
44326 spin_lock_irqsave(&port->lock, flags);
44327 if (!tty_hung_up_p(filp))
44328- port->count++;
44329+ atomic_inc(&port->count);
44330 port->blocked_open--;
44331 if (retval == 0)
44332 port->flags |= ASYNC_NORMAL_ACTIVE;
44333@@ -467,19 +467,19 @@ int tty_port_close_start(struct tty_port *port,
44334 return 0;
44335 }
44336
44337- if (tty->count == 1 && port->count != 1) {
44338+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
44339 printk(KERN_WARNING
44340 "tty_port_close_start: tty->count = 1 port count = %d.\n",
44341- port->count);
44342- port->count = 1;
44343+ atomic_read(&port->count));
44344+ atomic_set(&port->count, 1);
44345 }
44346- if (--port->count < 0) {
44347+ if (atomic_dec_return(&port->count) < 0) {
44348 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
44349- port->count);
44350- port->count = 0;
44351+ atomic_read(&port->count));
44352+ atomic_set(&port->count, 0);
44353 }
44354
44355- if (port->count) {
44356+ if (atomic_read(&port->count)) {
44357 spin_unlock_irqrestore(&port->lock, flags);
44358 if (port->ops->drop)
44359 port->ops->drop(port);
44360@@ -565,7 +565,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
44361 {
44362 spin_lock_irq(&port->lock);
44363 if (!tty_hung_up_p(filp))
44364- ++port->count;
44365+ atomic_inc(&port->count);
44366 spin_unlock_irq(&port->lock);
44367 tty_port_tty_set(port, tty);
44368
44369diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
44370index a9af1b9a..1e08e7f 100644
44371--- a/drivers/tty/vt/keyboard.c
44372+++ b/drivers/tty/vt/keyboard.c
44373@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
44374 kbd->kbdmode == VC_OFF) &&
44375 value != KVAL(K_SAK))
44376 return; /* SAK is allowed even in raw mode */
44377+
44378+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
44379+ {
44380+ void *func = fn_handler[value];
44381+ if (func == fn_show_state || func == fn_show_ptregs ||
44382+ func == fn_show_mem)
44383+ return;
44384+ }
44385+#endif
44386+
44387 fn_handler[value](vc);
44388 }
44389
44390@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44391 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
44392 return -EFAULT;
44393
44394- if (!capable(CAP_SYS_TTY_CONFIG))
44395- perm = 0;
44396-
44397 switch (cmd) {
44398 case KDGKBENT:
44399 /* Ensure another thread doesn't free it under us */
44400@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44401 spin_unlock_irqrestore(&kbd_event_lock, flags);
44402 return put_user(val, &user_kbe->kb_value);
44403 case KDSKBENT:
44404+ if (!capable(CAP_SYS_TTY_CONFIG))
44405+ perm = 0;
44406+
44407 if (!perm)
44408 return -EPERM;
44409 if (!i && v == K_NOSUCHMAP) {
44410@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44411 int i, j, k;
44412 int ret;
44413
44414- if (!capable(CAP_SYS_TTY_CONFIG))
44415- perm = 0;
44416-
44417 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
44418 if (!kbs) {
44419 ret = -ENOMEM;
44420@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44421 kfree(kbs);
44422 return ((p && *p) ? -EOVERFLOW : 0);
44423 case KDSKBSENT:
44424+ if (!capable(CAP_SYS_TTY_CONFIG))
44425+ perm = 0;
44426+
44427 if (!perm) {
44428 ret = -EPERM;
44429 goto reterr;
44430diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
44431index b645c47..a55c182 100644
44432--- a/drivers/uio/uio.c
44433+++ b/drivers/uio/uio.c
44434@@ -25,6 +25,7 @@
44435 #include <linux/kobject.h>
44436 #include <linux/cdev.h>
44437 #include <linux/uio_driver.h>
44438+#include <asm/local.h>
44439
44440 #define UIO_MAX_DEVICES (1U << MINORBITS)
44441
44442@@ -32,10 +33,10 @@ struct uio_device {
44443 struct module *owner;
44444 struct device *dev;
44445 int minor;
44446- atomic_t event;
44447+ atomic_unchecked_t event;
44448 struct fasync_struct *async_queue;
44449 wait_queue_head_t wait;
44450- int vma_count;
44451+ local_t vma_count;
44452 struct uio_info *info;
44453 struct kobject *map_dir;
44454 struct kobject *portio_dir;
44455@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
44456 struct device_attribute *attr, char *buf)
44457 {
44458 struct uio_device *idev = dev_get_drvdata(dev);
44459- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
44460+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
44461 }
44462
44463 static struct device_attribute uio_class_attributes[] = {
44464@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
44465 {
44466 struct uio_device *idev = info->uio_dev;
44467
44468- atomic_inc(&idev->event);
44469+ atomic_inc_unchecked(&idev->event);
44470 wake_up_interruptible(&idev->wait);
44471 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
44472 }
44473@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
44474 }
44475
44476 listener->dev = idev;
44477- listener->event_count = atomic_read(&idev->event);
44478+ listener->event_count = atomic_read_unchecked(&idev->event);
44479 filep->private_data = listener;
44480
44481 if (idev->info->open) {
44482@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
44483 return -EIO;
44484
44485 poll_wait(filep, &idev->wait, wait);
44486- if (listener->event_count != atomic_read(&idev->event))
44487+ if (listener->event_count != atomic_read_unchecked(&idev->event))
44488 return POLLIN | POLLRDNORM;
44489 return 0;
44490 }
44491@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
44492 do {
44493 set_current_state(TASK_INTERRUPTIBLE);
44494
44495- event_count = atomic_read(&idev->event);
44496+ event_count = atomic_read_unchecked(&idev->event);
44497 if (event_count != listener->event_count) {
44498 if (copy_to_user(buf, &event_count, count))
44499 retval = -EFAULT;
44500@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
44501 static void uio_vma_open(struct vm_area_struct *vma)
44502 {
44503 struct uio_device *idev = vma->vm_private_data;
44504- idev->vma_count++;
44505+ local_inc(&idev->vma_count);
44506 }
44507
44508 static void uio_vma_close(struct vm_area_struct *vma)
44509 {
44510 struct uio_device *idev = vma->vm_private_data;
44511- idev->vma_count--;
44512+ local_dec(&idev->vma_count);
44513 }
44514
44515 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
44516@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
44517 idev->owner = owner;
44518 idev->info = info;
44519 init_waitqueue_head(&idev->wait);
44520- atomic_set(&idev->event, 0);
44521+ atomic_set_unchecked(&idev->event, 0);
44522
44523 ret = uio_get_minor(idev);
44524 if (ret)
44525diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
44526index 8a7eb77..c00402f 100644
44527--- a/drivers/usb/atm/cxacru.c
44528+++ b/drivers/usb/atm/cxacru.c
44529@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
44530 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
44531 if (ret < 2)
44532 return -EINVAL;
44533- if (index < 0 || index > 0x7f)
44534+ if (index > 0x7f)
44535 return -EINVAL;
44536 pos += tmp;
44537
44538diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
44539index d3527dd..26effa2 100644
44540--- a/drivers/usb/atm/usbatm.c
44541+++ b/drivers/usb/atm/usbatm.c
44542@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44543 if (printk_ratelimit())
44544 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
44545 __func__, vpi, vci);
44546- atomic_inc(&vcc->stats->rx_err);
44547+ atomic_inc_unchecked(&vcc->stats->rx_err);
44548 return;
44549 }
44550
44551@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44552 if (length > ATM_MAX_AAL5_PDU) {
44553 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
44554 __func__, length, vcc);
44555- atomic_inc(&vcc->stats->rx_err);
44556+ atomic_inc_unchecked(&vcc->stats->rx_err);
44557 goto out;
44558 }
44559
44560@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44561 if (sarb->len < pdu_length) {
44562 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
44563 __func__, pdu_length, sarb->len, vcc);
44564- atomic_inc(&vcc->stats->rx_err);
44565+ atomic_inc_unchecked(&vcc->stats->rx_err);
44566 goto out;
44567 }
44568
44569 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
44570 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
44571 __func__, vcc);
44572- atomic_inc(&vcc->stats->rx_err);
44573+ atomic_inc_unchecked(&vcc->stats->rx_err);
44574 goto out;
44575 }
44576
44577@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44578 if (printk_ratelimit())
44579 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
44580 __func__, length);
44581- atomic_inc(&vcc->stats->rx_drop);
44582+ atomic_inc_unchecked(&vcc->stats->rx_drop);
44583 goto out;
44584 }
44585
44586@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44587
44588 vcc->push(vcc, skb);
44589
44590- atomic_inc(&vcc->stats->rx);
44591+ atomic_inc_unchecked(&vcc->stats->rx);
44592 out:
44593 skb_trim(sarb, 0);
44594 }
44595@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
44596 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
44597
44598 usbatm_pop(vcc, skb);
44599- atomic_inc(&vcc->stats->tx);
44600+ atomic_inc_unchecked(&vcc->stats->tx);
44601
44602 skb = skb_dequeue(&instance->sndqueue);
44603 }
44604@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
44605 if (!left--)
44606 return sprintf(page,
44607 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
44608- atomic_read(&atm_dev->stats.aal5.tx),
44609- atomic_read(&atm_dev->stats.aal5.tx_err),
44610- atomic_read(&atm_dev->stats.aal5.rx),
44611- atomic_read(&atm_dev->stats.aal5.rx_err),
44612- atomic_read(&atm_dev->stats.aal5.rx_drop));
44613+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
44614+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
44615+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
44616+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
44617+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
44618
44619 if (!left--) {
44620 if (instance->disconnected)
44621diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
44622index 2a3bbdf..91d72cf 100644
44623--- a/drivers/usb/core/devices.c
44624+++ b/drivers/usb/core/devices.c
44625@@ -126,7 +126,7 @@ static const char format_endpt[] =
44626 * time it gets called.
44627 */
44628 static struct device_connect_event {
44629- atomic_t count;
44630+ atomic_unchecked_t count;
44631 wait_queue_head_t wait;
44632 } device_event = {
44633 .count = ATOMIC_INIT(1),
44634@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44635
44636 void usbfs_conn_disc_event(void)
44637 {
44638- atomic_add(2, &device_event.count);
44639+ atomic_add_unchecked(2, &device_event.count);
44640 wake_up(&device_event.wait);
44641 }
44642
44643@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
44644
44645 poll_wait(file, &device_event.wait, wait);
44646
44647- event_count = atomic_read(&device_event.count);
44648+ event_count = atomic_read_unchecked(&device_event.count);
44649 if (file->f_version != event_count) {
44650 file->f_version = event_count;
44651 return POLLIN | POLLRDNORM;
44652diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44653index d53547d..6a22d02 100644
44654--- a/drivers/usb/core/hcd.c
44655+++ b/drivers/usb/core/hcd.c
44656@@ -1526,7 +1526,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44657 */
44658 usb_get_urb(urb);
44659 atomic_inc(&urb->use_count);
44660- atomic_inc(&urb->dev->urbnum);
44661+ atomic_inc_unchecked(&urb->dev->urbnum);
44662 usbmon_urb_submit(&hcd->self, urb);
44663
44664 /* NOTE requirements on root-hub callers (usbfs and the hub
44665@@ -1553,7 +1553,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44666 urb->hcpriv = NULL;
44667 INIT_LIST_HEAD(&urb->urb_list);
44668 atomic_dec(&urb->use_count);
44669- atomic_dec(&urb->dev->urbnum);
44670+ atomic_dec_unchecked(&urb->dev->urbnum);
44671 if (atomic_read(&urb->reject))
44672 wake_up(&usb_kill_urb_queue);
44673 usb_put_urb(urb);
44674diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44675index 444d30e..f15c850 100644
44676--- a/drivers/usb/core/message.c
44677+++ b/drivers/usb/core/message.c
44678@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44679 * method can wait for it to complete. Since you don't have a handle on the
44680 * URB used, you can't cancel the request.
44681 */
44682-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44683+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44684 __u8 requesttype, __u16 value, __u16 index, void *data,
44685 __u16 size, int timeout)
44686 {
44687diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44688index aa38db4..0a08682 100644
44689--- a/drivers/usb/core/sysfs.c
44690+++ b/drivers/usb/core/sysfs.c
44691@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44692 struct usb_device *udev;
44693
44694 udev = to_usb_device(dev);
44695- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44696+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44697 }
44698 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44699
44700diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44701index b10da72..43aa0b2 100644
44702--- a/drivers/usb/core/usb.c
44703+++ b/drivers/usb/core/usb.c
44704@@ -389,7 +389,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44705 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44706 dev->state = USB_STATE_ATTACHED;
44707 dev->lpm_disable_count = 1;
44708- atomic_set(&dev->urbnum, 0);
44709+ atomic_set_unchecked(&dev->urbnum, 0);
44710
44711 INIT_LIST_HEAD(&dev->ep0.urb_list);
44712 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44713diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44714index 5e29dde..eca992f 100644
44715--- a/drivers/usb/early/ehci-dbgp.c
44716+++ b/drivers/usb/early/ehci-dbgp.c
44717@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44718
44719 #ifdef CONFIG_KGDB
44720 static struct kgdb_io kgdbdbgp_io_ops;
44721-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44722+static struct kgdb_io kgdbdbgp_io_ops_console;
44723+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44724 #else
44725 #define dbgp_kgdb_mode (0)
44726 #endif
44727@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44728 .write_char = kgdbdbgp_write_char,
44729 };
44730
44731+static struct kgdb_io kgdbdbgp_io_ops_console = {
44732+ .name = "kgdbdbgp",
44733+ .read_char = kgdbdbgp_read_char,
44734+ .write_char = kgdbdbgp_write_char,
44735+ .is_console = 1
44736+};
44737+
44738 static int kgdbdbgp_wait_time;
44739
44740 static int __init kgdbdbgp_parse_config(char *str)
44741@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44742 ptr++;
44743 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44744 }
44745- kgdb_register_io_module(&kgdbdbgp_io_ops);
44746- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44747+ if (early_dbgp_console.index != -1)
44748+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44749+ else
44750+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44751
44752 return 0;
44753 }
44754diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44755index b369292..9f3ba40 100644
44756--- a/drivers/usb/gadget/u_serial.c
44757+++ b/drivers/usb/gadget/u_serial.c
44758@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44759 spin_lock_irq(&port->port_lock);
44760
44761 /* already open? Great. */
44762- if (port->port.count) {
44763+ if (atomic_read(&port->port.count)) {
44764 status = 0;
44765- port->port.count++;
44766+ atomic_inc(&port->port.count);
44767
44768 /* currently opening/closing? wait ... */
44769 } else if (port->openclose) {
44770@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44771 tty->driver_data = port;
44772 port->port.tty = tty;
44773
44774- port->port.count = 1;
44775+ atomic_set(&port->port.count, 1);
44776 port->openclose = false;
44777
44778 /* if connected, start the I/O stream */
44779@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44780
44781 spin_lock_irq(&port->port_lock);
44782
44783- if (port->port.count != 1) {
44784- if (port->port.count == 0)
44785+ if (atomic_read(&port->port.count) != 1) {
44786+ if (atomic_read(&port->port.count) == 0)
44787 WARN_ON(1);
44788 else
44789- --port->port.count;
44790+ atomic_dec(&port->port.count);
44791 goto exit;
44792 }
44793
44794@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44795 * and sleep if necessary
44796 */
44797 port->openclose = true;
44798- port->port.count = 0;
44799+ atomic_set(&port->port.count, 0);
44800
44801 gser = port->port_usb;
44802 if (gser && gser->disconnect)
44803@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
44804 int cond;
44805
44806 spin_lock_irq(&port->port_lock);
44807- cond = (port->port.count == 0) && !port->openclose;
44808+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44809 spin_unlock_irq(&port->port_lock);
44810 return cond;
44811 }
44812@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44813 /* if it's already open, start I/O ... and notify the serial
44814 * protocol about open/close status (connect/disconnect).
44815 */
44816- if (port->port.count) {
44817+ if (atomic_read(&port->port.count)) {
44818 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44819 gs_start_io(port);
44820 if (gser->connect)
44821@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
44822
44823 port->port_usb = NULL;
44824 gser->ioport = NULL;
44825- if (port->port.count > 0 || port->openclose) {
44826+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44827 wake_up_interruptible(&port->drain_wait);
44828 if (port->port.tty)
44829 tty_hangup(port->port.tty);
44830@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
44831
44832 /* finally, free any unused/unusable I/O buffers */
44833 spin_lock_irqsave(&port->port_lock, flags);
44834- if (port->port.count == 0 && !port->openclose)
44835+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44836 gs_buf_free(&port->port_write_buf);
44837 gs_free_requests(gser->out, &port->read_pool, NULL);
44838 gs_free_requests(gser->out, &port->read_queue, NULL);
44839diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44840index 5f3bcd3..bfca43f 100644
44841--- a/drivers/usb/serial/console.c
44842+++ b/drivers/usb/serial/console.c
44843@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44844
44845 info->port = port;
44846
44847- ++port->port.count;
44848+ atomic_inc(&port->port.count);
44849 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44850 if (serial->type->set_termios) {
44851 /*
44852@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44853 }
44854 /* Now that any required fake tty operations are completed restore
44855 * the tty port count */
44856- --port->port.count;
44857+ atomic_dec(&port->port.count);
44858 /* The console is special in terms of closing the device so
44859 * indicate this port is now acting as a system console. */
44860 port->port.console = 1;
44861@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44862 free_tty:
44863 kfree(tty);
44864 reset_open_count:
44865- port->port.count = 0;
44866+ atomic_set(&port->port.count, 0);
44867 usb_autopm_put_interface(serial->interface);
44868 error_get_interface:
44869 usb_serial_put(serial);
44870diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44871index 75f70f0..d467e1a 100644
44872--- a/drivers/usb/storage/usb.h
44873+++ b/drivers/usb/storage/usb.h
44874@@ -63,7 +63,7 @@ struct us_unusual_dev {
44875 __u8 useProtocol;
44876 __u8 useTransport;
44877 int (*initFunction)(struct us_data *);
44878-};
44879+} __do_const;
44880
44881
44882 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44883diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44884index d6bea3e..60b250e 100644
44885--- a/drivers/usb/wusbcore/wa-hc.h
44886+++ b/drivers/usb/wusbcore/wa-hc.h
44887@@ -192,7 +192,7 @@ struct wahc {
44888 struct list_head xfer_delayed_list;
44889 spinlock_t xfer_list_lock;
44890 struct work_struct xfer_work;
44891- atomic_t xfer_id_count;
44892+ atomic_unchecked_t xfer_id_count;
44893 };
44894
44895
44896@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44897 INIT_LIST_HEAD(&wa->xfer_delayed_list);
44898 spin_lock_init(&wa->xfer_list_lock);
44899 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
44900- atomic_set(&wa->xfer_id_count, 1);
44901+ atomic_set_unchecked(&wa->xfer_id_count, 1);
44902 }
44903
44904 /**
44905diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
44906index 6ef94bc..1b41265 100644
44907--- a/drivers/usb/wusbcore/wa-xfer.c
44908+++ b/drivers/usb/wusbcore/wa-xfer.c
44909@@ -296,7 +296,7 @@ out:
44910 */
44911 static void wa_xfer_id_init(struct wa_xfer *xfer)
44912 {
44913- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
44914+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
44915 }
44916
44917 /*
44918diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
44919index f80d3dd..8ca5ac7 100644
44920--- a/drivers/vhost/net.c
44921+++ b/drivers/vhost/net.c
44922@@ -150,6 +150,11 @@ static void vhost_net_ubuf_put_and_wait(struct vhost_net_ubuf_ref *ubufs)
44923 {
44924 kref_put(&ubufs->kref, vhost_net_zerocopy_done_signal);
44925 wait_event(ubufs->wait, !atomic_read(&ubufs->kref.refcount));
44926+}
44927+
44928+static void vhost_net_ubuf_put_wait_and_free(struct vhost_net_ubuf_ref *ubufs)
44929+{
44930+ vhost_net_ubuf_put_and_wait(ubufs);
44931 kfree(ubufs);
44932 }
44933
44934@@ -948,7 +953,7 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
44935 mutex_unlock(&vq->mutex);
44936
44937 if (oldubufs) {
44938- vhost_net_ubuf_put_and_wait(oldubufs);
44939+ vhost_net_ubuf_put_wait_and_free(oldubufs);
44940 mutex_lock(&vq->mutex);
44941 vhost_zerocopy_signal_used(n, vq);
44942 mutex_unlock(&vq->mutex);
44943@@ -966,7 +971,7 @@ err_used:
44944 rcu_assign_pointer(vq->private_data, oldsock);
44945 vhost_net_enable_vq(n, vq);
44946 if (ubufs)
44947- vhost_net_ubuf_put_and_wait(ubufs);
44948+ vhost_net_ubuf_put_wait_and_free(ubufs);
44949 err_ubufs:
44950 fput(sock->file);
44951 err_vq:
44952diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
44953index 5174eba..86e764a 100644
44954--- a/drivers/vhost/vringh.c
44955+++ b/drivers/vhost/vringh.c
44956@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
44957
44958 static inline int putu16_kern(u16 *p, u16 val)
44959 {
44960- ACCESS_ONCE(*p) = val;
44961+ ACCESS_ONCE_RW(*p) = val;
44962 return 0;
44963 }
44964
44965diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
44966index 8c55011..eed4ae1a 100644
44967--- a/drivers/video/aty/aty128fb.c
44968+++ b/drivers/video/aty/aty128fb.c
44969@@ -149,7 +149,7 @@ enum {
44970 };
44971
44972 /* Must match above enum */
44973-static char * const r128_family[] = {
44974+static const char * const r128_family[] = {
44975 "AGP",
44976 "PCI",
44977 "PRO AGP",
44978diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
44979index 4f27fdc..d3537e6 100644
44980--- a/drivers/video/aty/atyfb_base.c
44981+++ b/drivers/video/aty/atyfb_base.c
44982@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
44983 par->accel_flags = var->accel_flags; /* hack */
44984
44985 if (var->accel_flags) {
44986- info->fbops->fb_sync = atyfb_sync;
44987+ pax_open_kernel();
44988+ *(void **)&info->fbops->fb_sync = atyfb_sync;
44989+ pax_close_kernel();
44990 info->flags &= ~FBINFO_HWACCEL_DISABLED;
44991 } else {
44992- info->fbops->fb_sync = NULL;
44993+ pax_open_kernel();
44994+ *(void **)&info->fbops->fb_sync = NULL;
44995+ pax_close_kernel();
44996 info->flags |= FBINFO_HWACCEL_DISABLED;
44997 }
44998
44999diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
45000index 95ec042..e6affdd 100644
45001--- a/drivers/video/aty/mach64_cursor.c
45002+++ b/drivers/video/aty/mach64_cursor.c
45003@@ -7,6 +7,7 @@
45004 #include <linux/string.h>
45005
45006 #include <asm/io.h>
45007+#include <asm/pgtable.h>
45008
45009 #ifdef __sparc__
45010 #include <asm/fbio.h>
45011@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
45012 info->sprite.buf_align = 16; /* and 64 lines tall. */
45013 info->sprite.flags = FB_PIXMAP_IO;
45014
45015- info->fbops->fb_cursor = atyfb_cursor;
45016+ pax_open_kernel();
45017+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
45018+ pax_close_kernel();
45019
45020 return 0;
45021 }
45022diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
45023index bca6ccc..252107e 100644
45024--- a/drivers/video/backlight/kb3886_bl.c
45025+++ b/drivers/video/backlight/kb3886_bl.c
45026@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
45027 static unsigned long kb3886bl_flags;
45028 #define KB3886BL_SUSPENDED 0x01
45029
45030-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
45031+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
45032 {
45033 .ident = "Sahara Touch-iT",
45034 .matches = {
45035diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
45036index 900aa4e..6d49418 100644
45037--- a/drivers/video/fb_defio.c
45038+++ b/drivers/video/fb_defio.c
45039@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
45040
45041 BUG_ON(!fbdefio);
45042 mutex_init(&fbdefio->lock);
45043- info->fbops->fb_mmap = fb_deferred_io_mmap;
45044+ pax_open_kernel();
45045+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
45046+ pax_close_kernel();
45047 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
45048 INIT_LIST_HEAD(&fbdefio->pagelist);
45049 if (fbdefio->delay == 0) /* set a default of 1 s */
45050@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
45051 page->mapping = NULL;
45052 }
45053
45054- info->fbops->fb_mmap = NULL;
45055+ *(void **)&info->fbops->fb_mmap = NULL;
45056 mutex_destroy(&fbdefio->lock);
45057 }
45058 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
45059diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
45060index 5c3960d..15cf8fc 100644
45061--- a/drivers/video/fbcmap.c
45062+++ b/drivers/video/fbcmap.c
45063@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
45064 rc = -ENODEV;
45065 goto out;
45066 }
45067- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
45068- !info->fbops->fb_setcmap)) {
45069+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
45070 rc = -EINVAL;
45071 goto out1;
45072 }
45073diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
45074index 098bfc6..796841d 100644
45075--- a/drivers/video/fbmem.c
45076+++ b/drivers/video/fbmem.c
45077@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45078 image->dx += image->width + 8;
45079 }
45080 } else if (rotate == FB_ROTATE_UD) {
45081- for (x = 0; x < num && image->dx >= 0; x++) {
45082+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
45083 info->fbops->fb_imageblit(info, image);
45084 image->dx -= image->width + 8;
45085 }
45086@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45087 image->dy += image->height + 8;
45088 }
45089 } else if (rotate == FB_ROTATE_CCW) {
45090- for (x = 0; x < num && image->dy >= 0; x++) {
45091+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
45092 info->fbops->fb_imageblit(info, image);
45093 image->dy -= image->height + 8;
45094 }
45095@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
45096 return -EFAULT;
45097 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
45098 return -EINVAL;
45099- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
45100+ if (con2fb.framebuffer >= FB_MAX)
45101 return -EINVAL;
45102 if (!registered_fb[con2fb.framebuffer])
45103 request_module("fb%d", con2fb.framebuffer);
45104diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
45105index 7672d2e..b56437f 100644
45106--- a/drivers/video/i810/i810_accel.c
45107+++ b/drivers/video/i810/i810_accel.c
45108@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
45109 }
45110 }
45111 printk("ringbuffer lockup!!!\n");
45112+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
45113 i810_report_error(mmio);
45114 par->dev_flags |= LOCKUP;
45115 info->pixmap.scan_align = 1;
45116diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
45117index 3c14e43..eafa544 100644
45118--- a/drivers/video/logo/logo_linux_clut224.ppm
45119+++ b/drivers/video/logo/logo_linux_clut224.ppm
45120@@ -1,1604 +1,1123 @@
45121 P3
45122-# Standard 224-color Linux logo
45123 80 80
45124 255
45125- 0 0 0 0 0 0 0 0 0 0 0 0
45126- 0 0 0 0 0 0 0 0 0 0 0 0
45127- 0 0 0 0 0 0 0 0 0 0 0 0
45128- 0 0 0 0 0 0 0 0 0 0 0 0
45129- 0 0 0 0 0 0 0 0 0 0 0 0
45130- 0 0 0 0 0 0 0 0 0 0 0 0
45131- 0 0 0 0 0 0 0 0 0 0 0 0
45132- 0 0 0 0 0 0 0 0 0 0 0 0
45133- 0 0 0 0 0 0 0 0 0 0 0 0
45134- 6 6 6 6 6 6 10 10 10 10 10 10
45135- 10 10 10 6 6 6 6 6 6 6 6 6
45136- 0 0 0 0 0 0 0 0 0 0 0 0
45137- 0 0 0 0 0 0 0 0 0 0 0 0
45138- 0 0 0 0 0 0 0 0 0 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 0 0 0
45145- 0 0 0 0 0 0 0 0 0 0 0 0
45146- 0 0 0 0 0 0 0 0 0 0 0 0
45147- 0 0 0 0 0 0 0 0 0 0 0 0
45148- 0 0 0 0 0 0 0 0 0 0 0 0
45149- 0 0 0 0 0 0 0 0 0 0 0 0
45150- 0 0 0 0 0 0 0 0 0 0 0 0
45151- 0 0 0 0 0 0 0 0 0 0 0 0
45152- 0 0 0 0 0 0 0 0 0 0 0 0
45153- 0 0 0 6 6 6 10 10 10 14 14 14
45154- 22 22 22 26 26 26 30 30 30 34 34 34
45155- 30 30 30 30 30 30 26 26 26 18 18 18
45156- 14 14 14 10 10 10 6 6 6 0 0 0
45157- 0 0 0 0 0 0 0 0 0 0 0 0
45158- 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0
45165- 0 0 0 0 0 0 0 0 0 0 0 0
45166- 0 0 0 0 0 1 0 0 1 0 0 0
45167- 0 0 0 0 0 0 0 0 0 0 0 0
45168- 0 0 0 0 0 0 0 0 0 0 0 0
45169- 0 0 0 0 0 0 0 0 0 0 0 0
45170- 0 0 0 0 0 0 0 0 0 0 0 0
45171- 0 0 0 0 0 0 0 0 0 0 0 0
45172- 0 0 0 0 0 0 0 0 0 0 0 0
45173- 6 6 6 14 14 14 26 26 26 42 42 42
45174- 54 54 54 66 66 66 78 78 78 78 78 78
45175- 78 78 78 74 74 74 66 66 66 54 54 54
45176- 42 42 42 26 26 26 18 18 18 10 10 10
45177- 6 6 6 0 0 0 0 0 0 0 0 0
45178- 0 0 0 0 0 0 0 0 0 0 0 0
45179- 0 0 0 0 0 0 0 0 0 0 0 0
45180- 0 0 0 0 0 0 0 0 0 0 0 0
45181- 0 0 0 0 0 0 0 0 0 0 0 0
45182- 0 0 0 0 0 0 0 0 0 0 0 0
45183- 0 0 0 0 0 0 0 0 0 0 0 0
45184- 0 0 0 0 0 0 0 0 0 0 0 0
45185- 0 0 0 0 0 0 0 0 0 0 0 0
45186- 0 0 1 0 0 0 0 0 0 0 0 0
45187- 0 0 0 0 0 0 0 0 0 0 0 0
45188- 0 0 0 0 0 0 0 0 0 0 0 0
45189- 0 0 0 0 0 0 0 0 0 0 0 0
45190- 0 0 0 0 0 0 0 0 0 0 0 0
45191- 0 0 0 0 0 0 0 0 0 0 0 0
45192- 0 0 0 0 0 0 0 0 0 10 10 10
45193- 22 22 22 42 42 42 66 66 66 86 86 86
45194- 66 66 66 38 38 38 38 38 38 22 22 22
45195- 26 26 26 34 34 34 54 54 54 66 66 66
45196- 86 86 86 70 70 70 46 46 46 26 26 26
45197- 14 14 14 6 6 6 0 0 0 0 0 0
45198- 0 0 0 0 0 0 0 0 0 0 0 0
45199- 0 0 0 0 0 0 0 0 0 0 0 0
45200- 0 0 0 0 0 0 0 0 0 0 0 0
45201- 0 0 0 0 0 0 0 0 0 0 0 0
45202- 0 0 0 0 0 0 0 0 0 0 0 0
45203- 0 0 0 0 0 0 0 0 0 0 0 0
45204- 0 0 0 0 0 0 0 0 0 0 0 0
45205- 0 0 0 0 0 0 0 0 0 0 0 0
45206- 0 0 1 0 0 1 0 0 1 0 0 0
45207- 0 0 0 0 0 0 0 0 0 0 0 0
45208- 0 0 0 0 0 0 0 0 0 0 0 0
45209- 0 0 0 0 0 0 0 0 0 0 0 0
45210- 0 0 0 0 0 0 0 0 0 0 0 0
45211- 0 0 0 0 0 0 0 0 0 0 0 0
45212- 0 0 0 0 0 0 10 10 10 26 26 26
45213- 50 50 50 82 82 82 58 58 58 6 6 6
45214- 2 2 6 2 2 6 2 2 6 2 2 6
45215- 2 2 6 2 2 6 2 2 6 2 2 6
45216- 6 6 6 54 54 54 86 86 86 66 66 66
45217- 38 38 38 18 18 18 6 6 6 0 0 0
45218- 0 0 0 0 0 0 0 0 0 0 0 0
45219- 0 0 0 0 0 0 0 0 0 0 0 0
45220- 0 0 0 0 0 0 0 0 0 0 0 0
45221- 0 0 0 0 0 0 0 0 0 0 0 0
45222- 0 0 0 0 0 0 0 0 0 0 0 0
45223- 0 0 0 0 0 0 0 0 0 0 0 0
45224- 0 0 0 0 0 0 0 0 0 0 0 0
45225- 0 0 0 0 0 0 0 0 0 0 0 0
45226- 0 0 0 0 0 0 0 0 0 0 0 0
45227- 0 0 0 0 0 0 0 0 0 0 0 0
45228- 0 0 0 0 0 0 0 0 0 0 0 0
45229- 0 0 0 0 0 0 0 0 0 0 0 0
45230- 0 0 0 0 0 0 0 0 0 0 0 0
45231- 0 0 0 0 0 0 0 0 0 0 0 0
45232- 0 0 0 6 6 6 22 22 22 50 50 50
45233- 78 78 78 34 34 34 2 2 6 2 2 6
45234- 2 2 6 2 2 6 2 2 6 2 2 6
45235- 2 2 6 2 2 6 2 2 6 2 2 6
45236- 2 2 6 2 2 6 6 6 6 70 70 70
45237- 78 78 78 46 46 46 22 22 22 6 6 6
45238- 0 0 0 0 0 0 0 0 0 0 0 0
45239- 0 0 0 0 0 0 0 0 0 0 0 0
45240- 0 0 0 0 0 0 0 0 0 0 0 0
45241- 0 0 0 0 0 0 0 0 0 0 0 0
45242- 0 0 0 0 0 0 0 0 0 0 0 0
45243- 0 0 0 0 0 0 0 0 0 0 0 0
45244- 0 0 0 0 0 0 0 0 0 0 0 0
45245- 0 0 0 0 0 0 0 0 0 0 0 0
45246- 0 0 1 0 0 1 0 0 1 0 0 0
45247- 0 0 0 0 0 0 0 0 0 0 0 0
45248- 0 0 0 0 0 0 0 0 0 0 0 0
45249- 0 0 0 0 0 0 0 0 0 0 0 0
45250- 0 0 0 0 0 0 0 0 0 0 0 0
45251- 0 0 0 0 0 0 0 0 0 0 0 0
45252- 6 6 6 18 18 18 42 42 42 82 82 82
45253- 26 26 26 2 2 6 2 2 6 2 2 6
45254- 2 2 6 2 2 6 2 2 6 2 2 6
45255- 2 2 6 2 2 6 2 2 6 14 14 14
45256- 46 46 46 34 34 34 6 6 6 2 2 6
45257- 42 42 42 78 78 78 42 42 42 18 18 18
45258- 6 6 6 0 0 0 0 0 0 0 0 0
45259- 0 0 0 0 0 0 0 0 0 0 0 0
45260- 0 0 0 0 0 0 0 0 0 0 0 0
45261- 0 0 0 0 0 0 0 0 0 0 0 0
45262- 0 0 0 0 0 0 0 0 0 0 0 0
45263- 0 0 0 0 0 0 0 0 0 0 0 0
45264- 0 0 0 0 0 0 0 0 0 0 0 0
45265- 0 0 0 0 0 0 0 0 0 0 0 0
45266- 0 0 1 0 0 0 0 0 1 0 0 0
45267- 0 0 0 0 0 0 0 0 0 0 0 0
45268- 0 0 0 0 0 0 0 0 0 0 0 0
45269- 0 0 0 0 0 0 0 0 0 0 0 0
45270- 0 0 0 0 0 0 0 0 0 0 0 0
45271- 0 0 0 0 0 0 0 0 0 0 0 0
45272- 10 10 10 30 30 30 66 66 66 58 58 58
45273- 2 2 6 2 2 6 2 2 6 2 2 6
45274- 2 2 6 2 2 6 2 2 6 2 2 6
45275- 2 2 6 2 2 6 2 2 6 26 26 26
45276- 86 86 86 101 101 101 46 46 46 10 10 10
45277- 2 2 6 58 58 58 70 70 70 34 34 34
45278- 10 10 10 0 0 0 0 0 0 0 0 0
45279- 0 0 0 0 0 0 0 0 0 0 0 0
45280- 0 0 0 0 0 0 0 0 0 0 0 0
45281- 0 0 0 0 0 0 0 0 0 0 0 0
45282- 0 0 0 0 0 0 0 0 0 0 0 0
45283- 0 0 0 0 0 0 0 0 0 0 0 0
45284- 0 0 0 0 0 0 0 0 0 0 0 0
45285- 0 0 0 0 0 0 0 0 0 0 0 0
45286- 0 0 1 0 0 1 0 0 1 0 0 0
45287- 0 0 0 0 0 0 0 0 0 0 0 0
45288- 0 0 0 0 0 0 0 0 0 0 0 0
45289- 0 0 0 0 0 0 0 0 0 0 0 0
45290- 0 0 0 0 0 0 0 0 0 0 0 0
45291- 0 0 0 0 0 0 0 0 0 0 0 0
45292- 14 14 14 42 42 42 86 86 86 10 10 10
45293- 2 2 6 2 2 6 2 2 6 2 2 6
45294- 2 2 6 2 2 6 2 2 6 2 2 6
45295- 2 2 6 2 2 6 2 2 6 30 30 30
45296- 94 94 94 94 94 94 58 58 58 26 26 26
45297- 2 2 6 6 6 6 78 78 78 54 54 54
45298- 22 22 22 6 6 6 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 0 0 0
45304- 0 0 0 0 0 0 0 0 0 0 0 0
45305- 0 0 0 0 0 0 0 0 0 0 0 0
45306- 0 0 0 0 0 0 0 0 0 0 0 0
45307- 0 0 0 0 0 0 0 0 0 0 0 0
45308- 0 0 0 0 0 0 0 0 0 0 0 0
45309- 0 0 0 0 0 0 0 0 0 0 0 0
45310- 0 0 0 0 0 0 0 0 0 0 0 0
45311- 0 0 0 0 0 0 0 0 0 6 6 6
45312- 22 22 22 62 62 62 62 62 62 2 2 6
45313- 2 2 6 2 2 6 2 2 6 2 2 6
45314- 2 2 6 2 2 6 2 2 6 2 2 6
45315- 2 2 6 2 2 6 2 2 6 26 26 26
45316- 54 54 54 38 38 38 18 18 18 10 10 10
45317- 2 2 6 2 2 6 34 34 34 82 82 82
45318- 38 38 38 14 14 14 0 0 0 0 0 0
45319- 0 0 0 0 0 0 0 0 0 0 0 0
45320- 0 0 0 0 0 0 0 0 0 0 0 0
45321- 0 0 0 0 0 0 0 0 0 0 0 0
45322- 0 0 0 0 0 0 0 0 0 0 0 0
45323- 0 0 0 0 0 0 0 0 0 0 0 0
45324- 0 0 0 0 0 0 0 0 0 0 0 0
45325- 0 0 0 0 0 0 0 0 0 0 0 0
45326- 0 0 0 0 0 1 0 0 1 0 0 0
45327- 0 0 0 0 0 0 0 0 0 0 0 0
45328- 0 0 0 0 0 0 0 0 0 0 0 0
45329- 0 0 0 0 0 0 0 0 0 0 0 0
45330- 0 0 0 0 0 0 0 0 0 0 0 0
45331- 0 0 0 0 0 0 0 0 0 6 6 6
45332- 30 30 30 78 78 78 30 30 30 2 2 6
45333- 2 2 6 2 2 6 2 2 6 2 2 6
45334- 2 2 6 2 2 6 2 2 6 2 2 6
45335- 2 2 6 2 2 6 2 2 6 10 10 10
45336- 10 10 10 2 2 6 2 2 6 2 2 6
45337- 2 2 6 2 2 6 2 2 6 78 78 78
45338- 50 50 50 18 18 18 6 6 6 0 0 0
45339- 0 0 0 0 0 0 0 0 0 0 0 0
45340- 0 0 0 0 0 0 0 0 0 0 0 0
45341- 0 0 0 0 0 0 0 0 0 0 0 0
45342- 0 0 0 0 0 0 0 0 0 0 0 0
45343- 0 0 0 0 0 0 0 0 0 0 0 0
45344- 0 0 0 0 0 0 0 0 0 0 0 0
45345- 0 0 0 0 0 0 0 0 0 0 0 0
45346- 0 0 1 0 0 0 0 0 0 0 0 0
45347- 0 0 0 0 0 0 0 0 0 0 0 0
45348- 0 0 0 0 0 0 0 0 0 0 0 0
45349- 0 0 0 0 0 0 0 0 0 0 0 0
45350- 0 0 0 0 0 0 0 0 0 0 0 0
45351- 0 0 0 0 0 0 0 0 0 10 10 10
45352- 38 38 38 86 86 86 14 14 14 2 2 6
45353- 2 2 6 2 2 6 2 2 6 2 2 6
45354- 2 2 6 2 2 6 2 2 6 2 2 6
45355- 2 2 6 2 2 6 2 2 6 2 2 6
45356- 2 2 6 2 2 6 2 2 6 2 2 6
45357- 2 2 6 2 2 6 2 2 6 54 54 54
45358- 66 66 66 26 26 26 6 6 6 0 0 0
45359- 0 0 0 0 0 0 0 0 0 0 0 0
45360- 0 0 0 0 0 0 0 0 0 0 0 0
45361- 0 0 0 0 0 0 0 0 0 0 0 0
45362- 0 0 0 0 0 0 0 0 0 0 0 0
45363- 0 0 0 0 0 0 0 0 0 0 0 0
45364- 0 0 0 0 0 0 0 0 0 0 0 0
45365- 0 0 0 0 0 0 0 0 0 0 0 0
45366- 0 0 0 0 0 1 0 0 1 0 0 0
45367- 0 0 0 0 0 0 0 0 0 0 0 0
45368- 0 0 0 0 0 0 0 0 0 0 0 0
45369- 0 0 0 0 0 0 0 0 0 0 0 0
45370- 0 0 0 0 0 0 0 0 0 0 0 0
45371- 0 0 0 0 0 0 0 0 0 14 14 14
45372- 42 42 42 82 82 82 2 2 6 2 2 6
45373- 2 2 6 6 6 6 10 10 10 2 2 6
45374- 2 2 6 2 2 6 2 2 6 2 2 6
45375- 2 2 6 2 2 6 2 2 6 6 6 6
45376- 14 14 14 10 10 10 2 2 6 2 2 6
45377- 2 2 6 2 2 6 2 2 6 18 18 18
45378- 82 82 82 34 34 34 10 10 10 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 0 0 0
45384- 0 0 0 0 0 0 0 0 0 0 0 0
45385- 0 0 0 0 0 0 0 0 0 0 0 0
45386- 0 0 1 0 0 0 0 0 0 0 0 0
45387- 0 0 0 0 0 0 0 0 0 0 0 0
45388- 0 0 0 0 0 0 0 0 0 0 0 0
45389- 0 0 0 0 0 0 0 0 0 0 0 0
45390- 0 0 0 0 0 0 0 0 0 0 0 0
45391- 0 0 0 0 0 0 0 0 0 14 14 14
45392- 46 46 46 86 86 86 2 2 6 2 2 6
45393- 6 6 6 6 6 6 22 22 22 34 34 34
45394- 6 6 6 2 2 6 2 2 6 2 2 6
45395- 2 2 6 2 2 6 18 18 18 34 34 34
45396- 10 10 10 50 50 50 22 22 22 2 2 6
45397- 2 2 6 2 2 6 2 2 6 10 10 10
45398- 86 86 86 42 42 42 14 14 14 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 0 0 0
45404- 0 0 0 0 0 0 0 0 0 0 0 0
45405- 0 0 0 0 0 0 0 0 0 0 0 0
45406- 0 0 1 0 0 1 0 0 1 0 0 0
45407- 0 0 0 0 0 0 0 0 0 0 0 0
45408- 0 0 0 0 0 0 0 0 0 0 0 0
45409- 0 0 0 0 0 0 0 0 0 0 0 0
45410- 0 0 0 0 0 0 0 0 0 0 0 0
45411- 0 0 0 0 0 0 0 0 0 14 14 14
45412- 46 46 46 86 86 86 2 2 6 2 2 6
45413- 38 38 38 116 116 116 94 94 94 22 22 22
45414- 22 22 22 2 2 6 2 2 6 2 2 6
45415- 14 14 14 86 86 86 138 138 138 162 162 162
45416-154 154 154 38 38 38 26 26 26 6 6 6
45417- 2 2 6 2 2 6 2 2 6 2 2 6
45418- 86 86 86 46 46 46 14 14 14 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 0 0 0
45424- 0 0 0 0 0 0 0 0 0 0 0 0
45425- 0 0 0 0 0 0 0 0 0 0 0 0
45426- 0 0 0 0 0 0 0 0 0 0 0 0
45427- 0 0 0 0 0 0 0 0 0 0 0 0
45428- 0 0 0 0 0 0 0 0 0 0 0 0
45429- 0 0 0 0 0 0 0 0 0 0 0 0
45430- 0 0 0 0 0 0 0 0 0 0 0 0
45431- 0 0 0 0 0 0 0 0 0 14 14 14
45432- 46 46 46 86 86 86 2 2 6 14 14 14
45433-134 134 134 198 198 198 195 195 195 116 116 116
45434- 10 10 10 2 2 6 2 2 6 6 6 6
45435-101 98 89 187 187 187 210 210 210 218 218 218
45436-214 214 214 134 134 134 14 14 14 6 6 6
45437- 2 2 6 2 2 6 2 2 6 2 2 6
45438- 86 86 86 50 50 50 18 18 18 6 6 6
45439- 0 0 0 0 0 0 0 0 0 0 0 0
45440- 0 0 0 0 0 0 0 0 0 0 0 0
45441- 0 0 0 0 0 0 0 0 0 0 0 0
45442- 0 0 0 0 0 0 0 0 0 0 0 0
45443- 0 0 0 0 0 0 0 0 0 0 0 0
45444- 0 0 0 0 0 0 0 0 0 0 0 0
45445- 0 0 0 0 0 0 0 0 1 0 0 0
45446- 0 0 1 0 0 1 0 0 1 0 0 0
45447- 0 0 0 0 0 0 0 0 0 0 0 0
45448- 0 0 0 0 0 0 0 0 0 0 0 0
45449- 0 0 0 0 0 0 0 0 0 0 0 0
45450- 0 0 0 0 0 0 0 0 0 0 0 0
45451- 0 0 0 0 0 0 0 0 0 14 14 14
45452- 46 46 46 86 86 86 2 2 6 54 54 54
45453-218 218 218 195 195 195 226 226 226 246 246 246
45454- 58 58 58 2 2 6 2 2 6 30 30 30
45455-210 210 210 253 253 253 174 174 174 123 123 123
45456-221 221 221 234 234 234 74 74 74 2 2 6
45457- 2 2 6 2 2 6 2 2 6 2 2 6
45458- 70 70 70 58 58 58 22 22 22 6 6 6
45459- 0 0 0 0 0 0 0 0 0 0 0 0
45460- 0 0 0 0 0 0 0 0 0 0 0 0
45461- 0 0 0 0 0 0 0 0 0 0 0 0
45462- 0 0 0 0 0 0 0 0 0 0 0 0
45463- 0 0 0 0 0 0 0 0 0 0 0 0
45464- 0 0 0 0 0 0 0 0 0 0 0 0
45465- 0 0 0 0 0 0 0 0 0 0 0 0
45466- 0 0 0 0 0 0 0 0 0 0 0 0
45467- 0 0 0 0 0 0 0 0 0 0 0 0
45468- 0 0 0 0 0 0 0 0 0 0 0 0
45469- 0 0 0 0 0 0 0 0 0 0 0 0
45470- 0 0 0 0 0 0 0 0 0 0 0 0
45471- 0 0 0 0 0 0 0 0 0 14 14 14
45472- 46 46 46 82 82 82 2 2 6 106 106 106
45473-170 170 170 26 26 26 86 86 86 226 226 226
45474-123 123 123 10 10 10 14 14 14 46 46 46
45475-231 231 231 190 190 190 6 6 6 70 70 70
45476- 90 90 90 238 238 238 158 158 158 2 2 6
45477- 2 2 6 2 2 6 2 2 6 2 2 6
45478- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
45484- 0 0 0 0 0 0 0 0 0 0 0 0
45485- 0 0 0 0 0 0 0 0 1 0 0 0
45486- 0 0 1 0 0 1 0 0 1 0 0 0
45487- 0 0 0 0 0 0 0 0 0 0 0 0
45488- 0 0 0 0 0 0 0 0 0 0 0 0
45489- 0 0 0 0 0 0 0 0 0 0 0 0
45490- 0 0 0 0 0 0 0 0 0 0 0 0
45491- 0 0 0 0 0 0 0 0 0 14 14 14
45492- 42 42 42 86 86 86 6 6 6 116 116 116
45493-106 106 106 6 6 6 70 70 70 149 149 149
45494-128 128 128 18 18 18 38 38 38 54 54 54
45495-221 221 221 106 106 106 2 2 6 14 14 14
45496- 46 46 46 190 190 190 198 198 198 2 2 6
45497- 2 2 6 2 2 6 2 2 6 2 2 6
45498- 74 74 74 62 62 62 22 22 22 6 6 6
45499- 0 0 0 0 0 0 0 0 0 0 0 0
45500- 0 0 0 0 0 0 0 0 0 0 0 0
45501- 0 0 0 0 0 0 0 0 0 0 0 0
45502- 0 0 0 0 0 0 0 0 0 0 0 0
45503- 0 0 0 0 0 0 0 0 0 0 0 0
45504- 0 0 0 0 0 0 0 0 0 0 0 0
45505- 0 0 0 0 0 0 0 0 1 0 0 0
45506- 0 0 1 0 0 0 0 0 1 0 0 0
45507- 0 0 0 0 0 0 0 0 0 0 0 0
45508- 0 0 0 0 0 0 0 0 0 0 0 0
45509- 0 0 0 0 0 0 0 0 0 0 0 0
45510- 0 0 0 0 0 0 0 0 0 0 0 0
45511- 0 0 0 0 0 0 0 0 0 14 14 14
45512- 42 42 42 94 94 94 14 14 14 101 101 101
45513-128 128 128 2 2 6 18 18 18 116 116 116
45514-118 98 46 121 92 8 121 92 8 98 78 10
45515-162 162 162 106 106 106 2 2 6 2 2 6
45516- 2 2 6 195 195 195 195 195 195 6 6 6
45517- 2 2 6 2 2 6 2 2 6 2 2 6
45518- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
45524- 0 0 0 0 0 0 0 0 0 0 0 0
45525- 0 0 0 0 0 0 0 0 1 0 0 1
45526- 0 0 1 0 0 0 0 0 1 0 0 0
45527- 0 0 0 0 0 0 0 0 0 0 0 0
45528- 0 0 0 0 0 0 0 0 0 0 0 0
45529- 0 0 0 0 0 0 0 0 0 0 0 0
45530- 0 0 0 0 0 0 0 0 0 0 0 0
45531- 0 0 0 0 0 0 0 0 0 10 10 10
45532- 38 38 38 90 90 90 14 14 14 58 58 58
45533-210 210 210 26 26 26 54 38 6 154 114 10
45534-226 170 11 236 186 11 225 175 15 184 144 12
45535-215 174 15 175 146 61 37 26 9 2 2 6
45536- 70 70 70 246 246 246 138 138 138 2 2 6
45537- 2 2 6 2 2 6 2 2 6 2 2 6
45538- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
45544- 0 0 0 0 0 0 0 0 0 0 0 0
45545- 0 0 0 0 0 0 0 0 0 0 0 0
45546- 0 0 0 0 0 0 0 0 0 0 0 0
45547- 0 0 0 0 0 0 0 0 0 0 0 0
45548- 0 0 0 0 0 0 0 0 0 0 0 0
45549- 0 0 0 0 0 0 0 0 0 0 0 0
45550- 0 0 0 0 0 0 0 0 0 0 0 0
45551- 0 0 0 0 0 0 0 0 0 10 10 10
45552- 38 38 38 86 86 86 14 14 14 10 10 10
45553-195 195 195 188 164 115 192 133 9 225 175 15
45554-239 182 13 234 190 10 232 195 16 232 200 30
45555-245 207 45 241 208 19 232 195 16 184 144 12
45556-218 194 134 211 206 186 42 42 42 2 2 6
45557- 2 2 6 2 2 6 2 2 6 2 2 6
45558- 50 50 50 74 74 74 30 30 30 6 6 6
45559- 0 0 0 0 0 0 0 0 0 0 0 0
45560- 0 0 0 0 0 0 0 0 0 0 0 0
45561- 0 0 0 0 0 0 0 0 0 0 0 0
45562- 0 0 0 0 0 0 0 0 0 0 0 0
45563- 0 0 0 0 0 0 0 0 0 0 0 0
45564- 0 0 0 0 0 0 0 0 0 0 0 0
45565- 0 0 0 0 0 0 0 0 0 0 0 0
45566- 0 0 0 0 0 0 0 0 0 0 0 0
45567- 0 0 0 0 0 0 0 0 0 0 0 0
45568- 0 0 0 0 0 0 0 0 0 0 0 0
45569- 0 0 0 0 0 0 0 0 0 0 0 0
45570- 0 0 0 0 0 0 0 0 0 0 0 0
45571- 0 0 0 0 0 0 0 0 0 10 10 10
45572- 34 34 34 86 86 86 14 14 14 2 2 6
45573-121 87 25 192 133 9 219 162 10 239 182 13
45574-236 186 11 232 195 16 241 208 19 244 214 54
45575-246 218 60 246 218 38 246 215 20 241 208 19
45576-241 208 19 226 184 13 121 87 25 2 2 6
45577- 2 2 6 2 2 6 2 2 6 2 2 6
45578- 50 50 50 82 82 82 34 34 34 10 10 10
45579- 0 0 0 0 0 0 0 0 0 0 0 0
45580- 0 0 0 0 0 0 0 0 0 0 0 0
45581- 0 0 0 0 0 0 0 0 0 0 0 0
45582- 0 0 0 0 0 0 0 0 0 0 0 0
45583- 0 0 0 0 0 0 0 0 0 0 0 0
45584- 0 0 0 0 0 0 0 0 0 0 0 0
45585- 0 0 0 0 0 0 0 0 0 0 0 0
45586- 0 0 0 0 0 0 0 0 0 0 0 0
45587- 0 0 0 0 0 0 0 0 0 0 0 0
45588- 0 0 0 0 0 0 0 0 0 0 0 0
45589- 0 0 0 0 0 0 0 0 0 0 0 0
45590- 0 0 0 0 0 0 0 0 0 0 0 0
45591- 0 0 0 0 0 0 0 0 0 10 10 10
45592- 34 34 34 82 82 82 30 30 30 61 42 6
45593-180 123 7 206 145 10 230 174 11 239 182 13
45594-234 190 10 238 202 15 241 208 19 246 218 74
45595-246 218 38 246 215 20 246 215 20 246 215 20
45596-226 184 13 215 174 15 184 144 12 6 6 6
45597- 2 2 6 2 2 6 2 2 6 2 2 6
45598- 26 26 26 94 94 94 42 42 42 14 14 14
45599- 0 0 0 0 0 0 0 0 0 0 0 0
45600- 0 0 0 0 0 0 0 0 0 0 0 0
45601- 0 0 0 0 0 0 0 0 0 0 0 0
45602- 0 0 0 0 0 0 0 0 0 0 0 0
45603- 0 0 0 0 0 0 0 0 0 0 0 0
45604- 0 0 0 0 0 0 0 0 0 0 0 0
45605- 0 0 0 0 0 0 0 0 0 0 0 0
45606- 0 0 0 0 0 0 0 0 0 0 0 0
45607- 0 0 0 0 0 0 0 0 0 0 0 0
45608- 0 0 0 0 0 0 0 0 0 0 0 0
45609- 0 0 0 0 0 0 0 0 0 0 0 0
45610- 0 0 0 0 0 0 0 0 0 0 0 0
45611- 0 0 0 0 0 0 0 0 0 10 10 10
45612- 30 30 30 78 78 78 50 50 50 104 69 6
45613-192 133 9 216 158 10 236 178 12 236 186 11
45614-232 195 16 241 208 19 244 214 54 245 215 43
45615-246 215 20 246 215 20 241 208 19 198 155 10
45616-200 144 11 216 158 10 156 118 10 2 2 6
45617- 2 2 6 2 2 6 2 2 6 2 2 6
45618- 6 6 6 90 90 90 54 54 54 18 18 18
45619- 6 6 6 0 0 0 0 0 0 0 0 0
45620- 0 0 0 0 0 0 0 0 0 0 0 0
45621- 0 0 0 0 0 0 0 0 0 0 0 0
45622- 0 0 0 0 0 0 0 0 0 0 0 0
45623- 0 0 0 0 0 0 0 0 0 0 0 0
45624- 0 0 0 0 0 0 0 0 0 0 0 0
45625- 0 0 0 0 0 0 0 0 0 0 0 0
45626- 0 0 0 0 0 0 0 0 0 0 0 0
45627- 0 0 0 0 0 0 0 0 0 0 0 0
45628- 0 0 0 0 0 0 0 0 0 0 0 0
45629- 0 0 0 0 0 0 0 0 0 0 0 0
45630- 0 0 0 0 0 0 0 0 0 0 0 0
45631- 0 0 0 0 0 0 0 0 0 10 10 10
45632- 30 30 30 78 78 78 46 46 46 22 22 22
45633-137 92 6 210 162 10 239 182 13 238 190 10
45634-238 202 15 241 208 19 246 215 20 246 215 20
45635-241 208 19 203 166 17 185 133 11 210 150 10
45636-216 158 10 210 150 10 102 78 10 2 2 6
45637- 6 6 6 54 54 54 14 14 14 2 2 6
45638- 2 2 6 62 62 62 74 74 74 30 30 30
45639- 10 10 10 0 0 0 0 0 0 0 0 0
45640- 0 0 0 0 0 0 0 0 0 0 0 0
45641- 0 0 0 0 0 0 0 0 0 0 0 0
45642- 0 0 0 0 0 0 0 0 0 0 0 0
45643- 0 0 0 0 0 0 0 0 0 0 0 0
45644- 0 0 0 0 0 0 0 0 0 0 0 0
45645- 0 0 0 0 0 0 0 0 0 0 0 0
45646- 0 0 0 0 0 0 0 0 0 0 0 0
45647- 0 0 0 0 0 0 0 0 0 0 0 0
45648- 0 0 0 0 0 0 0 0 0 0 0 0
45649- 0 0 0 0 0 0 0 0 0 0 0 0
45650- 0 0 0 0 0 0 0 0 0 0 0 0
45651- 0 0 0 0 0 0 0 0 0 10 10 10
45652- 34 34 34 78 78 78 50 50 50 6 6 6
45653- 94 70 30 139 102 15 190 146 13 226 184 13
45654-232 200 30 232 195 16 215 174 15 190 146 13
45655-168 122 10 192 133 9 210 150 10 213 154 11
45656-202 150 34 182 157 106 101 98 89 2 2 6
45657- 2 2 6 78 78 78 116 116 116 58 58 58
45658- 2 2 6 22 22 22 90 90 90 46 46 46
45659- 18 18 18 6 6 6 0 0 0 0 0 0
45660- 0 0 0 0 0 0 0 0 0 0 0 0
45661- 0 0 0 0 0 0 0 0 0 0 0 0
45662- 0 0 0 0 0 0 0 0 0 0 0 0
45663- 0 0 0 0 0 0 0 0 0 0 0 0
45664- 0 0 0 0 0 0 0 0 0 0 0 0
45665- 0 0 0 0 0 0 0 0 0 0 0 0
45666- 0 0 0 0 0 0 0 0 0 0 0 0
45667- 0 0 0 0 0 0 0 0 0 0 0 0
45668- 0 0 0 0 0 0 0 0 0 0 0 0
45669- 0 0 0 0 0 0 0 0 0 0 0 0
45670- 0 0 0 0 0 0 0 0 0 0 0 0
45671- 0 0 0 0 0 0 0 0 0 10 10 10
45672- 38 38 38 86 86 86 50 50 50 6 6 6
45673-128 128 128 174 154 114 156 107 11 168 122 10
45674-198 155 10 184 144 12 197 138 11 200 144 11
45675-206 145 10 206 145 10 197 138 11 188 164 115
45676-195 195 195 198 198 198 174 174 174 14 14 14
45677- 2 2 6 22 22 22 116 116 116 116 116 116
45678- 22 22 22 2 2 6 74 74 74 70 70 70
45679- 30 30 30 10 10 10 0 0 0 0 0 0
45680- 0 0 0 0 0 0 0 0 0 0 0 0
45681- 0 0 0 0 0 0 0 0 0 0 0 0
45682- 0 0 0 0 0 0 0 0 0 0 0 0
45683- 0 0 0 0 0 0 0 0 0 0 0 0
45684- 0 0 0 0 0 0 0 0 0 0 0 0
45685- 0 0 0 0 0 0 0 0 0 0 0 0
45686- 0 0 0 0 0 0 0 0 0 0 0 0
45687- 0 0 0 0 0 0 0 0 0 0 0 0
45688- 0 0 0 0 0 0 0 0 0 0 0 0
45689- 0 0 0 0 0 0 0 0 0 0 0 0
45690- 0 0 0 0 0 0 0 0 0 0 0 0
45691- 0 0 0 0 0 0 6 6 6 18 18 18
45692- 50 50 50 101 101 101 26 26 26 10 10 10
45693-138 138 138 190 190 190 174 154 114 156 107 11
45694-197 138 11 200 144 11 197 138 11 192 133 9
45695-180 123 7 190 142 34 190 178 144 187 187 187
45696-202 202 202 221 221 221 214 214 214 66 66 66
45697- 2 2 6 2 2 6 50 50 50 62 62 62
45698- 6 6 6 2 2 6 10 10 10 90 90 90
45699- 50 50 50 18 18 18 6 6 6 0 0 0
45700- 0 0 0 0 0 0 0 0 0 0 0 0
45701- 0 0 0 0 0 0 0 0 0 0 0 0
45702- 0 0 0 0 0 0 0 0 0 0 0 0
45703- 0 0 0 0 0 0 0 0 0 0 0 0
45704- 0 0 0 0 0 0 0 0 0 0 0 0
45705- 0 0 0 0 0 0 0 0 0 0 0 0
45706- 0 0 0 0 0 0 0 0 0 0 0 0
45707- 0 0 0 0 0 0 0 0 0 0 0 0
45708- 0 0 0 0 0 0 0 0 0 0 0 0
45709- 0 0 0 0 0 0 0 0 0 0 0 0
45710- 0 0 0 0 0 0 0 0 0 0 0 0
45711- 0 0 0 0 0 0 10 10 10 34 34 34
45712- 74 74 74 74 74 74 2 2 6 6 6 6
45713-144 144 144 198 198 198 190 190 190 178 166 146
45714-154 121 60 156 107 11 156 107 11 168 124 44
45715-174 154 114 187 187 187 190 190 190 210 210 210
45716-246 246 246 253 253 253 253 253 253 182 182 182
45717- 6 6 6 2 2 6 2 2 6 2 2 6
45718- 2 2 6 2 2 6 2 2 6 62 62 62
45719- 74 74 74 34 34 34 14 14 14 0 0 0
45720- 0 0 0 0 0 0 0 0 0 0 0 0
45721- 0 0 0 0 0 0 0 0 0 0 0 0
45722- 0 0 0 0 0 0 0 0 0 0 0 0
45723- 0 0 0 0 0 0 0 0 0 0 0 0
45724- 0 0 0 0 0 0 0 0 0 0 0 0
45725- 0 0 0 0 0 0 0 0 0 0 0 0
45726- 0 0 0 0 0 0 0 0 0 0 0 0
45727- 0 0 0 0 0 0 0 0 0 0 0 0
45728- 0 0 0 0 0 0 0 0 0 0 0 0
45729- 0 0 0 0 0 0 0 0 0 0 0 0
45730- 0 0 0 0 0 0 0 0 0 0 0 0
45731- 0 0 0 10 10 10 22 22 22 54 54 54
45732- 94 94 94 18 18 18 2 2 6 46 46 46
45733-234 234 234 221 221 221 190 190 190 190 190 190
45734-190 190 190 187 187 187 187 187 187 190 190 190
45735-190 190 190 195 195 195 214 214 214 242 242 242
45736-253 253 253 253 253 253 253 253 253 253 253 253
45737- 82 82 82 2 2 6 2 2 6 2 2 6
45738- 2 2 6 2 2 6 2 2 6 14 14 14
45739- 86 86 86 54 54 54 22 22 22 6 6 6
45740- 0 0 0 0 0 0 0 0 0 0 0 0
45741- 0 0 0 0 0 0 0 0 0 0 0 0
45742- 0 0 0 0 0 0 0 0 0 0 0 0
45743- 0 0 0 0 0 0 0 0 0 0 0 0
45744- 0 0 0 0 0 0 0 0 0 0 0 0
45745- 0 0 0 0 0 0 0 0 0 0 0 0
45746- 0 0 0 0 0 0 0 0 0 0 0 0
45747- 0 0 0 0 0 0 0 0 0 0 0 0
45748- 0 0 0 0 0 0 0 0 0 0 0 0
45749- 0 0 0 0 0 0 0 0 0 0 0 0
45750- 0 0 0 0 0 0 0 0 0 0 0 0
45751- 6 6 6 18 18 18 46 46 46 90 90 90
45752- 46 46 46 18 18 18 6 6 6 182 182 182
45753-253 253 253 246 246 246 206 206 206 190 190 190
45754-190 190 190 190 190 190 190 190 190 190 190 190
45755-206 206 206 231 231 231 250 250 250 253 253 253
45756-253 253 253 253 253 253 253 253 253 253 253 253
45757-202 202 202 14 14 14 2 2 6 2 2 6
45758- 2 2 6 2 2 6 2 2 6 2 2 6
45759- 42 42 42 86 86 86 42 42 42 18 18 18
45760- 6 6 6 0 0 0 0 0 0 0 0 0
45761- 0 0 0 0 0 0 0 0 0 0 0 0
45762- 0 0 0 0 0 0 0 0 0 0 0 0
45763- 0 0 0 0 0 0 0 0 0 0 0 0
45764- 0 0 0 0 0 0 0 0 0 0 0 0
45765- 0 0 0 0 0 0 0 0 0 0 0 0
45766- 0 0 0 0 0 0 0 0 0 0 0 0
45767- 0 0 0 0 0 0 0 0 0 0 0 0
45768- 0 0 0 0 0 0 0 0 0 0 0 0
45769- 0 0 0 0 0 0 0 0 0 0 0 0
45770- 0 0 0 0 0 0 0 0 0 6 6 6
45771- 14 14 14 38 38 38 74 74 74 66 66 66
45772- 2 2 6 6 6 6 90 90 90 250 250 250
45773-253 253 253 253 253 253 238 238 238 198 198 198
45774-190 190 190 190 190 190 195 195 195 221 221 221
45775-246 246 246 253 253 253 253 253 253 253 253 253
45776-253 253 253 253 253 253 253 253 253 253 253 253
45777-253 253 253 82 82 82 2 2 6 2 2 6
45778- 2 2 6 2 2 6 2 2 6 2 2 6
45779- 2 2 6 78 78 78 70 70 70 34 34 34
45780- 14 14 14 6 6 6 0 0 0 0 0 0
45781- 0 0 0 0 0 0 0 0 0 0 0 0
45782- 0 0 0 0 0 0 0 0 0 0 0 0
45783- 0 0 0 0 0 0 0 0 0 0 0 0
45784- 0 0 0 0 0 0 0 0 0 0 0 0
45785- 0 0 0 0 0 0 0 0 0 0 0 0
45786- 0 0 0 0 0 0 0 0 0 0 0 0
45787- 0 0 0 0 0 0 0 0 0 0 0 0
45788- 0 0 0 0 0 0 0 0 0 0 0 0
45789- 0 0 0 0 0 0 0 0 0 0 0 0
45790- 0 0 0 0 0 0 0 0 0 14 14 14
45791- 34 34 34 66 66 66 78 78 78 6 6 6
45792- 2 2 6 18 18 18 218 218 218 253 253 253
45793-253 253 253 253 253 253 253 253 253 246 246 246
45794-226 226 226 231 231 231 246 246 246 253 253 253
45795-253 253 253 253 253 253 253 253 253 253 253 253
45796-253 253 253 253 253 253 253 253 253 253 253 253
45797-253 253 253 178 178 178 2 2 6 2 2 6
45798- 2 2 6 2 2 6 2 2 6 2 2 6
45799- 2 2 6 18 18 18 90 90 90 62 62 62
45800- 30 30 30 10 10 10 0 0 0 0 0 0
45801- 0 0 0 0 0 0 0 0 0 0 0 0
45802- 0 0 0 0 0 0 0 0 0 0 0 0
45803- 0 0 0 0 0 0 0 0 0 0 0 0
45804- 0 0 0 0 0 0 0 0 0 0 0 0
45805- 0 0 0 0 0 0 0 0 0 0 0 0
45806- 0 0 0 0 0 0 0 0 0 0 0 0
45807- 0 0 0 0 0 0 0 0 0 0 0 0
45808- 0 0 0 0 0 0 0 0 0 0 0 0
45809- 0 0 0 0 0 0 0 0 0 0 0 0
45810- 0 0 0 0 0 0 10 10 10 26 26 26
45811- 58 58 58 90 90 90 18 18 18 2 2 6
45812- 2 2 6 110 110 110 253 253 253 253 253 253
45813-253 253 253 253 253 253 253 253 253 253 253 253
45814-250 250 250 253 253 253 253 253 253 253 253 253
45815-253 253 253 253 253 253 253 253 253 253 253 253
45816-253 253 253 253 253 253 253 253 253 253 253 253
45817-253 253 253 231 231 231 18 18 18 2 2 6
45818- 2 2 6 2 2 6 2 2 6 2 2 6
45819- 2 2 6 2 2 6 18 18 18 94 94 94
45820- 54 54 54 26 26 26 10 10 10 0 0 0
45821- 0 0 0 0 0 0 0 0 0 0 0 0
45822- 0 0 0 0 0 0 0 0 0 0 0 0
45823- 0 0 0 0 0 0 0 0 0 0 0 0
45824- 0 0 0 0 0 0 0 0 0 0 0 0
45825- 0 0 0 0 0 0 0 0 0 0 0 0
45826- 0 0 0 0 0 0 0 0 0 0 0 0
45827- 0 0 0 0 0 0 0 0 0 0 0 0
45828- 0 0 0 0 0 0 0 0 0 0 0 0
45829- 0 0 0 0 0 0 0 0 0 0 0 0
45830- 0 0 0 6 6 6 22 22 22 50 50 50
45831- 90 90 90 26 26 26 2 2 6 2 2 6
45832- 14 14 14 195 195 195 250 250 250 253 253 253
45833-253 253 253 253 253 253 253 253 253 253 253 253
45834-253 253 253 253 253 253 253 253 253 253 253 253
45835-253 253 253 253 253 253 253 253 253 253 253 253
45836-253 253 253 253 253 253 253 253 253 253 253 253
45837-250 250 250 242 242 242 54 54 54 2 2 6
45838- 2 2 6 2 2 6 2 2 6 2 2 6
45839- 2 2 6 2 2 6 2 2 6 38 38 38
45840- 86 86 86 50 50 50 22 22 22 6 6 6
45841- 0 0 0 0 0 0 0 0 0 0 0 0
45842- 0 0 0 0 0 0 0 0 0 0 0 0
45843- 0 0 0 0 0 0 0 0 0 0 0 0
45844- 0 0 0 0 0 0 0 0 0 0 0 0
45845- 0 0 0 0 0 0 0 0 0 0 0 0
45846- 0 0 0 0 0 0 0 0 0 0 0 0
45847- 0 0 0 0 0 0 0 0 0 0 0 0
45848- 0 0 0 0 0 0 0 0 0 0 0 0
45849- 0 0 0 0 0 0 0 0 0 0 0 0
45850- 6 6 6 14 14 14 38 38 38 82 82 82
45851- 34 34 34 2 2 6 2 2 6 2 2 6
45852- 42 42 42 195 195 195 246 246 246 253 253 253
45853-253 253 253 253 253 253 253 253 253 250 250 250
45854-242 242 242 242 242 242 250 250 250 253 253 253
45855-253 253 253 253 253 253 253 253 253 253 253 253
45856-253 253 253 250 250 250 246 246 246 238 238 238
45857-226 226 226 231 231 231 101 101 101 6 6 6
45858- 2 2 6 2 2 6 2 2 6 2 2 6
45859- 2 2 6 2 2 6 2 2 6 2 2 6
45860- 38 38 38 82 82 82 42 42 42 14 14 14
45861- 6 6 6 0 0 0 0 0 0 0 0 0
45862- 0 0 0 0 0 0 0 0 0 0 0 0
45863- 0 0 0 0 0 0 0 0 0 0 0 0
45864- 0 0 0 0 0 0 0 0 0 0 0 0
45865- 0 0 0 0 0 0 0 0 0 0 0 0
45866- 0 0 0 0 0 0 0 0 0 0 0 0
45867- 0 0 0 0 0 0 0 0 0 0 0 0
45868- 0 0 0 0 0 0 0 0 0 0 0 0
45869- 0 0 0 0 0 0 0 0 0 0 0 0
45870- 10 10 10 26 26 26 62 62 62 66 66 66
45871- 2 2 6 2 2 6 2 2 6 6 6 6
45872- 70 70 70 170 170 170 206 206 206 234 234 234
45873-246 246 246 250 250 250 250 250 250 238 238 238
45874-226 226 226 231 231 231 238 238 238 250 250 250
45875-250 250 250 250 250 250 246 246 246 231 231 231
45876-214 214 214 206 206 206 202 202 202 202 202 202
45877-198 198 198 202 202 202 182 182 182 18 18 18
45878- 2 2 6 2 2 6 2 2 6 2 2 6
45879- 2 2 6 2 2 6 2 2 6 2 2 6
45880- 2 2 6 62 62 62 66 66 66 30 30 30
45881- 10 10 10 0 0 0 0 0 0 0 0 0
45882- 0 0 0 0 0 0 0 0 0 0 0 0
45883- 0 0 0 0 0 0 0 0 0 0 0 0
45884- 0 0 0 0 0 0 0 0 0 0 0 0
45885- 0 0 0 0 0 0 0 0 0 0 0 0
45886- 0 0 0 0 0 0 0 0 0 0 0 0
45887- 0 0 0 0 0 0 0 0 0 0 0 0
45888- 0 0 0 0 0 0 0 0 0 0 0 0
45889- 0 0 0 0 0 0 0 0 0 0 0 0
45890- 14 14 14 42 42 42 82 82 82 18 18 18
45891- 2 2 6 2 2 6 2 2 6 10 10 10
45892- 94 94 94 182 182 182 218 218 218 242 242 242
45893-250 250 250 253 253 253 253 253 253 250 250 250
45894-234 234 234 253 253 253 253 253 253 253 253 253
45895-253 253 253 253 253 253 253 253 253 246 246 246
45896-238 238 238 226 226 226 210 210 210 202 202 202
45897-195 195 195 195 195 195 210 210 210 158 158 158
45898- 6 6 6 14 14 14 50 50 50 14 14 14
45899- 2 2 6 2 2 6 2 2 6 2 2 6
45900- 2 2 6 6 6 6 86 86 86 46 46 46
45901- 18 18 18 6 6 6 0 0 0 0 0 0
45902- 0 0 0 0 0 0 0 0 0 0 0 0
45903- 0 0 0 0 0 0 0 0 0 0 0 0
45904- 0 0 0 0 0 0 0 0 0 0 0 0
45905- 0 0 0 0 0 0 0 0 0 0 0 0
45906- 0 0 0 0 0 0 0 0 0 0 0 0
45907- 0 0 0 0 0 0 0 0 0 0 0 0
45908- 0 0 0 0 0 0 0 0 0 0 0 0
45909- 0 0 0 0 0 0 0 0 0 6 6 6
45910- 22 22 22 54 54 54 70 70 70 2 2 6
45911- 2 2 6 10 10 10 2 2 6 22 22 22
45912-166 166 166 231 231 231 250 250 250 253 253 253
45913-253 253 253 253 253 253 253 253 253 250 250 250
45914-242 242 242 253 253 253 253 253 253 253 253 253
45915-253 253 253 253 253 253 253 253 253 253 253 253
45916-253 253 253 253 253 253 253 253 253 246 246 246
45917-231 231 231 206 206 206 198 198 198 226 226 226
45918- 94 94 94 2 2 6 6 6 6 38 38 38
45919- 30 30 30 2 2 6 2 2 6 2 2 6
45920- 2 2 6 2 2 6 62 62 62 66 66 66
45921- 26 26 26 10 10 10 0 0 0 0 0 0
45922- 0 0 0 0 0 0 0 0 0 0 0 0
45923- 0 0 0 0 0 0 0 0 0 0 0 0
45924- 0 0 0 0 0 0 0 0 0 0 0 0
45925- 0 0 0 0 0 0 0 0 0 0 0 0
45926- 0 0 0 0 0 0 0 0 0 0 0 0
45927- 0 0 0 0 0 0 0 0 0 0 0 0
45928- 0 0 0 0 0 0 0 0 0 0 0 0
45929- 0 0 0 0 0 0 0 0 0 10 10 10
45930- 30 30 30 74 74 74 50 50 50 2 2 6
45931- 26 26 26 26 26 26 2 2 6 106 106 106
45932-238 238 238 253 253 253 253 253 253 253 253 253
45933-253 253 253 253 253 253 253 253 253 253 253 253
45934-253 253 253 253 253 253 253 253 253 253 253 253
45935-253 253 253 253 253 253 253 253 253 253 253 253
45936-253 253 253 253 253 253 253 253 253 253 253 253
45937-253 253 253 246 246 246 218 218 218 202 202 202
45938-210 210 210 14 14 14 2 2 6 2 2 6
45939- 30 30 30 22 22 22 2 2 6 2 2 6
45940- 2 2 6 2 2 6 18 18 18 86 86 86
45941- 42 42 42 14 14 14 0 0 0 0 0 0
45942- 0 0 0 0 0 0 0 0 0 0 0 0
45943- 0 0 0 0 0 0 0 0 0 0 0 0
45944- 0 0 0 0 0 0 0 0 0 0 0 0
45945- 0 0 0 0 0 0 0 0 0 0 0 0
45946- 0 0 0 0 0 0 0 0 0 0 0 0
45947- 0 0 0 0 0 0 0 0 0 0 0 0
45948- 0 0 0 0 0 0 0 0 0 0 0 0
45949- 0 0 0 0 0 0 0 0 0 14 14 14
45950- 42 42 42 90 90 90 22 22 22 2 2 6
45951- 42 42 42 2 2 6 18 18 18 218 218 218
45952-253 253 253 253 253 253 253 253 253 253 253 253
45953-253 253 253 253 253 253 253 253 253 253 253 253
45954-253 253 253 253 253 253 253 253 253 253 253 253
45955-253 253 253 253 253 253 253 253 253 253 253 253
45956-253 253 253 253 253 253 253 253 253 253 253 253
45957-253 253 253 253 253 253 250 250 250 221 221 221
45958-218 218 218 101 101 101 2 2 6 14 14 14
45959- 18 18 18 38 38 38 10 10 10 2 2 6
45960- 2 2 6 2 2 6 2 2 6 78 78 78
45961- 58 58 58 22 22 22 6 6 6 0 0 0
45962- 0 0 0 0 0 0 0 0 0 0 0 0
45963- 0 0 0 0 0 0 0 0 0 0 0 0
45964- 0 0 0 0 0 0 0 0 0 0 0 0
45965- 0 0 0 0 0 0 0 0 0 0 0 0
45966- 0 0 0 0 0 0 0 0 0 0 0 0
45967- 0 0 0 0 0 0 0 0 0 0 0 0
45968- 0 0 0 0 0 0 0 0 0 0 0 0
45969- 0 0 0 0 0 0 6 6 6 18 18 18
45970- 54 54 54 82 82 82 2 2 6 26 26 26
45971- 22 22 22 2 2 6 123 123 123 253 253 253
45972-253 253 253 253 253 253 253 253 253 253 253 253
45973-253 253 253 253 253 253 253 253 253 253 253 253
45974-253 253 253 253 253 253 253 253 253 253 253 253
45975-253 253 253 253 253 253 253 253 253 253 253 253
45976-253 253 253 253 253 253 253 253 253 253 253 253
45977-253 253 253 253 253 253 253 253 253 250 250 250
45978-238 238 238 198 198 198 6 6 6 38 38 38
45979- 58 58 58 26 26 26 38 38 38 2 2 6
45980- 2 2 6 2 2 6 2 2 6 46 46 46
45981- 78 78 78 30 30 30 10 10 10 0 0 0
45982- 0 0 0 0 0 0 0 0 0 0 0 0
45983- 0 0 0 0 0 0 0 0 0 0 0 0
45984- 0 0 0 0 0 0 0 0 0 0 0 0
45985- 0 0 0 0 0 0 0 0 0 0 0 0
45986- 0 0 0 0 0 0 0 0 0 0 0 0
45987- 0 0 0 0 0 0 0 0 0 0 0 0
45988- 0 0 0 0 0 0 0 0 0 0 0 0
45989- 0 0 0 0 0 0 10 10 10 30 30 30
45990- 74 74 74 58 58 58 2 2 6 42 42 42
45991- 2 2 6 22 22 22 231 231 231 253 253 253
45992-253 253 253 253 253 253 253 253 253 253 253 253
45993-253 253 253 253 253 253 253 253 253 250 250 250
45994-253 253 253 253 253 253 253 253 253 253 253 253
45995-253 253 253 253 253 253 253 253 253 253 253 253
45996-253 253 253 253 253 253 253 253 253 253 253 253
45997-253 253 253 253 253 253 253 253 253 253 253 253
45998-253 253 253 246 246 246 46 46 46 38 38 38
45999- 42 42 42 14 14 14 38 38 38 14 14 14
46000- 2 2 6 2 2 6 2 2 6 6 6 6
46001- 86 86 86 46 46 46 14 14 14 0 0 0
46002- 0 0 0 0 0 0 0 0 0 0 0 0
46003- 0 0 0 0 0 0 0 0 0 0 0 0
46004- 0 0 0 0 0 0 0 0 0 0 0 0
46005- 0 0 0 0 0 0 0 0 0 0 0 0
46006- 0 0 0 0 0 0 0 0 0 0 0 0
46007- 0 0 0 0 0 0 0 0 0 0 0 0
46008- 0 0 0 0 0 0 0 0 0 0 0 0
46009- 0 0 0 6 6 6 14 14 14 42 42 42
46010- 90 90 90 18 18 18 18 18 18 26 26 26
46011- 2 2 6 116 116 116 253 253 253 253 253 253
46012-253 253 253 253 253 253 253 253 253 253 253 253
46013-253 253 253 253 253 253 250 250 250 238 238 238
46014-253 253 253 253 253 253 253 253 253 253 253 253
46015-253 253 253 253 253 253 253 253 253 253 253 253
46016-253 253 253 253 253 253 253 253 253 253 253 253
46017-253 253 253 253 253 253 253 253 253 253 253 253
46018-253 253 253 253 253 253 94 94 94 6 6 6
46019- 2 2 6 2 2 6 10 10 10 34 34 34
46020- 2 2 6 2 2 6 2 2 6 2 2 6
46021- 74 74 74 58 58 58 22 22 22 6 6 6
46022- 0 0 0 0 0 0 0 0 0 0 0 0
46023- 0 0 0 0 0 0 0 0 0 0 0 0
46024- 0 0 0 0 0 0 0 0 0 0 0 0
46025- 0 0 0 0 0 0 0 0 0 0 0 0
46026- 0 0 0 0 0 0 0 0 0 0 0 0
46027- 0 0 0 0 0 0 0 0 0 0 0 0
46028- 0 0 0 0 0 0 0 0 0 0 0 0
46029- 0 0 0 10 10 10 26 26 26 66 66 66
46030- 82 82 82 2 2 6 38 38 38 6 6 6
46031- 14 14 14 210 210 210 253 253 253 253 253 253
46032-253 253 253 253 253 253 253 253 253 253 253 253
46033-253 253 253 253 253 253 246 246 246 242 242 242
46034-253 253 253 253 253 253 253 253 253 253 253 253
46035-253 253 253 253 253 253 253 253 253 253 253 253
46036-253 253 253 253 253 253 253 253 253 253 253 253
46037-253 253 253 253 253 253 253 253 253 253 253 253
46038-253 253 253 253 253 253 144 144 144 2 2 6
46039- 2 2 6 2 2 6 2 2 6 46 46 46
46040- 2 2 6 2 2 6 2 2 6 2 2 6
46041- 42 42 42 74 74 74 30 30 30 10 10 10
46042- 0 0 0 0 0 0 0 0 0 0 0 0
46043- 0 0 0 0 0 0 0 0 0 0 0 0
46044- 0 0 0 0 0 0 0 0 0 0 0 0
46045- 0 0 0 0 0 0 0 0 0 0 0 0
46046- 0 0 0 0 0 0 0 0 0 0 0 0
46047- 0 0 0 0 0 0 0 0 0 0 0 0
46048- 0 0 0 0 0 0 0 0 0 0 0 0
46049- 6 6 6 14 14 14 42 42 42 90 90 90
46050- 26 26 26 6 6 6 42 42 42 2 2 6
46051- 74 74 74 250 250 250 253 253 253 253 253 253
46052-253 253 253 253 253 253 253 253 253 253 253 253
46053-253 253 253 253 253 253 242 242 242 242 242 242
46054-253 253 253 253 253 253 253 253 253 253 253 253
46055-253 253 253 253 253 253 253 253 253 253 253 253
46056-253 253 253 253 253 253 253 253 253 253 253 253
46057-253 253 253 253 253 253 253 253 253 253 253 253
46058-253 253 253 253 253 253 182 182 182 2 2 6
46059- 2 2 6 2 2 6 2 2 6 46 46 46
46060- 2 2 6 2 2 6 2 2 6 2 2 6
46061- 10 10 10 86 86 86 38 38 38 10 10 10
46062- 0 0 0 0 0 0 0 0 0 0 0 0
46063- 0 0 0 0 0 0 0 0 0 0 0 0
46064- 0 0 0 0 0 0 0 0 0 0 0 0
46065- 0 0 0 0 0 0 0 0 0 0 0 0
46066- 0 0 0 0 0 0 0 0 0 0 0 0
46067- 0 0 0 0 0 0 0 0 0 0 0 0
46068- 0 0 0 0 0 0 0 0 0 0 0 0
46069- 10 10 10 26 26 26 66 66 66 82 82 82
46070- 2 2 6 22 22 22 18 18 18 2 2 6
46071-149 149 149 253 253 253 253 253 253 253 253 253
46072-253 253 253 253 253 253 253 253 253 253 253 253
46073-253 253 253 253 253 253 234 234 234 242 242 242
46074-253 253 253 253 253 253 253 253 253 253 253 253
46075-253 253 253 253 253 253 253 253 253 253 253 253
46076-253 253 253 253 253 253 253 253 253 253 253 253
46077-253 253 253 253 253 253 253 253 253 253 253 253
46078-253 253 253 253 253 253 206 206 206 2 2 6
46079- 2 2 6 2 2 6 2 2 6 38 38 38
46080- 2 2 6 2 2 6 2 2 6 2 2 6
46081- 6 6 6 86 86 86 46 46 46 14 14 14
46082- 0 0 0 0 0 0 0 0 0 0 0 0
46083- 0 0 0 0 0 0 0 0 0 0 0 0
46084- 0 0 0 0 0 0 0 0 0 0 0 0
46085- 0 0 0 0 0 0 0 0 0 0 0 0
46086- 0 0 0 0 0 0 0 0 0 0 0 0
46087- 0 0 0 0 0 0 0 0 0 0 0 0
46088- 0 0 0 0 0 0 0 0 0 6 6 6
46089- 18 18 18 46 46 46 86 86 86 18 18 18
46090- 2 2 6 34 34 34 10 10 10 6 6 6
46091-210 210 210 253 253 253 253 253 253 253 253 253
46092-253 253 253 253 253 253 253 253 253 253 253 253
46093-253 253 253 253 253 253 234 234 234 242 242 242
46094-253 253 253 253 253 253 253 253 253 253 253 253
46095-253 253 253 253 253 253 253 253 253 253 253 253
46096-253 253 253 253 253 253 253 253 253 253 253 253
46097-253 253 253 253 253 253 253 253 253 253 253 253
46098-253 253 253 253 253 253 221 221 221 6 6 6
46099- 2 2 6 2 2 6 6 6 6 30 30 30
46100- 2 2 6 2 2 6 2 2 6 2 2 6
46101- 2 2 6 82 82 82 54 54 54 18 18 18
46102- 6 6 6 0 0 0 0 0 0 0 0 0
46103- 0 0 0 0 0 0 0 0 0 0 0 0
46104- 0 0 0 0 0 0 0 0 0 0 0 0
46105- 0 0 0 0 0 0 0 0 0 0 0 0
46106- 0 0 0 0 0 0 0 0 0 0 0 0
46107- 0 0 0 0 0 0 0 0 0 0 0 0
46108- 0 0 0 0 0 0 0 0 0 10 10 10
46109- 26 26 26 66 66 66 62 62 62 2 2 6
46110- 2 2 6 38 38 38 10 10 10 26 26 26
46111-238 238 238 253 253 253 253 253 253 253 253 253
46112-253 253 253 253 253 253 253 253 253 253 253 253
46113-253 253 253 253 253 253 231 231 231 238 238 238
46114-253 253 253 253 253 253 253 253 253 253 253 253
46115-253 253 253 253 253 253 253 253 253 253 253 253
46116-253 253 253 253 253 253 253 253 253 253 253 253
46117-253 253 253 253 253 253 253 253 253 253 253 253
46118-253 253 253 253 253 253 231 231 231 6 6 6
46119- 2 2 6 2 2 6 10 10 10 30 30 30
46120- 2 2 6 2 2 6 2 2 6 2 2 6
46121- 2 2 6 66 66 66 58 58 58 22 22 22
46122- 6 6 6 0 0 0 0 0 0 0 0 0
46123- 0 0 0 0 0 0 0 0 0 0 0 0
46124- 0 0 0 0 0 0 0 0 0 0 0 0
46125- 0 0 0 0 0 0 0 0 0 0 0 0
46126- 0 0 0 0 0 0 0 0 0 0 0 0
46127- 0 0 0 0 0 0 0 0 0 0 0 0
46128- 0 0 0 0 0 0 0 0 0 10 10 10
46129- 38 38 38 78 78 78 6 6 6 2 2 6
46130- 2 2 6 46 46 46 14 14 14 42 42 42
46131-246 246 246 253 253 253 253 253 253 253 253 253
46132-253 253 253 253 253 253 253 253 253 253 253 253
46133-253 253 253 253 253 253 231 231 231 242 242 242
46134-253 253 253 253 253 253 253 253 253 253 253 253
46135-253 253 253 253 253 253 253 253 253 253 253 253
46136-253 253 253 253 253 253 253 253 253 253 253 253
46137-253 253 253 253 253 253 253 253 253 253 253 253
46138-253 253 253 253 253 253 234 234 234 10 10 10
46139- 2 2 6 2 2 6 22 22 22 14 14 14
46140- 2 2 6 2 2 6 2 2 6 2 2 6
46141- 2 2 6 66 66 66 62 62 62 22 22 22
46142- 6 6 6 0 0 0 0 0 0 0 0 0
46143- 0 0 0 0 0 0 0 0 0 0 0 0
46144- 0 0 0 0 0 0 0 0 0 0 0 0
46145- 0 0 0 0 0 0 0 0 0 0 0 0
46146- 0 0 0 0 0 0 0 0 0 0 0 0
46147- 0 0 0 0 0 0 0 0 0 0 0 0
46148- 0 0 0 0 0 0 6 6 6 18 18 18
46149- 50 50 50 74 74 74 2 2 6 2 2 6
46150- 14 14 14 70 70 70 34 34 34 62 62 62
46151-250 250 250 253 253 253 253 253 253 253 253 253
46152-253 253 253 253 253 253 253 253 253 253 253 253
46153-253 253 253 253 253 253 231 231 231 246 246 246
46154-253 253 253 253 253 253 253 253 253 253 253 253
46155-253 253 253 253 253 253 253 253 253 253 253 253
46156-253 253 253 253 253 253 253 253 253 253 253 253
46157-253 253 253 253 253 253 253 253 253 253 253 253
46158-253 253 253 253 253 253 234 234 234 14 14 14
46159- 2 2 6 2 2 6 30 30 30 2 2 6
46160- 2 2 6 2 2 6 2 2 6 2 2 6
46161- 2 2 6 66 66 66 62 62 62 22 22 22
46162- 6 6 6 0 0 0 0 0 0 0 0 0
46163- 0 0 0 0 0 0 0 0 0 0 0 0
46164- 0 0 0 0 0 0 0 0 0 0 0 0
46165- 0 0 0 0 0 0 0 0 0 0 0 0
46166- 0 0 0 0 0 0 0 0 0 0 0 0
46167- 0 0 0 0 0 0 0 0 0 0 0 0
46168- 0 0 0 0 0 0 6 6 6 18 18 18
46169- 54 54 54 62 62 62 2 2 6 2 2 6
46170- 2 2 6 30 30 30 46 46 46 70 70 70
46171-250 250 250 253 253 253 253 253 253 253 253 253
46172-253 253 253 253 253 253 253 253 253 253 253 253
46173-253 253 253 253 253 253 231 231 231 246 246 246
46174-253 253 253 253 253 253 253 253 253 253 253 253
46175-253 253 253 253 253 253 253 253 253 253 253 253
46176-253 253 253 253 253 253 253 253 253 253 253 253
46177-253 253 253 253 253 253 253 253 253 253 253 253
46178-253 253 253 253 253 253 226 226 226 10 10 10
46179- 2 2 6 6 6 6 30 30 30 2 2 6
46180- 2 2 6 2 2 6 2 2 6 2 2 6
46181- 2 2 6 66 66 66 58 58 58 22 22 22
46182- 6 6 6 0 0 0 0 0 0 0 0 0
46183- 0 0 0 0 0 0 0 0 0 0 0 0
46184- 0 0 0 0 0 0 0 0 0 0 0 0
46185- 0 0 0 0 0 0 0 0 0 0 0 0
46186- 0 0 0 0 0 0 0 0 0 0 0 0
46187- 0 0 0 0 0 0 0 0 0 0 0 0
46188- 0 0 0 0 0 0 6 6 6 22 22 22
46189- 58 58 58 62 62 62 2 2 6 2 2 6
46190- 2 2 6 2 2 6 30 30 30 78 78 78
46191-250 250 250 253 253 253 253 253 253 253 253 253
46192-253 253 253 253 253 253 253 253 253 253 253 253
46193-253 253 253 253 253 253 231 231 231 246 246 246
46194-253 253 253 253 253 253 253 253 253 253 253 253
46195-253 253 253 253 253 253 253 253 253 253 253 253
46196-253 253 253 253 253 253 253 253 253 253 253 253
46197-253 253 253 253 253 253 253 253 253 253 253 253
46198-253 253 253 253 253 253 206 206 206 2 2 6
46199- 22 22 22 34 34 34 18 14 6 22 22 22
46200- 26 26 26 18 18 18 6 6 6 2 2 6
46201- 2 2 6 82 82 82 54 54 54 18 18 18
46202- 6 6 6 0 0 0 0 0 0 0 0 0
46203- 0 0 0 0 0 0 0 0 0 0 0 0
46204- 0 0 0 0 0 0 0 0 0 0 0 0
46205- 0 0 0 0 0 0 0 0 0 0 0 0
46206- 0 0 0 0 0 0 0 0 0 0 0 0
46207- 0 0 0 0 0 0 0 0 0 0 0 0
46208- 0 0 0 0 0 0 6 6 6 26 26 26
46209- 62 62 62 106 106 106 74 54 14 185 133 11
46210-210 162 10 121 92 8 6 6 6 62 62 62
46211-238 238 238 253 253 253 253 253 253 253 253 253
46212-253 253 253 253 253 253 253 253 253 253 253 253
46213-253 253 253 253 253 253 231 231 231 246 246 246
46214-253 253 253 253 253 253 253 253 253 253 253 253
46215-253 253 253 253 253 253 253 253 253 253 253 253
46216-253 253 253 253 253 253 253 253 253 253 253 253
46217-253 253 253 253 253 253 253 253 253 253 253 253
46218-253 253 253 253 253 253 158 158 158 18 18 18
46219- 14 14 14 2 2 6 2 2 6 2 2 6
46220- 6 6 6 18 18 18 66 66 66 38 38 38
46221- 6 6 6 94 94 94 50 50 50 18 18 18
46222- 6 6 6 0 0 0 0 0 0 0 0 0
46223- 0 0 0 0 0 0 0 0 0 0 0 0
46224- 0 0 0 0 0 0 0 0 0 0 0 0
46225- 0 0 0 0 0 0 0 0 0 0 0 0
46226- 0 0 0 0 0 0 0 0 0 0 0 0
46227- 0 0 0 0 0 0 0 0 0 6 6 6
46228- 10 10 10 10 10 10 18 18 18 38 38 38
46229- 78 78 78 142 134 106 216 158 10 242 186 14
46230-246 190 14 246 190 14 156 118 10 10 10 10
46231- 90 90 90 238 238 238 253 253 253 253 253 253
46232-253 253 253 253 253 253 253 253 253 253 253 253
46233-253 253 253 253 253 253 231 231 231 250 250 250
46234-253 253 253 253 253 253 253 253 253 253 253 253
46235-253 253 253 253 253 253 253 253 253 253 253 253
46236-253 253 253 253 253 253 253 253 253 253 253 253
46237-253 253 253 253 253 253 253 253 253 246 230 190
46238-238 204 91 238 204 91 181 142 44 37 26 9
46239- 2 2 6 2 2 6 2 2 6 2 2 6
46240- 2 2 6 2 2 6 38 38 38 46 46 46
46241- 26 26 26 106 106 106 54 54 54 18 18 18
46242- 6 6 6 0 0 0 0 0 0 0 0 0
46243- 0 0 0 0 0 0 0 0 0 0 0 0
46244- 0 0 0 0 0 0 0 0 0 0 0 0
46245- 0 0 0 0 0 0 0 0 0 0 0 0
46246- 0 0 0 0 0 0 0 0 0 0 0 0
46247- 0 0 0 6 6 6 14 14 14 22 22 22
46248- 30 30 30 38 38 38 50 50 50 70 70 70
46249-106 106 106 190 142 34 226 170 11 242 186 14
46250-246 190 14 246 190 14 246 190 14 154 114 10
46251- 6 6 6 74 74 74 226 226 226 253 253 253
46252-253 253 253 253 253 253 253 253 253 253 253 253
46253-253 253 253 253 253 253 231 231 231 250 250 250
46254-253 253 253 253 253 253 253 253 253 253 253 253
46255-253 253 253 253 253 253 253 253 253 253 253 253
46256-253 253 253 253 253 253 253 253 253 253 253 253
46257-253 253 253 253 253 253 253 253 253 228 184 62
46258-241 196 14 241 208 19 232 195 16 38 30 10
46259- 2 2 6 2 2 6 2 2 6 2 2 6
46260- 2 2 6 6 6 6 30 30 30 26 26 26
46261-203 166 17 154 142 90 66 66 66 26 26 26
46262- 6 6 6 0 0 0 0 0 0 0 0 0
46263- 0 0 0 0 0 0 0 0 0 0 0 0
46264- 0 0 0 0 0 0 0 0 0 0 0 0
46265- 0 0 0 0 0 0 0 0 0 0 0 0
46266- 0 0 0 0 0 0 0 0 0 0 0 0
46267- 6 6 6 18 18 18 38 38 38 58 58 58
46268- 78 78 78 86 86 86 101 101 101 123 123 123
46269-175 146 61 210 150 10 234 174 13 246 186 14
46270-246 190 14 246 190 14 246 190 14 238 190 10
46271-102 78 10 2 2 6 46 46 46 198 198 198
46272-253 253 253 253 253 253 253 253 253 253 253 253
46273-253 253 253 253 253 253 234 234 234 242 242 242
46274-253 253 253 253 253 253 253 253 253 253 253 253
46275-253 253 253 253 253 253 253 253 253 253 253 253
46276-253 253 253 253 253 253 253 253 253 253 253 253
46277-253 253 253 253 253 253 253 253 253 224 178 62
46278-242 186 14 241 196 14 210 166 10 22 18 6
46279- 2 2 6 2 2 6 2 2 6 2 2 6
46280- 2 2 6 2 2 6 6 6 6 121 92 8
46281-238 202 15 232 195 16 82 82 82 34 34 34
46282- 10 10 10 0 0 0 0 0 0 0 0 0
46283- 0 0 0 0 0 0 0 0 0 0 0 0
46284- 0 0 0 0 0 0 0 0 0 0 0 0
46285- 0 0 0 0 0 0 0 0 0 0 0 0
46286- 0 0 0 0 0 0 0 0 0 0 0 0
46287- 14 14 14 38 38 38 70 70 70 154 122 46
46288-190 142 34 200 144 11 197 138 11 197 138 11
46289-213 154 11 226 170 11 242 186 14 246 190 14
46290-246 190 14 246 190 14 246 190 14 246 190 14
46291-225 175 15 46 32 6 2 2 6 22 22 22
46292-158 158 158 250 250 250 253 253 253 253 253 253
46293-253 253 253 253 253 253 253 253 253 253 253 253
46294-253 253 253 253 253 253 253 253 253 253 253 253
46295-253 253 253 253 253 253 253 253 253 253 253 253
46296-253 253 253 253 253 253 253 253 253 253 253 253
46297-253 253 253 250 250 250 242 242 242 224 178 62
46298-239 182 13 236 186 11 213 154 11 46 32 6
46299- 2 2 6 2 2 6 2 2 6 2 2 6
46300- 2 2 6 2 2 6 61 42 6 225 175 15
46301-238 190 10 236 186 11 112 100 78 42 42 42
46302- 14 14 14 0 0 0 0 0 0 0 0 0
46303- 0 0 0 0 0 0 0 0 0 0 0 0
46304- 0 0 0 0 0 0 0 0 0 0 0 0
46305- 0 0 0 0 0 0 0 0 0 0 0 0
46306- 0 0 0 0 0 0 0 0 0 6 6 6
46307- 22 22 22 54 54 54 154 122 46 213 154 11
46308-226 170 11 230 174 11 226 170 11 226 170 11
46309-236 178 12 242 186 14 246 190 14 246 190 14
46310-246 190 14 246 190 14 246 190 14 246 190 14
46311-241 196 14 184 144 12 10 10 10 2 2 6
46312- 6 6 6 116 116 116 242 242 242 253 253 253
46313-253 253 253 253 253 253 253 253 253 253 253 253
46314-253 253 253 253 253 253 253 253 253 253 253 253
46315-253 253 253 253 253 253 253 253 253 253 253 253
46316-253 253 253 253 253 253 253 253 253 253 253 253
46317-253 253 253 231 231 231 198 198 198 214 170 54
46318-236 178 12 236 178 12 210 150 10 137 92 6
46319- 18 14 6 2 2 6 2 2 6 2 2 6
46320- 6 6 6 70 47 6 200 144 11 236 178 12
46321-239 182 13 239 182 13 124 112 88 58 58 58
46322- 22 22 22 6 6 6 0 0 0 0 0 0
46323- 0 0 0 0 0 0 0 0 0 0 0 0
46324- 0 0 0 0 0 0 0 0 0 0 0 0
46325- 0 0 0 0 0 0 0 0 0 0 0 0
46326- 0 0 0 0 0 0 0 0 0 10 10 10
46327- 30 30 30 70 70 70 180 133 36 226 170 11
46328-239 182 13 242 186 14 242 186 14 246 186 14
46329-246 190 14 246 190 14 246 190 14 246 190 14
46330-246 190 14 246 190 14 246 190 14 246 190 14
46331-246 190 14 232 195 16 98 70 6 2 2 6
46332- 2 2 6 2 2 6 66 66 66 221 221 221
46333-253 253 253 253 253 253 253 253 253 253 253 253
46334-253 253 253 253 253 253 253 253 253 253 253 253
46335-253 253 253 253 253 253 253 253 253 253 253 253
46336-253 253 253 253 253 253 253 253 253 253 253 253
46337-253 253 253 206 206 206 198 198 198 214 166 58
46338-230 174 11 230 174 11 216 158 10 192 133 9
46339-163 110 8 116 81 8 102 78 10 116 81 8
46340-167 114 7 197 138 11 226 170 11 239 182 13
46341-242 186 14 242 186 14 162 146 94 78 78 78
46342- 34 34 34 14 14 14 6 6 6 0 0 0
46343- 0 0 0 0 0 0 0 0 0 0 0 0
46344- 0 0 0 0 0 0 0 0 0 0 0 0
46345- 0 0 0 0 0 0 0 0 0 0 0 0
46346- 0 0 0 0 0 0 0 0 0 6 6 6
46347- 30 30 30 78 78 78 190 142 34 226 170 11
46348-239 182 13 246 190 14 246 190 14 246 190 14
46349-246 190 14 246 190 14 246 190 14 246 190 14
46350-246 190 14 246 190 14 246 190 14 246 190 14
46351-246 190 14 241 196 14 203 166 17 22 18 6
46352- 2 2 6 2 2 6 2 2 6 38 38 38
46353-218 218 218 253 253 253 253 253 253 253 253 253
46354-253 253 253 253 253 253 253 253 253 253 253 253
46355-253 253 253 253 253 253 253 253 253 253 253 253
46356-253 253 253 253 253 253 253 253 253 253 253 253
46357-250 250 250 206 206 206 198 198 198 202 162 69
46358-226 170 11 236 178 12 224 166 10 210 150 10
46359-200 144 11 197 138 11 192 133 9 197 138 11
46360-210 150 10 226 170 11 242 186 14 246 190 14
46361-246 190 14 246 186 14 225 175 15 124 112 88
46362- 62 62 62 30 30 30 14 14 14 6 6 6
46363- 0 0 0 0 0 0 0 0 0 0 0 0
46364- 0 0 0 0 0 0 0 0 0 0 0 0
46365- 0 0 0 0 0 0 0 0 0 0 0 0
46366- 0 0 0 0 0 0 0 0 0 10 10 10
46367- 30 30 30 78 78 78 174 135 50 224 166 10
46368-239 182 13 246 190 14 246 190 14 246 190 14
46369-246 190 14 246 190 14 246 190 14 246 190 14
46370-246 190 14 246 190 14 246 190 14 246 190 14
46371-246 190 14 246 190 14 241 196 14 139 102 15
46372- 2 2 6 2 2 6 2 2 6 2 2 6
46373- 78 78 78 250 250 250 253 253 253 253 253 253
46374-253 253 253 253 253 253 253 253 253 253 253 253
46375-253 253 253 253 253 253 253 253 253 253 253 253
46376-253 253 253 253 253 253 253 253 253 253 253 253
46377-250 250 250 214 214 214 198 198 198 190 150 46
46378-219 162 10 236 178 12 234 174 13 224 166 10
46379-216 158 10 213 154 11 213 154 11 216 158 10
46380-226 170 11 239 182 13 246 190 14 246 190 14
46381-246 190 14 246 190 14 242 186 14 206 162 42
46382-101 101 101 58 58 58 30 30 30 14 14 14
46383- 6 6 6 0 0 0 0 0 0 0 0 0
46384- 0 0 0 0 0 0 0 0 0 0 0 0
46385- 0 0 0 0 0 0 0 0 0 0 0 0
46386- 0 0 0 0 0 0 0 0 0 10 10 10
46387- 30 30 30 74 74 74 174 135 50 216 158 10
46388-236 178 12 246 190 14 246 190 14 246 190 14
46389-246 190 14 246 190 14 246 190 14 246 190 14
46390-246 190 14 246 190 14 246 190 14 246 190 14
46391-246 190 14 246 190 14 241 196 14 226 184 13
46392- 61 42 6 2 2 6 2 2 6 2 2 6
46393- 22 22 22 238 238 238 253 253 253 253 253 253
46394-253 253 253 253 253 253 253 253 253 253 253 253
46395-253 253 253 253 253 253 253 253 253 253 253 253
46396-253 253 253 253 253 253 253 253 253 253 253 253
46397-253 253 253 226 226 226 187 187 187 180 133 36
46398-216 158 10 236 178 12 239 182 13 236 178 12
46399-230 174 11 226 170 11 226 170 11 230 174 11
46400-236 178 12 242 186 14 246 190 14 246 190 14
46401-246 190 14 246 190 14 246 186 14 239 182 13
46402-206 162 42 106 106 106 66 66 66 34 34 34
46403- 14 14 14 6 6 6 0 0 0 0 0 0
46404- 0 0 0 0 0 0 0 0 0 0 0 0
46405- 0 0 0 0 0 0 0 0 0 0 0 0
46406- 0 0 0 0 0 0 0 0 0 6 6 6
46407- 26 26 26 70 70 70 163 133 67 213 154 11
46408-236 178 12 246 190 14 246 190 14 246 190 14
46409-246 190 14 246 190 14 246 190 14 246 190 14
46410-246 190 14 246 190 14 246 190 14 246 190 14
46411-246 190 14 246 190 14 246 190 14 241 196 14
46412-190 146 13 18 14 6 2 2 6 2 2 6
46413- 46 46 46 246 246 246 253 253 253 253 253 253
46414-253 253 253 253 253 253 253 253 253 253 253 253
46415-253 253 253 253 253 253 253 253 253 253 253 253
46416-253 253 253 253 253 253 253 253 253 253 253 253
46417-253 253 253 221 221 221 86 86 86 156 107 11
46418-216 158 10 236 178 12 242 186 14 246 186 14
46419-242 186 14 239 182 13 239 182 13 242 186 14
46420-242 186 14 246 186 14 246 190 14 246 190 14
46421-246 190 14 246 190 14 246 190 14 246 190 14
46422-242 186 14 225 175 15 142 122 72 66 66 66
46423- 30 30 30 10 10 10 0 0 0 0 0 0
46424- 0 0 0 0 0 0 0 0 0 0 0 0
46425- 0 0 0 0 0 0 0 0 0 0 0 0
46426- 0 0 0 0 0 0 0 0 0 6 6 6
46427- 26 26 26 70 70 70 163 133 67 210 150 10
46428-236 178 12 246 190 14 246 190 14 246 190 14
46429-246 190 14 246 190 14 246 190 14 246 190 14
46430-246 190 14 246 190 14 246 190 14 246 190 14
46431-246 190 14 246 190 14 246 190 14 246 190 14
46432-232 195 16 121 92 8 34 34 34 106 106 106
46433-221 221 221 253 253 253 253 253 253 253 253 253
46434-253 253 253 253 253 253 253 253 253 253 253 253
46435-253 253 253 253 253 253 253 253 253 253 253 253
46436-253 253 253 253 253 253 253 253 253 253 253 253
46437-242 242 242 82 82 82 18 14 6 163 110 8
46438-216 158 10 236 178 12 242 186 14 246 190 14
46439-246 190 14 246 190 14 246 190 14 246 190 14
46440-246 190 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 242 186 14 163 133 67
46443- 46 46 46 18 18 18 6 6 6 0 0 0
46444- 0 0 0 0 0 0 0 0 0 0 0 0
46445- 0 0 0 0 0 0 0 0 0 0 0 0
46446- 0 0 0 0 0 0 0 0 0 10 10 10
46447- 30 30 30 78 78 78 163 133 67 210 150 10
46448-236 178 12 246 186 14 246 190 14 246 190 14
46449-246 190 14 246 190 14 246 190 14 246 190 14
46450-246 190 14 246 190 14 246 190 14 246 190 14
46451-246 190 14 246 190 14 246 190 14 246 190 14
46452-241 196 14 215 174 15 190 178 144 253 253 253
46453-253 253 253 253 253 253 253 253 253 253 253 253
46454-253 253 253 253 253 253 253 253 253 253 253 253
46455-253 253 253 253 253 253 253 253 253 253 253 253
46456-253 253 253 253 253 253 253 253 253 218 218 218
46457- 58 58 58 2 2 6 22 18 6 167 114 7
46458-216 158 10 236 178 12 246 186 14 246 190 14
46459-246 190 14 246 190 14 246 190 14 246 190 14
46460-246 190 14 246 190 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 186 14 242 186 14 190 150 46
46463- 54 54 54 22 22 22 6 6 6 0 0 0
46464- 0 0 0 0 0 0 0 0 0 0 0 0
46465- 0 0 0 0 0 0 0 0 0 0 0 0
46466- 0 0 0 0 0 0 0 0 0 14 14 14
46467- 38 38 38 86 86 86 180 133 36 213 154 11
46468-236 178 12 246 186 14 246 190 14 246 190 14
46469-246 190 14 246 190 14 246 190 14 246 190 14
46470-246 190 14 246 190 14 246 190 14 246 190 14
46471-246 190 14 246 190 14 246 190 14 246 190 14
46472-246 190 14 232 195 16 190 146 13 214 214 214
46473-253 253 253 253 253 253 253 253 253 253 253 253
46474-253 253 253 253 253 253 253 253 253 253 253 253
46475-253 253 253 253 253 253 253 253 253 253 253 253
46476-253 253 253 250 250 250 170 170 170 26 26 26
46477- 2 2 6 2 2 6 37 26 9 163 110 8
46478-219 162 10 239 182 13 246 186 14 246 190 14
46479-246 190 14 246 190 14 246 190 14 246 190 14
46480-246 190 14 246 190 14 246 190 14 246 190 14
46481-246 190 14 246 190 14 246 190 14 246 190 14
46482-246 186 14 236 178 12 224 166 10 142 122 72
46483- 46 46 46 18 18 18 6 6 6 0 0 0
46484- 0 0 0 0 0 0 0 0 0 0 0 0
46485- 0 0 0 0 0 0 0 0 0 0 0 0
46486- 0 0 0 0 0 0 6 6 6 18 18 18
46487- 50 50 50 109 106 95 192 133 9 224 166 10
46488-242 186 14 246 190 14 246 190 14 246 190 14
46489-246 190 14 246 190 14 246 190 14 246 190 14
46490-246 190 14 246 190 14 246 190 14 246 190 14
46491-246 190 14 246 190 14 246 190 14 246 190 14
46492-242 186 14 226 184 13 210 162 10 142 110 46
46493-226 226 226 253 253 253 253 253 253 253 253 253
46494-253 253 253 253 253 253 253 253 253 253 253 253
46495-253 253 253 253 253 253 253 253 253 253 253 253
46496-198 198 198 66 66 66 2 2 6 2 2 6
46497- 2 2 6 2 2 6 50 34 6 156 107 11
46498-219 162 10 239 182 13 246 186 14 246 190 14
46499-246 190 14 246 190 14 246 190 14 246 190 14
46500-246 190 14 246 190 14 246 190 14 246 190 14
46501-246 190 14 246 190 14 246 190 14 242 186 14
46502-234 174 13 213 154 11 154 122 46 66 66 66
46503- 30 30 30 10 10 10 0 0 0 0 0 0
46504- 0 0 0 0 0 0 0 0 0 0 0 0
46505- 0 0 0 0 0 0 0 0 0 0 0 0
46506- 0 0 0 0 0 0 6 6 6 22 22 22
46507- 58 58 58 154 121 60 206 145 10 234 174 13
46508-242 186 14 246 186 14 246 190 14 246 190 14
46509-246 190 14 246 190 14 246 190 14 246 190 14
46510-246 190 14 246 190 14 246 190 14 246 190 14
46511-246 190 14 246 190 14 246 190 14 246 190 14
46512-246 186 14 236 178 12 210 162 10 163 110 8
46513- 61 42 6 138 138 138 218 218 218 250 250 250
46514-253 253 253 253 253 253 253 253 253 250 250 250
46515-242 242 242 210 210 210 144 144 144 66 66 66
46516- 6 6 6 2 2 6 2 2 6 2 2 6
46517- 2 2 6 2 2 6 61 42 6 163 110 8
46518-216 158 10 236 178 12 246 190 14 246 190 14
46519-246 190 14 246 190 14 246 190 14 246 190 14
46520-246 190 14 246 190 14 246 190 14 246 190 14
46521-246 190 14 239 182 13 230 174 11 216 158 10
46522-190 142 34 124 112 88 70 70 70 38 38 38
46523- 18 18 18 6 6 6 0 0 0 0 0 0
46524- 0 0 0 0 0 0 0 0 0 0 0 0
46525- 0 0 0 0 0 0 0 0 0 0 0 0
46526- 0 0 0 0 0 0 6 6 6 22 22 22
46527- 62 62 62 168 124 44 206 145 10 224 166 10
46528-236 178 12 239 182 13 242 186 14 242 186 14
46529-246 186 14 246 190 14 246 190 14 246 190 14
46530-246 190 14 246 190 14 246 190 14 246 190 14
46531-246 190 14 246 190 14 246 190 14 246 190 14
46532-246 190 14 236 178 12 216 158 10 175 118 6
46533- 80 54 7 2 2 6 6 6 6 30 30 30
46534- 54 54 54 62 62 62 50 50 50 38 38 38
46535- 14 14 14 2 2 6 2 2 6 2 2 6
46536- 2 2 6 2 2 6 2 2 6 2 2 6
46537- 2 2 6 6 6 6 80 54 7 167 114 7
46538-213 154 11 236 178 12 246 190 14 246 190 14
46539-246 190 14 246 190 14 246 190 14 246 190 14
46540-246 190 14 242 186 14 239 182 13 239 182 13
46541-230 174 11 210 150 10 174 135 50 124 112 88
46542- 82 82 82 54 54 54 34 34 34 18 18 18
46543- 6 6 6 0 0 0 0 0 0 0 0 0
46544- 0 0 0 0 0 0 0 0 0 0 0 0
46545- 0 0 0 0 0 0 0 0 0 0 0 0
46546- 0 0 0 0 0 0 6 6 6 18 18 18
46547- 50 50 50 158 118 36 192 133 9 200 144 11
46548-216 158 10 219 162 10 224 166 10 226 170 11
46549-230 174 11 236 178 12 239 182 13 239 182 13
46550-242 186 14 246 186 14 246 190 14 246 190 14
46551-246 190 14 246 190 14 246 190 14 246 190 14
46552-246 186 14 230 174 11 210 150 10 163 110 8
46553-104 69 6 10 10 10 2 2 6 2 2 6
46554- 2 2 6 2 2 6 2 2 6 2 2 6
46555- 2 2 6 2 2 6 2 2 6 2 2 6
46556- 2 2 6 2 2 6 2 2 6 2 2 6
46557- 2 2 6 6 6 6 91 60 6 167 114 7
46558-206 145 10 230 174 11 242 186 14 246 190 14
46559-246 190 14 246 190 14 246 186 14 242 186 14
46560-239 182 13 230 174 11 224 166 10 213 154 11
46561-180 133 36 124 112 88 86 86 86 58 58 58
46562- 38 38 38 22 22 22 10 10 10 6 6 6
46563- 0 0 0 0 0 0 0 0 0 0 0 0
46564- 0 0 0 0 0 0 0 0 0 0 0 0
46565- 0 0 0 0 0 0 0 0 0 0 0 0
46566- 0 0 0 0 0 0 0 0 0 14 14 14
46567- 34 34 34 70 70 70 138 110 50 158 118 36
46568-167 114 7 180 123 7 192 133 9 197 138 11
46569-200 144 11 206 145 10 213 154 11 219 162 10
46570-224 166 10 230 174 11 239 182 13 242 186 14
46571-246 186 14 246 186 14 246 186 14 246 186 14
46572-239 182 13 216 158 10 185 133 11 152 99 6
46573-104 69 6 18 14 6 2 2 6 2 2 6
46574- 2 2 6 2 2 6 2 2 6 2 2 6
46575- 2 2 6 2 2 6 2 2 6 2 2 6
46576- 2 2 6 2 2 6 2 2 6 2 2 6
46577- 2 2 6 6 6 6 80 54 7 152 99 6
46578-192 133 9 219 162 10 236 178 12 239 182 13
46579-246 186 14 242 186 14 239 182 13 236 178 12
46580-224 166 10 206 145 10 192 133 9 154 121 60
46581- 94 94 94 62 62 62 42 42 42 22 22 22
46582- 14 14 14 6 6 6 0 0 0 0 0 0
46583- 0 0 0 0 0 0 0 0 0 0 0 0
46584- 0 0 0 0 0 0 0 0 0 0 0 0
46585- 0 0 0 0 0 0 0 0 0 0 0 0
46586- 0 0 0 0 0 0 0 0 0 6 6 6
46587- 18 18 18 34 34 34 58 58 58 78 78 78
46588-101 98 89 124 112 88 142 110 46 156 107 11
46589-163 110 8 167 114 7 175 118 6 180 123 7
46590-185 133 11 197 138 11 210 150 10 219 162 10
46591-226 170 11 236 178 12 236 178 12 234 174 13
46592-219 162 10 197 138 11 163 110 8 130 83 6
46593- 91 60 6 10 10 10 2 2 6 2 2 6
46594- 18 18 18 38 38 38 38 38 38 38 38 38
46595- 38 38 38 38 38 38 38 38 38 38 38 38
46596- 38 38 38 38 38 38 26 26 26 2 2 6
46597- 2 2 6 6 6 6 70 47 6 137 92 6
46598-175 118 6 200 144 11 219 162 10 230 174 11
46599-234 174 13 230 174 11 219 162 10 210 150 10
46600-192 133 9 163 110 8 124 112 88 82 82 82
46601- 50 50 50 30 30 30 14 14 14 6 6 6
46602- 0 0 0 0 0 0 0 0 0 0 0 0
46603- 0 0 0 0 0 0 0 0 0 0 0 0
46604- 0 0 0 0 0 0 0 0 0 0 0 0
46605- 0 0 0 0 0 0 0 0 0 0 0 0
46606- 0 0 0 0 0 0 0 0 0 0 0 0
46607- 6 6 6 14 14 14 22 22 22 34 34 34
46608- 42 42 42 58 58 58 74 74 74 86 86 86
46609-101 98 89 122 102 70 130 98 46 121 87 25
46610-137 92 6 152 99 6 163 110 8 180 123 7
46611-185 133 11 197 138 11 206 145 10 200 144 11
46612-180 123 7 156 107 11 130 83 6 104 69 6
46613- 50 34 6 54 54 54 110 110 110 101 98 89
46614- 86 86 86 82 82 82 78 78 78 78 78 78
46615- 78 78 78 78 78 78 78 78 78 78 78 78
46616- 78 78 78 82 82 82 86 86 86 94 94 94
46617-106 106 106 101 101 101 86 66 34 124 80 6
46618-156 107 11 180 123 7 192 133 9 200 144 11
46619-206 145 10 200 144 11 192 133 9 175 118 6
46620-139 102 15 109 106 95 70 70 70 42 42 42
46621- 22 22 22 10 10 10 0 0 0 0 0 0
46622- 0 0 0 0 0 0 0 0 0 0 0 0
46623- 0 0 0 0 0 0 0 0 0 0 0 0
46624- 0 0 0 0 0 0 0 0 0 0 0 0
46625- 0 0 0 0 0 0 0 0 0 0 0 0
46626- 0 0 0 0 0 0 0 0 0 0 0 0
46627- 0 0 0 0 0 0 6 6 6 10 10 10
46628- 14 14 14 22 22 22 30 30 30 38 38 38
46629- 50 50 50 62 62 62 74 74 74 90 90 90
46630-101 98 89 112 100 78 121 87 25 124 80 6
46631-137 92 6 152 99 6 152 99 6 152 99 6
46632-138 86 6 124 80 6 98 70 6 86 66 30
46633-101 98 89 82 82 82 58 58 58 46 46 46
46634- 38 38 38 34 34 34 34 34 34 34 34 34
46635- 34 34 34 34 34 34 34 34 34 34 34 34
46636- 34 34 34 34 34 34 38 38 38 42 42 42
46637- 54 54 54 82 82 82 94 86 76 91 60 6
46638-134 86 6 156 107 11 167 114 7 175 118 6
46639-175 118 6 167 114 7 152 99 6 121 87 25
46640-101 98 89 62 62 62 34 34 34 18 18 18
46641- 6 6 6 0 0 0 0 0 0 0 0 0
46642- 0 0 0 0 0 0 0 0 0 0 0 0
46643- 0 0 0 0 0 0 0 0 0 0 0 0
46644- 0 0 0 0 0 0 0 0 0 0 0 0
46645- 0 0 0 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 6 6 6 6 6 6 10 10 10
46649- 18 18 18 22 22 22 30 30 30 42 42 42
46650- 50 50 50 66 66 66 86 86 86 101 98 89
46651-106 86 58 98 70 6 104 69 6 104 69 6
46652-104 69 6 91 60 6 82 62 34 90 90 90
46653- 62 62 62 38 38 38 22 22 22 14 14 14
46654- 10 10 10 10 10 10 10 10 10 10 10 10
46655- 10 10 10 10 10 10 6 6 6 10 10 10
46656- 10 10 10 10 10 10 10 10 10 14 14 14
46657- 22 22 22 42 42 42 70 70 70 89 81 66
46658- 80 54 7 104 69 6 124 80 6 137 92 6
46659-134 86 6 116 81 8 100 82 52 86 86 86
46660- 58 58 58 30 30 30 14 14 14 6 6 6
46661- 0 0 0 0 0 0 0 0 0 0 0 0
46662- 0 0 0 0 0 0 0 0 0 0 0 0
46663- 0 0 0 0 0 0 0 0 0 0 0 0
46664- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
46670- 18 18 18 26 26 26 38 38 38 54 54 54
46671- 70 70 70 86 86 86 94 86 76 89 81 66
46672- 89 81 66 86 86 86 74 74 74 50 50 50
46673- 30 30 30 14 14 14 6 6 6 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- 6 6 6 18 18 18 34 34 34 58 58 58
46678- 82 82 82 89 81 66 89 81 66 89 81 66
46679- 94 86 66 94 86 76 74 74 74 50 50 50
46680- 26 26 26 14 14 14 6 6 6 0 0 0
46681- 0 0 0 0 0 0 0 0 0 0 0 0
46682- 0 0 0 0 0 0 0 0 0 0 0 0
46683- 0 0 0 0 0 0 0 0 0 0 0 0
46684- 0 0 0 0 0 0 0 0 0 0 0 0
46685- 0 0 0 0 0 0 0 0 0 0 0 0
46686- 0 0 0 0 0 0 0 0 0 0 0 0
46687- 0 0 0 0 0 0 0 0 0 0 0 0
46688- 0 0 0 0 0 0 0 0 0 0 0 0
46689- 0 0 0 0 0 0 0 0 0 0 0 0
46690- 6 6 6 6 6 6 14 14 14 18 18 18
46691- 30 30 30 38 38 38 46 46 46 54 54 54
46692- 50 50 50 42 42 42 30 30 30 18 18 18
46693- 10 10 10 0 0 0 0 0 0 0 0 0
46694- 0 0 0 0 0 0 0 0 0 0 0 0
46695- 0 0 0 0 0 0 0 0 0 0 0 0
46696- 0 0 0 0 0 0 0 0 0 0 0 0
46697- 0 0 0 6 6 6 14 14 14 26 26 26
46698- 38 38 38 50 50 50 58 58 58 58 58 58
46699- 54 54 54 42 42 42 30 30 30 18 18 18
46700- 10 10 10 0 0 0 0 0 0 0 0 0
46701- 0 0 0 0 0 0 0 0 0 0 0 0
46702- 0 0 0 0 0 0 0 0 0 0 0 0
46703- 0 0 0 0 0 0 0 0 0 0 0 0
46704- 0 0 0 0 0 0 0 0 0 0 0 0
46705- 0 0 0 0 0 0 0 0 0 0 0 0
46706- 0 0 0 0 0 0 0 0 0 0 0 0
46707- 0 0 0 0 0 0 0 0 0 0 0 0
46708- 0 0 0 0 0 0 0 0 0 0 0 0
46709- 0 0 0 0 0 0 0 0 0 0 0 0
46710- 0 0 0 0 0 0 0 0 0 6 6 6
46711- 6 6 6 10 10 10 14 14 14 18 18 18
46712- 18 18 18 14 14 14 10 10 10 6 6 6
46713- 0 0 0 0 0 0 0 0 0 0 0 0
46714- 0 0 0 0 0 0 0 0 0 0 0 0
46715- 0 0 0 0 0 0 0 0 0 0 0 0
46716- 0 0 0 0 0 0 0 0 0 0 0 0
46717- 0 0 0 0 0 0 0 0 0 6 6 6
46718- 14 14 14 18 18 18 22 22 22 22 22 22
46719- 18 18 18 14 14 14 10 10 10 6 6 6
46720- 0 0 0 0 0 0 0 0 0 0 0 0
46721- 0 0 0 0 0 0 0 0 0 0 0 0
46722- 0 0 0 0 0 0 0 0 0 0 0 0
46723- 0 0 0 0 0 0 0 0 0 0 0 0
46724- 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
46761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46766+4 4 4 4 4 4
46767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46780+4 4 4 4 4 4
46781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46794+4 4 4 4 4 4
46795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46808+4 4 4 4 4 4
46809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46813+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46814+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46818+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46819+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46820+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46822+4 4 4 4 4 4
46823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46827+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46828+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46829+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46832+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46833+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46834+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46835+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46836+4 4 4 4 4 4
46837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46841+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46842+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46843+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46846+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46847+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46848+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46849+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46850+4 4 4 4 4 4
46851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46854+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46855+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46856+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46857+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46859+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46860+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46861+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46862+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46863+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46864+4 4 4 4 4 4
46865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46868+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46869+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46870+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46871+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46872+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46873+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46874+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46875+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46876+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46877+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46878+4 4 4 4 4 4
46879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46882+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46883+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46884+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46885+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46886+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46887+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46888+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46889+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46890+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46891+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46892+4 4 4 4 4 4
46893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46895+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46896+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46897+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46898+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46899+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46900+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46901+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46902+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46903+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46904+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46905+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46906+4 4 4 4 4 4
46907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46909+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46910+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46911+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46912+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46913+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46914+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46915+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46916+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46917+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46918+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46919+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46920+4 4 4 4 4 4
46921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46923+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46924+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46925+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46926+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46927+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46928+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46929+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46930+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46931+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46932+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46933+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46934+4 4 4 4 4 4
46935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46937+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46938+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46939+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46940+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46941+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46942+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46943+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46944+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
46945+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
46946+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
46947+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
46948+4 4 4 4 4 4
46949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46950+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
46951+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
46952+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
46953+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
46954+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
46955+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
46956+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
46957+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
46958+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
46959+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
46960+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
46961+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
46962+4 4 4 4 4 4
46963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46964+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
46965+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
46966+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
46967+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46968+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
46969+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
46970+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
46971+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
46972+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
46973+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
46974+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
46975+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
46976+0 0 0 4 4 4
46977+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46978+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
46979+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
46980+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
46981+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
46982+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
46983+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
46984+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
46985+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
46986+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
46987+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
46988+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
46989+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
46990+2 0 0 0 0 0
46991+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
46992+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
46993+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
46994+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
46995+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
46996+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
46997+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
46998+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
46999+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
47000+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
47001+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
47002+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
47003+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
47004+37 38 37 0 0 0
47005+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47006+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
47007+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
47008+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
47009+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
47010+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
47011+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
47012+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
47013+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
47014+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
47015+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
47016+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
47017+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
47018+85 115 134 4 0 0
47019+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
47020+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
47021+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
47022+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
47023+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
47024+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
47025+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
47026+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
47027+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
47028+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
47029+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
47030+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
47031+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
47032+60 73 81 4 0 0
47033+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
47034+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
47035+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
47036+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
47037+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
47038+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
47039+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
47040+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
47041+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
47042+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
47043+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
47044+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
47045+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
47046+16 19 21 4 0 0
47047+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
47048+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
47049+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
47050+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
47051+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
47052+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
47053+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
47054+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
47055+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
47056+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
47057+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
47058+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
47059+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
47060+4 0 0 4 3 3
47061+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
47062+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
47063+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
47064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
47065+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
47066+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
47067+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
47068+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
47069+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
47070+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
47071+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
47072+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
47073+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
47074+3 2 2 4 4 4
47075+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
47076+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
47077+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
47078+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47079+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
47080+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
47081+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
47082+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
47083+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
47084+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
47085+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
47086+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
47087+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
47088+4 4 4 4 4 4
47089+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
47090+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
47091+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
47092+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
47093+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
47094+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
47095+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
47096+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
47097+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
47098+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
47099+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
47100+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
47101+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
47102+4 4 4 4 4 4
47103+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
47104+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
47105+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
47106+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
47107+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
47108+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47109+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
47110+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
47111+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
47112+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
47113+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
47114+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
47115+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
47116+5 5 5 5 5 5
47117+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
47118+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
47119+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
47120+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
47121+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
47122+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47123+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
47124+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
47125+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
47126+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
47127+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
47128+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
47129+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47130+5 5 5 4 4 4
47131+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
47132+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
47133+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
47134+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
47135+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47136+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
47137+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
47138+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
47139+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
47140+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
47141+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
47142+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47144+4 4 4 4 4 4
47145+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
47146+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
47147+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
47148+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
47149+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
47150+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47151+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47152+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
47153+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
47154+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
47155+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
47156+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
47157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47158+4 4 4 4 4 4
47159+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
47160+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
47161+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
47162+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
47163+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47164+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
47165+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
47166+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
47167+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
47168+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
47169+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
47170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47172+4 4 4 4 4 4
47173+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
47174+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
47175+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
47176+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
47177+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47178+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47179+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47180+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
47181+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
47182+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
47183+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
47184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47186+4 4 4 4 4 4
47187+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
47188+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
47189+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
47190+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
47191+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47192+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
47193+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47194+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
47195+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
47196+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
47197+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47200+4 4 4 4 4 4
47201+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
47202+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
47203+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
47204+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
47205+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47206+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
47207+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
47208+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
47209+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
47210+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
47211+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
47212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47214+4 4 4 4 4 4
47215+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
47216+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
47217+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
47218+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
47219+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47220+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
47221+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
47222+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
47223+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
47224+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
47225+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
47226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47228+4 4 4 4 4 4
47229+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
47230+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
47231+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
47232+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47233+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
47234+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
47235+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
47236+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
47237+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
47238+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
47239+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47242+4 4 4 4 4 4
47243+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
47244+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
47245+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
47246+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47247+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47248+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
47249+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
47250+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
47251+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
47252+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
47253+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47256+4 4 4 4 4 4
47257+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
47258+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
47259+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47260+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47261+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47262+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
47263+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
47264+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
47265+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
47266+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
47267+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47270+4 4 4 4 4 4
47271+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
47272+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
47273+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47274+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47275+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47276+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
47277+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
47278+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
47279+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47280+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47281+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47284+4 4 4 4 4 4
47285+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47286+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
47287+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47288+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
47289+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
47290+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
47291+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
47292+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
47293+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47294+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47295+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47298+4 4 4 4 4 4
47299+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47300+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
47301+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47302+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
47303+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47304+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
47305+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
47306+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
47307+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47308+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47309+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47312+4 4 4 4 4 4
47313+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
47314+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
47315+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47316+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
47317+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
47318+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
47319+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
47320+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
47321+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47322+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47323+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47326+4 4 4 4 4 4
47327+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
47328+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
47329+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47330+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
47331+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
47332+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
47333+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
47334+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
47335+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47336+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47337+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47340+4 4 4 4 4 4
47341+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47342+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
47343+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47344+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
47345+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
47346+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
47347+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
47348+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
47349+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47350+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47351+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47354+4 4 4 4 4 4
47355+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
47356+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
47357+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47358+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
47359+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
47360+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
47361+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
47362+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
47363+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
47364+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47365+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47368+4 4 4 4 4 4
47369+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47370+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
47371+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
47372+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
47373+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
47374+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
47375+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
47376+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
47377+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47378+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47379+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47382+4 4 4 4 4 4
47383+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47384+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
47385+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47386+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
47387+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
47388+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
47389+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
47390+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
47391+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47392+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47393+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47396+4 4 4 4 4 4
47397+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47398+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
47399+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
47400+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
47401+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
47402+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
47403+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47404+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
47405+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47406+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47407+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47410+4 4 4 4 4 4
47411+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47412+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
47413+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
47414+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47415+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
47416+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
47417+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47418+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
47419+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47420+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47421+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47424+4 4 4 4 4 4
47425+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47426+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
47427+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
47428+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
47429+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
47430+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
47431+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
47432+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
47433+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
47434+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47435+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47438+4 4 4 4 4 4
47439+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47440+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
47441+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
47442+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
47443+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
47444+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
47445+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
47446+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
47447+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
47448+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47449+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47452+4 4 4 4 4 4
47453+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
47454+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
47455+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
47456+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
47457+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47458+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
47459+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
47460+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
47461+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
47462+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47463+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47466+4 4 4 4 4 4
47467+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47468+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
47469+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
47470+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
47471+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
47472+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
47473+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
47474+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
47475+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
47476+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47477+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47480+4 4 4 4 4 4
47481+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
47482+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
47483+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
47484+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
47485+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
47486+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
47487+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
47488+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
47489+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
47490+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
47491+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47494+4 4 4 4 4 4
47495+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
47496+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47497+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
47498+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
47499+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
47500+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
47501+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
47502+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
47503+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
47504+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
47505+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47508+4 4 4 4 4 4
47509+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
47510+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47511+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
47512+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
47513+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
47514+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
47515+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47516+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
47517+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
47518+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
47519+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47522+4 4 4 4 4 4
47523+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
47524+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
47525+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
47526+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
47527+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
47528+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
47529+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
47530+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
47531+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
47532+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
47533+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47536+4 4 4 4 4 4
47537+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
47538+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
47539+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47540+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
47541+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
47542+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
47543+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
47544+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
47545+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
47546+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
47547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47550+4 4 4 4 4 4
47551+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47552+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
47553+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
47554+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
47555+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
47556+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
47557+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
47558+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
47559+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
47560+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47564+4 4 4 4 4 4
47565+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
47566+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
47567+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
47568+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
47569+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
47570+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
47571+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
47572+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
47573+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
47574+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47578+4 4 4 4 4 4
47579+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
47580+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
47581+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
47582+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
47583+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
47584+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
47585+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
47586+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
47587+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47588+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47592+4 4 4 4 4 4
47593+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
47594+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47595+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
47596+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47597+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
47598+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
47599+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
47600+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
47601+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
47602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47606+4 4 4 4 4 4
47607+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
47608+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
47609+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
47610+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
47611+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
47612+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
47613+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
47614+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
47615+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
47616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47620+4 4 4 4 4 4
47621+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47622+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
47623+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
47624+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
47625+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
47626+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
47627+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
47628+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
47629+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47634+4 4 4 4 4 4
47635+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
47636+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
47637+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47638+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
47639+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
47640+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
47641+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
47642+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4
47645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47648+4 4 4 4 4 4
47649+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47650+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
47651+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
47652+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
47653+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
47654+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
47655+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
47656+6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47662+4 4 4 4 4 4
47663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47664+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47665+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47666+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47667+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47668+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47669+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47670+4 0 0 4 3 3 6 6 6 4 4 4 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 4 4 4
47674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47676+4 4 4 4 4 4
47677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47678+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47679+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47680+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47681+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47682+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47683+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47684+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47690+4 4 4 4 4 4
47691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47692+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47693+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47694+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47695+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47696+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47697+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47698+5 5 5 5 5 5 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
47703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47704+4 4 4 4 4 4
47705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47707+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47708+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47709+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47710+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47711+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47712+4 3 3 5 5 5 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
47717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47718+4 4 4 4 4 4
47719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47722+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47723+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47724+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47725+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47726+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
47731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47732+4 4 4 4 4 4
47733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47736+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47737+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47738+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47739+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47740+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47746+4 4 4 4 4 4
47747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47750+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47751+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47752+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47753+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47760+4 4 4 4 4 4
47761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47764+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47765+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47766+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47767+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47770+4 4 4 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 4 4 4 4 4 4 4 4 4
47774+4 4 4 4 4 4
47775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47779+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47780+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47781+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47784+4 4 4 4 4 4 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 4 4 4 4 4 4
47788+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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47794+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47795+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47802+4 4 4 4 4 4
47803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47807+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47808+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47809+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47816+4 4 4 4 4 4
47817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47821+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47822+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47830+4 4 4 4 4 4
47831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47835+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47836+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47844+4 4 4 4 4 4
47845diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47846index fe92eed..106e085 100644
47847--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47848+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47849@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47850 struct mb862xxfb_par *par = info->par;
47851
47852 if (info->var.bits_per_pixel == 32) {
47853- info->fbops->fb_fillrect = cfb_fillrect;
47854- info->fbops->fb_copyarea = cfb_copyarea;
47855- info->fbops->fb_imageblit = cfb_imageblit;
47856+ pax_open_kernel();
47857+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47858+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47859+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47860+ pax_close_kernel();
47861 } else {
47862 outreg(disp, GC_L0EM, 3);
47863- info->fbops->fb_fillrect = mb86290fb_fillrect;
47864- info->fbops->fb_copyarea = mb86290fb_copyarea;
47865- info->fbops->fb_imageblit = mb86290fb_imageblit;
47866+ pax_open_kernel();
47867+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47868+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47869+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47870+ pax_close_kernel();
47871 }
47872 outreg(draw, GDC_REG_DRAW_BASE, 0);
47873 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47874diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47875index ff22871..b129bed 100644
47876--- a/drivers/video/nvidia/nvidia.c
47877+++ b/drivers/video/nvidia/nvidia.c
47878@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47879 info->fix.line_length = (info->var.xres_virtual *
47880 info->var.bits_per_pixel) >> 3;
47881 if (info->var.accel_flags) {
47882- info->fbops->fb_imageblit = nvidiafb_imageblit;
47883- info->fbops->fb_fillrect = nvidiafb_fillrect;
47884- info->fbops->fb_copyarea = nvidiafb_copyarea;
47885- info->fbops->fb_sync = nvidiafb_sync;
47886+ pax_open_kernel();
47887+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47888+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47889+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47890+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47891+ pax_close_kernel();
47892 info->pixmap.scan_align = 4;
47893 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47894 info->flags |= FBINFO_READS_FAST;
47895 NVResetGraphics(info);
47896 } else {
47897- info->fbops->fb_imageblit = cfb_imageblit;
47898- info->fbops->fb_fillrect = cfb_fillrect;
47899- info->fbops->fb_copyarea = cfb_copyarea;
47900- info->fbops->fb_sync = NULL;
47901+ pax_open_kernel();
47902+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47903+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47904+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47905+ *(void **)&info->fbops->fb_sync = NULL;
47906+ pax_close_kernel();
47907 info->pixmap.scan_align = 1;
47908 info->flags |= FBINFO_HWACCEL_DISABLED;
47909 info->flags &= ~FBINFO_READS_FAST;
47910@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47911 info->pixmap.size = 8 * 1024;
47912 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47913
47914- if (!hwcur)
47915- info->fbops->fb_cursor = NULL;
47916+ if (!hwcur) {
47917+ pax_open_kernel();
47918+ *(void **)&info->fbops->fb_cursor = NULL;
47919+ pax_close_kernel();
47920+ }
47921
47922 info->var.accel_flags = (!noaccel);
47923
47924diff --git a/drivers/video/output.c b/drivers/video/output.c
47925index 0d6f2cd..6285b97 100644
47926--- a/drivers/video/output.c
47927+++ b/drivers/video/output.c
47928@@ -97,7 +97,7 @@ struct output_device *video_output_register(const char *name,
47929 new_dev->props = op;
47930 new_dev->dev.class = &video_output_class;
47931 new_dev->dev.parent = dev;
47932- dev_set_name(&new_dev->dev, name);
47933+ dev_set_name(&new_dev->dev, "%s", name);
47934 dev_set_drvdata(&new_dev->dev, devdata);
47935 ret_code = device_register(&new_dev->dev);
47936 if (ret_code) {
47937diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47938index 05c2dc3..ea1f391 100644
47939--- a/drivers/video/s1d13xxxfb.c
47940+++ b/drivers/video/s1d13xxxfb.c
47941@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47942
47943 switch(prod_id) {
47944 case S1D13506_PROD_ID: /* activate acceleration */
47945- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47946- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47947+ pax_open_kernel();
47948+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47949+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47950+ pax_close_kernel();
47951 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
47952 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
47953 break;
47954diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
47955index b2b33fc..f9f4658 100644
47956--- a/drivers/video/smscufx.c
47957+++ b/drivers/video/smscufx.c
47958@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
47959 fb_deferred_io_cleanup(info);
47960 kfree(info->fbdefio);
47961 info->fbdefio = NULL;
47962- info->fbops->fb_mmap = ufx_ops_mmap;
47963+ pax_open_kernel();
47964+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
47965+ pax_close_kernel();
47966 }
47967
47968 pr_debug("released /dev/fb%d user=%d count=%d",
47969diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
47970index ec03e72..f578436 100644
47971--- a/drivers/video/udlfb.c
47972+++ b/drivers/video/udlfb.c
47973@@ -623,11 +623,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
47974 dlfb_urb_completion(urb);
47975
47976 error:
47977- atomic_add(bytes_sent, &dev->bytes_sent);
47978- atomic_add(bytes_identical, &dev->bytes_identical);
47979- atomic_add(width*height*2, &dev->bytes_rendered);
47980+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47981+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47982+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
47983 end_cycles = get_cycles();
47984- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47985+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47986 >> 10)), /* Kcycles */
47987 &dev->cpu_kcycles_used);
47988
47989@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
47990 dlfb_urb_completion(urb);
47991
47992 error:
47993- atomic_add(bytes_sent, &dev->bytes_sent);
47994- atomic_add(bytes_identical, &dev->bytes_identical);
47995- atomic_add(bytes_rendered, &dev->bytes_rendered);
47996+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47997+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47998+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
47999 end_cycles = get_cycles();
48000- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48001+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48002 >> 10)), /* Kcycles */
48003 &dev->cpu_kcycles_used);
48004 }
48005@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
48006 fb_deferred_io_cleanup(info);
48007 kfree(info->fbdefio);
48008 info->fbdefio = NULL;
48009- info->fbops->fb_mmap = dlfb_ops_mmap;
48010+ pax_open_kernel();
48011+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
48012+ pax_close_kernel();
48013 }
48014
48015 pr_warn("released /dev/fb%d user=%d count=%d\n",
48016@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
48017 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48018 struct dlfb_data *dev = fb_info->par;
48019 return snprintf(buf, PAGE_SIZE, "%u\n",
48020- atomic_read(&dev->bytes_rendered));
48021+ atomic_read_unchecked(&dev->bytes_rendered));
48022 }
48023
48024 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48025@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48026 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48027 struct dlfb_data *dev = fb_info->par;
48028 return snprintf(buf, PAGE_SIZE, "%u\n",
48029- atomic_read(&dev->bytes_identical));
48030+ atomic_read_unchecked(&dev->bytes_identical));
48031 }
48032
48033 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48034@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48035 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48036 struct dlfb_data *dev = fb_info->par;
48037 return snprintf(buf, PAGE_SIZE, "%u\n",
48038- atomic_read(&dev->bytes_sent));
48039+ atomic_read_unchecked(&dev->bytes_sent));
48040 }
48041
48042 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48043@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48044 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48045 struct dlfb_data *dev = fb_info->par;
48046 return snprintf(buf, PAGE_SIZE, "%u\n",
48047- atomic_read(&dev->cpu_kcycles_used));
48048+ atomic_read_unchecked(&dev->cpu_kcycles_used));
48049 }
48050
48051 static ssize_t edid_show(
48052@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
48053 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48054 struct dlfb_data *dev = fb_info->par;
48055
48056- atomic_set(&dev->bytes_rendered, 0);
48057- atomic_set(&dev->bytes_identical, 0);
48058- atomic_set(&dev->bytes_sent, 0);
48059- atomic_set(&dev->cpu_kcycles_used, 0);
48060+ atomic_set_unchecked(&dev->bytes_rendered, 0);
48061+ atomic_set_unchecked(&dev->bytes_identical, 0);
48062+ atomic_set_unchecked(&dev->bytes_sent, 0);
48063+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
48064
48065 return count;
48066 }
48067diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
48068index e328a61..1b08ecb 100644
48069--- a/drivers/video/uvesafb.c
48070+++ b/drivers/video/uvesafb.c
48071@@ -19,6 +19,7 @@
48072 #include <linux/io.h>
48073 #include <linux/mutex.h>
48074 #include <linux/slab.h>
48075+#include <linux/moduleloader.h>
48076 #include <video/edid.h>
48077 #include <video/uvesafb.h>
48078 #ifdef CONFIG_X86
48079@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
48080 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
48081 par->pmi_setpal = par->ypan = 0;
48082 } else {
48083+
48084+#ifdef CONFIG_PAX_KERNEXEC
48085+#ifdef CONFIG_MODULES
48086+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
48087+#endif
48088+ if (!par->pmi_code) {
48089+ par->pmi_setpal = par->ypan = 0;
48090+ return 0;
48091+ }
48092+#endif
48093+
48094 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
48095 + task->t.regs.edi);
48096+
48097+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48098+ pax_open_kernel();
48099+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
48100+ pax_close_kernel();
48101+
48102+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
48103+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
48104+#else
48105 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
48106 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
48107+#endif
48108+
48109 printk(KERN_INFO "uvesafb: protected mode interface info at "
48110 "%04x:%04x\n",
48111 (u16)task->t.regs.es, (u16)task->t.regs.edi);
48112@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
48113 par->ypan = ypan;
48114
48115 if (par->pmi_setpal || par->ypan) {
48116+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
48117 if (__supported_pte_mask & _PAGE_NX) {
48118 par->pmi_setpal = par->ypan = 0;
48119 printk(KERN_WARNING "uvesafb: NX protection is actively."
48120 "We have better not to use the PMI.\n");
48121- } else {
48122+ } else
48123+#endif
48124 uvesafb_vbe_getpmi(task, par);
48125- }
48126 }
48127 #else
48128 /* The protected mode interface is not available on non-x86. */
48129@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48130 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
48131
48132 /* Disable blanking if the user requested so. */
48133- if (!blank)
48134- info->fbops->fb_blank = NULL;
48135+ if (!blank) {
48136+ pax_open_kernel();
48137+ *(void **)&info->fbops->fb_blank = NULL;
48138+ pax_close_kernel();
48139+ }
48140
48141 /*
48142 * Find out how much IO memory is required for the mode with
48143@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48144 info->flags = FBINFO_FLAG_DEFAULT |
48145 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
48146
48147- if (!par->ypan)
48148- info->fbops->fb_pan_display = NULL;
48149+ if (!par->ypan) {
48150+ pax_open_kernel();
48151+ *(void **)&info->fbops->fb_pan_display = NULL;
48152+ pax_close_kernel();
48153+ }
48154 }
48155
48156 static void uvesafb_init_mtrr(struct fb_info *info)
48157@@ -1836,6 +1866,11 @@ out:
48158 if (par->vbe_modes)
48159 kfree(par->vbe_modes);
48160
48161+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48162+ if (par->pmi_code)
48163+ module_free_exec(NULL, par->pmi_code);
48164+#endif
48165+
48166 framebuffer_release(info);
48167 return err;
48168 }
48169@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
48170 kfree(par->vbe_state_orig);
48171 if (par->vbe_state_saved)
48172 kfree(par->vbe_state_saved);
48173+
48174+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48175+ if (par->pmi_code)
48176+ module_free_exec(NULL, par->pmi_code);
48177+#endif
48178+
48179 }
48180
48181 framebuffer_release(info);
48182diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
48183index 501b340..d80aa17 100644
48184--- a/drivers/video/vesafb.c
48185+++ b/drivers/video/vesafb.c
48186@@ -9,6 +9,7 @@
48187 */
48188
48189 #include <linux/module.h>
48190+#include <linux/moduleloader.h>
48191 #include <linux/kernel.h>
48192 #include <linux/errno.h>
48193 #include <linux/string.h>
48194@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
48195 static int vram_total __initdata; /* Set total amount of memory */
48196 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
48197 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
48198-static void (*pmi_start)(void) __read_mostly;
48199-static void (*pmi_pal) (void) __read_mostly;
48200+static void (*pmi_start)(void) __read_only;
48201+static void (*pmi_pal) (void) __read_only;
48202 static int depth __read_mostly;
48203 static int vga_compat __read_mostly;
48204 /* --------------------------------------------------------------------- */
48205@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
48206 unsigned int size_vmode;
48207 unsigned int size_remap;
48208 unsigned int size_total;
48209+ void *pmi_code = NULL;
48210
48211 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
48212 return -ENODEV;
48213@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
48214 size_remap = size_total;
48215 vesafb_fix.smem_len = size_remap;
48216
48217-#ifndef __i386__
48218- screen_info.vesapm_seg = 0;
48219-#endif
48220-
48221 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
48222 printk(KERN_WARNING
48223 "vesafb: cannot reserve video memory at 0x%lx\n",
48224@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
48225 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
48226 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
48227
48228+#ifdef __i386__
48229+
48230+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48231+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
48232+ if (!pmi_code)
48233+#elif !defined(CONFIG_PAX_KERNEXEC)
48234+ if (0)
48235+#endif
48236+
48237+#endif
48238+ screen_info.vesapm_seg = 0;
48239+
48240 if (screen_info.vesapm_seg) {
48241- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
48242- screen_info.vesapm_seg,screen_info.vesapm_off);
48243+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
48244+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
48245 }
48246
48247 if (screen_info.vesapm_seg < 0xc000)
48248@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
48249
48250 if (ypan || pmi_setpal) {
48251 unsigned short *pmi_base;
48252+
48253 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
48254- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
48255- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
48256+
48257+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48258+ pax_open_kernel();
48259+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
48260+#else
48261+ pmi_code = pmi_base;
48262+#endif
48263+
48264+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
48265+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
48266+
48267+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48268+ pmi_start = ktva_ktla(pmi_start);
48269+ pmi_pal = ktva_ktla(pmi_pal);
48270+ pax_close_kernel();
48271+#endif
48272+
48273 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
48274 if (pmi_base[3]) {
48275 printk(KERN_INFO "vesafb: pmi: ports = ");
48276@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48277 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
48278 (ypan ? FBINFO_HWACCEL_YPAN : 0);
48279
48280- if (!ypan)
48281- info->fbops->fb_pan_display = NULL;
48282+ if (!ypan) {
48283+ pax_open_kernel();
48284+ *(void **)&info->fbops->fb_pan_display = NULL;
48285+ pax_close_kernel();
48286+ }
48287
48288 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
48289 err = -ENOMEM;
48290@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48291 info->node, info->fix.id);
48292 return 0;
48293 err:
48294+
48295+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48296+ module_free_exec(NULL, pmi_code);
48297+#endif
48298+
48299 if (info->screen_base)
48300 iounmap(info->screen_base);
48301 framebuffer_release(info);
48302diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
48303index 88714ae..16c2e11 100644
48304--- a/drivers/video/via/via_clock.h
48305+++ b/drivers/video/via/via_clock.h
48306@@ -56,7 +56,7 @@ struct via_clock {
48307
48308 void (*set_engine_pll_state)(u8 state);
48309 void (*set_engine_pll)(struct via_pll_config config);
48310-};
48311+} __no_const;
48312
48313
48314 static inline u32 get_pll_internal_frequency(u32 ref_freq,
48315diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
48316index fef20db..d28b1ab 100644
48317--- a/drivers/xen/xenfs/xenstored.c
48318+++ b/drivers/xen/xenfs/xenstored.c
48319@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
48320 static int xsd_kva_open(struct inode *inode, struct file *file)
48321 {
48322 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
48323+#ifdef CONFIG_GRKERNSEC_HIDESYM
48324+ NULL);
48325+#else
48326 xen_store_interface);
48327+#endif
48328+
48329 if (!file->private_data)
48330 return -ENOMEM;
48331 return 0;
48332diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
48333index 055562c..fdfb10d 100644
48334--- a/fs/9p/vfs_addr.c
48335+++ b/fs/9p/vfs_addr.c
48336@@ -186,7 +186,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
48337
48338 retval = v9fs_file_write_internal(inode,
48339 v9inode->writeback_fid,
48340- (__force const char __user *)buffer,
48341+ (const char __force_user *)buffer,
48342 len, &offset, 0);
48343 if (retval > 0)
48344 retval = 0;
48345diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
48346index d86edc8..40ff2fb 100644
48347--- a/fs/9p/vfs_inode.c
48348+++ b/fs/9p/vfs_inode.c
48349@@ -1314,7 +1314,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48350 void
48351 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48352 {
48353- char *s = nd_get_link(nd);
48354+ const char *s = nd_get_link(nd);
48355
48356 p9_debug(P9_DEBUG_VFS, " %s %s\n",
48357 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
48358diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
48359index 370b24c..ff0be7b 100644
48360--- a/fs/Kconfig.binfmt
48361+++ b/fs/Kconfig.binfmt
48362@@ -103,7 +103,7 @@ config HAVE_AOUT
48363
48364 config BINFMT_AOUT
48365 tristate "Kernel support for a.out and ECOFF binaries"
48366- depends on HAVE_AOUT
48367+ depends on HAVE_AOUT && BROKEN
48368 ---help---
48369 A.out (Assembler.OUTput) is a set of formats for libraries and
48370 executables used in the earliest versions of UNIX. Linux used
48371diff --git a/fs/aio.c b/fs/aio.c
48372index 2bbcacf..8614116 100644
48373--- a/fs/aio.c
48374+++ b/fs/aio.c
48375@@ -160,7 +160,7 @@ static int aio_setup_ring(struct kioctx *ctx)
48376 size += sizeof(struct io_event) * nr_events;
48377 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
48378
48379- if (nr_pages < 0)
48380+ if (nr_pages <= 0)
48381 return -EINVAL;
48382
48383 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
48384@@ -950,6 +950,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
48385 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
48386 {
48387 ssize_t ret;
48388+ struct iovec iovstack;
48389
48390 kiocb->ki_nr_segs = kiocb->ki_nbytes;
48391
48392@@ -957,17 +958,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
48393 if (compat)
48394 ret = compat_rw_copy_check_uvector(rw,
48395 (struct compat_iovec __user *)kiocb->ki_buf,
48396- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
48397+ kiocb->ki_nr_segs, 1, &iovstack,
48398 &kiocb->ki_iovec);
48399 else
48400 #endif
48401 ret = rw_copy_check_uvector(rw,
48402 (struct iovec __user *)kiocb->ki_buf,
48403- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
48404+ kiocb->ki_nr_segs, 1, &iovstack,
48405 &kiocb->ki_iovec);
48406 if (ret < 0)
48407 return ret;
48408
48409+ if (kiocb->ki_iovec == &iovstack) {
48410+ kiocb->ki_inline_vec = iovstack;
48411+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
48412+ }
48413+
48414 /* ki_nbytes now reflect bytes instead of segs */
48415 kiocb->ki_nbytes = ret;
48416 return 0;
48417diff --git a/fs/attr.c b/fs/attr.c
48418index 1449adb..a2038c2 100644
48419--- a/fs/attr.c
48420+++ b/fs/attr.c
48421@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
48422 unsigned long limit;
48423
48424 limit = rlimit(RLIMIT_FSIZE);
48425+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
48426 if (limit != RLIM_INFINITY && offset > limit)
48427 goto out_sig;
48428 if (offset > inode->i_sb->s_maxbytes)
48429diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
48430index 3db70da..7aeec5b 100644
48431--- a/fs/autofs4/waitq.c
48432+++ b/fs/autofs4/waitq.c
48433@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
48434 {
48435 unsigned long sigpipe, flags;
48436 mm_segment_t fs;
48437- const char *data = (const char *)addr;
48438+ const char __user *data = (const char __force_user *)addr;
48439 ssize_t wr = 0;
48440
48441 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
48442@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
48443 return 1;
48444 }
48445
48446+#ifdef CONFIG_GRKERNSEC_HIDESYM
48447+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
48448+#endif
48449+
48450 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48451 enum autofs_notify notify)
48452 {
48453@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48454
48455 /* If this is a direct mount request create a dummy name */
48456 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
48457+#ifdef CONFIG_GRKERNSEC_HIDESYM
48458+ /* this name does get written to userland via autofs4_write() */
48459+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
48460+#else
48461 qstr.len = sprintf(name, "%p", dentry);
48462+#endif
48463 else {
48464 qstr.len = autofs4_getpath(sbi, dentry, &name);
48465 if (!qstr.len) {
48466diff --git a/fs/befs/endian.h b/fs/befs/endian.h
48467index 2722387..c8dd2a7 100644
48468--- a/fs/befs/endian.h
48469+++ b/fs/befs/endian.h
48470@@ -11,7 +11,7 @@
48471
48472 #include <asm/byteorder.h>
48473
48474-static inline u64
48475+static inline u64 __intentional_overflow(-1)
48476 fs64_to_cpu(const struct super_block *sb, fs64 n)
48477 {
48478 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48479@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
48480 return (__force fs64)cpu_to_be64(n);
48481 }
48482
48483-static inline u32
48484+static inline u32 __intentional_overflow(-1)
48485 fs32_to_cpu(const struct super_block *sb, fs32 n)
48486 {
48487 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48488diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
48489index f95dddc..b1e2c1c 100644
48490--- a/fs/befs/linuxvfs.c
48491+++ b/fs/befs/linuxvfs.c
48492@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48493 {
48494 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
48495 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
48496- char *link = nd_get_link(nd);
48497+ const char *link = nd_get_link(nd);
48498 if (!IS_ERR(link))
48499 kfree(link);
48500 }
48501diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
48502index bce8769..7fc7544 100644
48503--- a/fs/binfmt_aout.c
48504+++ b/fs/binfmt_aout.c
48505@@ -16,6 +16,7 @@
48506 #include <linux/string.h>
48507 #include <linux/fs.h>
48508 #include <linux/file.h>
48509+#include <linux/security.h>
48510 #include <linux/stat.h>
48511 #include <linux/fcntl.h>
48512 #include <linux/ptrace.h>
48513@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
48514 #endif
48515 # define START_STACK(u) ((void __user *)u.start_stack)
48516
48517+ memset(&dump, 0, sizeof(dump));
48518+
48519 fs = get_fs();
48520 set_fs(KERNEL_DS);
48521 has_dumped = 1;
48522@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
48523
48524 /* If the size of the dump file exceeds the rlimit, then see what would happen
48525 if we wrote the stack, but not the data area. */
48526+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
48527 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
48528 dump.u_dsize = 0;
48529
48530 /* Make sure we have enough room to write the stack and data areas. */
48531+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
48532 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
48533 dump.u_ssize = 0;
48534
48535@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
48536 rlim = rlimit(RLIMIT_DATA);
48537 if (rlim >= RLIM_INFINITY)
48538 rlim = ~0;
48539+
48540+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
48541 if (ex.a_data + ex.a_bss > rlim)
48542 return -ENOMEM;
48543
48544@@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
48545
48546 install_exec_creds(bprm);
48547
48548+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48549+ current->mm->pax_flags = 0UL;
48550+#endif
48551+
48552+#ifdef CONFIG_PAX_PAGEEXEC
48553+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
48554+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
48555+
48556+#ifdef CONFIG_PAX_EMUTRAMP
48557+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
48558+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
48559+#endif
48560+
48561+#ifdef CONFIG_PAX_MPROTECT
48562+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
48563+ current->mm->pax_flags |= MF_PAX_MPROTECT;
48564+#endif
48565+
48566+ }
48567+#endif
48568+
48569 if (N_MAGIC(ex) == OMAGIC) {
48570 unsigned long text_addr, map_size;
48571 loff_t pos;
48572@@ -324,7 +352,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
48573 }
48574
48575 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
48576- PROT_READ | PROT_WRITE | PROT_EXEC,
48577+ PROT_READ | PROT_WRITE,
48578 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
48579 fd_offset + ex.a_text);
48580 if (error != N_DATADDR(ex)) {
48581diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
48582index f8a0b0e..8186af0 100644
48583--- a/fs/binfmt_elf.c
48584+++ b/fs/binfmt_elf.c
48585@@ -34,6 +34,7 @@
48586 #include <linux/utsname.h>
48587 #include <linux/coredump.h>
48588 #include <linux/sched.h>
48589+#include <linux/xattr.h>
48590 #include <asm/uaccess.h>
48591 #include <asm/param.h>
48592 #include <asm/page.h>
48593@@ -60,6 +61,10 @@ static int elf_core_dump(struct coredump_params *cprm);
48594 #define elf_core_dump NULL
48595 #endif
48596
48597+#ifdef CONFIG_PAX_MPROTECT
48598+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
48599+#endif
48600+
48601 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
48602 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
48603 #else
48604@@ -79,6 +84,11 @@ static struct linux_binfmt elf_format = {
48605 .load_binary = load_elf_binary,
48606 .load_shlib = load_elf_library,
48607 .core_dump = elf_core_dump,
48608+
48609+#ifdef CONFIG_PAX_MPROTECT
48610+ .handle_mprotect= elf_handle_mprotect,
48611+#endif
48612+
48613 .min_coredump = ELF_EXEC_PAGESIZE,
48614 };
48615
48616@@ -86,6 +96,8 @@ static struct linux_binfmt elf_format = {
48617
48618 static int set_brk(unsigned long start, unsigned long end)
48619 {
48620+ unsigned long e = end;
48621+
48622 start = ELF_PAGEALIGN(start);
48623 end = ELF_PAGEALIGN(end);
48624 if (end > start) {
48625@@ -94,7 +106,7 @@ static int set_brk(unsigned long start, unsigned long end)
48626 if (BAD_ADDR(addr))
48627 return addr;
48628 }
48629- current->mm->start_brk = current->mm->brk = end;
48630+ current->mm->start_brk = current->mm->brk = e;
48631 return 0;
48632 }
48633
48634@@ -155,12 +167,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48635 elf_addr_t __user *u_rand_bytes;
48636 const char *k_platform = ELF_PLATFORM;
48637 const char *k_base_platform = ELF_BASE_PLATFORM;
48638- unsigned char k_rand_bytes[16];
48639+ u32 k_rand_bytes[4];
48640 int items;
48641 elf_addr_t *elf_info;
48642 int ei_index = 0;
48643 const struct cred *cred = current_cred();
48644 struct vm_area_struct *vma;
48645+ unsigned long saved_auxv[AT_VECTOR_SIZE];
48646
48647 /*
48648 * In some cases (e.g. Hyper-Threading), we want to avoid L1
48649@@ -202,8 +215,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48650 * Generate 16 random bytes for userspace PRNG seeding.
48651 */
48652 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
48653- u_rand_bytes = (elf_addr_t __user *)
48654- STACK_ALLOC(p, sizeof(k_rand_bytes));
48655+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
48656+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
48657+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
48658+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
48659+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
48660+ u_rand_bytes = (elf_addr_t __user *) p;
48661 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
48662 return -EFAULT;
48663
48664@@ -318,9 +335,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48665 return -EFAULT;
48666 current->mm->env_end = p;
48667
48668+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
48669+
48670 /* Put the elf_info on the stack in the right place. */
48671 sp = (elf_addr_t __user *)envp + 1;
48672- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
48673+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
48674 return -EFAULT;
48675 return 0;
48676 }
48677@@ -388,15 +407,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
48678 an ELF header */
48679
48680 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48681- struct file *interpreter, unsigned long *interp_map_addr,
48682- unsigned long no_base)
48683+ struct file *interpreter, unsigned long no_base)
48684 {
48685 struct elf_phdr *elf_phdata;
48686 struct elf_phdr *eppnt;
48687- unsigned long load_addr = 0;
48688+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48689 int load_addr_set = 0;
48690 unsigned long last_bss = 0, elf_bss = 0;
48691- unsigned long error = ~0UL;
48692+ unsigned long error = -EINVAL;
48693 unsigned long total_size;
48694 int retval, i, size;
48695
48696@@ -442,6 +460,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48697 goto out_close;
48698 }
48699
48700+#ifdef CONFIG_PAX_SEGMEXEC
48701+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48702+ pax_task_size = SEGMEXEC_TASK_SIZE;
48703+#endif
48704+
48705 eppnt = elf_phdata;
48706 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48707 if (eppnt->p_type == PT_LOAD) {
48708@@ -465,8 +488,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48709 map_addr = elf_map(interpreter, load_addr + vaddr,
48710 eppnt, elf_prot, elf_type, total_size);
48711 total_size = 0;
48712- if (!*interp_map_addr)
48713- *interp_map_addr = map_addr;
48714 error = map_addr;
48715 if (BAD_ADDR(map_addr))
48716 goto out_close;
48717@@ -485,8 +506,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48718 k = load_addr + eppnt->p_vaddr;
48719 if (BAD_ADDR(k) ||
48720 eppnt->p_filesz > eppnt->p_memsz ||
48721- eppnt->p_memsz > TASK_SIZE ||
48722- TASK_SIZE - eppnt->p_memsz < k) {
48723+ eppnt->p_memsz > pax_task_size ||
48724+ pax_task_size - eppnt->p_memsz < k) {
48725 error = -ENOMEM;
48726 goto out_close;
48727 }
48728@@ -538,6 +559,315 @@ out:
48729 return error;
48730 }
48731
48732+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48733+#ifdef CONFIG_PAX_SOFTMODE
48734+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48735+{
48736+ unsigned long pax_flags = 0UL;
48737+
48738+#ifdef CONFIG_PAX_PAGEEXEC
48739+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48740+ pax_flags |= MF_PAX_PAGEEXEC;
48741+#endif
48742+
48743+#ifdef CONFIG_PAX_SEGMEXEC
48744+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48745+ pax_flags |= MF_PAX_SEGMEXEC;
48746+#endif
48747+
48748+#ifdef CONFIG_PAX_EMUTRAMP
48749+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48750+ pax_flags |= MF_PAX_EMUTRAMP;
48751+#endif
48752+
48753+#ifdef CONFIG_PAX_MPROTECT
48754+ if (elf_phdata->p_flags & PF_MPROTECT)
48755+ pax_flags |= MF_PAX_MPROTECT;
48756+#endif
48757+
48758+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48759+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48760+ pax_flags |= MF_PAX_RANDMMAP;
48761+#endif
48762+
48763+ return pax_flags;
48764+}
48765+#endif
48766+
48767+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48768+{
48769+ unsigned long pax_flags = 0UL;
48770+
48771+#ifdef CONFIG_PAX_PAGEEXEC
48772+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48773+ pax_flags |= MF_PAX_PAGEEXEC;
48774+#endif
48775+
48776+#ifdef CONFIG_PAX_SEGMEXEC
48777+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48778+ pax_flags |= MF_PAX_SEGMEXEC;
48779+#endif
48780+
48781+#ifdef CONFIG_PAX_EMUTRAMP
48782+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48783+ pax_flags |= MF_PAX_EMUTRAMP;
48784+#endif
48785+
48786+#ifdef CONFIG_PAX_MPROTECT
48787+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48788+ pax_flags |= MF_PAX_MPROTECT;
48789+#endif
48790+
48791+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48792+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48793+ pax_flags |= MF_PAX_RANDMMAP;
48794+#endif
48795+
48796+ return pax_flags;
48797+}
48798+#endif
48799+
48800+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48801+#ifdef CONFIG_PAX_SOFTMODE
48802+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48803+{
48804+ unsigned long pax_flags = 0UL;
48805+
48806+#ifdef CONFIG_PAX_PAGEEXEC
48807+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48808+ pax_flags |= MF_PAX_PAGEEXEC;
48809+#endif
48810+
48811+#ifdef CONFIG_PAX_SEGMEXEC
48812+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48813+ pax_flags |= MF_PAX_SEGMEXEC;
48814+#endif
48815+
48816+#ifdef CONFIG_PAX_EMUTRAMP
48817+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48818+ pax_flags |= MF_PAX_EMUTRAMP;
48819+#endif
48820+
48821+#ifdef CONFIG_PAX_MPROTECT
48822+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48823+ pax_flags |= MF_PAX_MPROTECT;
48824+#endif
48825+
48826+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48827+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48828+ pax_flags |= MF_PAX_RANDMMAP;
48829+#endif
48830+
48831+ return pax_flags;
48832+}
48833+#endif
48834+
48835+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48836+{
48837+ unsigned long pax_flags = 0UL;
48838+
48839+#ifdef CONFIG_PAX_PAGEEXEC
48840+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48841+ pax_flags |= MF_PAX_PAGEEXEC;
48842+#endif
48843+
48844+#ifdef CONFIG_PAX_SEGMEXEC
48845+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48846+ pax_flags |= MF_PAX_SEGMEXEC;
48847+#endif
48848+
48849+#ifdef CONFIG_PAX_EMUTRAMP
48850+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48851+ pax_flags |= MF_PAX_EMUTRAMP;
48852+#endif
48853+
48854+#ifdef CONFIG_PAX_MPROTECT
48855+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48856+ pax_flags |= MF_PAX_MPROTECT;
48857+#endif
48858+
48859+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48860+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48861+ pax_flags |= MF_PAX_RANDMMAP;
48862+#endif
48863+
48864+ return pax_flags;
48865+}
48866+#endif
48867+
48868+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48869+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48870+{
48871+ unsigned long pax_flags = 0UL;
48872+
48873+#ifdef CONFIG_PAX_EI_PAX
48874+
48875+#ifdef CONFIG_PAX_PAGEEXEC
48876+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48877+ pax_flags |= MF_PAX_PAGEEXEC;
48878+#endif
48879+
48880+#ifdef CONFIG_PAX_SEGMEXEC
48881+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48882+ pax_flags |= MF_PAX_SEGMEXEC;
48883+#endif
48884+
48885+#ifdef CONFIG_PAX_EMUTRAMP
48886+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48887+ pax_flags |= MF_PAX_EMUTRAMP;
48888+#endif
48889+
48890+#ifdef CONFIG_PAX_MPROTECT
48891+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48892+ pax_flags |= MF_PAX_MPROTECT;
48893+#endif
48894+
48895+#ifdef CONFIG_PAX_ASLR
48896+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48897+ pax_flags |= MF_PAX_RANDMMAP;
48898+#endif
48899+
48900+#else
48901+
48902+#ifdef CONFIG_PAX_PAGEEXEC
48903+ pax_flags |= MF_PAX_PAGEEXEC;
48904+#endif
48905+
48906+#ifdef CONFIG_PAX_SEGMEXEC
48907+ pax_flags |= MF_PAX_SEGMEXEC;
48908+#endif
48909+
48910+#ifdef CONFIG_PAX_MPROTECT
48911+ pax_flags |= MF_PAX_MPROTECT;
48912+#endif
48913+
48914+#ifdef CONFIG_PAX_RANDMMAP
48915+ if (randomize_va_space)
48916+ pax_flags |= MF_PAX_RANDMMAP;
48917+#endif
48918+
48919+#endif
48920+
48921+ return pax_flags;
48922+}
48923+
48924+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48925+{
48926+
48927+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48928+ unsigned long i;
48929+
48930+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48931+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48932+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48933+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48934+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48935+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48936+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48937+ return ~0UL;
48938+
48939+#ifdef CONFIG_PAX_SOFTMODE
48940+ if (pax_softmode)
48941+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48942+ else
48943+#endif
48944+
48945+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48946+ break;
48947+ }
48948+#endif
48949+
48950+ return ~0UL;
48951+}
48952+
48953+static unsigned long pax_parse_xattr_pax(struct file * const file)
48954+{
48955+
48956+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48957+ ssize_t xattr_size, i;
48958+ unsigned char xattr_value[sizeof("pemrs") - 1];
48959+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
48960+
48961+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
48962+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
48963+ return ~0UL;
48964+
48965+ for (i = 0; i < xattr_size; i++)
48966+ switch (xattr_value[i]) {
48967+ default:
48968+ return ~0UL;
48969+
48970+#define parse_flag(option1, option2, flag) \
48971+ case option1: \
48972+ if (pax_flags_hardmode & MF_PAX_##flag) \
48973+ return ~0UL; \
48974+ pax_flags_hardmode |= MF_PAX_##flag; \
48975+ break; \
48976+ case option2: \
48977+ if (pax_flags_softmode & MF_PAX_##flag) \
48978+ return ~0UL; \
48979+ pax_flags_softmode |= MF_PAX_##flag; \
48980+ break;
48981+
48982+ parse_flag('p', 'P', PAGEEXEC);
48983+ parse_flag('e', 'E', EMUTRAMP);
48984+ parse_flag('m', 'M', MPROTECT);
48985+ parse_flag('r', 'R', RANDMMAP);
48986+ parse_flag('s', 'S', SEGMEXEC);
48987+
48988+#undef parse_flag
48989+ }
48990+
48991+ if (pax_flags_hardmode & pax_flags_softmode)
48992+ return ~0UL;
48993+
48994+#ifdef CONFIG_PAX_SOFTMODE
48995+ if (pax_softmode)
48996+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
48997+ else
48998+#endif
48999+
49000+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
49001+#else
49002+ return ~0UL;
49003+#endif
49004+
49005+}
49006+
49007+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
49008+{
49009+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
49010+
49011+ pax_flags = pax_parse_ei_pax(elf_ex);
49012+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
49013+ xattr_pax_flags = pax_parse_xattr_pax(file);
49014+
49015+ if (pt_pax_flags == ~0UL)
49016+ pt_pax_flags = xattr_pax_flags;
49017+ else if (xattr_pax_flags == ~0UL)
49018+ xattr_pax_flags = pt_pax_flags;
49019+ if (pt_pax_flags != xattr_pax_flags)
49020+ return -EINVAL;
49021+ if (pt_pax_flags != ~0UL)
49022+ pax_flags = pt_pax_flags;
49023+
49024+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
49025+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49026+ if ((__supported_pte_mask & _PAGE_NX))
49027+ pax_flags &= ~MF_PAX_SEGMEXEC;
49028+ else
49029+ pax_flags &= ~MF_PAX_PAGEEXEC;
49030+ }
49031+#endif
49032+
49033+ if (0 > pax_check_flags(&pax_flags))
49034+ return -EINVAL;
49035+
49036+ current->mm->pax_flags = pax_flags;
49037+ return 0;
49038+}
49039+#endif
49040+
49041 /*
49042 * These are the functions used to load ELF style executables and shared
49043 * libraries. There is no binary dependent code anywhere else.
49044@@ -554,6 +884,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
49045 {
49046 unsigned int random_variable = 0;
49047
49048+#ifdef CONFIG_PAX_RANDUSTACK
49049+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
49050+ return stack_top - current->mm->delta_stack;
49051+#endif
49052+
49053 if ((current->flags & PF_RANDOMIZE) &&
49054 !(current->personality & ADDR_NO_RANDOMIZE)) {
49055 random_variable = get_random_int() & STACK_RND_MASK;
49056@@ -572,7 +907,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
49057 unsigned long load_addr = 0, load_bias = 0;
49058 int load_addr_set = 0;
49059 char * elf_interpreter = NULL;
49060- unsigned long error;
49061+ unsigned long error = 0;
49062 struct elf_phdr *elf_ppnt, *elf_phdata;
49063 unsigned long elf_bss, elf_brk;
49064 int retval, i;
49065@@ -582,12 +917,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
49066 unsigned long start_code, end_code, start_data, end_data;
49067 unsigned long reloc_func_desc __maybe_unused = 0;
49068 int executable_stack = EXSTACK_DEFAULT;
49069- unsigned long def_flags = 0;
49070 struct pt_regs *regs = current_pt_regs();
49071 struct {
49072 struct elfhdr elf_ex;
49073 struct elfhdr interp_elf_ex;
49074 } *loc;
49075+ unsigned long pax_task_size = TASK_SIZE;
49076
49077 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
49078 if (!loc) {
49079@@ -723,11 +1058,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
49080 goto out_free_dentry;
49081
49082 /* OK, This is the point of no return */
49083- current->mm->def_flags = def_flags;
49084+
49085+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49086+ current->mm->pax_flags = 0UL;
49087+#endif
49088+
49089+#ifdef CONFIG_PAX_DLRESOLVE
49090+ current->mm->call_dl_resolve = 0UL;
49091+#endif
49092+
49093+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
49094+ current->mm->call_syscall = 0UL;
49095+#endif
49096+
49097+#ifdef CONFIG_PAX_ASLR
49098+ current->mm->delta_mmap = 0UL;
49099+ current->mm->delta_stack = 0UL;
49100+#endif
49101+
49102+ current->mm->def_flags = 0;
49103+
49104+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49105+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
49106+ send_sig(SIGKILL, current, 0);
49107+ goto out_free_dentry;
49108+ }
49109+#endif
49110+
49111+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49112+ pax_set_initial_flags(bprm);
49113+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
49114+ if (pax_set_initial_flags_func)
49115+ (pax_set_initial_flags_func)(bprm);
49116+#endif
49117+
49118+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49119+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
49120+ current->mm->context.user_cs_limit = PAGE_SIZE;
49121+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
49122+ }
49123+#endif
49124+
49125+#ifdef CONFIG_PAX_SEGMEXEC
49126+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
49127+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
49128+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
49129+ pax_task_size = SEGMEXEC_TASK_SIZE;
49130+ current->mm->def_flags |= VM_NOHUGEPAGE;
49131+ }
49132+#endif
49133+
49134+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
49135+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49136+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
49137+ put_cpu();
49138+ }
49139+#endif
49140
49141 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
49142 may depend on the personality. */
49143 SET_PERSONALITY(loc->elf_ex);
49144+
49145+#ifdef CONFIG_PAX_ASLR
49146+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49147+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
49148+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
49149+ }
49150+#endif
49151+
49152+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49153+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49154+ executable_stack = EXSTACK_DISABLE_X;
49155+ current->personality &= ~READ_IMPLIES_EXEC;
49156+ } else
49157+#endif
49158+
49159 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
49160 current->personality |= READ_IMPLIES_EXEC;
49161
49162@@ -819,6 +1224,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
49163 #else
49164 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
49165 #endif
49166+
49167+#ifdef CONFIG_PAX_RANDMMAP
49168+ /* PaX: randomize base address at the default exe base if requested */
49169+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
49170+#ifdef CONFIG_SPARC64
49171+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
49172+#else
49173+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
49174+#endif
49175+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
49176+ elf_flags |= MAP_FIXED;
49177+ }
49178+#endif
49179+
49180 }
49181
49182 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
49183@@ -851,9 +1270,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
49184 * allowed task size. Note that p_filesz must always be
49185 * <= p_memsz so it is only necessary to check p_memsz.
49186 */
49187- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49188- elf_ppnt->p_memsz > TASK_SIZE ||
49189- TASK_SIZE - elf_ppnt->p_memsz < k) {
49190+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49191+ elf_ppnt->p_memsz > pax_task_size ||
49192+ pax_task_size - elf_ppnt->p_memsz < k) {
49193 /* set_brk can never work. Avoid overflows. */
49194 send_sig(SIGKILL, current, 0);
49195 retval = -EINVAL;
49196@@ -892,17 +1311,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
49197 goto out_free_dentry;
49198 }
49199 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
49200- send_sig(SIGSEGV, current, 0);
49201- retval = -EFAULT; /* Nobody gets to see this, but.. */
49202- goto out_free_dentry;
49203+ /*
49204+ * This bss-zeroing can fail if the ELF
49205+ * file specifies odd protections. So
49206+ * we don't check the return value
49207+ */
49208 }
49209
49210+#ifdef CONFIG_PAX_RANDMMAP
49211+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49212+ unsigned long start, size, flags;
49213+ vm_flags_t vm_flags;
49214+
49215+ start = ELF_PAGEALIGN(elf_brk);
49216+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
49217+ flags = MAP_FIXED | MAP_PRIVATE;
49218+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
49219+
49220+ down_write(&current->mm->mmap_sem);
49221+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
49222+ retval = -ENOMEM;
49223+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
49224+// if (current->personality & ADDR_NO_RANDOMIZE)
49225+// vm_flags |= VM_READ | VM_MAYREAD;
49226+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
49227+ retval = IS_ERR_VALUE(start) ? start : 0;
49228+ }
49229+ up_write(&current->mm->mmap_sem);
49230+ if (retval == 0)
49231+ retval = set_brk(start + size, start + size + PAGE_SIZE);
49232+ if (retval < 0) {
49233+ send_sig(SIGKILL, current, 0);
49234+ goto out_free_dentry;
49235+ }
49236+ }
49237+#endif
49238+
49239 if (elf_interpreter) {
49240- unsigned long interp_map_addr = 0;
49241-
49242 elf_entry = load_elf_interp(&loc->interp_elf_ex,
49243 interpreter,
49244- &interp_map_addr,
49245 load_bias);
49246 if (!IS_ERR((void *)elf_entry)) {
49247 /*
49248@@ -1124,7 +1571,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
49249 * Decide what to dump of a segment, part, all or none.
49250 */
49251 static unsigned long vma_dump_size(struct vm_area_struct *vma,
49252- unsigned long mm_flags)
49253+ unsigned long mm_flags, long signr)
49254 {
49255 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
49256
49257@@ -1162,7 +1609,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
49258 if (vma->vm_file == NULL)
49259 return 0;
49260
49261- if (FILTER(MAPPED_PRIVATE))
49262+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
49263 goto whole;
49264
49265 /*
49266@@ -1387,9 +1834,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
49267 {
49268 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
49269 int i = 0;
49270- do
49271+ do {
49272 i += 2;
49273- while (auxv[i - 2] != AT_NULL);
49274+ } while (auxv[i - 2] != AT_NULL);
49275 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
49276 }
49277
49278@@ -1398,7 +1845,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
49279 {
49280 mm_segment_t old_fs = get_fs();
49281 set_fs(KERNEL_DS);
49282- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
49283+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
49284 set_fs(old_fs);
49285 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
49286 }
49287@@ -2019,14 +2466,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
49288 }
49289
49290 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
49291- unsigned long mm_flags)
49292+ struct coredump_params *cprm)
49293 {
49294 struct vm_area_struct *vma;
49295 size_t size = 0;
49296
49297 for (vma = first_vma(current, gate_vma); vma != NULL;
49298 vma = next_vma(vma, gate_vma))
49299- size += vma_dump_size(vma, mm_flags);
49300+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49301 return size;
49302 }
49303
49304@@ -2119,7 +2566,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49305
49306 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
49307
49308- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
49309+ offset += elf_core_vma_data_size(gate_vma, cprm);
49310 offset += elf_core_extra_data_size();
49311 e_shoff = offset;
49312
49313@@ -2133,10 +2580,12 @@ static int elf_core_dump(struct coredump_params *cprm)
49314 offset = dataoff;
49315
49316 size += sizeof(*elf);
49317+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49318 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
49319 goto end_coredump;
49320
49321 size += sizeof(*phdr4note);
49322+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49323 if (size > cprm->limit
49324 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
49325 goto end_coredump;
49326@@ -2150,7 +2599,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49327 phdr.p_offset = offset;
49328 phdr.p_vaddr = vma->vm_start;
49329 phdr.p_paddr = 0;
49330- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
49331+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49332 phdr.p_memsz = vma->vm_end - vma->vm_start;
49333 offset += phdr.p_filesz;
49334 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
49335@@ -2161,6 +2610,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49336 phdr.p_align = ELF_EXEC_PAGESIZE;
49337
49338 size += sizeof(phdr);
49339+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49340 if (size > cprm->limit
49341 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
49342 goto end_coredump;
49343@@ -2185,7 +2635,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49344 unsigned long addr;
49345 unsigned long end;
49346
49347- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
49348+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49349
49350 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
49351 struct page *page;
49352@@ -2194,6 +2644,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49353 page = get_dump_page(addr);
49354 if (page) {
49355 void *kaddr = kmap(page);
49356+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
49357 stop = ((size += PAGE_SIZE) > cprm->limit) ||
49358 !dump_write(cprm->file, kaddr,
49359 PAGE_SIZE);
49360@@ -2211,6 +2662,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49361
49362 if (e_phnum == PN_XNUM) {
49363 size += sizeof(*shdr4extnum);
49364+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49365 if (size > cprm->limit
49366 || !dump_write(cprm->file, shdr4extnum,
49367 sizeof(*shdr4extnum)))
49368@@ -2231,6 +2683,97 @@ out:
49369
49370 #endif /* CONFIG_ELF_CORE */
49371
49372+#ifdef CONFIG_PAX_MPROTECT
49373+/* PaX: non-PIC ELF libraries need relocations on their executable segments
49374+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
49375+ * we'll remove VM_MAYWRITE for good on RELRO segments.
49376+ *
49377+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
49378+ * basis because we want to allow the common case and not the special ones.
49379+ */
49380+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
49381+{
49382+ struct elfhdr elf_h;
49383+ struct elf_phdr elf_p;
49384+ unsigned long i;
49385+ unsigned long oldflags;
49386+ bool is_textrel_rw, is_textrel_rx, is_relro;
49387+
49388+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
49389+ return;
49390+
49391+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
49392+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
49393+
49394+#ifdef CONFIG_PAX_ELFRELOCS
49395+ /* possible TEXTREL */
49396+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
49397+ 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);
49398+#else
49399+ is_textrel_rw = false;
49400+ is_textrel_rx = false;
49401+#endif
49402+
49403+ /* possible RELRO */
49404+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
49405+
49406+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
49407+ return;
49408+
49409+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49410+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49411+
49412+#ifdef CONFIG_PAX_ETEXECRELOCS
49413+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49414+#else
49415+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
49416+#endif
49417+
49418+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49419+ !elf_check_arch(&elf_h) ||
49420+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49421+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49422+ return;
49423+
49424+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49425+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49426+ return;
49427+ switch (elf_p.p_type) {
49428+ case PT_DYNAMIC:
49429+ if (!is_textrel_rw && !is_textrel_rx)
49430+ continue;
49431+ i = 0UL;
49432+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
49433+ elf_dyn dyn;
49434+
49435+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
49436+ return;
49437+ if (dyn.d_tag == DT_NULL)
49438+ return;
49439+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
49440+ gr_log_textrel(vma);
49441+ if (is_textrel_rw)
49442+ vma->vm_flags |= VM_MAYWRITE;
49443+ else
49444+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
49445+ vma->vm_flags &= ~VM_MAYWRITE;
49446+ return;
49447+ }
49448+ i++;
49449+ }
49450+ return;
49451+
49452+ case PT_GNU_RELRO:
49453+ if (!is_relro)
49454+ continue;
49455+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
49456+ vma->vm_flags &= ~VM_MAYWRITE;
49457+ return;
49458+ }
49459+ }
49460+}
49461+#endif
49462+
49463 static int __init init_elf_binfmt(void)
49464 {
49465 register_binfmt(&elf_format);
49466diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
49467index d50bbe5..af3b649 100644
49468--- a/fs/binfmt_flat.c
49469+++ b/fs/binfmt_flat.c
49470@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
49471 realdatastart = (unsigned long) -ENOMEM;
49472 printk("Unable to allocate RAM for process data, errno %d\n",
49473 (int)-realdatastart);
49474+ down_write(&current->mm->mmap_sem);
49475 vm_munmap(textpos, text_len);
49476+ up_write(&current->mm->mmap_sem);
49477 ret = realdatastart;
49478 goto err;
49479 }
49480@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49481 }
49482 if (IS_ERR_VALUE(result)) {
49483 printk("Unable to read data+bss, errno %d\n", (int)-result);
49484+ down_write(&current->mm->mmap_sem);
49485 vm_munmap(textpos, text_len);
49486 vm_munmap(realdatastart, len);
49487+ up_write(&current->mm->mmap_sem);
49488 ret = result;
49489 goto err;
49490 }
49491@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49492 }
49493 if (IS_ERR_VALUE(result)) {
49494 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
49495+ down_write(&current->mm->mmap_sem);
49496 vm_munmap(textpos, text_len + data_len + extra +
49497 MAX_SHARED_LIBS * sizeof(unsigned long));
49498+ up_write(&current->mm->mmap_sem);
49499 ret = result;
49500 goto err;
49501 }
49502diff --git a/fs/bio.c b/fs/bio.c
49503index 94bbc04..6fe78a4 100644
49504--- a/fs/bio.c
49505+++ b/fs/bio.c
49506@@ -1096,7 +1096,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
49507 /*
49508 * Overflow, abort
49509 */
49510- if (end < start)
49511+ if (end < start || end - start > INT_MAX - nr_pages)
49512 return ERR_PTR(-EINVAL);
49513
49514 nr_pages += end - start;
49515@@ -1230,7 +1230,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
49516 /*
49517 * Overflow, abort
49518 */
49519- if (end < start)
49520+ if (end < start || end - start > INT_MAX - nr_pages)
49521 return ERR_PTR(-EINVAL);
49522
49523 nr_pages += end - start;
49524@@ -1492,7 +1492,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
49525 const int read = bio_data_dir(bio) == READ;
49526 struct bio_map_data *bmd = bio->bi_private;
49527 int i;
49528- char *p = bmd->sgvecs[0].iov_base;
49529+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
49530
49531 bio_for_each_segment_all(bvec, bio, i) {
49532 char *addr = page_address(bvec->bv_page);
49533diff --git a/fs/block_dev.c b/fs/block_dev.c
49534index 2091db8..81dafe9 100644
49535--- a/fs/block_dev.c
49536+++ b/fs/block_dev.c
49537@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
49538 else if (bdev->bd_contains == bdev)
49539 return true; /* is a whole device which isn't held */
49540
49541- else if (whole->bd_holder == bd_may_claim)
49542+ else if (whole->bd_holder == (void *)bd_may_claim)
49543 return true; /* is a partition of a device that is being partitioned */
49544 else if (whole->bd_holder != NULL)
49545 return false; /* is a partition of a held device */
49546diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
49547index 02fae7f..48da375 100644
49548--- a/fs/btrfs/ctree.c
49549+++ b/fs/btrfs/ctree.c
49550@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
49551 free_extent_buffer(buf);
49552 add_root_to_dirty_list(root);
49553 } else {
49554- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
49555- parent_start = parent->start;
49556- else
49557+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
49558+ if (parent)
49559+ parent_start = parent->start;
49560+ else
49561+ parent_start = 0;
49562+ } else
49563 parent_start = 0;
49564
49565 WARN_ON(trans->transid != btrfs_header_generation(parent));
49566diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
49567index 0f81d67..0ad55fe 100644
49568--- a/fs/btrfs/ioctl.c
49569+++ b/fs/btrfs/ioctl.c
49570@@ -3084,9 +3084,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49571 for (i = 0; i < num_types; i++) {
49572 struct btrfs_space_info *tmp;
49573
49574+ /* Don't copy in more than we allocated */
49575 if (!slot_count)
49576 break;
49577
49578+ slot_count--;
49579+
49580 info = NULL;
49581 rcu_read_lock();
49582 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
49583@@ -3108,10 +3111,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49584 memcpy(dest, &space, sizeof(space));
49585 dest++;
49586 space_args.total_spaces++;
49587- slot_count--;
49588 }
49589- if (!slot_count)
49590- break;
49591 }
49592 up_read(&info->groups_sem);
49593 }
49594diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
49595index f0857e0..e7023c5 100644
49596--- a/fs/btrfs/super.c
49597+++ b/fs/btrfs/super.c
49598@@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
49599 function, line, errstr);
49600 return;
49601 }
49602- ACCESS_ONCE(trans->transaction->aborted) = errno;
49603+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
49604 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
49605 }
49606 /*
49607diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
49608index 622f469..e8d2d55 100644
49609--- a/fs/cachefiles/bind.c
49610+++ b/fs/cachefiles/bind.c
49611@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
49612 args);
49613
49614 /* start by checking things over */
49615- ASSERT(cache->fstop_percent >= 0 &&
49616- cache->fstop_percent < cache->fcull_percent &&
49617+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
49618 cache->fcull_percent < cache->frun_percent &&
49619 cache->frun_percent < 100);
49620
49621- ASSERT(cache->bstop_percent >= 0 &&
49622- cache->bstop_percent < cache->bcull_percent &&
49623+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
49624 cache->bcull_percent < cache->brun_percent &&
49625 cache->brun_percent < 100);
49626
49627diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
49628index 0a1467b..6a53245 100644
49629--- a/fs/cachefiles/daemon.c
49630+++ b/fs/cachefiles/daemon.c
49631@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
49632 if (n > buflen)
49633 return -EMSGSIZE;
49634
49635- if (copy_to_user(_buffer, buffer, n) != 0)
49636+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
49637 return -EFAULT;
49638
49639 return n;
49640@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
49641 if (test_bit(CACHEFILES_DEAD, &cache->flags))
49642 return -EIO;
49643
49644- if (datalen < 0 || datalen > PAGE_SIZE - 1)
49645+ if (datalen > PAGE_SIZE - 1)
49646 return -EOPNOTSUPP;
49647
49648 /* drag the command string into the kernel so we can parse it */
49649@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
49650 if (args[0] != '%' || args[1] != '\0')
49651 return -EINVAL;
49652
49653- if (fstop < 0 || fstop >= cache->fcull_percent)
49654+ if (fstop >= cache->fcull_percent)
49655 return cachefiles_daemon_range_error(cache, args);
49656
49657 cache->fstop_percent = fstop;
49658@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49659 if (args[0] != '%' || args[1] != '\0')
49660 return -EINVAL;
49661
49662- if (bstop < 0 || bstop >= cache->bcull_percent)
49663+ if (bstop >= cache->bcull_percent)
49664 return cachefiles_daemon_range_error(cache, args);
49665
49666 cache->bstop_percent = bstop;
49667diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49668index 4938251..7e01445 100644
49669--- a/fs/cachefiles/internal.h
49670+++ b/fs/cachefiles/internal.h
49671@@ -59,7 +59,7 @@ struct cachefiles_cache {
49672 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49673 struct rb_root active_nodes; /* active nodes (can't be culled) */
49674 rwlock_t active_lock; /* lock for active_nodes */
49675- atomic_t gravecounter; /* graveyard uniquifier */
49676+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49677 unsigned frun_percent; /* when to stop culling (% files) */
49678 unsigned fcull_percent; /* when to start culling (% files) */
49679 unsigned fstop_percent; /* when to stop allocating (% files) */
49680@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49681 * proc.c
49682 */
49683 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49684-extern atomic_t cachefiles_lookup_histogram[HZ];
49685-extern atomic_t cachefiles_mkdir_histogram[HZ];
49686-extern atomic_t cachefiles_create_histogram[HZ];
49687+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49688+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49689+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49690
49691 extern int __init cachefiles_proc_init(void);
49692 extern void cachefiles_proc_cleanup(void);
49693 static inline
49694-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49695+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49696 {
49697 unsigned long jif = jiffies - start_jif;
49698 if (jif >= HZ)
49699 jif = HZ - 1;
49700- atomic_inc(&histogram[jif]);
49701+ atomic_inc_unchecked(&histogram[jif]);
49702 }
49703
49704 #else
49705diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49706index 8c01c5fc..15f982e 100644
49707--- a/fs/cachefiles/namei.c
49708+++ b/fs/cachefiles/namei.c
49709@@ -317,7 +317,7 @@ try_again:
49710 /* first step is to make up a grave dentry in the graveyard */
49711 sprintf(nbuffer, "%08x%08x",
49712 (uint32_t) get_seconds(),
49713- (uint32_t) atomic_inc_return(&cache->gravecounter));
49714+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49715
49716 /* do the multiway lock magic */
49717 trap = lock_rename(cache->graveyard, dir);
49718diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49719index eccd339..4c1d995 100644
49720--- a/fs/cachefiles/proc.c
49721+++ b/fs/cachefiles/proc.c
49722@@ -14,9 +14,9 @@
49723 #include <linux/seq_file.h>
49724 #include "internal.h"
49725
49726-atomic_t cachefiles_lookup_histogram[HZ];
49727-atomic_t cachefiles_mkdir_histogram[HZ];
49728-atomic_t cachefiles_create_histogram[HZ];
49729+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49730+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49731+atomic_unchecked_t cachefiles_create_histogram[HZ];
49732
49733 /*
49734 * display the latency histogram
49735@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49736 return 0;
49737 default:
49738 index = (unsigned long) v - 3;
49739- x = atomic_read(&cachefiles_lookup_histogram[index]);
49740- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49741- z = atomic_read(&cachefiles_create_histogram[index]);
49742+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49743+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49744+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49745 if (x == 0 && y == 0 && z == 0)
49746 return 0;
49747
49748diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49749index 317f9ee..3d24511 100644
49750--- a/fs/cachefiles/rdwr.c
49751+++ b/fs/cachefiles/rdwr.c
49752@@ -966,7 +966,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49753 old_fs = get_fs();
49754 set_fs(KERNEL_DS);
49755 ret = file->f_op->write(
49756- file, (const void __user *) data, len, &pos);
49757+ file, (const void __force_user *) data, len, &pos);
49758 set_fs(old_fs);
49759 kunmap(page);
49760 file_end_write(file);
49761diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49762index f02d82b..2632cf86 100644
49763--- a/fs/ceph/dir.c
49764+++ b/fs/ceph/dir.c
49765@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49766 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49767 struct ceph_mds_client *mdsc = fsc->mdsc;
49768 unsigned frag = fpos_frag(filp->f_pos);
49769- int off = fpos_off(filp->f_pos);
49770+ unsigned int off = fpos_off(filp->f_pos);
49771 int err;
49772 u32 ftype;
49773 struct ceph_mds_reply_info_parsed *rinfo;
49774diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49775index d597483..747901b 100644
49776--- a/fs/cifs/cifs_debug.c
49777+++ b/fs/cifs/cifs_debug.c
49778@@ -284,8 +284,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49779
49780 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49781 #ifdef CONFIG_CIFS_STATS2
49782- atomic_set(&totBufAllocCount, 0);
49783- atomic_set(&totSmBufAllocCount, 0);
49784+ atomic_set_unchecked(&totBufAllocCount, 0);
49785+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49786 #endif /* CONFIG_CIFS_STATS2 */
49787 spin_lock(&cifs_tcp_ses_lock);
49788 list_for_each(tmp1, &cifs_tcp_ses_list) {
49789@@ -298,7 +298,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49790 tcon = list_entry(tmp3,
49791 struct cifs_tcon,
49792 tcon_list);
49793- atomic_set(&tcon->num_smbs_sent, 0);
49794+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49795 if (server->ops->clear_stats)
49796 server->ops->clear_stats(tcon);
49797 }
49798@@ -330,8 +330,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49799 smBufAllocCount.counter, cifs_min_small);
49800 #ifdef CONFIG_CIFS_STATS2
49801 seq_printf(m, "Total Large %d Small %d Allocations\n",
49802- atomic_read(&totBufAllocCount),
49803- atomic_read(&totSmBufAllocCount));
49804+ atomic_read_unchecked(&totBufAllocCount),
49805+ atomic_read_unchecked(&totSmBufAllocCount));
49806 #endif /* CONFIG_CIFS_STATS2 */
49807
49808 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49809@@ -360,7 +360,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49810 if (tcon->need_reconnect)
49811 seq_puts(m, "\tDISCONNECTED ");
49812 seq_printf(m, "\nSMBs: %d",
49813- atomic_read(&tcon->num_smbs_sent));
49814+ atomic_read_unchecked(&tcon->num_smbs_sent));
49815 if (server->ops->print_stats)
49816 server->ops->print_stats(m, tcon);
49817 }
49818diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49819index 3752b9f..8db5569 100644
49820--- a/fs/cifs/cifsfs.c
49821+++ b/fs/cifs/cifsfs.c
49822@@ -1035,7 +1035,7 @@ cifs_init_request_bufs(void)
49823 */
49824 cifs_req_cachep = kmem_cache_create("cifs_request",
49825 CIFSMaxBufSize + max_hdr_size, 0,
49826- SLAB_HWCACHE_ALIGN, NULL);
49827+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49828 if (cifs_req_cachep == NULL)
49829 return -ENOMEM;
49830
49831@@ -1062,7 +1062,7 @@ cifs_init_request_bufs(void)
49832 efficient to alloc 1 per page off the slab compared to 17K (5page)
49833 alloc of large cifs buffers even when page debugging is on */
49834 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49835- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49836+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49837 NULL);
49838 if (cifs_sm_req_cachep == NULL) {
49839 mempool_destroy(cifs_req_poolp);
49840@@ -1147,8 +1147,8 @@ init_cifs(void)
49841 atomic_set(&bufAllocCount, 0);
49842 atomic_set(&smBufAllocCount, 0);
49843 #ifdef CONFIG_CIFS_STATS2
49844- atomic_set(&totBufAllocCount, 0);
49845- atomic_set(&totSmBufAllocCount, 0);
49846+ atomic_set_unchecked(&totBufAllocCount, 0);
49847+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49848 #endif /* CONFIG_CIFS_STATS2 */
49849
49850 atomic_set(&midCount, 0);
49851diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49852index 4f07f6f..55de8ce 100644
49853--- a/fs/cifs/cifsglob.h
49854+++ b/fs/cifs/cifsglob.h
49855@@ -751,35 +751,35 @@ struct cifs_tcon {
49856 __u16 Flags; /* optional support bits */
49857 enum statusEnum tidStatus;
49858 #ifdef CONFIG_CIFS_STATS
49859- atomic_t num_smbs_sent;
49860+ atomic_unchecked_t num_smbs_sent;
49861 union {
49862 struct {
49863- atomic_t num_writes;
49864- atomic_t num_reads;
49865- atomic_t num_flushes;
49866- atomic_t num_oplock_brks;
49867- atomic_t num_opens;
49868- atomic_t num_closes;
49869- atomic_t num_deletes;
49870- atomic_t num_mkdirs;
49871- atomic_t num_posixopens;
49872- atomic_t num_posixmkdirs;
49873- atomic_t num_rmdirs;
49874- atomic_t num_renames;
49875- atomic_t num_t2renames;
49876- atomic_t num_ffirst;
49877- atomic_t num_fnext;
49878- atomic_t num_fclose;
49879- atomic_t num_hardlinks;
49880- atomic_t num_symlinks;
49881- atomic_t num_locks;
49882- atomic_t num_acl_get;
49883- atomic_t num_acl_set;
49884+ atomic_unchecked_t num_writes;
49885+ atomic_unchecked_t num_reads;
49886+ atomic_unchecked_t num_flushes;
49887+ atomic_unchecked_t num_oplock_brks;
49888+ atomic_unchecked_t num_opens;
49889+ atomic_unchecked_t num_closes;
49890+ atomic_unchecked_t num_deletes;
49891+ atomic_unchecked_t num_mkdirs;
49892+ atomic_unchecked_t num_posixopens;
49893+ atomic_unchecked_t num_posixmkdirs;
49894+ atomic_unchecked_t num_rmdirs;
49895+ atomic_unchecked_t num_renames;
49896+ atomic_unchecked_t num_t2renames;
49897+ atomic_unchecked_t num_ffirst;
49898+ atomic_unchecked_t num_fnext;
49899+ atomic_unchecked_t num_fclose;
49900+ atomic_unchecked_t num_hardlinks;
49901+ atomic_unchecked_t num_symlinks;
49902+ atomic_unchecked_t num_locks;
49903+ atomic_unchecked_t num_acl_get;
49904+ atomic_unchecked_t num_acl_set;
49905 } cifs_stats;
49906 #ifdef CONFIG_CIFS_SMB2
49907 struct {
49908- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49909- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49910+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49911+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49912 } smb2_stats;
49913 #endif /* CONFIG_CIFS_SMB2 */
49914 } stats;
49915@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49916 }
49917
49918 #ifdef CONFIG_CIFS_STATS
49919-#define cifs_stats_inc atomic_inc
49920+#define cifs_stats_inc atomic_inc_unchecked
49921
49922 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49923 unsigned int bytes)
49924@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49925 /* Various Debug counters */
49926 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49927 #ifdef CONFIG_CIFS_STATS2
49928-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49929-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49930+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49931+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49932 #endif
49933 GLOBAL_EXTERN atomic_t smBufAllocCount;
49934 GLOBAL_EXTERN atomic_t midCount;
49935diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49936index b83c3f5..6437caa 100644
49937--- a/fs/cifs/link.c
49938+++ b/fs/cifs/link.c
49939@@ -616,7 +616,7 @@ symlink_exit:
49940
49941 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49942 {
49943- char *p = nd_get_link(nd);
49944+ const char *p = nd_get_link(nd);
49945 if (!IS_ERR(p))
49946 kfree(p);
49947 }
49948diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
49949index 1bec014..f329411 100644
49950--- a/fs/cifs/misc.c
49951+++ b/fs/cifs/misc.c
49952@@ -169,7 +169,7 @@ cifs_buf_get(void)
49953 memset(ret_buf, 0, buf_size + 3);
49954 atomic_inc(&bufAllocCount);
49955 #ifdef CONFIG_CIFS_STATS2
49956- atomic_inc(&totBufAllocCount);
49957+ atomic_inc_unchecked(&totBufAllocCount);
49958 #endif /* CONFIG_CIFS_STATS2 */
49959 }
49960
49961@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
49962 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
49963 atomic_inc(&smBufAllocCount);
49964 #ifdef CONFIG_CIFS_STATS2
49965- atomic_inc(&totSmBufAllocCount);
49966+ atomic_inc_unchecked(&totSmBufAllocCount);
49967 #endif /* CONFIG_CIFS_STATS2 */
49968
49969 }
49970diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
49971index 3efdb9d..e845a5e 100644
49972--- a/fs/cifs/smb1ops.c
49973+++ b/fs/cifs/smb1ops.c
49974@@ -591,27 +591,27 @@ static void
49975 cifs_clear_stats(struct cifs_tcon *tcon)
49976 {
49977 #ifdef CONFIG_CIFS_STATS
49978- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
49979- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
49980- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
49981- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49982- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
49983- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
49984- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49985- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
49986- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
49987- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
49988- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
49989- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
49990- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
49991- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
49992- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
49993- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
49994- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
49995- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
49996- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
49997- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
49998- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
49999+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
50000+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
50001+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
50002+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50003+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
50004+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
50005+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50006+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
50007+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
50008+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
50009+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
50010+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
50011+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
50012+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
50013+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
50014+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
50015+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
50016+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
50017+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
50018+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
50019+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
50020 #endif
50021 }
50022
50023@@ -620,36 +620,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50024 {
50025 #ifdef CONFIG_CIFS_STATS
50026 seq_printf(m, " Oplocks breaks: %d",
50027- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
50028+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
50029 seq_printf(m, "\nReads: %d Bytes: %llu",
50030- atomic_read(&tcon->stats.cifs_stats.num_reads),
50031+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
50032 (long long)(tcon->bytes_read));
50033 seq_printf(m, "\nWrites: %d Bytes: %llu",
50034- atomic_read(&tcon->stats.cifs_stats.num_writes),
50035+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
50036 (long long)(tcon->bytes_written));
50037 seq_printf(m, "\nFlushes: %d",
50038- atomic_read(&tcon->stats.cifs_stats.num_flushes));
50039+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
50040 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
50041- atomic_read(&tcon->stats.cifs_stats.num_locks),
50042- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
50043- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
50044+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
50045+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
50046+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
50047 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
50048- atomic_read(&tcon->stats.cifs_stats.num_opens),
50049- atomic_read(&tcon->stats.cifs_stats.num_closes),
50050- atomic_read(&tcon->stats.cifs_stats.num_deletes));
50051+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
50052+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
50053+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
50054 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
50055- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
50056- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
50057+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
50058+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
50059 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
50060- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
50061- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
50062+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
50063+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
50064 seq_printf(m, "\nRenames: %d T2 Renames %d",
50065- atomic_read(&tcon->stats.cifs_stats.num_renames),
50066- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
50067+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
50068+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
50069 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
50070- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
50071- atomic_read(&tcon->stats.cifs_stats.num_fnext),
50072- atomic_read(&tcon->stats.cifs_stats.num_fclose));
50073+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
50074+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
50075+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
50076 #endif
50077 }
50078
50079diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
50080index f2e76f3..c44fac7 100644
50081--- a/fs/cifs/smb2ops.c
50082+++ b/fs/cifs/smb2ops.c
50083@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
50084 #ifdef CONFIG_CIFS_STATS
50085 int i;
50086 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
50087- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50088- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50089+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50090+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50091 }
50092 #endif
50093 }
50094@@ -284,66 +284,66 @@ static void
50095 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50096 {
50097 #ifdef CONFIG_CIFS_STATS
50098- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50099- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50100+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50101+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50102 seq_printf(m, "\nNegotiates: %d sent %d failed",
50103- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
50104- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
50105+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
50106+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
50107 seq_printf(m, "\nSessionSetups: %d sent %d failed",
50108- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
50109- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
50110+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
50111+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
50112 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
50113 seq_printf(m, "\nLogoffs: %d sent %d failed",
50114- atomic_read(&sent[SMB2_LOGOFF_HE]),
50115- atomic_read(&failed[SMB2_LOGOFF_HE]));
50116+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
50117+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
50118 seq_printf(m, "\nTreeConnects: %d sent %d failed",
50119- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
50120- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
50121+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
50122+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
50123 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
50124- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
50125- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
50126+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
50127+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
50128 seq_printf(m, "\nCreates: %d sent %d failed",
50129- atomic_read(&sent[SMB2_CREATE_HE]),
50130- atomic_read(&failed[SMB2_CREATE_HE]));
50131+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
50132+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
50133 seq_printf(m, "\nCloses: %d sent %d failed",
50134- atomic_read(&sent[SMB2_CLOSE_HE]),
50135- atomic_read(&failed[SMB2_CLOSE_HE]));
50136+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
50137+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
50138 seq_printf(m, "\nFlushes: %d sent %d failed",
50139- atomic_read(&sent[SMB2_FLUSH_HE]),
50140- atomic_read(&failed[SMB2_FLUSH_HE]));
50141+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
50142+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
50143 seq_printf(m, "\nReads: %d sent %d failed",
50144- atomic_read(&sent[SMB2_READ_HE]),
50145- atomic_read(&failed[SMB2_READ_HE]));
50146+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
50147+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
50148 seq_printf(m, "\nWrites: %d sent %d failed",
50149- atomic_read(&sent[SMB2_WRITE_HE]),
50150- atomic_read(&failed[SMB2_WRITE_HE]));
50151+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
50152+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
50153 seq_printf(m, "\nLocks: %d sent %d failed",
50154- atomic_read(&sent[SMB2_LOCK_HE]),
50155- atomic_read(&failed[SMB2_LOCK_HE]));
50156+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
50157+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
50158 seq_printf(m, "\nIOCTLs: %d sent %d failed",
50159- atomic_read(&sent[SMB2_IOCTL_HE]),
50160- atomic_read(&failed[SMB2_IOCTL_HE]));
50161+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
50162+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
50163 seq_printf(m, "\nCancels: %d sent %d failed",
50164- atomic_read(&sent[SMB2_CANCEL_HE]),
50165- atomic_read(&failed[SMB2_CANCEL_HE]));
50166+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
50167+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
50168 seq_printf(m, "\nEchos: %d sent %d failed",
50169- atomic_read(&sent[SMB2_ECHO_HE]),
50170- atomic_read(&failed[SMB2_ECHO_HE]));
50171+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
50172+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
50173 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
50174- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
50175- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
50176+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
50177+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
50178 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
50179- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
50180- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
50181+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
50182+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
50183 seq_printf(m, "\nQueryInfos: %d sent %d failed",
50184- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
50185- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
50186+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
50187+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
50188 seq_printf(m, "\nSetInfos: %d sent %d failed",
50189- atomic_read(&sent[SMB2_SET_INFO_HE]),
50190- atomic_read(&failed[SMB2_SET_INFO_HE]));
50191+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
50192+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
50193 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
50194- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
50195- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
50196+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
50197+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
50198 #endif
50199 }
50200
50201diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
50202index 2b95ce2..d079d75 100644
50203--- a/fs/cifs/smb2pdu.c
50204+++ b/fs/cifs/smb2pdu.c
50205@@ -1760,8 +1760,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
50206 default:
50207 cifs_dbg(VFS, "info level %u isn't supported\n",
50208 srch_inf->info_level);
50209- rc = -EINVAL;
50210- goto qdir_exit;
50211+ return -EINVAL;
50212 }
50213
50214 req->FileIndex = cpu_to_le32(index);
50215diff --git a/fs/coda/cache.c b/fs/coda/cache.c
50216index 1da168c..8bc7ff6 100644
50217--- a/fs/coda/cache.c
50218+++ b/fs/coda/cache.c
50219@@ -24,7 +24,7 @@
50220 #include "coda_linux.h"
50221 #include "coda_cache.h"
50222
50223-static atomic_t permission_epoch = ATOMIC_INIT(0);
50224+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
50225
50226 /* replace or extend an acl cache hit */
50227 void coda_cache_enter(struct inode *inode, int mask)
50228@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
50229 struct coda_inode_info *cii = ITOC(inode);
50230
50231 spin_lock(&cii->c_lock);
50232- cii->c_cached_epoch = atomic_read(&permission_epoch);
50233+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
50234 if (!uid_eq(cii->c_uid, current_fsuid())) {
50235 cii->c_uid = current_fsuid();
50236 cii->c_cached_perm = mask;
50237@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
50238 {
50239 struct coda_inode_info *cii = ITOC(inode);
50240 spin_lock(&cii->c_lock);
50241- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
50242+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
50243 spin_unlock(&cii->c_lock);
50244 }
50245
50246 /* remove all acl caches */
50247 void coda_cache_clear_all(struct super_block *sb)
50248 {
50249- atomic_inc(&permission_epoch);
50250+ atomic_inc_unchecked(&permission_epoch);
50251 }
50252
50253
50254@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
50255 spin_lock(&cii->c_lock);
50256 hit = (mask & cii->c_cached_perm) == mask &&
50257 uid_eq(cii->c_uid, current_fsuid()) &&
50258- cii->c_cached_epoch == atomic_read(&permission_epoch);
50259+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
50260 spin_unlock(&cii->c_lock);
50261
50262 return hit;
50263diff --git a/fs/compat.c b/fs/compat.c
50264index fc3b55d..7b568ae 100644
50265--- a/fs/compat.c
50266+++ b/fs/compat.c
50267@@ -54,7 +54,7 @@
50268 #include <asm/ioctls.h>
50269 #include "internal.h"
50270
50271-int compat_log = 1;
50272+int compat_log = 0;
50273
50274 int compat_printk(const char *fmt, ...)
50275 {
50276@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
50277
50278 set_fs(KERNEL_DS);
50279 /* The __user pointer cast is valid because of the set_fs() */
50280- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
50281+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
50282 set_fs(oldfs);
50283 /* truncating is ok because it's a user address */
50284 if (!ret)
50285@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
50286 goto out;
50287
50288 ret = -EINVAL;
50289- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
50290+ if (nr_segs > UIO_MAXIOV)
50291 goto out;
50292 if (nr_segs > fast_segs) {
50293 ret = -ENOMEM;
50294@@ -833,6 +833,7 @@ struct compat_old_linux_dirent {
50295
50296 struct compat_readdir_callback {
50297 struct compat_old_linux_dirent __user *dirent;
50298+ struct file * file;
50299 int result;
50300 };
50301
50302@@ -850,6 +851,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
50303 buf->result = -EOVERFLOW;
50304 return -EOVERFLOW;
50305 }
50306+
50307+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50308+ return 0;
50309+
50310 buf->result++;
50311 dirent = buf->dirent;
50312 if (!access_ok(VERIFY_WRITE, dirent,
50313@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
50314
50315 buf.result = 0;
50316 buf.dirent = dirent;
50317+ buf.file = f.file;
50318
50319 error = vfs_readdir(f.file, compat_fillonedir, &buf);
50320 if (buf.result)
50321@@ -899,6 +905,7 @@ struct compat_linux_dirent {
50322 struct compat_getdents_callback {
50323 struct compat_linux_dirent __user *current_dir;
50324 struct compat_linux_dirent __user *previous;
50325+ struct file * file;
50326 int count;
50327 int error;
50328 };
50329@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
50330 buf->error = -EOVERFLOW;
50331 return -EOVERFLOW;
50332 }
50333+
50334+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50335+ return 0;
50336+
50337 dirent = buf->previous;
50338 if (dirent) {
50339 if (__put_user(offset, &dirent->d_off))
50340@@ -965,6 +976,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50341 buf.previous = NULL;
50342 buf.count = count;
50343 buf.error = 0;
50344+ buf.file = f.file;
50345
50346 error = vfs_readdir(f.file, compat_filldir, &buf);
50347 if (error >= 0)
50348@@ -985,6 +997,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50349 struct compat_getdents_callback64 {
50350 struct linux_dirent64 __user *current_dir;
50351 struct linux_dirent64 __user *previous;
50352+ struct file * file;
50353 int count;
50354 int error;
50355 };
50356@@ -1001,6 +1014,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
50357 buf->error = -EINVAL; /* only used if we fail.. */
50358 if (reclen > buf->count)
50359 return -EINVAL;
50360+
50361+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50362+ return 0;
50363+
50364 dirent = buf->previous;
50365
50366 if (dirent) {
50367@@ -1050,13 +1067,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
50368 buf.previous = NULL;
50369 buf.count = count;
50370 buf.error = 0;
50371+ buf.file = f.file;
50372
50373 error = vfs_readdir(f.file, compat_filldir64, &buf);
50374 if (error >= 0)
50375 error = buf.error;
50376 lastdirent = buf.previous;
50377 if (lastdirent) {
50378- typeof(lastdirent->d_off) d_off = f.file->f_pos;
50379+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50380 if (__put_user_unaligned(d_off, &lastdirent->d_off))
50381 error = -EFAULT;
50382 else
50383diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
50384index a81147e..20bf2b5 100644
50385--- a/fs/compat_binfmt_elf.c
50386+++ b/fs/compat_binfmt_elf.c
50387@@ -30,11 +30,13 @@
50388 #undef elf_phdr
50389 #undef elf_shdr
50390 #undef elf_note
50391+#undef elf_dyn
50392 #undef elf_addr_t
50393 #define elfhdr elf32_hdr
50394 #define elf_phdr elf32_phdr
50395 #define elf_shdr elf32_shdr
50396 #define elf_note elf32_note
50397+#define elf_dyn Elf32_Dyn
50398 #define elf_addr_t Elf32_Addr
50399
50400 /*
50401diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
50402index 996cdc5..15e2f33 100644
50403--- a/fs/compat_ioctl.c
50404+++ b/fs/compat_ioctl.c
50405@@ -622,7 +622,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
50406 return -EFAULT;
50407 if (__get_user(udata, &ss32->iomem_base))
50408 return -EFAULT;
50409- ss.iomem_base = compat_ptr(udata);
50410+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
50411 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
50412 __get_user(ss.port_high, &ss32->port_high))
50413 return -EFAULT;
50414@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
50415 for (i = 0; i < nmsgs; i++) {
50416 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
50417 return -EFAULT;
50418- if (get_user(datap, &umsgs[i].buf) ||
50419- put_user(compat_ptr(datap), &tmsgs[i].buf))
50420+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
50421+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
50422 return -EFAULT;
50423 }
50424 return sys_ioctl(fd, cmd, (unsigned long)tdata);
50425@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
50426 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
50427 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
50428 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
50429- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50430+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50431 return -EFAULT;
50432
50433 return ioctl_preallocate(file, p);
50434@@ -1619,8 +1619,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
50435 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
50436 {
50437 unsigned int a, b;
50438- a = *(unsigned int *)p;
50439- b = *(unsigned int *)q;
50440+ a = *(const unsigned int *)p;
50441+ b = *(const unsigned int *)q;
50442 if (a > b)
50443 return 1;
50444 if (a < b)
50445diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
50446index 7aabc6a..34c1197 100644
50447--- a/fs/configfs/dir.c
50448+++ b/fs/configfs/dir.c
50449@@ -1565,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50450 }
50451 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
50452 struct configfs_dirent *next;
50453- const char * name;
50454+ const unsigned char * name;
50455+ char d_name[sizeof(next->s_dentry->d_iname)];
50456 int len;
50457 struct inode *inode = NULL;
50458
50459@@ -1575,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50460 continue;
50461
50462 name = configfs_get_name(next);
50463- len = strlen(name);
50464+ if (next->s_dentry && name == next->s_dentry->d_iname) {
50465+ len = next->s_dentry->d_name.len;
50466+ memcpy(d_name, name, len);
50467+ name = d_name;
50468+ } else
50469+ len = strlen(name);
50470
50471 /*
50472 * We'll have a dentry and an inode for
50473diff --git a/fs/coredump.c b/fs/coredump.c
50474index dafafba..10b3b27 100644
50475--- a/fs/coredump.c
50476+++ b/fs/coredump.c
50477@@ -52,7 +52,7 @@ struct core_name {
50478 char *corename;
50479 int used, size;
50480 };
50481-static atomic_t call_count = ATOMIC_INIT(1);
50482+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
50483
50484 /* The maximal length of core_pattern is also specified in sysctl.c */
50485
50486@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
50487 {
50488 char *old_corename = cn->corename;
50489
50490- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
50491+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
50492 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
50493
50494 if (!cn->corename) {
50495@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
50496 int pid_in_pattern = 0;
50497 int err = 0;
50498
50499- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
50500+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
50501 cn->corename = kmalloc(cn->size, GFP_KERNEL);
50502 cn->used = 0;
50503
50504@@ -435,8 +435,8 @@ static void wait_for_dump_helpers(struct file *file)
50505 struct pipe_inode_info *pipe = file->private_data;
50506
50507 pipe_lock(pipe);
50508- pipe->readers++;
50509- pipe->writers--;
50510+ atomic_inc(&pipe->readers);
50511+ atomic_dec(&pipe->writers);
50512 wake_up_interruptible_sync(&pipe->wait);
50513 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50514 pipe_unlock(pipe);
50515@@ -445,11 +445,11 @@ static void wait_for_dump_helpers(struct file *file)
50516 * We actually want wait_event_freezable() but then we need
50517 * to clear TIF_SIGPENDING and improve dump_interrupted().
50518 */
50519- wait_event_interruptible(pipe->wait, pipe->readers == 1);
50520+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
50521
50522 pipe_lock(pipe);
50523- pipe->readers--;
50524- pipe->writers++;
50525+ atomic_dec(&pipe->readers);
50526+ atomic_inc(&pipe->writers);
50527 pipe_unlock(pipe);
50528 }
50529
50530@@ -496,7 +496,8 @@ void do_coredump(siginfo_t *siginfo)
50531 struct files_struct *displaced;
50532 bool need_nonrelative = false;
50533 bool core_dumped = false;
50534- static atomic_t core_dump_count = ATOMIC_INIT(0);
50535+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
50536+ long signr = siginfo->si_signo;
50537 struct coredump_params cprm = {
50538 .siginfo = siginfo,
50539 .regs = signal_pt_regs(),
50540@@ -509,7 +510,10 @@ void do_coredump(siginfo_t *siginfo)
50541 .mm_flags = mm->flags,
50542 };
50543
50544- audit_core_dumps(siginfo->si_signo);
50545+ audit_core_dumps(signr);
50546+
50547+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
50548+ gr_handle_brute_attach(cprm.mm_flags);
50549
50550 binfmt = mm->binfmt;
50551 if (!binfmt || !binfmt->core_dump)
50552@@ -533,7 +537,7 @@ void do_coredump(siginfo_t *siginfo)
50553 need_nonrelative = true;
50554 }
50555
50556- retval = coredump_wait(siginfo->si_signo, &core_state);
50557+ retval = coredump_wait(signr, &core_state);
50558 if (retval < 0)
50559 goto fail_creds;
50560
50561@@ -576,7 +580,7 @@ void do_coredump(siginfo_t *siginfo)
50562 }
50563 cprm.limit = RLIM_INFINITY;
50564
50565- dump_count = atomic_inc_return(&core_dump_count);
50566+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
50567 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
50568 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
50569 task_tgid_vnr(current), current->comm);
50570@@ -608,6 +612,8 @@ void do_coredump(siginfo_t *siginfo)
50571 } else {
50572 struct inode *inode;
50573
50574+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
50575+
50576 if (cprm.limit < binfmt->min_coredump)
50577 goto fail_unlock;
50578
50579@@ -666,7 +672,7 @@ close_fail:
50580 filp_close(cprm.file, NULL);
50581 fail_dropcount:
50582 if (ispipe)
50583- atomic_dec(&core_dump_count);
50584+ atomic_dec_unchecked(&core_dump_count);
50585 fail_unlock:
50586 kfree(cn.corename);
50587 fail_corename:
50588@@ -687,7 +693,7 @@ int dump_write(struct file *file, const void *addr, int nr)
50589 {
50590 return !dump_interrupted() &&
50591 access_ok(VERIFY_READ, addr, nr) &&
50592- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
50593+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
50594 }
50595 EXPORT_SYMBOL(dump_write);
50596
50597diff --git a/fs/dcache.c b/fs/dcache.c
50598index f09b908..4dd10d8 100644
50599--- a/fs/dcache.c
50600+++ b/fs/dcache.c
50601@@ -3086,7 +3086,7 @@ void __init vfs_caches_init(unsigned long mempages)
50602 mempages -= reserve;
50603
50604 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50605- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50606+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
50607
50608 dcache_init();
50609 inode_init();
50610diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50611index 4888cb3..e0f7cf8 100644
50612--- a/fs/debugfs/inode.c
50613+++ b/fs/debugfs/inode.c
50614@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50615 */
50616 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50617 {
50618+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50619+ return __create_file(name, S_IFDIR | S_IRWXU,
50620+#else
50621 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50622+#endif
50623 parent, NULL, NULL);
50624 }
50625 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50626diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50627index 5eab400..810a3f5 100644
50628--- a/fs/ecryptfs/inode.c
50629+++ b/fs/ecryptfs/inode.c
50630@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50631 old_fs = get_fs();
50632 set_fs(get_ds());
50633 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50634- (char __user *)lower_buf,
50635+ (char __force_user *)lower_buf,
50636 PATH_MAX);
50637 set_fs(old_fs);
50638 if (rc < 0)
50639@@ -706,7 +706,7 @@ out:
50640 static void
50641 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50642 {
50643- char *buf = nd_get_link(nd);
50644+ const char *buf = nd_get_link(nd);
50645 if (!IS_ERR(buf)) {
50646 /* Free the char* */
50647 kfree(buf);
50648diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50649index e4141f2..d8263e8 100644
50650--- a/fs/ecryptfs/miscdev.c
50651+++ b/fs/ecryptfs/miscdev.c
50652@@ -304,7 +304,7 @@ check_list:
50653 goto out_unlock_msg_ctx;
50654 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50655 if (msg_ctx->msg) {
50656- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50657+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50658 goto out_unlock_msg_ctx;
50659 i += packet_length_size;
50660 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50661diff --git a/fs/exec.c b/fs/exec.c
50662index ffd7a81..e38107f 100644
50663--- a/fs/exec.c
50664+++ b/fs/exec.c
50665@@ -55,8 +55,20 @@
50666 #include <linux/pipe_fs_i.h>
50667 #include <linux/oom.h>
50668 #include <linux/compat.h>
50669+#include <linux/random.h>
50670+#include <linux/seq_file.h>
50671+#include <linux/coredump.h>
50672+#include <linux/mman.h>
50673+
50674+#ifdef CONFIG_PAX_REFCOUNT
50675+#include <linux/kallsyms.h>
50676+#include <linux/kdebug.h>
50677+#endif
50678+
50679+#include <trace/events/fs.h>
50680
50681 #include <asm/uaccess.h>
50682+#include <asm/sections.h>
50683 #include <asm/mmu_context.h>
50684 #include <asm/tlb.h>
50685
50686@@ -66,17 +78,32 @@
50687
50688 #include <trace/events/sched.h>
50689
50690+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50691+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50692+{
50693+ 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");
50694+}
50695+#endif
50696+
50697+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50698+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50699+EXPORT_SYMBOL(pax_set_initial_flags_func);
50700+#endif
50701+
50702 int suid_dumpable = 0;
50703
50704 static LIST_HEAD(formats);
50705 static DEFINE_RWLOCK(binfmt_lock);
50706
50707+extern int gr_process_kernel_exec_ban(void);
50708+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
50709+
50710 void __register_binfmt(struct linux_binfmt * fmt, int insert)
50711 {
50712 BUG_ON(!fmt);
50713 write_lock(&binfmt_lock);
50714- insert ? list_add(&fmt->lh, &formats) :
50715- list_add_tail(&fmt->lh, &formats);
50716+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50717+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50718 write_unlock(&binfmt_lock);
50719 }
50720
50721@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
50722 void unregister_binfmt(struct linux_binfmt * fmt)
50723 {
50724 write_lock(&binfmt_lock);
50725- list_del(&fmt->lh);
50726+ pax_list_del((struct list_head *)&fmt->lh);
50727 write_unlock(&binfmt_lock);
50728 }
50729
50730@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50731 int write)
50732 {
50733 struct page *page;
50734- int ret;
50735
50736-#ifdef CONFIG_STACK_GROWSUP
50737- if (write) {
50738- ret = expand_downwards(bprm->vma, pos);
50739- if (ret < 0)
50740- return NULL;
50741- }
50742-#endif
50743- ret = get_user_pages(current, bprm->mm, pos,
50744- 1, write, 1, &page, NULL);
50745- if (ret <= 0)
50746+ if (0 > expand_downwards(bprm->vma, pos))
50747+ return NULL;
50748+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50749 return NULL;
50750
50751 if (write) {
50752@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50753 if (size <= ARG_MAX)
50754 return page;
50755
50756+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50757+ // only allow 512KB for argv+env on suid/sgid binaries
50758+ // to prevent easy ASLR exhaustion
50759+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50760+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50761+ (size > (512 * 1024))) {
50762+ put_page(page);
50763+ return NULL;
50764+ }
50765+#endif
50766+
50767 /*
50768 * Limit to 1/4-th the stack size for the argv+env strings.
50769 * This ensures that:
50770@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50771 vma->vm_end = STACK_TOP_MAX;
50772 vma->vm_start = vma->vm_end - PAGE_SIZE;
50773 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50774+
50775+#ifdef CONFIG_PAX_SEGMEXEC
50776+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50777+#endif
50778+
50779 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50780 INIT_LIST_HEAD(&vma->anon_vma_chain);
50781
50782@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50783 mm->stack_vm = mm->total_vm = 1;
50784 up_write(&mm->mmap_sem);
50785 bprm->p = vma->vm_end - sizeof(void *);
50786+
50787+#ifdef CONFIG_PAX_RANDUSTACK
50788+ if (randomize_va_space)
50789+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
50790+#endif
50791+
50792 return 0;
50793 err:
50794 up_write(&mm->mmap_sem);
50795@@ -396,7 +437,7 @@ struct user_arg_ptr {
50796 } ptr;
50797 };
50798
50799-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50800+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50801 {
50802 const char __user *native;
50803
50804@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50805 compat_uptr_t compat;
50806
50807 if (get_user(compat, argv.ptr.compat + nr))
50808- return ERR_PTR(-EFAULT);
50809+ return (const char __force_user *)ERR_PTR(-EFAULT);
50810
50811 return compat_ptr(compat);
50812 }
50813 #endif
50814
50815 if (get_user(native, argv.ptr.native + nr))
50816- return ERR_PTR(-EFAULT);
50817+ return (const char __force_user *)ERR_PTR(-EFAULT);
50818
50819 return native;
50820 }
50821@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
50822 if (!p)
50823 break;
50824
50825- if (IS_ERR(p))
50826+ if (IS_ERR((const char __force_kernel *)p))
50827 return -EFAULT;
50828
50829 if (i >= max)
50830@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50831
50832 ret = -EFAULT;
50833 str = get_user_arg_ptr(argv, argc);
50834- if (IS_ERR(str))
50835+ if (IS_ERR((const char __force_kernel *)str))
50836 goto out;
50837
50838 len = strnlen_user(str, MAX_ARG_STRLEN);
50839@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50840 int r;
50841 mm_segment_t oldfs = get_fs();
50842 struct user_arg_ptr argv = {
50843- .ptr.native = (const char __user *const __user *)__argv,
50844+ .ptr.native = (const char __force_user * const __force_user *)__argv,
50845 };
50846
50847 set_fs(KERNEL_DS);
50848@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50849 unsigned long new_end = old_end - shift;
50850 struct mmu_gather tlb;
50851
50852- BUG_ON(new_start > new_end);
50853+ if (new_start >= new_end || new_start < mmap_min_addr)
50854+ return -ENOMEM;
50855
50856 /*
50857 * ensure there are no vmas between where we want to go
50858@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50859 if (vma != find_vma(mm, new_start))
50860 return -EFAULT;
50861
50862+#ifdef CONFIG_PAX_SEGMEXEC
50863+ BUG_ON(pax_find_mirror_vma(vma));
50864+#endif
50865+
50866 /*
50867 * cover the whole range: [new_start, old_end)
50868 */
50869@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50870 stack_top = arch_align_stack(stack_top);
50871 stack_top = PAGE_ALIGN(stack_top);
50872
50873- if (unlikely(stack_top < mmap_min_addr) ||
50874- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50875- return -ENOMEM;
50876-
50877 stack_shift = vma->vm_end - stack_top;
50878
50879 bprm->p -= stack_shift;
50880@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50881 bprm->exec -= stack_shift;
50882
50883 down_write(&mm->mmap_sem);
50884+
50885+ /* Move stack pages down in memory. */
50886+ if (stack_shift) {
50887+ ret = shift_arg_pages(vma, stack_shift);
50888+ if (ret)
50889+ goto out_unlock;
50890+ }
50891+
50892 vm_flags = VM_STACK_FLAGS;
50893
50894+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50895+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
50896+ vm_flags &= ~VM_EXEC;
50897+
50898+#ifdef CONFIG_PAX_MPROTECT
50899+ if (mm->pax_flags & MF_PAX_MPROTECT)
50900+ vm_flags &= ~VM_MAYEXEC;
50901+#endif
50902+
50903+ }
50904+#endif
50905+
50906 /*
50907 * Adjust stack execute permissions; explicitly enable for
50908 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
50909@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50910 goto out_unlock;
50911 BUG_ON(prev != vma);
50912
50913- /* Move stack pages down in memory. */
50914- if (stack_shift) {
50915- ret = shift_arg_pages(vma, stack_shift);
50916- if (ret)
50917- goto out_unlock;
50918- }
50919-
50920 /* mprotect_fixup is overkill to remove the temporary stack flags */
50921 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
50922
50923@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
50924 #endif
50925 current->mm->start_stack = bprm->p;
50926 ret = expand_stack(vma, stack_base);
50927+
50928+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
50929+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
50930+ unsigned long size;
50931+ vm_flags_t vm_flags;
50932+
50933+ size = STACK_TOP - vma->vm_end;
50934+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
50935+
50936+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
50937+
50938+#ifdef CONFIG_X86
50939+ if (!ret) {
50940+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
50941+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
50942+ }
50943+#endif
50944+
50945+ }
50946+#endif
50947+
50948 if (ret)
50949 ret = -EFAULT;
50950
50951@@ -772,6 +848,8 @@ struct file *open_exec(const char *name)
50952
50953 fsnotify_open(file);
50954
50955+ trace_open_exec(name);
50956+
50957 err = deny_write_access(file);
50958 if (err)
50959 goto exit;
50960@@ -795,7 +873,7 @@ int kernel_read(struct file *file, loff_t offset,
50961 old_fs = get_fs();
50962 set_fs(get_ds());
50963 /* The cast to a user pointer is valid due to the set_fs() */
50964- result = vfs_read(file, (void __user *)addr, count, &pos);
50965+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
50966 set_fs(old_fs);
50967 return result;
50968 }
50969@@ -1251,7 +1329,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
50970 }
50971 rcu_read_unlock();
50972
50973- if (p->fs->users > n_fs) {
50974+ if (atomic_read(&p->fs->users) > n_fs) {
50975 bprm->unsafe |= LSM_UNSAFE_SHARE;
50976 } else {
50977 res = -EAGAIN;
50978@@ -1451,6 +1529,31 @@ int search_binary_handler(struct linux_binprm *bprm)
50979
50980 EXPORT_SYMBOL(search_binary_handler);
50981
50982+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50983+static DEFINE_PER_CPU(u64, exec_counter);
50984+static int __init init_exec_counters(void)
50985+{
50986+ unsigned int cpu;
50987+
50988+ for_each_possible_cpu(cpu) {
50989+ per_cpu(exec_counter, cpu) = (u64)cpu;
50990+ }
50991+
50992+ return 0;
50993+}
50994+early_initcall(init_exec_counters);
50995+static inline void increment_exec_counter(void)
50996+{
50997+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
50998+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
50999+}
51000+#else
51001+static inline void increment_exec_counter(void) {}
51002+#endif
51003+
51004+extern void gr_handle_exec_args(struct linux_binprm *bprm,
51005+ struct user_arg_ptr argv);
51006+
51007 /*
51008 * sys_execve() executes a new program.
51009 */
51010@@ -1458,6 +1561,11 @@ static int do_execve_common(const char *filename,
51011 struct user_arg_ptr argv,
51012 struct user_arg_ptr envp)
51013 {
51014+#ifdef CONFIG_GRKERNSEC
51015+ struct file *old_exec_file;
51016+ struct acl_subject_label *old_acl;
51017+ struct rlimit old_rlim[RLIM_NLIMITS];
51018+#endif
51019 struct linux_binprm *bprm;
51020 struct file *file;
51021 struct files_struct *displaced;
51022@@ -1465,6 +1573,8 @@ static int do_execve_common(const char *filename,
51023 int retval;
51024 const struct cred *cred = current_cred();
51025
51026+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&cred->user->processes), 1);
51027+
51028 /*
51029 * We move the actual failure in case of RLIMIT_NPROC excess from
51030 * set*uid() to execve() because too many poorly written programs
51031@@ -1505,12 +1615,22 @@ static int do_execve_common(const char *filename,
51032 if (IS_ERR(file))
51033 goto out_unmark;
51034
51035+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
51036+ retval = -EPERM;
51037+ goto out_file;
51038+ }
51039+
51040 sched_exec();
51041
51042 bprm->file = file;
51043 bprm->filename = filename;
51044 bprm->interp = filename;
51045
51046+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
51047+ retval = -EACCES;
51048+ goto out_file;
51049+ }
51050+
51051 retval = bprm_mm_init(bprm);
51052 if (retval)
51053 goto out_file;
51054@@ -1527,24 +1647,70 @@ static int do_execve_common(const char *filename,
51055 if (retval < 0)
51056 goto out;
51057
51058+#ifdef CONFIG_GRKERNSEC
51059+ old_acl = current->acl;
51060+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
51061+ old_exec_file = current->exec_file;
51062+ get_file(file);
51063+ current->exec_file = file;
51064+#endif
51065+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51066+ /* limit suid stack to 8MB
51067+ * we saved the old limits above and will restore them if this exec fails
51068+ */
51069+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
51070+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
51071+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
51072+#endif
51073+
51074+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
51075+ retval = -EPERM;
51076+ goto out_fail;
51077+ }
51078+
51079+ if (!gr_tpe_allow(file)) {
51080+ retval = -EACCES;
51081+ goto out_fail;
51082+ }
51083+
51084+ if (gr_check_crash_exec(file)) {
51085+ retval = -EACCES;
51086+ goto out_fail;
51087+ }
51088+
51089+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
51090+ bprm->unsafe);
51091+ if (retval < 0)
51092+ goto out_fail;
51093+
51094 retval = copy_strings_kernel(1, &bprm->filename, bprm);
51095 if (retval < 0)
51096- goto out;
51097+ goto out_fail;
51098
51099 bprm->exec = bprm->p;
51100 retval = copy_strings(bprm->envc, envp, bprm);
51101 if (retval < 0)
51102- goto out;
51103+ goto out_fail;
51104
51105 retval = copy_strings(bprm->argc, argv, bprm);
51106 if (retval < 0)
51107- goto out;
51108+ goto out_fail;
51109+
51110+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
51111+
51112+ gr_handle_exec_args(bprm, argv);
51113
51114 retval = search_binary_handler(bprm);
51115 if (retval < 0)
51116- goto out;
51117+ goto out_fail;
51118+#ifdef CONFIG_GRKERNSEC
51119+ if (old_exec_file)
51120+ fput(old_exec_file);
51121+#endif
51122
51123 /* execve succeeded */
51124+
51125+ increment_exec_counter();
51126 current->fs->in_exec = 0;
51127 current->in_execve = 0;
51128 acct_update_integrals(current);
51129@@ -1553,6 +1719,14 @@ static int do_execve_common(const char *filename,
51130 put_files_struct(displaced);
51131 return retval;
51132
51133+out_fail:
51134+#ifdef CONFIG_GRKERNSEC
51135+ current->acl = old_acl;
51136+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
51137+ fput(current->exec_file);
51138+ current->exec_file = old_exec_file;
51139+#endif
51140+
51141 out:
51142 if (bprm->mm) {
51143 acct_arg_size(bprm, 0);
51144@@ -1701,3 +1875,283 @@ asmlinkage long compat_sys_execve(const char __user * filename,
51145 return error;
51146 }
51147 #endif
51148+
51149+int pax_check_flags(unsigned long *flags)
51150+{
51151+ int retval = 0;
51152+
51153+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
51154+ if (*flags & MF_PAX_SEGMEXEC)
51155+ {
51156+ *flags &= ~MF_PAX_SEGMEXEC;
51157+ retval = -EINVAL;
51158+ }
51159+#endif
51160+
51161+ if ((*flags & MF_PAX_PAGEEXEC)
51162+
51163+#ifdef CONFIG_PAX_PAGEEXEC
51164+ && (*flags & MF_PAX_SEGMEXEC)
51165+#endif
51166+
51167+ )
51168+ {
51169+ *flags &= ~MF_PAX_PAGEEXEC;
51170+ retval = -EINVAL;
51171+ }
51172+
51173+ if ((*flags & MF_PAX_MPROTECT)
51174+
51175+#ifdef CONFIG_PAX_MPROTECT
51176+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51177+#endif
51178+
51179+ )
51180+ {
51181+ *flags &= ~MF_PAX_MPROTECT;
51182+ retval = -EINVAL;
51183+ }
51184+
51185+ if ((*flags & MF_PAX_EMUTRAMP)
51186+
51187+#ifdef CONFIG_PAX_EMUTRAMP
51188+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51189+#endif
51190+
51191+ )
51192+ {
51193+ *flags &= ~MF_PAX_EMUTRAMP;
51194+ retval = -EINVAL;
51195+ }
51196+
51197+ return retval;
51198+}
51199+
51200+EXPORT_SYMBOL(pax_check_flags);
51201+
51202+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51203+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
51204+{
51205+ struct task_struct *tsk = current;
51206+ struct mm_struct *mm = current->mm;
51207+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
51208+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
51209+ char *path_exec = NULL;
51210+ char *path_fault = NULL;
51211+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
51212+ siginfo_t info = { };
51213+
51214+ if (buffer_exec && buffer_fault) {
51215+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
51216+
51217+ down_read(&mm->mmap_sem);
51218+ vma = mm->mmap;
51219+ while (vma && (!vma_exec || !vma_fault)) {
51220+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
51221+ vma_exec = vma;
51222+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
51223+ vma_fault = vma;
51224+ vma = vma->vm_next;
51225+ }
51226+ if (vma_exec) {
51227+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
51228+ if (IS_ERR(path_exec))
51229+ path_exec = "<path too long>";
51230+ else {
51231+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
51232+ if (path_exec) {
51233+ *path_exec = 0;
51234+ path_exec = buffer_exec;
51235+ } else
51236+ path_exec = "<path too long>";
51237+ }
51238+ }
51239+ if (vma_fault) {
51240+ start = vma_fault->vm_start;
51241+ end = vma_fault->vm_end;
51242+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
51243+ if (vma_fault->vm_file) {
51244+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
51245+ if (IS_ERR(path_fault))
51246+ path_fault = "<path too long>";
51247+ else {
51248+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
51249+ if (path_fault) {
51250+ *path_fault = 0;
51251+ path_fault = buffer_fault;
51252+ } else
51253+ path_fault = "<path too long>";
51254+ }
51255+ } else
51256+ path_fault = "<anonymous mapping>";
51257+ }
51258+ up_read(&mm->mmap_sem);
51259+ }
51260+ if (tsk->signal->curr_ip)
51261+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
51262+ else
51263+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
51264+ 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),
51265+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
51266+ free_page((unsigned long)buffer_exec);
51267+ free_page((unsigned long)buffer_fault);
51268+ pax_report_insns(regs, pc, sp);
51269+ info.si_signo = SIGKILL;
51270+ info.si_errno = 0;
51271+ info.si_code = SI_KERNEL;
51272+ info.si_pid = 0;
51273+ info.si_uid = 0;
51274+ do_coredump(&info);
51275+}
51276+#endif
51277+
51278+#ifdef CONFIG_PAX_REFCOUNT
51279+void pax_report_refcount_overflow(struct pt_regs *regs)
51280+{
51281+ if (current->signal->curr_ip)
51282+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
51283+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
51284+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51285+ else
51286+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
51287+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51288+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
51289+ show_regs(regs);
51290+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
51291+}
51292+#endif
51293+
51294+#ifdef CONFIG_PAX_USERCOPY
51295+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
51296+static noinline int check_stack_object(const void *obj, unsigned long len)
51297+{
51298+ const void * const stack = task_stack_page(current);
51299+ const void * const stackend = stack + THREAD_SIZE;
51300+
51301+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51302+ const void *frame = NULL;
51303+ const void *oldframe;
51304+#endif
51305+
51306+ if (obj + len < obj)
51307+ return -1;
51308+
51309+ if (obj + len <= stack || stackend <= obj)
51310+ return 0;
51311+
51312+ if (obj < stack || stackend < obj + len)
51313+ return -1;
51314+
51315+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51316+ oldframe = __builtin_frame_address(1);
51317+ if (oldframe)
51318+ frame = __builtin_frame_address(2);
51319+ /*
51320+ low ----------------------------------------------> high
51321+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
51322+ ^----------------^
51323+ allow copies only within here
51324+ */
51325+ while (stack <= frame && frame < stackend) {
51326+ /* if obj + len extends past the last frame, this
51327+ check won't pass and the next frame will be 0,
51328+ causing us to bail out and correctly report
51329+ the copy as invalid
51330+ */
51331+ if (obj + len <= frame)
51332+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
51333+ oldframe = frame;
51334+ frame = *(const void * const *)frame;
51335+ }
51336+ return -1;
51337+#else
51338+ return 1;
51339+#endif
51340+}
51341+
51342+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
51343+{
51344+ if (current->signal->curr_ip)
51345+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51346+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51347+ else
51348+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51349+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51350+ dump_stack();
51351+ gr_handle_kernel_exploit();
51352+ do_group_exit(SIGKILL);
51353+}
51354+#endif
51355+
51356+#ifdef CONFIG_PAX_USERCOPY
51357+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
51358+{
51359+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
51360+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
51361+#ifdef CONFIG_MODULES
51362+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
51363+#else
51364+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
51365+#endif
51366+
51367+#else
51368+ unsigned long textlow = (unsigned long)_stext;
51369+ unsigned long texthigh = (unsigned long)_etext;
51370+#endif
51371+
51372+ if (high <= textlow || low > texthigh)
51373+ return false;
51374+ else
51375+ return true;
51376+}
51377+#endif
51378+
51379+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
51380+{
51381+
51382+#ifdef CONFIG_PAX_USERCOPY
51383+ const char *type;
51384+
51385+ if (!n)
51386+ return;
51387+
51388+ type = check_heap_object(ptr, n);
51389+ if (!type) {
51390+ int ret = check_stack_object(ptr, n);
51391+ if (ret == 1 || ret == 2)
51392+ return;
51393+ if (ret == 0) {
51394+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
51395+ type = "<kernel text>";
51396+ else
51397+ return;
51398+ } else
51399+ type = "<process stack>";
51400+ }
51401+
51402+ pax_report_usercopy(ptr, n, to_user, type);
51403+#endif
51404+
51405+}
51406+EXPORT_SYMBOL(__check_object_size);
51407+
51408+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
51409+void pax_track_stack(void)
51410+{
51411+ unsigned long sp = (unsigned long)&sp;
51412+ if (sp < current_thread_info()->lowest_stack &&
51413+ sp > (unsigned long)task_stack_page(current))
51414+ current_thread_info()->lowest_stack = sp;
51415+}
51416+EXPORT_SYMBOL(pax_track_stack);
51417+#endif
51418+
51419+#ifdef CONFIG_PAX_SIZE_OVERFLOW
51420+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
51421+{
51422+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
51423+ dump_stack();
51424+ do_group_exit(SIGKILL);
51425+}
51426+EXPORT_SYMBOL(report_size_overflow);
51427+#endif
51428diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
51429index 9f9992b..8b59411 100644
51430--- a/fs/ext2/balloc.c
51431+++ b/fs/ext2/balloc.c
51432@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
51433
51434 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51435 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51436- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51437+ if (free_blocks < root_blocks + 1 &&
51438 !uid_eq(sbi->s_resuid, current_fsuid()) &&
51439 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51440- !in_group_p (sbi->s_resgid))) {
51441+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51442 return 0;
51443 }
51444 return 1;
51445diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
51446index 22548f5..41521d8 100644
51447--- a/fs/ext3/balloc.c
51448+++ b/fs/ext3/balloc.c
51449@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
51450
51451 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51452 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51453- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51454+ if (free_blocks < root_blocks + 1 &&
51455 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
51456 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51457- !in_group_p (sbi->s_resgid))) {
51458+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51459 return 0;
51460 }
51461 return 1;
51462diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
51463index d0f13ea..4b2dadd 100644
51464--- a/fs/ext4/balloc.c
51465+++ b/fs/ext4/balloc.c
51466@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
51467 /* Hm, nope. Are (enough) root reserved clusters available? */
51468 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
51469 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
51470- capable(CAP_SYS_RESOURCE) ||
51471- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
51472+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
51473+ capable_nolog(CAP_SYS_RESOURCE)) {
51474
51475 if (free_clusters >= (nclusters + dirty_clusters +
51476 resv_clusters))
51477diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
51478index 5aae3d1..b5da7f8 100644
51479--- a/fs/ext4/ext4.h
51480+++ b/fs/ext4/ext4.h
51481@@ -1252,19 +1252,19 @@ struct ext4_sb_info {
51482 unsigned long s_mb_last_start;
51483
51484 /* stats for buddy allocator */
51485- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
51486- atomic_t s_bal_success; /* we found long enough chunks */
51487- atomic_t s_bal_allocated; /* in blocks */
51488- atomic_t s_bal_ex_scanned; /* total extents scanned */
51489- atomic_t s_bal_goals; /* goal hits */
51490- atomic_t s_bal_breaks; /* too long searches */
51491- atomic_t s_bal_2orders; /* 2^order hits */
51492+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
51493+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
51494+ atomic_unchecked_t s_bal_allocated; /* in blocks */
51495+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
51496+ atomic_unchecked_t s_bal_goals; /* goal hits */
51497+ atomic_unchecked_t s_bal_breaks; /* too long searches */
51498+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
51499 spinlock_t s_bal_lock;
51500 unsigned long s_mb_buddies_generated;
51501 unsigned long long s_mb_generation_time;
51502- atomic_t s_mb_lost_chunks;
51503- atomic_t s_mb_preallocated;
51504- atomic_t s_mb_discarded;
51505+ atomic_unchecked_t s_mb_lost_chunks;
51506+ atomic_unchecked_t s_mb_preallocated;
51507+ atomic_unchecked_t s_mb_discarded;
51508 atomic_t s_lock_busy;
51509
51510 /* locality groups */
51511diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
51512index def8408..8253d11 100644
51513--- a/fs/ext4/mballoc.c
51514+++ b/fs/ext4/mballoc.c
51515@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
51516 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
51517
51518 if (EXT4_SB(sb)->s_mb_stats)
51519- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
51520+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
51521
51522 break;
51523 }
51524@@ -2170,7 +2170,7 @@ repeat:
51525 ac->ac_status = AC_STATUS_CONTINUE;
51526 ac->ac_flags |= EXT4_MB_HINT_FIRST;
51527 cr = 3;
51528- atomic_inc(&sbi->s_mb_lost_chunks);
51529+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
51530 goto repeat;
51531 }
51532 }
51533@@ -2678,25 +2678,25 @@ int ext4_mb_release(struct super_block *sb)
51534 if (sbi->s_mb_stats) {
51535 ext4_msg(sb, KERN_INFO,
51536 "mballoc: %u blocks %u reqs (%u success)",
51537- atomic_read(&sbi->s_bal_allocated),
51538- atomic_read(&sbi->s_bal_reqs),
51539- atomic_read(&sbi->s_bal_success));
51540+ atomic_read_unchecked(&sbi->s_bal_allocated),
51541+ atomic_read_unchecked(&sbi->s_bal_reqs),
51542+ atomic_read_unchecked(&sbi->s_bal_success));
51543 ext4_msg(sb, KERN_INFO,
51544 "mballoc: %u extents scanned, %u goal hits, "
51545 "%u 2^N hits, %u breaks, %u lost",
51546- atomic_read(&sbi->s_bal_ex_scanned),
51547- atomic_read(&sbi->s_bal_goals),
51548- atomic_read(&sbi->s_bal_2orders),
51549- atomic_read(&sbi->s_bal_breaks),
51550- atomic_read(&sbi->s_mb_lost_chunks));
51551+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
51552+ atomic_read_unchecked(&sbi->s_bal_goals),
51553+ atomic_read_unchecked(&sbi->s_bal_2orders),
51554+ atomic_read_unchecked(&sbi->s_bal_breaks),
51555+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
51556 ext4_msg(sb, KERN_INFO,
51557 "mballoc: %lu generated and it took %Lu",
51558 sbi->s_mb_buddies_generated,
51559 sbi->s_mb_generation_time);
51560 ext4_msg(sb, KERN_INFO,
51561 "mballoc: %u preallocated, %u discarded",
51562- atomic_read(&sbi->s_mb_preallocated),
51563- atomic_read(&sbi->s_mb_discarded));
51564+ atomic_read_unchecked(&sbi->s_mb_preallocated),
51565+ atomic_read_unchecked(&sbi->s_mb_discarded));
51566 }
51567
51568 free_percpu(sbi->s_locality_groups);
51569@@ -3150,16 +3150,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
51570 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
51571
51572 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
51573- atomic_inc(&sbi->s_bal_reqs);
51574- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51575+ atomic_inc_unchecked(&sbi->s_bal_reqs);
51576+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51577 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
51578- atomic_inc(&sbi->s_bal_success);
51579- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
51580+ atomic_inc_unchecked(&sbi->s_bal_success);
51581+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
51582 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
51583 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
51584- atomic_inc(&sbi->s_bal_goals);
51585+ atomic_inc_unchecked(&sbi->s_bal_goals);
51586 if (ac->ac_found > sbi->s_mb_max_to_scan)
51587- atomic_inc(&sbi->s_bal_breaks);
51588+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51589 }
51590
51591 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51592@@ -3559,7 +3559,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51593 trace_ext4_mb_new_inode_pa(ac, pa);
51594
51595 ext4_mb_use_inode_pa(ac, pa);
51596- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51597+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51598
51599 ei = EXT4_I(ac->ac_inode);
51600 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51601@@ -3619,7 +3619,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51602 trace_ext4_mb_new_group_pa(ac, pa);
51603
51604 ext4_mb_use_group_pa(ac, pa);
51605- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51606+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51607
51608 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51609 lg = ac->ac_lg;
51610@@ -3708,7 +3708,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51611 * from the bitmap and continue.
51612 */
51613 }
51614- atomic_add(free, &sbi->s_mb_discarded);
51615+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51616
51617 return err;
51618 }
51619@@ -3726,7 +3726,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51620 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51621 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51622 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51623- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51624+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51625 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51626
51627 return 0;
51628diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
51629index 214461e..3614c89 100644
51630--- a/fs/ext4/mmp.c
51631+++ b/fs/ext4/mmp.c
51632@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
51633 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
51634 const char *function, unsigned int line, const char *msg)
51635 {
51636- __ext4_warning(sb, function, line, msg);
51637+ __ext4_warning(sb, function, line, "%s", msg);
51638 __ext4_warning(sb, function, line,
51639 "MMP failure info: last update time: %llu, last update "
51640 "node: %s, last update device: %s\n",
51641diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
51642index b27c96d..6ed4df2 100644
51643--- a/fs/ext4/resize.c
51644+++ b/fs/ext4/resize.c
51645@@ -79,12 +79,20 @@ static int verify_group_input(struct super_block *sb,
51646 ext4_fsblk_t end = start + input->blocks_count;
51647 ext4_group_t group = input->group;
51648 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
51649- unsigned overhead = ext4_group_overhead_blocks(sb, group);
51650- ext4_fsblk_t metaend = start + overhead;
51651+ unsigned overhead;
51652+ ext4_fsblk_t metaend;
51653 struct buffer_head *bh = NULL;
51654 ext4_grpblk_t free_blocks_count, offset;
51655 int err = -EINVAL;
51656
51657+ if (group != sbi->s_groups_count) {
51658+ ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51659+ input->group, sbi->s_groups_count);
51660+ return -EINVAL;
51661+ }
51662+
51663+ overhead = ext4_group_overhead_blocks(sb, group);
51664+ metaend = start + overhead;
51665 input->free_blocks_count = free_blocks_count =
51666 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
51667
51668@@ -96,10 +104,7 @@ static int verify_group_input(struct super_block *sb,
51669 free_blocks_count, input->reserved_blocks);
51670
51671 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
51672- if (group != sbi->s_groups_count)
51673- ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51674- input->group, sbi->s_groups_count);
51675- else if (offset != 0)
51676+ if (offset != 0)
51677 ext4_warning(sb, "Last group not full");
51678 else if (input->reserved_blocks > input->blocks_count / 5)
51679 ext4_warning(sb, "Reserved blocks too high (%u)",
51680diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51681index 94cc84d..2490974 100644
51682--- a/fs/ext4/super.c
51683+++ b/fs/ext4/super.c
51684@@ -1236,7 +1236,7 @@ static ext4_fsblk_t get_sb_block(void **data)
51685 }
51686
51687 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
51688-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
51689+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
51690 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
51691
51692 #ifdef CONFIG_QUOTA
51693@@ -2378,7 +2378,7 @@ struct ext4_attr {
51694 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51695 const char *, size_t);
51696 int offset;
51697-};
51698+} __do_const;
51699
51700 static int parse_strtoull(const char *buf,
51701 unsigned long long max, unsigned long long *value)
51702diff --git a/fs/fcntl.c b/fs/fcntl.c
51703index 6599222..e7bf0de 100644
51704--- a/fs/fcntl.c
51705+++ b/fs/fcntl.c
51706@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51707 if (err)
51708 return err;
51709
51710+ if (gr_handle_chroot_fowner(pid, type))
51711+ return -ENOENT;
51712+ if (gr_check_protected_task_fowner(pid, type))
51713+ return -EACCES;
51714+
51715 f_modown(filp, pid, type, force);
51716 return 0;
51717 }
51718diff --git a/fs/fhandle.c b/fs/fhandle.c
51719index 999ff5c..41f4109 100644
51720--- a/fs/fhandle.c
51721+++ b/fs/fhandle.c
51722@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51723 } else
51724 retval = 0;
51725 /* copy the mount id */
51726- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51727- sizeof(*mnt_id)) ||
51728+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51729 copy_to_user(ufh, handle,
51730 sizeof(struct file_handle) + handle_bytes))
51731 retval = -EFAULT;
51732diff --git a/fs/file.c b/fs/file.c
51733index 4a78f98..9447397 100644
51734--- a/fs/file.c
51735+++ b/fs/file.c
51736@@ -16,6 +16,7 @@
51737 #include <linux/slab.h>
51738 #include <linux/vmalloc.h>
51739 #include <linux/file.h>
51740+#include <linux/security.h>
51741 #include <linux/fdtable.h>
51742 #include <linux/bitops.h>
51743 #include <linux/interrupt.h>
51744@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51745 if (!file)
51746 return __close_fd(files, fd);
51747
51748+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51749 if (fd >= rlimit(RLIMIT_NOFILE))
51750 return -EBADF;
51751
51752@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51753 if (unlikely(oldfd == newfd))
51754 return -EINVAL;
51755
51756+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51757 if (newfd >= rlimit(RLIMIT_NOFILE))
51758 return -EBADF;
51759
51760@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51761 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51762 {
51763 int err;
51764+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51765 if (from >= rlimit(RLIMIT_NOFILE))
51766 return -EINVAL;
51767 err = alloc_fd(from, flags);
51768diff --git a/fs/filesystems.c b/fs/filesystems.c
51769index 92567d9..fcd8cbf 100644
51770--- a/fs/filesystems.c
51771+++ b/fs/filesystems.c
51772@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
51773 int len = dot ? dot - name : strlen(name);
51774
51775 fs = __get_fs_type(name, len);
51776+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51777+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
51778+#else
51779 if (!fs && (request_module("fs-%.*s", len, name) == 0))
51780+#endif
51781 fs = __get_fs_type(name, len);
51782
51783 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51784diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51785index d8ac61d..79a36f0 100644
51786--- a/fs/fs_struct.c
51787+++ b/fs/fs_struct.c
51788@@ -4,6 +4,7 @@
51789 #include <linux/path.h>
51790 #include <linux/slab.h>
51791 #include <linux/fs_struct.h>
51792+#include <linux/grsecurity.h>
51793 #include "internal.h"
51794
51795 /*
51796@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
51797 write_seqcount_begin(&fs->seq);
51798 old_root = fs->root;
51799 fs->root = *path;
51800+ gr_set_chroot_entries(current, path);
51801 write_seqcount_end(&fs->seq);
51802 spin_unlock(&fs->lock);
51803 if (old_root.dentry)
51804@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
51805 int hits = 0;
51806 spin_lock(&fs->lock);
51807 write_seqcount_begin(&fs->seq);
51808+ /* this root replacement is only done by pivot_root,
51809+ leave grsec's chroot tagging alone for this task
51810+ so that a pivoted root isn't treated as a chroot
51811+ */
51812 hits += replace_path(&fs->root, old_root, new_root);
51813 hits += replace_path(&fs->pwd, old_root, new_root);
51814 write_seqcount_end(&fs->seq);
51815@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
51816 task_lock(tsk);
51817 spin_lock(&fs->lock);
51818 tsk->fs = NULL;
51819- kill = !--fs->users;
51820+ gr_clear_chroot_entries(tsk);
51821+ kill = !atomic_dec_return(&fs->users);
51822 spin_unlock(&fs->lock);
51823 task_unlock(tsk);
51824 if (kill)
51825@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51826 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51827 /* We don't need to lock fs - think why ;-) */
51828 if (fs) {
51829- fs->users = 1;
51830+ atomic_set(&fs->users, 1);
51831 fs->in_exec = 0;
51832 spin_lock_init(&fs->lock);
51833 seqcount_init(&fs->seq);
51834@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51835 spin_lock(&old->lock);
51836 fs->root = old->root;
51837 path_get(&fs->root);
51838+ /* instead of calling gr_set_chroot_entries here,
51839+ we call it from every caller of this function
51840+ */
51841 fs->pwd = old->pwd;
51842 path_get(&fs->pwd);
51843 spin_unlock(&old->lock);
51844@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
51845
51846 task_lock(current);
51847 spin_lock(&fs->lock);
51848- kill = !--fs->users;
51849+ kill = !atomic_dec_return(&fs->users);
51850 current->fs = new_fs;
51851+ gr_set_chroot_entries(current, &new_fs->root);
51852 spin_unlock(&fs->lock);
51853 task_unlock(current);
51854
51855@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
51856
51857 int current_umask(void)
51858 {
51859- return current->fs->umask;
51860+ return current->fs->umask | gr_acl_umask();
51861 }
51862 EXPORT_SYMBOL(current_umask);
51863
51864 /* to be mentioned only in INIT_TASK */
51865 struct fs_struct init_fs = {
51866- .users = 1,
51867+ .users = ATOMIC_INIT(1),
51868 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
51869 .seq = SEQCNT_ZERO,
51870 .umask = 0022,
51871diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
51872index e2cba1f..17a25bb 100644
51873--- a/fs/fscache/cookie.c
51874+++ b/fs/fscache/cookie.c
51875@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
51876 parent ? (char *) parent->def->name : "<no-parent>",
51877 def->name, netfs_data);
51878
51879- fscache_stat(&fscache_n_acquires);
51880+ fscache_stat_unchecked(&fscache_n_acquires);
51881
51882 /* if there's no parent cookie, then we don't create one here either */
51883 if (!parent) {
51884- fscache_stat(&fscache_n_acquires_null);
51885+ fscache_stat_unchecked(&fscache_n_acquires_null);
51886 _leave(" [no parent]");
51887 return NULL;
51888 }
51889@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
51890 /* allocate and initialise a cookie */
51891 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
51892 if (!cookie) {
51893- fscache_stat(&fscache_n_acquires_oom);
51894+ fscache_stat_unchecked(&fscache_n_acquires_oom);
51895 _leave(" [ENOMEM]");
51896 return NULL;
51897 }
51898@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51899
51900 switch (cookie->def->type) {
51901 case FSCACHE_COOKIE_TYPE_INDEX:
51902- fscache_stat(&fscache_n_cookie_index);
51903+ fscache_stat_unchecked(&fscache_n_cookie_index);
51904 break;
51905 case FSCACHE_COOKIE_TYPE_DATAFILE:
51906- fscache_stat(&fscache_n_cookie_data);
51907+ fscache_stat_unchecked(&fscache_n_cookie_data);
51908 break;
51909 default:
51910- fscache_stat(&fscache_n_cookie_special);
51911+ fscache_stat_unchecked(&fscache_n_cookie_special);
51912 break;
51913 }
51914
51915@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51916 if (fscache_acquire_non_index_cookie(cookie) < 0) {
51917 atomic_dec(&parent->n_children);
51918 __fscache_cookie_put(cookie);
51919- fscache_stat(&fscache_n_acquires_nobufs);
51920+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
51921 _leave(" = NULL");
51922 return NULL;
51923 }
51924 }
51925
51926- fscache_stat(&fscache_n_acquires_ok);
51927+ fscache_stat_unchecked(&fscache_n_acquires_ok);
51928 _leave(" = %p", cookie);
51929 return cookie;
51930 }
51931@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
51932 cache = fscache_select_cache_for_object(cookie->parent);
51933 if (!cache) {
51934 up_read(&fscache_addremove_sem);
51935- fscache_stat(&fscache_n_acquires_no_cache);
51936+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
51937 _leave(" = -ENOMEDIUM [no cache]");
51938 return -ENOMEDIUM;
51939 }
51940@@ -255,12 +255,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
51941 object = cache->ops->alloc_object(cache, cookie);
51942 fscache_stat_d(&fscache_n_cop_alloc_object);
51943 if (IS_ERR(object)) {
51944- fscache_stat(&fscache_n_object_no_alloc);
51945+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
51946 ret = PTR_ERR(object);
51947 goto error;
51948 }
51949
51950- fscache_stat(&fscache_n_object_alloc);
51951+ fscache_stat_unchecked(&fscache_n_object_alloc);
51952
51953 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
51954
51955@@ -376,7 +376,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
51956
51957 _enter("{%s}", cookie->def->name);
51958
51959- fscache_stat(&fscache_n_invalidates);
51960+ fscache_stat_unchecked(&fscache_n_invalidates);
51961
51962 /* Only permit invalidation of data files. Invalidating an index will
51963 * require the caller to release all its attachments to the tree rooted
51964@@ -434,10 +434,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
51965 {
51966 struct fscache_object *object;
51967
51968- fscache_stat(&fscache_n_updates);
51969+ fscache_stat_unchecked(&fscache_n_updates);
51970
51971 if (!cookie) {
51972- fscache_stat(&fscache_n_updates_null);
51973+ fscache_stat_unchecked(&fscache_n_updates_null);
51974 _leave(" [no cookie]");
51975 return;
51976 }
51977@@ -471,12 +471,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51978 struct fscache_object *object;
51979 unsigned long event;
51980
51981- fscache_stat(&fscache_n_relinquishes);
51982+ fscache_stat_unchecked(&fscache_n_relinquishes);
51983 if (retire)
51984- fscache_stat(&fscache_n_relinquishes_retire);
51985+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
51986
51987 if (!cookie) {
51988- fscache_stat(&fscache_n_relinquishes_null);
51989+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
51990 _leave(" [no cookie]");
51991 return;
51992 }
51993@@ -492,7 +492,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51994
51995 /* wait for the cookie to finish being instantiated (or to fail) */
51996 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
51997- fscache_stat(&fscache_n_relinquishes_waitcrt);
51998+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
51999 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
52000 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
52001 }
52002diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
52003index ee38fef..0a326d4 100644
52004--- a/fs/fscache/internal.h
52005+++ b/fs/fscache/internal.h
52006@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
52007 * stats.c
52008 */
52009 #ifdef CONFIG_FSCACHE_STATS
52010-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52011-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52012+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52013+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52014
52015-extern atomic_t fscache_n_op_pend;
52016-extern atomic_t fscache_n_op_run;
52017-extern atomic_t fscache_n_op_enqueue;
52018-extern atomic_t fscache_n_op_deferred_release;
52019-extern atomic_t fscache_n_op_release;
52020-extern atomic_t fscache_n_op_gc;
52021-extern atomic_t fscache_n_op_cancelled;
52022-extern atomic_t fscache_n_op_rejected;
52023+extern atomic_unchecked_t fscache_n_op_pend;
52024+extern atomic_unchecked_t fscache_n_op_run;
52025+extern atomic_unchecked_t fscache_n_op_enqueue;
52026+extern atomic_unchecked_t fscache_n_op_deferred_release;
52027+extern atomic_unchecked_t fscache_n_op_release;
52028+extern atomic_unchecked_t fscache_n_op_gc;
52029+extern atomic_unchecked_t fscache_n_op_cancelled;
52030+extern atomic_unchecked_t fscache_n_op_rejected;
52031
52032-extern atomic_t fscache_n_attr_changed;
52033-extern atomic_t fscache_n_attr_changed_ok;
52034-extern atomic_t fscache_n_attr_changed_nobufs;
52035-extern atomic_t fscache_n_attr_changed_nomem;
52036-extern atomic_t fscache_n_attr_changed_calls;
52037+extern atomic_unchecked_t fscache_n_attr_changed;
52038+extern atomic_unchecked_t fscache_n_attr_changed_ok;
52039+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
52040+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
52041+extern atomic_unchecked_t fscache_n_attr_changed_calls;
52042
52043-extern atomic_t fscache_n_allocs;
52044-extern atomic_t fscache_n_allocs_ok;
52045-extern atomic_t fscache_n_allocs_wait;
52046-extern atomic_t fscache_n_allocs_nobufs;
52047-extern atomic_t fscache_n_allocs_intr;
52048-extern atomic_t fscache_n_allocs_object_dead;
52049-extern atomic_t fscache_n_alloc_ops;
52050-extern atomic_t fscache_n_alloc_op_waits;
52051+extern atomic_unchecked_t fscache_n_allocs;
52052+extern atomic_unchecked_t fscache_n_allocs_ok;
52053+extern atomic_unchecked_t fscache_n_allocs_wait;
52054+extern atomic_unchecked_t fscache_n_allocs_nobufs;
52055+extern atomic_unchecked_t fscache_n_allocs_intr;
52056+extern atomic_unchecked_t fscache_n_allocs_object_dead;
52057+extern atomic_unchecked_t fscache_n_alloc_ops;
52058+extern atomic_unchecked_t fscache_n_alloc_op_waits;
52059
52060-extern atomic_t fscache_n_retrievals;
52061-extern atomic_t fscache_n_retrievals_ok;
52062-extern atomic_t fscache_n_retrievals_wait;
52063-extern atomic_t fscache_n_retrievals_nodata;
52064-extern atomic_t fscache_n_retrievals_nobufs;
52065-extern atomic_t fscache_n_retrievals_intr;
52066-extern atomic_t fscache_n_retrievals_nomem;
52067-extern atomic_t fscache_n_retrievals_object_dead;
52068-extern atomic_t fscache_n_retrieval_ops;
52069-extern atomic_t fscache_n_retrieval_op_waits;
52070+extern atomic_unchecked_t fscache_n_retrievals;
52071+extern atomic_unchecked_t fscache_n_retrievals_ok;
52072+extern atomic_unchecked_t fscache_n_retrievals_wait;
52073+extern atomic_unchecked_t fscache_n_retrievals_nodata;
52074+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
52075+extern atomic_unchecked_t fscache_n_retrievals_intr;
52076+extern atomic_unchecked_t fscache_n_retrievals_nomem;
52077+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
52078+extern atomic_unchecked_t fscache_n_retrieval_ops;
52079+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
52080
52081-extern atomic_t fscache_n_stores;
52082-extern atomic_t fscache_n_stores_ok;
52083-extern atomic_t fscache_n_stores_again;
52084-extern atomic_t fscache_n_stores_nobufs;
52085-extern atomic_t fscache_n_stores_oom;
52086-extern atomic_t fscache_n_store_ops;
52087-extern atomic_t fscache_n_store_calls;
52088-extern atomic_t fscache_n_store_pages;
52089-extern atomic_t fscache_n_store_radix_deletes;
52090-extern atomic_t fscache_n_store_pages_over_limit;
52091+extern atomic_unchecked_t fscache_n_stores;
52092+extern atomic_unchecked_t fscache_n_stores_ok;
52093+extern atomic_unchecked_t fscache_n_stores_again;
52094+extern atomic_unchecked_t fscache_n_stores_nobufs;
52095+extern atomic_unchecked_t fscache_n_stores_oom;
52096+extern atomic_unchecked_t fscache_n_store_ops;
52097+extern atomic_unchecked_t fscache_n_store_calls;
52098+extern atomic_unchecked_t fscache_n_store_pages;
52099+extern atomic_unchecked_t fscache_n_store_radix_deletes;
52100+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
52101
52102-extern atomic_t fscache_n_store_vmscan_not_storing;
52103-extern atomic_t fscache_n_store_vmscan_gone;
52104-extern atomic_t fscache_n_store_vmscan_busy;
52105-extern atomic_t fscache_n_store_vmscan_cancelled;
52106-extern atomic_t fscache_n_store_vmscan_wait;
52107+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52108+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
52109+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
52110+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52111+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
52112
52113-extern atomic_t fscache_n_marks;
52114-extern atomic_t fscache_n_uncaches;
52115+extern atomic_unchecked_t fscache_n_marks;
52116+extern atomic_unchecked_t fscache_n_uncaches;
52117
52118-extern atomic_t fscache_n_acquires;
52119-extern atomic_t fscache_n_acquires_null;
52120-extern atomic_t fscache_n_acquires_no_cache;
52121-extern atomic_t fscache_n_acquires_ok;
52122-extern atomic_t fscache_n_acquires_nobufs;
52123-extern atomic_t fscache_n_acquires_oom;
52124+extern atomic_unchecked_t fscache_n_acquires;
52125+extern atomic_unchecked_t fscache_n_acquires_null;
52126+extern atomic_unchecked_t fscache_n_acquires_no_cache;
52127+extern atomic_unchecked_t fscache_n_acquires_ok;
52128+extern atomic_unchecked_t fscache_n_acquires_nobufs;
52129+extern atomic_unchecked_t fscache_n_acquires_oom;
52130
52131-extern atomic_t fscache_n_invalidates;
52132-extern atomic_t fscache_n_invalidates_run;
52133+extern atomic_unchecked_t fscache_n_invalidates;
52134+extern atomic_unchecked_t fscache_n_invalidates_run;
52135
52136-extern atomic_t fscache_n_updates;
52137-extern atomic_t fscache_n_updates_null;
52138-extern atomic_t fscache_n_updates_run;
52139+extern atomic_unchecked_t fscache_n_updates;
52140+extern atomic_unchecked_t fscache_n_updates_null;
52141+extern atomic_unchecked_t fscache_n_updates_run;
52142
52143-extern atomic_t fscache_n_relinquishes;
52144-extern atomic_t fscache_n_relinquishes_null;
52145-extern atomic_t fscache_n_relinquishes_waitcrt;
52146-extern atomic_t fscache_n_relinquishes_retire;
52147+extern atomic_unchecked_t fscache_n_relinquishes;
52148+extern atomic_unchecked_t fscache_n_relinquishes_null;
52149+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52150+extern atomic_unchecked_t fscache_n_relinquishes_retire;
52151
52152-extern atomic_t fscache_n_cookie_index;
52153-extern atomic_t fscache_n_cookie_data;
52154-extern atomic_t fscache_n_cookie_special;
52155+extern atomic_unchecked_t fscache_n_cookie_index;
52156+extern atomic_unchecked_t fscache_n_cookie_data;
52157+extern atomic_unchecked_t fscache_n_cookie_special;
52158
52159-extern atomic_t fscache_n_object_alloc;
52160-extern atomic_t fscache_n_object_no_alloc;
52161-extern atomic_t fscache_n_object_lookups;
52162-extern atomic_t fscache_n_object_lookups_negative;
52163-extern atomic_t fscache_n_object_lookups_positive;
52164-extern atomic_t fscache_n_object_lookups_timed_out;
52165-extern atomic_t fscache_n_object_created;
52166-extern atomic_t fscache_n_object_avail;
52167-extern atomic_t fscache_n_object_dead;
52168+extern atomic_unchecked_t fscache_n_object_alloc;
52169+extern atomic_unchecked_t fscache_n_object_no_alloc;
52170+extern atomic_unchecked_t fscache_n_object_lookups;
52171+extern atomic_unchecked_t fscache_n_object_lookups_negative;
52172+extern atomic_unchecked_t fscache_n_object_lookups_positive;
52173+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
52174+extern atomic_unchecked_t fscache_n_object_created;
52175+extern atomic_unchecked_t fscache_n_object_avail;
52176+extern atomic_unchecked_t fscache_n_object_dead;
52177
52178-extern atomic_t fscache_n_checkaux_none;
52179-extern atomic_t fscache_n_checkaux_okay;
52180-extern atomic_t fscache_n_checkaux_update;
52181-extern atomic_t fscache_n_checkaux_obsolete;
52182+extern atomic_unchecked_t fscache_n_checkaux_none;
52183+extern atomic_unchecked_t fscache_n_checkaux_okay;
52184+extern atomic_unchecked_t fscache_n_checkaux_update;
52185+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
52186
52187 extern atomic_t fscache_n_cop_alloc_object;
52188 extern atomic_t fscache_n_cop_lookup_object;
52189@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
52190 atomic_inc(stat);
52191 }
52192
52193+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
52194+{
52195+ atomic_inc_unchecked(stat);
52196+}
52197+
52198 static inline void fscache_stat_d(atomic_t *stat)
52199 {
52200 atomic_dec(stat);
52201@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
52202
52203 #define __fscache_stat(stat) (NULL)
52204 #define fscache_stat(stat) do {} while (0)
52205+#define fscache_stat_unchecked(stat) do {} while (0)
52206 #define fscache_stat_d(stat) do {} while (0)
52207 #endif
52208
52209diff --git a/fs/fscache/object.c b/fs/fscache/object.c
52210index 50d41c1..10ee117 100644
52211--- a/fs/fscache/object.c
52212+++ b/fs/fscache/object.c
52213@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52214 /* Invalidate an object on disk */
52215 case FSCACHE_OBJECT_INVALIDATING:
52216 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
52217- fscache_stat(&fscache_n_invalidates_run);
52218+ fscache_stat_unchecked(&fscache_n_invalidates_run);
52219 fscache_stat(&fscache_n_cop_invalidate_object);
52220 fscache_invalidate_object(object);
52221 fscache_stat_d(&fscache_n_cop_invalidate_object);
52222@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52223 /* update the object metadata on disk */
52224 case FSCACHE_OBJECT_UPDATING:
52225 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
52226- fscache_stat(&fscache_n_updates_run);
52227+ fscache_stat_unchecked(&fscache_n_updates_run);
52228 fscache_stat(&fscache_n_cop_update_object);
52229 object->cache->ops->update_object(object);
52230 fscache_stat_d(&fscache_n_cop_update_object);
52231@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52232 spin_lock(&object->lock);
52233 object->state = FSCACHE_OBJECT_DEAD;
52234 spin_unlock(&object->lock);
52235- fscache_stat(&fscache_n_object_dead);
52236+ fscache_stat_unchecked(&fscache_n_object_dead);
52237 goto terminal_transit;
52238
52239 /* handle the parent cache of this object being withdrawn from
52240@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52241 spin_lock(&object->lock);
52242 object->state = FSCACHE_OBJECT_DEAD;
52243 spin_unlock(&object->lock);
52244- fscache_stat(&fscache_n_object_dead);
52245+ fscache_stat_unchecked(&fscache_n_object_dead);
52246 goto terminal_transit;
52247
52248 /* complain about the object being woken up once it is
52249@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52250 parent->cookie->def->name, cookie->def->name,
52251 object->cache->tag->name);
52252
52253- fscache_stat(&fscache_n_object_lookups);
52254+ fscache_stat_unchecked(&fscache_n_object_lookups);
52255 fscache_stat(&fscache_n_cop_lookup_object);
52256 ret = object->cache->ops->lookup_object(object);
52257 fscache_stat_d(&fscache_n_cop_lookup_object);
52258@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52259 if (ret == -ETIMEDOUT) {
52260 /* probably stuck behind another object, so move this one to
52261 * the back of the queue */
52262- fscache_stat(&fscache_n_object_lookups_timed_out);
52263+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
52264 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52265 }
52266
52267@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
52268
52269 spin_lock(&object->lock);
52270 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52271- fscache_stat(&fscache_n_object_lookups_negative);
52272+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
52273
52274 /* transit here to allow write requests to begin stacking up
52275 * and read requests to begin returning ENODATA */
52276@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
52277 * result, in which case there may be data available */
52278 spin_lock(&object->lock);
52279 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52280- fscache_stat(&fscache_n_object_lookups_positive);
52281+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
52282
52283 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
52284
52285@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
52286 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52287 } else {
52288 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
52289- fscache_stat(&fscache_n_object_created);
52290+ fscache_stat_unchecked(&fscache_n_object_created);
52291
52292 object->state = FSCACHE_OBJECT_AVAILABLE;
52293 spin_unlock(&object->lock);
52294@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
52295 fscache_enqueue_dependents(object);
52296
52297 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
52298- fscache_stat(&fscache_n_object_avail);
52299+ fscache_stat_unchecked(&fscache_n_object_avail);
52300
52301 _leave("");
52302 }
52303@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52304 enum fscache_checkaux result;
52305
52306 if (!object->cookie->def->check_aux) {
52307- fscache_stat(&fscache_n_checkaux_none);
52308+ fscache_stat_unchecked(&fscache_n_checkaux_none);
52309 return FSCACHE_CHECKAUX_OKAY;
52310 }
52311
52312@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52313 switch (result) {
52314 /* entry okay as is */
52315 case FSCACHE_CHECKAUX_OKAY:
52316- fscache_stat(&fscache_n_checkaux_okay);
52317+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
52318 break;
52319
52320 /* entry requires update */
52321 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
52322- fscache_stat(&fscache_n_checkaux_update);
52323+ fscache_stat_unchecked(&fscache_n_checkaux_update);
52324 break;
52325
52326 /* entry requires deletion */
52327 case FSCACHE_CHECKAUX_OBSOLETE:
52328- fscache_stat(&fscache_n_checkaux_obsolete);
52329+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
52330 break;
52331
52332 default:
52333diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
52334index 762a9ec..2023284 100644
52335--- a/fs/fscache/operation.c
52336+++ b/fs/fscache/operation.c
52337@@ -17,7 +17,7 @@
52338 #include <linux/slab.h>
52339 #include "internal.h"
52340
52341-atomic_t fscache_op_debug_id;
52342+atomic_unchecked_t fscache_op_debug_id;
52343 EXPORT_SYMBOL(fscache_op_debug_id);
52344
52345 /**
52346@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
52347 ASSERTCMP(atomic_read(&op->usage), >, 0);
52348 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
52349
52350- fscache_stat(&fscache_n_op_enqueue);
52351+ fscache_stat_unchecked(&fscache_n_op_enqueue);
52352 switch (op->flags & FSCACHE_OP_TYPE) {
52353 case FSCACHE_OP_ASYNC:
52354 _debug("queue async");
52355@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
52356 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
52357 if (op->processor)
52358 fscache_enqueue_operation(op);
52359- fscache_stat(&fscache_n_op_run);
52360+ fscache_stat_unchecked(&fscache_n_op_run);
52361 }
52362
52363 /*
52364@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52365 if (object->n_in_progress > 0) {
52366 atomic_inc(&op->usage);
52367 list_add_tail(&op->pend_link, &object->pending_ops);
52368- fscache_stat(&fscache_n_op_pend);
52369+ fscache_stat_unchecked(&fscache_n_op_pend);
52370 } else if (!list_empty(&object->pending_ops)) {
52371 atomic_inc(&op->usage);
52372 list_add_tail(&op->pend_link, &object->pending_ops);
52373- fscache_stat(&fscache_n_op_pend);
52374+ fscache_stat_unchecked(&fscache_n_op_pend);
52375 fscache_start_operations(object);
52376 } else {
52377 ASSERTCMP(object->n_in_progress, ==, 0);
52378@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52379 object->n_exclusive++; /* reads and writes must wait */
52380 atomic_inc(&op->usage);
52381 list_add_tail(&op->pend_link, &object->pending_ops);
52382- fscache_stat(&fscache_n_op_pend);
52383+ fscache_stat_unchecked(&fscache_n_op_pend);
52384 ret = 0;
52385 } else {
52386 /* If we're in any other state, there must have been an I/O
52387@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
52388 if (object->n_exclusive > 0) {
52389 atomic_inc(&op->usage);
52390 list_add_tail(&op->pend_link, &object->pending_ops);
52391- fscache_stat(&fscache_n_op_pend);
52392+ fscache_stat_unchecked(&fscache_n_op_pend);
52393 } else if (!list_empty(&object->pending_ops)) {
52394 atomic_inc(&op->usage);
52395 list_add_tail(&op->pend_link, &object->pending_ops);
52396- fscache_stat(&fscache_n_op_pend);
52397+ fscache_stat_unchecked(&fscache_n_op_pend);
52398 fscache_start_operations(object);
52399 } else {
52400 ASSERTCMP(object->n_exclusive, ==, 0);
52401@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
52402 object->n_ops++;
52403 atomic_inc(&op->usage);
52404 list_add_tail(&op->pend_link, &object->pending_ops);
52405- fscache_stat(&fscache_n_op_pend);
52406+ fscache_stat_unchecked(&fscache_n_op_pend);
52407 ret = 0;
52408 } else if (object->state == FSCACHE_OBJECT_DYING ||
52409 object->state == FSCACHE_OBJECT_LC_DYING ||
52410 object->state == FSCACHE_OBJECT_WITHDRAWING) {
52411- fscache_stat(&fscache_n_op_rejected);
52412+ fscache_stat_unchecked(&fscache_n_op_rejected);
52413 op->state = FSCACHE_OP_ST_CANCELLED;
52414 ret = -ENOBUFS;
52415 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
52416@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
52417 ret = -EBUSY;
52418 if (op->state == FSCACHE_OP_ST_PENDING) {
52419 ASSERT(!list_empty(&op->pend_link));
52420- fscache_stat(&fscache_n_op_cancelled);
52421+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52422 list_del_init(&op->pend_link);
52423 if (do_cancel)
52424 do_cancel(op);
52425@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
52426 while (!list_empty(&object->pending_ops)) {
52427 op = list_entry(object->pending_ops.next,
52428 struct fscache_operation, pend_link);
52429- fscache_stat(&fscache_n_op_cancelled);
52430+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52431 list_del_init(&op->pend_link);
52432
52433 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
52434@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
52435 op->state, ==, FSCACHE_OP_ST_CANCELLED);
52436 op->state = FSCACHE_OP_ST_DEAD;
52437
52438- fscache_stat(&fscache_n_op_release);
52439+ fscache_stat_unchecked(&fscache_n_op_release);
52440
52441 if (op->release) {
52442 op->release(op);
52443@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
52444 * lock, and defer it otherwise */
52445 if (!spin_trylock(&object->lock)) {
52446 _debug("defer put");
52447- fscache_stat(&fscache_n_op_deferred_release);
52448+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
52449
52450 cache = object->cache;
52451 spin_lock(&cache->op_gc_list_lock);
52452@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
52453
52454 _debug("GC DEFERRED REL OBJ%x OP%x",
52455 object->debug_id, op->debug_id);
52456- fscache_stat(&fscache_n_op_gc);
52457+ fscache_stat_unchecked(&fscache_n_op_gc);
52458
52459 ASSERTCMP(atomic_read(&op->usage), ==, 0);
52460 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
52461diff --git a/fs/fscache/page.c b/fs/fscache/page.c
52462index ff000e5..c44ec6d 100644
52463--- a/fs/fscache/page.c
52464+++ b/fs/fscache/page.c
52465@@ -61,7 +61,7 @@ try_again:
52466 val = radix_tree_lookup(&cookie->stores, page->index);
52467 if (!val) {
52468 rcu_read_unlock();
52469- fscache_stat(&fscache_n_store_vmscan_not_storing);
52470+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
52471 __fscache_uncache_page(cookie, page);
52472 return true;
52473 }
52474@@ -91,11 +91,11 @@ try_again:
52475 spin_unlock(&cookie->stores_lock);
52476
52477 if (xpage) {
52478- fscache_stat(&fscache_n_store_vmscan_cancelled);
52479- fscache_stat(&fscache_n_store_radix_deletes);
52480+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
52481+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52482 ASSERTCMP(xpage, ==, page);
52483 } else {
52484- fscache_stat(&fscache_n_store_vmscan_gone);
52485+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
52486 }
52487
52488 wake_up_bit(&cookie->flags, 0);
52489@@ -110,11 +110,11 @@ page_busy:
52490 * sleeping on memory allocation, so we may need to impose a timeout
52491 * too. */
52492 if (!(gfp & __GFP_WAIT)) {
52493- fscache_stat(&fscache_n_store_vmscan_busy);
52494+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
52495 return false;
52496 }
52497
52498- fscache_stat(&fscache_n_store_vmscan_wait);
52499+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
52500 __fscache_wait_on_page_write(cookie, page);
52501 gfp &= ~__GFP_WAIT;
52502 goto try_again;
52503@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
52504 FSCACHE_COOKIE_STORING_TAG);
52505 if (!radix_tree_tag_get(&cookie->stores, page->index,
52506 FSCACHE_COOKIE_PENDING_TAG)) {
52507- fscache_stat(&fscache_n_store_radix_deletes);
52508+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52509 xpage = radix_tree_delete(&cookie->stores, page->index);
52510 }
52511 spin_unlock(&cookie->stores_lock);
52512@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
52513
52514 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
52515
52516- fscache_stat(&fscache_n_attr_changed_calls);
52517+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
52518
52519 if (fscache_object_is_active(object)) {
52520 fscache_stat(&fscache_n_cop_attr_changed);
52521@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52522
52523 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52524
52525- fscache_stat(&fscache_n_attr_changed);
52526+ fscache_stat_unchecked(&fscache_n_attr_changed);
52527
52528 op = kzalloc(sizeof(*op), GFP_KERNEL);
52529 if (!op) {
52530- fscache_stat(&fscache_n_attr_changed_nomem);
52531+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
52532 _leave(" = -ENOMEM");
52533 return -ENOMEM;
52534 }
52535@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52536 if (fscache_submit_exclusive_op(object, op) < 0)
52537 goto nobufs;
52538 spin_unlock(&cookie->lock);
52539- fscache_stat(&fscache_n_attr_changed_ok);
52540+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
52541 fscache_put_operation(op);
52542 _leave(" = 0");
52543 return 0;
52544@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52545 nobufs:
52546 spin_unlock(&cookie->lock);
52547 kfree(op);
52548- fscache_stat(&fscache_n_attr_changed_nobufs);
52549+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
52550 _leave(" = %d", -ENOBUFS);
52551 return -ENOBUFS;
52552 }
52553@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52554 /* allocate a retrieval operation and attempt to submit it */
52555 op = kzalloc(sizeof(*op), GFP_NOIO);
52556 if (!op) {
52557- fscache_stat(&fscache_n_retrievals_nomem);
52558+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52559 return NULL;
52560 }
52561
52562@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52563 return 0;
52564 }
52565
52566- fscache_stat(&fscache_n_retrievals_wait);
52567+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52568
52569 jif = jiffies;
52570 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52571 fscache_wait_bit_interruptible,
52572 TASK_INTERRUPTIBLE) != 0) {
52573- fscache_stat(&fscache_n_retrievals_intr);
52574+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52575 _leave(" = -ERESTARTSYS");
52576 return -ERESTARTSYS;
52577 }
52578@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52579 */
52580 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52581 struct fscache_retrieval *op,
52582- atomic_t *stat_op_waits,
52583- atomic_t *stat_object_dead)
52584+ atomic_unchecked_t *stat_op_waits,
52585+ atomic_unchecked_t *stat_object_dead)
52586 {
52587 int ret;
52588
52589@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52590 goto check_if_dead;
52591
52592 _debug(">>> WT");
52593- fscache_stat(stat_op_waits);
52594+ fscache_stat_unchecked(stat_op_waits);
52595 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52596 fscache_wait_bit_interruptible,
52597 TASK_INTERRUPTIBLE) != 0) {
52598@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52599
52600 check_if_dead:
52601 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52602- fscache_stat(stat_object_dead);
52603+ fscache_stat_unchecked(stat_object_dead);
52604 _leave(" = -ENOBUFS [cancelled]");
52605 return -ENOBUFS;
52606 }
52607 if (unlikely(fscache_object_is_dead(object))) {
52608 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52609 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52610- fscache_stat(stat_object_dead);
52611+ fscache_stat_unchecked(stat_object_dead);
52612 return -ENOBUFS;
52613 }
52614 return 0;
52615@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52616
52617 _enter("%p,%p,,,", cookie, page);
52618
52619- fscache_stat(&fscache_n_retrievals);
52620+ fscache_stat_unchecked(&fscache_n_retrievals);
52621
52622 if (hlist_empty(&cookie->backing_objects))
52623 goto nobufs;
52624@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52625 goto nobufs_unlock_dec;
52626 spin_unlock(&cookie->lock);
52627
52628- fscache_stat(&fscache_n_retrieval_ops);
52629+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52630
52631 /* pin the netfs read context in case we need to do the actual netfs
52632 * read because we've encountered a cache read failure */
52633@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52634
52635 error:
52636 if (ret == -ENOMEM)
52637- fscache_stat(&fscache_n_retrievals_nomem);
52638+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52639 else if (ret == -ERESTARTSYS)
52640- fscache_stat(&fscache_n_retrievals_intr);
52641+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52642 else if (ret == -ENODATA)
52643- fscache_stat(&fscache_n_retrievals_nodata);
52644+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52645 else if (ret < 0)
52646- fscache_stat(&fscache_n_retrievals_nobufs);
52647+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52648 else
52649- fscache_stat(&fscache_n_retrievals_ok);
52650+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52651
52652 fscache_put_retrieval(op);
52653 _leave(" = %d", ret);
52654@@ -467,7 +467,7 @@ nobufs_unlock:
52655 spin_unlock(&cookie->lock);
52656 kfree(op);
52657 nobufs:
52658- fscache_stat(&fscache_n_retrievals_nobufs);
52659+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52660 _leave(" = -ENOBUFS");
52661 return -ENOBUFS;
52662 }
52663@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52664
52665 _enter("%p,,%d,,,", cookie, *nr_pages);
52666
52667- fscache_stat(&fscache_n_retrievals);
52668+ fscache_stat_unchecked(&fscache_n_retrievals);
52669
52670 if (hlist_empty(&cookie->backing_objects))
52671 goto nobufs;
52672@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52673 goto nobufs_unlock_dec;
52674 spin_unlock(&cookie->lock);
52675
52676- fscache_stat(&fscache_n_retrieval_ops);
52677+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52678
52679 /* pin the netfs read context in case we need to do the actual netfs
52680 * read because we've encountered a cache read failure */
52681@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52682
52683 error:
52684 if (ret == -ENOMEM)
52685- fscache_stat(&fscache_n_retrievals_nomem);
52686+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52687 else if (ret == -ERESTARTSYS)
52688- fscache_stat(&fscache_n_retrievals_intr);
52689+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52690 else if (ret == -ENODATA)
52691- fscache_stat(&fscache_n_retrievals_nodata);
52692+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52693 else if (ret < 0)
52694- fscache_stat(&fscache_n_retrievals_nobufs);
52695+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52696 else
52697- fscache_stat(&fscache_n_retrievals_ok);
52698+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52699
52700 fscache_put_retrieval(op);
52701 _leave(" = %d", ret);
52702@@ -591,7 +591,7 @@ nobufs_unlock:
52703 spin_unlock(&cookie->lock);
52704 kfree(op);
52705 nobufs:
52706- fscache_stat(&fscache_n_retrievals_nobufs);
52707+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52708 _leave(" = -ENOBUFS");
52709 return -ENOBUFS;
52710 }
52711@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52712
52713 _enter("%p,%p,,,", cookie, page);
52714
52715- fscache_stat(&fscache_n_allocs);
52716+ fscache_stat_unchecked(&fscache_n_allocs);
52717
52718 if (hlist_empty(&cookie->backing_objects))
52719 goto nobufs;
52720@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52721 goto nobufs_unlock;
52722 spin_unlock(&cookie->lock);
52723
52724- fscache_stat(&fscache_n_alloc_ops);
52725+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52726
52727 ret = fscache_wait_for_retrieval_activation(
52728 object, op,
52729@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52730
52731 error:
52732 if (ret == -ERESTARTSYS)
52733- fscache_stat(&fscache_n_allocs_intr);
52734+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52735 else if (ret < 0)
52736- fscache_stat(&fscache_n_allocs_nobufs);
52737+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52738 else
52739- fscache_stat(&fscache_n_allocs_ok);
52740+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52741
52742 fscache_put_retrieval(op);
52743 _leave(" = %d", ret);
52744@@ -677,7 +677,7 @@ nobufs_unlock:
52745 spin_unlock(&cookie->lock);
52746 kfree(op);
52747 nobufs:
52748- fscache_stat(&fscache_n_allocs_nobufs);
52749+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52750 _leave(" = -ENOBUFS");
52751 return -ENOBUFS;
52752 }
52753@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52754
52755 spin_lock(&cookie->stores_lock);
52756
52757- fscache_stat(&fscache_n_store_calls);
52758+ fscache_stat_unchecked(&fscache_n_store_calls);
52759
52760 /* find a page to store */
52761 page = NULL;
52762@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52763 page = results[0];
52764 _debug("gang %d [%lx]", n, page->index);
52765 if (page->index > op->store_limit) {
52766- fscache_stat(&fscache_n_store_pages_over_limit);
52767+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52768 goto superseded;
52769 }
52770
52771@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52772 spin_unlock(&cookie->stores_lock);
52773 spin_unlock(&object->lock);
52774
52775- fscache_stat(&fscache_n_store_pages);
52776+ fscache_stat_unchecked(&fscache_n_store_pages);
52777 fscache_stat(&fscache_n_cop_write_page);
52778 ret = object->cache->ops->write_page(op, page);
52779 fscache_stat_d(&fscache_n_cop_write_page);
52780@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52781 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52782 ASSERT(PageFsCache(page));
52783
52784- fscache_stat(&fscache_n_stores);
52785+ fscache_stat_unchecked(&fscache_n_stores);
52786
52787 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52788 _leave(" = -ENOBUFS [invalidating]");
52789@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52790 spin_unlock(&cookie->stores_lock);
52791 spin_unlock(&object->lock);
52792
52793- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52794+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52795 op->store_limit = object->store_limit;
52796
52797 if (fscache_submit_op(object, &op->op) < 0)
52798@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52799
52800 spin_unlock(&cookie->lock);
52801 radix_tree_preload_end();
52802- fscache_stat(&fscache_n_store_ops);
52803- fscache_stat(&fscache_n_stores_ok);
52804+ fscache_stat_unchecked(&fscache_n_store_ops);
52805+ fscache_stat_unchecked(&fscache_n_stores_ok);
52806
52807 /* the work queue now carries its own ref on the object */
52808 fscache_put_operation(&op->op);
52809@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52810 return 0;
52811
52812 already_queued:
52813- fscache_stat(&fscache_n_stores_again);
52814+ fscache_stat_unchecked(&fscache_n_stores_again);
52815 already_pending:
52816 spin_unlock(&cookie->stores_lock);
52817 spin_unlock(&object->lock);
52818 spin_unlock(&cookie->lock);
52819 radix_tree_preload_end();
52820 kfree(op);
52821- fscache_stat(&fscache_n_stores_ok);
52822+ fscache_stat_unchecked(&fscache_n_stores_ok);
52823 _leave(" = 0");
52824 return 0;
52825
52826@@ -959,14 +959,14 @@ nobufs:
52827 spin_unlock(&cookie->lock);
52828 radix_tree_preload_end();
52829 kfree(op);
52830- fscache_stat(&fscache_n_stores_nobufs);
52831+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52832 _leave(" = -ENOBUFS");
52833 return -ENOBUFS;
52834
52835 nomem_free:
52836 kfree(op);
52837 nomem:
52838- fscache_stat(&fscache_n_stores_oom);
52839+ fscache_stat_unchecked(&fscache_n_stores_oom);
52840 _leave(" = -ENOMEM");
52841 return -ENOMEM;
52842 }
52843@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52844 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52845 ASSERTCMP(page, !=, NULL);
52846
52847- fscache_stat(&fscache_n_uncaches);
52848+ fscache_stat_unchecked(&fscache_n_uncaches);
52849
52850 /* cache withdrawal may beat us to it */
52851 if (!PageFsCache(page))
52852@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52853 struct fscache_cookie *cookie = op->op.object->cookie;
52854
52855 #ifdef CONFIG_FSCACHE_STATS
52856- atomic_inc(&fscache_n_marks);
52857+ atomic_inc_unchecked(&fscache_n_marks);
52858 #endif
52859
52860 _debug("- mark %p{%lx}", page, page->index);
52861diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
52862index 40d13c7..ddf52b9 100644
52863--- a/fs/fscache/stats.c
52864+++ b/fs/fscache/stats.c
52865@@ -18,99 +18,99 @@
52866 /*
52867 * operation counters
52868 */
52869-atomic_t fscache_n_op_pend;
52870-atomic_t fscache_n_op_run;
52871-atomic_t fscache_n_op_enqueue;
52872-atomic_t fscache_n_op_requeue;
52873-atomic_t fscache_n_op_deferred_release;
52874-atomic_t fscache_n_op_release;
52875-atomic_t fscache_n_op_gc;
52876-atomic_t fscache_n_op_cancelled;
52877-atomic_t fscache_n_op_rejected;
52878+atomic_unchecked_t fscache_n_op_pend;
52879+atomic_unchecked_t fscache_n_op_run;
52880+atomic_unchecked_t fscache_n_op_enqueue;
52881+atomic_unchecked_t fscache_n_op_requeue;
52882+atomic_unchecked_t fscache_n_op_deferred_release;
52883+atomic_unchecked_t fscache_n_op_release;
52884+atomic_unchecked_t fscache_n_op_gc;
52885+atomic_unchecked_t fscache_n_op_cancelled;
52886+atomic_unchecked_t fscache_n_op_rejected;
52887
52888-atomic_t fscache_n_attr_changed;
52889-atomic_t fscache_n_attr_changed_ok;
52890-atomic_t fscache_n_attr_changed_nobufs;
52891-atomic_t fscache_n_attr_changed_nomem;
52892-atomic_t fscache_n_attr_changed_calls;
52893+atomic_unchecked_t fscache_n_attr_changed;
52894+atomic_unchecked_t fscache_n_attr_changed_ok;
52895+atomic_unchecked_t fscache_n_attr_changed_nobufs;
52896+atomic_unchecked_t fscache_n_attr_changed_nomem;
52897+atomic_unchecked_t fscache_n_attr_changed_calls;
52898
52899-atomic_t fscache_n_allocs;
52900-atomic_t fscache_n_allocs_ok;
52901-atomic_t fscache_n_allocs_wait;
52902-atomic_t fscache_n_allocs_nobufs;
52903-atomic_t fscache_n_allocs_intr;
52904-atomic_t fscache_n_allocs_object_dead;
52905-atomic_t fscache_n_alloc_ops;
52906-atomic_t fscache_n_alloc_op_waits;
52907+atomic_unchecked_t fscache_n_allocs;
52908+atomic_unchecked_t fscache_n_allocs_ok;
52909+atomic_unchecked_t fscache_n_allocs_wait;
52910+atomic_unchecked_t fscache_n_allocs_nobufs;
52911+atomic_unchecked_t fscache_n_allocs_intr;
52912+atomic_unchecked_t fscache_n_allocs_object_dead;
52913+atomic_unchecked_t fscache_n_alloc_ops;
52914+atomic_unchecked_t fscache_n_alloc_op_waits;
52915
52916-atomic_t fscache_n_retrievals;
52917-atomic_t fscache_n_retrievals_ok;
52918-atomic_t fscache_n_retrievals_wait;
52919-atomic_t fscache_n_retrievals_nodata;
52920-atomic_t fscache_n_retrievals_nobufs;
52921-atomic_t fscache_n_retrievals_intr;
52922-atomic_t fscache_n_retrievals_nomem;
52923-atomic_t fscache_n_retrievals_object_dead;
52924-atomic_t fscache_n_retrieval_ops;
52925-atomic_t fscache_n_retrieval_op_waits;
52926+atomic_unchecked_t fscache_n_retrievals;
52927+atomic_unchecked_t fscache_n_retrievals_ok;
52928+atomic_unchecked_t fscache_n_retrievals_wait;
52929+atomic_unchecked_t fscache_n_retrievals_nodata;
52930+atomic_unchecked_t fscache_n_retrievals_nobufs;
52931+atomic_unchecked_t fscache_n_retrievals_intr;
52932+atomic_unchecked_t fscache_n_retrievals_nomem;
52933+atomic_unchecked_t fscache_n_retrievals_object_dead;
52934+atomic_unchecked_t fscache_n_retrieval_ops;
52935+atomic_unchecked_t fscache_n_retrieval_op_waits;
52936
52937-atomic_t fscache_n_stores;
52938-atomic_t fscache_n_stores_ok;
52939-atomic_t fscache_n_stores_again;
52940-atomic_t fscache_n_stores_nobufs;
52941-atomic_t fscache_n_stores_oom;
52942-atomic_t fscache_n_store_ops;
52943-atomic_t fscache_n_store_calls;
52944-atomic_t fscache_n_store_pages;
52945-atomic_t fscache_n_store_radix_deletes;
52946-atomic_t fscache_n_store_pages_over_limit;
52947+atomic_unchecked_t fscache_n_stores;
52948+atomic_unchecked_t fscache_n_stores_ok;
52949+atomic_unchecked_t fscache_n_stores_again;
52950+atomic_unchecked_t fscache_n_stores_nobufs;
52951+atomic_unchecked_t fscache_n_stores_oom;
52952+atomic_unchecked_t fscache_n_store_ops;
52953+atomic_unchecked_t fscache_n_store_calls;
52954+atomic_unchecked_t fscache_n_store_pages;
52955+atomic_unchecked_t fscache_n_store_radix_deletes;
52956+atomic_unchecked_t fscache_n_store_pages_over_limit;
52957
52958-atomic_t fscache_n_store_vmscan_not_storing;
52959-atomic_t fscache_n_store_vmscan_gone;
52960-atomic_t fscache_n_store_vmscan_busy;
52961-atomic_t fscache_n_store_vmscan_cancelled;
52962-atomic_t fscache_n_store_vmscan_wait;
52963+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52964+atomic_unchecked_t fscache_n_store_vmscan_gone;
52965+atomic_unchecked_t fscache_n_store_vmscan_busy;
52966+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52967+atomic_unchecked_t fscache_n_store_vmscan_wait;
52968
52969-atomic_t fscache_n_marks;
52970-atomic_t fscache_n_uncaches;
52971+atomic_unchecked_t fscache_n_marks;
52972+atomic_unchecked_t fscache_n_uncaches;
52973
52974-atomic_t fscache_n_acquires;
52975-atomic_t fscache_n_acquires_null;
52976-atomic_t fscache_n_acquires_no_cache;
52977-atomic_t fscache_n_acquires_ok;
52978-atomic_t fscache_n_acquires_nobufs;
52979-atomic_t fscache_n_acquires_oom;
52980+atomic_unchecked_t fscache_n_acquires;
52981+atomic_unchecked_t fscache_n_acquires_null;
52982+atomic_unchecked_t fscache_n_acquires_no_cache;
52983+atomic_unchecked_t fscache_n_acquires_ok;
52984+atomic_unchecked_t fscache_n_acquires_nobufs;
52985+atomic_unchecked_t fscache_n_acquires_oom;
52986
52987-atomic_t fscache_n_invalidates;
52988-atomic_t fscache_n_invalidates_run;
52989+atomic_unchecked_t fscache_n_invalidates;
52990+atomic_unchecked_t fscache_n_invalidates_run;
52991
52992-atomic_t fscache_n_updates;
52993-atomic_t fscache_n_updates_null;
52994-atomic_t fscache_n_updates_run;
52995+atomic_unchecked_t fscache_n_updates;
52996+atomic_unchecked_t fscache_n_updates_null;
52997+atomic_unchecked_t fscache_n_updates_run;
52998
52999-atomic_t fscache_n_relinquishes;
53000-atomic_t fscache_n_relinquishes_null;
53001-atomic_t fscache_n_relinquishes_waitcrt;
53002-atomic_t fscache_n_relinquishes_retire;
53003+atomic_unchecked_t fscache_n_relinquishes;
53004+atomic_unchecked_t fscache_n_relinquishes_null;
53005+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
53006+atomic_unchecked_t fscache_n_relinquishes_retire;
53007
53008-atomic_t fscache_n_cookie_index;
53009-atomic_t fscache_n_cookie_data;
53010-atomic_t fscache_n_cookie_special;
53011+atomic_unchecked_t fscache_n_cookie_index;
53012+atomic_unchecked_t fscache_n_cookie_data;
53013+atomic_unchecked_t fscache_n_cookie_special;
53014
53015-atomic_t fscache_n_object_alloc;
53016-atomic_t fscache_n_object_no_alloc;
53017-atomic_t fscache_n_object_lookups;
53018-atomic_t fscache_n_object_lookups_negative;
53019-atomic_t fscache_n_object_lookups_positive;
53020-atomic_t fscache_n_object_lookups_timed_out;
53021-atomic_t fscache_n_object_created;
53022-atomic_t fscache_n_object_avail;
53023-atomic_t fscache_n_object_dead;
53024+atomic_unchecked_t fscache_n_object_alloc;
53025+atomic_unchecked_t fscache_n_object_no_alloc;
53026+atomic_unchecked_t fscache_n_object_lookups;
53027+atomic_unchecked_t fscache_n_object_lookups_negative;
53028+atomic_unchecked_t fscache_n_object_lookups_positive;
53029+atomic_unchecked_t fscache_n_object_lookups_timed_out;
53030+atomic_unchecked_t fscache_n_object_created;
53031+atomic_unchecked_t fscache_n_object_avail;
53032+atomic_unchecked_t fscache_n_object_dead;
53033
53034-atomic_t fscache_n_checkaux_none;
53035-atomic_t fscache_n_checkaux_okay;
53036-atomic_t fscache_n_checkaux_update;
53037-atomic_t fscache_n_checkaux_obsolete;
53038+atomic_unchecked_t fscache_n_checkaux_none;
53039+atomic_unchecked_t fscache_n_checkaux_okay;
53040+atomic_unchecked_t fscache_n_checkaux_update;
53041+atomic_unchecked_t fscache_n_checkaux_obsolete;
53042
53043 atomic_t fscache_n_cop_alloc_object;
53044 atomic_t fscache_n_cop_lookup_object;
53045@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
53046 seq_puts(m, "FS-Cache statistics\n");
53047
53048 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
53049- atomic_read(&fscache_n_cookie_index),
53050- atomic_read(&fscache_n_cookie_data),
53051- atomic_read(&fscache_n_cookie_special));
53052+ atomic_read_unchecked(&fscache_n_cookie_index),
53053+ atomic_read_unchecked(&fscache_n_cookie_data),
53054+ atomic_read_unchecked(&fscache_n_cookie_special));
53055
53056 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
53057- atomic_read(&fscache_n_object_alloc),
53058- atomic_read(&fscache_n_object_no_alloc),
53059- atomic_read(&fscache_n_object_avail),
53060- atomic_read(&fscache_n_object_dead));
53061+ atomic_read_unchecked(&fscache_n_object_alloc),
53062+ atomic_read_unchecked(&fscache_n_object_no_alloc),
53063+ atomic_read_unchecked(&fscache_n_object_avail),
53064+ atomic_read_unchecked(&fscache_n_object_dead));
53065 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
53066- atomic_read(&fscache_n_checkaux_none),
53067- atomic_read(&fscache_n_checkaux_okay),
53068- atomic_read(&fscache_n_checkaux_update),
53069- atomic_read(&fscache_n_checkaux_obsolete));
53070+ atomic_read_unchecked(&fscache_n_checkaux_none),
53071+ atomic_read_unchecked(&fscache_n_checkaux_okay),
53072+ atomic_read_unchecked(&fscache_n_checkaux_update),
53073+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
53074
53075 seq_printf(m, "Pages : mrk=%u unc=%u\n",
53076- atomic_read(&fscache_n_marks),
53077- atomic_read(&fscache_n_uncaches));
53078+ atomic_read_unchecked(&fscache_n_marks),
53079+ atomic_read_unchecked(&fscache_n_uncaches));
53080
53081 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
53082 " oom=%u\n",
53083- atomic_read(&fscache_n_acquires),
53084- atomic_read(&fscache_n_acquires_null),
53085- atomic_read(&fscache_n_acquires_no_cache),
53086- atomic_read(&fscache_n_acquires_ok),
53087- atomic_read(&fscache_n_acquires_nobufs),
53088- atomic_read(&fscache_n_acquires_oom));
53089+ atomic_read_unchecked(&fscache_n_acquires),
53090+ atomic_read_unchecked(&fscache_n_acquires_null),
53091+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
53092+ atomic_read_unchecked(&fscache_n_acquires_ok),
53093+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
53094+ atomic_read_unchecked(&fscache_n_acquires_oom));
53095
53096 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
53097- atomic_read(&fscache_n_object_lookups),
53098- atomic_read(&fscache_n_object_lookups_negative),
53099- atomic_read(&fscache_n_object_lookups_positive),
53100- atomic_read(&fscache_n_object_created),
53101- atomic_read(&fscache_n_object_lookups_timed_out));
53102+ atomic_read_unchecked(&fscache_n_object_lookups),
53103+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
53104+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
53105+ atomic_read_unchecked(&fscache_n_object_created),
53106+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
53107
53108 seq_printf(m, "Invals : n=%u run=%u\n",
53109- atomic_read(&fscache_n_invalidates),
53110- atomic_read(&fscache_n_invalidates_run));
53111+ atomic_read_unchecked(&fscache_n_invalidates),
53112+ atomic_read_unchecked(&fscache_n_invalidates_run));
53113
53114 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
53115- atomic_read(&fscache_n_updates),
53116- atomic_read(&fscache_n_updates_null),
53117- atomic_read(&fscache_n_updates_run));
53118+ atomic_read_unchecked(&fscache_n_updates),
53119+ atomic_read_unchecked(&fscache_n_updates_null),
53120+ atomic_read_unchecked(&fscache_n_updates_run));
53121
53122 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
53123- atomic_read(&fscache_n_relinquishes),
53124- atomic_read(&fscache_n_relinquishes_null),
53125- atomic_read(&fscache_n_relinquishes_waitcrt),
53126- atomic_read(&fscache_n_relinquishes_retire));
53127+ atomic_read_unchecked(&fscache_n_relinquishes),
53128+ atomic_read_unchecked(&fscache_n_relinquishes_null),
53129+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
53130+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
53131
53132 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
53133- atomic_read(&fscache_n_attr_changed),
53134- atomic_read(&fscache_n_attr_changed_ok),
53135- atomic_read(&fscache_n_attr_changed_nobufs),
53136- atomic_read(&fscache_n_attr_changed_nomem),
53137- atomic_read(&fscache_n_attr_changed_calls));
53138+ atomic_read_unchecked(&fscache_n_attr_changed),
53139+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
53140+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
53141+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
53142+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
53143
53144 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
53145- atomic_read(&fscache_n_allocs),
53146- atomic_read(&fscache_n_allocs_ok),
53147- atomic_read(&fscache_n_allocs_wait),
53148- atomic_read(&fscache_n_allocs_nobufs),
53149- atomic_read(&fscache_n_allocs_intr));
53150+ atomic_read_unchecked(&fscache_n_allocs),
53151+ atomic_read_unchecked(&fscache_n_allocs_ok),
53152+ atomic_read_unchecked(&fscache_n_allocs_wait),
53153+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
53154+ atomic_read_unchecked(&fscache_n_allocs_intr));
53155 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
53156- atomic_read(&fscache_n_alloc_ops),
53157- atomic_read(&fscache_n_alloc_op_waits),
53158- atomic_read(&fscache_n_allocs_object_dead));
53159+ atomic_read_unchecked(&fscache_n_alloc_ops),
53160+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
53161+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
53162
53163 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
53164 " int=%u oom=%u\n",
53165- atomic_read(&fscache_n_retrievals),
53166- atomic_read(&fscache_n_retrievals_ok),
53167- atomic_read(&fscache_n_retrievals_wait),
53168- atomic_read(&fscache_n_retrievals_nodata),
53169- atomic_read(&fscache_n_retrievals_nobufs),
53170- atomic_read(&fscache_n_retrievals_intr),
53171- atomic_read(&fscache_n_retrievals_nomem));
53172+ atomic_read_unchecked(&fscache_n_retrievals),
53173+ atomic_read_unchecked(&fscache_n_retrievals_ok),
53174+ atomic_read_unchecked(&fscache_n_retrievals_wait),
53175+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
53176+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
53177+ atomic_read_unchecked(&fscache_n_retrievals_intr),
53178+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
53179 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
53180- atomic_read(&fscache_n_retrieval_ops),
53181- atomic_read(&fscache_n_retrieval_op_waits),
53182- atomic_read(&fscache_n_retrievals_object_dead));
53183+ atomic_read_unchecked(&fscache_n_retrieval_ops),
53184+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
53185+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
53186
53187 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
53188- atomic_read(&fscache_n_stores),
53189- atomic_read(&fscache_n_stores_ok),
53190- atomic_read(&fscache_n_stores_again),
53191- atomic_read(&fscache_n_stores_nobufs),
53192- atomic_read(&fscache_n_stores_oom));
53193+ atomic_read_unchecked(&fscache_n_stores),
53194+ atomic_read_unchecked(&fscache_n_stores_ok),
53195+ atomic_read_unchecked(&fscache_n_stores_again),
53196+ atomic_read_unchecked(&fscache_n_stores_nobufs),
53197+ atomic_read_unchecked(&fscache_n_stores_oom));
53198 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
53199- atomic_read(&fscache_n_store_ops),
53200- atomic_read(&fscache_n_store_calls),
53201- atomic_read(&fscache_n_store_pages),
53202- atomic_read(&fscache_n_store_radix_deletes),
53203- atomic_read(&fscache_n_store_pages_over_limit));
53204+ atomic_read_unchecked(&fscache_n_store_ops),
53205+ atomic_read_unchecked(&fscache_n_store_calls),
53206+ atomic_read_unchecked(&fscache_n_store_pages),
53207+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
53208+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
53209
53210 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
53211- atomic_read(&fscache_n_store_vmscan_not_storing),
53212- atomic_read(&fscache_n_store_vmscan_gone),
53213- atomic_read(&fscache_n_store_vmscan_busy),
53214- atomic_read(&fscache_n_store_vmscan_cancelled),
53215- atomic_read(&fscache_n_store_vmscan_wait));
53216+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
53217+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
53218+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
53219+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
53220+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
53221
53222 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
53223- atomic_read(&fscache_n_op_pend),
53224- atomic_read(&fscache_n_op_run),
53225- atomic_read(&fscache_n_op_enqueue),
53226- atomic_read(&fscache_n_op_cancelled),
53227- atomic_read(&fscache_n_op_rejected));
53228+ atomic_read_unchecked(&fscache_n_op_pend),
53229+ atomic_read_unchecked(&fscache_n_op_run),
53230+ atomic_read_unchecked(&fscache_n_op_enqueue),
53231+ atomic_read_unchecked(&fscache_n_op_cancelled),
53232+ atomic_read_unchecked(&fscache_n_op_rejected));
53233 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
53234- atomic_read(&fscache_n_op_deferred_release),
53235- atomic_read(&fscache_n_op_release),
53236- atomic_read(&fscache_n_op_gc));
53237+ atomic_read_unchecked(&fscache_n_op_deferred_release),
53238+ atomic_read_unchecked(&fscache_n_op_release),
53239+ atomic_read_unchecked(&fscache_n_op_gc));
53240
53241 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
53242 atomic_read(&fscache_n_cop_alloc_object),
53243diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
53244index aef34b1..59bfd7b 100644
53245--- a/fs/fuse/cuse.c
53246+++ b/fs/fuse/cuse.c
53247@@ -600,10 +600,12 @@ static int __init cuse_init(void)
53248 INIT_LIST_HEAD(&cuse_conntbl[i]);
53249
53250 /* inherit and extend fuse_dev_operations */
53251- cuse_channel_fops = fuse_dev_operations;
53252- cuse_channel_fops.owner = THIS_MODULE;
53253- cuse_channel_fops.open = cuse_channel_open;
53254- cuse_channel_fops.release = cuse_channel_release;
53255+ pax_open_kernel();
53256+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
53257+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
53258+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
53259+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
53260+ pax_close_kernel();
53261
53262 cuse_class = class_create(THIS_MODULE, "cuse");
53263 if (IS_ERR(cuse_class))
53264diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
53265index 1d55f94..088da65 100644
53266--- a/fs/fuse/dev.c
53267+++ b/fs/fuse/dev.c
53268@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53269 ret = 0;
53270 pipe_lock(pipe);
53271
53272- if (!pipe->readers) {
53273+ if (!atomic_read(&pipe->readers)) {
53274 send_sig(SIGPIPE, current, 0);
53275 if (!ret)
53276 ret = -EPIPE;
53277@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53278 page_nr++;
53279 ret += buf->len;
53280
53281- if (pipe->files)
53282+ if (atomic_read(&pipe->files))
53283 do_wakeup = 1;
53284 }
53285
53286diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
53287index f3f783d..bf11a8e 100644
53288--- a/fs/fuse/dir.c
53289+++ b/fs/fuse/dir.c
53290@@ -1415,7 +1415,7 @@ static char *read_link(struct dentry *dentry)
53291 return link;
53292 }
53293
53294-static void free_link(char *link)
53295+static void free_link(const char *link)
53296 {
53297 if (!IS_ERR(link))
53298 free_page((unsigned long) link);
53299diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
53300index 62b484e..0f9a140 100644
53301--- a/fs/gfs2/inode.c
53302+++ b/fs/gfs2/inode.c
53303@@ -1441,7 +1441,7 @@ out:
53304
53305 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53306 {
53307- char *s = nd_get_link(nd);
53308+ const char *s = nd_get_link(nd);
53309 if (!IS_ERR(s))
53310 kfree(s);
53311 }
53312diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
53313index a3f868a..bb308ae 100644
53314--- a/fs/hugetlbfs/inode.c
53315+++ b/fs/hugetlbfs/inode.c
53316@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53317 struct mm_struct *mm = current->mm;
53318 struct vm_area_struct *vma;
53319 struct hstate *h = hstate_file(file);
53320+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
53321 struct vm_unmapped_area_info info;
53322
53323 if (len & ~huge_page_mask(h))
53324@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53325 return addr;
53326 }
53327
53328+#ifdef CONFIG_PAX_RANDMMAP
53329+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53330+#endif
53331+
53332 if (addr) {
53333 addr = ALIGN(addr, huge_page_size(h));
53334 vma = find_vma(mm, addr);
53335- if (TASK_SIZE - len >= addr &&
53336- (!vma || addr + len <= vma->vm_start))
53337+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
53338 return addr;
53339 }
53340
53341 info.flags = 0;
53342 info.length = len;
53343 info.low_limit = TASK_UNMAPPED_BASE;
53344+
53345+#ifdef CONFIG_PAX_RANDMMAP
53346+ if (mm->pax_flags & MF_PAX_RANDMMAP)
53347+ info.low_limit += mm->delta_mmap;
53348+#endif
53349+
53350 info.high_limit = TASK_SIZE;
53351 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
53352 info.align_offset = 0;
53353@@ -898,7 +908,7 @@ static struct file_system_type hugetlbfs_fs_type = {
53354 };
53355 MODULE_ALIAS_FS("hugetlbfs");
53356
53357-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53358+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53359
53360 static int can_do_hugetlb_shm(void)
53361 {
53362diff --git a/fs/inode.c b/fs/inode.c
53363index 00d5fc3..98ce7d7 100644
53364--- a/fs/inode.c
53365+++ b/fs/inode.c
53366@@ -878,8 +878,8 @@ unsigned int get_next_ino(void)
53367
53368 #ifdef CONFIG_SMP
53369 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
53370- static atomic_t shared_last_ino;
53371- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
53372+ static atomic_unchecked_t shared_last_ino;
53373+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
53374
53375 res = next - LAST_INO_BATCH;
53376 }
53377diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
53378index 4a6cf28..d3a29d3 100644
53379--- a/fs/jffs2/erase.c
53380+++ b/fs/jffs2/erase.c
53381@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
53382 struct jffs2_unknown_node marker = {
53383 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
53384 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53385- .totlen = cpu_to_je32(c->cleanmarker_size)
53386+ .totlen = cpu_to_je32(c->cleanmarker_size),
53387+ .hdr_crc = cpu_to_je32(0)
53388 };
53389
53390 jffs2_prealloc_raw_node_refs(c, jeb, 1);
53391diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
53392index a6597d6..41b30ec 100644
53393--- a/fs/jffs2/wbuf.c
53394+++ b/fs/jffs2/wbuf.c
53395@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
53396 {
53397 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
53398 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53399- .totlen = constant_cpu_to_je32(8)
53400+ .totlen = constant_cpu_to_je32(8),
53401+ .hdr_crc = constant_cpu_to_je32(0)
53402 };
53403
53404 /*
53405diff --git a/fs/jfs/super.c b/fs/jfs/super.c
53406index 788e0a9..8433098 100644
53407--- a/fs/jfs/super.c
53408+++ b/fs/jfs/super.c
53409@@ -878,7 +878,7 @@ static int __init init_jfs_fs(void)
53410
53411 jfs_inode_cachep =
53412 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
53413- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
53414+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
53415 init_once);
53416 if (jfs_inode_cachep == NULL)
53417 return -ENOMEM;
53418diff --git a/fs/libfs.c b/fs/libfs.c
53419index 916da8c..1588998 100644
53420--- a/fs/libfs.c
53421+++ b/fs/libfs.c
53422@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53423
53424 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
53425 struct dentry *next;
53426+ char d_name[sizeof(next->d_iname)];
53427+ const unsigned char *name;
53428+
53429 next = list_entry(p, struct dentry, d_u.d_child);
53430 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
53431 if (!simple_positive(next)) {
53432@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53433
53434 spin_unlock(&next->d_lock);
53435 spin_unlock(&dentry->d_lock);
53436- if (filldir(dirent, next->d_name.name,
53437+ name = next->d_name.name;
53438+ if (name == next->d_iname) {
53439+ memcpy(d_name, name, next->d_name.len);
53440+ name = d_name;
53441+ }
53442+ if (filldir(dirent, name,
53443 next->d_name.len, filp->f_pos,
53444 next->d_inode->i_ino,
53445 dt_type(next->d_inode)) < 0)
53446diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
53447index 9760ecb..9b838ef 100644
53448--- a/fs/lockd/clntproc.c
53449+++ b/fs/lockd/clntproc.c
53450@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
53451 /*
53452 * Cookie counter for NLM requests
53453 */
53454-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
53455+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
53456
53457 void nlmclnt_next_cookie(struct nlm_cookie *c)
53458 {
53459- u32 cookie = atomic_inc_return(&nlm_cookie);
53460+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
53461
53462 memcpy(c->data, &cookie, 4);
53463 c->len=4;
53464diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
53465index a2aa97d..10d6c41 100644
53466--- a/fs/lockd/svc.c
53467+++ b/fs/lockd/svc.c
53468@@ -305,7 +305,7 @@ static int lockd_start_svc(struct svc_serv *serv)
53469 svc_sock_update_bufs(serv);
53470 serv->sv_maxconn = nlm_max_connections;
53471
53472- nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name);
53473+ nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, "%s", serv->sv_name);
53474 if (IS_ERR(nlmsvc_task)) {
53475 error = PTR_ERR(nlmsvc_task);
53476 printk(KERN_WARNING
53477diff --git a/fs/locks.c b/fs/locks.c
53478index cb424a4..850e4dd 100644
53479--- a/fs/locks.c
53480+++ b/fs/locks.c
53481@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
53482 return;
53483
53484 if (filp->f_op && filp->f_op->flock) {
53485- struct file_lock fl = {
53486+ struct file_lock flock = {
53487 .fl_pid = current->tgid,
53488 .fl_file = filp,
53489 .fl_flags = FL_FLOCK,
53490 .fl_type = F_UNLCK,
53491 .fl_end = OFFSET_MAX,
53492 };
53493- filp->f_op->flock(filp, F_SETLKW, &fl);
53494- if (fl.fl_ops && fl.fl_ops->fl_release_private)
53495- fl.fl_ops->fl_release_private(&fl);
53496+ filp->f_op->flock(filp, F_SETLKW, &flock);
53497+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
53498+ flock.fl_ops->fl_release_private(&flock);
53499 }
53500
53501 lock_flocks();
53502diff --git a/fs/namei.c b/fs/namei.c
53503index 9ed9361..2b72db1 100644
53504--- a/fs/namei.c
53505+++ b/fs/namei.c
53506@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
53507 if (ret != -EACCES)
53508 return ret;
53509
53510+#ifdef CONFIG_GRKERNSEC
53511+ /* we'll block if we have to log due to a denied capability use */
53512+ if (mask & MAY_NOT_BLOCK)
53513+ return -ECHILD;
53514+#endif
53515+
53516 if (S_ISDIR(inode->i_mode)) {
53517 /* DACs are overridable for directories */
53518- if (inode_capable(inode, CAP_DAC_OVERRIDE))
53519- return 0;
53520 if (!(mask & MAY_WRITE))
53521- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53522+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53523+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53524 return 0;
53525+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
53526+ return 0;
53527 return -EACCES;
53528 }
53529 /*
53530+ * Searching includes executable on directories, else just read.
53531+ */
53532+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53533+ if (mask == MAY_READ)
53534+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53535+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53536+ return 0;
53537+
53538+ /*
53539 * Read/write DACs are always overridable.
53540 * Executable DACs are overridable when there is
53541 * at least one exec bit set.
53542@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
53543 if (inode_capable(inode, CAP_DAC_OVERRIDE))
53544 return 0;
53545
53546- /*
53547- * Searching includes executable on directories, else just read.
53548- */
53549- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53550- if (mask == MAY_READ)
53551- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53552- return 0;
53553-
53554 return -EACCES;
53555 }
53556
53557@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53558 {
53559 struct dentry *dentry = link->dentry;
53560 int error;
53561- char *s;
53562+ const char *s;
53563
53564 BUG_ON(nd->flags & LOOKUP_RCU);
53565
53566@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53567 if (error)
53568 goto out_put_nd_path;
53569
53570+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53571+ dentry->d_inode, dentry, nd->path.mnt)) {
53572+ error = -EACCES;
53573+ goto out_put_nd_path;
53574+ }
53575+
53576 nd->last_type = LAST_BIND;
53577 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53578 error = PTR_ERR(*p);
53579@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53580 if (res)
53581 break;
53582 res = walk_component(nd, path, LOOKUP_FOLLOW);
53583+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53584+ res = -EACCES;
53585 put_link(nd, &link, cookie);
53586 } while (res > 0);
53587
53588@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
53589 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53590 {
53591 unsigned long a, b, adata, bdata, mask, hash, len;
53592- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53593+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53594
53595 hash = a = 0;
53596 len = -sizeof(unsigned long);
53597@@ -1968,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
53598 if (err)
53599 break;
53600 err = lookup_last(nd, &path);
53601+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53602+ err = -EACCES;
53603 put_link(nd, &link, cookie);
53604 }
53605 }
53606@@ -1975,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
53607 if (!err)
53608 err = complete_walk(nd);
53609
53610+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53611+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53612+ path_put(&nd->path);
53613+ err = -ENOENT;
53614+ }
53615+ }
53616+
53617 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53618 if (!can_lookup(nd->inode)) {
53619 path_put(&nd->path);
53620@@ -2002,8 +2027,15 @@ static int filename_lookup(int dfd, struct filename *name,
53621 retval = path_lookupat(dfd, name->name,
53622 flags | LOOKUP_REVAL, nd);
53623
53624- if (likely(!retval))
53625+ if (likely(!retval)) {
53626 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53627+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53628+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53629+ path_put(&nd->path);
53630+ return -ENOENT;
53631+ }
53632+ }
53633+ }
53634 return retval;
53635 }
53636
53637@@ -2381,6 +2413,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53638 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53639 return -EPERM;
53640
53641+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53642+ return -EPERM;
53643+ if (gr_handle_rawio(inode))
53644+ return -EPERM;
53645+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53646+ return -EACCES;
53647+
53648 return 0;
53649 }
53650
53651@@ -2602,7 +2641,7 @@ looked_up:
53652 * cleared otherwise prior to returning.
53653 */
53654 static int lookup_open(struct nameidata *nd, struct path *path,
53655- struct file *file,
53656+ struct path *link, struct file *file,
53657 const struct open_flags *op,
53658 bool got_write, int *opened)
53659 {
53660@@ -2637,6 +2676,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53661 /* Negative dentry, just create the file */
53662 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53663 umode_t mode = op->mode;
53664+
53665+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53666+ error = -EACCES;
53667+ goto out_dput;
53668+ }
53669+
53670+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53671+ error = -EACCES;
53672+ goto out_dput;
53673+ }
53674+
53675 if (!IS_POSIXACL(dir->d_inode))
53676 mode &= ~current_umask();
53677 /*
53678@@ -2658,6 +2708,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53679 nd->flags & LOOKUP_EXCL);
53680 if (error)
53681 goto out_dput;
53682+ else
53683+ gr_handle_create(dentry, nd->path.mnt);
53684 }
53685 out_no_open:
53686 path->dentry = dentry;
53687@@ -2672,7 +2724,7 @@ out_dput:
53688 /*
53689 * Handle the last step of open()
53690 */
53691-static int do_last(struct nameidata *nd, struct path *path,
53692+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53693 struct file *file, const struct open_flags *op,
53694 int *opened, struct filename *name)
53695 {
53696@@ -2701,16 +2753,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53697 error = complete_walk(nd);
53698 if (error)
53699 return error;
53700+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53701+ error = -ENOENT;
53702+ goto out;
53703+ }
53704 audit_inode(name, nd->path.dentry, 0);
53705 if (open_flag & O_CREAT) {
53706 error = -EISDIR;
53707 goto out;
53708 }
53709+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53710+ error = -EACCES;
53711+ goto out;
53712+ }
53713 goto finish_open;
53714 case LAST_BIND:
53715 error = complete_walk(nd);
53716 if (error)
53717 return error;
53718+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53719+ error = -ENOENT;
53720+ goto out;
53721+ }
53722+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53723+ error = -EACCES;
53724+ goto out;
53725+ }
53726 audit_inode(name, dir, 0);
53727 goto finish_open;
53728 }
53729@@ -2759,7 +2827,7 @@ retry_lookup:
53730 */
53731 }
53732 mutex_lock(&dir->d_inode->i_mutex);
53733- error = lookup_open(nd, path, file, op, got_write, opened);
53734+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53735 mutex_unlock(&dir->d_inode->i_mutex);
53736
53737 if (error <= 0) {
53738@@ -2783,11 +2851,28 @@ retry_lookup:
53739 goto finish_open_created;
53740 }
53741
53742+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53743+ error = -ENOENT;
53744+ goto exit_dput;
53745+ }
53746+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53747+ error = -EACCES;
53748+ goto exit_dput;
53749+ }
53750+
53751 /*
53752 * create/update audit record if it already exists.
53753 */
53754- if (path->dentry->d_inode)
53755+ if (path->dentry->d_inode) {
53756+ /* only check if O_CREAT is specified, all other checks need to go
53757+ into may_open */
53758+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53759+ error = -EACCES;
53760+ goto exit_dput;
53761+ }
53762+
53763 audit_inode(name, path->dentry, 0);
53764+ }
53765
53766 /*
53767 * If atomic_open() acquired write access it is dropped now due to
53768@@ -2828,6 +2913,11 @@ finish_lookup:
53769 }
53770 }
53771 BUG_ON(inode != path->dentry->d_inode);
53772+ /* if we're resolving a symlink to another symlink */
53773+ if (link && gr_handle_symlink_owner(link, inode)) {
53774+ error = -EACCES;
53775+ goto out;
53776+ }
53777 return 1;
53778 }
53779
53780@@ -2837,7 +2927,6 @@ finish_lookup:
53781 save_parent.dentry = nd->path.dentry;
53782 save_parent.mnt = mntget(path->mnt);
53783 nd->path.dentry = path->dentry;
53784-
53785 }
53786 nd->inode = inode;
53787 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53788@@ -2846,6 +2935,16 @@ finish_lookup:
53789 path_put(&save_parent);
53790 return error;
53791 }
53792+
53793+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53794+ error = -ENOENT;
53795+ goto out;
53796+ }
53797+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53798+ error = -EACCES;
53799+ goto out;
53800+ }
53801+
53802 error = -EISDIR;
53803 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53804 goto out;
53805@@ -2944,7 +3043,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53806 if (unlikely(error))
53807 goto out;
53808
53809- error = do_last(nd, &path, file, op, &opened, pathname);
53810+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53811 while (unlikely(error > 0)) { /* trailing symlink */
53812 struct path link = path;
53813 void *cookie;
53814@@ -2962,7 +3061,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53815 error = follow_link(&link, nd, &cookie);
53816 if (unlikely(error))
53817 break;
53818- error = do_last(nd, &path, file, op, &opened, pathname);
53819+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53820 put_link(nd, &link, cookie);
53821 }
53822 out:
53823@@ -3062,8 +3161,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53824 goto unlock;
53825
53826 error = -EEXIST;
53827- if (dentry->d_inode)
53828+ if (dentry->d_inode) {
53829+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53830+ error = -ENOENT;
53831+ }
53832 goto fail;
53833+ }
53834 /*
53835 * Special case - lookup gave negative, but... we had foo/bar/
53836 * From the vfs_mknod() POV we just have a negative dentry -
53837@@ -3115,6 +3218,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53838 }
53839 EXPORT_SYMBOL(user_path_create);
53840
53841+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53842+{
53843+ struct filename *tmp = getname(pathname);
53844+ struct dentry *res;
53845+ if (IS_ERR(tmp))
53846+ return ERR_CAST(tmp);
53847+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53848+ if (IS_ERR(res))
53849+ putname(tmp);
53850+ else
53851+ *to = tmp;
53852+ return res;
53853+}
53854+
53855 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53856 {
53857 int error = may_create(dir, dentry);
53858@@ -3177,6 +3294,17 @@ retry:
53859
53860 if (!IS_POSIXACL(path.dentry->d_inode))
53861 mode &= ~current_umask();
53862+
53863+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
53864+ error = -EPERM;
53865+ goto out;
53866+ }
53867+
53868+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
53869+ error = -EACCES;
53870+ goto out;
53871+ }
53872+
53873 error = security_path_mknod(&path, dentry, mode, dev);
53874 if (error)
53875 goto out;
53876@@ -3193,6 +3321,8 @@ retry:
53877 break;
53878 }
53879 out:
53880+ if (!error)
53881+ gr_handle_create(dentry, path.mnt);
53882 done_path_create(&path, dentry);
53883 if (retry_estale(error, lookup_flags)) {
53884 lookup_flags |= LOOKUP_REVAL;
53885@@ -3245,9 +3375,16 @@ retry:
53886
53887 if (!IS_POSIXACL(path.dentry->d_inode))
53888 mode &= ~current_umask();
53889+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
53890+ error = -EACCES;
53891+ goto out;
53892+ }
53893 error = security_path_mkdir(&path, dentry, mode);
53894 if (!error)
53895 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
53896+ if (!error)
53897+ gr_handle_create(dentry, path.mnt);
53898+out:
53899 done_path_create(&path, dentry);
53900 if (retry_estale(error, lookup_flags)) {
53901 lookup_flags |= LOOKUP_REVAL;
53902@@ -3328,6 +3465,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
53903 struct filename *name;
53904 struct dentry *dentry;
53905 struct nameidata nd;
53906+ ino_t saved_ino = 0;
53907+ dev_t saved_dev = 0;
53908 unsigned int lookup_flags = 0;
53909 retry:
53910 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53911@@ -3360,10 +3499,21 @@ retry:
53912 error = -ENOENT;
53913 goto exit3;
53914 }
53915+
53916+ saved_ino = dentry->d_inode->i_ino;
53917+ saved_dev = gr_get_dev_from_dentry(dentry);
53918+
53919+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
53920+ error = -EACCES;
53921+ goto exit3;
53922+ }
53923+
53924 error = security_path_rmdir(&nd.path, dentry);
53925 if (error)
53926 goto exit3;
53927 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
53928+ if (!error && (saved_dev || saved_ino))
53929+ gr_handle_delete(saved_ino, saved_dev);
53930 exit3:
53931 dput(dentry);
53932 exit2:
53933@@ -3429,6 +3579,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
53934 struct dentry *dentry;
53935 struct nameidata nd;
53936 struct inode *inode = NULL;
53937+ ino_t saved_ino = 0;
53938+ dev_t saved_dev = 0;
53939 unsigned int lookup_flags = 0;
53940 retry:
53941 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53942@@ -3455,10 +3607,22 @@ retry:
53943 if (!inode)
53944 goto slashes;
53945 ihold(inode);
53946+
53947+ if (inode->i_nlink <= 1) {
53948+ saved_ino = inode->i_ino;
53949+ saved_dev = gr_get_dev_from_dentry(dentry);
53950+ }
53951+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
53952+ error = -EACCES;
53953+ goto exit2;
53954+ }
53955+
53956 error = security_path_unlink(&nd.path, dentry);
53957 if (error)
53958 goto exit2;
53959 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
53960+ if (!error && (saved_ino || saved_dev))
53961+ gr_handle_delete(saved_ino, saved_dev);
53962 exit2:
53963 dput(dentry);
53964 }
53965@@ -3536,9 +3700,17 @@ retry:
53966 if (IS_ERR(dentry))
53967 goto out_putname;
53968
53969+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
53970+ error = -EACCES;
53971+ goto out;
53972+ }
53973+
53974 error = security_path_symlink(&path, dentry, from->name);
53975 if (!error)
53976 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
53977+ if (!error)
53978+ gr_handle_create(dentry, path.mnt);
53979+out:
53980 done_path_create(&path, dentry);
53981 if (retry_estale(error, lookup_flags)) {
53982 lookup_flags |= LOOKUP_REVAL;
53983@@ -3612,6 +3784,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
53984 {
53985 struct dentry *new_dentry;
53986 struct path old_path, new_path;
53987+ struct filename *to = NULL;
53988 int how = 0;
53989 int error;
53990
53991@@ -3635,7 +3808,7 @@ retry:
53992 if (error)
53993 return error;
53994
53995- new_dentry = user_path_create(newdfd, newname, &new_path,
53996+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
53997 (how & LOOKUP_REVAL));
53998 error = PTR_ERR(new_dentry);
53999 if (IS_ERR(new_dentry))
54000@@ -3647,11 +3820,28 @@ retry:
54001 error = may_linkat(&old_path);
54002 if (unlikely(error))
54003 goto out_dput;
54004+
54005+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
54006+ old_path.dentry->d_inode,
54007+ old_path.dentry->d_inode->i_mode, to)) {
54008+ error = -EACCES;
54009+ goto out_dput;
54010+ }
54011+
54012+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
54013+ old_path.dentry, old_path.mnt, to)) {
54014+ error = -EACCES;
54015+ goto out_dput;
54016+ }
54017+
54018 error = security_path_link(old_path.dentry, &new_path, new_dentry);
54019 if (error)
54020 goto out_dput;
54021 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
54022+ if (!error)
54023+ gr_handle_create(new_dentry, new_path.mnt);
54024 out_dput:
54025+ putname(to);
54026 done_path_create(&new_path, new_dentry);
54027 if (retry_estale(error, how)) {
54028 how |= LOOKUP_REVAL;
54029@@ -3897,12 +4087,21 @@ retry:
54030 if (new_dentry == trap)
54031 goto exit5;
54032
54033+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
54034+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
54035+ to);
54036+ if (error)
54037+ goto exit5;
54038+
54039 error = security_path_rename(&oldnd.path, old_dentry,
54040 &newnd.path, new_dentry);
54041 if (error)
54042 goto exit5;
54043 error = vfs_rename(old_dir->d_inode, old_dentry,
54044 new_dir->d_inode, new_dentry);
54045+ if (!error)
54046+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
54047+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
54048 exit5:
54049 dput(new_dentry);
54050 exit4:
54051@@ -3934,6 +4133,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
54052
54053 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
54054 {
54055+ char tmpbuf[64];
54056+ const char *newlink;
54057 int len;
54058
54059 len = PTR_ERR(link);
54060@@ -3943,7 +4144,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
54061 len = strlen(link);
54062 if (len > (unsigned) buflen)
54063 len = buflen;
54064- if (copy_to_user(buffer, link, len))
54065+
54066+ if (len < sizeof(tmpbuf)) {
54067+ memcpy(tmpbuf, link, len);
54068+ newlink = tmpbuf;
54069+ } else
54070+ newlink = link;
54071+
54072+ if (copy_to_user(buffer, newlink, len))
54073 len = -EFAULT;
54074 out:
54075 return len;
54076diff --git a/fs/namespace.c b/fs/namespace.c
54077index 7b1ca9b..6faeccf 100644
54078--- a/fs/namespace.c
54079+++ b/fs/namespace.c
54080@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
54081 if (!(sb->s_flags & MS_RDONLY))
54082 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
54083 up_write(&sb->s_umount);
54084+
54085+ gr_log_remount(mnt->mnt_devname, retval);
54086+
54087 return retval;
54088 }
54089
54090@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
54091 }
54092 br_write_unlock(&vfsmount_lock);
54093 namespace_unlock();
54094+
54095+ gr_log_unmount(mnt->mnt_devname, retval);
54096+
54097 return retval;
54098 }
54099
54100@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
54101 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
54102 */
54103
54104-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
54105+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
54106 {
54107 struct path path;
54108 struct mount *mnt;
54109@@ -1342,7 +1348,7 @@ out:
54110 /*
54111 * The 2.0 compatible umount. No flags.
54112 */
54113-SYSCALL_DEFINE1(oldumount, char __user *, name)
54114+SYSCALL_DEFINE1(oldumount, const char __user *, name)
54115 {
54116 return sys_umount(name, 0);
54117 }
54118@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
54119 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
54120 MS_STRICTATIME);
54121
54122+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
54123+ retval = -EPERM;
54124+ goto dput_out;
54125+ }
54126+
54127+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
54128+ retval = -EPERM;
54129+ goto dput_out;
54130+ }
54131+
54132 if (flags & MS_REMOUNT)
54133 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
54134 data_page);
54135@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
54136 dev_name, data_page);
54137 dput_out:
54138 path_put(&path);
54139+
54140+ gr_log_mount(dev_name, dir_name, retval);
54141+
54142 return retval;
54143 }
54144
54145@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
54146 }
54147 EXPORT_SYMBOL(mount_subtree);
54148
54149-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
54150- char __user *, type, unsigned long, flags, void __user *, data)
54151+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
54152+ const char __user *, type, unsigned long, flags, void __user *, data)
54153 {
54154 int ret;
54155 char *kernel_type;
54156@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
54157 if (error)
54158 goto out2;
54159
54160+ if (gr_handle_chroot_pivot()) {
54161+ error = -EPERM;
54162+ goto out2;
54163+ }
54164+
54165 get_fs_root(current->fs, &root);
54166 old_mp = lock_mount(&old);
54167 error = PTR_ERR(old_mp);
54168@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
54169 !nsown_capable(CAP_SYS_ADMIN))
54170 return -EPERM;
54171
54172- if (fs->users != 1)
54173+ if (atomic_read(&fs->users) != 1)
54174 return -EINVAL;
54175
54176 get_mnt_ns(mnt_ns);
54177diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
54178index cff089a..4c3d57a 100644
54179--- a/fs/nfs/callback.c
54180+++ b/fs/nfs/callback.c
54181@@ -211,7 +211,6 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
54182 struct svc_rqst *rqstp;
54183 int (*callback_svc)(void *vrqstp);
54184 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
54185- char svc_name[12];
54186 int ret;
54187
54188 nfs_callback_bc_serv(minorversion, xprt, serv);
54189@@ -235,10 +234,9 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
54190
54191 svc_sock_update_bufs(serv);
54192
54193- sprintf(svc_name, "nfsv4.%u-svc", minorversion);
54194 cb_info->serv = serv;
54195 cb_info->rqst = rqstp;
54196- cb_info->task = kthread_run(callback_svc, cb_info->rqst, svc_name);
54197+ cb_info->task = kthread_run(callback_svc, cb_info->rqst, "nfsv4.%u-svc", minorversion);
54198 if (IS_ERR(cb_info->task)) {
54199 ret = PTR_ERR(cb_info->task);
54200 svc_exit_thread(cb_info->rqst);
54201diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
54202index a35582c..ebbdcd5 100644
54203--- a/fs/nfs/callback_xdr.c
54204+++ b/fs/nfs/callback_xdr.c
54205@@ -51,7 +51,7 @@ struct callback_op {
54206 callback_decode_arg_t decode_args;
54207 callback_encode_res_t encode_res;
54208 long res_maxsize;
54209-};
54210+} __do_const;
54211
54212 static struct callback_op callback_ops[];
54213
54214diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
54215index c1c7a9d..7afa0b8 100644
54216--- a/fs/nfs/inode.c
54217+++ b/fs/nfs/inode.c
54218@@ -1043,16 +1043,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
54219 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
54220 }
54221
54222-static atomic_long_t nfs_attr_generation_counter;
54223+static atomic_long_unchecked_t nfs_attr_generation_counter;
54224
54225 static unsigned long nfs_read_attr_generation_counter(void)
54226 {
54227- return atomic_long_read(&nfs_attr_generation_counter);
54228+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
54229 }
54230
54231 unsigned long nfs_inc_attr_generation_counter(void)
54232 {
54233- return atomic_long_inc_return(&nfs_attr_generation_counter);
54234+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
54235 }
54236
54237 void nfs_fattr_init(struct nfs_fattr *fattr)
54238diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
54239index 2c37442..9b9538b 100644
54240--- a/fs/nfs/nfs4state.c
54241+++ b/fs/nfs/nfs4state.c
54242@@ -1193,7 +1193,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp)
54243 snprintf(buf, sizeof(buf), "%s-manager",
54244 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
54245 rcu_read_unlock();
54246- task = kthread_run(nfs4_run_state_manager, clp, buf);
54247+ task = kthread_run(nfs4_run_state_manager, clp, "%s", buf);
54248 if (IS_ERR(task)) {
54249 printk(KERN_ERR "%s: kthread_run: %ld\n",
54250 __func__, PTR_ERR(task));
54251diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
54252index 27d74a2..c4c2a73 100644
54253--- a/fs/nfsd/nfs4proc.c
54254+++ b/fs/nfsd/nfs4proc.c
54255@@ -1126,7 +1126,7 @@ struct nfsd4_operation {
54256 nfsd4op_rsize op_rsize_bop;
54257 stateid_getter op_get_currentstateid;
54258 stateid_setter op_set_currentstateid;
54259-};
54260+} __do_const;
54261
54262 static struct nfsd4_operation nfsd4_ops[];
54263
54264diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
54265index 582321a..0224663 100644
54266--- a/fs/nfsd/nfs4xdr.c
54267+++ b/fs/nfsd/nfs4xdr.c
54268@@ -1458,7 +1458,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
54269
54270 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
54271
54272-static nfsd4_dec nfsd4_dec_ops[] = {
54273+static const nfsd4_dec nfsd4_dec_ops[] = {
54274 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54275 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54276 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54277@@ -1498,7 +1498,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
54278 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
54279 };
54280
54281-static nfsd4_dec nfsd41_dec_ops[] = {
54282+static const nfsd4_dec nfsd41_dec_ops[] = {
54283 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54284 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54285 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54286@@ -1560,7 +1560,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
54287 };
54288
54289 struct nfsd4_minorversion_ops {
54290- nfsd4_dec *decoders;
54291+ const nfsd4_dec *decoders;
54292 int nops;
54293 };
54294
54295diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
54296index e76244e..9fe8f2f1 100644
54297--- a/fs/nfsd/nfscache.c
54298+++ b/fs/nfsd/nfscache.c
54299@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
54300 {
54301 struct svc_cacherep *rp = rqstp->rq_cacherep;
54302 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
54303- int len;
54304+ long len;
54305 size_t bufsize = 0;
54306
54307 if (!rp)
54308 return;
54309
54310- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
54311- len >>= 2;
54312+ if (statp) {
54313+ len = (char*)statp - (char*)resv->iov_base;
54314+ len = resv->iov_len - len;
54315+ len >>= 2;
54316+ }
54317
54318 /* Don't cache excessive amounts of data and XDR failures */
54319 if (!statp || len > (256 >> 2)) {
54320diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
54321index 84ce601..633d226 100644
54322--- a/fs/nfsd/vfs.c
54323+++ b/fs/nfsd/vfs.c
54324@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54325 } else {
54326 oldfs = get_fs();
54327 set_fs(KERNEL_DS);
54328- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
54329+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
54330 set_fs(oldfs);
54331 }
54332
54333@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54334
54335 /* Write the data. */
54336 oldfs = get_fs(); set_fs(KERNEL_DS);
54337- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
54338+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
54339 set_fs(oldfs);
54340 if (host_err < 0)
54341 goto out_nfserr;
54342@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
54343 */
54344
54345 oldfs = get_fs(); set_fs(KERNEL_DS);
54346- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
54347+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
54348 set_fs(oldfs);
54349
54350 if (host_err < 0)
54351diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
54352index fea6bd5..8ee9d81 100644
54353--- a/fs/nls/nls_base.c
54354+++ b/fs/nls/nls_base.c
54355@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
54356
54357 int register_nls(struct nls_table * nls)
54358 {
54359- struct nls_table ** tmp = &tables;
54360+ struct nls_table *tmp = tables;
54361
54362 if (nls->next)
54363 return -EBUSY;
54364
54365 spin_lock(&nls_lock);
54366- while (*tmp) {
54367- if (nls == *tmp) {
54368+ while (tmp) {
54369+ if (nls == tmp) {
54370 spin_unlock(&nls_lock);
54371 return -EBUSY;
54372 }
54373- tmp = &(*tmp)->next;
54374+ tmp = tmp->next;
54375 }
54376- nls->next = tables;
54377+ pax_open_kernel();
54378+ *(struct nls_table **)&nls->next = tables;
54379+ pax_close_kernel();
54380 tables = nls;
54381 spin_unlock(&nls_lock);
54382 return 0;
54383@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
54384
54385 int unregister_nls(struct nls_table * nls)
54386 {
54387- struct nls_table ** tmp = &tables;
54388+ struct nls_table * const * tmp = &tables;
54389
54390 spin_lock(&nls_lock);
54391 while (*tmp) {
54392 if (nls == *tmp) {
54393- *tmp = nls->next;
54394+ pax_open_kernel();
54395+ *(struct nls_table **)tmp = nls->next;
54396+ pax_close_kernel();
54397 spin_unlock(&nls_lock);
54398 return 0;
54399 }
54400diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
54401index 7424929..35f6be5 100644
54402--- a/fs/nls/nls_euc-jp.c
54403+++ b/fs/nls/nls_euc-jp.c
54404@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
54405 p_nls = load_nls("cp932");
54406
54407 if (p_nls) {
54408- table.charset2upper = p_nls->charset2upper;
54409- table.charset2lower = p_nls->charset2lower;
54410+ pax_open_kernel();
54411+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54412+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54413+ pax_close_kernel();
54414 return register_nls(&table);
54415 }
54416
54417diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
54418index e7bc1d7..06bd4bb 100644
54419--- a/fs/nls/nls_koi8-ru.c
54420+++ b/fs/nls/nls_koi8-ru.c
54421@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
54422 p_nls = load_nls("koi8-u");
54423
54424 if (p_nls) {
54425- table.charset2upper = p_nls->charset2upper;
54426- table.charset2lower = p_nls->charset2lower;
54427+ pax_open_kernel();
54428+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54429+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54430+ pax_close_kernel();
54431 return register_nls(&table);
54432 }
54433
54434diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
54435index 6c80083..a1e6299 100644
54436--- a/fs/notify/fanotify/fanotify_user.c
54437+++ b/fs/notify/fanotify/fanotify_user.c
54438@@ -122,6 +122,7 @@ static int fill_event_metadata(struct fsnotify_group *group,
54439 metadata->event_len = FAN_EVENT_METADATA_LEN;
54440 metadata->metadata_len = FAN_EVENT_METADATA_LEN;
54441 metadata->vers = FANOTIFY_METADATA_VERSION;
54442+ metadata->reserved = 0;
54443 metadata->mask = event->mask & FAN_ALL_OUTGOING_EVENTS;
54444 metadata->pid = pid_vnr(event->tgid);
54445 if (unlikely(event->mask & FAN_Q_OVERFLOW))
54446@@ -252,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
54447
54448 fd = fanotify_event_metadata.fd;
54449 ret = -EFAULT;
54450- if (copy_to_user(buf, &fanotify_event_metadata,
54451- fanotify_event_metadata.event_len))
54452+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
54453+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
54454 goto out_close_fd;
54455
54456 ret = prepare_for_access_response(group, event, fd);
54457diff --git a/fs/notify/notification.c b/fs/notify/notification.c
54458index 7b51b05..5ea5ef6 100644
54459--- a/fs/notify/notification.c
54460+++ b/fs/notify/notification.c
54461@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
54462 * get set to 0 so it will never get 'freed'
54463 */
54464 static struct fsnotify_event *q_overflow_event;
54465-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54466+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54467
54468 /**
54469 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
54470@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54471 */
54472 u32 fsnotify_get_cookie(void)
54473 {
54474- return atomic_inc_return(&fsnotify_sync_cookie);
54475+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
54476 }
54477 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
54478
54479diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
54480index aa411c3..c260a84 100644
54481--- a/fs/ntfs/dir.c
54482+++ b/fs/ntfs/dir.c
54483@@ -1329,7 +1329,7 @@ find_next_index_buffer:
54484 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
54485 ~(s64)(ndir->itype.index.block_size - 1)));
54486 /* Bounds checks. */
54487- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54488+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54489 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
54490 "inode 0x%lx or driver bug.", vdir->i_ino);
54491 goto err_out;
54492diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
54493index c5670b8..01a3656 100644
54494--- a/fs/ntfs/file.c
54495+++ b/fs/ntfs/file.c
54496@@ -2241,6 +2241,6 @@ const struct inode_operations ntfs_file_inode_ops = {
54497 #endif /* NTFS_RW */
54498 };
54499
54500-const struct file_operations ntfs_empty_file_ops = {};
54501+const struct file_operations ntfs_empty_file_ops __read_only;
54502
54503-const struct inode_operations ntfs_empty_inode_ops = {};
54504+const struct inode_operations ntfs_empty_inode_ops __read_only;
54505diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
54506index aebeacd..0dcdd26 100644
54507--- a/fs/ocfs2/localalloc.c
54508+++ b/fs/ocfs2/localalloc.c
54509@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
54510 goto bail;
54511 }
54512
54513- atomic_inc(&osb->alloc_stats.moves);
54514+ atomic_inc_unchecked(&osb->alloc_stats.moves);
54515
54516 bail:
54517 if (handle)
54518diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
54519index d355e6e..578d905 100644
54520--- a/fs/ocfs2/ocfs2.h
54521+++ b/fs/ocfs2/ocfs2.h
54522@@ -235,11 +235,11 @@ enum ocfs2_vol_state
54523
54524 struct ocfs2_alloc_stats
54525 {
54526- atomic_t moves;
54527- atomic_t local_data;
54528- atomic_t bitmap_data;
54529- atomic_t bg_allocs;
54530- atomic_t bg_extends;
54531+ atomic_unchecked_t moves;
54532+ atomic_unchecked_t local_data;
54533+ atomic_unchecked_t bitmap_data;
54534+ atomic_unchecked_t bg_allocs;
54535+ atomic_unchecked_t bg_extends;
54536 };
54537
54538 enum ocfs2_local_alloc_state
54539diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
54540index b7e74b5..19c6536 100644
54541--- a/fs/ocfs2/suballoc.c
54542+++ b/fs/ocfs2/suballoc.c
54543@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
54544 mlog_errno(status);
54545 goto bail;
54546 }
54547- atomic_inc(&osb->alloc_stats.bg_extends);
54548+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
54549
54550 /* You should never ask for this much metadata */
54551 BUG_ON(bits_wanted >
54552@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
54553 mlog_errno(status);
54554 goto bail;
54555 }
54556- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54557+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54558
54559 *suballoc_loc = res.sr_bg_blkno;
54560 *suballoc_bit_start = res.sr_bit_offset;
54561@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
54562 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
54563 res->sr_bits);
54564
54565- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54566+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54567
54568 BUG_ON(res->sr_bits != 1);
54569
54570@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
54571 mlog_errno(status);
54572 goto bail;
54573 }
54574- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54575+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54576
54577 BUG_ON(res.sr_bits != 1);
54578
54579@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54580 cluster_start,
54581 num_clusters);
54582 if (!status)
54583- atomic_inc(&osb->alloc_stats.local_data);
54584+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
54585 } else {
54586 if (min_clusters > (osb->bitmap_cpg - 1)) {
54587 /* The only paths asking for contiguousness
54588@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54589 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
54590 res.sr_bg_blkno,
54591 res.sr_bit_offset);
54592- atomic_inc(&osb->alloc_stats.bitmap_data);
54593+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
54594 *num_clusters = res.sr_bits;
54595 }
54596 }
54597diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
54598index 01b8516..579c4df 100644
54599--- a/fs/ocfs2/super.c
54600+++ b/fs/ocfs2/super.c
54601@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
54602 "%10s => GlobalAllocs: %d LocalAllocs: %d "
54603 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
54604 "Stats",
54605- atomic_read(&osb->alloc_stats.bitmap_data),
54606- atomic_read(&osb->alloc_stats.local_data),
54607- atomic_read(&osb->alloc_stats.bg_allocs),
54608- atomic_read(&osb->alloc_stats.moves),
54609- atomic_read(&osb->alloc_stats.bg_extends));
54610+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
54611+ atomic_read_unchecked(&osb->alloc_stats.local_data),
54612+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
54613+ atomic_read_unchecked(&osb->alloc_stats.moves),
54614+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
54615
54616 out += snprintf(buf + out, len - out,
54617 "%10s => State: %u Descriptor: %llu Size: %u bits "
54618@@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
54619 spin_lock_init(&osb->osb_xattr_lock);
54620 ocfs2_init_steal_slots(osb);
54621
54622- atomic_set(&osb->alloc_stats.moves, 0);
54623- atomic_set(&osb->alloc_stats.local_data, 0);
54624- atomic_set(&osb->alloc_stats.bitmap_data, 0);
54625- atomic_set(&osb->alloc_stats.bg_allocs, 0);
54626- atomic_set(&osb->alloc_stats.bg_extends, 0);
54627+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
54628+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
54629+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
54630+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
54631+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
54632
54633 /* Copy the blockcheck stats from the superblock probe */
54634 osb->osb_ecc_stats = *stats;
54635diff --git a/fs/open.c b/fs/open.c
54636index 8c74100..4239c48 100644
54637--- a/fs/open.c
54638+++ b/fs/open.c
54639@@ -32,6 +32,8 @@
54640 #include <linux/dnotify.h>
54641 #include <linux/compat.h>
54642
54643+#define CREATE_TRACE_POINTS
54644+#include <trace/events/fs.h>
54645 #include "internal.h"
54646
54647 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54648@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
54649 error = locks_verify_truncate(inode, NULL, length);
54650 if (!error)
54651 error = security_path_truncate(path);
54652+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54653+ error = -EACCES;
54654 if (!error)
54655 error = do_truncate(path->dentry, length, 0, NULL);
54656
54657@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54658 error = locks_verify_truncate(inode, f.file, length);
54659 if (!error)
54660 error = security_path_truncate(&f.file->f_path);
54661+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54662+ error = -EACCES;
54663 if (!error)
54664 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54665 sb_end_write(inode->i_sb);
54666@@ -360,6 +366,9 @@ retry:
54667 if (__mnt_is_readonly(path.mnt))
54668 res = -EROFS;
54669
54670+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54671+ res = -EACCES;
54672+
54673 out_path_release:
54674 path_put(&path);
54675 if (retry_estale(res, lookup_flags)) {
54676@@ -391,6 +400,8 @@ retry:
54677 if (error)
54678 goto dput_and_out;
54679
54680+ gr_log_chdir(path.dentry, path.mnt);
54681+
54682 set_fs_pwd(current->fs, &path);
54683
54684 dput_and_out:
54685@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54686 goto out_putf;
54687
54688 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54689+
54690+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54691+ error = -EPERM;
54692+
54693+ if (!error)
54694+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54695+
54696 if (!error)
54697 set_fs_pwd(current->fs, &f.file->f_path);
54698 out_putf:
54699@@ -449,7 +467,13 @@ retry:
54700 if (error)
54701 goto dput_and_out;
54702
54703+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54704+ goto dput_and_out;
54705+
54706 set_fs_root(current->fs, &path);
54707+
54708+ gr_handle_chroot_chdir(&path);
54709+
54710 error = 0;
54711 dput_and_out:
54712 path_put(&path);
54713@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
54714 if (error)
54715 return error;
54716 mutex_lock(&inode->i_mutex);
54717+
54718+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54719+ error = -EACCES;
54720+ goto out_unlock;
54721+ }
54722+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54723+ error = -EACCES;
54724+ goto out_unlock;
54725+ }
54726+
54727 error = security_path_chmod(path, mode);
54728 if (error)
54729 goto out_unlock;
54730@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54731 uid = make_kuid(current_user_ns(), user);
54732 gid = make_kgid(current_user_ns(), group);
54733
54734+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54735+ return -EACCES;
54736+
54737 newattrs.ia_valid = ATTR_CTIME;
54738 if (user != (uid_t) -1) {
54739 if (!uid_valid(uid))
54740@@ -946,6 +983,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54741 } else {
54742 fsnotify_open(f);
54743 fd_install(fd, f);
54744+ trace_do_sys_open(tmp->name, flags, mode);
54745 }
54746 }
54747 putname(tmp);
54748diff --git a/fs/pipe.c b/fs/pipe.c
54749index d2c45e1..009fe1c 100644
54750--- a/fs/pipe.c
54751+++ b/fs/pipe.c
54752@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
54753
54754 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
54755 {
54756- if (pipe->files)
54757+ if (atomic_read(&pipe->files))
54758 mutex_lock_nested(&pipe->mutex, subclass);
54759 }
54760
54761@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
54762
54763 void pipe_unlock(struct pipe_inode_info *pipe)
54764 {
54765- if (pipe->files)
54766+ if (atomic_read(&pipe->files))
54767 mutex_unlock(&pipe->mutex);
54768 }
54769 EXPORT_SYMBOL(pipe_unlock);
54770@@ -449,9 +449,9 @@ redo:
54771 }
54772 if (bufs) /* More to do? */
54773 continue;
54774- if (!pipe->writers)
54775+ if (!atomic_read(&pipe->writers))
54776 break;
54777- if (!pipe->waiting_writers) {
54778+ if (!atomic_read(&pipe->waiting_writers)) {
54779 /* syscall merging: Usually we must not sleep
54780 * if O_NONBLOCK is set, or if we got some data.
54781 * But if a writer sleeps in kernel space, then
54782@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54783 ret = 0;
54784 __pipe_lock(pipe);
54785
54786- if (!pipe->readers) {
54787+ if (!atomic_read(&pipe->readers)) {
54788 send_sig(SIGPIPE, current, 0);
54789 ret = -EPIPE;
54790 goto out;
54791@@ -562,7 +562,7 @@ redo1:
54792 for (;;) {
54793 int bufs;
54794
54795- if (!pipe->readers) {
54796+ if (!atomic_read(&pipe->readers)) {
54797 send_sig(SIGPIPE, current, 0);
54798 if (!ret)
54799 ret = -EPIPE;
54800@@ -653,9 +653,9 @@ redo2:
54801 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54802 do_wakeup = 0;
54803 }
54804- pipe->waiting_writers++;
54805+ atomic_inc(&pipe->waiting_writers);
54806 pipe_wait(pipe);
54807- pipe->waiting_writers--;
54808+ atomic_dec(&pipe->waiting_writers);
54809 }
54810 out:
54811 __pipe_unlock(pipe);
54812@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54813 mask = 0;
54814 if (filp->f_mode & FMODE_READ) {
54815 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54816- if (!pipe->writers && filp->f_version != pipe->w_counter)
54817+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54818 mask |= POLLHUP;
54819 }
54820
54821@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54822 * Most Unices do not set POLLERR for FIFOs but on Linux they
54823 * behave exactly like pipes for poll().
54824 */
54825- if (!pipe->readers)
54826+ if (!atomic_read(&pipe->readers))
54827 mask |= POLLERR;
54828 }
54829
54830@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
54831
54832 __pipe_lock(pipe);
54833 if (file->f_mode & FMODE_READ)
54834- pipe->readers--;
54835+ atomic_dec(&pipe->readers);
54836 if (file->f_mode & FMODE_WRITE)
54837- pipe->writers--;
54838+ atomic_dec(&pipe->writers);
54839
54840- if (pipe->readers || pipe->writers) {
54841+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
54842 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54843 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54844 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
54845 }
54846 spin_lock(&inode->i_lock);
54847- if (!--pipe->files) {
54848+ if (atomic_dec_and_test(&pipe->files)) {
54849 inode->i_pipe = NULL;
54850 kill = 1;
54851 }
54852@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
54853 kfree(pipe);
54854 }
54855
54856-static struct vfsmount *pipe_mnt __read_mostly;
54857+struct vfsmount *pipe_mnt __read_mostly;
54858
54859 /*
54860 * pipefs_dname() is called from d_path().
54861@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
54862 goto fail_iput;
54863
54864 inode->i_pipe = pipe;
54865- pipe->files = 2;
54866- pipe->readers = pipe->writers = 1;
54867+ atomic_set(&pipe->files, 2);
54868+ atomic_set(&pipe->readers, 1);
54869+ atomic_set(&pipe->writers, 1);
54870 inode->i_fop = &pipefifo_fops;
54871
54872 /*
54873@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
54874 spin_lock(&inode->i_lock);
54875 if (inode->i_pipe) {
54876 pipe = inode->i_pipe;
54877- pipe->files++;
54878+ atomic_inc(&pipe->files);
54879 spin_unlock(&inode->i_lock);
54880 } else {
54881 spin_unlock(&inode->i_lock);
54882 pipe = alloc_pipe_info();
54883 if (!pipe)
54884 return -ENOMEM;
54885- pipe->files = 1;
54886+ atomic_set(&pipe->files, 1);
54887 spin_lock(&inode->i_lock);
54888 if (unlikely(inode->i_pipe)) {
54889- inode->i_pipe->files++;
54890+ atomic_inc(&inode->i_pipe->files);
54891 spin_unlock(&inode->i_lock);
54892 free_pipe_info(pipe);
54893 pipe = inode->i_pipe;
54894@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
54895 * opened, even when there is no process writing the FIFO.
54896 */
54897 pipe->r_counter++;
54898- if (pipe->readers++ == 0)
54899+ if (atomic_inc_return(&pipe->readers) == 1)
54900 wake_up_partner(pipe);
54901
54902- if (!is_pipe && !pipe->writers) {
54903+ if (!is_pipe && !atomic_read(&pipe->writers)) {
54904 if ((filp->f_flags & O_NONBLOCK)) {
54905 /* suppress POLLHUP until we have
54906 * seen a writer */
54907@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
54908 * errno=ENXIO when there is no process reading the FIFO.
54909 */
54910 ret = -ENXIO;
54911- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
54912+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
54913 goto err;
54914
54915 pipe->w_counter++;
54916- if (!pipe->writers++)
54917+ if (atomic_inc_return(&pipe->writers) == 1)
54918 wake_up_partner(pipe);
54919
54920- if (!is_pipe && !pipe->readers) {
54921+ if (!is_pipe && !atomic_read(&pipe->readers)) {
54922 if (wait_for_partner(pipe, &pipe->r_counter))
54923 goto err_wr;
54924 }
54925@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
54926 * the process can at least talk to itself.
54927 */
54928
54929- pipe->readers++;
54930- pipe->writers++;
54931+ atomic_inc(&pipe->readers);
54932+ atomic_inc(&pipe->writers);
54933 pipe->r_counter++;
54934 pipe->w_counter++;
54935- if (pipe->readers == 1 || pipe->writers == 1)
54936+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
54937 wake_up_partner(pipe);
54938 break;
54939
54940@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
54941 return 0;
54942
54943 err_rd:
54944- if (!--pipe->readers)
54945+ if (atomic_dec_and_test(&pipe->readers))
54946 wake_up_interruptible(&pipe->wait);
54947 ret = -ERESTARTSYS;
54948 goto err;
54949
54950 err_wr:
54951- if (!--pipe->writers)
54952+ if (atomic_dec_and_test(&pipe->writers))
54953 wake_up_interruptible(&pipe->wait);
54954 ret = -ERESTARTSYS;
54955 goto err;
54956
54957 err:
54958 spin_lock(&inode->i_lock);
54959- if (!--pipe->files) {
54960+ if (atomic_dec_and_test(&pipe->files)) {
54961 inode->i_pipe = NULL;
54962 kill = 1;
54963 }
54964diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54965index 15af622..0e9f4467 100644
54966--- a/fs/proc/Kconfig
54967+++ b/fs/proc/Kconfig
54968@@ -30,12 +30,12 @@ config PROC_FS
54969
54970 config PROC_KCORE
54971 bool "/proc/kcore support" if !ARM
54972- depends on PROC_FS && MMU
54973+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
54974
54975 config PROC_VMCORE
54976 bool "/proc/vmcore support"
54977- depends on PROC_FS && CRASH_DUMP
54978- default y
54979+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
54980+ default n
54981 help
54982 Exports the dump image of crashed kernel in ELF format.
54983
54984@@ -59,8 +59,8 @@ config PROC_SYSCTL
54985 limited in memory.
54986
54987 config PROC_PAGE_MONITOR
54988- default y
54989- depends on PROC_FS && MMU
54990+ default n
54991+ depends on PROC_FS && MMU && !GRKERNSEC
54992 bool "Enable /proc page monitoring" if EXPERT
54993 help
54994 Various /proc files exist to monitor process memory utilization:
54995diff --git a/fs/proc/array.c b/fs/proc/array.c
54996index cbd0f1b..adec3f0 100644
54997--- a/fs/proc/array.c
54998+++ b/fs/proc/array.c
54999@@ -60,6 +60,7 @@
55000 #include <linux/tty.h>
55001 #include <linux/string.h>
55002 #include <linux/mman.h>
55003+#include <linux/grsecurity.h>
55004 #include <linux/proc_fs.h>
55005 #include <linux/ioport.h>
55006 #include <linux/uaccess.h>
55007@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
55008 seq_putc(m, '\n');
55009 }
55010
55011+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55012+static inline void task_pax(struct seq_file *m, struct task_struct *p)
55013+{
55014+ if (p->mm)
55015+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
55016+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
55017+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
55018+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
55019+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
55020+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
55021+ else
55022+ seq_printf(m, "PaX:\t-----\n");
55023+}
55024+#endif
55025+
55026 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55027 struct pid *pid, struct task_struct *task)
55028 {
55029@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55030 task_cpus_allowed(m, task);
55031 cpuset_task_status_allowed(m, task);
55032 task_context_switch_counts(m, task);
55033+
55034+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55035+ task_pax(m, task);
55036+#endif
55037+
55038+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
55039+ task_grsec_rbac(m, task);
55040+#endif
55041+
55042 return 0;
55043 }
55044
55045+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55046+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55047+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55048+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55049+#endif
55050+
55051 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55052 struct pid *pid, struct task_struct *task, int whole)
55053 {
55054@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55055 char tcomm[sizeof(task->comm)];
55056 unsigned long flags;
55057
55058+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55059+ if (current->exec_id != m->exec_id) {
55060+ gr_log_badprocpid("stat");
55061+ return 0;
55062+ }
55063+#endif
55064+
55065 state = *get_task_state(task);
55066 vsize = eip = esp = 0;
55067 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55068@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55069 gtime = task_gtime(task);
55070 }
55071
55072+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55073+ if (PAX_RAND_FLAGS(mm)) {
55074+ eip = 0;
55075+ esp = 0;
55076+ wchan = 0;
55077+ }
55078+#endif
55079+#ifdef CONFIG_GRKERNSEC_HIDESYM
55080+ wchan = 0;
55081+ eip =0;
55082+ esp =0;
55083+#endif
55084+
55085 /* scale priority and nice values from timeslices to -20..20 */
55086 /* to make it look like a "normal" Unix priority/nice value */
55087 priority = task_prio(task);
55088@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55089 seq_put_decimal_ull(m, ' ', vsize);
55090 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
55091 seq_put_decimal_ull(m, ' ', rsslim);
55092+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55093+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
55094+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
55095+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
55096+#else
55097 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
55098 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
55099 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
55100+#endif
55101 seq_put_decimal_ull(m, ' ', esp);
55102 seq_put_decimal_ull(m, ' ', eip);
55103 /* The signal information here is obsolete.
55104@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55105 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
55106 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
55107
55108- if (mm && permitted) {
55109+ if (mm && permitted
55110+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55111+ && !PAX_RAND_FLAGS(mm)
55112+#endif
55113+ ) {
55114 seq_put_decimal_ull(m, ' ', mm->start_data);
55115 seq_put_decimal_ull(m, ' ', mm->end_data);
55116 seq_put_decimal_ull(m, ' ', mm->start_brk);
55117@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55118 struct pid *pid, struct task_struct *task)
55119 {
55120 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
55121- struct mm_struct *mm = get_task_mm(task);
55122+ struct mm_struct *mm;
55123
55124+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55125+ if (current->exec_id != m->exec_id) {
55126+ gr_log_badprocpid("statm");
55127+ return 0;
55128+ }
55129+#endif
55130+ mm = get_task_mm(task);
55131 if (mm) {
55132 size = task_statm(mm, &shared, &text, &data, &resident);
55133 mmput(mm);
55134@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55135 return 0;
55136 }
55137
55138+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55139+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
55140+{
55141+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
55142+}
55143+#endif
55144+
55145 #ifdef CONFIG_CHECKPOINT_RESTORE
55146 static struct pid *
55147 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
55148diff --git a/fs/proc/base.c b/fs/proc/base.c
55149index c3834da..b402b2b 100644
55150--- a/fs/proc/base.c
55151+++ b/fs/proc/base.c
55152@@ -113,6 +113,14 @@ struct pid_entry {
55153 union proc_op op;
55154 };
55155
55156+struct getdents_callback {
55157+ struct linux_dirent __user * current_dir;
55158+ struct linux_dirent __user * previous;
55159+ struct file * file;
55160+ int count;
55161+ int error;
55162+};
55163+
55164 #define NOD(NAME, MODE, IOP, FOP, OP) { \
55165 .name = (NAME), \
55166 .len = sizeof(NAME) - 1, \
55167@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
55168 if (!mm->arg_end)
55169 goto out_mm; /* Shh! No looking before we're done */
55170
55171+ if (gr_acl_handle_procpidmem(task))
55172+ goto out_mm;
55173+
55174 len = mm->arg_end - mm->arg_start;
55175
55176 if (len > PAGE_SIZE)
55177@@ -237,12 +248,28 @@ out:
55178 return res;
55179 }
55180
55181+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55182+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55183+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55184+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55185+#endif
55186+
55187 static int proc_pid_auxv(struct task_struct *task, char *buffer)
55188 {
55189 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
55190 int res = PTR_ERR(mm);
55191 if (mm && !IS_ERR(mm)) {
55192 unsigned int nwords = 0;
55193+
55194+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55195+ /* allow if we're currently ptracing this task */
55196+ if (PAX_RAND_FLAGS(mm) &&
55197+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
55198+ mmput(mm);
55199+ return 0;
55200+ }
55201+#endif
55202+
55203 do {
55204 nwords += 2;
55205 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
55206@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
55207 }
55208
55209
55210-#ifdef CONFIG_KALLSYMS
55211+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55212 /*
55213 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
55214 * Returns the resolved symbol. If that fails, simply return the address.
55215@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
55216 mutex_unlock(&task->signal->cred_guard_mutex);
55217 }
55218
55219-#ifdef CONFIG_STACKTRACE
55220+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55221
55222 #define MAX_STACK_TRACE_DEPTH 64
55223
55224@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
55225 return count;
55226 }
55227
55228-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55229+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55230 static int proc_pid_syscall(struct task_struct *task, char *buffer)
55231 {
55232 long nr;
55233@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
55234 /************************************************************************/
55235
55236 /* permission checks */
55237-static int proc_fd_access_allowed(struct inode *inode)
55238+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
55239 {
55240 struct task_struct *task;
55241 int allowed = 0;
55242@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
55243 */
55244 task = get_proc_task(inode);
55245 if (task) {
55246- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55247+ if (log)
55248+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55249+ else
55250+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55251 put_task_struct(task);
55252 }
55253 return allowed;
55254@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
55255 struct task_struct *task,
55256 int hide_pid_min)
55257 {
55258+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55259+ return false;
55260+
55261+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55262+ rcu_read_lock();
55263+ {
55264+ const struct cred *tmpcred = current_cred();
55265+ const struct cred *cred = __task_cred(task);
55266+
55267+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
55268+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55269+ || in_group_p(grsec_proc_gid)
55270+#endif
55271+ ) {
55272+ rcu_read_unlock();
55273+ return true;
55274+ }
55275+ }
55276+ rcu_read_unlock();
55277+
55278+ if (!pid->hide_pid)
55279+ return false;
55280+#endif
55281+
55282 if (pid->hide_pid < hide_pid_min)
55283 return true;
55284 if (in_group_p(pid->pid_gid))
55285 return true;
55286+
55287 return ptrace_may_access(task, PTRACE_MODE_READ);
55288 }
55289
55290@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
55291 put_task_struct(task);
55292
55293 if (!has_perms) {
55294+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55295+ {
55296+#else
55297 if (pid->hide_pid == 2) {
55298+#endif
55299 /*
55300 * Let's make getdents(), stat(), and open()
55301 * consistent with each other. If a process
55302@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55303 if (!task)
55304 return -ESRCH;
55305
55306+ if (gr_acl_handle_procpidmem(task)) {
55307+ put_task_struct(task);
55308+ return -EPERM;
55309+ }
55310+
55311 mm = mm_access(task, mode);
55312 put_task_struct(task);
55313
55314@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55315
55316 file->private_data = mm;
55317
55318+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55319+ file->f_version = current->exec_id;
55320+#endif
55321+
55322 return 0;
55323 }
55324
55325@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55326 ssize_t copied;
55327 char *page;
55328
55329+#ifdef CONFIG_GRKERNSEC
55330+ if (write)
55331+ return -EPERM;
55332+#endif
55333+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55334+ if (file->f_version != current->exec_id) {
55335+ gr_log_badprocpid("mem");
55336+ return 0;
55337+ }
55338+#endif
55339+
55340 if (!mm)
55341 return 0;
55342
55343@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55344 goto free;
55345
55346 while (count > 0) {
55347- int this_len = min_t(int, count, PAGE_SIZE);
55348+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
55349
55350 if (write && copy_from_user(page, buf, this_len)) {
55351 copied = -EFAULT;
55352@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55353 if (!mm)
55354 return 0;
55355
55356+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55357+ if (file->f_version != current->exec_id) {
55358+ gr_log_badprocpid("environ");
55359+ return 0;
55360+ }
55361+#endif
55362+
55363 page = (char *)__get_free_page(GFP_TEMPORARY);
55364 if (!page)
55365 return -ENOMEM;
55366@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55367 goto free;
55368 while (count > 0) {
55369 size_t this_len, max_len;
55370- int retval;
55371+ ssize_t retval;
55372
55373 if (src >= (mm->env_end - mm->env_start))
55374 break;
55375@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
55376 int error = -EACCES;
55377
55378 /* Are we allowed to snoop on the tasks file descriptors? */
55379- if (!proc_fd_access_allowed(inode))
55380+ if (!proc_fd_access_allowed(inode, 0))
55381 goto out;
55382
55383 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55384@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
55385 struct path path;
55386
55387 /* Are we allowed to snoop on the tasks file descriptors? */
55388- if (!proc_fd_access_allowed(inode))
55389- goto out;
55390+ /* logging this is needed for learning on chromium to work properly,
55391+ but we don't want to flood the logs from 'ps' which does a readlink
55392+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
55393+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
55394+ */
55395+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
55396+ if (!proc_fd_access_allowed(inode,0))
55397+ goto out;
55398+ } else {
55399+ if (!proc_fd_access_allowed(inode,1))
55400+ goto out;
55401+ }
55402
55403 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55404 if (error)
55405@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
55406 rcu_read_lock();
55407 cred = __task_cred(task);
55408 inode->i_uid = cred->euid;
55409+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55410+ inode->i_gid = grsec_proc_gid;
55411+#else
55412 inode->i_gid = cred->egid;
55413+#endif
55414 rcu_read_unlock();
55415 }
55416 security_task_to_inode(task, inode);
55417@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55418 return -ENOENT;
55419 }
55420 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55421+#ifdef CONFIG_GRKERNSEC_PROC_USER
55422+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55423+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55424+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55425+#endif
55426 task_dumpable(task)) {
55427 cred = __task_cred(task);
55428 stat->uid = cred->euid;
55429+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55430+ stat->gid = grsec_proc_gid;
55431+#else
55432 stat->gid = cred->egid;
55433+#endif
55434 }
55435 }
55436 rcu_read_unlock();
55437@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
55438
55439 if (task) {
55440 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55441+#ifdef CONFIG_GRKERNSEC_PROC_USER
55442+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55443+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55444+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55445+#endif
55446 task_dumpable(task)) {
55447 rcu_read_lock();
55448 cred = __task_cred(task);
55449 inode->i_uid = cred->euid;
55450+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55451+ inode->i_gid = grsec_proc_gid;
55452+#else
55453 inode->i_gid = cred->egid;
55454+#endif
55455 rcu_read_unlock();
55456 } else {
55457 inode->i_uid = GLOBAL_ROOT_UID;
55458@@ -2196,6 +2314,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
55459 if (!task)
55460 goto out_no_task;
55461
55462+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55463+ goto out;
55464+
55465 /*
55466 * Yes, it does not scale. And it should not. Don't add
55467 * new entries into /proc/<tgid>/ without very good reasons.
55468@@ -2240,6 +2361,9 @@ static int proc_pident_readdir(struct file *filp,
55469 if (!task)
55470 goto out_no_task;
55471
55472+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55473+ goto out;
55474+
55475 ret = 0;
55476 i = filp->f_pos;
55477 switch (i) {
55478@@ -2653,7 +2777,7 @@ static const struct pid_entry tgid_base_stuff[] = {
55479 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
55480 #endif
55481 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55482-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55483+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55484 INF("syscall", S_IRUGO, proc_pid_syscall),
55485 #endif
55486 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55487@@ -2678,10 +2802,10 @@ static const struct pid_entry tgid_base_stuff[] = {
55488 #ifdef CONFIG_SECURITY
55489 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55490 #endif
55491-#ifdef CONFIG_KALLSYMS
55492+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55493 INF("wchan", S_IRUGO, proc_pid_wchan),
55494 #endif
55495-#ifdef CONFIG_STACKTRACE
55496+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55497 ONE("stack", S_IRUGO, proc_pid_stack),
55498 #endif
55499 #ifdef CONFIG_SCHEDSTATS
55500@@ -2715,6 +2839,9 @@ static const struct pid_entry tgid_base_stuff[] = {
55501 #ifdef CONFIG_HARDWALL
55502 INF("hardwall", S_IRUGO, proc_pid_hardwall),
55503 #endif
55504+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55505+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
55506+#endif
55507 #ifdef CONFIG_USER_NS
55508 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
55509 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
55510@@ -2847,7 +2974,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
55511 if (!inode)
55512 goto out;
55513
55514+#ifdef CONFIG_GRKERNSEC_PROC_USER
55515+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
55516+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55517+ inode->i_gid = grsec_proc_gid;
55518+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
55519+#else
55520 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
55521+#endif
55522 inode->i_op = &proc_tgid_base_inode_operations;
55523 inode->i_fop = &proc_tgid_base_operations;
55524 inode->i_flags|=S_IMMUTABLE;
55525@@ -2885,7 +3019,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
55526 if (!task)
55527 goto out;
55528
55529+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55530+ goto out_put_task;
55531+
55532 result = proc_pid_instantiate(dir, dentry, task, NULL);
55533+out_put_task:
55534 put_task_struct(task);
55535 out:
55536 return result;
55537@@ -2948,6 +3086,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
55538 static int fake_filldir(void *buf, const char *name, int namelen,
55539 loff_t offset, u64 ino, unsigned d_type)
55540 {
55541+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
55542+ __buf->error = -EINVAL;
55543 return 0;
55544 }
55545
55546@@ -3007,7 +3147,7 @@ static const struct pid_entry tid_base_stuff[] = {
55547 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
55548 #endif
55549 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55550-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55551+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55552 INF("syscall", S_IRUGO, proc_pid_syscall),
55553 #endif
55554 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55555@@ -3034,10 +3174,10 @@ static const struct pid_entry tid_base_stuff[] = {
55556 #ifdef CONFIG_SECURITY
55557 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55558 #endif
55559-#ifdef CONFIG_KALLSYMS
55560+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55561 INF("wchan", S_IRUGO, proc_pid_wchan),
55562 #endif
55563-#ifdef CONFIG_STACKTRACE
55564+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55565 ONE("stack", S_IRUGO, proc_pid_stack),
55566 #endif
55567 #ifdef CONFIG_SCHEDSTATS
55568diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
55569index 82676e3..5f8518a 100644
55570--- a/fs/proc/cmdline.c
55571+++ b/fs/proc/cmdline.c
55572@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
55573
55574 static int __init proc_cmdline_init(void)
55575 {
55576+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55577+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
55578+#else
55579 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
55580+#endif
55581 return 0;
55582 }
55583 module_init(proc_cmdline_init);
55584diff --git a/fs/proc/devices.c b/fs/proc/devices.c
55585index b143471..bb105e5 100644
55586--- a/fs/proc/devices.c
55587+++ b/fs/proc/devices.c
55588@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
55589
55590 static int __init proc_devices_init(void)
55591 {
55592+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55593+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
55594+#else
55595 proc_create("devices", 0, NULL, &proc_devinfo_operations);
55596+#endif
55597 return 0;
55598 }
55599 module_init(proc_devices_init);
55600diff --git a/fs/proc/fd.c b/fs/proc/fd.c
55601index d7a4a28..0201742 100644
55602--- a/fs/proc/fd.c
55603+++ b/fs/proc/fd.c
55604@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
55605 if (!task)
55606 return -ENOENT;
55607
55608- files = get_files_struct(task);
55609+ if (!gr_acl_handle_procpidmem(task))
55610+ files = get_files_struct(task);
55611 put_task_struct(task);
55612
55613 if (files) {
55614@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
55615 */
55616 int proc_fd_permission(struct inode *inode, int mask)
55617 {
55618+ struct task_struct *task;
55619 int rv = generic_permission(inode, mask);
55620- if (rv == 0)
55621- return 0;
55622+
55623 if (task_pid(current) == proc_pid(inode))
55624 rv = 0;
55625+
55626+ task = get_proc_task(inode);
55627+ if (task == NULL)
55628+ return rv;
55629+
55630+ if (gr_acl_handle_procpidmem(task))
55631+ rv = -EACCES;
55632+
55633+ put_task_struct(task);
55634+
55635 return rv;
55636 }
55637
55638diff --git a/fs/proc/inode.c b/fs/proc/inode.c
55639index 073aea6..0630370 100644
55640--- a/fs/proc/inode.c
55641+++ b/fs/proc/inode.c
55642@@ -23,11 +23,17 @@
55643 #include <linux/slab.h>
55644 #include <linux/mount.h>
55645 #include <linux/magic.h>
55646+#include <linux/grsecurity.h>
55647
55648 #include <asm/uaccess.h>
55649
55650 #include "internal.h"
55651
55652+#ifdef CONFIG_PROC_SYSCTL
55653+extern const struct inode_operations proc_sys_inode_operations;
55654+extern const struct inode_operations proc_sys_dir_operations;
55655+#endif
55656+
55657 static void proc_evict_inode(struct inode *inode)
55658 {
55659 struct proc_dir_entry *de;
55660@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
55661 ns = PROC_I(inode)->ns.ns;
55662 if (ns_ops && ns)
55663 ns_ops->put(ns);
55664+
55665+#ifdef CONFIG_PROC_SYSCTL
55666+ if (inode->i_op == &proc_sys_inode_operations ||
55667+ inode->i_op == &proc_sys_dir_operations)
55668+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
55669+#endif
55670+
55671 }
55672
55673 static struct kmem_cache * proc_inode_cachep;
55674@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
55675 if (de->mode) {
55676 inode->i_mode = de->mode;
55677 inode->i_uid = de->uid;
55678+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55679+ inode->i_gid = grsec_proc_gid;
55680+#else
55681 inode->i_gid = de->gid;
55682+#endif
55683 }
55684 if (de->size)
55685 inode->i_size = de->size;
55686diff --git a/fs/proc/internal.h b/fs/proc/internal.h
55687index d600fb0..3b495fe 100644
55688--- a/fs/proc/internal.h
55689+++ b/fs/proc/internal.h
55690@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
55691 struct pid *, struct task_struct *);
55692 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
55693 struct pid *, struct task_struct *);
55694+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55695+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
55696+#endif
55697
55698 /*
55699 * base.c
55700diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
55701index 0a22194..a9fc8c1 100644
55702--- a/fs/proc/kcore.c
55703+++ b/fs/proc/kcore.c
55704@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55705 * the addresses in the elf_phdr on our list.
55706 */
55707 start = kc_offset_to_vaddr(*fpos - elf_buflen);
55708- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
55709+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
55710+ if (tsz > buflen)
55711 tsz = buflen;
55712-
55713+
55714 while (buflen) {
55715 struct kcore_list *m;
55716
55717@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55718 kfree(elf_buf);
55719 } else {
55720 if (kern_addr_valid(start)) {
55721- unsigned long n;
55722+ char *elf_buf;
55723+ mm_segment_t oldfs;
55724
55725- n = copy_to_user(buffer, (char *)start, tsz);
55726- /*
55727- * We cannot distinguish between fault on source
55728- * and fault on destination. When this happens
55729- * we clear too and hope it will trigger the
55730- * EFAULT again.
55731- */
55732- if (n) {
55733- if (clear_user(buffer + tsz - n,
55734- n))
55735+ elf_buf = kmalloc(tsz, GFP_KERNEL);
55736+ if (!elf_buf)
55737+ return -ENOMEM;
55738+ oldfs = get_fs();
55739+ set_fs(KERNEL_DS);
55740+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
55741+ set_fs(oldfs);
55742+ if (copy_to_user(buffer, elf_buf, tsz)) {
55743+ kfree(elf_buf);
55744 return -EFAULT;
55745+ }
55746 }
55747+ set_fs(oldfs);
55748+ kfree(elf_buf);
55749 } else {
55750 if (clear_user(buffer, tsz))
55751 return -EFAULT;
55752@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55753
55754 static int open_kcore(struct inode *inode, struct file *filp)
55755 {
55756+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55757+ return -EPERM;
55758+#endif
55759 if (!capable(CAP_SYS_RAWIO))
55760 return -EPERM;
55761 if (kcore_need_update)
55762diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55763index 5aa847a..f77c8d4 100644
55764--- a/fs/proc/meminfo.c
55765+++ b/fs/proc/meminfo.c
55766@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55767 vmi.used >> 10,
55768 vmi.largest_chunk >> 10
55769 #ifdef CONFIG_MEMORY_FAILURE
55770- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55771+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55772 #endif
55773 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55774 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
55775diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
55776index ccfd99b..1b7e255 100644
55777--- a/fs/proc/nommu.c
55778+++ b/fs/proc/nommu.c
55779@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
55780 if (len < 1)
55781 len = 1;
55782 seq_printf(m, "%*c", len, ' ');
55783- seq_path(m, &file->f_path, "");
55784+ seq_path(m, &file->f_path, "\n\\");
55785 }
55786
55787 seq_putc(m, '\n');
55788diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
55789index 986e832..6e8e859 100644
55790--- a/fs/proc/proc_net.c
55791+++ b/fs/proc/proc_net.c
55792@@ -23,6 +23,7 @@
55793 #include <linux/nsproxy.h>
55794 #include <net/net_namespace.h>
55795 #include <linux/seq_file.h>
55796+#include <linux/grsecurity.h>
55797
55798 #include "internal.h"
55799
55800@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
55801 struct task_struct *task;
55802 struct nsproxy *ns;
55803 struct net *net = NULL;
55804+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55805+ const struct cred *cred = current_cred();
55806+#endif
55807+
55808+#ifdef CONFIG_GRKERNSEC_PROC_USER
55809+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
55810+ return net;
55811+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55812+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
55813+ return net;
55814+#endif
55815
55816 rcu_read_lock();
55817 task = pid_task(proc_pid(dir), PIDTYPE_PID);
55818diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
55819index ac05f33..1e6dc7e 100644
55820--- a/fs/proc/proc_sysctl.c
55821+++ b/fs/proc/proc_sysctl.c
55822@@ -13,11 +13,15 @@
55823 #include <linux/module.h>
55824 #include "internal.h"
55825
55826+extern int gr_handle_chroot_sysctl(const int op);
55827+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
55828+ const int op);
55829+
55830 static const struct dentry_operations proc_sys_dentry_operations;
55831 static const struct file_operations proc_sys_file_operations;
55832-static const struct inode_operations proc_sys_inode_operations;
55833+const struct inode_operations proc_sys_inode_operations;
55834 static const struct file_operations proc_sys_dir_file_operations;
55835-static const struct inode_operations proc_sys_dir_operations;
55836+const struct inode_operations proc_sys_dir_operations;
55837
55838 void proc_sys_poll_notify(struct ctl_table_poll *poll)
55839 {
55840@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
55841
55842 err = NULL;
55843 d_set_d_op(dentry, &proc_sys_dentry_operations);
55844+
55845+ gr_handle_proc_create(dentry, inode);
55846+
55847 d_add(dentry, inode);
55848
55849 out:
55850@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55851 struct inode *inode = file_inode(filp);
55852 struct ctl_table_header *head = grab_header(inode);
55853 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
55854+ int op = write ? MAY_WRITE : MAY_READ;
55855 ssize_t error;
55856 size_t res;
55857
55858@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55859 * and won't be until we finish.
55860 */
55861 error = -EPERM;
55862- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
55863+ if (sysctl_perm(head, table, op))
55864 goto out;
55865
55866 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55867@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55868 if (!table->proc_handler)
55869 goto out;
55870
55871+#ifdef CONFIG_GRKERNSEC
55872+ error = -EPERM;
55873+ if (gr_handle_chroot_sysctl(op))
55874+ goto out;
55875+ dget(filp->f_path.dentry);
55876+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55877+ dput(filp->f_path.dentry);
55878+ goto out;
55879+ }
55880+ dput(filp->f_path.dentry);
55881+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55882+ goto out;
55883+ if (write && !capable(CAP_SYS_ADMIN))
55884+ goto out;
55885+#endif
55886+
55887 /* careful: calling conventions are nasty here */
55888 res = count;
55889 error = table->proc_handler(table, write, buf, &res, ppos);
55890@@ -598,6 +622,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55891 return -ENOMEM;
55892 } else {
55893 d_set_d_op(child, &proc_sys_dentry_operations);
55894+
55895+ gr_handle_proc_create(child, inode);
55896+
55897 d_add(child, inode);
55898 }
55899 } else {
55900@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55901 if ((*pos)++ < file->f_pos)
55902 return 0;
55903
55904+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55905+ return 0;
55906+
55907 if (unlikely(S_ISLNK(table->mode)))
55908 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55909 else
55910@@ -751,6 +781,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55911 if (IS_ERR(head))
55912 return PTR_ERR(head);
55913
55914+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55915+ return -ENOENT;
55916+
55917 generic_fillattr(inode, stat);
55918 if (table)
55919 stat->mode = (stat->mode & S_IFMT) | table->mode;
55920@@ -773,13 +806,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55921 .llseek = generic_file_llseek,
55922 };
55923
55924-static const struct inode_operations proc_sys_inode_operations = {
55925+const struct inode_operations proc_sys_inode_operations = {
55926 .permission = proc_sys_permission,
55927 .setattr = proc_sys_setattr,
55928 .getattr = proc_sys_getattr,
55929 };
55930
55931-static const struct inode_operations proc_sys_dir_operations = {
55932+const struct inode_operations proc_sys_dir_operations = {
55933 .lookup = proc_sys_lookup,
55934 .permission = proc_sys_permission,
55935 .setattr = proc_sys_setattr,
55936@@ -855,7 +888,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55937 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55938 const char *name, int namelen)
55939 {
55940- struct ctl_table *table;
55941+ ctl_table_no_const *table;
55942 struct ctl_dir *new;
55943 struct ctl_node *node;
55944 char *new_name;
55945@@ -867,7 +900,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55946 return NULL;
55947
55948 node = (struct ctl_node *)(new + 1);
55949- table = (struct ctl_table *)(node + 1);
55950+ table = (ctl_table_no_const *)(node + 1);
55951 new_name = (char *)(table + 2);
55952 memcpy(new_name, name, namelen);
55953 new_name[namelen] = '\0';
55954@@ -1036,7 +1069,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55955 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55956 struct ctl_table_root *link_root)
55957 {
55958- struct ctl_table *link_table, *entry, *link;
55959+ ctl_table_no_const *link_table, *link;
55960+ struct ctl_table *entry;
55961 struct ctl_table_header *links;
55962 struct ctl_node *node;
55963 char *link_name;
55964@@ -1059,7 +1093,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55965 return NULL;
55966
55967 node = (struct ctl_node *)(links + 1);
55968- link_table = (struct ctl_table *)(node + nr_entries);
55969+ link_table = (ctl_table_no_const *)(node + nr_entries);
55970 link_name = (char *)&link_table[nr_entries + 1];
55971
55972 for (link = link_table, entry = table; entry->procname; link++, entry++) {
55973@@ -1307,8 +1341,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55974 struct ctl_table_header ***subheader, struct ctl_table_set *set,
55975 struct ctl_table *table)
55976 {
55977- struct ctl_table *ctl_table_arg = NULL;
55978- struct ctl_table *entry, *files;
55979+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
55980+ struct ctl_table *entry;
55981 int nr_files = 0;
55982 int nr_dirs = 0;
55983 int err = -ENOMEM;
55984@@ -1320,10 +1354,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55985 nr_files++;
55986 }
55987
55988- files = table;
55989 /* If there are mixed files and directories we need a new table */
55990 if (nr_dirs && nr_files) {
55991- struct ctl_table *new;
55992+ ctl_table_no_const *new;
55993 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
55994 GFP_KERNEL);
55995 if (!files)
55996@@ -1341,7 +1374,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55997 /* Register everything except a directory full of subdirectories */
55998 if (nr_files || !nr_dirs) {
55999 struct ctl_table_header *header;
56000- header = __register_sysctl_table(set, path, files);
56001+ header = __register_sysctl_table(set, path, files ? files : table);
56002 if (!header) {
56003 kfree(ctl_table_arg);
56004 goto out;
56005diff --git a/fs/proc/root.c b/fs/proc/root.c
56006index 41a6ea9..23eaa92 100644
56007--- a/fs/proc/root.c
56008+++ b/fs/proc/root.c
56009@@ -182,7 +182,15 @@ void __init proc_root_init(void)
56010 #ifdef CONFIG_PROC_DEVICETREE
56011 proc_device_tree_init();
56012 #endif
56013+#ifdef CONFIG_GRKERNSEC_PROC_ADD
56014+#ifdef CONFIG_GRKERNSEC_PROC_USER
56015+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
56016+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56017+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
56018+#endif
56019+#else
56020 proc_mkdir("bus", NULL);
56021+#endif
56022 proc_sys_init();
56023 }
56024
56025diff --git a/fs/proc/self.c b/fs/proc/self.c
56026index 6b6a993..807cccc 100644
56027--- a/fs/proc/self.c
56028+++ b/fs/proc/self.c
56029@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
56030 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
56031 void *cookie)
56032 {
56033- char *s = nd_get_link(nd);
56034+ const char *s = nd_get_link(nd);
56035 if (!IS_ERR(s))
56036 kfree(s);
56037 }
56038diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
56039index 3e636d8..83e3b71 100644
56040--- a/fs/proc/task_mmu.c
56041+++ b/fs/proc/task_mmu.c
56042@@ -11,12 +11,19 @@
56043 #include <linux/rmap.h>
56044 #include <linux/swap.h>
56045 #include <linux/swapops.h>
56046+#include <linux/grsecurity.h>
56047
56048 #include <asm/elf.h>
56049 #include <asm/uaccess.h>
56050 #include <asm/tlbflush.h>
56051 #include "internal.h"
56052
56053+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56054+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
56055+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
56056+ _mm->pax_flags & MF_PAX_SEGMEXEC))
56057+#endif
56058+
56059 void task_mem(struct seq_file *m, struct mm_struct *mm)
56060 {
56061 unsigned long data, text, lib, swap;
56062@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56063 "VmExe:\t%8lu kB\n"
56064 "VmLib:\t%8lu kB\n"
56065 "VmPTE:\t%8lu kB\n"
56066- "VmSwap:\t%8lu kB\n",
56067- hiwater_vm << (PAGE_SHIFT-10),
56068+ "VmSwap:\t%8lu kB\n"
56069+
56070+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56071+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
56072+#endif
56073+
56074+ ,hiwater_vm << (PAGE_SHIFT-10),
56075 total_vm << (PAGE_SHIFT-10),
56076 mm->locked_vm << (PAGE_SHIFT-10),
56077 mm->pinned_vm << (PAGE_SHIFT-10),
56078@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56079 data << (PAGE_SHIFT-10),
56080 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
56081 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
56082- swap << (PAGE_SHIFT-10));
56083+ swap << (PAGE_SHIFT-10)
56084+
56085+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56086+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56087+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
56088+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
56089+#else
56090+ , mm->context.user_cs_base
56091+ , mm->context.user_cs_limit
56092+#endif
56093+#endif
56094+
56095+ );
56096 }
56097
56098 unsigned long task_vsize(struct mm_struct *mm)
56099@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56100 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
56101 }
56102
56103- /* We don't show the stack guard page in /proc/maps */
56104+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56105+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
56106+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
56107+#else
56108 start = vma->vm_start;
56109- if (stack_guard_page_start(vma, start))
56110- start += PAGE_SIZE;
56111 end = vma->vm_end;
56112- if (stack_guard_page_end(vma, end))
56113- end -= PAGE_SIZE;
56114+#endif
56115
56116 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
56117 start,
56118@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56119 flags & VM_WRITE ? 'w' : '-',
56120 flags & VM_EXEC ? 'x' : '-',
56121 flags & VM_MAYSHARE ? 's' : 'p',
56122+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56123+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
56124+#else
56125 pgoff,
56126+#endif
56127 MAJOR(dev), MINOR(dev), ino, &len);
56128
56129 /*
56130@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56131 */
56132 if (file) {
56133 pad_len_spaces(m, len);
56134- seq_path(m, &file->f_path, "\n");
56135+ seq_path(m, &file->f_path, "\n\\");
56136 goto done;
56137 }
56138
56139@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56140 * Thread stack in /proc/PID/task/TID/maps or
56141 * the main process stack.
56142 */
56143- if (!is_pid || (vma->vm_start <= mm->start_stack &&
56144- vma->vm_end >= mm->start_stack)) {
56145+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
56146+ (vma->vm_start <= mm->start_stack &&
56147+ vma->vm_end >= mm->start_stack)) {
56148 name = "[stack]";
56149 } else {
56150 /* Thread stack in /proc/PID/maps */
56151@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
56152 struct proc_maps_private *priv = m->private;
56153 struct task_struct *task = priv->task;
56154
56155+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56156+ if (current->exec_id != m->exec_id) {
56157+ gr_log_badprocpid("maps");
56158+ return 0;
56159+ }
56160+#endif
56161+
56162 show_map_vma(m, vma, is_pid);
56163
56164 if (m->count < m->size) /* vma is copied successfully */
56165@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56166 .private = &mss,
56167 };
56168
56169+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56170+ if (current->exec_id != m->exec_id) {
56171+ gr_log_badprocpid("smaps");
56172+ return 0;
56173+ }
56174+#endif
56175 memset(&mss, 0, sizeof mss);
56176- mss.vma = vma;
56177- /* mmap_sem is held in m_start */
56178- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56179- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56180-
56181+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56182+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
56183+#endif
56184+ mss.vma = vma;
56185+ /* mmap_sem is held in m_start */
56186+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56187+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56188+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56189+ }
56190+#endif
56191 show_map_vma(m, vma, is_pid);
56192
56193 seq_printf(m,
56194@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56195 "KernelPageSize: %8lu kB\n"
56196 "MMUPageSize: %8lu kB\n"
56197 "Locked: %8lu kB\n",
56198+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56199+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
56200+#else
56201 (vma->vm_end - vma->vm_start) >> 10,
56202+#endif
56203 mss.resident >> 10,
56204 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
56205 mss.shared_clean >> 10,
56206@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56207 int n;
56208 char buffer[50];
56209
56210+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56211+ if (current->exec_id != m->exec_id) {
56212+ gr_log_badprocpid("numa_maps");
56213+ return 0;
56214+ }
56215+#endif
56216+
56217 if (!mm)
56218 return 0;
56219
56220@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56221 mpol_to_str(buffer, sizeof(buffer), pol);
56222 mpol_cond_put(pol);
56223
56224+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56225+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
56226+#else
56227 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
56228+#endif
56229
56230 if (file) {
56231 seq_printf(m, " file=");
56232- seq_path(m, &file->f_path, "\n\t= ");
56233+ seq_path(m, &file->f_path, "\n\t\\= ");
56234 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
56235 seq_printf(m, " heap");
56236 } else {
56237diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
56238index 56123a6..5a2f6ec 100644
56239--- a/fs/proc/task_nommu.c
56240+++ b/fs/proc/task_nommu.c
56241@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56242 else
56243 bytes += kobjsize(mm);
56244
56245- if (current->fs && current->fs->users > 1)
56246+ if (current->fs && atomic_read(&current->fs->users) > 1)
56247 sbytes += kobjsize(current->fs);
56248 else
56249 bytes += kobjsize(current->fs);
56250@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
56251
56252 if (file) {
56253 pad_len_spaces(m, len);
56254- seq_path(m, &file->f_path, "");
56255+ seq_path(m, &file->f_path, "\n\\");
56256 } else if (mm) {
56257 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
56258
56259diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
56260index 17f7e08..e4b1529 100644
56261--- a/fs/proc/vmcore.c
56262+++ b/fs/proc/vmcore.c
56263@@ -99,9 +99,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
56264 nr_bytes = count;
56265
56266 /* If pfn is not ram, return zeros for sparse dump files */
56267- if (pfn_is_ram(pfn) == 0)
56268- memset(buf, 0, nr_bytes);
56269- else {
56270+ if (pfn_is_ram(pfn) == 0) {
56271+ if (userbuf) {
56272+ if (clear_user((char __force_user *)buf, nr_bytes))
56273+ return -EFAULT;
56274+ } else
56275+ memset(buf, 0, nr_bytes);
56276+ } else {
56277 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
56278 offset, userbuf);
56279 if (tmp < 0)
56280@@ -186,7 +190,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
56281 if (tsz > nr_bytes)
56282 tsz = nr_bytes;
56283
56284- tmp = read_from_oldmem(buffer, tsz, &start, 1);
56285+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
56286 if (tmp < 0)
56287 return tmp;
56288 buflen -= tsz;
56289diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
56290index b00fcc9..e0c6381 100644
56291--- a/fs/qnx6/qnx6.h
56292+++ b/fs/qnx6/qnx6.h
56293@@ -74,7 +74,7 @@ enum {
56294 BYTESEX_BE,
56295 };
56296
56297-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56298+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56299 {
56300 if (sbi->s_bytesex == BYTESEX_LE)
56301 return le64_to_cpu((__force __le64)n);
56302@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
56303 return (__force __fs64)cpu_to_be64(n);
56304 }
56305
56306-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56307+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56308 {
56309 if (sbi->s_bytesex == BYTESEX_LE)
56310 return le32_to_cpu((__force __le32)n);
56311diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
56312index 16e8abb..2dcf914 100644
56313--- a/fs/quota/netlink.c
56314+++ b/fs/quota/netlink.c
56315@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
56316 void quota_send_warning(struct kqid qid, dev_t dev,
56317 const char warntype)
56318 {
56319- static atomic_t seq;
56320+ static atomic_unchecked_t seq;
56321 struct sk_buff *skb;
56322 void *msg_head;
56323 int ret;
56324@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
56325 "VFS: Not enough memory to send quota warning.\n");
56326 return;
56327 }
56328- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
56329+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
56330 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
56331 if (!msg_head) {
56332 printk(KERN_ERR
56333diff --git a/fs/read_write.c b/fs/read_write.c
56334index 2cefa41..c7e2fe0 100644
56335--- a/fs/read_write.c
56336+++ b/fs/read_write.c
56337@@ -411,7 +411,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
56338
56339 old_fs = get_fs();
56340 set_fs(get_ds());
56341- p = (__force const char __user *)buf;
56342+ p = (const char __force_user *)buf;
56343 if (count > MAX_RW_COUNT)
56344 count = MAX_RW_COUNT;
56345 if (file->f_op->write)
56346diff --git a/fs/readdir.c b/fs/readdir.c
56347index fee38e0..12fdf47 100644
56348--- a/fs/readdir.c
56349+++ b/fs/readdir.c
56350@@ -17,6 +17,7 @@
56351 #include <linux/security.h>
56352 #include <linux/syscalls.h>
56353 #include <linux/unistd.h>
56354+#include <linux/namei.h>
56355
56356 #include <asm/uaccess.h>
56357
56358@@ -67,6 +68,7 @@ struct old_linux_dirent {
56359
56360 struct readdir_callback {
56361 struct old_linux_dirent __user * dirent;
56362+ struct file * file;
56363 int result;
56364 };
56365
56366@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
56367 buf->result = -EOVERFLOW;
56368 return -EOVERFLOW;
56369 }
56370+
56371+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56372+ return 0;
56373+
56374 buf->result++;
56375 dirent = buf->dirent;
56376 if (!access_ok(VERIFY_WRITE, dirent,
56377@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
56378
56379 buf.result = 0;
56380 buf.dirent = dirent;
56381+ buf.file = f.file;
56382
56383 error = vfs_readdir(f.file, fillonedir, &buf);
56384 if (buf.result)
56385@@ -139,6 +146,7 @@ struct linux_dirent {
56386 struct getdents_callback {
56387 struct linux_dirent __user * current_dir;
56388 struct linux_dirent __user * previous;
56389+ struct file * file;
56390 int count;
56391 int error;
56392 };
56393@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
56394 buf->error = -EOVERFLOW;
56395 return -EOVERFLOW;
56396 }
56397+
56398+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56399+ return 0;
56400+
56401 dirent = buf->previous;
56402 if (dirent) {
56403 if (__put_user(offset, &dirent->d_off))
56404@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56405 buf.previous = NULL;
56406 buf.count = count;
56407 buf.error = 0;
56408+ buf.file = f.file;
56409
56410 error = vfs_readdir(f.file, filldir, &buf);
56411 if (error >= 0)
56412@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56413 struct getdents_callback64 {
56414 struct linux_dirent64 __user * current_dir;
56415 struct linux_dirent64 __user * previous;
56416+ struct file *file;
56417 int count;
56418 int error;
56419 };
56420@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
56421 buf->error = -EINVAL; /* only used if we fail.. */
56422 if (reclen > buf->count)
56423 return -EINVAL;
56424+
56425+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56426+ return 0;
56427+
56428 dirent = buf->previous;
56429 if (dirent) {
56430 if (__put_user(offset, &dirent->d_off))
56431@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56432
56433 buf.current_dir = dirent;
56434 buf.previous = NULL;
56435+ buf.file = f.file;
56436 buf.count = count;
56437 buf.error = 0;
56438
56439@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56440 error = buf.error;
56441 lastdirent = buf.previous;
56442 if (lastdirent) {
56443- typeof(lastdirent->d_off) d_off = f.file->f_pos;
56444+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
56445 if (__put_user(d_off, &lastdirent->d_off))
56446 error = -EFAULT;
56447 else
56448diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
56449index 2b7882b..1c5ef48 100644
56450--- a/fs/reiserfs/do_balan.c
56451+++ b/fs/reiserfs/do_balan.c
56452@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
56453 return;
56454 }
56455
56456- atomic_inc(&(fs_generation(tb->tb_sb)));
56457+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
56458 do_balance_starts(tb);
56459
56460 /* balance leaf returns 0 except if combining L R and S into
56461diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
56462index 33532f7..4846ade 100644
56463--- a/fs/reiserfs/procfs.c
56464+++ b/fs/reiserfs/procfs.c
56465@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
56466 "SMALL_TAILS " : "NO_TAILS ",
56467 replay_only(sb) ? "REPLAY_ONLY " : "",
56468 convert_reiserfs(sb) ? "CONV " : "",
56469- atomic_read(&r->s_generation_counter),
56470+ atomic_read_unchecked(&r->s_generation_counter),
56471 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
56472 SF(s_do_balance), SF(s_unneeded_left_neighbor),
56473 SF(s_good_search_by_key_reada), SF(s_bmaps),
56474diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
56475index 157e474..65a6114 100644
56476--- a/fs/reiserfs/reiserfs.h
56477+++ b/fs/reiserfs/reiserfs.h
56478@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
56479 /* Comment? -Hans */
56480 wait_queue_head_t s_wait;
56481 /* To be obsoleted soon by per buffer seals.. -Hans */
56482- atomic_t s_generation_counter; // increased by one every time the
56483+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56484 // tree gets re-balanced
56485 unsigned long s_properties; /* File system properties. Currently holds
56486 on-disk FS format */
56487@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
56488 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56489
56490 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56491-#define get_generation(s) atomic_read (&fs_generation(s))
56492+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56493 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56494 #define __fs_changed(gen,s) (gen != get_generation (s))
56495 #define fs_changed(gen,s) \
56496diff --git a/fs/select.c b/fs/select.c
56497index 8c1c96c..a0f9b6d 100644
56498--- a/fs/select.c
56499+++ b/fs/select.c
56500@@ -20,6 +20,7 @@
56501 #include <linux/export.h>
56502 #include <linux/slab.h>
56503 #include <linux/poll.h>
56504+#include <linux/security.h>
56505 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
56506 #include <linux/file.h>
56507 #include <linux/fdtable.h>
56508@@ -827,6 +828,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
56509 struct poll_list *walk = head;
56510 unsigned long todo = nfds;
56511
56512+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
56513 if (nfds > rlimit(RLIMIT_NOFILE))
56514 return -EINVAL;
56515
56516diff --git a/fs/seq_file.c b/fs/seq_file.c
56517index 774c1eb..b67582a 100644
56518--- a/fs/seq_file.c
56519+++ b/fs/seq_file.c
56520@@ -10,6 +10,7 @@
56521 #include <linux/seq_file.h>
56522 #include <linux/slab.h>
56523 #include <linux/cred.h>
56524+#include <linux/sched.h>
56525
56526 #include <asm/uaccess.h>
56527 #include <asm/page.h>
56528@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
56529 #ifdef CONFIG_USER_NS
56530 p->user_ns = file->f_cred->user_ns;
56531 #endif
56532+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56533+ p->exec_id = current->exec_id;
56534+#endif
56535
56536 /*
56537 * Wrappers around seq_open(e.g. swaps_open) need to be
56538@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56539 return 0;
56540 }
56541 if (!m->buf) {
56542- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56543+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56544 if (!m->buf)
56545 return -ENOMEM;
56546 }
56547@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56548 Eoverflow:
56549 m->op->stop(m, p);
56550 kfree(m->buf);
56551- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56552+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56553 return !m->buf ? -ENOMEM : -EAGAIN;
56554 }
56555
56556@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56557
56558 /* grab buffer if we didn't have one */
56559 if (!m->buf) {
56560- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56561+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56562 if (!m->buf)
56563 goto Enomem;
56564 }
56565@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56566 goto Fill;
56567 m->op->stop(m, p);
56568 kfree(m->buf);
56569- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56570+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56571 if (!m->buf)
56572 goto Enomem;
56573 m->count = 0;
56574@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
56575 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
56576 void *data)
56577 {
56578- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
56579+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
56580 int res = -ENOMEM;
56581
56582 if (op) {
56583diff --git a/fs/splice.c b/fs/splice.c
56584index d37431d..81c3044 100644
56585--- a/fs/splice.c
56586+++ b/fs/splice.c
56587@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56588 pipe_lock(pipe);
56589
56590 for (;;) {
56591- if (!pipe->readers) {
56592+ if (!atomic_read(&pipe->readers)) {
56593 send_sig(SIGPIPE, current, 0);
56594 if (!ret)
56595 ret = -EPIPE;
56596@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56597 page_nr++;
56598 ret += buf->len;
56599
56600- if (pipe->files)
56601+ if (atomic_read(&pipe->files))
56602 do_wakeup = 1;
56603
56604 if (!--spd->nr_pages)
56605@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56606 do_wakeup = 0;
56607 }
56608
56609- pipe->waiting_writers++;
56610+ atomic_inc(&pipe->waiting_writers);
56611 pipe_wait(pipe);
56612- pipe->waiting_writers--;
56613+ atomic_dec(&pipe->waiting_writers);
56614 }
56615
56616 pipe_unlock(pipe);
56617@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
56618 old_fs = get_fs();
56619 set_fs(get_ds());
56620 /* The cast to a user pointer is valid due to the set_fs() */
56621- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
56622+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
56623 set_fs(old_fs);
56624
56625 return res;
56626@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
56627 old_fs = get_fs();
56628 set_fs(get_ds());
56629 /* The cast to a user pointer is valid due to the set_fs() */
56630- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
56631+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
56632 set_fs(old_fs);
56633
56634 return res;
56635@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
56636 goto err;
56637
56638 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
56639- vec[i].iov_base = (void __user *) page_address(page);
56640+ vec[i].iov_base = (void __force_user *) page_address(page);
56641 vec[i].iov_len = this_len;
56642 spd.pages[i] = page;
56643 spd.nr_pages++;
56644@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
56645 ops->release(pipe, buf);
56646 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
56647 pipe->nrbufs--;
56648- if (pipe->files)
56649+ if (atomic_read(&pipe->files))
56650 sd->need_wakeup = true;
56651 }
56652
56653@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
56654 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
56655 {
56656 while (!pipe->nrbufs) {
56657- if (!pipe->writers)
56658+ if (!atomic_read(&pipe->writers))
56659 return 0;
56660
56661- if (!pipe->waiting_writers && sd->num_spliced)
56662+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
56663 return 0;
56664
56665 if (sd->flags & SPLICE_F_NONBLOCK)
56666@@ -1193,7 +1193,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
56667 * out of the pipe right after the splice_to_pipe(). So set
56668 * PIPE_READERS appropriately.
56669 */
56670- pipe->readers = 1;
56671+ atomic_set(&pipe->readers, 1);
56672
56673 current->splice_pipe = pipe;
56674 }
56675@@ -1769,9 +1769,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56676 ret = -ERESTARTSYS;
56677 break;
56678 }
56679- if (!pipe->writers)
56680+ if (!atomic_read(&pipe->writers))
56681 break;
56682- if (!pipe->waiting_writers) {
56683+ if (!atomic_read(&pipe->waiting_writers)) {
56684 if (flags & SPLICE_F_NONBLOCK) {
56685 ret = -EAGAIN;
56686 break;
56687@@ -1803,7 +1803,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56688 pipe_lock(pipe);
56689
56690 while (pipe->nrbufs >= pipe->buffers) {
56691- if (!pipe->readers) {
56692+ if (!atomic_read(&pipe->readers)) {
56693 send_sig(SIGPIPE, current, 0);
56694 ret = -EPIPE;
56695 break;
56696@@ -1816,9 +1816,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56697 ret = -ERESTARTSYS;
56698 break;
56699 }
56700- pipe->waiting_writers++;
56701+ atomic_inc(&pipe->waiting_writers);
56702 pipe_wait(pipe);
56703- pipe->waiting_writers--;
56704+ atomic_dec(&pipe->waiting_writers);
56705 }
56706
56707 pipe_unlock(pipe);
56708@@ -1854,14 +1854,14 @@ retry:
56709 pipe_double_lock(ipipe, opipe);
56710
56711 do {
56712- if (!opipe->readers) {
56713+ if (!atomic_read(&opipe->readers)) {
56714 send_sig(SIGPIPE, current, 0);
56715 if (!ret)
56716 ret = -EPIPE;
56717 break;
56718 }
56719
56720- if (!ipipe->nrbufs && !ipipe->writers)
56721+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
56722 break;
56723
56724 /*
56725@@ -1958,7 +1958,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56726 pipe_double_lock(ipipe, opipe);
56727
56728 do {
56729- if (!opipe->readers) {
56730+ if (!atomic_read(&opipe->readers)) {
56731 send_sig(SIGPIPE, current, 0);
56732 if (!ret)
56733 ret = -EPIPE;
56734@@ -2003,7 +2003,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56735 * return EAGAIN if we have the potential of some data in the
56736 * future, otherwise just return 0
56737 */
56738- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
56739+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
56740 ret = -EAGAIN;
56741
56742 pipe_unlock(ipipe);
56743diff --git a/fs/stat.c b/fs/stat.c
56744index 04ce1ac..a13dd1e 100644
56745--- a/fs/stat.c
56746+++ b/fs/stat.c
56747@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
56748 stat->gid = inode->i_gid;
56749 stat->rdev = inode->i_rdev;
56750 stat->size = i_size_read(inode);
56751- stat->atime = inode->i_atime;
56752- stat->mtime = inode->i_mtime;
56753+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56754+ stat->atime = inode->i_ctime;
56755+ stat->mtime = inode->i_ctime;
56756+ } else {
56757+ stat->atime = inode->i_atime;
56758+ stat->mtime = inode->i_mtime;
56759+ }
56760 stat->ctime = inode->i_ctime;
56761 stat->blksize = (1 << inode->i_blkbits);
56762 stat->blocks = inode->i_blocks;
56763@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
56764 if (retval)
56765 return retval;
56766
56767- if (inode->i_op->getattr)
56768- return inode->i_op->getattr(path->mnt, path->dentry, stat);
56769+ if (inode->i_op->getattr) {
56770+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
56771+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56772+ stat->atime = stat->ctime;
56773+ stat->mtime = stat->ctime;
56774+ }
56775+ return retval;
56776+ }
56777
56778 generic_fillattr(inode, stat);
56779 return 0;
56780diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
56781index 15c68f9..36a8b3e 100644
56782--- a/fs/sysfs/bin.c
56783+++ b/fs/sysfs/bin.c
56784@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
56785 return ret;
56786 }
56787
56788-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
56789- void *buf, int len, int write)
56790+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
56791+ void *buf, size_t len, int write)
56792 {
56793 struct file *file = vma->vm_file;
56794 struct bin_buffer *bb = file->private_data;
56795 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
56796- int ret;
56797+ ssize_t ret;
56798
56799 if (!bb->vm_ops)
56800 return -EINVAL;
56801diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
56802index e8e0e71..3ca455a 100644
56803--- a/fs/sysfs/dir.c
56804+++ b/fs/sysfs/dir.c
56805@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
56806 *
56807 * Returns 31 bit hash of ns + name (so it fits in an off_t )
56808 */
56809-static unsigned int sysfs_name_hash(const void *ns, const char *name)
56810+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
56811 {
56812 unsigned long hash = init_name_hash();
56813 unsigned int len = strlen(name);
56814@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
56815 struct sysfs_dirent *sd;
56816 int rc;
56817
56818+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
56819+ const char *parent_name = parent_sd->s_name;
56820+
56821+ mode = S_IFDIR | S_IRWXU;
56822+
56823+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
56824+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
56825+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
56826+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
56827+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
56828+#endif
56829+
56830 /* allocate */
56831 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
56832 if (!sd)
56833diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
56834index 602f56d..6853db8 100644
56835--- a/fs/sysfs/file.c
56836+++ b/fs/sysfs/file.c
56837@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
56838
56839 struct sysfs_open_dirent {
56840 atomic_t refcnt;
56841- atomic_t event;
56842+ atomic_unchecked_t event;
56843 wait_queue_head_t poll;
56844 struct list_head buffers; /* goes through sysfs_buffer.list */
56845 };
56846@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
56847 if (!sysfs_get_active(attr_sd))
56848 return -ENODEV;
56849
56850- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
56851+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
56852 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
56853
56854 sysfs_put_active(attr_sd);
56855@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
56856 return -ENOMEM;
56857
56858 atomic_set(&new_od->refcnt, 0);
56859- atomic_set(&new_od->event, 1);
56860+ atomic_set_unchecked(&new_od->event, 1);
56861 init_waitqueue_head(&new_od->poll);
56862 INIT_LIST_HEAD(&new_od->buffers);
56863 goto retry;
56864@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
56865
56866 sysfs_put_active(attr_sd);
56867
56868- if (buffer->event != atomic_read(&od->event))
56869+ if (buffer->event != atomic_read_unchecked(&od->event))
56870 goto trigger;
56871
56872 return DEFAULT_POLLMASK;
56873@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
56874
56875 od = sd->s_attr.open;
56876 if (od) {
56877- atomic_inc(&od->event);
56878+ atomic_inc_unchecked(&od->event);
56879 wake_up_interruptible(&od->poll);
56880 }
56881
56882diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
56883index 8c940df..25b733e 100644
56884--- a/fs/sysfs/symlink.c
56885+++ b/fs/sysfs/symlink.c
56886@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56887
56888 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
56889 {
56890- char *page = nd_get_link(nd);
56891+ const char *page = nd_get_link(nd);
56892 if (!IS_ERR(page))
56893 free_page((unsigned long)page);
56894 }
56895diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
56896index 69d4889..a810bd4 100644
56897--- a/fs/sysv/sysv.h
56898+++ b/fs/sysv/sysv.h
56899@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
56900 #endif
56901 }
56902
56903-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56904+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56905 {
56906 if (sbi->s_bytesex == BYTESEX_PDP)
56907 return PDP_swab((__force __u32)n);
56908diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
56909index e18b988..f1d4ad0f 100644
56910--- a/fs/ubifs/io.c
56911+++ b/fs/ubifs/io.c
56912@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
56913 return err;
56914 }
56915
56916-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56917+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56918 {
56919 int err;
56920
56921diff --git a/fs/udf/misc.c b/fs/udf/misc.c
56922index c175b4d..8f36a16 100644
56923--- a/fs/udf/misc.c
56924+++ b/fs/udf/misc.c
56925@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
56926
56927 u8 udf_tag_checksum(const struct tag *t)
56928 {
56929- u8 *data = (u8 *)t;
56930+ const u8 *data = (const u8 *)t;
56931 u8 checksum = 0;
56932 int i;
56933 for (i = 0; i < sizeof(struct tag); ++i)
56934diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
56935index 8d974c4..b82f6ec 100644
56936--- a/fs/ufs/swab.h
56937+++ b/fs/ufs/swab.h
56938@@ -22,7 +22,7 @@ enum {
56939 BYTESEX_BE
56940 };
56941
56942-static inline u64
56943+static inline u64 __intentional_overflow(-1)
56944 fs64_to_cpu(struct super_block *sbp, __fs64 n)
56945 {
56946 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56947@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
56948 return (__force __fs64)cpu_to_be64(n);
56949 }
56950
56951-static inline u32
56952+static inline u32 __intentional_overflow(-1)
56953 fs32_to_cpu(struct super_block *sbp, __fs32 n)
56954 {
56955 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56956diff --git a/fs/utimes.c b/fs/utimes.c
56957index f4fb7ec..3fe03c0 100644
56958--- a/fs/utimes.c
56959+++ b/fs/utimes.c
56960@@ -1,6 +1,7 @@
56961 #include <linux/compiler.h>
56962 #include <linux/file.h>
56963 #include <linux/fs.h>
56964+#include <linux/security.h>
56965 #include <linux/linkage.h>
56966 #include <linux/mount.h>
56967 #include <linux/namei.h>
56968@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
56969 goto mnt_drop_write_and_out;
56970 }
56971 }
56972+
56973+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
56974+ error = -EACCES;
56975+ goto mnt_drop_write_and_out;
56976+ }
56977+
56978 mutex_lock(&inode->i_mutex);
56979 error = notify_change(path->dentry, &newattrs);
56980 mutex_unlock(&inode->i_mutex);
56981diff --git a/fs/xattr.c b/fs/xattr.c
56982index 3377dff..4d074d9 100644
56983--- a/fs/xattr.c
56984+++ b/fs/xattr.c
56985@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
56986 return rc;
56987 }
56988
56989+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56990+ssize_t
56991+pax_getxattr(struct dentry *dentry, void *value, size_t size)
56992+{
56993+ struct inode *inode = dentry->d_inode;
56994+ ssize_t error;
56995+
56996+ error = inode_permission(inode, MAY_EXEC);
56997+ if (error)
56998+ return error;
56999+
57000+ if (inode->i_op->getxattr)
57001+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
57002+ else
57003+ error = -EOPNOTSUPP;
57004+
57005+ return error;
57006+}
57007+EXPORT_SYMBOL(pax_getxattr);
57008+#endif
57009+
57010 ssize_t
57011 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
57012 {
57013@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
57014 * Extended attribute SET operations
57015 */
57016 static long
57017-setxattr(struct dentry *d, const char __user *name, const void __user *value,
57018+setxattr(struct path *path, const char __user *name, const void __user *value,
57019 size_t size, int flags)
57020 {
57021 int error;
57022@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
57023 posix_acl_fix_xattr_from_user(kvalue, size);
57024 }
57025
57026- error = vfs_setxattr(d, kname, kvalue, size, flags);
57027+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
57028+ error = -EACCES;
57029+ goto out;
57030+ }
57031+
57032+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
57033 out:
57034 if (vvalue)
57035 vfree(vvalue);
57036@@ -377,7 +403,7 @@ retry:
57037 return error;
57038 error = mnt_want_write(path.mnt);
57039 if (!error) {
57040- error = setxattr(path.dentry, name, value, size, flags);
57041+ error = setxattr(&path, name, value, size, flags);
57042 mnt_drop_write(path.mnt);
57043 }
57044 path_put(&path);
57045@@ -401,7 +427,7 @@ retry:
57046 return error;
57047 error = mnt_want_write(path.mnt);
57048 if (!error) {
57049- error = setxattr(path.dentry, name, value, size, flags);
57050+ error = setxattr(&path, name, value, size, flags);
57051 mnt_drop_write(path.mnt);
57052 }
57053 path_put(&path);
57054@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
57055 const void __user *,value, size_t, size, int, flags)
57056 {
57057 struct fd f = fdget(fd);
57058- struct dentry *dentry;
57059 int error = -EBADF;
57060
57061 if (!f.file)
57062 return error;
57063- dentry = f.file->f_path.dentry;
57064- audit_inode(NULL, dentry, 0);
57065+ audit_inode(NULL, f.file->f_path.dentry, 0);
57066 error = mnt_want_write_file(f.file);
57067 if (!error) {
57068- error = setxattr(dentry, name, value, size, flags);
57069+ error = setxattr(&f.file->f_path, name, value, size, flags);
57070 mnt_drop_write_file(f.file);
57071 }
57072 fdput(f);
57073diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
57074index 9fbea87..6b19972 100644
57075--- a/fs/xattr_acl.c
57076+++ b/fs/xattr_acl.c
57077@@ -76,8 +76,8 @@ struct posix_acl *
57078 posix_acl_from_xattr(struct user_namespace *user_ns,
57079 const void *value, size_t size)
57080 {
57081- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
57082- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
57083+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
57084+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
57085 int count;
57086 struct posix_acl *acl;
57087 struct posix_acl_entry *acl_e;
57088diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
57089index 8904284..ee0e14b 100644
57090--- a/fs/xfs/xfs_bmap.c
57091+++ b/fs/xfs/xfs_bmap.c
57092@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
57093
57094 #else
57095 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
57096-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
57097+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
57098 #endif /* DEBUG */
57099
57100 /*
57101diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
57102index 6157424..ac98f6d 100644
57103--- a/fs/xfs/xfs_dir2_sf.c
57104+++ b/fs/xfs/xfs_dir2_sf.c
57105@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
57106 }
57107
57108 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
57109- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57110+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
57111+ char name[sfep->namelen];
57112+ memcpy(name, sfep->name, sfep->namelen);
57113+ if (filldir(dirent, name, sfep->namelen,
57114+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
57115+ *offset = off & 0x7fffffff;
57116+ return 0;
57117+ }
57118+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57119 off & 0x7fffffff, ino, DT_UNKNOWN)) {
57120 *offset = off & 0x7fffffff;
57121 return 0;
57122diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
57123index 5e99968..45bd327 100644
57124--- a/fs/xfs/xfs_ioctl.c
57125+++ b/fs/xfs/xfs_ioctl.c
57126@@ -127,7 +127,7 @@ xfs_find_handle(
57127 }
57128
57129 error = -EFAULT;
57130- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
57131+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
57132 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
57133 goto out_put;
57134
57135diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
57136index ca9ecaa..60100c7 100644
57137--- a/fs/xfs/xfs_iops.c
57138+++ b/fs/xfs/xfs_iops.c
57139@@ -395,7 +395,7 @@ xfs_vn_put_link(
57140 struct nameidata *nd,
57141 void *p)
57142 {
57143- char *s = nd_get_link(nd);
57144+ const char *s = nd_get_link(nd);
57145
57146 if (!IS_ERR(s))
57147 kfree(s);
57148diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
57149new file mode 100644
57150index 0000000..c9c4ac3
57151--- /dev/null
57152+++ b/grsecurity/Kconfig
57153@@ -0,0 +1,1054 @@
57154+#
57155+# grecurity configuration
57156+#
57157+menu "Memory Protections"
57158+depends on GRKERNSEC
57159+
57160+config GRKERNSEC_KMEM
57161+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
57162+ default y if GRKERNSEC_CONFIG_AUTO
57163+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
57164+ help
57165+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
57166+ be written to or read from to modify or leak the contents of the running
57167+ kernel. /dev/port will also not be allowed to be opened and support
57168+ for /dev/cpu/*/msr will be removed. If you have module
57169+ support disabled, enabling this will close up five ways that are
57170+ currently used to insert malicious code into the running kernel.
57171+
57172+ Even with all these features enabled, we still highly recommend that
57173+ you use the RBAC system, as it is still possible for an attacker to
57174+ modify the running kernel through privileged I/O granted by ioperm/iopl.
57175+
57176+ If you are not using XFree86, you may be able to stop this additional
57177+ case by enabling the 'Disable privileged I/O' option. Though nothing
57178+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
57179+ but only to video memory, which is the only writing we allow in this
57180+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
57181+ not be allowed to mprotect it with PROT_WRITE later.
57182+ Enabling this feature will prevent the "cpupower" and "powertop" tools
57183+ from working.
57184+
57185+ It is highly recommended that you say Y here if you meet all the
57186+ conditions above.
57187+
57188+config GRKERNSEC_VM86
57189+ bool "Restrict VM86 mode"
57190+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57191+ depends on X86_32
57192+
57193+ help
57194+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
57195+ make use of a special execution mode on 32bit x86 processors called
57196+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
57197+ video cards and will still work with this option enabled. The purpose
57198+ of the option is to prevent exploitation of emulation errors in
57199+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
57200+ Nearly all users should be able to enable this option.
57201+
57202+config GRKERNSEC_IO
57203+ bool "Disable privileged I/O"
57204+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57205+ depends on X86
57206+ select RTC_CLASS
57207+ select RTC_INTF_DEV
57208+ select RTC_DRV_CMOS
57209+
57210+ help
57211+ If you say Y here, all ioperm and iopl calls will return an error.
57212+ Ioperm and iopl can be used to modify the running kernel.
57213+ Unfortunately, some programs need this access to operate properly,
57214+ the most notable of which are XFree86 and hwclock. hwclock can be
57215+ remedied by having RTC support in the kernel, so real-time
57216+ clock support is enabled if this option is enabled, to ensure
57217+ that hwclock operates correctly. XFree86 still will not
57218+ operate correctly with this option enabled, so DO NOT CHOOSE Y
57219+ IF YOU USE XFree86. If you use XFree86 and you still want to
57220+ protect your kernel against modification, use the RBAC system.
57221+
57222+config GRKERNSEC_JIT_HARDEN
57223+ bool "Harden BPF JIT against spray attacks"
57224+ default y if GRKERNSEC_CONFIG_AUTO
57225+ depends on BPF_JIT
57226+ help
57227+ If you say Y here, the native code generated by the kernel's Berkeley
57228+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
57229+ attacks that attempt to fit attacker-beneficial instructions in
57230+ 32bit immediate fields of JIT-generated native instructions. The
57231+ attacker will generally aim to cause an unintended instruction sequence
57232+ of JIT-generated native code to execute by jumping into the middle of
57233+ a generated instruction. This feature effectively randomizes the 32bit
57234+ immediate constants present in the generated code to thwart such attacks.
57235+
57236+ If you're using KERNEXEC, it's recommended that you enable this option
57237+ to supplement the hardening of the kernel.
57238+
57239+config GRKERNSEC_PERF_HARDEN
57240+ bool "Disable unprivileged PERF_EVENTS usage by default"
57241+ default y if GRKERNSEC_CONFIG_AUTO
57242+ depends on PERF_EVENTS
57243+ help
57244+ If you say Y here, the range of acceptable values for the
57245+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
57246+ default to a new value: 3. When the sysctl is set to this value, no
57247+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
57248+
57249+ Though PERF_EVENTS can be used legitimately for performance monitoring
57250+ and low-level application profiling, it is forced on regardless of
57251+ configuration, has been at fault for several vulnerabilities, and
57252+ creates new opportunities for side channels and other information leaks.
57253+
57254+ This feature puts PERF_EVENTS into a secure default state and permits
57255+ the administrator to change out of it temporarily if unprivileged
57256+ application profiling is needed.
57257+
57258+config GRKERNSEC_RAND_THREADSTACK
57259+ bool "Insert random gaps between thread stacks"
57260+ default y if GRKERNSEC_CONFIG_AUTO
57261+ depends on PAX_RANDMMAP && !PPC
57262+ help
57263+ If you say Y here, a random-sized gap will be enforced between allocated
57264+ thread stacks. Glibc's NPTL and other threading libraries that
57265+ pass MAP_STACK to the kernel for thread stack allocation are supported.
57266+ The implementation currently provides 8 bits of entropy for the gap.
57267+
57268+ Many distributions do not compile threaded remote services with the
57269+ -fstack-check argument to GCC, causing the variable-sized stack-based
57270+ allocator, alloca(), to not probe the stack on allocation. This
57271+ permits an unbounded alloca() to skip over any guard page and potentially
57272+ modify another thread's stack reliably. An enforced random gap
57273+ reduces the reliability of such an attack and increases the chance
57274+ that such a read/write to another thread's stack instead lands in
57275+ an unmapped area, causing a crash and triggering grsecurity's
57276+ anti-bruteforcing logic.
57277+
57278+config GRKERNSEC_PROC_MEMMAP
57279+ bool "Harden ASLR against information leaks and entropy reduction"
57280+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
57281+ depends on PAX_NOEXEC || PAX_ASLR
57282+ help
57283+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
57284+ give no information about the addresses of its mappings if
57285+ PaX features that rely on random addresses are enabled on the task.
57286+ In addition to sanitizing this information and disabling other
57287+ dangerous sources of information, this option causes reads of sensitive
57288+ /proc/<pid> entries where the file descriptor was opened in a different
57289+ task than the one performing the read. Such attempts are logged.
57290+ This option also limits argv/env strings for suid/sgid binaries
57291+ to 512KB to prevent a complete exhaustion of the stack entropy provided
57292+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
57293+ binaries to prevent alternative mmap layouts from being abused.
57294+
57295+ If you use PaX it is essential that you say Y here as it closes up
57296+ several holes that make full ASLR useless locally.
57297+
57298+config GRKERNSEC_BRUTE
57299+ bool "Deter exploit bruteforcing"
57300+ default y if GRKERNSEC_CONFIG_AUTO
57301+ help
57302+ If you say Y here, attempts to bruteforce exploits against forking
57303+ daemons such as apache or sshd, as well as against suid/sgid binaries
57304+ will be deterred. When a child of a forking daemon is killed by PaX
57305+ or crashes due to an illegal instruction or other suspicious signal,
57306+ the parent process will be delayed 30 seconds upon every subsequent
57307+ fork until the administrator is able to assess the situation and
57308+ restart the daemon.
57309+ In the suid/sgid case, the attempt is logged, the user has all their
57310+ existing instances of the suid/sgid binary terminated and will
57311+ be unable to execute any suid/sgid binaries for 15 minutes.
57312+
57313+ It is recommended that you also enable signal logging in the auditing
57314+ section so that logs are generated when a process triggers a suspicious
57315+ signal.
57316+ If the sysctl option is enabled, a sysctl option with name
57317+ "deter_bruteforce" is created.
57318+
57319+
57320+config GRKERNSEC_MODHARDEN
57321+ bool "Harden module auto-loading"
57322+ default y if GRKERNSEC_CONFIG_AUTO
57323+ depends on MODULES
57324+ help
57325+ If you say Y here, module auto-loading in response to use of some
57326+ feature implemented by an unloaded module will be restricted to
57327+ root users. Enabling this option helps defend against attacks
57328+ by unprivileged users who abuse the auto-loading behavior to
57329+ cause a vulnerable module to load that is then exploited.
57330+
57331+ If this option prevents a legitimate use of auto-loading for a
57332+ non-root user, the administrator can execute modprobe manually
57333+ with the exact name of the module mentioned in the alert log.
57334+ Alternatively, the administrator can add the module to the list
57335+ of modules loaded at boot by modifying init scripts.
57336+
57337+ Modification of init scripts will most likely be needed on
57338+ Ubuntu servers with encrypted home directory support enabled,
57339+ as the first non-root user logging in will cause the ecb(aes),
57340+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
57341+
57342+config GRKERNSEC_HIDESYM
57343+ bool "Hide kernel symbols"
57344+ default y if GRKERNSEC_CONFIG_AUTO
57345+ select PAX_USERCOPY_SLABS
57346+ help
57347+ If you say Y here, getting information on loaded modules, and
57348+ displaying all kernel symbols through a syscall will be restricted
57349+ to users with CAP_SYS_MODULE. For software compatibility reasons,
57350+ /proc/kallsyms will be restricted to the root user. The RBAC
57351+ system can hide that entry even from root.
57352+
57353+ This option also prevents leaking of kernel addresses through
57354+ several /proc entries.
57355+
57356+ Note that this option is only effective provided the following
57357+ conditions are met:
57358+ 1) The kernel using grsecurity is not precompiled by some distribution
57359+ 2) You have also enabled GRKERNSEC_DMESG
57360+ 3) You are using the RBAC system and hiding other files such as your
57361+ kernel image and System.map. Alternatively, enabling this option
57362+ causes the permissions on /boot, /lib/modules, and the kernel
57363+ source directory to change at compile time to prevent
57364+ reading by non-root users.
57365+ If the above conditions are met, this option will aid in providing a
57366+ useful protection against local kernel exploitation of overflows
57367+ and arbitrary read/write vulnerabilities.
57368+
57369+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
57370+ in addition to this feature.
57371+
57372+config GRKERNSEC_KERN_LOCKOUT
57373+ bool "Active kernel exploit response"
57374+ default y if GRKERNSEC_CONFIG_AUTO
57375+ depends on X86 || ARM || PPC || SPARC
57376+ help
57377+ If you say Y here, when a PaX alert is triggered due to suspicious
57378+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
57379+ or an OOPS occurs due to bad memory accesses, instead of just
57380+ terminating the offending process (and potentially allowing
57381+ a subsequent exploit from the same user), we will take one of two
57382+ actions:
57383+ If the user was root, we will panic the system
57384+ If the user was non-root, we will log the attempt, terminate
57385+ all processes owned by the user, then prevent them from creating
57386+ any new processes until the system is restarted
57387+ This deters repeated kernel exploitation/bruteforcing attempts
57388+ and is useful for later forensics.
57389+
57390+endmenu
57391+menu "Role Based Access Control Options"
57392+depends on GRKERNSEC
57393+
57394+config GRKERNSEC_RBAC_DEBUG
57395+ bool
57396+
57397+config GRKERNSEC_NO_RBAC
57398+ bool "Disable RBAC system"
57399+ help
57400+ If you say Y here, the /dev/grsec device will be removed from the kernel,
57401+ preventing the RBAC system from being enabled. You should only say Y
57402+ here if you have no intention of using the RBAC system, so as to prevent
57403+ an attacker with root access from misusing the RBAC system to hide files
57404+ and processes when loadable module support and /dev/[k]mem have been
57405+ locked down.
57406+
57407+config GRKERNSEC_ACL_HIDEKERN
57408+ bool "Hide kernel processes"
57409+ help
57410+ If you say Y here, all kernel threads will be hidden to all
57411+ processes but those whose subject has the "view hidden processes"
57412+ flag.
57413+
57414+config GRKERNSEC_ACL_MAXTRIES
57415+ int "Maximum tries before password lockout"
57416+ default 3
57417+ help
57418+ This option enforces the maximum number of times a user can attempt
57419+ to authorize themselves with the grsecurity RBAC system before being
57420+ denied the ability to attempt authorization again for a specified time.
57421+ The lower the number, the harder it will be to brute-force a password.
57422+
57423+config GRKERNSEC_ACL_TIMEOUT
57424+ int "Time to wait after max password tries, in seconds"
57425+ default 30
57426+ help
57427+ This option specifies the time the user must wait after attempting to
57428+ authorize to the RBAC system with the maximum number of invalid
57429+ passwords. The higher the number, the harder it will be to brute-force
57430+ a password.
57431+
57432+endmenu
57433+menu "Filesystem Protections"
57434+depends on GRKERNSEC
57435+
57436+config GRKERNSEC_PROC
57437+ bool "Proc restrictions"
57438+ default y if GRKERNSEC_CONFIG_AUTO
57439+ help
57440+ If you say Y here, the permissions of the /proc filesystem
57441+ will be altered to enhance system security and privacy. You MUST
57442+ choose either a user only restriction or a user and group restriction.
57443+ Depending upon the option you choose, you can either restrict users to
57444+ see only the processes they themselves run, or choose a group that can
57445+ view all processes and files normally restricted to root if you choose
57446+ the "restrict to user only" option. NOTE: If you're running identd or
57447+ ntpd as a non-root user, you will have to run it as the group you
57448+ specify here.
57449+
57450+config GRKERNSEC_PROC_USER
57451+ bool "Restrict /proc to user only"
57452+ depends on GRKERNSEC_PROC
57453+ help
57454+ If you say Y here, non-root users will only be able to view their own
57455+ processes, and restricts them from viewing network-related information,
57456+ and viewing kernel symbol and module information.
57457+
57458+config GRKERNSEC_PROC_USERGROUP
57459+ bool "Allow special group"
57460+ default y if GRKERNSEC_CONFIG_AUTO
57461+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
57462+ help
57463+ If you say Y here, you will be able to select a group that will be
57464+ able to view all processes and network-related information. If you've
57465+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
57466+ remain hidden. This option is useful if you want to run identd as
57467+ a non-root user. The group you select may also be chosen at boot time
57468+ via "grsec_proc_gid=" on the kernel commandline.
57469+
57470+config GRKERNSEC_PROC_GID
57471+ int "GID for special group"
57472+ depends on GRKERNSEC_PROC_USERGROUP
57473+ default 1001
57474+
57475+config GRKERNSEC_PROC_ADD
57476+ bool "Additional restrictions"
57477+ default y if GRKERNSEC_CONFIG_AUTO
57478+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
57479+ help
57480+ If you say Y here, additional restrictions will be placed on
57481+ /proc that keep normal users from viewing device information and
57482+ slabinfo information that could be useful for exploits.
57483+
57484+config GRKERNSEC_LINK
57485+ bool "Linking restrictions"
57486+ default y if GRKERNSEC_CONFIG_AUTO
57487+ help
57488+ If you say Y here, /tmp race exploits will be prevented, since users
57489+ will no longer be able to follow symlinks owned by other users in
57490+ world-writable +t directories (e.g. /tmp), unless the owner of the
57491+ symlink is the owner of the directory. users will also not be
57492+ able to hardlink to files they do not own. If the sysctl option is
57493+ enabled, a sysctl option with name "linking_restrictions" is created.
57494+
57495+config GRKERNSEC_SYMLINKOWN
57496+ bool "Kernel-enforced SymlinksIfOwnerMatch"
57497+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57498+ help
57499+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
57500+ that prevents it from being used as a security feature. As Apache
57501+ verifies the symlink by performing a stat() against the target of
57502+ the symlink before it is followed, an attacker can setup a symlink
57503+ to point to a same-owned file, then replace the symlink with one
57504+ that targets another user's file just after Apache "validates" the
57505+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
57506+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
57507+ will be in place for the group you specify. If the sysctl option
57508+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
57509+ created.
57510+
57511+config GRKERNSEC_SYMLINKOWN_GID
57512+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
57513+ depends on GRKERNSEC_SYMLINKOWN
57514+ default 1006
57515+ help
57516+ Setting this GID determines what group kernel-enforced
57517+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
57518+ is enabled, a sysctl option with name "symlinkown_gid" is created.
57519+
57520+config GRKERNSEC_FIFO
57521+ bool "FIFO restrictions"
57522+ default y if GRKERNSEC_CONFIG_AUTO
57523+ help
57524+ If you say Y here, users will not be able to write to FIFOs they don't
57525+ own in world-writable +t directories (e.g. /tmp), unless the owner of
57526+ the FIFO is the same owner of the directory it's held in. If the sysctl
57527+ option is enabled, a sysctl option with name "fifo_restrictions" is
57528+ created.
57529+
57530+config GRKERNSEC_SYSFS_RESTRICT
57531+ bool "Sysfs/debugfs restriction"
57532+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57533+ depends on SYSFS
57534+ help
57535+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
57536+ any filesystem normally mounted under it (e.g. debugfs) will be
57537+ mostly accessible only by root. These filesystems generally provide access
57538+ to hardware and debug information that isn't appropriate for unprivileged
57539+ users of the system. Sysfs and debugfs have also become a large source
57540+ of new vulnerabilities, ranging from infoleaks to local compromise.
57541+ There has been very little oversight with an eye toward security involved
57542+ in adding new exporters of information to these filesystems, so their
57543+ use is discouraged.
57544+ For reasons of compatibility, a few directories have been whitelisted
57545+ for access by non-root users:
57546+ /sys/fs/selinux
57547+ /sys/fs/fuse
57548+ /sys/devices/system/cpu
57549+
57550+config GRKERNSEC_ROFS
57551+ bool "Runtime read-only mount protection"
57552+ help
57553+ If you say Y here, a sysctl option with name "romount_protect" will
57554+ be created. By setting this option to 1 at runtime, filesystems
57555+ will be protected in the following ways:
57556+ * No new writable mounts will be allowed
57557+ * Existing read-only mounts won't be able to be remounted read/write
57558+ * Write operations will be denied on all block devices
57559+ This option acts independently of grsec_lock: once it is set to 1,
57560+ it cannot be turned off. Therefore, please be mindful of the resulting
57561+ behavior if this option is enabled in an init script on a read-only
57562+ filesystem. This feature is mainly intended for secure embedded systems.
57563+
57564+config GRKERNSEC_DEVICE_SIDECHANNEL
57565+ bool "Eliminate stat/notify-based device sidechannels"
57566+ default y if GRKERNSEC_CONFIG_AUTO
57567+ help
57568+ If you say Y here, timing analyses on block or character
57569+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
57570+ will be thwarted for unprivileged users. If a process without
57571+ CAP_MKNOD stats such a device, the last access and last modify times
57572+ will match the device's create time. No access or modify events
57573+ will be triggered through inotify/dnotify/fanotify for such devices.
57574+ This feature will prevent attacks that may at a minimum
57575+ allow an attacker to determine the administrator's password length.
57576+
57577+config GRKERNSEC_CHROOT
57578+ bool "Chroot jail restrictions"
57579+ default y if GRKERNSEC_CONFIG_AUTO
57580+ help
57581+ If you say Y here, you will be able to choose several options that will
57582+ make breaking out of a chrooted jail much more difficult. If you
57583+ encounter no software incompatibilities with the following options, it
57584+ is recommended that you enable each one.
57585+
57586+config GRKERNSEC_CHROOT_MOUNT
57587+ bool "Deny mounts"
57588+ default y if GRKERNSEC_CONFIG_AUTO
57589+ depends on GRKERNSEC_CHROOT
57590+ help
57591+ If you say Y here, processes inside a chroot will not be able to
57592+ mount or remount filesystems. If the sysctl option is enabled, a
57593+ sysctl option with name "chroot_deny_mount" is created.
57594+
57595+config GRKERNSEC_CHROOT_DOUBLE
57596+ bool "Deny double-chroots"
57597+ default y if GRKERNSEC_CONFIG_AUTO
57598+ depends on GRKERNSEC_CHROOT
57599+ help
57600+ If you say Y here, processes inside a chroot will not be able to chroot
57601+ again outside the chroot. This is a widely used method of breaking
57602+ out of a chroot jail and should not be allowed. If the sysctl
57603+ option is enabled, a sysctl option with name
57604+ "chroot_deny_chroot" is created.
57605+
57606+config GRKERNSEC_CHROOT_PIVOT
57607+ bool "Deny pivot_root in chroot"
57608+ default y if GRKERNSEC_CONFIG_AUTO
57609+ depends on GRKERNSEC_CHROOT
57610+ help
57611+ If you say Y here, processes inside a chroot will not be able to use
57612+ a function called pivot_root() that was introduced in Linux 2.3.41. It
57613+ works similar to chroot in that it changes the root filesystem. This
57614+ function could be misused in a chrooted process to attempt to break out
57615+ of the chroot, and therefore should not be allowed. If the sysctl
57616+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
57617+ created.
57618+
57619+config GRKERNSEC_CHROOT_CHDIR
57620+ bool "Enforce chdir(\"/\") on all chroots"
57621+ default y if GRKERNSEC_CONFIG_AUTO
57622+ depends on GRKERNSEC_CHROOT
57623+ help
57624+ If you say Y here, the current working directory of all newly-chrooted
57625+ applications will be set to the the root directory of the chroot.
57626+ The man page on chroot(2) states:
57627+ Note that this call does not change the current working
57628+ directory, so that `.' can be outside the tree rooted at
57629+ `/'. In particular, the super-user can escape from a
57630+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
57631+
57632+ It is recommended that you say Y here, since it's not known to break
57633+ any software. If the sysctl option is enabled, a sysctl option with
57634+ name "chroot_enforce_chdir" is created.
57635+
57636+config GRKERNSEC_CHROOT_CHMOD
57637+ bool "Deny (f)chmod +s"
57638+ default y if GRKERNSEC_CONFIG_AUTO
57639+ depends on GRKERNSEC_CHROOT
57640+ help
57641+ If you say Y here, processes inside a chroot will not be able to chmod
57642+ or fchmod files to make them have suid or sgid bits. This protects
57643+ against another published method of breaking a chroot. If the sysctl
57644+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
57645+ created.
57646+
57647+config GRKERNSEC_CHROOT_FCHDIR
57648+ bool "Deny fchdir out of chroot"
57649+ default y if GRKERNSEC_CONFIG_AUTO
57650+ depends on GRKERNSEC_CHROOT
57651+ help
57652+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
57653+ to a file descriptor of the chrooting process that points to a directory
57654+ outside the filesystem will be stopped. If the sysctl option
57655+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
57656+
57657+config GRKERNSEC_CHROOT_MKNOD
57658+ bool "Deny mknod"
57659+ default y if GRKERNSEC_CONFIG_AUTO
57660+ depends on GRKERNSEC_CHROOT
57661+ help
57662+ If you say Y here, processes inside a chroot will not be allowed to
57663+ mknod. The problem with using mknod inside a chroot is that it
57664+ would allow an attacker to create a device entry that is the same
57665+ as one on the physical root of your system, which could range from
57666+ anything from the console device to a device for your harddrive (which
57667+ they could then use to wipe the drive or steal data). It is recommended
57668+ that you say Y here, unless you run into software incompatibilities.
57669+ If the sysctl option is enabled, a sysctl option with name
57670+ "chroot_deny_mknod" is created.
57671+
57672+config GRKERNSEC_CHROOT_SHMAT
57673+ bool "Deny shmat() out of chroot"
57674+ default y if GRKERNSEC_CONFIG_AUTO
57675+ depends on GRKERNSEC_CHROOT
57676+ help
57677+ If you say Y here, processes inside a chroot will not be able to attach
57678+ to shared memory segments that were created outside of the chroot jail.
57679+ It is recommended that you say Y here. If the sysctl option is enabled,
57680+ a sysctl option with name "chroot_deny_shmat" is created.
57681+
57682+config GRKERNSEC_CHROOT_UNIX
57683+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
57684+ default y if GRKERNSEC_CONFIG_AUTO
57685+ depends on GRKERNSEC_CHROOT
57686+ help
57687+ If you say Y here, processes inside a chroot will not be able to
57688+ connect to abstract (meaning not belonging to a filesystem) Unix
57689+ domain sockets that were bound outside of a chroot. It is recommended
57690+ that you say Y here. If the sysctl option is enabled, a sysctl option
57691+ with name "chroot_deny_unix" is created.
57692+
57693+config GRKERNSEC_CHROOT_FINDTASK
57694+ bool "Protect outside processes"
57695+ default y if GRKERNSEC_CONFIG_AUTO
57696+ depends on GRKERNSEC_CHROOT
57697+ help
57698+ If you say Y here, processes inside a chroot will not be able to
57699+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
57700+ getsid, or view any process outside of the chroot. If the sysctl
57701+ option is enabled, a sysctl option with name "chroot_findtask" is
57702+ created.
57703+
57704+config GRKERNSEC_CHROOT_NICE
57705+ bool "Restrict priority changes"
57706+ default y if GRKERNSEC_CONFIG_AUTO
57707+ depends on GRKERNSEC_CHROOT
57708+ help
57709+ If you say Y here, processes inside a chroot will not be able to raise
57710+ the priority of processes in the chroot, or alter the priority of
57711+ processes outside the chroot. This provides more security than simply
57712+ removing CAP_SYS_NICE from the process' capability set. If the
57713+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
57714+ is created.
57715+
57716+config GRKERNSEC_CHROOT_SYSCTL
57717+ bool "Deny sysctl writes"
57718+ default y if GRKERNSEC_CONFIG_AUTO
57719+ depends on GRKERNSEC_CHROOT
57720+ help
57721+ If you say Y here, an attacker in a chroot will not be able to
57722+ write to sysctl entries, either by sysctl(2) or through a /proc
57723+ interface. It is strongly recommended that you say Y here. If the
57724+ sysctl option is enabled, a sysctl option with name
57725+ "chroot_deny_sysctl" is created.
57726+
57727+config GRKERNSEC_CHROOT_CAPS
57728+ bool "Capability restrictions"
57729+ default y if GRKERNSEC_CONFIG_AUTO
57730+ depends on GRKERNSEC_CHROOT
57731+ help
57732+ If you say Y here, the capabilities on all processes within a
57733+ chroot jail will be lowered to stop module insertion, raw i/o,
57734+ system and net admin tasks, rebooting the system, modifying immutable
57735+ files, modifying IPC owned by another, and changing the system time.
57736+ This is left an option because it can break some apps. Disable this
57737+ if your chrooted apps are having problems performing those kinds of
57738+ tasks. If the sysctl option is enabled, a sysctl option with
57739+ name "chroot_caps" is created.
57740+
57741+config GRKERNSEC_CHROOT_INITRD
57742+ bool "Exempt initrd tasks from restrictions"
57743+ default y if GRKERNSEC_CONFIG_AUTO
57744+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
57745+ help
57746+ If you say Y here, tasks started prior to init will be exempted from
57747+ grsecurity's chroot restrictions. This option is mainly meant to
57748+ resolve Plymouth's performing privileged operations unnecessarily
57749+ in a chroot.
57750+
57751+endmenu
57752+menu "Kernel Auditing"
57753+depends on GRKERNSEC
57754+
57755+config GRKERNSEC_AUDIT_GROUP
57756+ bool "Single group for auditing"
57757+ help
57758+ If you say Y here, the exec and chdir logging features will only operate
57759+ on a group you specify. This option is recommended if you only want to
57760+ watch certain users instead of having a large amount of logs from the
57761+ entire system. If the sysctl option is enabled, a sysctl option with
57762+ name "audit_group" is created.
57763+
57764+config GRKERNSEC_AUDIT_GID
57765+ int "GID for auditing"
57766+ depends on GRKERNSEC_AUDIT_GROUP
57767+ default 1007
57768+
57769+config GRKERNSEC_EXECLOG
57770+ bool "Exec logging"
57771+ help
57772+ If you say Y here, all execve() calls will be logged (since the
57773+ other exec*() calls are frontends to execve(), all execution
57774+ will be logged). Useful for shell-servers that like to keep track
57775+ of their users. If the sysctl option is enabled, a sysctl option with
57776+ name "exec_logging" is created.
57777+ WARNING: This option when enabled will produce a LOT of logs, especially
57778+ on an active system.
57779+
57780+config GRKERNSEC_RESLOG
57781+ bool "Resource logging"
57782+ default y if GRKERNSEC_CONFIG_AUTO
57783+ help
57784+ If you say Y here, all attempts to overstep resource limits will
57785+ be logged with the resource name, the requested size, and the current
57786+ limit. It is highly recommended that you say Y here. If the sysctl
57787+ option is enabled, a sysctl option with name "resource_logging" is
57788+ created. If the RBAC system is enabled, the sysctl value is ignored.
57789+
57790+config GRKERNSEC_CHROOT_EXECLOG
57791+ bool "Log execs within chroot"
57792+ help
57793+ If you say Y here, all executions inside a chroot jail will be logged
57794+ to syslog. This can cause a large amount of logs if certain
57795+ applications (eg. djb's daemontools) are installed on the system, and
57796+ is therefore left as an option. If the sysctl option is enabled, a
57797+ sysctl option with name "chroot_execlog" is created.
57798+
57799+config GRKERNSEC_AUDIT_PTRACE
57800+ bool "Ptrace logging"
57801+ help
57802+ If you say Y here, all attempts to attach to a process via ptrace
57803+ will be logged. If the sysctl option is enabled, a sysctl option
57804+ with name "audit_ptrace" is created.
57805+
57806+config GRKERNSEC_AUDIT_CHDIR
57807+ bool "Chdir logging"
57808+ help
57809+ If you say Y here, all chdir() calls will be logged. If the sysctl
57810+ option is enabled, a sysctl option with name "audit_chdir" is created.
57811+
57812+config GRKERNSEC_AUDIT_MOUNT
57813+ bool "(Un)Mount logging"
57814+ help
57815+ If you say Y here, all mounts and unmounts will be logged. If the
57816+ sysctl option is enabled, a sysctl option with name "audit_mount" is
57817+ created.
57818+
57819+config GRKERNSEC_SIGNAL
57820+ bool "Signal logging"
57821+ default y if GRKERNSEC_CONFIG_AUTO
57822+ help
57823+ If you say Y here, certain important signals will be logged, such as
57824+ SIGSEGV, which will as a result inform you of when a error in a program
57825+ occurred, which in some cases could mean a possible exploit attempt.
57826+ If the sysctl option is enabled, a sysctl option with name
57827+ "signal_logging" is created.
57828+
57829+config GRKERNSEC_FORKFAIL
57830+ bool "Fork failure logging"
57831+ help
57832+ If you say Y here, all failed fork() attempts will be logged.
57833+ This could suggest a fork bomb, or someone attempting to overstep
57834+ their process limit. If the sysctl option is enabled, a sysctl option
57835+ with name "forkfail_logging" is created.
57836+
57837+config GRKERNSEC_TIME
57838+ bool "Time change logging"
57839+ default y if GRKERNSEC_CONFIG_AUTO
57840+ help
57841+ If you say Y here, any changes of the system clock will be logged.
57842+ If the sysctl option is enabled, a sysctl option with name
57843+ "timechange_logging" is created.
57844+
57845+config GRKERNSEC_PROC_IPADDR
57846+ bool "/proc/<pid>/ipaddr support"
57847+ default y if GRKERNSEC_CONFIG_AUTO
57848+ help
57849+ If you say Y here, a new entry will be added to each /proc/<pid>
57850+ directory that contains the IP address of the person using the task.
57851+ The IP is carried across local TCP and AF_UNIX stream sockets.
57852+ This information can be useful for IDS/IPSes to perform remote response
57853+ to a local attack. The entry is readable by only the owner of the
57854+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
57855+ the RBAC system), and thus does not create privacy concerns.
57856+
57857+config GRKERNSEC_RWXMAP_LOG
57858+ bool 'Denied RWX mmap/mprotect logging'
57859+ default y if GRKERNSEC_CONFIG_AUTO
57860+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
57861+ help
57862+ If you say Y here, calls to mmap() and mprotect() with explicit
57863+ usage of PROT_WRITE and PROT_EXEC together will be logged when
57864+ denied by the PAX_MPROTECT feature. If the sysctl option is
57865+ enabled, a sysctl option with name "rwxmap_logging" is created.
57866+
57867+config GRKERNSEC_AUDIT_TEXTREL
57868+ bool 'ELF text relocations logging (READ HELP)'
57869+ depends on PAX_MPROTECT
57870+ help
57871+ If you say Y here, text relocations will be logged with the filename
57872+ of the offending library or binary. The purpose of the feature is
57873+ to help Linux distribution developers get rid of libraries and
57874+ binaries that need text relocations which hinder the future progress
57875+ of PaX. Only Linux distribution developers should say Y here, and
57876+ never on a production machine, as this option creates an information
57877+ leak that could aid an attacker in defeating the randomization of
57878+ a single memory region. If the sysctl option is enabled, a sysctl
57879+ option with name "audit_textrel" is created.
57880+
57881+endmenu
57882+
57883+menu "Executable Protections"
57884+depends on GRKERNSEC
57885+
57886+config GRKERNSEC_DMESG
57887+ bool "Dmesg(8) restriction"
57888+ default y if GRKERNSEC_CONFIG_AUTO
57889+ help
57890+ If you say Y here, non-root users will not be able to use dmesg(8)
57891+ to view the contents of the kernel's circular log buffer.
57892+ The kernel's log buffer often contains kernel addresses and other
57893+ identifying information useful to an attacker in fingerprinting a
57894+ system for a targeted exploit.
57895+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
57896+ created.
57897+
57898+config GRKERNSEC_HARDEN_PTRACE
57899+ bool "Deter ptrace-based process snooping"
57900+ default y if GRKERNSEC_CONFIG_AUTO
57901+ help
57902+ If you say Y here, TTY sniffers and other malicious monitoring
57903+ programs implemented through ptrace will be defeated. If you
57904+ have been using the RBAC system, this option has already been
57905+ enabled for several years for all users, with the ability to make
57906+ fine-grained exceptions.
57907+
57908+ This option only affects the ability of non-root users to ptrace
57909+ processes that are not a descendent of the ptracing process.
57910+ This means that strace ./binary and gdb ./binary will still work,
57911+ but attaching to arbitrary processes will not. If the sysctl
57912+ option is enabled, a sysctl option with name "harden_ptrace" is
57913+ created.
57914+
57915+config GRKERNSEC_PTRACE_READEXEC
57916+ bool "Require read access to ptrace sensitive binaries"
57917+ default y if GRKERNSEC_CONFIG_AUTO
57918+ help
57919+ If you say Y here, unprivileged users will not be able to ptrace unreadable
57920+ binaries. This option is useful in environments that
57921+ remove the read bits (e.g. file mode 4711) from suid binaries to
57922+ prevent infoleaking of their contents. This option adds
57923+ consistency to the use of that file mode, as the binary could normally
57924+ be read out when run without privileges while ptracing.
57925+
57926+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
57927+ is created.
57928+
57929+config GRKERNSEC_SETXID
57930+ bool "Enforce consistent multithreaded privileges"
57931+ default y if GRKERNSEC_CONFIG_AUTO
57932+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
57933+ help
57934+ If you say Y here, a change from a root uid to a non-root uid
57935+ in a multithreaded application will cause the resulting uids,
57936+ gids, supplementary groups, and capabilities in that thread
57937+ to be propagated to the other threads of the process. In most
57938+ cases this is unnecessary, as glibc will emulate this behavior
57939+ on behalf of the application. Other libcs do not act in the
57940+ same way, allowing the other threads of the process to continue
57941+ running with root privileges. If the sysctl option is enabled,
57942+ a sysctl option with name "consistent_setxid" is created.
57943+
57944+config GRKERNSEC_TPE
57945+ bool "Trusted Path Execution (TPE)"
57946+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57947+ help
57948+ If you say Y here, you will be able to choose a gid to add to the
57949+ supplementary groups of users you want to mark as "untrusted."
57950+ These users will not be able to execute any files that are not in
57951+ root-owned directories writable only by root. If the sysctl option
57952+ is enabled, a sysctl option with name "tpe" is created.
57953+
57954+config GRKERNSEC_TPE_ALL
57955+ bool "Partially restrict all non-root users"
57956+ depends on GRKERNSEC_TPE
57957+ help
57958+ If you say Y here, all non-root users will be covered under
57959+ a weaker TPE restriction. This is separate from, and in addition to,
57960+ the main TPE options that you have selected elsewhere. Thus, if a
57961+ "trusted" GID is chosen, this restriction applies to even that GID.
57962+ Under this restriction, all non-root users will only be allowed to
57963+ execute files in directories they own that are not group or
57964+ world-writable, or in directories owned by root and writable only by
57965+ root. If the sysctl option is enabled, a sysctl option with name
57966+ "tpe_restrict_all" is created.
57967+
57968+config GRKERNSEC_TPE_INVERT
57969+ bool "Invert GID option"
57970+ depends on GRKERNSEC_TPE
57971+ help
57972+ If you say Y here, the group you specify in the TPE configuration will
57973+ decide what group TPE restrictions will be *disabled* for. This
57974+ option is useful if you want TPE restrictions to be applied to most
57975+ users on the system. If the sysctl option is enabled, a sysctl option
57976+ with name "tpe_invert" is created. Unlike other sysctl options, this
57977+ entry will default to on for backward-compatibility.
57978+
57979+config GRKERNSEC_TPE_GID
57980+ int
57981+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
57982+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
57983+
57984+config GRKERNSEC_TPE_UNTRUSTED_GID
57985+ int "GID for TPE-untrusted users"
57986+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
57987+ default 1005
57988+ help
57989+ Setting this GID determines what group TPE restrictions will be
57990+ *enabled* for. If the sysctl option is enabled, a sysctl option
57991+ with name "tpe_gid" is created.
57992+
57993+config GRKERNSEC_TPE_TRUSTED_GID
57994+ int "GID for TPE-trusted users"
57995+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
57996+ default 1005
57997+ help
57998+ Setting this GID determines what group TPE restrictions will be
57999+ *disabled* for. If the sysctl option is enabled, a sysctl option
58000+ with name "tpe_gid" is created.
58001+
58002+endmenu
58003+menu "Network Protections"
58004+depends on GRKERNSEC
58005+
58006+config GRKERNSEC_RANDNET
58007+ bool "Larger entropy pools"
58008+ default y if GRKERNSEC_CONFIG_AUTO
58009+ help
58010+ If you say Y here, the entropy pools used for many features of Linux
58011+ and grsecurity will be doubled in size. Since several grsecurity
58012+ features use additional randomness, it is recommended that you say Y
58013+ here. Saying Y here has a similar effect as modifying
58014+ /proc/sys/kernel/random/poolsize.
58015+
58016+config GRKERNSEC_BLACKHOLE
58017+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
58018+ default y if GRKERNSEC_CONFIG_AUTO
58019+ depends on NET
58020+ help
58021+ If you say Y here, neither TCP resets nor ICMP
58022+ destination-unreachable packets will be sent in response to packets
58023+ sent to ports for which no associated listening process exists.
58024+ This feature supports both IPV4 and IPV6 and exempts the
58025+ loopback interface from blackholing. Enabling this feature
58026+ makes a host more resilient to DoS attacks and reduces network
58027+ visibility against scanners.
58028+
58029+ The blackhole feature as-implemented is equivalent to the FreeBSD
58030+ blackhole feature, as it prevents RST responses to all packets, not
58031+ just SYNs. Under most application behavior this causes no
58032+ problems, but applications (like haproxy) may not close certain
58033+ connections in a way that cleanly terminates them on the remote
58034+ end, leaving the remote host in LAST_ACK state. Because of this
58035+ side-effect and to prevent intentional LAST_ACK DoSes, this
58036+ feature also adds automatic mitigation against such attacks.
58037+ The mitigation drastically reduces the amount of time a socket
58038+ can spend in LAST_ACK state. If you're using haproxy and not
58039+ all servers it connects to have this option enabled, consider
58040+ disabling this feature on the haproxy host.
58041+
58042+ If the sysctl option is enabled, two sysctl options with names
58043+ "ip_blackhole" and "lastack_retries" will be created.
58044+ While "ip_blackhole" takes the standard zero/non-zero on/off
58045+ toggle, "lastack_retries" uses the same kinds of values as
58046+ "tcp_retries1" and "tcp_retries2". The default value of 4
58047+ prevents a socket from lasting more than 45 seconds in LAST_ACK
58048+ state.
58049+
58050+config GRKERNSEC_NO_SIMULT_CONNECT
58051+ bool "Disable TCP Simultaneous Connect"
58052+ default y if GRKERNSEC_CONFIG_AUTO
58053+ depends on NET
58054+ help
58055+ If you say Y here, a feature by Willy Tarreau will be enabled that
58056+ removes a weakness in Linux's strict implementation of TCP that
58057+ allows two clients to connect to each other without either entering
58058+ a listening state. The weakness allows an attacker to easily prevent
58059+ a client from connecting to a known server provided the source port
58060+ for the connection is guessed correctly.
58061+
58062+ As the weakness could be used to prevent an antivirus or IPS from
58063+ fetching updates, or prevent an SSL gateway from fetching a CRL,
58064+ it should be eliminated by enabling this option. Though Linux is
58065+ one of few operating systems supporting simultaneous connect, it
58066+ has no legitimate use in practice and is rarely supported by firewalls.
58067+
58068+config GRKERNSEC_SOCKET
58069+ bool "Socket restrictions"
58070+ depends on NET
58071+ help
58072+ If you say Y here, you will be able to choose from several options.
58073+ If you assign a GID on your system and add it to the supplementary
58074+ groups of users you want to restrict socket access to, this patch
58075+ will perform up to three things, based on the option(s) you choose.
58076+
58077+config GRKERNSEC_SOCKET_ALL
58078+ bool "Deny any sockets to group"
58079+ depends on GRKERNSEC_SOCKET
58080+ help
58081+ If you say Y here, you will be able to choose a GID of whose users will
58082+ be unable to connect to other hosts from your machine or run server
58083+ applications from your machine. If the sysctl option is enabled, a
58084+ sysctl option with name "socket_all" is created.
58085+
58086+config GRKERNSEC_SOCKET_ALL_GID
58087+ int "GID to deny all sockets for"
58088+ depends on GRKERNSEC_SOCKET_ALL
58089+ default 1004
58090+ help
58091+ Here you can choose the GID to disable socket access for. Remember to
58092+ add the users you want socket access disabled for to the GID
58093+ specified here. If the sysctl option is enabled, a sysctl option
58094+ with name "socket_all_gid" is created.
58095+
58096+config GRKERNSEC_SOCKET_CLIENT
58097+ bool "Deny client sockets to group"
58098+ depends on GRKERNSEC_SOCKET
58099+ help
58100+ If you say Y here, you will be able to choose a GID of whose users will
58101+ be unable to connect to other hosts from your machine, but will be
58102+ able to run servers. If this option is enabled, all users in the group
58103+ you specify will have to use passive mode when initiating ftp transfers
58104+ from the shell on your machine. If the sysctl option is enabled, a
58105+ sysctl option with name "socket_client" is created.
58106+
58107+config GRKERNSEC_SOCKET_CLIENT_GID
58108+ int "GID to deny client sockets for"
58109+ depends on GRKERNSEC_SOCKET_CLIENT
58110+ default 1003
58111+ help
58112+ Here you can choose the GID to disable client socket access for.
58113+ Remember to add the users you want client socket access disabled for to
58114+ the GID specified here. If the sysctl option is enabled, a sysctl
58115+ option with name "socket_client_gid" is created.
58116+
58117+config GRKERNSEC_SOCKET_SERVER
58118+ bool "Deny server sockets to group"
58119+ depends on GRKERNSEC_SOCKET
58120+ help
58121+ If you say Y here, you will be able to choose a GID of whose users will
58122+ be unable to run server applications from your machine. If the sysctl
58123+ option is enabled, a sysctl option with name "socket_server" is created.
58124+
58125+config GRKERNSEC_SOCKET_SERVER_GID
58126+ int "GID to deny server sockets for"
58127+ depends on GRKERNSEC_SOCKET_SERVER
58128+ default 1002
58129+ help
58130+ Here you can choose the GID to disable server socket access for.
58131+ Remember to add the users you want server socket access disabled for to
58132+ the GID specified here. If the sysctl option is enabled, a sysctl
58133+ option with name "socket_server_gid" is created.
58134+
58135+endmenu
58136+menu "Sysctl Support"
58137+depends on GRKERNSEC && SYSCTL
58138+
58139+config GRKERNSEC_SYSCTL
58140+ bool "Sysctl support"
58141+ default y if GRKERNSEC_CONFIG_AUTO
58142+ help
58143+ If you say Y here, you will be able to change the options that
58144+ grsecurity runs with at bootup, without having to recompile your
58145+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
58146+ to enable (1) or disable (0) various features. All the sysctl entries
58147+ are mutable until the "grsec_lock" entry is set to a non-zero value.
58148+ All features enabled in the kernel configuration are disabled at boot
58149+ if you do not say Y to the "Turn on features by default" option.
58150+ All options should be set at startup, and the grsec_lock entry should
58151+ be set to a non-zero value after all the options are set.
58152+ *THIS IS EXTREMELY IMPORTANT*
58153+
58154+config GRKERNSEC_SYSCTL_DISTRO
58155+ bool "Extra sysctl support for distro makers (READ HELP)"
58156+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
58157+ help
58158+ If you say Y here, additional sysctl options will be created
58159+ for features that affect processes running as root. Therefore,
58160+ it is critical when using this option that the grsec_lock entry be
58161+ enabled after boot. Only distros with prebuilt kernel packages
58162+ with this option enabled that can ensure grsec_lock is enabled
58163+ after boot should use this option.
58164+ *Failure to set grsec_lock after boot makes all grsec features
58165+ this option covers useless*
58166+
58167+ Currently this option creates the following sysctl entries:
58168+ "Disable Privileged I/O": "disable_priv_io"
58169+
58170+config GRKERNSEC_SYSCTL_ON
58171+ bool "Turn on features by default"
58172+ default y if GRKERNSEC_CONFIG_AUTO
58173+ depends on GRKERNSEC_SYSCTL
58174+ help
58175+ If you say Y here, instead of having all features enabled in the
58176+ kernel configuration disabled at boot time, the features will be
58177+ enabled at boot time. It is recommended you say Y here unless
58178+ there is some reason you would want all sysctl-tunable features to
58179+ be disabled by default. As mentioned elsewhere, it is important
58180+ to enable the grsec_lock entry once you have finished modifying
58181+ the sysctl entries.
58182+
58183+endmenu
58184+menu "Logging Options"
58185+depends on GRKERNSEC
58186+
58187+config GRKERNSEC_FLOODTIME
58188+ int "Seconds in between log messages (minimum)"
58189+ default 10
58190+ help
58191+ This option allows you to enforce the number of seconds between
58192+ grsecurity log messages. The default should be suitable for most
58193+ people, however, if you choose to change it, choose a value small enough
58194+ to allow informative logs to be produced, but large enough to
58195+ prevent flooding.
58196+
58197+config GRKERNSEC_FLOODBURST
58198+ int "Number of messages in a burst (maximum)"
58199+ default 6
58200+ help
58201+ This option allows you to choose the maximum number of messages allowed
58202+ within the flood time interval you chose in a separate option. The
58203+ default should be suitable for most people, however if you find that
58204+ many of your logs are being interpreted as flooding, you may want to
58205+ raise this value.
58206+
58207+endmenu
58208diff --git a/grsecurity/Makefile b/grsecurity/Makefile
58209new file mode 100644
58210index 0000000..1b9afa9
58211--- /dev/null
58212+++ b/grsecurity/Makefile
58213@@ -0,0 +1,38 @@
58214+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
58215+# during 2001-2009 it has been completely redesigned by Brad Spengler
58216+# into an RBAC system
58217+#
58218+# All code in this directory and various hooks inserted throughout the kernel
58219+# are copyright Brad Spengler - Open Source Security, Inc., and released
58220+# under the GPL v2 or higher
58221+
58222+KBUILD_CFLAGS += -Werror
58223+
58224+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
58225+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
58226+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
58227+
58228+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
58229+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
58230+ gracl_learn.o grsec_log.o
58231+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
58232+
58233+ifdef CONFIG_NET
58234+obj-y += grsec_sock.o
58235+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
58236+endif
58237+
58238+ifndef CONFIG_GRKERNSEC
58239+obj-y += grsec_disabled.o
58240+endif
58241+
58242+ifdef CONFIG_GRKERNSEC_HIDESYM
58243+extra-y := grsec_hidesym.o
58244+$(obj)/grsec_hidesym.o:
58245+ @-chmod -f 500 /boot
58246+ @-chmod -f 500 /lib/modules
58247+ @-chmod -f 500 /lib64/modules
58248+ @-chmod -f 500 /lib32/modules
58249+ @-chmod -f 700 .
58250+ @echo ' grsec: protected kernel image paths'
58251+endif
58252diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
58253new file mode 100644
58254index 0000000..0d5c602
58255--- /dev/null
58256+++ b/grsecurity/gracl.c
58257@@ -0,0 +1,4073 @@
58258+#include <linux/kernel.h>
58259+#include <linux/module.h>
58260+#include <linux/sched.h>
58261+#include <linux/mm.h>
58262+#include <linux/file.h>
58263+#include <linux/fs.h>
58264+#include <linux/namei.h>
58265+#include <linux/mount.h>
58266+#include <linux/tty.h>
58267+#include <linux/proc_fs.h>
58268+#include <linux/lglock.h>
58269+#include <linux/slab.h>
58270+#include <linux/vmalloc.h>
58271+#include <linux/types.h>
58272+#include <linux/sysctl.h>
58273+#include <linux/netdevice.h>
58274+#include <linux/ptrace.h>
58275+#include <linux/gracl.h>
58276+#include <linux/gralloc.h>
58277+#include <linux/security.h>
58278+#include <linux/grinternal.h>
58279+#include <linux/pid_namespace.h>
58280+#include <linux/stop_machine.h>
58281+#include <linux/fdtable.h>
58282+#include <linux/percpu.h>
58283+#include <linux/lglock.h>
58284+#include <linux/hugetlb.h>
58285+#include <linux/posix-timers.h>
58286+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58287+#include <linux/magic.h>
58288+#include <linux/pagemap.h>
58289+#include "../fs/btrfs/async-thread.h"
58290+#include "../fs/btrfs/ctree.h"
58291+#include "../fs/btrfs/btrfs_inode.h"
58292+#endif
58293+#include "../fs/mount.h"
58294+
58295+#include <asm/uaccess.h>
58296+#include <asm/errno.h>
58297+#include <asm/mman.h>
58298+
58299+extern struct lglock vfsmount_lock;
58300+
58301+static struct acl_role_db acl_role_set;
58302+static struct name_db name_set;
58303+static struct inodev_db inodev_set;
58304+
58305+/* for keeping track of userspace pointers used for subjects, so we
58306+ can share references in the kernel as well
58307+*/
58308+
58309+static struct path real_root;
58310+
58311+static struct acl_subj_map_db subj_map_set;
58312+
58313+static struct acl_role_label *default_role;
58314+
58315+static struct acl_role_label *role_list;
58316+
58317+static u16 acl_sp_role_value;
58318+
58319+extern char *gr_shared_page[4];
58320+static DEFINE_MUTEX(gr_dev_mutex);
58321+DEFINE_RWLOCK(gr_inode_lock);
58322+
58323+struct gr_arg *gr_usermode;
58324+
58325+static unsigned int gr_status __read_only = GR_STATUS_INIT;
58326+
58327+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
58328+extern void gr_clear_learn_entries(void);
58329+
58330+unsigned char *gr_system_salt;
58331+unsigned char *gr_system_sum;
58332+
58333+static struct sprole_pw **acl_special_roles = NULL;
58334+static __u16 num_sprole_pws = 0;
58335+
58336+static struct acl_role_label *kernel_role = NULL;
58337+
58338+static unsigned int gr_auth_attempts = 0;
58339+static unsigned long gr_auth_expires = 0UL;
58340+
58341+#ifdef CONFIG_NET
58342+extern struct vfsmount *sock_mnt;
58343+#endif
58344+
58345+extern struct vfsmount *pipe_mnt;
58346+extern struct vfsmount *shm_mnt;
58347+
58348+#ifdef CONFIG_HUGETLBFS
58349+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58350+#endif
58351+
58352+static struct acl_object_label *fakefs_obj_rw;
58353+static struct acl_object_label *fakefs_obj_rwx;
58354+
58355+extern int gr_init_uidset(void);
58356+extern void gr_free_uidset(void);
58357+extern void gr_remove_uid(uid_t uid);
58358+extern int gr_find_uid(uid_t uid);
58359+
58360+__inline__ int
58361+gr_acl_is_enabled(void)
58362+{
58363+ return (gr_status & GR_READY);
58364+}
58365+
58366+static inline dev_t __get_dev(const struct dentry *dentry)
58367+{
58368+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58369+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
58370+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
58371+ else
58372+#endif
58373+ return dentry->d_sb->s_dev;
58374+}
58375+
58376+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58377+{
58378+ return __get_dev(dentry);
58379+}
58380+
58381+static char gr_task_roletype_to_char(struct task_struct *task)
58382+{
58383+ switch (task->role->roletype &
58384+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
58385+ GR_ROLE_SPECIAL)) {
58386+ case GR_ROLE_DEFAULT:
58387+ return 'D';
58388+ case GR_ROLE_USER:
58389+ return 'U';
58390+ case GR_ROLE_GROUP:
58391+ return 'G';
58392+ case GR_ROLE_SPECIAL:
58393+ return 'S';
58394+ }
58395+
58396+ return 'X';
58397+}
58398+
58399+char gr_roletype_to_char(void)
58400+{
58401+ return gr_task_roletype_to_char(current);
58402+}
58403+
58404+__inline__ int
58405+gr_acl_tpe_check(void)
58406+{
58407+ if (unlikely(!(gr_status & GR_READY)))
58408+ return 0;
58409+ if (current->role->roletype & GR_ROLE_TPE)
58410+ return 1;
58411+ else
58412+ return 0;
58413+}
58414+
58415+int
58416+gr_handle_rawio(const struct inode *inode)
58417+{
58418+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58419+ if (inode && S_ISBLK(inode->i_mode) &&
58420+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58421+ !capable(CAP_SYS_RAWIO))
58422+ return 1;
58423+#endif
58424+ return 0;
58425+}
58426+
58427+static int
58428+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
58429+{
58430+ if (likely(lena != lenb))
58431+ return 0;
58432+
58433+ return !memcmp(a, b, lena);
58434+}
58435+
58436+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
58437+{
58438+ *buflen -= namelen;
58439+ if (*buflen < 0)
58440+ return -ENAMETOOLONG;
58441+ *buffer -= namelen;
58442+ memcpy(*buffer, str, namelen);
58443+ return 0;
58444+}
58445+
58446+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
58447+{
58448+ return prepend(buffer, buflen, name->name, name->len);
58449+}
58450+
58451+static int prepend_path(const struct path *path, struct path *root,
58452+ char **buffer, int *buflen)
58453+{
58454+ struct dentry *dentry = path->dentry;
58455+ struct vfsmount *vfsmnt = path->mnt;
58456+ struct mount *mnt = real_mount(vfsmnt);
58457+ bool slash = false;
58458+ int error = 0;
58459+
58460+ while (dentry != root->dentry || vfsmnt != root->mnt) {
58461+ struct dentry * parent;
58462+
58463+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
58464+ /* Global root? */
58465+ if (!mnt_has_parent(mnt)) {
58466+ goto out;
58467+ }
58468+ dentry = mnt->mnt_mountpoint;
58469+ mnt = mnt->mnt_parent;
58470+ vfsmnt = &mnt->mnt;
58471+ continue;
58472+ }
58473+ parent = dentry->d_parent;
58474+ prefetch(parent);
58475+ spin_lock(&dentry->d_lock);
58476+ error = prepend_name(buffer, buflen, &dentry->d_name);
58477+ spin_unlock(&dentry->d_lock);
58478+ if (!error)
58479+ error = prepend(buffer, buflen, "/", 1);
58480+ if (error)
58481+ break;
58482+
58483+ slash = true;
58484+ dentry = parent;
58485+ }
58486+
58487+out:
58488+ if (!error && !slash)
58489+ error = prepend(buffer, buflen, "/", 1);
58490+
58491+ return error;
58492+}
58493+
58494+/* this must be called with vfsmount_lock and rename_lock held */
58495+
58496+static char *__our_d_path(const struct path *path, struct path *root,
58497+ char *buf, int buflen)
58498+{
58499+ char *res = buf + buflen;
58500+ int error;
58501+
58502+ prepend(&res, &buflen, "\0", 1);
58503+ error = prepend_path(path, root, &res, &buflen);
58504+ if (error)
58505+ return ERR_PTR(error);
58506+
58507+ return res;
58508+}
58509+
58510+static char *
58511+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
58512+{
58513+ char *retval;
58514+
58515+ retval = __our_d_path(path, root, buf, buflen);
58516+ if (unlikely(IS_ERR(retval)))
58517+ retval = strcpy(buf, "<path too long>");
58518+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
58519+ retval[1] = '\0';
58520+
58521+ return retval;
58522+}
58523+
58524+static char *
58525+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58526+ char *buf, int buflen)
58527+{
58528+ struct path path;
58529+ char *res;
58530+
58531+ path.dentry = (struct dentry *)dentry;
58532+ path.mnt = (struct vfsmount *)vfsmnt;
58533+
58534+ /* we can use real_root.dentry, real_root.mnt, because this is only called
58535+ by the RBAC system */
58536+ res = gen_full_path(&path, &real_root, buf, buflen);
58537+
58538+ return res;
58539+}
58540+
58541+static char *
58542+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58543+ char *buf, int buflen)
58544+{
58545+ char *res;
58546+ struct path path;
58547+ struct path root;
58548+ struct task_struct *reaper = init_pid_ns.child_reaper;
58549+
58550+ path.dentry = (struct dentry *)dentry;
58551+ path.mnt = (struct vfsmount *)vfsmnt;
58552+
58553+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
58554+ get_fs_root(reaper->fs, &root);
58555+
58556+ br_read_lock(&vfsmount_lock);
58557+ write_seqlock(&rename_lock);
58558+ res = gen_full_path(&path, &root, buf, buflen);
58559+ write_sequnlock(&rename_lock);
58560+ br_read_unlock(&vfsmount_lock);
58561+
58562+ path_put(&root);
58563+ return res;
58564+}
58565+
58566+static char *
58567+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58568+{
58569+ char *ret;
58570+ br_read_lock(&vfsmount_lock);
58571+ write_seqlock(&rename_lock);
58572+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58573+ PAGE_SIZE);
58574+ write_sequnlock(&rename_lock);
58575+ br_read_unlock(&vfsmount_lock);
58576+ return ret;
58577+}
58578+
58579+static char *
58580+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58581+{
58582+ char *ret;
58583+ char *buf;
58584+ int buflen;
58585+
58586+ br_read_lock(&vfsmount_lock);
58587+ write_seqlock(&rename_lock);
58588+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
58589+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
58590+ buflen = (int)(ret - buf);
58591+ if (buflen >= 5)
58592+ prepend(&ret, &buflen, "/proc", 5);
58593+ else
58594+ ret = strcpy(buf, "<path too long>");
58595+ write_sequnlock(&rename_lock);
58596+ br_read_unlock(&vfsmount_lock);
58597+ return ret;
58598+}
58599+
58600+char *
58601+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
58602+{
58603+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58604+ PAGE_SIZE);
58605+}
58606+
58607+char *
58608+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
58609+{
58610+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58611+ PAGE_SIZE);
58612+}
58613+
58614+char *
58615+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
58616+{
58617+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
58618+ PAGE_SIZE);
58619+}
58620+
58621+char *
58622+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
58623+{
58624+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
58625+ PAGE_SIZE);
58626+}
58627+
58628+char *
58629+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
58630+{
58631+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
58632+ PAGE_SIZE);
58633+}
58634+
58635+__inline__ __u32
58636+to_gr_audit(const __u32 reqmode)
58637+{
58638+ /* masks off auditable permission flags, then shifts them to create
58639+ auditing flags, and adds the special case of append auditing if
58640+ we're requesting write */
58641+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
58642+}
58643+
58644+struct acl_subject_label *
58645+lookup_subject_map(const struct acl_subject_label *userp)
58646+{
58647+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
58648+ struct subject_map *match;
58649+
58650+ match = subj_map_set.s_hash[index];
58651+
58652+ while (match && match->user != userp)
58653+ match = match->next;
58654+
58655+ if (match != NULL)
58656+ return match->kernel;
58657+ else
58658+ return NULL;
58659+}
58660+
58661+static void
58662+insert_subj_map_entry(struct subject_map *subjmap)
58663+{
58664+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
58665+ struct subject_map **curr;
58666+
58667+ subjmap->prev = NULL;
58668+
58669+ curr = &subj_map_set.s_hash[index];
58670+ if (*curr != NULL)
58671+ (*curr)->prev = subjmap;
58672+
58673+ subjmap->next = *curr;
58674+ *curr = subjmap;
58675+
58676+ return;
58677+}
58678+
58679+static struct acl_role_label *
58680+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
58681+ const gid_t gid)
58682+{
58683+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
58684+ struct acl_role_label *match;
58685+ struct role_allowed_ip *ipp;
58686+ unsigned int x;
58687+ u32 curr_ip = task->signal->curr_ip;
58688+
58689+ task->signal->saved_ip = curr_ip;
58690+
58691+ match = acl_role_set.r_hash[index];
58692+
58693+ while (match) {
58694+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
58695+ for (x = 0; x < match->domain_child_num; x++) {
58696+ if (match->domain_children[x] == uid)
58697+ goto found;
58698+ }
58699+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
58700+ break;
58701+ match = match->next;
58702+ }
58703+found:
58704+ if (match == NULL) {
58705+ try_group:
58706+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
58707+ match = acl_role_set.r_hash[index];
58708+
58709+ while (match) {
58710+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
58711+ for (x = 0; x < match->domain_child_num; x++) {
58712+ if (match->domain_children[x] == gid)
58713+ goto found2;
58714+ }
58715+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
58716+ break;
58717+ match = match->next;
58718+ }
58719+found2:
58720+ if (match == NULL)
58721+ match = default_role;
58722+ if (match->allowed_ips == NULL)
58723+ return match;
58724+ else {
58725+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58726+ if (likely
58727+ ((ntohl(curr_ip) & ipp->netmask) ==
58728+ (ntohl(ipp->addr) & ipp->netmask)))
58729+ return match;
58730+ }
58731+ match = default_role;
58732+ }
58733+ } else if (match->allowed_ips == NULL) {
58734+ return match;
58735+ } else {
58736+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58737+ if (likely
58738+ ((ntohl(curr_ip) & ipp->netmask) ==
58739+ (ntohl(ipp->addr) & ipp->netmask)))
58740+ return match;
58741+ }
58742+ goto try_group;
58743+ }
58744+
58745+ return match;
58746+}
58747+
58748+struct acl_subject_label *
58749+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
58750+ const struct acl_role_label *role)
58751+{
58752+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58753+ struct acl_subject_label *match;
58754+
58755+ match = role->subj_hash[index];
58756+
58757+ while (match && (match->inode != ino || match->device != dev ||
58758+ (match->mode & GR_DELETED))) {
58759+ match = match->next;
58760+ }
58761+
58762+ if (match && !(match->mode & GR_DELETED))
58763+ return match;
58764+ else
58765+ return NULL;
58766+}
58767+
58768+struct acl_subject_label *
58769+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
58770+ const struct acl_role_label *role)
58771+{
58772+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58773+ struct acl_subject_label *match;
58774+
58775+ match = role->subj_hash[index];
58776+
58777+ while (match && (match->inode != ino || match->device != dev ||
58778+ !(match->mode & GR_DELETED))) {
58779+ match = match->next;
58780+ }
58781+
58782+ if (match && (match->mode & GR_DELETED))
58783+ return match;
58784+ else
58785+ return NULL;
58786+}
58787+
58788+static struct acl_object_label *
58789+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
58790+ const struct acl_subject_label *subj)
58791+{
58792+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58793+ struct acl_object_label *match;
58794+
58795+ match = subj->obj_hash[index];
58796+
58797+ while (match && (match->inode != ino || match->device != dev ||
58798+ (match->mode & GR_DELETED))) {
58799+ match = match->next;
58800+ }
58801+
58802+ if (match && !(match->mode & GR_DELETED))
58803+ return match;
58804+ else
58805+ return NULL;
58806+}
58807+
58808+static struct acl_object_label *
58809+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
58810+ const struct acl_subject_label *subj)
58811+{
58812+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58813+ struct acl_object_label *match;
58814+
58815+ match = subj->obj_hash[index];
58816+
58817+ while (match && (match->inode != ino || match->device != dev ||
58818+ !(match->mode & GR_DELETED))) {
58819+ match = match->next;
58820+ }
58821+
58822+ if (match && (match->mode & GR_DELETED))
58823+ return match;
58824+
58825+ match = subj->obj_hash[index];
58826+
58827+ while (match && (match->inode != ino || match->device != dev ||
58828+ (match->mode & GR_DELETED))) {
58829+ match = match->next;
58830+ }
58831+
58832+ if (match && !(match->mode & GR_DELETED))
58833+ return match;
58834+ else
58835+ return NULL;
58836+}
58837+
58838+static struct name_entry *
58839+lookup_name_entry(const char *name)
58840+{
58841+ unsigned int len = strlen(name);
58842+ unsigned int key = full_name_hash(name, len);
58843+ unsigned int index = key % name_set.n_size;
58844+ struct name_entry *match;
58845+
58846+ match = name_set.n_hash[index];
58847+
58848+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
58849+ match = match->next;
58850+
58851+ return match;
58852+}
58853+
58854+static struct name_entry *
58855+lookup_name_entry_create(const char *name)
58856+{
58857+ unsigned int len = strlen(name);
58858+ unsigned int key = full_name_hash(name, len);
58859+ unsigned int index = key % name_set.n_size;
58860+ struct name_entry *match;
58861+
58862+ match = name_set.n_hash[index];
58863+
58864+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58865+ !match->deleted))
58866+ match = match->next;
58867+
58868+ if (match && match->deleted)
58869+ return match;
58870+
58871+ match = name_set.n_hash[index];
58872+
58873+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58874+ match->deleted))
58875+ match = match->next;
58876+
58877+ if (match && !match->deleted)
58878+ return match;
58879+ else
58880+ return NULL;
58881+}
58882+
58883+static struct inodev_entry *
58884+lookup_inodev_entry(const ino_t ino, const dev_t dev)
58885+{
58886+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
58887+ struct inodev_entry *match;
58888+
58889+ match = inodev_set.i_hash[index];
58890+
58891+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
58892+ match = match->next;
58893+
58894+ return match;
58895+}
58896+
58897+static void
58898+insert_inodev_entry(struct inodev_entry *entry)
58899+{
58900+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
58901+ inodev_set.i_size);
58902+ struct inodev_entry **curr;
58903+
58904+ entry->prev = NULL;
58905+
58906+ curr = &inodev_set.i_hash[index];
58907+ if (*curr != NULL)
58908+ (*curr)->prev = entry;
58909+
58910+ entry->next = *curr;
58911+ *curr = entry;
58912+
58913+ return;
58914+}
58915+
58916+static void
58917+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
58918+{
58919+ unsigned int index =
58920+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
58921+ struct acl_role_label **curr;
58922+ struct acl_role_label *tmp, *tmp2;
58923+
58924+ curr = &acl_role_set.r_hash[index];
58925+
58926+ /* simple case, slot is empty, just set it to our role */
58927+ if (*curr == NULL) {
58928+ *curr = role;
58929+ } else {
58930+ /* example:
58931+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
58932+ 2 -> 3
58933+ */
58934+ /* first check to see if we can already be reached via this slot */
58935+ tmp = *curr;
58936+ while (tmp && tmp != role)
58937+ tmp = tmp->next;
58938+ if (tmp == role) {
58939+ /* we don't need to add ourselves to this slot's chain */
58940+ return;
58941+ }
58942+ /* we need to add ourselves to this chain, two cases */
58943+ if (role->next == NULL) {
58944+ /* simple case, append the current chain to our role */
58945+ role->next = *curr;
58946+ *curr = role;
58947+ } else {
58948+ /* 1 -> 2 -> 3 -> 4
58949+ 2 -> 3 -> 4
58950+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
58951+ */
58952+ /* trickier case: walk our role's chain until we find
58953+ the role for the start of the current slot's chain */
58954+ tmp = role;
58955+ tmp2 = *curr;
58956+ while (tmp->next && tmp->next != tmp2)
58957+ tmp = tmp->next;
58958+ if (tmp->next == tmp2) {
58959+ /* from example above, we found 3, so just
58960+ replace this slot's chain with ours */
58961+ *curr = role;
58962+ } else {
58963+ /* we didn't find a subset of our role's chain
58964+ in the current slot's chain, so append their
58965+ chain to ours, and set us as the first role in
58966+ the slot's chain
58967+
58968+ we could fold this case with the case above,
58969+ but making it explicit for clarity
58970+ */
58971+ tmp->next = tmp2;
58972+ *curr = role;
58973+ }
58974+ }
58975+ }
58976+
58977+ return;
58978+}
58979+
58980+static void
58981+insert_acl_role_label(struct acl_role_label *role)
58982+{
58983+ int i;
58984+
58985+ if (role_list == NULL) {
58986+ role_list = role;
58987+ role->prev = NULL;
58988+ } else {
58989+ role->prev = role_list;
58990+ role_list = role;
58991+ }
58992+
58993+ /* used for hash chains */
58994+ role->next = NULL;
58995+
58996+ if (role->roletype & GR_ROLE_DOMAIN) {
58997+ for (i = 0; i < role->domain_child_num; i++)
58998+ __insert_acl_role_label(role, role->domain_children[i]);
58999+ } else
59000+ __insert_acl_role_label(role, role->uidgid);
59001+}
59002+
59003+static int
59004+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
59005+{
59006+ struct name_entry **curr, *nentry;
59007+ struct inodev_entry *ientry;
59008+ unsigned int len = strlen(name);
59009+ unsigned int key = full_name_hash(name, len);
59010+ unsigned int index = key % name_set.n_size;
59011+
59012+ curr = &name_set.n_hash[index];
59013+
59014+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
59015+ curr = &((*curr)->next);
59016+
59017+ if (*curr != NULL)
59018+ return 1;
59019+
59020+ nentry = acl_alloc(sizeof (struct name_entry));
59021+ if (nentry == NULL)
59022+ return 0;
59023+ ientry = acl_alloc(sizeof (struct inodev_entry));
59024+ if (ientry == NULL)
59025+ return 0;
59026+ ientry->nentry = nentry;
59027+
59028+ nentry->key = key;
59029+ nentry->name = name;
59030+ nentry->inode = inode;
59031+ nentry->device = device;
59032+ nentry->len = len;
59033+ nentry->deleted = deleted;
59034+
59035+ nentry->prev = NULL;
59036+ curr = &name_set.n_hash[index];
59037+ if (*curr != NULL)
59038+ (*curr)->prev = nentry;
59039+ nentry->next = *curr;
59040+ *curr = nentry;
59041+
59042+ /* insert us into the table searchable by inode/dev */
59043+ insert_inodev_entry(ientry);
59044+
59045+ return 1;
59046+}
59047+
59048+static void
59049+insert_acl_obj_label(struct acl_object_label *obj,
59050+ struct acl_subject_label *subj)
59051+{
59052+ unsigned int index =
59053+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
59054+ struct acl_object_label **curr;
59055+
59056+
59057+ obj->prev = NULL;
59058+
59059+ curr = &subj->obj_hash[index];
59060+ if (*curr != NULL)
59061+ (*curr)->prev = obj;
59062+
59063+ obj->next = *curr;
59064+ *curr = obj;
59065+
59066+ return;
59067+}
59068+
59069+static void
59070+insert_acl_subj_label(struct acl_subject_label *obj,
59071+ struct acl_role_label *role)
59072+{
59073+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
59074+ struct acl_subject_label **curr;
59075+
59076+ obj->prev = NULL;
59077+
59078+ curr = &role->subj_hash[index];
59079+ if (*curr != NULL)
59080+ (*curr)->prev = obj;
59081+
59082+ obj->next = *curr;
59083+ *curr = obj;
59084+
59085+ return;
59086+}
59087+
59088+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
59089+
59090+static void *
59091+create_table(__u32 * len, int elementsize)
59092+{
59093+ unsigned int table_sizes[] = {
59094+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
59095+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
59096+ 4194301, 8388593, 16777213, 33554393, 67108859
59097+ };
59098+ void *newtable = NULL;
59099+ unsigned int pwr = 0;
59100+
59101+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
59102+ table_sizes[pwr] <= *len)
59103+ pwr++;
59104+
59105+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
59106+ return newtable;
59107+
59108+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
59109+ newtable =
59110+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
59111+ else
59112+ newtable = vmalloc(table_sizes[pwr] * elementsize);
59113+
59114+ *len = table_sizes[pwr];
59115+
59116+ return newtable;
59117+}
59118+
59119+static int
59120+init_variables(const struct gr_arg *arg)
59121+{
59122+ struct task_struct *reaper = init_pid_ns.child_reaper;
59123+ unsigned int stacksize;
59124+
59125+ subj_map_set.s_size = arg->role_db.num_subjects;
59126+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
59127+ name_set.n_size = arg->role_db.num_objects;
59128+ inodev_set.i_size = arg->role_db.num_objects;
59129+
59130+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
59131+ !name_set.n_size || !inodev_set.i_size)
59132+ return 1;
59133+
59134+ if (!gr_init_uidset())
59135+ return 1;
59136+
59137+ /* set up the stack that holds allocation info */
59138+
59139+ stacksize = arg->role_db.num_pointers + 5;
59140+
59141+ if (!acl_alloc_stack_init(stacksize))
59142+ return 1;
59143+
59144+ /* grab reference for the real root dentry and vfsmount */
59145+ get_fs_root(reaper->fs, &real_root);
59146+
59147+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59148+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
59149+#endif
59150+
59151+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
59152+ if (fakefs_obj_rw == NULL)
59153+ return 1;
59154+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
59155+
59156+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
59157+ if (fakefs_obj_rwx == NULL)
59158+ return 1;
59159+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
59160+
59161+ subj_map_set.s_hash =
59162+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
59163+ acl_role_set.r_hash =
59164+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
59165+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
59166+ inodev_set.i_hash =
59167+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
59168+
59169+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
59170+ !name_set.n_hash || !inodev_set.i_hash)
59171+ return 1;
59172+
59173+ memset(subj_map_set.s_hash, 0,
59174+ sizeof(struct subject_map *) * subj_map_set.s_size);
59175+ memset(acl_role_set.r_hash, 0,
59176+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
59177+ memset(name_set.n_hash, 0,
59178+ sizeof (struct name_entry *) * name_set.n_size);
59179+ memset(inodev_set.i_hash, 0,
59180+ sizeof (struct inodev_entry *) * inodev_set.i_size);
59181+
59182+ return 0;
59183+}
59184+
59185+/* free information not needed after startup
59186+ currently contains user->kernel pointer mappings for subjects
59187+*/
59188+
59189+static void
59190+free_init_variables(void)
59191+{
59192+ __u32 i;
59193+
59194+ if (subj_map_set.s_hash) {
59195+ for (i = 0; i < subj_map_set.s_size; i++) {
59196+ if (subj_map_set.s_hash[i]) {
59197+ kfree(subj_map_set.s_hash[i]);
59198+ subj_map_set.s_hash[i] = NULL;
59199+ }
59200+ }
59201+
59202+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
59203+ PAGE_SIZE)
59204+ kfree(subj_map_set.s_hash);
59205+ else
59206+ vfree(subj_map_set.s_hash);
59207+ }
59208+
59209+ return;
59210+}
59211+
59212+static void
59213+free_variables(void)
59214+{
59215+ struct acl_subject_label *s;
59216+ struct acl_role_label *r;
59217+ struct task_struct *task, *task2;
59218+ unsigned int x;
59219+
59220+ gr_clear_learn_entries();
59221+
59222+ read_lock(&tasklist_lock);
59223+ do_each_thread(task2, task) {
59224+ task->acl_sp_role = 0;
59225+ task->acl_role_id = 0;
59226+ task->acl = NULL;
59227+ task->role = NULL;
59228+ } while_each_thread(task2, task);
59229+ read_unlock(&tasklist_lock);
59230+
59231+ /* release the reference to the real root dentry and vfsmount */
59232+ path_put(&real_root);
59233+ memset(&real_root, 0, sizeof(real_root));
59234+
59235+ /* free all object hash tables */
59236+
59237+ FOR_EACH_ROLE_START(r)
59238+ if (r->subj_hash == NULL)
59239+ goto next_role;
59240+ FOR_EACH_SUBJECT_START(r, s, x)
59241+ if (s->obj_hash == NULL)
59242+ break;
59243+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59244+ kfree(s->obj_hash);
59245+ else
59246+ vfree(s->obj_hash);
59247+ FOR_EACH_SUBJECT_END(s, x)
59248+ FOR_EACH_NESTED_SUBJECT_START(r, s)
59249+ if (s->obj_hash == NULL)
59250+ break;
59251+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59252+ kfree(s->obj_hash);
59253+ else
59254+ vfree(s->obj_hash);
59255+ FOR_EACH_NESTED_SUBJECT_END(s)
59256+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
59257+ kfree(r->subj_hash);
59258+ else
59259+ vfree(r->subj_hash);
59260+ r->subj_hash = NULL;
59261+next_role:
59262+ FOR_EACH_ROLE_END(r)
59263+
59264+ acl_free_all();
59265+
59266+ if (acl_role_set.r_hash) {
59267+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
59268+ PAGE_SIZE)
59269+ kfree(acl_role_set.r_hash);
59270+ else
59271+ vfree(acl_role_set.r_hash);
59272+ }
59273+ if (name_set.n_hash) {
59274+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
59275+ PAGE_SIZE)
59276+ kfree(name_set.n_hash);
59277+ else
59278+ vfree(name_set.n_hash);
59279+ }
59280+
59281+ if (inodev_set.i_hash) {
59282+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
59283+ PAGE_SIZE)
59284+ kfree(inodev_set.i_hash);
59285+ else
59286+ vfree(inodev_set.i_hash);
59287+ }
59288+
59289+ gr_free_uidset();
59290+
59291+ memset(&name_set, 0, sizeof (struct name_db));
59292+ memset(&inodev_set, 0, sizeof (struct inodev_db));
59293+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
59294+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
59295+
59296+ default_role = NULL;
59297+ kernel_role = NULL;
59298+ role_list = NULL;
59299+
59300+ return;
59301+}
59302+
59303+static __u32
59304+count_user_objs(struct acl_object_label *userp)
59305+{
59306+ struct acl_object_label o_tmp;
59307+ __u32 num = 0;
59308+
59309+ while (userp) {
59310+ if (copy_from_user(&o_tmp, userp,
59311+ sizeof (struct acl_object_label)))
59312+ break;
59313+
59314+ userp = o_tmp.prev;
59315+ num++;
59316+ }
59317+
59318+ return num;
59319+}
59320+
59321+static struct acl_subject_label *
59322+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
59323+
59324+static int
59325+copy_user_glob(struct acl_object_label *obj)
59326+{
59327+ struct acl_object_label *g_tmp, **guser;
59328+ unsigned int len;
59329+ char *tmp;
59330+
59331+ if (obj->globbed == NULL)
59332+ return 0;
59333+
59334+ guser = &obj->globbed;
59335+ while (*guser) {
59336+ g_tmp = (struct acl_object_label *)
59337+ acl_alloc(sizeof (struct acl_object_label));
59338+ if (g_tmp == NULL)
59339+ return -ENOMEM;
59340+
59341+ if (copy_from_user(g_tmp, *guser,
59342+ sizeof (struct acl_object_label)))
59343+ return -EFAULT;
59344+
59345+ len = strnlen_user(g_tmp->filename, PATH_MAX);
59346+
59347+ if (!len || len >= PATH_MAX)
59348+ return -EINVAL;
59349+
59350+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59351+ return -ENOMEM;
59352+
59353+ if (copy_from_user(tmp, g_tmp->filename, len))
59354+ return -EFAULT;
59355+ tmp[len-1] = '\0';
59356+ g_tmp->filename = tmp;
59357+
59358+ *guser = g_tmp;
59359+ guser = &(g_tmp->next);
59360+ }
59361+
59362+ return 0;
59363+}
59364+
59365+static int
59366+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
59367+ struct acl_role_label *role)
59368+{
59369+ struct acl_object_label *o_tmp;
59370+ unsigned int len;
59371+ int ret;
59372+ char *tmp;
59373+
59374+ while (userp) {
59375+ if ((o_tmp = (struct acl_object_label *)
59376+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
59377+ return -ENOMEM;
59378+
59379+ if (copy_from_user(o_tmp, userp,
59380+ sizeof (struct acl_object_label)))
59381+ return -EFAULT;
59382+
59383+ userp = o_tmp->prev;
59384+
59385+ len = strnlen_user(o_tmp->filename, PATH_MAX);
59386+
59387+ if (!len || len >= PATH_MAX)
59388+ return -EINVAL;
59389+
59390+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59391+ return -ENOMEM;
59392+
59393+ if (copy_from_user(tmp, o_tmp->filename, len))
59394+ return -EFAULT;
59395+ tmp[len-1] = '\0';
59396+ o_tmp->filename = tmp;
59397+
59398+ insert_acl_obj_label(o_tmp, subj);
59399+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
59400+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
59401+ return -ENOMEM;
59402+
59403+ ret = copy_user_glob(o_tmp);
59404+ if (ret)
59405+ return ret;
59406+
59407+ if (o_tmp->nested) {
59408+ int already_copied;
59409+
59410+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
59411+ if (IS_ERR(o_tmp->nested))
59412+ return PTR_ERR(o_tmp->nested);
59413+
59414+ /* insert into nested subject list if we haven't copied this one yet
59415+ to prevent duplicate entries */
59416+ if (!already_copied) {
59417+ o_tmp->nested->next = role->hash->first;
59418+ role->hash->first = o_tmp->nested;
59419+ }
59420+ }
59421+ }
59422+
59423+ return 0;
59424+}
59425+
59426+static __u32
59427+count_user_subjs(struct acl_subject_label *userp)
59428+{
59429+ struct acl_subject_label s_tmp;
59430+ __u32 num = 0;
59431+
59432+ while (userp) {
59433+ if (copy_from_user(&s_tmp, userp,
59434+ sizeof (struct acl_subject_label)))
59435+ break;
59436+
59437+ userp = s_tmp.prev;
59438+ }
59439+
59440+ return num;
59441+}
59442+
59443+static int
59444+copy_user_allowedips(struct acl_role_label *rolep)
59445+{
59446+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
59447+
59448+ ruserip = rolep->allowed_ips;
59449+
59450+ while (ruserip) {
59451+ rlast = rtmp;
59452+
59453+ if ((rtmp = (struct role_allowed_ip *)
59454+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
59455+ return -ENOMEM;
59456+
59457+ if (copy_from_user(rtmp, ruserip,
59458+ sizeof (struct role_allowed_ip)))
59459+ return -EFAULT;
59460+
59461+ ruserip = rtmp->prev;
59462+
59463+ if (!rlast) {
59464+ rtmp->prev = NULL;
59465+ rolep->allowed_ips = rtmp;
59466+ } else {
59467+ rlast->next = rtmp;
59468+ rtmp->prev = rlast;
59469+ }
59470+
59471+ if (!ruserip)
59472+ rtmp->next = NULL;
59473+ }
59474+
59475+ return 0;
59476+}
59477+
59478+static int
59479+copy_user_transitions(struct acl_role_label *rolep)
59480+{
59481+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
59482+
59483+ unsigned int len;
59484+ char *tmp;
59485+
59486+ rusertp = rolep->transitions;
59487+
59488+ while (rusertp) {
59489+ rlast = rtmp;
59490+
59491+ if ((rtmp = (struct role_transition *)
59492+ acl_alloc(sizeof (struct role_transition))) == NULL)
59493+ return -ENOMEM;
59494+
59495+ if (copy_from_user(rtmp, rusertp,
59496+ sizeof (struct role_transition)))
59497+ return -EFAULT;
59498+
59499+ rusertp = rtmp->prev;
59500+
59501+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
59502+
59503+ if (!len || len >= GR_SPROLE_LEN)
59504+ return -EINVAL;
59505+
59506+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59507+ return -ENOMEM;
59508+
59509+ if (copy_from_user(tmp, rtmp->rolename, len))
59510+ return -EFAULT;
59511+ tmp[len-1] = '\0';
59512+ rtmp->rolename = tmp;
59513+
59514+ if (!rlast) {
59515+ rtmp->prev = NULL;
59516+ rolep->transitions = rtmp;
59517+ } else {
59518+ rlast->next = rtmp;
59519+ rtmp->prev = rlast;
59520+ }
59521+
59522+ if (!rusertp)
59523+ rtmp->next = NULL;
59524+ }
59525+
59526+ return 0;
59527+}
59528+
59529+static struct acl_subject_label *
59530+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
59531+{
59532+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
59533+ unsigned int len;
59534+ char *tmp;
59535+ __u32 num_objs;
59536+ struct acl_ip_label **i_tmp, *i_utmp2;
59537+ struct gr_hash_struct ghash;
59538+ struct subject_map *subjmap;
59539+ unsigned int i_num;
59540+ int err;
59541+
59542+ if (already_copied != NULL)
59543+ *already_copied = 0;
59544+
59545+ s_tmp = lookup_subject_map(userp);
59546+
59547+ /* we've already copied this subject into the kernel, just return
59548+ the reference to it, and don't copy it over again
59549+ */
59550+ if (s_tmp) {
59551+ if (already_copied != NULL)
59552+ *already_copied = 1;
59553+ return(s_tmp);
59554+ }
59555+
59556+ if ((s_tmp = (struct acl_subject_label *)
59557+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
59558+ return ERR_PTR(-ENOMEM);
59559+
59560+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
59561+ if (subjmap == NULL)
59562+ return ERR_PTR(-ENOMEM);
59563+
59564+ subjmap->user = userp;
59565+ subjmap->kernel = s_tmp;
59566+ insert_subj_map_entry(subjmap);
59567+
59568+ if (copy_from_user(s_tmp, userp,
59569+ sizeof (struct acl_subject_label)))
59570+ return ERR_PTR(-EFAULT);
59571+
59572+ len = strnlen_user(s_tmp->filename, PATH_MAX);
59573+
59574+ if (!len || len >= PATH_MAX)
59575+ return ERR_PTR(-EINVAL);
59576+
59577+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59578+ return ERR_PTR(-ENOMEM);
59579+
59580+ if (copy_from_user(tmp, s_tmp->filename, len))
59581+ return ERR_PTR(-EFAULT);
59582+ tmp[len-1] = '\0';
59583+ s_tmp->filename = tmp;
59584+
59585+ if (!strcmp(s_tmp->filename, "/"))
59586+ role->root_label = s_tmp;
59587+
59588+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
59589+ return ERR_PTR(-EFAULT);
59590+
59591+ /* copy user and group transition tables */
59592+
59593+ if (s_tmp->user_trans_num) {
59594+ uid_t *uidlist;
59595+
59596+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
59597+ if (uidlist == NULL)
59598+ return ERR_PTR(-ENOMEM);
59599+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
59600+ return ERR_PTR(-EFAULT);
59601+
59602+ s_tmp->user_transitions = uidlist;
59603+ }
59604+
59605+ if (s_tmp->group_trans_num) {
59606+ gid_t *gidlist;
59607+
59608+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
59609+ if (gidlist == NULL)
59610+ return ERR_PTR(-ENOMEM);
59611+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
59612+ return ERR_PTR(-EFAULT);
59613+
59614+ s_tmp->group_transitions = gidlist;
59615+ }
59616+
59617+ /* set up object hash table */
59618+ num_objs = count_user_objs(ghash.first);
59619+
59620+ s_tmp->obj_hash_size = num_objs;
59621+ s_tmp->obj_hash =
59622+ (struct acl_object_label **)
59623+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
59624+
59625+ if (!s_tmp->obj_hash)
59626+ return ERR_PTR(-ENOMEM);
59627+
59628+ memset(s_tmp->obj_hash, 0,
59629+ s_tmp->obj_hash_size *
59630+ sizeof (struct acl_object_label *));
59631+
59632+ /* add in objects */
59633+ err = copy_user_objs(ghash.first, s_tmp, role);
59634+
59635+ if (err)
59636+ return ERR_PTR(err);
59637+
59638+ /* set pointer for parent subject */
59639+ if (s_tmp->parent_subject) {
59640+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
59641+
59642+ if (IS_ERR(s_tmp2))
59643+ return s_tmp2;
59644+
59645+ s_tmp->parent_subject = s_tmp2;
59646+ }
59647+
59648+ /* add in ip acls */
59649+
59650+ if (!s_tmp->ip_num) {
59651+ s_tmp->ips = NULL;
59652+ goto insert;
59653+ }
59654+
59655+ i_tmp =
59656+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
59657+ sizeof (struct acl_ip_label *));
59658+
59659+ if (!i_tmp)
59660+ return ERR_PTR(-ENOMEM);
59661+
59662+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
59663+ *(i_tmp + i_num) =
59664+ (struct acl_ip_label *)
59665+ acl_alloc(sizeof (struct acl_ip_label));
59666+ if (!*(i_tmp + i_num))
59667+ return ERR_PTR(-ENOMEM);
59668+
59669+ if (copy_from_user
59670+ (&i_utmp2, s_tmp->ips + i_num,
59671+ sizeof (struct acl_ip_label *)))
59672+ return ERR_PTR(-EFAULT);
59673+
59674+ if (copy_from_user
59675+ (*(i_tmp + i_num), i_utmp2,
59676+ sizeof (struct acl_ip_label)))
59677+ return ERR_PTR(-EFAULT);
59678+
59679+ if ((*(i_tmp + i_num))->iface == NULL)
59680+ continue;
59681+
59682+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
59683+ if (!len || len >= IFNAMSIZ)
59684+ return ERR_PTR(-EINVAL);
59685+ tmp = acl_alloc(len);
59686+ if (tmp == NULL)
59687+ return ERR_PTR(-ENOMEM);
59688+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
59689+ return ERR_PTR(-EFAULT);
59690+ (*(i_tmp + i_num))->iface = tmp;
59691+ }
59692+
59693+ s_tmp->ips = i_tmp;
59694+
59695+insert:
59696+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
59697+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
59698+ return ERR_PTR(-ENOMEM);
59699+
59700+ return s_tmp;
59701+}
59702+
59703+static int
59704+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
59705+{
59706+ struct acl_subject_label s_pre;
59707+ struct acl_subject_label * ret;
59708+ int err;
59709+
59710+ while (userp) {
59711+ if (copy_from_user(&s_pre, userp,
59712+ sizeof (struct acl_subject_label)))
59713+ return -EFAULT;
59714+
59715+ ret = do_copy_user_subj(userp, role, NULL);
59716+
59717+ err = PTR_ERR(ret);
59718+ if (IS_ERR(ret))
59719+ return err;
59720+
59721+ insert_acl_subj_label(ret, role);
59722+
59723+ userp = s_pre.prev;
59724+ }
59725+
59726+ return 0;
59727+}
59728+
59729+static int
59730+copy_user_acl(struct gr_arg *arg)
59731+{
59732+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
59733+ struct acl_subject_label *subj_list;
59734+ struct sprole_pw *sptmp;
59735+ struct gr_hash_struct *ghash;
59736+ uid_t *domainlist;
59737+ unsigned int r_num;
59738+ unsigned int len;
59739+ char *tmp;
59740+ int err = 0;
59741+ __u16 i;
59742+ __u32 num_subjs;
59743+
59744+ /* we need a default and kernel role */
59745+ if (arg->role_db.num_roles < 2)
59746+ return -EINVAL;
59747+
59748+ /* copy special role authentication info from userspace */
59749+
59750+ num_sprole_pws = arg->num_sprole_pws;
59751+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
59752+
59753+ if (!acl_special_roles && num_sprole_pws)
59754+ return -ENOMEM;
59755+
59756+ for (i = 0; i < num_sprole_pws; i++) {
59757+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
59758+ if (!sptmp)
59759+ return -ENOMEM;
59760+ if (copy_from_user(sptmp, arg->sprole_pws + i,
59761+ sizeof (struct sprole_pw)))
59762+ return -EFAULT;
59763+
59764+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
59765+
59766+ if (!len || len >= GR_SPROLE_LEN)
59767+ return -EINVAL;
59768+
59769+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59770+ return -ENOMEM;
59771+
59772+ if (copy_from_user(tmp, sptmp->rolename, len))
59773+ return -EFAULT;
59774+
59775+ tmp[len-1] = '\0';
59776+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59777+ printk(KERN_ALERT "Copying special role %s\n", tmp);
59778+#endif
59779+ sptmp->rolename = tmp;
59780+ acl_special_roles[i] = sptmp;
59781+ }
59782+
59783+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
59784+
59785+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
59786+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
59787+
59788+ if (!r_tmp)
59789+ return -ENOMEM;
59790+
59791+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
59792+ sizeof (struct acl_role_label *)))
59793+ return -EFAULT;
59794+
59795+ if (copy_from_user(r_tmp, r_utmp2,
59796+ sizeof (struct acl_role_label)))
59797+ return -EFAULT;
59798+
59799+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
59800+
59801+ if (!len || len >= PATH_MAX)
59802+ return -EINVAL;
59803+
59804+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59805+ return -ENOMEM;
59806+
59807+ if (copy_from_user(tmp, r_tmp->rolename, len))
59808+ return -EFAULT;
59809+
59810+ tmp[len-1] = '\0';
59811+ r_tmp->rolename = tmp;
59812+
59813+ if (!strcmp(r_tmp->rolename, "default")
59814+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
59815+ default_role = r_tmp;
59816+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
59817+ kernel_role = r_tmp;
59818+ }
59819+
59820+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
59821+ return -ENOMEM;
59822+
59823+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
59824+ return -EFAULT;
59825+
59826+ r_tmp->hash = ghash;
59827+
59828+ num_subjs = count_user_subjs(r_tmp->hash->first);
59829+
59830+ r_tmp->subj_hash_size = num_subjs;
59831+ r_tmp->subj_hash =
59832+ (struct acl_subject_label **)
59833+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
59834+
59835+ if (!r_tmp->subj_hash)
59836+ return -ENOMEM;
59837+
59838+ err = copy_user_allowedips(r_tmp);
59839+ if (err)
59840+ return err;
59841+
59842+ /* copy domain info */
59843+ if (r_tmp->domain_children != NULL) {
59844+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
59845+ if (domainlist == NULL)
59846+ return -ENOMEM;
59847+
59848+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
59849+ return -EFAULT;
59850+
59851+ r_tmp->domain_children = domainlist;
59852+ }
59853+
59854+ err = copy_user_transitions(r_tmp);
59855+ if (err)
59856+ return err;
59857+
59858+ memset(r_tmp->subj_hash, 0,
59859+ r_tmp->subj_hash_size *
59860+ sizeof (struct acl_subject_label *));
59861+
59862+ /* acquire the list of subjects, then NULL out
59863+ the list prior to parsing the subjects for this role,
59864+ as during this parsing the list is replaced with a list
59865+ of *nested* subjects for the role
59866+ */
59867+ subj_list = r_tmp->hash->first;
59868+
59869+ /* set nested subject list to null */
59870+ r_tmp->hash->first = NULL;
59871+
59872+ err = copy_user_subjs(subj_list, r_tmp);
59873+
59874+ if (err)
59875+ return err;
59876+
59877+ insert_acl_role_label(r_tmp);
59878+ }
59879+
59880+ if (default_role == NULL || kernel_role == NULL)
59881+ return -EINVAL;
59882+
59883+ return err;
59884+}
59885+
59886+static int
59887+gracl_init(struct gr_arg *args)
59888+{
59889+ int error = 0;
59890+
59891+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
59892+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
59893+
59894+ if (init_variables(args)) {
59895+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
59896+ error = -ENOMEM;
59897+ free_variables();
59898+ goto out;
59899+ }
59900+
59901+ error = copy_user_acl(args);
59902+ free_init_variables();
59903+ if (error) {
59904+ free_variables();
59905+ goto out;
59906+ }
59907+
59908+ if ((error = gr_set_acls(0))) {
59909+ free_variables();
59910+ goto out;
59911+ }
59912+
59913+ pax_open_kernel();
59914+ gr_status |= GR_READY;
59915+ pax_close_kernel();
59916+
59917+ out:
59918+ return error;
59919+}
59920+
59921+/* derived from glibc fnmatch() 0: match, 1: no match*/
59922+
59923+static int
59924+glob_match(const char *p, const char *n)
59925+{
59926+ char c;
59927+
59928+ while ((c = *p++) != '\0') {
59929+ switch (c) {
59930+ case '?':
59931+ if (*n == '\0')
59932+ return 1;
59933+ else if (*n == '/')
59934+ return 1;
59935+ break;
59936+ case '\\':
59937+ if (*n != c)
59938+ return 1;
59939+ break;
59940+ case '*':
59941+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
59942+ if (*n == '/')
59943+ return 1;
59944+ else if (c == '?') {
59945+ if (*n == '\0')
59946+ return 1;
59947+ else
59948+ ++n;
59949+ }
59950+ }
59951+ if (c == '\0') {
59952+ return 0;
59953+ } else {
59954+ const char *endp;
59955+
59956+ if ((endp = strchr(n, '/')) == NULL)
59957+ endp = n + strlen(n);
59958+
59959+ if (c == '[') {
59960+ for (--p; n < endp; ++n)
59961+ if (!glob_match(p, n))
59962+ return 0;
59963+ } else if (c == '/') {
59964+ while (*n != '\0' && *n != '/')
59965+ ++n;
59966+ if (*n == '/' && !glob_match(p, n + 1))
59967+ return 0;
59968+ } else {
59969+ for (--p; n < endp; ++n)
59970+ if (*n == c && !glob_match(p, n))
59971+ return 0;
59972+ }
59973+
59974+ return 1;
59975+ }
59976+ case '[':
59977+ {
59978+ int not;
59979+ char cold;
59980+
59981+ if (*n == '\0' || *n == '/')
59982+ return 1;
59983+
59984+ not = (*p == '!' || *p == '^');
59985+ if (not)
59986+ ++p;
59987+
59988+ c = *p++;
59989+ for (;;) {
59990+ unsigned char fn = (unsigned char)*n;
59991+
59992+ if (c == '\0')
59993+ return 1;
59994+ else {
59995+ if (c == fn)
59996+ goto matched;
59997+ cold = c;
59998+ c = *p++;
59999+
60000+ if (c == '-' && *p != ']') {
60001+ unsigned char cend = *p++;
60002+
60003+ if (cend == '\0')
60004+ return 1;
60005+
60006+ if (cold <= fn && fn <= cend)
60007+ goto matched;
60008+
60009+ c = *p++;
60010+ }
60011+ }
60012+
60013+ if (c == ']')
60014+ break;
60015+ }
60016+ if (!not)
60017+ return 1;
60018+ break;
60019+ matched:
60020+ while (c != ']') {
60021+ if (c == '\0')
60022+ return 1;
60023+
60024+ c = *p++;
60025+ }
60026+ if (not)
60027+ return 1;
60028+ }
60029+ break;
60030+ default:
60031+ if (c != *n)
60032+ return 1;
60033+ }
60034+
60035+ ++n;
60036+ }
60037+
60038+ if (*n == '\0')
60039+ return 0;
60040+
60041+ if (*n == '/')
60042+ return 0;
60043+
60044+ return 1;
60045+}
60046+
60047+static struct acl_object_label *
60048+chk_glob_label(struct acl_object_label *globbed,
60049+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
60050+{
60051+ struct acl_object_label *tmp;
60052+
60053+ if (*path == NULL)
60054+ *path = gr_to_filename_nolock(dentry, mnt);
60055+
60056+ tmp = globbed;
60057+
60058+ while (tmp) {
60059+ if (!glob_match(tmp->filename, *path))
60060+ return tmp;
60061+ tmp = tmp->next;
60062+ }
60063+
60064+ return NULL;
60065+}
60066+
60067+static struct acl_object_label *
60068+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60069+ const ino_t curr_ino, const dev_t curr_dev,
60070+ const struct acl_subject_label *subj, char **path, const int checkglob)
60071+{
60072+ struct acl_subject_label *tmpsubj;
60073+ struct acl_object_label *retval;
60074+ struct acl_object_label *retval2;
60075+
60076+ tmpsubj = (struct acl_subject_label *) subj;
60077+ read_lock(&gr_inode_lock);
60078+ do {
60079+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
60080+ if (retval) {
60081+ if (checkglob && retval->globbed) {
60082+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
60083+ if (retval2)
60084+ retval = retval2;
60085+ }
60086+ break;
60087+ }
60088+ } while ((tmpsubj = tmpsubj->parent_subject));
60089+ read_unlock(&gr_inode_lock);
60090+
60091+ return retval;
60092+}
60093+
60094+static __inline__ struct acl_object_label *
60095+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60096+ struct dentry *curr_dentry,
60097+ const struct acl_subject_label *subj, char **path, const int checkglob)
60098+{
60099+ int newglob = checkglob;
60100+ ino_t inode;
60101+ dev_t device;
60102+
60103+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
60104+ as we don't want a / * rule to match instead of the / object
60105+ don't do this for create lookups that call this function though, since they're looking up
60106+ on the parent and thus need globbing checks on all paths
60107+ */
60108+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
60109+ newglob = GR_NO_GLOB;
60110+
60111+ spin_lock(&curr_dentry->d_lock);
60112+ inode = curr_dentry->d_inode->i_ino;
60113+ device = __get_dev(curr_dentry);
60114+ spin_unlock(&curr_dentry->d_lock);
60115+
60116+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
60117+}
60118+
60119+#ifdef CONFIG_HUGETLBFS
60120+static inline bool
60121+is_hugetlbfs_mnt(const struct vfsmount *mnt)
60122+{
60123+ int i;
60124+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
60125+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
60126+ return true;
60127+ }
60128+
60129+ return false;
60130+}
60131+#endif
60132+
60133+static struct acl_object_label *
60134+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60135+ const struct acl_subject_label *subj, char *path, const int checkglob)
60136+{
60137+ struct dentry *dentry = (struct dentry *) l_dentry;
60138+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60139+ struct mount *real_mnt = real_mount(mnt);
60140+ struct acl_object_label *retval;
60141+ struct dentry *parent;
60142+
60143+ br_read_lock(&vfsmount_lock);
60144+ write_seqlock(&rename_lock);
60145+
60146+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
60147+#ifdef CONFIG_NET
60148+ mnt == sock_mnt ||
60149+#endif
60150+#ifdef CONFIG_HUGETLBFS
60151+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
60152+#endif
60153+ /* ignore Eric Biederman */
60154+ IS_PRIVATE(l_dentry->d_inode))) {
60155+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
60156+ goto out;
60157+ }
60158+
60159+ for (;;) {
60160+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60161+ break;
60162+
60163+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60164+ if (!mnt_has_parent(real_mnt))
60165+ break;
60166+
60167+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
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+ parent = dentry->d_parent;
60178+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60179+ if (retval != NULL)
60180+ goto out;
60181+
60182+ dentry = parent;
60183+ }
60184+
60185+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60186+
60187+ /* real_root is pinned so we don't have to hold a reference */
60188+ if (retval == NULL)
60189+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
60190+out:
60191+ write_sequnlock(&rename_lock);
60192+ br_read_unlock(&vfsmount_lock);
60193+
60194+ BUG_ON(retval == NULL);
60195+
60196+ return retval;
60197+}
60198+
60199+static __inline__ struct acl_object_label *
60200+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60201+ const struct acl_subject_label *subj)
60202+{
60203+ char *path = NULL;
60204+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
60205+}
60206+
60207+static __inline__ struct acl_object_label *
60208+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60209+ const struct acl_subject_label *subj)
60210+{
60211+ char *path = NULL;
60212+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
60213+}
60214+
60215+static __inline__ struct acl_object_label *
60216+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60217+ const struct acl_subject_label *subj, char *path)
60218+{
60219+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
60220+}
60221+
60222+static struct acl_subject_label *
60223+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60224+ const struct acl_role_label *role)
60225+{
60226+ struct dentry *dentry = (struct dentry *) l_dentry;
60227+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60228+ struct mount *real_mnt = real_mount(mnt);
60229+ struct acl_subject_label *retval;
60230+ struct dentry *parent;
60231+
60232+ br_read_lock(&vfsmount_lock);
60233+ write_seqlock(&rename_lock);
60234+
60235+ for (;;) {
60236+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60237+ break;
60238+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60239+ if (!mnt_has_parent(real_mnt))
60240+ break;
60241+
60242+ spin_lock(&dentry->d_lock);
60243+ read_lock(&gr_inode_lock);
60244+ retval =
60245+ lookup_acl_subj_label(dentry->d_inode->i_ino,
60246+ __get_dev(dentry), role);
60247+ read_unlock(&gr_inode_lock);
60248+ spin_unlock(&dentry->d_lock);
60249+ if (retval != NULL)
60250+ goto out;
60251+
60252+ dentry = real_mnt->mnt_mountpoint;
60253+ real_mnt = real_mnt->mnt_parent;
60254+ mnt = &real_mnt->mnt;
60255+ continue;
60256+ }
60257+
60258+ spin_lock(&dentry->d_lock);
60259+ read_lock(&gr_inode_lock);
60260+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60261+ __get_dev(dentry), role);
60262+ read_unlock(&gr_inode_lock);
60263+ parent = dentry->d_parent;
60264+ spin_unlock(&dentry->d_lock);
60265+
60266+ if (retval != NULL)
60267+ goto out;
60268+
60269+ dentry = parent;
60270+ }
60271+
60272+ spin_lock(&dentry->d_lock);
60273+ read_lock(&gr_inode_lock);
60274+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60275+ __get_dev(dentry), role);
60276+ read_unlock(&gr_inode_lock);
60277+ spin_unlock(&dentry->d_lock);
60278+
60279+ if (unlikely(retval == NULL)) {
60280+ /* real_root is pinned, we don't need to hold a reference */
60281+ read_lock(&gr_inode_lock);
60282+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
60283+ __get_dev(real_root.dentry), role);
60284+ read_unlock(&gr_inode_lock);
60285+ }
60286+out:
60287+ write_sequnlock(&rename_lock);
60288+ br_read_unlock(&vfsmount_lock);
60289+
60290+ BUG_ON(retval == NULL);
60291+
60292+ return retval;
60293+}
60294+
60295+static void
60296+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
60297+{
60298+ struct task_struct *task = current;
60299+ const struct cred *cred = current_cred();
60300+
60301+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
60302+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60303+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60304+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
60305+
60306+ return;
60307+}
60308+
60309+static void
60310+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
60311+{
60312+ struct task_struct *task = current;
60313+ const struct cred *cred = current_cred();
60314+
60315+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60316+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60317+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60318+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
60319+
60320+ return;
60321+}
60322+
60323+static void
60324+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
60325+{
60326+ struct task_struct *task = current;
60327+ const struct cred *cred = current_cred();
60328+
60329+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60330+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60331+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60332+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
60333+
60334+ return;
60335+}
60336+
60337+__u32
60338+gr_search_file(const struct dentry * dentry, const __u32 mode,
60339+ const struct vfsmount * mnt)
60340+{
60341+ __u32 retval = mode;
60342+ struct acl_subject_label *curracl;
60343+ struct acl_object_label *currobj;
60344+
60345+ if (unlikely(!(gr_status & GR_READY)))
60346+ return (mode & ~GR_AUDITS);
60347+
60348+ curracl = current->acl;
60349+
60350+ currobj = chk_obj_label(dentry, mnt, curracl);
60351+ retval = currobj->mode & mode;
60352+
60353+ /* if we're opening a specified transfer file for writing
60354+ (e.g. /dev/initctl), then transfer our role to init
60355+ */
60356+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
60357+ current->role->roletype & GR_ROLE_PERSIST)) {
60358+ struct task_struct *task = init_pid_ns.child_reaper;
60359+
60360+ if (task->role != current->role) {
60361+ task->acl_sp_role = 0;
60362+ task->acl_role_id = current->acl_role_id;
60363+ task->role = current->role;
60364+ rcu_read_lock();
60365+ read_lock(&grsec_exec_file_lock);
60366+ gr_apply_subject_to_task(task);
60367+ read_unlock(&grsec_exec_file_lock);
60368+ rcu_read_unlock();
60369+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
60370+ }
60371+ }
60372+
60373+ if (unlikely
60374+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
60375+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
60376+ __u32 new_mode = mode;
60377+
60378+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60379+
60380+ retval = new_mode;
60381+
60382+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
60383+ new_mode |= GR_INHERIT;
60384+
60385+ if (!(mode & GR_NOLEARN))
60386+ gr_log_learn(dentry, mnt, new_mode);
60387+ }
60388+
60389+ return retval;
60390+}
60391+
60392+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
60393+ const struct dentry *parent,
60394+ const struct vfsmount *mnt)
60395+{
60396+ struct name_entry *match;
60397+ struct acl_object_label *matchpo;
60398+ struct acl_subject_label *curracl;
60399+ char *path;
60400+
60401+ if (unlikely(!(gr_status & GR_READY)))
60402+ return NULL;
60403+
60404+ preempt_disable();
60405+ path = gr_to_filename_rbac(new_dentry, mnt);
60406+ match = lookup_name_entry_create(path);
60407+
60408+ curracl = current->acl;
60409+
60410+ if (match) {
60411+ read_lock(&gr_inode_lock);
60412+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
60413+ read_unlock(&gr_inode_lock);
60414+
60415+ if (matchpo) {
60416+ preempt_enable();
60417+ return matchpo;
60418+ }
60419+ }
60420+
60421+ // lookup parent
60422+
60423+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
60424+
60425+ preempt_enable();
60426+ return matchpo;
60427+}
60428+
60429+__u32
60430+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
60431+ const struct vfsmount * mnt, const __u32 mode)
60432+{
60433+ struct acl_object_label *matchpo;
60434+ __u32 retval;
60435+
60436+ if (unlikely(!(gr_status & GR_READY)))
60437+ return (mode & ~GR_AUDITS);
60438+
60439+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
60440+
60441+ retval = matchpo->mode & mode;
60442+
60443+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
60444+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60445+ __u32 new_mode = mode;
60446+
60447+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60448+
60449+ gr_log_learn(new_dentry, mnt, new_mode);
60450+ return new_mode;
60451+ }
60452+
60453+ return retval;
60454+}
60455+
60456+__u32
60457+gr_check_link(const struct dentry * new_dentry,
60458+ const struct dentry * parent_dentry,
60459+ const struct vfsmount * parent_mnt,
60460+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
60461+{
60462+ struct acl_object_label *obj;
60463+ __u32 oldmode, newmode;
60464+ __u32 needmode;
60465+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
60466+ GR_DELETE | GR_INHERIT;
60467+
60468+ if (unlikely(!(gr_status & GR_READY)))
60469+ return (GR_CREATE | GR_LINK);
60470+
60471+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
60472+ oldmode = obj->mode;
60473+
60474+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
60475+ newmode = obj->mode;
60476+
60477+ needmode = newmode & checkmodes;
60478+
60479+ // old name for hardlink must have at least the permissions of the new name
60480+ if ((oldmode & needmode) != needmode)
60481+ goto bad;
60482+
60483+ // if old name had restrictions/auditing, make sure the new name does as well
60484+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
60485+
60486+ // don't allow hardlinking of suid/sgid/fcapped files without permission
60487+ if (is_privileged_binary(old_dentry))
60488+ needmode |= GR_SETID;
60489+
60490+ if ((newmode & needmode) != needmode)
60491+ goto bad;
60492+
60493+ // enforce minimum permissions
60494+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
60495+ return newmode;
60496+bad:
60497+ needmode = oldmode;
60498+ if (is_privileged_binary(old_dentry))
60499+ needmode |= GR_SETID;
60500+
60501+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
60502+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
60503+ return (GR_CREATE | GR_LINK);
60504+ } else if (newmode & GR_SUPPRESS)
60505+ return GR_SUPPRESS;
60506+ else
60507+ return 0;
60508+}
60509+
60510+int
60511+gr_check_hidden_task(const struct task_struct *task)
60512+{
60513+ if (unlikely(!(gr_status & GR_READY)))
60514+ return 0;
60515+
60516+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
60517+ return 1;
60518+
60519+ return 0;
60520+}
60521+
60522+int
60523+gr_check_protected_task(const struct task_struct *task)
60524+{
60525+ if (unlikely(!(gr_status & GR_READY) || !task))
60526+ return 0;
60527+
60528+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60529+ task->acl != current->acl)
60530+ return 1;
60531+
60532+ return 0;
60533+}
60534+
60535+int
60536+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60537+{
60538+ struct task_struct *p;
60539+ int ret = 0;
60540+
60541+ if (unlikely(!(gr_status & GR_READY) || !pid))
60542+ return ret;
60543+
60544+ read_lock(&tasklist_lock);
60545+ do_each_pid_task(pid, type, p) {
60546+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60547+ p->acl != current->acl) {
60548+ ret = 1;
60549+ goto out;
60550+ }
60551+ } while_each_pid_task(pid, type, p);
60552+out:
60553+ read_unlock(&tasklist_lock);
60554+
60555+ return ret;
60556+}
60557+
60558+void
60559+gr_copy_label(struct task_struct *tsk)
60560+{
60561+ tsk->signal->used_accept = 0;
60562+ tsk->acl_sp_role = 0;
60563+ tsk->acl_role_id = current->acl_role_id;
60564+ tsk->acl = current->acl;
60565+ tsk->role = current->role;
60566+ tsk->signal->curr_ip = current->signal->curr_ip;
60567+ tsk->signal->saved_ip = current->signal->saved_ip;
60568+ if (current->exec_file)
60569+ get_file(current->exec_file);
60570+ tsk->exec_file = current->exec_file;
60571+ tsk->is_writable = current->is_writable;
60572+ if (unlikely(current->signal->used_accept)) {
60573+ current->signal->curr_ip = 0;
60574+ current->signal->saved_ip = 0;
60575+ }
60576+
60577+ return;
60578+}
60579+
60580+static void
60581+gr_set_proc_res(struct task_struct *task)
60582+{
60583+ struct acl_subject_label *proc;
60584+ unsigned short i;
60585+
60586+ proc = task->acl;
60587+
60588+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
60589+ return;
60590+
60591+ for (i = 0; i < RLIM_NLIMITS; i++) {
60592+ if (!(proc->resmask & (1U << i)))
60593+ continue;
60594+
60595+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
60596+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
60597+
60598+ if (i == RLIMIT_CPU)
60599+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
60600+ }
60601+
60602+ return;
60603+}
60604+
60605+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
60606+
60607+int
60608+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
60609+{
60610+ unsigned int i;
60611+ __u16 num;
60612+ uid_t *uidlist;
60613+ uid_t curuid;
60614+ int realok = 0;
60615+ int effectiveok = 0;
60616+ int fsok = 0;
60617+ uid_t globalreal, globaleffective, globalfs;
60618+
60619+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
60620+ struct user_struct *user;
60621+
60622+ if (!uid_valid(real))
60623+ goto skipit;
60624+
60625+ /* find user based on global namespace */
60626+
60627+ globalreal = GR_GLOBAL_UID(real);
60628+
60629+ user = find_user(make_kuid(&init_user_ns, globalreal));
60630+ if (user == NULL)
60631+ goto skipit;
60632+
60633+ if (gr_process_kernel_setuid_ban(user)) {
60634+ /* for find_user */
60635+ free_uid(user);
60636+ return 1;
60637+ }
60638+
60639+ /* for find_user */
60640+ free_uid(user);
60641+
60642+skipit:
60643+#endif
60644+
60645+ if (unlikely(!(gr_status & GR_READY)))
60646+ return 0;
60647+
60648+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60649+ gr_log_learn_uid_change(real, effective, fs);
60650+
60651+ num = current->acl->user_trans_num;
60652+ uidlist = current->acl->user_transitions;
60653+
60654+ if (uidlist == NULL)
60655+ return 0;
60656+
60657+ if (!uid_valid(real)) {
60658+ realok = 1;
60659+ globalreal = (uid_t)-1;
60660+ } else {
60661+ globalreal = GR_GLOBAL_UID(real);
60662+ }
60663+ if (!uid_valid(effective)) {
60664+ effectiveok = 1;
60665+ globaleffective = (uid_t)-1;
60666+ } else {
60667+ globaleffective = GR_GLOBAL_UID(effective);
60668+ }
60669+ if (!uid_valid(fs)) {
60670+ fsok = 1;
60671+ globalfs = (uid_t)-1;
60672+ } else {
60673+ globalfs = GR_GLOBAL_UID(fs);
60674+ }
60675+
60676+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
60677+ for (i = 0; i < num; i++) {
60678+ curuid = uidlist[i];
60679+ if (globalreal == curuid)
60680+ realok = 1;
60681+ if (globaleffective == curuid)
60682+ effectiveok = 1;
60683+ if (globalfs == curuid)
60684+ fsok = 1;
60685+ }
60686+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
60687+ for (i = 0; i < num; i++) {
60688+ curuid = uidlist[i];
60689+ if (globalreal == curuid)
60690+ break;
60691+ if (globaleffective == curuid)
60692+ break;
60693+ if (globalfs == curuid)
60694+ break;
60695+ }
60696+ /* not in deny list */
60697+ if (i == num) {
60698+ realok = 1;
60699+ effectiveok = 1;
60700+ fsok = 1;
60701+ }
60702+ }
60703+
60704+ if (realok && effectiveok && fsok)
60705+ return 0;
60706+ else {
60707+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60708+ return 1;
60709+ }
60710+}
60711+
60712+int
60713+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
60714+{
60715+ unsigned int i;
60716+ __u16 num;
60717+ gid_t *gidlist;
60718+ gid_t curgid;
60719+ int realok = 0;
60720+ int effectiveok = 0;
60721+ int fsok = 0;
60722+ gid_t globalreal, globaleffective, globalfs;
60723+
60724+ if (unlikely(!(gr_status & GR_READY)))
60725+ return 0;
60726+
60727+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60728+ gr_log_learn_gid_change(real, effective, fs);
60729+
60730+ num = current->acl->group_trans_num;
60731+ gidlist = current->acl->group_transitions;
60732+
60733+ if (gidlist == NULL)
60734+ return 0;
60735+
60736+ if (!gid_valid(real)) {
60737+ realok = 1;
60738+ globalreal = (gid_t)-1;
60739+ } else {
60740+ globalreal = GR_GLOBAL_GID(real);
60741+ }
60742+ if (!gid_valid(effective)) {
60743+ effectiveok = 1;
60744+ globaleffective = (gid_t)-1;
60745+ } else {
60746+ globaleffective = GR_GLOBAL_GID(effective);
60747+ }
60748+ if (!gid_valid(fs)) {
60749+ fsok = 1;
60750+ globalfs = (gid_t)-1;
60751+ } else {
60752+ globalfs = GR_GLOBAL_GID(fs);
60753+ }
60754+
60755+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
60756+ for (i = 0; i < num; i++) {
60757+ curgid = gidlist[i];
60758+ if (globalreal == curgid)
60759+ realok = 1;
60760+ if (globaleffective == curgid)
60761+ effectiveok = 1;
60762+ if (globalfs == curgid)
60763+ fsok = 1;
60764+ }
60765+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
60766+ for (i = 0; i < num; i++) {
60767+ curgid = gidlist[i];
60768+ if (globalreal == curgid)
60769+ break;
60770+ if (globaleffective == curgid)
60771+ break;
60772+ if (globalfs == curgid)
60773+ break;
60774+ }
60775+ /* not in deny list */
60776+ if (i == num) {
60777+ realok = 1;
60778+ effectiveok = 1;
60779+ fsok = 1;
60780+ }
60781+ }
60782+
60783+ if (realok && effectiveok && fsok)
60784+ return 0;
60785+ else {
60786+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60787+ return 1;
60788+ }
60789+}
60790+
60791+extern int gr_acl_is_capable(const int cap);
60792+
60793+void
60794+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
60795+{
60796+ struct acl_role_label *role = task->role;
60797+ struct acl_subject_label *subj = NULL;
60798+ struct acl_object_label *obj;
60799+ struct file *filp;
60800+ uid_t uid;
60801+ gid_t gid;
60802+
60803+ if (unlikely(!(gr_status & GR_READY)))
60804+ return;
60805+
60806+ uid = GR_GLOBAL_UID(kuid);
60807+ gid = GR_GLOBAL_GID(kgid);
60808+
60809+ filp = task->exec_file;
60810+
60811+ /* kernel process, we'll give them the kernel role */
60812+ if (unlikely(!filp)) {
60813+ task->role = kernel_role;
60814+ task->acl = kernel_role->root_label;
60815+ return;
60816+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
60817+ role = lookup_acl_role_label(task, uid, gid);
60818+
60819+ /* don't change the role if we're not a privileged process */
60820+ if (role && task->role != role &&
60821+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
60822+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
60823+ return;
60824+
60825+ /* perform subject lookup in possibly new role
60826+ we can use this result below in the case where role == task->role
60827+ */
60828+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
60829+
60830+ /* if we changed uid/gid, but result in the same role
60831+ and are using inheritance, don't lose the inherited subject
60832+ if current subject is other than what normal lookup
60833+ would result in, we arrived via inheritance, don't
60834+ lose subject
60835+ */
60836+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
60837+ (subj == task->acl)))
60838+ task->acl = subj;
60839+
60840+ task->role = role;
60841+
60842+ task->is_writable = 0;
60843+
60844+ /* ignore additional mmap checks for processes that are writable
60845+ by the default ACL */
60846+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60847+ if (unlikely(obj->mode & GR_WRITE))
60848+ task->is_writable = 1;
60849+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60850+ if (unlikely(obj->mode & GR_WRITE))
60851+ task->is_writable = 1;
60852+
60853+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60854+ 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);
60855+#endif
60856+
60857+ gr_set_proc_res(task);
60858+
60859+ return;
60860+}
60861+
60862+int
60863+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60864+ const int unsafe_flags)
60865+{
60866+ struct task_struct *task = current;
60867+ struct acl_subject_label *newacl;
60868+ struct acl_object_label *obj;
60869+ __u32 retmode;
60870+
60871+ if (unlikely(!(gr_status & GR_READY)))
60872+ return 0;
60873+
60874+ newacl = chk_subj_label(dentry, mnt, task->role);
60875+
60876+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
60877+ did an exec
60878+ */
60879+ rcu_read_lock();
60880+ read_lock(&tasklist_lock);
60881+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
60882+ (task->parent->acl->mode & GR_POVERRIDE))) {
60883+ read_unlock(&tasklist_lock);
60884+ rcu_read_unlock();
60885+ goto skip_check;
60886+ }
60887+ read_unlock(&tasklist_lock);
60888+ rcu_read_unlock();
60889+
60890+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
60891+ !(task->role->roletype & GR_ROLE_GOD) &&
60892+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
60893+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60894+ if (unsafe_flags & LSM_UNSAFE_SHARE)
60895+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
60896+ else
60897+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
60898+ return -EACCES;
60899+ }
60900+
60901+skip_check:
60902+
60903+ obj = chk_obj_label(dentry, mnt, task->acl);
60904+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
60905+
60906+ if (!(task->acl->mode & GR_INHERITLEARN) &&
60907+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
60908+ if (obj->nested)
60909+ task->acl = obj->nested;
60910+ else
60911+ task->acl = newacl;
60912+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
60913+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
60914+
60915+ task->is_writable = 0;
60916+
60917+ /* ignore additional mmap checks for processes that are writable
60918+ by the default ACL */
60919+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
60920+ if (unlikely(obj->mode & GR_WRITE))
60921+ task->is_writable = 1;
60922+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
60923+ if (unlikely(obj->mode & GR_WRITE))
60924+ task->is_writable = 1;
60925+
60926+ gr_set_proc_res(task);
60927+
60928+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60929+ 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);
60930+#endif
60931+ return 0;
60932+}
60933+
60934+/* always called with valid inodev ptr */
60935+static void
60936+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
60937+{
60938+ struct acl_object_label *matchpo;
60939+ struct acl_subject_label *matchps;
60940+ struct acl_subject_label *subj;
60941+ struct acl_role_label *role;
60942+ unsigned int x;
60943+
60944+ FOR_EACH_ROLE_START(role)
60945+ FOR_EACH_SUBJECT_START(role, subj, x)
60946+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60947+ matchpo->mode |= GR_DELETED;
60948+ FOR_EACH_SUBJECT_END(subj,x)
60949+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60950+ /* nested subjects aren't in the role's subj_hash table */
60951+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60952+ matchpo->mode |= GR_DELETED;
60953+ FOR_EACH_NESTED_SUBJECT_END(subj)
60954+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
60955+ matchps->mode |= GR_DELETED;
60956+ FOR_EACH_ROLE_END(role)
60957+
60958+ inodev->nentry->deleted = 1;
60959+
60960+ return;
60961+}
60962+
60963+void
60964+gr_handle_delete(const ino_t ino, const dev_t dev)
60965+{
60966+ struct inodev_entry *inodev;
60967+
60968+ if (unlikely(!(gr_status & GR_READY)))
60969+ return;
60970+
60971+ write_lock(&gr_inode_lock);
60972+ inodev = lookup_inodev_entry(ino, dev);
60973+ if (inodev != NULL)
60974+ do_handle_delete(inodev, ino, dev);
60975+ write_unlock(&gr_inode_lock);
60976+
60977+ return;
60978+}
60979+
60980+static void
60981+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
60982+ const ino_t newinode, const dev_t newdevice,
60983+ struct acl_subject_label *subj)
60984+{
60985+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
60986+ struct acl_object_label *match;
60987+
60988+ match = subj->obj_hash[index];
60989+
60990+ while (match && (match->inode != oldinode ||
60991+ match->device != olddevice ||
60992+ !(match->mode & GR_DELETED)))
60993+ match = match->next;
60994+
60995+ if (match && (match->inode == oldinode)
60996+ && (match->device == olddevice)
60997+ && (match->mode & GR_DELETED)) {
60998+ if (match->prev == NULL) {
60999+ subj->obj_hash[index] = match->next;
61000+ if (match->next != NULL)
61001+ match->next->prev = NULL;
61002+ } else {
61003+ match->prev->next = match->next;
61004+ if (match->next != NULL)
61005+ match->next->prev = match->prev;
61006+ }
61007+ match->prev = NULL;
61008+ match->next = NULL;
61009+ match->inode = newinode;
61010+ match->device = newdevice;
61011+ match->mode &= ~GR_DELETED;
61012+
61013+ insert_acl_obj_label(match, subj);
61014+ }
61015+
61016+ return;
61017+}
61018+
61019+static void
61020+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
61021+ const ino_t newinode, const dev_t newdevice,
61022+ struct acl_role_label *role)
61023+{
61024+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
61025+ struct acl_subject_label *match;
61026+
61027+ match = role->subj_hash[index];
61028+
61029+ while (match && (match->inode != oldinode ||
61030+ match->device != olddevice ||
61031+ !(match->mode & GR_DELETED)))
61032+ match = match->next;
61033+
61034+ if (match && (match->inode == oldinode)
61035+ && (match->device == olddevice)
61036+ && (match->mode & GR_DELETED)) {
61037+ if (match->prev == NULL) {
61038+ role->subj_hash[index] = match->next;
61039+ if (match->next != NULL)
61040+ match->next->prev = NULL;
61041+ } else {
61042+ match->prev->next = match->next;
61043+ if (match->next != NULL)
61044+ match->next->prev = match->prev;
61045+ }
61046+ match->prev = NULL;
61047+ match->next = NULL;
61048+ match->inode = newinode;
61049+ match->device = newdevice;
61050+ match->mode &= ~GR_DELETED;
61051+
61052+ insert_acl_subj_label(match, role);
61053+ }
61054+
61055+ return;
61056+}
61057+
61058+static void
61059+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
61060+ const ino_t newinode, const dev_t newdevice)
61061+{
61062+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
61063+ struct inodev_entry *match;
61064+
61065+ match = inodev_set.i_hash[index];
61066+
61067+ while (match && (match->nentry->inode != oldinode ||
61068+ match->nentry->device != olddevice || !match->nentry->deleted))
61069+ match = match->next;
61070+
61071+ if (match && (match->nentry->inode == oldinode)
61072+ && (match->nentry->device == olddevice) &&
61073+ match->nentry->deleted) {
61074+ if (match->prev == NULL) {
61075+ inodev_set.i_hash[index] = match->next;
61076+ if (match->next != NULL)
61077+ match->next->prev = NULL;
61078+ } else {
61079+ match->prev->next = match->next;
61080+ if (match->next != NULL)
61081+ match->next->prev = match->prev;
61082+ }
61083+ match->prev = NULL;
61084+ match->next = NULL;
61085+ match->nentry->inode = newinode;
61086+ match->nentry->device = newdevice;
61087+ match->nentry->deleted = 0;
61088+
61089+ insert_inodev_entry(match);
61090+ }
61091+
61092+ return;
61093+}
61094+
61095+static void
61096+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
61097+{
61098+ struct acl_subject_label *subj;
61099+ struct acl_role_label *role;
61100+ unsigned int x;
61101+
61102+ FOR_EACH_ROLE_START(role)
61103+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
61104+
61105+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61106+ if ((subj->inode == ino) && (subj->device == dev)) {
61107+ subj->inode = ino;
61108+ subj->device = dev;
61109+ }
61110+ /* nested subjects aren't in the role's subj_hash table */
61111+ update_acl_obj_label(matchn->inode, matchn->device,
61112+ ino, dev, subj);
61113+ FOR_EACH_NESTED_SUBJECT_END(subj)
61114+ FOR_EACH_SUBJECT_START(role, subj, x)
61115+ update_acl_obj_label(matchn->inode, matchn->device,
61116+ ino, dev, subj);
61117+ FOR_EACH_SUBJECT_END(subj,x)
61118+ FOR_EACH_ROLE_END(role)
61119+
61120+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
61121+
61122+ return;
61123+}
61124+
61125+static void
61126+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
61127+ const struct vfsmount *mnt)
61128+{
61129+ ino_t ino = dentry->d_inode->i_ino;
61130+ dev_t dev = __get_dev(dentry);
61131+
61132+ __do_handle_create(matchn, ino, dev);
61133+
61134+ return;
61135+}
61136+
61137+void
61138+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61139+{
61140+ struct name_entry *matchn;
61141+
61142+ if (unlikely(!(gr_status & GR_READY)))
61143+ return;
61144+
61145+ preempt_disable();
61146+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
61147+
61148+ if (unlikely((unsigned long)matchn)) {
61149+ write_lock(&gr_inode_lock);
61150+ do_handle_create(matchn, dentry, mnt);
61151+ write_unlock(&gr_inode_lock);
61152+ }
61153+ preempt_enable();
61154+
61155+ return;
61156+}
61157+
61158+void
61159+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61160+{
61161+ struct name_entry *matchn;
61162+
61163+ if (unlikely(!(gr_status & GR_READY)))
61164+ return;
61165+
61166+ preempt_disable();
61167+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
61168+
61169+ if (unlikely((unsigned long)matchn)) {
61170+ write_lock(&gr_inode_lock);
61171+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
61172+ write_unlock(&gr_inode_lock);
61173+ }
61174+ preempt_enable();
61175+
61176+ return;
61177+}
61178+
61179+void
61180+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61181+ struct dentry *old_dentry,
61182+ struct dentry *new_dentry,
61183+ struct vfsmount *mnt, const __u8 replace)
61184+{
61185+ struct name_entry *matchn;
61186+ struct inodev_entry *inodev;
61187+ struct inode *inode = new_dentry->d_inode;
61188+ ino_t old_ino = old_dentry->d_inode->i_ino;
61189+ dev_t old_dev = __get_dev(old_dentry);
61190+
61191+ /* vfs_rename swaps the name and parent link for old_dentry and
61192+ new_dentry
61193+ at this point, old_dentry has the new name, parent link, and inode
61194+ for the renamed file
61195+ if a file is being replaced by a rename, new_dentry has the inode
61196+ and name for the replaced file
61197+ */
61198+
61199+ if (unlikely(!(gr_status & GR_READY)))
61200+ return;
61201+
61202+ preempt_disable();
61203+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
61204+
61205+ /* we wouldn't have to check d_inode if it weren't for
61206+ NFS silly-renaming
61207+ */
61208+
61209+ write_lock(&gr_inode_lock);
61210+ if (unlikely(replace && inode)) {
61211+ ino_t new_ino = inode->i_ino;
61212+ dev_t new_dev = __get_dev(new_dentry);
61213+
61214+ inodev = lookup_inodev_entry(new_ino, new_dev);
61215+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
61216+ do_handle_delete(inodev, new_ino, new_dev);
61217+ }
61218+
61219+ inodev = lookup_inodev_entry(old_ino, old_dev);
61220+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
61221+ do_handle_delete(inodev, old_ino, old_dev);
61222+
61223+ if (unlikely((unsigned long)matchn))
61224+ do_handle_create(matchn, old_dentry, mnt);
61225+
61226+ write_unlock(&gr_inode_lock);
61227+ preempt_enable();
61228+
61229+ return;
61230+}
61231+
61232+static int
61233+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
61234+ unsigned char **sum)
61235+{
61236+ struct acl_role_label *r;
61237+ struct role_allowed_ip *ipp;
61238+ struct role_transition *trans;
61239+ unsigned int i;
61240+ int found = 0;
61241+ u32 curr_ip = current->signal->curr_ip;
61242+
61243+ current->signal->saved_ip = curr_ip;
61244+
61245+ /* check transition table */
61246+
61247+ for (trans = current->role->transitions; trans; trans = trans->next) {
61248+ if (!strcmp(rolename, trans->rolename)) {
61249+ found = 1;
61250+ break;
61251+ }
61252+ }
61253+
61254+ if (!found)
61255+ return 0;
61256+
61257+ /* handle special roles that do not require authentication
61258+ and check ip */
61259+
61260+ FOR_EACH_ROLE_START(r)
61261+ if (!strcmp(rolename, r->rolename) &&
61262+ (r->roletype & GR_ROLE_SPECIAL)) {
61263+ found = 0;
61264+ if (r->allowed_ips != NULL) {
61265+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
61266+ if ((ntohl(curr_ip) & ipp->netmask) ==
61267+ (ntohl(ipp->addr) & ipp->netmask))
61268+ found = 1;
61269+ }
61270+ } else
61271+ found = 2;
61272+ if (!found)
61273+ return 0;
61274+
61275+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
61276+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
61277+ *salt = NULL;
61278+ *sum = NULL;
61279+ return 1;
61280+ }
61281+ }
61282+ FOR_EACH_ROLE_END(r)
61283+
61284+ for (i = 0; i < num_sprole_pws; i++) {
61285+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
61286+ *salt = acl_special_roles[i]->salt;
61287+ *sum = acl_special_roles[i]->sum;
61288+ return 1;
61289+ }
61290+ }
61291+
61292+ return 0;
61293+}
61294+
61295+static void
61296+assign_special_role(char *rolename)
61297+{
61298+ struct acl_object_label *obj;
61299+ struct acl_role_label *r;
61300+ struct acl_role_label *assigned = NULL;
61301+ struct task_struct *tsk;
61302+ struct file *filp;
61303+
61304+ FOR_EACH_ROLE_START(r)
61305+ if (!strcmp(rolename, r->rolename) &&
61306+ (r->roletype & GR_ROLE_SPECIAL)) {
61307+ assigned = r;
61308+ break;
61309+ }
61310+ FOR_EACH_ROLE_END(r)
61311+
61312+ if (!assigned)
61313+ return;
61314+
61315+ read_lock(&tasklist_lock);
61316+ read_lock(&grsec_exec_file_lock);
61317+
61318+ tsk = current->real_parent;
61319+ if (tsk == NULL)
61320+ goto out_unlock;
61321+
61322+ filp = tsk->exec_file;
61323+ if (filp == NULL)
61324+ goto out_unlock;
61325+
61326+ tsk->is_writable = 0;
61327+
61328+ tsk->acl_sp_role = 1;
61329+ tsk->acl_role_id = ++acl_sp_role_value;
61330+ tsk->role = assigned;
61331+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
61332+
61333+ /* ignore additional mmap checks for processes that are writable
61334+ by the default ACL */
61335+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61336+ if (unlikely(obj->mode & GR_WRITE))
61337+ tsk->is_writable = 1;
61338+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
61339+ if (unlikely(obj->mode & GR_WRITE))
61340+ tsk->is_writable = 1;
61341+
61342+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61343+ 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));
61344+#endif
61345+
61346+out_unlock:
61347+ read_unlock(&grsec_exec_file_lock);
61348+ read_unlock(&tasklist_lock);
61349+ return;
61350+}
61351+
61352+int gr_check_secure_terminal(struct task_struct *task)
61353+{
61354+ struct task_struct *p, *p2, *p3;
61355+ struct files_struct *files;
61356+ struct fdtable *fdt;
61357+ struct file *our_file = NULL, *file;
61358+ int i;
61359+
61360+ if (task->signal->tty == NULL)
61361+ return 1;
61362+
61363+ files = get_files_struct(task);
61364+ if (files != NULL) {
61365+ rcu_read_lock();
61366+ fdt = files_fdtable(files);
61367+ for (i=0; i < fdt->max_fds; i++) {
61368+ file = fcheck_files(files, i);
61369+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
61370+ get_file(file);
61371+ our_file = file;
61372+ }
61373+ }
61374+ rcu_read_unlock();
61375+ put_files_struct(files);
61376+ }
61377+
61378+ if (our_file == NULL)
61379+ return 1;
61380+
61381+ read_lock(&tasklist_lock);
61382+ do_each_thread(p2, p) {
61383+ files = get_files_struct(p);
61384+ if (files == NULL ||
61385+ (p->signal && p->signal->tty == task->signal->tty)) {
61386+ if (files != NULL)
61387+ put_files_struct(files);
61388+ continue;
61389+ }
61390+ rcu_read_lock();
61391+ fdt = files_fdtable(files);
61392+ for (i=0; i < fdt->max_fds; i++) {
61393+ file = fcheck_files(files, i);
61394+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
61395+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
61396+ p3 = task;
61397+ while (task_pid_nr(p3) > 0) {
61398+ if (p3 == p)
61399+ break;
61400+ p3 = p3->real_parent;
61401+ }
61402+ if (p3 == p)
61403+ break;
61404+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
61405+ gr_handle_alertkill(p);
61406+ rcu_read_unlock();
61407+ put_files_struct(files);
61408+ read_unlock(&tasklist_lock);
61409+ fput(our_file);
61410+ return 0;
61411+ }
61412+ }
61413+ rcu_read_unlock();
61414+ put_files_struct(files);
61415+ } while_each_thread(p2, p);
61416+ read_unlock(&tasklist_lock);
61417+
61418+ fput(our_file);
61419+ return 1;
61420+}
61421+
61422+static int gr_rbac_disable(void *unused)
61423+{
61424+ pax_open_kernel();
61425+ gr_status &= ~GR_READY;
61426+ pax_close_kernel();
61427+
61428+ return 0;
61429+}
61430+
61431+ssize_t
61432+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
61433+{
61434+ struct gr_arg_wrapper uwrap;
61435+ unsigned char *sprole_salt = NULL;
61436+ unsigned char *sprole_sum = NULL;
61437+ int error = sizeof (struct gr_arg_wrapper);
61438+ int error2 = 0;
61439+
61440+ mutex_lock(&gr_dev_mutex);
61441+
61442+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
61443+ error = -EPERM;
61444+ goto out;
61445+ }
61446+
61447+ if (count != sizeof (struct gr_arg_wrapper)) {
61448+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
61449+ error = -EINVAL;
61450+ goto out;
61451+ }
61452+
61453+
61454+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
61455+ gr_auth_expires = 0;
61456+ gr_auth_attempts = 0;
61457+ }
61458+
61459+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
61460+ error = -EFAULT;
61461+ goto out;
61462+ }
61463+
61464+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
61465+ error = -EINVAL;
61466+ goto out;
61467+ }
61468+
61469+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
61470+ error = -EFAULT;
61471+ goto out;
61472+ }
61473+
61474+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61475+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61476+ time_after(gr_auth_expires, get_seconds())) {
61477+ error = -EBUSY;
61478+ goto out;
61479+ }
61480+
61481+ /* if non-root trying to do anything other than use a special role,
61482+ do not attempt authentication, do not count towards authentication
61483+ locking
61484+ */
61485+
61486+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
61487+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61488+ gr_is_global_nonroot(current_uid())) {
61489+ error = -EPERM;
61490+ goto out;
61491+ }
61492+
61493+ /* ensure pw and special role name are null terminated */
61494+
61495+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
61496+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
61497+
61498+ /* Okay.
61499+ * We have our enough of the argument structure..(we have yet
61500+ * to copy_from_user the tables themselves) . Copy the tables
61501+ * only if we need them, i.e. for loading operations. */
61502+
61503+ switch (gr_usermode->mode) {
61504+ case GR_STATUS:
61505+ if (gr_status & GR_READY) {
61506+ error = 1;
61507+ if (!gr_check_secure_terminal(current))
61508+ error = 3;
61509+ } else
61510+ error = 2;
61511+ goto out;
61512+ case GR_SHUTDOWN:
61513+ if ((gr_status & GR_READY)
61514+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61515+ stop_machine(gr_rbac_disable, NULL, NULL);
61516+ free_variables();
61517+ memset(gr_usermode, 0, sizeof (struct gr_arg));
61518+ memset(gr_system_salt, 0, GR_SALT_LEN);
61519+ memset(gr_system_sum, 0, GR_SHA_LEN);
61520+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
61521+ } else if (gr_status & GR_READY) {
61522+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
61523+ error = -EPERM;
61524+ } else {
61525+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
61526+ error = -EAGAIN;
61527+ }
61528+ break;
61529+ case GR_ENABLE:
61530+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
61531+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
61532+ else {
61533+ if (gr_status & GR_READY)
61534+ error = -EAGAIN;
61535+ else
61536+ error = error2;
61537+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
61538+ }
61539+ break;
61540+ case GR_RELOAD:
61541+ if (!(gr_status & GR_READY)) {
61542+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
61543+ error = -EAGAIN;
61544+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61545+ stop_machine(gr_rbac_disable, NULL, NULL);
61546+ free_variables();
61547+ error2 = gracl_init(gr_usermode);
61548+ if (!error2)
61549+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
61550+ else {
61551+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61552+ error = error2;
61553+ }
61554+ } else {
61555+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61556+ error = -EPERM;
61557+ }
61558+ break;
61559+ case GR_SEGVMOD:
61560+ if (unlikely(!(gr_status & GR_READY))) {
61561+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
61562+ error = -EAGAIN;
61563+ break;
61564+ }
61565+
61566+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61567+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
61568+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
61569+ struct acl_subject_label *segvacl;
61570+ segvacl =
61571+ lookup_acl_subj_label(gr_usermode->segv_inode,
61572+ gr_usermode->segv_device,
61573+ current->role);
61574+ if (segvacl) {
61575+ segvacl->crashes = 0;
61576+ segvacl->expires = 0;
61577+ }
61578+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
61579+ gr_remove_uid(gr_usermode->segv_uid);
61580+ }
61581+ } else {
61582+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
61583+ error = -EPERM;
61584+ }
61585+ break;
61586+ case GR_SPROLE:
61587+ case GR_SPROLEPAM:
61588+ if (unlikely(!(gr_status & GR_READY))) {
61589+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
61590+ error = -EAGAIN;
61591+ break;
61592+ }
61593+
61594+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
61595+ current->role->expires = 0;
61596+ current->role->auth_attempts = 0;
61597+ }
61598+
61599+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61600+ time_after(current->role->expires, get_seconds())) {
61601+ error = -EBUSY;
61602+ goto out;
61603+ }
61604+
61605+ if (lookup_special_role_auth
61606+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
61607+ && ((!sprole_salt && !sprole_sum)
61608+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
61609+ char *p = "";
61610+ assign_special_role(gr_usermode->sp_role);
61611+ read_lock(&tasklist_lock);
61612+ if (current->real_parent)
61613+ p = current->real_parent->role->rolename;
61614+ read_unlock(&tasklist_lock);
61615+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
61616+ p, acl_sp_role_value);
61617+ } else {
61618+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
61619+ error = -EPERM;
61620+ if(!(current->role->auth_attempts++))
61621+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61622+
61623+ goto out;
61624+ }
61625+ break;
61626+ case GR_UNSPROLE:
61627+ if (unlikely(!(gr_status & GR_READY))) {
61628+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
61629+ error = -EAGAIN;
61630+ break;
61631+ }
61632+
61633+ if (current->role->roletype & GR_ROLE_SPECIAL) {
61634+ char *p = "";
61635+ int i = 0;
61636+
61637+ read_lock(&tasklist_lock);
61638+ if (current->real_parent) {
61639+ p = current->real_parent->role->rolename;
61640+ i = current->real_parent->acl_role_id;
61641+ }
61642+ read_unlock(&tasklist_lock);
61643+
61644+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
61645+ gr_set_acls(1);
61646+ } else {
61647+ error = -EPERM;
61648+ goto out;
61649+ }
61650+ break;
61651+ default:
61652+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
61653+ error = -EINVAL;
61654+ break;
61655+ }
61656+
61657+ if (error != -EPERM)
61658+ goto out;
61659+
61660+ if(!(gr_auth_attempts++))
61661+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61662+
61663+ out:
61664+ mutex_unlock(&gr_dev_mutex);
61665+ return error;
61666+}
61667+
61668+/* must be called with
61669+ rcu_read_lock();
61670+ read_lock(&tasklist_lock);
61671+ read_lock(&grsec_exec_file_lock);
61672+*/
61673+int gr_apply_subject_to_task(struct task_struct *task)
61674+{
61675+ struct acl_object_label *obj;
61676+ char *tmpname;
61677+ struct acl_subject_label *tmpsubj;
61678+ struct file *filp;
61679+ struct name_entry *nmatch;
61680+
61681+ filp = task->exec_file;
61682+ if (filp == NULL)
61683+ return 0;
61684+
61685+ /* the following is to apply the correct subject
61686+ on binaries running when the RBAC system
61687+ is enabled, when the binaries have been
61688+ replaced or deleted since their execution
61689+ -----
61690+ when the RBAC system starts, the inode/dev
61691+ from exec_file will be one the RBAC system
61692+ is unaware of. It only knows the inode/dev
61693+ of the present file on disk, or the absence
61694+ of it.
61695+ */
61696+ preempt_disable();
61697+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
61698+
61699+ nmatch = lookup_name_entry(tmpname);
61700+ preempt_enable();
61701+ tmpsubj = NULL;
61702+ if (nmatch) {
61703+ if (nmatch->deleted)
61704+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
61705+ else
61706+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
61707+ if (tmpsubj != NULL)
61708+ task->acl = tmpsubj;
61709+ }
61710+ if (tmpsubj == NULL)
61711+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
61712+ task->role);
61713+ if (task->acl) {
61714+ task->is_writable = 0;
61715+ /* ignore additional mmap checks for processes that are writable
61716+ by the default ACL */
61717+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61718+ if (unlikely(obj->mode & GR_WRITE))
61719+ task->is_writable = 1;
61720+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61721+ if (unlikely(obj->mode & GR_WRITE))
61722+ task->is_writable = 1;
61723+
61724+ gr_set_proc_res(task);
61725+
61726+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61727+ 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);
61728+#endif
61729+ } else {
61730+ return 1;
61731+ }
61732+
61733+ return 0;
61734+}
61735+
61736+int
61737+gr_set_acls(const int type)
61738+{
61739+ struct task_struct *task, *task2;
61740+ struct acl_role_label *role = current->role;
61741+ __u16 acl_role_id = current->acl_role_id;
61742+ const struct cred *cred;
61743+ int ret;
61744+
61745+ rcu_read_lock();
61746+ read_lock(&tasklist_lock);
61747+ read_lock(&grsec_exec_file_lock);
61748+ do_each_thread(task2, task) {
61749+ /* check to see if we're called from the exit handler,
61750+ if so, only replace ACLs that have inherited the admin
61751+ ACL */
61752+
61753+ if (type && (task->role != role ||
61754+ task->acl_role_id != acl_role_id))
61755+ continue;
61756+
61757+ task->acl_role_id = 0;
61758+ task->acl_sp_role = 0;
61759+
61760+ if (task->exec_file) {
61761+ cred = __task_cred(task);
61762+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
61763+ ret = gr_apply_subject_to_task(task);
61764+ if (ret) {
61765+ read_unlock(&grsec_exec_file_lock);
61766+ read_unlock(&tasklist_lock);
61767+ rcu_read_unlock();
61768+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
61769+ return ret;
61770+ }
61771+ } else {
61772+ // it's a kernel process
61773+ task->role = kernel_role;
61774+ task->acl = kernel_role->root_label;
61775+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
61776+ task->acl->mode &= ~GR_PROCFIND;
61777+#endif
61778+ }
61779+ } while_each_thread(task2, task);
61780+ read_unlock(&grsec_exec_file_lock);
61781+ read_unlock(&tasklist_lock);
61782+ rcu_read_unlock();
61783+
61784+ return 0;
61785+}
61786+
61787+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
61788+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
61789+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
61790+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
61791+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
61792+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
61793+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
61794+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
61795+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
61796+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
61797+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
61798+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
61799+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
61800+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
61801+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
61802+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
61803+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
61804+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
61805+};
61806+
61807+void
61808+gr_learn_resource(const struct task_struct *task,
61809+ const int res, const unsigned long wanted, const int gt)
61810+{
61811+ struct acl_subject_label *acl;
61812+ const struct cred *cred;
61813+
61814+ if (unlikely((gr_status & GR_READY) &&
61815+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
61816+ goto skip_reslog;
61817+
61818+ gr_log_resource(task, res, wanted, gt);
61819+skip_reslog:
61820+
61821+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
61822+ return;
61823+
61824+ acl = task->acl;
61825+
61826+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
61827+ !(acl->resmask & (1U << (unsigned short) res))))
61828+ return;
61829+
61830+ if (wanted >= acl->res[res].rlim_cur) {
61831+ unsigned long res_add;
61832+
61833+ res_add = wanted + res_learn_bumps[res];
61834+
61835+ acl->res[res].rlim_cur = res_add;
61836+
61837+ if (wanted > acl->res[res].rlim_max)
61838+ acl->res[res].rlim_max = res_add;
61839+
61840+ /* only log the subject filename, since resource logging is supported for
61841+ single-subject learning only */
61842+ rcu_read_lock();
61843+ cred = __task_cred(task);
61844+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61845+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
61846+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
61847+ "", (unsigned long) res, &task->signal->saved_ip);
61848+ rcu_read_unlock();
61849+ }
61850+
61851+ return;
61852+}
61853+EXPORT_SYMBOL(gr_learn_resource);
61854+#endif
61855+
61856+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
61857+void
61858+pax_set_initial_flags(struct linux_binprm *bprm)
61859+{
61860+ struct task_struct *task = current;
61861+ struct acl_subject_label *proc;
61862+ unsigned long flags;
61863+
61864+ if (unlikely(!(gr_status & GR_READY)))
61865+ return;
61866+
61867+ flags = pax_get_flags(task);
61868+
61869+ proc = task->acl;
61870+
61871+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
61872+ flags &= ~MF_PAX_PAGEEXEC;
61873+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
61874+ flags &= ~MF_PAX_SEGMEXEC;
61875+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
61876+ flags &= ~MF_PAX_RANDMMAP;
61877+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
61878+ flags &= ~MF_PAX_EMUTRAMP;
61879+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
61880+ flags &= ~MF_PAX_MPROTECT;
61881+
61882+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
61883+ flags |= MF_PAX_PAGEEXEC;
61884+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
61885+ flags |= MF_PAX_SEGMEXEC;
61886+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
61887+ flags |= MF_PAX_RANDMMAP;
61888+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
61889+ flags |= MF_PAX_EMUTRAMP;
61890+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
61891+ flags |= MF_PAX_MPROTECT;
61892+
61893+ pax_set_flags(task, flags);
61894+
61895+ return;
61896+}
61897+#endif
61898+
61899+int
61900+gr_handle_proc_ptrace(struct task_struct *task)
61901+{
61902+ struct file *filp;
61903+ struct task_struct *tmp = task;
61904+ struct task_struct *curtemp = current;
61905+ __u32 retmode;
61906+
61907+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61908+ if (unlikely(!(gr_status & GR_READY)))
61909+ return 0;
61910+#endif
61911+
61912+ read_lock(&tasklist_lock);
61913+ read_lock(&grsec_exec_file_lock);
61914+ filp = task->exec_file;
61915+
61916+ while (task_pid_nr(tmp) > 0) {
61917+ if (tmp == curtemp)
61918+ break;
61919+ tmp = tmp->real_parent;
61920+ }
61921+
61922+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61923+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
61924+ read_unlock(&grsec_exec_file_lock);
61925+ read_unlock(&tasklist_lock);
61926+ return 1;
61927+ }
61928+
61929+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61930+ if (!(gr_status & GR_READY)) {
61931+ read_unlock(&grsec_exec_file_lock);
61932+ read_unlock(&tasklist_lock);
61933+ return 0;
61934+ }
61935+#endif
61936+
61937+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
61938+ read_unlock(&grsec_exec_file_lock);
61939+ read_unlock(&tasklist_lock);
61940+
61941+ if (retmode & GR_NOPTRACE)
61942+ return 1;
61943+
61944+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
61945+ && (current->acl != task->acl || (current->acl != current->role->root_label
61946+ && task_pid_nr(current) != task_pid_nr(task))))
61947+ return 1;
61948+
61949+ return 0;
61950+}
61951+
61952+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
61953+{
61954+ if (unlikely(!(gr_status & GR_READY)))
61955+ return;
61956+
61957+ if (!(current->role->roletype & GR_ROLE_GOD))
61958+ return;
61959+
61960+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
61961+ p->role->rolename, gr_task_roletype_to_char(p),
61962+ p->acl->filename);
61963+}
61964+
61965+int
61966+gr_handle_ptrace(struct task_struct *task, const long request)
61967+{
61968+ struct task_struct *tmp = task;
61969+ struct task_struct *curtemp = current;
61970+ __u32 retmode;
61971+
61972+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61973+ if (unlikely(!(gr_status & GR_READY)))
61974+ return 0;
61975+#endif
61976+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
61977+ read_lock(&tasklist_lock);
61978+ while (task_pid_nr(tmp) > 0) {
61979+ if (tmp == curtemp)
61980+ break;
61981+ tmp = tmp->real_parent;
61982+ }
61983+
61984+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61985+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
61986+ read_unlock(&tasklist_lock);
61987+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61988+ return 1;
61989+ }
61990+ read_unlock(&tasklist_lock);
61991+ }
61992+
61993+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61994+ if (!(gr_status & GR_READY))
61995+ return 0;
61996+#endif
61997+
61998+ read_lock(&grsec_exec_file_lock);
61999+ if (unlikely(!task->exec_file)) {
62000+ read_unlock(&grsec_exec_file_lock);
62001+ return 0;
62002+ }
62003+
62004+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
62005+ read_unlock(&grsec_exec_file_lock);
62006+
62007+ if (retmode & GR_NOPTRACE) {
62008+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62009+ return 1;
62010+ }
62011+
62012+ if (retmode & GR_PTRACERD) {
62013+ switch (request) {
62014+ case PTRACE_SEIZE:
62015+ case PTRACE_POKETEXT:
62016+ case PTRACE_POKEDATA:
62017+ case PTRACE_POKEUSR:
62018+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
62019+ case PTRACE_SETREGS:
62020+ case PTRACE_SETFPREGS:
62021+#endif
62022+#ifdef CONFIG_X86
62023+ case PTRACE_SETFPXREGS:
62024+#endif
62025+#ifdef CONFIG_ALTIVEC
62026+ case PTRACE_SETVRREGS:
62027+#endif
62028+ return 1;
62029+ default:
62030+ return 0;
62031+ }
62032+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
62033+ !(current->role->roletype & GR_ROLE_GOD) &&
62034+ (current->acl != task->acl)) {
62035+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62036+ return 1;
62037+ }
62038+
62039+ return 0;
62040+}
62041+
62042+static int is_writable_mmap(const struct file *filp)
62043+{
62044+ struct task_struct *task = current;
62045+ struct acl_object_label *obj, *obj2;
62046+
62047+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
62048+ !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))) {
62049+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
62050+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
62051+ task->role->root_label);
62052+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
62053+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
62054+ return 1;
62055+ }
62056+ }
62057+ return 0;
62058+}
62059+
62060+int
62061+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
62062+{
62063+ __u32 mode;
62064+
62065+ if (unlikely(!file || !(prot & PROT_EXEC)))
62066+ return 1;
62067+
62068+ if (is_writable_mmap(file))
62069+ return 0;
62070+
62071+ mode =
62072+ gr_search_file(file->f_path.dentry,
62073+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62074+ file->f_path.mnt);
62075+
62076+ if (!gr_tpe_allow(file))
62077+ return 0;
62078+
62079+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62080+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62081+ return 0;
62082+ } else if (unlikely(!(mode & GR_EXEC))) {
62083+ return 0;
62084+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62085+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62086+ return 1;
62087+ }
62088+
62089+ return 1;
62090+}
62091+
62092+int
62093+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62094+{
62095+ __u32 mode;
62096+
62097+ if (unlikely(!file || !(prot & PROT_EXEC)))
62098+ return 1;
62099+
62100+ if (is_writable_mmap(file))
62101+ return 0;
62102+
62103+ mode =
62104+ gr_search_file(file->f_path.dentry,
62105+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62106+ file->f_path.mnt);
62107+
62108+ if (!gr_tpe_allow(file))
62109+ return 0;
62110+
62111+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62112+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62113+ return 0;
62114+ } else if (unlikely(!(mode & GR_EXEC))) {
62115+ return 0;
62116+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62117+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62118+ return 1;
62119+ }
62120+
62121+ return 1;
62122+}
62123+
62124+void
62125+gr_acl_handle_psacct(struct task_struct *task, const long code)
62126+{
62127+ unsigned long runtime;
62128+ unsigned long cputime;
62129+ unsigned int wday, cday;
62130+ __u8 whr, chr;
62131+ __u8 wmin, cmin;
62132+ __u8 wsec, csec;
62133+ struct timespec timeval;
62134+
62135+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
62136+ !(task->acl->mode & GR_PROCACCT)))
62137+ return;
62138+
62139+ do_posix_clock_monotonic_gettime(&timeval);
62140+ runtime = timeval.tv_sec - task->start_time.tv_sec;
62141+ wday = runtime / (3600 * 24);
62142+ runtime -= wday * (3600 * 24);
62143+ whr = runtime / 3600;
62144+ runtime -= whr * 3600;
62145+ wmin = runtime / 60;
62146+ runtime -= wmin * 60;
62147+ wsec = runtime;
62148+
62149+ cputime = (task->utime + task->stime) / HZ;
62150+ cday = cputime / (3600 * 24);
62151+ cputime -= cday * (3600 * 24);
62152+ chr = cputime / 3600;
62153+ cputime -= chr * 3600;
62154+ cmin = cputime / 60;
62155+ cputime -= cmin * 60;
62156+ csec = cputime;
62157+
62158+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
62159+
62160+ return;
62161+}
62162+
62163+void gr_set_kernel_label(struct task_struct *task)
62164+{
62165+ if (gr_status & GR_READY) {
62166+ task->role = kernel_role;
62167+ task->acl = kernel_role->root_label;
62168+ }
62169+ return;
62170+}
62171+
62172+#ifdef CONFIG_TASKSTATS
62173+int gr_is_taskstats_denied(int pid)
62174+{
62175+ struct task_struct *task;
62176+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62177+ const struct cred *cred;
62178+#endif
62179+ int ret = 0;
62180+
62181+ /* restrict taskstats viewing to un-chrooted root users
62182+ who have the 'view' subject flag if the RBAC system is enabled
62183+ */
62184+
62185+ rcu_read_lock();
62186+ read_lock(&tasklist_lock);
62187+ task = find_task_by_vpid(pid);
62188+ if (task) {
62189+#ifdef CONFIG_GRKERNSEC_CHROOT
62190+ if (proc_is_chrooted(task))
62191+ ret = -EACCES;
62192+#endif
62193+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62194+ cred = __task_cred(task);
62195+#ifdef CONFIG_GRKERNSEC_PROC_USER
62196+ if (gr_is_global_nonroot(cred->uid))
62197+ ret = -EACCES;
62198+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62199+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
62200+ ret = -EACCES;
62201+#endif
62202+#endif
62203+ if (gr_status & GR_READY) {
62204+ if (!(task->acl->mode & GR_VIEW))
62205+ ret = -EACCES;
62206+ }
62207+ } else
62208+ ret = -ENOENT;
62209+
62210+ read_unlock(&tasklist_lock);
62211+ rcu_read_unlock();
62212+
62213+ return ret;
62214+}
62215+#endif
62216+
62217+/* AUXV entries are filled via a descendant of search_binary_handler
62218+ after we've already applied the subject for the target
62219+*/
62220+int gr_acl_enable_at_secure(void)
62221+{
62222+ if (unlikely(!(gr_status & GR_READY)))
62223+ return 0;
62224+
62225+ if (current->acl->mode & GR_ATSECURE)
62226+ return 1;
62227+
62228+ return 0;
62229+}
62230+
62231+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
62232+{
62233+ struct task_struct *task = current;
62234+ struct dentry *dentry = file->f_path.dentry;
62235+ struct vfsmount *mnt = file->f_path.mnt;
62236+ struct acl_object_label *obj, *tmp;
62237+ struct acl_subject_label *subj;
62238+ unsigned int bufsize;
62239+ int is_not_root;
62240+ char *path;
62241+ dev_t dev = __get_dev(dentry);
62242+
62243+ if (unlikely(!(gr_status & GR_READY)))
62244+ return 1;
62245+
62246+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
62247+ return 1;
62248+
62249+ /* ignore Eric Biederman */
62250+ if (IS_PRIVATE(dentry->d_inode))
62251+ return 1;
62252+
62253+ subj = task->acl;
62254+ read_lock(&gr_inode_lock);
62255+ do {
62256+ obj = lookup_acl_obj_label(ino, dev, subj);
62257+ if (obj != NULL) {
62258+ read_unlock(&gr_inode_lock);
62259+ return (obj->mode & GR_FIND) ? 1 : 0;
62260+ }
62261+ } while ((subj = subj->parent_subject));
62262+ read_unlock(&gr_inode_lock);
62263+
62264+ /* this is purely an optimization since we're looking for an object
62265+ for the directory we're doing a readdir on
62266+ if it's possible for any globbed object to match the entry we're
62267+ filling into the directory, then the object we find here will be
62268+ an anchor point with attached globbed objects
62269+ */
62270+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
62271+ if (obj->globbed == NULL)
62272+ return (obj->mode & GR_FIND) ? 1 : 0;
62273+
62274+ is_not_root = ((obj->filename[0] == '/') &&
62275+ (obj->filename[1] == '\0')) ? 0 : 1;
62276+ bufsize = PAGE_SIZE - namelen - is_not_root;
62277+
62278+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
62279+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
62280+ return 1;
62281+
62282+ preempt_disable();
62283+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62284+ bufsize);
62285+
62286+ bufsize = strlen(path);
62287+
62288+ /* if base is "/", don't append an additional slash */
62289+ if (is_not_root)
62290+ *(path + bufsize) = '/';
62291+ memcpy(path + bufsize + is_not_root, name, namelen);
62292+ *(path + bufsize + namelen + is_not_root) = '\0';
62293+
62294+ tmp = obj->globbed;
62295+ while (tmp) {
62296+ if (!glob_match(tmp->filename, path)) {
62297+ preempt_enable();
62298+ return (tmp->mode & GR_FIND) ? 1 : 0;
62299+ }
62300+ tmp = tmp->next;
62301+ }
62302+ preempt_enable();
62303+ return (obj->mode & GR_FIND) ? 1 : 0;
62304+}
62305+
62306+void gr_put_exec_file(struct task_struct *task)
62307+{
62308+ struct file *filp;
62309+
62310+ write_lock(&grsec_exec_file_lock);
62311+ filp = task->exec_file;
62312+ task->exec_file = NULL;
62313+ write_unlock(&grsec_exec_file_lock);
62314+
62315+ if (filp)
62316+ fput(filp);
62317+
62318+ return;
62319+}
62320+
62321+
62322+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
62323+EXPORT_SYMBOL(gr_acl_is_enabled);
62324+#endif
62325+EXPORT_SYMBOL(gr_set_kernel_label);
62326+#ifdef CONFIG_SECURITY
62327+EXPORT_SYMBOL(gr_check_user_change);
62328+EXPORT_SYMBOL(gr_check_group_change);
62329+#endif
62330+
62331diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
62332new file mode 100644
62333index 0000000..34fefda
62334--- /dev/null
62335+++ b/grsecurity/gracl_alloc.c
62336@@ -0,0 +1,105 @@
62337+#include <linux/kernel.h>
62338+#include <linux/mm.h>
62339+#include <linux/slab.h>
62340+#include <linux/vmalloc.h>
62341+#include <linux/gracl.h>
62342+#include <linux/grsecurity.h>
62343+
62344+static unsigned long alloc_stack_next = 1;
62345+static unsigned long alloc_stack_size = 1;
62346+static void **alloc_stack;
62347+
62348+static __inline__ int
62349+alloc_pop(void)
62350+{
62351+ if (alloc_stack_next == 1)
62352+ return 0;
62353+
62354+ kfree(alloc_stack[alloc_stack_next - 2]);
62355+
62356+ alloc_stack_next--;
62357+
62358+ return 1;
62359+}
62360+
62361+static __inline__ int
62362+alloc_push(void *buf)
62363+{
62364+ if (alloc_stack_next >= alloc_stack_size)
62365+ return 1;
62366+
62367+ alloc_stack[alloc_stack_next - 1] = buf;
62368+
62369+ alloc_stack_next++;
62370+
62371+ return 0;
62372+}
62373+
62374+void *
62375+acl_alloc(unsigned long len)
62376+{
62377+ void *ret = NULL;
62378+
62379+ if (!len || len > PAGE_SIZE)
62380+ goto out;
62381+
62382+ ret = kmalloc(len, GFP_KERNEL);
62383+
62384+ if (ret) {
62385+ if (alloc_push(ret)) {
62386+ kfree(ret);
62387+ ret = NULL;
62388+ }
62389+ }
62390+
62391+out:
62392+ return ret;
62393+}
62394+
62395+void *
62396+acl_alloc_num(unsigned long num, unsigned long len)
62397+{
62398+ if (!len || (num > (PAGE_SIZE / len)))
62399+ return NULL;
62400+
62401+ return acl_alloc(num * len);
62402+}
62403+
62404+void
62405+acl_free_all(void)
62406+{
62407+ if (gr_acl_is_enabled() || !alloc_stack)
62408+ return;
62409+
62410+ while (alloc_pop()) ;
62411+
62412+ if (alloc_stack) {
62413+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
62414+ kfree(alloc_stack);
62415+ else
62416+ vfree(alloc_stack);
62417+ }
62418+
62419+ alloc_stack = NULL;
62420+ alloc_stack_size = 1;
62421+ alloc_stack_next = 1;
62422+
62423+ return;
62424+}
62425+
62426+int
62427+acl_alloc_stack_init(unsigned long size)
62428+{
62429+ if ((size * sizeof (void *)) <= PAGE_SIZE)
62430+ alloc_stack =
62431+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
62432+ else
62433+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
62434+
62435+ alloc_stack_size = size;
62436+
62437+ if (!alloc_stack)
62438+ return 0;
62439+ else
62440+ return 1;
62441+}
62442diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
62443new file mode 100644
62444index 0000000..bdd51ea
62445--- /dev/null
62446+++ b/grsecurity/gracl_cap.c
62447@@ -0,0 +1,110 @@
62448+#include <linux/kernel.h>
62449+#include <linux/module.h>
62450+#include <linux/sched.h>
62451+#include <linux/gracl.h>
62452+#include <linux/grsecurity.h>
62453+#include <linux/grinternal.h>
62454+
62455+extern const char *captab_log[];
62456+extern int captab_log_entries;
62457+
62458+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62459+{
62460+ struct acl_subject_label *curracl;
62461+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62462+ kernel_cap_t cap_audit = __cap_empty_set;
62463+
62464+ if (!gr_acl_is_enabled())
62465+ return 1;
62466+
62467+ curracl = task->acl;
62468+
62469+ cap_drop = curracl->cap_lower;
62470+ cap_mask = curracl->cap_mask;
62471+ cap_audit = curracl->cap_invert_audit;
62472+
62473+ while ((curracl = curracl->parent_subject)) {
62474+ /* if the cap isn't specified in the current computed mask but is specified in the
62475+ current level subject, and is lowered in the current level subject, then add
62476+ it to the set of dropped capabilities
62477+ otherwise, add the current level subject's mask to the current computed mask
62478+ */
62479+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62480+ cap_raise(cap_mask, cap);
62481+ if (cap_raised(curracl->cap_lower, cap))
62482+ cap_raise(cap_drop, cap);
62483+ if (cap_raised(curracl->cap_invert_audit, cap))
62484+ cap_raise(cap_audit, cap);
62485+ }
62486+ }
62487+
62488+ if (!cap_raised(cap_drop, cap)) {
62489+ if (cap_raised(cap_audit, cap))
62490+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
62491+ return 1;
62492+ }
62493+
62494+ curracl = task->acl;
62495+
62496+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
62497+ && cap_raised(cred->cap_effective, cap)) {
62498+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62499+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
62500+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
62501+ gr_to_filename(task->exec_file->f_path.dentry,
62502+ task->exec_file->f_path.mnt) : curracl->filename,
62503+ curracl->filename, 0UL,
62504+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
62505+ return 1;
62506+ }
62507+
62508+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
62509+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
62510+
62511+ return 0;
62512+}
62513+
62514+int
62515+gr_acl_is_capable(const int cap)
62516+{
62517+ return gr_task_acl_is_capable(current, current_cred(), cap);
62518+}
62519+
62520+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
62521+{
62522+ struct acl_subject_label *curracl;
62523+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62524+
62525+ if (!gr_acl_is_enabled())
62526+ return 1;
62527+
62528+ curracl = task->acl;
62529+
62530+ cap_drop = curracl->cap_lower;
62531+ cap_mask = curracl->cap_mask;
62532+
62533+ while ((curracl = curracl->parent_subject)) {
62534+ /* if the cap isn't specified in the current computed mask but is specified in the
62535+ current level subject, and is lowered in the current level subject, then add
62536+ it to the set of dropped capabilities
62537+ otherwise, add the current level subject's mask to the current computed mask
62538+ */
62539+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62540+ cap_raise(cap_mask, cap);
62541+ if (cap_raised(curracl->cap_lower, cap))
62542+ cap_raise(cap_drop, cap);
62543+ }
62544+ }
62545+
62546+ if (!cap_raised(cap_drop, cap))
62547+ return 1;
62548+
62549+ return 0;
62550+}
62551+
62552+int
62553+gr_acl_is_capable_nolog(const int cap)
62554+{
62555+ return gr_task_acl_is_capable_nolog(current, cap);
62556+}
62557+
62558diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
62559new file mode 100644
62560index 0000000..a340c17
62561--- /dev/null
62562+++ b/grsecurity/gracl_fs.c
62563@@ -0,0 +1,431 @@
62564+#include <linux/kernel.h>
62565+#include <linux/sched.h>
62566+#include <linux/types.h>
62567+#include <linux/fs.h>
62568+#include <linux/file.h>
62569+#include <linux/stat.h>
62570+#include <linux/grsecurity.h>
62571+#include <linux/grinternal.h>
62572+#include <linux/gracl.h>
62573+
62574+umode_t
62575+gr_acl_umask(void)
62576+{
62577+ if (unlikely(!gr_acl_is_enabled()))
62578+ return 0;
62579+
62580+ return current->role->umask;
62581+}
62582+
62583+__u32
62584+gr_acl_handle_hidden_file(const struct dentry * dentry,
62585+ const struct vfsmount * mnt)
62586+{
62587+ __u32 mode;
62588+
62589+ if (unlikely(!dentry->d_inode))
62590+ return GR_FIND;
62591+
62592+ mode =
62593+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
62594+
62595+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
62596+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62597+ return mode;
62598+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
62599+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62600+ return 0;
62601+ } else if (unlikely(!(mode & GR_FIND)))
62602+ return 0;
62603+
62604+ return GR_FIND;
62605+}
62606+
62607+__u32
62608+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62609+ int acc_mode)
62610+{
62611+ __u32 reqmode = GR_FIND;
62612+ __u32 mode;
62613+
62614+ if (unlikely(!dentry->d_inode))
62615+ return reqmode;
62616+
62617+ if (acc_mode & MAY_APPEND)
62618+ reqmode |= GR_APPEND;
62619+ else if (acc_mode & MAY_WRITE)
62620+ reqmode |= GR_WRITE;
62621+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
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_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62630+ reqmode & GR_READ ? " reading" : "",
62631+ reqmode & GR_WRITE ? " writing" : reqmode &
62632+ GR_APPEND ? " appending" : "");
62633+ return reqmode;
62634+ } else
62635+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62636+ {
62637+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62638+ reqmode & GR_READ ? " reading" : "",
62639+ reqmode & GR_WRITE ? " writing" : reqmode &
62640+ GR_APPEND ? " appending" : "");
62641+ return 0;
62642+ } else if (unlikely((mode & reqmode) != reqmode))
62643+ return 0;
62644+
62645+ return reqmode;
62646+}
62647+
62648+__u32
62649+gr_acl_handle_creat(const struct dentry * dentry,
62650+ const struct dentry * p_dentry,
62651+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
62652+ const int imode)
62653+{
62654+ __u32 reqmode = GR_WRITE | GR_CREATE;
62655+ __u32 mode;
62656+
62657+ if (acc_mode & MAY_APPEND)
62658+ reqmode |= GR_APPEND;
62659+ // if a directory was required or the directory already exists, then
62660+ // don't count this open as a read
62661+ if ((acc_mode & MAY_READ) &&
62662+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
62663+ reqmode |= GR_READ;
62664+ if ((open_flags & O_CREAT) &&
62665+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62666+ reqmode |= GR_SETID;
62667+
62668+ mode =
62669+ gr_check_create(dentry, p_dentry, p_mnt,
62670+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62671+
62672+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62673+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62674+ reqmode & GR_READ ? " reading" : "",
62675+ reqmode & GR_WRITE ? " writing" : reqmode &
62676+ GR_APPEND ? " appending" : "");
62677+ return reqmode;
62678+ } else
62679+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62680+ {
62681+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62682+ reqmode & GR_READ ? " reading" : "",
62683+ reqmode & GR_WRITE ? " writing" : reqmode &
62684+ GR_APPEND ? " appending" : "");
62685+ return 0;
62686+ } else if (unlikely((mode & reqmode) != reqmode))
62687+ return 0;
62688+
62689+ return reqmode;
62690+}
62691+
62692+__u32
62693+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
62694+ const int fmode)
62695+{
62696+ __u32 mode, reqmode = GR_FIND;
62697+
62698+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
62699+ reqmode |= GR_EXEC;
62700+ if (fmode & S_IWOTH)
62701+ reqmode |= GR_WRITE;
62702+ if (fmode & S_IROTH)
62703+ reqmode |= GR_READ;
62704+
62705+ mode =
62706+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62707+ mnt);
62708+
62709+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62710+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62711+ reqmode & GR_READ ? " reading" : "",
62712+ reqmode & GR_WRITE ? " writing" : "",
62713+ reqmode & GR_EXEC ? " executing" : "");
62714+ return reqmode;
62715+ } else
62716+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62717+ {
62718+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62719+ reqmode & GR_READ ? " reading" : "",
62720+ reqmode & GR_WRITE ? " writing" : "",
62721+ reqmode & GR_EXEC ? " executing" : "");
62722+ return 0;
62723+ } else if (unlikely((mode & reqmode) != reqmode))
62724+ return 0;
62725+
62726+ return reqmode;
62727+}
62728+
62729+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
62730+{
62731+ __u32 mode;
62732+
62733+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
62734+
62735+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62736+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
62737+ return mode;
62738+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62739+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
62740+ return 0;
62741+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62742+ return 0;
62743+
62744+ return (reqmode);
62745+}
62746+
62747+__u32
62748+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62749+{
62750+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
62751+}
62752+
62753+__u32
62754+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
62755+{
62756+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
62757+}
62758+
62759+__u32
62760+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
62761+{
62762+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
62763+}
62764+
62765+__u32
62766+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
62767+{
62768+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
62769+}
62770+
62771+__u32
62772+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
62773+ umode_t *modeptr)
62774+{
62775+ umode_t mode;
62776+
62777+ *modeptr &= ~gr_acl_umask();
62778+ mode = *modeptr;
62779+
62780+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
62781+ return 1;
62782+
62783+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
62784+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
62785+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
62786+ GR_CHMOD_ACL_MSG);
62787+ } else {
62788+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
62789+ }
62790+}
62791+
62792+__u32
62793+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
62794+{
62795+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
62796+}
62797+
62798+__u32
62799+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
62800+{
62801+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
62802+}
62803+
62804+__u32
62805+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
62806+{
62807+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
62808+}
62809+
62810+__u32
62811+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
62812+{
62813+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
62814+ GR_UNIXCONNECT_ACL_MSG);
62815+}
62816+
62817+/* hardlinks require at minimum create and link permission,
62818+ any additional privilege required is based on the
62819+ privilege of the file being linked to
62820+*/
62821+__u32
62822+gr_acl_handle_link(const struct dentry * new_dentry,
62823+ const struct dentry * parent_dentry,
62824+ const struct vfsmount * parent_mnt,
62825+ const struct dentry * old_dentry,
62826+ const struct vfsmount * old_mnt, const struct filename *to)
62827+{
62828+ __u32 mode;
62829+ __u32 needmode = GR_CREATE | GR_LINK;
62830+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
62831+
62832+ mode =
62833+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
62834+ old_mnt);
62835+
62836+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
62837+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62838+ return mode;
62839+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62840+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62841+ return 0;
62842+ } else if (unlikely((mode & needmode) != needmode))
62843+ return 0;
62844+
62845+ return 1;
62846+}
62847+
62848+__u32
62849+gr_acl_handle_symlink(const struct dentry * new_dentry,
62850+ const struct dentry * parent_dentry,
62851+ const struct vfsmount * parent_mnt, const struct filename *from)
62852+{
62853+ __u32 needmode = GR_WRITE | GR_CREATE;
62854+ __u32 mode;
62855+
62856+ mode =
62857+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
62858+ GR_CREATE | GR_AUDIT_CREATE |
62859+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
62860+
62861+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
62862+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62863+ return mode;
62864+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62865+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62866+ return 0;
62867+ } else if (unlikely((mode & needmode) != needmode))
62868+ return 0;
62869+
62870+ return (GR_WRITE | GR_CREATE);
62871+}
62872+
62873+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)
62874+{
62875+ __u32 mode;
62876+
62877+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62878+
62879+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62880+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
62881+ return mode;
62882+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62883+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
62884+ return 0;
62885+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62886+ return 0;
62887+
62888+ return (reqmode);
62889+}
62890+
62891+__u32
62892+gr_acl_handle_mknod(const struct dentry * new_dentry,
62893+ const struct dentry * parent_dentry,
62894+ const struct vfsmount * parent_mnt,
62895+ const int mode)
62896+{
62897+ __u32 reqmode = GR_WRITE | GR_CREATE;
62898+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62899+ reqmode |= GR_SETID;
62900+
62901+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62902+ reqmode, GR_MKNOD_ACL_MSG);
62903+}
62904+
62905+__u32
62906+gr_acl_handle_mkdir(const struct dentry *new_dentry,
62907+ const struct dentry *parent_dentry,
62908+ const struct vfsmount *parent_mnt)
62909+{
62910+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62911+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
62912+}
62913+
62914+#define RENAME_CHECK_SUCCESS(old, new) \
62915+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
62916+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
62917+
62918+int
62919+gr_acl_handle_rename(struct dentry *new_dentry,
62920+ struct dentry *parent_dentry,
62921+ const struct vfsmount *parent_mnt,
62922+ struct dentry *old_dentry,
62923+ struct inode *old_parent_inode,
62924+ struct vfsmount *old_mnt, const struct filename *newname)
62925+{
62926+ __u32 comp1, comp2;
62927+ int error = 0;
62928+
62929+ if (unlikely(!gr_acl_is_enabled()))
62930+ return 0;
62931+
62932+ if (!new_dentry->d_inode) {
62933+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
62934+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
62935+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
62936+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
62937+ GR_DELETE | GR_AUDIT_DELETE |
62938+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62939+ GR_SUPPRESS, old_mnt);
62940+ } else {
62941+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
62942+ GR_CREATE | GR_DELETE |
62943+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
62944+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62945+ GR_SUPPRESS, parent_mnt);
62946+ comp2 =
62947+ gr_search_file(old_dentry,
62948+ GR_READ | GR_WRITE | GR_AUDIT_READ |
62949+ GR_DELETE | GR_AUDIT_DELETE |
62950+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
62951+ }
62952+
62953+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
62954+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
62955+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62956+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
62957+ && !(comp2 & GR_SUPPRESS)) {
62958+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62959+ error = -EACCES;
62960+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
62961+ error = -EACCES;
62962+
62963+ return error;
62964+}
62965+
62966+void
62967+gr_acl_handle_exit(void)
62968+{
62969+ u16 id;
62970+ char *rolename;
62971+
62972+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
62973+ !(current->role->roletype & GR_ROLE_PERSIST))) {
62974+ id = current->acl_role_id;
62975+ rolename = current->role->rolename;
62976+ gr_set_acls(1);
62977+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
62978+ }
62979+
62980+ gr_put_exec_file(current);
62981+ return;
62982+}
62983+
62984+int
62985+gr_acl_handle_procpidmem(const struct task_struct *task)
62986+{
62987+ if (unlikely(!gr_acl_is_enabled()))
62988+ return 0;
62989+
62990+ if (task != current && task->acl->mode & GR_PROTPROCFD)
62991+ return -EACCES;
62992+
62993+ return 0;
62994+}
62995diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
62996new file mode 100644
62997index 0000000..8132048
62998--- /dev/null
62999+++ b/grsecurity/gracl_ip.c
63000@@ -0,0 +1,387 @@
63001+#include <linux/kernel.h>
63002+#include <asm/uaccess.h>
63003+#include <asm/errno.h>
63004+#include <net/sock.h>
63005+#include <linux/file.h>
63006+#include <linux/fs.h>
63007+#include <linux/net.h>
63008+#include <linux/in.h>
63009+#include <linux/skbuff.h>
63010+#include <linux/ip.h>
63011+#include <linux/udp.h>
63012+#include <linux/types.h>
63013+#include <linux/sched.h>
63014+#include <linux/netdevice.h>
63015+#include <linux/inetdevice.h>
63016+#include <linux/gracl.h>
63017+#include <linux/grsecurity.h>
63018+#include <linux/grinternal.h>
63019+
63020+#define GR_BIND 0x01
63021+#define GR_CONNECT 0x02
63022+#define GR_INVERT 0x04
63023+#define GR_BINDOVERRIDE 0x08
63024+#define GR_CONNECTOVERRIDE 0x10
63025+#define GR_SOCK_FAMILY 0x20
63026+
63027+static const char * gr_protocols[IPPROTO_MAX] = {
63028+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
63029+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
63030+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
63031+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
63032+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
63033+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
63034+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
63035+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
63036+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
63037+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
63038+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
63039+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
63040+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
63041+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
63042+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
63043+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
63044+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
63045+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
63046+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
63047+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
63048+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
63049+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
63050+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
63051+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
63052+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
63053+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
63054+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
63055+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
63056+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
63057+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
63058+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
63059+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
63060+ };
63061+
63062+static const char * gr_socktypes[SOCK_MAX] = {
63063+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
63064+ "unknown:7", "unknown:8", "unknown:9", "packet"
63065+ };
63066+
63067+static const char * gr_sockfamilies[AF_MAX+1] = {
63068+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
63069+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
63070+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
63071+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
63072+ };
63073+
63074+const char *
63075+gr_proto_to_name(unsigned char proto)
63076+{
63077+ return gr_protocols[proto];
63078+}
63079+
63080+const char *
63081+gr_socktype_to_name(unsigned char type)
63082+{
63083+ return gr_socktypes[type];
63084+}
63085+
63086+const char *
63087+gr_sockfamily_to_name(unsigned char family)
63088+{
63089+ return gr_sockfamilies[family];
63090+}
63091+
63092+int
63093+gr_search_socket(const int domain, const int type, const int protocol)
63094+{
63095+ struct acl_subject_label *curr;
63096+ const struct cred *cred = current_cred();
63097+
63098+ if (unlikely(!gr_acl_is_enabled()))
63099+ goto exit;
63100+
63101+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
63102+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
63103+ goto exit; // let the kernel handle it
63104+
63105+ curr = current->acl;
63106+
63107+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
63108+ /* the family is allowed, if this is PF_INET allow it only if
63109+ the extra sock type/protocol checks pass */
63110+ if (domain == PF_INET)
63111+ goto inet_check;
63112+ goto exit;
63113+ } else {
63114+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63115+ __u32 fakeip = 0;
63116+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63117+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63118+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63119+ gr_to_filename(current->exec_file->f_path.dentry,
63120+ current->exec_file->f_path.mnt) :
63121+ curr->filename, curr->filename,
63122+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
63123+ &current->signal->saved_ip);
63124+ goto exit;
63125+ }
63126+ goto exit_fail;
63127+ }
63128+
63129+inet_check:
63130+ /* the rest of this checking is for IPv4 only */
63131+ if (!curr->ips)
63132+ goto exit;
63133+
63134+ if ((curr->ip_type & (1U << type)) &&
63135+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
63136+ goto exit;
63137+
63138+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63139+ /* we don't place acls on raw sockets , and sometimes
63140+ dgram/ip sockets are opened for ioctl and not
63141+ bind/connect, so we'll fake a bind learn log */
63142+ if (type == SOCK_RAW || type == SOCK_PACKET) {
63143+ __u32 fakeip = 0;
63144+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63145+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63146+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63147+ gr_to_filename(current->exec_file->f_path.dentry,
63148+ current->exec_file->f_path.mnt) :
63149+ curr->filename, curr->filename,
63150+ &fakeip, 0, type,
63151+ protocol, GR_CONNECT, &current->signal->saved_ip);
63152+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
63153+ __u32 fakeip = 0;
63154+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63155+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63156+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63157+ gr_to_filename(current->exec_file->f_path.dentry,
63158+ current->exec_file->f_path.mnt) :
63159+ curr->filename, curr->filename,
63160+ &fakeip, 0, type,
63161+ protocol, GR_BIND, &current->signal->saved_ip);
63162+ }
63163+ /* we'll log when they use connect or bind */
63164+ goto exit;
63165+ }
63166+
63167+exit_fail:
63168+ if (domain == PF_INET)
63169+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
63170+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
63171+ else
63172+#ifndef CONFIG_IPV6
63173+ if (domain != PF_INET6)
63174+#endif
63175+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
63176+ gr_socktype_to_name(type), protocol);
63177+
63178+ return 0;
63179+exit:
63180+ return 1;
63181+}
63182+
63183+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)
63184+{
63185+ if ((ip->mode & mode) &&
63186+ (ip_port >= ip->low) &&
63187+ (ip_port <= ip->high) &&
63188+ ((ntohl(ip_addr) & our_netmask) ==
63189+ (ntohl(our_addr) & our_netmask))
63190+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
63191+ && (ip->type & (1U << type))) {
63192+ if (ip->mode & GR_INVERT)
63193+ return 2; // specifically denied
63194+ else
63195+ return 1; // allowed
63196+ }
63197+
63198+ return 0; // not specifically allowed, may continue parsing
63199+}
63200+
63201+static int
63202+gr_search_connectbind(const int full_mode, struct sock *sk,
63203+ struct sockaddr_in *addr, const int type)
63204+{
63205+ char iface[IFNAMSIZ] = {0};
63206+ struct acl_subject_label *curr;
63207+ struct acl_ip_label *ip;
63208+ struct inet_sock *isk;
63209+ struct net_device *dev;
63210+ struct in_device *idev;
63211+ unsigned long i;
63212+ int ret;
63213+ int mode = full_mode & (GR_BIND | GR_CONNECT);
63214+ __u32 ip_addr = 0;
63215+ __u32 our_addr;
63216+ __u32 our_netmask;
63217+ char *p;
63218+ __u16 ip_port = 0;
63219+ const struct cred *cred = current_cred();
63220+
63221+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
63222+ return 0;
63223+
63224+ curr = current->acl;
63225+ isk = inet_sk(sk);
63226+
63227+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
63228+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
63229+ addr->sin_addr.s_addr = curr->inaddr_any_override;
63230+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
63231+ struct sockaddr_in saddr;
63232+ int err;
63233+
63234+ saddr.sin_family = AF_INET;
63235+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
63236+ saddr.sin_port = isk->inet_sport;
63237+
63238+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63239+ if (err)
63240+ return err;
63241+
63242+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63243+ if (err)
63244+ return err;
63245+ }
63246+
63247+ if (!curr->ips)
63248+ return 0;
63249+
63250+ ip_addr = addr->sin_addr.s_addr;
63251+ ip_port = ntohs(addr->sin_port);
63252+
63253+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63254+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63255+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63256+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63257+ gr_to_filename(current->exec_file->f_path.dentry,
63258+ current->exec_file->f_path.mnt) :
63259+ curr->filename, curr->filename,
63260+ &ip_addr, ip_port, type,
63261+ sk->sk_protocol, mode, &current->signal->saved_ip);
63262+ return 0;
63263+ }
63264+
63265+ for (i = 0; i < curr->ip_num; i++) {
63266+ ip = *(curr->ips + i);
63267+ if (ip->iface != NULL) {
63268+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
63269+ p = strchr(iface, ':');
63270+ if (p != NULL)
63271+ *p = '\0';
63272+ dev = dev_get_by_name(sock_net(sk), iface);
63273+ if (dev == NULL)
63274+ continue;
63275+ idev = in_dev_get(dev);
63276+ if (idev == NULL) {
63277+ dev_put(dev);
63278+ continue;
63279+ }
63280+ rcu_read_lock();
63281+ for_ifa(idev) {
63282+ if (!strcmp(ip->iface, ifa->ifa_label)) {
63283+ our_addr = ifa->ifa_address;
63284+ our_netmask = 0xffffffff;
63285+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63286+ if (ret == 1) {
63287+ rcu_read_unlock();
63288+ in_dev_put(idev);
63289+ dev_put(dev);
63290+ return 0;
63291+ } else if (ret == 2) {
63292+ rcu_read_unlock();
63293+ in_dev_put(idev);
63294+ dev_put(dev);
63295+ goto denied;
63296+ }
63297+ }
63298+ } endfor_ifa(idev);
63299+ rcu_read_unlock();
63300+ in_dev_put(idev);
63301+ dev_put(dev);
63302+ } else {
63303+ our_addr = ip->addr;
63304+ our_netmask = ip->netmask;
63305+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63306+ if (ret == 1)
63307+ return 0;
63308+ else if (ret == 2)
63309+ goto denied;
63310+ }
63311+ }
63312+
63313+denied:
63314+ if (mode == GR_BIND)
63315+ 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));
63316+ else if (mode == GR_CONNECT)
63317+ 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));
63318+
63319+ return -EACCES;
63320+}
63321+
63322+int
63323+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
63324+{
63325+ /* always allow disconnection of dgram sockets with connect */
63326+ if (addr->sin_family == AF_UNSPEC)
63327+ return 0;
63328+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
63329+}
63330+
63331+int
63332+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
63333+{
63334+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
63335+}
63336+
63337+int gr_search_listen(struct socket *sock)
63338+{
63339+ struct sock *sk = sock->sk;
63340+ struct sockaddr_in addr;
63341+
63342+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63343+ addr.sin_port = inet_sk(sk)->inet_sport;
63344+
63345+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63346+}
63347+
63348+int gr_search_accept(struct socket *sock)
63349+{
63350+ struct sock *sk = sock->sk;
63351+ struct sockaddr_in addr;
63352+
63353+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63354+ addr.sin_port = inet_sk(sk)->inet_sport;
63355+
63356+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63357+}
63358+
63359+int
63360+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
63361+{
63362+ if (addr)
63363+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
63364+ else {
63365+ struct sockaddr_in sin;
63366+ const struct inet_sock *inet = inet_sk(sk);
63367+
63368+ sin.sin_addr.s_addr = inet->inet_daddr;
63369+ sin.sin_port = inet->inet_dport;
63370+
63371+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63372+ }
63373+}
63374+
63375+int
63376+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
63377+{
63378+ struct sockaddr_in sin;
63379+
63380+ if (unlikely(skb->len < sizeof (struct udphdr)))
63381+ return 0; // skip this packet
63382+
63383+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
63384+ sin.sin_port = udp_hdr(skb)->source;
63385+
63386+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63387+}
63388diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
63389new file mode 100644
63390index 0000000..25f54ef
63391--- /dev/null
63392+++ b/grsecurity/gracl_learn.c
63393@@ -0,0 +1,207 @@
63394+#include <linux/kernel.h>
63395+#include <linux/mm.h>
63396+#include <linux/sched.h>
63397+#include <linux/poll.h>
63398+#include <linux/string.h>
63399+#include <linux/file.h>
63400+#include <linux/types.h>
63401+#include <linux/vmalloc.h>
63402+#include <linux/grinternal.h>
63403+
63404+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
63405+ size_t count, loff_t *ppos);
63406+extern int gr_acl_is_enabled(void);
63407+
63408+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
63409+static int gr_learn_attached;
63410+
63411+/* use a 512k buffer */
63412+#define LEARN_BUFFER_SIZE (512 * 1024)
63413+
63414+static DEFINE_SPINLOCK(gr_learn_lock);
63415+static DEFINE_MUTEX(gr_learn_user_mutex);
63416+
63417+/* we need to maintain two buffers, so that the kernel context of grlearn
63418+ uses a semaphore around the userspace copying, and the other kernel contexts
63419+ use a spinlock when copying into the buffer, since they cannot sleep
63420+*/
63421+static char *learn_buffer;
63422+static char *learn_buffer_user;
63423+static int learn_buffer_len;
63424+static int learn_buffer_user_len;
63425+
63426+static ssize_t
63427+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
63428+{
63429+ DECLARE_WAITQUEUE(wait, current);
63430+ ssize_t retval = 0;
63431+
63432+ add_wait_queue(&learn_wait, &wait);
63433+ set_current_state(TASK_INTERRUPTIBLE);
63434+ do {
63435+ mutex_lock(&gr_learn_user_mutex);
63436+ spin_lock(&gr_learn_lock);
63437+ if (learn_buffer_len)
63438+ break;
63439+ spin_unlock(&gr_learn_lock);
63440+ mutex_unlock(&gr_learn_user_mutex);
63441+ if (file->f_flags & O_NONBLOCK) {
63442+ retval = -EAGAIN;
63443+ goto out;
63444+ }
63445+ if (signal_pending(current)) {
63446+ retval = -ERESTARTSYS;
63447+ goto out;
63448+ }
63449+
63450+ schedule();
63451+ } while (1);
63452+
63453+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
63454+ learn_buffer_user_len = learn_buffer_len;
63455+ retval = learn_buffer_len;
63456+ learn_buffer_len = 0;
63457+
63458+ spin_unlock(&gr_learn_lock);
63459+
63460+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
63461+ retval = -EFAULT;
63462+
63463+ mutex_unlock(&gr_learn_user_mutex);
63464+out:
63465+ set_current_state(TASK_RUNNING);
63466+ remove_wait_queue(&learn_wait, &wait);
63467+ return retval;
63468+}
63469+
63470+static unsigned int
63471+poll_learn(struct file * file, poll_table * wait)
63472+{
63473+ poll_wait(file, &learn_wait, wait);
63474+
63475+ if (learn_buffer_len)
63476+ return (POLLIN | POLLRDNORM);
63477+
63478+ return 0;
63479+}
63480+
63481+void
63482+gr_clear_learn_entries(void)
63483+{
63484+ char *tmp;
63485+
63486+ mutex_lock(&gr_learn_user_mutex);
63487+ spin_lock(&gr_learn_lock);
63488+ tmp = learn_buffer;
63489+ learn_buffer = NULL;
63490+ spin_unlock(&gr_learn_lock);
63491+ if (tmp)
63492+ vfree(tmp);
63493+ if (learn_buffer_user != NULL) {
63494+ vfree(learn_buffer_user);
63495+ learn_buffer_user = NULL;
63496+ }
63497+ learn_buffer_len = 0;
63498+ mutex_unlock(&gr_learn_user_mutex);
63499+
63500+ return;
63501+}
63502+
63503+void
63504+gr_add_learn_entry(const char *fmt, ...)
63505+{
63506+ va_list args;
63507+ unsigned int len;
63508+
63509+ if (!gr_learn_attached)
63510+ return;
63511+
63512+ spin_lock(&gr_learn_lock);
63513+
63514+ /* leave a gap at the end so we know when it's "full" but don't have to
63515+ compute the exact length of the string we're trying to append
63516+ */
63517+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
63518+ spin_unlock(&gr_learn_lock);
63519+ wake_up_interruptible(&learn_wait);
63520+ return;
63521+ }
63522+ if (learn_buffer == NULL) {
63523+ spin_unlock(&gr_learn_lock);
63524+ return;
63525+ }
63526+
63527+ va_start(args, fmt);
63528+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
63529+ va_end(args);
63530+
63531+ learn_buffer_len += len + 1;
63532+
63533+ spin_unlock(&gr_learn_lock);
63534+ wake_up_interruptible(&learn_wait);
63535+
63536+ return;
63537+}
63538+
63539+static int
63540+open_learn(struct inode *inode, struct file *file)
63541+{
63542+ if (file->f_mode & FMODE_READ && gr_learn_attached)
63543+ return -EBUSY;
63544+ if (file->f_mode & FMODE_READ) {
63545+ int retval = 0;
63546+ mutex_lock(&gr_learn_user_mutex);
63547+ if (learn_buffer == NULL)
63548+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
63549+ if (learn_buffer_user == NULL)
63550+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
63551+ if (learn_buffer == NULL) {
63552+ retval = -ENOMEM;
63553+ goto out_error;
63554+ }
63555+ if (learn_buffer_user == NULL) {
63556+ retval = -ENOMEM;
63557+ goto out_error;
63558+ }
63559+ learn_buffer_len = 0;
63560+ learn_buffer_user_len = 0;
63561+ gr_learn_attached = 1;
63562+out_error:
63563+ mutex_unlock(&gr_learn_user_mutex);
63564+ return retval;
63565+ }
63566+ return 0;
63567+}
63568+
63569+static int
63570+close_learn(struct inode *inode, struct file *file)
63571+{
63572+ if (file->f_mode & FMODE_READ) {
63573+ char *tmp = NULL;
63574+ mutex_lock(&gr_learn_user_mutex);
63575+ spin_lock(&gr_learn_lock);
63576+ tmp = learn_buffer;
63577+ learn_buffer = NULL;
63578+ spin_unlock(&gr_learn_lock);
63579+ if (tmp)
63580+ vfree(tmp);
63581+ if (learn_buffer_user != NULL) {
63582+ vfree(learn_buffer_user);
63583+ learn_buffer_user = NULL;
63584+ }
63585+ learn_buffer_len = 0;
63586+ learn_buffer_user_len = 0;
63587+ gr_learn_attached = 0;
63588+ mutex_unlock(&gr_learn_user_mutex);
63589+ }
63590+
63591+ return 0;
63592+}
63593+
63594+const struct file_operations grsec_fops = {
63595+ .read = read_learn,
63596+ .write = write_grsec_handler,
63597+ .open = open_learn,
63598+ .release = close_learn,
63599+ .poll = poll_learn,
63600+};
63601diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
63602new file mode 100644
63603index 0000000..39645c9
63604--- /dev/null
63605+++ b/grsecurity/gracl_res.c
63606@@ -0,0 +1,68 @@
63607+#include <linux/kernel.h>
63608+#include <linux/sched.h>
63609+#include <linux/gracl.h>
63610+#include <linux/grinternal.h>
63611+
63612+static const char *restab_log[] = {
63613+ [RLIMIT_CPU] = "RLIMIT_CPU",
63614+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
63615+ [RLIMIT_DATA] = "RLIMIT_DATA",
63616+ [RLIMIT_STACK] = "RLIMIT_STACK",
63617+ [RLIMIT_CORE] = "RLIMIT_CORE",
63618+ [RLIMIT_RSS] = "RLIMIT_RSS",
63619+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
63620+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
63621+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
63622+ [RLIMIT_AS] = "RLIMIT_AS",
63623+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
63624+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
63625+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
63626+ [RLIMIT_NICE] = "RLIMIT_NICE",
63627+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
63628+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
63629+ [GR_CRASH_RES] = "RLIMIT_CRASH"
63630+};
63631+
63632+void
63633+gr_log_resource(const struct task_struct *task,
63634+ const int res, const unsigned long wanted, const int gt)
63635+{
63636+ const struct cred *cred;
63637+ unsigned long rlim;
63638+
63639+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
63640+ return;
63641+
63642+ // not yet supported resource
63643+ if (unlikely(!restab_log[res]))
63644+ return;
63645+
63646+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
63647+ rlim = task_rlimit_max(task, res);
63648+ else
63649+ rlim = task_rlimit(task, res);
63650+
63651+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
63652+ return;
63653+
63654+ rcu_read_lock();
63655+ cred = __task_cred(task);
63656+
63657+ if (res == RLIMIT_NPROC &&
63658+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
63659+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
63660+ goto out_rcu_unlock;
63661+ else if (res == RLIMIT_MEMLOCK &&
63662+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
63663+ goto out_rcu_unlock;
63664+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
63665+ goto out_rcu_unlock;
63666+ rcu_read_unlock();
63667+
63668+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
63669+
63670+ return;
63671+out_rcu_unlock:
63672+ rcu_read_unlock();
63673+ return;
63674+}
63675diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
63676new file mode 100644
63677index 0000000..3c38bfe
63678--- /dev/null
63679+++ b/grsecurity/gracl_segv.c
63680@@ -0,0 +1,305 @@
63681+#include <linux/kernel.h>
63682+#include <linux/mm.h>
63683+#include <asm/uaccess.h>
63684+#include <asm/errno.h>
63685+#include <asm/mman.h>
63686+#include <net/sock.h>
63687+#include <linux/file.h>
63688+#include <linux/fs.h>
63689+#include <linux/net.h>
63690+#include <linux/in.h>
63691+#include <linux/slab.h>
63692+#include <linux/types.h>
63693+#include <linux/sched.h>
63694+#include <linux/timer.h>
63695+#include <linux/gracl.h>
63696+#include <linux/grsecurity.h>
63697+#include <linux/grinternal.h>
63698+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63699+#include <linux/magic.h>
63700+#include <linux/pagemap.h>
63701+#include "../fs/btrfs/async-thread.h"
63702+#include "../fs/btrfs/ctree.h"
63703+#include "../fs/btrfs/btrfs_inode.h"
63704+#endif
63705+
63706+static struct crash_uid *uid_set;
63707+static unsigned short uid_used;
63708+static DEFINE_SPINLOCK(gr_uid_lock);
63709+extern rwlock_t gr_inode_lock;
63710+extern struct acl_subject_label *
63711+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
63712+ struct acl_role_label *role);
63713+
63714+static inline dev_t __get_dev(const struct dentry *dentry)
63715+{
63716+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63717+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
63718+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
63719+ else
63720+#endif
63721+ return dentry->d_sb->s_dev;
63722+}
63723+
63724+int
63725+gr_init_uidset(void)
63726+{
63727+ uid_set =
63728+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
63729+ uid_used = 0;
63730+
63731+ return uid_set ? 1 : 0;
63732+}
63733+
63734+void
63735+gr_free_uidset(void)
63736+{
63737+ if (uid_set)
63738+ kfree(uid_set);
63739+
63740+ return;
63741+}
63742+
63743+int
63744+gr_find_uid(const uid_t uid)
63745+{
63746+ struct crash_uid *tmp = uid_set;
63747+ uid_t buid;
63748+ int low = 0, high = uid_used - 1, mid;
63749+
63750+ while (high >= low) {
63751+ mid = (low + high) >> 1;
63752+ buid = tmp[mid].uid;
63753+ if (buid == uid)
63754+ return mid;
63755+ if (buid > uid)
63756+ high = mid - 1;
63757+ if (buid < uid)
63758+ low = mid + 1;
63759+ }
63760+
63761+ return -1;
63762+}
63763+
63764+static __inline__ void
63765+gr_insertsort(void)
63766+{
63767+ unsigned short i, j;
63768+ struct crash_uid index;
63769+
63770+ for (i = 1; i < uid_used; i++) {
63771+ index = uid_set[i];
63772+ j = i;
63773+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
63774+ uid_set[j] = uid_set[j - 1];
63775+ j--;
63776+ }
63777+ uid_set[j] = index;
63778+ }
63779+
63780+ return;
63781+}
63782+
63783+static __inline__ void
63784+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
63785+{
63786+ int loc;
63787+ uid_t uid = GR_GLOBAL_UID(kuid);
63788+
63789+ if (uid_used == GR_UIDTABLE_MAX)
63790+ return;
63791+
63792+ loc = gr_find_uid(uid);
63793+
63794+ if (loc >= 0) {
63795+ uid_set[loc].expires = expires;
63796+ return;
63797+ }
63798+
63799+ uid_set[uid_used].uid = uid;
63800+ uid_set[uid_used].expires = expires;
63801+ uid_used++;
63802+
63803+ gr_insertsort();
63804+
63805+ return;
63806+}
63807+
63808+void
63809+gr_remove_uid(const unsigned short loc)
63810+{
63811+ unsigned short i;
63812+
63813+ for (i = loc + 1; i < uid_used; i++)
63814+ uid_set[i - 1] = uid_set[i];
63815+
63816+ uid_used--;
63817+
63818+ return;
63819+}
63820+
63821+int
63822+gr_check_crash_uid(const kuid_t kuid)
63823+{
63824+ int loc;
63825+ int ret = 0;
63826+ uid_t uid;
63827+
63828+ if (unlikely(!gr_acl_is_enabled()))
63829+ return 0;
63830+
63831+ uid = GR_GLOBAL_UID(kuid);
63832+
63833+ spin_lock(&gr_uid_lock);
63834+ loc = gr_find_uid(uid);
63835+
63836+ if (loc < 0)
63837+ goto out_unlock;
63838+
63839+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
63840+ gr_remove_uid(loc);
63841+ else
63842+ ret = 1;
63843+
63844+out_unlock:
63845+ spin_unlock(&gr_uid_lock);
63846+ return ret;
63847+}
63848+
63849+static __inline__ int
63850+proc_is_setxid(const struct cred *cred)
63851+{
63852+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
63853+ !uid_eq(cred->uid, cred->fsuid))
63854+ return 1;
63855+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
63856+ !gid_eq(cred->gid, cred->fsgid))
63857+ return 1;
63858+
63859+ return 0;
63860+}
63861+
63862+extern int gr_fake_force_sig(int sig, struct task_struct *t);
63863+
63864+void
63865+gr_handle_crash(struct task_struct *task, const int sig)
63866+{
63867+ struct acl_subject_label *curr;
63868+ struct task_struct *tsk, *tsk2;
63869+ const struct cred *cred;
63870+ const struct cred *cred2;
63871+
63872+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
63873+ return;
63874+
63875+ if (unlikely(!gr_acl_is_enabled()))
63876+ return;
63877+
63878+ curr = task->acl;
63879+
63880+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
63881+ return;
63882+
63883+ if (time_before_eq(curr->expires, get_seconds())) {
63884+ curr->expires = 0;
63885+ curr->crashes = 0;
63886+ }
63887+
63888+ curr->crashes++;
63889+
63890+ if (!curr->expires)
63891+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
63892+
63893+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63894+ time_after(curr->expires, get_seconds())) {
63895+ rcu_read_lock();
63896+ cred = __task_cred(task);
63897+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
63898+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63899+ spin_lock(&gr_uid_lock);
63900+ gr_insert_uid(cred->uid, curr->expires);
63901+ spin_unlock(&gr_uid_lock);
63902+ curr->expires = 0;
63903+ curr->crashes = 0;
63904+ read_lock(&tasklist_lock);
63905+ do_each_thread(tsk2, tsk) {
63906+ cred2 = __task_cred(tsk);
63907+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
63908+ gr_fake_force_sig(SIGKILL, tsk);
63909+ } while_each_thread(tsk2, tsk);
63910+ read_unlock(&tasklist_lock);
63911+ } else {
63912+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63913+ read_lock(&tasklist_lock);
63914+ read_lock(&grsec_exec_file_lock);
63915+ do_each_thread(tsk2, tsk) {
63916+ if (likely(tsk != task)) {
63917+ // if this thread has the same subject as the one that triggered
63918+ // RES_CRASH and it's the same binary, kill it
63919+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
63920+ gr_fake_force_sig(SIGKILL, tsk);
63921+ }
63922+ } while_each_thread(tsk2, tsk);
63923+ read_unlock(&grsec_exec_file_lock);
63924+ read_unlock(&tasklist_lock);
63925+ }
63926+ rcu_read_unlock();
63927+ }
63928+
63929+ return;
63930+}
63931+
63932+int
63933+gr_check_crash_exec(const struct file *filp)
63934+{
63935+ struct acl_subject_label *curr;
63936+
63937+ if (unlikely(!gr_acl_is_enabled()))
63938+ return 0;
63939+
63940+ read_lock(&gr_inode_lock);
63941+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
63942+ __get_dev(filp->f_path.dentry),
63943+ current->role);
63944+ read_unlock(&gr_inode_lock);
63945+
63946+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
63947+ (!curr->crashes && !curr->expires))
63948+ return 0;
63949+
63950+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63951+ time_after(curr->expires, get_seconds()))
63952+ return 1;
63953+ else if (time_before_eq(curr->expires, get_seconds())) {
63954+ curr->crashes = 0;
63955+ curr->expires = 0;
63956+ }
63957+
63958+ return 0;
63959+}
63960+
63961+void
63962+gr_handle_alertkill(struct task_struct *task)
63963+{
63964+ struct acl_subject_label *curracl;
63965+ __u32 curr_ip;
63966+ struct task_struct *p, *p2;
63967+
63968+ if (unlikely(!gr_acl_is_enabled()))
63969+ return;
63970+
63971+ curracl = task->acl;
63972+ curr_ip = task->signal->curr_ip;
63973+
63974+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
63975+ read_lock(&tasklist_lock);
63976+ do_each_thread(p2, p) {
63977+ if (p->signal->curr_ip == curr_ip)
63978+ gr_fake_force_sig(SIGKILL, p);
63979+ } while_each_thread(p2, p);
63980+ read_unlock(&tasklist_lock);
63981+ } else if (curracl->mode & GR_KILLPROC)
63982+ gr_fake_force_sig(SIGKILL, task);
63983+
63984+ return;
63985+}
63986diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
63987new file mode 100644
63988index 0000000..98011b0
63989--- /dev/null
63990+++ b/grsecurity/gracl_shm.c
63991@@ -0,0 +1,40 @@
63992+#include <linux/kernel.h>
63993+#include <linux/mm.h>
63994+#include <linux/sched.h>
63995+#include <linux/file.h>
63996+#include <linux/ipc.h>
63997+#include <linux/gracl.h>
63998+#include <linux/grsecurity.h>
63999+#include <linux/grinternal.h>
64000+
64001+int
64002+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64003+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64004+{
64005+ struct task_struct *task;
64006+
64007+ if (!gr_acl_is_enabled())
64008+ return 1;
64009+
64010+ rcu_read_lock();
64011+ read_lock(&tasklist_lock);
64012+
64013+ task = find_task_by_vpid(shm_cprid);
64014+
64015+ if (unlikely(!task))
64016+ task = find_task_by_vpid(shm_lapid);
64017+
64018+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
64019+ (task_pid_nr(task) == shm_lapid)) &&
64020+ (task->acl->mode & GR_PROTSHM) &&
64021+ (task->acl != current->acl))) {
64022+ read_unlock(&tasklist_lock);
64023+ rcu_read_unlock();
64024+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
64025+ return 0;
64026+ }
64027+ read_unlock(&tasklist_lock);
64028+ rcu_read_unlock();
64029+
64030+ return 1;
64031+}
64032diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
64033new file mode 100644
64034index 0000000..bc0be01
64035--- /dev/null
64036+++ b/grsecurity/grsec_chdir.c
64037@@ -0,0 +1,19 @@
64038+#include <linux/kernel.h>
64039+#include <linux/sched.h>
64040+#include <linux/fs.h>
64041+#include <linux/file.h>
64042+#include <linux/grsecurity.h>
64043+#include <linux/grinternal.h>
64044+
64045+void
64046+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
64047+{
64048+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64049+ if ((grsec_enable_chdir && grsec_enable_group &&
64050+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
64051+ !grsec_enable_group)) {
64052+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
64053+ }
64054+#endif
64055+ return;
64056+}
64057diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
64058new file mode 100644
64059index 0000000..bd6e105
64060--- /dev/null
64061+++ b/grsecurity/grsec_chroot.c
64062@@ -0,0 +1,370 @@
64063+#include <linux/kernel.h>
64064+#include <linux/module.h>
64065+#include <linux/sched.h>
64066+#include <linux/file.h>
64067+#include <linux/fs.h>
64068+#include <linux/mount.h>
64069+#include <linux/types.h>
64070+#include "../fs/mount.h"
64071+#include <linux/grsecurity.h>
64072+#include <linux/grinternal.h>
64073+
64074+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64075+static int gr_init_ran;
64076+#endif
64077+
64078+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
64079+{
64080+#ifdef CONFIG_GRKERNSEC
64081+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
64082+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
64083+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64084+ && gr_init_ran
64085+#endif
64086+ )
64087+ task->gr_is_chrooted = 1;
64088+ else {
64089+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64090+ if (task_pid_nr(task) == 1 && !gr_init_ran)
64091+ gr_init_ran = 1;
64092+#endif
64093+ task->gr_is_chrooted = 0;
64094+ }
64095+
64096+ task->gr_chroot_dentry = path->dentry;
64097+#endif
64098+ return;
64099+}
64100+
64101+void gr_clear_chroot_entries(struct task_struct *task)
64102+{
64103+#ifdef CONFIG_GRKERNSEC
64104+ task->gr_is_chrooted = 0;
64105+ task->gr_chroot_dentry = NULL;
64106+#endif
64107+ return;
64108+}
64109+
64110+int
64111+gr_handle_chroot_unix(const pid_t pid)
64112+{
64113+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64114+ struct task_struct *p;
64115+
64116+ if (unlikely(!grsec_enable_chroot_unix))
64117+ return 1;
64118+
64119+ if (likely(!proc_is_chrooted(current)))
64120+ return 1;
64121+
64122+ rcu_read_lock();
64123+ read_lock(&tasklist_lock);
64124+ p = find_task_by_vpid_unrestricted(pid);
64125+ if (unlikely(p && !have_same_root(current, p))) {
64126+ read_unlock(&tasklist_lock);
64127+ rcu_read_unlock();
64128+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
64129+ return 0;
64130+ }
64131+ read_unlock(&tasklist_lock);
64132+ rcu_read_unlock();
64133+#endif
64134+ return 1;
64135+}
64136+
64137+int
64138+gr_handle_chroot_nice(void)
64139+{
64140+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64141+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
64142+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
64143+ return -EPERM;
64144+ }
64145+#endif
64146+ return 0;
64147+}
64148+
64149+int
64150+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
64151+{
64152+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64153+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
64154+ && proc_is_chrooted(current)) {
64155+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
64156+ return -EACCES;
64157+ }
64158+#endif
64159+ return 0;
64160+}
64161+
64162+int
64163+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
64164+{
64165+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64166+ struct task_struct *p;
64167+ int ret = 0;
64168+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
64169+ return ret;
64170+
64171+ read_lock(&tasklist_lock);
64172+ do_each_pid_task(pid, type, p) {
64173+ if (!have_same_root(current, p)) {
64174+ ret = 1;
64175+ goto out;
64176+ }
64177+ } while_each_pid_task(pid, type, p);
64178+out:
64179+ read_unlock(&tasklist_lock);
64180+ return ret;
64181+#endif
64182+ return 0;
64183+}
64184+
64185+int
64186+gr_pid_is_chrooted(struct task_struct *p)
64187+{
64188+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64189+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
64190+ return 0;
64191+
64192+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
64193+ !have_same_root(current, p)) {
64194+ return 1;
64195+ }
64196+#endif
64197+ return 0;
64198+}
64199+
64200+EXPORT_SYMBOL(gr_pid_is_chrooted);
64201+
64202+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
64203+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
64204+{
64205+ struct path path, currentroot;
64206+ int ret = 0;
64207+
64208+ path.dentry = (struct dentry *)u_dentry;
64209+ path.mnt = (struct vfsmount *)u_mnt;
64210+ get_fs_root(current->fs, &currentroot);
64211+ if (path_is_under(&path, &currentroot))
64212+ ret = 1;
64213+ path_put(&currentroot);
64214+
64215+ return ret;
64216+}
64217+#endif
64218+
64219+int
64220+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
64221+{
64222+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64223+ if (!grsec_enable_chroot_fchdir)
64224+ return 1;
64225+
64226+ if (!proc_is_chrooted(current))
64227+ return 1;
64228+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
64229+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
64230+ return 0;
64231+ }
64232+#endif
64233+ return 1;
64234+}
64235+
64236+int
64237+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64238+ const time_t shm_createtime)
64239+{
64240+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64241+ struct task_struct *p;
64242+ time_t starttime;
64243+
64244+ if (unlikely(!grsec_enable_chroot_shmat))
64245+ return 1;
64246+
64247+ if (likely(!proc_is_chrooted(current)))
64248+ return 1;
64249+
64250+ rcu_read_lock();
64251+ read_lock(&tasklist_lock);
64252+
64253+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
64254+ starttime = p->start_time.tv_sec;
64255+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
64256+ if (have_same_root(current, p)) {
64257+ goto allow;
64258+ } else {
64259+ read_unlock(&tasklist_lock);
64260+ rcu_read_unlock();
64261+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64262+ return 0;
64263+ }
64264+ }
64265+ /* creator exited, pid reuse, fall through to next check */
64266+ }
64267+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
64268+ if (unlikely(!have_same_root(current, p))) {
64269+ read_unlock(&tasklist_lock);
64270+ rcu_read_unlock();
64271+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64272+ return 0;
64273+ }
64274+ }
64275+
64276+allow:
64277+ read_unlock(&tasklist_lock);
64278+ rcu_read_unlock();
64279+#endif
64280+ return 1;
64281+}
64282+
64283+void
64284+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
64285+{
64286+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64287+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
64288+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
64289+#endif
64290+ return;
64291+}
64292+
64293+int
64294+gr_handle_chroot_mknod(const struct dentry *dentry,
64295+ const struct vfsmount *mnt, const int mode)
64296+{
64297+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64298+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
64299+ proc_is_chrooted(current)) {
64300+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
64301+ return -EPERM;
64302+ }
64303+#endif
64304+ return 0;
64305+}
64306+
64307+int
64308+gr_handle_chroot_mount(const struct dentry *dentry,
64309+ const struct vfsmount *mnt, const char *dev_name)
64310+{
64311+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64312+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
64313+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
64314+ return -EPERM;
64315+ }
64316+#endif
64317+ return 0;
64318+}
64319+
64320+int
64321+gr_handle_chroot_pivot(void)
64322+{
64323+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64324+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
64325+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
64326+ return -EPERM;
64327+ }
64328+#endif
64329+ return 0;
64330+}
64331+
64332+int
64333+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
64334+{
64335+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64336+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
64337+ !gr_is_outside_chroot(dentry, mnt)) {
64338+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
64339+ return -EPERM;
64340+ }
64341+#endif
64342+ return 0;
64343+}
64344+
64345+extern const char *captab_log[];
64346+extern int captab_log_entries;
64347+
64348+int
64349+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64350+{
64351+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64352+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64353+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64354+ if (cap_raised(chroot_caps, cap)) {
64355+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
64356+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
64357+ }
64358+ return 0;
64359+ }
64360+ }
64361+#endif
64362+ return 1;
64363+}
64364+
64365+int
64366+gr_chroot_is_capable(const int cap)
64367+{
64368+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64369+ return gr_task_chroot_is_capable(current, current_cred(), cap);
64370+#endif
64371+ return 1;
64372+}
64373+
64374+int
64375+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
64376+{
64377+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64378+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64379+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64380+ if (cap_raised(chroot_caps, cap)) {
64381+ return 0;
64382+ }
64383+ }
64384+#endif
64385+ return 1;
64386+}
64387+
64388+int
64389+gr_chroot_is_capable_nolog(const int cap)
64390+{
64391+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64392+ return gr_task_chroot_is_capable_nolog(current, cap);
64393+#endif
64394+ return 1;
64395+}
64396+
64397+int
64398+gr_handle_chroot_sysctl(const int op)
64399+{
64400+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64401+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
64402+ proc_is_chrooted(current))
64403+ return -EACCES;
64404+#endif
64405+ return 0;
64406+}
64407+
64408+void
64409+gr_handle_chroot_chdir(const struct path *path)
64410+{
64411+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64412+ if (grsec_enable_chroot_chdir)
64413+ set_fs_pwd(current->fs, path);
64414+#endif
64415+ return;
64416+}
64417+
64418+int
64419+gr_handle_chroot_chmod(const struct dentry *dentry,
64420+ const struct vfsmount *mnt, const int mode)
64421+{
64422+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64423+ /* allow chmod +s on directories, but not files */
64424+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
64425+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
64426+ proc_is_chrooted(current)) {
64427+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
64428+ return -EPERM;
64429+ }
64430+#endif
64431+ return 0;
64432+}
64433diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
64434new file mode 100644
64435index 0000000..ce65ceb
64436--- /dev/null
64437+++ b/grsecurity/grsec_disabled.c
64438@@ -0,0 +1,434 @@
64439+#include <linux/kernel.h>
64440+#include <linux/module.h>
64441+#include <linux/sched.h>
64442+#include <linux/file.h>
64443+#include <linux/fs.h>
64444+#include <linux/kdev_t.h>
64445+#include <linux/net.h>
64446+#include <linux/in.h>
64447+#include <linux/ip.h>
64448+#include <linux/skbuff.h>
64449+#include <linux/sysctl.h>
64450+
64451+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64452+void
64453+pax_set_initial_flags(struct linux_binprm *bprm)
64454+{
64455+ return;
64456+}
64457+#endif
64458+
64459+#ifdef CONFIG_SYSCTL
64460+__u32
64461+gr_handle_sysctl(const struct ctl_table * table, const int op)
64462+{
64463+ return 0;
64464+}
64465+#endif
64466+
64467+#ifdef CONFIG_TASKSTATS
64468+int gr_is_taskstats_denied(int pid)
64469+{
64470+ return 0;
64471+}
64472+#endif
64473+
64474+int
64475+gr_acl_is_enabled(void)
64476+{
64477+ return 0;
64478+}
64479+
64480+void
64481+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64482+{
64483+ return;
64484+}
64485+
64486+int
64487+gr_handle_rawio(const struct inode *inode)
64488+{
64489+ return 0;
64490+}
64491+
64492+void
64493+gr_acl_handle_psacct(struct task_struct *task, const long code)
64494+{
64495+ return;
64496+}
64497+
64498+int
64499+gr_handle_ptrace(struct task_struct *task, const long request)
64500+{
64501+ return 0;
64502+}
64503+
64504+int
64505+gr_handle_proc_ptrace(struct task_struct *task)
64506+{
64507+ return 0;
64508+}
64509+
64510+int
64511+gr_set_acls(const int type)
64512+{
64513+ return 0;
64514+}
64515+
64516+int
64517+gr_check_hidden_task(const struct task_struct *tsk)
64518+{
64519+ return 0;
64520+}
64521+
64522+int
64523+gr_check_protected_task(const struct task_struct *task)
64524+{
64525+ return 0;
64526+}
64527+
64528+int
64529+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64530+{
64531+ return 0;
64532+}
64533+
64534+void
64535+gr_copy_label(struct task_struct *tsk)
64536+{
64537+ return;
64538+}
64539+
64540+void
64541+gr_set_pax_flags(struct task_struct *task)
64542+{
64543+ return;
64544+}
64545+
64546+int
64547+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64548+ const int unsafe_share)
64549+{
64550+ return 0;
64551+}
64552+
64553+void
64554+gr_handle_delete(const ino_t ino, const dev_t dev)
64555+{
64556+ return;
64557+}
64558+
64559+void
64560+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64561+{
64562+ return;
64563+}
64564+
64565+void
64566+gr_handle_crash(struct task_struct *task, const int sig)
64567+{
64568+ return;
64569+}
64570+
64571+int
64572+gr_check_crash_exec(const struct file *filp)
64573+{
64574+ return 0;
64575+}
64576+
64577+int
64578+gr_check_crash_uid(const kuid_t uid)
64579+{
64580+ return 0;
64581+}
64582+
64583+void
64584+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64585+ struct dentry *old_dentry,
64586+ struct dentry *new_dentry,
64587+ struct vfsmount *mnt, const __u8 replace)
64588+{
64589+ return;
64590+}
64591+
64592+int
64593+gr_search_socket(const int family, const int type, const int protocol)
64594+{
64595+ return 1;
64596+}
64597+
64598+int
64599+gr_search_connectbind(const int mode, const struct socket *sock,
64600+ const struct sockaddr_in *addr)
64601+{
64602+ return 0;
64603+}
64604+
64605+void
64606+gr_handle_alertkill(struct task_struct *task)
64607+{
64608+ return;
64609+}
64610+
64611+__u32
64612+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
64613+{
64614+ return 1;
64615+}
64616+
64617+__u32
64618+gr_acl_handle_hidden_file(const struct dentry * dentry,
64619+ const struct vfsmount * mnt)
64620+{
64621+ return 1;
64622+}
64623+
64624+__u32
64625+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
64626+ int acc_mode)
64627+{
64628+ return 1;
64629+}
64630+
64631+__u32
64632+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
64633+{
64634+ return 1;
64635+}
64636+
64637+__u32
64638+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
64639+{
64640+ return 1;
64641+}
64642+
64643+int
64644+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
64645+ unsigned int *vm_flags)
64646+{
64647+ return 1;
64648+}
64649+
64650+__u32
64651+gr_acl_handle_truncate(const struct dentry * dentry,
64652+ const struct vfsmount * mnt)
64653+{
64654+ return 1;
64655+}
64656+
64657+__u32
64658+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
64659+{
64660+ return 1;
64661+}
64662+
64663+__u32
64664+gr_acl_handle_access(const struct dentry * dentry,
64665+ const struct vfsmount * mnt, const int fmode)
64666+{
64667+ return 1;
64668+}
64669+
64670+__u32
64671+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
64672+ umode_t *mode)
64673+{
64674+ return 1;
64675+}
64676+
64677+__u32
64678+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
64679+{
64680+ return 1;
64681+}
64682+
64683+__u32
64684+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
64685+{
64686+ return 1;
64687+}
64688+
64689+void
64690+grsecurity_init(void)
64691+{
64692+ return;
64693+}
64694+
64695+umode_t gr_acl_umask(void)
64696+{
64697+ return 0;
64698+}
64699+
64700+__u32
64701+gr_acl_handle_mknod(const struct dentry * new_dentry,
64702+ const struct dentry * parent_dentry,
64703+ const struct vfsmount * parent_mnt,
64704+ const int mode)
64705+{
64706+ return 1;
64707+}
64708+
64709+__u32
64710+gr_acl_handle_mkdir(const struct dentry * new_dentry,
64711+ const struct dentry * parent_dentry,
64712+ const struct vfsmount * parent_mnt)
64713+{
64714+ return 1;
64715+}
64716+
64717+__u32
64718+gr_acl_handle_symlink(const struct dentry * new_dentry,
64719+ const struct dentry * parent_dentry,
64720+ const struct vfsmount * parent_mnt, const struct filename *from)
64721+{
64722+ return 1;
64723+}
64724+
64725+__u32
64726+gr_acl_handle_link(const struct dentry * new_dentry,
64727+ const struct dentry * parent_dentry,
64728+ const struct vfsmount * parent_mnt,
64729+ const struct dentry * old_dentry,
64730+ const struct vfsmount * old_mnt, const struct filename *to)
64731+{
64732+ return 1;
64733+}
64734+
64735+int
64736+gr_acl_handle_rename(const struct dentry *new_dentry,
64737+ const struct dentry *parent_dentry,
64738+ const struct vfsmount *parent_mnt,
64739+ const struct dentry *old_dentry,
64740+ const struct inode *old_parent_inode,
64741+ const struct vfsmount *old_mnt, const struct filename *newname)
64742+{
64743+ return 0;
64744+}
64745+
64746+int
64747+gr_acl_handle_filldir(const struct file *file, const char *name,
64748+ const int namelen, const ino_t ino)
64749+{
64750+ return 1;
64751+}
64752+
64753+int
64754+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64755+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64756+{
64757+ return 1;
64758+}
64759+
64760+int
64761+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
64762+{
64763+ return 0;
64764+}
64765+
64766+int
64767+gr_search_accept(const struct socket *sock)
64768+{
64769+ return 0;
64770+}
64771+
64772+int
64773+gr_search_listen(const struct socket *sock)
64774+{
64775+ return 0;
64776+}
64777+
64778+int
64779+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
64780+{
64781+ return 0;
64782+}
64783+
64784+__u32
64785+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
64786+{
64787+ return 1;
64788+}
64789+
64790+__u32
64791+gr_acl_handle_creat(const struct dentry * dentry,
64792+ const struct dentry * p_dentry,
64793+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
64794+ const int imode)
64795+{
64796+ return 1;
64797+}
64798+
64799+void
64800+gr_acl_handle_exit(void)
64801+{
64802+ return;
64803+}
64804+
64805+int
64806+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
64807+{
64808+ return 1;
64809+}
64810+
64811+void
64812+gr_set_role_label(const kuid_t uid, const kgid_t gid)
64813+{
64814+ return;
64815+}
64816+
64817+int
64818+gr_acl_handle_procpidmem(const struct task_struct *task)
64819+{
64820+ return 0;
64821+}
64822+
64823+int
64824+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
64825+{
64826+ return 0;
64827+}
64828+
64829+int
64830+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
64831+{
64832+ return 0;
64833+}
64834+
64835+void
64836+gr_set_kernel_label(struct task_struct *task)
64837+{
64838+ return;
64839+}
64840+
64841+int
64842+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64843+{
64844+ return 0;
64845+}
64846+
64847+int
64848+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64849+{
64850+ return 0;
64851+}
64852+
64853+int gr_acl_enable_at_secure(void)
64854+{
64855+ return 0;
64856+}
64857+
64858+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
64859+{
64860+ return dentry->d_sb->s_dev;
64861+}
64862+
64863+void gr_put_exec_file(struct task_struct *task)
64864+{
64865+ return;
64866+}
64867+
64868+EXPORT_SYMBOL(gr_set_kernel_label);
64869+#ifdef CONFIG_SECURITY
64870+EXPORT_SYMBOL(gr_check_user_change);
64871+EXPORT_SYMBOL(gr_check_group_change);
64872+#endif
64873diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
64874new file mode 100644
64875index 0000000..387032b
64876--- /dev/null
64877+++ b/grsecurity/grsec_exec.c
64878@@ -0,0 +1,187 @@
64879+#include <linux/kernel.h>
64880+#include <linux/sched.h>
64881+#include <linux/file.h>
64882+#include <linux/binfmts.h>
64883+#include <linux/fs.h>
64884+#include <linux/types.h>
64885+#include <linux/grdefs.h>
64886+#include <linux/grsecurity.h>
64887+#include <linux/grinternal.h>
64888+#include <linux/capability.h>
64889+#include <linux/module.h>
64890+#include <linux/compat.h>
64891+
64892+#include <asm/uaccess.h>
64893+
64894+#ifdef CONFIG_GRKERNSEC_EXECLOG
64895+static char gr_exec_arg_buf[132];
64896+static DEFINE_MUTEX(gr_exec_arg_mutex);
64897+#endif
64898+
64899+struct user_arg_ptr {
64900+#ifdef CONFIG_COMPAT
64901+ bool is_compat;
64902+#endif
64903+ union {
64904+ const char __user *const __user *native;
64905+#ifdef CONFIG_COMPAT
64906+ const compat_uptr_t __user *compat;
64907+#endif
64908+ } ptr;
64909+};
64910+
64911+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
64912+
64913+void
64914+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
64915+{
64916+#ifdef CONFIG_GRKERNSEC_EXECLOG
64917+ char *grarg = gr_exec_arg_buf;
64918+ unsigned int i, x, execlen = 0;
64919+ char c;
64920+
64921+ if (!((grsec_enable_execlog && grsec_enable_group &&
64922+ in_group_p(grsec_audit_gid))
64923+ || (grsec_enable_execlog && !grsec_enable_group)))
64924+ return;
64925+
64926+ mutex_lock(&gr_exec_arg_mutex);
64927+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
64928+
64929+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
64930+ const char __user *p;
64931+ unsigned int len;
64932+
64933+ p = get_user_arg_ptr(argv, i);
64934+ if (IS_ERR(p))
64935+ goto log;
64936+
64937+ len = strnlen_user(p, 128 - execlen);
64938+ if (len > 128 - execlen)
64939+ len = 128 - execlen;
64940+ else if (len > 0)
64941+ len--;
64942+ if (copy_from_user(grarg + execlen, p, len))
64943+ goto log;
64944+
64945+ /* rewrite unprintable characters */
64946+ for (x = 0; x < len; x++) {
64947+ c = *(grarg + execlen + x);
64948+ if (c < 32 || c > 126)
64949+ *(grarg + execlen + x) = ' ';
64950+ }
64951+
64952+ execlen += len;
64953+ *(grarg + execlen) = ' ';
64954+ *(grarg + execlen + 1) = '\0';
64955+ execlen++;
64956+ }
64957+
64958+ log:
64959+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
64960+ bprm->file->f_path.mnt, grarg);
64961+ mutex_unlock(&gr_exec_arg_mutex);
64962+#endif
64963+ return;
64964+}
64965+
64966+#ifdef CONFIG_GRKERNSEC
64967+extern int gr_acl_is_capable(const int cap);
64968+extern int gr_acl_is_capable_nolog(const int cap);
64969+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64970+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
64971+extern int gr_chroot_is_capable(const int cap);
64972+extern int gr_chroot_is_capable_nolog(const int cap);
64973+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64974+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
64975+#endif
64976+
64977+const char *captab_log[] = {
64978+ "CAP_CHOWN",
64979+ "CAP_DAC_OVERRIDE",
64980+ "CAP_DAC_READ_SEARCH",
64981+ "CAP_FOWNER",
64982+ "CAP_FSETID",
64983+ "CAP_KILL",
64984+ "CAP_SETGID",
64985+ "CAP_SETUID",
64986+ "CAP_SETPCAP",
64987+ "CAP_LINUX_IMMUTABLE",
64988+ "CAP_NET_BIND_SERVICE",
64989+ "CAP_NET_BROADCAST",
64990+ "CAP_NET_ADMIN",
64991+ "CAP_NET_RAW",
64992+ "CAP_IPC_LOCK",
64993+ "CAP_IPC_OWNER",
64994+ "CAP_SYS_MODULE",
64995+ "CAP_SYS_RAWIO",
64996+ "CAP_SYS_CHROOT",
64997+ "CAP_SYS_PTRACE",
64998+ "CAP_SYS_PACCT",
64999+ "CAP_SYS_ADMIN",
65000+ "CAP_SYS_BOOT",
65001+ "CAP_SYS_NICE",
65002+ "CAP_SYS_RESOURCE",
65003+ "CAP_SYS_TIME",
65004+ "CAP_SYS_TTY_CONFIG",
65005+ "CAP_MKNOD",
65006+ "CAP_LEASE",
65007+ "CAP_AUDIT_WRITE",
65008+ "CAP_AUDIT_CONTROL",
65009+ "CAP_SETFCAP",
65010+ "CAP_MAC_OVERRIDE",
65011+ "CAP_MAC_ADMIN",
65012+ "CAP_SYSLOG",
65013+ "CAP_WAKE_ALARM"
65014+};
65015+
65016+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
65017+
65018+int gr_is_capable(const int cap)
65019+{
65020+#ifdef CONFIG_GRKERNSEC
65021+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
65022+ return 1;
65023+ return 0;
65024+#else
65025+ return 1;
65026+#endif
65027+}
65028+
65029+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
65030+{
65031+#ifdef CONFIG_GRKERNSEC
65032+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
65033+ return 1;
65034+ return 0;
65035+#else
65036+ return 1;
65037+#endif
65038+}
65039+
65040+int gr_is_capable_nolog(const int cap)
65041+{
65042+#ifdef CONFIG_GRKERNSEC
65043+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
65044+ return 1;
65045+ return 0;
65046+#else
65047+ return 1;
65048+#endif
65049+}
65050+
65051+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
65052+{
65053+#ifdef CONFIG_GRKERNSEC
65054+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
65055+ return 1;
65056+ return 0;
65057+#else
65058+ return 1;
65059+#endif
65060+}
65061+
65062+EXPORT_SYMBOL(gr_is_capable);
65063+EXPORT_SYMBOL(gr_is_capable_nolog);
65064+EXPORT_SYMBOL(gr_task_is_capable);
65065+EXPORT_SYMBOL(gr_task_is_capable_nolog);
65066diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
65067new file mode 100644
65068index 0000000..06cc6ea
65069--- /dev/null
65070+++ b/grsecurity/grsec_fifo.c
65071@@ -0,0 +1,24 @@
65072+#include <linux/kernel.h>
65073+#include <linux/sched.h>
65074+#include <linux/fs.h>
65075+#include <linux/file.h>
65076+#include <linux/grinternal.h>
65077+
65078+int
65079+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
65080+ const struct dentry *dir, const int flag, const int acc_mode)
65081+{
65082+#ifdef CONFIG_GRKERNSEC_FIFO
65083+ const struct cred *cred = current_cred();
65084+
65085+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
65086+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
65087+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
65088+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
65089+ if (!inode_permission(dentry->d_inode, acc_mode))
65090+ 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));
65091+ return -EACCES;
65092+ }
65093+#endif
65094+ return 0;
65095+}
65096diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
65097new file mode 100644
65098index 0000000..8ca18bf
65099--- /dev/null
65100+++ b/grsecurity/grsec_fork.c
65101@@ -0,0 +1,23 @@
65102+#include <linux/kernel.h>
65103+#include <linux/sched.h>
65104+#include <linux/grsecurity.h>
65105+#include <linux/grinternal.h>
65106+#include <linux/errno.h>
65107+
65108+void
65109+gr_log_forkfail(const int retval)
65110+{
65111+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65112+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
65113+ switch (retval) {
65114+ case -EAGAIN:
65115+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
65116+ break;
65117+ case -ENOMEM:
65118+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
65119+ break;
65120+ }
65121+ }
65122+#endif
65123+ return;
65124+}
65125diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
65126new file mode 100644
65127index 0000000..a862e9f
65128--- /dev/null
65129+++ b/grsecurity/grsec_init.c
65130@@ -0,0 +1,283 @@
65131+#include <linux/kernel.h>
65132+#include <linux/sched.h>
65133+#include <linux/mm.h>
65134+#include <linux/gracl.h>
65135+#include <linux/slab.h>
65136+#include <linux/vmalloc.h>
65137+#include <linux/percpu.h>
65138+#include <linux/module.h>
65139+
65140+int grsec_enable_ptrace_readexec;
65141+int grsec_enable_setxid;
65142+int grsec_enable_symlinkown;
65143+kgid_t grsec_symlinkown_gid;
65144+int grsec_enable_brute;
65145+int grsec_enable_link;
65146+int grsec_enable_dmesg;
65147+int grsec_enable_harden_ptrace;
65148+int grsec_enable_fifo;
65149+int grsec_enable_execlog;
65150+int grsec_enable_signal;
65151+int grsec_enable_forkfail;
65152+int grsec_enable_audit_ptrace;
65153+int grsec_enable_time;
65154+int grsec_enable_audit_textrel;
65155+int grsec_enable_group;
65156+kgid_t grsec_audit_gid;
65157+int grsec_enable_chdir;
65158+int grsec_enable_mount;
65159+int grsec_enable_rofs;
65160+int grsec_enable_chroot_findtask;
65161+int grsec_enable_chroot_mount;
65162+int grsec_enable_chroot_shmat;
65163+int grsec_enable_chroot_fchdir;
65164+int grsec_enable_chroot_double;
65165+int grsec_enable_chroot_pivot;
65166+int grsec_enable_chroot_chdir;
65167+int grsec_enable_chroot_chmod;
65168+int grsec_enable_chroot_mknod;
65169+int grsec_enable_chroot_nice;
65170+int grsec_enable_chroot_execlog;
65171+int grsec_enable_chroot_caps;
65172+int grsec_enable_chroot_sysctl;
65173+int grsec_enable_chroot_unix;
65174+int grsec_enable_tpe;
65175+kgid_t grsec_tpe_gid;
65176+int grsec_enable_blackhole;
65177+#ifdef CONFIG_IPV6_MODULE
65178+EXPORT_SYMBOL(grsec_enable_blackhole);
65179+#endif
65180+int grsec_lastack_retries;
65181+int grsec_enable_tpe_all;
65182+int grsec_enable_tpe_invert;
65183+int grsec_enable_socket_all;
65184+kgid_t grsec_socket_all_gid;
65185+int grsec_enable_socket_client;
65186+kgid_t grsec_socket_client_gid;
65187+int grsec_enable_socket_server;
65188+kgid_t grsec_socket_server_gid;
65189+int grsec_resource_logging;
65190+int grsec_disable_privio;
65191+int grsec_enable_log_rwxmaps;
65192+int grsec_lock;
65193+
65194+DEFINE_SPINLOCK(grsec_alert_lock);
65195+unsigned long grsec_alert_wtime = 0;
65196+unsigned long grsec_alert_fyet = 0;
65197+
65198+DEFINE_SPINLOCK(grsec_audit_lock);
65199+
65200+DEFINE_RWLOCK(grsec_exec_file_lock);
65201+
65202+char *gr_shared_page[4];
65203+
65204+char *gr_alert_log_fmt;
65205+char *gr_audit_log_fmt;
65206+char *gr_alert_log_buf;
65207+char *gr_audit_log_buf;
65208+
65209+extern struct gr_arg *gr_usermode;
65210+extern unsigned char *gr_system_salt;
65211+extern unsigned char *gr_system_sum;
65212+
65213+void __init
65214+grsecurity_init(void)
65215+{
65216+ int j;
65217+ /* create the per-cpu shared pages */
65218+
65219+#ifdef CONFIG_X86
65220+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
65221+#endif
65222+
65223+ for (j = 0; j < 4; j++) {
65224+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
65225+ if (gr_shared_page[j] == NULL) {
65226+ panic("Unable to allocate grsecurity shared page");
65227+ return;
65228+ }
65229+ }
65230+
65231+ /* allocate log buffers */
65232+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
65233+ if (!gr_alert_log_fmt) {
65234+ panic("Unable to allocate grsecurity alert log format buffer");
65235+ return;
65236+ }
65237+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
65238+ if (!gr_audit_log_fmt) {
65239+ panic("Unable to allocate grsecurity audit log format buffer");
65240+ return;
65241+ }
65242+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65243+ if (!gr_alert_log_buf) {
65244+ panic("Unable to allocate grsecurity alert log buffer");
65245+ return;
65246+ }
65247+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65248+ if (!gr_audit_log_buf) {
65249+ panic("Unable to allocate grsecurity audit log buffer");
65250+ return;
65251+ }
65252+
65253+ /* allocate memory for authentication structure */
65254+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
65255+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
65256+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
65257+
65258+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
65259+ panic("Unable to allocate grsecurity authentication structure");
65260+ return;
65261+ }
65262+
65263+
65264+#ifdef CONFIG_GRKERNSEC_IO
65265+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
65266+ grsec_disable_privio = 1;
65267+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65268+ grsec_disable_privio = 1;
65269+#else
65270+ grsec_disable_privio = 0;
65271+#endif
65272+#endif
65273+
65274+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65275+ /* for backward compatibility, tpe_invert always defaults to on if
65276+ enabled in the kernel
65277+ */
65278+ grsec_enable_tpe_invert = 1;
65279+#endif
65280+
65281+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65282+#ifndef CONFIG_GRKERNSEC_SYSCTL
65283+ grsec_lock = 1;
65284+#endif
65285+
65286+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65287+ grsec_enable_audit_textrel = 1;
65288+#endif
65289+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65290+ grsec_enable_log_rwxmaps = 1;
65291+#endif
65292+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65293+ grsec_enable_group = 1;
65294+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
65295+#endif
65296+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65297+ grsec_enable_ptrace_readexec = 1;
65298+#endif
65299+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65300+ grsec_enable_chdir = 1;
65301+#endif
65302+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65303+ grsec_enable_harden_ptrace = 1;
65304+#endif
65305+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65306+ grsec_enable_mount = 1;
65307+#endif
65308+#ifdef CONFIG_GRKERNSEC_LINK
65309+ grsec_enable_link = 1;
65310+#endif
65311+#ifdef CONFIG_GRKERNSEC_BRUTE
65312+ grsec_enable_brute = 1;
65313+#endif
65314+#ifdef CONFIG_GRKERNSEC_DMESG
65315+ grsec_enable_dmesg = 1;
65316+#endif
65317+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65318+ grsec_enable_blackhole = 1;
65319+ grsec_lastack_retries = 4;
65320+#endif
65321+#ifdef CONFIG_GRKERNSEC_FIFO
65322+ grsec_enable_fifo = 1;
65323+#endif
65324+#ifdef CONFIG_GRKERNSEC_EXECLOG
65325+ grsec_enable_execlog = 1;
65326+#endif
65327+#ifdef CONFIG_GRKERNSEC_SETXID
65328+ grsec_enable_setxid = 1;
65329+#endif
65330+#ifdef CONFIG_GRKERNSEC_SIGNAL
65331+ grsec_enable_signal = 1;
65332+#endif
65333+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65334+ grsec_enable_forkfail = 1;
65335+#endif
65336+#ifdef CONFIG_GRKERNSEC_TIME
65337+ grsec_enable_time = 1;
65338+#endif
65339+#ifdef CONFIG_GRKERNSEC_RESLOG
65340+ grsec_resource_logging = 1;
65341+#endif
65342+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65343+ grsec_enable_chroot_findtask = 1;
65344+#endif
65345+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65346+ grsec_enable_chroot_unix = 1;
65347+#endif
65348+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65349+ grsec_enable_chroot_mount = 1;
65350+#endif
65351+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65352+ grsec_enable_chroot_fchdir = 1;
65353+#endif
65354+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65355+ grsec_enable_chroot_shmat = 1;
65356+#endif
65357+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65358+ grsec_enable_audit_ptrace = 1;
65359+#endif
65360+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65361+ grsec_enable_chroot_double = 1;
65362+#endif
65363+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65364+ grsec_enable_chroot_pivot = 1;
65365+#endif
65366+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65367+ grsec_enable_chroot_chdir = 1;
65368+#endif
65369+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65370+ grsec_enable_chroot_chmod = 1;
65371+#endif
65372+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65373+ grsec_enable_chroot_mknod = 1;
65374+#endif
65375+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65376+ grsec_enable_chroot_nice = 1;
65377+#endif
65378+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65379+ grsec_enable_chroot_execlog = 1;
65380+#endif
65381+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65382+ grsec_enable_chroot_caps = 1;
65383+#endif
65384+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65385+ grsec_enable_chroot_sysctl = 1;
65386+#endif
65387+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65388+ grsec_enable_symlinkown = 1;
65389+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
65390+#endif
65391+#ifdef CONFIG_GRKERNSEC_TPE
65392+ grsec_enable_tpe = 1;
65393+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
65394+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65395+ grsec_enable_tpe_all = 1;
65396+#endif
65397+#endif
65398+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65399+ grsec_enable_socket_all = 1;
65400+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
65401+#endif
65402+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65403+ grsec_enable_socket_client = 1;
65404+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
65405+#endif
65406+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65407+ grsec_enable_socket_server = 1;
65408+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
65409+#endif
65410+#endif
65411+
65412+ return;
65413+}
65414diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
65415new file mode 100644
65416index 0000000..5e05e20
65417--- /dev/null
65418+++ b/grsecurity/grsec_link.c
65419@@ -0,0 +1,58 @@
65420+#include <linux/kernel.h>
65421+#include <linux/sched.h>
65422+#include <linux/fs.h>
65423+#include <linux/file.h>
65424+#include <linux/grinternal.h>
65425+
65426+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
65427+{
65428+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65429+ const struct inode *link_inode = link->dentry->d_inode;
65430+
65431+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
65432+ /* ignore root-owned links, e.g. /proc/self */
65433+ gr_is_global_nonroot(link_inode->i_uid) && target &&
65434+ !uid_eq(link_inode->i_uid, target->i_uid)) {
65435+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
65436+ return 1;
65437+ }
65438+#endif
65439+ return 0;
65440+}
65441+
65442+int
65443+gr_handle_follow_link(const struct inode *parent,
65444+ const struct inode *inode,
65445+ const struct dentry *dentry, const struct vfsmount *mnt)
65446+{
65447+#ifdef CONFIG_GRKERNSEC_LINK
65448+ const struct cred *cred = current_cred();
65449+
65450+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
65451+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
65452+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
65453+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
65454+ return -EACCES;
65455+ }
65456+#endif
65457+ return 0;
65458+}
65459+
65460+int
65461+gr_handle_hardlink(const struct dentry *dentry,
65462+ const struct vfsmount *mnt,
65463+ struct inode *inode, const int mode, const struct filename *to)
65464+{
65465+#ifdef CONFIG_GRKERNSEC_LINK
65466+ const struct cred *cred = current_cred();
65467+
65468+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
65469+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
65470+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
65471+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
65472+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
65473+ return -EPERM;
65474+ }
65475+#endif
65476+ return 0;
65477+}
65478diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
65479new file mode 100644
65480index 0000000..7c06085
65481--- /dev/null
65482+++ b/grsecurity/grsec_log.c
65483@@ -0,0 +1,326 @@
65484+#include <linux/kernel.h>
65485+#include <linux/sched.h>
65486+#include <linux/file.h>
65487+#include <linux/tty.h>
65488+#include <linux/fs.h>
65489+#include <linux/grinternal.h>
65490+
65491+#ifdef CONFIG_TREE_PREEMPT_RCU
65492+#define DISABLE_PREEMPT() preempt_disable()
65493+#define ENABLE_PREEMPT() preempt_enable()
65494+#else
65495+#define DISABLE_PREEMPT()
65496+#define ENABLE_PREEMPT()
65497+#endif
65498+
65499+#define BEGIN_LOCKS(x) \
65500+ DISABLE_PREEMPT(); \
65501+ rcu_read_lock(); \
65502+ read_lock(&tasklist_lock); \
65503+ read_lock(&grsec_exec_file_lock); \
65504+ if (x != GR_DO_AUDIT) \
65505+ spin_lock(&grsec_alert_lock); \
65506+ else \
65507+ spin_lock(&grsec_audit_lock)
65508+
65509+#define END_LOCKS(x) \
65510+ if (x != GR_DO_AUDIT) \
65511+ spin_unlock(&grsec_alert_lock); \
65512+ else \
65513+ spin_unlock(&grsec_audit_lock); \
65514+ read_unlock(&grsec_exec_file_lock); \
65515+ read_unlock(&tasklist_lock); \
65516+ rcu_read_unlock(); \
65517+ ENABLE_PREEMPT(); \
65518+ if (x == GR_DONT_AUDIT) \
65519+ gr_handle_alertkill(current)
65520+
65521+enum {
65522+ FLOODING,
65523+ NO_FLOODING
65524+};
65525+
65526+extern char *gr_alert_log_fmt;
65527+extern char *gr_audit_log_fmt;
65528+extern char *gr_alert_log_buf;
65529+extern char *gr_audit_log_buf;
65530+
65531+static int gr_log_start(int audit)
65532+{
65533+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
65534+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
65535+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65536+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
65537+ unsigned long curr_secs = get_seconds();
65538+
65539+ if (audit == GR_DO_AUDIT)
65540+ goto set_fmt;
65541+
65542+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
65543+ grsec_alert_wtime = curr_secs;
65544+ grsec_alert_fyet = 0;
65545+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
65546+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
65547+ grsec_alert_fyet++;
65548+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
65549+ grsec_alert_wtime = curr_secs;
65550+ grsec_alert_fyet++;
65551+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
65552+ return FLOODING;
65553+ }
65554+ else return FLOODING;
65555+
65556+set_fmt:
65557+#endif
65558+ memset(buf, 0, PAGE_SIZE);
65559+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
65560+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
65561+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65562+ } else if (current->signal->curr_ip) {
65563+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
65564+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
65565+ } else if (gr_acl_is_enabled()) {
65566+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
65567+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65568+ } else {
65569+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
65570+ strcpy(buf, fmt);
65571+ }
65572+
65573+ return NO_FLOODING;
65574+}
65575+
65576+static void gr_log_middle(int audit, const char *msg, va_list ap)
65577+ __attribute__ ((format (printf, 2, 0)));
65578+
65579+static void gr_log_middle(int audit, const char *msg, va_list ap)
65580+{
65581+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65582+ unsigned int len = strlen(buf);
65583+
65584+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65585+
65586+ return;
65587+}
65588+
65589+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65590+ __attribute__ ((format (printf, 2, 3)));
65591+
65592+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65593+{
65594+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65595+ unsigned int len = strlen(buf);
65596+ va_list ap;
65597+
65598+ va_start(ap, msg);
65599+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65600+ va_end(ap);
65601+
65602+ return;
65603+}
65604+
65605+static void gr_log_end(int audit, int append_default)
65606+{
65607+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65608+ if (append_default) {
65609+ struct task_struct *task = current;
65610+ struct task_struct *parent = task->real_parent;
65611+ const struct cred *cred = __task_cred(task);
65612+ const struct cred *pcred = __task_cred(parent);
65613+ unsigned int len = strlen(buf);
65614+
65615+ 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));
65616+ }
65617+
65618+ printk("%s\n", buf);
65619+
65620+ return;
65621+}
65622+
65623+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
65624+{
65625+ int logtype;
65626+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
65627+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
65628+ void *voidptr = NULL;
65629+ int num1 = 0, num2 = 0;
65630+ unsigned long ulong1 = 0, ulong2 = 0;
65631+ struct dentry *dentry = NULL;
65632+ struct vfsmount *mnt = NULL;
65633+ struct file *file = NULL;
65634+ struct task_struct *task = NULL;
65635+ const struct cred *cred, *pcred;
65636+ va_list ap;
65637+
65638+ BEGIN_LOCKS(audit);
65639+ logtype = gr_log_start(audit);
65640+ if (logtype == FLOODING) {
65641+ END_LOCKS(audit);
65642+ return;
65643+ }
65644+ va_start(ap, argtypes);
65645+ switch (argtypes) {
65646+ case GR_TTYSNIFF:
65647+ task = va_arg(ap, struct task_struct *);
65648+ 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));
65649+ break;
65650+ case GR_SYSCTL_HIDDEN:
65651+ str1 = va_arg(ap, char *);
65652+ gr_log_middle_varargs(audit, msg, result, str1);
65653+ break;
65654+ case GR_RBAC:
65655+ dentry = va_arg(ap, struct dentry *);
65656+ mnt = va_arg(ap, struct vfsmount *);
65657+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
65658+ break;
65659+ case GR_RBAC_STR:
65660+ dentry = va_arg(ap, struct dentry *);
65661+ mnt = va_arg(ap, struct vfsmount *);
65662+ str1 = va_arg(ap, char *);
65663+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
65664+ break;
65665+ case GR_STR_RBAC:
65666+ str1 = va_arg(ap, char *);
65667+ dentry = va_arg(ap, struct dentry *);
65668+ mnt = va_arg(ap, struct vfsmount *);
65669+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
65670+ break;
65671+ case GR_RBAC_MODE2:
65672+ dentry = va_arg(ap, struct dentry *);
65673+ mnt = va_arg(ap, struct vfsmount *);
65674+ str1 = va_arg(ap, char *);
65675+ str2 = va_arg(ap, char *);
65676+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
65677+ break;
65678+ case GR_RBAC_MODE3:
65679+ dentry = va_arg(ap, struct dentry *);
65680+ mnt = va_arg(ap, struct vfsmount *);
65681+ str1 = va_arg(ap, char *);
65682+ str2 = va_arg(ap, char *);
65683+ str3 = va_arg(ap, char *);
65684+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
65685+ break;
65686+ case GR_FILENAME:
65687+ dentry = va_arg(ap, struct dentry *);
65688+ mnt = va_arg(ap, struct vfsmount *);
65689+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
65690+ break;
65691+ case GR_STR_FILENAME:
65692+ str1 = va_arg(ap, char *);
65693+ dentry = va_arg(ap, struct dentry *);
65694+ mnt = va_arg(ap, struct vfsmount *);
65695+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
65696+ break;
65697+ case GR_FILENAME_STR:
65698+ dentry = va_arg(ap, struct dentry *);
65699+ mnt = va_arg(ap, struct vfsmount *);
65700+ str1 = va_arg(ap, char *);
65701+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
65702+ break;
65703+ case GR_FILENAME_TWO_INT:
65704+ dentry = va_arg(ap, struct dentry *);
65705+ mnt = va_arg(ap, struct vfsmount *);
65706+ num1 = va_arg(ap, int);
65707+ num2 = va_arg(ap, int);
65708+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
65709+ break;
65710+ case GR_FILENAME_TWO_INT_STR:
65711+ dentry = va_arg(ap, struct dentry *);
65712+ mnt = va_arg(ap, struct vfsmount *);
65713+ num1 = va_arg(ap, int);
65714+ num2 = va_arg(ap, int);
65715+ str1 = va_arg(ap, char *);
65716+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
65717+ break;
65718+ case GR_TEXTREL:
65719+ file = va_arg(ap, struct file *);
65720+ ulong1 = va_arg(ap, unsigned long);
65721+ ulong2 = va_arg(ap, unsigned long);
65722+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
65723+ break;
65724+ case GR_PTRACE:
65725+ task = va_arg(ap, struct task_struct *);
65726+ 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));
65727+ break;
65728+ case GR_RESOURCE:
65729+ task = va_arg(ap, struct task_struct *);
65730+ cred = __task_cred(task);
65731+ pcred = __task_cred(task->real_parent);
65732+ ulong1 = va_arg(ap, unsigned long);
65733+ str1 = va_arg(ap, char *);
65734+ ulong2 = va_arg(ap, unsigned long);
65735+ 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));
65736+ break;
65737+ case GR_CAP:
65738+ task = va_arg(ap, struct task_struct *);
65739+ cred = __task_cred(task);
65740+ pcred = __task_cred(task->real_parent);
65741+ str1 = va_arg(ap, char *);
65742+ 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));
65743+ break;
65744+ case GR_SIG:
65745+ str1 = va_arg(ap, char *);
65746+ voidptr = va_arg(ap, void *);
65747+ gr_log_middle_varargs(audit, msg, str1, voidptr);
65748+ break;
65749+ case GR_SIG2:
65750+ task = va_arg(ap, struct task_struct *);
65751+ cred = __task_cred(task);
65752+ pcred = __task_cred(task->real_parent);
65753+ num1 = va_arg(ap, int);
65754+ 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));
65755+ break;
65756+ case GR_CRASH1:
65757+ task = va_arg(ap, struct task_struct *);
65758+ cred = __task_cred(task);
65759+ pcred = __task_cred(task->real_parent);
65760+ ulong1 = va_arg(ap, unsigned long);
65761+ 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);
65762+ break;
65763+ case GR_CRASH2:
65764+ task = va_arg(ap, struct task_struct *);
65765+ cred = __task_cred(task);
65766+ pcred = __task_cred(task->real_parent);
65767+ ulong1 = va_arg(ap, unsigned long);
65768+ 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);
65769+ break;
65770+ case GR_RWXMAP:
65771+ file = va_arg(ap, struct file *);
65772+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
65773+ break;
65774+ case GR_PSACCT:
65775+ {
65776+ unsigned int wday, cday;
65777+ __u8 whr, chr;
65778+ __u8 wmin, cmin;
65779+ __u8 wsec, csec;
65780+ char cur_tty[64] = { 0 };
65781+ char parent_tty[64] = { 0 };
65782+
65783+ task = va_arg(ap, struct task_struct *);
65784+ wday = va_arg(ap, unsigned int);
65785+ cday = va_arg(ap, unsigned int);
65786+ whr = va_arg(ap, int);
65787+ chr = va_arg(ap, int);
65788+ wmin = va_arg(ap, int);
65789+ cmin = va_arg(ap, int);
65790+ wsec = va_arg(ap, int);
65791+ csec = va_arg(ap, int);
65792+ ulong1 = va_arg(ap, unsigned long);
65793+ cred = __task_cred(task);
65794+ pcred = __task_cred(task->real_parent);
65795+
65796+ 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));
65797+ }
65798+ break;
65799+ default:
65800+ gr_log_middle(audit, msg, ap);
65801+ }
65802+ va_end(ap);
65803+ // these don't need DEFAULTSECARGS printed on the end
65804+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
65805+ gr_log_end(audit, 0);
65806+ else
65807+ gr_log_end(audit, 1);
65808+ END_LOCKS(audit);
65809+}
65810diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
65811new file mode 100644
65812index 0000000..f536303
65813--- /dev/null
65814+++ b/grsecurity/grsec_mem.c
65815@@ -0,0 +1,40 @@
65816+#include <linux/kernel.h>
65817+#include <linux/sched.h>
65818+#include <linux/mm.h>
65819+#include <linux/mman.h>
65820+#include <linux/grinternal.h>
65821+
65822+void
65823+gr_handle_ioperm(void)
65824+{
65825+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
65826+ return;
65827+}
65828+
65829+void
65830+gr_handle_iopl(void)
65831+{
65832+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
65833+ return;
65834+}
65835+
65836+void
65837+gr_handle_mem_readwrite(u64 from, u64 to)
65838+{
65839+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
65840+ return;
65841+}
65842+
65843+void
65844+gr_handle_vm86(void)
65845+{
65846+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
65847+ return;
65848+}
65849+
65850+void
65851+gr_log_badprocpid(const char *entry)
65852+{
65853+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
65854+ return;
65855+}
65856diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
65857new file mode 100644
65858index 0000000..2131422
65859--- /dev/null
65860+++ b/grsecurity/grsec_mount.c
65861@@ -0,0 +1,62 @@
65862+#include <linux/kernel.h>
65863+#include <linux/sched.h>
65864+#include <linux/mount.h>
65865+#include <linux/grsecurity.h>
65866+#include <linux/grinternal.h>
65867+
65868+void
65869+gr_log_remount(const char *devname, const int retval)
65870+{
65871+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65872+ if (grsec_enable_mount && (retval >= 0))
65873+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
65874+#endif
65875+ return;
65876+}
65877+
65878+void
65879+gr_log_unmount(const char *devname, const int retval)
65880+{
65881+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65882+ if (grsec_enable_mount && (retval >= 0))
65883+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
65884+#endif
65885+ return;
65886+}
65887+
65888+void
65889+gr_log_mount(const char *from, const char *to, const int retval)
65890+{
65891+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65892+ if (grsec_enable_mount && (retval >= 0))
65893+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
65894+#endif
65895+ return;
65896+}
65897+
65898+int
65899+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
65900+{
65901+#ifdef CONFIG_GRKERNSEC_ROFS
65902+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
65903+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
65904+ return -EPERM;
65905+ } else
65906+ return 0;
65907+#endif
65908+ return 0;
65909+}
65910+
65911+int
65912+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
65913+{
65914+#ifdef CONFIG_GRKERNSEC_ROFS
65915+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
65916+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
65917+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
65918+ return -EPERM;
65919+ } else
65920+ return 0;
65921+#endif
65922+ return 0;
65923+}
65924diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
65925new file mode 100644
65926index 0000000..a3b12a0
65927--- /dev/null
65928+++ b/grsecurity/grsec_pax.c
65929@@ -0,0 +1,36 @@
65930+#include <linux/kernel.h>
65931+#include <linux/sched.h>
65932+#include <linux/mm.h>
65933+#include <linux/file.h>
65934+#include <linux/grinternal.h>
65935+#include <linux/grsecurity.h>
65936+
65937+void
65938+gr_log_textrel(struct vm_area_struct * vma)
65939+{
65940+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65941+ if (grsec_enable_audit_textrel)
65942+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
65943+#endif
65944+ return;
65945+}
65946+
65947+void
65948+gr_log_rwxmmap(struct file *file)
65949+{
65950+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65951+ if (grsec_enable_log_rwxmaps)
65952+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
65953+#endif
65954+ return;
65955+}
65956+
65957+void
65958+gr_log_rwxmprotect(struct file *file)
65959+{
65960+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65961+ if (grsec_enable_log_rwxmaps)
65962+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
65963+#endif
65964+ return;
65965+}
65966diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
65967new file mode 100644
65968index 0000000..f7f29aa
65969--- /dev/null
65970+++ b/grsecurity/grsec_ptrace.c
65971@@ -0,0 +1,30 @@
65972+#include <linux/kernel.h>
65973+#include <linux/sched.h>
65974+#include <linux/grinternal.h>
65975+#include <linux/security.h>
65976+
65977+void
65978+gr_audit_ptrace(struct task_struct *task)
65979+{
65980+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65981+ if (grsec_enable_audit_ptrace)
65982+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
65983+#endif
65984+ return;
65985+}
65986+
65987+int
65988+gr_ptrace_readexec(struct file *file, int unsafe_flags)
65989+{
65990+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65991+ const struct dentry *dentry = file->f_path.dentry;
65992+ const struct vfsmount *mnt = file->f_path.mnt;
65993+
65994+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
65995+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
65996+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
65997+ return -EACCES;
65998+ }
65999+#endif
66000+ return 0;
66001+}
66002diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
66003new file mode 100644
66004index 0000000..4e29cc7
66005--- /dev/null
66006+++ b/grsecurity/grsec_sig.c
66007@@ -0,0 +1,246 @@
66008+#include <linux/kernel.h>
66009+#include <linux/sched.h>
66010+#include <linux/fs.h>
66011+#include <linux/delay.h>
66012+#include <linux/grsecurity.h>
66013+#include <linux/grinternal.h>
66014+#include <linux/hardirq.h>
66015+
66016+char *signames[] = {
66017+ [SIGSEGV] = "Segmentation fault",
66018+ [SIGILL] = "Illegal instruction",
66019+ [SIGABRT] = "Abort",
66020+ [SIGBUS] = "Invalid alignment/Bus error"
66021+};
66022+
66023+void
66024+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
66025+{
66026+#ifdef CONFIG_GRKERNSEC_SIGNAL
66027+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
66028+ (sig == SIGABRT) || (sig == SIGBUS))) {
66029+ if (task_pid_nr(t) == task_pid_nr(current)) {
66030+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
66031+ } else {
66032+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
66033+ }
66034+ }
66035+#endif
66036+ return;
66037+}
66038+
66039+int
66040+gr_handle_signal(const struct task_struct *p, const int sig)
66041+{
66042+#ifdef CONFIG_GRKERNSEC
66043+ /* ignore the 0 signal for protected task checks */
66044+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
66045+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
66046+ return -EPERM;
66047+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
66048+ return -EPERM;
66049+ }
66050+#endif
66051+ return 0;
66052+}
66053+
66054+#ifdef CONFIG_GRKERNSEC
66055+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
66056+
66057+int gr_fake_force_sig(int sig, struct task_struct *t)
66058+{
66059+ unsigned long int flags;
66060+ int ret, blocked, ignored;
66061+ struct k_sigaction *action;
66062+
66063+ spin_lock_irqsave(&t->sighand->siglock, flags);
66064+ action = &t->sighand->action[sig-1];
66065+ ignored = action->sa.sa_handler == SIG_IGN;
66066+ blocked = sigismember(&t->blocked, sig);
66067+ if (blocked || ignored) {
66068+ action->sa.sa_handler = SIG_DFL;
66069+ if (blocked) {
66070+ sigdelset(&t->blocked, sig);
66071+ recalc_sigpending_and_wake(t);
66072+ }
66073+ }
66074+ if (action->sa.sa_handler == SIG_DFL)
66075+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
66076+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
66077+
66078+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
66079+
66080+ return ret;
66081+}
66082+#endif
66083+
66084+#ifdef CONFIG_GRKERNSEC_BRUTE
66085+#define GR_USER_BAN_TIME (15 * 60)
66086+#define GR_DAEMON_BRUTE_TIME (30 * 60)
66087+
66088+static int __get_dumpable(unsigned long mm_flags)
66089+{
66090+ int ret;
66091+
66092+ ret = mm_flags & MMF_DUMPABLE_MASK;
66093+ return (ret >= 2) ? 2 : ret;
66094+}
66095+#endif
66096+
66097+void gr_handle_brute_attach(unsigned long mm_flags)
66098+{
66099+#ifdef CONFIG_GRKERNSEC_BRUTE
66100+ struct task_struct *p = current;
66101+ kuid_t uid = GLOBAL_ROOT_UID;
66102+ int daemon = 0;
66103+
66104+ if (!grsec_enable_brute)
66105+ return;
66106+
66107+ rcu_read_lock();
66108+ read_lock(&tasklist_lock);
66109+ read_lock(&grsec_exec_file_lock);
66110+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
66111+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
66112+ p->real_parent->brute = 1;
66113+ daemon = 1;
66114+ } else {
66115+ const struct cred *cred = __task_cred(p), *cred2;
66116+ struct task_struct *tsk, *tsk2;
66117+
66118+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
66119+ struct user_struct *user;
66120+
66121+ uid = cred->uid;
66122+
66123+ /* this is put upon execution past expiration */
66124+ user = find_user(uid);
66125+ if (user == NULL)
66126+ goto unlock;
66127+ user->suid_banned = 1;
66128+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
66129+ if (user->suid_ban_expires == ~0UL)
66130+ user->suid_ban_expires--;
66131+
66132+ /* only kill other threads of the same binary, from the same user */
66133+ do_each_thread(tsk2, tsk) {
66134+ cred2 = __task_cred(tsk);
66135+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
66136+ gr_fake_force_sig(SIGKILL, tsk);
66137+ } while_each_thread(tsk2, tsk);
66138+ }
66139+ }
66140+unlock:
66141+ read_unlock(&grsec_exec_file_lock);
66142+ read_unlock(&tasklist_lock);
66143+ rcu_read_unlock();
66144+
66145+ if (gr_is_global_nonroot(uid))
66146+ 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);
66147+ else if (daemon)
66148+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
66149+
66150+#endif
66151+ return;
66152+}
66153+
66154+void gr_handle_brute_check(void)
66155+{
66156+#ifdef CONFIG_GRKERNSEC_BRUTE
66157+ struct task_struct *p = current;
66158+
66159+ if (unlikely(p->brute)) {
66160+ if (!grsec_enable_brute)
66161+ p->brute = 0;
66162+ else if (time_before(get_seconds(), p->brute_expires))
66163+ msleep(30 * 1000);
66164+ }
66165+#endif
66166+ return;
66167+}
66168+
66169+void gr_handle_kernel_exploit(void)
66170+{
66171+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66172+ const struct cred *cred;
66173+ struct task_struct *tsk, *tsk2;
66174+ struct user_struct *user;
66175+ kuid_t uid;
66176+
66177+ if (in_irq() || in_serving_softirq() || in_nmi())
66178+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
66179+
66180+ uid = current_uid();
66181+
66182+ if (gr_is_global_root(uid))
66183+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
66184+ else {
66185+ /* kill all the processes of this user, hold a reference
66186+ to their creds struct, and prevent them from creating
66187+ another process until system reset
66188+ */
66189+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
66190+ GR_GLOBAL_UID(uid));
66191+ /* we intentionally leak this ref */
66192+ user = get_uid(current->cred->user);
66193+ if (user)
66194+ user->kernel_banned = 1;
66195+
66196+ /* kill all processes of this user */
66197+ read_lock(&tasklist_lock);
66198+ do_each_thread(tsk2, tsk) {
66199+ cred = __task_cred(tsk);
66200+ if (uid_eq(cred->uid, uid))
66201+ gr_fake_force_sig(SIGKILL, tsk);
66202+ } while_each_thread(tsk2, tsk);
66203+ read_unlock(&tasklist_lock);
66204+ }
66205+#endif
66206+}
66207+
66208+#ifdef CONFIG_GRKERNSEC_BRUTE
66209+static bool suid_ban_expired(struct user_struct *user)
66210+{
66211+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
66212+ user->suid_banned = 0;
66213+ user->suid_ban_expires = 0;
66214+ free_uid(user);
66215+ return true;
66216+ }
66217+
66218+ return false;
66219+}
66220+#endif
66221+
66222+int gr_process_kernel_exec_ban(void)
66223+{
66224+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66225+ if (unlikely(current->cred->user->kernel_banned))
66226+ return -EPERM;
66227+#endif
66228+ return 0;
66229+}
66230+
66231+int gr_process_kernel_setuid_ban(struct user_struct *user)
66232+{
66233+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66234+ if (unlikely(user->kernel_banned))
66235+ gr_fake_force_sig(SIGKILL, current);
66236+#endif
66237+ return 0;
66238+}
66239+
66240+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
66241+{
66242+#ifdef CONFIG_GRKERNSEC_BRUTE
66243+ struct user_struct *user = current->cred->user;
66244+ if (unlikely(user->suid_banned)) {
66245+ if (suid_ban_expired(user))
66246+ return 0;
66247+ /* disallow execution of suid binaries only */
66248+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
66249+ return -EPERM;
66250+ }
66251+#endif
66252+ return 0;
66253+}
66254diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
66255new file mode 100644
66256index 0000000..4030d57
66257--- /dev/null
66258+++ b/grsecurity/grsec_sock.c
66259@@ -0,0 +1,244 @@
66260+#include <linux/kernel.h>
66261+#include <linux/module.h>
66262+#include <linux/sched.h>
66263+#include <linux/file.h>
66264+#include <linux/net.h>
66265+#include <linux/in.h>
66266+#include <linux/ip.h>
66267+#include <net/sock.h>
66268+#include <net/inet_sock.h>
66269+#include <linux/grsecurity.h>
66270+#include <linux/grinternal.h>
66271+#include <linux/gracl.h>
66272+
66273+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
66274+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
66275+
66276+EXPORT_SYMBOL(gr_search_udp_recvmsg);
66277+EXPORT_SYMBOL(gr_search_udp_sendmsg);
66278+
66279+#ifdef CONFIG_UNIX_MODULE
66280+EXPORT_SYMBOL(gr_acl_handle_unix);
66281+EXPORT_SYMBOL(gr_acl_handle_mknod);
66282+EXPORT_SYMBOL(gr_handle_chroot_unix);
66283+EXPORT_SYMBOL(gr_handle_create);
66284+#endif
66285+
66286+#ifdef CONFIG_GRKERNSEC
66287+#define gr_conn_table_size 32749
66288+struct conn_table_entry {
66289+ struct conn_table_entry *next;
66290+ struct signal_struct *sig;
66291+};
66292+
66293+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
66294+DEFINE_SPINLOCK(gr_conn_table_lock);
66295+
66296+extern const char * gr_socktype_to_name(unsigned char type);
66297+extern const char * gr_proto_to_name(unsigned char proto);
66298+extern const char * gr_sockfamily_to_name(unsigned char family);
66299+
66300+static __inline__ int
66301+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
66302+{
66303+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
66304+}
66305+
66306+static __inline__ int
66307+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
66308+ __u16 sport, __u16 dport)
66309+{
66310+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
66311+ sig->gr_sport == sport && sig->gr_dport == dport))
66312+ return 1;
66313+ else
66314+ return 0;
66315+}
66316+
66317+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
66318+{
66319+ struct conn_table_entry **match;
66320+ unsigned int index;
66321+
66322+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66323+ sig->gr_sport, sig->gr_dport,
66324+ gr_conn_table_size);
66325+
66326+ newent->sig = sig;
66327+
66328+ match = &gr_conn_table[index];
66329+ newent->next = *match;
66330+ *match = newent;
66331+
66332+ return;
66333+}
66334+
66335+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
66336+{
66337+ struct conn_table_entry *match, *last = NULL;
66338+ unsigned int index;
66339+
66340+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66341+ sig->gr_sport, sig->gr_dport,
66342+ gr_conn_table_size);
66343+
66344+ match = gr_conn_table[index];
66345+ while (match && !conn_match(match->sig,
66346+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
66347+ sig->gr_dport)) {
66348+ last = match;
66349+ match = match->next;
66350+ }
66351+
66352+ if (match) {
66353+ if (last)
66354+ last->next = match->next;
66355+ else
66356+ gr_conn_table[index] = NULL;
66357+ kfree(match);
66358+ }
66359+
66360+ return;
66361+}
66362+
66363+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
66364+ __u16 sport, __u16 dport)
66365+{
66366+ struct conn_table_entry *match;
66367+ unsigned int index;
66368+
66369+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
66370+
66371+ match = gr_conn_table[index];
66372+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
66373+ match = match->next;
66374+
66375+ if (match)
66376+ return match->sig;
66377+ else
66378+ return NULL;
66379+}
66380+
66381+#endif
66382+
66383+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
66384+{
66385+#ifdef CONFIG_GRKERNSEC
66386+ struct signal_struct *sig = task->signal;
66387+ struct conn_table_entry *newent;
66388+
66389+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
66390+ if (newent == NULL)
66391+ return;
66392+ /* no bh lock needed since we are called with bh disabled */
66393+ spin_lock(&gr_conn_table_lock);
66394+ gr_del_task_from_ip_table_nolock(sig);
66395+ sig->gr_saddr = inet->inet_rcv_saddr;
66396+ sig->gr_daddr = inet->inet_daddr;
66397+ sig->gr_sport = inet->inet_sport;
66398+ sig->gr_dport = inet->inet_dport;
66399+ gr_add_to_task_ip_table_nolock(sig, newent);
66400+ spin_unlock(&gr_conn_table_lock);
66401+#endif
66402+ return;
66403+}
66404+
66405+void gr_del_task_from_ip_table(struct task_struct *task)
66406+{
66407+#ifdef CONFIG_GRKERNSEC
66408+ spin_lock_bh(&gr_conn_table_lock);
66409+ gr_del_task_from_ip_table_nolock(task->signal);
66410+ spin_unlock_bh(&gr_conn_table_lock);
66411+#endif
66412+ return;
66413+}
66414+
66415+void
66416+gr_attach_curr_ip(const struct sock *sk)
66417+{
66418+#ifdef CONFIG_GRKERNSEC
66419+ struct signal_struct *p, *set;
66420+ const struct inet_sock *inet = inet_sk(sk);
66421+
66422+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
66423+ return;
66424+
66425+ set = current->signal;
66426+
66427+ spin_lock_bh(&gr_conn_table_lock);
66428+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
66429+ inet->inet_dport, inet->inet_sport);
66430+ if (unlikely(p != NULL)) {
66431+ set->curr_ip = p->curr_ip;
66432+ set->used_accept = 1;
66433+ gr_del_task_from_ip_table_nolock(p);
66434+ spin_unlock_bh(&gr_conn_table_lock);
66435+ return;
66436+ }
66437+ spin_unlock_bh(&gr_conn_table_lock);
66438+
66439+ set->curr_ip = inet->inet_daddr;
66440+ set->used_accept = 1;
66441+#endif
66442+ return;
66443+}
66444+
66445+int
66446+gr_handle_sock_all(const int family, const int type, const int protocol)
66447+{
66448+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66449+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
66450+ (family != AF_UNIX)) {
66451+ if (family == AF_INET)
66452+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
66453+ else
66454+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
66455+ return -EACCES;
66456+ }
66457+#endif
66458+ return 0;
66459+}
66460+
66461+int
66462+gr_handle_sock_server(const struct sockaddr *sck)
66463+{
66464+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66465+ if (grsec_enable_socket_server &&
66466+ in_group_p(grsec_socket_server_gid) &&
66467+ sck && (sck->sa_family != AF_UNIX) &&
66468+ (sck->sa_family != AF_LOCAL)) {
66469+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66470+ return -EACCES;
66471+ }
66472+#endif
66473+ return 0;
66474+}
66475+
66476+int
66477+gr_handle_sock_server_other(const struct sock *sck)
66478+{
66479+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66480+ if (grsec_enable_socket_server &&
66481+ in_group_p(grsec_socket_server_gid) &&
66482+ sck && (sck->sk_family != AF_UNIX) &&
66483+ (sck->sk_family != AF_LOCAL)) {
66484+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66485+ return -EACCES;
66486+ }
66487+#endif
66488+ return 0;
66489+}
66490+
66491+int
66492+gr_handle_sock_client(const struct sockaddr *sck)
66493+{
66494+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66495+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
66496+ sck && (sck->sa_family != AF_UNIX) &&
66497+ (sck->sa_family != AF_LOCAL)) {
66498+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
66499+ return -EACCES;
66500+ }
66501+#endif
66502+ return 0;
66503+}
66504diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
66505new file mode 100644
66506index 0000000..f55ef0f
66507--- /dev/null
66508+++ b/grsecurity/grsec_sysctl.c
66509@@ -0,0 +1,469 @@
66510+#include <linux/kernel.h>
66511+#include <linux/sched.h>
66512+#include <linux/sysctl.h>
66513+#include <linux/grsecurity.h>
66514+#include <linux/grinternal.h>
66515+
66516+int
66517+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
66518+{
66519+#ifdef CONFIG_GRKERNSEC_SYSCTL
66520+ if (dirname == NULL || name == NULL)
66521+ return 0;
66522+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
66523+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
66524+ return -EACCES;
66525+ }
66526+#endif
66527+ return 0;
66528+}
66529+
66530+#ifdef CONFIG_GRKERNSEC_ROFS
66531+static int __maybe_unused one = 1;
66532+#endif
66533+
66534+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66535+struct ctl_table grsecurity_table[] = {
66536+#ifdef CONFIG_GRKERNSEC_SYSCTL
66537+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
66538+#ifdef CONFIG_GRKERNSEC_IO
66539+ {
66540+ .procname = "disable_priv_io",
66541+ .data = &grsec_disable_privio,
66542+ .maxlen = sizeof(int),
66543+ .mode = 0600,
66544+ .proc_handler = &proc_dointvec,
66545+ },
66546+#endif
66547+#endif
66548+#ifdef CONFIG_GRKERNSEC_LINK
66549+ {
66550+ .procname = "linking_restrictions",
66551+ .data = &grsec_enable_link,
66552+ .maxlen = sizeof(int),
66553+ .mode = 0600,
66554+ .proc_handler = &proc_dointvec,
66555+ },
66556+#endif
66557+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
66558+ {
66559+ .procname = "enforce_symlinksifowner",
66560+ .data = &grsec_enable_symlinkown,
66561+ .maxlen = sizeof(int),
66562+ .mode = 0600,
66563+ .proc_handler = &proc_dointvec,
66564+ },
66565+ {
66566+ .procname = "symlinkown_gid",
66567+ .data = &grsec_symlinkown_gid,
66568+ .maxlen = sizeof(int),
66569+ .mode = 0600,
66570+ .proc_handler = &proc_dointvec,
66571+ },
66572+#endif
66573+#ifdef CONFIG_GRKERNSEC_BRUTE
66574+ {
66575+ .procname = "deter_bruteforce",
66576+ .data = &grsec_enable_brute,
66577+ .maxlen = sizeof(int),
66578+ .mode = 0600,
66579+ .proc_handler = &proc_dointvec,
66580+ },
66581+#endif
66582+#ifdef CONFIG_GRKERNSEC_FIFO
66583+ {
66584+ .procname = "fifo_restrictions",
66585+ .data = &grsec_enable_fifo,
66586+ .maxlen = sizeof(int),
66587+ .mode = 0600,
66588+ .proc_handler = &proc_dointvec,
66589+ },
66590+#endif
66591+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66592+ {
66593+ .procname = "ptrace_readexec",
66594+ .data = &grsec_enable_ptrace_readexec,
66595+ .maxlen = sizeof(int),
66596+ .mode = 0600,
66597+ .proc_handler = &proc_dointvec,
66598+ },
66599+#endif
66600+#ifdef CONFIG_GRKERNSEC_SETXID
66601+ {
66602+ .procname = "consistent_setxid",
66603+ .data = &grsec_enable_setxid,
66604+ .maxlen = sizeof(int),
66605+ .mode = 0600,
66606+ .proc_handler = &proc_dointvec,
66607+ },
66608+#endif
66609+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
66610+ {
66611+ .procname = "ip_blackhole",
66612+ .data = &grsec_enable_blackhole,
66613+ .maxlen = sizeof(int),
66614+ .mode = 0600,
66615+ .proc_handler = &proc_dointvec,
66616+ },
66617+ {
66618+ .procname = "lastack_retries",
66619+ .data = &grsec_lastack_retries,
66620+ .maxlen = sizeof(int),
66621+ .mode = 0600,
66622+ .proc_handler = &proc_dointvec,
66623+ },
66624+#endif
66625+#ifdef CONFIG_GRKERNSEC_EXECLOG
66626+ {
66627+ .procname = "exec_logging",
66628+ .data = &grsec_enable_execlog,
66629+ .maxlen = sizeof(int),
66630+ .mode = 0600,
66631+ .proc_handler = &proc_dointvec,
66632+ },
66633+#endif
66634+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66635+ {
66636+ .procname = "rwxmap_logging",
66637+ .data = &grsec_enable_log_rwxmaps,
66638+ .maxlen = sizeof(int),
66639+ .mode = 0600,
66640+ .proc_handler = &proc_dointvec,
66641+ },
66642+#endif
66643+#ifdef CONFIG_GRKERNSEC_SIGNAL
66644+ {
66645+ .procname = "signal_logging",
66646+ .data = &grsec_enable_signal,
66647+ .maxlen = sizeof(int),
66648+ .mode = 0600,
66649+ .proc_handler = &proc_dointvec,
66650+ },
66651+#endif
66652+#ifdef CONFIG_GRKERNSEC_FORKFAIL
66653+ {
66654+ .procname = "forkfail_logging",
66655+ .data = &grsec_enable_forkfail,
66656+ .maxlen = sizeof(int),
66657+ .mode = 0600,
66658+ .proc_handler = &proc_dointvec,
66659+ },
66660+#endif
66661+#ifdef CONFIG_GRKERNSEC_TIME
66662+ {
66663+ .procname = "timechange_logging",
66664+ .data = &grsec_enable_time,
66665+ .maxlen = sizeof(int),
66666+ .mode = 0600,
66667+ .proc_handler = &proc_dointvec,
66668+ },
66669+#endif
66670+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
66671+ {
66672+ .procname = "chroot_deny_shmat",
66673+ .data = &grsec_enable_chroot_shmat,
66674+ .maxlen = sizeof(int),
66675+ .mode = 0600,
66676+ .proc_handler = &proc_dointvec,
66677+ },
66678+#endif
66679+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
66680+ {
66681+ .procname = "chroot_deny_unix",
66682+ .data = &grsec_enable_chroot_unix,
66683+ .maxlen = sizeof(int),
66684+ .mode = 0600,
66685+ .proc_handler = &proc_dointvec,
66686+ },
66687+#endif
66688+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
66689+ {
66690+ .procname = "chroot_deny_mount",
66691+ .data = &grsec_enable_chroot_mount,
66692+ .maxlen = sizeof(int),
66693+ .mode = 0600,
66694+ .proc_handler = &proc_dointvec,
66695+ },
66696+#endif
66697+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
66698+ {
66699+ .procname = "chroot_deny_fchdir",
66700+ .data = &grsec_enable_chroot_fchdir,
66701+ .maxlen = sizeof(int),
66702+ .mode = 0600,
66703+ .proc_handler = &proc_dointvec,
66704+ },
66705+#endif
66706+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
66707+ {
66708+ .procname = "chroot_deny_chroot",
66709+ .data = &grsec_enable_chroot_double,
66710+ .maxlen = sizeof(int),
66711+ .mode = 0600,
66712+ .proc_handler = &proc_dointvec,
66713+ },
66714+#endif
66715+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
66716+ {
66717+ .procname = "chroot_deny_pivot",
66718+ .data = &grsec_enable_chroot_pivot,
66719+ .maxlen = sizeof(int),
66720+ .mode = 0600,
66721+ .proc_handler = &proc_dointvec,
66722+ },
66723+#endif
66724+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
66725+ {
66726+ .procname = "chroot_enforce_chdir",
66727+ .data = &grsec_enable_chroot_chdir,
66728+ .maxlen = sizeof(int),
66729+ .mode = 0600,
66730+ .proc_handler = &proc_dointvec,
66731+ },
66732+#endif
66733+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
66734+ {
66735+ .procname = "chroot_deny_chmod",
66736+ .data = &grsec_enable_chroot_chmod,
66737+ .maxlen = sizeof(int),
66738+ .mode = 0600,
66739+ .proc_handler = &proc_dointvec,
66740+ },
66741+#endif
66742+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
66743+ {
66744+ .procname = "chroot_deny_mknod",
66745+ .data = &grsec_enable_chroot_mknod,
66746+ .maxlen = sizeof(int),
66747+ .mode = 0600,
66748+ .proc_handler = &proc_dointvec,
66749+ },
66750+#endif
66751+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
66752+ {
66753+ .procname = "chroot_restrict_nice",
66754+ .data = &grsec_enable_chroot_nice,
66755+ .maxlen = sizeof(int),
66756+ .mode = 0600,
66757+ .proc_handler = &proc_dointvec,
66758+ },
66759+#endif
66760+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
66761+ {
66762+ .procname = "chroot_execlog",
66763+ .data = &grsec_enable_chroot_execlog,
66764+ .maxlen = sizeof(int),
66765+ .mode = 0600,
66766+ .proc_handler = &proc_dointvec,
66767+ },
66768+#endif
66769+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66770+ {
66771+ .procname = "chroot_caps",
66772+ .data = &grsec_enable_chroot_caps,
66773+ .maxlen = sizeof(int),
66774+ .mode = 0600,
66775+ .proc_handler = &proc_dointvec,
66776+ },
66777+#endif
66778+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
66779+ {
66780+ .procname = "chroot_deny_sysctl",
66781+ .data = &grsec_enable_chroot_sysctl,
66782+ .maxlen = sizeof(int),
66783+ .mode = 0600,
66784+ .proc_handler = &proc_dointvec,
66785+ },
66786+#endif
66787+#ifdef CONFIG_GRKERNSEC_TPE
66788+ {
66789+ .procname = "tpe",
66790+ .data = &grsec_enable_tpe,
66791+ .maxlen = sizeof(int),
66792+ .mode = 0600,
66793+ .proc_handler = &proc_dointvec,
66794+ },
66795+ {
66796+ .procname = "tpe_gid",
66797+ .data = &grsec_tpe_gid,
66798+ .maxlen = sizeof(int),
66799+ .mode = 0600,
66800+ .proc_handler = &proc_dointvec,
66801+ },
66802+#endif
66803+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66804+ {
66805+ .procname = "tpe_invert",
66806+ .data = &grsec_enable_tpe_invert,
66807+ .maxlen = sizeof(int),
66808+ .mode = 0600,
66809+ .proc_handler = &proc_dointvec,
66810+ },
66811+#endif
66812+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66813+ {
66814+ .procname = "tpe_restrict_all",
66815+ .data = &grsec_enable_tpe_all,
66816+ .maxlen = sizeof(int),
66817+ .mode = 0600,
66818+ .proc_handler = &proc_dointvec,
66819+ },
66820+#endif
66821+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66822+ {
66823+ .procname = "socket_all",
66824+ .data = &grsec_enable_socket_all,
66825+ .maxlen = sizeof(int),
66826+ .mode = 0600,
66827+ .proc_handler = &proc_dointvec,
66828+ },
66829+ {
66830+ .procname = "socket_all_gid",
66831+ .data = &grsec_socket_all_gid,
66832+ .maxlen = sizeof(int),
66833+ .mode = 0600,
66834+ .proc_handler = &proc_dointvec,
66835+ },
66836+#endif
66837+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66838+ {
66839+ .procname = "socket_client",
66840+ .data = &grsec_enable_socket_client,
66841+ .maxlen = sizeof(int),
66842+ .mode = 0600,
66843+ .proc_handler = &proc_dointvec,
66844+ },
66845+ {
66846+ .procname = "socket_client_gid",
66847+ .data = &grsec_socket_client_gid,
66848+ .maxlen = sizeof(int),
66849+ .mode = 0600,
66850+ .proc_handler = &proc_dointvec,
66851+ },
66852+#endif
66853+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66854+ {
66855+ .procname = "socket_server",
66856+ .data = &grsec_enable_socket_server,
66857+ .maxlen = sizeof(int),
66858+ .mode = 0600,
66859+ .proc_handler = &proc_dointvec,
66860+ },
66861+ {
66862+ .procname = "socket_server_gid",
66863+ .data = &grsec_socket_server_gid,
66864+ .maxlen = sizeof(int),
66865+ .mode = 0600,
66866+ .proc_handler = &proc_dointvec,
66867+ },
66868+#endif
66869+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
66870+ {
66871+ .procname = "audit_group",
66872+ .data = &grsec_enable_group,
66873+ .maxlen = sizeof(int),
66874+ .mode = 0600,
66875+ .proc_handler = &proc_dointvec,
66876+ },
66877+ {
66878+ .procname = "audit_gid",
66879+ .data = &grsec_audit_gid,
66880+ .maxlen = sizeof(int),
66881+ .mode = 0600,
66882+ .proc_handler = &proc_dointvec,
66883+ },
66884+#endif
66885+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
66886+ {
66887+ .procname = "audit_chdir",
66888+ .data = &grsec_enable_chdir,
66889+ .maxlen = sizeof(int),
66890+ .mode = 0600,
66891+ .proc_handler = &proc_dointvec,
66892+ },
66893+#endif
66894+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66895+ {
66896+ .procname = "audit_mount",
66897+ .data = &grsec_enable_mount,
66898+ .maxlen = sizeof(int),
66899+ .mode = 0600,
66900+ .proc_handler = &proc_dointvec,
66901+ },
66902+#endif
66903+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
66904+ {
66905+ .procname = "audit_textrel",
66906+ .data = &grsec_enable_audit_textrel,
66907+ .maxlen = sizeof(int),
66908+ .mode = 0600,
66909+ .proc_handler = &proc_dointvec,
66910+ },
66911+#endif
66912+#ifdef CONFIG_GRKERNSEC_DMESG
66913+ {
66914+ .procname = "dmesg",
66915+ .data = &grsec_enable_dmesg,
66916+ .maxlen = sizeof(int),
66917+ .mode = 0600,
66918+ .proc_handler = &proc_dointvec,
66919+ },
66920+#endif
66921+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66922+ {
66923+ .procname = "chroot_findtask",
66924+ .data = &grsec_enable_chroot_findtask,
66925+ .maxlen = sizeof(int),
66926+ .mode = 0600,
66927+ .proc_handler = &proc_dointvec,
66928+ },
66929+#endif
66930+#ifdef CONFIG_GRKERNSEC_RESLOG
66931+ {
66932+ .procname = "resource_logging",
66933+ .data = &grsec_resource_logging,
66934+ .maxlen = sizeof(int),
66935+ .mode = 0600,
66936+ .proc_handler = &proc_dointvec,
66937+ },
66938+#endif
66939+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66940+ {
66941+ .procname = "audit_ptrace",
66942+ .data = &grsec_enable_audit_ptrace,
66943+ .maxlen = sizeof(int),
66944+ .mode = 0600,
66945+ .proc_handler = &proc_dointvec,
66946+ },
66947+#endif
66948+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66949+ {
66950+ .procname = "harden_ptrace",
66951+ .data = &grsec_enable_harden_ptrace,
66952+ .maxlen = sizeof(int),
66953+ .mode = 0600,
66954+ .proc_handler = &proc_dointvec,
66955+ },
66956+#endif
66957+ {
66958+ .procname = "grsec_lock",
66959+ .data = &grsec_lock,
66960+ .maxlen = sizeof(int),
66961+ .mode = 0600,
66962+ .proc_handler = &proc_dointvec,
66963+ },
66964+#endif
66965+#ifdef CONFIG_GRKERNSEC_ROFS
66966+ {
66967+ .procname = "romount_protect",
66968+ .data = &grsec_enable_rofs,
66969+ .maxlen = sizeof(int),
66970+ .mode = 0600,
66971+ .proc_handler = &proc_dointvec_minmax,
66972+ .extra1 = &one,
66973+ .extra2 = &one,
66974+ },
66975+#endif
66976+ { }
66977+};
66978+#endif
66979diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
66980new file mode 100644
66981index 0000000..0dc13c3
66982--- /dev/null
66983+++ b/grsecurity/grsec_time.c
66984@@ -0,0 +1,16 @@
66985+#include <linux/kernel.h>
66986+#include <linux/sched.h>
66987+#include <linux/grinternal.h>
66988+#include <linux/module.h>
66989+
66990+void
66991+gr_log_timechange(void)
66992+{
66993+#ifdef CONFIG_GRKERNSEC_TIME
66994+ if (grsec_enable_time)
66995+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
66996+#endif
66997+ return;
66998+}
66999+
67000+EXPORT_SYMBOL(gr_log_timechange);
67001diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
67002new file mode 100644
67003index 0000000..ee57dcf
67004--- /dev/null
67005+++ b/grsecurity/grsec_tpe.c
67006@@ -0,0 +1,73 @@
67007+#include <linux/kernel.h>
67008+#include <linux/sched.h>
67009+#include <linux/file.h>
67010+#include <linux/fs.h>
67011+#include <linux/grinternal.h>
67012+
67013+extern int gr_acl_tpe_check(void);
67014+
67015+int
67016+gr_tpe_allow(const struct file *file)
67017+{
67018+#ifdef CONFIG_GRKERNSEC
67019+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
67020+ const struct cred *cred = current_cred();
67021+ char *msg = NULL;
67022+ char *msg2 = NULL;
67023+
67024+ // never restrict root
67025+ if (gr_is_global_root(cred->uid))
67026+ return 1;
67027+
67028+ if (grsec_enable_tpe) {
67029+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
67030+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
67031+ msg = "not being in trusted group";
67032+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
67033+ msg = "being in untrusted group";
67034+#else
67035+ if (in_group_p(grsec_tpe_gid))
67036+ msg = "being in untrusted group";
67037+#endif
67038+ }
67039+ if (!msg && gr_acl_tpe_check())
67040+ msg = "being in untrusted role";
67041+
67042+ // not in any affected group/role
67043+ if (!msg)
67044+ goto next_check;
67045+
67046+ if (gr_is_global_nonroot(inode->i_uid))
67047+ msg2 = "file in non-root-owned directory";
67048+ else if (inode->i_mode & S_IWOTH)
67049+ msg2 = "file in world-writable directory";
67050+ else if (inode->i_mode & S_IWGRP)
67051+ msg2 = "file in group-writable directory";
67052+
67053+ if (msg && msg2) {
67054+ char fullmsg[70] = {0};
67055+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
67056+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
67057+ return 0;
67058+ }
67059+ msg = NULL;
67060+next_check:
67061+#ifdef CONFIG_GRKERNSEC_TPE_ALL
67062+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
67063+ return 1;
67064+
67065+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
67066+ msg = "directory not owned by user";
67067+ else if (inode->i_mode & S_IWOTH)
67068+ msg = "file in world-writable directory";
67069+ else if (inode->i_mode & S_IWGRP)
67070+ msg = "file in group-writable directory";
67071+
67072+ if (msg) {
67073+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
67074+ return 0;
67075+ }
67076+#endif
67077+#endif
67078+ return 1;
67079+}
67080diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
67081new file mode 100644
67082index 0000000..9f7b1ac
67083--- /dev/null
67084+++ b/grsecurity/grsum.c
67085@@ -0,0 +1,61 @@
67086+#include <linux/err.h>
67087+#include <linux/kernel.h>
67088+#include <linux/sched.h>
67089+#include <linux/mm.h>
67090+#include <linux/scatterlist.h>
67091+#include <linux/crypto.h>
67092+#include <linux/gracl.h>
67093+
67094+
67095+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
67096+#error "crypto and sha256 must be built into the kernel"
67097+#endif
67098+
67099+int
67100+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
67101+{
67102+ char *p;
67103+ struct crypto_hash *tfm;
67104+ struct hash_desc desc;
67105+ struct scatterlist sg;
67106+ unsigned char temp_sum[GR_SHA_LEN];
67107+ volatile int retval = 0;
67108+ volatile int dummy = 0;
67109+ unsigned int i;
67110+
67111+ sg_init_table(&sg, 1);
67112+
67113+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
67114+ if (IS_ERR(tfm)) {
67115+ /* should never happen, since sha256 should be built in */
67116+ return 1;
67117+ }
67118+
67119+ desc.tfm = tfm;
67120+ desc.flags = 0;
67121+
67122+ crypto_hash_init(&desc);
67123+
67124+ p = salt;
67125+ sg_set_buf(&sg, p, GR_SALT_LEN);
67126+ crypto_hash_update(&desc, &sg, sg.length);
67127+
67128+ p = entry->pw;
67129+ sg_set_buf(&sg, p, strlen(p));
67130+
67131+ crypto_hash_update(&desc, &sg, sg.length);
67132+
67133+ crypto_hash_final(&desc, temp_sum);
67134+
67135+ memset(entry->pw, 0, GR_PW_LEN);
67136+
67137+ for (i = 0; i < GR_SHA_LEN; i++)
67138+ if (sum[i] != temp_sum[i])
67139+ retval = 1;
67140+ else
67141+ dummy = 1; // waste a cycle
67142+
67143+ crypto_free_hash(tfm);
67144+
67145+ return retval;
67146+}
67147diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
67148index 77ff547..181834f 100644
67149--- a/include/asm-generic/4level-fixup.h
67150+++ b/include/asm-generic/4level-fixup.h
67151@@ -13,8 +13,10 @@
67152 #define pmd_alloc(mm, pud, address) \
67153 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
67154 NULL: pmd_offset(pud, address))
67155+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
67156
67157 #define pud_alloc(mm, pgd, address) (pgd)
67158+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
67159 #define pud_offset(pgd, start) (pgd)
67160 #define pud_none(pud) 0
67161 #define pud_bad(pud) 0
67162diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
67163index b7babf0..04ad282 100644
67164--- a/include/asm-generic/atomic-long.h
67165+++ b/include/asm-generic/atomic-long.h
67166@@ -22,6 +22,12 @@
67167
67168 typedef atomic64_t atomic_long_t;
67169
67170+#ifdef CONFIG_PAX_REFCOUNT
67171+typedef atomic64_unchecked_t atomic_long_unchecked_t;
67172+#else
67173+typedef atomic64_t atomic_long_unchecked_t;
67174+#endif
67175+
67176 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
67177
67178 static inline long atomic_long_read(atomic_long_t *l)
67179@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67180 return (long)atomic64_read(v);
67181 }
67182
67183+#ifdef CONFIG_PAX_REFCOUNT
67184+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67185+{
67186+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67187+
67188+ return (long)atomic64_read_unchecked(v);
67189+}
67190+#endif
67191+
67192 static inline void atomic_long_set(atomic_long_t *l, long i)
67193 {
67194 atomic64_t *v = (atomic64_t *)l;
67195@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67196 atomic64_set(v, i);
67197 }
67198
67199+#ifdef CONFIG_PAX_REFCOUNT
67200+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67201+{
67202+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67203+
67204+ atomic64_set_unchecked(v, i);
67205+}
67206+#endif
67207+
67208 static inline void atomic_long_inc(atomic_long_t *l)
67209 {
67210 atomic64_t *v = (atomic64_t *)l;
67211@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67212 atomic64_inc(v);
67213 }
67214
67215+#ifdef CONFIG_PAX_REFCOUNT
67216+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67217+{
67218+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67219+
67220+ atomic64_inc_unchecked(v);
67221+}
67222+#endif
67223+
67224 static inline void atomic_long_dec(atomic_long_t *l)
67225 {
67226 atomic64_t *v = (atomic64_t *)l;
67227@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67228 atomic64_dec(v);
67229 }
67230
67231+#ifdef CONFIG_PAX_REFCOUNT
67232+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67233+{
67234+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67235+
67236+ atomic64_dec_unchecked(v);
67237+}
67238+#endif
67239+
67240 static inline void atomic_long_add(long i, atomic_long_t *l)
67241 {
67242 atomic64_t *v = (atomic64_t *)l;
67243@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67244 atomic64_add(i, v);
67245 }
67246
67247+#ifdef CONFIG_PAX_REFCOUNT
67248+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67249+{
67250+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67251+
67252+ atomic64_add_unchecked(i, v);
67253+}
67254+#endif
67255+
67256 static inline void atomic_long_sub(long i, atomic_long_t *l)
67257 {
67258 atomic64_t *v = (atomic64_t *)l;
67259@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67260 atomic64_sub(i, v);
67261 }
67262
67263+#ifdef CONFIG_PAX_REFCOUNT
67264+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67265+{
67266+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67267+
67268+ atomic64_sub_unchecked(i, v);
67269+}
67270+#endif
67271+
67272 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67273 {
67274 atomic64_t *v = (atomic64_t *)l;
67275@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67276 return (long)atomic64_add_return(i, v);
67277 }
67278
67279+#ifdef CONFIG_PAX_REFCOUNT
67280+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67281+{
67282+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67283+
67284+ return (long)atomic64_add_return_unchecked(i, v);
67285+}
67286+#endif
67287+
67288 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67289 {
67290 atomic64_t *v = (atomic64_t *)l;
67291@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67292 return (long)atomic64_inc_return(v);
67293 }
67294
67295+#ifdef CONFIG_PAX_REFCOUNT
67296+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67297+{
67298+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67299+
67300+ return (long)atomic64_inc_return_unchecked(v);
67301+}
67302+#endif
67303+
67304 static inline long atomic_long_dec_return(atomic_long_t *l)
67305 {
67306 atomic64_t *v = (atomic64_t *)l;
67307@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67308
67309 typedef atomic_t atomic_long_t;
67310
67311+#ifdef CONFIG_PAX_REFCOUNT
67312+typedef atomic_unchecked_t atomic_long_unchecked_t;
67313+#else
67314+typedef atomic_t atomic_long_unchecked_t;
67315+#endif
67316+
67317 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
67318 static inline long atomic_long_read(atomic_long_t *l)
67319 {
67320@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67321 return (long)atomic_read(v);
67322 }
67323
67324+#ifdef CONFIG_PAX_REFCOUNT
67325+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67326+{
67327+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67328+
67329+ return (long)atomic_read_unchecked(v);
67330+}
67331+#endif
67332+
67333 static inline void atomic_long_set(atomic_long_t *l, long i)
67334 {
67335 atomic_t *v = (atomic_t *)l;
67336@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67337 atomic_set(v, i);
67338 }
67339
67340+#ifdef CONFIG_PAX_REFCOUNT
67341+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67342+{
67343+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67344+
67345+ atomic_set_unchecked(v, i);
67346+}
67347+#endif
67348+
67349 static inline void atomic_long_inc(atomic_long_t *l)
67350 {
67351 atomic_t *v = (atomic_t *)l;
67352@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67353 atomic_inc(v);
67354 }
67355
67356+#ifdef CONFIG_PAX_REFCOUNT
67357+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67358+{
67359+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67360+
67361+ atomic_inc_unchecked(v);
67362+}
67363+#endif
67364+
67365 static inline void atomic_long_dec(atomic_long_t *l)
67366 {
67367 atomic_t *v = (atomic_t *)l;
67368@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67369 atomic_dec(v);
67370 }
67371
67372+#ifdef CONFIG_PAX_REFCOUNT
67373+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67374+{
67375+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67376+
67377+ atomic_dec_unchecked(v);
67378+}
67379+#endif
67380+
67381 static inline void atomic_long_add(long i, atomic_long_t *l)
67382 {
67383 atomic_t *v = (atomic_t *)l;
67384@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67385 atomic_add(i, v);
67386 }
67387
67388+#ifdef CONFIG_PAX_REFCOUNT
67389+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67390+{
67391+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67392+
67393+ atomic_add_unchecked(i, v);
67394+}
67395+#endif
67396+
67397 static inline void atomic_long_sub(long i, atomic_long_t *l)
67398 {
67399 atomic_t *v = (atomic_t *)l;
67400@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67401 atomic_sub(i, v);
67402 }
67403
67404+#ifdef CONFIG_PAX_REFCOUNT
67405+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67406+{
67407+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67408+
67409+ atomic_sub_unchecked(i, v);
67410+}
67411+#endif
67412+
67413 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67414 {
67415 atomic_t *v = (atomic_t *)l;
67416@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67417 return (long)atomic_add_return(i, v);
67418 }
67419
67420+#ifdef CONFIG_PAX_REFCOUNT
67421+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67422+{
67423+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67424+
67425+ return (long)atomic_add_return_unchecked(i, v);
67426+}
67427+
67428+#endif
67429+
67430 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67431 {
67432 atomic_t *v = (atomic_t *)l;
67433@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67434 return (long)atomic_inc_return(v);
67435 }
67436
67437+#ifdef CONFIG_PAX_REFCOUNT
67438+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67439+{
67440+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67441+
67442+ return (long)atomic_inc_return_unchecked(v);
67443+}
67444+#endif
67445+
67446 static inline long atomic_long_dec_return(atomic_long_t *l)
67447 {
67448 atomic_t *v = (atomic_t *)l;
67449@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67450
67451 #endif /* BITS_PER_LONG == 64 */
67452
67453+#ifdef CONFIG_PAX_REFCOUNT
67454+static inline void pax_refcount_needs_these_functions(void)
67455+{
67456+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
67457+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
67458+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
67459+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
67460+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
67461+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
67462+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
67463+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
67464+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
67465+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
67466+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
67467+#ifdef CONFIG_X86
67468+ atomic_clear_mask_unchecked(0, NULL);
67469+ atomic_set_mask_unchecked(0, NULL);
67470+#endif
67471+
67472+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
67473+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
67474+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
67475+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
67476+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
67477+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
67478+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
67479+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
67480+}
67481+#else
67482+#define atomic_read_unchecked(v) atomic_read(v)
67483+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
67484+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
67485+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
67486+#define atomic_inc_unchecked(v) atomic_inc(v)
67487+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
67488+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
67489+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
67490+#define atomic_dec_unchecked(v) atomic_dec(v)
67491+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
67492+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
67493+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
67494+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
67495+
67496+#define atomic_long_read_unchecked(v) atomic_long_read(v)
67497+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
67498+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
67499+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
67500+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
67501+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
67502+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
67503+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
67504+#endif
67505+
67506 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
67507diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
67508index 33bd2de..f31bff97 100644
67509--- a/include/asm-generic/atomic.h
67510+++ b/include/asm-generic/atomic.h
67511@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
67512 * Atomically clears the bits set in @mask from @v
67513 */
67514 #ifndef atomic_clear_mask
67515-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
67516+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
67517 {
67518 unsigned long flags;
67519
67520diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
67521index b18ce4f..2ee2843 100644
67522--- a/include/asm-generic/atomic64.h
67523+++ b/include/asm-generic/atomic64.h
67524@@ -16,6 +16,8 @@ typedef struct {
67525 long long counter;
67526 } atomic64_t;
67527
67528+typedef atomic64_t atomic64_unchecked_t;
67529+
67530 #define ATOMIC64_INIT(i) { (i) }
67531
67532 extern long long atomic64_read(const atomic64_t *v);
67533@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
67534 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
67535 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
67536
67537+#define atomic64_read_unchecked(v) atomic64_read(v)
67538+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
67539+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
67540+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
67541+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
67542+#define atomic64_inc_unchecked(v) atomic64_inc(v)
67543+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
67544+#define atomic64_dec_unchecked(v) atomic64_dec(v)
67545+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
67546+
67547 #endif /* _ASM_GENERIC_ATOMIC64_H */
67548diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
67549index 1bfcfe5..e04c5c9 100644
67550--- a/include/asm-generic/cache.h
67551+++ b/include/asm-generic/cache.h
67552@@ -6,7 +6,7 @@
67553 * cache lines need to provide their own cache.h.
67554 */
67555
67556-#define L1_CACHE_SHIFT 5
67557-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
67558+#define L1_CACHE_SHIFT 5UL
67559+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
67560
67561 #endif /* __ASM_GENERIC_CACHE_H */
67562diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
67563index 0d68a1e..b74a761 100644
67564--- a/include/asm-generic/emergency-restart.h
67565+++ b/include/asm-generic/emergency-restart.h
67566@@ -1,7 +1,7 @@
67567 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
67568 #define _ASM_GENERIC_EMERGENCY_RESTART_H
67569
67570-static inline void machine_emergency_restart(void)
67571+static inline __noreturn void machine_emergency_restart(void)
67572 {
67573 machine_restart(NULL);
67574 }
67575diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
67576index 90f99c7..00ce236 100644
67577--- a/include/asm-generic/kmap_types.h
67578+++ b/include/asm-generic/kmap_types.h
67579@@ -2,9 +2,9 @@
67580 #define _ASM_GENERIC_KMAP_TYPES_H
67581
67582 #ifdef __WITH_KM_FENCE
67583-# define KM_TYPE_NR 41
67584+# define KM_TYPE_NR 42
67585 #else
67586-# define KM_TYPE_NR 20
67587+# define KM_TYPE_NR 21
67588 #endif
67589
67590 #endif
67591diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
67592index 9ceb03b..62b0b8f 100644
67593--- a/include/asm-generic/local.h
67594+++ b/include/asm-generic/local.h
67595@@ -23,24 +23,37 @@ typedef struct
67596 atomic_long_t a;
67597 } local_t;
67598
67599+typedef struct {
67600+ atomic_long_unchecked_t a;
67601+} local_unchecked_t;
67602+
67603 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
67604
67605 #define local_read(l) atomic_long_read(&(l)->a)
67606+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
67607 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
67608+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
67609 #define local_inc(l) atomic_long_inc(&(l)->a)
67610+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
67611 #define local_dec(l) atomic_long_dec(&(l)->a)
67612+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
67613 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
67614+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
67615 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
67616+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
67617
67618 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
67619 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
67620 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
67621 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
67622 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
67623+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
67624 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
67625 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
67626+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
67627
67628 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67629+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67630 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
67631 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
67632 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
67633diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
67634index 725612b..9cc513a 100644
67635--- a/include/asm-generic/pgtable-nopmd.h
67636+++ b/include/asm-generic/pgtable-nopmd.h
67637@@ -1,14 +1,19 @@
67638 #ifndef _PGTABLE_NOPMD_H
67639 #define _PGTABLE_NOPMD_H
67640
67641-#ifndef __ASSEMBLY__
67642-
67643 #include <asm-generic/pgtable-nopud.h>
67644
67645-struct mm_struct;
67646-
67647 #define __PAGETABLE_PMD_FOLDED
67648
67649+#define PMD_SHIFT PUD_SHIFT
67650+#define PTRS_PER_PMD 1
67651+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
67652+#define PMD_MASK (~(PMD_SIZE-1))
67653+
67654+#ifndef __ASSEMBLY__
67655+
67656+struct mm_struct;
67657+
67658 /*
67659 * Having the pmd type consist of a pud gets the size right, and allows
67660 * us to conceptually access the pud entry that this pmd is folded into
67661@@ -16,11 +21,6 @@ struct mm_struct;
67662 */
67663 typedef struct { pud_t pud; } pmd_t;
67664
67665-#define PMD_SHIFT PUD_SHIFT
67666-#define PTRS_PER_PMD 1
67667-#define PMD_SIZE (1UL << PMD_SHIFT)
67668-#define PMD_MASK (~(PMD_SIZE-1))
67669-
67670 /*
67671 * The "pud_xxx()" functions here are trivial for a folded two-level
67672 * setup: the pmd is never bad, and a pmd always exists (as it's folded
67673diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
67674index 810431d..0ec4804f 100644
67675--- a/include/asm-generic/pgtable-nopud.h
67676+++ b/include/asm-generic/pgtable-nopud.h
67677@@ -1,10 +1,15 @@
67678 #ifndef _PGTABLE_NOPUD_H
67679 #define _PGTABLE_NOPUD_H
67680
67681-#ifndef __ASSEMBLY__
67682-
67683 #define __PAGETABLE_PUD_FOLDED
67684
67685+#define PUD_SHIFT PGDIR_SHIFT
67686+#define PTRS_PER_PUD 1
67687+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
67688+#define PUD_MASK (~(PUD_SIZE-1))
67689+
67690+#ifndef __ASSEMBLY__
67691+
67692 /*
67693 * Having the pud type consist of a pgd gets the size right, and allows
67694 * us to conceptually access the pgd entry that this pud is folded into
67695@@ -12,11 +17,6 @@
67696 */
67697 typedef struct { pgd_t pgd; } pud_t;
67698
67699-#define PUD_SHIFT PGDIR_SHIFT
67700-#define PTRS_PER_PUD 1
67701-#define PUD_SIZE (1UL << PUD_SHIFT)
67702-#define PUD_MASK (~(PUD_SIZE-1))
67703-
67704 /*
67705 * The "pgd_xxx()" functions here are trivial for a folded two-level
67706 * setup: the pud is never bad, and a pud always exists (as it's folded
67707@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
67708 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
67709
67710 #define pgd_populate(mm, pgd, pud) do { } while (0)
67711+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
67712 /*
67713 * (puds are folded into pgds so this doesn't get actually called,
67714 * but the define is needed for a generic inline function.)
67715diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
67716index a59ff51..2594a70 100644
67717--- a/include/asm-generic/pgtable.h
67718+++ b/include/asm-generic/pgtable.h
67719@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
67720 }
67721 #endif /* CONFIG_NUMA_BALANCING */
67722
67723+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
67724+static inline unsigned long pax_open_kernel(void) { return 0; }
67725+#endif
67726+
67727+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
67728+static inline unsigned long pax_close_kernel(void) { return 0; }
67729+#endif
67730+
67731 #endif /* CONFIG_MMU */
67732
67733 #endif /* !__ASSEMBLY__ */
67734diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
67735index eb58d2d..df131bf 100644
67736--- a/include/asm-generic/vmlinux.lds.h
67737+++ b/include/asm-generic/vmlinux.lds.h
67738@@ -239,6 +239,7 @@
67739 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
67740 VMLINUX_SYMBOL(__start_rodata) = .; \
67741 *(.rodata) *(.rodata.*) \
67742+ *(.data..read_only) \
67743 *(__vermagic) /* Kernel version magic */ \
67744 . = ALIGN(8); \
67745 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
67746@@ -749,17 +750,18 @@
67747 * section in the linker script will go there too. @phdr should have
67748 * a leading colon.
67749 *
67750- * Note that this macros defines __per_cpu_load as an absolute symbol.
67751+ * Note that this macros defines per_cpu_load as an absolute symbol.
67752 * If there is no need to put the percpu section at a predetermined
67753 * address, use PERCPU_SECTION.
67754 */
67755 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
67756- VMLINUX_SYMBOL(__per_cpu_load) = .; \
67757- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
67758+ per_cpu_load = .; \
67759+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
67760 - LOAD_OFFSET) { \
67761+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
67762 PERCPU_INPUT(cacheline) \
67763 } phdr \
67764- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
67765+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
67766
67767 /**
67768 * PERCPU_SECTION - define output section for percpu area, simple version
67769diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
67770index 418d270..bfd2794 100644
67771--- a/include/crypto/algapi.h
67772+++ b/include/crypto/algapi.h
67773@@ -34,7 +34,7 @@ struct crypto_type {
67774 unsigned int maskclear;
67775 unsigned int maskset;
67776 unsigned int tfmsize;
67777-};
67778+} __do_const;
67779
67780 struct crypto_instance {
67781 struct crypto_alg alg;
67782diff --git a/include/drm/drmP.h b/include/drm/drmP.h
67783index 63d17ee..716de2b 100644
67784--- a/include/drm/drmP.h
67785+++ b/include/drm/drmP.h
67786@@ -72,6 +72,7 @@
67787 #include <linux/workqueue.h>
67788 #include <linux/poll.h>
67789 #include <asm/pgalloc.h>
67790+#include <asm/local.h>
67791 #include <drm/drm.h>
67792 #include <drm/drm_sarea.h>
67793
67794@@ -296,10 +297,12 @@ do { \
67795 * \param cmd command.
67796 * \param arg argument.
67797 */
67798-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
67799+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
67800+ struct drm_file *file_priv);
67801+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
67802 struct drm_file *file_priv);
67803
67804-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67805+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
67806 unsigned long arg);
67807
67808 #define DRM_IOCTL_NR(n) _IOC_NR(n)
67809@@ -314,10 +317,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67810 struct drm_ioctl_desc {
67811 unsigned int cmd;
67812 int flags;
67813- drm_ioctl_t *func;
67814+ drm_ioctl_t func;
67815 unsigned int cmd_drv;
67816 const char *name;
67817-};
67818+} __do_const;
67819
67820 /**
67821 * Creates a driver or general drm_ioctl_desc array entry for the given
67822@@ -1015,7 +1018,7 @@ struct drm_info_list {
67823 int (*show)(struct seq_file*, void*); /** show callback */
67824 u32 driver_features; /**< Required driver features for this entry */
67825 void *data;
67826-};
67827+} __do_const;
67828
67829 /**
67830 * debugfs node structure. This structure represents a debugfs file.
67831@@ -1088,7 +1091,7 @@ struct drm_device {
67832
67833 /** \name Usage Counters */
67834 /*@{ */
67835- int open_count; /**< Outstanding files open */
67836+ local_t open_count; /**< Outstanding files open */
67837 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
67838 atomic_t vma_count; /**< Outstanding vma areas open */
67839 int buf_use; /**< Buffers in use -- cannot alloc */
67840@@ -1099,7 +1102,7 @@ struct drm_device {
67841 /*@{ */
67842 unsigned long counters;
67843 enum drm_stat_type types[15];
67844- atomic_t counts[15];
67845+ atomic_unchecked_t counts[15];
67846 /*@} */
67847
67848 struct list_head filelist;
67849diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
67850index f43d556..94d9343 100644
67851--- a/include/drm/drm_crtc_helper.h
67852+++ b/include/drm/drm_crtc_helper.h
67853@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
67854 struct drm_connector *connector);
67855 /* disable encoder when not in use - more explicit than dpms off */
67856 void (*disable)(struct drm_encoder *encoder);
67857-};
67858+} __no_const;
67859
67860 /**
67861 * drm_connector_helper_funcs - helper operations for connectors
67862diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
67863index 72dcbe8..8db58d7 100644
67864--- a/include/drm/ttm/ttm_memory.h
67865+++ b/include/drm/ttm/ttm_memory.h
67866@@ -48,7 +48,7 @@
67867
67868 struct ttm_mem_shrink {
67869 int (*do_shrink) (struct ttm_mem_shrink *);
67870-};
67871+} __no_const;
67872
67873 /**
67874 * struct ttm_mem_global - Global memory accounting structure.
67875diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
67876index 4b840e8..155d235 100644
67877--- a/include/keys/asymmetric-subtype.h
67878+++ b/include/keys/asymmetric-subtype.h
67879@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
67880 /* Verify the signature on a key of this subtype (optional) */
67881 int (*verify_signature)(const struct key *key,
67882 const struct public_key_signature *sig);
67883-};
67884+} __do_const;
67885
67886 /**
67887 * asymmetric_key_subtype - Get the subtype from an asymmetric key
67888diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
67889index c1da539..1dcec55 100644
67890--- a/include/linux/atmdev.h
67891+++ b/include/linux/atmdev.h
67892@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
67893 #endif
67894
67895 struct k_atm_aal_stats {
67896-#define __HANDLE_ITEM(i) atomic_t i
67897+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67898 __AAL_STAT_ITEMS
67899 #undef __HANDLE_ITEM
67900 };
67901@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
67902 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
67903 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
67904 struct module *owner;
67905-};
67906+} __do_const ;
67907
67908 struct atmphy_ops {
67909 int (*start)(struct atm_dev *dev);
67910diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
67911index 70cf138..cabb82e 100644
67912--- a/include/linux/binfmts.h
67913+++ b/include/linux/binfmts.h
67914@@ -73,8 +73,9 @@ struct linux_binfmt {
67915 int (*load_binary)(struct linux_binprm *);
67916 int (*load_shlib)(struct file *);
67917 int (*core_dump)(struct coredump_params *cprm);
67918+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
67919 unsigned long min_coredump; /* minimal dump size */
67920-};
67921+} __do_const;
67922
67923 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
67924
67925diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
67926index 2fdb4a4..54aad7e 100644
67927--- a/include/linux/blkdev.h
67928+++ b/include/linux/blkdev.h
67929@@ -1526,7 +1526,7 @@ struct block_device_operations {
67930 /* this callback is with swap_lock and sometimes page table lock held */
67931 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
67932 struct module *owner;
67933-};
67934+} __do_const;
67935
67936 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
67937 unsigned long);
67938diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
67939index 7c2e030..b72475d 100644
67940--- a/include/linux/blktrace_api.h
67941+++ b/include/linux/blktrace_api.h
67942@@ -23,7 +23,7 @@ struct blk_trace {
67943 struct dentry *dir;
67944 struct dentry *dropped_file;
67945 struct dentry *msg_file;
67946- atomic_t dropped;
67947+ atomic_unchecked_t dropped;
67948 };
67949
67950 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
67951diff --git a/include/linux/cache.h b/include/linux/cache.h
67952index 4c57065..4307975 100644
67953--- a/include/linux/cache.h
67954+++ b/include/linux/cache.h
67955@@ -16,6 +16,10 @@
67956 #define __read_mostly
67957 #endif
67958
67959+#ifndef __read_only
67960+#define __read_only __read_mostly
67961+#endif
67962+
67963 #ifndef ____cacheline_aligned
67964 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
67965 #endif
67966diff --git a/include/linux/capability.h b/include/linux/capability.h
67967index d9a4f7f4..19f77d6 100644
67968--- a/include/linux/capability.h
67969+++ b/include/linux/capability.h
67970@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
67971 extern bool nsown_capable(int cap);
67972 extern bool inode_capable(const struct inode *inode, int cap);
67973 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
67974+extern bool capable_nolog(int cap);
67975+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
67976+extern bool inode_capable_nolog(const struct inode *inode, int cap);
67977
67978 /* audit system wants to get cap info from files as well */
67979 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
67980
67981+extern int is_privileged_binary(const struct dentry *dentry);
67982+
67983 #endif /* !_LINUX_CAPABILITY_H */
67984diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
67985index 8609d57..86e4d79 100644
67986--- a/include/linux/cdrom.h
67987+++ b/include/linux/cdrom.h
67988@@ -87,7 +87,6 @@ struct cdrom_device_ops {
67989
67990 /* driver specifications */
67991 const int capability; /* capability flags */
67992- int n_minors; /* number of active minor devices */
67993 /* handle uniform packets for scsi type devices (scsi,atapi) */
67994 int (*generic_packet) (struct cdrom_device_info *,
67995 struct packet_command *);
67996diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
67997index 4ce9056..86caac6 100644
67998--- a/include/linux/cleancache.h
67999+++ b/include/linux/cleancache.h
68000@@ -31,7 +31,7 @@ struct cleancache_ops {
68001 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
68002 void (*invalidate_inode)(int, struct cleancache_filekey);
68003 void (*invalidate_fs)(int);
68004-};
68005+} __no_const;
68006
68007 extern struct cleancache_ops *
68008 cleancache_register_ops(struct cleancache_ops *ops);
68009diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
68010index 1186098..f87e53d 100644
68011--- a/include/linux/clk-provider.h
68012+++ b/include/linux/clk-provider.h
68013@@ -132,6 +132,7 @@ struct clk_ops {
68014 unsigned long);
68015 void (*init)(struct clk_hw *hw);
68016 };
68017+typedef struct clk_ops __no_const clk_ops_no_const;
68018
68019 /**
68020 * struct clk_init_data - holds init data that's common to all clocks and is
68021diff --git a/include/linux/compat.h b/include/linux/compat.h
68022index 7f0c1dd..b5729c6 100644
68023--- a/include/linux/compat.h
68024+++ b/include/linux/compat.h
68025@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
68026 compat_size_t __user *len_ptr);
68027
68028 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
68029-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
68030+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
68031 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
68032 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
68033 compat_ssize_t msgsz, int msgflg);
68034@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
68035 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
68036 compat_ulong_t addr, compat_ulong_t data);
68037 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68038- compat_long_t addr, compat_long_t data);
68039+ compat_ulong_t addr, compat_ulong_t data);
68040
68041 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
68042 /*
68043diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
68044index 842de22..7f3a41f 100644
68045--- a/include/linux/compiler-gcc4.h
68046+++ b/include/linux/compiler-gcc4.h
68047@@ -39,9 +39,29 @@
68048 # define __compiletime_warning(message) __attribute__((warning(message)))
68049 # define __compiletime_error(message) __attribute__((error(message)))
68050 #endif /* __CHECKER__ */
68051+
68052+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
68053+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
68054+#define __bos0(ptr) __bos((ptr), 0)
68055+#define __bos1(ptr) __bos((ptr), 1)
68056 #endif /* GCC_VERSION >= 40300 */
68057
68058 #if GCC_VERSION >= 40500
68059+
68060+#ifdef CONSTIFY_PLUGIN
68061+#define __no_const __attribute__((no_const))
68062+#define __do_const __attribute__((do_const))
68063+#endif
68064+
68065+#ifdef SIZE_OVERFLOW_PLUGIN
68066+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
68067+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
68068+#endif
68069+
68070+#ifdef LATENT_ENTROPY_PLUGIN
68071+#define __latent_entropy __attribute__((latent_entropy))
68072+#endif
68073+
68074 /*
68075 * Mark a position in code as unreachable. This can be used to
68076 * suppress control flow warnings after asm blocks that transfer
68077diff --git a/include/linux/compiler.h b/include/linux/compiler.h
68078index 92669cd..1771a15 100644
68079--- a/include/linux/compiler.h
68080+++ b/include/linux/compiler.h
68081@@ -5,11 +5,14 @@
68082
68083 #ifdef __CHECKER__
68084 # define __user __attribute__((noderef, address_space(1)))
68085+# define __force_user __force __user
68086 # define __kernel __attribute__((address_space(0)))
68087+# define __force_kernel __force __kernel
68088 # define __safe __attribute__((safe))
68089 # define __force __attribute__((force))
68090 # define __nocast __attribute__((nocast))
68091 # define __iomem __attribute__((noderef, address_space(2)))
68092+# define __force_iomem __force __iomem
68093 # define __must_hold(x) __attribute__((context(x,1,1)))
68094 # define __acquires(x) __attribute__((context(x,0,1)))
68095 # define __releases(x) __attribute__((context(x,1,0)))
68096@@ -17,20 +20,37 @@
68097 # define __release(x) __context__(x,-1)
68098 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
68099 # define __percpu __attribute__((noderef, address_space(3)))
68100+# define __force_percpu __force __percpu
68101 #ifdef CONFIG_SPARSE_RCU_POINTER
68102 # define __rcu __attribute__((noderef, address_space(4)))
68103+# define __force_rcu __force __rcu
68104 #else
68105 # define __rcu
68106+# define __force_rcu
68107 #endif
68108 extern void __chk_user_ptr(const volatile void __user *);
68109 extern void __chk_io_ptr(const volatile void __iomem *);
68110 #else
68111-# define __user
68112-# define __kernel
68113+# ifdef CHECKER_PLUGIN
68114+//# define __user
68115+//# define __force_user
68116+//# define __kernel
68117+//# define __force_kernel
68118+# else
68119+# ifdef STRUCTLEAK_PLUGIN
68120+# define __user __attribute__((user))
68121+# else
68122+# define __user
68123+# endif
68124+# define __force_user
68125+# define __kernel
68126+# define __force_kernel
68127+# endif
68128 # define __safe
68129 # define __force
68130 # define __nocast
68131 # define __iomem
68132+# define __force_iomem
68133 # define __chk_user_ptr(x) (void)0
68134 # define __chk_io_ptr(x) (void)0
68135 # define __builtin_warning(x, y...) (1)
68136@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
68137 # define __release(x) (void)0
68138 # define __cond_lock(x,c) (c)
68139 # define __percpu
68140+# define __force_percpu
68141 # define __rcu
68142+# define __force_rcu
68143 #endif
68144
68145 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
68146@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68147 # define __attribute_const__ /* unimplemented */
68148 #endif
68149
68150+#ifndef __no_const
68151+# define __no_const
68152+#endif
68153+
68154+#ifndef __do_const
68155+# define __do_const
68156+#endif
68157+
68158+#ifndef __size_overflow
68159+# define __size_overflow(...)
68160+#endif
68161+
68162+#ifndef __intentional_overflow
68163+# define __intentional_overflow(...)
68164+#endif
68165+
68166+#ifndef __latent_entropy
68167+# define __latent_entropy
68168+#endif
68169+
68170 /*
68171 * Tell gcc if a function is cold. The compiler will assume any path
68172 * directly leading to the call is unlikely.
68173@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68174 #define __cold
68175 #endif
68176
68177+#ifndef __alloc_size
68178+#define __alloc_size(...)
68179+#endif
68180+
68181+#ifndef __bos
68182+#define __bos(ptr, arg)
68183+#endif
68184+
68185+#ifndef __bos0
68186+#define __bos0(ptr)
68187+#endif
68188+
68189+#ifndef __bos1
68190+#define __bos1(ptr)
68191+#endif
68192+
68193 /* Simple shorthand for a section definition */
68194 #ifndef __section
68195 # define __section(S) __attribute__ ((__section__(#S)))
68196@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68197 * use is to mediate communication between process-level code and irq/NMI
68198 * handlers, all running on the same CPU.
68199 */
68200-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
68201+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
68202+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
68203
68204 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
68205 #ifdef CONFIG_KPROBES
68206diff --git a/include/linux/completion.h b/include/linux/completion.h
68207index 33f0280..35c6568 100644
68208--- a/include/linux/completion.h
68209+++ b/include/linux/completion.h
68210@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
68211 extern void wait_for_completion(struct completion *);
68212 extern void wait_for_completion_io(struct completion *);
68213 extern int wait_for_completion_interruptible(struct completion *x);
68214-extern int wait_for_completion_killable(struct completion *x);
68215+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
68216 extern unsigned long wait_for_completion_timeout(struct completion *x,
68217 unsigned long timeout);
68218 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
68219 unsigned long timeout);
68220 extern long wait_for_completion_interruptible_timeout(
68221- struct completion *x, unsigned long timeout);
68222+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68223 extern long wait_for_completion_killable_timeout(
68224- struct completion *x, unsigned long timeout);
68225+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68226 extern bool try_wait_for_completion(struct completion *x);
68227 extern bool completion_done(struct completion *x);
68228
68229diff --git a/include/linux/configfs.h b/include/linux/configfs.h
68230index 34025df..d94bbbc 100644
68231--- a/include/linux/configfs.h
68232+++ b/include/linux/configfs.h
68233@@ -125,7 +125,7 @@ struct configfs_attribute {
68234 const char *ca_name;
68235 struct module *ca_owner;
68236 umode_t ca_mode;
68237-};
68238+} __do_const;
68239
68240 /*
68241 * Users often need to create attribute structures for their configurable
68242diff --git a/include/linux/cpu.h b/include/linux/cpu.h
68243index 9f3c7e8..a18c7b6 100644
68244--- a/include/linux/cpu.h
68245+++ b/include/linux/cpu.h
68246@@ -115,7 +115,7 @@ enum {
68247 /* Need to know about CPUs going up/down? */
68248 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
68249 #define cpu_notifier(fn, pri) { \
68250- static struct notifier_block fn##_nb __cpuinitdata = \
68251+ static struct notifier_block fn##_nb = \
68252 { .notifier_call = fn, .priority = pri }; \
68253 register_cpu_notifier(&fn##_nb); \
68254 }
68255diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
68256index 037d36a..ca5fe6e 100644
68257--- a/include/linux/cpufreq.h
68258+++ b/include/linux/cpufreq.h
68259@@ -262,7 +262,7 @@ struct cpufreq_driver {
68260 int (*suspend) (struct cpufreq_policy *policy);
68261 int (*resume) (struct cpufreq_policy *policy);
68262 struct freq_attr **attr;
68263-};
68264+} __do_const;
68265
68266 /* flags */
68267
68268@@ -321,6 +321,7 @@ struct global_attr {
68269 ssize_t (*store)(struct kobject *a, struct attribute *b,
68270 const char *c, size_t count);
68271 };
68272+typedef struct global_attr __no_const global_attr_no_const;
68273
68274 #define define_one_global_ro(_name) \
68275 static struct global_attr _name = \
68276diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
68277index 8f04062..900239a 100644
68278--- a/include/linux/cpuidle.h
68279+++ b/include/linux/cpuidle.h
68280@@ -52,7 +52,8 @@ struct cpuidle_state {
68281 int index);
68282
68283 int (*enter_dead) (struct cpuidle_device *dev, int index);
68284-};
68285+} __do_const;
68286+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
68287
68288 /* Idle State Flags */
68289 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
68290@@ -191,7 +192,7 @@ struct cpuidle_governor {
68291 void (*reflect) (struct cpuidle_device *dev, int index);
68292
68293 struct module *owner;
68294-};
68295+} __do_const;
68296
68297 #ifdef CONFIG_CPU_IDLE
68298
68299diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
68300index d08e4d2..95fad61 100644
68301--- a/include/linux/cpumask.h
68302+++ b/include/linux/cpumask.h
68303@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68304 }
68305
68306 /* Valid inputs for n are -1 and 0. */
68307-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68308+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68309 {
68310 return n+1;
68311 }
68312
68313-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68314+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68315 {
68316 return n+1;
68317 }
68318
68319-static inline unsigned int cpumask_next_and(int n,
68320+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
68321 const struct cpumask *srcp,
68322 const struct cpumask *andp)
68323 {
68324@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68325 *
68326 * Returns >= nr_cpu_ids if no further cpus set.
68327 */
68328-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68329+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68330 {
68331 /* -1 is a legal arg here. */
68332 if (n != -1)
68333@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68334 *
68335 * Returns >= nr_cpu_ids if no further cpus unset.
68336 */
68337-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68338+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68339 {
68340 /* -1 is a legal arg here. */
68341 if (n != -1)
68342@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68343 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
68344 }
68345
68346-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
68347+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
68348 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
68349
68350 /**
68351diff --git a/include/linux/cred.h b/include/linux/cred.h
68352index 04421e8..6bce4ef 100644
68353--- a/include/linux/cred.h
68354+++ b/include/linux/cred.h
68355@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
68356 static inline void validate_process_creds(void)
68357 {
68358 }
68359+static inline void validate_task_creds(struct task_struct *task)
68360+{
68361+}
68362 #endif
68363
68364 /**
68365diff --git a/include/linux/crypto.h b/include/linux/crypto.h
68366index b92eadf..b4ecdc1 100644
68367--- a/include/linux/crypto.h
68368+++ b/include/linux/crypto.h
68369@@ -373,7 +373,7 @@ struct cipher_tfm {
68370 const u8 *key, unsigned int keylen);
68371 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68372 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68373-};
68374+} __no_const;
68375
68376 struct hash_tfm {
68377 int (*init)(struct hash_desc *desc);
68378@@ -394,13 +394,13 @@ struct compress_tfm {
68379 int (*cot_decompress)(struct crypto_tfm *tfm,
68380 const u8 *src, unsigned int slen,
68381 u8 *dst, unsigned int *dlen);
68382-};
68383+} __no_const;
68384
68385 struct rng_tfm {
68386 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
68387 unsigned int dlen);
68388 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
68389-};
68390+} __no_const;
68391
68392 #define crt_ablkcipher crt_u.ablkcipher
68393 #define crt_aead crt_u.aead
68394diff --git a/include/linux/ctype.h b/include/linux/ctype.h
68395index 653589e..4ef254a 100644
68396--- a/include/linux/ctype.h
68397+++ b/include/linux/ctype.h
68398@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
68399 * Fast implementation of tolower() for internal usage. Do not use in your
68400 * code.
68401 */
68402-static inline char _tolower(const char c)
68403+static inline unsigned char _tolower(const unsigned char c)
68404 {
68405 return c | 0x20;
68406 }
68407diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
68408index 7925bf0..d5143d2 100644
68409--- a/include/linux/decompress/mm.h
68410+++ b/include/linux/decompress/mm.h
68411@@ -77,7 +77,7 @@ static void free(void *where)
68412 * warnings when not needed (indeed large_malloc / large_free are not
68413 * needed by inflate */
68414
68415-#define malloc(a) kmalloc(a, GFP_KERNEL)
68416+#define malloc(a) kmalloc((a), GFP_KERNEL)
68417 #define free(a) kfree(a)
68418
68419 #define large_malloc(a) vmalloc(a)
68420diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
68421index fe8c447..bdc1f33 100644
68422--- a/include/linux/devfreq.h
68423+++ b/include/linux/devfreq.h
68424@@ -114,7 +114,7 @@ struct devfreq_governor {
68425 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
68426 int (*event_handler)(struct devfreq *devfreq,
68427 unsigned int event, void *data);
68428-};
68429+} __do_const;
68430
68431 /**
68432 * struct devfreq - Device devfreq structure
68433diff --git a/include/linux/device.h b/include/linux/device.h
68434index c0a1261..dba7569 100644
68435--- a/include/linux/device.h
68436+++ b/include/linux/device.h
68437@@ -290,7 +290,7 @@ struct subsys_interface {
68438 struct list_head node;
68439 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
68440 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
68441-};
68442+} __do_const;
68443
68444 int subsys_interface_register(struct subsys_interface *sif);
68445 void subsys_interface_unregister(struct subsys_interface *sif);
68446@@ -473,7 +473,7 @@ struct device_type {
68447 void (*release)(struct device *dev);
68448
68449 const struct dev_pm_ops *pm;
68450-};
68451+} __do_const;
68452
68453 /* interface for exporting device attributes */
68454 struct device_attribute {
68455@@ -483,11 +483,12 @@ struct device_attribute {
68456 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
68457 const char *buf, size_t count);
68458 };
68459+typedef struct device_attribute __no_const device_attribute_no_const;
68460
68461 struct dev_ext_attribute {
68462 struct device_attribute attr;
68463 void *var;
68464-};
68465+} __do_const;
68466
68467 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
68468 char *buf);
68469diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
68470index 94af418..b1ca7a2 100644
68471--- a/include/linux/dma-mapping.h
68472+++ b/include/linux/dma-mapping.h
68473@@ -54,7 +54,7 @@ struct dma_map_ops {
68474 u64 (*get_required_mask)(struct device *dev);
68475 #endif
68476 int is_phys;
68477-};
68478+} __do_const;
68479
68480 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
68481
68482diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
68483index 96d3e4a..dc36433 100644
68484--- a/include/linux/dmaengine.h
68485+++ b/include/linux/dmaengine.h
68486@@ -1035,9 +1035,9 @@ struct dma_pinned_list {
68487 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
68488 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
68489
68490-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68491+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68492 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
68493-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68494+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68495 struct dma_pinned_list *pinned_list, struct page *page,
68496 unsigned int offset, size_t len);
68497
68498diff --git a/include/linux/efi.h b/include/linux/efi.h
68499index 2bc0ad7..3f7b006 100644
68500--- a/include/linux/efi.h
68501+++ b/include/linux/efi.h
68502@@ -745,6 +745,7 @@ struct efivar_operations {
68503 efi_set_variable_t *set_variable;
68504 efi_query_variable_store_t *query_variable_store;
68505 };
68506+typedef struct efivar_operations __no_const efivar_operations_no_const;
68507
68508 struct efivars {
68509 /*
68510diff --git a/include/linux/elf.h b/include/linux/elf.h
68511index 40a3c0e..4c45a38 100644
68512--- a/include/linux/elf.h
68513+++ b/include/linux/elf.h
68514@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
68515 #define elf_note elf32_note
68516 #define elf_addr_t Elf32_Off
68517 #define Elf_Half Elf32_Half
68518+#define elf_dyn Elf32_Dyn
68519
68520 #else
68521
68522@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
68523 #define elf_note elf64_note
68524 #define elf_addr_t Elf64_Off
68525 #define Elf_Half Elf64_Half
68526+#define elf_dyn Elf64_Dyn
68527
68528 #endif
68529
68530diff --git a/include/linux/err.h b/include/linux/err.h
68531index f2edce2..cc2082c 100644
68532--- a/include/linux/err.h
68533+++ b/include/linux/err.h
68534@@ -19,12 +19,12 @@
68535
68536 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
68537
68538-static inline void * __must_check ERR_PTR(long error)
68539+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
68540 {
68541 return (void *) error;
68542 }
68543
68544-static inline long __must_check PTR_ERR(const void *ptr)
68545+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
68546 {
68547 return (long) ptr;
68548 }
68549diff --git a/include/linux/extcon.h b/include/linux/extcon.h
68550index fcb51c8..bdafcf6 100644
68551--- a/include/linux/extcon.h
68552+++ b/include/linux/extcon.h
68553@@ -134,7 +134,7 @@ struct extcon_dev {
68554 /* /sys/class/extcon/.../mutually_exclusive/... */
68555 struct attribute_group attr_g_muex;
68556 struct attribute **attrs_muex;
68557- struct device_attribute *d_attrs_muex;
68558+ device_attribute_no_const *d_attrs_muex;
68559 };
68560
68561 /**
68562diff --git a/include/linux/fb.h b/include/linux/fb.h
68563index d49c60f..2834fbe 100644
68564--- a/include/linux/fb.h
68565+++ b/include/linux/fb.h
68566@@ -304,7 +304,7 @@ struct fb_ops {
68567 /* called at KDB enter and leave time to prepare the console */
68568 int (*fb_debug_enter)(struct fb_info *info);
68569 int (*fb_debug_leave)(struct fb_info *info);
68570-};
68571+} __do_const;
68572
68573 #ifdef CONFIG_FB_TILEBLITTING
68574 #define FB_TILE_CURSOR_NONE 0
68575diff --git a/include/linux/filter.h b/include/linux/filter.h
68576index f65f5a6..2f4f93a 100644
68577--- a/include/linux/filter.h
68578+++ b/include/linux/filter.h
68579@@ -20,6 +20,7 @@ struct compat_sock_fprog {
68580
68581 struct sk_buff;
68582 struct sock;
68583+struct bpf_jit_work;
68584
68585 struct sk_filter
68586 {
68587@@ -27,6 +28,9 @@ struct sk_filter
68588 unsigned int len; /* Number of filter blocks */
68589 unsigned int (*bpf_func)(const struct sk_buff *skb,
68590 const struct sock_filter *filter);
68591+#ifdef CONFIG_BPF_JIT
68592+ struct bpf_jit_work *work;
68593+#endif
68594 struct rcu_head rcu;
68595 struct sock_filter insns[0];
68596 };
68597diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
68598index 8293262..2b3b8bd 100644
68599--- a/include/linux/frontswap.h
68600+++ b/include/linux/frontswap.h
68601@@ -11,7 +11,7 @@ struct frontswap_ops {
68602 int (*load)(unsigned, pgoff_t, struct page *);
68603 void (*invalidate_page)(unsigned, pgoff_t);
68604 void (*invalidate_area)(unsigned);
68605-};
68606+} __no_const;
68607
68608 extern bool frontswap_enabled;
68609 extern struct frontswap_ops *
68610diff --git a/include/linux/fs.h b/include/linux/fs.h
68611index 65c2be2..4c53f6e 100644
68612--- a/include/linux/fs.h
68613+++ b/include/linux/fs.h
68614@@ -1543,7 +1543,8 @@ struct file_operations {
68615 long (*fallocate)(struct file *file, int mode, loff_t offset,
68616 loff_t len);
68617 int (*show_fdinfo)(struct seq_file *m, struct file *f);
68618-};
68619+} __do_const;
68620+typedef struct file_operations __no_const file_operations_no_const;
68621
68622 struct inode_operations {
68623 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
68624@@ -2688,4 +2689,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
68625 inode->i_flags |= S_NOSEC;
68626 }
68627
68628+static inline bool is_sidechannel_device(const struct inode *inode)
68629+{
68630+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
68631+ umode_t mode = inode->i_mode;
68632+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
68633+#else
68634+ return false;
68635+#endif
68636+}
68637+
68638 #endif /* _LINUX_FS_H */
68639diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
68640index 2b93a9a..855d94a 100644
68641--- a/include/linux/fs_struct.h
68642+++ b/include/linux/fs_struct.h
68643@@ -6,7 +6,7 @@
68644 #include <linux/seqlock.h>
68645
68646 struct fs_struct {
68647- int users;
68648+ atomic_t users;
68649 spinlock_t lock;
68650 seqcount_t seq;
68651 int umask;
68652diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
68653index 5dfa0aa..6acf322 100644
68654--- a/include/linux/fscache-cache.h
68655+++ b/include/linux/fscache-cache.h
68656@@ -112,7 +112,7 @@ struct fscache_operation {
68657 fscache_operation_release_t release;
68658 };
68659
68660-extern atomic_t fscache_op_debug_id;
68661+extern atomic_unchecked_t fscache_op_debug_id;
68662 extern void fscache_op_work_func(struct work_struct *work);
68663
68664 extern void fscache_enqueue_operation(struct fscache_operation *);
68665@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
68666 INIT_WORK(&op->work, fscache_op_work_func);
68667 atomic_set(&op->usage, 1);
68668 op->state = FSCACHE_OP_ST_INITIALISED;
68669- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
68670+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
68671 op->processor = processor;
68672 op->release = release;
68673 INIT_LIST_HEAD(&op->pend_link);
68674diff --git a/include/linux/fscache.h b/include/linux/fscache.h
68675index 7a08623..4c07b0f 100644
68676--- a/include/linux/fscache.h
68677+++ b/include/linux/fscache.h
68678@@ -152,7 +152,7 @@ struct fscache_cookie_def {
68679 * - this is mandatory for any object that may have data
68680 */
68681 void (*now_uncached)(void *cookie_netfs_data);
68682-};
68683+} __do_const;
68684
68685 /*
68686 * fscache cached network filesystem type
68687diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
68688index a78680a..87bd73e 100644
68689--- a/include/linux/fsnotify.h
68690+++ b/include/linux/fsnotify.h
68691@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
68692 struct inode *inode = path->dentry->d_inode;
68693 __u32 mask = FS_ACCESS;
68694
68695+ if (is_sidechannel_device(inode))
68696+ return;
68697+
68698 if (S_ISDIR(inode->i_mode))
68699 mask |= FS_ISDIR;
68700
68701@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
68702 struct inode *inode = path->dentry->d_inode;
68703 __u32 mask = FS_MODIFY;
68704
68705+ if (is_sidechannel_device(inode))
68706+ return;
68707+
68708 if (S_ISDIR(inode->i_mode))
68709 mask |= FS_ISDIR;
68710
68711@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
68712 */
68713 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
68714 {
68715- return kstrdup(name, GFP_KERNEL);
68716+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
68717 }
68718
68719 /*
68720diff --git a/include/linux/genhd.h b/include/linux/genhd.h
68721index 9f3c275..911b591 100644
68722--- a/include/linux/genhd.h
68723+++ b/include/linux/genhd.h
68724@@ -194,7 +194,7 @@ struct gendisk {
68725 struct kobject *slave_dir;
68726
68727 struct timer_rand_state *random;
68728- atomic_t sync_io; /* RAID */
68729+ atomic_unchecked_t sync_io; /* RAID */
68730 struct disk_events *ev;
68731 #ifdef CONFIG_BLK_DEV_INTEGRITY
68732 struct blk_integrity *integrity;
68733diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
68734index 023bc34..b02b46a 100644
68735--- a/include/linux/genl_magic_func.h
68736+++ b/include/linux/genl_magic_func.h
68737@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
68738 },
68739
68740 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
68741-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
68742+static struct genl_ops ZZZ_genl_ops[] = {
68743 #include GENL_MAGIC_INCLUDE_FILE
68744 };
68745
68746diff --git a/include/linux/gfp.h b/include/linux/gfp.h
68747index 0f615eb..5c3832f 100644
68748--- a/include/linux/gfp.h
68749+++ b/include/linux/gfp.h
68750@@ -35,6 +35,13 @@ struct vm_area_struct;
68751 #define ___GFP_NO_KSWAPD 0x400000u
68752 #define ___GFP_OTHER_NODE 0x800000u
68753 #define ___GFP_WRITE 0x1000000u
68754+
68755+#ifdef CONFIG_PAX_USERCOPY_SLABS
68756+#define ___GFP_USERCOPY 0x2000000u
68757+#else
68758+#define ___GFP_USERCOPY 0
68759+#endif
68760+
68761 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
68762
68763 /*
68764@@ -92,6 +99,7 @@ struct vm_area_struct;
68765 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
68766 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
68767 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
68768+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
68769
68770 /*
68771 * This may seem redundant, but it's a way of annotating false positives vs.
68772@@ -99,7 +107,7 @@ struct vm_area_struct;
68773 */
68774 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
68775
68776-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
68777+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
68778 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
68779
68780 /* This equals 0, but use constants in case they ever change */
68781@@ -153,6 +161,8 @@ struct vm_area_struct;
68782 /* 4GB DMA on some platforms */
68783 #define GFP_DMA32 __GFP_DMA32
68784
68785+#define GFP_USERCOPY __GFP_USERCOPY
68786+
68787 /* Convert GFP flags to their corresponding migrate type */
68788 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
68789 {
68790diff --git a/include/linux/gracl.h b/include/linux/gracl.h
68791new file mode 100644
68792index 0000000..ebe6d72
68793--- /dev/null
68794+++ b/include/linux/gracl.h
68795@@ -0,0 +1,319 @@
68796+#ifndef GR_ACL_H
68797+#define GR_ACL_H
68798+
68799+#include <linux/grdefs.h>
68800+#include <linux/resource.h>
68801+#include <linux/capability.h>
68802+#include <linux/dcache.h>
68803+#include <asm/resource.h>
68804+
68805+/* Major status information */
68806+
68807+#define GR_VERSION "grsecurity 2.9.1"
68808+#define GRSECURITY_VERSION 0x2901
68809+
68810+enum {
68811+ GR_SHUTDOWN = 0,
68812+ GR_ENABLE = 1,
68813+ GR_SPROLE = 2,
68814+ GR_RELOAD = 3,
68815+ GR_SEGVMOD = 4,
68816+ GR_STATUS = 5,
68817+ GR_UNSPROLE = 6,
68818+ GR_PASSSET = 7,
68819+ GR_SPROLEPAM = 8,
68820+};
68821+
68822+/* Password setup definitions
68823+ * kernel/grhash.c */
68824+enum {
68825+ GR_PW_LEN = 128,
68826+ GR_SALT_LEN = 16,
68827+ GR_SHA_LEN = 32,
68828+};
68829+
68830+enum {
68831+ GR_SPROLE_LEN = 64,
68832+};
68833+
68834+enum {
68835+ GR_NO_GLOB = 0,
68836+ GR_REG_GLOB,
68837+ GR_CREATE_GLOB
68838+};
68839+
68840+#define GR_NLIMITS 32
68841+
68842+/* Begin Data Structures */
68843+
68844+struct sprole_pw {
68845+ unsigned char *rolename;
68846+ unsigned char salt[GR_SALT_LEN];
68847+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
68848+};
68849+
68850+struct name_entry {
68851+ __u32 key;
68852+ ino_t inode;
68853+ dev_t device;
68854+ char *name;
68855+ __u16 len;
68856+ __u8 deleted;
68857+ struct name_entry *prev;
68858+ struct name_entry *next;
68859+};
68860+
68861+struct inodev_entry {
68862+ struct name_entry *nentry;
68863+ struct inodev_entry *prev;
68864+ struct inodev_entry *next;
68865+};
68866+
68867+struct acl_role_db {
68868+ struct acl_role_label **r_hash;
68869+ __u32 r_size;
68870+};
68871+
68872+struct inodev_db {
68873+ struct inodev_entry **i_hash;
68874+ __u32 i_size;
68875+};
68876+
68877+struct name_db {
68878+ struct name_entry **n_hash;
68879+ __u32 n_size;
68880+};
68881+
68882+struct crash_uid {
68883+ uid_t uid;
68884+ unsigned long expires;
68885+};
68886+
68887+struct gr_hash_struct {
68888+ void **table;
68889+ void **nametable;
68890+ void *first;
68891+ __u32 table_size;
68892+ __u32 used_size;
68893+ int type;
68894+};
68895+
68896+/* Userspace Grsecurity ACL data structures */
68897+
68898+struct acl_subject_label {
68899+ char *filename;
68900+ ino_t inode;
68901+ dev_t device;
68902+ __u32 mode;
68903+ kernel_cap_t cap_mask;
68904+ kernel_cap_t cap_lower;
68905+ kernel_cap_t cap_invert_audit;
68906+
68907+ struct rlimit res[GR_NLIMITS];
68908+ __u32 resmask;
68909+
68910+ __u8 user_trans_type;
68911+ __u8 group_trans_type;
68912+ uid_t *user_transitions;
68913+ gid_t *group_transitions;
68914+ __u16 user_trans_num;
68915+ __u16 group_trans_num;
68916+
68917+ __u32 sock_families[2];
68918+ __u32 ip_proto[8];
68919+ __u32 ip_type;
68920+ struct acl_ip_label **ips;
68921+ __u32 ip_num;
68922+ __u32 inaddr_any_override;
68923+
68924+ __u32 crashes;
68925+ unsigned long expires;
68926+
68927+ struct acl_subject_label *parent_subject;
68928+ struct gr_hash_struct *hash;
68929+ struct acl_subject_label *prev;
68930+ struct acl_subject_label *next;
68931+
68932+ struct acl_object_label **obj_hash;
68933+ __u32 obj_hash_size;
68934+ __u16 pax_flags;
68935+};
68936+
68937+struct role_allowed_ip {
68938+ __u32 addr;
68939+ __u32 netmask;
68940+
68941+ struct role_allowed_ip *prev;
68942+ struct role_allowed_ip *next;
68943+};
68944+
68945+struct role_transition {
68946+ char *rolename;
68947+
68948+ struct role_transition *prev;
68949+ struct role_transition *next;
68950+};
68951+
68952+struct acl_role_label {
68953+ char *rolename;
68954+ uid_t uidgid;
68955+ __u16 roletype;
68956+
68957+ __u16 auth_attempts;
68958+ unsigned long expires;
68959+
68960+ struct acl_subject_label *root_label;
68961+ struct gr_hash_struct *hash;
68962+
68963+ struct acl_role_label *prev;
68964+ struct acl_role_label *next;
68965+
68966+ struct role_transition *transitions;
68967+ struct role_allowed_ip *allowed_ips;
68968+ uid_t *domain_children;
68969+ __u16 domain_child_num;
68970+
68971+ umode_t umask;
68972+
68973+ struct acl_subject_label **subj_hash;
68974+ __u32 subj_hash_size;
68975+};
68976+
68977+struct user_acl_role_db {
68978+ struct acl_role_label **r_table;
68979+ __u32 num_pointers; /* Number of allocations to track */
68980+ __u32 num_roles; /* Number of roles */
68981+ __u32 num_domain_children; /* Number of domain children */
68982+ __u32 num_subjects; /* Number of subjects */
68983+ __u32 num_objects; /* Number of objects */
68984+};
68985+
68986+struct acl_object_label {
68987+ char *filename;
68988+ ino_t inode;
68989+ dev_t device;
68990+ __u32 mode;
68991+
68992+ struct acl_subject_label *nested;
68993+ struct acl_object_label *globbed;
68994+
68995+ /* next two structures not used */
68996+
68997+ struct acl_object_label *prev;
68998+ struct acl_object_label *next;
68999+};
69000+
69001+struct acl_ip_label {
69002+ char *iface;
69003+ __u32 addr;
69004+ __u32 netmask;
69005+ __u16 low, high;
69006+ __u8 mode;
69007+ __u32 type;
69008+ __u32 proto[8];
69009+
69010+ /* next two structures not used */
69011+
69012+ struct acl_ip_label *prev;
69013+ struct acl_ip_label *next;
69014+};
69015+
69016+struct gr_arg {
69017+ struct user_acl_role_db role_db;
69018+ unsigned char pw[GR_PW_LEN];
69019+ unsigned char salt[GR_SALT_LEN];
69020+ unsigned char sum[GR_SHA_LEN];
69021+ unsigned char sp_role[GR_SPROLE_LEN];
69022+ struct sprole_pw *sprole_pws;
69023+ dev_t segv_device;
69024+ ino_t segv_inode;
69025+ uid_t segv_uid;
69026+ __u16 num_sprole_pws;
69027+ __u16 mode;
69028+};
69029+
69030+struct gr_arg_wrapper {
69031+ struct gr_arg *arg;
69032+ __u32 version;
69033+ __u32 size;
69034+};
69035+
69036+struct subject_map {
69037+ struct acl_subject_label *user;
69038+ struct acl_subject_label *kernel;
69039+ struct subject_map *prev;
69040+ struct subject_map *next;
69041+};
69042+
69043+struct acl_subj_map_db {
69044+ struct subject_map **s_hash;
69045+ __u32 s_size;
69046+};
69047+
69048+/* End Data Structures Section */
69049+
69050+/* Hash functions generated by empirical testing by Brad Spengler
69051+ Makes good use of the low bits of the inode. Generally 0-1 times
69052+ in loop for successful match. 0-3 for unsuccessful match.
69053+ Shift/add algorithm with modulus of table size and an XOR*/
69054+
69055+static __inline__ unsigned int
69056+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
69057+{
69058+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
69059+}
69060+
69061+ static __inline__ unsigned int
69062+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
69063+{
69064+ return ((const unsigned long)userp % sz);
69065+}
69066+
69067+static __inline__ unsigned int
69068+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
69069+{
69070+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
69071+}
69072+
69073+static __inline__ unsigned int
69074+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
69075+{
69076+ return full_name_hash((const unsigned char *)name, len) % sz;
69077+}
69078+
69079+#define FOR_EACH_ROLE_START(role) \
69080+ role = role_list; \
69081+ while (role) {
69082+
69083+#define FOR_EACH_ROLE_END(role) \
69084+ role = role->prev; \
69085+ }
69086+
69087+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
69088+ subj = NULL; \
69089+ iter = 0; \
69090+ while (iter < role->subj_hash_size) { \
69091+ if (subj == NULL) \
69092+ subj = role->subj_hash[iter]; \
69093+ if (subj == NULL) { \
69094+ iter++; \
69095+ continue; \
69096+ }
69097+
69098+#define FOR_EACH_SUBJECT_END(subj,iter) \
69099+ subj = subj->next; \
69100+ if (subj == NULL) \
69101+ iter++; \
69102+ }
69103+
69104+
69105+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
69106+ subj = role->hash->first; \
69107+ while (subj != NULL) {
69108+
69109+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
69110+ subj = subj->next; \
69111+ }
69112+
69113+#endif
69114+
69115diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
69116new file mode 100644
69117index 0000000..323ecf2
69118--- /dev/null
69119+++ b/include/linux/gralloc.h
69120@@ -0,0 +1,9 @@
69121+#ifndef __GRALLOC_H
69122+#define __GRALLOC_H
69123+
69124+void acl_free_all(void);
69125+int acl_alloc_stack_init(unsigned long size);
69126+void *acl_alloc(unsigned long len);
69127+void *acl_alloc_num(unsigned long num, unsigned long len);
69128+
69129+#endif
69130diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
69131new file mode 100644
69132index 0000000..be66033
69133--- /dev/null
69134+++ b/include/linux/grdefs.h
69135@@ -0,0 +1,140 @@
69136+#ifndef GRDEFS_H
69137+#define GRDEFS_H
69138+
69139+/* Begin grsecurity status declarations */
69140+
69141+enum {
69142+ GR_READY = 0x01,
69143+ GR_STATUS_INIT = 0x00 // disabled state
69144+};
69145+
69146+/* Begin ACL declarations */
69147+
69148+/* Role flags */
69149+
69150+enum {
69151+ GR_ROLE_USER = 0x0001,
69152+ GR_ROLE_GROUP = 0x0002,
69153+ GR_ROLE_DEFAULT = 0x0004,
69154+ GR_ROLE_SPECIAL = 0x0008,
69155+ GR_ROLE_AUTH = 0x0010,
69156+ GR_ROLE_NOPW = 0x0020,
69157+ GR_ROLE_GOD = 0x0040,
69158+ GR_ROLE_LEARN = 0x0080,
69159+ GR_ROLE_TPE = 0x0100,
69160+ GR_ROLE_DOMAIN = 0x0200,
69161+ GR_ROLE_PAM = 0x0400,
69162+ GR_ROLE_PERSIST = 0x0800
69163+};
69164+
69165+/* ACL Subject and Object mode flags */
69166+enum {
69167+ GR_DELETED = 0x80000000
69168+};
69169+
69170+/* ACL Object-only mode flags */
69171+enum {
69172+ GR_READ = 0x00000001,
69173+ GR_APPEND = 0x00000002,
69174+ GR_WRITE = 0x00000004,
69175+ GR_EXEC = 0x00000008,
69176+ GR_FIND = 0x00000010,
69177+ GR_INHERIT = 0x00000020,
69178+ GR_SETID = 0x00000040,
69179+ GR_CREATE = 0x00000080,
69180+ GR_DELETE = 0x00000100,
69181+ GR_LINK = 0x00000200,
69182+ GR_AUDIT_READ = 0x00000400,
69183+ GR_AUDIT_APPEND = 0x00000800,
69184+ GR_AUDIT_WRITE = 0x00001000,
69185+ GR_AUDIT_EXEC = 0x00002000,
69186+ GR_AUDIT_FIND = 0x00004000,
69187+ GR_AUDIT_INHERIT= 0x00008000,
69188+ GR_AUDIT_SETID = 0x00010000,
69189+ GR_AUDIT_CREATE = 0x00020000,
69190+ GR_AUDIT_DELETE = 0x00040000,
69191+ GR_AUDIT_LINK = 0x00080000,
69192+ GR_PTRACERD = 0x00100000,
69193+ GR_NOPTRACE = 0x00200000,
69194+ GR_SUPPRESS = 0x00400000,
69195+ GR_NOLEARN = 0x00800000,
69196+ GR_INIT_TRANSFER= 0x01000000
69197+};
69198+
69199+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
69200+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
69201+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
69202+
69203+/* ACL subject-only mode flags */
69204+enum {
69205+ GR_KILL = 0x00000001,
69206+ GR_VIEW = 0x00000002,
69207+ GR_PROTECTED = 0x00000004,
69208+ GR_LEARN = 0x00000008,
69209+ GR_OVERRIDE = 0x00000010,
69210+ /* just a placeholder, this mode is only used in userspace */
69211+ GR_DUMMY = 0x00000020,
69212+ GR_PROTSHM = 0x00000040,
69213+ GR_KILLPROC = 0x00000080,
69214+ GR_KILLIPPROC = 0x00000100,
69215+ /* just a placeholder, this mode is only used in userspace */
69216+ GR_NOTROJAN = 0x00000200,
69217+ GR_PROTPROCFD = 0x00000400,
69218+ GR_PROCACCT = 0x00000800,
69219+ GR_RELAXPTRACE = 0x00001000,
69220+ //GR_NESTED = 0x00002000,
69221+ GR_INHERITLEARN = 0x00004000,
69222+ GR_PROCFIND = 0x00008000,
69223+ GR_POVERRIDE = 0x00010000,
69224+ GR_KERNELAUTH = 0x00020000,
69225+ GR_ATSECURE = 0x00040000,
69226+ GR_SHMEXEC = 0x00080000
69227+};
69228+
69229+enum {
69230+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
69231+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
69232+ GR_PAX_ENABLE_MPROTECT = 0x0004,
69233+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
69234+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
69235+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
69236+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
69237+ GR_PAX_DISABLE_MPROTECT = 0x0400,
69238+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
69239+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
69240+};
69241+
69242+enum {
69243+ GR_ID_USER = 0x01,
69244+ GR_ID_GROUP = 0x02,
69245+};
69246+
69247+enum {
69248+ GR_ID_ALLOW = 0x01,
69249+ GR_ID_DENY = 0x02,
69250+};
69251+
69252+#define GR_CRASH_RES 31
69253+#define GR_UIDTABLE_MAX 500
69254+
69255+/* begin resource learning section */
69256+enum {
69257+ GR_RLIM_CPU_BUMP = 60,
69258+ GR_RLIM_FSIZE_BUMP = 50000,
69259+ GR_RLIM_DATA_BUMP = 10000,
69260+ GR_RLIM_STACK_BUMP = 1000,
69261+ GR_RLIM_CORE_BUMP = 10000,
69262+ GR_RLIM_RSS_BUMP = 500000,
69263+ GR_RLIM_NPROC_BUMP = 1,
69264+ GR_RLIM_NOFILE_BUMP = 5,
69265+ GR_RLIM_MEMLOCK_BUMP = 50000,
69266+ GR_RLIM_AS_BUMP = 500000,
69267+ GR_RLIM_LOCKS_BUMP = 2,
69268+ GR_RLIM_SIGPENDING_BUMP = 5,
69269+ GR_RLIM_MSGQUEUE_BUMP = 10000,
69270+ GR_RLIM_NICE_BUMP = 1,
69271+ GR_RLIM_RTPRIO_BUMP = 1,
69272+ GR_RLIM_RTTIME_BUMP = 1000000
69273+};
69274+
69275+#endif
69276diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
69277new file mode 100644
69278index 0000000..12994b5
69279--- /dev/null
69280+++ b/include/linux/grinternal.h
69281@@ -0,0 +1,227 @@
69282+#ifndef __GRINTERNAL_H
69283+#define __GRINTERNAL_H
69284+
69285+#ifdef CONFIG_GRKERNSEC
69286+
69287+#include <linux/fs.h>
69288+#include <linux/mnt_namespace.h>
69289+#include <linux/nsproxy.h>
69290+#include <linux/gracl.h>
69291+#include <linux/grdefs.h>
69292+#include <linux/grmsg.h>
69293+
69294+void gr_add_learn_entry(const char *fmt, ...)
69295+ __attribute__ ((format (printf, 1, 2)));
69296+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
69297+ const struct vfsmount *mnt);
69298+__u32 gr_check_create(const struct dentry *new_dentry,
69299+ const struct dentry *parent,
69300+ const struct vfsmount *mnt, const __u32 mode);
69301+int gr_check_protected_task(const struct task_struct *task);
69302+__u32 to_gr_audit(const __u32 reqmode);
69303+int gr_set_acls(const int type);
69304+int gr_apply_subject_to_task(struct task_struct *task);
69305+int gr_acl_is_enabled(void);
69306+char gr_roletype_to_char(void);
69307+
69308+void gr_handle_alertkill(struct task_struct *task);
69309+char *gr_to_filename(const struct dentry *dentry,
69310+ const struct vfsmount *mnt);
69311+char *gr_to_filename1(const struct dentry *dentry,
69312+ const struct vfsmount *mnt);
69313+char *gr_to_filename2(const struct dentry *dentry,
69314+ const struct vfsmount *mnt);
69315+char *gr_to_filename3(const struct dentry *dentry,
69316+ const struct vfsmount *mnt);
69317+
69318+extern int grsec_enable_ptrace_readexec;
69319+extern int grsec_enable_harden_ptrace;
69320+extern int grsec_enable_link;
69321+extern int grsec_enable_fifo;
69322+extern int grsec_enable_execve;
69323+extern int grsec_enable_shm;
69324+extern int grsec_enable_execlog;
69325+extern int grsec_enable_signal;
69326+extern int grsec_enable_audit_ptrace;
69327+extern int grsec_enable_forkfail;
69328+extern int grsec_enable_time;
69329+extern int grsec_enable_rofs;
69330+extern int grsec_enable_chroot_shmat;
69331+extern int grsec_enable_chroot_mount;
69332+extern int grsec_enable_chroot_double;
69333+extern int grsec_enable_chroot_pivot;
69334+extern int grsec_enable_chroot_chdir;
69335+extern int grsec_enable_chroot_chmod;
69336+extern int grsec_enable_chroot_mknod;
69337+extern int grsec_enable_chroot_fchdir;
69338+extern int grsec_enable_chroot_nice;
69339+extern int grsec_enable_chroot_execlog;
69340+extern int grsec_enable_chroot_caps;
69341+extern int grsec_enable_chroot_sysctl;
69342+extern int grsec_enable_chroot_unix;
69343+extern int grsec_enable_symlinkown;
69344+extern kgid_t grsec_symlinkown_gid;
69345+extern int grsec_enable_tpe;
69346+extern kgid_t grsec_tpe_gid;
69347+extern int grsec_enable_tpe_all;
69348+extern int grsec_enable_tpe_invert;
69349+extern int grsec_enable_socket_all;
69350+extern kgid_t grsec_socket_all_gid;
69351+extern int grsec_enable_socket_client;
69352+extern kgid_t grsec_socket_client_gid;
69353+extern int grsec_enable_socket_server;
69354+extern kgid_t grsec_socket_server_gid;
69355+extern kgid_t grsec_audit_gid;
69356+extern int grsec_enable_group;
69357+extern int grsec_enable_audit_textrel;
69358+extern int grsec_enable_log_rwxmaps;
69359+extern int grsec_enable_mount;
69360+extern int grsec_enable_chdir;
69361+extern int grsec_resource_logging;
69362+extern int grsec_enable_blackhole;
69363+extern int grsec_lastack_retries;
69364+extern int grsec_enable_brute;
69365+extern int grsec_lock;
69366+
69367+extern spinlock_t grsec_alert_lock;
69368+extern unsigned long grsec_alert_wtime;
69369+extern unsigned long grsec_alert_fyet;
69370+
69371+extern spinlock_t grsec_audit_lock;
69372+
69373+extern rwlock_t grsec_exec_file_lock;
69374+
69375+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
69376+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
69377+ (tsk)->exec_file->f_path.mnt) : "/")
69378+
69379+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
69380+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
69381+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
69382+
69383+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
69384+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
69385+ (tsk)->exec_file->f_path.mnt) : "/")
69386+
69387+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
69388+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
69389+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
69390+
69391+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
69392+
69393+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
69394+
69395+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
69396+{
69397+ if (file1 && file2) {
69398+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
69399+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
69400+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
69401+ return true;
69402+ }
69403+
69404+ return false;
69405+}
69406+
69407+#define GR_CHROOT_CAPS {{ \
69408+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
69409+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
69410+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
69411+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
69412+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
69413+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
69414+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
69415+
69416+#define security_learn(normal_msg,args...) \
69417+({ \
69418+ read_lock(&grsec_exec_file_lock); \
69419+ gr_add_learn_entry(normal_msg "\n", ## args); \
69420+ read_unlock(&grsec_exec_file_lock); \
69421+})
69422+
69423+enum {
69424+ GR_DO_AUDIT,
69425+ GR_DONT_AUDIT,
69426+ /* used for non-audit messages that we shouldn't kill the task on */
69427+ GR_DONT_AUDIT_GOOD
69428+};
69429+
69430+enum {
69431+ GR_TTYSNIFF,
69432+ GR_RBAC,
69433+ GR_RBAC_STR,
69434+ GR_STR_RBAC,
69435+ GR_RBAC_MODE2,
69436+ GR_RBAC_MODE3,
69437+ GR_FILENAME,
69438+ GR_SYSCTL_HIDDEN,
69439+ GR_NOARGS,
69440+ GR_ONE_INT,
69441+ GR_ONE_INT_TWO_STR,
69442+ GR_ONE_STR,
69443+ GR_STR_INT,
69444+ GR_TWO_STR_INT,
69445+ GR_TWO_INT,
69446+ GR_TWO_U64,
69447+ GR_THREE_INT,
69448+ GR_FIVE_INT_TWO_STR,
69449+ GR_TWO_STR,
69450+ GR_THREE_STR,
69451+ GR_FOUR_STR,
69452+ GR_STR_FILENAME,
69453+ GR_FILENAME_STR,
69454+ GR_FILENAME_TWO_INT,
69455+ GR_FILENAME_TWO_INT_STR,
69456+ GR_TEXTREL,
69457+ GR_PTRACE,
69458+ GR_RESOURCE,
69459+ GR_CAP,
69460+ GR_SIG,
69461+ GR_SIG2,
69462+ GR_CRASH1,
69463+ GR_CRASH2,
69464+ GR_PSACCT,
69465+ GR_RWXMAP
69466+};
69467+
69468+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
69469+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
69470+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
69471+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
69472+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
69473+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
69474+#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)
69475+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
69476+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
69477+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
69478+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
69479+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
69480+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
69481+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
69482+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
69483+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
69484+#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)
69485+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
69486+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
69487+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
69488+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
69489+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
69490+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
69491+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
69492+#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)
69493+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
69494+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
69495+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
69496+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
69497+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
69498+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
69499+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
69500+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
69501+#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)
69502+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
69503+
69504+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
69505+
69506+#endif
69507+
69508+#endif
69509diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
69510new file mode 100644
69511index 0000000..2f159b5
69512--- /dev/null
69513+++ b/include/linux/grmsg.h
69514@@ -0,0 +1,112 @@
69515+#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"
69516+#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"
69517+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
69518+#define GR_STOPMOD_MSG "denied modification of module state by "
69519+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
69520+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
69521+#define GR_IOPERM_MSG "denied use of ioperm() by "
69522+#define GR_IOPL_MSG "denied use of iopl() by "
69523+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
69524+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
69525+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
69526+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
69527+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
69528+#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"
69529+#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"
69530+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
69531+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
69532+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
69533+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
69534+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
69535+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
69536+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
69537+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
69538+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
69539+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
69540+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
69541+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
69542+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
69543+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
69544+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
69545+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
69546+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
69547+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
69548+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
69549+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
69550+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
69551+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
69552+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
69553+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
69554+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
69555+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
69556+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
69557+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
69558+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
69559+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
69560+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
69561+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
69562+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
69563+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
69564+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
69565+#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"
69566+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
69567+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
69568+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
69569+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
69570+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
69571+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
69572+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
69573+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
69574+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
69575+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
69576+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
69577+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
69578+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
69579+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
69580+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
69581+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
69582+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
69583+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
69584+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
69585+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
69586+#define GR_FAILFORK_MSG "failed fork with errno %s by "
69587+#define GR_NICE_CHROOT_MSG "denied priority change by "
69588+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
69589+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
69590+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
69591+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
69592+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
69593+#define GR_TIME_MSG "time set by "
69594+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
69595+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
69596+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
69597+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
69598+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
69599+#define GR_BIND_MSG "denied bind() by "
69600+#define GR_CONNECT_MSG "denied connect() by "
69601+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
69602+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
69603+#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"
69604+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
69605+#define GR_CAP_ACL_MSG "use of %s denied for "
69606+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
69607+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
69608+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
69609+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
69610+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
69611+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
69612+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
69613+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
69614+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
69615+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
69616+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
69617+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
69618+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
69619+#define GR_VM86_MSG "denied use of vm86 by "
69620+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
69621+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
69622+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
69623+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
69624+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
69625+#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 "
69626+#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 "
69627diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
69628new file mode 100644
69629index 0000000..d957f6d
69630--- /dev/null
69631+++ b/include/linux/grsecurity.h
69632@@ -0,0 +1,241 @@
69633+#ifndef GR_SECURITY_H
69634+#define GR_SECURITY_H
69635+#include <linux/fs.h>
69636+#include <linux/fs_struct.h>
69637+#include <linux/binfmts.h>
69638+#include <linux/gracl.h>
69639+
69640+/* notify of brain-dead configs */
69641+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69642+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
69643+#endif
69644+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
69645+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
69646+#endif
69647+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
69648+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
69649+#endif
69650+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
69651+#error "CONFIG_PAX enabled, but no PaX options are enabled."
69652+#endif
69653+
69654+void gr_handle_brute_attach(unsigned long mm_flags);
69655+void gr_handle_brute_check(void);
69656+void gr_handle_kernel_exploit(void);
69657+
69658+char gr_roletype_to_char(void);
69659+
69660+int gr_acl_enable_at_secure(void);
69661+
69662+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
69663+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
69664+
69665+void gr_del_task_from_ip_table(struct task_struct *p);
69666+
69667+int gr_pid_is_chrooted(struct task_struct *p);
69668+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
69669+int gr_handle_chroot_nice(void);
69670+int gr_handle_chroot_sysctl(const int op);
69671+int gr_handle_chroot_setpriority(struct task_struct *p,
69672+ const int niceval);
69673+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
69674+int gr_handle_chroot_chroot(const struct dentry *dentry,
69675+ const struct vfsmount *mnt);
69676+void gr_handle_chroot_chdir(const struct path *path);
69677+int gr_handle_chroot_chmod(const struct dentry *dentry,
69678+ const struct vfsmount *mnt, const int mode);
69679+int gr_handle_chroot_mknod(const struct dentry *dentry,
69680+ const struct vfsmount *mnt, const int mode);
69681+int gr_handle_chroot_mount(const struct dentry *dentry,
69682+ const struct vfsmount *mnt,
69683+ const char *dev_name);
69684+int gr_handle_chroot_pivot(void);
69685+int gr_handle_chroot_unix(const pid_t pid);
69686+
69687+int gr_handle_rawio(const struct inode *inode);
69688+
69689+void gr_handle_ioperm(void);
69690+void gr_handle_iopl(void);
69691+
69692+umode_t gr_acl_umask(void);
69693+
69694+int gr_tpe_allow(const struct file *file);
69695+
69696+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
69697+void gr_clear_chroot_entries(struct task_struct *task);
69698+
69699+void gr_log_forkfail(const int retval);
69700+void gr_log_timechange(void);
69701+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
69702+void gr_log_chdir(const struct dentry *dentry,
69703+ const struct vfsmount *mnt);
69704+void gr_log_chroot_exec(const struct dentry *dentry,
69705+ const struct vfsmount *mnt);
69706+void gr_log_remount(const char *devname, const int retval);
69707+void gr_log_unmount(const char *devname, const int retval);
69708+void gr_log_mount(const char *from, const char *to, const int retval);
69709+void gr_log_textrel(struct vm_area_struct *vma);
69710+void gr_log_rwxmmap(struct file *file);
69711+void gr_log_rwxmprotect(struct file *file);
69712+
69713+int gr_handle_follow_link(const struct inode *parent,
69714+ const struct inode *inode,
69715+ const struct dentry *dentry,
69716+ const struct vfsmount *mnt);
69717+int gr_handle_fifo(const struct dentry *dentry,
69718+ const struct vfsmount *mnt,
69719+ const struct dentry *dir, const int flag,
69720+ const int acc_mode);
69721+int gr_handle_hardlink(const struct dentry *dentry,
69722+ const struct vfsmount *mnt,
69723+ struct inode *inode,
69724+ const int mode, const struct filename *to);
69725+
69726+int gr_is_capable(const int cap);
69727+int gr_is_capable_nolog(const int cap);
69728+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69729+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
69730+
69731+void gr_copy_label(struct task_struct *tsk);
69732+void gr_handle_crash(struct task_struct *task, const int sig);
69733+int gr_handle_signal(const struct task_struct *p, const int sig);
69734+int gr_check_crash_uid(const kuid_t uid);
69735+int gr_check_protected_task(const struct task_struct *task);
69736+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
69737+int gr_acl_handle_mmap(const struct file *file,
69738+ const unsigned long prot);
69739+int gr_acl_handle_mprotect(const struct file *file,
69740+ const unsigned long prot);
69741+int gr_check_hidden_task(const struct task_struct *tsk);
69742+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
69743+ const struct vfsmount *mnt);
69744+__u32 gr_acl_handle_utime(const struct dentry *dentry,
69745+ const struct vfsmount *mnt);
69746+__u32 gr_acl_handle_access(const struct dentry *dentry,
69747+ const struct vfsmount *mnt, const int fmode);
69748+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
69749+ const struct vfsmount *mnt, umode_t *mode);
69750+__u32 gr_acl_handle_chown(const struct dentry *dentry,
69751+ const struct vfsmount *mnt);
69752+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
69753+ const struct vfsmount *mnt);
69754+int gr_handle_ptrace(struct task_struct *task, const long request);
69755+int gr_handle_proc_ptrace(struct task_struct *task);
69756+__u32 gr_acl_handle_execve(const struct dentry *dentry,
69757+ const struct vfsmount *mnt);
69758+int gr_check_crash_exec(const struct file *filp);
69759+int gr_acl_is_enabled(void);
69760+void gr_set_kernel_label(struct task_struct *task);
69761+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
69762+ const kgid_t gid);
69763+int gr_set_proc_label(const struct dentry *dentry,
69764+ const struct vfsmount *mnt,
69765+ const int unsafe_flags);
69766+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
69767+ const struct vfsmount *mnt);
69768+__u32 gr_acl_handle_open(const struct dentry *dentry,
69769+ const struct vfsmount *mnt, int acc_mode);
69770+__u32 gr_acl_handle_creat(const struct dentry *dentry,
69771+ const struct dentry *p_dentry,
69772+ const struct vfsmount *p_mnt,
69773+ int open_flags, int acc_mode, const int imode);
69774+void gr_handle_create(const struct dentry *dentry,
69775+ const struct vfsmount *mnt);
69776+void gr_handle_proc_create(const struct dentry *dentry,
69777+ const struct inode *inode);
69778+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
69779+ const struct dentry *parent_dentry,
69780+ const struct vfsmount *parent_mnt,
69781+ const int mode);
69782+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
69783+ const struct dentry *parent_dentry,
69784+ const struct vfsmount *parent_mnt);
69785+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
69786+ const struct vfsmount *mnt);
69787+void gr_handle_delete(const ino_t ino, const dev_t dev);
69788+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
69789+ const struct vfsmount *mnt);
69790+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
69791+ const struct dentry *parent_dentry,
69792+ const struct vfsmount *parent_mnt,
69793+ const struct filename *from);
69794+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
69795+ const struct dentry *parent_dentry,
69796+ const struct vfsmount *parent_mnt,
69797+ const struct dentry *old_dentry,
69798+ const struct vfsmount *old_mnt, const struct filename *to);
69799+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
69800+int gr_acl_handle_rename(struct dentry *new_dentry,
69801+ struct dentry *parent_dentry,
69802+ const struct vfsmount *parent_mnt,
69803+ struct dentry *old_dentry,
69804+ struct inode *old_parent_inode,
69805+ struct vfsmount *old_mnt, const struct filename *newname);
69806+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69807+ struct dentry *old_dentry,
69808+ struct dentry *new_dentry,
69809+ struct vfsmount *mnt, const __u8 replace);
69810+__u32 gr_check_link(const struct dentry *new_dentry,
69811+ const struct dentry *parent_dentry,
69812+ const struct vfsmount *parent_mnt,
69813+ const struct dentry *old_dentry,
69814+ const struct vfsmount *old_mnt);
69815+int gr_acl_handle_filldir(const struct file *file, const char *name,
69816+ const unsigned int namelen, const ino_t ino);
69817+
69818+__u32 gr_acl_handle_unix(const struct dentry *dentry,
69819+ const struct vfsmount *mnt);
69820+void gr_acl_handle_exit(void);
69821+void gr_acl_handle_psacct(struct task_struct *task, const long code);
69822+int gr_acl_handle_procpidmem(const struct task_struct *task);
69823+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
69824+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
69825+void gr_audit_ptrace(struct task_struct *task);
69826+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
69827+void gr_put_exec_file(struct task_struct *task);
69828+
69829+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
69830+
69831+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
69832+extern void gr_learn_resource(const struct task_struct *task, const int res,
69833+ const unsigned long wanted, const int gt);
69834+#else
69835+static inline void gr_learn_resource(const struct task_struct *task, const int res,
69836+ const unsigned long wanted, const int gt)
69837+{
69838+}
69839+#endif
69840+
69841+#ifdef CONFIG_GRKERNSEC_RESLOG
69842+extern void gr_log_resource(const struct task_struct *task, const int res,
69843+ const unsigned long wanted, const int gt);
69844+#else
69845+static inline void gr_log_resource(const struct task_struct *task, const int res,
69846+ const unsigned long wanted, const int gt)
69847+{
69848+}
69849+#endif
69850+
69851+#ifdef CONFIG_GRKERNSEC
69852+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
69853+void gr_handle_vm86(void);
69854+void gr_handle_mem_readwrite(u64 from, u64 to);
69855+
69856+void gr_log_badprocpid(const char *entry);
69857+
69858+extern int grsec_enable_dmesg;
69859+extern int grsec_disable_privio;
69860+
69861+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69862+extern kgid_t grsec_proc_gid;
69863+#endif
69864+
69865+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69866+extern int grsec_enable_chroot_findtask;
69867+#endif
69868+#ifdef CONFIG_GRKERNSEC_SETXID
69869+extern int grsec_enable_setxid;
69870+#endif
69871+#endif
69872+
69873+#endif
69874diff --git a/include/linux/grsock.h b/include/linux/grsock.h
69875new file mode 100644
69876index 0000000..e7ffaaf
69877--- /dev/null
69878+++ b/include/linux/grsock.h
69879@@ -0,0 +1,19 @@
69880+#ifndef __GRSOCK_H
69881+#define __GRSOCK_H
69882+
69883+extern void gr_attach_curr_ip(const struct sock *sk);
69884+extern int gr_handle_sock_all(const int family, const int type,
69885+ const int protocol);
69886+extern int gr_handle_sock_server(const struct sockaddr *sck);
69887+extern int gr_handle_sock_server_other(const struct sock *sck);
69888+extern int gr_handle_sock_client(const struct sockaddr *sck);
69889+extern int gr_search_connect(struct socket * sock,
69890+ struct sockaddr_in * addr);
69891+extern int gr_search_bind(struct socket * sock,
69892+ struct sockaddr_in * addr);
69893+extern int gr_search_listen(struct socket * sock);
69894+extern int gr_search_accept(struct socket * sock);
69895+extern int gr_search_socket(const int domain, const int type,
69896+ const int protocol);
69897+
69898+#endif
69899diff --git a/include/linux/highmem.h b/include/linux/highmem.h
69900index 7fb31da..08b5114 100644
69901--- a/include/linux/highmem.h
69902+++ b/include/linux/highmem.h
69903@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
69904 kunmap_atomic(kaddr);
69905 }
69906
69907+static inline void sanitize_highpage(struct page *page)
69908+{
69909+ void *kaddr;
69910+ unsigned long flags;
69911+
69912+ local_irq_save(flags);
69913+ kaddr = kmap_atomic(page);
69914+ clear_page(kaddr);
69915+ kunmap_atomic(kaddr);
69916+ local_irq_restore(flags);
69917+}
69918+
69919 static inline void zero_user_segments(struct page *page,
69920 unsigned start1, unsigned end1,
69921 unsigned start2, unsigned end2)
69922diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
69923index 1c7b89a..7f52502 100644
69924--- a/include/linux/hwmon-sysfs.h
69925+++ b/include/linux/hwmon-sysfs.h
69926@@ -25,7 +25,8 @@
69927 struct sensor_device_attribute{
69928 struct device_attribute dev_attr;
69929 int index;
69930-};
69931+} __do_const;
69932+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
69933 #define to_sensor_dev_attr(_dev_attr) \
69934 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
69935
69936@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
69937 struct device_attribute dev_attr;
69938 u8 index;
69939 u8 nr;
69940-};
69941+} __do_const;
69942 #define to_sensor_dev_attr_2(_dev_attr) \
69943 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
69944
69945diff --git a/include/linux/i2c.h b/include/linux/i2c.h
69946index e988fa9..ff9f17e 100644
69947--- a/include/linux/i2c.h
69948+++ b/include/linux/i2c.h
69949@@ -366,6 +366,7 @@ struct i2c_algorithm {
69950 /* To determine what the adapter supports */
69951 u32 (*functionality) (struct i2c_adapter *);
69952 };
69953+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
69954
69955 /**
69956 * struct i2c_bus_recovery_info - I2C bus recovery information
69957diff --git a/include/linux/i2o.h b/include/linux/i2o.h
69958index d23c3c2..eb63c81 100644
69959--- a/include/linux/i2o.h
69960+++ b/include/linux/i2o.h
69961@@ -565,7 +565,7 @@ struct i2o_controller {
69962 struct i2o_device *exec; /* Executive */
69963 #if BITS_PER_LONG == 64
69964 spinlock_t context_list_lock; /* lock for context_list */
69965- atomic_t context_list_counter; /* needed for unique contexts */
69966+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
69967 struct list_head context_list; /* list of context id's
69968 and pointers */
69969 #endif
69970diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
69971index aff7ad8..3942bbd 100644
69972--- a/include/linux/if_pppox.h
69973+++ b/include/linux/if_pppox.h
69974@@ -76,7 +76,7 @@ struct pppox_proto {
69975 int (*ioctl)(struct socket *sock, unsigned int cmd,
69976 unsigned long arg);
69977 struct module *owner;
69978-};
69979+} __do_const;
69980
69981 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
69982 extern void unregister_pppox_proto(int proto_num);
69983diff --git a/include/linux/init.h b/include/linux/init.h
69984index 8618147..0821126 100644
69985--- a/include/linux/init.h
69986+++ b/include/linux/init.h
69987@@ -39,9 +39,36 @@
69988 * Also note, that this data cannot be "const".
69989 */
69990
69991+#ifdef MODULE
69992+#define add_init_latent_entropy
69993+#define add_devinit_latent_entropy
69994+#define add_cpuinit_latent_entropy
69995+#define add_meminit_latent_entropy
69996+#else
69997+#define add_init_latent_entropy __latent_entropy
69998+
69999+#ifdef CONFIG_HOTPLUG
70000+#define add_devinit_latent_entropy
70001+#else
70002+#define add_devinit_latent_entropy __latent_entropy
70003+#endif
70004+
70005+#ifdef CONFIG_HOTPLUG_CPU
70006+#define add_cpuinit_latent_entropy
70007+#else
70008+#define add_cpuinit_latent_entropy __latent_entropy
70009+#endif
70010+
70011+#ifdef CONFIG_MEMORY_HOTPLUG
70012+#define add_meminit_latent_entropy
70013+#else
70014+#define add_meminit_latent_entropy __latent_entropy
70015+#endif
70016+#endif
70017+
70018 /* These are for everybody (although not all archs will actually
70019 discard it in modules) */
70020-#define __init __section(.init.text) __cold notrace
70021+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
70022 #define __initdata __section(.init.data)
70023 #define __initconst __constsection(.init.rodata)
70024 #define __exitdata __section(.exit.data)
70025@@ -94,7 +121,7 @@
70026 #define __exit __section(.exit.text) __exitused __cold notrace
70027
70028 /* Used for HOTPLUG_CPU */
70029-#define __cpuinit __section(.cpuinit.text) __cold notrace
70030+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
70031 #define __cpuinitdata __section(.cpuinit.data)
70032 #define __cpuinitconst __constsection(.cpuinit.rodata)
70033 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
70034@@ -102,7 +129,7 @@
70035 #define __cpuexitconst __constsection(.cpuexit.rodata)
70036
70037 /* Used for MEMORY_HOTPLUG */
70038-#define __meminit __section(.meminit.text) __cold notrace
70039+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
70040 #define __meminitdata __section(.meminit.data)
70041 #define __meminitconst __constsection(.meminit.rodata)
70042 #define __memexit __section(.memexit.text) __exitused __cold notrace
70043diff --git a/include/linux/init_task.h b/include/linux/init_task.h
70044index 5cd0f09..c9f67cc 100644
70045--- a/include/linux/init_task.h
70046+++ b/include/linux/init_task.h
70047@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
70048
70049 #define INIT_TASK_COMM "swapper"
70050
70051+#ifdef CONFIG_X86
70052+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
70053+#else
70054+#define INIT_TASK_THREAD_INFO
70055+#endif
70056+
70057 /*
70058 * INIT_TASK is used to set up the first task table, touch at
70059 * your own risk!. Base=0, limit=0x1fffff (=2MB)
70060@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
70061 RCU_POINTER_INITIALIZER(cred, &init_cred), \
70062 .comm = INIT_TASK_COMM, \
70063 .thread = INIT_THREAD, \
70064+ INIT_TASK_THREAD_INFO \
70065 .fs = &init_fs, \
70066 .files = &init_files, \
70067 .signal = &init_signals, \
70068diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
70069index 5fa5afe..ac55b25 100644
70070--- a/include/linux/interrupt.h
70071+++ b/include/linux/interrupt.h
70072@@ -430,7 +430,7 @@ enum
70073 /* map softirq index to softirq name. update 'softirq_to_name' in
70074 * kernel/softirq.c when adding a new softirq.
70075 */
70076-extern char *softirq_to_name[NR_SOFTIRQS];
70077+extern const char * const softirq_to_name[NR_SOFTIRQS];
70078
70079 /* softirq mask and active fields moved to irq_cpustat_t in
70080 * asm/hardirq.h to get better cache usage. KAO
70081@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
70082
70083 struct softirq_action
70084 {
70085- void (*action)(struct softirq_action *);
70086-};
70087+ void (*action)(void);
70088+} __no_const;
70089
70090 asmlinkage void do_softirq(void);
70091 asmlinkage void __do_softirq(void);
70092-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
70093+extern void open_softirq(int nr, void (*action)(void));
70094 extern void softirq_init(void);
70095 extern void __raise_softirq_irqoff(unsigned int nr);
70096
70097diff --git a/include/linux/iommu.h b/include/linux/iommu.h
70098index 3aeb730..2177f39 100644
70099--- a/include/linux/iommu.h
70100+++ b/include/linux/iommu.h
70101@@ -113,7 +113,7 @@ struct iommu_ops {
70102 u32 (*domain_get_windows)(struct iommu_domain *domain);
70103
70104 unsigned long pgsize_bitmap;
70105-};
70106+} __do_const;
70107
70108 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
70109 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
70110diff --git a/include/linux/ioport.h b/include/linux/ioport.h
70111index 89b7c24..382af74 100644
70112--- a/include/linux/ioport.h
70113+++ b/include/linux/ioport.h
70114@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
70115 int adjust_resource(struct resource *res, resource_size_t start,
70116 resource_size_t size);
70117 resource_size_t resource_alignment(struct resource *res);
70118-static inline resource_size_t resource_size(const struct resource *res)
70119+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
70120 {
70121 return res->end - res->start + 1;
70122 }
70123diff --git a/include/linux/irq.h b/include/linux/irq.h
70124index bc4e066..50468a9 100644
70125--- a/include/linux/irq.h
70126+++ b/include/linux/irq.h
70127@@ -328,7 +328,8 @@ struct irq_chip {
70128 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
70129
70130 unsigned long flags;
70131-};
70132+} __do_const;
70133+typedef struct irq_chip __no_const irq_chip_no_const;
70134
70135 /*
70136 * irq_chip specific flags
70137diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
70138index 3e203eb..3fe68d0 100644
70139--- a/include/linux/irqchip/arm-gic.h
70140+++ b/include/linux/irqchip/arm-gic.h
70141@@ -59,9 +59,11 @@
70142
70143 #ifndef __ASSEMBLY__
70144
70145+#include <linux/irq.h>
70146+
70147 struct device_node;
70148
70149-extern struct irq_chip gic_arch_extn;
70150+extern irq_chip_no_const gic_arch_extn;
70151
70152 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
70153 u32 offset, struct device_node *);
70154diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
70155index 6883e19..06992b1 100644
70156--- a/include/linux/kallsyms.h
70157+++ b/include/linux/kallsyms.h
70158@@ -15,7 +15,8 @@
70159
70160 struct module;
70161
70162-#ifdef CONFIG_KALLSYMS
70163+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
70164+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70165 /* Lookup the address for a symbol. Returns 0 if not found. */
70166 unsigned long kallsyms_lookup_name(const char *name);
70167
70168@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
70169 /* Stupid that this does nothing, but I didn't create this mess. */
70170 #define __print_symbol(fmt, addr)
70171 #endif /*CONFIG_KALLSYMS*/
70172+#else /* when included by kallsyms.c, vsnprintf.c, or
70173+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
70174+extern void __print_symbol(const char *fmt, unsigned long address);
70175+extern int sprint_backtrace(char *buffer, unsigned long address);
70176+extern int sprint_symbol(char *buffer, unsigned long address);
70177+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
70178+const char *kallsyms_lookup(unsigned long addr,
70179+ unsigned long *symbolsize,
70180+ unsigned long *offset,
70181+ char **modname, char *namebuf);
70182+#endif
70183
70184 /* This macro allows us to keep printk typechecking */
70185 static __printf(1, 2)
70186diff --git a/include/linux/key-type.h b/include/linux/key-type.h
70187index 518a53a..5e28358 100644
70188--- a/include/linux/key-type.h
70189+++ b/include/linux/key-type.h
70190@@ -125,7 +125,7 @@ struct key_type {
70191 /* internal fields */
70192 struct list_head link; /* link in types list */
70193 struct lock_class_key lock_class; /* key->sem lock class */
70194-};
70195+} __do_const;
70196
70197 extern struct key_type key_type_keyring;
70198
70199diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
70200index c6e091b..a940adf 100644
70201--- a/include/linux/kgdb.h
70202+++ b/include/linux/kgdb.h
70203@@ -52,7 +52,7 @@ extern int kgdb_connected;
70204 extern int kgdb_io_module_registered;
70205
70206 extern atomic_t kgdb_setting_breakpoint;
70207-extern atomic_t kgdb_cpu_doing_single_step;
70208+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
70209
70210 extern struct task_struct *kgdb_usethread;
70211 extern struct task_struct *kgdb_contthread;
70212@@ -254,7 +254,7 @@ struct kgdb_arch {
70213 void (*correct_hw_break)(void);
70214
70215 void (*enable_nmi)(bool on);
70216-};
70217+} __do_const;
70218
70219 /**
70220 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
70221@@ -279,7 +279,7 @@ struct kgdb_io {
70222 void (*pre_exception) (void);
70223 void (*post_exception) (void);
70224 int is_console;
70225-};
70226+} __do_const;
70227
70228 extern struct kgdb_arch arch_kgdb_ops;
70229
70230diff --git a/include/linux/kmod.h b/include/linux/kmod.h
70231index 0555cc6..b16a7a4 100644
70232--- a/include/linux/kmod.h
70233+++ b/include/linux/kmod.h
70234@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
70235 * usually useless though. */
70236 extern __printf(2, 3)
70237 int __request_module(bool wait, const char *name, ...);
70238+extern __printf(3, 4)
70239+int ___request_module(bool wait, char *param_name, const char *name, ...);
70240 #define request_module(mod...) __request_module(true, mod)
70241 #define request_module_nowait(mod...) __request_module(false, mod)
70242 #define try_then_request_module(x, mod...) \
70243diff --git a/include/linux/kobject.h b/include/linux/kobject.h
70244index 939b112..ed6ed51 100644
70245--- a/include/linux/kobject.h
70246+++ b/include/linux/kobject.h
70247@@ -111,7 +111,7 @@ struct kobj_type {
70248 struct attribute **default_attrs;
70249 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
70250 const void *(*namespace)(struct kobject *kobj);
70251-};
70252+} __do_const;
70253
70254 struct kobj_uevent_env {
70255 char *envp[UEVENT_NUM_ENVP];
70256@@ -134,6 +134,7 @@ struct kobj_attribute {
70257 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
70258 const char *buf, size_t count);
70259 };
70260+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
70261
70262 extern const struct sysfs_ops kobj_sysfs_ops;
70263
70264diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
70265index f66b065..c2c29b4 100644
70266--- a/include/linux/kobject_ns.h
70267+++ b/include/linux/kobject_ns.h
70268@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
70269 const void *(*netlink_ns)(struct sock *sk);
70270 const void *(*initial_ns)(void);
70271 void (*drop_ns)(void *);
70272-};
70273+} __do_const;
70274
70275 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
70276 int kobj_ns_type_registered(enum kobj_ns_type type);
70277diff --git a/include/linux/kref.h b/include/linux/kref.h
70278index 484604d..0f6c5b6 100644
70279--- a/include/linux/kref.h
70280+++ b/include/linux/kref.h
70281@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
70282 static inline int kref_sub(struct kref *kref, unsigned int count,
70283 void (*release)(struct kref *kref))
70284 {
70285- WARN_ON(release == NULL);
70286+ BUG_ON(release == NULL);
70287
70288 if (atomic_sub_and_test((int) count, &kref->refcount)) {
70289 release(kref);
70290diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
70291index 8db53cf..c21121d 100644
70292--- a/include/linux/kvm_host.h
70293+++ b/include/linux/kvm_host.h
70294@@ -444,7 +444,7 @@ static inline void kvm_irqfd_exit(void)
70295 {
70296 }
70297 #endif
70298-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70299+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70300 struct module *module);
70301 void kvm_exit(void);
70302
70303@@ -616,7 +616,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
70304 struct kvm_guest_debug *dbg);
70305 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
70306
70307-int kvm_arch_init(void *opaque);
70308+int kvm_arch_init(const void *opaque);
70309 void kvm_arch_exit(void);
70310
70311 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
70312diff --git a/include/linux/libata.h b/include/linux/libata.h
70313index eae7a05..2cdd875 100644
70314--- a/include/linux/libata.h
70315+++ b/include/linux/libata.h
70316@@ -919,7 +919,7 @@ struct ata_port_operations {
70317 * fields must be pointers.
70318 */
70319 const struct ata_port_operations *inherits;
70320-};
70321+} __do_const;
70322
70323 struct ata_port_info {
70324 unsigned long flags;
70325diff --git a/include/linux/list.h b/include/linux/list.h
70326index b83e565..baa6c1d 100644
70327--- a/include/linux/list.h
70328+++ b/include/linux/list.h
70329@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
70330 extern void list_del(struct list_head *entry);
70331 #endif
70332
70333+extern void __pax_list_add(struct list_head *new,
70334+ struct list_head *prev,
70335+ struct list_head *next);
70336+static inline void pax_list_add(struct list_head *new, struct list_head *head)
70337+{
70338+ __pax_list_add(new, head, head->next);
70339+}
70340+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
70341+{
70342+ __pax_list_add(new, head->prev, head);
70343+}
70344+extern void pax_list_del(struct list_head *entry);
70345+
70346 /**
70347 * list_replace - replace old entry by new one
70348 * @old : the element to be replaced
70349@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
70350 INIT_LIST_HEAD(entry);
70351 }
70352
70353+extern void pax_list_del_init(struct list_head *entry);
70354+
70355 /**
70356 * list_move - delete from one list and add as another's head
70357 * @list: the entry to move
70358diff --git a/include/linux/math64.h b/include/linux/math64.h
70359index 2913b86..4209244 100644
70360--- a/include/linux/math64.h
70361+++ b/include/linux/math64.h
70362@@ -15,7 +15,7 @@
70363 * This is commonly provided by 32bit archs to provide an optimized 64bit
70364 * divide.
70365 */
70366-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70367+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70368 {
70369 *remainder = dividend % divisor;
70370 return dividend / divisor;
70371@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
70372 #define div64_ul(x, y) div_u64((x), (y))
70373
70374 #ifndef div_u64_rem
70375-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70376+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70377 {
70378 *remainder = do_div(dividend, divisor);
70379 return dividend;
70380@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
70381 * divide.
70382 */
70383 #ifndef div_u64
70384-static inline u64 div_u64(u64 dividend, u32 divisor)
70385+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
70386 {
70387 u32 remainder;
70388 return div_u64_rem(dividend, divisor, &remainder);
70389diff --git a/include/linux/mm.h b/include/linux/mm.h
70390index e0c8528..bcf0c29 100644
70391--- a/include/linux/mm.h
70392+++ b/include/linux/mm.h
70393@@ -104,6 +104,11 @@ extern unsigned int kobjsize(const void *objp);
70394 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
70395 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
70396 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
70397+
70398+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70399+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
70400+#endif
70401+
70402 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
70403
70404 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
70405@@ -205,8 +210,8 @@ struct vm_operations_struct {
70406 /* called by access_process_vm when get_user_pages() fails, typically
70407 * for use by special VMAs that can switch between memory and hardware
70408 */
70409- int (*access)(struct vm_area_struct *vma, unsigned long addr,
70410- void *buf, int len, int write);
70411+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
70412+ void *buf, size_t len, int write);
70413 #ifdef CONFIG_NUMA
70414 /*
70415 * set_policy() op must add a reference to any non-NULL @new mempolicy
70416@@ -236,6 +241,7 @@ struct vm_operations_struct {
70417 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
70418 unsigned long size, pgoff_t pgoff);
70419 };
70420+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
70421
70422 struct mmu_gather;
70423 struct inode;
70424@@ -980,8 +986,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
70425 unsigned long *pfn);
70426 int follow_phys(struct vm_area_struct *vma, unsigned long address,
70427 unsigned int flags, unsigned long *prot, resource_size_t *phys);
70428-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70429- void *buf, int len, int write);
70430+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70431+ void *buf, size_t len, int write);
70432
70433 static inline void unmap_shared_mapping_range(struct address_space *mapping,
70434 loff_t const holebegin, loff_t const holelen)
70435@@ -1020,9 +1026,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
70436 }
70437 #endif
70438
70439-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
70440-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
70441- void *buf, int len, int write);
70442+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
70443+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
70444+ void *buf, size_t len, int write);
70445
70446 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70447 unsigned long start, unsigned long nr_pages,
70448@@ -1053,34 +1059,6 @@ int set_page_dirty(struct page *page);
70449 int set_page_dirty_lock(struct page *page);
70450 int clear_page_dirty_for_io(struct page *page);
70451
70452-/* Is the vma a continuation of the stack vma above it? */
70453-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
70454-{
70455- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
70456-}
70457-
70458-static inline int stack_guard_page_start(struct vm_area_struct *vma,
70459- unsigned long addr)
70460-{
70461- return (vma->vm_flags & VM_GROWSDOWN) &&
70462- (vma->vm_start == addr) &&
70463- !vma_growsdown(vma->vm_prev, addr);
70464-}
70465-
70466-/* Is the vma a continuation of the stack vma below it? */
70467-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
70468-{
70469- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
70470-}
70471-
70472-static inline int stack_guard_page_end(struct vm_area_struct *vma,
70473- unsigned long addr)
70474-{
70475- return (vma->vm_flags & VM_GROWSUP) &&
70476- (vma->vm_end == addr) &&
70477- !vma_growsup(vma->vm_next, addr);
70478-}
70479-
70480 extern pid_t
70481 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
70482
70483@@ -1180,6 +1158,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
70484 }
70485 #endif
70486
70487+#ifdef CONFIG_MMU
70488+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
70489+#else
70490+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70491+{
70492+ return __pgprot(0);
70493+}
70494+#endif
70495+
70496 int vma_wants_writenotify(struct vm_area_struct *vma);
70497
70498 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
70499@@ -1198,8 +1185,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
70500 {
70501 return 0;
70502 }
70503+
70504+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
70505+ unsigned long address)
70506+{
70507+ return 0;
70508+}
70509 #else
70510 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70511+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70512 #endif
70513
70514 #ifdef __PAGETABLE_PMD_FOLDED
70515@@ -1208,8 +1202,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
70516 {
70517 return 0;
70518 }
70519+
70520+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
70521+ unsigned long address)
70522+{
70523+ return 0;
70524+}
70525 #else
70526 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
70527+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
70528 #endif
70529
70530 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
70531@@ -1227,11 +1228,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
70532 NULL: pud_offset(pgd, address);
70533 }
70534
70535+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70536+{
70537+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
70538+ NULL: pud_offset(pgd, address);
70539+}
70540+
70541 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70542 {
70543 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
70544 NULL: pmd_offset(pud, address);
70545 }
70546+
70547+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70548+{
70549+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
70550+ NULL: pmd_offset(pud, address);
70551+}
70552 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
70553
70554 #if USE_SPLIT_PTLOCKS
70555@@ -1517,6 +1530,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70556 unsigned long len, unsigned long prot, unsigned long flags,
70557 unsigned long pgoff, unsigned long *populate);
70558 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
70559+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
70560
70561 #ifdef CONFIG_MMU
70562 extern int __mm_populate(unsigned long addr, unsigned long len,
70563@@ -1545,10 +1559,11 @@ struct vm_unmapped_area_info {
70564 unsigned long high_limit;
70565 unsigned long align_mask;
70566 unsigned long align_offset;
70567+ unsigned long threadstack_offset;
70568 };
70569
70570-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
70571-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
70572+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
70573+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
70574
70575 /*
70576 * Search for an unmapped address range.
70577@@ -1560,7 +1575,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
70578 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
70579 */
70580 static inline unsigned long
70581-vm_unmapped_area(struct vm_unmapped_area_info *info)
70582+vm_unmapped_area(const struct vm_unmapped_area_info *info)
70583 {
70584 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
70585 return unmapped_area(info);
70586@@ -1623,6 +1638,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
70587 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
70588 struct vm_area_struct **pprev);
70589
70590+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
70591+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
70592+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
70593+
70594 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
70595 NULL if none. Assume start_addr < end_addr. */
70596 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
70597@@ -1651,15 +1670,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
70598 return vma;
70599 }
70600
70601-#ifdef CONFIG_MMU
70602-pgprot_t vm_get_page_prot(unsigned long vm_flags);
70603-#else
70604-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
70605-{
70606- return __pgprot(0);
70607-}
70608-#endif
70609-
70610 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
70611 unsigned long change_prot_numa(struct vm_area_struct *vma,
70612 unsigned long start, unsigned long end);
70613@@ -1711,6 +1721,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
70614 static inline void vm_stat_account(struct mm_struct *mm,
70615 unsigned long flags, struct file *file, long pages)
70616 {
70617+
70618+#ifdef CONFIG_PAX_RANDMMAP
70619+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
70620+#endif
70621+
70622 mm->total_vm += pages;
70623 }
70624 #endif /* CONFIG_PROC_FS */
70625@@ -1791,7 +1806,7 @@ extern int unpoison_memory(unsigned long pfn);
70626 extern int sysctl_memory_failure_early_kill;
70627 extern int sysctl_memory_failure_recovery;
70628 extern void shake_page(struct page *p, int access);
70629-extern atomic_long_t num_poisoned_pages;
70630+extern atomic_long_unchecked_t num_poisoned_pages;
70631 extern int soft_offline_page(struct page *page, int flags);
70632
70633 extern void dump_page(struct page *page);
70634@@ -1828,5 +1843,11 @@ void __init setup_nr_node_ids(void);
70635 static inline void setup_nr_node_ids(void) {}
70636 #endif
70637
70638+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70639+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
70640+#else
70641+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
70642+#endif
70643+
70644 #endif /* __KERNEL__ */
70645 #endif /* _LINUX_MM_H */
70646diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
70647index ace9a5f..81bdb59 100644
70648--- a/include/linux/mm_types.h
70649+++ b/include/linux/mm_types.h
70650@@ -289,6 +289,8 @@ struct vm_area_struct {
70651 #ifdef CONFIG_NUMA
70652 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
70653 #endif
70654+
70655+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
70656 };
70657
70658 struct core_thread {
70659@@ -437,6 +439,24 @@ struct mm_struct {
70660 int first_nid;
70661 #endif
70662 struct uprobes_state uprobes_state;
70663+
70664+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70665+ unsigned long pax_flags;
70666+#endif
70667+
70668+#ifdef CONFIG_PAX_DLRESOLVE
70669+ unsigned long call_dl_resolve;
70670+#endif
70671+
70672+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
70673+ unsigned long call_syscall;
70674+#endif
70675+
70676+#ifdef CONFIG_PAX_ASLR
70677+ unsigned long delta_mmap; /* randomized offset */
70678+ unsigned long delta_stack; /* randomized offset */
70679+#endif
70680+
70681 };
70682
70683 /* first nid will either be a valid NID or one of these values */
70684diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
70685index c5d5278..f0b68c8 100644
70686--- a/include/linux/mmiotrace.h
70687+++ b/include/linux/mmiotrace.h
70688@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
70689 /* Called from ioremap.c */
70690 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
70691 void __iomem *addr);
70692-extern void mmiotrace_iounmap(volatile void __iomem *addr);
70693+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
70694
70695 /* For anyone to insert markers. Remember trailing newline. */
70696 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
70697@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
70698 {
70699 }
70700
70701-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
70702+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
70703 {
70704 }
70705
70706diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
70707index 5c76737..61f518e 100644
70708--- a/include/linux/mmzone.h
70709+++ b/include/linux/mmzone.h
70710@@ -396,7 +396,7 @@ struct zone {
70711 unsigned long flags; /* zone flags, see below */
70712
70713 /* Zone statistics */
70714- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70715+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70716
70717 /*
70718 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
70719diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
70720index b508016..237cfe5 100644
70721--- a/include/linux/mod_devicetable.h
70722+++ b/include/linux/mod_devicetable.h
70723@@ -13,7 +13,7 @@
70724 typedef unsigned long kernel_ulong_t;
70725 #endif
70726
70727-#define PCI_ANY_ID (~0)
70728+#define PCI_ANY_ID ((__u16)~0)
70729
70730 struct pci_device_id {
70731 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
70732@@ -139,7 +139,7 @@ struct usb_device_id {
70733 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
70734 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
70735
70736-#define HID_ANY_ID (~0)
70737+#define HID_ANY_ID (~0U)
70738 #define HID_BUS_ANY 0xffff
70739 #define HID_GROUP_ANY 0x0000
70740
70741@@ -465,7 +465,7 @@ struct dmi_system_id {
70742 const char *ident;
70743 struct dmi_strmatch matches[4];
70744 void *driver_data;
70745-};
70746+} __do_const;
70747 /*
70748 * struct dmi_device_id appears during expansion of
70749 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
70750diff --git a/include/linux/module.h b/include/linux/module.h
70751index 46f1ea0..a34ca37 100644
70752--- a/include/linux/module.h
70753+++ b/include/linux/module.h
70754@@ -17,9 +17,11 @@
70755 #include <linux/moduleparam.h>
70756 #include <linux/tracepoint.h>
70757 #include <linux/export.h>
70758+#include <linux/fs.h>
70759
70760 #include <linux/percpu.h>
70761 #include <asm/module.h>
70762+#include <asm/pgtable.h>
70763
70764 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
70765 #define MODULE_SIG_STRING "~Module signature appended~\n"
70766@@ -54,12 +56,13 @@ struct module_attribute {
70767 int (*test)(struct module *);
70768 void (*free)(struct module *);
70769 };
70770+typedef struct module_attribute __no_const module_attribute_no_const;
70771
70772 struct module_version_attribute {
70773 struct module_attribute mattr;
70774 const char *module_name;
70775 const char *version;
70776-} __attribute__ ((__aligned__(sizeof(void *))));
70777+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
70778
70779 extern ssize_t __modver_version_show(struct module_attribute *,
70780 struct module_kobject *, char *);
70781@@ -232,7 +235,7 @@ struct module
70782
70783 /* Sysfs stuff. */
70784 struct module_kobject mkobj;
70785- struct module_attribute *modinfo_attrs;
70786+ module_attribute_no_const *modinfo_attrs;
70787 const char *version;
70788 const char *srcversion;
70789 struct kobject *holders_dir;
70790@@ -281,19 +284,16 @@ struct module
70791 int (*init)(void);
70792
70793 /* If this is non-NULL, vfree after init() returns */
70794- void *module_init;
70795+ void *module_init_rx, *module_init_rw;
70796
70797 /* Here is the actual code + data, vfree'd on unload. */
70798- void *module_core;
70799+ void *module_core_rx, *module_core_rw;
70800
70801 /* Here are the sizes of the init and core sections */
70802- unsigned int init_size, core_size;
70803+ unsigned int init_size_rw, core_size_rw;
70804
70805 /* The size of the executable code in each section. */
70806- unsigned int init_text_size, core_text_size;
70807-
70808- /* Size of RO sections of the module (text+rodata) */
70809- unsigned int init_ro_size, core_ro_size;
70810+ unsigned int init_size_rx, core_size_rx;
70811
70812 /* Arch-specific module values */
70813 struct mod_arch_specific arch;
70814@@ -349,6 +349,10 @@ struct module
70815 #ifdef CONFIG_EVENT_TRACING
70816 struct ftrace_event_call **trace_events;
70817 unsigned int num_trace_events;
70818+ struct file_operations trace_id;
70819+ struct file_operations trace_enable;
70820+ struct file_operations trace_format;
70821+ struct file_operations trace_filter;
70822 #endif
70823 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
70824 unsigned int num_ftrace_callsites;
70825@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
70826 bool is_module_percpu_address(unsigned long addr);
70827 bool is_module_text_address(unsigned long addr);
70828
70829+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
70830+{
70831+
70832+#ifdef CONFIG_PAX_KERNEXEC
70833+ if (ktla_ktva(addr) >= (unsigned long)start &&
70834+ ktla_ktva(addr) < (unsigned long)start + size)
70835+ return 1;
70836+#endif
70837+
70838+ return ((void *)addr >= start && (void *)addr < start + size);
70839+}
70840+
70841+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
70842+{
70843+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
70844+}
70845+
70846+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
70847+{
70848+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
70849+}
70850+
70851+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
70852+{
70853+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
70854+}
70855+
70856+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
70857+{
70858+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
70859+}
70860+
70861 static inline int within_module_core(unsigned long addr, const struct module *mod)
70862 {
70863- return (unsigned long)mod->module_core <= addr &&
70864- addr < (unsigned long)mod->module_core + mod->core_size;
70865+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
70866 }
70867
70868 static inline int within_module_init(unsigned long addr, const struct module *mod)
70869 {
70870- return (unsigned long)mod->module_init <= addr &&
70871- addr < (unsigned long)mod->module_init + mod->init_size;
70872+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
70873 }
70874
70875 /* Search for module by name: must hold module_mutex. */
70876diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
70877index 560ca53..ef621ef 100644
70878--- a/include/linux/moduleloader.h
70879+++ b/include/linux/moduleloader.h
70880@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
70881 sections. Returns NULL on failure. */
70882 void *module_alloc(unsigned long size);
70883
70884+#ifdef CONFIG_PAX_KERNEXEC
70885+void *module_alloc_exec(unsigned long size);
70886+#else
70887+#define module_alloc_exec(x) module_alloc(x)
70888+#endif
70889+
70890 /* Free memory returned from module_alloc. */
70891 void module_free(struct module *mod, void *module_region);
70892
70893+#ifdef CONFIG_PAX_KERNEXEC
70894+void module_free_exec(struct module *mod, void *module_region);
70895+#else
70896+#define module_free_exec(x, y) module_free((x), (y))
70897+#endif
70898+
70899 /*
70900 * Apply the given relocation to the (simplified) ELF. Return -error
70901 * or 0.
70902@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
70903 unsigned int relsec,
70904 struct module *me)
70905 {
70906+#ifdef CONFIG_MODULES
70907 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70908+#endif
70909 return -ENOEXEC;
70910 }
70911 #endif
70912@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
70913 unsigned int relsec,
70914 struct module *me)
70915 {
70916+#ifdef CONFIG_MODULES
70917 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70918+#endif
70919 return -ENOEXEC;
70920 }
70921 #endif
70922diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
70923index 137b419..fe663ec 100644
70924--- a/include/linux/moduleparam.h
70925+++ b/include/linux/moduleparam.h
70926@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
70927 * @len is usually just sizeof(string).
70928 */
70929 #define module_param_string(name, string, len, perm) \
70930- static const struct kparam_string __param_string_##name \
70931+ static const struct kparam_string __param_string_##name __used \
70932 = { len, string }; \
70933 __module_param_call(MODULE_PARAM_PREFIX, name, \
70934 &param_ops_string, \
70935@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
70936 */
70937 #define module_param_array_named(name, array, type, nump, perm) \
70938 param_check_##type(name, &(array)[0]); \
70939- static const struct kparam_array __param_arr_##name \
70940+ static const struct kparam_array __param_arr_##name __used \
70941 = { .max = ARRAY_SIZE(array), .num = nump, \
70942 .ops = &param_ops_##type, \
70943 .elemsize = sizeof(array[0]), .elem = array }; \
70944diff --git a/include/linux/namei.h b/include/linux/namei.h
70945index 5a5ff57..5ae5070 100644
70946--- a/include/linux/namei.h
70947+++ b/include/linux/namei.h
70948@@ -19,7 +19,7 @@ struct nameidata {
70949 unsigned seq;
70950 int last_type;
70951 unsigned depth;
70952- char *saved_names[MAX_NESTED_LINKS + 1];
70953+ const char *saved_names[MAX_NESTED_LINKS + 1];
70954 };
70955
70956 /*
70957@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
70958
70959 extern void nd_jump_link(struct nameidata *nd, struct path *path);
70960
70961-static inline void nd_set_link(struct nameidata *nd, char *path)
70962+static inline void nd_set_link(struct nameidata *nd, const char *path)
70963 {
70964 nd->saved_names[nd->depth] = path;
70965 }
70966
70967-static inline char *nd_get_link(struct nameidata *nd)
70968+static inline const char *nd_get_link(const struct nameidata *nd)
70969 {
70970 return nd->saved_names[nd->depth];
70971 }
70972diff --git a/include/linux/net.h b/include/linux/net.h
70973index 99c9f0c..e1cf296 100644
70974--- a/include/linux/net.h
70975+++ b/include/linux/net.h
70976@@ -183,7 +183,7 @@ struct net_proto_family {
70977 int (*create)(struct net *net, struct socket *sock,
70978 int protocol, int kern);
70979 struct module *owner;
70980-};
70981+} __do_const;
70982
70983 struct iovec;
70984 struct kvec;
70985diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
70986index 96e4c21..9cc8278 100644
70987--- a/include/linux/netdevice.h
70988+++ b/include/linux/netdevice.h
70989@@ -1026,6 +1026,7 @@ struct net_device_ops {
70990 int (*ndo_change_carrier)(struct net_device *dev,
70991 bool new_carrier);
70992 };
70993+typedef struct net_device_ops __no_const net_device_ops_no_const;
70994
70995 /*
70996 * The DEVICE structure.
70997@@ -1094,7 +1095,7 @@ struct net_device {
70998 int iflink;
70999
71000 struct net_device_stats stats;
71001- atomic_long_t rx_dropped; /* dropped packets by core network
71002+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
71003 * Do not use this in drivers.
71004 */
71005
71006diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
71007index 0060fde..481c6ae 100644
71008--- a/include/linux/netfilter.h
71009+++ b/include/linux/netfilter.h
71010@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
71011 #endif
71012 /* Use the module struct to lock set/get code in place */
71013 struct module *owner;
71014-};
71015+} __do_const;
71016
71017 /* Function to register/unregister hook points. */
71018 int nf_register_hook(struct nf_hook_ops *reg);
71019diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
71020index d80e275..c3510b8 100644
71021--- a/include/linux/netfilter/ipset/ip_set.h
71022+++ b/include/linux/netfilter/ipset/ip_set.h
71023@@ -124,7 +124,7 @@ struct ip_set_type_variant {
71024 /* Return true if "b" set is the same as "a"
71025 * according to the create set parameters */
71026 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
71027-};
71028+} __do_const;
71029
71030 /* The core set type structure */
71031 struct ip_set_type {
71032diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
71033index cadb740..d7c37c0 100644
71034--- a/include/linux/netfilter/nfnetlink.h
71035+++ b/include/linux/netfilter/nfnetlink.h
71036@@ -16,7 +16,7 @@ struct nfnl_callback {
71037 const struct nlattr * const cda[]);
71038 const struct nla_policy *policy; /* netlink attribute policy */
71039 const u_int16_t attr_count; /* number of nlattr's */
71040-};
71041+} __do_const;
71042
71043 struct nfnetlink_subsystem {
71044 const char *name;
71045diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
71046new file mode 100644
71047index 0000000..33f4af8
71048--- /dev/null
71049+++ b/include/linux/netfilter/xt_gradm.h
71050@@ -0,0 +1,9 @@
71051+#ifndef _LINUX_NETFILTER_XT_GRADM_H
71052+#define _LINUX_NETFILTER_XT_GRADM_H 1
71053+
71054+struct xt_gradm_mtinfo {
71055+ __u16 flags;
71056+ __u16 invflags;
71057+};
71058+
71059+#endif
71060diff --git a/include/linux/nls.h b/include/linux/nls.h
71061index 5dc635f..35f5e11 100644
71062--- a/include/linux/nls.h
71063+++ b/include/linux/nls.h
71064@@ -31,7 +31,7 @@ struct nls_table {
71065 const unsigned char *charset2upper;
71066 struct module *owner;
71067 struct nls_table *next;
71068-};
71069+} __do_const;
71070
71071 /* this value hold the maximum octet of charset */
71072 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
71073diff --git a/include/linux/notifier.h b/include/linux/notifier.h
71074index d14a4c3..a078786 100644
71075--- a/include/linux/notifier.h
71076+++ b/include/linux/notifier.h
71077@@ -54,7 +54,8 @@ struct notifier_block {
71078 notifier_fn_t notifier_call;
71079 struct notifier_block __rcu *next;
71080 int priority;
71081-};
71082+} __do_const;
71083+typedef struct notifier_block __no_const notifier_block_no_const;
71084
71085 struct atomic_notifier_head {
71086 spinlock_t lock;
71087diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
71088index a4c5624..79d6d88 100644
71089--- a/include/linux/oprofile.h
71090+++ b/include/linux/oprofile.h
71091@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
71092 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
71093 char const * name, ulong * val);
71094
71095-/** Create a file for read-only access to an atomic_t. */
71096+/** Create a file for read-only access to an atomic_unchecked_t. */
71097 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
71098- char const * name, atomic_t * val);
71099+ char const * name, atomic_unchecked_t * val);
71100
71101 /** create a directory */
71102 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
71103diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
71104index 8db71dc..a76bf2c 100644
71105--- a/include/linux/pci_hotplug.h
71106+++ b/include/linux/pci_hotplug.h
71107@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
71108 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
71109 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
71110 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
71111-};
71112+} __do_const;
71113+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
71114
71115 /**
71116 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
71117diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
71118index c5b6dbf..b124155 100644
71119--- a/include/linux/perf_event.h
71120+++ b/include/linux/perf_event.h
71121@@ -318,8 +318,8 @@ struct perf_event {
71122
71123 enum perf_event_active_state state;
71124 unsigned int attach_state;
71125- local64_t count;
71126- atomic64_t child_count;
71127+ local64_t count; /* PaX: fix it one day */
71128+ atomic64_unchecked_t child_count;
71129
71130 /*
71131 * These are the total time in nanoseconds that the event
71132@@ -370,8 +370,8 @@ struct perf_event {
71133 * These accumulate total time (in nanoseconds) that children
71134 * events have been enabled and running, respectively.
71135 */
71136- atomic64_t child_total_time_enabled;
71137- atomic64_t child_total_time_running;
71138+ atomic64_unchecked_t child_total_time_enabled;
71139+ atomic64_unchecked_t child_total_time_running;
71140
71141 /*
71142 * Protect attach/detach and child_list:
71143@@ -692,7 +692,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
71144 entry->ip[entry->nr++] = ip;
71145 }
71146
71147-extern int sysctl_perf_event_paranoid;
71148+extern int sysctl_perf_event_legitimately_concerned;
71149 extern int sysctl_perf_event_mlock;
71150 extern int sysctl_perf_event_sample_rate;
71151
71152@@ -700,19 +700,24 @@ extern int perf_proc_update_handler(struct ctl_table *table, int write,
71153 void __user *buffer, size_t *lenp,
71154 loff_t *ppos);
71155
71156+static inline bool perf_paranoid_any(void)
71157+{
71158+ return sysctl_perf_event_legitimately_concerned > 2;
71159+}
71160+
71161 static inline bool perf_paranoid_tracepoint_raw(void)
71162 {
71163- return sysctl_perf_event_paranoid > -1;
71164+ return sysctl_perf_event_legitimately_concerned > -1;
71165 }
71166
71167 static inline bool perf_paranoid_cpu(void)
71168 {
71169- return sysctl_perf_event_paranoid > 0;
71170+ return sysctl_perf_event_legitimately_concerned > 0;
71171 }
71172
71173 static inline bool perf_paranoid_kernel(void)
71174 {
71175- return sysctl_perf_event_paranoid > 1;
71176+ return sysctl_perf_event_legitimately_concerned > 1;
71177 }
71178
71179 extern void perf_event_init(void);
71180@@ -806,7 +811,7 @@ static inline void perf_restore_debug_store(void) { }
71181 */
71182 #define perf_cpu_notifier(fn) \
71183 do { \
71184- static struct notifier_block fn##_nb __cpuinitdata = \
71185+ static struct notifier_block fn##_nb = \
71186 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
71187 unsigned long cpu = smp_processor_id(); \
71188 unsigned long flags; \
71189@@ -826,7 +831,7 @@ struct perf_pmu_events_attr {
71190 struct device_attribute attr;
71191 u64 id;
71192 const char *event_str;
71193-};
71194+} __do_const;
71195
71196 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
71197 static struct perf_pmu_events_attr _var = { \
71198diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
71199index b8809fe..ae4ccd0 100644
71200--- a/include/linux/pipe_fs_i.h
71201+++ b/include/linux/pipe_fs_i.h
71202@@ -47,10 +47,10 @@ struct pipe_inode_info {
71203 struct mutex mutex;
71204 wait_queue_head_t wait;
71205 unsigned int nrbufs, curbuf, buffers;
71206- unsigned int readers;
71207- unsigned int writers;
71208- unsigned int files;
71209- unsigned int waiting_writers;
71210+ atomic_t readers;
71211+ atomic_t writers;
71212+ atomic_t files;
71213+ atomic_t waiting_writers;
71214 unsigned int r_counter;
71215 unsigned int w_counter;
71216 struct page *tmp_page;
71217diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
71218index 5f28cae..3d23723 100644
71219--- a/include/linux/platform_data/usb-ehci-s5p.h
71220+++ b/include/linux/platform_data/usb-ehci-s5p.h
71221@@ -14,7 +14,7 @@
71222 struct s5p_ehci_platdata {
71223 int (*phy_init)(struct platform_device *pdev, int type);
71224 int (*phy_exit)(struct platform_device *pdev, int type);
71225-};
71226+} __no_const;
71227
71228 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
71229
71230diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
71231index c256c59..8ea94c7 100644
71232--- a/include/linux/platform_data/usb-ohci-exynos.h
71233+++ b/include/linux/platform_data/usb-ohci-exynos.h
71234@@ -14,7 +14,7 @@
71235 struct exynos4_ohci_platdata {
71236 int (*phy_init)(struct platform_device *pdev, int type);
71237 int (*phy_exit)(struct platform_device *pdev, int type);
71238-};
71239+} __no_const;
71240
71241 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
71242
71243diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
71244index 7c1d252..c5c773e 100644
71245--- a/include/linux/pm_domain.h
71246+++ b/include/linux/pm_domain.h
71247@@ -48,7 +48,7 @@ struct gpd_dev_ops {
71248
71249 struct gpd_cpu_data {
71250 unsigned int saved_exit_latency;
71251- struct cpuidle_state *idle_state;
71252+ cpuidle_state_no_const *idle_state;
71253 };
71254
71255 struct generic_pm_domain {
71256diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
71257index 7d7e09e..8671ef8 100644
71258--- a/include/linux/pm_runtime.h
71259+++ b/include/linux/pm_runtime.h
71260@@ -104,7 +104,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
71261
71262 static inline void pm_runtime_mark_last_busy(struct device *dev)
71263 {
71264- ACCESS_ONCE(dev->power.last_busy) = jiffies;
71265+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
71266 }
71267
71268 #else /* !CONFIG_PM_RUNTIME */
71269diff --git a/include/linux/pnp.h b/include/linux/pnp.h
71270index 195aafc..49a7bc2 100644
71271--- a/include/linux/pnp.h
71272+++ b/include/linux/pnp.h
71273@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
71274 struct pnp_fixup {
71275 char id[7];
71276 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
71277-};
71278+} __do_const;
71279
71280 /* config parameters */
71281 #define PNP_CONFIG_NORMAL 0x0001
71282diff --git a/include/linux/poison.h b/include/linux/poison.h
71283index 2110a81..13a11bb 100644
71284--- a/include/linux/poison.h
71285+++ b/include/linux/poison.h
71286@@ -19,8 +19,8 @@
71287 * under normal circumstances, used to verify that nobody uses
71288 * non-initialized list entries.
71289 */
71290-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
71291-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
71292+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
71293+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
71294
71295 /********** include/linux/timer.h **********/
71296 /*
71297diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
71298index c0f44c2..1572583 100644
71299--- a/include/linux/power/smartreflex.h
71300+++ b/include/linux/power/smartreflex.h
71301@@ -238,7 +238,7 @@ struct omap_sr_class_data {
71302 int (*notify)(struct omap_sr *sr, u32 status);
71303 u8 notify_flags;
71304 u8 class_type;
71305-};
71306+} __do_const;
71307
71308 /**
71309 * struct omap_sr_nvalue_table - Smartreflex n-target value info
71310diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
71311index 4ea1d37..80f4b33 100644
71312--- a/include/linux/ppp-comp.h
71313+++ b/include/linux/ppp-comp.h
71314@@ -84,7 +84,7 @@ struct compressor {
71315 struct module *owner;
71316 /* Extra skb space needed by the compressor algorithm */
71317 unsigned int comp_extra;
71318-};
71319+} __do_const;
71320
71321 /*
71322 * The return value from decompress routine is the length of the
71323diff --git a/include/linux/printk.h b/include/linux/printk.h
71324index 22c7052..ad3fa0a 100644
71325--- a/include/linux/printk.h
71326+++ b/include/linux/printk.h
71327@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
71328 void early_printk(const char *s, ...) { }
71329 #endif
71330
71331+extern int kptr_restrict;
71332+
71333 #ifdef CONFIG_PRINTK
71334 asmlinkage __printf(5, 0)
71335 int vprintk_emit(int facility, int level,
71336@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
71337
71338 extern int printk_delay_msec;
71339 extern int dmesg_restrict;
71340-extern int kptr_restrict;
71341
71342 extern void wake_up_klogd(void);
71343
71344diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
71345index 608e60a..c26f864 100644
71346--- a/include/linux/proc_fs.h
71347+++ b/include/linux/proc_fs.h
71348@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
71349 return proc_create_data(name, mode, parent, proc_fops, NULL);
71350 }
71351
71352+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
71353+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
71354+{
71355+#ifdef CONFIG_GRKERNSEC_PROC_USER
71356+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
71357+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71358+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
71359+#else
71360+ return proc_create_data(name, mode, parent, proc_fops, NULL);
71361+#endif
71362+}
71363+
71364+
71365 extern void proc_set_size(struct proc_dir_entry *, loff_t);
71366 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
71367 extern void *PDE_DATA(const struct inode *);
71368diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
71369index 34a1e10..03a6d03 100644
71370--- a/include/linux/proc_ns.h
71371+++ b/include/linux/proc_ns.h
71372@@ -14,7 +14,7 @@ struct proc_ns_operations {
71373 void (*put)(void *ns);
71374 int (*install)(struct nsproxy *nsproxy, void *ns);
71375 unsigned int (*inum)(void *ns);
71376-};
71377+} __do_const;
71378
71379 struct proc_ns {
71380 void *ns;
71381diff --git a/include/linux/random.h b/include/linux/random.h
71382index 3b9377d..61b506a 100644
71383--- a/include/linux/random.h
71384+++ b/include/linux/random.h
71385@@ -32,6 +32,11 @@ void prandom_seed(u32 seed);
71386 u32 prandom_u32_state(struct rnd_state *);
71387 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
71388
71389+static inline unsigned long pax_get_random_long(void)
71390+{
71391+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
71392+}
71393+
71394 /*
71395 * Handle minimum values for seeds
71396 */
71397diff --git a/include/linux/rculist.h b/include/linux/rculist.h
71398index f4b1001..8ddb2b6 100644
71399--- a/include/linux/rculist.h
71400+++ b/include/linux/rculist.h
71401@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
71402 struct list_head *prev, struct list_head *next);
71403 #endif
71404
71405+extern void __pax_list_add_rcu(struct list_head *new,
71406+ struct list_head *prev, struct list_head *next);
71407+
71408 /**
71409 * list_add_rcu - add a new entry to rcu-protected list
71410 * @new: new entry to be added
71411@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
71412 __list_add_rcu(new, head, head->next);
71413 }
71414
71415+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
71416+{
71417+ __pax_list_add_rcu(new, head, head->next);
71418+}
71419+
71420 /**
71421 * list_add_tail_rcu - add a new entry to rcu-protected list
71422 * @new: new entry to be added
71423@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
71424 __list_add_rcu(new, head->prev, head);
71425 }
71426
71427+static inline void pax_list_add_tail_rcu(struct list_head *new,
71428+ struct list_head *head)
71429+{
71430+ __pax_list_add_rcu(new, head->prev, head);
71431+}
71432+
71433 /**
71434 * list_del_rcu - deletes entry from list without re-initialization
71435 * @entry: the element to delete from the list.
71436@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
71437 entry->prev = LIST_POISON2;
71438 }
71439
71440+extern void pax_list_del_rcu(struct list_head *entry);
71441+
71442 /**
71443 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
71444 * @n: the element to delete from the hash list.
71445diff --git a/include/linux/reboot.h b/include/linux/reboot.h
71446index 23b3630..e1bc12b 100644
71447--- a/include/linux/reboot.h
71448+++ b/include/linux/reboot.h
71449@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
71450 * Architecture-specific implementations of sys_reboot commands.
71451 */
71452
71453-extern void machine_restart(char *cmd);
71454-extern void machine_halt(void);
71455-extern void machine_power_off(void);
71456+extern void machine_restart(char *cmd) __noreturn;
71457+extern void machine_halt(void) __noreturn;
71458+extern void machine_power_off(void) __noreturn;
71459
71460 extern void machine_shutdown(void);
71461 struct pt_regs;
71462@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
71463 */
71464
71465 extern void kernel_restart_prepare(char *cmd);
71466-extern void kernel_restart(char *cmd);
71467-extern void kernel_halt(void);
71468-extern void kernel_power_off(void);
71469+extern void kernel_restart(char *cmd) __noreturn;
71470+extern void kernel_halt(void) __noreturn;
71471+extern void kernel_power_off(void) __noreturn;
71472
71473 extern int C_A_D; /* for sysctl */
71474 void ctrl_alt_del(void);
71475@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
71476 * Emergency restart, callable from an interrupt handler.
71477 */
71478
71479-extern void emergency_restart(void);
71480+extern void emergency_restart(void) __noreturn;
71481 #include <asm/emergency-restart.h>
71482
71483 #endif /* _LINUX_REBOOT_H */
71484diff --git a/include/linux/regset.h b/include/linux/regset.h
71485index 8e0c9fe..ac4d221 100644
71486--- a/include/linux/regset.h
71487+++ b/include/linux/regset.h
71488@@ -161,7 +161,8 @@ struct user_regset {
71489 unsigned int align;
71490 unsigned int bias;
71491 unsigned int core_note_type;
71492-};
71493+} __do_const;
71494+typedef struct user_regset __no_const user_regset_no_const;
71495
71496 /**
71497 * struct user_regset_view - available regsets
71498diff --git a/include/linux/relay.h b/include/linux/relay.h
71499index d7c8359..818daf5 100644
71500--- a/include/linux/relay.h
71501+++ b/include/linux/relay.h
71502@@ -157,7 +157,7 @@ struct rchan_callbacks
71503 * The callback should return 0 if successful, negative if not.
71504 */
71505 int (*remove_buf_file)(struct dentry *dentry);
71506-};
71507+} __no_const;
71508
71509 /*
71510 * CONFIG_RELAY kernel API, kernel/relay.c
71511diff --git a/include/linux/rio.h b/include/linux/rio.h
71512index 18e0993..8ab5b21 100644
71513--- a/include/linux/rio.h
71514+++ b/include/linux/rio.h
71515@@ -345,7 +345,7 @@ struct rio_ops {
71516 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
71517 u64 rstart, u32 size, u32 flags);
71518 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
71519-};
71520+} __no_const;
71521
71522 #define RIO_RESOURCE_MEM 0x00000100
71523 #define RIO_RESOURCE_DOORBELL 0x00000200
71524diff --git a/include/linux/rmap.h b/include/linux/rmap.h
71525index 6dacb93..6174423 100644
71526--- a/include/linux/rmap.h
71527+++ b/include/linux/rmap.h
71528@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
71529 void anon_vma_init(void); /* create anon_vma_cachep */
71530 int anon_vma_prepare(struct vm_area_struct *);
71531 void unlink_anon_vmas(struct vm_area_struct *);
71532-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
71533-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
71534+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
71535+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
71536
71537 static inline void anon_vma_merge(struct vm_area_struct *vma,
71538 struct vm_area_struct *next)
71539diff --git a/include/linux/sched.h b/include/linux/sched.h
71540index 178a8d9..52e71a3 100644
71541--- a/include/linux/sched.h
71542+++ b/include/linux/sched.h
71543@@ -62,6 +62,7 @@ struct bio_list;
71544 struct fs_struct;
71545 struct perf_event_context;
71546 struct blk_plug;
71547+struct linux_binprm;
71548
71549 /*
71550 * List of flags we want to share for kernel threads,
71551@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
71552 extern int in_sched_functions(unsigned long addr);
71553
71554 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
71555-extern signed long schedule_timeout(signed long timeout);
71556+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
71557 extern signed long schedule_timeout_interruptible(signed long timeout);
71558 extern signed long schedule_timeout_killable(signed long timeout);
71559 extern signed long schedule_timeout_uninterruptible(signed long timeout);
71560@@ -314,6 +315,19 @@ struct nsproxy;
71561 struct user_namespace;
71562
71563 #ifdef CONFIG_MMU
71564+
71565+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
71566+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
71567+#else
71568+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
71569+{
71570+ return 0;
71571+}
71572+#endif
71573+
71574+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
71575+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
71576+
71577 extern void arch_pick_mmap_layout(struct mm_struct *mm);
71578 extern unsigned long
71579 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
71580@@ -591,6 +605,17 @@ struct signal_struct {
71581 #ifdef CONFIG_TASKSTATS
71582 struct taskstats *stats;
71583 #endif
71584+
71585+#ifdef CONFIG_GRKERNSEC
71586+ u32 curr_ip;
71587+ u32 saved_ip;
71588+ u32 gr_saddr;
71589+ u32 gr_daddr;
71590+ u16 gr_sport;
71591+ u16 gr_dport;
71592+ u8 used_accept:1;
71593+#endif
71594+
71595 #ifdef CONFIG_AUDIT
71596 unsigned audit_tty;
71597 unsigned audit_tty_log_passwd;
71598@@ -671,6 +696,14 @@ struct user_struct {
71599 struct key *session_keyring; /* UID's default session keyring */
71600 #endif
71601
71602+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71603+ unsigned char kernel_banned;
71604+#endif
71605+#ifdef CONFIG_GRKERNSEC_BRUTE
71606+ unsigned char suid_banned;
71607+ unsigned long suid_ban_expires;
71608+#endif
71609+
71610 /* Hash table maintenance information */
71611 struct hlist_node uidhash_node;
71612 kuid_t uid;
71613@@ -1158,8 +1191,8 @@ struct task_struct {
71614 struct list_head thread_group;
71615
71616 struct completion *vfork_done; /* for vfork() */
71617- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
71618- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71619+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
71620+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71621
71622 cputime_t utime, stime, utimescaled, stimescaled;
71623 cputime_t gtime;
71624@@ -1184,11 +1217,6 @@ struct task_struct {
71625 struct task_cputime cputime_expires;
71626 struct list_head cpu_timers[3];
71627
71628-/* process credentials */
71629- const struct cred __rcu *real_cred; /* objective and real subjective task
71630- * credentials (COW) */
71631- const struct cred __rcu *cred; /* effective (overridable) subjective task
71632- * credentials (COW) */
71633 char comm[TASK_COMM_LEN]; /* executable name excluding path
71634 - access with [gs]et_task_comm (which lock
71635 it with task_lock())
71636@@ -1205,6 +1233,10 @@ struct task_struct {
71637 #endif
71638 /* CPU-specific state of this task */
71639 struct thread_struct thread;
71640+/* thread_info moved to task_struct */
71641+#ifdef CONFIG_X86
71642+ struct thread_info tinfo;
71643+#endif
71644 /* filesystem information */
71645 struct fs_struct *fs;
71646 /* open file information */
71647@@ -1278,6 +1310,10 @@ struct task_struct {
71648 gfp_t lockdep_reclaim_gfp;
71649 #endif
71650
71651+/* process credentials */
71652+ const struct cred __rcu *real_cred; /* objective and real subjective task
71653+ * credentials (COW) */
71654+
71655 /* journalling filesystem info */
71656 void *journal_info;
71657
71658@@ -1316,6 +1352,10 @@ struct task_struct {
71659 /* cg_list protected by css_set_lock and tsk->alloc_lock */
71660 struct list_head cg_list;
71661 #endif
71662+
71663+ const struct cred __rcu *cred; /* effective (overridable) subjective task
71664+ * credentials (COW) */
71665+
71666 #ifdef CONFIG_FUTEX
71667 struct robust_list_head __user *robust_list;
71668 #ifdef CONFIG_COMPAT
71669@@ -1416,8 +1456,74 @@ struct task_struct {
71670 unsigned int sequential_io;
71671 unsigned int sequential_io_avg;
71672 #endif
71673+
71674+#ifdef CONFIG_GRKERNSEC
71675+ /* grsecurity */
71676+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71677+ u64 exec_id;
71678+#endif
71679+#ifdef CONFIG_GRKERNSEC_SETXID
71680+ const struct cred *delayed_cred;
71681+#endif
71682+ struct dentry *gr_chroot_dentry;
71683+ struct acl_subject_label *acl;
71684+ struct acl_role_label *role;
71685+ struct file *exec_file;
71686+ unsigned long brute_expires;
71687+ u16 acl_role_id;
71688+ /* is this the task that authenticated to the special role */
71689+ u8 acl_sp_role;
71690+ u8 is_writable;
71691+ u8 brute;
71692+ u8 gr_is_chrooted;
71693+#endif
71694+
71695 };
71696
71697+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
71698+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
71699+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
71700+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
71701+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
71702+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
71703+
71704+#ifdef CONFIG_PAX_SOFTMODE
71705+extern int pax_softmode;
71706+#endif
71707+
71708+extern int pax_check_flags(unsigned long *);
71709+
71710+/* if tsk != current then task_lock must be held on it */
71711+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
71712+static inline unsigned long pax_get_flags(struct task_struct *tsk)
71713+{
71714+ if (likely(tsk->mm))
71715+ return tsk->mm->pax_flags;
71716+ else
71717+ return 0UL;
71718+}
71719+
71720+/* if tsk != current then task_lock must be held on it */
71721+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
71722+{
71723+ if (likely(tsk->mm)) {
71724+ tsk->mm->pax_flags = flags;
71725+ return 0;
71726+ }
71727+ return -EINVAL;
71728+}
71729+#endif
71730+
71731+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
71732+extern void pax_set_initial_flags(struct linux_binprm *bprm);
71733+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
71734+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
71735+#endif
71736+
71737+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
71738+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
71739+extern void pax_report_refcount_overflow(struct pt_regs *regs);
71740+
71741 /* Future-safe accessor for struct task_struct's cpus_allowed. */
71742 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
71743
71744@@ -1476,7 +1582,7 @@ struct pid_namespace;
71745 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
71746 struct pid_namespace *ns);
71747
71748-static inline pid_t task_pid_nr(struct task_struct *tsk)
71749+static inline pid_t task_pid_nr(const struct task_struct *tsk)
71750 {
71751 return tsk->pid;
71752 }
71753@@ -1919,7 +2025,9 @@ void yield(void);
71754 extern struct exec_domain default_exec_domain;
71755
71756 union thread_union {
71757+#ifndef CONFIG_X86
71758 struct thread_info thread_info;
71759+#endif
71760 unsigned long stack[THREAD_SIZE/sizeof(long)];
71761 };
71762
71763@@ -1952,6 +2060,7 @@ extern struct pid_namespace init_pid_ns;
71764 */
71765
71766 extern struct task_struct *find_task_by_vpid(pid_t nr);
71767+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
71768 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
71769 struct pid_namespace *ns);
71770
71771@@ -2118,7 +2227,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
71772 extern void exit_itimers(struct signal_struct *);
71773 extern void flush_itimer_signals(void);
71774
71775-extern void do_group_exit(int);
71776+extern __noreturn void do_group_exit(int);
71777
71778 extern int allow_signal(int);
71779 extern int disallow_signal(int);
71780@@ -2309,9 +2418,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
71781
71782 #endif
71783
71784-static inline int object_is_on_stack(void *obj)
71785+static inline int object_starts_on_stack(void *obj)
71786 {
71787- void *stack = task_stack_page(current);
71788+ const void *stack = task_stack_page(current);
71789
71790 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
71791 }
71792diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
71793index bf8086b..962b035 100644
71794--- a/include/linux/sched/sysctl.h
71795+++ b/include/linux/sched/sysctl.h
71796@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
71797 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
71798
71799 extern int sysctl_max_map_count;
71800+extern unsigned long sysctl_heap_stack_gap;
71801
71802 extern unsigned int sysctl_sched_latency;
71803 extern unsigned int sysctl_sched_min_granularity;
71804diff --git a/include/linux/security.h b/include/linux/security.h
71805index 4686491..2bd210e 100644
71806--- a/include/linux/security.h
71807+++ b/include/linux/security.h
71808@@ -26,6 +26,7 @@
71809 #include <linux/capability.h>
71810 #include <linux/slab.h>
71811 #include <linux/err.h>
71812+#include <linux/grsecurity.h>
71813
71814 struct linux_binprm;
71815 struct cred;
71816diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
71817index 2da29ac..aac448ec 100644
71818--- a/include/linux/seq_file.h
71819+++ b/include/linux/seq_file.h
71820@@ -26,6 +26,9 @@ struct seq_file {
71821 struct mutex lock;
71822 const struct seq_operations *op;
71823 int poll_event;
71824+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71825+ u64 exec_id;
71826+#endif
71827 #ifdef CONFIG_USER_NS
71828 struct user_namespace *user_ns;
71829 #endif
71830@@ -38,6 +41,7 @@ struct seq_operations {
71831 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
71832 int (*show) (struct seq_file *m, void *v);
71833 };
71834+typedef struct seq_operations __no_const seq_operations_no_const;
71835
71836 #define SEQ_SKIP 1
71837
71838diff --git a/include/linux/shm.h b/include/linux/shm.h
71839index 429c199..4d42e38 100644
71840--- a/include/linux/shm.h
71841+++ b/include/linux/shm.h
71842@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
71843
71844 /* The task created the shm object. NULL if the task is dead. */
71845 struct task_struct *shm_creator;
71846+#ifdef CONFIG_GRKERNSEC
71847+ time_t shm_createtime;
71848+ pid_t shm_lapid;
71849+#endif
71850 };
71851
71852 /* shm_mode upper byte flags */
71853diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
71854index dec1748..112c1f9 100644
71855--- a/include/linux/skbuff.h
71856+++ b/include/linux/skbuff.h
71857@@ -640,7 +640,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
71858 extern struct sk_buff *__alloc_skb(unsigned int size,
71859 gfp_t priority, int flags, int node);
71860 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
71861-static inline struct sk_buff *alloc_skb(unsigned int size,
71862+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
71863 gfp_t priority)
71864 {
71865 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
71866@@ -756,7 +756,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
71867 */
71868 static inline int skb_queue_empty(const struct sk_buff_head *list)
71869 {
71870- return list->next == (struct sk_buff *)list;
71871+ return list->next == (const struct sk_buff *)list;
71872 }
71873
71874 /**
71875@@ -769,7 +769,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
71876 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71877 const struct sk_buff *skb)
71878 {
71879- return skb->next == (struct sk_buff *)list;
71880+ return skb->next == (const struct sk_buff *)list;
71881 }
71882
71883 /**
71884@@ -782,7 +782,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71885 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
71886 const struct sk_buff *skb)
71887 {
71888- return skb->prev == (struct sk_buff *)list;
71889+ return skb->prev == (const struct sk_buff *)list;
71890 }
71891
71892 /**
71893@@ -1848,7 +1848,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
71894 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
71895 */
71896 #ifndef NET_SKB_PAD
71897-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
71898+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
71899 #endif
71900
71901 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
71902@@ -2443,7 +2443,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
71903 int noblock, int *err);
71904 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
71905 struct poll_table_struct *wait);
71906-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
71907+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
71908 int offset, struct iovec *to,
71909 int size);
71910 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
71911@@ -2733,6 +2733,9 @@ static inline void nf_reset(struct sk_buff *skb)
71912 nf_bridge_put(skb->nf_bridge);
71913 skb->nf_bridge = NULL;
71914 #endif
71915+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
71916+ skb->nf_trace = 0;
71917+#endif
71918 }
71919
71920 static inline void nf_reset_trace(struct sk_buff *skb)
71921diff --git a/include/linux/slab.h b/include/linux/slab.h
71922index 0c62175..9ece3d8 100644
71923--- a/include/linux/slab.h
71924+++ b/include/linux/slab.h
71925@@ -12,13 +12,20 @@
71926 #include <linux/gfp.h>
71927 #include <linux/types.h>
71928 #include <linux/workqueue.h>
71929-
71930+#include <linux/err.h>
71931
71932 /*
71933 * Flags to pass to kmem_cache_create().
71934 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
71935 */
71936 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
71937+
71938+#ifdef CONFIG_PAX_USERCOPY_SLABS
71939+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
71940+#else
71941+#define SLAB_USERCOPY 0x00000000UL
71942+#endif
71943+
71944 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
71945 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
71946 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
71947@@ -89,10 +96,13 @@
71948 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
71949 * Both make kfree a no-op.
71950 */
71951-#define ZERO_SIZE_PTR ((void *)16)
71952+#define ZERO_SIZE_PTR \
71953+({ \
71954+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
71955+ (void *)(-MAX_ERRNO-1L); \
71956+})
71957
71958-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
71959- (unsigned long)ZERO_SIZE_PTR)
71960+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
71961
71962
71963 struct mem_cgroup;
71964@@ -132,6 +142,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
71965 void kfree(const void *);
71966 void kzfree(const void *);
71967 size_t ksize(const void *);
71968+const char *check_heap_object(const void *ptr, unsigned long n);
71969+bool is_usercopy_object(const void *ptr);
71970
71971 /*
71972 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
71973@@ -164,7 +176,7 @@ struct kmem_cache {
71974 unsigned int align; /* Alignment as calculated */
71975 unsigned long flags; /* Active flags on the slab */
71976 const char *name; /* Slab name for sysfs */
71977- int refcount; /* Use counter */
71978+ atomic_t refcount; /* Use counter */
71979 void (*ctor)(void *); /* Called on object slot creation */
71980 struct list_head list; /* List of all slab caches on the system */
71981 };
71982@@ -226,6 +238,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
71983 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
71984 #endif
71985
71986+#ifdef CONFIG_PAX_USERCOPY_SLABS
71987+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
71988+#endif
71989+
71990 /*
71991 * Figure out which kmalloc slab an allocation of a certain size
71992 * belongs to.
71993@@ -234,7 +250,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
71994 * 2 = 120 .. 192 bytes
71995 * n = 2^(n-1) .. 2^n -1
71996 */
71997-static __always_inline int kmalloc_index(size_t size)
71998+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
71999 {
72000 if (!size)
72001 return 0;
72002@@ -406,6 +422,7 @@ void print_slabinfo_header(struct seq_file *m);
72003 * for general use, and so are not documented here. For a full list of
72004 * potential flags, always refer to linux/gfp.h.
72005 */
72006+
72007 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
72008 {
72009 if (size != 0 && n > SIZE_MAX / size)
72010@@ -465,7 +482,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
72011 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
72012 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
72013 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
72014-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
72015+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
72016 #define kmalloc_track_caller(size, flags) \
72017 __kmalloc_track_caller(size, flags, _RET_IP_)
72018 #else
72019@@ -485,7 +502,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
72020 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
72021 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
72022 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
72023-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
72024+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
72025 #define kmalloc_node_track_caller(size, flags, node) \
72026 __kmalloc_node_track_caller(size, flags, node, \
72027 _RET_IP_)
72028diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
72029index cd40158..d9dc02c 100644
72030--- a/include/linux/slab_def.h
72031+++ b/include/linux/slab_def.h
72032@@ -50,7 +50,7 @@ struct kmem_cache {
72033 /* 4) cache creation/removal */
72034 const char *name;
72035 struct list_head list;
72036- int refcount;
72037+ atomic_t refcount;
72038 int object_size;
72039 int align;
72040
72041@@ -66,10 +66,10 @@ struct kmem_cache {
72042 unsigned long node_allocs;
72043 unsigned long node_frees;
72044 unsigned long node_overflow;
72045- atomic_t allochit;
72046- atomic_t allocmiss;
72047- atomic_t freehit;
72048- atomic_t freemiss;
72049+ atomic_unchecked_t allochit;
72050+ atomic_unchecked_t allocmiss;
72051+ atomic_unchecked_t freehit;
72052+ atomic_unchecked_t freemiss;
72053
72054 /*
72055 * If debugging is enabled, then the allocator can add additional
72056@@ -103,7 +103,7 @@ struct kmem_cache {
72057 };
72058
72059 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
72060-void *__kmalloc(size_t size, gfp_t flags);
72061+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
72062
72063 #ifdef CONFIG_TRACING
72064 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
72065@@ -136,6 +136,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72066 cachep = kmalloc_dma_caches[i];
72067 else
72068 #endif
72069+
72070+#ifdef CONFIG_PAX_USERCOPY_SLABS
72071+ if (flags & GFP_USERCOPY)
72072+ cachep = kmalloc_usercopy_caches[i];
72073+ else
72074+#endif
72075+
72076 cachep = kmalloc_caches[i];
72077
72078 ret = kmem_cache_alloc_trace(cachep, flags, size);
72079@@ -146,7 +153,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72080 }
72081
72082 #ifdef CONFIG_NUMA
72083-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
72084+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72085 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72086
72087 #ifdef CONFIG_TRACING
72088@@ -185,6 +192,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
72089 cachep = kmalloc_dma_caches[i];
72090 else
72091 #endif
72092+
72093+#ifdef CONFIG_PAX_USERCOPY_SLABS
72094+ if (flags & GFP_USERCOPY)
72095+ cachep = kmalloc_usercopy_caches[i];
72096+ else
72097+#endif
72098+
72099 cachep = kmalloc_caches[i];
72100
72101 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
72102diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
72103index f28e14a..7831211 100644
72104--- a/include/linux/slob_def.h
72105+++ b/include/linux/slob_def.h
72106@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
72107 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
72108 }
72109
72110-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72111+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72112
72113 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
72114 {
72115@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72116 return __kmalloc_node(size, flags, NUMA_NO_NODE);
72117 }
72118
72119-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
72120+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
72121 {
72122 return kmalloc(size, flags);
72123 }
72124diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
72125index 027276f..092bfe8 100644
72126--- a/include/linux/slub_def.h
72127+++ b/include/linux/slub_def.h
72128@@ -80,7 +80,7 @@ struct kmem_cache {
72129 struct kmem_cache_order_objects max;
72130 struct kmem_cache_order_objects min;
72131 gfp_t allocflags; /* gfp flags to use on each alloc */
72132- int refcount; /* Refcount for slab cache destroy */
72133+ atomic_t refcount; /* Refcount for slab cache destroy */
72134 void (*ctor)(void *);
72135 int inuse; /* Offset to metadata */
72136 int align; /* Alignment */
72137@@ -105,7 +105,7 @@ struct kmem_cache {
72138 };
72139
72140 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
72141-void *__kmalloc(size_t size, gfp_t flags);
72142+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
72143
72144 static __always_inline void *
72145 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
72146@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
72147 }
72148 #endif
72149
72150-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
72151+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
72152 {
72153 unsigned int order = get_order(size);
72154 return kmalloc_order_trace(size, flags, order);
72155@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72156 }
72157
72158 #ifdef CONFIG_NUMA
72159-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72160+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72161 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72162
72163 #ifdef CONFIG_TRACING
72164diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
72165index 54f91d3..be2c379 100644
72166--- a/include/linux/sock_diag.h
72167+++ b/include/linux/sock_diag.h
72168@@ -11,7 +11,7 @@ struct sock;
72169 struct sock_diag_handler {
72170 __u8 family;
72171 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
72172-};
72173+} __do_const;
72174
72175 int sock_diag_register(const struct sock_diag_handler *h);
72176 void sock_diag_unregister(const struct sock_diag_handler *h);
72177diff --git a/include/linux/sonet.h b/include/linux/sonet.h
72178index 680f9a3..f13aeb0 100644
72179--- a/include/linux/sonet.h
72180+++ b/include/linux/sonet.h
72181@@ -7,7 +7,7 @@
72182 #include <uapi/linux/sonet.h>
72183
72184 struct k_sonet_stats {
72185-#define __HANDLE_ITEM(i) atomic_t i
72186+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72187 __SONET_ITEMS
72188 #undef __HANDLE_ITEM
72189 };
72190diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
72191index 07d8e53..dc934c9 100644
72192--- a/include/linux/sunrpc/addr.h
72193+++ b/include/linux/sunrpc/addr.h
72194@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
72195 {
72196 switch (sap->sa_family) {
72197 case AF_INET:
72198- return ntohs(((struct sockaddr_in *)sap)->sin_port);
72199+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
72200 case AF_INET6:
72201- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
72202+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
72203 }
72204 return 0;
72205 }
72206@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
72207 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
72208 const struct sockaddr *src)
72209 {
72210- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
72211+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
72212 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
72213
72214 dsin->sin_family = ssin->sin_family;
72215@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
72216 if (sa->sa_family != AF_INET6)
72217 return 0;
72218
72219- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
72220+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
72221 }
72222
72223 #endif /* _LINUX_SUNRPC_ADDR_H */
72224diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
72225index bfe11be..12bc8c4 100644
72226--- a/include/linux/sunrpc/clnt.h
72227+++ b/include/linux/sunrpc/clnt.h
72228@@ -96,7 +96,7 @@ struct rpc_procinfo {
72229 unsigned int p_timer; /* Which RTT timer to use */
72230 u32 p_statidx; /* Which procedure to account */
72231 const char * p_name; /* name of procedure */
72232-};
72233+} __do_const;
72234
72235 #ifdef __KERNEL__
72236
72237diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
72238index 1f0216b..6a4fa50 100644
72239--- a/include/linux/sunrpc/svc.h
72240+++ b/include/linux/sunrpc/svc.h
72241@@ -411,7 +411,7 @@ struct svc_procedure {
72242 unsigned int pc_count; /* call count */
72243 unsigned int pc_cachetype; /* cache info (NFS) */
72244 unsigned int pc_xdrressize; /* maximum size of XDR reply */
72245-};
72246+} __do_const;
72247
72248 /*
72249 * Function prototypes.
72250diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
72251index 0b8e3e6..33e0a01 100644
72252--- a/include/linux/sunrpc/svc_rdma.h
72253+++ b/include/linux/sunrpc/svc_rdma.h
72254@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
72255 extern unsigned int svcrdma_max_requests;
72256 extern unsigned int svcrdma_max_req_size;
72257
72258-extern atomic_t rdma_stat_recv;
72259-extern atomic_t rdma_stat_read;
72260-extern atomic_t rdma_stat_write;
72261-extern atomic_t rdma_stat_sq_starve;
72262-extern atomic_t rdma_stat_rq_starve;
72263-extern atomic_t rdma_stat_rq_poll;
72264-extern atomic_t rdma_stat_rq_prod;
72265-extern atomic_t rdma_stat_sq_poll;
72266-extern atomic_t rdma_stat_sq_prod;
72267+extern atomic_unchecked_t rdma_stat_recv;
72268+extern atomic_unchecked_t rdma_stat_read;
72269+extern atomic_unchecked_t rdma_stat_write;
72270+extern atomic_unchecked_t rdma_stat_sq_starve;
72271+extern atomic_unchecked_t rdma_stat_rq_starve;
72272+extern atomic_unchecked_t rdma_stat_rq_poll;
72273+extern atomic_unchecked_t rdma_stat_rq_prod;
72274+extern atomic_unchecked_t rdma_stat_sq_poll;
72275+extern atomic_unchecked_t rdma_stat_sq_prod;
72276
72277 #define RPCRDMA_VERSION 1
72278
72279diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
72280index ff374ab..7fd2ecb 100644
72281--- a/include/linux/sunrpc/svcauth.h
72282+++ b/include/linux/sunrpc/svcauth.h
72283@@ -109,7 +109,7 @@ struct auth_ops {
72284 int (*release)(struct svc_rqst *rq);
72285 void (*domain_release)(struct auth_domain *);
72286 int (*set_client)(struct svc_rqst *rq);
72287-};
72288+} __do_const;
72289
72290 #define SVC_GARBAGE 1
72291 #define SVC_SYSERR 2
72292diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
72293index a5ffd32..0935dea 100644
72294--- a/include/linux/swiotlb.h
72295+++ b/include/linux/swiotlb.h
72296@@ -60,7 +60,8 @@ extern void
72297
72298 extern void
72299 swiotlb_free_coherent(struct device *hwdev, size_t size,
72300- void *vaddr, dma_addr_t dma_handle);
72301+ void *vaddr, dma_addr_t dma_handle,
72302+ struct dma_attrs *attrs);
72303
72304 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
72305 unsigned long offset, size_t size,
72306diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
72307index 4147d70..31a1791 100644
72308--- a/include/linux/syscalls.h
72309+++ b/include/linux/syscalls.h
72310@@ -362,11 +362,11 @@ asmlinkage long sys_sync(void);
72311 asmlinkage long sys_fsync(unsigned int fd);
72312 asmlinkage long sys_fdatasync(unsigned int fd);
72313 asmlinkage long sys_bdflush(int func, long data);
72314-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
72315- char __user *type, unsigned long flags,
72316+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
72317+ const char __user *type, unsigned long flags,
72318 void __user *data);
72319-asmlinkage long sys_umount(char __user *name, int flags);
72320-asmlinkage long sys_oldumount(char __user *name);
72321+asmlinkage long sys_umount(const char __user *name, int flags);
72322+asmlinkage long sys_oldumount(const char __user *name);
72323 asmlinkage long sys_truncate(const char __user *path, long length);
72324 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
72325 asmlinkage long sys_stat(const char __user *filename,
72326@@ -578,7 +578,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
72327 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
72328 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
72329 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
72330- struct sockaddr __user *, int);
72331+ struct sockaddr __user *, int) __intentional_overflow(0);
72332 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
72333 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
72334 unsigned int vlen, unsigned flags);
72335diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
72336index 27b3b0b..e093dd9 100644
72337--- a/include/linux/syscore_ops.h
72338+++ b/include/linux/syscore_ops.h
72339@@ -16,7 +16,7 @@ struct syscore_ops {
72340 int (*suspend)(void);
72341 void (*resume)(void);
72342 void (*shutdown)(void);
72343-};
72344+} __do_const;
72345
72346 extern void register_syscore_ops(struct syscore_ops *ops);
72347 extern void unregister_syscore_ops(struct syscore_ops *ops);
72348diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
72349index 14a8ff2..af52bad 100644
72350--- a/include/linux/sysctl.h
72351+++ b/include/linux/sysctl.h
72352@@ -34,13 +34,13 @@ struct ctl_table_root;
72353 struct ctl_table_header;
72354 struct ctl_dir;
72355
72356-typedef struct ctl_table ctl_table;
72357-
72358 typedef int proc_handler (struct ctl_table *ctl, int write,
72359 void __user *buffer, size_t *lenp, loff_t *ppos);
72360
72361 extern int proc_dostring(struct ctl_table *, int,
72362 void __user *, size_t *, loff_t *);
72363+extern int proc_dostring_modpriv(struct ctl_table *, int,
72364+ void __user *, size_t *, loff_t *);
72365 extern int proc_dointvec(struct ctl_table *, int,
72366 void __user *, size_t *, loff_t *);
72367 extern int proc_dointvec_minmax(struct ctl_table *, int,
72368@@ -115,7 +115,9 @@ struct ctl_table
72369 struct ctl_table_poll *poll;
72370 void *extra1;
72371 void *extra2;
72372-};
72373+} __do_const;
72374+typedef struct ctl_table __no_const ctl_table_no_const;
72375+typedef struct ctl_table ctl_table;
72376
72377 struct ctl_node {
72378 struct rb_node node;
72379diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
72380index e2cee22..3ddb921 100644
72381--- a/include/linux/sysfs.h
72382+++ b/include/linux/sysfs.h
72383@@ -31,7 +31,8 @@ struct attribute {
72384 struct lock_class_key *key;
72385 struct lock_class_key skey;
72386 #endif
72387-};
72388+} __do_const;
72389+typedef struct attribute __no_const attribute_no_const;
72390
72391 /**
72392 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
72393@@ -59,8 +60,8 @@ struct attribute_group {
72394 umode_t (*is_visible)(struct kobject *,
72395 struct attribute *, int);
72396 struct attribute **attrs;
72397-};
72398-
72399+} __do_const;
72400+typedef struct attribute_group __no_const attribute_group_no_const;
72401
72402
72403 /**
72404@@ -107,7 +108,8 @@ struct bin_attribute {
72405 char *, loff_t, size_t);
72406 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
72407 struct vm_area_struct *vma);
72408-};
72409+} __do_const;
72410+typedef struct bin_attribute __no_const bin_attribute_no_const;
72411
72412 /**
72413 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
72414diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
72415index 7faf933..9b85a0c 100644
72416--- a/include/linux/sysrq.h
72417+++ b/include/linux/sysrq.h
72418@@ -16,6 +16,7 @@
72419
72420 #include <linux/errno.h>
72421 #include <linux/types.h>
72422+#include <linux/compiler.h>
72423
72424 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
72425 #define SYSRQ_DEFAULT_ENABLE 1
72426@@ -36,7 +37,7 @@ struct sysrq_key_op {
72427 char *help_msg;
72428 char *action_msg;
72429 int enable_mask;
72430-};
72431+} __do_const;
72432
72433 #ifdef CONFIG_MAGIC_SYSRQ
72434
72435diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
72436index e7e0473..7989295 100644
72437--- a/include/linux/thread_info.h
72438+++ b/include/linux/thread_info.h
72439@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
72440 #error "no set_restore_sigmask() provided and default one won't work"
72441 #endif
72442
72443+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
72444+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
72445+{
72446+#ifndef CONFIG_PAX_USERCOPY_DEBUG
72447+ if (!__builtin_constant_p(n))
72448+#endif
72449+ __check_object_size(ptr, n, to_user);
72450+}
72451+
72452 #endif /* __KERNEL__ */
72453
72454 #endif /* _LINUX_THREAD_INFO_H */
72455diff --git a/include/linux/tty.h b/include/linux/tty.h
72456index 8780bd2..d1ae08b 100644
72457--- a/include/linux/tty.h
72458+++ b/include/linux/tty.h
72459@@ -194,7 +194,7 @@ struct tty_port {
72460 const struct tty_port_operations *ops; /* Port operations */
72461 spinlock_t lock; /* Lock protecting tty field */
72462 int blocked_open; /* Waiting to open */
72463- int count; /* Usage count */
72464+ atomic_t count; /* Usage count */
72465 wait_queue_head_t open_wait; /* Open waiters */
72466 wait_queue_head_t close_wait; /* Close waiters */
72467 wait_queue_head_t delta_msr_wait; /* Modem status change */
72468@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
72469 struct tty_struct *tty, struct file *filp);
72470 static inline int tty_port_users(struct tty_port *port)
72471 {
72472- return port->count + port->blocked_open;
72473+ return atomic_read(&port->count) + port->blocked_open;
72474 }
72475
72476 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
72477diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
72478index 756a609..b302dd6 100644
72479--- a/include/linux/tty_driver.h
72480+++ b/include/linux/tty_driver.h
72481@@ -285,7 +285,7 @@ struct tty_operations {
72482 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
72483 #endif
72484 const struct file_operations *proc_fops;
72485-};
72486+} __do_const;
72487
72488 struct tty_driver {
72489 int magic; /* magic number for this structure */
72490diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
72491index 58390c7..95e214c 100644
72492--- a/include/linux/tty_ldisc.h
72493+++ b/include/linux/tty_ldisc.h
72494@@ -146,7 +146,7 @@ struct tty_ldisc_ops {
72495
72496 struct module *owner;
72497
72498- int refcount;
72499+ atomic_t refcount;
72500 };
72501
72502 struct tty_ldisc {
72503diff --git a/include/linux/types.h b/include/linux/types.h
72504index 4d118ba..c3ee9bf 100644
72505--- a/include/linux/types.h
72506+++ b/include/linux/types.h
72507@@ -176,10 +176,26 @@ typedef struct {
72508 int counter;
72509 } atomic_t;
72510
72511+#ifdef CONFIG_PAX_REFCOUNT
72512+typedef struct {
72513+ int counter;
72514+} atomic_unchecked_t;
72515+#else
72516+typedef atomic_t atomic_unchecked_t;
72517+#endif
72518+
72519 #ifdef CONFIG_64BIT
72520 typedef struct {
72521 long counter;
72522 } atomic64_t;
72523+
72524+#ifdef CONFIG_PAX_REFCOUNT
72525+typedef struct {
72526+ long counter;
72527+} atomic64_unchecked_t;
72528+#else
72529+typedef atomic64_t atomic64_unchecked_t;
72530+#endif
72531 #endif
72532
72533 struct list_head {
72534diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
72535index 5ca0951..ab496a5 100644
72536--- a/include/linux/uaccess.h
72537+++ b/include/linux/uaccess.h
72538@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
72539 long ret; \
72540 mm_segment_t old_fs = get_fs(); \
72541 \
72542- set_fs(KERNEL_DS); \
72543 pagefault_disable(); \
72544- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
72545- pagefault_enable(); \
72546+ set_fs(KERNEL_DS); \
72547+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
72548 set_fs(old_fs); \
72549+ pagefault_enable(); \
72550 ret; \
72551 })
72552
72553diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
72554index 8e522cbc..aa8572d 100644
72555--- a/include/linux/uidgid.h
72556+++ b/include/linux/uidgid.h
72557@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
72558
72559 #endif /* CONFIG_USER_NS */
72560
72561+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
72562+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
72563+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
72564+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
72565+
72566 #endif /* _LINUX_UIDGID_H */
72567diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
72568index 99c1b4d..562e6f3 100644
72569--- a/include/linux/unaligned/access_ok.h
72570+++ b/include/linux/unaligned/access_ok.h
72571@@ -4,34 +4,34 @@
72572 #include <linux/kernel.h>
72573 #include <asm/byteorder.h>
72574
72575-static inline u16 get_unaligned_le16(const void *p)
72576+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
72577 {
72578- return le16_to_cpup((__le16 *)p);
72579+ return le16_to_cpup((const __le16 *)p);
72580 }
72581
72582-static inline u32 get_unaligned_le32(const void *p)
72583+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
72584 {
72585- return le32_to_cpup((__le32 *)p);
72586+ return le32_to_cpup((const __le32 *)p);
72587 }
72588
72589-static inline u64 get_unaligned_le64(const void *p)
72590+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
72591 {
72592- return le64_to_cpup((__le64 *)p);
72593+ return le64_to_cpup((const __le64 *)p);
72594 }
72595
72596-static inline u16 get_unaligned_be16(const void *p)
72597+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
72598 {
72599- return be16_to_cpup((__be16 *)p);
72600+ return be16_to_cpup((const __be16 *)p);
72601 }
72602
72603-static inline u32 get_unaligned_be32(const void *p)
72604+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
72605 {
72606- return be32_to_cpup((__be32 *)p);
72607+ return be32_to_cpup((const __be32 *)p);
72608 }
72609
72610-static inline u64 get_unaligned_be64(const void *p)
72611+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
72612 {
72613- return be64_to_cpup((__be64 *)p);
72614+ return be64_to_cpup((const __be64 *)p);
72615 }
72616
72617 static inline void put_unaligned_le16(u16 val, void *p)
72618diff --git a/include/linux/usb.h b/include/linux/usb.h
72619index a0bee5a..5533a52 100644
72620--- a/include/linux/usb.h
72621+++ b/include/linux/usb.h
72622@@ -552,7 +552,7 @@ struct usb_device {
72623 int maxchild;
72624
72625 u32 quirks;
72626- atomic_t urbnum;
72627+ atomic_unchecked_t urbnum;
72628
72629 unsigned long active_duration;
72630
72631@@ -1607,7 +1607,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
72632
72633 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
72634 __u8 request, __u8 requesttype, __u16 value, __u16 index,
72635- void *data, __u16 size, int timeout);
72636+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
72637 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
72638 void *data, int len, int *actual_length, int timeout);
72639 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
72640diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
72641index e452ba6..78f8e80 100644
72642--- a/include/linux/usb/renesas_usbhs.h
72643+++ b/include/linux/usb/renesas_usbhs.h
72644@@ -39,7 +39,7 @@ enum {
72645 */
72646 struct renesas_usbhs_driver_callback {
72647 int (*notify_hotplug)(struct platform_device *pdev);
72648-};
72649+} __no_const;
72650
72651 /*
72652 * callback functions for platform
72653diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
72654index 6f8fbcf..8259001 100644
72655--- a/include/linux/vermagic.h
72656+++ b/include/linux/vermagic.h
72657@@ -25,9 +25,35 @@
72658 #define MODULE_ARCH_VERMAGIC ""
72659 #endif
72660
72661+#ifdef CONFIG_PAX_REFCOUNT
72662+#define MODULE_PAX_REFCOUNT "REFCOUNT "
72663+#else
72664+#define MODULE_PAX_REFCOUNT ""
72665+#endif
72666+
72667+#ifdef CONSTIFY_PLUGIN
72668+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
72669+#else
72670+#define MODULE_CONSTIFY_PLUGIN ""
72671+#endif
72672+
72673+#ifdef STACKLEAK_PLUGIN
72674+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
72675+#else
72676+#define MODULE_STACKLEAK_PLUGIN ""
72677+#endif
72678+
72679+#ifdef CONFIG_GRKERNSEC
72680+#define MODULE_GRSEC "GRSEC "
72681+#else
72682+#define MODULE_GRSEC ""
72683+#endif
72684+
72685 #define VERMAGIC_STRING \
72686 UTS_RELEASE " " \
72687 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
72688 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
72689- MODULE_ARCH_VERMAGIC
72690+ MODULE_ARCH_VERMAGIC \
72691+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
72692+ MODULE_GRSEC
72693
72694diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
72695index 7d5773a..541c01c 100644
72696--- a/include/linux/vmalloc.h
72697+++ b/include/linux/vmalloc.h
72698@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
72699 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
72700 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
72701 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
72702+
72703+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72704+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
72705+#endif
72706+
72707 /* bits [20..32] reserved for arch specific ioremap internals */
72708
72709 /*
72710@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
72711 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
72712 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
72713 unsigned long start, unsigned long end, gfp_t gfp_mask,
72714- pgprot_t prot, int node, const void *caller);
72715+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
72716 extern void vfree(const void *addr);
72717
72718 extern void *vmap(struct page **pages, unsigned int count,
72719@@ -137,8 +142,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
72720 extern void free_vm_area(struct vm_struct *area);
72721
72722 /* for /dev/kmem */
72723-extern long vread(char *buf, char *addr, unsigned long count);
72724-extern long vwrite(char *buf, char *addr, unsigned long count);
72725+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
72726+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
72727
72728 /*
72729 * Internals. Dont't use..
72730diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
72731index c586679..f06b389 100644
72732--- a/include/linux/vmstat.h
72733+++ b/include/linux/vmstat.h
72734@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
72735 /*
72736 * Zone based page accounting with per cpu differentials.
72737 */
72738-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72739+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72740
72741 static inline void zone_page_state_add(long x, struct zone *zone,
72742 enum zone_stat_item item)
72743 {
72744- atomic_long_add(x, &zone->vm_stat[item]);
72745- atomic_long_add(x, &vm_stat[item]);
72746+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
72747+ atomic_long_add_unchecked(x, &vm_stat[item]);
72748 }
72749
72750 static inline unsigned long global_page_state(enum zone_stat_item item)
72751 {
72752- long x = atomic_long_read(&vm_stat[item]);
72753+ long x = atomic_long_read_unchecked(&vm_stat[item]);
72754 #ifdef CONFIG_SMP
72755 if (x < 0)
72756 x = 0;
72757@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
72758 static inline unsigned long zone_page_state(struct zone *zone,
72759 enum zone_stat_item item)
72760 {
72761- long x = atomic_long_read(&zone->vm_stat[item]);
72762+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72763 #ifdef CONFIG_SMP
72764 if (x < 0)
72765 x = 0;
72766@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
72767 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
72768 enum zone_stat_item item)
72769 {
72770- long x = atomic_long_read(&zone->vm_stat[item]);
72771+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72772
72773 #ifdef CONFIG_SMP
72774 int cpu;
72775@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
72776
72777 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
72778 {
72779- atomic_long_inc(&zone->vm_stat[item]);
72780- atomic_long_inc(&vm_stat[item]);
72781+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
72782+ atomic_long_inc_unchecked(&vm_stat[item]);
72783 }
72784
72785 static inline void __inc_zone_page_state(struct page *page,
72786@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
72787
72788 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
72789 {
72790- atomic_long_dec(&zone->vm_stat[item]);
72791- atomic_long_dec(&vm_stat[item]);
72792+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
72793+ atomic_long_dec_unchecked(&vm_stat[item]);
72794 }
72795
72796 static inline void __dec_zone_page_state(struct page *page,
72797diff --git a/include/linux/xattr.h b/include/linux/xattr.h
72798index fdbafc6..49dfe4f 100644
72799--- a/include/linux/xattr.h
72800+++ b/include/linux/xattr.h
72801@@ -28,7 +28,7 @@ struct xattr_handler {
72802 size_t size, int handler_flags);
72803 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
72804 size_t size, int flags, int handler_flags);
72805-};
72806+} __do_const;
72807
72808 struct xattr {
72809 char *name;
72810@@ -37,6 +37,9 @@ struct xattr {
72811 };
72812
72813 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
72814+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
72815+ssize_t pax_getxattr(struct dentry *, void *, size_t);
72816+#endif
72817 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
72818 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
72819 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
72820diff --git a/include/linux/zlib.h b/include/linux/zlib.h
72821index 9c5a6b4..09c9438 100644
72822--- a/include/linux/zlib.h
72823+++ b/include/linux/zlib.h
72824@@ -31,6 +31,7 @@
72825 #define _ZLIB_H
72826
72827 #include <linux/zconf.h>
72828+#include <linux/compiler.h>
72829
72830 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
72831 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
72832@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
72833
72834 /* basic functions */
72835
72836-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
72837+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
72838 /*
72839 Returns the number of bytes that needs to be allocated for a per-
72840 stream workspace with the specified parameters. A pointer to this
72841diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
72842index 95d1c91..6798cca 100644
72843--- a/include/media/v4l2-dev.h
72844+++ b/include/media/v4l2-dev.h
72845@@ -76,7 +76,7 @@ struct v4l2_file_operations {
72846 int (*mmap) (struct file *, struct vm_area_struct *);
72847 int (*open) (struct file *);
72848 int (*release) (struct file *);
72849-};
72850+} __do_const;
72851
72852 /*
72853 * Newer version of video_device, handled by videodev2.c
72854diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
72855index adcbb20..62c2559 100644
72856--- a/include/net/9p/transport.h
72857+++ b/include/net/9p/transport.h
72858@@ -57,7 +57,7 @@ struct p9_trans_module {
72859 int (*cancel) (struct p9_client *, struct p9_req_t *req);
72860 int (*zc_request)(struct p9_client *, struct p9_req_t *,
72861 char *, char *, int , int, int, int);
72862-};
72863+} __do_const;
72864
72865 void v9fs_register_trans(struct p9_trans_module *m);
72866 void v9fs_unregister_trans(struct p9_trans_module *m);
72867diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
72868index fb94cf1..7c0c987 100644
72869--- a/include/net/bluetooth/l2cap.h
72870+++ b/include/net/bluetooth/l2cap.h
72871@@ -551,7 +551,7 @@ struct l2cap_ops {
72872 void (*defer) (struct l2cap_chan *chan);
72873 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
72874 unsigned long len, int nb);
72875-};
72876+} __do_const;
72877
72878 struct l2cap_conn {
72879 struct hci_conn *hcon;
72880diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
72881index f2ae33d..c457cf0 100644
72882--- a/include/net/caif/cfctrl.h
72883+++ b/include/net/caif/cfctrl.h
72884@@ -52,7 +52,7 @@ struct cfctrl_rsp {
72885 void (*radioset_rsp)(void);
72886 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
72887 struct cflayer *client_layer);
72888-};
72889+} __no_const;
72890
72891 /* Link Setup Parameters for CAIF-Links. */
72892 struct cfctrl_link_param {
72893@@ -101,8 +101,8 @@ struct cfctrl_request_info {
72894 struct cfctrl {
72895 struct cfsrvl serv;
72896 struct cfctrl_rsp res;
72897- atomic_t req_seq_no;
72898- atomic_t rsp_seq_no;
72899+ atomic_unchecked_t req_seq_no;
72900+ atomic_unchecked_t rsp_seq_no;
72901 struct list_head list;
72902 /* Protects from simultaneous access to first_req list */
72903 spinlock_t info_list_lock;
72904diff --git a/include/net/flow.h b/include/net/flow.h
72905index 628e11b..4c475df 100644
72906--- a/include/net/flow.h
72907+++ b/include/net/flow.h
72908@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
72909
72910 extern void flow_cache_flush(void);
72911 extern void flow_cache_flush_deferred(void);
72912-extern atomic_t flow_cache_genid;
72913+extern atomic_unchecked_t flow_cache_genid;
72914
72915 #endif
72916diff --git a/include/net/genetlink.h b/include/net/genetlink.h
72917index 93024a4..eeb6b6e 100644
72918--- a/include/net/genetlink.h
72919+++ b/include/net/genetlink.h
72920@@ -119,7 +119,7 @@ struct genl_ops {
72921 struct netlink_callback *cb);
72922 int (*done)(struct netlink_callback *cb);
72923 struct list_head ops_list;
72924-};
72925+} __do_const;
72926
72927 extern int genl_register_family(struct genl_family *family);
72928 extern int genl_register_family_with_ops(struct genl_family *family,
72929diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
72930index 734d9b5..48a9a4b 100644
72931--- a/include/net/gro_cells.h
72932+++ b/include/net/gro_cells.h
72933@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
72934 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
72935
72936 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
72937- atomic_long_inc(&dev->rx_dropped);
72938+ atomic_long_inc_unchecked(&dev->rx_dropped);
72939 kfree_skb(skb);
72940 return;
72941 }
72942diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
72943index de2c785..0588a6b 100644
72944--- a/include/net/inet_connection_sock.h
72945+++ b/include/net/inet_connection_sock.h
72946@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
72947 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
72948 int (*bind_conflict)(const struct sock *sk,
72949 const struct inet_bind_bucket *tb, bool relax);
72950-};
72951+} __do_const;
72952
72953 /** inet_connection_sock - INET connection oriented sock
72954 *
72955diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
72956index 53f464d..ba76aaa 100644
72957--- a/include/net/inetpeer.h
72958+++ b/include/net/inetpeer.h
72959@@ -47,8 +47,8 @@ struct inet_peer {
72960 */
72961 union {
72962 struct {
72963- atomic_t rid; /* Frag reception counter */
72964- atomic_t ip_id_count; /* IP ID for the next packet */
72965+ atomic_unchecked_t rid; /* Frag reception counter */
72966+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
72967 };
72968 struct rcu_head rcu;
72969 struct inet_peer *gc_next;
72970@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
72971 more++;
72972 inet_peer_refcheck(p);
72973 do {
72974- old = atomic_read(&p->ip_id_count);
72975+ old = atomic_read_unchecked(&p->ip_id_count);
72976 new = old + more;
72977 if (!new)
72978 new = 1;
72979- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
72980+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
72981 return new;
72982 }
72983
72984diff --git a/include/net/ip.h b/include/net/ip.h
72985index a68f838..74518ab 100644
72986--- a/include/net/ip.h
72987+++ b/include/net/ip.h
72988@@ -202,7 +202,7 @@ extern struct local_ports {
72989 } sysctl_local_ports;
72990 extern void inet_get_local_port_range(int *low, int *high);
72991
72992-extern unsigned long *sysctl_local_reserved_ports;
72993+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
72994 static inline int inet_is_reserved_local_port(int port)
72995 {
72996 return test_bit(port, sysctl_local_reserved_ports);
72997diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
72998index e49db91..76a81de 100644
72999--- a/include/net/ip_fib.h
73000+++ b/include/net/ip_fib.h
73001@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
73002
73003 #define FIB_RES_SADDR(net, res) \
73004 ((FIB_RES_NH(res).nh_saddr_genid == \
73005- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
73006+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
73007 FIB_RES_NH(res).nh_saddr : \
73008 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
73009 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
73010diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
73011index 4c062cc..3562c31 100644
73012--- a/include/net/ip_vs.h
73013+++ b/include/net/ip_vs.h
73014@@ -612,7 +612,7 @@ struct ip_vs_conn {
73015 struct ip_vs_conn *control; /* Master control connection */
73016 atomic_t n_control; /* Number of controlled ones */
73017 struct ip_vs_dest *dest; /* real server */
73018- atomic_t in_pkts; /* incoming packet counter */
73019+ atomic_unchecked_t in_pkts; /* incoming packet counter */
73020
73021 /* packet transmitter for different forwarding methods. If it
73022 mangles the packet, it must return NF_DROP or better NF_STOLEN,
73023@@ -761,7 +761,7 @@ struct ip_vs_dest {
73024 __be16 port; /* port number of the server */
73025 union nf_inet_addr addr; /* IP address of the server */
73026 volatile unsigned int flags; /* dest status flags */
73027- atomic_t conn_flags; /* flags to copy to conn */
73028+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
73029 atomic_t weight; /* server weight */
73030
73031 atomic_t refcnt; /* reference counter */
73032@@ -1013,11 +1013,11 @@ struct netns_ipvs {
73033 /* ip_vs_lblc */
73034 int sysctl_lblc_expiration;
73035 struct ctl_table_header *lblc_ctl_header;
73036- struct ctl_table *lblc_ctl_table;
73037+ ctl_table_no_const *lblc_ctl_table;
73038 /* ip_vs_lblcr */
73039 int sysctl_lblcr_expiration;
73040 struct ctl_table_header *lblcr_ctl_header;
73041- struct ctl_table *lblcr_ctl_table;
73042+ ctl_table_no_const *lblcr_ctl_table;
73043 /* ip_vs_est */
73044 struct list_head est_list; /* estimator list */
73045 spinlock_t est_lock;
73046diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
73047index 80ffde3..968b0f4 100644
73048--- a/include/net/irda/ircomm_tty.h
73049+++ b/include/net/irda/ircomm_tty.h
73050@@ -35,6 +35,7 @@
73051 #include <linux/termios.h>
73052 #include <linux/timer.h>
73053 #include <linux/tty.h> /* struct tty_struct */
73054+#include <asm/local.h>
73055
73056 #include <net/irda/irias_object.h>
73057 #include <net/irda/ircomm_core.h>
73058diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
73059index 714cc9a..ea05f3e 100644
73060--- a/include/net/iucv/af_iucv.h
73061+++ b/include/net/iucv/af_iucv.h
73062@@ -149,7 +149,7 @@ struct iucv_skb_cb {
73063 struct iucv_sock_list {
73064 struct hlist_head head;
73065 rwlock_t lock;
73066- atomic_t autobind_name;
73067+ atomic_unchecked_t autobind_name;
73068 };
73069
73070 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
73071diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
73072index df83f69..9b640b8 100644
73073--- a/include/net/llc_c_ac.h
73074+++ b/include/net/llc_c_ac.h
73075@@ -87,7 +87,7 @@
73076 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
73077 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
73078
73079-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73080+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73081
73082 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
73083 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
73084diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
73085index 6ca3113..f8026dd 100644
73086--- a/include/net/llc_c_ev.h
73087+++ b/include/net/llc_c_ev.h
73088@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
73089 return (struct llc_conn_state_ev *)skb->cb;
73090 }
73091
73092-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73093-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73094+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73095+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73096
73097 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
73098 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
73099diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
73100index 0e79cfb..f46db31 100644
73101--- a/include/net/llc_c_st.h
73102+++ b/include/net/llc_c_st.h
73103@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
73104 u8 next_state;
73105 llc_conn_ev_qfyr_t *ev_qualifiers;
73106 llc_conn_action_t *ev_actions;
73107-};
73108+} __do_const;
73109
73110 struct llc_conn_state {
73111 u8 current_state;
73112diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
73113index 37a3bbd..55a4241 100644
73114--- a/include/net/llc_s_ac.h
73115+++ b/include/net/llc_s_ac.h
73116@@ -23,7 +23,7 @@
73117 #define SAP_ACT_TEST_IND 9
73118
73119 /* All action functions must look like this */
73120-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73121+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73122
73123 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
73124 struct sk_buff *skb);
73125diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
73126index 567c681..cd73ac0 100644
73127--- a/include/net/llc_s_st.h
73128+++ b/include/net/llc_s_st.h
73129@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
73130 llc_sap_ev_t ev;
73131 u8 next_state;
73132 llc_sap_action_t *ev_actions;
73133-};
73134+} __do_const;
73135
73136 struct llc_sap_state {
73137 u8 curr_state;
73138diff --git a/include/net/mac80211.h b/include/net/mac80211.h
73139index 885898a..cdace34 100644
73140--- a/include/net/mac80211.h
73141+++ b/include/net/mac80211.h
73142@@ -4205,7 +4205,7 @@ struct rate_control_ops {
73143 void (*add_sta_debugfs)(void *priv, void *priv_sta,
73144 struct dentry *dir);
73145 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
73146-};
73147+} __do_const;
73148
73149 static inline int rate_supported(struct ieee80211_sta *sta,
73150 enum ieee80211_band band,
73151diff --git a/include/net/neighbour.h b/include/net/neighbour.h
73152index 7e748ad..5c6229b 100644
73153--- a/include/net/neighbour.h
73154+++ b/include/net/neighbour.h
73155@@ -123,7 +123,7 @@ struct neigh_ops {
73156 void (*error_report)(struct neighbour *, struct sk_buff *);
73157 int (*output)(struct neighbour *, struct sk_buff *);
73158 int (*connected_output)(struct neighbour *, struct sk_buff *);
73159-};
73160+} __do_const;
73161
73162 struct pneigh_entry {
73163 struct pneigh_entry *next;
73164diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
73165index b176978..ea169f4 100644
73166--- a/include/net/net_namespace.h
73167+++ b/include/net/net_namespace.h
73168@@ -117,7 +117,7 @@ struct net {
73169 #endif
73170 struct netns_ipvs *ipvs;
73171 struct sock *diag_nlsk;
73172- atomic_t rt_genid;
73173+ atomic_unchecked_t rt_genid;
73174 };
73175
73176 /*
73177@@ -274,7 +274,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
73178 #define __net_init __init
73179 #define __net_exit __exit_refok
73180 #define __net_initdata __initdata
73181+#ifdef CONSTIFY_PLUGIN
73182 #define __net_initconst __initconst
73183+#else
73184+#define __net_initconst __initdata
73185+#endif
73186 #endif
73187
73188 struct pernet_operations {
73189@@ -284,7 +288,7 @@ struct pernet_operations {
73190 void (*exit_batch)(struct list_head *net_exit_list);
73191 int *id;
73192 size_t size;
73193-};
73194+} __do_const;
73195
73196 /*
73197 * Use these carefully. If you implement a network device and it
73198@@ -332,12 +336,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
73199
73200 static inline int rt_genid(struct net *net)
73201 {
73202- return atomic_read(&net->rt_genid);
73203+ return atomic_read_unchecked(&net->rt_genid);
73204 }
73205
73206 static inline void rt_genid_bump(struct net *net)
73207 {
73208- atomic_inc(&net->rt_genid);
73209+ atomic_inc_unchecked(&net->rt_genid);
73210 }
73211
73212 #endif /* __NET_NET_NAMESPACE_H */
73213diff --git a/include/net/netdma.h b/include/net/netdma.h
73214index 8ba8ce2..99b7fff 100644
73215--- a/include/net/netdma.h
73216+++ b/include/net/netdma.h
73217@@ -24,7 +24,7 @@
73218 #include <linux/dmaengine.h>
73219 #include <linux/skbuff.h>
73220
73221-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73222+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73223 struct sk_buff *skb, int offset, struct iovec *to,
73224 size_t len, struct dma_pinned_list *pinned_list);
73225
73226diff --git a/include/net/netlink.h b/include/net/netlink.h
73227index 9690b0f..87aded7 100644
73228--- a/include/net/netlink.h
73229+++ b/include/net/netlink.h
73230@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
73231 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
73232 {
73233 if (mark)
73234- skb_trim(skb, (unsigned char *) mark - skb->data);
73235+ skb_trim(skb, (const unsigned char *) mark - skb->data);
73236 }
73237
73238 /**
73239diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
73240index c9c0c53..53f24c3 100644
73241--- a/include/net/netns/conntrack.h
73242+++ b/include/net/netns/conntrack.h
73243@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
73244 struct nf_proto_net {
73245 #ifdef CONFIG_SYSCTL
73246 struct ctl_table_header *ctl_table_header;
73247- struct ctl_table *ctl_table;
73248+ ctl_table_no_const *ctl_table;
73249 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
73250 struct ctl_table_header *ctl_compat_header;
73251- struct ctl_table *ctl_compat_table;
73252+ ctl_table_no_const *ctl_compat_table;
73253 #endif
73254 #endif
73255 unsigned int users;
73256@@ -58,7 +58,7 @@ struct nf_ip_net {
73257 struct nf_icmp_net icmpv6;
73258 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
73259 struct ctl_table_header *ctl_table_header;
73260- struct ctl_table *ctl_table;
73261+ ctl_table_no_const *ctl_table;
73262 #endif
73263 };
73264
73265diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
73266index 2ba9de8..47bd6c7 100644
73267--- a/include/net/netns/ipv4.h
73268+++ b/include/net/netns/ipv4.h
73269@@ -67,7 +67,7 @@ struct netns_ipv4 {
73270 kgid_t sysctl_ping_group_range[2];
73271 long sysctl_tcp_mem[3];
73272
73273- atomic_t dev_addr_genid;
73274+ atomic_unchecked_t dev_addr_genid;
73275
73276 #ifdef CONFIG_IP_MROUTE
73277 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
73278diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
73279index 005e2c2..023d340 100644
73280--- a/include/net/netns/ipv6.h
73281+++ b/include/net/netns/ipv6.h
73282@@ -71,7 +71,7 @@ struct netns_ipv6 {
73283 struct fib_rules_ops *mr6_rules_ops;
73284 #endif
73285 #endif
73286- atomic_t dev_addr_genid;
73287+ atomic_unchecked_t dev_addr_genid;
73288 };
73289
73290 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
73291diff --git a/include/net/protocol.h b/include/net/protocol.h
73292index 047c047..b9dad15 100644
73293--- a/include/net/protocol.h
73294+++ b/include/net/protocol.h
73295@@ -44,7 +44,7 @@ struct net_protocol {
73296 void (*err_handler)(struct sk_buff *skb, u32 info);
73297 unsigned int no_policy:1,
73298 netns_ok:1;
73299-};
73300+} __do_const;
73301
73302 #if IS_ENABLED(CONFIG_IPV6)
73303 struct inet6_protocol {
73304@@ -57,7 +57,7 @@ struct inet6_protocol {
73305 u8 type, u8 code, int offset,
73306 __be32 info);
73307 unsigned int flags; /* INET6_PROTO_xxx */
73308-};
73309+} __do_const;
73310
73311 #define INET6_PROTO_NOPOLICY 0x1
73312 #define INET6_PROTO_FINAL 0x2
73313diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
73314index 7026648..584cc8c 100644
73315--- a/include/net/rtnetlink.h
73316+++ b/include/net/rtnetlink.h
73317@@ -81,7 +81,7 @@ struct rtnl_link_ops {
73318 const struct net_device *dev);
73319 unsigned int (*get_num_tx_queues)(void);
73320 unsigned int (*get_num_rx_queues)(void);
73321-};
73322+} __do_const;
73323
73324 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
73325 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
73326diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
73327index cd89510..d67810f 100644
73328--- a/include/net/sctp/sctp.h
73329+++ b/include/net/sctp/sctp.h
73330@@ -330,9 +330,9 @@ do { \
73331
73332 #else /* SCTP_DEBUG */
73333
73334-#define SCTP_DEBUG_PRINTK(whatever...)
73335-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
73336-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
73337+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
73338+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
73339+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
73340 #define SCTP_ENABLE_DEBUG
73341 #define SCTP_DISABLE_DEBUG
73342 #define SCTP_ASSERT(expr, str, func)
73343diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
73344index 2a82d13..62a31c2 100644
73345--- a/include/net/sctp/sm.h
73346+++ b/include/net/sctp/sm.h
73347@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
73348 typedef struct {
73349 sctp_state_fn_t *fn;
73350 const char *name;
73351-} sctp_sm_table_entry_t;
73352+} __do_const sctp_sm_table_entry_t;
73353
73354 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
73355 * currently in use.
73356@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
73357 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
73358
73359 /* Extern declarations for major data structures. */
73360-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73361+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73362
73363
73364 /* Get the size of a DATA chunk payload. */
73365diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
73366index 1bd4c41..9250b5b 100644
73367--- a/include/net/sctp/structs.h
73368+++ b/include/net/sctp/structs.h
73369@@ -516,7 +516,7 @@ struct sctp_pf {
73370 struct sctp_association *asoc);
73371 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
73372 struct sctp_af *af;
73373-};
73374+} __do_const;
73375
73376
73377 /* Structure to track chunk fragments that have been acked, but peer
73378diff --git a/include/net/sock.h b/include/net/sock.h
73379index 66772cf..25bc45b 100644
73380--- a/include/net/sock.h
73381+++ b/include/net/sock.h
73382@@ -325,7 +325,7 @@ struct sock {
73383 #ifdef CONFIG_RPS
73384 __u32 sk_rxhash;
73385 #endif
73386- atomic_t sk_drops;
73387+ atomic_unchecked_t sk_drops;
73388 int sk_rcvbuf;
73389
73390 struct sk_filter __rcu *sk_filter;
73391@@ -1797,7 +1797,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
73392 }
73393
73394 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
73395- char __user *from, char *to,
73396+ char __user *from, unsigned char *to,
73397 int copy, int offset)
73398 {
73399 if (skb->ip_summed == CHECKSUM_NONE) {
73400@@ -2056,7 +2056,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
73401 }
73402 }
73403
73404-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73405+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73406
73407 /**
73408 * sk_page_frag - return an appropriate page_frag
73409diff --git a/include/net/tcp.h b/include/net/tcp.h
73410index 5bba80f..8520a82 100644
73411--- a/include/net/tcp.h
73412+++ b/include/net/tcp.h
73413@@ -524,7 +524,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
73414 extern void tcp_xmit_retransmit_queue(struct sock *);
73415 extern void tcp_simple_retransmit(struct sock *);
73416 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
73417-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73418+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73419
73420 extern void tcp_send_probe0(struct sock *);
73421 extern void tcp_send_partial(struct sock *);
73422@@ -697,8 +697,8 @@ struct tcp_skb_cb {
73423 struct inet6_skb_parm h6;
73424 #endif
73425 } header; /* For incoming frames */
73426- __u32 seq; /* Starting sequence number */
73427- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
73428+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
73429+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
73430 __u32 when; /* used to compute rtt's */
73431 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
73432
73433@@ -712,7 +712,7 @@ struct tcp_skb_cb {
73434
73435 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
73436 /* 1 byte hole */
73437- __u32 ack_seq; /* Sequence number ACK'd */
73438+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
73439 };
73440
73441 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
73442diff --git a/include/net/udp.h b/include/net/udp.h
73443index 065f379..ad99eed 100644
73444--- a/include/net/udp.h
73445+++ b/include/net/udp.h
73446@@ -181,6 +181,7 @@ extern int udp_get_port(struct sock *sk, unsigned short snum,
73447 extern void udp_err(struct sk_buff *, u32);
73448 extern int udp_sendmsg(struct kiocb *iocb, struct sock *sk,
73449 struct msghdr *msg, size_t len);
73450+extern int udp_push_pending_frames(struct sock *sk);
73451 extern void udp_flush_pending_frames(struct sock *sk);
73452 extern int udp_rcv(struct sk_buff *skb);
73453 extern int udp_ioctl(struct sock *sk, int cmd, unsigned long arg);
73454diff --git a/include/net/xfrm.h b/include/net/xfrm.h
73455index 94ce082..62b278d 100644
73456--- a/include/net/xfrm.h
73457+++ b/include/net/xfrm.h
73458@@ -305,7 +305,7 @@ struct xfrm_policy_afinfo {
73459 struct net_device *dev,
73460 const struct flowi *fl);
73461 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
73462-};
73463+} __do_const;
73464
73465 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
73466 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
73467@@ -341,7 +341,7 @@ struct xfrm_state_afinfo {
73468 struct sk_buff *skb);
73469 int (*transport_finish)(struct sk_buff *skb,
73470 int async);
73471-};
73472+} __do_const;
73473
73474 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
73475 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
73476@@ -424,7 +424,7 @@ struct xfrm_mode {
73477 struct module *owner;
73478 unsigned int encap;
73479 int flags;
73480-};
73481+} __do_const;
73482
73483 /* Flags for xfrm_mode. */
73484 enum {
73485@@ -521,7 +521,7 @@ struct xfrm_policy {
73486 struct timer_list timer;
73487
73488 struct flow_cache_object flo;
73489- atomic_t genid;
73490+ atomic_unchecked_t genid;
73491 u32 priority;
73492 u32 index;
73493 struct xfrm_mark mark;
73494diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
73495index 1a046b1..ee0bef0 100644
73496--- a/include/rdma/iw_cm.h
73497+++ b/include/rdma/iw_cm.h
73498@@ -122,7 +122,7 @@ struct iw_cm_verbs {
73499 int backlog);
73500
73501 int (*destroy_listen)(struct iw_cm_id *cm_id);
73502-};
73503+} __no_const;
73504
73505 /**
73506 * iw_create_cm_id - Create an IW CM identifier.
73507diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
73508index e1379b4..67eafbe 100644
73509--- a/include/scsi/libfc.h
73510+++ b/include/scsi/libfc.h
73511@@ -762,6 +762,7 @@ struct libfc_function_template {
73512 */
73513 void (*disc_stop_final) (struct fc_lport *);
73514 };
73515+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
73516
73517 /**
73518 * struct fc_disc - Discovery context
73519@@ -866,7 +867,7 @@ struct fc_lport {
73520 struct fc_vport *vport;
73521
73522 /* Operational Information */
73523- struct libfc_function_template tt;
73524+ libfc_function_template_no_const tt;
73525 u8 link_up;
73526 u8 qfull;
73527 enum fc_lport_state state;
73528diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
73529index cc64587..608f523 100644
73530--- a/include/scsi/scsi_device.h
73531+++ b/include/scsi/scsi_device.h
73532@@ -171,9 +171,9 @@ struct scsi_device {
73533 unsigned int max_device_blocked; /* what device_blocked counts down from */
73534 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
73535
73536- atomic_t iorequest_cnt;
73537- atomic_t iodone_cnt;
73538- atomic_t ioerr_cnt;
73539+ atomic_unchecked_t iorequest_cnt;
73540+ atomic_unchecked_t iodone_cnt;
73541+ atomic_unchecked_t ioerr_cnt;
73542
73543 struct device sdev_gendev,
73544 sdev_dev;
73545diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
73546index b797e8f..8e2c3aa 100644
73547--- a/include/scsi/scsi_transport_fc.h
73548+++ b/include/scsi/scsi_transport_fc.h
73549@@ -751,7 +751,8 @@ struct fc_function_template {
73550 unsigned long show_host_system_hostname:1;
73551
73552 unsigned long disable_target_scan:1;
73553-};
73554+} __do_const;
73555+typedef struct fc_function_template __no_const fc_function_template_no_const;
73556
73557
73558 /**
73559diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
73560index 9031a26..750d592 100644
73561--- a/include/sound/compress_driver.h
73562+++ b/include/sound/compress_driver.h
73563@@ -128,7 +128,7 @@ struct snd_compr_ops {
73564 struct snd_compr_caps *caps);
73565 int (*get_codec_caps) (struct snd_compr_stream *stream,
73566 struct snd_compr_codec_caps *codec);
73567-};
73568+} __no_const;
73569
73570 /**
73571 * struct snd_compr: Compressed device
73572diff --git a/include/sound/soc.h b/include/sound/soc.h
73573index 85c1522..f44bad1 100644
73574--- a/include/sound/soc.h
73575+++ b/include/sound/soc.h
73576@@ -781,7 +781,7 @@ struct snd_soc_codec_driver {
73577 /* probe ordering - for components with runtime dependencies */
73578 int probe_order;
73579 int remove_order;
73580-};
73581+} __do_const;
73582
73583 /* SoC platform interface */
73584 struct snd_soc_platform_driver {
73585@@ -827,7 +827,7 @@ struct snd_soc_platform_driver {
73586 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
73587 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
73588 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
73589-};
73590+} __do_const;
73591
73592 struct snd_soc_platform {
73593 const char *name;
73594diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
73595index 4ea4f98..a63629b 100644
73596--- a/include/target/target_core_base.h
73597+++ b/include/target/target_core_base.h
73598@@ -653,7 +653,7 @@ struct se_device {
73599 spinlock_t stats_lock;
73600 /* Active commands on this virtual SE device */
73601 atomic_t simple_cmds;
73602- atomic_t dev_ordered_id;
73603+ atomic_unchecked_t dev_ordered_id;
73604 atomic_t dev_ordered_sync;
73605 atomic_t dev_qf_count;
73606 int export_count;
73607diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
73608new file mode 100644
73609index 0000000..fb634b7
73610--- /dev/null
73611+++ b/include/trace/events/fs.h
73612@@ -0,0 +1,53 @@
73613+#undef TRACE_SYSTEM
73614+#define TRACE_SYSTEM fs
73615+
73616+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
73617+#define _TRACE_FS_H
73618+
73619+#include <linux/fs.h>
73620+#include <linux/tracepoint.h>
73621+
73622+TRACE_EVENT(do_sys_open,
73623+
73624+ TP_PROTO(const char *filename, int flags, int mode),
73625+
73626+ TP_ARGS(filename, flags, mode),
73627+
73628+ TP_STRUCT__entry(
73629+ __string( filename, filename )
73630+ __field( int, flags )
73631+ __field( int, mode )
73632+ ),
73633+
73634+ TP_fast_assign(
73635+ __assign_str(filename, filename);
73636+ __entry->flags = flags;
73637+ __entry->mode = mode;
73638+ ),
73639+
73640+ TP_printk("\"%s\" %x %o",
73641+ __get_str(filename), __entry->flags, __entry->mode)
73642+);
73643+
73644+TRACE_EVENT(open_exec,
73645+
73646+ TP_PROTO(const char *filename),
73647+
73648+ TP_ARGS(filename),
73649+
73650+ TP_STRUCT__entry(
73651+ __string( filename, filename )
73652+ ),
73653+
73654+ TP_fast_assign(
73655+ __assign_str(filename, filename);
73656+ ),
73657+
73658+ TP_printk("\"%s\"",
73659+ __get_str(filename))
73660+);
73661+
73662+#endif /* _TRACE_FS_H */
73663+
73664+/* This part must be outside protection */
73665+#include <trace/define_trace.h>
73666diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
73667index 1c09820..7f5ec79 100644
73668--- a/include/trace/events/irq.h
73669+++ b/include/trace/events/irq.h
73670@@ -36,7 +36,7 @@ struct softirq_action;
73671 */
73672 TRACE_EVENT(irq_handler_entry,
73673
73674- TP_PROTO(int irq, struct irqaction *action),
73675+ TP_PROTO(int irq, const struct irqaction *action),
73676
73677 TP_ARGS(irq, action),
73678
73679@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
73680 */
73681 TRACE_EVENT(irq_handler_exit,
73682
73683- TP_PROTO(int irq, struct irqaction *action, int ret),
73684+ TP_PROTO(int irq, const struct irqaction *action, int ret),
73685
73686 TP_ARGS(irq, action, ret),
73687
73688diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
73689index 7caf44c..23c6f27 100644
73690--- a/include/uapi/linux/a.out.h
73691+++ b/include/uapi/linux/a.out.h
73692@@ -39,6 +39,14 @@ enum machine_type {
73693 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
73694 };
73695
73696+/* Constants for the N_FLAGS field */
73697+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73698+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
73699+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
73700+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
73701+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73702+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73703+
73704 #if !defined (N_MAGIC)
73705 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
73706 #endif
73707diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
73708index d876736..ccce5c0 100644
73709--- a/include/uapi/linux/byteorder/little_endian.h
73710+++ b/include/uapi/linux/byteorder/little_endian.h
73711@@ -42,51 +42,51 @@
73712
73713 static inline __le64 __cpu_to_le64p(const __u64 *p)
73714 {
73715- return (__force __le64)*p;
73716+ return (__force const __le64)*p;
73717 }
73718-static inline __u64 __le64_to_cpup(const __le64 *p)
73719+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
73720 {
73721- return (__force __u64)*p;
73722+ return (__force const __u64)*p;
73723 }
73724 static inline __le32 __cpu_to_le32p(const __u32 *p)
73725 {
73726- return (__force __le32)*p;
73727+ return (__force const __le32)*p;
73728 }
73729 static inline __u32 __le32_to_cpup(const __le32 *p)
73730 {
73731- return (__force __u32)*p;
73732+ return (__force const __u32)*p;
73733 }
73734 static inline __le16 __cpu_to_le16p(const __u16 *p)
73735 {
73736- return (__force __le16)*p;
73737+ return (__force const __le16)*p;
73738 }
73739 static inline __u16 __le16_to_cpup(const __le16 *p)
73740 {
73741- return (__force __u16)*p;
73742+ return (__force const __u16)*p;
73743 }
73744 static inline __be64 __cpu_to_be64p(const __u64 *p)
73745 {
73746- return (__force __be64)__swab64p(p);
73747+ return (__force const __be64)__swab64p(p);
73748 }
73749 static inline __u64 __be64_to_cpup(const __be64 *p)
73750 {
73751- return __swab64p((__u64 *)p);
73752+ return __swab64p((const __u64 *)p);
73753 }
73754 static inline __be32 __cpu_to_be32p(const __u32 *p)
73755 {
73756- return (__force __be32)__swab32p(p);
73757+ return (__force const __be32)__swab32p(p);
73758 }
73759-static inline __u32 __be32_to_cpup(const __be32 *p)
73760+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
73761 {
73762- return __swab32p((__u32 *)p);
73763+ return __swab32p((const __u32 *)p);
73764 }
73765 static inline __be16 __cpu_to_be16p(const __u16 *p)
73766 {
73767- return (__force __be16)__swab16p(p);
73768+ return (__force const __be16)__swab16p(p);
73769 }
73770 static inline __u16 __be16_to_cpup(const __be16 *p)
73771 {
73772- return __swab16p((__u16 *)p);
73773+ return __swab16p((const __u16 *)p);
73774 }
73775 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
73776 #define __le64_to_cpus(x) do { (void)(x); } while (0)
73777diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
73778index ef6103b..d4e65dd 100644
73779--- a/include/uapi/linux/elf.h
73780+++ b/include/uapi/linux/elf.h
73781@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
73782 #define PT_GNU_EH_FRAME 0x6474e550
73783
73784 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
73785+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
73786+
73787+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
73788+
73789+/* Constants for the e_flags field */
73790+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73791+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
73792+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
73793+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
73794+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73795+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73796
73797 /*
73798 * Extended Numbering
73799@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
73800 #define DT_DEBUG 21
73801 #define DT_TEXTREL 22
73802 #define DT_JMPREL 23
73803+#define DT_FLAGS 30
73804+ #define DF_TEXTREL 0x00000004
73805 #define DT_ENCODING 32
73806 #define OLD_DT_LOOS 0x60000000
73807 #define DT_LOOS 0x6000000d
73808@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
73809 #define PF_W 0x2
73810 #define PF_X 0x1
73811
73812+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
73813+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
73814+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
73815+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
73816+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
73817+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
73818+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
73819+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
73820+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
73821+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
73822+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
73823+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
73824+
73825 typedef struct elf32_phdr{
73826 Elf32_Word p_type;
73827 Elf32_Off p_offset;
73828@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
73829 #define EI_OSABI 7
73830 #define EI_PAD 8
73831
73832+#define EI_PAX 14
73833+
73834 #define ELFMAG0 0x7f /* EI_MAG */
73835 #define ELFMAG1 'E'
73836 #define ELFMAG2 'L'
73837diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
73838index aa169c4..6a2771d 100644
73839--- a/include/uapi/linux/personality.h
73840+++ b/include/uapi/linux/personality.h
73841@@ -30,6 +30,7 @@ enum {
73842 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
73843 ADDR_NO_RANDOMIZE | \
73844 ADDR_COMPAT_LAYOUT | \
73845+ ADDR_LIMIT_3GB | \
73846 MMAP_PAGE_ZERO)
73847
73848 /*
73849diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
73850index 7530e74..e714828 100644
73851--- a/include/uapi/linux/screen_info.h
73852+++ b/include/uapi/linux/screen_info.h
73853@@ -43,7 +43,8 @@ struct screen_info {
73854 __u16 pages; /* 0x32 */
73855 __u16 vesa_attributes; /* 0x34 */
73856 __u32 capabilities; /* 0x36 */
73857- __u8 _reserved[6]; /* 0x3a */
73858+ __u16 vesapm_size; /* 0x3a */
73859+ __u8 _reserved[4]; /* 0x3c */
73860 } __attribute__((packed));
73861
73862 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
73863diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
73864index 0e011eb..82681b1 100644
73865--- a/include/uapi/linux/swab.h
73866+++ b/include/uapi/linux/swab.h
73867@@ -43,7 +43,7 @@
73868 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
73869 */
73870
73871-static inline __attribute_const__ __u16 __fswab16(__u16 val)
73872+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
73873 {
73874 #ifdef __HAVE_BUILTIN_BSWAP16__
73875 return __builtin_bswap16(val);
73876@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
73877 #endif
73878 }
73879
73880-static inline __attribute_const__ __u32 __fswab32(__u32 val)
73881+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
73882 {
73883 #ifdef __HAVE_BUILTIN_BSWAP32__
73884 return __builtin_bswap32(val);
73885@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
73886 #endif
73887 }
73888
73889-static inline __attribute_const__ __u64 __fswab64(__u64 val)
73890+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
73891 {
73892 #ifdef __HAVE_BUILTIN_BSWAP64__
73893 return __builtin_bswap64(val);
73894diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
73895index 6d67213..8dab561 100644
73896--- a/include/uapi/linux/sysctl.h
73897+++ b/include/uapi/linux/sysctl.h
73898@@ -155,7 +155,11 @@ enum
73899 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
73900 };
73901
73902-
73903+#ifdef CONFIG_PAX_SOFTMODE
73904+enum {
73905+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
73906+};
73907+#endif
73908
73909 /* CTL_VM names: */
73910 enum
73911diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
73912index e4629b9..6958086 100644
73913--- a/include/uapi/linux/xattr.h
73914+++ b/include/uapi/linux/xattr.h
73915@@ -63,5 +63,9 @@
73916 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
73917 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
73918
73919+/* User namespace */
73920+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
73921+#define XATTR_PAX_FLAGS_SUFFIX "flags"
73922+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
73923
73924 #endif /* _UAPI_LINUX_XATTR_H */
73925diff --git a/include/video/udlfb.h b/include/video/udlfb.h
73926index f9466fa..f4e2b81 100644
73927--- a/include/video/udlfb.h
73928+++ b/include/video/udlfb.h
73929@@ -53,10 +53,10 @@ struct dlfb_data {
73930 u32 pseudo_palette[256];
73931 int blank_mode; /*one of FB_BLANK_ */
73932 /* blit-only rendering path metrics, exposed through sysfs */
73933- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73934- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
73935- atomic_t bytes_sent; /* to usb, after compression including overhead */
73936- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
73937+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73938+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
73939+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
73940+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
73941 };
73942
73943 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
73944diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
73945index 1a91850..28573f8 100644
73946--- a/include/video/uvesafb.h
73947+++ b/include/video/uvesafb.h
73948@@ -122,6 +122,7 @@ struct uvesafb_par {
73949 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
73950 u8 pmi_setpal; /* PMI for palette changes */
73951 u16 *pmi_base; /* protected mode interface location */
73952+ u8 *pmi_code; /* protected mode code location */
73953 void *pmi_start;
73954 void *pmi_pal;
73955 u8 *vbe_state_orig; /*
73956diff --git a/init/Kconfig b/init/Kconfig
73957index 2d9b831..ae4c8ac 100644
73958--- a/init/Kconfig
73959+++ b/init/Kconfig
73960@@ -1029,6 +1029,7 @@ endif # CGROUPS
73961
73962 config CHECKPOINT_RESTORE
73963 bool "Checkpoint/restore support" if EXPERT
73964+ depends on !GRKERNSEC
73965 default n
73966 help
73967 Enables additional kernel features in a sake of checkpoint/restore.
73968@@ -1516,7 +1517,7 @@ config SLUB_DEBUG
73969
73970 config COMPAT_BRK
73971 bool "Disable heap randomization"
73972- default y
73973+ default n
73974 help
73975 Randomizing heap placement makes heap exploits harder, but it
73976 also breaks ancient binaries (including anything libc5 based).
73977@@ -1779,7 +1780,7 @@ config INIT_ALL_POSSIBLE
73978 config STOP_MACHINE
73979 bool
73980 default y
73981- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
73982+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
73983 help
73984 Need stop_machine() primitive.
73985
73986diff --git a/init/Makefile b/init/Makefile
73987index 7bc47ee..6da2dc7 100644
73988--- a/init/Makefile
73989+++ b/init/Makefile
73990@@ -2,6 +2,9 @@
73991 # Makefile for the linux kernel.
73992 #
73993
73994+ccflags-y := $(GCC_PLUGINS_CFLAGS)
73995+asflags-y := $(GCC_PLUGINS_AFLAGS)
73996+
73997 obj-y := main.o version.o mounts.o
73998 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
73999 obj-y += noinitramfs.o
74000diff --git a/init/do_mounts.c b/init/do_mounts.c
74001index a2b49f2..03a0e17c 100644
74002--- a/init/do_mounts.c
74003+++ b/init/do_mounts.c
74004@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
74005 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
74006 {
74007 struct super_block *s;
74008- int err = sys_mount(name, "/root", fs, flags, data);
74009+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
74010 if (err)
74011 return err;
74012
74013- sys_chdir("/root");
74014+ sys_chdir((const char __force_user *)"/root");
74015 s = current->fs->pwd.dentry->d_sb;
74016 ROOT_DEV = s->s_dev;
74017 printk(KERN_INFO
74018@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
74019 va_start(args, fmt);
74020 vsprintf(buf, fmt, args);
74021 va_end(args);
74022- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
74023+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
74024 if (fd >= 0) {
74025 sys_ioctl(fd, FDEJECT, 0);
74026 sys_close(fd);
74027 }
74028 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
74029- fd = sys_open("/dev/console", O_RDWR, 0);
74030+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
74031 if (fd >= 0) {
74032 sys_ioctl(fd, TCGETS, (long)&termios);
74033 termios.c_lflag &= ~ICANON;
74034 sys_ioctl(fd, TCSETSF, (long)&termios);
74035- sys_read(fd, &c, 1);
74036+ sys_read(fd, (char __user *)&c, 1);
74037 termios.c_lflag |= ICANON;
74038 sys_ioctl(fd, TCSETSF, (long)&termios);
74039 sys_close(fd);
74040@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
74041 mount_root();
74042 out:
74043 devtmpfs_mount("dev");
74044- sys_mount(".", "/", NULL, MS_MOVE, NULL);
74045- sys_chroot(".");
74046+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
74047+ sys_chroot((const char __force_user *)".");
74048 }
74049diff --git a/init/do_mounts.h b/init/do_mounts.h
74050index f5b978a..69dbfe8 100644
74051--- a/init/do_mounts.h
74052+++ b/init/do_mounts.h
74053@@ -15,15 +15,15 @@ extern int root_mountflags;
74054
74055 static inline int create_dev(char *name, dev_t dev)
74056 {
74057- sys_unlink(name);
74058- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
74059+ sys_unlink((char __force_user *)name);
74060+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
74061 }
74062
74063 #if BITS_PER_LONG == 32
74064 static inline u32 bstat(char *name)
74065 {
74066 struct stat64 stat;
74067- if (sys_stat64(name, &stat) != 0)
74068+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
74069 return 0;
74070 if (!S_ISBLK(stat.st_mode))
74071 return 0;
74072@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
74073 static inline u32 bstat(char *name)
74074 {
74075 struct stat stat;
74076- if (sys_newstat(name, &stat) != 0)
74077+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
74078 return 0;
74079 if (!S_ISBLK(stat.st_mode))
74080 return 0;
74081diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
74082index 3e0878e..8a9d7a0 100644
74083--- a/init/do_mounts_initrd.c
74084+++ b/init/do_mounts_initrd.c
74085@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
74086 {
74087 sys_unshare(CLONE_FS | CLONE_FILES);
74088 /* stdin/stdout/stderr for /linuxrc */
74089- sys_open("/dev/console", O_RDWR, 0);
74090+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
74091 sys_dup(0);
74092 sys_dup(0);
74093 /* move initrd over / and chdir/chroot in initrd root */
74094- sys_chdir("/root");
74095- sys_mount(".", "/", NULL, MS_MOVE, NULL);
74096- sys_chroot(".");
74097+ sys_chdir((const char __force_user *)"/root");
74098+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
74099+ sys_chroot((const char __force_user *)".");
74100 sys_setsid();
74101 return 0;
74102 }
74103@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
74104 create_dev("/dev/root.old", Root_RAM0);
74105 /* mount initrd on rootfs' /root */
74106 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
74107- sys_mkdir("/old", 0700);
74108- sys_chdir("/old");
74109+ sys_mkdir((const char __force_user *)"/old", 0700);
74110+ sys_chdir((const char __force_user *)"/old");
74111
74112 /* try loading default modules from initrd */
74113 load_default_modules();
74114@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
74115 current->flags &= ~PF_FREEZER_SKIP;
74116
74117 /* move initrd to rootfs' /old */
74118- sys_mount("..", ".", NULL, MS_MOVE, NULL);
74119+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
74120 /* switch root and cwd back to / of rootfs */
74121- sys_chroot("..");
74122+ sys_chroot((const char __force_user *)"..");
74123
74124 if (new_decode_dev(real_root_dev) == Root_RAM0) {
74125- sys_chdir("/old");
74126+ sys_chdir((const char __force_user *)"/old");
74127 return;
74128 }
74129
74130- sys_chdir("/");
74131+ sys_chdir((const char __force_user *)"/");
74132 ROOT_DEV = new_decode_dev(real_root_dev);
74133 mount_root();
74134
74135 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
74136- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
74137+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
74138 if (!error)
74139 printk("okay\n");
74140 else {
74141- int fd = sys_open("/dev/root.old", O_RDWR, 0);
74142+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
74143 if (error == -ENOENT)
74144 printk("/initrd does not exist. Ignored.\n");
74145 else
74146 printk("failed\n");
74147 printk(KERN_NOTICE "Unmounting old root\n");
74148- sys_umount("/old", MNT_DETACH);
74149+ sys_umount((char __force_user *)"/old", MNT_DETACH);
74150 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
74151 if (fd < 0) {
74152 error = fd;
74153@@ -127,11 +127,11 @@ int __init initrd_load(void)
74154 * mounted in the normal path.
74155 */
74156 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
74157- sys_unlink("/initrd.image");
74158+ sys_unlink((const char __force_user *)"/initrd.image");
74159 handle_initrd();
74160 return 1;
74161 }
74162 }
74163- sys_unlink("/initrd.image");
74164+ sys_unlink((const char __force_user *)"/initrd.image");
74165 return 0;
74166 }
74167diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
74168index 8cb6db5..d729f50 100644
74169--- a/init/do_mounts_md.c
74170+++ b/init/do_mounts_md.c
74171@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
74172 partitioned ? "_d" : "", minor,
74173 md_setup_args[ent].device_names);
74174
74175- fd = sys_open(name, 0, 0);
74176+ fd = sys_open((char __force_user *)name, 0, 0);
74177 if (fd < 0) {
74178 printk(KERN_ERR "md: open failed - cannot start "
74179 "array %s\n", name);
74180@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
74181 * array without it
74182 */
74183 sys_close(fd);
74184- fd = sys_open(name, 0, 0);
74185+ fd = sys_open((char __force_user *)name, 0, 0);
74186 sys_ioctl(fd, BLKRRPART, 0);
74187 }
74188 sys_close(fd);
74189@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
74190
74191 wait_for_device_probe();
74192
74193- fd = sys_open("/dev/md0", 0, 0);
74194+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
74195 if (fd >= 0) {
74196 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
74197 sys_close(fd);
74198diff --git a/init/init_task.c b/init/init_task.c
74199index ba0a7f36..2bcf1d5 100644
74200--- a/init/init_task.c
74201+++ b/init/init_task.c
74202@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
74203 * Initial thread structure. Alignment of this is handled by a special
74204 * linker map entry.
74205 */
74206+#ifdef CONFIG_X86
74207+union thread_union init_thread_union __init_task_data;
74208+#else
74209 union thread_union init_thread_union __init_task_data =
74210 { INIT_THREAD_INFO(init_task) };
74211+#endif
74212diff --git a/init/initramfs.c b/init/initramfs.c
74213index a67ef9d..2d17ed9 100644
74214--- a/init/initramfs.c
74215+++ b/init/initramfs.c
74216@@ -84,7 +84,7 @@ static void __init free_hash(void)
74217 }
74218 }
74219
74220-static long __init do_utime(char *filename, time_t mtime)
74221+static long __init do_utime(char __force_user *filename, time_t mtime)
74222 {
74223 struct timespec t[2];
74224
74225@@ -119,7 +119,7 @@ static void __init dir_utime(void)
74226 struct dir_entry *de, *tmp;
74227 list_for_each_entry_safe(de, tmp, &dir_list, list) {
74228 list_del(&de->list);
74229- do_utime(de->name, de->mtime);
74230+ do_utime((char __force_user *)de->name, de->mtime);
74231 kfree(de->name);
74232 kfree(de);
74233 }
74234@@ -281,7 +281,7 @@ static int __init maybe_link(void)
74235 if (nlink >= 2) {
74236 char *old = find_link(major, minor, ino, mode, collected);
74237 if (old)
74238- return (sys_link(old, collected) < 0) ? -1 : 1;
74239+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
74240 }
74241 return 0;
74242 }
74243@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
74244 {
74245 struct stat st;
74246
74247- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
74248+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
74249 if (S_ISDIR(st.st_mode))
74250- sys_rmdir(path);
74251+ sys_rmdir((char __force_user *)path);
74252 else
74253- sys_unlink(path);
74254+ sys_unlink((char __force_user *)path);
74255 }
74256 }
74257
74258@@ -315,7 +315,7 @@ static int __init do_name(void)
74259 int openflags = O_WRONLY|O_CREAT;
74260 if (ml != 1)
74261 openflags |= O_TRUNC;
74262- wfd = sys_open(collected, openflags, mode);
74263+ wfd = sys_open((char __force_user *)collected, openflags, mode);
74264
74265 if (wfd >= 0) {
74266 sys_fchown(wfd, uid, gid);
74267@@ -327,17 +327,17 @@ static int __init do_name(void)
74268 }
74269 }
74270 } else if (S_ISDIR(mode)) {
74271- sys_mkdir(collected, mode);
74272- sys_chown(collected, uid, gid);
74273- sys_chmod(collected, mode);
74274+ sys_mkdir((char __force_user *)collected, mode);
74275+ sys_chown((char __force_user *)collected, uid, gid);
74276+ sys_chmod((char __force_user *)collected, mode);
74277 dir_add(collected, mtime);
74278 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
74279 S_ISFIFO(mode) || S_ISSOCK(mode)) {
74280 if (maybe_link() == 0) {
74281- sys_mknod(collected, mode, rdev);
74282- sys_chown(collected, uid, gid);
74283- sys_chmod(collected, mode);
74284- do_utime(collected, mtime);
74285+ sys_mknod((char __force_user *)collected, mode, rdev);
74286+ sys_chown((char __force_user *)collected, uid, gid);
74287+ sys_chmod((char __force_user *)collected, mode);
74288+ do_utime((char __force_user *)collected, mtime);
74289 }
74290 }
74291 return 0;
74292@@ -346,15 +346,15 @@ static int __init do_name(void)
74293 static int __init do_copy(void)
74294 {
74295 if (count >= body_len) {
74296- sys_write(wfd, victim, body_len);
74297+ sys_write(wfd, (char __force_user *)victim, body_len);
74298 sys_close(wfd);
74299- do_utime(vcollected, mtime);
74300+ do_utime((char __force_user *)vcollected, mtime);
74301 kfree(vcollected);
74302 eat(body_len);
74303 state = SkipIt;
74304 return 0;
74305 } else {
74306- sys_write(wfd, victim, count);
74307+ sys_write(wfd, (char __force_user *)victim, count);
74308 body_len -= count;
74309 eat(count);
74310 return 1;
74311@@ -365,9 +365,9 @@ static int __init do_symlink(void)
74312 {
74313 collected[N_ALIGN(name_len) + body_len] = '\0';
74314 clean_path(collected, 0);
74315- sys_symlink(collected + N_ALIGN(name_len), collected);
74316- sys_lchown(collected, uid, gid);
74317- do_utime(collected, mtime);
74318+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
74319+ sys_lchown((char __force_user *)collected, uid, gid);
74320+ do_utime((char __force_user *)collected, mtime);
74321 state = SkipIt;
74322 next_state = Reset;
74323 return 0;
74324@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
74325 {
74326 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
74327 if (err)
74328- panic(err); /* Failed to decompress INTERNAL initramfs */
74329+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
74330 if (initrd_start) {
74331 #ifdef CONFIG_BLK_DEV_RAM
74332 int fd;
74333diff --git a/init/main.c b/init/main.c
74334index 9484f4b..4c01430 100644
74335--- a/init/main.c
74336+++ b/init/main.c
74337@@ -100,6 +100,8 @@ static inline void mark_rodata_ro(void) { }
74338 extern void tc_init(void);
74339 #endif
74340
74341+extern void grsecurity_init(void);
74342+
74343 /*
74344 * Debug helper: via this flag we know that we are in 'early bootup code'
74345 * where only the boot processor is running with IRQ disabled. This means
74346@@ -153,6 +155,64 @@ static int __init set_reset_devices(char *str)
74347
74348 __setup("reset_devices", set_reset_devices);
74349
74350+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74351+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
74352+static int __init setup_grsec_proc_gid(char *str)
74353+{
74354+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
74355+ return 1;
74356+}
74357+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
74358+#endif
74359+
74360+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
74361+unsigned long pax_user_shadow_base __read_only = 1UL << TASK_SIZE_MAX_SHIFT;
74362+EXPORT_SYMBOL(pax_user_shadow_base);
74363+extern char pax_enter_kernel_user[];
74364+extern char pax_exit_kernel_user[];
74365+extern pgdval_t clone_pgd_mask;
74366+#endif
74367+
74368+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
74369+static int __init setup_pax_nouderef(char *str)
74370+{
74371+#ifdef CONFIG_X86_32
74372+ unsigned int cpu;
74373+ struct desc_struct *gdt;
74374+
74375+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
74376+ gdt = get_cpu_gdt_table(cpu);
74377+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
74378+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
74379+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
74380+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
74381+ }
74382+ loadsegment(ds, __KERNEL_DS);
74383+ loadsegment(es, __KERNEL_DS);
74384+ loadsegment(ss, __KERNEL_DS);
74385+#else
74386+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
74387+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
74388+ clone_pgd_mask = ~(pgdval_t)0UL;
74389+ pax_user_shadow_base = 0UL;
74390+#endif
74391+
74392+ return 0;
74393+}
74394+early_param("pax_nouderef", setup_pax_nouderef);
74395+#endif
74396+
74397+#ifdef CONFIG_PAX_SOFTMODE
74398+int pax_softmode;
74399+
74400+static int __init setup_pax_softmode(char *str)
74401+{
74402+ get_option(&str, &pax_softmode);
74403+ return 1;
74404+}
74405+__setup("pax_softmode=", setup_pax_softmode);
74406+#endif
74407+
74408 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
74409 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
74410 static const char *panic_later, *panic_param;
74411@@ -655,8 +715,6 @@ static void __init do_ctors(void)
74412 bool initcall_debug;
74413 core_param(initcall_debug, initcall_debug, bool, 0644);
74414
74415-static char msgbuf[64];
74416-
74417 static int __init_or_module do_one_initcall_debug(initcall_t fn)
74418 {
74419 ktime_t calltime, delta, rettime;
74420@@ -679,23 +737,22 @@ int __init_or_module do_one_initcall(initcall_t fn)
74421 {
74422 int count = preempt_count();
74423 int ret;
74424+ const char *msg1 = "", *msg2 = "";
74425
74426 if (initcall_debug)
74427 ret = do_one_initcall_debug(fn);
74428 else
74429 ret = fn();
74430
74431- msgbuf[0] = 0;
74432-
74433 if (preempt_count() != count) {
74434- sprintf(msgbuf, "preemption imbalance ");
74435+ msg1 = " preemption imbalance";
74436 preempt_count() = count;
74437 }
74438 if (irqs_disabled()) {
74439- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
74440+ msg2 = " disabled interrupts";
74441 local_irq_enable();
74442 }
74443- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
74444+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
74445
74446 return ret;
74447 }
74448@@ -748,8 +805,14 @@ static void __init do_initcall_level(int level)
74449 level, level,
74450 &repair_env_string);
74451
74452- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
74453+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
74454 do_one_initcall(*fn);
74455+
74456+#ifdef LATENT_ENTROPY_PLUGIN
74457+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74458+#endif
74459+
74460+ }
74461 }
74462
74463 static void __init do_initcalls(void)
74464@@ -783,8 +846,14 @@ static void __init do_pre_smp_initcalls(void)
74465 {
74466 initcall_t *fn;
74467
74468- for (fn = __initcall_start; fn < __initcall0_start; fn++)
74469+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
74470 do_one_initcall(*fn);
74471+
74472+#ifdef LATENT_ENTROPY_PLUGIN
74473+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74474+#endif
74475+
74476+ }
74477 }
74478
74479 /*
74480@@ -802,8 +871,8 @@ static int run_init_process(const char *init_filename)
74481 {
74482 argv_init[0] = init_filename;
74483 return do_execve(init_filename,
74484- (const char __user *const __user *)argv_init,
74485- (const char __user *const __user *)envp_init);
74486+ (const char __user *const __force_user *)argv_init,
74487+ (const char __user *const __force_user *)envp_init);
74488 }
74489
74490 static noinline void __init kernel_init_freeable(void);
74491@@ -880,7 +949,7 @@ static noinline void __init kernel_init_freeable(void)
74492 do_basic_setup();
74493
74494 /* Open the /dev/console on the rootfs, this should never fail */
74495- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
74496+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
74497 pr_err("Warning: unable to open an initial console.\n");
74498
74499 (void) sys_dup(0);
74500@@ -893,11 +962,13 @@ static noinline void __init kernel_init_freeable(void)
74501 if (!ramdisk_execute_command)
74502 ramdisk_execute_command = "/init";
74503
74504- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
74505+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
74506 ramdisk_execute_command = NULL;
74507 prepare_namespace();
74508 }
74509
74510+ grsecurity_init();
74511+
74512 /*
74513 * Ok, we have completed the initial bootup, and
74514 * we're essentially up and running. Get rid of the
74515diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
74516index 130dfec..cc88451 100644
74517--- a/ipc/ipc_sysctl.c
74518+++ b/ipc/ipc_sysctl.c
74519@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
74520 static int proc_ipc_dointvec(ctl_table *table, int write,
74521 void __user *buffer, size_t *lenp, loff_t *ppos)
74522 {
74523- struct ctl_table ipc_table;
74524+ ctl_table_no_const ipc_table;
74525
74526 memcpy(&ipc_table, table, sizeof(ipc_table));
74527 ipc_table.data = get_ipc(table);
74528@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
74529 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
74530 void __user *buffer, size_t *lenp, loff_t *ppos)
74531 {
74532- struct ctl_table ipc_table;
74533+ ctl_table_no_const ipc_table;
74534
74535 memcpy(&ipc_table, table, sizeof(ipc_table));
74536 ipc_table.data = get_ipc(table);
74537@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
74538 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74539 void __user *buffer, size_t *lenp, loff_t *ppos)
74540 {
74541- struct ctl_table ipc_table;
74542+ ctl_table_no_const ipc_table;
74543 size_t lenp_bef = *lenp;
74544 int rc;
74545
74546@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74547 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
74548 void __user *buffer, size_t *lenp, loff_t *ppos)
74549 {
74550- struct ctl_table ipc_table;
74551+ ctl_table_no_const ipc_table;
74552 memcpy(&ipc_table, table, sizeof(ipc_table));
74553 ipc_table.data = get_ipc(table);
74554
74555@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
74556 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
74557 void __user *buffer, size_t *lenp, loff_t *ppos)
74558 {
74559- struct ctl_table ipc_table;
74560+ ctl_table_no_const ipc_table;
74561 size_t lenp_bef = *lenp;
74562 int oldval;
74563 int rc;
74564diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
74565index 383d638..943fdbb 100644
74566--- a/ipc/mq_sysctl.c
74567+++ b/ipc/mq_sysctl.c
74568@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
74569 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
74570 void __user *buffer, size_t *lenp, loff_t *ppos)
74571 {
74572- struct ctl_table mq_table;
74573+ ctl_table_no_const mq_table;
74574 memcpy(&mq_table, table, sizeof(mq_table));
74575 mq_table.data = get_mq(table);
74576
74577diff --git a/ipc/mqueue.c b/ipc/mqueue.c
74578index e4e47f6..a85e0ad 100644
74579--- a/ipc/mqueue.c
74580+++ b/ipc/mqueue.c
74581@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
74582 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
74583 info->attr.mq_msgsize);
74584
74585+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
74586 spin_lock(&mq_lock);
74587 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
74588 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
74589diff --git a/ipc/msg.c b/ipc/msg.c
74590index d0c6d96..69a893c 100644
74591--- a/ipc/msg.c
74592+++ b/ipc/msg.c
74593@@ -296,18 +296,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
74594 return security_msg_queue_associate(msq, msgflg);
74595 }
74596
74597+static struct ipc_ops msg_ops = {
74598+ .getnew = newque,
74599+ .associate = msg_security,
74600+ .more_checks = NULL
74601+};
74602+
74603 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
74604 {
74605 struct ipc_namespace *ns;
74606- struct ipc_ops msg_ops;
74607 struct ipc_params msg_params;
74608
74609 ns = current->nsproxy->ipc_ns;
74610
74611- msg_ops.getnew = newque;
74612- msg_ops.associate = msg_security;
74613- msg_ops.more_checks = NULL;
74614-
74615 msg_params.key = key;
74616 msg_params.flg = msgflg;
74617
74618diff --git a/ipc/sem.c b/ipc/sem.c
74619index 70480a3..f4e8262 100644
74620--- a/ipc/sem.c
74621+++ b/ipc/sem.c
74622@@ -460,10 +460,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
74623 return 0;
74624 }
74625
74626+static struct ipc_ops sem_ops = {
74627+ .getnew = newary,
74628+ .associate = sem_security,
74629+ .more_checks = sem_more_checks
74630+};
74631+
74632 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74633 {
74634 struct ipc_namespace *ns;
74635- struct ipc_ops sem_ops;
74636 struct ipc_params sem_params;
74637
74638 ns = current->nsproxy->ipc_ns;
74639@@ -471,10 +476,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74640 if (nsems < 0 || nsems > ns->sc_semmsl)
74641 return -EINVAL;
74642
74643- sem_ops.getnew = newary;
74644- sem_ops.associate = sem_security;
74645- sem_ops.more_checks = sem_more_checks;
74646-
74647 sem_params.key = key;
74648 sem_params.flg = semflg;
74649 sem_params.u.nsems = nsems;
74650diff --git a/ipc/shm.c b/ipc/shm.c
74651index 7e199fa..180a1ca 100644
74652--- a/ipc/shm.c
74653+++ b/ipc/shm.c
74654@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
74655 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
74656 #endif
74657
74658+#ifdef CONFIG_GRKERNSEC
74659+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74660+ const time_t shm_createtime, const kuid_t cuid,
74661+ const int shmid);
74662+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74663+ const time_t shm_createtime);
74664+#endif
74665+
74666 void shm_init_ns(struct ipc_namespace *ns)
74667 {
74668 ns->shm_ctlmax = SHMMAX;
74669@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
74670 shp->shm_lprid = 0;
74671 shp->shm_atim = shp->shm_dtim = 0;
74672 shp->shm_ctim = get_seconds();
74673+#ifdef CONFIG_GRKERNSEC
74674+ {
74675+ struct timespec timeval;
74676+ do_posix_clock_monotonic_gettime(&timeval);
74677+
74678+ shp->shm_createtime = timeval.tv_sec;
74679+ }
74680+#endif
74681 shp->shm_segsz = size;
74682 shp->shm_nattch = 0;
74683 shp->shm_file = file;
74684@@ -582,18 +598,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
74685 return 0;
74686 }
74687
74688+static struct ipc_ops shm_ops = {
74689+ .getnew = newseg,
74690+ .associate = shm_security,
74691+ .more_checks = shm_more_checks
74692+};
74693+
74694 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
74695 {
74696 struct ipc_namespace *ns;
74697- struct ipc_ops shm_ops;
74698 struct ipc_params shm_params;
74699
74700 ns = current->nsproxy->ipc_ns;
74701
74702- shm_ops.getnew = newseg;
74703- shm_ops.associate = shm_security;
74704- shm_ops.more_checks = shm_more_checks;
74705-
74706 shm_params.key = key;
74707 shm_params.flg = shmflg;
74708 shm_params.u.size = size;
74709@@ -1014,6 +1031,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74710 f_mode = FMODE_READ | FMODE_WRITE;
74711 }
74712 if (shmflg & SHM_EXEC) {
74713+
74714+#ifdef CONFIG_PAX_MPROTECT
74715+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
74716+ goto out;
74717+#endif
74718+
74719 prot |= PROT_EXEC;
74720 acc_mode |= S_IXUGO;
74721 }
74722@@ -1037,9 +1060,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74723 if (err)
74724 goto out_unlock;
74725
74726+#ifdef CONFIG_GRKERNSEC
74727+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
74728+ shp->shm_perm.cuid, shmid) ||
74729+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
74730+ err = -EACCES;
74731+ goto out_unlock;
74732+ }
74733+#endif
74734+
74735 path = shp->shm_file->f_path;
74736 path_get(&path);
74737 shp->shm_nattch++;
74738+#ifdef CONFIG_GRKERNSEC
74739+ shp->shm_lapid = current->pid;
74740+#endif
74741 size = i_size_read(path.dentry->d_inode);
74742 shm_unlock(shp);
74743
74744diff --git a/kernel/acct.c b/kernel/acct.c
74745index 8d6e145..33e0b1e 100644
74746--- a/kernel/acct.c
74747+++ b/kernel/acct.c
74748@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
74749 */
74750 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
74751 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
74752- file->f_op->write(file, (char *)&ac,
74753+ file->f_op->write(file, (char __force_user *)&ac,
74754 sizeof(acct_t), &file->f_pos);
74755 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
74756 set_fs(fs);
74757diff --git a/kernel/audit.c b/kernel/audit.c
74758index 91e53d0..d9e3ec4 100644
74759--- a/kernel/audit.c
74760+++ b/kernel/audit.c
74761@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
74762 3) suppressed due to audit_rate_limit
74763 4) suppressed due to audit_backlog_limit
74764 */
74765-static atomic_t audit_lost = ATOMIC_INIT(0);
74766+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
74767
74768 /* The netlink socket. */
74769 static struct sock *audit_sock;
74770@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
74771 unsigned long now;
74772 int print;
74773
74774- atomic_inc(&audit_lost);
74775+ atomic_inc_unchecked(&audit_lost);
74776
74777 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
74778
74779@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
74780 printk(KERN_WARNING
74781 "audit: audit_lost=%d audit_rate_limit=%d "
74782 "audit_backlog_limit=%d\n",
74783- atomic_read(&audit_lost),
74784+ atomic_read_unchecked(&audit_lost),
74785 audit_rate_limit,
74786 audit_backlog_limit);
74787 audit_panic(message);
74788@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
74789 status_set.pid = audit_pid;
74790 status_set.rate_limit = audit_rate_limit;
74791 status_set.backlog_limit = audit_backlog_limit;
74792- status_set.lost = atomic_read(&audit_lost);
74793+ status_set.lost = atomic_read_unchecked(&audit_lost);
74794 status_set.backlog = skb_queue_len(&audit_skb_queue);
74795 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
74796 &status_set, sizeof(status_set));
74797diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
74798index 6bd4a90..0ee9eff 100644
74799--- a/kernel/auditfilter.c
74800+++ b/kernel/auditfilter.c
74801@@ -423,7 +423,7 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
74802 f->lsm_rule = NULL;
74803
74804 /* Support legacy tests for a valid loginuid */
74805- if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295)) {
74806+ if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295U)) {
74807 f->type = AUDIT_LOGINUID_SET;
74808 f->val = 0;
74809 }
74810diff --git a/kernel/auditsc.c b/kernel/auditsc.c
74811index 3c8a601..3a416f6 100644
74812--- a/kernel/auditsc.c
74813+++ b/kernel/auditsc.c
74814@@ -1956,7 +1956,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
74815 }
74816
74817 /* global counter which is incremented every time something logs in */
74818-static atomic_t session_id = ATOMIC_INIT(0);
74819+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
74820
74821 /**
74822 * audit_set_loginuid - set current task's audit_context loginuid
74823@@ -1980,7 +1980,7 @@ int audit_set_loginuid(kuid_t loginuid)
74824 return -EPERM;
74825 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
74826
74827- sessionid = atomic_inc_return(&session_id);
74828+ sessionid = atomic_inc_return_unchecked(&session_id);
74829 if (context && context->in_syscall) {
74830 struct audit_buffer *ab;
74831
74832diff --git a/kernel/capability.c b/kernel/capability.c
74833index f6c2ce5..982c0f9 100644
74834--- a/kernel/capability.c
74835+++ b/kernel/capability.c
74836@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
74837 * before modification is attempted and the application
74838 * fails.
74839 */
74840+ if (tocopy > ARRAY_SIZE(kdata))
74841+ return -EFAULT;
74842+
74843 if (copy_to_user(dataptr, kdata, tocopy
74844 * sizeof(struct __user_cap_data_struct))) {
74845 return -EFAULT;
74846@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
74847 int ret;
74848
74849 rcu_read_lock();
74850- ret = security_capable(__task_cred(t), ns, cap);
74851+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
74852+ gr_task_is_capable(t, __task_cred(t), cap);
74853 rcu_read_unlock();
74854
74855- return (ret == 0);
74856+ return ret;
74857 }
74858
74859 /**
74860@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
74861 int ret;
74862
74863 rcu_read_lock();
74864- ret = security_capable_noaudit(__task_cred(t), ns, cap);
74865+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
74866 rcu_read_unlock();
74867
74868- return (ret == 0);
74869+ return ret;
74870 }
74871
74872 /**
74873@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
74874 BUG();
74875 }
74876
74877- if (security_capable(current_cred(), ns, cap) == 0) {
74878+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
74879 current->flags |= PF_SUPERPRIV;
74880 return true;
74881 }
74882@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
74883 }
74884 EXPORT_SYMBOL(ns_capable);
74885
74886+bool ns_capable_nolog(struct user_namespace *ns, int cap)
74887+{
74888+ if (unlikely(!cap_valid(cap))) {
74889+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
74890+ BUG();
74891+ }
74892+
74893+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
74894+ current->flags |= PF_SUPERPRIV;
74895+ return true;
74896+ }
74897+ return false;
74898+}
74899+EXPORT_SYMBOL(ns_capable_nolog);
74900+
74901 /**
74902 * file_ns_capable - Determine if the file's opener had a capability in effect
74903 * @file: The file we want to check
74904@@ -432,6 +451,12 @@ bool capable(int cap)
74905 }
74906 EXPORT_SYMBOL(capable);
74907
74908+bool capable_nolog(int cap)
74909+{
74910+ return ns_capable_nolog(&init_user_ns, cap);
74911+}
74912+EXPORT_SYMBOL(capable_nolog);
74913+
74914 /**
74915 * nsown_capable - Check superior capability to one's own user_ns
74916 * @cap: The capability in question
74917@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
74918
74919 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74920 }
74921+
74922+bool inode_capable_nolog(const struct inode *inode, int cap)
74923+{
74924+ struct user_namespace *ns = current_user_ns();
74925+
74926+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74927+}
74928diff --git a/kernel/cgroup.c b/kernel/cgroup.c
74929index a7c9e6d..a16aa75 100644
74930--- a/kernel/cgroup.c
74931+++ b/kernel/cgroup.c
74932@@ -5378,7 +5378,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
74933 struct css_set *cg = link->cg;
74934 struct task_struct *task;
74935 int count = 0;
74936- seq_printf(seq, "css_set %p\n", cg);
74937+ seq_printf(seq, "css_set %pK\n", cg);
74938 list_for_each_entry(task, &cg->tasks, cg_list) {
74939 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
74940 seq_puts(seq, " ...\n");
74941diff --git a/kernel/compat.c b/kernel/compat.c
74942index 0a09e48..f44f3f0 100644
74943--- a/kernel/compat.c
74944+++ b/kernel/compat.c
74945@@ -13,6 +13,7 @@
74946
74947 #include <linux/linkage.h>
74948 #include <linux/compat.h>
74949+#include <linux/module.h>
74950 #include <linux/errno.h>
74951 #include <linux/time.h>
74952 #include <linux/signal.h>
74953@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
74954 mm_segment_t oldfs;
74955 long ret;
74956
74957- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
74958+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
74959 oldfs = get_fs();
74960 set_fs(KERNEL_DS);
74961 ret = hrtimer_nanosleep_restart(restart);
74962@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
74963 oldfs = get_fs();
74964 set_fs(KERNEL_DS);
74965 ret = hrtimer_nanosleep(&tu,
74966- rmtp ? (struct timespec __user *)&rmt : NULL,
74967+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
74968 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
74969 set_fs(oldfs);
74970
74971@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
74972 mm_segment_t old_fs = get_fs();
74973
74974 set_fs(KERNEL_DS);
74975- ret = sys_sigpending((old_sigset_t __user *) &s);
74976+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
74977 set_fs(old_fs);
74978 if (ret == 0)
74979 ret = put_user(s, set);
74980@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
74981 mm_segment_t old_fs = get_fs();
74982
74983 set_fs(KERNEL_DS);
74984- ret = sys_old_getrlimit(resource, &r);
74985+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
74986 set_fs(old_fs);
74987
74988 if (!ret) {
74989@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
74990 set_fs (KERNEL_DS);
74991 ret = sys_wait4(pid,
74992 (stat_addr ?
74993- (unsigned int __user *) &status : NULL),
74994- options, (struct rusage __user *) &r);
74995+ (unsigned int __force_user *) &status : NULL),
74996+ options, (struct rusage __force_user *) &r);
74997 set_fs (old_fs);
74998
74999 if (ret > 0) {
75000@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
75001 memset(&info, 0, sizeof(info));
75002
75003 set_fs(KERNEL_DS);
75004- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
75005- uru ? (struct rusage __user *)&ru : NULL);
75006+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
75007+ uru ? (struct rusage __force_user *)&ru : NULL);
75008 set_fs(old_fs);
75009
75010 if ((ret < 0) || (info.si_signo == 0))
75011@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
75012 oldfs = get_fs();
75013 set_fs(KERNEL_DS);
75014 err = sys_timer_settime(timer_id, flags,
75015- (struct itimerspec __user *) &newts,
75016- (struct itimerspec __user *) &oldts);
75017+ (struct itimerspec __force_user *) &newts,
75018+ (struct itimerspec __force_user *) &oldts);
75019 set_fs(oldfs);
75020 if (!err && old && put_compat_itimerspec(old, &oldts))
75021 return -EFAULT;
75022@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
75023 oldfs = get_fs();
75024 set_fs(KERNEL_DS);
75025 err = sys_timer_gettime(timer_id,
75026- (struct itimerspec __user *) &ts);
75027+ (struct itimerspec __force_user *) &ts);
75028 set_fs(oldfs);
75029 if (!err && put_compat_itimerspec(setting, &ts))
75030 return -EFAULT;
75031@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
75032 oldfs = get_fs();
75033 set_fs(KERNEL_DS);
75034 err = sys_clock_settime(which_clock,
75035- (struct timespec __user *) &ts);
75036+ (struct timespec __force_user *) &ts);
75037 set_fs(oldfs);
75038 return err;
75039 }
75040@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
75041 oldfs = get_fs();
75042 set_fs(KERNEL_DS);
75043 err = sys_clock_gettime(which_clock,
75044- (struct timespec __user *) &ts);
75045+ (struct timespec __force_user *) &ts);
75046 set_fs(oldfs);
75047 if (!err && put_compat_timespec(&ts, tp))
75048 return -EFAULT;
75049@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
75050
75051 oldfs = get_fs();
75052 set_fs(KERNEL_DS);
75053- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
75054+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
75055 set_fs(oldfs);
75056
75057 err = compat_put_timex(utp, &txc);
75058@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
75059 oldfs = get_fs();
75060 set_fs(KERNEL_DS);
75061 err = sys_clock_getres(which_clock,
75062- (struct timespec __user *) &ts);
75063+ (struct timespec __force_user *) &ts);
75064 set_fs(oldfs);
75065 if (!err && tp && put_compat_timespec(&ts, tp))
75066 return -EFAULT;
75067@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
75068 long err;
75069 mm_segment_t oldfs;
75070 struct timespec tu;
75071- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
75072+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
75073
75074- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
75075+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
75076 oldfs = get_fs();
75077 set_fs(KERNEL_DS);
75078 err = clock_nanosleep_restart(restart);
75079@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
75080 oldfs = get_fs();
75081 set_fs(KERNEL_DS);
75082 err = sys_clock_nanosleep(which_clock, flags,
75083- (struct timespec __user *) &in,
75084- (struct timespec __user *) &out);
75085+ (struct timespec __force_user *) &in,
75086+ (struct timespec __force_user *) &out);
75087 set_fs(oldfs);
75088
75089 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
75090diff --git a/kernel/configs.c b/kernel/configs.c
75091index c18b1f1..b9a0132 100644
75092--- a/kernel/configs.c
75093+++ b/kernel/configs.c
75094@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
75095 struct proc_dir_entry *entry;
75096
75097 /* create the current config file */
75098+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
75099+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
75100+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
75101+ &ikconfig_file_ops);
75102+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75103+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
75104+ &ikconfig_file_ops);
75105+#endif
75106+#else
75107 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
75108 &ikconfig_file_ops);
75109+#endif
75110+
75111 if (!entry)
75112 return -ENOMEM;
75113
75114diff --git a/kernel/cred.c b/kernel/cred.c
75115index e0573a4..3874e41 100644
75116--- a/kernel/cred.c
75117+++ b/kernel/cred.c
75118@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
75119 validate_creds(cred);
75120 alter_cred_subscribers(cred, -1);
75121 put_cred(cred);
75122+
75123+#ifdef CONFIG_GRKERNSEC_SETXID
75124+ cred = (struct cred *) tsk->delayed_cred;
75125+ if (cred != NULL) {
75126+ tsk->delayed_cred = NULL;
75127+ validate_creds(cred);
75128+ alter_cred_subscribers(cred, -1);
75129+ put_cred(cred);
75130+ }
75131+#endif
75132 }
75133
75134 /**
75135@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
75136 * Always returns 0 thus allowing this function to be tail-called at the end
75137 * of, say, sys_setgid().
75138 */
75139-int commit_creds(struct cred *new)
75140+static int __commit_creds(struct cred *new)
75141 {
75142 struct task_struct *task = current;
75143 const struct cred *old = task->real_cred;
75144@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
75145
75146 get_cred(new); /* we will require a ref for the subj creds too */
75147
75148+ gr_set_role_label(task, new->uid, new->gid);
75149+
75150 /* dumpability changes */
75151 if (!uid_eq(old->euid, new->euid) ||
75152 !gid_eq(old->egid, new->egid) ||
75153@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
75154 put_cred(old);
75155 return 0;
75156 }
75157+#ifdef CONFIG_GRKERNSEC_SETXID
75158+extern int set_user(struct cred *new);
75159+
75160+void gr_delayed_cred_worker(void)
75161+{
75162+ const struct cred *new = current->delayed_cred;
75163+ struct cred *ncred;
75164+
75165+ current->delayed_cred = NULL;
75166+
75167+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
75168+ // from doing get_cred on it when queueing this
75169+ put_cred(new);
75170+ return;
75171+ } else if (new == NULL)
75172+ return;
75173+
75174+ ncred = prepare_creds();
75175+ if (!ncred)
75176+ goto die;
75177+ // uids
75178+ ncred->uid = new->uid;
75179+ ncred->euid = new->euid;
75180+ ncred->suid = new->suid;
75181+ ncred->fsuid = new->fsuid;
75182+ // gids
75183+ ncred->gid = new->gid;
75184+ ncred->egid = new->egid;
75185+ ncred->sgid = new->sgid;
75186+ ncred->fsgid = new->fsgid;
75187+ // groups
75188+ if (set_groups(ncred, new->group_info) < 0) {
75189+ abort_creds(ncred);
75190+ goto die;
75191+ }
75192+ // caps
75193+ ncred->securebits = new->securebits;
75194+ ncred->cap_inheritable = new->cap_inheritable;
75195+ ncred->cap_permitted = new->cap_permitted;
75196+ ncred->cap_effective = new->cap_effective;
75197+ ncred->cap_bset = new->cap_bset;
75198+
75199+ if (set_user(ncred)) {
75200+ abort_creds(ncred);
75201+ goto die;
75202+ }
75203+
75204+ // from doing get_cred on it when queueing this
75205+ put_cred(new);
75206+
75207+ __commit_creds(ncred);
75208+ return;
75209+die:
75210+ // from doing get_cred on it when queueing this
75211+ put_cred(new);
75212+ do_group_exit(SIGKILL);
75213+}
75214+#endif
75215+
75216+int commit_creds(struct cred *new)
75217+{
75218+#ifdef CONFIG_GRKERNSEC_SETXID
75219+ int ret;
75220+ int schedule_it = 0;
75221+ struct task_struct *t;
75222+
75223+ /* we won't get called with tasklist_lock held for writing
75224+ and interrupts disabled as the cred struct in that case is
75225+ init_cred
75226+ */
75227+ if (grsec_enable_setxid && !current_is_single_threaded() &&
75228+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
75229+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
75230+ schedule_it = 1;
75231+ }
75232+ ret = __commit_creds(new);
75233+ if (schedule_it) {
75234+ rcu_read_lock();
75235+ read_lock(&tasklist_lock);
75236+ for (t = next_thread(current); t != current;
75237+ t = next_thread(t)) {
75238+ if (t->delayed_cred == NULL) {
75239+ t->delayed_cred = get_cred(new);
75240+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
75241+ set_tsk_need_resched(t);
75242+ }
75243+ }
75244+ read_unlock(&tasklist_lock);
75245+ rcu_read_unlock();
75246+ }
75247+ return ret;
75248+#else
75249+ return __commit_creds(new);
75250+#endif
75251+}
75252+
75253 EXPORT_SYMBOL(commit_creds);
75254
75255 /**
75256diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
75257index 0506d44..2c20034 100644
75258--- a/kernel/debug/debug_core.c
75259+++ b/kernel/debug/debug_core.c
75260@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
75261 */
75262 static atomic_t masters_in_kgdb;
75263 static atomic_t slaves_in_kgdb;
75264-static atomic_t kgdb_break_tasklet_var;
75265+static atomic_unchecked_t kgdb_break_tasklet_var;
75266 atomic_t kgdb_setting_breakpoint;
75267
75268 struct task_struct *kgdb_usethread;
75269@@ -133,7 +133,7 @@ int kgdb_single_step;
75270 static pid_t kgdb_sstep_pid;
75271
75272 /* to keep track of the CPU which is doing the single stepping*/
75273-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75274+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75275
75276 /*
75277 * If you are debugging a problem where roundup (the collection of
75278@@ -541,7 +541,7 @@ return_normal:
75279 * kernel will only try for the value of sstep_tries before
75280 * giving up and continuing on.
75281 */
75282- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
75283+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
75284 (kgdb_info[cpu].task &&
75285 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
75286 atomic_set(&kgdb_active, -1);
75287@@ -635,8 +635,8 @@ cpu_master_loop:
75288 }
75289
75290 kgdb_restore:
75291- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
75292- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
75293+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
75294+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
75295 if (kgdb_info[sstep_cpu].task)
75296 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
75297 else
75298@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
75299 static void kgdb_tasklet_bpt(unsigned long ing)
75300 {
75301 kgdb_breakpoint();
75302- atomic_set(&kgdb_break_tasklet_var, 0);
75303+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
75304 }
75305
75306 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
75307
75308 void kgdb_schedule_breakpoint(void)
75309 {
75310- if (atomic_read(&kgdb_break_tasklet_var) ||
75311+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
75312 atomic_read(&kgdb_active) != -1 ||
75313 atomic_read(&kgdb_setting_breakpoint))
75314 return;
75315- atomic_inc(&kgdb_break_tasklet_var);
75316+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
75317 tasklet_schedule(&kgdb_tasklet_breakpoint);
75318 }
75319 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
75320diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
75321index 00eb8f7..d7e3244 100644
75322--- a/kernel/debug/kdb/kdb_main.c
75323+++ b/kernel/debug/kdb/kdb_main.c
75324@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
75325 continue;
75326
75327 kdb_printf("%-20s%8u 0x%p ", mod->name,
75328- mod->core_size, (void *)mod);
75329+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
75330 #ifdef CONFIG_MODULE_UNLOAD
75331 kdb_printf("%4ld ", module_refcount(mod));
75332 #endif
75333@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
75334 kdb_printf(" (Loading)");
75335 else
75336 kdb_printf(" (Live)");
75337- kdb_printf(" 0x%p", mod->module_core);
75338+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
75339
75340 #ifdef CONFIG_MODULE_UNLOAD
75341 {
75342diff --git a/kernel/events/core.c b/kernel/events/core.c
75343index b391907..a0e2372 100644
75344--- a/kernel/events/core.c
75345+++ b/kernel/events/core.c
75346@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
75347 * 0 - disallow raw tracepoint access for unpriv
75348 * 1 - disallow cpu events for unpriv
75349 * 2 - disallow kernel profiling for unpriv
75350+ * 3 - disallow all unpriv perf event use
75351 */
75352-int sysctl_perf_event_paranoid __read_mostly = 1;
75353+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
75354+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
75355+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
75356+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
75357+#else
75358+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
75359+#endif
75360
75361 /* Minimum for 512 kiB + 1 user control page */
75362 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
75363@@ -184,7 +191,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
75364 return 0;
75365 }
75366
75367-static atomic64_t perf_event_id;
75368+static atomic64_unchecked_t perf_event_id;
75369
75370 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
75371 enum event_type_t event_type);
75372@@ -2725,7 +2732,7 @@ static void __perf_event_read(void *info)
75373
75374 static inline u64 perf_event_count(struct perf_event *event)
75375 {
75376- return local64_read(&event->count) + atomic64_read(&event->child_count);
75377+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
75378 }
75379
75380 static u64 perf_event_read(struct perf_event *event)
75381@@ -3071,9 +3078,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
75382 mutex_lock(&event->child_mutex);
75383 total += perf_event_read(event);
75384 *enabled += event->total_time_enabled +
75385- atomic64_read(&event->child_total_time_enabled);
75386+ atomic64_read_unchecked(&event->child_total_time_enabled);
75387 *running += event->total_time_running +
75388- atomic64_read(&event->child_total_time_running);
75389+ atomic64_read_unchecked(&event->child_total_time_running);
75390
75391 list_for_each_entry(child, &event->child_list, child_list) {
75392 total += perf_event_read(child);
75393@@ -3459,10 +3466,10 @@ void perf_event_update_userpage(struct perf_event *event)
75394 userpg->offset -= local64_read(&event->hw.prev_count);
75395
75396 userpg->time_enabled = enabled +
75397- atomic64_read(&event->child_total_time_enabled);
75398+ atomic64_read_unchecked(&event->child_total_time_enabled);
75399
75400 userpg->time_running = running +
75401- atomic64_read(&event->child_total_time_running);
75402+ atomic64_read_unchecked(&event->child_total_time_running);
75403
75404 arch_perf_update_userpage(userpg, now);
75405
75406@@ -4012,7 +4019,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
75407
75408 /* Data. */
75409 sp = perf_user_stack_pointer(regs);
75410- rem = __output_copy_user(handle, (void *) sp, dump_size);
75411+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
75412 dyn_size = dump_size - rem;
75413
75414 perf_output_skip(handle, rem);
75415@@ -4100,11 +4107,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
75416 values[n++] = perf_event_count(event);
75417 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
75418 values[n++] = enabled +
75419- atomic64_read(&event->child_total_time_enabled);
75420+ atomic64_read_unchecked(&event->child_total_time_enabled);
75421 }
75422 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
75423 values[n++] = running +
75424- atomic64_read(&event->child_total_time_running);
75425+ atomic64_read_unchecked(&event->child_total_time_running);
75426 }
75427 if (read_format & PERF_FORMAT_ID)
75428 values[n++] = primary_event_id(event);
75429@@ -4813,12 +4820,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
75430 * need to add enough zero bytes after the string to handle
75431 * the 64bit alignment we do later.
75432 */
75433- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
75434+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
75435 if (!buf) {
75436 name = strncpy(tmp, "//enomem", sizeof(tmp));
75437 goto got_name;
75438 }
75439- name = d_path(&file->f_path, buf, PATH_MAX);
75440+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
75441 if (IS_ERR(name)) {
75442 name = strncpy(tmp, "//toolong", sizeof(tmp));
75443 goto got_name;
75444@@ -6240,7 +6247,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
75445 event->parent = parent_event;
75446
75447 event->ns = get_pid_ns(task_active_pid_ns(current));
75448- event->id = atomic64_inc_return(&perf_event_id);
75449+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
75450
75451 event->state = PERF_EVENT_STATE_INACTIVE;
75452
75453@@ -6550,6 +6557,11 @@ SYSCALL_DEFINE5(perf_event_open,
75454 if (flags & ~PERF_FLAG_ALL)
75455 return -EINVAL;
75456
75457+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
75458+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
75459+ return -EACCES;
75460+#endif
75461+
75462 err = perf_copy_attr(attr_uptr, &attr);
75463 if (err)
75464 return err;
75465@@ -6882,10 +6894,10 @@ static void sync_child_event(struct perf_event *child_event,
75466 /*
75467 * Add back the child's count to the parent's count:
75468 */
75469- atomic64_add(child_val, &parent_event->child_count);
75470- atomic64_add(child_event->total_time_enabled,
75471+ atomic64_add_unchecked(child_val, &parent_event->child_count);
75472+ atomic64_add_unchecked(child_event->total_time_enabled,
75473 &parent_event->child_total_time_enabled);
75474- atomic64_add(child_event->total_time_running,
75475+ atomic64_add_unchecked(child_event->total_time_running,
75476 &parent_event->child_total_time_running);
75477
75478 /*
75479diff --git a/kernel/events/internal.h b/kernel/events/internal.h
75480index ca65997..cc8cee4 100644
75481--- a/kernel/events/internal.h
75482+++ b/kernel/events/internal.h
75483@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
75484 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
75485 }
75486
75487-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
75488+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
75489 static inline unsigned int \
75490 func_name(struct perf_output_handle *handle, \
75491- const void *buf, unsigned int len) \
75492+ const void user *buf, unsigned int len) \
75493 { \
75494 unsigned long size, written; \
75495 \
75496@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
75497 return n;
75498 }
75499
75500-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
75501+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
75502
75503 #define MEMCPY_SKIP(dst, src, n) (n)
75504
75505-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
75506+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
75507
75508 #ifndef arch_perf_out_copy_user
75509 #define arch_perf_out_copy_user __copy_from_user_inatomic
75510 #endif
75511
75512-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
75513+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
75514
75515 /* Callchain handling */
75516 extern struct perf_callchain_entry *
75517diff --git a/kernel/exit.c b/kernel/exit.c
75518index 7bb73f9..d7978ed 100644
75519--- a/kernel/exit.c
75520+++ b/kernel/exit.c
75521@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
75522 struct task_struct *leader;
75523 int zap_leader;
75524 repeat:
75525+#ifdef CONFIG_NET
75526+ gr_del_task_from_ip_table(p);
75527+#endif
75528+
75529 /* don't need to get the RCU readlock here - the process is dead and
75530 * can't be modifying its own credentials. But shut RCU-lockdep up */
75531 rcu_read_lock();
75532@@ -340,7 +344,7 @@ int allow_signal(int sig)
75533 * know it'll be handled, so that they don't get converted to
75534 * SIGKILL or just silently dropped.
75535 */
75536- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
75537+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
75538 recalc_sigpending();
75539 spin_unlock_irq(&current->sighand->siglock);
75540 return 0;
75541@@ -709,6 +713,8 @@ void do_exit(long code)
75542 struct task_struct *tsk = current;
75543 int group_dead;
75544
75545+ set_fs(USER_DS);
75546+
75547 profile_task_exit(tsk);
75548
75549 WARN_ON(blk_needs_flush_plug(tsk));
75550@@ -725,7 +731,6 @@ void do_exit(long code)
75551 * mm_release()->clear_child_tid() from writing to a user-controlled
75552 * kernel address.
75553 */
75554- set_fs(USER_DS);
75555
75556 ptrace_event(PTRACE_EVENT_EXIT, code);
75557
75558@@ -784,6 +789,9 @@ void do_exit(long code)
75559 tsk->exit_code = code;
75560 taskstats_exit(tsk, group_dead);
75561
75562+ gr_acl_handle_psacct(tsk, code);
75563+ gr_acl_handle_exit();
75564+
75565 exit_mm(tsk);
75566
75567 if (group_dead)
75568@@ -905,7 +913,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
75569 * Take down every thread in the group. This is called by fatal signals
75570 * as well as by sys_exit_group (below).
75571 */
75572-void
75573+__noreturn void
75574 do_group_exit(int exit_code)
75575 {
75576 struct signal_struct *sig = current->signal;
75577diff --git a/kernel/fork.c b/kernel/fork.c
75578index 987b28a..4e03c05 100644
75579--- a/kernel/fork.c
75580+++ b/kernel/fork.c
75581@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
75582 *stackend = STACK_END_MAGIC; /* for overflow detection */
75583
75584 #ifdef CONFIG_CC_STACKPROTECTOR
75585- tsk->stack_canary = get_random_int();
75586+ tsk->stack_canary = pax_get_random_long();
75587 #endif
75588
75589 /*
75590@@ -345,13 +345,81 @@ free_tsk:
75591 }
75592
75593 #ifdef CONFIG_MMU
75594+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
75595+{
75596+ struct vm_area_struct *tmp;
75597+ unsigned long charge;
75598+ struct mempolicy *pol;
75599+ struct file *file;
75600+
75601+ charge = 0;
75602+ if (mpnt->vm_flags & VM_ACCOUNT) {
75603+ unsigned long len = vma_pages(mpnt);
75604+
75605+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75606+ goto fail_nomem;
75607+ charge = len;
75608+ }
75609+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75610+ if (!tmp)
75611+ goto fail_nomem;
75612+ *tmp = *mpnt;
75613+ tmp->vm_mm = mm;
75614+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
75615+ pol = mpol_dup(vma_policy(mpnt));
75616+ if (IS_ERR(pol))
75617+ goto fail_nomem_policy;
75618+ vma_set_policy(tmp, pol);
75619+ if (anon_vma_fork(tmp, mpnt))
75620+ goto fail_nomem_anon_vma_fork;
75621+ tmp->vm_flags &= ~VM_LOCKED;
75622+ tmp->vm_next = tmp->vm_prev = NULL;
75623+ tmp->vm_mirror = NULL;
75624+ file = tmp->vm_file;
75625+ if (file) {
75626+ struct inode *inode = file_inode(file);
75627+ struct address_space *mapping = file->f_mapping;
75628+
75629+ get_file(file);
75630+ if (tmp->vm_flags & VM_DENYWRITE)
75631+ atomic_dec(&inode->i_writecount);
75632+ mutex_lock(&mapping->i_mmap_mutex);
75633+ if (tmp->vm_flags & VM_SHARED)
75634+ mapping->i_mmap_writable++;
75635+ flush_dcache_mmap_lock(mapping);
75636+ /* insert tmp into the share list, just after mpnt */
75637+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75638+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
75639+ else
75640+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
75641+ flush_dcache_mmap_unlock(mapping);
75642+ mutex_unlock(&mapping->i_mmap_mutex);
75643+ }
75644+
75645+ /*
75646+ * Clear hugetlb-related page reserves for children. This only
75647+ * affects MAP_PRIVATE mappings. Faults generated by the child
75648+ * are not guaranteed to succeed, even if read-only
75649+ */
75650+ if (is_vm_hugetlb_page(tmp))
75651+ reset_vma_resv_huge_pages(tmp);
75652+
75653+ return tmp;
75654+
75655+fail_nomem_anon_vma_fork:
75656+ mpol_put(pol);
75657+fail_nomem_policy:
75658+ kmem_cache_free(vm_area_cachep, tmp);
75659+fail_nomem:
75660+ vm_unacct_memory(charge);
75661+ return NULL;
75662+}
75663+
75664 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75665 {
75666 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
75667 struct rb_node **rb_link, *rb_parent;
75668 int retval;
75669- unsigned long charge;
75670- struct mempolicy *pol;
75671
75672 uprobe_start_dup_mmap();
75673 down_write(&oldmm->mmap_sem);
75674@@ -365,8 +433,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75675 mm->locked_vm = 0;
75676 mm->mmap = NULL;
75677 mm->mmap_cache = NULL;
75678- mm->free_area_cache = oldmm->mmap_base;
75679- mm->cached_hole_size = ~0UL;
75680+ mm->free_area_cache = oldmm->free_area_cache;
75681+ mm->cached_hole_size = oldmm->cached_hole_size;
75682 mm->map_count = 0;
75683 cpumask_clear(mm_cpumask(mm));
75684 mm->mm_rb = RB_ROOT;
75685@@ -382,57 +450,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75686
75687 prev = NULL;
75688 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
75689- struct file *file;
75690-
75691 if (mpnt->vm_flags & VM_DONTCOPY) {
75692 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
75693 -vma_pages(mpnt));
75694 continue;
75695 }
75696- charge = 0;
75697- if (mpnt->vm_flags & VM_ACCOUNT) {
75698- unsigned long len = vma_pages(mpnt);
75699-
75700- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75701- goto fail_nomem;
75702- charge = len;
75703- }
75704- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75705- if (!tmp)
75706- goto fail_nomem;
75707- *tmp = *mpnt;
75708- INIT_LIST_HEAD(&tmp->anon_vma_chain);
75709- pol = mpol_dup(vma_policy(mpnt));
75710- retval = PTR_ERR(pol);
75711- if (IS_ERR(pol))
75712- goto fail_nomem_policy;
75713- vma_set_policy(tmp, pol);
75714- tmp->vm_mm = mm;
75715- if (anon_vma_fork(tmp, mpnt))
75716- goto fail_nomem_anon_vma_fork;
75717- tmp->vm_flags &= ~VM_LOCKED;
75718- tmp->vm_next = tmp->vm_prev = NULL;
75719- file = tmp->vm_file;
75720- if (file) {
75721- struct inode *inode = file_inode(file);
75722- struct address_space *mapping = file->f_mapping;
75723-
75724- get_file(file);
75725- if (tmp->vm_flags & VM_DENYWRITE)
75726- atomic_dec(&inode->i_writecount);
75727- mutex_lock(&mapping->i_mmap_mutex);
75728- if (tmp->vm_flags & VM_SHARED)
75729- mapping->i_mmap_writable++;
75730- flush_dcache_mmap_lock(mapping);
75731- /* insert tmp into the share list, just after mpnt */
75732- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75733- vma_nonlinear_insert(tmp,
75734- &mapping->i_mmap_nonlinear);
75735- else
75736- vma_interval_tree_insert_after(tmp, mpnt,
75737- &mapping->i_mmap);
75738- flush_dcache_mmap_unlock(mapping);
75739- mutex_unlock(&mapping->i_mmap_mutex);
75740+ tmp = dup_vma(mm, oldmm, mpnt);
75741+ if (!tmp) {
75742+ retval = -ENOMEM;
75743+ goto out;
75744 }
75745
75746 /*
75747@@ -464,6 +490,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75748 if (retval)
75749 goto out;
75750 }
75751+
75752+#ifdef CONFIG_PAX_SEGMEXEC
75753+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
75754+ struct vm_area_struct *mpnt_m;
75755+
75756+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
75757+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
75758+
75759+ if (!mpnt->vm_mirror)
75760+ continue;
75761+
75762+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
75763+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
75764+ mpnt->vm_mirror = mpnt_m;
75765+ } else {
75766+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
75767+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
75768+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
75769+ mpnt->vm_mirror->vm_mirror = mpnt;
75770+ }
75771+ }
75772+ BUG_ON(mpnt_m);
75773+ }
75774+#endif
75775+
75776 /* a new mm has just been created */
75777 arch_dup_mmap(oldmm, mm);
75778 retval = 0;
75779@@ -473,14 +524,6 @@ out:
75780 up_write(&oldmm->mmap_sem);
75781 uprobe_end_dup_mmap();
75782 return retval;
75783-fail_nomem_anon_vma_fork:
75784- mpol_put(pol);
75785-fail_nomem_policy:
75786- kmem_cache_free(vm_area_cachep, tmp);
75787-fail_nomem:
75788- retval = -ENOMEM;
75789- vm_unacct_memory(charge);
75790- goto out;
75791 }
75792
75793 static inline int mm_alloc_pgd(struct mm_struct *mm)
75794@@ -695,8 +738,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
75795 return ERR_PTR(err);
75796
75797 mm = get_task_mm(task);
75798- if (mm && mm != current->mm &&
75799- !ptrace_may_access(task, mode)) {
75800+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
75801+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
75802 mmput(mm);
75803 mm = ERR_PTR(-EACCES);
75804 }
75805@@ -918,13 +961,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
75806 spin_unlock(&fs->lock);
75807 return -EAGAIN;
75808 }
75809- fs->users++;
75810+ atomic_inc(&fs->users);
75811 spin_unlock(&fs->lock);
75812 return 0;
75813 }
75814 tsk->fs = copy_fs_struct(fs);
75815 if (!tsk->fs)
75816 return -ENOMEM;
75817+ /* Carry through gr_chroot_dentry and is_chrooted instead
75818+ of recomputing it here. Already copied when the task struct
75819+ is duplicated. This allows pivot_root to not be treated as
75820+ a chroot
75821+ */
75822+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
75823+
75824 return 0;
75825 }
75826
75827@@ -1197,10 +1247,13 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75828 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
75829 #endif
75830 retval = -EAGAIN;
75831+
75832+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
75833+
75834 if (atomic_read(&p->real_cred->user->processes) >=
75835 task_rlimit(p, RLIMIT_NPROC)) {
75836- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
75837- p->real_cred->user != INIT_USER)
75838+ if (p->real_cred->user != INIT_USER &&
75839+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
75840 goto bad_fork_free;
75841 }
75842 current->flags &= ~PF_NPROC_EXCEEDED;
75843@@ -1446,6 +1499,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75844 goto bad_fork_free_pid;
75845 }
75846
75847+ /* synchronizes with gr_set_acls()
75848+ we need to call this past the point of no return for fork()
75849+ */
75850+ gr_copy_label(p);
75851+
75852 if (clone_flags & CLONE_THREAD) {
75853 current->signal->nr_threads++;
75854 atomic_inc(&current->signal->live);
75855@@ -1529,6 +1587,8 @@ bad_fork_cleanup_count:
75856 bad_fork_free:
75857 free_task(p);
75858 fork_out:
75859+ gr_log_forkfail(retval);
75860+
75861 return ERR_PTR(retval);
75862 }
75863
75864@@ -1579,6 +1639,23 @@ long do_fork(unsigned long clone_flags,
75865 return -EINVAL;
75866 }
75867
75868+#ifdef CONFIG_GRKERNSEC
75869+ if (clone_flags & CLONE_NEWUSER) {
75870+ /*
75871+ * This doesn't really inspire confidence:
75872+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
75873+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
75874+ * Increases kernel attack surface in areas developers
75875+ * previously cared little about ("low importance due
75876+ * to requiring "root" capability")
75877+ * To be removed when this code receives *proper* review
75878+ */
75879+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
75880+ !capable(CAP_SETGID))
75881+ return -EPERM;
75882+ }
75883+#endif
75884+
75885 /*
75886 * Determine whether and which event to report to ptracer. When
75887 * called from kernel_thread or CLONE_UNTRACED is explicitly
75888@@ -1613,6 +1690,8 @@ long do_fork(unsigned long clone_flags,
75889 if (clone_flags & CLONE_PARENT_SETTID)
75890 put_user(nr, parent_tidptr);
75891
75892+ gr_handle_brute_check();
75893+
75894 if (clone_flags & CLONE_VFORK) {
75895 p->vfork_done = &vfork;
75896 init_completion(&vfork);
75897@@ -1763,7 +1842,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
75898 return 0;
75899
75900 /* don't need lock here; in the worst case we'll do useless copy */
75901- if (fs->users == 1)
75902+ if (atomic_read(&fs->users) == 1)
75903 return 0;
75904
75905 *new_fsp = copy_fs_struct(fs);
75906@@ -1875,7 +1954,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
75907 fs = current->fs;
75908 spin_lock(&fs->lock);
75909 current->fs = new_fs;
75910- if (--fs->users)
75911+ gr_set_chroot_entries(current, &current->fs->root);
75912+ if (atomic_dec_return(&fs->users))
75913 new_fs = NULL;
75914 else
75915 new_fs = fs;
75916diff --git a/kernel/futex.c b/kernel/futex.c
75917index 49dacfb..5c6b450 100644
75918--- a/kernel/futex.c
75919+++ b/kernel/futex.c
75920@@ -54,6 +54,7 @@
75921 #include <linux/mount.h>
75922 #include <linux/pagemap.h>
75923 #include <linux/syscalls.h>
75924+#include <linux/ptrace.h>
75925 #include <linux/signal.h>
75926 #include <linux/export.h>
75927 #include <linux/magic.h>
75928@@ -242,6 +243,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
75929 struct page *page, *page_head;
75930 int err, ro = 0;
75931
75932+#ifdef CONFIG_PAX_SEGMEXEC
75933+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
75934+ return -EFAULT;
75935+#endif
75936+
75937 /*
75938 * The futex address must be "naturally" aligned.
75939 */
75940@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
75941 {
75942 u32 curval;
75943 int i;
75944+ mm_segment_t oldfs;
75945
75946 /*
75947 * This will fail and we want it. Some arch implementations do
75948@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
75949 * implementation, the non-functional ones will return
75950 * -ENOSYS.
75951 */
75952+ oldfs = get_fs();
75953+ set_fs(USER_DS);
75954 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
75955 futex_cmpxchg_enabled = 1;
75956+ set_fs(oldfs);
75957
75958 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
75959 plist_head_init(&futex_queues[i].chain);
75960diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
75961index f9f44fd..29885e4 100644
75962--- a/kernel/futex_compat.c
75963+++ b/kernel/futex_compat.c
75964@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
75965 return 0;
75966 }
75967
75968-static void __user *futex_uaddr(struct robust_list __user *entry,
75969+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
75970 compat_long_t futex_offset)
75971 {
75972 compat_uptr_t base = ptr_to_compat(entry);
75973diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
75974index 9b22d03..6295b62 100644
75975--- a/kernel/gcov/base.c
75976+++ b/kernel/gcov/base.c
75977@@ -102,11 +102,6 @@ void gcov_enable_events(void)
75978 }
75979
75980 #ifdef CONFIG_MODULES
75981-static inline int within(void *addr, void *start, unsigned long size)
75982-{
75983- return ((addr >= start) && (addr < start + size));
75984-}
75985-
75986 /* Update list and generate events when modules are unloaded. */
75987 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75988 void *data)
75989@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75990 prev = NULL;
75991 /* Remove entries located in module from linked list. */
75992 for (info = gcov_info_head; info; info = info->next) {
75993- if (within(info, mod->module_core, mod->core_size)) {
75994+ if (within_module_core_rw((unsigned long)info, mod)) {
75995 if (prev)
75996 prev->next = info->next;
75997 else
75998diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
75999index fd4b13b..09a5ccb 100644
76000--- a/kernel/hrtimer.c
76001+++ b/kernel/hrtimer.c
76002@@ -1430,7 +1430,7 @@ void hrtimer_peek_ahead_timers(void)
76003 local_irq_restore(flags);
76004 }
76005
76006-static void run_hrtimer_softirq(struct softirq_action *h)
76007+static void run_hrtimer_softirq(void)
76008 {
76009 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
76010
76011@@ -1772,7 +1772,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
76012 return NOTIFY_OK;
76013 }
76014
76015-static struct notifier_block __cpuinitdata hrtimers_nb = {
76016+static struct notifier_block hrtimers_nb = {
76017 .notifier_call = hrtimer_cpu_notify,
76018 };
76019
76020diff --git a/kernel/irq_work.c b/kernel/irq_work.c
76021index 55fcce6..0e4cf34 100644
76022--- a/kernel/irq_work.c
76023+++ b/kernel/irq_work.c
76024@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
76025 return NOTIFY_OK;
76026 }
76027
76028-static struct notifier_block cpu_notify;
76029+static struct notifier_block cpu_notify = {
76030+ .notifier_call = irq_work_cpu_notify,
76031+ .priority = 0,
76032+};
76033
76034 static __init int irq_work_init_cpu_notifier(void)
76035 {
76036- cpu_notify.notifier_call = irq_work_cpu_notify;
76037- cpu_notify.priority = 0;
76038 register_cpu_notifier(&cpu_notify);
76039 return 0;
76040 }
76041diff --git a/kernel/jump_label.c b/kernel/jump_label.c
76042index 60f48fa..7f3a770 100644
76043--- a/kernel/jump_label.c
76044+++ b/kernel/jump_label.c
76045@@ -13,6 +13,7 @@
76046 #include <linux/sort.h>
76047 #include <linux/err.h>
76048 #include <linux/static_key.h>
76049+#include <linux/mm.h>
76050
76051 #ifdef HAVE_JUMP_LABEL
76052
76053@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
76054
76055 size = (((unsigned long)stop - (unsigned long)start)
76056 / sizeof(struct jump_entry));
76057+ pax_open_kernel();
76058 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
76059+ pax_close_kernel();
76060 }
76061
76062 static void jump_label_update(struct static_key *key, int enable);
76063@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
76064 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
76065 struct jump_entry *iter;
76066
76067+ pax_open_kernel();
76068 for (iter = iter_start; iter < iter_stop; iter++) {
76069 if (within_module_init(iter->code, mod))
76070 iter->code = 0;
76071 }
76072+ pax_close_kernel();
76073 }
76074
76075 static int
76076diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
76077index 3127ad5..159d880 100644
76078--- a/kernel/kallsyms.c
76079+++ b/kernel/kallsyms.c
76080@@ -11,6 +11,9 @@
76081 * Changed the compression method from stem compression to "table lookup"
76082 * compression (see scripts/kallsyms.c for a more complete description)
76083 */
76084+#ifdef CONFIG_GRKERNSEC_HIDESYM
76085+#define __INCLUDED_BY_HIDESYM 1
76086+#endif
76087 #include <linux/kallsyms.h>
76088 #include <linux/module.h>
76089 #include <linux/init.h>
76090@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
76091
76092 static inline int is_kernel_inittext(unsigned long addr)
76093 {
76094+ if (system_state != SYSTEM_BOOTING)
76095+ return 0;
76096+
76097 if (addr >= (unsigned long)_sinittext
76098 && addr <= (unsigned long)_einittext)
76099 return 1;
76100 return 0;
76101 }
76102
76103+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76104+#ifdef CONFIG_MODULES
76105+static inline int is_module_text(unsigned long addr)
76106+{
76107+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
76108+ return 1;
76109+
76110+ addr = ktla_ktva(addr);
76111+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
76112+}
76113+#else
76114+static inline int is_module_text(unsigned long addr)
76115+{
76116+ return 0;
76117+}
76118+#endif
76119+#endif
76120+
76121 static inline int is_kernel_text(unsigned long addr)
76122 {
76123 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
76124@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
76125
76126 static inline int is_kernel(unsigned long addr)
76127 {
76128+
76129+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76130+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
76131+ return 1;
76132+
76133+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
76134+#else
76135 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
76136+#endif
76137+
76138 return 1;
76139 return in_gate_area_no_mm(addr);
76140 }
76141
76142 static int is_ksym_addr(unsigned long addr)
76143 {
76144+
76145+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76146+ if (is_module_text(addr))
76147+ return 0;
76148+#endif
76149+
76150 if (all_var)
76151 return is_kernel(addr);
76152
76153@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
76154
76155 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
76156 {
76157- iter->name[0] = '\0';
76158 iter->nameoff = get_symbol_offset(new_pos);
76159 iter->pos = new_pos;
76160 }
76161@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
76162 {
76163 struct kallsym_iter *iter = m->private;
76164
76165+#ifdef CONFIG_GRKERNSEC_HIDESYM
76166+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
76167+ return 0;
76168+#endif
76169+
76170 /* Some debugging symbols have no name. Ignore them. */
76171 if (!iter->name[0])
76172 return 0;
76173@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
76174 */
76175 type = iter->exported ? toupper(iter->type) :
76176 tolower(iter->type);
76177+
76178 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
76179 type, iter->name, iter->module_name);
76180 } else
76181@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
76182 struct kallsym_iter *iter;
76183 int ret;
76184
76185- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
76186+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
76187 if (!iter)
76188 return -ENOMEM;
76189 reset_iter(iter, 0);
76190diff --git a/kernel/kcmp.c b/kernel/kcmp.c
76191index e30ac0f..3528cac 100644
76192--- a/kernel/kcmp.c
76193+++ b/kernel/kcmp.c
76194@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
76195 struct task_struct *task1, *task2;
76196 int ret;
76197
76198+#ifdef CONFIG_GRKERNSEC
76199+ return -ENOSYS;
76200+#endif
76201+
76202 rcu_read_lock();
76203
76204 /*
76205diff --git a/kernel/kexec.c b/kernel/kexec.c
76206index 59f7b55..4022f65 100644
76207--- a/kernel/kexec.c
76208+++ b/kernel/kexec.c
76209@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
76210 unsigned long flags)
76211 {
76212 struct compat_kexec_segment in;
76213- struct kexec_segment out, __user *ksegments;
76214+ struct kexec_segment out;
76215+ struct kexec_segment __user *ksegments;
76216 unsigned long i, result;
76217
76218 /* Don't allow clients that don't understand the native
76219diff --git a/kernel/kmod.c b/kernel/kmod.c
76220index 8241906..d625f2c 100644
76221--- a/kernel/kmod.c
76222+++ b/kernel/kmod.c
76223@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
76224 kfree(info->argv);
76225 }
76226
76227-static int call_modprobe(char *module_name, int wait)
76228+static int call_modprobe(char *module_name, char *module_param, int wait)
76229 {
76230 struct subprocess_info *info;
76231 static char *envp[] = {
76232@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
76233 NULL
76234 };
76235
76236- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
76237+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
76238 if (!argv)
76239 goto out;
76240
76241@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
76242 argv[1] = "-q";
76243 argv[2] = "--";
76244 argv[3] = module_name; /* check free_modprobe_argv() */
76245- argv[4] = NULL;
76246+ argv[4] = module_param;
76247+ argv[5] = NULL;
76248
76249 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
76250 NULL, free_modprobe_argv, NULL);
76251@@ -129,9 +130,8 @@ out:
76252 * If module auto-loading support is disabled then this function
76253 * becomes a no-operation.
76254 */
76255-int __request_module(bool wait, const char *fmt, ...)
76256+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
76257 {
76258- va_list args;
76259 char module_name[MODULE_NAME_LEN];
76260 unsigned int max_modprobes;
76261 int ret;
76262@@ -147,9 +147,7 @@ int __request_module(bool wait, const char *fmt, ...)
76263 */
76264 WARN_ON_ONCE(wait && current_is_async());
76265
76266- va_start(args, fmt);
76267- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
76268- va_end(args);
76269+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
76270 if (ret >= MODULE_NAME_LEN)
76271 return -ENAMETOOLONG;
76272
76273@@ -157,6 +155,20 @@ int __request_module(bool wait, const char *fmt, ...)
76274 if (ret)
76275 return ret;
76276
76277+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76278+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
76279+ /* hack to workaround consolekit/udisks stupidity */
76280+ read_lock(&tasklist_lock);
76281+ if (!strcmp(current->comm, "mount") &&
76282+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
76283+ read_unlock(&tasklist_lock);
76284+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
76285+ return -EPERM;
76286+ }
76287+ read_unlock(&tasklist_lock);
76288+ }
76289+#endif
76290+
76291 /* If modprobe needs a service that is in a module, we get a recursive
76292 * loop. Limit the number of running kmod threads to max_threads/2 or
76293 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
76294@@ -185,11 +197,52 @@ int __request_module(bool wait, const char *fmt, ...)
76295
76296 trace_module_request(module_name, wait, _RET_IP_);
76297
76298- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
76299+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
76300
76301 atomic_dec(&kmod_concurrent);
76302 return ret;
76303 }
76304+
76305+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
76306+{
76307+ va_list args;
76308+ int ret;
76309+
76310+ va_start(args, fmt);
76311+ ret = ____request_module(wait, module_param, fmt, args);
76312+ va_end(args);
76313+
76314+ return ret;
76315+}
76316+
76317+int __request_module(bool wait, const char *fmt, ...)
76318+{
76319+ va_list args;
76320+ int ret;
76321+
76322+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76323+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
76324+ char module_param[MODULE_NAME_LEN];
76325+
76326+ memset(module_param, 0, sizeof(module_param));
76327+
76328+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
76329+
76330+ va_start(args, fmt);
76331+ ret = ____request_module(wait, module_param, fmt, args);
76332+ va_end(args);
76333+
76334+ return ret;
76335+ }
76336+#endif
76337+
76338+ va_start(args, fmt);
76339+ ret = ____request_module(wait, NULL, fmt, args);
76340+ va_end(args);
76341+
76342+ return ret;
76343+}
76344+
76345 EXPORT_SYMBOL(__request_module);
76346 #endif /* CONFIG_MODULES */
76347
76348@@ -300,7 +353,7 @@ static int wait_for_helper(void *data)
76349 *
76350 * Thus the __user pointer cast is valid here.
76351 */
76352- sys_wait4(pid, (int __user *)&ret, 0, NULL);
76353+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
76354
76355 /*
76356 * If ret is 0, either ____call_usermodehelper failed and the
76357@@ -651,7 +704,7 @@ EXPORT_SYMBOL(call_usermodehelper);
76358 static int proc_cap_handler(struct ctl_table *table, int write,
76359 void __user *buffer, size_t *lenp, loff_t *ppos)
76360 {
76361- struct ctl_table t;
76362+ ctl_table_no_const t;
76363 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
76364 kernel_cap_t new_cap;
76365 int err, i;
76366diff --git a/kernel/kprobes.c b/kernel/kprobes.c
76367index bddf3b2..07b90dd 100644
76368--- a/kernel/kprobes.c
76369+++ b/kernel/kprobes.c
76370@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
76371 * kernel image and loaded module images reside. This is required
76372 * so x86_64 can correctly handle the %rip-relative fixups.
76373 */
76374- kip->insns = module_alloc(PAGE_SIZE);
76375+ kip->insns = module_alloc_exec(PAGE_SIZE);
76376 if (!kip->insns) {
76377 kfree(kip);
76378 return NULL;
76379@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
76380 */
76381 if (!list_is_singular(&kip->list)) {
76382 list_del(&kip->list);
76383- module_free(NULL, kip->insns);
76384+ module_free_exec(NULL, kip->insns);
76385 kfree(kip);
76386 }
76387 return 1;
76388@@ -2083,7 +2083,7 @@ static int __init init_kprobes(void)
76389 {
76390 int i, err = 0;
76391 unsigned long offset = 0, size = 0;
76392- char *modname, namebuf[128];
76393+ char *modname, namebuf[KSYM_NAME_LEN];
76394 const char *symbol_name;
76395 void *addr;
76396 struct kprobe_blackpoint *kb;
76397@@ -2168,11 +2168,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
76398 kprobe_type = "k";
76399
76400 if (sym)
76401- seq_printf(pi, "%p %s %s+0x%x %s ",
76402+ seq_printf(pi, "%pK %s %s+0x%x %s ",
76403 p->addr, kprobe_type, sym, offset,
76404 (modname ? modname : " "));
76405 else
76406- seq_printf(pi, "%p %s %p ",
76407+ seq_printf(pi, "%pK %s %pK ",
76408 p->addr, kprobe_type, p->addr);
76409
76410 if (!pp)
76411@@ -2209,7 +2209,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
76412 const char *sym = NULL;
76413 unsigned int i = *(loff_t *) v;
76414 unsigned long offset = 0;
76415- char *modname, namebuf[128];
76416+ char *modname, namebuf[KSYM_NAME_LEN];
76417
76418 head = &kprobe_table[i];
76419 preempt_disable();
76420diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
76421index 6ada93c..dce7d5d 100644
76422--- a/kernel/ksysfs.c
76423+++ b/kernel/ksysfs.c
76424@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
76425 {
76426 if (count+1 > UEVENT_HELPER_PATH_LEN)
76427 return -ENOENT;
76428+ if (!capable(CAP_SYS_ADMIN))
76429+ return -EPERM;
76430 memcpy(uevent_helper, buf, count);
76431 uevent_helper[count] = '\0';
76432 if (count && uevent_helper[count-1] == '\n')
76433@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
76434 return count;
76435 }
76436
76437-static struct bin_attribute notes_attr = {
76438+static bin_attribute_no_const notes_attr __read_only = {
76439 .attr = {
76440 .name = "notes",
76441 .mode = S_IRUGO,
76442diff --git a/kernel/lockdep.c b/kernel/lockdep.c
76443index 1f3186b..bb7dbc6 100644
76444--- a/kernel/lockdep.c
76445+++ b/kernel/lockdep.c
76446@@ -596,6 +596,10 @@ static int static_obj(void *obj)
76447 end = (unsigned long) &_end,
76448 addr = (unsigned long) obj;
76449
76450+#ifdef CONFIG_PAX_KERNEXEC
76451+ start = ktla_ktva(start);
76452+#endif
76453+
76454 /*
76455 * static variable?
76456 */
76457@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
76458 if (!static_obj(lock->key)) {
76459 debug_locks_off();
76460 printk("INFO: trying to register non-static key.\n");
76461+ printk("lock:%pS key:%pS.\n", lock, lock->key);
76462 printk("the code is fine but needs lockdep annotation.\n");
76463 printk("turning off the locking correctness validator.\n");
76464 dump_stack();
76465@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
76466 if (!class)
76467 return 0;
76468 }
76469- atomic_inc((atomic_t *)&class->ops);
76470+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
76471 if (very_verbose(class)) {
76472 printk("\nacquire class [%p] %s", class->key, class->name);
76473 if (class->name_version > 1)
76474diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
76475index b2c71c5..7b88d63 100644
76476--- a/kernel/lockdep_proc.c
76477+++ b/kernel/lockdep_proc.c
76478@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
76479 return 0;
76480 }
76481
76482- seq_printf(m, "%p", class->key);
76483+ seq_printf(m, "%pK", class->key);
76484 #ifdef CONFIG_DEBUG_LOCKDEP
76485 seq_printf(m, " OPS:%8ld", class->ops);
76486 #endif
76487@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
76488
76489 list_for_each_entry(entry, &class->locks_after, entry) {
76490 if (entry->distance == 1) {
76491- seq_printf(m, " -> [%p] ", entry->class->key);
76492+ seq_printf(m, " -> [%pK] ", entry->class->key);
76493 print_name(m, entry->class);
76494 seq_puts(m, "\n");
76495 }
76496@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
76497 if (!class->key)
76498 continue;
76499
76500- seq_printf(m, "[%p] ", class->key);
76501+ seq_printf(m, "[%pK] ", class->key);
76502 print_name(m, class);
76503 seq_puts(m, "\n");
76504 }
76505@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76506 if (!i)
76507 seq_line(m, '-', 40-namelen, namelen);
76508
76509- snprintf(ip, sizeof(ip), "[<%p>]",
76510+ snprintf(ip, sizeof(ip), "[<%pK>]",
76511 (void *)class->contention_point[i]);
76512 seq_printf(m, "%40s %14lu %29s %pS\n",
76513 name, stats->contention_point[i],
76514@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76515 if (!i)
76516 seq_line(m, '-', 40-namelen, namelen);
76517
76518- snprintf(ip, sizeof(ip), "[<%p>]",
76519+ snprintf(ip, sizeof(ip), "[<%pK>]",
76520 (void *)class->contending_point[i]);
76521 seq_printf(m, "%40s %14lu %29s %pS\n",
76522 name, stats->contending_point[i],
76523diff --git a/kernel/module.c b/kernel/module.c
76524index fa53db8..6f17200 100644
76525--- a/kernel/module.c
76526+++ b/kernel/module.c
76527@@ -61,6 +61,7 @@
76528 #include <linux/pfn.h>
76529 #include <linux/bsearch.h>
76530 #include <linux/fips.h>
76531+#include <linux/grsecurity.h>
76532 #include <uapi/linux/module.h>
76533 #include "module-internal.h"
76534
76535@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
76536
76537 /* Bounds of module allocation, for speeding __module_address.
76538 * Protected by module_mutex. */
76539-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
76540+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
76541+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
76542
76543 int register_module_notifier(struct notifier_block * nb)
76544 {
76545@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76546 return true;
76547
76548 list_for_each_entry_rcu(mod, &modules, list) {
76549- struct symsearch arr[] = {
76550+ struct symsearch modarr[] = {
76551 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
76552 NOT_GPL_ONLY, false },
76553 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
76554@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76555 if (mod->state == MODULE_STATE_UNFORMED)
76556 continue;
76557
76558- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
76559+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
76560 return true;
76561 }
76562 return false;
76563@@ -485,7 +487,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
76564 static int percpu_modalloc(struct module *mod,
76565 unsigned long size, unsigned long align)
76566 {
76567- if (align > PAGE_SIZE) {
76568+ if (align-1 >= PAGE_SIZE) {
76569 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
76570 mod->name, align, PAGE_SIZE);
76571 align = PAGE_SIZE;
76572@@ -1089,7 +1091,7 @@ struct module_attribute module_uevent =
76573 static ssize_t show_coresize(struct module_attribute *mattr,
76574 struct module_kobject *mk, char *buffer)
76575 {
76576- return sprintf(buffer, "%u\n", mk->mod->core_size);
76577+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
76578 }
76579
76580 static struct module_attribute modinfo_coresize =
76581@@ -1098,7 +1100,7 @@ static struct module_attribute modinfo_coresize =
76582 static ssize_t show_initsize(struct module_attribute *mattr,
76583 struct module_kobject *mk, char *buffer)
76584 {
76585- return sprintf(buffer, "%u\n", mk->mod->init_size);
76586+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
76587 }
76588
76589 static struct module_attribute modinfo_initsize =
76590@@ -1313,7 +1315,7 @@ resolve_symbol_wait(struct module *mod,
76591 */
76592 #ifdef CONFIG_SYSFS
76593
76594-#ifdef CONFIG_KALLSYMS
76595+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76596 static inline bool sect_empty(const Elf_Shdr *sect)
76597 {
76598 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
76599@@ -1453,7 +1455,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
76600 {
76601 unsigned int notes, loaded, i;
76602 struct module_notes_attrs *notes_attrs;
76603- struct bin_attribute *nattr;
76604+ bin_attribute_no_const *nattr;
76605
76606 /* failed to create section attributes, so can't create notes */
76607 if (!mod->sect_attrs)
76608@@ -1565,7 +1567,7 @@ static void del_usage_links(struct module *mod)
76609 static int module_add_modinfo_attrs(struct module *mod)
76610 {
76611 struct module_attribute *attr;
76612- struct module_attribute *temp_attr;
76613+ module_attribute_no_const *temp_attr;
76614 int error = 0;
76615 int i;
76616
76617@@ -1779,21 +1781,21 @@ static void set_section_ro_nx(void *base,
76618
76619 static void unset_module_core_ro_nx(struct module *mod)
76620 {
76621- set_page_attributes(mod->module_core + mod->core_text_size,
76622- mod->module_core + mod->core_size,
76623+ set_page_attributes(mod->module_core_rw,
76624+ mod->module_core_rw + mod->core_size_rw,
76625 set_memory_x);
76626- set_page_attributes(mod->module_core,
76627- mod->module_core + mod->core_ro_size,
76628+ set_page_attributes(mod->module_core_rx,
76629+ mod->module_core_rx + mod->core_size_rx,
76630 set_memory_rw);
76631 }
76632
76633 static void unset_module_init_ro_nx(struct module *mod)
76634 {
76635- set_page_attributes(mod->module_init + mod->init_text_size,
76636- mod->module_init + mod->init_size,
76637+ set_page_attributes(mod->module_init_rw,
76638+ mod->module_init_rw + mod->init_size_rw,
76639 set_memory_x);
76640- set_page_attributes(mod->module_init,
76641- mod->module_init + mod->init_ro_size,
76642+ set_page_attributes(mod->module_init_rx,
76643+ mod->module_init_rx + mod->init_size_rx,
76644 set_memory_rw);
76645 }
76646
76647@@ -1806,14 +1808,14 @@ void set_all_modules_text_rw(void)
76648 list_for_each_entry_rcu(mod, &modules, list) {
76649 if (mod->state == MODULE_STATE_UNFORMED)
76650 continue;
76651- if ((mod->module_core) && (mod->core_text_size)) {
76652- set_page_attributes(mod->module_core,
76653- mod->module_core + mod->core_text_size,
76654+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76655+ set_page_attributes(mod->module_core_rx,
76656+ mod->module_core_rx + mod->core_size_rx,
76657 set_memory_rw);
76658 }
76659- if ((mod->module_init) && (mod->init_text_size)) {
76660- set_page_attributes(mod->module_init,
76661- mod->module_init + mod->init_text_size,
76662+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76663+ set_page_attributes(mod->module_init_rx,
76664+ mod->module_init_rx + mod->init_size_rx,
76665 set_memory_rw);
76666 }
76667 }
76668@@ -1829,14 +1831,14 @@ void set_all_modules_text_ro(void)
76669 list_for_each_entry_rcu(mod, &modules, list) {
76670 if (mod->state == MODULE_STATE_UNFORMED)
76671 continue;
76672- if ((mod->module_core) && (mod->core_text_size)) {
76673- set_page_attributes(mod->module_core,
76674- mod->module_core + mod->core_text_size,
76675+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76676+ set_page_attributes(mod->module_core_rx,
76677+ mod->module_core_rx + mod->core_size_rx,
76678 set_memory_ro);
76679 }
76680- if ((mod->module_init) && (mod->init_text_size)) {
76681- set_page_attributes(mod->module_init,
76682- mod->module_init + mod->init_text_size,
76683+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76684+ set_page_attributes(mod->module_init_rx,
76685+ mod->module_init_rx + mod->init_size_rx,
76686 set_memory_ro);
76687 }
76688 }
76689@@ -1887,16 +1889,19 @@ static void free_module(struct module *mod)
76690
76691 /* This may be NULL, but that's OK */
76692 unset_module_init_ro_nx(mod);
76693- module_free(mod, mod->module_init);
76694+ module_free(mod, mod->module_init_rw);
76695+ module_free_exec(mod, mod->module_init_rx);
76696 kfree(mod->args);
76697 percpu_modfree(mod);
76698
76699 /* Free lock-classes: */
76700- lockdep_free_key_range(mod->module_core, mod->core_size);
76701+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
76702+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
76703
76704 /* Finally, free the core (containing the module structure) */
76705 unset_module_core_ro_nx(mod);
76706- module_free(mod, mod->module_core);
76707+ module_free_exec(mod, mod->module_core_rx);
76708+ module_free(mod, mod->module_core_rw);
76709
76710 #ifdef CONFIG_MPU
76711 update_protections(current->mm);
76712@@ -1966,9 +1971,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76713 int ret = 0;
76714 const struct kernel_symbol *ksym;
76715
76716+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76717+ int is_fs_load = 0;
76718+ int register_filesystem_found = 0;
76719+ char *p;
76720+
76721+ p = strstr(mod->args, "grsec_modharden_fs");
76722+ if (p) {
76723+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
76724+ /* copy \0 as well */
76725+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
76726+ is_fs_load = 1;
76727+ }
76728+#endif
76729+
76730 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
76731 const char *name = info->strtab + sym[i].st_name;
76732
76733+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76734+ /* it's a real shame this will never get ripped and copied
76735+ upstream! ;(
76736+ */
76737+ if (is_fs_load && !strcmp(name, "register_filesystem"))
76738+ register_filesystem_found = 1;
76739+#endif
76740+
76741 switch (sym[i].st_shndx) {
76742 case SHN_COMMON:
76743 /* We compiled with -fno-common. These are not
76744@@ -1989,7 +2016,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76745 ksym = resolve_symbol_wait(mod, info, name);
76746 /* Ok if resolved. */
76747 if (ksym && !IS_ERR(ksym)) {
76748+ pax_open_kernel();
76749 sym[i].st_value = ksym->value;
76750+ pax_close_kernel();
76751 break;
76752 }
76753
76754@@ -2008,11 +2037,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76755 secbase = (unsigned long)mod_percpu(mod);
76756 else
76757 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
76758+ pax_open_kernel();
76759 sym[i].st_value += secbase;
76760+ pax_close_kernel();
76761 break;
76762 }
76763 }
76764
76765+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76766+ if (is_fs_load && !register_filesystem_found) {
76767+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
76768+ ret = -EPERM;
76769+ }
76770+#endif
76771+
76772 return ret;
76773 }
76774
76775@@ -2096,22 +2134,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
76776 || s->sh_entsize != ~0UL
76777 || strstarts(sname, ".init"))
76778 continue;
76779- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
76780+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76781+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
76782+ else
76783+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
76784 pr_debug("\t%s\n", sname);
76785 }
76786- switch (m) {
76787- case 0: /* executable */
76788- mod->core_size = debug_align(mod->core_size);
76789- mod->core_text_size = mod->core_size;
76790- break;
76791- case 1: /* RO: text and ro-data */
76792- mod->core_size = debug_align(mod->core_size);
76793- mod->core_ro_size = mod->core_size;
76794- break;
76795- case 3: /* whole core */
76796- mod->core_size = debug_align(mod->core_size);
76797- break;
76798- }
76799 }
76800
76801 pr_debug("Init section allocation order:\n");
76802@@ -2125,23 +2153,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
76803 || s->sh_entsize != ~0UL
76804 || !strstarts(sname, ".init"))
76805 continue;
76806- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
76807- | INIT_OFFSET_MASK);
76808+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76809+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
76810+ else
76811+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
76812+ s->sh_entsize |= INIT_OFFSET_MASK;
76813 pr_debug("\t%s\n", sname);
76814 }
76815- switch (m) {
76816- case 0: /* executable */
76817- mod->init_size = debug_align(mod->init_size);
76818- mod->init_text_size = mod->init_size;
76819- break;
76820- case 1: /* RO: text and ro-data */
76821- mod->init_size = debug_align(mod->init_size);
76822- mod->init_ro_size = mod->init_size;
76823- break;
76824- case 3: /* whole init */
76825- mod->init_size = debug_align(mod->init_size);
76826- break;
76827- }
76828 }
76829 }
76830
76831@@ -2314,7 +2332,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76832
76833 /* Put symbol section at end of init part of module. */
76834 symsect->sh_flags |= SHF_ALLOC;
76835- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
76836+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
76837 info->index.sym) | INIT_OFFSET_MASK;
76838 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
76839
76840@@ -2331,13 +2349,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76841 }
76842
76843 /* Append room for core symbols at end of core part. */
76844- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
76845- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
76846- mod->core_size += strtab_size;
76847+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
76848+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
76849+ mod->core_size_rx += strtab_size;
76850
76851 /* Put string table section at end of init part of module. */
76852 strsect->sh_flags |= SHF_ALLOC;
76853- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
76854+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
76855 info->index.str) | INIT_OFFSET_MASK;
76856 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
76857 }
76858@@ -2355,12 +2373,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76859 /* Make sure we get permanent strtab: don't use info->strtab. */
76860 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
76861
76862+ pax_open_kernel();
76863+
76864 /* Set types up while we still have access to sections. */
76865 for (i = 0; i < mod->num_symtab; i++)
76866 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
76867
76868- mod->core_symtab = dst = mod->module_core + info->symoffs;
76869- mod->core_strtab = s = mod->module_core + info->stroffs;
76870+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
76871+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
76872 src = mod->symtab;
76873 for (ndst = i = 0; i < mod->num_symtab; i++) {
76874 if (i == 0 ||
76875@@ -2372,6 +2392,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76876 }
76877 }
76878 mod->core_num_syms = ndst;
76879+
76880+ pax_close_kernel();
76881 }
76882 #else
76883 static inline void layout_symtab(struct module *mod, struct load_info *info)
76884@@ -2405,17 +2427,33 @@ void * __weak module_alloc(unsigned long size)
76885 return vmalloc_exec(size);
76886 }
76887
76888-static void *module_alloc_update_bounds(unsigned long size)
76889+static void *module_alloc_update_bounds_rw(unsigned long size)
76890 {
76891 void *ret = module_alloc(size);
76892
76893 if (ret) {
76894 mutex_lock(&module_mutex);
76895 /* Update module bounds. */
76896- if ((unsigned long)ret < module_addr_min)
76897- module_addr_min = (unsigned long)ret;
76898- if ((unsigned long)ret + size > module_addr_max)
76899- module_addr_max = (unsigned long)ret + size;
76900+ if ((unsigned long)ret < module_addr_min_rw)
76901+ module_addr_min_rw = (unsigned long)ret;
76902+ if ((unsigned long)ret + size > module_addr_max_rw)
76903+ module_addr_max_rw = (unsigned long)ret + size;
76904+ mutex_unlock(&module_mutex);
76905+ }
76906+ return ret;
76907+}
76908+
76909+static void *module_alloc_update_bounds_rx(unsigned long size)
76910+{
76911+ void *ret = module_alloc_exec(size);
76912+
76913+ if (ret) {
76914+ mutex_lock(&module_mutex);
76915+ /* Update module bounds. */
76916+ if ((unsigned long)ret < module_addr_min_rx)
76917+ module_addr_min_rx = (unsigned long)ret;
76918+ if ((unsigned long)ret + size > module_addr_max_rx)
76919+ module_addr_max_rx = (unsigned long)ret + size;
76920 mutex_unlock(&module_mutex);
76921 }
76922 return ret;
76923@@ -2691,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
76924 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76925 {
76926 const char *modmagic = get_modinfo(info, "vermagic");
76927+ const char *license = get_modinfo(info, "license");
76928 int err;
76929
76930+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
76931+ if (!license || !license_is_gpl_compatible(license))
76932+ return -ENOEXEC;
76933+#endif
76934+
76935 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
76936 modmagic = NULL;
76937
76938@@ -2718,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76939 }
76940
76941 /* Set up license info based on the info section */
76942- set_license(mod, get_modinfo(info, "license"));
76943+ set_license(mod, license);
76944
76945 return 0;
76946 }
76947@@ -2799,7 +2843,7 @@ static int move_module(struct module *mod, struct load_info *info)
76948 void *ptr;
76949
76950 /* Do the allocs. */
76951- ptr = module_alloc_update_bounds(mod->core_size);
76952+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
76953 /*
76954 * The pointer to this block is stored in the module structure
76955 * which is inside the block. Just mark it as not being a
76956@@ -2809,11 +2853,11 @@ static int move_module(struct module *mod, struct load_info *info)
76957 if (!ptr)
76958 return -ENOMEM;
76959
76960- memset(ptr, 0, mod->core_size);
76961- mod->module_core = ptr;
76962+ memset(ptr, 0, mod->core_size_rw);
76963+ mod->module_core_rw = ptr;
76964
76965- if (mod->init_size) {
76966- ptr = module_alloc_update_bounds(mod->init_size);
76967+ if (mod->init_size_rw) {
76968+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
76969 /*
76970 * The pointer to this block is stored in the module structure
76971 * which is inside the block. This block doesn't need to be
76972@@ -2822,13 +2866,45 @@ static int move_module(struct module *mod, struct load_info *info)
76973 */
76974 kmemleak_ignore(ptr);
76975 if (!ptr) {
76976- module_free(mod, mod->module_core);
76977+ module_free(mod, mod->module_core_rw);
76978 return -ENOMEM;
76979 }
76980- memset(ptr, 0, mod->init_size);
76981- mod->module_init = ptr;
76982+ memset(ptr, 0, mod->init_size_rw);
76983+ mod->module_init_rw = ptr;
76984 } else
76985- mod->module_init = NULL;
76986+ mod->module_init_rw = NULL;
76987+
76988+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
76989+ kmemleak_not_leak(ptr);
76990+ if (!ptr) {
76991+ if (mod->module_init_rw)
76992+ module_free(mod, mod->module_init_rw);
76993+ module_free(mod, mod->module_core_rw);
76994+ return -ENOMEM;
76995+ }
76996+
76997+ pax_open_kernel();
76998+ memset(ptr, 0, mod->core_size_rx);
76999+ pax_close_kernel();
77000+ mod->module_core_rx = ptr;
77001+
77002+ if (mod->init_size_rx) {
77003+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
77004+ kmemleak_ignore(ptr);
77005+ if (!ptr && mod->init_size_rx) {
77006+ module_free_exec(mod, mod->module_core_rx);
77007+ if (mod->module_init_rw)
77008+ module_free(mod, mod->module_init_rw);
77009+ module_free(mod, mod->module_core_rw);
77010+ return -ENOMEM;
77011+ }
77012+
77013+ pax_open_kernel();
77014+ memset(ptr, 0, mod->init_size_rx);
77015+ pax_close_kernel();
77016+ mod->module_init_rx = ptr;
77017+ } else
77018+ mod->module_init_rx = NULL;
77019
77020 /* Transfer each section which specifies SHF_ALLOC */
77021 pr_debug("final section addresses:\n");
77022@@ -2839,16 +2915,45 @@ static int move_module(struct module *mod, struct load_info *info)
77023 if (!(shdr->sh_flags & SHF_ALLOC))
77024 continue;
77025
77026- if (shdr->sh_entsize & INIT_OFFSET_MASK)
77027- dest = mod->module_init
77028- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77029- else
77030- dest = mod->module_core + shdr->sh_entsize;
77031+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
77032+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
77033+ dest = mod->module_init_rw
77034+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77035+ else
77036+ dest = mod->module_init_rx
77037+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77038+ } else {
77039+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
77040+ dest = mod->module_core_rw + shdr->sh_entsize;
77041+ else
77042+ dest = mod->module_core_rx + shdr->sh_entsize;
77043+ }
77044+
77045+ if (shdr->sh_type != SHT_NOBITS) {
77046+
77047+#ifdef CONFIG_PAX_KERNEXEC
77048+#ifdef CONFIG_X86_64
77049+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
77050+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
77051+#endif
77052+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
77053+ pax_open_kernel();
77054+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
77055+ pax_close_kernel();
77056+ } else
77057+#endif
77058
77059- if (shdr->sh_type != SHT_NOBITS)
77060 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
77061+ }
77062 /* Update sh_addr to point to copy in image. */
77063- shdr->sh_addr = (unsigned long)dest;
77064+
77065+#ifdef CONFIG_PAX_KERNEXEC
77066+ if (shdr->sh_flags & SHF_EXECINSTR)
77067+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
77068+ else
77069+#endif
77070+
77071+ shdr->sh_addr = (unsigned long)dest;
77072 pr_debug("\t0x%lx %s\n",
77073 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
77074 }
77075@@ -2905,12 +3010,12 @@ static void flush_module_icache(const struct module *mod)
77076 * Do it before processing of module parameters, so the module
77077 * can provide parameter accessor functions of its own.
77078 */
77079- if (mod->module_init)
77080- flush_icache_range((unsigned long)mod->module_init,
77081- (unsigned long)mod->module_init
77082- + mod->init_size);
77083- flush_icache_range((unsigned long)mod->module_core,
77084- (unsigned long)mod->module_core + mod->core_size);
77085+ if (mod->module_init_rx)
77086+ flush_icache_range((unsigned long)mod->module_init_rx,
77087+ (unsigned long)mod->module_init_rx
77088+ + mod->init_size_rx);
77089+ flush_icache_range((unsigned long)mod->module_core_rx,
77090+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
77091
77092 set_fs(old_fs);
77093 }
77094@@ -2977,8 +3082,10 @@ static int alloc_module_percpu(struct module *mod, struct load_info *info)
77095 static void module_deallocate(struct module *mod, struct load_info *info)
77096 {
77097 percpu_modfree(mod);
77098- module_free(mod, mod->module_init);
77099- module_free(mod, mod->module_core);
77100+ module_free_exec(mod, mod->module_init_rx);
77101+ module_free_exec(mod, mod->module_core_rx);
77102+ module_free(mod, mod->module_init_rw);
77103+ module_free(mod, mod->module_core_rw);
77104 }
77105
77106 int __weak module_finalize(const Elf_Ehdr *hdr,
77107@@ -2991,7 +3098,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
77108 static int post_relocation(struct module *mod, const struct load_info *info)
77109 {
77110 /* Sort exception table now relocations are done. */
77111+ pax_open_kernel();
77112 sort_extable(mod->extable, mod->extable + mod->num_exentries);
77113+ pax_close_kernel();
77114
77115 /* Copy relocated percpu area over. */
77116 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
77117@@ -3045,16 +3154,16 @@ static int do_init_module(struct module *mod)
77118 MODULE_STATE_COMING, mod);
77119
77120 /* Set RO and NX regions for core */
77121- set_section_ro_nx(mod->module_core,
77122- mod->core_text_size,
77123- mod->core_ro_size,
77124- mod->core_size);
77125+ set_section_ro_nx(mod->module_core_rx,
77126+ mod->core_size_rx,
77127+ mod->core_size_rx,
77128+ mod->core_size_rx);
77129
77130 /* Set RO and NX regions for init */
77131- set_section_ro_nx(mod->module_init,
77132- mod->init_text_size,
77133- mod->init_ro_size,
77134- mod->init_size);
77135+ set_section_ro_nx(mod->module_init_rx,
77136+ mod->init_size_rx,
77137+ mod->init_size_rx,
77138+ mod->init_size_rx);
77139
77140 do_mod_ctors(mod);
77141 /* Start the module */
77142@@ -3116,11 +3225,12 @@ static int do_init_module(struct module *mod)
77143 mod->strtab = mod->core_strtab;
77144 #endif
77145 unset_module_init_ro_nx(mod);
77146- module_free(mod, mod->module_init);
77147- mod->module_init = NULL;
77148- mod->init_size = 0;
77149- mod->init_ro_size = 0;
77150- mod->init_text_size = 0;
77151+ module_free(mod, mod->module_init_rw);
77152+ module_free_exec(mod, mod->module_init_rx);
77153+ mod->module_init_rw = NULL;
77154+ mod->module_init_rx = NULL;
77155+ mod->init_size_rw = 0;
77156+ mod->init_size_rx = 0;
77157 mutex_unlock(&module_mutex);
77158 wake_up_all(&module_wq);
77159
77160@@ -3252,9 +3362,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
77161 if (err)
77162 goto free_unload;
77163
77164+ /* Now copy in args */
77165+ mod->args = strndup_user(uargs, ~0UL >> 1);
77166+ if (IS_ERR(mod->args)) {
77167+ err = PTR_ERR(mod->args);
77168+ goto free_unload;
77169+ }
77170+
77171 /* Set up MODINFO_ATTR fields */
77172 setup_modinfo(mod, info);
77173
77174+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77175+ {
77176+ char *p, *p2;
77177+
77178+ if (strstr(mod->args, "grsec_modharden_netdev")) {
77179+ 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);
77180+ err = -EPERM;
77181+ goto free_modinfo;
77182+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
77183+ p += sizeof("grsec_modharden_normal") - 1;
77184+ p2 = strstr(p, "_");
77185+ if (p2) {
77186+ *p2 = '\0';
77187+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
77188+ *p2 = '_';
77189+ }
77190+ err = -EPERM;
77191+ goto free_modinfo;
77192+ }
77193+ }
77194+#endif
77195+
77196 /* Fix up syms, so that st_value is a pointer to location. */
77197 err = simplify_symbols(mod, info);
77198 if (err < 0)
77199@@ -3270,13 +3409,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
77200
77201 flush_module_icache(mod);
77202
77203- /* Now copy in args */
77204- mod->args = strndup_user(uargs, ~0UL >> 1);
77205- if (IS_ERR(mod->args)) {
77206- err = PTR_ERR(mod->args);
77207- goto free_arch_cleanup;
77208- }
77209-
77210 dynamic_debug_setup(info->debug, info->num_debug);
77211
77212 /* Finally it's fully formed, ready to start executing. */
77213@@ -3311,11 +3443,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
77214 ddebug_cleanup:
77215 dynamic_debug_remove(info->debug);
77216 synchronize_sched();
77217- kfree(mod->args);
77218- free_arch_cleanup:
77219 module_arch_cleanup(mod);
77220 free_modinfo:
77221 free_modinfo(mod);
77222+ kfree(mod->args);
77223 free_unload:
77224 module_unload_free(mod);
77225 unlink_mod:
77226@@ -3398,10 +3529,16 @@ static const char *get_ksymbol(struct module *mod,
77227 unsigned long nextval;
77228
77229 /* At worse, next value is at end of module */
77230- if (within_module_init(addr, mod))
77231- nextval = (unsigned long)mod->module_init+mod->init_text_size;
77232+ if (within_module_init_rx(addr, mod))
77233+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
77234+ else if (within_module_init_rw(addr, mod))
77235+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
77236+ else if (within_module_core_rx(addr, mod))
77237+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
77238+ else if (within_module_core_rw(addr, mod))
77239+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
77240 else
77241- nextval = (unsigned long)mod->module_core+mod->core_text_size;
77242+ return NULL;
77243
77244 /* Scan for closest preceding symbol, and next symbol. (ELF
77245 starts real symbols at 1). */
77246@@ -3654,7 +3791,7 @@ static int m_show(struct seq_file *m, void *p)
77247 return 0;
77248
77249 seq_printf(m, "%s %u",
77250- mod->name, mod->init_size + mod->core_size);
77251+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
77252 print_unload_info(m, mod);
77253
77254 /* Informative for users. */
77255@@ -3663,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
77256 mod->state == MODULE_STATE_COMING ? "Loading":
77257 "Live");
77258 /* Used by oprofile and other similar tools. */
77259- seq_printf(m, " 0x%pK", mod->module_core);
77260+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
77261
77262 /* Taints info */
77263 if (mod->taints)
77264@@ -3699,7 +3836,17 @@ static const struct file_operations proc_modules_operations = {
77265
77266 static int __init proc_modules_init(void)
77267 {
77268+#ifndef CONFIG_GRKERNSEC_HIDESYM
77269+#ifdef CONFIG_GRKERNSEC_PROC_USER
77270+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
77271+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77272+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
77273+#else
77274 proc_create("modules", 0, NULL, &proc_modules_operations);
77275+#endif
77276+#else
77277+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
77278+#endif
77279 return 0;
77280 }
77281 module_init(proc_modules_init);
77282@@ -3760,14 +3907,14 @@ struct module *__module_address(unsigned long addr)
77283 {
77284 struct module *mod;
77285
77286- if (addr < module_addr_min || addr > module_addr_max)
77287+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
77288+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
77289 return NULL;
77290
77291 list_for_each_entry_rcu(mod, &modules, list) {
77292 if (mod->state == MODULE_STATE_UNFORMED)
77293 continue;
77294- if (within_module_core(addr, mod)
77295- || within_module_init(addr, mod))
77296+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
77297 return mod;
77298 }
77299 return NULL;
77300@@ -3802,11 +3949,20 @@ bool is_module_text_address(unsigned long addr)
77301 */
77302 struct module *__module_text_address(unsigned long addr)
77303 {
77304- struct module *mod = __module_address(addr);
77305+ struct module *mod;
77306+
77307+#ifdef CONFIG_X86_32
77308+ addr = ktla_ktva(addr);
77309+#endif
77310+
77311+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
77312+ return NULL;
77313+
77314+ mod = __module_address(addr);
77315+
77316 if (mod) {
77317 /* Make sure it's within the text section. */
77318- if (!within(addr, mod->module_init, mod->init_text_size)
77319- && !within(addr, mod->module_core, mod->core_text_size))
77320+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
77321 mod = NULL;
77322 }
77323 return mod;
77324diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
77325index 7e3443f..b2a1e6b 100644
77326--- a/kernel/mutex-debug.c
77327+++ b/kernel/mutex-debug.c
77328@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
77329 }
77330
77331 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77332- struct thread_info *ti)
77333+ struct task_struct *task)
77334 {
77335 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
77336
77337 /* Mark the current thread as blocked on the lock: */
77338- ti->task->blocked_on = waiter;
77339+ task->blocked_on = waiter;
77340 }
77341
77342 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77343- struct thread_info *ti)
77344+ struct task_struct *task)
77345 {
77346 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
77347- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
77348- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
77349- ti->task->blocked_on = NULL;
77350+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
77351+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
77352+ task->blocked_on = NULL;
77353
77354 list_del_init(&waiter->list);
77355 waiter->task = NULL;
77356diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
77357index 0799fd3..d06ae3b 100644
77358--- a/kernel/mutex-debug.h
77359+++ b/kernel/mutex-debug.h
77360@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
77361 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
77362 extern void debug_mutex_add_waiter(struct mutex *lock,
77363 struct mutex_waiter *waiter,
77364- struct thread_info *ti);
77365+ struct task_struct *task);
77366 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77367- struct thread_info *ti);
77368+ struct task_struct *task);
77369 extern void debug_mutex_unlock(struct mutex *lock);
77370 extern void debug_mutex_init(struct mutex *lock, const char *name,
77371 struct lock_class_key *key);
77372diff --git a/kernel/mutex.c b/kernel/mutex.c
77373index ad53a66..f1bf8bc 100644
77374--- a/kernel/mutex.c
77375+++ b/kernel/mutex.c
77376@@ -134,7 +134,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
77377 node->locked = 1;
77378 return;
77379 }
77380- ACCESS_ONCE(prev->next) = node;
77381+ ACCESS_ONCE_RW(prev->next) = node;
77382 smp_wmb();
77383 /* Wait until the lock holder passes the lock down */
77384 while (!ACCESS_ONCE(node->locked))
77385@@ -155,7 +155,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
77386 while (!(next = ACCESS_ONCE(node->next)))
77387 arch_mutex_cpu_relax();
77388 }
77389- ACCESS_ONCE(next->locked) = 1;
77390+ ACCESS_ONCE_RW(next->locked) = 1;
77391 smp_wmb();
77392 }
77393
77394@@ -341,7 +341,7 @@ slowpath:
77395 spin_lock_mutex(&lock->wait_lock, flags);
77396
77397 debug_mutex_lock_common(lock, &waiter);
77398- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
77399+ debug_mutex_add_waiter(lock, &waiter, task);
77400
77401 /* add waiting tasks to the end of the waitqueue (FIFO): */
77402 list_add_tail(&waiter.list, &lock->wait_list);
77403@@ -371,8 +371,7 @@ slowpath:
77404 * TASK_UNINTERRUPTIBLE case.)
77405 */
77406 if (unlikely(signal_pending_state(state, task))) {
77407- mutex_remove_waiter(lock, &waiter,
77408- task_thread_info(task));
77409+ mutex_remove_waiter(lock, &waiter, task);
77410 mutex_release(&lock->dep_map, 1, ip);
77411 spin_unlock_mutex(&lock->wait_lock, flags);
77412
77413@@ -391,7 +390,7 @@ slowpath:
77414 done:
77415 lock_acquired(&lock->dep_map, ip);
77416 /* got the lock - rejoice! */
77417- mutex_remove_waiter(lock, &waiter, current_thread_info());
77418+ mutex_remove_waiter(lock, &waiter, task);
77419 mutex_set_owner(lock);
77420
77421 /* set it to 0 if there are no waiters left: */
77422diff --git a/kernel/notifier.c b/kernel/notifier.c
77423index 2d5cc4c..d9ea600 100644
77424--- a/kernel/notifier.c
77425+++ b/kernel/notifier.c
77426@@ -5,6 +5,7 @@
77427 #include <linux/rcupdate.h>
77428 #include <linux/vmalloc.h>
77429 #include <linux/reboot.h>
77430+#include <linux/mm.h>
77431
77432 /*
77433 * Notifier list for kernel code which wants to be called
77434@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
77435 while ((*nl) != NULL) {
77436 if (n->priority > (*nl)->priority)
77437 break;
77438- nl = &((*nl)->next);
77439+ nl = (struct notifier_block **)&((*nl)->next);
77440 }
77441- n->next = *nl;
77442+ pax_open_kernel();
77443+ *(const void **)&n->next = *nl;
77444 rcu_assign_pointer(*nl, n);
77445+ pax_close_kernel();
77446 return 0;
77447 }
77448
77449@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
77450 return 0;
77451 if (n->priority > (*nl)->priority)
77452 break;
77453- nl = &((*nl)->next);
77454+ nl = (struct notifier_block **)&((*nl)->next);
77455 }
77456- n->next = *nl;
77457+ pax_open_kernel();
77458+ *(const void **)&n->next = *nl;
77459 rcu_assign_pointer(*nl, n);
77460+ pax_close_kernel();
77461 return 0;
77462 }
77463
77464@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
77465 {
77466 while ((*nl) != NULL) {
77467 if ((*nl) == n) {
77468+ pax_open_kernel();
77469 rcu_assign_pointer(*nl, n->next);
77470+ pax_close_kernel();
77471 return 0;
77472 }
77473- nl = &((*nl)->next);
77474+ nl = (struct notifier_block **)&((*nl)->next);
77475 }
77476 return -ENOENT;
77477 }
77478diff --git a/kernel/panic.c b/kernel/panic.c
77479index 167ec09..0dda5f9 100644
77480--- a/kernel/panic.c
77481+++ b/kernel/panic.c
77482@@ -400,7 +400,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
77483 unsigned taint, struct slowpath_args *args)
77484 {
77485 printk(KERN_WARNING "------------[ cut here ]------------\n");
77486- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
77487+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
77488
77489 if (args)
77490 vprintk(args->fmt, args->args);
77491@@ -453,7 +453,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
77492 */
77493 void __stack_chk_fail(void)
77494 {
77495- panic("stack-protector: Kernel stack is corrupted in: %p\n",
77496+ dump_stack();
77497+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
77498 __builtin_return_address(0));
77499 }
77500 EXPORT_SYMBOL(__stack_chk_fail);
77501diff --git a/kernel/pid.c b/kernel/pid.c
77502index 0db3e79..95b9dc2 100644
77503--- a/kernel/pid.c
77504+++ b/kernel/pid.c
77505@@ -33,6 +33,7 @@
77506 #include <linux/rculist.h>
77507 #include <linux/bootmem.h>
77508 #include <linux/hash.h>
77509+#include <linux/security.h>
77510 #include <linux/pid_namespace.h>
77511 #include <linux/init_task.h>
77512 #include <linux/syscalls.h>
77513@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
77514
77515 int pid_max = PID_MAX_DEFAULT;
77516
77517-#define RESERVED_PIDS 300
77518+#define RESERVED_PIDS 500
77519
77520 int pid_max_min = RESERVED_PIDS + 1;
77521 int pid_max_max = PID_MAX_LIMIT;
77522@@ -442,10 +443,18 @@ EXPORT_SYMBOL(pid_task);
77523 */
77524 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
77525 {
77526+ struct task_struct *task;
77527+
77528 rcu_lockdep_assert(rcu_read_lock_held(),
77529 "find_task_by_pid_ns() needs rcu_read_lock()"
77530 " protection");
77531- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77532+
77533+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77534+
77535+ if (gr_pid_is_chrooted(task))
77536+ return NULL;
77537+
77538+ return task;
77539 }
77540
77541 struct task_struct *find_task_by_vpid(pid_t vnr)
77542@@ -453,6 +462,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
77543 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
77544 }
77545
77546+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
77547+{
77548+ rcu_lockdep_assert(rcu_read_lock_held(),
77549+ "find_task_by_pid_ns() needs rcu_read_lock()"
77550+ " protection");
77551+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
77552+}
77553+
77554 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
77555 {
77556 struct pid *pid;
77557diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
77558index 6917e8e..9909aeb 100644
77559--- a/kernel/pid_namespace.c
77560+++ b/kernel/pid_namespace.c
77561@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
77562 void __user *buffer, size_t *lenp, loff_t *ppos)
77563 {
77564 struct pid_namespace *pid_ns = task_active_pid_ns(current);
77565- struct ctl_table tmp = *table;
77566+ ctl_table_no_const tmp = *table;
77567
77568 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
77569 return -EPERM;
77570diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
77571index 42670e9..8719c2f 100644
77572--- a/kernel/posix-cpu-timers.c
77573+++ b/kernel/posix-cpu-timers.c
77574@@ -1636,14 +1636,14 @@ struct k_clock clock_posix_cpu = {
77575
77576 static __init int init_posix_cpu_timers(void)
77577 {
77578- struct k_clock process = {
77579+ static struct k_clock process = {
77580 .clock_getres = process_cpu_clock_getres,
77581 .clock_get = process_cpu_clock_get,
77582 .timer_create = process_cpu_timer_create,
77583 .nsleep = process_cpu_nsleep,
77584 .nsleep_restart = process_cpu_nsleep_restart,
77585 };
77586- struct k_clock thread = {
77587+ static struct k_clock thread = {
77588 .clock_getres = thread_cpu_clock_getres,
77589 .clock_get = thread_cpu_clock_get,
77590 .timer_create = thread_cpu_timer_create,
77591diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
77592index 424c2d4..a9194f7 100644
77593--- a/kernel/posix-timers.c
77594+++ b/kernel/posix-timers.c
77595@@ -43,6 +43,7 @@
77596 #include <linux/hash.h>
77597 #include <linux/posix-clock.h>
77598 #include <linux/posix-timers.h>
77599+#include <linux/grsecurity.h>
77600 #include <linux/syscalls.h>
77601 #include <linux/wait.h>
77602 #include <linux/workqueue.h>
77603@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
77604 * which we beg off on and pass to do_sys_settimeofday().
77605 */
77606
77607-static struct k_clock posix_clocks[MAX_CLOCKS];
77608+static struct k_clock *posix_clocks[MAX_CLOCKS];
77609
77610 /*
77611 * These ones are defined below.
77612@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
77613 */
77614 static __init int init_posix_timers(void)
77615 {
77616- struct k_clock clock_realtime = {
77617+ static struct k_clock clock_realtime = {
77618 .clock_getres = hrtimer_get_res,
77619 .clock_get = posix_clock_realtime_get,
77620 .clock_set = posix_clock_realtime_set,
77621@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
77622 .timer_get = common_timer_get,
77623 .timer_del = common_timer_del,
77624 };
77625- struct k_clock clock_monotonic = {
77626+ static struct k_clock clock_monotonic = {
77627 .clock_getres = hrtimer_get_res,
77628 .clock_get = posix_ktime_get_ts,
77629 .nsleep = common_nsleep,
77630@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
77631 .timer_get = common_timer_get,
77632 .timer_del = common_timer_del,
77633 };
77634- struct k_clock clock_monotonic_raw = {
77635+ static struct k_clock clock_monotonic_raw = {
77636 .clock_getres = hrtimer_get_res,
77637 .clock_get = posix_get_monotonic_raw,
77638 };
77639- struct k_clock clock_realtime_coarse = {
77640+ static struct k_clock clock_realtime_coarse = {
77641 .clock_getres = posix_get_coarse_res,
77642 .clock_get = posix_get_realtime_coarse,
77643 };
77644- struct k_clock clock_monotonic_coarse = {
77645+ static struct k_clock clock_monotonic_coarse = {
77646 .clock_getres = posix_get_coarse_res,
77647 .clock_get = posix_get_monotonic_coarse,
77648 };
77649- struct k_clock clock_tai = {
77650+ static struct k_clock clock_tai = {
77651 .clock_getres = hrtimer_get_res,
77652 .clock_get = posix_get_tai,
77653 .nsleep = common_nsleep,
77654@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
77655 .timer_get = common_timer_get,
77656 .timer_del = common_timer_del,
77657 };
77658- struct k_clock clock_boottime = {
77659+ static struct k_clock clock_boottime = {
77660 .clock_getres = hrtimer_get_res,
77661 .clock_get = posix_get_boottime,
77662 .nsleep = common_nsleep,
77663@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
77664 return;
77665 }
77666
77667- posix_clocks[clock_id] = *new_clock;
77668+ posix_clocks[clock_id] = new_clock;
77669 }
77670 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
77671
77672@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
77673 return (id & CLOCKFD_MASK) == CLOCKFD ?
77674 &clock_posix_dynamic : &clock_posix_cpu;
77675
77676- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
77677+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
77678 return NULL;
77679- return &posix_clocks[id];
77680+ return posix_clocks[id];
77681 }
77682
77683 static int common_timer_create(struct k_itimer *new_timer)
77684@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
77685 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
77686 return -EFAULT;
77687
77688+ /* only the CLOCK_REALTIME clock can be set, all other clocks
77689+ have their clock_set fptr set to a nosettime dummy function
77690+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
77691+ call common_clock_set, which calls do_sys_settimeofday, which
77692+ we hook
77693+ */
77694+
77695 return kc->clock_set(which_clock, &new_tp);
77696 }
77697
77698diff --git a/kernel/power/process.c b/kernel/power/process.c
77699index 98088e0..aaf95c0 100644
77700--- a/kernel/power/process.c
77701+++ b/kernel/power/process.c
77702@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
77703 u64 elapsed_csecs64;
77704 unsigned int elapsed_csecs;
77705 bool wakeup = false;
77706+ bool timedout = false;
77707
77708 do_gettimeofday(&start);
77709
77710@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
77711
77712 while (true) {
77713 todo = 0;
77714+ if (time_after(jiffies, end_time))
77715+ timedout = true;
77716 read_lock(&tasklist_lock);
77717 do_each_thread(g, p) {
77718 if (p == current || !freeze_task(p))
77719 continue;
77720
77721- if (!freezer_should_skip(p))
77722+ if (!freezer_should_skip(p)) {
77723 todo++;
77724+ if (timedout) {
77725+ printk(KERN_ERR "Task refusing to freeze:\n");
77726+ sched_show_task(p);
77727+ }
77728+ }
77729 } while_each_thread(g, p);
77730 read_unlock(&tasklist_lock);
77731
77732@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
77733 todo += wq_busy;
77734 }
77735
77736- if (!todo || time_after(jiffies, end_time))
77737+ if (!todo || timedout)
77738 break;
77739
77740 if (pm_wakeup_pending()) {
77741diff --git a/kernel/printk.c b/kernel/printk.c
77742index 8212c1a..eb61021 100644
77743--- a/kernel/printk.c
77744+++ b/kernel/printk.c
77745@@ -390,6 +390,11 @@ static int check_syslog_permissions(int type, bool from_file)
77746 if (from_file && type != SYSLOG_ACTION_OPEN)
77747 return 0;
77748
77749+#ifdef CONFIG_GRKERNSEC_DMESG
77750+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
77751+ return -EPERM;
77752+#endif
77753+
77754 if (syslog_action_restricted(type)) {
77755 if (capable(CAP_SYSLOG))
77756 return 0;
77757diff --git a/kernel/profile.c b/kernel/profile.c
77758index 0bf4007..6234708 100644
77759--- a/kernel/profile.c
77760+++ b/kernel/profile.c
77761@@ -37,7 +37,7 @@ struct profile_hit {
77762 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
77763 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
77764
77765-static atomic_t *prof_buffer;
77766+static atomic_unchecked_t *prof_buffer;
77767 static unsigned long prof_len, prof_shift;
77768
77769 int prof_on __read_mostly;
77770@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
77771 hits[i].pc = 0;
77772 continue;
77773 }
77774- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77775+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77776 hits[i].hits = hits[i].pc = 0;
77777 }
77778 }
77779@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77780 * Add the current hit(s) and flush the write-queue out
77781 * to the global buffer:
77782 */
77783- atomic_add(nr_hits, &prof_buffer[pc]);
77784+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
77785 for (i = 0; i < NR_PROFILE_HIT; ++i) {
77786- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77787+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77788 hits[i].pc = hits[i].hits = 0;
77789 }
77790 out:
77791@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77792 {
77793 unsigned long pc;
77794 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
77795- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77796+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77797 }
77798 #endif /* !CONFIG_SMP */
77799
77800@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
77801 return -EFAULT;
77802 buf++; p++; count--; read++;
77803 }
77804- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
77805+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
77806 if (copy_to_user(buf, (void *)pnt, count))
77807 return -EFAULT;
77808 read += count;
77809@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
77810 }
77811 #endif
77812 profile_discard_flip_buffers();
77813- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
77814+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
77815 return count;
77816 }
77817
77818diff --git a/kernel/ptrace.c b/kernel/ptrace.c
77819index 335a7ae..3bbbceb 100644
77820--- a/kernel/ptrace.c
77821+++ b/kernel/ptrace.c
77822@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
77823 if (seize)
77824 flags |= PT_SEIZED;
77825 rcu_read_lock();
77826- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77827+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77828 flags |= PT_PTRACE_CAP;
77829 rcu_read_unlock();
77830 task->ptrace = flags;
77831@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
77832 break;
77833 return -EIO;
77834 }
77835- if (copy_to_user(dst, buf, retval))
77836+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
77837 return -EFAULT;
77838 copied += retval;
77839 src += retval;
77840@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
77841 bool seized = child->ptrace & PT_SEIZED;
77842 int ret = -EIO;
77843 siginfo_t siginfo, *si;
77844- void __user *datavp = (void __user *) data;
77845+ void __user *datavp = (__force void __user *) data;
77846 unsigned long __user *datalp = datavp;
77847 unsigned long flags;
77848
77849@@ -1011,14 +1011,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
77850 goto out;
77851 }
77852
77853+ if (gr_handle_ptrace(child, request)) {
77854+ ret = -EPERM;
77855+ goto out_put_task_struct;
77856+ }
77857+
77858 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77859 ret = ptrace_attach(child, request, addr, data);
77860 /*
77861 * Some architectures need to do book-keeping after
77862 * a ptrace attach.
77863 */
77864- if (!ret)
77865+ if (!ret) {
77866 arch_ptrace_attach(child);
77867+ gr_audit_ptrace(child);
77868+ }
77869 goto out_put_task_struct;
77870 }
77871
77872@@ -1046,7 +1053,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
77873 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
77874 if (copied != sizeof(tmp))
77875 return -EIO;
77876- return put_user(tmp, (unsigned long __user *)data);
77877+ return put_user(tmp, (__force unsigned long __user *)data);
77878 }
77879
77880 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
77881@@ -1140,7 +1147,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
77882 }
77883
77884 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77885- compat_long_t addr, compat_long_t data)
77886+ compat_ulong_t addr, compat_ulong_t data)
77887 {
77888 struct task_struct *child;
77889 long ret;
77890@@ -1156,14 +1163,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77891 goto out;
77892 }
77893
77894+ if (gr_handle_ptrace(child, request)) {
77895+ ret = -EPERM;
77896+ goto out_put_task_struct;
77897+ }
77898+
77899 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77900 ret = ptrace_attach(child, request, addr, data);
77901 /*
77902 * Some architectures need to do book-keeping after
77903 * a ptrace attach.
77904 */
77905- if (!ret)
77906+ if (!ret) {
77907 arch_ptrace_attach(child);
77908+ gr_audit_ptrace(child);
77909+ }
77910 goto out_put_task_struct;
77911 }
77912
77913diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
77914index 48ab703..07561d4 100644
77915--- a/kernel/rcupdate.c
77916+++ b/kernel/rcupdate.c
77917@@ -439,10 +439,10 @@ int rcu_jiffies_till_stall_check(void)
77918 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
77919 */
77920 if (till_stall_check < 3) {
77921- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
77922+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
77923 till_stall_check = 3;
77924 } else if (till_stall_check > 300) {
77925- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
77926+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
77927 till_stall_check = 300;
77928 }
77929 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
77930diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
77931index a0714a5..2ab5e34 100644
77932--- a/kernel/rcutiny.c
77933+++ b/kernel/rcutiny.c
77934@@ -46,7 +46,7 @@
77935 struct rcu_ctrlblk;
77936 static void invoke_rcu_callbacks(void);
77937 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
77938-static void rcu_process_callbacks(struct softirq_action *unused);
77939+static void rcu_process_callbacks(void);
77940 static void __call_rcu(struct rcu_head *head,
77941 void (*func)(struct rcu_head *rcu),
77942 struct rcu_ctrlblk *rcp);
77943@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
77944 rcu_is_callbacks_kthread()));
77945 }
77946
77947-static void rcu_process_callbacks(struct softirq_action *unused)
77948+static void rcu_process_callbacks(void)
77949 {
77950 __rcu_process_callbacks(&rcu_sched_ctrlblk);
77951 __rcu_process_callbacks(&rcu_bh_ctrlblk);
77952diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
77953index 8a23300..4255818 100644
77954--- a/kernel/rcutiny_plugin.h
77955+++ b/kernel/rcutiny_plugin.h
77956@@ -945,7 +945,7 @@ static int rcu_kthread(void *arg)
77957 have_rcu_kthread_work = morework;
77958 local_irq_restore(flags);
77959 if (work)
77960- rcu_process_callbacks(NULL);
77961+ rcu_process_callbacks();
77962 schedule_timeout_interruptible(1); /* Leave CPU for others. */
77963 }
77964
77965diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
77966index e1f3a8c..42c94a2 100644
77967--- a/kernel/rcutorture.c
77968+++ b/kernel/rcutorture.c
77969@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
77970 { 0 };
77971 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
77972 { 0 };
77973-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77974-static atomic_t n_rcu_torture_alloc;
77975-static atomic_t n_rcu_torture_alloc_fail;
77976-static atomic_t n_rcu_torture_free;
77977-static atomic_t n_rcu_torture_mberror;
77978-static atomic_t n_rcu_torture_error;
77979+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77980+static atomic_unchecked_t n_rcu_torture_alloc;
77981+static atomic_unchecked_t n_rcu_torture_alloc_fail;
77982+static atomic_unchecked_t n_rcu_torture_free;
77983+static atomic_unchecked_t n_rcu_torture_mberror;
77984+static atomic_unchecked_t n_rcu_torture_error;
77985 static long n_rcu_torture_barrier_error;
77986 static long n_rcu_torture_boost_ktrerror;
77987 static long n_rcu_torture_boost_rterror;
77988@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
77989
77990 spin_lock_bh(&rcu_torture_lock);
77991 if (list_empty(&rcu_torture_freelist)) {
77992- atomic_inc(&n_rcu_torture_alloc_fail);
77993+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
77994 spin_unlock_bh(&rcu_torture_lock);
77995 return NULL;
77996 }
77997- atomic_inc(&n_rcu_torture_alloc);
77998+ atomic_inc_unchecked(&n_rcu_torture_alloc);
77999 p = rcu_torture_freelist.next;
78000 list_del_init(p);
78001 spin_unlock_bh(&rcu_torture_lock);
78002@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
78003 static void
78004 rcu_torture_free(struct rcu_torture *p)
78005 {
78006- atomic_inc(&n_rcu_torture_free);
78007+ atomic_inc_unchecked(&n_rcu_torture_free);
78008 spin_lock_bh(&rcu_torture_lock);
78009 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
78010 spin_unlock_bh(&rcu_torture_lock);
78011@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
78012 i = rp->rtort_pipe_count;
78013 if (i > RCU_TORTURE_PIPE_LEN)
78014 i = RCU_TORTURE_PIPE_LEN;
78015- atomic_inc(&rcu_torture_wcount[i]);
78016+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78017 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
78018 rp->rtort_mbtest = 0;
78019 rcu_torture_free(rp);
78020@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
78021 i = rp->rtort_pipe_count;
78022 if (i > RCU_TORTURE_PIPE_LEN)
78023 i = RCU_TORTURE_PIPE_LEN;
78024- atomic_inc(&rcu_torture_wcount[i]);
78025+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78026 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
78027 rp->rtort_mbtest = 0;
78028 list_del(&rp->rtort_free);
78029@@ -990,7 +990,7 @@ rcu_torture_writer(void *arg)
78030 i = old_rp->rtort_pipe_count;
78031 if (i > RCU_TORTURE_PIPE_LEN)
78032 i = RCU_TORTURE_PIPE_LEN;
78033- atomic_inc(&rcu_torture_wcount[i]);
78034+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78035 old_rp->rtort_pipe_count++;
78036 cur_ops->deferred_free(old_rp);
78037 }
78038@@ -1076,7 +1076,7 @@ static void rcu_torture_timer(unsigned long unused)
78039 return;
78040 }
78041 if (p->rtort_mbtest == 0)
78042- atomic_inc(&n_rcu_torture_mberror);
78043+ atomic_inc_unchecked(&n_rcu_torture_mberror);
78044 spin_lock(&rand_lock);
78045 cur_ops->read_delay(&rand);
78046 n_rcu_torture_timers++;
78047@@ -1146,7 +1146,7 @@ rcu_torture_reader(void *arg)
78048 continue;
78049 }
78050 if (p->rtort_mbtest == 0)
78051- atomic_inc(&n_rcu_torture_mberror);
78052+ atomic_inc_unchecked(&n_rcu_torture_mberror);
78053 cur_ops->read_delay(&rand);
78054 preempt_disable();
78055 pipe_count = p->rtort_pipe_count;
78056@@ -1209,11 +1209,11 @@ rcu_torture_printk(char *page)
78057 rcu_torture_current,
78058 rcu_torture_current_version,
78059 list_empty(&rcu_torture_freelist),
78060- atomic_read(&n_rcu_torture_alloc),
78061- atomic_read(&n_rcu_torture_alloc_fail),
78062- atomic_read(&n_rcu_torture_free));
78063+ atomic_read_unchecked(&n_rcu_torture_alloc),
78064+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
78065+ atomic_read_unchecked(&n_rcu_torture_free));
78066 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
78067- atomic_read(&n_rcu_torture_mberror),
78068+ atomic_read_unchecked(&n_rcu_torture_mberror),
78069 n_rcu_torture_boost_ktrerror,
78070 n_rcu_torture_boost_rterror);
78071 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
78072@@ -1232,14 +1232,14 @@ rcu_torture_printk(char *page)
78073 n_barrier_attempts,
78074 n_rcu_torture_barrier_error);
78075 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
78076- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
78077+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
78078 n_rcu_torture_barrier_error != 0 ||
78079 n_rcu_torture_boost_ktrerror != 0 ||
78080 n_rcu_torture_boost_rterror != 0 ||
78081 n_rcu_torture_boost_failure != 0 ||
78082 i > 1) {
78083 cnt += sprintf(&page[cnt], "!!! ");
78084- atomic_inc(&n_rcu_torture_error);
78085+ atomic_inc_unchecked(&n_rcu_torture_error);
78086 WARN_ON_ONCE(1);
78087 }
78088 cnt += sprintf(&page[cnt], "Reader Pipe: ");
78089@@ -1253,7 +1253,7 @@ rcu_torture_printk(char *page)
78090 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
78091 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
78092 cnt += sprintf(&page[cnt], " %d",
78093- atomic_read(&rcu_torture_wcount[i]));
78094+ atomic_read_unchecked(&rcu_torture_wcount[i]));
78095 }
78096 cnt += sprintf(&page[cnt], "\n");
78097 if (cur_ops->stats)
78098@@ -1962,7 +1962,7 @@ rcu_torture_cleanup(void)
78099
78100 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
78101
78102- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
78103+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
78104 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
78105 else if (n_online_successes != n_online_attempts ||
78106 n_offline_successes != n_offline_attempts)
78107@@ -2031,18 +2031,18 @@ rcu_torture_init(void)
78108
78109 rcu_torture_current = NULL;
78110 rcu_torture_current_version = 0;
78111- atomic_set(&n_rcu_torture_alloc, 0);
78112- atomic_set(&n_rcu_torture_alloc_fail, 0);
78113- atomic_set(&n_rcu_torture_free, 0);
78114- atomic_set(&n_rcu_torture_mberror, 0);
78115- atomic_set(&n_rcu_torture_error, 0);
78116+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
78117+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
78118+ atomic_set_unchecked(&n_rcu_torture_free, 0);
78119+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
78120+ atomic_set_unchecked(&n_rcu_torture_error, 0);
78121 n_rcu_torture_barrier_error = 0;
78122 n_rcu_torture_boost_ktrerror = 0;
78123 n_rcu_torture_boost_rterror = 0;
78124 n_rcu_torture_boost_failure = 0;
78125 n_rcu_torture_boosts = 0;
78126 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
78127- atomic_set(&rcu_torture_wcount[i], 0);
78128+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
78129 for_each_possible_cpu(cpu) {
78130 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
78131 per_cpu(rcu_torture_count, cpu)[i] = 0;
78132diff --git a/kernel/rcutree.c b/kernel/rcutree.c
78133index 3538001..e379e0b 100644
78134--- a/kernel/rcutree.c
78135+++ b/kernel/rcutree.c
78136@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
78137 rcu_prepare_for_idle(smp_processor_id());
78138 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78139 smp_mb__before_atomic_inc(); /* See above. */
78140- atomic_inc(&rdtp->dynticks);
78141+ atomic_inc_unchecked(&rdtp->dynticks);
78142 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
78143- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78144+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78145
78146 /*
78147 * It is illegal to enter an extended quiescent state while
78148@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
78149 int user)
78150 {
78151 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
78152- atomic_inc(&rdtp->dynticks);
78153+ atomic_inc_unchecked(&rdtp->dynticks);
78154 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78155 smp_mb__after_atomic_inc(); /* See above. */
78156- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78157+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78158 rcu_cleanup_after_idle(smp_processor_id());
78159 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
78160 if (!user && !is_idle_task(current)) {
78161@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
78162 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
78163
78164 if (rdtp->dynticks_nmi_nesting == 0 &&
78165- (atomic_read(&rdtp->dynticks) & 0x1))
78166+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
78167 return;
78168 rdtp->dynticks_nmi_nesting++;
78169 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
78170- atomic_inc(&rdtp->dynticks);
78171+ atomic_inc_unchecked(&rdtp->dynticks);
78172 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78173 smp_mb__after_atomic_inc(); /* See above. */
78174- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78175+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78176 }
78177
78178 /**
78179@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
78180 return;
78181 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78182 smp_mb__before_atomic_inc(); /* See above. */
78183- atomic_inc(&rdtp->dynticks);
78184+ atomic_inc_unchecked(&rdtp->dynticks);
78185 smp_mb__after_atomic_inc(); /* Force delay to next write. */
78186- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78187+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78188 }
78189
78190 /**
78191@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
78192 int ret;
78193
78194 preempt_disable();
78195- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78196+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78197 preempt_enable();
78198 return ret;
78199 }
78200@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
78201 */
78202 static int dyntick_save_progress_counter(struct rcu_data *rdp)
78203 {
78204- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
78205+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78206 return (rdp->dynticks_snap & 0x1) == 0;
78207 }
78208
78209@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
78210 unsigned int curr;
78211 unsigned int snap;
78212
78213- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
78214+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78215 snap = (unsigned int)rdp->dynticks_snap;
78216
78217 /*
78218@@ -1440,9 +1440,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
78219 rdp = this_cpu_ptr(rsp->rda);
78220 rcu_preempt_check_blocked_tasks(rnp);
78221 rnp->qsmask = rnp->qsmaskinit;
78222- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
78223+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
78224 WARN_ON_ONCE(rnp->completed != rsp->completed);
78225- ACCESS_ONCE(rnp->completed) = rsp->completed;
78226+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
78227 if (rnp == rdp->mynode)
78228 rcu_start_gp_per_cpu(rsp, rnp, rdp);
78229 rcu_preempt_boost_start_gp(rnp);
78230@@ -1524,7 +1524,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
78231 */
78232 rcu_for_each_node_breadth_first(rsp, rnp) {
78233 raw_spin_lock_irq(&rnp->lock);
78234- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
78235+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
78236 rdp = this_cpu_ptr(rsp->rda);
78237 if (rnp == rdp->mynode)
78238 __rcu_process_gp_end(rsp, rnp, rdp);
78239@@ -1855,7 +1855,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
78240 rsp->qlen += rdp->qlen;
78241 rdp->n_cbs_orphaned += rdp->qlen;
78242 rdp->qlen_lazy = 0;
78243- ACCESS_ONCE(rdp->qlen) = 0;
78244+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78245 }
78246
78247 /*
78248@@ -2101,7 +2101,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
78249 }
78250 smp_mb(); /* List handling before counting for rcu_barrier(). */
78251 rdp->qlen_lazy -= count_lazy;
78252- ACCESS_ONCE(rdp->qlen) -= count;
78253+ ACCESS_ONCE_RW(rdp->qlen) -= count;
78254 rdp->n_cbs_invoked += count;
78255
78256 /* Reinstate batch limit if we have worked down the excess. */
78257@@ -2295,7 +2295,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
78258 /*
78259 * Do RCU core processing for the current CPU.
78260 */
78261-static void rcu_process_callbacks(struct softirq_action *unused)
78262+static void rcu_process_callbacks(void)
78263 {
78264 struct rcu_state *rsp;
78265
78266@@ -2419,7 +2419,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
78267 local_irq_restore(flags);
78268 return;
78269 }
78270- ACCESS_ONCE(rdp->qlen)++;
78271+ ACCESS_ONCE_RW(rdp->qlen)++;
78272 if (lazy)
78273 rdp->qlen_lazy++;
78274 else
78275@@ -2628,11 +2628,11 @@ void synchronize_sched_expedited(void)
78276 * counter wrap on a 32-bit system. Quite a few more CPUs would of
78277 * course be required on a 64-bit system.
78278 */
78279- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
78280+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
78281 (ulong)atomic_long_read(&rsp->expedited_done) +
78282 ULONG_MAX / 8)) {
78283 synchronize_sched();
78284- atomic_long_inc(&rsp->expedited_wrap);
78285+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
78286 return;
78287 }
78288
78289@@ -2640,7 +2640,7 @@ void synchronize_sched_expedited(void)
78290 * Take a ticket. Note that atomic_inc_return() implies a
78291 * full memory barrier.
78292 */
78293- snap = atomic_long_inc_return(&rsp->expedited_start);
78294+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
78295 firstsnap = snap;
78296 get_online_cpus();
78297 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
78298@@ -2653,14 +2653,14 @@ void synchronize_sched_expedited(void)
78299 synchronize_sched_expedited_cpu_stop,
78300 NULL) == -EAGAIN) {
78301 put_online_cpus();
78302- atomic_long_inc(&rsp->expedited_tryfail);
78303+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
78304
78305 /* Check to see if someone else did our work for us. */
78306 s = atomic_long_read(&rsp->expedited_done);
78307 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
78308 /* ensure test happens before caller kfree */
78309 smp_mb__before_atomic_inc(); /* ^^^ */
78310- atomic_long_inc(&rsp->expedited_workdone1);
78311+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
78312 return;
78313 }
78314
78315@@ -2669,7 +2669,7 @@ void synchronize_sched_expedited(void)
78316 udelay(trycount * num_online_cpus());
78317 } else {
78318 wait_rcu_gp(call_rcu_sched);
78319- atomic_long_inc(&rsp->expedited_normal);
78320+ atomic_long_inc_unchecked(&rsp->expedited_normal);
78321 return;
78322 }
78323
78324@@ -2678,7 +2678,7 @@ void synchronize_sched_expedited(void)
78325 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
78326 /* ensure test happens before caller kfree */
78327 smp_mb__before_atomic_inc(); /* ^^^ */
78328- atomic_long_inc(&rsp->expedited_workdone2);
78329+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
78330 return;
78331 }
78332
78333@@ -2690,10 +2690,10 @@ void synchronize_sched_expedited(void)
78334 * period works for us.
78335 */
78336 get_online_cpus();
78337- snap = atomic_long_read(&rsp->expedited_start);
78338+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
78339 smp_mb(); /* ensure read is before try_stop_cpus(). */
78340 }
78341- atomic_long_inc(&rsp->expedited_stoppedcpus);
78342+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
78343
78344 /*
78345 * Everyone up to our most recent fetch is covered by our grace
78346@@ -2702,16 +2702,16 @@ void synchronize_sched_expedited(void)
78347 * than we did already did their update.
78348 */
78349 do {
78350- atomic_long_inc(&rsp->expedited_done_tries);
78351+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
78352 s = atomic_long_read(&rsp->expedited_done);
78353 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
78354 /* ensure test happens before caller kfree */
78355 smp_mb__before_atomic_inc(); /* ^^^ */
78356- atomic_long_inc(&rsp->expedited_done_lost);
78357+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
78358 break;
78359 }
78360 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
78361- atomic_long_inc(&rsp->expedited_done_exit);
78362+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
78363
78364 put_online_cpus();
78365 }
78366@@ -2893,7 +2893,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78367 * ACCESS_ONCE() to prevent the compiler from speculating
78368 * the increment to precede the early-exit check.
78369 */
78370- ACCESS_ONCE(rsp->n_barrier_done)++;
78371+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78372 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
78373 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
78374 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
78375@@ -2943,7 +2943,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78376
78377 /* Increment ->n_barrier_done to prevent duplicate work. */
78378 smp_mb(); /* Keep increment after above mechanism. */
78379- ACCESS_ONCE(rsp->n_barrier_done)++;
78380+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78381 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
78382 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
78383 smp_mb(); /* Keep increment before caller's subsequent code. */
78384@@ -2988,10 +2988,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
78385 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
78386 init_callback_list(rdp);
78387 rdp->qlen_lazy = 0;
78388- ACCESS_ONCE(rdp->qlen) = 0;
78389+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78390 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
78391 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
78392- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
78393+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
78394 rdp->cpu = cpu;
78395 rdp->rsp = rsp;
78396 rcu_boot_init_nocb_percpu_data(rdp);
78397@@ -3024,8 +3024,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
78398 rdp->blimit = blimit;
78399 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
78400 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
78401- atomic_set(&rdp->dynticks->dynticks,
78402- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
78403+ atomic_set_unchecked(&rdp->dynticks->dynticks,
78404+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
78405 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
78406
78407 /* Add CPU to rcu_node bitmasks. */
78408@@ -3120,7 +3120,7 @@ static int __init rcu_spawn_gp_kthread(void)
78409 struct task_struct *t;
78410
78411 for_each_rcu_flavor(rsp) {
78412- t = kthread_run(rcu_gp_kthread, rsp, rsp->name);
78413+ t = kthread_run(rcu_gp_kthread, rsp, "%s", rsp->name);
78414 BUG_ON(IS_ERR(t));
78415 rnp = rcu_get_root(rsp);
78416 raw_spin_lock_irqsave(&rnp->lock, flags);
78417diff --git a/kernel/rcutree.h b/kernel/rcutree.h
78418index 4df5034..5ee93f2 100644
78419--- a/kernel/rcutree.h
78420+++ b/kernel/rcutree.h
78421@@ -87,7 +87,7 @@ struct rcu_dynticks {
78422 long long dynticks_nesting; /* Track irq/process nesting level. */
78423 /* Process level is worth LLONG_MAX/2. */
78424 int dynticks_nmi_nesting; /* Track NMI nesting level. */
78425- atomic_t dynticks; /* Even value for idle, else odd. */
78426+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
78427 #ifdef CONFIG_RCU_FAST_NO_HZ
78428 bool all_lazy; /* Are all CPU's CBs lazy? */
78429 unsigned long nonlazy_posted;
78430@@ -414,17 +414,17 @@ struct rcu_state {
78431 /* _rcu_barrier(). */
78432 /* End of fields guarded by barrier_mutex. */
78433
78434- atomic_long_t expedited_start; /* Starting ticket. */
78435- atomic_long_t expedited_done; /* Done ticket. */
78436- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
78437- atomic_long_t expedited_tryfail; /* # acquisition failures. */
78438- atomic_long_t expedited_workdone1; /* # done by others #1. */
78439- atomic_long_t expedited_workdone2; /* # done by others #2. */
78440- atomic_long_t expedited_normal; /* # fallbacks to normal. */
78441- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
78442- atomic_long_t expedited_done_tries; /* # tries to update _done. */
78443- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
78444- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
78445+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
78446+ atomic_long_t expedited_done; /* Done ticket. */
78447+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
78448+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
78449+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
78450+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
78451+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
78452+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
78453+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
78454+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
78455+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
78456
78457 unsigned long jiffies_force_qs; /* Time at which to invoke */
78458 /* force_quiescent_state(). */
78459diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
78460index 3db5a37..b395fb35 100644
78461--- a/kernel/rcutree_plugin.h
78462+++ b/kernel/rcutree_plugin.h
78463@@ -903,7 +903,7 @@ void synchronize_rcu_expedited(void)
78464
78465 /* Clean up and exit. */
78466 smp_mb(); /* ensure expedited GP seen before counter increment. */
78467- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
78468+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
78469 unlock_mb_ret:
78470 mutex_unlock(&sync_rcu_preempt_exp_mutex);
78471 mb_ret:
78472@@ -1451,7 +1451,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
78473 free_cpumask_var(cm);
78474 }
78475
78476-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
78477+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
78478 .store = &rcu_cpu_kthread_task,
78479 .thread_should_run = rcu_cpu_kthread_should_run,
78480 .thread_fn = rcu_cpu_kthread,
78481@@ -1916,7 +1916,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
78482 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
78483 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
78484 cpu, ticks_value, ticks_title,
78485- atomic_read(&rdtp->dynticks) & 0xfff,
78486+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
78487 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
78488 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
78489 fast_no_hz);
78490@@ -2079,7 +2079,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
78491
78492 /* Enqueue the callback on the nocb list and update counts. */
78493 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
78494- ACCESS_ONCE(*old_rhpp) = rhp;
78495+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
78496 atomic_long_add(rhcount, &rdp->nocb_q_count);
78497 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
78498
78499@@ -2219,12 +2219,12 @@ static int rcu_nocb_kthread(void *arg)
78500 * Extract queued callbacks, update counts, and wait
78501 * for a grace period to elapse.
78502 */
78503- ACCESS_ONCE(rdp->nocb_head) = NULL;
78504+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
78505 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
78506 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
78507 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
78508- ACCESS_ONCE(rdp->nocb_p_count) += c;
78509- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
78510+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
78511+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
78512 rcu_nocb_wait_gp(rdp);
78513
78514 /* Each pass through the following loop invokes a callback. */
78515@@ -2246,8 +2246,8 @@ static int rcu_nocb_kthread(void *arg)
78516 list = next;
78517 }
78518 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
78519- ACCESS_ONCE(rdp->nocb_p_count) -= c;
78520- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
78521+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
78522+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
78523 rdp->n_nocbs_invoked += c;
78524 }
78525 return 0;
78526@@ -2274,7 +2274,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
78527 t = kthread_run(rcu_nocb_kthread, rdp,
78528 "rcuo%c/%d", rsp->abbr, cpu);
78529 BUG_ON(IS_ERR(t));
78530- ACCESS_ONCE(rdp->nocb_kthread) = t;
78531+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
78532 }
78533 }
78534
78535diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
78536index cf6c174..a8f4b50 100644
78537--- a/kernel/rcutree_trace.c
78538+++ b/kernel/rcutree_trace.c
78539@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
78540 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
78541 rdp->passed_quiesce, rdp->qs_pending);
78542 seq_printf(m, " dt=%d/%llx/%d df=%lu",
78543- atomic_read(&rdp->dynticks->dynticks),
78544+ atomic_read_unchecked(&rdp->dynticks->dynticks),
78545 rdp->dynticks->dynticks_nesting,
78546 rdp->dynticks->dynticks_nmi_nesting,
78547 rdp->dynticks_fqs);
78548@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
78549 struct rcu_state *rsp = (struct rcu_state *)m->private;
78550
78551 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",
78552- atomic_long_read(&rsp->expedited_start),
78553+ atomic_long_read_unchecked(&rsp->expedited_start),
78554 atomic_long_read(&rsp->expedited_done),
78555- atomic_long_read(&rsp->expedited_wrap),
78556- atomic_long_read(&rsp->expedited_tryfail),
78557- atomic_long_read(&rsp->expedited_workdone1),
78558- atomic_long_read(&rsp->expedited_workdone2),
78559- atomic_long_read(&rsp->expedited_normal),
78560- atomic_long_read(&rsp->expedited_stoppedcpus),
78561- atomic_long_read(&rsp->expedited_done_tries),
78562- atomic_long_read(&rsp->expedited_done_lost),
78563- atomic_long_read(&rsp->expedited_done_exit));
78564+ atomic_long_read_unchecked(&rsp->expedited_wrap),
78565+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
78566+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
78567+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
78568+ atomic_long_read_unchecked(&rsp->expedited_normal),
78569+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
78570+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
78571+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
78572+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
78573 return 0;
78574 }
78575
78576diff --git a/kernel/resource.c b/kernel/resource.c
78577index d738698..5f8e60a 100644
78578--- a/kernel/resource.c
78579+++ b/kernel/resource.c
78580@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
78581
78582 static int __init ioresources_init(void)
78583 {
78584+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78585+#ifdef CONFIG_GRKERNSEC_PROC_USER
78586+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
78587+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
78588+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78589+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
78590+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
78591+#endif
78592+#else
78593 proc_create("ioports", 0, NULL, &proc_ioports_operations);
78594 proc_create("iomem", 0, NULL, &proc_iomem_operations);
78595+#endif
78596 return 0;
78597 }
78598 __initcall(ioresources_init);
78599diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
78600index 1d96dd0..994ff19 100644
78601--- a/kernel/rtmutex-tester.c
78602+++ b/kernel/rtmutex-tester.c
78603@@ -22,7 +22,7 @@
78604 #define MAX_RT_TEST_MUTEXES 8
78605
78606 static spinlock_t rttest_lock;
78607-static atomic_t rttest_event;
78608+static atomic_unchecked_t rttest_event;
78609
78610 struct test_thread_data {
78611 int opcode;
78612@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78613
78614 case RTTEST_LOCKCONT:
78615 td->mutexes[td->opdata] = 1;
78616- td->event = atomic_add_return(1, &rttest_event);
78617+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78618 return 0;
78619
78620 case RTTEST_RESET:
78621@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78622 return 0;
78623
78624 case RTTEST_RESETEVENT:
78625- atomic_set(&rttest_event, 0);
78626+ atomic_set_unchecked(&rttest_event, 0);
78627 return 0;
78628
78629 default:
78630@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78631 return ret;
78632
78633 td->mutexes[id] = 1;
78634- td->event = atomic_add_return(1, &rttest_event);
78635+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78636 rt_mutex_lock(&mutexes[id]);
78637- td->event = atomic_add_return(1, &rttest_event);
78638+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78639 td->mutexes[id] = 4;
78640 return 0;
78641
78642@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78643 return ret;
78644
78645 td->mutexes[id] = 1;
78646- td->event = atomic_add_return(1, &rttest_event);
78647+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78648 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
78649- td->event = atomic_add_return(1, &rttest_event);
78650+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78651 td->mutexes[id] = ret ? 0 : 4;
78652 return ret ? -EINTR : 0;
78653
78654@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78655 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
78656 return ret;
78657
78658- td->event = atomic_add_return(1, &rttest_event);
78659+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78660 rt_mutex_unlock(&mutexes[id]);
78661- td->event = atomic_add_return(1, &rttest_event);
78662+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78663 td->mutexes[id] = 0;
78664 return 0;
78665
78666@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78667 break;
78668
78669 td->mutexes[dat] = 2;
78670- td->event = atomic_add_return(1, &rttest_event);
78671+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78672 break;
78673
78674 default:
78675@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78676 return;
78677
78678 td->mutexes[dat] = 3;
78679- td->event = atomic_add_return(1, &rttest_event);
78680+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78681 break;
78682
78683 case RTTEST_LOCKNOWAIT:
78684@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78685 return;
78686
78687 td->mutexes[dat] = 1;
78688- td->event = atomic_add_return(1, &rttest_event);
78689+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78690 return;
78691
78692 default:
78693diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
78694index 64de5f8..7735e12 100644
78695--- a/kernel/sched/auto_group.c
78696+++ b/kernel/sched/auto_group.c
78697@@ -11,7 +11,7 @@
78698
78699 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
78700 static struct autogroup autogroup_default;
78701-static atomic_t autogroup_seq_nr;
78702+static atomic_unchecked_t autogroup_seq_nr;
78703
78704 void __init autogroup_init(struct task_struct *init_task)
78705 {
78706@@ -81,7 +81,7 @@ static inline struct autogroup *autogroup_create(void)
78707
78708 kref_init(&ag->kref);
78709 init_rwsem(&ag->lock);
78710- ag->id = atomic_inc_return(&autogroup_seq_nr);
78711+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
78712 ag->tg = tg;
78713 #ifdef CONFIG_RT_GROUP_SCHED
78714 /*
78715diff --git a/kernel/sched/core.c b/kernel/sched/core.c
78716index e8b3350..d83d44e 100644
78717--- a/kernel/sched/core.c
78718+++ b/kernel/sched/core.c
78719@@ -3440,7 +3440,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
78720 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78721 * positive (at least 1, or number of jiffies left till timeout) if completed.
78722 */
78723-long __sched
78724+long __sched __intentional_overflow(-1)
78725 wait_for_completion_interruptible_timeout(struct completion *x,
78726 unsigned long timeout)
78727 {
78728@@ -3457,7 +3457,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
78729 *
78730 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
78731 */
78732-int __sched wait_for_completion_killable(struct completion *x)
78733+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
78734 {
78735 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
78736 if (t == -ERESTARTSYS)
78737@@ -3478,7 +3478,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
78738 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78739 * positive (at least 1, or number of jiffies left till timeout) if completed.
78740 */
78741-long __sched
78742+long __sched __intentional_overflow(-1)
78743 wait_for_completion_killable_timeout(struct completion *x,
78744 unsigned long timeout)
78745 {
78746@@ -3704,6 +3704,8 @@ int can_nice(const struct task_struct *p, const int nice)
78747 /* convert nice value [19,-20] to rlimit style value [1,40] */
78748 int nice_rlim = 20 - nice;
78749
78750+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
78751+
78752 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
78753 capable(CAP_SYS_NICE));
78754 }
78755@@ -3737,7 +3739,8 @@ SYSCALL_DEFINE1(nice, int, increment)
78756 if (nice > 19)
78757 nice = 19;
78758
78759- if (increment < 0 && !can_nice(current, nice))
78760+ if (increment < 0 && (!can_nice(current, nice) ||
78761+ gr_handle_chroot_nice()))
78762 return -EPERM;
78763
78764 retval = security_task_setnice(current, nice);
78765@@ -3891,6 +3894,7 @@ recheck:
78766 unsigned long rlim_rtprio =
78767 task_rlimit(p, RLIMIT_RTPRIO);
78768
78769+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
78770 /* can't set/change the rt policy */
78771 if (policy != p->policy && !rlim_rtprio)
78772 return -EPERM;
78773@@ -4988,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
78774
78775 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
78776
78777-static struct ctl_table sd_ctl_dir[] = {
78778+static ctl_table_no_const sd_ctl_dir[] __read_only = {
78779 {
78780 .procname = "sched_domain",
78781 .mode = 0555,
78782@@ -5005,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
78783 {}
78784 };
78785
78786-static struct ctl_table *sd_alloc_ctl_entry(int n)
78787+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
78788 {
78789- struct ctl_table *entry =
78790+ ctl_table_no_const *entry =
78791 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
78792
78793 return entry;
78794 }
78795
78796-static void sd_free_ctl_entry(struct ctl_table **tablep)
78797+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
78798 {
78799- struct ctl_table *entry;
78800+ ctl_table_no_const *entry;
78801
78802 /*
78803 * In the intermediate directories, both the child directory and
78804@@ -5023,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
78805 * will always be set. In the lowest directory the names are
78806 * static strings and all have proc handlers.
78807 */
78808- for (entry = *tablep; entry->mode; entry++) {
78809- if (entry->child)
78810- sd_free_ctl_entry(&entry->child);
78811+ for (entry = tablep; entry->mode; entry++) {
78812+ if (entry->child) {
78813+ sd_free_ctl_entry(entry->child);
78814+ pax_open_kernel();
78815+ entry->child = NULL;
78816+ pax_close_kernel();
78817+ }
78818 if (entry->proc_handler == NULL)
78819 kfree(entry->procname);
78820 }
78821
78822- kfree(*tablep);
78823- *tablep = NULL;
78824+ kfree(tablep);
78825 }
78826
78827 static int min_load_idx = 0;
78828 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
78829
78830 static void
78831-set_table_entry(struct ctl_table *entry,
78832+set_table_entry(ctl_table_no_const *entry,
78833 const char *procname, void *data, int maxlen,
78834 umode_t mode, proc_handler *proc_handler,
78835 bool load_idx)
78836@@ -5058,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
78837 static struct ctl_table *
78838 sd_alloc_ctl_domain_table(struct sched_domain *sd)
78839 {
78840- struct ctl_table *table = sd_alloc_ctl_entry(13);
78841+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
78842
78843 if (table == NULL)
78844 return NULL;
78845@@ -5093,9 +5100,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
78846 return table;
78847 }
78848
78849-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
78850+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
78851 {
78852- struct ctl_table *entry, *table;
78853+ ctl_table_no_const *entry, *table;
78854 struct sched_domain *sd;
78855 int domain_num = 0, i;
78856 char buf[32];
78857@@ -5122,11 +5129,13 @@ static struct ctl_table_header *sd_sysctl_header;
78858 static void register_sched_domain_sysctl(void)
78859 {
78860 int i, cpu_num = num_possible_cpus();
78861- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
78862+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
78863 char buf[32];
78864
78865 WARN_ON(sd_ctl_dir[0].child);
78866+ pax_open_kernel();
78867 sd_ctl_dir[0].child = entry;
78868+ pax_close_kernel();
78869
78870 if (entry == NULL)
78871 return;
78872@@ -5149,8 +5158,12 @@ static void unregister_sched_domain_sysctl(void)
78873 if (sd_sysctl_header)
78874 unregister_sysctl_table(sd_sysctl_header);
78875 sd_sysctl_header = NULL;
78876- if (sd_ctl_dir[0].child)
78877- sd_free_ctl_entry(&sd_ctl_dir[0].child);
78878+ if (sd_ctl_dir[0].child) {
78879+ sd_free_ctl_entry(sd_ctl_dir[0].child);
78880+ pax_open_kernel();
78881+ sd_ctl_dir[0].child = NULL;
78882+ pax_close_kernel();
78883+ }
78884 }
78885 #else
78886 static void register_sched_domain_sysctl(void)
78887@@ -5249,7 +5262,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
78888 * happens before everything else. This has to be lower priority than
78889 * the notifier in the perf_event subsystem, though.
78890 */
78891-static struct notifier_block __cpuinitdata migration_notifier = {
78892+static struct notifier_block migration_notifier = {
78893 .notifier_call = migration_call,
78894 .priority = CPU_PRI_MIGRATION,
78895 };
78896diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
78897index c61a614..d7f3d7e 100644
78898--- a/kernel/sched/fair.c
78899+++ b/kernel/sched/fair.c
78900@@ -831,7 +831,7 @@ void task_numa_fault(int node, int pages, bool migrated)
78901
78902 static void reset_ptenuma_scan(struct task_struct *p)
78903 {
78904- ACCESS_ONCE(p->mm->numa_scan_seq)++;
78905+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
78906 p->mm->numa_scan_offset = 0;
78907 }
78908
78909@@ -5686,7 +5686,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
78910 * run_rebalance_domains is triggered when needed from the scheduler tick.
78911 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
78912 */
78913-static void run_rebalance_domains(struct softirq_action *h)
78914+static void run_rebalance_domains(void)
78915 {
78916 int this_cpu = smp_processor_id();
78917 struct rq *this_rq = cpu_rq(this_cpu);
78918diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
78919index ce39224..0e09343 100644
78920--- a/kernel/sched/sched.h
78921+++ b/kernel/sched/sched.h
78922@@ -1009,7 +1009,7 @@ struct sched_class {
78923 #ifdef CONFIG_FAIR_GROUP_SCHED
78924 void (*task_move_group) (struct task_struct *p, int on_rq);
78925 #endif
78926-};
78927+} __do_const;
78928
78929 #define sched_class_highest (&stop_sched_class)
78930 #define for_each_class(class) \
78931diff --git a/kernel/signal.c b/kernel/signal.c
78932index 113411b..17190e2 100644
78933--- a/kernel/signal.c
78934+++ b/kernel/signal.c
78935@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
78936
78937 int print_fatal_signals __read_mostly;
78938
78939-static void __user *sig_handler(struct task_struct *t, int sig)
78940+static __sighandler_t sig_handler(struct task_struct *t, int sig)
78941 {
78942 return t->sighand->action[sig - 1].sa.sa_handler;
78943 }
78944
78945-static int sig_handler_ignored(void __user *handler, int sig)
78946+static int sig_handler_ignored(__sighandler_t handler, int sig)
78947 {
78948 /* Is it explicitly or implicitly ignored? */
78949 return handler == SIG_IGN ||
78950@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
78951
78952 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
78953 {
78954- void __user *handler;
78955+ __sighandler_t handler;
78956
78957 handler = sig_handler(t, sig);
78958
78959@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
78960 atomic_inc(&user->sigpending);
78961 rcu_read_unlock();
78962
78963+ if (!override_rlimit)
78964+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
78965+
78966 if (override_rlimit ||
78967 atomic_read(&user->sigpending) <=
78968 task_rlimit(t, RLIMIT_SIGPENDING)) {
78969@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
78970
78971 int unhandled_signal(struct task_struct *tsk, int sig)
78972 {
78973- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
78974+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
78975 if (is_global_init(tsk))
78976 return 1;
78977 if (handler != SIG_IGN && handler != SIG_DFL)
78978@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
78979 }
78980 }
78981
78982+ /* allow glibc communication via tgkill to other threads in our
78983+ thread group */
78984+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
78985+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
78986+ && gr_handle_signal(t, sig))
78987+ return -EPERM;
78988+
78989 return security_task_kill(t, info, sig, 0);
78990 }
78991
78992@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78993 return send_signal(sig, info, p, 1);
78994 }
78995
78996-static int
78997+int
78998 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78999 {
79000 return send_signal(sig, info, t, 0);
79001@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79002 unsigned long int flags;
79003 int ret, blocked, ignored;
79004 struct k_sigaction *action;
79005+ int is_unhandled = 0;
79006
79007 spin_lock_irqsave(&t->sighand->siglock, flags);
79008 action = &t->sighand->action[sig-1];
79009@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79010 }
79011 if (action->sa.sa_handler == SIG_DFL)
79012 t->signal->flags &= ~SIGNAL_UNKILLABLE;
79013+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
79014+ is_unhandled = 1;
79015 ret = specific_send_sig_info(sig, info, t);
79016 spin_unlock_irqrestore(&t->sighand->siglock, flags);
79017
79018+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
79019+ normal operation */
79020+ if (is_unhandled) {
79021+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
79022+ gr_handle_crash(t, sig);
79023+ }
79024+
79025 return ret;
79026 }
79027
79028@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
79029 ret = check_kill_permission(sig, info, p);
79030 rcu_read_unlock();
79031
79032- if (!ret && sig)
79033+ if (!ret && sig) {
79034 ret = do_send_sig_info(sig, info, p, true);
79035+ if (!ret)
79036+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
79037+ }
79038
79039 return ret;
79040 }
79041@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
79042 int error = -ESRCH;
79043
79044 rcu_read_lock();
79045- p = find_task_by_vpid(pid);
79046+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79047+ /* allow glibc communication via tgkill to other threads in our
79048+ thread group */
79049+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
79050+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
79051+ p = find_task_by_vpid_unrestricted(pid);
79052+ else
79053+#endif
79054+ p = find_task_by_vpid(pid);
79055 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
79056 error = check_kill_permission(sig, info, p);
79057 /*
79058@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
79059 }
79060 seg = get_fs();
79061 set_fs(KERNEL_DS);
79062- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
79063- (stack_t __force __user *) &uoss,
79064+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
79065+ (stack_t __force_user *) &uoss,
79066 compat_user_stack_pointer());
79067 set_fs(seg);
79068 if (ret >= 0 && uoss_ptr) {
79069diff --git a/kernel/smp.c b/kernel/smp.c
79070index 4dba0f7..fe9f773 100644
79071--- a/kernel/smp.c
79072+++ b/kernel/smp.c
79073@@ -73,7 +73,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
79074 return NOTIFY_OK;
79075 }
79076
79077-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
79078+static struct notifier_block hotplug_cfd_notifier = {
79079 .notifier_call = hotplug_cfd,
79080 };
79081
79082diff --git a/kernel/smpboot.c b/kernel/smpboot.c
79083index 02fc5c9..e54c335 100644
79084--- a/kernel/smpboot.c
79085+++ b/kernel/smpboot.c
79086@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
79087 }
79088 smpboot_unpark_thread(plug_thread, cpu);
79089 }
79090- list_add(&plug_thread->list, &hotplug_threads);
79091+ pax_list_add(&plug_thread->list, &hotplug_threads);
79092 out:
79093 mutex_unlock(&smpboot_threads_lock);
79094 return ret;
79095@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
79096 {
79097 get_online_cpus();
79098 mutex_lock(&smpboot_threads_lock);
79099- list_del(&plug_thread->list);
79100+ pax_list_del(&plug_thread->list);
79101 smpboot_destroy_threads(plug_thread);
79102 mutex_unlock(&smpboot_threads_lock);
79103 put_online_cpus();
79104diff --git a/kernel/softirq.c b/kernel/softirq.c
79105index 3d6833f..da6d93d 100644
79106--- a/kernel/softirq.c
79107+++ b/kernel/softirq.c
79108@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
79109 EXPORT_SYMBOL(irq_stat);
79110 #endif
79111
79112-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
79113+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
79114
79115 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
79116
79117-char *softirq_to_name[NR_SOFTIRQS] = {
79118+const char * const softirq_to_name[NR_SOFTIRQS] = {
79119 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
79120 "TASKLET", "SCHED", "HRTIMER", "RCU"
79121 };
79122@@ -250,7 +250,7 @@ restart:
79123 kstat_incr_softirqs_this_cpu(vec_nr);
79124
79125 trace_softirq_entry(vec_nr);
79126- h->action(h);
79127+ h->action();
79128 trace_softirq_exit(vec_nr);
79129 if (unlikely(prev_count != preempt_count())) {
79130 printk(KERN_ERR "huh, entered softirq %u %s %p"
79131@@ -405,7 +405,7 @@ void __raise_softirq_irqoff(unsigned int nr)
79132 or_softirq_pending(1UL << nr);
79133 }
79134
79135-void open_softirq(int nr, void (*action)(struct softirq_action *))
79136+void __init open_softirq(int nr, void (*action)(void))
79137 {
79138 softirq_vec[nr].action = action;
79139 }
79140@@ -461,7 +461,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
79141
79142 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
79143
79144-static void tasklet_action(struct softirq_action *a)
79145+static void tasklet_action(void)
79146 {
79147 struct tasklet_struct *list;
79148
79149@@ -496,7 +496,7 @@ static void tasklet_action(struct softirq_action *a)
79150 }
79151 }
79152
79153-static void tasklet_hi_action(struct softirq_action *a)
79154+static void tasklet_hi_action(void)
79155 {
79156 struct tasklet_struct *list;
79157
79158@@ -730,7 +730,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
79159 return NOTIFY_OK;
79160 }
79161
79162-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
79163+static struct notifier_block remote_softirq_cpu_notifier = {
79164 .notifier_call = remote_softirq_cpu_notify,
79165 };
79166
79167@@ -847,11 +847,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
79168 return NOTIFY_OK;
79169 }
79170
79171-static struct notifier_block __cpuinitdata cpu_nfb = {
79172+static struct notifier_block cpu_nfb = {
79173 .notifier_call = cpu_callback
79174 };
79175
79176-static struct smp_hotplug_thread softirq_threads = {
79177+static struct smp_hotplug_thread softirq_threads __read_only = {
79178 .store = &ksoftirqd,
79179 .thread_should_run = ksoftirqd_should_run,
79180 .thread_fn = run_ksoftirqd,
79181diff --git a/kernel/srcu.c b/kernel/srcu.c
79182index 01d5ccb..cdcbee6 100644
79183--- a/kernel/srcu.c
79184+++ b/kernel/srcu.c
79185@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
79186
79187 idx = ACCESS_ONCE(sp->completed) & 0x1;
79188 preempt_disable();
79189- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79190+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79191 smp_mb(); /* B */ /* Avoid leaking the critical section. */
79192- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79193+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79194 preempt_enable();
79195 return idx;
79196 }
79197diff --git a/kernel/sys.c b/kernel/sys.c
79198index 2bbd9a7..0875671 100644
79199--- a/kernel/sys.c
79200+++ b/kernel/sys.c
79201@@ -163,6 +163,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
79202 error = -EACCES;
79203 goto out;
79204 }
79205+
79206+ if (gr_handle_chroot_setpriority(p, niceval)) {
79207+ error = -EACCES;
79208+ goto out;
79209+ }
79210+
79211 no_nice = security_task_setnice(p, niceval);
79212 if (no_nice) {
79213 error = no_nice;
79214@@ -626,6 +632,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
79215 goto error;
79216 }
79217
79218+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
79219+ goto error;
79220+
79221 if (rgid != (gid_t) -1 ||
79222 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
79223 new->sgid = new->egid;
79224@@ -661,6 +670,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
79225 old = current_cred();
79226
79227 retval = -EPERM;
79228+
79229+ if (gr_check_group_change(kgid, kgid, kgid))
79230+ goto error;
79231+
79232 if (nsown_capable(CAP_SETGID))
79233 new->gid = new->egid = new->sgid = new->fsgid = kgid;
79234 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
79235@@ -678,7 +691,7 @@ error:
79236 /*
79237 * change the user struct in a credentials set to match the new UID
79238 */
79239-static int set_user(struct cred *new)
79240+int set_user(struct cred *new)
79241 {
79242 struct user_struct *new_user;
79243
79244@@ -758,6 +771,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
79245 goto error;
79246 }
79247
79248+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
79249+ goto error;
79250+
79251 if (!uid_eq(new->uid, old->uid)) {
79252 retval = set_user(new);
79253 if (retval < 0)
79254@@ -808,6 +824,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
79255 old = current_cred();
79256
79257 retval = -EPERM;
79258+
79259+ if (gr_check_crash_uid(kuid))
79260+ goto error;
79261+ if (gr_check_user_change(kuid, kuid, kuid))
79262+ goto error;
79263+
79264 if (nsown_capable(CAP_SETUID)) {
79265 new->suid = new->uid = kuid;
79266 if (!uid_eq(kuid, old->uid)) {
79267@@ -877,6 +899,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
79268 goto error;
79269 }
79270
79271+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
79272+ goto error;
79273+
79274 if (ruid != (uid_t) -1) {
79275 new->uid = kruid;
79276 if (!uid_eq(kruid, old->uid)) {
79277@@ -959,6 +984,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
79278 goto error;
79279 }
79280
79281+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
79282+ goto error;
79283+
79284 if (rgid != (gid_t) -1)
79285 new->gid = krgid;
79286 if (egid != (gid_t) -1)
79287@@ -1020,12 +1048,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
79288 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
79289 nsown_capable(CAP_SETUID)) {
79290 if (!uid_eq(kuid, old->fsuid)) {
79291+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
79292+ goto error;
79293+
79294 new->fsuid = kuid;
79295 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
79296 goto change_okay;
79297 }
79298 }
79299
79300+error:
79301 abort_creds(new);
79302 return old_fsuid;
79303
79304@@ -1058,12 +1090,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
79305 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
79306 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
79307 nsown_capable(CAP_SETGID)) {
79308+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
79309+ goto error;
79310+
79311 if (!gid_eq(kgid, old->fsgid)) {
79312 new->fsgid = kgid;
79313 goto change_okay;
79314 }
79315 }
79316
79317+error:
79318 abort_creds(new);
79319 return old_fsgid;
79320
79321@@ -1432,19 +1468,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
79322 return -EFAULT;
79323
79324 down_read(&uts_sem);
79325- error = __copy_to_user(&name->sysname, &utsname()->sysname,
79326+ error = __copy_to_user(name->sysname, &utsname()->sysname,
79327 __OLD_UTS_LEN);
79328 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
79329- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
79330+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
79331 __OLD_UTS_LEN);
79332 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
79333- error |= __copy_to_user(&name->release, &utsname()->release,
79334+ error |= __copy_to_user(name->release, &utsname()->release,
79335 __OLD_UTS_LEN);
79336 error |= __put_user(0, name->release + __OLD_UTS_LEN);
79337- error |= __copy_to_user(&name->version, &utsname()->version,
79338+ error |= __copy_to_user(name->version, &utsname()->version,
79339 __OLD_UTS_LEN);
79340 error |= __put_user(0, name->version + __OLD_UTS_LEN);
79341- error |= __copy_to_user(&name->machine, &utsname()->machine,
79342+ error |= __copy_to_user(name->machine, &utsname()->machine,
79343 __OLD_UTS_LEN);
79344 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
79345 up_read(&uts_sem);
79346@@ -1646,6 +1682,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
79347 */
79348 new_rlim->rlim_cur = 1;
79349 }
79350+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
79351+ is changed to a lower value. Since tasks can be created by the same
79352+ user in between this limit change and an execve by this task, force
79353+ a recheck only for this task by setting PF_NPROC_EXCEEDED
79354+ */
79355+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
79356+ tsk->flags |= PF_NPROC_EXCEEDED;
79357 }
79358 if (!retval) {
79359 if (old_rlim)
79360diff --git a/kernel/sysctl.c b/kernel/sysctl.c
79361index 9edcf45..713c960 100644
79362--- a/kernel/sysctl.c
79363+++ b/kernel/sysctl.c
79364@@ -93,7 +93,6 @@
79365
79366
79367 #if defined(CONFIG_SYSCTL)
79368-
79369 /* External variables not in a header file. */
79370 extern int sysctl_overcommit_memory;
79371 extern int sysctl_overcommit_ratio;
79372@@ -119,18 +118,18 @@ extern int blk_iopoll_enabled;
79373
79374 /* Constants used for minimum and maximum */
79375 #ifdef CONFIG_LOCKUP_DETECTOR
79376-static int sixty = 60;
79377-static int neg_one = -1;
79378+static int sixty __read_only = 60;
79379 #endif
79380
79381-static int zero;
79382-static int __maybe_unused one = 1;
79383-static int __maybe_unused two = 2;
79384-static int __maybe_unused three = 3;
79385-static unsigned long one_ul = 1;
79386-static int one_hundred = 100;
79387+static int neg_one __read_only = -1;
79388+static int zero __read_only = 0;
79389+static int __maybe_unused one __read_only = 1;
79390+static int __maybe_unused two __read_only = 2;
79391+static int __maybe_unused three __read_only = 3;
79392+static unsigned long one_ul __read_only = 1;
79393+static int one_hundred __read_only = 100;
79394 #ifdef CONFIG_PRINTK
79395-static int ten_thousand = 10000;
79396+static int ten_thousand __read_only = 10000;
79397 #endif
79398
79399 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
79400@@ -177,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
79401 void __user *buffer, size_t *lenp, loff_t *ppos);
79402 #endif
79403
79404-#ifdef CONFIG_PRINTK
79405 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79406 void __user *buffer, size_t *lenp, loff_t *ppos);
79407-#endif
79408
79409 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
79410 void __user *buffer, size_t *lenp, loff_t *ppos);
79411@@ -211,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
79412
79413 #endif
79414
79415+extern struct ctl_table grsecurity_table[];
79416+
79417 static struct ctl_table kern_table[];
79418 static struct ctl_table vm_table[];
79419 static struct ctl_table fs_table[];
79420@@ -225,6 +224,20 @@ extern struct ctl_table epoll_table[];
79421 int sysctl_legacy_va_layout;
79422 #endif
79423
79424+#ifdef CONFIG_PAX_SOFTMODE
79425+static ctl_table pax_table[] = {
79426+ {
79427+ .procname = "softmode",
79428+ .data = &pax_softmode,
79429+ .maxlen = sizeof(unsigned int),
79430+ .mode = 0600,
79431+ .proc_handler = &proc_dointvec,
79432+ },
79433+
79434+ { }
79435+};
79436+#endif
79437+
79438 /* The default sysctl tables: */
79439
79440 static struct ctl_table sysctl_base_table[] = {
79441@@ -273,6 +286,22 @@ static int max_extfrag_threshold = 1000;
79442 #endif
79443
79444 static struct ctl_table kern_table[] = {
79445+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
79446+ {
79447+ .procname = "grsecurity",
79448+ .mode = 0500,
79449+ .child = grsecurity_table,
79450+ },
79451+#endif
79452+
79453+#ifdef CONFIG_PAX_SOFTMODE
79454+ {
79455+ .procname = "pax",
79456+ .mode = 0500,
79457+ .child = pax_table,
79458+ },
79459+#endif
79460+
79461 {
79462 .procname = "sched_child_runs_first",
79463 .data = &sysctl_sched_child_runs_first,
79464@@ -607,7 +636,7 @@ static struct ctl_table kern_table[] = {
79465 .data = &modprobe_path,
79466 .maxlen = KMOD_PATH_LEN,
79467 .mode = 0644,
79468- .proc_handler = proc_dostring,
79469+ .proc_handler = proc_dostring_modpriv,
79470 },
79471 {
79472 .procname = "modules_disabled",
79473@@ -774,16 +803,20 @@ static struct ctl_table kern_table[] = {
79474 .extra1 = &zero,
79475 .extra2 = &one,
79476 },
79477+#endif
79478 {
79479 .procname = "kptr_restrict",
79480 .data = &kptr_restrict,
79481 .maxlen = sizeof(int),
79482 .mode = 0644,
79483 .proc_handler = proc_dointvec_minmax_sysadmin,
79484+#ifdef CONFIG_GRKERNSEC_HIDESYM
79485+ .extra1 = &two,
79486+#else
79487 .extra1 = &zero,
79488+#endif
79489 .extra2 = &two,
79490 },
79491-#endif
79492 {
79493 .procname = "ngroups_max",
79494 .data = &ngroups_max,
79495@@ -1025,10 +1058,17 @@ static struct ctl_table kern_table[] = {
79496 */
79497 {
79498 .procname = "perf_event_paranoid",
79499- .data = &sysctl_perf_event_paranoid,
79500- .maxlen = sizeof(sysctl_perf_event_paranoid),
79501+ .data = &sysctl_perf_event_legitimately_concerned,
79502+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
79503 .mode = 0644,
79504- .proc_handler = proc_dointvec,
79505+ /* go ahead, be a hero */
79506+ .proc_handler = proc_dointvec_minmax_sysadmin,
79507+ .extra1 = &neg_one,
79508+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
79509+ .extra2 = &three,
79510+#else
79511+ .extra2 = &two,
79512+#endif
79513 },
79514 {
79515 .procname = "perf_event_mlock_kb",
79516@@ -1282,6 +1322,13 @@ static struct ctl_table vm_table[] = {
79517 .proc_handler = proc_dointvec_minmax,
79518 .extra1 = &zero,
79519 },
79520+ {
79521+ .procname = "heap_stack_gap",
79522+ .data = &sysctl_heap_stack_gap,
79523+ .maxlen = sizeof(sysctl_heap_stack_gap),
79524+ .mode = 0644,
79525+ .proc_handler = proc_doulongvec_minmax,
79526+ },
79527 #else
79528 {
79529 .procname = "nr_trim_pages",
79530@@ -1746,6 +1793,16 @@ int proc_dostring(struct ctl_table *table, int write,
79531 buffer, lenp, ppos);
79532 }
79533
79534+int proc_dostring_modpriv(struct ctl_table *table, int write,
79535+ void __user *buffer, size_t *lenp, loff_t *ppos)
79536+{
79537+ if (write && !capable(CAP_SYS_MODULE))
79538+ return -EPERM;
79539+
79540+ return _proc_do_string(table->data, table->maxlen, write,
79541+ buffer, lenp, ppos);
79542+}
79543+
79544 static size_t proc_skip_spaces(char **buf)
79545 {
79546 size_t ret;
79547@@ -1851,6 +1908,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
79548 len = strlen(tmp);
79549 if (len > *size)
79550 len = *size;
79551+ if (len > sizeof(tmp))
79552+ len = sizeof(tmp);
79553 if (copy_to_user(*buf, tmp, len))
79554 return -EFAULT;
79555 *size -= len;
79556@@ -2015,7 +2074,7 @@ int proc_dointvec(struct ctl_table *table, int write,
79557 static int proc_taint(struct ctl_table *table, int write,
79558 void __user *buffer, size_t *lenp, loff_t *ppos)
79559 {
79560- struct ctl_table t;
79561+ ctl_table_no_const t;
79562 unsigned long tmptaint = get_taint();
79563 int err;
79564
79565@@ -2043,7 +2102,6 @@ static int proc_taint(struct ctl_table *table, int write,
79566 return err;
79567 }
79568
79569-#ifdef CONFIG_PRINTK
79570 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79571 void __user *buffer, size_t *lenp, loff_t *ppos)
79572 {
79573@@ -2052,7 +2110,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79574
79575 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
79576 }
79577-#endif
79578
79579 struct do_proc_dointvec_minmax_conv_param {
79580 int *min;
79581@@ -2199,8 +2256,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
79582 *i = val;
79583 } else {
79584 val = convdiv * (*i) / convmul;
79585- if (!first)
79586+ if (!first) {
79587 err = proc_put_char(&buffer, &left, '\t');
79588+ if (err)
79589+ break;
79590+ }
79591 err = proc_put_long(&buffer, &left, val, false);
79592 if (err)
79593 break;
79594@@ -2592,6 +2652,12 @@ int proc_dostring(struct ctl_table *table, int write,
79595 return -ENOSYS;
79596 }
79597
79598+int proc_dostring_modpriv(struct ctl_table *table, int write,
79599+ void __user *buffer, size_t *lenp, loff_t *ppos)
79600+{
79601+ return -ENOSYS;
79602+}
79603+
79604 int proc_dointvec(struct ctl_table *table, int write,
79605 void __user *buffer, size_t *lenp, loff_t *ppos)
79606 {
79607@@ -2648,5 +2714,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
79608 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
79609 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
79610 EXPORT_SYMBOL(proc_dostring);
79611+EXPORT_SYMBOL(proc_dostring_modpriv);
79612 EXPORT_SYMBOL(proc_doulongvec_minmax);
79613 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
79614diff --git a/kernel/taskstats.c b/kernel/taskstats.c
79615index 145bb4d..b2aa969 100644
79616--- a/kernel/taskstats.c
79617+++ b/kernel/taskstats.c
79618@@ -28,9 +28,12 @@
79619 #include <linux/fs.h>
79620 #include <linux/file.h>
79621 #include <linux/pid_namespace.h>
79622+#include <linux/grsecurity.h>
79623 #include <net/genetlink.h>
79624 #include <linux/atomic.h>
79625
79626+extern int gr_is_taskstats_denied(int pid);
79627+
79628 /*
79629 * Maximum length of a cpumask that can be specified in
79630 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
79631@@ -570,6 +573,9 @@ err:
79632
79633 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
79634 {
79635+ if (gr_is_taskstats_denied(current->pid))
79636+ return -EACCES;
79637+
79638 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
79639 return cmd_attr_register_cpumask(info);
79640 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
79641diff --git a/kernel/time.c b/kernel/time.c
79642index d3617db..c98bbe9 100644
79643--- a/kernel/time.c
79644+++ b/kernel/time.c
79645@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
79646 return error;
79647
79648 if (tz) {
79649+ /* we log in do_settimeofday called below, so don't log twice
79650+ */
79651+ if (!tv)
79652+ gr_log_timechange();
79653+
79654 sys_tz = *tz;
79655 update_vsyscall_tz();
79656 if (firsttime) {
79657@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
79658 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
79659 * value to a scaled second value.
79660 */
79661-unsigned long
79662+unsigned long __intentional_overflow(-1)
79663 timespec_to_jiffies(const struct timespec *value)
79664 {
79665 unsigned long sec = value->tv_sec;
79666diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
79667index f11d83b..d016d91 100644
79668--- a/kernel/time/alarmtimer.c
79669+++ b/kernel/time/alarmtimer.c
79670@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
79671 struct platform_device *pdev;
79672 int error = 0;
79673 int i;
79674- struct k_clock alarm_clock = {
79675+ static struct k_clock alarm_clock = {
79676 .clock_getres = alarm_clock_getres,
79677 .clock_get = alarm_clock_get,
79678 .timer_create = alarm_timer_create,
79679diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
79680index 20d6fba..09e103a 100644
79681--- a/kernel/time/tick-broadcast.c
79682+++ b/kernel/time/tick-broadcast.c
79683@@ -147,7 +147,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
79684 * then clear the broadcast bit.
79685 */
79686 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
79687- int cpu = smp_processor_id();
79688+ cpu = smp_processor_id();
79689 cpumask_clear_cpu(cpu, tick_broadcast_mask);
79690 tick_broadcast_clear_oneshot(cpu);
79691 } else {
79692diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
79693index baeeb5c..c22704a 100644
79694--- a/kernel/time/timekeeping.c
79695+++ b/kernel/time/timekeeping.c
79696@@ -15,6 +15,7 @@
79697 #include <linux/init.h>
79698 #include <linux/mm.h>
79699 #include <linux/sched.h>
79700+#include <linux/grsecurity.h>
79701 #include <linux/syscore_ops.h>
79702 #include <linux/clocksource.h>
79703 #include <linux/jiffies.h>
79704@@ -495,6 +496,8 @@ int do_settimeofday(const struct timespec *tv)
79705 if (!timespec_valid_strict(tv))
79706 return -EINVAL;
79707
79708+ gr_log_timechange();
79709+
79710 raw_spin_lock_irqsave(&timekeeper_lock, flags);
79711 write_seqcount_begin(&timekeeper_seq);
79712
79713diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
79714index 3bdf283..cc68d83 100644
79715--- a/kernel/time/timer_list.c
79716+++ b/kernel/time/timer_list.c
79717@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
79718
79719 static void print_name_offset(struct seq_file *m, void *sym)
79720 {
79721+#ifdef CONFIG_GRKERNSEC_HIDESYM
79722+ SEQ_printf(m, "<%p>", NULL);
79723+#else
79724 char symname[KSYM_NAME_LEN];
79725
79726 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
79727 SEQ_printf(m, "<%pK>", sym);
79728 else
79729 SEQ_printf(m, "%s", symname);
79730+#endif
79731 }
79732
79733 static void
79734@@ -119,7 +123,11 @@ next_one:
79735 static void
79736 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
79737 {
79738+#ifdef CONFIG_GRKERNSEC_HIDESYM
79739+ SEQ_printf(m, " .base: %p\n", NULL);
79740+#else
79741 SEQ_printf(m, " .base: %pK\n", base);
79742+#endif
79743 SEQ_printf(m, " .index: %d\n",
79744 base->index);
79745 SEQ_printf(m, " .resolution: %Lu nsecs\n",
79746@@ -355,7 +363,11 @@ static int __init init_timer_list_procfs(void)
79747 {
79748 struct proc_dir_entry *pe;
79749
79750+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79751+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
79752+#else
79753 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
79754+#endif
79755 if (!pe)
79756 return -ENOMEM;
79757 return 0;
79758diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
79759index 0b537f2..40d6c20 100644
79760--- a/kernel/time/timer_stats.c
79761+++ b/kernel/time/timer_stats.c
79762@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
79763 static unsigned long nr_entries;
79764 static struct entry entries[MAX_ENTRIES];
79765
79766-static atomic_t overflow_count;
79767+static atomic_unchecked_t overflow_count;
79768
79769 /*
79770 * The entries are in a hash-table, for fast lookup:
79771@@ -140,7 +140,7 @@ static void reset_entries(void)
79772 nr_entries = 0;
79773 memset(entries, 0, sizeof(entries));
79774 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
79775- atomic_set(&overflow_count, 0);
79776+ atomic_set_unchecked(&overflow_count, 0);
79777 }
79778
79779 static struct entry *alloc_entry(void)
79780@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79781 if (likely(entry))
79782 entry->count++;
79783 else
79784- atomic_inc(&overflow_count);
79785+ atomic_inc_unchecked(&overflow_count);
79786
79787 out_unlock:
79788 raw_spin_unlock_irqrestore(lock, flags);
79789@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79790
79791 static void print_name_offset(struct seq_file *m, unsigned long addr)
79792 {
79793+#ifdef CONFIG_GRKERNSEC_HIDESYM
79794+ seq_printf(m, "<%p>", NULL);
79795+#else
79796 char symname[KSYM_NAME_LEN];
79797
79798 if (lookup_symbol_name(addr, symname) < 0)
79799- seq_printf(m, "<%p>", (void *)addr);
79800+ seq_printf(m, "<%pK>", (void *)addr);
79801 else
79802 seq_printf(m, "%s", symname);
79803+#endif
79804 }
79805
79806 static int tstats_show(struct seq_file *m, void *v)
79807@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
79808
79809 seq_puts(m, "Timer Stats Version: v0.2\n");
79810 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
79811- if (atomic_read(&overflow_count))
79812+ if (atomic_read_unchecked(&overflow_count))
79813 seq_printf(m, "Overflow: %d entries\n",
79814- atomic_read(&overflow_count));
79815+ atomic_read_unchecked(&overflow_count));
79816
79817 for (i = 0; i < nr_entries; i++) {
79818 entry = entries + i;
79819@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
79820 {
79821 struct proc_dir_entry *pe;
79822
79823+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79824+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
79825+#else
79826 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
79827+#endif
79828 if (!pe)
79829 return -ENOMEM;
79830 return 0;
79831diff --git a/kernel/timer.c b/kernel/timer.c
79832index 15ffdb3..62d885c 100644
79833--- a/kernel/timer.c
79834+++ b/kernel/timer.c
79835@@ -1364,7 +1364,7 @@ void update_process_times(int user_tick)
79836 /*
79837 * This function runs timers and the timer-tq in bottom half context.
79838 */
79839-static void run_timer_softirq(struct softirq_action *h)
79840+static void run_timer_softirq(void)
79841 {
79842 struct tvec_base *base = __this_cpu_read(tvec_bases);
79843
79844@@ -1427,7 +1427,7 @@ static void process_timeout(unsigned long __data)
79845 *
79846 * In all cases the return value is guaranteed to be non-negative.
79847 */
79848-signed long __sched schedule_timeout(signed long timeout)
79849+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
79850 {
79851 struct timer_list timer;
79852 unsigned long expire;
79853@@ -1633,7 +1633,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
79854 return NOTIFY_OK;
79855 }
79856
79857-static struct notifier_block __cpuinitdata timers_nb = {
79858+static struct notifier_block timers_nb = {
79859 .notifier_call = timer_cpu_notify,
79860 };
79861
79862diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
79863index b8b8560..75b1a09 100644
79864--- a/kernel/trace/blktrace.c
79865+++ b/kernel/trace/blktrace.c
79866@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
79867 struct blk_trace *bt = filp->private_data;
79868 char buf[16];
79869
79870- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
79871+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
79872
79873 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
79874 }
79875@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
79876 return 1;
79877
79878 bt = buf->chan->private_data;
79879- atomic_inc(&bt->dropped);
79880+ atomic_inc_unchecked(&bt->dropped);
79881 return 0;
79882 }
79883
79884@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
79885
79886 bt->dir = dir;
79887 bt->dev = dev;
79888- atomic_set(&bt->dropped, 0);
79889+ atomic_set_unchecked(&bt->dropped, 0);
79890
79891 ret = -EIO;
79892 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
79893diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
79894index 6c508ff..ee55a13 100644
79895--- a/kernel/trace/ftrace.c
79896+++ b/kernel/trace/ftrace.c
79897@@ -1915,12 +1915,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
79898 if (unlikely(ftrace_disabled))
79899 return 0;
79900
79901+ ret = ftrace_arch_code_modify_prepare();
79902+ FTRACE_WARN_ON(ret);
79903+ if (ret)
79904+ return 0;
79905+
79906 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
79907+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
79908 if (ret) {
79909 ftrace_bug(ret, ip);
79910- return 0;
79911 }
79912- return 1;
79913+ return ret ? 0 : 1;
79914 }
79915
79916 /*
79917@@ -3931,8 +3936,10 @@ static int ftrace_process_locs(struct module *mod,
79918 if (!count)
79919 return 0;
79920
79921+ pax_open_kernel();
79922 sort(start, count, sizeof(*start),
79923 ftrace_cmp_ips, ftrace_swap_ips);
79924+ pax_close_kernel();
79925
79926 start_pg = ftrace_allocate_pages(count);
79927 if (!start_pg)
79928@@ -4655,8 +4662,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
79929 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
79930
79931 static int ftrace_graph_active;
79932-static struct notifier_block ftrace_suspend_notifier;
79933-
79934 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
79935 {
79936 return 0;
79937@@ -4800,6 +4805,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
79938 return NOTIFY_DONE;
79939 }
79940
79941+static struct notifier_block ftrace_suspend_notifier = {
79942+ .notifier_call = ftrace_suspend_notifier_call
79943+};
79944+
79945 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79946 trace_func_graph_ent_t entryfunc)
79947 {
79948@@ -4813,7 +4822,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79949 goto out;
79950 }
79951
79952- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
79953 register_pm_notifier(&ftrace_suspend_notifier);
79954
79955 ftrace_graph_active++;
79956diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
79957index e444ff8..438b8f4 100644
79958--- a/kernel/trace/ring_buffer.c
79959+++ b/kernel/trace/ring_buffer.c
79960@@ -352,9 +352,9 @@ struct buffer_data_page {
79961 */
79962 struct buffer_page {
79963 struct list_head list; /* list of buffer pages */
79964- local_t write; /* index for next write */
79965+ local_unchecked_t write; /* index for next write */
79966 unsigned read; /* index for next read */
79967- local_t entries; /* entries on this page */
79968+ local_unchecked_t entries; /* entries on this page */
79969 unsigned long real_end; /* real end of data */
79970 struct buffer_data_page *page; /* Actual data page */
79971 };
79972@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
79973 unsigned long last_overrun;
79974 local_t entries_bytes;
79975 local_t entries;
79976- local_t overrun;
79977- local_t commit_overrun;
79978+ local_unchecked_t overrun;
79979+ local_unchecked_t commit_overrun;
79980 local_t dropped_events;
79981 local_t committing;
79982 local_t commits;
79983@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79984 *
79985 * We add a counter to the write field to denote this.
79986 */
79987- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
79988- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
79989+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
79990+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
79991
79992 /*
79993 * Just make sure we have seen our old_write and synchronize
79994@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79995 * cmpxchg to only update if an interrupt did not already
79996 * do it for us. If the cmpxchg fails, we don't care.
79997 */
79998- (void)local_cmpxchg(&next_page->write, old_write, val);
79999- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
80000+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
80001+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
80002
80003 /*
80004 * No need to worry about races with clearing out the commit.
80005@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
80006
80007 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
80008 {
80009- return local_read(&bpage->entries) & RB_WRITE_MASK;
80010+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
80011 }
80012
80013 static inline unsigned long rb_page_write(struct buffer_page *bpage)
80014 {
80015- return local_read(&bpage->write) & RB_WRITE_MASK;
80016+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
80017 }
80018
80019 static int
80020@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
80021 * bytes consumed in ring buffer from here.
80022 * Increment overrun to account for the lost events.
80023 */
80024- local_add(page_entries, &cpu_buffer->overrun);
80025+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
80026 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
80027 }
80028
80029@@ -2063,7 +2063,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
80030 * it is our responsibility to update
80031 * the counters.
80032 */
80033- local_add(entries, &cpu_buffer->overrun);
80034+ local_add_unchecked(entries, &cpu_buffer->overrun);
80035 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
80036
80037 /*
80038@@ -2213,7 +2213,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80039 if (tail == BUF_PAGE_SIZE)
80040 tail_page->real_end = 0;
80041
80042- local_sub(length, &tail_page->write);
80043+ local_sub_unchecked(length, &tail_page->write);
80044 return;
80045 }
80046
80047@@ -2248,7 +2248,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80048 rb_event_set_padding(event);
80049
80050 /* Set the write back to the previous setting */
80051- local_sub(length, &tail_page->write);
80052+ local_sub_unchecked(length, &tail_page->write);
80053 return;
80054 }
80055
80056@@ -2260,7 +2260,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80057
80058 /* Set write to end of buffer */
80059 length = (tail + length) - BUF_PAGE_SIZE;
80060- local_sub(length, &tail_page->write);
80061+ local_sub_unchecked(length, &tail_page->write);
80062 }
80063
80064 /*
80065@@ -2286,7 +2286,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
80066 * about it.
80067 */
80068 if (unlikely(next_page == commit_page)) {
80069- local_inc(&cpu_buffer->commit_overrun);
80070+ local_inc_unchecked(&cpu_buffer->commit_overrun);
80071 goto out_reset;
80072 }
80073
80074@@ -2342,7 +2342,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
80075 cpu_buffer->tail_page) &&
80076 (cpu_buffer->commit_page ==
80077 cpu_buffer->reader_page))) {
80078- local_inc(&cpu_buffer->commit_overrun);
80079+ local_inc_unchecked(&cpu_buffer->commit_overrun);
80080 goto out_reset;
80081 }
80082 }
80083@@ -2390,7 +2390,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
80084 length += RB_LEN_TIME_EXTEND;
80085
80086 tail_page = cpu_buffer->tail_page;
80087- write = local_add_return(length, &tail_page->write);
80088+ write = local_add_return_unchecked(length, &tail_page->write);
80089
80090 /* set write to only the index of the write */
80091 write &= RB_WRITE_MASK;
80092@@ -2407,7 +2407,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
80093 kmemcheck_annotate_bitfield(event, bitfield);
80094 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
80095
80096- local_inc(&tail_page->entries);
80097+ local_inc_unchecked(&tail_page->entries);
80098
80099 /*
80100 * If this is the first commit on the page, then update
80101@@ -2440,7 +2440,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
80102
80103 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
80104 unsigned long write_mask =
80105- local_read(&bpage->write) & ~RB_WRITE_MASK;
80106+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
80107 unsigned long event_length = rb_event_length(event);
80108 /*
80109 * This is on the tail page. It is possible that
80110@@ -2450,7 +2450,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
80111 */
80112 old_index += write_mask;
80113 new_index += write_mask;
80114- index = local_cmpxchg(&bpage->write, old_index, new_index);
80115+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
80116 if (index == old_index) {
80117 /* update counters */
80118 local_sub(event_length, &cpu_buffer->entries_bytes);
80119@@ -2842,7 +2842,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
80120
80121 /* Do the likely case first */
80122 if (likely(bpage->page == (void *)addr)) {
80123- local_dec(&bpage->entries);
80124+ local_dec_unchecked(&bpage->entries);
80125 return;
80126 }
80127
80128@@ -2854,7 +2854,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
80129 start = bpage;
80130 do {
80131 if (bpage->page == (void *)addr) {
80132- local_dec(&bpage->entries);
80133+ local_dec_unchecked(&bpage->entries);
80134 return;
80135 }
80136 rb_inc_page(cpu_buffer, &bpage);
80137@@ -3138,7 +3138,7 @@ static inline unsigned long
80138 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
80139 {
80140 return local_read(&cpu_buffer->entries) -
80141- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
80142+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
80143 }
80144
80145 /**
80146@@ -3227,7 +3227,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
80147 return 0;
80148
80149 cpu_buffer = buffer->buffers[cpu];
80150- ret = local_read(&cpu_buffer->overrun);
80151+ ret = local_read_unchecked(&cpu_buffer->overrun);
80152
80153 return ret;
80154 }
80155@@ -3250,7 +3250,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
80156 return 0;
80157
80158 cpu_buffer = buffer->buffers[cpu];
80159- ret = local_read(&cpu_buffer->commit_overrun);
80160+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
80161
80162 return ret;
80163 }
80164@@ -3335,7 +3335,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
80165 /* if you care about this being correct, lock the buffer */
80166 for_each_buffer_cpu(buffer, cpu) {
80167 cpu_buffer = buffer->buffers[cpu];
80168- overruns += local_read(&cpu_buffer->overrun);
80169+ overruns += local_read_unchecked(&cpu_buffer->overrun);
80170 }
80171
80172 return overruns;
80173@@ -3511,8 +3511,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80174 /*
80175 * Reset the reader page to size zero.
80176 */
80177- local_set(&cpu_buffer->reader_page->write, 0);
80178- local_set(&cpu_buffer->reader_page->entries, 0);
80179+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80180+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80181 local_set(&cpu_buffer->reader_page->page->commit, 0);
80182 cpu_buffer->reader_page->real_end = 0;
80183
80184@@ -3546,7 +3546,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80185 * want to compare with the last_overrun.
80186 */
80187 smp_mb();
80188- overwrite = local_read(&(cpu_buffer->overrun));
80189+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
80190
80191 /*
80192 * Here's the tricky part.
80193@@ -4116,8 +4116,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80194
80195 cpu_buffer->head_page
80196 = list_entry(cpu_buffer->pages, struct buffer_page, list);
80197- local_set(&cpu_buffer->head_page->write, 0);
80198- local_set(&cpu_buffer->head_page->entries, 0);
80199+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
80200+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
80201 local_set(&cpu_buffer->head_page->page->commit, 0);
80202
80203 cpu_buffer->head_page->read = 0;
80204@@ -4127,14 +4127,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80205
80206 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
80207 INIT_LIST_HEAD(&cpu_buffer->new_pages);
80208- local_set(&cpu_buffer->reader_page->write, 0);
80209- local_set(&cpu_buffer->reader_page->entries, 0);
80210+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80211+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80212 local_set(&cpu_buffer->reader_page->page->commit, 0);
80213 cpu_buffer->reader_page->read = 0;
80214
80215 local_set(&cpu_buffer->entries_bytes, 0);
80216- local_set(&cpu_buffer->overrun, 0);
80217- local_set(&cpu_buffer->commit_overrun, 0);
80218+ local_set_unchecked(&cpu_buffer->overrun, 0);
80219+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
80220 local_set(&cpu_buffer->dropped_events, 0);
80221 local_set(&cpu_buffer->entries, 0);
80222 local_set(&cpu_buffer->committing, 0);
80223@@ -4538,8 +4538,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
80224 rb_init_page(bpage);
80225 bpage = reader->page;
80226 reader->page = *data_page;
80227- local_set(&reader->write, 0);
80228- local_set(&reader->entries, 0);
80229+ local_set_unchecked(&reader->write, 0);
80230+ local_set_unchecked(&reader->entries, 0);
80231 reader->read = 0;
80232 *data_page = bpage;
80233
80234diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
80235index e71a8be..948710a 100644
80236--- a/kernel/trace/trace.c
80237+++ b/kernel/trace/trace.c
80238@@ -3201,7 +3201,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
80239 return 0;
80240 }
80241
80242-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
80243+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
80244 {
80245 /* do nothing if flag is already set */
80246 if (!!(trace_flags & mask) == !!enabled)
80247diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
80248index 20572ed..fe55cf3 100644
80249--- a/kernel/trace/trace.h
80250+++ b/kernel/trace/trace.h
80251@@ -1030,7 +1030,7 @@ extern const char *__stop___trace_bprintk_fmt[];
80252 void trace_printk_init_buffers(void);
80253 void trace_printk_start_comm(void);
80254 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
80255-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
80256+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
80257
80258 /*
80259 * Normal trace_printk() and friends allocates special buffers
80260diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
80261index 27963e2..5a6936f 100644
80262--- a/kernel/trace/trace_events.c
80263+++ b/kernel/trace/trace_events.c
80264@@ -1637,10 +1637,6 @@ static LIST_HEAD(ftrace_module_file_list);
80265 struct ftrace_module_file_ops {
80266 struct list_head list;
80267 struct module *mod;
80268- struct file_operations id;
80269- struct file_operations enable;
80270- struct file_operations format;
80271- struct file_operations filter;
80272 };
80273
80274 static struct ftrace_module_file_ops *
80275@@ -1681,17 +1677,12 @@ trace_create_file_ops(struct module *mod)
80276
80277 file_ops->mod = mod;
80278
80279- file_ops->id = ftrace_event_id_fops;
80280- file_ops->id.owner = mod;
80281-
80282- file_ops->enable = ftrace_enable_fops;
80283- file_ops->enable.owner = mod;
80284-
80285- file_ops->filter = ftrace_event_filter_fops;
80286- file_ops->filter.owner = mod;
80287-
80288- file_ops->format = ftrace_event_format_fops;
80289- file_ops->format.owner = mod;
80290+ pax_open_kernel();
80291+ mod->trace_id.owner = mod;
80292+ mod->trace_enable.owner = mod;
80293+ mod->trace_filter.owner = mod;
80294+ mod->trace_format.owner = mod;
80295+ pax_close_kernel();
80296
80297 list_add(&file_ops->list, &ftrace_module_file_list);
80298
80299@@ -1782,8 +1773,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
80300 struct ftrace_module_file_ops *file_ops)
80301 {
80302 return __trace_add_new_event(call, tr,
80303- &file_ops->id, &file_ops->enable,
80304- &file_ops->filter, &file_ops->format);
80305+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
80306+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
80307 }
80308
80309 #else
80310diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
80311index a5e8f48..a9690d2 100644
80312--- a/kernel/trace/trace_mmiotrace.c
80313+++ b/kernel/trace/trace_mmiotrace.c
80314@@ -24,7 +24,7 @@ struct header_iter {
80315 static struct trace_array *mmio_trace_array;
80316 static bool overrun_detected;
80317 static unsigned long prev_overruns;
80318-static atomic_t dropped_count;
80319+static atomic_unchecked_t dropped_count;
80320
80321 static void mmio_reset_data(struct trace_array *tr)
80322 {
80323@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
80324
80325 static unsigned long count_overruns(struct trace_iterator *iter)
80326 {
80327- unsigned long cnt = atomic_xchg(&dropped_count, 0);
80328+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
80329 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
80330
80331 if (over > prev_overruns)
80332@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
80333 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
80334 sizeof(*entry), 0, pc);
80335 if (!event) {
80336- atomic_inc(&dropped_count);
80337+ atomic_inc_unchecked(&dropped_count);
80338 return;
80339 }
80340 entry = ring_buffer_event_data(event);
80341@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
80342 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
80343 sizeof(*entry), 0, pc);
80344 if (!event) {
80345- atomic_inc(&dropped_count);
80346+ atomic_inc_unchecked(&dropped_count);
80347 return;
80348 }
80349 entry = ring_buffer_event_data(event);
80350diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
80351index bb922d9..2a54a257 100644
80352--- a/kernel/trace/trace_output.c
80353+++ b/kernel/trace/trace_output.c
80354@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
80355
80356 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
80357 if (!IS_ERR(p)) {
80358- p = mangle_path(s->buffer + s->len, p, "\n");
80359+ p = mangle_path(s->buffer + s->len, p, "\n\\");
80360 if (p) {
80361 s->len = p - s->buffer;
80362 return 1;
80363@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
80364 goto out;
80365 }
80366
80367+ pax_open_kernel();
80368 if (event->funcs->trace == NULL)
80369- event->funcs->trace = trace_nop_print;
80370+ *(void **)&event->funcs->trace = trace_nop_print;
80371 if (event->funcs->raw == NULL)
80372- event->funcs->raw = trace_nop_print;
80373+ *(void **)&event->funcs->raw = trace_nop_print;
80374 if (event->funcs->hex == NULL)
80375- event->funcs->hex = trace_nop_print;
80376+ *(void **)&event->funcs->hex = trace_nop_print;
80377 if (event->funcs->binary == NULL)
80378- event->funcs->binary = trace_nop_print;
80379+ *(void **)&event->funcs->binary = trace_nop_print;
80380+ pax_close_kernel();
80381
80382 key = event->type & (EVENT_HASHSIZE - 1);
80383
80384diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
80385index b20428c..4845a10 100644
80386--- a/kernel/trace/trace_stack.c
80387+++ b/kernel/trace/trace_stack.c
80388@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
80389 return;
80390
80391 /* we do not handle interrupt stacks yet */
80392- if (!object_is_on_stack(stack))
80393+ if (!object_starts_on_stack(stack))
80394 return;
80395
80396 local_irq_save(flags);
80397diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
80398index d8c30db..e065e89 100644
80399--- a/kernel/user_namespace.c
80400+++ b/kernel/user_namespace.c
80401@@ -853,7 +853,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
80402 if (atomic_read(&current->mm->mm_users) > 1)
80403 return -EINVAL;
80404
80405- if (current->fs->users != 1)
80406+ if (atomic_read(&current->fs->users) != 1)
80407 return -EINVAL;
80408
80409 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
80410diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
80411index 4f69f9a..7c6f8f8 100644
80412--- a/kernel/utsname_sysctl.c
80413+++ b/kernel/utsname_sysctl.c
80414@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
80415 static int proc_do_uts_string(ctl_table *table, int write,
80416 void __user *buffer, size_t *lenp, loff_t *ppos)
80417 {
80418- struct ctl_table uts_table;
80419+ ctl_table_no_const uts_table;
80420 int r;
80421 memcpy(&uts_table, table, sizeof(uts_table));
80422 uts_table.data = get_uts(table, write);
80423diff --git a/kernel/watchdog.c b/kernel/watchdog.c
80424index 05039e3..17490c7 100644
80425--- a/kernel/watchdog.c
80426+++ b/kernel/watchdog.c
80427@@ -531,7 +531,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
80428 }
80429 #endif /* CONFIG_SYSCTL */
80430
80431-static struct smp_hotplug_thread watchdog_threads = {
80432+static struct smp_hotplug_thread watchdog_threads __read_only = {
80433 .store = &softlockup_watchdog,
80434 .thread_should_run = watchdog_should_run,
80435 .thread_fn = watchdog,
80436diff --git a/kernel/workqueue.c b/kernel/workqueue.c
80437index ee8e29a..410568e 100644
80438--- a/kernel/workqueue.c
80439+++ b/kernel/workqueue.c
80440@@ -4584,7 +4584,7 @@ static void rebind_workers(struct worker_pool *pool)
80441 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
80442 worker_flags |= WORKER_REBOUND;
80443 worker_flags &= ~WORKER_UNBOUND;
80444- ACCESS_ONCE(worker->flags) = worker_flags;
80445+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
80446 }
80447
80448 spin_unlock_irq(&pool->lock);
80449diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
80450index 566cf2b..fdaa52c 100644
80451--- a/lib/Kconfig.debug
80452+++ b/lib/Kconfig.debug
80453@@ -549,7 +549,7 @@ config DEBUG_MUTEXES
80454
80455 config DEBUG_LOCK_ALLOC
80456 bool "Lock debugging: detect incorrect freeing of live locks"
80457- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80458+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80459 select DEBUG_SPINLOCK
80460 select DEBUG_MUTEXES
80461 select LOCKDEP
80462@@ -563,7 +563,7 @@ config DEBUG_LOCK_ALLOC
80463
80464 config PROVE_LOCKING
80465 bool "Lock debugging: prove locking correctness"
80466- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80467+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80468 select LOCKDEP
80469 select DEBUG_SPINLOCK
80470 select DEBUG_MUTEXES
80471@@ -614,7 +614,7 @@ config LOCKDEP
80472
80473 config LOCK_STAT
80474 bool "Lock usage statistics"
80475- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80476+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80477 select LOCKDEP
80478 select DEBUG_SPINLOCK
80479 select DEBUG_MUTEXES
80480@@ -1282,6 +1282,7 @@ config LATENCYTOP
80481 depends on DEBUG_KERNEL
80482 depends on STACKTRACE_SUPPORT
80483 depends on PROC_FS
80484+ depends on !GRKERNSEC_HIDESYM
80485 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
80486 select KALLSYMS
80487 select KALLSYMS_ALL
80488@@ -1298,7 +1299,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
80489 config DEBUG_STRICT_USER_COPY_CHECKS
80490 bool "Strict user copy size checks"
80491 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
80492- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
80493+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
80494 help
80495 Enabling this option turns a certain set of sanity checks for user
80496 copy operations into compile time failures.
80497@@ -1328,7 +1329,7 @@ config INTERVAL_TREE_TEST
80498
80499 config PROVIDE_OHCI1394_DMA_INIT
80500 bool "Remote debugging over FireWire early on boot"
80501- depends on PCI && X86
80502+ depends on PCI && X86 && !GRKERNSEC
80503 help
80504 If you want to debug problems which hang or crash the kernel early
80505 on boot and the crashing machine has a FireWire port, you can use
80506@@ -1357,7 +1358,7 @@ config PROVIDE_OHCI1394_DMA_INIT
80507
80508 config FIREWIRE_OHCI_REMOTE_DMA
80509 bool "Remote debugging over FireWire with firewire-ohci"
80510- depends on FIREWIRE_OHCI
80511+ depends on FIREWIRE_OHCI && !GRKERNSEC
80512 help
80513 This option lets you use the FireWire bus for remote debugging
80514 with help of the firewire-ohci driver. It enables unfiltered
80515diff --git a/lib/Makefile b/lib/Makefile
80516index c55a037..fb46e3b 100644
80517--- a/lib/Makefile
80518+++ b/lib/Makefile
80519@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
80520
80521 obj-$(CONFIG_BTREE) += btree.o
80522 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
80523-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
80524+obj-y += list_debug.o
80525 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
80526
80527 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
80528diff --git a/lib/bitmap.c b/lib/bitmap.c
80529index 06f7e4f..f3cf2b0 100644
80530--- a/lib/bitmap.c
80531+++ b/lib/bitmap.c
80532@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
80533 {
80534 int c, old_c, totaldigits, ndigits, nchunks, nbits;
80535 u32 chunk;
80536- const char __user __force *ubuf = (const char __user __force *)buf;
80537+ const char __user *ubuf = (const char __force_user *)buf;
80538
80539 bitmap_zero(maskp, nmaskbits);
80540
80541@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
80542 {
80543 if (!access_ok(VERIFY_READ, ubuf, ulen))
80544 return -EFAULT;
80545- return __bitmap_parse((const char __force *)ubuf,
80546+ return __bitmap_parse((const char __force_kernel *)ubuf,
80547 ulen, 1, maskp, nmaskbits);
80548
80549 }
80550@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
80551 {
80552 unsigned a, b;
80553 int c, old_c, totaldigits;
80554- const char __user __force *ubuf = (const char __user __force *)buf;
80555+ const char __user *ubuf = (const char __force_user *)buf;
80556 int exp_digit, in_range;
80557
80558 totaldigits = c = 0;
80559@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
80560 {
80561 if (!access_ok(VERIFY_READ, ubuf, ulen))
80562 return -EFAULT;
80563- return __bitmap_parselist((const char __force *)ubuf,
80564+ return __bitmap_parselist((const char __force_kernel *)ubuf,
80565 ulen, 1, maskp, nmaskbits);
80566 }
80567 EXPORT_SYMBOL(bitmap_parselist_user);
80568diff --git a/lib/bug.c b/lib/bug.c
80569index 1686034..a9c00c8 100644
80570--- a/lib/bug.c
80571+++ b/lib/bug.c
80572@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
80573 return BUG_TRAP_TYPE_NONE;
80574
80575 bug = find_bug(bugaddr);
80576+ if (!bug)
80577+ return BUG_TRAP_TYPE_NONE;
80578
80579 file = NULL;
80580 line = 0;
80581diff --git a/lib/debugobjects.c b/lib/debugobjects.c
80582index 37061ed..da83f48 100644
80583--- a/lib/debugobjects.c
80584+++ b/lib/debugobjects.c
80585@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
80586 if (limit > 4)
80587 return;
80588
80589- is_on_stack = object_is_on_stack(addr);
80590+ is_on_stack = object_starts_on_stack(addr);
80591 if (is_on_stack == onstack)
80592 return;
80593
80594diff --git a/lib/devres.c b/lib/devres.c
80595index 8235331..5881053 100644
80596--- a/lib/devres.c
80597+++ b/lib/devres.c
80598@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
80599 void devm_iounmap(struct device *dev, void __iomem *addr)
80600 {
80601 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
80602- (void *)addr));
80603+ (void __force *)addr));
80604 iounmap(addr);
80605 }
80606 EXPORT_SYMBOL(devm_iounmap);
80607@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
80608 {
80609 ioport_unmap(addr);
80610 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
80611- devm_ioport_map_match, (void *)addr));
80612+ devm_ioport_map_match, (void __force *)addr));
80613 }
80614 EXPORT_SYMBOL(devm_ioport_unmap);
80615 #endif /* CONFIG_HAS_IOPORT */
80616diff --git a/lib/div64.c b/lib/div64.c
80617index a163b6c..9618fa5 100644
80618--- a/lib/div64.c
80619+++ b/lib/div64.c
80620@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
80621 EXPORT_SYMBOL(__div64_32);
80622
80623 #ifndef div_s64_rem
80624-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80625+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80626 {
80627 u64 quotient;
80628
80629@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
80630 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
80631 */
80632 #ifndef div64_u64
80633-u64 div64_u64(u64 dividend, u64 divisor)
80634+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80635 {
80636 u32 high = divisor >> 32;
80637 u64 quot;
80638diff --git a/lib/dma-debug.c b/lib/dma-debug.c
80639index d87a17a..ac0d79a 100644
80640--- a/lib/dma-debug.c
80641+++ b/lib/dma-debug.c
80642@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
80643
80644 void dma_debug_add_bus(struct bus_type *bus)
80645 {
80646- struct notifier_block *nb;
80647+ notifier_block_no_const *nb;
80648
80649 if (global_disable)
80650 return;
80651@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
80652
80653 static void check_for_stack(struct device *dev, void *addr)
80654 {
80655- if (object_is_on_stack(addr))
80656+ if (object_starts_on_stack(addr))
80657 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
80658 "stack [addr=%p]\n", addr);
80659 }
80660diff --git a/lib/inflate.c b/lib/inflate.c
80661index 013a761..c28f3fc 100644
80662--- a/lib/inflate.c
80663+++ b/lib/inflate.c
80664@@ -269,7 +269,7 @@ static void free(void *where)
80665 malloc_ptr = free_mem_ptr;
80666 }
80667 #else
80668-#define malloc(a) kmalloc(a, GFP_KERNEL)
80669+#define malloc(a) kmalloc((a), GFP_KERNEL)
80670 #define free(a) kfree(a)
80671 #endif
80672
80673diff --git a/lib/ioremap.c b/lib/ioremap.c
80674index 0c9216c..863bd89 100644
80675--- a/lib/ioremap.c
80676+++ b/lib/ioremap.c
80677@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
80678 unsigned long next;
80679
80680 phys_addr -= addr;
80681- pmd = pmd_alloc(&init_mm, pud, addr);
80682+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
80683 if (!pmd)
80684 return -ENOMEM;
80685 do {
80686@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
80687 unsigned long next;
80688
80689 phys_addr -= addr;
80690- pud = pud_alloc(&init_mm, pgd, addr);
80691+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
80692 if (!pud)
80693 return -ENOMEM;
80694 do {
80695diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
80696index bd2bea9..6b3c95e 100644
80697--- a/lib/is_single_threaded.c
80698+++ b/lib/is_single_threaded.c
80699@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
80700 struct task_struct *p, *t;
80701 bool ret;
80702
80703+ if (!mm)
80704+ return true;
80705+
80706 if (atomic_read(&task->signal->live) != 1)
80707 return false;
80708
80709diff --git a/lib/kobject.c b/lib/kobject.c
80710index b7e29a6..2f3ca75 100644
80711--- a/lib/kobject.c
80712+++ b/lib/kobject.c
80713@@ -805,7 +805,7 @@ static struct kset *kset_create(const char *name,
80714 kset = kzalloc(sizeof(*kset), GFP_KERNEL);
80715 if (!kset)
80716 return NULL;
80717- retval = kobject_set_name(&kset->kobj, name);
80718+ retval = kobject_set_name(&kset->kobj, "%s", name);
80719 if (retval) {
80720 kfree(kset);
80721 return NULL;
80722@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
80723
80724
80725 static DEFINE_SPINLOCK(kobj_ns_type_lock);
80726-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
80727+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
80728
80729-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80730+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80731 {
80732 enum kobj_ns_type type = ops->type;
80733 int error;
80734diff --git a/lib/list_debug.c b/lib/list_debug.c
80735index c24c2f7..06e070b 100644
80736--- a/lib/list_debug.c
80737+++ b/lib/list_debug.c
80738@@ -11,7 +11,9 @@
80739 #include <linux/bug.h>
80740 #include <linux/kernel.h>
80741 #include <linux/rculist.h>
80742+#include <linux/mm.h>
80743
80744+#ifdef CONFIG_DEBUG_LIST
80745 /*
80746 * Insert a new entry between two known consecutive entries.
80747 *
80748@@ -19,21 +21,32 @@
80749 * the prev/next entries already!
80750 */
80751
80752-void __list_add(struct list_head *new,
80753- struct list_head *prev,
80754- struct list_head *next)
80755+static bool __list_add_debug(struct list_head *new,
80756+ struct list_head *prev,
80757+ struct list_head *next)
80758 {
80759- WARN(next->prev != prev,
80760+ if (WARN(next->prev != prev,
80761 "list_add corruption. next->prev should be "
80762 "prev (%p), but was %p. (next=%p).\n",
80763- prev, next->prev, next);
80764- WARN(prev->next != next,
80765+ prev, next->prev, next) ||
80766+ WARN(prev->next != next,
80767 "list_add corruption. prev->next should be "
80768 "next (%p), but was %p. (prev=%p).\n",
80769- next, prev->next, prev);
80770- WARN(new == prev || new == next,
80771- "list_add double add: new=%p, prev=%p, next=%p.\n",
80772- new, prev, next);
80773+ next, prev->next, prev) ||
80774+ WARN(new == prev || new == next,
80775+ "list_add double add: new=%p, prev=%p, next=%p.\n",
80776+ new, prev, next))
80777+ return false;
80778+ return true;
80779+}
80780+
80781+void __list_add(struct list_head *new,
80782+ struct list_head *prev,
80783+ struct list_head *next)
80784+{
80785+ if (!__list_add_debug(new, prev, next))
80786+ return;
80787+
80788 next->prev = new;
80789 new->next = next;
80790 new->prev = prev;
80791@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
80792 }
80793 EXPORT_SYMBOL(__list_add);
80794
80795-void __list_del_entry(struct list_head *entry)
80796+static bool __list_del_entry_debug(struct list_head *entry)
80797 {
80798 struct list_head *prev, *next;
80799
80800@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
80801 WARN(next->prev != entry,
80802 "list_del corruption. next->prev should be %p, "
80803 "but was %p\n", entry, next->prev))
80804+ return false;
80805+ return true;
80806+}
80807+
80808+void __list_del_entry(struct list_head *entry)
80809+{
80810+ if (!__list_del_entry_debug(entry))
80811 return;
80812
80813- __list_del(prev, next);
80814+ __list_del(entry->prev, entry->next);
80815 }
80816 EXPORT_SYMBOL(__list_del_entry);
80817
80818@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
80819 void __list_add_rcu(struct list_head *new,
80820 struct list_head *prev, struct list_head *next)
80821 {
80822- WARN(next->prev != prev,
80823- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
80824- prev, next->prev, next);
80825- WARN(prev->next != next,
80826- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
80827- next, prev->next, prev);
80828+ if (!__list_add_debug(new, prev, next))
80829+ return;
80830+
80831 new->next = next;
80832 new->prev = prev;
80833 rcu_assign_pointer(list_next_rcu(prev), new);
80834 next->prev = new;
80835 }
80836 EXPORT_SYMBOL(__list_add_rcu);
80837+#endif
80838+
80839+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
80840+{
80841+#ifdef CONFIG_DEBUG_LIST
80842+ if (!__list_add_debug(new, prev, next))
80843+ return;
80844+#endif
80845+
80846+ pax_open_kernel();
80847+ next->prev = new;
80848+ new->next = next;
80849+ new->prev = prev;
80850+ prev->next = new;
80851+ pax_close_kernel();
80852+}
80853+EXPORT_SYMBOL(__pax_list_add);
80854+
80855+void pax_list_del(struct list_head *entry)
80856+{
80857+#ifdef CONFIG_DEBUG_LIST
80858+ if (!__list_del_entry_debug(entry))
80859+ return;
80860+#endif
80861+
80862+ pax_open_kernel();
80863+ __list_del(entry->prev, entry->next);
80864+ entry->next = LIST_POISON1;
80865+ entry->prev = LIST_POISON2;
80866+ pax_close_kernel();
80867+}
80868+EXPORT_SYMBOL(pax_list_del);
80869+
80870+void pax_list_del_init(struct list_head *entry)
80871+{
80872+ pax_open_kernel();
80873+ __list_del(entry->prev, entry->next);
80874+ INIT_LIST_HEAD(entry);
80875+ pax_close_kernel();
80876+}
80877+EXPORT_SYMBOL(pax_list_del_init);
80878+
80879+void __pax_list_add_rcu(struct list_head *new,
80880+ struct list_head *prev, struct list_head *next)
80881+{
80882+#ifdef CONFIG_DEBUG_LIST
80883+ if (!__list_add_debug(new, prev, next))
80884+ return;
80885+#endif
80886+
80887+ pax_open_kernel();
80888+ new->next = next;
80889+ new->prev = prev;
80890+ rcu_assign_pointer(list_next_rcu(prev), new);
80891+ next->prev = new;
80892+ pax_close_kernel();
80893+}
80894+EXPORT_SYMBOL(__pax_list_add_rcu);
80895+
80896+void pax_list_del_rcu(struct list_head *entry)
80897+{
80898+#ifdef CONFIG_DEBUG_LIST
80899+ if (!__list_del_entry_debug(entry))
80900+ return;
80901+#endif
80902+
80903+ pax_open_kernel();
80904+ __list_del(entry->prev, entry->next);
80905+ entry->next = LIST_POISON1;
80906+ entry->prev = LIST_POISON2;
80907+ pax_close_kernel();
80908+}
80909+EXPORT_SYMBOL(pax_list_del_rcu);
80910diff --git a/lib/radix-tree.c b/lib/radix-tree.c
80911index e796429..6e38f9f 100644
80912--- a/lib/radix-tree.c
80913+++ b/lib/radix-tree.c
80914@@ -92,7 +92,7 @@ struct radix_tree_preload {
80915 int nr;
80916 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
80917 };
80918-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
80919+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
80920
80921 static inline void *ptr_to_indirect(void *ptr)
80922 {
80923diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
80924index bb2b201..46abaf9 100644
80925--- a/lib/strncpy_from_user.c
80926+++ b/lib/strncpy_from_user.c
80927@@ -21,7 +21,7 @@
80928 */
80929 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
80930 {
80931- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80932+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80933 long res = 0;
80934
80935 /*
80936diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
80937index a28df52..3d55877 100644
80938--- a/lib/strnlen_user.c
80939+++ b/lib/strnlen_user.c
80940@@ -26,7 +26,7 @@
80941 */
80942 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
80943 {
80944- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80945+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80946 long align, res = 0;
80947 unsigned long c;
80948
80949diff --git a/lib/swiotlb.c b/lib/swiotlb.c
80950index d23762e..e21eab2 100644
80951--- a/lib/swiotlb.c
80952+++ b/lib/swiotlb.c
80953@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
80954
80955 void
80956 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
80957- dma_addr_t dev_addr)
80958+ dma_addr_t dev_addr, struct dma_attrs *attrs)
80959 {
80960 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
80961
80962diff --git a/lib/usercopy.c b/lib/usercopy.c
80963index 4f5b1dd..7cab418 100644
80964--- a/lib/usercopy.c
80965+++ b/lib/usercopy.c
80966@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
80967 WARN(1, "Buffer overflow detected!\n");
80968 }
80969 EXPORT_SYMBOL(copy_from_user_overflow);
80970+
80971+void copy_to_user_overflow(void)
80972+{
80973+ WARN(1, "Buffer overflow detected!\n");
80974+}
80975+EXPORT_SYMBOL(copy_to_user_overflow);
80976diff --git a/lib/vsprintf.c b/lib/vsprintf.c
80977index e149c64..24aa71a 100644
80978--- a/lib/vsprintf.c
80979+++ b/lib/vsprintf.c
80980@@ -16,6 +16,9 @@
80981 * - scnprintf and vscnprintf
80982 */
80983
80984+#ifdef CONFIG_GRKERNSEC_HIDESYM
80985+#define __INCLUDED_BY_HIDESYM 1
80986+#endif
80987 #include <stdarg.h>
80988 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
80989 #include <linux/types.h>
80990@@ -981,7 +984,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
80991 return number(buf, end, *(const netdev_features_t *)addr, spec);
80992 }
80993
80994+#ifdef CONFIG_GRKERNSEC_HIDESYM
80995+int kptr_restrict __read_mostly = 2;
80996+#else
80997 int kptr_restrict __read_mostly;
80998+#endif
80999
81000 /*
81001 * Show a '%p' thing. A kernel extension is that the '%p' is followed
81002@@ -994,6 +1001,7 @@ int kptr_restrict __read_mostly;
81003 * - 'f' For simple symbolic function names without offset
81004 * - 'S' For symbolic direct pointers with offset
81005 * - 's' For symbolic direct pointers without offset
81006+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
81007 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
81008 * - 'B' For backtraced symbolic direct pointers with offset
81009 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
81010@@ -1052,12 +1060,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81011
81012 if (!ptr && *fmt != 'K') {
81013 /*
81014- * Print (null) with the same width as a pointer so it makes
81015+ * Print (nil) with the same width as a pointer so it makes
81016 * tabular output look nice.
81017 */
81018 if (spec.field_width == -1)
81019 spec.field_width = default_width;
81020- return string(buf, end, "(null)", spec);
81021+ return string(buf, end, "(nil)", spec);
81022 }
81023
81024 switch (*fmt) {
81025@@ -1067,6 +1075,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81026 /* Fallthrough */
81027 case 'S':
81028 case 's':
81029+#ifdef CONFIG_GRKERNSEC_HIDESYM
81030+ break;
81031+#else
81032+ return symbol_string(buf, end, ptr, spec, fmt);
81033+#endif
81034+ case 'A':
81035 case 'B':
81036 return symbol_string(buf, end, ptr, spec, fmt);
81037 case 'R':
81038@@ -1107,6 +1121,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81039 va_end(va);
81040 return buf;
81041 }
81042+ case 'P':
81043+ break;
81044 case 'K':
81045 /*
81046 * %pK cannot be used in IRQ context because its test
81047@@ -1136,6 +1152,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81048 return number(buf, end,
81049 (unsigned long long) *((phys_addr_t *)ptr), spec);
81050 }
81051+
81052+#ifdef CONFIG_GRKERNSEC_HIDESYM
81053+ /* 'P' = approved pointers to copy to userland,
81054+ as in the /proc/kallsyms case, as we make it display nothing
81055+ for non-root users, and the real contents for root users
81056+ Also ignore 'K' pointers, since we force their NULLing for non-root users
81057+ above
81058+ */
81059+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
81060+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
81061+ dump_stack();
81062+ ptr = NULL;
81063+ }
81064+#endif
81065+
81066 spec.flags |= SMALL;
81067 if (spec.field_width == -1) {
81068 spec.field_width = default_width;
81069@@ -1857,11 +1888,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
81070 typeof(type) value; \
81071 if (sizeof(type) == 8) { \
81072 args = PTR_ALIGN(args, sizeof(u32)); \
81073- *(u32 *)&value = *(u32 *)args; \
81074- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
81075+ *(u32 *)&value = *(const u32 *)args; \
81076+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
81077 } else { \
81078 args = PTR_ALIGN(args, sizeof(type)); \
81079- value = *(typeof(type) *)args; \
81080+ value = *(const typeof(type) *)args; \
81081 } \
81082 args += sizeof(type); \
81083 value; \
81084@@ -1924,7 +1955,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
81085 case FORMAT_TYPE_STR: {
81086 const char *str_arg = args;
81087 args += strlen(str_arg) + 1;
81088- str = string(str, end, (char *)str_arg, spec);
81089+ str = string(str, end, str_arg, spec);
81090 break;
81091 }
81092
81093diff --git a/localversion-grsec b/localversion-grsec
81094new file mode 100644
81095index 0000000..7cd6065
81096--- /dev/null
81097+++ b/localversion-grsec
81098@@ -0,0 +1 @@
81099+-grsec
81100diff --git a/mm/Kconfig b/mm/Kconfig
81101index e742d06..c56fdd8 100644
81102--- a/mm/Kconfig
81103+++ b/mm/Kconfig
81104@@ -317,10 +317,10 @@ config KSM
81105 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
81106
81107 config DEFAULT_MMAP_MIN_ADDR
81108- int "Low address space to protect from user allocation"
81109+ int "Low address space to protect from user allocation"
81110 depends on MMU
81111- default 4096
81112- help
81113+ default 65536
81114+ help
81115 This is the portion of low virtual memory which should be protected
81116 from userspace allocation. Keeping a user from writing to low pages
81117 can help reduce the impact of kernel NULL pointer bugs.
81118@@ -351,7 +351,7 @@ config MEMORY_FAILURE
81119
81120 config HWPOISON_INJECT
81121 tristate "HWPoison pages injector"
81122- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
81123+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
81124 select PROC_PAGE_MONITOR
81125
81126 config NOMMU_INITIAL_TRIM_EXCESS
81127diff --git a/mm/backing-dev.c b/mm/backing-dev.c
81128index 5025174..9fc1c5c 100644
81129--- a/mm/backing-dev.c
81130+++ b/mm/backing-dev.c
81131@@ -515,7 +515,6 @@ EXPORT_SYMBOL(bdi_destroy);
81132 int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
81133 unsigned int cap)
81134 {
81135- char tmp[32];
81136 int err;
81137
81138 bdi->name = name;
81139@@ -524,8 +523,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
81140 if (err)
81141 return err;
81142
81143- sprintf(tmp, "%.28s%s", name, "-%d");
81144- err = bdi_register(bdi, NULL, tmp, atomic_long_inc_return(&bdi_seq));
81145+ err = bdi_register(bdi, NULL, "%.28s-%ld", name, atomic_long_inc_return(&bdi_seq));
81146 if (err) {
81147 bdi_destroy(bdi);
81148 return err;
81149diff --git a/mm/filemap.c b/mm/filemap.c
81150index 7905fe7..e60faa8 100644
81151--- a/mm/filemap.c
81152+++ b/mm/filemap.c
81153@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
81154 struct address_space *mapping = file->f_mapping;
81155
81156 if (!mapping->a_ops->readpage)
81157- return -ENOEXEC;
81158+ return -ENODEV;
81159 file_accessed(file);
81160 vma->vm_ops = &generic_file_vm_ops;
81161 return 0;
81162@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
81163 *pos = i_size_read(inode);
81164
81165 if (limit != RLIM_INFINITY) {
81166+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
81167 if (*pos >= limit) {
81168 send_sig(SIGXFSZ, current, 0);
81169 return -EFBIG;
81170diff --git a/mm/fremap.c b/mm/fremap.c
81171index 87da359..3f41cb1 100644
81172--- a/mm/fremap.c
81173+++ b/mm/fremap.c
81174@@ -158,6 +158,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
81175 retry:
81176 vma = find_vma(mm, start);
81177
81178+#ifdef CONFIG_PAX_SEGMEXEC
81179+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
81180+ goto out;
81181+#endif
81182+
81183 /*
81184 * Make sure the vma is shared, that it supports prefaulting,
81185 * and that the remapped range is valid and fully within
81186diff --git a/mm/highmem.c b/mm/highmem.c
81187index b32b70c..e512eb0 100644
81188--- a/mm/highmem.c
81189+++ b/mm/highmem.c
81190@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
81191 * So no dangers, even with speculative execution.
81192 */
81193 page = pte_page(pkmap_page_table[i]);
81194+ pax_open_kernel();
81195 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
81196-
81197+ pax_close_kernel();
81198 set_page_address(page, NULL);
81199 need_flush = 1;
81200 }
81201@@ -198,9 +199,11 @@ start:
81202 }
81203 }
81204 vaddr = PKMAP_ADDR(last_pkmap_nr);
81205+
81206+ pax_open_kernel();
81207 set_pte_at(&init_mm, vaddr,
81208 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
81209-
81210+ pax_close_kernel();
81211 pkmap_count[last_pkmap_nr] = 1;
81212 set_page_address(page, (void *)vaddr);
81213
81214diff --git a/mm/hugetlb.c b/mm/hugetlb.c
81215index 5cf99bf..28634c8 100644
81216--- a/mm/hugetlb.c
81217+++ b/mm/hugetlb.c
81218@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
81219 struct hstate *h = &default_hstate;
81220 unsigned long tmp;
81221 int ret;
81222+ ctl_table_no_const hugetlb_table;
81223
81224 tmp = h->max_huge_pages;
81225
81226 if (write && h->order >= MAX_ORDER)
81227 return -EINVAL;
81228
81229- table->data = &tmp;
81230- table->maxlen = sizeof(unsigned long);
81231- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
81232+ hugetlb_table = *table;
81233+ hugetlb_table.data = &tmp;
81234+ hugetlb_table.maxlen = sizeof(unsigned long);
81235+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
81236 if (ret)
81237 goto out;
81238
81239@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
81240 struct hstate *h = &default_hstate;
81241 unsigned long tmp;
81242 int ret;
81243+ ctl_table_no_const hugetlb_table;
81244
81245 tmp = h->nr_overcommit_huge_pages;
81246
81247 if (write && h->order >= MAX_ORDER)
81248 return -EINVAL;
81249
81250- table->data = &tmp;
81251- table->maxlen = sizeof(unsigned long);
81252- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
81253+ hugetlb_table = *table;
81254+ hugetlb_table.data = &tmp;
81255+ hugetlb_table.maxlen = sizeof(unsigned long);
81256+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
81257 if (ret)
81258 goto out;
81259
81260@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
81261 return 1;
81262 }
81263
81264+#ifdef CONFIG_PAX_SEGMEXEC
81265+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
81266+{
81267+ struct mm_struct *mm = vma->vm_mm;
81268+ struct vm_area_struct *vma_m;
81269+ unsigned long address_m;
81270+ pte_t *ptep_m;
81271+
81272+ vma_m = pax_find_mirror_vma(vma);
81273+ if (!vma_m)
81274+ return;
81275+
81276+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81277+ address_m = address + SEGMEXEC_TASK_SIZE;
81278+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
81279+ get_page(page_m);
81280+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
81281+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
81282+}
81283+#endif
81284+
81285 /*
81286 * Hugetlb_cow() should be called with page lock of the original hugepage held.
81287 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
81288@@ -2663,6 +2688,11 @@ retry_avoidcopy:
81289 make_huge_pte(vma, new_page, 1));
81290 page_remove_rmap(old_page);
81291 hugepage_add_new_anon_rmap(new_page, vma, address);
81292+
81293+#ifdef CONFIG_PAX_SEGMEXEC
81294+ pax_mirror_huge_pte(vma, address, new_page);
81295+#endif
81296+
81297 /* Make the old page be freed below */
81298 new_page = old_page;
81299 }
81300@@ -2821,6 +2851,10 @@ retry:
81301 && (vma->vm_flags & VM_SHARED)));
81302 set_huge_pte_at(mm, address, ptep, new_pte);
81303
81304+#ifdef CONFIG_PAX_SEGMEXEC
81305+ pax_mirror_huge_pte(vma, address, page);
81306+#endif
81307+
81308 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
81309 /* Optimization, do the COW without a second fault */
81310 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
81311@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81312 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
81313 struct hstate *h = hstate_vma(vma);
81314
81315+#ifdef CONFIG_PAX_SEGMEXEC
81316+ struct vm_area_struct *vma_m;
81317+#endif
81318+
81319 address &= huge_page_mask(h);
81320
81321 ptep = huge_pte_offset(mm, address);
81322@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81323 VM_FAULT_SET_HINDEX(hstate_index(h));
81324 }
81325
81326+#ifdef CONFIG_PAX_SEGMEXEC
81327+ vma_m = pax_find_mirror_vma(vma);
81328+ if (vma_m) {
81329+ unsigned long address_m;
81330+
81331+ if (vma->vm_start > vma_m->vm_start) {
81332+ address_m = address;
81333+ address -= SEGMEXEC_TASK_SIZE;
81334+ vma = vma_m;
81335+ h = hstate_vma(vma);
81336+ } else
81337+ address_m = address + SEGMEXEC_TASK_SIZE;
81338+
81339+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
81340+ return VM_FAULT_OOM;
81341+ address_m &= HPAGE_MASK;
81342+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
81343+ }
81344+#endif
81345+
81346 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
81347 if (!ptep)
81348 return VM_FAULT_OOM;
81349diff --git a/mm/internal.h b/mm/internal.h
81350index 8562de0..7fdfe92 100644
81351--- a/mm/internal.h
81352+++ b/mm/internal.h
81353@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
81354 * in mm/page_alloc.c
81355 */
81356 extern void __free_pages_bootmem(struct page *page, unsigned int order);
81357+extern void free_compound_page(struct page *page);
81358 extern void prep_compound_page(struct page *page, unsigned long order);
81359 #ifdef CONFIG_MEMORY_FAILURE
81360 extern bool is_free_buddy_page(struct page *page);
81361diff --git a/mm/kmemleak.c b/mm/kmemleak.c
81362index c8d7f31..2dbeffd 100644
81363--- a/mm/kmemleak.c
81364+++ b/mm/kmemleak.c
81365@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
81366
81367 for (i = 0; i < object->trace_len; i++) {
81368 void *ptr = (void *)object->trace[i];
81369- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
81370+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
81371 }
81372 }
81373
81374@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
81375 return -ENOMEM;
81376 }
81377
81378- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
81379+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
81380 &kmemleak_fops);
81381 if (!dentry)
81382 pr_warning("Failed to create the debugfs kmemleak file\n");
81383diff --git a/mm/maccess.c b/mm/maccess.c
81384index d53adf9..03a24bf 100644
81385--- a/mm/maccess.c
81386+++ b/mm/maccess.c
81387@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
81388 set_fs(KERNEL_DS);
81389 pagefault_disable();
81390 ret = __copy_from_user_inatomic(dst,
81391- (__force const void __user *)src, size);
81392+ (const void __force_user *)src, size);
81393 pagefault_enable();
81394 set_fs(old_fs);
81395
81396@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
81397
81398 set_fs(KERNEL_DS);
81399 pagefault_disable();
81400- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
81401+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
81402 pagefault_enable();
81403 set_fs(old_fs);
81404
81405diff --git a/mm/madvise.c b/mm/madvise.c
81406index 7055883..4e8c835 100644
81407--- a/mm/madvise.c
81408+++ b/mm/madvise.c
81409@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
81410 pgoff_t pgoff;
81411 unsigned long new_flags = vma->vm_flags;
81412
81413+#ifdef CONFIG_PAX_SEGMEXEC
81414+ struct vm_area_struct *vma_m;
81415+#endif
81416+
81417 switch (behavior) {
81418 case MADV_NORMAL:
81419 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
81420@@ -126,6 +130,13 @@ success:
81421 /*
81422 * vm_flags is protected by the mmap_sem held in write mode.
81423 */
81424+
81425+#ifdef CONFIG_PAX_SEGMEXEC
81426+ vma_m = pax_find_mirror_vma(vma);
81427+ if (vma_m)
81428+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
81429+#endif
81430+
81431 vma->vm_flags = new_flags;
81432
81433 out:
81434@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81435 struct vm_area_struct ** prev,
81436 unsigned long start, unsigned long end)
81437 {
81438+
81439+#ifdef CONFIG_PAX_SEGMEXEC
81440+ struct vm_area_struct *vma_m;
81441+#endif
81442+
81443 *prev = vma;
81444 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
81445 return -EINVAL;
81446@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81447 zap_page_range(vma, start, end - start, &details);
81448 } else
81449 zap_page_range(vma, start, end - start, NULL);
81450+
81451+#ifdef CONFIG_PAX_SEGMEXEC
81452+ vma_m = pax_find_mirror_vma(vma);
81453+ if (vma_m) {
81454+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
81455+ struct zap_details details = {
81456+ .nonlinear_vma = vma_m,
81457+ .last_index = ULONG_MAX,
81458+ };
81459+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
81460+ } else
81461+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
81462+ }
81463+#endif
81464+
81465 return 0;
81466 }
81467
81468@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
81469 if (end < start)
81470 return error;
81471
81472+#ifdef CONFIG_PAX_SEGMEXEC
81473+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81474+ if (end > SEGMEXEC_TASK_SIZE)
81475+ goto out;
81476+ } else
81477+#endif
81478+
81479+ if (end > TASK_SIZE)
81480+ goto out;
81481+
81482 error = 0;
81483 if (end == start)
81484 return error;
81485diff --git a/mm/memcontrol.c b/mm/memcontrol.c
81486index fd79df5..15b0409 100644
81487--- a/mm/memcontrol.c
81488+++ b/mm/memcontrol.c
81489@@ -6296,14 +6296,6 @@ mem_cgroup_css_online(struct cgroup *cont)
81490
81491 error = memcg_init_kmem(memcg, &mem_cgroup_subsys);
81492 mutex_unlock(&memcg_create_mutex);
81493- if (error) {
81494- /*
81495- * We call put now because our (and parent's) refcnts
81496- * are already in place. mem_cgroup_put() will internally
81497- * call __mem_cgroup_free, so return directly
81498- */
81499- mem_cgroup_put(memcg);
81500- }
81501 return error;
81502 }
81503
81504diff --git a/mm/memory-failure.c b/mm/memory-failure.c
81505index ceb0c7f..b2b8e94 100644
81506--- a/mm/memory-failure.c
81507+++ b/mm/memory-failure.c
81508@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
81509
81510 int sysctl_memory_failure_recovery __read_mostly = 1;
81511
81512-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
81513+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
81514
81515 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
81516
81517@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
81518 pfn, t->comm, t->pid);
81519 si.si_signo = SIGBUS;
81520 si.si_errno = 0;
81521- si.si_addr = (void *)addr;
81522+ si.si_addr = (void __user *)addr;
81523 #ifdef __ARCH_SI_TRAPNO
81524 si.si_trapno = trapno;
81525 #endif
81526@@ -760,7 +760,7 @@ static struct page_state {
81527 unsigned long res;
81528 char *msg;
81529 int (*action)(struct page *p, unsigned long pfn);
81530-} error_states[] = {
81531+} __do_const error_states[] = {
81532 { reserved, reserved, "reserved kernel", me_kernel },
81533 /*
81534 * free pages are specially detected outside this table:
81535@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81536 nr_pages = 1 << compound_order(hpage);
81537 else /* normal page or thp */
81538 nr_pages = 1;
81539- atomic_long_add(nr_pages, &num_poisoned_pages);
81540+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
81541
81542 /*
81543 * We need/can do nothing about count=0 pages.
81544@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81545 if (!PageHWPoison(hpage)
81546 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
81547 || (p != hpage && TestSetPageHWPoison(hpage))) {
81548- atomic_long_sub(nr_pages, &num_poisoned_pages);
81549+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81550 return 0;
81551 }
81552 set_page_hwpoison_huge_page(hpage);
81553@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81554 }
81555 if (hwpoison_filter(p)) {
81556 if (TestClearPageHWPoison(p))
81557- atomic_long_sub(nr_pages, &num_poisoned_pages);
81558+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81559 unlock_page(hpage);
81560 put_page(hpage);
81561 return 0;
81562@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
81563 return 0;
81564 }
81565 if (TestClearPageHWPoison(p))
81566- atomic_long_sub(nr_pages, &num_poisoned_pages);
81567+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81568 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
81569 return 0;
81570 }
81571@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
81572 */
81573 if (TestClearPageHWPoison(page)) {
81574 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
81575- atomic_long_sub(nr_pages, &num_poisoned_pages);
81576+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81577 freeit = 1;
81578 if (PageHuge(page))
81579 clear_page_hwpoison_huge_page(page);
81580@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
81581 } else {
81582 set_page_hwpoison_huge_page(hpage);
81583 dequeue_hwpoisoned_huge_page(hpage);
81584- atomic_long_add(1 << compound_trans_order(hpage),
81585+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81586 &num_poisoned_pages);
81587 }
81588 /* keep elevated page count for bad page */
81589@@ -1552,11 +1552,11 @@ int soft_offline_page(struct page *page, int flags)
81590 if (PageHuge(page)) {
81591 set_page_hwpoison_huge_page(hpage);
81592 dequeue_hwpoisoned_huge_page(hpage);
81593- atomic_long_add(1 << compound_trans_order(hpage),
81594+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81595 &num_poisoned_pages);
81596 } else {
81597 SetPageHWPoison(page);
81598- atomic_long_inc(&num_poisoned_pages);
81599+ atomic_long_inc_unchecked(&num_poisoned_pages);
81600 }
81601 }
81602 /* keep elevated page count for bad page */
81603@@ -1596,7 +1596,7 @@ static int __soft_offline_page(struct page *page, int flags)
81604 put_page(page);
81605 pr_info("soft_offline: %#lx: invalidated\n", pfn);
81606 SetPageHWPoison(page);
81607- atomic_long_inc(&num_poisoned_pages);
81608+ atomic_long_inc_unchecked(&num_poisoned_pages);
81609 return 0;
81610 }
81611
81612@@ -1626,7 +1626,7 @@ static int __soft_offline_page(struct page *page, int flags)
81613 ret = -EIO;
81614 } else {
81615 SetPageHWPoison(page);
81616- atomic_long_inc(&num_poisoned_pages);
81617+ atomic_long_inc_unchecked(&num_poisoned_pages);
81618 }
81619 } else {
81620 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
81621diff --git a/mm/memory.c b/mm/memory.c
81622index 61a262b..77a94d1 100644
81623--- a/mm/memory.c
81624+++ b/mm/memory.c
81625@@ -429,6 +429,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81626 free_pte_range(tlb, pmd, addr);
81627 } while (pmd++, addr = next, addr != end);
81628
81629+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
81630 start &= PUD_MASK;
81631 if (start < floor)
81632 return;
81633@@ -443,6 +444,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81634 pmd = pmd_offset(pud, start);
81635 pud_clear(pud);
81636 pmd_free_tlb(tlb, pmd, start);
81637+#endif
81638+
81639 }
81640
81641 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81642@@ -462,6 +465,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81643 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
81644 } while (pud++, addr = next, addr != end);
81645
81646+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
81647 start &= PGDIR_MASK;
81648 if (start < floor)
81649 return;
81650@@ -476,6 +480,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81651 pud = pud_offset(pgd, start);
81652 pgd_clear(pgd);
81653 pud_free_tlb(tlb, pud, start);
81654+#endif
81655+
81656 }
81657
81658 /*
81659@@ -1635,12 +1641,6 @@ no_page_table:
81660 return page;
81661 }
81662
81663-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
81664-{
81665- return stack_guard_page_start(vma, addr) ||
81666- stack_guard_page_end(vma, addr+PAGE_SIZE);
81667-}
81668-
81669 /**
81670 * __get_user_pages() - pin user pages in memory
81671 * @tsk: task_struct of target task
81672@@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81673
81674 i = 0;
81675
81676- do {
81677+ while (nr_pages) {
81678 struct vm_area_struct *vma;
81679
81680- vma = find_extend_vma(mm, start);
81681+ vma = find_vma(mm, start);
81682 if (!vma && in_gate_area(mm, start)) {
81683 unsigned long pg = start & PAGE_MASK;
81684 pgd_t *pgd;
81685@@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81686 goto next_page;
81687 }
81688
81689- if (!vma ||
81690+ if (!vma || start < vma->vm_start ||
81691 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
81692 !(vm_flags & vma->vm_flags))
81693 return i ? : -EFAULT;
81694@@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81695 int ret;
81696 unsigned int fault_flags = 0;
81697
81698- /* For mlock, just skip the stack guard page. */
81699- if (foll_flags & FOLL_MLOCK) {
81700- if (stack_guard_page(vma, start))
81701- goto next_page;
81702- }
81703 if (foll_flags & FOLL_WRITE)
81704 fault_flags |= FAULT_FLAG_WRITE;
81705 if (nonblocking)
81706@@ -1892,7 +1887,7 @@ next_page:
81707 start += page_increm * PAGE_SIZE;
81708 nr_pages -= page_increm;
81709 } while (nr_pages && start < vma->vm_end);
81710- } while (nr_pages);
81711+ }
81712 return i;
81713 }
81714 EXPORT_SYMBOL(__get_user_pages);
81715@@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
81716 page_add_file_rmap(page);
81717 set_pte_at(mm, addr, pte, mk_pte(page, prot));
81718
81719+#ifdef CONFIG_PAX_SEGMEXEC
81720+ pax_mirror_file_pte(vma, addr, page, ptl);
81721+#endif
81722+
81723 retval = 0;
81724 pte_unmap_unlock(pte, ptl);
81725 return retval;
81726@@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
81727 if (!page_count(page))
81728 return -EINVAL;
81729 if (!(vma->vm_flags & VM_MIXEDMAP)) {
81730+
81731+#ifdef CONFIG_PAX_SEGMEXEC
81732+ struct vm_area_struct *vma_m;
81733+#endif
81734+
81735 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
81736 BUG_ON(vma->vm_flags & VM_PFNMAP);
81737 vma->vm_flags |= VM_MIXEDMAP;
81738+
81739+#ifdef CONFIG_PAX_SEGMEXEC
81740+ vma_m = pax_find_mirror_vma(vma);
81741+ if (vma_m)
81742+ vma_m->vm_flags |= VM_MIXEDMAP;
81743+#endif
81744+
81745 }
81746 return insert_page(vma, addr, page, vma->vm_page_prot);
81747 }
81748@@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
81749 unsigned long pfn)
81750 {
81751 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
81752+ BUG_ON(vma->vm_mirror);
81753
81754 if (addr < vma->vm_start || addr >= vma->vm_end)
81755 return -EFAULT;
81756@@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
81757
81758 BUG_ON(pud_huge(*pud));
81759
81760- pmd = pmd_alloc(mm, pud, addr);
81761+ pmd = (mm == &init_mm) ?
81762+ pmd_alloc_kernel(mm, pud, addr) :
81763+ pmd_alloc(mm, pud, addr);
81764 if (!pmd)
81765 return -ENOMEM;
81766 do {
81767@@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
81768 unsigned long next;
81769 int err;
81770
81771- pud = pud_alloc(mm, pgd, addr);
81772+ pud = (mm == &init_mm) ?
81773+ pud_alloc_kernel(mm, pgd, addr) :
81774+ pud_alloc(mm, pgd, addr);
81775 if (!pud)
81776 return -ENOMEM;
81777 do {
81778@@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
81779 copy_user_highpage(dst, src, va, vma);
81780 }
81781
81782+#ifdef CONFIG_PAX_SEGMEXEC
81783+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
81784+{
81785+ struct mm_struct *mm = vma->vm_mm;
81786+ spinlock_t *ptl;
81787+ pte_t *pte, entry;
81788+
81789+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
81790+ entry = *pte;
81791+ if (!pte_present(entry)) {
81792+ if (!pte_none(entry)) {
81793+ BUG_ON(pte_file(entry));
81794+ free_swap_and_cache(pte_to_swp_entry(entry));
81795+ pte_clear_not_present_full(mm, address, pte, 0);
81796+ }
81797+ } else {
81798+ struct page *page;
81799+
81800+ flush_cache_page(vma, address, pte_pfn(entry));
81801+ entry = ptep_clear_flush(vma, address, pte);
81802+ BUG_ON(pte_dirty(entry));
81803+ page = vm_normal_page(vma, address, entry);
81804+ if (page) {
81805+ update_hiwater_rss(mm);
81806+ if (PageAnon(page))
81807+ dec_mm_counter_fast(mm, MM_ANONPAGES);
81808+ else
81809+ dec_mm_counter_fast(mm, MM_FILEPAGES);
81810+ page_remove_rmap(page);
81811+ page_cache_release(page);
81812+ }
81813+ }
81814+ pte_unmap_unlock(pte, ptl);
81815+}
81816+
81817+/* PaX: if vma is mirrored, synchronize the mirror's PTE
81818+ *
81819+ * the ptl of the lower mapped page is held on entry and is not released on exit
81820+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
81821+ */
81822+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81823+{
81824+ struct mm_struct *mm = vma->vm_mm;
81825+ unsigned long address_m;
81826+ spinlock_t *ptl_m;
81827+ struct vm_area_struct *vma_m;
81828+ pmd_t *pmd_m;
81829+ pte_t *pte_m, entry_m;
81830+
81831+ BUG_ON(!page_m || !PageAnon(page_m));
81832+
81833+ vma_m = pax_find_mirror_vma(vma);
81834+ if (!vma_m)
81835+ return;
81836+
81837+ BUG_ON(!PageLocked(page_m));
81838+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81839+ address_m = address + SEGMEXEC_TASK_SIZE;
81840+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81841+ pte_m = pte_offset_map(pmd_m, address_m);
81842+ ptl_m = pte_lockptr(mm, pmd_m);
81843+ if (ptl != ptl_m) {
81844+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81845+ if (!pte_none(*pte_m))
81846+ goto out;
81847+ }
81848+
81849+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81850+ page_cache_get(page_m);
81851+ page_add_anon_rmap(page_m, vma_m, address_m);
81852+ inc_mm_counter_fast(mm, MM_ANONPAGES);
81853+ set_pte_at(mm, address_m, pte_m, entry_m);
81854+ update_mmu_cache(vma_m, address_m, pte_m);
81855+out:
81856+ if (ptl != ptl_m)
81857+ spin_unlock(ptl_m);
81858+ pte_unmap(pte_m);
81859+ unlock_page(page_m);
81860+}
81861+
81862+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81863+{
81864+ struct mm_struct *mm = vma->vm_mm;
81865+ unsigned long address_m;
81866+ spinlock_t *ptl_m;
81867+ struct vm_area_struct *vma_m;
81868+ pmd_t *pmd_m;
81869+ pte_t *pte_m, entry_m;
81870+
81871+ BUG_ON(!page_m || PageAnon(page_m));
81872+
81873+ vma_m = pax_find_mirror_vma(vma);
81874+ if (!vma_m)
81875+ return;
81876+
81877+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81878+ address_m = address + SEGMEXEC_TASK_SIZE;
81879+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81880+ pte_m = pte_offset_map(pmd_m, address_m);
81881+ ptl_m = pte_lockptr(mm, pmd_m);
81882+ if (ptl != ptl_m) {
81883+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81884+ if (!pte_none(*pte_m))
81885+ goto out;
81886+ }
81887+
81888+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81889+ page_cache_get(page_m);
81890+ page_add_file_rmap(page_m);
81891+ inc_mm_counter_fast(mm, MM_FILEPAGES);
81892+ set_pte_at(mm, address_m, pte_m, entry_m);
81893+ update_mmu_cache(vma_m, address_m, pte_m);
81894+out:
81895+ if (ptl != ptl_m)
81896+ spin_unlock(ptl_m);
81897+ pte_unmap(pte_m);
81898+}
81899+
81900+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
81901+{
81902+ struct mm_struct *mm = vma->vm_mm;
81903+ unsigned long address_m;
81904+ spinlock_t *ptl_m;
81905+ struct vm_area_struct *vma_m;
81906+ pmd_t *pmd_m;
81907+ pte_t *pte_m, entry_m;
81908+
81909+ vma_m = pax_find_mirror_vma(vma);
81910+ if (!vma_m)
81911+ return;
81912+
81913+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81914+ address_m = address + SEGMEXEC_TASK_SIZE;
81915+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81916+ pte_m = pte_offset_map(pmd_m, address_m);
81917+ ptl_m = pte_lockptr(mm, pmd_m);
81918+ if (ptl != ptl_m) {
81919+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81920+ if (!pte_none(*pte_m))
81921+ goto out;
81922+ }
81923+
81924+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
81925+ set_pte_at(mm, address_m, pte_m, entry_m);
81926+out:
81927+ if (ptl != ptl_m)
81928+ spin_unlock(ptl_m);
81929+ pte_unmap(pte_m);
81930+}
81931+
81932+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
81933+{
81934+ struct page *page_m;
81935+ pte_t entry;
81936+
81937+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
81938+ goto out;
81939+
81940+ entry = *pte;
81941+ page_m = vm_normal_page(vma, address, entry);
81942+ if (!page_m)
81943+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
81944+ else if (PageAnon(page_m)) {
81945+ if (pax_find_mirror_vma(vma)) {
81946+ pte_unmap_unlock(pte, ptl);
81947+ lock_page(page_m);
81948+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
81949+ if (pte_same(entry, *pte))
81950+ pax_mirror_anon_pte(vma, address, page_m, ptl);
81951+ else
81952+ unlock_page(page_m);
81953+ }
81954+ } else
81955+ pax_mirror_file_pte(vma, address, page_m, ptl);
81956+
81957+out:
81958+ pte_unmap_unlock(pte, ptl);
81959+}
81960+#endif
81961+
81962 /*
81963 * This routine handles present pages, when users try to write
81964 * to a shared page. It is done by copying the page to a new address
81965@@ -2799,6 +2995,12 @@ gotten:
81966 */
81967 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81968 if (likely(pte_same(*page_table, orig_pte))) {
81969+
81970+#ifdef CONFIG_PAX_SEGMEXEC
81971+ if (pax_find_mirror_vma(vma))
81972+ BUG_ON(!trylock_page(new_page));
81973+#endif
81974+
81975 if (old_page) {
81976 if (!PageAnon(old_page)) {
81977 dec_mm_counter_fast(mm, MM_FILEPAGES);
81978@@ -2850,6 +3052,10 @@ gotten:
81979 page_remove_rmap(old_page);
81980 }
81981
81982+#ifdef CONFIG_PAX_SEGMEXEC
81983+ pax_mirror_anon_pte(vma, address, new_page, ptl);
81984+#endif
81985+
81986 /* Free the old page.. */
81987 new_page = old_page;
81988 ret |= VM_FAULT_WRITE;
81989@@ -3125,6 +3331,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81990 swap_free(entry);
81991 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
81992 try_to_free_swap(page);
81993+
81994+#ifdef CONFIG_PAX_SEGMEXEC
81995+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
81996+#endif
81997+
81998 unlock_page(page);
81999 if (page != swapcache) {
82000 /*
82001@@ -3148,6 +3359,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
82002
82003 /* No need to invalidate - it was non-present before */
82004 update_mmu_cache(vma, address, page_table);
82005+
82006+#ifdef CONFIG_PAX_SEGMEXEC
82007+ pax_mirror_anon_pte(vma, address, page, ptl);
82008+#endif
82009+
82010 unlock:
82011 pte_unmap_unlock(page_table, ptl);
82012 out:
82013@@ -3167,40 +3383,6 @@ out_release:
82014 }
82015
82016 /*
82017- * This is like a special single-page "expand_{down|up}wards()",
82018- * except we must first make sure that 'address{-|+}PAGE_SIZE'
82019- * doesn't hit another vma.
82020- */
82021-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
82022-{
82023- address &= PAGE_MASK;
82024- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
82025- struct vm_area_struct *prev = vma->vm_prev;
82026-
82027- /*
82028- * Is there a mapping abutting this one below?
82029- *
82030- * That's only ok if it's the same stack mapping
82031- * that has gotten split..
82032- */
82033- if (prev && prev->vm_end == address)
82034- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
82035-
82036- expand_downwards(vma, address - PAGE_SIZE);
82037- }
82038- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
82039- struct vm_area_struct *next = vma->vm_next;
82040-
82041- /* As VM_GROWSDOWN but s/below/above/ */
82042- if (next && next->vm_start == address + PAGE_SIZE)
82043- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
82044-
82045- expand_upwards(vma, address + PAGE_SIZE);
82046- }
82047- return 0;
82048-}
82049-
82050-/*
82051 * We enter with non-exclusive mmap_sem (to exclude vma changes,
82052 * but allow concurrent faults), and pte mapped but not yet locked.
82053 * We return with mmap_sem still held, but pte unmapped and unlocked.
82054@@ -3209,27 +3391,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
82055 unsigned long address, pte_t *page_table, pmd_t *pmd,
82056 unsigned int flags)
82057 {
82058- struct page *page;
82059+ struct page *page = NULL;
82060 spinlock_t *ptl;
82061 pte_t entry;
82062
82063- pte_unmap(page_table);
82064-
82065- /* Check if we need to add a guard page to the stack */
82066- if (check_stack_guard_page(vma, address) < 0)
82067- return VM_FAULT_SIGBUS;
82068-
82069- /* Use the zero-page for reads */
82070 if (!(flags & FAULT_FLAG_WRITE)) {
82071 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
82072 vma->vm_page_prot));
82073- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
82074+ ptl = pte_lockptr(mm, pmd);
82075+ spin_lock(ptl);
82076 if (!pte_none(*page_table))
82077 goto unlock;
82078 goto setpte;
82079 }
82080
82081 /* Allocate our own private page. */
82082+ pte_unmap(page_table);
82083+
82084 if (unlikely(anon_vma_prepare(vma)))
82085 goto oom;
82086 page = alloc_zeroed_user_highpage_movable(vma, address);
82087@@ -3253,6 +3431,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
82088 if (!pte_none(*page_table))
82089 goto release;
82090
82091+#ifdef CONFIG_PAX_SEGMEXEC
82092+ if (pax_find_mirror_vma(vma))
82093+ BUG_ON(!trylock_page(page));
82094+#endif
82095+
82096 inc_mm_counter_fast(mm, MM_ANONPAGES);
82097 page_add_new_anon_rmap(page, vma, address);
82098 setpte:
82099@@ -3260,6 +3443,12 @@ setpte:
82100
82101 /* No need to invalidate - it was non-present before */
82102 update_mmu_cache(vma, address, page_table);
82103+
82104+#ifdef CONFIG_PAX_SEGMEXEC
82105+ if (page)
82106+ pax_mirror_anon_pte(vma, address, page, ptl);
82107+#endif
82108+
82109 unlock:
82110 pte_unmap_unlock(page_table, ptl);
82111 return 0;
82112@@ -3403,6 +3592,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82113 */
82114 /* Only go through if we didn't race with anybody else... */
82115 if (likely(pte_same(*page_table, orig_pte))) {
82116+
82117+#ifdef CONFIG_PAX_SEGMEXEC
82118+ if (anon && pax_find_mirror_vma(vma))
82119+ BUG_ON(!trylock_page(page));
82120+#endif
82121+
82122 flush_icache_page(vma, page);
82123 entry = mk_pte(page, vma->vm_page_prot);
82124 if (flags & FAULT_FLAG_WRITE)
82125@@ -3422,6 +3617,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82126
82127 /* no need to invalidate: a not-present page won't be cached */
82128 update_mmu_cache(vma, address, page_table);
82129+
82130+#ifdef CONFIG_PAX_SEGMEXEC
82131+ if (anon)
82132+ pax_mirror_anon_pte(vma, address, page, ptl);
82133+ else
82134+ pax_mirror_file_pte(vma, address, page, ptl);
82135+#endif
82136+
82137 } else {
82138 if (cow_page)
82139 mem_cgroup_uncharge_page(cow_page);
82140@@ -3743,6 +3946,12 @@ int handle_pte_fault(struct mm_struct *mm,
82141 if (flags & FAULT_FLAG_WRITE)
82142 flush_tlb_fix_spurious_fault(vma, address);
82143 }
82144+
82145+#ifdef CONFIG_PAX_SEGMEXEC
82146+ pax_mirror_pte(vma, address, pte, pmd, ptl);
82147+ return 0;
82148+#endif
82149+
82150 unlock:
82151 pte_unmap_unlock(pte, ptl);
82152 return 0;
82153@@ -3759,6 +3968,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82154 pmd_t *pmd;
82155 pte_t *pte;
82156
82157+#ifdef CONFIG_PAX_SEGMEXEC
82158+ struct vm_area_struct *vma_m;
82159+#endif
82160+
82161 __set_current_state(TASK_RUNNING);
82162
82163 count_vm_event(PGFAULT);
82164@@ -3770,6 +3983,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82165 if (unlikely(is_vm_hugetlb_page(vma)))
82166 return hugetlb_fault(mm, vma, address, flags);
82167
82168+#ifdef CONFIG_PAX_SEGMEXEC
82169+ vma_m = pax_find_mirror_vma(vma);
82170+ if (vma_m) {
82171+ unsigned long address_m;
82172+ pgd_t *pgd_m;
82173+ pud_t *pud_m;
82174+ pmd_t *pmd_m;
82175+
82176+ if (vma->vm_start > vma_m->vm_start) {
82177+ address_m = address;
82178+ address -= SEGMEXEC_TASK_SIZE;
82179+ vma = vma_m;
82180+ } else
82181+ address_m = address + SEGMEXEC_TASK_SIZE;
82182+
82183+ pgd_m = pgd_offset(mm, address_m);
82184+ pud_m = pud_alloc(mm, pgd_m, address_m);
82185+ if (!pud_m)
82186+ return VM_FAULT_OOM;
82187+ pmd_m = pmd_alloc(mm, pud_m, address_m);
82188+ if (!pmd_m)
82189+ return VM_FAULT_OOM;
82190+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
82191+ return VM_FAULT_OOM;
82192+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
82193+ }
82194+#endif
82195+
82196 retry:
82197 pgd = pgd_offset(mm, address);
82198 pud = pud_alloc(mm, pgd, address);
82199@@ -3868,6 +4109,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82200 spin_unlock(&mm->page_table_lock);
82201 return 0;
82202 }
82203+
82204+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82205+{
82206+ pud_t *new = pud_alloc_one(mm, address);
82207+ if (!new)
82208+ return -ENOMEM;
82209+
82210+ smp_wmb(); /* See comment in __pte_alloc */
82211+
82212+ spin_lock(&mm->page_table_lock);
82213+ if (pgd_present(*pgd)) /* Another has populated it */
82214+ pud_free(mm, new);
82215+ else
82216+ pgd_populate_kernel(mm, pgd, new);
82217+ spin_unlock(&mm->page_table_lock);
82218+ return 0;
82219+}
82220 #endif /* __PAGETABLE_PUD_FOLDED */
82221
82222 #ifndef __PAGETABLE_PMD_FOLDED
82223@@ -3898,6 +4156,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
82224 spin_unlock(&mm->page_table_lock);
82225 return 0;
82226 }
82227+
82228+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
82229+{
82230+ pmd_t *new = pmd_alloc_one(mm, address);
82231+ if (!new)
82232+ return -ENOMEM;
82233+
82234+ smp_wmb(); /* See comment in __pte_alloc */
82235+
82236+ spin_lock(&mm->page_table_lock);
82237+#ifndef __ARCH_HAS_4LEVEL_HACK
82238+ if (pud_present(*pud)) /* Another has populated it */
82239+ pmd_free(mm, new);
82240+ else
82241+ pud_populate_kernel(mm, pud, new);
82242+#else
82243+ if (pgd_present(*pud)) /* Another has populated it */
82244+ pmd_free(mm, new);
82245+ else
82246+ pgd_populate_kernel(mm, pud, new);
82247+#endif /* __ARCH_HAS_4LEVEL_HACK */
82248+ spin_unlock(&mm->page_table_lock);
82249+ return 0;
82250+}
82251 #endif /* __PAGETABLE_PMD_FOLDED */
82252
82253 #if !defined(__HAVE_ARCH_GATE_AREA)
82254@@ -3911,7 +4193,7 @@ static int __init gate_vma_init(void)
82255 gate_vma.vm_start = FIXADDR_USER_START;
82256 gate_vma.vm_end = FIXADDR_USER_END;
82257 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
82258- gate_vma.vm_page_prot = __P101;
82259+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
82260
82261 return 0;
82262 }
82263@@ -4045,8 +4327,8 @@ out:
82264 return ret;
82265 }
82266
82267-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82268- void *buf, int len, int write)
82269+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82270+ void *buf, size_t len, int write)
82271 {
82272 resource_size_t phys_addr;
82273 unsigned long prot = 0;
82274@@ -4071,8 +4353,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82275 * Access another process' address space as given in mm. If non-NULL, use the
82276 * given task for page fault accounting.
82277 */
82278-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82279- unsigned long addr, void *buf, int len, int write)
82280+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82281+ unsigned long addr, void *buf, size_t len, int write)
82282 {
82283 struct vm_area_struct *vma;
82284 void *old_buf = buf;
82285@@ -4080,7 +4362,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82286 down_read(&mm->mmap_sem);
82287 /* ignore errors, just check how much was successfully transferred */
82288 while (len) {
82289- int bytes, ret, offset;
82290+ ssize_t bytes, ret, offset;
82291 void *maddr;
82292 struct page *page = NULL;
82293
82294@@ -4139,8 +4421,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82295 *
82296 * The caller must hold a reference on @mm.
82297 */
82298-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82299- void *buf, int len, int write)
82300+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
82301+ void *buf, size_t len, int write)
82302 {
82303 return __access_remote_vm(NULL, mm, addr, buf, len, write);
82304 }
82305@@ -4150,11 +4432,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82306 * Source/target buffer must be kernel space,
82307 * Do not walk the page table directly, use get_user_pages
82308 */
82309-int access_process_vm(struct task_struct *tsk, unsigned long addr,
82310- void *buf, int len, int write)
82311+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
82312+ void *buf, size_t len, int write)
82313 {
82314 struct mm_struct *mm;
82315- int ret;
82316+ ssize_t ret;
82317
82318 mm = get_task_mm(tsk);
82319 if (!mm)
82320diff --git a/mm/mempolicy.c b/mm/mempolicy.c
82321index 7431001..0f8344e 100644
82322--- a/mm/mempolicy.c
82323+++ b/mm/mempolicy.c
82324@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82325 unsigned long vmstart;
82326 unsigned long vmend;
82327
82328+#ifdef CONFIG_PAX_SEGMEXEC
82329+ struct vm_area_struct *vma_m;
82330+#endif
82331+
82332 vma = find_vma(mm, start);
82333 if (!vma || vma->vm_start > start)
82334 return -EFAULT;
82335@@ -744,9 +748,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82336 if (err)
82337 goto out;
82338 }
82339+
82340 err = vma_replace_policy(vma, new_pol);
82341 if (err)
82342 goto out;
82343+
82344+#ifdef CONFIG_PAX_SEGMEXEC
82345+ vma_m = pax_find_mirror_vma(vma);
82346+ if (vma_m) {
82347+ err = vma_replace_policy(vma_m, new_pol);
82348+ if (err)
82349+ goto out;
82350+ }
82351+#endif
82352+
82353 }
82354
82355 out:
82356@@ -1202,6 +1217,17 @@ static long do_mbind(unsigned long start, unsigned long len,
82357
82358 if (end < start)
82359 return -EINVAL;
82360+
82361+#ifdef CONFIG_PAX_SEGMEXEC
82362+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82363+ if (end > SEGMEXEC_TASK_SIZE)
82364+ return -EINVAL;
82365+ } else
82366+#endif
82367+
82368+ if (end > TASK_SIZE)
82369+ return -EINVAL;
82370+
82371 if (end == start)
82372 return 0;
82373
82374@@ -1430,8 +1456,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82375 */
82376 tcred = __task_cred(task);
82377 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82378- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82379- !capable(CAP_SYS_NICE)) {
82380+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82381 rcu_read_unlock();
82382 err = -EPERM;
82383 goto out_put;
82384@@ -1462,6 +1487,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82385 goto out;
82386 }
82387
82388+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82389+ if (mm != current->mm &&
82390+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
82391+ mmput(mm);
82392+ err = -EPERM;
82393+ goto out;
82394+ }
82395+#endif
82396+
82397 err = do_migrate_pages(mm, old, new,
82398 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
82399
82400diff --git a/mm/migrate.c b/mm/migrate.c
82401index 6f0c244..6d1ae32 100644
82402--- a/mm/migrate.c
82403+++ b/mm/migrate.c
82404@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
82405 */
82406 tcred = __task_cred(task);
82407 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82408- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82409- !capable(CAP_SYS_NICE)) {
82410+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82411 rcu_read_unlock();
82412 err = -EPERM;
82413 goto out;
82414diff --git a/mm/mlock.c b/mm/mlock.c
82415index 79b7cf7..9944291 100644
82416--- a/mm/mlock.c
82417+++ b/mm/mlock.c
82418@@ -13,6 +13,7 @@
82419 #include <linux/pagemap.h>
82420 #include <linux/mempolicy.h>
82421 #include <linux/syscalls.h>
82422+#include <linux/security.h>
82423 #include <linux/sched.h>
82424 #include <linux/export.h>
82425 #include <linux/rmap.h>
82426@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
82427 {
82428 unsigned long nstart, end, tmp;
82429 struct vm_area_struct * vma, * prev;
82430- int error;
82431+ int error = 0;
82432
82433 VM_BUG_ON(start & ~PAGE_MASK);
82434 VM_BUG_ON(len != PAGE_ALIGN(len));
82435@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
82436 return -EINVAL;
82437 if (end == start)
82438 return 0;
82439+ if (end > TASK_SIZE)
82440+ return -EINVAL;
82441+
82442 vma = find_vma(current->mm, start);
82443 if (!vma || vma->vm_start > start)
82444 return -ENOMEM;
82445@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
82446 for (nstart = start ; ; ) {
82447 vm_flags_t newflags;
82448
82449+#ifdef CONFIG_PAX_SEGMEXEC
82450+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82451+ break;
82452+#endif
82453+
82454 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
82455
82456 newflags = vma->vm_flags & ~VM_LOCKED;
82457@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
82458 lock_limit >>= PAGE_SHIFT;
82459
82460 /* check against resource limits */
82461+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
82462 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
82463 error = do_mlock(start, len, 1);
82464 up_write(&current->mm->mmap_sem);
82465@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
82466 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
82467 vm_flags_t newflags;
82468
82469+#ifdef CONFIG_PAX_SEGMEXEC
82470+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82471+ break;
82472+#endif
82473+
82474 newflags = vma->vm_flags & ~VM_LOCKED;
82475 if (flags & MCL_CURRENT)
82476 newflags |= VM_LOCKED;
82477@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
82478 lock_limit >>= PAGE_SHIFT;
82479
82480 ret = -ENOMEM;
82481+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
82482 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
82483 capable(CAP_IPC_LOCK))
82484 ret = do_mlockall(flags);
82485diff --git a/mm/mmap.c b/mm/mmap.c
82486index f681e18..4c2577f 100644
82487--- a/mm/mmap.c
82488+++ b/mm/mmap.c
82489@@ -36,6 +36,7 @@
82490 #include <linux/sched/sysctl.h>
82491 #include <linux/notifier.h>
82492 #include <linux/memory.h>
82493+#include <linux/random.h>
82494
82495 #include <asm/uaccess.h>
82496 #include <asm/cacheflush.h>
82497@@ -52,6 +53,16 @@
82498 #define arch_rebalance_pgtables(addr, len) (addr)
82499 #endif
82500
82501+static inline void verify_mm_writelocked(struct mm_struct *mm)
82502+{
82503+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
82504+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82505+ up_read(&mm->mmap_sem);
82506+ BUG();
82507+ }
82508+#endif
82509+}
82510+
82511 static void unmap_region(struct mm_struct *mm,
82512 struct vm_area_struct *vma, struct vm_area_struct *prev,
82513 unsigned long start, unsigned long end);
82514@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
82515 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
82516 *
82517 */
82518-pgprot_t protection_map[16] = {
82519+pgprot_t protection_map[16] __read_only = {
82520 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
82521 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
82522 };
82523
82524-pgprot_t vm_get_page_prot(unsigned long vm_flags)
82525+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
82526 {
82527- return __pgprot(pgprot_val(protection_map[vm_flags &
82528+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
82529 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
82530 pgprot_val(arch_vm_get_page_prot(vm_flags)));
82531+
82532+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82533+ if (!(__supported_pte_mask & _PAGE_NX) &&
82534+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
82535+ (vm_flags & (VM_READ | VM_WRITE)))
82536+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
82537+#endif
82538+
82539+ return prot;
82540 }
82541 EXPORT_SYMBOL(vm_get_page_prot);
82542
82543@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
82544 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
82545 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
82546 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
82547+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
82548 /*
82549 * Make sure vm_committed_as in one cacheline and not cacheline shared with
82550 * other variables. It can be updated by several CPUs frequently.
82551@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
82552 struct vm_area_struct *next = vma->vm_next;
82553
82554 might_sleep();
82555+ BUG_ON(vma->vm_mirror);
82556 if (vma->vm_ops && vma->vm_ops->close)
82557 vma->vm_ops->close(vma);
82558 if (vma->vm_file)
82559@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
82560 * not page aligned -Ram Gupta
82561 */
82562 rlim = rlimit(RLIMIT_DATA);
82563+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
82564 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
82565 (mm->end_data - mm->start_data) > rlim)
82566 goto out;
82567@@ -933,6 +956,12 @@ static int
82568 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
82569 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82570 {
82571+
82572+#ifdef CONFIG_PAX_SEGMEXEC
82573+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
82574+ return 0;
82575+#endif
82576+
82577 if (is_mergeable_vma(vma, file, vm_flags) &&
82578 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82579 if (vma->vm_pgoff == vm_pgoff)
82580@@ -952,6 +981,12 @@ static int
82581 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82582 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82583 {
82584+
82585+#ifdef CONFIG_PAX_SEGMEXEC
82586+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
82587+ return 0;
82588+#endif
82589+
82590 if (is_mergeable_vma(vma, file, vm_flags) &&
82591 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82592 pgoff_t vm_pglen;
82593@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82594 struct vm_area_struct *vma_merge(struct mm_struct *mm,
82595 struct vm_area_struct *prev, unsigned long addr,
82596 unsigned long end, unsigned long vm_flags,
82597- struct anon_vma *anon_vma, struct file *file,
82598+ struct anon_vma *anon_vma, struct file *file,
82599 pgoff_t pgoff, struct mempolicy *policy)
82600 {
82601 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
82602 struct vm_area_struct *area, *next;
82603 int err;
82604
82605+#ifdef CONFIG_PAX_SEGMEXEC
82606+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
82607+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
82608+
82609+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
82610+#endif
82611+
82612 /*
82613 * We later require that vma->vm_flags == vm_flags,
82614 * so this tests vma->vm_flags & VM_SPECIAL, too.
82615@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82616 if (next && next->vm_end == end) /* cases 6, 7, 8 */
82617 next = next->vm_next;
82618
82619+#ifdef CONFIG_PAX_SEGMEXEC
82620+ if (prev)
82621+ prev_m = pax_find_mirror_vma(prev);
82622+ if (area)
82623+ area_m = pax_find_mirror_vma(area);
82624+ if (next)
82625+ next_m = pax_find_mirror_vma(next);
82626+#endif
82627+
82628 /*
82629 * Can it merge with the predecessor?
82630 */
82631@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82632 /* cases 1, 6 */
82633 err = vma_adjust(prev, prev->vm_start,
82634 next->vm_end, prev->vm_pgoff, NULL);
82635- } else /* cases 2, 5, 7 */
82636+
82637+#ifdef CONFIG_PAX_SEGMEXEC
82638+ if (!err && prev_m)
82639+ err = vma_adjust(prev_m, prev_m->vm_start,
82640+ next_m->vm_end, prev_m->vm_pgoff, NULL);
82641+#endif
82642+
82643+ } else { /* cases 2, 5, 7 */
82644 err = vma_adjust(prev, prev->vm_start,
82645 end, prev->vm_pgoff, NULL);
82646+
82647+#ifdef CONFIG_PAX_SEGMEXEC
82648+ if (!err && prev_m)
82649+ err = vma_adjust(prev_m, prev_m->vm_start,
82650+ end_m, prev_m->vm_pgoff, NULL);
82651+#endif
82652+
82653+ }
82654 if (err)
82655 return NULL;
82656 khugepaged_enter_vma_merge(prev);
82657@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82658 mpol_equal(policy, vma_policy(next)) &&
82659 can_vma_merge_before(next, vm_flags,
82660 anon_vma, file, pgoff+pglen)) {
82661- if (prev && addr < prev->vm_end) /* case 4 */
82662+ if (prev && addr < prev->vm_end) { /* case 4 */
82663 err = vma_adjust(prev, prev->vm_start,
82664 addr, prev->vm_pgoff, NULL);
82665- else /* cases 3, 8 */
82666+
82667+#ifdef CONFIG_PAX_SEGMEXEC
82668+ if (!err && prev_m)
82669+ err = vma_adjust(prev_m, prev_m->vm_start,
82670+ addr_m, prev_m->vm_pgoff, NULL);
82671+#endif
82672+
82673+ } else { /* cases 3, 8 */
82674 err = vma_adjust(area, addr, next->vm_end,
82675 next->vm_pgoff - pglen, NULL);
82676+
82677+#ifdef CONFIG_PAX_SEGMEXEC
82678+ if (!err && area_m)
82679+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
82680+ next_m->vm_pgoff - pglen, NULL);
82681+#endif
82682+
82683+ }
82684 if (err)
82685 return NULL;
82686 khugepaged_enter_vma_merge(area);
82687@@ -1165,8 +1246,10 @@ none:
82688 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82689 struct file *file, long pages)
82690 {
82691- const unsigned long stack_flags
82692- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
82693+
82694+#ifdef CONFIG_PAX_RANDMMAP
82695+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82696+#endif
82697
82698 mm->total_vm += pages;
82699
82700@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82701 mm->shared_vm += pages;
82702 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
82703 mm->exec_vm += pages;
82704- } else if (flags & stack_flags)
82705+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
82706 mm->stack_vm += pages;
82707 }
82708 #endif /* CONFIG_PROC_FS */
82709@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82710 * (the exception is when the underlying filesystem is noexec
82711 * mounted, in which case we dont add PROT_EXEC.)
82712 */
82713- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82714+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82715 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
82716 prot |= PROT_EXEC;
82717
82718@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82719 /* Obtain the address to map to. we verify (or select) it and ensure
82720 * that it represents a valid section of the address space.
82721 */
82722- addr = get_unmapped_area(file, addr, len, pgoff, flags);
82723+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
82724 if (addr & ~PAGE_MASK)
82725 return addr;
82726
82727@@ -1250,6 +1333,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82728 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
82729 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
82730
82731+#ifdef CONFIG_PAX_MPROTECT
82732+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82733+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82734+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
82735+ gr_log_rwxmmap(file);
82736+
82737+#ifdef CONFIG_PAX_EMUPLT
82738+ vm_flags &= ~VM_EXEC;
82739+#else
82740+ return -EPERM;
82741+#endif
82742+
82743+ }
82744+
82745+ if (!(vm_flags & VM_EXEC))
82746+ vm_flags &= ~VM_MAYEXEC;
82747+#else
82748+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82749+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82750+#endif
82751+ else
82752+ vm_flags &= ~VM_MAYWRITE;
82753+ }
82754+#endif
82755+
82756+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82757+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
82758+ vm_flags &= ~VM_PAGEEXEC;
82759+#endif
82760+
82761 if (flags & MAP_LOCKED)
82762 if (!can_do_mlock())
82763 return -EPERM;
82764@@ -1261,6 +1374,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82765 locked += mm->locked_vm;
82766 lock_limit = rlimit(RLIMIT_MEMLOCK);
82767 lock_limit >>= PAGE_SHIFT;
82768+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82769 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
82770 return -EAGAIN;
82771 }
82772@@ -1341,6 +1455,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82773 vm_flags |= VM_NORESERVE;
82774 }
82775
82776+ if (!gr_acl_handle_mmap(file, prot))
82777+ return -EACCES;
82778+
82779 addr = mmap_region(file, addr, len, vm_flags, pgoff);
82780 if (!IS_ERR_VALUE(addr) &&
82781 ((vm_flags & VM_LOCKED) ||
82782@@ -1432,7 +1549,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
82783 vm_flags_t vm_flags = vma->vm_flags;
82784
82785 /* If it was private or non-writable, the write bit is already clear */
82786- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
82787+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
82788 return 0;
82789
82790 /* The backer wishes to know when pages are first written to? */
82791@@ -1480,7 +1597,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82792 unsigned long charged = 0;
82793 struct inode *inode = file ? file_inode(file) : NULL;
82794
82795+#ifdef CONFIG_PAX_SEGMEXEC
82796+ struct vm_area_struct *vma_m = NULL;
82797+#endif
82798+
82799+ /*
82800+ * mm->mmap_sem is required to protect against another thread
82801+ * changing the mappings in case we sleep.
82802+ */
82803+ verify_mm_writelocked(mm);
82804+
82805 /* Check against address space limit. */
82806+
82807+#ifdef CONFIG_PAX_RANDMMAP
82808+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82809+#endif
82810+
82811 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
82812 unsigned long nr_pages;
82813
82814@@ -1499,11 +1631,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82815
82816 /* Clear old maps */
82817 error = -ENOMEM;
82818-munmap_back:
82819 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82820 if (do_munmap(mm, addr, len))
82821 return -ENOMEM;
82822- goto munmap_back;
82823+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82824 }
82825
82826 /*
82827@@ -1534,6 +1665,16 @@ munmap_back:
82828 goto unacct_error;
82829 }
82830
82831+#ifdef CONFIG_PAX_SEGMEXEC
82832+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
82833+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82834+ if (!vma_m) {
82835+ error = -ENOMEM;
82836+ goto free_vma;
82837+ }
82838+ }
82839+#endif
82840+
82841 vma->vm_mm = mm;
82842 vma->vm_start = addr;
82843 vma->vm_end = addr + len;
82844@@ -1558,6 +1699,13 @@ munmap_back:
82845 if (error)
82846 goto unmap_and_free_vma;
82847
82848+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82849+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
82850+ vma->vm_flags |= VM_PAGEEXEC;
82851+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82852+ }
82853+#endif
82854+
82855 /* Can addr have changed??
82856 *
82857 * Answer: Yes, several device drivers can do it in their
82858@@ -1596,6 +1744,11 @@ munmap_back:
82859 vma_link(mm, vma, prev, rb_link, rb_parent);
82860 file = vma->vm_file;
82861
82862+#ifdef CONFIG_PAX_SEGMEXEC
82863+ if (vma_m)
82864+ BUG_ON(pax_mirror_vma(vma_m, vma));
82865+#endif
82866+
82867 /* Once vma denies write, undo our temporary denial count */
82868 if (correct_wcount)
82869 atomic_inc(&inode->i_writecount);
82870@@ -1603,6 +1756,7 @@ out:
82871 perf_event_mmap(vma);
82872
82873 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
82874+ track_exec_limit(mm, addr, addr + len, vm_flags);
82875 if (vm_flags & VM_LOCKED) {
82876 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
82877 vma == get_gate_vma(current->mm)))
82878@@ -1626,6 +1780,12 @@ unmap_and_free_vma:
82879 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
82880 charged = 0;
82881 free_vma:
82882+
82883+#ifdef CONFIG_PAX_SEGMEXEC
82884+ if (vma_m)
82885+ kmem_cache_free(vm_area_cachep, vma_m);
82886+#endif
82887+
82888 kmem_cache_free(vm_area_cachep, vma);
82889 unacct_error:
82890 if (charged)
82891@@ -1633,7 +1793,63 @@ unacct_error:
82892 return error;
82893 }
82894
82895-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82896+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82897+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82898+{
82899+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
82900+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
82901+
82902+ return 0;
82903+}
82904+#endif
82905+
82906+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
82907+{
82908+ if (!vma) {
82909+#ifdef CONFIG_STACK_GROWSUP
82910+ if (addr > sysctl_heap_stack_gap)
82911+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
82912+ else
82913+ vma = find_vma(current->mm, 0);
82914+ if (vma && (vma->vm_flags & VM_GROWSUP))
82915+ return false;
82916+#endif
82917+ return true;
82918+ }
82919+
82920+ if (addr + len > vma->vm_start)
82921+ return false;
82922+
82923+ if (vma->vm_flags & VM_GROWSDOWN)
82924+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
82925+#ifdef CONFIG_STACK_GROWSUP
82926+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
82927+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
82928+#endif
82929+ else if (offset)
82930+ return offset <= vma->vm_start - addr - len;
82931+
82932+ return true;
82933+}
82934+
82935+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
82936+{
82937+ if (vma->vm_start < len)
82938+ return -ENOMEM;
82939+
82940+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
82941+ if (offset <= vma->vm_start - len)
82942+ return vma->vm_start - len - offset;
82943+ else
82944+ return -ENOMEM;
82945+ }
82946+
82947+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
82948+ return vma->vm_start - len - sysctl_heap_stack_gap;
82949+ return -ENOMEM;
82950+}
82951+
82952+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
82953 {
82954 /*
82955 * We implement the search by looking for an rbtree node that
82956@@ -1681,11 +1897,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82957 }
82958 }
82959
82960- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
82961+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
82962 check_current:
82963 /* Check if current node has a suitable gap */
82964 if (gap_start > high_limit)
82965 return -ENOMEM;
82966+
82967+ if (gap_end - gap_start > info->threadstack_offset)
82968+ gap_start += info->threadstack_offset;
82969+ else
82970+ gap_start = gap_end;
82971+
82972+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
82973+ if (gap_end - gap_start > sysctl_heap_stack_gap)
82974+ gap_start += sysctl_heap_stack_gap;
82975+ else
82976+ gap_start = gap_end;
82977+ }
82978+ if (vma->vm_flags & VM_GROWSDOWN) {
82979+ if (gap_end - gap_start > sysctl_heap_stack_gap)
82980+ gap_end -= sysctl_heap_stack_gap;
82981+ else
82982+ gap_end = gap_start;
82983+ }
82984 if (gap_end >= low_limit && gap_end - gap_start >= length)
82985 goto found;
82986
82987@@ -1735,7 +1969,7 @@ found:
82988 return gap_start;
82989 }
82990
82991-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
82992+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
82993 {
82994 struct mm_struct *mm = current->mm;
82995 struct vm_area_struct *vma;
82996@@ -1789,6 +2023,24 @@ check_current:
82997 gap_end = vma->vm_start;
82998 if (gap_end < low_limit)
82999 return -ENOMEM;
83000+
83001+ if (gap_end - gap_start > info->threadstack_offset)
83002+ gap_end -= info->threadstack_offset;
83003+ else
83004+ gap_end = gap_start;
83005+
83006+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
83007+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83008+ gap_start += sysctl_heap_stack_gap;
83009+ else
83010+ gap_start = gap_end;
83011+ }
83012+ if (vma->vm_flags & VM_GROWSDOWN) {
83013+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83014+ gap_end -= sysctl_heap_stack_gap;
83015+ else
83016+ gap_end = gap_start;
83017+ }
83018 if (gap_start <= high_limit && gap_end - gap_start >= length)
83019 goto found;
83020
83021@@ -1852,6 +2104,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
83022 struct mm_struct *mm = current->mm;
83023 struct vm_area_struct *vma;
83024 struct vm_unmapped_area_info info;
83025+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
83026
83027 if (len > TASK_SIZE)
83028 return -ENOMEM;
83029@@ -1859,29 +2112,45 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
83030 if (flags & MAP_FIXED)
83031 return addr;
83032
83033+#ifdef CONFIG_PAX_RANDMMAP
83034+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
83035+#endif
83036+
83037 if (addr) {
83038 addr = PAGE_ALIGN(addr);
83039 vma = find_vma(mm, addr);
83040- if (TASK_SIZE - len >= addr &&
83041- (!vma || addr + len <= vma->vm_start))
83042+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
83043 return addr;
83044 }
83045
83046 info.flags = 0;
83047 info.length = len;
83048 info.low_limit = TASK_UNMAPPED_BASE;
83049+
83050+#ifdef CONFIG_PAX_RANDMMAP
83051+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83052+ info.low_limit += mm->delta_mmap;
83053+#endif
83054+
83055 info.high_limit = TASK_SIZE;
83056 info.align_mask = 0;
83057+ info.threadstack_offset = offset;
83058 return vm_unmapped_area(&info);
83059 }
83060 #endif
83061
83062 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
83063 {
83064+
83065+#ifdef CONFIG_PAX_SEGMEXEC
83066+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
83067+ return;
83068+#endif
83069+
83070 /*
83071 * Is this a new hole at the lowest possible address?
83072 */
83073- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
83074+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
83075 mm->free_area_cache = addr;
83076 }
83077
83078@@ -1899,6 +2168,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83079 struct mm_struct *mm = current->mm;
83080 unsigned long addr = addr0;
83081 struct vm_unmapped_area_info info;
83082+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
83083
83084 /* requested length too big for entire address space */
83085 if (len > TASK_SIZE)
83086@@ -1907,12 +2177,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83087 if (flags & MAP_FIXED)
83088 return addr;
83089
83090+#ifdef CONFIG_PAX_RANDMMAP
83091+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
83092+#endif
83093+
83094 /* requesting a specific address */
83095 if (addr) {
83096 addr = PAGE_ALIGN(addr);
83097 vma = find_vma(mm, addr);
83098- if (TASK_SIZE - len >= addr &&
83099- (!vma || addr + len <= vma->vm_start))
83100+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
83101 return addr;
83102 }
83103
83104@@ -1921,6 +2194,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83105 info.low_limit = PAGE_SIZE;
83106 info.high_limit = mm->mmap_base;
83107 info.align_mask = 0;
83108+ info.threadstack_offset = offset;
83109 addr = vm_unmapped_area(&info);
83110
83111 /*
83112@@ -1933,6 +2207,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83113 VM_BUG_ON(addr != -ENOMEM);
83114 info.flags = 0;
83115 info.low_limit = TASK_UNMAPPED_BASE;
83116+
83117+#ifdef CONFIG_PAX_RANDMMAP
83118+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83119+ info.low_limit += mm->delta_mmap;
83120+#endif
83121+
83122 info.high_limit = TASK_SIZE;
83123 addr = vm_unmapped_area(&info);
83124 }
83125@@ -1943,6 +2223,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83126
83127 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
83128 {
83129+
83130+#ifdef CONFIG_PAX_SEGMEXEC
83131+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
83132+ return;
83133+#endif
83134+
83135 /*
83136 * Is this a new hole at the highest possible address?
83137 */
83138@@ -1950,8 +2236,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
83139 mm->free_area_cache = addr;
83140
83141 /* dont allow allocations above current base */
83142- if (mm->free_area_cache > mm->mmap_base)
83143+ if (mm->free_area_cache > mm->mmap_base) {
83144 mm->free_area_cache = mm->mmap_base;
83145+ mm->cached_hole_size = ~0UL;
83146+ }
83147 }
83148
83149 unsigned long
83150@@ -2047,6 +2335,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
83151 return vma;
83152 }
83153
83154+#ifdef CONFIG_PAX_SEGMEXEC
83155+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
83156+{
83157+ struct vm_area_struct *vma_m;
83158+
83159+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
83160+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
83161+ BUG_ON(vma->vm_mirror);
83162+ return NULL;
83163+ }
83164+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
83165+ vma_m = vma->vm_mirror;
83166+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
83167+ BUG_ON(vma->vm_file != vma_m->vm_file);
83168+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
83169+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
83170+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
83171+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
83172+ return vma_m;
83173+}
83174+#endif
83175+
83176 /*
83177 * Verify that the stack growth is acceptable and
83178 * update accounting. This is shared with both the
83179@@ -2063,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83180 return -ENOMEM;
83181
83182 /* Stack limit test */
83183+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
83184 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
83185 return -ENOMEM;
83186
83187@@ -2073,6 +2384,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83188 locked = mm->locked_vm + grow;
83189 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
83190 limit >>= PAGE_SHIFT;
83191+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
83192 if (locked > limit && !capable(CAP_IPC_LOCK))
83193 return -ENOMEM;
83194 }
83195@@ -2102,37 +2414,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83196 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
83197 * vma is the last one with address > vma->vm_end. Have to extend vma.
83198 */
83199+#ifndef CONFIG_IA64
83200+static
83201+#endif
83202 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83203 {
83204 int error;
83205+ bool locknext;
83206
83207 if (!(vma->vm_flags & VM_GROWSUP))
83208 return -EFAULT;
83209
83210+ /* Also guard against wrapping around to address 0. */
83211+ if (address < PAGE_ALIGN(address+1))
83212+ address = PAGE_ALIGN(address+1);
83213+ else
83214+ return -ENOMEM;
83215+
83216 /*
83217 * We must make sure the anon_vma is allocated
83218 * so that the anon_vma locking is not a noop.
83219 */
83220 if (unlikely(anon_vma_prepare(vma)))
83221 return -ENOMEM;
83222+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
83223+ if (locknext && anon_vma_prepare(vma->vm_next))
83224+ return -ENOMEM;
83225 vma_lock_anon_vma(vma);
83226+ if (locknext)
83227+ vma_lock_anon_vma(vma->vm_next);
83228
83229 /*
83230 * vma->vm_start/vm_end cannot change under us because the caller
83231 * is required to hold the mmap_sem in read mode. We need the
83232- * anon_vma lock to serialize against concurrent expand_stacks.
83233- * Also guard against wrapping around to address 0.
83234+ * anon_vma locks to serialize against concurrent expand_stacks
83235+ * and expand_upwards.
83236 */
83237- if (address < PAGE_ALIGN(address+4))
83238- address = PAGE_ALIGN(address+4);
83239- else {
83240- vma_unlock_anon_vma(vma);
83241- return -ENOMEM;
83242- }
83243 error = 0;
83244
83245 /* Somebody else might have raced and expanded it already */
83246- if (address > vma->vm_end) {
83247+ 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)
83248+ error = -ENOMEM;
83249+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
83250 unsigned long size, grow;
83251
83252 size = address - vma->vm_start;
83253@@ -2167,6 +2490,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83254 }
83255 }
83256 }
83257+ if (locknext)
83258+ vma_unlock_anon_vma(vma->vm_next);
83259 vma_unlock_anon_vma(vma);
83260 khugepaged_enter_vma_merge(vma);
83261 validate_mm(vma->vm_mm);
83262@@ -2181,6 +2506,8 @@ int expand_downwards(struct vm_area_struct *vma,
83263 unsigned long address)
83264 {
83265 int error;
83266+ bool lockprev = false;
83267+ struct vm_area_struct *prev;
83268
83269 /*
83270 * We must make sure the anon_vma is allocated
83271@@ -2194,6 +2521,15 @@ int expand_downwards(struct vm_area_struct *vma,
83272 if (error)
83273 return error;
83274
83275+ prev = vma->vm_prev;
83276+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
83277+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
83278+#endif
83279+ if (lockprev && anon_vma_prepare(prev))
83280+ return -ENOMEM;
83281+ if (lockprev)
83282+ vma_lock_anon_vma(prev);
83283+
83284 vma_lock_anon_vma(vma);
83285
83286 /*
83287@@ -2203,9 +2539,17 @@ int expand_downwards(struct vm_area_struct *vma,
83288 */
83289
83290 /* Somebody else might have raced and expanded it already */
83291- if (address < vma->vm_start) {
83292+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
83293+ error = -ENOMEM;
83294+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
83295 unsigned long size, grow;
83296
83297+#ifdef CONFIG_PAX_SEGMEXEC
83298+ struct vm_area_struct *vma_m;
83299+
83300+ vma_m = pax_find_mirror_vma(vma);
83301+#endif
83302+
83303 size = vma->vm_end - address;
83304 grow = (vma->vm_start - address) >> PAGE_SHIFT;
83305
83306@@ -2230,13 +2574,27 @@ int expand_downwards(struct vm_area_struct *vma,
83307 vma->vm_pgoff -= grow;
83308 anon_vma_interval_tree_post_update_vma(vma);
83309 vma_gap_update(vma);
83310+
83311+#ifdef CONFIG_PAX_SEGMEXEC
83312+ if (vma_m) {
83313+ anon_vma_interval_tree_pre_update_vma(vma_m);
83314+ vma_m->vm_start -= grow << PAGE_SHIFT;
83315+ vma_m->vm_pgoff -= grow;
83316+ anon_vma_interval_tree_post_update_vma(vma_m);
83317+ vma_gap_update(vma_m);
83318+ }
83319+#endif
83320+
83321 spin_unlock(&vma->vm_mm->page_table_lock);
83322
83323+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
83324 perf_event_mmap(vma);
83325 }
83326 }
83327 }
83328 vma_unlock_anon_vma(vma);
83329+ if (lockprev)
83330+ vma_unlock_anon_vma(prev);
83331 khugepaged_enter_vma_merge(vma);
83332 validate_mm(vma->vm_mm);
83333 return error;
83334@@ -2334,6 +2692,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
83335 do {
83336 long nrpages = vma_pages(vma);
83337
83338+#ifdef CONFIG_PAX_SEGMEXEC
83339+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
83340+ vma = remove_vma(vma);
83341+ continue;
83342+ }
83343+#endif
83344+
83345 if (vma->vm_flags & VM_ACCOUNT)
83346 nr_accounted += nrpages;
83347 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
83348@@ -2379,6 +2744,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
83349 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
83350 vma->vm_prev = NULL;
83351 do {
83352+
83353+#ifdef CONFIG_PAX_SEGMEXEC
83354+ if (vma->vm_mirror) {
83355+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
83356+ vma->vm_mirror->vm_mirror = NULL;
83357+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
83358+ vma->vm_mirror = NULL;
83359+ }
83360+#endif
83361+
83362 vma_rb_erase(vma, &mm->mm_rb);
83363 mm->map_count--;
83364 tail_vma = vma;
83365@@ -2410,14 +2785,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83366 struct vm_area_struct *new;
83367 int err = -ENOMEM;
83368
83369+#ifdef CONFIG_PAX_SEGMEXEC
83370+ struct vm_area_struct *vma_m, *new_m = NULL;
83371+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
83372+#endif
83373+
83374 if (is_vm_hugetlb_page(vma) && (addr &
83375 ~(huge_page_mask(hstate_vma(vma)))))
83376 return -EINVAL;
83377
83378+#ifdef CONFIG_PAX_SEGMEXEC
83379+ vma_m = pax_find_mirror_vma(vma);
83380+#endif
83381+
83382 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
83383 if (!new)
83384 goto out_err;
83385
83386+#ifdef CONFIG_PAX_SEGMEXEC
83387+ if (vma_m) {
83388+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
83389+ if (!new_m) {
83390+ kmem_cache_free(vm_area_cachep, new);
83391+ goto out_err;
83392+ }
83393+ }
83394+#endif
83395+
83396 /* most fields are the same, copy all, and then fixup */
83397 *new = *vma;
83398
83399@@ -2430,6 +2824,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83400 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
83401 }
83402
83403+#ifdef CONFIG_PAX_SEGMEXEC
83404+ if (vma_m) {
83405+ *new_m = *vma_m;
83406+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
83407+ new_m->vm_mirror = new;
83408+ new->vm_mirror = new_m;
83409+
83410+ if (new_below)
83411+ new_m->vm_end = addr_m;
83412+ else {
83413+ new_m->vm_start = addr_m;
83414+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
83415+ }
83416+ }
83417+#endif
83418+
83419 pol = mpol_dup(vma_policy(vma));
83420 if (IS_ERR(pol)) {
83421 err = PTR_ERR(pol);
83422@@ -2452,6 +2862,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83423 else
83424 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
83425
83426+#ifdef CONFIG_PAX_SEGMEXEC
83427+ if (!err && vma_m) {
83428+ if (anon_vma_clone(new_m, vma_m))
83429+ goto out_free_mpol;
83430+
83431+ mpol_get(pol);
83432+ vma_set_policy(new_m, pol);
83433+
83434+ if (new_m->vm_file)
83435+ get_file(new_m->vm_file);
83436+
83437+ if (new_m->vm_ops && new_m->vm_ops->open)
83438+ new_m->vm_ops->open(new_m);
83439+
83440+ if (new_below)
83441+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
83442+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
83443+ else
83444+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
83445+
83446+ if (err) {
83447+ if (new_m->vm_ops && new_m->vm_ops->close)
83448+ new_m->vm_ops->close(new_m);
83449+ if (new_m->vm_file)
83450+ fput(new_m->vm_file);
83451+ mpol_put(pol);
83452+ }
83453+ }
83454+#endif
83455+
83456 /* Success. */
83457 if (!err)
83458 return 0;
83459@@ -2461,10 +2901,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83460 new->vm_ops->close(new);
83461 if (new->vm_file)
83462 fput(new->vm_file);
83463- unlink_anon_vmas(new);
83464 out_free_mpol:
83465 mpol_put(pol);
83466 out_free_vma:
83467+
83468+#ifdef CONFIG_PAX_SEGMEXEC
83469+ if (new_m) {
83470+ unlink_anon_vmas(new_m);
83471+ kmem_cache_free(vm_area_cachep, new_m);
83472+ }
83473+#endif
83474+
83475+ unlink_anon_vmas(new);
83476 kmem_cache_free(vm_area_cachep, new);
83477 out_err:
83478 return err;
83479@@ -2477,6 +2925,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83480 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83481 unsigned long addr, int new_below)
83482 {
83483+
83484+#ifdef CONFIG_PAX_SEGMEXEC
83485+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
83486+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
83487+ if (mm->map_count >= sysctl_max_map_count-1)
83488+ return -ENOMEM;
83489+ } else
83490+#endif
83491+
83492 if (mm->map_count >= sysctl_max_map_count)
83493 return -ENOMEM;
83494
83495@@ -2488,11 +2945,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83496 * work. This now handles partial unmappings.
83497 * Jeremy Fitzhardinge <jeremy@goop.org>
83498 */
83499+#ifdef CONFIG_PAX_SEGMEXEC
83500 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83501 {
83502+ int ret = __do_munmap(mm, start, len);
83503+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
83504+ return ret;
83505+
83506+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
83507+}
83508+
83509+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83510+#else
83511+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83512+#endif
83513+{
83514 unsigned long end;
83515 struct vm_area_struct *vma, *prev, *last;
83516
83517+ /*
83518+ * mm->mmap_sem is required to protect against another thread
83519+ * changing the mappings in case we sleep.
83520+ */
83521+ verify_mm_writelocked(mm);
83522+
83523 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
83524 return -EINVAL;
83525
83526@@ -2567,6 +3043,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83527 /* Fix up all other VM information */
83528 remove_vma_list(mm, vma);
83529
83530+ track_exec_limit(mm, start, end, 0UL);
83531+
83532 return 0;
83533 }
83534
83535@@ -2575,6 +3053,13 @@ int vm_munmap(unsigned long start, size_t len)
83536 int ret;
83537 struct mm_struct *mm = current->mm;
83538
83539+
83540+#ifdef CONFIG_PAX_SEGMEXEC
83541+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
83542+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
83543+ return -EINVAL;
83544+#endif
83545+
83546 down_write(&mm->mmap_sem);
83547 ret = do_munmap(mm, start, len);
83548 up_write(&mm->mmap_sem);
83549@@ -2588,16 +3073,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
83550 return vm_munmap(addr, len);
83551 }
83552
83553-static inline void verify_mm_writelocked(struct mm_struct *mm)
83554-{
83555-#ifdef CONFIG_DEBUG_VM
83556- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
83557- WARN_ON(1);
83558- up_read(&mm->mmap_sem);
83559- }
83560-#endif
83561-}
83562-
83563 /*
83564 * this is really a simplified "do_mmap". it only handles
83565 * anonymous maps. eventually we may be able to do some
83566@@ -2611,6 +3086,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83567 struct rb_node ** rb_link, * rb_parent;
83568 pgoff_t pgoff = addr >> PAGE_SHIFT;
83569 int error;
83570+ unsigned long charged;
83571
83572 len = PAGE_ALIGN(len);
83573 if (!len)
83574@@ -2618,16 +3094,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83575
83576 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
83577
83578+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
83579+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
83580+ flags &= ~VM_EXEC;
83581+
83582+#ifdef CONFIG_PAX_MPROTECT
83583+ if (mm->pax_flags & MF_PAX_MPROTECT)
83584+ flags &= ~VM_MAYEXEC;
83585+#endif
83586+
83587+ }
83588+#endif
83589+
83590 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
83591 if (error & ~PAGE_MASK)
83592 return error;
83593
83594+ charged = len >> PAGE_SHIFT;
83595+
83596 /*
83597 * mlock MCL_FUTURE?
83598 */
83599 if (mm->def_flags & VM_LOCKED) {
83600 unsigned long locked, lock_limit;
83601- locked = len >> PAGE_SHIFT;
83602+ locked = charged;
83603 locked += mm->locked_vm;
83604 lock_limit = rlimit(RLIMIT_MEMLOCK);
83605 lock_limit >>= PAGE_SHIFT;
83606@@ -2644,21 +3134,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83607 /*
83608 * Clear old maps. this also does some error checking for us
83609 */
83610- munmap_back:
83611 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
83612 if (do_munmap(mm, addr, len))
83613 return -ENOMEM;
83614- goto munmap_back;
83615+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
83616 }
83617
83618 /* Check against address space limits *after* clearing old maps... */
83619- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
83620+ if (!may_expand_vm(mm, charged))
83621 return -ENOMEM;
83622
83623 if (mm->map_count > sysctl_max_map_count)
83624 return -ENOMEM;
83625
83626- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
83627+ if (security_vm_enough_memory_mm(mm, charged))
83628 return -ENOMEM;
83629
83630 /* Can we just expand an old private anonymous mapping? */
83631@@ -2672,7 +3161,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83632 */
83633 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83634 if (!vma) {
83635- vm_unacct_memory(len >> PAGE_SHIFT);
83636+ vm_unacct_memory(charged);
83637 return -ENOMEM;
83638 }
83639
83640@@ -2686,9 +3175,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83641 vma_link(mm, vma, prev, rb_link, rb_parent);
83642 out:
83643 perf_event_mmap(vma);
83644- mm->total_vm += len >> PAGE_SHIFT;
83645+ mm->total_vm += charged;
83646 if (flags & VM_LOCKED)
83647- mm->locked_vm += (len >> PAGE_SHIFT);
83648+ mm->locked_vm += charged;
83649+ track_exec_limit(mm, addr, addr + len, flags);
83650 return addr;
83651 }
83652
83653@@ -2750,6 +3240,7 @@ void exit_mmap(struct mm_struct *mm)
83654 while (vma) {
83655 if (vma->vm_flags & VM_ACCOUNT)
83656 nr_accounted += vma_pages(vma);
83657+ vma->vm_mirror = NULL;
83658 vma = remove_vma(vma);
83659 }
83660 vm_unacct_memory(nr_accounted);
83661@@ -2766,6 +3257,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83662 struct vm_area_struct *prev;
83663 struct rb_node **rb_link, *rb_parent;
83664
83665+#ifdef CONFIG_PAX_SEGMEXEC
83666+ struct vm_area_struct *vma_m = NULL;
83667+#endif
83668+
83669+ if (security_mmap_addr(vma->vm_start))
83670+ return -EPERM;
83671+
83672 /*
83673 * The vm_pgoff of a purely anonymous vma should be irrelevant
83674 * until its first write fault, when page's anon_vma and index
83675@@ -2789,7 +3287,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83676 security_vm_enough_memory_mm(mm, vma_pages(vma)))
83677 return -ENOMEM;
83678
83679+#ifdef CONFIG_PAX_SEGMEXEC
83680+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
83681+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83682+ if (!vma_m)
83683+ return -ENOMEM;
83684+ }
83685+#endif
83686+
83687 vma_link(mm, vma, prev, rb_link, rb_parent);
83688+
83689+#ifdef CONFIG_PAX_SEGMEXEC
83690+ if (vma_m)
83691+ BUG_ON(pax_mirror_vma(vma_m, vma));
83692+#endif
83693+
83694 return 0;
83695 }
83696
83697@@ -2809,6 +3321,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83698 struct mempolicy *pol;
83699 bool faulted_in_anon_vma = true;
83700
83701+ BUG_ON(vma->vm_mirror);
83702+
83703 /*
83704 * If anonymous vma has not yet been faulted, update new pgoff
83705 * to match new location, to increase its chance of merging.
83706@@ -2875,6 +3389,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83707 return NULL;
83708 }
83709
83710+#ifdef CONFIG_PAX_SEGMEXEC
83711+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
83712+{
83713+ struct vm_area_struct *prev_m;
83714+ struct rb_node **rb_link_m, *rb_parent_m;
83715+ struct mempolicy *pol_m;
83716+
83717+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
83718+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
83719+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
83720+ *vma_m = *vma;
83721+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
83722+ if (anon_vma_clone(vma_m, vma))
83723+ return -ENOMEM;
83724+ pol_m = vma_policy(vma_m);
83725+ mpol_get(pol_m);
83726+ vma_set_policy(vma_m, pol_m);
83727+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
83728+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
83729+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
83730+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
83731+ if (vma_m->vm_file)
83732+ get_file(vma_m->vm_file);
83733+ if (vma_m->vm_ops && vma_m->vm_ops->open)
83734+ vma_m->vm_ops->open(vma_m);
83735+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
83736+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
83737+ vma_m->vm_mirror = vma;
83738+ vma->vm_mirror = vma_m;
83739+ return 0;
83740+}
83741+#endif
83742+
83743 /*
83744 * Return true if the calling process may expand its vm space by the passed
83745 * number of pages
83746@@ -2886,6 +3433,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
83747
83748 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
83749
83750+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
83751 if (cur + npages > lim)
83752 return 0;
83753 return 1;
83754@@ -2956,6 +3504,22 @@ int install_special_mapping(struct mm_struct *mm,
83755 vma->vm_start = addr;
83756 vma->vm_end = addr + len;
83757
83758+#ifdef CONFIG_PAX_MPROTECT
83759+ if (mm->pax_flags & MF_PAX_MPROTECT) {
83760+#ifndef CONFIG_PAX_MPROTECT_COMPAT
83761+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
83762+ return -EPERM;
83763+ if (!(vm_flags & VM_EXEC))
83764+ vm_flags &= ~VM_MAYEXEC;
83765+#else
83766+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
83767+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
83768+#endif
83769+ else
83770+ vm_flags &= ~VM_MAYWRITE;
83771+ }
83772+#endif
83773+
83774 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
83775 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
83776
83777diff --git a/mm/mprotect.c b/mm/mprotect.c
83778index 94722a4..07d9926 100644
83779--- a/mm/mprotect.c
83780+++ b/mm/mprotect.c
83781@@ -23,10 +23,18 @@
83782 #include <linux/mmu_notifier.h>
83783 #include <linux/migrate.h>
83784 #include <linux/perf_event.h>
83785+#include <linux/sched/sysctl.h>
83786+
83787+#ifdef CONFIG_PAX_MPROTECT
83788+#include <linux/elf.h>
83789+#include <linux/binfmts.h>
83790+#endif
83791+
83792 #include <asm/uaccess.h>
83793 #include <asm/pgtable.h>
83794 #include <asm/cacheflush.h>
83795 #include <asm/tlbflush.h>
83796+#include <asm/mmu_context.h>
83797
83798 #ifndef pgprot_modify
83799 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
83800@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
83801 return pages;
83802 }
83803
83804+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83805+/* called while holding the mmap semaphor for writing except stack expansion */
83806+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
83807+{
83808+ unsigned long oldlimit, newlimit = 0UL;
83809+
83810+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
83811+ return;
83812+
83813+ spin_lock(&mm->page_table_lock);
83814+ oldlimit = mm->context.user_cs_limit;
83815+ if ((prot & VM_EXEC) && oldlimit < end)
83816+ /* USER_CS limit moved up */
83817+ newlimit = end;
83818+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
83819+ /* USER_CS limit moved down */
83820+ newlimit = start;
83821+
83822+ if (newlimit) {
83823+ mm->context.user_cs_limit = newlimit;
83824+
83825+#ifdef CONFIG_SMP
83826+ wmb();
83827+ cpus_clear(mm->context.cpu_user_cs_mask);
83828+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
83829+#endif
83830+
83831+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
83832+ }
83833+ spin_unlock(&mm->page_table_lock);
83834+ if (newlimit == end) {
83835+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
83836+
83837+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
83838+ if (is_vm_hugetlb_page(vma))
83839+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
83840+ else
83841+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
83842+ }
83843+}
83844+#endif
83845+
83846 int
83847 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83848 unsigned long start, unsigned long end, unsigned long newflags)
83849@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83850 int error;
83851 int dirty_accountable = 0;
83852
83853+#ifdef CONFIG_PAX_SEGMEXEC
83854+ struct vm_area_struct *vma_m = NULL;
83855+ unsigned long start_m, end_m;
83856+
83857+ start_m = start + SEGMEXEC_TASK_SIZE;
83858+ end_m = end + SEGMEXEC_TASK_SIZE;
83859+#endif
83860+
83861 if (newflags == oldflags) {
83862 *pprev = vma;
83863 return 0;
83864 }
83865
83866+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
83867+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
83868+
83869+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
83870+ return -ENOMEM;
83871+
83872+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
83873+ return -ENOMEM;
83874+ }
83875+
83876 /*
83877 * If we make a private mapping writable we increase our commit;
83878 * but (without finer accounting) cannot reduce our commit if we
83879@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83880 }
83881 }
83882
83883+#ifdef CONFIG_PAX_SEGMEXEC
83884+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
83885+ if (start != vma->vm_start) {
83886+ error = split_vma(mm, vma, start, 1);
83887+ if (error)
83888+ goto fail;
83889+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
83890+ *pprev = (*pprev)->vm_next;
83891+ }
83892+
83893+ if (end != vma->vm_end) {
83894+ error = split_vma(mm, vma, end, 0);
83895+ if (error)
83896+ goto fail;
83897+ }
83898+
83899+ if (pax_find_mirror_vma(vma)) {
83900+ error = __do_munmap(mm, start_m, end_m - start_m);
83901+ if (error)
83902+ goto fail;
83903+ } else {
83904+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83905+ if (!vma_m) {
83906+ error = -ENOMEM;
83907+ goto fail;
83908+ }
83909+ vma->vm_flags = newflags;
83910+ error = pax_mirror_vma(vma_m, vma);
83911+ if (error) {
83912+ vma->vm_flags = oldflags;
83913+ goto fail;
83914+ }
83915+ }
83916+ }
83917+#endif
83918+
83919 /*
83920 * First try to merge with previous and/or next vma.
83921 */
83922@@ -296,9 +400,21 @@ success:
83923 * vm_flags and vm_page_prot are protected by the mmap_sem
83924 * held in write mode.
83925 */
83926+
83927+#ifdef CONFIG_PAX_SEGMEXEC
83928+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
83929+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
83930+#endif
83931+
83932 vma->vm_flags = newflags;
83933+
83934+#ifdef CONFIG_PAX_MPROTECT
83935+ if (mm->binfmt && mm->binfmt->handle_mprotect)
83936+ mm->binfmt->handle_mprotect(vma, newflags);
83937+#endif
83938+
83939 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
83940- vm_get_page_prot(newflags));
83941+ vm_get_page_prot(vma->vm_flags));
83942
83943 if (vma_wants_writenotify(vma)) {
83944 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
83945@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83946 end = start + len;
83947 if (end <= start)
83948 return -ENOMEM;
83949+
83950+#ifdef CONFIG_PAX_SEGMEXEC
83951+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
83952+ if (end > SEGMEXEC_TASK_SIZE)
83953+ return -EINVAL;
83954+ } else
83955+#endif
83956+
83957+ if (end > TASK_SIZE)
83958+ return -EINVAL;
83959+
83960 if (!arch_validate_prot(prot))
83961 return -EINVAL;
83962
83963@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83964 /*
83965 * Does the application expect PROT_READ to imply PROT_EXEC:
83966 */
83967- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
83968+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
83969 prot |= PROT_EXEC;
83970
83971 vm_flags = calc_vm_prot_bits(prot);
83972@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83973 if (start > vma->vm_start)
83974 prev = vma;
83975
83976+#ifdef CONFIG_PAX_MPROTECT
83977+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
83978+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
83979+#endif
83980+
83981 for (nstart = start ; ; ) {
83982 unsigned long newflags;
83983
83984@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83985
83986 /* newflags >> 4 shift VM_MAY% in place of VM_% */
83987 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
83988+ if (prot & (PROT_WRITE | PROT_EXEC))
83989+ gr_log_rwxmprotect(vma->vm_file);
83990+
83991+ error = -EACCES;
83992+ goto out;
83993+ }
83994+
83995+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
83996 error = -EACCES;
83997 goto out;
83998 }
83999@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84000 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
84001 if (error)
84002 goto out;
84003+
84004+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
84005+
84006 nstart = tmp;
84007
84008 if (nstart < prev->vm_end)
84009diff --git a/mm/mremap.c b/mm/mremap.c
84010index 463a257..c0c7a92 100644
84011--- a/mm/mremap.c
84012+++ b/mm/mremap.c
84013@@ -126,6 +126,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
84014 continue;
84015 pte = ptep_get_and_clear(mm, old_addr, old_pte);
84016 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
84017+
84018+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
84019+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
84020+ pte = pte_exprotect(pte);
84021+#endif
84022+
84023 set_pte_at(mm, new_addr, new_pte, pte);
84024 }
84025
84026@@ -318,6 +324,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
84027 if (is_vm_hugetlb_page(vma))
84028 goto Einval;
84029
84030+#ifdef CONFIG_PAX_SEGMEXEC
84031+ if (pax_find_mirror_vma(vma))
84032+ goto Einval;
84033+#endif
84034+
84035 /* We can't remap across vm area boundaries */
84036 if (old_len > vma->vm_end - addr)
84037 goto Efault;
84038@@ -373,20 +384,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
84039 unsigned long ret = -EINVAL;
84040 unsigned long charged = 0;
84041 unsigned long map_flags;
84042+ unsigned long pax_task_size = TASK_SIZE;
84043
84044 if (new_addr & ~PAGE_MASK)
84045 goto out;
84046
84047- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
84048+#ifdef CONFIG_PAX_SEGMEXEC
84049+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
84050+ pax_task_size = SEGMEXEC_TASK_SIZE;
84051+#endif
84052+
84053+ pax_task_size -= PAGE_SIZE;
84054+
84055+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
84056 goto out;
84057
84058 /* Check if the location we're moving into overlaps the
84059 * old location at all, and fail if it does.
84060 */
84061- if ((new_addr <= addr) && (new_addr+new_len) > addr)
84062- goto out;
84063-
84064- if ((addr <= new_addr) && (addr+old_len) > new_addr)
84065+ if (addr + old_len > new_addr && new_addr + new_len > addr)
84066 goto out;
84067
84068 ret = do_munmap(mm, new_addr, new_len);
84069@@ -455,6 +471,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84070 unsigned long ret = -EINVAL;
84071 unsigned long charged = 0;
84072 bool locked = false;
84073+ unsigned long pax_task_size = TASK_SIZE;
84074
84075 down_write(&current->mm->mmap_sem);
84076
84077@@ -475,6 +492,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84078 if (!new_len)
84079 goto out;
84080
84081+#ifdef CONFIG_PAX_SEGMEXEC
84082+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
84083+ pax_task_size = SEGMEXEC_TASK_SIZE;
84084+#endif
84085+
84086+ pax_task_size -= PAGE_SIZE;
84087+
84088+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
84089+ old_len > pax_task_size || addr > pax_task_size-old_len)
84090+ goto out;
84091+
84092 if (flags & MREMAP_FIXED) {
84093 if (flags & MREMAP_MAYMOVE)
84094 ret = mremap_to(addr, old_len, new_addr, new_len,
84095@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84096 new_addr = addr;
84097 }
84098 ret = addr;
84099+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
84100 goto out;
84101 }
84102 }
84103@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84104 goto out;
84105 }
84106
84107+ map_flags = vma->vm_flags;
84108 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
84109+ if (!(ret & ~PAGE_MASK)) {
84110+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
84111+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
84112+ }
84113 }
84114 out:
84115 if (ret & ~PAGE_MASK)
84116diff --git a/mm/nommu.c b/mm/nommu.c
84117index 298884d..5f74980 100644
84118--- a/mm/nommu.c
84119+++ b/mm/nommu.c
84120@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
84121 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
84122 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
84123 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
84124-int heap_stack_gap = 0;
84125
84126 atomic_long_t mmap_pages_allocated;
84127
84128@@ -842,15 +841,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
84129 EXPORT_SYMBOL(find_vma);
84130
84131 /*
84132- * find a VMA
84133- * - we don't extend stack VMAs under NOMMU conditions
84134- */
84135-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
84136-{
84137- return find_vma(mm, addr);
84138-}
84139-
84140-/*
84141 * expand a stack to a given address
84142 * - not supported under NOMMU conditions
84143 */
84144@@ -1561,6 +1551,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
84145
84146 /* most fields are the same, copy all, and then fixup */
84147 *new = *vma;
84148+ INIT_LIST_HEAD(&new->anon_vma_chain);
84149 *region = *vma->vm_region;
84150 new->vm_region = region;
84151
84152@@ -1995,8 +1986,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
84153 }
84154 EXPORT_SYMBOL(generic_file_remap_pages);
84155
84156-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84157- unsigned long addr, void *buf, int len, int write)
84158+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84159+ unsigned long addr, void *buf, size_t len, int write)
84160 {
84161 struct vm_area_struct *vma;
84162
84163@@ -2037,8 +2028,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84164 *
84165 * The caller must hold a reference on @mm.
84166 */
84167-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84168- void *buf, int len, int write)
84169+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
84170+ void *buf, size_t len, int write)
84171 {
84172 return __access_remote_vm(NULL, mm, addr, buf, len, write);
84173 }
84174@@ -2047,7 +2038,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84175 * Access another process' address space.
84176 * - source/target buffer must be kernel space
84177 */
84178-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
84179+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
84180 {
84181 struct mm_struct *mm;
84182
84183diff --git a/mm/page-writeback.c b/mm/page-writeback.c
84184index 4514ad7..92eaa1c 100644
84185--- a/mm/page-writeback.c
84186+++ b/mm/page-writeback.c
84187@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
84188 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
84189 * - the bdi dirty thresh drops quickly due to change of JBOD workload
84190 */
84191-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
84192+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
84193 unsigned long thresh,
84194 unsigned long bg_thresh,
84195 unsigned long dirty,
84196@@ -1634,7 +1634,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
84197 }
84198 }
84199
84200-static struct notifier_block __cpuinitdata ratelimit_nb = {
84201+static struct notifier_block ratelimit_nb = {
84202 .notifier_call = ratelimit_handler,
84203 .next = NULL,
84204 };
84205diff --git a/mm/page_alloc.c b/mm/page_alloc.c
84206index c3edb62..2d60097 100644
84207--- a/mm/page_alloc.c
84208+++ b/mm/page_alloc.c
84209@@ -60,6 +60,7 @@
84210 #include <linux/page-debug-flags.h>
84211 #include <linux/hugetlb.h>
84212 #include <linux/sched/rt.h>
84213+#include <linux/random.h>
84214
84215 #include <asm/tlbflush.h>
84216 #include <asm/div64.h>
84217@@ -345,7 +346,7 @@ out:
84218 * This usage means that zero-order pages may not be compound.
84219 */
84220
84221-static void free_compound_page(struct page *page)
84222+void free_compound_page(struct page *page)
84223 {
84224 __free_pages_ok(page, compound_order(page));
84225 }
84226@@ -702,6 +703,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
84227 int i;
84228 int bad = 0;
84229
84230+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84231+ unsigned long index = 1UL << order;
84232+#endif
84233+
84234 trace_mm_page_free(page, order);
84235 kmemcheck_free_shadow(page, order);
84236
84237@@ -717,6 +722,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
84238 debug_check_no_obj_freed(page_address(page),
84239 PAGE_SIZE << order);
84240 }
84241+
84242+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84243+ for (; index; --index)
84244+ sanitize_highpage(page + index - 1);
84245+#endif
84246+
84247 arch_free_page(page, order);
84248 kernel_map_pages(page, 1 << order, 0);
84249
84250@@ -739,6 +750,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
84251 local_irq_restore(flags);
84252 }
84253
84254+#ifdef CONFIG_PAX_LATENT_ENTROPY
84255+bool __meminitdata extra_latent_entropy;
84256+
84257+static int __init setup_pax_extra_latent_entropy(char *str)
84258+{
84259+ extra_latent_entropy = true;
84260+ return 0;
84261+}
84262+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
84263+
84264+volatile u64 latent_entropy;
84265+#endif
84266+
84267 /*
84268 * Read access to zone->managed_pages is safe because it's unsigned long,
84269 * but we still need to serialize writers. Currently all callers of
84270@@ -761,6 +785,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
84271 set_page_count(p, 0);
84272 }
84273
84274+#ifdef CONFIG_PAX_LATENT_ENTROPY
84275+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
84276+ u64 hash = 0;
84277+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
84278+ const u64 *data = lowmem_page_address(page);
84279+
84280+ for (index = 0; index < end; index++)
84281+ hash ^= hash + data[index];
84282+ latent_entropy ^= hash;
84283+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84284+ }
84285+#endif
84286+
84287 page_zone(page)->managed_pages += 1 << order;
84288 set_page_refcounted(page);
84289 __free_pages(page, order);
84290@@ -870,8 +907,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
84291 arch_alloc_page(page, order);
84292 kernel_map_pages(page, 1 << order, 1);
84293
84294+#ifndef CONFIG_PAX_MEMORY_SANITIZE
84295 if (gfp_flags & __GFP_ZERO)
84296 prep_zero_page(page, order, gfp_flags);
84297+#endif
84298
84299 if (order && (gfp_flags & __GFP_COMP))
84300 prep_compound_page(page, order);
84301diff --git a/mm/page_io.c b/mm/page_io.c
84302index a8a3ef4..7260a60 100644
84303--- a/mm/page_io.c
84304+++ b/mm/page_io.c
84305@@ -214,7 +214,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
84306 struct file *swap_file = sis->swap_file;
84307 struct address_space *mapping = swap_file->f_mapping;
84308 struct iovec iov = {
84309- .iov_base = kmap(page),
84310+ .iov_base = (void __force_user *)kmap(page),
84311 .iov_len = PAGE_SIZE,
84312 };
84313
84314diff --git a/mm/percpu.c b/mm/percpu.c
84315index 8c8e08f..73a5cda 100644
84316--- a/mm/percpu.c
84317+++ b/mm/percpu.c
84318@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
84319 static unsigned int pcpu_high_unit_cpu __read_mostly;
84320
84321 /* the address of the first chunk which starts with the kernel static area */
84322-void *pcpu_base_addr __read_mostly;
84323+void *pcpu_base_addr __read_only;
84324 EXPORT_SYMBOL_GPL(pcpu_base_addr);
84325
84326 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
84327diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
84328index fd26d04..0cea1b0 100644
84329--- a/mm/process_vm_access.c
84330+++ b/mm/process_vm_access.c
84331@@ -13,6 +13,7 @@
84332 #include <linux/uio.h>
84333 #include <linux/sched.h>
84334 #include <linux/highmem.h>
84335+#include <linux/security.h>
84336 #include <linux/ptrace.h>
84337 #include <linux/slab.h>
84338 #include <linux/syscalls.h>
84339@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
84340 size_t iov_l_curr_offset = 0;
84341 ssize_t iov_len;
84342
84343+ return -ENOSYS; // PaX: until properly audited
84344+
84345 /*
84346 * Work out how many pages of struct pages we're going to need
84347 * when eventually calling get_user_pages
84348 */
84349 for (i = 0; i < riovcnt; i++) {
84350 iov_len = rvec[i].iov_len;
84351- if (iov_len > 0) {
84352- nr_pages_iov = ((unsigned long)rvec[i].iov_base
84353- + iov_len)
84354- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
84355- / PAGE_SIZE + 1;
84356- nr_pages = max(nr_pages, nr_pages_iov);
84357- }
84358+ if (iov_len <= 0)
84359+ continue;
84360+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
84361+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
84362+ nr_pages = max(nr_pages, nr_pages_iov);
84363 }
84364
84365 if (nr_pages == 0)
84366@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
84367 goto free_proc_pages;
84368 }
84369
84370+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
84371+ rc = -EPERM;
84372+ goto put_task_struct;
84373+ }
84374+
84375 mm = mm_access(task, PTRACE_MODE_ATTACH);
84376 if (!mm || IS_ERR(mm)) {
84377 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
84378diff --git a/mm/rmap.c b/mm/rmap.c
84379index 6280da8..ecce194 100644
84380--- a/mm/rmap.c
84381+++ b/mm/rmap.c
84382@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84383 struct anon_vma *anon_vma = vma->anon_vma;
84384 struct anon_vma_chain *avc;
84385
84386+#ifdef CONFIG_PAX_SEGMEXEC
84387+ struct anon_vma_chain *avc_m = NULL;
84388+#endif
84389+
84390 might_sleep();
84391 if (unlikely(!anon_vma)) {
84392 struct mm_struct *mm = vma->vm_mm;
84393@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84394 if (!avc)
84395 goto out_enomem;
84396
84397+#ifdef CONFIG_PAX_SEGMEXEC
84398+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
84399+ if (!avc_m)
84400+ goto out_enomem_free_avc;
84401+#endif
84402+
84403 anon_vma = find_mergeable_anon_vma(vma);
84404 allocated = NULL;
84405 if (!anon_vma) {
84406@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84407 /* page_table_lock to protect against threads */
84408 spin_lock(&mm->page_table_lock);
84409 if (likely(!vma->anon_vma)) {
84410+
84411+#ifdef CONFIG_PAX_SEGMEXEC
84412+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
84413+
84414+ if (vma_m) {
84415+ BUG_ON(vma_m->anon_vma);
84416+ vma_m->anon_vma = anon_vma;
84417+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
84418+ avc_m = NULL;
84419+ }
84420+#endif
84421+
84422 vma->anon_vma = anon_vma;
84423 anon_vma_chain_link(vma, avc, anon_vma);
84424 allocated = NULL;
84425@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84426
84427 if (unlikely(allocated))
84428 put_anon_vma(allocated);
84429+
84430+#ifdef CONFIG_PAX_SEGMEXEC
84431+ if (unlikely(avc_m))
84432+ anon_vma_chain_free(avc_m);
84433+#endif
84434+
84435 if (unlikely(avc))
84436 anon_vma_chain_free(avc);
84437 }
84438 return 0;
84439
84440 out_enomem_free_avc:
84441+
84442+#ifdef CONFIG_PAX_SEGMEXEC
84443+ if (avc_m)
84444+ anon_vma_chain_free(avc_m);
84445+#endif
84446+
84447 anon_vma_chain_free(avc);
84448 out_enomem:
84449 return -ENOMEM;
84450@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
84451 * Attach the anon_vmas from src to dst.
84452 * Returns 0 on success, -ENOMEM on failure.
84453 */
84454-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84455+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
84456 {
84457 struct anon_vma_chain *avc, *pavc;
84458 struct anon_vma *root = NULL;
84459@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84460 * the corresponding VMA in the parent process is attached to.
84461 * Returns 0 on success, non-zero on failure.
84462 */
84463-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
84464+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
84465 {
84466 struct anon_vma_chain *avc;
84467 struct anon_vma *anon_vma;
84468diff --git a/mm/shmem.c b/mm/shmem.c
84469index 5e6a842..b41916e 100644
84470--- a/mm/shmem.c
84471+++ b/mm/shmem.c
84472@@ -33,7 +33,7 @@
84473 #include <linux/swap.h>
84474 #include <linux/aio.h>
84475
84476-static struct vfsmount *shm_mnt;
84477+struct vfsmount *shm_mnt;
84478
84479 #ifdef CONFIG_SHMEM
84480 /*
84481@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
84482 #define BOGO_DIRENT_SIZE 20
84483
84484 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
84485-#define SHORT_SYMLINK_LEN 128
84486+#define SHORT_SYMLINK_LEN 64
84487
84488 /*
84489 * shmem_fallocate and shmem_writepage communicate via inode->i_private
84490@@ -2203,6 +2203,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
84491 static int shmem_xattr_validate(const char *name)
84492 {
84493 struct { const char *prefix; size_t len; } arr[] = {
84494+
84495+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84496+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
84497+#endif
84498+
84499 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
84500 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
84501 };
84502@@ -2258,6 +2263,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
84503 if (err)
84504 return err;
84505
84506+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84507+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
84508+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
84509+ return -EOPNOTSUPP;
84510+ if (size > 8)
84511+ return -EINVAL;
84512+ }
84513+#endif
84514+
84515 return simple_xattr_set(&info->xattrs, name, value, size, flags);
84516 }
84517
84518@@ -2570,8 +2584,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
84519 int err = -ENOMEM;
84520
84521 /* Round up to L1_CACHE_BYTES to resist false sharing */
84522- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
84523- L1_CACHE_BYTES), GFP_KERNEL);
84524+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
84525 if (!sbinfo)
84526 return -ENOMEM;
84527
84528diff --git a/mm/slab.c b/mm/slab.c
84529index 8ccd296..012fe4e 100644
84530--- a/mm/slab.c
84531+++ b/mm/slab.c
84532@@ -366,10 +366,10 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
84533 if ((x)->max_freeable < i) \
84534 (x)->max_freeable = i; \
84535 } while (0)
84536-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
84537-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
84538-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
84539-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
84540+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
84541+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
84542+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
84543+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
84544 #else
84545 #define STATS_INC_ACTIVE(x) do { } while (0)
84546 #define STATS_DEC_ACTIVE(x) do { } while (0)
84547@@ -477,7 +477,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
84548 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
84549 */
84550 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
84551- const struct slab *slab, void *obj)
84552+ const struct slab *slab, const void *obj)
84553 {
84554 u32 offset = (obj - slab->s_mem);
84555 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
84556@@ -1384,7 +1384,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
84557 return notifier_from_errno(err);
84558 }
84559
84560-static struct notifier_block __cpuinitdata cpucache_notifier = {
84561+static struct notifier_block cpucache_notifier = {
84562 &cpuup_callback, NULL, 0
84563 };
84564
84565@@ -1565,12 +1565,12 @@ void __init kmem_cache_init(void)
84566 */
84567
84568 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
84569- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
84570+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
84571
84572 if (INDEX_AC != INDEX_NODE)
84573 kmalloc_caches[INDEX_NODE] =
84574 create_kmalloc_cache("kmalloc-node",
84575- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
84576+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
84577
84578 slab_early_init = 0;
84579
84580@@ -3800,6 +3800,7 @@ void kfree(const void *objp)
84581
84582 if (unlikely(ZERO_OR_NULL_PTR(objp)))
84583 return;
84584+ VM_BUG_ON(!virt_addr_valid(objp));
84585 local_irq_save(flags);
84586 kfree_debugcheck(objp);
84587 c = virt_to_cache(objp);
84588@@ -4241,10 +4242,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
84589 }
84590 /* cpu stats */
84591 {
84592- unsigned long allochit = atomic_read(&cachep->allochit);
84593- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
84594- unsigned long freehit = atomic_read(&cachep->freehit);
84595- unsigned long freemiss = atomic_read(&cachep->freemiss);
84596+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
84597+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
84598+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
84599+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
84600
84601 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
84602 allochit, allocmiss, freehit, freemiss);
84603@@ -4476,13 +4477,71 @@ static const struct file_operations proc_slabstats_operations = {
84604 static int __init slab_proc_init(void)
84605 {
84606 #ifdef CONFIG_DEBUG_SLAB_LEAK
84607- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
84608+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
84609 #endif
84610 return 0;
84611 }
84612 module_init(slab_proc_init);
84613 #endif
84614
84615+bool is_usercopy_object(const void *ptr)
84616+{
84617+ struct page *page;
84618+ struct kmem_cache *cachep;
84619+
84620+ if (ZERO_OR_NULL_PTR(ptr))
84621+ return false;
84622+
84623+ if (!slab_is_available())
84624+ return false;
84625+
84626+ if (!virt_addr_valid(ptr))
84627+ return false;
84628+
84629+ page = virt_to_head_page(ptr);
84630+
84631+ if (!PageSlab(page))
84632+ return false;
84633+
84634+ cachep = page->slab_cache;
84635+ return cachep->flags & SLAB_USERCOPY;
84636+}
84637+
84638+#ifdef CONFIG_PAX_USERCOPY
84639+const char *check_heap_object(const void *ptr, unsigned long n)
84640+{
84641+ struct page *page;
84642+ struct kmem_cache *cachep;
84643+ struct slab *slabp;
84644+ unsigned int objnr;
84645+ unsigned long offset;
84646+
84647+ if (ZERO_OR_NULL_PTR(ptr))
84648+ return "<null>";
84649+
84650+ if (!virt_addr_valid(ptr))
84651+ return NULL;
84652+
84653+ page = virt_to_head_page(ptr);
84654+
84655+ if (!PageSlab(page))
84656+ return NULL;
84657+
84658+ cachep = page->slab_cache;
84659+ if (!(cachep->flags & SLAB_USERCOPY))
84660+ return cachep->name;
84661+
84662+ slabp = page->slab_page;
84663+ objnr = obj_to_index(cachep, slabp, ptr);
84664+ BUG_ON(objnr >= cachep->num);
84665+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
84666+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
84667+ return NULL;
84668+
84669+ return cachep->name;
84670+}
84671+#endif
84672+
84673 /**
84674 * ksize - get the actual amount of memory allocated for a given object
84675 * @objp: Pointer to the object
84676diff --git a/mm/slab.h b/mm/slab.h
84677index f96b49e..5634e90 100644
84678--- a/mm/slab.h
84679+++ b/mm/slab.h
84680@@ -67,7 +67,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84681
84682 /* Legal flag mask for kmem_cache_create(), for various configurations */
84683 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
84684- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
84685+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
84686
84687 #if defined(CONFIG_DEBUG_SLAB)
84688 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
84689@@ -229,6 +229,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
84690 return s;
84691
84692 page = virt_to_head_page(x);
84693+
84694+ BUG_ON(!PageSlab(page));
84695+
84696 cachep = page->slab_cache;
84697 if (slab_equal_or_root(cachep, s))
84698 return cachep;
84699diff --git a/mm/slab_common.c b/mm/slab_common.c
84700index 2d41450..e22088e 100644
84701--- a/mm/slab_common.c
84702+++ b/mm/slab_common.c
84703@@ -22,7 +22,7 @@
84704
84705 #include "slab.h"
84706
84707-enum slab_state slab_state;
84708+enum slab_state slab_state __read_only;
84709 LIST_HEAD(slab_caches);
84710 DEFINE_MUTEX(slab_mutex);
84711 struct kmem_cache *kmem_cache;
84712@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
84713
84714 err = __kmem_cache_create(s, flags);
84715 if (!err) {
84716- s->refcount = 1;
84717+ atomic_set(&s->refcount, 1);
84718 list_add(&s->list, &slab_caches);
84719 memcg_cache_list_add(memcg, s);
84720 } else {
84721@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
84722
84723 get_online_cpus();
84724 mutex_lock(&slab_mutex);
84725- s->refcount--;
84726- if (!s->refcount) {
84727+ if (atomic_dec_and_test(&s->refcount)) {
84728 list_del(&s->list);
84729
84730 if (!__kmem_cache_shutdown(s)) {
84731@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
84732 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
84733 name, size, err);
84734
84735- s->refcount = -1; /* Exempt from merging for now */
84736+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
84737 }
84738
84739 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84740@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84741
84742 create_boot_cache(s, name, size, flags);
84743 list_add(&s->list, &slab_caches);
84744- s->refcount = 1;
84745+ atomic_set(&s->refcount, 1);
84746 return s;
84747 }
84748
84749@@ -327,6 +326,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
84750 EXPORT_SYMBOL(kmalloc_dma_caches);
84751 #endif
84752
84753+#ifdef CONFIG_PAX_USERCOPY_SLABS
84754+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
84755+EXPORT_SYMBOL(kmalloc_usercopy_caches);
84756+#endif
84757+
84758 /*
84759 * Conversion table for small slabs sizes / 8 to the index in the
84760 * kmalloc array. This is necessary for slabs < 192 since we have non power
84761@@ -391,6 +395,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
84762 return kmalloc_dma_caches[index];
84763
84764 #endif
84765+
84766+#ifdef CONFIG_PAX_USERCOPY_SLABS
84767+ if (unlikely((flags & GFP_USERCOPY)))
84768+ return kmalloc_usercopy_caches[index];
84769+
84770+#endif
84771+
84772 return kmalloc_caches[index];
84773 }
84774
84775@@ -447,7 +458,7 @@ void __init create_kmalloc_caches(unsigned long flags)
84776 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
84777 if (!kmalloc_caches[i]) {
84778 kmalloc_caches[i] = create_kmalloc_cache(NULL,
84779- 1 << i, flags);
84780+ 1 << i, SLAB_USERCOPY | flags);
84781 }
84782
84783 /*
84784@@ -456,10 +467,10 @@ void __init create_kmalloc_caches(unsigned long flags)
84785 * earlier power of two caches
84786 */
84787 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
84788- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
84789+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
84790
84791 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
84792- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
84793+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
84794 }
84795
84796 /* Kmalloc array is now usable */
84797@@ -492,6 +503,23 @@ void __init create_kmalloc_caches(unsigned long flags)
84798 }
84799 }
84800 #endif
84801+
84802+#ifdef CONFIG_PAX_USERCOPY_SLABS
84803+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
84804+ struct kmem_cache *s = kmalloc_caches[i];
84805+
84806+ if (s) {
84807+ int size = kmalloc_size(i);
84808+ char *n = kasprintf(GFP_NOWAIT,
84809+ "usercopy-kmalloc-%d", size);
84810+
84811+ BUG_ON(!n);
84812+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
84813+ size, SLAB_USERCOPY | flags);
84814+ }
84815+ }
84816+#endif
84817+
84818 }
84819 #endif /* !CONFIG_SLOB */
84820
84821diff --git a/mm/slob.c b/mm/slob.c
84822index eeed4a0..6ee34ec 100644
84823--- a/mm/slob.c
84824+++ b/mm/slob.c
84825@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
84826 /*
84827 * Return the size of a slob block.
84828 */
84829-static slobidx_t slob_units(slob_t *s)
84830+static slobidx_t slob_units(const slob_t *s)
84831 {
84832 if (s->units > 0)
84833 return s->units;
84834@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
84835 /*
84836 * Return the next free slob block pointer after this one.
84837 */
84838-static slob_t *slob_next(slob_t *s)
84839+static slob_t *slob_next(const slob_t *s)
84840 {
84841 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
84842 slobidx_t next;
84843@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
84844 /*
84845 * Returns true if s is the last free block in its page.
84846 */
84847-static int slob_last(slob_t *s)
84848+static int slob_last(const slob_t *s)
84849 {
84850 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
84851 }
84852
84853-static void *slob_new_pages(gfp_t gfp, int order, int node)
84854+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
84855 {
84856- void *page;
84857+ struct page *page;
84858
84859 #ifdef CONFIG_NUMA
84860 if (node != NUMA_NO_NODE)
84861@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
84862 if (!page)
84863 return NULL;
84864
84865- return page_address(page);
84866+ __SetPageSlab(page);
84867+ return page;
84868 }
84869
84870-static void slob_free_pages(void *b, int order)
84871+static void slob_free_pages(struct page *sp, int order)
84872 {
84873 if (current->reclaim_state)
84874 current->reclaim_state->reclaimed_slab += 1 << order;
84875- free_pages((unsigned long)b, order);
84876+ __ClearPageSlab(sp);
84877+ reset_page_mapcount(sp);
84878+ sp->private = 0;
84879+ __free_pages(sp, order);
84880 }
84881
84882 /*
84883@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
84884
84885 /* Not enough space: must allocate a new page */
84886 if (!b) {
84887- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84888- if (!b)
84889+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84890+ if (!sp)
84891 return NULL;
84892- sp = virt_to_page(b);
84893- __SetPageSlab(sp);
84894+ b = page_address(sp);
84895
84896 spin_lock_irqsave(&slob_lock, flags);
84897 sp->units = SLOB_UNITS(PAGE_SIZE);
84898 sp->freelist = b;
84899+ sp->private = 0;
84900 INIT_LIST_HEAD(&sp->list);
84901 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
84902 set_slob_page_free(sp, slob_list);
84903@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
84904 if (slob_page_free(sp))
84905 clear_slob_page_free(sp);
84906 spin_unlock_irqrestore(&slob_lock, flags);
84907- __ClearPageSlab(sp);
84908- page_mapcount_reset(sp);
84909- slob_free_pages(b, 0);
84910+ slob_free_pages(sp, 0);
84911 return;
84912 }
84913
84914@@ -424,11 +426,10 @@ out:
84915 */
84916
84917 static __always_inline void *
84918-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84919+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
84920 {
84921- unsigned int *m;
84922- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84923- void *ret;
84924+ slob_t *m;
84925+ void *ret = NULL;
84926
84927 gfp &= gfp_allowed_mask;
84928
84929@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84930
84931 if (!m)
84932 return NULL;
84933- *m = size;
84934+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
84935+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
84936+ m[0].units = size;
84937+ m[1].units = align;
84938 ret = (void *)m + align;
84939
84940 trace_kmalloc_node(caller, ret,
84941 size, size + align, gfp, node);
84942 } else {
84943 unsigned int order = get_order(size);
84944+ struct page *page;
84945
84946 if (likely(order))
84947 gfp |= __GFP_COMP;
84948- ret = slob_new_pages(gfp, order, node);
84949+ page = slob_new_pages(gfp, order, node);
84950+ if (page) {
84951+ ret = page_address(page);
84952+ page->private = size;
84953+ }
84954
84955 trace_kmalloc_node(caller, ret,
84956 size, PAGE_SIZE << order, gfp, node);
84957 }
84958
84959- kmemleak_alloc(ret, size, 1, gfp);
84960+ return ret;
84961+}
84962+
84963+static __always_inline void *
84964+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84965+{
84966+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84967+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
84968+
84969+ if (!ZERO_OR_NULL_PTR(ret))
84970+ kmemleak_alloc(ret, size, 1, gfp);
84971 return ret;
84972 }
84973
84974@@ -493,34 +512,112 @@ void kfree(const void *block)
84975 return;
84976 kmemleak_free(block);
84977
84978+ VM_BUG_ON(!virt_addr_valid(block));
84979 sp = virt_to_page(block);
84980- if (PageSlab(sp)) {
84981+ VM_BUG_ON(!PageSlab(sp));
84982+ if (!sp->private) {
84983 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84984- unsigned int *m = (unsigned int *)(block - align);
84985- slob_free(m, *m + align);
84986- } else
84987+ slob_t *m = (slob_t *)(block - align);
84988+ slob_free(m, m[0].units + align);
84989+ } else {
84990+ __ClearPageSlab(sp);
84991+ reset_page_mapcount(sp);
84992+ sp->private = 0;
84993 __free_pages(sp, compound_order(sp));
84994+ }
84995 }
84996 EXPORT_SYMBOL(kfree);
84997
84998+bool is_usercopy_object(const void *ptr)
84999+{
85000+ if (!slab_is_available())
85001+ return false;
85002+
85003+ // PAX: TODO
85004+
85005+ return false;
85006+}
85007+
85008+#ifdef CONFIG_PAX_USERCOPY
85009+const char *check_heap_object(const void *ptr, unsigned long n)
85010+{
85011+ struct page *page;
85012+ const slob_t *free;
85013+ const void *base;
85014+ unsigned long flags;
85015+
85016+ if (ZERO_OR_NULL_PTR(ptr))
85017+ return "<null>";
85018+
85019+ if (!virt_addr_valid(ptr))
85020+ return NULL;
85021+
85022+ page = virt_to_head_page(ptr);
85023+ if (!PageSlab(page))
85024+ return NULL;
85025+
85026+ if (page->private) {
85027+ base = page;
85028+ if (base <= ptr && n <= page->private - (ptr - base))
85029+ return NULL;
85030+ return "<slob>";
85031+ }
85032+
85033+ /* some tricky double walking to find the chunk */
85034+ spin_lock_irqsave(&slob_lock, flags);
85035+ base = (void *)((unsigned long)ptr & PAGE_MASK);
85036+ free = page->freelist;
85037+
85038+ while (!slob_last(free) && (void *)free <= ptr) {
85039+ base = free + slob_units(free);
85040+ free = slob_next(free);
85041+ }
85042+
85043+ while (base < (void *)free) {
85044+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
85045+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
85046+ int offset;
85047+
85048+ if (ptr < base + align)
85049+ break;
85050+
85051+ offset = ptr - base - align;
85052+ if (offset >= m) {
85053+ base += size;
85054+ continue;
85055+ }
85056+
85057+ if (n > m - offset)
85058+ break;
85059+
85060+ spin_unlock_irqrestore(&slob_lock, flags);
85061+ return NULL;
85062+ }
85063+
85064+ spin_unlock_irqrestore(&slob_lock, flags);
85065+ return "<slob>";
85066+}
85067+#endif
85068+
85069 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
85070 size_t ksize(const void *block)
85071 {
85072 struct page *sp;
85073 int align;
85074- unsigned int *m;
85075+ slob_t *m;
85076
85077 BUG_ON(!block);
85078 if (unlikely(block == ZERO_SIZE_PTR))
85079 return 0;
85080
85081 sp = virt_to_page(block);
85082- if (unlikely(!PageSlab(sp)))
85083- return PAGE_SIZE << compound_order(sp);
85084+ VM_BUG_ON(!PageSlab(sp));
85085+ if (sp->private)
85086+ return sp->private;
85087
85088 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85089- m = (unsigned int *)(block - align);
85090- return SLOB_UNITS(*m) * SLOB_UNIT;
85091+ m = (slob_t *)(block - align);
85092+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
85093 }
85094 EXPORT_SYMBOL(ksize);
85095
85096@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
85097
85098 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
85099 {
85100- void *b;
85101+ void *b = NULL;
85102
85103 flags &= gfp_allowed_mask;
85104
85105 lockdep_trace_alloc(flags);
85106
85107+#ifdef CONFIG_PAX_USERCOPY_SLABS
85108+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
85109+#else
85110 if (c->size < PAGE_SIZE) {
85111 b = slob_alloc(c->size, flags, c->align, node);
85112 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
85113 SLOB_UNITS(c->size) * SLOB_UNIT,
85114 flags, node);
85115 } else {
85116- b = slob_new_pages(flags, get_order(c->size), node);
85117+ struct page *sp;
85118+
85119+ sp = slob_new_pages(flags, get_order(c->size), node);
85120+ if (sp) {
85121+ b = page_address(sp);
85122+ sp->private = c->size;
85123+ }
85124 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
85125 PAGE_SIZE << get_order(c->size),
85126 flags, node);
85127 }
85128+#endif
85129
85130 if (c->ctor)
85131 c->ctor(b);
85132@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
85133
85134 static void __kmem_cache_free(void *b, int size)
85135 {
85136- if (size < PAGE_SIZE)
85137+ struct page *sp;
85138+
85139+ sp = virt_to_page(b);
85140+ BUG_ON(!PageSlab(sp));
85141+ if (!sp->private)
85142 slob_free(b, size);
85143 else
85144- slob_free_pages(b, get_order(size));
85145+ slob_free_pages(sp, get_order(size));
85146 }
85147
85148 static void kmem_rcu_free(struct rcu_head *head)
85149@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
85150
85151 void kmem_cache_free(struct kmem_cache *c, void *b)
85152 {
85153+ int size = c->size;
85154+
85155+#ifdef CONFIG_PAX_USERCOPY_SLABS
85156+ if (size + c->align < PAGE_SIZE) {
85157+ size += c->align;
85158+ b -= c->align;
85159+ }
85160+#endif
85161+
85162 kmemleak_free_recursive(b, c->flags);
85163 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
85164 struct slob_rcu *slob_rcu;
85165- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
85166- slob_rcu->size = c->size;
85167+ slob_rcu = b + (size - sizeof(struct slob_rcu));
85168+ slob_rcu->size = size;
85169 call_rcu(&slob_rcu->head, kmem_rcu_free);
85170 } else {
85171- __kmem_cache_free(b, c->size);
85172+ __kmem_cache_free(b, size);
85173 }
85174
85175+#ifdef CONFIG_PAX_USERCOPY_SLABS
85176+ trace_kfree(_RET_IP_, b);
85177+#else
85178 trace_kmem_cache_free(_RET_IP_, b);
85179+#endif
85180+
85181 }
85182 EXPORT_SYMBOL(kmem_cache_free);
85183
85184diff --git a/mm/slub.c b/mm/slub.c
85185index 57707f0..c28619b 100644
85186--- a/mm/slub.c
85187+++ b/mm/slub.c
85188@@ -198,7 +198,7 @@ struct track {
85189
85190 enum track_item { TRACK_ALLOC, TRACK_FREE };
85191
85192-#ifdef CONFIG_SYSFS
85193+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85194 static int sysfs_slab_add(struct kmem_cache *);
85195 static int sysfs_slab_alias(struct kmem_cache *, const char *);
85196 static void sysfs_slab_remove(struct kmem_cache *);
85197@@ -519,7 +519,7 @@ static void print_track(const char *s, struct track *t)
85198 if (!t->addr)
85199 return;
85200
85201- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
85202+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
85203 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
85204 #ifdef CONFIG_STACKTRACE
85205 {
85206@@ -2661,7 +2661,7 @@ static int slub_min_objects;
85207 * Merge control. If this is set then no merging of slab caches will occur.
85208 * (Could be removed. This was introduced to pacify the merge skeptics.)
85209 */
85210-static int slub_nomerge;
85211+static int slub_nomerge = 1;
85212
85213 /*
85214 * Calculate the order of allocation given an slab object size.
85215@@ -3283,6 +3283,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
85216 EXPORT_SYMBOL(__kmalloc_node);
85217 #endif
85218
85219+bool is_usercopy_object(const void *ptr)
85220+{
85221+ struct page *page;
85222+ struct kmem_cache *s;
85223+
85224+ if (ZERO_OR_NULL_PTR(ptr))
85225+ return false;
85226+
85227+ if (!slab_is_available())
85228+ return false;
85229+
85230+ if (!virt_addr_valid(ptr))
85231+ return false;
85232+
85233+ page = virt_to_head_page(ptr);
85234+
85235+ if (!PageSlab(page))
85236+ return false;
85237+
85238+ s = page->slab_cache;
85239+ return s->flags & SLAB_USERCOPY;
85240+}
85241+
85242+#ifdef CONFIG_PAX_USERCOPY
85243+const char *check_heap_object(const void *ptr, unsigned long n)
85244+{
85245+ struct page *page;
85246+ struct kmem_cache *s;
85247+ unsigned long offset;
85248+
85249+ if (ZERO_OR_NULL_PTR(ptr))
85250+ return "<null>";
85251+
85252+ if (!virt_addr_valid(ptr))
85253+ return NULL;
85254+
85255+ page = virt_to_head_page(ptr);
85256+
85257+ if (!PageSlab(page))
85258+ return NULL;
85259+
85260+ s = page->slab_cache;
85261+ if (!(s->flags & SLAB_USERCOPY))
85262+ return s->name;
85263+
85264+ offset = (ptr - page_address(page)) % s->size;
85265+ if (offset <= s->object_size && n <= s->object_size - offset)
85266+ return NULL;
85267+
85268+ return s->name;
85269+}
85270+#endif
85271+
85272 size_t ksize(const void *object)
85273 {
85274 struct page *page;
85275@@ -3347,6 +3400,7 @@ void kfree(const void *x)
85276 if (unlikely(ZERO_OR_NULL_PTR(x)))
85277 return;
85278
85279+ VM_BUG_ON(!virt_addr_valid(x));
85280 page = virt_to_head_page(x);
85281 if (unlikely(!PageSlab(page))) {
85282 BUG_ON(!PageCompound(page));
85283@@ -3652,7 +3706,7 @@ static int slab_unmergeable(struct kmem_cache *s)
85284 /*
85285 * We may have set a slab to be unmergeable during bootstrap.
85286 */
85287- if (s->refcount < 0)
85288+ if (atomic_read(&s->refcount) < 0)
85289 return 1;
85290
85291 return 0;
85292@@ -3710,7 +3764,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85293
85294 s = find_mergeable(memcg, size, align, flags, name, ctor);
85295 if (s) {
85296- s->refcount++;
85297+ atomic_inc(&s->refcount);
85298 /*
85299 * Adjust the object sizes so that we clear
85300 * the complete object on kzalloc.
85301@@ -3719,7 +3773,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85302 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
85303
85304 if (sysfs_slab_alias(s, name)) {
85305- s->refcount--;
85306+ atomic_dec(&s->refcount);
85307 s = NULL;
85308 }
85309 }
85310@@ -3781,7 +3835,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
85311 return NOTIFY_OK;
85312 }
85313
85314-static struct notifier_block __cpuinitdata slab_notifier = {
85315+static struct notifier_block slab_notifier = {
85316 .notifier_call = slab_cpuup_callback
85317 };
85318
85319@@ -3839,7 +3893,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
85320 }
85321 #endif
85322
85323-#ifdef CONFIG_SYSFS
85324+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85325 static int count_inuse(struct page *page)
85326 {
85327 return page->inuse;
85328@@ -4226,12 +4280,12 @@ static void resiliency_test(void)
85329 validate_slab_cache(kmalloc_caches[9]);
85330 }
85331 #else
85332-#ifdef CONFIG_SYSFS
85333+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85334 static void resiliency_test(void) {};
85335 #endif
85336 #endif
85337
85338-#ifdef CONFIG_SYSFS
85339+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85340 enum slab_stat_type {
85341 SL_ALL, /* All slabs */
85342 SL_PARTIAL, /* Only partially allocated slabs */
85343@@ -4475,7 +4529,7 @@ SLAB_ATTR_RO(ctor);
85344
85345 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
85346 {
85347- return sprintf(buf, "%d\n", s->refcount - 1);
85348+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
85349 }
85350 SLAB_ATTR_RO(aliases);
85351
85352@@ -4563,6 +4617,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
85353 SLAB_ATTR_RO(cache_dma);
85354 #endif
85355
85356+#ifdef CONFIG_PAX_USERCOPY_SLABS
85357+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
85358+{
85359+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
85360+}
85361+SLAB_ATTR_RO(usercopy);
85362+#endif
85363+
85364 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
85365 {
85366 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
85367@@ -4897,6 +4959,9 @@ static struct attribute *slab_attrs[] = {
85368 #ifdef CONFIG_ZONE_DMA
85369 &cache_dma_attr.attr,
85370 #endif
85371+#ifdef CONFIG_PAX_USERCOPY_SLABS
85372+ &usercopy_attr.attr,
85373+#endif
85374 #ifdef CONFIG_NUMA
85375 &remote_node_defrag_ratio_attr.attr,
85376 #endif
85377@@ -5128,6 +5193,7 @@ static char *create_unique_id(struct kmem_cache *s)
85378 return name;
85379 }
85380
85381+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85382 static int sysfs_slab_add(struct kmem_cache *s)
85383 {
85384 int err;
85385@@ -5151,7 +5217,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
85386 }
85387
85388 s->kobj.kset = slab_kset;
85389- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
85390+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
85391 if (err) {
85392 kobject_put(&s->kobj);
85393 return err;
85394@@ -5185,6 +5251,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
85395 kobject_del(&s->kobj);
85396 kobject_put(&s->kobj);
85397 }
85398+#endif
85399
85400 /*
85401 * Need to buffer aliases during bootup until sysfs becomes
85402@@ -5198,6 +5265,7 @@ struct saved_alias {
85403
85404 static struct saved_alias *alias_list;
85405
85406+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85407 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85408 {
85409 struct saved_alias *al;
85410@@ -5220,6 +5288,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85411 alias_list = al;
85412 return 0;
85413 }
85414+#endif
85415
85416 static int __init slab_sysfs_init(void)
85417 {
85418diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
85419index 27eeab3..7c3f7f2 100644
85420--- a/mm/sparse-vmemmap.c
85421+++ b/mm/sparse-vmemmap.c
85422@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
85423 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85424 if (!p)
85425 return NULL;
85426- pud_populate(&init_mm, pud, p);
85427+ pud_populate_kernel(&init_mm, pud, p);
85428 }
85429 return pud;
85430 }
85431@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
85432 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85433 if (!p)
85434 return NULL;
85435- pgd_populate(&init_mm, pgd, p);
85436+ pgd_populate_kernel(&init_mm, pgd, p);
85437 }
85438 return pgd;
85439 }
85440diff --git a/mm/sparse.c b/mm/sparse.c
85441index 1c91f0d3..485470a 100644
85442--- a/mm/sparse.c
85443+++ b/mm/sparse.c
85444@@ -761,7 +761,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
85445
85446 for (i = 0; i < PAGES_PER_SECTION; i++) {
85447 if (PageHWPoison(&memmap[i])) {
85448- atomic_long_sub(1, &num_poisoned_pages);
85449+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
85450 ClearPageHWPoison(&memmap[i]);
85451 }
85452 }
85453diff --git a/mm/swap.c b/mm/swap.c
85454index dfd7d71..ccdf688 100644
85455--- a/mm/swap.c
85456+++ b/mm/swap.c
85457@@ -31,6 +31,7 @@
85458 #include <linux/memcontrol.h>
85459 #include <linux/gfp.h>
85460 #include <linux/uio.h>
85461+#include <linux/hugetlb.h>
85462
85463 #include "internal.h"
85464
85465@@ -73,6 +74,8 @@ static void __put_compound_page(struct page *page)
85466
85467 __page_cache_release(page);
85468 dtor = get_compound_page_dtor(page);
85469+ if (!PageHuge(page))
85470+ BUG_ON(dtor != free_compound_page);
85471 (*dtor)(page);
85472 }
85473
85474diff --git a/mm/swapfile.c b/mm/swapfile.c
85475index 746af55b..7ac94ae 100644
85476--- a/mm/swapfile.c
85477+++ b/mm/swapfile.c
85478@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
85479
85480 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
85481 /* Activity counter to indicate that a swapon or swapoff has occurred */
85482-static atomic_t proc_poll_event = ATOMIC_INIT(0);
85483+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
85484
85485 static inline unsigned char swap_count(unsigned char ent)
85486 {
85487@@ -1684,7 +1684,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
85488 }
85489 filp_close(swap_file, NULL);
85490 err = 0;
85491- atomic_inc(&proc_poll_event);
85492+ atomic_inc_unchecked(&proc_poll_event);
85493 wake_up_interruptible(&proc_poll_wait);
85494
85495 out_dput:
85496@@ -1701,8 +1701,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
85497
85498 poll_wait(file, &proc_poll_wait, wait);
85499
85500- if (seq->poll_event != atomic_read(&proc_poll_event)) {
85501- seq->poll_event = atomic_read(&proc_poll_event);
85502+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
85503+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85504 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
85505 }
85506
85507@@ -1800,7 +1800,7 @@ static int swaps_open(struct inode *inode, struct file *file)
85508 return ret;
85509
85510 seq = file->private_data;
85511- seq->poll_event = atomic_read(&proc_poll_event);
85512+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85513 return 0;
85514 }
85515
85516@@ -2143,7 +2143,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
85517 (frontswap_map) ? "FS" : "");
85518
85519 mutex_unlock(&swapon_mutex);
85520- atomic_inc(&proc_poll_event);
85521+ atomic_inc_unchecked(&proc_poll_event);
85522 wake_up_interruptible(&proc_poll_wait);
85523
85524 if (S_ISREG(inode->i_mode))
85525diff --git a/mm/util.c b/mm/util.c
85526index ab1424d..7c5bd5a 100644
85527--- a/mm/util.c
85528+++ b/mm/util.c
85529@@ -294,6 +294,12 @@ done:
85530 void arch_pick_mmap_layout(struct mm_struct *mm)
85531 {
85532 mm->mmap_base = TASK_UNMAPPED_BASE;
85533+
85534+#ifdef CONFIG_PAX_RANDMMAP
85535+ if (mm->pax_flags & MF_PAX_RANDMMAP)
85536+ mm->mmap_base += mm->delta_mmap;
85537+#endif
85538+
85539 mm->get_unmapped_area = arch_get_unmapped_area;
85540 mm->unmap_area = arch_unmap_area;
85541 }
85542diff --git a/mm/vmalloc.c b/mm/vmalloc.c
85543index d365724..6cae7c2 100644
85544--- a/mm/vmalloc.c
85545+++ b/mm/vmalloc.c
85546@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
85547
85548 pte = pte_offset_kernel(pmd, addr);
85549 do {
85550- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85551- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85552+
85553+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85554+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
85555+ BUG_ON(!pte_exec(*pte));
85556+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
85557+ continue;
85558+ }
85559+#endif
85560+
85561+ {
85562+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85563+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85564+ }
85565 } while (pte++, addr += PAGE_SIZE, addr != end);
85566 }
85567
85568@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
85569 pte = pte_alloc_kernel(pmd, addr);
85570 if (!pte)
85571 return -ENOMEM;
85572+
85573+ pax_open_kernel();
85574 do {
85575 struct page *page = pages[*nr];
85576
85577- if (WARN_ON(!pte_none(*pte)))
85578+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85579+ if (pgprot_val(prot) & _PAGE_NX)
85580+#endif
85581+
85582+ if (!pte_none(*pte)) {
85583+ pax_close_kernel();
85584+ WARN_ON(1);
85585 return -EBUSY;
85586- if (WARN_ON(!page))
85587+ }
85588+ if (!page) {
85589+ pax_close_kernel();
85590+ WARN_ON(1);
85591 return -ENOMEM;
85592+ }
85593 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
85594 (*nr)++;
85595 } while (pte++, addr += PAGE_SIZE, addr != end);
85596+ pax_close_kernel();
85597 return 0;
85598 }
85599
85600@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
85601 pmd_t *pmd;
85602 unsigned long next;
85603
85604- pmd = pmd_alloc(&init_mm, pud, addr);
85605+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85606 if (!pmd)
85607 return -ENOMEM;
85608 do {
85609@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
85610 pud_t *pud;
85611 unsigned long next;
85612
85613- pud = pud_alloc(&init_mm, pgd, addr);
85614+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85615 if (!pud)
85616 return -ENOMEM;
85617 do {
85618@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
85619 if (addr >= MODULES_VADDR && addr < MODULES_END)
85620 return 1;
85621 #endif
85622+
85623+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85624+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
85625+ return 1;
85626+#endif
85627+
85628 return is_vmalloc_addr(x);
85629 }
85630
85631@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
85632
85633 if (!pgd_none(*pgd)) {
85634 pud_t *pud = pud_offset(pgd, addr);
85635+#ifdef CONFIG_X86
85636+ if (!pud_large(*pud))
85637+#endif
85638 if (!pud_none(*pud)) {
85639 pmd_t *pmd = pmd_offset(pud, addr);
85640+#ifdef CONFIG_X86
85641+ if (!pmd_large(*pmd))
85642+#endif
85643 if (!pmd_none(*pmd)) {
85644 pte_t *ptep, pte;
85645
85646@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
85647 * Allocate a region of KVA of the specified size and alignment, within the
85648 * vstart and vend.
85649 */
85650-static struct vmap_area *alloc_vmap_area(unsigned long size,
85651+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
85652 unsigned long align,
85653 unsigned long vstart, unsigned long vend,
85654 int node, gfp_t gfp_mask)
85655@@ -1337,6 +1373,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
85656 struct vm_struct *area;
85657
85658 BUG_ON(in_interrupt());
85659+
85660+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85661+ if (flags & VM_KERNEXEC) {
85662+ if (start != VMALLOC_START || end != VMALLOC_END)
85663+ return NULL;
85664+ start = (unsigned long)MODULES_EXEC_VADDR;
85665+ end = (unsigned long)MODULES_EXEC_END;
85666+ }
85667+#endif
85668+
85669 if (flags & VM_IOREMAP) {
85670 int bit = fls(size);
85671
85672@@ -1581,6 +1627,11 @@ void *vmap(struct page **pages, unsigned int count,
85673 if (count > totalram_pages)
85674 return NULL;
85675
85676+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85677+ if (!(pgprot_val(prot) & _PAGE_NX))
85678+ flags |= VM_KERNEXEC;
85679+#endif
85680+
85681 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
85682 __builtin_return_address(0));
85683 if (!area)
85684@@ -1682,6 +1733,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
85685 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
85686 goto fail;
85687
85688+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85689+ if (!(pgprot_val(prot) & _PAGE_NX))
85690+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
85691+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
85692+ else
85693+#endif
85694+
85695 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
85696 start, end, node, gfp_mask, caller);
85697 if (!area)
85698@@ -1858,10 +1916,9 @@ EXPORT_SYMBOL(vzalloc_node);
85699 * For tight control over page level allocator and protection flags
85700 * use __vmalloc() instead.
85701 */
85702-
85703 void *vmalloc_exec(unsigned long size)
85704 {
85705- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
85706+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
85707 NUMA_NO_NODE, __builtin_return_address(0));
85708 }
85709
85710@@ -2168,6 +2225,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
85711 unsigned long uaddr = vma->vm_start;
85712 unsigned long usize = vma->vm_end - vma->vm_start;
85713
85714+ BUG_ON(vma->vm_mirror);
85715+
85716 if ((PAGE_SIZE-1) & (unsigned long)addr)
85717 return -EINVAL;
85718
85719@@ -2629,7 +2688,11 @@ static int s_show(struct seq_file *m, void *p)
85720 v->addr, v->addr + v->size, v->size);
85721
85722 if (v->caller)
85723+#ifdef CONFIG_GRKERNSEC_HIDESYM
85724+ seq_printf(m, " %pK", v->caller);
85725+#else
85726 seq_printf(m, " %pS", v->caller);
85727+#endif
85728
85729 if (v->nr_pages)
85730 seq_printf(m, " pages=%d", v->nr_pages);
85731diff --git a/mm/vmstat.c b/mm/vmstat.c
85732index f42745e..62f8346 100644
85733--- a/mm/vmstat.c
85734+++ b/mm/vmstat.c
85735@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
85736 *
85737 * vm_stat contains the global counters
85738 */
85739-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85740+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85741 EXPORT_SYMBOL(vm_stat);
85742
85743 #ifdef CONFIG_SMP
85744@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
85745 v = p->vm_stat_diff[i];
85746 p->vm_stat_diff[i] = 0;
85747 local_irq_restore(flags);
85748- atomic_long_add(v, &zone->vm_stat[i]);
85749+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85750 global_diff[i] += v;
85751 #ifdef CONFIG_NUMA
85752 /* 3 seconds idle till flush */
85753@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
85754
85755 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
85756 if (global_diff[i])
85757- atomic_long_add(global_diff[i], &vm_stat[i]);
85758+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
85759 }
85760
85761 /*
85762@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85763 if (pset->vm_stat_diff[i]) {
85764 int v = pset->vm_stat_diff[i];
85765 pset->vm_stat_diff[i] = 0;
85766- atomic_long_add(v, &zone->vm_stat[i]);
85767- atomic_long_add(v, &vm_stat[i]);
85768+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85769+ atomic_long_add_unchecked(v, &vm_stat[i]);
85770 }
85771 }
85772 #endif
85773@@ -1226,7 +1226,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
85774 return NOTIFY_OK;
85775 }
85776
85777-static struct notifier_block __cpuinitdata vmstat_notifier =
85778+static struct notifier_block vmstat_notifier =
85779 { &vmstat_cpuup_callback, NULL, 0 };
85780 #endif
85781
85782@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
85783 start_cpu_timer(cpu);
85784 #endif
85785 #ifdef CONFIG_PROC_FS
85786- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
85787- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
85788- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
85789- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
85790+ {
85791+ mode_t gr_mode = S_IRUGO;
85792+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85793+ gr_mode = S_IRUSR;
85794+#endif
85795+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
85796+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
85797+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85798+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
85799+#else
85800+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
85801+#endif
85802+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
85803+ }
85804 #endif
85805 return 0;
85806 }
85807diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
85808index 9424f37..6aabf19 100644
85809--- a/net/8021q/vlan.c
85810+++ b/net/8021q/vlan.c
85811@@ -469,7 +469,7 @@ out:
85812 return NOTIFY_DONE;
85813 }
85814
85815-static struct notifier_block vlan_notifier_block __read_mostly = {
85816+static struct notifier_block vlan_notifier_block = {
85817 .notifier_call = vlan_device_event,
85818 };
85819
85820@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
85821 err = -EPERM;
85822 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
85823 break;
85824- if ((args.u.name_type >= 0) &&
85825- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
85826+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
85827 struct vlan_net *vn;
85828
85829 vn = net_generic(net, vlan_net_id);
85830diff --git a/net/9p/mod.c b/net/9p/mod.c
85831index 6ab36ae..6f1841b 100644
85832--- a/net/9p/mod.c
85833+++ b/net/9p/mod.c
85834@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
85835 void v9fs_register_trans(struct p9_trans_module *m)
85836 {
85837 spin_lock(&v9fs_trans_lock);
85838- list_add_tail(&m->list, &v9fs_trans_list);
85839+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
85840 spin_unlock(&v9fs_trans_lock);
85841 }
85842 EXPORT_SYMBOL(v9fs_register_trans);
85843@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
85844 void v9fs_unregister_trans(struct p9_trans_module *m)
85845 {
85846 spin_lock(&v9fs_trans_lock);
85847- list_del_init(&m->list);
85848+ pax_list_del_init((struct list_head *)&m->list);
85849 spin_unlock(&v9fs_trans_lock);
85850 }
85851 EXPORT_SYMBOL(v9fs_unregister_trans);
85852diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
85853index 02efb25..41541a9 100644
85854--- a/net/9p/trans_fd.c
85855+++ b/net/9p/trans_fd.c
85856@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
85857 oldfs = get_fs();
85858 set_fs(get_ds());
85859 /* The cast to a user pointer is valid due to the set_fs() */
85860- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
85861+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
85862 set_fs(oldfs);
85863
85864 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
85865diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
85866index 876fbe8..8bbea9f 100644
85867--- a/net/atm/atm_misc.c
85868+++ b/net/atm/atm_misc.c
85869@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
85870 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
85871 return 1;
85872 atm_return(vcc, truesize);
85873- atomic_inc(&vcc->stats->rx_drop);
85874+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85875 return 0;
85876 }
85877 EXPORT_SYMBOL(atm_charge);
85878@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
85879 }
85880 }
85881 atm_return(vcc, guess);
85882- atomic_inc(&vcc->stats->rx_drop);
85883+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85884 return NULL;
85885 }
85886 EXPORT_SYMBOL(atm_alloc_charge);
85887@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
85888
85889 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85890 {
85891-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85892+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85893 __SONET_ITEMS
85894 #undef __HANDLE_ITEM
85895 }
85896@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
85897
85898 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85899 {
85900-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85901+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
85902 __SONET_ITEMS
85903 #undef __HANDLE_ITEM
85904 }
85905diff --git a/net/atm/lec.h b/net/atm/lec.h
85906index 4149db1..f2ab682 100644
85907--- a/net/atm/lec.h
85908+++ b/net/atm/lec.h
85909@@ -48,7 +48,7 @@ struct lane2_ops {
85910 const u8 *tlvs, u32 sizeoftlvs);
85911 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
85912 const u8 *tlvs, u32 sizeoftlvs);
85913-};
85914+} __no_const;
85915
85916 /*
85917 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
85918diff --git a/net/atm/proc.c b/net/atm/proc.c
85919index bbb6461..cf04016 100644
85920--- a/net/atm/proc.c
85921+++ b/net/atm/proc.c
85922@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
85923 const struct k_atm_aal_stats *stats)
85924 {
85925 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
85926- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
85927- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
85928- atomic_read(&stats->rx_drop));
85929+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
85930+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
85931+ atomic_read_unchecked(&stats->rx_drop));
85932 }
85933
85934 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
85935diff --git a/net/atm/resources.c b/net/atm/resources.c
85936index 0447d5d..3cf4728 100644
85937--- a/net/atm/resources.c
85938+++ b/net/atm/resources.c
85939@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
85940 static void copy_aal_stats(struct k_atm_aal_stats *from,
85941 struct atm_aal_stats *to)
85942 {
85943-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85944+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85945 __AAL_STAT_ITEMS
85946 #undef __HANDLE_ITEM
85947 }
85948@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
85949 static void subtract_aal_stats(struct k_atm_aal_stats *from,
85950 struct atm_aal_stats *to)
85951 {
85952-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85953+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
85954 __AAL_STAT_ITEMS
85955 #undef __HANDLE_ITEM
85956 }
85957diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
85958index d5744b7..506bae3 100644
85959--- a/net/ax25/sysctl_net_ax25.c
85960+++ b/net/ax25/sysctl_net_ax25.c
85961@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
85962 {
85963 char path[sizeof("net/ax25/") + IFNAMSIZ];
85964 int k;
85965- struct ctl_table *table;
85966+ ctl_table_no_const *table;
85967
85968 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
85969 if (!table)
85970diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
85971index f680ee1..97e3542 100644
85972--- a/net/batman-adv/bat_iv_ogm.c
85973+++ b/net/batman-adv/bat_iv_ogm.c
85974@@ -79,7 +79,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
85975
85976 /* randomize initial seqno to avoid collision */
85977 get_random_bytes(&random_seqno, sizeof(random_seqno));
85978- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85979+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85980
85981 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
85982 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
85983@@ -627,9 +627,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
85984 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
85985
85986 /* change sequence number to network order */
85987- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
85988+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
85989 batadv_ogm_packet->seqno = htonl(seqno);
85990- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
85991+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
85992
85993 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
85994 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
85995@@ -1037,7 +1037,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
85996 return;
85997
85998 /* could be changed by schedule_own_packet() */
85999- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
86000+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
86001
86002 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
86003 has_directlink_flag = 1;
86004diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
86005index 522243a..b48c0ef 100644
86006--- a/net/batman-adv/hard-interface.c
86007+++ b/net/batman-adv/hard-interface.c
86008@@ -401,7 +401,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
86009 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
86010 dev_add_pack(&hard_iface->batman_adv_ptype);
86011
86012- atomic_set(&hard_iface->frag_seqno, 1);
86013+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
86014 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
86015 hard_iface->net_dev->name);
86016
86017@@ -550,7 +550,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
86018 /* This can't be called via a bat_priv callback because
86019 * we have no bat_priv yet.
86020 */
86021- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
86022+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
86023 hard_iface->bat_iv.ogm_buff = NULL;
86024
86025 return hard_iface;
86026diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
86027index 819dfb0..9a672d1 100644
86028--- a/net/batman-adv/soft-interface.c
86029+++ b/net/batman-adv/soft-interface.c
86030@@ -253,7 +253,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
86031 primary_if->net_dev->dev_addr, ETH_ALEN);
86032
86033 /* set broadcast sequence number */
86034- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
86035+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
86036 bcast_packet->seqno = htonl(seqno);
86037
86038 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
86039@@ -472,7 +472,7 @@ static int batadv_softif_init_late(struct net_device *dev)
86040 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
86041
86042 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
86043- atomic_set(&bat_priv->bcast_seqno, 1);
86044+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
86045 atomic_set(&bat_priv->tt.vn, 0);
86046 atomic_set(&bat_priv->tt.local_changes, 0);
86047 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
86048diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
86049index aba8364..50fcbb8 100644
86050--- a/net/batman-adv/types.h
86051+++ b/net/batman-adv/types.h
86052@@ -51,7 +51,7 @@
86053 struct batadv_hard_iface_bat_iv {
86054 unsigned char *ogm_buff;
86055 int ogm_buff_len;
86056- atomic_t ogm_seqno;
86057+ atomic_unchecked_t ogm_seqno;
86058 };
86059
86060 /**
86061@@ -75,7 +75,7 @@ struct batadv_hard_iface {
86062 int16_t if_num;
86063 char if_status;
86064 struct net_device *net_dev;
86065- atomic_t frag_seqno;
86066+ atomic_unchecked_t frag_seqno;
86067 struct kobject *hardif_obj;
86068 atomic_t refcount;
86069 struct packet_type batman_adv_ptype;
86070@@ -558,7 +558,7 @@ struct batadv_priv {
86071 #ifdef CONFIG_BATMAN_ADV_DEBUG
86072 atomic_t log_level;
86073 #endif
86074- atomic_t bcast_seqno;
86075+ atomic_unchecked_t bcast_seqno;
86076 atomic_t bcast_queue_left;
86077 atomic_t batman_queue_left;
86078 char num_ifaces;
86079diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
86080index 0bb3b59..ffcbf2f 100644
86081--- a/net/batman-adv/unicast.c
86082+++ b/net/batman-adv/unicast.c
86083@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
86084 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
86085 frag2->flags = large_tail;
86086
86087- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
86088+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
86089 frag1->seqno = htons(seqno - 1);
86090 frag2->seqno = htons(seqno);
86091
86092diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
86093index ace5e55..a65a1c0 100644
86094--- a/net/bluetooth/hci_core.c
86095+++ b/net/bluetooth/hci_core.c
86096@@ -2211,16 +2211,16 @@ int hci_register_dev(struct hci_dev *hdev)
86097 list_add(&hdev->list, &hci_dev_list);
86098 write_unlock(&hci_dev_list_lock);
86099
86100- hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND |
86101- WQ_MEM_RECLAIM, 1);
86102+ hdev->workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
86103+ WQ_MEM_RECLAIM, 1, hdev->name);
86104 if (!hdev->workqueue) {
86105 error = -ENOMEM;
86106 goto err;
86107 }
86108
86109- hdev->req_workqueue = alloc_workqueue(hdev->name,
86110+ hdev->req_workqueue = alloc_workqueue("%s",
86111 WQ_HIGHPRI | WQ_UNBOUND |
86112- WQ_MEM_RECLAIM, 1);
86113+ WQ_MEM_RECLAIM, 1, hdev->name);
86114 if (!hdev->req_workqueue) {
86115 destroy_workqueue(hdev->workqueue);
86116 error = -ENOMEM;
86117diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
86118index 9bd7d95..6c4884f 100644
86119--- a/net/bluetooth/hci_sock.c
86120+++ b/net/bluetooth/hci_sock.c
86121@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
86122 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
86123 }
86124
86125- len = min_t(unsigned int, len, sizeof(uf));
86126+ len = min((size_t)len, sizeof(uf));
86127 if (copy_from_user(&uf, optval, len)) {
86128 err = -EFAULT;
86129 break;
86130diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
86131index 68843a2..30e9342 100644
86132--- a/net/bluetooth/l2cap_core.c
86133+++ b/net/bluetooth/l2cap_core.c
86134@@ -3507,8 +3507,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
86135 break;
86136
86137 case L2CAP_CONF_RFC:
86138- if (olen == sizeof(rfc))
86139- memcpy(&rfc, (void *)val, olen);
86140+ if (olen != sizeof(rfc))
86141+ break;
86142+
86143+ memcpy(&rfc, (void *)val, olen);
86144
86145 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
86146 rfc.mode != chan->mode)
86147diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
86148index 36fed40..be2eeb2 100644
86149--- a/net/bluetooth/l2cap_sock.c
86150+++ b/net/bluetooth/l2cap_sock.c
86151@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
86152 struct sock *sk = sock->sk;
86153 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
86154 struct l2cap_options opts;
86155- int len, err = 0;
86156+ int err = 0;
86157+ size_t len = optlen;
86158 u32 opt;
86159
86160 BT_DBG("sk %p", sk);
86161@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
86162 opts.max_tx = chan->max_tx;
86163 opts.txwin_size = chan->tx_win;
86164
86165- len = min_t(unsigned int, sizeof(opts), optlen);
86166+ len = min(sizeof(opts), len);
86167 if (copy_from_user((char *) &opts, optval, len)) {
86168 err = -EFAULT;
86169 break;
86170@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86171 struct bt_security sec;
86172 struct bt_power pwr;
86173 struct l2cap_conn *conn;
86174- int len, err = 0;
86175+ int err = 0;
86176+ size_t len = optlen;
86177 u32 opt;
86178
86179 BT_DBG("sk %p", sk);
86180@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86181
86182 sec.level = BT_SECURITY_LOW;
86183
86184- len = min_t(unsigned int, sizeof(sec), optlen);
86185+ len = min(sizeof(sec), len);
86186 if (copy_from_user((char *) &sec, optval, len)) {
86187 err = -EFAULT;
86188 break;
86189@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86190
86191 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
86192
86193- len = min_t(unsigned int, sizeof(pwr), optlen);
86194+ len = min(sizeof(pwr), len);
86195 if (copy_from_user((char *) &pwr, optval, len)) {
86196 err = -EFAULT;
86197 break;
86198diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
86199index 30b3721..c1bd0a0 100644
86200--- a/net/bluetooth/rfcomm/sock.c
86201+++ b/net/bluetooth/rfcomm/sock.c
86202@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
86203 struct sock *sk = sock->sk;
86204 struct bt_security sec;
86205 int err = 0;
86206- size_t len;
86207+ size_t len = optlen;
86208 u32 opt;
86209
86210 BT_DBG("sk %p", sk);
86211@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
86212
86213 sec.level = BT_SECURITY_LOW;
86214
86215- len = min_t(unsigned int, sizeof(sec), optlen);
86216+ len = min(sizeof(sec), len);
86217 if (copy_from_user((char *) &sec, optval, len)) {
86218 err = -EFAULT;
86219 break;
86220diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
86221index b6e44ad..5b0d514 100644
86222--- a/net/bluetooth/rfcomm/tty.c
86223+++ b/net/bluetooth/rfcomm/tty.c
86224@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
86225 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
86226
86227 spin_lock_irqsave(&dev->port.lock, flags);
86228- if (dev->port.count > 0) {
86229+ if (atomic_read(&dev->port.count) > 0) {
86230 spin_unlock_irqrestore(&dev->port.lock, flags);
86231 return;
86232 }
86233@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
86234 return -ENODEV;
86235
86236 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
86237- dev->channel, dev->port.count);
86238+ dev->channel, atomic_read(&dev->port.count));
86239
86240 spin_lock_irqsave(&dev->port.lock, flags);
86241- if (++dev->port.count > 1) {
86242+ if (atomic_inc_return(&dev->port.count) > 1) {
86243 spin_unlock_irqrestore(&dev->port.lock, flags);
86244 return 0;
86245 }
86246@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
86247 return;
86248
86249 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
86250- dev->port.count);
86251+ atomic_read(&dev->port.count));
86252
86253 spin_lock_irqsave(&dev->port.lock, flags);
86254- if (!--dev->port.count) {
86255+ if (!atomic_dec_return(&dev->port.count)) {
86256 spin_unlock_irqrestore(&dev->port.lock, flags);
86257 if (dev->tty_dev->parent)
86258 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
86259diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
86260index 3d110c4..4e1b2eb 100644
86261--- a/net/bridge/netfilter/ebtables.c
86262+++ b/net/bridge/netfilter/ebtables.c
86263@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86264 tmp.valid_hooks = t->table->valid_hooks;
86265 }
86266 mutex_unlock(&ebt_mutex);
86267- if (copy_to_user(user, &tmp, *len) != 0){
86268+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
86269 BUGPRINT("c2u Didn't work\n");
86270 ret = -EFAULT;
86271 break;
86272@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
86273 goto out;
86274 tmp.valid_hooks = t->valid_hooks;
86275
86276- if (copy_to_user(user, &tmp, *len) != 0) {
86277+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
86278 ret = -EFAULT;
86279 break;
86280 }
86281@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
86282 tmp.entries_size = t->table->entries_size;
86283 tmp.valid_hooks = t->table->valid_hooks;
86284
86285- if (copy_to_user(user, &tmp, *len) != 0) {
86286+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
86287 ret = -EFAULT;
86288 break;
86289 }
86290diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
86291index 2bd4b58..0dc30a1 100644
86292--- a/net/caif/cfctrl.c
86293+++ b/net/caif/cfctrl.c
86294@@ -10,6 +10,7 @@
86295 #include <linux/spinlock.h>
86296 #include <linux/slab.h>
86297 #include <linux/pkt_sched.h>
86298+#include <linux/sched.h>
86299 #include <net/caif/caif_layer.h>
86300 #include <net/caif/cfpkt.h>
86301 #include <net/caif/cfctrl.h>
86302@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
86303 memset(&dev_info, 0, sizeof(dev_info));
86304 dev_info.id = 0xff;
86305 cfsrvl_init(&this->serv, 0, &dev_info, false);
86306- atomic_set(&this->req_seq_no, 1);
86307- atomic_set(&this->rsp_seq_no, 1);
86308+ atomic_set_unchecked(&this->req_seq_no, 1);
86309+ atomic_set_unchecked(&this->rsp_seq_no, 1);
86310 this->serv.layer.receive = cfctrl_recv;
86311 sprintf(this->serv.layer.name, "ctrl");
86312 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
86313@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
86314 struct cfctrl_request_info *req)
86315 {
86316 spin_lock_bh(&ctrl->info_list_lock);
86317- atomic_inc(&ctrl->req_seq_no);
86318- req->sequence_no = atomic_read(&ctrl->req_seq_no);
86319+ atomic_inc_unchecked(&ctrl->req_seq_no);
86320+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
86321 list_add_tail(&req->list, &ctrl->list);
86322 spin_unlock_bh(&ctrl->info_list_lock);
86323 }
86324@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
86325 if (p != first)
86326 pr_warn("Requests are not received in order\n");
86327
86328- atomic_set(&ctrl->rsp_seq_no,
86329+ atomic_set_unchecked(&ctrl->rsp_seq_no,
86330 p->sequence_no);
86331 list_del(&p->list);
86332 goto out;
86333diff --git a/net/can/af_can.c b/net/can/af_can.c
86334index c4e5085..aa9efdf 100644
86335--- a/net/can/af_can.c
86336+++ b/net/can/af_can.c
86337@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
86338 };
86339
86340 /* notifier block for netdevice event */
86341-static struct notifier_block can_netdev_notifier __read_mostly = {
86342+static struct notifier_block can_netdev_notifier = {
86343 .notifier_call = can_notifier,
86344 };
86345
86346diff --git a/net/can/gw.c b/net/can/gw.c
86347index 3ee690e..00d581b 100644
86348--- a/net/can/gw.c
86349+++ b/net/can/gw.c
86350@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
86351 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
86352
86353 static HLIST_HEAD(cgw_list);
86354-static struct notifier_block notifier;
86355
86356 static struct kmem_cache *cgw_cache __read_mostly;
86357
86358@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
86359 return err;
86360 }
86361
86362+static struct notifier_block notifier = {
86363+ .notifier_call = cgw_notifier
86364+};
86365+
86366 static __init int cgw_module_init(void)
86367 {
86368 /* sanitize given module parameter */
86369@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
86370 return -ENOMEM;
86371
86372 /* set notifier */
86373- notifier.notifier_call = cgw_notifier;
86374 register_netdevice_notifier(&notifier);
86375
86376 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
86377diff --git a/net/compat.c b/net/compat.c
86378index f0a1ba6..0541331 100644
86379--- a/net/compat.c
86380+++ b/net/compat.c
86381@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
86382 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
86383 __get_user(kmsg->msg_flags, &umsg->msg_flags))
86384 return -EFAULT;
86385- kmsg->msg_name = compat_ptr(tmp1);
86386- kmsg->msg_iov = compat_ptr(tmp2);
86387- kmsg->msg_control = compat_ptr(tmp3);
86388+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
86389+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
86390+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
86391 return 0;
86392 }
86393
86394@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86395
86396 if (kern_msg->msg_namelen) {
86397 if (mode == VERIFY_READ) {
86398- int err = move_addr_to_kernel(kern_msg->msg_name,
86399+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
86400 kern_msg->msg_namelen,
86401 kern_address);
86402 if (err < 0)
86403@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86404 kern_msg->msg_name = NULL;
86405
86406 tot_len = iov_from_user_compat_to_kern(kern_iov,
86407- (struct compat_iovec __user *)kern_msg->msg_iov,
86408+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
86409 kern_msg->msg_iovlen);
86410 if (tot_len >= 0)
86411 kern_msg->msg_iov = kern_iov;
86412@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86413
86414 #define CMSG_COMPAT_FIRSTHDR(msg) \
86415 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
86416- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
86417+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
86418 (struct compat_cmsghdr __user *)NULL)
86419
86420 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
86421 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
86422 (ucmlen) <= (unsigned long) \
86423 ((mhdr)->msg_controllen - \
86424- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
86425+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
86426
86427 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
86428 struct compat_cmsghdr __user *cmsg, int cmsg_len)
86429 {
86430 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
86431- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
86432+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
86433 msg->msg_controllen)
86434 return NULL;
86435 return (struct compat_cmsghdr __user *)ptr;
86436@@ -219,7 +219,7 @@ Efault:
86437
86438 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
86439 {
86440- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86441+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86442 struct compat_cmsghdr cmhdr;
86443 struct compat_timeval ctv;
86444 struct compat_timespec cts[3];
86445@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
86446
86447 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
86448 {
86449- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86450+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86451 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
86452 int fdnum = scm->fp->count;
86453 struct file **fp = scm->fp->fp;
86454@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
86455 return -EFAULT;
86456 old_fs = get_fs();
86457 set_fs(KERNEL_DS);
86458- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
86459+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
86460 set_fs(old_fs);
86461
86462 return err;
86463@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
86464 len = sizeof(ktime);
86465 old_fs = get_fs();
86466 set_fs(KERNEL_DS);
86467- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
86468+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
86469 set_fs(old_fs);
86470
86471 if (!err) {
86472@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86473 case MCAST_JOIN_GROUP:
86474 case MCAST_LEAVE_GROUP:
86475 {
86476- struct compat_group_req __user *gr32 = (void *)optval;
86477+ struct compat_group_req __user *gr32 = (void __user *)optval;
86478 struct group_req __user *kgr =
86479 compat_alloc_user_space(sizeof(struct group_req));
86480 u32 interface;
86481@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86482 case MCAST_BLOCK_SOURCE:
86483 case MCAST_UNBLOCK_SOURCE:
86484 {
86485- struct compat_group_source_req __user *gsr32 = (void *)optval;
86486+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
86487 struct group_source_req __user *kgsr = compat_alloc_user_space(
86488 sizeof(struct group_source_req));
86489 u32 interface;
86490@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86491 }
86492 case MCAST_MSFILTER:
86493 {
86494- struct compat_group_filter __user *gf32 = (void *)optval;
86495+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86496 struct group_filter __user *kgf;
86497 u32 interface, fmode, numsrc;
86498
86499@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
86500 char __user *optval, int __user *optlen,
86501 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
86502 {
86503- struct compat_group_filter __user *gf32 = (void *)optval;
86504+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86505 struct group_filter __user *kgf;
86506 int __user *koptlen;
86507 u32 interface, fmode, numsrc;
86508@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
86509
86510 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
86511 return -EINVAL;
86512- if (copy_from_user(a, args, nas[call]))
86513+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
86514 return -EFAULT;
86515 a0 = a[0];
86516 a1 = a[1];
86517diff --git a/net/core/datagram.c b/net/core/datagram.c
86518index b71423d..0360434 100644
86519--- a/net/core/datagram.c
86520+++ b/net/core/datagram.c
86521@@ -295,7 +295,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
86522 }
86523
86524 kfree_skb(skb);
86525- atomic_inc(&sk->sk_drops);
86526+ atomic_inc_unchecked(&sk->sk_drops);
86527 sk_mem_reclaim_partial(sk);
86528
86529 return err;
86530diff --git a/net/core/dev.c b/net/core/dev.c
86531index faebb39..a38fb42 100644
86532--- a/net/core/dev.c
86533+++ b/net/core/dev.c
86534@@ -1649,7 +1649,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86535 {
86536 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
86537 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
86538- atomic_long_inc(&dev->rx_dropped);
86539+ atomic_long_inc_unchecked(&dev->rx_dropped);
86540 kfree_skb(skb);
86541 return NET_RX_DROP;
86542 }
86543@@ -1658,7 +1658,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86544 skb_orphan(skb);
86545
86546 if (unlikely(!is_skb_forwardable(dev, skb))) {
86547- atomic_long_inc(&dev->rx_dropped);
86548+ atomic_long_inc_unchecked(&dev->rx_dropped);
86549 kfree_skb(skb);
86550 return NET_RX_DROP;
86551 }
86552@@ -2404,7 +2404,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
86553
86554 struct dev_gso_cb {
86555 void (*destructor)(struct sk_buff *skb);
86556-};
86557+} __no_const;
86558
86559 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
86560
86561@@ -3139,7 +3139,7 @@ enqueue:
86562
86563 local_irq_restore(flags);
86564
86565- atomic_long_inc(&skb->dev->rx_dropped);
86566+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86567 kfree_skb(skb);
86568 return NET_RX_DROP;
86569 }
86570@@ -3211,7 +3211,7 @@ int netif_rx_ni(struct sk_buff *skb)
86571 }
86572 EXPORT_SYMBOL(netif_rx_ni);
86573
86574-static void net_tx_action(struct softirq_action *h)
86575+static void net_tx_action(void)
86576 {
86577 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86578
86579@@ -3538,7 +3538,7 @@ ncls:
86580 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
86581 } else {
86582 drop:
86583- atomic_long_inc(&skb->dev->rx_dropped);
86584+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86585 kfree_skb(skb);
86586 /* Jamal, now you will not able to escape explaining
86587 * me how you were going to use this. :-)
86588@@ -4146,7 +4146,7 @@ void netif_napi_del(struct napi_struct *napi)
86589 }
86590 EXPORT_SYMBOL(netif_napi_del);
86591
86592-static void net_rx_action(struct softirq_action *h)
86593+static void net_rx_action(void)
86594 {
86595 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86596 unsigned long time_limit = jiffies + 2;
86597@@ -5583,7 +5583,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
86598 } else {
86599 netdev_stats_to_stats64(storage, &dev->stats);
86600 }
86601- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
86602+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
86603 return storage;
86604 }
86605 EXPORT_SYMBOL(dev_get_stats);
86606diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
86607index 5b7d0e1..cb960fc 100644
86608--- a/net/core/dev_ioctl.c
86609+++ b/net/core/dev_ioctl.c
86610@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
86611 if (no_module && capable(CAP_NET_ADMIN))
86612 no_module = request_module("netdev-%s", name);
86613 if (no_module && capable(CAP_SYS_MODULE)) {
86614+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86615+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
86616+#else
86617 if (!request_module("%s", name))
86618 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
86619 name);
86620+#endif
86621 }
86622 }
86623 EXPORT_SYMBOL(dev_load);
86624diff --git a/net/core/ethtool.c b/net/core/ethtool.c
86625index ce91766..3b71cdb 100644
86626--- a/net/core/ethtool.c
86627+++ b/net/core/ethtool.c
86628@@ -1319,10 +1319,19 @@ static int ethtool_get_dump_data(struct net_device *dev,
86629 if (ret)
86630 return ret;
86631
86632- len = (tmp.len > dump.len) ? dump.len : tmp.len;
86633+ len = min(tmp.len, dump.len);
86634 if (!len)
86635 return -EFAULT;
86636
86637+ /* Don't ever let the driver think there's more space available
86638+ * than it requested with .get_dump_flag().
86639+ */
86640+ dump.len = len;
86641+
86642+ /* Always allocate enough space to hold the whole thing so that the
86643+ * driver does not need to check the length and bother with partial
86644+ * dumping.
86645+ */
86646 data = vzalloc(tmp.len);
86647 if (!data)
86648 return -ENOMEM;
86649@@ -1330,6 +1339,16 @@ static int ethtool_get_dump_data(struct net_device *dev,
86650 if (ret)
86651 goto out;
86652
86653+ /* There are two sane possibilities:
86654+ * 1. The driver's .get_dump_data() does not touch dump.len.
86655+ * 2. Or it may set dump.len to how much it really writes, which
86656+ * should be tmp.len (or len if it can do a partial dump).
86657+ * In any case respond to userspace with the actual length of data
86658+ * it's receiving.
86659+ */
86660+ WARN_ON(dump.len != len && dump.len != tmp.len);
86661+ dump.len = len;
86662+
86663 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
86664 ret = -EFAULT;
86665 goto out;
86666diff --git a/net/core/flow.c b/net/core/flow.c
86667index 7102f16..146b4bd 100644
86668--- a/net/core/flow.c
86669+++ b/net/core/flow.c
86670@@ -61,7 +61,7 @@ struct flow_cache {
86671 struct timer_list rnd_timer;
86672 };
86673
86674-atomic_t flow_cache_genid = ATOMIC_INIT(0);
86675+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
86676 EXPORT_SYMBOL(flow_cache_genid);
86677 static struct flow_cache flow_cache_global;
86678 static struct kmem_cache *flow_cachep __read_mostly;
86679@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
86680
86681 static int flow_entry_valid(struct flow_cache_entry *fle)
86682 {
86683- if (atomic_read(&flow_cache_genid) != fle->genid)
86684+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
86685 return 0;
86686 if (fle->object && !fle->object->ops->check(fle->object))
86687 return 0;
86688@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
86689 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
86690 fcp->hash_count++;
86691 }
86692- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
86693+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
86694 flo = fle->object;
86695 if (!flo)
86696 goto ret_object;
86697@@ -279,7 +279,7 @@ nocache:
86698 }
86699 flo = resolver(net, key, family, dir, flo, ctx);
86700 if (fle) {
86701- fle->genid = atomic_read(&flow_cache_genid);
86702+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
86703 if (!IS_ERR(flo))
86704 fle->object = flo;
86705 else
86706diff --git a/net/core/iovec.c b/net/core/iovec.c
86707index de178e4..1dabd8b 100644
86708--- a/net/core/iovec.c
86709+++ b/net/core/iovec.c
86710@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86711 if (m->msg_namelen) {
86712 if (mode == VERIFY_READ) {
86713 void __user *namep;
86714- namep = (void __user __force *) m->msg_name;
86715+ namep = (void __force_user *) m->msg_name;
86716 err = move_addr_to_kernel(namep, m->msg_namelen,
86717 address);
86718 if (err < 0)
86719@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86720 }
86721
86722 size = m->msg_iovlen * sizeof(struct iovec);
86723- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
86724+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
86725 return -EFAULT;
86726
86727 m->msg_iov = iov;
86728diff --git a/net/core/neighbour.c b/net/core/neighbour.c
86729index 5c56b21..8766fbf 100644
86730--- a/net/core/neighbour.c
86731+++ b/net/core/neighbour.c
86732@@ -2769,7 +2769,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
86733 size_t *lenp, loff_t *ppos)
86734 {
86735 int size, ret;
86736- ctl_table tmp = *ctl;
86737+ ctl_table_no_const tmp = *ctl;
86738
86739 tmp.extra1 = &zero;
86740 tmp.extra2 = &unres_qlen_max;
86741diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
86742index 569d355..79cf2d0 100644
86743--- a/net/core/net-procfs.c
86744+++ b/net/core/net-procfs.c
86745@@ -271,8 +271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
86746 else
86747 seq_printf(seq, "%04x", ntohs(pt->type));
86748
86749+#ifdef CONFIG_GRKERNSEC_HIDESYM
86750+ seq_printf(seq, " %-8s %pf\n",
86751+ pt->dev ? pt->dev->name : "", NULL);
86752+#else
86753 seq_printf(seq, " %-8s %pf\n",
86754 pt->dev ? pt->dev->name : "", pt->func);
86755+#endif
86756 }
86757
86758 return 0;
86759diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
86760index 981fed3..536af34 100644
86761--- a/net/core/net-sysfs.c
86762+++ b/net/core/net-sysfs.c
86763@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
86764 }
86765 EXPORT_SYMBOL(netdev_class_remove_file);
86766
86767-int netdev_kobject_init(void)
86768+int __init netdev_kobject_init(void)
86769 {
86770 kobj_ns_type_register(&net_ns_type_operations);
86771 return class_register(&net_class);
86772diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
86773index f9765203..9feaef8 100644
86774--- a/net/core/net_namespace.c
86775+++ b/net/core/net_namespace.c
86776@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
86777 int error;
86778 LIST_HEAD(net_exit_list);
86779
86780- list_add_tail(&ops->list, list);
86781+ pax_list_add_tail((struct list_head *)&ops->list, list);
86782 if (ops->init || (ops->id && ops->size)) {
86783 for_each_net(net) {
86784 error = ops_init(ops, net);
86785@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
86786
86787 out_undo:
86788 /* If I have an error cleanup all namespaces I initialized */
86789- list_del(&ops->list);
86790+ pax_list_del((struct list_head *)&ops->list);
86791 ops_exit_list(ops, &net_exit_list);
86792 ops_free_list(ops, &net_exit_list);
86793 return error;
86794@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
86795 struct net *net;
86796 LIST_HEAD(net_exit_list);
86797
86798- list_del(&ops->list);
86799+ pax_list_del((struct list_head *)&ops->list);
86800 for_each_net(net)
86801 list_add_tail(&net->exit_list, &net_exit_list);
86802 ops_exit_list(ops, &net_exit_list);
86803@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
86804 mutex_lock(&net_mutex);
86805 error = register_pernet_operations(&pernet_list, ops);
86806 if (!error && (first_device == &pernet_list))
86807- first_device = &ops->list;
86808+ first_device = (struct list_head *)&ops->list;
86809 mutex_unlock(&net_mutex);
86810 return error;
86811 }
86812diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
86813index a08bd2b..4e8f43c 100644
86814--- a/net/core/rtnetlink.c
86815+++ b/net/core/rtnetlink.c
86816@@ -58,7 +58,7 @@ struct rtnl_link {
86817 rtnl_doit_func doit;
86818 rtnl_dumpit_func dumpit;
86819 rtnl_calcit_func calcit;
86820-};
86821+} __no_const;
86822
86823 static DEFINE_MUTEX(rtnl_mutex);
86824
86825@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
86826 if (rtnl_link_ops_get(ops->kind))
86827 return -EEXIST;
86828
86829- if (!ops->dellink)
86830- ops->dellink = unregister_netdevice_queue;
86831+ if (!ops->dellink) {
86832+ pax_open_kernel();
86833+ *(void **)&ops->dellink = unregister_netdevice_queue;
86834+ pax_close_kernel();
86835+ }
86836
86837- list_add_tail(&ops->list, &link_ops);
86838+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
86839 return 0;
86840 }
86841 EXPORT_SYMBOL_GPL(__rtnl_link_register);
86842@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
86843 for_each_net(net) {
86844 __rtnl_kill_links(net, ops);
86845 }
86846- list_del(&ops->list);
86847+ pax_list_del((struct list_head *)&ops->list);
86848 }
86849 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
86850
86851diff --git a/net/core/scm.c b/net/core/scm.c
86852index 03795d0..eaf7368 100644
86853--- a/net/core/scm.c
86854+++ b/net/core/scm.c
86855@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
86856 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86857 {
86858 struct cmsghdr __user *cm
86859- = (__force struct cmsghdr __user *)msg->msg_control;
86860+ = (struct cmsghdr __force_user *)msg->msg_control;
86861 struct cmsghdr cmhdr;
86862 int cmlen = CMSG_LEN(len);
86863 int err;
86864@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86865 err = -EFAULT;
86866 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
86867 goto out;
86868- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
86869+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
86870 goto out;
86871 cmlen = CMSG_SPACE(len);
86872 if (msg->msg_controllen < cmlen)
86873@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
86874 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86875 {
86876 struct cmsghdr __user *cm
86877- = (__force struct cmsghdr __user*)msg->msg_control;
86878+ = (struct cmsghdr __force_user *)msg->msg_control;
86879
86880 int fdmax = 0;
86881 int fdnum = scm->fp->count;
86882@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86883 if (fdnum < fdmax)
86884 fdmax = fdnum;
86885
86886- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
86887+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
86888 i++, cmfptr++)
86889 {
86890 struct socket *sock;
86891diff --git a/net/core/sock.c b/net/core/sock.c
86892index d6d024c..6ea7ab4 100644
86893--- a/net/core/sock.c
86894+++ b/net/core/sock.c
86895@@ -390,7 +390,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86896 struct sk_buff_head *list = &sk->sk_receive_queue;
86897
86898 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
86899- atomic_inc(&sk->sk_drops);
86900+ atomic_inc_unchecked(&sk->sk_drops);
86901 trace_sock_rcvqueue_full(sk, skb);
86902 return -ENOMEM;
86903 }
86904@@ -400,7 +400,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86905 return err;
86906
86907 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
86908- atomic_inc(&sk->sk_drops);
86909+ atomic_inc_unchecked(&sk->sk_drops);
86910 return -ENOBUFS;
86911 }
86912
86913@@ -420,7 +420,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86914 skb_dst_force(skb);
86915
86916 spin_lock_irqsave(&list->lock, flags);
86917- skb->dropcount = atomic_read(&sk->sk_drops);
86918+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86919 __skb_queue_tail(list, skb);
86920 spin_unlock_irqrestore(&list->lock, flags);
86921
86922@@ -440,7 +440,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86923 skb->dev = NULL;
86924
86925 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
86926- atomic_inc(&sk->sk_drops);
86927+ atomic_inc_unchecked(&sk->sk_drops);
86928 goto discard_and_relse;
86929 }
86930 if (nested)
86931@@ -458,7 +458,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86932 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
86933 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
86934 bh_unlock_sock(sk);
86935- atomic_inc(&sk->sk_drops);
86936+ atomic_inc_unchecked(&sk->sk_drops);
86937 goto discard_and_relse;
86938 }
86939
86940@@ -933,12 +933,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86941 struct timeval tm;
86942 } v;
86943
86944- int lv = sizeof(int);
86945- int len;
86946+ unsigned int lv = sizeof(int);
86947+ unsigned int len;
86948
86949 if (get_user(len, optlen))
86950 return -EFAULT;
86951- if (len < 0)
86952+ if (len > INT_MAX)
86953 return -EINVAL;
86954
86955 memset(&v, 0, sizeof(v));
86956@@ -1090,11 +1090,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86957
86958 case SO_PEERNAME:
86959 {
86960- char address[128];
86961+ char address[_K_SS_MAXSIZE];
86962
86963 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
86964 return -ENOTCONN;
86965- if (lv < len)
86966+ if (lv < len || sizeof address < len)
86967 return -EINVAL;
86968 if (copy_to_user(optval, address, len))
86969 return -EFAULT;
86970@@ -1161,7 +1161,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86971
86972 if (len > lv)
86973 len = lv;
86974- if (copy_to_user(optval, &v, len))
86975+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
86976 return -EFAULT;
86977 lenout:
86978 if (put_user(len, optlen))
86979@@ -2277,7 +2277,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
86980 */
86981 smp_wmb();
86982 atomic_set(&sk->sk_refcnt, 1);
86983- atomic_set(&sk->sk_drops, 0);
86984+ atomic_set_unchecked(&sk->sk_drops, 0);
86985 }
86986 EXPORT_SYMBOL(sock_init_data);
86987
86988diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
86989index a0e9cf6..ef7f9ed 100644
86990--- a/net/core/sock_diag.c
86991+++ b/net/core/sock_diag.c
86992@@ -9,26 +9,33 @@
86993 #include <linux/inet_diag.h>
86994 #include <linux/sock_diag.h>
86995
86996-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
86997+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
86998 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
86999 static DEFINE_MUTEX(sock_diag_table_mutex);
87000
87001 int sock_diag_check_cookie(void *sk, __u32 *cookie)
87002 {
87003+#ifndef CONFIG_GRKERNSEC_HIDESYM
87004 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
87005 cookie[1] != INET_DIAG_NOCOOKIE) &&
87006 ((u32)(unsigned long)sk != cookie[0] ||
87007 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
87008 return -ESTALE;
87009 else
87010+#endif
87011 return 0;
87012 }
87013 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
87014
87015 void sock_diag_save_cookie(void *sk, __u32 *cookie)
87016 {
87017+#ifdef CONFIG_GRKERNSEC_HIDESYM
87018+ cookie[0] = 0;
87019+ cookie[1] = 0;
87020+#else
87021 cookie[0] = (u32)(unsigned long)sk;
87022 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
87023+#endif
87024 }
87025 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
87026
87027@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
87028 mutex_lock(&sock_diag_table_mutex);
87029 if (sock_diag_handlers[hndl->family])
87030 err = -EBUSY;
87031- else
87032+ else {
87033+ pax_open_kernel();
87034 sock_diag_handlers[hndl->family] = hndl;
87035+ pax_close_kernel();
87036+ }
87037 mutex_unlock(&sock_diag_table_mutex);
87038
87039 return err;
87040@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
87041
87042 mutex_lock(&sock_diag_table_mutex);
87043 BUG_ON(sock_diag_handlers[family] != hnld);
87044+ pax_open_kernel();
87045 sock_diag_handlers[family] = NULL;
87046+ pax_close_kernel();
87047 mutex_unlock(&sock_diag_table_mutex);
87048 }
87049 EXPORT_SYMBOL_GPL(sock_diag_unregister);
87050diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
87051index cfdb46a..cef55e1 100644
87052--- a/net/core/sysctl_net_core.c
87053+++ b/net/core/sysctl_net_core.c
87054@@ -28,7 +28,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
87055 {
87056 unsigned int orig_size, size;
87057 int ret, i;
87058- ctl_table tmp = {
87059+ ctl_table_no_const tmp = {
87060 .data = &size,
87061 .maxlen = sizeof(size),
87062 .mode = table->mode
87063@@ -211,13 +211,12 @@ static struct ctl_table netns_core_table[] = {
87064
87065 static __net_init int sysctl_core_net_init(struct net *net)
87066 {
87067- struct ctl_table *tbl;
87068+ ctl_table_no_const *tbl = NULL;
87069
87070 net->core.sysctl_somaxconn = SOMAXCONN;
87071
87072- tbl = netns_core_table;
87073 if (!net_eq(net, &init_net)) {
87074- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
87075+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
87076 if (tbl == NULL)
87077 goto err_dup;
87078
87079@@ -227,17 +226,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
87080 if (net->user_ns != &init_user_ns) {
87081 tbl[0].procname = NULL;
87082 }
87083- }
87084-
87085- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
87086+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
87087+ } else
87088+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
87089 if (net->core.sysctl_hdr == NULL)
87090 goto err_reg;
87091
87092 return 0;
87093
87094 err_reg:
87095- if (tbl != netns_core_table)
87096- kfree(tbl);
87097+ kfree(tbl);
87098 err_dup:
87099 return -ENOMEM;
87100 }
87101@@ -252,7 +250,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
87102 kfree(tbl);
87103 }
87104
87105-static __net_initdata struct pernet_operations sysctl_core_ops = {
87106+static __net_initconst struct pernet_operations sysctl_core_ops = {
87107 .init = sysctl_core_net_init,
87108 .exit = sysctl_core_net_exit,
87109 };
87110diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
87111index c21f200..bc4565b 100644
87112--- a/net/decnet/af_decnet.c
87113+++ b/net/decnet/af_decnet.c
87114@@ -465,6 +465,7 @@ static struct proto dn_proto = {
87115 .sysctl_rmem = sysctl_decnet_rmem,
87116 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
87117 .obj_size = sizeof(struct dn_sock),
87118+ .slab_flags = SLAB_USERCOPY,
87119 };
87120
87121 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
87122diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
87123index a55eecc..dd8428c 100644
87124--- a/net/decnet/sysctl_net_decnet.c
87125+++ b/net/decnet/sysctl_net_decnet.c
87126@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
87127
87128 if (len > *lenp) len = *lenp;
87129
87130- if (copy_to_user(buffer, addr, len))
87131+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
87132 return -EFAULT;
87133
87134 *lenp = len;
87135@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
87136
87137 if (len > *lenp) len = *lenp;
87138
87139- if (copy_to_user(buffer, devname, len))
87140+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
87141 return -EFAULT;
87142
87143 *lenp = len;
87144diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
87145index d01be2a..8976537 100644
87146--- a/net/ipv4/af_inet.c
87147+++ b/net/ipv4/af_inet.c
87148@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
87149
87150 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
87151
87152- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
87153- if (!sysctl_local_reserved_ports)
87154- goto out;
87155-
87156 rc = proto_register(&tcp_prot, 1);
87157 if (rc)
87158- goto out_free_reserved_ports;
87159+ goto out;
87160
87161 rc = proto_register(&udp_prot, 1);
87162 if (rc)
87163@@ -1818,8 +1814,6 @@ out_unregister_udp_proto:
87164 proto_unregister(&udp_prot);
87165 out_unregister_tcp_proto:
87166 proto_unregister(&tcp_prot);
87167-out_free_reserved_ports:
87168- kfree(sysctl_local_reserved_ports);
87169 goto out;
87170 }
87171
87172diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
87173index 2e7f194..0fa4d6d 100644
87174--- a/net/ipv4/ah4.c
87175+++ b/net/ipv4/ah4.c
87176@@ -420,7 +420,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
87177 return;
87178
87179 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87180- atomic_inc(&flow_cache_genid);
87181+ atomic_inc_unchecked(&flow_cache_genid);
87182 rt_genid_bump(net);
87183
87184 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
87185diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
87186index dfc39d4..0b82c4d 100644
87187--- a/net/ipv4/devinet.c
87188+++ b/net/ipv4/devinet.c
87189@@ -1529,7 +1529,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
87190 idx = 0;
87191 head = &net->dev_index_head[h];
87192 rcu_read_lock();
87193- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
87194+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
87195 net->dev_base_seq;
87196 hlist_for_each_entry_rcu(dev, head, index_hlist) {
87197 if (idx < s_idx)
87198@@ -1840,7 +1840,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
87199 idx = 0;
87200 head = &net->dev_index_head[h];
87201 rcu_read_lock();
87202- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
87203+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
87204 net->dev_base_seq;
87205 hlist_for_each_entry_rcu(dev, head, index_hlist) {
87206 if (idx < s_idx)
87207@@ -2065,7 +2065,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
87208 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
87209 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
87210
87211-static struct devinet_sysctl_table {
87212+static const struct devinet_sysctl_table {
87213 struct ctl_table_header *sysctl_header;
87214 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
87215 } devinet_sysctl = {
87216@@ -2183,7 +2183,7 @@ static __net_init int devinet_init_net(struct net *net)
87217 int err;
87218 struct ipv4_devconf *all, *dflt;
87219 #ifdef CONFIG_SYSCTL
87220- struct ctl_table *tbl = ctl_forward_entry;
87221+ ctl_table_no_const *tbl = NULL;
87222 struct ctl_table_header *forw_hdr;
87223 #endif
87224
87225@@ -2201,7 +2201,7 @@ static __net_init int devinet_init_net(struct net *net)
87226 goto err_alloc_dflt;
87227
87228 #ifdef CONFIG_SYSCTL
87229- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
87230+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
87231 if (tbl == NULL)
87232 goto err_alloc_ctl;
87233
87234@@ -2221,7 +2221,10 @@ static __net_init int devinet_init_net(struct net *net)
87235 goto err_reg_dflt;
87236
87237 err = -ENOMEM;
87238- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
87239+ if (!net_eq(net, &init_net))
87240+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
87241+ else
87242+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
87243 if (forw_hdr == NULL)
87244 goto err_reg_ctl;
87245 net->ipv4.forw_hdr = forw_hdr;
87246@@ -2237,8 +2240,7 @@ err_reg_ctl:
87247 err_reg_dflt:
87248 __devinet_sysctl_unregister(all);
87249 err_reg_all:
87250- if (tbl != ctl_forward_entry)
87251- kfree(tbl);
87252+ kfree(tbl);
87253 err_alloc_ctl:
87254 #endif
87255 if (dflt != &ipv4_devconf_dflt)
87256diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
87257index 4cfe34d..a6ba66e 100644
87258--- a/net/ipv4/esp4.c
87259+++ b/net/ipv4/esp4.c
87260@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
87261 return;
87262
87263 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87264- atomic_inc(&flow_cache_genid);
87265+ atomic_inc_unchecked(&flow_cache_genid);
87266 rt_genid_bump(net);
87267
87268 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
87269diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
87270index c7629a2..b62d139 100644
87271--- a/net/ipv4/fib_frontend.c
87272+++ b/net/ipv4/fib_frontend.c
87273@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
87274 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87275 fib_sync_up(dev);
87276 #endif
87277- atomic_inc(&net->ipv4.dev_addr_genid);
87278+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87279 rt_cache_flush(dev_net(dev));
87280 break;
87281 case NETDEV_DOWN:
87282 fib_del_ifaddr(ifa, NULL);
87283- atomic_inc(&net->ipv4.dev_addr_genid);
87284+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87285 if (ifa->ifa_dev->ifa_list == NULL) {
87286 /* Last address was deleted from this interface.
87287 * Disable IP.
87288@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
87289 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87290 fib_sync_up(dev);
87291 #endif
87292- atomic_inc(&net->ipv4.dev_addr_genid);
87293+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87294 rt_cache_flush(net);
87295 break;
87296 case NETDEV_DOWN:
87297diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
87298index 8f6cb7a..34507f9 100644
87299--- a/net/ipv4/fib_semantics.c
87300+++ b/net/ipv4/fib_semantics.c
87301@@ -765,7 +765,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
87302 nh->nh_saddr = inet_select_addr(nh->nh_dev,
87303 nh->nh_gw,
87304 nh->nh_parent->fib_scope);
87305- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
87306+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
87307
87308 return nh->nh_saddr;
87309 }
87310diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
87311index 6acb541..9ea617d 100644
87312--- a/net/ipv4/inet_connection_sock.c
87313+++ b/net/ipv4/inet_connection_sock.c
87314@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
87315 .range = { 32768, 61000 },
87316 };
87317
87318-unsigned long *sysctl_local_reserved_ports;
87319+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
87320 EXPORT_SYMBOL(sysctl_local_reserved_ports);
87321
87322 void inet_get_local_port_range(int *low, int *high)
87323diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
87324index 6af375a..c493c74 100644
87325--- a/net/ipv4/inet_hashtables.c
87326+++ b/net/ipv4/inet_hashtables.c
87327@@ -18,12 +18,15 @@
87328 #include <linux/sched.h>
87329 #include <linux/slab.h>
87330 #include <linux/wait.h>
87331+#include <linux/security.h>
87332
87333 #include <net/inet_connection_sock.h>
87334 #include <net/inet_hashtables.h>
87335 #include <net/secure_seq.h>
87336 #include <net/ip.h>
87337
87338+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
87339+
87340 /*
87341 * Allocate and initialize a new local port bind bucket.
87342 * The bindhash mutex for snum's hash chain must be held here.
87343@@ -554,6 +557,8 @@ ok:
87344 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
87345 spin_unlock(&head->lock);
87346
87347+ gr_update_task_in_ip_table(current, inet_sk(sk));
87348+
87349 if (tw) {
87350 inet_twsk_deschedule(tw, death_row);
87351 while (twrefcnt) {
87352diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
87353index 000e3d2..5472da3 100644
87354--- a/net/ipv4/inetpeer.c
87355+++ b/net/ipv4/inetpeer.c
87356@@ -503,8 +503,8 @@ relookup:
87357 if (p) {
87358 p->daddr = *daddr;
87359 atomic_set(&p->refcnt, 1);
87360- atomic_set(&p->rid, 0);
87361- atomic_set(&p->ip_id_count,
87362+ atomic_set_unchecked(&p->rid, 0);
87363+ atomic_set_unchecked(&p->ip_id_count,
87364 (daddr->family == AF_INET) ?
87365 secure_ip_id(daddr->addr.a4) :
87366 secure_ipv6_id(daddr->addr.a6));
87367diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
87368index b66910a..cfe416e 100644
87369--- a/net/ipv4/ip_fragment.c
87370+++ b/net/ipv4/ip_fragment.c
87371@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
87372 return 0;
87373
87374 start = qp->rid;
87375- end = atomic_inc_return(&peer->rid);
87376+ end = atomic_inc_return_unchecked(&peer->rid);
87377 qp->rid = end;
87378
87379 rc = qp->q.fragments && (end - start) > max;
87380@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
87381
87382 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87383 {
87384- struct ctl_table *table;
87385+ ctl_table_no_const *table = NULL;
87386 struct ctl_table_header *hdr;
87387
87388- table = ip4_frags_ns_ctl_table;
87389 if (!net_eq(net, &init_net)) {
87390- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87391+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87392 if (table == NULL)
87393 goto err_alloc;
87394
87395@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87396 /* Don't export sysctls to unprivileged users */
87397 if (net->user_ns != &init_user_ns)
87398 table[0].procname = NULL;
87399- }
87400+ hdr = register_net_sysctl(net, "net/ipv4", table);
87401+ } else
87402+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
87403
87404- hdr = register_net_sysctl(net, "net/ipv4", table);
87405 if (hdr == NULL)
87406 goto err_reg;
87407
87408@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87409 return 0;
87410
87411 err_reg:
87412- if (!net_eq(net, &init_net))
87413- kfree(table);
87414+ kfree(table);
87415 err_alloc:
87416 return -ENOMEM;
87417 }
87418diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
87419index 2a83591..68e7458 100644
87420--- a/net/ipv4/ip_gre.c
87421+++ b/net/ipv4/ip_gre.c
87422@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
87423 module_param(log_ecn_error, bool, 0644);
87424 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87425
87426-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
87427+static struct rtnl_link_ops ipgre_link_ops;
87428 static int ipgre_tunnel_init(struct net_device *dev);
87429
87430 static int ipgre_net_id __read_mostly;
87431@@ -503,10 +503,11 @@ static int ipgre_tunnel_ioctl(struct net_device *dev,
87432
87433 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
87434 return -EFAULT;
87435- if (p.iph.version != 4 || p.iph.protocol != IPPROTO_GRE ||
87436- p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)) ||
87437- ((p.i_flags|p.o_flags)&(GRE_VERSION|GRE_ROUTING))) {
87438- return -EINVAL;
87439+ if (cmd == SIOCADDTUNNEL || cmd == SIOCCHGTUNNEL) {
87440+ if (p.iph.version != 4 || p.iph.protocol != IPPROTO_GRE ||
87441+ p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)) ||
87442+ ((p.i_flags|p.o_flags)&(GRE_VERSION|GRE_ROUTING)))
87443+ return -EINVAL;
87444 }
87445 p.i_flags = gre_flags_to_tnl_flags(p.i_flags);
87446 p.o_flags = gre_flags_to_tnl_flags(p.o_flags);
87447@@ -918,7 +919,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
87448 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
87449 };
87450
87451-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87452+static struct rtnl_link_ops ipgre_link_ops = {
87453 .kind = "gre",
87454 .maxtype = IFLA_GRE_MAX,
87455 .policy = ipgre_policy,
87456@@ -932,7 +933,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87457 .fill_info = ipgre_fill_info,
87458 };
87459
87460-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
87461+static struct rtnl_link_ops ipgre_tap_ops = {
87462 .kind = "gretap",
87463 .maxtype = IFLA_GRE_MAX,
87464 .policy = ipgre_policy,
87465diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
87466index d9c4f11..02b82dbc 100644
87467--- a/net/ipv4/ip_sockglue.c
87468+++ b/net/ipv4/ip_sockglue.c
87469@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87470 len = min_t(unsigned int, len, opt->optlen);
87471 if (put_user(len, optlen))
87472 return -EFAULT;
87473- if (copy_to_user(optval, opt->__data, len))
87474+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
87475+ copy_to_user(optval, opt->__data, len))
87476 return -EFAULT;
87477 return 0;
87478 }
87479@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87480 if (sk->sk_type != SOCK_STREAM)
87481 return -ENOPROTOOPT;
87482
87483- msg.msg_control = optval;
87484+ msg.msg_control = (void __force_kernel *)optval;
87485 msg.msg_controllen = len;
87486 msg.msg_flags = flags;
87487
87488diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
87489index c118f6b..63856c4 100644
87490--- a/net/ipv4/ip_vti.c
87491+++ b/net/ipv4/ip_vti.c
87492@@ -47,7 +47,7 @@
87493 #define HASH_SIZE 16
87494 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
87495
87496-static struct rtnl_link_ops vti_link_ops __read_mostly;
87497+static struct rtnl_link_ops vti_link_ops;
87498
87499 static int vti_net_id __read_mostly;
87500 struct vti_net {
87501@@ -606,17 +606,10 @@ static int __net_init vti_fb_tunnel_init(struct net_device *dev)
87502 struct iphdr *iph = &tunnel->parms.iph;
87503 struct vti_net *ipn = net_generic(dev_net(dev), vti_net_id);
87504
87505- tunnel->dev = dev;
87506- strcpy(tunnel->parms.name, dev->name);
87507-
87508 iph->version = 4;
87509 iph->protocol = IPPROTO_IPIP;
87510 iph->ihl = 5;
87511
87512- dev->tstats = alloc_percpu(struct pcpu_tstats);
87513- if (!dev->tstats)
87514- return -ENOMEM;
87515-
87516 dev_hold(dev);
87517 rcu_assign_pointer(ipn->tunnels_wc[0], tunnel);
87518 return 0;
87519@@ -847,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
87520 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
87521 };
87522
87523-static struct rtnl_link_ops vti_link_ops __read_mostly = {
87524+static struct rtnl_link_ops vti_link_ops = {
87525 .kind = "vti",
87526 .maxtype = IFLA_VTI_MAX,
87527 .policy = vti_policy,
87528diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
87529index 59cb8c7..a72160c 100644
87530--- a/net/ipv4/ipcomp.c
87531+++ b/net/ipv4/ipcomp.c
87532@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
87533 return;
87534
87535 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87536- atomic_inc(&flow_cache_genid);
87537+ atomic_inc_unchecked(&flow_cache_genid);
87538 rt_genid_bump(net);
87539
87540 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
87541diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
87542index efa1138..20dbba0 100644
87543--- a/net/ipv4/ipconfig.c
87544+++ b/net/ipv4/ipconfig.c
87545@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
87546
87547 mm_segment_t oldfs = get_fs();
87548 set_fs(get_ds());
87549- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87550+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87551 set_fs(oldfs);
87552 return res;
87553 }
87554@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
87555
87556 mm_segment_t oldfs = get_fs();
87557 set_fs(get_ds());
87558- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87559+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87560 set_fs(oldfs);
87561 return res;
87562 }
87563@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
87564
87565 mm_segment_t oldfs = get_fs();
87566 set_fs(get_ds());
87567- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
87568+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
87569 set_fs(oldfs);
87570 return res;
87571 }
87572diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
87573index 77bfcce..64a55d4 100644
87574--- a/net/ipv4/ipip.c
87575+++ b/net/ipv4/ipip.c
87576@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87577 static int ipip_net_id __read_mostly;
87578
87579 static int ipip_tunnel_init(struct net_device *dev);
87580-static struct rtnl_link_ops ipip_link_ops __read_mostly;
87581+static struct rtnl_link_ops ipip_link_ops;
87582
87583 static int ipip_err(struct sk_buff *skb, u32 info)
87584 {
87585@@ -404,7 +404,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
87586 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
87587 };
87588
87589-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
87590+static struct rtnl_link_ops ipip_link_ops = {
87591 .kind = "ipip",
87592 .maxtype = IFLA_IPTUN_MAX,
87593 .policy = ipip_policy,
87594diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
87595index 85a4f21..1beb1f5 100644
87596--- a/net/ipv4/netfilter/arp_tables.c
87597+++ b/net/ipv4/netfilter/arp_tables.c
87598@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
87599 #endif
87600
87601 static int get_info(struct net *net, void __user *user,
87602- const int *len, int compat)
87603+ int len, int compat)
87604 {
87605 char name[XT_TABLE_MAXNAMELEN];
87606 struct xt_table *t;
87607 int ret;
87608
87609- if (*len != sizeof(struct arpt_getinfo)) {
87610- duprintf("length %u != %Zu\n", *len,
87611+ if (len != sizeof(struct arpt_getinfo)) {
87612+ duprintf("length %u != %Zu\n", len,
87613 sizeof(struct arpt_getinfo));
87614 return -EINVAL;
87615 }
87616@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
87617 info.size = private->size;
87618 strcpy(info.name, name);
87619
87620- if (copy_to_user(user, &info, *len) != 0)
87621+ if (copy_to_user(user, &info, len) != 0)
87622 ret = -EFAULT;
87623 else
87624 ret = 0;
87625@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
87626
87627 switch (cmd) {
87628 case ARPT_SO_GET_INFO:
87629- ret = get_info(sock_net(sk), user, len, 1);
87630+ ret = get_info(sock_net(sk), user, *len, 1);
87631 break;
87632 case ARPT_SO_GET_ENTRIES:
87633 ret = compat_get_entries(sock_net(sk), user, len);
87634@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
87635
87636 switch (cmd) {
87637 case ARPT_SO_GET_INFO:
87638- ret = get_info(sock_net(sk), user, len, 0);
87639+ ret = get_info(sock_net(sk), user, *len, 0);
87640 break;
87641
87642 case ARPT_SO_GET_ENTRIES:
87643diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
87644index d23118d..6ad7277 100644
87645--- a/net/ipv4/netfilter/ip_tables.c
87646+++ b/net/ipv4/netfilter/ip_tables.c
87647@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
87648 #endif
87649
87650 static int get_info(struct net *net, void __user *user,
87651- const int *len, int compat)
87652+ int len, int compat)
87653 {
87654 char name[XT_TABLE_MAXNAMELEN];
87655 struct xt_table *t;
87656 int ret;
87657
87658- if (*len != sizeof(struct ipt_getinfo)) {
87659- duprintf("length %u != %zu\n", *len,
87660+ if (len != sizeof(struct ipt_getinfo)) {
87661+ duprintf("length %u != %zu\n", len,
87662 sizeof(struct ipt_getinfo));
87663 return -EINVAL;
87664 }
87665@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
87666 info.size = private->size;
87667 strcpy(info.name, name);
87668
87669- if (copy_to_user(user, &info, *len) != 0)
87670+ if (copy_to_user(user, &info, len) != 0)
87671 ret = -EFAULT;
87672 else
87673 ret = 0;
87674@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87675
87676 switch (cmd) {
87677 case IPT_SO_GET_INFO:
87678- ret = get_info(sock_net(sk), user, len, 1);
87679+ ret = get_info(sock_net(sk), user, *len, 1);
87680 break;
87681 case IPT_SO_GET_ENTRIES:
87682 ret = compat_get_entries(sock_net(sk), user, len);
87683@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87684
87685 switch (cmd) {
87686 case IPT_SO_GET_INFO:
87687- ret = get_info(sock_net(sk), user, len, 0);
87688+ ret = get_info(sock_net(sk), user, *len, 0);
87689 break;
87690
87691 case IPT_SO_GET_ENTRIES:
87692diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
87693index 7d93d62..cbbf2a3 100644
87694--- a/net/ipv4/ping.c
87695+++ b/net/ipv4/ping.c
87696@@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
87697 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87698 0, sock_i_ino(sp),
87699 atomic_read(&sp->sk_refcnt), sp,
87700- atomic_read(&sp->sk_drops), len);
87701+ atomic_read_unchecked(&sp->sk_drops), len);
87702 }
87703
87704 static int ping_seq_show(struct seq_file *seq, void *v)
87705diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
87706index dd44e0a..06dcca4 100644
87707--- a/net/ipv4/raw.c
87708+++ b/net/ipv4/raw.c
87709@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
87710 int raw_rcv(struct sock *sk, struct sk_buff *skb)
87711 {
87712 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
87713- atomic_inc(&sk->sk_drops);
87714+ atomic_inc_unchecked(&sk->sk_drops);
87715 kfree_skb(skb);
87716 return NET_RX_DROP;
87717 }
87718@@ -745,16 +745,20 @@ static int raw_init(struct sock *sk)
87719
87720 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
87721 {
87722+ struct icmp_filter filter;
87723+
87724 if (optlen > sizeof(struct icmp_filter))
87725 optlen = sizeof(struct icmp_filter);
87726- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
87727+ if (copy_from_user(&filter, optval, optlen))
87728 return -EFAULT;
87729+ raw_sk(sk)->filter = filter;
87730 return 0;
87731 }
87732
87733 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
87734 {
87735 int len, ret = -EFAULT;
87736+ struct icmp_filter filter;
87737
87738 if (get_user(len, optlen))
87739 goto out;
87740@@ -764,8 +768,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
87741 if (len > sizeof(struct icmp_filter))
87742 len = sizeof(struct icmp_filter);
87743 ret = -EFAULT;
87744- if (put_user(len, optlen) ||
87745- copy_to_user(optval, &raw_sk(sk)->filter, len))
87746+ filter = raw_sk(sk)->filter;
87747+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
87748 goto out;
87749 ret = 0;
87750 out: return ret;
87751@@ -994,7 +998,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87752 0, 0L, 0,
87753 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87754 0, sock_i_ino(sp),
87755- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87756+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87757 }
87758
87759 static int raw_seq_show(struct seq_file *seq, void *v)
87760diff --git a/net/ipv4/route.c b/net/ipv4/route.c
87761index d35bbf0..faa3ab8 100644
87762--- a/net/ipv4/route.c
87763+++ b/net/ipv4/route.c
87764@@ -2558,34 +2558,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
87765 .maxlen = sizeof(int),
87766 .mode = 0200,
87767 .proc_handler = ipv4_sysctl_rtcache_flush,
87768+ .extra1 = &init_net,
87769 },
87770 { },
87771 };
87772
87773 static __net_init int sysctl_route_net_init(struct net *net)
87774 {
87775- struct ctl_table *tbl;
87776+ ctl_table_no_const *tbl = NULL;
87777
87778- tbl = ipv4_route_flush_table;
87779 if (!net_eq(net, &init_net)) {
87780- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87781+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87782 if (tbl == NULL)
87783 goto err_dup;
87784
87785 /* Don't export sysctls to unprivileged users */
87786 if (net->user_ns != &init_user_ns)
87787 tbl[0].procname = NULL;
87788- }
87789- tbl[0].extra1 = net;
87790+ tbl[0].extra1 = net;
87791+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87792+ } else
87793+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
87794
87795- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87796 if (net->ipv4.route_hdr == NULL)
87797 goto err_reg;
87798 return 0;
87799
87800 err_reg:
87801- if (tbl != ipv4_route_flush_table)
87802- kfree(tbl);
87803+ kfree(tbl);
87804 err_dup:
87805 return -ENOMEM;
87806 }
87807@@ -2608,7 +2608,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
87808
87809 static __net_init int rt_genid_init(struct net *net)
87810 {
87811- atomic_set(&net->rt_genid, 0);
87812+ atomic_set_unchecked(&net->rt_genid, 0);
87813 get_random_bytes(&net->ipv4.dev_addr_genid,
87814 sizeof(net->ipv4.dev_addr_genid));
87815 return 0;
87816diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
87817index fa2f63f..6554815 100644
87818--- a/net/ipv4/sysctl_net_ipv4.c
87819+++ b/net/ipv4/sysctl_net_ipv4.c
87820@@ -55,7 +55,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
87821 {
87822 int ret;
87823 int range[2];
87824- ctl_table tmp = {
87825+ ctl_table_no_const tmp = {
87826 .data = &range,
87827 .maxlen = sizeof(range),
87828 .mode = table->mode,
87829@@ -108,7 +108,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
87830 int ret;
87831 gid_t urange[2];
87832 kgid_t low, high;
87833- ctl_table tmp = {
87834+ ctl_table_no_const tmp = {
87835 .data = &urange,
87836 .maxlen = sizeof(urange),
87837 .mode = table->mode,
87838@@ -139,7 +139,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
87839 void __user *buffer, size_t *lenp, loff_t *ppos)
87840 {
87841 char val[TCP_CA_NAME_MAX];
87842- ctl_table tbl = {
87843+ ctl_table_no_const tbl = {
87844 .data = val,
87845 .maxlen = TCP_CA_NAME_MAX,
87846 };
87847@@ -158,7 +158,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
87848 void __user *buffer, size_t *lenp,
87849 loff_t *ppos)
87850 {
87851- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
87852+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
87853 int ret;
87854
87855 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87856@@ -175,7 +175,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
87857 void __user *buffer, size_t *lenp,
87858 loff_t *ppos)
87859 {
87860- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
87861+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
87862 int ret;
87863
87864 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87865@@ -201,15 +201,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87866 struct mem_cgroup *memcg;
87867 #endif
87868
87869- ctl_table tmp = {
87870+ ctl_table_no_const tmp = {
87871 .data = &vec,
87872 .maxlen = sizeof(vec),
87873 .mode = ctl->mode,
87874 };
87875
87876 if (!write) {
87877- ctl->data = &net->ipv4.sysctl_tcp_mem;
87878- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
87879+ ctl_table_no_const tcp_mem = *ctl;
87880+
87881+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
87882+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
87883 }
87884
87885 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
87886@@ -236,7 +238,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87887 static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
87888 size_t *lenp, loff_t *ppos)
87889 {
87890- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87891+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87892 struct tcp_fastopen_context *ctxt;
87893 int ret;
87894 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
87895@@ -477,7 +479,7 @@ static struct ctl_table ipv4_table[] = {
87896 },
87897 {
87898 .procname = "ip_local_reserved_ports",
87899- .data = NULL, /* initialized in sysctl_ipv4_init */
87900+ .data = sysctl_local_reserved_ports,
87901 .maxlen = 65536,
87902 .mode = 0644,
87903 .proc_handler = proc_do_large_bitmap,
87904@@ -842,11 +844,10 @@ static struct ctl_table ipv4_net_table[] = {
87905
87906 static __net_init int ipv4_sysctl_init_net(struct net *net)
87907 {
87908- struct ctl_table *table;
87909+ ctl_table_no_const *table = NULL;
87910
87911- table = ipv4_net_table;
87912 if (!net_eq(net, &init_net)) {
87913- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
87914+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
87915 if (table == NULL)
87916 goto err_alloc;
87917
87918@@ -881,15 +882,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
87919
87920 tcp_init_mem(net);
87921
87922- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87923+ if (!net_eq(net, &init_net))
87924+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87925+ else
87926+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
87927 if (net->ipv4.ipv4_hdr == NULL)
87928 goto err_reg;
87929
87930 return 0;
87931
87932 err_reg:
87933- if (!net_eq(net, &init_net))
87934- kfree(table);
87935+ kfree(table);
87936 err_alloc:
87937 return -ENOMEM;
87938 }
87939@@ -911,16 +914,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
87940 static __init int sysctl_ipv4_init(void)
87941 {
87942 struct ctl_table_header *hdr;
87943- struct ctl_table *i;
87944-
87945- for (i = ipv4_table; i->procname; i++) {
87946- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
87947- i->data = sysctl_local_reserved_ports;
87948- break;
87949- }
87950- }
87951- if (!i->procname)
87952- return -EINVAL;
87953
87954 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
87955 if (hdr == NULL)
87956diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
87957index 9c62257..651cc27 100644
87958--- a/net/ipv4/tcp_input.c
87959+++ b/net/ipv4/tcp_input.c
87960@@ -4436,7 +4436,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
87961 * simplifies code)
87962 */
87963 static void
87964-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87965+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87966 struct sk_buff *head, struct sk_buff *tail,
87967 u32 start, u32 end)
87968 {
87969@@ -5522,6 +5522,7 @@ discard:
87970 tcp_paws_reject(&tp->rx_opt, 0))
87971 goto discard_and_undo;
87972
87973+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
87974 if (th->syn) {
87975 /* We see SYN without ACK. It is attempt of
87976 * simultaneous connect with crossed SYNs.
87977@@ -5572,6 +5573,7 @@ discard:
87978 goto discard;
87979 #endif
87980 }
87981+#endif
87982 /* "fifth, if neither of the SYN or RST bits is set then
87983 * drop the segment and return."
87984 */
87985@@ -5616,7 +5618,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
87986 goto discard;
87987
87988 if (th->syn) {
87989- if (th->fin)
87990+ if (th->fin || th->urg || th->psh)
87991 goto discard;
87992 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
87993 return 1;
87994diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
87995index 7999fc5..c812f42 100644
87996--- a/net/ipv4/tcp_ipv4.c
87997+++ b/net/ipv4/tcp_ipv4.c
87998@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
87999 EXPORT_SYMBOL(sysctl_tcp_low_latency);
88000
88001
88002+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88003+extern int grsec_enable_blackhole;
88004+#endif
88005+
88006 #ifdef CONFIG_TCP_MD5SIG
88007 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
88008 __be32 daddr, __be32 saddr, const struct tcphdr *th);
88009@@ -1855,6 +1859,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
88010 return 0;
88011
88012 reset:
88013+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88014+ if (!grsec_enable_blackhole)
88015+#endif
88016 tcp_v4_send_reset(rsk, skb);
88017 discard:
88018 kfree_skb(skb);
88019@@ -2000,12 +2007,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
88020 TCP_SKB_CB(skb)->sacked = 0;
88021
88022 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88023- if (!sk)
88024+ if (!sk) {
88025+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88026+ ret = 1;
88027+#endif
88028 goto no_tcp_socket;
88029-
88030+ }
88031 process:
88032- if (sk->sk_state == TCP_TIME_WAIT)
88033+ if (sk->sk_state == TCP_TIME_WAIT) {
88034+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88035+ ret = 2;
88036+#endif
88037 goto do_time_wait;
88038+ }
88039
88040 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
88041 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88042@@ -2058,6 +2072,10 @@ csum_error:
88043 bad_packet:
88044 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88045 } else {
88046+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88047+ if (!grsec_enable_blackhole || (ret == 1 &&
88048+ (skb->dev->flags & IFF_LOOPBACK)))
88049+#endif
88050 tcp_v4_send_reset(NULL, skb);
88051 }
88052
88053diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
88054index 0f01788..d52a859 100644
88055--- a/net/ipv4/tcp_minisocks.c
88056+++ b/net/ipv4/tcp_minisocks.c
88057@@ -27,6 +27,10 @@
88058 #include <net/inet_common.h>
88059 #include <net/xfrm.h>
88060
88061+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88062+extern int grsec_enable_blackhole;
88063+#endif
88064+
88065 int sysctl_tcp_syncookies __read_mostly = 1;
88066 EXPORT_SYMBOL(sysctl_tcp_syncookies);
88067
88068@@ -717,7 +721,10 @@ embryonic_reset:
88069 * avoid becoming vulnerable to outside attack aiming at
88070 * resetting legit local connections.
88071 */
88072- req->rsk_ops->send_reset(sk, skb);
88073+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88074+ if (!grsec_enable_blackhole)
88075+#endif
88076+ req->rsk_ops->send_reset(sk, skb);
88077 } else if (fastopen) { /* received a valid RST pkt */
88078 reqsk_fastopen_remove(sk, req, true);
88079 tcp_reset(sk);
88080diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
88081index d4943f6..e7a74a5 100644
88082--- a/net/ipv4/tcp_probe.c
88083+++ b/net/ipv4/tcp_probe.c
88084@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
88085 if (cnt + width >= len)
88086 break;
88087
88088- if (copy_to_user(buf + cnt, tbuf, width))
88089+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
88090 return -EFAULT;
88091 cnt += width;
88092 }
88093diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
88094index 4b85e6f..22f9ac9 100644
88095--- a/net/ipv4/tcp_timer.c
88096+++ b/net/ipv4/tcp_timer.c
88097@@ -22,6 +22,10 @@
88098 #include <linux/gfp.h>
88099 #include <net/tcp.h>
88100
88101+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88102+extern int grsec_lastack_retries;
88103+#endif
88104+
88105 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
88106 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
88107 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
88108@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
88109 }
88110 }
88111
88112+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88113+ if ((sk->sk_state == TCP_LAST_ACK) &&
88114+ (grsec_lastack_retries > 0) &&
88115+ (grsec_lastack_retries < retry_until))
88116+ retry_until = grsec_lastack_retries;
88117+#endif
88118+
88119 if (retransmits_timed_out(sk, retry_until,
88120 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
88121 /* Has it gone just too far? */
88122diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
88123index 0bf5d399..5a2dd92 100644
88124--- a/net/ipv4/udp.c
88125+++ b/net/ipv4/udp.c
88126@@ -87,6 +87,7 @@
88127 #include <linux/types.h>
88128 #include <linux/fcntl.h>
88129 #include <linux/module.h>
88130+#include <linux/security.h>
88131 #include <linux/socket.h>
88132 #include <linux/sockios.h>
88133 #include <linux/igmp.h>
88134@@ -111,6 +112,10 @@
88135 #include <trace/events/skb.h>
88136 #include "udp_impl.h"
88137
88138+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88139+extern int grsec_enable_blackhole;
88140+#endif
88141+
88142 struct udp_table udp_table __read_mostly;
88143 EXPORT_SYMBOL(udp_table);
88144
88145@@ -594,6 +599,9 @@ found:
88146 return s;
88147 }
88148
88149+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
88150+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
88151+
88152 /*
88153 * This routine is called by the ICMP module when it gets some
88154 * sort of error condition. If err < 0 then the socket should
88155@@ -799,7 +807,7 @@ send:
88156 /*
88157 * Push out all pending data as one UDP datagram. Socket is locked.
88158 */
88159-static int udp_push_pending_frames(struct sock *sk)
88160+int udp_push_pending_frames(struct sock *sk)
88161 {
88162 struct udp_sock *up = udp_sk(sk);
88163 struct inet_sock *inet = inet_sk(sk);
88164@@ -818,6 +826,7 @@ out:
88165 up->pending = 0;
88166 return err;
88167 }
88168+EXPORT_SYMBOL(udp_push_pending_frames);
88169
88170 int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
88171 size_t len)
88172@@ -889,9 +898,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
88173 dport = usin->sin_port;
88174 if (dport == 0)
88175 return -EINVAL;
88176+
88177+ err = gr_search_udp_sendmsg(sk, usin);
88178+ if (err)
88179+ return err;
88180 } else {
88181 if (sk->sk_state != TCP_ESTABLISHED)
88182 return -EDESTADDRREQ;
88183+
88184+ err = gr_search_udp_sendmsg(sk, NULL);
88185+ if (err)
88186+ return err;
88187+
88188 daddr = inet->inet_daddr;
88189 dport = inet->inet_dport;
88190 /* Open fast path for connected socket.
88191@@ -1135,7 +1153,7 @@ static unsigned int first_packet_length(struct sock *sk)
88192 IS_UDPLITE(sk));
88193 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88194 IS_UDPLITE(sk));
88195- atomic_inc(&sk->sk_drops);
88196+ atomic_inc_unchecked(&sk->sk_drops);
88197 __skb_unlink(skb, rcvq);
88198 __skb_queue_tail(&list_kill, skb);
88199 }
88200@@ -1221,6 +1239,10 @@ try_again:
88201 if (!skb)
88202 goto out;
88203
88204+ err = gr_search_udp_recvmsg(sk, skb);
88205+ if (err)
88206+ goto out_free;
88207+
88208 ulen = skb->len - sizeof(struct udphdr);
88209 copied = len;
88210 if (copied > ulen)
88211@@ -1254,7 +1276,7 @@ try_again:
88212 if (unlikely(err)) {
88213 trace_kfree_skb(skb, udp_recvmsg);
88214 if (!peeked) {
88215- atomic_inc(&sk->sk_drops);
88216+ atomic_inc_unchecked(&sk->sk_drops);
88217 UDP_INC_STATS_USER(sock_net(sk),
88218 UDP_MIB_INERRORS, is_udplite);
88219 }
88220@@ -1541,7 +1563,7 @@ csum_error:
88221 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
88222 drop:
88223 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88224- atomic_inc(&sk->sk_drops);
88225+ atomic_inc_unchecked(&sk->sk_drops);
88226 kfree_skb(skb);
88227 return -1;
88228 }
88229@@ -1560,7 +1582,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88230 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88231
88232 if (!skb1) {
88233- atomic_inc(&sk->sk_drops);
88234+ atomic_inc_unchecked(&sk->sk_drops);
88235 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88236 IS_UDPLITE(sk));
88237 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88238@@ -1729,6 +1751,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88239 goto csum_error;
88240
88241 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88242+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88243+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88244+#endif
88245 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
88246
88247 /*
88248@@ -2159,7 +2184,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
88249 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
88250 0, sock_i_ino(sp),
88251 atomic_read(&sp->sk_refcnt), sp,
88252- atomic_read(&sp->sk_drops), len);
88253+ atomic_read_unchecked(&sp->sk_drops), len);
88254 }
88255
88256 int udp4_seq_show(struct seq_file *seq, void *v)
88257diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
88258index 9a459be..086b866 100644
88259--- a/net/ipv4/xfrm4_policy.c
88260+++ b/net/ipv4/xfrm4_policy.c
88261@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
88262
88263 static int __net_init xfrm4_net_init(struct net *net)
88264 {
88265- struct ctl_table *table;
88266+ ctl_table_no_const *table = NULL;
88267 struct ctl_table_header *hdr;
88268
88269- table = xfrm4_policy_table;
88270 if (!net_eq(net, &init_net)) {
88271- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
88272+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
88273 if (!table)
88274 goto err_alloc;
88275
88276 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
88277- }
88278-
88279- hdr = register_net_sysctl(net, "net/ipv4", table);
88280+ hdr = register_net_sysctl(net, "net/ipv4", table);
88281+ } else
88282+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
88283 if (!hdr)
88284 goto err_reg;
88285
88286@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
88287 return 0;
88288
88289 err_reg:
88290- if (!net_eq(net, &init_net))
88291- kfree(table);
88292+ kfree(table);
88293 err_alloc:
88294 return -ENOMEM;
88295 }
88296diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
88297index 4ab4c38..1533b2d 100644
88298--- a/net/ipv6/addrconf.c
88299+++ b/net/ipv6/addrconf.c
88300@@ -621,7 +621,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
88301 idx = 0;
88302 head = &net->dev_index_head[h];
88303 rcu_read_lock();
88304- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
88305+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
88306 net->dev_base_seq;
88307 hlist_for_each_entry_rcu(dev, head, index_hlist) {
88308 if (idx < s_idx)
88309@@ -2372,7 +2372,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
88310 p.iph.ihl = 5;
88311 p.iph.protocol = IPPROTO_IPV6;
88312 p.iph.ttl = 64;
88313- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
88314+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
88315
88316 if (ops->ndo_do_ioctl) {
88317 mm_segment_t oldfs = get_fs();
88318@@ -3994,7 +3994,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
88319 s_ip_idx = ip_idx = cb->args[2];
88320
88321 rcu_read_lock();
88322- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
88323+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
88324 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
88325 idx = 0;
88326 head = &net->dev_index_head[h];
88327@@ -4579,7 +4579,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
88328 dst_free(&ifp->rt->dst);
88329 break;
88330 }
88331- atomic_inc(&net->ipv6.dev_addr_genid);
88332+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
88333 }
88334
88335 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
88336@@ -4599,7 +4599,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
88337 int *valp = ctl->data;
88338 int val = *valp;
88339 loff_t pos = *ppos;
88340- ctl_table lctl;
88341+ ctl_table_no_const lctl;
88342 int ret;
88343
88344 /*
88345@@ -4681,7 +4681,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
88346 int *valp = ctl->data;
88347 int val = *valp;
88348 loff_t pos = *ppos;
88349- ctl_table lctl;
88350+ ctl_table_no_const lctl;
88351 int ret;
88352
88353 /*
88354diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
88355index b4ff0a4..db9b764 100644
88356--- a/net/ipv6/icmp.c
88357+++ b/net/ipv6/icmp.c
88358@@ -980,7 +980,7 @@ ctl_table ipv6_icmp_table_template[] = {
88359
88360 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
88361 {
88362- struct ctl_table *table;
88363+ ctl_table_no_const *table;
88364
88365 table = kmemdup(ipv6_icmp_table_template,
88366 sizeof(ipv6_icmp_table_template),
88367diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
88368index ecd6073..58162ae 100644
88369--- a/net/ipv6/ip6_gre.c
88370+++ b/net/ipv6/ip6_gre.c
88371@@ -74,7 +74,7 @@ struct ip6gre_net {
88372 struct net_device *fb_tunnel_dev;
88373 };
88374
88375-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
88376+static struct rtnl_link_ops ip6gre_link_ops;
88377 static int ip6gre_tunnel_init(struct net_device *dev);
88378 static void ip6gre_tunnel_setup(struct net_device *dev);
88379 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
88380@@ -1283,7 +1283,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
88381 }
88382
88383
88384-static struct inet6_protocol ip6gre_protocol __read_mostly = {
88385+static struct inet6_protocol ip6gre_protocol = {
88386 .handler = ip6gre_rcv,
88387 .err_handler = ip6gre_err,
88388 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
88389@@ -1617,7 +1617,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
88390 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
88391 };
88392
88393-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
88394+static struct rtnl_link_ops ip6gre_link_ops = {
88395 .kind = "ip6gre",
88396 .maxtype = IFLA_GRE_MAX,
88397 .policy = ip6gre_policy,
88398@@ -1630,7 +1630,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
88399 .fill_info = ip6gre_fill_info,
88400 };
88401
88402-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
88403+static struct rtnl_link_ops ip6gre_tap_ops = {
88404 .kind = "ip6gretap",
88405 .maxtype = IFLA_GRE_MAX,
88406 .policy = ip6gre_policy,
88407diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
88408index d5d20cd..6e3ddf8 100644
88409--- a/net/ipv6/ip6_output.c
88410+++ b/net/ipv6/ip6_output.c
88411@@ -1098,11 +1098,12 @@ static inline struct ipv6_rt_hdr *ip6_rthdr_dup(struct ipv6_rt_hdr *src,
88412 return src ? kmemdup(src, (src->hdrlen + 1) * 8, gfp) : NULL;
88413 }
88414
88415-static void ip6_append_data_mtu(int *mtu,
88416+static void ip6_append_data_mtu(unsigned int *mtu,
88417 int *maxfraglen,
88418 unsigned int fragheaderlen,
88419 struct sk_buff *skb,
88420- struct rt6_info *rt)
88421+ struct rt6_info *rt,
88422+ bool pmtuprobe)
88423 {
88424 if (!(rt->dst.flags & DST_XFRM_TUNNEL)) {
88425 if (skb == NULL) {
88426@@ -1114,7 +1115,9 @@ static void ip6_append_data_mtu(int *mtu,
88427 * this fragment is not first, the headers
88428 * space is regarded as data space.
88429 */
88430- *mtu = dst_mtu(rt->dst.path);
88431+ *mtu = min(*mtu, pmtuprobe ?
88432+ rt->dst.dev->mtu :
88433+ dst_mtu(rt->dst.path));
88434 }
88435 *maxfraglen = ((*mtu - fragheaderlen) & ~7)
88436 + fragheaderlen - sizeof(struct frag_hdr);
88437@@ -1131,11 +1134,10 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
88438 struct ipv6_pinfo *np = inet6_sk(sk);
88439 struct inet_cork *cork;
88440 struct sk_buff *skb, *skb_prev = NULL;
88441- unsigned int maxfraglen, fragheaderlen;
88442+ unsigned int maxfraglen, fragheaderlen, mtu;
88443 int exthdrlen;
88444 int dst_exthdrlen;
88445 int hh_len;
88446- int mtu;
88447 int copy;
88448 int err;
88449 int offset = 0;
88450@@ -1292,7 +1294,9 @@ alloc_new_skb:
88451 /* update mtu and maxfraglen if necessary */
88452 if (skb == NULL || skb_prev == NULL)
88453 ip6_append_data_mtu(&mtu, &maxfraglen,
88454- fragheaderlen, skb, rt);
88455+ fragheaderlen, skb, rt,
88456+ np->pmtudisc ==
88457+ IPV6_PMTUDISC_PROBE);
88458
88459 skb_prev = skb;
88460
88461diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
88462index 1e55866..b398dab 100644
88463--- a/net/ipv6/ip6_tunnel.c
88464+++ b/net/ipv6/ip6_tunnel.c
88465@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
88466
88467 static int ip6_tnl_dev_init(struct net_device *dev);
88468 static void ip6_tnl_dev_setup(struct net_device *dev);
88469-static struct rtnl_link_ops ip6_link_ops __read_mostly;
88470+static struct rtnl_link_ops ip6_link_ops;
88471
88472 static int ip6_tnl_net_id __read_mostly;
88473 struct ip6_tnl_net {
88474@@ -1672,7 +1672,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
88475 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
88476 };
88477
88478-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
88479+static struct rtnl_link_ops ip6_link_ops = {
88480 .kind = "ip6tnl",
88481 .maxtype = IFLA_IPTUN_MAX,
88482 .policy = ip6_tnl_policy,
88483diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
88484index d1e2e8e..51c19ae 100644
88485--- a/net/ipv6/ipv6_sockglue.c
88486+++ b/net/ipv6/ipv6_sockglue.c
88487@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
88488 if (sk->sk_type != SOCK_STREAM)
88489 return -ENOPROTOOPT;
88490
88491- msg.msg_control = optval;
88492+ msg.msg_control = (void __force_kernel *)optval;
88493 msg.msg_controllen = len;
88494 msg.msg_flags = flags;
88495
88496diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
88497index 44400c2..8e11f52 100644
88498--- a/net/ipv6/netfilter/ip6_tables.c
88499+++ b/net/ipv6/netfilter/ip6_tables.c
88500@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
88501 #endif
88502
88503 static int get_info(struct net *net, void __user *user,
88504- const int *len, int compat)
88505+ int len, int compat)
88506 {
88507 char name[XT_TABLE_MAXNAMELEN];
88508 struct xt_table *t;
88509 int ret;
88510
88511- if (*len != sizeof(struct ip6t_getinfo)) {
88512- duprintf("length %u != %zu\n", *len,
88513+ if (len != sizeof(struct ip6t_getinfo)) {
88514+ duprintf("length %u != %zu\n", len,
88515 sizeof(struct ip6t_getinfo));
88516 return -EINVAL;
88517 }
88518@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
88519 info.size = private->size;
88520 strcpy(info.name, name);
88521
88522- if (copy_to_user(user, &info, *len) != 0)
88523+ if (copy_to_user(user, &info, len) != 0)
88524 ret = -EFAULT;
88525 else
88526 ret = 0;
88527@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88528
88529 switch (cmd) {
88530 case IP6T_SO_GET_INFO:
88531- ret = get_info(sock_net(sk), user, len, 1);
88532+ ret = get_info(sock_net(sk), user, *len, 1);
88533 break;
88534 case IP6T_SO_GET_ENTRIES:
88535 ret = compat_get_entries(sock_net(sk), user, len);
88536@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88537
88538 switch (cmd) {
88539 case IP6T_SO_GET_INFO:
88540- ret = get_info(sock_net(sk), user, len, 0);
88541+ ret = get_info(sock_net(sk), user, *len, 0);
88542 break;
88543
88544 case IP6T_SO_GET_ENTRIES:
88545diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
88546index dffdc1a..ccc6678 100644
88547--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
88548+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
88549@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
88550
88551 static int nf_ct_frag6_sysctl_register(struct net *net)
88552 {
88553- struct ctl_table *table;
88554+ ctl_table_no_const *table = NULL;
88555 struct ctl_table_header *hdr;
88556
88557- table = nf_ct_frag6_sysctl_table;
88558 if (!net_eq(net, &init_net)) {
88559- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
88560+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
88561 GFP_KERNEL);
88562 if (table == NULL)
88563 goto err_alloc;
88564@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88565 table[0].data = &net->nf_frag.frags.timeout;
88566 table[1].data = &net->nf_frag.frags.low_thresh;
88567 table[2].data = &net->nf_frag.frags.high_thresh;
88568- }
88569-
88570- hdr = register_net_sysctl(net, "net/netfilter", table);
88571+ hdr = register_net_sysctl(net, "net/netfilter", table);
88572+ } else
88573+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
88574 if (hdr == NULL)
88575 goto err_reg;
88576
88577@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88578 return 0;
88579
88580 err_reg:
88581- if (!net_eq(net, &init_net))
88582- kfree(table);
88583+ kfree(table);
88584 err_alloc:
88585 return -ENOMEM;
88586 }
88587diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
88588index eedff8c..6e13a47 100644
88589--- a/net/ipv6/raw.c
88590+++ b/net/ipv6/raw.c
88591@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
88592 {
88593 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
88594 skb_checksum_complete(skb)) {
88595- atomic_inc(&sk->sk_drops);
88596+ atomic_inc_unchecked(&sk->sk_drops);
88597 kfree_skb(skb);
88598 return NET_RX_DROP;
88599 }
88600@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88601 struct raw6_sock *rp = raw6_sk(sk);
88602
88603 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
88604- atomic_inc(&sk->sk_drops);
88605+ atomic_inc_unchecked(&sk->sk_drops);
88606 kfree_skb(skb);
88607 return NET_RX_DROP;
88608 }
88609@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88610
88611 if (inet->hdrincl) {
88612 if (skb_checksum_complete(skb)) {
88613- atomic_inc(&sk->sk_drops);
88614+ atomic_inc_unchecked(&sk->sk_drops);
88615 kfree_skb(skb);
88616 return NET_RX_DROP;
88617 }
88618@@ -602,7 +602,7 @@ out:
88619 return err;
88620 }
88621
88622-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
88623+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
88624 struct flowi6 *fl6, struct dst_entry **dstp,
88625 unsigned int flags)
88626 {
88627@@ -914,12 +914,15 @@ do_confirm:
88628 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
88629 char __user *optval, int optlen)
88630 {
88631+ struct icmp6_filter filter;
88632+
88633 switch (optname) {
88634 case ICMPV6_FILTER:
88635 if (optlen > sizeof(struct icmp6_filter))
88636 optlen = sizeof(struct icmp6_filter);
88637- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
88638+ if (copy_from_user(&filter, optval, optlen))
88639 return -EFAULT;
88640+ raw6_sk(sk)->filter = filter;
88641 return 0;
88642 default:
88643 return -ENOPROTOOPT;
88644@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88645 char __user *optval, int __user *optlen)
88646 {
88647 int len;
88648+ struct icmp6_filter filter;
88649
88650 switch (optname) {
88651 case ICMPV6_FILTER:
88652@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88653 len = sizeof(struct icmp6_filter);
88654 if (put_user(len, optlen))
88655 return -EFAULT;
88656- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
88657+ filter = raw6_sk(sk)->filter;
88658+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
88659 return -EFAULT;
88660 return 0;
88661 default:
88662@@ -1251,7 +1256,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
88663 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
88664 0,
88665 sock_i_ino(sp),
88666- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
88667+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
88668 }
88669
88670 static int raw6_seq_show(struct seq_file *seq, void *v)
88671diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
88672index 790d9f4..68ae078 100644
88673--- a/net/ipv6/reassembly.c
88674+++ b/net/ipv6/reassembly.c
88675@@ -621,12 +621,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
88676
88677 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88678 {
88679- struct ctl_table *table;
88680+ ctl_table_no_const *table = NULL;
88681 struct ctl_table_header *hdr;
88682
88683- table = ip6_frags_ns_ctl_table;
88684 if (!net_eq(net, &init_net)) {
88685- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88686+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88687 if (table == NULL)
88688 goto err_alloc;
88689
88690@@ -637,9 +636,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88691 /* Don't export sysctls to unprivileged users */
88692 if (net->user_ns != &init_user_ns)
88693 table[0].procname = NULL;
88694- }
88695+ hdr = register_net_sysctl(net, "net/ipv6", table);
88696+ } else
88697+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
88698
88699- hdr = register_net_sysctl(net, "net/ipv6", table);
88700 if (hdr == NULL)
88701 goto err_reg;
88702
88703@@ -647,8 +647,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88704 return 0;
88705
88706 err_reg:
88707- if (!net_eq(net, &init_net))
88708- kfree(table);
88709+ kfree(table);
88710 err_alloc:
88711 return -ENOMEM;
88712 }
88713diff --git a/net/ipv6/route.c b/net/ipv6/route.c
88714index ad0aa6b..beaef03 100644
88715--- a/net/ipv6/route.c
88716+++ b/net/ipv6/route.c
88717@@ -2881,7 +2881,7 @@ ctl_table ipv6_route_table_template[] = {
88718
88719 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
88720 {
88721- struct ctl_table *table;
88722+ ctl_table_no_const *table;
88723
88724 table = kmemdup(ipv6_route_table_template,
88725 sizeof(ipv6_route_table_template),
88726diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
88727index 3353634..3d5084a 100644
88728--- a/net/ipv6/sit.c
88729+++ b/net/ipv6/sit.c
88730@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
88731 static void ipip6_dev_free(struct net_device *dev);
88732 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
88733 __be32 *v4dst);
88734-static struct rtnl_link_ops sit_link_ops __read_mostly;
88735+static struct rtnl_link_ops sit_link_ops;
88736
88737 static int sit_net_id __read_mostly;
88738 struct sit_net {
88739@@ -1453,7 +1453,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
88740 #endif
88741 };
88742
88743-static struct rtnl_link_ops sit_link_ops __read_mostly = {
88744+static struct rtnl_link_ops sit_link_ops = {
88745 .kind = "sit",
88746 .maxtype = IFLA_IPTUN_MAX,
88747 .policy = ipip6_policy,
88748diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
88749index e85c48b..b8268d3 100644
88750--- a/net/ipv6/sysctl_net_ipv6.c
88751+++ b/net/ipv6/sysctl_net_ipv6.c
88752@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
88753
88754 static int __net_init ipv6_sysctl_net_init(struct net *net)
88755 {
88756- struct ctl_table *ipv6_table;
88757+ ctl_table_no_const *ipv6_table;
88758 struct ctl_table *ipv6_route_table;
88759 struct ctl_table *ipv6_icmp_table;
88760 int err;
88761diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
88762index 0a17ed9..2526cc3 100644
88763--- a/net/ipv6/tcp_ipv6.c
88764+++ b/net/ipv6/tcp_ipv6.c
88765@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
88766 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
88767 }
88768
88769+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88770+extern int grsec_enable_blackhole;
88771+#endif
88772+
88773 static void tcp_v6_hash(struct sock *sk)
88774 {
88775 if (sk->sk_state != TCP_CLOSE) {
88776@@ -1398,6 +1402,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
88777 return 0;
88778
88779 reset:
88780+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88781+ if (!grsec_enable_blackhole)
88782+#endif
88783 tcp_v6_send_reset(sk, skb);
88784 discard:
88785 if (opt_skb)
88786@@ -1480,12 +1487,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
88787 TCP_SKB_CB(skb)->sacked = 0;
88788
88789 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88790- if (!sk)
88791+ if (!sk) {
88792+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88793+ ret = 1;
88794+#endif
88795 goto no_tcp_socket;
88796+ }
88797
88798 process:
88799- if (sk->sk_state == TCP_TIME_WAIT)
88800+ if (sk->sk_state == TCP_TIME_WAIT) {
88801+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88802+ ret = 2;
88803+#endif
88804 goto do_time_wait;
88805+ }
88806
88807 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
88808 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88809@@ -1536,6 +1551,10 @@ csum_error:
88810 bad_packet:
88811 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88812 } else {
88813+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88814+ if (!grsec_enable_blackhole || (ret == 1 &&
88815+ (skb->dev->flags & IFF_LOOPBACK)))
88816+#endif
88817 tcp_v6_send_reset(NULL, skb);
88818 }
88819
88820diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
88821index 42923b1..d09c290 100644
88822--- a/net/ipv6/udp.c
88823+++ b/net/ipv6/udp.c
88824@@ -52,6 +52,10 @@
88825 #include <trace/events/skb.h>
88826 #include "udp_impl.h"
88827
88828+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88829+extern int grsec_enable_blackhole;
88830+#endif
88831+
88832 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
88833 {
88834 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
88835@@ -419,7 +423,7 @@ try_again:
88836 if (unlikely(err)) {
88837 trace_kfree_skb(skb, udpv6_recvmsg);
88838 if (!peeked) {
88839- atomic_inc(&sk->sk_drops);
88840+ atomic_inc_unchecked(&sk->sk_drops);
88841 if (is_udp4)
88842 UDP_INC_STATS_USER(sock_net(sk),
88843 UDP_MIB_INERRORS,
88844@@ -665,7 +669,7 @@ csum_error:
88845 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
88846 drop:
88847 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88848- atomic_inc(&sk->sk_drops);
88849+ atomic_inc_unchecked(&sk->sk_drops);
88850 kfree_skb(skb);
88851 return -1;
88852 }
88853@@ -723,7 +727,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88854 if (likely(skb1 == NULL))
88855 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88856 if (!skb1) {
88857- atomic_inc(&sk->sk_drops);
88858+ atomic_inc_unchecked(&sk->sk_drops);
88859 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88860 IS_UDPLITE(sk));
88861 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88862@@ -860,6 +864,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88863 goto csum_error;
88864
88865 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88866+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88867+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88868+#endif
88869 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
88870
88871 kfree_skb(skb);
88872@@ -955,11 +962,16 @@ static int udp_v6_push_pending_frames(struct sock *sk)
88873 struct udphdr *uh;
88874 struct udp_sock *up = udp_sk(sk);
88875 struct inet_sock *inet = inet_sk(sk);
88876- struct flowi6 *fl6 = &inet->cork.fl.u.ip6;
88877+ struct flowi6 *fl6;
88878 int err = 0;
88879 int is_udplite = IS_UDPLITE(sk);
88880 __wsum csum = 0;
88881
88882+ if (up->pending == AF_INET)
88883+ return udp_push_pending_frames(sk);
88884+
88885+ fl6 = &inet->cork.fl.u.ip6;
88886+
88887 /* Grab the skbuff where UDP header space exists. */
88888 if ((skb = skb_peek(&sk->sk_write_queue)) == NULL)
88889 goto out;
88890@@ -1387,7 +1399,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
88891 0,
88892 sock_i_ino(sp),
88893 atomic_read(&sp->sk_refcnt), sp,
88894- atomic_read(&sp->sk_drops));
88895+ atomic_read_unchecked(&sp->sk_drops));
88896 }
88897
88898 int udp6_seq_show(struct seq_file *seq, void *v)
88899diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
88900index 23ed03d..465a71d 100644
88901--- a/net/ipv6/xfrm6_policy.c
88902+++ b/net/ipv6/xfrm6_policy.c
88903@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
88904
88905 static int __net_init xfrm6_net_init(struct net *net)
88906 {
88907- struct ctl_table *table;
88908+ ctl_table_no_const *table = NULL;
88909 struct ctl_table_header *hdr;
88910
88911- table = xfrm6_policy_table;
88912 if (!net_eq(net, &init_net)) {
88913- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
88914+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
88915 if (!table)
88916 goto err_alloc;
88917
88918 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
88919- }
88920+ hdr = register_net_sysctl(net, "net/ipv6", table);
88921+ } else
88922+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
88923
88924- hdr = register_net_sysctl(net, "net/ipv6", table);
88925 if (!hdr)
88926 goto err_reg;
88927
88928@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
88929 return 0;
88930
88931 err_reg:
88932- if (!net_eq(net, &init_net))
88933- kfree(table);
88934+ kfree(table);
88935 err_alloc:
88936 return -ENOMEM;
88937 }
88938diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
88939index 41ac7938..75e3bb1 100644
88940--- a/net/irda/ircomm/ircomm_tty.c
88941+++ b/net/irda/ircomm/ircomm_tty.c
88942@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88943 add_wait_queue(&port->open_wait, &wait);
88944
88945 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
88946- __FILE__, __LINE__, tty->driver->name, port->count);
88947+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88948
88949 spin_lock_irqsave(&port->lock, flags);
88950 if (!tty_hung_up_p(filp))
88951- port->count--;
88952+ atomic_dec(&port->count);
88953 port->blocked_open++;
88954 spin_unlock_irqrestore(&port->lock, flags);
88955
88956@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88957 }
88958
88959 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
88960- __FILE__, __LINE__, tty->driver->name, port->count);
88961+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88962
88963 schedule();
88964 }
88965@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88966
88967 spin_lock_irqsave(&port->lock, flags);
88968 if (!tty_hung_up_p(filp))
88969- port->count++;
88970+ atomic_inc(&port->count);
88971 port->blocked_open--;
88972 spin_unlock_irqrestore(&port->lock, flags);
88973
88974 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
88975- __FILE__, __LINE__, tty->driver->name, port->count);
88976+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88977
88978 if (!retval)
88979 port->flags |= ASYNC_NORMAL_ACTIVE;
88980@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
88981
88982 /* ++ is not atomic, so this should be protected - Jean II */
88983 spin_lock_irqsave(&self->port.lock, flags);
88984- self->port.count++;
88985+ atomic_inc(&self->port.count);
88986 spin_unlock_irqrestore(&self->port.lock, flags);
88987 tty_port_tty_set(&self->port, tty);
88988
88989 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
88990- self->line, self->port.count);
88991+ self->line, atomic_read(&self->port.count));
88992
88993 /* Not really used by us, but lets do it anyway */
88994 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
88995@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
88996 tty_kref_put(port->tty);
88997 }
88998 port->tty = NULL;
88999- port->count = 0;
89000+ atomic_set(&port->count, 0);
89001 spin_unlock_irqrestore(&port->lock, flags);
89002
89003 wake_up_interruptible(&port->open_wait);
89004@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
89005 seq_putc(m, '\n');
89006
89007 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
89008- seq_printf(m, "Open count: %d\n", self->port.count);
89009+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
89010 seq_printf(m, "Max data size: %d\n", self->max_data_size);
89011 seq_printf(m, "Max header size: %d\n", self->max_header_size);
89012
89013diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
89014index ae69165..c8b82d8 100644
89015--- a/net/iucv/af_iucv.c
89016+++ b/net/iucv/af_iucv.c
89017@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
89018
89019 write_lock_bh(&iucv_sk_list.lock);
89020
89021- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
89022+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
89023 while (__iucv_get_sock_by_name(name)) {
89024 sprintf(name, "%08x",
89025- atomic_inc_return(&iucv_sk_list.autobind_name));
89026+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
89027 }
89028
89029 write_unlock_bh(&iucv_sk_list.lock);
89030diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
89031index 4fe76ff..426a904 100644
89032--- a/net/iucv/iucv.c
89033+++ b/net/iucv/iucv.c
89034@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
89035 return NOTIFY_OK;
89036 }
89037
89038-static struct notifier_block __refdata iucv_cpu_notifier = {
89039+static struct notifier_block iucv_cpu_notifier = {
89040 .notifier_call = iucv_cpu_notify,
89041 };
89042
89043diff --git a/net/key/af_key.c b/net/key/af_key.c
89044index 9da8620..97070ad 100644
89045--- a/net/key/af_key.c
89046+++ b/net/key/af_key.c
89047@@ -3047,10 +3047,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
89048 static u32 get_acqseq(void)
89049 {
89050 u32 res;
89051- static atomic_t acqseq;
89052+ static atomic_unchecked_t acqseq;
89053
89054 do {
89055- res = atomic_inc_return(&acqseq);
89056+ res = atomic_inc_return_unchecked(&acqseq);
89057 } while (!res);
89058 return res;
89059 }
89060diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
89061index 8dec687..5ebee2d 100644
89062--- a/net/l2tp/l2tp_ppp.c
89063+++ b/net/l2tp/l2tp_ppp.c
89064@@ -1793,7 +1793,8 @@ static const struct proto_ops pppol2tp_ops = {
89065
89066 static const struct pppox_proto pppol2tp_proto = {
89067 .create = pppol2tp_create,
89068- .ioctl = pppol2tp_ioctl
89069+ .ioctl = pppol2tp_ioctl,
89070+ .owner = THIS_MODULE,
89071 };
89072
89073 #ifdef CONFIG_L2TP_V3
89074diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
89075index 4fdb306e..920086a 100644
89076--- a/net/mac80211/cfg.c
89077+++ b/net/mac80211/cfg.c
89078@@ -804,7 +804,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
89079 ret = ieee80211_vif_use_channel(sdata, chandef,
89080 IEEE80211_CHANCTX_EXCLUSIVE);
89081 }
89082- } else if (local->open_count == local->monitors) {
89083+ } else if (local_read(&local->open_count) == local->monitors) {
89084 local->_oper_chandef = *chandef;
89085 ieee80211_hw_config(local, 0);
89086 }
89087@@ -2920,7 +2920,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
89088 else
89089 local->probe_req_reg--;
89090
89091- if (!local->open_count)
89092+ if (!local_read(&local->open_count))
89093 break;
89094
89095 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
89096@@ -3383,8 +3383,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
89097 if (chanctx_conf) {
89098 *chandef = chanctx_conf->def;
89099 ret = 0;
89100- } else if (local->open_count > 0 &&
89101- local->open_count == local->monitors &&
89102+ } else if (local_read(&local->open_count) > 0 &&
89103+ local_read(&local->open_count) == local->monitors &&
89104 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
89105 if (local->use_chanctx)
89106 *chandef = local->monitor_chandef;
89107diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
89108index 9ca8e32..48e4a9b 100644
89109--- a/net/mac80211/ieee80211_i.h
89110+++ b/net/mac80211/ieee80211_i.h
89111@@ -28,6 +28,7 @@
89112 #include <net/ieee80211_radiotap.h>
89113 #include <net/cfg80211.h>
89114 #include <net/mac80211.h>
89115+#include <asm/local.h>
89116 #include "key.h"
89117 #include "sta_info.h"
89118 #include "debug.h"
89119@@ -891,7 +892,7 @@ struct ieee80211_local {
89120 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
89121 spinlock_t queue_stop_reason_lock;
89122
89123- int open_count;
89124+ local_t open_count;
89125 int monitors, cooked_mntrs;
89126 /* number of interfaces with corresponding FIF_ flags */
89127 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
89128diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
89129index 98d20c0..586675b 100644
89130--- a/net/mac80211/iface.c
89131+++ b/net/mac80211/iface.c
89132@@ -502,7 +502,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89133 break;
89134 }
89135
89136- if (local->open_count == 0) {
89137+ if (local_read(&local->open_count) == 0) {
89138 res = drv_start(local);
89139 if (res)
89140 goto err_del_bss;
89141@@ -545,7 +545,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89142 break;
89143 }
89144
89145- if (local->monitors == 0 && local->open_count == 0) {
89146+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
89147 res = ieee80211_add_virtual_monitor(local);
89148 if (res)
89149 goto err_stop;
89150@@ -653,7 +653,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89151 atomic_inc(&local->iff_promiscs);
89152
89153 if (coming_up)
89154- local->open_count++;
89155+ local_inc(&local->open_count);
89156
89157 if (hw_reconf_flags)
89158 ieee80211_hw_config(local, hw_reconf_flags);
89159@@ -691,7 +691,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89160 err_del_interface:
89161 drv_remove_interface(local, sdata);
89162 err_stop:
89163- if (!local->open_count)
89164+ if (!local_read(&local->open_count))
89165 drv_stop(local);
89166 err_del_bss:
89167 sdata->bss = NULL;
89168@@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89169 }
89170
89171 if (going_down)
89172- local->open_count--;
89173+ local_dec(&local->open_count);
89174
89175 switch (sdata->vif.type) {
89176 case NL80211_IFTYPE_AP_VLAN:
89177@@ -895,7 +895,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89178 }
89179 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
89180
89181- if (local->open_count == 0)
89182+ if (local_read(&local->open_count) == 0)
89183 ieee80211_clear_tx_pending(local);
89184
89185 /*
89186@@ -931,7 +931,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89187
89188 ieee80211_recalc_ps(local, -1);
89189
89190- if (local->open_count == 0) {
89191+ if (local_read(&local->open_count) == 0) {
89192 ieee80211_stop_device(local);
89193
89194 /* no reconfiguring after stop! */
89195@@ -942,7 +942,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89196 ieee80211_configure_filter(local);
89197 ieee80211_hw_config(local, hw_reconf_flags);
89198
89199- if (local->monitors == local->open_count)
89200+ if (local->monitors == local_read(&local->open_count))
89201 ieee80211_add_virtual_monitor(local);
89202 }
89203
89204diff --git a/net/mac80211/main.c b/net/mac80211/main.c
89205index 8a7bfc4..4407cd0 100644
89206--- a/net/mac80211/main.c
89207+++ b/net/mac80211/main.c
89208@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
89209 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
89210 IEEE80211_CONF_CHANGE_POWER);
89211
89212- if (changed && local->open_count) {
89213+ if (changed && local_read(&local->open_count)) {
89214 ret = drv_config(local, changed);
89215 /*
89216 * Goal:
89217diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
89218index 7fc5d0d..07ea536 100644
89219--- a/net/mac80211/pm.c
89220+++ b/net/mac80211/pm.c
89221@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89222 struct ieee80211_sub_if_data *sdata;
89223 struct sta_info *sta;
89224
89225- if (!local->open_count)
89226+ if (!local_read(&local->open_count))
89227 goto suspend;
89228
89229 ieee80211_scan_cancel(local);
89230@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89231 cancel_work_sync(&local->dynamic_ps_enable_work);
89232 del_timer_sync(&local->dynamic_ps_timer);
89233
89234- local->wowlan = wowlan && local->open_count;
89235+ local->wowlan = wowlan && local_read(&local->open_count);
89236 if (local->wowlan) {
89237 int err = drv_suspend(local, wowlan);
89238 if (err < 0) {
89239@@ -113,7 +113,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89240 WARN_ON(!list_empty(&local->chanctx_list));
89241
89242 /* stop hardware - this must stop RX */
89243- if (local->open_count)
89244+ if (local_read(&local->open_count))
89245 ieee80211_stop_device(local);
89246
89247 suspend:
89248diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
89249index a02bef3..f2f38dd 100644
89250--- a/net/mac80211/rate.c
89251+++ b/net/mac80211/rate.c
89252@@ -712,7 +712,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
89253
89254 ASSERT_RTNL();
89255
89256- if (local->open_count)
89257+ if (local_read(&local->open_count))
89258 return -EBUSY;
89259
89260 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
89261diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
89262index c97a065..ff61928 100644
89263--- a/net/mac80211/rc80211_pid_debugfs.c
89264+++ b/net/mac80211/rc80211_pid_debugfs.c
89265@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
89266
89267 spin_unlock_irqrestore(&events->lock, status);
89268
89269- if (copy_to_user(buf, pb, p))
89270+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
89271 return -EFAULT;
89272
89273 return p;
89274diff --git a/net/mac80211/util.c b/net/mac80211/util.c
89275index 72e6292..e6319eb 100644
89276--- a/net/mac80211/util.c
89277+++ b/net/mac80211/util.c
89278@@ -1472,7 +1472,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
89279 }
89280 #endif
89281 /* everything else happens only if HW was up & running */
89282- if (!local->open_count)
89283+ if (!local_read(&local->open_count))
89284 goto wake_up;
89285
89286 /*
89287@@ -1696,7 +1696,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
89288 local->in_reconfig = false;
89289 barrier();
89290
89291- if (local->monitors == local->open_count && local->monitors > 0)
89292+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
89293 ieee80211_add_virtual_monitor(local);
89294
89295 /*
89296diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
89297index 56d22ca..87c778f 100644
89298--- a/net/netfilter/Kconfig
89299+++ b/net/netfilter/Kconfig
89300@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
89301
89302 To compile it as a module, choose M here. If unsure, say N.
89303
89304+config NETFILTER_XT_MATCH_GRADM
89305+ tristate '"gradm" match support'
89306+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
89307+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
89308+ ---help---
89309+ The gradm match allows to match on grsecurity RBAC being enabled.
89310+ It is useful when iptables rules are applied early on bootup to
89311+ prevent connections to the machine (except from a trusted host)
89312+ while the RBAC system is disabled.
89313+
89314 config NETFILTER_XT_MATCH_HASHLIMIT
89315 tristate '"hashlimit" match support'
89316 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
89317diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
89318index a1abf87..dbcb7ee 100644
89319--- a/net/netfilter/Makefile
89320+++ b/net/netfilter/Makefile
89321@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
89322 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
89323 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
89324 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
89325+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
89326 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
89327 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
89328 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
89329diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
89330index f771390..145b765 100644
89331--- a/net/netfilter/ipset/ip_set_core.c
89332+++ b/net/netfilter/ipset/ip_set_core.c
89333@@ -1820,7 +1820,7 @@ done:
89334 return ret;
89335 }
89336
89337-static struct nf_sockopt_ops so_set __read_mostly = {
89338+static struct nf_sockopt_ops so_set = {
89339 .pf = PF_INET,
89340 .get_optmin = SO_IP_SET,
89341 .get_optmax = SO_IP_SET + 1,
89342diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
89343index a083bda..da661c3 100644
89344--- a/net/netfilter/ipvs/ip_vs_conn.c
89345+++ b/net/netfilter/ipvs/ip_vs_conn.c
89346@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
89347 /* Increase the refcnt counter of the dest */
89348 ip_vs_dest_hold(dest);
89349
89350- conn_flags = atomic_read(&dest->conn_flags);
89351+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
89352 if (cp->protocol != IPPROTO_UDP)
89353 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
89354 flags = cp->flags;
89355@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
89356
89357 cp->control = NULL;
89358 atomic_set(&cp->n_control, 0);
89359- atomic_set(&cp->in_pkts, 0);
89360+ atomic_set_unchecked(&cp->in_pkts, 0);
89361
89362 cp->packet_xmit = NULL;
89363 cp->app = NULL;
89364@@ -1190,7 +1190,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
89365
89366 /* Don't drop the entry if its number of incoming packets is not
89367 located in [0, 8] */
89368- i = atomic_read(&cp->in_pkts);
89369+ i = atomic_read_unchecked(&cp->in_pkts);
89370 if (i > 8 || i < 0) return 0;
89371
89372 if (!todrop_rate[i]) return 0;
89373diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
89374index 23b8eb5..48a8959 100644
89375--- a/net/netfilter/ipvs/ip_vs_core.c
89376+++ b/net/netfilter/ipvs/ip_vs_core.c
89377@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
89378 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
89379 /* do not touch skb anymore */
89380
89381- atomic_inc(&cp->in_pkts);
89382+ atomic_inc_unchecked(&cp->in_pkts);
89383 ip_vs_conn_put(cp);
89384 return ret;
89385 }
89386@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
89387 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
89388 pkts = sysctl_sync_threshold(ipvs);
89389 else
89390- pkts = atomic_add_return(1, &cp->in_pkts);
89391+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89392
89393 if (ipvs->sync_state & IP_VS_STATE_MASTER)
89394 ip_vs_sync_conn(net, cp, pkts);
89395diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
89396index 9e6c2a0..28552e2 100644
89397--- a/net/netfilter/ipvs/ip_vs_ctl.c
89398+++ b/net/netfilter/ipvs/ip_vs_ctl.c
89399@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
89400 */
89401 ip_vs_rs_hash(ipvs, dest);
89402 }
89403- atomic_set(&dest->conn_flags, conn_flags);
89404+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
89405
89406 /* bind the service */
89407 if (!dest->svc) {
89408@@ -1657,7 +1657,7 @@ proc_do_sync_ports(ctl_table *table, int write,
89409 * align with netns init in ip_vs_control_net_init()
89410 */
89411
89412-static struct ctl_table vs_vars[] = {
89413+static ctl_table_no_const vs_vars[] __read_only = {
89414 {
89415 .procname = "amemthresh",
89416 .maxlen = sizeof(int),
89417@@ -2060,7 +2060,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
89418 " %-7s %-6d %-10d %-10d\n",
89419 &dest->addr.in6,
89420 ntohs(dest->port),
89421- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
89422+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
89423 atomic_read(&dest->weight),
89424 atomic_read(&dest->activeconns),
89425 atomic_read(&dest->inactconns));
89426@@ -2071,7 +2071,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
89427 "%-7s %-6d %-10d %-10d\n",
89428 ntohl(dest->addr.ip),
89429 ntohs(dest->port),
89430- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
89431+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
89432 atomic_read(&dest->weight),
89433 atomic_read(&dest->activeconns),
89434 atomic_read(&dest->inactconns));
89435@@ -2549,7 +2549,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
89436
89437 entry.addr = dest->addr.ip;
89438 entry.port = dest->port;
89439- entry.conn_flags = atomic_read(&dest->conn_flags);
89440+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
89441 entry.weight = atomic_read(&dest->weight);
89442 entry.u_threshold = dest->u_threshold;
89443 entry.l_threshold = dest->l_threshold;
89444@@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
89445 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
89446 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
89447 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
89448- (atomic_read(&dest->conn_flags) &
89449+ (atomic_read_unchecked(&dest->conn_flags) &
89450 IP_VS_CONN_F_FWD_MASK)) ||
89451 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
89452 atomic_read(&dest->weight)) ||
89453@@ -3682,7 +3682,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
89454 {
89455 int idx;
89456 struct netns_ipvs *ipvs = net_ipvs(net);
89457- struct ctl_table *tbl;
89458+ ctl_table_no_const *tbl;
89459
89460 atomic_set(&ipvs->dropentry, 0);
89461 spin_lock_init(&ipvs->dropentry_lock);
89462diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
89463index 5ea26bd..c9bc65f 100644
89464--- a/net/netfilter/ipvs/ip_vs_lblc.c
89465+++ b/net/netfilter/ipvs/ip_vs_lblc.c
89466@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
89467 * IPVS LBLC sysctl table
89468 */
89469 #ifdef CONFIG_SYSCTL
89470-static ctl_table vs_vars_table[] = {
89471+static ctl_table_no_const vs_vars_table[] __read_only = {
89472 {
89473 .procname = "lblc_expiration",
89474 .data = NULL,
89475diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
89476index 50123c2..067c773 100644
89477--- a/net/netfilter/ipvs/ip_vs_lblcr.c
89478+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
89479@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
89480 * IPVS LBLCR sysctl table
89481 */
89482
89483-static ctl_table vs_vars_table[] = {
89484+static ctl_table_no_const vs_vars_table[] __read_only = {
89485 {
89486 .procname = "lblcr_expiration",
89487 .data = NULL,
89488diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
89489index f6046d9..4f10cfd 100644
89490--- a/net/netfilter/ipvs/ip_vs_sync.c
89491+++ b/net/netfilter/ipvs/ip_vs_sync.c
89492@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
89493 cp = cp->control;
89494 if (cp) {
89495 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
89496- pkts = atomic_add_return(1, &cp->in_pkts);
89497+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89498 else
89499 pkts = sysctl_sync_threshold(ipvs);
89500 ip_vs_sync_conn(net, cp->control, pkts);
89501@@ -758,7 +758,7 @@ control:
89502 if (!cp)
89503 return;
89504 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
89505- pkts = atomic_add_return(1, &cp->in_pkts);
89506+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89507 else
89508 pkts = sysctl_sync_threshold(ipvs);
89509 goto sloop;
89510@@ -882,7 +882,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
89511
89512 if (opt)
89513 memcpy(&cp->in_seq, opt, sizeof(*opt));
89514- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
89515+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
89516 cp->state = state;
89517 cp->old_state = cp->state;
89518 /*
89519diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
89520index b75ff64..0c51bbe 100644
89521--- a/net/netfilter/ipvs/ip_vs_xmit.c
89522+++ b/net/netfilter/ipvs/ip_vs_xmit.c
89523@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
89524 else
89525 rc = NF_ACCEPT;
89526 /* do not touch skb anymore */
89527- atomic_inc(&cp->in_pkts);
89528+ atomic_inc_unchecked(&cp->in_pkts);
89529 goto out;
89530 }
89531
89532@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
89533 else
89534 rc = NF_ACCEPT;
89535 /* do not touch skb anymore */
89536- atomic_inc(&cp->in_pkts);
89537+ atomic_inc_unchecked(&cp->in_pkts);
89538 goto out;
89539 }
89540
89541diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
89542index 2d3030a..7ba1c0a 100644
89543--- a/net/netfilter/nf_conntrack_acct.c
89544+++ b/net/netfilter/nf_conntrack_acct.c
89545@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
89546 #ifdef CONFIG_SYSCTL
89547 static int nf_conntrack_acct_init_sysctl(struct net *net)
89548 {
89549- struct ctl_table *table;
89550+ ctl_table_no_const *table;
89551
89552 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
89553 GFP_KERNEL);
89554diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
89555index 0283bae..5febcb0 100644
89556--- a/net/netfilter/nf_conntrack_core.c
89557+++ b/net/netfilter/nf_conntrack_core.c
89558@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
89559 #define DYING_NULLS_VAL ((1<<30)+1)
89560 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
89561
89562+#ifdef CONFIG_GRKERNSEC_HIDESYM
89563+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
89564+#endif
89565+
89566 int nf_conntrack_init_net(struct net *net)
89567 {
89568 int ret;
89569@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
89570 goto err_stat;
89571 }
89572
89573+#ifdef CONFIG_GRKERNSEC_HIDESYM
89574+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
89575+#else
89576 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
89577+#endif
89578 if (!net->ct.slabname) {
89579 ret = -ENOMEM;
89580 goto err_slabname;
89581diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
89582index 1df1761..ce8b88a 100644
89583--- a/net/netfilter/nf_conntrack_ecache.c
89584+++ b/net/netfilter/nf_conntrack_ecache.c
89585@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
89586 #ifdef CONFIG_SYSCTL
89587 static int nf_conntrack_event_init_sysctl(struct net *net)
89588 {
89589- struct ctl_table *table;
89590+ ctl_table_no_const *table;
89591
89592 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
89593 GFP_KERNEL);
89594diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
89595index 974a2a4..52cc6ff 100644
89596--- a/net/netfilter/nf_conntrack_helper.c
89597+++ b/net/netfilter/nf_conntrack_helper.c
89598@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
89599
89600 static int nf_conntrack_helper_init_sysctl(struct net *net)
89601 {
89602- struct ctl_table *table;
89603+ ctl_table_no_const *table;
89604
89605 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
89606 GFP_KERNEL);
89607diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
89608index 0ab9636..cea3c6a 100644
89609--- a/net/netfilter/nf_conntrack_proto.c
89610+++ b/net/netfilter/nf_conntrack_proto.c
89611@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
89612
89613 static void
89614 nf_ct_unregister_sysctl(struct ctl_table_header **header,
89615- struct ctl_table **table,
89616+ ctl_table_no_const **table,
89617 unsigned int users)
89618 {
89619 if (users > 0)
89620diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
89621index a99b6c3..3841268 100644
89622--- a/net/netfilter/nf_conntrack_proto_dccp.c
89623+++ b/net/netfilter/nf_conntrack_proto_dccp.c
89624@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
89625 out_invalid:
89626 if (LOG_INVALID(net, IPPROTO_DCCP))
89627 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
89628- NULL, msg);
89629+ NULL, "%s", msg);
89630 return false;
89631 }
89632
89633@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
89634
89635 out_invalid:
89636 if (LOG_INVALID(net, IPPROTO_DCCP))
89637- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
89638+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
89639 return -NF_ACCEPT;
89640 }
89641
89642diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
89643index bd700b4..4a3dc61 100644
89644--- a/net/netfilter/nf_conntrack_standalone.c
89645+++ b/net/netfilter/nf_conntrack_standalone.c
89646@@ -471,7 +471,7 @@ static ctl_table nf_ct_netfilter_table[] = {
89647
89648 static int nf_conntrack_standalone_init_sysctl(struct net *net)
89649 {
89650- struct ctl_table *table;
89651+ ctl_table_no_const *table;
89652
89653 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
89654 GFP_KERNEL);
89655diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
89656index 902fb0a..87f7fdb 100644
89657--- a/net/netfilter/nf_conntrack_timestamp.c
89658+++ b/net/netfilter/nf_conntrack_timestamp.c
89659@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
89660 #ifdef CONFIG_SYSCTL
89661 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
89662 {
89663- struct ctl_table *table;
89664+ ctl_table_no_const *table;
89665
89666 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
89667 GFP_KERNEL);
89668diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
89669index 3b18dd1..f79e0ca 100644
89670--- a/net/netfilter/nf_log.c
89671+++ b/net/netfilter/nf_log.c
89672@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
89673
89674 #ifdef CONFIG_SYSCTL
89675 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
89676-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
89677+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
89678
89679 static int nf_log_proc_dostring(ctl_table *table, int write,
89680 void __user *buffer, size_t *lenp, loff_t *ppos)
89681@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
89682 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
89683 mutex_unlock(&nf_log_mutex);
89684 } else {
89685+ ctl_table_no_const nf_log_table = *table;
89686+
89687 mutex_lock(&nf_log_mutex);
89688 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
89689 lockdep_is_held(&nf_log_mutex));
89690 if (!logger)
89691- table->data = "NONE";
89692+ nf_log_table.data = "NONE";
89693 else
89694- table->data = logger->name;
89695- r = proc_dostring(table, write, buffer, lenp, ppos);
89696+ nf_log_table.data = logger->name;
89697+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
89698 mutex_unlock(&nf_log_mutex);
89699 }
89700
89701diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
89702index f042ae5..30ea486 100644
89703--- a/net/netfilter/nf_sockopt.c
89704+++ b/net/netfilter/nf_sockopt.c
89705@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
89706 }
89707 }
89708
89709- list_add(&reg->list, &nf_sockopts);
89710+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
89711 out:
89712 mutex_unlock(&nf_sockopt_mutex);
89713 return ret;
89714@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
89715 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
89716 {
89717 mutex_lock(&nf_sockopt_mutex);
89718- list_del(&reg->list);
89719+ pax_list_del((struct list_head *)&reg->list);
89720 mutex_unlock(&nf_sockopt_mutex);
89721 }
89722 EXPORT_SYMBOL(nf_unregister_sockopt);
89723diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
89724index 962e979..d4ae2e9 100644
89725--- a/net/netfilter/nfnetlink_log.c
89726+++ b/net/netfilter/nfnetlink_log.c
89727@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
89728 struct nfnl_log_net {
89729 spinlock_t instances_lock;
89730 struct hlist_head instance_table[INSTANCE_BUCKETS];
89731- atomic_t global_seq;
89732+ atomic_unchecked_t global_seq;
89733 };
89734
89735 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
89736@@ -559,7 +559,7 @@ __build_packet_message(struct nfnl_log_net *log,
89737 /* global sequence number */
89738 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
89739 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
89740- htonl(atomic_inc_return(&log->global_seq))))
89741+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
89742 goto nla_put_failure;
89743
89744 if (data_len) {
89745diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
89746new file mode 100644
89747index 0000000..c566332
89748--- /dev/null
89749+++ b/net/netfilter/xt_gradm.c
89750@@ -0,0 +1,51 @@
89751+/*
89752+ * gradm match for netfilter
89753