]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.10.2-201307212247.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.10.2-201307212247.patch
CommitLineData
b6d202b5
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 4336730..cb79194 100644
267--- a/Makefile
268+++ b/Makefile
269@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
270
271 HOSTCC = gcc
272 HOSTCXX = g++
273-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
274-HOSTCXXFLAGS = -O2
275+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
276+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
277+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
278
279 # Decide whether to build built-in, modular, or both.
280 # Normally, just do built-in.
281@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
282 # Rules shared between *config targets and build targets
283
284 # Basic helpers built in scripts/
285-PHONY += scripts_basic
286-scripts_basic:
287+PHONY += scripts_basic gcc-plugins
288+scripts_basic: gcc-plugins
289 $(Q)$(MAKE) $(build)=scripts/basic
290 $(Q)rm -f .tmp_quiet_recordmcount
291
292@@ -576,6 +577,65 @@ else
293 KBUILD_CFLAGS += -O2
294 endif
295
296+ifndef DISABLE_PAX_PLUGINS
297+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
298+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
299+else
300+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
301+endif
302+ifneq ($(PLUGINCC),)
303+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
304+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
305+endif
306+ifdef CONFIG_PAX_MEMORY_STACKLEAK
307+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
308+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
309+endif
310+ifdef CONFIG_KALLOCSTAT_PLUGIN
311+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
312+endif
313+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
314+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
315+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
316+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
317+endif
318+ifdef CONFIG_CHECKER_PLUGIN
319+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
320+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
321+endif
322+endif
323+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
324+ifdef CONFIG_PAX_SIZE_OVERFLOW
325+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
326+endif
327+ifdef CONFIG_PAX_LATENT_ENTROPY
328+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
329+endif
330+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
331+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
332+endif
333+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
334+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
335+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
336+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
337+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
338+ifeq ($(KBUILD_EXTMOD),)
339+gcc-plugins:
340+ $(Q)$(MAKE) $(build)=tools/gcc
341+else
342+gcc-plugins: ;
343+endif
344+else
345+gcc-plugins:
346+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
347+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
348+else
349+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
350+endif
351+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
352+endif
353+endif
354+
355 include $(srctree)/arch/$(SRCARCH)/Makefile
356
357 ifdef CONFIG_READABLE_ASM
358@@ -733,7 +793,7 @@ export mod_sign_cmd
359
360
361 ifeq ($(KBUILD_EXTMOD),)
362-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
363+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
364
365 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
366 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
367@@ -782,6 +842,8 @@ endif
368
369 # The actual objects are generated when descending,
370 # make sure no implicit rule kicks in
371+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
372+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
373 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
374
375 # Handle descending into subdirectories listed in $(vmlinux-dirs)
376@@ -791,7 +853,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
377 # Error messages still appears in the original language
378
379 PHONY += $(vmlinux-dirs)
380-$(vmlinux-dirs): prepare scripts
381+$(vmlinux-dirs): gcc-plugins prepare scripts
382 $(Q)$(MAKE) $(build)=$@
383
384 # Store (new) KERNELRELASE string in include/config/kernel.release
385@@ -835,6 +897,7 @@ prepare0: archprepare FORCE
386 $(Q)$(MAKE) $(build)=.
387
388 # All the preparing..
389+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
390 prepare: prepare0
391
392 # Generate some files
393@@ -942,6 +1005,8 @@ all: modules
394 # using awk while concatenating to the final file.
395
396 PHONY += modules
397+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
398+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
399 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
400 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
401 @$(kecho) ' Building modules, stage 2.';
402@@ -957,7 +1022,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
403
404 # Target to prepare building external modules
405 PHONY += modules_prepare
406-modules_prepare: prepare scripts
407+modules_prepare: gcc-plugins prepare scripts
408
409 # Target to install modules
410 PHONY += modules_install
411@@ -1023,7 +1088,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
412 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
413 signing_key.priv signing_key.x509 x509.genkey \
414 extra_certificates signing_key.x509.keyid \
415- signing_key.x509.signer
416+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
417
418 # clean - Delete most, but leave enough to build external modules
419 #
420@@ -1063,6 +1128,7 @@ distclean: mrproper
421 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
422 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
423 -o -name '.*.rej' \
424+ -o -name '.*.rej' -o -name '*.so' \
425 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
426 -type f -print | xargs rm -f
427
428@@ -1223,6 +1289,8 @@ PHONY += $(module-dirs) modules
429 $(module-dirs): crmodverdir $(objtree)/Module.symvers
430 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
431
432+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 modules: $(module-dirs)
435 @$(kecho) ' Building modules, stage 2.';
436 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
437@@ -1359,17 +1427,21 @@ else
438 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
439 endif
440
441-%.s: %.c prepare scripts FORCE
442+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
443+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
444+%.s: %.c gcc-plugins prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 %.i: %.c prepare scripts FORCE
447 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
448-%.o: %.c prepare scripts FORCE
449+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
450+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
451+%.o: %.c gcc-plugins prepare scripts FORCE
452 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
453 %.lst: %.c prepare scripts FORCE
454 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
455-%.s: %.S prepare scripts FORCE
456+%.s: %.S gcc-plugins prepare scripts FORCE
457 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
458-%.o: %.S prepare scripts FORCE
459+%.o: %.S gcc-plugins prepare scripts FORCE
460 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
461 %.symtypes: %.c prepare scripts FORCE
462 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
463@@ -1379,11 +1451,15 @@ endif
464 $(cmd_crmodverdir)
465 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
466 $(build)=$(build-dir)
467-%/: prepare scripts FORCE
468+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
469+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
470+%/: gcc-plugins prepare scripts FORCE
471 $(cmd_crmodverdir)
472 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
473 $(build)=$(build-dir)
474-%.ko: prepare scripts FORCE
475+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
476+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
477+%.ko: gcc-plugins prepare scripts FORCE
478 $(cmd_crmodverdir)
479 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
480 $(build)=$(build-dir) $(@:.ko=.o)
481diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
482index c2cbe4f..f7264b4 100644
483--- a/arch/alpha/include/asm/atomic.h
484+++ b/arch/alpha/include/asm/atomic.h
485@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
486 #define atomic_dec(v) atomic_sub(1,(v))
487 #define atomic64_dec(v) atomic64_sub(1,(v))
488
489+#define atomic64_read_unchecked(v) atomic64_read(v)
490+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
491+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
492+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
493+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
494+#define atomic64_inc_unchecked(v) atomic64_inc(v)
495+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
496+#define atomic64_dec_unchecked(v) atomic64_dec(v)
497+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
498+
499 #define smp_mb__before_atomic_dec() smp_mb()
500 #define smp_mb__after_atomic_dec() smp_mb()
501 #define smp_mb__before_atomic_inc() smp_mb()
502diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
503index ad368a9..fbe0f25 100644
504--- a/arch/alpha/include/asm/cache.h
505+++ b/arch/alpha/include/asm/cache.h
506@@ -4,19 +4,19 @@
507 #ifndef __ARCH_ALPHA_CACHE_H
508 #define __ARCH_ALPHA_CACHE_H
509
510+#include <linux/const.h>
511
512 /* Bytes per L1 (data) cache line. */
513 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
514-# define L1_CACHE_BYTES 64
515 # define L1_CACHE_SHIFT 6
516 #else
517 /* Both EV4 and EV5 are write-through, read-allocate,
518 direct-mapped, physical.
519 */
520-# define L1_CACHE_BYTES 32
521 # define L1_CACHE_SHIFT 5
522 #endif
523
524+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
525 #define SMP_CACHE_BYTES L1_CACHE_BYTES
526
527 #endif
528diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
529index 968d999..d36b2df 100644
530--- a/arch/alpha/include/asm/elf.h
531+++ b/arch/alpha/include/asm/elf.h
532@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
533
534 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
535
536+#ifdef CONFIG_PAX_ASLR
537+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
538+
539+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
540+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
541+#endif
542+
543 /* $0 is set by ld.so to a pointer to a function which might be
544 registered using atexit. This provides a mean for the dynamic
545 linker to call DT_FINI functions for shared libraries that have
546diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
547index bc2a0da..8ad11ee 100644
548--- a/arch/alpha/include/asm/pgalloc.h
549+++ b/arch/alpha/include/asm/pgalloc.h
550@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
551 pgd_set(pgd, pmd);
552 }
553
554+static inline void
555+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
556+{
557+ pgd_populate(mm, pgd, pmd);
558+}
559+
560 extern pgd_t *pgd_alloc(struct mm_struct *mm);
561
562 static inline void
563diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
564index 81a4342..348b927 100644
565--- a/arch/alpha/include/asm/pgtable.h
566+++ b/arch/alpha/include/asm/pgtable.h
567@@ -102,6 +102,17 @@ struct vm_area_struct;
568 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
569 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
570 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
571+
572+#ifdef CONFIG_PAX_PAGEEXEC
573+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
574+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
575+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
576+#else
577+# define PAGE_SHARED_NOEXEC PAGE_SHARED
578+# define PAGE_COPY_NOEXEC PAGE_COPY
579+# define PAGE_READONLY_NOEXEC PAGE_READONLY
580+#endif
581+
582 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
583
584 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
585diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
586index 2fd00b7..cfd5069 100644
587--- a/arch/alpha/kernel/module.c
588+++ b/arch/alpha/kernel/module.c
589@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
590
591 /* The small sections were sorted to the end of the segment.
592 The following should definitely cover them. */
593- gp = (u64)me->module_core + me->core_size - 0x8000;
594+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
595 got = sechdrs[me->arch.gotsecindex].sh_addr;
596
597 for (i = 0; i < n; i++) {
598diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
599index b9e37ad..44c24e7 100644
600--- a/arch/alpha/kernel/osf_sys.c
601+++ b/arch/alpha/kernel/osf_sys.c
602@@ -1297,10 +1297,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
603 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
604
605 static unsigned long
606-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
607- unsigned long limit)
608+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
609+ unsigned long limit, unsigned long flags)
610 {
611 struct vm_unmapped_area_info info;
612+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
613
614 info.flags = 0;
615 info.length = len;
616@@ -1308,6 +1309,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
617 info.high_limit = limit;
618 info.align_mask = 0;
619 info.align_offset = 0;
620+ info.threadstack_offset = offset;
621 return vm_unmapped_area(&info);
622 }
623
624@@ -1340,20 +1342,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
625 merely specific addresses, but regions of memory -- perhaps
626 this feature should be incorporated into all ports? */
627
628+#ifdef CONFIG_PAX_RANDMMAP
629+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
630+#endif
631+
632 if (addr) {
633- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
634+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
635 if (addr != (unsigned long) -ENOMEM)
636 return addr;
637 }
638
639 /* Next, try allocating at TASK_UNMAPPED_BASE. */
640- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
641- len, limit);
642+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
643+
644 if (addr != (unsigned long) -ENOMEM)
645 return addr;
646
647 /* Finally, try allocating in low memory. */
648- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
649+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
650
651 return addr;
652 }
653diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
654index 0c4132d..88f0d53 100644
655--- a/arch/alpha/mm/fault.c
656+++ b/arch/alpha/mm/fault.c
657@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
658 __reload_thread(pcb);
659 }
660
661+#ifdef CONFIG_PAX_PAGEEXEC
662+/*
663+ * PaX: decide what to do with offenders (regs->pc = fault address)
664+ *
665+ * returns 1 when task should be killed
666+ * 2 when patched PLT trampoline was detected
667+ * 3 when unpatched PLT trampoline was detected
668+ */
669+static int pax_handle_fetch_fault(struct pt_regs *regs)
670+{
671+
672+#ifdef CONFIG_PAX_EMUPLT
673+ int err;
674+
675+ do { /* PaX: patched PLT emulation #1 */
676+ unsigned int ldah, ldq, jmp;
677+
678+ err = get_user(ldah, (unsigned int *)regs->pc);
679+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
680+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
681+
682+ if (err)
683+ break;
684+
685+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
686+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
687+ jmp == 0x6BFB0000U)
688+ {
689+ unsigned long r27, addr;
690+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
691+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
692+
693+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
694+ err = get_user(r27, (unsigned long *)addr);
695+ if (err)
696+ break;
697+
698+ regs->r27 = r27;
699+ regs->pc = r27;
700+ return 2;
701+ }
702+ } while (0);
703+
704+ do { /* PaX: patched PLT emulation #2 */
705+ unsigned int ldah, lda, br;
706+
707+ err = get_user(ldah, (unsigned int *)regs->pc);
708+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
709+ err |= get_user(br, (unsigned int *)(regs->pc+8));
710+
711+ if (err)
712+ break;
713+
714+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
715+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
716+ (br & 0xFFE00000U) == 0xC3E00000U)
717+ {
718+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
719+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
720+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
721+
722+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
723+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
724+ return 2;
725+ }
726+ } while (0);
727+
728+ do { /* PaX: unpatched PLT emulation */
729+ unsigned int br;
730+
731+ err = get_user(br, (unsigned int *)regs->pc);
732+
733+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
734+ unsigned int br2, ldq, nop, jmp;
735+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
736+
737+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
738+ err = get_user(br2, (unsigned int *)addr);
739+ err |= get_user(ldq, (unsigned int *)(addr+4));
740+ err |= get_user(nop, (unsigned int *)(addr+8));
741+ err |= get_user(jmp, (unsigned int *)(addr+12));
742+ err |= get_user(resolver, (unsigned long *)(addr+16));
743+
744+ if (err)
745+ break;
746+
747+ if (br2 == 0xC3600000U &&
748+ ldq == 0xA77B000CU &&
749+ nop == 0x47FF041FU &&
750+ jmp == 0x6B7B0000U)
751+ {
752+ regs->r28 = regs->pc+4;
753+ regs->r27 = addr+16;
754+ regs->pc = resolver;
755+ return 3;
756+ }
757+ }
758+ } while (0);
759+#endif
760+
761+ return 1;
762+}
763+
764+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
765+{
766+ unsigned long i;
767+
768+ printk(KERN_ERR "PAX: bytes at PC: ");
769+ for (i = 0; i < 5; i++) {
770+ unsigned int c;
771+ if (get_user(c, (unsigned int *)pc+i))
772+ printk(KERN_CONT "???????? ");
773+ else
774+ printk(KERN_CONT "%08x ", c);
775+ }
776+ printk("\n");
777+}
778+#endif
779
780 /*
781 * This routine handles page faults. It determines the address,
782@@ -133,8 +251,29 @@ retry:
783 good_area:
784 si_code = SEGV_ACCERR;
785 if (cause < 0) {
786- if (!(vma->vm_flags & VM_EXEC))
787+ if (!(vma->vm_flags & VM_EXEC)) {
788+
789+#ifdef CONFIG_PAX_PAGEEXEC
790+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
791+ goto bad_area;
792+
793+ up_read(&mm->mmap_sem);
794+ switch (pax_handle_fetch_fault(regs)) {
795+
796+#ifdef CONFIG_PAX_EMUPLT
797+ case 2:
798+ case 3:
799+ return;
800+#endif
801+
802+ }
803+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
804+ do_group_exit(SIGKILL);
805+#else
806 goto bad_area;
807+#endif
808+
809+ }
810 } else if (!cause) {
811 /* Allow reads even for write-only mappings */
812 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
813diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
814index 136f263..f471277 100644
815--- a/arch/arm/Kconfig
816+++ b/arch/arm/Kconfig
817@@ -1766,7 +1766,7 @@ config ALIGNMENT_TRAP
818
819 config UACCESS_WITH_MEMCPY
820 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
821- depends on MMU
822+ depends on MMU && !PAX_MEMORY_UDEREF
823 default y if CPU_FEROCEON
824 help
825 Implement faster copy_to_user and clear_user methods for CPU
826diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
827index da1c77d..2ee6056 100644
828--- a/arch/arm/include/asm/atomic.h
829+++ b/arch/arm/include/asm/atomic.h
830@@ -17,17 +17,35 @@
831 #include <asm/barrier.h>
832 #include <asm/cmpxchg.h>
833
834+#ifdef CONFIG_GENERIC_ATOMIC64
835+#include <asm-generic/atomic64.h>
836+#endif
837+
838 #define ATOMIC_INIT(i) { (i) }
839
840 #ifdef __KERNEL__
841
842+#define _ASM_EXTABLE(from, to) \
843+" .pushsection __ex_table,\"a\"\n"\
844+" .align 3\n" \
845+" .long " #from ", " #to"\n" \
846+" .popsection"
847+
848 /*
849 * On ARM, ordinary assignment (str instruction) doesn't clear the local
850 * strex/ldrex monitor on some implementations. The reason we can use it for
851 * atomic_set() is the clrex or dummy strex done on every exception return.
852 */
853 #define atomic_read(v) (*(volatile int *)&(v)->counter)
854+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
855+{
856+ return v->counter;
857+}
858 #define atomic_set(v,i) (((v)->counter) = (i))
859+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
860+{
861+ v->counter = i;
862+}
863
864 #if __LINUX_ARM_ARCH__ >= 6
865
866@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
867 int result;
868
869 __asm__ __volatile__("@ atomic_add\n"
870+"1: ldrex %1, [%3]\n"
871+" adds %0, %1, %4\n"
872+
873+#ifdef CONFIG_PAX_REFCOUNT
874+" bvc 3f\n"
875+"2: bkpt 0xf103\n"
876+"3:\n"
877+#endif
878+
879+" strex %1, %0, [%3]\n"
880+" teq %1, #0\n"
881+" bne 1b"
882+
883+#ifdef CONFIG_PAX_REFCOUNT
884+"\n4:\n"
885+ _ASM_EXTABLE(2b, 4b)
886+#endif
887+
888+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
889+ : "r" (&v->counter), "Ir" (i)
890+ : "cc");
891+}
892+
893+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
894+{
895+ unsigned long tmp;
896+ int result;
897+
898+ __asm__ __volatile__("@ atomic_add_unchecked\n"
899 "1: ldrex %0, [%3]\n"
900 " add %0, %0, %4\n"
901 " strex %1, %0, [%3]\n"
902@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
903 smp_mb();
904
905 __asm__ __volatile__("@ atomic_add_return\n"
906+"1: ldrex %1, [%3]\n"
907+" adds %0, %1, %4\n"
908+
909+#ifdef CONFIG_PAX_REFCOUNT
910+" bvc 3f\n"
911+" mov %0, %1\n"
912+"2: bkpt 0xf103\n"
913+"3:\n"
914+#endif
915+
916+" strex %1, %0, [%3]\n"
917+" teq %1, #0\n"
918+" bne 1b"
919+
920+#ifdef CONFIG_PAX_REFCOUNT
921+"\n4:\n"
922+ _ASM_EXTABLE(2b, 4b)
923+#endif
924+
925+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
926+ : "r" (&v->counter), "Ir" (i)
927+ : "cc");
928+
929+ smp_mb();
930+
931+ return result;
932+}
933+
934+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
935+{
936+ unsigned long tmp;
937+ int result;
938+
939+ smp_mb();
940+
941+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
942 "1: ldrex %0, [%3]\n"
943 " add %0, %0, %4\n"
944 " strex %1, %0, [%3]\n"
945@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
946 int result;
947
948 __asm__ __volatile__("@ atomic_sub\n"
949+"1: ldrex %1, [%3]\n"
950+" subs %0, %1, %4\n"
951+
952+#ifdef CONFIG_PAX_REFCOUNT
953+" bvc 3f\n"
954+"2: bkpt 0xf103\n"
955+"3:\n"
956+#endif
957+
958+" strex %1, %0, [%3]\n"
959+" teq %1, #0\n"
960+" bne 1b"
961+
962+#ifdef CONFIG_PAX_REFCOUNT
963+"\n4:\n"
964+ _ASM_EXTABLE(2b, 4b)
965+#endif
966+
967+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
968+ : "r" (&v->counter), "Ir" (i)
969+ : "cc");
970+}
971+
972+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
973+{
974+ unsigned long tmp;
975+ int result;
976+
977+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
978 "1: ldrex %0, [%3]\n"
979 " sub %0, %0, %4\n"
980 " strex %1, %0, [%3]\n"
981@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
982 smp_mb();
983
984 __asm__ __volatile__("@ atomic_sub_return\n"
985-"1: ldrex %0, [%3]\n"
986-" sub %0, %0, %4\n"
987+"1: ldrex %1, [%3]\n"
988+" subs %0, %1, %4\n"
989+
990+#ifdef CONFIG_PAX_REFCOUNT
991+" bvc 3f\n"
992+" mov %0, %1\n"
993+"2: bkpt 0xf103\n"
994+"3:\n"
995+#endif
996+
997 " strex %1, %0, [%3]\n"
998 " teq %1, #0\n"
999 " bne 1b"
1000+
1001+#ifdef CONFIG_PAX_REFCOUNT
1002+"\n4:\n"
1003+ _ASM_EXTABLE(2b, 4b)
1004+#endif
1005+
1006 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1007 : "r" (&v->counter), "Ir" (i)
1008 : "cc");
1009@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1010 return oldval;
1011 }
1012
1013+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1014+{
1015+ unsigned long oldval, res;
1016+
1017+ smp_mb();
1018+
1019+ do {
1020+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1021+ "ldrex %1, [%3]\n"
1022+ "mov %0, #0\n"
1023+ "teq %1, %4\n"
1024+ "strexeq %0, %5, [%3]\n"
1025+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1026+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1027+ : "cc");
1028+ } while (res);
1029+
1030+ smp_mb();
1031+
1032+ return oldval;
1033+}
1034+
1035 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1036 {
1037 unsigned long tmp, tmp2;
1038@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1039
1040 return val;
1041 }
1042+
1043+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1044+{
1045+ return atomic_add_return(i, v);
1046+}
1047+
1048 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1049+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1050+{
1051+ (void) atomic_add_return(i, v);
1052+}
1053
1054 static inline int atomic_sub_return(int i, atomic_t *v)
1055 {
1056@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1057 return val;
1058 }
1059 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1060+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1061+{
1062+ (void) atomic_sub_return(i, v);
1063+}
1064
1065 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1066 {
1067@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1068 return ret;
1069 }
1070
1071+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1072+{
1073+ return atomic_cmpxchg(v, old, new);
1074+}
1075+
1076 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1077 {
1078 unsigned long flags;
1079@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1080 #endif /* __LINUX_ARM_ARCH__ */
1081
1082 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1083+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1084+{
1085+ return xchg(&v->counter, new);
1086+}
1087
1088 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1089 {
1090@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1091 }
1092
1093 #define atomic_inc(v) atomic_add(1, v)
1094+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1095+{
1096+ atomic_add_unchecked(1, v);
1097+}
1098 #define atomic_dec(v) atomic_sub(1, v)
1099+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1100+{
1101+ atomic_sub_unchecked(1, v);
1102+}
1103
1104 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1105+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1106+{
1107+ return atomic_add_return_unchecked(1, v) == 0;
1108+}
1109 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1110 #define atomic_inc_return(v) (atomic_add_return(1, v))
1111+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1112+{
1113+ return atomic_add_return_unchecked(1, v);
1114+}
1115 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1116 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1117
1118@@ -241,6 +428,14 @@ typedef struct {
1119 u64 __aligned(8) counter;
1120 } atomic64_t;
1121
1122+#ifdef CONFIG_PAX_REFCOUNT
1123+typedef struct {
1124+ u64 __aligned(8) counter;
1125+} atomic64_unchecked_t;
1126+#else
1127+typedef atomic64_t atomic64_unchecked_t;
1128+#endif
1129+
1130 #define ATOMIC64_INIT(i) { (i) }
1131
1132 #ifdef CONFIG_ARM_LPAE
1133@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1134 return result;
1135 }
1136
1137+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1138+{
1139+ u64 result;
1140+
1141+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1142+" ldrd %0, %H0, [%1]"
1143+ : "=&r" (result)
1144+ : "r" (&v->counter), "Qo" (v->counter)
1145+ );
1146+
1147+ return result;
1148+}
1149+
1150 static inline void atomic64_set(atomic64_t *v, u64 i)
1151 {
1152 __asm__ __volatile__("@ atomic64_set\n"
1153@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1154 : "r" (&v->counter), "r" (i)
1155 );
1156 }
1157+
1158+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1159+{
1160+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1161+" strd %2, %H2, [%1]"
1162+ : "=Qo" (v->counter)
1163+ : "r" (&v->counter), "r" (i)
1164+ );
1165+}
1166 #else
1167 static inline u64 atomic64_read(const atomic64_t *v)
1168 {
1169@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1170 return result;
1171 }
1172
1173+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1174+{
1175+ u64 result;
1176+
1177+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1178+" ldrexd %0, %H0, [%1]"
1179+ : "=&r" (result)
1180+ : "r" (&v->counter), "Qo" (v->counter)
1181+ );
1182+
1183+ return result;
1184+}
1185+
1186 static inline void atomic64_set(atomic64_t *v, u64 i)
1187 {
1188 u64 tmp;
1189@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1190 : "r" (&v->counter), "r" (i)
1191 : "cc");
1192 }
1193+
1194+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1195+{
1196+ u64 tmp;
1197+
1198+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1199+"1: ldrexd %0, %H0, [%2]\n"
1200+" strexd %0, %3, %H3, [%2]\n"
1201+" teq %0, #0\n"
1202+" bne 1b"
1203+ : "=&r" (tmp), "=Qo" (v->counter)
1204+ : "r" (&v->counter), "r" (i)
1205+ : "cc");
1206+}
1207+
1208 #endif
1209
1210 static inline void atomic64_add(u64 i, atomic64_t *v)
1211@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1212 __asm__ __volatile__("@ atomic64_add\n"
1213 "1: ldrexd %0, %H0, [%3]\n"
1214 " adds %0, %0, %4\n"
1215+" adcs %H0, %H0, %H4\n"
1216+
1217+#ifdef CONFIG_PAX_REFCOUNT
1218+" bvc 3f\n"
1219+"2: bkpt 0xf103\n"
1220+"3:\n"
1221+#endif
1222+
1223+" strexd %1, %0, %H0, [%3]\n"
1224+" teq %1, #0\n"
1225+" bne 1b"
1226+
1227+#ifdef CONFIG_PAX_REFCOUNT
1228+"\n4:\n"
1229+ _ASM_EXTABLE(2b, 4b)
1230+#endif
1231+
1232+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1233+ : "r" (&v->counter), "r" (i)
1234+ : "cc");
1235+}
1236+
1237+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1238+{
1239+ u64 result;
1240+ unsigned long tmp;
1241+
1242+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1243+"1: ldrexd %0, %H0, [%3]\n"
1244+" adds %0, %0, %4\n"
1245 " adc %H0, %H0, %H4\n"
1246 " strexd %1, %0, %H0, [%3]\n"
1247 " teq %1, #0\n"
1248@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1249
1250 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1251 {
1252- u64 result;
1253- unsigned long tmp;
1254+ u64 result, tmp;
1255
1256 smp_mb();
1257
1258 __asm__ __volatile__("@ atomic64_add_return\n"
1259+"1: ldrexd %1, %H1, [%3]\n"
1260+" adds %0, %1, %4\n"
1261+" adcs %H0, %H1, %H4\n"
1262+
1263+#ifdef CONFIG_PAX_REFCOUNT
1264+" bvc 3f\n"
1265+" mov %0, %1\n"
1266+" mov %H0, %H1\n"
1267+"2: bkpt 0xf103\n"
1268+"3:\n"
1269+#endif
1270+
1271+" strexd %1, %0, %H0, [%3]\n"
1272+" teq %1, #0\n"
1273+" bne 1b"
1274+
1275+#ifdef CONFIG_PAX_REFCOUNT
1276+"\n4:\n"
1277+ _ASM_EXTABLE(2b, 4b)
1278+#endif
1279+
1280+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1281+ : "r" (&v->counter), "r" (i)
1282+ : "cc");
1283+
1284+ smp_mb();
1285+
1286+ return result;
1287+}
1288+
1289+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1290+{
1291+ u64 result;
1292+ unsigned long tmp;
1293+
1294+ smp_mb();
1295+
1296+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1297 "1: ldrexd %0, %H0, [%3]\n"
1298 " adds %0, %0, %4\n"
1299 " adc %H0, %H0, %H4\n"
1300@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1301 __asm__ __volatile__("@ atomic64_sub\n"
1302 "1: ldrexd %0, %H0, [%3]\n"
1303 " subs %0, %0, %4\n"
1304+" sbcs %H0, %H0, %H4\n"
1305+
1306+#ifdef CONFIG_PAX_REFCOUNT
1307+" bvc 3f\n"
1308+"2: bkpt 0xf103\n"
1309+"3:\n"
1310+#endif
1311+
1312+" strexd %1, %0, %H0, [%3]\n"
1313+" teq %1, #0\n"
1314+" bne 1b"
1315+
1316+#ifdef CONFIG_PAX_REFCOUNT
1317+"\n4:\n"
1318+ _ASM_EXTABLE(2b, 4b)
1319+#endif
1320+
1321+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1322+ : "r" (&v->counter), "r" (i)
1323+ : "cc");
1324+}
1325+
1326+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1327+{
1328+ u64 result;
1329+ unsigned long tmp;
1330+
1331+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1332+"1: ldrexd %0, %H0, [%3]\n"
1333+" subs %0, %0, %4\n"
1334 " sbc %H0, %H0, %H4\n"
1335 " strexd %1, %0, %H0, [%3]\n"
1336 " teq %1, #0\n"
1337@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1338
1339 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1340 {
1341- u64 result;
1342- unsigned long tmp;
1343+ u64 result, tmp;
1344
1345 smp_mb();
1346
1347 __asm__ __volatile__("@ atomic64_sub_return\n"
1348-"1: ldrexd %0, %H0, [%3]\n"
1349-" subs %0, %0, %4\n"
1350-" sbc %H0, %H0, %H4\n"
1351+"1: ldrexd %1, %H1, [%3]\n"
1352+" subs %0, %1, %4\n"
1353+" sbcs %H0, %H1, %H4\n"
1354+
1355+#ifdef CONFIG_PAX_REFCOUNT
1356+" bvc 3f\n"
1357+" mov %0, %1\n"
1358+" mov %H0, %H1\n"
1359+"2: bkpt 0xf103\n"
1360+"3:\n"
1361+#endif
1362+
1363 " strexd %1, %0, %H0, [%3]\n"
1364 " teq %1, #0\n"
1365 " bne 1b"
1366+
1367+#ifdef CONFIG_PAX_REFCOUNT
1368+"\n4:\n"
1369+ _ASM_EXTABLE(2b, 4b)
1370+#endif
1371+
1372 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1373 : "r" (&v->counter), "r" (i)
1374 : "cc");
1375@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1376 return oldval;
1377 }
1378
1379+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1380+{
1381+ u64 oldval;
1382+ unsigned long res;
1383+
1384+ smp_mb();
1385+
1386+ do {
1387+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1388+ "ldrexd %1, %H1, [%3]\n"
1389+ "mov %0, #0\n"
1390+ "teq %1, %4\n"
1391+ "teqeq %H1, %H4\n"
1392+ "strexdeq %0, %5, %H5, [%3]"
1393+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1394+ : "r" (&ptr->counter), "r" (old), "r" (new)
1395+ : "cc");
1396+ } while (res);
1397+
1398+ smp_mb();
1399+
1400+ return oldval;
1401+}
1402+
1403 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1404 {
1405 u64 result;
1406@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1407
1408 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1409 {
1410- u64 result;
1411- unsigned long tmp;
1412+ u64 result, tmp;
1413
1414 smp_mb();
1415
1416 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1417-"1: ldrexd %0, %H0, [%3]\n"
1418-" subs %0, %0, #1\n"
1419-" sbc %H0, %H0, #0\n"
1420+"1: ldrexd %1, %H1, [%3]\n"
1421+" subs %0, %1, #1\n"
1422+" sbcs %H0, %H1, #0\n"
1423+
1424+#ifdef CONFIG_PAX_REFCOUNT
1425+" bvc 3f\n"
1426+" mov %0, %1\n"
1427+" mov %H0, %H1\n"
1428+"2: bkpt 0xf103\n"
1429+"3:\n"
1430+#endif
1431+
1432 " teq %H0, #0\n"
1433-" bmi 2f\n"
1434+" bmi 4f\n"
1435 " strexd %1, %0, %H0, [%3]\n"
1436 " teq %1, #0\n"
1437 " bne 1b\n"
1438-"2:"
1439+"4:\n"
1440+
1441+#ifdef CONFIG_PAX_REFCOUNT
1442+ _ASM_EXTABLE(2b, 4b)
1443+#endif
1444+
1445 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1446 : "r" (&v->counter)
1447 : "cc");
1448@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1449 " teq %0, %5\n"
1450 " teqeq %H0, %H5\n"
1451 " moveq %1, #0\n"
1452-" beq 2f\n"
1453+" beq 4f\n"
1454 " adds %0, %0, %6\n"
1455-" adc %H0, %H0, %H6\n"
1456+" adcs %H0, %H0, %H6\n"
1457+
1458+#ifdef CONFIG_PAX_REFCOUNT
1459+" bvc 3f\n"
1460+"2: bkpt 0xf103\n"
1461+"3:\n"
1462+#endif
1463+
1464 " strexd %2, %0, %H0, [%4]\n"
1465 " teq %2, #0\n"
1466 " bne 1b\n"
1467-"2:"
1468+"4:\n"
1469+
1470+#ifdef CONFIG_PAX_REFCOUNT
1471+ _ASM_EXTABLE(2b, 4b)
1472+#endif
1473+
1474 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1475 : "r" (&v->counter), "r" (u), "r" (a)
1476 : "cc");
1477@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1478
1479 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1480 #define atomic64_inc(v) atomic64_add(1LL, (v))
1481+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1482 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1483+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1484 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1485 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1486 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1487+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1488 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1489 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1490 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1491diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1492index 75fe66b..ba3dee4 100644
1493--- a/arch/arm/include/asm/cache.h
1494+++ b/arch/arm/include/asm/cache.h
1495@@ -4,8 +4,10 @@
1496 #ifndef __ASMARM_CACHE_H
1497 #define __ASMARM_CACHE_H
1498
1499+#include <linux/const.h>
1500+
1501 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1502-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1503+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1504
1505 /*
1506 * Memory returned by kmalloc() may be used for DMA, so we must make
1507@@ -24,5 +26,6 @@
1508 #endif
1509
1510 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1511+#define __read_only __attribute__ ((__section__(".data..read_only")))
1512
1513 #endif
1514diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1515index 17d0ae8..014e350 100644
1516--- a/arch/arm/include/asm/cacheflush.h
1517+++ b/arch/arm/include/asm/cacheflush.h
1518@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1519 void (*dma_unmap_area)(const void *, size_t, int);
1520
1521 void (*dma_flush_range)(const void *, const void *);
1522-};
1523+} __no_const;
1524
1525 /*
1526 * Select the calling method
1527diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1528index 6dcc164..b14d917 100644
1529--- a/arch/arm/include/asm/checksum.h
1530+++ b/arch/arm/include/asm/checksum.h
1531@@ -37,7 +37,19 @@ __wsum
1532 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1533
1534 __wsum
1535-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1536+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1537+
1538+static inline __wsum
1539+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1540+{
1541+ __wsum ret;
1542+ pax_open_userland();
1543+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1544+ pax_close_userland();
1545+ return ret;
1546+}
1547+
1548+
1549
1550 /*
1551 * Fold a partial checksum without adding pseudo headers
1552diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1553index 4f009c1..466c59b 100644
1554--- a/arch/arm/include/asm/cmpxchg.h
1555+++ b/arch/arm/include/asm/cmpxchg.h
1556@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1557
1558 #define xchg(ptr,x) \
1559 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1560+#define xchg_unchecked(ptr,x) \
1561+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1562
1563 #include <asm-generic/cmpxchg-local.h>
1564
1565diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1566index 6ddbe44..b5e38b1 100644
1567--- a/arch/arm/include/asm/domain.h
1568+++ b/arch/arm/include/asm/domain.h
1569@@ -48,18 +48,37 @@
1570 * Domain types
1571 */
1572 #define DOMAIN_NOACCESS 0
1573-#define DOMAIN_CLIENT 1
1574 #ifdef CONFIG_CPU_USE_DOMAINS
1575+#define DOMAIN_USERCLIENT 1
1576+#define DOMAIN_KERNELCLIENT 1
1577 #define DOMAIN_MANAGER 3
1578+#define DOMAIN_VECTORS DOMAIN_USER
1579 #else
1580+
1581+#ifdef CONFIG_PAX_KERNEXEC
1582 #define DOMAIN_MANAGER 1
1583+#define DOMAIN_KERNEXEC 3
1584+#else
1585+#define DOMAIN_MANAGER 1
1586+#endif
1587+
1588+#ifdef CONFIG_PAX_MEMORY_UDEREF
1589+#define DOMAIN_USERCLIENT 0
1590+#define DOMAIN_UDEREF 1
1591+#define DOMAIN_VECTORS DOMAIN_KERNEL
1592+#else
1593+#define DOMAIN_USERCLIENT 1
1594+#define DOMAIN_VECTORS DOMAIN_USER
1595+#endif
1596+#define DOMAIN_KERNELCLIENT 1
1597+
1598 #endif
1599
1600 #define domain_val(dom,type) ((type) << (2*(dom)))
1601
1602 #ifndef __ASSEMBLY__
1603
1604-#ifdef CONFIG_CPU_USE_DOMAINS
1605+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1606 static inline void set_domain(unsigned val)
1607 {
1608 asm volatile(
1609@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1610 isb();
1611 }
1612
1613-#define modify_domain(dom,type) \
1614- do { \
1615- struct thread_info *thread = current_thread_info(); \
1616- unsigned int domain = thread->cpu_domain; \
1617- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1618- thread->cpu_domain = domain | domain_val(dom, type); \
1619- set_domain(thread->cpu_domain); \
1620- } while (0)
1621-
1622+extern void modify_domain(unsigned int dom, unsigned int type);
1623 #else
1624 static inline void set_domain(unsigned val) { }
1625 static inline void modify_domain(unsigned dom, unsigned type) { }
1626diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1627index 38050b1..9d90e8b 100644
1628--- a/arch/arm/include/asm/elf.h
1629+++ b/arch/arm/include/asm/elf.h
1630@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1631 the loader. We need to make sure that it is out of the way of the program
1632 that it will "exec", and that there is sufficient room for the brk. */
1633
1634-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1635+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1636+
1637+#ifdef CONFIG_PAX_ASLR
1638+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1639+
1640+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1641+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1642+#endif
1643
1644 /* When the program starts, a1 contains a pointer to a function to be
1645 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1646@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1647 extern void elf_set_personality(const struct elf32_hdr *);
1648 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1649
1650-struct mm_struct;
1651-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1652-#define arch_randomize_brk arch_randomize_brk
1653-
1654 #endif
1655diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1656index de53547..52b9a28 100644
1657--- a/arch/arm/include/asm/fncpy.h
1658+++ b/arch/arm/include/asm/fncpy.h
1659@@ -81,7 +81,9 @@
1660 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1661 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1662 \
1663+ pax_open_kernel(); \
1664 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1665+ pax_close_kernel(); \
1666 flush_icache_range((unsigned long)(dest_buf), \
1667 (unsigned long)(dest_buf) + (size)); \
1668 \
1669diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1670index e42cf59..7b94b8f 100644
1671--- a/arch/arm/include/asm/futex.h
1672+++ b/arch/arm/include/asm/futex.h
1673@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1674 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1675 return -EFAULT;
1676
1677+ pax_open_userland();
1678+
1679 smp_mb();
1680 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1681 "1: ldrex %1, [%4]\n"
1682@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1683 : "cc", "memory");
1684 smp_mb();
1685
1686+ pax_close_userland();
1687+
1688 *uval = val;
1689 return ret;
1690 }
1691@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1692 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1693 return -EFAULT;
1694
1695+ pax_open_userland();
1696+
1697 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1698 "1: " TUSER(ldr) " %1, [%4]\n"
1699 " teq %1, %2\n"
1700@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1701 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1702 : "cc", "memory");
1703
1704+ pax_close_userland();
1705+
1706 *uval = val;
1707 return ret;
1708 }
1709@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1710 return -EFAULT;
1711
1712 pagefault_disable(); /* implies preempt_disable() */
1713+ pax_open_userland();
1714
1715 switch (op) {
1716 case FUTEX_OP_SET:
1717@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1718 ret = -ENOSYS;
1719 }
1720
1721+ pax_close_userland();
1722 pagefault_enable(); /* subsumes preempt_enable() */
1723
1724 if (!ret) {
1725diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1726index 83eb2f7..ed77159 100644
1727--- a/arch/arm/include/asm/kmap_types.h
1728+++ b/arch/arm/include/asm/kmap_types.h
1729@@ -4,6 +4,6 @@
1730 /*
1731 * This is the "bare minimum". AIO seems to require this.
1732 */
1733-#define KM_TYPE_NR 16
1734+#define KM_TYPE_NR 17
1735
1736 #endif
1737diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1738index 9e614a1..3302cca 100644
1739--- a/arch/arm/include/asm/mach/dma.h
1740+++ b/arch/arm/include/asm/mach/dma.h
1741@@ -22,7 +22,7 @@ struct dma_ops {
1742 int (*residue)(unsigned int, dma_t *); /* optional */
1743 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1744 const char *type;
1745-};
1746+} __do_const;
1747
1748 struct dma_struct {
1749 void *addr; /* single DMA address */
1750diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1751index 2fe141f..192dc01 100644
1752--- a/arch/arm/include/asm/mach/map.h
1753+++ b/arch/arm/include/asm/mach/map.h
1754@@ -27,13 +27,16 @@ struct map_desc {
1755 #define MT_MINICLEAN 6
1756 #define MT_LOW_VECTORS 7
1757 #define MT_HIGH_VECTORS 8
1758-#define MT_MEMORY 9
1759+#define MT_MEMORY_RWX 9
1760 #define MT_ROM 10
1761-#define MT_MEMORY_NONCACHED 11
1762+#define MT_MEMORY_NONCACHED_RX 11
1763 #define MT_MEMORY_DTCM 12
1764 #define MT_MEMORY_ITCM 13
1765 #define MT_MEMORY_SO 14
1766 #define MT_MEMORY_DMA_READY 15
1767+#define MT_MEMORY_RW 16
1768+#define MT_MEMORY_RX 17
1769+#define MT_MEMORY_NONCACHED_RW 18
1770
1771 #ifdef CONFIG_MMU
1772 extern void iotable_init(struct map_desc *, int);
1773diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1774index 12f71a1..04e063c 100644
1775--- a/arch/arm/include/asm/outercache.h
1776+++ b/arch/arm/include/asm/outercache.h
1777@@ -35,7 +35,7 @@ struct outer_cache_fns {
1778 #endif
1779 void (*set_debug)(unsigned long);
1780 void (*resume)(void);
1781-};
1782+} __no_const;
1783
1784 #ifdef CONFIG_OUTER_CACHE
1785
1786diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1787index 812a494..71fc0b6 100644
1788--- a/arch/arm/include/asm/page.h
1789+++ b/arch/arm/include/asm/page.h
1790@@ -114,7 +114,7 @@ struct cpu_user_fns {
1791 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1792 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1793 unsigned long vaddr, struct vm_area_struct *vma);
1794-};
1795+} __no_const;
1796
1797 #ifdef MULTI_USER
1798 extern struct cpu_user_fns cpu_user;
1799diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1800index 943504f..c37a730 100644
1801--- a/arch/arm/include/asm/pgalloc.h
1802+++ b/arch/arm/include/asm/pgalloc.h
1803@@ -17,6 +17,7 @@
1804 #include <asm/processor.h>
1805 #include <asm/cacheflush.h>
1806 #include <asm/tlbflush.h>
1807+#include <asm/system_info.h>
1808
1809 #define check_pgt_cache() do { } while (0)
1810
1811@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1812 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1813 }
1814
1815+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1816+{
1817+ pud_populate(mm, pud, pmd);
1818+}
1819+
1820 #else /* !CONFIG_ARM_LPAE */
1821
1822 /*
1823@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1824 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1825 #define pmd_free(mm, pmd) do { } while (0)
1826 #define pud_populate(mm,pmd,pte) BUG()
1827+#define pud_populate_kernel(mm,pmd,pte) BUG()
1828
1829 #endif /* CONFIG_ARM_LPAE */
1830
1831@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1832 __free_page(pte);
1833 }
1834
1835+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1836+{
1837+#ifdef CONFIG_ARM_LPAE
1838+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1839+#else
1840+ if (addr & SECTION_SIZE)
1841+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1842+ else
1843+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1844+#endif
1845+ flush_pmd_entry(pmdp);
1846+}
1847+
1848 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1849 pmdval_t prot)
1850 {
1851@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1852 static inline void
1853 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1854 {
1855- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1856+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1857 }
1858 #define pmd_pgtable(pmd) pmd_page(pmd)
1859
1860diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1861index 5cfba15..f415e1a 100644
1862--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1863+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1864@@ -20,12 +20,15 @@
1865 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1866 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1867 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1868+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1869 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1870 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1871 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1872+
1873 /*
1874 * - section
1875 */
1876+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1877 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1878 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1879 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1880@@ -37,6 +40,7 @@
1881 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1882 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1883 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1884+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1885
1886 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1887 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1888@@ -66,6 +70,7 @@
1889 * - extended small page/tiny page
1890 */
1891 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1892+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1893 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1894 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1895 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1896diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1897index f97ee02..07f1be5 100644
1898--- a/arch/arm/include/asm/pgtable-2level.h
1899+++ b/arch/arm/include/asm/pgtable-2level.h
1900@@ -125,6 +125,7 @@
1901 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1902 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1903 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1904+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1905
1906 /*
1907 * These are the memory types, defined to be compatible with
1908diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1909index 18f5cef..25b8f43 100644
1910--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1911+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1912@@ -41,6 +41,7 @@
1913 */
1914 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1915 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1916+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1917 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1918 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1919 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1920@@ -71,6 +72,7 @@
1921 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1922 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1923 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1924+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1925 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1926
1927 /*
1928diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1929index 86b8fe3..e25f975 100644
1930--- a/arch/arm/include/asm/pgtable-3level.h
1931+++ b/arch/arm/include/asm/pgtable-3level.h
1932@@ -74,6 +74,7 @@
1933 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1934 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1935 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1936+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1937 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1938 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1939 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1940@@ -82,6 +83,7 @@
1941 /*
1942 * To be used in assembly code with the upper page attributes.
1943 */
1944+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1945 #define L_PTE_XN_HIGH (1 << (54 - 32))
1946 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1947
1948diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1949index 9bcd262..fba731c 100644
1950--- a/arch/arm/include/asm/pgtable.h
1951+++ b/arch/arm/include/asm/pgtable.h
1952@@ -30,6 +30,9 @@
1953 #include <asm/pgtable-2level.h>
1954 #endif
1955
1956+#define ktla_ktva(addr) (addr)
1957+#define ktva_ktla(addr) (addr)
1958+
1959 /*
1960 * Just any arbitrary offset to the start of the vmalloc VM area: the
1961 * current 8MB value just means that there will be a 8MB "hole" after the
1962@@ -45,6 +48,9 @@
1963 #define LIBRARY_TEXT_START 0x0c000000
1964
1965 #ifndef __ASSEMBLY__
1966+extern pteval_t __supported_pte_mask;
1967+extern pmdval_t __supported_pmd_mask;
1968+
1969 extern void __pte_error(const char *file, int line, pte_t);
1970 extern void __pmd_error(const char *file, int line, pmd_t);
1971 extern void __pgd_error(const char *file, int line, pgd_t);
1972@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1973 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1974 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1975
1976+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1977+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1978+
1979+#ifdef CONFIG_PAX_KERNEXEC
1980+#include <asm/domain.h>
1981+#include <linux/thread_info.h>
1982+#include <linux/preempt.h>
1983+#endif
1984+
1985+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1986+static inline int test_domain(int domain, int domaintype)
1987+{
1988+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
1989+}
1990+#endif
1991+
1992+#ifdef CONFIG_PAX_KERNEXEC
1993+static inline unsigned long pax_open_kernel(void) {
1994+#ifdef CONFIG_ARM_LPAE
1995+ /* TODO */
1996+#else
1997+ preempt_disable();
1998+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
1999+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2000+#endif
2001+ return 0;
2002+}
2003+
2004+static inline unsigned long pax_close_kernel(void) {
2005+#ifdef CONFIG_ARM_LPAE
2006+ /* TODO */
2007+#else
2008+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2009+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2010+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2011+ preempt_enable_no_resched();
2012+#endif
2013+ return 0;
2014+}
2015+#else
2016+static inline unsigned long pax_open_kernel(void) { return 0; }
2017+static inline unsigned long pax_close_kernel(void) { return 0; }
2018+#endif
2019+
2020 /*
2021 * This is the lowest virtual address we can permit any user space
2022 * mapping to be mapped at. This is particularly important for
2023@@ -72,8 +122,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2024 /*
2025 * The pgprot_* and protection_map entries will be fixed up in runtime
2026 * to include the cachable and bufferable bits based on memory policy,
2027- * as well as any architecture dependent bits like global/ASID and SMP
2028- * shared mapping bits.
2029+ * as well as any architecture dependent bits like global/ASID, PXN,
2030+ * and SMP shared mapping bits.
2031 */
2032 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2033
2034@@ -257,7 +307,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2035 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2036 {
2037 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2038- L_PTE_NONE | L_PTE_VALID;
2039+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2040 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2041 return pte;
2042 }
2043diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2044index f3628fb..a0672dd 100644
2045--- a/arch/arm/include/asm/proc-fns.h
2046+++ b/arch/arm/include/asm/proc-fns.h
2047@@ -75,7 +75,7 @@ extern struct processor {
2048 unsigned int suspend_size;
2049 void (*do_suspend)(void *);
2050 void (*do_resume)(void *);
2051-} processor;
2052+} __do_const processor;
2053
2054 #ifndef MULTI_CPU
2055 extern void cpu_proc_init(void);
2056diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2057index 06e7d50..8a8e251 100644
2058--- a/arch/arm/include/asm/processor.h
2059+++ b/arch/arm/include/asm/processor.h
2060@@ -65,9 +65,8 @@ struct thread_struct {
2061 regs->ARM_cpsr |= PSR_ENDSTATE; \
2062 regs->ARM_pc = pc & ~1; /* pc */ \
2063 regs->ARM_sp = sp; /* sp */ \
2064- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2065- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2066- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2067+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2068+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2069 nommu_start_thread(regs); \
2070 })
2071
2072diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2073index ce0dbe7..c085b6f 100644
2074--- a/arch/arm/include/asm/psci.h
2075+++ b/arch/arm/include/asm/psci.h
2076@@ -29,7 +29,7 @@ struct psci_operations {
2077 int (*cpu_off)(struct psci_power_state state);
2078 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2079 int (*migrate)(unsigned long cpuid);
2080-};
2081+} __no_const;
2082
2083 extern struct psci_operations psci_ops;
2084
2085diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2086index d3a22be..3a69ad5 100644
2087--- a/arch/arm/include/asm/smp.h
2088+++ b/arch/arm/include/asm/smp.h
2089@@ -107,7 +107,7 @@ struct smp_operations {
2090 int (*cpu_disable)(unsigned int cpu);
2091 #endif
2092 #endif
2093-};
2094+} __no_const;
2095
2096 /*
2097 * set platform specific SMP operations
2098diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2099index 1995d1a..76693a2 100644
2100--- a/arch/arm/include/asm/thread_info.h
2101+++ b/arch/arm/include/asm/thread_info.h
2102@@ -77,9 +77,9 @@ struct thread_info {
2103 .flags = 0, \
2104 .preempt_count = INIT_PREEMPT_COUNT, \
2105 .addr_limit = KERNEL_DS, \
2106- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2107- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2108- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2109+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2110+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2111+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2112 .restart_block = { \
2113 .fn = do_no_restart_syscall, \
2114 }, \
2115@@ -152,7 +152,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2116 #define TIF_SYSCALL_AUDIT 9
2117 #define TIF_SYSCALL_TRACEPOINT 10
2118 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2119-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2120+/* within 8 bits of TIF_SYSCALL_TRACE
2121+ * to meet flexible second operand requirements
2122+ */
2123+#define TIF_GRSEC_SETXID 12
2124+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2125 #define TIF_USING_IWMMXT 17
2126 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2127 #define TIF_RESTORE_SIGMASK 20
2128@@ -166,10 +170,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2129 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2130 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2131 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2132+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2133
2134 /* Checks for any syscall work in entry-common.S */
2135 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2136- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2137+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2138
2139 /*
2140 * Change these and you break ASM code in entry-common.S
2141diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2142index 7e1f760..d42d7f8 100644
2143--- a/arch/arm/include/asm/uaccess.h
2144+++ b/arch/arm/include/asm/uaccess.h
2145@@ -18,6 +18,7 @@
2146 #include <asm/domain.h>
2147 #include <asm/unified.h>
2148 #include <asm/compiler.h>
2149+#include <asm/pgtable.h>
2150
2151 #define VERIFY_READ 0
2152 #define VERIFY_WRITE 1
2153@@ -63,11 +64,35 @@ extern int __put_user_bad(void);
2154 static inline void set_fs(mm_segment_t fs)
2155 {
2156 current_thread_info()->addr_limit = fs;
2157- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2158+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2159 }
2160
2161 #define segment_eq(a,b) ((a) == (b))
2162
2163+static inline void pax_open_userland(void)
2164+{
2165+
2166+#ifdef CONFIG_PAX_MEMORY_UDEREF
2167+ if (segment_eq(get_fs(), USER_DS)) {
2168+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2169+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2170+ }
2171+#endif
2172+
2173+}
2174+
2175+static inline void pax_close_userland(void)
2176+{
2177+
2178+#ifdef CONFIG_PAX_MEMORY_UDEREF
2179+ if (segment_eq(get_fs(), USER_DS)) {
2180+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2181+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2182+ }
2183+#endif
2184+
2185+}
2186+
2187 #define __addr_ok(addr) ({ \
2188 unsigned long flag; \
2189 __asm__("cmp %2, %0; movlo %0, #0" \
2190@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2191
2192 #define get_user(x,p) \
2193 ({ \
2194+ int __e; \
2195 might_fault(); \
2196- __get_user_check(x,p); \
2197+ pax_open_userland(); \
2198+ __e = __get_user_check(x,p); \
2199+ pax_close_userland(); \
2200+ __e; \
2201 })
2202
2203 extern int __put_user_1(void *, unsigned int);
2204@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2205
2206 #define put_user(x,p) \
2207 ({ \
2208+ int __e; \
2209 might_fault(); \
2210- __put_user_check(x,p); \
2211+ pax_open_userland(); \
2212+ __e = __put_user_check(x,p); \
2213+ pax_close_userland(); \
2214+ __e; \
2215 })
2216
2217 #else /* CONFIG_MMU */
2218@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2219 #define __get_user(x,ptr) \
2220 ({ \
2221 long __gu_err = 0; \
2222+ pax_open_userland(); \
2223 __get_user_err((x),(ptr),__gu_err); \
2224+ pax_close_userland(); \
2225 __gu_err; \
2226 })
2227
2228 #define __get_user_error(x,ptr,err) \
2229 ({ \
2230+ pax_open_userland(); \
2231 __get_user_err((x),(ptr),err); \
2232+ pax_close_userland(); \
2233 (void) 0; \
2234 })
2235
2236@@ -312,13 +349,17 @@ do { \
2237 #define __put_user(x,ptr) \
2238 ({ \
2239 long __pu_err = 0; \
2240+ pax_open_userland(); \
2241 __put_user_err((x),(ptr),__pu_err); \
2242+ pax_close_userland(); \
2243 __pu_err; \
2244 })
2245
2246 #define __put_user_error(x,ptr,err) \
2247 ({ \
2248+ pax_open_userland(); \
2249 __put_user_err((x),(ptr),err); \
2250+ pax_close_userland(); \
2251 (void) 0; \
2252 })
2253
2254@@ -418,11 +459,44 @@ do { \
2255
2256
2257 #ifdef CONFIG_MMU
2258-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2259-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2260+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2261+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2262+
2263+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2264+{
2265+ unsigned long ret;
2266+
2267+ check_object_size(to, n, false);
2268+ pax_open_userland();
2269+ ret = ___copy_from_user(to, from, n);
2270+ pax_close_userland();
2271+ return ret;
2272+}
2273+
2274+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2275+{
2276+ unsigned long ret;
2277+
2278+ check_object_size(from, n, true);
2279+ pax_open_userland();
2280+ ret = ___copy_to_user(to, from, n);
2281+ pax_close_userland();
2282+ return ret;
2283+}
2284+
2285 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2286-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2287+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2288 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2289+
2290+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2291+{
2292+ unsigned long ret;
2293+ pax_open_userland();
2294+ ret = ___clear_user(addr, n);
2295+ pax_close_userland();
2296+ return ret;
2297+}
2298+
2299 #else
2300 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2301 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2302@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2303
2304 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2305 {
2306+ if ((long)n < 0)
2307+ return n;
2308+
2309 if (access_ok(VERIFY_READ, from, n))
2310 n = __copy_from_user(to, from, n);
2311 else /* security hole - plug it */
2312@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2313
2314 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2315 {
2316+ if ((long)n < 0)
2317+ return n;
2318+
2319 if (access_ok(VERIFY_WRITE, to, n))
2320 n = __copy_to_user(to, from, n);
2321 return n;
2322diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2323index 96ee092..37f1844 100644
2324--- a/arch/arm/include/uapi/asm/ptrace.h
2325+++ b/arch/arm/include/uapi/asm/ptrace.h
2326@@ -73,7 +73,7 @@
2327 * ARMv7 groups of PSR bits
2328 */
2329 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2330-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2331+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2332 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2333 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2334
2335diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2336index 60d3b73..e5a0f22 100644
2337--- a/arch/arm/kernel/armksyms.c
2338+++ b/arch/arm/kernel/armksyms.c
2339@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2340
2341 /* networking */
2342 EXPORT_SYMBOL(csum_partial);
2343-EXPORT_SYMBOL(csum_partial_copy_from_user);
2344+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2345 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2346 EXPORT_SYMBOL(__csum_ipv6_magic);
2347
2348@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2349 #ifdef CONFIG_MMU
2350 EXPORT_SYMBOL(copy_page);
2351
2352-EXPORT_SYMBOL(__copy_from_user);
2353-EXPORT_SYMBOL(__copy_to_user);
2354-EXPORT_SYMBOL(__clear_user);
2355+EXPORT_SYMBOL(___copy_from_user);
2356+EXPORT_SYMBOL(___copy_to_user);
2357+EXPORT_SYMBOL(___clear_user);
2358
2359 EXPORT_SYMBOL(__get_user_1);
2360 EXPORT_SYMBOL(__get_user_2);
2361diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2362index 582b405..50351b7 100644
2363--- a/arch/arm/kernel/entry-armv.S
2364+++ b/arch/arm/kernel/entry-armv.S
2365@@ -47,6 +47,87 @@
2366 9997:
2367 .endm
2368
2369+ .macro pax_enter_kernel
2370+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2371+ @ make aligned space for saved DACR
2372+ sub sp, sp, #8
2373+ @ save regs
2374+ stmdb sp!, {r1, r2}
2375+ @ read DACR from cpu_domain into r1
2376+ mov r2, sp
2377+ @ assume 8K pages, since we have to split the immediate in two
2378+ bic r2, r2, #(0x1fc0)
2379+ bic r2, r2, #(0x3f)
2380+ ldr r1, [r2, #TI_CPU_DOMAIN]
2381+ @ store old DACR on stack
2382+ str r1, [sp, #8]
2383+#ifdef CONFIG_PAX_KERNEXEC
2384+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2385+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2386+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2387+#endif
2388+#ifdef CONFIG_PAX_MEMORY_UDEREF
2389+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2390+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2391+#endif
2392+ @ write r1 to current_thread_info()->cpu_domain
2393+ str r1, [r2, #TI_CPU_DOMAIN]
2394+ @ write r1 to DACR
2395+ mcr p15, 0, r1, c3, c0, 0
2396+ @ instruction sync
2397+ instr_sync
2398+ @ restore regs
2399+ ldmia sp!, {r1, r2}
2400+#endif
2401+ .endm
2402+
2403+ .macro pax_open_userland
2404+#ifdef CONFIG_PAX_MEMORY_UDEREF
2405+ @ save regs
2406+ stmdb sp!, {r0, r1}
2407+ @ read DACR from cpu_domain into r1
2408+ mov r0, sp
2409+ @ assume 8K pages, since we have to split the immediate in two
2410+ bic r0, r0, #(0x1fc0)
2411+ bic r0, r0, #(0x3f)
2412+ ldr r1, [r0, #TI_CPU_DOMAIN]
2413+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2414+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2415+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2416+ @ write r1 to current_thread_info()->cpu_domain
2417+ str r1, [r0, #TI_CPU_DOMAIN]
2418+ @ write r1 to DACR
2419+ mcr p15, 0, r1, c3, c0, 0
2420+ @ instruction sync
2421+ instr_sync
2422+ @ restore regs
2423+ ldmia sp!, {r0, r1}
2424+#endif
2425+ .endm
2426+
2427+ .macro pax_close_userland
2428+#ifdef CONFIG_PAX_MEMORY_UDEREF
2429+ @ save regs
2430+ stmdb sp!, {r0, r1}
2431+ @ read DACR from cpu_domain into r1
2432+ mov r0, sp
2433+ @ assume 8K pages, since we have to split the immediate in two
2434+ bic r0, r0, #(0x1fc0)
2435+ bic r0, r0, #(0x3f)
2436+ ldr r1, [r0, #TI_CPU_DOMAIN]
2437+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2438+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2439+ @ write r1 to current_thread_info()->cpu_domain
2440+ str r1, [r0, #TI_CPU_DOMAIN]
2441+ @ write r1 to DACR
2442+ mcr p15, 0, r1, c3, c0, 0
2443+ @ instruction sync
2444+ instr_sync
2445+ @ restore regs
2446+ ldmia sp!, {r0, r1}
2447+#endif
2448+ .endm
2449+
2450 .macro pabt_helper
2451 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2452 #ifdef MULTI_PABORT
2453@@ -89,11 +170,15 @@
2454 * Invalid mode handlers
2455 */
2456 .macro inv_entry, reason
2457+
2458+ pax_enter_kernel
2459+
2460 sub sp, sp, #S_FRAME_SIZE
2461 ARM( stmib sp, {r1 - lr} )
2462 THUMB( stmia sp, {r0 - r12} )
2463 THUMB( str sp, [sp, #S_SP] )
2464 THUMB( str lr, [sp, #S_LR] )
2465+
2466 mov r1, #\reason
2467 .endm
2468
2469@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2470 .macro svc_entry, stack_hole=0
2471 UNWIND(.fnstart )
2472 UNWIND(.save {r0 - pc} )
2473+
2474+ pax_enter_kernel
2475+
2476 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2477+
2478 #ifdef CONFIG_THUMB2_KERNEL
2479 SPFIX( str r0, [sp] ) @ temporarily saved
2480 SPFIX( mov r0, sp )
2481@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2482 ldmia r0, {r3 - r5}
2483 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2484 mov r6, #-1 @ "" "" "" ""
2485+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2486+ @ offset sp by 8 as done in pax_enter_kernel
2487+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2488+#else
2489 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2490+#endif
2491 SPFIX( addeq r2, r2, #4 )
2492 str r3, [sp, #-4]! @ save the "real" r0 copied
2493 @ from the exception stack
2494@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2495 .macro usr_entry
2496 UNWIND(.fnstart )
2497 UNWIND(.cantunwind ) @ don't unwind the user space
2498+
2499+ pax_enter_kernel_user
2500+
2501 sub sp, sp, #S_FRAME_SIZE
2502 ARM( stmib sp, {r1 - r12} )
2503 THUMB( stmia sp, {r0 - r12} )
2504@@ -414,7 +511,9 @@ __und_usr:
2505 tst r3, #PSR_T_BIT @ Thumb mode?
2506 bne __und_usr_thumb
2507 sub r4, r2, #4 @ ARM instr at LR - 4
2508+ pax_open_userland
2509 1: ldrt r0, [r4]
2510+ pax_close_userland
2511 #ifdef CONFIG_CPU_ENDIAN_BE8
2512 rev r0, r0 @ little endian instruction
2513 #endif
2514@@ -449,10 +548,14 @@ __und_usr_thumb:
2515 */
2516 .arch armv6t2
2517 #endif
2518+ pax_open_userland
2519 2: ldrht r5, [r4]
2520+ pax_close_userland
2521 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2522 blo __und_usr_fault_16 @ 16bit undefined instruction
2523+ pax_open_userland
2524 3: ldrht r0, [r2]
2525+ pax_close_userland
2526 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2527 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2528 orr r0, r0, r5, lsl #16
2529@@ -690,7 +793,7 @@ ENTRY(__switch_to)
2530 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2531 THUMB( str sp, [ip], #4 )
2532 THUMB( str lr, [ip], #4 )
2533-#ifdef CONFIG_CPU_USE_DOMAINS
2534+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2535 ldr r6, [r2, #TI_CPU_DOMAIN]
2536 #endif
2537 set_tls r3, r4, r5
2538@@ -699,7 +802,7 @@ ENTRY(__switch_to)
2539 ldr r8, =__stack_chk_guard
2540 ldr r7, [r7, #TSK_STACK_CANARY]
2541 #endif
2542-#ifdef CONFIG_CPU_USE_DOMAINS
2543+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2544 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2545 #endif
2546 mov r5, r0
2547diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2548index bc5bc0a..d0998ca 100644
2549--- a/arch/arm/kernel/entry-common.S
2550+++ b/arch/arm/kernel/entry-common.S
2551@@ -10,18 +10,46 @@
2552
2553 #include <asm/unistd.h>
2554 #include <asm/ftrace.h>
2555+#include <asm/domain.h>
2556 #include <asm/unwind.h>
2557
2558+#include "entry-header.S"
2559+
2560 #ifdef CONFIG_NEED_RET_TO_USER
2561 #include <mach/entry-macro.S>
2562 #else
2563 .macro arch_ret_to_user, tmp1, tmp2
2564+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2565+ @ save regs
2566+ stmdb sp!, {r1, r2}
2567+ @ read DACR from cpu_domain into r1
2568+ mov r2, sp
2569+ @ assume 8K pages, since we have to split the immediate in two
2570+ bic r2, r2, #(0x1fc0)
2571+ bic r2, r2, #(0x3f)
2572+ ldr r1, [r2, #TI_CPU_DOMAIN]
2573+#ifdef CONFIG_PAX_KERNEXEC
2574+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2575+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2576+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2577+#endif
2578+#ifdef CONFIG_PAX_MEMORY_UDEREF
2579+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2580+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2581+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2582+#endif
2583+ @ write r1 to current_thread_info()->cpu_domain
2584+ str r1, [r2, #TI_CPU_DOMAIN]
2585+ @ write r1 to DACR
2586+ mcr p15, 0, r1, c3, c0, 0
2587+ @ instruction sync
2588+ instr_sync
2589+ @ restore regs
2590+ ldmia sp!, {r1, r2}
2591+#endif
2592 .endm
2593 #endif
2594
2595-#include "entry-header.S"
2596-
2597-
2598 .align 5
2599 /*
2600 * This is the fast syscall return path. We do as little as
2601@@ -350,6 +378,7 @@ ENDPROC(ftrace_stub)
2602
2603 .align 5
2604 ENTRY(vector_swi)
2605+
2606 sub sp, sp, #S_FRAME_SIZE
2607 stmia sp, {r0 - r12} @ Calling r0 - r12
2608 ARM( add r8, sp, #S_PC )
2609@@ -399,6 +428,12 @@ ENTRY(vector_swi)
2610 ldr scno, [lr, #-4] @ get SWI instruction
2611 #endif
2612
2613+ /*
2614+ * do this here to avoid a performance hit of wrapping the code above
2615+ * that directly dereferences userland to parse the SWI instruction
2616+ */
2617+ pax_enter_kernel_user
2618+
2619 #ifdef CONFIG_ALIGNMENT_TRAP
2620 ldr ip, __cr_alignment
2621 ldr ip, [ip]
2622diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2623index 160f337..db67ee4 100644
2624--- a/arch/arm/kernel/entry-header.S
2625+++ b/arch/arm/kernel/entry-header.S
2626@@ -73,6 +73,60 @@
2627 msr cpsr_c, \rtemp @ switch back to the SVC mode
2628 .endm
2629
2630+ .macro pax_enter_kernel_user
2631+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2632+ @ save regs
2633+ stmdb sp!, {r0, r1}
2634+ @ read DACR from cpu_domain into r1
2635+ mov r0, sp
2636+ @ assume 8K pages, since we have to split the immediate in two
2637+ bic r0, r0, #(0x1fc0)
2638+ bic r0, r0, #(0x3f)
2639+ ldr r1, [r0, #TI_CPU_DOMAIN]
2640+#ifdef CONFIG_PAX_MEMORY_UDEREF
2641+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2642+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2643+#endif
2644+#ifdef CONFIG_PAX_KERNEXEC
2645+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2646+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2647+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2648+#endif
2649+ @ write r1 to current_thread_info()->cpu_domain
2650+ str r1, [r0, #TI_CPU_DOMAIN]
2651+ @ write r1 to DACR
2652+ mcr p15, 0, r1, c3, c0, 0
2653+ @ instruction sync
2654+ instr_sync
2655+ @ restore regs
2656+ ldmia sp!, {r0, r1}
2657+#endif
2658+ .endm
2659+
2660+ .macro pax_exit_kernel
2661+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2662+ @ save regs
2663+ stmdb sp!, {r0, r1}
2664+ @ read old DACR from stack into r1
2665+ ldr r1, [sp, #(8 + S_SP)]
2666+ sub r1, r1, #8
2667+ ldr r1, [r1]
2668+
2669+ @ write r1 to current_thread_info()->cpu_domain
2670+ mov r0, sp
2671+ @ assume 8K pages, since we have to split the immediate in two
2672+ bic r0, r0, #(0x1fc0)
2673+ bic r0, r0, #(0x3f)
2674+ str r1, [r0, #TI_CPU_DOMAIN]
2675+ @ write r1 to DACR
2676+ mcr p15, 0, r1, c3, c0, 0
2677+ @ instruction sync
2678+ instr_sync
2679+ @ restore regs
2680+ ldmia sp!, {r0, r1}
2681+#endif
2682+ .endm
2683+
2684 #ifndef CONFIG_THUMB2_KERNEL
2685 .macro svc_exit, rpsr, irq = 0
2686 .if \irq != 0
2687@@ -92,6 +146,9 @@
2688 blne trace_hardirqs_off
2689 #endif
2690 .endif
2691+
2692+ pax_exit_kernel
2693+
2694 msr spsr_cxsf, \rpsr
2695 #if defined(CONFIG_CPU_V6)
2696 ldr r0, [sp]
2697@@ -155,6 +212,9 @@
2698 blne trace_hardirqs_off
2699 #endif
2700 .endif
2701+
2702+ pax_exit_kernel
2703+
2704 ldr lr, [sp, #S_SP] @ top of the stack
2705 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2706 clrex @ clear the exclusive monitor
2707diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2708index 2adda11..7fbe958 100644
2709--- a/arch/arm/kernel/fiq.c
2710+++ b/arch/arm/kernel/fiq.c
2711@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2712 #if defined(CONFIG_CPU_USE_DOMAINS)
2713 memcpy((void *)0xffff001c, start, length);
2714 #else
2715+ pax_open_kernel();
2716 memcpy(vectors_page + 0x1c, start, length);
2717+ pax_close_kernel();
2718 #endif
2719 flush_icache_range(0xffff001c, 0xffff001c + length);
2720 if (!vectors_high())
2721diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2722index 8bac553..caee108 100644
2723--- a/arch/arm/kernel/head.S
2724+++ b/arch/arm/kernel/head.S
2725@@ -52,7 +52,9 @@
2726 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2727
2728 .macro pgtbl, rd, phys
2729- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2730+ mov \rd, #TEXT_OFFSET
2731+ sub \rd, #PG_DIR_SIZE
2732+ add \rd, \rd, \phys
2733 .endm
2734
2735 /*
2736@@ -434,7 +436,7 @@ __enable_mmu:
2737 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2738 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2739 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2740- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2741+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2742 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2743 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2744 #endif
2745diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2746index 1fd749e..47adb08 100644
2747--- a/arch/arm/kernel/hw_breakpoint.c
2748+++ b/arch/arm/kernel/hw_breakpoint.c
2749@@ -1029,7 +1029,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2750 return NOTIFY_OK;
2751 }
2752
2753-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2754+static struct notifier_block dbg_reset_nb = {
2755 .notifier_call = dbg_reset_notify,
2756 };
2757
2758diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2759index 1e9be5d..03edbc2 100644
2760--- a/arch/arm/kernel/module.c
2761+++ b/arch/arm/kernel/module.c
2762@@ -37,12 +37,37 @@
2763 #endif
2764
2765 #ifdef CONFIG_MMU
2766-void *module_alloc(unsigned long size)
2767+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2768 {
2769+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2770+ return NULL;
2771 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2772- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2773+ GFP_KERNEL, prot, -1,
2774 __builtin_return_address(0));
2775 }
2776+
2777+void *module_alloc(unsigned long size)
2778+{
2779+
2780+#ifdef CONFIG_PAX_KERNEXEC
2781+ return __module_alloc(size, PAGE_KERNEL);
2782+#else
2783+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2784+#endif
2785+
2786+}
2787+
2788+#ifdef CONFIG_PAX_KERNEXEC
2789+void module_free_exec(struct module *mod, void *module_region)
2790+{
2791+ module_free(mod, module_region);
2792+}
2793+
2794+void *module_alloc_exec(unsigned long size)
2795+{
2796+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2797+}
2798+#endif
2799 #endif
2800
2801 int
2802diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2803index 07314af..c46655c 100644
2804--- a/arch/arm/kernel/patch.c
2805+++ b/arch/arm/kernel/patch.c
2806@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2807 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2808 int size;
2809
2810+ pax_open_kernel();
2811 if (thumb2 && __opcode_is_thumb16(insn)) {
2812 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2813 size = sizeof(u16);
2814@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2815 *(u32 *)addr = insn;
2816 size = sizeof(u32);
2817 }
2818+ pax_close_kernel();
2819
2820 flush_icache_range((uintptr_t)(addr),
2821 (uintptr_t)(addr) + size);
2822diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2823index 1f2740e..b36e225 100644
2824--- a/arch/arm/kernel/perf_event_cpu.c
2825+++ b/arch/arm/kernel/perf_event_cpu.c
2826@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2827 return NOTIFY_OK;
2828 }
2829
2830-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2831+static struct notifier_block cpu_pmu_hotplug_notifier = {
2832 .notifier_call = cpu_pmu_notify,
2833 };
2834
2835diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2836index 6e8931c..82ec6a5 100644
2837--- a/arch/arm/kernel/process.c
2838+++ b/arch/arm/kernel/process.c
2839@@ -28,7 +28,6 @@
2840 #include <linux/tick.h>
2841 #include <linux/utsname.h>
2842 #include <linux/uaccess.h>
2843-#include <linux/random.h>
2844 #include <linux/hw_breakpoint.h>
2845 #include <linux/cpuidle.h>
2846 #include <linux/leds.h>
2847@@ -223,6 +222,7 @@ void machine_power_off(void)
2848
2849 if (pm_power_off)
2850 pm_power_off();
2851+ BUG();
2852 }
2853
2854 /*
2855@@ -236,7 +236,7 @@ void machine_power_off(void)
2856 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2857 * to use. Implementing such co-ordination would be essentially impossible.
2858 */
2859-void machine_restart(char *cmd)
2860+__noreturn void machine_restart(char *cmd)
2861 {
2862 smp_send_stop();
2863
2864@@ -258,8 +258,8 @@ void __show_regs(struct pt_regs *regs)
2865
2866 show_regs_print_info(KERN_DEFAULT);
2867
2868- print_symbol("PC is at %s\n", instruction_pointer(regs));
2869- print_symbol("LR is at %s\n", regs->ARM_lr);
2870+ printk("PC is at %pA\n", instruction_pointer(regs));
2871+ printk("LR is at %pA\n", regs->ARM_lr);
2872 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2873 "sp : %08lx ip : %08lx fp : %08lx\n",
2874 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2875@@ -426,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2876 return 0;
2877 }
2878
2879-unsigned long arch_randomize_brk(struct mm_struct *mm)
2880-{
2881- unsigned long range_end = mm->brk + 0x02000000;
2882- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2883-}
2884-
2885 #ifdef CONFIG_MMU
2886 /*
2887 * The vectors page is always readable from user space for the
2888@@ -441,12 +435,12 @@ unsigned long arch_randomize_brk(struct mm_struct *mm)
2889 static struct vm_area_struct gate_vma = {
2890 .vm_start = 0xffff0000,
2891 .vm_end = 0xffff0000 + PAGE_SIZE,
2892- .vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC,
2893+ .vm_flags = VM_NONE,
2894 };
2895
2896 static int __init gate_vma_init(void)
2897 {
2898- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2899+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2900 return 0;
2901 }
2902 arch_initcall(gate_vma_init);
2903diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2904index 3653164..d83e55d 100644
2905--- a/arch/arm/kernel/psci.c
2906+++ b/arch/arm/kernel/psci.c
2907@@ -24,7 +24,7 @@
2908 #include <asm/opcodes-virt.h>
2909 #include <asm/psci.h>
2910
2911-struct psci_operations psci_ops;
2912+struct psci_operations psci_ops __read_only;
2913
2914 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2915
2916diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2917index 03deeff..741ce88 100644
2918--- a/arch/arm/kernel/ptrace.c
2919+++ b/arch/arm/kernel/ptrace.c
2920@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2921 return current_thread_info()->syscall;
2922 }
2923
2924+#ifdef CONFIG_GRKERNSEC_SETXID
2925+extern void gr_delayed_cred_worker(void);
2926+#endif
2927+
2928 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2929 {
2930 current_thread_info()->syscall = scno;
2931
2932+#ifdef CONFIG_GRKERNSEC_SETXID
2933+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2934+ gr_delayed_cred_worker();
2935+#endif
2936+
2937 /* Do the secure computing check first; failures should be fast. */
2938 if (secure_computing(scno) == -1)
2939 return -1;
2940diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2941index b4b1d39..efdc9be 100644
2942--- a/arch/arm/kernel/setup.c
2943+++ b/arch/arm/kernel/setup.c
2944@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2945 unsigned int elf_hwcap __read_mostly;
2946 EXPORT_SYMBOL(elf_hwcap);
2947
2948+pteval_t __supported_pte_mask __read_only;
2949+pmdval_t __supported_pmd_mask __read_only;
2950
2951 #ifdef MULTI_CPU
2952-struct processor processor __read_mostly;
2953+struct processor processor;
2954 #endif
2955 #ifdef MULTI_TLB
2956-struct cpu_tlb_fns cpu_tlb __read_mostly;
2957+struct cpu_tlb_fns cpu_tlb __read_only;
2958 #endif
2959 #ifdef MULTI_USER
2960-struct cpu_user_fns cpu_user __read_mostly;
2961+struct cpu_user_fns cpu_user __read_only;
2962 #endif
2963 #ifdef MULTI_CACHE
2964-struct cpu_cache_fns cpu_cache __read_mostly;
2965+struct cpu_cache_fns cpu_cache __read_only;
2966 #endif
2967 #ifdef CONFIG_OUTER_CACHE
2968-struct outer_cache_fns outer_cache __read_mostly;
2969+struct outer_cache_fns outer_cache __read_only;
2970 EXPORT_SYMBOL(outer_cache);
2971 #endif
2972
2973@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2974 asm("mrc p15, 0, %0, c0, c1, 4"
2975 : "=r" (mmfr0));
2976 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2977- (mmfr0 & 0x000000f0) >= 0x00000030)
2978+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2979 cpu_arch = CPU_ARCH_ARMv7;
2980- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2981+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2982+ __supported_pte_mask |= L_PTE_PXN;
2983+ __supported_pmd_mask |= PMD_PXNTABLE;
2984+ }
2985+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2986 (mmfr0 & 0x000000f0) == 0x00000020)
2987 cpu_arch = CPU_ARCH_ARMv6;
2988 else
2989@@ -479,7 +485,7 @@ static void __init setup_processor(void)
2990 __cpu_architecture = __get_cpu_architecture();
2991
2992 #ifdef MULTI_CPU
2993- processor = *list->proc;
2994+ memcpy((void *)&processor, list->proc, sizeof processor);
2995 #endif
2996 #ifdef MULTI_TLB
2997 cpu_tlb = *list->tlb;
2998diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
2999index 296786b..a8d4dd5 100644
3000--- a/arch/arm/kernel/signal.c
3001+++ b/arch/arm/kernel/signal.c
3002@@ -396,22 +396,14 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3003 __put_user(sigreturn_codes[idx+1], rc+1))
3004 return 1;
3005
3006- if (cpsr & MODE32_BIT) {
3007- /*
3008- * 32-bit code can use the new high-page
3009- * signal return code support.
3010- */
3011- retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
3012- } else {
3013- /*
3014- * Ensure that the instruction cache sees
3015- * the return code written onto the stack.
3016- */
3017- flush_icache_range((unsigned long)rc,
3018- (unsigned long)(rc + 2));
3019+ /*
3020+ * Ensure that the instruction cache sees
3021+ * the return code written onto the stack.
3022+ */
3023+ flush_icache_range((unsigned long)rc,
3024+ (unsigned long)(rc + 2));
3025
3026- retcode = ((unsigned long)rc) + thumb;
3027- }
3028+ retcode = ((unsigned long)rc) + thumb;
3029 }
3030
3031 regs->ARM_r0 = map_sig(ksig->sig);
3032diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3033index 5919eb4..b5d6dfe 100644
3034--- a/arch/arm/kernel/smp.c
3035+++ b/arch/arm/kernel/smp.c
3036@@ -70,7 +70,7 @@ enum ipi_msg_type {
3037
3038 static DECLARE_COMPLETION(cpu_running);
3039
3040-static struct smp_operations smp_ops;
3041+static struct smp_operations smp_ops __read_only;
3042
3043 void __init smp_set_ops(struct smp_operations *ops)
3044 {
3045diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3046index 18b32e8..b0c8dca 100644
3047--- a/arch/arm/kernel/traps.c
3048+++ b/arch/arm/kernel/traps.c
3049@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3050 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3051 {
3052 #ifdef CONFIG_KALLSYMS
3053- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3054+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3055 #else
3056 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3057 #endif
3058@@ -259,6 +259,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3059 static int die_owner = -1;
3060 static unsigned int die_nest_count;
3061
3062+extern void gr_handle_kernel_exploit(void);
3063+
3064 static unsigned long oops_begin(void)
3065 {
3066 int cpu;
3067@@ -301,6 +303,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3068 panic("Fatal exception in interrupt");
3069 if (panic_on_oops)
3070 panic("Fatal exception");
3071+
3072+ gr_handle_kernel_exploit();
3073+
3074 if (signr)
3075 do_exit(signr);
3076 }
3077@@ -594,7 +599,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3078 * The user helper at 0xffff0fe0 must be used instead.
3079 * (see entry-armv.S for details)
3080 */
3081+ pax_open_kernel();
3082 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3083+ pax_close_kernel();
3084 }
3085 return 0;
3086
3087@@ -834,13 +841,10 @@ void __init early_trap_init(void *vectors_base)
3088 */
3089 kuser_get_tls_init(vectors);
3090
3091- /*
3092- * Copy signal return handlers into the vector page, and
3093- * set sigreturn to be a pointer to these.
3094- */
3095- memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE),
3096- sigreturn_codes, sizeof(sigreturn_codes));
3097-
3098 flush_icache_range(vectors, vectors + PAGE_SIZE);
3099- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3100+
3101+#ifndef CONFIG_PAX_MEMORY_UDEREF
3102+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3103+#endif
3104+
3105 }
3106diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3107index a871b8e..123b00a 100644
3108--- a/arch/arm/kernel/vmlinux.lds.S
3109+++ b/arch/arm/kernel/vmlinux.lds.S
3110@@ -8,7 +8,11 @@
3111 #include <asm/thread_info.h>
3112 #include <asm/memory.h>
3113 #include <asm/page.h>
3114-
3115+
3116+#ifdef CONFIG_PAX_KERNEXEC
3117+#include <asm/pgtable.h>
3118+#endif
3119+
3120 #define PROC_INFO \
3121 . = ALIGN(4); \
3122 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3123@@ -94,6 +98,11 @@ SECTIONS
3124 _text = .;
3125 HEAD_TEXT
3126 }
3127+
3128+#ifdef CONFIG_PAX_KERNEXEC
3129+ . = ALIGN(1<<SECTION_SHIFT);
3130+#endif
3131+
3132 .text : { /* Real text segment */
3133 _stext = .; /* Text and read-only data */
3134 __exception_text_start = .;
3135@@ -116,6 +125,8 @@ SECTIONS
3136 ARM_CPU_KEEP(PROC_INFO)
3137 }
3138
3139+ _etext = .; /* End of text section */
3140+
3141 RO_DATA(PAGE_SIZE)
3142
3143 . = ALIGN(4);
3144@@ -146,7 +157,9 @@ SECTIONS
3145
3146 NOTES
3147
3148- _etext = .; /* End of text and rodata section */
3149+#ifdef CONFIG_PAX_KERNEXEC
3150+ . = ALIGN(1<<SECTION_SHIFT);
3151+#endif
3152
3153 #ifndef CONFIG_XIP_KERNEL
3154 . = ALIGN(PAGE_SIZE);
3155@@ -207,6 +220,11 @@ SECTIONS
3156 . = PAGE_OFFSET + TEXT_OFFSET;
3157 #else
3158 __init_end = .;
3159+
3160+#ifdef CONFIG_PAX_KERNEXEC
3161+ . = ALIGN(1<<SECTION_SHIFT);
3162+#endif
3163+
3164 . = ALIGN(THREAD_SIZE);
3165 __data_loc = .;
3166 #endif
3167diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3168index 14a0d98..7771a7d 100644
3169--- a/arch/arm/lib/clear_user.S
3170+++ b/arch/arm/lib/clear_user.S
3171@@ -12,14 +12,14 @@
3172
3173 .text
3174
3175-/* Prototype: int __clear_user(void *addr, size_t sz)
3176+/* Prototype: int ___clear_user(void *addr, size_t sz)
3177 * Purpose : clear some user memory
3178 * Params : addr - user memory address to clear
3179 * : sz - number of bytes to clear
3180 * Returns : number of bytes NOT cleared
3181 */
3182 ENTRY(__clear_user_std)
3183-WEAK(__clear_user)
3184+WEAK(___clear_user)
3185 stmfd sp!, {r1, lr}
3186 mov r2, #0
3187 cmp r1, #4
3188@@ -44,7 +44,7 @@ WEAK(__clear_user)
3189 USER( strnebt r2, [r0])
3190 mov r0, #0
3191 ldmfd sp!, {r1, pc}
3192-ENDPROC(__clear_user)
3193+ENDPROC(___clear_user)
3194 ENDPROC(__clear_user_std)
3195
3196 .pushsection .fixup,"ax"
3197diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3198index 66a477a..bee61d3 100644
3199--- a/arch/arm/lib/copy_from_user.S
3200+++ b/arch/arm/lib/copy_from_user.S
3201@@ -16,7 +16,7 @@
3202 /*
3203 * Prototype:
3204 *
3205- * size_t __copy_from_user(void *to, const void *from, size_t n)
3206+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3207 *
3208 * Purpose:
3209 *
3210@@ -84,11 +84,11 @@
3211
3212 .text
3213
3214-ENTRY(__copy_from_user)
3215+ENTRY(___copy_from_user)
3216
3217 #include "copy_template.S"
3218
3219-ENDPROC(__copy_from_user)
3220+ENDPROC(___copy_from_user)
3221
3222 .pushsection .fixup,"ax"
3223 .align 0
3224diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3225index 6ee2f67..d1cce76 100644
3226--- a/arch/arm/lib/copy_page.S
3227+++ b/arch/arm/lib/copy_page.S
3228@@ -10,6 +10,7 @@
3229 * ASM optimised string functions
3230 */
3231 #include <linux/linkage.h>
3232+#include <linux/const.h>
3233 #include <asm/assembler.h>
3234 #include <asm/asm-offsets.h>
3235 #include <asm/cache.h>
3236diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3237index d066df6..df28194 100644
3238--- a/arch/arm/lib/copy_to_user.S
3239+++ b/arch/arm/lib/copy_to_user.S
3240@@ -16,7 +16,7 @@
3241 /*
3242 * Prototype:
3243 *
3244- * size_t __copy_to_user(void *to, const void *from, size_t n)
3245+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3246 *
3247 * Purpose:
3248 *
3249@@ -88,11 +88,11 @@
3250 .text
3251
3252 ENTRY(__copy_to_user_std)
3253-WEAK(__copy_to_user)
3254+WEAK(___copy_to_user)
3255
3256 #include "copy_template.S"
3257
3258-ENDPROC(__copy_to_user)
3259+ENDPROC(___copy_to_user)
3260 ENDPROC(__copy_to_user_std)
3261
3262 .pushsection .fixup,"ax"
3263diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3264index 7d08b43..f7ca7ea 100644
3265--- a/arch/arm/lib/csumpartialcopyuser.S
3266+++ b/arch/arm/lib/csumpartialcopyuser.S
3267@@ -57,8 +57,8 @@
3268 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3269 */
3270
3271-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3272-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3273+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3274+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3275
3276 #include "csumpartialcopygeneric.S"
3277
3278diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3279index 64dbfa5..84a3fd9 100644
3280--- a/arch/arm/lib/delay.c
3281+++ b/arch/arm/lib/delay.c
3282@@ -28,7 +28,7 @@
3283 /*
3284 * Default to the loop-based delay implementation.
3285 */
3286-struct arm_delay_ops arm_delay_ops = {
3287+struct arm_delay_ops arm_delay_ops __read_only = {
3288 .delay = __loop_delay,
3289 .const_udelay = __loop_const_udelay,
3290 .udelay = __loop_udelay,
3291diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3292index 025f742..8432b08 100644
3293--- a/arch/arm/lib/uaccess_with_memcpy.c
3294+++ b/arch/arm/lib/uaccess_with_memcpy.c
3295@@ -104,7 +104,7 @@ out:
3296 }
3297
3298 unsigned long
3299-__copy_to_user(void __user *to, const void *from, unsigned long n)
3300+___copy_to_user(void __user *to, const void *from, unsigned long n)
3301 {
3302 /*
3303 * This test is stubbed out of the main function above to keep
3304diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3305index f389228..592ef66 100644
3306--- a/arch/arm/mach-kirkwood/common.c
3307+++ b/arch/arm/mach-kirkwood/common.c
3308@@ -149,7 +149,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3309 clk_gate_ops.disable(hw);
3310 }
3311
3312-static struct clk_ops clk_gate_fn_ops;
3313+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3314+{
3315+ return clk_gate_ops.is_enabled(hw);
3316+}
3317+
3318+static struct clk_ops clk_gate_fn_ops = {
3319+ .enable = clk_gate_fn_enable,
3320+ .disable = clk_gate_fn_disable,
3321+ .is_enabled = clk_gate_fn_is_enabled,
3322+};
3323
3324 static struct clk __init *clk_register_gate_fn(struct device *dev,
3325 const char *name,
3326@@ -183,14 +192,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3327 gate_fn->fn_en = fn_en;
3328 gate_fn->fn_dis = fn_dis;
3329
3330- /* ops is the gate ops, but with our enable/disable functions */
3331- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3332- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3333- clk_gate_fn_ops = clk_gate_ops;
3334- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3335- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3336- }
3337-
3338 clk = clk_register(dev, &gate_fn->gate.hw);
3339
3340 if (IS_ERR(clk))
3341diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3342index f6eeb87..cc90868 100644
3343--- a/arch/arm/mach-omap2/board-n8x0.c
3344+++ b/arch/arm/mach-omap2/board-n8x0.c
3345@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3346 }
3347 #endif
3348
3349-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3350+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3351 .late_init = n8x0_menelaus_late_init,
3352 };
3353
3354diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3355index 6c4da12..d9ca72d 100644
3356--- a/arch/arm/mach-omap2/gpmc.c
3357+++ b/arch/arm/mach-omap2/gpmc.c
3358@@ -147,7 +147,6 @@ struct omap3_gpmc_regs {
3359 };
3360
3361 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3362-static struct irq_chip gpmc_irq_chip;
3363 static unsigned gpmc_irq_start;
3364
3365 static struct resource gpmc_mem_root;
3366@@ -711,6 +710,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3367
3368 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3369
3370+static struct irq_chip gpmc_irq_chip = {
3371+ .name = "gpmc",
3372+ .irq_startup = gpmc_irq_noop_ret,
3373+ .irq_enable = gpmc_irq_enable,
3374+ .irq_disable = gpmc_irq_disable,
3375+ .irq_shutdown = gpmc_irq_noop,
3376+ .irq_ack = gpmc_irq_noop,
3377+ .irq_mask = gpmc_irq_noop,
3378+ .irq_unmask = gpmc_irq_noop,
3379+
3380+};
3381+
3382 static int gpmc_setup_irq(void)
3383 {
3384 int i;
3385@@ -725,15 +736,6 @@ static int gpmc_setup_irq(void)
3386 return gpmc_irq_start;
3387 }
3388
3389- gpmc_irq_chip.name = "gpmc";
3390- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3391- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3392- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3393- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3394- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3395- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3396- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3397-
3398 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3399 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3400
3401diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3402index f8bb3b9..831e7b8 100644
3403--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3404+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3405@@ -339,7 +339,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3406 return NOTIFY_OK;
3407 }
3408
3409-static struct notifier_block __refdata irq_hotplug_notifier = {
3410+static struct notifier_block irq_hotplug_notifier = {
3411 .notifier_call = irq_cpu_hotplug_notify,
3412 };
3413
3414diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3415index e6d2307..d057195 100644
3416--- a/arch/arm/mach-omap2/omap_device.c
3417+++ b/arch/arm/mach-omap2/omap_device.c
3418@@ -499,7 +499,7 @@ void omap_device_delete(struct omap_device *od)
3419 struct platform_device __init *omap_device_build(const char *pdev_name,
3420 int pdev_id,
3421 struct omap_hwmod *oh,
3422- void *pdata, int pdata_len)
3423+ const void *pdata, int pdata_len)
3424 {
3425 struct omap_hwmod *ohs[] = { oh };
3426
3427@@ -527,7 +527,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3428 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3429 int pdev_id,
3430 struct omap_hwmod **ohs,
3431- int oh_cnt, void *pdata,
3432+ int oh_cnt, const void *pdata,
3433 int pdata_len)
3434 {
3435 int ret = -ENOMEM;
3436diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3437index 044c31d..2ee0861 100644
3438--- a/arch/arm/mach-omap2/omap_device.h
3439+++ b/arch/arm/mach-omap2/omap_device.h
3440@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3441 /* Core code interface */
3442
3443 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3444- struct omap_hwmod *oh, void *pdata,
3445+ struct omap_hwmod *oh, const void *pdata,
3446 int pdata_len);
3447
3448 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3449 struct omap_hwmod **oh, int oh_cnt,
3450- void *pdata, int pdata_len);
3451+ const void *pdata, int pdata_len);
3452
3453 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3454 struct omap_hwmod **ohs, int oh_cnt);
3455diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3456index 7341eff..fd75e34 100644
3457--- a/arch/arm/mach-omap2/omap_hwmod.c
3458+++ b/arch/arm/mach-omap2/omap_hwmod.c
3459@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3460 int (*init_clkdm)(struct omap_hwmod *oh);
3461 void (*update_context_lost)(struct omap_hwmod *oh);
3462 int (*get_context_lost)(struct omap_hwmod *oh);
3463-};
3464+} __no_const;
3465
3466 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3467-static struct omap_hwmod_soc_ops soc_ops;
3468+static struct omap_hwmod_soc_ops soc_ops __read_only;
3469
3470 /* omap_hwmod_list contains all registered struct omap_hwmods */
3471 static LIST_HEAD(omap_hwmod_list);
3472diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3473index d15c7bb..b2d1f0c 100644
3474--- a/arch/arm/mach-omap2/wd_timer.c
3475+++ b/arch/arm/mach-omap2/wd_timer.c
3476@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3477 struct omap_hwmod *oh;
3478 char *oh_name = "wd_timer2";
3479 char *dev_name = "omap_wdt";
3480- struct omap_wd_timer_platform_data pdata;
3481+ static struct omap_wd_timer_platform_data pdata = {
3482+ .read_reset_sources = prm_read_reset_sources
3483+ };
3484
3485 if (!cpu_class_is_omap2() || of_have_populated_dt())
3486 return 0;
3487@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3488 return -EINVAL;
3489 }
3490
3491- pdata.read_reset_sources = prm_read_reset_sources;
3492-
3493 pdev = omap_device_build(dev_name, id, oh, &pdata,
3494 sizeof(struct omap_wd_timer_platform_data));
3495 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3496diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3497index 0cdba8d..297993e 100644
3498--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3499+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3500@@ -181,7 +181,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3501 bool entered_lp2 = false;
3502
3503 if (tegra_pending_sgi())
3504- ACCESS_ONCE(abort_flag) = true;
3505+ ACCESS_ONCE_RW(abort_flag) = true;
3506
3507 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3508
3509diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3510index cad3ca86..1d79e0f 100644
3511--- a/arch/arm/mach-ux500/setup.h
3512+++ b/arch/arm/mach-ux500/setup.h
3513@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3514 .type = MT_DEVICE, \
3515 }
3516
3517-#define __MEM_DEV_DESC(x, sz) { \
3518- .virtual = IO_ADDRESS(x), \
3519- .pfn = __phys_to_pfn(x), \
3520- .length = sz, \
3521- .type = MT_MEMORY, \
3522-}
3523-
3524 extern struct smp_operations ux500_smp_ops;
3525 extern void ux500_cpu_die(unsigned int cpu);
3526
3527diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3528index 35955b5..b475042 100644
3529--- a/arch/arm/mm/Kconfig
3530+++ b/arch/arm/mm/Kconfig
3531@@ -432,7 +432,7 @@ config CPU_32v5
3532
3533 config CPU_32v6
3534 bool
3535- select CPU_USE_DOMAINS if CPU_V6 && MMU
3536+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3537 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3538
3539 config CPU_32v6K
3540@@ -581,6 +581,7 @@ config CPU_CP15_MPU
3541
3542 config CPU_USE_DOMAINS
3543 bool
3544+ depends on !ARM_LPAE && !PAX_KERNEXEC
3545 help
3546 This option enables or disables the use of domain switching
3547 via the set_fs() function.
3548diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3549index 6f4585b..7b6f52b 100644
3550--- a/arch/arm/mm/alignment.c
3551+++ b/arch/arm/mm/alignment.c
3552@@ -211,10 +211,12 @@ union offset_union {
3553 #define __get16_unaligned_check(ins,val,addr) \
3554 do { \
3555 unsigned int err = 0, v, a = addr; \
3556+ pax_open_userland(); \
3557 __get8_unaligned_check(ins,v,a,err); \
3558 val = v << ((BE) ? 8 : 0); \
3559 __get8_unaligned_check(ins,v,a,err); \
3560 val |= v << ((BE) ? 0 : 8); \
3561+ pax_close_userland(); \
3562 if (err) \
3563 goto fault; \
3564 } while (0)
3565@@ -228,6 +230,7 @@ union offset_union {
3566 #define __get32_unaligned_check(ins,val,addr) \
3567 do { \
3568 unsigned int err = 0, v, a = addr; \
3569+ pax_open_userland(); \
3570 __get8_unaligned_check(ins,v,a,err); \
3571 val = v << ((BE) ? 24 : 0); \
3572 __get8_unaligned_check(ins,v,a,err); \
3573@@ -236,6 +239,7 @@ union offset_union {
3574 val |= v << ((BE) ? 8 : 16); \
3575 __get8_unaligned_check(ins,v,a,err); \
3576 val |= v << ((BE) ? 0 : 24); \
3577+ pax_close_userland(); \
3578 if (err) \
3579 goto fault; \
3580 } while (0)
3581@@ -249,6 +253,7 @@ union offset_union {
3582 #define __put16_unaligned_check(ins,val,addr) \
3583 do { \
3584 unsigned int err = 0, v = val, a = addr; \
3585+ pax_open_userland(); \
3586 __asm__( FIRST_BYTE_16 \
3587 ARM( "1: "ins" %1, [%2], #1\n" ) \
3588 THUMB( "1: "ins" %1, [%2]\n" ) \
3589@@ -268,6 +273,7 @@ union offset_union {
3590 " .popsection\n" \
3591 : "=r" (err), "=&r" (v), "=&r" (a) \
3592 : "0" (err), "1" (v), "2" (a)); \
3593+ pax_close_userland(); \
3594 if (err) \
3595 goto fault; \
3596 } while (0)
3597@@ -281,6 +287,7 @@ union offset_union {
3598 #define __put32_unaligned_check(ins,val,addr) \
3599 do { \
3600 unsigned int err = 0, v = val, a = addr; \
3601+ pax_open_userland(); \
3602 __asm__( FIRST_BYTE_32 \
3603 ARM( "1: "ins" %1, [%2], #1\n" ) \
3604 THUMB( "1: "ins" %1, [%2]\n" ) \
3605@@ -310,6 +317,7 @@ union offset_union {
3606 " .popsection\n" \
3607 : "=r" (err), "=&r" (v), "=&r" (a) \
3608 : "0" (err), "1" (v), "2" (a)); \
3609+ pax_close_userland(); \
3610 if (err) \
3611 goto fault; \
3612 } while (0)
3613diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3614index 5dbf13f..1a60561 100644
3615--- a/arch/arm/mm/fault.c
3616+++ b/arch/arm/mm/fault.c
3617@@ -25,6 +25,7 @@
3618 #include <asm/system_misc.h>
3619 #include <asm/system_info.h>
3620 #include <asm/tlbflush.h>
3621+#include <asm/sections.h>
3622
3623 #include "fault.h"
3624
3625@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3626 if (fixup_exception(regs))
3627 return;
3628
3629+#ifdef CONFIG_PAX_KERNEXEC
3630+ if ((fsr & FSR_WRITE) &&
3631+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3632+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3633+ {
3634+ if (current->signal->curr_ip)
3635+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3636+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3637+ else
3638+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3639+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3640+ }
3641+#endif
3642+
3643 /*
3644 * No handler, we'll have to terminate things with extreme prejudice.
3645 */
3646@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3647 }
3648 #endif
3649
3650+#ifdef CONFIG_PAX_PAGEEXEC
3651+ if (fsr & FSR_LNX_PF) {
3652+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3653+ do_group_exit(SIGKILL);
3654+ }
3655+#endif
3656+
3657 tsk->thread.address = addr;
3658 tsk->thread.error_code = fsr;
3659 tsk->thread.trap_no = 14;
3660@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3661 }
3662 #endif /* CONFIG_MMU */
3663
3664+#ifdef CONFIG_PAX_PAGEEXEC
3665+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3666+{
3667+ long i;
3668+
3669+ printk(KERN_ERR "PAX: bytes at PC: ");
3670+ for (i = 0; i < 20; i++) {
3671+ unsigned char c;
3672+ if (get_user(c, (__force unsigned char __user *)pc+i))
3673+ printk(KERN_CONT "?? ");
3674+ else
3675+ printk(KERN_CONT "%02x ", c);
3676+ }
3677+ printk("\n");
3678+
3679+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3680+ for (i = -1; i < 20; i++) {
3681+ unsigned long c;
3682+ if (get_user(c, (__force unsigned long __user *)sp+i))
3683+ printk(KERN_CONT "???????? ");
3684+ else
3685+ printk(KERN_CONT "%08lx ", c);
3686+ }
3687+ printk("\n");
3688+}
3689+#endif
3690+
3691 /*
3692 * First Level Translation Fault Handler
3693 *
3694@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3695 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3696 struct siginfo info;
3697
3698+#ifdef CONFIG_PAX_MEMORY_UDEREF
3699+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3700+ if (current->signal->curr_ip)
3701+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3702+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3703+ else
3704+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3705+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3706+ goto die;
3707+ }
3708+#endif
3709+
3710 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3711 return;
3712
3713+die:
3714 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3715 inf->name, fsr, addr);
3716
3717@@ -575,9 +637,49 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3718 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3719 struct siginfo info;
3720
3721+ if (user_mode(regs)) {
3722+ if (addr == 0xffff0fe0UL) {
3723+ /*
3724+ * PaX: __kuser_get_tls emulation
3725+ */
3726+ regs->ARM_r0 = current_thread_info()->tp_value;
3727+ regs->ARM_pc = regs->ARM_lr;
3728+ return;
3729+ }
3730+ }
3731+
3732+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3733+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3734+ if (current->signal->curr_ip)
3735+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3736+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3737+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3738+ else
3739+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3740+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3741+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3742+ goto die;
3743+ }
3744+#endif
3745+
3746+#ifdef CONFIG_PAX_REFCOUNT
3747+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3748+ unsigned int bkpt;
3749+
3750+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3751+ current->thread.error_code = ifsr;
3752+ current->thread.trap_no = 0;
3753+ pax_report_refcount_overflow(regs);
3754+ fixup_exception(regs);
3755+ return;
3756+ }
3757+ }
3758+#endif
3759+
3760 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3761 return;
3762
3763+die:
3764 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3765 inf->name, ifsr, addr);
3766
3767diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3768index cf08bdf..772656c 100644
3769--- a/arch/arm/mm/fault.h
3770+++ b/arch/arm/mm/fault.h
3771@@ -3,6 +3,7 @@
3772
3773 /*
3774 * Fault status register encodings. We steal bit 31 for our own purposes.
3775+ * Set when the FSR value is from an instruction fault.
3776 */
3777 #define FSR_LNX_PF (1 << 31)
3778 #define FSR_WRITE (1 << 11)
3779@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3780 }
3781 #endif
3782
3783+/* valid for LPAE and !LPAE */
3784+static inline int is_xn_fault(unsigned int fsr)
3785+{
3786+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3787+}
3788+
3789+static inline int is_domain_fault(unsigned int fsr)
3790+{
3791+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3792+}
3793+
3794 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3795 unsigned long search_exception_table(unsigned long addr);
3796
3797diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3798index 0ecc43f..190b956 100644
3799--- a/arch/arm/mm/init.c
3800+++ b/arch/arm/mm/init.c
3801@@ -30,6 +30,8 @@
3802 #include <asm/setup.h>
3803 #include <asm/tlb.h>
3804 #include <asm/fixmap.h>
3805+#include <asm/system_info.h>
3806+#include <asm/cp15.h>
3807
3808 #include <asm/mach/arch.h>
3809 #include <asm/mach/map.h>
3810@@ -726,7 +728,46 @@ void free_initmem(void)
3811 {
3812 #ifdef CONFIG_HAVE_TCM
3813 extern char __tcm_start, __tcm_end;
3814+#endif
3815
3816+#ifdef CONFIG_PAX_KERNEXEC
3817+ unsigned long addr;
3818+ pgd_t *pgd;
3819+ pud_t *pud;
3820+ pmd_t *pmd;
3821+ int cpu_arch = cpu_architecture();
3822+ unsigned int cr = get_cr();
3823+
3824+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3825+ /* make pages tables, etc before .text NX */
3826+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3827+ pgd = pgd_offset_k(addr);
3828+ pud = pud_offset(pgd, addr);
3829+ pmd = pmd_offset(pud, addr);
3830+ __section_update(pmd, addr, PMD_SECT_XN);
3831+ }
3832+ /* make init NX */
3833+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3834+ pgd = pgd_offset_k(addr);
3835+ pud = pud_offset(pgd, addr);
3836+ pmd = pmd_offset(pud, addr);
3837+ __section_update(pmd, addr, PMD_SECT_XN);
3838+ }
3839+ /* make kernel code/rodata RX */
3840+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3841+ pgd = pgd_offset_k(addr);
3842+ pud = pud_offset(pgd, addr);
3843+ pmd = pmd_offset(pud, addr);
3844+#ifdef CONFIG_ARM_LPAE
3845+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3846+#else
3847+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3848+#endif
3849+ }
3850+ }
3851+#endif
3852+
3853+#ifdef CONFIG_HAVE_TCM
3854 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3855 free_reserved_area(&__tcm_start, &__tcm_end, 0, "TCM link");
3856 #endif
3857diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3858index 04d9006..c547d85 100644
3859--- a/arch/arm/mm/ioremap.c
3860+++ b/arch/arm/mm/ioremap.c
3861@@ -392,9 +392,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3862 unsigned int mtype;
3863
3864 if (cached)
3865- mtype = MT_MEMORY;
3866+ mtype = MT_MEMORY_RX;
3867 else
3868- mtype = MT_MEMORY_NONCACHED;
3869+ mtype = MT_MEMORY_NONCACHED_RX;
3870
3871 return __arm_ioremap_caller(phys_addr, size, mtype,
3872 __builtin_return_address(0));
3873diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3874index 10062ce..8695745 100644
3875--- a/arch/arm/mm/mmap.c
3876+++ b/arch/arm/mm/mmap.c
3877@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3878 struct vm_area_struct *vma;
3879 int do_align = 0;
3880 int aliasing = cache_is_vipt_aliasing();
3881+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3882 struct vm_unmapped_area_info info;
3883
3884 /*
3885@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3886 if (len > TASK_SIZE)
3887 return -ENOMEM;
3888
3889+#ifdef CONFIG_PAX_RANDMMAP
3890+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3891+#endif
3892+
3893 if (addr) {
3894 if (do_align)
3895 addr = COLOUR_ALIGN(addr, pgoff);
3896@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3897 addr = PAGE_ALIGN(addr);
3898
3899 vma = find_vma(mm, addr);
3900- if (TASK_SIZE - len >= addr &&
3901- (!vma || addr + len <= vma->vm_start))
3902+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3903 return addr;
3904 }
3905
3906@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3907 info.high_limit = TASK_SIZE;
3908 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3909 info.align_offset = pgoff << PAGE_SHIFT;
3910+ info.threadstack_offset = offset;
3911 return vm_unmapped_area(&info);
3912 }
3913
3914@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3915 unsigned long addr = addr0;
3916 int do_align = 0;
3917 int aliasing = cache_is_vipt_aliasing();
3918+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3919 struct vm_unmapped_area_info info;
3920
3921 /*
3922@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3923 return addr;
3924 }
3925
3926+#ifdef CONFIG_PAX_RANDMMAP
3927+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3928+#endif
3929+
3930 /* requesting a specific address */
3931 if (addr) {
3932 if (do_align)
3933@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3934 else
3935 addr = PAGE_ALIGN(addr);
3936 vma = find_vma(mm, addr);
3937- if (TASK_SIZE - len >= addr &&
3938- (!vma || addr + len <= vma->vm_start))
3939+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3940 return addr;
3941 }
3942
3943@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3944 info.high_limit = mm->mmap_base;
3945 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3946 info.align_offset = pgoff << PAGE_SHIFT;
3947+ info.threadstack_offset = offset;
3948 addr = vm_unmapped_area(&info);
3949
3950 /*
3951@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3952 {
3953 unsigned long random_factor = 0UL;
3954
3955+#ifdef CONFIG_PAX_RANDMMAP
3956+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3957+#endif
3958+
3959 /* 8 bits of randomness in 20 address space bits */
3960 if ((current->flags & PF_RANDOMIZE) &&
3961 !(current->personality & ADDR_NO_RANDOMIZE))
3962@@ -180,10 +194,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3963
3964 if (mmap_is_legacy()) {
3965 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3966+
3967+#ifdef CONFIG_PAX_RANDMMAP
3968+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3969+ mm->mmap_base += mm->delta_mmap;
3970+#endif
3971+
3972 mm->get_unmapped_area = arch_get_unmapped_area;
3973 mm->unmap_area = arch_unmap_area;
3974 } else {
3975 mm->mmap_base = mmap_base(random_factor);
3976+
3977+#ifdef CONFIG_PAX_RANDMMAP
3978+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3979+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3980+#endif
3981+
3982 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3983 mm->unmap_area = arch_unmap_area_topdown;
3984 }
3985diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3986index 4d409e6..f375351 100644
3987--- a/arch/arm/mm/mmu.c
3988+++ b/arch/arm/mm/mmu.c
3989@@ -36,6 +36,22 @@
3990 #include "mm.h"
3991 #include "tcm.h"
3992
3993+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3994+void modify_domain(unsigned int dom, unsigned int type)
3995+{
3996+ struct thread_info *thread = current_thread_info();
3997+ unsigned int domain = thread->cpu_domain;
3998+ /*
3999+ * DOMAIN_MANAGER might be defined to some other value,
4000+ * use the arch-defined constant
4001+ */
4002+ domain &= ~domain_val(dom, 3);
4003+ thread->cpu_domain = domain | domain_val(dom, type);
4004+ set_domain(thread->cpu_domain);
4005+}
4006+EXPORT_SYMBOL(modify_domain);
4007+#endif
4008+
4009 /*
4010 * empty_zero_page is a special page that is used for
4011 * zero-initialized data and COW.
4012@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4013
4014 #endif /* ifdef CONFIG_CPU_CP15 / else */
4015
4016-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4017+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4018 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4019
4020-static struct mem_type mem_types[] = {
4021+#ifdef CONFIG_PAX_KERNEXEC
4022+#define L_PTE_KERNEXEC L_PTE_RDONLY
4023+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4024+#else
4025+#define L_PTE_KERNEXEC L_PTE_DIRTY
4026+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4027+#endif
4028+
4029+static struct mem_type mem_types[] __read_only = {
4030 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4031 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4032 L_PTE_SHARED,
4033@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4034 [MT_UNCACHED] = {
4035 .prot_pte = PROT_PTE_DEVICE,
4036 .prot_l1 = PMD_TYPE_TABLE,
4037- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4038+ .prot_sect = PROT_SECT_DEVICE,
4039 .domain = DOMAIN_IO,
4040 },
4041 [MT_CACHECLEAN] = {
4042- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4043+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4044 .domain = DOMAIN_KERNEL,
4045 },
4046 #ifndef CONFIG_ARM_LPAE
4047 [MT_MINICLEAN] = {
4048- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4049+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4050 .domain = DOMAIN_KERNEL,
4051 },
4052 #endif
4053@@ -277,36 +301,65 @@ static struct mem_type mem_types[] = {
4054 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4055 L_PTE_RDONLY,
4056 .prot_l1 = PMD_TYPE_TABLE,
4057- .domain = DOMAIN_USER,
4058+ .domain = DOMAIN_VECTORS,
4059 },
4060 [MT_HIGH_VECTORS] = {
4061- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4062- L_PTE_USER | L_PTE_RDONLY,
4063+ /* we always want the vector page to be noaccess for userland on archs with
4064+ XN where we can enforce some reasonable measure of security
4065+ therefore, when kernexec is disabled, instead of L_PTE_USER | L_PTE_RDONLY
4066+ which turns into supervisor rwx, userland rx, we instead omit that entirely,
4067+ leaving it as supervisor rwx only
4068+ */
4069+#ifdef CONFIG_PAX_KERNEXEC
4070+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_RDONLY,
4071+#elif __LINUX_ARM_ARCH__ >= 6
4072+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4073+#else
4074+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_USER | L_PTE_RDONLY,
4075+#endif
4076 .prot_l1 = PMD_TYPE_TABLE,
4077- .domain = DOMAIN_USER,
4078+ .domain = DOMAIN_VECTORS,
4079 },
4080- [MT_MEMORY] = {
4081+ [MT_MEMORY_RWX] = {
4082 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4083 .prot_l1 = PMD_TYPE_TABLE,
4084 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4085 .domain = DOMAIN_KERNEL,
4086 },
4087+ [MT_MEMORY_RW] = {
4088+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4089+ .prot_l1 = PMD_TYPE_TABLE,
4090+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4091+ .domain = DOMAIN_KERNEL,
4092+ },
4093+ [MT_MEMORY_RX] = {
4094+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4095+ .prot_l1 = PMD_TYPE_TABLE,
4096+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4097+ .domain = DOMAIN_KERNEL,
4098+ },
4099 [MT_ROM] = {
4100- .prot_sect = PMD_TYPE_SECT,
4101+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4102 .domain = DOMAIN_KERNEL,
4103 },
4104- [MT_MEMORY_NONCACHED] = {
4105+ [MT_MEMORY_NONCACHED_RW] = {
4106 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4107 L_PTE_MT_BUFFERABLE,
4108 .prot_l1 = PMD_TYPE_TABLE,
4109 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4110 .domain = DOMAIN_KERNEL,
4111 },
4112+ [MT_MEMORY_NONCACHED_RX] = {
4113+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4114+ L_PTE_MT_BUFFERABLE,
4115+ .prot_l1 = PMD_TYPE_TABLE,
4116+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4117+ .domain = DOMAIN_KERNEL,
4118+ },
4119 [MT_MEMORY_DTCM] = {
4120- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4121- L_PTE_XN,
4122+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4123 .prot_l1 = PMD_TYPE_TABLE,
4124- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4125+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4126 .domain = DOMAIN_KERNEL,
4127 },
4128 [MT_MEMORY_ITCM] = {
4129@@ -316,10 +369,10 @@ static struct mem_type mem_types[] = {
4130 },
4131 [MT_MEMORY_SO] = {
4132 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4133- L_PTE_MT_UNCACHED | L_PTE_XN,
4134+ L_PTE_MT_UNCACHED,
4135 .prot_l1 = PMD_TYPE_TABLE,
4136 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4137- PMD_SECT_UNCACHED | PMD_SECT_XN,
4138+ PMD_SECT_UNCACHED,
4139 .domain = DOMAIN_KERNEL,
4140 },
4141 [MT_MEMORY_DMA_READY] = {
4142@@ -405,9 +458,35 @@ static void __init build_mem_type_table(void)
4143 * to prevent speculative instruction fetches.
4144 */
4145 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4146+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4147 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4148+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4149 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4150+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4151 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4152+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4153+
4154+ /* Mark other regions on ARMv6+ as execute-never */
4155+
4156+#ifdef CONFIG_PAX_KERNEXEC
4157+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4158+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4159+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4160+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4161+#ifndef CONFIG_ARM_LPAE
4162+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4163+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4164+#endif
4165+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4166+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4167+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4168+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4169+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4170+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4171+#endif
4172+
4173+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4174+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4175 }
4176 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4177 /*
4178@@ -468,6 +547,9 @@ static void __init build_mem_type_table(void)
4179 * from SVC mode and no access from userspace.
4180 */
4181 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4182+#ifdef CONFIG_PAX_KERNEXEC
4183+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4184+#endif
4185 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4186 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4187 #endif
4188@@ -485,11 +567,17 @@ static void __init build_mem_type_table(void)
4189 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4190 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4191 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4192- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4193- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4194+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4195+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4196+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4197+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4198+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4199+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4200 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4201- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4202- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4203+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4204+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4205+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4206+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4207 }
4208 }
4209
4210@@ -500,15 +588,20 @@ static void __init build_mem_type_table(void)
4211 if (cpu_arch >= CPU_ARCH_ARMv6) {
4212 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4213 /* Non-cacheable Normal is XCB = 001 */
4214- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4215+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4216+ PMD_SECT_BUFFERED;
4217+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4218 PMD_SECT_BUFFERED;
4219 } else {
4220 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4221- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4222+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4223+ PMD_SECT_TEX(1);
4224+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4225 PMD_SECT_TEX(1);
4226 }
4227 } else {
4228- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4229+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4230+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4231 }
4232
4233 #ifdef CONFIG_ARM_LPAE
4234@@ -524,6 +617,8 @@ static void __init build_mem_type_table(void)
4235 vecs_pgprot |= PTE_EXT_AF;
4236 #endif
4237
4238+ user_pgprot |= __supported_pte_mask;
4239+
4240 for (i = 0; i < 16; i++) {
4241 pteval_t v = pgprot_val(protection_map[i]);
4242 protection_map[i] = __pgprot(v | user_pgprot);
4243@@ -541,10 +636,15 @@ static void __init build_mem_type_table(void)
4244
4245 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4246 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4247- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4248- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4249+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4250+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4251+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4252+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4253+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4254+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4255 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4256- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4257+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4258+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4259 mem_types[MT_ROM].prot_sect |= cp->pmd;
4260
4261 switch (cp->pmd) {
4262@@ -1166,18 +1266,15 @@ void __init arm_mm_memblock_reserve(void)
4263 * called function. This means you can't use any function or debugging
4264 * method which may touch any device, otherwise the kernel _will_ crash.
4265 */
4266+
4267+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4268+
4269 static void __init devicemaps_init(struct machine_desc *mdesc)
4270 {
4271 struct map_desc map;
4272 unsigned long addr;
4273- void *vectors;
4274
4275- /*
4276- * Allocate the vector page early.
4277- */
4278- vectors = early_alloc(PAGE_SIZE);
4279-
4280- early_trap_init(vectors);
4281+ early_trap_init(&vectors);
4282
4283 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4284 pmd_clear(pmd_off_k(addr));
4285@@ -1217,7 +1314,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4286 * location (0xffff0000). If we aren't using high-vectors, also
4287 * create a mapping at the low-vectors virtual address.
4288 */
4289- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4290+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4291 map.virtual = 0xffff0000;
4292 map.length = PAGE_SIZE;
4293 map.type = MT_HIGH_VECTORS;
4294@@ -1275,8 +1372,39 @@ static void __init map_lowmem(void)
4295 map.pfn = __phys_to_pfn(start);
4296 map.virtual = __phys_to_virt(start);
4297 map.length = end - start;
4298- map.type = MT_MEMORY;
4299
4300+#ifdef CONFIG_PAX_KERNEXEC
4301+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4302+ struct map_desc kernel;
4303+ struct map_desc initmap;
4304+
4305+ /* when freeing initmem we will make this RW */
4306+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4307+ initmap.virtual = (unsigned long)__init_begin;
4308+ initmap.length = _sdata - __init_begin;
4309+ initmap.type = MT_MEMORY_RWX;
4310+ create_mapping(&initmap);
4311+
4312+ /* when freeing initmem we will make this RX */
4313+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4314+ kernel.virtual = (unsigned long)_stext;
4315+ kernel.length = __init_begin - _stext;
4316+ kernel.type = MT_MEMORY_RWX;
4317+ create_mapping(&kernel);
4318+
4319+ if (map.virtual < (unsigned long)_stext) {
4320+ map.length = (unsigned long)_stext - map.virtual;
4321+ map.type = MT_MEMORY_RWX;
4322+ create_mapping(&map);
4323+ }
4324+
4325+ map.pfn = __phys_to_pfn(__pa(_sdata));
4326+ map.virtual = (unsigned long)_sdata;
4327+ map.length = end - __pa(_sdata);
4328+ }
4329+#endif
4330+
4331+ map.type = MT_MEMORY_RW;
4332 create_mapping(&map);
4333 }
4334 }
4335diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4336index 9704097..3e36dde 100644
4337--- a/arch/arm/mm/proc-v7-2level.S
4338+++ b/arch/arm/mm/proc-v7-2level.S
4339@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4340 tst r1, #L_PTE_XN
4341 orrne r3, r3, #PTE_EXT_XN
4342
4343+ tst r1, #L_PTE_PXN
4344+ orrne r3, r3, #PTE_EXT_PXN
4345+
4346 tst r1, #L_PTE_YOUNG
4347 tstne r1, #L_PTE_VALID
4348 #ifndef CONFIG_CPU_USE_DOMAINS
4349diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4350index a5bc92d..0bb4730 100644
4351--- a/arch/arm/plat-omap/sram.c
4352+++ b/arch/arm/plat-omap/sram.c
4353@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4354 * Looks like we need to preserve some bootloader code at the
4355 * beginning of SRAM for jumping to flash for reboot to work...
4356 */
4357+ pax_open_kernel();
4358 memset_io(omap_sram_base + omap_sram_skip, 0,
4359 omap_sram_size - omap_sram_skip);
4360+ pax_close_kernel();
4361 }
4362diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4363index ce6d763..cfea917 100644
4364--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4365+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4366@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4367 int (*started)(unsigned ch);
4368 int (*flush)(unsigned ch);
4369 int (*stop)(unsigned ch);
4370-};
4371+} __no_const;
4372
4373 extern void *samsung_dmadev_get_ops(void);
4374 extern void *s3c_dma_get_ops(void);
4375diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4376index f4726dc..39ed646 100644
4377--- a/arch/arm64/kernel/debug-monitors.c
4378+++ b/arch/arm64/kernel/debug-monitors.c
4379@@ -149,7 +149,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4380 return NOTIFY_OK;
4381 }
4382
4383-static struct notifier_block __cpuinitdata os_lock_nb = {
4384+static struct notifier_block os_lock_nb = {
4385 .notifier_call = os_lock_notify,
4386 };
4387
4388diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4389index 5ab825c..96aaec8 100644
4390--- a/arch/arm64/kernel/hw_breakpoint.c
4391+++ b/arch/arm64/kernel/hw_breakpoint.c
4392@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4393 return NOTIFY_OK;
4394 }
4395
4396-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4397+static struct notifier_block hw_breakpoint_reset_nb = {
4398 .notifier_call = hw_breakpoint_reset_notify,
4399 };
4400
4401diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4402index c3a58a1..78fbf54 100644
4403--- a/arch/avr32/include/asm/cache.h
4404+++ b/arch/avr32/include/asm/cache.h
4405@@ -1,8 +1,10 @@
4406 #ifndef __ASM_AVR32_CACHE_H
4407 #define __ASM_AVR32_CACHE_H
4408
4409+#include <linux/const.h>
4410+
4411 #define L1_CACHE_SHIFT 5
4412-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4413+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4414
4415 /*
4416 * Memory returned by kmalloc() may be used for DMA, so we must make
4417diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4418index d232888..87c8df1 100644
4419--- a/arch/avr32/include/asm/elf.h
4420+++ b/arch/avr32/include/asm/elf.h
4421@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4422 the loader. We need to make sure that it is out of the way of the program
4423 that it will "exec", and that there is sufficient room for the brk. */
4424
4425-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4426+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4427
4428+#ifdef CONFIG_PAX_ASLR
4429+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4430+
4431+#define PAX_DELTA_MMAP_LEN 15
4432+#define PAX_DELTA_STACK_LEN 15
4433+#endif
4434
4435 /* This yields a mask that user programs can use to figure out what
4436 instruction set this CPU supports. This could be done in user space,
4437diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4438index 479330b..53717a8 100644
4439--- a/arch/avr32/include/asm/kmap_types.h
4440+++ b/arch/avr32/include/asm/kmap_types.h
4441@@ -2,9 +2,9 @@
4442 #define __ASM_AVR32_KMAP_TYPES_H
4443
4444 #ifdef CONFIG_DEBUG_HIGHMEM
4445-# define KM_TYPE_NR 29
4446+# define KM_TYPE_NR 30
4447 #else
4448-# define KM_TYPE_NR 14
4449+# define KM_TYPE_NR 15
4450 #endif
4451
4452 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4453diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4454index b2f2d2d..d1c85cb 100644
4455--- a/arch/avr32/mm/fault.c
4456+++ b/arch/avr32/mm/fault.c
4457@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4458
4459 int exception_trace = 1;
4460
4461+#ifdef CONFIG_PAX_PAGEEXEC
4462+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4463+{
4464+ unsigned long i;
4465+
4466+ printk(KERN_ERR "PAX: bytes at PC: ");
4467+ for (i = 0; i < 20; i++) {
4468+ unsigned char c;
4469+ if (get_user(c, (unsigned char *)pc+i))
4470+ printk(KERN_CONT "???????? ");
4471+ else
4472+ printk(KERN_CONT "%02x ", c);
4473+ }
4474+ printk("\n");
4475+}
4476+#endif
4477+
4478 /*
4479 * This routine handles page faults. It determines the address and the
4480 * problem, and then passes it off to one of the appropriate routines.
4481@@ -174,6 +191,16 @@ bad_area:
4482 up_read(&mm->mmap_sem);
4483
4484 if (user_mode(regs)) {
4485+
4486+#ifdef CONFIG_PAX_PAGEEXEC
4487+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4488+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4489+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4490+ do_group_exit(SIGKILL);
4491+ }
4492+ }
4493+#endif
4494+
4495 if (exception_trace && printk_ratelimit())
4496 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4497 "sp %08lx ecr %lu\n",
4498diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4499index 568885a..f8008df 100644
4500--- a/arch/blackfin/include/asm/cache.h
4501+++ b/arch/blackfin/include/asm/cache.h
4502@@ -7,6 +7,7 @@
4503 #ifndef __ARCH_BLACKFIN_CACHE_H
4504 #define __ARCH_BLACKFIN_CACHE_H
4505
4506+#include <linux/const.h>
4507 #include <linux/linkage.h> /* for asmlinkage */
4508
4509 /*
4510@@ -14,7 +15,7 @@
4511 * Blackfin loads 32 bytes for cache
4512 */
4513 #define L1_CACHE_SHIFT 5
4514-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4515+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4516 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4517
4518 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4519diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4520index aea2718..3639a60 100644
4521--- a/arch/cris/include/arch-v10/arch/cache.h
4522+++ b/arch/cris/include/arch-v10/arch/cache.h
4523@@ -1,8 +1,9 @@
4524 #ifndef _ASM_ARCH_CACHE_H
4525 #define _ASM_ARCH_CACHE_H
4526
4527+#include <linux/const.h>
4528 /* Etrax 100LX have 32-byte cache-lines. */
4529-#define L1_CACHE_BYTES 32
4530 #define L1_CACHE_SHIFT 5
4531+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4532
4533 #endif /* _ASM_ARCH_CACHE_H */
4534diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4535index 7caf25d..ee65ac5 100644
4536--- a/arch/cris/include/arch-v32/arch/cache.h
4537+++ b/arch/cris/include/arch-v32/arch/cache.h
4538@@ -1,11 +1,12 @@
4539 #ifndef _ASM_CRIS_ARCH_CACHE_H
4540 #define _ASM_CRIS_ARCH_CACHE_H
4541
4542+#include <linux/const.h>
4543 #include <arch/hwregs/dma.h>
4544
4545 /* A cache-line is 32 bytes. */
4546-#define L1_CACHE_BYTES 32
4547 #define L1_CACHE_SHIFT 5
4548+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4549
4550 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4551
4552diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4553index b86329d..6709906 100644
4554--- a/arch/frv/include/asm/atomic.h
4555+++ b/arch/frv/include/asm/atomic.h
4556@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4557 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4558 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4559
4560+#define atomic64_read_unchecked(v) atomic64_read(v)
4561+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4562+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4563+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4564+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4565+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4566+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4567+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4568+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4569+
4570 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4571 {
4572 int c, old;
4573diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4574index 2797163..c2a401d 100644
4575--- a/arch/frv/include/asm/cache.h
4576+++ b/arch/frv/include/asm/cache.h
4577@@ -12,10 +12,11 @@
4578 #ifndef __ASM_CACHE_H
4579 #define __ASM_CACHE_H
4580
4581+#include <linux/const.h>
4582
4583 /* bytes per L1 cache line */
4584 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4585-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4586+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4587
4588 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4589 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4590diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4591index 43901f2..0d8b865 100644
4592--- a/arch/frv/include/asm/kmap_types.h
4593+++ b/arch/frv/include/asm/kmap_types.h
4594@@ -2,6 +2,6 @@
4595 #ifndef _ASM_KMAP_TYPES_H
4596 #define _ASM_KMAP_TYPES_H
4597
4598-#define KM_TYPE_NR 17
4599+#define KM_TYPE_NR 18
4600
4601 #endif
4602diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4603index 836f147..4cf23f5 100644
4604--- a/arch/frv/mm/elf-fdpic.c
4605+++ b/arch/frv/mm/elf-fdpic.c
4606@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4607 {
4608 struct vm_area_struct *vma;
4609 struct vm_unmapped_area_info info;
4610+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4611
4612 if (len > TASK_SIZE)
4613 return -ENOMEM;
4614@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4615 if (addr) {
4616 addr = PAGE_ALIGN(addr);
4617 vma = find_vma(current->mm, addr);
4618- if (TASK_SIZE - len >= addr &&
4619- (!vma || addr + len <= vma->vm_start))
4620+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4621 goto success;
4622 }
4623
4624@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4625 info.high_limit = (current->mm->start_stack - 0x00200000);
4626 info.align_mask = 0;
4627 info.align_offset = 0;
4628+ info.threadstack_offset = offset;
4629 addr = vm_unmapped_area(&info);
4630 if (!(addr & ~PAGE_MASK))
4631 goto success;
4632diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4633index f4ca594..adc72fd6 100644
4634--- a/arch/hexagon/include/asm/cache.h
4635+++ b/arch/hexagon/include/asm/cache.h
4636@@ -21,9 +21,11 @@
4637 #ifndef __ASM_CACHE_H
4638 #define __ASM_CACHE_H
4639
4640+#include <linux/const.h>
4641+
4642 /* Bytes per L1 cache line */
4643-#define L1_CACHE_SHIFT (5)
4644-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4645+#define L1_CACHE_SHIFT 5
4646+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4647
4648 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4649 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4650diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4651index 6e6fe18..a6ae668 100644
4652--- a/arch/ia64/include/asm/atomic.h
4653+++ b/arch/ia64/include/asm/atomic.h
4654@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4655 #define atomic64_inc(v) atomic64_add(1, (v))
4656 #define atomic64_dec(v) atomic64_sub(1, (v))
4657
4658+#define atomic64_read_unchecked(v) atomic64_read(v)
4659+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4660+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4661+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4662+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4663+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4664+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4665+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4666+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4667+
4668 /* Atomic operations are already serializing */
4669 #define smp_mb__before_atomic_dec() barrier()
4670 #define smp_mb__after_atomic_dec() barrier()
4671diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4672index 988254a..e1ee885 100644
4673--- a/arch/ia64/include/asm/cache.h
4674+++ b/arch/ia64/include/asm/cache.h
4675@@ -1,6 +1,7 @@
4676 #ifndef _ASM_IA64_CACHE_H
4677 #define _ASM_IA64_CACHE_H
4678
4679+#include <linux/const.h>
4680
4681 /*
4682 * Copyright (C) 1998-2000 Hewlett-Packard Co
4683@@ -9,7 +10,7 @@
4684
4685 /* Bytes per L1 (data) cache line. */
4686 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4687-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4688+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4689
4690 #ifdef CONFIG_SMP
4691 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4692diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4693index 5a83c5c..4d7f553 100644
4694--- a/arch/ia64/include/asm/elf.h
4695+++ b/arch/ia64/include/asm/elf.h
4696@@ -42,6 +42,13 @@
4697 */
4698 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4699
4700+#ifdef CONFIG_PAX_ASLR
4701+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4702+
4703+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4704+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4705+#endif
4706+
4707 #define PT_IA_64_UNWIND 0x70000001
4708
4709 /* IA-64 relocations: */
4710diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4711index 96a8d92..617a1cf 100644
4712--- a/arch/ia64/include/asm/pgalloc.h
4713+++ b/arch/ia64/include/asm/pgalloc.h
4714@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4715 pgd_val(*pgd_entry) = __pa(pud);
4716 }
4717
4718+static inline void
4719+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4720+{
4721+ pgd_populate(mm, pgd_entry, pud);
4722+}
4723+
4724 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4725 {
4726 return quicklist_alloc(0, GFP_KERNEL, NULL);
4727@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4728 pud_val(*pud_entry) = __pa(pmd);
4729 }
4730
4731+static inline void
4732+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4733+{
4734+ pud_populate(mm, pud_entry, pmd);
4735+}
4736+
4737 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4738 {
4739 return quicklist_alloc(0, GFP_KERNEL, NULL);
4740diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4741index 815810c..d60bd4c 100644
4742--- a/arch/ia64/include/asm/pgtable.h
4743+++ b/arch/ia64/include/asm/pgtable.h
4744@@ -12,7 +12,7 @@
4745 * David Mosberger-Tang <davidm@hpl.hp.com>
4746 */
4747
4748-
4749+#include <linux/const.h>
4750 #include <asm/mman.h>
4751 #include <asm/page.h>
4752 #include <asm/processor.h>
4753@@ -142,6 +142,17 @@
4754 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4755 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4756 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4757+
4758+#ifdef CONFIG_PAX_PAGEEXEC
4759+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4760+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4761+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4762+#else
4763+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4764+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4765+# define PAGE_COPY_NOEXEC PAGE_COPY
4766+#endif
4767+
4768 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4769 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4770 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4771diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4772index 54ff557..70c88b7 100644
4773--- a/arch/ia64/include/asm/spinlock.h
4774+++ b/arch/ia64/include/asm/spinlock.h
4775@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4776 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4777
4778 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4779- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4780+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4781 }
4782
4783 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4784diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4785index 449c8c0..18965fb 100644
4786--- a/arch/ia64/include/asm/uaccess.h
4787+++ b/arch/ia64/include/asm/uaccess.h
4788@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4789 static inline unsigned long
4790 __copy_to_user (void __user *to, const void *from, unsigned long count)
4791 {
4792+ if (count > INT_MAX)
4793+ return count;
4794+
4795+ if (!__builtin_constant_p(count))
4796+ check_object_size(from, count, true);
4797+
4798 return __copy_user(to, (__force void __user *) from, count);
4799 }
4800
4801 static inline unsigned long
4802 __copy_from_user (void *to, const void __user *from, unsigned long count)
4803 {
4804+ if (count > INT_MAX)
4805+ return count;
4806+
4807+ if (!__builtin_constant_p(count))
4808+ check_object_size(to, count, false);
4809+
4810 return __copy_user((__force void __user *) to, from, count);
4811 }
4812
4813@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4814 ({ \
4815 void __user *__cu_to = (to); \
4816 const void *__cu_from = (from); \
4817- long __cu_len = (n); \
4818+ unsigned long __cu_len = (n); \
4819 \
4820- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4821+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4822+ if (!__builtin_constant_p(n)) \
4823+ check_object_size(__cu_from, __cu_len, true); \
4824 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4825+ } \
4826 __cu_len; \
4827 })
4828
4829@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4830 ({ \
4831 void *__cu_to = (to); \
4832 const void __user *__cu_from = (from); \
4833- long __cu_len = (n); \
4834+ unsigned long __cu_len = (n); \
4835 \
4836 __chk_user_ptr(__cu_from); \
4837- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4838+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4839+ if (!__builtin_constant_p(n)) \
4840+ check_object_size(__cu_to, __cu_len, false); \
4841 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4842+ } \
4843 __cu_len; \
4844 })
4845
4846diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4847index 2d67317..07d8bfa 100644
4848--- a/arch/ia64/kernel/err_inject.c
4849+++ b/arch/ia64/kernel/err_inject.c
4850@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4851 return NOTIFY_OK;
4852 }
4853
4854-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4855+static struct notifier_block err_inject_cpu_notifier =
4856 {
4857 .notifier_call = err_inject_cpu_callback,
4858 };
4859diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4860index d7396db..b33e873 100644
4861--- a/arch/ia64/kernel/mca.c
4862+++ b/arch/ia64/kernel/mca.c
4863@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4864 return NOTIFY_OK;
4865 }
4866
4867-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4868+static struct notifier_block mca_cpu_notifier = {
4869 .notifier_call = mca_cpu_callback
4870 };
4871
4872diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4873index 24603be..948052d 100644
4874--- a/arch/ia64/kernel/module.c
4875+++ b/arch/ia64/kernel/module.c
4876@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4877 void
4878 module_free (struct module *mod, void *module_region)
4879 {
4880- if (mod && mod->arch.init_unw_table &&
4881- module_region == mod->module_init) {
4882+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4883 unw_remove_unwind_table(mod->arch.init_unw_table);
4884 mod->arch.init_unw_table = NULL;
4885 }
4886@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4887 }
4888
4889 static inline int
4890+in_init_rx (const struct module *mod, uint64_t addr)
4891+{
4892+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4893+}
4894+
4895+static inline int
4896+in_init_rw (const struct module *mod, uint64_t addr)
4897+{
4898+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4899+}
4900+
4901+static inline int
4902 in_init (const struct module *mod, uint64_t addr)
4903 {
4904- return addr - (uint64_t) mod->module_init < mod->init_size;
4905+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4906+}
4907+
4908+static inline int
4909+in_core_rx (const struct module *mod, uint64_t addr)
4910+{
4911+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4912+}
4913+
4914+static inline int
4915+in_core_rw (const struct module *mod, uint64_t addr)
4916+{
4917+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4918 }
4919
4920 static inline int
4921 in_core (const struct module *mod, uint64_t addr)
4922 {
4923- return addr - (uint64_t) mod->module_core < mod->core_size;
4924+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4925 }
4926
4927 static inline int
4928@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4929 break;
4930
4931 case RV_BDREL:
4932- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4933+ if (in_init_rx(mod, val))
4934+ val -= (uint64_t) mod->module_init_rx;
4935+ else if (in_init_rw(mod, val))
4936+ val -= (uint64_t) mod->module_init_rw;
4937+ else if (in_core_rx(mod, val))
4938+ val -= (uint64_t) mod->module_core_rx;
4939+ else if (in_core_rw(mod, val))
4940+ val -= (uint64_t) mod->module_core_rw;
4941 break;
4942
4943 case RV_LTV:
4944@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4945 * addresses have been selected...
4946 */
4947 uint64_t gp;
4948- if (mod->core_size > MAX_LTOFF)
4949+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4950 /*
4951 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4952 * at the end of the module.
4953 */
4954- gp = mod->core_size - MAX_LTOFF / 2;
4955+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4956 else
4957- gp = mod->core_size / 2;
4958- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4959+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4960+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4961 mod->arch.gp = gp;
4962 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4963 }
4964diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4965index 2b3c2d7..a318d84 100644
4966--- a/arch/ia64/kernel/palinfo.c
4967+++ b/arch/ia64/kernel/palinfo.c
4968@@ -980,7 +980,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4969 return NOTIFY_OK;
4970 }
4971
4972-static struct notifier_block __refdata palinfo_cpu_notifier =
4973+static struct notifier_block palinfo_cpu_notifier =
4974 {
4975 .notifier_call = palinfo_cpu_callback,
4976 .priority = 0,
4977diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4978index 4bc580a..7767f24 100644
4979--- a/arch/ia64/kernel/salinfo.c
4980+++ b/arch/ia64/kernel/salinfo.c
4981@@ -609,7 +609,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4982 return NOTIFY_OK;
4983 }
4984
4985-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4986+static struct notifier_block salinfo_cpu_notifier =
4987 {
4988 .notifier_call = salinfo_cpu_callback,
4989 .priority = 0,
4990diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4991index 41e33f8..65180b2 100644
4992--- a/arch/ia64/kernel/sys_ia64.c
4993+++ b/arch/ia64/kernel/sys_ia64.c
4994@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4995 unsigned long align_mask = 0;
4996 struct mm_struct *mm = current->mm;
4997 struct vm_unmapped_area_info info;
4998+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4999
5000 if (len > RGN_MAP_LIMIT)
5001 return -ENOMEM;
5002@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5003 if (REGION_NUMBER(addr) == RGN_HPAGE)
5004 addr = 0;
5005 #endif
5006+
5007+#ifdef CONFIG_PAX_RANDMMAP
5008+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5009+ addr = mm->free_area_cache;
5010+ else
5011+#endif
5012+
5013 if (!addr)
5014 addr = TASK_UNMAPPED_BASE;
5015
5016@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5017 info.high_limit = TASK_SIZE;
5018 info.align_mask = align_mask;
5019 info.align_offset = 0;
5020+ info.threadstack_offset = offset;
5021 return vm_unmapped_area(&info);
5022 }
5023
5024diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
5025index dc00b2c..cce53c2 100644
5026--- a/arch/ia64/kernel/topology.c
5027+++ b/arch/ia64/kernel/topology.c
5028@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
5029 return NOTIFY_OK;
5030 }
5031
5032-static struct notifier_block __cpuinitdata cache_cpu_notifier =
5033+static struct notifier_block cache_cpu_notifier =
5034 {
5035 .notifier_call = cache_cpu_callback
5036 };
5037diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5038index 0ccb28f..8992469 100644
5039--- a/arch/ia64/kernel/vmlinux.lds.S
5040+++ b/arch/ia64/kernel/vmlinux.lds.S
5041@@ -198,7 +198,7 @@ SECTIONS {
5042 /* Per-cpu data: */
5043 . = ALIGN(PERCPU_PAGE_SIZE);
5044 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5045- __phys_per_cpu_start = __per_cpu_load;
5046+ __phys_per_cpu_start = per_cpu_load;
5047 /*
5048 * ensure percpu data fits
5049 * into percpu page size
5050diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5051index 6cf0341..d352594 100644
5052--- a/arch/ia64/mm/fault.c
5053+++ b/arch/ia64/mm/fault.c
5054@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5055 return pte_present(pte);
5056 }
5057
5058+#ifdef CONFIG_PAX_PAGEEXEC
5059+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5060+{
5061+ unsigned long i;
5062+
5063+ printk(KERN_ERR "PAX: bytes at PC: ");
5064+ for (i = 0; i < 8; i++) {
5065+ unsigned int c;
5066+ if (get_user(c, (unsigned int *)pc+i))
5067+ printk(KERN_CONT "???????? ");
5068+ else
5069+ printk(KERN_CONT "%08x ", c);
5070+ }
5071+ printk("\n");
5072+}
5073+#endif
5074+
5075 # define VM_READ_BIT 0
5076 # define VM_WRITE_BIT 1
5077 # define VM_EXEC_BIT 2
5078@@ -149,8 +166,21 @@ retry:
5079 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5080 goto bad_area;
5081
5082- if ((vma->vm_flags & mask) != mask)
5083+ if ((vma->vm_flags & mask) != mask) {
5084+
5085+#ifdef CONFIG_PAX_PAGEEXEC
5086+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5087+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5088+ goto bad_area;
5089+
5090+ up_read(&mm->mmap_sem);
5091+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5092+ do_group_exit(SIGKILL);
5093+ }
5094+#endif
5095+
5096 goto bad_area;
5097+ }
5098
5099 /*
5100 * If for any reason at all we couldn't handle the fault, make
5101diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5102index 76069c1..c2aa816 100644
5103--- a/arch/ia64/mm/hugetlbpage.c
5104+++ b/arch/ia64/mm/hugetlbpage.c
5105@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5106 unsigned long pgoff, unsigned long flags)
5107 {
5108 struct vm_unmapped_area_info info;
5109+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5110
5111 if (len > RGN_MAP_LIMIT)
5112 return -ENOMEM;
5113@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5114 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5115 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5116 info.align_offset = 0;
5117+ info.threadstack_offset = offset;
5118 return vm_unmapped_area(&info);
5119 }
5120
5121diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5122index d1fe4b4..2628f37 100644
5123--- a/arch/ia64/mm/init.c
5124+++ b/arch/ia64/mm/init.c
5125@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5126 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5127 vma->vm_end = vma->vm_start + PAGE_SIZE;
5128 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5129+
5130+#ifdef CONFIG_PAX_PAGEEXEC
5131+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5132+ vma->vm_flags &= ~VM_EXEC;
5133+
5134+#ifdef CONFIG_PAX_MPROTECT
5135+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5136+ vma->vm_flags &= ~VM_MAYEXEC;
5137+#endif
5138+
5139+ }
5140+#endif
5141+
5142 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5143 down_write(&current->mm->mmap_sem);
5144 if (insert_vm_struct(current->mm, vma)) {
5145diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5146index 40b3ee9..8c2c112 100644
5147--- a/arch/m32r/include/asm/cache.h
5148+++ b/arch/m32r/include/asm/cache.h
5149@@ -1,8 +1,10 @@
5150 #ifndef _ASM_M32R_CACHE_H
5151 #define _ASM_M32R_CACHE_H
5152
5153+#include <linux/const.h>
5154+
5155 /* L1 cache line size */
5156 #define L1_CACHE_SHIFT 4
5157-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5158+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5159
5160 #endif /* _ASM_M32R_CACHE_H */
5161diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5162index 82abd15..d95ae5d 100644
5163--- a/arch/m32r/lib/usercopy.c
5164+++ b/arch/m32r/lib/usercopy.c
5165@@ -14,6 +14,9 @@
5166 unsigned long
5167 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5168 {
5169+ if ((long)n < 0)
5170+ return n;
5171+
5172 prefetch(from);
5173 if (access_ok(VERIFY_WRITE, to, n))
5174 __copy_user(to,from,n);
5175@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5176 unsigned long
5177 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5178 {
5179+ if ((long)n < 0)
5180+ return n;
5181+
5182 prefetchw(to);
5183 if (access_ok(VERIFY_READ, from, n))
5184 __copy_user_zeroing(to,from,n);
5185diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5186index 0395c51..5f26031 100644
5187--- a/arch/m68k/include/asm/cache.h
5188+++ b/arch/m68k/include/asm/cache.h
5189@@ -4,9 +4,11 @@
5190 #ifndef __ARCH_M68K_CACHE_H
5191 #define __ARCH_M68K_CACHE_H
5192
5193+#include <linux/const.h>
5194+
5195 /* bytes per L1 cache line */
5196 #define L1_CACHE_SHIFT 4
5197-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5198+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5199
5200 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5201
5202diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5203index 3c52fa6..11b2ad8 100644
5204--- a/arch/metag/mm/hugetlbpage.c
5205+++ b/arch/metag/mm/hugetlbpage.c
5206@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5207 info.high_limit = TASK_SIZE;
5208 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5209 info.align_offset = 0;
5210+ info.threadstack_offset = 0;
5211 return vm_unmapped_area(&info);
5212 }
5213
5214diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5215index 4efe96a..60e8699 100644
5216--- a/arch/microblaze/include/asm/cache.h
5217+++ b/arch/microblaze/include/asm/cache.h
5218@@ -13,11 +13,12 @@
5219 #ifndef _ASM_MICROBLAZE_CACHE_H
5220 #define _ASM_MICROBLAZE_CACHE_H
5221
5222+#include <linux/const.h>
5223 #include <asm/registers.h>
5224
5225 #define L1_CACHE_SHIFT 5
5226 /* word-granular cache in microblaze */
5227-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5228+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5229
5230 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5231
5232diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5233index 08b6079..eb272cf 100644
5234--- a/arch/mips/include/asm/atomic.h
5235+++ b/arch/mips/include/asm/atomic.h
5236@@ -21,6 +21,10 @@
5237 #include <asm/cmpxchg.h>
5238 #include <asm/war.h>
5239
5240+#ifdef CONFIG_GENERIC_ATOMIC64
5241+#include <asm-generic/atomic64.h>
5242+#endif
5243+
5244 #define ATOMIC_INIT(i) { (i) }
5245
5246 /*
5247@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5248 */
5249 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5250
5251+#define atomic64_read_unchecked(v) atomic64_read(v)
5252+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5253+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5254+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5255+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5256+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5257+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5258+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5259+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5260+
5261 #endif /* CONFIG_64BIT */
5262
5263 /*
5264diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5265index b4db69f..8f3b093 100644
5266--- a/arch/mips/include/asm/cache.h
5267+++ b/arch/mips/include/asm/cache.h
5268@@ -9,10 +9,11 @@
5269 #ifndef _ASM_CACHE_H
5270 #define _ASM_CACHE_H
5271
5272+#include <linux/const.h>
5273 #include <kmalloc.h>
5274
5275 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5276-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5277+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5278
5279 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5280 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5281diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5282index cf3ae24..238d22f 100644
5283--- a/arch/mips/include/asm/elf.h
5284+++ b/arch/mips/include/asm/elf.h
5285@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5286 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5287 #endif
5288
5289+#ifdef CONFIG_PAX_ASLR
5290+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5291+
5292+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5293+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5294+#endif
5295+
5296 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5297 struct linux_binprm;
5298 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5299 int uses_interp);
5300
5301-struct mm_struct;
5302-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5303-#define arch_randomize_brk arch_randomize_brk
5304-
5305 #endif /* _ASM_ELF_H */
5306diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5307index c1f6afa..38cc6e9 100644
5308--- a/arch/mips/include/asm/exec.h
5309+++ b/arch/mips/include/asm/exec.h
5310@@ -12,6 +12,6 @@
5311 #ifndef _ASM_EXEC_H
5312 #define _ASM_EXEC_H
5313
5314-extern unsigned long arch_align_stack(unsigned long sp);
5315+#define arch_align_stack(x) ((x) & ~0xfUL)
5316
5317 #endif /* _ASM_EXEC_H */
5318diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5319index f59552f..3abe9b9 100644
5320--- a/arch/mips/include/asm/page.h
5321+++ b/arch/mips/include/asm/page.h
5322@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5323 #ifdef CONFIG_CPU_MIPS32
5324 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5325 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5326- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5327+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5328 #else
5329 typedef struct { unsigned long long pte; } pte_t;
5330 #define pte_val(x) ((x).pte)
5331diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5332index 881d18b..cea38bc 100644
5333--- a/arch/mips/include/asm/pgalloc.h
5334+++ b/arch/mips/include/asm/pgalloc.h
5335@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5336 {
5337 set_pud(pud, __pud((unsigned long)pmd));
5338 }
5339+
5340+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5341+{
5342+ pud_populate(mm, pud, pmd);
5343+}
5344 #endif
5345
5346 /*
5347diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5348index 895320e..bf63e10 100644
5349--- a/arch/mips/include/asm/thread_info.h
5350+++ b/arch/mips/include/asm/thread_info.h
5351@@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
5352 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5353 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5354 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5355+/* li takes a 32bit immediate */
5356+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5357 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5358
5359 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5360@@ -130,15 +132,18 @@ static inline struct thread_info *current_thread_info(void)
5361 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5362 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5363 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5364+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5365+
5366+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5367
5368 /* work to do in syscall_trace_leave() */
5369-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5370+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5371
5372 /* work to do on interrupt/exception return */
5373 #define _TIF_WORK_MASK \
5374 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5375 /* work to do on any return to u-space */
5376-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5377+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5378
5379 #endif /* __KERNEL__ */
5380
5381diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5382index 1188e00..41cf144 100644
5383--- a/arch/mips/kernel/binfmt_elfn32.c
5384+++ b/arch/mips/kernel/binfmt_elfn32.c
5385@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5386 #undef ELF_ET_DYN_BASE
5387 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5388
5389+#ifdef CONFIG_PAX_ASLR
5390+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5391+
5392+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5393+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5394+#endif
5395+
5396 #include <asm/processor.h>
5397 #include <linux/module.h>
5398 #include <linux/elfcore.h>
5399diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5400index 202e581..689ca79 100644
5401--- a/arch/mips/kernel/binfmt_elfo32.c
5402+++ b/arch/mips/kernel/binfmt_elfo32.c
5403@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5404 #undef ELF_ET_DYN_BASE
5405 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5406
5407+#ifdef CONFIG_PAX_ASLR
5408+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5409+
5410+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5411+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5412+#endif
5413+
5414 #include <asm/processor.h>
5415
5416 /*
5417diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5418index c6a041d..b3e7318 100644
5419--- a/arch/mips/kernel/process.c
5420+++ b/arch/mips/kernel/process.c
5421@@ -563,15 +563,3 @@ unsigned long get_wchan(struct task_struct *task)
5422 out:
5423 return pc;
5424 }
5425-
5426-/*
5427- * Don't forget that the stack pointer must be aligned on a 8 bytes
5428- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5429- */
5430-unsigned long arch_align_stack(unsigned long sp)
5431-{
5432- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5433- sp -= get_random_int() & ~PAGE_MASK;
5434-
5435- return sp & ALMASK;
5436-}
5437diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5438index 9c6299c..2fb4c22 100644
5439--- a/arch/mips/kernel/ptrace.c
5440+++ b/arch/mips/kernel/ptrace.c
5441@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5442 return arch;
5443 }
5444
5445+#ifdef CONFIG_GRKERNSEC_SETXID
5446+extern void gr_delayed_cred_worker(void);
5447+#endif
5448+
5449 /*
5450 * Notification of system call entry/exit
5451 * - triggered by current->work.syscall_trace
5452@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5453 /* do the secure computing check first */
5454 secure_computing_strict(regs->regs[2]);
5455
5456+#ifdef CONFIG_GRKERNSEC_SETXID
5457+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5458+ gr_delayed_cred_worker();
5459+#endif
5460+
5461 if (!(current->ptrace & PT_PTRACED))
5462 goto out;
5463
5464diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5465index 9b36424..e7f4154 100644
5466--- a/arch/mips/kernel/scall32-o32.S
5467+++ b/arch/mips/kernel/scall32-o32.S
5468@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5469
5470 stack_done:
5471 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5472- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5473+ li t1, _TIF_SYSCALL_WORK
5474 and t0, t1
5475 bnez t0, syscall_trace_entry # -> yes
5476
5477diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5478index 97a5909..59622f8 100644
5479--- a/arch/mips/kernel/scall64-64.S
5480+++ b/arch/mips/kernel/scall64-64.S
5481@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5482
5483 sd a3, PT_R26(sp) # save a3 for syscall restarting
5484
5485- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5486+ li t1, _TIF_SYSCALL_WORK
5487 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5488 and t0, t1, t0
5489 bnez t0, syscall_trace_entry
5490diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5491index edcb659..fb2ab09 100644
5492--- a/arch/mips/kernel/scall64-n32.S
5493+++ b/arch/mips/kernel/scall64-n32.S
5494@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5495
5496 sd a3, PT_R26(sp) # save a3 for syscall restarting
5497
5498- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5499+ li t1, _TIF_SYSCALL_WORK
5500 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5501 and t0, t1, t0
5502 bnez t0, n32_syscall_trace_entry
5503diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5504index 74f485d..47d2c38 100644
5505--- a/arch/mips/kernel/scall64-o32.S
5506+++ b/arch/mips/kernel/scall64-o32.S
5507@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5508 PTR 4b, bad_stack
5509 .previous
5510
5511- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5512+ li t1, _TIF_SYSCALL_WORK
5513 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5514 and t0, t1, t0
5515 bnez t0, trace_a_syscall
5516diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5517index 0fead53..a2c0fb5 100644
5518--- a/arch/mips/mm/fault.c
5519+++ b/arch/mips/mm/fault.c
5520@@ -27,6 +27,23 @@
5521 #include <asm/highmem.h> /* For VMALLOC_END */
5522 #include <linux/kdebug.h>
5523
5524+#ifdef CONFIG_PAX_PAGEEXEC
5525+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5526+{
5527+ unsigned long i;
5528+
5529+ printk(KERN_ERR "PAX: bytes at PC: ");
5530+ for (i = 0; i < 5; i++) {
5531+ unsigned int c;
5532+ if (get_user(c, (unsigned int *)pc+i))
5533+ printk(KERN_CONT "???????? ");
5534+ else
5535+ printk(KERN_CONT "%08x ", c);
5536+ }
5537+ printk("\n");
5538+}
5539+#endif
5540+
5541 /*
5542 * This routine handles page faults. It determines the address,
5543 * and the problem, and then passes it off to one of the appropriate
5544diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5545index 7e5fe27..9656513 100644
5546--- a/arch/mips/mm/mmap.c
5547+++ b/arch/mips/mm/mmap.c
5548@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5549 struct vm_area_struct *vma;
5550 unsigned long addr = addr0;
5551 int do_color_align;
5552+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5553 struct vm_unmapped_area_info info;
5554
5555 if (unlikely(len > TASK_SIZE))
5556@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5557 do_color_align = 1;
5558
5559 /* requesting a specific address */
5560+
5561+#ifdef CONFIG_PAX_RANDMMAP
5562+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5563+#endif
5564+
5565 if (addr) {
5566 if (do_color_align)
5567 addr = COLOUR_ALIGN(addr, pgoff);
5568@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5569 addr = PAGE_ALIGN(addr);
5570
5571 vma = find_vma(mm, addr);
5572- if (TASK_SIZE - len >= addr &&
5573- (!vma || addr + len <= vma->vm_start))
5574+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5575 return addr;
5576 }
5577
5578 info.length = len;
5579 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
5580 info.align_offset = pgoff << PAGE_SHIFT;
5581+ info.threadstack_offset = offset;
5582
5583 if (dir == DOWN) {
5584 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
5585@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5586 {
5587 unsigned long random_factor = 0UL;
5588
5589+#ifdef CONFIG_PAX_RANDMMAP
5590+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5591+#endif
5592+
5593 if (current->flags & PF_RANDOMIZE) {
5594 random_factor = get_random_int();
5595 random_factor = random_factor << PAGE_SHIFT;
5596@@ -157,42 +167,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5597
5598 if (mmap_is_legacy()) {
5599 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5600+
5601+#ifdef CONFIG_PAX_RANDMMAP
5602+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5603+ mm->mmap_base += mm->delta_mmap;
5604+#endif
5605+
5606 mm->get_unmapped_area = arch_get_unmapped_area;
5607 mm->unmap_area = arch_unmap_area;
5608 } else {
5609 mm->mmap_base = mmap_base(random_factor);
5610+
5611+#ifdef CONFIG_PAX_RANDMMAP
5612+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5613+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5614+#endif
5615+
5616 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5617 mm->unmap_area = arch_unmap_area_topdown;
5618 }
5619 }
5620
5621-static inline unsigned long brk_rnd(void)
5622-{
5623- unsigned long rnd = get_random_int();
5624-
5625- rnd = rnd << PAGE_SHIFT;
5626- /* 8MB for 32bit, 256MB for 64bit */
5627- if (TASK_IS_32BIT_ADDR)
5628- rnd = rnd & 0x7ffffful;
5629- else
5630- rnd = rnd & 0xffffffful;
5631-
5632- return rnd;
5633-}
5634-
5635-unsigned long arch_randomize_brk(struct mm_struct *mm)
5636-{
5637- unsigned long base = mm->brk;
5638- unsigned long ret;
5639-
5640- ret = PAGE_ALIGN(base + brk_rnd());
5641-
5642- if (ret < mm->brk)
5643- return mm->brk;
5644-
5645- return ret;
5646-}
5647-
5648 int __virt_addr_valid(const volatile void *kaddr)
5649 {
5650 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5651diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5652index 967d144..db12197 100644
5653--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5654+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5655@@ -11,12 +11,14 @@
5656 #ifndef _ASM_PROC_CACHE_H
5657 #define _ASM_PROC_CACHE_H
5658
5659+#include <linux/const.h>
5660+
5661 /* L1 cache */
5662
5663 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5664 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5665-#define L1_CACHE_BYTES 16 /* bytes per entry */
5666 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5667+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5668 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5669
5670 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5671diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5672index bcb5df2..84fabd2 100644
5673--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5674+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5675@@ -16,13 +16,15 @@
5676 #ifndef _ASM_PROC_CACHE_H
5677 #define _ASM_PROC_CACHE_H
5678
5679+#include <linux/const.h>
5680+
5681 /*
5682 * L1 cache
5683 */
5684 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5685 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5686-#define L1_CACHE_BYTES 32 /* bytes per entry */
5687 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5688+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5689 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5690
5691 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5692diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5693index 4ce7a01..449202a 100644
5694--- a/arch/openrisc/include/asm/cache.h
5695+++ b/arch/openrisc/include/asm/cache.h
5696@@ -19,11 +19,13 @@
5697 #ifndef __ASM_OPENRISC_CACHE_H
5698 #define __ASM_OPENRISC_CACHE_H
5699
5700+#include <linux/const.h>
5701+
5702 /* FIXME: How can we replace these with values from the CPU...
5703 * they shouldn't be hard-coded!
5704 */
5705
5706-#define L1_CACHE_BYTES 16
5707 #define L1_CACHE_SHIFT 4
5708+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5709
5710 #endif /* __ASM_OPENRISC_CACHE_H */
5711diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5712index 472886c..00e7df9 100644
5713--- a/arch/parisc/include/asm/atomic.h
5714+++ b/arch/parisc/include/asm/atomic.h
5715@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
5716 return dec;
5717 }
5718
5719+#define atomic64_read_unchecked(v) atomic64_read(v)
5720+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5721+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5722+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5723+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5724+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5725+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5726+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5727+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5728+
5729 #endif /* !CONFIG_64BIT */
5730
5731
5732diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5733index 47f11c7..3420df2 100644
5734--- a/arch/parisc/include/asm/cache.h
5735+++ b/arch/parisc/include/asm/cache.h
5736@@ -5,6 +5,7 @@
5737 #ifndef __ARCH_PARISC_CACHE_H
5738 #define __ARCH_PARISC_CACHE_H
5739
5740+#include <linux/const.h>
5741
5742 /*
5743 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5744@@ -15,13 +16,13 @@
5745 * just ruin performance.
5746 */
5747 #ifdef CONFIG_PA20
5748-#define L1_CACHE_BYTES 64
5749 #define L1_CACHE_SHIFT 6
5750 #else
5751-#define L1_CACHE_BYTES 32
5752 #define L1_CACHE_SHIFT 5
5753 #endif
5754
5755+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5756+
5757 #ifndef __ASSEMBLY__
5758
5759 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5760diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5761index ad2b503..bdf1651 100644
5762--- a/arch/parisc/include/asm/elf.h
5763+++ b/arch/parisc/include/asm/elf.h
5764@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5765
5766 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5767
5768+#ifdef CONFIG_PAX_ASLR
5769+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5770+
5771+#define PAX_DELTA_MMAP_LEN 16
5772+#define PAX_DELTA_STACK_LEN 16
5773+#endif
5774+
5775 /* This yields a mask that user programs can use to figure out what
5776 instruction set this CPU supports. This could be done in user space,
5777 but it's not easy, and we've already done it here. */
5778diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5779index fc987a1..6e068ef 100644
5780--- a/arch/parisc/include/asm/pgalloc.h
5781+++ b/arch/parisc/include/asm/pgalloc.h
5782@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5783 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5784 }
5785
5786+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5787+{
5788+ pgd_populate(mm, pgd, pmd);
5789+}
5790+
5791 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5792 {
5793 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5794@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5795 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5796 #define pmd_free(mm, x) do { } while (0)
5797 #define pgd_populate(mm, pmd, pte) BUG()
5798+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5799
5800 #endif
5801
5802diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5803index 1e40d7f..a3eb445 100644
5804--- a/arch/parisc/include/asm/pgtable.h
5805+++ b/arch/parisc/include/asm/pgtable.h
5806@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5807 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5808 #define PAGE_COPY PAGE_EXECREAD
5809 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5810+
5811+#ifdef CONFIG_PAX_PAGEEXEC
5812+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5813+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5814+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5815+#else
5816+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5817+# define PAGE_COPY_NOEXEC PAGE_COPY
5818+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5819+#endif
5820+
5821 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5822 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5823 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5824diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5825index e0a8235..ce2f1e1 100644
5826--- a/arch/parisc/include/asm/uaccess.h
5827+++ b/arch/parisc/include/asm/uaccess.h
5828@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5829 const void __user *from,
5830 unsigned long n)
5831 {
5832- int sz = __compiletime_object_size(to);
5833+ size_t sz = __compiletime_object_size(to);
5834 int ret = -EFAULT;
5835
5836- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5837+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5838 ret = __copy_from_user(to, from, n);
5839 else
5840 copy_from_user_overflow();
5841diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5842index 2a625fb..9908930 100644
5843--- a/arch/parisc/kernel/module.c
5844+++ b/arch/parisc/kernel/module.c
5845@@ -98,16 +98,38 @@
5846
5847 /* three functions to determine where in the module core
5848 * or init pieces the location is */
5849+static inline int in_init_rx(struct module *me, void *loc)
5850+{
5851+ return (loc >= me->module_init_rx &&
5852+ loc < (me->module_init_rx + me->init_size_rx));
5853+}
5854+
5855+static inline int in_init_rw(struct module *me, void *loc)
5856+{
5857+ return (loc >= me->module_init_rw &&
5858+ loc < (me->module_init_rw + me->init_size_rw));
5859+}
5860+
5861 static inline int in_init(struct module *me, void *loc)
5862 {
5863- return (loc >= me->module_init &&
5864- loc <= (me->module_init + me->init_size));
5865+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5866+}
5867+
5868+static inline int in_core_rx(struct module *me, void *loc)
5869+{
5870+ return (loc >= me->module_core_rx &&
5871+ loc < (me->module_core_rx + me->core_size_rx));
5872+}
5873+
5874+static inline int in_core_rw(struct module *me, void *loc)
5875+{
5876+ return (loc >= me->module_core_rw &&
5877+ loc < (me->module_core_rw + me->core_size_rw));
5878 }
5879
5880 static inline int in_core(struct module *me, void *loc)
5881 {
5882- return (loc >= me->module_core &&
5883- loc <= (me->module_core + me->core_size));
5884+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5885 }
5886
5887 static inline int in_local(struct module *me, void *loc)
5888@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5889 }
5890
5891 /* align things a bit */
5892- me->core_size = ALIGN(me->core_size, 16);
5893- me->arch.got_offset = me->core_size;
5894- me->core_size += gots * sizeof(struct got_entry);
5895+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5896+ me->arch.got_offset = me->core_size_rw;
5897+ me->core_size_rw += gots * sizeof(struct got_entry);
5898
5899- me->core_size = ALIGN(me->core_size, 16);
5900- me->arch.fdesc_offset = me->core_size;
5901- me->core_size += fdescs * sizeof(Elf_Fdesc);
5902+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5903+ me->arch.fdesc_offset = me->core_size_rw;
5904+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5905
5906 me->arch.got_max = gots;
5907 me->arch.fdesc_max = fdescs;
5908@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5909
5910 BUG_ON(value == 0);
5911
5912- got = me->module_core + me->arch.got_offset;
5913+ got = me->module_core_rw + me->arch.got_offset;
5914 for (i = 0; got[i].addr; i++)
5915 if (got[i].addr == value)
5916 goto out;
5917@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5918 #ifdef CONFIG_64BIT
5919 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5920 {
5921- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5922+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5923
5924 if (!value) {
5925 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5926@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5927
5928 /* Create new one */
5929 fdesc->addr = value;
5930- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5931+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5932 return (Elf_Addr)fdesc;
5933 }
5934 #endif /* CONFIG_64BIT */
5935@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5936
5937 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5938 end = table + sechdrs[me->arch.unwind_section].sh_size;
5939- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5940+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5941
5942 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5943 me->arch.unwind_section, table, end, gp);
5944diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5945index 5dfd248..64914ac 100644
5946--- a/arch/parisc/kernel/sys_parisc.c
5947+++ b/arch/parisc/kernel/sys_parisc.c
5948@@ -33,9 +33,11 @@
5949 #include <linux/utsname.h>
5950 #include <linux/personality.h>
5951
5952-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5953+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5954+ unsigned long flags)
5955 {
5956 struct vm_unmapped_area_info info;
5957+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5958
5959 info.flags = 0;
5960 info.length = len;
5961@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5962 info.high_limit = TASK_SIZE;
5963 info.align_mask = 0;
5964 info.align_offset = 0;
5965+ info.threadstack_offset = offset;
5966 return vm_unmapped_area(&info);
5967 }
5968
5969@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
5970 return (unsigned long) mapping >> 8;
5971 }
5972
5973-static unsigned long get_shared_area(struct address_space *mapping,
5974- unsigned long addr, unsigned long len, unsigned long pgoff)
5975+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5976+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5977 {
5978 struct vm_unmapped_area_info info;
5979+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5980
5981 info.flags = 0;
5982 info.length = len;
5983@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5984 info.high_limit = TASK_SIZE;
5985 info.align_mask = PAGE_MASK & (SHMLBA - 1);
5986 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
5987+ info.threadstack_offset = offset;
5988 return vm_unmapped_area(&info);
5989 }
5990
5991@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5992 return -EINVAL;
5993 return addr;
5994 }
5995- if (!addr)
5996+ if (!addr) {
5997 addr = TASK_UNMAPPED_BASE;
5998
5999+#ifdef CONFIG_PAX_RANDMMAP
6000+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
6001+ addr += current->mm->delta_mmap;
6002+#endif
6003+
6004+ }
6005+
6006 if (filp) {
6007- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
6008+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
6009 } else if(flags & MAP_SHARED) {
6010- addr = get_shared_area(NULL, addr, len, pgoff);
6011+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
6012 } else {
6013- addr = get_unshared_area(addr, len);
6014+ addr = get_unshared_area(filp, addr, len, flags);
6015 }
6016 return addr;
6017 }
6018diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
6019index 04e47c6..7a8faf6 100644
6020--- a/arch/parisc/kernel/traps.c
6021+++ b/arch/parisc/kernel/traps.c
6022@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
6023
6024 down_read(&current->mm->mmap_sem);
6025 vma = find_vma(current->mm,regs->iaoq[0]);
6026- if (vma && (regs->iaoq[0] >= vma->vm_start)
6027- && (vma->vm_flags & VM_EXEC)) {
6028-
6029+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
6030 fault_address = regs->iaoq[0];
6031 fault_space = regs->iasq[0];
6032
6033diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
6034index f247a34..dc0f219 100644
6035--- a/arch/parisc/mm/fault.c
6036+++ b/arch/parisc/mm/fault.c
6037@@ -15,6 +15,7 @@
6038 #include <linux/sched.h>
6039 #include <linux/interrupt.h>
6040 #include <linux/module.h>
6041+#include <linux/unistd.h>
6042
6043 #include <asm/uaccess.h>
6044 #include <asm/traps.h>
6045@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
6046 static unsigned long
6047 parisc_acctyp(unsigned long code, unsigned int inst)
6048 {
6049- if (code == 6 || code == 16)
6050+ if (code == 6 || code == 7 || code == 16)
6051 return VM_EXEC;
6052
6053 switch (inst & 0xf0000000) {
6054@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
6055 }
6056 #endif
6057
6058+#ifdef CONFIG_PAX_PAGEEXEC
6059+/*
6060+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
6061+ *
6062+ * returns 1 when task should be killed
6063+ * 2 when rt_sigreturn trampoline was detected
6064+ * 3 when unpatched PLT trampoline was detected
6065+ */
6066+static int pax_handle_fetch_fault(struct pt_regs *regs)
6067+{
6068+
6069+#ifdef CONFIG_PAX_EMUPLT
6070+ int err;
6071+
6072+ do { /* PaX: unpatched PLT emulation */
6073+ unsigned int bl, depwi;
6074+
6075+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6076+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6077+
6078+ if (err)
6079+ break;
6080+
6081+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6082+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6083+
6084+ err = get_user(ldw, (unsigned int *)addr);
6085+ err |= get_user(bv, (unsigned int *)(addr+4));
6086+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6087+
6088+ if (err)
6089+ break;
6090+
6091+ if (ldw == 0x0E801096U &&
6092+ bv == 0xEAC0C000U &&
6093+ ldw2 == 0x0E881095U)
6094+ {
6095+ unsigned int resolver, map;
6096+
6097+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6098+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6099+ if (err)
6100+ break;
6101+
6102+ regs->gr[20] = instruction_pointer(regs)+8;
6103+ regs->gr[21] = map;
6104+ regs->gr[22] = resolver;
6105+ regs->iaoq[0] = resolver | 3UL;
6106+ regs->iaoq[1] = regs->iaoq[0] + 4;
6107+ return 3;
6108+ }
6109+ }
6110+ } while (0);
6111+#endif
6112+
6113+#ifdef CONFIG_PAX_EMUTRAMP
6114+
6115+#ifndef CONFIG_PAX_EMUSIGRT
6116+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6117+ return 1;
6118+#endif
6119+
6120+ do { /* PaX: rt_sigreturn emulation */
6121+ unsigned int ldi1, ldi2, bel, nop;
6122+
6123+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6124+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6125+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6126+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6127+
6128+ if (err)
6129+ break;
6130+
6131+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6132+ ldi2 == 0x3414015AU &&
6133+ bel == 0xE4008200U &&
6134+ nop == 0x08000240U)
6135+ {
6136+ regs->gr[25] = (ldi1 & 2) >> 1;
6137+ regs->gr[20] = __NR_rt_sigreturn;
6138+ regs->gr[31] = regs->iaoq[1] + 16;
6139+ regs->sr[0] = regs->iasq[1];
6140+ regs->iaoq[0] = 0x100UL;
6141+ regs->iaoq[1] = regs->iaoq[0] + 4;
6142+ regs->iasq[0] = regs->sr[2];
6143+ regs->iasq[1] = regs->sr[2];
6144+ return 2;
6145+ }
6146+ } while (0);
6147+#endif
6148+
6149+ return 1;
6150+}
6151+
6152+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6153+{
6154+ unsigned long i;
6155+
6156+ printk(KERN_ERR "PAX: bytes at PC: ");
6157+ for (i = 0; i < 5; i++) {
6158+ unsigned int c;
6159+ if (get_user(c, (unsigned int *)pc+i))
6160+ printk(KERN_CONT "???????? ");
6161+ else
6162+ printk(KERN_CONT "%08x ", c);
6163+ }
6164+ printk("\n");
6165+}
6166+#endif
6167+
6168 int fixup_exception(struct pt_regs *regs)
6169 {
6170 const struct exception_table_entry *fix;
6171@@ -194,8 +305,33 @@ good_area:
6172
6173 acc_type = parisc_acctyp(code,regs->iir);
6174
6175- if ((vma->vm_flags & acc_type) != acc_type)
6176+ if ((vma->vm_flags & acc_type) != acc_type) {
6177+
6178+#ifdef CONFIG_PAX_PAGEEXEC
6179+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6180+ (address & ~3UL) == instruction_pointer(regs))
6181+ {
6182+ up_read(&mm->mmap_sem);
6183+ switch (pax_handle_fetch_fault(regs)) {
6184+
6185+#ifdef CONFIG_PAX_EMUPLT
6186+ case 3:
6187+ return;
6188+#endif
6189+
6190+#ifdef CONFIG_PAX_EMUTRAMP
6191+ case 2:
6192+ return;
6193+#endif
6194+
6195+ }
6196+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6197+ do_group_exit(SIGKILL);
6198+ }
6199+#endif
6200+
6201 goto bad_area;
6202+ }
6203
6204 /*
6205 * If for any reason at all we couldn't handle the fault, make
6206diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6207index e3b1d41..8e81edf 100644
6208--- a/arch/powerpc/include/asm/atomic.h
6209+++ b/arch/powerpc/include/asm/atomic.h
6210@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6211 return t1;
6212 }
6213
6214+#define atomic64_read_unchecked(v) atomic64_read(v)
6215+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6216+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6217+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6218+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6219+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6220+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6221+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6222+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6223+
6224 #endif /* __powerpc64__ */
6225
6226 #endif /* __KERNEL__ */
6227diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6228index 9e495c9..b6878e5 100644
6229--- a/arch/powerpc/include/asm/cache.h
6230+++ b/arch/powerpc/include/asm/cache.h
6231@@ -3,6 +3,7 @@
6232
6233 #ifdef __KERNEL__
6234
6235+#include <linux/const.h>
6236
6237 /* bytes per L1 cache line */
6238 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6239@@ -22,7 +23,7 @@
6240 #define L1_CACHE_SHIFT 7
6241 #endif
6242
6243-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6244+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6245
6246 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6247
6248diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6249index cc0655a..13eac2e 100644
6250--- a/arch/powerpc/include/asm/elf.h
6251+++ b/arch/powerpc/include/asm/elf.h
6252@@ -28,8 +28,19 @@
6253 the loader. We need to make sure that it is out of the way of the program
6254 that it will "exec", and that there is sufficient room for the brk. */
6255
6256-extern unsigned long randomize_et_dyn(unsigned long base);
6257-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6258+#define ELF_ET_DYN_BASE (0x20000000)
6259+
6260+#ifdef CONFIG_PAX_ASLR
6261+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6262+
6263+#ifdef __powerpc64__
6264+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6265+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6266+#else
6267+#define PAX_DELTA_MMAP_LEN 15
6268+#define PAX_DELTA_STACK_LEN 15
6269+#endif
6270+#endif
6271
6272 /*
6273 * Our registers are always unsigned longs, whether we're a 32 bit
6274@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6275 (0x7ff >> (PAGE_SHIFT - 12)) : \
6276 (0x3ffff >> (PAGE_SHIFT - 12)))
6277
6278-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6279-#define arch_randomize_brk arch_randomize_brk
6280-
6281-
6282 #ifdef CONFIG_SPU_BASE
6283 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6284 #define NT_SPU 1
6285diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6286index 8196e9c..d83a9f3 100644
6287--- a/arch/powerpc/include/asm/exec.h
6288+++ b/arch/powerpc/include/asm/exec.h
6289@@ -4,6 +4,6 @@
6290 #ifndef _ASM_POWERPC_EXEC_H
6291 #define _ASM_POWERPC_EXEC_H
6292
6293-extern unsigned long arch_align_stack(unsigned long sp);
6294+#define arch_align_stack(x) ((x) & ~0xfUL)
6295
6296 #endif /* _ASM_POWERPC_EXEC_H */
6297diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6298index 5acabbd..7ea14fa 100644
6299--- a/arch/powerpc/include/asm/kmap_types.h
6300+++ b/arch/powerpc/include/asm/kmap_types.h
6301@@ -10,7 +10,7 @@
6302 * 2 of the License, or (at your option) any later version.
6303 */
6304
6305-#define KM_TYPE_NR 16
6306+#define KM_TYPE_NR 17
6307
6308 #endif /* __KERNEL__ */
6309 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6310diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6311index 8565c25..2865190 100644
6312--- a/arch/powerpc/include/asm/mman.h
6313+++ b/arch/powerpc/include/asm/mman.h
6314@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6315 }
6316 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6317
6318-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6319+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6320 {
6321 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6322 }
6323diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6324index 988c812..63c7d70 100644
6325--- a/arch/powerpc/include/asm/page.h
6326+++ b/arch/powerpc/include/asm/page.h
6327@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6328 * and needs to be executable. This means the whole heap ends
6329 * up being executable.
6330 */
6331-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6332- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6333+#define VM_DATA_DEFAULT_FLAGS32 \
6334+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6335+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6336
6337 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6338 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6339@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6340 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6341 #endif
6342
6343+#define ktla_ktva(addr) (addr)
6344+#define ktva_ktla(addr) (addr)
6345+
6346 #ifndef CONFIG_PPC_BOOK3S_64
6347 /*
6348 * Use the top bit of the higher-level page table entries to indicate whether
6349diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6350index 88693ce..ac6f9ab 100644
6351--- a/arch/powerpc/include/asm/page_64.h
6352+++ b/arch/powerpc/include/asm/page_64.h
6353@@ -153,15 +153,18 @@ do { \
6354 * stack by default, so in the absence of a PT_GNU_STACK program header
6355 * we turn execute permission off.
6356 */
6357-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6358- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6359+#define VM_STACK_DEFAULT_FLAGS32 \
6360+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6361+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6362
6363 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6364 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6365
6366+#ifndef CONFIG_PAX_PAGEEXEC
6367 #define VM_STACK_DEFAULT_FLAGS \
6368 (is_32bit_task() ? \
6369 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6370+#endif
6371
6372 #include <asm-generic/getorder.h>
6373
6374diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6375index b66ae72..4a378cd 100644
6376--- a/arch/powerpc/include/asm/pgalloc-64.h
6377+++ b/arch/powerpc/include/asm/pgalloc-64.h
6378@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6379 #ifndef CONFIG_PPC_64K_PAGES
6380
6381 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6382+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6383
6384 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6385 {
6386@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6387 pud_set(pud, (unsigned long)pmd);
6388 }
6389
6390+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6391+{
6392+ pud_populate(mm, pud, pmd);
6393+}
6394+
6395 #define pmd_populate(mm, pmd, pte_page) \
6396 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6397 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6398@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
6399 #endif
6400
6401 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6402+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6403
6404 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6405 pte_t *pte)
6406diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6407index 7aeb955..19f748e 100644
6408--- a/arch/powerpc/include/asm/pgtable.h
6409+++ b/arch/powerpc/include/asm/pgtable.h
6410@@ -2,6 +2,7 @@
6411 #define _ASM_POWERPC_PGTABLE_H
6412 #ifdef __KERNEL__
6413
6414+#include <linux/const.h>
6415 #ifndef __ASSEMBLY__
6416 #include <asm/processor.h> /* For TASK_SIZE */
6417 #include <asm/mmu.h>
6418diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6419index 4aad413..85d86bf 100644
6420--- a/arch/powerpc/include/asm/pte-hash32.h
6421+++ b/arch/powerpc/include/asm/pte-hash32.h
6422@@ -21,6 +21,7 @@
6423 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6424 #define _PAGE_USER 0x004 /* usermode access allowed */
6425 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6426+#define _PAGE_EXEC _PAGE_GUARDED
6427 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6428 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6429 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6430diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6431index 4a9e408..724aa59 100644
6432--- a/arch/powerpc/include/asm/reg.h
6433+++ b/arch/powerpc/include/asm/reg.h
6434@@ -234,6 +234,7 @@
6435 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6436 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6437 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6438+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6439 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6440 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6441 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6442diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
6443index ffbaabe..eabe843 100644
6444--- a/arch/powerpc/include/asm/smp.h
6445+++ b/arch/powerpc/include/asm/smp.h
6446@@ -50,7 +50,7 @@ struct smp_ops_t {
6447 int (*cpu_disable)(void);
6448 void (*cpu_die)(unsigned int nr);
6449 int (*cpu_bootable)(unsigned int nr);
6450-};
6451+} __no_const;
6452
6453 extern void smp_send_debugger_break(void);
6454 extern void start_secondary_resume(void);
6455diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6456index ba7b197..d292e26 100644
6457--- a/arch/powerpc/include/asm/thread_info.h
6458+++ b/arch/powerpc/include/asm/thread_info.h
6459@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
6460 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
6461 TIF_NEED_RESCHED */
6462 #define TIF_32BIT 4 /* 32 bit binary */
6463-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
6464 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6465 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6466 #define TIF_SINGLESTEP 8 /* singlestepping active */
6467@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
6468 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6469 for stack store? */
6470 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6471+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
6472+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6473+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
6474
6475 /* as above, but as bit values */
6476 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6477@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
6478 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6479 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6480 #define _TIF_NOHZ (1<<TIF_NOHZ)
6481+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6482 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6483 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6484- _TIF_NOHZ)
6485+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
6486
6487 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6488 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6489diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6490index 4db4959..aba5c41 100644
6491--- a/arch/powerpc/include/asm/uaccess.h
6492+++ b/arch/powerpc/include/asm/uaccess.h
6493@@ -318,52 +318,6 @@ do { \
6494 extern unsigned long __copy_tofrom_user(void __user *to,
6495 const void __user *from, unsigned long size);
6496
6497-#ifndef __powerpc64__
6498-
6499-static inline unsigned long copy_from_user(void *to,
6500- const void __user *from, unsigned long n)
6501-{
6502- unsigned long over;
6503-
6504- if (access_ok(VERIFY_READ, from, n))
6505- return __copy_tofrom_user((__force void __user *)to, from, n);
6506- if ((unsigned long)from < TASK_SIZE) {
6507- over = (unsigned long)from + n - TASK_SIZE;
6508- return __copy_tofrom_user((__force void __user *)to, from,
6509- n - over) + over;
6510- }
6511- return n;
6512-}
6513-
6514-static inline unsigned long copy_to_user(void __user *to,
6515- const void *from, unsigned long n)
6516-{
6517- unsigned long over;
6518-
6519- if (access_ok(VERIFY_WRITE, to, n))
6520- return __copy_tofrom_user(to, (__force void __user *)from, n);
6521- if ((unsigned long)to < TASK_SIZE) {
6522- over = (unsigned long)to + n - TASK_SIZE;
6523- return __copy_tofrom_user(to, (__force void __user *)from,
6524- n - over) + over;
6525- }
6526- return n;
6527-}
6528-
6529-#else /* __powerpc64__ */
6530-
6531-#define __copy_in_user(to, from, size) \
6532- __copy_tofrom_user((to), (from), (size))
6533-
6534-extern unsigned long copy_from_user(void *to, const void __user *from,
6535- unsigned long n);
6536-extern unsigned long copy_to_user(void __user *to, const void *from,
6537- unsigned long n);
6538-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6539- unsigned long n);
6540-
6541-#endif /* __powerpc64__ */
6542-
6543 static inline unsigned long __copy_from_user_inatomic(void *to,
6544 const void __user *from, unsigned long n)
6545 {
6546@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6547 if (ret == 0)
6548 return 0;
6549 }
6550+
6551+ if (!__builtin_constant_p(n))
6552+ check_object_size(to, n, false);
6553+
6554 return __copy_tofrom_user((__force void __user *)to, from, n);
6555 }
6556
6557@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6558 if (ret == 0)
6559 return 0;
6560 }
6561+
6562+ if (!__builtin_constant_p(n))
6563+ check_object_size(from, n, true);
6564+
6565 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6566 }
6567
6568@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6569 return __copy_to_user_inatomic(to, from, size);
6570 }
6571
6572+#ifndef __powerpc64__
6573+
6574+static inline unsigned long __must_check copy_from_user(void *to,
6575+ const void __user *from, unsigned long n)
6576+{
6577+ unsigned long over;
6578+
6579+ if ((long)n < 0)
6580+ return n;
6581+
6582+ if (access_ok(VERIFY_READ, from, n)) {
6583+ if (!__builtin_constant_p(n))
6584+ check_object_size(to, n, false);
6585+ return __copy_tofrom_user((__force void __user *)to, from, n);
6586+ }
6587+ if ((unsigned long)from < TASK_SIZE) {
6588+ over = (unsigned long)from + n - TASK_SIZE;
6589+ if (!__builtin_constant_p(n - over))
6590+ check_object_size(to, n - over, false);
6591+ return __copy_tofrom_user((__force void __user *)to, from,
6592+ n - over) + over;
6593+ }
6594+ return n;
6595+}
6596+
6597+static inline unsigned long __must_check copy_to_user(void __user *to,
6598+ const void *from, unsigned long n)
6599+{
6600+ unsigned long over;
6601+
6602+ if ((long)n < 0)
6603+ return n;
6604+
6605+ if (access_ok(VERIFY_WRITE, to, n)) {
6606+ if (!__builtin_constant_p(n))
6607+ check_object_size(from, n, true);
6608+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6609+ }
6610+ if ((unsigned long)to < TASK_SIZE) {
6611+ over = (unsigned long)to + n - TASK_SIZE;
6612+ if (!__builtin_constant_p(n))
6613+ check_object_size(from, n - over, true);
6614+ return __copy_tofrom_user(to, (__force void __user *)from,
6615+ n - over) + over;
6616+ }
6617+ return n;
6618+}
6619+
6620+#else /* __powerpc64__ */
6621+
6622+#define __copy_in_user(to, from, size) \
6623+ __copy_tofrom_user((to), (from), (size))
6624+
6625+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6626+{
6627+ if ((long)n < 0 || n > INT_MAX)
6628+ return n;
6629+
6630+ if (!__builtin_constant_p(n))
6631+ check_object_size(to, n, false);
6632+
6633+ if (likely(access_ok(VERIFY_READ, from, n)))
6634+ n = __copy_from_user(to, from, n);
6635+ else
6636+ memset(to, 0, n);
6637+ return n;
6638+}
6639+
6640+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6641+{
6642+ if ((long)n < 0 || n > INT_MAX)
6643+ return n;
6644+
6645+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6646+ if (!__builtin_constant_p(n))
6647+ check_object_size(from, n, true);
6648+ n = __copy_to_user(to, from, n);
6649+ }
6650+ return n;
6651+}
6652+
6653+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6654+ unsigned long n);
6655+
6656+#endif /* __powerpc64__ */
6657+
6658 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6659
6660 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6661diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6662index 645170a..6cf0271 100644
6663--- a/arch/powerpc/kernel/exceptions-64e.S
6664+++ b/arch/powerpc/kernel/exceptions-64e.S
6665@@ -757,6 +757,7 @@ storage_fault_common:
6666 std r14,_DAR(r1)
6667 std r15,_DSISR(r1)
6668 addi r3,r1,STACK_FRAME_OVERHEAD
6669+ bl .save_nvgprs
6670 mr r4,r14
6671 mr r5,r15
6672 ld r14,PACA_EXGEN+EX_R14(r13)
6673@@ -765,8 +766,7 @@ storage_fault_common:
6674 cmpdi r3,0
6675 bne- 1f
6676 b .ret_from_except_lite
6677-1: bl .save_nvgprs
6678- mr r5,r3
6679+1: mr r5,r3
6680 addi r3,r1,STACK_FRAME_OVERHEAD
6681 ld r4,_DAR(r1)
6682 bl .bad_page_fault
6683diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6684index 40e4a17..5a84b37 100644
6685--- a/arch/powerpc/kernel/exceptions-64s.S
6686+++ b/arch/powerpc/kernel/exceptions-64s.S
6687@@ -1362,10 +1362,10 @@ handle_page_fault:
6688 11: ld r4,_DAR(r1)
6689 ld r5,_DSISR(r1)
6690 addi r3,r1,STACK_FRAME_OVERHEAD
6691+ bl .save_nvgprs
6692 bl .do_page_fault
6693 cmpdi r3,0
6694 beq+ 12f
6695- bl .save_nvgprs
6696 mr r5,r3
6697 addi r3,r1,STACK_FRAME_OVERHEAD
6698 lwz r4,_DAR(r1)
6699diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6700index 2e3200c..72095ce 100644
6701--- a/arch/powerpc/kernel/module_32.c
6702+++ b/arch/powerpc/kernel/module_32.c
6703@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6704 me->arch.core_plt_section = i;
6705 }
6706 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6707- printk("Module doesn't contain .plt or .init.plt sections.\n");
6708+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6709 return -ENOEXEC;
6710 }
6711
6712@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6713
6714 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6715 /* Init, or core PLT? */
6716- if (location >= mod->module_core
6717- && location < mod->module_core + mod->core_size)
6718+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6719+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6720 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6721- else
6722+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6723+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6724 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6725+ else {
6726+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6727+ return ~0UL;
6728+ }
6729
6730 /* Find this entry, or if that fails, the next avail. entry */
6731 while (entry->jump[0]) {
6732diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6733index 076d124..6cb2cbf 100644
6734--- a/arch/powerpc/kernel/process.c
6735+++ b/arch/powerpc/kernel/process.c
6736@@ -874,8 +874,8 @@ void show_regs(struct pt_regs * regs)
6737 * Lookup NIP late so we have the best change of getting the
6738 * above info out without failing
6739 */
6740- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6741- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6742+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6743+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6744 #endif
6745 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
6746 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
6747@@ -1335,10 +1335,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6748 newsp = stack[0];
6749 ip = stack[STACK_FRAME_LR_SAVE];
6750 if (!firstframe || ip != lr) {
6751- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6752+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6753 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6754 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6755- printk(" (%pS)",
6756+ printk(" (%pA)",
6757 (void *)current->ret_stack[curr_frame].ret);
6758 curr_frame--;
6759 }
6760@@ -1358,7 +1358,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6761 struct pt_regs *regs = (struct pt_regs *)
6762 (sp + STACK_FRAME_OVERHEAD);
6763 lr = regs->link;
6764- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6765+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6766 regs->trap, (void *)regs->nip, (void *)lr);
6767 firstframe = 1;
6768 }
6769@@ -1394,58 +1394,3 @@ void notrace __ppc64_runlatch_off(void)
6770 mtspr(SPRN_CTRLT, ctrl);
6771 }
6772 #endif /* CONFIG_PPC64 */
6773-
6774-unsigned long arch_align_stack(unsigned long sp)
6775-{
6776- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6777- sp -= get_random_int() & ~PAGE_MASK;
6778- return sp & ~0xf;
6779-}
6780-
6781-static inline unsigned long brk_rnd(void)
6782-{
6783- unsigned long rnd = 0;
6784-
6785- /* 8MB for 32bit, 1GB for 64bit */
6786- if (is_32bit_task())
6787- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6788- else
6789- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6790-
6791- return rnd << PAGE_SHIFT;
6792-}
6793-
6794-unsigned long arch_randomize_brk(struct mm_struct *mm)
6795-{
6796- unsigned long base = mm->brk;
6797- unsigned long ret;
6798-
6799-#ifdef CONFIG_PPC_STD_MMU_64
6800- /*
6801- * If we are using 1TB segments and we are allowed to randomise
6802- * the heap, we can put it above 1TB so it is backed by a 1TB
6803- * segment. Otherwise the heap will be in the bottom 1TB
6804- * which always uses 256MB segments and this may result in a
6805- * performance penalty.
6806- */
6807- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6808- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6809-#endif
6810-
6811- ret = PAGE_ALIGN(base + brk_rnd());
6812-
6813- if (ret < mm->brk)
6814- return mm->brk;
6815-
6816- return ret;
6817-}
6818-
6819-unsigned long randomize_et_dyn(unsigned long base)
6820-{
6821- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6822-
6823- if (ret < base)
6824- return base;
6825-
6826- return ret;
6827-}
6828diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6829index 98c2fc1..b73a4ca 100644
6830--- a/arch/powerpc/kernel/ptrace.c
6831+++ b/arch/powerpc/kernel/ptrace.c
6832@@ -1781,6 +1781,10 @@ long arch_ptrace(struct task_struct *child, long request,
6833 return ret;
6834 }
6835
6836+#ifdef CONFIG_GRKERNSEC_SETXID
6837+extern void gr_delayed_cred_worker(void);
6838+#endif
6839+
6840 /*
6841 * We must return the syscall number to actually look up in the table.
6842 * This can be -1L to skip running any syscall at all.
6843@@ -1793,6 +1797,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6844
6845 secure_computing_strict(regs->gpr[0]);
6846
6847+#ifdef CONFIG_GRKERNSEC_SETXID
6848+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6849+ gr_delayed_cred_worker();
6850+#endif
6851+
6852 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6853 tracehook_report_syscall_entry(regs))
6854 /*
6855@@ -1827,6 +1836,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6856 {
6857 int step;
6858
6859+#ifdef CONFIG_GRKERNSEC_SETXID
6860+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6861+ gr_delayed_cred_worker();
6862+#endif
6863+
6864 audit_syscall_exit(regs);
6865
6866 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6867diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6868index 201385c..0f01828 100644
6869--- a/arch/powerpc/kernel/signal_32.c
6870+++ b/arch/powerpc/kernel/signal_32.c
6871@@ -976,7 +976,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6872 /* Save user registers on the stack */
6873 frame = &rt_sf->uc.uc_mcontext;
6874 addr = frame;
6875- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6876+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6877 sigret = 0;
6878 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6879 } else {
6880diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6881index 3459473..2d40783 100644
6882--- a/arch/powerpc/kernel/signal_64.c
6883+++ b/arch/powerpc/kernel/signal_64.c
6884@@ -749,7 +749,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6885 #endif
6886
6887 /* Set up to return from userspace. */
6888- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6889+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6890 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6891 } else {
6892 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6893diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6894index e68a845..8b140e6 100644
6895--- a/arch/powerpc/kernel/sysfs.c
6896+++ b/arch/powerpc/kernel/sysfs.c
6897@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6898 return NOTIFY_OK;
6899 }
6900
6901-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6902+static struct notifier_block sysfs_cpu_nb = {
6903 .notifier_call = sysfs_cpu_notify,
6904 };
6905
6906diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6907index c0e5caf..68e8305 100644
6908--- a/arch/powerpc/kernel/traps.c
6909+++ b/arch/powerpc/kernel/traps.c
6910@@ -143,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6911 return flags;
6912 }
6913
6914+extern void gr_handle_kernel_exploit(void);
6915+
6916 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6917 int signr)
6918 {
6919@@ -192,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6920 panic("Fatal exception in interrupt");
6921 if (panic_on_oops)
6922 panic("Fatal exception");
6923+
6924+ gr_handle_kernel_exploit();
6925+
6926 do_exit(signr);
6927 }
6928
6929diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6930index d4f463a..8fb7431 100644
6931--- a/arch/powerpc/kernel/vdso.c
6932+++ b/arch/powerpc/kernel/vdso.c
6933@@ -34,6 +34,7 @@
6934 #include <asm/firmware.h>
6935 #include <asm/vdso.h>
6936 #include <asm/vdso_datapage.h>
6937+#include <asm/mman.h>
6938
6939 #include "setup.h"
6940
6941@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6942 vdso_base = VDSO32_MBASE;
6943 #endif
6944
6945- current->mm->context.vdso_base = 0;
6946+ current->mm->context.vdso_base = ~0UL;
6947
6948 /* vDSO has a problem and was disabled, just don't "enable" it for the
6949 * process
6950@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6951 vdso_base = get_unmapped_area(NULL, vdso_base,
6952 (vdso_pages << PAGE_SHIFT) +
6953 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6954- 0, 0);
6955+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6956 if (IS_ERR_VALUE(vdso_base)) {
6957 rc = vdso_base;
6958 goto fail_mmapsem;
6959diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6960index 5eea6f3..5d10396 100644
6961--- a/arch/powerpc/lib/usercopy_64.c
6962+++ b/arch/powerpc/lib/usercopy_64.c
6963@@ -9,22 +9,6 @@
6964 #include <linux/module.h>
6965 #include <asm/uaccess.h>
6966
6967-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6968-{
6969- if (likely(access_ok(VERIFY_READ, from, n)))
6970- n = __copy_from_user(to, from, n);
6971- else
6972- memset(to, 0, n);
6973- return n;
6974-}
6975-
6976-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6977-{
6978- if (likely(access_ok(VERIFY_WRITE, to, n)))
6979- n = __copy_to_user(to, from, n);
6980- return n;
6981-}
6982-
6983 unsigned long copy_in_user(void __user *to, const void __user *from,
6984 unsigned long n)
6985 {
6986@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6987 return n;
6988 }
6989
6990-EXPORT_SYMBOL(copy_from_user);
6991-EXPORT_SYMBOL(copy_to_user);
6992 EXPORT_SYMBOL(copy_in_user);
6993
6994diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6995index 8726779..a33c512 100644
6996--- a/arch/powerpc/mm/fault.c
6997+++ b/arch/powerpc/mm/fault.c
6998@@ -33,6 +33,10 @@
6999 #include <linux/magic.h>
7000 #include <linux/ratelimit.h>
7001 #include <linux/context_tracking.h>
7002+#include <linux/slab.h>
7003+#include <linux/pagemap.h>
7004+#include <linux/compiler.h>
7005+#include <linux/unistd.h>
7006
7007 #include <asm/firmware.h>
7008 #include <asm/page.h>
7009@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
7010 }
7011 #endif
7012
7013+#ifdef CONFIG_PAX_PAGEEXEC
7014+/*
7015+ * PaX: decide what to do with offenders (regs->nip = fault address)
7016+ *
7017+ * returns 1 when task should be killed
7018+ */
7019+static int pax_handle_fetch_fault(struct pt_regs *regs)
7020+{
7021+ return 1;
7022+}
7023+
7024+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7025+{
7026+ unsigned long i;
7027+
7028+ printk(KERN_ERR "PAX: bytes at PC: ");
7029+ for (i = 0; i < 5; i++) {
7030+ unsigned int c;
7031+ if (get_user(c, (unsigned int __user *)pc+i))
7032+ printk(KERN_CONT "???????? ");
7033+ else
7034+ printk(KERN_CONT "%08x ", c);
7035+ }
7036+ printk("\n");
7037+}
7038+#endif
7039+
7040 /*
7041 * Check whether the instruction at regs->nip is a store using
7042 * an update addressing form which will update r1.
7043@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
7044 * indicate errors in DSISR but can validly be set in SRR1.
7045 */
7046 if (trap == 0x400)
7047- error_code &= 0x48200000;
7048+ error_code &= 0x58200000;
7049 else
7050 is_write = error_code & DSISR_ISSTORE;
7051 #else
7052@@ -371,7 +402,7 @@ good_area:
7053 * "undefined". Of those that can be set, this is the only
7054 * one which seems bad.
7055 */
7056- if (error_code & 0x10000000)
7057+ if (error_code & DSISR_GUARDED)
7058 /* Guarded storage error. */
7059 goto bad_area;
7060 #endif /* CONFIG_8xx */
7061@@ -386,7 +417,7 @@ good_area:
7062 * processors use the same I/D cache coherency mechanism
7063 * as embedded.
7064 */
7065- if (error_code & DSISR_PROTFAULT)
7066+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
7067 goto bad_area;
7068 #endif /* CONFIG_PPC_STD_MMU */
7069
7070@@ -471,6 +502,23 @@ bad_area:
7071 bad_area_nosemaphore:
7072 /* User mode accesses cause a SIGSEGV */
7073 if (user_mode(regs)) {
7074+
7075+#ifdef CONFIG_PAX_PAGEEXEC
7076+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7077+#ifdef CONFIG_PPC_STD_MMU
7078+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7079+#else
7080+ if (is_exec && regs->nip == address) {
7081+#endif
7082+ switch (pax_handle_fetch_fault(regs)) {
7083+ }
7084+
7085+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7086+ do_group_exit(SIGKILL);
7087+ }
7088+ }
7089+#endif
7090+
7091 _exception(SIGSEGV, regs, code, address);
7092 goto bail;
7093 }
7094diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7095index 67a42ed..cd463e0 100644
7096--- a/arch/powerpc/mm/mmap_64.c
7097+++ b/arch/powerpc/mm/mmap_64.c
7098@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7099 {
7100 unsigned long rnd = 0;
7101
7102+#ifdef CONFIG_PAX_RANDMMAP
7103+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7104+#endif
7105+
7106 if (current->flags & PF_RANDOMIZE) {
7107 /* 8MB for 32bit, 1GB for 64bit */
7108 if (is_32bit_task())
7109@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7110 */
7111 if (mmap_is_legacy()) {
7112 mm->mmap_base = TASK_UNMAPPED_BASE;
7113+
7114+#ifdef CONFIG_PAX_RANDMMAP
7115+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7116+ mm->mmap_base += mm->delta_mmap;
7117+#endif
7118+
7119 mm->get_unmapped_area = arch_get_unmapped_area;
7120 mm->unmap_area = arch_unmap_area;
7121 } else {
7122 mm->mmap_base = mmap_base();
7123+
7124+#ifdef CONFIG_PAX_RANDMMAP
7125+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7126+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7127+#endif
7128+
7129 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7130 mm->unmap_area = arch_unmap_area_topdown;
7131 }
7132diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7133index e779642..e5bb889 100644
7134--- a/arch/powerpc/mm/mmu_context_nohash.c
7135+++ b/arch/powerpc/mm/mmu_context_nohash.c
7136@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7137 return NOTIFY_OK;
7138 }
7139
7140-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7141+static struct notifier_block mmu_context_cpu_nb = {
7142 .notifier_call = mmu_context_cpu_notify,
7143 };
7144
7145diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7146index 88c0425..717feb8 100644
7147--- a/arch/powerpc/mm/numa.c
7148+++ b/arch/powerpc/mm/numa.c
7149@@ -919,7 +919,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7150 return ret;
7151 }
7152
7153-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7154+static struct notifier_block ppc64_numa_nb = {
7155 .notifier_call = cpu_numa_callback,
7156 .priority = 1 /* Must run before sched domains notifier. */
7157 };
7158diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7159index 3e99c14..f00953c 100644
7160--- a/arch/powerpc/mm/slice.c
7161+++ b/arch/powerpc/mm/slice.c
7162@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7163 if ((mm->task_size - len) < addr)
7164 return 0;
7165 vma = find_vma(mm, addr);
7166- return (!vma || (addr + len) <= vma->vm_start);
7167+ return check_heap_stack_gap(vma, addr, len, 0);
7168 }
7169
7170 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7171@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
7172 info.align_offset = 0;
7173
7174 addr = TASK_UNMAPPED_BASE;
7175+
7176+#ifdef CONFIG_PAX_RANDMMAP
7177+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7178+ addr += mm->delta_mmap;
7179+#endif
7180+
7181 while (addr < TASK_SIZE) {
7182 info.low_limit = addr;
7183 if (!slice_scan_available(addr, available, 1, &addr))
7184@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7185 if (fixed && addr > (mm->task_size - len))
7186 return -EINVAL;
7187
7188+#ifdef CONFIG_PAX_RANDMMAP
7189+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7190+ addr = 0;
7191+#endif
7192+
7193 /* If hint, make sure it matches our alignment restrictions */
7194 if (!fixed && addr) {
7195 addr = _ALIGN_UP(addr, 1ul << pshift);
7196diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
7197index 9098692..3d54cd1 100644
7198--- a/arch/powerpc/platforms/cell/spufs/file.c
7199+++ b/arch/powerpc/platforms/cell/spufs/file.c
7200@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7201 return VM_FAULT_NOPAGE;
7202 }
7203
7204-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
7205+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
7206 unsigned long address,
7207- void *buf, int len, int write)
7208+ void *buf, size_t len, int write)
7209 {
7210 struct spu_context *ctx = vma->vm_file->private_data;
7211 unsigned long offset = address - vma->vm_start;
7212diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7213index bdb738a..49c9f95 100644
7214--- a/arch/powerpc/platforms/powermac/smp.c
7215+++ b/arch/powerpc/platforms/powermac/smp.c
7216@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7217 return NOTIFY_OK;
7218 }
7219
7220-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7221+static struct notifier_block smp_core99_cpu_nb = {
7222 .notifier_call = smp_core99_cpu_notify,
7223 };
7224 #endif /* CONFIG_HOTPLUG_CPU */
7225diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7226index c797832..ce575c8 100644
7227--- a/arch/s390/include/asm/atomic.h
7228+++ b/arch/s390/include/asm/atomic.h
7229@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7230 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7231 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7232
7233+#define atomic64_read_unchecked(v) atomic64_read(v)
7234+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7235+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7236+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7237+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7238+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7239+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7240+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7241+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7242+
7243 #define smp_mb__before_atomic_dec() smp_mb()
7244 #define smp_mb__after_atomic_dec() smp_mb()
7245 #define smp_mb__before_atomic_inc() smp_mb()
7246diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7247index 4d7ccac..d03d0ad 100644
7248--- a/arch/s390/include/asm/cache.h
7249+++ b/arch/s390/include/asm/cache.h
7250@@ -9,8 +9,10 @@
7251 #ifndef __ARCH_S390_CACHE_H
7252 #define __ARCH_S390_CACHE_H
7253
7254-#define L1_CACHE_BYTES 256
7255+#include <linux/const.h>
7256+
7257 #define L1_CACHE_SHIFT 8
7258+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7259 #define NET_SKB_PAD 32
7260
7261 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7262diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7263index 78f4f87..598ce39 100644
7264--- a/arch/s390/include/asm/elf.h
7265+++ b/arch/s390/include/asm/elf.h
7266@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
7267 the loader. We need to make sure that it is out of the way of the program
7268 that it will "exec", and that there is sufficient room for the brk. */
7269
7270-extern unsigned long randomize_et_dyn(unsigned long base);
7271-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7272+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7273+
7274+#ifdef CONFIG_PAX_ASLR
7275+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7276+
7277+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7278+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7279+#endif
7280
7281 /* This yields a mask that user programs can use to figure out what
7282 instruction set this CPU supports. */
7283@@ -222,9 +228,6 @@ struct linux_binprm;
7284 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7285 int arch_setup_additional_pages(struct linux_binprm *, int);
7286
7287-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7288-#define arch_randomize_brk arch_randomize_brk
7289-
7290 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7291
7292 #endif
7293diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7294index c4a93d6..4d2a9b4 100644
7295--- a/arch/s390/include/asm/exec.h
7296+++ b/arch/s390/include/asm/exec.h
7297@@ -7,6 +7,6 @@
7298 #ifndef __ASM_EXEC_H
7299 #define __ASM_EXEC_H
7300
7301-extern unsigned long arch_align_stack(unsigned long sp);
7302+#define arch_align_stack(x) ((x) & ~0xfUL)
7303
7304 #endif /* __ASM_EXEC_H */
7305diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7306index 9c33ed4..e40cbef 100644
7307--- a/arch/s390/include/asm/uaccess.h
7308+++ b/arch/s390/include/asm/uaccess.h
7309@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7310 copy_to_user(void __user *to, const void *from, unsigned long n)
7311 {
7312 might_fault();
7313+
7314+ if ((long)n < 0)
7315+ return n;
7316+
7317 return __copy_to_user(to, from, n);
7318 }
7319
7320@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7321 static inline unsigned long __must_check
7322 __copy_from_user(void *to, const void __user *from, unsigned long n)
7323 {
7324+ if ((long)n < 0)
7325+ return n;
7326+
7327 if (__builtin_constant_p(n) && (n <= 256))
7328 return uaccess.copy_from_user_small(n, from, to);
7329 else
7330@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7331 static inline unsigned long __must_check
7332 copy_from_user(void *to, const void __user *from, unsigned long n)
7333 {
7334- unsigned int sz = __compiletime_object_size(to);
7335+ size_t sz = __compiletime_object_size(to);
7336
7337 might_fault();
7338- if (unlikely(sz != -1 && sz < n)) {
7339+
7340+ if ((long)n < 0)
7341+ return n;
7342+
7343+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7344 copy_from_user_overflow();
7345 return n;
7346 }
7347diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7348index 7845e15..59c4353 100644
7349--- a/arch/s390/kernel/module.c
7350+++ b/arch/s390/kernel/module.c
7351@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7352
7353 /* Increase core size by size of got & plt and set start
7354 offsets for got and plt. */
7355- me->core_size = ALIGN(me->core_size, 4);
7356- me->arch.got_offset = me->core_size;
7357- me->core_size += me->arch.got_size;
7358- me->arch.plt_offset = me->core_size;
7359- me->core_size += me->arch.plt_size;
7360+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7361+ me->arch.got_offset = me->core_size_rw;
7362+ me->core_size_rw += me->arch.got_size;
7363+ me->arch.plt_offset = me->core_size_rx;
7364+ me->core_size_rx += me->arch.plt_size;
7365 return 0;
7366 }
7367
7368@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7369 if (info->got_initialized == 0) {
7370 Elf_Addr *gotent;
7371
7372- gotent = me->module_core + me->arch.got_offset +
7373+ gotent = me->module_core_rw + me->arch.got_offset +
7374 info->got_offset;
7375 *gotent = val;
7376 info->got_initialized = 1;
7377@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7378 rc = apply_rela_bits(loc, val, 0, 64, 0);
7379 else if (r_type == R_390_GOTENT ||
7380 r_type == R_390_GOTPLTENT) {
7381- val += (Elf_Addr) me->module_core - loc;
7382+ val += (Elf_Addr) me->module_core_rw - loc;
7383 rc = apply_rela_bits(loc, val, 1, 32, 1);
7384 }
7385 break;
7386@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7387 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7388 if (info->plt_initialized == 0) {
7389 unsigned int *ip;
7390- ip = me->module_core + me->arch.plt_offset +
7391+ ip = me->module_core_rx + me->arch.plt_offset +
7392 info->plt_offset;
7393 #ifndef CONFIG_64BIT
7394 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7395@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7396 val - loc + 0xffffUL < 0x1ffffeUL) ||
7397 (r_type == R_390_PLT32DBL &&
7398 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7399- val = (Elf_Addr) me->module_core +
7400+ val = (Elf_Addr) me->module_core_rx +
7401 me->arch.plt_offset +
7402 info->plt_offset;
7403 val += rela->r_addend - loc;
7404@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7405 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7406 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7407 val = val + rela->r_addend -
7408- ((Elf_Addr) me->module_core + me->arch.got_offset);
7409+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7410 if (r_type == R_390_GOTOFF16)
7411 rc = apply_rela_bits(loc, val, 0, 16, 0);
7412 else if (r_type == R_390_GOTOFF32)
7413@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7414 break;
7415 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7416 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7417- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7418+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7419 rela->r_addend - loc;
7420 if (r_type == R_390_GOTPC)
7421 rc = apply_rela_bits(loc, val, 1, 32, 0);
7422diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7423index 2bc3edd..ab9d598 100644
7424--- a/arch/s390/kernel/process.c
7425+++ b/arch/s390/kernel/process.c
7426@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
7427 }
7428 return 0;
7429 }
7430-
7431-unsigned long arch_align_stack(unsigned long sp)
7432-{
7433- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7434- sp -= get_random_int() & ~PAGE_MASK;
7435- return sp & ~0xf;
7436-}
7437-
7438-static inline unsigned long brk_rnd(void)
7439-{
7440- /* 8MB for 32bit, 1GB for 64bit */
7441- if (is_32bit_task())
7442- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7443- else
7444- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7445-}
7446-
7447-unsigned long arch_randomize_brk(struct mm_struct *mm)
7448-{
7449- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7450-
7451- if (ret < mm->brk)
7452- return mm->brk;
7453- return ret;
7454-}
7455-
7456-unsigned long randomize_et_dyn(unsigned long base)
7457-{
7458- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7459-
7460- if (!(current->flags & PF_RANDOMIZE))
7461- return base;
7462- if (ret < base)
7463- return base;
7464- return ret;
7465-}
7466diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7467index 06bafec..2bca531 100644
7468--- a/arch/s390/mm/mmap.c
7469+++ b/arch/s390/mm/mmap.c
7470@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7471 */
7472 if (mmap_is_legacy()) {
7473 mm->mmap_base = TASK_UNMAPPED_BASE;
7474+
7475+#ifdef CONFIG_PAX_RANDMMAP
7476+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7477+ mm->mmap_base += mm->delta_mmap;
7478+#endif
7479+
7480 mm->get_unmapped_area = arch_get_unmapped_area;
7481 mm->unmap_area = arch_unmap_area;
7482 } else {
7483 mm->mmap_base = mmap_base();
7484+
7485+#ifdef CONFIG_PAX_RANDMMAP
7486+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7487+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7488+#endif
7489+
7490 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7491 mm->unmap_area = arch_unmap_area_topdown;
7492 }
7493@@ -175,10 +187,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7494 */
7495 if (mmap_is_legacy()) {
7496 mm->mmap_base = TASK_UNMAPPED_BASE;
7497+
7498+#ifdef CONFIG_PAX_RANDMMAP
7499+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7500+ mm->mmap_base += mm->delta_mmap;
7501+#endif
7502+
7503 mm->get_unmapped_area = s390_get_unmapped_area;
7504 mm->unmap_area = arch_unmap_area;
7505 } else {
7506 mm->mmap_base = mmap_base();
7507+
7508+#ifdef CONFIG_PAX_RANDMMAP
7509+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7510+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7511+#endif
7512+
7513 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7514 mm->unmap_area = arch_unmap_area_topdown;
7515 }
7516diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7517index ae3d59f..f65f075 100644
7518--- a/arch/score/include/asm/cache.h
7519+++ b/arch/score/include/asm/cache.h
7520@@ -1,7 +1,9 @@
7521 #ifndef _ASM_SCORE_CACHE_H
7522 #define _ASM_SCORE_CACHE_H
7523
7524+#include <linux/const.h>
7525+
7526 #define L1_CACHE_SHIFT 4
7527-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7528+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7529
7530 #endif /* _ASM_SCORE_CACHE_H */
7531diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7532index f9f3cd5..58ff438 100644
7533--- a/arch/score/include/asm/exec.h
7534+++ b/arch/score/include/asm/exec.h
7535@@ -1,6 +1,6 @@
7536 #ifndef _ASM_SCORE_EXEC_H
7537 #define _ASM_SCORE_EXEC_H
7538
7539-extern unsigned long arch_align_stack(unsigned long sp);
7540+#define arch_align_stack(x) (x)
7541
7542 #endif /* _ASM_SCORE_EXEC_H */
7543diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7544index f4c6d02..e9355c3 100644
7545--- a/arch/score/kernel/process.c
7546+++ b/arch/score/kernel/process.c
7547@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
7548
7549 return task_pt_regs(task)->cp0_epc;
7550 }
7551-
7552-unsigned long arch_align_stack(unsigned long sp)
7553-{
7554- return sp;
7555-}
7556diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7557index ef9e555..331bd29 100644
7558--- a/arch/sh/include/asm/cache.h
7559+++ b/arch/sh/include/asm/cache.h
7560@@ -9,10 +9,11 @@
7561 #define __ASM_SH_CACHE_H
7562 #ifdef __KERNEL__
7563
7564+#include <linux/const.h>
7565 #include <linux/init.h>
7566 #include <cpu/cache.h>
7567
7568-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7569+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7570
7571 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7572
7573diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7574index 03f2b55..b0270327 100644
7575--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7576+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7577@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7578 return NOTIFY_OK;
7579 }
7580
7581-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7582+static struct notifier_block shx3_cpu_notifier = {
7583 .notifier_call = shx3_cpu_callback,
7584 };
7585
7586diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7587index 6777177..cb5e44f 100644
7588--- a/arch/sh/mm/mmap.c
7589+++ b/arch/sh/mm/mmap.c
7590@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7591 struct mm_struct *mm = current->mm;
7592 struct vm_area_struct *vma;
7593 int do_colour_align;
7594+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7595 struct vm_unmapped_area_info info;
7596
7597 if (flags & MAP_FIXED) {
7598@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7599 if (filp || (flags & MAP_SHARED))
7600 do_colour_align = 1;
7601
7602+#ifdef CONFIG_PAX_RANDMMAP
7603+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7604+#endif
7605+
7606 if (addr) {
7607 if (do_colour_align)
7608 addr = COLOUR_ALIGN(addr, pgoff);
7609@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7610 addr = PAGE_ALIGN(addr);
7611
7612 vma = find_vma(mm, addr);
7613- if (TASK_SIZE - len >= addr &&
7614- (!vma || addr + len <= vma->vm_start))
7615+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7616 return addr;
7617 }
7618
7619 info.flags = 0;
7620 info.length = len;
7621- info.low_limit = TASK_UNMAPPED_BASE;
7622+ info.low_limit = mm->mmap_base;
7623 info.high_limit = TASK_SIZE;
7624 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7625 info.align_offset = pgoff << PAGE_SHIFT;
7626@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7627 struct mm_struct *mm = current->mm;
7628 unsigned long addr = addr0;
7629 int do_colour_align;
7630+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7631 struct vm_unmapped_area_info info;
7632
7633 if (flags & MAP_FIXED) {
7634@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7635 if (filp || (flags & MAP_SHARED))
7636 do_colour_align = 1;
7637
7638+#ifdef CONFIG_PAX_RANDMMAP
7639+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7640+#endif
7641+
7642 /* requesting a specific address */
7643 if (addr) {
7644 if (do_colour_align)
7645@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7646 addr = PAGE_ALIGN(addr);
7647
7648 vma = find_vma(mm, addr);
7649- if (TASK_SIZE - len >= addr &&
7650- (!vma || addr + len <= vma->vm_start))
7651+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7652 return addr;
7653 }
7654
7655@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7656 VM_BUG_ON(addr != -ENOMEM);
7657 info.flags = 0;
7658 info.low_limit = TASK_UNMAPPED_BASE;
7659+
7660+#ifdef CONFIG_PAX_RANDMMAP
7661+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7662+ info.low_limit += mm->delta_mmap;
7663+#endif
7664+
7665 info.high_limit = TASK_SIZE;
7666 addr = vm_unmapped_area(&info);
7667 }
7668diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7669index be56a24..443328f 100644
7670--- a/arch/sparc/include/asm/atomic_64.h
7671+++ b/arch/sparc/include/asm/atomic_64.h
7672@@ -14,18 +14,40 @@
7673 #define ATOMIC64_INIT(i) { (i) }
7674
7675 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7676+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7677+{
7678+ return v->counter;
7679+}
7680 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7681+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7682+{
7683+ return v->counter;
7684+}
7685
7686 #define atomic_set(v, i) (((v)->counter) = i)
7687+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7688+{
7689+ v->counter = i;
7690+}
7691 #define atomic64_set(v, i) (((v)->counter) = i)
7692+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7693+{
7694+ v->counter = i;
7695+}
7696
7697 extern void atomic_add(int, atomic_t *);
7698+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7699 extern void atomic64_add(long, atomic64_t *);
7700+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7701 extern void atomic_sub(int, atomic_t *);
7702+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7703 extern void atomic64_sub(long, atomic64_t *);
7704+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7705
7706 extern int atomic_add_ret(int, atomic_t *);
7707+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7708 extern long atomic64_add_ret(long, atomic64_t *);
7709+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7710 extern int atomic_sub_ret(int, atomic_t *);
7711 extern long atomic64_sub_ret(long, atomic64_t *);
7712
7713@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7714 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7715
7716 #define atomic_inc_return(v) atomic_add_ret(1, v)
7717+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7718+{
7719+ return atomic_add_ret_unchecked(1, v);
7720+}
7721 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7722+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7723+{
7724+ return atomic64_add_ret_unchecked(1, v);
7725+}
7726
7727 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7728 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7729
7730 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7731+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7732+{
7733+ return atomic_add_ret_unchecked(i, v);
7734+}
7735 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7736+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7737+{
7738+ return atomic64_add_ret_unchecked(i, v);
7739+}
7740
7741 /*
7742 * atomic_inc_and_test - increment and test
7743@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7744 * other cases.
7745 */
7746 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7747+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7748+{
7749+ return atomic_inc_return_unchecked(v) == 0;
7750+}
7751 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7752
7753 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7754@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7755 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7756
7757 #define atomic_inc(v) atomic_add(1, v)
7758+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7759+{
7760+ atomic_add_unchecked(1, v);
7761+}
7762 #define atomic64_inc(v) atomic64_add(1, v)
7763+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7764+{
7765+ atomic64_add_unchecked(1, v);
7766+}
7767
7768 #define atomic_dec(v) atomic_sub(1, v)
7769+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7770+{
7771+ atomic_sub_unchecked(1, v);
7772+}
7773 #define atomic64_dec(v) atomic64_sub(1, v)
7774+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7775+{
7776+ atomic64_sub_unchecked(1, v);
7777+}
7778
7779 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7780 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7781
7782 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7783+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7784+{
7785+ return cmpxchg(&v->counter, old, new);
7786+}
7787 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7788+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7789+{
7790+ return xchg(&v->counter, new);
7791+}
7792
7793 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7794 {
7795- int c, old;
7796+ int c, old, new;
7797 c = atomic_read(v);
7798 for (;;) {
7799- if (unlikely(c == (u)))
7800+ if (unlikely(c == u))
7801 break;
7802- old = atomic_cmpxchg((v), c, c + (a));
7803+
7804+ asm volatile("addcc %2, %0, %0\n"
7805+
7806+#ifdef CONFIG_PAX_REFCOUNT
7807+ "tvs %%icc, 6\n"
7808+#endif
7809+
7810+ : "=r" (new)
7811+ : "0" (c), "ir" (a)
7812+ : "cc");
7813+
7814+ old = atomic_cmpxchg(v, c, new);
7815 if (likely(old == c))
7816 break;
7817 c = old;
7818@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7819 #define atomic64_cmpxchg(v, o, n) \
7820 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7821 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7822+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7823+{
7824+ return xchg(&v->counter, new);
7825+}
7826
7827 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7828 {
7829- long c, old;
7830+ long c, old, new;
7831 c = atomic64_read(v);
7832 for (;;) {
7833- if (unlikely(c == (u)))
7834+ if (unlikely(c == u))
7835 break;
7836- old = atomic64_cmpxchg((v), c, c + (a));
7837+
7838+ asm volatile("addcc %2, %0, %0\n"
7839+
7840+#ifdef CONFIG_PAX_REFCOUNT
7841+ "tvs %%xcc, 6\n"
7842+#endif
7843+
7844+ : "=r" (new)
7845+ : "0" (c), "ir" (a)
7846+ : "cc");
7847+
7848+ old = atomic64_cmpxchg(v, c, new);
7849 if (likely(old == c))
7850 break;
7851 c = old;
7852 }
7853- return c != (u);
7854+ return c != u;
7855 }
7856
7857 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7858diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7859index 5bb6991..5c2132e 100644
7860--- a/arch/sparc/include/asm/cache.h
7861+++ b/arch/sparc/include/asm/cache.h
7862@@ -7,10 +7,12 @@
7863 #ifndef _SPARC_CACHE_H
7864 #define _SPARC_CACHE_H
7865
7866+#include <linux/const.h>
7867+
7868 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7869
7870 #define L1_CACHE_SHIFT 5
7871-#define L1_CACHE_BYTES 32
7872+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7873
7874 #ifdef CONFIG_SPARC32
7875 #define SMP_CACHE_BYTES_SHIFT 5
7876diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7877index a24e41f..47677ff 100644
7878--- a/arch/sparc/include/asm/elf_32.h
7879+++ b/arch/sparc/include/asm/elf_32.h
7880@@ -114,6 +114,13 @@ typedef struct {
7881
7882 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7883
7884+#ifdef CONFIG_PAX_ASLR
7885+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7886+
7887+#define PAX_DELTA_MMAP_LEN 16
7888+#define PAX_DELTA_STACK_LEN 16
7889+#endif
7890+
7891 /* This yields a mask that user programs can use to figure out what
7892 instruction set this cpu supports. This can NOT be done in userspace
7893 on Sparc. */
7894diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7895index 370ca1e..d4f4a98 100644
7896--- a/arch/sparc/include/asm/elf_64.h
7897+++ b/arch/sparc/include/asm/elf_64.h
7898@@ -189,6 +189,13 @@ typedef struct {
7899 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7900 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7901
7902+#ifdef CONFIG_PAX_ASLR
7903+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7904+
7905+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7906+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7907+#endif
7908+
7909 extern unsigned long sparc64_elf_hwcap;
7910 #define ELF_HWCAP sparc64_elf_hwcap
7911
7912diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7913index 9b1c36d..209298b 100644
7914--- a/arch/sparc/include/asm/pgalloc_32.h
7915+++ b/arch/sparc/include/asm/pgalloc_32.h
7916@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7917 }
7918
7919 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7920+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7921
7922 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7923 unsigned long address)
7924diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7925index bcfe063..b333142 100644
7926--- a/arch/sparc/include/asm/pgalloc_64.h
7927+++ b/arch/sparc/include/asm/pgalloc_64.h
7928@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7929 }
7930
7931 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7932+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7933
7934 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7935 {
7936diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7937index 6fc1348..390c50a 100644
7938--- a/arch/sparc/include/asm/pgtable_32.h
7939+++ b/arch/sparc/include/asm/pgtable_32.h
7940@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7941 #define PAGE_SHARED SRMMU_PAGE_SHARED
7942 #define PAGE_COPY SRMMU_PAGE_COPY
7943 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7944+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7945+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7946+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7947 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7948
7949 /* Top-level page directory - dummy used by init-mm.
7950@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7951
7952 /* xwr */
7953 #define __P000 PAGE_NONE
7954-#define __P001 PAGE_READONLY
7955-#define __P010 PAGE_COPY
7956-#define __P011 PAGE_COPY
7957+#define __P001 PAGE_READONLY_NOEXEC
7958+#define __P010 PAGE_COPY_NOEXEC
7959+#define __P011 PAGE_COPY_NOEXEC
7960 #define __P100 PAGE_READONLY
7961 #define __P101 PAGE_READONLY
7962 #define __P110 PAGE_COPY
7963 #define __P111 PAGE_COPY
7964
7965 #define __S000 PAGE_NONE
7966-#define __S001 PAGE_READONLY
7967-#define __S010 PAGE_SHARED
7968-#define __S011 PAGE_SHARED
7969+#define __S001 PAGE_READONLY_NOEXEC
7970+#define __S010 PAGE_SHARED_NOEXEC
7971+#define __S011 PAGE_SHARED_NOEXEC
7972 #define __S100 PAGE_READONLY
7973 #define __S101 PAGE_READONLY
7974 #define __S110 PAGE_SHARED
7975diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7976index 79da178..c2eede8 100644
7977--- a/arch/sparc/include/asm/pgtsrmmu.h
7978+++ b/arch/sparc/include/asm/pgtsrmmu.h
7979@@ -115,6 +115,11 @@
7980 SRMMU_EXEC | SRMMU_REF)
7981 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7982 SRMMU_EXEC | SRMMU_REF)
7983+
7984+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7985+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7986+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7987+
7988 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7989 SRMMU_DIRTY | SRMMU_REF)
7990
7991diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7992index 9689176..63c18ea 100644
7993--- a/arch/sparc/include/asm/spinlock_64.h
7994+++ b/arch/sparc/include/asm/spinlock_64.h
7995@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7996
7997 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7998
7999-static void inline arch_read_lock(arch_rwlock_t *lock)
8000+static inline void arch_read_lock(arch_rwlock_t *lock)
8001 {
8002 unsigned long tmp1, tmp2;
8003
8004 __asm__ __volatile__ (
8005 "1: ldsw [%2], %0\n"
8006 " brlz,pn %0, 2f\n"
8007-"4: add %0, 1, %1\n"
8008+"4: addcc %0, 1, %1\n"
8009+
8010+#ifdef CONFIG_PAX_REFCOUNT
8011+" tvs %%icc, 6\n"
8012+#endif
8013+
8014 " cas [%2], %0, %1\n"
8015 " cmp %0, %1\n"
8016 " bne,pn %%icc, 1b\n"
8017@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8018 " .previous"
8019 : "=&r" (tmp1), "=&r" (tmp2)
8020 : "r" (lock)
8021- : "memory");
8022+ : "memory", "cc");
8023 }
8024
8025-static int inline arch_read_trylock(arch_rwlock_t *lock)
8026+static inline int arch_read_trylock(arch_rwlock_t *lock)
8027 {
8028 int tmp1, tmp2;
8029
8030@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8031 "1: ldsw [%2], %0\n"
8032 " brlz,a,pn %0, 2f\n"
8033 " mov 0, %0\n"
8034-" add %0, 1, %1\n"
8035+" addcc %0, 1, %1\n"
8036+
8037+#ifdef CONFIG_PAX_REFCOUNT
8038+" tvs %%icc, 6\n"
8039+#endif
8040+
8041 " cas [%2], %0, %1\n"
8042 " cmp %0, %1\n"
8043 " bne,pn %%icc, 1b\n"
8044@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8045 return tmp1;
8046 }
8047
8048-static void inline arch_read_unlock(arch_rwlock_t *lock)
8049+static inline void arch_read_unlock(arch_rwlock_t *lock)
8050 {
8051 unsigned long tmp1, tmp2;
8052
8053 __asm__ __volatile__(
8054 "1: lduw [%2], %0\n"
8055-" sub %0, 1, %1\n"
8056+" subcc %0, 1, %1\n"
8057+
8058+#ifdef CONFIG_PAX_REFCOUNT
8059+" tvs %%icc, 6\n"
8060+#endif
8061+
8062 " cas [%2], %0, %1\n"
8063 " cmp %0, %1\n"
8064 " bne,pn %%xcc, 1b\n"
8065@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8066 : "memory");
8067 }
8068
8069-static void inline arch_write_lock(arch_rwlock_t *lock)
8070+static inline void arch_write_lock(arch_rwlock_t *lock)
8071 {
8072 unsigned long mask, tmp1, tmp2;
8073
8074@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8075 : "memory");
8076 }
8077
8078-static void inline arch_write_unlock(arch_rwlock_t *lock)
8079+static inline void arch_write_unlock(arch_rwlock_t *lock)
8080 {
8081 __asm__ __volatile__(
8082 " stw %%g0, [%0]"
8083@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8084 : "memory");
8085 }
8086
8087-static int inline arch_write_trylock(arch_rwlock_t *lock)
8088+static inline int arch_write_trylock(arch_rwlock_t *lock)
8089 {
8090 unsigned long mask, tmp1, tmp2, result;
8091
8092diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8093index dd38075..e7cac83 100644
8094--- a/arch/sparc/include/asm/thread_info_32.h
8095+++ b/arch/sparc/include/asm/thread_info_32.h
8096@@ -49,6 +49,8 @@ struct thread_info {
8097 unsigned long w_saved;
8098
8099 struct restart_block restart_block;
8100+
8101+ unsigned long lowest_stack;
8102 };
8103
8104 /*
8105diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8106index d5e5042..9bfee76 100644
8107--- a/arch/sparc/include/asm/thread_info_64.h
8108+++ b/arch/sparc/include/asm/thread_info_64.h
8109@@ -63,6 +63,8 @@ struct thread_info {
8110 struct pt_regs *kern_una_regs;
8111 unsigned int kern_una_insn;
8112
8113+ unsigned long lowest_stack;
8114+
8115 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8116 };
8117
8118@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8119 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8120 /* flag bit 6 is available */
8121 #define TIF_32BIT 7 /* 32-bit binary */
8122-/* flag bit 8 is available */
8123+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8124 #define TIF_SECCOMP 9 /* secure computing */
8125 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8126 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8127+
8128 /* NOTE: Thread flags >= 12 should be ones we have no interest
8129 * in using in assembly, else we can't use the mask as
8130 * an immediate value in instructions such as andcc.
8131@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8132 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8133 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8134 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8135+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8136
8137 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8138 _TIF_DO_NOTIFY_RESUME_MASK | \
8139 _TIF_NEED_RESCHED)
8140 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8141
8142+#define _TIF_WORK_SYSCALL \
8143+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8144+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8145+
8146+
8147 /*
8148 * Thread-synchronous status.
8149 *
8150diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8151index 0167d26..767bb0c 100644
8152--- a/arch/sparc/include/asm/uaccess.h
8153+++ b/arch/sparc/include/asm/uaccess.h
8154@@ -1,5 +1,6 @@
8155 #ifndef ___ASM_SPARC_UACCESS_H
8156 #define ___ASM_SPARC_UACCESS_H
8157+
8158 #if defined(__sparc__) && defined(__arch64__)
8159 #include <asm/uaccess_64.h>
8160 #else
8161diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8162index 53a28dd..50c38c3 100644
8163--- a/arch/sparc/include/asm/uaccess_32.h
8164+++ b/arch/sparc/include/asm/uaccess_32.h
8165@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8166
8167 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8168 {
8169- if (n && __access_ok((unsigned long) to, n))
8170+ if ((long)n < 0)
8171+ return n;
8172+
8173+ if (n && __access_ok((unsigned long) to, n)) {
8174+ if (!__builtin_constant_p(n))
8175+ check_object_size(from, n, true);
8176 return __copy_user(to, (__force void __user *) from, n);
8177- else
8178+ } else
8179 return n;
8180 }
8181
8182 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8183 {
8184+ if ((long)n < 0)
8185+ return n;
8186+
8187+ if (!__builtin_constant_p(n))
8188+ check_object_size(from, n, true);
8189+
8190 return __copy_user(to, (__force void __user *) from, n);
8191 }
8192
8193 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8194 {
8195- if (n && __access_ok((unsigned long) from, n))
8196+ if ((long)n < 0)
8197+ return n;
8198+
8199+ if (n && __access_ok((unsigned long) from, n)) {
8200+ if (!__builtin_constant_p(n))
8201+ check_object_size(to, n, false);
8202 return __copy_user((__force void __user *) to, from, n);
8203- else
8204+ } else
8205 return n;
8206 }
8207
8208 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8209 {
8210+ if ((long)n < 0)
8211+ return n;
8212+
8213 return __copy_user((__force void __user *) to, from, n);
8214 }
8215
8216diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8217index e562d3c..191f176 100644
8218--- a/arch/sparc/include/asm/uaccess_64.h
8219+++ b/arch/sparc/include/asm/uaccess_64.h
8220@@ -10,6 +10,7 @@
8221 #include <linux/compiler.h>
8222 #include <linux/string.h>
8223 #include <linux/thread_info.h>
8224+#include <linux/kernel.h>
8225 #include <asm/asi.h>
8226 #include <asm/spitfire.h>
8227 #include <asm-generic/uaccess-unaligned.h>
8228@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8229 static inline unsigned long __must_check
8230 copy_from_user(void *to, const void __user *from, unsigned long size)
8231 {
8232- unsigned long ret = ___copy_from_user(to, from, size);
8233+ unsigned long ret;
8234
8235+ if ((long)size < 0 || size > INT_MAX)
8236+ return size;
8237+
8238+ if (!__builtin_constant_p(size))
8239+ check_object_size(to, size, false);
8240+
8241+ ret = ___copy_from_user(to, from, size);
8242 if (unlikely(ret))
8243 ret = copy_from_user_fixup(to, from, size);
8244
8245@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8246 static inline unsigned long __must_check
8247 copy_to_user(void __user *to, const void *from, unsigned long size)
8248 {
8249- unsigned long ret = ___copy_to_user(to, from, size);
8250+ unsigned long ret;
8251
8252+ if ((long)size < 0 || size > INT_MAX)
8253+ return size;
8254+
8255+ if (!__builtin_constant_p(size))
8256+ check_object_size(from, size, true);
8257+
8258+ ret = ___copy_to_user(to, from, size);
8259 if (unlikely(ret))
8260 ret = copy_to_user_fixup(to, from, size);
8261 return ret;
8262diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8263index d432fb2..6056af1 100644
8264--- a/arch/sparc/kernel/Makefile
8265+++ b/arch/sparc/kernel/Makefile
8266@@ -3,7 +3,7 @@
8267 #
8268
8269 asflags-y := -ansi
8270-ccflags-y := -Werror
8271+#ccflags-y := -Werror
8272
8273 extra-y := head_$(BITS).o
8274
8275diff --git a/arch/sparc/kernel/ds.c b/arch/sparc/kernel/ds.c
8276index 5ef48da..11d460f 100644
8277--- a/arch/sparc/kernel/ds.c
8278+++ b/arch/sparc/kernel/ds.c
8279@@ -783,6 +783,16 @@ void ldom_set_var(const char *var, const char *value)
8280 char *base, *p;
8281 int msg_len, loops;
8282
8283+ if (strlen(var) + strlen(value) + 2 >
8284+ sizeof(pkt) - sizeof(pkt.header)) {
8285+ printk(KERN_ERR PFX
8286+ "contents length: %zu, which more than max: %lu,"
8287+ "so could not set (%s) variable to (%s).\n",
8288+ strlen(var) + strlen(value) + 2,
8289+ sizeof(pkt) - sizeof(pkt.header), var, value);
8290+ return;
8291+ }
8292+
8293 memset(&pkt, 0, sizeof(pkt));
8294 pkt.header.data.tag.type = DS_DATA;
8295 pkt.header.data.handle = cp->handle;
8296diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8297index fdd819d..5af08c8 100644
8298--- a/arch/sparc/kernel/process_32.c
8299+++ b/arch/sparc/kernel/process_32.c
8300@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
8301
8302 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8303 r->psr, r->pc, r->npc, r->y, print_tainted());
8304- printk("PC: <%pS>\n", (void *) r->pc);
8305+ printk("PC: <%pA>\n", (void *) r->pc);
8306 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8307 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8308 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8309 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8310 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8311 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8312- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8313+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8314
8315 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8316 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8317@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8318 rw = (struct reg_window32 *) fp;
8319 pc = rw->ins[7];
8320 printk("[%08lx : ", pc);
8321- printk("%pS ] ", (void *) pc);
8322+ printk("%pA ] ", (void *) pc);
8323 fp = rw->ins[6];
8324 } while (++count < 16);
8325 printk("\n");
8326diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8327index baebab2..9cd13b1 100644
8328--- a/arch/sparc/kernel/process_64.c
8329+++ b/arch/sparc/kernel/process_64.c
8330@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
8331 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8332 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8333 if (regs->tstate & TSTATE_PRIV)
8334- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8335+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8336 }
8337
8338 void show_regs(struct pt_regs *regs)
8339@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
8340
8341 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8342 regs->tpc, regs->tnpc, regs->y, print_tainted());
8343- printk("TPC: <%pS>\n", (void *) regs->tpc);
8344+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8345 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8346 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8347 regs->u_regs[3]);
8348@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
8349 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8350 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8351 regs->u_regs[15]);
8352- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8353+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8354 show_regwindow(regs);
8355 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8356 }
8357@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
8358 ((tp && tp->task) ? tp->task->pid : -1));
8359
8360 if (gp->tstate & TSTATE_PRIV) {
8361- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8362+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8363 (void *) gp->tpc,
8364 (void *) gp->o7,
8365 (void *) gp->i7,
8366diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
8367index 79cc0d1..ec62734 100644
8368--- a/arch/sparc/kernel/prom_common.c
8369+++ b/arch/sparc/kernel/prom_common.c
8370@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
8371
8372 unsigned int prom_early_allocated __initdata;
8373
8374-static struct of_pdt_ops prom_sparc_ops __initdata = {
8375+static struct of_pdt_ops prom_sparc_ops __initconst = {
8376 .nextprop = prom_common_nextprop,
8377 .getproplen = prom_getproplen,
8378 .getproperty = prom_getproperty,
8379diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8380index 7ff45e4..a58f271 100644
8381--- a/arch/sparc/kernel/ptrace_64.c
8382+++ b/arch/sparc/kernel/ptrace_64.c
8383@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8384 return ret;
8385 }
8386
8387+#ifdef CONFIG_GRKERNSEC_SETXID
8388+extern void gr_delayed_cred_worker(void);
8389+#endif
8390+
8391 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8392 {
8393 int ret = 0;
8394@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8395 /* do the secure computing check first */
8396 secure_computing_strict(regs->u_regs[UREG_G1]);
8397
8398+#ifdef CONFIG_GRKERNSEC_SETXID
8399+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8400+ gr_delayed_cred_worker();
8401+#endif
8402+
8403 if (test_thread_flag(TIF_SYSCALL_TRACE))
8404 ret = tracehook_report_syscall_entry(regs);
8405
8406@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8407
8408 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8409 {
8410+#ifdef CONFIG_GRKERNSEC_SETXID
8411+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8412+ gr_delayed_cred_worker();
8413+#endif
8414+
8415 audit_syscall_exit(regs);
8416
8417 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8418diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8419index 3a8d184..49498a8 100644
8420--- a/arch/sparc/kernel/sys_sparc_32.c
8421+++ b/arch/sparc/kernel/sys_sparc_32.c
8422@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8423 if (len > TASK_SIZE - PAGE_SIZE)
8424 return -ENOMEM;
8425 if (!addr)
8426- addr = TASK_UNMAPPED_BASE;
8427+ addr = current->mm->mmap_base;
8428
8429 info.flags = 0;
8430 info.length = len;
8431diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8432index 2daaaa6..4fb84dc 100644
8433--- a/arch/sparc/kernel/sys_sparc_64.c
8434+++ b/arch/sparc/kernel/sys_sparc_64.c
8435@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8436 struct vm_area_struct * vma;
8437 unsigned long task_size = TASK_SIZE;
8438 int do_color_align;
8439+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8440 struct vm_unmapped_area_info info;
8441
8442 if (flags & MAP_FIXED) {
8443 /* We do not accept a shared mapping if it would violate
8444 * cache aliasing constraints.
8445 */
8446- if ((flags & MAP_SHARED) &&
8447+ if ((filp || (flags & MAP_SHARED)) &&
8448 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8449 return -EINVAL;
8450 return addr;
8451@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8452 if (filp || (flags & MAP_SHARED))
8453 do_color_align = 1;
8454
8455+#ifdef CONFIG_PAX_RANDMMAP
8456+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8457+#endif
8458+
8459 if (addr) {
8460 if (do_color_align)
8461 addr = COLOR_ALIGN(addr, pgoff);
8462@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8463 addr = PAGE_ALIGN(addr);
8464
8465 vma = find_vma(mm, addr);
8466- if (task_size - len >= addr &&
8467- (!vma || addr + len <= vma->vm_start))
8468+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8469 return addr;
8470 }
8471
8472 info.flags = 0;
8473 info.length = len;
8474- info.low_limit = TASK_UNMAPPED_BASE;
8475+ info.low_limit = mm->mmap_base;
8476 info.high_limit = min(task_size, VA_EXCLUDE_START);
8477 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8478 info.align_offset = pgoff << PAGE_SHIFT;
8479+ info.threadstack_offset = offset;
8480 addr = vm_unmapped_area(&info);
8481
8482 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8483 VM_BUG_ON(addr != -ENOMEM);
8484 info.low_limit = VA_EXCLUDE_END;
8485+
8486+#ifdef CONFIG_PAX_RANDMMAP
8487+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8488+ info.low_limit += mm->delta_mmap;
8489+#endif
8490+
8491 info.high_limit = task_size;
8492 addr = vm_unmapped_area(&info);
8493 }
8494@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8495 unsigned long task_size = STACK_TOP32;
8496 unsigned long addr = addr0;
8497 int do_color_align;
8498+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8499 struct vm_unmapped_area_info info;
8500
8501 /* This should only ever run for 32-bit processes. */
8502@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8503 /* We do not accept a shared mapping if it would violate
8504 * cache aliasing constraints.
8505 */
8506- if ((flags & MAP_SHARED) &&
8507+ if ((filp || (flags & MAP_SHARED)) &&
8508 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8509 return -EINVAL;
8510 return addr;
8511@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8512 if (filp || (flags & MAP_SHARED))
8513 do_color_align = 1;
8514
8515+#ifdef CONFIG_PAX_RANDMMAP
8516+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8517+#endif
8518+
8519 /* requesting a specific address */
8520 if (addr) {
8521 if (do_color_align)
8522@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8523 addr = PAGE_ALIGN(addr);
8524
8525 vma = find_vma(mm, addr);
8526- if (task_size - len >= addr &&
8527- (!vma || addr + len <= vma->vm_start))
8528+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8529 return addr;
8530 }
8531
8532@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8533 info.high_limit = mm->mmap_base;
8534 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8535 info.align_offset = pgoff << PAGE_SHIFT;
8536+ info.threadstack_offset = offset;
8537 addr = vm_unmapped_area(&info);
8538
8539 /*
8540@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8541 VM_BUG_ON(addr != -ENOMEM);
8542 info.flags = 0;
8543 info.low_limit = TASK_UNMAPPED_BASE;
8544+
8545+#ifdef CONFIG_PAX_RANDMMAP
8546+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8547+ info.low_limit += mm->delta_mmap;
8548+#endif
8549+
8550 info.high_limit = STACK_TOP32;
8551 addr = vm_unmapped_area(&info);
8552 }
8553@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
8554 EXPORT_SYMBOL(get_fb_unmapped_area);
8555
8556 /* Essentially the same as PowerPC. */
8557-static unsigned long mmap_rnd(void)
8558+static unsigned long mmap_rnd(struct mm_struct *mm)
8559 {
8560 unsigned long rnd = 0UL;
8561
8562+#ifdef CONFIG_PAX_RANDMMAP
8563+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8564+#endif
8565+
8566 if (current->flags & PF_RANDOMIZE) {
8567 unsigned long val = get_random_int();
8568 if (test_thread_flag(TIF_32BIT))
8569@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
8570
8571 void arch_pick_mmap_layout(struct mm_struct *mm)
8572 {
8573- unsigned long random_factor = mmap_rnd();
8574+ unsigned long random_factor = mmap_rnd(mm);
8575 unsigned long gap;
8576
8577 /*
8578@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8579 gap == RLIM_INFINITY ||
8580 sysctl_legacy_va_layout) {
8581 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8582+
8583+#ifdef CONFIG_PAX_RANDMMAP
8584+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8585+ mm->mmap_base += mm->delta_mmap;
8586+#endif
8587+
8588 mm->get_unmapped_area = arch_get_unmapped_area;
8589 mm->unmap_area = arch_unmap_area;
8590 } else {
8591@@ -301,6 +333,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8592 gap = (task_size / 6 * 5);
8593
8594 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8595+
8596+#ifdef CONFIG_PAX_RANDMMAP
8597+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8598+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8599+#endif
8600+
8601 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8602 mm->unmap_area = arch_unmap_area_topdown;
8603 }
8604diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8605index 22a1098..6255eb9 100644
8606--- a/arch/sparc/kernel/syscalls.S
8607+++ b/arch/sparc/kernel/syscalls.S
8608@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
8609 #endif
8610 .align 32
8611 1: ldx [%g6 + TI_FLAGS], %l5
8612- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8613+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8614 be,pt %icc, rtrap
8615 nop
8616 call syscall_trace_leave
8617@@ -184,7 +184,7 @@ linux_sparc_syscall32:
8618
8619 srl %i5, 0, %o5 ! IEU1
8620 srl %i2, 0, %o2 ! IEU0 Group
8621- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8622+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8623 bne,pn %icc, linux_syscall_trace32 ! CTI
8624 mov %i0, %l5 ! IEU1
8625 call %l7 ! CTI Group brk forced
8626@@ -207,7 +207,7 @@ linux_sparc_syscall:
8627
8628 mov %i3, %o3 ! IEU1
8629 mov %i4, %o4 ! IEU0 Group
8630- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8631+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8632 bne,pn %icc, linux_syscall_trace ! CTI Group
8633 mov %i0, %l5 ! IEU0
8634 2: call %l7 ! CTI Group brk forced
8635@@ -223,7 +223,7 @@ ret_sys_call:
8636
8637 cmp %o0, -ERESTART_RESTARTBLOCK
8638 bgeu,pn %xcc, 1f
8639- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8640+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8641 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8642
8643 2:
8644diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8645index 654e8aa..45f431b 100644
8646--- a/arch/sparc/kernel/sysfs.c
8647+++ b/arch/sparc/kernel/sysfs.c
8648@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8649 return NOTIFY_OK;
8650 }
8651
8652-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8653+static struct notifier_block sysfs_cpu_nb = {
8654 .notifier_call = sysfs_cpu_notify,
8655 };
8656
8657diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8658index 6629829..036032d 100644
8659--- a/arch/sparc/kernel/traps_32.c
8660+++ b/arch/sparc/kernel/traps_32.c
8661@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8662 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8663 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8664
8665+extern void gr_handle_kernel_exploit(void);
8666+
8667 void die_if_kernel(char *str, struct pt_regs *regs)
8668 {
8669 static int die_counter;
8670@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8671 count++ < 30 &&
8672 (((unsigned long) rw) >= PAGE_OFFSET) &&
8673 !(((unsigned long) rw) & 0x7)) {
8674- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8675+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8676 (void *) rw->ins[7]);
8677 rw = (struct reg_window32 *)rw->ins[6];
8678 }
8679 }
8680 printk("Instruction DUMP:");
8681 instruction_dump ((unsigned long *) regs->pc);
8682- if(regs->psr & PSR_PS)
8683+ if(regs->psr & PSR_PS) {
8684+ gr_handle_kernel_exploit();
8685 do_exit(SIGKILL);
8686+ }
8687 do_exit(SIGSEGV);
8688 }
8689
8690diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8691index b3f833a..ac74b2d 100644
8692--- a/arch/sparc/kernel/traps_64.c
8693+++ b/arch/sparc/kernel/traps_64.c
8694@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8695 i + 1,
8696 p->trapstack[i].tstate, p->trapstack[i].tpc,
8697 p->trapstack[i].tnpc, p->trapstack[i].tt);
8698- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8699+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8700 }
8701 }
8702
8703@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8704
8705 lvl -= 0x100;
8706 if (regs->tstate & TSTATE_PRIV) {
8707+
8708+#ifdef CONFIG_PAX_REFCOUNT
8709+ if (lvl == 6)
8710+ pax_report_refcount_overflow(regs);
8711+#endif
8712+
8713 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8714 die_if_kernel(buffer, regs);
8715 }
8716@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8717 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8718 {
8719 char buffer[32];
8720-
8721+
8722 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8723 0, lvl, SIGTRAP) == NOTIFY_STOP)
8724 return;
8725
8726+#ifdef CONFIG_PAX_REFCOUNT
8727+ if (lvl == 6)
8728+ pax_report_refcount_overflow(regs);
8729+#endif
8730+
8731 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8732
8733 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8734@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8735 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8736 printk("%s" "ERROR(%d): ",
8737 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8738- printk("TPC<%pS>\n", (void *) regs->tpc);
8739+ printk("TPC<%pA>\n", (void *) regs->tpc);
8740 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8741 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8742 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8743@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8744 smp_processor_id(),
8745 (type & 0x1) ? 'I' : 'D',
8746 regs->tpc);
8747- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8748+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8749 panic("Irrecoverable Cheetah+ parity error.");
8750 }
8751
8752@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8753 smp_processor_id(),
8754 (type & 0x1) ? 'I' : 'D',
8755 regs->tpc);
8756- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8757+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8758 }
8759
8760 struct sun4v_error_entry {
8761@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8762
8763 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8764 regs->tpc, tl);
8765- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8766+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8767 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8768- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8769+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8770 (void *) regs->u_regs[UREG_I7]);
8771 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8772 "pte[%lx] error[%lx]\n",
8773@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8774
8775 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8776 regs->tpc, tl);
8777- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8778+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8779 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8780- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8781+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8782 (void *) regs->u_regs[UREG_I7]);
8783 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8784 "pte[%lx] error[%lx]\n",
8785@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8786 fp = (unsigned long)sf->fp + STACK_BIAS;
8787 }
8788
8789- printk(" [%016lx] %pS\n", pc, (void *) pc);
8790+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8791 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8792 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8793 int index = tsk->curr_ret_stack;
8794 if (tsk->ret_stack && index >= graph) {
8795 pc = tsk->ret_stack[index - graph].ret;
8796- printk(" [%016lx] %pS\n", pc, (void *) pc);
8797+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8798 graph++;
8799 }
8800 }
8801@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8802 return (struct reg_window *) (fp + STACK_BIAS);
8803 }
8804
8805+extern void gr_handle_kernel_exploit(void);
8806+
8807 void die_if_kernel(char *str, struct pt_regs *regs)
8808 {
8809 static int die_counter;
8810@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8811 while (rw &&
8812 count++ < 30 &&
8813 kstack_valid(tp, (unsigned long) rw)) {
8814- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8815+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8816 (void *) rw->ins[7]);
8817
8818 rw = kernel_stack_up(rw);
8819@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8820 }
8821 user_instruction_dump ((unsigned int __user *) regs->tpc);
8822 }
8823- if (regs->tstate & TSTATE_PRIV)
8824+ if (regs->tstate & TSTATE_PRIV) {
8825+ gr_handle_kernel_exploit();
8826 do_exit(SIGKILL);
8827+ }
8828 do_exit(SIGSEGV);
8829 }
8830 EXPORT_SYMBOL(die_if_kernel);
8831diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8832index 8201c25e..072a2a7 100644
8833--- a/arch/sparc/kernel/unaligned_64.c
8834+++ b/arch/sparc/kernel/unaligned_64.c
8835@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8836 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8837
8838 if (__ratelimit(&ratelimit)) {
8839- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8840+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8841 regs->tpc, (void *) regs->tpc);
8842 }
8843 }
8844diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8845index dbe119b..089c7c1 100644
8846--- a/arch/sparc/lib/Makefile
8847+++ b/arch/sparc/lib/Makefile
8848@@ -2,7 +2,7 @@
8849 #
8850
8851 asflags-y := -ansi -DST_DIV0=0x02
8852-ccflags-y := -Werror
8853+#ccflags-y := -Werror
8854
8855 lib-$(CONFIG_SPARC32) += ashrdi3.o
8856 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8857diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8858index 85c233d..68500e0 100644
8859--- a/arch/sparc/lib/atomic_64.S
8860+++ b/arch/sparc/lib/atomic_64.S
8861@@ -17,7 +17,12 @@
8862 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8863 BACKOFF_SETUP(%o2)
8864 1: lduw [%o1], %g1
8865- add %g1, %o0, %g7
8866+ addcc %g1, %o0, %g7
8867+
8868+#ifdef CONFIG_PAX_REFCOUNT
8869+ tvs %icc, 6
8870+#endif
8871+
8872 cas [%o1], %g1, %g7
8873 cmp %g1, %g7
8874 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8875@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8876 2: BACKOFF_SPIN(%o2, %o3, 1b)
8877 ENDPROC(atomic_add)
8878
8879+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8880+ BACKOFF_SETUP(%o2)
8881+1: lduw [%o1], %g1
8882+ add %g1, %o0, %g7
8883+ cas [%o1], %g1, %g7
8884+ cmp %g1, %g7
8885+ bne,pn %icc, 2f
8886+ nop
8887+ retl
8888+ nop
8889+2: BACKOFF_SPIN(%o2, %o3, 1b)
8890+ENDPROC(atomic_add_unchecked)
8891+
8892 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8893 BACKOFF_SETUP(%o2)
8894 1: lduw [%o1], %g1
8895- sub %g1, %o0, %g7
8896+ subcc %g1, %o0, %g7
8897+
8898+#ifdef CONFIG_PAX_REFCOUNT
8899+ tvs %icc, 6
8900+#endif
8901+
8902 cas [%o1], %g1, %g7
8903 cmp %g1, %g7
8904 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8905@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8906 2: BACKOFF_SPIN(%o2, %o3, 1b)
8907 ENDPROC(atomic_sub)
8908
8909+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8910+ BACKOFF_SETUP(%o2)
8911+1: lduw [%o1], %g1
8912+ sub %g1, %o0, %g7
8913+ cas [%o1], %g1, %g7
8914+ cmp %g1, %g7
8915+ bne,pn %icc, 2f
8916+ nop
8917+ retl
8918+ nop
8919+2: BACKOFF_SPIN(%o2, %o3, 1b)
8920+ENDPROC(atomic_sub_unchecked)
8921+
8922 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8923 BACKOFF_SETUP(%o2)
8924 1: lduw [%o1], %g1
8925- add %g1, %o0, %g7
8926+ addcc %g1, %o0, %g7
8927+
8928+#ifdef CONFIG_PAX_REFCOUNT
8929+ tvs %icc, 6
8930+#endif
8931+
8932 cas [%o1], %g1, %g7
8933 cmp %g1, %g7
8934 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8935@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8936 2: BACKOFF_SPIN(%o2, %o3, 1b)
8937 ENDPROC(atomic_add_ret)
8938
8939+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8940+ BACKOFF_SETUP(%o2)
8941+1: lduw [%o1], %g1
8942+ addcc %g1, %o0, %g7
8943+ cas [%o1], %g1, %g7
8944+ cmp %g1, %g7
8945+ bne,pn %icc, 2f
8946+ add %g7, %o0, %g7
8947+ sra %g7, 0, %o0
8948+ retl
8949+ nop
8950+2: BACKOFF_SPIN(%o2, %o3, 1b)
8951+ENDPROC(atomic_add_ret_unchecked)
8952+
8953 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8954 BACKOFF_SETUP(%o2)
8955 1: lduw [%o1], %g1
8956- sub %g1, %o0, %g7
8957+ subcc %g1, %o0, %g7
8958+
8959+#ifdef CONFIG_PAX_REFCOUNT
8960+ tvs %icc, 6
8961+#endif
8962+
8963 cas [%o1], %g1, %g7
8964 cmp %g1, %g7
8965 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8966@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8967 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8968 BACKOFF_SETUP(%o2)
8969 1: ldx [%o1], %g1
8970- add %g1, %o0, %g7
8971+ addcc %g1, %o0, %g7
8972+
8973+#ifdef CONFIG_PAX_REFCOUNT
8974+ tvs %xcc, 6
8975+#endif
8976+
8977 casx [%o1], %g1, %g7
8978 cmp %g1, %g7
8979 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8980@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8981 2: BACKOFF_SPIN(%o2, %o3, 1b)
8982 ENDPROC(atomic64_add)
8983
8984+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8985+ BACKOFF_SETUP(%o2)
8986+1: ldx [%o1], %g1
8987+ addcc %g1, %o0, %g7
8988+ casx [%o1], %g1, %g7
8989+ cmp %g1, %g7
8990+ bne,pn %xcc, 2f
8991+ nop
8992+ retl
8993+ nop
8994+2: BACKOFF_SPIN(%o2, %o3, 1b)
8995+ENDPROC(atomic64_add_unchecked)
8996+
8997 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8998 BACKOFF_SETUP(%o2)
8999 1: ldx [%o1], %g1
9000- sub %g1, %o0, %g7
9001+ subcc %g1, %o0, %g7
9002+
9003+#ifdef CONFIG_PAX_REFCOUNT
9004+ tvs %xcc, 6
9005+#endif
9006+
9007 casx [%o1], %g1, %g7
9008 cmp %g1, %g7
9009 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9010@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9011 2: BACKOFF_SPIN(%o2, %o3, 1b)
9012 ENDPROC(atomic64_sub)
9013
9014+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9015+ BACKOFF_SETUP(%o2)
9016+1: ldx [%o1], %g1
9017+ subcc %g1, %o0, %g7
9018+ casx [%o1], %g1, %g7
9019+ cmp %g1, %g7
9020+ bne,pn %xcc, 2f
9021+ nop
9022+ retl
9023+ nop
9024+2: BACKOFF_SPIN(%o2, %o3, 1b)
9025+ENDPROC(atomic64_sub_unchecked)
9026+
9027 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9028 BACKOFF_SETUP(%o2)
9029 1: ldx [%o1], %g1
9030- add %g1, %o0, %g7
9031+ addcc %g1, %o0, %g7
9032+
9033+#ifdef CONFIG_PAX_REFCOUNT
9034+ tvs %xcc, 6
9035+#endif
9036+
9037 casx [%o1], %g1, %g7
9038 cmp %g1, %g7
9039 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9040@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9041 2: BACKOFF_SPIN(%o2, %o3, 1b)
9042 ENDPROC(atomic64_add_ret)
9043
9044+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9045+ BACKOFF_SETUP(%o2)
9046+1: ldx [%o1], %g1
9047+ addcc %g1, %o0, %g7
9048+ casx [%o1], %g1, %g7
9049+ cmp %g1, %g7
9050+ bne,pn %xcc, 2f
9051+ add %g7, %o0, %g7
9052+ mov %g7, %o0
9053+ retl
9054+ nop
9055+2: BACKOFF_SPIN(%o2, %o3, 1b)
9056+ENDPROC(atomic64_add_ret_unchecked)
9057+
9058 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9059 BACKOFF_SETUP(%o2)
9060 1: ldx [%o1], %g1
9061- sub %g1, %o0, %g7
9062+ subcc %g1, %o0, %g7
9063+
9064+#ifdef CONFIG_PAX_REFCOUNT
9065+ tvs %xcc, 6
9066+#endif
9067+
9068 casx [%o1], %g1, %g7
9069 cmp %g1, %g7
9070 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9071diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9072index 0c4e35e..745d3e4 100644
9073--- a/arch/sparc/lib/ksyms.c
9074+++ b/arch/sparc/lib/ksyms.c
9075@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9076
9077 /* Atomic counter implementation. */
9078 EXPORT_SYMBOL(atomic_add);
9079+EXPORT_SYMBOL(atomic_add_unchecked);
9080 EXPORT_SYMBOL(atomic_add_ret);
9081+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9082 EXPORT_SYMBOL(atomic_sub);
9083+EXPORT_SYMBOL(atomic_sub_unchecked);
9084 EXPORT_SYMBOL(atomic_sub_ret);
9085 EXPORT_SYMBOL(atomic64_add);
9086+EXPORT_SYMBOL(atomic64_add_unchecked);
9087 EXPORT_SYMBOL(atomic64_add_ret);
9088+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9089 EXPORT_SYMBOL(atomic64_sub);
9090+EXPORT_SYMBOL(atomic64_sub_unchecked);
9091 EXPORT_SYMBOL(atomic64_sub_ret);
9092 EXPORT_SYMBOL(atomic64_dec_if_positive);
9093
9094diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9095index 30c3ecc..736f015 100644
9096--- a/arch/sparc/mm/Makefile
9097+++ b/arch/sparc/mm/Makefile
9098@@ -2,7 +2,7 @@
9099 #
9100
9101 asflags-y := -ansi
9102-ccflags-y := -Werror
9103+#ccflags-y := -Werror
9104
9105 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9106 obj-y += fault_$(BITS).o
9107diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9108index e98bfda..ea8d221 100644
9109--- a/arch/sparc/mm/fault_32.c
9110+++ b/arch/sparc/mm/fault_32.c
9111@@ -21,6 +21,9 @@
9112 #include <linux/perf_event.h>
9113 #include <linux/interrupt.h>
9114 #include <linux/kdebug.h>
9115+#include <linux/slab.h>
9116+#include <linux/pagemap.h>
9117+#include <linux/compiler.h>
9118
9119 #include <asm/page.h>
9120 #include <asm/pgtable.h>
9121@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9122 return safe_compute_effective_address(regs, insn);
9123 }
9124
9125+#ifdef CONFIG_PAX_PAGEEXEC
9126+#ifdef CONFIG_PAX_DLRESOLVE
9127+static void pax_emuplt_close(struct vm_area_struct *vma)
9128+{
9129+ vma->vm_mm->call_dl_resolve = 0UL;
9130+}
9131+
9132+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9133+{
9134+ unsigned int *kaddr;
9135+
9136+ vmf->page = alloc_page(GFP_HIGHUSER);
9137+ if (!vmf->page)
9138+ return VM_FAULT_OOM;
9139+
9140+ kaddr = kmap(vmf->page);
9141+ memset(kaddr, 0, PAGE_SIZE);
9142+ kaddr[0] = 0x9DE3BFA8U; /* save */
9143+ flush_dcache_page(vmf->page);
9144+ kunmap(vmf->page);
9145+ return VM_FAULT_MAJOR;
9146+}
9147+
9148+static const struct vm_operations_struct pax_vm_ops = {
9149+ .close = pax_emuplt_close,
9150+ .fault = pax_emuplt_fault
9151+};
9152+
9153+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9154+{
9155+ int ret;
9156+
9157+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9158+ vma->vm_mm = current->mm;
9159+ vma->vm_start = addr;
9160+ vma->vm_end = addr + PAGE_SIZE;
9161+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9162+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9163+ vma->vm_ops = &pax_vm_ops;
9164+
9165+ ret = insert_vm_struct(current->mm, vma);
9166+ if (ret)
9167+ return ret;
9168+
9169+ ++current->mm->total_vm;
9170+ return 0;
9171+}
9172+#endif
9173+
9174+/*
9175+ * PaX: decide what to do with offenders (regs->pc = fault address)
9176+ *
9177+ * returns 1 when task should be killed
9178+ * 2 when patched PLT trampoline was detected
9179+ * 3 when unpatched PLT trampoline was detected
9180+ */
9181+static int pax_handle_fetch_fault(struct pt_regs *regs)
9182+{
9183+
9184+#ifdef CONFIG_PAX_EMUPLT
9185+ int err;
9186+
9187+ do { /* PaX: patched PLT emulation #1 */
9188+ unsigned int sethi1, sethi2, jmpl;
9189+
9190+ err = get_user(sethi1, (unsigned int *)regs->pc);
9191+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9192+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9193+
9194+ if (err)
9195+ break;
9196+
9197+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9198+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9199+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9200+ {
9201+ unsigned int addr;
9202+
9203+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9204+ addr = regs->u_regs[UREG_G1];
9205+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9206+ regs->pc = addr;
9207+ regs->npc = addr+4;
9208+ return 2;
9209+ }
9210+ } while (0);
9211+
9212+ do { /* PaX: patched PLT emulation #2 */
9213+ unsigned int ba;
9214+
9215+ err = get_user(ba, (unsigned int *)regs->pc);
9216+
9217+ if (err)
9218+ break;
9219+
9220+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9221+ unsigned int addr;
9222+
9223+ if ((ba & 0xFFC00000U) == 0x30800000U)
9224+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9225+ else
9226+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9227+ regs->pc = addr;
9228+ regs->npc = addr+4;
9229+ return 2;
9230+ }
9231+ } while (0);
9232+
9233+ do { /* PaX: patched PLT emulation #3 */
9234+ unsigned int sethi, bajmpl, nop;
9235+
9236+ err = get_user(sethi, (unsigned int *)regs->pc);
9237+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9238+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9239+
9240+ if (err)
9241+ break;
9242+
9243+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9244+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9245+ nop == 0x01000000U)
9246+ {
9247+ unsigned int addr;
9248+
9249+ addr = (sethi & 0x003FFFFFU) << 10;
9250+ regs->u_regs[UREG_G1] = addr;
9251+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9252+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9253+ else
9254+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9255+ regs->pc = addr;
9256+ regs->npc = addr+4;
9257+ return 2;
9258+ }
9259+ } while (0);
9260+
9261+ do { /* PaX: unpatched PLT emulation step 1 */
9262+ unsigned int sethi, ba, nop;
9263+
9264+ err = get_user(sethi, (unsigned int *)regs->pc);
9265+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9266+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9267+
9268+ if (err)
9269+ break;
9270+
9271+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9272+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9273+ nop == 0x01000000U)
9274+ {
9275+ unsigned int addr, save, call;
9276+
9277+ if ((ba & 0xFFC00000U) == 0x30800000U)
9278+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9279+ else
9280+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9281+
9282+ err = get_user(save, (unsigned int *)addr);
9283+ err |= get_user(call, (unsigned int *)(addr+4));
9284+ err |= get_user(nop, (unsigned int *)(addr+8));
9285+ if (err)
9286+ break;
9287+
9288+#ifdef CONFIG_PAX_DLRESOLVE
9289+ if (save == 0x9DE3BFA8U &&
9290+ (call & 0xC0000000U) == 0x40000000U &&
9291+ nop == 0x01000000U)
9292+ {
9293+ struct vm_area_struct *vma;
9294+ unsigned long call_dl_resolve;
9295+
9296+ down_read(&current->mm->mmap_sem);
9297+ call_dl_resolve = current->mm->call_dl_resolve;
9298+ up_read(&current->mm->mmap_sem);
9299+ if (likely(call_dl_resolve))
9300+ goto emulate;
9301+
9302+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9303+
9304+ down_write(&current->mm->mmap_sem);
9305+ if (current->mm->call_dl_resolve) {
9306+ call_dl_resolve = current->mm->call_dl_resolve;
9307+ up_write(&current->mm->mmap_sem);
9308+ if (vma)
9309+ kmem_cache_free(vm_area_cachep, vma);
9310+ goto emulate;
9311+ }
9312+
9313+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9314+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9315+ up_write(&current->mm->mmap_sem);
9316+ if (vma)
9317+ kmem_cache_free(vm_area_cachep, vma);
9318+ return 1;
9319+ }
9320+
9321+ if (pax_insert_vma(vma, call_dl_resolve)) {
9322+ up_write(&current->mm->mmap_sem);
9323+ kmem_cache_free(vm_area_cachep, vma);
9324+ return 1;
9325+ }
9326+
9327+ current->mm->call_dl_resolve = call_dl_resolve;
9328+ up_write(&current->mm->mmap_sem);
9329+
9330+emulate:
9331+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9332+ regs->pc = call_dl_resolve;
9333+ regs->npc = addr+4;
9334+ return 3;
9335+ }
9336+#endif
9337+
9338+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9339+ if ((save & 0xFFC00000U) == 0x05000000U &&
9340+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9341+ nop == 0x01000000U)
9342+ {
9343+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9344+ regs->u_regs[UREG_G2] = addr + 4;
9345+ addr = (save & 0x003FFFFFU) << 10;
9346+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9347+ regs->pc = addr;
9348+ regs->npc = addr+4;
9349+ return 3;
9350+ }
9351+ }
9352+ } while (0);
9353+
9354+ do { /* PaX: unpatched PLT emulation step 2 */
9355+ unsigned int save, call, nop;
9356+
9357+ err = get_user(save, (unsigned int *)(regs->pc-4));
9358+ err |= get_user(call, (unsigned int *)regs->pc);
9359+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9360+ if (err)
9361+ break;
9362+
9363+ if (save == 0x9DE3BFA8U &&
9364+ (call & 0xC0000000U) == 0x40000000U &&
9365+ nop == 0x01000000U)
9366+ {
9367+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9368+
9369+ regs->u_regs[UREG_RETPC] = regs->pc;
9370+ regs->pc = dl_resolve;
9371+ regs->npc = dl_resolve+4;
9372+ return 3;
9373+ }
9374+ } while (0);
9375+#endif
9376+
9377+ return 1;
9378+}
9379+
9380+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9381+{
9382+ unsigned long i;
9383+
9384+ printk(KERN_ERR "PAX: bytes at PC: ");
9385+ for (i = 0; i < 8; i++) {
9386+ unsigned int c;
9387+ if (get_user(c, (unsigned int *)pc+i))
9388+ printk(KERN_CONT "???????? ");
9389+ else
9390+ printk(KERN_CONT "%08x ", c);
9391+ }
9392+ printk("\n");
9393+}
9394+#endif
9395+
9396 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9397 int text_fault)
9398 {
9399@@ -230,6 +504,24 @@ good_area:
9400 if (!(vma->vm_flags & VM_WRITE))
9401 goto bad_area;
9402 } else {
9403+
9404+#ifdef CONFIG_PAX_PAGEEXEC
9405+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9406+ up_read(&mm->mmap_sem);
9407+ switch (pax_handle_fetch_fault(regs)) {
9408+
9409+#ifdef CONFIG_PAX_EMUPLT
9410+ case 2:
9411+ case 3:
9412+ return;
9413+#endif
9414+
9415+ }
9416+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9417+ do_group_exit(SIGKILL);
9418+ }
9419+#endif
9420+
9421 /* Allow reads even for write-only mappings */
9422 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9423 goto bad_area;
9424diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9425index 5062ff3..e0b75f3 100644
9426--- a/arch/sparc/mm/fault_64.c
9427+++ b/arch/sparc/mm/fault_64.c
9428@@ -21,6 +21,9 @@
9429 #include <linux/kprobes.h>
9430 #include <linux/kdebug.h>
9431 #include <linux/percpu.h>
9432+#include <linux/slab.h>
9433+#include <linux/pagemap.h>
9434+#include <linux/compiler.h>
9435
9436 #include <asm/page.h>
9437 #include <asm/pgtable.h>
9438@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9439 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9440 regs->tpc);
9441 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9442- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9443+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9444 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9445 dump_stack();
9446 unhandled_fault(regs->tpc, current, regs);
9447@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9448 show_regs(regs);
9449 }
9450
9451+#ifdef CONFIG_PAX_PAGEEXEC
9452+#ifdef CONFIG_PAX_DLRESOLVE
9453+static void pax_emuplt_close(struct vm_area_struct *vma)
9454+{
9455+ vma->vm_mm->call_dl_resolve = 0UL;
9456+}
9457+
9458+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9459+{
9460+ unsigned int *kaddr;
9461+
9462+ vmf->page = alloc_page(GFP_HIGHUSER);
9463+ if (!vmf->page)
9464+ return VM_FAULT_OOM;
9465+
9466+ kaddr = kmap(vmf->page);
9467+ memset(kaddr, 0, PAGE_SIZE);
9468+ kaddr[0] = 0x9DE3BFA8U; /* save */
9469+ flush_dcache_page(vmf->page);
9470+ kunmap(vmf->page);
9471+ return VM_FAULT_MAJOR;
9472+}
9473+
9474+static const struct vm_operations_struct pax_vm_ops = {
9475+ .close = pax_emuplt_close,
9476+ .fault = pax_emuplt_fault
9477+};
9478+
9479+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9480+{
9481+ int ret;
9482+
9483+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9484+ vma->vm_mm = current->mm;
9485+ vma->vm_start = addr;
9486+ vma->vm_end = addr + PAGE_SIZE;
9487+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9488+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9489+ vma->vm_ops = &pax_vm_ops;
9490+
9491+ ret = insert_vm_struct(current->mm, vma);
9492+ if (ret)
9493+ return ret;
9494+
9495+ ++current->mm->total_vm;
9496+ return 0;
9497+}
9498+#endif
9499+
9500+/*
9501+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9502+ *
9503+ * returns 1 when task should be killed
9504+ * 2 when patched PLT trampoline was detected
9505+ * 3 when unpatched PLT trampoline was detected
9506+ */
9507+static int pax_handle_fetch_fault(struct pt_regs *regs)
9508+{
9509+
9510+#ifdef CONFIG_PAX_EMUPLT
9511+ int err;
9512+
9513+ do { /* PaX: patched PLT emulation #1 */
9514+ unsigned int sethi1, sethi2, jmpl;
9515+
9516+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9517+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9518+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9519+
9520+ if (err)
9521+ break;
9522+
9523+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9524+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9525+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9526+ {
9527+ unsigned long addr;
9528+
9529+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9530+ addr = regs->u_regs[UREG_G1];
9531+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9532+
9533+ if (test_thread_flag(TIF_32BIT))
9534+ addr &= 0xFFFFFFFFUL;
9535+
9536+ regs->tpc = addr;
9537+ regs->tnpc = addr+4;
9538+ return 2;
9539+ }
9540+ } while (0);
9541+
9542+ do { /* PaX: patched PLT emulation #2 */
9543+ unsigned int ba;
9544+
9545+ err = get_user(ba, (unsigned int *)regs->tpc);
9546+
9547+ if (err)
9548+ break;
9549+
9550+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9551+ unsigned long addr;
9552+
9553+ if ((ba & 0xFFC00000U) == 0x30800000U)
9554+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9555+ else
9556+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9557+
9558+ if (test_thread_flag(TIF_32BIT))
9559+ addr &= 0xFFFFFFFFUL;
9560+
9561+ regs->tpc = addr;
9562+ regs->tnpc = addr+4;
9563+ return 2;
9564+ }
9565+ } while (0);
9566+
9567+ do { /* PaX: patched PLT emulation #3 */
9568+ unsigned int sethi, bajmpl, nop;
9569+
9570+ err = get_user(sethi, (unsigned int *)regs->tpc);
9571+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9572+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9573+
9574+ if (err)
9575+ break;
9576+
9577+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9578+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9579+ nop == 0x01000000U)
9580+ {
9581+ unsigned long addr;
9582+
9583+ addr = (sethi & 0x003FFFFFU) << 10;
9584+ regs->u_regs[UREG_G1] = addr;
9585+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9586+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9587+ else
9588+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9589+
9590+ if (test_thread_flag(TIF_32BIT))
9591+ addr &= 0xFFFFFFFFUL;
9592+
9593+ regs->tpc = addr;
9594+ regs->tnpc = addr+4;
9595+ return 2;
9596+ }
9597+ } while (0);
9598+
9599+ do { /* PaX: patched PLT emulation #4 */
9600+ unsigned int sethi, mov1, call, mov2;
9601+
9602+ err = get_user(sethi, (unsigned int *)regs->tpc);
9603+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9604+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9605+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9606+
9607+ if (err)
9608+ break;
9609+
9610+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9611+ mov1 == 0x8210000FU &&
9612+ (call & 0xC0000000U) == 0x40000000U &&
9613+ mov2 == 0x9E100001U)
9614+ {
9615+ unsigned long addr;
9616+
9617+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9618+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9619+
9620+ if (test_thread_flag(TIF_32BIT))
9621+ addr &= 0xFFFFFFFFUL;
9622+
9623+ regs->tpc = addr;
9624+ regs->tnpc = addr+4;
9625+ return 2;
9626+ }
9627+ } while (0);
9628+
9629+ do { /* PaX: patched PLT emulation #5 */
9630+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9631+
9632+ err = get_user(sethi, (unsigned int *)regs->tpc);
9633+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9634+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9635+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9636+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9637+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9638+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9639+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9640+
9641+ if (err)
9642+ break;
9643+
9644+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9645+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9646+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9647+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9648+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9649+ sllx == 0x83287020U &&
9650+ jmpl == 0x81C04005U &&
9651+ nop == 0x01000000U)
9652+ {
9653+ unsigned long addr;
9654+
9655+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9656+ regs->u_regs[UREG_G1] <<= 32;
9657+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9658+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9659+ regs->tpc = addr;
9660+ regs->tnpc = addr+4;
9661+ return 2;
9662+ }
9663+ } while (0);
9664+
9665+ do { /* PaX: patched PLT emulation #6 */
9666+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9667+
9668+ err = get_user(sethi, (unsigned int *)regs->tpc);
9669+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9670+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9671+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9672+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9673+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9674+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9675+
9676+ if (err)
9677+ break;
9678+
9679+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9680+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9681+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9682+ sllx == 0x83287020U &&
9683+ (or & 0xFFFFE000U) == 0x8A116000U &&
9684+ jmpl == 0x81C04005U &&
9685+ nop == 0x01000000U)
9686+ {
9687+ unsigned long addr;
9688+
9689+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9690+ regs->u_regs[UREG_G1] <<= 32;
9691+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9692+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9693+ regs->tpc = addr;
9694+ regs->tnpc = addr+4;
9695+ return 2;
9696+ }
9697+ } while (0);
9698+
9699+ do { /* PaX: unpatched PLT emulation step 1 */
9700+ unsigned int sethi, ba, nop;
9701+
9702+ err = get_user(sethi, (unsigned int *)regs->tpc);
9703+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9704+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9705+
9706+ if (err)
9707+ break;
9708+
9709+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9710+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9711+ nop == 0x01000000U)
9712+ {
9713+ unsigned long addr;
9714+ unsigned int save, call;
9715+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9716+
9717+ if ((ba & 0xFFC00000U) == 0x30800000U)
9718+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9719+ else
9720+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9721+
9722+ if (test_thread_flag(TIF_32BIT))
9723+ addr &= 0xFFFFFFFFUL;
9724+
9725+ err = get_user(save, (unsigned int *)addr);
9726+ err |= get_user(call, (unsigned int *)(addr+4));
9727+ err |= get_user(nop, (unsigned int *)(addr+8));
9728+ if (err)
9729+ break;
9730+
9731+#ifdef CONFIG_PAX_DLRESOLVE
9732+ if (save == 0x9DE3BFA8U &&
9733+ (call & 0xC0000000U) == 0x40000000U &&
9734+ nop == 0x01000000U)
9735+ {
9736+ struct vm_area_struct *vma;
9737+ unsigned long call_dl_resolve;
9738+
9739+ down_read(&current->mm->mmap_sem);
9740+ call_dl_resolve = current->mm->call_dl_resolve;
9741+ up_read(&current->mm->mmap_sem);
9742+ if (likely(call_dl_resolve))
9743+ goto emulate;
9744+
9745+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9746+
9747+ down_write(&current->mm->mmap_sem);
9748+ if (current->mm->call_dl_resolve) {
9749+ call_dl_resolve = current->mm->call_dl_resolve;
9750+ up_write(&current->mm->mmap_sem);
9751+ if (vma)
9752+ kmem_cache_free(vm_area_cachep, vma);
9753+ goto emulate;
9754+ }
9755+
9756+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9757+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9758+ up_write(&current->mm->mmap_sem);
9759+ if (vma)
9760+ kmem_cache_free(vm_area_cachep, vma);
9761+ return 1;
9762+ }
9763+
9764+ if (pax_insert_vma(vma, call_dl_resolve)) {
9765+ up_write(&current->mm->mmap_sem);
9766+ kmem_cache_free(vm_area_cachep, vma);
9767+ return 1;
9768+ }
9769+
9770+ current->mm->call_dl_resolve = call_dl_resolve;
9771+ up_write(&current->mm->mmap_sem);
9772+
9773+emulate:
9774+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9775+ regs->tpc = call_dl_resolve;
9776+ regs->tnpc = addr+4;
9777+ return 3;
9778+ }
9779+#endif
9780+
9781+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9782+ if ((save & 0xFFC00000U) == 0x05000000U &&
9783+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9784+ nop == 0x01000000U)
9785+ {
9786+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9787+ regs->u_regs[UREG_G2] = addr + 4;
9788+ addr = (save & 0x003FFFFFU) << 10;
9789+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9790+
9791+ if (test_thread_flag(TIF_32BIT))
9792+ addr &= 0xFFFFFFFFUL;
9793+
9794+ regs->tpc = addr;
9795+ regs->tnpc = addr+4;
9796+ return 3;
9797+ }
9798+
9799+ /* PaX: 64-bit PLT stub */
9800+ err = get_user(sethi1, (unsigned int *)addr);
9801+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9802+ err |= get_user(or1, (unsigned int *)(addr+8));
9803+ err |= get_user(or2, (unsigned int *)(addr+12));
9804+ err |= get_user(sllx, (unsigned int *)(addr+16));
9805+ err |= get_user(add, (unsigned int *)(addr+20));
9806+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9807+ err |= get_user(nop, (unsigned int *)(addr+28));
9808+ if (err)
9809+ break;
9810+
9811+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9812+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9813+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9814+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9815+ sllx == 0x89293020U &&
9816+ add == 0x8A010005U &&
9817+ jmpl == 0x89C14000U &&
9818+ nop == 0x01000000U)
9819+ {
9820+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9821+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9822+ regs->u_regs[UREG_G4] <<= 32;
9823+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9824+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9825+ regs->u_regs[UREG_G4] = addr + 24;
9826+ addr = regs->u_regs[UREG_G5];
9827+ regs->tpc = addr;
9828+ regs->tnpc = addr+4;
9829+ return 3;
9830+ }
9831+ }
9832+ } while (0);
9833+
9834+#ifdef CONFIG_PAX_DLRESOLVE
9835+ do { /* PaX: unpatched PLT emulation step 2 */
9836+ unsigned int save, call, nop;
9837+
9838+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9839+ err |= get_user(call, (unsigned int *)regs->tpc);
9840+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9841+ if (err)
9842+ break;
9843+
9844+ if (save == 0x9DE3BFA8U &&
9845+ (call & 0xC0000000U) == 0x40000000U &&
9846+ nop == 0x01000000U)
9847+ {
9848+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9849+
9850+ if (test_thread_flag(TIF_32BIT))
9851+ dl_resolve &= 0xFFFFFFFFUL;
9852+
9853+ regs->u_regs[UREG_RETPC] = regs->tpc;
9854+ regs->tpc = dl_resolve;
9855+ regs->tnpc = dl_resolve+4;
9856+ return 3;
9857+ }
9858+ } while (0);
9859+#endif
9860+
9861+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9862+ unsigned int sethi, ba, nop;
9863+
9864+ err = get_user(sethi, (unsigned int *)regs->tpc);
9865+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9866+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9867+
9868+ if (err)
9869+ break;
9870+
9871+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9872+ (ba & 0xFFF00000U) == 0x30600000U &&
9873+ nop == 0x01000000U)
9874+ {
9875+ unsigned long addr;
9876+
9877+ addr = (sethi & 0x003FFFFFU) << 10;
9878+ regs->u_regs[UREG_G1] = addr;
9879+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9880+
9881+ if (test_thread_flag(TIF_32BIT))
9882+ addr &= 0xFFFFFFFFUL;
9883+
9884+ regs->tpc = addr;
9885+ regs->tnpc = addr+4;
9886+ return 2;
9887+ }
9888+ } while (0);
9889+
9890+#endif
9891+
9892+ return 1;
9893+}
9894+
9895+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9896+{
9897+ unsigned long i;
9898+
9899+ printk(KERN_ERR "PAX: bytes at PC: ");
9900+ for (i = 0; i < 8; i++) {
9901+ unsigned int c;
9902+ if (get_user(c, (unsigned int *)pc+i))
9903+ printk(KERN_CONT "???????? ");
9904+ else
9905+ printk(KERN_CONT "%08x ", c);
9906+ }
9907+ printk("\n");
9908+}
9909+#endif
9910+
9911 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9912 {
9913 struct mm_struct *mm = current->mm;
9914@@ -341,6 +804,29 @@ retry:
9915 if (!vma)
9916 goto bad_area;
9917
9918+#ifdef CONFIG_PAX_PAGEEXEC
9919+ /* PaX: detect ITLB misses on non-exec pages */
9920+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9921+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9922+ {
9923+ if (address != regs->tpc)
9924+ goto good_area;
9925+
9926+ up_read(&mm->mmap_sem);
9927+ switch (pax_handle_fetch_fault(regs)) {
9928+
9929+#ifdef CONFIG_PAX_EMUPLT
9930+ case 2:
9931+ case 3:
9932+ return;
9933+#endif
9934+
9935+ }
9936+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9937+ do_group_exit(SIGKILL);
9938+ }
9939+#endif
9940+
9941 /* Pure DTLB misses do not tell us whether the fault causing
9942 * load/store/atomic was a write or not, it only says that there
9943 * was no match. So in such a case we (carefully) read the
9944diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9945index d2b5944..bd813f2 100644
9946--- a/arch/sparc/mm/hugetlbpage.c
9947+++ b/arch/sparc/mm/hugetlbpage.c
9948@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9949
9950 info.flags = 0;
9951 info.length = len;
9952- info.low_limit = TASK_UNMAPPED_BASE;
9953+ info.low_limit = mm->mmap_base;
9954 info.high_limit = min(task_size, VA_EXCLUDE_START);
9955 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9956 info.align_offset = 0;
9957@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9958 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9959 VM_BUG_ON(addr != -ENOMEM);
9960 info.low_limit = VA_EXCLUDE_END;
9961+
9962+#ifdef CONFIG_PAX_RANDMMAP
9963+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9964+ info.low_limit += mm->delta_mmap;
9965+#endif
9966+
9967 info.high_limit = task_size;
9968 addr = vm_unmapped_area(&info);
9969 }
9970@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9971 VM_BUG_ON(addr != -ENOMEM);
9972 info.flags = 0;
9973 info.low_limit = TASK_UNMAPPED_BASE;
9974+
9975+#ifdef CONFIG_PAX_RANDMMAP
9976+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9977+ info.low_limit += mm->delta_mmap;
9978+#endif
9979+
9980 info.high_limit = STACK_TOP32;
9981 addr = vm_unmapped_area(&info);
9982 }
9983@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9984 struct mm_struct *mm = current->mm;
9985 struct vm_area_struct *vma;
9986 unsigned long task_size = TASK_SIZE;
9987+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9988
9989 if (test_thread_flag(TIF_32BIT))
9990 task_size = STACK_TOP32;
9991@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9992 return addr;
9993 }
9994
9995+#ifdef CONFIG_PAX_RANDMMAP
9996+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9997+#endif
9998+
9999 if (addr) {
10000 addr = ALIGN(addr, HPAGE_SIZE);
10001 vma = find_vma(mm, addr);
10002- if (task_size - len >= addr &&
10003- (!vma || addr + len <= vma->vm_start))
10004+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10005 return addr;
10006 }
10007 if (mm->get_unmapped_area == arch_get_unmapped_area)
10008diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
10009index f4500c6..889656c 100644
10010--- a/arch/tile/include/asm/atomic_64.h
10011+++ b/arch/tile/include/asm/atomic_64.h
10012@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10013
10014 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10015
10016+#define atomic64_read_unchecked(v) atomic64_read(v)
10017+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10018+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10019+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10020+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10021+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10022+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10023+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10024+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10025+
10026 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
10027 #define smp_mb__before_atomic_dec() smp_mb()
10028 #define smp_mb__after_atomic_dec() smp_mb()
10029diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
10030index a9a5299..0fce79e 100644
10031--- a/arch/tile/include/asm/cache.h
10032+++ b/arch/tile/include/asm/cache.h
10033@@ -15,11 +15,12 @@
10034 #ifndef _ASM_TILE_CACHE_H
10035 #define _ASM_TILE_CACHE_H
10036
10037+#include <linux/const.h>
10038 #include <arch/chip.h>
10039
10040 /* bytes per L1 data cache line */
10041 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10042-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10043+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10044
10045 /* bytes per L2 cache line */
10046 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10047diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10048index 8a082bc..7a6bf87 100644
10049--- a/arch/tile/include/asm/uaccess.h
10050+++ b/arch/tile/include/asm/uaccess.h
10051@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10052 const void __user *from,
10053 unsigned long n)
10054 {
10055- int sz = __compiletime_object_size(to);
10056+ size_t sz = __compiletime_object_size(to);
10057
10058- if (likely(sz == -1 || sz >= n))
10059+ if (likely(sz == (size_t)-1 || sz >= n))
10060 n = _copy_from_user(to, from, n);
10061 else
10062 copy_from_user_overflow();
10063diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
10064index 650ccff..45fe2d6 100644
10065--- a/arch/tile/mm/hugetlbpage.c
10066+++ b/arch/tile/mm/hugetlbpage.c
10067@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
10068 info.high_limit = TASK_SIZE;
10069 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10070 info.align_offset = 0;
10071+ info.threadstack_offset = 0;
10072 return vm_unmapped_area(&info);
10073 }
10074
10075@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
10076 info.high_limit = current->mm->mmap_base;
10077 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10078 info.align_offset = 0;
10079+ info.threadstack_offset = 0;
10080 addr = vm_unmapped_area(&info);
10081
10082 /*
10083diff --git a/arch/um/Makefile b/arch/um/Makefile
10084index 133f7de..1d6f2f1 100644
10085--- a/arch/um/Makefile
10086+++ b/arch/um/Makefile
10087@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10088 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10089 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10090
10091+ifdef CONSTIFY_PLUGIN
10092+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10093+endif
10094+
10095 #This will adjust *FLAGS accordingly to the platform.
10096 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10097
10098diff --git a/arch/um/defconfig b/arch/um/defconfig
10099index 08107a7..ab22afe 100644
10100--- a/arch/um/defconfig
10101+++ b/arch/um/defconfig
10102@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
10103 CONFIG_X86_L1_CACHE_SHIFT=5
10104 CONFIG_X86_XADD=y
10105 CONFIG_X86_PPRO_FENCE=y
10106-CONFIG_X86_WP_WORKS_OK=y
10107 CONFIG_X86_INVLPG=y
10108 CONFIG_X86_BSWAP=y
10109 CONFIG_X86_POPAD_OK=y
10110diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10111index 19e1bdd..3665b77 100644
10112--- a/arch/um/include/asm/cache.h
10113+++ b/arch/um/include/asm/cache.h
10114@@ -1,6 +1,7 @@
10115 #ifndef __UM_CACHE_H
10116 #define __UM_CACHE_H
10117
10118+#include <linux/const.h>
10119
10120 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10121 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10122@@ -12,6 +13,6 @@
10123 # define L1_CACHE_SHIFT 5
10124 #endif
10125
10126-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10127+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10128
10129 #endif
10130diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10131index 2e0a6b1..a64d0f5 100644
10132--- a/arch/um/include/asm/kmap_types.h
10133+++ b/arch/um/include/asm/kmap_types.h
10134@@ -8,6 +8,6 @@
10135
10136 /* No more #include "asm/arch/kmap_types.h" ! */
10137
10138-#define KM_TYPE_NR 14
10139+#define KM_TYPE_NR 15
10140
10141 #endif
10142diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10143index 5ff53d9..5850cdf 100644
10144--- a/arch/um/include/asm/page.h
10145+++ b/arch/um/include/asm/page.h
10146@@ -14,6 +14,9 @@
10147 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10148 #define PAGE_MASK (~(PAGE_SIZE-1))
10149
10150+#define ktla_ktva(addr) (addr)
10151+#define ktva_ktla(addr) (addr)
10152+
10153 #ifndef __ASSEMBLY__
10154
10155 struct page;
10156diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10157index 0032f92..cd151e0 100644
10158--- a/arch/um/include/asm/pgtable-3level.h
10159+++ b/arch/um/include/asm/pgtable-3level.h
10160@@ -58,6 +58,7 @@
10161 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10162 #define pud_populate(mm, pud, pmd) \
10163 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10164+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10165
10166 #ifdef CONFIG_64BIT
10167 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10168diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10169index bbcef52..6a2a483 100644
10170--- a/arch/um/kernel/process.c
10171+++ b/arch/um/kernel/process.c
10172@@ -367,22 +367,6 @@ int singlestepping(void * t)
10173 return 2;
10174 }
10175
10176-/*
10177- * Only x86 and x86_64 have an arch_align_stack().
10178- * All other arches have "#define arch_align_stack(x) (x)"
10179- * in their asm/system.h
10180- * As this is included in UML from asm-um/system-generic.h,
10181- * we can use it to behave as the subarch does.
10182- */
10183-#ifndef arch_align_stack
10184-unsigned long arch_align_stack(unsigned long sp)
10185-{
10186- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10187- sp -= get_random_int() % 8192;
10188- return sp & ~0xf;
10189-}
10190-#endif
10191-
10192 unsigned long get_wchan(struct task_struct *p)
10193 {
10194 unsigned long stack_page, sp, ip;
10195diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10196index ad8f795..2c7eec6 100644
10197--- a/arch/unicore32/include/asm/cache.h
10198+++ b/arch/unicore32/include/asm/cache.h
10199@@ -12,8 +12,10 @@
10200 #ifndef __UNICORE_CACHE_H__
10201 #define __UNICORE_CACHE_H__
10202
10203-#define L1_CACHE_SHIFT (5)
10204-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10205+#include <linux/const.h>
10206+
10207+#define L1_CACHE_SHIFT 5
10208+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10209
10210 /*
10211 * Memory returned by kmalloc() may be used for DMA, so we must make
10212diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10213index fe120da..24177f7 100644
10214--- a/arch/x86/Kconfig
10215+++ b/arch/x86/Kconfig
10216@@ -239,7 +239,7 @@ config X86_HT
10217
10218 config X86_32_LAZY_GS
10219 def_bool y
10220- depends on X86_32 && !CC_STACKPROTECTOR
10221+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10222
10223 config ARCH_HWEIGHT_CFLAGS
10224 string
10225@@ -1073,6 +1073,7 @@ config MICROCODE_EARLY
10226
10227 config X86_MSR
10228 tristate "/dev/cpu/*/msr - Model-specific register support"
10229+ depends on !GRKERNSEC_KMEM
10230 ---help---
10231 This device gives privileged processes access to the x86
10232 Model-Specific Registers (MSRs). It is a character device with
10233@@ -1096,7 +1097,7 @@ choice
10234
10235 config NOHIGHMEM
10236 bool "off"
10237- depends on !X86_NUMAQ
10238+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10239 ---help---
10240 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10241 However, the address space of 32-bit x86 processors is only 4
10242@@ -1133,7 +1134,7 @@ config NOHIGHMEM
10243
10244 config HIGHMEM4G
10245 bool "4GB"
10246- depends on !X86_NUMAQ
10247+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10248 ---help---
10249 Select this if you have a 32-bit processor and between 1 and 4
10250 gigabytes of physical RAM.
10251@@ -1186,7 +1187,7 @@ config PAGE_OFFSET
10252 hex
10253 default 0xB0000000 if VMSPLIT_3G_OPT
10254 default 0x80000000 if VMSPLIT_2G
10255- default 0x78000000 if VMSPLIT_2G_OPT
10256+ default 0x70000000 if VMSPLIT_2G_OPT
10257 default 0x40000000 if VMSPLIT_1G
10258 default 0xC0000000
10259 depends on X86_32
10260@@ -1584,6 +1585,7 @@ config SECCOMP
10261
10262 config CC_STACKPROTECTOR
10263 bool "Enable -fstack-protector buffer overflow detection"
10264+ depends on X86_64 || !PAX_MEMORY_UDEREF
10265 ---help---
10266 This option turns on the -fstack-protector GCC feature. This
10267 feature puts, at the beginning of functions, a canary value on
10268@@ -1703,6 +1705,8 @@ config X86_NEED_RELOCS
10269 config PHYSICAL_ALIGN
10270 hex "Alignment value to which kernel should be aligned" if X86_32
10271 default "0x1000000"
10272+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
10273+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
10274 range 0x2000 0x1000000
10275 ---help---
10276 This value puts the alignment restrictions on physical address
10277@@ -1778,9 +1782,10 @@ config DEBUG_HOTPLUG_CPU0
10278 If unsure, say N.
10279
10280 config COMPAT_VDSO
10281- def_bool y
10282+ def_bool n
10283 prompt "Compat VDSO support"
10284 depends on X86_32 || IA32_EMULATION
10285+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10286 ---help---
10287 Map the 32-bit VDSO to the predictable old-style address too.
10288
10289diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10290index c026cca..14657ae 100644
10291--- a/arch/x86/Kconfig.cpu
10292+++ b/arch/x86/Kconfig.cpu
10293@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10294
10295 config X86_F00F_BUG
10296 def_bool y
10297- depends on M586MMX || M586TSC || M586 || M486
10298+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10299
10300 config X86_INVD_BUG
10301 def_bool y
10302@@ -327,7 +327,7 @@ config X86_INVD_BUG
10303
10304 config X86_ALIGNMENT_16
10305 def_bool y
10306- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10307+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10308
10309 config X86_INTEL_USERCOPY
10310 def_bool y
10311@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10312 # generates cmov.
10313 config X86_CMOV
10314 def_bool y
10315- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10316+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10317
10318 config X86_MINIMUM_CPU_FAMILY
10319 int
10320diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10321index c198b7e..63eea60 100644
10322--- a/arch/x86/Kconfig.debug
10323+++ b/arch/x86/Kconfig.debug
10324@@ -84,7 +84,7 @@ config X86_PTDUMP
10325 config DEBUG_RODATA
10326 bool "Write protect kernel read-only data structures"
10327 default y
10328- depends on DEBUG_KERNEL
10329+ depends on DEBUG_KERNEL && BROKEN
10330 ---help---
10331 Mark the kernel read-only data as write-protected in the pagetables,
10332 in order to catch accidental (and incorrect) writes to such const
10333@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10334
10335 config DEBUG_SET_MODULE_RONX
10336 bool "Set loadable kernel module data as NX and text as RO"
10337- depends on MODULES
10338+ depends on MODULES && BROKEN
10339 ---help---
10340 This option helps catch unintended modifications to loadable
10341 kernel module's text and read-only data. It also prevents execution
10342diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10343index 5c47726..8c4fa67 100644
10344--- a/arch/x86/Makefile
10345+++ b/arch/x86/Makefile
10346@@ -54,6 +54,7 @@ else
10347 UTS_MACHINE := x86_64
10348 CHECKFLAGS += -D__x86_64__ -m64
10349
10350+ biarch := $(call cc-option,-m64)
10351 KBUILD_AFLAGS += -m64
10352 KBUILD_CFLAGS += -m64
10353
10354@@ -234,3 +235,12 @@ define archhelp
10355 echo ' FDARGS="..." arguments for the booted kernel'
10356 echo ' FDINITRD=file initrd for the booted kernel'
10357 endef
10358+
10359+define OLD_LD
10360+
10361+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10362+*** Please upgrade your binutils to 2.18 or newer
10363+endef
10364+
10365+archprepare:
10366+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10367diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10368index 379814b..add62ce 100644
10369--- a/arch/x86/boot/Makefile
10370+++ b/arch/x86/boot/Makefile
10371@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10372 $(call cc-option, -fno-stack-protector) \
10373 $(call cc-option, -mpreferred-stack-boundary=2)
10374 KBUILD_CFLAGS += $(call cc-option, -m32)
10375+ifdef CONSTIFY_PLUGIN
10376+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10377+endif
10378 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10379 GCOV_PROFILE := n
10380
10381diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10382index 878e4b9..20537ab 100644
10383--- a/arch/x86/boot/bitops.h
10384+++ b/arch/x86/boot/bitops.h
10385@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10386 u8 v;
10387 const u32 *p = (const u32 *)addr;
10388
10389- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10390+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10391 return v;
10392 }
10393
10394@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10395
10396 static inline void set_bit(int nr, void *addr)
10397 {
10398- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10399+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10400 }
10401
10402 #endif /* BOOT_BITOPS_H */
10403diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10404index 5b75319..331a4ca 100644
10405--- a/arch/x86/boot/boot.h
10406+++ b/arch/x86/boot/boot.h
10407@@ -85,7 +85,7 @@ static inline void io_delay(void)
10408 static inline u16 ds(void)
10409 {
10410 u16 seg;
10411- asm("movw %%ds,%0" : "=rm" (seg));
10412+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10413 return seg;
10414 }
10415
10416@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10417 static inline int memcmp(const void *s1, const void *s2, size_t len)
10418 {
10419 u8 diff;
10420- asm("repe; cmpsb; setnz %0"
10421+ asm volatile("repe; cmpsb; setnz %0"
10422 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10423 return diff;
10424 }
10425diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10426index 5ef205c..342191d 100644
10427--- a/arch/x86/boot/compressed/Makefile
10428+++ b/arch/x86/boot/compressed/Makefile
10429@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10430 KBUILD_CFLAGS += $(cflags-y)
10431 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10432 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10433+ifdef CONSTIFY_PLUGIN
10434+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10435+endif
10436
10437 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10438 GCOV_PROFILE := n
10439diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10440index d606463..b887794 100644
10441--- a/arch/x86/boot/compressed/eboot.c
10442+++ b/arch/x86/boot/compressed/eboot.c
10443@@ -150,7 +150,6 @@ again:
10444 *addr = max_addr;
10445 }
10446
10447-free_pool:
10448 efi_call_phys1(sys_table->boottime->free_pool, map);
10449
10450 fail:
10451@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10452 if (i == map_size / desc_size)
10453 status = EFI_NOT_FOUND;
10454
10455-free_pool:
10456 efi_call_phys1(sys_table->boottime->free_pool, map);
10457 fail:
10458 return status;
10459diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
10460index a53440e..c3dbf1e 100644
10461--- a/arch/x86/boot/compressed/efi_stub_32.S
10462+++ b/arch/x86/boot/compressed/efi_stub_32.S
10463@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
10464 * parameter 2, ..., param n. To make things easy, we save the return
10465 * address of efi_call_phys in a global variable.
10466 */
10467- popl %ecx
10468- movl %ecx, saved_return_addr(%edx)
10469- /* get the function pointer into ECX*/
10470- popl %ecx
10471- movl %ecx, efi_rt_function_ptr(%edx)
10472+ popl saved_return_addr(%edx)
10473+ popl efi_rt_function_ptr(%edx)
10474
10475 /*
10476 * 3. Call the physical function.
10477 */
10478- call *%ecx
10479+ call *efi_rt_function_ptr(%edx)
10480
10481 /*
10482 * 4. Balance the stack. And because EAX contain the return value,
10483@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
10484 1: popl %edx
10485 subl $1b, %edx
10486
10487- movl efi_rt_function_ptr(%edx), %ecx
10488- pushl %ecx
10489+ pushl efi_rt_function_ptr(%edx)
10490
10491 /*
10492 * 10. Push the saved return address onto the stack and return.
10493 */
10494- movl saved_return_addr(%edx), %ecx
10495- pushl %ecx
10496- ret
10497+ jmpl *saved_return_addr(%edx)
10498 ENDPROC(efi_call_phys)
10499 .previous
10500
10501diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10502index 1e3184f..0d11e2e 100644
10503--- a/arch/x86/boot/compressed/head_32.S
10504+++ b/arch/x86/boot/compressed/head_32.S
10505@@ -118,7 +118,7 @@ preferred_addr:
10506 notl %eax
10507 andl %eax, %ebx
10508 #else
10509- movl $LOAD_PHYSICAL_ADDR, %ebx
10510+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10511 #endif
10512
10513 /* Target address to relocate to for decompression */
10514@@ -204,7 +204,7 @@ relocated:
10515 * and where it was actually loaded.
10516 */
10517 movl %ebp, %ebx
10518- subl $LOAD_PHYSICAL_ADDR, %ebx
10519+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10520 jz 2f /* Nothing to be done if loaded at compiled addr. */
10521 /*
10522 * Process relocations.
10523@@ -212,8 +212,7 @@ relocated:
10524
10525 1: subl $4, %edi
10526 movl (%edi), %ecx
10527- testl %ecx, %ecx
10528- jz 2f
10529+ jecxz 2f
10530 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10531 jmp 1b
10532 2:
10533diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10534index 16f24e6..47491a3 100644
10535--- a/arch/x86/boot/compressed/head_64.S
10536+++ b/arch/x86/boot/compressed/head_64.S
10537@@ -97,7 +97,7 @@ ENTRY(startup_32)
10538 notl %eax
10539 andl %eax, %ebx
10540 #else
10541- movl $LOAD_PHYSICAL_ADDR, %ebx
10542+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10543 #endif
10544
10545 /* Target address to relocate to for decompression */
10546@@ -272,7 +272,7 @@ preferred_addr:
10547 notq %rax
10548 andq %rax, %rbp
10549 #else
10550- movq $LOAD_PHYSICAL_ADDR, %rbp
10551+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10552 #endif
10553
10554 /* Target address to relocate to for decompression */
10555@@ -363,8 +363,8 @@ gdt:
10556 .long gdt
10557 .word 0
10558 .quad 0x0000000000000000 /* NULL descriptor */
10559- .quad 0x00af9a000000ffff /* __KERNEL_CS */
10560- .quad 0x00cf92000000ffff /* __KERNEL_DS */
10561+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
10562+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
10563 .quad 0x0080890000000000 /* TS descriptor */
10564 .quad 0x0000000000000000 /* TS continued */
10565 gdt_end:
10566diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10567index 7cb56c6..d382d84 100644
10568--- a/arch/x86/boot/compressed/misc.c
10569+++ b/arch/x86/boot/compressed/misc.c
10570@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10571 case PT_LOAD:
10572 #ifdef CONFIG_RELOCATABLE
10573 dest = output;
10574- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10575+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10576 #else
10577 dest = (void *)(phdr->p_paddr);
10578 #endif
10579@@ -354,7 +354,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10580 error("Destination address too large");
10581 #endif
10582 #ifndef CONFIG_RELOCATABLE
10583- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10584+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10585 error("Wrong destination address");
10586 #endif
10587
10588diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10589index 4d3ff03..e4972ff 100644
10590--- a/arch/x86/boot/cpucheck.c
10591+++ b/arch/x86/boot/cpucheck.c
10592@@ -74,7 +74,7 @@ static int has_fpu(void)
10593 u16 fcw = -1, fsw = -1;
10594 u32 cr0;
10595
10596- asm("movl %%cr0,%0" : "=r" (cr0));
10597+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10598 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10599 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10600 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10601@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10602 {
10603 u32 f0, f1;
10604
10605- asm("pushfl ; "
10606+ asm volatile("pushfl ; "
10607 "pushfl ; "
10608 "popl %0 ; "
10609 "movl %0,%1 ; "
10610@@ -115,7 +115,7 @@ static void get_flags(void)
10611 set_bit(X86_FEATURE_FPU, cpu.flags);
10612
10613 if (has_eflag(X86_EFLAGS_ID)) {
10614- asm("cpuid"
10615+ asm volatile("cpuid"
10616 : "=a" (max_intel_level),
10617 "=b" (cpu_vendor[0]),
10618 "=d" (cpu_vendor[1]),
10619@@ -124,7 +124,7 @@ static void get_flags(void)
10620
10621 if (max_intel_level >= 0x00000001 &&
10622 max_intel_level <= 0x0000ffff) {
10623- asm("cpuid"
10624+ asm volatile("cpuid"
10625 : "=a" (tfms),
10626 "=c" (cpu.flags[4]),
10627 "=d" (cpu.flags[0])
10628@@ -136,7 +136,7 @@ static void get_flags(void)
10629 cpu.model += ((tfms >> 16) & 0xf) << 4;
10630 }
10631
10632- asm("cpuid"
10633+ asm volatile("cpuid"
10634 : "=a" (max_amd_level)
10635 : "a" (0x80000000)
10636 : "ebx", "ecx", "edx");
10637@@ -144,7 +144,7 @@ static void get_flags(void)
10638 if (max_amd_level >= 0x80000001 &&
10639 max_amd_level <= 0x8000ffff) {
10640 u32 eax = 0x80000001;
10641- asm("cpuid"
10642+ asm volatile("cpuid"
10643 : "+a" (eax),
10644 "=c" (cpu.flags[6]),
10645 "=d" (cpu.flags[1])
10646@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10647 u32 ecx = MSR_K7_HWCR;
10648 u32 eax, edx;
10649
10650- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10651+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10652 eax &= ~(1 << 15);
10653- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10654+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10655
10656 get_flags(); /* Make sure it really did something */
10657 err = check_flags();
10658@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10659 u32 ecx = MSR_VIA_FCR;
10660 u32 eax, edx;
10661
10662- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10663+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10664 eax |= (1<<1)|(1<<7);
10665- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10666+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10667
10668 set_bit(X86_FEATURE_CX8, cpu.flags);
10669 err = check_flags();
10670@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10671 u32 eax, edx;
10672 u32 level = 1;
10673
10674- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10675- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10676- asm("cpuid"
10677+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10678+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10679+ asm volatile("cpuid"
10680 : "+a" (level), "=d" (cpu.flags[0])
10681 : : "ecx", "ebx");
10682- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10683+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10684
10685 err = check_flags();
10686 }
10687diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10688index 9ec06a1..2c25e79 100644
10689--- a/arch/x86/boot/header.S
10690+++ b/arch/x86/boot/header.S
10691@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10692 # single linked list of
10693 # struct setup_data
10694
10695-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10696+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10697
10698 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10699+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10700+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10701+#else
10702 #define VO_INIT_SIZE (VO__end - VO__text)
10703+#endif
10704 #if ZO_INIT_SIZE > VO_INIT_SIZE
10705 #define INIT_SIZE ZO_INIT_SIZE
10706 #else
10707diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10708index db75d07..8e6d0af 100644
10709--- a/arch/x86/boot/memory.c
10710+++ b/arch/x86/boot/memory.c
10711@@ -19,7 +19,7 @@
10712
10713 static int detect_memory_e820(void)
10714 {
10715- int count = 0;
10716+ unsigned int count = 0;
10717 struct biosregs ireg, oreg;
10718 struct e820entry *desc = boot_params.e820_map;
10719 static struct e820entry buf; /* static so it is zeroed */
10720diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10721index 11e8c6e..fdbb1ed 100644
10722--- a/arch/x86/boot/video-vesa.c
10723+++ b/arch/x86/boot/video-vesa.c
10724@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10725
10726 boot_params.screen_info.vesapm_seg = oreg.es;
10727 boot_params.screen_info.vesapm_off = oreg.di;
10728+ boot_params.screen_info.vesapm_size = oreg.cx;
10729 }
10730
10731 /*
10732diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10733index 43eda28..5ab5fdb 100644
10734--- a/arch/x86/boot/video.c
10735+++ b/arch/x86/boot/video.c
10736@@ -96,7 +96,7 @@ static void store_mode_params(void)
10737 static unsigned int get_entry(void)
10738 {
10739 char entry_buf[4];
10740- int i, len = 0;
10741+ unsigned int i, len = 0;
10742 int key;
10743 unsigned int v;
10744
10745diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10746index 9105655..5e37f27 100644
10747--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10748+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10749@@ -8,6 +8,8 @@
10750 * including this sentence is retained in full.
10751 */
10752
10753+#include <asm/alternative-asm.h>
10754+
10755 .extern crypto_ft_tab
10756 .extern crypto_it_tab
10757 .extern crypto_fl_tab
10758@@ -70,6 +72,8 @@
10759 je B192; \
10760 leaq 32(r9),r9;
10761
10762+#define ret pax_force_retaddr 0, 1; ret
10763+
10764 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10765 movq r1,r2; \
10766 movq r3,r4; \
10767diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10768index 477e9d7..3ab339f 100644
10769--- a/arch/x86/crypto/aesni-intel_asm.S
10770+++ b/arch/x86/crypto/aesni-intel_asm.S
10771@@ -31,6 +31,7 @@
10772
10773 #include <linux/linkage.h>
10774 #include <asm/inst.h>
10775+#include <asm/alternative-asm.h>
10776
10777 #ifdef __x86_64__
10778 .data
10779@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
10780 pop %r14
10781 pop %r13
10782 pop %r12
10783+ pax_force_retaddr 0, 1
10784 ret
10785 ENDPROC(aesni_gcm_dec)
10786
10787@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
10788 pop %r14
10789 pop %r13
10790 pop %r12
10791+ pax_force_retaddr 0, 1
10792 ret
10793 ENDPROC(aesni_gcm_enc)
10794
10795@@ -1722,6 +1725,7 @@ _key_expansion_256a:
10796 pxor %xmm1, %xmm0
10797 movaps %xmm0, (TKEYP)
10798 add $0x10, TKEYP
10799+ pax_force_retaddr_bts
10800 ret
10801 ENDPROC(_key_expansion_128)
10802 ENDPROC(_key_expansion_256a)
10803@@ -1748,6 +1752,7 @@ _key_expansion_192a:
10804 shufps $0b01001110, %xmm2, %xmm1
10805 movaps %xmm1, 0x10(TKEYP)
10806 add $0x20, TKEYP
10807+ pax_force_retaddr_bts
10808 ret
10809 ENDPROC(_key_expansion_192a)
10810
10811@@ -1768,6 +1773,7 @@ _key_expansion_192b:
10812
10813 movaps %xmm0, (TKEYP)
10814 add $0x10, TKEYP
10815+ pax_force_retaddr_bts
10816 ret
10817 ENDPROC(_key_expansion_192b)
10818
10819@@ -1781,6 +1787,7 @@ _key_expansion_256b:
10820 pxor %xmm1, %xmm2
10821 movaps %xmm2, (TKEYP)
10822 add $0x10, TKEYP
10823+ pax_force_retaddr_bts
10824 ret
10825 ENDPROC(_key_expansion_256b)
10826
10827@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
10828 #ifndef __x86_64__
10829 popl KEYP
10830 #endif
10831+ pax_force_retaddr 0, 1
10832 ret
10833 ENDPROC(aesni_set_key)
10834
10835@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
10836 popl KLEN
10837 popl KEYP
10838 #endif
10839+ pax_force_retaddr 0, 1
10840 ret
10841 ENDPROC(aesni_enc)
10842
10843@@ -1974,6 +1983,7 @@ _aesni_enc1:
10844 AESENC KEY STATE
10845 movaps 0x70(TKEYP), KEY
10846 AESENCLAST KEY STATE
10847+ pax_force_retaddr_bts
10848 ret
10849 ENDPROC(_aesni_enc1)
10850
10851@@ -2083,6 +2093,7 @@ _aesni_enc4:
10852 AESENCLAST KEY STATE2
10853 AESENCLAST KEY STATE3
10854 AESENCLAST KEY STATE4
10855+ pax_force_retaddr_bts
10856 ret
10857 ENDPROC(_aesni_enc4)
10858
10859@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
10860 popl KLEN
10861 popl KEYP
10862 #endif
10863+ pax_force_retaddr 0, 1
10864 ret
10865 ENDPROC(aesni_dec)
10866
10867@@ -2164,6 +2176,7 @@ _aesni_dec1:
10868 AESDEC KEY STATE
10869 movaps 0x70(TKEYP), KEY
10870 AESDECLAST KEY STATE
10871+ pax_force_retaddr_bts
10872 ret
10873 ENDPROC(_aesni_dec1)
10874
10875@@ -2273,6 +2286,7 @@ _aesni_dec4:
10876 AESDECLAST KEY STATE2
10877 AESDECLAST KEY STATE3
10878 AESDECLAST KEY STATE4
10879+ pax_force_retaddr_bts
10880 ret
10881 ENDPROC(_aesni_dec4)
10882
10883@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
10884 popl KEYP
10885 popl LEN
10886 #endif
10887+ pax_force_retaddr 0, 1
10888 ret
10889 ENDPROC(aesni_ecb_enc)
10890
10891@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
10892 popl KEYP
10893 popl LEN
10894 #endif
10895+ pax_force_retaddr 0, 1
10896 ret
10897 ENDPROC(aesni_ecb_dec)
10898
10899@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
10900 popl LEN
10901 popl IVP
10902 #endif
10903+ pax_force_retaddr 0, 1
10904 ret
10905 ENDPROC(aesni_cbc_enc)
10906
10907@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
10908 popl LEN
10909 popl IVP
10910 #endif
10911+ pax_force_retaddr 0, 1
10912 ret
10913 ENDPROC(aesni_cbc_dec)
10914
10915@@ -2550,6 +2568,7 @@ _aesni_inc_init:
10916 mov $1, TCTR_LOW
10917 MOVQ_R64_XMM TCTR_LOW INC
10918 MOVQ_R64_XMM CTR TCTR_LOW
10919+ pax_force_retaddr_bts
10920 ret
10921 ENDPROC(_aesni_inc_init)
10922
10923@@ -2579,6 +2598,7 @@ _aesni_inc:
10924 .Linc_low:
10925 movaps CTR, IV
10926 PSHUFB_XMM BSWAP_MASK IV
10927+ pax_force_retaddr_bts
10928 ret
10929 ENDPROC(_aesni_inc)
10930
10931@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
10932 .Lctr_enc_ret:
10933 movups IV, (IVP)
10934 .Lctr_enc_just_ret:
10935+ pax_force_retaddr 0, 1
10936 ret
10937 ENDPROC(aesni_ctr_enc)
10938
10939@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
10940 pxor INC, STATE4
10941 movdqu STATE4, 0x70(OUTP)
10942
10943+ pax_force_retaddr 0, 1
10944 ret
10945 ENDPROC(aesni_xts_crypt8)
10946
10947diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10948index 246c670..4d1ed00 100644
10949--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10950+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10951@@ -21,6 +21,7 @@
10952 */
10953
10954 #include <linux/linkage.h>
10955+#include <asm/alternative-asm.h>
10956
10957 .file "blowfish-x86_64-asm.S"
10958 .text
10959@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
10960 jnz .L__enc_xor;
10961
10962 write_block();
10963+ pax_force_retaddr 0, 1
10964 ret;
10965 .L__enc_xor:
10966 xor_block();
10967+ pax_force_retaddr 0, 1
10968 ret;
10969 ENDPROC(__blowfish_enc_blk)
10970
10971@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
10972
10973 movq %r11, %rbp;
10974
10975+ pax_force_retaddr 0, 1
10976 ret;
10977 ENDPROC(blowfish_dec_blk)
10978
10979@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
10980
10981 popq %rbx;
10982 popq %rbp;
10983+ pax_force_retaddr 0, 1
10984 ret;
10985
10986 .L__enc_xor4:
10987@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
10988
10989 popq %rbx;
10990 popq %rbp;
10991+ pax_force_retaddr 0, 1
10992 ret;
10993 ENDPROC(__blowfish_enc_blk_4way)
10994
10995@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
10996 popq %rbx;
10997 popq %rbp;
10998
10999+ pax_force_retaddr 0, 1
11000 ret;
11001 ENDPROC(blowfish_dec_blk_4way)
11002diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
11003index 310319c..ce174a4 100644
11004--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
11005+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
11006@@ -21,6 +21,7 @@
11007 */
11008
11009 #include <linux/linkage.h>
11010+#include <asm/alternative-asm.h>
11011
11012 .file "camellia-x86_64-asm_64.S"
11013 .text
11014@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
11015 enc_outunpack(mov, RT1);
11016
11017 movq RRBP, %rbp;
11018+ pax_force_retaddr 0, 1
11019 ret;
11020
11021 .L__enc_xor:
11022 enc_outunpack(xor, RT1);
11023
11024 movq RRBP, %rbp;
11025+ pax_force_retaddr 0, 1
11026 ret;
11027 ENDPROC(__camellia_enc_blk)
11028
11029@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
11030 dec_outunpack();
11031
11032 movq RRBP, %rbp;
11033+ pax_force_retaddr 0, 1
11034 ret;
11035 ENDPROC(camellia_dec_blk)
11036
11037@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
11038
11039 movq RRBP, %rbp;
11040 popq %rbx;
11041+ pax_force_retaddr 0, 1
11042 ret;
11043
11044 .L__enc2_xor:
11045@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
11046
11047 movq RRBP, %rbp;
11048 popq %rbx;
11049+ pax_force_retaddr 0, 1
11050 ret;
11051 ENDPROC(__camellia_enc_blk_2way)
11052
11053@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
11054
11055 movq RRBP, %rbp;
11056 movq RXOR, %rbx;
11057+ pax_force_retaddr 0, 1
11058 ret;
11059 ENDPROC(camellia_dec_blk_2way)
11060diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11061index c35fd5d..c1ee236 100644
11062--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11063+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11064@@ -24,6 +24,7 @@
11065 */
11066
11067 #include <linux/linkage.h>
11068+#include <asm/alternative-asm.h>
11069
11070 .file "cast5-avx-x86_64-asm_64.S"
11071
11072@@ -281,6 +282,7 @@ __cast5_enc_blk16:
11073 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11074 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11075
11076+ pax_force_retaddr 0, 1
11077 ret;
11078 ENDPROC(__cast5_enc_blk16)
11079
11080@@ -352,6 +354,7 @@ __cast5_dec_blk16:
11081 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11082 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11083
11084+ pax_force_retaddr 0, 1
11085 ret;
11086
11087 .L__skip_dec:
11088@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
11089 vmovdqu RR4, (6*4*4)(%r11);
11090 vmovdqu RL4, (7*4*4)(%r11);
11091
11092+ pax_force_retaddr
11093 ret;
11094 ENDPROC(cast5_ecb_enc_16way)
11095
11096@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
11097 vmovdqu RR4, (6*4*4)(%r11);
11098 vmovdqu RL4, (7*4*4)(%r11);
11099
11100+ pax_force_retaddr
11101 ret;
11102 ENDPROC(cast5_ecb_dec_16way)
11103
11104@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
11105
11106 popq %r12;
11107
11108+ pax_force_retaddr
11109 ret;
11110 ENDPROC(cast5_cbc_dec_16way)
11111
11112@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
11113
11114 popq %r12;
11115
11116+ pax_force_retaddr
11117 ret;
11118 ENDPROC(cast5_ctr_16way)
11119diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11120index e3531f8..18ded3a 100644
11121--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11122+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11123@@ -24,6 +24,7 @@
11124 */
11125
11126 #include <linux/linkage.h>
11127+#include <asm/alternative-asm.h>
11128 #include "glue_helper-asm-avx.S"
11129
11130 .file "cast6-avx-x86_64-asm_64.S"
11131@@ -295,6 +296,7 @@ __cast6_enc_blk8:
11132 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11133 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11134
11135+ pax_force_retaddr 0, 1
11136 ret;
11137 ENDPROC(__cast6_enc_blk8)
11138
11139@@ -340,6 +342,7 @@ __cast6_dec_blk8:
11140 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11141 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11142
11143+ pax_force_retaddr 0, 1
11144 ret;
11145 ENDPROC(__cast6_dec_blk8)
11146
11147@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
11148
11149 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11150
11151+ pax_force_retaddr
11152 ret;
11153 ENDPROC(cast6_ecb_enc_8way)
11154
11155@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
11156
11157 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11158
11159+ pax_force_retaddr
11160 ret;
11161 ENDPROC(cast6_ecb_dec_8way)
11162
11163@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
11164
11165 popq %r12;
11166
11167+ pax_force_retaddr
11168 ret;
11169 ENDPROC(cast6_cbc_dec_8way)
11170
11171@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
11172
11173 popq %r12;
11174
11175+ pax_force_retaddr
11176 ret;
11177 ENDPROC(cast6_ctr_8way)
11178
11179@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
11180 /* dst <= regs xor IVs(in dst) */
11181 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11182
11183+ pax_force_retaddr
11184 ret;
11185 ENDPROC(cast6_xts_enc_8way)
11186
11187@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
11188 /* dst <= regs xor IVs(in dst) */
11189 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11190
11191+ pax_force_retaddr
11192 ret;
11193 ENDPROC(cast6_xts_dec_8way)
11194diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11195index 9279e0b..9270820 100644
11196--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11197+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11198@@ -1,4 +1,5 @@
11199 #include <linux/linkage.h>
11200+#include <asm/alternative-asm.h>
11201
11202 # enter salsa20_encrypt_bytes
11203 ENTRY(salsa20_encrypt_bytes)
11204@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
11205 add %r11,%rsp
11206 mov %rdi,%rax
11207 mov %rsi,%rdx
11208+ pax_force_retaddr 0, 1
11209 ret
11210 # bytesatleast65:
11211 ._bytesatleast65:
11212@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
11213 add %r11,%rsp
11214 mov %rdi,%rax
11215 mov %rsi,%rdx
11216+ pax_force_retaddr
11217 ret
11218 ENDPROC(salsa20_keysetup)
11219
11220@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
11221 add %r11,%rsp
11222 mov %rdi,%rax
11223 mov %rsi,%rdx
11224+ pax_force_retaddr
11225 ret
11226 ENDPROC(salsa20_ivsetup)
11227diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11228index 2f202f4..d9164d6 100644
11229--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11230+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11231@@ -24,6 +24,7 @@
11232 */
11233
11234 #include <linux/linkage.h>
11235+#include <asm/alternative-asm.h>
11236 #include "glue_helper-asm-avx.S"
11237
11238 .file "serpent-avx-x86_64-asm_64.S"
11239@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
11240 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11241 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11242
11243+ pax_force_retaddr
11244 ret;
11245 ENDPROC(__serpent_enc_blk8_avx)
11246
11247@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
11248 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11249 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11250
11251+ pax_force_retaddr
11252 ret;
11253 ENDPROC(__serpent_dec_blk8_avx)
11254
11255@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
11256
11257 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11258
11259+ pax_force_retaddr
11260 ret;
11261 ENDPROC(serpent_ecb_enc_8way_avx)
11262
11263@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
11264
11265 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11266
11267+ pax_force_retaddr
11268 ret;
11269 ENDPROC(serpent_ecb_dec_8way_avx)
11270
11271@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
11272
11273 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11274
11275+ pax_force_retaddr
11276 ret;
11277 ENDPROC(serpent_cbc_dec_8way_avx)
11278
11279@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
11280
11281 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11282
11283+ pax_force_retaddr
11284 ret;
11285 ENDPROC(serpent_ctr_8way_avx)
11286
11287@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
11288 /* dst <= regs xor IVs(in dst) */
11289 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11290
11291+ pax_force_retaddr
11292 ret;
11293 ENDPROC(serpent_xts_enc_8way_avx)
11294
11295@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
11296 /* dst <= regs xor IVs(in dst) */
11297 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11298
11299+ pax_force_retaddr
11300 ret;
11301 ENDPROC(serpent_xts_dec_8way_avx)
11302diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11303index acc066c..1559cc4 100644
11304--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11305+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11306@@ -25,6 +25,7 @@
11307 */
11308
11309 #include <linux/linkage.h>
11310+#include <asm/alternative-asm.h>
11311
11312 .file "serpent-sse2-x86_64-asm_64.S"
11313 .text
11314@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
11315 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11316 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11317
11318+ pax_force_retaddr
11319 ret;
11320
11321 .L__enc_xor8:
11322 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11323 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11324
11325+ pax_force_retaddr
11326 ret;
11327 ENDPROC(__serpent_enc_blk_8way)
11328
11329@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
11330 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11331 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11332
11333+ pax_force_retaddr
11334 ret;
11335 ENDPROC(serpent_dec_blk_8way)
11336diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11337index a410950..3356d42 100644
11338--- a/arch/x86/crypto/sha1_ssse3_asm.S
11339+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11340@@ -29,6 +29,7 @@
11341 */
11342
11343 #include <linux/linkage.h>
11344+#include <asm/alternative-asm.h>
11345
11346 #define CTX %rdi // arg1
11347 #define BUF %rsi // arg2
11348@@ -104,6 +105,7 @@
11349 pop %r12
11350 pop %rbp
11351 pop %rbx
11352+ pax_force_retaddr 0, 1
11353 ret
11354
11355 ENDPROC(\name)
11356diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11357index 0505813..63b1d00 100644
11358--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11359+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11360@@ -24,6 +24,7 @@
11361 */
11362
11363 #include <linux/linkage.h>
11364+#include <asm/alternative-asm.h>
11365 #include "glue_helper-asm-avx.S"
11366
11367 .file "twofish-avx-x86_64-asm_64.S"
11368@@ -284,6 +285,7 @@ __twofish_enc_blk8:
11369 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11370 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11371
11372+ pax_force_retaddr 0, 1
11373 ret;
11374 ENDPROC(__twofish_enc_blk8)
11375
11376@@ -324,6 +326,7 @@ __twofish_dec_blk8:
11377 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11378 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11379
11380+ pax_force_retaddr 0, 1
11381 ret;
11382 ENDPROC(__twofish_dec_blk8)
11383
11384@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
11385
11386 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11387
11388+ pax_force_retaddr 0, 1
11389 ret;
11390 ENDPROC(twofish_ecb_enc_8way)
11391
11392@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
11393
11394 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11395
11396+ pax_force_retaddr 0, 1
11397 ret;
11398 ENDPROC(twofish_ecb_dec_8way)
11399
11400@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
11401
11402 popq %r12;
11403
11404+ pax_force_retaddr 0, 1
11405 ret;
11406 ENDPROC(twofish_cbc_dec_8way)
11407
11408@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
11409
11410 popq %r12;
11411
11412+ pax_force_retaddr 0, 1
11413 ret;
11414 ENDPROC(twofish_ctr_8way)
11415
11416@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
11417 /* dst <= regs xor IVs(in dst) */
11418 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11419
11420+ pax_force_retaddr 0, 1
11421 ret;
11422 ENDPROC(twofish_xts_enc_8way)
11423
11424@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
11425 /* dst <= regs xor IVs(in dst) */
11426 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11427
11428+ pax_force_retaddr 0, 1
11429 ret;
11430 ENDPROC(twofish_xts_dec_8way)
11431diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11432index 1c3b7ce..b365c5e 100644
11433--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11434+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11435@@ -21,6 +21,7 @@
11436 */
11437
11438 #include <linux/linkage.h>
11439+#include <asm/alternative-asm.h>
11440
11441 .file "twofish-x86_64-asm-3way.S"
11442 .text
11443@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
11444 popq %r13;
11445 popq %r14;
11446 popq %r15;
11447+ pax_force_retaddr 0, 1
11448 ret;
11449
11450 .L__enc_xor3:
11451@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
11452 popq %r13;
11453 popq %r14;
11454 popq %r15;
11455+ pax_force_retaddr 0, 1
11456 ret;
11457 ENDPROC(__twofish_enc_blk_3way)
11458
11459@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
11460 popq %r13;
11461 popq %r14;
11462 popq %r15;
11463+ pax_force_retaddr 0, 1
11464 ret;
11465 ENDPROC(twofish_dec_blk_3way)
11466diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11467index a039d21..29e7615 100644
11468--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11469+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11470@@ -22,6 +22,7 @@
11471
11472 #include <linux/linkage.h>
11473 #include <asm/asm-offsets.h>
11474+#include <asm/alternative-asm.h>
11475
11476 #define a_offset 0
11477 #define b_offset 4
11478@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
11479
11480 popq R1
11481 movq $1,%rax
11482+ pax_force_retaddr 0, 1
11483 ret
11484 ENDPROC(twofish_enc_blk)
11485
11486@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
11487
11488 popq R1
11489 movq $1,%rax
11490+ pax_force_retaddr 0, 1
11491 ret
11492 ENDPROC(twofish_dec_blk)
11493diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11494index 52ff81c..98af645 100644
11495--- a/arch/x86/ia32/ia32_aout.c
11496+++ b/arch/x86/ia32/ia32_aout.c
11497@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11498 unsigned long dump_start, dump_size;
11499 struct user32 dump;
11500
11501+ memset(&dump, 0, sizeof(dump));
11502+
11503 fs = get_fs();
11504 set_fs(KERNEL_DS);
11505 has_dumped = 1;
11506diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11507index cf1a471..3bc4cf8 100644
11508--- a/arch/x86/ia32/ia32_signal.c
11509+++ b/arch/x86/ia32/ia32_signal.c
11510@@ -340,7 +340,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
11511 sp -= frame_size;
11512 /* Align the stack pointer according to the i386 ABI,
11513 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11514- sp = ((sp + 4) & -16ul) - 4;
11515+ sp = ((sp - 12) & -16ul) - 4;
11516 return (void __user *) sp;
11517 }
11518
11519@@ -398,7 +398,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
11520 * These are actually not used anymore, but left because some
11521 * gdb versions depend on them as a marker.
11522 */
11523- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11524+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11525 } put_user_catch(err);
11526
11527 if (err)
11528@@ -440,7 +440,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11529 0xb8,
11530 __NR_ia32_rt_sigreturn,
11531 0x80cd,
11532- 0,
11533+ 0
11534 };
11535
11536 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
11537@@ -463,16 +463,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11538
11539 if (ksig->ka.sa.sa_flags & SA_RESTORER)
11540 restorer = ksig->ka.sa.sa_restorer;
11541+ else if (current->mm->context.vdso)
11542+ /* Return stub is in 32bit vsyscall page */
11543+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11544 else
11545- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11546- rt_sigreturn);
11547+ restorer = &frame->retcode;
11548 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11549
11550 /*
11551 * Not actually used anymore, but left because some gdb
11552 * versions need it.
11553 */
11554- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11555+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11556 } put_user_catch(err);
11557
11558 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
11559diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11560index 474dc1b..24aaa3e 100644
11561--- a/arch/x86/ia32/ia32entry.S
11562+++ b/arch/x86/ia32/ia32entry.S
11563@@ -15,8 +15,10 @@
11564 #include <asm/irqflags.h>
11565 #include <asm/asm.h>
11566 #include <asm/smap.h>
11567+#include <asm/pgtable.h>
11568 #include <linux/linkage.h>
11569 #include <linux/err.h>
11570+#include <asm/alternative-asm.h>
11571
11572 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11573 #include <linux/elf-em.h>
11574@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11575 ENDPROC(native_irq_enable_sysexit)
11576 #endif
11577
11578+ .macro pax_enter_kernel_user
11579+ pax_set_fptr_mask
11580+#ifdef CONFIG_PAX_MEMORY_UDEREF
11581+ call pax_enter_kernel_user
11582+#endif
11583+ .endm
11584+
11585+ .macro pax_exit_kernel_user
11586+#ifdef CONFIG_PAX_MEMORY_UDEREF
11587+ call pax_exit_kernel_user
11588+#endif
11589+#ifdef CONFIG_PAX_RANDKSTACK
11590+ pushq %rax
11591+ pushq %r11
11592+ call pax_randomize_kstack
11593+ popq %r11
11594+ popq %rax
11595+#endif
11596+ .endm
11597+
11598+ .macro pax_erase_kstack
11599+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11600+ call pax_erase_kstack
11601+#endif
11602+ .endm
11603+
11604 /*
11605 * 32bit SYSENTER instruction entry.
11606 *
11607@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11608 CFI_REGISTER rsp,rbp
11609 SWAPGS_UNSAFE_STACK
11610 movq PER_CPU_VAR(kernel_stack), %rsp
11611- addq $(KERNEL_STACK_OFFSET),%rsp
11612- /*
11613- * No need to follow this irqs on/off section: the syscall
11614- * disabled irqs, here we enable it straight after entry:
11615- */
11616- ENABLE_INTERRUPTS(CLBR_NONE)
11617 movl %ebp,%ebp /* zero extension */
11618 pushq_cfi $__USER32_DS
11619 /*CFI_REL_OFFSET ss,0*/
11620@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11621 CFI_REL_OFFSET rsp,0
11622 pushfq_cfi
11623 /*CFI_REL_OFFSET rflags,0*/
11624- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11625- CFI_REGISTER rip,r10
11626+ orl $X86_EFLAGS_IF,(%rsp)
11627+ GET_THREAD_INFO(%r11)
11628+ movl TI_sysenter_return(%r11), %r11d
11629+ CFI_REGISTER rip,r11
11630 pushq_cfi $__USER32_CS
11631 /*CFI_REL_OFFSET cs,0*/
11632 movl %eax, %eax
11633- pushq_cfi %r10
11634+ pushq_cfi %r11
11635 CFI_REL_OFFSET rip,0
11636 pushq_cfi %rax
11637 cld
11638 SAVE_ARGS 0,1,0
11639+ pax_enter_kernel_user
11640+
11641+#ifdef CONFIG_PAX_RANDKSTACK
11642+ pax_erase_kstack
11643+#endif
11644+
11645+ /*
11646+ * No need to follow this irqs on/off section: the syscall
11647+ * disabled irqs, here we enable it straight after entry:
11648+ */
11649+ ENABLE_INTERRUPTS(CLBR_NONE)
11650 /* no need to do an access_ok check here because rbp has been
11651 32bit zero extended */
11652+
11653+#ifdef CONFIG_PAX_MEMORY_UDEREF
11654+ mov pax_user_shadow_base,%r11
11655+ add %r11,%rbp
11656+#endif
11657+
11658 ASM_STAC
11659 1: movl (%rbp),%ebp
11660 _ASM_EXTABLE(1b,ia32_badarg)
11661 ASM_CLAC
11662- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11663- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11664+ GET_THREAD_INFO(%r11)
11665+ orl $TS_COMPAT,TI_status(%r11)
11666+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11667 CFI_REMEMBER_STATE
11668 jnz sysenter_tracesys
11669 cmpq $(IA32_NR_syscalls-1),%rax
11670@@ -162,12 +204,15 @@ sysenter_do_call:
11671 sysenter_dispatch:
11672 call *ia32_sys_call_table(,%rax,8)
11673 movq %rax,RAX-ARGOFFSET(%rsp)
11674+ GET_THREAD_INFO(%r11)
11675 DISABLE_INTERRUPTS(CLBR_NONE)
11676 TRACE_IRQS_OFF
11677- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11678+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11679 jnz sysexit_audit
11680 sysexit_from_sys_call:
11681- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11682+ pax_exit_kernel_user
11683+ pax_erase_kstack
11684+ andl $~TS_COMPAT,TI_status(%r11)
11685 /* clear IF, that popfq doesn't enable interrupts early */
11686 andl $~0x200,EFLAGS-R11(%rsp)
11687 movl RIP-R11(%rsp),%edx /* User %eip */
11688@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11689 movl %eax,%esi /* 2nd arg: syscall number */
11690 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11691 call __audit_syscall_entry
11692+
11693+ pax_erase_kstack
11694+
11695 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11696 cmpq $(IA32_NR_syscalls-1),%rax
11697 ja ia32_badsys
11698@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11699 .endm
11700
11701 .macro auditsys_exit exit
11702- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11703+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11704 jnz ia32_ret_from_sys_call
11705 TRACE_IRQS_ON
11706 ENABLE_INTERRUPTS(CLBR_NONE)
11707@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11708 1: setbe %al /* 1 if error, 0 if not */
11709 movzbl %al,%edi /* zero-extend that into %edi */
11710 call __audit_syscall_exit
11711+ GET_THREAD_INFO(%r11)
11712 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11713 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11714 DISABLE_INTERRUPTS(CLBR_NONE)
11715 TRACE_IRQS_OFF
11716- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11717+ testl %edi,TI_flags(%r11)
11718 jz \exit
11719 CLEAR_RREGS -ARGOFFSET
11720 jmp int_with_check
11721@@ -237,7 +286,7 @@ sysexit_audit:
11722
11723 sysenter_tracesys:
11724 #ifdef CONFIG_AUDITSYSCALL
11725- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11726+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11727 jz sysenter_auditsys
11728 #endif
11729 SAVE_REST
11730@@ -249,6 +298,9 @@ sysenter_tracesys:
11731 RESTORE_REST
11732 cmpq $(IA32_NR_syscalls-1),%rax
11733 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11734+
11735+ pax_erase_kstack
11736+
11737 jmp sysenter_do_call
11738 CFI_ENDPROC
11739 ENDPROC(ia32_sysenter_target)
11740@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11741 ENTRY(ia32_cstar_target)
11742 CFI_STARTPROC32 simple
11743 CFI_SIGNAL_FRAME
11744- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11745+ CFI_DEF_CFA rsp,0
11746 CFI_REGISTER rip,rcx
11747 /*CFI_REGISTER rflags,r11*/
11748 SWAPGS_UNSAFE_STACK
11749 movl %esp,%r8d
11750 CFI_REGISTER rsp,r8
11751 movq PER_CPU_VAR(kernel_stack),%rsp
11752+ SAVE_ARGS 8*6,0,0
11753+ pax_enter_kernel_user
11754+
11755+#ifdef CONFIG_PAX_RANDKSTACK
11756+ pax_erase_kstack
11757+#endif
11758+
11759 /*
11760 * No need to follow this irqs on/off section: the syscall
11761 * disabled irqs and here we enable it straight after entry:
11762 */
11763 ENABLE_INTERRUPTS(CLBR_NONE)
11764- SAVE_ARGS 8,0,0
11765 movl %eax,%eax /* zero extension */
11766 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11767 movq %rcx,RIP-ARGOFFSET(%rsp)
11768@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11769 /* no need to do an access_ok check here because r8 has been
11770 32bit zero extended */
11771 /* hardware stack frame is complete now */
11772+
11773+#ifdef CONFIG_PAX_MEMORY_UDEREF
11774+ mov pax_user_shadow_base,%r11
11775+ add %r11,%r8
11776+#endif
11777+
11778 ASM_STAC
11779 1: movl (%r8),%r9d
11780 _ASM_EXTABLE(1b,ia32_badarg)
11781 ASM_CLAC
11782- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11783- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11784+ GET_THREAD_INFO(%r11)
11785+ orl $TS_COMPAT,TI_status(%r11)
11786+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11787 CFI_REMEMBER_STATE
11788 jnz cstar_tracesys
11789 cmpq $IA32_NR_syscalls-1,%rax
11790@@ -319,12 +384,15 @@ cstar_do_call:
11791 cstar_dispatch:
11792 call *ia32_sys_call_table(,%rax,8)
11793 movq %rax,RAX-ARGOFFSET(%rsp)
11794+ GET_THREAD_INFO(%r11)
11795 DISABLE_INTERRUPTS(CLBR_NONE)
11796 TRACE_IRQS_OFF
11797- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11798+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11799 jnz sysretl_audit
11800 sysretl_from_sys_call:
11801- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11802+ pax_exit_kernel_user
11803+ pax_erase_kstack
11804+ andl $~TS_COMPAT,TI_status(%r11)
11805 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11806 movl RIP-ARGOFFSET(%rsp),%ecx
11807 CFI_REGISTER rip,rcx
11808@@ -352,7 +420,7 @@ sysretl_audit:
11809
11810 cstar_tracesys:
11811 #ifdef CONFIG_AUDITSYSCALL
11812- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11813+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11814 jz cstar_auditsys
11815 #endif
11816 xchgl %r9d,%ebp
11817@@ -366,6 +434,9 @@ cstar_tracesys:
11818 xchgl %ebp,%r9d
11819 cmpq $(IA32_NR_syscalls-1),%rax
11820 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11821+
11822+ pax_erase_kstack
11823+
11824 jmp cstar_do_call
11825 END(ia32_cstar_target)
11826
11827@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11828 CFI_REL_OFFSET rip,RIP-RIP
11829 PARAVIRT_ADJUST_EXCEPTION_FRAME
11830 SWAPGS
11831- /*
11832- * No need to follow this irqs on/off section: the syscall
11833- * disabled irqs and here we enable it straight after entry:
11834- */
11835- ENABLE_INTERRUPTS(CLBR_NONE)
11836 movl %eax,%eax
11837 pushq_cfi %rax
11838 cld
11839 /* note the registers are not zero extended to the sf.
11840 this could be a problem. */
11841 SAVE_ARGS 0,1,0
11842- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11843- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11844+ pax_enter_kernel_user
11845+
11846+#ifdef CONFIG_PAX_RANDKSTACK
11847+ pax_erase_kstack
11848+#endif
11849+
11850+ /*
11851+ * No need to follow this irqs on/off section: the syscall
11852+ * disabled irqs and here we enable it straight after entry:
11853+ */
11854+ ENABLE_INTERRUPTS(CLBR_NONE)
11855+ GET_THREAD_INFO(%r11)
11856+ orl $TS_COMPAT,TI_status(%r11)
11857+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11858 jnz ia32_tracesys
11859 cmpq $(IA32_NR_syscalls-1),%rax
11860 ja ia32_badsys
11861@@ -442,6 +520,9 @@ ia32_tracesys:
11862 RESTORE_REST
11863 cmpq $(IA32_NR_syscalls-1),%rax
11864 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11865+
11866+ pax_erase_kstack
11867+
11868 jmp ia32_do_call
11869 END(ia32_syscall)
11870
11871diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11872index 8e0ceec..af13504 100644
11873--- a/arch/x86/ia32/sys_ia32.c
11874+++ b/arch/x86/ia32/sys_ia32.c
11875@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11876 */
11877 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11878 {
11879- typeof(ubuf->st_uid) uid = 0;
11880- typeof(ubuf->st_gid) gid = 0;
11881+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11882+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11883 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11884 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11885 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11886diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11887index 372231c..a5aa1a1 100644
11888--- a/arch/x86/include/asm/alternative-asm.h
11889+++ b/arch/x86/include/asm/alternative-asm.h
11890@@ -18,6 +18,45 @@
11891 .endm
11892 #endif
11893
11894+#ifdef KERNEXEC_PLUGIN
11895+ .macro pax_force_retaddr_bts rip=0
11896+ btsq $63,\rip(%rsp)
11897+ .endm
11898+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11899+ .macro pax_force_retaddr rip=0, reload=0
11900+ btsq $63,\rip(%rsp)
11901+ .endm
11902+ .macro pax_force_fptr ptr
11903+ btsq $63,\ptr
11904+ .endm
11905+ .macro pax_set_fptr_mask
11906+ .endm
11907+#endif
11908+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11909+ .macro pax_force_retaddr rip=0, reload=0
11910+ .if \reload
11911+ pax_set_fptr_mask
11912+ .endif
11913+ orq %r10,\rip(%rsp)
11914+ .endm
11915+ .macro pax_force_fptr ptr
11916+ orq %r10,\ptr
11917+ .endm
11918+ .macro pax_set_fptr_mask
11919+ movabs $0x8000000000000000,%r10
11920+ .endm
11921+#endif
11922+#else
11923+ .macro pax_force_retaddr rip=0, reload=0
11924+ .endm
11925+ .macro pax_force_fptr ptr
11926+ .endm
11927+ .macro pax_force_retaddr_bts rip=0
11928+ .endm
11929+ .macro pax_set_fptr_mask
11930+ .endm
11931+#endif
11932+
11933 .macro altinstruction_entry orig alt feature orig_len alt_len
11934 .long \orig - .
11935 .long \alt - .
11936diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11937index 58ed6d9..f1cbe58 100644
11938--- a/arch/x86/include/asm/alternative.h
11939+++ b/arch/x86/include/asm/alternative.h
11940@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11941 ".pushsection .discard,\"aw\",@progbits\n" \
11942 DISCARD_ENTRY(1) \
11943 ".popsection\n" \
11944- ".pushsection .altinstr_replacement, \"ax\"\n" \
11945+ ".pushsection .altinstr_replacement, \"a\"\n" \
11946 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11947 ".popsection"
11948
11949@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11950 DISCARD_ENTRY(1) \
11951 DISCARD_ENTRY(2) \
11952 ".popsection\n" \
11953- ".pushsection .altinstr_replacement, \"ax\"\n" \
11954+ ".pushsection .altinstr_replacement, \"a\"\n" \
11955 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11956 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11957 ".popsection"
11958diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11959index 3388034..050f0b9 100644
11960--- a/arch/x86/include/asm/apic.h
11961+++ b/arch/x86/include/asm/apic.h
11962@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11963
11964 #ifdef CONFIG_X86_LOCAL_APIC
11965
11966-extern unsigned int apic_verbosity;
11967+extern int apic_verbosity;
11968 extern int local_apic_timer_c2_ok;
11969
11970 extern int disable_apic;
11971diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11972index 20370c6..a2eb9b0 100644
11973--- a/arch/x86/include/asm/apm.h
11974+++ b/arch/x86/include/asm/apm.h
11975@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11976 __asm__ __volatile__(APM_DO_ZERO_SEGS
11977 "pushl %%edi\n\t"
11978 "pushl %%ebp\n\t"
11979- "lcall *%%cs:apm_bios_entry\n\t"
11980+ "lcall *%%ss:apm_bios_entry\n\t"
11981 "setc %%al\n\t"
11982 "popl %%ebp\n\t"
11983 "popl %%edi\n\t"
11984@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11985 __asm__ __volatile__(APM_DO_ZERO_SEGS
11986 "pushl %%edi\n\t"
11987 "pushl %%ebp\n\t"
11988- "lcall *%%cs:apm_bios_entry\n\t"
11989+ "lcall *%%ss:apm_bios_entry\n\t"
11990 "setc %%bl\n\t"
11991 "popl %%ebp\n\t"
11992 "popl %%edi\n\t"
11993diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11994index 722aa3b..3a0bb27 100644
11995--- a/arch/x86/include/asm/atomic.h
11996+++ b/arch/x86/include/asm/atomic.h
11997@@ -22,7 +22,18 @@
11998 */
11999 static inline int atomic_read(const atomic_t *v)
12000 {
12001- return (*(volatile int *)&(v)->counter);
12002+ return (*(volatile const int *)&(v)->counter);
12003+}
12004+
12005+/**
12006+ * atomic_read_unchecked - read atomic variable
12007+ * @v: pointer of type atomic_unchecked_t
12008+ *
12009+ * Atomically reads the value of @v.
12010+ */
12011+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
12012+{
12013+ return (*(volatile const int *)&(v)->counter);
12014 }
12015
12016 /**
12017@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
12018 }
12019
12020 /**
12021+ * atomic_set_unchecked - set atomic variable
12022+ * @v: pointer of type atomic_unchecked_t
12023+ * @i: required value
12024+ *
12025+ * Atomically sets the value of @v to @i.
12026+ */
12027+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
12028+{
12029+ v->counter = i;
12030+}
12031+
12032+/**
12033 * atomic_add - add integer to atomic variable
12034 * @i: integer value to add
12035 * @v: pointer of type atomic_t
12036@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
12037 */
12038 static inline void atomic_add(int i, atomic_t *v)
12039 {
12040- asm volatile(LOCK_PREFIX "addl %1,%0"
12041+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12042+
12043+#ifdef CONFIG_PAX_REFCOUNT
12044+ "jno 0f\n"
12045+ LOCK_PREFIX "subl %1,%0\n"
12046+ "int $4\n0:\n"
12047+ _ASM_EXTABLE(0b, 0b)
12048+#endif
12049+
12050+ : "+m" (v->counter)
12051+ : "ir" (i));
12052+}
12053+
12054+/**
12055+ * atomic_add_unchecked - add integer to atomic variable
12056+ * @i: integer value to add
12057+ * @v: pointer of type atomic_unchecked_t
12058+ *
12059+ * Atomically adds @i to @v.
12060+ */
12061+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
12062+{
12063+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12064 : "+m" (v->counter)
12065 : "ir" (i));
12066 }
12067@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
12068 */
12069 static inline void atomic_sub(int i, atomic_t *v)
12070 {
12071- asm volatile(LOCK_PREFIX "subl %1,%0"
12072+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12073+
12074+#ifdef CONFIG_PAX_REFCOUNT
12075+ "jno 0f\n"
12076+ LOCK_PREFIX "addl %1,%0\n"
12077+ "int $4\n0:\n"
12078+ _ASM_EXTABLE(0b, 0b)
12079+#endif
12080+
12081+ : "+m" (v->counter)
12082+ : "ir" (i));
12083+}
12084+
12085+/**
12086+ * atomic_sub_unchecked - subtract integer from atomic variable
12087+ * @i: integer value to subtract
12088+ * @v: pointer of type atomic_unchecked_t
12089+ *
12090+ * Atomically subtracts @i from @v.
12091+ */
12092+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
12093+{
12094+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12095 : "+m" (v->counter)
12096 : "ir" (i));
12097 }
12098@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12099 {
12100 unsigned char c;
12101
12102- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
12103+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
12104+
12105+#ifdef CONFIG_PAX_REFCOUNT
12106+ "jno 0f\n"
12107+ LOCK_PREFIX "addl %2,%0\n"
12108+ "int $4\n0:\n"
12109+ _ASM_EXTABLE(0b, 0b)
12110+#endif
12111+
12112+ "sete %1\n"
12113 : "+m" (v->counter), "=qm" (c)
12114 : "ir" (i) : "memory");
12115 return c;
12116@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12117 */
12118 static inline void atomic_inc(atomic_t *v)
12119 {
12120- asm volatile(LOCK_PREFIX "incl %0"
12121+ asm volatile(LOCK_PREFIX "incl %0\n"
12122+
12123+#ifdef CONFIG_PAX_REFCOUNT
12124+ "jno 0f\n"
12125+ LOCK_PREFIX "decl %0\n"
12126+ "int $4\n0:\n"
12127+ _ASM_EXTABLE(0b, 0b)
12128+#endif
12129+
12130+ : "+m" (v->counter));
12131+}
12132+
12133+/**
12134+ * atomic_inc_unchecked - increment atomic variable
12135+ * @v: pointer of type atomic_unchecked_t
12136+ *
12137+ * Atomically increments @v by 1.
12138+ */
12139+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12140+{
12141+ asm volatile(LOCK_PREFIX "incl %0\n"
12142 : "+m" (v->counter));
12143 }
12144
12145@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12146 */
12147 static inline void atomic_dec(atomic_t *v)
12148 {
12149- asm volatile(LOCK_PREFIX "decl %0"
12150+ asm volatile(LOCK_PREFIX "decl %0\n"
12151+
12152+#ifdef CONFIG_PAX_REFCOUNT
12153+ "jno 0f\n"
12154+ LOCK_PREFIX "incl %0\n"
12155+ "int $4\n0:\n"
12156+ _ASM_EXTABLE(0b, 0b)
12157+#endif
12158+
12159+ : "+m" (v->counter));
12160+}
12161+
12162+/**
12163+ * atomic_dec_unchecked - decrement atomic variable
12164+ * @v: pointer of type atomic_unchecked_t
12165+ *
12166+ * Atomically decrements @v by 1.
12167+ */
12168+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12169+{
12170+ asm volatile(LOCK_PREFIX "decl %0\n"
12171 : "+m" (v->counter));
12172 }
12173
12174@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12175 {
12176 unsigned char c;
12177
12178- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12179+ asm volatile(LOCK_PREFIX "decl %0\n"
12180+
12181+#ifdef CONFIG_PAX_REFCOUNT
12182+ "jno 0f\n"
12183+ LOCK_PREFIX "incl %0\n"
12184+ "int $4\n0:\n"
12185+ _ASM_EXTABLE(0b, 0b)
12186+#endif
12187+
12188+ "sete %1\n"
12189 : "+m" (v->counter), "=qm" (c)
12190 : : "memory");
12191 return c != 0;
12192@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12193 {
12194 unsigned char c;
12195
12196- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12197+ asm volatile(LOCK_PREFIX "incl %0\n"
12198+
12199+#ifdef CONFIG_PAX_REFCOUNT
12200+ "jno 0f\n"
12201+ LOCK_PREFIX "decl %0\n"
12202+ "int $4\n0:\n"
12203+ _ASM_EXTABLE(0b, 0b)
12204+#endif
12205+
12206+ "sete %1\n"
12207+ : "+m" (v->counter), "=qm" (c)
12208+ : : "memory");
12209+ return c != 0;
12210+}
12211+
12212+/**
12213+ * atomic_inc_and_test_unchecked - increment and test
12214+ * @v: pointer of type atomic_unchecked_t
12215+ *
12216+ * Atomically increments @v by 1
12217+ * and returns true if the result is zero, or false for all
12218+ * other cases.
12219+ */
12220+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12221+{
12222+ unsigned char c;
12223+
12224+ asm volatile(LOCK_PREFIX "incl %0\n"
12225+ "sete %1\n"
12226 : "+m" (v->counter), "=qm" (c)
12227 : : "memory");
12228 return c != 0;
12229@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12230 {
12231 unsigned char c;
12232
12233- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12234+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12235+
12236+#ifdef CONFIG_PAX_REFCOUNT
12237+ "jno 0f\n"
12238+ LOCK_PREFIX "subl %2,%0\n"
12239+ "int $4\n0:\n"
12240+ _ASM_EXTABLE(0b, 0b)
12241+#endif
12242+
12243+ "sets %1\n"
12244 : "+m" (v->counter), "=qm" (c)
12245 : "ir" (i) : "memory");
12246 return c;
12247@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12248 */
12249 static inline int atomic_add_return(int i, atomic_t *v)
12250 {
12251+ return i + xadd_check_overflow(&v->counter, i);
12252+}
12253+
12254+/**
12255+ * atomic_add_return_unchecked - add integer and return
12256+ * @i: integer value to add
12257+ * @v: pointer of type atomic_unchecked_t
12258+ *
12259+ * Atomically adds @i to @v and returns @i + @v
12260+ */
12261+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12262+{
12263 return i + xadd(&v->counter, i);
12264 }
12265
12266@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12267 }
12268
12269 #define atomic_inc_return(v) (atomic_add_return(1, v))
12270+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12271+{
12272+ return atomic_add_return_unchecked(1, v);
12273+}
12274 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12275
12276 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12277@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12278 return cmpxchg(&v->counter, old, new);
12279 }
12280
12281+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12282+{
12283+ return cmpxchg(&v->counter, old, new);
12284+}
12285+
12286 static inline int atomic_xchg(atomic_t *v, int new)
12287 {
12288 return xchg(&v->counter, new);
12289 }
12290
12291+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12292+{
12293+ return xchg(&v->counter, new);
12294+}
12295+
12296 /**
12297 * __atomic_add_unless - add unless the number is already a given value
12298 * @v: pointer of type atomic_t
12299@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12300 */
12301 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12302 {
12303- int c, old;
12304+ int c, old, new;
12305 c = atomic_read(v);
12306 for (;;) {
12307- if (unlikely(c == (u)))
12308+ if (unlikely(c == u))
12309 break;
12310- old = atomic_cmpxchg((v), c, c + (a));
12311+
12312+ asm volatile("addl %2,%0\n"
12313+
12314+#ifdef CONFIG_PAX_REFCOUNT
12315+ "jno 0f\n"
12316+ "subl %2,%0\n"
12317+ "int $4\n0:\n"
12318+ _ASM_EXTABLE(0b, 0b)
12319+#endif
12320+
12321+ : "=r" (new)
12322+ : "0" (c), "ir" (a));
12323+
12324+ old = atomic_cmpxchg(v, c, new);
12325 if (likely(old == c))
12326 break;
12327 c = old;
12328@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12329 }
12330
12331 /**
12332+ * atomic_inc_not_zero_hint - increment if not null
12333+ * @v: pointer of type atomic_t
12334+ * @hint: probable value of the atomic before the increment
12335+ *
12336+ * This version of atomic_inc_not_zero() gives a hint of probable
12337+ * value of the atomic. This helps processor to not read the memory
12338+ * before doing the atomic read/modify/write cycle, lowering
12339+ * number of bus transactions on some arches.
12340+ *
12341+ * Returns: 0 if increment was not done, 1 otherwise.
12342+ */
12343+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12344+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12345+{
12346+ int val, c = hint, new;
12347+
12348+ /* sanity test, should be removed by compiler if hint is a constant */
12349+ if (!hint)
12350+ return __atomic_add_unless(v, 1, 0);
12351+
12352+ do {
12353+ asm volatile("incl %0\n"
12354+
12355+#ifdef CONFIG_PAX_REFCOUNT
12356+ "jno 0f\n"
12357+ "decl %0\n"
12358+ "int $4\n0:\n"
12359+ _ASM_EXTABLE(0b, 0b)
12360+#endif
12361+
12362+ : "=r" (new)
12363+ : "0" (c));
12364+
12365+ val = atomic_cmpxchg(v, c, new);
12366+ if (val == c)
12367+ return 1;
12368+ c = val;
12369+ } while (c);
12370+
12371+ return 0;
12372+}
12373+
12374+/**
12375 * atomic_inc_short - increment of a short integer
12376 * @v: pointer to type int
12377 *
12378@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12379 #endif
12380
12381 /* These are x86-specific, used by some header files */
12382-#define atomic_clear_mask(mask, addr) \
12383- asm volatile(LOCK_PREFIX "andl %0,%1" \
12384- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12385+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12386+{
12387+ asm volatile(LOCK_PREFIX "andl %1,%0"
12388+ : "+m" (v->counter)
12389+ : "r" (~(mask))
12390+ : "memory");
12391+}
12392
12393-#define atomic_set_mask(mask, addr) \
12394- asm volatile(LOCK_PREFIX "orl %0,%1" \
12395- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12396- : "memory")
12397+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12398+{
12399+ asm volatile(LOCK_PREFIX "andl %1,%0"
12400+ : "+m" (v->counter)
12401+ : "r" (~(mask))
12402+ : "memory");
12403+}
12404+
12405+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12406+{
12407+ asm volatile(LOCK_PREFIX "orl %1,%0"
12408+ : "+m" (v->counter)
12409+ : "r" (mask)
12410+ : "memory");
12411+}
12412+
12413+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12414+{
12415+ asm volatile(LOCK_PREFIX "orl %1,%0"
12416+ : "+m" (v->counter)
12417+ : "r" (mask)
12418+ : "memory");
12419+}
12420
12421 /* Atomic operations are already serializing on x86 */
12422 #define smp_mb__before_atomic_dec() barrier()
12423diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12424index b154de7..aadebd8 100644
12425--- a/arch/x86/include/asm/atomic64_32.h
12426+++ b/arch/x86/include/asm/atomic64_32.h
12427@@ -12,6 +12,14 @@ typedef struct {
12428 u64 __aligned(8) counter;
12429 } atomic64_t;
12430
12431+#ifdef CONFIG_PAX_REFCOUNT
12432+typedef struct {
12433+ u64 __aligned(8) counter;
12434+} atomic64_unchecked_t;
12435+#else
12436+typedef atomic64_t atomic64_unchecked_t;
12437+#endif
12438+
12439 #define ATOMIC64_INIT(val) { (val) }
12440
12441 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12442@@ -37,21 +45,31 @@ typedef struct {
12443 ATOMIC64_DECL_ONE(sym##_386)
12444
12445 ATOMIC64_DECL_ONE(add_386);
12446+ATOMIC64_DECL_ONE(add_unchecked_386);
12447 ATOMIC64_DECL_ONE(sub_386);
12448+ATOMIC64_DECL_ONE(sub_unchecked_386);
12449 ATOMIC64_DECL_ONE(inc_386);
12450+ATOMIC64_DECL_ONE(inc_unchecked_386);
12451 ATOMIC64_DECL_ONE(dec_386);
12452+ATOMIC64_DECL_ONE(dec_unchecked_386);
12453 #endif
12454
12455 #define alternative_atomic64(f, out, in...) \
12456 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12457
12458 ATOMIC64_DECL(read);
12459+ATOMIC64_DECL(read_unchecked);
12460 ATOMIC64_DECL(set);
12461+ATOMIC64_DECL(set_unchecked);
12462 ATOMIC64_DECL(xchg);
12463 ATOMIC64_DECL(add_return);
12464+ATOMIC64_DECL(add_return_unchecked);
12465 ATOMIC64_DECL(sub_return);
12466+ATOMIC64_DECL(sub_return_unchecked);
12467 ATOMIC64_DECL(inc_return);
12468+ATOMIC64_DECL(inc_return_unchecked);
12469 ATOMIC64_DECL(dec_return);
12470+ATOMIC64_DECL(dec_return_unchecked);
12471 ATOMIC64_DECL(dec_if_positive);
12472 ATOMIC64_DECL(inc_not_zero);
12473 ATOMIC64_DECL(add_unless);
12474@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12475 }
12476
12477 /**
12478+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12479+ * @p: pointer to type atomic64_unchecked_t
12480+ * @o: expected value
12481+ * @n: new value
12482+ *
12483+ * Atomically sets @v to @n if it was equal to @o and returns
12484+ * the old value.
12485+ */
12486+
12487+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12488+{
12489+ return cmpxchg64(&v->counter, o, n);
12490+}
12491+
12492+/**
12493 * atomic64_xchg - xchg atomic64 variable
12494 * @v: pointer to type atomic64_t
12495 * @n: value to assign
12496@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12497 }
12498
12499 /**
12500+ * atomic64_set_unchecked - set atomic64 variable
12501+ * @v: pointer to type atomic64_unchecked_t
12502+ * @n: value to assign
12503+ *
12504+ * Atomically sets the value of @v to @n.
12505+ */
12506+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12507+{
12508+ unsigned high = (unsigned)(i >> 32);
12509+ unsigned low = (unsigned)i;
12510+ alternative_atomic64(set, /* no output */,
12511+ "S" (v), "b" (low), "c" (high)
12512+ : "eax", "edx", "memory");
12513+}
12514+
12515+/**
12516 * atomic64_read - read atomic64 variable
12517 * @v: pointer to type atomic64_t
12518 *
12519@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12520 }
12521
12522 /**
12523+ * atomic64_read_unchecked - read atomic64 variable
12524+ * @v: pointer to type atomic64_unchecked_t
12525+ *
12526+ * Atomically reads the value of @v and returns it.
12527+ */
12528+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12529+{
12530+ long long r;
12531+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12532+ return r;
12533+ }
12534+
12535+/**
12536 * atomic64_add_return - add and return
12537 * @i: integer value to add
12538 * @v: pointer to type atomic64_t
12539@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12540 return i;
12541 }
12542
12543+/**
12544+ * atomic64_add_return_unchecked - add and return
12545+ * @i: integer value to add
12546+ * @v: pointer to type atomic64_unchecked_t
12547+ *
12548+ * Atomically adds @i to @v and returns @i + *@v
12549+ */
12550+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12551+{
12552+ alternative_atomic64(add_return_unchecked,
12553+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12554+ ASM_NO_INPUT_CLOBBER("memory"));
12555+ return i;
12556+}
12557+
12558 /*
12559 * Other variants with different arithmetic operators:
12560 */
12561@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12562 return a;
12563 }
12564
12565+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12566+{
12567+ long long a;
12568+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12569+ "S" (v) : "memory", "ecx");
12570+ return a;
12571+}
12572+
12573 static inline long long atomic64_dec_return(atomic64_t *v)
12574 {
12575 long long a;
12576@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12577 }
12578
12579 /**
12580+ * atomic64_add_unchecked - add integer to atomic64 variable
12581+ * @i: integer value to add
12582+ * @v: pointer to type atomic64_unchecked_t
12583+ *
12584+ * Atomically adds @i to @v.
12585+ */
12586+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12587+{
12588+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12589+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12590+ ASM_NO_INPUT_CLOBBER("memory"));
12591+ return i;
12592+}
12593+
12594+/**
12595 * atomic64_sub - subtract the atomic64 variable
12596 * @i: integer value to subtract
12597 * @v: pointer to type atomic64_t
12598diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12599index 0e1cbfc..5623683 100644
12600--- a/arch/x86/include/asm/atomic64_64.h
12601+++ b/arch/x86/include/asm/atomic64_64.h
12602@@ -18,7 +18,19 @@
12603 */
12604 static inline long atomic64_read(const atomic64_t *v)
12605 {
12606- return (*(volatile long *)&(v)->counter);
12607+ return (*(volatile const long *)&(v)->counter);
12608+}
12609+
12610+/**
12611+ * atomic64_read_unchecked - read atomic64 variable
12612+ * @v: pointer of type atomic64_unchecked_t
12613+ *
12614+ * Atomically reads the value of @v.
12615+ * Doesn't imply a read memory barrier.
12616+ */
12617+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12618+{
12619+ return (*(volatile const long *)&(v)->counter);
12620 }
12621
12622 /**
12623@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12624 }
12625
12626 /**
12627+ * atomic64_set_unchecked - set atomic64 variable
12628+ * @v: pointer to type atomic64_unchecked_t
12629+ * @i: required value
12630+ *
12631+ * Atomically sets the value of @v to @i.
12632+ */
12633+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12634+{
12635+ v->counter = i;
12636+}
12637+
12638+/**
12639 * atomic64_add - add integer to atomic64 variable
12640 * @i: integer value to add
12641 * @v: pointer to type atomic64_t
12642@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12643 */
12644 static inline void atomic64_add(long i, atomic64_t *v)
12645 {
12646+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12647+
12648+#ifdef CONFIG_PAX_REFCOUNT
12649+ "jno 0f\n"
12650+ LOCK_PREFIX "subq %1,%0\n"
12651+ "int $4\n0:\n"
12652+ _ASM_EXTABLE(0b, 0b)
12653+#endif
12654+
12655+ : "=m" (v->counter)
12656+ : "er" (i), "m" (v->counter));
12657+}
12658+
12659+/**
12660+ * atomic64_add_unchecked - add integer to atomic64 variable
12661+ * @i: integer value to add
12662+ * @v: pointer to type atomic64_unchecked_t
12663+ *
12664+ * Atomically adds @i to @v.
12665+ */
12666+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12667+{
12668 asm volatile(LOCK_PREFIX "addq %1,%0"
12669 : "=m" (v->counter)
12670 : "er" (i), "m" (v->counter));
12671@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12672 */
12673 static inline void atomic64_sub(long i, atomic64_t *v)
12674 {
12675- asm volatile(LOCK_PREFIX "subq %1,%0"
12676+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12677+
12678+#ifdef CONFIG_PAX_REFCOUNT
12679+ "jno 0f\n"
12680+ LOCK_PREFIX "addq %1,%0\n"
12681+ "int $4\n0:\n"
12682+ _ASM_EXTABLE(0b, 0b)
12683+#endif
12684+
12685+ : "=m" (v->counter)
12686+ : "er" (i), "m" (v->counter));
12687+}
12688+
12689+/**
12690+ * atomic64_sub_unchecked - subtract the atomic64 variable
12691+ * @i: integer value to subtract
12692+ * @v: pointer to type atomic64_unchecked_t
12693+ *
12694+ * Atomically subtracts @i from @v.
12695+ */
12696+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12697+{
12698+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12699 : "=m" (v->counter)
12700 : "er" (i), "m" (v->counter));
12701 }
12702@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12703 {
12704 unsigned char c;
12705
12706- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12707+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12708+
12709+#ifdef CONFIG_PAX_REFCOUNT
12710+ "jno 0f\n"
12711+ LOCK_PREFIX "addq %2,%0\n"
12712+ "int $4\n0:\n"
12713+ _ASM_EXTABLE(0b, 0b)
12714+#endif
12715+
12716+ "sete %1\n"
12717 : "=m" (v->counter), "=qm" (c)
12718 : "er" (i), "m" (v->counter) : "memory");
12719 return c;
12720@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12721 */
12722 static inline void atomic64_inc(atomic64_t *v)
12723 {
12724+ asm volatile(LOCK_PREFIX "incq %0\n"
12725+
12726+#ifdef CONFIG_PAX_REFCOUNT
12727+ "jno 0f\n"
12728+ LOCK_PREFIX "decq %0\n"
12729+ "int $4\n0:\n"
12730+ _ASM_EXTABLE(0b, 0b)
12731+#endif
12732+
12733+ : "=m" (v->counter)
12734+ : "m" (v->counter));
12735+}
12736+
12737+/**
12738+ * atomic64_inc_unchecked - increment atomic64 variable
12739+ * @v: pointer to type atomic64_unchecked_t
12740+ *
12741+ * Atomically increments @v by 1.
12742+ */
12743+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12744+{
12745 asm volatile(LOCK_PREFIX "incq %0"
12746 : "=m" (v->counter)
12747 : "m" (v->counter));
12748@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12749 */
12750 static inline void atomic64_dec(atomic64_t *v)
12751 {
12752- asm volatile(LOCK_PREFIX "decq %0"
12753+ asm volatile(LOCK_PREFIX "decq %0\n"
12754+
12755+#ifdef CONFIG_PAX_REFCOUNT
12756+ "jno 0f\n"
12757+ LOCK_PREFIX "incq %0\n"
12758+ "int $4\n0:\n"
12759+ _ASM_EXTABLE(0b, 0b)
12760+#endif
12761+
12762+ : "=m" (v->counter)
12763+ : "m" (v->counter));
12764+}
12765+
12766+/**
12767+ * atomic64_dec_unchecked - decrement atomic64 variable
12768+ * @v: pointer to type atomic64_t
12769+ *
12770+ * Atomically decrements @v by 1.
12771+ */
12772+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12773+{
12774+ asm volatile(LOCK_PREFIX "decq %0\n"
12775 : "=m" (v->counter)
12776 : "m" (v->counter));
12777 }
12778@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12779 {
12780 unsigned char c;
12781
12782- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12783+ asm volatile(LOCK_PREFIX "decq %0\n"
12784+
12785+#ifdef CONFIG_PAX_REFCOUNT
12786+ "jno 0f\n"
12787+ LOCK_PREFIX "incq %0\n"
12788+ "int $4\n0:\n"
12789+ _ASM_EXTABLE(0b, 0b)
12790+#endif
12791+
12792+ "sete %1\n"
12793 : "=m" (v->counter), "=qm" (c)
12794 : "m" (v->counter) : "memory");
12795 return c != 0;
12796@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12797 {
12798 unsigned char c;
12799
12800- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12801+ asm volatile(LOCK_PREFIX "incq %0\n"
12802+
12803+#ifdef CONFIG_PAX_REFCOUNT
12804+ "jno 0f\n"
12805+ LOCK_PREFIX "decq %0\n"
12806+ "int $4\n0:\n"
12807+ _ASM_EXTABLE(0b, 0b)
12808+#endif
12809+
12810+ "sete %1\n"
12811 : "=m" (v->counter), "=qm" (c)
12812 : "m" (v->counter) : "memory");
12813 return c != 0;
12814@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12815 {
12816 unsigned char c;
12817
12818- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12819+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12820+
12821+#ifdef CONFIG_PAX_REFCOUNT
12822+ "jno 0f\n"
12823+ LOCK_PREFIX "subq %2,%0\n"
12824+ "int $4\n0:\n"
12825+ _ASM_EXTABLE(0b, 0b)
12826+#endif
12827+
12828+ "sets %1\n"
12829 : "=m" (v->counter), "=qm" (c)
12830 : "er" (i), "m" (v->counter) : "memory");
12831 return c;
12832@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12833 */
12834 static inline long atomic64_add_return(long i, atomic64_t *v)
12835 {
12836+ return i + xadd_check_overflow(&v->counter, i);
12837+}
12838+
12839+/**
12840+ * atomic64_add_return_unchecked - add and return
12841+ * @i: integer value to add
12842+ * @v: pointer to type atomic64_unchecked_t
12843+ *
12844+ * Atomically adds @i to @v and returns @i + @v
12845+ */
12846+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12847+{
12848 return i + xadd(&v->counter, i);
12849 }
12850
12851@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12852 }
12853
12854 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12855+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12856+{
12857+ return atomic64_add_return_unchecked(1, v);
12858+}
12859 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12860
12861 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12862@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12863 return cmpxchg(&v->counter, old, new);
12864 }
12865
12866+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12867+{
12868+ return cmpxchg(&v->counter, old, new);
12869+}
12870+
12871 static inline long atomic64_xchg(atomic64_t *v, long new)
12872 {
12873 return xchg(&v->counter, new);
12874@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12875 */
12876 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12877 {
12878- long c, old;
12879+ long c, old, new;
12880 c = atomic64_read(v);
12881 for (;;) {
12882- if (unlikely(c == (u)))
12883+ if (unlikely(c == u))
12884 break;
12885- old = atomic64_cmpxchg((v), c, c + (a));
12886+
12887+ asm volatile("add %2,%0\n"
12888+
12889+#ifdef CONFIG_PAX_REFCOUNT
12890+ "jno 0f\n"
12891+ "sub %2,%0\n"
12892+ "int $4\n0:\n"
12893+ _ASM_EXTABLE(0b, 0b)
12894+#endif
12895+
12896+ : "=r" (new)
12897+ : "0" (c), "ir" (a));
12898+
12899+ old = atomic64_cmpxchg(v, c, new);
12900 if (likely(old == c))
12901 break;
12902 c = old;
12903 }
12904- return c != (u);
12905+ return c != u;
12906 }
12907
12908 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12909diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12910index 6dfd019..28e188d 100644
12911--- a/arch/x86/include/asm/bitops.h
12912+++ b/arch/x86/include/asm/bitops.h
12913@@ -40,7 +40,7 @@
12914 * a mask operation on a byte.
12915 */
12916 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12917-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12918+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12919 #define CONST_MASK(nr) (1 << ((nr) & 7))
12920
12921 /**
12922@@ -486,7 +486,7 @@ static inline int fls(int x)
12923 * at position 64.
12924 */
12925 #ifdef CONFIG_X86_64
12926-static __always_inline int fls64(__u64 x)
12927+static __always_inline long fls64(__u64 x)
12928 {
12929 int bitpos = -1;
12930 /*
12931diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12932index 4fa687a..60f2d39 100644
12933--- a/arch/x86/include/asm/boot.h
12934+++ b/arch/x86/include/asm/boot.h
12935@@ -6,10 +6,15 @@
12936 #include <uapi/asm/boot.h>
12937
12938 /* Physical address where kernel should be loaded. */
12939-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12940+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12941 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12942 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12943
12944+#ifndef __ASSEMBLY__
12945+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12946+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12947+#endif
12948+
12949 /* Minimum kernel alignment, as a power of two */
12950 #ifdef CONFIG_X86_64
12951 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12952diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12953index 48f99f1..d78ebf9 100644
12954--- a/arch/x86/include/asm/cache.h
12955+++ b/arch/x86/include/asm/cache.h
12956@@ -5,12 +5,13 @@
12957
12958 /* L1 cache line size */
12959 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12960-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12961+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12962
12963 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12964+#define __read_only __attribute__((__section__(".data..read_only")))
12965
12966 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12967-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12968+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12969
12970 #ifdef CONFIG_X86_VSMP
12971 #ifdef CONFIG_SMP
12972diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12973index 9863ee3..4a1f8e1 100644
12974--- a/arch/x86/include/asm/cacheflush.h
12975+++ b/arch/x86/include/asm/cacheflush.h
12976@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12977 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12978
12979 if (pg_flags == _PGMT_DEFAULT)
12980- return -1;
12981+ return ~0UL;
12982 else if (pg_flags == _PGMT_WC)
12983 return _PAGE_CACHE_WC;
12984 else if (pg_flags == _PGMT_UC_MINUS)
12985diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12986index 46fc474..b02b0f9 100644
12987--- a/arch/x86/include/asm/checksum_32.h
12988+++ b/arch/x86/include/asm/checksum_32.h
12989@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12990 int len, __wsum sum,
12991 int *src_err_ptr, int *dst_err_ptr);
12992
12993+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12994+ int len, __wsum sum,
12995+ int *src_err_ptr, int *dst_err_ptr);
12996+
12997+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12998+ int len, __wsum sum,
12999+ int *src_err_ptr, int *dst_err_ptr);
13000+
13001 /*
13002 * Note: when you get a NULL pointer exception here this means someone
13003 * passed in an incorrect kernel address to one of these functions.
13004@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
13005 int *err_ptr)
13006 {
13007 might_sleep();
13008- return csum_partial_copy_generic((__force void *)src, dst,
13009+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
13010 len, sum, err_ptr, NULL);
13011 }
13012
13013@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
13014 {
13015 might_sleep();
13016 if (access_ok(VERIFY_WRITE, dst, len))
13017- return csum_partial_copy_generic(src, (__force void *)dst,
13018+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
13019 len, sum, NULL, err_ptr);
13020
13021 if (len)
13022diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
13023index d47786a..ce1b05d 100644
13024--- a/arch/x86/include/asm/cmpxchg.h
13025+++ b/arch/x86/include/asm/cmpxchg.h
13026@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
13027 __compiletime_error("Bad argument size for cmpxchg");
13028 extern void __xadd_wrong_size(void)
13029 __compiletime_error("Bad argument size for xadd");
13030+extern void __xadd_check_overflow_wrong_size(void)
13031+ __compiletime_error("Bad argument size for xadd_check_overflow");
13032 extern void __add_wrong_size(void)
13033 __compiletime_error("Bad argument size for add");
13034+extern void __add_check_overflow_wrong_size(void)
13035+ __compiletime_error("Bad argument size for add_check_overflow");
13036
13037 /*
13038 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
13039@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
13040 __ret; \
13041 })
13042
13043+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
13044+ ({ \
13045+ __typeof__ (*(ptr)) __ret = (arg); \
13046+ switch (sizeof(*(ptr))) { \
13047+ case __X86_CASE_L: \
13048+ asm volatile (lock #op "l %0, %1\n" \
13049+ "jno 0f\n" \
13050+ "mov %0,%1\n" \
13051+ "int $4\n0:\n" \
13052+ _ASM_EXTABLE(0b, 0b) \
13053+ : "+r" (__ret), "+m" (*(ptr)) \
13054+ : : "memory", "cc"); \
13055+ break; \
13056+ case __X86_CASE_Q: \
13057+ asm volatile (lock #op "q %q0, %1\n" \
13058+ "jno 0f\n" \
13059+ "mov %0,%1\n" \
13060+ "int $4\n0:\n" \
13061+ _ASM_EXTABLE(0b, 0b) \
13062+ : "+r" (__ret), "+m" (*(ptr)) \
13063+ : : "memory", "cc"); \
13064+ break; \
13065+ default: \
13066+ __ ## op ## _check_overflow_wrong_size(); \
13067+ } \
13068+ __ret; \
13069+ })
13070+
13071 /*
13072 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
13073 * Since this is generally used to protect other memory information, we
13074@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
13075 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
13076 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
13077
13078+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
13079+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
13080+
13081 #define __add(ptr, inc, lock) \
13082 ({ \
13083 __typeof__ (*(ptr)) __ret = (inc); \
13084diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
13085index 59c6c40..5e0b22c 100644
13086--- a/arch/x86/include/asm/compat.h
13087+++ b/arch/x86/include/asm/compat.h
13088@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
13089 typedef u32 compat_uint_t;
13090 typedef u32 compat_ulong_t;
13091 typedef u64 __attribute__((aligned(4))) compat_u64;
13092-typedef u32 compat_uptr_t;
13093+typedef u32 __user compat_uptr_t;
13094
13095 struct compat_timespec {
13096 compat_time_t tv_sec;
13097diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
13098index e99ac27..e89e28c 100644
13099--- a/arch/x86/include/asm/cpufeature.h
13100+++ b/arch/x86/include/asm/cpufeature.h
13101@@ -211,7 +211,7 @@
13102 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
13103 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
13104 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
13105-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
13106+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
13107 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
13108 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
13109 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
13110@@ -394,7 +394,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
13111 ".section .discard,\"aw\",@progbits\n"
13112 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
13113 ".previous\n"
13114- ".section .altinstr_replacement,\"ax\"\n"
13115+ ".section .altinstr_replacement,\"a\"\n"
13116 "3: movb $1,%0\n"
13117 "4:\n"
13118 ".previous\n"
13119diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
13120index 8bf1c06..b6ae785 100644
13121--- a/arch/x86/include/asm/desc.h
13122+++ b/arch/x86/include/asm/desc.h
13123@@ -4,6 +4,7 @@
13124 #include <asm/desc_defs.h>
13125 #include <asm/ldt.h>
13126 #include <asm/mmu.h>
13127+#include <asm/pgtable.h>
13128
13129 #include <linux/smp.h>
13130 #include <linux/percpu.h>
13131@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13132
13133 desc->type = (info->read_exec_only ^ 1) << 1;
13134 desc->type |= info->contents << 2;
13135+ desc->type |= info->seg_not_present ^ 1;
13136
13137 desc->s = 1;
13138 desc->dpl = 0x3;
13139@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13140 }
13141
13142 extern struct desc_ptr idt_descr;
13143-extern gate_desc idt_table[];
13144 extern struct desc_ptr nmi_idt_descr;
13145-extern gate_desc nmi_idt_table[];
13146-
13147-struct gdt_page {
13148- struct desc_struct gdt[GDT_ENTRIES];
13149-} __attribute__((aligned(PAGE_SIZE)));
13150-
13151-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13152+extern gate_desc idt_table[256];
13153+extern gate_desc nmi_idt_table[256];
13154
13155+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13156 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13157 {
13158- return per_cpu(gdt_page, cpu).gdt;
13159+ return cpu_gdt_table[cpu];
13160 }
13161
13162 #ifdef CONFIG_X86_64
13163@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13164 unsigned long base, unsigned dpl, unsigned flags,
13165 unsigned short seg)
13166 {
13167- gate->a = (seg << 16) | (base & 0xffff);
13168- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13169+ gate->gate.offset_low = base;
13170+ gate->gate.seg = seg;
13171+ gate->gate.reserved = 0;
13172+ gate->gate.type = type;
13173+ gate->gate.s = 0;
13174+ gate->gate.dpl = dpl;
13175+ gate->gate.p = 1;
13176+ gate->gate.offset_high = base >> 16;
13177 }
13178
13179 #endif
13180@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13181
13182 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13183 {
13184+ pax_open_kernel();
13185 memcpy(&idt[entry], gate, sizeof(*gate));
13186+ pax_close_kernel();
13187 }
13188
13189 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13190 {
13191+ pax_open_kernel();
13192 memcpy(&ldt[entry], desc, 8);
13193+ pax_close_kernel();
13194 }
13195
13196 static inline void
13197@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13198 default: size = sizeof(*gdt); break;
13199 }
13200
13201+ pax_open_kernel();
13202 memcpy(&gdt[entry], desc, size);
13203+ pax_close_kernel();
13204 }
13205
13206 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13207@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13208
13209 static inline void native_load_tr_desc(void)
13210 {
13211+ pax_open_kernel();
13212 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13213+ pax_close_kernel();
13214 }
13215
13216 static inline void native_load_gdt(const struct desc_ptr *dtr)
13217@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13218 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13219 unsigned int i;
13220
13221+ pax_open_kernel();
13222 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13223 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13224+ pax_close_kernel();
13225 }
13226
13227 #define _LDT_empty(info) \
13228@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13229 preempt_enable();
13230 }
13231
13232-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13233+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13234 {
13235 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13236 }
13237@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13238 }
13239
13240 #ifdef CONFIG_X86_64
13241-static inline void set_nmi_gate(int gate, void *addr)
13242+static inline void set_nmi_gate(int gate, const void *addr)
13243 {
13244 gate_desc s;
13245
13246@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13247 }
13248 #endif
13249
13250-static inline void _set_gate(int gate, unsigned type, void *addr,
13251+static inline void _set_gate(int gate, unsigned type, const void *addr,
13252 unsigned dpl, unsigned ist, unsigned seg)
13253 {
13254 gate_desc s;
13255@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13256 * Pentium F0 0F bugfix can have resulted in the mapped
13257 * IDT being write-protected.
13258 */
13259-static inline void set_intr_gate(unsigned int n, void *addr)
13260+static inline void set_intr_gate(unsigned int n, const void *addr)
13261 {
13262 BUG_ON((unsigned)n > 0xFF);
13263 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13264@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13265 /*
13266 * This routine sets up an interrupt gate at directory privilege level 3.
13267 */
13268-static inline void set_system_intr_gate(unsigned int n, void *addr)
13269+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13270 {
13271 BUG_ON((unsigned)n > 0xFF);
13272 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13273 }
13274
13275-static inline void set_system_trap_gate(unsigned int n, void *addr)
13276+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13277 {
13278 BUG_ON((unsigned)n > 0xFF);
13279 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13280 }
13281
13282-static inline void set_trap_gate(unsigned int n, void *addr)
13283+static inline void set_trap_gate(unsigned int n, const void *addr)
13284 {
13285 BUG_ON((unsigned)n > 0xFF);
13286 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13287@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13288 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13289 {
13290 BUG_ON((unsigned)n > 0xFF);
13291- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13292+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13293 }
13294
13295-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13296+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13297 {
13298 BUG_ON((unsigned)n > 0xFF);
13299 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13300 }
13301
13302-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13303+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13304 {
13305 BUG_ON((unsigned)n > 0xFF);
13306 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13307 }
13308
13309+#ifdef CONFIG_X86_32
13310+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13311+{
13312+ struct desc_struct d;
13313+
13314+ if (likely(limit))
13315+ limit = (limit - 1UL) >> PAGE_SHIFT;
13316+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13317+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13318+}
13319+#endif
13320+
13321 #endif /* _ASM_X86_DESC_H */
13322diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13323index 278441f..b95a174 100644
13324--- a/arch/x86/include/asm/desc_defs.h
13325+++ b/arch/x86/include/asm/desc_defs.h
13326@@ -31,6 +31,12 @@ struct desc_struct {
13327 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13328 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13329 };
13330+ struct {
13331+ u16 offset_low;
13332+ u16 seg;
13333+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13334+ unsigned offset_high: 16;
13335+ } gate;
13336 };
13337 } __attribute__((packed));
13338
13339diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13340index ced283a..ffe04cc 100644
13341--- a/arch/x86/include/asm/div64.h
13342+++ b/arch/x86/include/asm/div64.h
13343@@ -39,7 +39,7 @@
13344 __mod; \
13345 })
13346
13347-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13348+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13349 {
13350 union {
13351 u64 v64;
13352diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13353index 9c999c1..3860cb8 100644
13354--- a/arch/x86/include/asm/elf.h
13355+++ b/arch/x86/include/asm/elf.h
13356@@ -243,7 +243,25 @@ extern int force_personality32;
13357 the loader. We need to make sure that it is out of the way of the program
13358 that it will "exec", and that there is sufficient room for the brk. */
13359
13360+#ifdef CONFIG_PAX_SEGMEXEC
13361+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13362+#else
13363 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13364+#endif
13365+
13366+#ifdef CONFIG_PAX_ASLR
13367+#ifdef CONFIG_X86_32
13368+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13369+
13370+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13371+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13372+#else
13373+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13374+
13375+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13376+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13377+#endif
13378+#endif
13379
13380 /* This yields a mask that user programs can use to figure out what
13381 instruction set this CPU supports. This could be done in user space,
13382@@ -296,16 +314,12 @@ do { \
13383
13384 #define ARCH_DLINFO \
13385 do { \
13386- if (vdso_enabled) \
13387- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13388- (unsigned long)current->mm->context.vdso); \
13389+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13390 } while (0)
13391
13392 #define ARCH_DLINFO_X32 \
13393 do { \
13394- if (vdso_enabled) \
13395- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13396- (unsigned long)current->mm->context.vdso); \
13397+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13398 } while (0)
13399
13400 #define AT_SYSINFO 32
13401@@ -320,7 +334,7 @@ else \
13402
13403 #endif /* !CONFIG_X86_32 */
13404
13405-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13406+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13407
13408 #define VDSO_ENTRY \
13409 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13410@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13411 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13412 #define compat_arch_setup_additional_pages syscall32_setup_pages
13413
13414-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13415-#define arch_randomize_brk arch_randomize_brk
13416-
13417 /*
13418 * True on X86_32 or when emulating IA32 on X86_64
13419 */
13420diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13421index 75ce3f4..882e801 100644
13422--- a/arch/x86/include/asm/emergency-restart.h
13423+++ b/arch/x86/include/asm/emergency-restart.h
13424@@ -13,6 +13,6 @@ enum reboot_type {
13425
13426 extern enum reboot_type reboot_type;
13427
13428-extern void machine_emergency_restart(void);
13429+extern void machine_emergency_restart(void) __noreturn;
13430
13431 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13432diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13433index e25cc33..425d099 100644
13434--- a/arch/x86/include/asm/fpu-internal.h
13435+++ b/arch/x86/include/asm/fpu-internal.h
13436@@ -127,7 +127,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13437 ({ \
13438 int err; \
13439 asm volatile(ASM_STAC "\n" \
13440- "1:" #insn "\n\t" \
13441+ "1:" \
13442+ __copyuser_seg \
13443+ #insn "\n\t" \
13444 "2: " ASM_CLAC "\n" \
13445 ".section .fixup,\"ax\"\n" \
13446 "3: movl $-1,%[err]\n" \
13447@@ -300,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13448 "emms\n\t" /* clear stack tags */
13449 "fildl %P[addr]", /* set F?P to defined value */
13450 X86_FEATURE_FXSAVE_LEAK,
13451- [addr] "m" (tsk->thread.fpu.has_fpu));
13452+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13453
13454 return fpu_restore_checking(&tsk->thread.fpu);
13455 }
13456diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13457index be27ba1..8f13ff9 100644
13458--- a/arch/x86/include/asm/futex.h
13459+++ b/arch/x86/include/asm/futex.h
13460@@ -12,6 +12,7 @@
13461 #include <asm/smap.h>
13462
13463 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13464+ typecheck(u32 __user *, uaddr); \
13465 asm volatile("\t" ASM_STAC "\n" \
13466 "1:\t" insn "\n" \
13467 "2:\t" ASM_CLAC "\n" \
13468@@ -20,15 +21,16 @@
13469 "\tjmp\t2b\n" \
13470 "\t.previous\n" \
13471 _ASM_EXTABLE(1b, 3b) \
13472- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13473+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13474 : "i" (-EFAULT), "0" (oparg), "1" (0))
13475
13476 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13477+ typecheck(u32 __user *, uaddr); \
13478 asm volatile("\t" ASM_STAC "\n" \
13479 "1:\tmovl %2, %0\n" \
13480 "\tmovl\t%0, %3\n" \
13481 "\t" insn "\n" \
13482- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13483+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13484 "\tjnz\t1b\n" \
13485 "3:\t" ASM_CLAC "\n" \
13486 "\t.section .fixup,\"ax\"\n" \
13487@@ -38,7 +40,7 @@
13488 _ASM_EXTABLE(1b, 4b) \
13489 _ASM_EXTABLE(2b, 4b) \
13490 : "=&a" (oldval), "=&r" (ret), \
13491- "+m" (*uaddr), "=&r" (tem) \
13492+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13493 : "r" (oparg), "i" (-EFAULT), "1" (0))
13494
13495 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13496@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13497
13498 switch (op) {
13499 case FUTEX_OP_SET:
13500- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13501+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13502 break;
13503 case FUTEX_OP_ADD:
13504- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13505+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13506 uaddr, oparg);
13507 break;
13508 case FUTEX_OP_OR:
13509@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13510 return -EFAULT;
13511
13512 asm volatile("\t" ASM_STAC "\n"
13513- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13514+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13515 "2:\t" ASM_CLAC "\n"
13516 "\t.section .fixup, \"ax\"\n"
13517 "3:\tmov %3, %0\n"
13518 "\tjmp 2b\n"
13519 "\t.previous\n"
13520 _ASM_EXTABLE(1b, 3b)
13521- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13522+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13523 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13524 : "memory"
13525 );
13526diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13527index 1da97ef..9c2ebff 100644
13528--- a/arch/x86/include/asm/hw_irq.h
13529+++ b/arch/x86/include/asm/hw_irq.h
13530@@ -148,8 +148,8 @@ extern void setup_ioapic_dest(void);
13531 extern void enable_IO_APIC(void);
13532
13533 /* Statistics */
13534-extern atomic_t irq_err_count;
13535-extern atomic_t irq_mis_count;
13536+extern atomic_unchecked_t irq_err_count;
13537+extern atomic_unchecked_t irq_mis_count;
13538
13539 /* EISA */
13540 extern void eisa_set_level_irq(unsigned int irq);
13541diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13542index a203659..9889f1c 100644
13543--- a/arch/x86/include/asm/i8259.h
13544+++ b/arch/x86/include/asm/i8259.h
13545@@ -62,7 +62,7 @@ struct legacy_pic {
13546 void (*init)(int auto_eoi);
13547 int (*irq_pending)(unsigned int irq);
13548 void (*make_irq)(unsigned int irq);
13549-};
13550+} __do_const;
13551
13552 extern struct legacy_pic *legacy_pic;
13553 extern struct legacy_pic null_legacy_pic;
13554diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13555index d8e8eef..1765f78 100644
13556--- a/arch/x86/include/asm/io.h
13557+++ b/arch/x86/include/asm/io.h
13558@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13559 "m" (*(volatile type __force *)addr) barrier); }
13560
13561 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13562-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13563-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13564+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13565+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13566
13567 build_mmio_read(__readb, "b", unsigned char, "=q", )
13568-build_mmio_read(__readw, "w", unsigned short, "=r", )
13569-build_mmio_read(__readl, "l", unsigned int, "=r", )
13570+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13571+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13572
13573 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13574 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13575@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13576 return ioremap_nocache(offset, size);
13577 }
13578
13579-extern void iounmap(volatile void __iomem *addr);
13580+extern void iounmap(const volatile void __iomem *addr);
13581
13582 extern void set_iounmap_nonlazy(void);
13583
13584@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13585
13586 #include <linux/vmalloc.h>
13587
13588+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13589+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13590+{
13591+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13592+}
13593+
13594+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13595+{
13596+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13597+}
13598+
13599 /*
13600 * Convert a virtual cached pointer to an uncached pointer
13601 */
13602diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13603index bba3cf8..06bc8da 100644
13604--- a/arch/x86/include/asm/irqflags.h
13605+++ b/arch/x86/include/asm/irqflags.h
13606@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13607 sti; \
13608 sysexit
13609
13610+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13611+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13612+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13613+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13614+
13615 #else
13616 #define INTERRUPT_RETURN iret
13617 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13618diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13619index 5a6d287..f815789 100644
13620--- a/arch/x86/include/asm/kprobes.h
13621+++ b/arch/x86/include/asm/kprobes.h
13622@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13623 #define RELATIVEJUMP_SIZE 5
13624 #define RELATIVECALL_OPCODE 0xe8
13625 #define RELATIVE_ADDR_SIZE 4
13626-#define MAX_STACK_SIZE 64
13627-#define MIN_STACK_SIZE(ADDR) \
13628- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13629- THREAD_SIZE - (unsigned long)(ADDR))) \
13630- ? (MAX_STACK_SIZE) \
13631- : (((unsigned long)current_thread_info()) + \
13632- THREAD_SIZE - (unsigned long)(ADDR)))
13633+#define MAX_STACK_SIZE 64UL
13634+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13635
13636 #define flush_insn_slot(p) do { } while (0)
13637
13638diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13639index 2d89e39..baee879 100644
13640--- a/arch/x86/include/asm/local.h
13641+++ b/arch/x86/include/asm/local.h
13642@@ -10,33 +10,97 @@ typedef struct {
13643 atomic_long_t a;
13644 } local_t;
13645
13646+typedef struct {
13647+ atomic_long_unchecked_t a;
13648+} local_unchecked_t;
13649+
13650 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13651
13652 #define local_read(l) atomic_long_read(&(l)->a)
13653+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13654 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13655+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13656
13657 static inline void local_inc(local_t *l)
13658 {
13659- asm volatile(_ASM_INC "%0"
13660+ asm volatile(_ASM_INC "%0\n"
13661+
13662+#ifdef CONFIG_PAX_REFCOUNT
13663+ "jno 0f\n"
13664+ _ASM_DEC "%0\n"
13665+ "int $4\n0:\n"
13666+ _ASM_EXTABLE(0b, 0b)
13667+#endif
13668+
13669+ : "+m" (l->a.counter));
13670+}
13671+
13672+static inline void local_inc_unchecked(local_unchecked_t *l)
13673+{
13674+ asm volatile(_ASM_INC "%0\n"
13675 : "+m" (l->a.counter));
13676 }
13677
13678 static inline void local_dec(local_t *l)
13679 {
13680- asm volatile(_ASM_DEC "%0"
13681+ asm volatile(_ASM_DEC "%0\n"
13682+
13683+#ifdef CONFIG_PAX_REFCOUNT
13684+ "jno 0f\n"
13685+ _ASM_INC "%0\n"
13686+ "int $4\n0:\n"
13687+ _ASM_EXTABLE(0b, 0b)
13688+#endif
13689+
13690+ : "+m" (l->a.counter));
13691+}
13692+
13693+static inline void local_dec_unchecked(local_unchecked_t *l)
13694+{
13695+ asm volatile(_ASM_DEC "%0\n"
13696 : "+m" (l->a.counter));
13697 }
13698
13699 static inline void local_add(long i, local_t *l)
13700 {
13701- asm volatile(_ASM_ADD "%1,%0"
13702+ asm volatile(_ASM_ADD "%1,%0\n"
13703+
13704+#ifdef CONFIG_PAX_REFCOUNT
13705+ "jno 0f\n"
13706+ _ASM_SUB "%1,%0\n"
13707+ "int $4\n0:\n"
13708+ _ASM_EXTABLE(0b, 0b)
13709+#endif
13710+
13711+ : "+m" (l->a.counter)
13712+ : "ir" (i));
13713+}
13714+
13715+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13716+{
13717+ asm volatile(_ASM_ADD "%1,%0\n"
13718 : "+m" (l->a.counter)
13719 : "ir" (i));
13720 }
13721
13722 static inline void local_sub(long i, local_t *l)
13723 {
13724- asm volatile(_ASM_SUB "%1,%0"
13725+ asm volatile(_ASM_SUB "%1,%0\n"
13726+
13727+#ifdef CONFIG_PAX_REFCOUNT
13728+ "jno 0f\n"
13729+ _ASM_ADD "%1,%0\n"
13730+ "int $4\n0:\n"
13731+ _ASM_EXTABLE(0b, 0b)
13732+#endif
13733+
13734+ : "+m" (l->a.counter)
13735+ : "ir" (i));
13736+}
13737+
13738+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13739+{
13740+ asm volatile(_ASM_SUB "%1,%0\n"
13741 : "+m" (l->a.counter)
13742 : "ir" (i));
13743 }
13744@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13745 {
13746 unsigned char c;
13747
13748- asm volatile(_ASM_SUB "%2,%0; sete %1"
13749+ asm volatile(_ASM_SUB "%2,%0\n"
13750+
13751+#ifdef CONFIG_PAX_REFCOUNT
13752+ "jno 0f\n"
13753+ _ASM_ADD "%2,%0\n"
13754+ "int $4\n0:\n"
13755+ _ASM_EXTABLE(0b, 0b)
13756+#endif
13757+
13758+ "sete %1\n"
13759 : "+m" (l->a.counter), "=qm" (c)
13760 : "ir" (i) : "memory");
13761 return c;
13762@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13763 {
13764 unsigned char c;
13765
13766- asm volatile(_ASM_DEC "%0; sete %1"
13767+ asm volatile(_ASM_DEC "%0\n"
13768+
13769+#ifdef CONFIG_PAX_REFCOUNT
13770+ "jno 0f\n"
13771+ _ASM_INC "%0\n"
13772+ "int $4\n0:\n"
13773+ _ASM_EXTABLE(0b, 0b)
13774+#endif
13775+
13776+ "sete %1\n"
13777 : "+m" (l->a.counter), "=qm" (c)
13778 : : "memory");
13779 return c != 0;
13780@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13781 {
13782 unsigned char c;
13783
13784- asm volatile(_ASM_INC "%0; sete %1"
13785+ asm volatile(_ASM_INC "%0\n"
13786+
13787+#ifdef CONFIG_PAX_REFCOUNT
13788+ "jno 0f\n"
13789+ _ASM_DEC "%0\n"
13790+ "int $4\n0:\n"
13791+ _ASM_EXTABLE(0b, 0b)
13792+#endif
13793+
13794+ "sete %1\n"
13795 : "+m" (l->a.counter), "=qm" (c)
13796 : : "memory");
13797 return c != 0;
13798@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13799 {
13800 unsigned char c;
13801
13802- asm volatile(_ASM_ADD "%2,%0; sets %1"
13803+ asm volatile(_ASM_ADD "%2,%0\n"
13804+
13805+#ifdef CONFIG_PAX_REFCOUNT
13806+ "jno 0f\n"
13807+ _ASM_SUB "%2,%0\n"
13808+ "int $4\n0:\n"
13809+ _ASM_EXTABLE(0b, 0b)
13810+#endif
13811+
13812+ "sets %1\n"
13813 : "+m" (l->a.counter), "=qm" (c)
13814 : "ir" (i) : "memory");
13815 return c;
13816@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13817 static inline long local_add_return(long i, local_t *l)
13818 {
13819 long __i = i;
13820+ asm volatile(_ASM_XADD "%0, %1\n"
13821+
13822+#ifdef CONFIG_PAX_REFCOUNT
13823+ "jno 0f\n"
13824+ _ASM_MOV "%0,%1\n"
13825+ "int $4\n0:\n"
13826+ _ASM_EXTABLE(0b, 0b)
13827+#endif
13828+
13829+ : "+r" (i), "+m" (l->a.counter)
13830+ : : "memory");
13831+ return i + __i;
13832+}
13833+
13834+/**
13835+ * local_add_return_unchecked - add and return
13836+ * @i: integer value to add
13837+ * @l: pointer to type local_unchecked_t
13838+ *
13839+ * Atomically adds @i to @l and returns @i + @l
13840+ */
13841+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13842+{
13843+ long __i = i;
13844 asm volatile(_ASM_XADD "%0, %1;"
13845 : "+r" (i), "+m" (l->a.counter)
13846 : : "memory");
13847@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13848
13849 #define local_cmpxchg(l, o, n) \
13850 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13851+#define local_cmpxchg_unchecked(l, o, n) \
13852+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13853 /* Always has a lock prefix */
13854 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13855
13856diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13857new file mode 100644
13858index 0000000..2bfd3ba
13859--- /dev/null
13860+++ b/arch/x86/include/asm/mman.h
13861@@ -0,0 +1,15 @@
13862+#ifndef _X86_MMAN_H
13863+#define _X86_MMAN_H
13864+
13865+#include <uapi/asm/mman.h>
13866+
13867+#ifdef __KERNEL__
13868+#ifndef __ASSEMBLY__
13869+#ifdef CONFIG_X86_32
13870+#define arch_mmap_check i386_mmap_check
13871+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13872+#endif
13873+#endif
13874+#endif
13875+
13876+#endif /* X86_MMAN_H */
13877diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13878index 5f55e69..e20bfb1 100644
13879--- a/arch/x86/include/asm/mmu.h
13880+++ b/arch/x86/include/asm/mmu.h
13881@@ -9,7 +9,7 @@
13882 * we put the segment information here.
13883 */
13884 typedef struct {
13885- void *ldt;
13886+ struct desc_struct *ldt;
13887 int size;
13888
13889 #ifdef CONFIG_X86_64
13890@@ -18,7 +18,19 @@ typedef struct {
13891 #endif
13892
13893 struct mutex lock;
13894- void *vdso;
13895+ unsigned long vdso;
13896+
13897+#ifdef CONFIG_X86_32
13898+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13899+ unsigned long user_cs_base;
13900+ unsigned long user_cs_limit;
13901+
13902+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13903+ cpumask_t cpu_user_cs_mask;
13904+#endif
13905+
13906+#endif
13907+#endif
13908 } mm_context_t;
13909
13910 #ifdef CONFIG_SMP
13911diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13912index cdbf367..adb37ac 100644
13913--- a/arch/x86/include/asm/mmu_context.h
13914+++ b/arch/x86/include/asm/mmu_context.h
13915@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13916
13917 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13918 {
13919+
13920+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13921+ unsigned int i;
13922+ pgd_t *pgd;
13923+
13924+ pax_open_kernel();
13925+ pgd = get_cpu_pgd(smp_processor_id());
13926+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13927+ set_pgd_batched(pgd+i, native_make_pgd(0));
13928+ pax_close_kernel();
13929+#endif
13930+
13931 #ifdef CONFIG_SMP
13932 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13933 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13934@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13935 struct task_struct *tsk)
13936 {
13937 unsigned cpu = smp_processor_id();
13938+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13939+ int tlbstate = TLBSTATE_OK;
13940+#endif
13941
13942 if (likely(prev != next)) {
13943 #ifdef CONFIG_SMP
13944+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13945+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13946+#endif
13947 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13948 this_cpu_write(cpu_tlbstate.active_mm, next);
13949 #endif
13950 cpumask_set_cpu(cpu, mm_cpumask(next));
13951
13952 /* Re-load page tables */
13953+#ifdef CONFIG_PAX_PER_CPU_PGD
13954+ pax_open_kernel();
13955+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13956+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13957+ pax_close_kernel();
13958+ load_cr3(get_cpu_pgd(cpu));
13959+#else
13960 load_cr3(next->pgd);
13961+#endif
13962
13963 /* stop flush ipis for the previous mm */
13964 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13965@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13966 */
13967 if (unlikely(prev->context.ldt != next->context.ldt))
13968 load_LDT_nolock(&next->context);
13969- }
13970+
13971+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13972+ if (!(__supported_pte_mask & _PAGE_NX)) {
13973+ smp_mb__before_clear_bit();
13974+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13975+ smp_mb__after_clear_bit();
13976+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13977+ }
13978+#endif
13979+
13980+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13981+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13982+ prev->context.user_cs_limit != next->context.user_cs_limit))
13983+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13984 #ifdef CONFIG_SMP
13985+ else if (unlikely(tlbstate != TLBSTATE_OK))
13986+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13987+#endif
13988+#endif
13989+
13990+ }
13991 else {
13992+
13993+#ifdef CONFIG_PAX_PER_CPU_PGD
13994+ pax_open_kernel();
13995+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13996+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13997+ pax_close_kernel();
13998+ load_cr3(get_cpu_pgd(cpu));
13999+#endif
14000+
14001+#ifdef CONFIG_SMP
14002 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
14003 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
14004
14005@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14006 * tlb flush IPI delivery. We must reload CR3
14007 * to make sure to use no freed page tables.
14008 */
14009+
14010+#ifndef CONFIG_PAX_PER_CPU_PGD
14011 load_cr3(next->pgd);
14012+#endif
14013+
14014 load_LDT_nolock(&next->context);
14015+
14016+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14017+ if (!(__supported_pte_mask & _PAGE_NX))
14018+ cpu_set(cpu, next->context.cpu_user_cs_mask);
14019+#endif
14020+
14021+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14022+#ifdef CONFIG_PAX_PAGEEXEC
14023+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
14024+#endif
14025+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14026+#endif
14027+
14028 }
14029+#endif
14030 }
14031-#endif
14032 }
14033
14034 #define activate_mm(prev, next) \
14035diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
14036index e3b7819..b257c64 100644
14037--- a/arch/x86/include/asm/module.h
14038+++ b/arch/x86/include/asm/module.h
14039@@ -5,6 +5,7 @@
14040
14041 #ifdef CONFIG_X86_64
14042 /* X86_64 does not define MODULE_PROC_FAMILY */
14043+#define MODULE_PROC_FAMILY ""
14044 #elif defined CONFIG_M486
14045 #define MODULE_PROC_FAMILY "486 "
14046 #elif defined CONFIG_M586
14047@@ -57,8 +58,20 @@
14048 #error unknown processor family
14049 #endif
14050
14051-#ifdef CONFIG_X86_32
14052-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
14053+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14054+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
14055+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
14056+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
14057+#else
14058+#define MODULE_PAX_KERNEXEC ""
14059 #endif
14060
14061+#ifdef CONFIG_PAX_MEMORY_UDEREF
14062+#define MODULE_PAX_UDEREF "UDEREF "
14063+#else
14064+#define MODULE_PAX_UDEREF ""
14065+#endif
14066+
14067+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
14068+
14069 #endif /* _ASM_X86_MODULE_H */
14070diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
14071index 86f9301..b365cda 100644
14072--- a/arch/x86/include/asm/nmi.h
14073+++ b/arch/x86/include/asm/nmi.h
14074@@ -40,11 +40,11 @@ struct nmiaction {
14075 nmi_handler_t handler;
14076 unsigned long flags;
14077 const char *name;
14078-};
14079+} __do_const;
14080
14081 #define register_nmi_handler(t, fn, fg, n, init...) \
14082 ({ \
14083- static struct nmiaction init fn##_na = { \
14084+ static const struct nmiaction init fn##_na = { \
14085 .handler = (fn), \
14086 .name = (n), \
14087 .flags = (fg), \
14088@@ -52,7 +52,7 @@ struct nmiaction {
14089 __register_nmi_handler((t), &fn##_na); \
14090 })
14091
14092-int __register_nmi_handler(unsigned int, struct nmiaction *);
14093+int __register_nmi_handler(unsigned int, const struct nmiaction *);
14094
14095 void unregister_nmi_handler(unsigned int, const char *);
14096
14097diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
14098index c878924..21f4889 100644
14099--- a/arch/x86/include/asm/page.h
14100+++ b/arch/x86/include/asm/page.h
14101@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
14102 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
14103
14104 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
14105+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
14106
14107 #define __boot_va(x) __va(x)
14108 #define __boot_pa(x) __pa(x)
14109diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
14110index 0f1ddee..e2fc3d1 100644
14111--- a/arch/x86/include/asm/page_64.h
14112+++ b/arch/x86/include/asm/page_64.h
14113@@ -7,9 +7,9 @@
14114
14115 /* duplicated to the one in bootmem.h */
14116 extern unsigned long max_pfn;
14117-extern unsigned long phys_base;
14118+extern const unsigned long phys_base;
14119
14120-static inline unsigned long __phys_addr_nodebug(unsigned long x)
14121+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
14122 {
14123 unsigned long y = x - __START_KERNEL_map;
14124
14125diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
14126index cfdc9ee..3f7b5d6 100644
14127--- a/arch/x86/include/asm/paravirt.h
14128+++ b/arch/x86/include/asm/paravirt.h
14129@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
14130 return (pmd_t) { ret };
14131 }
14132
14133-static inline pmdval_t pmd_val(pmd_t pmd)
14134+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14135 {
14136 pmdval_t ret;
14137
14138@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14139 val);
14140 }
14141
14142+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14143+{
14144+ pgdval_t val = native_pgd_val(pgd);
14145+
14146+ if (sizeof(pgdval_t) > sizeof(long))
14147+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14148+ val, (u64)val >> 32);
14149+ else
14150+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14151+ val);
14152+}
14153+
14154 static inline void pgd_clear(pgd_t *pgdp)
14155 {
14156 set_pgd(pgdp, __pgd(0));
14157@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14158 pv_mmu_ops.set_fixmap(idx, phys, flags);
14159 }
14160
14161+#ifdef CONFIG_PAX_KERNEXEC
14162+static inline unsigned long pax_open_kernel(void)
14163+{
14164+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14165+}
14166+
14167+static inline unsigned long pax_close_kernel(void)
14168+{
14169+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14170+}
14171+#else
14172+static inline unsigned long pax_open_kernel(void) { return 0; }
14173+static inline unsigned long pax_close_kernel(void) { return 0; }
14174+#endif
14175+
14176 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14177
14178 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14179@@ -926,7 +953,7 @@ extern void default_banner(void);
14180
14181 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14182 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14183-#define PARA_INDIRECT(addr) *%cs:addr
14184+#define PARA_INDIRECT(addr) *%ss:addr
14185 #endif
14186
14187 #define INTERRUPT_RETURN \
14188@@ -1001,6 +1028,21 @@ extern void default_banner(void);
14189 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14190 CLBR_NONE, \
14191 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14192+
14193+#define GET_CR0_INTO_RDI \
14194+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14195+ mov %rax,%rdi
14196+
14197+#define SET_RDI_INTO_CR0 \
14198+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14199+
14200+#define GET_CR3_INTO_RDI \
14201+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14202+ mov %rax,%rdi
14203+
14204+#define SET_RDI_INTO_CR3 \
14205+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14206+
14207 #endif /* CONFIG_X86_32 */
14208
14209 #endif /* __ASSEMBLY__ */
14210diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14211index 0db1fca..52310cc 100644
14212--- a/arch/x86/include/asm/paravirt_types.h
14213+++ b/arch/x86/include/asm/paravirt_types.h
14214@@ -84,7 +84,7 @@ struct pv_init_ops {
14215 */
14216 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14217 unsigned long addr, unsigned len);
14218-};
14219+} __no_const;
14220
14221
14222 struct pv_lazy_ops {
14223@@ -98,7 +98,7 @@ struct pv_time_ops {
14224 unsigned long long (*sched_clock)(void);
14225 unsigned long long (*steal_clock)(int cpu);
14226 unsigned long (*get_tsc_khz)(void);
14227-};
14228+} __no_const;
14229
14230 struct pv_cpu_ops {
14231 /* hooks for various privileged instructions */
14232@@ -192,7 +192,7 @@ struct pv_cpu_ops {
14233
14234 void (*start_context_switch)(struct task_struct *prev);
14235 void (*end_context_switch)(struct task_struct *next);
14236-};
14237+} __no_const;
14238
14239 struct pv_irq_ops {
14240 /*
14241@@ -223,7 +223,7 @@ struct pv_apic_ops {
14242 unsigned long start_eip,
14243 unsigned long start_esp);
14244 #endif
14245-};
14246+} __no_const;
14247
14248 struct pv_mmu_ops {
14249 unsigned long (*read_cr2)(void);
14250@@ -313,6 +313,7 @@ struct pv_mmu_ops {
14251 struct paravirt_callee_save make_pud;
14252
14253 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14254+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14255 #endif /* PAGETABLE_LEVELS == 4 */
14256 #endif /* PAGETABLE_LEVELS >= 3 */
14257
14258@@ -324,6 +325,12 @@ struct pv_mmu_ops {
14259 an mfn. We can tell which is which from the index. */
14260 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14261 phys_addr_t phys, pgprot_t flags);
14262+
14263+#ifdef CONFIG_PAX_KERNEXEC
14264+ unsigned long (*pax_open_kernel)(void);
14265+ unsigned long (*pax_close_kernel)(void);
14266+#endif
14267+
14268 };
14269
14270 struct arch_spinlock;
14271@@ -334,7 +341,7 @@ struct pv_lock_ops {
14272 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14273 int (*spin_trylock)(struct arch_spinlock *lock);
14274 void (*spin_unlock)(struct arch_spinlock *lock);
14275-};
14276+} __no_const;
14277
14278 /* This contains all the paravirt structures: we get a convenient
14279 * number for each function using the offset which we use to indicate
14280diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14281index b4389a4..7024269 100644
14282--- a/arch/x86/include/asm/pgalloc.h
14283+++ b/arch/x86/include/asm/pgalloc.h
14284@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14285 pmd_t *pmd, pte_t *pte)
14286 {
14287 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14288+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14289+}
14290+
14291+static inline void pmd_populate_user(struct mm_struct *mm,
14292+ pmd_t *pmd, pte_t *pte)
14293+{
14294+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14295 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14296 }
14297
14298@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14299
14300 #ifdef CONFIG_X86_PAE
14301 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14302+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14303+{
14304+ pud_populate(mm, pudp, pmd);
14305+}
14306 #else /* !CONFIG_X86_PAE */
14307 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14308 {
14309 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14310 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14311 }
14312+
14313+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14314+{
14315+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14316+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14317+}
14318 #endif /* CONFIG_X86_PAE */
14319
14320 #if PAGETABLE_LEVELS > 3
14321@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14322 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14323 }
14324
14325+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14326+{
14327+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14328+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14329+}
14330+
14331 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14332 {
14333 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14334diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14335index f2b489c..4f7e2e5 100644
14336--- a/arch/x86/include/asm/pgtable-2level.h
14337+++ b/arch/x86/include/asm/pgtable-2level.h
14338@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14339
14340 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14341 {
14342+ pax_open_kernel();
14343 *pmdp = pmd;
14344+ pax_close_kernel();
14345 }
14346
14347 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14348diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14349index 4cc9f2b..5fd9226 100644
14350--- a/arch/x86/include/asm/pgtable-3level.h
14351+++ b/arch/x86/include/asm/pgtable-3level.h
14352@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14353
14354 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14355 {
14356+ pax_open_kernel();
14357 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14358+ pax_close_kernel();
14359 }
14360
14361 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14362 {
14363+ pax_open_kernel();
14364 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14365+ pax_close_kernel();
14366 }
14367
14368 /*
14369diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14370index 1e67223..dd6e7ea 100644
14371--- a/arch/x86/include/asm/pgtable.h
14372+++ b/arch/x86/include/asm/pgtable.h
14373@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14374
14375 #ifndef __PAGETABLE_PUD_FOLDED
14376 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14377+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14378 #define pgd_clear(pgd) native_pgd_clear(pgd)
14379 #endif
14380
14381@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14382
14383 #define arch_end_context_switch(prev) do {} while(0)
14384
14385+#define pax_open_kernel() native_pax_open_kernel()
14386+#define pax_close_kernel() native_pax_close_kernel()
14387 #endif /* CONFIG_PARAVIRT */
14388
14389+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14390+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14391+
14392+#ifdef CONFIG_PAX_KERNEXEC
14393+static inline unsigned long native_pax_open_kernel(void)
14394+{
14395+ unsigned long cr0;
14396+
14397+ preempt_disable();
14398+ barrier();
14399+ cr0 = read_cr0() ^ X86_CR0_WP;
14400+ BUG_ON(cr0 & X86_CR0_WP);
14401+ write_cr0(cr0);
14402+ return cr0 ^ X86_CR0_WP;
14403+}
14404+
14405+static inline unsigned long native_pax_close_kernel(void)
14406+{
14407+ unsigned long cr0;
14408+
14409+ cr0 = read_cr0() ^ X86_CR0_WP;
14410+ BUG_ON(!(cr0 & X86_CR0_WP));
14411+ write_cr0(cr0);
14412+ barrier();
14413+ preempt_enable_no_resched();
14414+ return cr0 ^ X86_CR0_WP;
14415+}
14416+#else
14417+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14418+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14419+#endif
14420+
14421 /*
14422 * The following only work if pte_present() is true.
14423 * Undefined behaviour if not..
14424 */
14425+static inline int pte_user(pte_t pte)
14426+{
14427+ return pte_val(pte) & _PAGE_USER;
14428+}
14429+
14430 static inline int pte_dirty(pte_t pte)
14431 {
14432 return pte_flags(pte) & _PAGE_DIRTY;
14433@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
14434 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
14435 }
14436
14437+static inline unsigned long pgd_pfn(pgd_t pgd)
14438+{
14439+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
14440+}
14441+
14442 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
14443
14444 static inline int pmd_large(pmd_t pte)
14445@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14446 return pte_clear_flags(pte, _PAGE_RW);
14447 }
14448
14449+static inline pte_t pte_mkread(pte_t pte)
14450+{
14451+ return __pte(pte_val(pte) | _PAGE_USER);
14452+}
14453+
14454 static inline pte_t pte_mkexec(pte_t pte)
14455 {
14456- return pte_clear_flags(pte, _PAGE_NX);
14457+#ifdef CONFIG_X86_PAE
14458+ if (__supported_pte_mask & _PAGE_NX)
14459+ return pte_clear_flags(pte, _PAGE_NX);
14460+ else
14461+#endif
14462+ return pte_set_flags(pte, _PAGE_USER);
14463+}
14464+
14465+static inline pte_t pte_exprotect(pte_t pte)
14466+{
14467+#ifdef CONFIG_X86_PAE
14468+ if (__supported_pte_mask & _PAGE_NX)
14469+ return pte_set_flags(pte, _PAGE_NX);
14470+ else
14471+#endif
14472+ return pte_clear_flags(pte, _PAGE_USER);
14473 }
14474
14475 static inline pte_t pte_mkdirty(pte_t pte)
14476@@ -394,6 +459,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14477 #endif
14478
14479 #ifndef __ASSEMBLY__
14480+
14481+#ifdef CONFIG_PAX_PER_CPU_PGD
14482+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14483+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14484+{
14485+ return cpu_pgd[cpu];
14486+}
14487+#endif
14488+
14489 #include <linux/mm_types.h>
14490 #include <linux/log2.h>
14491
14492@@ -529,7 +603,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
14493 * Currently stuck as a macro due to indirect forward reference to
14494 * linux/mmzone.h's __section_mem_map_addr() definition:
14495 */
14496-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
14497+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
14498
14499 /* Find an entry in the second-level page table.. */
14500 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
14501@@ -569,7 +643,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
14502 * Currently stuck as a macro due to indirect forward reference to
14503 * linux/mmzone.h's __section_mem_map_addr() definition:
14504 */
14505-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
14506+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
14507
14508 /* to find an entry in a page-table-directory. */
14509 static inline unsigned long pud_index(unsigned long address)
14510@@ -584,7 +658,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14511
14512 static inline int pgd_bad(pgd_t pgd)
14513 {
14514- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14515+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14516 }
14517
14518 static inline int pgd_none(pgd_t pgd)
14519@@ -607,7 +681,12 @@ static inline int pgd_none(pgd_t pgd)
14520 * pgd_offset() returns a (pgd_t *)
14521 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14522 */
14523-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14524+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14525+
14526+#ifdef CONFIG_PAX_PER_CPU_PGD
14527+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14528+#endif
14529+
14530 /*
14531 * a shortcut which implies the use of the kernel's pgd, instead
14532 * of a process's
14533@@ -618,6 +697,22 @@ static inline int pgd_none(pgd_t pgd)
14534 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14535 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14536
14537+#ifdef CONFIG_X86_32
14538+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14539+#else
14540+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14541+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14542+
14543+#ifdef CONFIG_PAX_MEMORY_UDEREF
14544+#ifdef __ASSEMBLY__
14545+#define pax_user_shadow_base pax_user_shadow_base(%rip)
14546+#else
14547+extern unsigned long pax_user_shadow_base;
14548+#endif
14549+#endif
14550+
14551+#endif
14552+
14553 #ifndef __ASSEMBLY__
14554
14555 extern int direct_gbpages;
14556@@ -784,11 +879,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14557 * dst and src can be on the same page, but the range must not overlap,
14558 * and must not cross a page boundary.
14559 */
14560-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14561+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14562 {
14563- memcpy(dst, src, count * sizeof(pgd_t));
14564+ pax_open_kernel();
14565+ while (count--)
14566+ *dst++ = *src++;
14567+ pax_close_kernel();
14568 }
14569
14570+#ifdef CONFIG_PAX_PER_CPU_PGD
14571+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14572+#endif
14573+
14574+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14575+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14576+#else
14577+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14578+#endif
14579+
14580 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
14581 static inline int page_level_shift(enum pg_level level)
14582 {
14583diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14584index 9ee3221..b979c6b 100644
14585--- a/arch/x86/include/asm/pgtable_32.h
14586+++ b/arch/x86/include/asm/pgtable_32.h
14587@@ -25,9 +25,6 @@
14588 struct mm_struct;
14589 struct vm_area_struct;
14590
14591-extern pgd_t swapper_pg_dir[1024];
14592-extern pgd_t initial_page_table[1024];
14593-
14594 static inline void pgtable_cache_init(void) { }
14595 static inline void check_pgt_cache(void) { }
14596 void paging_init(void);
14597@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14598 # include <asm/pgtable-2level.h>
14599 #endif
14600
14601+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14602+extern pgd_t initial_page_table[PTRS_PER_PGD];
14603+#ifdef CONFIG_X86_PAE
14604+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14605+#endif
14606+
14607 #if defined(CONFIG_HIGHPTE)
14608 #define pte_offset_map(dir, address) \
14609 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14610@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14611 /* Clear a kernel PTE and flush it from the TLB */
14612 #define kpte_clear_flush(ptep, vaddr) \
14613 do { \
14614+ pax_open_kernel(); \
14615 pte_clear(&init_mm, (vaddr), (ptep)); \
14616+ pax_close_kernel(); \
14617 __flush_tlb_one((vaddr)); \
14618 } while (0)
14619
14620 #endif /* !__ASSEMBLY__ */
14621
14622+#define HAVE_ARCH_UNMAPPED_AREA
14623+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14624+
14625 /*
14626 * kern_addr_valid() is (1) for FLATMEM and (0) for
14627 * SPARSEMEM and DISCONTIGMEM
14628diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14629index ed5903b..c7fe163 100644
14630--- a/arch/x86/include/asm/pgtable_32_types.h
14631+++ b/arch/x86/include/asm/pgtable_32_types.h
14632@@ -8,7 +8,7 @@
14633 */
14634 #ifdef CONFIG_X86_PAE
14635 # include <asm/pgtable-3level_types.h>
14636-# define PMD_SIZE (1UL << PMD_SHIFT)
14637+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14638 # define PMD_MASK (~(PMD_SIZE - 1))
14639 #else
14640 # include <asm/pgtable-2level_types.h>
14641@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14642 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14643 #endif
14644
14645+#ifdef CONFIG_PAX_KERNEXEC
14646+#ifndef __ASSEMBLY__
14647+extern unsigned char MODULES_EXEC_VADDR[];
14648+extern unsigned char MODULES_EXEC_END[];
14649+#endif
14650+#include <asm/boot.h>
14651+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14652+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14653+#else
14654+#define ktla_ktva(addr) (addr)
14655+#define ktva_ktla(addr) (addr)
14656+#endif
14657+
14658 #define MODULES_VADDR VMALLOC_START
14659 #define MODULES_END VMALLOC_END
14660 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14661diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14662index e22c1db..23a625a 100644
14663--- a/arch/x86/include/asm/pgtable_64.h
14664+++ b/arch/x86/include/asm/pgtable_64.h
14665@@ -16,10 +16,14 @@
14666
14667 extern pud_t level3_kernel_pgt[512];
14668 extern pud_t level3_ident_pgt[512];
14669+extern pud_t level3_vmalloc_start_pgt[512];
14670+extern pud_t level3_vmalloc_end_pgt[512];
14671+extern pud_t level3_vmemmap_pgt[512];
14672+extern pud_t level2_vmemmap_pgt[512];
14673 extern pmd_t level2_kernel_pgt[512];
14674 extern pmd_t level2_fixmap_pgt[512];
14675-extern pmd_t level2_ident_pgt[512];
14676-extern pgd_t init_level4_pgt[];
14677+extern pmd_t level2_ident_pgt[512*2];
14678+extern pgd_t init_level4_pgt[512];
14679
14680 #define swapper_pg_dir init_level4_pgt
14681
14682@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14683
14684 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14685 {
14686+ pax_open_kernel();
14687 *pmdp = pmd;
14688+ pax_close_kernel();
14689 }
14690
14691 static inline void native_pmd_clear(pmd_t *pmd)
14692@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14693
14694 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14695 {
14696+ pax_open_kernel();
14697 *pudp = pud;
14698+ pax_close_kernel();
14699 }
14700
14701 static inline void native_pud_clear(pud_t *pud)
14702@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14703
14704 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14705 {
14706+ pax_open_kernel();
14707+ *pgdp = pgd;
14708+ pax_close_kernel();
14709+}
14710+
14711+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14712+{
14713 *pgdp = pgd;
14714 }
14715
14716diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14717index 2d88344..4679fc3 100644
14718--- a/arch/x86/include/asm/pgtable_64_types.h
14719+++ b/arch/x86/include/asm/pgtable_64_types.h
14720@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
14721 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14722 #define MODULES_END _AC(0xffffffffff000000, UL)
14723 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14724+#define MODULES_EXEC_VADDR MODULES_VADDR
14725+#define MODULES_EXEC_END MODULES_END
14726+
14727+#define ktla_ktva(addr) (addr)
14728+#define ktva_ktla(addr) (addr)
14729
14730 #define EARLY_DYNAMIC_PAGE_TABLES 64
14731
14732diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14733index e642300..0ef8f31 100644
14734--- a/arch/x86/include/asm/pgtable_types.h
14735+++ b/arch/x86/include/asm/pgtable_types.h
14736@@ -16,13 +16,12 @@
14737 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14738 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14739 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14740-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14741+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14742 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14743 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14744 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14745-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14746-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14747-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14748+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14749+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14750 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14751
14752 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14753@@ -40,7 +39,6 @@
14754 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14755 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14756 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14757-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14758 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14759 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14760 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14761@@ -57,8 +55,10 @@
14762
14763 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14764 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14765-#else
14766+#elif defined(CONFIG_KMEMCHECK)
14767 #define _PAGE_NX (_AT(pteval_t, 0))
14768+#else
14769+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14770 #endif
14771
14772 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14773@@ -116,6 +116,9 @@
14774 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14775 _PAGE_ACCESSED)
14776
14777+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14778+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14779+
14780 #define __PAGE_KERNEL_EXEC \
14781 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14782 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14783@@ -126,7 +129,7 @@
14784 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14785 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14786 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14787-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14788+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14789 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14790 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14791 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14792@@ -188,8 +191,8 @@
14793 * bits are combined, this will alow user to access the high address mapped
14794 * VDSO in the presence of CONFIG_COMPAT_VDSO
14795 */
14796-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14797-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14798+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14799+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14800 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14801 #endif
14802
14803@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14804 {
14805 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14806 }
14807+#endif
14808
14809+#if PAGETABLE_LEVELS == 3
14810+#include <asm-generic/pgtable-nopud.h>
14811+#endif
14812+
14813+#if PAGETABLE_LEVELS == 2
14814+#include <asm-generic/pgtable-nopmd.h>
14815+#endif
14816+
14817+#ifndef __ASSEMBLY__
14818 #if PAGETABLE_LEVELS > 3
14819 typedef struct { pudval_t pud; } pud_t;
14820
14821@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14822 return pud.pud;
14823 }
14824 #else
14825-#include <asm-generic/pgtable-nopud.h>
14826-
14827 static inline pudval_t native_pud_val(pud_t pud)
14828 {
14829 return native_pgd_val(pud.pgd);
14830@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14831 return pmd.pmd;
14832 }
14833 #else
14834-#include <asm-generic/pgtable-nopmd.h>
14835-
14836 static inline pmdval_t native_pmd_val(pmd_t pmd)
14837 {
14838 return native_pgd_val(pmd.pud.pgd);
14839@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14840
14841 extern pteval_t __supported_pte_mask;
14842 extern void set_nx(void);
14843-extern int nx_enabled;
14844
14845 #define pgprot_writecombine pgprot_writecombine
14846 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14847diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14848index 22224b3..4080dab 100644
14849--- a/arch/x86/include/asm/processor.h
14850+++ b/arch/x86/include/asm/processor.h
14851@@ -282,7 +282,7 @@ struct tss_struct {
14852
14853 } ____cacheline_aligned;
14854
14855-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14856+extern struct tss_struct init_tss[NR_CPUS];
14857
14858 /*
14859 * Save the original ist values for checking stack pointers during debugging
14860@@ -823,11 +823,18 @@ static inline void spin_lock_prefetch(const void *x)
14861 */
14862 #define TASK_SIZE PAGE_OFFSET
14863 #define TASK_SIZE_MAX TASK_SIZE
14864+
14865+#ifdef CONFIG_PAX_SEGMEXEC
14866+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14867+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14868+#else
14869 #define STACK_TOP TASK_SIZE
14870-#define STACK_TOP_MAX STACK_TOP
14871+#endif
14872+
14873+#define STACK_TOP_MAX TASK_SIZE
14874
14875 #define INIT_THREAD { \
14876- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14877+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14878 .vm86_info = NULL, \
14879 .sysenter_cs = __KERNEL_CS, \
14880 .io_bitmap_ptr = NULL, \
14881@@ -841,7 +848,7 @@ static inline void spin_lock_prefetch(const void *x)
14882 */
14883 #define INIT_TSS { \
14884 .x86_tss = { \
14885- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14886+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14887 .ss0 = __KERNEL_DS, \
14888 .ss1 = __KERNEL_CS, \
14889 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14890@@ -852,11 +859,7 @@ static inline void spin_lock_prefetch(const void *x)
14891 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14892
14893 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14894-#define KSTK_TOP(info) \
14895-({ \
14896- unsigned long *__ptr = (unsigned long *)(info); \
14897- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14898-})
14899+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14900
14901 /*
14902 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14903@@ -871,7 +874,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14904 #define task_pt_regs(task) \
14905 ({ \
14906 struct pt_regs *__regs__; \
14907- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14908+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14909 __regs__ - 1; \
14910 })
14911
14912@@ -881,13 +884,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14913 /*
14914 * User space process size. 47bits minus one guard page.
14915 */
14916-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14917+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14918
14919 /* This decides where the kernel will search for a free chunk of vm
14920 * space during mmap's.
14921 */
14922 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14923- 0xc0000000 : 0xFFFFe000)
14924+ 0xc0000000 : 0xFFFFf000)
14925
14926 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14927 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14928@@ -898,11 +901,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14929 #define STACK_TOP_MAX TASK_SIZE_MAX
14930
14931 #define INIT_THREAD { \
14932- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14933+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14934 }
14935
14936 #define INIT_TSS { \
14937- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14938+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14939 }
14940
14941 /*
14942@@ -930,6 +933,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14943 */
14944 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14945
14946+#ifdef CONFIG_PAX_SEGMEXEC
14947+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14948+#endif
14949+
14950 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14951
14952 /* Get/set a process' ability to use the timestamp counter instruction */
14953@@ -970,7 +977,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
14954 return ratio;
14955 }
14956
14957-extern unsigned long arch_align_stack(unsigned long sp);
14958+#define arch_align_stack(x) ((x) & ~0xfUL)
14959 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14960
14961 void default_idle(void);
14962@@ -980,6 +987,6 @@ bool xen_set_default_idle(void);
14963 #define xen_set_default_idle 0
14964 #endif
14965
14966-void stop_this_cpu(void *dummy);
14967+void stop_this_cpu(void *dummy) __noreturn;
14968
14969 #endif /* _ASM_X86_PROCESSOR_H */
14970diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14971index 942a086..6c26446 100644
14972--- a/arch/x86/include/asm/ptrace.h
14973+++ b/arch/x86/include/asm/ptrace.h
14974@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14975 }
14976
14977 /*
14978- * user_mode_vm(regs) determines whether a register set came from user mode.
14979+ * user_mode(regs) determines whether a register set came from user mode.
14980 * This is true if V8086 mode was enabled OR if the register set was from
14981 * protected mode with RPL-3 CS value. This tricky test checks that with
14982 * one comparison. Many places in the kernel can bypass this full check
14983- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14984+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14985+ * be used.
14986 */
14987-static inline int user_mode(struct pt_regs *regs)
14988+static inline int user_mode_novm(struct pt_regs *regs)
14989 {
14990 #ifdef CONFIG_X86_32
14991 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14992 #else
14993- return !!(regs->cs & 3);
14994+ return !!(regs->cs & SEGMENT_RPL_MASK);
14995 #endif
14996 }
14997
14998-static inline int user_mode_vm(struct pt_regs *regs)
14999+static inline int user_mode(struct pt_regs *regs)
15000 {
15001 #ifdef CONFIG_X86_32
15002 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
15003 USER_RPL;
15004 #else
15005- return user_mode(regs);
15006+ return user_mode_novm(regs);
15007 #endif
15008 }
15009
15010@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
15011 #ifdef CONFIG_X86_64
15012 static inline bool user_64bit_mode(struct pt_regs *regs)
15013 {
15014+ unsigned long cs = regs->cs & 0xffff;
15015 #ifndef CONFIG_PARAVIRT
15016 /*
15017 * On non-paravirt systems, this is the only long mode CPL 3
15018 * selector. We do not allow long mode selectors in the LDT.
15019 */
15020- return regs->cs == __USER_CS;
15021+ return cs == __USER_CS;
15022 #else
15023 /* Headers are too twisted for this to go in paravirt.h. */
15024- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
15025+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
15026 #endif
15027 }
15028
15029@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
15030 * Traps from the kernel do not save sp and ss.
15031 * Use the helper function to retrieve sp.
15032 */
15033- if (offset == offsetof(struct pt_regs, sp) &&
15034- regs->cs == __KERNEL_CS)
15035- return kernel_stack_pointer(regs);
15036+ if (offset == offsetof(struct pt_regs, sp)) {
15037+ unsigned long cs = regs->cs & 0xffff;
15038+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
15039+ return kernel_stack_pointer(regs);
15040+ }
15041 #endif
15042 return *(unsigned long *)((unsigned long)regs + offset);
15043 }
15044diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
15045index 9c6b890..5305f53 100644
15046--- a/arch/x86/include/asm/realmode.h
15047+++ b/arch/x86/include/asm/realmode.h
15048@@ -22,16 +22,14 @@ struct real_mode_header {
15049 #endif
15050 /* APM/BIOS reboot */
15051 u32 machine_real_restart_asm;
15052-#ifdef CONFIG_X86_64
15053 u32 machine_real_restart_seg;
15054-#endif
15055 };
15056
15057 /* This must match data at trampoline_32/64.S */
15058 struct trampoline_header {
15059 #ifdef CONFIG_X86_32
15060 u32 start;
15061- u16 gdt_pad;
15062+ u16 boot_cs;
15063 u16 gdt_limit;
15064 u32 gdt_base;
15065 #else
15066diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
15067index a82c4f1..ac45053 100644
15068--- a/arch/x86/include/asm/reboot.h
15069+++ b/arch/x86/include/asm/reboot.h
15070@@ -6,13 +6,13 @@
15071 struct pt_regs;
15072
15073 struct machine_ops {
15074- void (*restart)(char *cmd);
15075- void (*halt)(void);
15076- void (*power_off)(void);
15077+ void (* __noreturn restart)(char *cmd);
15078+ void (* __noreturn halt)(void);
15079+ void (* __noreturn power_off)(void);
15080 void (*shutdown)(void);
15081 void (*crash_shutdown)(struct pt_regs *);
15082- void (*emergency_restart)(void);
15083-};
15084+ void (* __noreturn emergency_restart)(void);
15085+} __no_const;
15086
15087 extern struct machine_ops machine_ops;
15088
15089diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
15090index cad82c9..2e5c5c1 100644
15091--- a/arch/x86/include/asm/rwsem.h
15092+++ b/arch/x86/include/asm/rwsem.h
15093@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
15094 {
15095 asm volatile("# beginning down_read\n\t"
15096 LOCK_PREFIX _ASM_INC "(%1)\n\t"
15097+
15098+#ifdef CONFIG_PAX_REFCOUNT
15099+ "jno 0f\n"
15100+ LOCK_PREFIX _ASM_DEC "(%1)\n"
15101+ "int $4\n0:\n"
15102+ _ASM_EXTABLE(0b, 0b)
15103+#endif
15104+
15105 /* adds 0x00000001 */
15106 " jns 1f\n"
15107 " call call_rwsem_down_read_failed\n"
15108@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
15109 "1:\n\t"
15110 " mov %1,%2\n\t"
15111 " add %3,%2\n\t"
15112+
15113+#ifdef CONFIG_PAX_REFCOUNT
15114+ "jno 0f\n"
15115+ "sub %3,%2\n"
15116+ "int $4\n0:\n"
15117+ _ASM_EXTABLE(0b, 0b)
15118+#endif
15119+
15120 " jle 2f\n\t"
15121 LOCK_PREFIX " cmpxchg %2,%0\n\t"
15122 " jnz 1b\n\t"
15123@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
15124 long tmp;
15125 asm volatile("# beginning down_write\n\t"
15126 LOCK_PREFIX " xadd %1,(%2)\n\t"
15127+
15128+#ifdef CONFIG_PAX_REFCOUNT
15129+ "jno 0f\n"
15130+ "mov %1,(%2)\n"
15131+ "int $4\n0:\n"
15132+ _ASM_EXTABLE(0b, 0b)
15133+#endif
15134+
15135 /* adds 0xffff0001, returns the old value */
15136 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
15137 /* was the active mask 0 before? */
15138@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
15139 long tmp;
15140 asm volatile("# beginning __up_read\n\t"
15141 LOCK_PREFIX " xadd %1,(%2)\n\t"
15142+
15143+#ifdef CONFIG_PAX_REFCOUNT
15144+ "jno 0f\n"
15145+ "mov %1,(%2)\n"
15146+ "int $4\n0:\n"
15147+ _ASM_EXTABLE(0b, 0b)
15148+#endif
15149+
15150 /* subtracts 1, returns the old value */
15151 " jns 1f\n\t"
15152 " call call_rwsem_wake\n" /* expects old value in %edx */
15153@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
15154 long tmp;
15155 asm volatile("# beginning __up_write\n\t"
15156 LOCK_PREFIX " xadd %1,(%2)\n\t"
15157+
15158+#ifdef CONFIG_PAX_REFCOUNT
15159+ "jno 0f\n"
15160+ "mov %1,(%2)\n"
15161+ "int $4\n0:\n"
15162+ _ASM_EXTABLE(0b, 0b)
15163+#endif
15164+
15165 /* subtracts 0xffff0001, returns the old value */
15166 " jns 1f\n\t"
15167 " call call_rwsem_wake\n" /* expects old value in %edx */
15168@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15169 {
15170 asm volatile("# beginning __downgrade_write\n\t"
15171 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15172+
15173+#ifdef CONFIG_PAX_REFCOUNT
15174+ "jno 0f\n"
15175+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15176+ "int $4\n0:\n"
15177+ _ASM_EXTABLE(0b, 0b)
15178+#endif
15179+
15180 /*
15181 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15182 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15183@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15184 */
15185 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15186 {
15187- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15188+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15189+
15190+#ifdef CONFIG_PAX_REFCOUNT
15191+ "jno 0f\n"
15192+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15193+ "int $4\n0:\n"
15194+ _ASM_EXTABLE(0b, 0b)
15195+#endif
15196+
15197 : "+m" (sem->count)
15198 : "er" (delta));
15199 }
15200@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15201 */
15202 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15203 {
15204- return delta + xadd(&sem->count, delta);
15205+ return delta + xadd_check_overflow(&sem->count, delta);
15206 }
15207
15208 #endif /* __KERNEL__ */
15209diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15210index c48a950..c6d7468 100644
15211--- a/arch/x86/include/asm/segment.h
15212+++ b/arch/x86/include/asm/segment.h
15213@@ -64,10 +64,15 @@
15214 * 26 - ESPFIX small SS
15215 * 27 - per-cpu [ offset to per-cpu data area ]
15216 * 28 - stack_canary-20 [ for stack protector ]
15217- * 29 - unused
15218- * 30 - unused
15219+ * 29 - PCI BIOS CS
15220+ * 30 - PCI BIOS DS
15221 * 31 - TSS for double fault handler
15222 */
15223+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15224+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15225+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15226+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15227+
15228 #define GDT_ENTRY_TLS_MIN 6
15229 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15230
15231@@ -79,6 +84,8 @@
15232
15233 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15234
15235+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15236+
15237 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15238
15239 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15240@@ -104,6 +111,12 @@
15241 #define __KERNEL_STACK_CANARY 0
15242 #endif
15243
15244+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15245+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15246+
15247+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15248+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15249+
15250 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15251
15252 /*
15253@@ -141,7 +154,7 @@
15254 */
15255
15256 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15257-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15258+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15259
15260
15261 #else
15262@@ -165,6 +178,8 @@
15263 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15264 #define __USER32_DS __USER_DS
15265
15266+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15267+
15268 #define GDT_ENTRY_TSS 8 /* needs two entries */
15269 #define GDT_ENTRY_LDT 10 /* needs two entries */
15270 #define GDT_ENTRY_TLS_MIN 12
15271@@ -185,6 +200,7 @@
15272 #endif
15273
15274 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15275+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15276 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15277 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15278 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15279@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15280 {
15281 unsigned long __limit;
15282 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15283- return __limit + 1;
15284+ return __limit;
15285 }
15286
15287 #endif /* !__ASSEMBLY__ */
15288diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15289index b073aae..39f9bdd 100644
15290--- a/arch/x86/include/asm/smp.h
15291+++ b/arch/x86/include/asm/smp.h
15292@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15293 /* cpus sharing the last level cache: */
15294 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15295 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15296-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15297+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15298
15299 static inline struct cpumask *cpu_sibling_mask(int cpu)
15300 {
15301@@ -79,7 +79,7 @@ struct smp_ops {
15302
15303 void (*send_call_func_ipi)(const struct cpumask *mask);
15304 void (*send_call_func_single_ipi)(int cpu);
15305-};
15306+} __no_const;
15307
15308 /* Globals due to paravirt */
15309 extern void set_cpu_sibling_map(int cpu);
15310@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15311 extern int safe_smp_processor_id(void);
15312
15313 #elif defined(CONFIG_X86_64_SMP)
15314-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15315-
15316-#define stack_smp_processor_id() \
15317-({ \
15318- struct thread_info *ti; \
15319- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15320- ti->cpu; \
15321-})
15322+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15323+#define stack_smp_processor_id() raw_smp_processor_id()
15324 #define safe_smp_processor_id() smp_processor_id()
15325
15326 #endif
15327diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15328index 33692ea..350a534 100644
15329--- a/arch/x86/include/asm/spinlock.h
15330+++ b/arch/x86/include/asm/spinlock.h
15331@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15332 static inline void arch_read_lock(arch_rwlock_t *rw)
15333 {
15334 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15335+
15336+#ifdef CONFIG_PAX_REFCOUNT
15337+ "jno 0f\n"
15338+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15339+ "int $4\n0:\n"
15340+ _ASM_EXTABLE(0b, 0b)
15341+#endif
15342+
15343 "jns 1f\n"
15344 "call __read_lock_failed\n\t"
15345 "1:\n"
15346@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15347 static inline void arch_write_lock(arch_rwlock_t *rw)
15348 {
15349 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15350+
15351+#ifdef CONFIG_PAX_REFCOUNT
15352+ "jno 0f\n"
15353+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15354+ "int $4\n0:\n"
15355+ _ASM_EXTABLE(0b, 0b)
15356+#endif
15357+
15358 "jz 1f\n"
15359 "call __write_lock_failed\n\t"
15360 "1:\n"
15361@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15362
15363 static inline void arch_read_unlock(arch_rwlock_t *rw)
15364 {
15365- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15366+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15367+
15368+#ifdef CONFIG_PAX_REFCOUNT
15369+ "jno 0f\n"
15370+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15371+ "int $4\n0:\n"
15372+ _ASM_EXTABLE(0b, 0b)
15373+#endif
15374+
15375 :"+m" (rw->lock) : : "memory");
15376 }
15377
15378 static inline void arch_write_unlock(arch_rwlock_t *rw)
15379 {
15380- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15381+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15382+
15383+#ifdef CONFIG_PAX_REFCOUNT
15384+ "jno 0f\n"
15385+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15386+ "int $4\n0:\n"
15387+ _ASM_EXTABLE(0b, 0b)
15388+#endif
15389+
15390 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15391 }
15392
15393diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15394index 6a99859..03cb807 100644
15395--- a/arch/x86/include/asm/stackprotector.h
15396+++ b/arch/x86/include/asm/stackprotector.h
15397@@ -47,7 +47,7 @@
15398 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15399 */
15400 #define GDT_STACK_CANARY_INIT \
15401- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15402+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15403
15404 /*
15405 * Initialize the stackprotector canary value.
15406@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15407
15408 static inline void load_stack_canary_segment(void)
15409 {
15410-#ifdef CONFIG_X86_32
15411+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15412 asm volatile ("mov %0, %%gs" : : "r" (0));
15413 #endif
15414 }
15415diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15416index 70bbe39..4ae2bd4 100644
15417--- a/arch/x86/include/asm/stacktrace.h
15418+++ b/arch/x86/include/asm/stacktrace.h
15419@@ -11,28 +11,20 @@
15420
15421 extern int kstack_depth_to_print;
15422
15423-struct thread_info;
15424+struct task_struct;
15425 struct stacktrace_ops;
15426
15427-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15428- unsigned long *stack,
15429- unsigned long bp,
15430- const struct stacktrace_ops *ops,
15431- void *data,
15432- unsigned long *end,
15433- int *graph);
15434+typedef unsigned long walk_stack_t(struct task_struct *task,
15435+ void *stack_start,
15436+ unsigned long *stack,
15437+ unsigned long bp,
15438+ const struct stacktrace_ops *ops,
15439+ void *data,
15440+ unsigned long *end,
15441+ int *graph);
15442
15443-extern unsigned long
15444-print_context_stack(struct thread_info *tinfo,
15445- unsigned long *stack, unsigned long bp,
15446- const struct stacktrace_ops *ops, void *data,
15447- unsigned long *end, int *graph);
15448-
15449-extern unsigned long
15450-print_context_stack_bp(struct thread_info *tinfo,
15451- unsigned long *stack, unsigned long bp,
15452- const struct stacktrace_ops *ops, void *data,
15453- unsigned long *end, int *graph);
15454+extern walk_stack_t print_context_stack;
15455+extern walk_stack_t print_context_stack_bp;
15456
15457 /* Generic stack tracer with callbacks */
15458
15459@@ -40,7 +32,7 @@ struct stacktrace_ops {
15460 void (*address)(void *data, unsigned long address, int reliable);
15461 /* On negative return stop dumping */
15462 int (*stack)(void *data, char *name);
15463- walk_stack_t walk_stack;
15464+ walk_stack_t *walk_stack;
15465 };
15466
15467 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15468diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15469index 4ec45b3..a4f0a8a 100644
15470--- a/arch/x86/include/asm/switch_to.h
15471+++ b/arch/x86/include/asm/switch_to.h
15472@@ -108,7 +108,7 @@ do { \
15473 "call __switch_to\n\t" \
15474 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15475 __switch_canary \
15476- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15477+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15478 "movq %%rax,%%rdi\n\t" \
15479 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15480 "jnz ret_from_fork\n\t" \
15481@@ -119,7 +119,7 @@ do { \
15482 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15483 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15484 [_tif_fork] "i" (_TIF_FORK), \
15485- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15486+ [thread_info] "m" (current_tinfo), \
15487 [current_task] "m" (current_task) \
15488 __switch_canary_iparam \
15489 : "memory", "cc" __EXTRA_CLOBBER)
15490diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15491index a1df6e8..e002940 100644
15492--- a/arch/x86/include/asm/thread_info.h
15493+++ b/arch/x86/include/asm/thread_info.h
15494@@ -10,6 +10,7 @@
15495 #include <linux/compiler.h>
15496 #include <asm/page.h>
15497 #include <asm/types.h>
15498+#include <asm/percpu.h>
15499
15500 /*
15501 * low level task data that entry.S needs immediate access to
15502@@ -23,7 +24,6 @@ struct exec_domain;
15503 #include <linux/atomic.h>
15504
15505 struct thread_info {
15506- struct task_struct *task; /* main task structure */
15507 struct exec_domain *exec_domain; /* execution domain */
15508 __u32 flags; /* low level flags */
15509 __u32 status; /* thread synchronous flags */
15510@@ -33,19 +33,13 @@ struct thread_info {
15511 mm_segment_t addr_limit;
15512 struct restart_block restart_block;
15513 void __user *sysenter_return;
15514-#ifdef CONFIG_X86_32
15515- unsigned long previous_esp; /* ESP of the previous stack in
15516- case of nested (IRQ) stacks
15517- */
15518- __u8 supervisor_stack[0];
15519-#endif
15520+ unsigned long lowest_stack;
15521 unsigned int sig_on_uaccess_error:1;
15522 unsigned int uaccess_err:1; /* uaccess failed */
15523 };
15524
15525-#define INIT_THREAD_INFO(tsk) \
15526+#define INIT_THREAD_INFO \
15527 { \
15528- .task = &tsk, \
15529 .exec_domain = &default_exec_domain, \
15530 .flags = 0, \
15531 .cpu = 0, \
15532@@ -56,7 +50,7 @@ struct thread_info {
15533 }, \
15534 }
15535
15536-#define init_thread_info (init_thread_union.thread_info)
15537+#define init_thread_info (init_thread_union.stack)
15538 #define init_stack (init_thread_union.stack)
15539
15540 #else /* !__ASSEMBLY__ */
15541@@ -97,6 +91,7 @@ struct thread_info {
15542 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15543 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15544 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15545+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15546
15547 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15548 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15549@@ -121,17 +116,18 @@ struct thread_info {
15550 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15551 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15552 #define _TIF_X32 (1 << TIF_X32)
15553+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15554
15555 /* work to do in syscall_trace_enter() */
15556 #define _TIF_WORK_SYSCALL_ENTRY \
15557 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15558 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15559- _TIF_NOHZ)
15560+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15561
15562 /* work to do in syscall_trace_leave() */
15563 #define _TIF_WORK_SYSCALL_EXIT \
15564 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15565- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15566+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15567
15568 /* work to do on interrupt/exception return */
15569 #define _TIF_WORK_MASK \
15570@@ -142,7 +138,7 @@ struct thread_info {
15571 /* work to do on any return to user space */
15572 #define _TIF_ALLWORK_MASK \
15573 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15574- _TIF_NOHZ)
15575+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15576
15577 /* Only used for 64 bit */
15578 #define _TIF_DO_NOTIFY_MASK \
15579@@ -158,45 +154,40 @@ struct thread_info {
15580
15581 #define PREEMPT_ACTIVE 0x10000000
15582
15583-#ifdef CONFIG_X86_32
15584-
15585-#define STACK_WARN (THREAD_SIZE/8)
15586-/*
15587- * macros/functions for gaining access to the thread information structure
15588- *
15589- * preempt_count needs to be 1 initially, until the scheduler is functional.
15590- */
15591-#ifndef __ASSEMBLY__
15592-
15593-
15594-/* how to get the current stack pointer from C */
15595-register unsigned long current_stack_pointer asm("esp") __used;
15596-
15597-/* how to get the thread information struct from C */
15598-static inline struct thread_info *current_thread_info(void)
15599-{
15600- return (struct thread_info *)
15601- (current_stack_pointer & ~(THREAD_SIZE - 1));
15602-}
15603-
15604-#else /* !__ASSEMBLY__ */
15605-
15606+#ifdef __ASSEMBLY__
15607 /* how to get the thread information struct from ASM */
15608 #define GET_THREAD_INFO(reg) \
15609- movl $-THREAD_SIZE, reg; \
15610- andl %esp, reg
15611+ mov PER_CPU_VAR(current_tinfo), reg
15612
15613 /* use this one if reg already contains %esp */
15614-#define GET_THREAD_INFO_WITH_ESP(reg) \
15615- andl $-THREAD_SIZE, reg
15616+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15617+#else
15618+/* how to get the thread information struct from C */
15619+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15620+
15621+static __always_inline struct thread_info *current_thread_info(void)
15622+{
15623+ return this_cpu_read_stable(current_tinfo);
15624+}
15625+#endif
15626+
15627+#ifdef CONFIG_X86_32
15628+
15629+#define STACK_WARN (THREAD_SIZE/8)
15630+/*
15631+ * macros/functions for gaining access to the thread information structure
15632+ *
15633+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15634+ */
15635+#ifndef __ASSEMBLY__
15636+
15637+/* how to get the current stack pointer from C */
15638+register unsigned long current_stack_pointer asm("esp") __used;
15639
15640 #endif
15641
15642 #else /* X86_32 */
15643
15644-#include <asm/percpu.h>
15645-#define KERNEL_STACK_OFFSET (5*8)
15646-
15647 /*
15648 * macros/functions for gaining access to the thread information structure
15649 * preempt_count needs to be 1 initially, until the scheduler is functional.
15650@@ -204,27 +195,8 @@ static inline struct thread_info *current_thread_info(void)
15651 #ifndef __ASSEMBLY__
15652 DECLARE_PER_CPU(unsigned long, kernel_stack);
15653
15654-static inline struct thread_info *current_thread_info(void)
15655-{
15656- struct thread_info *ti;
15657- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15658- KERNEL_STACK_OFFSET - THREAD_SIZE);
15659- return ti;
15660-}
15661-
15662-#else /* !__ASSEMBLY__ */
15663-
15664-/* how to get the thread information struct from ASM */
15665-#define GET_THREAD_INFO(reg) \
15666- movq PER_CPU_VAR(kernel_stack),reg ; \
15667- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15668-
15669-/*
15670- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15671- * a certain register (to be used in assembler memory operands).
15672- */
15673-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15674-
15675+/* how to get the current stack pointer from C */
15676+register unsigned long current_stack_pointer asm("rsp") __used;
15677 #endif
15678
15679 #endif /* !X86_32 */
15680@@ -283,5 +255,12 @@ static inline bool is_ia32_task(void)
15681 extern void arch_task_cache_init(void);
15682 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15683 extern void arch_release_task_struct(struct task_struct *tsk);
15684+
15685+#define __HAVE_THREAD_FUNCTIONS
15686+#define task_thread_info(task) (&(task)->tinfo)
15687+#define task_stack_page(task) ((task)->stack)
15688+#define setup_thread_stack(p, org) do {} while (0)
15689+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15690+
15691 #endif
15692 #endif /* _ASM_X86_THREAD_INFO_H */
15693diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15694index 5ee2687..70d5895 100644
15695--- a/arch/x86/include/asm/uaccess.h
15696+++ b/arch/x86/include/asm/uaccess.h
15697@@ -7,6 +7,7 @@
15698 #include <linux/compiler.h>
15699 #include <linux/thread_info.h>
15700 #include <linux/string.h>
15701+#include <linux/sched.h>
15702 #include <asm/asm.h>
15703 #include <asm/page.h>
15704 #include <asm/smap.h>
15705@@ -29,7 +30,12 @@
15706
15707 #define get_ds() (KERNEL_DS)
15708 #define get_fs() (current_thread_info()->addr_limit)
15709+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15710+void __set_fs(mm_segment_t x);
15711+void set_fs(mm_segment_t x);
15712+#else
15713 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15714+#endif
15715
15716 #define segment_eq(a, b) ((a).seg == (b).seg)
15717
15718@@ -77,8 +83,33 @@
15719 * checks that the pointer is in the user space range - after calling
15720 * this function, memory access functions may still return -EFAULT.
15721 */
15722-#define access_ok(type, addr, size) \
15723- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15724+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15725+#define access_ok(type, addr, size) \
15726+({ \
15727+ long __size = size; \
15728+ unsigned long __addr = (unsigned long)addr; \
15729+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15730+ unsigned long __end_ao = __addr + __size - 1; \
15731+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15732+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15733+ while(__addr_ao <= __end_ao) { \
15734+ char __c_ao; \
15735+ __addr_ao += PAGE_SIZE; \
15736+ if (__size > PAGE_SIZE) \
15737+ cond_resched(); \
15738+ if (__get_user(__c_ao, (char __user *)__addr)) \
15739+ break; \
15740+ if (type != VERIFY_WRITE) { \
15741+ __addr = __addr_ao; \
15742+ continue; \
15743+ } \
15744+ if (__put_user(__c_ao, (char __user *)__addr)) \
15745+ break; \
15746+ __addr = __addr_ao; \
15747+ } \
15748+ } \
15749+ __ret_ao; \
15750+})
15751
15752 /*
15753 * The exception table consists of pairs of addresses relative to the
15754@@ -176,13 +207,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15755 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15756 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15757
15758-
15759+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15760+#define __copyuser_seg "gs;"
15761+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15762+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15763+#else
15764+#define __copyuser_seg
15765+#define __COPYUSER_SET_ES
15766+#define __COPYUSER_RESTORE_ES
15767+#endif
15768
15769 #ifdef CONFIG_X86_32
15770 #define __put_user_asm_u64(x, addr, err, errret) \
15771 asm volatile(ASM_STAC "\n" \
15772- "1: movl %%eax,0(%2)\n" \
15773- "2: movl %%edx,4(%2)\n" \
15774+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15775+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15776 "3: " ASM_CLAC "\n" \
15777 ".section .fixup,\"ax\"\n" \
15778 "4: movl %3,%0\n" \
15779@@ -195,8 +234,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15780
15781 #define __put_user_asm_ex_u64(x, addr) \
15782 asm volatile(ASM_STAC "\n" \
15783- "1: movl %%eax,0(%1)\n" \
15784- "2: movl %%edx,4(%1)\n" \
15785+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15786+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15787 "3: " ASM_CLAC "\n" \
15788 _ASM_EXTABLE_EX(1b, 2b) \
15789 _ASM_EXTABLE_EX(2b, 3b) \
15790@@ -246,7 +285,7 @@ extern void __put_user_8(void);
15791 __typeof__(*(ptr)) __pu_val; \
15792 __chk_user_ptr(ptr); \
15793 might_fault(); \
15794- __pu_val = x; \
15795+ __pu_val = (x); \
15796 switch (sizeof(*(ptr))) { \
15797 case 1: \
15798 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15799@@ -345,7 +384,7 @@ do { \
15800
15801 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15802 asm volatile(ASM_STAC "\n" \
15803- "1: mov"itype" %2,%"rtype"1\n" \
15804+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15805 "2: " ASM_CLAC "\n" \
15806 ".section .fixup,\"ax\"\n" \
15807 "3: mov %3,%0\n" \
15808@@ -353,7 +392,7 @@ do { \
15809 " jmp 2b\n" \
15810 ".previous\n" \
15811 _ASM_EXTABLE(1b, 3b) \
15812- : "=r" (err), ltype(x) \
15813+ : "=r" (err), ltype (x) \
15814 : "m" (__m(addr)), "i" (errret), "0" (err))
15815
15816 #define __get_user_size_ex(x, ptr, size) \
15817@@ -378,7 +417,7 @@ do { \
15818 } while (0)
15819
15820 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15821- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15822+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15823 "2:\n" \
15824 _ASM_EXTABLE_EX(1b, 2b) \
15825 : ltype(x) : "m" (__m(addr)))
15826@@ -395,13 +434,24 @@ do { \
15827 int __gu_err; \
15828 unsigned long __gu_val; \
15829 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15830- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15831+ (x) = (__typeof__(*(ptr)))__gu_val; \
15832 __gu_err; \
15833 })
15834
15835 /* FIXME: this hack is definitely wrong -AK */
15836 struct __large_struct { unsigned long buf[100]; };
15837-#define __m(x) (*(struct __large_struct __user *)(x))
15838+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15839+#define ____m(x) \
15840+({ \
15841+ unsigned long ____x = (unsigned long)(x); \
15842+ if (____x < pax_user_shadow_base) \
15843+ ____x += pax_user_shadow_base; \
15844+ (typeof(x))____x; \
15845+})
15846+#else
15847+#define ____m(x) (x)
15848+#endif
15849+#define __m(x) (*(struct __large_struct __user *)____m(x))
15850
15851 /*
15852 * Tell gcc we read from memory instead of writing: this is because
15853@@ -410,7 +460,7 @@ struct __large_struct { unsigned long buf[100]; };
15854 */
15855 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15856 asm volatile(ASM_STAC "\n" \
15857- "1: mov"itype" %"rtype"1,%2\n" \
15858+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15859 "2: " ASM_CLAC "\n" \
15860 ".section .fixup,\"ax\"\n" \
15861 "3: mov %3,%0\n" \
15862@@ -418,10 +468,10 @@ struct __large_struct { unsigned long buf[100]; };
15863 ".previous\n" \
15864 _ASM_EXTABLE(1b, 3b) \
15865 : "=r"(err) \
15866- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15867+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15868
15869 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15870- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15871+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15872 "2:\n" \
15873 _ASM_EXTABLE_EX(1b, 2b) \
15874 : : ltype(x), "m" (__m(addr)))
15875@@ -460,8 +510,12 @@ struct __large_struct { unsigned long buf[100]; };
15876 * On error, the variable @x is set to zero.
15877 */
15878
15879+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15880+#define __get_user(x, ptr) get_user((x), (ptr))
15881+#else
15882 #define __get_user(x, ptr) \
15883 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15884+#endif
15885
15886 /**
15887 * __put_user: - Write a simple value into user space, with less checking.
15888@@ -483,8 +537,12 @@ struct __large_struct { unsigned long buf[100]; };
15889 * Returns zero on success, or -EFAULT on error.
15890 */
15891
15892+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15893+#define __put_user(x, ptr) put_user((x), (ptr))
15894+#else
15895 #define __put_user(x, ptr) \
15896 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15897+#endif
15898
15899 #define __get_user_unaligned __get_user
15900 #define __put_user_unaligned __put_user
15901@@ -502,7 +560,7 @@ struct __large_struct { unsigned long buf[100]; };
15902 #define get_user_ex(x, ptr) do { \
15903 unsigned long __gue_val; \
15904 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15905- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15906+ (x) = (__typeof__(*(ptr)))__gue_val; \
15907 } while (0)
15908
15909 #define put_user_try uaccess_try
15910@@ -519,8 +577,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15911 extern __must_check long strlen_user(const char __user *str);
15912 extern __must_check long strnlen_user(const char __user *str, long n);
15913
15914-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15915-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15916+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15917+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15918
15919 /*
15920 * movsl can be slow when source and dest are not both 8-byte aligned
15921diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15922index 7f760a9..04b1c65 100644
15923--- a/arch/x86/include/asm/uaccess_32.h
15924+++ b/arch/x86/include/asm/uaccess_32.h
15925@@ -11,15 +11,15 @@
15926 #include <asm/page.h>
15927
15928 unsigned long __must_check __copy_to_user_ll
15929- (void __user *to, const void *from, unsigned long n);
15930+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15931 unsigned long __must_check __copy_from_user_ll
15932- (void *to, const void __user *from, unsigned long n);
15933+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15934 unsigned long __must_check __copy_from_user_ll_nozero
15935- (void *to, const void __user *from, unsigned long n);
15936+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15937 unsigned long __must_check __copy_from_user_ll_nocache
15938- (void *to, const void __user *from, unsigned long n);
15939+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15940 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15941- (void *to, const void __user *from, unsigned long n);
15942+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15943
15944 /**
15945 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15946@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15947 static __always_inline unsigned long __must_check
15948 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15949 {
15950+ if ((long)n < 0)
15951+ return n;
15952+
15953+ check_object_size(from, n, true);
15954+
15955 if (__builtin_constant_p(n)) {
15956 unsigned long ret;
15957
15958@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15959 __copy_to_user(void __user *to, const void *from, unsigned long n)
15960 {
15961 might_fault();
15962+
15963 return __copy_to_user_inatomic(to, from, n);
15964 }
15965
15966 static __always_inline unsigned long
15967 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15968 {
15969+ if ((long)n < 0)
15970+ return n;
15971+
15972 /* Avoid zeroing the tail if the copy fails..
15973 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15974 * but as the zeroing behaviour is only significant when n is not
15975@@ -137,6 +146,12 @@ static __always_inline unsigned long
15976 __copy_from_user(void *to, const void __user *from, unsigned long n)
15977 {
15978 might_fault();
15979+
15980+ if ((long)n < 0)
15981+ return n;
15982+
15983+ check_object_size(to, n, false);
15984+
15985 if (__builtin_constant_p(n)) {
15986 unsigned long ret;
15987
15988@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15989 const void __user *from, unsigned long n)
15990 {
15991 might_fault();
15992+
15993+ if ((long)n < 0)
15994+ return n;
15995+
15996 if (__builtin_constant_p(n)) {
15997 unsigned long ret;
15998
15999@@ -181,15 +200,19 @@ static __always_inline unsigned long
16000 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
16001 unsigned long n)
16002 {
16003- return __copy_from_user_ll_nocache_nozero(to, from, n);
16004+ if ((long)n < 0)
16005+ return n;
16006+
16007+ return __copy_from_user_ll_nocache_nozero(to, from, n);
16008 }
16009
16010-unsigned long __must_check copy_to_user(void __user *to,
16011- const void *from, unsigned long n);
16012-unsigned long __must_check _copy_from_user(void *to,
16013- const void __user *from,
16014- unsigned long n);
16015-
16016+extern void copy_to_user_overflow(void)
16017+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16018+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16019+#else
16020+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16021+#endif
16022+;
16023
16024 extern void copy_from_user_overflow(void)
16025 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16026@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
16027 #endif
16028 ;
16029
16030-static inline unsigned long __must_check copy_from_user(void *to,
16031- const void __user *from,
16032- unsigned long n)
16033+/**
16034+ * copy_to_user: - Copy a block of data into user space.
16035+ * @to: Destination address, in user space.
16036+ * @from: Source address, in kernel space.
16037+ * @n: Number of bytes to copy.
16038+ *
16039+ * Context: User context only. This function may sleep.
16040+ *
16041+ * Copy data from kernel space to user space.
16042+ *
16043+ * Returns number of bytes that could not be copied.
16044+ * On success, this will be zero.
16045+ */
16046+static inline unsigned long __must_check
16047+copy_to_user(void __user *to, const void *from, unsigned long n)
16048 {
16049- int sz = __compiletime_object_size(to);
16050+ size_t sz = __compiletime_object_size(from);
16051
16052- if (likely(sz == -1 || sz >= n))
16053- n = _copy_from_user(to, from, n);
16054- else
16055+ if (unlikely(sz != (size_t)-1 && sz < n))
16056+ copy_to_user_overflow();
16057+ else if (access_ok(VERIFY_WRITE, to, n))
16058+ n = __copy_to_user(to, from, n);
16059+ return n;
16060+}
16061+
16062+/**
16063+ * copy_from_user: - Copy a block of data from user space.
16064+ * @to: Destination address, in kernel space.
16065+ * @from: Source address, in user space.
16066+ * @n: Number of bytes to copy.
16067+ *
16068+ * Context: User context only. This function may sleep.
16069+ *
16070+ * Copy data from user space to kernel space.
16071+ *
16072+ * Returns number of bytes that could not be copied.
16073+ * On success, this will be zero.
16074+ *
16075+ * If some data could not be copied, this function will pad the copied
16076+ * data to the requested size using zero bytes.
16077+ */
16078+static inline unsigned long __must_check
16079+copy_from_user(void *to, const void __user *from, unsigned long n)
16080+{
16081+ size_t sz = __compiletime_object_size(to);
16082+
16083+ check_object_size(to, n, false);
16084+
16085+ if (unlikely(sz != (size_t)-1 && sz < n))
16086 copy_from_user_overflow();
16087-
16088+ else if (access_ok(VERIFY_READ, from, n))
16089+ n = __copy_from_user(to, from, n);
16090+ else if ((long)n > 0)
16091+ memset(to, 0, n);
16092 return n;
16093 }
16094
16095diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
16096index 142810c..1f2a0a7 100644
16097--- a/arch/x86/include/asm/uaccess_64.h
16098+++ b/arch/x86/include/asm/uaccess_64.h
16099@@ -10,6 +10,9 @@
16100 #include <asm/alternative.h>
16101 #include <asm/cpufeature.h>
16102 #include <asm/page.h>
16103+#include <asm/pgtable.h>
16104+
16105+#define set_fs(x) (current_thread_info()->addr_limit = (x))
16106
16107 /*
16108 * Copy To/From Userspace
16109@@ -17,13 +20,13 @@
16110
16111 /* Handles exceptions in both to and from, but doesn't do access_ok */
16112 __must_check unsigned long
16113-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
16114+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
16115 __must_check unsigned long
16116-copy_user_generic_string(void *to, const void *from, unsigned len);
16117+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
16118 __must_check unsigned long
16119-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
16120+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
16121
16122-static __always_inline __must_check unsigned long
16123+static __always_inline __must_check __size_overflow(3) unsigned long
16124 copy_user_generic(void *to, const void *from, unsigned len)
16125 {
16126 unsigned ret;
16127@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
16128 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
16129 "=d" (len)),
16130 "1" (to), "2" (from), "3" (len)
16131- : "memory", "rcx", "r8", "r9", "r10", "r11");
16132+ : "memory", "rcx", "r8", "r9", "r11");
16133 return ret;
16134 }
16135
16136+static __always_inline __must_check unsigned long
16137+__copy_to_user(void __user *to, const void *from, unsigned long len);
16138+static __always_inline __must_check unsigned long
16139+__copy_from_user(void *to, const void __user *from, unsigned long len);
16140 __must_check unsigned long
16141-_copy_to_user(void __user *to, const void *from, unsigned len);
16142-__must_check unsigned long
16143-_copy_from_user(void *to, const void __user *from, unsigned len);
16144-__must_check unsigned long
16145-copy_in_user(void __user *to, const void __user *from, unsigned len);
16146+copy_in_user(void __user *to, const void __user *from, unsigned long len);
16147+
16148+extern void copy_to_user_overflow(void)
16149+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16150+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16151+#else
16152+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16153+#endif
16154+;
16155+
16156+extern void copy_from_user_overflow(void)
16157+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16158+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16159+#else
16160+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16161+#endif
16162+;
16163
16164 static inline unsigned long __must_check copy_from_user(void *to,
16165 const void __user *from,
16166 unsigned long n)
16167 {
16168- int sz = __compiletime_object_size(to);
16169-
16170 might_fault();
16171- if (likely(sz == -1 || sz >= n))
16172- n = _copy_from_user(to, from, n);
16173-#ifdef CONFIG_DEBUG_VM
16174- else
16175- WARN(1, "Buffer overflow detected!\n");
16176-#endif
16177+
16178+ check_object_size(to, n, false);
16179+
16180+ if (access_ok(VERIFY_READ, from, n))
16181+ n = __copy_from_user(to, from, n);
16182+ else if (n < INT_MAX)
16183+ memset(to, 0, n);
16184 return n;
16185 }
16186
16187 static __always_inline __must_check
16188-int copy_to_user(void __user *dst, const void *src, unsigned size)
16189+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16190 {
16191 might_fault();
16192
16193- return _copy_to_user(dst, src, size);
16194+ if (access_ok(VERIFY_WRITE, dst, size))
16195+ size = __copy_to_user(dst, src, size);
16196+ return size;
16197 }
16198
16199 static __always_inline __must_check
16200-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16201+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16202 {
16203- int ret = 0;
16204+ size_t sz = __compiletime_object_size(dst);
16205+ unsigned ret = 0;
16206
16207 might_fault();
16208+
16209+ if (size > INT_MAX)
16210+ return size;
16211+
16212+ check_object_size(dst, size, false);
16213+
16214+#ifdef CONFIG_PAX_MEMORY_UDEREF
16215+ if (!__access_ok(VERIFY_READ, src, size))
16216+ return size;
16217+#endif
16218+
16219+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16220+ copy_from_user_overflow();
16221+ return size;
16222+ }
16223+
16224 if (!__builtin_constant_p(size))
16225- return copy_user_generic(dst, (__force void *)src, size);
16226+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16227 switch (size) {
16228- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16229+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16230 ret, "b", "b", "=q", 1);
16231 return ret;
16232- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16233+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16234 ret, "w", "w", "=r", 2);
16235 return ret;
16236- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16237+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16238 ret, "l", "k", "=r", 4);
16239 return ret;
16240- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16241+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16242 ret, "q", "", "=r", 8);
16243 return ret;
16244 case 10:
16245- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16246+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16247 ret, "q", "", "=r", 10);
16248 if (unlikely(ret))
16249 return ret;
16250 __get_user_asm(*(u16 *)(8 + (char *)dst),
16251- (u16 __user *)(8 + (char __user *)src),
16252+ (const u16 __user *)(8 + (const char __user *)src),
16253 ret, "w", "w", "=r", 2);
16254 return ret;
16255 case 16:
16256- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16257+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16258 ret, "q", "", "=r", 16);
16259 if (unlikely(ret))
16260 return ret;
16261 __get_user_asm(*(u64 *)(8 + (char *)dst),
16262- (u64 __user *)(8 + (char __user *)src),
16263+ (const u64 __user *)(8 + (const char __user *)src),
16264 ret, "q", "", "=r", 8);
16265 return ret;
16266 default:
16267- return copy_user_generic(dst, (__force void *)src, size);
16268+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16269 }
16270 }
16271
16272 static __always_inline __must_check
16273-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16274+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16275 {
16276- int ret = 0;
16277+ size_t sz = __compiletime_object_size(src);
16278+ unsigned ret = 0;
16279
16280 might_fault();
16281+
16282+ if (size > INT_MAX)
16283+ return size;
16284+
16285+ check_object_size(src, size, true);
16286+
16287+#ifdef CONFIG_PAX_MEMORY_UDEREF
16288+ if (!__access_ok(VERIFY_WRITE, dst, size))
16289+ return size;
16290+#endif
16291+
16292+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16293+ copy_to_user_overflow();
16294+ return size;
16295+ }
16296+
16297 if (!__builtin_constant_p(size))
16298- return copy_user_generic((__force void *)dst, src, size);
16299+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16300 switch (size) {
16301- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16302+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16303 ret, "b", "b", "iq", 1);
16304 return ret;
16305- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16306+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16307 ret, "w", "w", "ir", 2);
16308 return ret;
16309- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16310+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16311 ret, "l", "k", "ir", 4);
16312 return ret;
16313- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16314+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16315 ret, "q", "", "er", 8);
16316 return ret;
16317 case 10:
16318- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16319+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16320 ret, "q", "", "er", 10);
16321 if (unlikely(ret))
16322 return ret;
16323 asm("":::"memory");
16324- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16325+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16326 ret, "w", "w", "ir", 2);
16327 return ret;
16328 case 16:
16329- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16330+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16331 ret, "q", "", "er", 16);
16332 if (unlikely(ret))
16333 return ret;
16334 asm("":::"memory");
16335- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16336+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16337 ret, "q", "", "er", 8);
16338 return ret;
16339 default:
16340- return copy_user_generic((__force void *)dst, src, size);
16341+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16342 }
16343 }
16344
16345 static __always_inline __must_check
16346-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16347+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16348 {
16349- int ret = 0;
16350+ unsigned ret = 0;
16351
16352 might_fault();
16353+
16354+ if (size > INT_MAX)
16355+ return size;
16356+
16357+#ifdef CONFIG_PAX_MEMORY_UDEREF
16358+ if (!__access_ok(VERIFY_READ, src, size))
16359+ return size;
16360+ if (!__access_ok(VERIFY_WRITE, dst, size))
16361+ return size;
16362+#endif
16363+
16364 if (!__builtin_constant_p(size))
16365- return copy_user_generic((__force void *)dst,
16366- (__force void *)src, size);
16367+ return copy_user_generic((__force_kernel void *)____m(dst),
16368+ (__force_kernel const void *)____m(src), size);
16369 switch (size) {
16370 case 1: {
16371 u8 tmp;
16372- __get_user_asm(tmp, (u8 __user *)src,
16373+ __get_user_asm(tmp, (const u8 __user *)src,
16374 ret, "b", "b", "=q", 1);
16375 if (likely(!ret))
16376 __put_user_asm(tmp, (u8 __user *)dst,
16377@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16378 }
16379 case 2: {
16380 u16 tmp;
16381- __get_user_asm(tmp, (u16 __user *)src,
16382+ __get_user_asm(tmp, (const u16 __user *)src,
16383 ret, "w", "w", "=r", 2);
16384 if (likely(!ret))
16385 __put_user_asm(tmp, (u16 __user *)dst,
16386@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16387
16388 case 4: {
16389 u32 tmp;
16390- __get_user_asm(tmp, (u32 __user *)src,
16391+ __get_user_asm(tmp, (const u32 __user *)src,
16392 ret, "l", "k", "=r", 4);
16393 if (likely(!ret))
16394 __put_user_asm(tmp, (u32 __user *)dst,
16395@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16396 }
16397 case 8: {
16398 u64 tmp;
16399- __get_user_asm(tmp, (u64 __user *)src,
16400+ __get_user_asm(tmp, (const u64 __user *)src,
16401 ret, "q", "", "=r", 8);
16402 if (likely(!ret))
16403 __put_user_asm(tmp, (u64 __user *)dst,
16404@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16405 return ret;
16406 }
16407 default:
16408- return copy_user_generic((__force void *)dst,
16409- (__force void *)src, size);
16410+ return copy_user_generic((__force_kernel void *)____m(dst),
16411+ (__force_kernel const void *)____m(src), size);
16412 }
16413 }
16414
16415 static __must_check __always_inline int
16416-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16417+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16418 {
16419- return copy_user_generic(dst, (__force const void *)src, size);
16420+ if (size > INT_MAX)
16421+ return size;
16422+
16423+#ifdef CONFIG_PAX_MEMORY_UDEREF
16424+ if (!__access_ok(VERIFY_READ, src, size))
16425+ return size;
16426+#endif
16427+
16428+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16429 }
16430
16431-static __must_check __always_inline int
16432-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16433+static __must_check __always_inline unsigned long
16434+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16435 {
16436- return copy_user_generic((__force void *)dst, src, size);
16437+ if (size > INT_MAX)
16438+ return size;
16439+
16440+#ifdef CONFIG_PAX_MEMORY_UDEREF
16441+ if (!__access_ok(VERIFY_WRITE, dst, size))
16442+ return size;
16443+#endif
16444+
16445+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16446 }
16447
16448-extern long __copy_user_nocache(void *dst, const void __user *src,
16449- unsigned size, int zerorest);
16450+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16451+ unsigned long size, int zerorest) __size_overflow(3);
16452
16453-static inline int
16454-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16455+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16456 {
16457 might_sleep();
16458+
16459+ if (size > INT_MAX)
16460+ return size;
16461+
16462+#ifdef CONFIG_PAX_MEMORY_UDEREF
16463+ if (!__access_ok(VERIFY_READ, src, size))
16464+ return size;
16465+#endif
16466+
16467 return __copy_user_nocache(dst, src, size, 1);
16468 }
16469
16470-static inline int
16471-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16472- unsigned size)
16473+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16474+ unsigned long size)
16475 {
16476+ if (size > INT_MAX)
16477+ return size;
16478+
16479+#ifdef CONFIG_PAX_MEMORY_UDEREF
16480+ if (!__access_ok(VERIFY_READ, src, size))
16481+ return size;
16482+#endif
16483+
16484 return __copy_user_nocache(dst, src, size, 0);
16485 }
16486
16487-unsigned long
16488-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16489+extern unsigned long
16490+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16491
16492 #endif /* _ASM_X86_UACCESS_64_H */
16493diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16494index 5b238981..77fdd78 100644
16495--- a/arch/x86/include/asm/word-at-a-time.h
16496+++ b/arch/x86/include/asm/word-at-a-time.h
16497@@ -11,7 +11,7 @@
16498 * and shift, for example.
16499 */
16500 struct word_at_a_time {
16501- const unsigned long one_bits, high_bits;
16502+ unsigned long one_bits, high_bits;
16503 };
16504
16505 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16506diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16507index d8d9922..bf6cecb 100644
16508--- a/arch/x86/include/asm/x86_init.h
16509+++ b/arch/x86/include/asm/x86_init.h
16510@@ -129,7 +129,7 @@ struct x86_init_ops {
16511 struct x86_init_timers timers;
16512 struct x86_init_iommu iommu;
16513 struct x86_init_pci pci;
16514-};
16515+} __no_const;
16516
16517 /**
16518 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16519@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
16520 void (*setup_percpu_clockev)(void);
16521 void (*early_percpu_clock_init)(void);
16522 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16523-};
16524+} __no_const;
16525
16526 /**
16527 * struct x86_platform_ops - platform specific runtime functions
16528@@ -166,7 +166,7 @@ struct x86_platform_ops {
16529 void (*save_sched_clock_state)(void);
16530 void (*restore_sched_clock_state)(void);
16531 void (*apic_post_init)(void);
16532-};
16533+} __no_const;
16534
16535 struct pci_dev;
16536 struct msi_msg;
16537@@ -180,7 +180,7 @@ struct x86_msi_ops {
16538 void (*teardown_msi_irqs)(struct pci_dev *dev);
16539 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16540 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
16541-};
16542+} __no_const;
16543
16544 struct IO_APIC_route_entry;
16545 struct io_apic_irq_attr;
16546@@ -201,7 +201,7 @@ struct x86_io_apic_ops {
16547 unsigned int destination, int vector,
16548 struct io_apic_irq_attr *attr);
16549 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
16550-};
16551+} __no_const;
16552
16553 extern struct x86_init_ops x86_init;
16554 extern struct x86_cpuinit_ops x86_cpuinit;
16555diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16556index 0415cda..b43d877 100644
16557--- a/arch/x86/include/asm/xsave.h
16558+++ b/arch/x86/include/asm/xsave.h
16559@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16560 return -EFAULT;
16561
16562 __asm__ __volatile__(ASM_STAC "\n"
16563- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16564+ "1:"
16565+ __copyuser_seg
16566+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16567 "2: " ASM_CLAC "\n"
16568 ".section .fixup,\"ax\"\n"
16569 "3: movl $-1,%[err]\n"
16570@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16571 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16572 {
16573 int err;
16574- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16575+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16576 u32 lmask = mask;
16577 u32 hmask = mask >> 32;
16578
16579 __asm__ __volatile__(ASM_STAC "\n"
16580- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16581+ "1:"
16582+ __copyuser_seg
16583+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16584 "2: " ASM_CLAC "\n"
16585 ".section .fixup,\"ax\"\n"
16586 "3: movl $-1,%[err]\n"
16587diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16588index bbae024..e1528f9 100644
16589--- a/arch/x86/include/uapi/asm/e820.h
16590+++ b/arch/x86/include/uapi/asm/e820.h
16591@@ -63,7 +63,7 @@ struct e820map {
16592 #define ISA_START_ADDRESS 0xa0000
16593 #define ISA_END_ADDRESS 0x100000
16594
16595-#define BIOS_BEGIN 0x000a0000
16596+#define BIOS_BEGIN 0x000c0000
16597 #define BIOS_END 0x00100000
16598
16599 #define BIOS_ROM_BASE 0xffe00000
16600diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16601index 7bd3bd3..5dac791 100644
16602--- a/arch/x86/kernel/Makefile
16603+++ b/arch/x86/kernel/Makefile
16604@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16605 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16606 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16607 obj-y += probe_roms.o
16608-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16609+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16610 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16611 obj-y += syscall_$(BITS).o
16612 obj-$(CONFIG_X86_64) += vsyscall_64.o
16613diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16614index 230c8ea..f915130 100644
16615--- a/arch/x86/kernel/acpi/boot.c
16616+++ b/arch/x86/kernel/acpi/boot.c
16617@@ -1361,7 +1361,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16618 * If your system is blacklisted here, but you find that acpi=force
16619 * works for you, please contact linux-acpi@vger.kernel.org
16620 */
16621-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16622+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16623 /*
16624 * Boxes that need ACPI disabled
16625 */
16626@@ -1436,7 +1436,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16627 };
16628
16629 /* second table for DMI checks that should run after early-quirks */
16630-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16631+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16632 /*
16633 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16634 * which includes some code which overrides all temperature
16635diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16636index b44577b..27d8443 100644
16637--- a/arch/x86/kernel/acpi/sleep.c
16638+++ b/arch/x86/kernel/acpi/sleep.c
16639@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16640 #else /* CONFIG_64BIT */
16641 #ifdef CONFIG_SMP
16642 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16643+
16644+ pax_open_kernel();
16645 early_gdt_descr.address =
16646 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16647+ pax_close_kernel();
16648+
16649 initial_gs = per_cpu_offset(smp_processor_id());
16650 #endif
16651 initial_code = (unsigned long)wakeup_long64;
16652diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16653index d1daa66..59fecba 100644
16654--- a/arch/x86/kernel/acpi/wakeup_32.S
16655+++ b/arch/x86/kernel/acpi/wakeup_32.S
16656@@ -29,13 +29,11 @@ wakeup_pmode_return:
16657 # and restore the stack ... but you need gdt for this to work
16658 movl saved_context_esp, %esp
16659
16660- movl %cs:saved_magic, %eax
16661- cmpl $0x12345678, %eax
16662+ cmpl $0x12345678, saved_magic
16663 jne bogus_magic
16664
16665 # jump to place where we left off
16666- movl saved_eip, %eax
16667- jmp *%eax
16668+ jmp *(saved_eip)
16669
16670 bogus_magic:
16671 jmp bogus_magic
16672diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16673index c15cf9a..0e63558 100644
16674--- a/arch/x86/kernel/alternative.c
16675+++ b/arch/x86/kernel/alternative.c
16676@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16677 */
16678 for (a = start; a < end; a++) {
16679 instr = (u8 *)&a->instr_offset + a->instr_offset;
16680+
16681+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16682+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16683+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16684+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16685+#endif
16686+
16687 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16688 BUG_ON(a->replacementlen > a->instrlen);
16689 BUG_ON(a->instrlen > sizeof(insnbuf));
16690@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16691 for (poff = start; poff < end; poff++) {
16692 u8 *ptr = (u8 *)poff + *poff;
16693
16694+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16695+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16696+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16697+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16698+#endif
16699+
16700 if (!*poff || ptr < text || ptr >= text_end)
16701 continue;
16702 /* turn DS segment override prefix into lock prefix */
16703- if (*ptr == 0x3e)
16704+ if (*ktla_ktva(ptr) == 0x3e)
16705 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16706 }
16707 mutex_unlock(&text_mutex);
16708@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16709 for (poff = start; poff < end; poff++) {
16710 u8 *ptr = (u8 *)poff + *poff;
16711
16712+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16713+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16714+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16715+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16716+#endif
16717+
16718 if (!*poff || ptr < text || ptr >= text_end)
16719 continue;
16720 /* turn lock prefix into DS segment override prefix */
16721- if (*ptr == 0xf0)
16722+ if (*ktla_ktva(ptr) == 0xf0)
16723 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16724 }
16725 mutex_unlock(&text_mutex);
16726@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16727
16728 BUG_ON(p->len > MAX_PATCH_LEN);
16729 /* prep the buffer with the original instructions */
16730- memcpy(insnbuf, p->instr, p->len);
16731+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16732 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16733 (unsigned long)p->instr, p->len);
16734
16735@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16736 if (!uniproc_patched || num_possible_cpus() == 1)
16737 free_init_pages("SMP alternatives",
16738 (unsigned long)__smp_locks,
16739- (unsigned long)__smp_locks_end);
16740+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16741 #endif
16742
16743 apply_paravirt(__parainstructions, __parainstructions_end);
16744@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16745 * instructions. And on the local CPU you need to be protected again NMI or MCE
16746 * handlers seeing an inconsistent instruction while you patch.
16747 */
16748-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16749+void *__kprobes text_poke_early(void *addr, const void *opcode,
16750 size_t len)
16751 {
16752 unsigned long flags;
16753 local_irq_save(flags);
16754- memcpy(addr, opcode, len);
16755+
16756+ pax_open_kernel();
16757+ memcpy(ktla_ktva(addr), opcode, len);
16758 sync_core();
16759+ pax_close_kernel();
16760+
16761 local_irq_restore(flags);
16762 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16763 that causes hangs on some VIA CPUs. */
16764@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16765 */
16766 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16767 {
16768- unsigned long flags;
16769- char *vaddr;
16770+ unsigned char *vaddr = ktla_ktva(addr);
16771 struct page *pages[2];
16772- int i;
16773+ size_t i;
16774
16775 if (!core_kernel_text((unsigned long)addr)) {
16776- pages[0] = vmalloc_to_page(addr);
16777- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16778+ pages[0] = vmalloc_to_page(vaddr);
16779+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16780 } else {
16781- pages[0] = virt_to_page(addr);
16782+ pages[0] = virt_to_page(vaddr);
16783 WARN_ON(!PageReserved(pages[0]));
16784- pages[1] = virt_to_page(addr + PAGE_SIZE);
16785+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16786 }
16787 BUG_ON(!pages[0]);
16788- local_irq_save(flags);
16789- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16790- if (pages[1])
16791- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16792- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16793- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16794- clear_fixmap(FIX_TEXT_POKE0);
16795- if (pages[1])
16796- clear_fixmap(FIX_TEXT_POKE1);
16797- local_flush_tlb();
16798- sync_core();
16799- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16800- that causes hangs on some VIA CPUs. */
16801+ text_poke_early(addr, opcode, len);
16802 for (i = 0; i < len; i++)
16803- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16804- local_irq_restore(flags);
16805+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16806 return addr;
16807 }
16808
16809diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16810index 904611b..004dde6 100644
16811--- a/arch/x86/kernel/apic/apic.c
16812+++ b/arch/x86/kernel/apic/apic.c
16813@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16814 /*
16815 * Debug level, exported for io_apic.c
16816 */
16817-unsigned int apic_verbosity;
16818+int apic_verbosity;
16819
16820 int pic_mode;
16821
16822@@ -1955,7 +1955,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16823 apic_write(APIC_ESR, 0);
16824 v1 = apic_read(APIC_ESR);
16825 ack_APIC_irq();
16826- atomic_inc(&irq_err_count);
16827+ atomic_inc_unchecked(&irq_err_count);
16828
16829 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16830 smp_processor_id(), v0 , v1);
16831diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16832index 00c77cf..2dc6a2d 100644
16833--- a/arch/x86/kernel/apic/apic_flat_64.c
16834+++ b/arch/x86/kernel/apic/apic_flat_64.c
16835@@ -157,7 +157,7 @@ static int flat_probe(void)
16836 return 1;
16837 }
16838
16839-static struct apic apic_flat = {
16840+static struct apic apic_flat __read_only = {
16841 .name = "flat",
16842 .probe = flat_probe,
16843 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16844@@ -271,7 +271,7 @@ static int physflat_probe(void)
16845 return 0;
16846 }
16847
16848-static struct apic apic_physflat = {
16849+static struct apic apic_physflat __read_only = {
16850
16851 .name = "physical flat",
16852 .probe = physflat_probe,
16853diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16854index e145f28..2752888 100644
16855--- a/arch/x86/kernel/apic/apic_noop.c
16856+++ b/arch/x86/kernel/apic/apic_noop.c
16857@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16858 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16859 }
16860
16861-struct apic apic_noop = {
16862+struct apic apic_noop __read_only = {
16863 .name = "noop",
16864 .probe = noop_probe,
16865 .acpi_madt_oem_check = NULL,
16866diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16867index d50e364..543bee3 100644
16868--- a/arch/x86/kernel/apic/bigsmp_32.c
16869+++ b/arch/x86/kernel/apic/bigsmp_32.c
16870@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16871 return dmi_bigsmp;
16872 }
16873
16874-static struct apic apic_bigsmp = {
16875+static struct apic apic_bigsmp __read_only = {
16876
16877 .name = "bigsmp",
16878 .probe = probe_bigsmp,
16879diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16880index 0874799..a7a7892 100644
16881--- a/arch/x86/kernel/apic/es7000_32.c
16882+++ b/arch/x86/kernel/apic/es7000_32.c
16883@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16884 return ret && es7000_apic_is_cluster();
16885 }
16886
16887-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16888-static struct apic __refdata apic_es7000_cluster = {
16889+static struct apic apic_es7000_cluster __read_only = {
16890
16891 .name = "es7000",
16892 .probe = probe_es7000,
16893@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16894 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16895 };
16896
16897-static struct apic __refdata apic_es7000 = {
16898+static struct apic apic_es7000 __read_only = {
16899
16900 .name = "es7000",
16901 .probe = probe_es7000,
16902diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16903index 9ed796c..e930fe4 100644
16904--- a/arch/x86/kernel/apic/io_apic.c
16905+++ b/arch/x86/kernel/apic/io_apic.c
16906@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16907 }
16908 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16909
16910-void lock_vector_lock(void)
16911+void lock_vector_lock(void) __acquires(vector_lock)
16912 {
16913 /* Used to the online set of cpus does not change
16914 * during assign_irq_vector.
16915@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
16916 raw_spin_lock(&vector_lock);
16917 }
16918
16919-void unlock_vector_lock(void)
16920+void unlock_vector_lock(void) __releases(vector_lock)
16921 {
16922 raw_spin_unlock(&vector_lock);
16923 }
16924@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
16925 ack_APIC_irq();
16926 }
16927
16928-atomic_t irq_mis_count;
16929+atomic_unchecked_t irq_mis_count;
16930
16931 #ifdef CONFIG_GENERIC_PENDING_IRQ
16932 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16933@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
16934 * at the cpu.
16935 */
16936 if (!(v & (1 << (i & 0x1f)))) {
16937- atomic_inc(&irq_mis_count);
16938+ atomic_inc_unchecked(&irq_mis_count);
16939
16940 eoi_ioapic_irq(irq, cfg);
16941 }
16942diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16943index d661ee9..791fd33 100644
16944--- a/arch/x86/kernel/apic/numaq_32.c
16945+++ b/arch/x86/kernel/apic/numaq_32.c
16946@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16947 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16948 }
16949
16950-/* Use __refdata to keep false positive warning calm. */
16951-static struct apic __refdata apic_numaq = {
16952+static struct apic apic_numaq __read_only = {
16953
16954 .name = "NUMAQ",
16955 .probe = probe_numaq,
16956diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16957index eb35ef9..f184a21 100644
16958--- a/arch/x86/kernel/apic/probe_32.c
16959+++ b/arch/x86/kernel/apic/probe_32.c
16960@@ -72,7 +72,7 @@ static int probe_default(void)
16961 return 1;
16962 }
16963
16964-static struct apic apic_default = {
16965+static struct apic apic_default __read_only = {
16966
16967 .name = "default",
16968 .probe = probe_default,
16969diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16970index 77c95c0..434f8a4 100644
16971--- a/arch/x86/kernel/apic/summit_32.c
16972+++ b/arch/x86/kernel/apic/summit_32.c
16973@@ -486,7 +486,7 @@ void setup_summit(void)
16974 }
16975 #endif
16976
16977-static struct apic apic_summit = {
16978+static struct apic apic_summit __read_only = {
16979
16980 .name = "summit",
16981 .probe = probe_summit,
16982diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16983index c88baa4..757aee1 100644
16984--- a/arch/x86/kernel/apic/x2apic_cluster.c
16985+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16986@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16987 return notifier_from_errno(err);
16988 }
16989
16990-static struct notifier_block __refdata x2apic_cpu_notifier = {
16991+static struct notifier_block x2apic_cpu_notifier = {
16992 .notifier_call = update_clusterinfo,
16993 };
16994
16995@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16996 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16997 }
16998
16999-static struct apic apic_x2apic_cluster = {
17000+static struct apic apic_x2apic_cluster __read_only = {
17001
17002 .name = "cluster x2apic",
17003 .probe = x2apic_cluster_probe,
17004diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
17005index 562a76d..a003c0f 100644
17006--- a/arch/x86/kernel/apic/x2apic_phys.c
17007+++ b/arch/x86/kernel/apic/x2apic_phys.c
17008@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
17009 return apic == &apic_x2apic_phys;
17010 }
17011
17012-static struct apic apic_x2apic_phys = {
17013+static struct apic apic_x2apic_phys __read_only = {
17014
17015 .name = "physical x2apic",
17016 .probe = x2apic_phys_probe,
17017diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
17018index 794f6eb..67e1db2 100644
17019--- a/arch/x86/kernel/apic/x2apic_uv_x.c
17020+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
17021@@ -342,7 +342,7 @@ static int uv_probe(void)
17022 return apic == &apic_x2apic_uv_x;
17023 }
17024
17025-static struct apic __refdata apic_x2apic_uv_x = {
17026+static struct apic apic_x2apic_uv_x __read_only = {
17027
17028 .name = "UV large system",
17029 .probe = uv_probe,
17030diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
17031index 53a4e27..038760a 100644
17032--- a/arch/x86/kernel/apm_32.c
17033+++ b/arch/x86/kernel/apm_32.c
17034@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
17035 * This is for buggy BIOS's that refer to (real mode) segment 0x40
17036 * even though they are called in protected mode.
17037 */
17038-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
17039+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
17040 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
17041
17042 static const char driver_version[] = "1.16ac"; /* no spaces */
17043@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
17044 BUG_ON(cpu != 0);
17045 gdt = get_cpu_gdt_table(cpu);
17046 save_desc_40 = gdt[0x40 / 8];
17047+
17048+ pax_open_kernel();
17049 gdt[0x40 / 8] = bad_bios_desc;
17050+ pax_close_kernel();
17051
17052 apm_irq_save(flags);
17053 APM_DO_SAVE_SEGS;
17054@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
17055 &call->esi);
17056 APM_DO_RESTORE_SEGS;
17057 apm_irq_restore(flags);
17058+
17059+ pax_open_kernel();
17060 gdt[0x40 / 8] = save_desc_40;
17061+ pax_close_kernel();
17062+
17063 put_cpu();
17064
17065 return call->eax & 0xff;
17066@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
17067 BUG_ON(cpu != 0);
17068 gdt = get_cpu_gdt_table(cpu);
17069 save_desc_40 = gdt[0x40 / 8];
17070+
17071+ pax_open_kernel();
17072 gdt[0x40 / 8] = bad_bios_desc;
17073+ pax_close_kernel();
17074
17075 apm_irq_save(flags);
17076 APM_DO_SAVE_SEGS;
17077@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
17078 &call->eax);
17079 APM_DO_RESTORE_SEGS;
17080 apm_irq_restore(flags);
17081+
17082+ pax_open_kernel();
17083 gdt[0x40 / 8] = save_desc_40;
17084+ pax_close_kernel();
17085+
17086 put_cpu();
17087 return error;
17088 }
17089@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
17090 * code to that CPU.
17091 */
17092 gdt = get_cpu_gdt_table(0);
17093+
17094+ pax_open_kernel();
17095 set_desc_base(&gdt[APM_CS >> 3],
17096 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
17097 set_desc_base(&gdt[APM_CS_16 >> 3],
17098 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
17099 set_desc_base(&gdt[APM_DS >> 3],
17100 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
17101+ pax_close_kernel();
17102
17103 proc_create("apm", 0, NULL, &apm_file_ops);
17104
17105diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
17106index 2861082..6d4718e 100644
17107--- a/arch/x86/kernel/asm-offsets.c
17108+++ b/arch/x86/kernel/asm-offsets.c
17109@@ -33,6 +33,8 @@ void common(void) {
17110 OFFSET(TI_status, thread_info, status);
17111 OFFSET(TI_addr_limit, thread_info, addr_limit);
17112 OFFSET(TI_preempt_count, thread_info, preempt_count);
17113+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
17114+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
17115
17116 BLANK();
17117 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
17118@@ -53,8 +55,26 @@ void common(void) {
17119 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
17120 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
17121 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
17122+
17123+#ifdef CONFIG_PAX_KERNEXEC
17124+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
17125 #endif
17126
17127+#ifdef CONFIG_PAX_MEMORY_UDEREF
17128+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
17129+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
17130+#ifdef CONFIG_X86_64
17131+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
17132+#endif
17133+#endif
17134+
17135+#endif
17136+
17137+ BLANK();
17138+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
17139+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
17140+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
17141+
17142 #ifdef CONFIG_XEN
17143 BLANK();
17144 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17145diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17146index e7c798b..2b2019b 100644
17147--- a/arch/x86/kernel/asm-offsets_64.c
17148+++ b/arch/x86/kernel/asm-offsets_64.c
17149@@ -77,6 +77,7 @@ int main(void)
17150 BLANK();
17151 #undef ENTRY
17152
17153+ DEFINE(TSS_size, sizeof(struct tss_struct));
17154 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17155 BLANK();
17156
17157diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17158index b0684e4..22ccfd7 100644
17159--- a/arch/x86/kernel/cpu/Makefile
17160+++ b/arch/x86/kernel/cpu/Makefile
17161@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17162 CFLAGS_REMOVE_perf_event.o = -pg
17163 endif
17164
17165-# Make sure load_percpu_segment has no stackprotector
17166-nostackp := $(call cc-option, -fno-stack-protector)
17167-CFLAGS_common.o := $(nostackp)
17168-
17169 obj-y := intel_cacheinfo.o scattered.o topology.o
17170 obj-y += proc.o capflags.o powerflags.o common.o
17171 obj-y += rdrand.o
17172diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17173index 5013a48..0782c53 100644
17174--- a/arch/x86/kernel/cpu/amd.c
17175+++ b/arch/x86/kernel/cpu/amd.c
17176@@ -744,7 +744,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17177 unsigned int size)
17178 {
17179 /* AMD errata T13 (order #21922) */
17180- if ((c->x86 == 6)) {
17181+ if (c->x86 == 6) {
17182 /* Duron Rev A0 */
17183 if (c->x86_model == 3 && c->x86_mask == 0)
17184 size = 64;
17185diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17186index 22018f7..bc6f5e3 100644
17187--- a/arch/x86/kernel/cpu/common.c
17188+++ b/arch/x86/kernel/cpu/common.c
17189@@ -88,60 +88,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17190
17191 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17192
17193-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17194-#ifdef CONFIG_X86_64
17195- /*
17196- * We need valid kernel segments for data and code in long mode too
17197- * IRET will check the segment types kkeil 2000/10/28
17198- * Also sysret mandates a special GDT layout
17199- *
17200- * TLS descriptors are currently at a different place compared to i386.
17201- * Hopefully nobody expects them at a fixed place (Wine?)
17202- */
17203- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17204- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17205- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17206- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17207- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17208- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17209-#else
17210- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17211- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17212- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17213- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17214- /*
17215- * Segments used for calling PnP BIOS have byte granularity.
17216- * They code segments and data segments have fixed 64k limits,
17217- * the transfer segment sizes are set at run time.
17218- */
17219- /* 32-bit code */
17220- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17221- /* 16-bit code */
17222- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17223- /* 16-bit data */
17224- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17225- /* 16-bit data */
17226- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17227- /* 16-bit data */
17228- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17229- /*
17230- * The APM segments have byte granularity and their bases
17231- * are set at run time. All have 64k limits.
17232- */
17233- /* 32-bit code */
17234- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17235- /* 16-bit code */
17236- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17237- /* data */
17238- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17239-
17240- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17241- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17242- GDT_STACK_CANARY_INIT
17243-#endif
17244-} };
17245-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17246-
17247 static int __init x86_xsave_setup(char *s)
17248 {
17249 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17250@@ -386,7 +332,7 @@ void switch_to_new_gdt(int cpu)
17251 {
17252 struct desc_ptr gdt_descr;
17253
17254- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17255+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17256 gdt_descr.size = GDT_SIZE - 1;
17257 load_gdt(&gdt_descr);
17258 /* Reload the per-cpu base */
17259@@ -882,6 +828,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17260 /* Filter out anything that depends on CPUID levels we don't have */
17261 filter_cpuid_features(c, true);
17262
17263+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17264+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17265+#endif
17266+
17267 /* If the model name is still unset, do table lookup. */
17268 if (!c->x86_model_id[0]) {
17269 const char *p;
17270@@ -1069,10 +1019,12 @@ static __init int setup_disablecpuid(char *arg)
17271 }
17272 __setup("clearcpuid=", setup_disablecpuid);
17273
17274+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17275+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17276+
17277 #ifdef CONFIG_X86_64
17278 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17279-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17280- (unsigned long) nmi_idt_table };
17281+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17282
17283 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17284 irq_stack_union) __aligned(PAGE_SIZE);
17285@@ -1086,7 +1038,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17286 EXPORT_PER_CPU_SYMBOL(current_task);
17287
17288 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17289- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17290+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17291 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17292
17293 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17294@@ -1231,7 +1183,7 @@ void __cpuinit cpu_init(void)
17295 load_ucode_ap();
17296
17297 cpu = stack_smp_processor_id();
17298- t = &per_cpu(init_tss, cpu);
17299+ t = init_tss + cpu;
17300 oist = &per_cpu(orig_ist, cpu);
17301
17302 #ifdef CONFIG_NUMA
17303@@ -1257,7 +1209,7 @@ void __cpuinit cpu_init(void)
17304 switch_to_new_gdt(cpu);
17305 loadsegment(fs, 0);
17306
17307- load_idt((const struct desc_ptr *)&idt_descr);
17308+ load_idt(&idt_descr);
17309
17310 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17311 syscall_init();
17312@@ -1266,7 +1218,6 @@ void __cpuinit cpu_init(void)
17313 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17314 barrier();
17315
17316- x86_configure_nx();
17317 enable_x2apic();
17318
17319 /*
17320@@ -1318,7 +1269,7 @@ void __cpuinit cpu_init(void)
17321 {
17322 int cpu = smp_processor_id();
17323 struct task_struct *curr = current;
17324- struct tss_struct *t = &per_cpu(init_tss, cpu);
17325+ struct tss_struct *t = init_tss + cpu;
17326 struct thread_struct *thread = &curr->thread;
17327
17328 show_ucode_info_early();
17329diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17330index 7c6f7d5..8cac382 100644
17331--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17332+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17333@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17334 };
17335
17336 #ifdef CONFIG_AMD_NB
17337+static struct attribute *default_attrs_amd_nb[] = {
17338+ &type.attr,
17339+ &level.attr,
17340+ &coherency_line_size.attr,
17341+ &physical_line_partition.attr,
17342+ &ways_of_associativity.attr,
17343+ &number_of_sets.attr,
17344+ &size.attr,
17345+ &shared_cpu_map.attr,
17346+ &shared_cpu_list.attr,
17347+ NULL,
17348+ NULL,
17349+ NULL,
17350+ NULL
17351+};
17352+
17353 static struct attribute ** __cpuinit amd_l3_attrs(void)
17354 {
17355 static struct attribute **attrs;
17356@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17357
17358 n = ARRAY_SIZE(default_attrs);
17359
17360- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17361- n += 2;
17362-
17363- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17364- n += 1;
17365-
17366- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17367- if (attrs == NULL)
17368- return attrs = default_attrs;
17369-
17370- for (n = 0; default_attrs[n]; n++)
17371- attrs[n] = default_attrs[n];
17372+ attrs = default_attrs_amd_nb;
17373
17374 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17375 attrs[n++] = &cache_disable_0.attr;
17376@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17377 .default_attrs = default_attrs,
17378 };
17379
17380+#ifdef CONFIG_AMD_NB
17381+static struct kobj_type ktype_cache_amd_nb = {
17382+ .sysfs_ops = &sysfs_ops,
17383+ .default_attrs = default_attrs_amd_nb,
17384+};
17385+#endif
17386+
17387 static struct kobj_type ktype_percpu_entry = {
17388 .sysfs_ops = &sysfs_ops,
17389 };
17390@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17391 return retval;
17392 }
17393
17394+#ifdef CONFIG_AMD_NB
17395+ amd_l3_attrs();
17396+#endif
17397+
17398 for (i = 0; i < num_cache_leaves; i++) {
17399+ struct kobj_type *ktype;
17400+
17401 this_object = INDEX_KOBJECT_PTR(cpu, i);
17402 this_object->cpu = cpu;
17403 this_object->index = i;
17404
17405 this_leaf = CPUID4_INFO_IDX(cpu, i);
17406
17407- ktype_cache.default_attrs = default_attrs;
17408+ ktype = &ktype_cache;
17409 #ifdef CONFIG_AMD_NB
17410 if (this_leaf->base.nb)
17411- ktype_cache.default_attrs = amd_l3_attrs();
17412+ ktype = &ktype_cache_amd_nb;
17413 #endif
17414 retval = kobject_init_and_add(&(this_object->kobj),
17415- &ktype_cache,
17416+ ktype,
17417 per_cpu(ici_cache_kobject, cpu),
17418 "index%1lu", i);
17419 if (unlikely(retval)) {
17420@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17421 return NOTIFY_OK;
17422 }
17423
17424-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17425+static struct notifier_block cacheinfo_cpu_notifier = {
17426 .notifier_call = cacheinfo_cpu_callback,
17427 };
17428
17429diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17430index 9239504..b2471ce 100644
17431--- a/arch/x86/kernel/cpu/mcheck/mce.c
17432+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17433@@ -45,6 +45,7 @@
17434 #include <asm/processor.h>
17435 #include <asm/mce.h>
17436 #include <asm/msr.h>
17437+#include <asm/local.h>
17438
17439 #include "mce-internal.h"
17440
17441@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17442 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17443 m->cs, m->ip);
17444
17445- if (m->cs == __KERNEL_CS)
17446+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17447 print_symbol("{%s}", m->ip);
17448 pr_cont("\n");
17449 }
17450@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17451
17452 #define PANIC_TIMEOUT 5 /* 5 seconds */
17453
17454-static atomic_t mce_paniced;
17455+static atomic_unchecked_t mce_paniced;
17456
17457 static int fake_panic;
17458-static atomic_t mce_fake_paniced;
17459+static atomic_unchecked_t mce_fake_paniced;
17460
17461 /* Panic in progress. Enable interrupts and wait for final IPI */
17462 static void wait_for_panic(void)
17463@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17464 /*
17465 * Make sure only one CPU runs in machine check panic
17466 */
17467- if (atomic_inc_return(&mce_paniced) > 1)
17468+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17469 wait_for_panic();
17470 barrier();
17471
17472@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17473 console_verbose();
17474 } else {
17475 /* Don't log too much for fake panic */
17476- if (atomic_inc_return(&mce_fake_paniced) > 1)
17477+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17478 return;
17479 }
17480 /* First print corrected ones that are still unlogged */
17481@@ -353,7 +354,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17482 if (!fake_panic) {
17483 if (panic_timeout == 0)
17484 panic_timeout = mca_cfg.panic_timeout;
17485- panic(msg);
17486+ panic("%s", msg);
17487 } else
17488 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
17489 }
17490@@ -683,7 +684,7 @@ static int mce_timed_out(u64 *t)
17491 * might have been modified by someone else.
17492 */
17493 rmb();
17494- if (atomic_read(&mce_paniced))
17495+ if (atomic_read_unchecked(&mce_paniced))
17496 wait_for_panic();
17497 if (!mca_cfg.monarch_timeout)
17498 goto out;
17499@@ -1654,7 +1655,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17500 }
17501
17502 /* Call the installed machine check handler for this CPU setup. */
17503-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17504+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17505 unexpected_machine_check;
17506
17507 /*
17508@@ -1677,7 +1678,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17509 return;
17510 }
17511
17512+ pax_open_kernel();
17513 machine_check_vector = do_machine_check;
17514+ pax_close_kernel();
17515
17516 __mcheck_cpu_init_generic();
17517 __mcheck_cpu_init_vendor(c);
17518@@ -1691,7 +1694,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17519 */
17520
17521 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17522-static int mce_chrdev_open_count; /* #times opened */
17523+static local_t mce_chrdev_open_count; /* #times opened */
17524 static int mce_chrdev_open_exclu; /* already open exclusive? */
17525
17526 static int mce_chrdev_open(struct inode *inode, struct file *file)
17527@@ -1699,7 +1702,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17528 spin_lock(&mce_chrdev_state_lock);
17529
17530 if (mce_chrdev_open_exclu ||
17531- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17532+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17533 spin_unlock(&mce_chrdev_state_lock);
17534
17535 return -EBUSY;
17536@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17537
17538 if (file->f_flags & O_EXCL)
17539 mce_chrdev_open_exclu = 1;
17540- mce_chrdev_open_count++;
17541+ local_inc(&mce_chrdev_open_count);
17542
17543 spin_unlock(&mce_chrdev_state_lock);
17544
17545@@ -1718,7 +1721,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17546 {
17547 spin_lock(&mce_chrdev_state_lock);
17548
17549- mce_chrdev_open_count--;
17550+ local_dec(&mce_chrdev_open_count);
17551 mce_chrdev_open_exclu = 0;
17552
17553 spin_unlock(&mce_chrdev_state_lock);
17554@@ -2364,7 +2367,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17555 return NOTIFY_OK;
17556 }
17557
17558-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17559+static struct notifier_block mce_cpu_notifier = {
17560 .notifier_call = mce_cpu_callback,
17561 };
17562
17563@@ -2374,7 +2377,7 @@ static __init void mce_init_banks(void)
17564
17565 for (i = 0; i < mca_cfg.banks; i++) {
17566 struct mce_bank *b = &mce_banks[i];
17567- struct device_attribute *a = &b->attr;
17568+ device_attribute_no_const *a = &b->attr;
17569
17570 sysfs_attr_init(&a->attr);
17571 a->attr.name = b->attrname;
17572@@ -2442,7 +2445,7 @@ struct dentry *mce_get_debugfs_dir(void)
17573 static void mce_reset(void)
17574 {
17575 cpu_missing = 0;
17576- atomic_set(&mce_fake_paniced, 0);
17577+ atomic_set_unchecked(&mce_fake_paniced, 0);
17578 atomic_set(&mce_executing, 0);
17579 atomic_set(&mce_callin, 0);
17580 atomic_set(&global_nwo, 0);
17581diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17582index 1c044b1..37a2a43 100644
17583--- a/arch/x86/kernel/cpu/mcheck/p5.c
17584+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17585@@ -11,6 +11,7 @@
17586 #include <asm/processor.h>
17587 #include <asm/mce.h>
17588 #include <asm/msr.h>
17589+#include <asm/pgtable.h>
17590
17591 /* By default disabled */
17592 int mce_p5_enabled __read_mostly;
17593@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17594 if (!cpu_has(c, X86_FEATURE_MCE))
17595 return;
17596
17597+ pax_open_kernel();
17598 machine_check_vector = pentium_machine_check;
17599+ pax_close_kernel();
17600 /* Make sure the vector pointer is visible before we enable MCEs: */
17601 wmb();
17602
17603diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17604index 47a1870..8c019a7 100644
17605--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17606+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17607@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17608 return notifier_from_errno(err);
17609 }
17610
17611-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17612+static struct notifier_block thermal_throttle_cpu_notifier =
17613 {
17614 .notifier_call = thermal_throttle_cpu_callback,
17615 };
17616diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17617index e9a701a..35317d6 100644
17618--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17619+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17620@@ -10,6 +10,7 @@
17621 #include <asm/processor.h>
17622 #include <asm/mce.h>
17623 #include <asm/msr.h>
17624+#include <asm/pgtable.h>
17625
17626 /* Machine check handler for WinChip C6: */
17627 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17628@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17629 {
17630 u32 lo, hi;
17631
17632+ pax_open_kernel();
17633 machine_check_vector = winchip_machine_check;
17634+ pax_close_kernel();
17635 /* Make sure the vector pointer is visible before we enable MCEs: */
17636 wmb();
17637
17638diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17639index 726bf96..81f0526 100644
17640--- a/arch/x86/kernel/cpu/mtrr/main.c
17641+++ b/arch/x86/kernel/cpu/mtrr/main.c
17642@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17643 u64 size_or_mask, size_and_mask;
17644 static bool mtrr_aps_delayed_init;
17645
17646-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17647+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17648
17649 const struct mtrr_ops *mtrr_if;
17650
17651diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17652index df5e41f..816c719 100644
17653--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17654+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17655@@ -25,7 +25,7 @@ struct mtrr_ops {
17656 int (*validate_add_page)(unsigned long base, unsigned long size,
17657 unsigned int type);
17658 int (*have_wrcomb)(void);
17659-};
17660+} __do_const;
17661
17662 extern int generic_get_free_region(unsigned long base, unsigned long size,
17663 int replace_reg);
17664diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17665index 1025f3c..824f677 100644
17666--- a/arch/x86/kernel/cpu/perf_event.c
17667+++ b/arch/x86/kernel/cpu/perf_event.c
17668@@ -1311,7 +1311,7 @@ static void __init pmu_check_apic(void)
17669 pr_info("no hardware sampling interrupt available.\n");
17670 }
17671
17672-static struct attribute_group x86_pmu_format_group = {
17673+static attribute_group_no_const x86_pmu_format_group = {
17674 .name = "format",
17675 .attrs = NULL,
17676 };
17677@@ -1410,7 +1410,7 @@ static struct attribute *events_attr[] = {
17678 NULL,
17679 };
17680
17681-static struct attribute_group x86_pmu_events_group = {
17682+static attribute_group_no_const x86_pmu_events_group = {
17683 .name = "events",
17684 .attrs = events_attr,
17685 };
17686@@ -1920,7 +1920,7 @@ static unsigned long get_segment_base(unsigned int segment)
17687 if (idx > GDT_ENTRIES)
17688 return 0;
17689
17690- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17691+ desc = get_cpu_gdt_table(smp_processor_id());
17692 }
17693
17694 return get_desc_base(desc + idx);
17695@@ -2010,7 +2010,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17696 break;
17697
17698 perf_callchain_store(entry, frame.return_address);
17699- fp = frame.next_frame;
17700+ fp = (const void __force_user *)frame.next_frame;
17701 }
17702 }
17703
17704diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17705index a9e2207..d70c83a 100644
17706--- a/arch/x86/kernel/cpu/perf_event_intel.c
17707+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17708@@ -2022,10 +2022,10 @@ __init int intel_pmu_init(void)
17709 * v2 and above have a perf capabilities MSR
17710 */
17711 if (version > 1) {
17712- u64 capabilities;
17713+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17714
17715- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17716- x86_pmu.intel_cap.capabilities = capabilities;
17717+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17718+ x86_pmu.intel_cap.capabilities = capabilities;
17719 }
17720
17721 intel_ds_init();
17722diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17723index 52441a2..f94fae8 100644
17724--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17725+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17726@@ -3093,7 +3093,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17727 static int __init uncore_type_init(struct intel_uncore_type *type)
17728 {
17729 struct intel_uncore_pmu *pmus;
17730- struct attribute_group *attr_group;
17731+ attribute_group_no_const *attr_group;
17732 struct attribute **attrs;
17733 int i, j;
17734
17735@@ -3518,7 +3518,7 @@ static int
17736 return NOTIFY_OK;
17737 }
17738
17739-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17740+static struct notifier_block uncore_cpu_nb = {
17741 .notifier_call = uncore_cpu_notifier,
17742 /*
17743 * to migrate uncore events, our notifier should be executed
17744diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17745index f952891..4722ad4 100644
17746--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17747+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17748@@ -488,7 +488,7 @@ struct intel_uncore_box {
17749 struct uncore_event_desc {
17750 struct kobj_attribute attr;
17751 const char *config;
17752-};
17753+} __do_const;
17754
17755 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17756 { \
17757diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17758index 1e4dbcf..b9a34c2 100644
17759--- a/arch/x86/kernel/cpuid.c
17760+++ b/arch/x86/kernel/cpuid.c
17761@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17762 return notifier_from_errno(err);
17763 }
17764
17765-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17766+static struct notifier_block cpuid_class_cpu_notifier =
17767 {
17768 .notifier_call = cpuid_class_cpu_callback,
17769 };
17770diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17771index 74467fe..18793d5 100644
17772--- a/arch/x86/kernel/crash.c
17773+++ b/arch/x86/kernel/crash.c
17774@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17775 {
17776 #ifdef CONFIG_X86_32
17777 struct pt_regs fixed_regs;
17778-#endif
17779
17780-#ifdef CONFIG_X86_32
17781- if (!user_mode_vm(regs)) {
17782+ if (!user_mode(regs)) {
17783 crash_fixup_ss_esp(&fixed_regs, regs);
17784 regs = &fixed_regs;
17785 }
17786diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
17787index afa64ad..dce67dd 100644
17788--- a/arch/x86/kernel/crash_dump_64.c
17789+++ b/arch/x86/kernel/crash_dump_64.c
17790@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
17791 return -ENOMEM;
17792
17793 if (userbuf) {
17794- if (copy_to_user(buf, vaddr + offset, csize)) {
17795+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
17796 iounmap(vaddr);
17797 return -EFAULT;
17798 }
17799diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17800index 155a13f..1672b9b 100644
17801--- a/arch/x86/kernel/doublefault_32.c
17802+++ b/arch/x86/kernel/doublefault_32.c
17803@@ -11,7 +11,7 @@
17804
17805 #define DOUBLEFAULT_STACKSIZE (1024)
17806 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17807-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17808+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17809
17810 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17811
17812@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17813 unsigned long gdt, tss;
17814
17815 native_store_gdt(&gdt_desc);
17816- gdt = gdt_desc.address;
17817+ gdt = (unsigned long)gdt_desc.address;
17818
17819 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17820
17821@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17822 /* 0x2 bit is always set */
17823 .flags = X86_EFLAGS_SF | 0x2,
17824 .sp = STACK_START,
17825- .es = __USER_DS,
17826+ .es = __KERNEL_DS,
17827 .cs = __KERNEL_CS,
17828 .ss = __KERNEL_DS,
17829- .ds = __USER_DS,
17830+ .ds = __KERNEL_DS,
17831 .fs = __KERNEL_PERCPU,
17832
17833 .__cr3 = __pa_nodebug(swapper_pg_dir),
17834diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17835index deb6421..622e0ed 100644
17836--- a/arch/x86/kernel/dumpstack.c
17837+++ b/arch/x86/kernel/dumpstack.c
17838@@ -2,6 +2,9 @@
17839 * Copyright (C) 1991, 1992 Linus Torvalds
17840 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17841 */
17842+#ifdef CONFIG_GRKERNSEC_HIDESYM
17843+#define __INCLUDED_BY_HIDESYM 1
17844+#endif
17845 #include <linux/kallsyms.h>
17846 #include <linux/kprobes.h>
17847 #include <linux/uaccess.h>
17848@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17849 static void
17850 print_ftrace_graph_addr(unsigned long addr, void *data,
17851 const struct stacktrace_ops *ops,
17852- struct thread_info *tinfo, int *graph)
17853+ struct task_struct *task, int *graph)
17854 {
17855- struct task_struct *task;
17856 unsigned long ret_addr;
17857 int index;
17858
17859 if (addr != (unsigned long)return_to_handler)
17860 return;
17861
17862- task = tinfo->task;
17863 index = task->curr_ret_stack;
17864
17865 if (!task->ret_stack || index < *graph)
17866@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17867 static inline void
17868 print_ftrace_graph_addr(unsigned long addr, void *data,
17869 const struct stacktrace_ops *ops,
17870- struct thread_info *tinfo, int *graph)
17871+ struct task_struct *task, int *graph)
17872 { }
17873 #endif
17874
17875@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17876 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17877 */
17878
17879-static inline int valid_stack_ptr(struct thread_info *tinfo,
17880- void *p, unsigned int size, void *end)
17881+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17882 {
17883- void *t = tinfo;
17884 if (end) {
17885 if (p < end && p >= (end-THREAD_SIZE))
17886 return 1;
17887@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17888 }
17889
17890 unsigned long
17891-print_context_stack(struct thread_info *tinfo,
17892+print_context_stack(struct task_struct *task, void *stack_start,
17893 unsigned long *stack, unsigned long bp,
17894 const struct stacktrace_ops *ops, void *data,
17895 unsigned long *end, int *graph)
17896 {
17897 struct stack_frame *frame = (struct stack_frame *)bp;
17898
17899- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17900+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17901 unsigned long addr;
17902
17903 addr = *stack;
17904@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17905 } else {
17906 ops->address(data, addr, 0);
17907 }
17908- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17909+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17910 }
17911 stack++;
17912 }
17913@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17914 EXPORT_SYMBOL_GPL(print_context_stack);
17915
17916 unsigned long
17917-print_context_stack_bp(struct thread_info *tinfo,
17918+print_context_stack_bp(struct task_struct *task, void *stack_start,
17919 unsigned long *stack, unsigned long bp,
17920 const struct stacktrace_ops *ops, void *data,
17921 unsigned long *end, int *graph)
17922@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17923 struct stack_frame *frame = (struct stack_frame *)bp;
17924 unsigned long *ret_addr = &frame->return_address;
17925
17926- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17927+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17928 unsigned long addr = *ret_addr;
17929
17930 if (!__kernel_text_address(addr))
17931@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17932 ops->address(data, addr, 1);
17933 frame = frame->next_frame;
17934 ret_addr = &frame->return_address;
17935- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17936+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17937 }
17938
17939 return (unsigned long)frame;
17940@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
17941 }
17942 EXPORT_SYMBOL_GPL(oops_begin);
17943
17944+extern void gr_handle_kernel_exploit(void);
17945+
17946 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17947 {
17948 if (regs && kexec_should_crash(current))
17949@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17950 panic("Fatal exception in interrupt");
17951 if (panic_on_oops)
17952 panic("Fatal exception");
17953- do_exit(signr);
17954+
17955+ gr_handle_kernel_exploit();
17956+
17957+ do_group_exit(signr);
17958 }
17959
17960 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17961@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17962 print_modules();
17963 show_regs(regs);
17964 #ifdef CONFIG_X86_32
17965- if (user_mode_vm(regs)) {
17966+ if (user_mode(regs)) {
17967 sp = regs->sp;
17968 ss = regs->ss & 0xffff;
17969 } else {
17970@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17971 unsigned long flags = oops_begin();
17972 int sig = SIGSEGV;
17973
17974- if (!user_mode_vm(regs))
17975+ if (!user_mode(regs))
17976 report_bug(regs->ip, regs);
17977
17978 if (__die(str, regs, err))
17979diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17980index f2a1770..540657f 100644
17981--- a/arch/x86/kernel/dumpstack_32.c
17982+++ b/arch/x86/kernel/dumpstack_32.c
17983@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17984 bp = stack_frame(task, regs);
17985
17986 for (;;) {
17987- struct thread_info *context;
17988+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17989
17990- context = (struct thread_info *)
17991- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17992- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17993+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17994
17995- stack = (unsigned long *)context->previous_esp;
17996- if (!stack)
17997+ if (stack_start == task_stack_page(task))
17998 break;
17999+ stack = *(unsigned long **)stack_start;
18000 if (ops->stack(data, "IRQ") < 0)
18001 break;
18002 touch_nmi_watchdog();
18003@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
18004 int i;
18005
18006 show_regs_print_info(KERN_EMERG);
18007- __show_regs(regs, !user_mode_vm(regs));
18008+ __show_regs(regs, !user_mode(regs));
18009
18010 /*
18011 * When in-kernel, we also print out the stack and code at the
18012 * time of the fault..
18013 */
18014- if (!user_mode_vm(regs)) {
18015+ if (!user_mode(regs)) {
18016 unsigned int code_prologue = code_bytes * 43 / 64;
18017 unsigned int code_len = code_bytes;
18018 unsigned char c;
18019 u8 *ip;
18020+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
18021
18022 pr_emerg("Stack:\n");
18023 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
18024
18025 pr_emerg("Code:");
18026
18027- ip = (u8 *)regs->ip - code_prologue;
18028+ ip = (u8 *)regs->ip - code_prologue + cs_base;
18029 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
18030 /* try starting at IP */
18031- ip = (u8 *)regs->ip;
18032+ ip = (u8 *)regs->ip + cs_base;
18033 code_len = code_len - code_prologue + 1;
18034 }
18035 for (i = 0; i < code_len; i++, ip++) {
18036@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
18037 pr_cont(" Bad EIP value.");
18038 break;
18039 }
18040- if (ip == (u8 *)regs->ip)
18041+ if (ip == (u8 *)regs->ip + cs_base)
18042 pr_cont(" <%02x>", c);
18043 else
18044 pr_cont(" %02x", c);
18045@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
18046 {
18047 unsigned short ud2;
18048
18049+ ip = ktla_ktva(ip);
18050 if (ip < PAGE_OFFSET)
18051 return 0;
18052 if (probe_kernel_address((unsigned short *)ip, ud2))
18053@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
18054
18055 return ud2 == 0x0b0f;
18056 }
18057+
18058+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18059+void pax_check_alloca(unsigned long size)
18060+{
18061+ unsigned long sp = (unsigned long)&sp, stack_left;
18062+
18063+ /* all kernel stacks are of the same size */
18064+ stack_left = sp & (THREAD_SIZE - 1);
18065+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18066+}
18067+EXPORT_SYMBOL(pax_check_alloca);
18068+#endif
18069diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
18070index addb207..99635fa 100644
18071--- a/arch/x86/kernel/dumpstack_64.c
18072+++ b/arch/x86/kernel/dumpstack_64.c
18073@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18074 unsigned long *irq_stack_end =
18075 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
18076 unsigned used = 0;
18077- struct thread_info *tinfo;
18078 int graph = 0;
18079 unsigned long dummy;
18080+ void *stack_start;
18081
18082 if (!task)
18083 task = current;
18084@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18085 * current stack address. If the stacks consist of nested
18086 * exceptions
18087 */
18088- tinfo = task_thread_info(task);
18089 for (;;) {
18090 char *id;
18091 unsigned long *estack_end;
18092+
18093 estack_end = in_exception_stack(cpu, (unsigned long)stack,
18094 &used, &id);
18095
18096@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18097 if (ops->stack(data, id) < 0)
18098 break;
18099
18100- bp = ops->walk_stack(tinfo, stack, bp, ops,
18101+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
18102 data, estack_end, &graph);
18103 ops->stack(data, "<EOE>");
18104 /*
18105@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18106 * second-to-last pointer (index -2 to end) in the
18107 * exception stack:
18108 */
18109+ if ((u16)estack_end[-1] != __KERNEL_DS)
18110+ goto out;
18111 stack = (unsigned long *) estack_end[-2];
18112 continue;
18113 }
18114@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18115 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18116 if (ops->stack(data, "IRQ") < 0)
18117 break;
18118- bp = ops->walk_stack(tinfo, stack, bp,
18119+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18120 ops, data, irq_stack_end, &graph);
18121 /*
18122 * We link to the next stack (which would be
18123@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18124 /*
18125 * This handles the process stack:
18126 */
18127- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18128+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18129+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18130+out:
18131 put_cpu();
18132 }
18133 EXPORT_SYMBOL(dump_trace);
18134@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
18135
18136 return ud2 == 0x0b0f;
18137 }
18138+
18139+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18140+void pax_check_alloca(unsigned long size)
18141+{
18142+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18143+ unsigned cpu, used;
18144+ char *id;
18145+
18146+ /* check the process stack first */
18147+ stack_start = (unsigned long)task_stack_page(current);
18148+ stack_end = stack_start + THREAD_SIZE;
18149+ if (likely(stack_start <= sp && sp < stack_end)) {
18150+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18151+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18152+ return;
18153+ }
18154+
18155+ cpu = get_cpu();
18156+
18157+ /* check the irq stacks */
18158+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18159+ stack_start = stack_end - IRQ_STACK_SIZE;
18160+ if (stack_start <= sp && sp < stack_end) {
18161+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18162+ put_cpu();
18163+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18164+ return;
18165+ }
18166+
18167+ /* check the exception stacks */
18168+ used = 0;
18169+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18170+ stack_start = stack_end - EXCEPTION_STKSZ;
18171+ if (stack_end && stack_start <= sp && sp < stack_end) {
18172+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18173+ put_cpu();
18174+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18175+ return;
18176+ }
18177+
18178+ put_cpu();
18179+
18180+ /* unknown stack */
18181+ BUG();
18182+}
18183+EXPORT_SYMBOL(pax_check_alloca);
18184+#endif
18185diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
18186index d32abea..74daf4f 100644
18187--- a/arch/x86/kernel/e820.c
18188+++ b/arch/x86/kernel/e820.c
18189@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
18190
18191 static void early_panic(char *msg)
18192 {
18193- early_printk(msg);
18194- panic(msg);
18195+ early_printk("%s", msg);
18196+ panic("%s", msg);
18197 }
18198
18199 static int userdef __initdata;
18200diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18201index d15f575..d692043 100644
18202--- a/arch/x86/kernel/early_printk.c
18203+++ b/arch/x86/kernel/early_printk.c
18204@@ -7,6 +7,7 @@
18205 #include <linux/pci_regs.h>
18206 #include <linux/pci_ids.h>
18207 #include <linux/errno.h>
18208+#include <linux/sched.h>
18209 #include <asm/io.h>
18210 #include <asm/processor.h>
18211 #include <asm/fcntl.h>
18212diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18213index 8f3e2de..caecc4e 100644
18214--- a/arch/x86/kernel/entry_32.S
18215+++ b/arch/x86/kernel/entry_32.S
18216@@ -177,13 +177,153 @@
18217 /*CFI_REL_OFFSET gs, PT_GS*/
18218 .endm
18219 .macro SET_KERNEL_GS reg
18220+
18221+#ifdef CONFIG_CC_STACKPROTECTOR
18222 movl $(__KERNEL_STACK_CANARY), \reg
18223+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18224+ movl $(__USER_DS), \reg
18225+#else
18226+ xorl \reg, \reg
18227+#endif
18228+
18229 movl \reg, %gs
18230 .endm
18231
18232 #endif /* CONFIG_X86_32_LAZY_GS */
18233
18234-.macro SAVE_ALL
18235+.macro pax_enter_kernel
18236+#ifdef CONFIG_PAX_KERNEXEC
18237+ call pax_enter_kernel
18238+#endif
18239+.endm
18240+
18241+.macro pax_exit_kernel
18242+#ifdef CONFIG_PAX_KERNEXEC
18243+ call pax_exit_kernel
18244+#endif
18245+.endm
18246+
18247+#ifdef CONFIG_PAX_KERNEXEC
18248+ENTRY(pax_enter_kernel)
18249+#ifdef CONFIG_PARAVIRT
18250+ pushl %eax
18251+ pushl %ecx
18252+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18253+ mov %eax, %esi
18254+#else
18255+ mov %cr0, %esi
18256+#endif
18257+ bts $16, %esi
18258+ jnc 1f
18259+ mov %cs, %esi
18260+ cmp $__KERNEL_CS, %esi
18261+ jz 3f
18262+ ljmp $__KERNEL_CS, $3f
18263+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18264+2:
18265+#ifdef CONFIG_PARAVIRT
18266+ mov %esi, %eax
18267+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18268+#else
18269+ mov %esi, %cr0
18270+#endif
18271+3:
18272+#ifdef CONFIG_PARAVIRT
18273+ popl %ecx
18274+ popl %eax
18275+#endif
18276+ ret
18277+ENDPROC(pax_enter_kernel)
18278+
18279+ENTRY(pax_exit_kernel)
18280+#ifdef CONFIG_PARAVIRT
18281+ pushl %eax
18282+ pushl %ecx
18283+#endif
18284+ mov %cs, %esi
18285+ cmp $__KERNEXEC_KERNEL_CS, %esi
18286+ jnz 2f
18287+#ifdef CONFIG_PARAVIRT
18288+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18289+ mov %eax, %esi
18290+#else
18291+ mov %cr0, %esi
18292+#endif
18293+ btr $16, %esi
18294+ ljmp $__KERNEL_CS, $1f
18295+1:
18296+#ifdef CONFIG_PARAVIRT
18297+ mov %esi, %eax
18298+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18299+#else
18300+ mov %esi, %cr0
18301+#endif
18302+2:
18303+#ifdef CONFIG_PARAVIRT
18304+ popl %ecx
18305+ popl %eax
18306+#endif
18307+ ret
18308+ENDPROC(pax_exit_kernel)
18309+#endif
18310+
18311+ .macro pax_erase_kstack
18312+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18313+ call pax_erase_kstack
18314+#endif
18315+ .endm
18316+
18317+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18318+/*
18319+ * ebp: thread_info
18320+ */
18321+ENTRY(pax_erase_kstack)
18322+ pushl %edi
18323+ pushl %ecx
18324+ pushl %eax
18325+
18326+ mov TI_lowest_stack(%ebp), %edi
18327+ mov $-0xBEEF, %eax
18328+ std
18329+
18330+1: mov %edi, %ecx
18331+ and $THREAD_SIZE_asm - 1, %ecx
18332+ shr $2, %ecx
18333+ repne scasl
18334+ jecxz 2f
18335+
18336+ cmp $2*16, %ecx
18337+ jc 2f
18338+
18339+ mov $2*16, %ecx
18340+ repe scasl
18341+ jecxz 2f
18342+ jne 1b
18343+
18344+2: cld
18345+ mov %esp, %ecx
18346+ sub %edi, %ecx
18347+
18348+ cmp $THREAD_SIZE_asm, %ecx
18349+ jb 3f
18350+ ud2
18351+3:
18352+
18353+ shr $2, %ecx
18354+ rep stosl
18355+
18356+ mov TI_task_thread_sp0(%ebp), %edi
18357+ sub $128, %edi
18358+ mov %edi, TI_lowest_stack(%ebp)
18359+
18360+ popl %eax
18361+ popl %ecx
18362+ popl %edi
18363+ ret
18364+ENDPROC(pax_erase_kstack)
18365+#endif
18366+
18367+.macro __SAVE_ALL _DS
18368 cld
18369 PUSH_GS
18370 pushl_cfi %fs
18371@@ -206,7 +346,7 @@
18372 CFI_REL_OFFSET ecx, 0
18373 pushl_cfi %ebx
18374 CFI_REL_OFFSET ebx, 0
18375- movl $(__USER_DS), %edx
18376+ movl $\_DS, %edx
18377 movl %edx, %ds
18378 movl %edx, %es
18379 movl $(__KERNEL_PERCPU), %edx
18380@@ -214,6 +354,15 @@
18381 SET_KERNEL_GS %edx
18382 .endm
18383
18384+.macro SAVE_ALL
18385+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18386+ __SAVE_ALL __KERNEL_DS
18387+ pax_enter_kernel
18388+#else
18389+ __SAVE_ALL __USER_DS
18390+#endif
18391+.endm
18392+
18393 .macro RESTORE_INT_REGS
18394 popl_cfi %ebx
18395 CFI_RESTORE ebx
18396@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18397 popfl_cfi
18398 jmp syscall_exit
18399 CFI_ENDPROC
18400-END(ret_from_fork)
18401+ENDPROC(ret_from_fork)
18402
18403 ENTRY(ret_from_kernel_thread)
18404 CFI_STARTPROC
18405@@ -344,7 +493,15 @@ ret_from_intr:
18406 andl $SEGMENT_RPL_MASK, %eax
18407 #endif
18408 cmpl $USER_RPL, %eax
18409+
18410+#ifdef CONFIG_PAX_KERNEXEC
18411+ jae resume_userspace
18412+
18413+ pax_exit_kernel
18414+ jmp resume_kernel
18415+#else
18416 jb resume_kernel # not returning to v8086 or userspace
18417+#endif
18418
18419 ENTRY(resume_userspace)
18420 LOCKDEP_SYS_EXIT
18421@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18422 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18423 # int/exception return?
18424 jne work_pending
18425- jmp restore_all
18426-END(ret_from_exception)
18427+ jmp restore_all_pax
18428+ENDPROC(ret_from_exception)
18429
18430 #ifdef CONFIG_PREEMPT
18431 ENTRY(resume_kernel)
18432@@ -372,7 +529,7 @@ need_resched:
18433 jz restore_all
18434 call preempt_schedule_irq
18435 jmp need_resched
18436-END(resume_kernel)
18437+ENDPROC(resume_kernel)
18438 #endif
18439 CFI_ENDPROC
18440 /*
18441@@ -406,30 +563,45 @@ sysenter_past_esp:
18442 /*CFI_REL_OFFSET cs, 0*/
18443 /*
18444 * Push current_thread_info()->sysenter_return to the stack.
18445- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18446- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18447 */
18448- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18449+ pushl_cfi $0
18450 CFI_REL_OFFSET eip, 0
18451
18452 pushl_cfi %eax
18453 SAVE_ALL
18454+ GET_THREAD_INFO(%ebp)
18455+ movl TI_sysenter_return(%ebp),%ebp
18456+ movl %ebp,PT_EIP(%esp)
18457 ENABLE_INTERRUPTS(CLBR_NONE)
18458
18459 /*
18460 * Load the potential sixth argument from user stack.
18461 * Careful about security.
18462 */
18463+ movl PT_OLDESP(%esp),%ebp
18464+
18465+#ifdef CONFIG_PAX_MEMORY_UDEREF
18466+ mov PT_OLDSS(%esp),%ds
18467+1: movl %ds:(%ebp),%ebp
18468+ push %ss
18469+ pop %ds
18470+#else
18471 cmpl $__PAGE_OFFSET-3,%ebp
18472 jae syscall_fault
18473 ASM_STAC
18474 1: movl (%ebp),%ebp
18475 ASM_CLAC
18476+#endif
18477+
18478 movl %ebp,PT_EBP(%esp)
18479 _ASM_EXTABLE(1b,syscall_fault)
18480
18481 GET_THREAD_INFO(%ebp)
18482
18483+#ifdef CONFIG_PAX_RANDKSTACK
18484+ pax_erase_kstack
18485+#endif
18486+
18487 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18488 jnz sysenter_audit
18489 sysenter_do_call:
18490@@ -444,12 +616,24 @@ sysenter_do_call:
18491 testl $_TIF_ALLWORK_MASK, %ecx
18492 jne sysexit_audit
18493 sysenter_exit:
18494+
18495+#ifdef CONFIG_PAX_RANDKSTACK
18496+ pushl_cfi %eax
18497+ movl %esp, %eax
18498+ call pax_randomize_kstack
18499+ popl_cfi %eax
18500+#endif
18501+
18502+ pax_erase_kstack
18503+
18504 /* if something modifies registers it must also disable sysexit */
18505 movl PT_EIP(%esp), %edx
18506 movl PT_OLDESP(%esp), %ecx
18507 xorl %ebp,%ebp
18508 TRACE_IRQS_ON
18509 1: mov PT_FS(%esp), %fs
18510+2: mov PT_DS(%esp), %ds
18511+3: mov PT_ES(%esp), %es
18512 PTGS_TO_GS
18513 ENABLE_INTERRUPTS_SYSEXIT
18514
18515@@ -466,6 +650,9 @@ sysenter_audit:
18516 movl %eax,%edx /* 2nd arg: syscall number */
18517 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18518 call __audit_syscall_entry
18519+
18520+ pax_erase_kstack
18521+
18522 pushl_cfi %ebx
18523 movl PT_EAX(%esp),%eax /* reload syscall number */
18524 jmp sysenter_do_call
18525@@ -491,10 +678,16 @@ sysexit_audit:
18526
18527 CFI_ENDPROC
18528 .pushsection .fixup,"ax"
18529-2: movl $0,PT_FS(%esp)
18530+4: movl $0,PT_FS(%esp)
18531+ jmp 1b
18532+5: movl $0,PT_DS(%esp)
18533+ jmp 1b
18534+6: movl $0,PT_ES(%esp)
18535 jmp 1b
18536 .popsection
18537- _ASM_EXTABLE(1b,2b)
18538+ _ASM_EXTABLE(1b,4b)
18539+ _ASM_EXTABLE(2b,5b)
18540+ _ASM_EXTABLE(3b,6b)
18541 PTGS_TO_GS_EX
18542 ENDPROC(ia32_sysenter_target)
18543
18544@@ -509,6 +702,11 @@ ENTRY(system_call)
18545 pushl_cfi %eax # save orig_eax
18546 SAVE_ALL
18547 GET_THREAD_INFO(%ebp)
18548+
18549+#ifdef CONFIG_PAX_RANDKSTACK
18550+ pax_erase_kstack
18551+#endif
18552+
18553 # system call tracing in operation / emulation
18554 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18555 jnz syscall_trace_entry
18556@@ -527,6 +725,15 @@ syscall_exit:
18557 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18558 jne syscall_exit_work
18559
18560+restore_all_pax:
18561+
18562+#ifdef CONFIG_PAX_RANDKSTACK
18563+ movl %esp, %eax
18564+ call pax_randomize_kstack
18565+#endif
18566+
18567+ pax_erase_kstack
18568+
18569 restore_all:
18570 TRACE_IRQS_IRET
18571 restore_all_notrace:
18572@@ -583,14 +790,34 @@ ldt_ss:
18573 * compensating for the offset by changing to the ESPFIX segment with
18574 * a base address that matches for the difference.
18575 */
18576-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18577+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18578 mov %esp, %edx /* load kernel esp */
18579 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18580 mov %dx, %ax /* eax: new kernel esp */
18581 sub %eax, %edx /* offset (low word is 0) */
18582+#ifdef CONFIG_SMP
18583+ movl PER_CPU_VAR(cpu_number), %ebx
18584+ shll $PAGE_SHIFT_asm, %ebx
18585+ addl $cpu_gdt_table, %ebx
18586+#else
18587+ movl $cpu_gdt_table, %ebx
18588+#endif
18589 shr $16, %edx
18590- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18591- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18592+
18593+#ifdef CONFIG_PAX_KERNEXEC
18594+ mov %cr0, %esi
18595+ btr $16, %esi
18596+ mov %esi, %cr0
18597+#endif
18598+
18599+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18600+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18601+
18602+#ifdef CONFIG_PAX_KERNEXEC
18603+ bts $16, %esi
18604+ mov %esi, %cr0
18605+#endif
18606+
18607 pushl_cfi $__ESPFIX_SS
18608 pushl_cfi %eax /* new kernel esp */
18609 /* Disable interrupts, but do not irqtrace this section: we
18610@@ -619,20 +846,18 @@ work_resched:
18611 movl TI_flags(%ebp), %ecx
18612 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18613 # than syscall tracing?
18614- jz restore_all
18615+ jz restore_all_pax
18616 testb $_TIF_NEED_RESCHED, %cl
18617 jnz work_resched
18618
18619 work_notifysig: # deal with pending signals and
18620 # notify-resume requests
18621+ movl %esp, %eax
18622 #ifdef CONFIG_VM86
18623 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18624- movl %esp, %eax
18625 jne work_notifysig_v86 # returning to kernel-space or
18626 # vm86-space
18627 1:
18628-#else
18629- movl %esp, %eax
18630 #endif
18631 TRACE_IRQS_ON
18632 ENABLE_INTERRUPTS(CLBR_NONE)
18633@@ -653,7 +878,7 @@ work_notifysig_v86:
18634 movl %eax, %esp
18635 jmp 1b
18636 #endif
18637-END(work_pending)
18638+ENDPROC(work_pending)
18639
18640 # perform syscall exit tracing
18641 ALIGN
18642@@ -661,11 +886,14 @@ syscall_trace_entry:
18643 movl $-ENOSYS,PT_EAX(%esp)
18644 movl %esp, %eax
18645 call syscall_trace_enter
18646+
18647+ pax_erase_kstack
18648+
18649 /* What it returned is what we'll actually use. */
18650 cmpl $(NR_syscalls), %eax
18651 jnae syscall_call
18652 jmp syscall_exit
18653-END(syscall_trace_entry)
18654+ENDPROC(syscall_trace_entry)
18655
18656 # perform syscall exit tracing
18657 ALIGN
18658@@ -678,21 +906,25 @@ syscall_exit_work:
18659 movl %esp, %eax
18660 call syscall_trace_leave
18661 jmp resume_userspace
18662-END(syscall_exit_work)
18663+ENDPROC(syscall_exit_work)
18664 CFI_ENDPROC
18665
18666 RING0_INT_FRAME # can't unwind into user space anyway
18667 syscall_fault:
18668+#ifdef CONFIG_PAX_MEMORY_UDEREF
18669+ push %ss
18670+ pop %ds
18671+#endif
18672 ASM_CLAC
18673 GET_THREAD_INFO(%ebp)
18674 movl $-EFAULT,PT_EAX(%esp)
18675 jmp resume_userspace
18676-END(syscall_fault)
18677+ENDPROC(syscall_fault)
18678
18679 syscall_badsys:
18680 movl $-ENOSYS,PT_EAX(%esp)
18681 jmp resume_userspace
18682-END(syscall_badsys)
18683+ENDPROC(syscall_badsys)
18684 CFI_ENDPROC
18685 /*
18686 * End of kprobes section
18687@@ -708,8 +940,15 @@ END(syscall_badsys)
18688 * normal stack and adjusts ESP with the matching offset.
18689 */
18690 /* fixup the stack */
18691- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18692- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18693+#ifdef CONFIG_SMP
18694+ movl PER_CPU_VAR(cpu_number), %ebx
18695+ shll $PAGE_SHIFT_asm, %ebx
18696+ addl $cpu_gdt_table, %ebx
18697+#else
18698+ movl $cpu_gdt_table, %ebx
18699+#endif
18700+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18701+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18702 shl $16, %eax
18703 addl %esp, %eax /* the adjusted stack pointer */
18704 pushl_cfi $__KERNEL_DS
18705@@ -762,7 +1001,7 @@ vector=vector+1
18706 .endr
18707 2: jmp common_interrupt
18708 .endr
18709-END(irq_entries_start)
18710+ENDPROC(irq_entries_start)
18711
18712 .previous
18713 END(interrupt)
18714@@ -813,7 +1052,7 @@ ENTRY(coprocessor_error)
18715 pushl_cfi $do_coprocessor_error
18716 jmp error_code
18717 CFI_ENDPROC
18718-END(coprocessor_error)
18719+ENDPROC(coprocessor_error)
18720
18721 ENTRY(simd_coprocessor_error)
18722 RING0_INT_FRAME
18723@@ -835,7 +1074,7 @@ ENTRY(simd_coprocessor_error)
18724 #endif
18725 jmp error_code
18726 CFI_ENDPROC
18727-END(simd_coprocessor_error)
18728+ENDPROC(simd_coprocessor_error)
18729
18730 ENTRY(device_not_available)
18731 RING0_INT_FRAME
18732@@ -844,18 +1083,18 @@ ENTRY(device_not_available)
18733 pushl_cfi $do_device_not_available
18734 jmp error_code
18735 CFI_ENDPROC
18736-END(device_not_available)
18737+ENDPROC(device_not_available)
18738
18739 #ifdef CONFIG_PARAVIRT
18740 ENTRY(native_iret)
18741 iret
18742 _ASM_EXTABLE(native_iret, iret_exc)
18743-END(native_iret)
18744+ENDPROC(native_iret)
18745
18746 ENTRY(native_irq_enable_sysexit)
18747 sti
18748 sysexit
18749-END(native_irq_enable_sysexit)
18750+ENDPROC(native_irq_enable_sysexit)
18751 #endif
18752
18753 ENTRY(overflow)
18754@@ -865,7 +1104,7 @@ ENTRY(overflow)
18755 pushl_cfi $do_overflow
18756 jmp error_code
18757 CFI_ENDPROC
18758-END(overflow)
18759+ENDPROC(overflow)
18760
18761 ENTRY(bounds)
18762 RING0_INT_FRAME
18763@@ -874,7 +1113,7 @@ ENTRY(bounds)
18764 pushl_cfi $do_bounds
18765 jmp error_code
18766 CFI_ENDPROC
18767-END(bounds)
18768+ENDPROC(bounds)
18769
18770 ENTRY(invalid_op)
18771 RING0_INT_FRAME
18772@@ -883,7 +1122,7 @@ ENTRY(invalid_op)
18773 pushl_cfi $do_invalid_op
18774 jmp error_code
18775 CFI_ENDPROC
18776-END(invalid_op)
18777+ENDPROC(invalid_op)
18778
18779 ENTRY(coprocessor_segment_overrun)
18780 RING0_INT_FRAME
18781@@ -892,7 +1131,7 @@ ENTRY(coprocessor_segment_overrun)
18782 pushl_cfi $do_coprocessor_segment_overrun
18783 jmp error_code
18784 CFI_ENDPROC
18785-END(coprocessor_segment_overrun)
18786+ENDPROC(coprocessor_segment_overrun)
18787
18788 ENTRY(invalid_TSS)
18789 RING0_EC_FRAME
18790@@ -900,7 +1139,7 @@ ENTRY(invalid_TSS)
18791 pushl_cfi $do_invalid_TSS
18792 jmp error_code
18793 CFI_ENDPROC
18794-END(invalid_TSS)
18795+ENDPROC(invalid_TSS)
18796
18797 ENTRY(segment_not_present)
18798 RING0_EC_FRAME
18799@@ -908,7 +1147,7 @@ ENTRY(segment_not_present)
18800 pushl_cfi $do_segment_not_present
18801 jmp error_code
18802 CFI_ENDPROC
18803-END(segment_not_present)
18804+ENDPROC(segment_not_present)
18805
18806 ENTRY(stack_segment)
18807 RING0_EC_FRAME
18808@@ -916,7 +1155,7 @@ ENTRY(stack_segment)
18809 pushl_cfi $do_stack_segment
18810 jmp error_code
18811 CFI_ENDPROC
18812-END(stack_segment)
18813+ENDPROC(stack_segment)
18814
18815 ENTRY(alignment_check)
18816 RING0_EC_FRAME
18817@@ -924,7 +1163,7 @@ ENTRY(alignment_check)
18818 pushl_cfi $do_alignment_check
18819 jmp error_code
18820 CFI_ENDPROC
18821-END(alignment_check)
18822+ENDPROC(alignment_check)
18823
18824 ENTRY(divide_error)
18825 RING0_INT_FRAME
18826@@ -933,7 +1172,7 @@ ENTRY(divide_error)
18827 pushl_cfi $do_divide_error
18828 jmp error_code
18829 CFI_ENDPROC
18830-END(divide_error)
18831+ENDPROC(divide_error)
18832
18833 #ifdef CONFIG_X86_MCE
18834 ENTRY(machine_check)
18835@@ -943,7 +1182,7 @@ ENTRY(machine_check)
18836 pushl_cfi machine_check_vector
18837 jmp error_code
18838 CFI_ENDPROC
18839-END(machine_check)
18840+ENDPROC(machine_check)
18841 #endif
18842
18843 ENTRY(spurious_interrupt_bug)
18844@@ -953,7 +1192,7 @@ ENTRY(spurious_interrupt_bug)
18845 pushl_cfi $do_spurious_interrupt_bug
18846 jmp error_code
18847 CFI_ENDPROC
18848-END(spurious_interrupt_bug)
18849+ENDPROC(spurious_interrupt_bug)
18850 /*
18851 * End of kprobes section
18852 */
18853@@ -1063,7 +1302,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
18854
18855 ENTRY(mcount)
18856 ret
18857-END(mcount)
18858+ENDPROC(mcount)
18859
18860 ENTRY(ftrace_caller)
18861 cmpl $0, function_trace_stop
18862@@ -1096,7 +1335,7 @@ ftrace_graph_call:
18863 .globl ftrace_stub
18864 ftrace_stub:
18865 ret
18866-END(ftrace_caller)
18867+ENDPROC(ftrace_caller)
18868
18869 ENTRY(ftrace_regs_caller)
18870 pushf /* push flags before compare (in cs location) */
18871@@ -1197,7 +1436,7 @@ trace:
18872 popl %ecx
18873 popl %eax
18874 jmp ftrace_stub
18875-END(mcount)
18876+ENDPROC(mcount)
18877 #endif /* CONFIG_DYNAMIC_FTRACE */
18878 #endif /* CONFIG_FUNCTION_TRACER */
18879
18880@@ -1215,7 +1454,7 @@ ENTRY(ftrace_graph_caller)
18881 popl %ecx
18882 popl %eax
18883 ret
18884-END(ftrace_graph_caller)
18885+ENDPROC(ftrace_graph_caller)
18886
18887 .globl return_to_handler
18888 return_to_handler:
18889@@ -1271,15 +1510,18 @@ error_code:
18890 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18891 REG_TO_PTGS %ecx
18892 SET_KERNEL_GS %ecx
18893- movl $(__USER_DS), %ecx
18894+ movl $(__KERNEL_DS), %ecx
18895 movl %ecx, %ds
18896 movl %ecx, %es
18897+
18898+ pax_enter_kernel
18899+
18900 TRACE_IRQS_OFF
18901 movl %esp,%eax # pt_regs pointer
18902 call *%edi
18903 jmp ret_from_exception
18904 CFI_ENDPROC
18905-END(page_fault)
18906+ENDPROC(page_fault)
18907
18908 /*
18909 * Debug traps and NMI can happen at the one SYSENTER instruction
18910@@ -1322,7 +1564,7 @@ debug_stack_correct:
18911 call do_debug
18912 jmp ret_from_exception
18913 CFI_ENDPROC
18914-END(debug)
18915+ENDPROC(debug)
18916
18917 /*
18918 * NMI is doubly nasty. It can happen _while_ we're handling
18919@@ -1360,6 +1602,9 @@ nmi_stack_correct:
18920 xorl %edx,%edx # zero error code
18921 movl %esp,%eax # pt_regs pointer
18922 call do_nmi
18923+
18924+ pax_exit_kernel
18925+
18926 jmp restore_all_notrace
18927 CFI_ENDPROC
18928
18929@@ -1396,12 +1641,15 @@ nmi_espfix_stack:
18930 FIXUP_ESPFIX_STACK # %eax == %esp
18931 xorl %edx,%edx # zero error code
18932 call do_nmi
18933+
18934+ pax_exit_kernel
18935+
18936 RESTORE_REGS
18937 lss 12+4(%esp), %esp # back to espfix stack
18938 CFI_ADJUST_CFA_OFFSET -24
18939 jmp irq_return
18940 CFI_ENDPROC
18941-END(nmi)
18942+ENDPROC(nmi)
18943
18944 ENTRY(int3)
18945 RING0_INT_FRAME
18946@@ -1414,14 +1662,14 @@ ENTRY(int3)
18947 call do_int3
18948 jmp ret_from_exception
18949 CFI_ENDPROC
18950-END(int3)
18951+ENDPROC(int3)
18952
18953 ENTRY(general_protection)
18954 RING0_EC_FRAME
18955 pushl_cfi $do_general_protection
18956 jmp error_code
18957 CFI_ENDPROC
18958-END(general_protection)
18959+ENDPROC(general_protection)
18960
18961 #ifdef CONFIG_KVM_GUEST
18962 ENTRY(async_page_fault)
18963@@ -1430,7 +1678,7 @@ ENTRY(async_page_fault)
18964 pushl_cfi $do_async_page_fault
18965 jmp error_code
18966 CFI_ENDPROC
18967-END(async_page_fault)
18968+ENDPROC(async_page_fault)
18969 #endif
18970
18971 /*
18972diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18973index 7272089..6204f9c5 100644
18974--- a/arch/x86/kernel/entry_64.S
18975+++ b/arch/x86/kernel/entry_64.S
18976@@ -59,6 +59,8 @@
18977 #include <asm/context_tracking.h>
18978 #include <asm/smap.h>
18979 #include <linux/err.h>
18980+#include <asm/pgtable.h>
18981+#include <asm/alternative-asm.h>
18982
18983 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18984 #include <linux/elf-em.h>
18985@@ -80,8 +82,9 @@
18986 #ifdef CONFIG_DYNAMIC_FTRACE
18987
18988 ENTRY(function_hook)
18989+ pax_force_retaddr
18990 retq
18991-END(function_hook)
18992+ENDPROC(function_hook)
18993
18994 /* skip is set if stack has been adjusted */
18995 .macro ftrace_caller_setup skip=0
18996@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18997 #endif
18998
18999 GLOBAL(ftrace_stub)
19000+ pax_force_retaddr
19001 retq
19002-END(ftrace_caller)
19003+ENDPROC(ftrace_caller)
19004
19005 ENTRY(ftrace_regs_caller)
19006 /* Save the current flags before compare (in SS location)*/
19007@@ -191,7 +195,7 @@ ftrace_restore_flags:
19008 popfq
19009 jmp ftrace_stub
19010
19011-END(ftrace_regs_caller)
19012+ENDPROC(ftrace_regs_caller)
19013
19014
19015 #else /* ! CONFIG_DYNAMIC_FTRACE */
19016@@ -212,6 +216,7 @@ ENTRY(function_hook)
19017 #endif
19018
19019 GLOBAL(ftrace_stub)
19020+ pax_force_retaddr
19021 retq
19022
19023 trace:
19024@@ -225,12 +230,13 @@ trace:
19025 #endif
19026 subq $MCOUNT_INSN_SIZE, %rdi
19027
19028+ pax_force_fptr ftrace_trace_function
19029 call *ftrace_trace_function
19030
19031 MCOUNT_RESTORE_FRAME
19032
19033 jmp ftrace_stub
19034-END(function_hook)
19035+ENDPROC(function_hook)
19036 #endif /* CONFIG_DYNAMIC_FTRACE */
19037 #endif /* CONFIG_FUNCTION_TRACER */
19038
19039@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
19040
19041 MCOUNT_RESTORE_FRAME
19042
19043+ pax_force_retaddr
19044 retq
19045-END(ftrace_graph_caller)
19046+ENDPROC(ftrace_graph_caller)
19047
19048 GLOBAL(return_to_handler)
19049 subq $24, %rsp
19050@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
19051 movq 8(%rsp), %rdx
19052 movq (%rsp), %rax
19053 addq $24, %rsp
19054+ pax_force_fptr %rdi
19055 jmp *%rdi
19056+ENDPROC(return_to_handler)
19057 #endif
19058
19059
19060@@ -284,6 +293,309 @@ ENTRY(native_usergs_sysret64)
19061 ENDPROC(native_usergs_sysret64)
19062 #endif /* CONFIG_PARAVIRT */
19063
19064+ .macro ljmpq sel, off
19065+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
19066+ .byte 0x48; ljmp *1234f(%rip)
19067+ .pushsection .rodata
19068+ .align 16
19069+ 1234: .quad \off; .word \sel
19070+ .popsection
19071+#else
19072+ pushq $\sel
19073+ pushq $\off
19074+ lretq
19075+#endif
19076+ .endm
19077+
19078+ .macro pax_enter_kernel
19079+ pax_set_fptr_mask
19080+#ifdef CONFIG_PAX_KERNEXEC
19081+ call pax_enter_kernel
19082+#endif
19083+ .endm
19084+
19085+ .macro pax_exit_kernel
19086+#ifdef CONFIG_PAX_KERNEXEC
19087+ call pax_exit_kernel
19088+#endif
19089+ .endm
19090+
19091+#ifdef CONFIG_PAX_KERNEXEC
19092+ENTRY(pax_enter_kernel)
19093+ pushq %rdi
19094+
19095+#ifdef CONFIG_PARAVIRT
19096+ PV_SAVE_REGS(CLBR_RDI)
19097+#endif
19098+
19099+ GET_CR0_INTO_RDI
19100+ bts $16,%rdi
19101+ jnc 3f
19102+ mov %cs,%edi
19103+ cmp $__KERNEL_CS,%edi
19104+ jnz 2f
19105+1:
19106+
19107+#ifdef CONFIG_PARAVIRT
19108+ PV_RESTORE_REGS(CLBR_RDI)
19109+#endif
19110+
19111+ popq %rdi
19112+ pax_force_retaddr
19113+ retq
19114+
19115+2: ljmpq __KERNEL_CS,1b
19116+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19117+4: SET_RDI_INTO_CR0
19118+ jmp 1b
19119+ENDPROC(pax_enter_kernel)
19120+
19121+ENTRY(pax_exit_kernel)
19122+ pushq %rdi
19123+
19124+#ifdef CONFIG_PARAVIRT
19125+ PV_SAVE_REGS(CLBR_RDI)
19126+#endif
19127+
19128+ mov %cs,%rdi
19129+ cmp $__KERNEXEC_KERNEL_CS,%edi
19130+ jz 2f
19131+ GET_CR0_INTO_RDI
19132+ bts $16,%rdi
19133+ jnc 4f
19134+1:
19135+
19136+#ifdef CONFIG_PARAVIRT
19137+ PV_RESTORE_REGS(CLBR_RDI);
19138+#endif
19139+
19140+ popq %rdi
19141+ pax_force_retaddr
19142+ retq
19143+
19144+2: GET_CR0_INTO_RDI
19145+ btr $16,%rdi
19146+ jnc 4f
19147+ ljmpq __KERNEL_CS,3f
19148+3: SET_RDI_INTO_CR0
19149+ jmp 1b
19150+4: ud2
19151+ jmp 4b
19152+ENDPROC(pax_exit_kernel)
19153+#endif
19154+
19155+ .macro pax_enter_kernel_user
19156+ pax_set_fptr_mask
19157+#ifdef CONFIG_PAX_MEMORY_UDEREF
19158+ call pax_enter_kernel_user
19159+#endif
19160+ .endm
19161+
19162+ .macro pax_exit_kernel_user
19163+#ifdef CONFIG_PAX_MEMORY_UDEREF
19164+ call pax_exit_kernel_user
19165+#endif
19166+#ifdef CONFIG_PAX_RANDKSTACK
19167+ pushq %rax
19168+ pushq %r11
19169+ call pax_randomize_kstack
19170+ popq %r11
19171+ popq %rax
19172+#endif
19173+ .endm
19174+
19175+#ifdef CONFIG_PAX_MEMORY_UDEREF
19176+ENTRY(pax_enter_kernel_user)
19177+ pushq %rdi
19178+ pushq %rbx
19179+
19180+#ifdef CONFIG_PARAVIRT
19181+ PV_SAVE_REGS(CLBR_RDI)
19182+#endif
19183+
19184+ GET_CR3_INTO_RDI
19185+ mov %rdi,%rbx
19186+ add $__START_KERNEL_map,%rbx
19187+ sub phys_base(%rip),%rbx
19188+
19189+#ifdef CONFIG_PARAVIRT
19190+ cmpl $0, pv_info+PARAVIRT_enabled
19191+ jz 1f
19192+ pushq %rdi
19193+ i = 0
19194+ .rept USER_PGD_PTRS
19195+ mov i*8(%rbx),%rsi
19196+ mov $0,%sil
19197+ lea i*8(%rbx),%rdi
19198+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19199+ i = i + 1
19200+ .endr
19201+ popq %rdi
19202+ jmp 2f
19203+1:
19204+#endif
19205+
19206+ i = 0
19207+ .rept USER_PGD_PTRS
19208+ movb $0,i*8(%rbx)
19209+ i = i + 1
19210+ .endr
19211+
19212+#ifdef CONFIG_PARAVIRT
19213+2:
19214+#endif
19215+ SET_RDI_INTO_CR3
19216+
19217+#ifdef CONFIG_PAX_KERNEXEC
19218+ GET_CR0_INTO_RDI
19219+ bts $16,%rdi
19220+ SET_RDI_INTO_CR0
19221+#endif
19222+
19223+#ifdef CONFIG_PARAVIRT
19224+ PV_RESTORE_REGS(CLBR_RDI)
19225+#endif
19226+
19227+ popq %rbx
19228+ popq %rdi
19229+ pax_force_retaddr
19230+ retq
19231+ENDPROC(pax_enter_kernel_user)
19232+
19233+ENTRY(pax_exit_kernel_user)
19234+ pushq %rdi
19235+ pushq %rbx
19236+
19237+#ifdef CONFIG_PARAVIRT
19238+ PV_SAVE_REGS(CLBR_RDI)
19239+#endif
19240+
19241+#ifdef CONFIG_PAX_KERNEXEC
19242+ GET_CR0_INTO_RDI
19243+ btr $16,%rdi
19244+ jnc 3f
19245+ SET_RDI_INTO_CR0
19246+#endif
19247+
19248+ GET_CR3_INTO_RDI
19249+ mov %rdi,%rbx
19250+ add $__START_KERNEL_map,%rbx
19251+ sub phys_base(%rip),%rbx
19252+
19253+#ifdef CONFIG_PARAVIRT
19254+ cmpl $0, pv_info+PARAVIRT_enabled
19255+ jz 1f
19256+ i = 0
19257+ .rept USER_PGD_PTRS
19258+ mov i*8(%rbx),%rsi
19259+ mov $0x67,%sil
19260+ lea i*8(%rbx),%rdi
19261+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19262+ i = i + 1
19263+ .endr
19264+ jmp 2f
19265+1:
19266+#endif
19267+
19268+ i = 0
19269+ .rept USER_PGD_PTRS
19270+ movb $0x67,i*8(%rbx)
19271+ i = i + 1
19272+ .endr
19273+
19274+#ifdef CONFIG_PARAVIRT
19275+2: PV_RESTORE_REGS(CLBR_RDI)
19276+#endif
19277+
19278+ popq %rbx
19279+ popq %rdi
19280+ pax_force_retaddr
19281+ retq
19282+3: ud2
19283+ jmp 3b
19284+ENDPROC(pax_exit_kernel_user)
19285+#endif
19286+
19287+ .macro pax_enter_kernel_nmi
19288+ pax_set_fptr_mask
19289+
19290+#ifdef CONFIG_PAX_KERNEXEC
19291+ GET_CR0_INTO_RDI
19292+ bts $16,%rdi
19293+ jc 110f
19294+ SET_RDI_INTO_CR0
19295+ or $2,%ebx
19296+110:
19297+#endif
19298+ .endm
19299+
19300+ .macro pax_exit_kernel_nmi
19301+#ifdef CONFIG_PAX_KERNEXEC
19302+ btr $1,%ebx
19303+ jnc 110f
19304+ GET_CR0_INTO_RDI
19305+ btr $16,%rdi
19306+ SET_RDI_INTO_CR0
19307+110:
19308+#endif
19309+ .endm
19310+
19311+ .macro pax_erase_kstack
19312+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19313+ call pax_erase_kstack
19314+#endif
19315+ .endm
19316+
19317+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19318+ENTRY(pax_erase_kstack)
19319+ pushq %rdi
19320+ pushq %rcx
19321+ pushq %rax
19322+ pushq %r11
19323+
19324+ GET_THREAD_INFO(%r11)
19325+ mov TI_lowest_stack(%r11), %rdi
19326+ mov $-0xBEEF, %rax
19327+ std
19328+
19329+1: mov %edi, %ecx
19330+ and $THREAD_SIZE_asm - 1, %ecx
19331+ shr $3, %ecx
19332+ repne scasq
19333+ jecxz 2f
19334+
19335+ cmp $2*8, %ecx
19336+ jc 2f
19337+
19338+ mov $2*8, %ecx
19339+ repe scasq
19340+ jecxz 2f
19341+ jne 1b
19342+
19343+2: cld
19344+ mov %esp, %ecx
19345+ sub %edi, %ecx
19346+
19347+ cmp $THREAD_SIZE_asm, %rcx
19348+ jb 3f
19349+ ud2
19350+3:
19351+
19352+ shr $3, %ecx
19353+ rep stosq
19354+
19355+ mov TI_task_thread_sp0(%r11), %rdi
19356+ sub $256, %rdi
19357+ mov %rdi, TI_lowest_stack(%r11)
19358+
19359+ popq %r11
19360+ popq %rax
19361+ popq %rcx
19362+ popq %rdi
19363+ pax_force_retaddr
19364+ ret
19365+ENDPROC(pax_erase_kstack)
19366+#endif
19367
19368 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19369 #ifdef CONFIG_TRACE_IRQFLAGS
19370@@ -375,8 +687,8 @@ ENDPROC(native_usergs_sysret64)
19371 .endm
19372
19373 .macro UNFAKE_STACK_FRAME
19374- addq $8*6, %rsp
19375- CFI_ADJUST_CFA_OFFSET -(6*8)
19376+ addq $8*6 + ARG_SKIP, %rsp
19377+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19378 .endm
19379
19380 /*
19381@@ -463,7 +775,7 @@ ENDPROC(native_usergs_sysret64)
19382 movq %rsp, %rsi
19383
19384 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19385- testl $3, CS-RBP(%rsi)
19386+ testb $3, CS-RBP(%rsi)
19387 je 1f
19388 SWAPGS
19389 /*
19390@@ -498,9 +810,10 @@ ENTRY(save_rest)
19391 movq_cfi r15, R15+16
19392 movq %r11, 8(%rsp) /* return address */
19393 FIXUP_TOP_OF_STACK %r11, 16
19394+ pax_force_retaddr
19395 ret
19396 CFI_ENDPROC
19397-END(save_rest)
19398+ENDPROC(save_rest)
19399
19400 /* save complete stack frame */
19401 .pushsection .kprobes.text, "ax"
19402@@ -529,9 +842,10 @@ ENTRY(save_paranoid)
19403 js 1f /* negative -> in kernel */
19404 SWAPGS
19405 xorl %ebx,%ebx
19406-1: ret
19407+1: pax_force_retaddr_bts
19408+ ret
19409 CFI_ENDPROC
19410-END(save_paranoid)
19411+ENDPROC(save_paranoid)
19412 .popsection
19413
19414 /*
19415@@ -553,7 +867,7 @@ ENTRY(ret_from_fork)
19416
19417 RESTORE_REST
19418
19419- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19420+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19421 jz 1f
19422
19423 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19424@@ -571,7 +885,7 @@ ENTRY(ret_from_fork)
19425 RESTORE_REST
19426 jmp int_ret_from_sys_call
19427 CFI_ENDPROC
19428-END(ret_from_fork)
19429+ENDPROC(ret_from_fork)
19430
19431 /*
19432 * System call entry. Up to 6 arguments in registers are supported.
19433@@ -608,7 +922,7 @@ END(ret_from_fork)
19434 ENTRY(system_call)
19435 CFI_STARTPROC simple
19436 CFI_SIGNAL_FRAME
19437- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19438+ CFI_DEF_CFA rsp,0
19439 CFI_REGISTER rip,rcx
19440 /*CFI_REGISTER rflags,r11*/
19441 SWAPGS_UNSAFE_STACK
19442@@ -621,16 +935,23 @@ GLOBAL(system_call_after_swapgs)
19443
19444 movq %rsp,PER_CPU_VAR(old_rsp)
19445 movq PER_CPU_VAR(kernel_stack),%rsp
19446+ SAVE_ARGS 8*6,0
19447+ pax_enter_kernel_user
19448+
19449+#ifdef CONFIG_PAX_RANDKSTACK
19450+ pax_erase_kstack
19451+#endif
19452+
19453 /*
19454 * No need to follow this irqs off/on section - it's straight
19455 * and short:
19456 */
19457 ENABLE_INTERRUPTS(CLBR_NONE)
19458- SAVE_ARGS 8,0
19459 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19460 movq %rcx,RIP-ARGOFFSET(%rsp)
19461 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19462- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19463+ GET_THREAD_INFO(%rcx)
19464+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19465 jnz tracesys
19466 system_call_fastpath:
19467 #if __SYSCALL_MASK == ~0
19468@@ -640,7 +961,7 @@ system_call_fastpath:
19469 cmpl $__NR_syscall_max,%eax
19470 #endif
19471 ja badsys
19472- movq %r10,%rcx
19473+ movq R10-ARGOFFSET(%rsp),%rcx
19474 call *sys_call_table(,%rax,8) # XXX: rip relative
19475 movq %rax,RAX-ARGOFFSET(%rsp)
19476 /*
19477@@ -654,10 +975,13 @@ sysret_check:
19478 LOCKDEP_SYS_EXIT
19479 DISABLE_INTERRUPTS(CLBR_NONE)
19480 TRACE_IRQS_OFF
19481- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19482+ GET_THREAD_INFO(%rcx)
19483+ movl TI_flags(%rcx),%edx
19484 andl %edi,%edx
19485 jnz sysret_careful
19486 CFI_REMEMBER_STATE
19487+ pax_exit_kernel_user
19488+ pax_erase_kstack
19489 /*
19490 * sysretq will re-enable interrupts:
19491 */
19492@@ -709,14 +1033,18 @@ badsys:
19493 * jump back to the normal fast path.
19494 */
19495 auditsys:
19496- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19497+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19498 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19499 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19500 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19501 movq %rax,%rsi /* 2nd arg: syscall number */
19502 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19503 call __audit_syscall_entry
19504+
19505+ pax_erase_kstack
19506+
19507 LOAD_ARGS 0 /* reload call-clobbered registers */
19508+ pax_set_fptr_mask
19509 jmp system_call_fastpath
19510
19511 /*
19512@@ -737,7 +1065,7 @@ sysret_audit:
19513 /* Do syscall tracing */
19514 tracesys:
19515 #ifdef CONFIG_AUDITSYSCALL
19516- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19517+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19518 jz auditsys
19519 #endif
19520 SAVE_REST
19521@@ -745,12 +1073,16 @@ tracesys:
19522 FIXUP_TOP_OF_STACK %rdi
19523 movq %rsp,%rdi
19524 call syscall_trace_enter
19525+
19526+ pax_erase_kstack
19527+
19528 /*
19529 * Reload arg registers from stack in case ptrace changed them.
19530 * We don't reload %rax because syscall_trace_enter() returned
19531 * the value it wants us to use in the table lookup.
19532 */
19533 LOAD_ARGS ARGOFFSET, 1
19534+ pax_set_fptr_mask
19535 RESTORE_REST
19536 #if __SYSCALL_MASK == ~0
19537 cmpq $__NR_syscall_max,%rax
19538@@ -759,7 +1091,7 @@ tracesys:
19539 cmpl $__NR_syscall_max,%eax
19540 #endif
19541 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19542- movq %r10,%rcx /* fixup for C */
19543+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19544 call *sys_call_table(,%rax,8)
19545 movq %rax,RAX-ARGOFFSET(%rsp)
19546 /* Use IRET because user could have changed frame */
19547@@ -780,7 +1112,9 @@ GLOBAL(int_with_check)
19548 andl %edi,%edx
19549 jnz int_careful
19550 andl $~TS_COMPAT,TI_status(%rcx)
19551- jmp retint_swapgs
19552+ pax_exit_kernel_user
19553+ pax_erase_kstack
19554+ jmp retint_swapgs_pax
19555
19556 /* Either reschedule or signal or syscall exit tracking needed. */
19557 /* First do a reschedule test. */
19558@@ -826,7 +1160,7 @@ int_restore_rest:
19559 TRACE_IRQS_OFF
19560 jmp int_with_check
19561 CFI_ENDPROC
19562-END(system_call)
19563+ENDPROC(system_call)
19564
19565 .macro FORK_LIKE func
19566 ENTRY(stub_\func)
19567@@ -839,9 +1173,10 @@ ENTRY(stub_\func)
19568 DEFAULT_FRAME 0 8 /* offset 8: return address */
19569 call sys_\func
19570 RESTORE_TOP_OF_STACK %r11, 8
19571+ pax_force_retaddr
19572 ret $REST_SKIP /* pop extended registers */
19573 CFI_ENDPROC
19574-END(stub_\func)
19575+ENDPROC(stub_\func)
19576 .endm
19577
19578 .macro FIXED_FRAME label,func
19579@@ -851,9 +1186,10 @@ ENTRY(\label)
19580 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
19581 call \func
19582 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
19583+ pax_force_retaddr
19584 ret
19585 CFI_ENDPROC
19586-END(\label)
19587+ENDPROC(\label)
19588 .endm
19589
19590 FORK_LIKE clone
19591@@ -870,9 +1206,10 @@ ENTRY(ptregscall_common)
19592 movq_cfi_restore R12+8, r12
19593 movq_cfi_restore RBP+8, rbp
19594 movq_cfi_restore RBX+8, rbx
19595+ pax_force_retaddr
19596 ret $REST_SKIP /* pop extended registers */
19597 CFI_ENDPROC
19598-END(ptregscall_common)
19599+ENDPROC(ptregscall_common)
19600
19601 ENTRY(stub_execve)
19602 CFI_STARTPROC
19603@@ -885,7 +1222,7 @@ ENTRY(stub_execve)
19604 RESTORE_REST
19605 jmp int_ret_from_sys_call
19606 CFI_ENDPROC
19607-END(stub_execve)
19608+ENDPROC(stub_execve)
19609
19610 /*
19611 * sigreturn is special because it needs to restore all registers on return.
19612@@ -902,7 +1239,7 @@ ENTRY(stub_rt_sigreturn)
19613 RESTORE_REST
19614 jmp int_ret_from_sys_call
19615 CFI_ENDPROC
19616-END(stub_rt_sigreturn)
19617+ENDPROC(stub_rt_sigreturn)
19618
19619 #ifdef CONFIG_X86_X32_ABI
19620 ENTRY(stub_x32_rt_sigreturn)
19621@@ -916,7 +1253,7 @@ ENTRY(stub_x32_rt_sigreturn)
19622 RESTORE_REST
19623 jmp int_ret_from_sys_call
19624 CFI_ENDPROC
19625-END(stub_x32_rt_sigreturn)
19626+ENDPROC(stub_x32_rt_sigreturn)
19627
19628 ENTRY(stub_x32_execve)
19629 CFI_STARTPROC
19630@@ -930,7 +1267,7 @@ ENTRY(stub_x32_execve)
19631 RESTORE_REST
19632 jmp int_ret_from_sys_call
19633 CFI_ENDPROC
19634-END(stub_x32_execve)
19635+ENDPROC(stub_x32_execve)
19636
19637 #endif
19638
19639@@ -967,7 +1304,7 @@ vector=vector+1
19640 2: jmp common_interrupt
19641 .endr
19642 CFI_ENDPROC
19643-END(irq_entries_start)
19644+ENDPROC(irq_entries_start)
19645
19646 .previous
19647 END(interrupt)
19648@@ -987,6 +1324,16 @@ END(interrupt)
19649 subq $ORIG_RAX-RBP, %rsp
19650 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19651 SAVE_ARGS_IRQ
19652+#ifdef CONFIG_PAX_MEMORY_UDEREF
19653+ testb $3, CS(%rdi)
19654+ jnz 1f
19655+ pax_enter_kernel
19656+ jmp 2f
19657+1: pax_enter_kernel_user
19658+2:
19659+#else
19660+ pax_enter_kernel
19661+#endif
19662 call \func
19663 .endm
19664
19665@@ -1019,7 +1366,7 @@ ret_from_intr:
19666
19667 exit_intr:
19668 GET_THREAD_INFO(%rcx)
19669- testl $3,CS-ARGOFFSET(%rsp)
19670+ testb $3,CS-ARGOFFSET(%rsp)
19671 je retint_kernel
19672
19673 /* Interrupt came from user space */
19674@@ -1041,12 +1388,16 @@ retint_swapgs: /* return to user-space */
19675 * The iretq could re-enable interrupts:
19676 */
19677 DISABLE_INTERRUPTS(CLBR_ANY)
19678+ pax_exit_kernel_user
19679+retint_swapgs_pax:
19680 TRACE_IRQS_IRETQ
19681 SWAPGS
19682 jmp restore_args
19683
19684 retint_restore_args: /* return to kernel space */
19685 DISABLE_INTERRUPTS(CLBR_ANY)
19686+ pax_exit_kernel
19687+ pax_force_retaddr (RIP-ARGOFFSET)
19688 /*
19689 * The iretq could re-enable interrupts:
19690 */
19691@@ -1129,7 +1480,7 @@ ENTRY(retint_kernel)
19692 #endif
19693
19694 CFI_ENDPROC
19695-END(common_interrupt)
19696+ENDPROC(common_interrupt)
19697 /*
19698 * End of kprobes section
19699 */
19700@@ -1147,7 +1498,7 @@ ENTRY(\sym)
19701 interrupt \do_sym
19702 jmp ret_from_intr
19703 CFI_ENDPROC
19704-END(\sym)
19705+ENDPROC(\sym)
19706 .endm
19707
19708 #ifdef CONFIG_SMP
19709@@ -1208,12 +1559,22 @@ ENTRY(\sym)
19710 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19711 call error_entry
19712 DEFAULT_FRAME 0
19713+#ifdef CONFIG_PAX_MEMORY_UDEREF
19714+ testb $3, CS(%rsp)
19715+ jnz 1f
19716+ pax_enter_kernel
19717+ jmp 2f
19718+1: pax_enter_kernel_user
19719+2:
19720+#else
19721+ pax_enter_kernel
19722+#endif
19723 movq %rsp,%rdi /* pt_regs pointer */
19724 xorl %esi,%esi /* no error code */
19725 call \do_sym
19726 jmp error_exit /* %ebx: no swapgs flag */
19727 CFI_ENDPROC
19728-END(\sym)
19729+ENDPROC(\sym)
19730 .endm
19731
19732 .macro paranoidzeroentry sym do_sym
19733@@ -1226,15 +1587,25 @@ ENTRY(\sym)
19734 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19735 call save_paranoid
19736 TRACE_IRQS_OFF
19737+#ifdef CONFIG_PAX_MEMORY_UDEREF
19738+ testb $3, CS(%rsp)
19739+ jnz 1f
19740+ pax_enter_kernel
19741+ jmp 2f
19742+1: pax_enter_kernel_user
19743+2:
19744+#else
19745+ pax_enter_kernel
19746+#endif
19747 movq %rsp,%rdi /* pt_regs pointer */
19748 xorl %esi,%esi /* no error code */
19749 call \do_sym
19750 jmp paranoid_exit /* %ebx: no swapgs flag */
19751 CFI_ENDPROC
19752-END(\sym)
19753+ENDPROC(\sym)
19754 .endm
19755
19756-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19757+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19758 .macro paranoidzeroentry_ist sym do_sym ist
19759 ENTRY(\sym)
19760 INTR_FRAME
19761@@ -1245,14 +1616,30 @@ ENTRY(\sym)
19762 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19763 call save_paranoid
19764 TRACE_IRQS_OFF_DEBUG
19765+#ifdef CONFIG_PAX_MEMORY_UDEREF
19766+ testb $3, CS(%rsp)
19767+ jnz 1f
19768+ pax_enter_kernel
19769+ jmp 2f
19770+1: pax_enter_kernel_user
19771+2:
19772+#else
19773+ pax_enter_kernel
19774+#endif
19775 movq %rsp,%rdi /* pt_regs pointer */
19776 xorl %esi,%esi /* no error code */
19777+#ifdef CONFIG_SMP
19778+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19779+ lea init_tss(%r12), %r12
19780+#else
19781+ lea init_tss(%rip), %r12
19782+#endif
19783 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19784 call \do_sym
19785 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19786 jmp paranoid_exit /* %ebx: no swapgs flag */
19787 CFI_ENDPROC
19788-END(\sym)
19789+ENDPROC(\sym)
19790 .endm
19791
19792 .macro errorentry sym do_sym
19793@@ -1264,13 +1651,23 @@ ENTRY(\sym)
19794 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19795 call error_entry
19796 DEFAULT_FRAME 0
19797+#ifdef CONFIG_PAX_MEMORY_UDEREF
19798+ testb $3, CS(%rsp)
19799+ jnz 1f
19800+ pax_enter_kernel
19801+ jmp 2f
19802+1: pax_enter_kernel_user
19803+2:
19804+#else
19805+ pax_enter_kernel
19806+#endif
19807 movq %rsp,%rdi /* pt_regs pointer */
19808 movq ORIG_RAX(%rsp),%rsi /* get error code */
19809 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19810 call \do_sym
19811 jmp error_exit /* %ebx: no swapgs flag */
19812 CFI_ENDPROC
19813-END(\sym)
19814+ENDPROC(\sym)
19815 .endm
19816
19817 /* error code is on the stack already */
19818@@ -1284,13 +1681,23 @@ ENTRY(\sym)
19819 call save_paranoid
19820 DEFAULT_FRAME 0
19821 TRACE_IRQS_OFF
19822+#ifdef CONFIG_PAX_MEMORY_UDEREF
19823+ testb $3, CS(%rsp)
19824+ jnz 1f
19825+ pax_enter_kernel
19826+ jmp 2f
19827+1: pax_enter_kernel_user
19828+2:
19829+#else
19830+ pax_enter_kernel
19831+#endif
19832 movq %rsp,%rdi /* pt_regs pointer */
19833 movq ORIG_RAX(%rsp),%rsi /* get error code */
19834 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19835 call \do_sym
19836 jmp paranoid_exit /* %ebx: no swapgs flag */
19837 CFI_ENDPROC
19838-END(\sym)
19839+ENDPROC(\sym)
19840 .endm
19841
19842 zeroentry divide_error do_divide_error
19843@@ -1320,9 +1727,10 @@ gs_change:
19844 2: mfence /* workaround */
19845 SWAPGS
19846 popfq_cfi
19847+ pax_force_retaddr
19848 ret
19849 CFI_ENDPROC
19850-END(native_load_gs_index)
19851+ENDPROC(native_load_gs_index)
19852
19853 _ASM_EXTABLE(gs_change,bad_gs)
19854 .section .fixup,"ax"
19855@@ -1350,9 +1758,10 @@ ENTRY(call_softirq)
19856 CFI_DEF_CFA_REGISTER rsp
19857 CFI_ADJUST_CFA_OFFSET -8
19858 decl PER_CPU_VAR(irq_count)
19859+ pax_force_retaddr
19860 ret
19861 CFI_ENDPROC
19862-END(call_softirq)
19863+ENDPROC(call_softirq)
19864
19865 #ifdef CONFIG_XEN
19866 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19867@@ -1390,7 +1799,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19868 decl PER_CPU_VAR(irq_count)
19869 jmp error_exit
19870 CFI_ENDPROC
19871-END(xen_do_hypervisor_callback)
19872+ENDPROC(xen_do_hypervisor_callback)
19873
19874 /*
19875 * Hypervisor uses this for application faults while it executes.
19876@@ -1449,7 +1858,7 @@ ENTRY(xen_failsafe_callback)
19877 SAVE_ALL
19878 jmp error_exit
19879 CFI_ENDPROC
19880-END(xen_failsafe_callback)
19881+ENDPROC(xen_failsafe_callback)
19882
19883 apicinterrupt HYPERVISOR_CALLBACK_VECTOR \
19884 xen_hvm_callback_vector xen_evtchn_do_upcall
19885@@ -1501,18 +1910,33 @@ ENTRY(paranoid_exit)
19886 DEFAULT_FRAME
19887 DISABLE_INTERRUPTS(CLBR_NONE)
19888 TRACE_IRQS_OFF_DEBUG
19889- testl %ebx,%ebx /* swapgs needed? */
19890+ testl $1,%ebx /* swapgs needed? */
19891 jnz paranoid_restore
19892- testl $3,CS(%rsp)
19893+ testb $3,CS(%rsp)
19894 jnz paranoid_userspace
19895+#ifdef CONFIG_PAX_MEMORY_UDEREF
19896+ pax_exit_kernel
19897+ TRACE_IRQS_IRETQ 0
19898+ SWAPGS_UNSAFE_STACK
19899+ RESTORE_ALL 8
19900+ pax_force_retaddr_bts
19901+ jmp irq_return
19902+#endif
19903 paranoid_swapgs:
19904+#ifdef CONFIG_PAX_MEMORY_UDEREF
19905+ pax_exit_kernel_user
19906+#else
19907+ pax_exit_kernel
19908+#endif
19909 TRACE_IRQS_IRETQ 0
19910 SWAPGS_UNSAFE_STACK
19911 RESTORE_ALL 8
19912 jmp irq_return
19913 paranoid_restore:
19914+ pax_exit_kernel
19915 TRACE_IRQS_IRETQ_DEBUG 0
19916 RESTORE_ALL 8
19917+ pax_force_retaddr_bts
19918 jmp irq_return
19919 paranoid_userspace:
19920 GET_THREAD_INFO(%rcx)
19921@@ -1541,7 +1965,7 @@ paranoid_schedule:
19922 TRACE_IRQS_OFF
19923 jmp paranoid_userspace
19924 CFI_ENDPROC
19925-END(paranoid_exit)
19926+ENDPROC(paranoid_exit)
19927
19928 /*
19929 * Exception entry point. This expects an error code/orig_rax on the stack.
19930@@ -1568,12 +1992,13 @@ ENTRY(error_entry)
19931 movq_cfi r14, R14+8
19932 movq_cfi r15, R15+8
19933 xorl %ebx,%ebx
19934- testl $3,CS+8(%rsp)
19935+ testb $3,CS+8(%rsp)
19936 je error_kernelspace
19937 error_swapgs:
19938 SWAPGS
19939 error_sti:
19940 TRACE_IRQS_OFF
19941+ pax_force_retaddr_bts
19942 ret
19943
19944 /*
19945@@ -1600,7 +2025,7 @@ bstep_iret:
19946 movq %rcx,RIP+8(%rsp)
19947 jmp error_swapgs
19948 CFI_ENDPROC
19949-END(error_entry)
19950+ENDPROC(error_entry)
19951
19952
19953 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19954@@ -1611,7 +2036,7 @@ ENTRY(error_exit)
19955 DISABLE_INTERRUPTS(CLBR_NONE)
19956 TRACE_IRQS_OFF
19957 GET_THREAD_INFO(%rcx)
19958- testl %eax,%eax
19959+ testl $1,%eax
19960 jne retint_kernel
19961 LOCKDEP_SYS_EXIT_IRQ
19962 movl TI_flags(%rcx),%edx
19963@@ -1620,7 +2045,7 @@ ENTRY(error_exit)
19964 jnz retint_careful
19965 jmp retint_swapgs
19966 CFI_ENDPROC
19967-END(error_exit)
19968+ENDPROC(error_exit)
19969
19970 /*
19971 * Test if a given stack is an NMI stack or not.
19972@@ -1678,9 +2103,11 @@ ENTRY(nmi)
19973 * If %cs was not the kernel segment, then the NMI triggered in user
19974 * space, which means it is definitely not nested.
19975 */
19976+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19977+ je 1f
19978 cmpl $__KERNEL_CS, 16(%rsp)
19979 jne first_nmi
19980-
19981+1:
19982 /*
19983 * Check the special variable on the stack to see if NMIs are
19984 * executing.
19985@@ -1714,8 +2141,7 @@ nested_nmi:
19986
19987 1:
19988 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
19989- leaq -1*8(%rsp), %rdx
19990- movq %rdx, %rsp
19991+ subq $8, %rsp
19992 CFI_ADJUST_CFA_OFFSET 1*8
19993 leaq -10*8(%rsp), %rdx
19994 pushq_cfi $__KERNEL_DS
19995@@ -1733,6 +2159,7 @@ nested_nmi_out:
19996 CFI_RESTORE rdx
19997
19998 /* No need to check faults here */
19999+# pax_force_retaddr_bts
20000 INTERRUPT_RETURN
20001
20002 CFI_RESTORE_STATE
20003@@ -1849,6 +2276,8 @@ end_repeat_nmi:
20004 */
20005 movq %cr2, %r12
20006
20007+ pax_enter_kernel_nmi
20008+
20009 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
20010 movq %rsp,%rdi
20011 movq $-1,%rsi
20012@@ -1861,26 +2290,31 @@ end_repeat_nmi:
20013 movq %r12, %cr2
20014 1:
20015
20016- testl %ebx,%ebx /* swapgs needed? */
20017+ testl $1,%ebx /* swapgs needed? */
20018 jnz nmi_restore
20019 nmi_swapgs:
20020 SWAPGS_UNSAFE_STACK
20021 nmi_restore:
20022+ pax_exit_kernel_nmi
20023 /* Pop the extra iret frame at once */
20024 RESTORE_ALL 6*8
20025+ testb $3, 8(%rsp)
20026+ jnz 1f
20027+ pax_force_retaddr_bts
20028+1:
20029
20030 /* Clear the NMI executing stack variable */
20031 movq $0, 5*8(%rsp)
20032 jmp irq_return
20033 CFI_ENDPROC
20034-END(nmi)
20035+ENDPROC(nmi)
20036
20037 ENTRY(ignore_sysret)
20038 CFI_STARTPROC
20039 mov $-ENOSYS,%eax
20040 sysret
20041 CFI_ENDPROC
20042-END(ignore_sysret)
20043+ENDPROC(ignore_sysret)
20044
20045 /*
20046 * End of kprobes section
20047diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
20048index 42a392a..fbbd930 100644
20049--- a/arch/x86/kernel/ftrace.c
20050+++ b/arch/x86/kernel/ftrace.c
20051@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
20052 {
20053 unsigned char replaced[MCOUNT_INSN_SIZE];
20054
20055+ ip = ktla_ktva(ip);
20056+
20057 /*
20058 * Note: Due to modules and __init, code can
20059 * disappear and change, we need to protect against faulting
20060@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20061 unsigned char old[MCOUNT_INSN_SIZE], *new;
20062 int ret;
20063
20064- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
20065+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
20066 new = ftrace_call_replace(ip, (unsigned long)func);
20067
20068 /* See comment above by declaration of modifying_ftrace_code */
20069@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20070 /* Also update the regs callback function */
20071 if (!ret) {
20072 ip = (unsigned long)(&ftrace_regs_call);
20073- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
20074+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
20075 new = ftrace_call_replace(ip, (unsigned long)func);
20076 ret = ftrace_modify_code(ip, old, new);
20077 }
20078@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
20079 * kernel identity mapping to modify code.
20080 */
20081 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
20082- ip = (unsigned long)__va(__pa_symbol(ip));
20083+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
20084
20085 return probe_kernel_write((void *)ip, val, size);
20086 }
20087@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
20088 unsigned char replaced[MCOUNT_INSN_SIZE];
20089 unsigned char brk = BREAKPOINT_INSTRUCTION;
20090
20091- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
20092+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
20093 return -EFAULT;
20094
20095 /* Make sure it is what we expect it to be */
20096@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
20097 return ret;
20098
20099 fail_update:
20100- probe_kernel_write((void *)ip, &old_code[0], 1);
20101+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
20102 goto out;
20103 }
20104
20105@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
20106 {
20107 unsigned char code[MCOUNT_INSN_SIZE];
20108
20109+ ip = ktla_ktva(ip);
20110+
20111 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
20112 return -EFAULT;
20113
20114diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
20115index 55b6761..a6456fc 100644
20116--- a/arch/x86/kernel/head64.c
20117+++ b/arch/x86/kernel/head64.c
20118@@ -67,12 +67,12 @@ again:
20119 pgd = *pgd_p;
20120
20121 /*
20122- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
20123- * critical -- __PAGE_OFFSET would point us back into the dynamic
20124+ * The use of __early_va rather than __va here is critical:
20125+ * __va would point us back into the dynamic
20126 * range and we might end up looping forever...
20127 */
20128 if (pgd)
20129- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
20130+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
20131 else {
20132 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
20133 reset_early_page_tables();
20134@@ -82,13 +82,13 @@ again:
20135 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
20136 for (i = 0; i < PTRS_PER_PUD; i++)
20137 pud_p[i] = 0;
20138- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
20139+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
20140 }
20141 pud_p += pud_index(address);
20142 pud = *pud_p;
20143
20144 if (pud)
20145- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
20146+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
20147 else {
20148 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
20149 reset_early_page_tables();
20150@@ -98,7 +98,7 @@ again:
20151 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
20152 for (i = 0; i < PTRS_PER_PMD; i++)
20153 pmd_p[i] = 0;
20154- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
20155+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
20156 }
20157 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
20158 pmd_p[pmd_index(address)] = pmd;
20159@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
20160 if (console_loglevel == 10)
20161 early_printk("Kernel alive\n");
20162
20163- clear_page(init_level4_pgt);
20164 /* set init_level4_pgt kernel high mapping*/
20165 init_level4_pgt[511] = early_level4_pgt[511];
20166
20167diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
20168index 73afd11..d1670f5 100644
20169--- a/arch/x86/kernel/head_32.S
20170+++ b/arch/x86/kernel/head_32.S
20171@@ -26,6 +26,12 @@
20172 /* Physical address */
20173 #define pa(X) ((X) - __PAGE_OFFSET)
20174
20175+#ifdef CONFIG_PAX_KERNEXEC
20176+#define ta(X) (X)
20177+#else
20178+#define ta(X) ((X) - __PAGE_OFFSET)
20179+#endif
20180+
20181 /*
20182 * References to members of the new_cpu_data structure.
20183 */
20184@@ -55,11 +61,7 @@
20185 * and small than max_low_pfn, otherwise will waste some page table entries
20186 */
20187
20188-#if PTRS_PER_PMD > 1
20189-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
20190-#else
20191-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
20192-#endif
20193+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
20194
20195 /* Number of possible pages in the lowmem region */
20196 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
20197@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
20198 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20199
20200 /*
20201+ * Real beginning of normal "text" segment
20202+ */
20203+ENTRY(stext)
20204+ENTRY(_stext)
20205+
20206+/*
20207 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
20208 * %esi points to the real-mode code as a 32-bit pointer.
20209 * CS and DS must be 4 GB flat segments, but we don't depend on
20210@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20211 * can.
20212 */
20213 __HEAD
20214+
20215+#ifdef CONFIG_PAX_KERNEXEC
20216+ jmp startup_32
20217+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20218+.fill PAGE_SIZE-5,1,0xcc
20219+#endif
20220+
20221 ENTRY(startup_32)
20222 movl pa(stack_start),%ecx
20223
20224@@ -106,6 +121,59 @@ ENTRY(startup_32)
20225 2:
20226 leal -__PAGE_OFFSET(%ecx),%esp
20227
20228+#ifdef CONFIG_SMP
20229+ movl $pa(cpu_gdt_table),%edi
20230+ movl $__per_cpu_load,%eax
20231+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20232+ rorl $16,%eax
20233+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20234+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20235+ movl $__per_cpu_end - 1,%eax
20236+ subl $__per_cpu_start,%eax
20237+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20238+#endif
20239+
20240+#ifdef CONFIG_PAX_MEMORY_UDEREF
20241+ movl $NR_CPUS,%ecx
20242+ movl $pa(cpu_gdt_table),%edi
20243+1:
20244+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20245+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20246+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20247+ addl $PAGE_SIZE_asm,%edi
20248+ loop 1b
20249+#endif
20250+
20251+#ifdef CONFIG_PAX_KERNEXEC
20252+ movl $pa(boot_gdt),%edi
20253+ movl $__LOAD_PHYSICAL_ADDR,%eax
20254+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20255+ rorl $16,%eax
20256+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20257+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20258+ rorl $16,%eax
20259+
20260+ ljmp $(__BOOT_CS),$1f
20261+1:
20262+
20263+ movl $NR_CPUS,%ecx
20264+ movl $pa(cpu_gdt_table),%edi
20265+ addl $__PAGE_OFFSET,%eax
20266+1:
20267+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20268+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20269+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20270+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20271+ rorl $16,%eax
20272+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20273+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20274+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20275+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20276+ rorl $16,%eax
20277+ addl $PAGE_SIZE_asm,%edi
20278+ loop 1b
20279+#endif
20280+
20281 /*
20282 * Clear BSS first so that there are no surprises...
20283 */
20284@@ -201,8 +269,11 @@ ENTRY(startup_32)
20285 movl %eax, pa(max_pfn_mapped)
20286
20287 /* Do early initialization of the fixmap area */
20288- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20289- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20290+#ifdef CONFIG_COMPAT_VDSO
20291+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20292+#else
20293+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20294+#endif
20295 #else /* Not PAE */
20296
20297 page_pde_offset = (__PAGE_OFFSET >> 20);
20298@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20299 movl %eax, pa(max_pfn_mapped)
20300
20301 /* Do early initialization of the fixmap area */
20302- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20303- movl %eax,pa(initial_page_table+0xffc)
20304+#ifdef CONFIG_COMPAT_VDSO
20305+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20306+#else
20307+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20308+#endif
20309 #endif
20310
20311 #ifdef CONFIG_PARAVIRT
20312@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20313 cmpl $num_subarch_entries, %eax
20314 jae bad_subarch
20315
20316- movl pa(subarch_entries)(,%eax,4), %eax
20317- subl $__PAGE_OFFSET, %eax
20318- jmp *%eax
20319+ jmp *pa(subarch_entries)(,%eax,4)
20320
20321 bad_subarch:
20322 WEAK(lguest_entry)
20323@@ -261,10 +333,10 @@ WEAK(xen_entry)
20324 __INITDATA
20325
20326 subarch_entries:
20327- .long default_entry /* normal x86/PC */
20328- .long lguest_entry /* lguest hypervisor */
20329- .long xen_entry /* Xen hypervisor */
20330- .long default_entry /* Moorestown MID */
20331+ .long ta(default_entry) /* normal x86/PC */
20332+ .long ta(lguest_entry) /* lguest hypervisor */
20333+ .long ta(xen_entry) /* Xen hypervisor */
20334+ .long ta(default_entry) /* Moorestown MID */
20335 num_subarch_entries = (. - subarch_entries) / 4
20336 .previous
20337 #else
20338@@ -355,6 +427,7 @@ default_entry:
20339 movl pa(mmu_cr4_features),%eax
20340 movl %eax,%cr4
20341
20342+#ifdef CONFIG_X86_PAE
20343 testb $X86_CR4_PAE, %al # check if PAE is enabled
20344 jz enable_paging
20345
20346@@ -383,6 +456,9 @@ default_entry:
20347 /* Make changes effective */
20348 wrmsr
20349
20350+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20351+#endif
20352+
20353 enable_paging:
20354
20355 /*
20356@@ -451,14 +527,20 @@ is486:
20357 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20358 movl %eax,%ss # after changing gdt.
20359
20360- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20361+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20362 movl %eax,%ds
20363 movl %eax,%es
20364
20365 movl $(__KERNEL_PERCPU), %eax
20366 movl %eax,%fs # set this cpu's percpu
20367
20368+#ifdef CONFIG_CC_STACKPROTECTOR
20369 movl $(__KERNEL_STACK_CANARY),%eax
20370+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20371+ movl $(__USER_DS),%eax
20372+#else
20373+ xorl %eax,%eax
20374+#endif
20375 movl %eax,%gs
20376
20377 xorl %eax,%eax # Clear LDT
20378@@ -534,8 +616,11 @@ setup_once:
20379 * relocation. Manually set base address in stack canary
20380 * segment descriptor.
20381 */
20382- movl $gdt_page,%eax
20383+ movl $cpu_gdt_table,%eax
20384 movl $stack_canary,%ecx
20385+#ifdef CONFIG_SMP
20386+ addl $__per_cpu_load,%ecx
20387+#endif
20388 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20389 shrl $16, %ecx
20390 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20391@@ -566,7 +651,7 @@ ENDPROC(early_idt_handlers)
20392 /* This is global to keep gas from relaxing the jumps */
20393 ENTRY(early_idt_handler)
20394 cld
20395- cmpl $2,%ss:early_recursion_flag
20396+ cmpl $1,%ss:early_recursion_flag
20397 je hlt_loop
20398 incl %ss:early_recursion_flag
20399
20400@@ -604,8 +689,8 @@ ENTRY(early_idt_handler)
20401 pushl (20+6*4)(%esp) /* trapno */
20402 pushl $fault_msg
20403 call printk
20404-#endif
20405 call dump_stack
20406+#endif
20407 hlt_loop:
20408 hlt
20409 jmp hlt_loop
20410@@ -624,8 +709,11 @@ ENDPROC(early_idt_handler)
20411 /* This is the default interrupt "handler" :-) */
20412 ALIGN
20413 ignore_int:
20414- cld
20415 #ifdef CONFIG_PRINTK
20416+ cmpl $2,%ss:early_recursion_flag
20417+ je hlt_loop
20418+ incl %ss:early_recursion_flag
20419+ cld
20420 pushl %eax
20421 pushl %ecx
20422 pushl %edx
20423@@ -634,9 +722,6 @@ ignore_int:
20424 movl $(__KERNEL_DS),%eax
20425 movl %eax,%ds
20426 movl %eax,%es
20427- cmpl $2,early_recursion_flag
20428- je hlt_loop
20429- incl early_recursion_flag
20430 pushl 16(%esp)
20431 pushl 24(%esp)
20432 pushl 32(%esp)
20433@@ -670,29 +755,43 @@ ENTRY(setup_once_ref)
20434 /*
20435 * BSS section
20436 */
20437-__PAGE_ALIGNED_BSS
20438- .align PAGE_SIZE
20439 #ifdef CONFIG_X86_PAE
20440+.section .initial_pg_pmd,"a",@progbits
20441 initial_pg_pmd:
20442 .fill 1024*KPMDS,4,0
20443 #else
20444+.section .initial_page_table,"a",@progbits
20445 ENTRY(initial_page_table)
20446 .fill 1024,4,0
20447 #endif
20448+.section .initial_pg_fixmap,"a",@progbits
20449 initial_pg_fixmap:
20450 .fill 1024,4,0
20451+.section .empty_zero_page,"a",@progbits
20452 ENTRY(empty_zero_page)
20453 .fill 4096,1,0
20454+.section .swapper_pg_dir,"a",@progbits
20455 ENTRY(swapper_pg_dir)
20456+#ifdef CONFIG_X86_PAE
20457+ .fill 4,8,0
20458+#else
20459 .fill 1024,4,0
20460+#endif
20461+
20462+/*
20463+ * The IDT has to be page-aligned to simplify the Pentium
20464+ * F0 0F bug workaround.. We have a special link segment
20465+ * for this.
20466+ */
20467+.section .idt,"a",@progbits
20468+ENTRY(idt_table)
20469+ .fill 256,8,0
20470
20471 /*
20472 * This starts the data section.
20473 */
20474 #ifdef CONFIG_X86_PAE
20475-__PAGE_ALIGNED_DATA
20476- /* Page-aligned for the benefit of paravirt? */
20477- .align PAGE_SIZE
20478+.section .initial_page_table,"a",@progbits
20479 ENTRY(initial_page_table)
20480 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20481 # if KPMDS == 3
20482@@ -711,12 +810,20 @@ ENTRY(initial_page_table)
20483 # error "Kernel PMDs should be 1, 2 or 3"
20484 # endif
20485 .align PAGE_SIZE /* needs to be page-sized too */
20486+
20487+#ifdef CONFIG_PAX_PER_CPU_PGD
20488+ENTRY(cpu_pgd)
20489+ .rept NR_CPUS
20490+ .fill 4,8,0
20491+ .endr
20492+#endif
20493+
20494 #endif
20495
20496 .data
20497 .balign 4
20498 ENTRY(stack_start)
20499- .long init_thread_union+THREAD_SIZE
20500+ .long init_thread_union+THREAD_SIZE-8
20501
20502 __INITRODATA
20503 int_msg:
20504@@ -744,7 +851,7 @@ fault_msg:
20505 * segment size, and 32-bit linear address value:
20506 */
20507
20508- .data
20509+.section .rodata,"a",@progbits
20510 .globl boot_gdt_descr
20511 .globl idt_descr
20512
20513@@ -753,7 +860,7 @@ fault_msg:
20514 .word 0 # 32 bit align gdt_desc.address
20515 boot_gdt_descr:
20516 .word __BOOT_DS+7
20517- .long boot_gdt - __PAGE_OFFSET
20518+ .long pa(boot_gdt)
20519
20520 .word 0 # 32-bit align idt_desc.address
20521 idt_descr:
20522@@ -764,7 +871,7 @@ idt_descr:
20523 .word 0 # 32 bit align gdt_desc.address
20524 ENTRY(early_gdt_descr)
20525 .word GDT_ENTRIES*8-1
20526- .long gdt_page /* Overwritten for secondary CPUs */
20527+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20528
20529 /*
20530 * The boot_gdt must mirror the equivalent in setup.S and is
20531@@ -773,5 +880,65 @@ ENTRY(early_gdt_descr)
20532 .align L1_CACHE_BYTES
20533 ENTRY(boot_gdt)
20534 .fill GDT_ENTRY_BOOT_CS,8,0
20535- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20536- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20537+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20538+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20539+
20540+ .align PAGE_SIZE_asm
20541+ENTRY(cpu_gdt_table)
20542+ .rept NR_CPUS
20543+ .quad 0x0000000000000000 /* NULL descriptor */
20544+ .quad 0x0000000000000000 /* 0x0b reserved */
20545+ .quad 0x0000000000000000 /* 0x13 reserved */
20546+ .quad 0x0000000000000000 /* 0x1b reserved */
20547+
20548+#ifdef CONFIG_PAX_KERNEXEC
20549+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20550+#else
20551+ .quad 0x0000000000000000 /* 0x20 unused */
20552+#endif
20553+
20554+ .quad 0x0000000000000000 /* 0x28 unused */
20555+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20556+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20557+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20558+ .quad 0x0000000000000000 /* 0x4b reserved */
20559+ .quad 0x0000000000000000 /* 0x53 reserved */
20560+ .quad 0x0000000000000000 /* 0x5b reserved */
20561+
20562+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20563+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20564+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20565+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20566+
20567+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20568+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20569+
20570+ /*
20571+ * Segments used for calling PnP BIOS have byte granularity.
20572+ * The code segments and data segments have fixed 64k limits,
20573+ * the transfer segment sizes are set at run time.
20574+ */
20575+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20576+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20577+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20578+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20579+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20580+
20581+ /*
20582+ * The APM segments have byte granularity and their bases
20583+ * are set at run time. All have 64k limits.
20584+ */
20585+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20586+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20587+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20588+
20589+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20590+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20591+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20592+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20593+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20594+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20595+
20596+ /* Be sure this is zeroed to avoid false validations in Xen */
20597+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20598+ .endr
20599diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20600index 321d65e..863089b 100644
20601--- a/arch/x86/kernel/head_64.S
20602+++ b/arch/x86/kernel/head_64.S
20603@@ -20,6 +20,8 @@
20604 #include <asm/processor-flags.h>
20605 #include <asm/percpu.h>
20606 #include <asm/nops.h>
20607+#include <asm/cpufeature.h>
20608+#include <asm/alternative-asm.h>
20609
20610 #ifdef CONFIG_PARAVIRT
20611 #include <asm/asm-offsets.h>
20612@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20613 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20614 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20615 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20616+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20617+L3_VMALLOC_START = pud_index(VMALLOC_START)
20618+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20619+L3_VMALLOC_END = pud_index(VMALLOC_END)
20620+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20621+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20622
20623 .text
20624 __HEAD
20625@@ -89,11 +97,23 @@ startup_64:
20626 * Fixup the physical addresses in the page table
20627 */
20628 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
20629+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20630+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20631+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20632+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20633+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20634
20635- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20636- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20637+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
20638+#ifndef CONFIG_XEN
20639+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
20640+#endif
20641
20642- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20643+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20644+
20645+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20646+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
20647+
20648+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20649
20650 /*
20651 * Set up the identity mapping for the switchover. These
20652@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
20653 movq $(init_level4_pgt - __START_KERNEL_map), %rax
20654 1:
20655
20656- /* Enable PAE mode and PGE */
20657- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
20658+ /* Enable PAE mode and PSE/PGE */
20659+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
20660 movq %rcx, %cr4
20661
20662 /* Setup early boot stage 4 level pagetables. */
20663@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
20664 movl $MSR_EFER, %ecx
20665 rdmsr
20666 btsl $_EFER_SCE, %eax /* Enable System Call */
20667- btl $20,%edi /* No Execute supported? */
20668+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20669 jnc 1f
20670 btsl $_EFER_NX, %eax
20671 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
20672+ leaq init_level4_pgt(%rip), %rdi
20673+#ifndef CONFIG_EFI
20674+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20675+#endif
20676+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20677+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20678+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20679+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20680 1: wrmsr /* Make changes effective */
20681
20682 /* Setup cr0 */
20683@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
20684 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
20685 * address given in m16:64.
20686 */
20687+ pax_set_fptr_mask
20688 movq initial_code(%rip),%rax
20689 pushq $0 # fake return address to stop unwinder
20690 pushq $__KERNEL_CS # set correct cs
20691@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
20692 call dump_stack
20693 #ifdef CONFIG_KALLSYMS
20694 leaq early_idt_ripmsg(%rip),%rdi
20695- movq 40(%rsp),%rsi # %rip again
20696+ movq 88(%rsp),%rsi # %rip again
20697 call __print_symbol
20698 #endif
20699 #endif /* EARLY_PRINTK */
20700@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
20701 early_recursion_flag:
20702 .long 0
20703
20704+ .section .rodata,"a",@progbits
20705 #ifdef CONFIG_EARLY_PRINTK
20706 early_idt_msg:
20707 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20708@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
20709 NEXT_PAGE(early_dynamic_pgts)
20710 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
20711
20712- .data
20713+ .section .rodata,"a",@progbits
20714
20715-#ifndef CONFIG_XEN
20716 NEXT_PAGE(init_level4_pgt)
20717- .fill 512,8,0
20718-#else
20719-NEXT_PAGE(init_level4_pgt)
20720- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20721 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20722 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20723+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20724+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20725+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20726+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20727+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20728+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20729 .org init_level4_pgt + L4_START_KERNEL*8, 0
20730 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20731 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20732
20733+#ifdef CONFIG_PAX_PER_CPU_PGD
20734+NEXT_PAGE(cpu_pgd)
20735+ .rept NR_CPUS
20736+ .fill 512,8,0
20737+ .endr
20738+#endif
20739+
20740 NEXT_PAGE(level3_ident_pgt)
20741 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20742+#ifdef CONFIG_XEN
20743 .fill 511, 8, 0
20744+#else
20745+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20746+ .fill 510,8,0
20747+#endif
20748+
20749+NEXT_PAGE(level3_vmalloc_start_pgt)
20750+ .fill 512,8,0
20751+
20752+NEXT_PAGE(level3_vmalloc_end_pgt)
20753+ .fill 512,8,0
20754+
20755+NEXT_PAGE(level3_vmemmap_pgt)
20756+ .fill L3_VMEMMAP_START,8,0
20757+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20758+
20759 NEXT_PAGE(level2_ident_pgt)
20760- /* Since I easily can, map the first 1G.
20761+ /* Since I easily can, map the first 2G.
20762 * Don't set NX because code runs from these pages.
20763 */
20764- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20765-#endif
20766+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20767
20768 NEXT_PAGE(level3_kernel_pgt)
20769 .fill L3_START_KERNEL,8,0
20770@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
20771 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20772 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20773
20774+NEXT_PAGE(level2_vmemmap_pgt)
20775+ .fill 512,8,0
20776+
20777 NEXT_PAGE(level2_kernel_pgt)
20778 /*
20779 * 512 MB kernel mapping. We spend a full page on this pagetable
20780@@ -488,39 +544,64 @@ NEXT_PAGE(level2_kernel_pgt)
20781 KERNEL_IMAGE_SIZE/PMD_SIZE)
20782
20783 NEXT_PAGE(level2_fixmap_pgt)
20784- .fill 506,8,0
20785- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20786- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20787- .fill 5,8,0
20788+ .fill 507,8,0
20789+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20790+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20791+ .fill 4,8,0
20792
20793-NEXT_PAGE(level1_fixmap_pgt)
20794+NEXT_PAGE(level1_vsyscall_pgt)
20795 .fill 512,8,0
20796
20797 #undef PMDS
20798
20799- .data
20800+ .align PAGE_SIZE
20801+ENTRY(cpu_gdt_table)
20802+ .rept NR_CPUS
20803+ .quad 0x0000000000000000 /* NULL descriptor */
20804+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20805+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20806+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20807+ .quad 0x00cffb000000ffff /* __USER32_CS */
20808+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20809+ .quad 0x00affb000000ffff /* __USER_CS */
20810+
20811+#ifdef CONFIG_PAX_KERNEXEC
20812+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20813+#else
20814+ .quad 0x0 /* unused */
20815+#endif
20816+
20817+ .quad 0,0 /* TSS */
20818+ .quad 0,0 /* LDT */
20819+ .quad 0,0,0 /* three TLS descriptors */
20820+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20821+ /* asm/segment.h:GDT_ENTRIES must match this */
20822+
20823+ /* zero the remaining page */
20824+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20825+ .endr
20826+
20827 .align 16
20828 .globl early_gdt_descr
20829 early_gdt_descr:
20830 .word GDT_ENTRIES*8-1
20831 early_gdt_descr_base:
20832- .quad INIT_PER_CPU_VAR(gdt_page)
20833+ .quad cpu_gdt_table
20834
20835 ENTRY(phys_base)
20836 /* This must match the first entry in level2_kernel_pgt */
20837 .quad 0x0000000000000000
20838
20839 #include "../../x86/xen/xen-head.S"
20840-
20841- .section .bss, "aw", @nobits
20842- .align L1_CACHE_BYTES
20843-ENTRY(idt_table)
20844- .skip IDT_ENTRIES * 16
20845
20846- .align L1_CACHE_BYTES
20847-ENTRY(nmi_idt_table)
20848- .skip IDT_ENTRIES * 16
20849-
20850- __PAGE_ALIGNED_BSS
20851+ .section .rodata,"a",@progbits
20852 NEXT_PAGE(empty_zero_page)
20853 .skip PAGE_SIZE
20854+
20855+ .align L1_CACHE_BYTES
20856+ENTRY(idt_table)
20857+ .fill 512,8,0
20858+
20859+ .align L1_CACHE_BYTES
20860+ENTRY(nmi_idt_table)
20861+ .fill 512,8,0
20862diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20863index 0fa6912..37fce70 100644
20864--- a/arch/x86/kernel/i386_ksyms_32.c
20865+++ b/arch/x86/kernel/i386_ksyms_32.c
20866@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20867 EXPORT_SYMBOL(cmpxchg8b_emu);
20868 #endif
20869
20870+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20871+
20872 /* Networking helper routines. */
20873 EXPORT_SYMBOL(csum_partial_copy_generic);
20874+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20875+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20876
20877 EXPORT_SYMBOL(__get_user_1);
20878 EXPORT_SYMBOL(__get_user_2);
20879@@ -37,3 +41,7 @@ EXPORT_SYMBOL(strstr);
20880
20881 EXPORT_SYMBOL(csum_partial);
20882 EXPORT_SYMBOL(empty_zero_page);
20883+
20884+#ifdef CONFIG_PAX_KERNEXEC
20885+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20886+#endif
20887diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20888index cb33909..1163b40 100644
20889--- a/arch/x86/kernel/i387.c
20890+++ b/arch/x86/kernel/i387.c
20891@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20892 static inline bool interrupted_user_mode(void)
20893 {
20894 struct pt_regs *regs = get_irq_regs();
20895- return regs && user_mode_vm(regs);
20896+ return regs && user_mode(regs);
20897 }
20898
20899 /*
20900diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20901index 9a5c460..84868423 100644
20902--- a/arch/x86/kernel/i8259.c
20903+++ b/arch/x86/kernel/i8259.c
20904@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
20905 static void make_8259A_irq(unsigned int irq)
20906 {
20907 disable_irq_nosync(irq);
20908- io_apic_irqs &= ~(1<<irq);
20909+ io_apic_irqs &= ~(1UL<<irq);
20910 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
20911 i8259A_chip.name);
20912 enable_irq(irq);
20913@@ -209,7 +209,7 @@ spurious_8259A_irq:
20914 "spurious 8259A interrupt: IRQ%d.\n", irq);
20915 spurious_irq_mask |= irqmask;
20916 }
20917- atomic_inc(&irq_err_count);
20918+ atomic_inc_unchecked(&irq_err_count);
20919 /*
20920 * Theoretically we do not have to handle this IRQ,
20921 * but in Linux this does not cause problems and is
20922@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20923 /* (slave's support for AEOI in flat mode is to be investigated) */
20924 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20925
20926+ pax_open_kernel();
20927 if (auto_eoi)
20928 /*
20929 * In AEOI mode we just have to mask the interrupt
20930 * when acking.
20931 */
20932- i8259A_chip.irq_mask_ack = disable_8259A_irq;
20933+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20934 else
20935- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20936+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20937+ pax_close_kernel();
20938
20939 udelay(100); /* wait for 8259A to initialize */
20940
20941diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20942index a979b5b..1d6db75 100644
20943--- a/arch/x86/kernel/io_delay.c
20944+++ b/arch/x86/kernel/io_delay.c
20945@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20946 * Quirk table for systems that misbehave (lock up, etc.) if port
20947 * 0x80 is used:
20948 */
20949-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20950+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20951 {
20952 .callback = dmi_io_delay_0xed_port,
20953 .ident = "Compaq Presario V6000",
20954diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20955index 4ddaf66..6292f4e 100644
20956--- a/arch/x86/kernel/ioport.c
20957+++ b/arch/x86/kernel/ioport.c
20958@@ -6,6 +6,7 @@
20959 #include <linux/sched.h>
20960 #include <linux/kernel.h>
20961 #include <linux/capability.h>
20962+#include <linux/security.h>
20963 #include <linux/errno.h>
20964 #include <linux/types.h>
20965 #include <linux/ioport.h>
20966@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20967
20968 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20969 return -EINVAL;
20970+#ifdef CONFIG_GRKERNSEC_IO
20971+ if (turn_on && grsec_disable_privio) {
20972+ gr_handle_ioperm();
20973+ return -EPERM;
20974+ }
20975+#endif
20976 if (turn_on && !capable(CAP_SYS_RAWIO))
20977 return -EPERM;
20978
20979@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20980 * because the ->io_bitmap_max value must match the bitmap
20981 * contents:
20982 */
20983- tss = &per_cpu(init_tss, get_cpu());
20984+ tss = init_tss + get_cpu();
20985
20986 if (turn_on)
20987 bitmap_clear(t->io_bitmap_ptr, from, num);
20988@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
20989 return -EINVAL;
20990 /* Trying to gain more privileges? */
20991 if (level > old) {
20992+#ifdef CONFIG_GRKERNSEC_IO
20993+ if (grsec_disable_privio) {
20994+ gr_handle_iopl();
20995+ return -EPERM;
20996+ }
20997+#endif
20998 if (!capable(CAP_SYS_RAWIO))
20999 return -EPERM;
21000 }
21001diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
21002index ac0631d..ff7cb62 100644
21003--- a/arch/x86/kernel/irq.c
21004+++ b/arch/x86/kernel/irq.c
21005@@ -18,7 +18,7 @@
21006 #include <asm/mce.h>
21007 #include <asm/hw_irq.h>
21008
21009-atomic_t irq_err_count;
21010+atomic_unchecked_t irq_err_count;
21011
21012 /* Function pointer for generic interrupt vector handling */
21013 void (*x86_platform_ipi_callback)(void) = NULL;
21014@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
21015 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
21016 seq_printf(p, " Machine check polls\n");
21017 #endif
21018- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
21019+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
21020 #if defined(CONFIG_X86_IO_APIC)
21021- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
21022+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
21023 #endif
21024 return 0;
21025 }
21026@@ -164,7 +164,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
21027
21028 u64 arch_irq_stat(void)
21029 {
21030- u64 sum = atomic_read(&irq_err_count);
21031+ u64 sum = atomic_read_unchecked(&irq_err_count);
21032 return sum;
21033 }
21034
21035diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
21036index 344faf8..355f60d 100644
21037--- a/arch/x86/kernel/irq_32.c
21038+++ b/arch/x86/kernel/irq_32.c
21039@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
21040 __asm__ __volatile__("andl %%esp,%0" :
21041 "=r" (sp) : "0" (THREAD_SIZE - 1));
21042
21043- return sp < (sizeof(struct thread_info) + STACK_WARN);
21044+ return sp < STACK_WARN;
21045 }
21046
21047 static void print_stack_overflow(void)
21048@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
21049 * per-CPU IRQ handling contexts (thread information and stack)
21050 */
21051 union irq_ctx {
21052- struct thread_info tinfo;
21053- u32 stack[THREAD_SIZE/sizeof(u32)];
21054+ unsigned long previous_esp;
21055+ u32 stack[THREAD_SIZE/sizeof(u32)];
21056 } __attribute__((aligned(THREAD_SIZE)));
21057
21058 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
21059@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
21060 static inline int
21061 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21062 {
21063- union irq_ctx *curctx, *irqctx;
21064+ union irq_ctx *irqctx;
21065 u32 *isp, arg1, arg2;
21066
21067- curctx = (union irq_ctx *) current_thread_info();
21068 irqctx = __this_cpu_read(hardirq_ctx);
21069
21070 /*
21071@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21072 * handler) we can't do that and just have to keep using the
21073 * current stack (which is the irq stack already after all)
21074 */
21075- if (unlikely(curctx == irqctx))
21076+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
21077 return 0;
21078
21079 /* build the stack frame on the IRQ stack */
21080- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21081- irqctx->tinfo.task = curctx->tinfo.task;
21082- irqctx->tinfo.previous_esp = current_stack_pointer;
21083+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21084+ irqctx->previous_esp = current_stack_pointer;
21085
21086- /* Copy the preempt_count so that the [soft]irq checks work. */
21087- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
21088+#ifdef CONFIG_PAX_MEMORY_UDEREF
21089+ __set_fs(MAKE_MM_SEG(0));
21090+#endif
21091
21092 if (unlikely(overflow))
21093 call_on_stack(print_stack_overflow, isp);
21094@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21095 : "0" (irq), "1" (desc), "2" (isp),
21096 "D" (desc->handle_irq)
21097 : "memory", "cc", "ecx");
21098+
21099+#ifdef CONFIG_PAX_MEMORY_UDEREF
21100+ __set_fs(current_thread_info()->addr_limit);
21101+#endif
21102+
21103 return 1;
21104 }
21105
21106@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21107 */
21108 void __cpuinit irq_ctx_init(int cpu)
21109 {
21110- union irq_ctx *irqctx;
21111-
21112 if (per_cpu(hardirq_ctx, cpu))
21113 return;
21114
21115- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21116- THREADINFO_GFP,
21117- THREAD_SIZE_ORDER));
21118- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21119- irqctx->tinfo.cpu = cpu;
21120- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
21121- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21122-
21123- per_cpu(hardirq_ctx, cpu) = irqctx;
21124-
21125- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21126- THREADINFO_GFP,
21127- THREAD_SIZE_ORDER));
21128- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21129- irqctx->tinfo.cpu = cpu;
21130- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21131-
21132- per_cpu(softirq_ctx, cpu) = irqctx;
21133+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21134+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21135+
21136+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21137+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21138
21139 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21140 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21141@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
21142 asmlinkage void do_softirq(void)
21143 {
21144 unsigned long flags;
21145- struct thread_info *curctx;
21146 union irq_ctx *irqctx;
21147 u32 *isp;
21148
21149@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
21150 local_irq_save(flags);
21151
21152 if (local_softirq_pending()) {
21153- curctx = current_thread_info();
21154 irqctx = __this_cpu_read(softirq_ctx);
21155- irqctx->tinfo.task = curctx->task;
21156- irqctx->tinfo.previous_esp = current_stack_pointer;
21157+ irqctx->previous_esp = current_stack_pointer;
21158
21159 /* build the stack frame on the softirq stack */
21160- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21161+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21162+
21163+#ifdef CONFIG_PAX_MEMORY_UDEREF
21164+ __set_fs(MAKE_MM_SEG(0));
21165+#endif
21166
21167 call_on_stack(__do_softirq, isp);
21168+
21169+#ifdef CONFIG_PAX_MEMORY_UDEREF
21170+ __set_fs(current_thread_info()->addr_limit);
21171+#endif
21172+
21173 /*
21174 * Shouldn't happen, we returned above if in_interrupt():
21175 */
21176@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21177 if (unlikely(!desc))
21178 return false;
21179
21180- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21181+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21182 if (unlikely(overflow))
21183 print_stack_overflow();
21184 desc->handle_irq(irq, desc);
21185diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21186index d04d3ec..ea4b374 100644
21187--- a/arch/x86/kernel/irq_64.c
21188+++ b/arch/x86/kernel/irq_64.c
21189@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21190 u64 estack_top, estack_bottom;
21191 u64 curbase = (u64)task_stack_page(current);
21192
21193- if (user_mode_vm(regs))
21194+ if (user_mode(regs))
21195 return;
21196
21197 if (regs->sp >= curbase + sizeof(struct thread_info) +
21198diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21199index dc1404b..bbc43e7 100644
21200--- a/arch/x86/kernel/kdebugfs.c
21201+++ b/arch/x86/kernel/kdebugfs.c
21202@@ -27,7 +27,7 @@ struct setup_data_node {
21203 u32 len;
21204 };
21205
21206-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21207+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21208 size_t count, loff_t *ppos)
21209 {
21210 struct setup_data_node *node = file->private_data;
21211diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21212index 836f832..a8bda67 100644
21213--- a/arch/x86/kernel/kgdb.c
21214+++ b/arch/x86/kernel/kgdb.c
21215@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21216 #ifdef CONFIG_X86_32
21217 switch (regno) {
21218 case GDB_SS:
21219- if (!user_mode_vm(regs))
21220+ if (!user_mode(regs))
21221 *(unsigned long *)mem = __KERNEL_DS;
21222 break;
21223 case GDB_SP:
21224- if (!user_mode_vm(regs))
21225+ if (!user_mode(regs))
21226 *(unsigned long *)mem = kernel_stack_pointer(regs);
21227 break;
21228 case GDB_GS:
21229@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21230 bp->attr.bp_addr = breakinfo[breakno].addr;
21231 bp->attr.bp_len = breakinfo[breakno].len;
21232 bp->attr.bp_type = breakinfo[breakno].type;
21233- info->address = breakinfo[breakno].addr;
21234+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21235+ info->address = ktla_ktva(breakinfo[breakno].addr);
21236+ else
21237+ info->address = breakinfo[breakno].addr;
21238 info->len = breakinfo[breakno].len;
21239 info->type = breakinfo[breakno].type;
21240 val = arch_install_hw_breakpoint(bp);
21241@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21242 case 'k':
21243 /* clear the trace bit */
21244 linux_regs->flags &= ~X86_EFLAGS_TF;
21245- atomic_set(&kgdb_cpu_doing_single_step, -1);
21246+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21247
21248 /* set the trace bit if we're stepping */
21249 if (remcomInBuffer[0] == 's') {
21250 linux_regs->flags |= X86_EFLAGS_TF;
21251- atomic_set(&kgdb_cpu_doing_single_step,
21252+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21253 raw_smp_processor_id());
21254 }
21255
21256@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21257
21258 switch (cmd) {
21259 case DIE_DEBUG:
21260- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21261+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21262 if (user_mode(regs))
21263 return single_step_cont(regs, args);
21264 break;
21265@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21266 #endif /* CONFIG_DEBUG_RODATA */
21267
21268 bpt->type = BP_BREAKPOINT;
21269- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21270+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21271 BREAK_INSTR_SIZE);
21272 if (err)
21273 return err;
21274- err = probe_kernel_write((char *)bpt->bpt_addr,
21275+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21276 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21277 #ifdef CONFIG_DEBUG_RODATA
21278 if (!err)
21279@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21280 return -EBUSY;
21281 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21282 BREAK_INSTR_SIZE);
21283- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21284+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21285 if (err)
21286 return err;
21287 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21288@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21289 if (mutex_is_locked(&text_mutex))
21290 goto knl_write;
21291 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21292- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21293+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21294 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21295 goto knl_write;
21296 return err;
21297 knl_write:
21298 #endif /* CONFIG_DEBUG_RODATA */
21299- return probe_kernel_write((char *)bpt->bpt_addr,
21300+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21301 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21302 }
21303
21304diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
21305index 211bce4..6e2580a 100644
21306--- a/arch/x86/kernel/kprobes/core.c
21307+++ b/arch/x86/kernel/kprobes/core.c
21308@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21309 s32 raddr;
21310 } __packed *insn;
21311
21312- insn = (struct __arch_relative_insn *)from;
21313+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21314+
21315+ pax_open_kernel();
21316 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21317 insn->op = op;
21318+ pax_close_kernel();
21319 }
21320
21321 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21322@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21323 kprobe_opcode_t opcode;
21324 kprobe_opcode_t *orig_opcodes = opcodes;
21325
21326- if (search_exception_tables((unsigned long)opcodes))
21327+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21328 return 0; /* Page fault may occur on this address. */
21329
21330 retry:
21331@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21332 * for the first byte, we can recover the original instruction
21333 * from it and kp->opcode.
21334 */
21335- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21336+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21337 buf[0] = kp->opcode;
21338- return (unsigned long)buf;
21339+ return ktva_ktla((unsigned long)buf);
21340 }
21341
21342 /*
21343@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21344 /* Another subsystem puts a breakpoint, failed to recover */
21345 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21346 return 0;
21347+ pax_open_kernel();
21348 memcpy(dest, insn.kaddr, insn.length);
21349+ pax_close_kernel();
21350
21351 #ifdef CONFIG_X86_64
21352 if (insn_rip_relative(&insn)) {
21353@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21354 return 0;
21355 }
21356 disp = (u8 *) dest + insn_offset_displacement(&insn);
21357+ pax_open_kernel();
21358 *(s32 *) disp = (s32) newdisp;
21359+ pax_close_kernel();
21360 }
21361 #endif
21362 return insn.length;
21363@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21364 * nor set current_kprobe, because it doesn't use single
21365 * stepping.
21366 */
21367- regs->ip = (unsigned long)p->ainsn.insn;
21368+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21369 preempt_enable_no_resched();
21370 return;
21371 }
21372@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21373 regs->flags &= ~X86_EFLAGS_IF;
21374 /* single step inline if the instruction is an int3 */
21375 if (p->opcode == BREAKPOINT_INSTRUCTION)
21376- regs->ip = (unsigned long)p->addr;
21377+ regs->ip = ktla_ktva((unsigned long)p->addr);
21378 else
21379- regs->ip = (unsigned long)p->ainsn.insn;
21380+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21381 }
21382
21383 /*
21384@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21385 setup_singlestep(p, regs, kcb, 0);
21386 return 1;
21387 }
21388- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21389+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21390 /*
21391 * The breakpoint instruction was removed right
21392 * after we hit it. Another cpu has removed
21393@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21394 " movq %rax, 152(%rsp)\n"
21395 RESTORE_REGS_STRING
21396 " popfq\n"
21397+#ifdef KERNEXEC_PLUGIN
21398+ " btsq $63,(%rsp)\n"
21399+#endif
21400 #else
21401 " pushf\n"
21402 SAVE_REGS_STRING
21403@@ -779,7 +789,7 @@ static void __kprobes
21404 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21405 {
21406 unsigned long *tos = stack_addr(regs);
21407- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21408+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21409 unsigned long orig_ip = (unsigned long)p->addr;
21410 kprobe_opcode_t *insn = p->ainsn.insn;
21411
21412@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21413 struct die_args *args = data;
21414 int ret = NOTIFY_DONE;
21415
21416- if (args->regs && user_mode_vm(args->regs))
21417+ if (args->regs && user_mode(args->regs))
21418 return ret;
21419
21420 switch (val) {
21421diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
21422index 76dc6f0..66bdfc3 100644
21423--- a/arch/x86/kernel/kprobes/opt.c
21424+++ b/arch/x86/kernel/kprobes/opt.c
21425@@ -79,6 +79,7 @@ found:
21426 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
21427 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
21428 {
21429+ pax_open_kernel();
21430 #ifdef CONFIG_X86_64
21431 *addr++ = 0x48;
21432 *addr++ = 0xbf;
21433@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
21434 *addr++ = 0xb8;
21435 #endif
21436 *(unsigned long *)addr = val;
21437+ pax_close_kernel();
21438 }
21439
21440 static void __used __kprobes kprobes_optinsn_template_holder(void)
21441@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21442 * Verify if the address gap is in 2GB range, because this uses
21443 * a relative jump.
21444 */
21445- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21446+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21447 if (abs(rel) > 0x7fffffff)
21448 return -ERANGE;
21449
21450@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21451 op->optinsn.size = ret;
21452
21453 /* Copy arch-dep-instance from template */
21454- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21455+ pax_open_kernel();
21456+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21457+ pax_close_kernel();
21458
21459 /* Set probe information */
21460 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21461
21462 /* Set probe function call */
21463- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21464+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21465
21466 /* Set returning jmp instruction at the tail of out-of-line buffer */
21467- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21468+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21469 (u8 *)op->kp.addr + op->optinsn.size);
21470
21471 flush_icache_range((unsigned long) buf,
21472@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21473 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21474
21475 /* Backup instructions which will be replaced by jump address */
21476- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21477+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21478 RELATIVE_ADDR_SIZE);
21479
21480 insn_buf[0] = RELATIVEJUMP_OPCODE;
21481@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21482 /* This kprobe is really able to run optimized path. */
21483 op = container_of(p, struct optimized_kprobe, kp);
21484 /* Detour through copied instructions */
21485- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21486+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21487 if (!reenter)
21488 reset_current_kprobe();
21489 preempt_enable_no_resched();
21490diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21491index cd6d9a5..16245a4 100644
21492--- a/arch/x86/kernel/kvm.c
21493+++ b/arch/x86/kernel/kvm.c
21494@@ -455,7 +455,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21495 return NOTIFY_OK;
21496 }
21497
21498-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21499+static struct notifier_block kvm_cpu_notifier = {
21500 .notifier_call = kvm_cpu_notify,
21501 };
21502 #endif
21503diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21504index ebc9873..1b9724b 100644
21505--- a/arch/x86/kernel/ldt.c
21506+++ b/arch/x86/kernel/ldt.c
21507@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21508 if (reload) {
21509 #ifdef CONFIG_SMP
21510 preempt_disable();
21511- load_LDT(pc);
21512+ load_LDT_nolock(pc);
21513 if (!cpumask_equal(mm_cpumask(current->mm),
21514 cpumask_of(smp_processor_id())))
21515 smp_call_function(flush_ldt, current->mm, 1);
21516 preempt_enable();
21517 #else
21518- load_LDT(pc);
21519+ load_LDT_nolock(pc);
21520 #endif
21521 }
21522 if (oldsize) {
21523@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21524 return err;
21525
21526 for (i = 0; i < old->size; i++)
21527- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21528+ write_ldt_entry(new->ldt, i, old->ldt + i);
21529 return 0;
21530 }
21531
21532@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21533 retval = copy_ldt(&mm->context, &old_mm->context);
21534 mutex_unlock(&old_mm->context.lock);
21535 }
21536+
21537+ if (tsk == current) {
21538+ mm->context.vdso = 0;
21539+
21540+#ifdef CONFIG_X86_32
21541+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21542+ mm->context.user_cs_base = 0UL;
21543+ mm->context.user_cs_limit = ~0UL;
21544+
21545+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21546+ cpus_clear(mm->context.cpu_user_cs_mask);
21547+#endif
21548+
21549+#endif
21550+#endif
21551+
21552+ }
21553+
21554 return retval;
21555 }
21556
21557@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21558 }
21559 }
21560
21561+#ifdef CONFIG_PAX_SEGMEXEC
21562+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21563+ error = -EINVAL;
21564+ goto out_unlock;
21565+ }
21566+#endif
21567+
21568 fill_ldt(&ldt, &ldt_info);
21569 if (oldmode)
21570 ldt.avl = 0;
21571diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21572index 5b19e4d..6476a76 100644
21573--- a/arch/x86/kernel/machine_kexec_32.c
21574+++ b/arch/x86/kernel/machine_kexec_32.c
21575@@ -26,7 +26,7 @@
21576 #include <asm/cacheflush.h>
21577 #include <asm/debugreg.h>
21578
21579-static void set_idt(void *newidt, __u16 limit)
21580+static void set_idt(struct desc_struct *newidt, __u16 limit)
21581 {
21582 struct desc_ptr curidt;
21583
21584@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21585 }
21586
21587
21588-static void set_gdt(void *newgdt, __u16 limit)
21589+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21590 {
21591 struct desc_ptr curgdt;
21592
21593@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21594 }
21595
21596 control_page = page_address(image->control_code_page);
21597- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21598+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21599
21600 relocate_kernel_ptr = control_page;
21601 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21602diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21603index 22db92b..d546bec 100644
21604--- a/arch/x86/kernel/microcode_core.c
21605+++ b/arch/x86/kernel/microcode_core.c
21606@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21607 return NOTIFY_OK;
21608 }
21609
21610-static struct notifier_block __refdata mc_cpu_notifier = {
21611+static struct notifier_block mc_cpu_notifier = {
21612 .notifier_call = mc_cpu_callback,
21613 };
21614
21615diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21616index 5fb2ceb..3ae90bb 100644
21617--- a/arch/x86/kernel/microcode_intel.c
21618+++ b/arch/x86/kernel/microcode_intel.c
21619@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21620
21621 static int get_ucode_user(void *to, const void *from, size_t n)
21622 {
21623- return copy_from_user(to, from, n);
21624+ return copy_from_user(to, (const void __force_user *)from, n);
21625 }
21626
21627 static enum ucode_state
21628 request_microcode_user(int cpu, const void __user *buf, size_t size)
21629 {
21630- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21631+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21632 }
21633
21634 static void microcode_fini_cpu(int cpu)
21635diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21636index 216a4d7..228255a 100644
21637--- a/arch/x86/kernel/module.c
21638+++ b/arch/x86/kernel/module.c
21639@@ -43,15 +43,60 @@ do { \
21640 } while (0)
21641 #endif
21642
21643-void *module_alloc(unsigned long size)
21644+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21645 {
21646- if (PAGE_ALIGN(size) > MODULES_LEN)
21647+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21648 return NULL;
21649 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21650- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21651+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21652 -1, __builtin_return_address(0));
21653 }
21654
21655+void *module_alloc(unsigned long size)
21656+{
21657+
21658+#ifdef CONFIG_PAX_KERNEXEC
21659+ return __module_alloc(size, PAGE_KERNEL);
21660+#else
21661+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21662+#endif
21663+
21664+}
21665+
21666+#ifdef CONFIG_PAX_KERNEXEC
21667+#ifdef CONFIG_X86_32
21668+void *module_alloc_exec(unsigned long size)
21669+{
21670+ struct vm_struct *area;
21671+
21672+ if (size == 0)
21673+ return NULL;
21674+
21675+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21676+ return area ? area->addr : NULL;
21677+}
21678+EXPORT_SYMBOL(module_alloc_exec);
21679+
21680+void module_free_exec(struct module *mod, void *module_region)
21681+{
21682+ vunmap(module_region);
21683+}
21684+EXPORT_SYMBOL(module_free_exec);
21685+#else
21686+void module_free_exec(struct module *mod, void *module_region)
21687+{
21688+ module_free(mod, module_region);
21689+}
21690+EXPORT_SYMBOL(module_free_exec);
21691+
21692+void *module_alloc_exec(unsigned long size)
21693+{
21694+ return __module_alloc(size, PAGE_KERNEL_RX);
21695+}
21696+EXPORT_SYMBOL(module_alloc_exec);
21697+#endif
21698+#endif
21699+
21700 #ifdef CONFIG_X86_32
21701 int apply_relocate(Elf32_Shdr *sechdrs,
21702 const char *strtab,
21703@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21704 unsigned int i;
21705 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21706 Elf32_Sym *sym;
21707- uint32_t *location;
21708+ uint32_t *plocation, location;
21709
21710 DEBUGP("Applying relocate section %u to %u\n",
21711 relsec, sechdrs[relsec].sh_info);
21712 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21713 /* This is where to make the change */
21714- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21715- + rel[i].r_offset;
21716+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21717+ location = (uint32_t)plocation;
21718+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21719+ plocation = ktla_ktva((void *)plocation);
21720 /* This is the symbol it is referring to. Note that all
21721 undefined symbols have been resolved. */
21722 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21723@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21724 switch (ELF32_R_TYPE(rel[i].r_info)) {
21725 case R_386_32:
21726 /* We add the value into the location given */
21727- *location += sym->st_value;
21728+ pax_open_kernel();
21729+ *plocation += sym->st_value;
21730+ pax_close_kernel();
21731 break;
21732 case R_386_PC32:
21733 /* Add the value, subtract its position */
21734- *location += sym->st_value - (uint32_t)location;
21735+ pax_open_kernel();
21736+ *plocation += sym->st_value - location;
21737+ pax_close_kernel();
21738 break;
21739 default:
21740 pr_err("%s: Unknown relocation: %u\n",
21741@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21742 case R_X86_64_NONE:
21743 break;
21744 case R_X86_64_64:
21745+ pax_open_kernel();
21746 *(u64 *)loc = val;
21747+ pax_close_kernel();
21748 break;
21749 case R_X86_64_32:
21750+ pax_open_kernel();
21751 *(u32 *)loc = val;
21752+ pax_close_kernel();
21753 if (val != *(u32 *)loc)
21754 goto overflow;
21755 break;
21756 case R_X86_64_32S:
21757+ pax_open_kernel();
21758 *(s32 *)loc = val;
21759+ pax_close_kernel();
21760 if ((s64)val != *(s32 *)loc)
21761 goto overflow;
21762 break;
21763 case R_X86_64_PC32:
21764 val -= (u64)loc;
21765+ pax_open_kernel();
21766 *(u32 *)loc = val;
21767+ pax_close_kernel();
21768+
21769 #if 0
21770 if ((s64)val != *(s32 *)loc)
21771 goto overflow;
21772diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21773index ce13049..e2e9c3c 100644
21774--- a/arch/x86/kernel/msr.c
21775+++ b/arch/x86/kernel/msr.c
21776@@ -233,7 +233,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21777 return notifier_from_errno(err);
21778 }
21779
21780-static struct notifier_block __refdata msr_class_cpu_notifier = {
21781+static struct notifier_block msr_class_cpu_notifier = {
21782 .notifier_call = msr_class_cpu_callback,
21783 };
21784
21785diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21786index 6030805..2d33f21 100644
21787--- a/arch/x86/kernel/nmi.c
21788+++ b/arch/x86/kernel/nmi.c
21789@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21790 return handled;
21791 }
21792
21793-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21794+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21795 {
21796 struct nmi_desc *desc = nmi_to_desc(type);
21797 unsigned long flags;
21798@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21799 * event confuses some handlers (kdump uses this flag)
21800 */
21801 if (action->flags & NMI_FLAG_FIRST)
21802- list_add_rcu(&action->list, &desc->head);
21803+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21804 else
21805- list_add_tail_rcu(&action->list, &desc->head);
21806+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21807
21808 spin_unlock_irqrestore(&desc->lock, flags);
21809 return 0;
21810@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21811 if (!strcmp(n->name, name)) {
21812 WARN(in_nmi(),
21813 "Trying to free NMI (%s) from NMI context!\n", n->name);
21814- list_del_rcu(&n->list);
21815+ pax_list_del_rcu((struct list_head *)&n->list);
21816 break;
21817 }
21818 }
21819@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21820 dotraplinkage notrace __kprobes void
21821 do_nmi(struct pt_regs *regs, long error_code)
21822 {
21823+
21824+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21825+ if (!user_mode(regs)) {
21826+ unsigned long cs = regs->cs & 0xFFFF;
21827+ unsigned long ip = ktva_ktla(regs->ip);
21828+
21829+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21830+ regs->ip = ip;
21831+ }
21832+#endif
21833+
21834 nmi_nesting_preprocess(regs);
21835
21836 nmi_enter();
21837diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21838index 6d9582e..f746287 100644
21839--- a/arch/x86/kernel/nmi_selftest.c
21840+++ b/arch/x86/kernel/nmi_selftest.c
21841@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21842 {
21843 /* trap all the unknown NMIs we may generate */
21844 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21845- __initdata);
21846+ __initconst);
21847 }
21848
21849 static void __init cleanup_nmi_testsuite(void)
21850@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21851 unsigned long timeout;
21852
21853 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21854- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21855+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21856 nmi_fail = FAILURE;
21857 return;
21858 }
21859diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21860index 676b8c7..870ba04 100644
21861--- a/arch/x86/kernel/paravirt-spinlocks.c
21862+++ b/arch/x86/kernel/paravirt-spinlocks.c
21863@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21864 arch_spin_lock(lock);
21865 }
21866
21867-struct pv_lock_ops pv_lock_ops = {
21868+struct pv_lock_ops pv_lock_ops __read_only = {
21869 #ifdef CONFIG_SMP
21870 .spin_is_locked = __ticket_spin_is_locked,
21871 .spin_is_contended = __ticket_spin_is_contended,
21872diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21873index cd6de64..27c6af0 100644
21874--- a/arch/x86/kernel/paravirt.c
21875+++ b/arch/x86/kernel/paravirt.c
21876@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21877 {
21878 return x;
21879 }
21880+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21881+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21882+#endif
21883
21884 void __init default_banner(void)
21885 {
21886@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21887 if (opfunc == NULL)
21888 /* If there's no function, patch it with a ud2a (BUG) */
21889 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21890- else if (opfunc == _paravirt_nop)
21891+ else if (opfunc == (void *)_paravirt_nop)
21892 /* If the operation is a nop, then nop the callsite */
21893 ret = paravirt_patch_nop();
21894
21895 /* identity functions just return their single argument */
21896- else if (opfunc == _paravirt_ident_32)
21897+ else if (opfunc == (void *)_paravirt_ident_32)
21898 ret = paravirt_patch_ident_32(insnbuf, len);
21899- else if (opfunc == _paravirt_ident_64)
21900+ else if (opfunc == (void *)_paravirt_ident_64)
21901 ret = paravirt_patch_ident_64(insnbuf, len);
21902+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21903+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21904+ ret = paravirt_patch_ident_64(insnbuf, len);
21905+#endif
21906
21907 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21908 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21909@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21910 if (insn_len > len || start == NULL)
21911 insn_len = len;
21912 else
21913- memcpy(insnbuf, start, insn_len);
21914+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21915
21916 return insn_len;
21917 }
21918@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
21919 return this_cpu_read(paravirt_lazy_mode);
21920 }
21921
21922-struct pv_info pv_info = {
21923+struct pv_info pv_info __read_only = {
21924 .name = "bare hardware",
21925 .paravirt_enabled = 0,
21926 .kernel_rpl = 0,
21927@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21928 #endif
21929 };
21930
21931-struct pv_init_ops pv_init_ops = {
21932+struct pv_init_ops pv_init_ops __read_only = {
21933 .patch = native_patch,
21934 };
21935
21936-struct pv_time_ops pv_time_ops = {
21937+struct pv_time_ops pv_time_ops __read_only = {
21938 .sched_clock = native_sched_clock,
21939 .steal_clock = native_steal_clock,
21940 };
21941
21942-struct pv_irq_ops pv_irq_ops = {
21943+struct pv_irq_ops pv_irq_ops __read_only = {
21944 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21945 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21946 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21947@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21948 #endif
21949 };
21950
21951-struct pv_cpu_ops pv_cpu_ops = {
21952+struct pv_cpu_ops pv_cpu_ops __read_only = {
21953 .cpuid = native_cpuid,
21954 .get_debugreg = native_get_debugreg,
21955 .set_debugreg = native_set_debugreg,
21956@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21957 .end_context_switch = paravirt_nop,
21958 };
21959
21960-struct pv_apic_ops pv_apic_ops = {
21961+struct pv_apic_ops pv_apic_ops __read_only= {
21962 #ifdef CONFIG_X86_LOCAL_APIC
21963 .startup_ipi_hook = paravirt_nop,
21964 #endif
21965 };
21966
21967-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21968+#ifdef CONFIG_X86_32
21969+#ifdef CONFIG_X86_PAE
21970+/* 64-bit pagetable entries */
21971+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21972+#else
21973 /* 32-bit pagetable entries */
21974 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21975+#endif
21976 #else
21977 /* 64-bit pagetable entries */
21978 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21979 #endif
21980
21981-struct pv_mmu_ops pv_mmu_ops = {
21982+struct pv_mmu_ops pv_mmu_ops __read_only = {
21983
21984 .read_cr2 = native_read_cr2,
21985 .write_cr2 = native_write_cr2,
21986@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21987 .make_pud = PTE_IDENT,
21988
21989 .set_pgd = native_set_pgd,
21990+ .set_pgd_batched = native_set_pgd_batched,
21991 #endif
21992 #endif /* PAGETABLE_LEVELS >= 3 */
21993
21994@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21995 },
21996
21997 .set_fixmap = native_set_fixmap,
21998+
21999+#ifdef CONFIG_PAX_KERNEXEC
22000+ .pax_open_kernel = native_pax_open_kernel,
22001+ .pax_close_kernel = native_pax_close_kernel,
22002+#endif
22003+
22004 };
22005
22006 EXPORT_SYMBOL_GPL(pv_time_ops);
22007diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
22008index 299d493..2ccb0ee 100644
22009--- a/arch/x86/kernel/pci-calgary_64.c
22010+++ b/arch/x86/kernel/pci-calgary_64.c
22011@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
22012 tce_space = be64_to_cpu(readq(target));
22013 tce_space = tce_space & TAR_SW_BITS;
22014
22015- tce_space = tce_space & (~specified_table_size);
22016+ tce_space = tce_space & (~(unsigned long)specified_table_size);
22017 info->tce_space = (u64 *)__va(tce_space);
22018 }
22019 }
22020diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
22021index 35ccf75..7a15747 100644
22022--- a/arch/x86/kernel/pci-iommu_table.c
22023+++ b/arch/x86/kernel/pci-iommu_table.c
22024@@ -2,7 +2,7 @@
22025 #include <asm/iommu_table.h>
22026 #include <linux/string.h>
22027 #include <linux/kallsyms.h>
22028-
22029+#include <linux/sched.h>
22030
22031 #define DEBUG 1
22032
22033diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
22034index 6c483ba..d10ce2f 100644
22035--- a/arch/x86/kernel/pci-swiotlb.c
22036+++ b/arch/x86/kernel/pci-swiotlb.c
22037@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
22038 void *vaddr, dma_addr_t dma_addr,
22039 struct dma_attrs *attrs)
22040 {
22041- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
22042+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
22043 }
22044
22045 static struct dma_map_ops swiotlb_dma_ops = {
22046diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
22047index 81a5f5e..20f8b58 100644
22048--- a/arch/x86/kernel/process.c
22049+++ b/arch/x86/kernel/process.c
22050@@ -36,7 +36,8 @@
22051 * section. Since TSS's are completely CPU-local, we want them
22052 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
22053 */
22054-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
22055+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
22056+EXPORT_SYMBOL(init_tss);
22057
22058 #ifdef CONFIG_X86_64
22059 static DEFINE_PER_CPU(unsigned char, is_idle);
22060@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
22061 task_xstate_cachep =
22062 kmem_cache_create("task_xstate", xstate_size,
22063 __alignof__(union thread_xstate),
22064- SLAB_PANIC | SLAB_NOTRACK, NULL);
22065+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
22066 }
22067
22068 /*
22069@@ -105,7 +106,7 @@ void exit_thread(void)
22070 unsigned long *bp = t->io_bitmap_ptr;
22071
22072 if (bp) {
22073- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
22074+ struct tss_struct *tss = init_tss + get_cpu();
22075
22076 t->io_bitmap_ptr = NULL;
22077 clear_thread_flag(TIF_IO_BITMAP);
22078@@ -125,6 +126,9 @@ void flush_thread(void)
22079 {
22080 struct task_struct *tsk = current;
22081
22082+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
22083+ loadsegment(gs, 0);
22084+#endif
22085 flush_ptrace_hw_breakpoint(tsk);
22086 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
22087 drop_init_fpu(tsk);
22088@@ -271,7 +275,7 @@ static void __exit_idle(void)
22089 void exit_idle(void)
22090 {
22091 /* idle loop has pid 0 */
22092- if (current->pid)
22093+ if (task_pid_nr(current))
22094 return;
22095 __exit_idle();
22096 }
22097@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
22098 return ret;
22099 }
22100 #endif
22101-void stop_this_cpu(void *dummy)
22102+__noreturn void stop_this_cpu(void *dummy)
22103 {
22104 local_irq_disable();
22105 /*
22106@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
22107 }
22108 early_param("idle", idle_setup);
22109
22110-unsigned long arch_align_stack(unsigned long sp)
22111+#ifdef CONFIG_PAX_RANDKSTACK
22112+void pax_randomize_kstack(struct pt_regs *regs)
22113 {
22114- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
22115- sp -= get_random_int() % 8192;
22116- return sp & ~0xf;
22117-}
22118+ struct thread_struct *thread = &current->thread;
22119+ unsigned long time;
22120
22121-unsigned long arch_randomize_brk(struct mm_struct *mm)
22122-{
22123- unsigned long range_end = mm->brk + 0x02000000;
22124- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
22125-}
22126+ if (!randomize_va_space)
22127+ return;
22128+
22129+ if (v8086_mode(regs))
22130+ return;
22131
22132+ rdtscl(time);
22133+
22134+ /* P4 seems to return a 0 LSB, ignore it */
22135+#ifdef CONFIG_MPENTIUM4
22136+ time &= 0x3EUL;
22137+ time <<= 2;
22138+#elif defined(CONFIG_X86_64)
22139+ time &= 0xFUL;
22140+ time <<= 4;
22141+#else
22142+ time &= 0x1FUL;
22143+ time <<= 3;
22144+#endif
22145+
22146+ thread->sp0 ^= time;
22147+ load_sp0(init_tss + smp_processor_id(), thread);
22148+
22149+#ifdef CONFIG_X86_64
22150+ this_cpu_write(kernel_stack, thread->sp0);
22151+#endif
22152+}
22153+#endif
22154diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
22155index 7305f7d..22f73d6 100644
22156--- a/arch/x86/kernel/process_32.c
22157+++ b/arch/x86/kernel/process_32.c
22158@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
22159 unsigned long thread_saved_pc(struct task_struct *tsk)
22160 {
22161 return ((unsigned long *)tsk->thread.sp)[3];
22162+//XXX return tsk->thread.eip;
22163 }
22164
22165 void __show_regs(struct pt_regs *regs, int all)
22166@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
22167 unsigned long sp;
22168 unsigned short ss, gs;
22169
22170- if (user_mode_vm(regs)) {
22171+ if (user_mode(regs)) {
22172 sp = regs->sp;
22173 ss = regs->ss & 0xffff;
22174- gs = get_user_gs(regs);
22175 } else {
22176 sp = kernel_stack_pointer(regs);
22177 savesegment(ss, ss);
22178- savesegment(gs, gs);
22179 }
22180+ gs = get_user_gs(regs);
22181
22182 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
22183 (u16)regs->cs, regs->ip, regs->flags,
22184- smp_processor_id());
22185+ raw_smp_processor_id());
22186 print_symbol("EIP is at %s\n", regs->ip);
22187
22188 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22189@@ -128,20 +128,21 @@ void release_thread(struct task_struct *dead_task)
22190 int copy_thread(unsigned long clone_flags, unsigned long sp,
22191 unsigned long arg, struct task_struct *p)
22192 {
22193- struct pt_regs *childregs = task_pt_regs(p);
22194+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22195 struct task_struct *tsk;
22196 int err;
22197
22198 p->thread.sp = (unsigned long) childregs;
22199 p->thread.sp0 = (unsigned long) (childregs+1);
22200+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22201
22202 if (unlikely(p->flags & PF_KTHREAD)) {
22203 /* kernel thread */
22204 memset(childregs, 0, sizeof(struct pt_regs));
22205 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22206- task_user_gs(p) = __KERNEL_STACK_CANARY;
22207- childregs->ds = __USER_DS;
22208- childregs->es = __USER_DS;
22209+ savesegment(gs, childregs->gs);
22210+ childregs->ds = __KERNEL_DS;
22211+ childregs->es = __KERNEL_DS;
22212 childregs->fs = __KERNEL_PERCPU;
22213 childregs->bx = sp; /* function */
22214 childregs->bp = arg;
22215@@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22216 struct thread_struct *prev = &prev_p->thread,
22217 *next = &next_p->thread;
22218 int cpu = smp_processor_id();
22219- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22220+ struct tss_struct *tss = init_tss + cpu;
22221 fpu_switch_t fpu;
22222
22223 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22224@@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22225 */
22226 lazy_save_gs(prev->gs);
22227
22228+#ifdef CONFIG_PAX_MEMORY_UDEREF
22229+ __set_fs(task_thread_info(next_p)->addr_limit);
22230+#endif
22231+
22232 /*
22233 * Load the per-thread Thread-Local Storage descriptor.
22234 */
22235@@ -302,6 +307,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22236 */
22237 arch_end_context_switch(next_p);
22238
22239+ this_cpu_write(current_task, next_p);
22240+ this_cpu_write(current_tinfo, &next_p->tinfo);
22241+
22242 /*
22243 * Restore %gs if needed (which is common)
22244 */
22245@@ -310,8 +318,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22246
22247 switch_fpu_finish(next_p, fpu);
22248
22249- this_cpu_write(current_task, next_p);
22250-
22251 return prev_p;
22252 }
22253
22254@@ -341,4 +347,3 @@ unsigned long get_wchan(struct task_struct *p)
22255 } while (count++ < 16);
22256 return 0;
22257 }
22258-
22259diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22260index 355ae06..4530766 100644
22261--- a/arch/x86/kernel/process_64.c
22262+++ b/arch/x86/kernel/process_64.c
22263@@ -151,10 +151,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22264 struct pt_regs *childregs;
22265 struct task_struct *me = current;
22266
22267- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22268+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22269 childregs = task_pt_regs(p);
22270 p->thread.sp = (unsigned long) childregs;
22271 p->thread.usersp = me->thread.usersp;
22272+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22273 set_tsk_thread_flag(p, TIF_FORK);
22274 p->fpu_counter = 0;
22275 p->thread.io_bitmap_ptr = NULL;
22276@@ -273,7 +274,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22277 struct thread_struct *prev = &prev_p->thread;
22278 struct thread_struct *next = &next_p->thread;
22279 int cpu = smp_processor_id();
22280- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22281+ struct tss_struct *tss = init_tss + cpu;
22282 unsigned fsindex, gsindex;
22283 fpu_switch_t fpu;
22284
22285@@ -355,10 +356,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22286 prev->usersp = this_cpu_read(old_rsp);
22287 this_cpu_write(old_rsp, next->usersp);
22288 this_cpu_write(current_task, next_p);
22289+ this_cpu_write(current_tinfo, &next_p->tinfo);
22290
22291- this_cpu_write(kernel_stack,
22292- (unsigned long)task_stack_page(next_p) +
22293- THREAD_SIZE - KERNEL_STACK_OFFSET);
22294+ this_cpu_write(kernel_stack, next->sp0);
22295
22296 /*
22297 * Now maybe reload the debug registers and handle I/O bitmaps
22298@@ -427,12 +427,11 @@ unsigned long get_wchan(struct task_struct *p)
22299 if (!p || p == current || p->state == TASK_RUNNING)
22300 return 0;
22301 stack = (unsigned long)task_stack_page(p);
22302- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22303+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22304 return 0;
22305 fp = *(u64 *)(p->thread.sp);
22306 do {
22307- if (fp < (unsigned long)stack ||
22308- fp >= (unsigned long)stack+THREAD_SIZE)
22309+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22310 return 0;
22311 ip = *(u64 *)(fp+8);
22312 if (!in_sched_functions(ip))
22313diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22314index 29a8120..a50b5ee 100644
22315--- a/arch/x86/kernel/ptrace.c
22316+++ b/arch/x86/kernel/ptrace.c
22317@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22318 {
22319 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22320 unsigned long sp = (unsigned long)&regs->sp;
22321- struct thread_info *tinfo;
22322
22323- if (context == (sp & ~(THREAD_SIZE - 1)))
22324+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22325 return sp;
22326
22327- tinfo = (struct thread_info *)context;
22328- if (tinfo->previous_esp)
22329- return tinfo->previous_esp;
22330+ sp = *(unsigned long *)context;
22331+ if (sp)
22332+ return sp;
22333
22334 return (unsigned long)regs;
22335 }
22336@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22337 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22338 {
22339 int i;
22340- int dr7 = 0;
22341+ unsigned long dr7 = 0;
22342 struct arch_hw_breakpoint *info;
22343
22344 for (i = 0; i < HBP_NUM; i++) {
22345@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22346 unsigned long addr, unsigned long data)
22347 {
22348 int ret;
22349- unsigned long __user *datap = (unsigned long __user *)data;
22350+ unsigned long __user *datap = (__force unsigned long __user *)data;
22351
22352 switch (request) {
22353 /* read the word at location addr in the USER area. */
22354@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22355 if ((int) addr < 0)
22356 return -EIO;
22357 ret = do_get_thread_area(child, addr,
22358- (struct user_desc __user *)data);
22359+ (__force struct user_desc __user *) data);
22360 break;
22361
22362 case PTRACE_SET_THREAD_AREA:
22363 if ((int) addr < 0)
22364 return -EIO;
22365 ret = do_set_thread_area(child, addr,
22366- (struct user_desc __user *)data, 0);
22367+ (__force struct user_desc __user *) data, 0);
22368 break;
22369 #endif
22370
22371@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22372
22373 #ifdef CONFIG_X86_64
22374
22375-static struct user_regset x86_64_regsets[] __read_mostly = {
22376+static user_regset_no_const x86_64_regsets[] __read_only = {
22377 [REGSET_GENERAL] = {
22378 .core_note_type = NT_PRSTATUS,
22379 .n = sizeof(struct user_regs_struct) / sizeof(long),
22380@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22381 #endif /* CONFIG_X86_64 */
22382
22383 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22384-static struct user_regset x86_32_regsets[] __read_mostly = {
22385+static user_regset_no_const x86_32_regsets[] __read_only = {
22386 [REGSET_GENERAL] = {
22387 .core_note_type = NT_PRSTATUS,
22388 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22389@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22390 */
22391 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22392
22393-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22394+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22395 {
22396 #ifdef CONFIG_X86_64
22397 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22398@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22399 memset(info, 0, sizeof(*info));
22400 info->si_signo = SIGTRAP;
22401 info->si_code = si_code;
22402- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22403+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22404 }
22405
22406 void user_single_step_siginfo(struct task_struct *tsk,
22407@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22408 # define IS_IA32 0
22409 #endif
22410
22411+#ifdef CONFIG_GRKERNSEC_SETXID
22412+extern void gr_delayed_cred_worker(void);
22413+#endif
22414+
22415 /*
22416 * We must return the syscall number to actually look up in the table.
22417 * This can be -1L to skip running any syscall at all.
22418@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22419
22420 user_exit();
22421
22422+#ifdef CONFIG_GRKERNSEC_SETXID
22423+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22424+ gr_delayed_cred_worker();
22425+#endif
22426+
22427 /*
22428 * If we stepped into a sysenter/syscall insn, it trapped in
22429 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22430@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22431 */
22432 user_exit();
22433
22434+#ifdef CONFIG_GRKERNSEC_SETXID
22435+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22436+ gr_delayed_cred_worker();
22437+#endif
22438+
22439 audit_syscall_exit(regs);
22440
22441 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22442diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22443index 2cb9470..ff1fd80 100644
22444--- a/arch/x86/kernel/pvclock.c
22445+++ b/arch/x86/kernel/pvclock.c
22446@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22447 return pv_tsc_khz;
22448 }
22449
22450-static atomic64_t last_value = ATOMIC64_INIT(0);
22451+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22452
22453 void pvclock_resume(void)
22454 {
22455- atomic64_set(&last_value, 0);
22456+ atomic64_set_unchecked(&last_value, 0);
22457 }
22458
22459 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22460@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22461 * updating at the same time, and one of them could be slightly behind,
22462 * making the assumption that last_value always go forward fail to hold.
22463 */
22464- last = atomic64_read(&last_value);
22465+ last = atomic64_read_unchecked(&last_value);
22466 do {
22467 if (ret < last)
22468 return last;
22469- last = atomic64_cmpxchg(&last_value, last, ret);
22470+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22471 } while (unlikely(last != ret));
22472
22473 return ret;
22474diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22475index 76fa1e9..abf09ea 100644
22476--- a/arch/x86/kernel/reboot.c
22477+++ b/arch/x86/kernel/reboot.c
22478@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22479 EXPORT_SYMBOL(pm_power_off);
22480
22481 static const struct desc_ptr no_idt = {};
22482-static int reboot_mode;
22483+static unsigned short reboot_mode;
22484 enum reboot_type reboot_type = BOOT_ACPI;
22485 int reboot_force;
22486
22487@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22488
22489 void __noreturn machine_real_restart(unsigned int type)
22490 {
22491+
22492+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22493+ struct desc_struct *gdt;
22494+#endif
22495+
22496 local_irq_disable();
22497
22498 /*
22499@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22500
22501 /* Jump to the identity-mapped low memory code */
22502 #ifdef CONFIG_X86_32
22503- asm volatile("jmpl *%0" : :
22504+
22505+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22506+ gdt = get_cpu_gdt_table(smp_processor_id());
22507+ pax_open_kernel();
22508+#ifdef CONFIG_PAX_MEMORY_UDEREF
22509+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22510+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22511+ loadsegment(ds, __KERNEL_DS);
22512+ loadsegment(es, __KERNEL_DS);
22513+ loadsegment(ss, __KERNEL_DS);
22514+#endif
22515+#ifdef CONFIG_PAX_KERNEXEC
22516+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22517+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22518+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22519+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22520+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22521+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22522+#endif
22523+ pax_close_kernel();
22524+#endif
22525+
22526+ asm volatile("ljmpl *%0" : :
22527 "rm" (real_mode_header->machine_real_restart_asm),
22528 "a" (type));
22529 #else
22530@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22531 * try to force a triple fault and then cycle between hitting the keyboard
22532 * controller and doing that
22533 */
22534-static void native_machine_emergency_restart(void)
22535+static void __noreturn native_machine_emergency_restart(void)
22536 {
22537 int i;
22538 int attempt = 0;
22539@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22540 #endif
22541 }
22542
22543-static void __machine_emergency_restart(int emergency)
22544+static void __noreturn __machine_emergency_restart(int emergency)
22545 {
22546 reboot_emergency = emergency;
22547 machine_ops.emergency_restart();
22548 }
22549
22550-static void native_machine_restart(char *__unused)
22551+static void __noreturn native_machine_restart(char *__unused)
22552 {
22553 pr_notice("machine restart\n");
22554
22555@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22556 __machine_emergency_restart(0);
22557 }
22558
22559-static void native_machine_halt(void)
22560+static void __noreturn native_machine_halt(void)
22561 {
22562 /* Stop other cpus and apics */
22563 machine_shutdown();
22564@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22565 stop_this_cpu(NULL);
22566 }
22567
22568-static void native_machine_power_off(void)
22569+static void __noreturn native_machine_power_off(void)
22570 {
22571 if (pm_power_off) {
22572 if (!reboot_force)
22573@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22574 }
22575 /* A fallback in case there is no PM info available */
22576 tboot_shutdown(TB_SHUTDOWN_HALT);
22577+ unreachable();
22578 }
22579
22580-struct machine_ops machine_ops = {
22581+struct machine_ops machine_ops __read_only = {
22582 .power_off = native_machine_power_off,
22583 .shutdown = native_machine_shutdown,
22584 .emergency_restart = native_machine_emergency_restart,
22585diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22586index f2bb9c9..bed145d7 100644
22587--- a/arch/x86/kernel/relocate_kernel_64.S
22588+++ b/arch/x86/kernel/relocate_kernel_64.S
22589@@ -11,6 +11,7 @@
22590 #include <asm/kexec.h>
22591 #include <asm/processor-flags.h>
22592 #include <asm/pgtable_types.h>
22593+#include <asm/alternative-asm.h>
22594
22595 /*
22596 * Must be relocatable PIC code callable as a C function
22597@@ -167,6 +168,7 @@ identity_mapped:
22598 xorq %r14, %r14
22599 xorq %r15, %r15
22600
22601+ pax_force_retaddr 0, 1
22602 ret
22603
22604 1:
22605diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22606index 56f7fcf..fa229f4 100644
22607--- a/arch/x86/kernel/setup.c
22608+++ b/arch/x86/kernel/setup.c
22609@@ -110,6 +110,7 @@
22610 #include <asm/mce.h>
22611 #include <asm/alternative.h>
22612 #include <asm/prom.h>
22613+#include <asm/boot.h>
22614
22615 /*
22616 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
22617@@ -444,7 +445,7 @@ static void __init parse_setup_data(void)
22618
22619 switch (data->type) {
22620 case SETUP_E820_EXT:
22621- parse_e820_ext(data);
22622+ parse_e820_ext((struct setup_data __force_kernel *)data);
22623 break;
22624 case SETUP_DTB:
22625 add_dtb(pa_data);
22626@@ -771,7 +772,7 @@ static void __init trim_bios_range(void)
22627 * area (640->1Mb) as ram even though it is not.
22628 * take them out.
22629 */
22630- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22631+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22632
22633 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22634 }
22635@@ -779,7 +780,7 @@ static void __init trim_bios_range(void)
22636 /* called before trim_bios_range() to spare extra sanitize */
22637 static void __init e820_add_kernel_range(void)
22638 {
22639- u64 start = __pa_symbol(_text);
22640+ u64 start = __pa_symbol(ktla_ktva(_text));
22641 u64 size = __pa_symbol(_end) - start;
22642
22643 /*
22644@@ -841,8 +842,12 @@ static void __init trim_low_memory_range(void)
22645
22646 void __init setup_arch(char **cmdline_p)
22647 {
22648+#ifdef CONFIG_X86_32
22649+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
22650+#else
22651 memblock_reserve(__pa_symbol(_text),
22652 (unsigned long)__bss_stop - (unsigned long)_text);
22653+#endif
22654
22655 early_reserve_initrd();
22656
22657@@ -934,14 +939,14 @@ void __init setup_arch(char **cmdline_p)
22658
22659 if (!boot_params.hdr.root_flags)
22660 root_mountflags &= ~MS_RDONLY;
22661- init_mm.start_code = (unsigned long) _text;
22662- init_mm.end_code = (unsigned long) _etext;
22663+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22664+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22665 init_mm.end_data = (unsigned long) _edata;
22666 init_mm.brk = _brk_end;
22667
22668- code_resource.start = __pa_symbol(_text);
22669- code_resource.end = __pa_symbol(_etext)-1;
22670- data_resource.start = __pa_symbol(_etext);
22671+ code_resource.start = __pa_symbol(ktla_ktva(_text));
22672+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
22673+ data_resource.start = __pa_symbol(_sdata);
22674 data_resource.end = __pa_symbol(_edata)-1;
22675 bss_resource.start = __pa_symbol(__bss_start);
22676 bss_resource.end = __pa_symbol(__bss_stop)-1;
22677diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22678index 5cdff03..80fa283 100644
22679--- a/arch/x86/kernel/setup_percpu.c
22680+++ b/arch/x86/kernel/setup_percpu.c
22681@@ -21,19 +21,17 @@
22682 #include <asm/cpu.h>
22683 #include <asm/stackprotector.h>
22684
22685-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22686+#ifdef CONFIG_SMP
22687+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22688 EXPORT_PER_CPU_SYMBOL(cpu_number);
22689+#endif
22690
22691-#ifdef CONFIG_X86_64
22692 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22693-#else
22694-#define BOOT_PERCPU_OFFSET 0
22695-#endif
22696
22697 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22698 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22699
22700-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22701+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22702 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22703 };
22704 EXPORT_SYMBOL(__per_cpu_offset);
22705@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22706 {
22707 #ifdef CONFIG_NEED_MULTIPLE_NODES
22708 pg_data_t *last = NULL;
22709- unsigned int cpu;
22710+ int cpu;
22711
22712 for_each_possible_cpu(cpu) {
22713 int node = early_cpu_to_node(cpu);
22714@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22715 {
22716 #ifdef CONFIG_X86_32
22717 struct desc_struct gdt;
22718+ unsigned long base = per_cpu_offset(cpu);
22719
22720- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22721- 0x2 | DESCTYPE_S, 0x8);
22722- gdt.s = 1;
22723+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22724+ 0x83 | DESCTYPE_S, 0xC);
22725 write_gdt_entry(get_cpu_gdt_table(cpu),
22726 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22727 #endif
22728@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22729 /* alrighty, percpu areas up and running */
22730 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22731 for_each_possible_cpu(cpu) {
22732+#ifdef CONFIG_CC_STACKPROTECTOR
22733+#ifdef CONFIG_X86_32
22734+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22735+#endif
22736+#endif
22737 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22738 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22739 per_cpu(cpu_number, cpu) = cpu;
22740@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22741 */
22742 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22743 #endif
22744+#ifdef CONFIG_CC_STACKPROTECTOR
22745+#ifdef CONFIG_X86_32
22746+ if (!cpu)
22747+ per_cpu(stack_canary.canary, cpu) = canary;
22748+#endif
22749+#endif
22750 /*
22751 * Up to this point, the boot CPU has been using .init.data
22752 * area. Reload any changed state for the boot CPU.
22753diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22754index 6956299..f20beae 100644
22755--- a/arch/x86/kernel/signal.c
22756+++ b/arch/x86/kernel/signal.c
22757@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22758 * Align the stack pointer according to the i386 ABI,
22759 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22760 */
22761- sp = ((sp + 4) & -16ul) - 4;
22762+ sp = ((sp - 12) & -16ul) - 4;
22763 #else /* !CONFIG_X86_32 */
22764 sp = round_down(sp, 16) - 8;
22765 #endif
22766@@ -304,9 +304,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22767 }
22768
22769 if (current->mm->context.vdso)
22770- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22771+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22772 else
22773- restorer = &frame->retcode;
22774+ restorer = (void __user *)&frame->retcode;
22775 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22776 restorer = ksig->ka.sa.sa_restorer;
22777
22778@@ -320,7 +320,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22779 * reasons and because gdb uses it as a signature to notice
22780 * signal handler stack frames.
22781 */
22782- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22783+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22784
22785 if (err)
22786 return -EFAULT;
22787@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22788 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22789
22790 /* Set up to return from userspace. */
22791- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22792+ if (current->mm->context.vdso)
22793+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22794+ else
22795+ restorer = (void __user *)&frame->retcode;
22796 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22797 restorer = ksig->ka.sa.sa_restorer;
22798 put_user_ex(restorer, &frame->pretcode);
22799@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22800 * reasons and because gdb uses it as a signature to notice
22801 * signal handler stack frames.
22802 */
22803- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22804+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22805 } put_user_catch(err);
22806
22807 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
22808@@ -615,7 +618,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22809 {
22810 int usig = signr_convert(ksig->sig);
22811 sigset_t *set = sigmask_to_save();
22812- compat_sigset_t *cset = (compat_sigset_t *) set;
22813+ sigset_t sigcopy;
22814+ compat_sigset_t *cset;
22815+
22816+ sigcopy = *set;
22817+
22818+ cset = (compat_sigset_t *) &sigcopy;
22819
22820 /* Set up the stack frame */
22821 if (is_ia32_frame()) {
22822@@ -626,7 +634,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22823 } else if (is_x32_frame()) {
22824 return x32_setup_rt_frame(ksig, cset, regs);
22825 } else {
22826- return __setup_rt_frame(ksig->sig, ksig, set, regs);
22827+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
22828 }
22829 }
22830
22831diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22832index 48d2b7d..90d328a 100644
22833--- a/arch/x86/kernel/smp.c
22834+++ b/arch/x86/kernel/smp.c
22835@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22836
22837 __setup("nonmi_ipi", nonmi_ipi_setup);
22838
22839-struct smp_ops smp_ops = {
22840+struct smp_ops smp_ops __read_only = {
22841 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22842 .smp_prepare_cpus = native_smp_prepare_cpus,
22843 .smp_cpus_done = native_smp_cpus_done,
22844diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22845index bfd348e..4816ad8 100644
22846--- a/arch/x86/kernel/smpboot.c
22847+++ b/arch/x86/kernel/smpboot.c
22848@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22849 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22850 (THREAD_SIZE + task_stack_page(idle))) - 1);
22851 per_cpu(current_task, cpu) = idle;
22852+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22853
22854 #ifdef CONFIG_X86_32
22855 /* Stack for startup_32 can be just as for start_secondary onwards */
22856@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22857 #else
22858 clear_tsk_thread_flag(idle, TIF_FORK);
22859 initial_gs = per_cpu_offset(cpu);
22860- per_cpu(kernel_stack, cpu) =
22861- (unsigned long)task_stack_page(idle) -
22862- KERNEL_STACK_OFFSET + THREAD_SIZE;
22863+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22864 #endif
22865+
22866+ pax_open_kernel();
22867 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22868+ pax_close_kernel();
22869+
22870 initial_code = (unsigned long)start_secondary;
22871 stack_start = idle->thread.sp;
22872
22873@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22874 /* the FPU context is blank, nobody can own it */
22875 __cpu_disable_lazy_restore(cpu);
22876
22877+#ifdef CONFIG_PAX_PER_CPU_PGD
22878+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22879+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22880+ KERNEL_PGD_PTRS);
22881+#endif
22882+
22883+ /* the FPU context is blank, nobody can own it */
22884+ __cpu_disable_lazy_restore(cpu);
22885+
22886 err = do_boot_cpu(apicid, cpu, tidle);
22887 if (err) {
22888 pr_debug("do_boot_cpu failed %d\n", err);
22889diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22890index 9b4d51d..5d28b58 100644
22891--- a/arch/x86/kernel/step.c
22892+++ b/arch/x86/kernel/step.c
22893@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22894 struct desc_struct *desc;
22895 unsigned long base;
22896
22897- seg &= ~7UL;
22898+ seg >>= 3;
22899
22900 mutex_lock(&child->mm->context.lock);
22901- if (unlikely((seg >> 3) >= child->mm->context.size))
22902+ if (unlikely(seg >= child->mm->context.size))
22903 addr = -1L; /* bogus selector, access would fault */
22904 else {
22905 desc = child->mm->context.ldt + seg;
22906@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22907 addr += base;
22908 }
22909 mutex_unlock(&child->mm->context.lock);
22910- }
22911+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22912+ addr = ktla_ktva(addr);
22913
22914 return addr;
22915 }
22916@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22917 unsigned char opcode[15];
22918 unsigned long addr = convert_ip_to_linear(child, regs);
22919
22920+ if (addr == -EINVAL)
22921+ return 0;
22922+
22923 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22924 for (i = 0; i < copied; i++) {
22925 switch (opcode[i]) {
22926diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22927new file mode 100644
22928index 0000000..5877189
22929--- /dev/null
22930+++ b/arch/x86/kernel/sys_i386_32.c
22931@@ -0,0 +1,189 @@
22932+/*
22933+ * This file contains various random system calls that
22934+ * have a non-standard calling sequence on the Linux/i386
22935+ * platform.
22936+ */
22937+
22938+#include <linux/errno.h>
22939+#include <linux/sched.h>
22940+#include <linux/mm.h>
22941+#include <linux/fs.h>
22942+#include <linux/smp.h>
22943+#include <linux/sem.h>
22944+#include <linux/msg.h>
22945+#include <linux/shm.h>
22946+#include <linux/stat.h>
22947+#include <linux/syscalls.h>
22948+#include <linux/mman.h>
22949+#include <linux/file.h>
22950+#include <linux/utsname.h>
22951+#include <linux/ipc.h>
22952+#include <linux/elf.h>
22953+
22954+#include <linux/uaccess.h>
22955+#include <linux/unistd.h>
22956+
22957+#include <asm/syscalls.h>
22958+
22959+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22960+{
22961+ unsigned long pax_task_size = TASK_SIZE;
22962+
22963+#ifdef CONFIG_PAX_SEGMEXEC
22964+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22965+ pax_task_size = SEGMEXEC_TASK_SIZE;
22966+#endif
22967+
22968+ if (flags & MAP_FIXED)
22969+ if (len > pax_task_size || addr > pax_task_size - len)
22970+ return -EINVAL;
22971+
22972+ return 0;
22973+}
22974+
22975+/*
22976+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
22977+ */
22978+static unsigned long get_align_mask(void)
22979+{
22980+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
22981+ return 0;
22982+
22983+ if (!(current->flags & PF_RANDOMIZE))
22984+ return 0;
22985+
22986+ return va_align.mask;
22987+}
22988+
22989+unsigned long
22990+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22991+ unsigned long len, unsigned long pgoff, unsigned long flags)
22992+{
22993+ struct mm_struct *mm = current->mm;
22994+ struct vm_area_struct *vma;
22995+ unsigned long pax_task_size = TASK_SIZE;
22996+ struct vm_unmapped_area_info info;
22997+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22998+
22999+#ifdef CONFIG_PAX_SEGMEXEC
23000+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23001+ pax_task_size = SEGMEXEC_TASK_SIZE;
23002+#endif
23003+
23004+ pax_task_size -= PAGE_SIZE;
23005+
23006+ if (len > pax_task_size)
23007+ return -ENOMEM;
23008+
23009+ if (flags & MAP_FIXED)
23010+ return addr;
23011+
23012+#ifdef CONFIG_PAX_RANDMMAP
23013+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23014+#endif
23015+
23016+ if (addr) {
23017+ addr = PAGE_ALIGN(addr);
23018+ if (pax_task_size - len >= addr) {
23019+ vma = find_vma(mm, addr);
23020+ if (check_heap_stack_gap(vma, addr, len, offset))
23021+ return addr;
23022+ }
23023+ }
23024+
23025+ info.flags = 0;
23026+ info.length = len;
23027+ info.align_mask = filp ? get_align_mask() : 0;
23028+ info.align_offset = pgoff << PAGE_SHIFT;
23029+ info.threadstack_offset = offset;
23030+
23031+#ifdef CONFIG_PAX_PAGEEXEC
23032+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
23033+ info.low_limit = 0x00110000UL;
23034+ info.high_limit = mm->start_code;
23035+
23036+#ifdef CONFIG_PAX_RANDMMAP
23037+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23038+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
23039+#endif
23040+
23041+ if (info.low_limit < info.high_limit) {
23042+ addr = vm_unmapped_area(&info);
23043+ if (!IS_ERR_VALUE(addr))
23044+ return addr;
23045+ }
23046+ } else
23047+#endif
23048+
23049+ info.low_limit = mm->mmap_base;
23050+ info.high_limit = pax_task_size;
23051+
23052+ return vm_unmapped_area(&info);
23053+}
23054+
23055+unsigned long
23056+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23057+ const unsigned long len, const unsigned long pgoff,
23058+ const unsigned long flags)
23059+{
23060+ struct vm_area_struct *vma;
23061+ struct mm_struct *mm = current->mm;
23062+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
23063+ struct vm_unmapped_area_info info;
23064+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23065+
23066+#ifdef CONFIG_PAX_SEGMEXEC
23067+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23068+ pax_task_size = SEGMEXEC_TASK_SIZE;
23069+#endif
23070+
23071+ pax_task_size -= PAGE_SIZE;
23072+
23073+ /* requested length too big for entire address space */
23074+ if (len > pax_task_size)
23075+ return -ENOMEM;
23076+
23077+ if (flags & MAP_FIXED)
23078+ return addr;
23079+
23080+#ifdef CONFIG_PAX_PAGEEXEC
23081+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
23082+ goto bottomup;
23083+#endif
23084+
23085+#ifdef CONFIG_PAX_RANDMMAP
23086+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23087+#endif
23088+
23089+ /* requesting a specific address */
23090+ if (addr) {
23091+ addr = PAGE_ALIGN(addr);
23092+ if (pax_task_size - len >= addr) {
23093+ vma = find_vma(mm, addr);
23094+ if (check_heap_stack_gap(vma, addr, len, offset))
23095+ return addr;
23096+ }
23097+ }
23098+
23099+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
23100+ info.length = len;
23101+ info.low_limit = PAGE_SIZE;
23102+ info.high_limit = mm->mmap_base;
23103+ info.align_mask = filp ? get_align_mask() : 0;
23104+ info.align_offset = pgoff << PAGE_SHIFT;
23105+ info.threadstack_offset = offset;
23106+
23107+ addr = vm_unmapped_area(&info);
23108+ if (!(addr & ~PAGE_MASK))
23109+ return addr;
23110+ VM_BUG_ON(addr != -ENOMEM);
23111+
23112+bottomup:
23113+ /*
23114+ * A failed mmap() very likely causes application failure,
23115+ * so fall back to the bottom-up function here. This scenario
23116+ * can happen with large stack limits and large mmap()
23117+ * allocations.
23118+ */
23119+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
23120+}
23121diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
23122index dbded5a..ace2781 100644
23123--- a/arch/x86/kernel/sys_x86_64.c
23124+++ b/arch/x86/kernel/sys_x86_64.c
23125@@ -81,8 +81,8 @@ out:
23126 return error;
23127 }
23128
23129-static void find_start_end(unsigned long flags, unsigned long *begin,
23130- unsigned long *end)
23131+static void find_start_end(struct mm_struct *mm, unsigned long flags,
23132+ unsigned long *begin, unsigned long *end)
23133 {
23134 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
23135 unsigned long new_begin;
23136@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
23137 *begin = new_begin;
23138 }
23139 } else {
23140- *begin = TASK_UNMAPPED_BASE;
23141+ *begin = mm->mmap_base;
23142 *end = TASK_SIZE;
23143 }
23144 }
23145@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23146 struct vm_area_struct *vma;
23147 struct vm_unmapped_area_info info;
23148 unsigned long begin, end;
23149+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23150
23151 if (flags & MAP_FIXED)
23152 return addr;
23153
23154- find_start_end(flags, &begin, &end);
23155+ find_start_end(mm, flags, &begin, &end);
23156
23157 if (len > end)
23158 return -ENOMEM;
23159
23160+#ifdef CONFIG_PAX_RANDMMAP
23161+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23162+#endif
23163+
23164 if (addr) {
23165 addr = PAGE_ALIGN(addr);
23166 vma = find_vma(mm, addr);
23167- if (end - len >= addr &&
23168- (!vma || addr + len <= vma->vm_start))
23169+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23170 return addr;
23171 }
23172
23173@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23174 info.high_limit = end;
23175 info.align_mask = filp ? get_align_mask() : 0;
23176 info.align_offset = pgoff << PAGE_SHIFT;
23177+ info.threadstack_offset = offset;
23178 return vm_unmapped_area(&info);
23179 }
23180
23181@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23182 struct mm_struct *mm = current->mm;
23183 unsigned long addr = addr0;
23184 struct vm_unmapped_area_info info;
23185+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23186
23187 /* requested length too big for entire address space */
23188 if (len > TASK_SIZE)
23189@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23190 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23191 goto bottomup;
23192
23193+#ifdef CONFIG_PAX_RANDMMAP
23194+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23195+#endif
23196+
23197 /* requesting a specific address */
23198 if (addr) {
23199 addr = PAGE_ALIGN(addr);
23200 vma = find_vma(mm, addr);
23201- if (TASK_SIZE - len >= addr &&
23202- (!vma || addr + len <= vma->vm_start))
23203+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23204 return addr;
23205 }
23206
23207@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23208 info.high_limit = mm->mmap_base;
23209 info.align_mask = filp ? get_align_mask() : 0;
23210 info.align_offset = pgoff << PAGE_SHIFT;
23211+ info.threadstack_offset = offset;
23212 addr = vm_unmapped_area(&info);
23213 if (!(addr & ~PAGE_MASK))
23214 return addr;
23215diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23216index f84fe00..f41d9f1 100644
23217--- a/arch/x86/kernel/tboot.c
23218+++ b/arch/x86/kernel/tboot.c
23219@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23220
23221 void tboot_shutdown(u32 shutdown_type)
23222 {
23223- void (*shutdown)(void);
23224+ void (* __noreturn shutdown)(void);
23225
23226 if (!tboot_enabled())
23227 return;
23228@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23229
23230 switch_to_tboot_pt();
23231
23232- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23233+ shutdown = (void *)tboot->shutdown_entry;
23234 shutdown();
23235
23236 /* should not reach here */
23237@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23238 return 0;
23239 }
23240
23241-static atomic_t ap_wfs_count;
23242+static atomic_unchecked_t ap_wfs_count;
23243
23244 static int tboot_wait_for_aps(int num_aps)
23245 {
23246@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23247 {
23248 switch (action) {
23249 case CPU_DYING:
23250- atomic_inc(&ap_wfs_count);
23251+ atomic_inc_unchecked(&ap_wfs_count);
23252 if (num_online_cpus() == 1)
23253- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23254+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23255 return NOTIFY_BAD;
23256 break;
23257 }
23258 return NOTIFY_OK;
23259 }
23260
23261-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23262+static struct notifier_block tboot_cpu_notifier =
23263 {
23264 .notifier_call = tboot_cpu_callback,
23265 };
23266@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23267
23268 tboot_create_trampoline();
23269
23270- atomic_set(&ap_wfs_count, 0);
23271+ atomic_set_unchecked(&ap_wfs_count, 0);
23272 register_hotcpu_notifier(&tboot_cpu_notifier);
23273
23274 acpi_os_set_prepare_sleep(&tboot_sleep);
23275diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23276index 24d3c91..d06b473 100644
23277--- a/arch/x86/kernel/time.c
23278+++ b/arch/x86/kernel/time.c
23279@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23280 {
23281 unsigned long pc = instruction_pointer(regs);
23282
23283- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23284+ if (!user_mode(regs) && in_lock_functions(pc)) {
23285 #ifdef CONFIG_FRAME_POINTER
23286- return *(unsigned long *)(regs->bp + sizeof(long));
23287+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23288 #else
23289 unsigned long *sp =
23290 (unsigned long *)kernel_stack_pointer(regs);
23291@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23292 * or above a saved flags. Eflags has bits 22-31 zero,
23293 * kernel addresses don't.
23294 */
23295+
23296+#ifdef CONFIG_PAX_KERNEXEC
23297+ return ktla_ktva(sp[0]);
23298+#else
23299 if (sp[0] >> 22)
23300 return sp[0];
23301 if (sp[1] >> 22)
23302 return sp[1];
23303 #endif
23304+
23305+#endif
23306 }
23307 return pc;
23308 }
23309diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23310index f7fec09..9991981 100644
23311--- a/arch/x86/kernel/tls.c
23312+++ b/arch/x86/kernel/tls.c
23313@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23314 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23315 return -EINVAL;
23316
23317+#ifdef CONFIG_PAX_SEGMEXEC
23318+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23319+ return -EINVAL;
23320+#endif
23321+
23322 set_tls_desc(p, idx, &info, 1);
23323
23324 return 0;
23325@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23326
23327 if (kbuf)
23328 info = kbuf;
23329- else if (__copy_from_user(infobuf, ubuf, count))
23330+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23331 return -EFAULT;
23332 else
23333 info = infobuf;
23334diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23335index 772e2a8..bad5bf6 100644
23336--- a/arch/x86/kernel/traps.c
23337+++ b/arch/x86/kernel/traps.c
23338@@ -68,12 +68,6 @@
23339 #include <asm/setup.h>
23340
23341 asmlinkage int system_call(void);
23342-
23343-/*
23344- * The IDT has to be page-aligned to simplify the Pentium
23345- * F0 0F bug workaround.
23346- */
23347-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23348 #endif
23349
23350 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23351@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23352 }
23353
23354 static int __kprobes
23355-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23356+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23357 struct pt_regs *regs, long error_code)
23358 {
23359 #ifdef CONFIG_X86_32
23360- if (regs->flags & X86_VM_MASK) {
23361+ if (v8086_mode(regs)) {
23362 /*
23363 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23364 * On nmi (interrupt 2), do_trap should not be called.
23365@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23366 return -1;
23367 }
23368 #endif
23369- if (!user_mode(regs)) {
23370+ if (!user_mode_novm(regs)) {
23371 if (!fixup_exception(regs)) {
23372 tsk->thread.error_code = error_code;
23373 tsk->thread.trap_nr = trapnr;
23374+
23375+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23376+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23377+ str = "PAX: suspicious stack segment fault";
23378+#endif
23379+
23380 die(str, regs, error_code);
23381 }
23382+
23383+#ifdef CONFIG_PAX_REFCOUNT
23384+ if (trapnr == 4)
23385+ pax_report_refcount_overflow(regs);
23386+#endif
23387+
23388 return 0;
23389 }
23390
23391@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23392 }
23393
23394 static void __kprobes
23395-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23396+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23397 long error_code, siginfo_t *info)
23398 {
23399 struct task_struct *tsk = current;
23400@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23401 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23402 printk_ratelimit()) {
23403 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23404- tsk->comm, tsk->pid, str,
23405+ tsk->comm, task_pid_nr(tsk), str,
23406 regs->ip, regs->sp, error_code);
23407 print_vma_addr(" in ", regs->ip);
23408 pr_cont("\n");
23409@@ -273,7 +279,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23410 conditional_sti(regs);
23411
23412 #ifdef CONFIG_X86_32
23413- if (regs->flags & X86_VM_MASK) {
23414+ if (v8086_mode(regs)) {
23415 local_irq_enable();
23416 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23417 goto exit;
23418@@ -281,18 +287,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23419 #endif
23420
23421 tsk = current;
23422- if (!user_mode(regs)) {
23423+ if (!user_mode_novm(regs)) {
23424 if (fixup_exception(regs))
23425 goto exit;
23426
23427 tsk->thread.error_code = error_code;
23428 tsk->thread.trap_nr = X86_TRAP_GP;
23429 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23430- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23431+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23432+
23433+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23434+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23435+ die("PAX: suspicious general protection fault", regs, error_code);
23436+ else
23437+#endif
23438+
23439 die("general protection fault", regs, error_code);
23440+ }
23441 goto exit;
23442 }
23443
23444+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23445+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23446+ struct mm_struct *mm = tsk->mm;
23447+ unsigned long limit;
23448+
23449+ down_write(&mm->mmap_sem);
23450+ limit = mm->context.user_cs_limit;
23451+ if (limit < TASK_SIZE) {
23452+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23453+ up_write(&mm->mmap_sem);
23454+ return;
23455+ }
23456+ up_write(&mm->mmap_sem);
23457+ }
23458+#endif
23459+
23460 tsk->thread.error_code = error_code;
23461 tsk->thread.trap_nr = X86_TRAP_GP;
23462
23463@@ -450,7 +480,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23464 /* It's safe to allow irq's after DR6 has been saved */
23465 preempt_conditional_sti(regs);
23466
23467- if (regs->flags & X86_VM_MASK) {
23468+ if (v8086_mode(regs)) {
23469 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23470 X86_TRAP_DB);
23471 preempt_conditional_cli(regs);
23472@@ -465,7 +495,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23473 * We already checked v86 mode above, so we can check for kernel mode
23474 * by just checking the CPL of CS.
23475 */
23476- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23477+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23478 tsk->thread.debugreg6 &= ~DR_STEP;
23479 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23480 regs->flags &= ~X86_EFLAGS_TF;
23481@@ -497,7 +527,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23482 return;
23483 conditional_sti(regs);
23484
23485- if (!user_mode_vm(regs))
23486+ if (!user_mode(regs))
23487 {
23488 if (!fixup_exception(regs)) {
23489 task->thread.error_code = error_code;
23490diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23491index 2ed8459..7cf329f 100644
23492--- a/arch/x86/kernel/uprobes.c
23493+++ b/arch/x86/kernel/uprobes.c
23494@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23495 int ret = NOTIFY_DONE;
23496
23497 /* We are only interested in userspace traps */
23498- if (regs && !user_mode_vm(regs))
23499+ if (regs && !user_mode(regs))
23500 return NOTIFY_DONE;
23501
23502 switch (val) {
23503@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
23504
23505 if (ncopied != rasize) {
23506 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
23507- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
23508+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
23509
23510 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
23511 }
23512diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23513index b9242ba..50c5edd 100644
23514--- a/arch/x86/kernel/verify_cpu.S
23515+++ b/arch/x86/kernel/verify_cpu.S
23516@@ -20,6 +20,7 @@
23517 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23518 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23519 * arch/x86/kernel/head_32.S: processor startup
23520+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23521 *
23522 * verify_cpu, returns the status of longmode and SSE in register %eax.
23523 * 0: Success 1: Failure
23524diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23525index e8edcf5..27f9344 100644
23526--- a/arch/x86/kernel/vm86_32.c
23527+++ b/arch/x86/kernel/vm86_32.c
23528@@ -44,6 +44,7 @@
23529 #include <linux/ptrace.h>
23530 #include <linux/audit.h>
23531 #include <linux/stddef.h>
23532+#include <linux/grsecurity.h>
23533
23534 #include <asm/uaccess.h>
23535 #include <asm/io.h>
23536@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23537 do_exit(SIGSEGV);
23538 }
23539
23540- tss = &per_cpu(init_tss, get_cpu());
23541+ tss = init_tss + get_cpu();
23542 current->thread.sp0 = current->thread.saved_sp0;
23543 current->thread.sysenter_cs = __KERNEL_CS;
23544 load_sp0(tss, &current->thread);
23545@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
23546
23547 if (tsk->thread.saved_sp0)
23548 return -EPERM;
23549+
23550+#ifdef CONFIG_GRKERNSEC_VM86
23551+ if (!capable(CAP_SYS_RAWIO)) {
23552+ gr_handle_vm86();
23553+ return -EPERM;
23554+ }
23555+#endif
23556+
23557 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
23558 offsetof(struct kernel_vm86_struct, vm86plus) -
23559 sizeof(info.regs));
23560@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
23561 int tmp;
23562 struct vm86plus_struct __user *v86;
23563
23564+#ifdef CONFIG_GRKERNSEC_VM86
23565+ if (!capable(CAP_SYS_RAWIO)) {
23566+ gr_handle_vm86();
23567+ return -EPERM;
23568+ }
23569+#endif
23570+
23571 tsk = current;
23572 switch (cmd) {
23573 case VM86_REQUEST_IRQ:
23574@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23575 tsk->thread.saved_fs = info->regs32->fs;
23576 tsk->thread.saved_gs = get_user_gs(info->regs32);
23577
23578- tss = &per_cpu(init_tss, get_cpu());
23579+ tss = init_tss + get_cpu();
23580 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23581 if (cpu_has_sep)
23582 tsk->thread.sysenter_cs = 0;
23583@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23584 goto cannot_handle;
23585 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23586 goto cannot_handle;
23587- intr_ptr = (unsigned long __user *) (i << 2);
23588+ intr_ptr = (__force unsigned long __user *) (i << 2);
23589 if (get_user(segoffs, intr_ptr))
23590 goto cannot_handle;
23591 if ((segoffs >> 16) == BIOSSEG)
23592diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23593index 10c4f30..57377c2 100644
23594--- a/arch/x86/kernel/vmlinux.lds.S
23595+++ b/arch/x86/kernel/vmlinux.lds.S
23596@@ -26,6 +26,13 @@
23597 #include <asm/page_types.h>
23598 #include <asm/cache.h>
23599 #include <asm/boot.h>
23600+#include <asm/segment.h>
23601+
23602+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23603+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23604+#else
23605+#define __KERNEL_TEXT_OFFSET 0
23606+#endif
23607
23608 #undef i386 /* in case the preprocessor is a 32bit one */
23609
23610@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23611
23612 PHDRS {
23613 text PT_LOAD FLAGS(5); /* R_E */
23614+#ifdef CONFIG_X86_32
23615+ module PT_LOAD FLAGS(5); /* R_E */
23616+#endif
23617+#ifdef CONFIG_XEN
23618+ rodata PT_LOAD FLAGS(5); /* R_E */
23619+#else
23620+ rodata PT_LOAD FLAGS(4); /* R__ */
23621+#endif
23622 data PT_LOAD FLAGS(6); /* RW_ */
23623-#ifdef CONFIG_X86_64
23624+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23625 #ifdef CONFIG_SMP
23626 percpu PT_LOAD FLAGS(6); /* RW_ */
23627 #endif
23628+ text.init PT_LOAD FLAGS(5); /* R_E */
23629+ text.exit PT_LOAD FLAGS(5); /* R_E */
23630 init PT_LOAD FLAGS(7); /* RWE */
23631-#endif
23632 note PT_NOTE FLAGS(0); /* ___ */
23633 }
23634
23635 SECTIONS
23636 {
23637 #ifdef CONFIG_X86_32
23638- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23639- phys_startup_32 = startup_32 - LOAD_OFFSET;
23640+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23641 #else
23642- . = __START_KERNEL;
23643- phys_startup_64 = startup_64 - LOAD_OFFSET;
23644+ . = __START_KERNEL;
23645 #endif
23646
23647 /* Text and read-only data */
23648- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23649- _text = .;
23650+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23651 /* bootstrapping code */
23652+#ifdef CONFIG_X86_32
23653+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23654+#else
23655+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23656+#endif
23657+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23658+ _text = .;
23659 HEAD_TEXT
23660 . = ALIGN(8);
23661 _stext = .;
23662@@ -104,13 +124,48 @@ SECTIONS
23663 IRQENTRY_TEXT
23664 *(.fixup)
23665 *(.gnu.warning)
23666- /* End of text section */
23667- _etext = .;
23668 } :text = 0x9090
23669
23670- NOTES :text :note
23671+ . += __KERNEL_TEXT_OFFSET;
23672
23673- EXCEPTION_TABLE(16) :text = 0x9090
23674+#ifdef CONFIG_X86_32
23675+ . = ALIGN(PAGE_SIZE);
23676+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23677+
23678+#ifdef CONFIG_PAX_KERNEXEC
23679+ MODULES_EXEC_VADDR = .;
23680+ BYTE(0)
23681+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23682+ . = ALIGN(HPAGE_SIZE) - 1;
23683+ MODULES_EXEC_END = .;
23684+#endif
23685+
23686+ } :module
23687+#endif
23688+
23689+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23690+ /* End of text section */
23691+ BYTE(0)
23692+ _etext = . - __KERNEL_TEXT_OFFSET;
23693+ }
23694+
23695+#ifdef CONFIG_X86_32
23696+ . = ALIGN(PAGE_SIZE);
23697+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23698+ *(.idt)
23699+ . = ALIGN(PAGE_SIZE);
23700+ *(.empty_zero_page)
23701+ *(.initial_pg_fixmap)
23702+ *(.initial_pg_pmd)
23703+ *(.initial_page_table)
23704+ *(.swapper_pg_dir)
23705+ } :rodata
23706+#endif
23707+
23708+ . = ALIGN(PAGE_SIZE);
23709+ NOTES :rodata :note
23710+
23711+ EXCEPTION_TABLE(16) :rodata
23712
23713 #if defined(CONFIG_DEBUG_RODATA)
23714 /* .text should occupy whole number of pages */
23715@@ -122,16 +177,20 @@ SECTIONS
23716
23717 /* Data */
23718 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23719+
23720+#ifdef CONFIG_PAX_KERNEXEC
23721+ . = ALIGN(HPAGE_SIZE);
23722+#else
23723+ . = ALIGN(PAGE_SIZE);
23724+#endif
23725+
23726 /* Start of data section */
23727 _sdata = .;
23728
23729 /* init_task */
23730 INIT_TASK_DATA(THREAD_SIZE)
23731
23732-#ifdef CONFIG_X86_32
23733- /* 32 bit has nosave before _edata */
23734 NOSAVE_DATA
23735-#endif
23736
23737 PAGE_ALIGNED_DATA(PAGE_SIZE)
23738
23739@@ -172,12 +231,19 @@ SECTIONS
23740 #endif /* CONFIG_X86_64 */
23741
23742 /* Init code and data - will be freed after init */
23743- . = ALIGN(PAGE_SIZE);
23744 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23745+ BYTE(0)
23746+
23747+#ifdef CONFIG_PAX_KERNEXEC
23748+ . = ALIGN(HPAGE_SIZE);
23749+#else
23750+ . = ALIGN(PAGE_SIZE);
23751+#endif
23752+
23753 __init_begin = .; /* paired with __init_end */
23754- }
23755+ } :init.begin
23756
23757-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23758+#ifdef CONFIG_SMP
23759 /*
23760 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23761 * output PHDR, so the next output section - .init.text - should
23762@@ -186,12 +252,27 @@ SECTIONS
23763 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23764 #endif
23765
23766- INIT_TEXT_SECTION(PAGE_SIZE)
23767-#ifdef CONFIG_X86_64
23768- :init
23769-#endif
23770+ . = ALIGN(PAGE_SIZE);
23771+ init_begin = .;
23772+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23773+ VMLINUX_SYMBOL(_sinittext) = .;
23774+ INIT_TEXT
23775+ VMLINUX_SYMBOL(_einittext) = .;
23776+ . = ALIGN(PAGE_SIZE);
23777+ } :text.init
23778
23779- INIT_DATA_SECTION(16)
23780+ /*
23781+ * .exit.text is discard at runtime, not link time, to deal with
23782+ * references from .altinstructions and .eh_frame
23783+ */
23784+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23785+ EXIT_TEXT
23786+ . = ALIGN(16);
23787+ } :text.exit
23788+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23789+
23790+ . = ALIGN(PAGE_SIZE);
23791+ INIT_DATA_SECTION(16) :init
23792
23793 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23794 __x86_cpu_dev_start = .;
23795@@ -253,19 +334,12 @@ SECTIONS
23796 }
23797
23798 . = ALIGN(8);
23799- /*
23800- * .exit.text is discard at runtime, not link time, to deal with
23801- * references from .altinstructions and .eh_frame
23802- */
23803- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23804- EXIT_TEXT
23805- }
23806
23807 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23808 EXIT_DATA
23809 }
23810
23811-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23812+#ifndef CONFIG_SMP
23813 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23814 #endif
23815
23816@@ -284,16 +358,10 @@ SECTIONS
23817 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23818 __smp_locks = .;
23819 *(.smp_locks)
23820- . = ALIGN(PAGE_SIZE);
23821 __smp_locks_end = .;
23822+ . = ALIGN(PAGE_SIZE);
23823 }
23824
23825-#ifdef CONFIG_X86_64
23826- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23827- NOSAVE_DATA
23828- }
23829-#endif
23830-
23831 /* BSS */
23832 . = ALIGN(PAGE_SIZE);
23833 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23834@@ -309,6 +377,7 @@ SECTIONS
23835 __brk_base = .;
23836 . += 64 * 1024; /* 64k alignment slop space */
23837 *(.brk_reservation) /* areas brk users have reserved */
23838+ . = ALIGN(HPAGE_SIZE);
23839 __brk_limit = .;
23840 }
23841
23842@@ -335,13 +404,12 @@ SECTIONS
23843 * for the boot processor.
23844 */
23845 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23846-INIT_PER_CPU(gdt_page);
23847 INIT_PER_CPU(irq_stack_union);
23848
23849 /*
23850 * Build-time check on the image size:
23851 */
23852-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23853+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23854 "kernel image bigger than KERNEL_IMAGE_SIZE");
23855
23856 #ifdef CONFIG_SMP
23857diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23858index 9a907a6..f83f921 100644
23859--- a/arch/x86/kernel/vsyscall_64.c
23860+++ b/arch/x86/kernel/vsyscall_64.c
23861@@ -56,15 +56,13 @@
23862 DEFINE_VVAR(int, vgetcpu_mode);
23863 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23864
23865-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23866+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23867
23868 static int __init vsyscall_setup(char *str)
23869 {
23870 if (str) {
23871 if (!strcmp("emulate", str))
23872 vsyscall_mode = EMULATE;
23873- else if (!strcmp("native", str))
23874- vsyscall_mode = NATIVE;
23875 else if (!strcmp("none", str))
23876 vsyscall_mode = NONE;
23877 else
23878@@ -323,8 +321,7 @@ do_ret:
23879 return true;
23880
23881 sigsegv:
23882- force_sig(SIGSEGV, current);
23883- return true;
23884+ do_group_exit(SIGKILL);
23885 }
23886
23887 /*
23888@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23889 extern char __vvar_page;
23890 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23891
23892- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23893- vsyscall_mode == NATIVE
23894- ? PAGE_KERNEL_VSYSCALL
23895- : PAGE_KERNEL_VVAR);
23896+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23897 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23898 (unsigned long)VSYSCALL_START);
23899
23900diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23901index b014d94..6d6ca7b 100644
23902--- a/arch/x86/kernel/x8664_ksyms_64.c
23903+++ b/arch/x86/kernel/x8664_ksyms_64.c
23904@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23905 EXPORT_SYMBOL(copy_user_generic_unrolled);
23906 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23907 EXPORT_SYMBOL(__copy_user_nocache);
23908-EXPORT_SYMBOL(_copy_from_user);
23909-EXPORT_SYMBOL(_copy_to_user);
23910
23911 EXPORT_SYMBOL(copy_page);
23912 EXPORT_SYMBOL(clear_page);
23913diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23914index 45a14db..075bb9b 100644
23915--- a/arch/x86/kernel/x86_init.c
23916+++ b/arch/x86/kernel/x86_init.c
23917@@ -85,7 +85,7 @@ struct x86_init_ops x86_init __initdata = {
23918 },
23919 };
23920
23921-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23922+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23923 .early_percpu_clock_init = x86_init_noop,
23924 .setup_percpu_clockev = setup_secondary_APIC_clock,
23925 };
23926@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23927 static void default_nmi_init(void) { };
23928 static int default_i8042_detect(void) { return 1; };
23929
23930-struct x86_platform_ops x86_platform = {
23931+struct x86_platform_ops x86_platform __read_only = {
23932 .calibrate_tsc = native_calibrate_tsc,
23933 .get_wallclock = mach_get_cmos_time,
23934 .set_wallclock = mach_set_rtc_mmss,
23935@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
23936 };
23937
23938 EXPORT_SYMBOL_GPL(x86_platform);
23939-struct x86_msi_ops x86_msi = {
23940+struct x86_msi_ops x86_msi __read_only = {
23941 .setup_msi_irqs = native_setup_msi_irqs,
23942 .compose_msi_msg = native_compose_msi_msg,
23943 .teardown_msi_irq = native_teardown_msi_irq,
23944@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
23945 .setup_hpet_msi = default_setup_hpet_msi,
23946 };
23947
23948-struct x86_io_apic_ops x86_io_apic_ops = {
23949+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23950 .init = native_io_apic_init_mappings,
23951 .read = native_io_apic_read,
23952 .write = native_io_apic_write,
23953diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23954index ada87a3..afea76d 100644
23955--- a/arch/x86/kernel/xsave.c
23956+++ b/arch/x86/kernel/xsave.c
23957@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23958 {
23959 int err;
23960
23961+ buf = (struct xsave_struct __user *)____m(buf);
23962 if (use_xsave())
23963 err = xsave_user(buf);
23964 else if (use_fxsr())
23965@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23966 */
23967 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23968 {
23969+ buf = (void __user *)____m(buf);
23970 if (use_xsave()) {
23971 if ((unsigned long)buf % 64 || fx_only) {
23972 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23973diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23974index a20ecb5..d0e2194 100644
23975--- a/arch/x86/kvm/cpuid.c
23976+++ b/arch/x86/kvm/cpuid.c
23977@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23978 struct kvm_cpuid2 *cpuid,
23979 struct kvm_cpuid_entry2 __user *entries)
23980 {
23981- int r;
23982+ int r, i;
23983
23984 r = -E2BIG;
23985 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23986 goto out;
23987 r = -EFAULT;
23988- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23989- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23990+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23991 goto out;
23992+ for (i = 0; i < cpuid->nent; ++i) {
23993+ struct kvm_cpuid_entry2 cpuid_entry;
23994+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23995+ goto out;
23996+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23997+ }
23998 vcpu->arch.cpuid_nent = cpuid->nent;
23999 kvm_apic_set_version(vcpu);
24000 kvm_x86_ops->cpuid_update(vcpu);
24001@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
24002 struct kvm_cpuid2 *cpuid,
24003 struct kvm_cpuid_entry2 __user *entries)
24004 {
24005- int r;
24006+ int r, i;
24007
24008 r = -E2BIG;
24009 if (cpuid->nent < vcpu->arch.cpuid_nent)
24010 goto out;
24011 r = -EFAULT;
24012- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
24013- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24014+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24015 goto out;
24016+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
24017+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
24018+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
24019+ goto out;
24020+ }
24021 return 0;
24022
24023 out:
24024diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
24025index 5953dce..f11a7d2 100644
24026--- a/arch/x86/kvm/emulate.c
24027+++ b/arch/x86/kvm/emulate.c
24028@@ -329,6 +329,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24029
24030 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
24031 do { \
24032+ unsigned long _tmp; \
24033 __asm__ __volatile__ ( \
24034 _PRE_EFLAGS("0", "4", "2") \
24035 _op _suffix " %"_x"3,%1; " \
24036@@ -343,8 +344,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24037 /* Raw emulation: instruction has two explicit operands. */
24038 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
24039 do { \
24040- unsigned long _tmp; \
24041- \
24042 switch ((ctxt)->dst.bytes) { \
24043 case 2: \
24044 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
24045@@ -360,7 +359,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24046
24047 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
24048 do { \
24049- unsigned long _tmp; \
24050 switch ((ctxt)->dst.bytes) { \
24051 case 1: \
24052 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
24053diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
24054index 0eee2c8..94a32c3 100644
24055--- a/arch/x86/kvm/lapic.c
24056+++ b/arch/x86/kvm/lapic.c
24057@@ -55,7 +55,7 @@
24058 #define APIC_BUS_CYCLE_NS 1
24059
24060 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
24061-#define apic_debug(fmt, arg...)
24062+#define apic_debug(fmt, arg...) do {} while (0)
24063
24064 #define APIC_LVT_NUM 6
24065 /* 14 is the version for Xeon and Pentium 8.4.8*/
24066diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
24067index da20860..d19fdf5 100644
24068--- a/arch/x86/kvm/paging_tmpl.h
24069+++ b/arch/x86/kvm/paging_tmpl.h
24070@@ -208,7 +208,7 @@ retry_walk:
24071 if (unlikely(kvm_is_error_hva(host_addr)))
24072 goto error;
24073
24074- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
24075+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
24076 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
24077 goto error;
24078 walker->ptep_user[walker->level - 1] = ptep_user;
24079diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
24080index a14a6ea..dc86cf0 100644
24081--- a/arch/x86/kvm/svm.c
24082+++ b/arch/x86/kvm/svm.c
24083@@ -3493,7 +3493,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
24084 int cpu = raw_smp_processor_id();
24085
24086 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
24087+
24088+ pax_open_kernel();
24089 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
24090+ pax_close_kernel();
24091+
24092 load_TR_desc();
24093 }
24094
24095@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
24096 #endif
24097 #endif
24098
24099+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24100+ __set_fs(current_thread_info()->addr_limit);
24101+#endif
24102+
24103 reload_tss(vcpu);
24104
24105 local_irq_disable();
24106diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
24107index 5402c94..c3bdeee 100644
24108--- a/arch/x86/kvm/vmx.c
24109+++ b/arch/x86/kvm/vmx.c
24110@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
24111 #endif
24112 }
24113
24114-static void vmcs_clear_bits(unsigned long field, u32 mask)
24115+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
24116 {
24117 vmcs_writel(field, vmcs_readl(field) & ~mask);
24118 }
24119
24120-static void vmcs_set_bits(unsigned long field, u32 mask)
24121+static void vmcs_set_bits(unsigned long field, unsigned long mask)
24122 {
24123 vmcs_writel(field, vmcs_readl(field) | mask);
24124 }
24125@@ -1517,7 +1517,11 @@ static void reload_tss(void)
24126 struct desc_struct *descs;
24127
24128 descs = (void *)gdt->address;
24129+
24130+ pax_open_kernel();
24131 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
24132+ pax_close_kernel();
24133+
24134 load_TR_desc();
24135 }
24136
24137@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
24138 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
24139 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
24140
24141+#ifdef CONFIG_PAX_PER_CPU_PGD
24142+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24143+#endif
24144+
24145 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
24146 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
24147 vmx->loaded_vmcs->cpu = cpu;
24148@@ -2935,8 +2943,11 @@ static __init int hardware_setup(void)
24149 if (!cpu_has_vmx_flexpriority())
24150 flexpriority_enabled = 0;
24151
24152- if (!cpu_has_vmx_tpr_shadow())
24153- kvm_x86_ops->update_cr8_intercept = NULL;
24154+ if (!cpu_has_vmx_tpr_shadow()) {
24155+ pax_open_kernel();
24156+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24157+ pax_close_kernel();
24158+ }
24159
24160 if (enable_ept && !cpu_has_vmx_ept_2m_page())
24161 kvm_disable_largepages();
24162@@ -2947,13 +2958,15 @@ static __init int hardware_setup(void)
24163 if (!cpu_has_vmx_apicv())
24164 enable_apicv = 0;
24165
24166+ pax_open_kernel();
24167 if (enable_apicv)
24168- kvm_x86_ops->update_cr8_intercept = NULL;
24169+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24170 else {
24171- kvm_x86_ops->hwapic_irr_update = NULL;
24172- kvm_x86_ops->deliver_posted_interrupt = NULL;
24173- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
24174+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
24175+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
24176+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
24177 }
24178+ pax_close_kernel();
24179
24180 if (nested)
24181 nested_vmx_setup_ctls_msrs();
24182@@ -4076,7 +4089,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
24183
24184 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
24185 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
24186+
24187+#ifndef CONFIG_PAX_PER_CPU_PGD
24188 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24189+#endif
24190
24191 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
24192 #ifdef CONFIG_X86_64
24193@@ -4098,7 +4114,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
24194 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
24195 vmx->host_idt_base = dt.address;
24196
24197- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
24198+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
24199
24200 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
24201 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
24202@@ -7030,6 +7046,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24203 "jmp 2f \n\t"
24204 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
24205 "2: "
24206+
24207+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24208+ "ljmp %[cs],$3f\n\t"
24209+ "3: "
24210+#endif
24211+
24212 /* Save guest registers, load host registers, keep flags */
24213 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
24214 "pop %0 \n\t"
24215@@ -7082,6 +7104,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24216 #endif
24217 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
24218 [wordsize]"i"(sizeof(ulong))
24219+
24220+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24221+ ,[cs]"i"(__KERNEL_CS)
24222+#endif
24223+
24224 : "cc", "memory"
24225 #ifdef CONFIG_X86_64
24226 , "rax", "rbx", "rdi", "rsi"
24227@@ -7095,7 +7122,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24228 if (debugctlmsr)
24229 update_debugctlmsr(debugctlmsr);
24230
24231-#ifndef CONFIG_X86_64
24232+#ifdef CONFIG_X86_32
24233 /*
24234 * The sysexit path does not restore ds/es, so we must set them to
24235 * a reasonable value ourselves.
24236@@ -7104,8 +7131,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24237 * may be executed in interrupt context, which saves and restore segments
24238 * around it, nullifying its effect.
24239 */
24240- loadsegment(ds, __USER_DS);
24241- loadsegment(es, __USER_DS);
24242+ loadsegment(ds, __KERNEL_DS);
24243+ loadsegment(es, __KERNEL_DS);
24244+ loadsegment(ss, __KERNEL_DS);
24245+
24246+#ifdef CONFIG_PAX_KERNEXEC
24247+ loadsegment(fs, __KERNEL_PERCPU);
24248+#endif
24249+
24250+#ifdef CONFIG_PAX_MEMORY_UDEREF
24251+ __set_fs(current_thread_info()->addr_limit);
24252+#endif
24253+
24254 #endif
24255
24256 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24257diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24258index e8ba99c..ee9d7d9 100644
24259--- a/arch/x86/kvm/x86.c
24260+++ b/arch/x86/kvm/x86.c
24261@@ -1725,8 +1725,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24262 {
24263 struct kvm *kvm = vcpu->kvm;
24264 int lm = is_long_mode(vcpu);
24265- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24266- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24267+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24268+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24269 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24270 : kvm->arch.xen_hvm_config.blob_size_32;
24271 u32 page_num = data & ~PAGE_MASK;
24272@@ -2609,6 +2609,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24273 if (n < msr_list.nmsrs)
24274 goto out;
24275 r = -EFAULT;
24276+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24277+ goto out;
24278 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24279 num_msrs_to_save * sizeof(u32)))
24280 goto out;
24281@@ -5297,7 +5299,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24282 };
24283 #endif
24284
24285-int kvm_arch_init(void *opaque)
24286+int kvm_arch_init(const void *opaque)
24287 {
24288 int r;
24289 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24290diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24291index 7114c63..a1018fc 100644
24292--- a/arch/x86/lguest/boot.c
24293+++ b/arch/x86/lguest/boot.c
24294@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24295 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24296 * Launcher to reboot us.
24297 */
24298-static void lguest_restart(char *reason)
24299+static __noreturn void lguest_restart(char *reason)
24300 {
24301 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24302+ BUG();
24303 }
24304
24305 /*G:050
24306diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24307index 00933d5..3a64af9 100644
24308--- a/arch/x86/lib/atomic64_386_32.S
24309+++ b/arch/x86/lib/atomic64_386_32.S
24310@@ -48,6 +48,10 @@ BEGIN(read)
24311 movl (v), %eax
24312 movl 4(v), %edx
24313 RET_ENDP
24314+BEGIN(read_unchecked)
24315+ movl (v), %eax
24316+ movl 4(v), %edx
24317+RET_ENDP
24318 #undef v
24319
24320 #define v %esi
24321@@ -55,6 +59,10 @@ BEGIN(set)
24322 movl %ebx, (v)
24323 movl %ecx, 4(v)
24324 RET_ENDP
24325+BEGIN(set_unchecked)
24326+ movl %ebx, (v)
24327+ movl %ecx, 4(v)
24328+RET_ENDP
24329 #undef v
24330
24331 #define v %esi
24332@@ -70,6 +78,20 @@ RET_ENDP
24333 BEGIN(add)
24334 addl %eax, (v)
24335 adcl %edx, 4(v)
24336+
24337+#ifdef CONFIG_PAX_REFCOUNT
24338+ jno 0f
24339+ subl %eax, (v)
24340+ sbbl %edx, 4(v)
24341+ int $4
24342+0:
24343+ _ASM_EXTABLE(0b, 0b)
24344+#endif
24345+
24346+RET_ENDP
24347+BEGIN(add_unchecked)
24348+ addl %eax, (v)
24349+ adcl %edx, 4(v)
24350 RET_ENDP
24351 #undef v
24352
24353@@ -77,6 +99,24 @@ RET_ENDP
24354 BEGIN(add_return)
24355 addl (v), %eax
24356 adcl 4(v), %edx
24357+
24358+#ifdef CONFIG_PAX_REFCOUNT
24359+ into
24360+1234:
24361+ _ASM_EXTABLE(1234b, 2f)
24362+#endif
24363+
24364+ movl %eax, (v)
24365+ movl %edx, 4(v)
24366+
24367+#ifdef CONFIG_PAX_REFCOUNT
24368+2:
24369+#endif
24370+
24371+RET_ENDP
24372+BEGIN(add_return_unchecked)
24373+ addl (v), %eax
24374+ adcl 4(v), %edx
24375 movl %eax, (v)
24376 movl %edx, 4(v)
24377 RET_ENDP
24378@@ -86,6 +126,20 @@ RET_ENDP
24379 BEGIN(sub)
24380 subl %eax, (v)
24381 sbbl %edx, 4(v)
24382+
24383+#ifdef CONFIG_PAX_REFCOUNT
24384+ jno 0f
24385+ addl %eax, (v)
24386+ adcl %edx, 4(v)
24387+ int $4
24388+0:
24389+ _ASM_EXTABLE(0b, 0b)
24390+#endif
24391+
24392+RET_ENDP
24393+BEGIN(sub_unchecked)
24394+ subl %eax, (v)
24395+ sbbl %edx, 4(v)
24396 RET_ENDP
24397 #undef v
24398
24399@@ -96,6 +150,27 @@ BEGIN(sub_return)
24400 sbbl $0, %edx
24401 addl (v), %eax
24402 adcl 4(v), %edx
24403+
24404+#ifdef CONFIG_PAX_REFCOUNT
24405+ into
24406+1234:
24407+ _ASM_EXTABLE(1234b, 2f)
24408+#endif
24409+
24410+ movl %eax, (v)
24411+ movl %edx, 4(v)
24412+
24413+#ifdef CONFIG_PAX_REFCOUNT
24414+2:
24415+#endif
24416+
24417+RET_ENDP
24418+BEGIN(sub_return_unchecked)
24419+ negl %edx
24420+ negl %eax
24421+ sbbl $0, %edx
24422+ addl (v), %eax
24423+ adcl 4(v), %edx
24424 movl %eax, (v)
24425 movl %edx, 4(v)
24426 RET_ENDP
24427@@ -105,6 +180,20 @@ RET_ENDP
24428 BEGIN(inc)
24429 addl $1, (v)
24430 adcl $0, 4(v)
24431+
24432+#ifdef CONFIG_PAX_REFCOUNT
24433+ jno 0f
24434+ subl $1, (v)
24435+ sbbl $0, 4(v)
24436+ int $4
24437+0:
24438+ _ASM_EXTABLE(0b, 0b)
24439+#endif
24440+
24441+RET_ENDP
24442+BEGIN(inc_unchecked)
24443+ addl $1, (v)
24444+ adcl $0, 4(v)
24445 RET_ENDP
24446 #undef v
24447
24448@@ -114,6 +203,26 @@ BEGIN(inc_return)
24449 movl 4(v), %edx
24450 addl $1, %eax
24451 adcl $0, %edx
24452+
24453+#ifdef CONFIG_PAX_REFCOUNT
24454+ into
24455+1234:
24456+ _ASM_EXTABLE(1234b, 2f)
24457+#endif
24458+
24459+ movl %eax, (v)
24460+ movl %edx, 4(v)
24461+
24462+#ifdef CONFIG_PAX_REFCOUNT
24463+2:
24464+#endif
24465+
24466+RET_ENDP
24467+BEGIN(inc_return_unchecked)
24468+ movl (v), %eax
24469+ movl 4(v), %edx
24470+ addl $1, %eax
24471+ adcl $0, %edx
24472 movl %eax, (v)
24473 movl %edx, 4(v)
24474 RET_ENDP
24475@@ -123,6 +232,20 @@ RET_ENDP
24476 BEGIN(dec)
24477 subl $1, (v)
24478 sbbl $0, 4(v)
24479+
24480+#ifdef CONFIG_PAX_REFCOUNT
24481+ jno 0f
24482+ addl $1, (v)
24483+ adcl $0, 4(v)
24484+ int $4
24485+0:
24486+ _ASM_EXTABLE(0b, 0b)
24487+#endif
24488+
24489+RET_ENDP
24490+BEGIN(dec_unchecked)
24491+ subl $1, (v)
24492+ sbbl $0, 4(v)
24493 RET_ENDP
24494 #undef v
24495
24496@@ -132,6 +255,26 @@ BEGIN(dec_return)
24497 movl 4(v), %edx
24498 subl $1, %eax
24499 sbbl $0, %edx
24500+
24501+#ifdef CONFIG_PAX_REFCOUNT
24502+ into
24503+1234:
24504+ _ASM_EXTABLE(1234b, 2f)
24505+#endif
24506+
24507+ movl %eax, (v)
24508+ movl %edx, 4(v)
24509+
24510+#ifdef CONFIG_PAX_REFCOUNT
24511+2:
24512+#endif
24513+
24514+RET_ENDP
24515+BEGIN(dec_return_unchecked)
24516+ movl (v), %eax
24517+ movl 4(v), %edx
24518+ subl $1, %eax
24519+ sbbl $0, %edx
24520 movl %eax, (v)
24521 movl %edx, 4(v)
24522 RET_ENDP
24523@@ -143,6 +286,13 @@ BEGIN(add_unless)
24524 adcl %edx, %edi
24525 addl (v), %eax
24526 adcl 4(v), %edx
24527+
24528+#ifdef CONFIG_PAX_REFCOUNT
24529+ into
24530+1234:
24531+ _ASM_EXTABLE(1234b, 2f)
24532+#endif
24533+
24534 cmpl %eax, %ecx
24535 je 3f
24536 1:
24537@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24538 1:
24539 addl $1, %eax
24540 adcl $0, %edx
24541+
24542+#ifdef CONFIG_PAX_REFCOUNT
24543+ into
24544+1234:
24545+ _ASM_EXTABLE(1234b, 2f)
24546+#endif
24547+
24548 movl %eax, (v)
24549 movl %edx, 4(v)
24550 movl $1, %eax
24551@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24552 movl 4(v), %edx
24553 subl $1, %eax
24554 sbbl $0, %edx
24555+
24556+#ifdef CONFIG_PAX_REFCOUNT
24557+ into
24558+1234:
24559+ _ASM_EXTABLE(1234b, 1f)
24560+#endif
24561+
24562 js 1f
24563 movl %eax, (v)
24564 movl %edx, 4(v)
24565diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24566index f5cc9eb..51fa319 100644
24567--- a/arch/x86/lib/atomic64_cx8_32.S
24568+++ b/arch/x86/lib/atomic64_cx8_32.S
24569@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24570 CFI_STARTPROC
24571
24572 read64 %ecx
24573+ pax_force_retaddr
24574 ret
24575 CFI_ENDPROC
24576 ENDPROC(atomic64_read_cx8)
24577
24578+ENTRY(atomic64_read_unchecked_cx8)
24579+ CFI_STARTPROC
24580+
24581+ read64 %ecx
24582+ pax_force_retaddr
24583+ ret
24584+ CFI_ENDPROC
24585+ENDPROC(atomic64_read_unchecked_cx8)
24586+
24587 ENTRY(atomic64_set_cx8)
24588 CFI_STARTPROC
24589
24590@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24591 cmpxchg8b (%esi)
24592 jne 1b
24593
24594+ pax_force_retaddr
24595 ret
24596 CFI_ENDPROC
24597 ENDPROC(atomic64_set_cx8)
24598
24599+ENTRY(atomic64_set_unchecked_cx8)
24600+ CFI_STARTPROC
24601+
24602+1:
24603+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24604+ * are atomic on 586 and newer */
24605+ cmpxchg8b (%esi)
24606+ jne 1b
24607+
24608+ pax_force_retaddr
24609+ ret
24610+ CFI_ENDPROC
24611+ENDPROC(atomic64_set_unchecked_cx8)
24612+
24613 ENTRY(atomic64_xchg_cx8)
24614 CFI_STARTPROC
24615
24616@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24617 cmpxchg8b (%esi)
24618 jne 1b
24619
24620+ pax_force_retaddr
24621 ret
24622 CFI_ENDPROC
24623 ENDPROC(atomic64_xchg_cx8)
24624
24625-.macro addsub_return func ins insc
24626-ENTRY(atomic64_\func\()_return_cx8)
24627+.macro addsub_return func ins insc unchecked=""
24628+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24629 CFI_STARTPROC
24630 SAVE ebp
24631 SAVE ebx
24632@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24633 movl %edx, %ecx
24634 \ins\()l %esi, %ebx
24635 \insc\()l %edi, %ecx
24636+
24637+.ifb \unchecked
24638+#ifdef CONFIG_PAX_REFCOUNT
24639+ into
24640+2:
24641+ _ASM_EXTABLE(2b, 3f)
24642+#endif
24643+.endif
24644+
24645 LOCK_PREFIX
24646 cmpxchg8b (%ebp)
24647 jne 1b
24648-
24649-10:
24650 movl %ebx, %eax
24651 movl %ecx, %edx
24652+
24653+.ifb \unchecked
24654+#ifdef CONFIG_PAX_REFCOUNT
24655+3:
24656+#endif
24657+.endif
24658+
24659 RESTORE edi
24660 RESTORE esi
24661 RESTORE ebx
24662 RESTORE ebp
24663+ pax_force_retaddr
24664 ret
24665 CFI_ENDPROC
24666-ENDPROC(atomic64_\func\()_return_cx8)
24667+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24668 .endm
24669
24670 addsub_return add add adc
24671 addsub_return sub sub sbb
24672+addsub_return add add adc _unchecked
24673+addsub_return sub sub sbb _unchecked
24674
24675-.macro incdec_return func ins insc
24676-ENTRY(atomic64_\func\()_return_cx8)
24677+.macro incdec_return func ins insc unchecked=""
24678+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24679 CFI_STARTPROC
24680 SAVE ebx
24681
24682@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24683 movl %edx, %ecx
24684 \ins\()l $1, %ebx
24685 \insc\()l $0, %ecx
24686+
24687+.ifb \unchecked
24688+#ifdef CONFIG_PAX_REFCOUNT
24689+ into
24690+2:
24691+ _ASM_EXTABLE(2b, 3f)
24692+#endif
24693+.endif
24694+
24695 LOCK_PREFIX
24696 cmpxchg8b (%esi)
24697 jne 1b
24698
24699-10:
24700 movl %ebx, %eax
24701 movl %ecx, %edx
24702+
24703+.ifb \unchecked
24704+#ifdef CONFIG_PAX_REFCOUNT
24705+3:
24706+#endif
24707+.endif
24708+
24709 RESTORE ebx
24710+ pax_force_retaddr
24711 ret
24712 CFI_ENDPROC
24713-ENDPROC(atomic64_\func\()_return_cx8)
24714+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24715 .endm
24716
24717 incdec_return inc add adc
24718 incdec_return dec sub sbb
24719+incdec_return inc add adc _unchecked
24720+incdec_return dec sub sbb _unchecked
24721
24722 ENTRY(atomic64_dec_if_positive_cx8)
24723 CFI_STARTPROC
24724@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24725 movl %edx, %ecx
24726 subl $1, %ebx
24727 sbb $0, %ecx
24728+
24729+#ifdef CONFIG_PAX_REFCOUNT
24730+ into
24731+1234:
24732+ _ASM_EXTABLE(1234b, 2f)
24733+#endif
24734+
24735 js 2f
24736 LOCK_PREFIX
24737 cmpxchg8b (%esi)
24738@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24739 movl %ebx, %eax
24740 movl %ecx, %edx
24741 RESTORE ebx
24742+ pax_force_retaddr
24743 ret
24744 CFI_ENDPROC
24745 ENDPROC(atomic64_dec_if_positive_cx8)
24746@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24747 movl %edx, %ecx
24748 addl %ebp, %ebx
24749 adcl %edi, %ecx
24750+
24751+#ifdef CONFIG_PAX_REFCOUNT
24752+ into
24753+1234:
24754+ _ASM_EXTABLE(1234b, 3f)
24755+#endif
24756+
24757 LOCK_PREFIX
24758 cmpxchg8b (%esi)
24759 jne 1b
24760@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24761 CFI_ADJUST_CFA_OFFSET -8
24762 RESTORE ebx
24763 RESTORE ebp
24764+ pax_force_retaddr
24765 ret
24766 4:
24767 cmpl %edx, 4(%esp)
24768@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24769 xorl %ecx, %ecx
24770 addl $1, %ebx
24771 adcl %edx, %ecx
24772+
24773+#ifdef CONFIG_PAX_REFCOUNT
24774+ into
24775+1234:
24776+ _ASM_EXTABLE(1234b, 3f)
24777+#endif
24778+
24779 LOCK_PREFIX
24780 cmpxchg8b (%esi)
24781 jne 1b
24782@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24783 movl $1, %eax
24784 3:
24785 RESTORE ebx
24786+ pax_force_retaddr
24787 ret
24788 CFI_ENDPROC
24789 ENDPROC(atomic64_inc_not_zero_cx8)
24790diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24791index e78b8ee..7e173a8 100644
24792--- a/arch/x86/lib/checksum_32.S
24793+++ b/arch/x86/lib/checksum_32.S
24794@@ -29,7 +29,8 @@
24795 #include <asm/dwarf2.h>
24796 #include <asm/errno.h>
24797 #include <asm/asm.h>
24798-
24799+#include <asm/segment.h>
24800+
24801 /*
24802 * computes a partial checksum, e.g. for TCP/UDP fragments
24803 */
24804@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24805
24806 #define ARGBASE 16
24807 #define FP 12
24808-
24809-ENTRY(csum_partial_copy_generic)
24810+
24811+ENTRY(csum_partial_copy_generic_to_user)
24812 CFI_STARTPROC
24813+
24814+#ifdef CONFIG_PAX_MEMORY_UDEREF
24815+ pushl_cfi %gs
24816+ popl_cfi %es
24817+ jmp csum_partial_copy_generic
24818+#endif
24819+
24820+ENTRY(csum_partial_copy_generic_from_user)
24821+
24822+#ifdef CONFIG_PAX_MEMORY_UDEREF
24823+ pushl_cfi %gs
24824+ popl_cfi %ds
24825+#endif
24826+
24827+ENTRY(csum_partial_copy_generic)
24828 subl $4,%esp
24829 CFI_ADJUST_CFA_OFFSET 4
24830 pushl_cfi %edi
24831@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24832 jmp 4f
24833 SRC(1: movw (%esi), %bx )
24834 addl $2, %esi
24835-DST( movw %bx, (%edi) )
24836+DST( movw %bx, %es:(%edi) )
24837 addl $2, %edi
24838 addw %bx, %ax
24839 adcl $0, %eax
24840@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24841 SRC(1: movl (%esi), %ebx )
24842 SRC( movl 4(%esi), %edx )
24843 adcl %ebx, %eax
24844-DST( movl %ebx, (%edi) )
24845+DST( movl %ebx, %es:(%edi) )
24846 adcl %edx, %eax
24847-DST( movl %edx, 4(%edi) )
24848+DST( movl %edx, %es:4(%edi) )
24849
24850 SRC( movl 8(%esi), %ebx )
24851 SRC( movl 12(%esi), %edx )
24852 adcl %ebx, %eax
24853-DST( movl %ebx, 8(%edi) )
24854+DST( movl %ebx, %es:8(%edi) )
24855 adcl %edx, %eax
24856-DST( movl %edx, 12(%edi) )
24857+DST( movl %edx, %es:12(%edi) )
24858
24859 SRC( movl 16(%esi), %ebx )
24860 SRC( movl 20(%esi), %edx )
24861 adcl %ebx, %eax
24862-DST( movl %ebx, 16(%edi) )
24863+DST( movl %ebx, %es:16(%edi) )
24864 adcl %edx, %eax
24865-DST( movl %edx, 20(%edi) )
24866+DST( movl %edx, %es:20(%edi) )
24867
24868 SRC( movl 24(%esi), %ebx )
24869 SRC( movl 28(%esi), %edx )
24870 adcl %ebx, %eax
24871-DST( movl %ebx, 24(%edi) )
24872+DST( movl %ebx, %es:24(%edi) )
24873 adcl %edx, %eax
24874-DST( movl %edx, 28(%edi) )
24875+DST( movl %edx, %es:28(%edi) )
24876
24877 lea 32(%esi), %esi
24878 lea 32(%edi), %edi
24879@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24880 shrl $2, %edx # This clears CF
24881 SRC(3: movl (%esi), %ebx )
24882 adcl %ebx, %eax
24883-DST( movl %ebx, (%edi) )
24884+DST( movl %ebx, %es:(%edi) )
24885 lea 4(%esi), %esi
24886 lea 4(%edi), %edi
24887 dec %edx
24888@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24889 jb 5f
24890 SRC( movw (%esi), %cx )
24891 leal 2(%esi), %esi
24892-DST( movw %cx, (%edi) )
24893+DST( movw %cx, %es:(%edi) )
24894 leal 2(%edi), %edi
24895 je 6f
24896 shll $16,%ecx
24897 SRC(5: movb (%esi), %cl )
24898-DST( movb %cl, (%edi) )
24899+DST( movb %cl, %es:(%edi) )
24900 6: addl %ecx, %eax
24901 adcl $0, %eax
24902 7:
24903@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24904
24905 6001:
24906 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24907- movl $-EFAULT, (%ebx)
24908+ movl $-EFAULT, %ss:(%ebx)
24909
24910 # zero the complete destination - computing the rest
24911 # is too much work
24912@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24913
24914 6002:
24915 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24916- movl $-EFAULT,(%ebx)
24917+ movl $-EFAULT,%ss:(%ebx)
24918 jmp 5000b
24919
24920 .previous
24921
24922+ pushl_cfi %ss
24923+ popl_cfi %ds
24924+ pushl_cfi %ss
24925+ popl_cfi %es
24926 popl_cfi %ebx
24927 CFI_RESTORE ebx
24928 popl_cfi %esi
24929@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24930 popl_cfi %ecx # equivalent to addl $4,%esp
24931 ret
24932 CFI_ENDPROC
24933-ENDPROC(csum_partial_copy_generic)
24934+ENDPROC(csum_partial_copy_generic_to_user)
24935
24936 #else
24937
24938 /* Version for PentiumII/PPro */
24939
24940 #define ROUND1(x) \
24941+ nop; nop; nop; \
24942 SRC(movl x(%esi), %ebx ) ; \
24943 addl %ebx, %eax ; \
24944- DST(movl %ebx, x(%edi) ) ;
24945+ DST(movl %ebx, %es:x(%edi)) ;
24946
24947 #define ROUND(x) \
24948+ nop; nop; nop; \
24949 SRC(movl x(%esi), %ebx ) ; \
24950 adcl %ebx, %eax ; \
24951- DST(movl %ebx, x(%edi) ) ;
24952+ DST(movl %ebx, %es:x(%edi)) ;
24953
24954 #define ARGBASE 12
24955-
24956-ENTRY(csum_partial_copy_generic)
24957+
24958+ENTRY(csum_partial_copy_generic_to_user)
24959 CFI_STARTPROC
24960+
24961+#ifdef CONFIG_PAX_MEMORY_UDEREF
24962+ pushl_cfi %gs
24963+ popl_cfi %es
24964+ jmp csum_partial_copy_generic
24965+#endif
24966+
24967+ENTRY(csum_partial_copy_generic_from_user)
24968+
24969+#ifdef CONFIG_PAX_MEMORY_UDEREF
24970+ pushl_cfi %gs
24971+ popl_cfi %ds
24972+#endif
24973+
24974+ENTRY(csum_partial_copy_generic)
24975 pushl_cfi %ebx
24976 CFI_REL_OFFSET ebx, 0
24977 pushl_cfi %edi
24978@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24979 subl %ebx, %edi
24980 lea -1(%esi),%edx
24981 andl $-32,%edx
24982- lea 3f(%ebx,%ebx), %ebx
24983+ lea 3f(%ebx,%ebx,2), %ebx
24984 testl %esi, %esi
24985 jmp *%ebx
24986 1: addl $64,%esi
24987@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24988 jb 5f
24989 SRC( movw (%esi), %dx )
24990 leal 2(%esi), %esi
24991-DST( movw %dx, (%edi) )
24992+DST( movw %dx, %es:(%edi) )
24993 leal 2(%edi), %edi
24994 je 6f
24995 shll $16,%edx
24996 5:
24997 SRC( movb (%esi), %dl )
24998-DST( movb %dl, (%edi) )
24999+DST( movb %dl, %es:(%edi) )
25000 6: addl %edx, %eax
25001 adcl $0, %eax
25002 7:
25003 .section .fixup, "ax"
25004 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
25005- movl $-EFAULT, (%ebx)
25006+ movl $-EFAULT, %ss:(%ebx)
25007 # zero the complete destination (computing the rest is too much work)
25008 movl ARGBASE+8(%esp),%edi # dst
25009 movl ARGBASE+12(%esp),%ecx # len
25010@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
25011 rep; stosb
25012 jmp 7b
25013 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25014- movl $-EFAULT, (%ebx)
25015+ movl $-EFAULT, %ss:(%ebx)
25016 jmp 7b
25017 .previous
25018
25019+#ifdef CONFIG_PAX_MEMORY_UDEREF
25020+ pushl_cfi %ss
25021+ popl_cfi %ds
25022+ pushl_cfi %ss
25023+ popl_cfi %es
25024+#endif
25025+
25026 popl_cfi %esi
25027 CFI_RESTORE esi
25028 popl_cfi %edi
25029@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
25030 CFI_RESTORE ebx
25031 ret
25032 CFI_ENDPROC
25033-ENDPROC(csum_partial_copy_generic)
25034+ENDPROC(csum_partial_copy_generic_to_user)
25035
25036 #undef ROUND
25037 #undef ROUND1
25038diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
25039index f2145cf..cea889d 100644
25040--- a/arch/x86/lib/clear_page_64.S
25041+++ b/arch/x86/lib/clear_page_64.S
25042@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
25043 movl $4096/8,%ecx
25044 xorl %eax,%eax
25045 rep stosq
25046+ pax_force_retaddr
25047 ret
25048 CFI_ENDPROC
25049 ENDPROC(clear_page_c)
25050@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
25051 movl $4096,%ecx
25052 xorl %eax,%eax
25053 rep stosb
25054+ pax_force_retaddr
25055 ret
25056 CFI_ENDPROC
25057 ENDPROC(clear_page_c_e)
25058@@ -43,6 +45,7 @@ ENTRY(clear_page)
25059 leaq 64(%rdi),%rdi
25060 jnz .Lloop
25061 nop
25062+ pax_force_retaddr
25063 ret
25064 CFI_ENDPROC
25065 .Lclear_page_end:
25066@@ -58,7 +61,7 @@ ENDPROC(clear_page)
25067
25068 #include <asm/cpufeature.h>
25069
25070- .section .altinstr_replacement,"ax"
25071+ .section .altinstr_replacement,"a"
25072 1: .byte 0xeb /* jmp <disp8> */
25073 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
25074 2: .byte 0xeb /* jmp <disp8> */
25075diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
25076index 1e572c5..2a162cd 100644
25077--- a/arch/x86/lib/cmpxchg16b_emu.S
25078+++ b/arch/x86/lib/cmpxchg16b_emu.S
25079@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
25080
25081 popf
25082 mov $1, %al
25083+ pax_force_retaddr
25084 ret
25085
25086 not_same:
25087 popf
25088 xor %al,%al
25089+ pax_force_retaddr
25090 ret
25091
25092 CFI_ENDPROC
25093diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
25094index 176cca6..1166c50 100644
25095--- a/arch/x86/lib/copy_page_64.S
25096+++ b/arch/x86/lib/copy_page_64.S
25097@@ -9,6 +9,7 @@ copy_page_rep:
25098 CFI_STARTPROC
25099 movl $4096/8, %ecx
25100 rep movsq
25101+ pax_force_retaddr
25102 ret
25103 CFI_ENDPROC
25104 ENDPROC(copy_page_rep)
25105@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
25106
25107 ENTRY(copy_page)
25108 CFI_STARTPROC
25109- subq $2*8, %rsp
25110- CFI_ADJUST_CFA_OFFSET 2*8
25111+ subq $3*8, %rsp
25112+ CFI_ADJUST_CFA_OFFSET 3*8
25113 movq %rbx, (%rsp)
25114 CFI_REL_OFFSET rbx, 0
25115 movq %r12, 1*8(%rsp)
25116 CFI_REL_OFFSET r12, 1*8
25117+ movq %r13, 2*8(%rsp)
25118+ CFI_REL_OFFSET r13, 2*8
25119
25120 movl $(4096/64)-5, %ecx
25121 .p2align 4
25122@@ -36,7 +39,7 @@ ENTRY(copy_page)
25123 movq 0x8*2(%rsi), %rdx
25124 movq 0x8*3(%rsi), %r8
25125 movq 0x8*4(%rsi), %r9
25126- movq 0x8*5(%rsi), %r10
25127+ movq 0x8*5(%rsi), %r13
25128 movq 0x8*6(%rsi), %r11
25129 movq 0x8*7(%rsi), %r12
25130
25131@@ -47,7 +50,7 @@ ENTRY(copy_page)
25132 movq %rdx, 0x8*2(%rdi)
25133 movq %r8, 0x8*3(%rdi)
25134 movq %r9, 0x8*4(%rdi)
25135- movq %r10, 0x8*5(%rdi)
25136+ movq %r13, 0x8*5(%rdi)
25137 movq %r11, 0x8*6(%rdi)
25138 movq %r12, 0x8*7(%rdi)
25139
25140@@ -66,7 +69,7 @@ ENTRY(copy_page)
25141 movq 0x8*2(%rsi), %rdx
25142 movq 0x8*3(%rsi), %r8
25143 movq 0x8*4(%rsi), %r9
25144- movq 0x8*5(%rsi), %r10
25145+ movq 0x8*5(%rsi), %r13
25146 movq 0x8*6(%rsi), %r11
25147 movq 0x8*7(%rsi), %r12
25148
25149@@ -75,7 +78,7 @@ ENTRY(copy_page)
25150 movq %rdx, 0x8*2(%rdi)
25151 movq %r8, 0x8*3(%rdi)
25152 movq %r9, 0x8*4(%rdi)
25153- movq %r10, 0x8*5(%rdi)
25154+ movq %r13, 0x8*5(%rdi)
25155 movq %r11, 0x8*6(%rdi)
25156 movq %r12, 0x8*7(%rdi)
25157
25158@@ -87,8 +90,11 @@ ENTRY(copy_page)
25159 CFI_RESTORE rbx
25160 movq 1*8(%rsp), %r12
25161 CFI_RESTORE r12
25162- addq $2*8, %rsp
25163- CFI_ADJUST_CFA_OFFSET -2*8
25164+ movq 2*8(%rsp), %r13
25165+ CFI_RESTORE r13
25166+ addq $3*8, %rsp
25167+ CFI_ADJUST_CFA_OFFSET -3*8
25168+ pax_force_retaddr
25169 ret
25170 .Lcopy_page_end:
25171 CFI_ENDPROC
25172@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25173
25174 #include <asm/cpufeature.h>
25175
25176- .section .altinstr_replacement,"ax"
25177+ .section .altinstr_replacement,"a"
25178 1: .byte 0xeb /* jmp <disp8> */
25179 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25180 2:
25181diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25182index a30ca15..d25fab6 100644
25183--- a/arch/x86/lib/copy_user_64.S
25184+++ b/arch/x86/lib/copy_user_64.S
25185@@ -18,6 +18,7 @@
25186 #include <asm/alternative-asm.h>
25187 #include <asm/asm.h>
25188 #include <asm/smap.h>
25189+#include <asm/pgtable.h>
25190
25191 /*
25192 * By placing feature2 after feature1 in altinstructions section, we logically
25193@@ -31,7 +32,7 @@
25194 .byte 0xe9 /* 32bit jump */
25195 .long \orig-1f /* by default jump to orig */
25196 1:
25197- .section .altinstr_replacement,"ax"
25198+ .section .altinstr_replacement,"a"
25199 2: .byte 0xe9 /* near jump with 32bit immediate */
25200 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25201 3: .byte 0xe9 /* near jump with 32bit immediate */
25202@@ -70,47 +71,20 @@
25203 #endif
25204 .endm
25205
25206-/* Standard copy_to_user with segment limit checking */
25207-ENTRY(_copy_to_user)
25208- CFI_STARTPROC
25209- GET_THREAD_INFO(%rax)
25210- movq %rdi,%rcx
25211- addq %rdx,%rcx
25212- jc bad_to_user
25213- cmpq TI_addr_limit(%rax),%rcx
25214- ja bad_to_user
25215- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25216- copy_user_generic_unrolled,copy_user_generic_string, \
25217- copy_user_enhanced_fast_string
25218- CFI_ENDPROC
25219-ENDPROC(_copy_to_user)
25220-
25221-/* Standard copy_from_user with segment limit checking */
25222-ENTRY(_copy_from_user)
25223- CFI_STARTPROC
25224- GET_THREAD_INFO(%rax)
25225- movq %rsi,%rcx
25226- addq %rdx,%rcx
25227- jc bad_from_user
25228- cmpq TI_addr_limit(%rax),%rcx
25229- ja bad_from_user
25230- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25231- copy_user_generic_unrolled,copy_user_generic_string, \
25232- copy_user_enhanced_fast_string
25233- CFI_ENDPROC
25234-ENDPROC(_copy_from_user)
25235-
25236 .section .fixup,"ax"
25237 /* must zero dest */
25238 ENTRY(bad_from_user)
25239 bad_from_user:
25240 CFI_STARTPROC
25241+ testl %edx,%edx
25242+ js bad_to_user
25243 movl %edx,%ecx
25244 xorl %eax,%eax
25245 rep
25246 stosb
25247 bad_to_user:
25248 movl %edx,%eax
25249+ pax_force_retaddr
25250 ret
25251 CFI_ENDPROC
25252 ENDPROC(bad_from_user)
25253@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25254 jz 17f
25255 1: movq (%rsi),%r8
25256 2: movq 1*8(%rsi),%r9
25257-3: movq 2*8(%rsi),%r10
25258+3: movq 2*8(%rsi),%rax
25259 4: movq 3*8(%rsi),%r11
25260 5: movq %r8,(%rdi)
25261 6: movq %r9,1*8(%rdi)
25262-7: movq %r10,2*8(%rdi)
25263+7: movq %rax,2*8(%rdi)
25264 8: movq %r11,3*8(%rdi)
25265 9: movq 4*8(%rsi),%r8
25266 10: movq 5*8(%rsi),%r9
25267-11: movq 6*8(%rsi),%r10
25268+11: movq 6*8(%rsi),%rax
25269 12: movq 7*8(%rsi),%r11
25270 13: movq %r8,4*8(%rdi)
25271 14: movq %r9,5*8(%rdi)
25272-15: movq %r10,6*8(%rdi)
25273+15: movq %rax,6*8(%rdi)
25274 16: movq %r11,7*8(%rdi)
25275 leaq 64(%rsi),%rsi
25276 leaq 64(%rdi),%rdi
25277@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25278 jnz 21b
25279 23: xor %eax,%eax
25280 ASM_CLAC
25281+ pax_force_retaddr
25282 ret
25283
25284 .section .fixup,"ax"
25285@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25286 movsb
25287 4: xorl %eax,%eax
25288 ASM_CLAC
25289+ pax_force_retaddr
25290 ret
25291
25292 .section .fixup,"ax"
25293@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25294 movsb
25295 2: xorl %eax,%eax
25296 ASM_CLAC
25297+ pax_force_retaddr
25298 ret
25299
25300 .section .fixup,"ax"
25301diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25302index 6a4f43c..f08b4a2 100644
25303--- a/arch/x86/lib/copy_user_nocache_64.S
25304+++ b/arch/x86/lib/copy_user_nocache_64.S
25305@@ -8,6 +8,7 @@
25306
25307 #include <linux/linkage.h>
25308 #include <asm/dwarf2.h>
25309+#include <asm/alternative-asm.h>
25310
25311 #define FIX_ALIGNMENT 1
25312
25313@@ -16,6 +17,7 @@
25314 #include <asm/thread_info.h>
25315 #include <asm/asm.h>
25316 #include <asm/smap.h>
25317+#include <asm/pgtable.h>
25318
25319 .macro ALIGN_DESTINATION
25320 #ifdef FIX_ALIGNMENT
25321@@ -49,6 +51,15 @@
25322 */
25323 ENTRY(__copy_user_nocache)
25324 CFI_STARTPROC
25325+
25326+#ifdef CONFIG_PAX_MEMORY_UDEREF
25327+ mov pax_user_shadow_base,%rcx
25328+ cmp %rcx,%rsi
25329+ jae 1f
25330+ add %rcx,%rsi
25331+1:
25332+#endif
25333+
25334 ASM_STAC
25335 cmpl $8,%edx
25336 jb 20f /* less then 8 bytes, go to byte copy loop */
25337@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25338 jz 17f
25339 1: movq (%rsi),%r8
25340 2: movq 1*8(%rsi),%r9
25341-3: movq 2*8(%rsi),%r10
25342+3: movq 2*8(%rsi),%rax
25343 4: movq 3*8(%rsi),%r11
25344 5: movnti %r8,(%rdi)
25345 6: movnti %r9,1*8(%rdi)
25346-7: movnti %r10,2*8(%rdi)
25347+7: movnti %rax,2*8(%rdi)
25348 8: movnti %r11,3*8(%rdi)
25349 9: movq 4*8(%rsi),%r8
25350 10: movq 5*8(%rsi),%r9
25351-11: movq 6*8(%rsi),%r10
25352+11: movq 6*8(%rsi),%rax
25353 12: movq 7*8(%rsi),%r11
25354 13: movnti %r8,4*8(%rdi)
25355 14: movnti %r9,5*8(%rdi)
25356-15: movnti %r10,6*8(%rdi)
25357+15: movnti %rax,6*8(%rdi)
25358 16: movnti %r11,7*8(%rdi)
25359 leaq 64(%rsi),%rsi
25360 leaq 64(%rdi),%rdi
25361@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25362 23: xorl %eax,%eax
25363 ASM_CLAC
25364 sfence
25365+ pax_force_retaddr
25366 ret
25367
25368 .section .fixup,"ax"
25369diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25370index 2419d5f..953ee51 100644
25371--- a/arch/x86/lib/csum-copy_64.S
25372+++ b/arch/x86/lib/csum-copy_64.S
25373@@ -9,6 +9,7 @@
25374 #include <asm/dwarf2.h>
25375 #include <asm/errno.h>
25376 #include <asm/asm.h>
25377+#include <asm/alternative-asm.h>
25378
25379 /*
25380 * Checksum copy with exception handling.
25381@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25382 CFI_RESTORE rbp
25383 addq $7*8, %rsp
25384 CFI_ADJUST_CFA_OFFSET -7*8
25385+ pax_force_retaddr 0, 1
25386 ret
25387 CFI_RESTORE_STATE
25388
25389diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25390index 25b7ae8..169fafc 100644
25391--- a/arch/x86/lib/csum-wrappers_64.c
25392+++ b/arch/x86/lib/csum-wrappers_64.c
25393@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25394 len -= 2;
25395 }
25396 }
25397- isum = csum_partial_copy_generic((__force const void *)src,
25398+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25399 dst, len, isum, errp, NULL);
25400 if (unlikely(*errp))
25401 goto out_err;
25402@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25403 }
25404
25405 *errp = 0;
25406- return csum_partial_copy_generic(src, (void __force *)dst,
25407+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25408 len, isum, NULL, errp);
25409 }
25410 EXPORT_SYMBOL(csum_partial_copy_to_user);
25411diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25412index a451235..79fb5cf 100644
25413--- a/arch/x86/lib/getuser.S
25414+++ b/arch/x86/lib/getuser.S
25415@@ -33,17 +33,40 @@
25416 #include <asm/thread_info.h>
25417 #include <asm/asm.h>
25418 #include <asm/smap.h>
25419+#include <asm/segment.h>
25420+#include <asm/pgtable.h>
25421+#include <asm/alternative-asm.h>
25422+
25423+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25424+#define __copyuser_seg gs;
25425+#else
25426+#define __copyuser_seg
25427+#endif
25428
25429 .text
25430 ENTRY(__get_user_1)
25431 CFI_STARTPROC
25432+
25433+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25434 GET_THREAD_INFO(%_ASM_DX)
25435 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25436 jae bad_get_user
25437 ASM_STAC
25438-1: movzbl (%_ASM_AX),%edx
25439+
25440+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25441+ mov pax_user_shadow_base,%_ASM_DX
25442+ cmp %_ASM_DX,%_ASM_AX
25443+ jae 1234f
25444+ add %_ASM_DX,%_ASM_AX
25445+1234:
25446+#endif
25447+
25448+#endif
25449+
25450+1: __copyuser_seg movzbl (%_ASM_AX),%edx
25451 xor %eax,%eax
25452 ASM_CLAC
25453+ pax_force_retaddr
25454 ret
25455 CFI_ENDPROC
25456 ENDPROC(__get_user_1)
25457@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
25458 ENTRY(__get_user_2)
25459 CFI_STARTPROC
25460 add $1,%_ASM_AX
25461+
25462+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25463 jc bad_get_user
25464 GET_THREAD_INFO(%_ASM_DX)
25465 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25466 jae bad_get_user
25467 ASM_STAC
25468-2: movzwl -1(%_ASM_AX),%edx
25469+
25470+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25471+ mov pax_user_shadow_base,%_ASM_DX
25472+ cmp %_ASM_DX,%_ASM_AX
25473+ jae 1234f
25474+ add %_ASM_DX,%_ASM_AX
25475+1234:
25476+#endif
25477+
25478+#endif
25479+
25480+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25481 xor %eax,%eax
25482 ASM_CLAC
25483+ pax_force_retaddr
25484 ret
25485 CFI_ENDPROC
25486 ENDPROC(__get_user_2)
25487@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
25488 ENTRY(__get_user_4)
25489 CFI_STARTPROC
25490 add $3,%_ASM_AX
25491+
25492+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25493 jc bad_get_user
25494 GET_THREAD_INFO(%_ASM_DX)
25495 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25496 jae bad_get_user
25497 ASM_STAC
25498-3: movl -3(%_ASM_AX),%edx
25499+
25500+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25501+ mov pax_user_shadow_base,%_ASM_DX
25502+ cmp %_ASM_DX,%_ASM_AX
25503+ jae 1234f
25504+ add %_ASM_DX,%_ASM_AX
25505+1234:
25506+#endif
25507+
25508+#endif
25509+
25510+3: __copyuser_seg movl -3(%_ASM_AX),%edx
25511 xor %eax,%eax
25512 ASM_CLAC
25513+ pax_force_retaddr
25514 ret
25515 CFI_ENDPROC
25516 ENDPROC(__get_user_4)
25517@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
25518 GET_THREAD_INFO(%_ASM_DX)
25519 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25520 jae bad_get_user
25521+
25522+#ifdef CONFIG_PAX_MEMORY_UDEREF
25523+ mov pax_user_shadow_base,%_ASM_DX
25524+ cmp %_ASM_DX,%_ASM_AX
25525+ jae 1234f
25526+ add %_ASM_DX,%_ASM_AX
25527+1234:
25528+#endif
25529+
25530 ASM_STAC
25531 4: movq -7(%_ASM_AX),%rdx
25532 xor %eax,%eax
25533 ASM_CLAC
25534+ pax_force_retaddr
25535 ret
25536 #else
25537 add $7,%_ASM_AX
25538@@ -102,6 +163,7 @@ ENTRY(__get_user_8)
25539 5: movl -3(%_ASM_AX),%ecx
25540 xor %eax,%eax
25541 ASM_CLAC
25542+ pax_force_retaddr
25543 ret
25544 #endif
25545 CFI_ENDPROC
25546@@ -113,6 +175,7 @@ bad_get_user:
25547 xor %edx,%edx
25548 mov $(-EFAULT),%_ASM_AX
25549 ASM_CLAC
25550+ pax_force_retaddr
25551 ret
25552 CFI_ENDPROC
25553 END(bad_get_user)
25554@@ -124,6 +187,7 @@ bad_get_user_8:
25555 xor %ecx,%ecx
25556 mov $(-EFAULT),%_ASM_AX
25557 ASM_CLAC
25558+ pax_force_retaddr
25559 ret
25560 CFI_ENDPROC
25561 END(bad_get_user_8)
25562diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25563index 54fcffe..7be149e 100644
25564--- a/arch/x86/lib/insn.c
25565+++ b/arch/x86/lib/insn.c
25566@@ -20,8 +20,10 @@
25567
25568 #ifdef __KERNEL__
25569 #include <linux/string.h>
25570+#include <asm/pgtable_types.h>
25571 #else
25572 #include <string.h>
25573+#define ktla_ktva(addr) addr
25574 #endif
25575 #include <asm/inat.h>
25576 #include <asm/insn.h>
25577@@ -53,8 +55,8 @@
25578 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25579 {
25580 memset(insn, 0, sizeof(*insn));
25581- insn->kaddr = kaddr;
25582- insn->next_byte = kaddr;
25583+ insn->kaddr = ktla_ktva(kaddr);
25584+ insn->next_byte = ktla_ktva(kaddr);
25585 insn->x86_64 = x86_64 ? 1 : 0;
25586 insn->opnd_bytes = 4;
25587 if (x86_64)
25588diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25589index 05a95e7..326f2fa 100644
25590--- a/arch/x86/lib/iomap_copy_64.S
25591+++ b/arch/x86/lib/iomap_copy_64.S
25592@@ -17,6 +17,7 @@
25593
25594 #include <linux/linkage.h>
25595 #include <asm/dwarf2.h>
25596+#include <asm/alternative-asm.h>
25597
25598 /*
25599 * override generic version in lib/iomap_copy.c
25600@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25601 CFI_STARTPROC
25602 movl %edx,%ecx
25603 rep movsd
25604+ pax_force_retaddr
25605 ret
25606 CFI_ENDPROC
25607 ENDPROC(__iowrite32_copy)
25608diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25609index 56313a3..aa84a79 100644
25610--- a/arch/x86/lib/memcpy_64.S
25611+++ b/arch/x86/lib/memcpy_64.S
25612@@ -33,6 +33,7 @@
25613 rep movsq
25614 movl %edx, %ecx
25615 rep movsb
25616+ pax_force_retaddr
25617 ret
25618 .Lmemcpy_e:
25619 .previous
25620@@ -49,6 +50,7 @@
25621 movq %rdi, %rax
25622 movq %rdx, %rcx
25623 rep movsb
25624+ pax_force_retaddr
25625 ret
25626 .Lmemcpy_e_e:
25627 .previous
25628@@ -76,13 +78,13 @@ ENTRY(memcpy)
25629 */
25630 movq 0*8(%rsi), %r8
25631 movq 1*8(%rsi), %r9
25632- movq 2*8(%rsi), %r10
25633+ movq 2*8(%rsi), %rcx
25634 movq 3*8(%rsi), %r11
25635 leaq 4*8(%rsi), %rsi
25636
25637 movq %r8, 0*8(%rdi)
25638 movq %r9, 1*8(%rdi)
25639- movq %r10, 2*8(%rdi)
25640+ movq %rcx, 2*8(%rdi)
25641 movq %r11, 3*8(%rdi)
25642 leaq 4*8(%rdi), %rdi
25643 jae .Lcopy_forward_loop
25644@@ -105,12 +107,12 @@ ENTRY(memcpy)
25645 subq $0x20, %rdx
25646 movq -1*8(%rsi), %r8
25647 movq -2*8(%rsi), %r9
25648- movq -3*8(%rsi), %r10
25649+ movq -3*8(%rsi), %rcx
25650 movq -4*8(%rsi), %r11
25651 leaq -4*8(%rsi), %rsi
25652 movq %r8, -1*8(%rdi)
25653 movq %r9, -2*8(%rdi)
25654- movq %r10, -3*8(%rdi)
25655+ movq %rcx, -3*8(%rdi)
25656 movq %r11, -4*8(%rdi)
25657 leaq -4*8(%rdi), %rdi
25658 jae .Lcopy_backward_loop
25659@@ -130,12 +132,13 @@ ENTRY(memcpy)
25660 */
25661 movq 0*8(%rsi), %r8
25662 movq 1*8(%rsi), %r9
25663- movq -2*8(%rsi, %rdx), %r10
25664+ movq -2*8(%rsi, %rdx), %rcx
25665 movq -1*8(%rsi, %rdx), %r11
25666 movq %r8, 0*8(%rdi)
25667 movq %r9, 1*8(%rdi)
25668- movq %r10, -2*8(%rdi, %rdx)
25669+ movq %rcx, -2*8(%rdi, %rdx)
25670 movq %r11, -1*8(%rdi, %rdx)
25671+ pax_force_retaddr
25672 retq
25673 .p2align 4
25674 .Lless_16bytes:
25675@@ -148,6 +151,7 @@ ENTRY(memcpy)
25676 movq -1*8(%rsi, %rdx), %r9
25677 movq %r8, 0*8(%rdi)
25678 movq %r9, -1*8(%rdi, %rdx)
25679+ pax_force_retaddr
25680 retq
25681 .p2align 4
25682 .Lless_8bytes:
25683@@ -161,6 +165,7 @@ ENTRY(memcpy)
25684 movl -4(%rsi, %rdx), %r8d
25685 movl %ecx, (%rdi)
25686 movl %r8d, -4(%rdi, %rdx)
25687+ pax_force_retaddr
25688 retq
25689 .p2align 4
25690 .Lless_3bytes:
25691@@ -179,6 +184,7 @@ ENTRY(memcpy)
25692 movb %cl, (%rdi)
25693
25694 .Lend:
25695+ pax_force_retaddr
25696 retq
25697 CFI_ENDPROC
25698 ENDPROC(memcpy)
25699diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25700index 65268a6..c9518d1 100644
25701--- a/arch/x86/lib/memmove_64.S
25702+++ b/arch/x86/lib/memmove_64.S
25703@@ -61,13 +61,13 @@ ENTRY(memmove)
25704 5:
25705 sub $0x20, %rdx
25706 movq 0*8(%rsi), %r11
25707- movq 1*8(%rsi), %r10
25708+ movq 1*8(%rsi), %rcx
25709 movq 2*8(%rsi), %r9
25710 movq 3*8(%rsi), %r8
25711 leaq 4*8(%rsi), %rsi
25712
25713 movq %r11, 0*8(%rdi)
25714- movq %r10, 1*8(%rdi)
25715+ movq %rcx, 1*8(%rdi)
25716 movq %r9, 2*8(%rdi)
25717 movq %r8, 3*8(%rdi)
25718 leaq 4*8(%rdi), %rdi
25719@@ -81,10 +81,10 @@ ENTRY(memmove)
25720 4:
25721 movq %rdx, %rcx
25722 movq -8(%rsi, %rdx), %r11
25723- lea -8(%rdi, %rdx), %r10
25724+ lea -8(%rdi, %rdx), %r9
25725 shrq $3, %rcx
25726 rep movsq
25727- movq %r11, (%r10)
25728+ movq %r11, (%r9)
25729 jmp 13f
25730 .Lmemmove_end_forward:
25731
25732@@ -95,14 +95,14 @@ ENTRY(memmove)
25733 7:
25734 movq %rdx, %rcx
25735 movq (%rsi), %r11
25736- movq %rdi, %r10
25737+ movq %rdi, %r9
25738 leaq -8(%rsi, %rdx), %rsi
25739 leaq -8(%rdi, %rdx), %rdi
25740 shrq $3, %rcx
25741 std
25742 rep movsq
25743 cld
25744- movq %r11, (%r10)
25745+ movq %r11, (%r9)
25746 jmp 13f
25747
25748 /*
25749@@ -127,13 +127,13 @@ ENTRY(memmove)
25750 8:
25751 subq $0x20, %rdx
25752 movq -1*8(%rsi), %r11
25753- movq -2*8(%rsi), %r10
25754+ movq -2*8(%rsi), %rcx
25755 movq -3*8(%rsi), %r9
25756 movq -4*8(%rsi), %r8
25757 leaq -4*8(%rsi), %rsi
25758
25759 movq %r11, -1*8(%rdi)
25760- movq %r10, -2*8(%rdi)
25761+ movq %rcx, -2*8(%rdi)
25762 movq %r9, -3*8(%rdi)
25763 movq %r8, -4*8(%rdi)
25764 leaq -4*8(%rdi), %rdi
25765@@ -151,11 +151,11 @@ ENTRY(memmove)
25766 * Move data from 16 bytes to 31 bytes.
25767 */
25768 movq 0*8(%rsi), %r11
25769- movq 1*8(%rsi), %r10
25770+ movq 1*8(%rsi), %rcx
25771 movq -2*8(%rsi, %rdx), %r9
25772 movq -1*8(%rsi, %rdx), %r8
25773 movq %r11, 0*8(%rdi)
25774- movq %r10, 1*8(%rdi)
25775+ movq %rcx, 1*8(%rdi)
25776 movq %r9, -2*8(%rdi, %rdx)
25777 movq %r8, -1*8(%rdi, %rdx)
25778 jmp 13f
25779@@ -167,9 +167,9 @@ ENTRY(memmove)
25780 * Move data from 8 bytes to 15 bytes.
25781 */
25782 movq 0*8(%rsi), %r11
25783- movq -1*8(%rsi, %rdx), %r10
25784+ movq -1*8(%rsi, %rdx), %r9
25785 movq %r11, 0*8(%rdi)
25786- movq %r10, -1*8(%rdi, %rdx)
25787+ movq %r9, -1*8(%rdi, %rdx)
25788 jmp 13f
25789 10:
25790 cmpq $4, %rdx
25791@@ -178,9 +178,9 @@ ENTRY(memmove)
25792 * Move data from 4 bytes to 7 bytes.
25793 */
25794 movl (%rsi), %r11d
25795- movl -4(%rsi, %rdx), %r10d
25796+ movl -4(%rsi, %rdx), %r9d
25797 movl %r11d, (%rdi)
25798- movl %r10d, -4(%rdi, %rdx)
25799+ movl %r9d, -4(%rdi, %rdx)
25800 jmp 13f
25801 11:
25802 cmp $2, %rdx
25803@@ -189,9 +189,9 @@ ENTRY(memmove)
25804 * Move data from 2 bytes to 3 bytes.
25805 */
25806 movw (%rsi), %r11w
25807- movw -2(%rsi, %rdx), %r10w
25808+ movw -2(%rsi, %rdx), %r9w
25809 movw %r11w, (%rdi)
25810- movw %r10w, -2(%rdi, %rdx)
25811+ movw %r9w, -2(%rdi, %rdx)
25812 jmp 13f
25813 12:
25814 cmp $1, %rdx
25815@@ -202,6 +202,7 @@ ENTRY(memmove)
25816 movb (%rsi), %r11b
25817 movb %r11b, (%rdi)
25818 13:
25819+ pax_force_retaddr
25820 retq
25821 CFI_ENDPROC
25822
25823@@ -210,6 +211,7 @@ ENTRY(memmove)
25824 /* Forward moving data. */
25825 movq %rdx, %rcx
25826 rep movsb
25827+ pax_force_retaddr
25828 retq
25829 .Lmemmove_end_forward_efs:
25830 .previous
25831diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25832index 2dcb380..963660a 100644
25833--- a/arch/x86/lib/memset_64.S
25834+++ b/arch/x86/lib/memset_64.S
25835@@ -30,6 +30,7 @@
25836 movl %edx,%ecx
25837 rep stosb
25838 movq %r9,%rax
25839+ pax_force_retaddr
25840 ret
25841 .Lmemset_e:
25842 .previous
25843@@ -52,6 +53,7 @@
25844 movq %rdx,%rcx
25845 rep stosb
25846 movq %r9,%rax
25847+ pax_force_retaddr
25848 ret
25849 .Lmemset_e_e:
25850 .previous
25851@@ -59,7 +61,7 @@
25852 ENTRY(memset)
25853 ENTRY(__memset)
25854 CFI_STARTPROC
25855- movq %rdi,%r10
25856+ movq %rdi,%r11
25857
25858 /* expand byte value */
25859 movzbl %sil,%ecx
25860@@ -117,7 +119,8 @@ ENTRY(__memset)
25861 jnz .Lloop_1
25862
25863 .Lende:
25864- movq %r10,%rax
25865+ movq %r11,%rax
25866+ pax_force_retaddr
25867 ret
25868
25869 CFI_RESTORE_STATE
25870diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25871index c9f2d9b..e7fd2c0 100644
25872--- a/arch/x86/lib/mmx_32.c
25873+++ b/arch/x86/lib/mmx_32.c
25874@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25875 {
25876 void *p;
25877 int i;
25878+ unsigned long cr0;
25879
25880 if (unlikely(in_interrupt()))
25881 return __memcpy(to, from, len);
25882@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25883 kernel_fpu_begin();
25884
25885 __asm__ __volatile__ (
25886- "1: prefetch (%0)\n" /* This set is 28 bytes */
25887- " prefetch 64(%0)\n"
25888- " prefetch 128(%0)\n"
25889- " prefetch 192(%0)\n"
25890- " prefetch 256(%0)\n"
25891+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25892+ " prefetch 64(%1)\n"
25893+ " prefetch 128(%1)\n"
25894+ " prefetch 192(%1)\n"
25895+ " prefetch 256(%1)\n"
25896 "2: \n"
25897 ".section .fixup, \"ax\"\n"
25898- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25899+ "3: \n"
25900+
25901+#ifdef CONFIG_PAX_KERNEXEC
25902+ " movl %%cr0, %0\n"
25903+ " movl %0, %%eax\n"
25904+ " andl $0xFFFEFFFF, %%eax\n"
25905+ " movl %%eax, %%cr0\n"
25906+#endif
25907+
25908+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25909+
25910+#ifdef CONFIG_PAX_KERNEXEC
25911+ " movl %0, %%cr0\n"
25912+#endif
25913+
25914 " jmp 2b\n"
25915 ".previous\n"
25916 _ASM_EXTABLE(1b, 3b)
25917- : : "r" (from));
25918+ : "=&r" (cr0) : "r" (from) : "ax");
25919
25920 for ( ; i > 5; i--) {
25921 __asm__ __volatile__ (
25922- "1: prefetch 320(%0)\n"
25923- "2: movq (%0), %%mm0\n"
25924- " movq 8(%0), %%mm1\n"
25925- " movq 16(%0), %%mm2\n"
25926- " movq 24(%0), %%mm3\n"
25927- " movq %%mm0, (%1)\n"
25928- " movq %%mm1, 8(%1)\n"
25929- " movq %%mm2, 16(%1)\n"
25930- " movq %%mm3, 24(%1)\n"
25931- " movq 32(%0), %%mm0\n"
25932- " movq 40(%0), %%mm1\n"
25933- " movq 48(%0), %%mm2\n"
25934- " movq 56(%0), %%mm3\n"
25935- " movq %%mm0, 32(%1)\n"
25936- " movq %%mm1, 40(%1)\n"
25937- " movq %%mm2, 48(%1)\n"
25938- " movq %%mm3, 56(%1)\n"
25939+ "1: prefetch 320(%1)\n"
25940+ "2: movq (%1), %%mm0\n"
25941+ " movq 8(%1), %%mm1\n"
25942+ " movq 16(%1), %%mm2\n"
25943+ " movq 24(%1), %%mm3\n"
25944+ " movq %%mm0, (%2)\n"
25945+ " movq %%mm1, 8(%2)\n"
25946+ " movq %%mm2, 16(%2)\n"
25947+ " movq %%mm3, 24(%2)\n"
25948+ " movq 32(%1), %%mm0\n"
25949+ " movq 40(%1), %%mm1\n"
25950+ " movq 48(%1), %%mm2\n"
25951+ " movq 56(%1), %%mm3\n"
25952+ " movq %%mm0, 32(%2)\n"
25953+ " movq %%mm1, 40(%2)\n"
25954+ " movq %%mm2, 48(%2)\n"
25955+ " movq %%mm3, 56(%2)\n"
25956 ".section .fixup, \"ax\"\n"
25957- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25958+ "3:\n"
25959+
25960+#ifdef CONFIG_PAX_KERNEXEC
25961+ " movl %%cr0, %0\n"
25962+ " movl %0, %%eax\n"
25963+ " andl $0xFFFEFFFF, %%eax\n"
25964+ " movl %%eax, %%cr0\n"
25965+#endif
25966+
25967+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25968+
25969+#ifdef CONFIG_PAX_KERNEXEC
25970+ " movl %0, %%cr0\n"
25971+#endif
25972+
25973 " jmp 2b\n"
25974 ".previous\n"
25975 _ASM_EXTABLE(1b, 3b)
25976- : : "r" (from), "r" (to) : "memory");
25977+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25978
25979 from += 64;
25980 to += 64;
25981@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25982 static void fast_copy_page(void *to, void *from)
25983 {
25984 int i;
25985+ unsigned long cr0;
25986
25987 kernel_fpu_begin();
25988
25989@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25990 * but that is for later. -AV
25991 */
25992 __asm__ __volatile__(
25993- "1: prefetch (%0)\n"
25994- " prefetch 64(%0)\n"
25995- " prefetch 128(%0)\n"
25996- " prefetch 192(%0)\n"
25997- " prefetch 256(%0)\n"
25998+ "1: prefetch (%1)\n"
25999+ " prefetch 64(%1)\n"
26000+ " prefetch 128(%1)\n"
26001+ " prefetch 192(%1)\n"
26002+ " prefetch 256(%1)\n"
26003 "2: \n"
26004 ".section .fixup, \"ax\"\n"
26005- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26006+ "3: \n"
26007+
26008+#ifdef CONFIG_PAX_KERNEXEC
26009+ " movl %%cr0, %0\n"
26010+ " movl %0, %%eax\n"
26011+ " andl $0xFFFEFFFF, %%eax\n"
26012+ " movl %%eax, %%cr0\n"
26013+#endif
26014+
26015+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26016+
26017+#ifdef CONFIG_PAX_KERNEXEC
26018+ " movl %0, %%cr0\n"
26019+#endif
26020+
26021 " jmp 2b\n"
26022 ".previous\n"
26023- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26024+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26025
26026 for (i = 0; i < (4096-320)/64; i++) {
26027 __asm__ __volatile__ (
26028- "1: prefetch 320(%0)\n"
26029- "2: movq (%0), %%mm0\n"
26030- " movntq %%mm0, (%1)\n"
26031- " movq 8(%0), %%mm1\n"
26032- " movntq %%mm1, 8(%1)\n"
26033- " movq 16(%0), %%mm2\n"
26034- " movntq %%mm2, 16(%1)\n"
26035- " movq 24(%0), %%mm3\n"
26036- " movntq %%mm3, 24(%1)\n"
26037- " movq 32(%0), %%mm4\n"
26038- " movntq %%mm4, 32(%1)\n"
26039- " movq 40(%0), %%mm5\n"
26040- " movntq %%mm5, 40(%1)\n"
26041- " movq 48(%0), %%mm6\n"
26042- " movntq %%mm6, 48(%1)\n"
26043- " movq 56(%0), %%mm7\n"
26044- " movntq %%mm7, 56(%1)\n"
26045+ "1: prefetch 320(%1)\n"
26046+ "2: movq (%1), %%mm0\n"
26047+ " movntq %%mm0, (%2)\n"
26048+ " movq 8(%1), %%mm1\n"
26049+ " movntq %%mm1, 8(%2)\n"
26050+ " movq 16(%1), %%mm2\n"
26051+ " movntq %%mm2, 16(%2)\n"
26052+ " movq 24(%1), %%mm3\n"
26053+ " movntq %%mm3, 24(%2)\n"
26054+ " movq 32(%1), %%mm4\n"
26055+ " movntq %%mm4, 32(%2)\n"
26056+ " movq 40(%1), %%mm5\n"
26057+ " movntq %%mm5, 40(%2)\n"
26058+ " movq 48(%1), %%mm6\n"
26059+ " movntq %%mm6, 48(%2)\n"
26060+ " movq 56(%1), %%mm7\n"
26061+ " movntq %%mm7, 56(%2)\n"
26062 ".section .fixup, \"ax\"\n"
26063- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26064+ "3:\n"
26065+
26066+#ifdef CONFIG_PAX_KERNEXEC
26067+ " movl %%cr0, %0\n"
26068+ " movl %0, %%eax\n"
26069+ " andl $0xFFFEFFFF, %%eax\n"
26070+ " movl %%eax, %%cr0\n"
26071+#endif
26072+
26073+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26074+
26075+#ifdef CONFIG_PAX_KERNEXEC
26076+ " movl %0, %%cr0\n"
26077+#endif
26078+
26079 " jmp 2b\n"
26080 ".previous\n"
26081- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
26082+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26083
26084 from += 64;
26085 to += 64;
26086@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
26087 static void fast_copy_page(void *to, void *from)
26088 {
26089 int i;
26090+ unsigned long cr0;
26091
26092 kernel_fpu_begin();
26093
26094 __asm__ __volatile__ (
26095- "1: prefetch (%0)\n"
26096- " prefetch 64(%0)\n"
26097- " prefetch 128(%0)\n"
26098- " prefetch 192(%0)\n"
26099- " prefetch 256(%0)\n"
26100+ "1: prefetch (%1)\n"
26101+ " prefetch 64(%1)\n"
26102+ " prefetch 128(%1)\n"
26103+ " prefetch 192(%1)\n"
26104+ " prefetch 256(%1)\n"
26105 "2: \n"
26106 ".section .fixup, \"ax\"\n"
26107- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26108+ "3: \n"
26109+
26110+#ifdef CONFIG_PAX_KERNEXEC
26111+ " movl %%cr0, %0\n"
26112+ " movl %0, %%eax\n"
26113+ " andl $0xFFFEFFFF, %%eax\n"
26114+ " movl %%eax, %%cr0\n"
26115+#endif
26116+
26117+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26118+
26119+#ifdef CONFIG_PAX_KERNEXEC
26120+ " movl %0, %%cr0\n"
26121+#endif
26122+
26123 " jmp 2b\n"
26124 ".previous\n"
26125- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26126+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26127
26128 for (i = 0; i < 4096/64; i++) {
26129 __asm__ __volatile__ (
26130- "1: prefetch 320(%0)\n"
26131- "2: movq (%0), %%mm0\n"
26132- " movq 8(%0), %%mm1\n"
26133- " movq 16(%0), %%mm2\n"
26134- " movq 24(%0), %%mm3\n"
26135- " movq %%mm0, (%1)\n"
26136- " movq %%mm1, 8(%1)\n"
26137- " movq %%mm2, 16(%1)\n"
26138- " movq %%mm3, 24(%1)\n"
26139- " movq 32(%0), %%mm0\n"
26140- " movq 40(%0), %%mm1\n"
26141- " movq 48(%0), %%mm2\n"
26142- " movq 56(%0), %%mm3\n"
26143- " movq %%mm0, 32(%1)\n"
26144- " movq %%mm1, 40(%1)\n"
26145- " movq %%mm2, 48(%1)\n"
26146- " movq %%mm3, 56(%1)\n"
26147+ "1: prefetch 320(%1)\n"
26148+ "2: movq (%1), %%mm0\n"
26149+ " movq 8(%1), %%mm1\n"
26150+ " movq 16(%1), %%mm2\n"
26151+ " movq 24(%1), %%mm3\n"
26152+ " movq %%mm0, (%2)\n"
26153+ " movq %%mm1, 8(%2)\n"
26154+ " movq %%mm2, 16(%2)\n"
26155+ " movq %%mm3, 24(%2)\n"
26156+ " movq 32(%1), %%mm0\n"
26157+ " movq 40(%1), %%mm1\n"
26158+ " movq 48(%1), %%mm2\n"
26159+ " movq 56(%1), %%mm3\n"
26160+ " movq %%mm0, 32(%2)\n"
26161+ " movq %%mm1, 40(%2)\n"
26162+ " movq %%mm2, 48(%2)\n"
26163+ " movq %%mm3, 56(%2)\n"
26164 ".section .fixup, \"ax\"\n"
26165- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26166+ "3:\n"
26167+
26168+#ifdef CONFIG_PAX_KERNEXEC
26169+ " movl %%cr0, %0\n"
26170+ " movl %0, %%eax\n"
26171+ " andl $0xFFFEFFFF, %%eax\n"
26172+ " movl %%eax, %%cr0\n"
26173+#endif
26174+
26175+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26176+
26177+#ifdef CONFIG_PAX_KERNEXEC
26178+ " movl %0, %%cr0\n"
26179+#endif
26180+
26181 " jmp 2b\n"
26182 ".previous\n"
26183 _ASM_EXTABLE(1b, 3b)
26184- : : "r" (from), "r" (to) : "memory");
26185+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26186
26187 from += 64;
26188 to += 64;
26189diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26190index f6d13ee..aca5f0b 100644
26191--- a/arch/x86/lib/msr-reg.S
26192+++ b/arch/x86/lib/msr-reg.S
26193@@ -3,6 +3,7 @@
26194 #include <asm/dwarf2.h>
26195 #include <asm/asm.h>
26196 #include <asm/msr.h>
26197+#include <asm/alternative-asm.h>
26198
26199 #ifdef CONFIG_X86_64
26200 /*
26201@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26202 CFI_STARTPROC
26203 pushq_cfi %rbx
26204 pushq_cfi %rbp
26205- movq %rdi, %r10 /* Save pointer */
26206+ movq %rdi, %r9 /* Save pointer */
26207 xorl %r11d, %r11d /* Return value */
26208 movl (%rdi), %eax
26209 movl 4(%rdi), %ecx
26210@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26211 movl 28(%rdi), %edi
26212 CFI_REMEMBER_STATE
26213 1: \op
26214-2: movl %eax, (%r10)
26215+2: movl %eax, (%r9)
26216 movl %r11d, %eax /* Return value */
26217- movl %ecx, 4(%r10)
26218- movl %edx, 8(%r10)
26219- movl %ebx, 12(%r10)
26220- movl %ebp, 20(%r10)
26221- movl %esi, 24(%r10)
26222- movl %edi, 28(%r10)
26223+ movl %ecx, 4(%r9)
26224+ movl %edx, 8(%r9)
26225+ movl %ebx, 12(%r9)
26226+ movl %ebp, 20(%r9)
26227+ movl %esi, 24(%r9)
26228+ movl %edi, 28(%r9)
26229 popq_cfi %rbp
26230 popq_cfi %rbx
26231+ pax_force_retaddr
26232 ret
26233 3:
26234 CFI_RESTORE_STATE
26235diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26236index fc6ba17..d4d989d 100644
26237--- a/arch/x86/lib/putuser.S
26238+++ b/arch/x86/lib/putuser.S
26239@@ -16,7 +16,9 @@
26240 #include <asm/errno.h>
26241 #include <asm/asm.h>
26242 #include <asm/smap.h>
26243-
26244+#include <asm/segment.h>
26245+#include <asm/pgtable.h>
26246+#include <asm/alternative-asm.h>
26247
26248 /*
26249 * __put_user_X
26250@@ -30,57 +32,125 @@
26251 * as they get called from within inline assembly.
26252 */
26253
26254-#define ENTER CFI_STARTPROC ; \
26255- GET_THREAD_INFO(%_ASM_BX)
26256-#define EXIT ASM_CLAC ; \
26257- ret ; \
26258+#define ENTER CFI_STARTPROC
26259+#define EXIT ASM_CLAC ; \
26260+ pax_force_retaddr ; \
26261+ ret ; \
26262 CFI_ENDPROC
26263
26264+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26265+#define _DEST %_ASM_CX,%_ASM_BX
26266+#else
26267+#define _DEST %_ASM_CX
26268+#endif
26269+
26270+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26271+#define __copyuser_seg gs;
26272+#else
26273+#define __copyuser_seg
26274+#endif
26275+
26276 .text
26277 ENTRY(__put_user_1)
26278 ENTER
26279+
26280+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26281+ GET_THREAD_INFO(%_ASM_BX)
26282 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26283 jae bad_put_user
26284 ASM_STAC
26285-1: movb %al,(%_ASM_CX)
26286+
26287+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26288+ mov pax_user_shadow_base,%_ASM_BX
26289+ cmp %_ASM_BX,%_ASM_CX
26290+ jb 1234f
26291+ xor %ebx,%ebx
26292+1234:
26293+#endif
26294+
26295+#endif
26296+
26297+1: __copyuser_seg movb %al,(_DEST)
26298 xor %eax,%eax
26299 EXIT
26300 ENDPROC(__put_user_1)
26301
26302 ENTRY(__put_user_2)
26303 ENTER
26304+
26305+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26306+ GET_THREAD_INFO(%_ASM_BX)
26307 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26308 sub $1,%_ASM_BX
26309 cmp %_ASM_BX,%_ASM_CX
26310 jae bad_put_user
26311 ASM_STAC
26312-2: movw %ax,(%_ASM_CX)
26313+
26314+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26315+ mov pax_user_shadow_base,%_ASM_BX
26316+ cmp %_ASM_BX,%_ASM_CX
26317+ jb 1234f
26318+ xor %ebx,%ebx
26319+1234:
26320+#endif
26321+
26322+#endif
26323+
26324+2: __copyuser_seg movw %ax,(_DEST)
26325 xor %eax,%eax
26326 EXIT
26327 ENDPROC(__put_user_2)
26328
26329 ENTRY(__put_user_4)
26330 ENTER
26331+
26332+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26333+ GET_THREAD_INFO(%_ASM_BX)
26334 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26335 sub $3,%_ASM_BX
26336 cmp %_ASM_BX,%_ASM_CX
26337 jae bad_put_user
26338 ASM_STAC
26339-3: movl %eax,(%_ASM_CX)
26340+
26341+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26342+ mov pax_user_shadow_base,%_ASM_BX
26343+ cmp %_ASM_BX,%_ASM_CX
26344+ jb 1234f
26345+ xor %ebx,%ebx
26346+1234:
26347+#endif
26348+
26349+#endif
26350+
26351+3: __copyuser_seg movl %eax,(_DEST)
26352 xor %eax,%eax
26353 EXIT
26354 ENDPROC(__put_user_4)
26355
26356 ENTRY(__put_user_8)
26357 ENTER
26358+
26359+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26360+ GET_THREAD_INFO(%_ASM_BX)
26361 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26362 sub $7,%_ASM_BX
26363 cmp %_ASM_BX,%_ASM_CX
26364 jae bad_put_user
26365 ASM_STAC
26366-4: mov %_ASM_AX,(%_ASM_CX)
26367+
26368+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26369+ mov pax_user_shadow_base,%_ASM_BX
26370+ cmp %_ASM_BX,%_ASM_CX
26371+ jb 1234f
26372+ xor %ebx,%ebx
26373+1234:
26374+#endif
26375+
26376+#endif
26377+
26378+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26379 #ifdef CONFIG_X86_32
26380-5: movl %edx,4(%_ASM_CX)
26381+5: __copyuser_seg movl %edx,4(_DEST)
26382 #endif
26383 xor %eax,%eax
26384 EXIT
26385diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26386index 1cad221..de671ee 100644
26387--- a/arch/x86/lib/rwlock.S
26388+++ b/arch/x86/lib/rwlock.S
26389@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26390 FRAME
26391 0: LOCK_PREFIX
26392 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26393+
26394+#ifdef CONFIG_PAX_REFCOUNT
26395+ jno 1234f
26396+ LOCK_PREFIX
26397+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26398+ int $4
26399+1234:
26400+ _ASM_EXTABLE(1234b, 1234b)
26401+#endif
26402+
26403 1: rep; nop
26404 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26405 jne 1b
26406 LOCK_PREFIX
26407 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26408+
26409+#ifdef CONFIG_PAX_REFCOUNT
26410+ jno 1234f
26411+ LOCK_PREFIX
26412+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26413+ int $4
26414+1234:
26415+ _ASM_EXTABLE(1234b, 1234b)
26416+#endif
26417+
26418 jnz 0b
26419 ENDFRAME
26420+ pax_force_retaddr
26421 ret
26422 CFI_ENDPROC
26423 END(__write_lock_failed)
26424@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26425 FRAME
26426 0: LOCK_PREFIX
26427 READ_LOCK_SIZE(inc) (%__lock_ptr)
26428+
26429+#ifdef CONFIG_PAX_REFCOUNT
26430+ jno 1234f
26431+ LOCK_PREFIX
26432+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26433+ int $4
26434+1234:
26435+ _ASM_EXTABLE(1234b, 1234b)
26436+#endif
26437+
26438 1: rep; nop
26439 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26440 js 1b
26441 LOCK_PREFIX
26442 READ_LOCK_SIZE(dec) (%__lock_ptr)
26443+
26444+#ifdef CONFIG_PAX_REFCOUNT
26445+ jno 1234f
26446+ LOCK_PREFIX
26447+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26448+ int $4
26449+1234:
26450+ _ASM_EXTABLE(1234b, 1234b)
26451+#endif
26452+
26453 js 0b
26454 ENDFRAME
26455+ pax_force_retaddr
26456 ret
26457 CFI_ENDPROC
26458 END(__read_lock_failed)
26459diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26460index 5dff5f0..cadebf4 100644
26461--- a/arch/x86/lib/rwsem.S
26462+++ b/arch/x86/lib/rwsem.S
26463@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26464 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26465 CFI_RESTORE __ASM_REG(dx)
26466 restore_common_regs
26467+ pax_force_retaddr
26468 ret
26469 CFI_ENDPROC
26470 ENDPROC(call_rwsem_down_read_failed)
26471@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26472 movq %rax,%rdi
26473 call rwsem_down_write_failed
26474 restore_common_regs
26475+ pax_force_retaddr
26476 ret
26477 CFI_ENDPROC
26478 ENDPROC(call_rwsem_down_write_failed)
26479@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26480 movq %rax,%rdi
26481 call rwsem_wake
26482 restore_common_regs
26483-1: ret
26484+1: pax_force_retaddr
26485+ ret
26486 CFI_ENDPROC
26487 ENDPROC(call_rwsem_wake)
26488
26489@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26490 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26491 CFI_RESTORE __ASM_REG(dx)
26492 restore_common_regs
26493+ pax_force_retaddr
26494 ret
26495 CFI_ENDPROC
26496 ENDPROC(call_rwsem_downgrade_wake)
26497diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26498index a63efd6..ccecad8 100644
26499--- a/arch/x86/lib/thunk_64.S
26500+++ b/arch/x86/lib/thunk_64.S
26501@@ -8,6 +8,7 @@
26502 #include <linux/linkage.h>
26503 #include <asm/dwarf2.h>
26504 #include <asm/calling.h>
26505+#include <asm/alternative-asm.h>
26506
26507 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26508 .macro THUNK name, func, put_ret_addr_in_rdi=0
26509@@ -41,5 +42,6 @@
26510 SAVE_ARGS
26511 restore:
26512 RESTORE_ARGS
26513+ pax_force_retaddr
26514 ret
26515 CFI_ENDPROC
26516diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26517index 3eb18ac..6890bc3 100644
26518--- a/arch/x86/lib/usercopy_32.c
26519+++ b/arch/x86/lib/usercopy_32.c
26520@@ -42,11 +42,13 @@ do { \
26521 int __d0; \
26522 might_fault(); \
26523 __asm__ __volatile__( \
26524+ __COPYUSER_SET_ES \
26525 ASM_STAC "\n" \
26526 "0: rep; stosl\n" \
26527 " movl %2,%0\n" \
26528 "1: rep; stosb\n" \
26529 "2: " ASM_CLAC "\n" \
26530+ __COPYUSER_RESTORE_ES \
26531 ".section .fixup,\"ax\"\n" \
26532 "3: lea 0(%2,%0,4),%0\n" \
26533 " jmp 2b\n" \
26534@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26535
26536 #ifdef CONFIG_X86_INTEL_USERCOPY
26537 static unsigned long
26538-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26539+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26540 {
26541 int d0, d1;
26542 __asm__ __volatile__(
26543@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26544 " .align 2,0x90\n"
26545 "3: movl 0(%4), %%eax\n"
26546 "4: movl 4(%4), %%edx\n"
26547- "5: movl %%eax, 0(%3)\n"
26548- "6: movl %%edx, 4(%3)\n"
26549+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26550+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26551 "7: movl 8(%4), %%eax\n"
26552 "8: movl 12(%4),%%edx\n"
26553- "9: movl %%eax, 8(%3)\n"
26554- "10: movl %%edx, 12(%3)\n"
26555+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26556+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26557 "11: movl 16(%4), %%eax\n"
26558 "12: movl 20(%4), %%edx\n"
26559- "13: movl %%eax, 16(%3)\n"
26560- "14: movl %%edx, 20(%3)\n"
26561+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26562+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26563 "15: movl 24(%4), %%eax\n"
26564 "16: movl 28(%4), %%edx\n"
26565- "17: movl %%eax, 24(%3)\n"
26566- "18: movl %%edx, 28(%3)\n"
26567+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26568+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26569 "19: movl 32(%4), %%eax\n"
26570 "20: movl 36(%4), %%edx\n"
26571- "21: movl %%eax, 32(%3)\n"
26572- "22: movl %%edx, 36(%3)\n"
26573+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26574+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26575 "23: movl 40(%4), %%eax\n"
26576 "24: movl 44(%4), %%edx\n"
26577- "25: movl %%eax, 40(%3)\n"
26578- "26: movl %%edx, 44(%3)\n"
26579+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26580+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26581 "27: movl 48(%4), %%eax\n"
26582 "28: movl 52(%4), %%edx\n"
26583- "29: movl %%eax, 48(%3)\n"
26584- "30: movl %%edx, 52(%3)\n"
26585+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26586+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26587 "31: movl 56(%4), %%eax\n"
26588 "32: movl 60(%4), %%edx\n"
26589- "33: movl %%eax, 56(%3)\n"
26590- "34: movl %%edx, 60(%3)\n"
26591+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26592+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26593 " addl $-64, %0\n"
26594 " addl $64, %4\n"
26595 " addl $64, %3\n"
26596@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26597 " shrl $2, %0\n"
26598 " andl $3, %%eax\n"
26599 " cld\n"
26600+ __COPYUSER_SET_ES
26601 "99: rep; movsl\n"
26602 "36: movl %%eax, %0\n"
26603 "37: rep; movsb\n"
26604 "100:\n"
26605+ __COPYUSER_RESTORE_ES
26606 ".section .fixup,\"ax\"\n"
26607 "101: lea 0(%%eax,%0,4),%0\n"
26608 " jmp 100b\n"
26609@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26610 }
26611
26612 static unsigned long
26613+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26614+{
26615+ int d0, d1;
26616+ __asm__ __volatile__(
26617+ " .align 2,0x90\n"
26618+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26619+ " cmpl $67, %0\n"
26620+ " jbe 3f\n"
26621+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26622+ " .align 2,0x90\n"
26623+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26624+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26625+ "5: movl %%eax, 0(%3)\n"
26626+ "6: movl %%edx, 4(%3)\n"
26627+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26628+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26629+ "9: movl %%eax, 8(%3)\n"
26630+ "10: movl %%edx, 12(%3)\n"
26631+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26632+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26633+ "13: movl %%eax, 16(%3)\n"
26634+ "14: movl %%edx, 20(%3)\n"
26635+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26636+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26637+ "17: movl %%eax, 24(%3)\n"
26638+ "18: movl %%edx, 28(%3)\n"
26639+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26640+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26641+ "21: movl %%eax, 32(%3)\n"
26642+ "22: movl %%edx, 36(%3)\n"
26643+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26644+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26645+ "25: movl %%eax, 40(%3)\n"
26646+ "26: movl %%edx, 44(%3)\n"
26647+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26648+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26649+ "29: movl %%eax, 48(%3)\n"
26650+ "30: movl %%edx, 52(%3)\n"
26651+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26652+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26653+ "33: movl %%eax, 56(%3)\n"
26654+ "34: movl %%edx, 60(%3)\n"
26655+ " addl $-64, %0\n"
26656+ " addl $64, %4\n"
26657+ " addl $64, %3\n"
26658+ " cmpl $63, %0\n"
26659+ " ja 1b\n"
26660+ "35: movl %0, %%eax\n"
26661+ " shrl $2, %0\n"
26662+ " andl $3, %%eax\n"
26663+ " cld\n"
26664+ "99: rep; "__copyuser_seg" movsl\n"
26665+ "36: movl %%eax, %0\n"
26666+ "37: rep; "__copyuser_seg" movsb\n"
26667+ "100:\n"
26668+ ".section .fixup,\"ax\"\n"
26669+ "101: lea 0(%%eax,%0,4),%0\n"
26670+ " jmp 100b\n"
26671+ ".previous\n"
26672+ _ASM_EXTABLE(1b,100b)
26673+ _ASM_EXTABLE(2b,100b)
26674+ _ASM_EXTABLE(3b,100b)
26675+ _ASM_EXTABLE(4b,100b)
26676+ _ASM_EXTABLE(5b,100b)
26677+ _ASM_EXTABLE(6b,100b)
26678+ _ASM_EXTABLE(7b,100b)
26679+ _ASM_EXTABLE(8b,100b)
26680+ _ASM_EXTABLE(9b,100b)
26681+ _ASM_EXTABLE(10b,100b)
26682+ _ASM_EXTABLE(11b,100b)
26683+ _ASM_EXTABLE(12b,100b)
26684+ _ASM_EXTABLE(13b,100b)
26685+ _ASM_EXTABLE(14b,100b)
26686+ _ASM_EXTABLE(15b,100b)
26687+ _ASM_EXTABLE(16b,100b)
26688+ _ASM_EXTABLE(17b,100b)
26689+ _ASM_EXTABLE(18b,100b)
26690+ _ASM_EXTABLE(19b,100b)
26691+ _ASM_EXTABLE(20b,100b)
26692+ _ASM_EXTABLE(21b,100b)
26693+ _ASM_EXTABLE(22b,100b)
26694+ _ASM_EXTABLE(23b,100b)
26695+ _ASM_EXTABLE(24b,100b)
26696+ _ASM_EXTABLE(25b,100b)
26697+ _ASM_EXTABLE(26b,100b)
26698+ _ASM_EXTABLE(27b,100b)
26699+ _ASM_EXTABLE(28b,100b)
26700+ _ASM_EXTABLE(29b,100b)
26701+ _ASM_EXTABLE(30b,100b)
26702+ _ASM_EXTABLE(31b,100b)
26703+ _ASM_EXTABLE(32b,100b)
26704+ _ASM_EXTABLE(33b,100b)
26705+ _ASM_EXTABLE(34b,100b)
26706+ _ASM_EXTABLE(35b,100b)
26707+ _ASM_EXTABLE(36b,100b)
26708+ _ASM_EXTABLE(37b,100b)
26709+ _ASM_EXTABLE(99b,101b)
26710+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26711+ : "1"(to), "2"(from), "0"(size)
26712+ : "eax", "edx", "memory");
26713+ return size;
26714+}
26715+
26716+static unsigned long __size_overflow(3)
26717 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26718 {
26719 int d0, d1;
26720 __asm__ __volatile__(
26721 " .align 2,0x90\n"
26722- "0: movl 32(%4), %%eax\n"
26723+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26724 " cmpl $67, %0\n"
26725 " jbe 2f\n"
26726- "1: movl 64(%4), %%eax\n"
26727+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26728 " .align 2,0x90\n"
26729- "2: movl 0(%4), %%eax\n"
26730- "21: movl 4(%4), %%edx\n"
26731+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26732+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26733 " movl %%eax, 0(%3)\n"
26734 " movl %%edx, 4(%3)\n"
26735- "3: movl 8(%4), %%eax\n"
26736- "31: movl 12(%4),%%edx\n"
26737+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26738+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26739 " movl %%eax, 8(%3)\n"
26740 " movl %%edx, 12(%3)\n"
26741- "4: movl 16(%4), %%eax\n"
26742- "41: movl 20(%4), %%edx\n"
26743+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26744+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26745 " movl %%eax, 16(%3)\n"
26746 " movl %%edx, 20(%3)\n"
26747- "10: movl 24(%4), %%eax\n"
26748- "51: movl 28(%4), %%edx\n"
26749+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26750+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26751 " movl %%eax, 24(%3)\n"
26752 " movl %%edx, 28(%3)\n"
26753- "11: movl 32(%4), %%eax\n"
26754- "61: movl 36(%4), %%edx\n"
26755+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26756+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26757 " movl %%eax, 32(%3)\n"
26758 " movl %%edx, 36(%3)\n"
26759- "12: movl 40(%4), %%eax\n"
26760- "71: movl 44(%4), %%edx\n"
26761+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26762+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26763 " movl %%eax, 40(%3)\n"
26764 " movl %%edx, 44(%3)\n"
26765- "13: movl 48(%4), %%eax\n"
26766- "81: movl 52(%4), %%edx\n"
26767+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26768+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26769 " movl %%eax, 48(%3)\n"
26770 " movl %%edx, 52(%3)\n"
26771- "14: movl 56(%4), %%eax\n"
26772- "91: movl 60(%4), %%edx\n"
26773+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26774+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26775 " movl %%eax, 56(%3)\n"
26776 " movl %%edx, 60(%3)\n"
26777 " addl $-64, %0\n"
26778@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26779 " shrl $2, %0\n"
26780 " andl $3, %%eax\n"
26781 " cld\n"
26782- "6: rep; movsl\n"
26783+ "6: rep; "__copyuser_seg" movsl\n"
26784 " movl %%eax,%0\n"
26785- "7: rep; movsb\n"
26786+ "7: rep; "__copyuser_seg" movsb\n"
26787 "8:\n"
26788 ".section .fixup,\"ax\"\n"
26789 "9: lea 0(%%eax,%0,4),%0\n"
26790@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26791 * hyoshiok@miraclelinux.com
26792 */
26793
26794-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26795+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26796 const void __user *from, unsigned long size)
26797 {
26798 int d0, d1;
26799
26800 __asm__ __volatile__(
26801 " .align 2,0x90\n"
26802- "0: movl 32(%4), %%eax\n"
26803+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26804 " cmpl $67, %0\n"
26805 " jbe 2f\n"
26806- "1: movl 64(%4), %%eax\n"
26807+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26808 " .align 2,0x90\n"
26809- "2: movl 0(%4), %%eax\n"
26810- "21: movl 4(%4), %%edx\n"
26811+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26812+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26813 " movnti %%eax, 0(%3)\n"
26814 " movnti %%edx, 4(%3)\n"
26815- "3: movl 8(%4), %%eax\n"
26816- "31: movl 12(%4),%%edx\n"
26817+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26818+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26819 " movnti %%eax, 8(%3)\n"
26820 " movnti %%edx, 12(%3)\n"
26821- "4: movl 16(%4), %%eax\n"
26822- "41: movl 20(%4), %%edx\n"
26823+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26824+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26825 " movnti %%eax, 16(%3)\n"
26826 " movnti %%edx, 20(%3)\n"
26827- "10: movl 24(%4), %%eax\n"
26828- "51: movl 28(%4), %%edx\n"
26829+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26830+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26831 " movnti %%eax, 24(%3)\n"
26832 " movnti %%edx, 28(%3)\n"
26833- "11: movl 32(%4), %%eax\n"
26834- "61: movl 36(%4), %%edx\n"
26835+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26836+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26837 " movnti %%eax, 32(%3)\n"
26838 " movnti %%edx, 36(%3)\n"
26839- "12: movl 40(%4), %%eax\n"
26840- "71: movl 44(%4), %%edx\n"
26841+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26842+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26843 " movnti %%eax, 40(%3)\n"
26844 " movnti %%edx, 44(%3)\n"
26845- "13: movl 48(%4), %%eax\n"
26846- "81: movl 52(%4), %%edx\n"
26847+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26848+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26849 " movnti %%eax, 48(%3)\n"
26850 " movnti %%edx, 52(%3)\n"
26851- "14: movl 56(%4), %%eax\n"
26852- "91: movl 60(%4), %%edx\n"
26853+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26854+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26855 " movnti %%eax, 56(%3)\n"
26856 " movnti %%edx, 60(%3)\n"
26857 " addl $-64, %0\n"
26858@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26859 " shrl $2, %0\n"
26860 " andl $3, %%eax\n"
26861 " cld\n"
26862- "6: rep; movsl\n"
26863+ "6: rep; "__copyuser_seg" movsl\n"
26864 " movl %%eax,%0\n"
26865- "7: rep; movsb\n"
26866+ "7: rep; "__copyuser_seg" movsb\n"
26867 "8:\n"
26868 ".section .fixup,\"ax\"\n"
26869 "9: lea 0(%%eax,%0,4),%0\n"
26870@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26871 return size;
26872 }
26873
26874-static unsigned long __copy_user_intel_nocache(void *to,
26875+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26876 const void __user *from, unsigned long size)
26877 {
26878 int d0, d1;
26879
26880 __asm__ __volatile__(
26881 " .align 2,0x90\n"
26882- "0: movl 32(%4), %%eax\n"
26883+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26884 " cmpl $67, %0\n"
26885 " jbe 2f\n"
26886- "1: movl 64(%4), %%eax\n"
26887+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26888 " .align 2,0x90\n"
26889- "2: movl 0(%4), %%eax\n"
26890- "21: movl 4(%4), %%edx\n"
26891+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26892+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26893 " movnti %%eax, 0(%3)\n"
26894 " movnti %%edx, 4(%3)\n"
26895- "3: movl 8(%4), %%eax\n"
26896- "31: movl 12(%4),%%edx\n"
26897+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26898+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26899 " movnti %%eax, 8(%3)\n"
26900 " movnti %%edx, 12(%3)\n"
26901- "4: movl 16(%4), %%eax\n"
26902- "41: movl 20(%4), %%edx\n"
26903+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26904+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26905 " movnti %%eax, 16(%3)\n"
26906 " movnti %%edx, 20(%3)\n"
26907- "10: movl 24(%4), %%eax\n"
26908- "51: movl 28(%4), %%edx\n"
26909+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26910+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26911 " movnti %%eax, 24(%3)\n"
26912 " movnti %%edx, 28(%3)\n"
26913- "11: movl 32(%4), %%eax\n"
26914- "61: movl 36(%4), %%edx\n"
26915+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26916+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26917 " movnti %%eax, 32(%3)\n"
26918 " movnti %%edx, 36(%3)\n"
26919- "12: movl 40(%4), %%eax\n"
26920- "71: movl 44(%4), %%edx\n"
26921+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26922+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26923 " movnti %%eax, 40(%3)\n"
26924 " movnti %%edx, 44(%3)\n"
26925- "13: movl 48(%4), %%eax\n"
26926- "81: movl 52(%4), %%edx\n"
26927+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26928+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26929 " movnti %%eax, 48(%3)\n"
26930 " movnti %%edx, 52(%3)\n"
26931- "14: movl 56(%4), %%eax\n"
26932- "91: movl 60(%4), %%edx\n"
26933+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26934+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26935 " movnti %%eax, 56(%3)\n"
26936 " movnti %%edx, 60(%3)\n"
26937 " addl $-64, %0\n"
26938@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26939 " shrl $2, %0\n"
26940 " andl $3, %%eax\n"
26941 " cld\n"
26942- "6: rep; movsl\n"
26943+ "6: rep; "__copyuser_seg" movsl\n"
26944 " movl %%eax,%0\n"
26945- "7: rep; movsb\n"
26946+ "7: rep; "__copyuser_seg" movsb\n"
26947 "8:\n"
26948 ".section .fixup,\"ax\"\n"
26949 "9: lea 0(%%eax,%0,4),%0\n"
26950@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26951 */
26952 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26953 unsigned long size);
26954-unsigned long __copy_user_intel(void __user *to, const void *from,
26955+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26956+ unsigned long size);
26957+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26958 unsigned long size);
26959 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26960 const void __user *from, unsigned long size);
26961 #endif /* CONFIG_X86_INTEL_USERCOPY */
26962
26963 /* Generic arbitrary sized copy. */
26964-#define __copy_user(to, from, size) \
26965+#define __copy_user(to, from, size, prefix, set, restore) \
26966 do { \
26967 int __d0, __d1, __d2; \
26968 __asm__ __volatile__( \
26969+ set \
26970 " cmp $7,%0\n" \
26971 " jbe 1f\n" \
26972 " movl %1,%0\n" \
26973 " negl %0\n" \
26974 " andl $7,%0\n" \
26975 " subl %0,%3\n" \
26976- "4: rep; movsb\n" \
26977+ "4: rep; "prefix"movsb\n" \
26978 " movl %3,%0\n" \
26979 " shrl $2,%0\n" \
26980 " andl $3,%3\n" \
26981 " .align 2,0x90\n" \
26982- "0: rep; movsl\n" \
26983+ "0: rep; "prefix"movsl\n" \
26984 " movl %3,%0\n" \
26985- "1: rep; movsb\n" \
26986+ "1: rep; "prefix"movsb\n" \
26987 "2:\n" \
26988+ restore \
26989 ".section .fixup,\"ax\"\n" \
26990 "5: addl %3,%0\n" \
26991 " jmp 2b\n" \
26992@@ -538,14 +650,14 @@ do { \
26993 " negl %0\n" \
26994 " andl $7,%0\n" \
26995 " subl %0,%3\n" \
26996- "4: rep; movsb\n" \
26997+ "4: rep; "__copyuser_seg"movsb\n" \
26998 " movl %3,%0\n" \
26999 " shrl $2,%0\n" \
27000 " andl $3,%3\n" \
27001 " .align 2,0x90\n" \
27002- "0: rep; movsl\n" \
27003+ "0: rep; "__copyuser_seg"movsl\n" \
27004 " movl %3,%0\n" \
27005- "1: rep; movsb\n" \
27006+ "1: rep; "__copyuser_seg"movsb\n" \
27007 "2:\n" \
27008 ".section .fixup,\"ax\"\n" \
27009 "5: addl %3,%0\n" \
27010@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
27011 {
27012 stac();
27013 if (movsl_is_ok(to, from, n))
27014- __copy_user(to, from, n);
27015+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
27016 else
27017- n = __copy_user_intel(to, from, n);
27018+ n = __generic_copy_to_user_intel(to, from, n);
27019 clac();
27020 return n;
27021 }
27022@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
27023 {
27024 stac();
27025 if (movsl_is_ok(to, from, n))
27026- __copy_user(to, from, n);
27027+ __copy_user(to, from, n, __copyuser_seg, "", "");
27028 else
27029- n = __copy_user_intel((void __user *)to,
27030- (const void *)from, n);
27031+ n = __generic_copy_from_user_intel(to, from, n);
27032 clac();
27033 return n;
27034 }
27035@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
27036 if (n > 64 && cpu_has_xmm2)
27037 n = __copy_user_intel_nocache(to, from, n);
27038 else
27039- __copy_user(to, from, n);
27040+ __copy_user(to, from, n, __copyuser_seg, "", "");
27041 #else
27042- __copy_user(to, from, n);
27043+ __copy_user(to, from, n, __copyuser_seg, "", "");
27044 #endif
27045 clac();
27046 return n;
27047 }
27048 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
27049
27050-/**
27051- * copy_to_user: - Copy a block of data into user space.
27052- * @to: Destination address, in user space.
27053- * @from: Source address, in kernel space.
27054- * @n: Number of bytes to copy.
27055- *
27056- * Context: User context only. This function may sleep.
27057- *
27058- * Copy data from kernel space to user space.
27059- *
27060- * Returns number of bytes that could not be copied.
27061- * On success, this will be zero.
27062- */
27063-unsigned long
27064-copy_to_user(void __user *to, const void *from, unsigned long n)
27065+#ifdef CONFIG_PAX_MEMORY_UDEREF
27066+void __set_fs(mm_segment_t x)
27067 {
27068- if (access_ok(VERIFY_WRITE, to, n))
27069- n = __copy_to_user(to, from, n);
27070- return n;
27071+ switch (x.seg) {
27072+ case 0:
27073+ loadsegment(gs, 0);
27074+ break;
27075+ case TASK_SIZE_MAX:
27076+ loadsegment(gs, __USER_DS);
27077+ break;
27078+ case -1UL:
27079+ loadsegment(gs, __KERNEL_DS);
27080+ break;
27081+ default:
27082+ BUG();
27083+ }
27084 }
27085-EXPORT_SYMBOL(copy_to_user);
27086+EXPORT_SYMBOL(__set_fs);
27087
27088-/**
27089- * copy_from_user: - Copy a block of data from user space.
27090- * @to: Destination address, in kernel space.
27091- * @from: Source address, in user space.
27092- * @n: Number of bytes to copy.
27093- *
27094- * Context: User context only. This function may sleep.
27095- *
27096- * Copy data from user space to kernel space.
27097- *
27098- * Returns number of bytes that could not be copied.
27099- * On success, this will be zero.
27100- *
27101- * If some data could not be copied, this function will pad the copied
27102- * data to the requested size using zero bytes.
27103- */
27104-unsigned long
27105-_copy_from_user(void *to, const void __user *from, unsigned long n)
27106+void set_fs(mm_segment_t x)
27107 {
27108- if (access_ok(VERIFY_READ, from, n))
27109- n = __copy_from_user(to, from, n);
27110- else
27111- memset(to, 0, n);
27112- return n;
27113+ current_thread_info()->addr_limit = x;
27114+ __set_fs(x);
27115 }
27116-EXPORT_SYMBOL(_copy_from_user);
27117+EXPORT_SYMBOL(set_fs);
27118+#endif
27119diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27120index 906fea3..5646695 100644
27121--- a/arch/x86/lib/usercopy_64.c
27122+++ b/arch/x86/lib/usercopy_64.c
27123@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27124 _ASM_EXTABLE(0b,3b)
27125 _ASM_EXTABLE(1b,2b)
27126 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27127- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27128+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27129 [zero] "r" (0UL), [eight] "r" (8UL));
27130 clac();
27131 return size;
27132@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27133 }
27134 EXPORT_SYMBOL(clear_user);
27135
27136-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27137+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27138 {
27139- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27140- return copy_user_generic((__force void *)to, (__force void *)from, len);
27141- }
27142- return len;
27143+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27144+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27145+ return len;
27146 }
27147 EXPORT_SYMBOL(copy_in_user);
27148
27149@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27150 * it is not necessary to optimize tail handling.
27151 */
27152 unsigned long
27153-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27154+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27155 {
27156 char c;
27157 unsigned zero_len;
27158diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27159index 903ec1e..c4166b2 100644
27160--- a/arch/x86/mm/extable.c
27161+++ b/arch/x86/mm/extable.c
27162@@ -6,12 +6,24 @@
27163 static inline unsigned long
27164 ex_insn_addr(const struct exception_table_entry *x)
27165 {
27166- return (unsigned long)&x->insn + x->insn;
27167+ unsigned long reloc = 0;
27168+
27169+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27170+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27171+#endif
27172+
27173+ return (unsigned long)&x->insn + x->insn + reloc;
27174 }
27175 static inline unsigned long
27176 ex_fixup_addr(const struct exception_table_entry *x)
27177 {
27178- return (unsigned long)&x->fixup + x->fixup;
27179+ unsigned long reloc = 0;
27180+
27181+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27182+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27183+#endif
27184+
27185+ return (unsigned long)&x->fixup + x->fixup + reloc;
27186 }
27187
27188 int fixup_exception(struct pt_regs *regs)
27189@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27190 unsigned long new_ip;
27191
27192 #ifdef CONFIG_PNPBIOS
27193- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27194+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27195 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27196 extern u32 pnp_bios_is_utter_crap;
27197 pnp_bios_is_utter_crap = 1;
27198@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27199 i += 4;
27200 p->fixup -= i;
27201 i += 4;
27202+
27203+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27204+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27205+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27206+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27207+#endif
27208+
27209 }
27210 }
27211
27212diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27213index 654be4a..d36985f 100644
27214--- a/arch/x86/mm/fault.c
27215+++ b/arch/x86/mm/fault.c
27216@@ -14,11 +14,18 @@
27217 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27218 #include <linux/prefetch.h> /* prefetchw */
27219 #include <linux/context_tracking.h> /* exception_enter(), ... */
27220+#include <linux/unistd.h>
27221+#include <linux/compiler.h>
27222
27223 #include <asm/traps.h> /* dotraplinkage, ... */
27224 #include <asm/pgalloc.h> /* pgd_*(), ... */
27225 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27226 #include <asm/fixmap.h> /* VSYSCALL_START */
27227+#include <asm/tlbflush.h>
27228+
27229+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27230+#include <asm/stacktrace.h>
27231+#endif
27232
27233 /*
27234 * Page fault error code bits:
27235@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27236 int ret = 0;
27237
27238 /* kprobe_running() needs smp_processor_id() */
27239- if (kprobes_built_in() && !user_mode_vm(regs)) {
27240+ if (kprobes_built_in() && !user_mode(regs)) {
27241 preempt_disable();
27242 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27243 ret = 1;
27244@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27245 return !instr_lo || (instr_lo>>1) == 1;
27246 case 0x00:
27247 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27248- if (probe_kernel_address(instr, opcode))
27249+ if (user_mode(regs)) {
27250+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27251+ return 0;
27252+ } else if (probe_kernel_address(instr, opcode))
27253 return 0;
27254
27255 *prefetch = (instr_lo == 0xF) &&
27256@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27257 while (instr < max_instr) {
27258 unsigned char opcode;
27259
27260- if (probe_kernel_address(instr, opcode))
27261+ if (user_mode(regs)) {
27262+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27263+ break;
27264+ } else if (probe_kernel_address(instr, opcode))
27265 break;
27266
27267 instr++;
27268@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27269 force_sig_info(si_signo, &info, tsk);
27270 }
27271
27272+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27273+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27274+#endif
27275+
27276+#ifdef CONFIG_PAX_EMUTRAMP
27277+static int pax_handle_fetch_fault(struct pt_regs *regs);
27278+#endif
27279+
27280+#ifdef CONFIG_PAX_PAGEEXEC
27281+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27282+{
27283+ pgd_t *pgd;
27284+ pud_t *pud;
27285+ pmd_t *pmd;
27286+
27287+ pgd = pgd_offset(mm, address);
27288+ if (!pgd_present(*pgd))
27289+ return NULL;
27290+ pud = pud_offset(pgd, address);
27291+ if (!pud_present(*pud))
27292+ return NULL;
27293+ pmd = pmd_offset(pud, address);
27294+ if (!pmd_present(*pmd))
27295+ return NULL;
27296+ return pmd;
27297+}
27298+#endif
27299+
27300 DEFINE_SPINLOCK(pgd_lock);
27301 LIST_HEAD(pgd_list);
27302
27303@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27304 for (address = VMALLOC_START & PMD_MASK;
27305 address >= TASK_SIZE && address < FIXADDR_TOP;
27306 address += PMD_SIZE) {
27307+
27308+#ifdef CONFIG_PAX_PER_CPU_PGD
27309+ unsigned long cpu;
27310+#else
27311 struct page *page;
27312+#endif
27313
27314 spin_lock(&pgd_lock);
27315+
27316+#ifdef CONFIG_PAX_PER_CPU_PGD
27317+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27318+ pgd_t *pgd = get_cpu_pgd(cpu);
27319+ pmd_t *ret;
27320+#else
27321 list_for_each_entry(page, &pgd_list, lru) {
27322+ pgd_t *pgd;
27323 spinlock_t *pgt_lock;
27324 pmd_t *ret;
27325
27326@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
27327 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27328
27329 spin_lock(pgt_lock);
27330- ret = vmalloc_sync_one(page_address(page), address);
27331+ pgd = page_address(page);
27332+#endif
27333+
27334+ ret = vmalloc_sync_one(pgd, address);
27335+
27336+#ifndef CONFIG_PAX_PER_CPU_PGD
27337 spin_unlock(pgt_lock);
27338+#endif
27339
27340 if (!ret)
27341 break;
27342@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27343 * an interrupt in the middle of a task switch..
27344 */
27345 pgd_paddr = read_cr3();
27346+
27347+#ifdef CONFIG_PAX_PER_CPU_PGD
27348+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27349+#endif
27350+
27351 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27352 if (!pmd_k)
27353 return -1;
27354@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27355 * happen within a race in page table update. In the later
27356 * case just flush:
27357 */
27358+
27359+#ifdef CONFIG_PAX_PER_CPU_PGD
27360+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27361+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27362+#else
27363 pgd = pgd_offset(current->active_mm, address);
27364+#endif
27365+
27366 pgd_ref = pgd_offset_k(address);
27367 if (pgd_none(*pgd_ref))
27368 return -1;
27369@@ -543,7 +614,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27370 static int is_errata100(struct pt_regs *regs, unsigned long address)
27371 {
27372 #ifdef CONFIG_X86_64
27373- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27374+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27375 return 1;
27376 #endif
27377 return 0;
27378@@ -570,7 +641,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27379 }
27380
27381 static const char nx_warning[] = KERN_CRIT
27382-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27383+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27384
27385 static void
27386 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27387@@ -579,15 +650,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27388 if (!oops_may_print())
27389 return;
27390
27391- if (error_code & PF_INSTR) {
27392+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27393 unsigned int level;
27394
27395 pte_t *pte = lookup_address(address, &level);
27396
27397 if (pte && pte_present(*pte) && !pte_exec(*pte))
27398- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27399+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27400 }
27401
27402+#ifdef CONFIG_PAX_KERNEXEC
27403+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27404+ if (current->signal->curr_ip)
27405+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27406+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27407+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27408+ else
27409+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27410+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27411+ }
27412+#endif
27413+
27414 printk(KERN_ALERT "BUG: unable to handle kernel ");
27415 if (address < PAGE_SIZE)
27416 printk(KERN_CONT "NULL pointer dereference");
27417@@ -750,6 +833,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27418 return;
27419 }
27420 #endif
27421+
27422+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27423+ if (pax_is_fetch_fault(regs, error_code, address)) {
27424+
27425+#ifdef CONFIG_PAX_EMUTRAMP
27426+ switch (pax_handle_fetch_fault(regs)) {
27427+ case 2:
27428+ return;
27429+ }
27430+#endif
27431+
27432+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27433+ do_group_exit(SIGKILL);
27434+ }
27435+#endif
27436+
27437 /* Kernel addresses are always protection faults: */
27438 if (address >= TASK_SIZE)
27439 error_code |= PF_PROT;
27440@@ -835,7 +934,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27441 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27442 printk(KERN_ERR
27443 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27444- tsk->comm, tsk->pid, address);
27445+ tsk->comm, task_pid_nr(tsk), address);
27446 code = BUS_MCEERR_AR;
27447 }
27448 #endif
27449@@ -898,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27450 return 1;
27451 }
27452
27453+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27454+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27455+{
27456+ pte_t *pte;
27457+ pmd_t *pmd;
27458+ spinlock_t *ptl;
27459+ unsigned char pte_mask;
27460+
27461+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27462+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27463+ return 0;
27464+
27465+ /* PaX: it's our fault, let's handle it if we can */
27466+
27467+ /* PaX: take a look at read faults before acquiring any locks */
27468+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27469+ /* instruction fetch attempt from a protected page in user mode */
27470+ up_read(&mm->mmap_sem);
27471+
27472+#ifdef CONFIG_PAX_EMUTRAMP
27473+ switch (pax_handle_fetch_fault(regs)) {
27474+ case 2:
27475+ return 1;
27476+ }
27477+#endif
27478+
27479+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27480+ do_group_exit(SIGKILL);
27481+ }
27482+
27483+ pmd = pax_get_pmd(mm, address);
27484+ if (unlikely(!pmd))
27485+ return 0;
27486+
27487+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27488+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27489+ pte_unmap_unlock(pte, ptl);
27490+ return 0;
27491+ }
27492+
27493+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27494+ /* write attempt to a protected page in user mode */
27495+ pte_unmap_unlock(pte, ptl);
27496+ return 0;
27497+ }
27498+
27499+#ifdef CONFIG_SMP
27500+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27501+#else
27502+ if (likely(address > get_limit(regs->cs)))
27503+#endif
27504+ {
27505+ set_pte(pte, pte_mkread(*pte));
27506+ __flush_tlb_one(address);
27507+ pte_unmap_unlock(pte, ptl);
27508+ up_read(&mm->mmap_sem);
27509+ return 1;
27510+ }
27511+
27512+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27513+
27514+ /*
27515+ * PaX: fill DTLB with user rights and retry
27516+ */
27517+ __asm__ __volatile__ (
27518+ "orb %2,(%1)\n"
27519+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27520+/*
27521+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27522+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27523+ * page fault when examined during a TLB load attempt. this is true not only
27524+ * for PTEs holding a non-present entry but also present entries that will
27525+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27526+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27527+ * for our target pages since their PTEs are simply not in the TLBs at all.
27528+
27529+ * the best thing in omitting it is that we gain around 15-20% speed in the
27530+ * fast path of the page fault handler and can get rid of tracing since we
27531+ * can no longer flush unintended entries.
27532+ */
27533+ "invlpg (%0)\n"
27534+#endif
27535+ __copyuser_seg"testb $0,(%0)\n"
27536+ "xorb %3,(%1)\n"
27537+ :
27538+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27539+ : "memory", "cc");
27540+ pte_unmap_unlock(pte, ptl);
27541+ up_read(&mm->mmap_sem);
27542+ return 1;
27543+}
27544+#endif
27545+
27546 /*
27547 * Handle a spurious fault caused by a stale TLB entry.
27548 *
27549@@ -964,6 +1156,9 @@ int show_unhandled_signals = 1;
27550 static inline int
27551 access_error(unsigned long error_code, struct vm_area_struct *vma)
27552 {
27553+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27554+ return 1;
27555+
27556 if (error_code & PF_WRITE) {
27557 /* write, present and write, not present: */
27558 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27559@@ -992,7 +1187,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27560 if (error_code & PF_USER)
27561 return false;
27562
27563- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27564+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27565 return false;
27566
27567 return true;
27568@@ -1008,18 +1203,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27569 {
27570 struct vm_area_struct *vma;
27571 struct task_struct *tsk;
27572- unsigned long address;
27573 struct mm_struct *mm;
27574 int fault;
27575 int write = error_code & PF_WRITE;
27576 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27577 (write ? FAULT_FLAG_WRITE : 0);
27578
27579- tsk = current;
27580- mm = tsk->mm;
27581-
27582 /* Get the faulting address: */
27583- address = read_cr2();
27584+ unsigned long address = read_cr2();
27585+
27586+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27587+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
27588+ if (!search_exception_tables(regs->ip)) {
27589+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27590+ bad_area_nosemaphore(regs, error_code, address);
27591+ return;
27592+ }
27593+ if (address < pax_user_shadow_base) {
27594+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27595+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27596+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27597+ } else
27598+ address -= pax_user_shadow_base;
27599+ }
27600+#endif
27601+
27602+ tsk = current;
27603+ mm = tsk->mm;
27604
27605 /*
27606 * Detect and handle instructions that would cause a page fault for
27607@@ -1080,7 +1290,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27608 * User-mode registers count as a user access even for any
27609 * potential system fault or CPU buglet:
27610 */
27611- if (user_mode_vm(regs)) {
27612+ if (user_mode(regs)) {
27613 local_irq_enable();
27614 error_code |= PF_USER;
27615 } else {
27616@@ -1142,6 +1352,11 @@ retry:
27617 might_sleep();
27618 }
27619
27620+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27621+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27622+ return;
27623+#endif
27624+
27625 vma = find_vma(mm, address);
27626 if (unlikely(!vma)) {
27627 bad_area(regs, error_code, address);
27628@@ -1153,18 +1368,24 @@ retry:
27629 bad_area(regs, error_code, address);
27630 return;
27631 }
27632- if (error_code & PF_USER) {
27633- /*
27634- * Accessing the stack below %sp is always a bug.
27635- * The large cushion allows instructions like enter
27636- * and pusha to work. ("enter $65535, $31" pushes
27637- * 32 pointers and then decrements %sp by 65535.)
27638- */
27639- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27640- bad_area(regs, error_code, address);
27641- return;
27642- }
27643+ /*
27644+ * Accessing the stack below %sp is always a bug.
27645+ * The large cushion allows instructions like enter
27646+ * and pusha to work. ("enter $65535, $31" pushes
27647+ * 32 pointers and then decrements %sp by 65535.)
27648+ */
27649+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27650+ bad_area(regs, error_code, address);
27651+ return;
27652 }
27653+
27654+#ifdef CONFIG_PAX_SEGMEXEC
27655+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27656+ bad_area(regs, error_code, address);
27657+ return;
27658+ }
27659+#endif
27660+
27661 if (unlikely(expand_stack(vma, address))) {
27662 bad_area(regs, error_code, address);
27663 return;
27664@@ -1230,3 +1451,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27665 __do_page_fault(regs, error_code);
27666 exception_exit(prev_state);
27667 }
27668+
27669+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27670+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27671+{
27672+ struct mm_struct *mm = current->mm;
27673+ unsigned long ip = regs->ip;
27674+
27675+ if (v8086_mode(regs))
27676+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27677+
27678+#ifdef CONFIG_PAX_PAGEEXEC
27679+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27680+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27681+ return true;
27682+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27683+ return true;
27684+ return false;
27685+ }
27686+#endif
27687+
27688+#ifdef CONFIG_PAX_SEGMEXEC
27689+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27690+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27691+ return true;
27692+ return false;
27693+ }
27694+#endif
27695+
27696+ return false;
27697+}
27698+#endif
27699+
27700+#ifdef CONFIG_PAX_EMUTRAMP
27701+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27702+{
27703+ int err;
27704+
27705+ do { /* PaX: libffi trampoline emulation */
27706+ unsigned char mov, jmp;
27707+ unsigned int addr1, addr2;
27708+
27709+#ifdef CONFIG_X86_64
27710+ if ((regs->ip + 9) >> 32)
27711+ break;
27712+#endif
27713+
27714+ err = get_user(mov, (unsigned char __user *)regs->ip);
27715+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27716+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27717+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27718+
27719+ if (err)
27720+ break;
27721+
27722+ if (mov == 0xB8 && jmp == 0xE9) {
27723+ regs->ax = addr1;
27724+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27725+ return 2;
27726+ }
27727+ } while (0);
27728+
27729+ do { /* PaX: gcc trampoline emulation #1 */
27730+ unsigned char mov1, mov2;
27731+ unsigned short jmp;
27732+ unsigned int addr1, addr2;
27733+
27734+#ifdef CONFIG_X86_64
27735+ if ((regs->ip + 11) >> 32)
27736+ break;
27737+#endif
27738+
27739+ err = get_user(mov1, (unsigned char __user *)regs->ip);
27740+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27741+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27742+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27743+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27744+
27745+ if (err)
27746+ break;
27747+
27748+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27749+ regs->cx = addr1;
27750+ regs->ax = addr2;
27751+ regs->ip = addr2;
27752+ return 2;
27753+ }
27754+ } while (0);
27755+
27756+ do { /* PaX: gcc trampoline emulation #2 */
27757+ unsigned char mov, jmp;
27758+ unsigned int addr1, addr2;
27759+
27760+#ifdef CONFIG_X86_64
27761+ if ((regs->ip + 9) >> 32)
27762+ break;
27763+#endif
27764+
27765+ err = get_user(mov, (unsigned char __user *)regs->ip);
27766+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27767+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27768+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27769+
27770+ if (err)
27771+ break;
27772+
27773+ if (mov == 0xB9 && jmp == 0xE9) {
27774+ regs->cx = addr1;
27775+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27776+ return 2;
27777+ }
27778+ } while (0);
27779+
27780+ return 1; /* PaX in action */
27781+}
27782+
27783+#ifdef CONFIG_X86_64
27784+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27785+{
27786+ int err;
27787+
27788+ do { /* PaX: libffi trampoline emulation */
27789+ unsigned short mov1, mov2, jmp1;
27790+ unsigned char stcclc, jmp2;
27791+ unsigned long addr1, addr2;
27792+
27793+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27794+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27795+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27796+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27797+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27798+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27799+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27800+
27801+ if (err)
27802+ break;
27803+
27804+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27805+ regs->r11 = addr1;
27806+ regs->r10 = addr2;
27807+ if (stcclc == 0xF8)
27808+ regs->flags &= ~X86_EFLAGS_CF;
27809+ else
27810+ regs->flags |= X86_EFLAGS_CF;
27811+ regs->ip = addr1;
27812+ return 2;
27813+ }
27814+ } while (0);
27815+
27816+ do { /* PaX: gcc trampoline emulation #1 */
27817+ unsigned short mov1, mov2, jmp1;
27818+ unsigned char jmp2;
27819+ unsigned int addr1;
27820+ unsigned long addr2;
27821+
27822+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27823+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27824+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27825+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27826+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27827+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27828+
27829+ if (err)
27830+ break;
27831+
27832+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27833+ regs->r11 = addr1;
27834+ regs->r10 = addr2;
27835+ regs->ip = addr1;
27836+ return 2;
27837+ }
27838+ } while (0);
27839+
27840+ do { /* PaX: gcc trampoline emulation #2 */
27841+ unsigned short mov1, mov2, jmp1;
27842+ unsigned char jmp2;
27843+ unsigned long addr1, addr2;
27844+
27845+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27846+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27847+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27848+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27849+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27850+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27851+
27852+ if (err)
27853+ break;
27854+
27855+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27856+ regs->r11 = addr1;
27857+ regs->r10 = addr2;
27858+ regs->ip = addr1;
27859+ return 2;
27860+ }
27861+ } while (0);
27862+
27863+ return 1; /* PaX in action */
27864+}
27865+#endif
27866+
27867+/*
27868+ * PaX: decide what to do with offenders (regs->ip = fault address)
27869+ *
27870+ * returns 1 when task should be killed
27871+ * 2 when gcc trampoline was detected
27872+ */
27873+static int pax_handle_fetch_fault(struct pt_regs *regs)
27874+{
27875+ if (v8086_mode(regs))
27876+ return 1;
27877+
27878+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27879+ return 1;
27880+
27881+#ifdef CONFIG_X86_32
27882+ return pax_handle_fetch_fault_32(regs);
27883+#else
27884+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27885+ return pax_handle_fetch_fault_32(regs);
27886+ else
27887+ return pax_handle_fetch_fault_64(regs);
27888+#endif
27889+}
27890+#endif
27891+
27892+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27893+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27894+{
27895+ long i;
27896+
27897+ printk(KERN_ERR "PAX: bytes at PC: ");
27898+ for (i = 0; i < 20; i++) {
27899+ unsigned char c;
27900+ if (get_user(c, (unsigned char __force_user *)pc+i))
27901+ printk(KERN_CONT "?? ");
27902+ else
27903+ printk(KERN_CONT "%02x ", c);
27904+ }
27905+ printk("\n");
27906+
27907+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27908+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27909+ unsigned long c;
27910+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27911+#ifdef CONFIG_X86_32
27912+ printk(KERN_CONT "???????? ");
27913+#else
27914+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27915+ printk(KERN_CONT "???????? ???????? ");
27916+ else
27917+ printk(KERN_CONT "???????????????? ");
27918+#endif
27919+ } else {
27920+#ifdef CONFIG_X86_64
27921+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27922+ printk(KERN_CONT "%08x ", (unsigned int)c);
27923+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27924+ } else
27925+#endif
27926+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27927+ }
27928+ }
27929+ printk("\n");
27930+}
27931+#endif
27932+
27933+/**
27934+ * probe_kernel_write(): safely attempt to write to a location
27935+ * @dst: address to write to
27936+ * @src: pointer to the data that shall be written
27937+ * @size: size of the data chunk
27938+ *
27939+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27940+ * happens, handle that and return -EFAULT.
27941+ */
27942+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27943+{
27944+ long ret;
27945+ mm_segment_t old_fs = get_fs();
27946+
27947+ set_fs(KERNEL_DS);
27948+ pagefault_disable();
27949+ pax_open_kernel();
27950+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27951+ pax_close_kernel();
27952+ pagefault_enable();
27953+ set_fs(old_fs);
27954+
27955+ return ret ? -EFAULT : 0;
27956+}
27957diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27958index dd74e46..7d26398 100644
27959--- a/arch/x86/mm/gup.c
27960+++ b/arch/x86/mm/gup.c
27961@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27962 addr = start;
27963 len = (unsigned long) nr_pages << PAGE_SHIFT;
27964 end = start + len;
27965- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27966+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27967 (void __user *)start, len)))
27968 return 0;
27969
27970diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27971index 252b8f5..4dcfdc1 100644
27972--- a/arch/x86/mm/highmem_32.c
27973+++ b/arch/x86/mm/highmem_32.c
27974@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27975 idx = type + KM_TYPE_NR*smp_processor_id();
27976 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27977 BUG_ON(!pte_none(*(kmap_pte-idx)));
27978+
27979+ pax_open_kernel();
27980 set_pte(kmap_pte-idx, mk_pte(page, prot));
27981+ pax_close_kernel();
27982+
27983 arch_flush_lazy_mmu_mode();
27984
27985 return (void *)vaddr;
27986diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27987index ae1aa71..d9bea75 100644
27988--- a/arch/x86/mm/hugetlbpage.c
27989+++ b/arch/x86/mm/hugetlbpage.c
27990@@ -271,23 +271,30 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
27991 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
27992 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27993 unsigned long addr, unsigned long len,
27994- unsigned long pgoff, unsigned long flags)
27995+ unsigned long pgoff, unsigned long flags, unsigned long offset)
27996 {
27997 struct hstate *h = hstate_file(file);
27998 struct vm_unmapped_area_info info;
27999-
28000+
28001 info.flags = 0;
28002 info.length = len;
28003 info.low_limit = TASK_UNMAPPED_BASE;
28004+
28005+#ifdef CONFIG_PAX_RANDMMAP
28006+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28007+ info.low_limit += current->mm->delta_mmap;
28008+#endif
28009+
28010 info.high_limit = TASK_SIZE;
28011 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28012 info.align_offset = 0;
28013+ info.threadstack_offset = offset;
28014 return vm_unmapped_area(&info);
28015 }
28016
28017 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28018 unsigned long addr0, unsigned long len,
28019- unsigned long pgoff, unsigned long flags)
28020+ unsigned long pgoff, unsigned long flags, unsigned long offset)
28021 {
28022 struct hstate *h = hstate_file(file);
28023 struct vm_unmapped_area_info info;
28024@@ -299,6 +306,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28025 info.high_limit = current->mm->mmap_base;
28026 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28027 info.align_offset = 0;
28028+ info.threadstack_offset = offset;
28029 addr = vm_unmapped_area(&info);
28030
28031 /*
28032@@ -311,6 +319,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28033 VM_BUG_ON(addr != -ENOMEM);
28034 info.flags = 0;
28035 info.low_limit = TASK_UNMAPPED_BASE;
28036+
28037+#ifdef CONFIG_PAX_RANDMMAP
28038+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28039+ info.low_limit += current->mm->delta_mmap;
28040+#endif
28041+
28042 info.high_limit = TASK_SIZE;
28043 addr = vm_unmapped_area(&info);
28044 }
28045@@ -325,10 +339,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28046 struct hstate *h = hstate_file(file);
28047 struct mm_struct *mm = current->mm;
28048 struct vm_area_struct *vma;
28049+ unsigned long pax_task_size = TASK_SIZE;
28050+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
28051
28052 if (len & ~huge_page_mask(h))
28053 return -EINVAL;
28054- if (len > TASK_SIZE)
28055+
28056+#ifdef CONFIG_PAX_SEGMEXEC
28057+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28058+ pax_task_size = SEGMEXEC_TASK_SIZE;
28059+#endif
28060+
28061+ pax_task_size -= PAGE_SIZE;
28062+
28063+ if (len > pax_task_size)
28064 return -ENOMEM;
28065
28066 if (flags & MAP_FIXED) {
28067@@ -337,19 +361,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28068 return addr;
28069 }
28070
28071+#ifdef CONFIG_PAX_RANDMMAP
28072+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28073+#endif
28074+
28075 if (addr) {
28076 addr = ALIGN(addr, huge_page_size(h));
28077 vma = find_vma(mm, addr);
28078- if (TASK_SIZE - len >= addr &&
28079- (!vma || addr + len <= vma->vm_start))
28080+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28081 return addr;
28082 }
28083 if (mm->get_unmapped_area == arch_get_unmapped_area)
28084 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
28085- pgoff, flags);
28086+ pgoff, flags, offset);
28087 else
28088 return hugetlb_get_unmapped_area_topdown(file, addr, len,
28089- pgoff, flags);
28090+ pgoff, flags, offset);
28091 }
28092
28093 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
28094diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
28095index 1f34e92..d252637 100644
28096--- a/arch/x86/mm/init.c
28097+++ b/arch/x86/mm/init.c
28098@@ -4,6 +4,7 @@
28099 #include <linux/swap.h>
28100 #include <linux/memblock.h>
28101 #include <linux/bootmem.h> /* for max_low_pfn */
28102+#include <linux/tboot.h>
28103
28104 #include <asm/cacheflush.h>
28105 #include <asm/e820.h>
28106@@ -17,6 +18,8 @@
28107 #include <asm/proto.h>
28108 #include <asm/dma.h> /* for MAX_DMA_PFN */
28109 #include <asm/microcode.h>
28110+#include <asm/desc.h>
28111+#include <asm/bios_ebda.h>
28112
28113 #include "mm_internal.h"
28114
28115@@ -465,7 +468,15 @@ void __init init_mem_mapping(void)
28116 early_ioremap_page_table_range_init();
28117 #endif
28118
28119+#ifdef CONFIG_PAX_PER_CPU_PGD
28120+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28121+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28122+ KERNEL_PGD_PTRS);
28123+ load_cr3(get_cpu_pgd(0));
28124+#else
28125 load_cr3(swapper_pg_dir);
28126+#endif
28127+
28128 __flush_tlb_all();
28129
28130 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
28131@@ -481,10 +492,40 @@ void __init init_mem_mapping(void)
28132 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
28133 * mmio resources as well as potential bios/acpi data regions.
28134 */
28135+
28136+#ifdef CONFIG_GRKERNSEC_KMEM
28137+static unsigned int ebda_start __read_only;
28138+static unsigned int ebda_end __read_only;
28139+#endif
28140+
28141 int devmem_is_allowed(unsigned long pagenr)
28142 {
28143- if (pagenr < 256)
28144+#ifdef CONFIG_GRKERNSEC_KMEM
28145+ /* allow BDA */
28146+ if (!pagenr)
28147 return 1;
28148+ /* allow EBDA */
28149+ if (pagenr >= ebda_start && pagenr < ebda_end)
28150+ return 1;
28151+ /* if tboot is in use, allow access to its hardcoded serial log range */
28152+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28153+ return 1;
28154+#else
28155+ if (!pagenr)
28156+ return 1;
28157+#ifdef CONFIG_VM86
28158+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28159+ return 1;
28160+#endif
28161+#endif
28162+
28163+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28164+ return 1;
28165+#ifdef CONFIG_GRKERNSEC_KMEM
28166+ /* throw out everything else below 1MB */
28167+ if (pagenr <= 256)
28168+ return 0;
28169+#endif
28170 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28171 return 0;
28172 if (!page_is_ram(pagenr))
28173@@ -538,8 +579,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28174 #endif
28175 }
28176
28177+#ifdef CONFIG_GRKERNSEC_KMEM
28178+static inline void gr_init_ebda(void)
28179+{
28180+ unsigned int ebda_addr;
28181+ unsigned int ebda_size = 0;
28182+
28183+ ebda_addr = get_bios_ebda();
28184+ if (ebda_addr) {
28185+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28186+ ebda_size <<= 10;
28187+ }
28188+ if (ebda_addr && ebda_size) {
28189+ ebda_start = ebda_addr >> PAGE_SHIFT;
28190+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28191+ } else {
28192+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28193+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28194+ }
28195+}
28196+#else
28197+static inline void gr_init_ebda(void) { }
28198+#endif
28199+
28200 void free_initmem(void)
28201 {
28202+#ifdef CONFIG_PAX_KERNEXEC
28203+#ifdef CONFIG_X86_32
28204+ /* PaX: limit KERNEL_CS to actual size */
28205+ unsigned long addr, limit;
28206+ struct desc_struct d;
28207+ int cpu;
28208+#else
28209+ pgd_t *pgd;
28210+ pud_t *pud;
28211+ pmd_t *pmd;
28212+ unsigned long addr, end;
28213+#endif
28214+#endif
28215+
28216+ gr_init_ebda();
28217+
28218+#ifdef CONFIG_PAX_KERNEXEC
28219+#ifdef CONFIG_X86_32
28220+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28221+ limit = (limit - 1UL) >> PAGE_SHIFT;
28222+
28223+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28224+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28225+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28226+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28227+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28228+ }
28229+
28230+ /* PaX: make KERNEL_CS read-only */
28231+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28232+ if (!paravirt_enabled())
28233+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28234+/*
28235+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28236+ pgd = pgd_offset_k(addr);
28237+ pud = pud_offset(pgd, addr);
28238+ pmd = pmd_offset(pud, addr);
28239+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28240+ }
28241+*/
28242+#ifdef CONFIG_X86_PAE
28243+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28244+/*
28245+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28246+ pgd = pgd_offset_k(addr);
28247+ pud = pud_offset(pgd, addr);
28248+ pmd = pmd_offset(pud, addr);
28249+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28250+ }
28251+*/
28252+#endif
28253+
28254+#ifdef CONFIG_MODULES
28255+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28256+#endif
28257+
28258+#else
28259+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28260+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28261+ pgd = pgd_offset_k(addr);
28262+ pud = pud_offset(pgd, addr);
28263+ pmd = pmd_offset(pud, addr);
28264+ if (!pmd_present(*pmd))
28265+ continue;
28266+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28267+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28268+ else
28269+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28270+ }
28271+
28272+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28273+ end = addr + KERNEL_IMAGE_SIZE;
28274+ for (; addr < end; addr += PMD_SIZE) {
28275+ pgd = pgd_offset_k(addr);
28276+ pud = pud_offset(pgd, addr);
28277+ pmd = pmd_offset(pud, addr);
28278+ if (!pmd_present(*pmd))
28279+ continue;
28280+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28281+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28282+ }
28283+#endif
28284+
28285+ flush_tlb_all();
28286+#endif
28287+
28288 free_init_pages("unused kernel memory",
28289 (unsigned long)(&__init_begin),
28290 (unsigned long)(&__init_end));
28291diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28292index 3ac7e31..89611b7 100644
28293--- a/arch/x86/mm/init_32.c
28294+++ b/arch/x86/mm/init_32.c
28295@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
28296 bool __read_mostly __vmalloc_start_set = false;
28297
28298 /*
28299- * Creates a middle page table and puts a pointer to it in the
28300- * given global directory entry. This only returns the gd entry
28301- * in non-PAE compilation mode, since the middle layer is folded.
28302- */
28303-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28304-{
28305- pud_t *pud;
28306- pmd_t *pmd_table;
28307-
28308-#ifdef CONFIG_X86_PAE
28309- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28310- pmd_table = (pmd_t *)alloc_low_page();
28311- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28312- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28313- pud = pud_offset(pgd, 0);
28314- BUG_ON(pmd_table != pmd_offset(pud, 0));
28315-
28316- return pmd_table;
28317- }
28318-#endif
28319- pud = pud_offset(pgd, 0);
28320- pmd_table = pmd_offset(pud, 0);
28321-
28322- return pmd_table;
28323-}
28324-
28325-/*
28326 * Create a page table and place a pointer to it in a middle page
28327 * directory entry:
28328 */
28329@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28330 pte_t *page_table = (pte_t *)alloc_low_page();
28331
28332 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28333+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28334+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28335+#else
28336 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28337+#endif
28338 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28339 }
28340
28341 return pte_offset_kernel(pmd, 0);
28342 }
28343
28344+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28345+{
28346+ pud_t *pud;
28347+ pmd_t *pmd_table;
28348+
28349+ pud = pud_offset(pgd, 0);
28350+ pmd_table = pmd_offset(pud, 0);
28351+
28352+ return pmd_table;
28353+}
28354+
28355 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28356 {
28357 int pgd_idx = pgd_index(vaddr);
28358@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28359 int pgd_idx, pmd_idx;
28360 unsigned long vaddr;
28361 pgd_t *pgd;
28362+ pud_t *pud;
28363 pmd_t *pmd;
28364 pte_t *pte = NULL;
28365 unsigned long count = page_table_range_init_count(start, end);
28366@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28367 pgd = pgd_base + pgd_idx;
28368
28369 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28370- pmd = one_md_table_init(pgd);
28371- pmd = pmd + pmd_index(vaddr);
28372+ pud = pud_offset(pgd, vaddr);
28373+ pmd = pmd_offset(pud, vaddr);
28374+
28375+#ifdef CONFIG_X86_PAE
28376+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28377+#endif
28378+
28379 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28380 pmd++, pmd_idx++) {
28381 pte = page_table_kmap_check(one_page_table_init(pmd),
28382@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28383 }
28384 }
28385
28386-static inline int is_kernel_text(unsigned long addr)
28387+static inline int is_kernel_text(unsigned long start, unsigned long end)
28388 {
28389- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28390- return 1;
28391- return 0;
28392+ if ((start > ktla_ktva((unsigned long)_etext) ||
28393+ end <= ktla_ktva((unsigned long)_stext)) &&
28394+ (start > ktla_ktva((unsigned long)_einittext) ||
28395+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28396+
28397+#ifdef CONFIG_ACPI_SLEEP
28398+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28399+#endif
28400+
28401+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28402+ return 0;
28403+ return 1;
28404 }
28405
28406 /*
28407@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
28408 unsigned long last_map_addr = end;
28409 unsigned long start_pfn, end_pfn;
28410 pgd_t *pgd_base = swapper_pg_dir;
28411- int pgd_idx, pmd_idx, pte_ofs;
28412+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28413 unsigned long pfn;
28414 pgd_t *pgd;
28415+ pud_t *pud;
28416 pmd_t *pmd;
28417 pte_t *pte;
28418 unsigned pages_2m, pages_4k;
28419@@ -291,8 +295,13 @@ repeat:
28420 pfn = start_pfn;
28421 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28422 pgd = pgd_base + pgd_idx;
28423- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28424- pmd = one_md_table_init(pgd);
28425+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28426+ pud = pud_offset(pgd, 0);
28427+ pmd = pmd_offset(pud, 0);
28428+
28429+#ifdef CONFIG_X86_PAE
28430+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28431+#endif
28432
28433 if (pfn >= end_pfn)
28434 continue;
28435@@ -304,14 +313,13 @@ repeat:
28436 #endif
28437 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28438 pmd++, pmd_idx++) {
28439- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28440+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28441
28442 /*
28443 * Map with big pages if possible, otherwise
28444 * create normal page tables:
28445 */
28446 if (use_pse) {
28447- unsigned int addr2;
28448 pgprot_t prot = PAGE_KERNEL_LARGE;
28449 /*
28450 * first pass will use the same initial
28451@@ -322,11 +330,7 @@ repeat:
28452 _PAGE_PSE);
28453
28454 pfn &= PMD_MASK >> PAGE_SHIFT;
28455- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28456- PAGE_OFFSET + PAGE_SIZE-1;
28457-
28458- if (is_kernel_text(addr) ||
28459- is_kernel_text(addr2))
28460+ if (is_kernel_text(address, address + PMD_SIZE))
28461 prot = PAGE_KERNEL_LARGE_EXEC;
28462
28463 pages_2m++;
28464@@ -343,7 +347,7 @@ repeat:
28465 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28466 pte += pte_ofs;
28467 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28468- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28469+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28470 pgprot_t prot = PAGE_KERNEL;
28471 /*
28472 * first pass will use the same initial
28473@@ -351,7 +355,7 @@ repeat:
28474 */
28475 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28476
28477- if (is_kernel_text(addr))
28478+ if (is_kernel_text(address, address + PAGE_SIZE))
28479 prot = PAGE_KERNEL_EXEC;
28480
28481 pages_4k++;
28482@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
28483
28484 pud = pud_offset(pgd, va);
28485 pmd = pmd_offset(pud, va);
28486- if (!pmd_present(*pmd))
28487+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
28488 break;
28489
28490 /* should not be large page here */
28491@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
28492
28493 static void __init pagetable_init(void)
28494 {
28495- pgd_t *pgd_base = swapper_pg_dir;
28496-
28497- permanent_kmaps_init(pgd_base);
28498+ permanent_kmaps_init(swapper_pg_dir);
28499 }
28500
28501-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28502+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28503 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28504
28505 /* user-defined highmem size */
28506@@ -772,7 +774,7 @@ void __init mem_init(void)
28507 after_bootmem = 1;
28508
28509 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28510- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28511+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28512 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28513
28514 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28515@@ -813,10 +815,10 @@ void __init mem_init(void)
28516 ((unsigned long)&__init_end -
28517 (unsigned long)&__init_begin) >> 10,
28518
28519- (unsigned long)&_etext, (unsigned long)&_edata,
28520- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28521+ (unsigned long)&_sdata, (unsigned long)&_edata,
28522+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28523
28524- (unsigned long)&_text, (unsigned long)&_etext,
28525+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28526 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28527
28528 /*
28529@@ -906,6 +908,7 @@ void set_kernel_text_rw(void)
28530 if (!kernel_set_to_readonly)
28531 return;
28532
28533+ start = ktla_ktva(start);
28534 pr_debug("Set kernel text: %lx - %lx for read write\n",
28535 start, start+size);
28536
28537@@ -920,6 +923,7 @@ void set_kernel_text_ro(void)
28538 if (!kernel_set_to_readonly)
28539 return;
28540
28541+ start = ktla_ktva(start);
28542 pr_debug("Set kernel text: %lx - %lx for read only\n",
28543 start, start+size);
28544
28545@@ -948,6 +952,7 @@ void mark_rodata_ro(void)
28546 unsigned long start = PFN_ALIGN(_text);
28547 unsigned long size = PFN_ALIGN(_etext) - start;
28548
28549+ start = ktla_ktva(start);
28550 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28551 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28552 size >> 10);
28553diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28554index bb00c46..f31d2f0 100644
28555--- a/arch/x86/mm/init_64.c
28556+++ b/arch/x86/mm/init_64.c
28557@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28558 * around without checking the pgd every time.
28559 */
28560
28561-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28562+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28563 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28564
28565 int force_personality32;
28566@@ -184,12 +184,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28567
28568 for (address = start; address <= end; address += PGDIR_SIZE) {
28569 const pgd_t *pgd_ref = pgd_offset_k(address);
28570+
28571+#ifdef CONFIG_PAX_PER_CPU_PGD
28572+ unsigned long cpu;
28573+#else
28574 struct page *page;
28575+#endif
28576
28577 if (pgd_none(*pgd_ref))
28578 continue;
28579
28580 spin_lock(&pgd_lock);
28581+
28582+#ifdef CONFIG_PAX_PER_CPU_PGD
28583+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28584+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28585+#else
28586 list_for_each_entry(page, &pgd_list, lru) {
28587 pgd_t *pgd;
28588 spinlock_t *pgt_lock;
28589@@ -198,6 +208,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28590 /* the pgt_lock only for Xen */
28591 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28592 spin_lock(pgt_lock);
28593+#endif
28594
28595 if (pgd_none(*pgd))
28596 set_pgd(pgd, *pgd_ref);
28597@@ -205,7 +216,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28598 BUG_ON(pgd_page_vaddr(*pgd)
28599 != pgd_page_vaddr(*pgd_ref));
28600
28601+#ifndef CONFIG_PAX_PER_CPU_PGD
28602 spin_unlock(pgt_lock);
28603+#endif
28604+
28605 }
28606 spin_unlock(&pgd_lock);
28607 }
28608@@ -238,7 +252,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28609 {
28610 if (pgd_none(*pgd)) {
28611 pud_t *pud = (pud_t *)spp_getpage();
28612- pgd_populate(&init_mm, pgd, pud);
28613+ pgd_populate_kernel(&init_mm, pgd, pud);
28614 if (pud != pud_offset(pgd, 0))
28615 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28616 pud, pud_offset(pgd, 0));
28617@@ -250,7 +264,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28618 {
28619 if (pud_none(*pud)) {
28620 pmd_t *pmd = (pmd_t *) spp_getpage();
28621- pud_populate(&init_mm, pud, pmd);
28622+ pud_populate_kernel(&init_mm, pud, pmd);
28623 if (pmd != pmd_offset(pud, 0))
28624 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28625 pmd, pmd_offset(pud, 0));
28626@@ -279,7 +293,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28627 pmd = fill_pmd(pud, vaddr);
28628 pte = fill_pte(pmd, vaddr);
28629
28630+ pax_open_kernel();
28631 set_pte(pte, new_pte);
28632+ pax_close_kernel();
28633
28634 /*
28635 * It's enough to flush this one mapping.
28636@@ -338,14 +354,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28637 pgd = pgd_offset_k((unsigned long)__va(phys));
28638 if (pgd_none(*pgd)) {
28639 pud = (pud_t *) spp_getpage();
28640- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28641- _PAGE_USER));
28642+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28643 }
28644 pud = pud_offset(pgd, (unsigned long)__va(phys));
28645 if (pud_none(*pud)) {
28646 pmd = (pmd_t *) spp_getpage();
28647- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28648- _PAGE_USER));
28649+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28650 }
28651 pmd = pmd_offset(pud, phys);
28652 BUG_ON(!pmd_none(*pmd));
28653@@ -586,7 +600,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28654 prot);
28655
28656 spin_lock(&init_mm.page_table_lock);
28657- pud_populate(&init_mm, pud, pmd);
28658+ pud_populate_kernel(&init_mm, pud, pmd);
28659 spin_unlock(&init_mm.page_table_lock);
28660 }
28661 __flush_tlb_all();
28662@@ -627,7 +641,7 @@ kernel_physical_mapping_init(unsigned long start,
28663 page_size_mask);
28664
28665 spin_lock(&init_mm.page_table_lock);
28666- pgd_populate(&init_mm, pgd, pud);
28667+ pgd_populate_kernel(&init_mm, pgd, pud);
28668 spin_unlock(&init_mm.page_table_lock);
28669 pgd_changed = true;
28670 }
28671@@ -1221,8 +1235,8 @@ int kern_addr_valid(unsigned long addr)
28672 static struct vm_area_struct gate_vma = {
28673 .vm_start = VSYSCALL_START,
28674 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28675- .vm_page_prot = PAGE_READONLY_EXEC,
28676- .vm_flags = VM_READ | VM_EXEC
28677+ .vm_page_prot = PAGE_READONLY,
28678+ .vm_flags = VM_READ
28679 };
28680
28681 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28682@@ -1256,7 +1270,7 @@ int in_gate_area_no_mm(unsigned long addr)
28683
28684 const char *arch_vma_name(struct vm_area_struct *vma)
28685 {
28686- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28687+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28688 return "[vdso]";
28689 if (vma == &gate_vma)
28690 return "[vsyscall]";
28691diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28692index 7b179b4..6bd17777 100644
28693--- a/arch/x86/mm/iomap_32.c
28694+++ b/arch/x86/mm/iomap_32.c
28695@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28696 type = kmap_atomic_idx_push();
28697 idx = type + KM_TYPE_NR * smp_processor_id();
28698 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28699+
28700+ pax_open_kernel();
28701 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28702+ pax_close_kernel();
28703+
28704 arch_flush_lazy_mmu_mode();
28705
28706 return (void *)vaddr;
28707diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28708index 9a1e658..da003f3 100644
28709--- a/arch/x86/mm/ioremap.c
28710+++ b/arch/x86/mm/ioremap.c
28711@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28712 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28713 int is_ram = page_is_ram(pfn);
28714
28715- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28716+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28717 return NULL;
28718 WARN_ON_ONCE(is_ram);
28719 }
28720@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28721 *
28722 * Caller must ensure there is only one unmapping for the same pointer.
28723 */
28724-void iounmap(volatile void __iomem *addr)
28725+void iounmap(const volatile void __iomem *addr)
28726 {
28727 struct vm_struct *p, *o;
28728
28729@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28730
28731 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28732 if (page_is_ram(start >> PAGE_SHIFT))
28733+#ifdef CONFIG_HIGHMEM
28734+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28735+#endif
28736 return __va(phys);
28737
28738 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28739@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28740 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
28741 {
28742 if (page_is_ram(phys >> PAGE_SHIFT))
28743+#ifdef CONFIG_HIGHMEM
28744+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
28745+#endif
28746 return;
28747
28748 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
28749@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
28750 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28751
28752 static __initdata int after_paging_init;
28753-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28754+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28755
28756 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28757 {
28758@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
28759 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28760
28761 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28762- memset(bm_pte, 0, sizeof(bm_pte));
28763- pmd_populate_kernel(&init_mm, pmd, bm_pte);
28764+ pmd_populate_user(&init_mm, pmd, bm_pte);
28765
28766 /*
28767 * The boot-ioremap range spans multiple pmds, for which
28768diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28769index d87dd6d..bf3fa66 100644
28770--- a/arch/x86/mm/kmemcheck/kmemcheck.c
28771+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28772@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28773 * memory (e.g. tracked pages)? For now, we need this to avoid
28774 * invoking kmemcheck for PnP BIOS calls.
28775 */
28776- if (regs->flags & X86_VM_MASK)
28777+ if (v8086_mode(regs))
28778 return false;
28779- if (regs->cs != __KERNEL_CS)
28780+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28781 return false;
28782
28783 pte = kmemcheck_pte_lookup(address);
28784diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28785index 845df68..1d8d29f 100644
28786--- a/arch/x86/mm/mmap.c
28787+++ b/arch/x86/mm/mmap.c
28788@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28789 * Leave an at least ~128 MB hole with possible stack randomization.
28790 */
28791 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28792-#define MAX_GAP (TASK_SIZE/6*5)
28793+#define MAX_GAP (pax_task_size/6*5)
28794
28795 static int mmap_is_legacy(void)
28796 {
28797@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28798 return rnd << PAGE_SHIFT;
28799 }
28800
28801-static unsigned long mmap_base(void)
28802+static unsigned long mmap_base(struct mm_struct *mm)
28803 {
28804 unsigned long gap = rlimit(RLIMIT_STACK);
28805+ unsigned long pax_task_size = TASK_SIZE;
28806+
28807+#ifdef CONFIG_PAX_SEGMEXEC
28808+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28809+ pax_task_size = SEGMEXEC_TASK_SIZE;
28810+#endif
28811
28812 if (gap < MIN_GAP)
28813 gap = MIN_GAP;
28814 else if (gap > MAX_GAP)
28815 gap = MAX_GAP;
28816
28817- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28818+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28819 }
28820
28821 /*
28822 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28823 * does, but not when emulating X86_32
28824 */
28825-static unsigned long mmap_legacy_base(void)
28826+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28827 {
28828- if (mmap_is_ia32())
28829+ if (mmap_is_ia32()) {
28830+
28831+#ifdef CONFIG_PAX_SEGMEXEC
28832+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28833+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28834+ else
28835+#endif
28836+
28837 return TASK_UNMAPPED_BASE;
28838- else
28839+ } else
28840 return TASK_UNMAPPED_BASE + mmap_rnd();
28841 }
28842
28843@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28844 void arch_pick_mmap_layout(struct mm_struct *mm)
28845 {
28846 if (mmap_is_legacy()) {
28847- mm->mmap_base = mmap_legacy_base();
28848+ mm->mmap_base = mmap_legacy_base(mm);
28849+
28850+#ifdef CONFIG_PAX_RANDMMAP
28851+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28852+ mm->mmap_base += mm->delta_mmap;
28853+#endif
28854+
28855 mm->get_unmapped_area = arch_get_unmapped_area;
28856 mm->unmap_area = arch_unmap_area;
28857 } else {
28858- mm->mmap_base = mmap_base();
28859+ mm->mmap_base = mmap_base(mm);
28860+
28861+#ifdef CONFIG_PAX_RANDMMAP
28862+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28863+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28864+#endif
28865+
28866 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28867 mm->unmap_area = arch_unmap_area_topdown;
28868 }
28869diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28870index dc0b727..f612039 100644
28871--- a/arch/x86/mm/mmio-mod.c
28872+++ b/arch/x86/mm/mmio-mod.c
28873@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28874 break;
28875 default:
28876 {
28877- unsigned char *ip = (unsigned char *)instptr;
28878+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28879 my_trace->opcode = MMIO_UNKNOWN_OP;
28880 my_trace->width = 0;
28881 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28882@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28883 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28884 void __iomem *addr)
28885 {
28886- static atomic_t next_id;
28887+ static atomic_unchecked_t next_id;
28888 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28889 /* These are page-unaligned. */
28890 struct mmiotrace_map map = {
28891@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28892 .private = trace
28893 },
28894 .phys = offset,
28895- .id = atomic_inc_return(&next_id)
28896+ .id = atomic_inc_return_unchecked(&next_id)
28897 };
28898 map.map_id = trace->id;
28899
28900@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28901 ioremap_trace_core(offset, size, addr);
28902 }
28903
28904-static void iounmap_trace_core(volatile void __iomem *addr)
28905+static void iounmap_trace_core(const volatile void __iomem *addr)
28906 {
28907 struct mmiotrace_map map = {
28908 .phys = 0,
28909@@ -328,7 +328,7 @@ not_enabled:
28910 }
28911 }
28912
28913-void mmiotrace_iounmap(volatile void __iomem *addr)
28914+void mmiotrace_iounmap(const volatile void __iomem *addr)
28915 {
28916 might_sleep();
28917 if (is_enabled()) /* recheck and proper locking in *_core() */
28918diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
28919index a71c4e2..301ae44 100644
28920--- a/arch/x86/mm/numa.c
28921+++ b/arch/x86/mm/numa.c
28922@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
28923 return true;
28924 }
28925
28926-static int __init numa_register_memblks(struct numa_meminfo *mi)
28927+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
28928 {
28929 unsigned long uninitialized_var(pfn_align);
28930 int i, nid;
28931diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28932index d0b1773..4c3327c 100644
28933--- a/arch/x86/mm/pageattr-test.c
28934+++ b/arch/x86/mm/pageattr-test.c
28935@@ -36,7 +36,7 @@ enum {
28936
28937 static int pte_testbit(pte_t pte)
28938 {
28939- return pte_flags(pte) & _PAGE_UNUSED1;
28940+ return pte_flags(pte) & _PAGE_CPA_TEST;
28941 }
28942
28943 struct split_state {
28944diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28945index bb32480..aef8278 100644
28946--- a/arch/x86/mm/pageattr.c
28947+++ b/arch/x86/mm/pageattr.c
28948@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28949 */
28950 #ifdef CONFIG_PCI_BIOS
28951 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28952- pgprot_val(forbidden) |= _PAGE_NX;
28953+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28954 #endif
28955
28956 /*
28957@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28958 * Does not cover __inittext since that is gone later on. On
28959 * 64bit we do not enforce !NX on the low mapping
28960 */
28961- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28962- pgprot_val(forbidden) |= _PAGE_NX;
28963+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28964+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28965
28966+#ifdef CONFIG_DEBUG_RODATA
28967 /*
28968 * The .rodata section needs to be read-only. Using the pfn
28969 * catches all aliases.
28970@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28971 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
28972 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
28973 pgprot_val(forbidden) |= _PAGE_RW;
28974+#endif
28975
28976 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28977 /*
28978@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28979 }
28980 #endif
28981
28982+#ifdef CONFIG_PAX_KERNEXEC
28983+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28984+ pgprot_val(forbidden) |= _PAGE_RW;
28985+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28986+ }
28987+#endif
28988+
28989 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28990
28991 return prot;
28992@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
28993 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28994 {
28995 /* change init_mm */
28996+ pax_open_kernel();
28997 set_pte_atomic(kpte, pte);
28998+
28999 #ifdef CONFIG_X86_32
29000 if (!SHARED_KERNEL_PMD) {
29001+
29002+#ifdef CONFIG_PAX_PER_CPU_PGD
29003+ unsigned long cpu;
29004+#else
29005 struct page *page;
29006+#endif
29007
29008+#ifdef CONFIG_PAX_PER_CPU_PGD
29009+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29010+ pgd_t *pgd = get_cpu_pgd(cpu);
29011+#else
29012 list_for_each_entry(page, &pgd_list, lru) {
29013- pgd_t *pgd;
29014+ pgd_t *pgd = (pgd_t *)page_address(page);
29015+#endif
29016+
29017 pud_t *pud;
29018 pmd_t *pmd;
29019
29020- pgd = (pgd_t *)page_address(page) + pgd_index(address);
29021+ pgd += pgd_index(address);
29022 pud = pud_offset(pgd, address);
29023 pmd = pmd_offset(pud, address);
29024 set_pte_atomic((pte_t *)pmd, pte);
29025 }
29026 }
29027 #endif
29028+ pax_close_kernel();
29029 }
29030
29031 static int
29032diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
29033index 6574388..87e9bef 100644
29034--- a/arch/x86/mm/pat.c
29035+++ b/arch/x86/mm/pat.c
29036@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
29037
29038 if (!entry) {
29039 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
29040- current->comm, current->pid, start, end - 1);
29041+ current->comm, task_pid_nr(current), start, end - 1);
29042 return -EINVAL;
29043 }
29044
29045@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29046
29047 while (cursor < to) {
29048 if (!devmem_is_allowed(pfn)) {
29049- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
29050- current->comm, from, to - 1);
29051+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
29052+ current->comm, from, to - 1, cursor);
29053 return 0;
29054 }
29055 cursor += PAGE_SIZE;
29056@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
29057 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
29058 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
29059 "for [mem %#010Lx-%#010Lx]\n",
29060- current->comm, current->pid,
29061+ current->comm, task_pid_nr(current),
29062 cattr_name(flags),
29063 base, (unsigned long long)(base + size-1));
29064 return -EINVAL;
29065@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29066 flags = lookup_memtype(paddr);
29067 if (want_flags != flags) {
29068 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
29069- current->comm, current->pid,
29070+ current->comm, task_pid_nr(current),
29071 cattr_name(want_flags),
29072 (unsigned long long)paddr,
29073 (unsigned long long)(paddr + size - 1),
29074@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29075 free_memtype(paddr, paddr + size);
29076 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
29077 " for [mem %#010Lx-%#010Lx], got %s\n",
29078- current->comm, current->pid,
29079+ current->comm, task_pid_nr(current),
29080 cattr_name(want_flags),
29081 (unsigned long long)paddr,
29082 (unsigned long long)(paddr + size - 1),
29083diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
29084index 415f6c4..d319983 100644
29085--- a/arch/x86/mm/pat_rbtree.c
29086+++ b/arch/x86/mm/pat_rbtree.c
29087@@ -160,7 +160,7 @@ success:
29088
29089 failure:
29090 printk(KERN_INFO "%s:%d conflicting memory types "
29091- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
29092+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
29093 end, cattr_name(found_type), cattr_name(match->type));
29094 return -EBUSY;
29095 }
29096diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
29097index 9f0614d..92ae64a 100644
29098--- a/arch/x86/mm/pf_in.c
29099+++ b/arch/x86/mm/pf_in.c
29100@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
29101 int i;
29102 enum reason_type rv = OTHERS;
29103
29104- p = (unsigned char *)ins_addr;
29105+ p = (unsigned char *)ktla_ktva(ins_addr);
29106 p += skip_prefix(p, &prf);
29107 p += get_opcode(p, &opcode);
29108
29109@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
29110 struct prefix_bits prf;
29111 int i;
29112
29113- p = (unsigned char *)ins_addr;
29114+ p = (unsigned char *)ktla_ktva(ins_addr);
29115 p += skip_prefix(p, &prf);
29116 p += get_opcode(p, &opcode);
29117
29118@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29119 struct prefix_bits prf;
29120 int i;
29121
29122- p = (unsigned char *)ins_addr;
29123+ p = (unsigned char *)ktla_ktva(ins_addr);
29124 p += skip_prefix(p, &prf);
29125 p += get_opcode(p, &opcode);
29126
29127@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29128 struct prefix_bits prf;
29129 int i;
29130
29131- p = (unsigned char *)ins_addr;
29132+ p = (unsigned char *)ktla_ktva(ins_addr);
29133 p += skip_prefix(p, &prf);
29134 p += get_opcode(p, &opcode);
29135 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29136@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29137 struct prefix_bits prf;
29138 int i;
29139
29140- p = (unsigned char *)ins_addr;
29141+ p = (unsigned char *)ktla_ktva(ins_addr);
29142 p += skip_prefix(p, &prf);
29143 p += get_opcode(p, &opcode);
29144 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29145diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29146index 17fda6a..489c74a 100644
29147--- a/arch/x86/mm/pgtable.c
29148+++ b/arch/x86/mm/pgtable.c
29149@@ -91,10 +91,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29150 list_del(&page->lru);
29151 }
29152
29153-#define UNSHARED_PTRS_PER_PGD \
29154- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29155+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29156+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29157
29158+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29159+{
29160+ unsigned int count = USER_PGD_PTRS;
29161
29162+ while (count--)
29163+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29164+}
29165+#endif
29166+
29167+#ifdef CONFIG_PAX_PER_CPU_PGD
29168+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29169+{
29170+ unsigned int count = USER_PGD_PTRS;
29171+
29172+ while (count--) {
29173+ pgd_t pgd;
29174+
29175+#ifdef CONFIG_X86_64
29176+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29177+#else
29178+ pgd = *src++;
29179+#endif
29180+
29181+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29182+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29183+#endif
29184+
29185+ *dst++ = pgd;
29186+ }
29187+
29188+}
29189+#endif
29190+
29191+#ifdef CONFIG_X86_64
29192+#define pxd_t pud_t
29193+#define pyd_t pgd_t
29194+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29195+#define pxd_free(mm, pud) pud_free((mm), (pud))
29196+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29197+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29198+#define PYD_SIZE PGDIR_SIZE
29199+#else
29200+#define pxd_t pmd_t
29201+#define pyd_t pud_t
29202+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29203+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29204+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29205+#define pyd_offset(mm, address) pud_offset((mm), (address))
29206+#define PYD_SIZE PUD_SIZE
29207+#endif
29208+
29209+#ifdef CONFIG_PAX_PER_CPU_PGD
29210+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29211+static inline void pgd_dtor(pgd_t *pgd) {}
29212+#else
29213 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29214 {
29215 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29216@@ -135,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd)
29217 pgd_list_del(pgd);
29218 spin_unlock(&pgd_lock);
29219 }
29220+#endif
29221
29222 /*
29223 * List of all pgd's needed for non-PAE so it can invalidate entries
29224@@ -147,7 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
29225 * -- nyc
29226 */
29227
29228-#ifdef CONFIG_X86_PAE
29229+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29230 /*
29231 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29232 * updating the top-level pagetable entries to guarantee the
29233@@ -159,7 +214,7 @@ static void pgd_dtor(pgd_t *pgd)
29234 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29235 * and initialize the kernel pmds here.
29236 */
29237-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29238+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29239
29240 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29241 {
29242@@ -177,36 +232,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29243 */
29244 flush_tlb_mm(mm);
29245 }
29246+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29247+#define PREALLOCATED_PXDS USER_PGD_PTRS
29248 #else /* !CONFIG_X86_PAE */
29249
29250 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29251-#define PREALLOCATED_PMDS 0
29252+#define PREALLOCATED_PXDS 0
29253
29254 #endif /* CONFIG_X86_PAE */
29255
29256-static void free_pmds(pmd_t *pmds[])
29257+static void free_pxds(pxd_t *pxds[])
29258 {
29259 int i;
29260
29261- for(i = 0; i < PREALLOCATED_PMDS; i++)
29262- if (pmds[i])
29263- free_page((unsigned long)pmds[i]);
29264+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29265+ if (pxds[i])
29266+ free_page((unsigned long)pxds[i]);
29267 }
29268
29269-static int preallocate_pmds(pmd_t *pmds[])
29270+static int preallocate_pxds(pxd_t *pxds[])
29271 {
29272 int i;
29273 bool failed = false;
29274
29275- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29276- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29277- if (pmd == NULL)
29278+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29279+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29280+ if (pxd == NULL)
29281 failed = true;
29282- pmds[i] = pmd;
29283+ pxds[i] = pxd;
29284 }
29285
29286 if (failed) {
29287- free_pmds(pmds);
29288+ free_pxds(pxds);
29289 return -ENOMEM;
29290 }
29291
29292@@ -219,51 +276,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29293 * preallocate which never got a corresponding vma will need to be
29294 * freed manually.
29295 */
29296-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29297+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29298 {
29299 int i;
29300
29301- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29302+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29303 pgd_t pgd = pgdp[i];
29304
29305 if (pgd_val(pgd) != 0) {
29306- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29307+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29308
29309- pgdp[i] = native_make_pgd(0);
29310+ set_pgd(pgdp + i, native_make_pgd(0));
29311
29312- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29313- pmd_free(mm, pmd);
29314+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29315+ pxd_free(mm, pxd);
29316 }
29317 }
29318 }
29319
29320-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29321+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29322 {
29323- pud_t *pud;
29324+ pyd_t *pyd;
29325 unsigned long addr;
29326 int i;
29327
29328- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29329+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29330 return;
29331
29332- pud = pud_offset(pgd, 0);
29333+#ifdef CONFIG_X86_64
29334+ pyd = pyd_offset(mm, 0L);
29335+#else
29336+ pyd = pyd_offset(pgd, 0L);
29337+#endif
29338
29339- for (addr = i = 0; i < PREALLOCATED_PMDS;
29340- i++, pud++, addr += PUD_SIZE) {
29341- pmd_t *pmd = pmds[i];
29342+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29343+ i++, pyd++, addr += PYD_SIZE) {
29344+ pxd_t *pxd = pxds[i];
29345
29346 if (i >= KERNEL_PGD_BOUNDARY)
29347- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29348- sizeof(pmd_t) * PTRS_PER_PMD);
29349+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29350+ sizeof(pxd_t) * PTRS_PER_PMD);
29351
29352- pud_populate(mm, pud, pmd);
29353+ pyd_populate(mm, pyd, pxd);
29354 }
29355 }
29356
29357 pgd_t *pgd_alloc(struct mm_struct *mm)
29358 {
29359 pgd_t *pgd;
29360- pmd_t *pmds[PREALLOCATED_PMDS];
29361+ pxd_t *pxds[PREALLOCATED_PXDS];
29362
29363 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29364
29365@@ -272,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29366
29367 mm->pgd = pgd;
29368
29369- if (preallocate_pmds(pmds) != 0)
29370+ if (preallocate_pxds(pxds) != 0)
29371 goto out_free_pgd;
29372
29373 if (paravirt_pgd_alloc(mm) != 0)
29374- goto out_free_pmds;
29375+ goto out_free_pxds;
29376
29377 /*
29378 * Make sure that pre-populating the pmds is atomic with
29379@@ -286,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29380 spin_lock(&pgd_lock);
29381
29382 pgd_ctor(mm, pgd);
29383- pgd_prepopulate_pmd(mm, pgd, pmds);
29384+ pgd_prepopulate_pxd(mm, pgd, pxds);
29385
29386 spin_unlock(&pgd_lock);
29387
29388 return pgd;
29389
29390-out_free_pmds:
29391- free_pmds(pmds);
29392+out_free_pxds:
29393+ free_pxds(pxds);
29394 out_free_pgd:
29395 free_page((unsigned long)pgd);
29396 out:
29397@@ -302,7 +363,7 @@ out:
29398
29399 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29400 {
29401- pgd_mop_up_pmds(mm, pgd);
29402+ pgd_mop_up_pxds(mm, pgd);
29403 pgd_dtor(pgd);
29404 paravirt_pgd_free(mm, pgd);
29405 free_page((unsigned long)pgd);
29406diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29407index a69bcb8..19068ab 100644
29408--- a/arch/x86/mm/pgtable_32.c
29409+++ b/arch/x86/mm/pgtable_32.c
29410@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29411 return;
29412 }
29413 pte = pte_offset_kernel(pmd, vaddr);
29414+
29415+ pax_open_kernel();
29416 if (pte_val(pteval))
29417 set_pte_at(&init_mm, vaddr, pte, pteval);
29418 else
29419 pte_clear(&init_mm, vaddr, pte);
29420+ pax_close_kernel();
29421
29422 /*
29423 * It's enough to flush this one mapping.
29424diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29425index e666cbb..61788c45 100644
29426--- a/arch/x86/mm/physaddr.c
29427+++ b/arch/x86/mm/physaddr.c
29428@@ -10,7 +10,7 @@
29429 #ifdef CONFIG_X86_64
29430
29431 #ifdef CONFIG_DEBUG_VIRTUAL
29432-unsigned long __phys_addr(unsigned long x)
29433+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29434 {
29435 unsigned long y = x - __START_KERNEL_map;
29436
29437@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29438 #else
29439
29440 #ifdef CONFIG_DEBUG_VIRTUAL
29441-unsigned long __phys_addr(unsigned long x)
29442+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29443 {
29444 unsigned long phys_addr = x - PAGE_OFFSET;
29445 /* VMALLOC_* aren't constants */
29446diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29447index 410531d..0f16030 100644
29448--- a/arch/x86/mm/setup_nx.c
29449+++ b/arch/x86/mm/setup_nx.c
29450@@ -5,8 +5,10 @@
29451 #include <asm/pgtable.h>
29452 #include <asm/proto.h>
29453
29454+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29455 static int disable_nx __cpuinitdata;
29456
29457+#ifndef CONFIG_PAX_PAGEEXEC
29458 /*
29459 * noexec = on|off
29460 *
29461@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29462 return 0;
29463 }
29464 early_param("noexec", noexec_setup);
29465+#endif
29466+
29467+#endif
29468
29469 void __cpuinit x86_configure_nx(void)
29470 {
29471+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29472 if (cpu_has_nx && !disable_nx)
29473 __supported_pte_mask |= _PAGE_NX;
29474 else
29475+#endif
29476 __supported_pte_mask &= ~_PAGE_NX;
29477 }
29478
29479diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29480index 282375f..e03a98f 100644
29481--- a/arch/x86/mm/tlb.c
29482+++ b/arch/x86/mm/tlb.c
29483@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29484 BUG();
29485 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29486 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29487+
29488+#ifndef CONFIG_PAX_PER_CPU_PGD
29489 load_cr3(swapper_pg_dir);
29490+#endif
29491+
29492 }
29493 }
29494 EXPORT_SYMBOL_GPL(leave_mm);
29495diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29496index 877b9a1..a8ecf42 100644
29497--- a/arch/x86/net/bpf_jit.S
29498+++ b/arch/x86/net/bpf_jit.S
29499@@ -9,6 +9,7 @@
29500 */
29501 #include <linux/linkage.h>
29502 #include <asm/dwarf2.h>
29503+#include <asm/alternative-asm.h>
29504
29505 /*
29506 * Calling convention :
29507@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29508 jle bpf_slow_path_word
29509 mov (SKBDATA,%rsi),%eax
29510 bswap %eax /* ntohl() */
29511+ pax_force_retaddr
29512 ret
29513
29514 sk_load_half:
29515@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29516 jle bpf_slow_path_half
29517 movzwl (SKBDATA,%rsi),%eax
29518 rol $8,%ax # ntohs()
29519+ pax_force_retaddr
29520 ret
29521
29522 sk_load_byte:
29523@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29524 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29525 jle bpf_slow_path_byte
29526 movzbl (SKBDATA,%rsi),%eax
29527+ pax_force_retaddr
29528 ret
29529
29530 /**
29531@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29532 movzbl (SKBDATA,%rsi),%ebx
29533 and $15,%bl
29534 shl $2,%bl
29535+ pax_force_retaddr
29536 ret
29537
29538 /* rsi contains offset and can be scratched */
29539@@ -109,6 +114,7 @@ bpf_slow_path_word:
29540 js bpf_error
29541 mov -12(%rbp),%eax
29542 bswap %eax
29543+ pax_force_retaddr
29544 ret
29545
29546 bpf_slow_path_half:
29547@@ -117,12 +123,14 @@ bpf_slow_path_half:
29548 mov -12(%rbp),%ax
29549 rol $8,%ax
29550 movzwl %ax,%eax
29551+ pax_force_retaddr
29552 ret
29553
29554 bpf_slow_path_byte:
29555 bpf_slow_path_common(1)
29556 js bpf_error
29557 movzbl -12(%rbp),%eax
29558+ pax_force_retaddr
29559 ret
29560
29561 bpf_slow_path_byte_msh:
29562@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29563 and $15,%al
29564 shl $2,%al
29565 xchg %eax,%ebx
29566+ pax_force_retaddr
29567 ret
29568
29569 #define sk_negative_common(SIZE) \
29570@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29571 sk_negative_common(4)
29572 mov (%rax), %eax
29573 bswap %eax
29574+ pax_force_retaddr
29575 ret
29576
29577 bpf_slow_path_half_neg:
29578@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29579 mov (%rax),%ax
29580 rol $8,%ax
29581 movzwl %ax,%eax
29582+ pax_force_retaddr
29583 ret
29584
29585 bpf_slow_path_byte_neg:
29586@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29587 .globl sk_load_byte_negative_offset
29588 sk_negative_common(1)
29589 movzbl (%rax), %eax
29590+ pax_force_retaddr
29591 ret
29592
29593 bpf_slow_path_byte_msh_neg:
29594@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29595 and $15,%al
29596 shl $2,%al
29597 xchg %eax,%ebx
29598+ pax_force_retaddr
29599 ret
29600
29601 bpf_error:
29602@@ -197,4 +210,5 @@ bpf_error:
29603 xor %eax,%eax
29604 mov -8(%rbp),%rbx
29605 leaveq
29606+ pax_force_retaddr
29607 ret
29608diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29609index f66b540..3e88dfb 100644
29610--- a/arch/x86/net/bpf_jit_comp.c
29611+++ b/arch/x86/net/bpf_jit_comp.c
29612@@ -12,6 +12,7 @@
29613 #include <linux/netdevice.h>
29614 #include <linux/filter.h>
29615 #include <linux/if_vlan.h>
29616+#include <linux/random.h>
29617
29618 /*
29619 * Conventions :
29620@@ -49,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29621 return ptr + len;
29622 }
29623
29624+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29625+#define MAX_INSTR_CODE_SIZE 96
29626+#else
29627+#define MAX_INSTR_CODE_SIZE 64
29628+#endif
29629+
29630 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29631
29632 #define EMIT1(b1) EMIT(b1, 1)
29633 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29634 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29635 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29636+
29637+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29638+/* original constant will appear in ecx */
29639+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29640+do { \
29641+ /* mov ecx, randkey */ \
29642+ EMIT1(0xb9); \
29643+ EMIT(_key, 4); \
29644+ /* xor ecx, randkey ^ off */ \
29645+ EMIT2(0x81, 0xf1); \
29646+ EMIT((_key) ^ (_off), 4); \
29647+} while (0)
29648+
29649+#define EMIT1_off32(b1, _off) \
29650+do { \
29651+ switch (b1) { \
29652+ case 0x05: /* add eax, imm32 */ \
29653+ case 0x2d: /* sub eax, imm32 */ \
29654+ case 0x25: /* and eax, imm32 */ \
29655+ case 0x0d: /* or eax, imm32 */ \
29656+ case 0xb8: /* mov eax, imm32 */ \
29657+ case 0x35: /* xor eax, imm32 */ \
29658+ case 0x3d: /* cmp eax, imm32 */ \
29659+ case 0xa9: /* test eax, imm32 */ \
29660+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29661+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29662+ break; \
29663+ case 0xbb: /* mov ebx, imm32 */ \
29664+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29665+ /* mov ebx, ecx */ \
29666+ EMIT2(0x89, 0xcb); \
29667+ break; \
29668+ case 0xbe: /* mov esi, imm32 */ \
29669+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29670+ /* mov esi, ecx */ \
29671+ EMIT2(0x89, 0xce); \
29672+ break; \
29673+ case 0xe8: /* call rel imm32, always to known funcs */ \
29674+ EMIT1(b1); \
29675+ EMIT(_off, 4); \
29676+ break; \
29677+ case 0xe9: /* jmp rel imm32 */ \
29678+ EMIT1(b1); \
29679+ EMIT(_off, 4); \
29680+ /* prevent fall-through, we're not called if off = 0 */ \
29681+ EMIT(0xcccccccc, 4); \
29682+ EMIT(0xcccccccc, 4); \
29683+ break; \
29684+ default: \
29685+ BUILD_BUG(); \
29686+ } \
29687+} while (0)
29688+
29689+#define EMIT2_off32(b1, b2, _off) \
29690+do { \
29691+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29692+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29693+ EMIT(randkey, 4); \
29694+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29695+ EMIT((_off) - randkey, 4); \
29696+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29697+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29698+ /* imul eax, ecx */ \
29699+ EMIT3(0x0f, 0xaf, 0xc1); \
29700+ } else { \
29701+ BUILD_BUG(); \
29702+ } \
29703+} while (0)
29704+#else
29705 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29706+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29707+#endif
29708
29709 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29710 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29711@@ -90,6 +168,24 @@ do { \
29712 #define X86_JBE 0x76
29713 #define X86_JA 0x77
29714
29715+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29716+#define APPEND_FLOW_VERIFY() \
29717+do { \
29718+ /* mov ecx, randkey */ \
29719+ EMIT1(0xb9); \
29720+ EMIT(randkey, 4); \
29721+ /* cmp ecx, randkey */ \
29722+ EMIT2(0x81, 0xf9); \
29723+ EMIT(randkey, 4); \
29724+ /* jz after 8 int 3s */ \
29725+ EMIT2(0x74, 0x08); \
29726+ EMIT(0xcccccccc, 4); \
29727+ EMIT(0xcccccccc, 4); \
29728+} while (0)
29729+#else
29730+#define APPEND_FLOW_VERIFY() do { } while (0)
29731+#endif
29732+
29733 #define EMIT_COND_JMP(op, offset) \
29734 do { \
29735 if (is_near(offset)) \
29736@@ -97,6 +193,7 @@ do { \
29737 else { \
29738 EMIT2(0x0f, op + 0x10); \
29739 EMIT(offset, 4); /* jxx .+off32 */ \
29740+ APPEND_FLOW_VERIFY(); \
29741 } \
29742 } while (0)
29743
29744@@ -121,6 +218,11 @@ static inline void bpf_flush_icache(void *start, void *end)
29745 set_fs(old_fs);
29746 }
29747
29748+struct bpf_jit_work {
29749+ struct work_struct work;
29750+ void *image;
29751+};
29752+
29753 #define CHOOSE_LOAD_FUNC(K, func) \
29754 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29755
29756@@ -146,7 +248,7 @@ static int pkt_type_offset(void)
29757
29758 void bpf_jit_compile(struct sk_filter *fp)
29759 {
29760- u8 temp[64];
29761+ u8 temp[MAX_INSTR_CODE_SIZE];
29762 u8 *prog;
29763 unsigned int proglen, oldproglen = 0;
29764 int ilen, i;
29765@@ -159,6 +261,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29766 unsigned int *addrs;
29767 const struct sock_filter *filter = fp->insns;
29768 int flen = fp->len;
29769+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29770+ unsigned int randkey;
29771+#endif
29772
29773 if (!bpf_jit_enable)
29774 return;
29775@@ -167,11 +272,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29776 if (addrs == NULL)
29777 return;
29778
29779+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29780+ if (!fp->work)
29781+ goto out;
29782+
29783+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29784+ randkey = get_random_int();
29785+#endif
29786+
29787 /* Before first pass, make a rough estimation of addrs[]
29788- * each bpf instruction is translated to less than 64 bytes
29789+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29790 */
29791 for (proglen = 0, i = 0; i < flen; i++) {
29792- proglen += 64;
29793+ proglen += MAX_INSTR_CODE_SIZE;
29794 addrs[i] = proglen;
29795 }
29796 cleanup_addr = proglen; /* epilogue address */
29797@@ -282,10 +395,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29798 case BPF_S_ALU_MUL_K: /* A *= K */
29799 if (is_imm8(K))
29800 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29801- else {
29802- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29803- EMIT(K, 4);
29804- }
29805+ else
29806+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29807 break;
29808 case BPF_S_ALU_DIV_X: /* A /= X; */
29809 seen |= SEEN_XREG;
29810@@ -325,13 +436,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29811 break;
29812 case BPF_S_ALU_MOD_K: /* A %= K; */
29813 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29814+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29815+ DILUTE_CONST_SEQUENCE(K, randkey);
29816+#else
29817 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29818+#endif
29819 EMIT2(0xf7, 0xf1); /* div %ecx */
29820 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29821 break;
29822 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29823+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29824+ DILUTE_CONST_SEQUENCE(K, randkey);
29825+ // imul rax, rcx
29826+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29827+#else
29828 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29829 EMIT(K, 4);
29830+#endif
29831 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29832 break;
29833 case BPF_S_ALU_AND_X:
29834@@ -602,8 +723,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29835 if (is_imm8(K)) {
29836 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29837 } else {
29838- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29839- EMIT(K, 4);
29840+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29841 }
29842 } else {
29843 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29844@@ -686,17 +806,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29845 break;
29846 default:
29847 /* hmm, too complex filter, give up with jit compiler */
29848- goto out;
29849+ goto error;
29850 }
29851 ilen = prog - temp;
29852 if (image) {
29853 if (unlikely(proglen + ilen > oldproglen)) {
29854 pr_err("bpb_jit_compile fatal error\n");
29855- kfree(addrs);
29856- module_free(NULL, image);
29857- return;
29858+ module_free_exec(NULL, image);
29859+ goto error;
29860 }
29861+ pax_open_kernel();
29862 memcpy(image + proglen, temp, ilen);
29863+ pax_close_kernel();
29864 }
29865 proglen += ilen;
29866 addrs[i] = proglen;
29867@@ -717,11 +838,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29868 break;
29869 }
29870 if (proglen == oldproglen) {
29871- image = module_alloc(max_t(unsigned int,
29872- proglen,
29873- sizeof(struct work_struct)));
29874+ image = module_alloc_exec(proglen);
29875 if (!image)
29876- goto out;
29877+ goto error;
29878 }
29879 oldproglen = proglen;
29880 }
29881@@ -732,7 +851,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29882 if (image) {
29883 bpf_flush_icache(image, image + proglen);
29884 fp->bpf_func = (void *)image;
29885- }
29886+ } else
29887+error:
29888+ kfree(fp->work);
29889+
29890 out:
29891 kfree(addrs);
29892 return;
29893@@ -740,18 +862,20 @@ out:
29894
29895 static void jit_free_defer(struct work_struct *arg)
29896 {
29897- module_free(NULL, arg);
29898+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29899+ kfree(arg);
29900 }
29901
29902 /* run from softirq, we must use a work_struct to call
29903- * module_free() from process context
29904+ * module_free_exec() from process context
29905 */
29906 void bpf_jit_free(struct sk_filter *fp)
29907 {
29908 if (fp->bpf_func != sk_run_filter) {
29909- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29910+ struct work_struct *work = &fp->work->work;
29911
29912 INIT_WORK(work, jit_free_defer);
29913+ fp->work->image = fp->bpf_func;
29914 schedule_work(work);
29915 }
29916 }
29917diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29918index d6aa6e8..266395a 100644
29919--- a/arch/x86/oprofile/backtrace.c
29920+++ b/arch/x86/oprofile/backtrace.c
29921@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29922 struct stack_frame_ia32 *fp;
29923 unsigned long bytes;
29924
29925- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29926+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29927 if (bytes != sizeof(bufhead))
29928 return NULL;
29929
29930- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29931+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29932
29933 oprofile_add_trace(bufhead[0].return_address);
29934
29935@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29936 struct stack_frame bufhead[2];
29937 unsigned long bytes;
29938
29939- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29940+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29941 if (bytes != sizeof(bufhead))
29942 return NULL;
29943
29944@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29945 {
29946 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29947
29948- if (!user_mode_vm(regs)) {
29949+ if (!user_mode(regs)) {
29950 unsigned long stack = kernel_stack_pointer(regs);
29951 if (depth)
29952 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29953diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29954index 48768df..ba9143c 100644
29955--- a/arch/x86/oprofile/nmi_int.c
29956+++ b/arch/x86/oprofile/nmi_int.c
29957@@ -23,6 +23,7 @@
29958 #include <asm/nmi.h>
29959 #include <asm/msr.h>
29960 #include <asm/apic.h>
29961+#include <asm/pgtable.h>
29962
29963 #include "op_counter.h"
29964 #include "op_x86_model.h"
29965@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29966 if (ret)
29967 return ret;
29968
29969- if (!model->num_virt_counters)
29970- model->num_virt_counters = model->num_counters;
29971+ if (!model->num_virt_counters) {
29972+ pax_open_kernel();
29973+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
29974+ pax_close_kernel();
29975+ }
29976
29977 mux_init(ops);
29978
29979diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29980index b2b9443..be58856 100644
29981--- a/arch/x86/oprofile/op_model_amd.c
29982+++ b/arch/x86/oprofile/op_model_amd.c
29983@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29984 num_counters = AMD64_NUM_COUNTERS;
29985 }
29986
29987- op_amd_spec.num_counters = num_counters;
29988- op_amd_spec.num_controls = num_counters;
29989- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29990+ pax_open_kernel();
29991+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29992+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29993+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29994+ pax_close_kernel();
29995
29996 return 0;
29997 }
29998diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29999index d90528e..0127e2b 100644
30000--- a/arch/x86/oprofile/op_model_ppro.c
30001+++ b/arch/x86/oprofile/op_model_ppro.c
30002@@ -19,6 +19,7 @@
30003 #include <asm/msr.h>
30004 #include <asm/apic.h>
30005 #include <asm/nmi.h>
30006+#include <asm/pgtable.h>
30007
30008 #include "op_x86_model.h"
30009 #include "op_counter.h"
30010@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
30011
30012 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
30013
30014- op_arch_perfmon_spec.num_counters = num_counters;
30015- op_arch_perfmon_spec.num_controls = num_counters;
30016+ pax_open_kernel();
30017+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
30018+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
30019+ pax_close_kernel();
30020 }
30021
30022 static int arch_perfmon_init(struct oprofile_operations *ignore)
30023diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
30024index 71e8a67..6a313bb 100644
30025--- a/arch/x86/oprofile/op_x86_model.h
30026+++ b/arch/x86/oprofile/op_x86_model.h
30027@@ -52,7 +52,7 @@ struct op_x86_model_spec {
30028 void (*switch_ctrl)(struct op_x86_model_spec const *model,
30029 struct op_msrs const * const msrs);
30030 #endif
30031-};
30032+} __do_const;
30033
30034 struct op_counter_config;
30035
30036diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
30037index e9e6ed5..e47ae67 100644
30038--- a/arch/x86/pci/amd_bus.c
30039+++ b/arch/x86/pci/amd_bus.c
30040@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
30041 return NOTIFY_OK;
30042 }
30043
30044-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
30045+static struct notifier_block amd_cpu_notifier = {
30046 .notifier_call = amd_cpu_notify,
30047 };
30048
30049diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
30050index 372e9b8..e775a6c 100644
30051--- a/arch/x86/pci/irq.c
30052+++ b/arch/x86/pci/irq.c
30053@@ -50,7 +50,7 @@ struct irq_router {
30054 struct irq_router_handler {
30055 u16 vendor;
30056 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
30057-};
30058+} __do_const;
30059
30060 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
30061 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
30062@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
30063 return 0;
30064 }
30065
30066-static __initdata struct irq_router_handler pirq_routers[] = {
30067+static __initconst const struct irq_router_handler pirq_routers[] = {
30068 { PCI_VENDOR_ID_INTEL, intel_router_probe },
30069 { PCI_VENDOR_ID_AL, ali_router_probe },
30070 { PCI_VENDOR_ID_ITE, ite_router_probe },
30071@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
30072 static void __init pirq_find_router(struct irq_router *r)
30073 {
30074 struct irq_routing_table *rt = pirq_table;
30075- struct irq_router_handler *h;
30076+ const struct irq_router_handler *h;
30077
30078 #ifdef CONFIG_PCI_BIOS
30079 if (!rt->signature) {
30080@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
30081 return 0;
30082 }
30083
30084-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
30085+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
30086 {
30087 .callback = fix_broken_hp_bios_irq9,
30088 .ident = "HP Pavilion N5400 Series Laptop",
30089diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
30090index 6eb18c4..20d83de 100644
30091--- a/arch/x86/pci/mrst.c
30092+++ b/arch/x86/pci/mrst.c
30093@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
30094 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
30095 pci_mmcfg_late_init();
30096 pcibios_enable_irq = mrst_pci_irq_enable;
30097- pci_root_ops = pci_mrst_ops;
30098+ pax_open_kernel();
30099+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
30100+ pax_close_kernel();
30101 pci_soc_mode = 1;
30102 /* Continue with standard init */
30103 return 1;
30104diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
30105index c77b24a..c979855 100644
30106--- a/arch/x86/pci/pcbios.c
30107+++ b/arch/x86/pci/pcbios.c
30108@@ -79,7 +79,7 @@ union bios32 {
30109 static struct {
30110 unsigned long address;
30111 unsigned short segment;
30112-} bios32_indirect = { 0, __KERNEL_CS };
30113+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
30114
30115 /*
30116 * Returns the entry point for the given service, NULL on error
30117@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30118 unsigned long length; /* %ecx */
30119 unsigned long entry; /* %edx */
30120 unsigned long flags;
30121+ struct desc_struct d, *gdt;
30122
30123 local_irq_save(flags);
30124- __asm__("lcall *(%%edi); cld"
30125+
30126+ gdt = get_cpu_gdt_table(smp_processor_id());
30127+
30128+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30129+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30130+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30131+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30132+
30133+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30134 : "=a" (return_code),
30135 "=b" (address),
30136 "=c" (length),
30137 "=d" (entry)
30138 : "0" (service),
30139 "1" (0),
30140- "D" (&bios32_indirect));
30141+ "D" (&bios32_indirect),
30142+ "r"(__PCIBIOS_DS)
30143+ : "memory");
30144+
30145+ pax_open_kernel();
30146+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30147+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30148+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30149+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30150+ pax_close_kernel();
30151+
30152 local_irq_restore(flags);
30153
30154 switch (return_code) {
30155- case 0:
30156- return address + entry;
30157- case 0x80: /* Not present */
30158- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30159- return 0;
30160- default: /* Shouldn't happen */
30161- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30162- service, return_code);
30163+ case 0: {
30164+ int cpu;
30165+ unsigned char flags;
30166+
30167+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30168+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30169+ printk(KERN_WARNING "bios32_service: not valid\n");
30170 return 0;
30171+ }
30172+ address = address + PAGE_OFFSET;
30173+ length += 16UL; /* some BIOSs underreport this... */
30174+ flags = 4;
30175+ if (length >= 64*1024*1024) {
30176+ length >>= PAGE_SHIFT;
30177+ flags |= 8;
30178+ }
30179+
30180+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30181+ gdt = get_cpu_gdt_table(cpu);
30182+ pack_descriptor(&d, address, length, 0x9b, flags);
30183+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30184+ pack_descriptor(&d, address, length, 0x93, flags);
30185+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30186+ }
30187+ return entry;
30188+ }
30189+ case 0x80: /* Not present */
30190+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30191+ return 0;
30192+ default: /* Shouldn't happen */
30193+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30194+ service, return_code);
30195+ return 0;
30196 }
30197 }
30198
30199 static struct {
30200 unsigned long address;
30201 unsigned short segment;
30202-} pci_indirect = { 0, __KERNEL_CS };
30203+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30204
30205-static int pci_bios_present;
30206+static int pci_bios_present __read_only;
30207
30208 static int check_pcibios(void)
30209 {
30210@@ -131,11 +174,13 @@ static int check_pcibios(void)
30211 unsigned long flags, pcibios_entry;
30212
30213 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30214- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30215+ pci_indirect.address = pcibios_entry;
30216
30217 local_irq_save(flags);
30218- __asm__(
30219- "lcall *(%%edi); cld\n\t"
30220+ __asm__("movw %w6, %%ds\n\t"
30221+ "lcall *%%ss:(%%edi); cld\n\t"
30222+ "push %%ss\n\t"
30223+ "pop %%ds\n\t"
30224 "jc 1f\n\t"
30225 "xor %%ah, %%ah\n"
30226 "1:"
30227@@ -144,7 +189,8 @@ static int check_pcibios(void)
30228 "=b" (ebx),
30229 "=c" (ecx)
30230 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30231- "D" (&pci_indirect)
30232+ "D" (&pci_indirect),
30233+ "r" (__PCIBIOS_DS)
30234 : "memory");
30235 local_irq_restore(flags);
30236
30237@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30238
30239 switch (len) {
30240 case 1:
30241- __asm__("lcall *(%%esi); cld\n\t"
30242+ __asm__("movw %w6, %%ds\n\t"
30243+ "lcall *%%ss:(%%esi); cld\n\t"
30244+ "push %%ss\n\t"
30245+ "pop %%ds\n\t"
30246 "jc 1f\n\t"
30247 "xor %%ah, %%ah\n"
30248 "1:"
30249@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30250 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30251 "b" (bx),
30252 "D" ((long)reg),
30253- "S" (&pci_indirect));
30254+ "S" (&pci_indirect),
30255+ "r" (__PCIBIOS_DS));
30256 /*
30257 * Zero-extend the result beyond 8 bits, do not trust the
30258 * BIOS having done it:
30259@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30260 *value &= 0xff;
30261 break;
30262 case 2:
30263- __asm__("lcall *(%%esi); cld\n\t"
30264+ __asm__("movw %w6, %%ds\n\t"
30265+ "lcall *%%ss:(%%esi); cld\n\t"
30266+ "push %%ss\n\t"
30267+ "pop %%ds\n\t"
30268 "jc 1f\n\t"
30269 "xor %%ah, %%ah\n"
30270 "1:"
30271@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30272 : "1" (PCIBIOS_READ_CONFIG_WORD),
30273 "b" (bx),
30274 "D" ((long)reg),
30275- "S" (&pci_indirect));
30276+ "S" (&pci_indirect),
30277+ "r" (__PCIBIOS_DS));
30278 /*
30279 * Zero-extend the result beyond 16 bits, do not trust the
30280 * BIOS having done it:
30281@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30282 *value &= 0xffff;
30283 break;
30284 case 4:
30285- __asm__("lcall *(%%esi); cld\n\t"
30286+ __asm__("movw %w6, %%ds\n\t"
30287+ "lcall *%%ss:(%%esi); cld\n\t"
30288+ "push %%ss\n\t"
30289+ "pop %%ds\n\t"
30290 "jc 1f\n\t"
30291 "xor %%ah, %%ah\n"
30292 "1:"
30293@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30294 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30295 "b" (bx),
30296 "D" ((long)reg),
30297- "S" (&pci_indirect));
30298+ "S" (&pci_indirect),
30299+ "r" (__PCIBIOS_DS));
30300 break;
30301 }
30302
30303@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30304
30305 switch (len) {
30306 case 1:
30307- __asm__("lcall *(%%esi); cld\n\t"
30308+ __asm__("movw %w6, %%ds\n\t"
30309+ "lcall *%%ss:(%%esi); cld\n\t"
30310+ "push %%ss\n\t"
30311+ "pop %%ds\n\t"
30312 "jc 1f\n\t"
30313 "xor %%ah, %%ah\n"
30314 "1:"
30315@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30316 "c" (value),
30317 "b" (bx),
30318 "D" ((long)reg),
30319- "S" (&pci_indirect));
30320+ "S" (&pci_indirect),
30321+ "r" (__PCIBIOS_DS));
30322 break;
30323 case 2:
30324- __asm__("lcall *(%%esi); cld\n\t"
30325+ __asm__("movw %w6, %%ds\n\t"
30326+ "lcall *%%ss:(%%esi); cld\n\t"
30327+ "push %%ss\n\t"
30328+ "pop %%ds\n\t"
30329 "jc 1f\n\t"
30330 "xor %%ah, %%ah\n"
30331 "1:"
30332@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30333 "c" (value),
30334 "b" (bx),
30335 "D" ((long)reg),
30336- "S" (&pci_indirect));
30337+ "S" (&pci_indirect),
30338+ "r" (__PCIBIOS_DS));
30339 break;
30340 case 4:
30341- __asm__("lcall *(%%esi); cld\n\t"
30342+ __asm__("movw %w6, %%ds\n\t"
30343+ "lcall *%%ss:(%%esi); cld\n\t"
30344+ "push %%ss\n\t"
30345+ "pop %%ds\n\t"
30346 "jc 1f\n\t"
30347 "xor %%ah, %%ah\n"
30348 "1:"
30349@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30350 "c" (value),
30351 "b" (bx),
30352 "D" ((long)reg),
30353- "S" (&pci_indirect));
30354+ "S" (&pci_indirect),
30355+ "r" (__PCIBIOS_DS));
30356 break;
30357 }
30358
30359@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30360
30361 DBG("PCI: Fetching IRQ routing table... ");
30362 __asm__("push %%es\n\t"
30363+ "movw %w8, %%ds\n\t"
30364 "push %%ds\n\t"
30365 "pop %%es\n\t"
30366- "lcall *(%%esi); cld\n\t"
30367+ "lcall *%%ss:(%%esi); cld\n\t"
30368 "pop %%es\n\t"
30369+ "push %%ss\n\t"
30370+ "pop %%ds\n"
30371 "jc 1f\n\t"
30372 "xor %%ah, %%ah\n"
30373 "1:"
30374@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30375 "1" (0),
30376 "D" ((long) &opt),
30377 "S" (&pci_indirect),
30378- "m" (opt)
30379+ "m" (opt),
30380+ "r" (__PCIBIOS_DS)
30381 : "memory");
30382 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30383 if (ret & 0xff00)
30384@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30385 {
30386 int ret;
30387
30388- __asm__("lcall *(%%esi); cld\n\t"
30389+ __asm__("movw %w5, %%ds\n\t"
30390+ "lcall *%%ss:(%%esi); cld\n\t"
30391+ "push %%ss\n\t"
30392+ "pop %%ds\n"
30393 "jc 1f\n\t"
30394 "xor %%ah, %%ah\n"
30395 "1:"
30396@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30397 : "0" (PCIBIOS_SET_PCI_HW_INT),
30398 "b" ((dev->bus->number << 8) | dev->devfn),
30399 "c" ((irq << 8) | (pin + 10)),
30400- "S" (&pci_indirect));
30401+ "S" (&pci_indirect),
30402+ "r" (__PCIBIOS_DS));
30403 return !(ret & 0xff00);
30404 }
30405 EXPORT_SYMBOL(pcibios_set_irq_routing);
30406diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30407index 40e4469..0592924 100644
30408--- a/arch/x86/platform/efi/efi_32.c
30409+++ b/arch/x86/platform/efi/efi_32.c
30410@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30411 {
30412 struct desc_ptr gdt_descr;
30413
30414+#ifdef CONFIG_PAX_KERNEXEC
30415+ struct desc_struct d;
30416+#endif
30417+
30418 local_irq_save(efi_rt_eflags);
30419
30420 load_cr3(initial_page_table);
30421 __flush_tlb_all();
30422
30423+#ifdef CONFIG_PAX_KERNEXEC
30424+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30425+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30426+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30427+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30428+#endif
30429+
30430 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30431 gdt_descr.size = GDT_SIZE - 1;
30432 load_gdt(&gdt_descr);
30433@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
30434 {
30435 struct desc_ptr gdt_descr;
30436
30437+#ifdef CONFIG_PAX_KERNEXEC
30438+ struct desc_struct d;
30439+
30440+ memset(&d, 0, sizeof d);
30441+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30442+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30443+#endif
30444+
30445 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30446 gdt_descr.size = GDT_SIZE - 1;
30447 load_gdt(&gdt_descr);
30448
30449+#ifdef CONFIG_PAX_PER_CPU_PGD
30450+ load_cr3(get_cpu_pgd(smp_processor_id()));
30451+#else
30452 load_cr3(swapper_pg_dir);
30453+#endif
30454+
30455 __flush_tlb_all();
30456
30457 local_irq_restore(efi_rt_eflags);
30458diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
30459index 39a0e7f1..ecc2f1e 100644
30460--- a/arch/x86/platform/efi/efi_64.c
30461+++ b/arch/x86/platform/efi/efi_64.c
30462@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
30463 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
30464 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
30465 }
30466+
30467+#ifdef CONFIG_PAX_PER_CPU_PGD
30468+ load_cr3(swapper_pg_dir);
30469+#endif
30470+
30471 __flush_tlb_all();
30472 }
30473
30474@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
30475 for (pgd = 0; pgd < n_pgds; pgd++)
30476 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
30477 kfree(save_pgd);
30478+
30479+#ifdef CONFIG_PAX_PER_CPU_PGD
30480+ load_cr3(get_cpu_pgd(smp_processor_id()));
30481+#endif
30482+
30483 __flush_tlb_all();
30484 local_irq_restore(efi_flags);
30485 early_code_mapping_set_exec(0);
30486diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30487index fbe66e6..eae5e38 100644
30488--- a/arch/x86/platform/efi/efi_stub_32.S
30489+++ b/arch/x86/platform/efi/efi_stub_32.S
30490@@ -6,7 +6,9 @@
30491 */
30492
30493 #include <linux/linkage.h>
30494+#include <linux/init.h>
30495 #include <asm/page_types.h>
30496+#include <asm/segment.h>
30497
30498 /*
30499 * efi_call_phys(void *, ...) is a function with variable parameters.
30500@@ -20,7 +22,7 @@
30501 * service functions will comply with gcc calling convention, too.
30502 */
30503
30504-.text
30505+__INIT
30506 ENTRY(efi_call_phys)
30507 /*
30508 * 0. The function can only be called in Linux kernel. So CS has been
30509@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30510 * The mapping of lower virtual memory has been created in prelog and
30511 * epilog.
30512 */
30513- movl $1f, %edx
30514- subl $__PAGE_OFFSET, %edx
30515- jmp *%edx
30516+#ifdef CONFIG_PAX_KERNEXEC
30517+ movl $(__KERNEXEC_EFI_DS), %edx
30518+ mov %edx, %ds
30519+ mov %edx, %es
30520+ mov %edx, %ss
30521+ addl $2f,(1f)
30522+ ljmp *(1f)
30523+
30524+__INITDATA
30525+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30526+.previous
30527+
30528+2:
30529+ subl $2b,(1b)
30530+#else
30531+ jmp 1f-__PAGE_OFFSET
30532 1:
30533+#endif
30534
30535 /*
30536 * 2. Now on the top of stack is the return
30537@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30538 * parameter 2, ..., param n. To make things easy, we save the return
30539 * address of efi_call_phys in a global variable.
30540 */
30541- popl %edx
30542- movl %edx, saved_return_addr
30543- /* get the function pointer into ECX*/
30544- popl %ecx
30545- movl %ecx, efi_rt_function_ptr
30546- movl $2f, %edx
30547- subl $__PAGE_OFFSET, %edx
30548- pushl %edx
30549+ popl (saved_return_addr)
30550+ popl (efi_rt_function_ptr)
30551
30552 /*
30553 * 3. Clear PG bit in %CR0.
30554@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30555 /*
30556 * 5. Call the physical function.
30557 */
30558- jmp *%ecx
30559+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30560
30561-2:
30562 /*
30563 * 6. After EFI runtime service returns, control will return to
30564 * following instruction. We'd better readjust stack pointer first.
30565@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30566 movl %cr0, %edx
30567 orl $0x80000000, %edx
30568 movl %edx, %cr0
30569- jmp 1f
30570-1:
30571+
30572 /*
30573 * 8. Now restore the virtual mode from flat mode by
30574 * adding EIP with PAGE_OFFSET.
30575 */
30576- movl $1f, %edx
30577- jmp *%edx
30578+#ifdef CONFIG_PAX_KERNEXEC
30579+ movl $(__KERNEL_DS), %edx
30580+ mov %edx, %ds
30581+ mov %edx, %es
30582+ mov %edx, %ss
30583+ ljmp $(__KERNEL_CS),$1f
30584+#else
30585+ jmp 1f+__PAGE_OFFSET
30586+#endif
30587 1:
30588
30589 /*
30590 * 9. Balance the stack. And because EAX contain the return value,
30591 * we'd better not clobber it.
30592 */
30593- leal efi_rt_function_ptr, %edx
30594- movl (%edx), %ecx
30595- pushl %ecx
30596+ pushl (efi_rt_function_ptr)
30597
30598 /*
30599- * 10. Push the saved return address onto the stack and return.
30600+ * 10. Return to the saved return address.
30601 */
30602- leal saved_return_addr, %edx
30603- movl (%edx), %ecx
30604- pushl %ecx
30605- ret
30606+ jmpl *(saved_return_addr)
30607 ENDPROC(efi_call_phys)
30608 .previous
30609
30610-.data
30611+__INITDATA
30612 saved_return_addr:
30613 .long 0
30614 efi_rt_function_ptr:
30615diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30616index 4c07cca..2c8427d 100644
30617--- a/arch/x86/platform/efi/efi_stub_64.S
30618+++ b/arch/x86/platform/efi/efi_stub_64.S
30619@@ -7,6 +7,7 @@
30620 */
30621
30622 #include <linux/linkage.h>
30623+#include <asm/alternative-asm.h>
30624
30625 #define SAVE_XMM \
30626 mov %rsp, %rax; \
30627@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30628 call *%rdi
30629 addq $32, %rsp
30630 RESTORE_XMM
30631+ pax_force_retaddr 0, 1
30632 ret
30633 ENDPROC(efi_call0)
30634
30635@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30636 call *%rdi
30637 addq $32, %rsp
30638 RESTORE_XMM
30639+ pax_force_retaddr 0, 1
30640 ret
30641 ENDPROC(efi_call1)
30642
30643@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30644 call *%rdi
30645 addq $32, %rsp
30646 RESTORE_XMM
30647+ pax_force_retaddr 0, 1
30648 ret
30649 ENDPROC(efi_call2)
30650
30651@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30652 call *%rdi
30653 addq $32, %rsp
30654 RESTORE_XMM
30655+ pax_force_retaddr 0, 1
30656 ret
30657 ENDPROC(efi_call3)
30658
30659@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30660 call *%rdi
30661 addq $32, %rsp
30662 RESTORE_XMM
30663+ pax_force_retaddr 0, 1
30664 ret
30665 ENDPROC(efi_call4)
30666
30667@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30668 call *%rdi
30669 addq $48, %rsp
30670 RESTORE_XMM
30671+ pax_force_retaddr 0, 1
30672 ret
30673 ENDPROC(efi_call5)
30674
30675@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30676 call *%rdi
30677 addq $48, %rsp
30678 RESTORE_XMM
30679+ pax_force_retaddr 0, 1
30680 ret
30681 ENDPROC(efi_call6)
30682diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30683index a0a0a43..a48e233 100644
30684--- a/arch/x86/platform/mrst/mrst.c
30685+++ b/arch/x86/platform/mrst/mrst.c
30686@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30687 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30688 int sfi_mrtc_num;
30689
30690-static void mrst_power_off(void)
30691+static __noreturn void mrst_power_off(void)
30692 {
30693+ BUG();
30694 }
30695
30696-static void mrst_reboot(void)
30697+static __noreturn void mrst_reboot(void)
30698 {
30699 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30700+ BUG();
30701 }
30702
30703 /* parse all the mtimer info to a static mtimer array */
30704diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30705index d6ee929..3637cb5 100644
30706--- a/arch/x86/platform/olpc/olpc_dt.c
30707+++ b/arch/x86/platform/olpc/olpc_dt.c
30708@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30709 return res;
30710 }
30711
30712-static struct of_pdt_ops prom_olpc_ops __initdata = {
30713+static struct of_pdt_ops prom_olpc_ops __initconst = {
30714 .nextprop = olpc_dt_nextprop,
30715 .getproplen = olpc_dt_getproplen,
30716 .getproperty = olpc_dt_getproperty,
30717diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30718index 1cf5b30..fd45732 100644
30719--- a/arch/x86/power/cpu.c
30720+++ b/arch/x86/power/cpu.c
30721@@ -137,11 +137,8 @@ static void do_fpu_end(void)
30722 static void fix_processor_context(void)
30723 {
30724 int cpu = smp_processor_id();
30725- struct tss_struct *t = &per_cpu(init_tss, cpu);
30726-#ifdef CONFIG_X86_64
30727- struct desc_struct *desc = get_cpu_gdt_table(cpu);
30728- tss_desc tss;
30729-#endif
30730+ struct tss_struct *t = init_tss + cpu;
30731+
30732 set_tss_desc(cpu, t); /*
30733 * This just modifies memory; should not be
30734 * necessary. But... This is necessary, because
30735@@ -150,10 +147,6 @@ static void fix_processor_context(void)
30736 */
30737
30738 #ifdef CONFIG_X86_64
30739- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
30740- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
30741- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
30742-
30743 syscall_init(); /* This sets MSR_*STAR and related */
30744 #endif
30745 load_TR_desc(); /* This does ltr */
30746diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30747index a44f457..9140171 100644
30748--- a/arch/x86/realmode/init.c
30749+++ b/arch/x86/realmode/init.c
30750@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
30751 __va(real_mode_header->trampoline_header);
30752
30753 #ifdef CONFIG_X86_32
30754- trampoline_header->start = __pa_symbol(startup_32_smp);
30755+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
30756+
30757+#ifdef CONFIG_PAX_KERNEXEC
30758+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30759+#endif
30760+
30761+ trampoline_header->boot_cs = __BOOT_CS;
30762 trampoline_header->gdt_limit = __BOOT_DS + 7;
30763 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
30764 #else
30765@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
30766 *trampoline_cr4_features = read_cr4();
30767
30768 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
30769- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
30770+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
30771 trampoline_pgd[511] = init_level4_pgt[511].pgd;
30772 #endif
30773 }
30774diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30775index 8869287..d577672 100644
30776--- a/arch/x86/realmode/rm/Makefile
30777+++ b/arch/x86/realmode/rm/Makefile
30778@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30779 $(call cc-option, -fno-unit-at-a-time)) \
30780 $(call cc-option, -fno-stack-protector) \
30781 $(call cc-option, -mpreferred-stack-boundary=2)
30782+ifdef CONSTIFY_PLUGIN
30783+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30784+endif
30785 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30786 GCOV_PROFILE := n
30787diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30788index a28221d..93c40f1 100644
30789--- a/arch/x86/realmode/rm/header.S
30790+++ b/arch/x86/realmode/rm/header.S
30791@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30792 #endif
30793 /* APM/BIOS reboot */
30794 .long pa_machine_real_restart_asm
30795-#ifdef CONFIG_X86_64
30796+#ifdef CONFIG_X86_32
30797+ .long __KERNEL_CS
30798+#else
30799 .long __KERNEL32_CS
30800 #endif
30801 END(real_mode_header)
30802diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30803index c1b2791..f9e31c7 100644
30804--- a/arch/x86/realmode/rm/trampoline_32.S
30805+++ b/arch/x86/realmode/rm/trampoline_32.S
30806@@ -25,6 +25,12 @@
30807 #include <asm/page_types.h>
30808 #include "realmode.h"
30809
30810+#ifdef CONFIG_PAX_KERNEXEC
30811+#define ta(X) (X)
30812+#else
30813+#define ta(X) (pa_ ## X)
30814+#endif
30815+
30816 .text
30817 .code16
30818
30819@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30820
30821 cli # We should be safe anyway
30822
30823- movl tr_start, %eax # where we need to go
30824-
30825 movl $0xA5A5A5A5, trampoline_status
30826 # write marker for master knows we're running
30827
30828@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30829 movw $1, %dx # protected mode (PE) bit
30830 lmsw %dx # into protected mode
30831
30832- ljmpl $__BOOT_CS, $pa_startup_32
30833+ ljmpl *(trampoline_header)
30834
30835 .section ".text32","ax"
30836 .code32
30837@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30838 .balign 8
30839 GLOBAL(trampoline_header)
30840 tr_start: .space 4
30841- tr_gdt_pad: .space 2
30842+ tr_boot_cs: .space 2
30843 tr_gdt: .space 6
30844 END(trampoline_header)
30845
30846diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30847index bb360dc..3e5945f 100644
30848--- a/arch/x86/realmode/rm/trampoline_64.S
30849+++ b/arch/x86/realmode/rm/trampoline_64.S
30850@@ -107,7 +107,7 @@ ENTRY(startup_32)
30851 wrmsr
30852
30853 # Enable paging and in turn activate Long Mode
30854- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30855+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
30856 movl %eax, %cr0
30857
30858 /*
30859diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
30860index e812034..c747134 100644
30861--- a/arch/x86/tools/Makefile
30862+++ b/arch/x86/tools/Makefile
30863@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
30864
30865 $(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c
30866
30867-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
30868+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
30869 hostprogs-y += relocs
30870 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
30871 relocs: $(obj)/relocs
30872diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30873index f7bab68..b6d9886 100644
30874--- a/arch/x86/tools/relocs.c
30875+++ b/arch/x86/tools/relocs.c
30876@@ -1,5 +1,7 @@
30877 /* This is included from relocs_32/64.c */
30878
30879+#include "../../../include/generated/autoconf.h"
30880+
30881 #define ElfW(type) _ElfW(ELF_BITS, type)
30882 #define _ElfW(bits, type) __ElfW(bits, type)
30883 #define __ElfW(bits, type) Elf##bits##_##type
30884@@ -11,6 +13,7 @@
30885 #define Elf_Sym ElfW(Sym)
30886
30887 static Elf_Ehdr ehdr;
30888+static Elf_Phdr *phdr;
30889
30890 struct relocs {
30891 uint32_t *offset;
30892@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
30893 }
30894 }
30895
30896+static void read_phdrs(FILE *fp)
30897+{
30898+ unsigned int i;
30899+
30900+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
30901+ if (!phdr) {
30902+ die("Unable to allocate %d program headers\n",
30903+ ehdr.e_phnum);
30904+ }
30905+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30906+ die("Seek to %d failed: %s\n",
30907+ ehdr.e_phoff, strerror(errno));
30908+ }
30909+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30910+ die("Cannot read ELF program headers: %s\n",
30911+ strerror(errno));
30912+ }
30913+ for(i = 0; i < ehdr.e_phnum; i++) {
30914+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
30915+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
30916+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
30917+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
30918+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
30919+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
30920+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
30921+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
30922+ }
30923+
30924+}
30925+
30926 static void read_shdrs(FILE *fp)
30927 {
30928- int i;
30929+ unsigned int i;
30930 Elf_Shdr shdr;
30931
30932 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30933@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
30934
30935 static void read_strtabs(FILE *fp)
30936 {
30937- int i;
30938+ unsigned int i;
30939 for (i = 0; i < ehdr.e_shnum; i++) {
30940 struct section *sec = &secs[i];
30941 if (sec->shdr.sh_type != SHT_STRTAB) {
30942@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
30943
30944 static void read_symtabs(FILE *fp)
30945 {
30946- int i,j;
30947+ unsigned int i,j;
30948 for (i = 0; i < ehdr.e_shnum; i++) {
30949 struct section *sec = &secs[i];
30950 if (sec->shdr.sh_type != SHT_SYMTAB) {
30951@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
30952 }
30953
30954
30955-static void read_relocs(FILE *fp)
30956+static void read_relocs(FILE *fp, int use_real_mode)
30957 {
30958- int i,j;
30959+ unsigned int i,j;
30960+ uint32_t base;
30961+
30962 for (i = 0; i < ehdr.e_shnum; i++) {
30963 struct section *sec = &secs[i];
30964 if (sec->shdr.sh_type != SHT_REL_TYPE) {
30965@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
30966 die("Cannot read symbol table: %s\n",
30967 strerror(errno));
30968 }
30969+ base = 0;
30970+
30971+#ifdef CONFIG_X86_32
30972+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30973+ if (phdr[j].p_type != PT_LOAD )
30974+ continue;
30975+ if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
30976+ continue;
30977+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30978+ break;
30979+ }
30980+#endif
30981+
30982 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
30983 Elf_Rel *rel = &sec->reltab[j];
30984- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
30985+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
30986 rel->r_info = elf_xword_to_cpu(rel->r_info);
30987 #if (SHT_REL_TYPE == SHT_RELA)
30988 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
30989@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
30990
30991 static void print_absolute_symbols(void)
30992 {
30993- int i;
30994+ unsigned int i;
30995 const char *format;
30996
30997 if (ELF_BITS == 64)
30998@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
30999 for (i = 0; i < ehdr.e_shnum; i++) {
31000 struct section *sec = &secs[i];
31001 char *sym_strtab;
31002- int j;
31003+ unsigned int j;
31004
31005 if (sec->shdr.sh_type != SHT_SYMTAB) {
31006 continue;
31007@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
31008
31009 static void print_absolute_relocs(void)
31010 {
31011- int i, printed = 0;
31012+ unsigned int i, printed = 0;
31013 const char *format;
31014
31015 if (ELF_BITS == 64)
31016@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
31017 struct section *sec_applies, *sec_symtab;
31018 char *sym_strtab;
31019 Elf_Sym *sh_symtab;
31020- int j;
31021+ unsigned int j;
31022 if (sec->shdr.sh_type != SHT_REL_TYPE) {
31023 continue;
31024 }
31025@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
31026 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
31027 Elf_Sym *sym, const char *symname))
31028 {
31029- int i;
31030+ unsigned int i;
31031 /* Walk through the relocations */
31032 for (i = 0; i < ehdr.e_shnum; i++) {
31033 char *sym_strtab;
31034 Elf_Sym *sh_symtab;
31035 struct section *sec_applies, *sec_symtab;
31036- int j;
31037+ unsigned int j;
31038 struct section *sec = &secs[i];
31039
31040 if (sec->shdr.sh_type != SHT_REL_TYPE) {
31041@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
31042 {
31043 unsigned r_type = ELF32_R_TYPE(rel->r_info);
31044 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
31045+ char *sym_strtab = sec->link->link->strtab;
31046+
31047+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
31048+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
31049+ return 0;
31050+
31051+#ifdef CONFIG_PAX_KERNEXEC
31052+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
31053+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
31054+ return 0;
31055+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
31056+ return 0;
31057+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
31058+ return 0;
31059+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
31060+ return 0;
31061+#endif
31062
31063 switch (r_type) {
31064 case R_386_NONE:
31065@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
31066
31067 static void emit_relocs(int as_text, int use_real_mode)
31068 {
31069- int i;
31070+ unsigned int i;
31071 int (*write_reloc)(uint32_t, FILE *) = write32;
31072 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
31073 const char *symname);
31074@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
31075 {
31076 regex_init(use_real_mode);
31077 read_ehdr(fp);
31078+ read_phdrs(fp);
31079 read_shdrs(fp);
31080 read_strtabs(fp);
31081 read_symtabs(fp);
31082- read_relocs(fp);
31083+ read_relocs(fp, use_real_mode);
31084 if (ELF_BITS == 64)
31085 percpu_init();
31086 if (show_absolute_syms) {
31087diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
31088index 80ffa5b..a33bd15 100644
31089--- a/arch/x86/um/tls_32.c
31090+++ b/arch/x86/um/tls_32.c
31091@@ -260,7 +260,7 @@ out:
31092 if (unlikely(task == current &&
31093 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
31094 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
31095- "without flushed TLS.", current->pid);
31096+ "without flushed TLS.", task_pid_nr(current));
31097 }
31098
31099 return 0;
31100diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
31101index fd14be1..e3c79c0 100644
31102--- a/arch/x86/vdso/Makefile
31103+++ b/arch/x86/vdso/Makefile
31104@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
31105 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
31106 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
31107
31108-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31109+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31110 GCOV_PROFILE := n
31111
31112 #
31113diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
31114index 0faad64..39ef157 100644
31115--- a/arch/x86/vdso/vdso32-setup.c
31116+++ b/arch/x86/vdso/vdso32-setup.c
31117@@ -25,6 +25,7 @@
31118 #include <asm/tlbflush.h>
31119 #include <asm/vdso.h>
31120 #include <asm/proto.h>
31121+#include <asm/mman.h>
31122
31123 enum {
31124 VDSO_DISABLED = 0,
31125@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
31126 void enable_sep_cpu(void)
31127 {
31128 int cpu = get_cpu();
31129- struct tss_struct *tss = &per_cpu(init_tss, cpu);
31130+ struct tss_struct *tss = init_tss + cpu;
31131
31132 if (!boot_cpu_has(X86_FEATURE_SEP)) {
31133 put_cpu();
31134@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
31135 gate_vma.vm_start = FIXADDR_USER_START;
31136 gate_vma.vm_end = FIXADDR_USER_END;
31137 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
31138- gate_vma.vm_page_prot = __P101;
31139+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
31140
31141 return 0;
31142 }
31143@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31144 if (compat)
31145 addr = VDSO_HIGH_BASE;
31146 else {
31147- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
31148+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
31149 if (IS_ERR_VALUE(addr)) {
31150 ret = addr;
31151 goto up_fail;
31152 }
31153 }
31154
31155- current->mm->context.vdso = (void *)addr;
31156+ current->mm->context.vdso = addr;
31157
31158 if (compat_uses_vma || !compat) {
31159 /*
31160@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31161 }
31162
31163 current_thread_info()->sysenter_return =
31164- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31165+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31166
31167 up_fail:
31168 if (ret)
31169- current->mm->context.vdso = NULL;
31170+ current->mm->context.vdso = 0;
31171
31172 up_write(&mm->mmap_sem);
31173
31174@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
31175
31176 const char *arch_vma_name(struct vm_area_struct *vma)
31177 {
31178- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31179+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31180 return "[vdso]";
31181+
31182+#ifdef CONFIG_PAX_SEGMEXEC
31183+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
31184+ return "[vdso]";
31185+#endif
31186+
31187 return NULL;
31188 }
31189
31190@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31191 * Check to see if the corresponding task was created in compat vdso
31192 * mode.
31193 */
31194- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
31195+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
31196 return &gate_vma;
31197 return NULL;
31198 }
31199diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
31200index 431e875..cbb23f3 100644
31201--- a/arch/x86/vdso/vma.c
31202+++ b/arch/x86/vdso/vma.c
31203@@ -16,8 +16,6 @@
31204 #include <asm/vdso.h>
31205 #include <asm/page.h>
31206
31207-unsigned int __read_mostly vdso_enabled = 1;
31208-
31209 extern char vdso_start[], vdso_end[];
31210 extern unsigned short vdso_sync_cpuid;
31211
31212@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31213 * unaligned here as a result of stack start randomization.
31214 */
31215 addr = PAGE_ALIGN(addr);
31216- addr = align_vdso_addr(addr);
31217
31218 return addr;
31219 }
31220@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31221 unsigned size)
31222 {
31223 struct mm_struct *mm = current->mm;
31224- unsigned long addr;
31225+ unsigned long addr = 0;
31226 int ret;
31227
31228- if (!vdso_enabled)
31229- return 0;
31230-
31231 down_write(&mm->mmap_sem);
31232+
31233+#ifdef CONFIG_PAX_RANDMMAP
31234+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31235+#endif
31236+
31237 addr = vdso_addr(mm->start_stack, size);
31238+ addr = align_vdso_addr(addr);
31239 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31240 if (IS_ERR_VALUE(addr)) {
31241 ret = addr;
31242 goto up_fail;
31243 }
31244
31245- current->mm->context.vdso = (void *)addr;
31246+ mm->context.vdso = addr;
31247
31248 ret = install_special_mapping(mm, addr, size,
31249 VM_READ|VM_EXEC|
31250 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31251 pages);
31252- if (ret) {
31253- current->mm->context.vdso = NULL;
31254- goto up_fail;
31255- }
31256+ if (ret)
31257+ mm->context.vdso = 0;
31258
31259 up_fail:
31260 up_write(&mm->mmap_sem);
31261@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31262 vdsox32_size);
31263 }
31264 #endif
31265-
31266-static __init int vdso_setup(char *s)
31267-{
31268- vdso_enabled = simple_strtoul(s, NULL, 0);
31269- return 0;
31270-}
31271-__setup("vdso=", vdso_setup);
31272diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31273index a492be2..08678da 100644
31274--- a/arch/x86/xen/enlighten.c
31275+++ b/arch/x86/xen/enlighten.c
31276@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31277
31278 struct shared_info xen_dummy_shared_info;
31279
31280-void *xen_initial_gdt;
31281-
31282 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31283 __read_mostly int xen_have_vector_callback;
31284 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31285@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31286 {
31287 unsigned long va = dtr->address;
31288 unsigned int size = dtr->size + 1;
31289- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31290- unsigned long frames[pages];
31291+ unsigned long frames[65536 / PAGE_SIZE];
31292 int f;
31293
31294 /*
31295@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31296 {
31297 unsigned long va = dtr->address;
31298 unsigned int size = dtr->size + 1;
31299- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31300- unsigned long frames[pages];
31301+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
31302 int f;
31303
31304 /*
31305@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31306 * 8-byte entries, or 16 4k pages..
31307 */
31308
31309- BUG_ON(size > 65536);
31310+ BUG_ON(size > GDT_SIZE);
31311 BUG_ON(va & ~PAGE_MASK);
31312
31313 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
31314@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31315 return 0;
31316 }
31317
31318-static void set_xen_basic_apic_ops(void)
31319+static void __init set_xen_basic_apic_ops(void)
31320 {
31321 apic->read = xen_apic_read;
31322 apic->write = xen_apic_write;
31323@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31324 #endif
31325 };
31326
31327-static void xen_reboot(int reason)
31328+static __noreturn void xen_reboot(int reason)
31329 {
31330 struct sched_shutdown r = { .reason = reason };
31331
31332- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31333- BUG();
31334+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31335+ BUG();
31336 }
31337
31338-static void xen_restart(char *msg)
31339+static __noreturn void xen_restart(char *msg)
31340 {
31341 xen_reboot(SHUTDOWN_reboot);
31342 }
31343
31344-static void xen_emergency_restart(void)
31345+static __noreturn void xen_emergency_restart(void)
31346 {
31347 xen_reboot(SHUTDOWN_reboot);
31348 }
31349
31350-static void xen_machine_halt(void)
31351+static __noreturn void xen_machine_halt(void)
31352 {
31353 xen_reboot(SHUTDOWN_poweroff);
31354 }
31355
31356-static void xen_machine_power_off(void)
31357+static __noreturn void xen_machine_power_off(void)
31358 {
31359 if (pm_power_off)
31360 pm_power_off();
31361@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
31362 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31363
31364 /* Work out if we support NX */
31365- x86_configure_nx();
31366+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31367+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31368+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31369+ unsigned l, h;
31370+
31371+ __supported_pte_mask |= _PAGE_NX;
31372+ rdmsr(MSR_EFER, l, h);
31373+ l |= EFER_NX;
31374+ wrmsr(MSR_EFER, l, h);
31375+ }
31376+#endif
31377
31378 xen_setup_features();
31379
31380@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
31381
31382 machine_ops = xen_machine_ops;
31383
31384- /*
31385- * The only reliable way to retain the initial address of the
31386- * percpu gdt_page is to remember it here, so we can go and
31387- * mark it RW later, when the initial percpu area is freed.
31388- */
31389- xen_initial_gdt = &per_cpu(gdt_page, 0);
31390-
31391 xen_smp_init();
31392
31393 #ifdef CONFIG_ACPI_NUMA
31394@@ -1700,7 +1699,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31395 return NOTIFY_OK;
31396 }
31397
31398-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31399+static struct notifier_block xen_hvm_cpu_notifier = {
31400 .notifier_call = xen_hvm_cpu_notify,
31401 };
31402
31403diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31404index fdc3ba2..3daee39 100644
31405--- a/arch/x86/xen/mmu.c
31406+++ b/arch/x86/xen/mmu.c
31407@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31408 /* L3_k[510] -> level2_kernel_pgt
31409 * L3_i[511] -> level2_fixmap_pgt */
31410 convert_pfn_mfn(level3_kernel_pgt);
31411+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31412+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31413+ convert_pfn_mfn(level3_vmemmap_pgt);
31414
31415 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31416 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31417@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31418 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31419 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31420 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31421+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31422+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31423+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31424 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31425 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31426+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31427 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31428 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31429
31430@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
31431 pv_mmu_ops.set_pud = xen_set_pud;
31432 #if PAGETABLE_LEVELS == 4
31433 pv_mmu_ops.set_pgd = xen_set_pgd;
31434+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31435 #endif
31436
31437 /* This will work as long as patching hasn't happened yet
31438@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31439 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31440 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31441 .set_pgd = xen_set_pgd_hyper,
31442+ .set_pgd_batched = xen_set_pgd_hyper,
31443
31444 .alloc_pud = xen_alloc_pmd_init,
31445 .release_pud = xen_release_pmd_init,
31446diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31447index d99cae8..18401e1 100644
31448--- a/arch/x86/xen/smp.c
31449+++ b/arch/x86/xen/smp.c
31450@@ -240,11 +240,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31451 {
31452 BUG_ON(smp_processor_id() != 0);
31453 native_smp_prepare_boot_cpu();
31454-
31455- /* We've switched to the "real" per-cpu gdt, so make sure the
31456- old memory can be recycled */
31457- make_lowmem_page_readwrite(xen_initial_gdt);
31458-
31459 xen_filter_cpu_maps();
31460 xen_setup_vcpu_info_placement();
31461 }
31462@@ -314,7 +309,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31463 ctxt->user_regs.ss = __KERNEL_DS;
31464 #ifdef CONFIG_X86_32
31465 ctxt->user_regs.fs = __KERNEL_PERCPU;
31466- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31467+ savesegment(gs, ctxt->user_regs.gs);
31468 #else
31469 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31470 #endif
31471@@ -324,8 +319,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31472
31473 {
31474 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
31475- ctxt->user_regs.ds = __USER_DS;
31476- ctxt->user_regs.es = __USER_DS;
31477+ ctxt->user_regs.ds = __KERNEL_DS;
31478+ ctxt->user_regs.es = __KERNEL_DS;
31479
31480 xen_copy_trap_info(ctxt->trap_ctxt);
31481
31482@@ -370,13 +365,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31483 int rc;
31484
31485 per_cpu(current_task, cpu) = idle;
31486+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31487 #ifdef CONFIG_X86_32
31488 irq_ctx_init(cpu);
31489 #else
31490 clear_tsk_thread_flag(idle, TIF_FORK);
31491- per_cpu(kernel_stack, cpu) =
31492- (unsigned long)task_stack_page(idle) -
31493- KERNEL_STACK_OFFSET + THREAD_SIZE;
31494+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31495 #endif
31496 xen_setup_runstate_info(cpu);
31497 xen_setup_timer(cpu);
31498@@ -651,7 +645,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31499
31500 void __init xen_smp_init(void)
31501 {
31502- smp_ops = xen_smp_ops;
31503+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31504 xen_fill_possible_map();
31505 xen_init_spinlocks();
31506 }
31507diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31508index 33ca6e4..0ded929 100644
31509--- a/arch/x86/xen/xen-asm_32.S
31510+++ b/arch/x86/xen/xen-asm_32.S
31511@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31512 ESP_OFFSET=4 # bytes pushed onto stack
31513
31514 /*
31515- * Store vcpu_info pointer for easy access. Do it this way to
31516- * avoid having to reload %fs
31517+ * Store vcpu_info pointer for easy access.
31518 */
31519 #ifdef CONFIG_SMP
31520- GET_THREAD_INFO(%eax)
31521- movl %ss:TI_cpu(%eax), %eax
31522- movl %ss:__per_cpu_offset(,%eax,4), %eax
31523- mov %ss:xen_vcpu(%eax), %eax
31524+ push %fs
31525+ mov $(__KERNEL_PERCPU), %eax
31526+ mov %eax, %fs
31527+ mov PER_CPU_VAR(xen_vcpu), %eax
31528+ pop %fs
31529 #else
31530 movl %ss:xen_vcpu, %eax
31531 #endif
31532diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31533index 7faed58..ba4427c 100644
31534--- a/arch/x86/xen/xen-head.S
31535+++ b/arch/x86/xen/xen-head.S
31536@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31537 #ifdef CONFIG_X86_32
31538 mov %esi,xen_start_info
31539 mov $init_thread_union+THREAD_SIZE,%esp
31540+#ifdef CONFIG_SMP
31541+ movl $cpu_gdt_table,%edi
31542+ movl $__per_cpu_load,%eax
31543+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31544+ rorl $16,%eax
31545+ movb %al,__KERNEL_PERCPU + 4(%edi)
31546+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31547+ movl $__per_cpu_end - 1,%eax
31548+ subl $__per_cpu_start,%eax
31549+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31550+#endif
31551 #else
31552 mov %rsi,xen_start_info
31553 mov $init_thread_union+THREAD_SIZE,%rsp
31554diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31555index a95b417..b6dbd0b 100644
31556--- a/arch/x86/xen/xen-ops.h
31557+++ b/arch/x86/xen/xen-ops.h
31558@@ -10,8 +10,6 @@
31559 extern const char xen_hypervisor_callback[];
31560 extern const char xen_failsafe_callback[];
31561
31562-extern void *xen_initial_gdt;
31563-
31564 struct trap_info;
31565 void xen_copy_trap_info(struct trap_info *traps);
31566
31567diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31568index 525bd3d..ef888b1 100644
31569--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31570+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31571@@ -119,9 +119,9 @@
31572 ----------------------------------------------------------------------*/
31573
31574 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31575-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31576 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31577 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31578+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31579
31580 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31581 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31582diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31583index 2f33760..835e50a 100644
31584--- a/arch/xtensa/variants/fsf/include/variant/core.h
31585+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31586@@ -11,6 +11,7 @@
31587 #ifndef _XTENSA_CORE_H
31588 #define _XTENSA_CORE_H
31589
31590+#include <linux/const.h>
31591
31592 /****************************************************************************
31593 Parameters Useful for Any Code, USER or PRIVILEGED
31594@@ -112,9 +113,9 @@
31595 ----------------------------------------------------------------------*/
31596
31597 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31598-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31599 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31600 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31601+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31602
31603 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31604 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31605diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31606index af00795..2bb8105 100644
31607--- a/arch/xtensa/variants/s6000/include/variant/core.h
31608+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31609@@ -11,6 +11,7 @@
31610 #ifndef _XTENSA_CORE_CONFIGURATION_H
31611 #define _XTENSA_CORE_CONFIGURATION_H
31612
31613+#include <linux/const.h>
31614
31615 /****************************************************************************
31616 Parameters Useful for Any Code, USER or PRIVILEGED
31617@@ -118,9 +119,9 @@
31618 ----------------------------------------------------------------------*/
31619
31620 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31621-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31622 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31623 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31624+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31625
31626 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31627 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31628diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31629index 58916af..eb9dbcf6 100644
31630--- a/block/blk-iopoll.c
31631+++ b/block/blk-iopoll.c
31632@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31633 }
31634 EXPORT_SYMBOL(blk_iopoll_complete);
31635
31636-static void blk_iopoll_softirq(struct softirq_action *h)
31637+static void blk_iopoll_softirq(void)
31638 {
31639 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31640 int rearm = 0, budget = blk_iopoll_budget;
31641@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31642 return NOTIFY_OK;
31643 }
31644
31645-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31646+static struct notifier_block blk_iopoll_cpu_notifier = {
31647 .notifier_call = blk_iopoll_cpu_notify,
31648 };
31649
31650diff --git a/block/blk-map.c b/block/blk-map.c
31651index 623e1cd..ca1e109 100644
31652--- a/block/blk-map.c
31653+++ b/block/blk-map.c
31654@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31655 if (!len || !kbuf)
31656 return -EINVAL;
31657
31658- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31659+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31660 if (do_copy)
31661 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31662 else
31663diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31664index 467c8de..f3628c5 100644
31665--- a/block/blk-softirq.c
31666+++ b/block/blk-softirq.c
31667@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31668 * Softirq action handler - move entries to local list and loop over them
31669 * while passing them to the queue registered handler.
31670 */
31671-static void blk_done_softirq(struct softirq_action *h)
31672+static void blk_done_softirq(void)
31673 {
31674 struct list_head *cpu_list, local_list;
31675
31676@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31677 return NOTIFY_OK;
31678 }
31679
31680-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31681+static struct notifier_block blk_cpu_notifier = {
31682 .notifier_call = blk_cpu_notify,
31683 };
31684
31685diff --git a/block/bsg.c b/block/bsg.c
31686index 420a5a9..23834aa 100644
31687--- a/block/bsg.c
31688+++ b/block/bsg.c
31689@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31690 struct sg_io_v4 *hdr, struct bsg_device *bd,
31691 fmode_t has_write_perm)
31692 {
31693+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31694+ unsigned char *cmdptr;
31695+
31696 if (hdr->request_len > BLK_MAX_CDB) {
31697 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31698 if (!rq->cmd)
31699 return -ENOMEM;
31700- }
31701+ cmdptr = rq->cmd;
31702+ } else
31703+ cmdptr = tmpcmd;
31704
31705- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31706+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31707 hdr->request_len))
31708 return -EFAULT;
31709
31710+ if (cmdptr != rq->cmd)
31711+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31712+
31713 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31714 if (blk_verify_command(rq->cmd, has_write_perm))
31715 return -EPERM;
31716diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31717index 7c668c8..db3521c 100644
31718--- a/block/compat_ioctl.c
31719+++ b/block/compat_ioctl.c
31720@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31721 err |= __get_user(f->spec1, &uf->spec1);
31722 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31723 err |= __get_user(name, &uf->name);
31724- f->name = compat_ptr(name);
31725+ f->name = (void __force_kernel *)compat_ptr(name);
31726 if (err) {
31727 err = -EFAULT;
31728 goto out;
31729diff --git a/block/genhd.c b/block/genhd.c
31730index cdeb527..10aa34d 100644
31731--- a/block/genhd.c
31732+++ b/block/genhd.c
31733@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
31734
31735 /*
31736 * Register device numbers dev..(dev+range-1)
31737- * range must be nonzero
31738+ * Noop if @range is zero.
31739 * The hash chain is sorted on range, so that subranges can override.
31740 */
31741 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
31742 struct kobject *(*probe)(dev_t, int *, void *),
31743 int (*lock)(dev_t, void *), void *data)
31744 {
31745- kobj_map(bdev_map, devt, range, module, probe, lock, data);
31746+ if (range)
31747+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
31748 }
31749
31750 EXPORT_SYMBOL(blk_register_region);
31751
31752+/* undo blk_register_region(), noop if @range is zero */
31753 void blk_unregister_region(dev_t devt, unsigned long range)
31754 {
31755- kobj_unmap(bdev_map, devt, range);
31756+ if (range)
31757+ kobj_unmap(bdev_map, devt, range);
31758 }
31759
31760 EXPORT_SYMBOL(blk_unregister_region);
31761diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31762index c85fc89..51e690b 100644
31763--- a/block/partitions/efi.c
31764+++ b/block/partitions/efi.c
31765@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31766 if (!gpt)
31767 return NULL;
31768
31769+ if (!le32_to_cpu(gpt->num_partition_entries))
31770+ return NULL;
31771+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31772+ if (!pte)
31773+ return NULL;
31774+
31775 count = le32_to_cpu(gpt->num_partition_entries) *
31776 le32_to_cpu(gpt->sizeof_partition_entry);
31777- if (!count)
31778- return NULL;
31779- pte = kmalloc(count, GFP_KERNEL);
31780- if (!pte)
31781- return NULL;
31782-
31783 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31784 (u8 *) pte,
31785 count) < count) {
31786diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31787index a5ffcc9..3cedc9c 100644
31788--- a/block/scsi_ioctl.c
31789+++ b/block/scsi_ioctl.c
31790@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
31791 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31792 struct sg_io_hdr *hdr, fmode_t mode)
31793 {
31794- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31795+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31796+ unsigned char *cmdptr;
31797+
31798+ if (rq->cmd != rq->__cmd)
31799+ cmdptr = rq->cmd;
31800+ else
31801+ cmdptr = tmpcmd;
31802+
31803+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31804 return -EFAULT;
31805+
31806+ if (cmdptr != rq->cmd)
31807+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31808+
31809 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31810 return -EPERM;
31811
31812@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31813 int err;
31814 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31815 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31816+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31817+ unsigned char *cmdptr;
31818
31819 if (!sic)
31820 return -EINVAL;
31821@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31822 */
31823 err = -EFAULT;
31824 rq->cmd_len = cmdlen;
31825- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31826+
31827+ if (rq->cmd != rq->__cmd)
31828+ cmdptr = rq->cmd;
31829+ else
31830+ cmdptr = tmpcmd;
31831+
31832+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31833 goto error;
31834
31835+ if (rq->cmd != cmdptr)
31836+ memcpy(rq->cmd, cmdptr, cmdlen);
31837+
31838 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31839 goto error;
31840
31841diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31842index 7bdd61b..afec999 100644
31843--- a/crypto/cryptd.c
31844+++ b/crypto/cryptd.c
31845@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31846
31847 struct cryptd_blkcipher_request_ctx {
31848 crypto_completion_t complete;
31849-};
31850+} __no_const;
31851
31852 struct cryptd_hash_ctx {
31853 struct crypto_shash *child;
31854@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31855
31856 struct cryptd_aead_request_ctx {
31857 crypto_completion_t complete;
31858-};
31859+} __no_const;
31860
31861 static void cryptd_queue_worker(struct work_struct *work);
31862
31863diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
31864index b2c99dc..476c9fb 100644
31865--- a/crypto/pcrypt.c
31866+++ b/crypto/pcrypt.c
31867@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
31868 int ret;
31869
31870 pinst->kobj.kset = pcrypt_kset;
31871- ret = kobject_add(&pinst->kobj, NULL, name);
31872+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
31873 if (!ret)
31874 kobject_uevent(&pinst->kobj, KOBJ_ADD);
31875
31876@@ -455,8 +455,8 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
31877
31878 get_online_cpus();
31879
31880- pcrypt->wq = alloc_workqueue(name,
31881- WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
31882+ pcrypt->wq = alloc_workqueue("%s",
31883+ WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1, name);
31884 if (!pcrypt->wq)
31885 goto err;
31886
31887diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31888index f220d64..d359ad6 100644
31889--- a/drivers/acpi/apei/apei-internal.h
31890+++ b/drivers/acpi/apei/apei-internal.h
31891@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31892 struct apei_exec_ins_type {
31893 u32 flags;
31894 apei_exec_ins_func_t run;
31895-};
31896+} __do_const;
31897
31898 struct apei_exec_context {
31899 u32 ip;
31900diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31901index 33dc6a0..4b24b47 100644
31902--- a/drivers/acpi/apei/cper.c
31903+++ b/drivers/acpi/apei/cper.c
31904@@ -39,12 +39,12 @@
31905 */
31906 u64 cper_next_record_id(void)
31907 {
31908- static atomic64_t seq;
31909+ static atomic64_unchecked_t seq;
31910
31911- if (!atomic64_read(&seq))
31912- atomic64_set(&seq, ((u64)get_seconds()) << 32);
31913+ if (!atomic64_read_unchecked(&seq))
31914+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31915
31916- return atomic64_inc_return(&seq);
31917+ return atomic64_inc_return_unchecked(&seq);
31918 }
31919 EXPORT_SYMBOL_GPL(cper_next_record_id);
31920
31921diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31922index be60399..778b33e8 100644
31923--- a/drivers/acpi/bgrt.c
31924+++ b/drivers/acpi/bgrt.c
31925@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31926 return -ENODEV;
31927
31928 sysfs_bin_attr_init(&image_attr);
31929- image_attr.private = bgrt_image;
31930- image_attr.size = bgrt_image_size;
31931+ pax_open_kernel();
31932+ *(void **)&image_attr.private = bgrt_image;
31933+ *(size_t *)&image_attr.size = bgrt_image_size;
31934+ pax_close_kernel();
31935
31936 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31937 if (!bgrt_kobj)
31938diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31939index cb96296..b81293b 100644
31940--- a/drivers/acpi/blacklist.c
31941+++ b/drivers/acpi/blacklist.c
31942@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31943 u32 is_critical_error;
31944 };
31945
31946-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31947+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31948
31949 /*
31950 * POLICY: If *anything* doesn't work, put it on the blacklist.
31951@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31952 return 0;
31953 }
31954
31955-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31956+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31957 {
31958 .callback = dmi_disable_osi_vista,
31959 .ident = "Fujitsu Siemens",
31960diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31961index 7586544..636a2f0 100644
31962--- a/drivers/acpi/ec_sys.c
31963+++ b/drivers/acpi/ec_sys.c
31964@@ -12,6 +12,7 @@
31965 #include <linux/acpi.h>
31966 #include <linux/debugfs.h>
31967 #include <linux/module.h>
31968+#include <linux/uaccess.h>
31969 #include "internal.h"
31970
31971 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31972@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31973 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31974 */
31975 unsigned int size = EC_SPACE_SIZE;
31976- u8 *data = (u8 *) buf;
31977+ u8 data;
31978 loff_t init_off = *off;
31979 int err = 0;
31980
31981@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31982 size = count;
31983
31984 while (size) {
31985- err = ec_read(*off, &data[*off - init_off]);
31986+ err = ec_read(*off, &data);
31987 if (err)
31988 return err;
31989+ if (put_user(data, &buf[*off - init_off]))
31990+ return -EFAULT;
31991 *off += 1;
31992 size--;
31993 }
31994@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31995
31996 unsigned int size = count;
31997 loff_t init_off = *off;
31998- u8 *data = (u8 *) buf;
31999 int err = 0;
32000
32001 if (*off >= EC_SPACE_SIZE)
32002@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32003 }
32004
32005 while (size) {
32006- u8 byte_write = data[*off - init_off];
32007+ u8 byte_write;
32008+ if (get_user(byte_write, &buf[*off - init_off]))
32009+ return -EFAULT;
32010 err = ec_write(*off, byte_write);
32011 if (err)
32012 return err;
32013diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
32014index eb133c7..f571552 100644
32015--- a/drivers/acpi/processor_idle.c
32016+++ b/drivers/acpi/processor_idle.c
32017@@ -994,7 +994,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
32018 {
32019 int i, count = CPUIDLE_DRIVER_STATE_START;
32020 struct acpi_processor_cx *cx;
32021- struct cpuidle_state *state;
32022+ cpuidle_state_no_const *state;
32023 struct cpuidle_driver *drv = &acpi_idle_driver;
32024
32025 if (!pr->flags.power_setup_done)
32026diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
32027index fcae5fa..e9f71ea 100644
32028--- a/drivers/acpi/sysfs.c
32029+++ b/drivers/acpi/sysfs.c
32030@@ -423,11 +423,11 @@ static u32 num_counters;
32031 static struct attribute **all_attrs;
32032 static u32 acpi_gpe_count;
32033
32034-static struct attribute_group interrupt_stats_attr_group = {
32035+static attribute_group_no_const interrupt_stats_attr_group = {
32036 .name = "interrupts",
32037 };
32038
32039-static struct kobj_attribute *counter_attrs;
32040+static kobj_attribute_no_const *counter_attrs;
32041
32042 static void delete_gpe_attr_array(void)
32043 {
32044diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
32045index 7b9bdd8..37638ca 100644
32046--- a/drivers/ata/libahci.c
32047+++ b/drivers/ata/libahci.c
32048@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
32049 }
32050 EXPORT_SYMBOL_GPL(ahci_kick_engine);
32051
32052-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32053+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32054 struct ata_taskfile *tf, int is_cmd, u16 flags,
32055 unsigned long timeout_msec)
32056 {
32057diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
32058index adf002a..39bb8f9 100644
32059--- a/drivers/ata/libata-core.c
32060+++ b/drivers/ata/libata-core.c
32061@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
32062 struct ata_port *ap;
32063 unsigned int tag;
32064
32065- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32066+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32067 ap = qc->ap;
32068
32069 qc->flags = 0;
32070@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
32071 struct ata_port *ap;
32072 struct ata_link *link;
32073
32074- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32075+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32076 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
32077 ap = qc->ap;
32078 link = qc->dev->link;
32079@@ -5926,6 +5926,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32080 return;
32081
32082 spin_lock(&lock);
32083+ pax_open_kernel();
32084
32085 for (cur = ops->inherits; cur; cur = cur->inherits) {
32086 void **inherit = (void **)cur;
32087@@ -5939,8 +5940,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32088 if (IS_ERR(*pp))
32089 *pp = NULL;
32090
32091- ops->inherits = NULL;
32092+ *(struct ata_port_operations **)&ops->inherits = NULL;
32093
32094+ pax_close_kernel();
32095 spin_unlock(&lock);
32096 }
32097
32098diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
32099index 7638121..357a965 100644
32100--- a/drivers/ata/pata_arasan_cf.c
32101+++ b/drivers/ata/pata_arasan_cf.c
32102@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
32103 /* Handle platform specific quirks */
32104 if (quirk) {
32105 if (quirk & CF_BROKEN_PIO) {
32106- ap->ops->set_piomode = NULL;
32107+ pax_open_kernel();
32108+ *(void **)&ap->ops->set_piomode = NULL;
32109+ pax_close_kernel();
32110 ap->pio_mask = 0;
32111 }
32112 if (quirk & CF_BROKEN_MWDMA)
32113diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
32114index f9b983a..887b9d8 100644
32115--- a/drivers/atm/adummy.c
32116+++ b/drivers/atm/adummy.c
32117@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
32118 vcc->pop(vcc, skb);
32119 else
32120 dev_kfree_skb_any(skb);
32121- atomic_inc(&vcc->stats->tx);
32122+ atomic_inc_unchecked(&vcc->stats->tx);
32123
32124 return 0;
32125 }
32126diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
32127index 77a7480d..05cde58 100644
32128--- a/drivers/atm/ambassador.c
32129+++ b/drivers/atm/ambassador.c
32130@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
32131 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
32132
32133 // VC layer stats
32134- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32135+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32136
32137 // free the descriptor
32138 kfree (tx_descr);
32139@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32140 dump_skb ("<<<", vc, skb);
32141
32142 // VC layer stats
32143- atomic_inc(&atm_vcc->stats->rx);
32144+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32145 __net_timestamp(skb);
32146 // end of our responsibility
32147 atm_vcc->push (atm_vcc, skb);
32148@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32149 } else {
32150 PRINTK (KERN_INFO, "dropped over-size frame");
32151 // should we count this?
32152- atomic_inc(&atm_vcc->stats->rx_drop);
32153+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32154 }
32155
32156 } else {
32157@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
32158 }
32159
32160 if (check_area (skb->data, skb->len)) {
32161- atomic_inc(&atm_vcc->stats->tx_err);
32162+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
32163 return -ENOMEM; // ?
32164 }
32165
32166diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
32167index 0e3f8f9..765a7a5 100644
32168--- a/drivers/atm/atmtcp.c
32169+++ b/drivers/atm/atmtcp.c
32170@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32171 if (vcc->pop) vcc->pop(vcc,skb);
32172 else dev_kfree_skb(skb);
32173 if (dev_data) return 0;
32174- atomic_inc(&vcc->stats->tx_err);
32175+ atomic_inc_unchecked(&vcc->stats->tx_err);
32176 return -ENOLINK;
32177 }
32178 size = skb->len+sizeof(struct atmtcp_hdr);
32179@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32180 if (!new_skb) {
32181 if (vcc->pop) vcc->pop(vcc,skb);
32182 else dev_kfree_skb(skb);
32183- atomic_inc(&vcc->stats->tx_err);
32184+ atomic_inc_unchecked(&vcc->stats->tx_err);
32185 return -ENOBUFS;
32186 }
32187 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
32188@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32189 if (vcc->pop) vcc->pop(vcc,skb);
32190 else dev_kfree_skb(skb);
32191 out_vcc->push(out_vcc,new_skb);
32192- atomic_inc(&vcc->stats->tx);
32193- atomic_inc(&out_vcc->stats->rx);
32194+ atomic_inc_unchecked(&vcc->stats->tx);
32195+ atomic_inc_unchecked(&out_vcc->stats->rx);
32196 return 0;
32197 }
32198
32199@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32200 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32201 read_unlock(&vcc_sklist_lock);
32202 if (!out_vcc) {
32203- atomic_inc(&vcc->stats->tx_err);
32204+ atomic_inc_unchecked(&vcc->stats->tx_err);
32205 goto done;
32206 }
32207 skb_pull(skb,sizeof(struct atmtcp_hdr));
32208@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32209 __net_timestamp(new_skb);
32210 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32211 out_vcc->push(out_vcc,new_skb);
32212- atomic_inc(&vcc->stats->tx);
32213- atomic_inc(&out_vcc->stats->rx);
32214+ atomic_inc_unchecked(&vcc->stats->tx);
32215+ atomic_inc_unchecked(&out_vcc->stats->rx);
32216 done:
32217 if (vcc->pop) vcc->pop(vcc,skb);
32218 else dev_kfree_skb(skb);
32219diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
32220index b1955ba..b179940 100644
32221--- a/drivers/atm/eni.c
32222+++ b/drivers/atm/eni.c
32223@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
32224 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
32225 vcc->dev->number);
32226 length = 0;
32227- atomic_inc(&vcc->stats->rx_err);
32228+ atomic_inc_unchecked(&vcc->stats->rx_err);
32229 }
32230 else {
32231 length = ATM_CELL_SIZE-1; /* no HEC */
32232@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32233 size);
32234 }
32235 eff = length = 0;
32236- atomic_inc(&vcc->stats->rx_err);
32237+ atomic_inc_unchecked(&vcc->stats->rx_err);
32238 }
32239 else {
32240 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32241@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32242 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32243 vcc->dev->number,vcc->vci,length,size << 2,descr);
32244 length = eff = 0;
32245- atomic_inc(&vcc->stats->rx_err);
32246+ atomic_inc_unchecked(&vcc->stats->rx_err);
32247 }
32248 }
32249 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32250@@ -767,7 +767,7 @@ rx_dequeued++;
32251 vcc->push(vcc,skb);
32252 pushed++;
32253 }
32254- atomic_inc(&vcc->stats->rx);
32255+ atomic_inc_unchecked(&vcc->stats->rx);
32256 }
32257 wake_up(&eni_dev->rx_wait);
32258 }
32259@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32260 PCI_DMA_TODEVICE);
32261 if (vcc->pop) vcc->pop(vcc,skb);
32262 else dev_kfree_skb_irq(skb);
32263- atomic_inc(&vcc->stats->tx);
32264+ atomic_inc_unchecked(&vcc->stats->tx);
32265 wake_up(&eni_dev->tx_wait);
32266 dma_complete++;
32267 }
32268diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32269index b41c948..a002b17 100644
32270--- a/drivers/atm/firestream.c
32271+++ b/drivers/atm/firestream.c
32272@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32273 }
32274 }
32275
32276- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32277+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32278
32279 fs_dprintk (FS_DEBUG_TXMEM, "i");
32280 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32281@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32282 #endif
32283 skb_put (skb, qe->p1 & 0xffff);
32284 ATM_SKB(skb)->vcc = atm_vcc;
32285- atomic_inc(&atm_vcc->stats->rx);
32286+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32287 __net_timestamp(skb);
32288 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32289 atm_vcc->push (atm_vcc, skb);
32290@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32291 kfree (pe);
32292 }
32293 if (atm_vcc)
32294- atomic_inc(&atm_vcc->stats->rx_drop);
32295+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32296 break;
32297 case 0x1f: /* Reassembly abort: no buffers. */
32298 /* Silently increment error counter. */
32299 if (atm_vcc)
32300- atomic_inc(&atm_vcc->stats->rx_drop);
32301+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32302 break;
32303 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32304 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32305diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32306index 204814e..cede831 100644
32307--- a/drivers/atm/fore200e.c
32308+++ b/drivers/atm/fore200e.c
32309@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32310 #endif
32311 /* check error condition */
32312 if (*entry->status & STATUS_ERROR)
32313- atomic_inc(&vcc->stats->tx_err);
32314+ atomic_inc_unchecked(&vcc->stats->tx_err);
32315 else
32316- atomic_inc(&vcc->stats->tx);
32317+ atomic_inc_unchecked(&vcc->stats->tx);
32318 }
32319 }
32320
32321@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32322 if (skb == NULL) {
32323 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32324
32325- atomic_inc(&vcc->stats->rx_drop);
32326+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32327 return -ENOMEM;
32328 }
32329
32330@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32331
32332 dev_kfree_skb_any(skb);
32333
32334- atomic_inc(&vcc->stats->rx_drop);
32335+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32336 return -ENOMEM;
32337 }
32338
32339 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32340
32341 vcc->push(vcc, skb);
32342- atomic_inc(&vcc->stats->rx);
32343+ atomic_inc_unchecked(&vcc->stats->rx);
32344
32345 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32346
32347@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32348 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32349 fore200e->atm_dev->number,
32350 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32351- atomic_inc(&vcc->stats->rx_err);
32352+ atomic_inc_unchecked(&vcc->stats->rx_err);
32353 }
32354 }
32355
32356@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32357 goto retry_here;
32358 }
32359
32360- atomic_inc(&vcc->stats->tx_err);
32361+ atomic_inc_unchecked(&vcc->stats->tx_err);
32362
32363 fore200e->tx_sat++;
32364 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32365diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32366index 507362a..a845e57 100644
32367--- a/drivers/atm/he.c
32368+++ b/drivers/atm/he.c
32369@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32370
32371 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32372 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32373- atomic_inc(&vcc->stats->rx_drop);
32374+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32375 goto return_host_buffers;
32376 }
32377
32378@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32379 RBRQ_LEN_ERR(he_dev->rbrq_head)
32380 ? "LEN_ERR" : "",
32381 vcc->vpi, vcc->vci);
32382- atomic_inc(&vcc->stats->rx_err);
32383+ atomic_inc_unchecked(&vcc->stats->rx_err);
32384 goto return_host_buffers;
32385 }
32386
32387@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32388 vcc->push(vcc, skb);
32389 spin_lock(&he_dev->global_lock);
32390
32391- atomic_inc(&vcc->stats->rx);
32392+ atomic_inc_unchecked(&vcc->stats->rx);
32393
32394 return_host_buffers:
32395 ++pdus_assembled;
32396@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32397 tpd->vcc->pop(tpd->vcc, tpd->skb);
32398 else
32399 dev_kfree_skb_any(tpd->skb);
32400- atomic_inc(&tpd->vcc->stats->tx_err);
32401+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32402 }
32403 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32404 return;
32405@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32406 vcc->pop(vcc, skb);
32407 else
32408 dev_kfree_skb_any(skb);
32409- atomic_inc(&vcc->stats->tx_err);
32410+ atomic_inc_unchecked(&vcc->stats->tx_err);
32411 return -EINVAL;
32412 }
32413
32414@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32415 vcc->pop(vcc, skb);
32416 else
32417 dev_kfree_skb_any(skb);
32418- atomic_inc(&vcc->stats->tx_err);
32419+ atomic_inc_unchecked(&vcc->stats->tx_err);
32420 return -EINVAL;
32421 }
32422 #endif
32423@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32424 vcc->pop(vcc, skb);
32425 else
32426 dev_kfree_skb_any(skb);
32427- atomic_inc(&vcc->stats->tx_err);
32428+ atomic_inc_unchecked(&vcc->stats->tx_err);
32429 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32430 return -ENOMEM;
32431 }
32432@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32433 vcc->pop(vcc, skb);
32434 else
32435 dev_kfree_skb_any(skb);
32436- atomic_inc(&vcc->stats->tx_err);
32437+ atomic_inc_unchecked(&vcc->stats->tx_err);
32438 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32439 return -ENOMEM;
32440 }
32441@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32442 __enqueue_tpd(he_dev, tpd, cid);
32443 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32444
32445- atomic_inc(&vcc->stats->tx);
32446+ atomic_inc_unchecked(&vcc->stats->tx);
32447
32448 return 0;
32449 }
32450diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32451index 1dc0519..1aadaf7 100644
32452--- a/drivers/atm/horizon.c
32453+++ b/drivers/atm/horizon.c
32454@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32455 {
32456 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32457 // VC layer stats
32458- atomic_inc(&vcc->stats->rx);
32459+ atomic_inc_unchecked(&vcc->stats->rx);
32460 __net_timestamp(skb);
32461 // end of our responsibility
32462 vcc->push (vcc, skb);
32463@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32464 dev->tx_iovec = NULL;
32465
32466 // VC layer stats
32467- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32468+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32469
32470 // free the skb
32471 hrz_kfree_skb (skb);
32472diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32473index 272f009..a18ba55 100644
32474--- a/drivers/atm/idt77252.c
32475+++ b/drivers/atm/idt77252.c
32476@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32477 else
32478 dev_kfree_skb(skb);
32479
32480- atomic_inc(&vcc->stats->tx);
32481+ atomic_inc_unchecked(&vcc->stats->tx);
32482 }
32483
32484 atomic_dec(&scq->used);
32485@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32486 if ((sb = dev_alloc_skb(64)) == NULL) {
32487 printk("%s: Can't allocate buffers for aal0.\n",
32488 card->name);
32489- atomic_add(i, &vcc->stats->rx_drop);
32490+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32491 break;
32492 }
32493 if (!atm_charge(vcc, sb->truesize)) {
32494 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32495 card->name);
32496- atomic_add(i - 1, &vcc->stats->rx_drop);
32497+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32498 dev_kfree_skb(sb);
32499 break;
32500 }
32501@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32502 ATM_SKB(sb)->vcc = vcc;
32503 __net_timestamp(sb);
32504 vcc->push(vcc, sb);
32505- atomic_inc(&vcc->stats->rx);
32506+ atomic_inc_unchecked(&vcc->stats->rx);
32507
32508 cell += ATM_CELL_PAYLOAD;
32509 }
32510@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32511 "(CDC: %08x)\n",
32512 card->name, len, rpp->len, readl(SAR_REG_CDC));
32513 recycle_rx_pool_skb(card, rpp);
32514- atomic_inc(&vcc->stats->rx_err);
32515+ atomic_inc_unchecked(&vcc->stats->rx_err);
32516 return;
32517 }
32518 if (stat & SAR_RSQE_CRC) {
32519 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32520 recycle_rx_pool_skb(card, rpp);
32521- atomic_inc(&vcc->stats->rx_err);
32522+ atomic_inc_unchecked(&vcc->stats->rx_err);
32523 return;
32524 }
32525 if (skb_queue_len(&rpp->queue) > 1) {
32526@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32527 RXPRINTK("%s: Can't alloc RX skb.\n",
32528 card->name);
32529 recycle_rx_pool_skb(card, rpp);
32530- atomic_inc(&vcc->stats->rx_err);
32531+ atomic_inc_unchecked(&vcc->stats->rx_err);
32532 return;
32533 }
32534 if (!atm_charge(vcc, skb->truesize)) {
32535@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32536 __net_timestamp(skb);
32537
32538 vcc->push(vcc, skb);
32539- atomic_inc(&vcc->stats->rx);
32540+ atomic_inc_unchecked(&vcc->stats->rx);
32541
32542 return;
32543 }
32544@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32545 __net_timestamp(skb);
32546
32547 vcc->push(vcc, skb);
32548- atomic_inc(&vcc->stats->rx);
32549+ atomic_inc_unchecked(&vcc->stats->rx);
32550
32551 if (skb->truesize > SAR_FB_SIZE_3)
32552 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32553@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32554 if (vcc->qos.aal != ATM_AAL0) {
32555 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32556 card->name, vpi, vci);
32557- atomic_inc(&vcc->stats->rx_drop);
32558+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32559 goto drop;
32560 }
32561
32562 if ((sb = dev_alloc_skb(64)) == NULL) {
32563 printk("%s: Can't allocate buffers for AAL0.\n",
32564 card->name);
32565- atomic_inc(&vcc->stats->rx_err);
32566+ atomic_inc_unchecked(&vcc->stats->rx_err);
32567 goto drop;
32568 }
32569
32570@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32571 ATM_SKB(sb)->vcc = vcc;
32572 __net_timestamp(sb);
32573 vcc->push(vcc, sb);
32574- atomic_inc(&vcc->stats->rx);
32575+ atomic_inc_unchecked(&vcc->stats->rx);
32576
32577 drop:
32578 skb_pull(queue, 64);
32579@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32580
32581 if (vc == NULL) {
32582 printk("%s: NULL connection in send().\n", card->name);
32583- atomic_inc(&vcc->stats->tx_err);
32584+ atomic_inc_unchecked(&vcc->stats->tx_err);
32585 dev_kfree_skb(skb);
32586 return -EINVAL;
32587 }
32588 if (!test_bit(VCF_TX, &vc->flags)) {
32589 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32590- atomic_inc(&vcc->stats->tx_err);
32591+ atomic_inc_unchecked(&vcc->stats->tx_err);
32592 dev_kfree_skb(skb);
32593 return -EINVAL;
32594 }
32595@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32596 break;
32597 default:
32598 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32599- atomic_inc(&vcc->stats->tx_err);
32600+ atomic_inc_unchecked(&vcc->stats->tx_err);
32601 dev_kfree_skb(skb);
32602 return -EINVAL;
32603 }
32604
32605 if (skb_shinfo(skb)->nr_frags != 0) {
32606 printk("%s: No scatter-gather yet.\n", card->name);
32607- atomic_inc(&vcc->stats->tx_err);
32608+ atomic_inc_unchecked(&vcc->stats->tx_err);
32609 dev_kfree_skb(skb);
32610 return -EINVAL;
32611 }
32612@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32613
32614 err = queue_skb(card, vc, skb, oam);
32615 if (err) {
32616- atomic_inc(&vcc->stats->tx_err);
32617+ atomic_inc_unchecked(&vcc->stats->tx_err);
32618 dev_kfree_skb(skb);
32619 return err;
32620 }
32621@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32622 skb = dev_alloc_skb(64);
32623 if (!skb) {
32624 printk("%s: Out of memory in send_oam().\n", card->name);
32625- atomic_inc(&vcc->stats->tx_err);
32626+ atomic_inc_unchecked(&vcc->stats->tx_err);
32627 return -ENOMEM;
32628 }
32629 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32630diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32631index 4217f29..88f547a 100644
32632--- a/drivers/atm/iphase.c
32633+++ b/drivers/atm/iphase.c
32634@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32635 status = (u_short) (buf_desc_ptr->desc_mode);
32636 if (status & (RX_CER | RX_PTE | RX_OFL))
32637 {
32638- atomic_inc(&vcc->stats->rx_err);
32639+ atomic_inc_unchecked(&vcc->stats->rx_err);
32640 IF_ERR(printk("IA: bad packet, dropping it");)
32641 if (status & RX_CER) {
32642 IF_ERR(printk(" cause: packet CRC error\n");)
32643@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32644 len = dma_addr - buf_addr;
32645 if (len > iadev->rx_buf_sz) {
32646 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32647- atomic_inc(&vcc->stats->rx_err);
32648+ atomic_inc_unchecked(&vcc->stats->rx_err);
32649 goto out_free_desc;
32650 }
32651
32652@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32653 ia_vcc = INPH_IA_VCC(vcc);
32654 if (ia_vcc == NULL)
32655 {
32656- atomic_inc(&vcc->stats->rx_err);
32657+ atomic_inc_unchecked(&vcc->stats->rx_err);
32658 atm_return(vcc, skb->truesize);
32659 dev_kfree_skb_any(skb);
32660 goto INCR_DLE;
32661@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32662 if ((length > iadev->rx_buf_sz) || (length >
32663 (skb->len - sizeof(struct cpcs_trailer))))
32664 {
32665- atomic_inc(&vcc->stats->rx_err);
32666+ atomic_inc_unchecked(&vcc->stats->rx_err);
32667 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32668 length, skb->len);)
32669 atm_return(vcc, skb->truesize);
32670@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32671
32672 IF_RX(printk("rx_dle_intr: skb push");)
32673 vcc->push(vcc,skb);
32674- atomic_inc(&vcc->stats->rx);
32675+ atomic_inc_unchecked(&vcc->stats->rx);
32676 iadev->rx_pkt_cnt++;
32677 }
32678 INCR_DLE:
32679@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32680 {
32681 struct k_sonet_stats *stats;
32682 stats = &PRIV(_ia_dev[board])->sonet_stats;
32683- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32684- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32685- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32686- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32687- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32688- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32689- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32690- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32691- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32692+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32693+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32694+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32695+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32696+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32697+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32698+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32699+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32700+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32701 }
32702 ia_cmds.status = 0;
32703 break;
32704@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32705 if ((desc == 0) || (desc > iadev->num_tx_desc))
32706 {
32707 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32708- atomic_inc(&vcc->stats->tx);
32709+ atomic_inc_unchecked(&vcc->stats->tx);
32710 if (vcc->pop)
32711 vcc->pop(vcc, skb);
32712 else
32713@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32714 ATM_DESC(skb) = vcc->vci;
32715 skb_queue_tail(&iadev->tx_dma_q, skb);
32716
32717- atomic_inc(&vcc->stats->tx);
32718+ atomic_inc_unchecked(&vcc->stats->tx);
32719 iadev->tx_pkt_cnt++;
32720 /* Increment transaction counter */
32721 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32722
32723 #if 0
32724 /* add flow control logic */
32725- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32726+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32727 if (iavcc->vc_desc_cnt > 10) {
32728 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32729 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32730diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32731index fa7d701..1e404c7 100644
32732--- a/drivers/atm/lanai.c
32733+++ b/drivers/atm/lanai.c
32734@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32735 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32736 lanai_endtx(lanai, lvcc);
32737 lanai_free_skb(lvcc->tx.atmvcc, skb);
32738- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32739+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32740 }
32741
32742 /* Try to fill the buffer - don't call unless there is backlog */
32743@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32744 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32745 __net_timestamp(skb);
32746 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32747- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32748+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32749 out:
32750 lvcc->rx.buf.ptr = end;
32751 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32752@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32753 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32754 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32755 lanai->stats.service_rxnotaal5++;
32756- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32757+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32758 return 0;
32759 }
32760 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32761@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32762 int bytes;
32763 read_unlock(&vcc_sklist_lock);
32764 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32765- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32766+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32767 lvcc->stats.x.aal5.service_trash++;
32768 bytes = (SERVICE_GET_END(s) * 16) -
32769 (((unsigned long) lvcc->rx.buf.ptr) -
32770@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32771 }
32772 if (s & SERVICE_STREAM) {
32773 read_unlock(&vcc_sklist_lock);
32774- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32775+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32776 lvcc->stats.x.aal5.service_stream++;
32777 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32778 "PDU on VCI %d!\n", lanai->number, vci);
32779@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32780 return 0;
32781 }
32782 DPRINTK("got rx crc error on vci %d\n", vci);
32783- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32784+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32785 lvcc->stats.x.aal5.service_rxcrc++;
32786 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32787 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32788diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32789index 6587dc2..149833d 100644
32790--- a/drivers/atm/nicstar.c
32791+++ b/drivers/atm/nicstar.c
32792@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32793 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32794 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32795 card->index);
32796- atomic_inc(&vcc->stats->tx_err);
32797+ atomic_inc_unchecked(&vcc->stats->tx_err);
32798 dev_kfree_skb_any(skb);
32799 return -EINVAL;
32800 }
32801@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32802 if (!vc->tx) {
32803 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32804 card->index);
32805- atomic_inc(&vcc->stats->tx_err);
32806+ atomic_inc_unchecked(&vcc->stats->tx_err);
32807 dev_kfree_skb_any(skb);
32808 return -EINVAL;
32809 }
32810@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32811 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32812 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32813 card->index);
32814- atomic_inc(&vcc->stats->tx_err);
32815+ atomic_inc_unchecked(&vcc->stats->tx_err);
32816 dev_kfree_skb_any(skb);
32817 return -EINVAL;
32818 }
32819
32820 if (skb_shinfo(skb)->nr_frags != 0) {
32821 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32822- atomic_inc(&vcc->stats->tx_err);
32823+ atomic_inc_unchecked(&vcc->stats->tx_err);
32824 dev_kfree_skb_any(skb);
32825 return -EINVAL;
32826 }
32827@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32828 }
32829
32830 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32831- atomic_inc(&vcc->stats->tx_err);
32832+ atomic_inc_unchecked(&vcc->stats->tx_err);
32833 dev_kfree_skb_any(skb);
32834 return -EIO;
32835 }
32836- atomic_inc(&vcc->stats->tx);
32837+ atomic_inc_unchecked(&vcc->stats->tx);
32838
32839 return 0;
32840 }
32841@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32842 printk
32843 ("nicstar%d: Can't allocate buffers for aal0.\n",
32844 card->index);
32845- atomic_add(i, &vcc->stats->rx_drop);
32846+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32847 break;
32848 }
32849 if (!atm_charge(vcc, sb->truesize)) {
32850 RXPRINTK
32851 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32852 card->index);
32853- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32854+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32855 dev_kfree_skb_any(sb);
32856 break;
32857 }
32858@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32859 ATM_SKB(sb)->vcc = vcc;
32860 __net_timestamp(sb);
32861 vcc->push(vcc, sb);
32862- atomic_inc(&vcc->stats->rx);
32863+ atomic_inc_unchecked(&vcc->stats->rx);
32864 cell += ATM_CELL_PAYLOAD;
32865 }
32866
32867@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32868 if (iovb == NULL) {
32869 printk("nicstar%d: Out of iovec buffers.\n",
32870 card->index);
32871- atomic_inc(&vcc->stats->rx_drop);
32872+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32873 recycle_rx_buf(card, skb);
32874 return;
32875 }
32876@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32877 small or large buffer itself. */
32878 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32879 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32880- atomic_inc(&vcc->stats->rx_err);
32881+ atomic_inc_unchecked(&vcc->stats->rx_err);
32882 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32883 NS_MAX_IOVECS);
32884 NS_PRV_IOVCNT(iovb) = 0;
32885@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32886 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32887 card->index);
32888 which_list(card, skb);
32889- atomic_inc(&vcc->stats->rx_err);
32890+ atomic_inc_unchecked(&vcc->stats->rx_err);
32891 recycle_rx_buf(card, skb);
32892 vc->rx_iov = NULL;
32893 recycle_iov_buf(card, iovb);
32894@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32895 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32896 card->index);
32897 which_list(card, skb);
32898- atomic_inc(&vcc->stats->rx_err);
32899+ atomic_inc_unchecked(&vcc->stats->rx_err);
32900 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32901 NS_PRV_IOVCNT(iovb));
32902 vc->rx_iov = NULL;
32903@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32904 printk(" - PDU size mismatch.\n");
32905 else
32906 printk(".\n");
32907- atomic_inc(&vcc->stats->rx_err);
32908+ atomic_inc_unchecked(&vcc->stats->rx_err);
32909 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32910 NS_PRV_IOVCNT(iovb));
32911 vc->rx_iov = NULL;
32912@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32913 /* skb points to a small buffer */
32914 if (!atm_charge(vcc, skb->truesize)) {
32915 push_rxbufs(card, skb);
32916- atomic_inc(&vcc->stats->rx_drop);
32917+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32918 } else {
32919 skb_put(skb, len);
32920 dequeue_sm_buf(card, skb);
32921@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32922 ATM_SKB(skb)->vcc = vcc;
32923 __net_timestamp(skb);
32924 vcc->push(vcc, skb);
32925- atomic_inc(&vcc->stats->rx);
32926+ atomic_inc_unchecked(&vcc->stats->rx);
32927 }
32928 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32929 struct sk_buff *sb;
32930@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32931 if (len <= NS_SMBUFSIZE) {
32932 if (!atm_charge(vcc, sb->truesize)) {
32933 push_rxbufs(card, sb);
32934- atomic_inc(&vcc->stats->rx_drop);
32935+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32936 } else {
32937 skb_put(sb, len);
32938 dequeue_sm_buf(card, sb);
32939@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32940 ATM_SKB(sb)->vcc = vcc;
32941 __net_timestamp(sb);
32942 vcc->push(vcc, sb);
32943- atomic_inc(&vcc->stats->rx);
32944+ atomic_inc_unchecked(&vcc->stats->rx);
32945 }
32946
32947 push_rxbufs(card, skb);
32948@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32949
32950 if (!atm_charge(vcc, skb->truesize)) {
32951 push_rxbufs(card, skb);
32952- atomic_inc(&vcc->stats->rx_drop);
32953+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32954 } else {
32955 dequeue_lg_buf(card, skb);
32956 #ifdef NS_USE_DESTRUCTORS
32957@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32958 ATM_SKB(skb)->vcc = vcc;
32959 __net_timestamp(skb);
32960 vcc->push(vcc, skb);
32961- atomic_inc(&vcc->stats->rx);
32962+ atomic_inc_unchecked(&vcc->stats->rx);
32963 }
32964
32965 push_rxbufs(card, sb);
32966@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32967 printk
32968 ("nicstar%d: Out of huge buffers.\n",
32969 card->index);
32970- atomic_inc(&vcc->stats->rx_drop);
32971+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32972 recycle_iovec_rx_bufs(card,
32973 (struct iovec *)
32974 iovb->data,
32975@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32976 card->hbpool.count++;
32977 } else
32978 dev_kfree_skb_any(hb);
32979- atomic_inc(&vcc->stats->rx_drop);
32980+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32981 } else {
32982 /* Copy the small buffer to the huge buffer */
32983 sb = (struct sk_buff *)iov->iov_base;
32984@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32985 #endif /* NS_USE_DESTRUCTORS */
32986 __net_timestamp(hb);
32987 vcc->push(vcc, hb);
32988- atomic_inc(&vcc->stats->rx);
32989+ atomic_inc_unchecked(&vcc->stats->rx);
32990 }
32991 }
32992
32993diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32994index 32784d1..4a8434a 100644
32995--- a/drivers/atm/solos-pci.c
32996+++ b/drivers/atm/solos-pci.c
32997@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32998 }
32999 atm_charge(vcc, skb->truesize);
33000 vcc->push(vcc, skb);
33001- atomic_inc(&vcc->stats->rx);
33002+ atomic_inc_unchecked(&vcc->stats->rx);
33003 break;
33004
33005 case PKT_STATUS:
33006@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
33007 vcc = SKB_CB(oldskb)->vcc;
33008
33009 if (vcc) {
33010- atomic_inc(&vcc->stats->tx);
33011+ atomic_inc_unchecked(&vcc->stats->tx);
33012 solos_pop(vcc, oldskb);
33013 } else {
33014 dev_kfree_skb_irq(oldskb);
33015diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
33016index 0215934..ce9f5b1 100644
33017--- a/drivers/atm/suni.c
33018+++ b/drivers/atm/suni.c
33019@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
33020
33021
33022 #define ADD_LIMITED(s,v) \
33023- atomic_add((v),&stats->s); \
33024- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
33025+ atomic_add_unchecked((v),&stats->s); \
33026+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
33027
33028
33029 static void suni_hz(unsigned long from_timer)
33030diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
33031index 5120a96..e2572bd 100644
33032--- a/drivers/atm/uPD98402.c
33033+++ b/drivers/atm/uPD98402.c
33034@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
33035 struct sonet_stats tmp;
33036 int error = 0;
33037
33038- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33039+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33040 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
33041 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
33042 if (zero && !error) {
33043@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
33044
33045
33046 #define ADD_LIMITED(s,v) \
33047- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
33048- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
33049- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33050+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
33051+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
33052+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33053
33054
33055 static void stat_event(struct atm_dev *dev)
33056@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
33057 if (reason & uPD98402_INT_PFM) stat_event(dev);
33058 if (reason & uPD98402_INT_PCO) {
33059 (void) GET(PCOCR); /* clear interrupt cause */
33060- atomic_add(GET(HECCT),
33061+ atomic_add_unchecked(GET(HECCT),
33062 &PRIV(dev)->sonet_stats.uncorr_hcs);
33063 }
33064 if ((reason & uPD98402_INT_RFO) &&
33065@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
33066 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
33067 uPD98402_INT_LOS),PIMR); /* enable them */
33068 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
33069- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33070- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
33071- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
33072+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33073+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
33074+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
33075 return 0;
33076 }
33077
33078diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
33079index 969c3c2..9b72956 100644
33080--- a/drivers/atm/zatm.c
33081+++ b/drivers/atm/zatm.c
33082@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33083 }
33084 if (!size) {
33085 dev_kfree_skb_irq(skb);
33086- if (vcc) atomic_inc(&vcc->stats->rx_err);
33087+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
33088 continue;
33089 }
33090 if (!atm_charge(vcc,skb->truesize)) {
33091@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33092 skb->len = size;
33093 ATM_SKB(skb)->vcc = vcc;
33094 vcc->push(vcc,skb);
33095- atomic_inc(&vcc->stats->rx);
33096+ atomic_inc_unchecked(&vcc->stats->rx);
33097 }
33098 zout(pos & 0xffff,MTA(mbx));
33099 #if 0 /* probably a stupid idea */
33100@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
33101 skb_queue_head(&zatm_vcc->backlog,skb);
33102 break;
33103 }
33104- atomic_inc(&vcc->stats->tx);
33105+ atomic_inc_unchecked(&vcc->stats->tx);
33106 wake_up(&zatm_vcc->tx_wait);
33107 }
33108
33109diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
33110index d78b204..ecc1929 100644
33111--- a/drivers/base/attribute_container.c
33112+++ b/drivers/base/attribute_container.c
33113@@ -167,7 +167,7 @@ attribute_container_add_device(struct device *dev,
33114 ic->classdev.parent = get_device(dev);
33115 ic->classdev.class = cont->class;
33116 cont->class->dev_release = attribute_container_release;
33117- dev_set_name(&ic->classdev, dev_name(dev));
33118+ dev_set_name(&ic->classdev, "%s", dev_name(dev));
33119 if (fn)
33120 fn(cont, dev, &ic->classdev);
33121 else
33122diff --git a/drivers/base/bus.c b/drivers/base/bus.c
33123index d414331..b4dd4ba 100644
33124--- a/drivers/base/bus.c
33125+++ b/drivers/base/bus.c
33126@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
33127 return -EINVAL;
33128
33129 mutex_lock(&subsys->p->mutex);
33130- list_add_tail(&sif->node, &subsys->p->interfaces);
33131+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
33132 if (sif->add_dev) {
33133 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33134 while ((dev = subsys_dev_iter_next(&iter)))
33135@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
33136 subsys = sif->subsys;
33137
33138 mutex_lock(&subsys->p->mutex);
33139- list_del_init(&sif->node);
33140+ pax_list_del_init((struct list_head *)&sif->node);
33141 if (sif->remove_dev) {
33142 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33143 while ((dev = subsys_dev_iter_next(&iter)))
33144diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
33145index 7413d06..79155fa 100644
33146--- a/drivers/base/devtmpfs.c
33147+++ b/drivers/base/devtmpfs.c
33148@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
33149 if (!thread)
33150 return 0;
33151
33152- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
33153+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
33154 if (err)
33155 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
33156 else
33157@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
33158 *err = sys_unshare(CLONE_NEWNS);
33159 if (*err)
33160 goto out;
33161- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
33162+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
33163 if (*err)
33164 goto out;
33165- sys_chdir("/.."); /* will traverse into overmounted root */
33166- sys_chroot(".");
33167+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
33168+ sys_chroot((char __force_user *)".");
33169 complete(&setup_done);
33170 while (1) {
33171 spin_lock(&req_lock);
33172diff --git a/drivers/base/node.c b/drivers/base/node.c
33173index 7616a77c..8f57f51 100644
33174--- a/drivers/base/node.c
33175+++ b/drivers/base/node.c
33176@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
33177 struct node_attr {
33178 struct device_attribute attr;
33179 enum node_states state;
33180-};
33181+} __do_const;
33182
33183 static ssize_t show_node_state(struct device *dev,
33184 struct device_attribute *attr, char *buf)
33185diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
33186index 7072404..76dcebd 100644
33187--- a/drivers/base/power/domain.c
33188+++ b/drivers/base/power/domain.c
33189@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
33190 {
33191 struct cpuidle_driver *cpuidle_drv;
33192 struct gpd_cpu_data *cpu_data;
33193- struct cpuidle_state *idle_state;
33194+ cpuidle_state_no_const *idle_state;
33195 int ret = 0;
33196
33197 if (IS_ERR_OR_NULL(genpd) || state < 0)
33198@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
33199 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
33200 {
33201 struct gpd_cpu_data *cpu_data;
33202- struct cpuidle_state *idle_state;
33203+ cpuidle_state_no_const *idle_state;
33204 int ret = 0;
33205
33206 if (IS_ERR_OR_NULL(genpd))
33207diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
33208index a53ebd2..8f73eeb 100644
33209--- a/drivers/base/power/sysfs.c
33210+++ b/drivers/base/power/sysfs.c
33211@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
33212 return -EIO;
33213 }
33214 }
33215- return sprintf(buf, p);
33216+ return sprintf(buf, "%s", p);
33217 }
33218
33219 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
33220diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
33221index 79715e7..df06b3b 100644
33222--- a/drivers/base/power/wakeup.c
33223+++ b/drivers/base/power/wakeup.c
33224@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
33225 * They need to be modified together atomically, so it's better to use one
33226 * atomic variable to hold them both.
33227 */
33228-static atomic_t combined_event_count = ATOMIC_INIT(0);
33229+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
33230
33231 #define IN_PROGRESS_BITS (sizeof(int) * 4)
33232 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
33233
33234 static void split_counters(unsigned int *cnt, unsigned int *inpr)
33235 {
33236- unsigned int comb = atomic_read(&combined_event_count);
33237+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
33238
33239 *cnt = (comb >> IN_PROGRESS_BITS);
33240 *inpr = comb & MAX_IN_PROGRESS;
33241@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33242 ws->start_prevent_time = ws->last_time;
33243
33244 /* Increment the counter of events in progress. */
33245- cec = atomic_inc_return(&combined_event_count);
33246+ cec = atomic_inc_return_unchecked(&combined_event_count);
33247
33248 trace_wakeup_source_activate(ws->name, cec);
33249 }
33250@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33251 * Increment the counter of registered wakeup events and decrement the
33252 * couter of wakeup events in progress simultaneously.
33253 */
33254- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33255+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33256 trace_wakeup_source_deactivate(ws->name, cec);
33257
33258 split_counters(&cnt, &inpr);
33259diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
33260index e8d11b6..7b1b36f 100644
33261--- a/drivers/base/syscore.c
33262+++ b/drivers/base/syscore.c
33263@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
33264 void register_syscore_ops(struct syscore_ops *ops)
33265 {
33266 mutex_lock(&syscore_ops_lock);
33267- list_add_tail(&ops->node, &syscore_ops_list);
33268+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33269 mutex_unlock(&syscore_ops_lock);
33270 }
33271 EXPORT_SYMBOL_GPL(register_syscore_ops);
33272@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33273 void unregister_syscore_ops(struct syscore_ops *ops)
33274 {
33275 mutex_lock(&syscore_ops_lock);
33276- list_del(&ops->node);
33277+ pax_list_del((struct list_head *)&ops->node);
33278 mutex_unlock(&syscore_ops_lock);
33279 }
33280 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33281diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33282index 62b6c2c..4a11354 100644
33283--- a/drivers/block/cciss.c
33284+++ b/drivers/block/cciss.c
33285@@ -1189,6 +1189,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33286 int err;
33287 u32 cp;
33288
33289+ memset(&arg64, 0, sizeof(arg64));
33290+
33291 err = 0;
33292 err |=
33293 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33294@@ -3010,7 +3012,7 @@ static void start_io(ctlr_info_t *h)
33295 while (!list_empty(&h->reqQ)) {
33296 c = list_entry(h->reqQ.next, CommandList_struct, list);
33297 /* can't do anything if fifo is full */
33298- if ((h->access.fifo_full(h))) {
33299+ if ((h->access->fifo_full(h))) {
33300 dev_warn(&h->pdev->dev, "fifo full\n");
33301 break;
33302 }
33303@@ -3020,7 +3022,7 @@ static void start_io(ctlr_info_t *h)
33304 h->Qdepth--;
33305
33306 /* Tell the controller execute command */
33307- h->access.submit_command(h, c);
33308+ h->access->submit_command(h, c);
33309
33310 /* Put job onto the completed Q */
33311 addQ(&h->cmpQ, c);
33312@@ -3446,17 +3448,17 @@ startio:
33313
33314 static inline unsigned long get_next_completion(ctlr_info_t *h)
33315 {
33316- return h->access.command_completed(h);
33317+ return h->access->command_completed(h);
33318 }
33319
33320 static inline int interrupt_pending(ctlr_info_t *h)
33321 {
33322- return h->access.intr_pending(h);
33323+ return h->access->intr_pending(h);
33324 }
33325
33326 static inline long interrupt_not_for_us(ctlr_info_t *h)
33327 {
33328- return ((h->access.intr_pending(h) == 0) ||
33329+ return ((h->access->intr_pending(h) == 0) ||
33330 (h->interrupts_enabled == 0));
33331 }
33332
33333@@ -3489,7 +3491,7 @@ static inline u32 next_command(ctlr_info_t *h)
33334 u32 a;
33335
33336 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33337- return h->access.command_completed(h);
33338+ return h->access->command_completed(h);
33339
33340 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33341 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33342@@ -4046,7 +4048,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33343 trans_support & CFGTBL_Trans_use_short_tags);
33344
33345 /* Change the access methods to the performant access methods */
33346- h->access = SA5_performant_access;
33347+ h->access = &SA5_performant_access;
33348 h->transMethod = CFGTBL_Trans_Performant;
33349
33350 return;
33351@@ -4319,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33352 if (prod_index < 0)
33353 return -ENODEV;
33354 h->product_name = products[prod_index].product_name;
33355- h->access = *(products[prod_index].access);
33356+ h->access = products[prod_index].access;
33357
33358 if (cciss_board_disabled(h)) {
33359 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33360@@ -5051,7 +5053,7 @@ reinit_after_soft_reset:
33361 }
33362
33363 /* make sure the board interrupts are off */
33364- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33365+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33366 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33367 if (rc)
33368 goto clean2;
33369@@ -5101,7 +5103,7 @@ reinit_after_soft_reset:
33370 * fake ones to scoop up any residual completions.
33371 */
33372 spin_lock_irqsave(&h->lock, flags);
33373- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33374+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33375 spin_unlock_irqrestore(&h->lock, flags);
33376 free_irq(h->intr[h->intr_mode], h);
33377 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33378@@ -5121,9 +5123,9 @@ reinit_after_soft_reset:
33379 dev_info(&h->pdev->dev, "Board READY.\n");
33380 dev_info(&h->pdev->dev,
33381 "Waiting for stale completions to drain.\n");
33382- h->access.set_intr_mask(h, CCISS_INTR_ON);
33383+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33384 msleep(10000);
33385- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33386+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33387
33388 rc = controller_reset_failed(h->cfgtable);
33389 if (rc)
33390@@ -5146,7 +5148,7 @@ reinit_after_soft_reset:
33391 cciss_scsi_setup(h);
33392
33393 /* Turn the interrupts on so we can service requests */
33394- h->access.set_intr_mask(h, CCISS_INTR_ON);
33395+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33396
33397 /* Get the firmware version */
33398 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33399@@ -5218,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33400 kfree(flush_buf);
33401 if (return_code != IO_OK)
33402 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33403- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33404+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33405 free_irq(h->intr[h->intr_mode], h);
33406 }
33407
33408diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33409index 7fda30e..eb5dfe0 100644
33410--- a/drivers/block/cciss.h
33411+++ b/drivers/block/cciss.h
33412@@ -101,7 +101,7 @@ struct ctlr_info
33413 /* information about each logical volume */
33414 drive_info_struct *drv[CISS_MAX_LUN];
33415
33416- struct access_method access;
33417+ struct access_method *access;
33418
33419 /* queue and queue Info */
33420 struct list_head reqQ;
33421diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33422index 639d26b..fd6ad1f 100644
33423--- a/drivers/block/cpqarray.c
33424+++ b/drivers/block/cpqarray.c
33425@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33426 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33427 goto Enomem4;
33428 }
33429- hba[i]->access.set_intr_mask(hba[i], 0);
33430+ hba[i]->access->set_intr_mask(hba[i], 0);
33431 if (request_irq(hba[i]->intr, do_ida_intr,
33432 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33433 {
33434@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33435 add_timer(&hba[i]->timer);
33436
33437 /* Enable IRQ now that spinlock and rate limit timer are set up */
33438- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33439+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33440
33441 for(j=0; j<NWD; j++) {
33442 struct gendisk *disk = ida_gendisk[i][j];
33443@@ -694,7 +694,7 @@ DBGINFO(
33444 for(i=0; i<NR_PRODUCTS; i++) {
33445 if (board_id == products[i].board_id) {
33446 c->product_name = products[i].product_name;
33447- c->access = *(products[i].access);
33448+ c->access = products[i].access;
33449 break;
33450 }
33451 }
33452@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33453 hba[ctlr]->intr = intr;
33454 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33455 hba[ctlr]->product_name = products[j].product_name;
33456- hba[ctlr]->access = *(products[j].access);
33457+ hba[ctlr]->access = products[j].access;
33458 hba[ctlr]->ctlr = ctlr;
33459 hba[ctlr]->board_id = board_id;
33460 hba[ctlr]->pci_dev = NULL; /* not PCI */
33461@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
33462
33463 while((c = h->reqQ) != NULL) {
33464 /* Can't do anything if we're busy */
33465- if (h->access.fifo_full(h) == 0)
33466+ if (h->access->fifo_full(h) == 0)
33467 return;
33468
33469 /* Get the first entry from the request Q */
33470@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
33471 h->Qdepth--;
33472
33473 /* Tell the controller to do our bidding */
33474- h->access.submit_command(h, c);
33475+ h->access->submit_command(h, c);
33476
33477 /* Get onto the completion Q */
33478 addQ(&h->cmpQ, c);
33479@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33480 unsigned long flags;
33481 __u32 a,a1;
33482
33483- istat = h->access.intr_pending(h);
33484+ istat = h->access->intr_pending(h);
33485 /* Is this interrupt for us? */
33486 if (istat == 0)
33487 return IRQ_NONE;
33488@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33489 */
33490 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33491 if (istat & FIFO_NOT_EMPTY) {
33492- while((a = h->access.command_completed(h))) {
33493+ while((a = h->access->command_completed(h))) {
33494 a1 = a; a &= ~3;
33495 if ((c = h->cmpQ) == NULL)
33496 {
33497@@ -1193,6 +1193,7 @@ out_passthru:
33498 ida_pci_info_struct pciinfo;
33499
33500 if (!arg) return -EINVAL;
33501+ memset(&pciinfo, 0, sizeof(pciinfo));
33502 pciinfo.bus = host->pci_dev->bus->number;
33503 pciinfo.dev_fn = host->pci_dev->devfn;
33504 pciinfo.board_id = host->board_id;
33505@@ -1447,11 +1448,11 @@ static int sendcmd(
33506 /*
33507 * Disable interrupt
33508 */
33509- info_p->access.set_intr_mask(info_p, 0);
33510+ info_p->access->set_intr_mask(info_p, 0);
33511 /* Make sure there is room in the command FIFO */
33512 /* Actually it should be completely empty at this time. */
33513 for (i = 200000; i > 0; i--) {
33514- temp = info_p->access.fifo_full(info_p);
33515+ temp = info_p->access->fifo_full(info_p);
33516 if (temp != 0) {
33517 break;
33518 }
33519@@ -1464,7 +1465,7 @@ DBG(
33520 /*
33521 * Send the cmd
33522 */
33523- info_p->access.submit_command(info_p, c);
33524+ info_p->access->submit_command(info_p, c);
33525 complete = pollcomplete(ctlr);
33526
33527 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33528@@ -1547,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33529 * we check the new geometry. Then turn interrupts back on when
33530 * we're done.
33531 */
33532- host->access.set_intr_mask(host, 0);
33533+ host->access->set_intr_mask(host, 0);
33534 getgeometry(ctlr);
33535- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33536+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33537
33538 for(i=0; i<NWD; i++) {
33539 struct gendisk *disk = ida_gendisk[ctlr][i];
33540@@ -1589,7 +1590,7 @@ static int pollcomplete(int ctlr)
33541 /* Wait (up to 2 seconds) for a command to complete */
33542
33543 for (i = 200000; i > 0; i--) {
33544- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33545+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33546 if (done == 0) {
33547 udelay(10); /* a short fixed delay */
33548 } else
33549diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33550index be73e9d..7fbf140 100644
33551--- a/drivers/block/cpqarray.h
33552+++ b/drivers/block/cpqarray.h
33553@@ -99,7 +99,7 @@ struct ctlr_info {
33554 drv_info_t drv[NWD];
33555 struct proc_dir_entry *proc;
33556
33557- struct access_method access;
33558+ struct access_method *access;
33559
33560 cmdlist_t *reqQ;
33561 cmdlist_t *cmpQ;
33562diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33563index f943aac..99bfd19 100644
33564--- a/drivers/block/drbd/drbd_int.h
33565+++ b/drivers/block/drbd/drbd_int.h
33566@@ -582,7 +582,7 @@ struct drbd_epoch {
33567 struct drbd_tconn *tconn;
33568 struct list_head list;
33569 unsigned int barrier_nr;
33570- atomic_t epoch_size; /* increased on every request added. */
33571+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33572 atomic_t active; /* increased on every req. added, and dec on every finished. */
33573 unsigned long flags;
33574 };
33575@@ -1021,7 +1021,7 @@ struct drbd_conf {
33576 unsigned int al_tr_number;
33577 int al_tr_cycle;
33578 wait_queue_head_t seq_wait;
33579- atomic_t packet_seq;
33580+ atomic_unchecked_t packet_seq;
33581 unsigned int peer_seq;
33582 spinlock_t peer_seq_lock;
33583 unsigned int minor;
33584@@ -1562,7 +1562,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33585 char __user *uoptval;
33586 int err;
33587
33588- uoptval = (char __user __force *)optval;
33589+ uoptval = (char __force_user *)optval;
33590
33591 set_fs(KERNEL_DS);
33592 if (level == SOL_SOCKET)
33593diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33594index a5dca6a..bb27967 100644
33595--- a/drivers/block/drbd/drbd_main.c
33596+++ b/drivers/block/drbd/drbd_main.c
33597@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33598 p->sector = sector;
33599 p->block_id = block_id;
33600 p->blksize = blksize;
33601- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33602+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33603 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33604 }
33605
33606@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33607 return -EIO;
33608 p->sector = cpu_to_be64(req->i.sector);
33609 p->block_id = (unsigned long)req;
33610- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33611+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33612 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33613 if (mdev->state.conn >= C_SYNC_SOURCE &&
33614 mdev->state.conn <= C_PAUSED_SYNC_T)
33615@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33616 {
33617 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33618
33619- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33620- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33621+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33622+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33623 kfree(tconn->current_epoch);
33624
33625 idr_destroy(&tconn->volumes);
33626diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33627index 4222aff..1f79506 100644
33628--- a/drivers/block/drbd/drbd_receiver.c
33629+++ b/drivers/block/drbd/drbd_receiver.c
33630@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
33631 {
33632 int err;
33633
33634- atomic_set(&mdev->packet_seq, 0);
33635+ atomic_set_unchecked(&mdev->packet_seq, 0);
33636 mdev->peer_seq = 0;
33637
33638 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33639@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33640 do {
33641 next_epoch = NULL;
33642
33643- epoch_size = atomic_read(&epoch->epoch_size);
33644+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33645
33646 switch (ev & ~EV_CLEANUP) {
33647 case EV_PUT:
33648@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33649 rv = FE_DESTROYED;
33650 } else {
33651 epoch->flags = 0;
33652- atomic_set(&epoch->epoch_size, 0);
33653+ atomic_set_unchecked(&epoch->epoch_size, 0);
33654 /* atomic_set(&epoch->active, 0); is already zero */
33655 if (rv == FE_STILL_LIVE)
33656 rv = FE_RECYCLED;
33657@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33658 conn_wait_active_ee_empty(tconn);
33659 drbd_flush(tconn);
33660
33661- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33662+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33663 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33664 if (epoch)
33665 break;
33666@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33667 }
33668
33669 epoch->flags = 0;
33670- atomic_set(&epoch->epoch_size, 0);
33671+ atomic_set_unchecked(&epoch->epoch_size, 0);
33672 atomic_set(&epoch->active, 0);
33673
33674 spin_lock(&tconn->epoch_lock);
33675- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33676+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33677 list_add(&epoch->list, &tconn->current_epoch->list);
33678 tconn->current_epoch = epoch;
33679 tconn->epochs++;
33680@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33681
33682 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33683 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33684- atomic_inc(&tconn->current_epoch->epoch_size);
33685+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33686 err2 = drbd_drain_block(mdev, pi->size);
33687 if (!err)
33688 err = err2;
33689@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33690
33691 spin_lock(&tconn->epoch_lock);
33692 peer_req->epoch = tconn->current_epoch;
33693- atomic_inc(&peer_req->epoch->epoch_size);
33694+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33695 atomic_inc(&peer_req->epoch->active);
33696 spin_unlock(&tconn->epoch_lock);
33697
33698@@ -4347,7 +4347,7 @@ struct data_cmd {
33699 int expect_payload;
33700 size_t pkt_size;
33701 int (*fn)(struct drbd_tconn *, struct packet_info *);
33702-};
33703+} __do_const;
33704
33705 static struct data_cmd drbd_cmd_handler[] = {
33706 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33707@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33708 if (!list_empty(&tconn->current_epoch->list))
33709 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33710 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33711- atomic_set(&tconn->current_epoch->epoch_size, 0);
33712+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33713 tconn->send.seen_any_write_yet = false;
33714
33715 conn_info(tconn, "Connection closed\n");
33716@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33717 struct asender_cmd {
33718 size_t pkt_size;
33719 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33720-};
33721+} __do_const;
33722
33723 static struct asender_cmd asender_tbl[] = {
33724 [P_PING] = { 0, got_Ping },
33725diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33726index d92d50f..a7e9d97 100644
33727--- a/drivers/block/loop.c
33728+++ b/drivers/block/loop.c
33729@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
33730
33731 file_start_write(file);
33732 set_fs(get_ds());
33733- bw = file->f_op->write(file, buf, len, &pos);
33734+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33735 set_fs(old_fs);
33736 file_end_write(file);
33737 if (likely(bw == len))
33738diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
33739index f5d0ea1..c62380a 100644
33740--- a/drivers/block/pktcdvd.c
33741+++ b/drivers/block/pktcdvd.c
33742@@ -84,7 +84,7 @@
33743 #define MAX_SPEED 0xffff
33744
33745 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
33746- ~(sector_t)((pd)->settings.size - 1))
33747+ ~(sector_t)((pd)->settings.size - 1UL))
33748
33749 static DEFINE_MUTEX(pktcdvd_mutex);
33750 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
33751diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33752index 8a3aff7..d7538c2 100644
33753--- a/drivers/cdrom/cdrom.c
33754+++ b/drivers/cdrom/cdrom.c
33755@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33756 ENSURE(reset, CDC_RESET);
33757 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33758 cdi->mc_flags = 0;
33759- cdo->n_minors = 0;
33760 cdi->options = CDO_USE_FFLAGS;
33761
33762 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33763@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33764 else
33765 cdi->cdda_method = CDDA_OLD;
33766
33767- if (!cdo->generic_packet)
33768- cdo->generic_packet = cdrom_dummy_generic_packet;
33769+ if (!cdo->generic_packet) {
33770+ pax_open_kernel();
33771+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33772+ pax_close_kernel();
33773+ }
33774
33775 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33776 mutex_lock(&cdrom_mutex);
33777@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33778 if (cdi->exit)
33779 cdi->exit(cdi);
33780
33781- cdi->ops->n_minors--;
33782 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33783 }
33784
33785@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
33786 */
33787 nr = nframes;
33788 do {
33789- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33790+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33791 if (cgc.buffer)
33792 break;
33793
33794@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
33795 struct cdrom_device_info *cdi;
33796 int ret;
33797
33798- ret = scnprintf(info + *pos, max_size - *pos, header);
33799+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
33800 if (!ret)
33801 return 1;
33802
33803diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33804index 4afcb65..a68a32d 100644
33805--- a/drivers/cdrom/gdrom.c
33806+++ b/drivers/cdrom/gdrom.c
33807@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33808 .audio_ioctl = gdrom_audio_ioctl,
33809 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33810 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33811- .n_minors = 1,
33812 };
33813
33814 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33815diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33816index 3bb6fa3..34013fb 100644
33817--- a/drivers/char/Kconfig
33818+++ b/drivers/char/Kconfig
33819@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33820
33821 config DEVKMEM
33822 bool "/dev/kmem virtual device support"
33823- default y
33824+ default n
33825+ depends on !GRKERNSEC_KMEM
33826 help
33827 Say Y here if you want to support the /dev/kmem device. The
33828 /dev/kmem device is rarely used, but can be used for certain
33829@@ -582,6 +583,7 @@ config DEVPORT
33830 bool
33831 depends on !M68K
33832 depends on ISA || PCI
33833+ depends on !GRKERNSEC_KMEM
33834 default y
33835
33836 source "drivers/s390/char/Kconfig"
33837diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
33838index a48e05b..6bac831 100644
33839--- a/drivers/char/agp/compat_ioctl.c
33840+++ b/drivers/char/agp/compat_ioctl.c
33841@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
33842 return -ENOMEM;
33843 }
33844
33845- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
33846+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
33847 sizeof(*usegment) * ureserve.seg_count)) {
33848 kfree(usegment);
33849 kfree(ksegment);
33850diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33851index 2e04433..771f2cc 100644
33852--- a/drivers/char/agp/frontend.c
33853+++ b/drivers/char/agp/frontend.c
33854@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33855 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33856 return -EFAULT;
33857
33858- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33859+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33860 return -EFAULT;
33861
33862 client = agp_find_client_by_pid(reserve.pid);
33863@@ -847,7 +847,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33864 if (segment == NULL)
33865 return -ENOMEM;
33866
33867- if (copy_from_user(segment, (void __user *) reserve.seg_list,
33868+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
33869 sizeof(struct agp_segment) * reserve.seg_count)) {
33870 kfree(segment);
33871 return -EFAULT;
33872diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33873index 4f94375..413694e 100644
33874--- a/drivers/char/genrtc.c
33875+++ b/drivers/char/genrtc.c
33876@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
33877 switch (cmd) {
33878
33879 case RTC_PLL_GET:
33880+ memset(&pll, 0, sizeof(pll));
33881 if (get_rtc_pll(&pll))
33882 return -EINVAL;
33883 else
33884diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33885index d784650..e8bfd69 100644
33886--- a/drivers/char/hpet.c
33887+++ b/drivers/char/hpet.c
33888@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33889 }
33890
33891 static int
33892-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33893+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33894 struct hpet_info *info)
33895 {
33896 struct hpet_timer __iomem *timer;
33897diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
33898index 86fe45c..c0ea948 100644
33899--- a/drivers/char/hw_random/intel-rng.c
33900+++ b/drivers/char/hw_random/intel-rng.c
33901@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
33902
33903 if (no_fwh_detect)
33904 return -ENODEV;
33905- printk(warning);
33906+ printk("%s", warning);
33907 return -EBUSY;
33908 }
33909
33910diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33911index 4445fa1..7c6de37 100644
33912--- a/drivers/char/ipmi/ipmi_msghandler.c
33913+++ b/drivers/char/ipmi/ipmi_msghandler.c
33914@@ -420,7 +420,7 @@ struct ipmi_smi {
33915 struct proc_dir_entry *proc_dir;
33916 char proc_dir_name[10];
33917
33918- atomic_t stats[IPMI_NUM_STATS];
33919+ atomic_unchecked_t stats[IPMI_NUM_STATS];
33920
33921 /*
33922 * run_to_completion duplicate of smb_info, smi_info
33923@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33924
33925
33926 #define ipmi_inc_stat(intf, stat) \
33927- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33928+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33929 #define ipmi_get_stat(intf, stat) \
33930- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33931+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33932
33933 static int is_lan_addr(struct ipmi_addr *addr)
33934 {
33935@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33936 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33937 init_waitqueue_head(&intf->waitq);
33938 for (i = 0; i < IPMI_NUM_STATS; i++)
33939- atomic_set(&intf->stats[i], 0);
33940+ atomic_set_unchecked(&intf->stats[i], 0);
33941
33942 intf->proc_dir = NULL;
33943
33944diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33945index af4b23f..79806fc 100644
33946--- a/drivers/char/ipmi/ipmi_si_intf.c
33947+++ b/drivers/char/ipmi/ipmi_si_intf.c
33948@@ -275,7 +275,7 @@ struct smi_info {
33949 unsigned char slave_addr;
33950
33951 /* Counters and things for the proc filesystem. */
33952- atomic_t stats[SI_NUM_STATS];
33953+ atomic_unchecked_t stats[SI_NUM_STATS];
33954
33955 struct task_struct *thread;
33956
33957@@ -284,9 +284,9 @@ struct smi_info {
33958 };
33959
33960 #define smi_inc_stat(smi, stat) \
33961- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33962+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33963 #define smi_get_stat(smi, stat) \
33964- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33965+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33966
33967 #define SI_MAX_PARMS 4
33968
33969@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
33970 atomic_set(&new_smi->req_events, 0);
33971 new_smi->run_to_completion = 0;
33972 for (i = 0; i < SI_NUM_STATS; i++)
33973- atomic_set(&new_smi->stats[i], 0);
33974+ atomic_set_unchecked(&new_smi->stats[i], 0);
33975
33976 new_smi->interrupt_disabled = 1;
33977 atomic_set(&new_smi->stop_operation, 0);
33978diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33979index 1ccbe94..6ad651a 100644
33980--- a/drivers/char/mem.c
33981+++ b/drivers/char/mem.c
33982@@ -18,6 +18,7 @@
33983 #include <linux/raw.h>
33984 #include <linux/tty.h>
33985 #include <linux/capability.h>
33986+#include <linux/security.h>
33987 #include <linux/ptrace.h>
33988 #include <linux/device.h>
33989 #include <linux/highmem.h>
33990@@ -38,6 +39,10 @@
33991
33992 #define DEVPORT_MINOR 4
33993
33994+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33995+extern const struct file_operations grsec_fops;
33996+#endif
33997+
33998 static inline unsigned long size_inside_page(unsigned long start,
33999 unsigned long size)
34000 {
34001@@ -69,9 +74,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34002
34003 while (cursor < to) {
34004 if (!devmem_is_allowed(pfn)) {
34005+#ifdef CONFIG_GRKERNSEC_KMEM
34006+ gr_handle_mem_readwrite(from, to);
34007+#else
34008 printk(KERN_INFO
34009 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
34010 current->comm, from, to);
34011+#endif
34012 return 0;
34013 }
34014 cursor += PAGE_SIZE;
34015@@ -79,6 +88,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34016 }
34017 return 1;
34018 }
34019+#elif defined(CONFIG_GRKERNSEC_KMEM)
34020+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34021+{
34022+ return 0;
34023+}
34024 #else
34025 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34026 {
34027@@ -121,6 +135,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34028
34029 while (count > 0) {
34030 unsigned long remaining;
34031+ char *temp;
34032
34033 sz = size_inside_page(p, count);
34034
34035@@ -136,7 +151,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34036 if (!ptr)
34037 return -EFAULT;
34038
34039- remaining = copy_to_user(buf, ptr, sz);
34040+#ifdef CONFIG_PAX_USERCOPY
34041+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34042+ if (!temp) {
34043+ unxlate_dev_mem_ptr(p, ptr);
34044+ return -ENOMEM;
34045+ }
34046+ memcpy(temp, ptr, sz);
34047+#else
34048+ temp = ptr;
34049+#endif
34050+
34051+ remaining = copy_to_user(buf, temp, sz);
34052+
34053+#ifdef CONFIG_PAX_USERCOPY
34054+ kfree(temp);
34055+#endif
34056+
34057 unxlate_dev_mem_ptr(p, ptr);
34058 if (remaining)
34059 return -EFAULT;
34060@@ -379,7 +410,7 @@ static ssize_t read_oldmem(struct file *file, char __user *buf,
34061 else
34062 csize = count;
34063
34064- rc = copy_oldmem_page(pfn, buf, csize, offset, 1);
34065+ rc = copy_oldmem_page(pfn, (char __force_kernel *)buf, csize, offset, 1);
34066 if (rc < 0)
34067 return rc;
34068 buf += csize;
34069@@ -399,9 +430,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34070 size_t count, loff_t *ppos)
34071 {
34072 unsigned long p = *ppos;
34073- ssize_t low_count, read, sz;
34074+ ssize_t low_count, read, sz, err = 0;
34075 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
34076- int err = 0;
34077
34078 read = 0;
34079 if (p < (unsigned long) high_memory) {
34080@@ -423,6 +453,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34081 }
34082 #endif
34083 while (low_count > 0) {
34084+ char *temp;
34085+
34086 sz = size_inside_page(p, low_count);
34087
34088 /*
34089@@ -432,7 +464,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34090 */
34091 kbuf = xlate_dev_kmem_ptr((char *)p);
34092
34093- if (copy_to_user(buf, kbuf, sz))
34094+#ifdef CONFIG_PAX_USERCOPY
34095+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34096+ if (!temp)
34097+ return -ENOMEM;
34098+ memcpy(temp, kbuf, sz);
34099+#else
34100+ temp = kbuf;
34101+#endif
34102+
34103+ err = copy_to_user(buf, temp, sz);
34104+
34105+#ifdef CONFIG_PAX_USERCOPY
34106+ kfree(temp);
34107+#endif
34108+
34109+ if (err)
34110 return -EFAULT;
34111 buf += sz;
34112 p += sz;
34113@@ -869,6 +916,9 @@ static const struct memdev {
34114 #ifdef CONFIG_CRASH_DUMP
34115 [12] = { "oldmem", 0, &oldmem_fops, NULL },
34116 #endif
34117+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34118+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
34119+#endif
34120 };
34121
34122 static int memory_open(struct inode *inode, struct file *filp)
34123@@ -940,7 +990,7 @@ static int __init chr_dev_init(void)
34124 continue;
34125
34126 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
34127- NULL, devlist[minor].name);
34128+ NULL, "%s", devlist[minor].name);
34129 }
34130
34131 return tty_init();
34132diff --git a/drivers/char/mwave/tp3780i.c b/drivers/char/mwave/tp3780i.c
34133index c689697..04e6d6a2 100644
34134--- a/drivers/char/mwave/tp3780i.c
34135+++ b/drivers/char/mwave/tp3780i.c
34136@@ -479,6 +479,7 @@ int tp3780I_QueryAbilities(THINKPAD_BD_DATA * pBDData, MW_ABILITIES * pAbilities
34137 PRINTK_2(TRACE_TP3780I,
34138 "tp3780i::tp3780I_QueryAbilities entry pBDData %p\n", pBDData);
34139
34140+ memset(pAbilities, 0, sizeof(*pAbilities));
34141 /* fill out standard constant fields */
34142 pAbilities->instr_per_sec = pBDData->rDspSettings.uIps;
34143 pAbilities->data_size = pBDData->rDspSettings.uDStoreSize;
34144diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
34145index 9df78e2..01ba9ae 100644
34146--- a/drivers/char/nvram.c
34147+++ b/drivers/char/nvram.c
34148@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
34149
34150 spin_unlock_irq(&rtc_lock);
34151
34152- if (copy_to_user(buf, contents, tmp - contents))
34153+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
34154 return -EFAULT;
34155
34156 *ppos = i;
34157diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
34158index 5c5cc00..ac9edb7 100644
34159--- a/drivers/char/pcmcia/synclink_cs.c
34160+++ b/drivers/char/pcmcia/synclink_cs.c
34161@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34162
34163 if (debug_level >= DEBUG_LEVEL_INFO)
34164 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
34165- __FILE__, __LINE__, info->device_name, port->count);
34166+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
34167
34168- WARN_ON(!port->count);
34169+ WARN_ON(!atomic_read(&port->count));
34170
34171 if (tty_port_close_start(port, tty, filp) == 0)
34172 goto cleanup;
34173@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34174 cleanup:
34175 if (debug_level >= DEBUG_LEVEL_INFO)
34176 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
34177- tty->driver->name, port->count);
34178+ tty->driver->name, atomic_read(&port->count));
34179 }
34180
34181 /* Wait until the transmitter is empty.
34182@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34183
34184 if (debug_level >= DEBUG_LEVEL_INFO)
34185 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
34186- __FILE__, __LINE__, tty->driver->name, port->count);
34187+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
34188
34189 /* If port is closing, signal caller to try again */
34190 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
34191@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34192 goto cleanup;
34193 }
34194 spin_lock(&port->lock);
34195- port->count++;
34196+ atomic_inc(&port->count);
34197 spin_unlock(&port->lock);
34198 spin_unlock_irqrestore(&info->netlock, flags);
34199
34200- if (port->count == 1) {
34201+ if (atomic_read(&port->count) == 1) {
34202 /* 1st open on this device, init hardware */
34203 retval = startup(info, tty);
34204 if (retval < 0)
34205@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
34206 unsigned short new_crctype;
34207
34208 /* return error if TTY interface open */
34209- if (info->port.count)
34210+ if (atomic_read(&info->port.count))
34211 return -EBUSY;
34212
34213 switch (encoding)
34214@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
34215
34216 /* arbitrate between network and tty opens */
34217 spin_lock_irqsave(&info->netlock, flags);
34218- if (info->port.count != 0 || info->netcount != 0) {
34219+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
34220 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
34221 spin_unlock_irqrestore(&info->netlock, flags);
34222 return -EBUSY;
34223@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34224 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
34225
34226 /* return error if TTY interface open */
34227- if (info->port.count)
34228+ if (atomic_read(&info->port.count))
34229 return -EBUSY;
34230
34231 if (cmd != SIOCWANDEV)
34232diff --git a/drivers/char/random.c b/drivers/char/random.c
34233index 35487e8..dac8bd1 100644
34234--- a/drivers/char/random.c
34235+++ b/drivers/char/random.c
34236@@ -272,8 +272,13 @@
34237 /*
34238 * Configuration information
34239 */
34240+#ifdef CONFIG_GRKERNSEC_RANDNET
34241+#define INPUT_POOL_WORDS 512
34242+#define OUTPUT_POOL_WORDS 128
34243+#else
34244 #define INPUT_POOL_WORDS 128
34245 #define OUTPUT_POOL_WORDS 32
34246+#endif
34247 #define SEC_XFER_SIZE 512
34248 #define EXTRACT_SIZE 10
34249
34250@@ -313,10 +318,17 @@ static struct poolinfo {
34251 int poolwords;
34252 int tap1, tap2, tap3, tap4, tap5;
34253 } poolinfo_table[] = {
34254+#ifdef CONFIG_GRKERNSEC_RANDNET
34255+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
34256+ { 512, 411, 308, 208, 104, 1 },
34257+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
34258+ { 128, 103, 76, 51, 25, 1 },
34259+#else
34260 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
34261 { 128, 103, 76, 51, 25, 1 },
34262 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
34263 { 32, 26, 20, 14, 7, 1 },
34264+#endif
34265 #if 0
34266 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
34267 { 2048, 1638, 1231, 819, 411, 1 },
34268@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
34269 input_rotate += i ? 7 : 14;
34270 }
34271
34272- ACCESS_ONCE(r->input_rotate) = input_rotate;
34273- ACCESS_ONCE(r->add_ptr) = i;
34274+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
34275+ ACCESS_ONCE_RW(r->add_ptr) = i;
34276 smp_wmb();
34277
34278 if (out)
34279@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
34280
34281 extract_buf(r, tmp);
34282 i = min_t(int, nbytes, EXTRACT_SIZE);
34283- if (copy_to_user(buf, tmp, i)) {
34284+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
34285 ret = -EFAULT;
34286 break;
34287 }
34288@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
34289 #include <linux/sysctl.h>
34290
34291 static int min_read_thresh = 8, min_write_thresh;
34292-static int max_read_thresh = INPUT_POOL_WORDS * 32;
34293+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
34294 static int max_write_thresh = INPUT_POOL_WORDS * 32;
34295 static char sysctl_bootid[16];
34296
34297@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
34298 static int proc_do_uuid(ctl_table *table, int write,
34299 void __user *buffer, size_t *lenp, loff_t *ppos)
34300 {
34301- ctl_table fake_table;
34302+ ctl_table_no_const fake_table;
34303 unsigned char buf[64], tmp_uuid[16], *uuid;
34304
34305 uuid = table->data;
34306diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
34307index bf2349db..5456d53 100644
34308--- a/drivers/char/sonypi.c
34309+++ b/drivers/char/sonypi.c
34310@@ -54,6 +54,7 @@
34311
34312 #include <asm/uaccess.h>
34313 #include <asm/io.h>
34314+#include <asm/local.h>
34315
34316 #include <linux/sonypi.h>
34317
34318@@ -490,7 +491,7 @@ static struct sonypi_device {
34319 spinlock_t fifo_lock;
34320 wait_queue_head_t fifo_proc_list;
34321 struct fasync_struct *fifo_async;
34322- int open_count;
34323+ local_t open_count;
34324 int model;
34325 struct input_dev *input_jog_dev;
34326 struct input_dev *input_key_dev;
34327@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
34328 static int sonypi_misc_release(struct inode *inode, struct file *file)
34329 {
34330 mutex_lock(&sonypi_device.lock);
34331- sonypi_device.open_count--;
34332+ local_dec(&sonypi_device.open_count);
34333 mutex_unlock(&sonypi_device.lock);
34334 return 0;
34335 }
34336@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
34337 {
34338 mutex_lock(&sonypi_device.lock);
34339 /* Flush input queue on first open */
34340- if (!sonypi_device.open_count)
34341+ if (!local_read(&sonypi_device.open_count))
34342 kfifo_reset(&sonypi_device.fifo);
34343- sonypi_device.open_count++;
34344+ local_inc(&sonypi_device.open_count);
34345 mutex_unlock(&sonypi_device.lock);
34346
34347 return 0;
34348diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
34349index 64420b3..5c40b56 100644
34350--- a/drivers/char/tpm/tpm_acpi.c
34351+++ b/drivers/char/tpm/tpm_acpi.c
34352@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
34353 virt = acpi_os_map_memory(start, len);
34354 if (!virt) {
34355 kfree(log->bios_event_log);
34356+ log->bios_event_log = NULL;
34357 printk("%s: ERROR - Unable to map memory\n", __func__);
34358 return -EIO;
34359 }
34360
34361- memcpy_fromio(log->bios_event_log, virt, len);
34362+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34363
34364 acpi_os_unmap_memory(virt, len);
34365 return 0;
34366diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34367index 84ddc55..1d32f1e 100644
34368--- a/drivers/char/tpm/tpm_eventlog.c
34369+++ b/drivers/char/tpm/tpm_eventlog.c
34370@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34371 event = addr;
34372
34373 if ((event->event_type == 0 && event->event_size == 0) ||
34374- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34375+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34376 return NULL;
34377
34378 return addr;
34379@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34380 return NULL;
34381
34382 if ((event->event_type == 0 && event->event_size == 0) ||
34383- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34384+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34385 return NULL;
34386
34387 (*pos)++;
34388@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34389 int i;
34390
34391 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34392- seq_putc(m, data[i]);
34393+ if (!seq_putc(m, data[i]))
34394+ return -EFAULT;
34395
34396 return 0;
34397 }
34398diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34399index 1b456fe..2510242 100644
34400--- a/drivers/char/virtio_console.c
34401+++ b/drivers/char/virtio_console.c
34402@@ -679,7 +679,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34403 if (to_user) {
34404 ssize_t ret;
34405
34406- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34407+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34408 if (ret)
34409 return -EFAULT;
34410 } else {
34411@@ -778,7 +778,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34412 if (!port_has_data(port) && !port->host_connected)
34413 return 0;
34414
34415- return fill_readbuf(port, ubuf, count, true);
34416+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34417 }
34418
34419 static int wait_port_writable(struct port *port, bool nonblock)
34420diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
34421index a33f46f..a720eed 100644
34422--- a/drivers/clk/clk-composite.c
34423+++ b/drivers/clk/clk-composite.c
34424@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
34425 struct clk *clk;
34426 struct clk_init_data init;
34427 struct clk_composite *composite;
34428- struct clk_ops *clk_composite_ops;
34429+ clk_ops_no_const *clk_composite_ops;
34430
34431 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
34432 if (!composite) {
34433diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
34434index bd11315..7f87098 100644
34435--- a/drivers/clk/socfpga/clk.c
34436+++ b/drivers/clk/socfpga/clk.c
34437@@ -22,6 +22,7 @@
34438 #include <linux/clk-provider.h>
34439 #include <linux/io.h>
34440 #include <linux/of.h>
34441+#include <asm/pgtable.h>
34442
34443 /* Clock Manager offsets */
34444 #define CLKMGR_CTRL 0x0
34445@@ -135,8 +136,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
34446 if (strcmp(clk_name, "main_pll") || strcmp(clk_name, "periph_pll") ||
34447 strcmp(clk_name, "sdram_pll")) {
34448 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
34449- clk_pll_ops.enable = clk_gate_ops.enable;
34450- clk_pll_ops.disable = clk_gate_ops.disable;
34451+ pax_open_kernel();
34452+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
34453+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
34454+ pax_close_kernel();
34455 }
34456
34457 clk = clk_register(NULL, &socfpga_clk->hw.hw);
34458diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
34459index a2b2541..bc1e7ff 100644
34460--- a/drivers/clocksource/arm_arch_timer.c
34461+++ b/drivers/clocksource/arm_arch_timer.c
34462@@ -264,7 +264,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34463 return NOTIFY_OK;
34464 }
34465
34466-static struct notifier_block arch_timer_cpu_nb __cpuinitdata = {
34467+static struct notifier_block arch_timer_cpu_nb = {
34468 .notifier_call = arch_timer_cpu_notify,
34469 };
34470
34471diff --git a/drivers/clocksource/metag_generic.c b/drivers/clocksource/metag_generic.c
34472index ade7513..069445f 100644
34473--- a/drivers/clocksource/metag_generic.c
34474+++ b/drivers/clocksource/metag_generic.c
34475@@ -169,7 +169,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34476 return NOTIFY_OK;
34477 }
34478
34479-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34480+static struct notifier_block arch_timer_cpu_nb = {
34481 .notifier_call = arch_timer_cpu_notify,
34482 };
34483
34484diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34485index edc089e..bc7c0bc 100644
34486--- a/drivers/cpufreq/acpi-cpufreq.c
34487+++ b/drivers/cpufreq/acpi-cpufreq.c
34488@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34489 return sprintf(buf, "%u\n", boost_enabled);
34490 }
34491
34492-static struct global_attr global_boost = __ATTR(boost, 0644,
34493+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34494 show_global_boost,
34495 store_global_boost);
34496
34497@@ -705,8 +705,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34498 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34499 per_cpu(acfreq_data, cpu) = data;
34500
34501- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34502- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34503+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34504+ pax_open_kernel();
34505+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34506+ pax_close_kernel();
34507+ }
34508
34509 result = acpi_processor_register_performance(data->acpi_data, cpu);
34510 if (result)
34511@@ -832,7 +835,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34512 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34513 break;
34514 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34515- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34516+ pax_open_kernel();
34517+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34518+ pax_close_kernel();
34519 policy->cur = get_cur_freq_on_cpu(cpu);
34520 break;
34521 default:
34522@@ -843,8 +848,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34523 acpi_processor_notify_smm(THIS_MODULE);
34524
34525 /* Check for APERF/MPERF support in hardware */
34526- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34527- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34528+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34529+ pax_open_kernel();
34530+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34531+ pax_close_kernel();
34532+ }
34533
34534 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34535 for (i = 0; i < perf->state_count; i++)
34536diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34537index 2d53f47..eb3803e 100644
34538--- a/drivers/cpufreq/cpufreq.c
34539+++ b/drivers/cpufreq/cpufreq.c
34540@@ -1851,7 +1851,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34541 return NOTIFY_OK;
34542 }
34543
34544-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34545+static struct notifier_block cpufreq_cpu_notifier = {
34546 .notifier_call = cpufreq_cpu_callback,
34547 };
34548
34549@@ -1883,8 +1883,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34550
34551 pr_debug("trying to register driver %s\n", driver_data->name);
34552
34553- if (driver_data->setpolicy)
34554- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34555+ if (driver_data->setpolicy) {
34556+ pax_open_kernel();
34557+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34558+ pax_close_kernel();
34559+ }
34560
34561 write_lock_irqsave(&cpufreq_driver_lock, flags);
34562 if (cpufreq_driver) {
34563diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34564index dc9b72e..11c0302 100644
34565--- a/drivers/cpufreq/cpufreq_governor.c
34566+++ b/drivers/cpufreq/cpufreq_governor.c
34567@@ -238,7 +238,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
34568 struct dbs_data *dbs_data;
34569 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
34570 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
34571- struct od_ops *od_ops = NULL;
34572+ const struct od_ops *od_ops = NULL;
34573 struct od_dbs_tuners *od_tuners = NULL;
34574 struct cs_dbs_tuners *cs_tuners = NULL;
34575 struct cpu_dbs_common_info *cpu_cdbs;
34576@@ -301,7 +301,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
34577
34578 if ((cdata->governor == GOV_CONSERVATIVE) &&
34579 (!policy->governor->initialized)) {
34580- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34581+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34582
34583 cpufreq_register_notifier(cs_ops->notifier_block,
34584 CPUFREQ_TRANSITION_NOTIFIER);
34585@@ -318,7 +318,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
34586
34587 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
34588 (policy->governor->initialized == 1)) {
34589- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34590+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34591
34592 cpufreq_unregister_notifier(cs_ops->notifier_block,
34593 CPUFREQ_TRANSITION_NOTIFIER);
34594diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34595index e16a961..0e68927 100644
34596--- a/drivers/cpufreq/cpufreq_governor.h
34597+++ b/drivers/cpufreq/cpufreq_governor.h
34598@@ -204,7 +204,7 @@ struct common_dbs_data {
34599 void (*exit)(struct dbs_data *dbs_data);
34600
34601 /* Governor specific ops, see below */
34602- void *gov_ops;
34603+ const void *gov_ops;
34604 };
34605
34606 /* Governer Per policy data */
34607diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
34608index 93eb5cb..f8ab572 100644
34609--- a/drivers/cpufreq/cpufreq_ondemand.c
34610+++ b/drivers/cpufreq/cpufreq_ondemand.c
34611@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
34612 (struct cpufreq_policy *, unsigned int, unsigned int),
34613 unsigned int powersave_bias)
34614 {
34615- od_ops.powersave_bias_target = f;
34616+ pax_open_kernel();
34617+ *(void **)&od_ops.powersave_bias_target = f;
34618+ pax_close_kernel();
34619 od_set_powersave_bias(powersave_bias);
34620 }
34621 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
34622
34623 void od_unregister_powersave_bias_handler(void)
34624 {
34625- od_ops.powersave_bias_target = generic_powersave_bias_target;
34626+ pax_open_kernel();
34627+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
34628+ pax_close_kernel();
34629 od_set_powersave_bias(0);
34630 }
34631 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
34632diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34633index 591b6fb..2a01183 100644
34634--- a/drivers/cpufreq/cpufreq_stats.c
34635+++ b/drivers/cpufreq/cpufreq_stats.c
34636@@ -367,7 +367,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34637 }
34638
34639 /* priority=1 so this will get called before cpufreq_remove_dev */
34640-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34641+static struct notifier_block cpufreq_stat_cpu_notifier = {
34642 .notifier_call = cpufreq_stat_cpu_callback,
34643 .priority = 1,
34644 };
34645diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34646index 421ef37..e708530c 100644
34647--- a/drivers/cpufreq/p4-clockmod.c
34648+++ b/drivers/cpufreq/p4-clockmod.c
34649@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34650 case 0x0F: /* Core Duo */
34651 case 0x16: /* Celeron Core */
34652 case 0x1C: /* Atom */
34653- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34654+ pax_open_kernel();
34655+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34656+ pax_close_kernel();
34657 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34658 case 0x0D: /* Pentium M (Dothan) */
34659- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34660+ pax_open_kernel();
34661+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34662+ pax_close_kernel();
34663 /* fall through */
34664 case 0x09: /* Pentium M (Banias) */
34665 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34666@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34667
34668 /* on P-4s, the TSC runs with constant frequency independent whether
34669 * throttling is active or not. */
34670- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34671+ pax_open_kernel();
34672+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34673+ pax_close_kernel();
34674
34675 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34676 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34677diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
34678index c71ee14..7c2e183 100644
34679--- a/drivers/cpufreq/sparc-us3-cpufreq.c
34680+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
34681@@ -18,14 +18,12 @@
34682 #include <asm/head.h>
34683 #include <asm/timer.h>
34684
34685-static struct cpufreq_driver *cpufreq_us3_driver;
34686-
34687 struct us3_freq_percpu_info {
34688 struct cpufreq_frequency_table table[4];
34689 };
34690
34691 /* Indexed by cpu number. */
34692-static struct us3_freq_percpu_info *us3_freq_table;
34693+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
34694
34695 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
34696 * in the Safari config register.
34697@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
34698
34699 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
34700 {
34701- if (cpufreq_us3_driver)
34702- us3_set_cpu_divider_index(policy, 0);
34703+ us3_set_cpu_divider_index(policy->cpu, 0);
34704
34705 return 0;
34706 }
34707
34708+static int __init us3_freq_init(void);
34709+static void __exit us3_freq_exit(void);
34710+
34711+static struct cpufreq_driver cpufreq_us3_driver = {
34712+ .init = us3_freq_cpu_init,
34713+ .verify = us3_freq_verify,
34714+ .target = us3_freq_target,
34715+ .get = us3_freq_get,
34716+ .exit = us3_freq_cpu_exit,
34717+ .owner = THIS_MODULE,
34718+ .name = "UltraSPARC-III",
34719+
34720+};
34721+
34722 static int __init us3_freq_init(void)
34723 {
34724 unsigned long manuf, impl, ver;
34725@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
34726 (impl == CHEETAH_IMPL ||
34727 impl == CHEETAH_PLUS_IMPL ||
34728 impl == JAGUAR_IMPL ||
34729- impl == PANTHER_IMPL)) {
34730- struct cpufreq_driver *driver;
34731-
34732- ret = -ENOMEM;
34733- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
34734- if (!driver)
34735- goto err_out;
34736-
34737- us3_freq_table = kzalloc(
34738- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
34739- GFP_KERNEL);
34740- if (!us3_freq_table)
34741- goto err_out;
34742-
34743- driver->init = us3_freq_cpu_init;
34744- driver->verify = us3_freq_verify;
34745- driver->target = us3_freq_target;
34746- driver->get = us3_freq_get;
34747- driver->exit = us3_freq_cpu_exit;
34748- driver->owner = THIS_MODULE,
34749- strcpy(driver->name, "UltraSPARC-III");
34750-
34751- cpufreq_us3_driver = driver;
34752- ret = cpufreq_register_driver(driver);
34753- if (ret)
34754- goto err_out;
34755-
34756- return 0;
34757-
34758-err_out:
34759- if (driver) {
34760- kfree(driver);
34761- cpufreq_us3_driver = NULL;
34762- }
34763- kfree(us3_freq_table);
34764- us3_freq_table = NULL;
34765- return ret;
34766- }
34767+ impl == PANTHER_IMPL))
34768+ return cpufreq_register_driver(&cpufreq_us3_driver);
34769
34770 return -ENODEV;
34771 }
34772
34773 static void __exit us3_freq_exit(void)
34774 {
34775- if (cpufreq_us3_driver) {
34776- cpufreq_unregister_driver(cpufreq_us3_driver);
34777- kfree(cpufreq_us3_driver);
34778- cpufreq_us3_driver = NULL;
34779- kfree(us3_freq_table);
34780- us3_freq_table = NULL;
34781- }
34782+ cpufreq_unregister_driver(&cpufreq_us3_driver);
34783 }
34784
34785 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
34786diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34787index 618e6f4..e89d915 100644
34788--- a/drivers/cpufreq/speedstep-centrino.c
34789+++ b/drivers/cpufreq/speedstep-centrino.c
34790@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34791 !cpu_has(cpu, X86_FEATURE_EST))
34792 return -ENODEV;
34793
34794- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34795- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34796+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34797+ pax_open_kernel();
34798+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34799+ pax_close_kernel();
34800+ }
34801
34802 if (policy->cpu != 0)
34803 return -ENODEV;
34804diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34805index c3a93fe..e808f24 100644
34806--- a/drivers/cpuidle/cpuidle.c
34807+++ b/drivers/cpuidle/cpuidle.c
34808@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
34809
34810 static void poll_idle_init(struct cpuidle_driver *drv)
34811 {
34812- struct cpuidle_state *state = &drv->states[0];
34813+ cpuidle_state_no_const *state = &drv->states[0];
34814
34815 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34816 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34817diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34818index ea2f8e7..70ac501 100644
34819--- a/drivers/cpuidle/governor.c
34820+++ b/drivers/cpuidle/governor.c
34821@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34822 mutex_lock(&cpuidle_lock);
34823 if (__cpuidle_find_governor(gov->name) == NULL) {
34824 ret = 0;
34825- list_add_tail(&gov->governor_list, &cpuidle_governors);
34826+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34827 if (!cpuidle_curr_governor ||
34828 cpuidle_curr_governor->rating < gov->rating)
34829 cpuidle_switch_governor(gov);
34830@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34831 new_gov = cpuidle_replace_governor(gov->rating);
34832 cpuidle_switch_governor(new_gov);
34833 }
34834- list_del(&gov->governor_list);
34835+ pax_list_del((struct list_head *)&gov->governor_list);
34836 mutex_unlock(&cpuidle_lock);
34837 }
34838
34839diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34840index 428754a..8bdf9cc 100644
34841--- a/drivers/cpuidle/sysfs.c
34842+++ b/drivers/cpuidle/sysfs.c
34843@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34844 NULL
34845 };
34846
34847-static struct attribute_group cpuidle_attr_group = {
34848+static attribute_group_no_const cpuidle_attr_group = {
34849 .attrs = cpuidle_default_attrs,
34850 .name = "cpuidle",
34851 };
34852diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34853index 3b36797..db0b0c0 100644
34854--- a/drivers/devfreq/devfreq.c
34855+++ b/drivers/devfreq/devfreq.c
34856@@ -477,7 +477,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
34857 GFP_KERNEL);
34858 devfreq->last_stat_updated = jiffies;
34859
34860- dev_set_name(&devfreq->dev, dev_name(dev));
34861+ dev_set_name(&devfreq->dev, "%s", dev_name(dev));
34862 err = device_register(&devfreq->dev);
34863 if (err) {
34864 put_device(&devfreq->dev);
34865@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34866 goto err_out;
34867 }
34868
34869- list_add(&governor->node, &devfreq_governor_list);
34870+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34871
34872 list_for_each_entry(devfreq, &devfreq_list, node) {
34873 int ret = 0;
34874@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34875 }
34876 }
34877
34878- list_del(&governor->node);
34879+ pax_list_del((struct list_head *)&governor->node);
34880 err_out:
34881 mutex_unlock(&devfreq_list_lock);
34882
34883diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34884index b70709b..1d8d02a 100644
34885--- a/drivers/dma/sh/shdma.c
34886+++ b/drivers/dma/sh/shdma.c
34887@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34888 return ret;
34889 }
34890
34891-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34892+static struct notifier_block sh_dmae_nmi_notifier = {
34893 .notifier_call = sh_dmae_nmi_handler,
34894
34895 /* Run before NMI debug handler and KGDB */
34896diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34897index 67610a6..30f8a11 100644
34898--- a/drivers/edac/edac_mc_sysfs.c
34899+++ b/drivers/edac/edac_mc_sysfs.c
34900@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
34901 struct dev_ch_attribute {
34902 struct device_attribute attr;
34903 int channel;
34904-};
34905+} __do_const;
34906
34907 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34908 struct dev_ch_attribute dev_attr_legacy_##_name = \
34909@@ -1003,14 +1003,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
34910 }
34911
34912 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
34913+ pax_open_kernel();
34914 if (mci->get_sdram_scrub_rate) {
34915- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34916- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34917+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34918+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34919 }
34920 if (mci->set_sdram_scrub_rate) {
34921- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34922- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34923+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34924+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34925 }
34926+ pax_close_kernel();
34927 err = device_create_file(&mci->dev,
34928 &dev_attr_sdram_scrub_rate);
34929 if (err) {
34930diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34931index e8658e4..22746d6 100644
34932--- a/drivers/edac/edac_pci_sysfs.c
34933+++ b/drivers/edac/edac_pci_sysfs.c
34934@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34935 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34936 static int edac_pci_poll_msec = 1000; /* one second workq period */
34937
34938-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34939-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34940+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34941+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34942
34943 static struct kobject *edac_pci_top_main_kobj;
34944 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34945@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34946 void *value;
34947 ssize_t(*show) (void *, char *);
34948 ssize_t(*store) (void *, const char *, size_t);
34949-};
34950+} __do_const;
34951
34952 /* Set of show/store abstract level functions for PCI Parity object */
34953 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34954@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34955 edac_printk(KERN_CRIT, EDAC_PCI,
34956 "Signaled System Error on %s\n",
34957 pci_name(dev));
34958- atomic_inc(&pci_nonparity_count);
34959+ atomic_inc_unchecked(&pci_nonparity_count);
34960 }
34961
34962 if (status & (PCI_STATUS_PARITY)) {
34963@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34964 "Master Data Parity Error on %s\n",
34965 pci_name(dev));
34966
34967- atomic_inc(&pci_parity_count);
34968+ atomic_inc_unchecked(&pci_parity_count);
34969 }
34970
34971 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34972@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34973 "Detected Parity Error on %s\n",
34974 pci_name(dev));
34975
34976- atomic_inc(&pci_parity_count);
34977+ atomic_inc_unchecked(&pci_parity_count);
34978 }
34979 }
34980
34981@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34982 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34983 "Signaled System Error on %s\n",
34984 pci_name(dev));
34985- atomic_inc(&pci_nonparity_count);
34986+ atomic_inc_unchecked(&pci_nonparity_count);
34987 }
34988
34989 if (status & (PCI_STATUS_PARITY)) {
34990@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34991 "Master Data Parity Error on "
34992 "%s\n", pci_name(dev));
34993
34994- atomic_inc(&pci_parity_count);
34995+ atomic_inc_unchecked(&pci_parity_count);
34996 }
34997
34998 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34999@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
35000 "Detected Parity Error on %s\n",
35001 pci_name(dev));
35002
35003- atomic_inc(&pci_parity_count);
35004+ atomic_inc_unchecked(&pci_parity_count);
35005 }
35006 }
35007 }
35008@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
35009 if (!check_pci_errors)
35010 return;
35011
35012- before_count = atomic_read(&pci_parity_count);
35013+ before_count = atomic_read_unchecked(&pci_parity_count);
35014
35015 /* scan all PCI devices looking for a Parity Error on devices and
35016 * bridges.
35017@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
35018 /* Only if operator has selected panic on PCI Error */
35019 if (edac_pci_get_panic_on_pe()) {
35020 /* If the count is different 'after' from 'before' */
35021- if (before_count != atomic_read(&pci_parity_count))
35022+ if (before_count != atomic_read_unchecked(&pci_parity_count))
35023 panic("EDAC: PCI Parity Error");
35024 }
35025 }
35026diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
35027index 51b7e3a..aa8a3e8 100644
35028--- a/drivers/edac/mce_amd.h
35029+++ b/drivers/edac/mce_amd.h
35030@@ -77,7 +77,7 @@ struct amd_decoder_ops {
35031 bool (*mc0_mce)(u16, u8);
35032 bool (*mc1_mce)(u16, u8);
35033 bool (*mc2_mce)(u16, u8);
35034-};
35035+} __no_const;
35036
35037 void amd_report_gart_errors(bool);
35038 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
35039diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
35040index 57ea7f4..789e3c3 100644
35041--- a/drivers/firewire/core-card.c
35042+++ b/drivers/firewire/core-card.c
35043@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
35044
35045 void fw_core_remove_card(struct fw_card *card)
35046 {
35047- struct fw_card_driver dummy_driver = dummy_driver_template;
35048+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
35049
35050 card->driver->update_phy_reg(card, 4,
35051 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
35052diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
35053index 664a6ff..af13580 100644
35054--- a/drivers/firewire/core-device.c
35055+++ b/drivers/firewire/core-device.c
35056@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
35057 struct config_rom_attribute {
35058 struct device_attribute attr;
35059 u32 key;
35060-};
35061+} __do_const;
35062
35063 static ssize_t show_immediate(struct device *dev,
35064 struct device_attribute *dattr, char *buf)
35065diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
35066index 28a94c7..58da63a 100644
35067--- a/drivers/firewire/core-transaction.c
35068+++ b/drivers/firewire/core-transaction.c
35069@@ -38,6 +38,7 @@
35070 #include <linux/timer.h>
35071 #include <linux/types.h>
35072 #include <linux/workqueue.h>
35073+#include <linux/sched.h>
35074
35075 #include <asm/byteorder.h>
35076
35077diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
35078index 515a42c..5ecf3ba 100644
35079--- a/drivers/firewire/core.h
35080+++ b/drivers/firewire/core.h
35081@@ -111,6 +111,7 @@ struct fw_card_driver {
35082
35083 int (*stop_iso)(struct fw_iso_context *ctx);
35084 };
35085+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
35086
35087 void fw_card_initialize(struct fw_card *card,
35088 const struct fw_card_driver *driver, struct device *device);
35089diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
35090index 94a58a0..f5eba42 100644
35091--- a/drivers/firmware/dmi-id.c
35092+++ b/drivers/firmware/dmi-id.c
35093@@ -16,7 +16,7 @@
35094 struct dmi_device_attribute{
35095 struct device_attribute dev_attr;
35096 int field;
35097-};
35098+} __do_const;
35099 #define to_dmi_dev_attr(_dev_attr) \
35100 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
35101
35102diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
35103index b95159b..841ae55 100644
35104--- a/drivers/firmware/dmi_scan.c
35105+++ b/drivers/firmware/dmi_scan.c
35106@@ -497,11 +497,6 @@ void __init dmi_scan_machine(void)
35107 }
35108 }
35109 else {
35110- /*
35111- * no iounmap() for that ioremap(); it would be a no-op, but
35112- * it's so early in setup that sucker gets confused into doing
35113- * what it shouldn't if we actually call it.
35114- */
35115 p = dmi_ioremap(0xF0000, 0x10000);
35116 if (p == NULL)
35117 goto error;
35118@@ -786,7 +781,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
35119 if (buf == NULL)
35120 return -1;
35121
35122- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
35123+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
35124
35125 iounmap(buf);
35126 return 0;
35127diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
35128index 5145fa3..0d3babd 100644
35129--- a/drivers/firmware/efi/efi.c
35130+++ b/drivers/firmware/efi/efi.c
35131@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
35132 };
35133
35134 static struct efivars generic_efivars;
35135-static struct efivar_operations generic_ops;
35136+static efivar_operations_no_const generic_ops __read_only;
35137
35138 static int generic_ops_register(void)
35139 {
35140- generic_ops.get_variable = efi.get_variable;
35141- generic_ops.set_variable = efi.set_variable;
35142- generic_ops.get_next_variable = efi.get_next_variable;
35143- generic_ops.query_variable_store = efi_query_variable_store;
35144+ pax_open_kernel();
35145+ *(void **)&generic_ops.get_variable = efi.get_variable;
35146+ *(void **)&generic_ops.set_variable = efi.set_variable;
35147+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
35148+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
35149+ pax_close_kernel();
35150
35151 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
35152 }
35153diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
35154index 8bd1bb6..c48b0c6 100644
35155--- a/drivers/firmware/efi/efivars.c
35156+++ b/drivers/firmware/efi/efivars.c
35157@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
35158 static int
35159 create_efivars_bin_attributes(void)
35160 {
35161- struct bin_attribute *attr;
35162+ bin_attribute_no_const *attr;
35163 int error;
35164
35165 /* new_var */
35166diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
35167index 2a90ba6..07f3733 100644
35168--- a/drivers/firmware/google/memconsole.c
35169+++ b/drivers/firmware/google/memconsole.c
35170@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
35171 if (!found_memconsole())
35172 return -ENODEV;
35173
35174- memconsole_bin_attr.size = memconsole_length;
35175+ pax_open_kernel();
35176+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
35177+ pax_close_kernel();
35178
35179 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
35180
35181diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
35182index e16d932..f0206ef 100644
35183--- a/drivers/gpio/gpio-ich.c
35184+++ b/drivers/gpio/gpio-ich.c
35185@@ -69,7 +69,7 @@ struct ichx_desc {
35186 /* Some chipsets have quirks, let these use their own request/get */
35187 int (*request)(struct gpio_chip *chip, unsigned offset);
35188 int (*get)(struct gpio_chip *chip, unsigned offset);
35189-};
35190+} __do_const;
35191
35192 static struct {
35193 spinlock_t lock;
35194diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
35195index 9902732..64b62dd 100644
35196--- a/drivers/gpio/gpio-vr41xx.c
35197+++ b/drivers/gpio/gpio-vr41xx.c
35198@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
35199 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
35200 maskl, pendl, maskh, pendh);
35201
35202- atomic_inc(&irq_err_count);
35203+ atomic_inc_unchecked(&irq_err_count);
35204
35205 return -EINVAL;
35206 }
35207diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
35208index ed1334e..ee0dd42 100644
35209--- a/drivers/gpu/drm/drm_crtc_helper.c
35210+++ b/drivers/gpu/drm/drm_crtc_helper.c
35211@@ -321,7 +321,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
35212 struct drm_crtc *tmp;
35213 int crtc_mask = 1;
35214
35215- WARN(!crtc, "checking null crtc?\n");
35216+ BUG_ON(!crtc);
35217
35218 dev = crtc->dev;
35219
35220diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
35221index 9cc247f..36aa285 100644
35222--- a/drivers/gpu/drm/drm_drv.c
35223+++ b/drivers/gpu/drm/drm_drv.c
35224@@ -306,7 +306,7 @@ module_exit(drm_core_exit);
35225 /**
35226 * Copy and IOCTL return string to user space
35227 */
35228-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
35229+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
35230 {
35231 int len;
35232
35233@@ -376,7 +376,7 @@ long drm_ioctl(struct file *filp,
35234 struct drm_file *file_priv = filp->private_data;
35235 struct drm_device *dev;
35236 const struct drm_ioctl_desc *ioctl = NULL;
35237- drm_ioctl_t *func;
35238+ drm_ioctl_no_const_t func;
35239 unsigned int nr = DRM_IOCTL_NR(cmd);
35240 int retcode = -EINVAL;
35241 char stack_kdata[128];
35242@@ -389,7 +389,7 @@ long drm_ioctl(struct file *filp,
35243 return -ENODEV;
35244
35245 atomic_inc(&dev->ioctl_count);
35246- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
35247+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
35248 ++file_priv->ioctl_count;
35249
35250 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
35251diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
35252index 429e07d..e681a2c 100644
35253--- a/drivers/gpu/drm/drm_fops.c
35254+++ b/drivers/gpu/drm/drm_fops.c
35255@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
35256 }
35257
35258 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
35259- atomic_set(&dev->counts[i], 0);
35260+ atomic_set_unchecked(&dev->counts[i], 0);
35261
35262 dev->sigdata.lock = NULL;
35263
35264@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
35265 if (drm_device_is_unplugged(dev))
35266 return -ENODEV;
35267
35268- if (!dev->open_count++)
35269+ if (local_inc_return(&dev->open_count) == 1)
35270 need_setup = 1;
35271 mutex_lock(&dev->struct_mutex);
35272 old_imapping = inode->i_mapping;
35273@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
35274 retcode = drm_open_helper(inode, filp, dev);
35275 if (retcode)
35276 goto err_undo;
35277- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
35278+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
35279 if (need_setup) {
35280 retcode = drm_setup(dev);
35281 if (retcode)
35282@@ -166,7 +166,7 @@ err_undo:
35283 iput(container_of(dev->dev_mapping, struct inode, i_data));
35284 dev->dev_mapping = old_mapping;
35285 mutex_unlock(&dev->struct_mutex);
35286- dev->open_count--;
35287+ local_dec(&dev->open_count);
35288 return retcode;
35289 }
35290 EXPORT_SYMBOL(drm_open);
35291@@ -441,7 +441,7 @@ int drm_release(struct inode *inode, struct file *filp)
35292
35293 mutex_lock(&drm_global_mutex);
35294
35295- DRM_DEBUG("open_count = %d\n", dev->open_count);
35296+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
35297
35298 if (dev->driver->preclose)
35299 dev->driver->preclose(dev, file_priv);
35300@@ -450,10 +450,10 @@ int drm_release(struct inode *inode, struct file *filp)
35301 * Begin inline drm_release
35302 */
35303
35304- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
35305+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
35306 task_pid_nr(current),
35307 (long)old_encode_dev(file_priv->minor->device),
35308- dev->open_count);
35309+ local_read(&dev->open_count));
35310
35311 /* Release any auth tokens that might point to this file_priv,
35312 (do that under the drm_global_mutex) */
35313@@ -550,8 +550,8 @@ int drm_release(struct inode *inode, struct file *filp)
35314 * End inline drm_release
35315 */
35316
35317- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
35318- if (!--dev->open_count) {
35319+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
35320+ if (local_dec_and_test(&dev->open_count)) {
35321 if (atomic_read(&dev->ioctl_count)) {
35322 DRM_ERROR("Device busy: %d\n",
35323 atomic_read(&dev->ioctl_count));
35324diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
35325index f731116..629842c 100644
35326--- a/drivers/gpu/drm/drm_global.c
35327+++ b/drivers/gpu/drm/drm_global.c
35328@@ -36,7 +36,7 @@
35329 struct drm_global_item {
35330 struct mutex mutex;
35331 void *object;
35332- int refcount;
35333+ atomic_t refcount;
35334 };
35335
35336 static struct drm_global_item glob[DRM_GLOBAL_NUM];
35337@@ -49,7 +49,7 @@ void drm_global_init(void)
35338 struct drm_global_item *item = &glob[i];
35339 mutex_init(&item->mutex);
35340 item->object = NULL;
35341- item->refcount = 0;
35342+ atomic_set(&item->refcount, 0);
35343 }
35344 }
35345
35346@@ -59,7 +59,7 @@ void drm_global_release(void)
35347 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
35348 struct drm_global_item *item = &glob[i];
35349 BUG_ON(item->object != NULL);
35350- BUG_ON(item->refcount != 0);
35351+ BUG_ON(atomic_read(&item->refcount) != 0);
35352 }
35353 }
35354
35355@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35356 void *object;
35357
35358 mutex_lock(&item->mutex);
35359- if (item->refcount == 0) {
35360+ if (atomic_read(&item->refcount) == 0) {
35361 item->object = kzalloc(ref->size, GFP_KERNEL);
35362 if (unlikely(item->object == NULL)) {
35363 ret = -ENOMEM;
35364@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35365 goto out_err;
35366
35367 }
35368- ++item->refcount;
35369+ atomic_inc(&item->refcount);
35370 ref->object = item->object;
35371 object = item->object;
35372 mutex_unlock(&item->mutex);
35373@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
35374 struct drm_global_item *item = &glob[ref->global_type];
35375
35376 mutex_lock(&item->mutex);
35377- BUG_ON(item->refcount == 0);
35378+ BUG_ON(atomic_read(&item->refcount) == 0);
35379 BUG_ON(ref->object != item->object);
35380- if (--item->refcount == 0) {
35381+ if (atomic_dec_and_test(&item->refcount)) {
35382 ref->release(ref);
35383 item->object = NULL;
35384 }
35385diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
35386index d4b20ce..77a8d41 100644
35387--- a/drivers/gpu/drm/drm_info.c
35388+++ b/drivers/gpu/drm/drm_info.c
35389@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
35390 struct drm_local_map *map;
35391 struct drm_map_list *r_list;
35392
35393- /* Hardcoded from _DRM_FRAME_BUFFER,
35394- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
35395- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
35396- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
35397+ static const char * const types[] = {
35398+ [_DRM_FRAME_BUFFER] = "FB",
35399+ [_DRM_REGISTERS] = "REG",
35400+ [_DRM_SHM] = "SHM",
35401+ [_DRM_AGP] = "AGP",
35402+ [_DRM_SCATTER_GATHER] = "SG",
35403+ [_DRM_CONSISTENT] = "PCI",
35404+ [_DRM_GEM] = "GEM" };
35405 const char *type;
35406 int i;
35407
35408@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
35409 map = r_list->map;
35410 if (!map)
35411 continue;
35412- if (map->type < 0 || map->type > 5)
35413+ if (map->type >= ARRAY_SIZE(types))
35414 type = "??";
35415 else
35416 type = types[map->type];
35417@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
35418 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
35419 vma->vm_flags & VM_LOCKED ? 'l' : '-',
35420 vma->vm_flags & VM_IO ? 'i' : '-',
35421+#ifdef CONFIG_GRKERNSEC_HIDESYM
35422+ 0);
35423+#else
35424 vma->vm_pgoff);
35425+#endif
35426
35427 #if defined(__i386__)
35428 pgprot = pgprot_val(vma->vm_page_prot);
35429diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
35430index 2f4c434..dd12cd2 100644
35431--- a/drivers/gpu/drm/drm_ioc32.c
35432+++ b/drivers/gpu/drm/drm_ioc32.c
35433@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
35434 request = compat_alloc_user_space(nbytes);
35435 if (!access_ok(VERIFY_WRITE, request, nbytes))
35436 return -EFAULT;
35437- list = (struct drm_buf_desc *) (request + 1);
35438+ list = (struct drm_buf_desc __user *) (request + 1);
35439
35440 if (__put_user(count, &request->count)
35441 || __put_user(list, &request->list))
35442@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
35443 request = compat_alloc_user_space(nbytes);
35444 if (!access_ok(VERIFY_WRITE, request, nbytes))
35445 return -EFAULT;
35446- list = (struct drm_buf_pub *) (request + 1);
35447+ list = (struct drm_buf_pub __user *) (request + 1);
35448
35449 if (__put_user(count, &request->count)
35450 || __put_user(list, &request->list))
35451@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
35452 return 0;
35453 }
35454
35455-drm_ioctl_compat_t *drm_compat_ioctls[] = {
35456+drm_ioctl_compat_t drm_compat_ioctls[] = {
35457 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
35458 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
35459 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
35460@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
35461 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35462 {
35463 unsigned int nr = DRM_IOCTL_NR(cmd);
35464- drm_ioctl_compat_t *fn;
35465 int ret;
35466
35467 /* Assume that ioctls without an explicit compat routine will just
35468@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35469 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
35470 return drm_ioctl(filp, cmd, arg);
35471
35472- fn = drm_compat_ioctls[nr];
35473-
35474- if (fn != NULL)
35475- ret = (*fn) (filp, cmd, arg);
35476+ if (drm_compat_ioctls[nr] != NULL)
35477+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
35478 else
35479 ret = drm_ioctl(filp, cmd, arg);
35480
35481diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
35482index e77bd8b..1571b85 100644
35483--- a/drivers/gpu/drm/drm_ioctl.c
35484+++ b/drivers/gpu/drm/drm_ioctl.c
35485@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
35486 stats->data[i].value =
35487 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
35488 else
35489- stats->data[i].value = atomic_read(&dev->counts[i]);
35490+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
35491 stats->data[i].type = dev->types[i];
35492 }
35493
35494diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
35495index d752c96..fe08455 100644
35496--- a/drivers/gpu/drm/drm_lock.c
35497+++ b/drivers/gpu/drm/drm_lock.c
35498@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35499 if (drm_lock_take(&master->lock, lock->context)) {
35500 master->lock.file_priv = file_priv;
35501 master->lock.lock_time = jiffies;
35502- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
35503+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
35504 break; /* Got lock */
35505 }
35506
35507@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35508 return -EINVAL;
35509 }
35510
35511- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
35512+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
35513
35514 if (drm_lock_free(&master->lock, lock->context)) {
35515 /* FIXME: Should really bail out here. */
35516diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
35517index 16f3ec5..b28f9ca 100644
35518--- a/drivers/gpu/drm/drm_stub.c
35519+++ b/drivers/gpu/drm/drm_stub.c
35520@@ -501,7 +501,7 @@ void drm_unplug_dev(struct drm_device *dev)
35521
35522 drm_device_set_unplugged(dev);
35523
35524- if (dev->open_count == 0) {
35525+ if (local_read(&dev->open_count) == 0) {
35526 drm_put_dev(dev);
35527 }
35528 mutex_unlock(&drm_global_mutex);
35529diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
35530index 0229665..f61329c 100644
35531--- a/drivers/gpu/drm/drm_sysfs.c
35532+++ b/drivers/gpu/drm/drm_sysfs.c
35533@@ -499,7 +499,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
35534 int drm_sysfs_device_add(struct drm_minor *minor)
35535 {
35536 int err;
35537- char *minor_str;
35538+ const char *minor_str;
35539
35540 minor->kdev.parent = minor->dev->dev;
35541
35542diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
35543index 004ecdf..db1f6e0 100644
35544--- a/drivers/gpu/drm/i810/i810_dma.c
35545+++ b/drivers/gpu/drm/i810/i810_dma.c
35546@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
35547 dma->buflist[vertex->idx],
35548 vertex->discard, vertex->used);
35549
35550- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35551- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35552+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35553+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35554 sarea_priv->last_enqueue = dev_priv->counter - 1;
35555 sarea_priv->last_dispatch = (int)hw_status[5];
35556
35557@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35558 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35559 mc->last_render);
35560
35561- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35562- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35563+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35564+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35565 sarea_priv->last_enqueue = dev_priv->counter - 1;
35566 sarea_priv->last_dispatch = (int)hw_status[5];
35567
35568diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35569index 6e0acad..93c8289 100644
35570--- a/drivers/gpu/drm/i810/i810_drv.h
35571+++ b/drivers/gpu/drm/i810/i810_drv.h
35572@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
35573 int page_flipping;
35574
35575 wait_queue_head_t irq_queue;
35576- atomic_t irq_received;
35577- atomic_t irq_emitted;
35578+ atomic_unchecked_t irq_received;
35579+ atomic_unchecked_t irq_emitted;
35580
35581 int front_offset;
35582 } drm_i810_private_t;
35583diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35584index e913d32..4d9b351 100644
35585--- a/drivers/gpu/drm/i915/i915_debugfs.c
35586+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35587@@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35588 I915_READ(GTIMR));
35589 }
35590 seq_printf(m, "Interrupts received: %d\n",
35591- atomic_read(&dev_priv->irq_received));
35592+ atomic_read_unchecked(&dev_priv->irq_received));
35593 for_each_ring(ring, dev_priv, i) {
35594 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35595 seq_printf(m,
35596diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35597index 3b315ba..aac280f 100644
35598--- a/drivers/gpu/drm/i915/i915_dma.c
35599+++ b/drivers/gpu/drm/i915/i915_dma.c
35600@@ -1259,7 +1259,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35601 bool can_switch;
35602
35603 spin_lock(&dev->count_lock);
35604- can_switch = (dev->open_count == 0);
35605+ can_switch = (local_read(&dev->open_count) == 0);
35606 spin_unlock(&dev->count_lock);
35607 return can_switch;
35608 }
35609diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35610index 9669a0b..bb65176 100644
35611--- a/drivers/gpu/drm/i915/i915_drv.h
35612+++ b/drivers/gpu/drm/i915/i915_drv.h
35613@@ -915,7 +915,7 @@ typedef struct drm_i915_private {
35614 drm_dma_handle_t *status_page_dmah;
35615 struct resource mch_res;
35616
35617- atomic_t irq_received;
35618+ atomic_unchecked_t irq_received;
35619
35620 /* protects the irq masks */
35621 spinlock_t irq_lock;
35622@@ -1811,7 +1811,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35623 struct drm_i915_private *dev_priv, unsigned port);
35624 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35625 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35626-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35627+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35628 {
35629 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35630 }
35631diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35632index 117ce38..eefd237 100644
35633--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35634+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35635@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35636
35637 static int
35638 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35639- int count)
35640+ unsigned int count)
35641 {
35642- int i;
35643+ unsigned int i;
35644 int relocs_total = 0;
35645 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35646
35647diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35648index 3c59584..500f2e9 100644
35649--- a/drivers/gpu/drm/i915/i915_ioc32.c
35650+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35651@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35652 (unsigned long)request);
35653 }
35654
35655-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35656+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35657 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35658 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35659 [DRM_I915_GETPARAM] = compat_i915_getparam,
35660@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35661 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35662 {
35663 unsigned int nr = DRM_IOCTL_NR(cmd);
35664- drm_ioctl_compat_t *fn = NULL;
35665 int ret;
35666
35667 if (nr < DRM_COMMAND_BASE)
35668 return drm_compat_ioctl(filp, cmd, arg);
35669
35670- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35671- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35672-
35673- if (fn != NULL)
35674+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35675+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35676 ret = (*fn) (filp, cmd, arg);
35677- else
35678+ } else
35679 ret = drm_ioctl(filp, cmd, arg);
35680
35681 return ret;
35682diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35683index 0aa2ef0..77c03d0 100644
35684--- a/drivers/gpu/drm/i915/i915_irq.c
35685+++ b/drivers/gpu/drm/i915/i915_irq.c
35686@@ -679,7 +679,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35687 int pipe;
35688 u32 pipe_stats[I915_MAX_PIPES];
35689
35690- atomic_inc(&dev_priv->irq_received);
35691+ atomic_inc_unchecked(&dev_priv->irq_received);
35692
35693 while (true) {
35694 iir = I915_READ(VLV_IIR);
35695@@ -844,7 +844,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35696 irqreturn_t ret = IRQ_NONE;
35697 int i;
35698
35699- atomic_inc(&dev_priv->irq_received);
35700+ atomic_inc_unchecked(&dev_priv->irq_received);
35701
35702 /* disable master interrupt before clearing iir */
35703 de_ier = I915_READ(DEIER);
35704@@ -934,7 +934,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35705 int ret = IRQ_NONE;
35706 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
35707
35708- atomic_inc(&dev_priv->irq_received);
35709+ atomic_inc_unchecked(&dev_priv->irq_received);
35710
35711 /* disable master interrupt before clearing iir */
35712 de_ier = I915_READ(DEIER);
35713@@ -2098,7 +2098,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35714 {
35715 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35716
35717- atomic_set(&dev_priv->irq_received, 0);
35718+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35719
35720 I915_WRITE(HWSTAM, 0xeffe);
35721
35722@@ -2133,7 +2133,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35723 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35724 int pipe;
35725
35726- atomic_set(&dev_priv->irq_received, 0);
35727+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35728
35729 /* VLV magic */
35730 I915_WRITE(VLV_IMR, 0);
35731@@ -2420,7 +2420,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35732 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35733 int pipe;
35734
35735- atomic_set(&dev_priv->irq_received, 0);
35736+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35737
35738 for_each_pipe(pipe)
35739 I915_WRITE(PIPESTAT(pipe), 0);
35740@@ -2499,7 +2499,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35741 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35742 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35743
35744- atomic_inc(&dev_priv->irq_received);
35745+ atomic_inc_unchecked(&dev_priv->irq_received);
35746
35747 iir = I915_READ16(IIR);
35748 if (iir == 0)
35749@@ -2574,7 +2574,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35750 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35751 int pipe;
35752
35753- atomic_set(&dev_priv->irq_received, 0);
35754+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35755
35756 if (I915_HAS_HOTPLUG(dev)) {
35757 I915_WRITE(PORT_HOTPLUG_EN, 0);
35758@@ -2673,7 +2673,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35759 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35760 int pipe, ret = IRQ_NONE;
35761
35762- atomic_inc(&dev_priv->irq_received);
35763+ atomic_inc_unchecked(&dev_priv->irq_received);
35764
35765 iir = I915_READ(IIR);
35766 do {
35767@@ -2800,7 +2800,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35768 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35769 int pipe;
35770
35771- atomic_set(&dev_priv->irq_received, 0);
35772+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35773
35774 I915_WRITE(PORT_HOTPLUG_EN, 0);
35775 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35776@@ -2907,7 +2907,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35777 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35778 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35779
35780- atomic_inc(&dev_priv->irq_received);
35781+ atomic_inc_unchecked(&dev_priv->irq_received);
35782
35783 iir = I915_READ(IIR);
35784
35785diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35786index 56746dc..b5a214f 100644
35787--- a/drivers/gpu/drm/i915/intel_display.c
35788+++ b/drivers/gpu/drm/i915/intel_display.c
35789@@ -8919,13 +8919,13 @@ struct intel_quirk {
35790 int subsystem_vendor;
35791 int subsystem_device;
35792 void (*hook)(struct drm_device *dev);
35793-};
35794+} __do_const;
35795
35796 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35797 struct intel_dmi_quirk {
35798 void (*hook)(struct drm_device *dev);
35799 const struct dmi_system_id (*dmi_id_list)[];
35800-};
35801+} __do_const;
35802
35803 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35804 {
35805@@ -8933,18 +8933,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35806 return 1;
35807 }
35808
35809-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35810+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35811 {
35812- .dmi_id_list = &(const struct dmi_system_id[]) {
35813- {
35814- .callback = intel_dmi_reverse_brightness,
35815- .ident = "NCR Corporation",
35816- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35817- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35818- },
35819- },
35820- { } /* terminating entry */
35821+ .callback = intel_dmi_reverse_brightness,
35822+ .ident = "NCR Corporation",
35823+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35824+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35825 },
35826+ },
35827+ { } /* terminating entry */
35828+};
35829+
35830+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35831+ {
35832+ .dmi_id_list = &intel_dmi_quirks_table,
35833 .hook = quirk_invert_brightness,
35834 },
35835 };
35836diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35837index 54558a0..2d97005 100644
35838--- a/drivers/gpu/drm/mga/mga_drv.h
35839+++ b/drivers/gpu/drm/mga/mga_drv.h
35840@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35841 u32 clear_cmd;
35842 u32 maccess;
35843
35844- atomic_t vbl_received; /**< Number of vblanks received. */
35845+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35846 wait_queue_head_t fence_queue;
35847- atomic_t last_fence_retired;
35848+ atomic_unchecked_t last_fence_retired;
35849 u32 next_fence_to_post;
35850
35851 unsigned int fb_cpp;
35852diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35853index 709e90d..89a1c0d 100644
35854--- a/drivers/gpu/drm/mga/mga_ioc32.c
35855+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35856@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35857 return 0;
35858 }
35859
35860-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35861+drm_ioctl_compat_t mga_compat_ioctls[] = {
35862 [DRM_MGA_INIT] = compat_mga_init,
35863 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35864 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35865@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35866 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35867 {
35868 unsigned int nr = DRM_IOCTL_NR(cmd);
35869- drm_ioctl_compat_t *fn = NULL;
35870 int ret;
35871
35872 if (nr < DRM_COMMAND_BASE)
35873 return drm_compat_ioctl(filp, cmd, arg);
35874
35875- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35876- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35877-
35878- if (fn != NULL)
35879+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35880+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35881 ret = (*fn) (filp, cmd, arg);
35882- else
35883+ } else
35884 ret = drm_ioctl(filp, cmd, arg);
35885
35886 return ret;
35887diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35888index 598c281..60d590e 100644
35889--- a/drivers/gpu/drm/mga/mga_irq.c
35890+++ b/drivers/gpu/drm/mga/mga_irq.c
35891@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35892 if (crtc != 0)
35893 return 0;
35894
35895- return atomic_read(&dev_priv->vbl_received);
35896+ return atomic_read_unchecked(&dev_priv->vbl_received);
35897 }
35898
35899
35900@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35901 /* VBLANK interrupt */
35902 if (status & MGA_VLINEPEN) {
35903 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35904- atomic_inc(&dev_priv->vbl_received);
35905+ atomic_inc_unchecked(&dev_priv->vbl_received);
35906 drm_handle_vblank(dev, 0);
35907 handled = 1;
35908 }
35909@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35910 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35911 MGA_WRITE(MGA_PRIMEND, prim_end);
35912
35913- atomic_inc(&dev_priv->last_fence_retired);
35914+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35915 DRM_WAKEUP(&dev_priv->fence_queue);
35916 handled = 1;
35917 }
35918@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35919 * using fences.
35920 */
35921 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35922- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35923+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35924 - *sequence) <= (1 << 23)));
35925
35926 *sequence = cur_fence;
35927diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35928index 6aa2137..fe8dc55 100644
35929--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35930+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35931@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35932 struct bit_table {
35933 const char id;
35934 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35935-};
35936+} __no_const;
35937
35938 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35939
35940diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35941index f2b30f8..d0f9a95 100644
35942--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35943+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35944@@ -92,7 +92,7 @@ struct nouveau_drm {
35945 struct drm_global_reference mem_global_ref;
35946 struct ttm_bo_global_ref bo_global_ref;
35947 struct ttm_bo_device bdev;
35948- atomic_t validate_sequence;
35949+ atomic_unchecked_t validate_sequence;
35950 int (*move)(struct nouveau_channel *,
35951 struct ttm_buffer_object *,
35952 struct ttm_mem_reg *, struct ttm_mem_reg *);
35953diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35954index b4b4d0c..b7edc15 100644
35955--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35956+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35957@@ -322,7 +322,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35958 int ret, i;
35959 struct nouveau_bo *res_bo = NULL;
35960
35961- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35962+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35963 retry:
35964 if (++trycnt > 100000) {
35965 NV_ERROR(cli, "%s failed and gave up.\n", __func__);
35966@@ -359,7 +359,7 @@ retry:
35967 if (ret) {
35968 validate_fini(op, NULL);
35969 if (unlikely(ret == -EAGAIN)) {
35970- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35971+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35972 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
35973 sequence);
35974 if (!ret)
35975diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35976index 08214bc..9208577 100644
35977--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35978+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35979@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35980 unsigned long arg)
35981 {
35982 unsigned int nr = DRM_IOCTL_NR(cmd);
35983- drm_ioctl_compat_t *fn = NULL;
35984+ drm_ioctl_compat_t fn = NULL;
35985 int ret;
35986
35987 if (nr < DRM_COMMAND_BASE)
35988diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35989index 25d3495..d81aaf6 100644
35990--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35991+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35992@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35993 bool can_switch;
35994
35995 spin_lock(&dev->count_lock);
35996- can_switch = (dev->open_count == 0);
35997+ can_switch = (local_read(&dev->open_count) == 0);
35998 spin_unlock(&dev->count_lock);
35999 return can_switch;
36000 }
36001diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
36002index 489cb8c..0b8d0d3 100644
36003--- a/drivers/gpu/drm/qxl/qxl_ttm.c
36004+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
36005@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
36006 }
36007 }
36008
36009-static struct vm_operations_struct qxl_ttm_vm_ops;
36010+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
36011 static const struct vm_operations_struct *ttm_vm_ops;
36012
36013 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36014@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
36015 return r;
36016 if (unlikely(ttm_vm_ops == NULL)) {
36017 ttm_vm_ops = vma->vm_ops;
36018+ pax_open_kernel();
36019 qxl_ttm_vm_ops = *ttm_vm_ops;
36020 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
36021+ pax_close_kernel();
36022 }
36023 vma->vm_ops = &qxl_ttm_vm_ops;
36024 return 0;
36025@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
36026 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
36027 {
36028 #if defined(CONFIG_DEBUG_FS)
36029- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
36030- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
36031- unsigned i;
36032+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
36033+ {
36034+ .name = "qxl_mem_mm",
36035+ .show = &qxl_mm_dump_table,
36036+ },
36037+ {
36038+ .name = "qxl_surf_mm",
36039+ .show = &qxl_mm_dump_table,
36040+ }
36041+ };
36042
36043- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
36044- if (i == 0)
36045- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
36046- else
36047- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
36048- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
36049- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
36050- qxl_mem_types_list[i].driver_features = 0;
36051- if (i == 0)
36052- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
36053- else
36054- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
36055+ pax_open_kernel();
36056+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
36057+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
36058+ pax_close_kernel();
36059
36060- }
36061- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
36062+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
36063 #else
36064 return 0;
36065 #endif
36066diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
36067index d4660cf..70dbe65 100644
36068--- a/drivers/gpu/drm/r128/r128_cce.c
36069+++ b/drivers/gpu/drm/r128/r128_cce.c
36070@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
36071
36072 /* GH: Simple idle check.
36073 */
36074- atomic_set(&dev_priv->idle_count, 0);
36075+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36076
36077 /* We don't support anything other than bus-mastering ring mode,
36078 * but the ring can be in either AGP or PCI space for the ring
36079diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
36080index 930c71b..499aded 100644
36081--- a/drivers/gpu/drm/r128/r128_drv.h
36082+++ b/drivers/gpu/drm/r128/r128_drv.h
36083@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
36084 int is_pci;
36085 unsigned long cce_buffers_offset;
36086
36087- atomic_t idle_count;
36088+ atomic_unchecked_t idle_count;
36089
36090 int page_flipping;
36091 int current_page;
36092 u32 crtc_offset;
36093 u32 crtc_offset_cntl;
36094
36095- atomic_t vbl_received;
36096+ atomic_unchecked_t vbl_received;
36097
36098 u32 color_fmt;
36099 unsigned int front_offset;
36100diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
36101index a954c54..9cc595c 100644
36102--- a/drivers/gpu/drm/r128/r128_ioc32.c
36103+++ b/drivers/gpu/drm/r128/r128_ioc32.c
36104@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
36105 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
36106 }
36107
36108-drm_ioctl_compat_t *r128_compat_ioctls[] = {
36109+drm_ioctl_compat_t r128_compat_ioctls[] = {
36110 [DRM_R128_INIT] = compat_r128_init,
36111 [DRM_R128_DEPTH] = compat_r128_depth,
36112 [DRM_R128_STIPPLE] = compat_r128_stipple,
36113@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
36114 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36115 {
36116 unsigned int nr = DRM_IOCTL_NR(cmd);
36117- drm_ioctl_compat_t *fn = NULL;
36118 int ret;
36119
36120 if (nr < DRM_COMMAND_BASE)
36121 return drm_compat_ioctl(filp, cmd, arg);
36122
36123- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
36124- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36125-
36126- if (fn != NULL)
36127+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
36128+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36129 ret = (*fn) (filp, cmd, arg);
36130- else
36131+ } else
36132 ret = drm_ioctl(filp, cmd, arg);
36133
36134 return ret;
36135diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
36136index 2ea4f09..d391371 100644
36137--- a/drivers/gpu/drm/r128/r128_irq.c
36138+++ b/drivers/gpu/drm/r128/r128_irq.c
36139@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
36140 if (crtc != 0)
36141 return 0;
36142
36143- return atomic_read(&dev_priv->vbl_received);
36144+ return atomic_read_unchecked(&dev_priv->vbl_received);
36145 }
36146
36147 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36148@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36149 /* VBLANK interrupt */
36150 if (status & R128_CRTC_VBLANK_INT) {
36151 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
36152- atomic_inc(&dev_priv->vbl_received);
36153+ atomic_inc_unchecked(&dev_priv->vbl_received);
36154 drm_handle_vblank(dev, 0);
36155 return IRQ_HANDLED;
36156 }
36157diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
36158index 19bb7e6..de7e2a2 100644
36159--- a/drivers/gpu/drm/r128/r128_state.c
36160+++ b/drivers/gpu/drm/r128/r128_state.c
36161@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
36162
36163 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
36164 {
36165- if (atomic_read(&dev_priv->idle_count) == 0)
36166+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
36167 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
36168 else
36169- atomic_set(&dev_priv->idle_count, 0);
36170+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36171 }
36172
36173 #endif
36174diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
36175index 5a82b6b..9e69c73 100644
36176--- a/drivers/gpu/drm/radeon/mkregtable.c
36177+++ b/drivers/gpu/drm/radeon/mkregtable.c
36178@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
36179 regex_t mask_rex;
36180 regmatch_t match[4];
36181 char buf[1024];
36182- size_t end;
36183+ long end;
36184 int len;
36185 int done = 0;
36186 int r;
36187 unsigned o;
36188 struct offset *offset;
36189 char last_reg_s[10];
36190- int last_reg;
36191+ unsigned long last_reg;
36192
36193 if (regcomp
36194 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
36195diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
36196index b0dc0b6..a9bfe9c 100644
36197--- a/drivers/gpu/drm/radeon/radeon_device.c
36198+++ b/drivers/gpu/drm/radeon/radeon_device.c
36199@@ -1014,7 +1014,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
36200 bool can_switch;
36201
36202 spin_lock(&dev->count_lock);
36203- can_switch = (dev->open_count == 0);
36204+ can_switch = (local_read(&dev->open_count) == 0);
36205 spin_unlock(&dev->count_lock);
36206 return can_switch;
36207 }
36208diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
36209index b369d42..8dd04eb 100644
36210--- a/drivers/gpu/drm/radeon/radeon_drv.h
36211+++ b/drivers/gpu/drm/radeon/radeon_drv.h
36212@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
36213
36214 /* SW interrupt */
36215 wait_queue_head_t swi_queue;
36216- atomic_t swi_emitted;
36217+ atomic_unchecked_t swi_emitted;
36218 int vblank_crtc;
36219 uint32_t irq_enable_reg;
36220 uint32_t r500_disp_irq_reg;
36221diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
36222index c180df8..5fd8186 100644
36223--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
36224+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
36225@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36226 request = compat_alloc_user_space(sizeof(*request));
36227 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
36228 || __put_user(req32.param, &request->param)
36229- || __put_user((void __user *)(unsigned long)req32.value,
36230+ || __put_user((unsigned long)req32.value,
36231 &request->value))
36232 return -EFAULT;
36233
36234@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36235 #define compat_radeon_cp_setparam NULL
36236 #endif /* X86_64 || IA64 */
36237
36238-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36239+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
36240 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
36241 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
36242 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
36243@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36244 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36245 {
36246 unsigned int nr = DRM_IOCTL_NR(cmd);
36247- drm_ioctl_compat_t *fn = NULL;
36248 int ret;
36249
36250 if (nr < DRM_COMMAND_BASE)
36251 return drm_compat_ioctl(filp, cmd, arg);
36252
36253- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
36254- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36255-
36256- if (fn != NULL)
36257+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
36258+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36259 ret = (*fn) (filp, cmd, arg);
36260- else
36261+ } else
36262 ret = drm_ioctl(filp, cmd, arg);
36263
36264 return ret;
36265diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
36266index 8d68e97..9dcfed8 100644
36267--- a/drivers/gpu/drm/radeon/radeon_irq.c
36268+++ b/drivers/gpu/drm/radeon/radeon_irq.c
36269@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
36270 unsigned int ret;
36271 RING_LOCALS;
36272
36273- atomic_inc(&dev_priv->swi_emitted);
36274- ret = atomic_read(&dev_priv->swi_emitted);
36275+ atomic_inc_unchecked(&dev_priv->swi_emitted);
36276+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
36277
36278 BEGIN_RING(4);
36279 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
36280@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
36281 drm_radeon_private_t *dev_priv =
36282 (drm_radeon_private_t *) dev->dev_private;
36283
36284- atomic_set(&dev_priv->swi_emitted, 0);
36285+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
36286 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
36287
36288 dev->max_vblank_count = 0x001fffff;
36289diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
36290index 4d20910..6726b6d 100644
36291--- a/drivers/gpu/drm/radeon/radeon_state.c
36292+++ b/drivers/gpu/drm/radeon/radeon_state.c
36293@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
36294 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
36295 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
36296
36297- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36298+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36299 sarea_priv->nbox * sizeof(depth_boxes[0])))
36300 return -EFAULT;
36301
36302@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
36303 {
36304 drm_radeon_private_t *dev_priv = dev->dev_private;
36305 drm_radeon_getparam_t *param = data;
36306- int value;
36307+ int value = 0;
36308
36309 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
36310
36311diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
36312index 6c0ce89..57a2529 100644
36313--- a/drivers/gpu/drm/radeon/radeon_ttm.c
36314+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
36315@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
36316 man->size = size >> PAGE_SHIFT;
36317 }
36318
36319-static struct vm_operations_struct radeon_ttm_vm_ops;
36320+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
36321 static const struct vm_operations_struct *ttm_vm_ops = NULL;
36322
36323 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36324@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
36325 }
36326 if (unlikely(ttm_vm_ops == NULL)) {
36327 ttm_vm_ops = vma->vm_ops;
36328+ pax_open_kernel();
36329 radeon_ttm_vm_ops = *ttm_vm_ops;
36330 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
36331+ pax_close_kernel();
36332 }
36333 vma->vm_ops = &radeon_ttm_vm_ops;
36334 return 0;
36335@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
36336 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
36337 {
36338 #if defined(CONFIG_DEBUG_FS)
36339- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
36340- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
36341+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
36342+ {
36343+ .name = "radeon_vram_mm",
36344+ .show = &radeon_mm_dump_table,
36345+ },
36346+ {
36347+ .name = "radeon_gtt_mm",
36348+ .show = &radeon_mm_dump_table,
36349+ },
36350+ {
36351+ .name = "ttm_page_pool",
36352+ .show = &ttm_page_alloc_debugfs,
36353+ },
36354+ {
36355+ .name = "ttm_dma_page_pool",
36356+ .show = &ttm_dma_page_alloc_debugfs,
36357+ },
36358+ };
36359 unsigned i;
36360
36361- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
36362- if (i == 0)
36363- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
36364- else
36365- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
36366- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36367- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36368- radeon_mem_types_list[i].driver_features = 0;
36369- if (i == 0)
36370- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36371- else
36372- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36373-
36374- }
36375- /* Add ttm page pool to debugfs */
36376- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
36377- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36378- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36379- radeon_mem_types_list[i].driver_features = 0;
36380- radeon_mem_types_list[i++].data = NULL;
36381+ pax_open_kernel();
36382+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36383+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36384+ pax_close_kernel();
36385 #ifdef CONFIG_SWIOTLB
36386- if (swiotlb_nr_tbl()) {
36387- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
36388- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36389- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36390- radeon_mem_types_list[i].driver_features = 0;
36391- radeon_mem_types_list[i++].data = NULL;
36392- }
36393+ if (swiotlb_nr_tbl())
36394+ i++;
36395 #endif
36396 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
36397
36398diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
36399index 55880d5..9e95342 100644
36400--- a/drivers/gpu/drm/radeon/rs690.c
36401+++ b/drivers/gpu/drm/radeon/rs690.c
36402@@ -327,9 +327,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
36403 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
36404 rdev->pm.sideport_bandwidth.full)
36405 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
36406- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
36407+ read_delay_latency.full = dfixed_const(800 * 1000);
36408 read_delay_latency.full = dfixed_div(read_delay_latency,
36409 rdev->pm.igp_sideport_mclk);
36410+ a.full = dfixed_const(370);
36411+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
36412 } else {
36413 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
36414 rdev->pm.k8_bandwidth.full)
36415diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
36416index dbc2def..0a9f710 100644
36417--- a/drivers/gpu/drm/ttm/ttm_memory.c
36418+++ b/drivers/gpu/drm/ttm/ttm_memory.c
36419@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
36420 zone->glob = glob;
36421 glob->zone_kernel = zone;
36422 ret = kobject_init_and_add(
36423- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
36424+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
36425 if (unlikely(ret != 0)) {
36426 kobject_put(&zone->kobj);
36427 return ret;
36428@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
36429 zone->glob = glob;
36430 glob->zone_dma32 = zone;
36431 ret = kobject_init_and_add(
36432- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
36433+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
36434 if (unlikely(ret != 0)) {
36435 kobject_put(&zone->kobj);
36436 return ret;
36437diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36438index bd2a3b4..122d9ad 100644
36439--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
36440+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36441@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
36442 static int ttm_pool_mm_shrink(struct shrinker *shrink,
36443 struct shrink_control *sc)
36444 {
36445- static atomic_t start_pool = ATOMIC_INIT(0);
36446+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
36447 unsigned i;
36448- unsigned pool_offset = atomic_add_return(1, &start_pool);
36449+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
36450 struct ttm_page_pool *pool;
36451 int shrink_pages = sc->nr_to_scan;
36452
36453diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
36454index dc0c065..58a0782 100644
36455--- a/drivers/gpu/drm/udl/udl_fb.c
36456+++ b/drivers/gpu/drm/udl/udl_fb.c
36457@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
36458 fb_deferred_io_cleanup(info);
36459 kfree(info->fbdefio);
36460 info->fbdefio = NULL;
36461- info->fbops->fb_mmap = udl_fb_mmap;
36462 }
36463
36464 pr_warn("released /dev/fb%d user=%d count=%d\n",
36465diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
36466index 893a650..6190d3b 100644
36467--- a/drivers/gpu/drm/via/via_drv.h
36468+++ b/drivers/gpu/drm/via/via_drv.h
36469@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
36470 typedef uint32_t maskarray_t[5];
36471
36472 typedef struct drm_via_irq {
36473- atomic_t irq_received;
36474+ atomic_unchecked_t irq_received;
36475 uint32_t pending_mask;
36476 uint32_t enable_mask;
36477 wait_queue_head_t irq_queue;
36478@@ -75,7 +75,7 @@ typedef struct drm_via_private {
36479 struct timeval last_vblank;
36480 int last_vblank_valid;
36481 unsigned usec_per_vblank;
36482- atomic_t vbl_received;
36483+ atomic_unchecked_t vbl_received;
36484 drm_via_state_t hc_state;
36485 char pci_buf[VIA_PCI_BUF_SIZE];
36486 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
36487diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
36488index ac98964..5dbf512 100644
36489--- a/drivers/gpu/drm/via/via_irq.c
36490+++ b/drivers/gpu/drm/via/via_irq.c
36491@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
36492 if (crtc != 0)
36493 return 0;
36494
36495- return atomic_read(&dev_priv->vbl_received);
36496+ return atomic_read_unchecked(&dev_priv->vbl_received);
36497 }
36498
36499 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36500@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36501
36502 status = VIA_READ(VIA_REG_INTERRUPT);
36503 if (status & VIA_IRQ_VBLANK_PENDING) {
36504- atomic_inc(&dev_priv->vbl_received);
36505- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
36506+ atomic_inc_unchecked(&dev_priv->vbl_received);
36507+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
36508 do_gettimeofday(&cur_vblank);
36509 if (dev_priv->last_vblank_valid) {
36510 dev_priv->usec_per_vblank =
36511@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36512 dev_priv->last_vblank = cur_vblank;
36513 dev_priv->last_vblank_valid = 1;
36514 }
36515- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
36516+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
36517 DRM_DEBUG("US per vblank is: %u\n",
36518 dev_priv->usec_per_vblank);
36519 }
36520@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36521
36522 for (i = 0; i < dev_priv->num_irqs; ++i) {
36523 if (status & cur_irq->pending_mask) {
36524- atomic_inc(&cur_irq->irq_received);
36525+ atomic_inc_unchecked(&cur_irq->irq_received);
36526 DRM_WAKEUP(&cur_irq->irq_queue);
36527 handled = 1;
36528 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
36529@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
36530 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36531 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
36532 masks[irq][4]));
36533- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
36534+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
36535 } else {
36536 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36537 (((cur_irq_sequence =
36538- atomic_read(&cur_irq->irq_received)) -
36539+ atomic_read_unchecked(&cur_irq->irq_received)) -
36540 *sequence) <= (1 << 23)));
36541 }
36542 *sequence = cur_irq_sequence;
36543@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
36544 }
36545
36546 for (i = 0; i < dev_priv->num_irqs; ++i) {
36547- atomic_set(&cur_irq->irq_received, 0);
36548+ atomic_set_unchecked(&cur_irq->irq_received, 0);
36549 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
36550 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
36551 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
36552@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
36553 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
36554 case VIA_IRQ_RELATIVE:
36555 irqwait->request.sequence +=
36556- atomic_read(&cur_irq->irq_received);
36557+ atomic_read_unchecked(&cur_irq->irq_received);
36558 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
36559 case VIA_IRQ_ABSOLUTE:
36560 break;
36561diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36562index 13aeda7..4a952d1 100644
36563--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36564+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36565@@ -290,7 +290,7 @@ struct vmw_private {
36566 * Fencing and IRQs.
36567 */
36568
36569- atomic_t marker_seq;
36570+ atomic_unchecked_t marker_seq;
36571 wait_queue_head_t fence_queue;
36572 wait_queue_head_t fifo_queue;
36573 int fence_queue_waiters; /* Protected by hw_mutex */
36574diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36575index 3eb1486..0a47ee9 100644
36576--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36577+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36578@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
36579 (unsigned int) min,
36580 (unsigned int) fifo->capabilities);
36581
36582- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36583+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36584 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
36585 vmw_marker_queue_init(&fifo->marker_queue);
36586 return vmw_fifo_send_fence(dev_priv, &dummy);
36587@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
36588 if (reserveable)
36589 iowrite32(bytes, fifo_mem +
36590 SVGA_FIFO_RESERVED);
36591- return fifo_mem + (next_cmd >> 2);
36592+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36593 } else {
36594 need_bounce = true;
36595 }
36596@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36597
36598 fm = vmw_fifo_reserve(dev_priv, bytes);
36599 if (unlikely(fm == NULL)) {
36600- *seqno = atomic_read(&dev_priv->marker_seq);
36601+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36602 ret = -ENOMEM;
36603 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36604 false, 3*HZ);
36605@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36606 }
36607
36608 do {
36609- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36610+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36611 } while (*seqno == 0);
36612
36613 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36614diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36615index c509d40..3b640c3 100644
36616--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36617+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36618@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
36619 int ret;
36620
36621 num_clips = arg->num_clips;
36622- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36623+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36624
36625 if (unlikely(num_clips == 0))
36626 return 0;
36627@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
36628 int ret;
36629
36630 num_clips = arg->num_clips;
36631- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36632+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36633
36634 if (unlikely(num_clips == 0))
36635 return 0;
36636diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36637index 4640adb..e1384ed 100644
36638--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36639+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36640@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36641 * emitted. Then the fence is stale and signaled.
36642 */
36643
36644- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36645+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36646 > VMW_FENCE_WRAP);
36647
36648 return ret;
36649@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36650
36651 if (fifo_idle)
36652 down_read(&fifo_state->rwsem);
36653- signal_seq = atomic_read(&dev_priv->marker_seq);
36654+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36655 ret = 0;
36656
36657 for (;;) {
36658diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36659index 8a8725c2..afed796 100644
36660--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36661+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36662@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36663 while (!vmw_lag_lt(queue, us)) {
36664 spin_lock(&queue->lock);
36665 if (list_empty(&queue->head))
36666- seqno = atomic_read(&dev_priv->marker_seq);
36667+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36668 else {
36669 marker = list_first_entry(&queue->head,
36670 struct vmw_marker, head);
36671diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
36672index 8c04943..4370ed9 100644
36673--- a/drivers/gpu/host1x/drm/dc.c
36674+++ b/drivers/gpu/host1x/drm/dc.c
36675@@ -999,7 +999,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
36676 }
36677
36678 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
36679- dc->debugfs_files[i].data = dc;
36680+ *(void **)&dc->debugfs_files[i].data = dc;
36681
36682 err = drm_debugfs_create_files(dc->debugfs_files,
36683 ARRAY_SIZE(debugfs_files),
36684diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36685index 402f486..f862d7e 100644
36686--- a/drivers/hid/hid-core.c
36687+++ b/drivers/hid/hid-core.c
36688@@ -2275,7 +2275,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36689
36690 int hid_add_device(struct hid_device *hdev)
36691 {
36692- static atomic_t id = ATOMIC_INIT(0);
36693+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36694 int ret;
36695
36696 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36697@@ -2309,7 +2309,7 @@ int hid_add_device(struct hid_device *hdev)
36698 /* XXX hack, any other cleaner solution after the driver core
36699 * is converted to allow more than 20 bytes as the device name? */
36700 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36701- hdev->vendor, hdev->product, atomic_inc_return(&id));
36702+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36703
36704 hid_debug_register(hdev, dev_name(&hdev->dev));
36705 ret = device_add(&hdev->dev);
36706diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36707index 90124ff..3761764 100644
36708--- a/drivers/hid/hid-wiimote-debug.c
36709+++ b/drivers/hid/hid-wiimote-debug.c
36710@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36711 else if (size == 0)
36712 return -EIO;
36713
36714- if (copy_to_user(u, buf, size))
36715+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36716 return -EFAULT;
36717
36718 *off += size;
36719diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36720index 0b122f8..b1d8160 100644
36721--- a/drivers/hv/channel.c
36722+++ b/drivers/hv/channel.c
36723@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36724 int ret = 0;
36725 int t;
36726
36727- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36728- atomic_inc(&vmbus_connection.next_gpadl_handle);
36729+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36730+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36731
36732 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36733 if (ret)
36734diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36735index ae49237..380d4c9 100644
36736--- a/drivers/hv/hv.c
36737+++ b/drivers/hv/hv.c
36738@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36739 u64 output_address = (output) ? virt_to_phys(output) : 0;
36740 u32 output_address_hi = output_address >> 32;
36741 u32 output_address_lo = output_address & 0xFFFFFFFF;
36742- void *hypercall_page = hv_context.hypercall_page;
36743+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36744
36745 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36746 "=a"(hv_status_lo) : "d" (control_hi),
36747diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36748index 12f2f9e..679603c 100644
36749--- a/drivers/hv/hyperv_vmbus.h
36750+++ b/drivers/hv/hyperv_vmbus.h
36751@@ -591,7 +591,7 @@ enum vmbus_connect_state {
36752 struct vmbus_connection {
36753 enum vmbus_connect_state conn_state;
36754
36755- atomic_t next_gpadl_handle;
36756+ atomic_unchecked_t next_gpadl_handle;
36757
36758 /*
36759 * Represents channel interrupts. Each bit position represents a
36760diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36761index 4004e54..c2de226 100644
36762--- a/drivers/hv/vmbus_drv.c
36763+++ b/drivers/hv/vmbus_drv.c
36764@@ -668,10 +668,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36765 {
36766 int ret = 0;
36767
36768- static atomic_t device_num = ATOMIC_INIT(0);
36769+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36770
36771 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36772- atomic_inc_return(&device_num));
36773+ atomic_inc_return_unchecked(&device_num));
36774
36775 child_device_obj->device.bus = &hv_bus;
36776 child_device_obj->device.parent = &hv_acpi_dev->dev;
36777diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36778index 6351aba..dc4aaf4 100644
36779--- a/drivers/hwmon/acpi_power_meter.c
36780+++ b/drivers/hwmon/acpi_power_meter.c
36781@@ -117,7 +117,7 @@ struct sensor_template {
36782 struct device_attribute *devattr,
36783 const char *buf, size_t count);
36784 int index;
36785-};
36786+} __do_const;
36787
36788 /* Averaging interval */
36789 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36790@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36791 struct sensor_template *attrs)
36792 {
36793 struct device *dev = &resource->acpi_dev->dev;
36794- struct sensor_device_attribute *sensors =
36795+ sensor_device_attribute_no_const *sensors =
36796 &resource->sensors[resource->num_sensors];
36797 int res = 0;
36798
36799diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36800index 62c2e32..8f2859a 100644
36801--- a/drivers/hwmon/applesmc.c
36802+++ b/drivers/hwmon/applesmc.c
36803@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36804 {
36805 struct applesmc_node_group *grp;
36806 struct applesmc_dev_attr *node;
36807- struct attribute *attr;
36808+ attribute_no_const *attr;
36809 int ret, i;
36810
36811 for (grp = groups; grp->format; grp++) {
36812diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36813index b25c643..a13460d 100644
36814--- a/drivers/hwmon/asus_atk0110.c
36815+++ b/drivers/hwmon/asus_atk0110.c
36816@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36817 struct atk_sensor_data {
36818 struct list_head list;
36819 struct atk_data *data;
36820- struct device_attribute label_attr;
36821- struct device_attribute input_attr;
36822- struct device_attribute limit1_attr;
36823- struct device_attribute limit2_attr;
36824+ device_attribute_no_const label_attr;
36825+ device_attribute_no_const input_attr;
36826+ device_attribute_no_const limit1_attr;
36827+ device_attribute_no_const limit2_attr;
36828 char label_attr_name[ATTR_NAME_SIZE];
36829 char input_attr_name[ATTR_NAME_SIZE];
36830 char limit1_attr_name[ATTR_NAME_SIZE];
36831@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36832 static struct device_attribute atk_name_attr =
36833 __ATTR(name, 0444, atk_name_show, NULL);
36834
36835-static void atk_init_attribute(struct device_attribute *attr, char *name,
36836+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36837 sysfs_show_func show)
36838 {
36839 sysfs_attr_init(&attr->attr);
36840diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36841index 658ce3a..0d0c2f3 100644
36842--- a/drivers/hwmon/coretemp.c
36843+++ b/drivers/hwmon/coretemp.c
36844@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36845 return NOTIFY_OK;
36846 }
36847
36848-static struct notifier_block coretemp_cpu_notifier __refdata = {
36849+static struct notifier_block coretemp_cpu_notifier = {
36850 .notifier_call = coretemp_cpu_callback,
36851 };
36852
36853diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36854index 1429f6e..ee03d59 100644
36855--- a/drivers/hwmon/ibmaem.c
36856+++ b/drivers/hwmon/ibmaem.c
36857@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
36858 struct aem_rw_sensor_template *rw)
36859 {
36860 struct device *dev = &data->pdev->dev;
36861- struct sensor_device_attribute *sensors = data->sensors;
36862+ sensor_device_attribute_no_const *sensors = data->sensors;
36863 int err;
36864
36865 /* Set up read-only sensors */
36866diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
36867index 52b77af..aed1ddf 100644
36868--- a/drivers/hwmon/iio_hwmon.c
36869+++ b/drivers/hwmon/iio_hwmon.c
36870@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
36871 {
36872 struct device *dev = &pdev->dev;
36873 struct iio_hwmon_state *st;
36874- struct sensor_device_attribute *a;
36875+ sensor_device_attribute_no_const *a;
36876 int ret, i;
36877 int in_i = 1, temp_i = 1, curr_i = 1;
36878 enum iio_chan_type type;
36879diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36880index 9add6092..ee7ba3f 100644
36881--- a/drivers/hwmon/pmbus/pmbus_core.c
36882+++ b/drivers/hwmon/pmbus/pmbus_core.c
36883@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
36884 return 0;
36885 }
36886
36887-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36888+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
36889 const char *name,
36890 umode_t mode,
36891 ssize_t (*show)(struct device *dev,
36892@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36893 dev_attr->store = store;
36894 }
36895
36896-static void pmbus_attr_init(struct sensor_device_attribute *a,
36897+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
36898 const char *name,
36899 umode_t mode,
36900 ssize_t (*show)(struct device *dev,
36901@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
36902 u16 reg, u8 mask)
36903 {
36904 struct pmbus_boolean *boolean;
36905- struct sensor_device_attribute *a;
36906+ sensor_device_attribute_no_const *a;
36907
36908 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
36909 if (!boolean)
36910@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
36911 bool update, bool readonly)
36912 {
36913 struct pmbus_sensor *sensor;
36914- struct device_attribute *a;
36915+ device_attribute_no_const *a;
36916
36917 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
36918 if (!sensor)
36919@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
36920 const char *lstring, int index)
36921 {
36922 struct pmbus_label *label;
36923- struct device_attribute *a;
36924+ device_attribute_no_const *a;
36925
36926 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
36927 if (!label)
36928diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36929index 2507f90..1645765 100644
36930--- a/drivers/hwmon/sht15.c
36931+++ b/drivers/hwmon/sht15.c
36932@@ -169,7 +169,7 @@ struct sht15_data {
36933 int supply_uv;
36934 bool supply_uv_valid;
36935 struct work_struct update_supply_work;
36936- atomic_t interrupt_handled;
36937+ atomic_unchecked_t interrupt_handled;
36938 };
36939
36940 /**
36941@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
36942 ret = gpio_direction_input(data->pdata->gpio_data);
36943 if (ret)
36944 return ret;
36945- atomic_set(&data->interrupt_handled, 0);
36946+ atomic_set_unchecked(&data->interrupt_handled, 0);
36947
36948 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36949 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36950 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36951 /* Only relevant if the interrupt hasn't occurred. */
36952- if (!atomic_read(&data->interrupt_handled))
36953+ if (!atomic_read_unchecked(&data->interrupt_handled))
36954 schedule_work(&data->read_work);
36955 }
36956 ret = wait_event_timeout(data->wait_queue,
36957@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36958
36959 /* First disable the interrupt */
36960 disable_irq_nosync(irq);
36961- atomic_inc(&data->interrupt_handled);
36962+ atomic_inc_unchecked(&data->interrupt_handled);
36963 /* Then schedule a reading work struct */
36964 if (data->state != SHT15_READING_NOTHING)
36965 schedule_work(&data->read_work);
36966@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36967 * If not, then start the interrupt again - care here as could
36968 * have gone low in meantime so verify it hasn't!
36969 */
36970- atomic_set(&data->interrupt_handled, 0);
36971+ atomic_set_unchecked(&data->interrupt_handled, 0);
36972 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36973 /* If still not occurred or another handler was scheduled */
36974 if (gpio_get_value(data->pdata->gpio_data)
36975- || atomic_read(&data->interrupt_handled))
36976+ || atomic_read_unchecked(&data->interrupt_handled))
36977 return;
36978 }
36979
36980diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36981index 76f157b..9c0db1b 100644
36982--- a/drivers/hwmon/via-cputemp.c
36983+++ b/drivers/hwmon/via-cputemp.c
36984@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36985 return NOTIFY_OK;
36986 }
36987
36988-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36989+static struct notifier_block via_cputemp_cpu_notifier = {
36990 .notifier_call = via_cputemp_cpu_callback,
36991 };
36992
36993diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36994index 07f01ac..d79ad3d 100644
36995--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36996+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36997@@ -43,7 +43,7 @@
36998 extern struct i2c_adapter amd756_smbus;
36999
37000 static struct i2c_adapter *s4882_adapter;
37001-static struct i2c_algorithm *s4882_algo;
37002+static i2c_algorithm_no_const *s4882_algo;
37003
37004 /* Wrapper access functions for multiplexed SMBus */
37005 static DEFINE_MUTEX(amd756_lock);
37006diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
37007index 2ca268d..c6acbdf 100644
37008--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
37009+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
37010@@ -41,7 +41,7 @@
37011 extern struct i2c_adapter *nforce2_smbus;
37012
37013 static struct i2c_adapter *s4985_adapter;
37014-static struct i2c_algorithm *s4985_algo;
37015+static i2c_algorithm_no_const *s4985_algo;
37016
37017 /* Wrapper access functions for multiplexed SMBus */
37018 static DEFINE_MUTEX(nforce2_lock);
37019diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
37020index c3ccdea..5b3dc1a 100644
37021--- a/drivers/i2c/i2c-dev.c
37022+++ b/drivers/i2c/i2c-dev.c
37023@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
37024 break;
37025 }
37026
37027- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
37028+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
37029 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
37030 if (IS_ERR(rdwr_pa[i].buf)) {
37031 res = PTR_ERR(rdwr_pa[i].buf);
37032diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
37033index 2ff6204..218c16e 100644
37034--- a/drivers/ide/ide-cd.c
37035+++ b/drivers/ide/ide-cd.c
37036@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
37037 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
37038 if ((unsigned long)buf & alignment
37039 || blk_rq_bytes(rq) & q->dma_pad_mask
37040- || object_is_on_stack(buf))
37041+ || object_starts_on_stack(buf))
37042 drive->dma = 0;
37043 }
37044 }
37045diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
37046index e145931..08bfc59 100644
37047--- a/drivers/iio/industrialio-core.c
37048+++ b/drivers/iio/industrialio-core.c
37049@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
37050 }
37051
37052 static
37053-int __iio_device_attr_init(struct device_attribute *dev_attr,
37054+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
37055 const char *postfix,
37056 struct iio_chan_spec const *chan,
37057 ssize_t (*readfunc)(struct device *dev,
37058diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
37059index 784b97c..c9ceadf 100644
37060--- a/drivers/infiniband/core/cm.c
37061+++ b/drivers/infiniband/core/cm.c
37062@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
37063
37064 struct cm_counter_group {
37065 struct kobject obj;
37066- atomic_long_t counter[CM_ATTR_COUNT];
37067+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
37068 };
37069
37070 struct cm_counter_attribute {
37071@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
37072 struct ib_mad_send_buf *msg = NULL;
37073 int ret;
37074
37075- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37076+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37077 counter[CM_REQ_COUNTER]);
37078
37079 /* Quick state check to discard duplicate REQs. */
37080@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
37081 if (!cm_id_priv)
37082 return;
37083
37084- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37085+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37086 counter[CM_REP_COUNTER]);
37087 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
37088 if (ret)
37089@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
37090 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
37091 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
37092 spin_unlock_irq(&cm_id_priv->lock);
37093- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37094+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37095 counter[CM_RTU_COUNTER]);
37096 goto out;
37097 }
37098@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
37099 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
37100 dreq_msg->local_comm_id);
37101 if (!cm_id_priv) {
37102- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37103+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37104 counter[CM_DREQ_COUNTER]);
37105 cm_issue_drep(work->port, work->mad_recv_wc);
37106 return -EINVAL;
37107@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
37108 case IB_CM_MRA_REP_RCVD:
37109 break;
37110 case IB_CM_TIMEWAIT:
37111- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37112+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37113 counter[CM_DREQ_COUNTER]);
37114 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
37115 goto unlock;
37116@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
37117 cm_free_msg(msg);
37118 goto deref;
37119 case IB_CM_DREQ_RCVD:
37120- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37121+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37122 counter[CM_DREQ_COUNTER]);
37123 goto unlock;
37124 default:
37125@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
37126 ib_modify_mad(cm_id_priv->av.port->mad_agent,
37127 cm_id_priv->msg, timeout)) {
37128 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
37129- atomic_long_inc(&work->port->
37130+ atomic_long_inc_unchecked(&work->port->
37131 counter_group[CM_RECV_DUPLICATES].
37132 counter[CM_MRA_COUNTER]);
37133 goto out;
37134@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
37135 break;
37136 case IB_CM_MRA_REQ_RCVD:
37137 case IB_CM_MRA_REP_RCVD:
37138- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37139+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37140 counter[CM_MRA_COUNTER]);
37141 /* fall through */
37142 default:
37143@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
37144 case IB_CM_LAP_IDLE:
37145 break;
37146 case IB_CM_MRA_LAP_SENT:
37147- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37148+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37149 counter[CM_LAP_COUNTER]);
37150 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
37151 goto unlock;
37152@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
37153 cm_free_msg(msg);
37154 goto deref;
37155 case IB_CM_LAP_RCVD:
37156- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37157+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37158 counter[CM_LAP_COUNTER]);
37159 goto unlock;
37160 default:
37161@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
37162 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
37163 if (cur_cm_id_priv) {
37164 spin_unlock_irq(&cm.lock);
37165- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37166+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37167 counter[CM_SIDR_REQ_COUNTER]);
37168 goto out; /* Duplicate message. */
37169 }
37170@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
37171 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
37172 msg->retries = 1;
37173
37174- atomic_long_add(1 + msg->retries,
37175+ atomic_long_add_unchecked(1 + msg->retries,
37176 &port->counter_group[CM_XMIT].counter[attr_index]);
37177 if (msg->retries)
37178- atomic_long_add(msg->retries,
37179+ atomic_long_add_unchecked(msg->retries,
37180 &port->counter_group[CM_XMIT_RETRIES].
37181 counter[attr_index]);
37182
37183@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
37184 }
37185
37186 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
37187- atomic_long_inc(&port->counter_group[CM_RECV].
37188+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
37189 counter[attr_id - CM_ATTR_ID_OFFSET]);
37190
37191 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
37192@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
37193 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
37194
37195 return sprintf(buf, "%ld\n",
37196- atomic_long_read(&group->counter[cm_attr->index]));
37197+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
37198 }
37199
37200 static const struct sysfs_ops cm_counter_ops = {
37201diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
37202index 9f5ad7c..588cd84 100644
37203--- a/drivers/infiniband/core/fmr_pool.c
37204+++ b/drivers/infiniband/core/fmr_pool.c
37205@@ -98,8 +98,8 @@ struct ib_fmr_pool {
37206
37207 struct task_struct *thread;
37208
37209- atomic_t req_ser;
37210- atomic_t flush_ser;
37211+ atomic_unchecked_t req_ser;
37212+ atomic_unchecked_t flush_ser;
37213
37214 wait_queue_head_t force_wait;
37215 };
37216@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37217 struct ib_fmr_pool *pool = pool_ptr;
37218
37219 do {
37220- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
37221+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
37222 ib_fmr_batch_release(pool);
37223
37224- atomic_inc(&pool->flush_ser);
37225+ atomic_inc_unchecked(&pool->flush_ser);
37226 wake_up_interruptible(&pool->force_wait);
37227
37228 if (pool->flush_function)
37229@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37230 }
37231
37232 set_current_state(TASK_INTERRUPTIBLE);
37233- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
37234+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
37235 !kthread_should_stop())
37236 schedule();
37237 __set_current_state(TASK_RUNNING);
37238@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
37239 pool->dirty_watermark = params->dirty_watermark;
37240 pool->dirty_len = 0;
37241 spin_lock_init(&pool->pool_lock);
37242- atomic_set(&pool->req_ser, 0);
37243- atomic_set(&pool->flush_ser, 0);
37244+ atomic_set_unchecked(&pool->req_ser, 0);
37245+ atomic_set_unchecked(&pool->flush_ser, 0);
37246 init_waitqueue_head(&pool->force_wait);
37247
37248 pool->thread = kthread_run(ib_fmr_cleanup_thread,
37249@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
37250 }
37251 spin_unlock_irq(&pool->pool_lock);
37252
37253- serial = atomic_inc_return(&pool->req_ser);
37254+ serial = atomic_inc_return_unchecked(&pool->req_ser);
37255 wake_up_process(pool->thread);
37256
37257 if (wait_event_interruptible(pool->force_wait,
37258- atomic_read(&pool->flush_ser) - serial >= 0))
37259+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
37260 return -EINTR;
37261
37262 return 0;
37263@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
37264 } else {
37265 list_add_tail(&fmr->list, &pool->dirty_list);
37266 if (++pool->dirty_len >= pool->dirty_watermark) {
37267- atomic_inc(&pool->req_ser);
37268+ atomic_inc_unchecked(&pool->req_ser);
37269 wake_up_process(pool->thread);
37270 }
37271 }
37272diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
37273index 4cb8eb2..146bf60 100644
37274--- a/drivers/infiniband/hw/cxgb4/mem.c
37275+++ b/drivers/infiniband/hw/cxgb4/mem.c
37276@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37277 int err;
37278 struct fw_ri_tpte tpt;
37279 u32 stag_idx;
37280- static atomic_t key;
37281+ static atomic_unchecked_t key;
37282
37283 if (c4iw_fatal_error(rdev))
37284 return -EIO;
37285@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37286 if (rdev->stats.stag.cur > rdev->stats.stag.max)
37287 rdev->stats.stag.max = rdev->stats.stag.cur;
37288 mutex_unlock(&rdev->stats.lock);
37289- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
37290+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
37291 }
37292 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
37293 __func__, stag_state, type, pdid, stag_idx);
37294diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
37295index 79b3dbc..96e5fcc 100644
37296--- a/drivers/infiniband/hw/ipath/ipath_rc.c
37297+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
37298@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37299 struct ib_atomic_eth *ateth;
37300 struct ipath_ack_entry *e;
37301 u64 vaddr;
37302- atomic64_t *maddr;
37303+ atomic64_unchecked_t *maddr;
37304 u64 sdata;
37305 u32 rkey;
37306 u8 next;
37307@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37308 IB_ACCESS_REMOTE_ATOMIC)))
37309 goto nack_acc_unlck;
37310 /* Perform atomic OP and save result. */
37311- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37312+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37313 sdata = be64_to_cpu(ateth->swap_data);
37314 e = &qp->s_ack_queue[qp->r_head_ack_queue];
37315 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
37316- (u64) atomic64_add_return(sdata, maddr) - sdata :
37317+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37318 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37319 be64_to_cpu(ateth->compare_data),
37320 sdata);
37321diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
37322index 1f95bba..9530f87 100644
37323--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
37324+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
37325@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
37326 unsigned long flags;
37327 struct ib_wc wc;
37328 u64 sdata;
37329- atomic64_t *maddr;
37330+ atomic64_unchecked_t *maddr;
37331 enum ib_wc_status send_status;
37332
37333 /*
37334@@ -382,11 +382,11 @@ again:
37335 IB_ACCESS_REMOTE_ATOMIC)))
37336 goto acc_err;
37337 /* Perform atomic OP and save result. */
37338- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37339+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37340 sdata = wqe->wr.wr.atomic.compare_add;
37341 *(u64 *) sqp->s_sge.sge.vaddr =
37342 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
37343- (u64) atomic64_add_return(sdata, maddr) - sdata :
37344+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37345 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37346 sdata, wqe->wr.wr.atomic.swap);
37347 goto send_comp;
37348diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
37349index 9d3e5c1..d9afe4a 100644
37350--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
37351+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
37352@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
37353 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
37354 }
37355
37356-int mthca_QUERY_FW(struct mthca_dev *dev)
37357+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
37358 {
37359 struct mthca_mailbox *mailbox;
37360 u32 *outbox;
37361diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
37362index ed9a989..e0c5871 100644
37363--- a/drivers/infiniband/hw/mthca/mthca_mr.c
37364+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
37365@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
37366 return key;
37367 }
37368
37369-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37370+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37371 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
37372 {
37373 struct mthca_mailbox *mailbox;
37374diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
37375index 4291410..d2ab1fb 100644
37376--- a/drivers/infiniband/hw/nes/nes.c
37377+++ b/drivers/infiniband/hw/nes/nes.c
37378@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
37379 LIST_HEAD(nes_adapter_list);
37380 static LIST_HEAD(nes_dev_list);
37381
37382-atomic_t qps_destroyed;
37383+atomic_unchecked_t qps_destroyed;
37384
37385 static unsigned int ee_flsh_adapter;
37386 static unsigned int sysfs_nonidx_addr;
37387@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
37388 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
37389 struct nes_adapter *nesadapter = nesdev->nesadapter;
37390
37391- atomic_inc(&qps_destroyed);
37392+ atomic_inc_unchecked(&qps_destroyed);
37393
37394 /* Free the control structures */
37395
37396diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
37397index 33cc589..3bd6538 100644
37398--- a/drivers/infiniband/hw/nes/nes.h
37399+++ b/drivers/infiniband/hw/nes/nes.h
37400@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
37401 extern unsigned int wqm_quanta;
37402 extern struct list_head nes_adapter_list;
37403
37404-extern atomic_t cm_connects;
37405-extern atomic_t cm_accepts;
37406-extern atomic_t cm_disconnects;
37407-extern atomic_t cm_closes;
37408-extern atomic_t cm_connecteds;
37409-extern atomic_t cm_connect_reqs;
37410-extern atomic_t cm_rejects;
37411-extern atomic_t mod_qp_timouts;
37412-extern atomic_t qps_created;
37413-extern atomic_t qps_destroyed;
37414-extern atomic_t sw_qps_destroyed;
37415+extern atomic_unchecked_t cm_connects;
37416+extern atomic_unchecked_t cm_accepts;
37417+extern atomic_unchecked_t cm_disconnects;
37418+extern atomic_unchecked_t cm_closes;
37419+extern atomic_unchecked_t cm_connecteds;
37420+extern atomic_unchecked_t cm_connect_reqs;
37421+extern atomic_unchecked_t cm_rejects;
37422+extern atomic_unchecked_t mod_qp_timouts;
37423+extern atomic_unchecked_t qps_created;
37424+extern atomic_unchecked_t qps_destroyed;
37425+extern atomic_unchecked_t sw_qps_destroyed;
37426 extern u32 mh_detected;
37427 extern u32 mh_pauses_sent;
37428 extern u32 cm_packets_sent;
37429@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
37430 extern u32 cm_packets_received;
37431 extern u32 cm_packets_dropped;
37432 extern u32 cm_packets_retrans;
37433-extern atomic_t cm_listens_created;
37434-extern atomic_t cm_listens_destroyed;
37435+extern atomic_unchecked_t cm_listens_created;
37436+extern atomic_unchecked_t cm_listens_destroyed;
37437 extern u32 cm_backlog_drops;
37438-extern atomic_t cm_loopbacks;
37439-extern atomic_t cm_nodes_created;
37440-extern atomic_t cm_nodes_destroyed;
37441-extern atomic_t cm_accel_dropped_pkts;
37442-extern atomic_t cm_resets_recvd;
37443-extern atomic_t pau_qps_created;
37444-extern atomic_t pau_qps_destroyed;
37445+extern atomic_unchecked_t cm_loopbacks;
37446+extern atomic_unchecked_t cm_nodes_created;
37447+extern atomic_unchecked_t cm_nodes_destroyed;
37448+extern atomic_unchecked_t cm_accel_dropped_pkts;
37449+extern atomic_unchecked_t cm_resets_recvd;
37450+extern atomic_unchecked_t pau_qps_created;
37451+extern atomic_unchecked_t pau_qps_destroyed;
37452
37453 extern u32 int_mod_timer_init;
37454 extern u32 int_mod_cq_depth_256;
37455diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
37456index 24b9f1a..00fd004 100644
37457--- a/drivers/infiniband/hw/nes/nes_cm.c
37458+++ b/drivers/infiniband/hw/nes/nes_cm.c
37459@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
37460 u32 cm_packets_retrans;
37461 u32 cm_packets_created;
37462 u32 cm_packets_received;
37463-atomic_t cm_listens_created;
37464-atomic_t cm_listens_destroyed;
37465+atomic_unchecked_t cm_listens_created;
37466+atomic_unchecked_t cm_listens_destroyed;
37467 u32 cm_backlog_drops;
37468-atomic_t cm_loopbacks;
37469-atomic_t cm_nodes_created;
37470-atomic_t cm_nodes_destroyed;
37471-atomic_t cm_accel_dropped_pkts;
37472-atomic_t cm_resets_recvd;
37473+atomic_unchecked_t cm_loopbacks;
37474+atomic_unchecked_t cm_nodes_created;
37475+atomic_unchecked_t cm_nodes_destroyed;
37476+atomic_unchecked_t cm_accel_dropped_pkts;
37477+atomic_unchecked_t cm_resets_recvd;
37478
37479 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
37480 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
37481@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
37482
37483 static struct nes_cm_core *g_cm_core;
37484
37485-atomic_t cm_connects;
37486-atomic_t cm_accepts;
37487-atomic_t cm_disconnects;
37488-atomic_t cm_closes;
37489-atomic_t cm_connecteds;
37490-atomic_t cm_connect_reqs;
37491-atomic_t cm_rejects;
37492+atomic_unchecked_t cm_connects;
37493+atomic_unchecked_t cm_accepts;
37494+atomic_unchecked_t cm_disconnects;
37495+atomic_unchecked_t cm_closes;
37496+atomic_unchecked_t cm_connecteds;
37497+atomic_unchecked_t cm_connect_reqs;
37498+atomic_unchecked_t cm_rejects;
37499
37500 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
37501 {
37502@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
37503 kfree(listener);
37504 listener = NULL;
37505 ret = 0;
37506- atomic_inc(&cm_listens_destroyed);
37507+ atomic_inc_unchecked(&cm_listens_destroyed);
37508 } else {
37509 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
37510 }
37511@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
37512 cm_node->rem_mac);
37513
37514 add_hte_node(cm_core, cm_node);
37515- atomic_inc(&cm_nodes_created);
37516+ atomic_inc_unchecked(&cm_nodes_created);
37517
37518 return cm_node;
37519 }
37520@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
37521 }
37522
37523 atomic_dec(&cm_core->node_cnt);
37524- atomic_inc(&cm_nodes_destroyed);
37525+ atomic_inc_unchecked(&cm_nodes_destroyed);
37526 nesqp = cm_node->nesqp;
37527 if (nesqp) {
37528 nesqp->cm_node = NULL;
37529@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
37530
37531 static void drop_packet(struct sk_buff *skb)
37532 {
37533- atomic_inc(&cm_accel_dropped_pkts);
37534+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37535 dev_kfree_skb_any(skb);
37536 }
37537
37538@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
37539 {
37540
37541 int reset = 0; /* whether to send reset in case of err.. */
37542- atomic_inc(&cm_resets_recvd);
37543+ atomic_inc_unchecked(&cm_resets_recvd);
37544 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
37545 " refcnt=%d\n", cm_node, cm_node->state,
37546 atomic_read(&cm_node->ref_count));
37547@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
37548 rem_ref_cm_node(cm_node->cm_core, cm_node);
37549 return NULL;
37550 }
37551- atomic_inc(&cm_loopbacks);
37552+ atomic_inc_unchecked(&cm_loopbacks);
37553 loopbackremotenode->loopbackpartner = cm_node;
37554 loopbackremotenode->tcp_cntxt.rcv_wscale =
37555 NES_CM_DEFAULT_RCV_WND_SCALE;
37556@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
37557 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
37558 else {
37559 rem_ref_cm_node(cm_core, cm_node);
37560- atomic_inc(&cm_accel_dropped_pkts);
37561+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37562 dev_kfree_skb_any(skb);
37563 }
37564 break;
37565@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37566
37567 if ((cm_id) && (cm_id->event_handler)) {
37568 if (issue_disconn) {
37569- atomic_inc(&cm_disconnects);
37570+ atomic_inc_unchecked(&cm_disconnects);
37571 cm_event.event = IW_CM_EVENT_DISCONNECT;
37572 cm_event.status = disconn_status;
37573 cm_event.local_addr = cm_id->local_addr;
37574@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37575 }
37576
37577 if (issue_close) {
37578- atomic_inc(&cm_closes);
37579+ atomic_inc_unchecked(&cm_closes);
37580 nes_disconnect(nesqp, 1);
37581
37582 cm_id->provider_data = nesqp;
37583@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37584
37585 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
37586 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
37587- atomic_inc(&cm_accepts);
37588+ atomic_inc_unchecked(&cm_accepts);
37589
37590 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
37591 netdev_refcnt_read(nesvnic->netdev));
37592@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
37593 struct nes_cm_core *cm_core;
37594 u8 *start_buff;
37595
37596- atomic_inc(&cm_rejects);
37597+ atomic_inc_unchecked(&cm_rejects);
37598 cm_node = (struct nes_cm_node *)cm_id->provider_data;
37599 loopback = cm_node->loopbackpartner;
37600 cm_core = cm_node->cm_core;
37601@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37602 ntohl(cm_id->local_addr.sin_addr.s_addr),
37603 ntohs(cm_id->local_addr.sin_port));
37604
37605- atomic_inc(&cm_connects);
37606+ atomic_inc_unchecked(&cm_connects);
37607 nesqp->active_conn = 1;
37608
37609 /* cache the cm_id in the qp */
37610@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
37611 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
37612 return err;
37613 }
37614- atomic_inc(&cm_listens_created);
37615+ atomic_inc_unchecked(&cm_listens_created);
37616 }
37617
37618 cm_id->add_ref(cm_id);
37619@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
37620
37621 if (nesqp->destroyed)
37622 return;
37623- atomic_inc(&cm_connecteds);
37624+ atomic_inc_unchecked(&cm_connecteds);
37625 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
37626 " local port 0x%04X. jiffies = %lu.\n",
37627 nesqp->hwqp.qp_id,
37628@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
37629
37630 cm_id->add_ref(cm_id);
37631 ret = cm_id->event_handler(cm_id, &cm_event);
37632- atomic_inc(&cm_closes);
37633+ atomic_inc_unchecked(&cm_closes);
37634 cm_event.event = IW_CM_EVENT_CLOSE;
37635 cm_event.status = 0;
37636 cm_event.provider_data = cm_id->provider_data;
37637@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
37638 return;
37639 cm_id = cm_node->cm_id;
37640
37641- atomic_inc(&cm_connect_reqs);
37642+ atomic_inc_unchecked(&cm_connect_reqs);
37643 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37644 cm_node, cm_id, jiffies);
37645
37646@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
37647 return;
37648 cm_id = cm_node->cm_id;
37649
37650- atomic_inc(&cm_connect_reqs);
37651+ atomic_inc_unchecked(&cm_connect_reqs);
37652 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37653 cm_node, cm_id, jiffies);
37654
37655diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
37656index 4166452..fc952c3 100644
37657--- a/drivers/infiniband/hw/nes/nes_mgt.c
37658+++ b/drivers/infiniband/hw/nes/nes_mgt.c
37659@@ -40,8 +40,8 @@
37660 #include "nes.h"
37661 #include "nes_mgt.h"
37662
37663-atomic_t pau_qps_created;
37664-atomic_t pau_qps_destroyed;
37665+atomic_unchecked_t pau_qps_created;
37666+atomic_unchecked_t pau_qps_destroyed;
37667
37668 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
37669 {
37670@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
37671 {
37672 struct sk_buff *skb;
37673 unsigned long flags;
37674- atomic_inc(&pau_qps_destroyed);
37675+ atomic_inc_unchecked(&pau_qps_destroyed);
37676
37677 /* Free packets that have not yet been forwarded */
37678 /* Lock is acquired by skb_dequeue when removing the skb */
37679@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
37680 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
37681 skb_queue_head_init(&nesqp->pau_list);
37682 spin_lock_init(&nesqp->pau_lock);
37683- atomic_inc(&pau_qps_created);
37684+ atomic_inc_unchecked(&pau_qps_created);
37685 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37686 }
37687
37688diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37689index 49eb511..a774366 100644
37690--- a/drivers/infiniband/hw/nes/nes_nic.c
37691+++ b/drivers/infiniband/hw/nes/nes_nic.c
37692@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37693 target_stat_values[++index] = mh_detected;
37694 target_stat_values[++index] = mh_pauses_sent;
37695 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37696- target_stat_values[++index] = atomic_read(&cm_connects);
37697- target_stat_values[++index] = atomic_read(&cm_accepts);
37698- target_stat_values[++index] = atomic_read(&cm_disconnects);
37699- target_stat_values[++index] = atomic_read(&cm_connecteds);
37700- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37701- target_stat_values[++index] = atomic_read(&cm_rejects);
37702- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37703- target_stat_values[++index] = atomic_read(&qps_created);
37704- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37705- target_stat_values[++index] = atomic_read(&qps_destroyed);
37706- target_stat_values[++index] = atomic_read(&cm_closes);
37707+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37708+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37709+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37710+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37711+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37712+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37713+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37714+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37715+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37716+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37717+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37718 target_stat_values[++index] = cm_packets_sent;
37719 target_stat_values[++index] = cm_packets_bounced;
37720 target_stat_values[++index] = cm_packets_created;
37721 target_stat_values[++index] = cm_packets_received;
37722 target_stat_values[++index] = cm_packets_dropped;
37723 target_stat_values[++index] = cm_packets_retrans;
37724- target_stat_values[++index] = atomic_read(&cm_listens_created);
37725- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37726+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37727+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37728 target_stat_values[++index] = cm_backlog_drops;
37729- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37730- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37731- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37732- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37733- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37734+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37735+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37736+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37737+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37738+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37739 target_stat_values[++index] = nesadapter->free_4kpbl;
37740 target_stat_values[++index] = nesadapter->free_256pbl;
37741 target_stat_values[++index] = int_mod_timer_init;
37742 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37743 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37744 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37745- target_stat_values[++index] = atomic_read(&pau_qps_created);
37746- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37747+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37748+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37749 }
37750
37751 /**
37752diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37753index 8f67fe2..8960859 100644
37754--- a/drivers/infiniband/hw/nes/nes_verbs.c
37755+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37756@@ -46,9 +46,9 @@
37757
37758 #include <rdma/ib_umem.h>
37759
37760-atomic_t mod_qp_timouts;
37761-atomic_t qps_created;
37762-atomic_t sw_qps_destroyed;
37763+atomic_unchecked_t mod_qp_timouts;
37764+atomic_unchecked_t qps_created;
37765+atomic_unchecked_t sw_qps_destroyed;
37766
37767 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37768
37769@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37770 if (init_attr->create_flags)
37771 return ERR_PTR(-EINVAL);
37772
37773- atomic_inc(&qps_created);
37774+ atomic_inc_unchecked(&qps_created);
37775 switch (init_attr->qp_type) {
37776 case IB_QPT_RC:
37777 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37778@@ -1465,7 +1465,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37779 struct iw_cm_event cm_event;
37780 int ret = 0;
37781
37782- atomic_inc(&sw_qps_destroyed);
37783+ atomic_inc_unchecked(&sw_qps_destroyed);
37784 nesqp->destroyed = 1;
37785
37786 /* Blow away the connection if it exists. */
37787diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37788index 4d11575..3e890e5 100644
37789--- a/drivers/infiniband/hw/qib/qib.h
37790+++ b/drivers/infiniband/hw/qib/qib.h
37791@@ -51,6 +51,7 @@
37792 #include <linux/completion.h>
37793 #include <linux/kref.h>
37794 #include <linux/sched.h>
37795+#include <linux/slab.h>
37796
37797 #include "qib_common.h"
37798 #include "qib_verbs.h"
37799diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37800index da739d9..da1c7f4 100644
37801--- a/drivers/input/gameport/gameport.c
37802+++ b/drivers/input/gameport/gameport.c
37803@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37804 */
37805 static void gameport_init_port(struct gameport *gameport)
37806 {
37807- static atomic_t gameport_no = ATOMIC_INIT(0);
37808+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37809
37810 __module_get(THIS_MODULE);
37811
37812 mutex_init(&gameport->drv_mutex);
37813 device_initialize(&gameport->dev);
37814 dev_set_name(&gameport->dev, "gameport%lu",
37815- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37816+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37817 gameport->dev.bus = &gameport_bus;
37818 gameport->dev.release = gameport_release_port;
37819 if (gameport->parent)
37820diff --git a/drivers/input/input.c b/drivers/input/input.c
37821index c044699..174d71a 100644
37822--- a/drivers/input/input.c
37823+++ b/drivers/input/input.c
37824@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37825 */
37826 int input_register_device(struct input_dev *dev)
37827 {
37828- static atomic_t input_no = ATOMIC_INIT(0);
37829+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37830 struct input_devres *devres = NULL;
37831 struct input_handler *handler;
37832 unsigned int packet_size;
37833@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37834 dev->setkeycode = input_default_setkeycode;
37835
37836 dev_set_name(&dev->dev, "input%ld",
37837- (unsigned long) atomic_inc_return(&input_no) - 1);
37838+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37839
37840 error = device_add(&dev->dev);
37841 if (error)
37842diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37843index 04c69af..5f92d00 100644
37844--- a/drivers/input/joystick/sidewinder.c
37845+++ b/drivers/input/joystick/sidewinder.c
37846@@ -30,6 +30,7 @@
37847 #include <linux/kernel.h>
37848 #include <linux/module.h>
37849 #include <linux/slab.h>
37850+#include <linux/sched.h>
37851 #include <linux/init.h>
37852 #include <linux/input.h>
37853 #include <linux/gameport.h>
37854diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37855index fa061d4..4a6957c 100644
37856--- a/drivers/input/joystick/xpad.c
37857+++ b/drivers/input/joystick/xpad.c
37858@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37859
37860 static int xpad_led_probe(struct usb_xpad *xpad)
37861 {
37862- static atomic_t led_seq = ATOMIC_INIT(0);
37863+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37864 long led_no;
37865 struct xpad_led *led;
37866 struct led_classdev *led_cdev;
37867@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37868 if (!led)
37869 return -ENOMEM;
37870
37871- led_no = (long)atomic_inc_return(&led_seq) - 1;
37872+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37873
37874 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37875 led->xpad = xpad;
37876diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37877index 2f0b39d..7370f13 100644
37878--- a/drivers/input/mouse/psmouse.h
37879+++ b/drivers/input/mouse/psmouse.h
37880@@ -116,7 +116,7 @@ struct psmouse_attribute {
37881 ssize_t (*set)(struct psmouse *psmouse, void *data,
37882 const char *buf, size_t count);
37883 bool protect;
37884-};
37885+} __do_const;
37886 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37887
37888 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37889diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37890index 4c842c3..590b0bf 100644
37891--- a/drivers/input/mousedev.c
37892+++ b/drivers/input/mousedev.c
37893@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37894
37895 spin_unlock_irq(&client->packet_lock);
37896
37897- if (copy_to_user(buffer, data, count))
37898+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37899 return -EFAULT;
37900
37901 return count;
37902diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37903index 25fc597..558bf3b3 100644
37904--- a/drivers/input/serio/serio.c
37905+++ b/drivers/input/serio/serio.c
37906@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37907 */
37908 static void serio_init_port(struct serio *serio)
37909 {
37910- static atomic_t serio_no = ATOMIC_INIT(0);
37911+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37912
37913 __module_get(THIS_MODULE);
37914
37915@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37916 mutex_init(&serio->drv_mutex);
37917 device_initialize(&serio->dev);
37918 dev_set_name(&serio->dev, "serio%ld",
37919- (long)atomic_inc_return(&serio_no) - 1);
37920+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37921 serio->dev.bus = &serio_bus;
37922 serio->dev.release = serio_release_port;
37923 serio->dev.groups = serio_device_attr_groups;
37924diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37925index d8f98b1..f62a640 100644
37926--- a/drivers/iommu/iommu.c
37927+++ b/drivers/iommu/iommu.c
37928@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
37929 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37930 {
37931 bus_register_notifier(bus, &iommu_bus_nb);
37932- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37933+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37934 }
37935
37936 /**
37937diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
37938index dcfea4e..f4226b2 100644
37939--- a/drivers/iommu/irq_remapping.c
37940+++ b/drivers/iommu/irq_remapping.c
37941@@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
37942 void panic_if_irq_remap(const char *msg)
37943 {
37944 if (irq_remapping_enabled)
37945- panic(msg);
37946+ panic("%s", msg);
37947 }
37948
37949 static void ir_ack_apic_edge(struct irq_data *data)
37950@@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
37951
37952 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
37953 {
37954- chip->irq_print_chip = ir_print_prefix;
37955- chip->irq_ack = ir_ack_apic_edge;
37956- chip->irq_eoi = ir_ack_apic_level;
37957- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37958+ pax_open_kernel();
37959+ *(void **)&chip->irq_print_chip = ir_print_prefix;
37960+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
37961+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
37962+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37963+ pax_close_kernel();
37964 }
37965
37966 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
37967diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
37968index 19ceaa6..3625818 100644
37969--- a/drivers/irqchip/irq-gic.c
37970+++ b/drivers/irqchip/irq-gic.c
37971@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
37972 * Supported arch specific GIC irq extension.
37973 * Default make them NULL.
37974 */
37975-struct irq_chip gic_arch_extn = {
37976+irq_chip_no_const gic_arch_extn = {
37977 .irq_eoi = NULL,
37978 .irq_mask = NULL,
37979 .irq_unmask = NULL,
37980@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
37981 chained_irq_exit(chip, desc);
37982 }
37983
37984-static struct irq_chip gic_chip = {
37985+static irq_chip_no_const gic_chip __read_only = {
37986 .name = "GIC",
37987 .irq_mask = gic_mask_irq,
37988 .irq_unmask = gic_unmask_irq,
37989diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37990index ac6f72b..81150f2 100644
37991--- a/drivers/isdn/capi/capi.c
37992+++ b/drivers/isdn/capi/capi.c
37993@@ -81,8 +81,8 @@ struct capiminor {
37994
37995 struct capi20_appl *ap;
37996 u32 ncci;
37997- atomic_t datahandle;
37998- atomic_t msgid;
37999+ atomic_unchecked_t datahandle;
38000+ atomic_unchecked_t msgid;
38001
38002 struct tty_port port;
38003 int ttyinstop;
38004@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
38005 capimsg_setu16(s, 2, mp->ap->applid);
38006 capimsg_setu8 (s, 4, CAPI_DATA_B3);
38007 capimsg_setu8 (s, 5, CAPI_RESP);
38008- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
38009+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
38010 capimsg_setu32(s, 8, mp->ncci);
38011 capimsg_setu16(s, 12, datahandle);
38012 }
38013@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
38014 mp->outbytes -= len;
38015 spin_unlock_bh(&mp->outlock);
38016
38017- datahandle = atomic_inc_return(&mp->datahandle);
38018+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
38019 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
38020 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
38021 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
38022 capimsg_setu16(skb->data, 2, mp->ap->applid);
38023 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
38024 capimsg_setu8 (skb->data, 5, CAPI_REQ);
38025- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
38026+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
38027 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
38028 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
38029 capimsg_setu16(skb->data, 16, len); /* Data length */
38030diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
38031index 600c79b..3752bab 100644
38032--- a/drivers/isdn/gigaset/interface.c
38033+++ b/drivers/isdn/gigaset/interface.c
38034@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
38035 }
38036 tty->driver_data = cs;
38037
38038- ++cs->port.count;
38039+ atomic_inc(&cs->port.count);
38040
38041- if (cs->port.count == 1) {
38042+ if (atomic_read(&cs->port.count) == 1) {
38043 tty_port_tty_set(&cs->port, tty);
38044 cs->port.low_latency = 1;
38045 }
38046@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
38047
38048 if (!cs->connected)
38049 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
38050- else if (!cs->port.count)
38051+ else if (!atomic_read(&cs->port.count))
38052 dev_warn(cs->dev, "%s: device not opened\n", __func__);
38053- else if (!--cs->port.count)
38054+ else if (!atomic_dec_return(&cs->port.count))
38055 tty_port_tty_set(&cs->port, NULL);
38056
38057 mutex_unlock(&cs->mutex);
38058diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
38059index 4d9b195..455075c 100644
38060--- a/drivers/isdn/hardware/avm/b1.c
38061+++ b/drivers/isdn/hardware/avm/b1.c
38062@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
38063 }
38064 if (left) {
38065 if (t4file->user) {
38066- if (copy_from_user(buf, dp, left))
38067+ if (left > sizeof buf || copy_from_user(buf, dp, left))
38068 return -EFAULT;
38069 } else {
38070 memcpy(buf, dp, left);
38071@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
38072 }
38073 if (left) {
38074 if (config->user) {
38075- if (copy_from_user(buf, dp, left))
38076+ if (left > sizeof buf || copy_from_user(buf, dp, left))
38077 return -EFAULT;
38078 } else {
38079 memcpy(buf, dp, left);
38080diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
38081index 3c5f249..5fac4d0 100644
38082--- a/drivers/isdn/i4l/isdn_tty.c
38083+++ b/drivers/isdn/i4l/isdn_tty.c
38084@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
38085
38086 #ifdef ISDN_DEBUG_MODEM_OPEN
38087 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
38088- port->count);
38089+ atomic_read(&port->count));
38090 #endif
38091- port->count++;
38092+ atomic_inc(&port->count);
38093 port->tty = tty;
38094 /*
38095 * Start up serial port
38096@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
38097 #endif
38098 return;
38099 }
38100- if ((tty->count == 1) && (port->count != 1)) {
38101+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
38102 /*
38103 * Uh, oh. tty->count is 1, which means that the tty
38104 * structure will be freed. Info->count should always
38105@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
38106 * serial port won't be shutdown.
38107 */
38108 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
38109- "info->count is %d\n", port->count);
38110- port->count = 1;
38111+ "info->count is %d\n", atomic_read(&port->count));
38112+ atomic_set(&port->count, 1);
38113 }
38114- if (--port->count < 0) {
38115+ if (atomic_dec_return(&port->count) < 0) {
38116 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
38117- info->line, port->count);
38118- port->count = 0;
38119+ info->line, atomic_read(&port->count));
38120+ atomic_set(&port->count, 0);
38121 }
38122- if (port->count) {
38123+ if (atomic_read(&port->count)) {
38124 #ifdef ISDN_DEBUG_MODEM_OPEN
38125 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
38126 #endif
38127@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
38128 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
38129 return;
38130 isdn_tty_shutdown(info);
38131- port->count = 0;
38132+ atomic_set(&port->count, 0);
38133 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38134 port->tty = NULL;
38135 wake_up_interruptible(&port->open_wait);
38136@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
38137 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
38138 modem_info *info = &dev->mdm.info[i];
38139
38140- if (info->port.count == 0)
38141+ if (atomic_read(&info->port.count) == 0)
38142 continue;
38143 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
38144 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
38145diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
38146index e74df7c..03a03ba 100644
38147--- a/drivers/isdn/icn/icn.c
38148+++ b/drivers/isdn/icn/icn.c
38149@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
38150 if (count > len)
38151 count = len;
38152 if (user) {
38153- if (copy_from_user(msg, buf, count))
38154+ if (count > sizeof msg || copy_from_user(msg, buf, count))
38155 return -EFAULT;
38156 } else
38157 memcpy(msg, buf, count);
38158diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
38159index 6a8405d..0bd1c7e 100644
38160--- a/drivers/leds/leds-clevo-mail.c
38161+++ b/drivers/leds/leds-clevo-mail.c
38162@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
38163 * detected as working, but in reality it is not) as low as
38164 * possible.
38165 */
38166-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
38167+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
38168 {
38169 .callback = clevo_mail_led_dmi_callback,
38170 .ident = "Clevo D410J",
38171diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
38172index 64e204e..c6bf189 100644
38173--- a/drivers/leds/leds-ss4200.c
38174+++ b/drivers/leds/leds-ss4200.c
38175@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
38176 * detected as working, but in reality it is not) as low as
38177 * possible.
38178 */
38179-static struct dmi_system_id __initdata nas_led_whitelist[] = {
38180+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
38181 {
38182 .callback = ss4200_led_dmi_callback,
38183 .ident = "Intel SS4200-E",
38184diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
38185index 0bf1e4e..b4bf44e 100644
38186--- a/drivers/lguest/core.c
38187+++ b/drivers/lguest/core.c
38188@@ -97,9 +97,17 @@ static __init int map_switcher(void)
38189 * The end address needs +1 because __get_vm_area allocates an
38190 * extra guard page, so we need space for that.
38191 */
38192+
38193+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
38194+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
38195+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
38196+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
38197+#else
38198 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
38199 VM_ALLOC, switcher_addr, switcher_addr
38200 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
38201+#endif
38202+
38203 if (!switcher_vma) {
38204 err = -ENOMEM;
38205 printk("lguest: could not map switcher pages high\n");
38206@@ -124,7 +132,7 @@ static __init int map_switcher(void)
38207 * Now the Switcher is mapped at the right address, we can't fail!
38208 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
38209 */
38210- memcpy(switcher_vma->addr, start_switcher_text,
38211+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
38212 end_switcher_text - start_switcher_text);
38213
38214 printk(KERN_INFO "lguest: mapped switcher at %p\n",
38215diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
38216index 5b9ac32..2ef4f26 100644
38217--- a/drivers/lguest/page_tables.c
38218+++ b/drivers/lguest/page_tables.c
38219@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
38220 /*:*/
38221
38222 #ifdef CONFIG_X86_PAE
38223-static void release_pmd(pmd_t *spmd)
38224+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
38225 {
38226 /* If the entry's not present, there's nothing to release. */
38227 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
38228diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
38229index f0a3347..f6608b2 100644
38230--- a/drivers/lguest/x86/core.c
38231+++ b/drivers/lguest/x86/core.c
38232@@ -59,7 +59,7 @@ static struct {
38233 /* Offset from where switcher.S was compiled to where we've copied it */
38234 static unsigned long switcher_offset(void)
38235 {
38236- return switcher_addr - (unsigned long)start_switcher_text;
38237+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
38238 }
38239
38240 /* This cpu's struct lguest_pages (after the Switcher text page) */
38241@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
38242 * These copies are pretty cheap, so we do them unconditionally: */
38243 /* Save the current Host top-level page directory.
38244 */
38245+
38246+#ifdef CONFIG_PAX_PER_CPU_PGD
38247+ pages->state.host_cr3 = read_cr3();
38248+#else
38249 pages->state.host_cr3 = __pa(current->mm->pgd);
38250+#endif
38251+
38252 /*
38253 * Set up the Guest's page tables to see this CPU's pages (and no
38254 * other CPU's pages).
38255@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
38256 * compiled-in switcher code and the high-mapped copy we just made.
38257 */
38258 for (i = 0; i < IDT_ENTRIES; i++)
38259- default_idt_entries[i] += switcher_offset();
38260+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
38261
38262 /*
38263 * Set up the Switcher's per-cpu areas.
38264@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
38265 * it will be undisturbed when we switch. To change %cs and jump we
38266 * need this structure to feed to Intel's "lcall" instruction.
38267 */
38268- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
38269+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
38270 lguest_entry.segment = LGUEST_CS;
38271
38272 /*
38273diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
38274index 40634b0..4f5855e 100644
38275--- a/drivers/lguest/x86/switcher_32.S
38276+++ b/drivers/lguest/x86/switcher_32.S
38277@@ -87,6 +87,7 @@
38278 #include <asm/page.h>
38279 #include <asm/segment.h>
38280 #include <asm/lguest.h>
38281+#include <asm/processor-flags.h>
38282
38283 // We mark the start of the code to copy
38284 // It's placed in .text tho it's never run here
38285@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
38286 // Changes type when we load it: damn Intel!
38287 // For after we switch over our page tables
38288 // That entry will be read-only: we'd crash.
38289+
38290+#ifdef CONFIG_PAX_KERNEXEC
38291+ mov %cr0, %edx
38292+ xor $X86_CR0_WP, %edx
38293+ mov %edx, %cr0
38294+#endif
38295+
38296 movl $(GDT_ENTRY_TSS*8), %edx
38297 ltr %dx
38298
38299@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
38300 // Let's clear it again for our return.
38301 // The GDT descriptor of the Host
38302 // Points to the table after two "size" bytes
38303- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
38304+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
38305 // Clear "used" from type field (byte 5, bit 2)
38306- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
38307+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
38308+
38309+#ifdef CONFIG_PAX_KERNEXEC
38310+ mov %cr0, %eax
38311+ xor $X86_CR0_WP, %eax
38312+ mov %eax, %cr0
38313+#endif
38314
38315 // Once our page table's switched, the Guest is live!
38316 // The Host fades as we run this final step.
38317@@ -295,13 +309,12 @@ deliver_to_host:
38318 // I consulted gcc, and it gave
38319 // These instructions, which I gladly credit:
38320 leal (%edx,%ebx,8), %eax
38321- movzwl (%eax),%edx
38322- movl 4(%eax), %eax
38323- xorw %ax, %ax
38324- orl %eax, %edx
38325+ movl 4(%eax), %edx
38326+ movw (%eax), %dx
38327 // Now the address of the handler's in %edx
38328 // We call it now: its "iret" drops us home.
38329- jmp *%edx
38330+ ljmp $__KERNEL_CS, $1f
38331+1: jmp *%edx
38332
38333 // Every interrupt can come to us here
38334 // But we must truly tell each apart.
38335diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
38336index 0003992..854bbce 100644
38337--- a/drivers/md/bcache/closure.h
38338+++ b/drivers/md/bcache/closure.h
38339@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
38340 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
38341 struct workqueue_struct *wq)
38342 {
38343- BUG_ON(object_is_on_stack(cl));
38344+ BUG_ON(object_starts_on_stack(cl));
38345 closure_set_ip(cl);
38346 cl->fn = fn;
38347 cl->wq = wq;
38348diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
38349index 5a2c754..0fa55db 100644
38350--- a/drivers/md/bitmap.c
38351+++ b/drivers/md/bitmap.c
38352@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
38353 chunk_kb ? "KB" : "B");
38354 if (bitmap->storage.file) {
38355 seq_printf(seq, ", file: ");
38356- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
38357+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
38358 }
38359
38360 seq_printf(seq, "\n");
38361diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
38362index aa04f02..2a1309e 100644
38363--- a/drivers/md/dm-ioctl.c
38364+++ b/drivers/md/dm-ioctl.c
38365@@ -1694,7 +1694,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
38366 cmd == DM_LIST_VERSIONS_CMD)
38367 return 0;
38368
38369- if ((cmd == DM_DEV_CREATE_CMD)) {
38370+ if (cmd == DM_DEV_CREATE_CMD) {
38371 if (!*param->name) {
38372 DMWARN("name not supplied when creating device");
38373 return -EINVAL;
38374diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
38375index 699b5be..eac0a15 100644
38376--- a/drivers/md/dm-raid1.c
38377+++ b/drivers/md/dm-raid1.c
38378@@ -40,7 +40,7 @@ enum dm_raid1_error {
38379
38380 struct mirror {
38381 struct mirror_set *ms;
38382- atomic_t error_count;
38383+ atomic_unchecked_t error_count;
38384 unsigned long error_type;
38385 struct dm_dev *dev;
38386 sector_t offset;
38387@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
38388 struct mirror *m;
38389
38390 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
38391- if (!atomic_read(&m->error_count))
38392+ if (!atomic_read_unchecked(&m->error_count))
38393 return m;
38394
38395 return NULL;
38396@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
38397 * simple way to tell if a device has encountered
38398 * errors.
38399 */
38400- atomic_inc(&m->error_count);
38401+ atomic_inc_unchecked(&m->error_count);
38402
38403 if (test_and_set_bit(error_type, &m->error_type))
38404 return;
38405@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
38406 struct mirror *m = get_default_mirror(ms);
38407
38408 do {
38409- if (likely(!atomic_read(&m->error_count)))
38410+ if (likely(!atomic_read_unchecked(&m->error_count)))
38411 return m;
38412
38413 if (m-- == ms->mirror)
38414@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
38415 {
38416 struct mirror *default_mirror = get_default_mirror(m->ms);
38417
38418- return !atomic_read(&default_mirror->error_count);
38419+ return !atomic_read_unchecked(&default_mirror->error_count);
38420 }
38421
38422 static int mirror_available(struct mirror_set *ms, struct bio *bio)
38423@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
38424 */
38425 if (likely(region_in_sync(ms, region, 1)))
38426 m = choose_mirror(ms, bio->bi_sector);
38427- else if (m && atomic_read(&m->error_count))
38428+ else if (m && atomic_read_unchecked(&m->error_count))
38429 m = NULL;
38430
38431 if (likely(m))
38432@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
38433 }
38434
38435 ms->mirror[mirror].ms = ms;
38436- atomic_set(&(ms->mirror[mirror].error_count), 0);
38437+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
38438 ms->mirror[mirror].error_type = 0;
38439 ms->mirror[mirror].offset = offset;
38440
38441@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
38442 */
38443 static char device_status_char(struct mirror *m)
38444 {
38445- if (!atomic_read(&(m->error_count)))
38446+ if (!atomic_read_unchecked(&(m->error_count)))
38447 return 'A';
38448
38449 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
38450diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
38451index d907ca6..cfb8384 100644
38452--- a/drivers/md/dm-stripe.c
38453+++ b/drivers/md/dm-stripe.c
38454@@ -20,7 +20,7 @@ struct stripe {
38455 struct dm_dev *dev;
38456 sector_t physical_start;
38457
38458- atomic_t error_count;
38459+ atomic_unchecked_t error_count;
38460 };
38461
38462 struct stripe_c {
38463@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
38464 kfree(sc);
38465 return r;
38466 }
38467- atomic_set(&(sc->stripe[i].error_count), 0);
38468+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
38469 }
38470
38471 ti->private = sc;
38472@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
38473 DMEMIT("%d ", sc->stripes);
38474 for (i = 0; i < sc->stripes; i++) {
38475 DMEMIT("%s ", sc->stripe[i].dev->name);
38476- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
38477+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
38478 'D' : 'A';
38479 }
38480 buffer[i] = '\0';
38481@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
38482 */
38483 for (i = 0; i < sc->stripes; i++)
38484 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
38485- atomic_inc(&(sc->stripe[i].error_count));
38486- if (atomic_read(&(sc->stripe[i].error_count)) <
38487+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
38488+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
38489 DM_IO_ERROR_THRESHOLD)
38490 schedule_work(&sc->trigger_event);
38491 }
38492diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
38493index 1ff252a..ee384c1 100644
38494--- a/drivers/md/dm-table.c
38495+++ b/drivers/md/dm-table.c
38496@@ -389,7 +389,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
38497 if (!dev_size)
38498 return 0;
38499
38500- if ((start >= dev_size) || (start + len > dev_size)) {
38501+ if ((start >= dev_size) || (len > dev_size - start)) {
38502 DMWARN("%s: %s too small for target: "
38503 "start=%llu, len=%llu, dev_size=%llu",
38504 dm_device_name(ti->table->md), bdevname(bdev, b),
38505diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
38506index 60bce43..9b997d0 100644
38507--- a/drivers/md/dm-thin-metadata.c
38508+++ b/drivers/md/dm-thin-metadata.c
38509@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38510 {
38511 pmd->info.tm = pmd->tm;
38512 pmd->info.levels = 2;
38513- pmd->info.value_type.context = pmd->data_sm;
38514+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38515 pmd->info.value_type.size = sizeof(__le64);
38516 pmd->info.value_type.inc = data_block_inc;
38517 pmd->info.value_type.dec = data_block_dec;
38518@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38519
38520 pmd->bl_info.tm = pmd->tm;
38521 pmd->bl_info.levels = 1;
38522- pmd->bl_info.value_type.context = pmd->data_sm;
38523+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38524 pmd->bl_info.value_type.size = sizeof(__le64);
38525 pmd->bl_info.value_type.inc = data_block_inc;
38526 pmd->bl_info.value_type.dec = data_block_dec;
38527diff --git a/drivers/md/dm.c b/drivers/md/dm.c
38528index d5370a9..8761bbc 100644
38529--- a/drivers/md/dm.c
38530+++ b/drivers/md/dm.c
38531@@ -169,9 +169,9 @@ struct mapped_device {
38532 /*
38533 * Event handling.
38534 */
38535- atomic_t event_nr;
38536+ atomic_unchecked_t event_nr;
38537 wait_queue_head_t eventq;
38538- atomic_t uevent_seq;
38539+ atomic_unchecked_t uevent_seq;
38540 struct list_head uevent_list;
38541 spinlock_t uevent_lock; /* Protect access to uevent_list */
38542
38543@@ -1877,8 +1877,8 @@ static struct mapped_device *alloc_dev(int minor)
38544 rwlock_init(&md->map_lock);
38545 atomic_set(&md->holders, 1);
38546 atomic_set(&md->open_count, 0);
38547- atomic_set(&md->event_nr, 0);
38548- atomic_set(&md->uevent_seq, 0);
38549+ atomic_set_unchecked(&md->event_nr, 0);
38550+ atomic_set_unchecked(&md->uevent_seq, 0);
38551 INIT_LIST_HEAD(&md->uevent_list);
38552 spin_lock_init(&md->uevent_lock);
38553
38554@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
38555
38556 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
38557
38558- atomic_inc(&md->event_nr);
38559+ atomic_inc_unchecked(&md->event_nr);
38560 wake_up(&md->eventq);
38561 }
38562
38563@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
38564
38565 uint32_t dm_next_uevent_seq(struct mapped_device *md)
38566 {
38567- return atomic_add_return(1, &md->uevent_seq);
38568+ return atomic_add_return_unchecked(1, &md->uevent_seq);
38569 }
38570
38571 uint32_t dm_get_event_nr(struct mapped_device *md)
38572 {
38573- return atomic_read(&md->event_nr);
38574+ return atomic_read_unchecked(&md->event_nr);
38575 }
38576
38577 int dm_wait_event(struct mapped_device *md, int event_nr)
38578 {
38579 return wait_event_interruptible(md->eventq,
38580- (event_nr != atomic_read(&md->event_nr)));
38581+ (event_nr != atomic_read_unchecked(&md->event_nr)));
38582 }
38583
38584 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
38585diff --git a/drivers/md/md.c b/drivers/md/md.c
38586index 9b82377..6b6922d 100644
38587--- a/drivers/md/md.c
38588+++ b/drivers/md/md.c
38589@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
38590 * start build, activate spare
38591 */
38592 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
38593-static atomic_t md_event_count;
38594+static atomic_unchecked_t md_event_count;
38595 void md_new_event(struct mddev *mddev)
38596 {
38597- atomic_inc(&md_event_count);
38598+ atomic_inc_unchecked(&md_event_count);
38599 wake_up(&md_event_waiters);
38600 }
38601 EXPORT_SYMBOL_GPL(md_new_event);
38602@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
38603 */
38604 static void md_new_event_inintr(struct mddev *mddev)
38605 {
38606- atomic_inc(&md_event_count);
38607+ atomic_inc_unchecked(&md_event_count);
38608 wake_up(&md_event_waiters);
38609 }
38610
38611@@ -1501,7 +1501,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
38612 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
38613 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
38614 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
38615- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38616+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38617
38618 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
38619 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
38620@@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
38621 else
38622 sb->resync_offset = cpu_to_le64(0);
38623
38624- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
38625+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
38626
38627 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
38628 sb->size = cpu_to_le64(mddev->dev_sectors);
38629@@ -2750,7 +2750,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
38630 static ssize_t
38631 errors_show(struct md_rdev *rdev, char *page)
38632 {
38633- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
38634+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
38635 }
38636
38637 static ssize_t
38638@@ -2759,7 +2759,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
38639 char *e;
38640 unsigned long n = simple_strtoul(buf, &e, 10);
38641 if (*buf && (*e == 0 || *e == '\n')) {
38642- atomic_set(&rdev->corrected_errors, n);
38643+ atomic_set_unchecked(&rdev->corrected_errors, n);
38644 return len;
38645 }
38646 return -EINVAL;
38647@@ -3207,8 +3207,8 @@ int md_rdev_init(struct md_rdev *rdev)
38648 rdev->sb_loaded = 0;
38649 rdev->bb_page = NULL;
38650 atomic_set(&rdev->nr_pending, 0);
38651- atomic_set(&rdev->read_errors, 0);
38652- atomic_set(&rdev->corrected_errors, 0);
38653+ atomic_set_unchecked(&rdev->read_errors, 0);
38654+ atomic_set_unchecked(&rdev->corrected_errors, 0);
38655
38656 INIT_LIST_HEAD(&rdev->same_set);
38657 init_waitqueue_head(&rdev->blocked_wait);
38658@@ -7009,7 +7009,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
38659
38660 spin_unlock(&pers_lock);
38661 seq_printf(seq, "\n");
38662- seq->poll_event = atomic_read(&md_event_count);
38663+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38664 return 0;
38665 }
38666 if (v == (void*)2) {
38667@@ -7112,7 +7112,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
38668 return error;
38669
38670 seq = file->private_data;
38671- seq->poll_event = atomic_read(&md_event_count);
38672+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38673 return error;
38674 }
38675
38676@@ -7126,7 +7126,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
38677 /* always allow read */
38678 mask = POLLIN | POLLRDNORM;
38679
38680- if (seq->poll_event != atomic_read(&md_event_count))
38681+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
38682 mask |= POLLERR | POLLPRI;
38683 return mask;
38684 }
38685@@ -7170,7 +7170,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
38686 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
38687 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38688 (int)part_stat_read(&disk->part0, sectors[1]) -
38689- atomic_read(&disk->sync_io);
38690+ atomic_read_unchecked(&disk->sync_io);
38691 /* sync IO will cause sync_io to increase before the disk_stats
38692 * as sync_io is counted when a request starts, and
38693 * disk_stats is counted when it completes.
38694diff --git a/drivers/md/md.h b/drivers/md/md.h
38695index 653f992b6..6af6c40 100644
38696--- a/drivers/md/md.h
38697+++ b/drivers/md/md.h
38698@@ -94,13 +94,13 @@ struct md_rdev {
38699 * only maintained for arrays that
38700 * support hot removal
38701 */
38702- atomic_t read_errors; /* number of consecutive read errors that
38703+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
38704 * we have tried to ignore.
38705 */
38706 struct timespec last_read_error; /* monotonic time since our
38707 * last read error
38708 */
38709- atomic_t corrected_errors; /* number of corrected read errors,
38710+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
38711 * for reporting to userspace and storing
38712 * in superblock.
38713 */
38714@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
38715
38716 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
38717 {
38718- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38719+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38720 }
38721
38722 struct md_personality
38723diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
38724index 3e6d115..ffecdeb 100644
38725--- a/drivers/md/persistent-data/dm-space-map.h
38726+++ b/drivers/md/persistent-data/dm-space-map.h
38727@@ -71,6 +71,7 @@ struct dm_space_map {
38728 dm_sm_threshold_fn fn,
38729 void *context);
38730 };
38731+typedef struct dm_space_map __no_const dm_space_map_no_const;
38732
38733 /*----------------------------------------------------------------*/
38734
38735diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
38736index 6e17f81..140f717 100644
38737--- a/drivers/md/raid1.c
38738+++ b/drivers/md/raid1.c
38739@@ -1822,7 +1822,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
38740 if (r1_sync_page_io(rdev, sect, s,
38741 bio->bi_io_vec[idx].bv_page,
38742 READ) != 0)
38743- atomic_add(s, &rdev->corrected_errors);
38744+ atomic_add_unchecked(s, &rdev->corrected_errors);
38745 }
38746 sectors -= s;
38747 sect += s;
38748@@ -2042,7 +2042,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
38749 test_bit(In_sync, &rdev->flags)) {
38750 if (r1_sync_page_io(rdev, sect, s,
38751 conf->tmppage, READ)) {
38752- atomic_add(s, &rdev->corrected_errors);
38753+ atomic_add_unchecked(s, &rdev->corrected_errors);
38754 printk(KERN_INFO
38755 "md/raid1:%s: read error corrected "
38756 "(%d sectors at %llu on %s)\n",
38757diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38758index 6ddae25..514caa9 100644
38759--- a/drivers/md/raid10.c
38760+++ b/drivers/md/raid10.c
38761@@ -1940,7 +1940,7 @@ static void end_sync_read(struct bio *bio, int error)
38762 /* The write handler will notice the lack of
38763 * R10BIO_Uptodate and record any errors etc
38764 */
38765- atomic_add(r10_bio->sectors,
38766+ atomic_add_unchecked(r10_bio->sectors,
38767 &conf->mirrors[d].rdev->corrected_errors);
38768
38769 /* for reconstruct, we always reschedule after a read.
38770@@ -2286,7 +2286,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38771 {
38772 struct timespec cur_time_mon;
38773 unsigned long hours_since_last;
38774- unsigned int read_errors = atomic_read(&rdev->read_errors);
38775+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38776
38777 ktime_get_ts(&cur_time_mon);
38778
38779@@ -2308,9 +2308,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38780 * overflowing the shift of read_errors by hours_since_last.
38781 */
38782 if (hours_since_last >= 8 * sizeof(read_errors))
38783- atomic_set(&rdev->read_errors, 0);
38784+ atomic_set_unchecked(&rdev->read_errors, 0);
38785 else
38786- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38787+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38788 }
38789
38790 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38791@@ -2364,8 +2364,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38792 return;
38793
38794 check_decay_read_errors(mddev, rdev);
38795- atomic_inc(&rdev->read_errors);
38796- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38797+ atomic_inc_unchecked(&rdev->read_errors);
38798+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38799 char b[BDEVNAME_SIZE];
38800 bdevname(rdev->bdev, b);
38801
38802@@ -2373,7 +2373,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38803 "md/raid10:%s: %s: Raid device exceeded "
38804 "read_error threshold [cur %d:max %d]\n",
38805 mdname(mddev), b,
38806- atomic_read(&rdev->read_errors), max_read_errors);
38807+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38808 printk(KERN_NOTICE
38809 "md/raid10:%s: %s: Failing raid device\n",
38810 mdname(mddev), b);
38811@@ -2528,7 +2528,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38812 sect +
38813 choose_data_offset(r10_bio, rdev)),
38814 bdevname(rdev->bdev, b));
38815- atomic_add(s, &rdev->corrected_errors);
38816+ atomic_add_unchecked(s, &rdev->corrected_errors);
38817 }
38818
38819 rdev_dec_pending(rdev, mddev);
38820diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38821index 05e4a10..48fbe37 100644
38822--- a/drivers/md/raid5.c
38823+++ b/drivers/md/raid5.c
38824@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38825 mdname(conf->mddev), STRIPE_SECTORS,
38826 (unsigned long long)s,
38827 bdevname(rdev->bdev, b));
38828- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38829+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38830 clear_bit(R5_ReadError, &sh->dev[i].flags);
38831 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38832 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38833 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38834
38835- if (atomic_read(&rdev->read_errors))
38836- atomic_set(&rdev->read_errors, 0);
38837+ if (atomic_read_unchecked(&rdev->read_errors))
38838+ atomic_set_unchecked(&rdev->read_errors, 0);
38839 } else {
38840 const char *bdn = bdevname(rdev->bdev, b);
38841 int retry = 0;
38842 int set_bad = 0;
38843
38844 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38845- atomic_inc(&rdev->read_errors);
38846+ atomic_inc_unchecked(&rdev->read_errors);
38847 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38848 printk_ratelimited(
38849 KERN_WARNING
38850@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38851 mdname(conf->mddev),
38852 (unsigned long long)s,
38853 bdn);
38854- } else if (atomic_read(&rdev->read_errors)
38855+ } else if (atomic_read_unchecked(&rdev->read_errors)
38856 > conf->max_nr_stripes)
38857 printk(KERN_WARNING
38858 "md/raid:%s: Too many read errors, failing device %s.\n",
38859diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38860index 401ef64..836e563 100644
38861--- a/drivers/media/dvb-core/dvbdev.c
38862+++ b/drivers/media/dvb-core/dvbdev.c
38863@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38864 const struct dvb_device *template, void *priv, int type)
38865 {
38866 struct dvb_device *dvbdev;
38867- struct file_operations *dvbdevfops;
38868+ file_operations_no_const *dvbdevfops;
38869 struct device *clsdev;
38870 int minor;
38871 int id;
38872diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38873index 9b6c3bb..baeb5c7 100644
38874--- a/drivers/media/dvb-frontends/dib3000.h
38875+++ b/drivers/media/dvb-frontends/dib3000.h
38876@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38877 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38878 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38879 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38880-};
38881+} __no_const;
38882
38883 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
38884 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38885diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
38886index c7a9be1..683f6f8 100644
38887--- a/drivers/media/pci/cx88/cx88-video.c
38888+++ b/drivers/media/pci/cx88/cx88-video.c
38889@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
38890
38891 /* ------------------------------------------------------------------ */
38892
38893-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38894-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38895-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38896+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38897+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38898+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38899
38900 module_param_array(video_nr, int, NULL, 0444);
38901 module_param_array(vbi_nr, int, NULL, 0444);
38902diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38903index d338b19..aae4f9e 100644
38904--- a/drivers/media/platform/omap/omap_vout.c
38905+++ b/drivers/media/platform/omap/omap_vout.c
38906@@ -63,7 +63,6 @@ enum omap_vout_channels {
38907 OMAP_VIDEO2,
38908 };
38909
38910-static struct videobuf_queue_ops video_vbq_ops;
38911 /* Variables configurable through module params*/
38912 static u32 video1_numbuffers = 3;
38913 static u32 video2_numbuffers = 3;
38914@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
38915 {
38916 struct videobuf_queue *q;
38917 struct omap_vout_device *vout = NULL;
38918+ static struct videobuf_queue_ops video_vbq_ops = {
38919+ .buf_setup = omap_vout_buffer_setup,
38920+ .buf_prepare = omap_vout_buffer_prepare,
38921+ .buf_release = omap_vout_buffer_release,
38922+ .buf_queue = omap_vout_buffer_queue,
38923+ };
38924
38925 vout = video_drvdata(file);
38926 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38927@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
38928 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38929
38930 q = &vout->vbq;
38931- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38932- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38933- video_vbq_ops.buf_release = omap_vout_buffer_release;
38934- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38935 spin_lock_init(&vout->vbq_lock);
38936
38937 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38938diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38939index 04e6490..2df65bf 100644
38940--- a/drivers/media/platform/s5p-tv/mixer.h
38941+++ b/drivers/media/platform/s5p-tv/mixer.h
38942@@ -156,7 +156,7 @@ struct mxr_layer {
38943 /** layer index (unique identifier) */
38944 int idx;
38945 /** callbacks for layer methods */
38946- struct mxr_layer_ops ops;
38947+ struct mxr_layer_ops *ops;
38948 /** format array */
38949 const struct mxr_format **fmt_array;
38950 /** size of format array */
38951diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38952index b93a21f..2535195 100644
38953--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38954+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38955@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38956 {
38957 struct mxr_layer *layer;
38958 int ret;
38959- struct mxr_layer_ops ops = {
38960+ static struct mxr_layer_ops ops = {
38961 .release = mxr_graph_layer_release,
38962 .buffer_set = mxr_graph_buffer_set,
38963 .stream_set = mxr_graph_stream_set,
38964diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38965index b713403..53cb5ad 100644
38966--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38967+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38968@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38969 layer->update_buf = next;
38970 }
38971
38972- layer->ops.buffer_set(layer, layer->update_buf);
38973+ layer->ops->buffer_set(layer, layer->update_buf);
38974
38975 if (done && done != layer->shadow_buf)
38976 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38977diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38978index ef0efdf..8c78eb6 100644
38979--- a/drivers/media/platform/s5p-tv/mixer_video.c
38980+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38981@@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38982 layer->geo.src.height = layer->geo.src.full_height;
38983
38984 mxr_geometry_dump(mdev, &layer->geo);
38985- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38986+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38987 mxr_geometry_dump(mdev, &layer->geo);
38988 }
38989
38990@@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38991 layer->geo.dst.full_width = mbus_fmt.width;
38992 layer->geo.dst.full_height = mbus_fmt.height;
38993 layer->geo.dst.field = mbus_fmt.field;
38994- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38995+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38996
38997 mxr_geometry_dump(mdev, &layer->geo);
38998 }
38999@@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
39000 /* set source size to highest accepted value */
39001 geo->src.full_width = max(geo->dst.full_width, pix->width);
39002 geo->src.full_height = max(geo->dst.full_height, pix->height);
39003- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
39004+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
39005 mxr_geometry_dump(mdev, &layer->geo);
39006 /* set cropping to total visible screen */
39007 geo->src.width = pix->width;
39008@@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
39009 geo->src.x_offset = 0;
39010 geo->src.y_offset = 0;
39011 /* assure consistency of geometry */
39012- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
39013+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
39014 mxr_geometry_dump(mdev, &layer->geo);
39015 /* set full size to lowest possible value */
39016 geo->src.full_width = 0;
39017 geo->src.full_height = 0;
39018- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
39019+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
39020 mxr_geometry_dump(mdev, &layer->geo);
39021
39022 /* returning results */
39023@@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
39024 target->width = s->r.width;
39025 target->height = s->r.height;
39026
39027- layer->ops.fix_geometry(layer, stage, s->flags);
39028+ layer->ops->fix_geometry(layer, stage, s->flags);
39029
39030 /* retrieve update selection rectangle */
39031 res.left = target->x_offset;
39032@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
39033 mxr_output_get(mdev);
39034
39035 mxr_layer_update_output(layer);
39036- layer->ops.format_set(layer);
39037+ layer->ops->format_set(layer);
39038 /* enabling layer in hardware */
39039 spin_lock_irqsave(&layer->enq_slock, flags);
39040 layer->state = MXR_LAYER_STREAMING;
39041 spin_unlock_irqrestore(&layer->enq_slock, flags);
39042
39043- layer->ops.stream_set(layer, MXR_ENABLE);
39044+ layer->ops->stream_set(layer, MXR_ENABLE);
39045 mxr_streamer_get(mdev);
39046
39047 return 0;
39048@@ -1030,7 +1030,7 @@ static int stop_streaming(struct vb2_queue *vq)
39049 spin_unlock_irqrestore(&layer->enq_slock, flags);
39050
39051 /* disabling layer in hardware */
39052- layer->ops.stream_set(layer, MXR_DISABLE);
39053+ layer->ops->stream_set(layer, MXR_DISABLE);
39054 /* remove one streamer */
39055 mxr_streamer_put(mdev);
39056 /* allow changes in output configuration */
39057@@ -1069,8 +1069,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
39058
39059 void mxr_layer_release(struct mxr_layer *layer)
39060 {
39061- if (layer->ops.release)
39062- layer->ops.release(layer);
39063+ if (layer->ops->release)
39064+ layer->ops->release(layer);
39065 }
39066
39067 void mxr_base_layer_release(struct mxr_layer *layer)
39068@@ -1096,7 +1096,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
39069
39070 layer->mdev = mdev;
39071 layer->idx = idx;
39072- layer->ops = *ops;
39073+ layer->ops = ops;
39074
39075 spin_lock_init(&layer->enq_slock);
39076 INIT_LIST_HEAD(&layer->enq_list);
39077diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39078index 3d13a63..da31bf1 100644
39079--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39080+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39081@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
39082 {
39083 struct mxr_layer *layer;
39084 int ret;
39085- struct mxr_layer_ops ops = {
39086+ static struct mxr_layer_ops ops = {
39087 .release = mxr_vp_layer_release,
39088 .buffer_set = mxr_vp_buffer_set,
39089 .stream_set = mxr_vp_stream_set,
39090diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
39091index 545c04c..a14bded 100644
39092--- a/drivers/media/radio/radio-cadet.c
39093+++ b/drivers/media/radio/radio-cadet.c
39094@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
39095 unsigned char readbuf[RDS_BUFFER];
39096 int i = 0;
39097
39098+ if (count > RDS_BUFFER)
39099+ return -EFAULT;
39100 mutex_lock(&dev->lock);
39101 if (dev->rdsstat == 0)
39102 cadet_start_rds(dev);
39103@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
39104 while (i < count && dev->rdsin != dev->rdsout)
39105 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
39106
39107- if (i && copy_to_user(data, readbuf, i))
39108+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
39109 i = -EFAULT;
39110 unlock:
39111 mutex_unlock(&dev->lock);
39112diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
39113index 3940bb0..fb3952a 100644
39114--- a/drivers/media/usb/dvb-usb/cxusb.c
39115+++ b/drivers/media/usb/dvb-usb/cxusb.c
39116@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
39117
39118 struct dib0700_adapter_state {
39119 int (*set_param_save) (struct dvb_frontend *);
39120-};
39121+} __no_const;
39122
39123 static int dib7070_set_param_override(struct dvb_frontend *fe)
39124 {
39125diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
39126index 6e237b6..dc25556 100644
39127--- a/drivers/media/usb/dvb-usb/dw2102.c
39128+++ b/drivers/media/usb/dvb-usb/dw2102.c
39129@@ -118,7 +118,7 @@ struct su3000_state {
39130
39131 struct s6x0_state {
39132 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
39133-};
39134+} __no_const;
39135
39136 /* debug */
39137 static int dvb_usb_dw2102_debug;
39138diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
39139index f129551..ecf6514 100644
39140--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
39141+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
39142@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
39143 __u32 reserved;
39144 };
39145
39146-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
39147+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
39148 enum v4l2_memory memory)
39149 {
39150 void __user *up_pln;
39151@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
39152 return 0;
39153 }
39154
39155-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
39156+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
39157 enum v4l2_memory memory)
39158 {
39159 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
39160@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
39161 put_user(kp->start_block, &up->start_block) ||
39162 put_user(kp->blocks, &up->blocks) ||
39163 put_user(tmp, &up->edid) ||
39164- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
39165+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
39166 return -EFAULT;
39167 return 0;
39168 }
39169diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
39170index 7658586..1079260 100644
39171--- a/drivers/media/v4l2-core/v4l2-ioctl.c
39172+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
39173@@ -1995,7 +1995,8 @@ struct v4l2_ioctl_info {
39174 struct file *file, void *fh, void *p);
39175 } u;
39176 void (*debug)(const void *arg, bool write_only);
39177-};
39178+} __do_const;
39179+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
39180
39181 /* This control needs a priority check */
39182 #define INFO_FL_PRIO (1 << 0)
39183@@ -2177,7 +2178,7 @@ static long __video_do_ioctl(struct file *file,
39184 struct video_device *vfd = video_devdata(file);
39185 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
39186 bool write_only = false;
39187- struct v4l2_ioctl_info default_info;
39188+ v4l2_ioctl_info_no_const default_info;
39189 const struct v4l2_ioctl_info *info;
39190 void *fh = file->private_data;
39191 struct v4l2_fh *vfh = NULL;
39192@@ -2251,7 +2252,7 @@ done:
39193 }
39194
39195 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39196- void * __user *user_ptr, void ***kernel_ptr)
39197+ void __user **user_ptr, void ***kernel_ptr)
39198 {
39199 int ret = 0;
39200
39201@@ -2267,7 +2268,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39202 ret = -EINVAL;
39203 break;
39204 }
39205- *user_ptr = (void __user *)buf->m.planes;
39206+ *user_ptr = (void __force_user *)buf->m.planes;
39207 *kernel_ptr = (void *)&buf->m.planes;
39208 *array_size = sizeof(struct v4l2_plane) * buf->length;
39209 ret = 1;
39210@@ -2302,7 +2303,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39211 ret = -EINVAL;
39212 break;
39213 }
39214- *user_ptr = (void __user *)ctrls->controls;
39215+ *user_ptr = (void __force_user *)ctrls->controls;
39216 *kernel_ptr = (void *)&ctrls->controls;
39217 *array_size = sizeof(struct v4l2_ext_control)
39218 * ctrls->count;
39219diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
39220index 767ff4d..c69d259 100644
39221--- a/drivers/message/fusion/mptbase.c
39222+++ b/drivers/message/fusion/mptbase.c
39223@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
39224 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
39225 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
39226
39227+#ifdef CONFIG_GRKERNSEC_HIDESYM
39228+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
39229+#else
39230 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
39231 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
39232+#endif
39233+
39234 /*
39235 * Rounding UP to nearest 4-kB boundary here...
39236 */
39237@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
39238 ioc->facts.GlobalCredits);
39239
39240 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
39241+#ifdef CONFIG_GRKERNSEC_HIDESYM
39242+ NULL, NULL);
39243+#else
39244 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
39245+#endif
39246 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
39247 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
39248 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
39249diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
39250index dd239bd..689c4f7 100644
39251--- a/drivers/message/fusion/mptsas.c
39252+++ b/drivers/message/fusion/mptsas.c
39253@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
39254 return 0;
39255 }
39256
39257+static inline void
39258+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39259+{
39260+ if (phy_info->port_details) {
39261+ phy_info->port_details->rphy = rphy;
39262+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39263+ ioc->name, rphy));
39264+ }
39265+
39266+ if (rphy) {
39267+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39268+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39269+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39270+ ioc->name, rphy, rphy->dev.release));
39271+ }
39272+}
39273+
39274 /* no mutex */
39275 static void
39276 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
39277@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
39278 return NULL;
39279 }
39280
39281-static inline void
39282-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39283-{
39284- if (phy_info->port_details) {
39285- phy_info->port_details->rphy = rphy;
39286- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39287- ioc->name, rphy));
39288- }
39289-
39290- if (rphy) {
39291- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39292- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39293- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39294- ioc->name, rphy, rphy->dev.release));
39295- }
39296-}
39297-
39298 static inline struct sas_port *
39299 mptsas_get_port(struct mptsas_phyinfo *phy_info)
39300 {
39301diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
39302index 727819c..ad74694 100644
39303--- a/drivers/message/fusion/mptscsih.c
39304+++ b/drivers/message/fusion/mptscsih.c
39305@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
39306
39307 h = shost_priv(SChost);
39308
39309- if (h) {
39310- if (h->info_kbuf == NULL)
39311- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39312- return h->info_kbuf;
39313- h->info_kbuf[0] = '\0';
39314+ if (!h)
39315+ return NULL;
39316
39317- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39318- h->info_kbuf[size-1] = '\0';
39319- }
39320+ if (h->info_kbuf == NULL)
39321+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39322+ return h->info_kbuf;
39323+ h->info_kbuf[0] = '\0';
39324+
39325+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39326+ h->info_kbuf[size-1] = '\0';
39327
39328 return h->info_kbuf;
39329 }
39330diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
39331index b7d87cd..9890039 100644
39332--- a/drivers/message/i2o/i2o_proc.c
39333+++ b/drivers/message/i2o/i2o_proc.c
39334@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
39335 "Array Controller Device"
39336 };
39337
39338-static char *chtostr(char *tmp, u8 *chars, int n)
39339-{
39340- tmp[0] = 0;
39341- return strncat(tmp, (char *)chars, n);
39342-}
39343-
39344 static int i2o_report_query_status(struct seq_file *seq, int block_status,
39345 char *group)
39346 {
39347@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39348 } *result;
39349
39350 i2o_exec_execute_ddm_table ddm_table;
39351- char tmp[28 + 1];
39352
39353 result = kmalloc(sizeof(*result), GFP_KERNEL);
39354 if (!result)
39355@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39356
39357 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
39358 seq_printf(seq, "%-#8x", ddm_table.module_id);
39359- seq_printf(seq, "%-29s",
39360- chtostr(tmp, ddm_table.module_name_version, 28));
39361+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
39362 seq_printf(seq, "%9d ", ddm_table.data_size);
39363 seq_printf(seq, "%8d", ddm_table.code_size);
39364
39365@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39366
39367 i2o_driver_result_table *result;
39368 i2o_driver_store_table *dst;
39369- char tmp[28 + 1];
39370
39371 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
39372 if (result == NULL)
39373@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39374
39375 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
39376 seq_printf(seq, "%-#8x", dst->module_id);
39377- seq_printf(seq, "%-29s",
39378- chtostr(tmp, dst->module_name_version, 28));
39379- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
39380+ seq_printf(seq, "%-.28s", dst->module_name_version);
39381+ seq_printf(seq, "%-.8s", dst->date);
39382 seq_printf(seq, "%8d ", dst->module_size);
39383 seq_printf(seq, "%8d ", dst->mpb_size);
39384 seq_printf(seq, "0x%04x", dst->module_flags);
39385@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39386 // == (allow) 512d bytes (max)
39387 static u16 *work16 = (u16 *) work32;
39388 int token;
39389- char tmp[16 + 1];
39390
39391 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
39392
39393@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39394 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
39395 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
39396 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
39397- seq_printf(seq, "Vendor info : %s\n",
39398- chtostr(tmp, (u8 *) (work32 + 2), 16));
39399- seq_printf(seq, "Product info : %s\n",
39400- chtostr(tmp, (u8 *) (work32 + 6), 16));
39401- seq_printf(seq, "Description : %s\n",
39402- chtostr(tmp, (u8 *) (work32 + 10), 16));
39403- seq_printf(seq, "Product rev. : %s\n",
39404- chtostr(tmp, (u8 *) (work32 + 14), 8));
39405+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
39406+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
39407+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
39408+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
39409
39410 seq_printf(seq, "Serial number : ");
39411 print_serial_number(seq, (u8 *) (work32 + 16),
39412@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39413 u8 pad[256]; // allow up to 256 byte (max) serial number
39414 } result;
39415
39416- char tmp[24 + 1];
39417-
39418 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
39419
39420 if (token < 0) {
39421@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39422 }
39423
39424 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
39425- seq_printf(seq, "Module name : %s\n",
39426- chtostr(tmp, result.module_name, 24));
39427- seq_printf(seq, "Module revision : %s\n",
39428- chtostr(tmp, result.module_rev, 8));
39429+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
39430+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
39431
39432 seq_printf(seq, "Serial number : ");
39433 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
39434@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39435 u8 instance_number[4];
39436 } result;
39437
39438- char tmp[64 + 1];
39439-
39440 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
39441
39442 if (token < 0) {
39443@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39444 return 0;
39445 }
39446
39447- seq_printf(seq, "Device name : %s\n",
39448- chtostr(tmp, result.device_name, 64));
39449- seq_printf(seq, "Service name : %s\n",
39450- chtostr(tmp, result.service_name, 64));
39451- seq_printf(seq, "Physical name : %s\n",
39452- chtostr(tmp, result.physical_location, 64));
39453- seq_printf(seq, "Instance number : %s\n",
39454- chtostr(tmp, result.instance_number, 4));
39455+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
39456+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
39457+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
39458+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
39459
39460 return 0;
39461 }
39462diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
39463index a8c08f3..155fe3d 100644
39464--- a/drivers/message/i2o/iop.c
39465+++ b/drivers/message/i2o/iop.c
39466@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
39467
39468 spin_lock_irqsave(&c->context_list_lock, flags);
39469
39470- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
39471- atomic_inc(&c->context_list_counter);
39472+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
39473+ atomic_inc_unchecked(&c->context_list_counter);
39474
39475- entry->context = atomic_read(&c->context_list_counter);
39476+ entry->context = atomic_read_unchecked(&c->context_list_counter);
39477
39478 list_add(&entry->list, &c->context_list);
39479
39480@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
39481
39482 #if BITS_PER_LONG == 64
39483 spin_lock_init(&c->context_list_lock);
39484- atomic_set(&c->context_list_counter, 0);
39485+ atomic_set_unchecked(&c->context_list_counter, 0);
39486 INIT_LIST_HEAD(&c->context_list);
39487 #endif
39488
39489diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
39490index 45ece11..8efa218 100644
39491--- a/drivers/mfd/janz-cmodio.c
39492+++ b/drivers/mfd/janz-cmodio.c
39493@@ -13,6 +13,7 @@
39494
39495 #include <linux/kernel.h>
39496 #include <linux/module.h>
39497+#include <linux/slab.h>
39498 #include <linux/init.h>
39499 #include <linux/pci.h>
39500 #include <linux/interrupt.h>
39501diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
39502index a5f9888..1c0ed56 100644
39503--- a/drivers/mfd/twl4030-irq.c
39504+++ b/drivers/mfd/twl4030-irq.c
39505@@ -35,6 +35,7 @@
39506 #include <linux/of.h>
39507 #include <linux/irqdomain.h>
39508 #include <linux/i2c/twl.h>
39509+#include <asm/pgtable.h>
39510
39511 #include "twl-core.h"
39512
39513@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
39514 * Install an irq handler for each of the SIH modules;
39515 * clone dummy irq_chip since PIH can't *do* anything
39516 */
39517- twl4030_irq_chip = dummy_irq_chip;
39518- twl4030_irq_chip.name = "twl4030";
39519+ pax_open_kernel();
39520+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
39521+ *(const char **)&twl4030_irq_chip.name = "twl4030";
39522
39523- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39524+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39525+ pax_close_kernel();
39526
39527 for (i = irq_base; i < irq_end; i++) {
39528 irq_set_chip_and_handler(i, &twl4030_irq_chip,
39529diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
39530index 277a8db..0e0b754 100644
39531--- a/drivers/mfd/twl6030-irq.c
39532+++ b/drivers/mfd/twl6030-irq.c
39533@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
39534 * install an irq handler for each of the modules;
39535 * clone dummy irq_chip since PIH can't *do* anything
39536 */
39537- twl6030_irq_chip = dummy_irq_chip;
39538- twl6030_irq_chip.name = "twl6030";
39539- twl6030_irq_chip.irq_set_type = NULL;
39540- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39541+ pax_open_kernel();
39542+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
39543+ *(const char **)&twl6030_irq_chip.name = "twl6030";
39544+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
39545+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39546+ pax_close_kernel();
39547
39548 for (i = irq_base; i < irq_end; i++) {
39549 irq_set_chip_and_handler(i, &twl6030_irq_chip,
39550diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
39551index f32550a..e3e52a2 100644
39552--- a/drivers/misc/c2port/core.c
39553+++ b/drivers/misc/c2port/core.c
39554@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
39555 mutex_init(&c2dev->mutex);
39556
39557 /* Create binary file */
39558- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39559+ pax_open_kernel();
39560+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39561+ pax_close_kernel();
39562 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
39563 if (unlikely(ret))
39564 goto error_device_create_bin_file;
39565diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
39566index 36f5d52..32311c3 100644
39567--- a/drivers/misc/kgdbts.c
39568+++ b/drivers/misc/kgdbts.c
39569@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
39570 char before[BREAK_INSTR_SIZE];
39571 char after[BREAK_INSTR_SIZE];
39572
39573- probe_kernel_read(before, (char *)kgdbts_break_test,
39574+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
39575 BREAK_INSTR_SIZE);
39576 init_simple_test();
39577 ts.tst = plant_and_detach_test;
39578@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
39579 /* Activate test with initial breakpoint */
39580 if (!is_early)
39581 kgdb_breakpoint();
39582- probe_kernel_read(after, (char *)kgdbts_break_test,
39583+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
39584 BREAK_INSTR_SIZE);
39585 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
39586 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
39587diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
39588index 4cd4a3d..b48cbc7 100644
39589--- a/drivers/misc/lis3lv02d/lis3lv02d.c
39590+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
39591@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
39592 * the lid is closed. This leads to interrupts as soon as a little move
39593 * is done.
39594 */
39595- atomic_inc(&lis3->count);
39596+ atomic_inc_unchecked(&lis3->count);
39597
39598 wake_up_interruptible(&lis3->misc_wait);
39599 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
39600@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
39601 if (lis3->pm_dev)
39602 pm_runtime_get_sync(lis3->pm_dev);
39603
39604- atomic_set(&lis3->count, 0);
39605+ atomic_set_unchecked(&lis3->count, 0);
39606 return 0;
39607 }
39608
39609@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
39610 add_wait_queue(&lis3->misc_wait, &wait);
39611 while (true) {
39612 set_current_state(TASK_INTERRUPTIBLE);
39613- data = atomic_xchg(&lis3->count, 0);
39614+ data = atomic_xchg_unchecked(&lis3->count, 0);
39615 if (data)
39616 break;
39617
39618@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
39619 struct lis3lv02d, miscdev);
39620
39621 poll_wait(file, &lis3->misc_wait, wait);
39622- if (atomic_read(&lis3->count))
39623+ if (atomic_read_unchecked(&lis3->count))
39624 return POLLIN | POLLRDNORM;
39625 return 0;
39626 }
39627diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
39628index c439c82..1f20f57 100644
39629--- a/drivers/misc/lis3lv02d/lis3lv02d.h
39630+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
39631@@ -297,7 +297,7 @@ struct lis3lv02d {
39632 struct input_polled_dev *idev; /* input device */
39633 struct platform_device *pdev; /* platform device */
39634 struct regulator_bulk_data regulators[2];
39635- atomic_t count; /* interrupt count after last read */
39636+ atomic_unchecked_t count; /* interrupt count after last read */
39637 union axis_conversion ac; /* hw -> logical axis */
39638 int mapped_btns[3];
39639
39640diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
39641index 2f30bad..c4c13d0 100644
39642--- a/drivers/misc/sgi-gru/gruhandles.c
39643+++ b/drivers/misc/sgi-gru/gruhandles.c
39644@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
39645 unsigned long nsec;
39646
39647 nsec = CLKS2NSEC(clks);
39648- atomic_long_inc(&mcs_op_statistics[op].count);
39649- atomic_long_add(nsec, &mcs_op_statistics[op].total);
39650+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
39651+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
39652 if (mcs_op_statistics[op].max < nsec)
39653 mcs_op_statistics[op].max = nsec;
39654 }
39655diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
39656index 797d796..ae8f01e 100644
39657--- a/drivers/misc/sgi-gru/gruprocfs.c
39658+++ b/drivers/misc/sgi-gru/gruprocfs.c
39659@@ -32,9 +32,9 @@
39660
39661 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
39662
39663-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
39664+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
39665 {
39666- unsigned long val = atomic_long_read(v);
39667+ unsigned long val = atomic_long_read_unchecked(v);
39668
39669 seq_printf(s, "%16lu %s\n", val, id);
39670 }
39671@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
39672
39673 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
39674 for (op = 0; op < mcsop_last; op++) {
39675- count = atomic_long_read(&mcs_op_statistics[op].count);
39676- total = atomic_long_read(&mcs_op_statistics[op].total);
39677+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
39678+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
39679 max = mcs_op_statistics[op].max;
39680 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
39681 count ? total / count : 0, max);
39682diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
39683index 5c3ce24..4915ccb 100644
39684--- a/drivers/misc/sgi-gru/grutables.h
39685+++ b/drivers/misc/sgi-gru/grutables.h
39686@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
39687 * GRU statistics.
39688 */
39689 struct gru_stats_s {
39690- atomic_long_t vdata_alloc;
39691- atomic_long_t vdata_free;
39692- atomic_long_t gts_alloc;
39693- atomic_long_t gts_free;
39694- atomic_long_t gms_alloc;
39695- atomic_long_t gms_free;
39696- atomic_long_t gts_double_allocate;
39697- atomic_long_t assign_context;
39698- atomic_long_t assign_context_failed;
39699- atomic_long_t free_context;
39700- atomic_long_t load_user_context;
39701- atomic_long_t load_kernel_context;
39702- atomic_long_t lock_kernel_context;
39703- atomic_long_t unlock_kernel_context;
39704- atomic_long_t steal_user_context;
39705- atomic_long_t steal_kernel_context;
39706- atomic_long_t steal_context_failed;
39707- atomic_long_t nopfn;
39708- atomic_long_t asid_new;
39709- atomic_long_t asid_next;
39710- atomic_long_t asid_wrap;
39711- atomic_long_t asid_reuse;
39712- atomic_long_t intr;
39713- atomic_long_t intr_cbr;
39714- atomic_long_t intr_tfh;
39715- atomic_long_t intr_spurious;
39716- atomic_long_t intr_mm_lock_failed;
39717- atomic_long_t call_os;
39718- atomic_long_t call_os_wait_queue;
39719- atomic_long_t user_flush_tlb;
39720- atomic_long_t user_unload_context;
39721- atomic_long_t user_exception;
39722- atomic_long_t set_context_option;
39723- atomic_long_t check_context_retarget_intr;
39724- atomic_long_t check_context_unload;
39725- atomic_long_t tlb_dropin;
39726- atomic_long_t tlb_preload_page;
39727- atomic_long_t tlb_dropin_fail_no_asid;
39728- atomic_long_t tlb_dropin_fail_upm;
39729- atomic_long_t tlb_dropin_fail_invalid;
39730- atomic_long_t tlb_dropin_fail_range_active;
39731- atomic_long_t tlb_dropin_fail_idle;
39732- atomic_long_t tlb_dropin_fail_fmm;
39733- atomic_long_t tlb_dropin_fail_no_exception;
39734- atomic_long_t tfh_stale_on_fault;
39735- atomic_long_t mmu_invalidate_range;
39736- atomic_long_t mmu_invalidate_page;
39737- atomic_long_t flush_tlb;
39738- atomic_long_t flush_tlb_gru;
39739- atomic_long_t flush_tlb_gru_tgh;
39740- atomic_long_t flush_tlb_gru_zero_asid;
39741+ atomic_long_unchecked_t vdata_alloc;
39742+ atomic_long_unchecked_t vdata_free;
39743+ atomic_long_unchecked_t gts_alloc;
39744+ atomic_long_unchecked_t gts_free;
39745+ atomic_long_unchecked_t gms_alloc;
39746+ atomic_long_unchecked_t gms_free;
39747+ atomic_long_unchecked_t gts_double_allocate;
39748+ atomic_long_unchecked_t assign_context;
39749+ atomic_long_unchecked_t assign_context_failed;
39750+ atomic_long_unchecked_t free_context;
39751+ atomic_long_unchecked_t load_user_context;
39752+ atomic_long_unchecked_t load_kernel_context;
39753+ atomic_long_unchecked_t lock_kernel_context;
39754+ atomic_long_unchecked_t unlock_kernel_context;
39755+ atomic_long_unchecked_t steal_user_context;
39756+ atomic_long_unchecked_t steal_kernel_context;
39757+ atomic_long_unchecked_t steal_context_failed;
39758+ atomic_long_unchecked_t nopfn;
39759+ atomic_long_unchecked_t asid_new;
39760+ atomic_long_unchecked_t asid_next;
39761+ atomic_long_unchecked_t asid_wrap;
39762+ atomic_long_unchecked_t asid_reuse;
39763+ atomic_long_unchecked_t intr;
39764+ atomic_long_unchecked_t intr_cbr;
39765+ atomic_long_unchecked_t intr_tfh;
39766+ atomic_long_unchecked_t intr_spurious;
39767+ atomic_long_unchecked_t intr_mm_lock_failed;
39768+ atomic_long_unchecked_t call_os;
39769+ atomic_long_unchecked_t call_os_wait_queue;
39770+ atomic_long_unchecked_t user_flush_tlb;
39771+ atomic_long_unchecked_t user_unload_context;
39772+ atomic_long_unchecked_t user_exception;
39773+ atomic_long_unchecked_t set_context_option;
39774+ atomic_long_unchecked_t check_context_retarget_intr;
39775+ atomic_long_unchecked_t check_context_unload;
39776+ atomic_long_unchecked_t tlb_dropin;
39777+ atomic_long_unchecked_t tlb_preload_page;
39778+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
39779+ atomic_long_unchecked_t tlb_dropin_fail_upm;
39780+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
39781+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
39782+ atomic_long_unchecked_t tlb_dropin_fail_idle;
39783+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
39784+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
39785+ atomic_long_unchecked_t tfh_stale_on_fault;
39786+ atomic_long_unchecked_t mmu_invalidate_range;
39787+ atomic_long_unchecked_t mmu_invalidate_page;
39788+ atomic_long_unchecked_t flush_tlb;
39789+ atomic_long_unchecked_t flush_tlb_gru;
39790+ atomic_long_unchecked_t flush_tlb_gru_tgh;
39791+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
39792
39793- atomic_long_t copy_gpa;
39794- atomic_long_t read_gpa;
39795+ atomic_long_unchecked_t copy_gpa;
39796+ atomic_long_unchecked_t read_gpa;
39797
39798- atomic_long_t mesq_receive;
39799- atomic_long_t mesq_receive_none;
39800- atomic_long_t mesq_send;
39801- atomic_long_t mesq_send_failed;
39802- atomic_long_t mesq_noop;
39803- atomic_long_t mesq_send_unexpected_error;
39804- atomic_long_t mesq_send_lb_overflow;
39805- atomic_long_t mesq_send_qlimit_reached;
39806- atomic_long_t mesq_send_amo_nacked;
39807- atomic_long_t mesq_send_put_nacked;
39808- atomic_long_t mesq_page_overflow;
39809- atomic_long_t mesq_qf_locked;
39810- atomic_long_t mesq_qf_noop_not_full;
39811- atomic_long_t mesq_qf_switch_head_failed;
39812- atomic_long_t mesq_qf_unexpected_error;
39813- atomic_long_t mesq_noop_unexpected_error;
39814- atomic_long_t mesq_noop_lb_overflow;
39815- atomic_long_t mesq_noop_qlimit_reached;
39816- atomic_long_t mesq_noop_amo_nacked;
39817- atomic_long_t mesq_noop_put_nacked;
39818- atomic_long_t mesq_noop_page_overflow;
39819+ atomic_long_unchecked_t mesq_receive;
39820+ atomic_long_unchecked_t mesq_receive_none;
39821+ atomic_long_unchecked_t mesq_send;
39822+ atomic_long_unchecked_t mesq_send_failed;
39823+ atomic_long_unchecked_t mesq_noop;
39824+ atomic_long_unchecked_t mesq_send_unexpected_error;
39825+ atomic_long_unchecked_t mesq_send_lb_overflow;
39826+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39827+ atomic_long_unchecked_t mesq_send_amo_nacked;
39828+ atomic_long_unchecked_t mesq_send_put_nacked;
39829+ atomic_long_unchecked_t mesq_page_overflow;
39830+ atomic_long_unchecked_t mesq_qf_locked;
39831+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39832+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39833+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39834+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39835+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39836+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39837+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39838+ atomic_long_unchecked_t mesq_noop_put_nacked;
39839+ atomic_long_unchecked_t mesq_noop_page_overflow;
39840
39841 };
39842
39843@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39844 tghop_invalidate, mcsop_last};
39845
39846 struct mcs_op_statistic {
39847- atomic_long_t count;
39848- atomic_long_t total;
39849+ atomic_long_unchecked_t count;
39850+ atomic_long_unchecked_t total;
39851 unsigned long max;
39852 };
39853
39854@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39855
39856 #define STAT(id) do { \
39857 if (gru_options & OPT_STATS) \
39858- atomic_long_inc(&gru_stats.id); \
39859+ atomic_long_inc_unchecked(&gru_stats.id); \
39860 } while (0)
39861
39862 #ifdef CONFIG_SGI_GRU_DEBUG
39863diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39864index c862cd4..0d176fe 100644
39865--- a/drivers/misc/sgi-xp/xp.h
39866+++ b/drivers/misc/sgi-xp/xp.h
39867@@ -288,7 +288,7 @@ struct xpc_interface {
39868 xpc_notify_func, void *);
39869 void (*received) (short, int, void *);
39870 enum xp_retval (*partid_to_nasids) (short, void *);
39871-};
39872+} __no_const;
39873
39874 extern struct xpc_interface xpc_interface;
39875
39876diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39877index b94d5f7..7f494c5 100644
39878--- a/drivers/misc/sgi-xp/xpc.h
39879+++ b/drivers/misc/sgi-xp/xpc.h
39880@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39881 void (*received_payload) (struct xpc_channel *, void *);
39882 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39883 };
39884+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39885
39886 /* struct xpc_partition act_state values (for XPC HB) */
39887
39888@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39889 /* found in xpc_main.c */
39890 extern struct device *xpc_part;
39891 extern struct device *xpc_chan;
39892-extern struct xpc_arch_operations xpc_arch_ops;
39893+extern xpc_arch_operations_no_const xpc_arch_ops;
39894 extern int xpc_disengage_timelimit;
39895 extern int xpc_disengage_timedout;
39896 extern int xpc_activate_IRQ_rcvd;
39897diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39898index d971817..33bdca5 100644
39899--- a/drivers/misc/sgi-xp/xpc_main.c
39900+++ b/drivers/misc/sgi-xp/xpc_main.c
39901@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39902 .notifier_call = xpc_system_die,
39903 };
39904
39905-struct xpc_arch_operations xpc_arch_ops;
39906+xpc_arch_operations_no_const xpc_arch_ops;
39907
39908 /*
39909 * Timer function to enforce the timelimit on the partition disengage.
39910@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39911
39912 if (((die_args->trapnr == X86_TRAP_MF) ||
39913 (die_args->trapnr == X86_TRAP_XF)) &&
39914- !user_mode_vm(die_args->regs))
39915+ !user_mode(die_args->regs))
39916 xpc_die_deactivate();
39917
39918 break;
39919diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39920index 49f04bc..65660c2 100644
39921--- a/drivers/mmc/core/mmc_ops.c
39922+++ b/drivers/mmc/core/mmc_ops.c
39923@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39924 void *data_buf;
39925 int is_on_stack;
39926
39927- is_on_stack = object_is_on_stack(buf);
39928+ is_on_stack = object_starts_on_stack(buf);
39929 if (is_on_stack) {
39930 /*
39931 * dma onto stack is unsafe/nonportable, but callers to this
39932diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39933index 0b74189..818358f 100644
39934--- a/drivers/mmc/host/dw_mmc.h
39935+++ b/drivers/mmc/host/dw_mmc.h
39936@@ -202,5 +202,5 @@ struct dw_mci_drv_data {
39937 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
39938 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
39939 int (*parse_dt)(struct dw_mci *host);
39940-};
39941+} __do_const;
39942 #endif /* _DW_MMC_H_ */
39943diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39944index c6f6246..60760a8 100644
39945--- a/drivers/mmc/host/sdhci-s3c.c
39946+++ b/drivers/mmc/host/sdhci-s3c.c
39947@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39948 * we can use overriding functions instead of default.
39949 */
39950 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39951- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39952- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39953- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39954+ pax_open_kernel();
39955+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39956+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39957+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39958+ pax_close_kernel();
39959 }
39960
39961 /* It supports additional host capabilities if needed */
39962diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39963index 0c8bb6b..6f35deb 100644
39964--- a/drivers/mtd/nand/denali.c
39965+++ b/drivers/mtd/nand/denali.c
39966@@ -24,6 +24,7 @@
39967 #include <linux/slab.h>
39968 #include <linux/mtd/mtd.h>
39969 #include <linux/module.h>
39970+#include <linux/slab.h>
39971
39972 #include "denali.h"
39973
39974diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39975index 51b9d6a..52af9a7 100644
39976--- a/drivers/mtd/nftlmount.c
39977+++ b/drivers/mtd/nftlmount.c
39978@@ -24,6 +24,7 @@
39979 #include <asm/errno.h>
39980 #include <linux/delay.h>
39981 #include <linux/slab.h>
39982+#include <linux/sched.h>
39983 #include <linux/mtd/mtd.h>
39984 #include <linux/mtd/nand.h>
39985 #include <linux/mtd/nftl.h>
39986diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39987index f9d5615..99dd95f 100644
39988--- a/drivers/mtd/sm_ftl.c
39989+++ b/drivers/mtd/sm_ftl.c
39990@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39991 #define SM_CIS_VENDOR_OFFSET 0x59
39992 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39993 {
39994- struct attribute_group *attr_group;
39995+ attribute_group_no_const *attr_group;
39996 struct attribute **attributes;
39997 struct sm_sysfs_attribute *vendor_attribute;
39998
39999diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
40000index f975696..4597e21 100644
40001--- a/drivers/net/bonding/bond_main.c
40002+++ b/drivers/net/bonding/bond_main.c
40003@@ -4870,7 +4870,7 @@ static unsigned int bond_get_num_tx_queues(void)
40004 return tx_queues;
40005 }
40006
40007-static struct rtnl_link_ops bond_link_ops __read_mostly = {
40008+static struct rtnl_link_ops bond_link_ops = {
40009 .kind = "bond",
40010 .priv_size = sizeof(struct bonding),
40011 .setup = bond_setup,
40012@@ -4995,8 +4995,8 @@ static void __exit bonding_exit(void)
40013
40014 bond_destroy_debugfs();
40015
40016- rtnl_link_unregister(&bond_link_ops);
40017 unregister_pernet_subsys(&bond_net_ops);
40018+ rtnl_link_unregister(&bond_link_ops);
40019
40020 #ifdef CONFIG_NET_POLL_CONTROLLER
40021 /*
40022diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
40023index e1d2643..7f4133b 100644
40024--- a/drivers/net/ethernet/8390/ax88796.c
40025+++ b/drivers/net/ethernet/8390/ax88796.c
40026@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
40027 if (ax->plat->reg_offsets)
40028 ei_local->reg_offset = ax->plat->reg_offsets;
40029 else {
40030+ resource_size_t _mem_size = mem_size;
40031+ do_div(_mem_size, 0x18);
40032 ei_local->reg_offset = ax->reg_offsets;
40033 for (ret = 0; ret < 0x18; ret++)
40034- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
40035+ ax->reg_offsets[ret] = _mem_size * ret;
40036 }
40037
40038 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
40039diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
40040index 151675d..0139a9d 100644
40041--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
40042+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
40043@@ -1112,7 +1112,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
40044 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
40045 {
40046 /* RX_MODE controlling object */
40047- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
40048+ bnx2x_init_rx_mode_obj(bp);
40049
40050 /* multicast configuration controlling object */
40051 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
40052diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
40053index ce1a916..10b52b0 100644
40054--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
40055+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
40056@@ -960,6 +960,9 @@ static int bnx2x_set_dump(struct net_device *dev, struct ethtool_dump *val)
40057 struct bnx2x *bp = netdev_priv(dev);
40058
40059 /* Use the ethtool_dump "flag" field as the dump preset index */
40060+ if (val->flag < 1 || val->flag > DUMP_MAX_PRESETS)
40061+ return -EINVAL;
40062+
40063 bp->dump_preset_idx = val->flag;
40064 return 0;
40065 }
40066@@ -986,8 +989,6 @@ static int bnx2x_get_dump_data(struct net_device *dev,
40067 struct bnx2x *bp = netdev_priv(dev);
40068 struct dump_header dump_hdr = {0};
40069
40070- memset(p, 0, dump->len);
40071-
40072 /* Disable parity attentions as long as following dump may
40073 * cause false alarms by reading never written registers. We
40074 * will re-enable parity attentions right after the dump.
40075diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40076index b4c9dea..2a9927f 100644
40077--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40078+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40079@@ -11497,6 +11497,8 @@ static int bnx2x_init_bp(struct bnx2x *bp)
40080 bp->min_msix_vec_cnt = 2;
40081 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
40082
40083+ bp->dump_preset_idx = 1;
40084+
40085 return rc;
40086 }
40087
40088diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40089index 32a9609..0b1c53a 100644
40090--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40091+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40092@@ -2387,15 +2387,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
40093 return rc;
40094 }
40095
40096-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
40097- struct bnx2x_rx_mode_obj *o)
40098+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
40099 {
40100 if (CHIP_IS_E1x(bp)) {
40101- o->wait_comp = bnx2x_empty_rx_mode_wait;
40102- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
40103+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
40104+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
40105 } else {
40106- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
40107- o->config_rx_mode = bnx2x_set_rx_mode_e2;
40108+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
40109+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
40110 }
40111 }
40112
40113diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40114index 43c00bc..dd1d03d 100644
40115--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40116+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40117@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
40118
40119 /********************* RX MODE ****************/
40120
40121-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
40122- struct bnx2x_rx_mode_obj *o);
40123+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
40124
40125 /**
40126 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
40127diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
40128index ff6e30e..87e8452 100644
40129--- a/drivers/net/ethernet/broadcom/tg3.h
40130+++ b/drivers/net/ethernet/broadcom/tg3.h
40131@@ -147,6 +147,7 @@
40132 #define CHIPREV_ID_5750_A0 0x4000
40133 #define CHIPREV_ID_5750_A1 0x4001
40134 #define CHIPREV_ID_5750_A3 0x4003
40135+#define CHIPREV_ID_5750_C1 0x4201
40136 #define CHIPREV_ID_5750_C2 0x4202
40137 #define CHIPREV_ID_5752_A0_HW 0x5000
40138 #define CHIPREV_ID_5752_A0 0x6000
40139diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
40140index 71497e8..b650951 100644
40141--- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
40142+++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
40143@@ -3037,7 +3037,9 @@ static void t3_io_resume(struct pci_dev *pdev)
40144 CH_ALERT(adapter, "adapter recovering, PEX ERR 0x%x\n",
40145 t3_read_reg(adapter, A_PCIE_PEX_ERR));
40146
40147+ rtnl_lock();
40148 t3_resume_ports(adapter);
40149+ rtnl_unlock();
40150 }
40151
40152 static const struct pci_error_handlers t3_err_handler = {
40153diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40154index 8cffcdf..aadf043 100644
40155--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40156+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40157@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
40158 */
40159 struct l2t_skb_cb {
40160 arp_failure_handler_func arp_failure_handler;
40161-};
40162+} __no_const;
40163
40164 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
40165
40166diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
40167index 4c83003..2a2a5b9 100644
40168--- a/drivers/net/ethernet/dec/tulip/de4x5.c
40169+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
40170@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40171 for (i=0; i<ETH_ALEN; i++) {
40172 tmp.addr[i] = dev->dev_addr[i];
40173 }
40174- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
40175+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
40176 break;
40177
40178 case DE4X5_SET_HWADDR: /* Set the hardware address */
40179@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40180 spin_lock_irqsave(&lp->lock, flags);
40181 memcpy(&statbuf, &lp->pktStats, ioc->len);
40182 spin_unlock_irqrestore(&lp->lock, flags);
40183- if (copy_to_user(ioc->data, &statbuf, ioc->len))
40184+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
40185 return -EFAULT;
40186 break;
40187 }
40188diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
40189index a0b4be5..d8cb082 100644
40190--- a/drivers/net/ethernet/emulex/benet/be_main.c
40191+++ b/drivers/net/ethernet/emulex/benet/be_main.c
40192@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
40193
40194 if (wrapped)
40195 newacc += 65536;
40196- ACCESS_ONCE(*acc) = newacc;
40197+ ACCESS_ONCE_RW(*acc) = newacc;
40198 }
40199
40200 void populate_erx_stats(struct be_adapter *adapter,
40201diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
40202index 21b85fb..b49e5fc 100644
40203--- a/drivers/net/ethernet/faraday/ftgmac100.c
40204+++ b/drivers/net/ethernet/faraday/ftgmac100.c
40205@@ -31,6 +31,8 @@
40206 #include <linux/netdevice.h>
40207 #include <linux/phy.h>
40208 #include <linux/platform_device.h>
40209+#include <linux/interrupt.h>
40210+#include <linux/irqreturn.h>
40211 #include <net/ip.h>
40212
40213 #include "ftgmac100.h"
40214diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
40215index a6eda8d..935d273 100644
40216--- a/drivers/net/ethernet/faraday/ftmac100.c
40217+++ b/drivers/net/ethernet/faraday/ftmac100.c
40218@@ -31,6 +31,8 @@
40219 #include <linux/module.h>
40220 #include <linux/netdevice.h>
40221 #include <linux/platform_device.h>
40222+#include <linux/interrupt.h>
40223+#include <linux/irqreturn.h>
40224
40225 #include "ftmac100.h"
40226
40227diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40228index 331987d..3be1135 100644
40229--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40230+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40231@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
40232 }
40233
40234 /* update the base incval used to calculate frequency adjustment */
40235- ACCESS_ONCE(adapter->base_incval) = incval;
40236+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
40237 smp_mb();
40238
40239 /* need lock to prevent incorrect read while modifying cyclecounter */
40240diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40241index fbe5363..266b4e3 100644
40242--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
40243+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40244@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40245 struct __vxge_hw_fifo *fifo;
40246 struct vxge_hw_fifo_config *config;
40247 u32 txdl_size, txdl_per_memblock;
40248- struct vxge_hw_mempool_cbs fifo_mp_callback;
40249+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
40250+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
40251+ };
40252+
40253 struct __vxge_hw_virtualpath *vpath;
40254
40255 if ((vp == NULL) || (attr == NULL)) {
40256@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40257 goto exit;
40258 }
40259
40260- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
40261-
40262 fifo->mempool =
40263 __vxge_hw_mempool_create(vpath->hldev,
40264 fifo->config->memblock_size,
40265diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40266index 5e7fb1d..f8d1810 100644
40267--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40268+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40269@@ -1948,7 +1948,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
40270 op_mode = QLC_83XX_DEFAULT_OPMODE;
40271
40272 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
40273- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
40274+ pax_open_kernel();
40275+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
40276+ pax_close_kernel();
40277 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40278 } else {
40279 return -EIO;
40280diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40281index b0c3de9..fc5857e 100644
40282--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40283+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40284@@ -200,15 +200,21 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
40285 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
40286 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
40287 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40288- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
40289+ pax_open_kernel();
40290+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
40291+ pax_close_kernel();
40292 } else if (priv_level == QLCNIC_PRIV_FUNC) {
40293 ahw->op_mode = QLCNIC_PRIV_FUNC;
40294 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
40295- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
40296+ pax_open_kernel();
40297+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
40298+ pax_close_kernel();
40299 } else if (priv_level == QLCNIC_MGMT_FUNC) {
40300 ahw->op_mode = QLCNIC_MGMT_FUNC;
40301 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40302- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
40303+ pax_open_kernel();
40304+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
40305+ pax_close_kernel();
40306 } else {
40307 return -EIO;
40308 }
40309diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
40310index 393f961..d343034 100644
40311--- a/drivers/net/ethernet/realtek/r8169.c
40312+++ b/drivers/net/ethernet/realtek/r8169.c
40313@@ -753,22 +753,22 @@ struct rtl8169_private {
40314 struct mdio_ops {
40315 void (*write)(struct rtl8169_private *, int, int);
40316 int (*read)(struct rtl8169_private *, int);
40317- } mdio_ops;
40318+ } __no_const mdio_ops;
40319
40320 struct pll_power_ops {
40321 void (*down)(struct rtl8169_private *);
40322 void (*up)(struct rtl8169_private *);
40323- } pll_power_ops;
40324+ } __no_const pll_power_ops;
40325
40326 struct jumbo_ops {
40327 void (*enable)(struct rtl8169_private *);
40328 void (*disable)(struct rtl8169_private *);
40329- } jumbo_ops;
40330+ } __no_const jumbo_ops;
40331
40332 struct csi_ops {
40333 void (*write)(struct rtl8169_private *, int, int);
40334 u32 (*read)(struct rtl8169_private *, int);
40335- } csi_ops;
40336+ } __no_const csi_ops;
40337
40338 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
40339 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
40340diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
40341index 9a95abf..36df7f9 100644
40342--- a/drivers/net/ethernet/sfc/ptp.c
40343+++ b/drivers/net/ethernet/sfc/ptp.c
40344@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
40345 (u32)((u64)ptp->start.dma_addr >> 32));
40346
40347 /* Clear flag that signals MC ready */
40348- ACCESS_ONCE(*start) = 0;
40349+ ACCESS_ONCE_RW(*start) = 0;
40350 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
40351 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
40352
40353diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40354index 50617c5..b13724c 100644
40355--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40356+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40357@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
40358
40359 writel(value, ioaddr + MMC_CNTRL);
40360
40361- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40362- MMC_CNTRL, value);
40363+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40364+// MMC_CNTRL, value);
40365 }
40366
40367 /* To mask all all interrupts.*/
40368diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
40369index e6fe0d8..2b7d752 100644
40370--- a/drivers/net/hyperv/hyperv_net.h
40371+++ b/drivers/net/hyperv/hyperv_net.h
40372@@ -101,7 +101,7 @@ struct rndis_device {
40373
40374 enum rndis_device_state state;
40375 bool link_state;
40376- atomic_t new_req_id;
40377+ atomic_unchecked_t new_req_id;
40378
40379 spinlock_t request_lock;
40380 struct list_head req_list;
40381diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
40382index 0775f0a..d4fb316 100644
40383--- a/drivers/net/hyperv/rndis_filter.c
40384+++ b/drivers/net/hyperv/rndis_filter.c
40385@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
40386 * template
40387 */
40388 set = &rndis_msg->msg.set_req;
40389- set->req_id = atomic_inc_return(&dev->new_req_id);
40390+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40391
40392 /* Add to the request list */
40393 spin_lock_irqsave(&dev->request_lock, flags);
40394@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
40395
40396 /* Setup the rndis set */
40397 halt = &request->request_msg.msg.halt_req;
40398- halt->req_id = atomic_inc_return(&dev->new_req_id);
40399+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40400
40401 /* Ignore return since this msg is optional. */
40402 rndis_filter_send_request(dev, request);
40403diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
40404index bf0d55e..82bcfbd1 100644
40405--- a/drivers/net/ieee802154/fakehard.c
40406+++ b/drivers/net/ieee802154/fakehard.c
40407@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
40408 phy->transmit_power = 0xbf;
40409
40410 dev->netdev_ops = &fake_ops;
40411- dev->ml_priv = &fake_mlme;
40412+ dev->ml_priv = (void *)&fake_mlme;
40413
40414 priv = netdev_priv(dev);
40415 priv->phy = phy;
40416diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
40417index 6e91931..2b0ebe7 100644
40418--- a/drivers/net/macvlan.c
40419+++ b/drivers/net/macvlan.c
40420@@ -905,13 +905,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
40421 int macvlan_link_register(struct rtnl_link_ops *ops)
40422 {
40423 /* common fields */
40424- ops->priv_size = sizeof(struct macvlan_dev);
40425- ops->validate = macvlan_validate;
40426- ops->maxtype = IFLA_MACVLAN_MAX;
40427- ops->policy = macvlan_policy;
40428- ops->changelink = macvlan_changelink;
40429- ops->get_size = macvlan_get_size;
40430- ops->fill_info = macvlan_fill_info;
40431+ pax_open_kernel();
40432+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
40433+ *(void **)&ops->validate = macvlan_validate;
40434+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
40435+ *(const void **)&ops->policy = macvlan_policy;
40436+ *(void **)&ops->changelink = macvlan_changelink;
40437+ *(void **)&ops->get_size = macvlan_get_size;
40438+ *(void **)&ops->fill_info = macvlan_fill_info;
40439+ pax_close_kernel();
40440
40441 return rtnl_link_register(ops);
40442 };
40443@@ -967,7 +969,7 @@ static int macvlan_device_event(struct notifier_block *unused,
40444 return NOTIFY_DONE;
40445 }
40446
40447-static struct notifier_block macvlan_notifier_block __read_mostly = {
40448+static struct notifier_block macvlan_notifier_block = {
40449 .notifier_call = macvlan_device_event,
40450 };
40451
40452diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
40453index b6dd6a7..5c38a02 100644
40454--- a/drivers/net/macvtap.c
40455+++ b/drivers/net/macvtap.c
40456@@ -1094,7 +1094,7 @@ static int macvtap_device_event(struct notifier_block *unused,
40457 return NOTIFY_DONE;
40458 }
40459
40460-static struct notifier_block macvtap_notifier_block __read_mostly = {
40461+static struct notifier_block macvtap_notifier_block = {
40462 .notifier_call = macvtap_device_event,
40463 };
40464
40465diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
40466index daec9b0..6428fcb 100644
40467--- a/drivers/net/phy/mdio-bitbang.c
40468+++ b/drivers/net/phy/mdio-bitbang.c
40469@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
40470 struct mdiobb_ctrl *ctrl = bus->priv;
40471
40472 module_put(ctrl->ops->owner);
40473+ mdiobus_unregister(bus);
40474 mdiobus_free(bus);
40475 }
40476 EXPORT_SYMBOL(free_mdio_bitbang);
40477diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
40478index 72ff14b..11d442d 100644
40479--- a/drivers/net/ppp/ppp_generic.c
40480+++ b/drivers/net/ppp/ppp_generic.c
40481@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40482 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
40483 struct ppp_stats stats;
40484 struct ppp_comp_stats cstats;
40485- char *vers;
40486
40487 switch (cmd) {
40488 case SIOCGPPPSTATS:
40489@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40490 break;
40491
40492 case SIOCGPPPVER:
40493- vers = PPP_VERSION;
40494- if (copy_to_user(addr, vers, strlen(vers) + 1))
40495+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
40496 break;
40497 err = 0;
40498 break;
40499diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
40500index 1252d9c..80e660b 100644
40501--- a/drivers/net/slip/slhc.c
40502+++ b/drivers/net/slip/slhc.c
40503@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
40504 register struct tcphdr *thp;
40505 register struct iphdr *ip;
40506 register struct cstate *cs;
40507- int len, hdrlen;
40508+ long len, hdrlen;
40509 unsigned char *cp = icp;
40510
40511 /* We've got a compressed packet; read the change byte */
40512diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
40513index b305105..8ead6df 100644
40514--- a/drivers/net/team/team.c
40515+++ b/drivers/net/team/team.c
40516@@ -2682,7 +2682,7 @@ static int team_device_event(struct notifier_block *unused,
40517 return NOTIFY_DONE;
40518 }
40519
40520-static struct notifier_block team_notifier_block __read_mostly = {
40521+static struct notifier_block team_notifier_block = {
40522 .notifier_call = team_device_event,
40523 };
40524
40525diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40526index 9c61f87..213609e 100644
40527--- a/drivers/net/tun.c
40528+++ b/drivers/net/tun.c
40529@@ -1852,7 +1852,7 @@ unlock:
40530 }
40531
40532 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40533- unsigned long arg, int ifreq_len)
40534+ unsigned long arg, size_t ifreq_len)
40535 {
40536 struct tun_file *tfile = file->private_data;
40537 struct tun_struct *tun;
40538@@ -1864,6 +1864,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40539 int vnet_hdr_sz;
40540 int ret;
40541
40542+ if (ifreq_len > sizeof ifr)
40543+ return -EFAULT;
40544+
40545 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40546 if (copy_from_user(&ifr, argp, ifreq_len))
40547 return -EFAULT;
40548diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40549index cba1d46..f703766 100644
40550--- a/drivers/net/usb/hso.c
40551+++ b/drivers/net/usb/hso.c
40552@@ -71,7 +71,7 @@
40553 #include <asm/byteorder.h>
40554 #include <linux/serial_core.h>
40555 #include <linux/serial.h>
40556-
40557+#include <asm/local.h>
40558
40559 #define MOD_AUTHOR "Option Wireless"
40560 #define MOD_DESCRIPTION "USB High Speed Option driver"
40561@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40562 struct urb *urb;
40563
40564 urb = serial->rx_urb[0];
40565- if (serial->port.count > 0) {
40566+ if (atomic_read(&serial->port.count) > 0) {
40567 count = put_rxbuf_data(urb, serial);
40568 if (count == -1)
40569 return;
40570@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40571 DUMP1(urb->transfer_buffer, urb->actual_length);
40572
40573 /* Anyone listening? */
40574- if (serial->port.count == 0)
40575+ if (atomic_read(&serial->port.count) == 0)
40576 return;
40577
40578 if (status == 0) {
40579@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40580 tty_port_tty_set(&serial->port, tty);
40581
40582 /* check for port already opened, if not set the termios */
40583- serial->port.count++;
40584- if (serial->port.count == 1) {
40585+ if (atomic_inc_return(&serial->port.count) == 1) {
40586 serial->rx_state = RX_IDLE;
40587 /* Force default termio settings */
40588 _hso_serial_set_termios(tty, NULL);
40589@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40590 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40591 if (result) {
40592 hso_stop_serial_device(serial->parent);
40593- serial->port.count--;
40594+ atomic_dec(&serial->port.count);
40595 kref_put(&serial->parent->ref, hso_serial_ref_free);
40596 }
40597 } else {
40598@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40599
40600 /* reset the rts and dtr */
40601 /* do the actual close */
40602- serial->port.count--;
40603+ atomic_dec(&serial->port.count);
40604
40605- if (serial->port.count <= 0) {
40606- serial->port.count = 0;
40607+ if (atomic_read(&serial->port.count) <= 0) {
40608+ atomic_set(&serial->port.count, 0);
40609 tty_port_tty_set(&serial->port, NULL);
40610 if (!usb_gone)
40611 hso_stop_serial_device(serial->parent);
40612@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40613
40614 /* the actual setup */
40615 spin_lock_irqsave(&serial->serial_lock, flags);
40616- if (serial->port.count)
40617+ if (atomic_read(&serial->port.count))
40618 _hso_serial_set_termios(tty, old);
40619 else
40620 tty->termios = *old;
40621@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
40622 D1("Pending read interrupt on port %d\n", i);
40623 spin_lock(&serial->serial_lock);
40624 if (serial->rx_state == RX_IDLE &&
40625- serial->port.count > 0) {
40626+ atomic_read(&serial->port.count) > 0) {
40627 /* Setup and send a ctrl req read on
40628 * port i */
40629 if (!serial->rx_urb_filled[0]) {
40630@@ -3057,7 +3056,7 @@ static int hso_resume(struct usb_interface *iface)
40631 /* Start all serial ports */
40632 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
40633 if (serial_table[i] && (serial_table[i]->interface == iface)) {
40634- if (dev2ser(serial_table[i])->port.count) {
40635+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
40636 result =
40637 hso_start_serial_device(serial_table[i], GFP_NOIO);
40638 hso_kick_transmit(dev2ser(serial_table[i]));
40639diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
40640index 57325f3..36b181f 100644
40641--- a/drivers/net/vxlan.c
40642+++ b/drivers/net/vxlan.c
40643@@ -1579,7 +1579,7 @@ nla_put_failure:
40644 return -EMSGSIZE;
40645 }
40646
40647-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
40648+static struct rtnl_link_ops vxlan_link_ops = {
40649 .kind = "vxlan",
40650 .maxtype = IFLA_VXLAN_MAX,
40651 .policy = vxlan_policy,
40652diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
40653index 34c8a33..3261fdc 100644
40654--- a/drivers/net/wireless/at76c50x-usb.c
40655+++ b/drivers/net/wireless/at76c50x-usb.c
40656@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
40657 }
40658
40659 /* Convert timeout from the DFU status to jiffies */
40660-static inline unsigned long at76_get_timeout(struct dfu_status *s)
40661+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
40662 {
40663 return msecs_to_jiffies((s->poll_timeout[2] << 16)
40664 | (s->poll_timeout[1] << 8)
40665diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40666index 8d78253..bebbb68 100644
40667--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40668+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40669@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40670 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
40671 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
40672
40673- ACCESS_ONCE(ads->ds_link) = i->link;
40674- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
40675+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
40676+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
40677
40678 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
40679 ctl6 = SM(i->keytype, AR_EncrType);
40680@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40681
40682 if ((i->is_first || i->is_last) &&
40683 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
40684- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
40685+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
40686 | set11nTries(i->rates, 1)
40687 | set11nTries(i->rates, 2)
40688 | set11nTries(i->rates, 3)
40689 | (i->dur_update ? AR_DurUpdateEna : 0)
40690 | SM(0, AR_BurstDur);
40691
40692- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
40693+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
40694 | set11nRate(i->rates, 1)
40695 | set11nRate(i->rates, 2)
40696 | set11nRate(i->rates, 3);
40697 } else {
40698- ACCESS_ONCE(ads->ds_ctl2) = 0;
40699- ACCESS_ONCE(ads->ds_ctl3) = 0;
40700+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
40701+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
40702 }
40703
40704 if (!i->is_first) {
40705- ACCESS_ONCE(ads->ds_ctl0) = 0;
40706- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40707- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40708+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
40709+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40710+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40711 return;
40712 }
40713
40714@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40715 break;
40716 }
40717
40718- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40719+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40720 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40721 | SM(i->txpower, AR_XmitPower)
40722 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40723@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40724 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
40725 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
40726
40727- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40728- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40729+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40730+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40731
40732 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
40733 return;
40734
40735- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40736+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40737 | set11nPktDurRTSCTS(i->rates, 1);
40738
40739- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40740+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40741 | set11nPktDurRTSCTS(i->rates, 3);
40742
40743- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40744+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40745 | set11nRateFlags(i->rates, 1)
40746 | set11nRateFlags(i->rates, 2)
40747 | set11nRateFlags(i->rates, 3)
40748diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40749index 301bf72..3f5654f 100644
40750--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40751+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40752@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40753 (i->qcu << AR_TxQcuNum_S) | desc_len;
40754
40755 checksum += val;
40756- ACCESS_ONCE(ads->info) = val;
40757+ ACCESS_ONCE_RW(ads->info) = val;
40758
40759 checksum += i->link;
40760- ACCESS_ONCE(ads->link) = i->link;
40761+ ACCESS_ONCE_RW(ads->link) = i->link;
40762
40763 checksum += i->buf_addr[0];
40764- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
40765+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
40766 checksum += i->buf_addr[1];
40767- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
40768+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
40769 checksum += i->buf_addr[2];
40770- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
40771+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
40772 checksum += i->buf_addr[3];
40773- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
40774+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
40775
40776 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
40777- ACCESS_ONCE(ads->ctl3) = val;
40778+ ACCESS_ONCE_RW(ads->ctl3) = val;
40779 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
40780- ACCESS_ONCE(ads->ctl5) = val;
40781+ ACCESS_ONCE_RW(ads->ctl5) = val;
40782 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
40783- ACCESS_ONCE(ads->ctl7) = val;
40784+ ACCESS_ONCE_RW(ads->ctl7) = val;
40785 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
40786- ACCESS_ONCE(ads->ctl9) = val;
40787+ ACCESS_ONCE_RW(ads->ctl9) = val;
40788
40789 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
40790- ACCESS_ONCE(ads->ctl10) = checksum;
40791+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
40792
40793 if (i->is_first || i->is_last) {
40794- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
40795+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
40796 | set11nTries(i->rates, 1)
40797 | set11nTries(i->rates, 2)
40798 | set11nTries(i->rates, 3)
40799 | (i->dur_update ? AR_DurUpdateEna : 0)
40800 | SM(0, AR_BurstDur);
40801
40802- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
40803+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
40804 | set11nRate(i->rates, 1)
40805 | set11nRate(i->rates, 2)
40806 | set11nRate(i->rates, 3);
40807 } else {
40808- ACCESS_ONCE(ads->ctl13) = 0;
40809- ACCESS_ONCE(ads->ctl14) = 0;
40810+ ACCESS_ONCE_RW(ads->ctl13) = 0;
40811+ ACCESS_ONCE_RW(ads->ctl14) = 0;
40812 }
40813
40814 ads->ctl20 = 0;
40815@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40816
40817 ctl17 = SM(i->keytype, AR_EncrType);
40818 if (!i->is_first) {
40819- ACCESS_ONCE(ads->ctl11) = 0;
40820- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40821- ACCESS_ONCE(ads->ctl15) = 0;
40822- ACCESS_ONCE(ads->ctl16) = 0;
40823- ACCESS_ONCE(ads->ctl17) = ctl17;
40824- ACCESS_ONCE(ads->ctl18) = 0;
40825- ACCESS_ONCE(ads->ctl19) = 0;
40826+ ACCESS_ONCE_RW(ads->ctl11) = 0;
40827+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40828+ ACCESS_ONCE_RW(ads->ctl15) = 0;
40829+ ACCESS_ONCE_RW(ads->ctl16) = 0;
40830+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40831+ ACCESS_ONCE_RW(ads->ctl18) = 0;
40832+ ACCESS_ONCE_RW(ads->ctl19) = 0;
40833 return;
40834 }
40835
40836- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40837+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40838 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40839 | SM(i->txpower, AR_XmitPower)
40840 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40841@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40842 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
40843 ctl12 |= SM(val, AR_PAPRDChainMask);
40844
40845- ACCESS_ONCE(ads->ctl12) = ctl12;
40846- ACCESS_ONCE(ads->ctl17) = ctl17;
40847+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
40848+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40849
40850- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40851+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40852 | set11nPktDurRTSCTS(i->rates, 1);
40853
40854- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40855+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40856 | set11nPktDurRTSCTS(i->rates, 3);
40857
40858- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
40859+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
40860 | set11nRateFlags(i->rates, 1)
40861 | set11nRateFlags(i->rates, 2)
40862 | set11nRateFlags(i->rates, 3)
40863 | SM(i->rtscts_rate, AR_RTSCTSRate);
40864
40865- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
40866+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
40867 }
40868
40869 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
40870diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
40871index ae30343..a117806 100644
40872--- a/drivers/net/wireless/ath/ath9k/hw.h
40873+++ b/drivers/net/wireless/ath/ath9k/hw.h
40874@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
40875
40876 /* ANI */
40877 void (*ani_cache_ini_regs)(struct ath_hw *ah);
40878-};
40879+} __no_const;
40880
40881 /**
40882 * struct ath_spec_scan - parameters for Atheros spectral scan
40883@@ -721,7 +721,7 @@ struct ath_hw_ops {
40884 struct ath_spec_scan *param);
40885 void (*spectral_scan_trigger)(struct ath_hw *ah);
40886 void (*spectral_scan_wait)(struct ath_hw *ah);
40887-};
40888+} __no_const;
40889
40890 struct ath_nf_limits {
40891 s16 max;
40892diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40893index b37a582..680835d 100644
40894--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40895+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40896@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40897 */
40898 if (il3945_mod_params.disable_hw_scan) {
40899 D_INFO("Disabling hw_scan\n");
40900- il3945_mac_ops.hw_scan = NULL;
40901+ pax_open_kernel();
40902+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40903+ pax_close_kernel();
40904 }
40905
40906 D_INFO("*** LOAD DRIVER ***\n");
40907diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40908index d532948..a1cb592 100644
40909--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40910+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40911@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40912 {
40913 struct iwl_priv *priv = file->private_data;
40914 char buf[64];
40915- int buf_size;
40916+ size_t buf_size;
40917 u32 offset, len;
40918
40919 memset(buf, 0, sizeof(buf));
40920@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40921 struct iwl_priv *priv = file->private_data;
40922
40923 char buf[8];
40924- int buf_size;
40925+ size_t buf_size;
40926 u32 reset_flag;
40927
40928 memset(buf, 0, sizeof(buf));
40929@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40930 {
40931 struct iwl_priv *priv = file->private_data;
40932 char buf[8];
40933- int buf_size;
40934+ size_t buf_size;
40935 int ht40;
40936
40937 memset(buf, 0, sizeof(buf));
40938@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40939 {
40940 struct iwl_priv *priv = file->private_data;
40941 char buf[8];
40942- int buf_size;
40943+ size_t buf_size;
40944 int value;
40945
40946 memset(buf, 0, sizeof(buf));
40947@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40948 {
40949 struct iwl_priv *priv = file->private_data;
40950 char buf[8];
40951- int buf_size;
40952+ size_t buf_size;
40953 int clear;
40954
40955 memset(buf, 0, sizeof(buf));
40956@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40957 {
40958 struct iwl_priv *priv = file->private_data;
40959 char buf[8];
40960- int buf_size;
40961+ size_t buf_size;
40962 int trace;
40963
40964 memset(buf, 0, sizeof(buf));
40965@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40966 {
40967 struct iwl_priv *priv = file->private_data;
40968 char buf[8];
40969- int buf_size;
40970+ size_t buf_size;
40971 int missed;
40972
40973 memset(buf, 0, sizeof(buf));
40974@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40975
40976 struct iwl_priv *priv = file->private_data;
40977 char buf[8];
40978- int buf_size;
40979+ size_t buf_size;
40980 int plcp;
40981
40982 memset(buf, 0, sizeof(buf));
40983@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40984
40985 struct iwl_priv *priv = file->private_data;
40986 char buf[8];
40987- int buf_size;
40988+ size_t buf_size;
40989 int flush;
40990
40991 memset(buf, 0, sizeof(buf));
40992@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40993
40994 struct iwl_priv *priv = file->private_data;
40995 char buf[8];
40996- int buf_size;
40997+ size_t buf_size;
40998 int rts;
40999
41000 if (!priv->cfg->ht_params)
41001@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
41002 {
41003 struct iwl_priv *priv = file->private_data;
41004 char buf[8];
41005- int buf_size;
41006+ size_t buf_size;
41007
41008 memset(buf, 0, sizeof(buf));
41009 buf_size = min(count, sizeof(buf) - 1);
41010@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
41011 struct iwl_priv *priv = file->private_data;
41012 u32 event_log_flag;
41013 char buf[8];
41014- int buf_size;
41015+ size_t buf_size;
41016
41017 /* check that the interface is up */
41018 if (!iwl_is_ready(priv))
41019@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
41020 struct iwl_priv *priv = file->private_data;
41021 char buf[8];
41022 u32 calib_disabled;
41023- int buf_size;
41024+ size_t buf_size;
41025
41026 memset(buf, 0, sizeof(buf));
41027 buf_size = min(count, sizeof(buf) - 1);
41028diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
41029index 50ba0a4..29424e7 100644
41030--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
41031+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
41032@@ -1329,7 +1329,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
41033 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
41034
41035 char buf[8];
41036- int buf_size;
41037+ size_t buf_size;
41038 u32 reset_flag;
41039
41040 memset(buf, 0, sizeof(buf));
41041@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
41042 {
41043 struct iwl_trans *trans = file->private_data;
41044 char buf[8];
41045- int buf_size;
41046+ size_t buf_size;
41047 int csr;
41048
41049 memset(buf, 0, sizeof(buf));
41050diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
41051index cb34c78..9fec0dc 100644
41052--- a/drivers/net/wireless/mac80211_hwsim.c
41053+++ b/drivers/net/wireless/mac80211_hwsim.c
41054@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
41055
41056 if (channels > 1) {
41057 hwsim_if_comb.num_different_channels = channels;
41058- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
41059- mac80211_hwsim_ops.cancel_hw_scan =
41060- mac80211_hwsim_cancel_hw_scan;
41061- mac80211_hwsim_ops.sw_scan_start = NULL;
41062- mac80211_hwsim_ops.sw_scan_complete = NULL;
41063- mac80211_hwsim_ops.remain_on_channel =
41064- mac80211_hwsim_roc;
41065- mac80211_hwsim_ops.cancel_remain_on_channel =
41066- mac80211_hwsim_croc;
41067- mac80211_hwsim_ops.add_chanctx =
41068- mac80211_hwsim_add_chanctx;
41069- mac80211_hwsim_ops.remove_chanctx =
41070- mac80211_hwsim_remove_chanctx;
41071- mac80211_hwsim_ops.change_chanctx =
41072- mac80211_hwsim_change_chanctx;
41073- mac80211_hwsim_ops.assign_vif_chanctx =
41074- mac80211_hwsim_assign_vif_chanctx;
41075- mac80211_hwsim_ops.unassign_vif_chanctx =
41076- mac80211_hwsim_unassign_vif_chanctx;
41077+ pax_open_kernel();
41078+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
41079+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
41080+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
41081+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
41082+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
41083+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
41084+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
41085+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
41086+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
41087+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
41088+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
41089+ pax_close_kernel();
41090 }
41091
41092 spin_lock_init(&hwsim_radio_lock);
41093diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
41094index 8169a85..7fa3b47 100644
41095--- a/drivers/net/wireless/rndis_wlan.c
41096+++ b/drivers/net/wireless/rndis_wlan.c
41097@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
41098
41099 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
41100
41101- if (rts_threshold < 0 || rts_threshold > 2347)
41102+ if (rts_threshold > 2347)
41103 rts_threshold = 2347;
41104
41105 tmp = cpu_to_le32(rts_threshold);
41106diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
41107index 7510723..5ba37f5 100644
41108--- a/drivers/net/wireless/rt2x00/rt2x00.h
41109+++ b/drivers/net/wireless/rt2x00/rt2x00.h
41110@@ -386,7 +386,7 @@ struct rt2x00_intf {
41111 * for hardware which doesn't support hardware
41112 * sequence counting.
41113 */
41114- atomic_t seqno;
41115+ atomic_unchecked_t seqno;
41116 };
41117
41118 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
41119diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
41120index 2c12311..7b77f24 100644
41121--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
41122+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
41123@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
41124 * sequence counter given by mac80211.
41125 */
41126 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
41127- seqno = atomic_add_return(0x10, &intf->seqno);
41128+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
41129 else
41130- seqno = atomic_read(&intf->seqno);
41131+ seqno = atomic_read_unchecked(&intf->seqno);
41132
41133 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
41134 hdr->seq_ctrl |= cpu_to_le16(seqno);
41135diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
41136index e2b3d9c..67a5184 100644
41137--- a/drivers/net/wireless/ti/wl1251/sdio.c
41138+++ b/drivers/net/wireless/ti/wl1251/sdio.c
41139@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
41140
41141 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
41142
41143- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41144- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41145+ pax_open_kernel();
41146+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41147+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41148+ pax_close_kernel();
41149
41150 wl1251_info("using dedicated interrupt line");
41151 } else {
41152- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41153- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41154+ pax_open_kernel();
41155+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41156+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41157+ pax_close_kernel();
41158
41159 wl1251_info("using SDIO interrupt");
41160 }
41161diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
41162index 1c627da..69f7d17 100644
41163--- a/drivers/net/wireless/ti/wl12xx/main.c
41164+++ b/drivers/net/wireless/ti/wl12xx/main.c
41165@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41166 sizeof(wl->conf.mem));
41167
41168 /* read data preparation is only needed by wl127x */
41169- wl->ops->prepare_read = wl127x_prepare_read;
41170+ pax_open_kernel();
41171+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41172+ pax_close_kernel();
41173
41174 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
41175 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
41176@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41177 sizeof(wl->conf.mem));
41178
41179 /* read data preparation is only needed by wl127x */
41180- wl->ops->prepare_read = wl127x_prepare_read;
41181+ pax_open_kernel();
41182+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41183+ pax_close_kernel();
41184
41185 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
41186 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
41187diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
41188index 9fa692d..b31fee0 100644
41189--- a/drivers/net/wireless/ti/wl18xx/main.c
41190+++ b/drivers/net/wireless/ti/wl18xx/main.c
41191@@ -1687,8 +1687,10 @@ static int wl18xx_setup(struct wl1271 *wl)
41192 }
41193
41194 if (!checksum_param) {
41195- wl18xx_ops.set_rx_csum = NULL;
41196- wl18xx_ops.init_vif = NULL;
41197+ pax_open_kernel();
41198+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
41199+ *(void **)&wl18xx_ops.init_vif = NULL;
41200+ pax_close_kernel();
41201 }
41202
41203 /* Enable 11a Band only if we have 5G antennas */
41204diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
41205index 7ef0b4a..ff65c28 100644
41206--- a/drivers/net/wireless/zd1211rw/zd_usb.c
41207+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
41208@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
41209 {
41210 struct zd_usb *usb = urb->context;
41211 struct zd_usb_interrupt *intr = &usb->intr;
41212- int len;
41213+ unsigned int len;
41214 u16 int_num;
41215
41216 ZD_ASSERT(in_interrupt());
41217diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
41218index d93b2b6..ae50401 100644
41219--- a/drivers/oprofile/buffer_sync.c
41220+++ b/drivers/oprofile/buffer_sync.c
41221@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
41222 if (cookie == NO_COOKIE)
41223 offset = pc;
41224 if (cookie == INVALID_COOKIE) {
41225- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41226+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41227 offset = pc;
41228 }
41229 if (cookie != last_cookie) {
41230@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
41231 /* add userspace sample */
41232
41233 if (!mm) {
41234- atomic_inc(&oprofile_stats.sample_lost_no_mm);
41235+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
41236 return 0;
41237 }
41238
41239 cookie = lookup_dcookie(mm, s->eip, &offset);
41240
41241 if (cookie == INVALID_COOKIE) {
41242- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41243+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41244 return 0;
41245 }
41246
41247@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
41248 /* ignore backtraces if failed to add a sample */
41249 if (state == sb_bt_start) {
41250 state = sb_bt_ignore;
41251- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
41252+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
41253 }
41254 }
41255 release_mm(mm);
41256diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
41257index c0cc4e7..44d4e54 100644
41258--- a/drivers/oprofile/event_buffer.c
41259+++ b/drivers/oprofile/event_buffer.c
41260@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
41261 }
41262
41263 if (buffer_pos == buffer_size) {
41264- atomic_inc(&oprofile_stats.event_lost_overflow);
41265+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
41266 return;
41267 }
41268
41269diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
41270index ed2c3ec..deda85a 100644
41271--- a/drivers/oprofile/oprof.c
41272+++ b/drivers/oprofile/oprof.c
41273@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
41274 if (oprofile_ops.switch_events())
41275 return;
41276
41277- atomic_inc(&oprofile_stats.multiplex_counter);
41278+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
41279 start_switch_worker();
41280 }
41281
41282diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
41283index 84a208d..d61b0a1 100644
41284--- a/drivers/oprofile/oprofile_files.c
41285+++ b/drivers/oprofile/oprofile_files.c
41286@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
41287
41288 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
41289
41290-static ssize_t timeout_read(struct file *file, char __user *buf,
41291+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
41292 size_t count, loff_t *offset)
41293 {
41294 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
41295diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
41296index 917d28e..d62d981 100644
41297--- a/drivers/oprofile/oprofile_stats.c
41298+++ b/drivers/oprofile/oprofile_stats.c
41299@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
41300 cpu_buf->sample_invalid_eip = 0;
41301 }
41302
41303- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
41304- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
41305- atomic_set(&oprofile_stats.event_lost_overflow, 0);
41306- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
41307- atomic_set(&oprofile_stats.multiplex_counter, 0);
41308+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
41309+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
41310+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
41311+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
41312+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
41313 }
41314
41315
41316diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
41317index 38b6fc0..b5cbfce 100644
41318--- a/drivers/oprofile/oprofile_stats.h
41319+++ b/drivers/oprofile/oprofile_stats.h
41320@@ -13,11 +13,11 @@
41321 #include <linux/atomic.h>
41322
41323 struct oprofile_stat_struct {
41324- atomic_t sample_lost_no_mm;
41325- atomic_t sample_lost_no_mapping;
41326- atomic_t bt_lost_no_mapping;
41327- atomic_t event_lost_overflow;
41328- atomic_t multiplex_counter;
41329+ atomic_unchecked_t sample_lost_no_mm;
41330+ atomic_unchecked_t sample_lost_no_mapping;
41331+ atomic_unchecked_t bt_lost_no_mapping;
41332+ atomic_unchecked_t event_lost_overflow;
41333+ atomic_unchecked_t multiplex_counter;
41334 };
41335
41336 extern struct oprofile_stat_struct oprofile_stats;
41337diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
41338index 7c12d9c..558bf3bb 100644
41339--- a/drivers/oprofile/oprofilefs.c
41340+++ b/drivers/oprofile/oprofilefs.c
41341@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
41342
41343
41344 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
41345- char const *name, atomic_t *val)
41346+ char const *name, atomic_unchecked_t *val)
41347 {
41348 return __oprofilefs_create_file(sb, root, name,
41349 &atomic_ro_fops, 0444, val);
41350diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
41351index 93404f7..4a313d8 100644
41352--- a/drivers/oprofile/timer_int.c
41353+++ b/drivers/oprofile/timer_int.c
41354@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
41355 return NOTIFY_OK;
41356 }
41357
41358-static struct notifier_block __refdata oprofile_cpu_notifier = {
41359+static struct notifier_block oprofile_cpu_notifier = {
41360 .notifier_call = oprofile_cpu_notify,
41361 };
41362
41363diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
41364index 92ed045..62d39bd7 100644
41365--- a/drivers/parport/procfs.c
41366+++ b/drivers/parport/procfs.c
41367@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
41368
41369 *ppos += len;
41370
41371- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
41372+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
41373 }
41374
41375 #ifdef CONFIG_PARPORT_1284
41376@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
41377
41378 *ppos += len;
41379
41380- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
41381+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
41382 }
41383 #endif /* IEEE1284.3 support. */
41384
41385diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
41386index c35e8ad..fc33beb 100644
41387--- a/drivers/pci/hotplug/acpiphp_ibm.c
41388+++ b/drivers/pci/hotplug/acpiphp_ibm.c
41389@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
41390 goto init_cleanup;
41391 }
41392
41393- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41394+ pax_open_kernel();
41395+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41396+ pax_close_kernel();
41397 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
41398
41399 return retval;
41400diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
41401index a6a71c4..c91097b 100644
41402--- a/drivers/pci/hotplug/cpcihp_generic.c
41403+++ b/drivers/pci/hotplug/cpcihp_generic.c
41404@@ -73,7 +73,6 @@ static u16 port;
41405 static unsigned int enum_bit;
41406 static u8 enum_mask;
41407
41408-static struct cpci_hp_controller_ops generic_hpc_ops;
41409 static struct cpci_hp_controller generic_hpc;
41410
41411 static int __init validate_parameters(void)
41412@@ -139,6 +138,10 @@ static int query_enum(void)
41413 return ((value & enum_mask) == enum_mask);
41414 }
41415
41416+static struct cpci_hp_controller_ops generic_hpc_ops = {
41417+ .query_enum = query_enum,
41418+};
41419+
41420 static int __init cpcihp_generic_init(void)
41421 {
41422 int status;
41423@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
41424 pci_dev_put(dev);
41425
41426 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
41427- generic_hpc_ops.query_enum = query_enum;
41428 generic_hpc.ops = &generic_hpc_ops;
41429
41430 status = cpci_hp_register_controller(&generic_hpc);
41431diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
41432index 449b4bb..257e2e8 100644
41433--- a/drivers/pci/hotplug/cpcihp_zt5550.c
41434+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
41435@@ -59,7 +59,6 @@
41436 /* local variables */
41437 static bool debug;
41438 static bool poll;
41439-static struct cpci_hp_controller_ops zt5550_hpc_ops;
41440 static struct cpci_hp_controller zt5550_hpc;
41441
41442 /* Primary cPCI bus bridge device */
41443@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
41444 return 0;
41445 }
41446
41447+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
41448+ .query_enum = zt5550_hc_query_enum,
41449+};
41450+
41451 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
41452 {
41453 int status;
41454@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
41455 dbg("returned from zt5550_hc_config");
41456
41457 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
41458- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
41459 zt5550_hpc.ops = &zt5550_hpc_ops;
41460 if(!poll) {
41461 zt5550_hpc.irq = hc_dev->irq;
41462 zt5550_hpc.irq_flags = IRQF_SHARED;
41463 zt5550_hpc.dev_id = hc_dev;
41464
41465- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41466- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41467- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41468+ pax_open_kernel();
41469+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41470+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41471+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41472+ pax_open_kernel();
41473 } else {
41474 info("using ENUM# polling mode");
41475 }
41476diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
41477index 76ba8a1..20ca857 100644
41478--- a/drivers/pci/hotplug/cpqphp_nvram.c
41479+++ b/drivers/pci/hotplug/cpqphp_nvram.c
41480@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
41481
41482 void compaq_nvram_init (void __iomem *rom_start)
41483 {
41484+
41485+#ifndef CONFIG_PAX_KERNEXEC
41486 if (rom_start) {
41487 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
41488 }
41489+#endif
41490+
41491 dbg("int15 entry = %p\n", compaq_int15_entry_point);
41492
41493 /* initialize our int15 lock */
41494diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
41495index ec20f74..c1d961e 100644
41496--- a/drivers/pci/hotplug/pci_hotplug_core.c
41497+++ b/drivers/pci/hotplug/pci_hotplug_core.c
41498@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
41499 return -EINVAL;
41500 }
41501
41502- slot->ops->owner = owner;
41503- slot->ops->mod_name = mod_name;
41504+ pax_open_kernel();
41505+ *(struct module **)&slot->ops->owner = owner;
41506+ *(const char **)&slot->ops->mod_name = mod_name;
41507+ pax_close_kernel();
41508
41509 mutex_lock(&pci_hp_mutex);
41510 /*
41511diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
41512index 7d72c5e..edce02c 100644
41513--- a/drivers/pci/hotplug/pciehp_core.c
41514+++ b/drivers/pci/hotplug/pciehp_core.c
41515@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41516 struct slot *slot = ctrl->slot;
41517 struct hotplug_slot *hotplug = NULL;
41518 struct hotplug_slot_info *info = NULL;
41519- struct hotplug_slot_ops *ops = NULL;
41520+ hotplug_slot_ops_no_const *ops = NULL;
41521 char name[SLOT_NAME_SIZE];
41522 int retval = -ENOMEM;
41523
41524diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41525index 5b4a9d9..cd5ac1f 100644
41526--- a/drivers/pci/pci-sysfs.c
41527+++ b/drivers/pci/pci-sysfs.c
41528@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41529 {
41530 /* allocate attribute structure, piggyback attribute name */
41531 int name_len = write_combine ? 13 : 10;
41532- struct bin_attribute *res_attr;
41533+ bin_attribute_no_const *res_attr;
41534 int retval;
41535
41536 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41537@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41538 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41539 {
41540 int retval;
41541- struct bin_attribute *attr;
41542+ bin_attribute_no_const *attr;
41543
41544 /* If the device has VPD, try to expose it in sysfs. */
41545 if (dev->vpd) {
41546@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41547 {
41548 int retval;
41549 int rom_size = 0;
41550- struct bin_attribute *attr;
41551+ bin_attribute_no_const *attr;
41552
41553 if (!sysfs_initialized)
41554 return -EACCES;
41555diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41556index d1182c4..2a138ec 100644
41557--- a/drivers/pci/pci.h
41558+++ b/drivers/pci/pci.h
41559@@ -92,7 +92,7 @@ struct pci_vpd_ops {
41560 struct pci_vpd {
41561 unsigned int len;
41562 const struct pci_vpd_ops *ops;
41563- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41564+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41565 };
41566
41567 int pci_vpd_pci22_init(struct pci_dev *dev);
41568diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41569index d320df6..ca9a8f6 100644
41570--- a/drivers/pci/pcie/aspm.c
41571+++ b/drivers/pci/pcie/aspm.c
41572@@ -27,9 +27,9 @@
41573 #define MODULE_PARAM_PREFIX "pcie_aspm."
41574
41575 /* Note: those are not register definitions */
41576-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41577-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41578-#define ASPM_STATE_L1 (4) /* L1 state */
41579+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41580+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41581+#define ASPM_STATE_L1 (4U) /* L1 state */
41582 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41583 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41584
41585diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41586index ea37072..10e58e56 100644
41587--- a/drivers/pci/probe.c
41588+++ b/drivers/pci/probe.c
41589@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41590 struct pci_bus_region region;
41591 bool bar_too_big = false, bar_disabled = false;
41592
41593- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41594+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41595
41596 /* No printks while decoding is disabled! */
41597 if (!dev->mmio_always_on) {
41598diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41599index 0812608..b04018c4 100644
41600--- a/drivers/pci/proc.c
41601+++ b/drivers/pci/proc.c
41602@@ -453,7 +453,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41603 static int __init pci_proc_init(void)
41604 {
41605 struct pci_dev *dev = NULL;
41606+
41607+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41608+#ifdef CONFIG_GRKERNSEC_PROC_USER
41609+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41610+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41611+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41612+#endif
41613+#else
41614 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41615+#endif
41616 proc_create("devices", 0, proc_bus_pci_dir,
41617 &proc_bus_pci_dev_operations);
41618 proc_initialized = 1;
41619diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
41620index 3e5b4497..dcdfb70 100644
41621--- a/drivers/platform/x86/chromeos_laptop.c
41622+++ b/drivers/platform/x86/chromeos_laptop.c
41623@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
41624 return 0;
41625 }
41626
41627-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
41628+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
41629 {
41630 .ident = "Samsung Series 5 550 - Touchpad",
41631 .matches = {
41632diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41633index 6b22938..bc9700e 100644
41634--- a/drivers/platform/x86/msi-laptop.c
41635+++ b/drivers/platform/x86/msi-laptop.c
41636@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
41637
41638 if (!quirks->ec_read_only) {
41639 /* allow userland write sysfs file */
41640- dev_attr_bluetooth.store = store_bluetooth;
41641- dev_attr_wlan.store = store_wlan;
41642- dev_attr_threeg.store = store_threeg;
41643- dev_attr_bluetooth.attr.mode |= S_IWUSR;
41644- dev_attr_wlan.attr.mode |= S_IWUSR;
41645- dev_attr_threeg.attr.mode |= S_IWUSR;
41646+ pax_open_kernel();
41647+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
41648+ *(void **)&dev_attr_wlan.store = store_wlan;
41649+ *(void **)&dev_attr_threeg.store = store_threeg;
41650+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
41651+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
41652+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
41653+ pax_close_kernel();
41654 }
41655
41656 /* disable hardware control by fn key */
41657diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
41658index 2ac045f..39c443d 100644
41659--- a/drivers/platform/x86/sony-laptop.c
41660+++ b/drivers/platform/x86/sony-laptop.c
41661@@ -2483,7 +2483,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
41662 }
41663
41664 /* High speed charging function */
41665-static struct device_attribute *hsc_handle;
41666+static device_attribute_no_const *hsc_handle;
41667
41668 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
41669 struct device_attribute *attr,
41670diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
41671index 54d31c0..3f896d3 100644
41672--- a/drivers/platform/x86/thinkpad_acpi.c
41673+++ b/drivers/platform/x86/thinkpad_acpi.c
41674@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
41675 return 0;
41676 }
41677
41678-void static hotkey_mask_warn_incomplete_mask(void)
41679+static void hotkey_mask_warn_incomplete_mask(void)
41680 {
41681 /* log only what the user can fix... */
41682 const u32 wantedmask = hotkey_driver_mask &
41683@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
41684 }
41685 }
41686
41687-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41688- struct tp_nvram_state *newn,
41689- const u32 event_mask)
41690-{
41691-
41692 #define TPACPI_COMPARE_KEY(__scancode, __member) \
41693 do { \
41694 if ((event_mask & (1 << __scancode)) && \
41695@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41696 tpacpi_hotkey_send_key(__scancode); \
41697 } while (0)
41698
41699- void issue_volchange(const unsigned int oldvol,
41700- const unsigned int newvol)
41701- {
41702- unsigned int i = oldvol;
41703+static void issue_volchange(const unsigned int oldvol,
41704+ const unsigned int newvol,
41705+ const u32 event_mask)
41706+{
41707+ unsigned int i = oldvol;
41708
41709- while (i > newvol) {
41710- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41711- i--;
41712- }
41713- while (i < newvol) {
41714- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41715- i++;
41716- }
41717+ while (i > newvol) {
41718+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41719+ i--;
41720 }
41721+ while (i < newvol) {
41722+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41723+ i++;
41724+ }
41725+}
41726
41727- void issue_brightnesschange(const unsigned int oldbrt,
41728- const unsigned int newbrt)
41729- {
41730- unsigned int i = oldbrt;
41731+static void issue_brightnesschange(const unsigned int oldbrt,
41732+ const unsigned int newbrt,
41733+ const u32 event_mask)
41734+{
41735+ unsigned int i = oldbrt;
41736
41737- while (i > newbrt) {
41738- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41739- i--;
41740- }
41741- while (i < newbrt) {
41742- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41743- i++;
41744- }
41745+ while (i > newbrt) {
41746+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41747+ i--;
41748+ }
41749+ while (i < newbrt) {
41750+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41751+ i++;
41752 }
41753+}
41754
41755+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41756+ struct tp_nvram_state *newn,
41757+ const u32 event_mask)
41758+{
41759 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
41760 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
41761 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
41762@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41763 oldn->volume_level != newn->volume_level) {
41764 /* recently muted, or repeated mute keypress, or
41765 * multiple presses ending in mute */
41766- issue_volchange(oldn->volume_level, newn->volume_level);
41767+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41768 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
41769 }
41770 } else {
41771@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41772 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41773 }
41774 if (oldn->volume_level != newn->volume_level) {
41775- issue_volchange(oldn->volume_level, newn->volume_level);
41776+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41777 } else if (oldn->volume_toggle != newn->volume_toggle) {
41778 /* repeated vol up/down keypress at end of scale ? */
41779 if (newn->volume_level == 0)
41780@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41781 /* handle brightness */
41782 if (oldn->brightness_level != newn->brightness_level) {
41783 issue_brightnesschange(oldn->brightness_level,
41784- newn->brightness_level);
41785+ newn->brightness_level,
41786+ event_mask);
41787 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
41788 /* repeated key presses that didn't change state */
41789 if (newn->brightness_level == 0)
41790@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41791 && !tp_features.bright_unkfw)
41792 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41793 }
41794+}
41795
41796 #undef TPACPI_COMPARE_KEY
41797 #undef TPACPI_MAY_SEND_KEY
41798-}
41799
41800 /*
41801 * Polling driver
41802diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
41803index 769d265..a3a05ca 100644
41804--- a/drivers/pnp/pnpbios/bioscalls.c
41805+++ b/drivers/pnp/pnpbios/bioscalls.c
41806@@ -58,7 +58,7 @@ do { \
41807 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
41808 } while(0)
41809
41810-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
41811+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
41812 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
41813
41814 /*
41815@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41816
41817 cpu = get_cpu();
41818 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
41819+
41820+ pax_open_kernel();
41821 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
41822+ pax_close_kernel();
41823
41824 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
41825 spin_lock_irqsave(&pnp_bios_lock, flags);
41826@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41827 :"memory");
41828 spin_unlock_irqrestore(&pnp_bios_lock, flags);
41829
41830+ pax_open_kernel();
41831 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
41832+ pax_close_kernel();
41833+
41834 put_cpu();
41835
41836 /* If we get here and this is set then the PnP BIOS faulted on us. */
41837@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
41838 return status;
41839 }
41840
41841-void pnpbios_calls_init(union pnp_bios_install_struct *header)
41842+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
41843 {
41844 int i;
41845
41846@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41847 pnp_bios_callpoint.offset = header->fields.pm16offset;
41848 pnp_bios_callpoint.segment = PNP_CS16;
41849
41850+ pax_open_kernel();
41851+
41852 for_each_possible_cpu(i) {
41853 struct desc_struct *gdt = get_cpu_gdt_table(i);
41854 if (!gdt)
41855@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41856 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
41857 (unsigned long)__va(header->fields.pm16dseg));
41858 }
41859+
41860+ pax_close_kernel();
41861 }
41862diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
41863index 3e6db1c..1fbbdae 100644
41864--- a/drivers/pnp/resource.c
41865+++ b/drivers/pnp/resource.c
41866@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
41867 return 1;
41868
41869 /* check if the resource is valid */
41870- if (*irq < 0 || *irq > 15)
41871+ if (*irq > 15)
41872 return 0;
41873
41874 /* check if the resource is reserved */
41875@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
41876 return 1;
41877
41878 /* check if the resource is valid */
41879- if (*dma < 0 || *dma == 4 || *dma > 7)
41880+ if (*dma == 4 || *dma > 7)
41881 return 0;
41882
41883 /* check if the resource is reserved */
41884diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
41885index 0c52e2a..3421ab7 100644
41886--- a/drivers/power/pda_power.c
41887+++ b/drivers/power/pda_power.c
41888@@ -37,7 +37,11 @@ static int polling;
41889
41890 #if IS_ENABLED(CONFIG_USB_PHY)
41891 static struct usb_phy *transceiver;
41892-static struct notifier_block otg_nb;
41893+static int otg_handle_notification(struct notifier_block *nb,
41894+ unsigned long event, void *unused);
41895+static struct notifier_block otg_nb = {
41896+ .notifier_call = otg_handle_notification
41897+};
41898 #endif
41899
41900 static struct regulator *ac_draw;
41901@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
41902
41903 #if IS_ENABLED(CONFIG_USB_PHY)
41904 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41905- otg_nb.notifier_call = otg_handle_notification;
41906 ret = usb_register_notifier(transceiver, &otg_nb);
41907 if (ret) {
41908 dev_err(dev, "failure to register otg notifier\n");
41909diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41910index cc439fd..8fa30df 100644
41911--- a/drivers/power/power_supply.h
41912+++ b/drivers/power/power_supply.h
41913@@ -16,12 +16,12 @@ struct power_supply;
41914
41915 #ifdef CONFIG_SYSFS
41916
41917-extern void power_supply_init_attrs(struct device_type *dev_type);
41918+extern void power_supply_init_attrs(void);
41919 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41920
41921 #else
41922
41923-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41924+static inline void power_supply_init_attrs(void) {}
41925 #define power_supply_uevent NULL
41926
41927 #endif /* CONFIG_SYSFS */
41928diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41929index 1c517c3..ffa2f17 100644
41930--- a/drivers/power/power_supply_core.c
41931+++ b/drivers/power/power_supply_core.c
41932@@ -24,7 +24,10 @@
41933 struct class *power_supply_class;
41934 EXPORT_SYMBOL_GPL(power_supply_class);
41935
41936-static struct device_type power_supply_dev_type;
41937+extern const struct attribute_group *power_supply_attr_groups[];
41938+static struct device_type power_supply_dev_type = {
41939+ .groups = power_supply_attr_groups,
41940+};
41941
41942 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
41943 struct power_supply *supply)
41944@@ -554,7 +557,7 @@ static int __init power_supply_class_init(void)
41945 return PTR_ERR(power_supply_class);
41946
41947 power_supply_class->dev_uevent = power_supply_uevent;
41948- power_supply_init_attrs(&power_supply_dev_type);
41949+ power_supply_init_attrs();
41950
41951 return 0;
41952 }
41953diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41954index 29178f7..c65f324 100644
41955--- a/drivers/power/power_supply_sysfs.c
41956+++ b/drivers/power/power_supply_sysfs.c
41957@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
41958 .is_visible = power_supply_attr_is_visible,
41959 };
41960
41961-static const struct attribute_group *power_supply_attr_groups[] = {
41962+const struct attribute_group *power_supply_attr_groups[] = {
41963 &power_supply_attr_group,
41964 NULL,
41965 };
41966
41967-void power_supply_init_attrs(struct device_type *dev_type)
41968+void power_supply_init_attrs(void)
41969 {
41970 int i;
41971
41972- dev_type->groups = power_supply_attr_groups;
41973-
41974 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41975 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41976 }
41977diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41978index d428ef9..fdc0357 100644
41979--- a/drivers/regulator/max8660.c
41980+++ b/drivers/regulator/max8660.c
41981@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41982 max8660->shadow_regs[MAX8660_OVER1] = 5;
41983 } else {
41984 /* Otherwise devices can be toggled via software */
41985- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41986- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41987+ pax_open_kernel();
41988+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41989+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41990+ pax_close_kernel();
41991 }
41992
41993 /*
41994diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41995index adb1414..c13e0ce 100644
41996--- a/drivers/regulator/max8973-regulator.c
41997+++ b/drivers/regulator/max8973-regulator.c
41998@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41999 if (!pdata->enable_ext_control) {
42000 max->desc.enable_reg = MAX8973_VOUT;
42001 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
42002- max8973_dcdc_ops.enable = regulator_enable_regmap;
42003- max8973_dcdc_ops.disable = regulator_disable_regmap;
42004- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
42005+ pax_open_kernel();
42006+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
42007+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
42008+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
42009+ pax_close_kernel();
42010 }
42011
42012 max->enable_external_control = pdata->enable_ext_control;
42013diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
42014index b716283..3cc4349 100644
42015--- a/drivers/regulator/mc13892-regulator.c
42016+++ b/drivers/regulator/mc13892-regulator.c
42017@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
42018 }
42019 mc13xxx_unlock(mc13892);
42020
42021- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
42022+ pax_open_kernel();
42023+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
42024 = mc13892_vcam_set_mode;
42025- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
42026+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
42027 = mc13892_vcam_get_mode;
42028+ pax_close_kernel();
42029
42030 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
42031 ARRAY_SIZE(mc13892_regulators));
42032diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
42033index f1cb706..4c7832a 100644
42034--- a/drivers/rtc/rtc-cmos.c
42035+++ b/drivers/rtc/rtc-cmos.c
42036@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
42037 hpet_rtc_timer_init();
42038
42039 /* export at least the first block of NVRAM */
42040- nvram.size = address_space - NVRAM_OFFSET;
42041+ pax_open_kernel();
42042+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
42043+ pax_close_kernel();
42044 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
42045 if (retval < 0) {
42046 dev_dbg(dev, "can't create nvram file? %d\n", retval);
42047diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
42048index d049393..bb20be0 100644
42049--- a/drivers/rtc/rtc-dev.c
42050+++ b/drivers/rtc/rtc-dev.c
42051@@ -16,6 +16,7 @@
42052 #include <linux/module.h>
42053 #include <linux/rtc.h>
42054 #include <linux/sched.h>
42055+#include <linux/grsecurity.h>
42056 #include "rtc-core.h"
42057
42058 static dev_t rtc_devt;
42059@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
42060 if (copy_from_user(&tm, uarg, sizeof(tm)))
42061 return -EFAULT;
42062
42063+ gr_log_timechange();
42064+
42065 return rtc_set_time(rtc, &tm);
42066
42067 case RTC_PIE_ON:
42068diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
42069index b53992a..776df84 100644
42070--- a/drivers/rtc/rtc-ds1307.c
42071+++ b/drivers/rtc/rtc-ds1307.c
42072@@ -107,7 +107,7 @@ struct ds1307 {
42073 u8 offset; /* register's offset */
42074 u8 regs[11];
42075 u16 nvram_offset;
42076- struct bin_attribute *nvram;
42077+ bin_attribute_no_const *nvram;
42078 enum ds_type type;
42079 unsigned long flags;
42080 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
42081diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
42082index 130f29a..6179d03 100644
42083--- a/drivers/rtc/rtc-m48t59.c
42084+++ b/drivers/rtc/rtc-m48t59.c
42085@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
42086 goto out;
42087 }
42088
42089- m48t59_nvram_attr.size = pdata->offset;
42090+ pax_open_kernel();
42091+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
42092+ pax_close_kernel();
42093
42094 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
42095 if (ret) {
42096diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
42097index e693af6..2e525b6 100644
42098--- a/drivers/scsi/bfa/bfa_fcpim.h
42099+++ b/drivers/scsi/bfa/bfa_fcpim.h
42100@@ -36,7 +36,7 @@ struct bfa_iotag_s {
42101
42102 struct bfa_itn_s {
42103 bfa_isr_func_t isr;
42104-};
42105+} __no_const;
42106
42107 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
42108 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
42109diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
42110index 23a90e7..9cf04ee 100644
42111--- a/drivers/scsi/bfa/bfa_ioc.h
42112+++ b/drivers/scsi/bfa/bfa_ioc.h
42113@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
42114 bfa_ioc_disable_cbfn_t disable_cbfn;
42115 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
42116 bfa_ioc_reset_cbfn_t reset_cbfn;
42117-};
42118+} __no_const;
42119
42120 /*
42121 * IOC event notification mechanism.
42122@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
42123 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
42124 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
42125 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
42126-};
42127+} __no_const;
42128
42129 /*
42130 * Queue element to wait for room in request queue. FIFO order is
42131diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
42132index df0c3c7..b00e1d0 100644
42133--- a/drivers/scsi/hosts.c
42134+++ b/drivers/scsi/hosts.c
42135@@ -42,7 +42,7 @@
42136 #include "scsi_logging.h"
42137
42138
42139-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42140+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42141
42142
42143 static void scsi_host_cls_release(struct device *dev)
42144@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
42145 * subtract one because we increment first then return, but we need to
42146 * know what the next host number was before increment
42147 */
42148- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
42149+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
42150 shost->dma_channel = 0xff;
42151
42152 /* These three are default values which can be overridden */
42153diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
42154index 7f4f790..b75b92a 100644
42155--- a/drivers/scsi/hpsa.c
42156+++ b/drivers/scsi/hpsa.c
42157@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
42158 unsigned long flags;
42159
42160 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
42161- return h->access.command_completed(h, q);
42162+ return h->access->command_completed(h, q);
42163
42164 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
42165 a = rq->head[rq->current_entry];
42166@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
42167 while (!list_empty(&h->reqQ)) {
42168 c = list_entry(h->reqQ.next, struct CommandList, list);
42169 /* can't do anything if fifo is full */
42170- if ((h->access.fifo_full(h))) {
42171+ if ((h->access->fifo_full(h))) {
42172 dev_warn(&h->pdev->dev, "fifo full\n");
42173 break;
42174 }
42175@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
42176
42177 /* Tell the controller execute command */
42178 spin_unlock_irqrestore(&h->lock, flags);
42179- h->access.submit_command(h, c);
42180+ h->access->submit_command(h, c);
42181 spin_lock_irqsave(&h->lock, flags);
42182 }
42183 spin_unlock_irqrestore(&h->lock, flags);
42184@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
42185
42186 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
42187 {
42188- return h->access.command_completed(h, q);
42189+ return h->access->command_completed(h, q);
42190 }
42191
42192 static inline bool interrupt_pending(struct ctlr_info *h)
42193 {
42194- return h->access.intr_pending(h);
42195+ return h->access->intr_pending(h);
42196 }
42197
42198 static inline long interrupt_not_for_us(struct ctlr_info *h)
42199 {
42200- return (h->access.intr_pending(h) == 0) ||
42201+ return (h->access->intr_pending(h) == 0) ||
42202 (h->interrupts_enabled == 0);
42203 }
42204
42205@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
42206 if (prod_index < 0)
42207 return -ENODEV;
42208 h->product_name = products[prod_index].product_name;
42209- h->access = *(products[prod_index].access);
42210+ h->access = products[prod_index].access;
42211
42212 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
42213 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
42214@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
42215
42216 assert_spin_locked(&lockup_detector_lock);
42217 remove_ctlr_from_lockup_detector_list(h);
42218- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42219+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42220 spin_lock_irqsave(&h->lock, flags);
42221 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
42222 spin_unlock_irqrestore(&h->lock, flags);
42223@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
42224 }
42225
42226 /* make sure the board interrupts are off */
42227- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42228+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42229
42230 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
42231 goto clean2;
42232@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
42233 * fake ones to scoop up any residual completions.
42234 */
42235 spin_lock_irqsave(&h->lock, flags);
42236- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42237+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42238 spin_unlock_irqrestore(&h->lock, flags);
42239 free_irqs(h);
42240 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
42241@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
42242 dev_info(&h->pdev->dev, "Board READY.\n");
42243 dev_info(&h->pdev->dev,
42244 "Waiting for stale completions to drain.\n");
42245- h->access.set_intr_mask(h, HPSA_INTR_ON);
42246+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42247 msleep(10000);
42248- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42249+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42250
42251 rc = controller_reset_failed(h->cfgtable);
42252 if (rc)
42253@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
42254 }
42255
42256 /* Turn the interrupts on so we can service requests */
42257- h->access.set_intr_mask(h, HPSA_INTR_ON);
42258+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42259
42260 hpsa_hba_inquiry(h);
42261 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
42262@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
42263 * To write all data in the battery backed cache to disks
42264 */
42265 hpsa_flush_cache(h);
42266- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42267+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42268 hpsa_free_irqs_and_disable_msix(h);
42269 }
42270
42271@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
42272 return;
42273 }
42274 /* Change the access methods to the performant access methods */
42275- h->access = SA5_performant_access;
42276+ h->access = &SA5_performant_access;
42277 h->transMethod = CFGTBL_Trans_Performant;
42278 }
42279
42280diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
42281index 9816479..c5d4e97 100644
42282--- a/drivers/scsi/hpsa.h
42283+++ b/drivers/scsi/hpsa.h
42284@@ -79,7 +79,7 @@ struct ctlr_info {
42285 unsigned int msix_vector;
42286 unsigned int msi_vector;
42287 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
42288- struct access_method access;
42289+ struct access_method *access;
42290
42291 /* queue and queue Info */
42292 struct list_head reqQ;
42293diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
42294index 8b928c6..9c76300 100644
42295--- a/drivers/scsi/libfc/fc_exch.c
42296+++ b/drivers/scsi/libfc/fc_exch.c
42297@@ -100,12 +100,12 @@ struct fc_exch_mgr {
42298 u16 pool_max_index;
42299
42300 struct {
42301- atomic_t no_free_exch;
42302- atomic_t no_free_exch_xid;
42303- atomic_t xid_not_found;
42304- atomic_t xid_busy;
42305- atomic_t seq_not_found;
42306- atomic_t non_bls_resp;
42307+ atomic_unchecked_t no_free_exch;
42308+ atomic_unchecked_t no_free_exch_xid;
42309+ atomic_unchecked_t xid_not_found;
42310+ atomic_unchecked_t xid_busy;
42311+ atomic_unchecked_t seq_not_found;
42312+ atomic_unchecked_t non_bls_resp;
42313 } stats;
42314 };
42315
42316@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
42317 /* allocate memory for exchange */
42318 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
42319 if (!ep) {
42320- atomic_inc(&mp->stats.no_free_exch);
42321+ atomic_inc_unchecked(&mp->stats.no_free_exch);
42322 goto out;
42323 }
42324 memset(ep, 0, sizeof(*ep));
42325@@ -797,7 +797,7 @@ out:
42326 return ep;
42327 err:
42328 spin_unlock_bh(&pool->lock);
42329- atomic_inc(&mp->stats.no_free_exch_xid);
42330+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
42331 mempool_free(ep, mp->ep_pool);
42332 return NULL;
42333 }
42334@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42335 xid = ntohs(fh->fh_ox_id); /* we originated exch */
42336 ep = fc_exch_find(mp, xid);
42337 if (!ep) {
42338- atomic_inc(&mp->stats.xid_not_found);
42339+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42340 reject = FC_RJT_OX_ID;
42341 goto out;
42342 }
42343@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42344 ep = fc_exch_find(mp, xid);
42345 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
42346 if (ep) {
42347- atomic_inc(&mp->stats.xid_busy);
42348+ atomic_inc_unchecked(&mp->stats.xid_busy);
42349 reject = FC_RJT_RX_ID;
42350 goto rel;
42351 }
42352@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42353 }
42354 xid = ep->xid; /* get our XID */
42355 } else if (!ep) {
42356- atomic_inc(&mp->stats.xid_not_found);
42357+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42358 reject = FC_RJT_RX_ID; /* XID not found */
42359 goto out;
42360 }
42361@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42362 } else {
42363 sp = &ep->seq;
42364 if (sp->id != fh->fh_seq_id) {
42365- atomic_inc(&mp->stats.seq_not_found);
42366+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42367 if (f_ctl & FC_FC_END_SEQ) {
42368 /*
42369 * Update sequence_id based on incoming last
42370@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42371
42372 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
42373 if (!ep) {
42374- atomic_inc(&mp->stats.xid_not_found);
42375+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42376 goto out;
42377 }
42378 if (ep->esb_stat & ESB_ST_COMPLETE) {
42379- atomic_inc(&mp->stats.xid_not_found);
42380+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42381 goto rel;
42382 }
42383 if (ep->rxid == FC_XID_UNKNOWN)
42384 ep->rxid = ntohs(fh->fh_rx_id);
42385 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
42386- atomic_inc(&mp->stats.xid_not_found);
42387+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42388 goto rel;
42389 }
42390 if (ep->did != ntoh24(fh->fh_s_id) &&
42391 ep->did != FC_FID_FLOGI) {
42392- atomic_inc(&mp->stats.xid_not_found);
42393+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42394 goto rel;
42395 }
42396 sof = fr_sof(fp);
42397@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42398 sp->ssb_stat |= SSB_ST_RESP;
42399 sp->id = fh->fh_seq_id;
42400 } else if (sp->id != fh->fh_seq_id) {
42401- atomic_inc(&mp->stats.seq_not_found);
42402+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42403 goto rel;
42404 }
42405
42406@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42407 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
42408
42409 if (!sp)
42410- atomic_inc(&mp->stats.xid_not_found);
42411+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42412 else
42413- atomic_inc(&mp->stats.non_bls_resp);
42414+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
42415
42416 fc_frame_free(fp);
42417 }
42418@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
42419
42420 list_for_each_entry(ema, &lport->ema_list, ema_list) {
42421 mp = ema->mp;
42422- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
42423+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
42424 st->fc_no_free_exch_xid +=
42425- atomic_read(&mp->stats.no_free_exch_xid);
42426- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
42427- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
42428- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
42429- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
42430+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
42431+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
42432+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
42433+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
42434+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
42435 }
42436 }
42437 EXPORT_SYMBOL(fc_exch_update_stats);
42438diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
42439index 161c98e..6d563b3 100644
42440--- a/drivers/scsi/libsas/sas_ata.c
42441+++ b/drivers/scsi/libsas/sas_ata.c
42442@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
42443 .postreset = ata_std_postreset,
42444 .error_handler = ata_std_error_handler,
42445 .post_internal_cmd = sas_ata_post_internal,
42446- .qc_defer = ata_std_qc_defer,
42447+ .qc_defer = ata_std_qc_defer,
42448 .qc_prep = ata_noop_qc_prep,
42449 .qc_issue = sas_ata_qc_issue,
42450 .qc_fill_rtf = sas_ata_qc_fill_rtf,
42451diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
42452index bcc56ca..6f4174a 100644
42453--- a/drivers/scsi/lpfc/lpfc.h
42454+++ b/drivers/scsi/lpfc/lpfc.h
42455@@ -431,7 +431,7 @@ struct lpfc_vport {
42456 struct dentry *debug_nodelist;
42457 struct dentry *vport_debugfs_root;
42458 struct lpfc_debugfs_trc *disc_trc;
42459- atomic_t disc_trc_cnt;
42460+ atomic_unchecked_t disc_trc_cnt;
42461 #endif
42462 uint8_t stat_data_enabled;
42463 uint8_t stat_data_blocked;
42464@@ -865,8 +865,8 @@ struct lpfc_hba {
42465 struct timer_list fabric_block_timer;
42466 unsigned long bit_flags;
42467 #define FABRIC_COMANDS_BLOCKED 0
42468- atomic_t num_rsrc_err;
42469- atomic_t num_cmd_success;
42470+ atomic_unchecked_t num_rsrc_err;
42471+ atomic_unchecked_t num_cmd_success;
42472 unsigned long last_rsrc_error_time;
42473 unsigned long last_ramp_down_time;
42474 unsigned long last_ramp_up_time;
42475@@ -902,7 +902,7 @@ struct lpfc_hba {
42476
42477 struct dentry *debug_slow_ring_trc;
42478 struct lpfc_debugfs_trc *slow_ring_trc;
42479- atomic_t slow_ring_trc_cnt;
42480+ atomic_unchecked_t slow_ring_trc_cnt;
42481 /* iDiag debugfs sub-directory */
42482 struct dentry *idiag_root;
42483 struct dentry *idiag_pci_cfg;
42484diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
42485index f525ecb..32549a4 100644
42486--- a/drivers/scsi/lpfc/lpfc_debugfs.c
42487+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
42488@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
42489
42490 #include <linux/debugfs.h>
42491
42492-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42493+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42494 static unsigned long lpfc_debugfs_start_time = 0L;
42495
42496 /* iDiag */
42497@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
42498 lpfc_debugfs_enable = 0;
42499
42500 len = 0;
42501- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
42502+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
42503 (lpfc_debugfs_max_disc_trc - 1);
42504 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
42505 dtp = vport->disc_trc + i;
42506@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
42507 lpfc_debugfs_enable = 0;
42508
42509 len = 0;
42510- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
42511+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
42512 (lpfc_debugfs_max_slow_ring_trc - 1);
42513 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
42514 dtp = phba->slow_ring_trc + i;
42515@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42516 !vport || !vport->disc_trc)
42517 return;
42518
42519- index = atomic_inc_return(&vport->disc_trc_cnt) &
42520+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42521 (lpfc_debugfs_max_disc_trc - 1);
42522 dtp = vport->disc_trc + index;
42523 dtp->fmt = fmt;
42524 dtp->data1 = data1;
42525 dtp->data2 = data2;
42526 dtp->data3 = data3;
42527- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42528+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42529 dtp->jif = jiffies;
42530 #endif
42531 return;
42532@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42533 !phba || !phba->slow_ring_trc)
42534 return;
42535
42536- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42537+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42538 (lpfc_debugfs_max_slow_ring_trc - 1);
42539 dtp = phba->slow_ring_trc + index;
42540 dtp->fmt = fmt;
42541 dtp->data1 = data1;
42542 dtp->data2 = data2;
42543 dtp->data3 = data3;
42544- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42545+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42546 dtp->jif = jiffies;
42547 #endif
42548 return;
42549@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42550 "slow_ring buffer\n");
42551 goto debug_failed;
42552 }
42553- atomic_set(&phba->slow_ring_trc_cnt, 0);
42554+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42555 memset(phba->slow_ring_trc, 0,
42556 (sizeof(struct lpfc_debugfs_trc) *
42557 lpfc_debugfs_max_slow_ring_trc));
42558@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42559 "buffer\n");
42560 goto debug_failed;
42561 }
42562- atomic_set(&vport->disc_trc_cnt, 0);
42563+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42564
42565 snprintf(name, sizeof(name), "discovery_trace");
42566 vport->debug_disc_trc =
42567diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42568index cb465b2..2e7b25f 100644
42569--- a/drivers/scsi/lpfc/lpfc_init.c
42570+++ b/drivers/scsi/lpfc/lpfc_init.c
42571@@ -10950,8 +10950,10 @@ lpfc_init(void)
42572 "misc_register returned with status %d", error);
42573
42574 if (lpfc_enable_npiv) {
42575- lpfc_transport_functions.vport_create = lpfc_vport_create;
42576- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42577+ pax_open_kernel();
42578+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42579+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42580+ pax_close_kernel();
42581 }
42582 lpfc_transport_template =
42583 fc_attach_transport(&lpfc_transport_functions);
42584diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42585index 8523b278e..ce1d812 100644
42586--- a/drivers/scsi/lpfc/lpfc_scsi.c
42587+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42588@@ -331,7 +331,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42589 uint32_t evt_posted;
42590
42591 spin_lock_irqsave(&phba->hbalock, flags);
42592- atomic_inc(&phba->num_rsrc_err);
42593+ atomic_inc_unchecked(&phba->num_rsrc_err);
42594 phba->last_rsrc_error_time = jiffies;
42595
42596 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42597@@ -372,7 +372,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42598 unsigned long flags;
42599 struct lpfc_hba *phba = vport->phba;
42600 uint32_t evt_posted;
42601- atomic_inc(&phba->num_cmd_success);
42602+ atomic_inc_unchecked(&phba->num_cmd_success);
42603
42604 if (vport->cfg_lun_queue_depth <= queue_depth)
42605 return;
42606@@ -416,8 +416,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42607 unsigned long num_rsrc_err, num_cmd_success;
42608 int i;
42609
42610- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42611- num_cmd_success = atomic_read(&phba->num_cmd_success);
42612+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42613+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42614
42615 /*
42616 * The error and success command counters are global per
42617@@ -445,8 +445,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42618 }
42619 }
42620 lpfc_destroy_vport_work_array(phba, vports);
42621- atomic_set(&phba->num_rsrc_err, 0);
42622- atomic_set(&phba->num_cmd_success, 0);
42623+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42624+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42625 }
42626
42627 /**
42628@@ -480,8 +480,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42629 }
42630 }
42631 lpfc_destroy_vport_work_array(phba, vports);
42632- atomic_set(&phba->num_rsrc_err, 0);
42633- atomic_set(&phba->num_cmd_success, 0);
42634+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42635+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42636 }
42637
42638 /**
42639diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
42640index 8e1b737..50ff510 100644
42641--- a/drivers/scsi/pmcraid.c
42642+++ b/drivers/scsi/pmcraid.c
42643@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
42644 res->scsi_dev = scsi_dev;
42645 scsi_dev->hostdata = res;
42646 res->change_detected = 0;
42647- atomic_set(&res->read_failures, 0);
42648- atomic_set(&res->write_failures, 0);
42649+ atomic_set_unchecked(&res->read_failures, 0);
42650+ atomic_set_unchecked(&res->write_failures, 0);
42651 rc = 0;
42652 }
42653 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
42654@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
42655
42656 /* If this was a SCSI read/write command keep count of errors */
42657 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
42658- atomic_inc(&res->read_failures);
42659+ atomic_inc_unchecked(&res->read_failures);
42660 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
42661- atomic_inc(&res->write_failures);
42662+ atomic_inc_unchecked(&res->write_failures);
42663
42664 if (!RES_IS_GSCSI(res->cfg_entry) &&
42665 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
42666@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
42667 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42668 * hrrq_id assigned here in queuecommand
42669 */
42670- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42671+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42672 pinstance->num_hrrq;
42673 cmd->cmd_done = pmcraid_io_done;
42674
42675@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
42676 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42677 * hrrq_id assigned here in queuecommand
42678 */
42679- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42680+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42681 pinstance->num_hrrq;
42682
42683 if (request_size) {
42684@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
42685
42686 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
42687 /* add resources only after host is added into system */
42688- if (!atomic_read(&pinstance->expose_resources))
42689+ if (!atomic_read_unchecked(&pinstance->expose_resources))
42690 return;
42691
42692 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
42693@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
42694 init_waitqueue_head(&pinstance->reset_wait_q);
42695
42696 atomic_set(&pinstance->outstanding_cmds, 0);
42697- atomic_set(&pinstance->last_message_id, 0);
42698- atomic_set(&pinstance->expose_resources, 0);
42699+ atomic_set_unchecked(&pinstance->last_message_id, 0);
42700+ atomic_set_unchecked(&pinstance->expose_resources, 0);
42701
42702 INIT_LIST_HEAD(&pinstance->free_res_q);
42703 INIT_LIST_HEAD(&pinstance->used_res_q);
42704@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
42705 /* Schedule worker thread to handle CCN and take care of adding and
42706 * removing devices to OS
42707 */
42708- atomic_set(&pinstance->expose_resources, 1);
42709+ atomic_set_unchecked(&pinstance->expose_resources, 1);
42710 schedule_work(&pinstance->worker_q);
42711 return rc;
42712
42713diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
42714index e1d150f..6c6df44 100644
42715--- a/drivers/scsi/pmcraid.h
42716+++ b/drivers/scsi/pmcraid.h
42717@@ -748,7 +748,7 @@ struct pmcraid_instance {
42718 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
42719
42720 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
42721- atomic_t last_message_id;
42722+ atomic_unchecked_t last_message_id;
42723
42724 /* configuration table */
42725 struct pmcraid_config_table *cfg_table;
42726@@ -777,7 +777,7 @@ struct pmcraid_instance {
42727 atomic_t outstanding_cmds;
42728
42729 /* should add/delete resources to mid-layer now ?*/
42730- atomic_t expose_resources;
42731+ atomic_unchecked_t expose_resources;
42732
42733
42734
42735@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
42736 struct pmcraid_config_table_entry_ext cfg_entry_ext;
42737 };
42738 struct scsi_device *scsi_dev; /* Link scsi_device structure */
42739- atomic_t read_failures; /* count of failed READ commands */
42740- atomic_t write_failures; /* count of failed WRITE commands */
42741+ atomic_unchecked_t read_failures; /* count of failed READ commands */
42742+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
42743
42744 /* To indicate add/delete/modify during CCN */
42745 u8 change_detected;
42746diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
42747index bf60c63..74d4dce 100644
42748--- a/drivers/scsi/qla2xxx/qla_attr.c
42749+++ b/drivers/scsi/qla2xxx/qla_attr.c
42750@@ -2001,7 +2001,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
42751 return 0;
42752 }
42753
42754-struct fc_function_template qla2xxx_transport_functions = {
42755+fc_function_template_no_const qla2xxx_transport_functions = {
42756
42757 .show_host_node_name = 1,
42758 .show_host_port_name = 1,
42759@@ -2048,7 +2048,7 @@ struct fc_function_template qla2xxx_transport_functions = {
42760 .bsg_timeout = qla24xx_bsg_timeout,
42761 };
42762
42763-struct fc_function_template qla2xxx_transport_vport_functions = {
42764+fc_function_template_no_const qla2xxx_transport_vport_functions = {
42765
42766 .show_host_node_name = 1,
42767 .show_host_port_name = 1,
42768diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
42769index 026bfde..90c4018 100644
42770--- a/drivers/scsi/qla2xxx/qla_gbl.h
42771+++ b/drivers/scsi/qla2xxx/qla_gbl.h
42772@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
42773 struct device_attribute;
42774 extern struct device_attribute *qla2x00_host_attrs[];
42775 struct fc_function_template;
42776-extern struct fc_function_template qla2xxx_transport_functions;
42777-extern struct fc_function_template qla2xxx_transport_vport_functions;
42778+extern fc_function_template_no_const qla2xxx_transport_functions;
42779+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
42780 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
42781 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
42782 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
42783diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
42784index ad72c1d..afc9a98 100644
42785--- a/drivers/scsi/qla2xxx/qla_os.c
42786+++ b/drivers/scsi/qla2xxx/qla_os.c
42787@@ -1571,8 +1571,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
42788 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
42789 /* Ok, a 64bit DMA mask is applicable. */
42790 ha->flags.enable_64bit_addressing = 1;
42791- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42792- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42793+ pax_open_kernel();
42794+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42795+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42796+ pax_close_kernel();
42797 return;
42798 }
42799 }
42800diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
42801index ddf16a8..80f4dd0 100644
42802--- a/drivers/scsi/qla4xxx/ql4_def.h
42803+++ b/drivers/scsi/qla4xxx/ql4_def.h
42804@@ -291,7 +291,7 @@ struct ddb_entry {
42805 * (4000 only) */
42806 atomic_t relogin_timer; /* Max Time to wait for
42807 * relogin to complete */
42808- atomic_t relogin_retry_count; /* Num of times relogin has been
42809+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
42810 * retried */
42811 uint32_t default_time2wait; /* Default Min time between
42812 * relogins (+aens) */
42813diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
42814index 4d231c1..2892c37 100644
42815--- a/drivers/scsi/qla4xxx/ql4_os.c
42816+++ b/drivers/scsi/qla4xxx/ql4_os.c
42817@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
42818 */
42819 if (!iscsi_is_session_online(cls_sess)) {
42820 /* Reset retry relogin timer */
42821- atomic_inc(&ddb_entry->relogin_retry_count);
42822+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
42823 DEBUG2(ql4_printk(KERN_INFO, ha,
42824 "%s: index[%d] relogin timed out-retrying"
42825 " relogin (%d), retry (%d)\n", __func__,
42826 ddb_entry->fw_ddb_index,
42827- atomic_read(&ddb_entry->relogin_retry_count),
42828+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
42829 ddb_entry->default_time2wait + 4));
42830 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
42831 atomic_set(&ddb_entry->retry_relogin_timer,
42832@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
42833
42834 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
42835 atomic_set(&ddb_entry->relogin_timer, 0);
42836- atomic_set(&ddb_entry->relogin_retry_count, 0);
42837+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
42838 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
42839 ddb_entry->default_relogin_timeout =
42840 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
42841diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
42842index 2c0d0ec..4e8681a 100644
42843--- a/drivers/scsi/scsi.c
42844+++ b/drivers/scsi/scsi.c
42845@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
42846 unsigned long timeout;
42847 int rtn = 0;
42848
42849- atomic_inc(&cmd->device->iorequest_cnt);
42850+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42851
42852 /* check if the device is still usable */
42853 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
42854diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
42855index 86d5220..f22c51a 100644
42856--- a/drivers/scsi/scsi_lib.c
42857+++ b/drivers/scsi/scsi_lib.c
42858@@ -1458,7 +1458,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
42859 shost = sdev->host;
42860 scsi_init_cmd_errh(cmd);
42861 cmd->result = DID_NO_CONNECT << 16;
42862- atomic_inc(&cmd->device->iorequest_cnt);
42863+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42864
42865 /*
42866 * SCSI request completion path will do scsi_device_unbusy(),
42867@@ -1484,9 +1484,9 @@ static void scsi_softirq_done(struct request *rq)
42868
42869 INIT_LIST_HEAD(&cmd->eh_entry);
42870
42871- atomic_inc(&cmd->device->iodone_cnt);
42872+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
42873 if (cmd->result)
42874- atomic_inc(&cmd->device->ioerr_cnt);
42875+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
42876
42877 disposition = scsi_decide_disposition(cmd);
42878 if (disposition != SUCCESS &&
42879diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
42880index 931a7d9..0c2a754 100644
42881--- a/drivers/scsi/scsi_sysfs.c
42882+++ b/drivers/scsi/scsi_sysfs.c
42883@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
42884 char *buf) \
42885 { \
42886 struct scsi_device *sdev = to_scsi_device(dev); \
42887- unsigned long long count = atomic_read(&sdev->field); \
42888+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
42889 return snprintf(buf, 20, "0x%llx\n", count); \
42890 } \
42891 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
42892diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
42893index 84a1fdf..693b0d6 100644
42894--- a/drivers/scsi/scsi_tgt_lib.c
42895+++ b/drivers/scsi/scsi_tgt_lib.c
42896@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
42897 int err;
42898
42899 dprintk("%lx %u\n", uaddr, len);
42900- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
42901+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
42902 if (err) {
42903 /*
42904 * TODO: need to fixup sg_tablesize, max_segment_size,
42905diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42906index e106c27..11a380e 100644
42907--- a/drivers/scsi/scsi_transport_fc.c
42908+++ b/drivers/scsi/scsi_transport_fc.c
42909@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42910 * Netlink Infrastructure
42911 */
42912
42913-static atomic_t fc_event_seq;
42914+static atomic_unchecked_t fc_event_seq;
42915
42916 /**
42917 * fc_get_event_number - Obtain the next sequential FC event number
42918@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
42919 u32
42920 fc_get_event_number(void)
42921 {
42922- return atomic_add_return(1, &fc_event_seq);
42923+ return atomic_add_return_unchecked(1, &fc_event_seq);
42924 }
42925 EXPORT_SYMBOL(fc_get_event_number);
42926
42927@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
42928 {
42929 int error;
42930
42931- atomic_set(&fc_event_seq, 0);
42932+ atomic_set_unchecked(&fc_event_seq, 0);
42933
42934 error = transport_class_register(&fc_host_class);
42935 if (error)
42936@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42937 char *cp;
42938
42939 *val = simple_strtoul(buf, &cp, 0);
42940- if ((*cp && (*cp != '\n')) || (*val < 0))
42941+ if (*cp && (*cp != '\n'))
42942 return -EINVAL;
42943 /*
42944 * Check for overflow; dev_loss_tmo is u32
42945diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42946index 133926b..903000d 100644
42947--- a/drivers/scsi/scsi_transport_iscsi.c
42948+++ b/drivers/scsi/scsi_transport_iscsi.c
42949@@ -80,7 +80,7 @@ struct iscsi_internal {
42950 struct transport_container session_cont;
42951 };
42952
42953-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42954+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42955 static struct workqueue_struct *iscsi_eh_timer_workq;
42956
42957 static DEFINE_IDA(iscsi_sess_ida);
42958@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42959 int err;
42960
42961 ihost = shost->shost_data;
42962- session->sid = atomic_add_return(1, &iscsi_session_nr);
42963+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42964
42965 if (target_id == ISCSI_MAX_TARGET) {
42966 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42967@@ -3944,7 +3944,7 @@ static __init int iscsi_transport_init(void)
42968 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42969 ISCSI_TRANSPORT_VERSION);
42970
42971- atomic_set(&iscsi_session_nr, 0);
42972+ atomic_set_unchecked(&iscsi_session_nr, 0);
42973
42974 err = class_register(&iscsi_transport_class);
42975 if (err)
42976diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42977index f379c7f..e8fc69c 100644
42978--- a/drivers/scsi/scsi_transport_srp.c
42979+++ b/drivers/scsi/scsi_transport_srp.c
42980@@ -33,7 +33,7 @@
42981 #include "scsi_transport_srp_internal.h"
42982
42983 struct srp_host_attrs {
42984- atomic_t next_port_id;
42985+ atomic_unchecked_t next_port_id;
42986 };
42987 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42988
42989@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42990 struct Scsi_Host *shost = dev_to_shost(dev);
42991 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42992
42993- atomic_set(&srp_host->next_port_id, 0);
42994+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42995 return 0;
42996 }
42997
42998@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42999 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
43000 rport->roles = ids->roles;
43001
43002- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
43003+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
43004 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
43005
43006 transport_setup_device(&rport->dev);
43007diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
43008index 6f6a1b4..80704a9 100644
43009--- a/drivers/scsi/sd.c
43010+++ b/drivers/scsi/sd.c
43011@@ -2918,7 +2918,7 @@ static int sd_probe(struct device *dev)
43012 sdkp->disk = gd;
43013 sdkp->index = index;
43014 atomic_set(&sdkp->openers, 0);
43015- atomic_set(&sdkp->device->ioerr_cnt, 0);
43016+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
43017
43018 if (!sdp->request_queue->rq_timeout) {
43019 if (sdp->type != TYPE_MOD)
43020diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
43021index df5e961..df6b97f 100644
43022--- a/drivers/scsi/sg.c
43023+++ b/drivers/scsi/sg.c
43024@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
43025 sdp->disk->disk_name,
43026 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
43027 NULL,
43028- (char *)arg);
43029+ (char __user *)arg);
43030 case BLKTRACESTART:
43031 return blk_trace_startstop(sdp->device->request_queue, 1);
43032 case BLKTRACESTOP:
43033diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
43034index 32b7bb1..2f1c4bd 100644
43035--- a/drivers/spi/spi.c
43036+++ b/drivers/spi/spi.c
43037@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
43038 EXPORT_SYMBOL_GPL(spi_bus_unlock);
43039
43040 /* portable code must never pass more than 32 bytes */
43041-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
43042+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
43043
43044 static u8 *buf;
43045
43046diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
43047index 3675020..e80d92c 100644
43048--- a/drivers/staging/media/solo6x10/solo6x10-core.c
43049+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
43050@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
43051
43052 static int solo_sysfs_init(struct solo_dev *solo_dev)
43053 {
43054- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
43055+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
43056 struct device *dev = &solo_dev->dev;
43057 const char *driver;
43058 int i;
43059diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
43060index 34afc16..ffe44dd 100644
43061--- a/drivers/staging/octeon/ethernet-rx.c
43062+++ b/drivers/staging/octeon/ethernet-rx.c
43063@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
43064 /* Increment RX stats for virtual ports */
43065 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
43066 #ifdef CONFIG_64BIT
43067- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
43068- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
43069+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
43070+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
43071 #else
43072- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
43073- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
43074+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
43075+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
43076 #endif
43077 }
43078 netif_receive_skb(skb);
43079@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
43080 dev->name);
43081 */
43082 #ifdef CONFIG_64BIT
43083- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
43084+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
43085 #else
43086- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
43087+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
43088 #endif
43089 dev_kfree_skb_irq(skb);
43090 }
43091diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
43092index c3a90e7..023619a 100644
43093--- a/drivers/staging/octeon/ethernet.c
43094+++ b/drivers/staging/octeon/ethernet.c
43095@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
43096 * since the RX tasklet also increments it.
43097 */
43098 #ifdef CONFIG_64BIT
43099- atomic64_add(rx_status.dropped_packets,
43100- (atomic64_t *)&priv->stats.rx_dropped);
43101+ atomic64_add_unchecked(rx_status.dropped_packets,
43102+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
43103 #else
43104- atomic_add(rx_status.dropped_packets,
43105- (atomic_t *)&priv->stats.rx_dropped);
43106+ atomic_add_unchecked(rx_status.dropped_packets,
43107+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
43108 #endif
43109 }
43110
43111diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
43112index dc23395..cf7e9b1 100644
43113--- a/drivers/staging/rtl8712/rtl871x_io.h
43114+++ b/drivers/staging/rtl8712/rtl871x_io.h
43115@@ -108,7 +108,7 @@ struct _io_ops {
43116 u8 *pmem);
43117 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
43118 u8 *pmem);
43119-};
43120+} __no_const;
43121
43122 struct io_req {
43123 struct list_head list;
43124diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
43125index 1f5088b..0e59820 100644
43126--- a/drivers/staging/sbe-2t3e3/netdev.c
43127+++ b/drivers/staging/sbe-2t3e3/netdev.c
43128@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43129 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
43130
43131 if (rlen)
43132- if (copy_to_user(data, &resp, rlen))
43133+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
43134 return -EFAULT;
43135
43136 return 0;
43137diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
43138index a863a98..d272795 100644
43139--- a/drivers/staging/usbip/vhci.h
43140+++ b/drivers/staging/usbip/vhci.h
43141@@ -83,7 +83,7 @@ struct vhci_hcd {
43142 unsigned resuming:1;
43143 unsigned long re_timeout;
43144
43145- atomic_t seqnum;
43146+ atomic_unchecked_t seqnum;
43147
43148 /*
43149 * NOTE:
43150diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
43151index d7974cb..d78076b 100644
43152--- a/drivers/staging/usbip/vhci_hcd.c
43153+++ b/drivers/staging/usbip/vhci_hcd.c
43154@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
43155
43156 spin_lock(&vdev->priv_lock);
43157
43158- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
43159+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43160 if (priv->seqnum == 0xffff)
43161 dev_info(&urb->dev->dev, "seqnum max\n");
43162
43163@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
43164 return -ENOMEM;
43165 }
43166
43167- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
43168+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43169 if (unlink->seqnum == 0xffff)
43170 pr_info("seqnum max\n");
43171
43172@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
43173 vdev->rhport = rhport;
43174 }
43175
43176- atomic_set(&vhci->seqnum, 0);
43177+ atomic_set_unchecked(&vhci->seqnum, 0);
43178 spin_lock_init(&vhci->lock);
43179
43180 hcd->power_budget = 0; /* no limit */
43181diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
43182index d07fcb5..358e1e1 100644
43183--- a/drivers/staging/usbip/vhci_rx.c
43184+++ b/drivers/staging/usbip/vhci_rx.c
43185@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
43186 if (!urb) {
43187 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
43188 pr_info("max seqnum %d\n",
43189- atomic_read(&the_controller->seqnum));
43190+ atomic_read_unchecked(&the_controller->seqnum));
43191 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
43192 return;
43193 }
43194diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
43195index 8417c2f..ef5ebd6 100644
43196--- a/drivers/staging/vt6655/hostap.c
43197+++ b/drivers/staging/vt6655/hostap.c
43198@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
43199 *
43200 */
43201
43202+static net_device_ops_no_const apdev_netdev_ops;
43203+
43204 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43205 {
43206 PSDevice apdev_priv;
43207 struct net_device *dev = pDevice->dev;
43208 int ret;
43209- const struct net_device_ops apdev_netdev_ops = {
43210- .ndo_start_xmit = pDevice->tx_80211,
43211- };
43212
43213 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43214
43215@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43216 *apdev_priv = *pDevice;
43217 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43218
43219+ /* only half broken now */
43220+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43221 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43222
43223 pDevice->apdev->type = ARPHRD_IEEE80211;
43224diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
43225index c699a30..b90a5fd 100644
43226--- a/drivers/staging/vt6656/hostap.c
43227+++ b/drivers/staging/vt6656/hostap.c
43228@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
43229 *
43230 */
43231
43232+static net_device_ops_no_const apdev_netdev_ops;
43233+
43234 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
43235 {
43236 struct vnt_private *apdev_priv;
43237 struct net_device *dev = pDevice->dev;
43238 int ret;
43239- const struct net_device_ops apdev_netdev_ops = {
43240- .ndo_start_xmit = pDevice->tx_80211,
43241- };
43242
43243 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43244
43245@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
43246 *apdev_priv = *pDevice;
43247 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43248
43249+ /* only half broken now */
43250+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43251 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43252
43253 pDevice->apdev->type = ARPHRD_IEEE80211;
43254diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
43255index d7e51e4..d07eaab 100644
43256--- a/drivers/staging/zcache/tmem.c
43257+++ b/drivers/staging/zcache/tmem.c
43258@@ -51,7 +51,7 @@
43259 * A tmem host implementation must use this function to register callbacks
43260 * for memory allocation.
43261 */
43262-static struct tmem_hostops tmem_hostops;
43263+static tmem_hostops_no_const tmem_hostops;
43264
43265 static void tmem_objnode_tree_init(void);
43266
43267@@ -65,7 +65,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
43268 * A tmem host implementation must use this function to register
43269 * callbacks for a page-accessible memory (PAM) implementation.
43270 */
43271-static struct tmem_pamops tmem_pamops;
43272+static tmem_pamops_no_const tmem_pamops;
43273
43274 void tmem_register_pamops(struct tmem_pamops *m)
43275 {
43276diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
43277index d128ce2..a43980c 100644
43278--- a/drivers/staging/zcache/tmem.h
43279+++ b/drivers/staging/zcache/tmem.h
43280@@ -226,6 +226,7 @@ struct tmem_pamops {
43281 int (*replace_in_obj)(void *, struct tmem_obj *);
43282 #endif
43283 };
43284+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
43285 extern void tmem_register_pamops(struct tmem_pamops *m);
43286
43287 /* memory allocation methods provided by the host implementation */
43288@@ -235,6 +236,7 @@ struct tmem_hostops {
43289 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
43290 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
43291 };
43292+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
43293 extern void tmem_register_hostops(struct tmem_hostops *m);
43294
43295 /* core tmem accessor functions */
43296diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
43297index 4630481..c26782a 100644
43298--- a/drivers/target/target_core_device.c
43299+++ b/drivers/target/target_core_device.c
43300@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
43301 spin_lock_init(&dev->se_port_lock);
43302 spin_lock_init(&dev->se_tmr_lock);
43303 spin_lock_init(&dev->qf_cmd_lock);
43304- atomic_set(&dev->dev_ordered_id, 0);
43305+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
43306 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
43307 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
43308 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
43309diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
43310index 21e3158..43c6004 100644
43311--- a/drivers/target/target_core_transport.c
43312+++ b/drivers/target/target_core_transport.c
43313@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
43314 * Used to determine when ORDERED commands should go from
43315 * Dormant to Active status.
43316 */
43317- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
43318+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
43319 smp_mb__after_atomic_inc();
43320 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
43321 cmd->se_ordered_id, cmd->sam_task_attr,
43322diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
43323index 33f83fe..d80f8e1 100644
43324--- a/drivers/tty/cyclades.c
43325+++ b/drivers/tty/cyclades.c
43326@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
43327 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
43328 info->port.count);
43329 #endif
43330- info->port.count++;
43331+ atomic_inc(&info->port.count);
43332 #ifdef CY_DEBUG_COUNT
43333 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
43334- current->pid, info->port.count);
43335+ current->pid, atomic_read(&info->port.count));
43336 #endif
43337
43338 /*
43339@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
43340 for (j = 0; j < cy_card[i].nports; j++) {
43341 info = &cy_card[i].ports[j];
43342
43343- if (info->port.count) {
43344+ if (atomic_read(&info->port.count)) {
43345 /* XXX is the ldisc num worth this? */
43346 struct tty_struct *tty;
43347 struct tty_ldisc *ld;
43348diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
43349index eb255e8..f637a57 100644
43350--- a/drivers/tty/hvc/hvc_console.c
43351+++ b/drivers/tty/hvc/hvc_console.c
43352@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
43353
43354 spin_lock_irqsave(&hp->port.lock, flags);
43355 /* Check and then increment for fast path open. */
43356- if (hp->port.count++ > 0) {
43357+ if (atomic_inc_return(&hp->port.count) > 1) {
43358 spin_unlock_irqrestore(&hp->port.lock, flags);
43359 hvc_kick();
43360 return 0;
43361@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43362
43363 spin_lock_irqsave(&hp->port.lock, flags);
43364
43365- if (--hp->port.count == 0) {
43366+ if (atomic_dec_return(&hp->port.count) == 0) {
43367 spin_unlock_irqrestore(&hp->port.lock, flags);
43368 /* We are done with the tty pointer now. */
43369 tty_port_tty_set(&hp->port, NULL);
43370@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43371 */
43372 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
43373 } else {
43374- if (hp->port.count < 0)
43375+ if (atomic_read(&hp->port.count) < 0)
43376 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
43377- hp->vtermno, hp->port.count);
43378+ hp->vtermno, atomic_read(&hp->port.count));
43379 spin_unlock_irqrestore(&hp->port.lock, flags);
43380 }
43381 }
43382@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
43383 * open->hangup case this can be called after the final close so prevent
43384 * that from happening for now.
43385 */
43386- if (hp->port.count <= 0) {
43387+ if (atomic_read(&hp->port.count) <= 0) {
43388 spin_unlock_irqrestore(&hp->port.lock, flags);
43389 return;
43390 }
43391
43392- hp->port.count = 0;
43393+ atomic_set(&hp->port.count, 0);
43394 spin_unlock_irqrestore(&hp->port.lock, flags);
43395 tty_port_tty_set(&hp->port, NULL);
43396
43397@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
43398 return -EPIPE;
43399
43400 /* FIXME what's this (unprotected) check for? */
43401- if (hp->port.count <= 0)
43402+ if (atomic_read(&hp->port.count) <= 0)
43403 return -EIO;
43404
43405 spin_lock_irqsave(&hp->lock, flags);
43406diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
43407index 81e939e..95ead10 100644
43408--- a/drivers/tty/hvc/hvcs.c
43409+++ b/drivers/tty/hvc/hvcs.c
43410@@ -83,6 +83,7 @@
43411 #include <asm/hvcserver.h>
43412 #include <asm/uaccess.h>
43413 #include <asm/vio.h>
43414+#include <asm/local.h>
43415
43416 /*
43417 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
43418@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
43419
43420 spin_lock_irqsave(&hvcsd->lock, flags);
43421
43422- if (hvcsd->port.count > 0) {
43423+ if (atomic_read(&hvcsd->port.count) > 0) {
43424 spin_unlock_irqrestore(&hvcsd->lock, flags);
43425 printk(KERN_INFO "HVCS: vterm state unchanged. "
43426 "The hvcs device node is still in use.\n");
43427@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
43428 }
43429 }
43430
43431- hvcsd->port.count = 0;
43432+ atomic_set(&hvcsd->port.count, 0);
43433 hvcsd->port.tty = tty;
43434 tty->driver_data = hvcsd;
43435
43436@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
43437 unsigned long flags;
43438
43439 spin_lock_irqsave(&hvcsd->lock, flags);
43440- hvcsd->port.count++;
43441+ atomic_inc(&hvcsd->port.count);
43442 hvcsd->todo_mask |= HVCS_SCHED_READ;
43443 spin_unlock_irqrestore(&hvcsd->lock, flags);
43444
43445@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43446 hvcsd = tty->driver_data;
43447
43448 spin_lock_irqsave(&hvcsd->lock, flags);
43449- if (--hvcsd->port.count == 0) {
43450+ if (atomic_dec_and_test(&hvcsd->port.count)) {
43451
43452 vio_disable_interrupts(hvcsd->vdev);
43453
43454@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43455
43456 free_irq(irq, hvcsd);
43457 return;
43458- } else if (hvcsd->port.count < 0) {
43459+ } else if (atomic_read(&hvcsd->port.count) < 0) {
43460 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
43461 " is missmanaged.\n",
43462- hvcsd->vdev->unit_address, hvcsd->port.count);
43463+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
43464 }
43465
43466 spin_unlock_irqrestore(&hvcsd->lock, flags);
43467@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43468
43469 spin_lock_irqsave(&hvcsd->lock, flags);
43470 /* Preserve this so that we know how many kref refs to put */
43471- temp_open_count = hvcsd->port.count;
43472+ temp_open_count = atomic_read(&hvcsd->port.count);
43473
43474 /*
43475 * Don't kref put inside the spinlock because the destruction
43476@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43477 tty->driver_data = NULL;
43478 hvcsd->port.tty = NULL;
43479
43480- hvcsd->port.count = 0;
43481+ atomic_set(&hvcsd->port.count, 0);
43482
43483 /* This will drop any buffered data on the floor which is OK in a hangup
43484 * scenario. */
43485@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
43486 * the middle of a write operation? This is a crummy place to do this
43487 * but we want to keep it all in the spinlock.
43488 */
43489- if (hvcsd->port.count <= 0) {
43490+ if (atomic_read(&hvcsd->port.count) <= 0) {
43491 spin_unlock_irqrestore(&hvcsd->lock, flags);
43492 return -ENODEV;
43493 }
43494@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
43495 {
43496 struct hvcs_struct *hvcsd = tty->driver_data;
43497
43498- if (!hvcsd || hvcsd->port.count <= 0)
43499+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
43500 return 0;
43501
43502 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
43503diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
43504index 8fd72ff..34a0bed 100644
43505--- a/drivers/tty/ipwireless/tty.c
43506+++ b/drivers/tty/ipwireless/tty.c
43507@@ -29,6 +29,7 @@
43508 #include <linux/tty_driver.h>
43509 #include <linux/tty_flip.h>
43510 #include <linux/uaccess.h>
43511+#include <asm/local.h>
43512
43513 #include "tty.h"
43514 #include "network.h"
43515@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43516 mutex_unlock(&tty->ipw_tty_mutex);
43517 return -ENODEV;
43518 }
43519- if (tty->port.count == 0)
43520+ if (atomic_read(&tty->port.count) == 0)
43521 tty->tx_bytes_queued = 0;
43522
43523- tty->port.count++;
43524+ atomic_inc(&tty->port.count);
43525
43526 tty->port.tty = linux_tty;
43527 linux_tty->driver_data = tty;
43528@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43529
43530 static void do_ipw_close(struct ipw_tty *tty)
43531 {
43532- tty->port.count--;
43533-
43534- if (tty->port.count == 0) {
43535+ if (atomic_dec_return(&tty->port.count) == 0) {
43536 struct tty_struct *linux_tty = tty->port.tty;
43537
43538 if (linux_tty != NULL) {
43539@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
43540 return;
43541
43542 mutex_lock(&tty->ipw_tty_mutex);
43543- if (tty->port.count == 0) {
43544+ if (atomic_read(&tty->port.count) == 0) {
43545 mutex_unlock(&tty->ipw_tty_mutex);
43546 return;
43547 }
43548@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
43549
43550 mutex_lock(&tty->ipw_tty_mutex);
43551
43552- if (!tty->port.count) {
43553+ if (!atomic_read(&tty->port.count)) {
43554 mutex_unlock(&tty->ipw_tty_mutex);
43555 return;
43556 }
43557@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
43558 return -ENODEV;
43559
43560 mutex_lock(&tty->ipw_tty_mutex);
43561- if (!tty->port.count) {
43562+ if (!atomic_read(&tty->port.count)) {
43563 mutex_unlock(&tty->ipw_tty_mutex);
43564 return -EINVAL;
43565 }
43566@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
43567 if (!tty)
43568 return -ENODEV;
43569
43570- if (!tty->port.count)
43571+ if (!atomic_read(&tty->port.count))
43572 return -EINVAL;
43573
43574 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
43575@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
43576 if (!tty)
43577 return 0;
43578
43579- if (!tty->port.count)
43580+ if (!atomic_read(&tty->port.count))
43581 return 0;
43582
43583 return tty->tx_bytes_queued;
43584@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
43585 if (!tty)
43586 return -ENODEV;
43587
43588- if (!tty->port.count)
43589+ if (!atomic_read(&tty->port.count))
43590 return -EINVAL;
43591
43592 return get_control_lines(tty);
43593@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
43594 if (!tty)
43595 return -ENODEV;
43596
43597- if (!tty->port.count)
43598+ if (!atomic_read(&tty->port.count))
43599 return -EINVAL;
43600
43601 return set_control_lines(tty, set, clear);
43602@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
43603 if (!tty)
43604 return -ENODEV;
43605
43606- if (!tty->port.count)
43607+ if (!atomic_read(&tty->port.count))
43608 return -EINVAL;
43609
43610 /* FIXME: Exactly how is the tty object locked here .. */
43611@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
43612 * are gone */
43613 mutex_lock(&ttyj->ipw_tty_mutex);
43614 }
43615- while (ttyj->port.count)
43616+ while (atomic_read(&ttyj->port.count))
43617 do_ipw_close(ttyj);
43618 ipwireless_disassociate_network_ttys(network,
43619 ttyj->channel_idx);
43620diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
43621index 1deaca4..c8582d4 100644
43622--- a/drivers/tty/moxa.c
43623+++ b/drivers/tty/moxa.c
43624@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
43625 }
43626
43627 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
43628- ch->port.count++;
43629+ atomic_inc(&ch->port.count);
43630 tty->driver_data = ch;
43631 tty_port_tty_set(&ch->port, tty);
43632 mutex_lock(&ch->port.mutex);
43633diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
43634index 6422390..49003ac8 100644
43635--- a/drivers/tty/n_gsm.c
43636+++ b/drivers/tty/n_gsm.c
43637@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
43638 spin_lock_init(&dlci->lock);
43639 mutex_init(&dlci->mutex);
43640 dlci->fifo = &dlci->_fifo;
43641- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
43642+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
43643 kfree(dlci);
43644 return NULL;
43645 }
43646@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
43647 struct gsm_dlci *dlci = tty->driver_data;
43648 struct tty_port *port = &dlci->port;
43649
43650- port->count++;
43651+ atomic_inc(&port->count);
43652 dlci_get(dlci);
43653 dlci_get(dlci->gsm->dlci[0]);
43654 mux_get(dlci->gsm);
43655diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
43656index 6c7fe90..9241dab 100644
43657--- a/drivers/tty/n_tty.c
43658+++ b/drivers/tty/n_tty.c
43659@@ -2203,6 +2203,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
43660 {
43661 *ops = tty_ldisc_N_TTY;
43662 ops->owner = NULL;
43663- ops->refcount = ops->flags = 0;
43664+ atomic_set(&ops->refcount, 0);
43665+ ops->flags = 0;
43666 }
43667 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
43668diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
43669index abfd990..5ab5da9 100644
43670--- a/drivers/tty/pty.c
43671+++ b/drivers/tty/pty.c
43672@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
43673 panic("Couldn't register Unix98 pts driver");
43674
43675 /* Now create the /dev/ptmx special device */
43676+ pax_open_kernel();
43677 tty_default_fops(&ptmx_fops);
43678- ptmx_fops.open = ptmx_open;
43679+ *(void **)&ptmx_fops.open = ptmx_open;
43680+ pax_close_kernel();
43681
43682 cdev_init(&ptmx_cdev, &ptmx_fops);
43683 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43684diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43685index 354564e..fe50d9a 100644
43686--- a/drivers/tty/rocket.c
43687+++ b/drivers/tty/rocket.c
43688@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43689 tty->driver_data = info;
43690 tty_port_tty_set(port, tty);
43691
43692- if (port->count++ == 0) {
43693+ if (atomic_inc_return(&port->count) == 1) {
43694 atomic_inc(&rp_num_ports_open);
43695
43696 #ifdef ROCKET_DEBUG_OPEN
43697@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43698 #endif
43699 }
43700 #ifdef ROCKET_DEBUG_OPEN
43701- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43702+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43703 #endif
43704
43705 /*
43706@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
43707 spin_unlock_irqrestore(&info->port.lock, flags);
43708 return;
43709 }
43710- if (info->port.count)
43711+ if (atomic_read(&info->port.count))
43712 atomic_dec(&rp_num_ports_open);
43713 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43714 spin_unlock_irqrestore(&info->port.lock, flags);
43715diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43716index 1002054..dd644a8 100644
43717--- a/drivers/tty/serial/kgdboc.c
43718+++ b/drivers/tty/serial/kgdboc.c
43719@@ -24,8 +24,9 @@
43720 #define MAX_CONFIG_LEN 40
43721
43722 static struct kgdb_io kgdboc_io_ops;
43723+static struct kgdb_io kgdboc_io_ops_console;
43724
43725-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43726+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43727 static int configured = -1;
43728
43729 static char config[MAX_CONFIG_LEN];
43730@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43731 kgdboc_unregister_kbd();
43732 if (configured == 1)
43733 kgdb_unregister_io_module(&kgdboc_io_ops);
43734+ else if (configured == 2)
43735+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43736 }
43737
43738 static int configure_kgdboc(void)
43739@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43740 int err;
43741 char *cptr = config;
43742 struct console *cons;
43743+ int is_console = 0;
43744
43745 err = kgdboc_option_setup(config);
43746 if (err || !strlen(config) || isspace(config[0]))
43747 goto noconfig;
43748
43749 err = -ENODEV;
43750- kgdboc_io_ops.is_console = 0;
43751 kgdb_tty_driver = NULL;
43752
43753 kgdboc_use_kms = 0;
43754@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43755 int idx;
43756 if (cons->device && cons->device(cons, &idx) == p &&
43757 idx == tty_line) {
43758- kgdboc_io_ops.is_console = 1;
43759+ is_console = 1;
43760 break;
43761 }
43762 cons = cons->next;
43763@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43764 kgdb_tty_line = tty_line;
43765
43766 do_register:
43767- err = kgdb_register_io_module(&kgdboc_io_ops);
43768+ if (is_console) {
43769+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43770+ configured = 2;
43771+ } else {
43772+ err = kgdb_register_io_module(&kgdboc_io_ops);
43773+ configured = 1;
43774+ }
43775 if (err)
43776 goto noconfig;
43777
43778@@ -205,8 +214,6 @@ do_register:
43779 if (err)
43780 goto nmi_con_failed;
43781
43782- configured = 1;
43783-
43784 return 0;
43785
43786 nmi_con_failed:
43787@@ -223,7 +230,7 @@ noconfig:
43788 static int __init init_kgdboc(void)
43789 {
43790 /* Already configured? */
43791- if (configured == 1)
43792+ if (configured >= 1)
43793 return 0;
43794
43795 return configure_kgdboc();
43796@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43797 if (config[len - 1] == '\n')
43798 config[len - 1] = '\0';
43799
43800- if (configured == 1)
43801+ if (configured >= 1)
43802 cleanup_kgdboc();
43803
43804 /* Go and configure with the new params. */
43805@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43806 .post_exception = kgdboc_post_exp_handler,
43807 };
43808
43809+static struct kgdb_io kgdboc_io_ops_console = {
43810+ .name = "kgdboc",
43811+ .read_char = kgdboc_get_char,
43812+ .write_char = kgdboc_put_char,
43813+ .pre_exception = kgdboc_pre_exp_handler,
43814+ .post_exception = kgdboc_post_exp_handler,
43815+ .is_console = 1
43816+};
43817+
43818 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43819 /* This is only available if kgdboc is a built in for early debugging */
43820 static int __init kgdboc_early_init(char *opt)
43821diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43822index 0c8a9fa..234a95f 100644
43823--- a/drivers/tty/serial/samsung.c
43824+++ b/drivers/tty/serial/samsung.c
43825@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43826 }
43827 }
43828
43829+static int s3c64xx_serial_startup(struct uart_port *port);
43830 static int s3c24xx_serial_startup(struct uart_port *port)
43831 {
43832 struct s3c24xx_uart_port *ourport = to_ourport(port);
43833 int ret;
43834
43835+ /* Startup sequence is different for s3c64xx and higher SoC's */
43836+ if (s3c24xx_serial_has_interrupt_mask(port))
43837+ return s3c64xx_serial_startup(port);
43838+
43839 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43840 port->mapbase, port->membase);
43841
43842@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43843 /* setup info for port */
43844 port->dev = &platdev->dev;
43845
43846- /* Startup sequence is different for s3c64xx and higher SoC's */
43847- if (s3c24xx_serial_has_interrupt_mask(port))
43848- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43849-
43850 port->uartclk = 1;
43851
43852 if (cfg->uart_flags & UPF_CONS_FLOW) {
43853diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43854index f87dbfd..42ad4b1 100644
43855--- a/drivers/tty/serial/serial_core.c
43856+++ b/drivers/tty/serial/serial_core.c
43857@@ -1454,7 +1454,7 @@ static void uart_hangup(struct tty_struct *tty)
43858 uart_flush_buffer(tty);
43859 uart_shutdown(tty, state);
43860 spin_lock_irqsave(&port->lock, flags);
43861- port->count = 0;
43862+ atomic_set(&port->count, 0);
43863 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43864 spin_unlock_irqrestore(&port->lock, flags);
43865 tty_port_tty_set(port, NULL);
43866@@ -1550,7 +1550,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43867 goto end;
43868 }
43869
43870- port->count++;
43871+ atomic_inc(&port->count);
43872 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43873 retval = -ENXIO;
43874 goto err_dec_count;
43875@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43876 /*
43877 * Make sure the device is in D0 state.
43878 */
43879- if (port->count == 1)
43880+ if (atomic_read(&port->count) == 1)
43881 uart_change_pm(state, UART_PM_STATE_ON);
43882
43883 /*
43884@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43885 end:
43886 return retval;
43887 err_dec_count:
43888- port->count--;
43889+ atomic_inc(&port->count);
43890 mutex_unlock(&port->mutex);
43891 goto end;
43892 }
43893diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43894index 8eaf1ab..85c030d 100644
43895--- a/drivers/tty/synclink.c
43896+++ b/drivers/tty/synclink.c
43897@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43898
43899 if (debug_level >= DEBUG_LEVEL_INFO)
43900 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43901- __FILE__,__LINE__, info->device_name, info->port.count);
43902+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43903
43904 if (tty_port_close_start(&info->port, tty, filp) == 0)
43905 goto cleanup;
43906@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43907 cleanup:
43908 if (debug_level >= DEBUG_LEVEL_INFO)
43909 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43910- tty->driver->name, info->port.count);
43911+ tty->driver->name, atomic_read(&info->port.count));
43912
43913 } /* end of mgsl_close() */
43914
43915@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43916
43917 mgsl_flush_buffer(tty);
43918 shutdown(info);
43919-
43920- info->port.count = 0;
43921+
43922+ atomic_set(&info->port.count, 0);
43923 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43924 info->port.tty = NULL;
43925
43926@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43927
43928 if (debug_level >= DEBUG_LEVEL_INFO)
43929 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43930- __FILE__,__LINE__, tty->driver->name, port->count );
43931+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43932
43933 spin_lock_irqsave(&info->irq_spinlock, flags);
43934 if (!tty_hung_up_p(filp)) {
43935 extra_count = true;
43936- port->count--;
43937+ atomic_dec(&port->count);
43938 }
43939 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43940 port->blocked_open++;
43941@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43942
43943 if (debug_level >= DEBUG_LEVEL_INFO)
43944 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43945- __FILE__,__LINE__, tty->driver->name, port->count );
43946+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43947
43948 tty_unlock(tty);
43949 schedule();
43950@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43951
43952 /* FIXME: Racy on hangup during close wait */
43953 if (extra_count)
43954- port->count++;
43955+ atomic_inc(&port->count);
43956 port->blocked_open--;
43957
43958 if (debug_level >= DEBUG_LEVEL_INFO)
43959 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43960- __FILE__,__LINE__, tty->driver->name, port->count );
43961+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43962
43963 if (!retval)
43964 port->flags |= ASYNC_NORMAL_ACTIVE;
43965@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43966
43967 if (debug_level >= DEBUG_LEVEL_INFO)
43968 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
43969- __FILE__,__LINE__,tty->driver->name, info->port.count);
43970+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43971
43972 /* If port is closing, signal caller to try again */
43973 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43974@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43975 spin_unlock_irqrestore(&info->netlock, flags);
43976 goto cleanup;
43977 }
43978- info->port.count++;
43979+ atomic_inc(&info->port.count);
43980 spin_unlock_irqrestore(&info->netlock, flags);
43981
43982- if (info->port.count == 1) {
43983+ if (atomic_read(&info->port.count) == 1) {
43984 /* 1st open on this device, init hardware */
43985 retval = startup(info);
43986 if (retval < 0)
43987@@ -3446,8 +3446,8 @@ cleanup:
43988 if (retval) {
43989 if (tty->count == 1)
43990 info->port.tty = NULL; /* tty layer will release tty struct */
43991- if(info->port.count)
43992- info->port.count--;
43993+ if (atomic_read(&info->port.count))
43994+ atomic_dec(&info->port.count);
43995 }
43996
43997 return retval;
43998@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43999 unsigned short new_crctype;
44000
44001 /* return error if TTY interface open */
44002- if (info->port.count)
44003+ if (atomic_read(&info->port.count))
44004 return -EBUSY;
44005
44006 switch (encoding)
44007@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
44008
44009 /* arbitrate between network and tty opens */
44010 spin_lock_irqsave(&info->netlock, flags);
44011- if (info->port.count != 0 || info->netcount != 0) {
44012+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44013 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44014 spin_unlock_irqrestore(&info->netlock, flags);
44015 return -EBUSY;
44016@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44017 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44018
44019 /* return error if TTY interface open */
44020- if (info->port.count)
44021+ if (atomic_read(&info->port.count))
44022 return -EBUSY;
44023
44024 if (cmd != SIOCWANDEV)
44025diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
44026index 1abf946..1ee34fc 100644
44027--- a/drivers/tty/synclink_gt.c
44028+++ b/drivers/tty/synclink_gt.c
44029@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44030 tty->driver_data = info;
44031 info->port.tty = tty;
44032
44033- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
44034+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
44035
44036 /* If port is closing, signal caller to try again */
44037 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44038@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44039 mutex_unlock(&info->port.mutex);
44040 goto cleanup;
44041 }
44042- info->port.count++;
44043+ atomic_inc(&info->port.count);
44044 spin_unlock_irqrestore(&info->netlock, flags);
44045
44046- if (info->port.count == 1) {
44047+ if (atomic_read(&info->port.count) == 1) {
44048 /* 1st open on this device, init hardware */
44049 retval = startup(info);
44050 if (retval < 0) {
44051@@ -715,8 +715,8 @@ cleanup:
44052 if (retval) {
44053 if (tty->count == 1)
44054 info->port.tty = NULL; /* tty layer will release tty struct */
44055- if(info->port.count)
44056- info->port.count--;
44057+ if(atomic_read(&info->port.count))
44058+ atomic_dec(&info->port.count);
44059 }
44060
44061 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
44062@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44063
44064 if (sanity_check(info, tty->name, "close"))
44065 return;
44066- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
44067+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
44068
44069 if (tty_port_close_start(&info->port, tty, filp) == 0)
44070 goto cleanup;
44071@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44072 tty_port_close_end(&info->port, tty);
44073 info->port.tty = NULL;
44074 cleanup:
44075- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
44076+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
44077 }
44078
44079 static void hangup(struct tty_struct *tty)
44080@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
44081 shutdown(info);
44082
44083 spin_lock_irqsave(&info->port.lock, flags);
44084- info->port.count = 0;
44085+ atomic_set(&info->port.count, 0);
44086 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44087 info->port.tty = NULL;
44088 spin_unlock_irqrestore(&info->port.lock, flags);
44089@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44090 unsigned short new_crctype;
44091
44092 /* return error if TTY interface open */
44093- if (info->port.count)
44094+ if (atomic_read(&info->port.count))
44095 return -EBUSY;
44096
44097 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
44098@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
44099
44100 /* arbitrate between network and tty opens */
44101 spin_lock_irqsave(&info->netlock, flags);
44102- if (info->port.count != 0 || info->netcount != 0) {
44103+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44104 DBGINFO(("%s hdlc_open busy\n", dev->name));
44105 spin_unlock_irqrestore(&info->netlock, flags);
44106 return -EBUSY;
44107@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44108 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
44109
44110 /* return error if TTY interface open */
44111- if (info->port.count)
44112+ if (atomic_read(&info->port.count))
44113 return -EBUSY;
44114
44115 if (cmd != SIOCWANDEV)
44116@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
44117 if (port == NULL)
44118 continue;
44119 spin_lock(&port->lock);
44120- if ((port->port.count || port->netcount) &&
44121+ if ((atomic_read(&port->port.count) || port->netcount) &&
44122 port->pending_bh && !port->bh_running &&
44123 !port->bh_requested) {
44124 DBGISR(("%s bh queued\n", port->device_name));
44125@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44126 spin_lock_irqsave(&info->lock, flags);
44127 if (!tty_hung_up_p(filp)) {
44128 extra_count = true;
44129- port->count--;
44130+ atomic_dec(&port->count);
44131 }
44132 spin_unlock_irqrestore(&info->lock, flags);
44133 port->blocked_open++;
44134@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44135 remove_wait_queue(&port->open_wait, &wait);
44136
44137 if (extra_count)
44138- port->count++;
44139+ atomic_inc(&port->count);
44140 port->blocked_open--;
44141
44142 if (!retval)
44143diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
44144index ff17138..e38b41e 100644
44145--- a/drivers/tty/synclinkmp.c
44146+++ b/drivers/tty/synclinkmp.c
44147@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44148
44149 if (debug_level >= DEBUG_LEVEL_INFO)
44150 printk("%s(%d):%s open(), old ref count = %d\n",
44151- __FILE__,__LINE__,tty->driver->name, info->port.count);
44152+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44153
44154 /* If port is closing, signal caller to try again */
44155 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44156@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44157 spin_unlock_irqrestore(&info->netlock, flags);
44158 goto cleanup;
44159 }
44160- info->port.count++;
44161+ atomic_inc(&info->port.count);
44162 spin_unlock_irqrestore(&info->netlock, flags);
44163
44164- if (info->port.count == 1) {
44165+ if (atomic_read(&info->port.count) == 1) {
44166 /* 1st open on this device, init hardware */
44167 retval = startup(info);
44168 if (retval < 0)
44169@@ -796,8 +796,8 @@ cleanup:
44170 if (retval) {
44171 if (tty->count == 1)
44172 info->port.tty = NULL; /* tty layer will release tty struct */
44173- if(info->port.count)
44174- info->port.count--;
44175+ if(atomic_read(&info->port.count))
44176+ atomic_dec(&info->port.count);
44177 }
44178
44179 return retval;
44180@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44181
44182 if (debug_level >= DEBUG_LEVEL_INFO)
44183 printk("%s(%d):%s close() entry, count=%d\n",
44184- __FILE__,__LINE__, info->device_name, info->port.count);
44185+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
44186
44187 if (tty_port_close_start(&info->port, tty, filp) == 0)
44188 goto cleanup;
44189@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44190 cleanup:
44191 if (debug_level >= DEBUG_LEVEL_INFO)
44192 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
44193- tty->driver->name, info->port.count);
44194+ tty->driver->name, atomic_read(&info->port.count));
44195 }
44196
44197 /* Called by tty_hangup() when a hangup is signaled.
44198@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
44199 shutdown(info);
44200
44201 spin_lock_irqsave(&info->port.lock, flags);
44202- info->port.count = 0;
44203+ atomic_set(&info->port.count, 0);
44204 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44205 info->port.tty = NULL;
44206 spin_unlock_irqrestore(&info->port.lock, flags);
44207@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44208 unsigned short new_crctype;
44209
44210 /* return error if TTY interface open */
44211- if (info->port.count)
44212+ if (atomic_read(&info->port.count))
44213 return -EBUSY;
44214
44215 switch (encoding)
44216@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
44217
44218 /* arbitrate between network and tty opens */
44219 spin_lock_irqsave(&info->netlock, flags);
44220- if (info->port.count != 0 || info->netcount != 0) {
44221+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44222 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44223 spin_unlock_irqrestore(&info->netlock, flags);
44224 return -EBUSY;
44225@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44226 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44227
44228 /* return error if TTY interface open */
44229- if (info->port.count)
44230+ if (atomic_read(&info->port.count))
44231 return -EBUSY;
44232
44233 if (cmd != SIOCWANDEV)
44234@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
44235 * do not request bottom half processing if the
44236 * device is not open in a normal mode.
44237 */
44238- if ( port && (port->port.count || port->netcount) &&
44239+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
44240 port->pending_bh && !port->bh_running &&
44241 !port->bh_requested ) {
44242 if ( debug_level >= DEBUG_LEVEL_ISR )
44243@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44244
44245 if (debug_level >= DEBUG_LEVEL_INFO)
44246 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
44247- __FILE__,__LINE__, tty->driver->name, port->count );
44248+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44249
44250 spin_lock_irqsave(&info->lock, flags);
44251 if (!tty_hung_up_p(filp)) {
44252 extra_count = true;
44253- port->count--;
44254+ atomic_dec(&port->count);
44255 }
44256 spin_unlock_irqrestore(&info->lock, flags);
44257 port->blocked_open++;
44258@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44259
44260 if (debug_level >= DEBUG_LEVEL_INFO)
44261 printk("%s(%d):%s block_til_ready() count=%d\n",
44262- __FILE__,__LINE__, tty->driver->name, port->count );
44263+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44264
44265 tty_unlock(tty);
44266 schedule();
44267@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44268 remove_wait_queue(&port->open_wait, &wait);
44269
44270 if (extra_count)
44271- port->count++;
44272+ atomic_inc(&port->count);
44273 port->blocked_open--;
44274
44275 if (debug_level >= DEBUG_LEVEL_INFO)
44276 printk("%s(%d):%s block_til_ready() after, count=%d\n",
44277- __FILE__,__LINE__, tty->driver->name, port->count );
44278+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44279
44280 if (!retval)
44281 port->flags |= ASYNC_NORMAL_ACTIVE;
44282diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
44283index b51c154..17d55d1 100644
44284--- a/drivers/tty/sysrq.c
44285+++ b/drivers/tty/sysrq.c
44286@@ -1022,7 +1022,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
44287 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
44288 size_t count, loff_t *ppos)
44289 {
44290- if (count) {
44291+ if (count && capable(CAP_SYS_ADMIN)) {
44292 char c;
44293
44294 if (get_user(c, buf))
44295diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
44296index 4476682..d77e748 100644
44297--- a/drivers/tty/tty_io.c
44298+++ b/drivers/tty/tty_io.c
44299@@ -3466,7 +3466,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
44300
44301 void tty_default_fops(struct file_operations *fops)
44302 {
44303- *fops = tty_fops;
44304+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
44305 }
44306
44307 /*
44308diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
44309index 1afe192..73d2c20 100644
44310--- a/drivers/tty/tty_ldisc.c
44311+++ b/drivers/tty/tty_ldisc.c
44312@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
44313 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44314 tty_ldiscs[disc] = new_ldisc;
44315 new_ldisc->num = disc;
44316- new_ldisc->refcount = 0;
44317+ atomic_set(&new_ldisc->refcount, 0);
44318 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44319
44320 return ret;
44321@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
44322 return -EINVAL;
44323
44324 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44325- if (tty_ldiscs[disc]->refcount)
44326+ if (atomic_read(&tty_ldiscs[disc]->refcount))
44327 ret = -EBUSY;
44328 else
44329 tty_ldiscs[disc] = NULL;
44330@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
44331 if (ldops) {
44332 ret = ERR_PTR(-EAGAIN);
44333 if (try_module_get(ldops->owner)) {
44334- ldops->refcount++;
44335+ atomic_inc(&ldops->refcount);
44336 ret = ldops;
44337 }
44338 }
44339@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
44340 unsigned long flags;
44341
44342 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44343- ldops->refcount--;
44344+ atomic_dec(&ldops->refcount);
44345 module_put(ldops->owner);
44346 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44347 }
44348@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
44349 /* unreleased reader reference(s) will cause this WARN */
44350 WARN_ON(!atomic_dec_and_test(&ld->users));
44351
44352- ld->ops->refcount--;
44353+ atomic_dec(&ld->ops->refcount);
44354 module_put(ld->ops->owner);
44355 kfree(ld);
44356 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44357diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
44358index 121aeb9..0d2c4b9 100644
44359--- a/drivers/tty/tty_port.c
44360+++ b/drivers/tty/tty_port.c
44361@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
44362 unsigned long flags;
44363
44364 spin_lock_irqsave(&port->lock, flags);
44365- port->count = 0;
44366+ atomic_set(&port->count, 0);
44367 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44368 tty = port->tty;
44369 if (tty)
44370@@ -391,7 +391,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44371 /* The port lock protects the port counts */
44372 spin_lock_irqsave(&port->lock, flags);
44373 if (!tty_hung_up_p(filp))
44374- port->count--;
44375+ atomic_dec(&port->count);
44376 port->blocked_open++;
44377 spin_unlock_irqrestore(&port->lock, flags);
44378
44379@@ -433,7 +433,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44380 we must not mess that up further */
44381 spin_lock_irqsave(&port->lock, flags);
44382 if (!tty_hung_up_p(filp))
44383- port->count++;
44384+ atomic_inc(&port->count);
44385 port->blocked_open--;
44386 if (retval == 0)
44387 port->flags |= ASYNC_NORMAL_ACTIVE;
44388@@ -467,19 +467,19 @@ int tty_port_close_start(struct tty_port *port,
44389 return 0;
44390 }
44391
44392- if (tty->count == 1 && port->count != 1) {
44393+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
44394 printk(KERN_WARNING
44395 "tty_port_close_start: tty->count = 1 port count = %d.\n",
44396- port->count);
44397- port->count = 1;
44398+ atomic_read(&port->count));
44399+ atomic_set(&port->count, 1);
44400 }
44401- if (--port->count < 0) {
44402+ if (atomic_dec_return(&port->count) < 0) {
44403 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
44404- port->count);
44405- port->count = 0;
44406+ atomic_read(&port->count));
44407+ atomic_set(&port->count, 0);
44408 }
44409
44410- if (port->count) {
44411+ if (atomic_read(&port->count)) {
44412 spin_unlock_irqrestore(&port->lock, flags);
44413 if (port->ops->drop)
44414 port->ops->drop(port);
44415@@ -565,7 +565,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
44416 {
44417 spin_lock_irq(&port->lock);
44418 if (!tty_hung_up_p(filp))
44419- ++port->count;
44420+ atomic_inc(&port->count);
44421 spin_unlock_irq(&port->lock);
44422 tty_port_tty_set(port, tty);
44423
44424diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
44425index a9af1b9a..1e08e7f 100644
44426--- a/drivers/tty/vt/keyboard.c
44427+++ b/drivers/tty/vt/keyboard.c
44428@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
44429 kbd->kbdmode == VC_OFF) &&
44430 value != KVAL(K_SAK))
44431 return; /* SAK is allowed even in raw mode */
44432+
44433+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
44434+ {
44435+ void *func = fn_handler[value];
44436+ if (func == fn_show_state || func == fn_show_ptregs ||
44437+ func == fn_show_mem)
44438+ return;
44439+ }
44440+#endif
44441+
44442 fn_handler[value](vc);
44443 }
44444
44445@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44446 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
44447 return -EFAULT;
44448
44449- if (!capable(CAP_SYS_TTY_CONFIG))
44450- perm = 0;
44451-
44452 switch (cmd) {
44453 case KDGKBENT:
44454 /* Ensure another thread doesn't free it under us */
44455@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44456 spin_unlock_irqrestore(&kbd_event_lock, flags);
44457 return put_user(val, &user_kbe->kb_value);
44458 case KDSKBENT:
44459+ if (!capable(CAP_SYS_TTY_CONFIG))
44460+ perm = 0;
44461+
44462 if (!perm)
44463 return -EPERM;
44464 if (!i && v == K_NOSUCHMAP) {
44465@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44466 int i, j, k;
44467 int ret;
44468
44469- if (!capable(CAP_SYS_TTY_CONFIG))
44470- perm = 0;
44471-
44472 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
44473 if (!kbs) {
44474 ret = -ENOMEM;
44475@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44476 kfree(kbs);
44477 return ((p && *p) ? -EOVERFLOW : 0);
44478 case KDSKBSENT:
44479+ if (!capable(CAP_SYS_TTY_CONFIG))
44480+ perm = 0;
44481+
44482 if (!perm) {
44483 ret = -EPERM;
44484 goto reterr;
44485diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
44486index b645c47..a55c182 100644
44487--- a/drivers/uio/uio.c
44488+++ b/drivers/uio/uio.c
44489@@ -25,6 +25,7 @@
44490 #include <linux/kobject.h>
44491 #include <linux/cdev.h>
44492 #include <linux/uio_driver.h>
44493+#include <asm/local.h>
44494
44495 #define UIO_MAX_DEVICES (1U << MINORBITS)
44496
44497@@ -32,10 +33,10 @@ struct uio_device {
44498 struct module *owner;
44499 struct device *dev;
44500 int minor;
44501- atomic_t event;
44502+ atomic_unchecked_t event;
44503 struct fasync_struct *async_queue;
44504 wait_queue_head_t wait;
44505- int vma_count;
44506+ local_t vma_count;
44507 struct uio_info *info;
44508 struct kobject *map_dir;
44509 struct kobject *portio_dir;
44510@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
44511 struct device_attribute *attr, char *buf)
44512 {
44513 struct uio_device *idev = dev_get_drvdata(dev);
44514- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
44515+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
44516 }
44517
44518 static struct device_attribute uio_class_attributes[] = {
44519@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
44520 {
44521 struct uio_device *idev = info->uio_dev;
44522
44523- atomic_inc(&idev->event);
44524+ atomic_inc_unchecked(&idev->event);
44525 wake_up_interruptible(&idev->wait);
44526 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
44527 }
44528@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
44529 }
44530
44531 listener->dev = idev;
44532- listener->event_count = atomic_read(&idev->event);
44533+ listener->event_count = atomic_read_unchecked(&idev->event);
44534 filep->private_data = listener;
44535
44536 if (idev->info->open) {
44537@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
44538 return -EIO;
44539
44540 poll_wait(filep, &idev->wait, wait);
44541- if (listener->event_count != atomic_read(&idev->event))
44542+ if (listener->event_count != atomic_read_unchecked(&idev->event))
44543 return POLLIN | POLLRDNORM;
44544 return 0;
44545 }
44546@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
44547 do {
44548 set_current_state(TASK_INTERRUPTIBLE);
44549
44550- event_count = atomic_read(&idev->event);
44551+ event_count = atomic_read_unchecked(&idev->event);
44552 if (event_count != listener->event_count) {
44553 if (copy_to_user(buf, &event_count, count))
44554 retval = -EFAULT;
44555@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
44556 static void uio_vma_open(struct vm_area_struct *vma)
44557 {
44558 struct uio_device *idev = vma->vm_private_data;
44559- idev->vma_count++;
44560+ local_inc(&idev->vma_count);
44561 }
44562
44563 static void uio_vma_close(struct vm_area_struct *vma)
44564 {
44565 struct uio_device *idev = vma->vm_private_data;
44566- idev->vma_count--;
44567+ local_dec(&idev->vma_count);
44568 }
44569
44570 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
44571@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
44572 idev->owner = owner;
44573 idev->info = info;
44574 init_waitqueue_head(&idev->wait);
44575- atomic_set(&idev->event, 0);
44576+ atomic_set_unchecked(&idev->event, 0);
44577
44578 ret = uio_get_minor(idev);
44579 if (ret)
44580diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
44581index 8a7eb77..c00402f 100644
44582--- a/drivers/usb/atm/cxacru.c
44583+++ b/drivers/usb/atm/cxacru.c
44584@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
44585 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
44586 if (ret < 2)
44587 return -EINVAL;
44588- if (index < 0 || index > 0x7f)
44589+ if (index > 0x7f)
44590 return -EINVAL;
44591 pos += tmp;
44592
44593diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
44594index d3527dd..26effa2 100644
44595--- a/drivers/usb/atm/usbatm.c
44596+++ b/drivers/usb/atm/usbatm.c
44597@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44598 if (printk_ratelimit())
44599 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
44600 __func__, vpi, vci);
44601- atomic_inc(&vcc->stats->rx_err);
44602+ atomic_inc_unchecked(&vcc->stats->rx_err);
44603 return;
44604 }
44605
44606@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44607 if (length > ATM_MAX_AAL5_PDU) {
44608 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
44609 __func__, length, vcc);
44610- atomic_inc(&vcc->stats->rx_err);
44611+ atomic_inc_unchecked(&vcc->stats->rx_err);
44612 goto out;
44613 }
44614
44615@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44616 if (sarb->len < pdu_length) {
44617 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
44618 __func__, pdu_length, sarb->len, vcc);
44619- atomic_inc(&vcc->stats->rx_err);
44620+ atomic_inc_unchecked(&vcc->stats->rx_err);
44621 goto out;
44622 }
44623
44624 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
44625 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
44626 __func__, vcc);
44627- atomic_inc(&vcc->stats->rx_err);
44628+ atomic_inc_unchecked(&vcc->stats->rx_err);
44629 goto out;
44630 }
44631
44632@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44633 if (printk_ratelimit())
44634 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
44635 __func__, length);
44636- atomic_inc(&vcc->stats->rx_drop);
44637+ atomic_inc_unchecked(&vcc->stats->rx_drop);
44638 goto out;
44639 }
44640
44641@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44642
44643 vcc->push(vcc, skb);
44644
44645- atomic_inc(&vcc->stats->rx);
44646+ atomic_inc_unchecked(&vcc->stats->rx);
44647 out:
44648 skb_trim(sarb, 0);
44649 }
44650@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
44651 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
44652
44653 usbatm_pop(vcc, skb);
44654- atomic_inc(&vcc->stats->tx);
44655+ atomic_inc_unchecked(&vcc->stats->tx);
44656
44657 skb = skb_dequeue(&instance->sndqueue);
44658 }
44659@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
44660 if (!left--)
44661 return sprintf(page,
44662 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
44663- atomic_read(&atm_dev->stats.aal5.tx),
44664- atomic_read(&atm_dev->stats.aal5.tx_err),
44665- atomic_read(&atm_dev->stats.aal5.rx),
44666- atomic_read(&atm_dev->stats.aal5.rx_err),
44667- atomic_read(&atm_dev->stats.aal5.rx_drop));
44668+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
44669+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
44670+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
44671+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
44672+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
44673
44674 if (!left--) {
44675 if (instance->disconnected)
44676diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
44677index 2a3bbdf..91d72cf 100644
44678--- a/drivers/usb/core/devices.c
44679+++ b/drivers/usb/core/devices.c
44680@@ -126,7 +126,7 @@ static const char format_endpt[] =
44681 * time it gets called.
44682 */
44683 static struct device_connect_event {
44684- atomic_t count;
44685+ atomic_unchecked_t count;
44686 wait_queue_head_t wait;
44687 } device_event = {
44688 .count = ATOMIC_INIT(1),
44689@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44690
44691 void usbfs_conn_disc_event(void)
44692 {
44693- atomic_add(2, &device_event.count);
44694+ atomic_add_unchecked(2, &device_event.count);
44695 wake_up(&device_event.wait);
44696 }
44697
44698@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
44699
44700 poll_wait(file, &device_event.wait, wait);
44701
44702- event_count = atomic_read(&device_event.count);
44703+ event_count = atomic_read_unchecked(&device_event.count);
44704 if (file->f_version != event_count) {
44705 file->f_version = event_count;
44706 return POLLIN | POLLRDNORM;
44707diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44708index d53547d..6a22d02 100644
44709--- a/drivers/usb/core/hcd.c
44710+++ b/drivers/usb/core/hcd.c
44711@@ -1526,7 +1526,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44712 */
44713 usb_get_urb(urb);
44714 atomic_inc(&urb->use_count);
44715- atomic_inc(&urb->dev->urbnum);
44716+ atomic_inc_unchecked(&urb->dev->urbnum);
44717 usbmon_urb_submit(&hcd->self, urb);
44718
44719 /* NOTE requirements on root-hub callers (usbfs and the hub
44720@@ -1553,7 +1553,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44721 urb->hcpriv = NULL;
44722 INIT_LIST_HEAD(&urb->urb_list);
44723 atomic_dec(&urb->use_count);
44724- atomic_dec(&urb->dev->urbnum);
44725+ atomic_dec_unchecked(&urb->dev->urbnum);
44726 if (atomic_read(&urb->reject))
44727 wake_up(&usb_kill_urb_queue);
44728 usb_put_urb(urb);
44729diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44730index 444d30e..f15c850 100644
44731--- a/drivers/usb/core/message.c
44732+++ b/drivers/usb/core/message.c
44733@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44734 * method can wait for it to complete. Since you don't have a handle on the
44735 * URB used, you can't cancel the request.
44736 */
44737-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44738+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44739 __u8 requesttype, __u16 value, __u16 index, void *data,
44740 __u16 size, int timeout)
44741 {
44742diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44743index aa38db4..0a08682 100644
44744--- a/drivers/usb/core/sysfs.c
44745+++ b/drivers/usb/core/sysfs.c
44746@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44747 struct usb_device *udev;
44748
44749 udev = to_usb_device(dev);
44750- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44751+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44752 }
44753 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44754
44755diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44756index b10da72..43aa0b2 100644
44757--- a/drivers/usb/core/usb.c
44758+++ b/drivers/usb/core/usb.c
44759@@ -389,7 +389,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44760 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44761 dev->state = USB_STATE_ATTACHED;
44762 dev->lpm_disable_count = 1;
44763- atomic_set(&dev->urbnum, 0);
44764+ atomic_set_unchecked(&dev->urbnum, 0);
44765
44766 INIT_LIST_HEAD(&dev->ep0.urb_list);
44767 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44768diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44769index 5e29dde..eca992f 100644
44770--- a/drivers/usb/early/ehci-dbgp.c
44771+++ b/drivers/usb/early/ehci-dbgp.c
44772@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44773
44774 #ifdef CONFIG_KGDB
44775 static struct kgdb_io kgdbdbgp_io_ops;
44776-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44777+static struct kgdb_io kgdbdbgp_io_ops_console;
44778+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44779 #else
44780 #define dbgp_kgdb_mode (0)
44781 #endif
44782@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44783 .write_char = kgdbdbgp_write_char,
44784 };
44785
44786+static struct kgdb_io kgdbdbgp_io_ops_console = {
44787+ .name = "kgdbdbgp",
44788+ .read_char = kgdbdbgp_read_char,
44789+ .write_char = kgdbdbgp_write_char,
44790+ .is_console = 1
44791+};
44792+
44793 static int kgdbdbgp_wait_time;
44794
44795 static int __init kgdbdbgp_parse_config(char *str)
44796@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44797 ptr++;
44798 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44799 }
44800- kgdb_register_io_module(&kgdbdbgp_io_ops);
44801- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44802+ if (early_dbgp_console.index != -1)
44803+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44804+ else
44805+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44806
44807 return 0;
44808 }
44809diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44810index b369292..9f3ba40 100644
44811--- a/drivers/usb/gadget/u_serial.c
44812+++ b/drivers/usb/gadget/u_serial.c
44813@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44814 spin_lock_irq(&port->port_lock);
44815
44816 /* already open? Great. */
44817- if (port->port.count) {
44818+ if (atomic_read(&port->port.count)) {
44819 status = 0;
44820- port->port.count++;
44821+ atomic_inc(&port->port.count);
44822
44823 /* currently opening/closing? wait ... */
44824 } else if (port->openclose) {
44825@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44826 tty->driver_data = port;
44827 port->port.tty = tty;
44828
44829- port->port.count = 1;
44830+ atomic_set(&port->port.count, 1);
44831 port->openclose = false;
44832
44833 /* if connected, start the I/O stream */
44834@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44835
44836 spin_lock_irq(&port->port_lock);
44837
44838- if (port->port.count != 1) {
44839- if (port->port.count == 0)
44840+ if (atomic_read(&port->port.count) != 1) {
44841+ if (atomic_read(&port->port.count) == 0)
44842 WARN_ON(1);
44843 else
44844- --port->port.count;
44845+ atomic_dec(&port->port.count);
44846 goto exit;
44847 }
44848
44849@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44850 * and sleep if necessary
44851 */
44852 port->openclose = true;
44853- port->port.count = 0;
44854+ atomic_set(&port->port.count, 0);
44855
44856 gser = port->port_usb;
44857 if (gser && gser->disconnect)
44858@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
44859 int cond;
44860
44861 spin_lock_irq(&port->port_lock);
44862- cond = (port->port.count == 0) && !port->openclose;
44863+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44864 spin_unlock_irq(&port->port_lock);
44865 return cond;
44866 }
44867@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44868 /* if it's already open, start I/O ... and notify the serial
44869 * protocol about open/close status (connect/disconnect).
44870 */
44871- if (port->port.count) {
44872+ if (atomic_read(&port->port.count)) {
44873 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44874 gs_start_io(port);
44875 if (gser->connect)
44876@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
44877
44878 port->port_usb = NULL;
44879 gser->ioport = NULL;
44880- if (port->port.count > 0 || port->openclose) {
44881+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44882 wake_up_interruptible(&port->drain_wait);
44883 if (port->port.tty)
44884 tty_hangup(port->port.tty);
44885@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
44886
44887 /* finally, free any unused/unusable I/O buffers */
44888 spin_lock_irqsave(&port->port_lock, flags);
44889- if (port->port.count == 0 && !port->openclose)
44890+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44891 gs_buf_free(&port->port_write_buf);
44892 gs_free_requests(gser->out, &port->read_pool, NULL);
44893 gs_free_requests(gser->out, &port->read_queue, NULL);
44894diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44895index 5f3bcd3..bfca43f 100644
44896--- a/drivers/usb/serial/console.c
44897+++ b/drivers/usb/serial/console.c
44898@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44899
44900 info->port = port;
44901
44902- ++port->port.count;
44903+ atomic_inc(&port->port.count);
44904 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44905 if (serial->type->set_termios) {
44906 /*
44907@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44908 }
44909 /* Now that any required fake tty operations are completed restore
44910 * the tty port count */
44911- --port->port.count;
44912+ atomic_dec(&port->port.count);
44913 /* The console is special in terms of closing the device so
44914 * indicate this port is now acting as a system console. */
44915 port->port.console = 1;
44916@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44917 free_tty:
44918 kfree(tty);
44919 reset_open_count:
44920- port->port.count = 0;
44921+ atomic_set(&port->port.count, 0);
44922 usb_autopm_put_interface(serial->interface);
44923 error_get_interface:
44924 usb_serial_put(serial);
44925diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44926index 75f70f0..d467e1a 100644
44927--- a/drivers/usb/storage/usb.h
44928+++ b/drivers/usb/storage/usb.h
44929@@ -63,7 +63,7 @@ struct us_unusual_dev {
44930 __u8 useProtocol;
44931 __u8 useTransport;
44932 int (*initFunction)(struct us_data *);
44933-};
44934+} __do_const;
44935
44936
44937 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44938diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44939index d6bea3e..60b250e 100644
44940--- a/drivers/usb/wusbcore/wa-hc.h
44941+++ b/drivers/usb/wusbcore/wa-hc.h
44942@@ -192,7 +192,7 @@ struct wahc {
44943 struct list_head xfer_delayed_list;
44944 spinlock_t xfer_list_lock;
44945 struct work_struct xfer_work;
44946- atomic_t xfer_id_count;
44947+ atomic_unchecked_t xfer_id_count;
44948 };
44949
44950
44951@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44952 INIT_LIST_HEAD(&wa->xfer_delayed_list);
44953 spin_lock_init(&wa->xfer_list_lock);
44954 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
44955- atomic_set(&wa->xfer_id_count, 1);
44956+ atomic_set_unchecked(&wa->xfer_id_count, 1);
44957 }
44958
44959 /**
44960diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
44961index 6ef94bc..1b41265 100644
44962--- a/drivers/usb/wusbcore/wa-xfer.c
44963+++ b/drivers/usb/wusbcore/wa-xfer.c
44964@@ -296,7 +296,7 @@ out:
44965 */
44966 static void wa_xfer_id_init(struct wa_xfer *xfer)
44967 {
44968- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
44969+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
44970 }
44971
44972 /*
44973diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
44974index f80d3dd..8ca5ac7 100644
44975--- a/drivers/vhost/net.c
44976+++ b/drivers/vhost/net.c
44977@@ -150,6 +150,11 @@ static void vhost_net_ubuf_put_and_wait(struct vhost_net_ubuf_ref *ubufs)
44978 {
44979 kref_put(&ubufs->kref, vhost_net_zerocopy_done_signal);
44980 wait_event(ubufs->wait, !atomic_read(&ubufs->kref.refcount));
44981+}
44982+
44983+static void vhost_net_ubuf_put_wait_and_free(struct vhost_net_ubuf_ref *ubufs)
44984+{
44985+ vhost_net_ubuf_put_and_wait(ubufs);
44986 kfree(ubufs);
44987 }
44988
44989@@ -948,7 +953,7 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
44990 mutex_unlock(&vq->mutex);
44991
44992 if (oldubufs) {
44993- vhost_net_ubuf_put_and_wait(oldubufs);
44994+ vhost_net_ubuf_put_wait_and_free(oldubufs);
44995 mutex_lock(&vq->mutex);
44996 vhost_zerocopy_signal_used(n, vq);
44997 mutex_unlock(&vq->mutex);
44998@@ -966,7 +971,7 @@ err_used:
44999 rcu_assign_pointer(vq->private_data, oldsock);
45000 vhost_net_enable_vq(n, vq);
45001 if (ubufs)
45002- vhost_net_ubuf_put_and_wait(ubufs);
45003+ vhost_net_ubuf_put_wait_and_free(ubufs);
45004 err_ubufs:
45005 fput(sock->file);
45006 err_vq:
45007diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
45008index 5174eba..86e764a 100644
45009--- a/drivers/vhost/vringh.c
45010+++ b/drivers/vhost/vringh.c
45011@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
45012
45013 static inline int putu16_kern(u16 *p, u16 val)
45014 {
45015- ACCESS_ONCE(*p) = val;
45016+ ACCESS_ONCE_RW(*p) = val;
45017 return 0;
45018 }
45019
45020diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
45021index 8c55011..eed4ae1a 100644
45022--- a/drivers/video/aty/aty128fb.c
45023+++ b/drivers/video/aty/aty128fb.c
45024@@ -149,7 +149,7 @@ enum {
45025 };
45026
45027 /* Must match above enum */
45028-static char * const r128_family[] = {
45029+static const char * const r128_family[] = {
45030 "AGP",
45031 "PCI",
45032 "PRO AGP",
45033diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
45034index 4f27fdc..d3537e6 100644
45035--- a/drivers/video/aty/atyfb_base.c
45036+++ b/drivers/video/aty/atyfb_base.c
45037@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
45038 par->accel_flags = var->accel_flags; /* hack */
45039
45040 if (var->accel_flags) {
45041- info->fbops->fb_sync = atyfb_sync;
45042+ pax_open_kernel();
45043+ *(void **)&info->fbops->fb_sync = atyfb_sync;
45044+ pax_close_kernel();
45045 info->flags &= ~FBINFO_HWACCEL_DISABLED;
45046 } else {
45047- info->fbops->fb_sync = NULL;
45048+ pax_open_kernel();
45049+ *(void **)&info->fbops->fb_sync = NULL;
45050+ pax_close_kernel();
45051 info->flags |= FBINFO_HWACCEL_DISABLED;
45052 }
45053
45054diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
45055index 95ec042..e6affdd 100644
45056--- a/drivers/video/aty/mach64_cursor.c
45057+++ b/drivers/video/aty/mach64_cursor.c
45058@@ -7,6 +7,7 @@
45059 #include <linux/string.h>
45060
45061 #include <asm/io.h>
45062+#include <asm/pgtable.h>
45063
45064 #ifdef __sparc__
45065 #include <asm/fbio.h>
45066@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
45067 info->sprite.buf_align = 16; /* and 64 lines tall. */
45068 info->sprite.flags = FB_PIXMAP_IO;
45069
45070- info->fbops->fb_cursor = atyfb_cursor;
45071+ pax_open_kernel();
45072+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
45073+ pax_close_kernel();
45074
45075 return 0;
45076 }
45077diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
45078index bca6ccc..252107e 100644
45079--- a/drivers/video/backlight/kb3886_bl.c
45080+++ b/drivers/video/backlight/kb3886_bl.c
45081@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
45082 static unsigned long kb3886bl_flags;
45083 #define KB3886BL_SUSPENDED 0x01
45084
45085-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
45086+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
45087 {
45088 .ident = "Sahara Touch-iT",
45089 .matches = {
45090diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
45091index 900aa4e..6d49418 100644
45092--- a/drivers/video/fb_defio.c
45093+++ b/drivers/video/fb_defio.c
45094@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
45095
45096 BUG_ON(!fbdefio);
45097 mutex_init(&fbdefio->lock);
45098- info->fbops->fb_mmap = fb_deferred_io_mmap;
45099+ pax_open_kernel();
45100+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
45101+ pax_close_kernel();
45102 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
45103 INIT_LIST_HEAD(&fbdefio->pagelist);
45104 if (fbdefio->delay == 0) /* set a default of 1 s */
45105@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
45106 page->mapping = NULL;
45107 }
45108
45109- info->fbops->fb_mmap = NULL;
45110+ *(void **)&info->fbops->fb_mmap = NULL;
45111 mutex_destroy(&fbdefio->lock);
45112 }
45113 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
45114diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
45115index 5c3960d..15cf8fc 100644
45116--- a/drivers/video/fbcmap.c
45117+++ b/drivers/video/fbcmap.c
45118@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
45119 rc = -ENODEV;
45120 goto out;
45121 }
45122- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
45123- !info->fbops->fb_setcmap)) {
45124+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
45125 rc = -EINVAL;
45126 goto out1;
45127 }
45128diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
45129index 098bfc6..796841d 100644
45130--- a/drivers/video/fbmem.c
45131+++ b/drivers/video/fbmem.c
45132@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45133 image->dx += image->width + 8;
45134 }
45135 } else if (rotate == FB_ROTATE_UD) {
45136- for (x = 0; x < num && image->dx >= 0; x++) {
45137+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
45138 info->fbops->fb_imageblit(info, image);
45139 image->dx -= image->width + 8;
45140 }
45141@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45142 image->dy += image->height + 8;
45143 }
45144 } else if (rotate == FB_ROTATE_CCW) {
45145- for (x = 0; x < num && image->dy >= 0; x++) {
45146+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
45147 info->fbops->fb_imageblit(info, image);
45148 image->dy -= image->height + 8;
45149 }
45150@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
45151 return -EFAULT;
45152 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
45153 return -EINVAL;
45154- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
45155+ if (con2fb.framebuffer >= FB_MAX)
45156 return -EINVAL;
45157 if (!registered_fb[con2fb.framebuffer])
45158 request_module("fb%d", con2fb.framebuffer);
45159diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
45160index 7672d2e..b56437f 100644
45161--- a/drivers/video/i810/i810_accel.c
45162+++ b/drivers/video/i810/i810_accel.c
45163@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
45164 }
45165 }
45166 printk("ringbuffer lockup!!!\n");
45167+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
45168 i810_report_error(mmio);
45169 par->dev_flags |= LOCKUP;
45170 info->pixmap.scan_align = 1;
45171diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
45172index 3c14e43..eafa544 100644
45173--- a/drivers/video/logo/logo_linux_clut224.ppm
45174+++ b/drivers/video/logo/logo_linux_clut224.ppm
45175@@ -1,1604 +1,1123 @@
45176 P3
45177-# Standard 224-color Linux logo
45178 80 80
45179 255
45180- 0 0 0 0 0 0 0 0 0 0 0 0
45181- 0 0 0 0 0 0 0 0 0 0 0 0
45182- 0 0 0 0 0 0 0 0 0 0 0 0
45183- 0 0 0 0 0 0 0 0 0 0 0 0
45184- 0 0 0 0 0 0 0 0 0 0 0 0
45185- 0 0 0 0 0 0 0 0 0 0 0 0
45186- 0 0 0 0 0 0 0 0 0 0 0 0
45187- 0 0 0 0 0 0 0 0 0 0 0 0
45188- 0 0 0 0 0 0 0 0 0 0 0 0
45189- 6 6 6 6 6 6 10 10 10 10 10 10
45190- 10 10 10 6 6 6 6 6 6 6 6 6
45191- 0 0 0 0 0 0 0 0 0 0 0 0
45192- 0 0 0 0 0 0 0 0 0 0 0 0
45193- 0 0 0 0 0 0 0 0 0 0 0 0
45194- 0 0 0 0 0 0 0 0 0 0 0 0
45195- 0 0 0 0 0 0 0 0 0 0 0 0
45196- 0 0 0 0 0 0 0 0 0 0 0 0
45197- 0 0 0 0 0 0 0 0 0 0 0 0
45198- 0 0 0 0 0 0 0 0 0 0 0 0
45199- 0 0 0 0 0 0 0 0 0 0 0 0
45200- 0 0 0 0 0 0 0 0 0 0 0 0
45201- 0 0 0 0 0 0 0 0 0 0 0 0
45202- 0 0 0 0 0 0 0 0 0 0 0 0
45203- 0 0 0 0 0 0 0 0 0 0 0 0
45204- 0 0 0 0 0 0 0 0 0 0 0 0
45205- 0 0 0 0 0 0 0 0 0 0 0 0
45206- 0 0 0 0 0 0 0 0 0 0 0 0
45207- 0 0 0 0 0 0 0 0 0 0 0 0
45208- 0 0 0 6 6 6 10 10 10 14 14 14
45209- 22 22 22 26 26 26 30 30 30 34 34 34
45210- 30 30 30 30 30 30 26 26 26 18 18 18
45211- 14 14 14 10 10 10 6 6 6 0 0 0
45212- 0 0 0 0 0 0 0 0 0 0 0 0
45213- 0 0 0 0 0 0 0 0 0 0 0 0
45214- 0 0 0 0 0 0 0 0 0 0 0 0
45215- 0 0 0 0 0 0 0 0 0 0 0 0
45216- 0 0 0 0 0 0 0 0 0 0 0 0
45217- 0 0 0 0 0 0 0 0 0 0 0 0
45218- 0 0 0 0 0 0 0 0 0 0 0 0
45219- 0 0 0 0 0 0 0 0 0 0 0 0
45220- 0 0 0 0 0 0 0 0 0 0 0 0
45221- 0 0 0 0 0 1 0 0 1 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- 6 6 6 14 14 14 26 26 26 42 42 42
45229- 54 54 54 66 66 66 78 78 78 78 78 78
45230- 78 78 78 74 74 74 66 66 66 54 54 54
45231- 42 42 42 26 26 26 18 18 18 10 10 10
45232- 6 6 6 0 0 0 0 0 0 0 0 0
45233- 0 0 0 0 0 0 0 0 0 0 0 0
45234- 0 0 0 0 0 0 0 0 0 0 0 0
45235- 0 0 0 0 0 0 0 0 0 0 0 0
45236- 0 0 0 0 0 0 0 0 0 0 0 0
45237- 0 0 0 0 0 0 0 0 0 0 0 0
45238- 0 0 0 0 0 0 0 0 0 0 0 0
45239- 0 0 0 0 0 0 0 0 0 0 0 0
45240- 0 0 0 0 0 0 0 0 0 0 0 0
45241- 0 0 1 0 0 0 0 0 0 0 0 0
45242- 0 0 0 0 0 0 0 0 0 0 0 0
45243- 0 0 0 0 0 0 0 0 0 0 0 0
45244- 0 0 0 0 0 0 0 0 0 0 0 0
45245- 0 0 0 0 0 0 0 0 0 0 0 0
45246- 0 0 0 0 0 0 0 0 0 0 0 0
45247- 0 0 0 0 0 0 0 0 0 10 10 10
45248- 22 22 22 42 42 42 66 66 66 86 86 86
45249- 66 66 66 38 38 38 38 38 38 22 22 22
45250- 26 26 26 34 34 34 54 54 54 66 66 66
45251- 86 86 86 70 70 70 46 46 46 26 26 26
45252- 14 14 14 6 6 6 0 0 0 0 0 0
45253- 0 0 0 0 0 0 0 0 0 0 0 0
45254- 0 0 0 0 0 0 0 0 0 0 0 0
45255- 0 0 0 0 0 0 0 0 0 0 0 0
45256- 0 0 0 0 0 0 0 0 0 0 0 0
45257- 0 0 0 0 0 0 0 0 0 0 0 0
45258- 0 0 0 0 0 0 0 0 0 0 0 0
45259- 0 0 0 0 0 0 0 0 0 0 0 0
45260- 0 0 0 0 0 0 0 0 0 0 0 0
45261- 0 0 1 0 0 1 0 0 1 0 0 0
45262- 0 0 0 0 0 0 0 0 0 0 0 0
45263- 0 0 0 0 0 0 0 0 0 0 0 0
45264- 0 0 0 0 0 0 0 0 0 0 0 0
45265- 0 0 0 0 0 0 0 0 0 0 0 0
45266- 0 0 0 0 0 0 0 0 0 0 0 0
45267- 0 0 0 0 0 0 10 10 10 26 26 26
45268- 50 50 50 82 82 82 58 58 58 6 6 6
45269- 2 2 6 2 2 6 2 2 6 2 2 6
45270- 2 2 6 2 2 6 2 2 6 2 2 6
45271- 6 6 6 54 54 54 86 86 86 66 66 66
45272- 38 38 38 18 18 18 6 6 6 0 0 0
45273- 0 0 0 0 0 0 0 0 0 0 0 0
45274- 0 0 0 0 0 0 0 0 0 0 0 0
45275- 0 0 0 0 0 0 0 0 0 0 0 0
45276- 0 0 0 0 0 0 0 0 0 0 0 0
45277- 0 0 0 0 0 0 0 0 0 0 0 0
45278- 0 0 0 0 0 0 0 0 0 0 0 0
45279- 0 0 0 0 0 0 0 0 0 0 0 0
45280- 0 0 0 0 0 0 0 0 0 0 0 0
45281- 0 0 0 0 0 0 0 0 0 0 0 0
45282- 0 0 0 0 0 0 0 0 0 0 0 0
45283- 0 0 0 0 0 0 0 0 0 0 0 0
45284- 0 0 0 0 0 0 0 0 0 0 0 0
45285- 0 0 0 0 0 0 0 0 0 0 0 0
45286- 0 0 0 0 0 0 0 0 0 0 0 0
45287- 0 0 0 6 6 6 22 22 22 50 50 50
45288- 78 78 78 34 34 34 2 2 6 2 2 6
45289- 2 2 6 2 2 6 2 2 6 2 2 6
45290- 2 2 6 2 2 6 2 2 6 2 2 6
45291- 2 2 6 2 2 6 6 6 6 70 70 70
45292- 78 78 78 46 46 46 22 22 22 6 6 6
45293- 0 0 0 0 0 0 0 0 0 0 0 0
45294- 0 0 0 0 0 0 0 0 0 0 0 0
45295- 0 0 0 0 0 0 0 0 0 0 0 0
45296- 0 0 0 0 0 0 0 0 0 0 0 0
45297- 0 0 0 0 0 0 0 0 0 0 0 0
45298- 0 0 0 0 0 0 0 0 0 0 0 0
45299- 0 0 0 0 0 0 0 0 0 0 0 0
45300- 0 0 0 0 0 0 0 0 0 0 0 0
45301- 0 0 1 0 0 1 0 0 1 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- 6 6 6 18 18 18 42 42 42 82 82 82
45308- 26 26 26 2 2 6 2 2 6 2 2 6
45309- 2 2 6 2 2 6 2 2 6 2 2 6
45310- 2 2 6 2 2 6 2 2 6 14 14 14
45311- 46 46 46 34 34 34 6 6 6 2 2 6
45312- 42 42 42 78 78 78 42 42 42 18 18 18
45313- 6 6 6 0 0 0 0 0 0 0 0 0
45314- 0 0 0 0 0 0 0 0 0 0 0 0
45315- 0 0 0 0 0 0 0 0 0 0 0 0
45316- 0 0 0 0 0 0 0 0 0 0 0 0
45317- 0 0 0 0 0 0 0 0 0 0 0 0
45318- 0 0 0 0 0 0 0 0 0 0 0 0
45319- 0 0 0 0 0 0 0 0 0 0 0 0
45320- 0 0 0 0 0 0 0 0 0 0 0 0
45321- 0 0 1 0 0 0 0 0 1 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 0 0 0 0 0 0 0
45327- 10 10 10 30 30 30 66 66 66 58 58 58
45328- 2 2 6 2 2 6 2 2 6 2 2 6
45329- 2 2 6 2 2 6 2 2 6 2 2 6
45330- 2 2 6 2 2 6 2 2 6 26 26 26
45331- 86 86 86 101 101 101 46 46 46 10 10 10
45332- 2 2 6 58 58 58 70 70 70 34 34 34
45333- 10 10 10 0 0 0 0 0 0 0 0 0
45334- 0 0 0 0 0 0 0 0 0 0 0 0
45335- 0 0 0 0 0 0 0 0 0 0 0 0
45336- 0 0 0 0 0 0 0 0 0 0 0 0
45337- 0 0 0 0 0 0 0 0 0 0 0 0
45338- 0 0 0 0 0 0 0 0 0 0 0 0
45339- 0 0 0 0 0 0 0 0 0 0 0 0
45340- 0 0 0 0 0 0 0 0 0 0 0 0
45341- 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
45347- 14 14 14 42 42 42 86 86 86 10 10 10
45348- 2 2 6 2 2 6 2 2 6 2 2 6
45349- 2 2 6 2 2 6 2 2 6 2 2 6
45350- 2 2 6 2 2 6 2 2 6 30 30 30
45351- 94 94 94 94 94 94 58 58 58 26 26 26
45352- 2 2 6 6 6 6 78 78 78 54 54 54
45353- 22 22 22 6 6 6 0 0 0 0 0 0
45354- 0 0 0 0 0 0 0 0 0 0 0 0
45355- 0 0 0 0 0 0 0 0 0 0 0 0
45356- 0 0 0 0 0 0 0 0 0 0 0 0
45357- 0 0 0 0 0 0 0 0 0 0 0 0
45358- 0 0 0 0 0 0 0 0 0 0 0 0
45359- 0 0 0 0 0 0 0 0 0 0 0 0
45360- 0 0 0 0 0 0 0 0 0 0 0 0
45361- 0 0 0 0 0 0 0 0 0 0 0 0
45362- 0 0 0 0 0 0 0 0 0 0 0 0
45363- 0 0 0 0 0 0 0 0 0 0 0 0
45364- 0 0 0 0 0 0 0 0 0 0 0 0
45365- 0 0 0 0 0 0 0 0 0 0 0 0
45366- 0 0 0 0 0 0 0 0 0 6 6 6
45367- 22 22 22 62 62 62 62 62 62 2 2 6
45368- 2 2 6 2 2 6 2 2 6 2 2 6
45369- 2 2 6 2 2 6 2 2 6 2 2 6
45370- 2 2 6 2 2 6 2 2 6 26 26 26
45371- 54 54 54 38 38 38 18 18 18 10 10 10
45372- 2 2 6 2 2 6 34 34 34 82 82 82
45373- 38 38 38 14 14 14 0 0 0 0 0 0
45374- 0 0 0 0 0 0 0 0 0 0 0 0
45375- 0 0 0 0 0 0 0 0 0 0 0 0
45376- 0 0 0 0 0 0 0 0 0 0 0 0
45377- 0 0 0 0 0 0 0 0 0 0 0 0
45378- 0 0 0 0 0 0 0 0 0 0 0 0
45379- 0 0 0 0 0 0 0 0 0 0 0 0
45380- 0 0 0 0 0 0 0 0 0 0 0 0
45381- 0 0 0 0 0 1 0 0 1 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 0 0 0 0 0 0 0 6 6 6
45387- 30 30 30 78 78 78 30 30 30 2 2 6
45388- 2 2 6 2 2 6 2 2 6 2 2 6
45389- 2 2 6 2 2 6 2 2 6 2 2 6
45390- 2 2 6 2 2 6 2 2 6 10 10 10
45391- 10 10 10 2 2 6 2 2 6 2 2 6
45392- 2 2 6 2 2 6 2 2 6 78 78 78
45393- 50 50 50 18 18 18 6 6 6 0 0 0
45394- 0 0 0 0 0 0 0 0 0 0 0 0
45395- 0 0 0 0 0 0 0 0 0 0 0 0
45396- 0 0 0 0 0 0 0 0 0 0 0 0
45397- 0 0 0 0 0 0 0 0 0 0 0 0
45398- 0 0 0 0 0 0 0 0 0 0 0 0
45399- 0 0 0 0 0 0 0 0 0 0 0 0
45400- 0 0 0 0 0 0 0 0 0 0 0 0
45401- 0 0 1 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 0 0 0 0 0 0 0 10 10 10
45407- 38 38 38 86 86 86 14 14 14 2 2 6
45408- 2 2 6 2 2 6 2 2 6 2 2 6
45409- 2 2 6 2 2 6 2 2 6 2 2 6
45410- 2 2 6 2 2 6 2 2 6 2 2 6
45411- 2 2 6 2 2 6 2 2 6 2 2 6
45412- 2 2 6 2 2 6 2 2 6 54 54 54
45413- 66 66 66 26 26 26 6 6 6 0 0 0
45414- 0 0 0 0 0 0 0 0 0 0 0 0
45415- 0 0 0 0 0 0 0 0 0 0 0 0
45416- 0 0 0 0 0 0 0 0 0 0 0 0
45417- 0 0 0 0 0 0 0 0 0 0 0 0
45418- 0 0 0 0 0 0 0 0 0 0 0 0
45419- 0 0 0 0 0 0 0 0 0 0 0 0
45420- 0 0 0 0 0 0 0 0 0 0 0 0
45421- 0 0 0 0 0 1 0 0 1 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 14 14 14
45427- 42 42 42 82 82 82 2 2 6 2 2 6
45428- 2 2 6 6 6 6 10 10 10 2 2 6
45429- 2 2 6 2 2 6 2 2 6 2 2 6
45430- 2 2 6 2 2 6 2 2 6 6 6 6
45431- 14 14 14 10 10 10 2 2 6 2 2 6
45432- 2 2 6 2 2 6 2 2 6 18 18 18
45433- 82 82 82 34 34 34 10 10 10 0 0 0
45434- 0 0 0 0 0 0 0 0 0 0 0 0
45435- 0 0 0 0 0 0 0 0 0 0 0 0
45436- 0 0 0 0 0 0 0 0 0 0 0 0
45437- 0 0 0 0 0 0 0 0 0 0 0 0
45438- 0 0 0 0 0 0 0 0 0 0 0 0
45439- 0 0 0 0 0 0 0 0 0 0 0 0
45440- 0 0 0 0 0 0 0 0 0 0 0 0
45441- 0 0 1 0 0 0 0 0 0 0 0 0
45442- 0 0 0 0 0 0 0 0 0 0 0 0
45443- 0 0 0 0 0 0 0 0 0 0 0 0
45444- 0 0 0 0 0 0 0 0 0 0 0 0
45445- 0 0 0 0 0 0 0 0 0 0 0 0
45446- 0 0 0 0 0 0 0 0 0 14 14 14
45447- 46 46 46 86 86 86 2 2 6 2 2 6
45448- 6 6 6 6 6 6 22 22 22 34 34 34
45449- 6 6 6 2 2 6 2 2 6 2 2 6
45450- 2 2 6 2 2 6 18 18 18 34 34 34
45451- 10 10 10 50 50 50 22 22 22 2 2 6
45452- 2 2 6 2 2 6 2 2 6 10 10 10
45453- 86 86 86 42 42 42 14 14 14 0 0 0
45454- 0 0 0 0 0 0 0 0 0 0 0 0
45455- 0 0 0 0 0 0 0 0 0 0 0 0
45456- 0 0 0 0 0 0 0 0 0 0 0 0
45457- 0 0 0 0 0 0 0 0 0 0 0 0
45458- 0 0 0 0 0 0 0 0 0 0 0 0
45459- 0 0 0 0 0 0 0 0 0 0 0 0
45460- 0 0 0 0 0 0 0 0 0 0 0 0
45461- 0 0 1 0 0 1 0 0 1 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 14 14 14
45467- 46 46 46 86 86 86 2 2 6 2 2 6
45468- 38 38 38 116 116 116 94 94 94 22 22 22
45469- 22 22 22 2 2 6 2 2 6 2 2 6
45470- 14 14 14 86 86 86 138 138 138 162 162 162
45471-154 154 154 38 38 38 26 26 26 6 6 6
45472- 2 2 6 2 2 6 2 2 6 2 2 6
45473- 86 86 86 46 46 46 14 14 14 0 0 0
45474- 0 0 0 0 0 0 0 0 0 0 0 0
45475- 0 0 0 0 0 0 0 0 0 0 0 0
45476- 0 0 0 0 0 0 0 0 0 0 0 0
45477- 0 0 0 0 0 0 0 0 0 0 0 0
45478- 0 0 0 0 0 0 0 0 0 0 0 0
45479- 0 0 0 0 0 0 0 0 0 0 0 0
45480- 0 0 0 0 0 0 0 0 0 0 0 0
45481- 0 0 0 0 0 0 0 0 0 0 0 0
45482- 0 0 0 0 0 0 0 0 0 0 0 0
45483- 0 0 0 0 0 0 0 0 0 0 0 0
45484- 0 0 0 0 0 0 0 0 0 0 0 0
45485- 0 0 0 0 0 0 0 0 0 0 0 0
45486- 0 0 0 0 0 0 0 0 0 14 14 14
45487- 46 46 46 86 86 86 2 2 6 14 14 14
45488-134 134 134 198 198 198 195 195 195 116 116 116
45489- 10 10 10 2 2 6 2 2 6 6 6 6
45490-101 98 89 187 187 187 210 210 210 218 218 218
45491-214 214 214 134 134 134 14 14 14 6 6 6
45492- 2 2 6 2 2 6 2 2 6 2 2 6
45493- 86 86 86 50 50 50 18 18 18 6 6 6
45494- 0 0 0 0 0 0 0 0 0 0 0 0
45495- 0 0 0 0 0 0 0 0 0 0 0 0
45496- 0 0 0 0 0 0 0 0 0 0 0 0
45497- 0 0 0 0 0 0 0 0 0 0 0 0
45498- 0 0 0 0 0 0 0 0 0 0 0 0
45499- 0 0 0 0 0 0 0 0 0 0 0 0
45500- 0 0 0 0 0 0 0 0 1 0 0 0
45501- 0 0 1 0 0 1 0 0 1 0 0 0
45502- 0 0 0 0 0 0 0 0 0 0 0 0
45503- 0 0 0 0 0 0 0 0 0 0 0 0
45504- 0 0 0 0 0 0 0 0 0 0 0 0
45505- 0 0 0 0 0 0 0 0 0 0 0 0
45506- 0 0 0 0 0 0 0 0 0 14 14 14
45507- 46 46 46 86 86 86 2 2 6 54 54 54
45508-218 218 218 195 195 195 226 226 226 246 246 246
45509- 58 58 58 2 2 6 2 2 6 30 30 30
45510-210 210 210 253 253 253 174 174 174 123 123 123
45511-221 221 221 234 234 234 74 74 74 2 2 6
45512- 2 2 6 2 2 6 2 2 6 2 2 6
45513- 70 70 70 58 58 58 22 22 22 6 6 6
45514- 0 0 0 0 0 0 0 0 0 0 0 0
45515- 0 0 0 0 0 0 0 0 0 0 0 0
45516- 0 0 0 0 0 0 0 0 0 0 0 0
45517- 0 0 0 0 0 0 0 0 0 0 0 0
45518- 0 0 0 0 0 0 0 0 0 0 0 0
45519- 0 0 0 0 0 0 0 0 0 0 0 0
45520- 0 0 0 0 0 0 0 0 0 0 0 0
45521- 0 0 0 0 0 0 0 0 0 0 0 0
45522- 0 0 0 0 0 0 0 0 0 0 0 0
45523- 0 0 0 0 0 0 0 0 0 0 0 0
45524- 0 0 0 0 0 0 0 0 0 0 0 0
45525- 0 0 0 0 0 0 0 0 0 0 0 0
45526- 0 0 0 0 0 0 0 0 0 14 14 14
45527- 46 46 46 82 82 82 2 2 6 106 106 106
45528-170 170 170 26 26 26 86 86 86 226 226 226
45529-123 123 123 10 10 10 14 14 14 46 46 46
45530-231 231 231 190 190 190 6 6 6 70 70 70
45531- 90 90 90 238 238 238 158 158 158 2 2 6
45532- 2 2 6 2 2 6 2 2 6 2 2 6
45533- 70 70 70 58 58 58 22 22 22 6 6 6
45534- 0 0 0 0 0 0 0 0 0 0 0 0
45535- 0 0 0 0 0 0 0 0 0 0 0 0
45536- 0 0 0 0 0 0 0 0 0 0 0 0
45537- 0 0 0 0 0 0 0 0 0 0 0 0
45538- 0 0 0 0 0 0 0 0 0 0 0 0
45539- 0 0 0 0 0 0 0 0 0 0 0 0
45540- 0 0 0 0 0 0 0 0 1 0 0 0
45541- 0 0 1 0 0 1 0 0 1 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 14 14 14
45547- 42 42 42 86 86 86 6 6 6 116 116 116
45548-106 106 106 6 6 6 70 70 70 149 149 149
45549-128 128 128 18 18 18 38 38 38 54 54 54
45550-221 221 221 106 106 106 2 2 6 14 14 14
45551- 46 46 46 190 190 190 198 198 198 2 2 6
45552- 2 2 6 2 2 6 2 2 6 2 2 6
45553- 74 74 74 62 62 62 22 22 22 6 6 6
45554- 0 0 0 0 0 0 0 0 0 0 0 0
45555- 0 0 0 0 0 0 0 0 0 0 0 0
45556- 0 0 0 0 0 0 0 0 0 0 0 0
45557- 0 0 0 0 0 0 0 0 0 0 0 0
45558- 0 0 0 0 0 0 0 0 0 0 0 0
45559- 0 0 0 0 0 0 0 0 0 0 0 0
45560- 0 0 0 0 0 0 0 0 1 0 0 0
45561- 0 0 1 0 0 0 0 0 1 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 14 14 14
45567- 42 42 42 94 94 94 14 14 14 101 101 101
45568-128 128 128 2 2 6 18 18 18 116 116 116
45569-118 98 46 121 92 8 121 92 8 98 78 10
45570-162 162 162 106 106 106 2 2 6 2 2 6
45571- 2 2 6 195 195 195 195 195 195 6 6 6
45572- 2 2 6 2 2 6 2 2 6 2 2 6
45573- 74 74 74 62 62 62 22 22 22 6 6 6
45574- 0 0 0 0 0 0 0 0 0 0 0 0
45575- 0 0 0 0 0 0 0 0 0 0 0 0
45576- 0 0 0 0 0 0 0 0 0 0 0 0
45577- 0 0 0 0 0 0 0 0 0 0 0 0
45578- 0 0 0 0 0 0 0 0 0 0 0 0
45579- 0 0 0 0 0 0 0 0 0 0 0 0
45580- 0 0 0 0 0 0 0 0 1 0 0 1
45581- 0 0 1 0 0 0 0 0 1 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 10 10 10
45587- 38 38 38 90 90 90 14 14 14 58 58 58
45588-210 210 210 26 26 26 54 38 6 154 114 10
45589-226 170 11 236 186 11 225 175 15 184 144 12
45590-215 174 15 175 146 61 37 26 9 2 2 6
45591- 70 70 70 246 246 246 138 138 138 2 2 6
45592- 2 2 6 2 2 6 2 2 6 2 2 6
45593- 70 70 70 66 66 66 26 26 26 6 6 6
45594- 0 0 0 0 0 0 0 0 0 0 0 0
45595- 0 0 0 0 0 0 0 0 0 0 0 0
45596- 0 0 0 0 0 0 0 0 0 0 0 0
45597- 0 0 0 0 0 0 0 0 0 0 0 0
45598- 0 0 0 0 0 0 0 0 0 0 0 0
45599- 0 0 0 0 0 0 0 0 0 0 0 0
45600- 0 0 0 0 0 0 0 0 0 0 0 0
45601- 0 0 0 0 0 0 0 0 0 0 0 0
45602- 0 0 0 0 0 0 0 0 0 0 0 0
45603- 0 0 0 0 0 0 0 0 0 0 0 0
45604- 0 0 0 0 0 0 0 0 0 0 0 0
45605- 0 0 0 0 0 0 0 0 0 0 0 0
45606- 0 0 0 0 0 0 0 0 0 10 10 10
45607- 38 38 38 86 86 86 14 14 14 10 10 10
45608-195 195 195 188 164 115 192 133 9 225 175 15
45609-239 182 13 234 190 10 232 195 16 232 200 30
45610-245 207 45 241 208 19 232 195 16 184 144 12
45611-218 194 134 211 206 186 42 42 42 2 2 6
45612- 2 2 6 2 2 6 2 2 6 2 2 6
45613- 50 50 50 74 74 74 30 30 30 6 6 6
45614- 0 0 0 0 0 0 0 0 0 0 0 0
45615- 0 0 0 0 0 0 0 0 0 0 0 0
45616- 0 0 0 0 0 0 0 0 0 0 0 0
45617- 0 0 0 0 0 0 0 0 0 0 0 0
45618- 0 0 0 0 0 0 0 0 0 0 0 0
45619- 0 0 0 0 0 0 0 0 0 0 0 0
45620- 0 0 0 0 0 0 0 0 0 0 0 0
45621- 0 0 0 0 0 0 0 0 0 0 0 0
45622- 0 0 0 0 0 0 0 0 0 0 0 0
45623- 0 0 0 0 0 0 0 0 0 0 0 0
45624- 0 0 0 0 0 0 0 0 0 0 0 0
45625- 0 0 0 0 0 0 0 0 0 0 0 0
45626- 0 0 0 0 0 0 0 0 0 10 10 10
45627- 34 34 34 86 86 86 14 14 14 2 2 6
45628-121 87 25 192 133 9 219 162 10 239 182 13
45629-236 186 11 232 195 16 241 208 19 244 214 54
45630-246 218 60 246 218 38 246 215 20 241 208 19
45631-241 208 19 226 184 13 121 87 25 2 2 6
45632- 2 2 6 2 2 6 2 2 6 2 2 6
45633- 50 50 50 82 82 82 34 34 34 10 10 10
45634- 0 0 0 0 0 0 0 0 0 0 0 0
45635- 0 0 0 0 0 0 0 0 0 0 0 0
45636- 0 0 0 0 0 0 0 0 0 0 0 0
45637- 0 0 0 0 0 0 0 0 0 0 0 0
45638- 0 0 0 0 0 0 0 0 0 0 0 0
45639- 0 0 0 0 0 0 0 0 0 0 0 0
45640- 0 0 0 0 0 0 0 0 0 0 0 0
45641- 0 0 0 0 0 0 0 0 0 0 0 0
45642- 0 0 0 0 0 0 0 0 0 0 0 0
45643- 0 0 0 0 0 0 0 0 0 0 0 0
45644- 0 0 0 0 0 0 0 0 0 0 0 0
45645- 0 0 0 0 0 0 0 0 0 0 0 0
45646- 0 0 0 0 0 0 0 0 0 10 10 10
45647- 34 34 34 82 82 82 30 30 30 61 42 6
45648-180 123 7 206 145 10 230 174 11 239 182 13
45649-234 190 10 238 202 15 241 208 19 246 218 74
45650-246 218 38 246 215 20 246 215 20 246 215 20
45651-226 184 13 215 174 15 184 144 12 6 6 6
45652- 2 2 6 2 2 6 2 2 6 2 2 6
45653- 26 26 26 94 94 94 42 42 42 14 14 14
45654- 0 0 0 0 0 0 0 0 0 0 0 0
45655- 0 0 0 0 0 0 0 0 0 0 0 0
45656- 0 0 0 0 0 0 0 0 0 0 0 0
45657- 0 0 0 0 0 0 0 0 0 0 0 0
45658- 0 0 0 0 0 0 0 0 0 0 0 0
45659- 0 0 0 0 0 0 0 0 0 0 0 0
45660- 0 0 0 0 0 0 0 0 0 0 0 0
45661- 0 0 0 0 0 0 0 0 0 0 0 0
45662- 0 0 0 0 0 0 0 0 0 0 0 0
45663- 0 0 0 0 0 0 0 0 0 0 0 0
45664- 0 0 0 0 0 0 0 0 0 0 0 0
45665- 0 0 0 0 0 0 0 0 0 0 0 0
45666- 0 0 0 0 0 0 0 0 0 10 10 10
45667- 30 30 30 78 78 78 50 50 50 104 69 6
45668-192 133 9 216 158 10 236 178 12 236 186 11
45669-232 195 16 241 208 19 244 214 54 245 215 43
45670-246 215 20 246 215 20 241 208 19 198 155 10
45671-200 144 11 216 158 10 156 118 10 2 2 6
45672- 2 2 6 2 2 6 2 2 6 2 2 6
45673- 6 6 6 90 90 90 54 54 54 18 18 18
45674- 6 6 6 0 0 0 0 0 0 0 0 0
45675- 0 0 0 0 0 0 0 0 0 0 0 0
45676- 0 0 0 0 0 0 0 0 0 0 0 0
45677- 0 0 0 0 0 0 0 0 0 0 0 0
45678- 0 0 0 0 0 0 0 0 0 0 0 0
45679- 0 0 0 0 0 0 0 0 0 0 0 0
45680- 0 0 0 0 0 0 0 0 0 0 0 0
45681- 0 0 0 0 0 0 0 0 0 0 0 0
45682- 0 0 0 0 0 0 0 0 0 0 0 0
45683- 0 0 0 0 0 0 0 0 0 0 0 0
45684- 0 0 0 0 0 0 0 0 0 0 0 0
45685- 0 0 0 0 0 0 0 0 0 0 0 0
45686- 0 0 0 0 0 0 0 0 0 10 10 10
45687- 30 30 30 78 78 78 46 46 46 22 22 22
45688-137 92 6 210 162 10 239 182 13 238 190 10
45689-238 202 15 241 208 19 246 215 20 246 215 20
45690-241 208 19 203 166 17 185 133 11 210 150 10
45691-216 158 10 210 150 10 102 78 10 2 2 6
45692- 6 6 6 54 54 54 14 14 14 2 2 6
45693- 2 2 6 62 62 62 74 74 74 30 30 30
45694- 10 10 10 0 0 0 0 0 0 0 0 0
45695- 0 0 0 0 0 0 0 0 0 0 0 0
45696- 0 0 0 0 0 0 0 0 0 0 0 0
45697- 0 0 0 0 0 0 0 0 0 0 0 0
45698- 0 0 0 0 0 0 0 0 0 0 0 0
45699- 0 0 0 0 0 0 0 0 0 0 0 0
45700- 0 0 0 0 0 0 0 0 0 0 0 0
45701- 0 0 0 0 0 0 0 0 0 0 0 0
45702- 0 0 0 0 0 0 0 0 0 0 0 0
45703- 0 0 0 0 0 0 0 0 0 0 0 0
45704- 0 0 0 0 0 0 0 0 0 0 0 0
45705- 0 0 0 0 0 0 0 0 0 0 0 0
45706- 0 0 0 0 0 0 0 0 0 10 10 10
45707- 34 34 34 78 78 78 50 50 50 6 6 6
45708- 94 70 30 139 102 15 190 146 13 226 184 13
45709-232 200 30 232 195 16 215 174 15 190 146 13
45710-168 122 10 192 133 9 210 150 10 213 154 11
45711-202 150 34 182 157 106 101 98 89 2 2 6
45712- 2 2 6 78 78 78 116 116 116 58 58 58
45713- 2 2 6 22 22 22 90 90 90 46 46 46
45714- 18 18 18 6 6 6 0 0 0 0 0 0
45715- 0 0 0 0 0 0 0 0 0 0 0 0
45716- 0 0 0 0 0 0 0 0 0 0 0 0
45717- 0 0 0 0 0 0 0 0 0 0 0 0
45718- 0 0 0 0 0 0 0 0 0 0 0 0
45719- 0 0 0 0 0 0 0 0 0 0 0 0
45720- 0 0 0 0 0 0 0 0 0 0 0 0
45721- 0 0 0 0 0 0 0 0 0 0 0 0
45722- 0 0 0 0 0 0 0 0 0 0 0 0
45723- 0 0 0 0 0 0 0 0 0 0 0 0
45724- 0 0 0 0 0 0 0 0 0 0 0 0
45725- 0 0 0 0 0 0 0 0 0 0 0 0
45726- 0 0 0 0 0 0 0 0 0 10 10 10
45727- 38 38 38 86 86 86 50 50 50 6 6 6
45728-128 128 128 174 154 114 156 107 11 168 122 10
45729-198 155 10 184 144 12 197 138 11 200 144 11
45730-206 145 10 206 145 10 197 138 11 188 164 115
45731-195 195 195 198 198 198 174 174 174 14 14 14
45732- 2 2 6 22 22 22 116 116 116 116 116 116
45733- 22 22 22 2 2 6 74 74 74 70 70 70
45734- 30 30 30 10 10 10 0 0 0 0 0 0
45735- 0 0 0 0 0 0 0 0 0 0 0 0
45736- 0 0 0 0 0 0 0 0 0 0 0 0
45737- 0 0 0 0 0 0 0 0 0 0 0 0
45738- 0 0 0 0 0 0 0 0 0 0 0 0
45739- 0 0 0 0 0 0 0 0 0 0 0 0
45740- 0 0 0 0 0 0 0 0 0 0 0 0
45741- 0 0 0 0 0 0 0 0 0 0 0 0
45742- 0 0 0 0 0 0 0 0 0 0 0 0
45743- 0 0 0 0 0 0 0 0 0 0 0 0
45744- 0 0 0 0 0 0 0 0 0 0 0 0
45745- 0 0 0 0 0 0 0 0 0 0 0 0
45746- 0 0 0 0 0 0 6 6 6 18 18 18
45747- 50 50 50 101 101 101 26 26 26 10 10 10
45748-138 138 138 190 190 190 174 154 114 156 107 11
45749-197 138 11 200 144 11 197 138 11 192 133 9
45750-180 123 7 190 142 34 190 178 144 187 187 187
45751-202 202 202 221 221 221 214 214 214 66 66 66
45752- 2 2 6 2 2 6 50 50 50 62 62 62
45753- 6 6 6 2 2 6 10 10 10 90 90 90
45754- 50 50 50 18 18 18 6 6 6 0 0 0
45755- 0 0 0 0 0 0 0 0 0 0 0 0
45756- 0 0 0 0 0 0 0 0 0 0 0 0
45757- 0 0 0 0 0 0 0 0 0 0 0 0
45758- 0 0 0 0 0 0 0 0 0 0 0 0
45759- 0 0 0 0 0 0 0 0 0 0 0 0
45760- 0 0 0 0 0 0 0 0 0 0 0 0
45761- 0 0 0 0 0 0 0 0 0 0 0 0
45762- 0 0 0 0 0 0 0 0 0 0 0 0
45763- 0 0 0 0 0 0 0 0 0 0 0 0
45764- 0 0 0 0 0 0 0 0 0 0 0 0
45765- 0 0 0 0 0 0 0 0 0 0 0 0
45766- 0 0 0 0 0 0 10 10 10 34 34 34
45767- 74 74 74 74 74 74 2 2 6 6 6 6
45768-144 144 144 198 198 198 190 190 190 178 166 146
45769-154 121 60 156 107 11 156 107 11 168 124 44
45770-174 154 114 187 187 187 190 190 190 210 210 210
45771-246 246 246 253 253 253 253 253 253 182 182 182
45772- 6 6 6 2 2 6 2 2 6 2 2 6
45773- 2 2 6 2 2 6 2 2 6 62 62 62
45774- 74 74 74 34 34 34 14 14 14 0 0 0
45775- 0 0 0 0 0 0 0 0 0 0 0 0
45776- 0 0 0 0 0 0 0 0 0 0 0 0
45777- 0 0 0 0 0 0 0 0 0 0 0 0
45778- 0 0 0 0 0 0 0 0 0 0 0 0
45779- 0 0 0 0 0 0 0 0 0 0 0 0
45780- 0 0 0 0 0 0 0 0 0 0 0 0
45781- 0 0 0 0 0 0 0 0 0 0 0 0
45782- 0 0 0 0 0 0 0 0 0 0 0 0
45783- 0 0 0 0 0 0 0 0 0 0 0 0
45784- 0 0 0 0 0 0 0 0 0 0 0 0
45785- 0 0 0 0 0 0 0 0 0 0 0 0
45786- 0 0 0 10 10 10 22 22 22 54 54 54
45787- 94 94 94 18 18 18 2 2 6 46 46 46
45788-234 234 234 221 221 221 190 190 190 190 190 190
45789-190 190 190 187 187 187 187 187 187 190 190 190
45790-190 190 190 195 195 195 214 214 214 242 242 242
45791-253 253 253 253 253 253 253 253 253 253 253 253
45792- 82 82 82 2 2 6 2 2 6 2 2 6
45793- 2 2 6 2 2 6 2 2 6 14 14 14
45794- 86 86 86 54 54 54 22 22 22 6 6 6
45795- 0 0 0 0 0 0 0 0 0 0 0 0
45796- 0 0 0 0 0 0 0 0 0 0 0 0
45797- 0 0 0 0 0 0 0 0 0 0 0 0
45798- 0 0 0 0 0 0 0 0 0 0 0 0
45799- 0 0 0 0 0 0 0 0 0 0 0 0
45800- 0 0 0 0 0 0 0 0 0 0 0 0
45801- 0 0 0 0 0 0 0 0 0 0 0 0
45802- 0 0 0 0 0 0 0 0 0 0 0 0
45803- 0 0 0 0 0 0 0 0 0 0 0 0
45804- 0 0 0 0 0 0 0 0 0 0 0 0
45805- 0 0 0 0 0 0 0 0 0 0 0 0
45806- 6 6 6 18 18 18 46 46 46 90 90 90
45807- 46 46 46 18 18 18 6 6 6 182 182 182
45808-253 253 253 246 246 246 206 206 206 190 190 190
45809-190 190 190 190 190 190 190 190 190 190 190 190
45810-206 206 206 231 231 231 250 250 250 253 253 253
45811-253 253 253 253 253 253 253 253 253 253 253 253
45812-202 202 202 14 14 14 2 2 6 2 2 6
45813- 2 2 6 2 2 6 2 2 6 2 2 6
45814- 42 42 42 86 86 86 42 42 42 18 18 18
45815- 6 6 6 0 0 0 0 0 0 0 0 0
45816- 0 0 0 0 0 0 0 0 0 0 0 0
45817- 0 0 0 0 0 0 0 0 0 0 0 0
45818- 0 0 0 0 0 0 0 0 0 0 0 0
45819- 0 0 0 0 0 0 0 0 0 0 0 0
45820- 0 0 0 0 0 0 0 0 0 0 0 0
45821- 0 0 0 0 0 0 0 0 0 0 0 0
45822- 0 0 0 0 0 0 0 0 0 0 0 0
45823- 0 0 0 0 0 0 0 0 0 0 0 0
45824- 0 0 0 0 0 0 0 0 0 0 0 0
45825- 0 0 0 0 0 0 0 0 0 6 6 6
45826- 14 14 14 38 38 38 74 74 74 66 66 66
45827- 2 2 6 6 6 6 90 90 90 250 250 250
45828-253 253 253 253 253 253 238 238 238 198 198 198
45829-190 190 190 190 190 190 195 195 195 221 221 221
45830-246 246 246 253 253 253 253 253 253 253 253 253
45831-253 253 253 253 253 253 253 253 253 253 253 253
45832-253 253 253 82 82 82 2 2 6 2 2 6
45833- 2 2 6 2 2 6 2 2 6 2 2 6
45834- 2 2 6 78 78 78 70 70 70 34 34 34
45835- 14 14 14 6 6 6 0 0 0 0 0 0
45836- 0 0 0 0 0 0 0 0 0 0 0 0
45837- 0 0 0 0 0 0 0 0 0 0 0 0
45838- 0 0 0 0 0 0 0 0 0 0 0 0
45839- 0 0 0 0 0 0 0 0 0 0 0 0
45840- 0 0 0 0 0 0 0 0 0 0 0 0
45841- 0 0 0 0 0 0 0 0 0 0 0 0
45842- 0 0 0 0 0 0 0 0 0 0 0 0
45843- 0 0 0 0 0 0 0 0 0 0 0 0
45844- 0 0 0 0 0 0 0 0 0 0 0 0
45845- 0 0 0 0 0 0 0 0 0 14 14 14
45846- 34 34 34 66 66 66 78 78 78 6 6 6
45847- 2 2 6 18 18 18 218 218 218 253 253 253
45848-253 253 253 253 253 253 253 253 253 246 246 246
45849-226 226 226 231 231 231 246 246 246 253 253 253
45850-253 253 253 253 253 253 253 253 253 253 253 253
45851-253 253 253 253 253 253 253 253 253 253 253 253
45852-253 253 253 178 178 178 2 2 6 2 2 6
45853- 2 2 6 2 2 6 2 2 6 2 2 6
45854- 2 2 6 18 18 18 90 90 90 62 62 62
45855- 30 30 30 10 10 10 0 0 0 0 0 0
45856- 0 0 0 0 0 0 0 0 0 0 0 0
45857- 0 0 0 0 0 0 0 0 0 0 0 0
45858- 0 0 0 0 0 0 0 0 0 0 0 0
45859- 0 0 0 0 0 0 0 0 0 0 0 0
45860- 0 0 0 0 0 0 0 0 0 0 0 0
45861- 0 0 0 0 0 0 0 0 0 0 0 0
45862- 0 0 0 0 0 0 0 0 0 0 0 0
45863- 0 0 0 0 0 0 0 0 0 0 0 0
45864- 0 0 0 0 0 0 0 0 0 0 0 0
45865- 0 0 0 0 0 0 10 10 10 26 26 26
45866- 58 58 58 90 90 90 18 18 18 2 2 6
45867- 2 2 6 110 110 110 253 253 253 253 253 253
45868-253 253 253 253 253 253 253 253 253 253 253 253
45869-250 250 250 253 253 253 253 253 253 253 253 253
45870-253 253 253 253 253 253 253 253 253 253 253 253
45871-253 253 253 253 253 253 253 253 253 253 253 253
45872-253 253 253 231 231 231 18 18 18 2 2 6
45873- 2 2 6 2 2 6 2 2 6 2 2 6
45874- 2 2 6 2 2 6 18 18 18 94 94 94
45875- 54 54 54 26 26 26 10 10 10 0 0 0
45876- 0 0 0 0 0 0 0 0 0 0 0 0
45877- 0 0 0 0 0 0 0 0 0 0 0 0
45878- 0 0 0 0 0 0 0 0 0 0 0 0
45879- 0 0 0 0 0 0 0 0 0 0 0 0
45880- 0 0 0 0 0 0 0 0 0 0 0 0
45881- 0 0 0 0 0 0 0 0 0 0 0 0
45882- 0 0 0 0 0 0 0 0 0 0 0 0
45883- 0 0 0 0 0 0 0 0 0 0 0 0
45884- 0 0 0 0 0 0 0 0 0 0 0 0
45885- 0 0 0 6 6 6 22 22 22 50 50 50
45886- 90 90 90 26 26 26 2 2 6 2 2 6
45887- 14 14 14 195 195 195 250 250 250 253 253 253
45888-253 253 253 253 253 253 253 253 253 253 253 253
45889-253 253 253 253 253 253 253 253 253 253 253 253
45890-253 253 253 253 253 253 253 253 253 253 253 253
45891-253 253 253 253 253 253 253 253 253 253 253 253
45892-250 250 250 242 242 242 54 54 54 2 2 6
45893- 2 2 6 2 2 6 2 2 6 2 2 6
45894- 2 2 6 2 2 6 2 2 6 38 38 38
45895- 86 86 86 50 50 50 22 22 22 6 6 6
45896- 0 0 0 0 0 0 0 0 0 0 0 0
45897- 0 0 0 0 0 0 0 0 0 0 0 0
45898- 0 0 0 0 0 0 0 0 0 0 0 0
45899- 0 0 0 0 0 0 0 0 0 0 0 0
45900- 0 0 0 0 0 0 0 0 0 0 0 0
45901- 0 0 0 0 0 0 0 0 0 0 0 0
45902- 0 0 0 0 0 0 0 0 0 0 0 0
45903- 0 0 0 0 0 0 0 0 0 0 0 0
45904- 0 0 0 0 0 0 0 0 0 0 0 0
45905- 6 6 6 14 14 14 38 38 38 82 82 82
45906- 34 34 34 2 2 6 2 2 6 2 2 6
45907- 42 42 42 195 195 195 246 246 246 253 253 253
45908-253 253 253 253 253 253 253 253 253 250 250 250
45909-242 242 242 242 242 242 250 250 250 253 253 253
45910-253 253 253 253 253 253 253 253 253 253 253 253
45911-253 253 253 250 250 250 246 246 246 238 238 238
45912-226 226 226 231 231 231 101 101 101 6 6 6
45913- 2 2 6 2 2 6 2 2 6 2 2 6
45914- 2 2 6 2 2 6 2 2 6 2 2 6
45915- 38 38 38 82 82 82 42 42 42 14 14 14
45916- 6 6 6 0 0 0 0 0 0 0 0 0
45917- 0 0 0 0 0 0 0 0 0 0 0 0
45918- 0 0 0 0 0 0 0 0 0 0 0 0
45919- 0 0 0 0 0 0 0 0 0 0 0 0
45920- 0 0 0 0 0 0 0 0 0 0 0 0
45921- 0 0 0 0 0 0 0 0 0 0 0 0
45922- 0 0 0 0 0 0 0 0 0 0 0 0
45923- 0 0 0 0 0 0 0 0 0 0 0 0
45924- 0 0 0 0 0 0 0 0 0 0 0 0
45925- 10 10 10 26 26 26 62 62 62 66 66 66
45926- 2 2 6 2 2 6 2 2 6 6 6 6
45927- 70 70 70 170 170 170 206 206 206 234 234 234
45928-246 246 246 250 250 250 250 250 250 238 238 238
45929-226 226 226 231 231 231 238 238 238 250 250 250
45930-250 250 250 250 250 250 246 246 246 231 231 231
45931-214 214 214 206 206 206 202 202 202 202 202 202
45932-198 198 198 202 202 202 182 182 182 18 18 18
45933- 2 2 6 2 2 6 2 2 6 2 2 6
45934- 2 2 6 2 2 6 2 2 6 2 2 6
45935- 2 2 6 62 62 62 66 66 66 30 30 30
45936- 10 10 10 0 0 0 0 0 0 0 0 0
45937- 0 0 0 0 0 0 0 0 0 0 0 0
45938- 0 0 0 0 0 0 0 0 0 0 0 0
45939- 0 0 0 0 0 0 0 0 0 0 0 0
45940- 0 0 0 0 0 0 0 0 0 0 0 0
45941- 0 0 0 0 0 0 0 0 0 0 0 0
45942- 0 0 0 0 0 0 0 0 0 0 0 0
45943- 0 0 0 0 0 0 0 0 0 0 0 0
45944- 0 0 0 0 0 0 0 0 0 0 0 0
45945- 14 14 14 42 42 42 82 82 82 18 18 18
45946- 2 2 6 2 2 6 2 2 6 10 10 10
45947- 94 94 94 182 182 182 218 218 218 242 242 242
45948-250 250 250 253 253 253 253 253 253 250 250 250
45949-234 234 234 253 253 253 253 253 253 253 253 253
45950-253 253 253 253 253 253 253 253 253 246 246 246
45951-238 238 238 226 226 226 210 210 210 202 202 202
45952-195 195 195 195 195 195 210 210 210 158 158 158
45953- 6 6 6 14 14 14 50 50 50 14 14 14
45954- 2 2 6 2 2 6 2 2 6 2 2 6
45955- 2 2 6 6 6 6 86 86 86 46 46 46
45956- 18 18 18 6 6 6 0 0 0 0 0 0
45957- 0 0 0 0 0 0 0 0 0 0 0 0
45958- 0 0 0 0 0 0 0 0 0 0 0 0
45959- 0 0 0 0 0 0 0 0 0 0 0 0
45960- 0 0 0 0 0 0 0 0 0 0 0 0
45961- 0 0 0 0 0 0 0 0 0 0 0 0
45962- 0 0 0 0 0 0 0 0 0 0 0 0
45963- 0 0 0 0 0 0 0 0 0 0 0 0
45964- 0 0 0 0 0 0 0 0 0 6 6 6
45965- 22 22 22 54 54 54 70 70 70 2 2 6
45966- 2 2 6 10 10 10 2 2 6 22 22 22
45967-166 166 166 231 231 231 250 250 250 253 253 253
45968-253 253 253 253 253 253 253 253 253 250 250 250
45969-242 242 242 253 253 253 253 253 253 253 253 253
45970-253 253 253 253 253 253 253 253 253 253 253 253
45971-253 253 253 253 253 253 253 253 253 246 246 246
45972-231 231 231 206 206 206 198 198 198 226 226 226
45973- 94 94 94 2 2 6 6 6 6 38 38 38
45974- 30 30 30 2 2 6 2 2 6 2 2 6
45975- 2 2 6 2 2 6 62 62 62 66 66 66
45976- 26 26 26 10 10 10 0 0 0 0 0 0
45977- 0 0 0 0 0 0 0 0 0 0 0 0
45978- 0 0 0 0 0 0 0 0 0 0 0 0
45979- 0 0 0 0 0 0 0 0 0 0 0 0
45980- 0 0 0 0 0 0 0 0 0 0 0 0
45981- 0 0 0 0 0 0 0 0 0 0 0 0
45982- 0 0 0 0 0 0 0 0 0 0 0 0
45983- 0 0 0 0 0 0 0 0 0 0 0 0
45984- 0 0 0 0 0 0 0 0 0 10 10 10
45985- 30 30 30 74 74 74 50 50 50 2 2 6
45986- 26 26 26 26 26 26 2 2 6 106 106 106
45987-238 238 238 253 253 253 253 253 253 253 253 253
45988-253 253 253 253 253 253 253 253 253 253 253 253
45989-253 253 253 253 253 253 253 253 253 253 253 253
45990-253 253 253 253 253 253 253 253 253 253 253 253
45991-253 253 253 253 253 253 253 253 253 253 253 253
45992-253 253 253 246 246 246 218 218 218 202 202 202
45993-210 210 210 14 14 14 2 2 6 2 2 6
45994- 30 30 30 22 22 22 2 2 6 2 2 6
45995- 2 2 6 2 2 6 18 18 18 86 86 86
45996- 42 42 42 14 14 14 0 0 0 0 0 0
45997- 0 0 0 0 0 0 0 0 0 0 0 0
45998- 0 0 0 0 0 0 0 0 0 0 0 0
45999- 0 0 0 0 0 0 0 0 0 0 0 0
46000- 0 0 0 0 0 0 0 0 0 0 0 0
46001- 0 0 0 0 0 0 0 0 0 0 0 0
46002- 0 0 0 0 0 0 0 0 0 0 0 0
46003- 0 0 0 0 0 0 0 0 0 0 0 0
46004- 0 0 0 0 0 0 0 0 0 14 14 14
46005- 42 42 42 90 90 90 22 22 22 2 2 6
46006- 42 42 42 2 2 6 18 18 18 218 218 218
46007-253 253 253 253 253 253 253 253 253 253 253 253
46008-253 253 253 253 253 253 253 253 253 253 253 253
46009-253 253 253 253 253 253 253 253 253 253 253 253
46010-253 253 253 253 253 253 253 253 253 253 253 253
46011-253 253 253 253 253 253 253 253 253 253 253 253
46012-253 253 253 253 253 253 250 250 250 221 221 221
46013-218 218 218 101 101 101 2 2 6 14 14 14
46014- 18 18 18 38 38 38 10 10 10 2 2 6
46015- 2 2 6 2 2 6 2 2 6 78 78 78
46016- 58 58 58 22 22 22 6 6 6 0 0 0
46017- 0 0 0 0 0 0 0 0 0 0 0 0
46018- 0 0 0 0 0 0 0 0 0 0 0 0
46019- 0 0 0 0 0 0 0 0 0 0 0 0
46020- 0 0 0 0 0 0 0 0 0 0 0 0
46021- 0 0 0 0 0 0 0 0 0 0 0 0
46022- 0 0 0 0 0 0 0 0 0 0 0 0
46023- 0 0 0 0 0 0 0 0 0 0 0 0
46024- 0 0 0 0 0 0 6 6 6 18 18 18
46025- 54 54 54 82 82 82 2 2 6 26 26 26
46026- 22 22 22 2 2 6 123 123 123 253 253 253
46027-253 253 253 253 253 253 253 253 253 253 253 253
46028-253 253 253 253 253 253 253 253 253 253 253 253
46029-253 253 253 253 253 253 253 253 253 253 253 253
46030-253 253 253 253 253 253 253 253 253 253 253 253
46031-253 253 253 253 253 253 253 253 253 253 253 253
46032-253 253 253 253 253 253 253 253 253 250 250 250
46033-238 238 238 198 198 198 6 6 6 38 38 38
46034- 58 58 58 26 26 26 38 38 38 2 2 6
46035- 2 2 6 2 2 6 2 2 6 46 46 46
46036- 78 78 78 30 30 30 10 10 10 0 0 0
46037- 0 0 0 0 0 0 0 0 0 0 0 0
46038- 0 0 0 0 0 0 0 0 0 0 0 0
46039- 0 0 0 0 0 0 0 0 0 0 0 0
46040- 0 0 0 0 0 0 0 0 0 0 0 0
46041- 0 0 0 0 0 0 0 0 0 0 0 0
46042- 0 0 0 0 0 0 0 0 0 0 0 0
46043- 0 0 0 0 0 0 0 0 0 0 0 0
46044- 0 0 0 0 0 0 10 10 10 30 30 30
46045- 74 74 74 58 58 58 2 2 6 42 42 42
46046- 2 2 6 22 22 22 231 231 231 253 253 253
46047-253 253 253 253 253 253 253 253 253 253 253 253
46048-253 253 253 253 253 253 253 253 253 250 250 250
46049-253 253 253 253 253 253 253 253 253 253 253 253
46050-253 253 253 253 253 253 253 253 253 253 253 253
46051-253 253 253 253 253 253 253 253 253 253 253 253
46052-253 253 253 253 253 253 253 253 253 253 253 253
46053-253 253 253 246 246 246 46 46 46 38 38 38
46054- 42 42 42 14 14 14 38 38 38 14 14 14
46055- 2 2 6 2 2 6 2 2 6 6 6 6
46056- 86 86 86 46 46 46 14 14 14 0 0 0
46057- 0 0 0 0 0 0 0 0 0 0 0 0
46058- 0 0 0 0 0 0 0 0 0 0 0 0
46059- 0 0 0 0 0 0 0 0 0 0 0 0
46060- 0 0 0 0 0 0 0 0 0 0 0 0
46061- 0 0 0 0 0 0 0 0 0 0 0 0
46062- 0 0 0 0 0 0 0 0 0 0 0 0
46063- 0 0 0 0 0 0 0 0 0 0 0 0
46064- 0 0 0 6 6 6 14 14 14 42 42 42
46065- 90 90 90 18 18 18 18 18 18 26 26 26
46066- 2 2 6 116 116 116 253 253 253 253 253 253
46067-253 253 253 253 253 253 253 253 253 253 253 253
46068-253 253 253 253 253 253 250 250 250 238 238 238
46069-253 253 253 253 253 253 253 253 253 253 253 253
46070-253 253 253 253 253 253 253 253 253 253 253 253
46071-253 253 253 253 253 253 253 253 253 253 253 253
46072-253 253 253 253 253 253 253 253 253 253 253 253
46073-253 253 253 253 253 253 94 94 94 6 6 6
46074- 2 2 6 2 2 6 10 10 10 34 34 34
46075- 2 2 6 2 2 6 2 2 6 2 2 6
46076- 74 74 74 58 58 58 22 22 22 6 6 6
46077- 0 0 0 0 0 0 0 0 0 0 0 0
46078- 0 0 0 0 0 0 0 0 0 0 0 0
46079- 0 0 0 0 0 0 0 0 0 0 0 0
46080- 0 0 0 0 0 0 0 0 0 0 0 0
46081- 0 0 0 0 0 0 0 0 0 0 0 0
46082- 0 0 0 0 0 0 0 0 0 0 0 0
46083- 0 0 0 0 0 0 0 0 0 0 0 0
46084- 0 0 0 10 10 10 26 26 26 66 66 66
46085- 82 82 82 2 2 6 38 38 38 6 6 6
46086- 14 14 14 210 210 210 253 253 253 253 253 253
46087-253 253 253 253 253 253 253 253 253 253 253 253
46088-253 253 253 253 253 253 246 246 246 242 242 242
46089-253 253 253 253 253 253 253 253 253 253 253 253
46090-253 253 253 253 253 253 253 253 253 253 253 253
46091-253 253 253 253 253 253 253 253 253 253 253 253
46092-253 253 253 253 253 253 253 253 253 253 253 253
46093-253 253 253 253 253 253 144 144 144 2 2 6
46094- 2 2 6 2 2 6 2 2 6 46 46 46
46095- 2 2 6 2 2 6 2 2 6 2 2 6
46096- 42 42 42 74 74 74 30 30 30 10 10 10
46097- 0 0 0 0 0 0 0 0 0 0 0 0
46098- 0 0 0 0 0 0 0 0 0 0 0 0
46099- 0 0 0 0 0 0 0 0 0 0 0 0
46100- 0 0 0 0 0 0 0 0 0 0 0 0
46101- 0 0 0 0 0 0 0 0 0 0 0 0
46102- 0 0 0 0 0 0 0 0 0 0 0 0
46103- 0 0 0 0 0 0 0 0 0 0 0 0
46104- 6 6 6 14 14 14 42 42 42 90 90 90
46105- 26 26 26 6 6 6 42 42 42 2 2 6
46106- 74 74 74 250 250 250 253 253 253 253 253 253
46107-253 253 253 253 253 253 253 253 253 253 253 253
46108-253 253 253 253 253 253 242 242 242 242 242 242
46109-253 253 253 253 253 253 253 253 253 253 253 253
46110-253 253 253 253 253 253 253 253 253 253 253 253
46111-253 253 253 253 253 253 253 253 253 253 253 253
46112-253 253 253 253 253 253 253 253 253 253 253 253
46113-253 253 253 253 253 253 182 182 182 2 2 6
46114- 2 2 6 2 2 6 2 2 6 46 46 46
46115- 2 2 6 2 2 6 2 2 6 2 2 6
46116- 10 10 10 86 86 86 38 38 38 10 10 10
46117- 0 0 0 0 0 0 0 0 0 0 0 0
46118- 0 0 0 0 0 0 0 0 0 0 0 0
46119- 0 0 0 0 0 0 0 0 0 0 0 0
46120- 0 0 0 0 0 0 0 0 0 0 0 0
46121- 0 0 0 0 0 0 0 0 0 0 0 0
46122- 0 0 0 0 0 0 0 0 0 0 0 0
46123- 0 0 0 0 0 0 0 0 0 0 0 0
46124- 10 10 10 26 26 26 66 66 66 82 82 82
46125- 2 2 6 22 22 22 18 18 18 2 2 6
46126-149 149 149 253 253 253 253 253 253 253 253 253
46127-253 253 253 253 253 253 253 253 253 253 253 253
46128-253 253 253 253 253 253 234 234 234 242 242 242
46129-253 253 253 253 253 253 253 253 253 253 253 253
46130-253 253 253 253 253 253 253 253 253 253 253 253
46131-253 253 253 253 253 253 253 253 253 253 253 253
46132-253 253 253 253 253 253 253 253 253 253 253 253
46133-253 253 253 253 253 253 206 206 206 2 2 6
46134- 2 2 6 2 2 6 2 2 6 38 38 38
46135- 2 2 6 2 2 6 2 2 6 2 2 6
46136- 6 6 6 86 86 86 46 46 46 14 14 14
46137- 0 0 0 0 0 0 0 0 0 0 0 0
46138- 0 0 0 0 0 0 0 0 0 0 0 0
46139- 0 0 0 0 0 0 0 0 0 0 0 0
46140- 0 0 0 0 0 0 0 0 0 0 0 0
46141- 0 0 0 0 0 0 0 0 0 0 0 0
46142- 0 0 0 0 0 0 0 0 0 0 0 0
46143- 0 0 0 0 0 0 0 0 0 6 6 6
46144- 18 18 18 46 46 46 86 86 86 18 18 18
46145- 2 2 6 34 34 34 10 10 10 6 6 6
46146-210 210 210 253 253 253 253 253 253 253 253 253
46147-253 253 253 253 253 253 253 253 253 253 253 253
46148-253 253 253 253 253 253 234 234 234 242 242 242
46149-253 253 253 253 253 253 253 253 253 253 253 253
46150-253 253 253 253 253 253 253 253 253 253 253 253
46151-253 253 253 253 253 253 253 253 253 253 253 253
46152-253 253 253 253 253 253 253 253 253 253 253 253
46153-253 253 253 253 253 253 221 221 221 6 6 6
46154- 2 2 6 2 2 6 6 6 6 30 30 30
46155- 2 2 6 2 2 6 2 2 6 2 2 6
46156- 2 2 6 82 82 82 54 54 54 18 18 18
46157- 6 6 6 0 0 0 0 0 0 0 0 0
46158- 0 0 0 0 0 0 0 0 0 0 0 0
46159- 0 0 0 0 0 0 0 0 0 0 0 0
46160- 0 0 0 0 0 0 0 0 0 0 0 0
46161- 0 0 0 0 0 0 0 0 0 0 0 0
46162- 0 0 0 0 0 0 0 0 0 0 0 0
46163- 0 0 0 0 0 0 0 0 0 10 10 10
46164- 26 26 26 66 66 66 62 62 62 2 2 6
46165- 2 2 6 38 38 38 10 10 10 26 26 26
46166-238 238 238 253 253 253 253 253 253 253 253 253
46167-253 253 253 253 253 253 253 253 253 253 253 253
46168-253 253 253 253 253 253 231 231 231 238 238 238
46169-253 253 253 253 253 253 253 253 253 253 253 253
46170-253 253 253 253 253 253 253 253 253 253 253 253
46171-253 253 253 253 253 253 253 253 253 253 253 253
46172-253 253 253 253 253 253 253 253 253 253 253 253
46173-253 253 253 253 253 253 231 231 231 6 6 6
46174- 2 2 6 2 2 6 10 10 10 30 30 30
46175- 2 2 6 2 2 6 2 2 6 2 2 6
46176- 2 2 6 66 66 66 58 58 58 22 22 22
46177- 6 6 6 0 0 0 0 0 0 0 0 0
46178- 0 0 0 0 0 0 0 0 0 0 0 0
46179- 0 0 0 0 0 0 0 0 0 0 0 0
46180- 0 0 0 0 0 0 0 0 0 0 0 0
46181- 0 0 0 0 0 0 0 0 0 0 0 0
46182- 0 0 0 0 0 0 0 0 0 0 0 0
46183- 0 0 0 0 0 0 0 0 0 10 10 10
46184- 38 38 38 78 78 78 6 6 6 2 2 6
46185- 2 2 6 46 46 46 14 14 14 42 42 42
46186-246 246 246 253 253 253 253 253 253 253 253 253
46187-253 253 253 253 253 253 253 253 253 253 253 253
46188-253 253 253 253 253 253 231 231 231 242 242 242
46189-253 253 253 253 253 253 253 253 253 253 253 253
46190-253 253 253 253 253 253 253 253 253 253 253 253
46191-253 253 253 253 253 253 253 253 253 253 253 253
46192-253 253 253 253 253 253 253 253 253 253 253 253
46193-253 253 253 253 253 253 234 234 234 10 10 10
46194- 2 2 6 2 2 6 22 22 22 14 14 14
46195- 2 2 6 2 2 6 2 2 6 2 2 6
46196- 2 2 6 66 66 66 62 62 62 22 22 22
46197- 6 6 6 0 0 0 0 0 0 0 0 0
46198- 0 0 0 0 0 0 0 0 0 0 0 0
46199- 0 0 0 0 0 0 0 0 0 0 0 0
46200- 0 0 0 0 0 0 0 0 0 0 0 0
46201- 0 0 0 0 0 0 0 0 0 0 0 0
46202- 0 0 0 0 0 0 0 0 0 0 0 0
46203- 0 0 0 0 0 0 6 6 6 18 18 18
46204- 50 50 50 74 74 74 2 2 6 2 2 6
46205- 14 14 14 70 70 70 34 34 34 62 62 62
46206-250 250 250 253 253 253 253 253 253 253 253 253
46207-253 253 253 253 253 253 253 253 253 253 253 253
46208-253 253 253 253 253 253 231 231 231 246 246 246
46209-253 253 253 253 253 253 253 253 253 253 253 253
46210-253 253 253 253 253 253 253 253 253 253 253 253
46211-253 253 253 253 253 253 253 253 253 253 253 253
46212-253 253 253 253 253 253 253 253 253 253 253 253
46213-253 253 253 253 253 253 234 234 234 14 14 14
46214- 2 2 6 2 2 6 30 30 30 2 2 6
46215- 2 2 6 2 2 6 2 2 6 2 2 6
46216- 2 2 6 66 66 66 62 62 62 22 22 22
46217- 6 6 6 0 0 0 0 0 0 0 0 0
46218- 0 0 0 0 0 0 0 0 0 0 0 0
46219- 0 0 0 0 0 0 0 0 0 0 0 0
46220- 0 0 0 0 0 0 0 0 0 0 0 0
46221- 0 0 0 0 0 0 0 0 0 0 0 0
46222- 0 0 0 0 0 0 0 0 0 0 0 0
46223- 0 0 0 0 0 0 6 6 6 18 18 18
46224- 54 54 54 62 62 62 2 2 6 2 2 6
46225- 2 2 6 30 30 30 46 46 46 70 70 70
46226-250 250 250 253 253 253 253 253 253 253 253 253
46227-253 253 253 253 253 253 253 253 253 253 253 253
46228-253 253 253 253 253 253 231 231 231 246 246 246
46229-253 253 253 253 253 253 253 253 253 253 253 253
46230-253 253 253 253 253 253 253 253 253 253 253 253
46231-253 253 253 253 253 253 253 253 253 253 253 253
46232-253 253 253 253 253 253 253 253 253 253 253 253
46233-253 253 253 253 253 253 226 226 226 10 10 10
46234- 2 2 6 6 6 6 30 30 30 2 2 6
46235- 2 2 6 2 2 6 2 2 6 2 2 6
46236- 2 2 6 66 66 66 58 58 58 22 22 22
46237- 6 6 6 0 0 0 0 0 0 0 0 0
46238- 0 0 0 0 0 0 0 0 0 0 0 0
46239- 0 0 0 0 0 0 0 0 0 0 0 0
46240- 0 0 0 0 0 0 0 0 0 0 0 0
46241- 0 0 0 0 0 0 0 0 0 0 0 0
46242- 0 0 0 0 0 0 0 0 0 0 0 0
46243- 0 0 0 0 0 0 6 6 6 22 22 22
46244- 58 58 58 62 62 62 2 2 6 2 2 6
46245- 2 2 6 2 2 6 30 30 30 78 78 78
46246-250 250 250 253 253 253 253 253 253 253 253 253
46247-253 253 253 253 253 253 253 253 253 253 253 253
46248-253 253 253 253 253 253 231 231 231 246 246 246
46249-253 253 253 253 253 253 253 253 253 253 253 253
46250-253 253 253 253 253 253 253 253 253 253 253 253
46251-253 253 253 253 253 253 253 253 253 253 253 253
46252-253 253 253 253 253 253 253 253 253 253 253 253
46253-253 253 253 253 253 253 206 206 206 2 2 6
46254- 22 22 22 34 34 34 18 14 6 22 22 22
46255- 26 26 26 18 18 18 6 6 6 2 2 6
46256- 2 2 6 82 82 82 54 54 54 18 18 18
46257- 6 6 6 0 0 0 0 0 0 0 0 0
46258- 0 0 0 0 0 0 0 0 0 0 0 0
46259- 0 0 0 0 0 0 0 0 0 0 0 0
46260- 0 0 0 0 0 0 0 0 0 0 0 0
46261- 0 0 0 0 0 0 0 0 0 0 0 0
46262- 0 0 0 0 0 0 0 0 0 0 0 0
46263- 0 0 0 0 0 0 6 6 6 26 26 26
46264- 62 62 62 106 106 106 74 54 14 185 133 11
46265-210 162 10 121 92 8 6 6 6 62 62 62
46266-238 238 238 253 253 253 253 253 253 253 253 253
46267-253 253 253 253 253 253 253 253 253 253 253 253
46268-253 253 253 253 253 253 231 231 231 246 246 246
46269-253 253 253 253 253 253 253 253 253 253 253 253
46270-253 253 253 253 253 253 253 253 253 253 253 253
46271-253 253 253 253 253 253 253 253 253 253 253 253
46272-253 253 253 253 253 253 253 253 253 253 253 253
46273-253 253 253 253 253 253 158 158 158 18 18 18
46274- 14 14 14 2 2 6 2 2 6 2 2 6
46275- 6 6 6 18 18 18 66 66 66 38 38 38
46276- 6 6 6 94 94 94 50 50 50 18 18 18
46277- 6 6 6 0 0 0 0 0 0 0 0 0
46278- 0 0 0 0 0 0 0 0 0 0 0 0
46279- 0 0 0 0 0 0 0 0 0 0 0 0
46280- 0 0 0 0 0 0 0 0 0 0 0 0
46281- 0 0 0 0 0 0 0 0 0 0 0 0
46282- 0 0 0 0 0 0 0 0 0 6 6 6
46283- 10 10 10 10 10 10 18 18 18 38 38 38
46284- 78 78 78 142 134 106 216 158 10 242 186 14
46285-246 190 14 246 190 14 156 118 10 10 10 10
46286- 90 90 90 238 238 238 253 253 253 253 253 253
46287-253 253 253 253 253 253 253 253 253 253 253 253
46288-253 253 253 253 253 253 231 231 231 250 250 250
46289-253 253 253 253 253 253 253 253 253 253 253 253
46290-253 253 253 253 253 253 253 253 253 253 253 253
46291-253 253 253 253 253 253 253 253 253 253 253 253
46292-253 253 253 253 253 253 253 253 253 246 230 190
46293-238 204 91 238 204 91 181 142 44 37 26 9
46294- 2 2 6 2 2 6 2 2 6 2 2 6
46295- 2 2 6 2 2 6 38 38 38 46 46 46
46296- 26 26 26 106 106 106 54 54 54 18 18 18
46297- 6 6 6 0 0 0 0 0 0 0 0 0
46298- 0 0 0 0 0 0 0 0 0 0 0 0
46299- 0 0 0 0 0 0 0 0 0 0 0 0
46300- 0 0 0 0 0 0 0 0 0 0 0 0
46301- 0 0 0 0 0 0 0 0 0 0 0 0
46302- 0 0 0 6 6 6 14 14 14 22 22 22
46303- 30 30 30 38 38 38 50 50 50 70 70 70
46304-106 106 106 190 142 34 226 170 11 242 186 14
46305-246 190 14 246 190 14 246 190 14 154 114 10
46306- 6 6 6 74 74 74 226 226 226 253 253 253
46307-253 253 253 253 253 253 253 253 253 253 253 253
46308-253 253 253 253 253 253 231 231 231 250 250 250
46309-253 253 253 253 253 253 253 253 253 253 253 253
46310-253 253 253 253 253 253 253 253 253 253 253 253
46311-253 253 253 253 253 253 253 253 253 253 253 253
46312-253 253 253 253 253 253 253 253 253 228 184 62
46313-241 196 14 241 208 19 232 195 16 38 30 10
46314- 2 2 6 2 2 6 2 2 6 2 2 6
46315- 2 2 6 6 6 6 30 30 30 26 26 26
46316-203 166 17 154 142 90 66 66 66 26 26 26
46317- 6 6 6 0 0 0 0 0 0 0 0 0
46318- 0 0 0 0 0 0 0 0 0 0 0 0
46319- 0 0 0 0 0 0 0 0 0 0 0 0
46320- 0 0 0 0 0 0 0 0 0 0 0 0
46321- 0 0 0 0 0 0 0 0 0 0 0 0
46322- 6 6 6 18 18 18 38 38 38 58 58 58
46323- 78 78 78 86 86 86 101 101 101 123 123 123
46324-175 146 61 210 150 10 234 174 13 246 186 14
46325-246 190 14 246 190 14 246 190 14 238 190 10
46326-102 78 10 2 2 6 46 46 46 198 198 198
46327-253 253 253 253 253 253 253 253 253 253 253 253
46328-253 253 253 253 253 253 234 234 234 242 242 242
46329-253 253 253 253 253 253 253 253 253 253 253 253
46330-253 253 253 253 253 253 253 253 253 253 253 253
46331-253 253 253 253 253 253 253 253 253 253 253 253
46332-253 253 253 253 253 253 253 253 253 224 178 62
46333-242 186 14 241 196 14 210 166 10 22 18 6
46334- 2 2 6 2 2 6 2 2 6 2 2 6
46335- 2 2 6 2 2 6 6 6 6 121 92 8
46336-238 202 15 232 195 16 82 82 82 34 34 34
46337- 10 10 10 0 0 0 0 0 0 0 0 0
46338- 0 0 0 0 0 0 0 0 0 0 0 0
46339- 0 0 0 0 0 0 0 0 0 0 0 0
46340- 0 0 0 0 0 0 0 0 0 0 0 0
46341- 0 0 0 0 0 0 0 0 0 0 0 0
46342- 14 14 14 38 38 38 70 70 70 154 122 46
46343-190 142 34 200 144 11 197 138 11 197 138 11
46344-213 154 11 226 170 11 242 186 14 246 190 14
46345-246 190 14 246 190 14 246 190 14 246 190 14
46346-225 175 15 46 32 6 2 2 6 22 22 22
46347-158 158 158 250 250 250 253 253 253 253 253 253
46348-253 253 253 253 253 253 253 253 253 253 253 253
46349-253 253 253 253 253 253 253 253 253 253 253 253
46350-253 253 253 253 253 253 253 253 253 253 253 253
46351-253 253 253 253 253 253 253 253 253 253 253 253
46352-253 253 253 250 250 250 242 242 242 224 178 62
46353-239 182 13 236 186 11 213 154 11 46 32 6
46354- 2 2 6 2 2 6 2 2 6 2 2 6
46355- 2 2 6 2 2 6 61 42 6 225 175 15
46356-238 190 10 236 186 11 112 100 78 42 42 42
46357- 14 14 14 0 0 0 0 0 0 0 0 0
46358- 0 0 0 0 0 0 0 0 0 0 0 0
46359- 0 0 0 0 0 0 0 0 0 0 0 0
46360- 0 0 0 0 0 0 0 0 0 0 0 0
46361- 0 0 0 0 0 0 0 0 0 6 6 6
46362- 22 22 22 54 54 54 154 122 46 213 154 11
46363-226 170 11 230 174 11 226 170 11 226 170 11
46364-236 178 12 242 186 14 246 190 14 246 190 14
46365-246 190 14 246 190 14 246 190 14 246 190 14
46366-241 196 14 184 144 12 10 10 10 2 2 6
46367- 6 6 6 116 116 116 242 242 242 253 253 253
46368-253 253 253 253 253 253 253 253 253 253 253 253
46369-253 253 253 253 253 253 253 253 253 253 253 253
46370-253 253 253 253 253 253 253 253 253 253 253 253
46371-253 253 253 253 253 253 253 253 253 253 253 253
46372-253 253 253 231 231 231 198 198 198 214 170 54
46373-236 178 12 236 178 12 210 150 10 137 92 6
46374- 18 14 6 2 2 6 2 2 6 2 2 6
46375- 6 6 6 70 47 6 200 144 11 236 178 12
46376-239 182 13 239 182 13 124 112 88 58 58 58
46377- 22 22 22 6 6 6 0 0 0 0 0 0
46378- 0 0 0 0 0 0 0 0 0 0 0 0
46379- 0 0 0 0 0 0 0 0 0 0 0 0
46380- 0 0 0 0 0 0 0 0 0 0 0 0
46381- 0 0 0 0 0 0 0 0 0 10 10 10
46382- 30 30 30 70 70 70 180 133 36 226 170 11
46383-239 182 13 242 186 14 242 186 14 246 186 14
46384-246 190 14 246 190 14 246 190 14 246 190 14
46385-246 190 14 246 190 14 246 190 14 246 190 14
46386-246 190 14 232 195 16 98 70 6 2 2 6
46387- 2 2 6 2 2 6 66 66 66 221 221 221
46388-253 253 253 253 253 253 253 253 253 253 253 253
46389-253 253 253 253 253 253 253 253 253 253 253 253
46390-253 253 253 253 253 253 253 253 253 253 253 253
46391-253 253 253 253 253 253 253 253 253 253 253 253
46392-253 253 253 206 206 206 198 198 198 214 166 58
46393-230 174 11 230 174 11 216 158 10 192 133 9
46394-163 110 8 116 81 8 102 78 10 116 81 8
46395-167 114 7 197 138 11 226 170 11 239 182 13
46396-242 186 14 242 186 14 162 146 94 78 78 78
46397- 34 34 34 14 14 14 6 6 6 0 0 0
46398- 0 0 0 0 0 0 0 0 0 0 0 0
46399- 0 0 0 0 0 0 0 0 0 0 0 0
46400- 0 0 0 0 0 0 0 0 0 0 0 0
46401- 0 0 0 0 0 0 0 0 0 6 6 6
46402- 30 30 30 78 78 78 190 142 34 226 170 11
46403-239 182 13 246 190 14 246 190 14 246 190 14
46404-246 190 14 246 190 14 246 190 14 246 190 14
46405-246 190 14 246 190 14 246 190 14 246 190 14
46406-246 190 14 241 196 14 203 166 17 22 18 6
46407- 2 2 6 2 2 6 2 2 6 38 38 38
46408-218 218 218 253 253 253 253 253 253 253 253 253
46409-253 253 253 253 253 253 253 253 253 253 253 253
46410-253 253 253 253 253 253 253 253 253 253 253 253
46411-253 253 253 253 253 253 253 253 253 253 253 253
46412-250 250 250 206 206 206 198 198 198 202 162 69
46413-226 170 11 236 178 12 224 166 10 210 150 10
46414-200 144 11 197 138 11 192 133 9 197 138 11
46415-210 150 10 226 170 11 242 186 14 246 190 14
46416-246 190 14 246 186 14 225 175 15 124 112 88
46417- 62 62 62 30 30 30 14 14 14 6 6 6
46418- 0 0 0 0 0 0 0 0 0 0 0 0
46419- 0 0 0 0 0 0 0 0 0 0 0 0
46420- 0 0 0 0 0 0 0 0 0 0 0 0
46421- 0 0 0 0 0 0 0 0 0 10 10 10
46422- 30 30 30 78 78 78 174 135 50 224 166 10
46423-239 182 13 246 190 14 246 190 14 246 190 14
46424-246 190 14 246 190 14 246 190 14 246 190 14
46425-246 190 14 246 190 14 246 190 14 246 190 14
46426-246 190 14 246 190 14 241 196 14 139 102 15
46427- 2 2 6 2 2 6 2 2 6 2 2 6
46428- 78 78 78 250 250 250 253 253 253 253 253 253
46429-253 253 253 253 253 253 253 253 253 253 253 253
46430-253 253 253 253 253 253 253 253 253 253 253 253
46431-253 253 253 253 253 253 253 253 253 253 253 253
46432-250 250 250 214 214 214 198 198 198 190 150 46
46433-219 162 10 236 178 12 234 174 13 224 166 10
46434-216 158 10 213 154 11 213 154 11 216 158 10
46435-226 170 11 239 182 13 246 190 14 246 190 14
46436-246 190 14 246 190 14 242 186 14 206 162 42
46437-101 101 101 58 58 58 30 30 30 14 14 14
46438- 6 6 6 0 0 0 0 0 0 0 0 0
46439- 0 0 0 0 0 0 0 0 0 0 0 0
46440- 0 0 0 0 0 0 0 0 0 0 0 0
46441- 0 0 0 0 0 0 0 0 0 10 10 10
46442- 30 30 30 74 74 74 174 135 50 216 158 10
46443-236 178 12 246 190 14 246 190 14 246 190 14
46444-246 190 14 246 190 14 246 190 14 246 190 14
46445-246 190 14 246 190 14 246 190 14 246 190 14
46446-246 190 14 246 190 14 241 196 14 226 184 13
46447- 61 42 6 2 2 6 2 2 6 2 2 6
46448- 22 22 22 238 238 238 253 253 253 253 253 253
46449-253 253 253 253 253 253 253 253 253 253 253 253
46450-253 253 253 253 253 253 253 253 253 253 253 253
46451-253 253 253 253 253 253 253 253 253 253 253 253
46452-253 253 253 226 226 226 187 187 187 180 133 36
46453-216 158 10 236 178 12 239 182 13 236 178 12
46454-230 174 11 226 170 11 226 170 11 230 174 11
46455-236 178 12 242 186 14 246 190 14 246 190 14
46456-246 190 14 246 190 14 246 186 14 239 182 13
46457-206 162 42 106 106 106 66 66 66 34 34 34
46458- 14 14 14 6 6 6 0 0 0 0 0 0
46459- 0 0 0 0 0 0 0 0 0 0 0 0
46460- 0 0 0 0 0 0 0 0 0 0 0 0
46461- 0 0 0 0 0 0 0 0 0 6 6 6
46462- 26 26 26 70 70 70 163 133 67 213 154 11
46463-236 178 12 246 190 14 246 190 14 246 190 14
46464-246 190 14 246 190 14 246 190 14 246 190 14
46465-246 190 14 246 190 14 246 190 14 246 190 14
46466-246 190 14 246 190 14 246 190 14 241 196 14
46467-190 146 13 18 14 6 2 2 6 2 2 6
46468- 46 46 46 246 246 246 253 253 253 253 253 253
46469-253 253 253 253 253 253 253 253 253 253 253 253
46470-253 253 253 253 253 253 253 253 253 253 253 253
46471-253 253 253 253 253 253 253 253 253 253 253 253
46472-253 253 253 221 221 221 86 86 86 156 107 11
46473-216 158 10 236 178 12 242 186 14 246 186 14
46474-242 186 14 239 182 13 239 182 13 242 186 14
46475-242 186 14 246 186 14 246 190 14 246 190 14
46476-246 190 14 246 190 14 246 190 14 246 190 14
46477-242 186 14 225 175 15 142 122 72 66 66 66
46478- 30 30 30 10 10 10 0 0 0 0 0 0
46479- 0 0 0 0 0 0 0 0 0 0 0 0
46480- 0 0 0 0 0 0 0 0 0 0 0 0
46481- 0 0 0 0 0 0 0 0 0 6 6 6
46482- 26 26 26 70 70 70 163 133 67 210 150 10
46483-236 178 12 246 190 14 246 190 14 246 190 14
46484-246 190 14 246 190 14 246 190 14 246 190 14
46485-246 190 14 246 190 14 246 190 14 246 190 14
46486-246 190 14 246 190 14 246 190 14 246 190 14
46487-232 195 16 121 92 8 34 34 34 106 106 106
46488-221 221 221 253 253 253 253 253 253 253 253 253
46489-253 253 253 253 253 253 253 253 253 253 253 253
46490-253 253 253 253 253 253 253 253 253 253 253 253
46491-253 253 253 253 253 253 253 253 253 253 253 253
46492-242 242 242 82 82 82 18 14 6 163 110 8
46493-216 158 10 236 178 12 242 186 14 246 190 14
46494-246 190 14 246 190 14 246 190 14 246 190 14
46495-246 190 14 246 190 14 246 190 14 246 190 14
46496-246 190 14 246 190 14 246 190 14 246 190 14
46497-246 190 14 246 190 14 242 186 14 163 133 67
46498- 46 46 46 18 18 18 6 6 6 0 0 0
46499- 0 0 0 0 0 0 0 0 0 0 0 0
46500- 0 0 0 0 0 0 0 0 0 0 0 0
46501- 0 0 0 0 0 0 0 0 0 10 10 10
46502- 30 30 30 78 78 78 163 133 67 210 150 10
46503-236 178 12 246 186 14 246 190 14 246 190 14
46504-246 190 14 246 190 14 246 190 14 246 190 14
46505-246 190 14 246 190 14 246 190 14 246 190 14
46506-246 190 14 246 190 14 246 190 14 246 190 14
46507-241 196 14 215 174 15 190 178 144 253 253 253
46508-253 253 253 253 253 253 253 253 253 253 253 253
46509-253 253 253 253 253 253 253 253 253 253 253 253
46510-253 253 253 253 253 253 253 253 253 253 253 253
46511-253 253 253 253 253 253 253 253 253 218 218 218
46512- 58 58 58 2 2 6 22 18 6 167 114 7
46513-216 158 10 236 178 12 246 186 14 246 190 14
46514-246 190 14 246 190 14 246 190 14 246 190 14
46515-246 190 14 246 190 14 246 190 14 246 190 14
46516-246 190 14 246 190 14 246 190 14 246 190 14
46517-246 190 14 246 186 14 242 186 14 190 150 46
46518- 54 54 54 22 22 22 6 6 6 0 0 0
46519- 0 0 0 0 0 0 0 0 0 0 0 0
46520- 0 0 0 0 0 0 0 0 0 0 0 0
46521- 0 0 0 0 0 0 0 0 0 14 14 14
46522- 38 38 38 86 86 86 180 133 36 213 154 11
46523-236 178 12 246 186 14 246 190 14 246 190 14
46524-246 190 14 246 190 14 246 190 14 246 190 14
46525-246 190 14 246 190 14 246 190 14 246 190 14
46526-246 190 14 246 190 14 246 190 14 246 190 14
46527-246 190 14 232 195 16 190 146 13 214 214 214
46528-253 253 253 253 253 253 253 253 253 253 253 253
46529-253 253 253 253 253 253 253 253 253 253 253 253
46530-253 253 253 253 253 253 253 253 253 253 253 253
46531-253 253 253 250 250 250 170 170 170 26 26 26
46532- 2 2 6 2 2 6 37 26 9 163 110 8
46533-219 162 10 239 182 13 246 186 14 246 190 14
46534-246 190 14 246 190 14 246 190 14 246 190 14
46535-246 190 14 246 190 14 246 190 14 246 190 14
46536-246 190 14 246 190 14 246 190 14 246 190 14
46537-246 186 14 236 178 12 224 166 10 142 122 72
46538- 46 46 46 18 18 18 6 6 6 0 0 0
46539- 0 0 0 0 0 0 0 0 0 0 0 0
46540- 0 0 0 0 0 0 0 0 0 0 0 0
46541- 0 0 0 0 0 0 6 6 6 18 18 18
46542- 50 50 50 109 106 95 192 133 9 224 166 10
46543-242 186 14 246 190 14 246 190 14 246 190 14
46544-246 190 14 246 190 14 246 190 14 246 190 14
46545-246 190 14 246 190 14 246 190 14 246 190 14
46546-246 190 14 246 190 14 246 190 14 246 190 14
46547-242 186 14 226 184 13 210 162 10 142 110 46
46548-226 226 226 253 253 253 253 253 253 253 253 253
46549-253 253 253 253 253 253 253 253 253 253 253 253
46550-253 253 253 253 253 253 253 253 253 253 253 253
46551-198 198 198 66 66 66 2 2 6 2 2 6
46552- 2 2 6 2 2 6 50 34 6 156 107 11
46553-219 162 10 239 182 13 246 186 14 246 190 14
46554-246 190 14 246 190 14 246 190 14 246 190 14
46555-246 190 14 246 190 14 246 190 14 246 190 14
46556-246 190 14 246 190 14 246 190 14 242 186 14
46557-234 174 13 213 154 11 154 122 46 66 66 66
46558- 30 30 30 10 10 10 0 0 0 0 0 0
46559- 0 0 0 0 0 0 0 0 0 0 0 0
46560- 0 0 0 0 0 0 0 0 0 0 0 0
46561- 0 0 0 0 0 0 6 6 6 22 22 22
46562- 58 58 58 154 121 60 206 145 10 234 174 13
46563-242 186 14 246 186 14 246 190 14 246 190 14
46564-246 190 14 246 190 14 246 190 14 246 190 14
46565-246 190 14 246 190 14 246 190 14 246 190 14
46566-246 190 14 246 190 14 246 190 14 246 190 14
46567-246 186 14 236 178 12 210 162 10 163 110 8
46568- 61 42 6 138 138 138 218 218 218 250 250 250
46569-253 253 253 253 253 253 253 253 253 250 250 250
46570-242 242 242 210 210 210 144 144 144 66 66 66
46571- 6 6 6 2 2 6 2 2 6 2 2 6
46572- 2 2 6 2 2 6 61 42 6 163 110 8
46573-216 158 10 236 178 12 246 190 14 246 190 14
46574-246 190 14 246 190 14 246 190 14 246 190 14
46575-246 190 14 246 190 14 246 190 14 246 190 14
46576-246 190 14 239 182 13 230 174 11 216 158 10
46577-190 142 34 124 112 88 70 70 70 38 38 38
46578- 18 18 18 6 6 6 0 0 0 0 0 0
46579- 0 0 0 0 0 0 0 0 0 0 0 0
46580- 0 0 0 0 0 0 0 0 0 0 0 0
46581- 0 0 0 0 0 0 6 6 6 22 22 22
46582- 62 62 62 168 124 44 206 145 10 224 166 10
46583-236 178 12 239 182 13 242 186 14 242 186 14
46584-246 186 14 246 190 14 246 190 14 246 190 14
46585-246 190 14 246 190 14 246 190 14 246 190 14
46586-246 190 14 246 190 14 246 190 14 246 190 14
46587-246 190 14 236 178 12 216 158 10 175 118 6
46588- 80 54 7 2 2 6 6 6 6 30 30 30
46589- 54 54 54 62 62 62 50 50 50 38 38 38
46590- 14 14 14 2 2 6 2 2 6 2 2 6
46591- 2 2 6 2 2 6 2 2 6 2 2 6
46592- 2 2 6 6 6 6 80 54 7 167 114 7
46593-213 154 11 236 178 12 246 190 14 246 190 14
46594-246 190 14 246 190 14 246 190 14 246 190 14
46595-246 190 14 242 186 14 239 182 13 239 182 13
46596-230 174 11 210 150 10 174 135 50 124 112 88
46597- 82 82 82 54 54 54 34 34 34 18 18 18
46598- 6 6 6 0 0 0 0 0 0 0 0 0
46599- 0 0 0 0 0 0 0 0 0 0 0 0
46600- 0 0 0 0 0 0 0 0 0 0 0 0
46601- 0 0 0 0 0 0 6 6 6 18 18 18
46602- 50 50 50 158 118 36 192 133 9 200 144 11
46603-216 158 10 219 162 10 224 166 10 226 170 11
46604-230 174 11 236 178 12 239 182 13 239 182 13
46605-242 186 14 246 186 14 246 190 14 246 190 14
46606-246 190 14 246 190 14 246 190 14 246 190 14
46607-246 186 14 230 174 11 210 150 10 163 110 8
46608-104 69 6 10 10 10 2 2 6 2 2 6
46609- 2 2 6 2 2 6 2 2 6 2 2 6
46610- 2 2 6 2 2 6 2 2 6 2 2 6
46611- 2 2 6 2 2 6 2 2 6 2 2 6
46612- 2 2 6 6 6 6 91 60 6 167 114 7
46613-206 145 10 230 174 11 242 186 14 246 190 14
46614-246 190 14 246 190 14 246 186 14 242 186 14
46615-239 182 13 230 174 11 224 166 10 213 154 11
46616-180 133 36 124 112 88 86 86 86 58 58 58
46617- 38 38 38 22 22 22 10 10 10 6 6 6
46618- 0 0 0 0 0 0 0 0 0 0 0 0
46619- 0 0 0 0 0 0 0 0 0 0 0 0
46620- 0 0 0 0 0 0 0 0 0 0 0 0
46621- 0 0 0 0 0 0 0 0 0 14 14 14
46622- 34 34 34 70 70 70 138 110 50 158 118 36
46623-167 114 7 180 123 7 192 133 9 197 138 11
46624-200 144 11 206 145 10 213 154 11 219 162 10
46625-224 166 10 230 174 11 239 182 13 242 186 14
46626-246 186 14 246 186 14 246 186 14 246 186 14
46627-239 182 13 216 158 10 185 133 11 152 99 6
46628-104 69 6 18 14 6 2 2 6 2 2 6
46629- 2 2 6 2 2 6 2 2 6 2 2 6
46630- 2 2 6 2 2 6 2 2 6 2 2 6
46631- 2 2 6 2 2 6 2 2 6 2 2 6
46632- 2 2 6 6 6 6 80 54 7 152 99 6
46633-192 133 9 219 162 10 236 178 12 239 182 13
46634-246 186 14 242 186 14 239 182 13 236 178 12
46635-224 166 10 206 145 10 192 133 9 154 121 60
46636- 94 94 94 62 62 62 42 42 42 22 22 22
46637- 14 14 14 6 6 6 0 0 0 0 0 0
46638- 0 0 0 0 0 0 0 0 0 0 0 0
46639- 0 0 0 0 0 0 0 0 0 0 0 0
46640- 0 0 0 0 0 0 0 0 0 0 0 0
46641- 0 0 0 0 0 0 0 0 0 6 6 6
46642- 18 18 18 34 34 34 58 58 58 78 78 78
46643-101 98 89 124 112 88 142 110 46 156 107 11
46644-163 110 8 167 114 7 175 118 6 180 123 7
46645-185 133 11 197 138 11 210 150 10 219 162 10
46646-226 170 11 236 178 12 236 178 12 234 174 13
46647-219 162 10 197 138 11 163 110 8 130 83 6
46648- 91 60 6 10 10 10 2 2 6 2 2 6
46649- 18 18 18 38 38 38 38 38 38 38 38 38
46650- 38 38 38 38 38 38 38 38 38 38 38 38
46651- 38 38 38 38 38 38 26 26 26 2 2 6
46652- 2 2 6 6 6 6 70 47 6 137 92 6
46653-175 118 6 200 144 11 219 162 10 230 174 11
46654-234 174 13 230 174 11 219 162 10 210 150 10
46655-192 133 9 163 110 8 124 112 88 82 82 82
46656- 50 50 50 30 30 30 14 14 14 6 6 6
46657- 0 0 0 0 0 0 0 0 0 0 0 0
46658- 0 0 0 0 0 0 0 0 0 0 0 0
46659- 0 0 0 0 0 0 0 0 0 0 0 0
46660- 0 0 0 0 0 0 0 0 0 0 0 0
46661- 0 0 0 0 0 0 0 0 0 0 0 0
46662- 6 6 6 14 14 14 22 22 22 34 34 34
46663- 42 42 42 58 58 58 74 74 74 86 86 86
46664-101 98 89 122 102 70 130 98 46 121 87 25
46665-137 92 6 152 99 6 163 110 8 180 123 7
46666-185 133 11 197 138 11 206 145 10 200 144 11
46667-180 123 7 156 107 11 130 83 6 104 69 6
46668- 50 34 6 54 54 54 110 110 110 101 98 89
46669- 86 86 86 82 82 82 78 78 78 78 78 78
46670- 78 78 78 78 78 78 78 78 78 78 78 78
46671- 78 78 78 82 82 82 86 86 86 94 94 94
46672-106 106 106 101 101 101 86 66 34 124 80 6
46673-156 107 11 180 123 7 192 133 9 200 144 11
46674-206 145 10 200 144 11 192 133 9 175 118 6
46675-139 102 15 109 106 95 70 70 70 42 42 42
46676- 22 22 22 10 10 10 0 0 0 0 0 0
46677- 0 0 0 0 0 0 0 0 0 0 0 0
46678- 0 0 0 0 0 0 0 0 0 0 0 0
46679- 0 0 0 0 0 0 0 0 0 0 0 0
46680- 0 0 0 0 0 0 0 0 0 0 0 0
46681- 0 0 0 0 0 0 0 0 0 0 0 0
46682- 0 0 0 0 0 0 6 6 6 10 10 10
46683- 14 14 14 22 22 22 30 30 30 38 38 38
46684- 50 50 50 62 62 62 74 74 74 90 90 90
46685-101 98 89 112 100 78 121 87 25 124 80 6
46686-137 92 6 152 99 6 152 99 6 152 99 6
46687-138 86 6 124 80 6 98 70 6 86 66 30
46688-101 98 89 82 82 82 58 58 58 46 46 46
46689- 38 38 38 34 34 34 34 34 34 34 34 34
46690- 34 34 34 34 34 34 34 34 34 34 34 34
46691- 34 34 34 34 34 34 38 38 38 42 42 42
46692- 54 54 54 82 82 82 94 86 76 91 60 6
46693-134 86 6 156 107 11 167 114 7 175 118 6
46694-175 118 6 167 114 7 152 99 6 121 87 25
46695-101 98 89 62 62 62 34 34 34 18 18 18
46696- 6 6 6 0 0 0 0 0 0 0 0 0
46697- 0 0 0 0 0 0 0 0 0 0 0 0
46698- 0 0 0 0 0 0 0 0 0 0 0 0
46699- 0 0 0 0 0 0 0 0 0 0 0 0
46700- 0 0 0 0 0 0 0 0 0 0 0 0
46701- 0 0 0 0 0 0 0 0 0 0 0 0
46702- 0 0 0 0 0 0 0 0 0 0 0 0
46703- 0 0 0 6 6 6 6 6 6 10 10 10
46704- 18 18 18 22 22 22 30 30 30 42 42 42
46705- 50 50 50 66 66 66 86 86 86 101 98 89
46706-106 86 58 98 70 6 104 69 6 104 69 6
46707-104 69 6 91 60 6 82 62 34 90 90 90
46708- 62 62 62 38 38 38 22 22 22 14 14 14
46709- 10 10 10 10 10 10 10 10 10 10 10 10
46710- 10 10 10 10 10 10 6 6 6 10 10 10
46711- 10 10 10 10 10 10 10 10 10 14 14 14
46712- 22 22 22 42 42 42 70 70 70 89 81 66
46713- 80 54 7 104 69 6 124 80 6 137 92 6
46714-134 86 6 116 81 8 100 82 52 86 86 86
46715- 58 58 58 30 30 30 14 14 14 6 6 6
46716- 0 0 0 0 0 0 0 0 0 0 0 0
46717- 0 0 0 0 0 0 0 0 0 0 0 0
46718- 0 0 0 0 0 0 0 0 0 0 0 0
46719- 0 0 0 0 0 0 0 0 0 0 0 0
46720- 0 0 0 0 0 0 0 0 0 0 0 0
46721- 0 0 0 0 0 0 0 0 0 0 0 0
46722- 0 0 0 0 0 0 0 0 0 0 0 0
46723- 0 0 0 0 0 0 0 0 0 0 0 0
46724- 0 0 0 6 6 6 10 10 10 14 14 14
46725- 18 18 18 26 26 26 38 38 38 54 54 54
46726- 70 70 70 86 86 86 94 86 76 89 81 66
46727- 89 81 66 86 86 86 74 74 74 50 50 50
46728- 30 30 30 14 14 14 6 6 6 0 0 0
46729- 0 0 0 0 0 0 0 0 0 0 0 0
46730- 0 0 0 0 0 0 0 0 0 0 0 0
46731- 0 0 0 0 0 0 0 0 0 0 0 0
46732- 6 6 6 18 18 18 34 34 34 58 58 58
46733- 82 82 82 89 81 66 89 81 66 89 81 66
46734- 94 86 66 94 86 76 74 74 74 50 50 50
46735- 26 26 26 14 14 14 6 6 6 0 0 0
46736- 0 0 0 0 0 0 0 0 0 0 0 0
46737- 0 0 0 0 0 0 0 0 0 0 0 0
46738- 0 0 0 0 0 0 0 0 0 0 0 0
46739- 0 0 0 0 0 0 0 0 0 0 0 0
46740- 0 0 0 0 0 0 0 0 0 0 0 0
46741- 0 0 0 0 0 0 0 0 0 0 0 0
46742- 0 0 0 0 0 0 0 0 0 0 0 0
46743- 0 0 0 0 0 0 0 0 0 0 0 0
46744- 0 0 0 0 0 0 0 0 0 0 0 0
46745- 6 6 6 6 6 6 14 14 14 18 18 18
46746- 30 30 30 38 38 38 46 46 46 54 54 54
46747- 50 50 50 42 42 42 30 30 30 18 18 18
46748- 10 10 10 0 0 0 0 0 0 0 0 0
46749- 0 0 0 0 0 0 0 0 0 0 0 0
46750- 0 0 0 0 0 0 0 0 0 0 0 0
46751- 0 0 0 0 0 0 0 0 0 0 0 0
46752- 0 0 0 6 6 6 14 14 14 26 26 26
46753- 38 38 38 50 50 50 58 58 58 58 58 58
46754- 54 54 54 42 42 42 30 30 30 18 18 18
46755- 10 10 10 0 0 0 0 0 0 0 0 0
46756- 0 0 0 0 0 0 0 0 0 0 0 0
46757- 0 0 0 0 0 0 0 0 0 0 0 0
46758- 0 0 0 0 0 0 0 0 0 0 0 0
46759- 0 0 0 0 0 0 0 0 0 0 0 0
46760- 0 0 0 0 0 0 0 0 0 0 0 0
46761- 0 0 0 0 0 0 0 0 0 0 0 0
46762- 0 0 0 0 0 0 0 0 0 0 0 0
46763- 0 0 0 0 0 0 0 0 0 0 0 0
46764- 0 0 0 0 0 0 0 0 0 0 0 0
46765- 0 0 0 0 0 0 0 0 0 6 6 6
46766- 6 6 6 10 10 10 14 14 14 18 18 18
46767- 18 18 18 14 14 14 10 10 10 6 6 6
46768- 0 0 0 0 0 0 0 0 0 0 0 0
46769- 0 0 0 0 0 0 0 0 0 0 0 0
46770- 0 0 0 0 0 0 0 0 0 0 0 0
46771- 0 0 0 0 0 0 0 0 0 0 0 0
46772- 0 0 0 0 0 0 0 0 0 6 6 6
46773- 14 14 14 18 18 18 22 22 22 22 22 22
46774- 18 18 18 14 14 14 10 10 10 6 6 6
46775- 0 0 0 0 0 0 0 0 0 0 0 0
46776- 0 0 0 0 0 0 0 0 0 0 0 0
46777- 0 0 0 0 0 0 0 0 0 0 0 0
46778- 0 0 0 0 0 0 0 0 0 0 0 0
46779- 0 0 0 0 0 0 0 0 0 0 0 0
46780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46786+4 4 4 4 4 4 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
46794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46800+4 4 4 4 4 4 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
46808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46821+4 4 4 4 4 4
46822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46835+4 4 4 4 4 4
46836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46849+4 4 4 4 4 4
46850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46852+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46863+4 4 4 4 4 4
46864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46868+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46869+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46873+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46874+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46875+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46877+4 4 4 4 4 4
46878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46882+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46883+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46884+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46887+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46888+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46889+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46890+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46891+4 4 4 4 4 4
46892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46896+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46897+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46898+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46901+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46902+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46903+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46904+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46905+4 4 4 4 4 4
46906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46909+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46910+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46911+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46912+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46914+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46915+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46916+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46917+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46918+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46919+4 4 4 4 4 4
46920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46923+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46924+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46925+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46926+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46927+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46928+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46929+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46930+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46931+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46932+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46933+4 4 4 4 4 4
46934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46937+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46938+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46939+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46940+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46941+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46942+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46943+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46944+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46945+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46946+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46947+4 4 4 4 4 4
46948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46950+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46951+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46952+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46953+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46954+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46955+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46956+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46957+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46958+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46959+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46960+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46961+4 4 4 4 4 4
46962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46964+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46965+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46966+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46967+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46968+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46969+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46970+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46971+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46972+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46973+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46974+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46975+4 4 4 4 4 4
46976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46978+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46979+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46980+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46981+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46982+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46983+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46984+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46985+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46986+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46987+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46988+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46989+4 4 4 4 4 4
46990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46992+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46993+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46994+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46995+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46996+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46997+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46998+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46999+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
47000+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
47001+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
47002+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
47003+4 4 4 4 4 4
47004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47005+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
47006+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
47007+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
47008+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
47009+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
47010+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
47011+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
47012+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
47013+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
47014+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
47015+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
47016+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
47017+4 4 4 4 4 4
47018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47019+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
47020+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
47021+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
47022+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47023+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
47024+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
47025+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
47026+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
47027+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
47028+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
47029+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
47030+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
47031+0 0 0 4 4 4
47032+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
47033+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
47034+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
47035+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
47036+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
47037+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
47038+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
47039+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
47040+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
47041+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
47042+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
47043+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
47044+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
47045+2 0 0 0 0 0
47046+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
47047+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
47048+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
47049+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
47050+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
47051+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
47052+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
47053+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
47054+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
47055+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
47056+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
47057+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
47058+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
47059+37 38 37 0 0 0
47060+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47061+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
47062+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
47063+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
47064+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
47065+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
47066+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
47067+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
47068+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
47069+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
47070+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
47071+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
47072+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
47073+85 115 134 4 0 0
47074+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
47075+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
47076+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
47077+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
47078+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
47079+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
47080+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
47081+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
47082+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
47083+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
47084+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
47085+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
47086+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
47087+60 73 81 4 0 0
47088+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
47089+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
47090+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
47091+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
47092+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
47093+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
47094+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
47095+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
47096+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
47097+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
47098+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
47099+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
47100+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
47101+16 19 21 4 0 0
47102+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
47103+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
47104+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
47105+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
47106+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
47107+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
47108+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
47109+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
47110+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
47111+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
47112+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
47113+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
47114+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
47115+4 0 0 4 3 3
47116+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
47117+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
47118+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
47119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
47120+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
47121+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
47122+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
47123+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
47124+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
47125+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
47126+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
47127+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
47128+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
47129+3 2 2 4 4 4
47130+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
47131+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
47132+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
47133+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47134+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
47135+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
47136+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
47137+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
47138+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
47139+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
47140+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
47141+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
47142+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
47143+4 4 4 4 4 4
47144+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
47145+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
47146+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
47147+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
47148+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
47149+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
47150+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
47151+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
47152+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
47153+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
47154+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
47155+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
47156+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
47157+4 4 4 4 4 4
47158+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
47159+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
47160+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
47161+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
47162+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
47163+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47164+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
47165+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
47166+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
47167+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
47168+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
47169+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
47170+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
47171+5 5 5 5 5 5
47172+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
47173+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
47174+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
47175+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
47176+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
47177+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47178+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
47179+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
47180+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
47181+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
47182+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
47183+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
47184+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47185+5 5 5 4 4 4
47186+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
47187+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
47188+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
47189+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
47190+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47191+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
47192+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
47193+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
47194+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
47195+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
47196+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
47197+4 0 0 4 0 0 5 5 5 5 5 5 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
47200+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
47201+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
47202+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
47203+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
47204+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
47205+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47206+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47207+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
47208+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
47209+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
47210+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
47211+3 3 3 5 5 5 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
47214+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
47215+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
47216+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
47217+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
47218+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47219+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
47220+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
47221+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
47222+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
47223+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
47224+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
47225+4 4 4 4 4 4 4 4 4 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
47228+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
47229+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
47230+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
47231+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
47232+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47233+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47234+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47235+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
47236+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
47237+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
47238+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
47239+4 4 4 4 4 4 4 4 4 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
47242+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
47243+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
47244+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
47245+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
47246+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47247+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
47248+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47249+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
47250+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
47251+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
47252+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47253+4 4 4 4 4 4 4 4 4 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
47256+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
47257+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
47258+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
47259+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
47260+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47261+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
47262+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
47263+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
47264+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
47265+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
47266+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
47267+4 4 4 4 4 4 4 4 4 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
47270+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
47271+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
47272+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
47273+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
47274+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47275+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
47276+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
47277+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
47278+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
47279+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
47280+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
47281+4 4 4 4 4 4 4 4 4 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
47284+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
47285+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
47286+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
47287+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47288+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
47289+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
47290+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
47291+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
47292+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
47293+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
47294+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47295+4 4 4 4 4 4 4 4 4 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
47298+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
47299+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
47300+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
47301+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47302+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47303+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
47304+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
47305+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
47306+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
47307+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
47308+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47309+4 4 4 4 4 4 4 4 4 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
47312+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
47313+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
47314+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47315+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47316+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47317+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
47318+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
47319+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
47320+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
47321+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
47322+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47323+4 4 4 4 4 4 4 4 4 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
47326+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
47327+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
47328+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47329+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47330+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47331+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
47332+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
47333+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
47334+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47335+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47336+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47337+4 4 4 4 4 4 4 4 4 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
47340+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47341+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
47342+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47343+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
47344+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
47345+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
47346+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
47347+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
47348+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47349+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47350+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47351+4 4 4 4 4 4 4 4 4 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
47354+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47355+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
47356+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47357+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
47358+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47359+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
47360+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
47361+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
47362+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47363+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47364+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47365+4 4 4 4 4 4 4 4 4 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
47368+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
47369+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
47370+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47371+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
47372+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
47373+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
47374+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
47375+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
47376+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47377+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47378+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47379+4 4 4 4 4 4 4 4 4 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
47382+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
47383+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
47384+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47385+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
47386+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
47387+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
47388+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
47389+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
47390+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47391+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47392+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47393+4 4 4 4 4 4 4 4 4 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
47396+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47397+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
47398+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47399+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
47400+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
47401+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
47402+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
47403+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
47404+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47405+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47406+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47407+4 4 4 4 4 4 4 4 4 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
47410+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
47411+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
47412+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47413+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
47414+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
47415+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
47416+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
47417+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
47418+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
47419+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47420+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47421+4 4 4 4 4 4 4 4 4 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
47424+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47425+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
47426+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
47427+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
47428+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
47429+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
47430+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
47431+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
47432+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47433+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47434+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47435+4 4 4 4 4 4 4 4 4 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
47438+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47439+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
47440+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47441+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
47442+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
47443+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
47444+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
47445+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
47446+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47447+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47448+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47449+4 4 4 4 4 4 4 4 4 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
47452+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47453+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
47454+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
47455+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
47456+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
47457+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
47458+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47459+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
47460+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47461+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47462+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47463+4 4 4 4 4 4 4 4 4 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
47466+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47467+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
47468+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
47469+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47470+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
47471+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
47472+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47473+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
47474+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47475+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47476+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47477+4 4 4 4 4 4 4 4 4 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
47480+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47481+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
47482+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
47483+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
47484+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
47485+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
47486+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
47487+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
47488+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
47489+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47490+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47491+4 4 4 4 4 4 4 4 4 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
47494+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47495+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
47496+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
47497+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
47498+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
47499+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
47500+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
47501+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
47502+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
47503+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47504+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47505+4 4 4 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
47508+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
47509+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
47510+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
47511+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
47512+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47513+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
47514+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
47515+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
47516+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
47517+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47518+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47519+4 4 4 4 4 4 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
47522+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47523+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
47524+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
47525+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
47526+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
47527+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
47528+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
47529+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
47530+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
47531+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47532+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47533+4 4 4 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
47536+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
47537+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
47538+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
47539+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
47540+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
47541+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
47542+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
47543+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
47544+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
47545+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
47546+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
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
47550+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
47551+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47552+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
47553+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
47554+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
47555+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
47556+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
47557+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
47558+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
47559+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
47560+0 0 0 4 4 4 4 4 4 4 4 4 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
47564+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
47565+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47566+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
47567+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
47568+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
47569+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
47570+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47571+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
47572+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
47573+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
47574+4 3 3 5 5 5 4 4 4 4 4 4 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
47578+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
47579+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
47580+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
47581+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
47582+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
47583+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
47584+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
47585+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
47586+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
47587+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
47588+5 5 5 4 4 4 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
47592+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
47593+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
47594+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47595+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
47596+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
47597+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
47598+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
47599+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
47600+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
47601+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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
47606+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47607+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
47608+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
47609+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
47610+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
47611+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
47612+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
47613+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
47614+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
47615+13 16 17 4 0 0 4 0 0 4 3 3 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
47620+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
47621+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
47622+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
47623+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
47624+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
47625+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
47626+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
47627+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
47628+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
47629+4 0 0 4 0 0 5 5 5 5 5 5 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
47634+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
47635+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
47636+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
47637+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
47638+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
47639+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
47640+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
47641+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
47642+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47643+4 3 3 5 5 5 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
47648+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
47649+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47650+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
47651+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47652+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
47653+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
47654+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
47655+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
47656+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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
47662+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
47663+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
47664+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
47665+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
47666+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
47667+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
47668+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
47669+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
47670+4 0 0 4 0 0 4 0 0 6 6 6 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
47676+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47677+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
47678+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
47679+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
47680+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
47681+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
47682+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
47683+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
47684+4 0 0 4 4 4 4 4 4 4 4 4 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
47690+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
47691+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
47692+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47693+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
47694+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
47695+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
47696+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
47697+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
47698+4 4 4 4 4 4 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
47704+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47705+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
47706+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
47707+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
47708+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
47709+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
47710+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
47711+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47712+4 4 4 4 4 4 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
47718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47719+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47720+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47721+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47722+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47723+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47724+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47725+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
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
47732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47733+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47734+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47735+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47736+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47737+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47738+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47739+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
47740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47741+4 4 4 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
47746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47747+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47748+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47749+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47750+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47751+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47752+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47753+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
47760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47762+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47763+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47764+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47765+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47766+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47767+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47770+4 4 4 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
47774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47777+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47778+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47779+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47780+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47784+4 4 4 4 4 4 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
47788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47791+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47792+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47793+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47794+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47798+4 4 4 4 4 4 4 4 4 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
47802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47805+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47806+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47807+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47808+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
47816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47819+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47820+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47821+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47822+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47827+4 4 4 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
47830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47834+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47835+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47836+6 6 6 4 3 3 5 5 5 4 4 4 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
47844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47848+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47849+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47850+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47857+4 4 4 4 4 4
47858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47862+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47863+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47864+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47871+4 4 4 4 4 4
47872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47876+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47877+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47885+4 4 4 4 4 4
47886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47890+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47891+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47899+4 4 4 4 4 4
47900diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47901index fe92eed..106e085 100644
47902--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47903+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47904@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47905 struct mb862xxfb_par *par = info->par;
47906
47907 if (info->var.bits_per_pixel == 32) {
47908- info->fbops->fb_fillrect = cfb_fillrect;
47909- info->fbops->fb_copyarea = cfb_copyarea;
47910- info->fbops->fb_imageblit = cfb_imageblit;
47911+ pax_open_kernel();
47912+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47913+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47914+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47915+ pax_close_kernel();
47916 } else {
47917 outreg(disp, GC_L0EM, 3);
47918- info->fbops->fb_fillrect = mb86290fb_fillrect;
47919- info->fbops->fb_copyarea = mb86290fb_copyarea;
47920- info->fbops->fb_imageblit = mb86290fb_imageblit;
47921+ pax_open_kernel();
47922+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47923+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47924+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47925+ pax_close_kernel();
47926 }
47927 outreg(draw, GDC_REG_DRAW_BASE, 0);
47928 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47929diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47930index ff22871..b129bed 100644
47931--- a/drivers/video/nvidia/nvidia.c
47932+++ b/drivers/video/nvidia/nvidia.c
47933@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47934 info->fix.line_length = (info->var.xres_virtual *
47935 info->var.bits_per_pixel) >> 3;
47936 if (info->var.accel_flags) {
47937- info->fbops->fb_imageblit = nvidiafb_imageblit;
47938- info->fbops->fb_fillrect = nvidiafb_fillrect;
47939- info->fbops->fb_copyarea = nvidiafb_copyarea;
47940- info->fbops->fb_sync = nvidiafb_sync;
47941+ pax_open_kernel();
47942+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47943+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47944+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47945+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47946+ pax_close_kernel();
47947 info->pixmap.scan_align = 4;
47948 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47949 info->flags |= FBINFO_READS_FAST;
47950 NVResetGraphics(info);
47951 } else {
47952- info->fbops->fb_imageblit = cfb_imageblit;
47953- info->fbops->fb_fillrect = cfb_fillrect;
47954- info->fbops->fb_copyarea = cfb_copyarea;
47955- info->fbops->fb_sync = NULL;
47956+ pax_open_kernel();
47957+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47958+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47959+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47960+ *(void **)&info->fbops->fb_sync = NULL;
47961+ pax_close_kernel();
47962 info->pixmap.scan_align = 1;
47963 info->flags |= FBINFO_HWACCEL_DISABLED;
47964 info->flags &= ~FBINFO_READS_FAST;
47965@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47966 info->pixmap.size = 8 * 1024;
47967 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47968
47969- if (!hwcur)
47970- info->fbops->fb_cursor = NULL;
47971+ if (!hwcur) {
47972+ pax_open_kernel();
47973+ *(void **)&info->fbops->fb_cursor = NULL;
47974+ pax_close_kernel();
47975+ }
47976
47977 info->var.accel_flags = (!noaccel);
47978
47979diff --git a/drivers/video/output.c b/drivers/video/output.c
47980index 0d6f2cd..6285b97 100644
47981--- a/drivers/video/output.c
47982+++ b/drivers/video/output.c
47983@@ -97,7 +97,7 @@ struct output_device *video_output_register(const char *name,
47984 new_dev->props = op;
47985 new_dev->dev.class = &video_output_class;
47986 new_dev->dev.parent = dev;
47987- dev_set_name(&new_dev->dev, name);
47988+ dev_set_name(&new_dev->dev, "%s", name);
47989 dev_set_drvdata(&new_dev->dev, devdata);
47990 ret_code = device_register(&new_dev->dev);
47991 if (ret_code) {
47992diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47993index 05c2dc3..ea1f391 100644
47994--- a/drivers/video/s1d13xxxfb.c
47995+++ b/drivers/video/s1d13xxxfb.c
47996@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47997
47998 switch(prod_id) {
47999 case S1D13506_PROD_ID: /* activate acceleration */
48000- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
48001- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
48002+ pax_open_kernel();
48003+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
48004+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
48005+ pax_close_kernel();
48006 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
48007 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
48008 break;
48009diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
48010index b2b33fc..f9f4658 100644
48011--- a/drivers/video/smscufx.c
48012+++ b/drivers/video/smscufx.c
48013@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
48014 fb_deferred_io_cleanup(info);
48015 kfree(info->fbdefio);
48016 info->fbdefio = NULL;
48017- info->fbops->fb_mmap = ufx_ops_mmap;
48018+ pax_open_kernel();
48019+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
48020+ pax_close_kernel();
48021 }
48022
48023 pr_debug("released /dev/fb%d user=%d count=%d",
48024diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
48025index ec03e72..f578436 100644
48026--- a/drivers/video/udlfb.c
48027+++ b/drivers/video/udlfb.c
48028@@ -623,11 +623,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
48029 dlfb_urb_completion(urb);
48030
48031 error:
48032- atomic_add(bytes_sent, &dev->bytes_sent);
48033- atomic_add(bytes_identical, &dev->bytes_identical);
48034- atomic_add(width*height*2, &dev->bytes_rendered);
48035+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48036+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48037+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
48038 end_cycles = get_cycles();
48039- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48040+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48041 >> 10)), /* Kcycles */
48042 &dev->cpu_kcycles_used);
48043
48044@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
48045 dlfb_urb_completion(urb);
48046
48047 error:
48048- atomic_add(bytes_sent, &dev->bytes_sent);
48049- atomic_add(bytes_identical, &dev->bytes_identical);
48050- atomic_add(bytes_rendered, &dev->bytes_rendered);
48051+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48052+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48053+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
48054 end_cycles = get_cycles();
48055- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48056+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48057 >> 10)), /* Kcycles */
48058 &dev->cpu_kcycles_used);
48059 }
48060@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
48061 fb_deferred_io_cleanup(info);
48062 kfree(info->fbdefio);
48063 info->fbdefio = NULL;
48064- info->fbops->fb_mmap = dlfb_ops_mmap;
48065+ pax_open_kernel();
48066+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
48067+ pax_close_kernel();
48068 }
48069
48070 pr_warn("released /dev/fb%d user=%d count=%d\n",
48071@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
48072 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48073 struct dlfb_data *dev = fb_info->par;
48074 return snprintf(buf, PAGE_SIZE, "%u\n",
48075- atomic_read(&dev->bytes_rendered));
48076+ atomic_read_unchecked(&dev->bytes_rendered));
48077 }
48078
48079 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48080@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48081 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48082 struct dlfb_data *dev = fb_info->par;
48083 return snprintf(buf, PAGE_SIZE, "%u\n",
48084- atomic_read(&dev->bytes_identical));
48085+ atomic_read_unchecked(&dev->bytes_identical));
48086 }
48087
48088 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48089@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48090 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48091 struct dlfb_data *dev = fb_info->par;
48092 return snprintf(buf, PAGE_SIZE, "%u\n",
48093- atomic_read(&dev->bytes_sent));
48094+ atomic_read_unchecked(&dev->bytes_sent));
48095 }
48096
48097 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48098@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48099 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48100 struct dlfb_data *dev = fb_info->par;
48101 return snprintf(buf, PAGE_SIZE, "%u\n",
48102- atomic_read(&dev->cpu_kcycles_used));
48103+ atomic_read_unchecked(&dev->cpu_kcycles_used));
48104 }
48105
48106 static ssize_t edid_show(
48107@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
48108 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48109 struct dlfb_data *dev = fb_info->par;
48110
48111- atomic_set(&dev->bytes_rendered, 0);
48112- atomic_set(&dev->bytes_identical, 0);
48113- atomic_set(&dev->bytes_sent, 0);
48114- atomic_set(&dev->cpu_kcycles_used, 0);
48115+ atomic_set_unchecked(&dev->bytes_rendered, 0);
48116+ atomic_set_unchecked(&dev->bytes_identical, 0);
48117+ atomic_set_unchecked(&dev->bytes_sent, 0);
48118+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
48119
48120 return count;
48121 }
48122diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
48123index e328a61..1b08ecb 100644
48124--- a/drivers/video/uvesafb.c
48125+++ b/drivers/video/uvesafb.c
48126@@ -19,6 +19,7 @@
48127 #include <linux/io.h>
48128 #include <linux/mutex.h>
48129 #include <linux/slab.h>
48130+#include <linux/moduleloader.h>
48131 #include <video/edid.h>
48132 #include <video/uvesafb.h>
48133 #ifdef CONFIG_X86
48134@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
48135 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
48136 par->pmi_setpal = par->ypan = 0;
48137 } else {
48138+
48139+#ifdef CONFIG_PAX_KERNEXEC
48140+#ifdef CONFIG_MODULES
48141+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
48142+#endif
48143+ if (!par->pmi_code) {
48144+ par->pmi_setpal = par->ypan = 0;
48145+ return 0;
48146+ }
48147+#endif
48148+
48149 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
48150 + task->t.regs.edi);
48151+
48152+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48153+ pax_open_kernel();
48154+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
48155+ pax_close_kernel();
48156+
48157+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
48158+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
48159+#else
48160 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
48161 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
48162+#endif
48163+
48164 printk(KERN_INFO "uvesafb: protected mode interface info at "
48165 "%04x:%04x\n",
48166 (u16)task->t.regs.es, (u16)task->t.regs.edi);
48167@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
48168 par->ypan = ypan;
48169
48170 if (par->pmi_setpal || par->ypan) {
48171+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
48172 if (__supported_pte_mask & _PAGE_NX) {
48173 par->pmi_setpal = par->ypan = 0;
48174 printk(KERN_WARNING "uvesafb: NX protection is actively."
48175 "We have better not to use the PMI.\n");
48176- } else {
48177+ } else
48178+#endif
48179 uvesafb_vbe_getpmi(task, par);
48180- }
48181 }
48182 #else
48183 /* The protected mode interface is not available on non-x86. */
48184@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48185 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
48186
48187 /* Disable blanking if the user requested so. */
48188- if (!blank)
48189- info->fbops->fb_blank = NULL;
48190+ if (!blank) {
48191+ pax_open_kernel();
48192+ *(void **)&info->fbops->fb_blank = NULL;
48193+ pax_close_kernel();
48194+ }
48195
48196 /*
48197 * Find out how much IO memory is required for the mode with
48198@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48199 info->flags = FBINFO_FLAG_DEFAULT |
48200 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
48201
48202- if (!par->ypan)
48203- info->fbops->fb_pan_display = NULL;
48204+ if (!par->ypan) {
48205+ pax_open_kernel();
48206+ *(void **)&info->fbops->fb_pan_display = NULL;
48207+ pax_close_kernel();
48208+ }
48209 }
48210
48211 static void uvesafb_init_mtrr(struct fb_info *info)
48212@@ -1836,6 +1866,11 @@ out:
48213 if (par->vbe_modes)
48214 kfree(par->vbe_modes);
48215
48216+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48217+ if (par->pmi_code)
48218+ module_free_exec(NULL, par->pmi_code);
48219+#endif
48220+
48221 framebuffer_release(info);
48222 return err;
48223 }
48224@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
48225 kfree(par->vbe_state_orig);
48226 if (par->vbe_state_saved)
48227 kfree(par->vbe_state_saved);
48228+
48229+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48230+ if (par->pmi_code)
48231+ module_free_exec(NULL, par->pmi_code);
48232+#endif
48233+
48234 }
48235
48236 framebuffer_release(info);
48237diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
48238index 501b340..d80aa17 100644
48239--- a/drivers/video/vesafb.c
48240+++ b/drivers/video/vesafb.c
48241@@ -9,6 +9,7 @@
48242 */
48243
48244 #include <linux/module.h>
48245+#include <linux/moduleloader.h>
48246 #include <linux/kernel.h>
48247 #include <linux/errno.h>
48248 #include <linux/string.h>
48249@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
48250 static int vram_total __initdata; /* Set total amount of memory */
48251 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
48252 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
48253-static void (*pmi_start)(void) __read_mostly;
48254-static void (*pmi_pal) (void) __read_mostly;
48255+static void (*pmi_start)(void) __read_only;
48256+static void (*pmi_pal) (void) __read_only;
48257 static int depth __read_mostly;
48258 static int vga_compat __read_mostly;
48259 /* --------------------------------------------------------------------- */
48260@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
48261 unsigned int size_vmode;
48262 unsigned int size_remap;
48263 unsigned int size_total;
48264+ void *pmi_code = NULL;
48265
48266 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
48267 return -ENODEV;
48268@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
48269 size_remap = size_total;
48270 vesafb_fix.smem_len = size_remap;
48271
48272-#ifndef __i386__
48273- screen_info.vesapm_seg = 0;
48274-#endif
48275-
48276 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
48277 printk(KERN_WARNING
48278 "vesafb: cannot reserve video memory at 0x%lx\n",
48279@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
48280 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
48281 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
48282
48283+#ifdef __i386__
48284+
48285+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48286+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
48287+ if (!pmi_code)
48288+#elif !defined(CONFIG_PAX_KERNEXEC)
48289+ if (0)
48290+#endif
48291+
48292+#endif
48293+ screen_info.vesapm_seg = 0;
48294+
48295 if (screen_info.vesapm_seg) {
48296- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
48297- screen_info.vesapm_seg,screen_info.vesapm_off);
48298+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
48299+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
48300 }
48301
48302 if (screen_info.vesapm_seg < 0xc000)
48303@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
48304
48305 if (ypan || pmi_setpal) {
48306 unsigned short *pmi_base;
48307+
48308 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
48309- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
48310- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
48311+
48312+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48313+ pax_open_kernel();
48314+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
48315+#else
48316+ pmi_code = pmi_base;
48317+#endif
48318+
48319+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
48320+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
48321+
48322+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48323+ pmi_start = ktva_ktla(pmi_start);
48324+ pmi_pal = ktva_ktla(pmi_pal);
48325+ pax_close_kernel();
48326+#endif
48327+
48328 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
48329 if (pmi_base[3]) {
48330 printk(KERN_INFO "vesafb: pmi: ports = ");
48331@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48332 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
48333 (ypan ? FBINFO_HWACCEL_YPAN : 0);
48334
48335- if (!ypan)
48336- info->fbops->fb_pan_display = NULL;
48337+ if (!ypan) {
48338+ pax_open_kernel();
48339+ *(void **)&info->fbops->fb_pan_display = NULL;
48340+ pax_close_kernel();
48341+ }
48342
48343 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
48344 err = -ENOMEM;
48345@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48346 info->node, info->fix.id);
48347 return 0;
48348 err:
48349+
48350+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48351+ module_free_exec(NULL, pmi_code);
48352+#endif
48353+
48354 if (info->screen_base)
48355 iounmap(info->screen_base);
48356 framebuffer_release(info);
48357diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
48358index 88714ae..16c2e11 100644
48359--- a/drivers/video/via/via_clock.h
48360+++ b/drivers/video/via/via_clock.h
48361@@ -56,7 +56,7 @@ struct via_clock {
48362
48363 void (*set_engine_pll_state)(u8 state);
48364 void (*set_engine_pll)(struct via_pll_config config);
48365-};
48366+} __no_const;
48367
48368
48369 static inline u32 get_pll_internal_frequency(u32 ref_freq,
48370diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
48371index fef20db..d28b1ab 100644
48372--- a/drivers/xen/xenfs/xenstored.c
48373+++ b/drivers/xen/xenfs/xenstored.c
48374@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
48375 static int xsd_kva_open(struct inode *inode, struct file *file)
48376 {
48377 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
48378+#ifdef CONFIG_GRKERNSEC_HIDESYM
48379+ NULL);
48380+#else
48381 xen_store_interface);
48382+#endif
48383+
48384 if (!file->private_data)
48385 return -ENOMEM;
48386 return 0;
48387diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
48388index 055562c..fdfb10d 100644
48389--- a/fs/9p/vfs_addr.c
48390+++ b/fs/9p/vfs_addr.c
48391@@ -186,7 +186,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
48392
48393 retval = v9fs_file_write_internal(inode,
48394 v9inode->writeback_fid,
48395- (__force const char __user *)buffer,
48396+ (const char __force_user *)buffer,
48397 len, &offset, 0);
48398 if (retval > 0)
48399 retval = 0;
48400diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
48401index d86edc8..40ff2fb 100644
48402--- a/fs/9p/vfs_inode.c
48403+++ b/fs/9p/vfs_inode.c
48404@@ -1314,7 +1314,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48405 void
48406 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48407 {
48408- char *s = nd_get_link(nd);
48409+ const char *s = nd_get_link(nd);
48410
48411 p9_debug(P9_DEBUG_VFS, " %s %s\n",
48412 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
48413diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
48414index 370b24c..ff0be7b 100644
48415--- a/fs/Kconfig.binfmt
48416+++ b/fs/Kconfig.binfmt
48417@@ -103,7 +103,7 @@ config HAVE_AOUT
48418
48419 config BINFMT_AOUT
48420 tristate "Kernel support for a.out and ECOFF binaries"
48421- depends on HAVE_AOUT
48422+ depends on HAVE_AOUT && BROKEN
48423 ---help---
48424 A.out (Assembler.OUTput) is a set of formats for libraries and
48425 executables used in the earliest versions of UNIX. Linux used
48426diff --git a/fs/aio.c b/fs/aio.c
48427index 2bbcacf..8614116 100644
48428--- a/fs/aio.c
48429+++ b/fs/aio.c
48430@@ -160,7 +160,7 @@ static int aio_setup_ring(struct kioctx *ctx)
48431 size += sizeof(struct io_event) * nr_events;
48432 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
48433
48434- if (nr_pages < 0)
48435+ if (nr_pages <= 0)
48436 return -EINVAL;
48437
48438 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
48439@@ -950,6 +950,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
48440 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
48441 {
48442 ssize_t ret;
48443+ struct iovec iovstack;
48444
48445 kiocb->ki_nr_segs = kiocb->ki_nbytes;
48446
48447@@ -957,17 +958,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
48448 if (compat)
48449 ret = compat_rw_copy_check_uvector(rw,
48450 (struct compat_iovec __user *)kiocb->ki_buf,
48451- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
48452+ kiocb->ki_nr_segs, 1, &iovstack,
48453 &kiocb->ki_iovec);
48454 else
48455 #endif
48456 ret = rw_copy_check_uvector(rw,
48457 (struct iovec __user *)kiocb->ki_buf,
48458- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
48459+ kiocb->ki_nr_segs, 1, &iovstack,
48460 &kiocb->ki_iovec);
48461 if (ret < 0)
48462 return ret;
48463
48464+ if (kiocb->ki_iovec == &iovstack) {
48465+ kiocb->ki_inline_vec = iovstack;
48466+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
48467+ }
48468+
48469 /* ki_nbytes now reflect bytes instead of segs */
48470 kiocb->ki_nbytes = ret;
48471 return 0;
48472diff --git a/fs/attr.c b/fs/attr.c
48473index 1449adb..a2038c2 100644
48474--- a/fs/attr.c
48475+++ b/fs/attr.c
48476@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
48477 unsigned long limit;
48478
48479 limit = rlimit(RLIMIT_FSIZE);
48480+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
48481 if (limit != RLIM_INFINITY && offset > limit)
48482 goto out_sig;
48483 if (offset > inode->i_sb->s_maxbytes)
48484diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
48485index 3db70da..7aeec5b 100644
48486--- a/fs/autofs4/waitq.c
48487+++ b/fs/autofs4/waitq.c
48488@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
48489 {
48490 unsigned long sigpipe, flags;
48491 mm_segment_t fs;
48492- const char *data = (const char *)addr;
48493+ const char __user *data = (const char __force_user *)addr;
48494 ssize_t wr = 0;
48495
48496 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
48497@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
48498 return 1;
48499 }
48500
48501+#ifdef CONFIG_GRKERNSEC_HIDESYM
48502+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
48503+#endif
48504+
48505 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48506 enum autofs_notify notify)
48507 {
48508@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48509
48510 /* If this is a direct mount request create a dummy name */
48511 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
48512+#ifdef CONFIG_GRKERNSEC_HIDESYM
48513+ /* this name does get written to userland via autofs4_write() */
48514+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
48515+#else
48516 qstr.len = sprintf(name, "%p", dentry);
48517+#endif
48518 else {
48519 qstr.len = autofs4_getpath(sbi, dentry, &name);
48520 if (!qstr.len) {
48521diff --git a/fs/befs/endian.h b/fs/befs/endian.h
48522index 2722387..c8dd2a7 100644
48523--- a/fs/befs/endian.h
48524+++ b/fs/befs/endian.h
48525@@ -11,7 +11,7 @@
48526
48527 #include <asm/byteorder.h>
48528
48529-static inline u64
48530+static inline u64 __intentional_overflow(-1)
48531 fs64_to_cpu(const struct super_block *sb, fs64 n)
48532 {
48533 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48534@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
48535 return (__force fs64)cpu_to_be64(n);
48536 }
48537
48538-static inline u32
48539+static inline u32 __intentional_overflow(-1)
48540 fs32_to_cpu(const struct super_block *sb, fs32 n)
48541 {
48542 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48543diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
48544index f95dddc..b1e2c1c 100644
48545--- a/fs/befs/linuxvfs.c
48546+++ b/fs/befs/linuxvfs.c
48547@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48548 {
48549 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
48550 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
48551- char *link = nd_get_link(nd);
48552+ const char *link = nd_get_link(nd);
48553 if (!IS_ERR(link))
48554 kfree(link);
48555 }
48556diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
48557index bce8769..7fc7544 100644
48558--- a/fs/binfmt_aout.c
48559+++ b/fs/binfmt_aout.c
48560@@ -16,6 +16,7 @@
48561 #include <linux/string.h>
48562 #include <linux/fs.h>
48563 #include <linux/file.h>
48564+#include <linux/security.h>
48565 #include <linux/stat.h>
48566 #include <linux/fcntl.h>
48567 #include <linux/ptrace.h>
48568@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
48569 #endif
48570 # define START_STACK(u) ((void __user *)u.start_stack)
48571
48572+ memset(&dump, 0, sizeof(dump));
48573+
48574 fs = get_fs();
48575 set_fs(KERNEL_DS);
48576 has_dumped = 1;
48577@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
48578
48579 /* If the size of the dump file exceeds the rlimit, then see what would happen
48580 if we wrote the stack, but not the data area. */
48581+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
48582 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
48583 dump.u_dsize = 0;
48584
48585 /* Make sure we have enough room to write the stack and data areas. */
48586+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
48587 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
48588 dump.u_ssize = 0;
48589
48590@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
48591 rlim = rlimit(RLIMIT_DATA);
48592 if (rlim >= RLIM_INFINITY)
48593 rlim = ~0;
48594+
48595+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
48596 if (ex.a_data + ex.a_bss > rlim)
48597 return -ENOMEM;
48598
48599@@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
48600
48601 install_exec_creds(bprm);
48602
48603+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48604+ current->mm->pax_flags = 0UL;
48605+#endif
48606+
48607+#ifdef CONFIG_PAX_PAGEEXEC
48608+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
48609+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
48610+
48611+#ifdef CONFIG_PAX_EMUTRAMP
48612+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
48613+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
48614+#endif
48615+
48616+#ifdef CONFIG_PAX_MPROTECT
48617+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
48618+ current->mm->pax_flags |= MF_PAX_MPROTECT;
48619+#endif
48620+
48621+ }
48622+#endif
48623+
48624 if (N_MAGIC(ex) == OMAGIC) {
48625 unsigned long text_addr, map_size;
48626 loff_t pos;
48627@@ -324,7 +352,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
48628 }
48629
48630 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
48631- PROT_READ | PROT_WRITE | PROT_EXEC,
48632+ PROT_READ | PROT_WRITE,
48633 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
48634 fd_offset + ex.a_text);
48635 if (error != N_DATADDR(ex)) {
48636diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
48637index f8a0b0e..8186af0 100644
48638--- a/fs/binfmt_elf.c
48639+++ b/fs/binfmt_elf.c
48640@@ -34,6 +34,7 @@
48641 #include <linux/utsname.h>
48642 #include <linux/coredump.h>
48643 #include <linux/sched.h>
48644+#include <linux/xattr.h>
48645 #include <asm/uaccess.h>
48646 #include <asm/param.h>
48647 #include <asm/page.h>
48648@@ -60,6 +61,10 @@ static int elf_core_dump(struct coredump_params *cprm);
48649 #define elf_core_dump NULL
48650 #endif
48651
48652+#ifdef CONFIG_PAX_MPROTECT
48653+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
48654+#endif
48655+
48656 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
48657 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
48658 #else
48659@@ -79,6 +84,11 @@ static struct linux_binfmt elf_format = {
48660 .load_binary = load_elf_binary,
48661 .load_shlib = load_elf_library,
48662 .core_dump = elf_core_dump,
48663+
48664+#ifdef CONFIG_PAX_MPROTECT
48665+ .handle_mprotect= elf_handle_mprotect,
48666+#endif
48667+
48668 .min_coredump = ELF_EXEC_PAGESIZE,
48669 };
48670
48671@@ -86,6 +96,8 @@ static struct linux_binfmt elf_format = {
48672
48673 static int set_brk(unsigned long start, unsigned long end)
48674 {
48675+ unsigned long e = end;
48676+
48677 start = ELF_PAGEALIGN(start);
48678 end = ELF_PAGEALIGN(end);
48679 if (end > start) {
48680@@ -94,7 +106,7 @@ static int set_brk(unsigned long start, unsigned long end)
48681 if (BAD_ADDR(addr))
48682 return addr;
48683 }
48684- current->mm->start_brk = current->mm->brk = end;
48685+ current->mm->start_brk = current->mm->brk = e;
48686 return 0;
48687 }
48688
48689@@ -155,12 +167,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48690 elf_addr_t __user *u_rand_bytes;
48691 const char *k_platform = ELF_PLATFORM;
48692 const char *k_base_platform = ELF_BASE_PLATFORM;
48693- unsigned char k_rand_bytes[16];
48694+ u32 k_rand_bytes[4];
48695 int items;
48696 elf_addr_t *elf_info;
48697 int ei_index = 0;
48698 const struct cred *cred = current_cred();
48699 struct vm_area_struct *vma;
48700+ unsigned long saved_auxv[AT_VECTOR_SIZE];
48701
48702 /*
48703 * In some cases (e.g. Hyper-Threading), we want to avoid L1
48704@@ -202,8 +215,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48705 * Generate 16 random bytes for userspace PRNG seeding.
48706 */
48707 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
48708- u_rand_bytes = (elf_addr_t __user *)
48709- STACK_ALLOC(p, sizeof(k_rand_bytes));
48710+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
48711+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
48712+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
48713+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
48714+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
48715+ u_rand_bytes = (elf_addr_t __user *) p;
48716 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
48717 return -EFAULT;
48718
48719@@ -318,9 +335,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48720 return -EFAULT;
48721 current->mm->env_end = p;
48722
48723+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
48724+
48725 /* Put the elf_info on the stack in the right place. */
48726 sp = (elf_addr_t __user *)envp + 1;
48727- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
48728+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
48729 return -EFAULT;
48730 return 0;
48731 }
48732@@ -388,15 +407,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
48733 an ELF header */
48734
48735 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48736- struct file *interpreter, unsigned long *interp_map_addr,
48737- unsigned long no_base)
48738+ struct file *interpreter, unsigned long no_base)
48739 {
48740 struct elf_phdr *elf_phdata;
48741 struct elf_phdr *eppnt;
48742- unsigned long load_addr = 0;
48743+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48744 int load_addr_set = 0;
48745 unsigned long last_bss = 0, elf_bss = 0;
48746- unsigned long error = ~0UL;
48747+ unsigned long error = -EINVAL;
48748 unsigned long total_size;
48749 int retval, i, size;
48750
48751@@ -442,6 +460,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48752 goto out_close;
48753 }
48754
48755+#ifdef CONFIG_PAX_SEGMEXEC
48756+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48757+ pax_task_size = SEGMEXEC_TASK_SIZE;
48758+#endif
48759+
48760 eppnt = elf_phdata;
48761 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48762 if (eppnt->p_type == PT_LOAD) {
48763@@ -465,8 +488,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48764 map_addr = elf_map(interpreter, load_addr + vaddr,
48765 eppnt, elf_prot, elf_type, total_size);
48766 total_size = 0;
48767- if (!*interp_map_addr)
48768- *interp_map_addr = map_addr;
48769 error = map_addr;
48770 if (BAD_ADDR(map_addr))
48771 goto out_close;
48772@@ -485,8 +506,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48773 k = load_addr + eppnt->p_vaddr;
48774 if (BAD_ADDR(k) ||
48775 eppnt->p_filesz > eppnt->p_memsz ||
48776- eppnt->p_memsz > TASK_SIZE ||
48777- TASK_SIZE - eppnt->p_memsz < k) {
48778+ eppnt->p_memsz > pax_task_size ||
48779+ pax_task_size - eppnt->p_memsz < k) {
48780 error = -ENOMEM;
48781 goto out_close;
48782 }
48783@@ -538,6 +559,315 @@ out:
48784 return error;
48785 }
48786
48787+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48788+#ifdef CONFIG_PAX_SOFTMODE
48789+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48790+{
48791+ unsigned long pax_flags = 0UL;
48792+
48793+#ifdef CONFIG_PAX_PAGEEXEC
48794+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48795+ pax_flags |= MF_PAX_PAGEEXEC;
48796+#endif
48797+
48798+#ifdef CONFIG_PAX_SEGMEXEC
48799+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48800+ pax_flags |= MF_PAX_SEGMEXEC;
48801+#endif
48802+
48803+#ifdef CONFIG_PAX_EMUTRAMP
48804+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48805+ pax_flags |= MF_PAX_EMUTRAMP;
48806+#endif
48807+
48808+#ifdef CONFIG_PAX_MPROTECT
48809+ if (elf_phdata->p_flags & PF_MPROTECT)
48810+ pax_flags |= MF_PAX_MPROTECT;
48811+#endif
48812+
48813+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48814+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48815+ pax_flags |= MF_PAX_RANDMMAP;
48816+#endif
48817+
48818+ return pax_flags;
48819+}
48820+#endif
48821+
48822+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48823+{
48824+ unsigned long pax_flags = 0UL;
48825+
48826+#ifdef CONFIG_PAX_PAGEEXEC
48827+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48828+ pax_flags |= MF_PAX_PAGEEXEC;
48829+#endif
48830+
48831+#ifdef CONFIG_PAX_SEGMEXEC
48832+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48833+ pax_flags |= MF_PAX_SEGMEXEC;
48834+#endif
48835+
48836+#ifdef CONFIG_PAX_EMUTRAMP
48837+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48838+ pax_flags |= MF_PAX_EMUTRAMP;
48839+#endif
48840+
48841+#ifdef CONFIG_PAX_MPROTECT
48842+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48843+ pax_flags |= MF_PAX_MPROTECT;
48844+#endif
48845+
48846+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48847+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48848+ pax_flags |= MF_PAX_RANDMMAP;
48849+#endif
48850+
48851+ return pax_flags;
48852+}
48853+#endif
48854+
48855+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48856+#ifdef CONFIG_PAX_SOFTMODE
48857+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48858+{
48859+ unsigned long pax_flags = 0UL;
48860+
48861+#ifdef CONFIG_PAX_PAGEEXEC
48862+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48863+ pax_flags |= MF_PAX_PAGEEXEC;
48864+#endif
48865+
48866+#ifdef CONFIG_PAX_SEGMEXEC
48867+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48868+ pax_flags |= MF_PAX_SEGMEXEC;
48869+#endif
48870+
48871+#ifdef CONFIG_PAX_EMUTRAMP
48872+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48873+ pax_flags |= MF_PAX_EMUTRAMP;
48874+#endif
48875+
48876+#ifdef CONFIG_PAX_MPROTECT
48877+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48878+ pax_flags |= MF_PAX_MPROTECT;
48879+#endif
48880+
48881+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48882+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48883+ pax_flags |= MF_PAX_RANDMMAP;
48884+#endif
48885+
48886+ return pax_flags;
48887+}
48888+#endif
48889+
48890+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48891+{
48892+ unsigned long pax_flags = 0UL;
48893+
48894+#ifdef CONFIG_PAX_PAGEEXEC
48895+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48896+ pax_flags |= MF_PAX_PAGEEXEC;
48897+#endif
48898+
48899+#ifdef CONFIG_PAX_SEGMEXEC
48900+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48901+ pax_flags |= MF_PAX_SEGMEXEC;
48902+#endif
48903+
48904+#ifdef CONFIG_PAX_EMUTRAMP
48905+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48906+ pax_flags |= MF_PAX_EMUTRAMP;
48907+#endif
48908+
48909+#ifdef CONFIG_PAX_MPROTECT
48910+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48911+ pax_flags |= MF_PAX_MPROTECT;
48912+#endif
48913+
48914+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48915+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48916+ pax_flags |= MF_PAX_RANDMMAP;
48917+#endif
48918+
48919+ return pax_flags;
48920+}
48921+#endif
48922+
48923+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48924+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48925+{
48926+ unsigned long pax_flags = 0UL;
48927+
48928+#ifdef CONFIG_PAX_EI_PAX
48929+
48930+#ifdef CONFIG_PAX_PAGEEXEC
48931+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48932+ pax_flags |= MF_PAX_PAGEEXEC;
48933+#endif
48934+
48935+#ifdef CONFIG_PAX_SEGMEXEC
48936+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48937+ pax_flags |= MF_PAX_SEGMEXEC;
48938+#endif
48939+
48940+#ifdef CONFIG_PAX_EMUTRAMP
48941+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48942+ pax_flags |= MF_PAX_EMUTRAMP;
48943+#endif
48944+
48945+#ifdef CONFIG_PAX_MPROTECT
48946+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48947+ pax_flags |= MF_PAX_MPROTECT;
48948+#endif
48949+
48950+#ifdef CONFIG_PAX_ASLR
48951+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48952+ pax_flags |= MF_PAX_RANDMMAP;
48953+#endif
48954+
48955+#else
48956+
48957+#ifdef CONFIG_PAX_PAGEEXEC
48958+ pax_flags |= MF_PAX_PAGEEXEC;
48959+#endif
48960+
48961+#ifdef CONFIG_PAX_SEGMEXEC
48962+ pax_flags |= MF_PAX_SEGMEXEC;
48963+#endif
48964+
48965+#ifdef CONFIG_PAX_MPROTECT
48966+ pax_flags |= MF_PAX_MPROTECT;
48967+#endif
48968+
48969+#ifdef CONFIG_PAX_RANDMMAP
48970+ if (randomize_va_space)
48971+ pax_flags |= MF_PAX_RANDMMAP;
48972+#endif
48973+
48974+#endif
48975+
48976+ return pax_flags;
48977+}
48978+
48979+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48980+{
48981+
48982+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48983+ unsigned long i;
48984+
48985+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48986+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48987+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48988+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48989+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48990+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48991+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48992+ return ~0UL;
48993+
48994+#ifdef CONFIG_PAX_SOFTMODE
48995+ if (pax_softmode)
48996+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48997+ else
48998+#endif
48999+
49000+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
49001+ break;
49002+ }
49003+#endif
49004+
49005+ return ~0UL;
49006+}
49007+
49008+static unsigned long pax_parse_xattr_pax(struct file * const file)
49009+{
49010+
49011+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
49012+ ssize_t xattr_size, i;
49013+ unsigned char xattr_value[sizeof("pemrs") - 1];
49014+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
49015+
49016+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
49017+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
49018+ return ~0UL;
49019+
49020+ for (i = 0; i < xattr_size; i++)
49021+ switch (xattr_value[i]) {
49022+ default:
49023+ return ~0UL;
49024+
49025+#define parse_flag(option1, option2, flag) \
49026+ case option1: \
49027+ if (pax_flags_hardmode & MF_PAX_##flag) \
49028+ return ~0UL; \
49029+ pax_flags_hardmode |= MF_PAX_##flag; \
49030+ break; \
49031+ case option2: \
49032+ if (pax_flags_softmode & MF_PAX_##flag) \
49033+ return ~0UL; \
49034+ pax_flags_softmode |= MF_PAX_##flag; \
49035+ break;
49036+
49037+ parse_flag('p', 'P', PAGEEXEC);
49038+ parse_flag('e', 'E', EMUTRAMP);
49039+ parse_flag('m', 'M', MPROTECT);
49040+ parse_flag('r', 'R', RANDMMAP);
49041+ parse_flag('s', 'S', SEGMEXEC);
49042+
49043+#undef parse_flag
49044+ }
49045+
49046+ if (pax_flags_hardmode & pax_flags_softmode)
49047+ return ~0UL;
49048+
49049+#ifdef CONFIG_PAX_SOFTMODE
49050+ if (pax_softmode)
49051+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
49052+ else
49053+#endif
49054+
49055+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
49056+#else
49057+ return ~0UL;
49058+#endif
49059+
49060+}
49061+
49062+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
49063+{
49064+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
49065+
49066+ pax_flags = pax_parse_ei_pax(elf_ex);
49067+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
49068+ xattr_pax_flags = pax_parse_xattr_pax(file);
49069+
49070+ if (pt_pax_flags == ~0UL)
49071+ pt_pax_flags = xattr_pax_flags;
49072+ else if (xattr_pax_flags == ~0UL)
49073+ xattr_pax_flags = pt_pax_flags;
49074+ if (pt_pax_flags != xattr_pax_flags)
49075+ return -EINVAL;
49076+ if (pt_pax_flags != ~0UL)
49077+ pax_flags = pt_pax_flags;
49078+
49079+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
49080+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49081+ if ((__supported_pte_mask & _PAGE_NX))
49082+ pax_flags &= ~MF_PAX_SEGMEXEC;
49083+ else
49084+ pax_flags &= ~MF_PAX_PAGEEXEC;
49085+ }
49086+#endif
49087+
49088+ if (0 > pax_check_flags(&pax_flags))
49089+ return -EINVAL;
49090+
49091+ current->mm->pax_flags = pax_flags;
49092+ return 0;
49093+}
49094+#endif
49095+
49096 /*
49097 * These are the functions used to load ELF style executables and shared
49098 * libraries. There is no binary dependent code anywhere else.
49099@@ -554,6 +884,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
49100 {
49101 unsigned int random_variable = 0;
49102
49103+#ifdef CONFIG_PAX_RANDUSTACK
49104+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
49105+ return stack_top - current->mm->delta_stack;
49106+#endif
49107+
49108 if ((current->flags & PF_RANDOMIZE) &&
49109 !(current->personality & ADDR_NO_RANDOMIZE)) {
49110 random_variable = get_random_int() & STACK_RND_MASK;
49111@@ -572,7 +907,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
49112 unsigned long load_addr = 0, load_bias = 0;
49113 int load_addr_set = 0;
49114 char * elf_interpreter = NULL;
49115- unsigned long error;
49116+ unsigned long error = 0;
49117 struct elf_phdr *elf_ppnt, *elf_phdata;
49118 unsigned long elf_bss, elf_brk;
49119 int retval, i;
49120@@ -582,12 +917,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
49121 unsigned long start_code, end_code, start_data, end_data;
49122 unsigned long reloc_func_desc __maybe_unused = 0;
49123 int executable_stack = EXSTACK_DEFAULT;
49124- unsigned long def_flags = 0;
49125 struct pt_regs *regs = current_pt_regs();
49126 struct {
49127 struct elfhdr elf_ex;
49128 struct elfhdr interp_elf_ex;
49129 } *loc;
49130+ unsigned long pax_task_size = TASK_SIZE;
49131
49132 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
49133 if (!loc) {
49134@@ -723,11 +1058,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
49135 goto out_free_dentry;
49136
49137 /* OK, This is the point of no return */
49138- current->mm->def_flags = def_flags;
49139+
49140+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49141+ current->mm->pax_flags = 0UL;
49142+#endif
49143+
49144+#ifdef CONFIG_PAX_DLRESOLVE
49145+ current->mm->call_dl_resolve = 0UL;
49146+#endif
49147+
49148+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
49149+ current->mm->call_syscall = 0UL;
49150+#endif
49151+
49152+#ifdef CONFIG_PAX_ASLR
49153+ current->mm->delta_mmap = 0UL;
49154+ current->mm->delta_stack = 0UL;
49155+#endif
49156+
49157+ current->mm->def_flags = 0;
49158+
49159+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49160+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
49161+ send_sig(SIGKILL, current, 0);
49162+ goto out_free_dentry;
49163+ }
49164+#endif
49165+
49166+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49167+ pax_set_initial_flags(bprm);
49168+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
49169+ if (pax_set_initial_flags_func)
49170+ (pax_set_initial_flags_func)(bprm);
49171+#endif
49172+
49173+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49174+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
49175+ current->mm->context.user_cs_limit = PAGE_SIZE;
49176+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
49177+ }
49178+#endif
49179+
49180+#ifdef CONFIG_PAX_SEGMEXEC
49181+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
49182+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
49183+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
49184+ pax_task_size = SEGMEXEC_TASK_SIZE;
49185+ current->mm->def_flags |= VM_NOHUGEPAGE;
49186+ }
49187+#endif
49188+
49189+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
49190+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49191+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
49192+ put_cpu();
49193+ }
49194+#endif
49195
49196 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
49197 may depend on the personality. */
49198 SET_PERSONALITY(loc->elf_ex);
49199+
49200+#ifdef CONFIG_PAX_ASLR
49201+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49202+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
49203+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
49204+ }
49205+#endif
49206+
49207+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49208+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49209+ executable_stack = EXSTACK_DISABLE_X;
49210+ current->personality &= ~READ_IMPLIES_EXEC;
49211+ } else
49212+#endif
49213+
49214 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
49215 current->personality |= READ_IMPLIES_EXEC;
49216
49217@@ -819,6 +1224,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
49218 #else
49219 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
49220 #endif
49221+
49222+#ifdef CONFIG_PAX_RANDMMAP
49223+ /* PaX: randomize base address at the default exe base if requested */
49224+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
49225+#ifdef CONFIG_SPARC64
49226+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
49227+#else
49228+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
49229+#endif
49230+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
49231+ elf_flags |= MAP_FIXED;
49232+ }
49233+#endif
49234+
49235 }
49236
49237 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
49238@@ -851,9 +1270,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
49239 * allowed task size. Note that p_filesz must always be
49240 * <= p_memsz so it is only necessary to check p_memsz.
49241 */
49242- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49243- elf_ppnt->p_memsz > TASK_SIZE ||
49244- TASK_SIZE - elf_ppnt->p_memsz < k) {
49245+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49246+ elf_ppnt->p_memsz > pax_task_size ||
49247+ pax_task_size - elf_ppnt->p_memsz < k) {
49248 /* set_brk can never work. Avoid overflows. */
49249 send_sig(SIGKILL, current, 0);
49250 retval = -EINVAL;
49251@@ -892,17 +1311,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
49252 goto out_free_dentry;
49253 }
49254 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
49255- send_sig(SIGSEGV, current, 0);
49256- retval = -EFAULT; /* Nobody gets to see this, but.. */
49257- goto out_free_dentry;
49258+ /*
49259+ * This bss-zeroing can fail if the ELF
49260+ * file specifies odd protections. So
49261+ * we don't check the return value
49262+ */
49263 }
49264
49265+#ifdef CONFIG_PAX_RANDMMAP
49266+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49267+ unsigned long start, size, flags;
49268+ vm_flags_t vm_flags;
49269+
49270+ start = ELF_PAGEALIGN(elf_brk);
49271+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
49272+ flags = MAP_FIXED | MAP_PRIVATE;
49273+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
49274+
49275+ down_write(&current->mm->mmap_sem);
49276+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
49277+ retval = -ENOMEM;
49278+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
49279+// if (current->personality & ADDR_NO_RANDOMIZE)
49280+// vm_flags |= VM_READ | VM_MAYREAD;
49281+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
49282+ retval = IS_ERR_VALUE(start) ? start : 0;
49283+ }
49284+ up_write(&current->mm->mmap_sem);
49285+ if (retval == 0)
49286+ retval = set_brk(start + size, start + size + PAGE_SIZE);
49287+ if (retval < 0) {
49288+ send_sig(SIGKILL, current, 0);
49289+ goto out_free_dentry;
49290+ }
49291+ }
49292+#endif
49293+
49294 if (elf_interpreter) {
49295- unsigned long interp_map_addr = 0;
49296-
49297 elf_entry = load_elf_interp(&loc->interp_elf_ex,
49298 interpreter,
49299- &interp_map_addr,
49300 load_bias);
49301 if (!IS_ERR((void *)elf_entry)) {
49302 /*
49303@@ -1124,7 +1571,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
49304 * Decide what to dump of a segment, part, all or none.
49305 */
49306 static unsigned long vma_dump_size(struct vm_area_struct *vma,
49307- unsigned long mm_flags)
49308+ unsigned long mm_flags, long signr)
49309 {
49310 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
49311
49312@@ -1162,7 +1609,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
49313 if (vma->vm_file == NULL)
49314 return 0;
49315
49316- if (FILTER(MAPPED_PRIVATE))
49317+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
49318 goto whole;
49319
49320 /*
49321@@ -1387,9 +1834,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
49322 {
49323 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
49324 int i = 0;
49325- do
49326+ do {
49327 i += 2;
49328- while (auxv[i - 2] != AT_NULL);
49329+ } while (auxv[i - 2] != AT_NULL);
49330 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
49331 }
49332
49333@@ -1398,7 +1845,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
49334 {
49335 mm_segment_t old_fs = get_fs();
49336 set_fs(KERNEL_DS);
49337- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
49338+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
49339 set_fs(old_fs);
49340 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
49341 }
49342@@ -2019,14 +2466,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
49343 }
49344
49345 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
49346- unsigned long mm_flags)
49347+ struct coredump_params *cprm)
49348 {
49349 struct vm_area_struct *vma;
49350 size_t size = 0;
49351
49352 for (vma = first_vma(current, gate_vma); vma != NULL;
49353 vma = next_vma(vma, gate_vma))
49354- size += vma_dump_size(vma, mm_flags);
49355+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49356 return size;
49357 }
49358
49359@@ -2119,7 +2566,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49360
49361 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
49362
49363- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
49364+ offset += elf_core_vma_data_size(gate_vma, cprm);
49365 offset += elf_core_extra_data_size();
49366 e_shoff = offset;
49367
49368@@ -2133,10 +2580,12 @@ static int elf_core_dump(struct coredump_params *cprm)
49369 offset = dataoff;
49370
49371 size += sizeof(*elf);
49372+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49373 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
49374 goto end_coredump;
49375
49376 size += sizeof(*phdr4note);
49377+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49378 if (size > cprm->limit
49379 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
49380 goto end_coredump;
49381@@ -2150,7 +2599,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49382 phdr.p_offset = offset;
49383 phdr.p_vaddr = vma->vm_start;
49384 phdr.p_paddr = 0;
49385- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
49386+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49387 phdr.p_memsz = vma->vm_end - vma->vm_start;
49388 offset += phdr.p_filesz;
49389 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
49390@@ -2161,6 +2610,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49391 phdr.p_align = ELF_EXEC_PAGESIZE;
49392
49393 size += sizeof(phdr);
49394+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49395 if (size > cprm->limit
49396 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
49397 goto end_coredump;
49398@@ -2185,7 +2635,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49399 unsigned long addr;
49400 unsigned long end;
49401
49402- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
49403+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49404
49405 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
49406 struct page *page;
49407@@ -2194,6 +2644,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49408 page = get_dump_page(addr);
49409 if (page) {
49410 void *kaddr = kmap(page);
49411+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
49412 stop = ((size += PAGE_SIZE) > cprm->limit) ||
49413 !dump_write(cprm->file, kaddr,
49414 PAGE_SIZE);
49415@@ -2211,6 +2662,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49416
49417 if (e_phnum == PN_XNUM) {
49418 size += sizeof(*shdr4extnum);
49419+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49420 if (size > cprm->limit
49421 || !dump_write(cprm->file, shdr4extnum,
49422 sizeof(*shdr4extnum)))
49423@@ -2231,6 +2683,97 @@ out:
49424
49425 #endif /* CONFIG_ELF_CORE */
49426
49427+#ifdef CONFIG_PAX_MPROTECT
49428+/* PaX: non-PIC ELF libraries need relocations on their executable segments
49429+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
49430+ * we'll remove VM_MAYWRITE for good on RELRO segments.
49431+ *
49432+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
49433+ * basis because we want to allow the common case and not the special ones.
49434+ */
49435+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
49436+{
49437+ struct elfhdr elf_h;
49438+ struct elf_phdr elf_p;
49439+ unsigned long i;
49440+ unsigned long oldflags;
49441+ bool is_textrel_rw, is_textrel_rx, is_relro;
49442+
49443+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
49444+ return;
49445+
49446+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
49447+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
49448+
49449+#ifdef CONFIG_PAX_ELFRELOCS
49450+ /* possible TEXTREL */
49451+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
49452+ 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);
49453+#else
49454+ is_textrel_rw = false;
49455+ is_textrel_rx = false;
49456+#endif
49457+
49458+ /* possible RELRO */
49459+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
49460+
49461+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
49462+ return;
49463+
49464+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49465+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49466+
49467+#ifdef CONFIG_PAX_ETEXECRELOCS
49468+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49469+#else
49470+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
49471+#endif
49472+
49473+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49474+ !elf_check_arch(&elf_h) ||
49475+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49476+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49477+ return;
49478+
49479+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49480+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49481+ return;
49482+ switch (elf_p.p_type) {
49483+ case PT_DYNAMIC:
49484+ if (!is_textrel_rw && !is_textrel_rx)
49485+ continue;
49486+ i = 0UL;
49487+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
49488+ elf_dyn dyn;
49489+
49490+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
49491+ return;
49492+ if (dyn.d_tag == DT_NULL)
49493+ return;
49494+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
49495+ gr_log_textrel(vma);
49496+ if (is_textrel_rw)
49497+ vma->vm_flags |= VM_MAYWRITE;
49498+ else
49499+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
49500+ vma->vm_flags &= ~VM_MAYWRITE;
49501+ return;
49502+ }
49503+ i++;
49504+ }
49505+ return;
49506+
49507+ case PT_GNU_RELRO:
49508+ if (!is_relro)
49509+ continue;
49510+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
49511+ vma->vm_flags &= ~VM_MAYWRITE;
49512+ return;
49513+ }
49514+ }
49515+}
49516+#endif
49517+
49518 static int __init init_elf_binfmt(void)
49519 {
49520 register_binfmt(&elf_format);
49521diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
49522index d50bbe5..af3b649 100644
49523--- a/fs/binfmt_flat.c
49524+++ b/fs/binfmt_flat.c
49525@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
49526 realdatastart = (unsigned long) -ENOMEM;
49527 printk("Unable to allocate RAM for process data, errno %d\n",
49528 (int)-realdatastart);
49529+ down_write(&current->mm->mmap_sem);
49530 vm_munmap(textpos, text_len);
49531+ up_write(&current->mm->mmap_sem);
49532 ret = realdatastart;
49533 goto err;
49534 }
49535@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49536 }
49537 if (IS_ERR_VALUE(result)) {
49538 printk("Unable to read data+bss, errno %d\n", (int)-result);
49539+ down_write(&current->mm->mmap_sem);
49540 vm_munmap(textpos, text_len);
49541 vm_munmap(realdatastart, len);
49542+ up_write(&current->mm->mmap_sem);
49543 ret = result;
49544 goto err;
49545 }
49546@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49547 }
49548 if (IS_ERR_VALUE(result)) {
49549 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
49550+ down_write(&current->mm->mmap_sem);
49551 vm_munmap(textpos, text_len + data_len + extra +
49552 MAX_SHARED_LIBS * sizeof(unsigned long));
49553+ up_write(&current->mm->mmap_sem);
49554 ret = result;
49555 goto err;
49556 }
49557diff --git a/fs/bio.c b/fs/bio.c
49558index 94bbc04..6fe78a4 100644
49559--- a/fs/bio.c
49560+++ b/fs/bio.c
49561@@ -1096,7 +1096,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
49562 /*
49563 * Overflow, abort
49564 */
49565- if (end < start)
49566+ if (end < start || end - start > INT_MAX - nr_pages)
49567 return ERR_PTR(-EINVAL);
49568
49569 nr_pages += end - start;
49570@@ -1230,7 +1230,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
49571 /*
49572 * Overflow, abort
49573 */
49574- if (end < start)
49575+ if (end < start || end - start > INT_MAX - nr_pages)
49576 return ERR_PTR(-EINVAL);
49577
49578 nr_pages += end - start;
49579@@ -1492,7 +1492,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
49580 const int read = bio_data_dir(bio) == READ;
49581 struct bio_map_data *bmd = bio->bi_private;
49582 int i;
49583- char *p = bmd->sgvecs[0].iov_base;
49584+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
49585
49586 bio_for_each_segment_all(bvec, bio, i) {
49587 char *addr = page_address(bvec->bv_page);
49588diff --git a/fs/block_dev.c b/fs/block_dev.c
49589index 2091db8..81dafe9 100644
49590--- a/fs/block_dev.c
49591+++ b/fs/block_dev.c
49592@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
49593 else if (bdev->bd_contains == bdev)
49594 return true; /* is a whole device which isn't held */
49595
49596- else if (whole->bd_holder == bd_may_claim)
49597+ else if (whole->bd_holder == (void *)bd_may_claim)
49598 return true; /* is a partition of a device that is being partitioned */
49599 else if (whole->bd_holder != NULL)
49600 return false; /* is a partition of a held device */
49601diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
49602index 7fb054b..ad36c67 100644
49603--- a/fs/btrfs/ctree.c
49604+++ b/fs/btrfs/ctree.c
49605@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
49606 free_extent_buffer(buf);
49607 add_root_to_dirty_list(root);
49608 } else {
49609- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
49610- parent_start = parent->start;
49611- else
49612+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
49613+ if (parent)
49614+ parent_start = parent->start;
49615+ else
49616+ parent_start = 0;
49617+ } else
49618 parent_start = 0;
49619
49620 WARN_ON(trans->transid != btrfs_header_generation(parent));
49621diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
49622index 0f81d67..0ad55fe 100644
49623--- a/fs/btrfs/ioctl.c
49624+++ b/fs/btrfs/ioctl.c
49625@@ -3084,9 +3084,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49626 for (i = 0; i < num_types; i++) {
49627 struct btrfs_space_info *tmp;
49628
49629+ /* Don't copy in more than we allocated */
49630 if (!slot_count)
49631 break;
49632
49633+ slot_count--;
49634+
49635 info = NULL;
49636 rcu_read_lock();
49637 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
49638@@ -3108,10 +3111,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49639 memcpy(dest, &space, sizeof(space));
49640 dest++;
49641 space_args.total_spaces++;
49642- slot_count--;
49643 }
49644- if (!slot_count)
49645- break;
49646 }
49647 up_read(&info->groups_sem);
49648 }
49649diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
49650index f0857e0..e7023c5 100644
49651--- a/fs/btrfs/super.c
49652+++ b/fs/btrfs/super.c
49653@@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
49654 function, line, errstr);
49655 return;
49656 }
49657- ACCESS_ONCE(trans->transaction->aborted) = errno;
49658+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
49659 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
49660 }
49661 /*
49662diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
49663index 622f469..e8d2d55 100644
49664--- a/fs/cachefiles/bind.c
49665+++ b/fs/cachefiles/bind.c
49666@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
49667 args);
49668
49669 /* start by checking things over */
49670- ASSERT(cache->fstop_percent >= 0 &&
49671- cache->fstop_percent < cache->fcull_percent &&
49672+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
49673 cache->fcull_percent < cache->frun_percent &&
49674 cache->frun_percent < 100);
49675
49676- ASSERT(cache->bstop_percent >= 0 &&
49677- cache->bstop_percent < cache->bcull_percent &&
49678+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
49679 cache->bcull_percent < cache->brun_percent &&
49680 cache->brun_percent < 100);
49681
49682diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
49683index 0a1467b..6a53245 100644
49684--- a/fs/cachefiles/daemon.c
49685+++ b/fs/cachefiles/daemon.c
49686@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
49687 if (n > buflen)
49688 return -EMSGSIZE;
49689
49690- if (copy_to_user(_buffer, buffer, n) != 0)
49691+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
49692 return -EFAULT;
49693
49694 return n;
49695@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
49696 if (test_bit(CACHEFILES_DEAD, &cache->flags))
49697 return -EIO;
49698
49699- if (datalen < 0 || datalen > PAGE_SIZE - 1)
49700+ if (datalen > PAGE_SIZE - 1)
49701 return -EOPNOTSUPP;
49702
49703 /* drag the command string into the kernel so we can parse it */
49704@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
49705 if (args[0] != '%' || args[1] != '\0')
49706 return -EINVAL;
49707
49708- if (fstop < 0 || fstop >= cache->fcull_percent)
49709+ if (fstop >= cache->fcull_percent)
49710 return cachefiles_daemon_range_error(cache, args);
49711
49712 cache->fstop_percent = fstop;
49713@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49714 if (args[0] != '%' || args[1] != '\0')
49715 return -EINVAL;
49716
49717- if (bstop < 0 || bstop >= cache->bcull_percent)
49718+ if (bstop >= cache->bcull_percent)
49719 return cachefiles_daemon_range_error(cache, args);
49720
49721 cache->bstop_percent = bstop;
49722diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49723index 4938251..7e01445 100644
49724--- a/fs/cachefiles/internal.h
49725+++ b/fs/cachefiles/internal.h
49726@@ -59,7 +59,7 @@ struct cachefiles_cache {
49727 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49728 struct rb_root active_nodes; /* active nodes (can't be culled) */
49729 rwlock_t active_lock; /* lock for active_nodes */
49730- atomic_t gravecounter; /* graveyard uniquifier */
49731+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49732 unsigned frun_percent; /* when to stop culling (% files) */
49733 unsigned fcull_percent; /* when to start culling (% files) */
49734 unsigned fstop_percent; /* when to stop allocating (% files) */
49735@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49736 * proc.c
49737 */
49738 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49739-extern atomic_t cachefiles_lookup_histogram[HZ];
49740-extern atomic_t cachefiles_mkdir_histogram[HZ];
49741-extern atomic_t cachefiles_create_histogram[HZ];
49742+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49743+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49744+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49745
49746 extern int __init cachefiles_proc_init(void);
49747 extern void cachefiles_proc_cleanup(void);
49748 static inline
49749-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49750+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49751 {
49752 unsigned long jif = jiffies - start_jif;
49753 if (jif >= HZ)
49754 jif = HZ - 1;
49755- atomic_inc(&histogram[jif]);
49756+ atomic_inc_unchecked(&histogram[jif]);
49757 }
49758
49759 #else
49760diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49761index 8c01c5fc..15f982e 100644
49762--- a/fs/cachefiles/namei.c
49763+++ b/fs/cachefiles/namei.c
49764@@ -317,7 +317,7 @@ try_again:
49765 /* first step is to make up a grave dentry in the graveyard */
49766 sprintf(nbuffer, "%08x%08x",
49767 (uint32_t) get_seconds(),
49768- (uint32_t) atomic_inc_return(&cache->gravecounter));
49769+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49770
49771 /* do the multiway lock magic */
49772 trap = lock_rename(cache->graveyard, dir);
49773diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49774index eccd339..4c1d995 100644
49775--- a/fs/cachefiles/proc.c
49776+++ b/fs/cachefiles/proc.c
49777@@ -14,9 +14,9 @@
49778 #include <linux/seq_file.h>
49779 #include "internal.h"
49780
49781-atomic_t cachefiles_lookup_histogram[HZ];
49782-atomic_t cachefiles_mkdir_histogram[HZ];
49783-atomic_t cachefiles_create_histogram[HZ];
49784+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49785+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49786+atomic_unchecked_t cachefiles_create_histogram[HZ];
49787
49788 /*
49789 * display the latency histogram
49790@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49791 return 0;
49792 default:
49793 index = (unsigned long) v - 3;
49794- x = atomic_read(&cachefiles_lookup_histogram[index]);
49795- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49796- z = atomic_read(&cachefiles_create_histogram[index]);
49797+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49798+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49799+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49800 if (x == 0 && y == 0 && z == 0)
49801 return 0;
49802
49803diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49804index 317f9ee..3d24511 100644
49805--- a/fs/cachefiles/rdwr.c
49806+++ b/fs/cachefiles/rdwr.c
49807@@ -966,7 +966,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49808 old_fs = get_fs();
49809 set_fs(KERNEL_DS);
49810 ret = file->f_op->write(
49811- file, (const void __user *) data, len, &pos);
49812+ file, (const void __force_user *) data, len, &pos);
49813 set_fs(old_fs);
49814 kunmap(page);
49815 file_end_write(file);
49816diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49817index f02d82b..2632cf86 100644
49818--- a/fs/ceph/dir.c
49819+++ b/fs/ceph/dir.c
49820@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49821 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49822 struct ceph_mds_client *mdsc = fsc->mdsc;
49823 unsigned frag = fpos_frag(filp->f_pos);
49824- int off = fpos_off(filp->f_pos);
49825+ unsigned int off = fpos_off(filp->f_pos);
49826 int err;
49827 u32 ftype;
49828 struct ceph_mds_reply_info_parsed *rinfo;
49829diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49830index d597483..747901b 100644
49831--- a/fs/cifs/cifs_debug.c
49832+++ b/fs/cifs/cifs_debug.c
49833@@ -284,8 +284,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49834
49835 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49836 #ifdef CONFIG_CIFS_STATS2
49837- atomic_set(&totBufAllocCount, 0);
49838- atomic_set(&totSmBufAllocCount, 0);
49839+ atomic_set_unchecked(&totBufAllocCount, 0);
49840+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49841 #endif /* CONFIG_CIFS_STATS2 */
49842 spin_lock(&cifs_tcp_ses_lock);
49843 list_for_each(tmp1, &cifs_tcp_ses_list) {
49844@@ -298,7 +298,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49845 tcon = list_entry(tmp3,
49846 struct cifs_tcon,
49847 tcon_list);
49848- atomic_set(&tcon->num_smbs_sent, 0);
49849+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49850 if (server->ops->clear_stats)
49851 server->ops->clear_stats(tcon);
49852 }
49853@@ -330,8 +330,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49854 smBufAllocCount.counter, cifs_min_small);
49855 #ifdef CONFIG_CIFS_STATS2
49856 seq_printf(m, "Total Large %d Small %d Allocations\n",
49857- atomic_read(&totBufAllocCount),
49858- atomic_read(&totSmBufAllocCount));
49859+ atomic_read_unchecked(&totBufAllocCount),
49860+ atomic_read_unchecked(&totSmBufAllocCount));
49861 #endif /* CONFIG_CIFS_STATS2 */
49862
49863 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49864@@ -360,7 +360,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49865 if (tcon->need_reconnect)
49866 seq_puts(m, "\tDISCONNECTED ");
49867 seq_printf(m, "\nSMBs: %d",
49868- atomic_read(&tcon->num_smbs_sent));
49869+ atomic_read_unchecked(&tcon->num_smbs_sent));
49870 if (server->ops->print_stats)
49871 server->ops->print_stats(m, tcon);
49872 }
49873diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49874index 3752b9f..8db5569 100644
49875--- a/fs/cifs/cifsfs.c
49876+++ b/fs/cifs/cifsfs.c
49877@@ -1035,7 +1035,7 @@ cifs_init_request_bufs(void)
49878 */
49879 cifs_req_cachep = kmem_cache_create("cifs_request",
49880 CIFSMaxBufSize + max_hdr_size, 0,
49881- SLAB_HWCACHE_ALIGN, NULL);
49882+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49883 if (cifs_req_cachep == NULL)
49884 return -ENOMEM;
49885
49886@@ -1062,7 +1062,7 @@ cifs_init_request_bufs(void)
49887 efficient to alloc 1 per page off the slab compared to 17K (5page)
49888 alloc of large cifs buffers even when page debugging is on */
49889 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49890- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49891+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49892 NULL);
49893 if (cifs_sm_req_cachep == NULL) {
49894 mempool_destroy(cifs_req_poolp);
49895@@ -1147,8 +1147,8 @@ init_cifs(void)
49896 atomic_set(&bufAllocCount, 0);
49897 atomic_set(&smBufAllocCount, 0);
49898 #ifdef CONFIG_CIFS_STATS2
49899- atomic_set(&totBufAllocCount, 0);
49900- atomic_set(&totSmBufAllocCount, 0);
49901+ atomic_set_unchecked(&totBufAllocCount, 0);
49902+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49903 #endif /* CONFIG_CIFS_STATS2 */
49904
49905 atomic_set(&midCount, 0);
49906diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49907index 4f07f6f..55de8ce 100644
49908--- a/fs/cifs/cifsglob.h
49909+++ b/fs/cifs/cifsglob.h
49910@@ -751,35 +751,35 @@ struct cifs_tcon {
49911 __u16 Flags; /* optional support bits */
49912 enum statusEnum tidStatus;
49913 #ifdef CONFIG_CIFS_STATS
49914- atomic_t num_smbs_sent;
49915+ atomic_unchecked_t num_smbs_sent;
49916 union {
49917 struct {
49918- atomic_t num_writes;
49919- atomic_t num_reads;
49920- atomic_t num_flushes;
49921- atomic_t num_oplock_brks;
49922- atomic_t num_opens;
49923- atomic_t num_closes;
49924- atomic_t num_deletes;
49925- atomic_t num_mkdirs;
49926- atomic_t num_posixopens;
49927- atomic_t num_posixmkdirs;
49928- atomic_t num_rmdirs;
49929- atomic_t num_renames;
49930- atomic_t num_t2renames;
49931- atomic_t num_ffirst;
49932- atomic_t num_fnext;
49933- atomic_t num_fclose;
49934- atomic_t num_hardlinks;
49935- atomic_t num_symlinks;
49936- atomic_t num_locks;
49937- atomic_t num_acl_get;
49938- atomic_t num_acl_set;
49939+ atomic_unchecked_t num_writes;
49940+ atomic_unchecked_t num_reads;
49941+ atomic_unchecked_t num_flushes;
49942+ atomic_unchecked_t num_oplock_brks;
49943+ atomic_unchecked_t num_opens;
49944+ atomic_unchecked_t num_closes;
49945+ atomic_unchecked_t num_deletes;
49946+ atomic_unchecked_t num_mkdirs;
49947+ atomic_unchecked_t num_posixopens;
49948+ atomic_unchecked_t num_posixmkdirs;
49949+ atomic_unchecked_t num_rmdirs;
49950+ atomic_unchecked_t num_renames;
49951+ atomic_unchecked_t num_t2renames;
49952+ atomic_unchecked_t num_ffirst;
49953+ atomic_unchecked_t num_fnext;
49954+ atomic_unchecked_t num_fclose;
49955+ atomic_unchecked_t num_hardlinks;
49956+ atomic_unchecked_t num_symlinks;
49957+ atomic_unchecked_t num_locks;
49958+ atomic_unchecked_t num_acl_get;
49959+ atomic_unchecked_t num_acl_set;
49960 } cifs_stats;
49961 #ifdef CONFIG_CIFS_SMB2
49962 struct {
49963- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49964- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49965+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49966+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49967 } smb2_stats;
49968 #endif /* CONFIG_CIFS_SMB2 */
49969 } stats;
49970@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49971 }
49972
49973 #ifdef CONFIG_CIFS_STATS
49974-#define cifs_stats_inc atomic_inc
49975+#define cifs_stats_inc atomic_inc_unchecked
49976
49977 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49978 unsigned int bytes)
49979@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49980 /* Various Debug counters */
49981 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49982 #ifdef CONFIG_CIFS_STATS2
49983-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49984-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49985+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49986+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49987 #endif
49988 GLOBAL_EXTERN atomic_t smBufAllocCount;
49989 GLOBAL_EXTERN atomic_t midCount;
49990diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49991index b83c3f5..6437caa 100644
49992--- a/fs/cifs/link.c
49993+++ b/fs/cifs/link.c
49994@@ -616,7 +616,7 @@ symlink_exit:
49995
49996 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49997 {
49998- char *p = nd_get_link(nd);
49999+ const char *p = nd_get_link(nd);
50000 if (!IS_ERR(p))
50001 kfree(p);
50002 }
50003diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
50004index 1bec014..f329411 100644
50005--- a/fs/cifs/misc.c
50006+++ b/fs/cifs/misc.c
50007@@ -169,7 +169,7 @@ cifs_buf_get(void)
50008 memset(ret_buf, 0, buf_size + 3);
50009 atomic_inc(&bufAllocCount);
50010 #ifdef CONFIG_CIFS_STATS2
50011- atomic_inc(&totBufAllocCount);
50012+ atomic_inc_unchecked(&totBufAllocCount);
50013 #endif /* CONFIG_CIFS_STATS2 */
50014 }
50015
50016@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
50017 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
50018 atomic_inc(&smBufAllocCount);
50019 #ifdef CONFIG_CIFS_STATS2
50020- atomic_inc(&totSmBufAllocCount);
50021+ atomic_inc_unchecked(&totSmBufAllocCount);
50022 #endif /* CONFIG_CIFS_STATS2 */
50023
50024 }
50025diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
50026index 3efdb9d..e845a5e 100644
50027--- a/fs/cifs/smb1ops.c
50028+++ b/fs/cifs/smb1ops.c
50029@@ -591,27 +591,27 @@ static void
50030 cifs_clear_stats(struct cifs_tcon *tcon)
50031 {
50032 #ifdef CONFIG_CIFS_STATS
50033- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
50034- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
50035- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
50036- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50037- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
50038- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
50039- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50040- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
50041- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
50042- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
50043- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
50044- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
50045- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
50046- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
50047- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
50048- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
50049- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
50050- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
50051- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
50052- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
50053- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
50054+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
50055+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
50056+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
50057+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50058+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
50059+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
50060+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50061+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
50062+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
50063+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
50064+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
50065+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
50066+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
50067+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
50068+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
50069+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
50070+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
50071+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
50072+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
50073+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
50074+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
50075 #endif
50076 }
50077
50078@@ -620,36 +620,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50079 {
50080 #ifdef CONFIG_CIFS_STATS
50081 seq_printf(m, " Oplocks breaks: %d",
50082- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
50083+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
50084 seq_printf(m, "\nReads: %d Bytes: %llu",
50085- atomic_read(&tcon->stats.cifs_stats.num_reads),
50086+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
50087 (long long)(tcon->bytes_read));
50088 seq_printf(m, "\nWrites: %d Bytes: %llu",
50089- atomic_read(&tcon->stats.cifs_stats.num_writes),
50090+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
50091 (long long)(tcon->bytes_written));
50092 seq_printf(m, "\nFlushes: %d",
50093- atomic_read(&tcon->stats.cifs_stats.num_flushes));
50094+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
50095 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
50096- atomic_read(&tcon->stats.cifs_stats.num_locks),
50097- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
50098- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
50099+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
50100+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
50101+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
50102 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
50103- atomic_read(&tcon->stats.cifs_stats.num_opens),
50104- atomic_read(&tcon->stats.cifs_stats.num_closes),
50105- atomic_read(&tcon->stats.cifs_stats.num_deletes));
50106+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
50107+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
50108+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
50109 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
50110- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
50111- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
50112+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
50113+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
50114 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
50115- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
50116- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
50117+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
50118+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
50119 seq_printf(m, "\nRenames: %d T2 Renames %d",
50120- atomic_read(&tcon->stats.cifs_stats.num_renames),
50121- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
50122+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
50123+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
50124 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
50125- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
50126- atomic_read(&tcon->stats.cifs_stats.num_fnext),
50127- atomic_read(&tcon->stats.cifs_stats.num_fclose));
50128+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
50129+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
50130+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
50131 #endif
50132 }
50133
50134diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
50135index f2e76f3..c44fac7 100644
50136--- a/fs/cifs/smb2ops.c
50137+++ b/fs/cifs/smb2ops.c
50138@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
50139 #ifdef CONFIG_CIFS_STATS
50140 int i;
50141 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
50142- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50143- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50144+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50145+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50146 }
50147 #endif
50148 }
50149@@ -284,66 +284,66 @@ static void
50150 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50151 {
50152 #ifdef CONFIG_CIFS_STATS
50153- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50154- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50155+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50156+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50157 seq_printf(m, "\nNegotiates: %d sent %d failed",
50158- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
50159- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
50160+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
50161+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
50162 seq_printf(m, "\nSessionSetups: %d sent %d failed",
50163- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
50164- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
50165+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
50166+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
50167 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
50168 seq_printf(m, "\nLogoffs: %d sent %d failed",
50169- atomic_read(&sent[SMB2_LOGOFF_HE]),
50170- atomic_read(&failed[SMB2_LOGOFF_HE]));
50171+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
50172+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
50173 seq_printf(m, "\nTreeConnects: %d sent %d failed",
50174- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
50175- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
50176+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
50177+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
50178 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
50179- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
50180- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
50181+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
50182+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
50183 seq_printf(m, "\nCreates: %d sent %d failed",
50184- atomic_read(&sent[SMB2_CREATE_HE]),
50185- atomic_read(&failed[SMB2_CREATE_HE]));
50186+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
50187+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
50188 seq_printf(m, "\nCloses: %d sent %d failed",
50189- atomic_read(&sent[SMB2_CLOSE_HE]),
50190- atomic_read(&failed[SMB2_CLOSE_HE]));
50191+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
50192+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
50193 seq_printf(m, "\nFlushes: %d sent %d failed",
50194- atomic_read(&sent[SMB2_FLUSH_HE]),
50195- atomic_read(&failed[SMB2_FLUSH_HE]));
50196+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
50197+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
50198 seq_printf(m, "\nReads: %d sent %d failed",
50199- atomic_read(&sent[SMB2_READ_HE]),
50200- atomic_read(&failed[SMB2_READ_HE]));
50201+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
50202+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
50203 seq_printf(m, "\nWrites: %d sent %d failed",
50204- atomic_read(&sent[SMB2_WRITE_HE]),
50205- atomic_read(&failed[SMB2_WRITE_HE]));
50206+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
50207+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
50208 seq_printf(m, "\nLocks: %d sent %d failed",
50209- atomic_read(&sent[SMB2_LOCK_HE]),
50210- atomic_read(&failed[SMB2_LOCK_HE]));
50211+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
50212+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
50213 seq_printf(m, "\nIOCTLs: %d sent %d failed",
50214- atomic_read(&sent[SMB2_IOCTL_HE]),
50215- atomic_read(&failed[SMB2_IOCTL_HE]));
50216+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
50217+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
50218 seq_printf(m, "\nCancels: %d sent %d failed",
50219- atomic_read(&sent[SMB2_CANCEL_HE]),
50220- atomic_read(&failed[SMB2_CANCEL_HE]));
50221+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
50222+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
50223 seq_printf(m, "\nEchos: %d sent %d failed",
50224- atomic_read(&sent[SMB2_ECHO_HE]),
50225- atomic_read(&failed[SMB2_ECHO_HE]));
50226+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
50227+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
50228 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
50229- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
50230- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
50231+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
50232+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
50233 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
50234- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
50235- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
50236+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
50237+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
50238 seq_printf(m, "\nQueryInfos: %d sent %d failed",
50239- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
50240- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
50241+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
50242+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
50243 seq_printf(m, "\nSetInfos: %d sent %d failed",
50244- atomic_read(&sent[SMB2_SET_INFO_HE]),
50245- atomic_read(&failed[SMB2_SET_INFO_HE]));
50246+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
50247+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
50248 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
50249- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
50250- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
50251+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
50252+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
50253 #endif
50254 }
50255
50256diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
50257index 2b95ce2..d079d75 100644
50258--- a/fs/cifs/smb2pdu.c
50259+++ b/fs/cifs/smb2pdu.c
50260@@ -1760,8 +1760,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
50261 default:
50262 cifs_dbg(VFS, "info level %u isn't supported\n",
50263 srch_inf->info_level);
50264- rc = -EINVAL;
50265- goto qdir_exit;
50266+ return -EINVAL;
50267 }
50268
50269 req->FileIndex = cpu_to_le32(index);
50270diff --git a/fs/coda/cache.c b/fs/coda/cache.c
50271index 1da168c..8bc7ff6 100644
50272--- a/fs/coda/cache.c
50273+++ b/fs/coda/cache.c
50274@@ -24,7 +24,7 @@
50275 #include "coda_linux.h"
50276 #include "coda_cache.h"
50277
50278-static atomic_t permission_epoch = ATOMIC_INIT(0);
50279+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
50280
50281 /* replace or extend an acl cache hit */
50282 void coda_cache_enter(struct inode *inode, int mask)
50283@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
50284 struct coda_inode_info *cii = ITOC(inode);
50285
50286 spin_lock(&cii->c_lock);
50287- cii->c_cached_epoch = atomic_read(&permission_epoch);
50288+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
50289 if (!uid_eq(cii->c_uid, current_fsuid())) {
50290 cii->c_uid = current_fsuid();
50291 cii->c_cached_perm = mask;
50292@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
50293 {
50294 struct coda_inode_info *cii = ITOC(inode);
50295 spin_lock(&cii->c_lock);
50296- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
50297+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
50298 spin_unlock(&cii->c_lock);
50299 }
50300
50301 /* remove all acl caches */
50302 void coda_cache_clear_all(struct super_block *sb)
50303 {
50304- atomic_inc(&permission_epoch);
50305+ atomic_inc_unchecked(&permission_epoch);
50306 }
50307
50308
50309@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
50310 spin_lock(&cii->c_lock);
50311 hit = (mask & cii->c_cached_perm) == mask &&
50312 uid_eq(cii->c_uid, current_fsuid()) &&
50313- cii->c_cached_epoch == atomic_read(&permission_epoch);
50314+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
50315 spin_unlock(&cii->c_lock);
50316
50317 return hit;
50318diff --git a/fs/compat.c b/fs/compat.c
50319index fc3b55d..7b568ae 100644
50320--- a/fs/compat.c
50321+++ b/fs/compat.c
50322@@ -54,7 +54,7 @@
50323 #include <asm/ioctls.h>
50324 #include "internal.h"
50325
50326-int compat_log = 1;
50327+int compat_log = 0;
50328
50329 int compat_printk(const char *fmt, ...)
50330 {
50331@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
50332
50333 set_fs(KERNEL_DS);
50334 /* The __user pointer cast is valid because of the set_fs() */
50335- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
50336+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
50337 set_fs(oldfs);
50338 /* truncating is ok because it's a user address */
50339 if (!ret)
50340@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
50341 goto out;
50342
50343 ret = -EINVAL;
50344- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
50345+ if (nr_segs > UIO_MAXIOV)
50346 goto out;
50347 if (nr_segs > fast_segs) {
50348 ret = -ENOMEM;
50349@@ -833,6 +833,7 @@ struct compat_old_linux_dirent {
50350
50351 struct compat_readdir_callback {
50352 struct compat_old_linux_dirent __user *dirent;
50353+ struct file * file;
50354 int result;
50355 };
50356
50357@@ -850,6 +851,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
50358 buf->result = -EOVERFLOW;
50359 return -EOVERFLOW;
50360 }
50361+
50362+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50363+ return 0;
50364+
50365 buf->result++;
50366 dirent = buf->dirent;
50367 if (!access_ok(VERIFY_WRITE, dirent,
50368@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
50369
50370 buf.result = 0;
50371 buf.dirent = dirent;
50372+ buf.file = f.file;
50373
50374 error = vfs_readdir(f.file, compat_fillonedir, &buf);
50375 if (buf.result)
50376@@ -899,6 +905,7 @@ struct compat_linux_dirent {
50377 struct compat_getdents_callback {
50378 struct compat_linux_dirent __user *current_dir;
50379 struct compat_linux_dirent __user *previous;
50380+ struct file * file;
50381 int count;
50382 int error;
50383 };
50384@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
50385 buf->error = -EOVERFLOW;
50386 return -EOVERFLOW;
50387 }
50388+
50389+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50390+ return 0;
50391+
50392 dirent = buf->previous;
50393 if (dirent) {
50394 if (__put_user(offset, &dirent->d_off))
50395@@ -965,6 +976,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50396 buf.previous = NULL;
50397 buf.count = count;
50398 buf.error = 0;
50399+ buf.file = f.file;
50400
50401 error = vfs_readdir(f.file, compat_filldir, &buf);
50402 if (error >= 0)
50403@@ -985,6 +997,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50404 struct compat_getdents_callback64 {
50405 struct linux_dirent64 __user *current_dir;
50406 struct linux_dirent64 __user *previous;
50407+ struct file * file;
50408 int count;
50409 int error;
50410 };
50411@@ -1001,6 +1014,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
50412 buf->error = -EINVAL; /* only used if we fail.. */
50413 if (reclen > buf->count)
50414 return -EINVAL;
50415+
50416+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50417+ return 0;
50418+
50419 dirent = buf->previous;
50420
50421 if (dirent) {
50422@@ -1050,13 +1067,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
50423 buf.previous = NULL;
50424 buf.count = count;
50425 buf.error = 0;
50426+ buf.file = f.file;
50427
50428 error = vfs_readdir(f.file, compat_filldir64, &buf);
50429 if (error >= 0)
50430 error = buf.error;
50431 lastdirent = buf.previous;
50432 if (lastdirent) {
50433- typeof(lastdirent->d_off) d_off = f.file->f_pos;
50434+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50435 if (__put_user_unaligned(d_off, &lastdirent->d_off))
50436 error = -EFAULT;
50437 else
50438diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
50439index a81147e..20bf2b5 100644
50440--- a/fs/compat_binfmt_elf.c
50441+++ b/fs/compat_binfmt_elf.c
50442@@ -30,11 +30,13 @@
50443 #undef elf_phdr
50444 #undef elf_shdr
50445 #undef elf_note
50446+#undef elf_dyn
50447 #undef elf_addr_t
50448 #define elfhdr elf32_hdr
50449 #define elf_phdr elf32_phdr
50450 #define elf_shdr elf32_shdr
50451 #define elf_note elf32_note
50452+#define elf_dyn Elf32_Dyn
50453 #define elf_addr_t Elf32_Addr
50454
50455 /*
50456diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
50457index 996cdc5..15e2f33 100644
50458--- a/fs/compat_ioctl.c
50459+++ b/fs/compat_ioctl.c
50460@@ -622,7 +622,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
50461 return -EFAULT;
50462 if (__get_user(udata, &ss32->iomem_base))
50463 return -EFAULT;
50464- ss.iomem_base = compat_ptr(udata);
50465+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
50466 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
50467 __get_user(ss.port_high, &ss32->port_high))
50468 return -EFAULT;
50469@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
50470 for (i = 0; i < nmsgs; i++) {
50471 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
50472 return -EFAULT;
50473- if (get_user(datap, &umsgs[i].buf) ||
50474- put_user(compat_ptr(datap), &tmsgs[i].buf))
50475+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
50476+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
50477 return -EFAULT;
50478 }
50479 return sys_ioctl(fd, cmd, (unsigned long)tdata);
50480@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
50481 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
50482 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
50483 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
50484- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50485+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50486 return -EFAULT;
50487
50488 return ioctl_preallocate(file, p);
50489@@ -1619,8 +1619,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
50490 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
50491 {
50492 unsigned int a, b;
50493- a = *(unsigned int *)p;
50494- b = *(unsigned int *)q;
50495+ a = *(const unsigned int *)p;
50496+ b = *(const unsigned int *)q;
50497 if (a > b)
50498 return 1;
50499 if (a < b)
50500diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
50501index 7aabc6a..34c1197 100644
50502--- a/fs/configfs/dir.c
50503+++ b/fs/configfs/dir.c
50504@@ -1565,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50505 }
50506 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
50507 struct configfs_dirent *next;
50508- const char * name;
50509+ const unsigned char * name;
50510+ char d_name[sizeof(next->s_dentry->d_iname)];
50511 int len;
50512 struct inode *inode = NULL;
50513
50514@@ -1575,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50515 continue;
50516
50517 name = configfs_get_name(next);
50518- len = strlen(name);
50519+ if (next->s_dentry && name == next->s_dentry->d_iname) {
50520+ len = next->s_dentry->d_name.len;
50521+ memcpy(d_name, name, len);
50522+ name = d_name;
50523+ } else
50524+ len = strlen(name);
50525
50526 /*
50527 * We'll have a dentry and an inode for
50528diff --git a/fs/coredump.c b/fs/coredump.c
50529index dafafba..10b3b27 100644
50530--- a/fs/coredump.c
50531+++ b/fs/coredump.c
50532@@ -52,7 +52,7 @@ struct core_name {
50533 char *corename;
50534 int used, size;
50535 };
50536-static atomic_t call_count = ATOMIC_INIT(1);
50537+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
50538
50539 /* The maximal length of core_pattern is also specified in sysctl.c */
50540
50541@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
50542 {
50543 char *old_corename = cn->corename;
50544
50545- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
50546+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
50547 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
50548
50549 if (!cn->corename) {
50550@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
50551 int pid_in_pattern = 0;
50552 int err = 0;
50553
50554- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
50555+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
50556 cn->corename = kmalloc(cn->size, GFP_KERNEL);
50557 cn->used = 0;
50558
50559@@ -435,8 +435,8 @@ static void wait_for_dump_helpers(struct file *file)
50560 struct pipe_inode_info *pipe = file->private_data;
50561
50562 pipe_lock(pipe);
50563- pipe->readers++;
50564- pipe->writers--;
50565+ atomic_inc(&pipe->readers);
50566+ atomic_dec(&pipe->writers);
50567 wake_up_interruptible_sync(&pipe->wait);
50568 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50569 pipe_unlock(pipe);
50570@@ -445,11 +445,11 @@ static void wait_for_dump_helpers(struct file *file)
50571 * We actually want wait_event_freezable() but then we need
50572 * to clear TIF_SIGPENDING and improve dump_interrupted().
50573 */
50574- wait_event_interruptible(pipe->wait, pipe->readers == 1);
50575+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
50576
50577 pipe_lock(pipe);
50578- pipe->readers--;
50579- pipe->writers++;
50580+ atomic_dec(&pipe->readers);
50581+ atomic_inc(&pipe->writers);
50582 pipe_unlock(pipe);
50583 }
50584
50585@@ -496,7 +496,8 @@ void do_coredump(siginfo_t *siginfo)
50586 struct files_struct *displaced;
50587 bool need_nonrelative = false;
50588 bool core_dumped = false;
50589- static atomic_t core_dump_count = ATOMIC_INIT(0);
50590+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
50591+ long signr = siginfo->si_signo;
50592 struct coredump_params cprm = {
50593 .siginfo = siginfo,
50594 .regs = signal_pt_regs(),
50595@@ -509,7 +510,10 @@ void do_coredump(siginfo_t *siginfo)
50596 .mm_flags = mm->flags,
50597 };
50598
50599- audit_core_dumps(siginfo->si_signo);
50600+ audit_core_dumps(signr);
50601+
50602+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
50603+ gr_handle_brute_attach(cprm.mm_flags);
50604
50605 binfmt = mm->binfmt;
50606 if (!binfmt || !binfmt->core_dump)
50607@@ -533,7 +537,7 @@ void do_coredump(siginfo_t *siginfo)
50608 need_nonrelative = true;
50609 }
50610
50611- retval = coredump_wait(siginfo->si_signo, &core_state);
50612+ retval = coredump_wait(signr, &core_state);
50613 if (retval < 0)
50614 goto fail_creds;
50615
50616@@ -576,7 +580,7 @@ void do_coredump(siginfo_t *siginfo)
50617 }
50618 cprm.limit = RLIM_INFINITY;
50619
50620- dump_count = atomic_inc_return(&core_dump_count);
50621+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
50622 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
50623 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
50624 task_tgid_vnr(current), current->comm);
50625@@ -608,6 +612,8 @@ void do_coredump(siginfo_t *siginfo)
50626 } else {
50627 struct inode *inode;
50628
50629+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
50630+
50631 if (cprm.limit < binfmt->min_coredump)
50632 goto fail_unlock;
50633
50634@@ -666,7 +672,7 @@ close_fail:
50635 filp_close(cprm.file, NULL);
50636 fail_dropcount:
50637 if (ispipe)
50638- atomic_dec(&core_dump_count);
50639+ atomic_dec_unchecked(&core_dump_count);
50640 fail_unlock:
50641 kfree(cn.corename);
50642 fail_corename:
50643@@ -687,7 +693,7 @@ int dump_write(struct file *file, const void *addr, int nr)
50644 {
50645 return !dump_interrupted() &&
50646 access_ok(VERIFY_READ, addr, nr) &&
50647- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
50648+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
50649 }
50650 EXPORT_SYMBOL(dump_write);
50651
50652diff --git a/fs/dcache.c b/fs/dcache.c
50653index f09b908..4dd10d8 100644
50654--- a/fs/dcache.c
50655+++ b/fs/dcache.c
50656@@ -3086,7 +3086,7 @@ void __init vfs_caches_init(unsigned long mempages)
50657 mempages -= reserve;
50658
50659 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50660- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50661+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
50662
50663 dcache_init();
50664 inode_init();
50665diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50666index 4888cb3..e0f7cf8 100644
50667--- a/fs/debugfs/inode.c
50668+++ b/fs/debugfs/inode.c
50669@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50670 */
50671 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50672 {
50673+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50674+ return __create_file(name, S_IFDIR | S_IRWXU,
50675+#else
50676 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50677+#endif
50678 parent, NULL, NULL);
50679 }
50680 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50681diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50682index 5eab400..810a3f5 100644
50683--- a/fs/ecryptfs/inode.c
50684+++ b/fs/ecryptfs/inode.c
50685@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50686 old_fs = get_fs();
50687 set_fs(get_ds());
50688 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50689- (char __user *)lower_buf,
50690+ (char __force_user *)lower_buf,
50691 PATH_MAX);
50692 set_fs(old_fs);
50693 if (rc < 0)
50694@@ -706,7 +706,7 @@ out:
50695 static void
50696 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50697 {
50698- char *buf = nd_get_link(nd);
50699+ const char *buf = nd_get_link(nd);
50700 if (!IS_ERR(buf)) {
50701 /* Free the char* */
50702 kfree(buf);
50703diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50704index e4141f2..d8263e8 100644
50705--- a/fs/ecryptfs/miscdev.c
50706+++ b/fs/ecryptfs/miscdev.c
50707@@ -304,7 +304,7 @@ check_list:
50708 goto out_unlock_msg_ctx;
50709 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50710 if (msg_ctx->msg) {
50711- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50712+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50713 goto out_unlock_msg_ctx;
50714 i += packet_length_size;
50715 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50716diff --git a/fs/exec.c b/fs/exec.c
50717index ffd7a81..e38107f 100644
50718--- a/fs/exec.c
50719+++ b/fs/exec.c
50720@@ -55,8 +55,20 @@
50721 #include <linux/pipe_fs_i.h>
50722 #include <linux/oom.h>
50723 #include <linux/compat.h>
50724+#include <linux/random.h>
50725+#include <linux/seq_file.h>
50726+#include <linux/coredump.h>
50727+#include <linux/mman.h>
50728+
50729+#ifdef CONFIG_PAX_REFCOUNT
50730+#include <linux/kallsyms.h>
50731+#include <linux/kdebug.h>
50732+#endif
50733+
50734+#include <trace/events/fs.h>
50735
50736 #include <asm/uaccess.h>
50737+#include <asm/sections.h>
50738 #include <asm/mmu_context.h>
50739 #include <asm/tlb.h>
50740
50741@@ -66,17 +78,32 @@
50742
50743 #include <trace/events/sched.h>
50744
50745+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50746+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50747+{
50748+ 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");
50749+}
50750+#endif
50751+
50752+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50753+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50754+EXPORT_SYMBOL(pax_set_initial_flags_func);
50755+#endif
50756+
50757 int suid_dumpable = 0;
50758
50759 static LIST_HEAD(formats);
50760 static DEFINE_RWLOCK(binfmt_lock);
50761
50762+extern int gr_process_kernel_exec_ban(void);
50763+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
50764+
50765 void __register_binfmt(struct linux_binfmt * fmt, int insert)
50766 {
50767 BUG_ON(!fmt);
50768 write_lock(&binfmt_lock);
50769- insert ? list_add(&fmt->lh, &formats) :
50770- list_add_tail(&fmt->lh, &formats);
50771+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50772+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50773 write_unlock(&binfmt_lock);
50774 }
50775
50776@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
50777 void unregister_binfmt(struct linux_binfmt * fmt)
50778 {
50779 write_lock(&binfmt_lock);
50780- list_del(&fmt->lh);
50781+ pax_list_del((struct list_head *)&fmt->lh);
50782 write_unlock(&binfmt_lock);
50783 }
50784
50785@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50786 int write)
50787 {
50788 struct page *page;
50789- int ret;
50790
50791-#ifdef CONFIG_STACK_GROWSUP
50792- if (write) {
50793- ret = expand_downwards(bprm->vma, pos);
50794- if (ret < 0)
50795- return NULL;
50796- }
50797-#endif
50798- ret = get_user_pages(current, bprm->mm, pos,
50799- 1, write, 1, &page, NULL);
50800- if (ret <= 0)
50801+ if (0 > expand_downwards(bprm->vma, pos))
50802+ return NULL;
50803+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50804 return NULL;
50805
50806 if (write) {
50807@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50808 if (size <= ARG_MAX)
50809 return page;
50810
50811+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50812+ // only allow 512KB for argv+env on suid/sgid binaries
50813+ // to prevent easy ASLR exhaustion
50814+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50815+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50816+ (size > (512 * 1024))) {
50817+ put_page(page);
50818+ return NULL;
50819+ }
50820+#endif
50821+
50822 /*
50823 * Limit to 1/4-th the stack size for the argv+env strings.
50824 * This ensures that:
50825@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50826 vma->vm_end = STACK_TOP_MAX;
50827 vma->vm_start = vma->vm_end - PAGE_SIZE;
50828 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50829+
50830+#ifdef CONFIG_PAX_SEGMEXEC
50831+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50832+#endif
50833+
50834 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50835 INIT_LIST_HEAD(&vma->anon_vma_chain);
50836
50837@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50838 mm->stack_vm = mm->total_vm = 1;
50839 up_write(&mm->mmap_sem);
50840 bprm->p = vma->vm_end - sizeof(void *);
50841+
50842+#ifdef CONFIG_PAX_RANDUSTACK
50843+ if (randomize_va_space)
50844+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
50845+#endif
50846+
50847 return 0;
50848 err:
50849 up_write(&mm->mmap_sem);
50850@@ -396,7 +437,7 @@ struct user_arg_ptr {
50851 } ptr;
50852 };
50853
50854-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50855+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50856 {
50857 const char __user *native;
50858
50859@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50860 compat_uptr_t compat;
50861
50862 if (get_user(compat, argv.ptr.compat + nr))
50863- return ERR_PTR(-EFAULT);
50864+ return (const char __force_user *)ERR_PTR(-EFAULT);
50865
50866 return compat_ptr(compat);
50867 }
50868 #endif
50869
50870 if (get_user(native, argv.ptr.native + nr))
50871- return ERR_PTR(-EFAULT);
50872+ return (const char __force_user *)ERR_PTR(-EFAULT);
50873
50874 return native;
50875 }
50876@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
50877 if (!p)
50878 break;
50879
50880- if (IS_ERR(p))
50881+ if (IS_ERR((const char __force_kernel *)p))
50882 return -EFAULT;
50883
50884 if (i >= max)
50885@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50886
50887 ret = -EFAULT;
50888 str = get_user_arg_ptr(argv, argc);
50889- if (IS_ERR(str))
50890+ if (IS_ERR((const char __force_kernel *)str))
50891 goto out;
50892
50893 len = strnlen_user(str, MAX_ARG_STRLEN);
50894@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50895 int r;
50896 mm_segment_t oldfs = get_fs();
50897 struct user_arg_ptr argv = {
50898- .ptr.native = (const char __user *const __user *)__argv,
50899+ .ptr.native = (const char __force_user * const __force_user *)__argv,
50900 };
50901
50902 set_fs(KERNEL_DS);
50903@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50904 unsigned long new_end = old_end - shift;
50905 struct mmu_gather tlb;
50906
50907- BUG_ON(new_start > new_end);
50908+ if (new_start >= new_end || new_start < mmap_min_addr)
50909+ return -ENOMEM;
50910
50911 /*
50912 * ensure there are no vmas between where we want to go
50913@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50914 if (vma != find_vma(mm, new_start))
50915 return -EFAULT;
50916
50917+#ifdef CONFIG_PAX_SEGMEXEC
50918+ BUG_ON(pax_find_mirror_vma(vma));
50919+#endif
50920+
50921 /*
50922 * cover the whole range: [new_start, old_end)
50923 */
50924@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50925 stack_top = arch_align_stack(stack_top);
50926 stack_top = PAGE_ALIGN(stack_top);
50927
50928- if (unlikely(stack_top < mmap_min_addr) ||
50929- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50930- return -ENOMEM;
50931-
50932 stack_shift = vma->vm_end - stack_top;
50933
50934 bprm->p -= stack_shift;
50935@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50936 bprm->exec -= stack_shift;
50937
50938 down_write(&mm->mmap_sem);
50939+
50940+ /* Move stack pages down in memory. */
50941+ if (stack_shift) {
50942+ ret = shift_arg_pages(vma, stack_shift);
50943+ if (ret)
50944+ goto out_unlock;
50945+ }
50946+
50947 vm_flags = VM_STACK_FLAGS;
50948
50949+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50950+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
50951+ vm_flags &= ~VM_EXEC;
50952+
50953+#ifdef CONFIG_PAX_MPROTECT
50954+ if (mm->pax_flags & MF_PAX_MPROTECT)
50955+ vm_flags &= ~VM_MAYEXEC;
50956+#endif
50957+
50958+ }
50959+#endif
50960+
50961 /*
50962 * Adjust stack execute permissions; explicitly enable for
50963 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
50964@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50965 goto out_unlock;
50966 BUG_ON(prev != vma);
50967
50968- /* Move stack pages down in memory. */
50969- if (stack_shift) {
50970- ret = shift_arg_pages(vma, stack_shift);
50971- if (ret)
50972- goto out_unlock;
50973- }
50974-
50975 /* mprotect_fixup is overkill to remove the temporary stack flags */
50976 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
50977
50978@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
50979 #endif
50980 current->mm->start_stack = bprm->p;
50981 ret = expand_stack(vma, stack_base);
50982+
50983+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
50984+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
50985+ unsigned long size;
50986+ vm_flags_t vm_flags;
50987+
50988+ size = STACK_TOP - vma->vm_end;
50989+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
50990+
50991+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
50992+
50993+#ifdef CONFIG_X86
50994+ if (!ret) {
50995+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
50996+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
50997+ }
50998+#endif
50999+
51000+ }
51001+#endif
51002+
51003 if (ret)
51004 ret = -EFAULT;
51005
51006@@ -772,6 +848,8 @@ struct file *open_exec(const char *name)
51007
51008 fsnotify_open(file);
51009
51010+ trace_open_exec(name);
51011+
51012 err = deny_write_access(file);
51013 if (err)
51014 goto exit;
51015@@ -795,7 +873,7 @@ int kernel_read(struct file *file, loff_t offset,
51016 old_fs = get_fs();
51017 set_fs(get_ds());
51018 /* The cast to a user pointer is valid due to the set_fs() */
51019- result = vfs_read(file, (void __user *)addr, count, &pos);
51020+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
51021 set_fs(old_fs);
51022 return result;
51023 }
51024@@ -1251,7 +1329,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
51025 }
51026 rcu_read_unlock();
51027
51028- if (p->fs->users > n_fs) {
51029+ if (atomic_read(&p->fs->users) > n_fs) {
51030 bprm->unsafe |= LSM_UNSAFE_SHARE;
51031 } else {
51032 res = -EAGAIN;
51033@@ -1451,6 +1529,31 @@ int search_binary_handler(struct linux_binprm *bprm)
51034
51035 EXPORT_SYMBOL(search_binary_handler);
51036
51037+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51038+static DEFINE_PER_CPU(u64, exec_counter);
51039+static int __init init_exec_counters(void)
51040+{
51041+ unsigned int cpu;
51042+
51043+ for_each_possible_cpu(cpu) {
51044+ per_cpu(exec_counter, cpu) = (u64)cpu;
51045+ }
51046+
51047+ return 0;
51048+}
51049+early_initcall(init_exec_counters);
51050+static inline void increment_exec_counter(void)
51051+{
51052+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
51053+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
51054+}
51055+#else
51056+static inline void increment_exec_counter(void) {}
51057+#endif
51058+
51059+extern void gr_handle_exec_args(struct linux_binprm *bprm,
51060+ struct user_arg_ptr argv);
51061+
51062 /*
51063 * sys_execve() executes a new program.
51064 */
51065@@ -1458,6 +1561,11 @@ static int do_execve_common(const char *filename,
51066 struct user_arg_ptr argv,
51067 struct user_arg_ptr envp)
51068 {
51069+#ifdef CONFIG_GRKERNSEC
51070+ struct file *old_exec_file;
51071+ struct acl_subject_label *old_acl;
51072+ struct rlimit old_rlim[RLIM_NLIMITS];
51073+#endif
51074 struct linux_binprm *bprm;
51075 struct file *file;
51076 struct files_struct *displaced;
51077@@ -1465,6 +1573,8 @@ static int do_execve_common(const char *filename,
51078 int retval;
51079 const struct cred *cred = current_cred();
51080
51081+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&cred->user->processes), 1);
51082+
51083 /*
51084 * We move the actual failure in case of RLIMIT_NPROC excess from
51085 * set*uid() to execve() because too many poorly written programs
51086@@ -1505,12 +1615,22 @@ static int do_execve_common(const char *filename,
51087 if (IS_ERR(file))
51088 goto out_unmark;
51089
51090+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
51091+ retval = -EPERM;
51092+ goto out_file;
51093+ }
51094+
51095 sched_exec();
51096
51097 bprm->file = file;
51098 bprm->filename = filename;
51099 bprm->interp = filename;
51100
51101+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
51102+ retval = -EACCES;
51103+ goto out_file;
51104+ }
51105+
51106 retval = bprm_mm_init(bprm);
51107 if (retval)
51108 goto out_file;
51109@@ -1527,24 +1647,70 @@ static int do_execve_common(const char *filename,
51110 if (retval < 0)
51111 goto out;
51112
51113+#ifdef CONFIG_GRKERNSEC
51114+ old_acl = current->acl;
51115+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
51116+ old_exec_file = current->exec_file;
51117+ get_file(file);
51118+ current->exec_file = file;
51119+#endif
51120+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51121+ /* limit suid stack to 8MB
51122+ * we saved the old limits above and will restore them if this exec fails
51123+ */
51124+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
51125+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
51126+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
51127+#endif
51128+
51129+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
51130+ retval = -EPERM;
51131+ goto out_fail;
51132+ }
51133+
51134+ if (!gr_tpe_allow(file)) {
51135+ retval = -EACCES;
51136+ goto out_fail;
51137+ }
51138+
51139+ if (gr_check_crash_exec(file)) {
51140+ retval = -EACCES;
51141+ goto out_fail;
51142+ }
51143+
51144+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
51145+ bprm->unsafe);
51146+ if (retval < 0)
51147+ goto out_fail;
51148+
51149 retval = copy_strings_kernel(1, &bprm->filename, bprm);
51150 if (retval < 0)
51151- goto out;
51152+ goto out_fail;
51153
51154 bprm->exec = bprm->p;
51155 retval = copy_strings(bprm->envc, envp, bprm);
51156 if (retval < 0)
51157- goto out;
51158+ goto out_fail;
51159
51160 retval = copy_strings(bprm->argc, argv, bprm);
51161 if (retval < 0)
51162- goto out;
51163+ goto out_fail;
51164+
51165+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
51166+
51167+ gr_handle_exec_args(bprm, argv);
51168
51169 retval = search_binary_handler(bprm);
51170 if (retval < 0)
51171- goto out;
51172+ goto out_fail;
51173+#ifdef CONFIG_GRKERNSEC
51174+ if (old_exec_file)
51175+ fput(old_exec_file);
51176+#endif
51177
51178 /* execve succeeded */
51179+
51180+ increment_exec_counter();
51181 current->fs->in_exec = 0;
51182 current->in_execve = 0;
51183 acct_update_integrals(current);
51184@@ -1553,6 +1719,14 @@ static int do_execve_common(const char *filename,
51185 put_files_struct(displaced);
51186 return retval;
51187
51188+out_fail:
51189+#ifdef CONFIG_GRKERNSEC
51190+ current->acl = old_acl;
51191+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
51192+ fput(current->exec_file);
51193+ current->exec_file = old_exec_file;
51194+#endif
51195+
51196 out:
51197 if (bprm->mm) {
51198 acct_arg_size(bprm, 0);
51199@@ -1701,3 +1875,283 @@ asmlinkage long compat_sys_execve(const char __user * filename,
51200 return error;
51201 }
51202 #endif
51203+
51204+int pax_check_flags(unsigned long *flags)
51205+{
51206+ int retval = 0;
51207+
51208+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
51209+ if (*flags & MF_PAX_SEGMEXEC)
51210+ {
51211+ *flags &= ~MF_PAX_SEGMEXEC;
51212+ retval = -EINVAL;
51213+ }
51214+#endif
51215+
51216+ if ((*flags & MF_PAX_PAGEEXEC)
51217+
51218+#ifdef CONFIG_PAX_PAGEEXEC
51219+ && (*flags & MF_PAX_SEGMEXEC)
51220+#endif
51221+
51222+ )
51223+ {
51224+ *flags &= ~MF_PAX_PAGEEXEC;
51225+ retval = -EINVAL;
51226+ }
51227+
51228+ if ((*flags & MF_PAX_MPROTECT)
51229+
51230+#ifdef CONFIG_PAX_MPROTECT
51231+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51232+#endif
51233+
51234+ )
51235+ {
51236+ *flags &= ~MF_PAX_MPROTECT;
51237+ retval = -EINVAL;
51238+ }
51239+
51240+ if ((*flags & MF_PAX_EMUTRAMP)
51241+
51242+#ifdef CONFIG_PAX_EMUTRAMP
51243+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51244+#endif
51245+
51246+ )
51247+ {
51248+ *flags &= ~MF_PAX_EMUTRAMP;
51249+ retval = -EINVAL;
51250+ }
51251+
51252+ return retval;
51253+}
51254+
51255+EXPORT_SYMBOL(pax_check_flags);
51256+
51257+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51258+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
51259+{
51260+ struct task_struct *tsk = current;
51261+ struct mm_struct *mm = current->mm;
51262+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
51263+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
51264+ char *path_exec = NULL;
51265+ char *path_fault = NULL;
51266+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
51267+ siginfo_t info = { };
51268+
51269+ if (buffer_exec && buffer_fault) {
51270+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
51271+
51272+ down_read(&mm->mmap_sem);
51273+ vma = mm->mmap;
51274+ while (vma && (!vma_exec || !vma_fault)) {
51275+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
51276+ vma_exec = vma;
51277+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
51278+ vma_fault = vma;
51279+ vma = vma->vm_next;
51280+ }
51281+ if (vma_exec) {
51282+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
51283+ if (IS_ERR(path_exec))
51284+ path_exec = "<path too long>";
51285+ else {
51286+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
51287+ if (path_exec) {
51288+ *path_exec = 0;
51289+ path_exec = buffer_exec;
51290+ } else
51291+ path_exec = "<path too long>";
51292+ }
51293+ }
51294+ if (vma_fault) {
51295+ start = vma_fault->vm_start;
51296+ end = vma_fault->vm_end;
51297+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
51298+ if (vma_fault->vm_file) {
51299+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
51300+ if (IS_ERR(path_fault))
51301+ path_fault = "<path too long>";
51302+ else {
51303+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
51304+ if (path_fault) {
51305+ *path_fault = 0;
51306+ path_fault = buffer_fault;
51307+ } else
51308+ path_fault = "<path too long>";
51309+ }
51310+ } else
51311+ path_fault = "<anonymous mapping>";
51312+ }
51313+ up_read(&mm->mmap_sem);
51314+ }
51315+ if (tsk->signal->curr_ip)
51316+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
51317+ else
51318+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
51319+ 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),
51320+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
51321+ free_page((unsigned long)buffer_exec);
51322+ free_page((unsigned long)buffer_fault);
51323+ pax_report_insns(regs, pc, sp);
51324+ info.si_signo = SIGKILL;
51325+ info.si_errno = 0;
51326+ info.si_code = SI_KERNEL;
51327+ info.si_pid = 0;
51328+ info.si_uid = 0;
51329+ do_coredump(&info);
51330+}
51331+#endif
51332+
51333+#ifdef CONFIG_PAX_REFCOUNT
51334+void pax_report_refcount_overflow(struct pt_regs *regs)
51335+{
51336+ if (current->signal->curr_ip)
51337+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
51338+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
51339+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51340+ else
51341+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
51342+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51343+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
51344+ show_regs(regs);
51345+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
51346+}
51347+#endif
51348+
51349+#ifdef CONFIG_PAX_USERCOPY
51350+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
51351+static noinline int check_stack_object(const void *obj, unsigned long len)
51352+{
51353+ const void * const stack = task_stack_page(current);
51354+ const void * const stackend = stack + THREAD_SIZE;
51355+
51356+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51357+ const void *frame = NULL;
51358+ const void *oldframe;
51359+#endif
51360+
51361+ if (obj + len < obj)
51362+ return -1;
51363+
51364+ if (obj + len <= stack || stackend <= obj)
51365+ return 0;
51366+
51367+ if (obj < stack || stackend < obj + len)
51368+ return -1;
51369+
51370+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51371+ oldframe = __builtin_frame_address(1);
51372+ if (oldframe)
51373+ frame = __builtin_frame_address(2);
51374+ /*
51375+ low ----------------------------------------------> high
51376+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
51377+ ^----------------^
51378+ allow copies only within here
51379+ */
51380+ while (stack <= frame && frame < stackend) {
51381+ /* if obj + len extends past the last frame, this
51382+ check won't pass and the next frame will be 0,
51383+ causing us to bail out and correctly report
51384+ the copy as invalid
51385+ */
51386+ if (obj + len <= frame)
51387+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
51388+ oldframe = frame;
51389+ frame = *(const void * const *)frame;
51390+ }
51391+ return -1;
51392+#else
51393+ return 1;
51394+#endif
51395+}
51396+
51397+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
51398+{
51399+ if (current->signal->curr_ip)
51400+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51401+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51402+ else
51403+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51404+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51405+ dump_stack();
51406+ gr_handle_kernel_exploit();
51407+ do_group_exit(SIGKILL);
51408+}
51409+#endif
51410+
51411+#ifdef CONFIG_PAX_USERCOPY
51412+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
51413+{
51414+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
51415+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
51416+#ifdef CONFIG_MODULES
51417+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
51418+#else
51419+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
51420+#endif
51421+
51422+#else
51423+ unsigned long textlow = (unsigned long)_stext;
51424+ unsigned long texthigh = (unsigned long)_etext;
51425+#endif
51426+
51427+ if (high <= textlow || low > texthigh)
51428+ return false;
51429+ else
51430+ return true;
51431+}
51432+#endif
51433+
51434+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
51435+{
51436+
51437+#ifdef CONFIG_PAX_USERCOPY
51438+ const char *type;
51439+
51440+ if (!n)
51441+ return;
51442+
51443+ type = check_heap_object(ptr, n);
51444+ if (!type) {
51445+ int ret = check_stack_object(ptr, n);
51446+ if (ret == 1 || ret == 2)
51447+ return;
51448+ if (ret == 0) {
51449+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
51450+ type = "<kernel text>";
51451+ else
51452+ return;
51453+ } else
51454+ type = "<process stack>";
51455+ }
51456+
51457+ pax_report_usercopy(ptr, n, to_user, type);
51458+#endif
51459+
51460+}
51461+EXPORT_SYMBOL(__check_object_size);
51462+
51463+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
51464+void pax_track_stack(void)
51465+{
51466+ unsigned long sp = (unsigned long)&sp;
51467+ if (sp < current_thread_info()->lowest_stack &&
51468+ sp > (unsigned long)task_stack_page(current))
51469+ current_thread_info()->lowest_stack = sp;
51470+}
51471+EXPORT_SYMBOL(pax_track_stack);
51472+#endif
51473+
51474+#ifdef CONFIG_PAX_SIZE_OVERFLOW
51475+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
51476+{
51477+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
51478+ dump_stack();
51479+ do_group_exit(SIGKILL);
51480+}
51481+EXPORT_SYMBOL(report_size_overflow);
51482+#endif
51483diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
51484index 9f9992b..8b59411 100644
51485--- a/fs/ext2/balloc.c
51486+++ b/fs/ext2/balloc.c
51487@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
51488
51489 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51490 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51491- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51492+ if (free_blocks < root_blocks + 1 &&
51493 !uid_eq(sbi->s_resuid, current_fsuid()) &&
51494 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51495- !in_group_p (sbi->s_resgid))) {
51496+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51497 return 0;
51498 }
51499 return 1;
51500diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
51501index 22548f5..41521d8 100644
51502--- a/fs/ext3/balloc.c
51503+++ b/fs/ext3/balloc.c
51504@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
51505
51506 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51507 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51508- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51509+ if (free_blocks < root_blocks + 1 &&
51510 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
51511 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51512- !in_group_p (sbi->s_resgid))) {
51513+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51514 return 0;
51515 }
51516 return 1;
51517diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
51518index 3742e4c..69a797f 100644
51519--- a/fs/ext4/balloc.c
51520+++ b/fs/ext4/balloc.c
51521@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
51522 /* Hm, nope. Are (enough) root reserved clusters available? */
51523 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
51524 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
51525- capable(CAP_SYS_RESOURCE) ||
51526- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
51527+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
51528+ capable_nolog(CAP_SYS_RESOURCE)) {
51529
51530 if (free_clusters >= (nclusters + dirty_clusters +
51531 resv_clusters))
51532diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
51533index 5aae3d1..b5da7f8 100644
51534--- a/fs/ext4/ext4.h
51535+++ b/fs/ext4/ext4.h
51536@@ -1252,19 +1252,19 @@ struct ext4_sb_info {
51537 unsigned long s_mb_last_start;
51538
51539 /* stats for buddy allocator */
51540- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
51541- atomic_t s_bal_success; /* we found long enough chunks */
51542- atomic_t s_bal_allocated; /* in blocks */
51543- atomic_t s_bal_ex_scanned; /* total extents scanned */
51544- atomic_t s_bal_goals; /* goal hits */
51545- atomic_t s_bal_breaks; /* too long searches */
51546- atomic_t s_bal_2orders; /* 2^order hits */
51547+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
51548+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
51549+ atomic_unchecked_t s_bal_allocated; /* in blocks */
51550+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
51551+ atomic_unchecked_t s_bal_goals; /* goal hits */
51552+ atomic_unchecked_t s_bal_breaks; /* too long searches */
51553+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
51554 spinlock_t s_bal_lock;
51555 unsigned long s_mb_buddies_generated;
51556 unsigned long long s_mb_generation_time;
51557- atomic_t s_mb_lost_chunks;
51558- atomic_t s_mb_preallocated;
51559- atomic_t s_mb_discarded;
51560+ atomic_unchecked_t s_mb_lost_chunks;
51561+ atomic_unchecked_t s_mb_preallocated;
51562+ atomic_unchecked_t s_mb_discarded;
51563 atomic_t s_lock_busy;
51564
51565 /* locality groups */
51566diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
51567index 59c6750..a549154 100644
51568--- a/fs/ext4/mballoc.c
51569+++ b/fs/ext4/mballoc.c
51570@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
51571 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
51572
51573 if (EXT4_SB(sb)->s_mb_stats)
51574- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
51575+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
51576
51577 break;
51578 }
51579@@ -2170,7 +2170,7 @@ repeat:
51580 ac->ac_status = AC_STATUS_CONTINUE;
51581 ac->ac_flags |= EXT4_MB_HINT_FIRST;
51582 cr = 3;
51583- atomic_inc(&sbi->s_mb_lost_chunks);
51584+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
51585 goto repeat;
51586 }
51587 }
51588@@ -2678,25 +2678,25 @@ int ext4_mb_release(struct super_block *sb)
51589 if (sbi->s_mb_stats) {
51590 ext4_msg(sb, KERN_INFO,
51591 "mballoc: %u blocks %u reqs (%u success)",
51592- atomic_read(&sbi->s_bal_allocated),
51593- atomic_read(&sbi->s_bal_reqs),
51594- atomic_read(&sbi->s_bal_success));
51595+ atomic_read_unchecked(&sbi->s_bal_allocated),
51596+ atomic_read_unchecked(&sbi->s_bal_reqs),
51597+ atomic_read_unchecked(&sbi->s_bal_success));
51598 ext4_msg(sb, KERN_INFO,
51599 "mballoc: %u extents scanned, %u goal hits, "
51600 "%u 2^N hits, %u breaks, %u lost",
51601- atomic_read(&sbi->s_bal_ex_scanned),
51602- atomic_read(&sbi->s_bal_goals),
51603- atomic_read(&sbi->s_bal_2orders),
51604- atomic_read(&sbi->s_bal_breaks),
51605- atomic_read(&sbi->s_mb_lost_chunks));
51606+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
51607+ atomic_read_unchecked(&sbi->s_bal_goals),
51608+ atomic_read_unchecked(&sbi->s_bal_2orders),
51609+ atomic_read_unchecked(&sbi->s_bal_breaks),
51610+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
51611 ext4_msg(sb, KERN_INFO,
51612 "mballoc: %lu generated and it took %Lu",
51613 sbi->s_mb_buddies_generated,
51614 sbi->s_mb_generation_time);
51615 ext4_msg(sb, KERN_INFO,
51616 "mballoc: %u preallocated, %u discarded",
51617- atomic_read(&sbi->s_mb_preallocated),
51618- atomic_read(&sbi->s_mb_discarded));
51619+ atomic_read_unchecked(&sbi->s_mb_preallocated),
51620+ atomic_read_unchecked(&sbi->s_mb_discarded));
51621 }
51622
51623 free_percpu(sbi->s_locality_groups);
51624@@ -3150,16 +3150,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
51625 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
51626
51627 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
51628- atomic_inc(&sbi->s_bal_reqs);
51629- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51630+ atomic_inc_unchecked(&sbi->s_bal_reqs);
51631+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51632 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
51633- atomic_inc(&sbi->s_bal_success);
51634- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
51635+ atomic_inc_unchecked(&sbi->s_bal_success);
51636+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
51637 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
51638 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
51639- atomic_inc(&sbi->s_bal_goals);
51640+ atomic_inc_unchecked(&sbi->s_bal_goals);
51641 if (ac->ac_found > sbi->s_mb_max_to_scan)
51642- atomic_inc(&sbi->s_bal_breaks);
51643+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51644 }
51645
51646 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51647@@ -3559,7 +3559,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51648 trace_ext4_mb_new_inode_pa(ac, pa);
51649
51650 ext4_mb_use_inode_pa(ac, pa);
51651- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51652+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51653
51654 ei = EXT4_I(ac->ac_inode);
51655 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51656@@ -3619,7 +3619,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51657 trace_ext4_mb_new_group_pa(ac, pa);
51658
51659 ext4_mb_use_group_pa(ac, pa);
51660- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51661+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51662
51663 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51664 lg = ac->ac_lg;
51665@@ -3708,7 +3708,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51666 * from the bitmap and continue.
51667 */
51668 }
51669- atomic_add(free, &sbi->s_mb_discarded);
51670+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51671
51672 return err;
51673 }
51674@@ -3726,7 +3726,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51675 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51676 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51677 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51678- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51679+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51680 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51681
51682 return 0;
51683diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
51684index 214461e..3614c89 100644
51685--- a/fs/ext4/mmp.c
51686+++ b/fs/ext4/mmp.c
51687@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
51688 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
51689 const char *function, unsigned int line, const char *msg)
51690 {
51691- __ext4_warning(sb, function, line, msg);
51692+ __ext4_warning(sb, function, line, "%s", msg);
51693 __ext4_warning(sb, function, line,
51694 "MMP failure info: last update time: %llu, last update "
51695 "node: %s, last update device: %s\n",
51696diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
51697index 49d3c01..9579efd 100644
51698--- a/fs/ext4/resize.c
51699+++ b/fs/ext4/resize.c
51700@@ -79,12 +79,20 @@ static int verify_group_input(struct super_block *sb,
51701 ext4_fsblk_t end = start + input->blocks_count;
51702 ext4_group_t group = input->group;
51703 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
51704- unsigned overhead = ext4_group_overhead_blocks(sb, group);
51705- ext4_fsblk_t metaend = start + overhead;
51706+ unsigned overhead;
51707+ ext4_fsblk_t metaend;
51708 struct buffer_head *bh = NULL;
51709 ext4_grpblk_t free_blocks_count, offset;
51710 int err = -EINVAL;
51711
51712+ if (group != sbi->s_groups_count) {
51713+ ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51714+ input->group, sbi->s_groups_count);
51715+ return -EINVAL;
51716+ }
51717+
51718+ overhead = ext4_group_overhead_blocks(sb, group);
51719+ metaend = start + overhead;
51720 input->free_blocks_count = free_blocks_count =
51721 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
51722
51723@@ -96,10 +104,7 @@ static int verify_group_input(struct super_block *sb,
51724 free_blocks_count, input->reserved_blocks);
51725
51726 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
51727- if (group != sbi->s_groups_count)
51728- ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51729- input->group, sbi->s_groups_count);
51730- else if (offset != 0)
51731+ if (offset != 0)
51732 ext4_warning(sb, "Last group not full");
51733 else if (input->reserved_blocks > input->blocks_count / 5)
51734 ext4_warning(sb, "Reserved blocks too high (%u)",
51735diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51736index 6681c03..d88cd33 100644
51737--- a/fs/ext4/super.c
51738+++ b/fs/ext4/super.c
51739@@ -1236,7 +1236,7 @@ static ext4_fsblk_t get_sb_block(void **data)
51740 }
51741
51742 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
51743-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
51744+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
51745 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
51746
51747 #ifdef CONFIG_QUOTA
51748@@ -2372,7 +2372,7 @@ struct ext4_attr {
51749 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51750 const char *, size_t);
51751 int offset;
51752-};
51753+} __do_const;
51754
51755 static int parse_strtoull(const char *buf,
51756 unsigned long long max, unsigned long long *value)
51757diff --git a/fs/fcntl.c b/fs/fcntl.c
51758index 6599222..e7bf0de 100644
51759--- a/fs/fcntl.c
51760+++ b/fs/fcntl.c
51761@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51762 if (err)
51763 return err;
51764
51765+ if (gr_handle_chroot_fowner(pid, type))
51766+ return -ENOENT;
51767+ if (gr_check_protected_task_fowner(pid, type))
51768+ return -EACCES;
51769+
51770 f_modown(filp, pid, type, force);
51771 return 0;
51772 }
51773diff --git a/fs/fhandle.c b/fs/fhandle.c
51774index 999ff5c..41f4109 100644
51775--- a/fs/fhandle.c
51776+++ b/fs/fhandle.c
51777@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51778 } else
51779 retval = 0;
51780 /* copy the mount id */
51781- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51782- sizeof(*mnt_id)) ||
51783+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51784 copy_to_user(ufh, handle,
51785 sizeof(struct file_handle) + handle_bytes))
51786 retval = -EFAULT;
51787diff --git a/fs/file.c b/fs/file.c
51788index 4a78f98..9447397 100644
51789--- a/fs/file.c
51790+++ b/fs/file.c
51791@@ -16,6 +16,7 @@
51792 #include <linux/slab.h>
51793 #include <linux/vmalloc.h>
51794 #include <linux/file.h>
51795+#include <linux/security.h>
51796 #include <linux/fdtable.h>
51797 #include <linux/bitops.h>
51798 #include <linux/interrupt.h>
51799@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51800 if (!file)
51801 return __close_fd(files, fd);
51802
51803+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51804 if (fd >= rlimit(RLIMIT_NOFILE))
51805 return -EBADF;
51806
51807@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51808 if (unlikely(oldfd == newfd))
51809 return -EINVAL;
51810
51811+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51812 if (newfd >= rlimit(RLIMIT_NOFILE))
51813 return -EBADF;
51814
51815@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51816 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51817 {
51818 int err;
51819+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51820 if (from >= rlimit(RLIMIT_NOFILE))
51821 return -EINVAL;
51822 err = alloc_fd(from, flags);
51823diff --git a/fs/filesystems.c b/fs/filesystems.c
51824index 92567d9..fcd8cbf 100644
51825--- a/fs/filesystems.c
51826+++ b/fs/filesystems.c
51827@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
51828 int len = dot ? dot - name : strlen(name);
51829
51830 fs = __get_fs_type(name, len);
51831+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51832+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
51833+#else
51834 if (!fs && (request_module("fs-%.*s", len, name) == 0))
51835+#endif
51836 fs = __get_fs_type(name, len);
51837
51838 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51839diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51840index d8ac61d..79a36f0 100644
51841--- a/fs/fs_struct.c
51842+++ b/fs/fs_struct.c
51843@@ -4,6 +4,7 @@
51844 #include <linux/path.h>
51845 #include <linux/slab.h>
51846 #include <linux/fs_struct.h>
51847+#include <linux/grsecurity.h>
51848 #include "internal.h"
51849
51850 /*
51851@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
51852 write_seqcount_begin(&fs->seq);
51853 old_root = fs->root;
51854 fs->root = *path;
51855+ gr_set_chroot_entries(current, path);
51856 write_seqcount_end(&fs->seq);
51857 spin_unlock(&fs->lock);
51858 if (old_root.dentry)
51859@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
51860 int hits = 0;
51861 spin_lock(&fs->lock);
51862 write_seqcount_begin(&fs->seq);
51863+ /* this root replacement is only done by pivot_root,
51864+ leave grsec's chroot tagging alone for this task
51865+ so that a pivoted root isn't treated as a chroot
51866+ */
51867 hits += replace_path(&fs->root, old_root, new_root);
51868 hits += replace_path(&fs->pwd, old_root, new_root);
51869 write_seqcount_end(&fs->seq);
51870@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
51871 task_lock(tsk);
51872 spin_lock(&fs->lock);
51873 tsk->fs = NULL;
51874- kill = !--fs->users;
51875+ gr_clear_chroot_entries(tsk);
51876+ kill = !atomic_dec_return(&fs->users);
51877 spin_unlock(&fs->lock);
51878 task_unlock(tsk);
51879 if (kill)
51880@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51881 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51882 /* We don't need to lock fs - think why ;-) */
51883 if (fs) {
51884- fs->users = 1;
51885+ atomic_set(&fs->users, 1);
51886 fs->in_exec = 0;
51887 spin_lock_init(&fs->lock);
51888 seqcount_init(&fs->seq);
51889@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51890 spin_lock(&old->lock);
51891 fs->root = old->root;
51892 path_get(&fs->root);
51893+ /* instead of calling gr_set_chroot_entries here,
51894+ we call it from every caller of this function
51895+ */
51896 fs->pwd = old->pwd;
51897 path_get(&fs->pwd);
51898 spin_unlock(&old->lock);
51899@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
51900
51901 task_lock(current);
51902 spin_lock(&fs->lock);
51903- kill = !--fs->users;
51904+ kill = !atomic_dec_return(&fs->users);
51905 current->fs = new_fs;
51906+ gr_set_chroot_entries(current, &new_fs->root);
51907 spin_unlock(&fs->lock);
51908 task_unlock(current);
51909
51910@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
51911
51912 int current_umask(void)
51913 {
51914- return current->fs->umask;
51915+ return current->fs->umask | gr_acl_umask();
51916 }
51917 EXPORT_SYMBOL(current_umask);
51918
51919 /* to be mentioned only in INIT_TASK */
51920 struct fs_struct init_fs = {
51921- .users = 1,
51922+ .users = ATOMIC_INIT(1),
51923 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
51924 .seq = SEQCNT_ZERO,
51925 .umask = 0022,
51926diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
51927index e2cba1f..17a25bb 100644
51928--- a/fs/fscache/cookie.c
51929+++ b/fs/fscache/cookie.c
51930@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
51931 parent ? (char *) parent->def->name : "<no-parent>",
51932 def->name, netfs_data);
51933
51934- fscache_stat(&fscache_n_acquires);
51935+ fscache_stat_unchecked(&fscache_n_acquires);
51936
51937 /* if there's no parent cookie, then we don't create one here either */
51938 if (!parent) {
51939- fscache_stat(&fscache_n_acquires_null);
51940+ fscache_stat_unchecked(&fscache_n_acquires_null);
51941 _leave(" [no parent]");
51942 return NULL;
51943 }
51944@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
51945 /* allocate and initialise a cookie */
51946 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
51947 if (!cookie) {
51948- fscache_stat(&fscache_n_acquires_oom);
51949+ fscache_stat_unchecked(&fscache_n_acquires_oom);
51950 _leave(" [ENOMEM]");
51951 return NULL;
51952 }
51953@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51954
51955 switch (cookie->def->type) {
51956 case FSCACHE_COOKIE_TYPE_INDEX:
51957- fscache_stat(&fscache_n_cookie_index);
51958+ fscache_stat_unchecked(&fscache_n_cookie_index);
51959 break;
51960 case FSCACHE_COOKIE_TYPE_DATAFILE:
51961- fscache_stat(&fscache_n_cookie_data);
51962+ fscache_stat_unchecked(&fscache_n_cookie_data);
51963 break;
51964 default:
51965- fscache_stat(&fscache_n_cookie_special);
51966+ fscache_stat_unchecked(&fscache_n_cookie_special);
51967 break;
51968 }
51969
51970@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51971 if (fscache_acquire_non_index_cookie(cookie) < 0) {
51972 atomic_dec(&parent->n_children);
51973 __fscache_cookie_put(cookie);
51974- fscache_stat(&fscache_n_acquires_nobufs);
51975+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
51976 _leave(" = NULL");
51977 return NULL;
51978 }
51979 }
51980
51981- fscache_stat(&fscache_n_acquires_ok);
51982+ fscache_stat_unchecked(&fscache_n_acquires_ok);
51983 _leave(" = %p", cookie);
51984 return cookie;
51985 }
51986@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
51987 cache = fscache_select_cache_for_object(cookie->parent);
51988 if (!cache) {
51989 up_read(&fscache_addremove_sem);
51990- fscache_stat(&fscache_n_acquires_no_cache);
51991+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
51992 _leave(" = -ENOMEDIUM [no cache]");
51993 return -ENOMEDIUM;
51994 }
51995@@ -255,12 +255,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
51996 object = cache->ops->alloc_object(cache, cookie);
51997 fscache_stat_d(&fscache_n_cop_alloc_object);
51998 if (IS_ERR(object)) {
51999- fscache_stat(&fscache_n_object_no_alloc);
52000+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
52001 ret = PTR_ERR(object);
52002 goto error;
52003 }
52004
52005- fscache_stat(&fscache_n_object_alloc);
52006+ fscache_stat_unchecked(&fscache_n_object_alloc);
52007
52008 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
52009
52010@@ -376,7 +376,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
52011
52012 _enter("{%s}", cookie->def->name);
52013
52014- fscache_stat(&fscache_n_invalidates);
52015+ fscache_stat_unchecked(&fscache_n_invalidates);
52016
52017 /* Only permit invalidation of data files. Invalidating an index will
52018 * require the caller to release all its attachments to the tree rooted
52019@@ -434,10 +434,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
52020 {
52021 struct fscache_object *object;
52022
52023- fscache_stat(&fscache_n_updates);
52024+ fscache_stat_unchecked(&fscache_n_updates);
52025
52026 if (!cookie) {
52027- fscache_stat(&fscache_n_updates_null);
52028+ fscache_stat_unchecked(&fscache_n_updates_null);
52029 _leave(" [no cookie]");
52030 return;
52031 }
52032@@ -471,12 +471,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52033 struct fscache_object *object;
52034 unsigned long event;
52035
52036- fscache_stat(&fscache_n_relinquishes);
52037+ fscache_stat_unchecked(&fscache_n_relinquishes);
52038 if (retire)
52039- fscache_stat(&fscache_n_relinquishes_retire);
52040+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
52041
52042 if (!cookie) {
52043- fscache_stat(&fscache_n_relinquishes_null);
52044+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
52045 _leave(" [no cookie]");
52046 return;
52047 }
52048@@ -492,7 +492,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52049
52050 /* wait for the cookie to finish being instantiated (or to fail) */
52051 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
52052- fscache_stat(&fscache_n_relinquishes_waitcrt);
52053+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
52054 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
52055 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
52056 }
52057diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
52058index ee38fef..0a326d4 100644
52059--- a/fs/fscache/internal.h
52060+++ b/fs/fscache/internal.h
52061@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
52062 * stats.c
52063 */
52064 #ifdef CONFIG_FSCACHE_STATS
52065-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52066-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52067+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52068+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52069
52070-extern atomic_t fscache_n_op_pend;
52071-extern atomic_t fscache_n_op_run;
52072-extern atomic_t fscache_n_op_enqueue;
52073-extern atomic_t fscache_n_op_deferred_release;
52074-extern atomic_t fscache_n_op_release;
52075-extern atomic_t fscache_n_op_gc;
52076-extern atomic_t fscache_n_op_cancelled;
52077-extern atomic_t fscache_n_op_rejected;
52078+extern atomic_unchecked_t fscache_n_op_pend;
52079+extern atomic_unchecked_t fscache_n_op_run;
52080+extern atomic_unchecked_t fscache_n_op_enqueue;
52081+extern atomic_unchecked_t fscache_n_op_deferred_release;
52082+extern atomic_unchecked_t fscache_n_op_release;
52083+extern atomic_unchecked_t fscache_n_op_gc;
52084+extern atomic_unchecked_t fscache_n_op_cancelled;
52085+extern atomic_unchecked_t fscache_n_op_rejected;
52086
52087-extern atomic_t fscache_n_attr_changed;
52088-extern atomic_t fscache_n_attr_changed_ok;
52089-extern atomic_t fscache_n_attr_changed_nobufs;
52090-extern atomic_t fscache_n_attr_changed_nomem;
52091-extern atomic_t fscache_n_attr_changed_calls;
52092+extern atomic_unchecked_t fscache_n_attr_changed;
52093+extern atomic_unchecked_t fscache_n_attr_changed_ok;
52094+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
52095+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
52096+extern atomic_unchecked_t fscache_n_attr_changed_calls;
52097
52098-extern atomic_t fscache_n_allocs;
52099-extern atomic_t fscache_n_allocs_ok;
52100-extern atomic_t fscache_n_allocs_wait;
52101-extern atomic_t fscache_n_allocs_nobufs;
52102-extern atomic_t fscache_n_allocs_intr;
52103-extern atomic_t fscache_n_allocs_object_dead;
52104-extern atomic_t fscache_n_alloc_ops;
52105-extern atomic_t fscache_n_alloc_op_waits;
52106+extern atomic_unchecked_t fscache_n_allocs;
52107+extern atomic_unchecked_t fscache_n_allocs_ok;
52108+extern atomic_unchecked_t fscache_n_allocs_wait;
52109+extern atomic_unchecked_t fscache_n_allocs_nobufs;
52110+extern atomic_unchecked_t fscache_n_allocs_intr;
52111+extern atomic_unchecked_t fscache_n_allocs_object_dead;
52112+extern atomic_unchecked_t fscache_n_alloc_ops;
52113+extern atomic_unchecked_t fscache_n_alloc_op_waits;
52114
52115-extern atomic_t fscache_n_retrievals;
52116-extern atomic_t fscache_n_retrievals_ok;
52117-extern atomic_t fscache_n_retrievals_wait;
52118-extern atomic_t fscache_n_retrievals_nodata;
52119-extern atomic_t fscache_n_retrievals_nobufs;
52120-extern atomic_t fscache_n_retrievals_intr;
52121-extern atomic_t fscache_n_retrievals_nomem;
52122-extern atomic_t fscache_n_retrievals_object_dead;
52123-extern atomic_t fscache_n_retrieval_ops;
52124-extern atomic_t fscache_n_retrieval_op_waits;
52125+extern atomic_unchecked_t fscache_n_retrievals;
52126+extern atomic_unchecked_t fscache_n_retrievals_ok;
52127+extern atomic_unchecked_t fscache_n_retrievals_wait;
52128+extern atomic_unchecked_t fscache_n_retrievals_nodata;
52129+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
52130+extern atomic_unchecked_t fscache_n_retrievals_intr;
52131+extern atomic_unchecked_t fscache_n_retrievals_nomem;
52132+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
52133+extern atomic_unchecked_t fscache_n_retrieval_ops;
52134+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
52135
52136-extern atomic_t fscache_n_stores;
52137-extern atomic_t fscache_n_stores_ok;
52138-extern atomic_t fscache_n_stores_again;
52139-extern atomic_t fscache_n_stores_nobufs;
52140-extern atomic_t fscache_n_stores_oom;
52141-extern atomic_t fscache_n_store_ops;
52142-extern atomic_t fscache_n_store_calls;
52143-extern atomic_t fscache_n_store_pages;
52144-extern atomic_t fscache_n_store_radix_deletes;
52145-extern atomic_t fscache_n_store_pages_over_limit;
52146+extern atomic_unchecked_t fscache_n_stores;
52147+extern atomic_unchecked_t fscache_n_stores_ok;
52148+extern atomic_unchecked_t fscache_n_stores_again;
52149+extern atomic_unchecked_t fscache_n_stores_nobufs;
52150+extern atomic_unchecked_t fscache_n_stores_oom;
52151+extern atomic_unchecked_t fscache_n_store_ops;
52152+extern atomic_unchecked_t fscache_n_store_calls;
52153+extern atomic_unchecked_t fscache_n_store_pages;
52154+extern atomic_unchecked_t fscache_n_store_radix_deletes;
52155+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
52156
52157-extern atomic_t fscache_n_store_vmscan_not_storing;
52158-extern atomic_t fscache_n_store_vmscan_gone;
52159-extern atomic_t fscache_n_store_vmscan_busy;
52160-extern atomic_t fscache_n_store_vmscan_cancelled;
52161-extern atomic_t fscache_n_store_vmscan_wait;
52162+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52163+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
52164+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
52165+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52166+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
52167
52168-extern atomic_t fscache_n_marks;
52169-extern atomic_t fscache_n_uncaches;
52170+extern atomic_unchecked_t fscache_n_marks;
52171+extern atomic_unchecked_t fscache_n_uncaches;
52172
52173-extern atomic_t fscache_n_acquires;
52174-extern atomic_t fscache_n_acquires_null;
52175-extern atomic_t fscache_n_acquires_no_cache;
52176-extern atomic_t fscache_n_acquires_ok;
52177-extern atomic_t fscache_n_acquires_nobufs;
52178-extern atomic_t fscache_n_acquires_oom;
52179+extern atomic_unchecked_t fscache_n_acquires;
52180+extern atomic_unchecked_t fscache_n_acquires_null;
52181+extern atomic_unchecked_t fscache_n_acquires_no_cache;
52182+extern atomic_unchecked_t fscache_n_acquires_ok;
52183+extern atomic_unchecked_t fscache_n_acquires_nobufs;
52184+extern atomic_unchecked_t fscache_n_acquires_oom;
52185
52186-extern atomic_t fscache_n_invalidates;
52187-extern atomic_t fscache_n_invalidates_run;
52188+extern atomic_unchecked_t fscache_n_invalidates;
52189+extern atomic_unchecked_t fscache_n_invalidates_run;
52190
52191-extern atomic_t fscache_n_updates;
52192-extern atomic_t fscache_n_updates_null;
52193-extern atomic_t fscache_n_updates_run;
52194+extern atomic_unchecked_t fscache_n_updates;
52195+extern atomic_unchecked_t fscache_n_updates_null;
52196+extern atomic_unchecked_t fscache_n_updates_run;
52197
52198-extern atomic_t fscache_n_relinquishes;
52199-extern atomic_t fscache_n_relinquishes_null;
52200-extern atomic_t fscache_n_relinquishes_waitcrt;
52201-extern atomic_t fscache_n_relinquishes_retire;
52202+extern atomic_unchecked_t fscache_n_relinquishes;
52203+extern atomic_unchecked_t fscache_n_relinquishes_null;
52204+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52205+extern atomic_unchecked_t fscache_n_relinquishes_retire;
52206
52207-extern atomic_t fscache_n_cookie_index;
52208-extern atomic_t fscache_n_cookie_data;
52209-extern atomic_t fscache_n_cookie_special;
52210+extern atomic_unchecked_t fscache_n_cookie_index;
52211+extern atomic_unchecked_t fscache_n_cookie_data;
52212+extern atomic_unchecked_t fscache_n_cookie_special;
52213
52214-extern atomic_t fscache_n_object_alloc;
52215-extern atomic_t fscache_n_object_no_alloc;
52216-extern atomic_t fscache_n_object_lookups;
52217-extern atomic_t fscache_n_object_lookups_negative;
52218-extern atomic_t fscache_n_object_lookups_positive;
52219-extern atomic_t fscache_n_object_lookups_timed_out;
52220-extern atomic_t fscache_n_object_created;
52221-extern atomic_t fscache_n_object_avail;
52222-extern atomic_t fscache_n_object_dead;
52223+extern atomic_unchecked_t fscache_n_object_alloc;
52224+extern atomic_unchecked_t fscache_n_object_no_alloc;
52225+extern atomic_unchecked_t fscache_n_object_lookups;
52226+extern atomic_unchecked_t fscache_n_object_lookups_negative;
52227+extern atomic_unchecked_t fscache_n_object_lookups_positive;
52228+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
52229+extern atomic_unchecked_t fscache_n_object_created;
52230+extern atomic_unchecked_t fscache_n_object_avail;
52231+extern atomic_unchecked_t fscache_n_object_dead;
52232
52233-extern atomic_t fscache_n_checkaux_none;
52234-extern atomic_t fscache_n_checkaux_okay;
52235-extern atomic_t fscache_n_checkaux_update;
52236-extern atomic_t fscache_n_checkaux_obsolete;
52237+extern atomic_unchecked_t fscache_n_checkaux_none;
52238+extern atomic_unchecked_t fscache_n_checkaux_okay;
52239+extern atomic_unchecked_t fscache_n_checkaux_update;
52240+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
52241
52242 extern atomic_t fscache_n_cop_alloc_object;
52243 extern atomic_t fscache_n_cop_lookup_object;
52244@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
52245 atomic_inc(stat);
52246 }
52247
52248+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
52249+{
52250+ atomic_inc_unchecked(stat);
52251+}
52252+
52253 static inline void fscache_stat_d(atomic_t *stat)
52254 {
52255 atomic_dec(stat);
52256@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
52257
52258 #define __fscache_stat(stat) (NULL)
52259 #define fscache_stat(stat) do {} while (0)
52260+#define fscache_stat_unchecked(stat) do {} while (0)
52261 #define fscache_stat_d(stat) do {} while (0)
52262 #endif
52263
52264diff --git a/fs/fscache/object.c b/fs/fscache/object.c
52265index 50d41c1..10ee117 100644
52266--- a/fs/fscache/object.c
52267+++ b/fs/fscache/object.c
52268@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52269 /* Invalidate an object on disk */
52270 case FSCACHE_OBJECT_INVALIDATING:
52271 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
52272- fscache_stat(&fscache_n_invalidates_run);
52273+ fscache_stat_unchecked(&fscache_n_invalidates_run);
52274 fscache_stat(&fscache_n_cop_invalidate_object);
52275 fscache_invalidate_object(object);
52276 fscache_stat_d(&fscache_n_cop_invalidate_object);
52277@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52278 /* update the object metadata on disk */
52279 case FSCACHE_OBJECT_UPDATING:
52280 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
52281- fscache_stat(&fscache_n_updates_run);
52282+ fscache_stat_unchecked(&fscache_n_updates_run);
52283 fscache_stat(&fscache_n_cop_update_object);
52284 object->cache->ops->update_object(object);
52285 fscache_stat_d(&fscache_n_cop_update_object);
52286@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52287 spin_lock(&object->lock);
52288 object->state = FSCACHE_OBJECT_DEAD;
52289 spin_unlock(&object->lock);
52290- fscache_stat(&fscache_n_object_dead);
52291+ fscache_stat_unchecked(&fscache_n_object_dead);
52292 goto terminal_transit;
52293
52294 /* handle the parent cache of this object being withdrawn from
52295@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52296 spin_lock(&object->lock);
52297 object->state = FSCACHE_OBJECT_DEAD;
52298 spin_unlock(&object->lock);
52299- fscache_stat(&fscache_n_object_dead);
52300+ fscache_stat_unchecked(&fscache_n_object_dead);
52301 goto terminal_transit;
52302
52303 /* complain about the object being woken up once it is
52304@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52305 parent->cookie->def->name, cookie->def->name,
52306 object->cache->tag->name);
52307
52308- fscache_stat(&fscache_n_object_lookups);
52309+ fscache_stat_unchecked(&fscache_n_object_lookups);
52310 fscache_stat(&fscache_n_cop_lookup_object);
52311 ret = object->cache->ops->lookup_object(object);
52312 fscache_stat_d(&fscache_n_cop_lookup_object);
52313@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52314 if (ret == -ETIMEDOUT) {
52315 /* probably stuck behind another object, so move this one to
52316 * the back of the queue */
52317- fscache_stat(&fscache_n_object_lookups_timed_out);
52318+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
52319 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52320 }
52321
52322@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
52323
52324 spin_lock(&object->lock);
52325 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52326- fscache_stat(&fscache_n_object_lookups_negative);
52327+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
52328
52329 /* transit here to allow write requests to begin stacking up
52330 * and read requests to begin returning ENODATA */
52331@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
52332 * result, in which case there may be data available */
52333 spin_lock(&object->lock);
52334 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52335- fscache_stat(&fscache_n_object_lookups_positive);
52336+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
52337
52338 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
52339
52340@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
52341 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52342 } else {
52343 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
52344- fscache_stat(&fscache_n_object_created);
52345+ fscache_stat_unchecked(&fscache_n_object_created);
52346
52347 object->state = FSCACHE_OBJECT_AVAILABLE;
52348 spin_unlock(&object->lock);
52349@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
52350 fscache_enqueue_dependents(object);
52351
52352 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
52353- fscache_stat(&fscache_n_object_avail);
52354+ fscache_stat_unchecked(&fscache_n_object_avail);
52355
52356 _leave("");
52357 }
52358@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52359 enum fscache_checkaux result;
52360
52361 if (!object->cookie->def->check_aux) {
52362- fscache_stat(&fscache_n_checkaux_none);
52363+ fscache_stat_unchecked(&fscache_n_checkaux_none);
52364 return FSCACHE_CHECKAUX_OKAY;
52365 }
52366
52367@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52368 switch (result) {
52369 /* entry okay as is */
52370 case FSCACHE_CHECKAUX_OKAY:
52371- fscache_stat(&fscache_n_checkaux_okay);
52372+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
52373 break;
52374
52375 /* entry requires update */
52376 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
52377- fscache_stat(&fscache_n_checkaux_update);
52378+ fscache_stat_unchecked(&fscache_n_checkaux_update);
52379 break;
52380
52381 /* entry requires deletion */
52382 case FSCACHE_CHECKAUX_OBSOLETE:
52383- fscache_stat(&fscache_n_checkaux_obsolete);
52384+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
52385 break;
52386
52387 default:
52388diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
52389index 762a9ec..2023284 100644
52390--- a/fs/fscache/operation.c
52391+++ b/fs/fscache/operation.c
52392@@ -17,7 +17,7 @@
52393 #include <linux/slab.h>
52394 #include "internal.h"
52395
52396-atomic_t fscache_op_debug_id;
52397+atomic_unchecked_t fscache_op_debug_id;
52398 EXPORT_SYMBOL(fscache_op_debug_id);
52399
52400 /**
52401@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
52402 ASSERTCMP(atomic_read(&op->usage), >, 0);
52403 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
52404
52405- fscache_stat(&fscache_n_op_enqueue);
52406+ fscache_stat_unchecked(&fscache_n_op_enqueue);
52407 switch (op->flags & FSCACHE_OP_TYPE) {
52408 case FSCACHE_OP_ASYNC:
52409 _debug("queue async");
52410@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
52411 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
52412 if (op->processor)
52413 fscache_enqueue_operation(op);
52414- fscache_stat(&fscache_n_op_run);
52415+ fscache_stat_unchecked(&fscache_n_op_run);
52416 }
52417
52418 /*
52419@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52420 if (object->n_in_progress > 0) {
52421 atomic_inc(&op->usage);
52422 list_add_tail(&op->pend_link, &object->pending_ops);
52423- fscache_stat(&fscache_n_op_pend);
52424+ fscache_stat_unchecked(&fscache_n_op_pend);
52425 } else if (!list_empty(&object->pending_ops)) {
52426 atomic_inc(&op->usage);
52427 list_add_tail(&op->pend_link, &object->pending_ops);
52428- fscache_stat(&fscache_n_op_pend);
52429+ fscache_stat_unchecked(&fscache_n_op_pend);
52430 fscache_start_operations(object);
52431 } else {
52432 ASSERTCMP(object->n_in_progress, ==, 0);
52433@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52434 object->n_exclusive++; /* reads and writes must wait */
52435 atomic_inc(&op->usage);
52436 list_add_tail(&op->pend_link, &object->pending_ops);
52437- fscache_stat(&fscache_n_op_pend);
52438+ fscache_stat_unchecked(&fscache_n_op_pend);
52439 ret = 0;
52440 } else {
52441 /* If we're in any other state, there must have been an I/O
52442@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
52443 if (object->n_exclusive > 0) {
52444 atomic_inc(&op->usage);
52445 list_add_tail(&op->pend_link, &object->pending_ops);
52446- fscache_stat(&fscache_n_op_pend);
52447+ fscache_stat_unchecked(&fscache_n_op_pend);
52448 } else if (!list_empty(&object->pending_ops)) {
52449 atomic_inc(&op->usage);
52450 list_add_tail(&op->pend_link, &object->pending_ops);
52451- fscache_stat(&fscache_n_op_pend);
52452+ fscache_stat_unchecked(&fscache_n_op_pend);
52453 fscache_start_operations(object);
52454 } else {
52455 ASSERTCMP(object->n_exclusive, ==, 0);
52456@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
52457 object->n_ops++;
52458 atomic_inc(&op->usage);
52459 list_add_tail(&op->pend_link, &object->pending_ops);
52460- fscache_stat(&fscache_n_op_pend);
52461+ fscache_stat_unchecked(&fscache_n_op_pend);
52462 ret = 0;
52463 } else if (object->state == FSCACHE_OBJECT_DYING ||
52464 object->state == FSCACHE_OBJECT_LC_DYING ||
52465 object->state == FSCACHE_OBJECT_WITHDRAWING) {
52466- fscache_stat(&fscache_n_op_rejected);
52467+ fscache_stat_unchecked(&fscache_n_op_rejected);
52468 op->state = FSCACHE_OP_ST_CANCELLED;
52469 ret = -ENOBUFS;
52470 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
52471@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
52472 ret = -EBUSY;
52473 if (op->state == FSCACHE_OP_ST_PENDING) {
52474 ASSERT(!list_empty(&op->pend_link));
52475- fscache_stat(&fscache_n_op_cancelled);
52476+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52477 list_del_init(&op->pend_link);
52478 if (do_cancel)
52479 do_cancel(op);
52480@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
52481 while (!list_empty(&object->pending_ops)) {
52482 op = list_entry(object->pending_ops.next,
52483 struct fscache_operation, pend_link);
52484- fscache_stat(&fscache_n_op_cancelled);
52485+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52486 list_del_init(&op->pend_link);
52487
52488 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
52489@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
52490 op->state, ==, FSCACHE_OP_ST_CANCELLED);
52491 op->state = FSCACHE_OP_ST_DEAD;
52492
52493- fscache_stat(&fscache_n_op_release);
52494+ fscache_stat_unchecked(&fscache_n_op_release);
52495
52496 if (op->release) {
52497 op->release(op);
52498@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
52499 * lock, and defer it otherwise */
52500 if (!spin_trylock(&object->lock)) {
52501 _debug("defer put");
52502- fscache_stat(&fscache_n_op_deferred_release);
52503+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
52504
52505 cache = object->cache;
52506 spin_lock(&cache->op_gc_list_lock);
52507@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
52508
52509 _debug("GC DEFERRED REL OBJ%x OP%x",
52510 object->debug_id, op->debug_id);
52511- fscache_stat(&fscache_n_op_gc);
52512+ fscache_stat_unchecked(&fscache_n_op_gc);
52513
52514 ASSERTCMP(atomic_read(&op->usage), ==, 0);
52515 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
52516diff --git a/fs/fscache/page.c b/fs/fscache/page.c
52517index ff000e5..c44ec6d 100644
52518--- a/fs/fscache/page.c
52519+++ b/fs/fscache/page.c
52520@@ -61,7 +61,7 @@ try_again:
52521 val = radix_tree_lookup(&cookie->stores, page->index);
52522 if (!val) {
52523 rcu_read_unlock();
52524- fscache_stat(&fscache_n_store_vmscan_not_storing);
52525+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
52526 __fscache_uncache_page(cookie, page);
52527 return true;
52528 }
52529@@ -91,11 +91,11 @@ try_again:
52530 spin_unlock(&cookie->stores_lock);
52531
52532 if (xpage) {
52533- fscache_stat(&fscache_n_store_vmscan_cancelled);
52534- fscache_stat(&fscache_n_store_radix_deletes);
52535+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
52536+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52537 ASSERTCMP(xpage, ==, page);
52538 } else {
52539- fscache_stat(&fscache_n_store_vmscan_gone);
52540+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
52541 }
52542
52543 wake_up_bit(&cookie->flags, 0);
52544@@ -110,11 +110,11 @@ page_busy:
52545 * sleeping on memory allocation, so we may need to impose a timeout
52546 * too. */
52547 if (!(gfp & __GFP_WAIT)) {
52548- fscache_stat(&fscache_n_store_vmscan_busy);
52549+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
52550 return false;
52551 }
52552
52553- fscache_stat(&fscache_n_store_vmscan_wait);
52554+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
52555 __fscache_wait_on_page_write(cookie, page);
52556 gfp &= ~__GFP_WAIT;
52557 goto try_again;
52558@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
52559 FSCACHE_COOKIE_STORING_TAG);
52560 if (!radix_tree_tag_get(&cookie->stores, page->index,
52561 FSCACHE_COOKIE_PENDING_TAG)) {
52562- fscache_stat(&fscache_n_store_radix_deletes);
52563+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52564 xpage = radix_tree_delete(&cookie->stores, page->index);
52565 }
52566 spin_unlock(&cookie->stores_lock);
52567@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
52568
52569 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
52570
52571- fscache_stat(&fscache_n_attr_changed_calls);
52572+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
52573
52574 if (fscache_object_is_active(object)) {
52575 fscache_stat(&fscache_n_cop_attr_changed);
52576@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52577
52578 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52579
52580- fscache_stat(&fscache_n_attr_changed);
52581+ fscache_stat_unchecked(&fscache_n_attr_changed);
52582
52583 op = kzalloc(sizeof(*op), GFP_KERNEL);
52584 if (!op) {
52585- fscache_stat(&fscache_n_attr_changed_nomem);
52586+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
52587 _leave(" = -ENOMEM");
52588 return -ENOMEM;
52589 }
52590@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52591 if (fscache_submit_exclusive_op(object, op) < 0)
52592 goto nobufs;
52593 spin_unlock(&cookie->lock);
52594- fscache_stat(&fscache_n_attr_changed_ok);
52595+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
52596 fscache_put_operation(op);
52597 _leave(" = 0");
52598 return 0;
52599@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52600 nobufs:
52601 spin_unlock(&cookie->lock);
52602 kfree(op);
52603- fscache_stat(&fscache_n_attr_changed_nobufs);
52604+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
52605 _leave(" = %d", -ENOBUFS);
52606 return -ENOBUFS;
52607 }
52608@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52609 /* allocate a retrieval operation and attempt to submit it */
52610 op = kzalloc(sizeof(*op), GFP_NOIO);
52611 if (!op) {
52612- fscache_stat(&fscache_n_retrievals_nomem);
52613+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52614 return NULL;
52615 }
52616
52617@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52618 return 0;
52619 }
52620
52621- fscache_stat(&fscache_n_retrievals_wait);
52622+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52623
52624 jif = jiffies;
52625 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52626 fscache_wait_bit_interruptible,
52627 TASK_INTERRUPTIBLE) != 0) {
52628- fscache_stat(&fscache_n_retrievals_intr);
52629+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52630 _leave(" = -ERESTARTSYS");
52631 return -ERESTARTSYS;
52632 }
52633@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52634 */
52635 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52636 struct fscache_retrieval *op,
52637- atomic_t *stat_op_waits,
52638- atomic_t *stat_object_dead)
52639+ atomic_unchecked_t *stat_op_waits,
52640+ atomic_unchecked_t *stat_object_dead)
52641 {
52642 int ret;
52643
52644@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52645 goto check_if_dead;
52646
52647 _debug(">>> WT");
52648- fscache_stat(stat_op_waits);
52649+ fscache_stat_unchecked(stat_op_waits);
52650 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52651 fscache_wait_bit_interruptible,
52652 TASK_INTERRUPTIBLE) != 0) {
52653@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52654
52655 check_if_dead:
52656 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52657- fscache_stat(stat_object_dead);
52658+ fscache_stat_unchecked(stat_object_dead);
52659 _leave(" = -ENOBUFS [cancelled]");
52660 return -ENOBUFS;
52661 }
52662 if (unlikely(fscache_object_is_dead(object))) {
52663 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52664 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52665- fscache_stat(stat_object_dead);
52666+ fscache_stat_unchecked(stat_object_dead);
52667 return -ENOBUFS;
52668 }
52669 return 0;
52670@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52671
52672 _enter("%p,%p,,,", cookie, page);
52673
52674- fscache_stat(&fscache_n_retrievals);
52675+ fscache_stat_unchecked(&fscache_n_retrievals);
52676
52677 if (hlist_empty(&cookie->backing_objects))
52678 goto nobufs;
52679@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52680 goto nobufs_unlock_dec;
52681 spin_unlock(&cookie->lock);
52682
52683- fscache_stat(&fscache_n_retrieval_ops);
52684+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52685
52686 /* pin the netfs read context in case we need to do the actual netfs
52687 * read because we've encountered a cache read failure */
52688@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52689
52690 error:
52691 if (ret == -ENOMEM)
52692- fscache_stat(&fscache_n_retrievals_nomem);
52693+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52694 else if (ret == -ERESTARTSYS)
52695- fscache_stat(&fscache_n_retrievals_intr);
52696+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52697 else if (ret == -ENODATA)
52698- fscache_stat(&fscache_n_retrievals_nodata);
52699+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52700 else if (ret < 0)
52701- fscache_stat(&fscache_n_retrievals_nobufs);
52702+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52703 else
52704- fscache_stat(&fscache_n_retrievals_ok);
52705+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52706
52707 fscache_put_retrieval(op);
52708 _leave(" = %d", ret);
52709@@ -467,7 +467,7 @@ nobufs_unlock:
52710 spin_unlock(&cookie->lock);
52711 kfree(op);
52712 nobufs:
52713- fscache_stat(&fscache_n_retrievals_nobufs);
52714+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52715 _leave(" = -ENOBUFS");
52716 return -ENOBUFS;
52717 }
52718@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52719
52720 _enter("%p,,%d,,,", cookie, *nr_pages);
52721
52722- fscache_stat(&fscache_n_retrievals);
52723+ fscache_stat_unchecked(&fscache_n_retrievals);
52724
52725 if (hlist_empty(&cookie->backing_objects))
52726 goto nobufs;
52727@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52728 goto nobufs_unlock_dec;
52729 spin_unlock(&cookie->lock);
52730
52731- fscache_stat(&fscache_n_retrieval_ops);
52732+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52733
52734 /* pin the netfs read context in case we need to do the actual netfs
52735 * read because we've encountered a cache read failure */
52736@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52737
52738 error:
52739 if (ret == -ENOMEM)
52740- fscache_stat(&fscache_n_retrievals_nomem);
52741+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52742 else if (ret == -ERESTARTSYS)
52743- fscache_stat(&fscache_n_retrievals_intr);
52744+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52745 else if (ret == -ENODATA)
52746- fscache_stat(&fscache_n_retrievals_nodata);
52747+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52748 else if (ret < 0)
52749- fscache_stat(&fscache_n_retrievals_nobufs);
52750+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52751 else
52752- fscache_stat(&fscache_n_retrievals_ok);
52753+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52754
52755 fscache_put_retrieval(op);
52756 _leave(" = %d", ret);
52757@@ -591,7 +591,7 @@ nobufs_unlock:
52758 spin_unlock(&cookie->lock);
52759 kfree(op);
52760 nobufs:
52761- fscache_stat(&fscache_n_retrievals_nobufs);
52762+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52763 _leave(" = -ENOBUFS");
52764 return -ENOBUFS;
52765 }
52766@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52767
52768 _enter("%p,%p,,,", cookie, page);
52769
52770- fscache_stat(&fscache_n_allocs);
52771+ fscache_stat_unchecked(&fscache_n_allocs);
52772
52773 if (hlist_empty(&cookie->backing_objects))
52774 goto nobufs;
52775@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52776 goto nobufs_unlock;
52777 spin_unlock(&cookie->lock);
52778
52779- fscache_stat(&fscache_n_alloc_ops);
52780+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52781
52782 ret = fscache_wait_for_retrieval_activation(
52783 object, op,
52784@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52785
52786 error:
52787 if (ret == -ERESTARTSYS)
52788- fscache_stat(&fscache_n_allocs_intr);
52789+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52790 else if (ret < 0)
52791- fscache_stat(&fscache_n_allocs_nobufs);
52792+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52793 else
52794- fscache_stat(&fscache_n_allocs_ok);
52795+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52796
52797 fscache_put_retrieval(op);
52798 _leave(" = %d", ret);
52799@@ -677,7 +677,7 @@ nobufs_unlock:
52800 spin_unlock(&cookie->lock);
52801 kfree(op);
52802 nobufs:
52803- fscache_stat(&fscache_n_allocs_nobufs);
52804+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52805 _leave(" = -ENOBUFS");
52806 return -ENOBUFS;
52807 }
52808@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52809
52810 spin_lock(&cookie->stores_lock);
52811
52812- fscache_stat(&fscache_n_store_calls);
52813+ fscache_stat_unchecked(&fscache_n_store_calls);
52814
52815 /* find a page to store */
52816 page = NULL;
52817@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52818 page = results[0];
52819 _debug("gang %d [%lx]", n, page->index);
52820 if (page->index > op->store_limit) {
52821- fscache_stat(&fscache_n_store_pages_over_limit);
52822+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52823 goto superseded;
52824 }
52825
52826@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52827 spin_unlock(&cookie->stores_lock);
52828 spin_unlock(&object->lock);
52829
52830- fscache_stat(&fscache_n_store_pages);
52831+ fscache_stat_unchecked(&fscache_n_store_pages);
52832 fscache_stat(&fscache_n_cop_write_page);
52833 ret = object->cache->ops->write_page(op, page);
52834 fscache_stat_d(&fscache_n_cop_write_page);
52835@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52836 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52837 ASSERT(PageFsCache(page));
52838
52839- fscache_stat(&fscache_n_stores);
52840+ fscache_stat_unchecked(&fscache_n_stores);
52841
52842 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52843 _leave(" = -ENOBUFS [invalidating]");
52844@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52845 spin_unlock(&cookie->stores_lock);
52846 spin_unlock(&object->lock);
52847
52848- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52849+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52850 op->store_limit = object->store_limit;
52851
52852 if (fscache_submit_op(object, &op->op) < 0)
52853@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52854
52855 spin_unlock(&cookie->lock);
52856 radix_tree_preload_end();
52857- fscache_stat(&fscache_n_store_ops);
52858- fscache_stat(&fscache_n_stores_ok);
52859+ fscache_stat_unchecked(&fscache_n_store_ops);
52860+ fscache_stat_unchecked(&fscache_n_stores_ok);
52861
52862 /* the work queue now carries its own ref on the object */
52863 fscache_put_operation(&op->op);
52864@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52865 return 0;
52866
52867 already_queued:
52868- fscache_stat(&fscache_n_stores_again);
52869+ fscache_stat_unchecked(&fscache_n_stores_again);
52870 already_pending:
52871 spin_unlock(&cookie->stores_lock);
52872 spin_unlock(&object->lock);
52873 spin_unlock(&cookie->lock);
52874 radix_tree_preload_end();
52875 kfree(op);
52876- fscache_stat(&fscache_n_stores_ok);
52877+ fscache_stat_unchecked(&fscache_n_stores_ok);
52878 _leave(" = 0");
52879 return 0;
52880
52881@@ -959,14 +959,14 @@ nobufs:
52882 spin_unlock(&cookie->lock);
52883 radix_tree_preload_end();
52884 kfree(op);
52885- fscache_stat(&fscache_n_stores_nobufs);
52886+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52887 _leave(" = -ENOBUFS");
52888 return -ENOBUFS;
52889
52890 nomem_free:
52891 kfree(op);
52892 nomem:
52893- fscache_stat(&fscache_n_stores_oom);
52894+ fscache_stat_unchecked(&fscache_n_stores_oom);
52895 _leave(" = -ENOMEM");
52896 return -ENOMEM;
52897 }
52898@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52899 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52900 ASSERTCMP(page, !=, NULL);
52901
52902- fscache_stat(&fscache_n_uncaches);
52903+ fscache_stat_unchecked(&fscache_n_uncaches);
52904
52905 /* cache withdrawal may beat us to it */
52906 if (!PageFsCache(page))
52907@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52908 struct fscache_cookie *cookie = op->op.object->cookie;
52909
52910 #ifdef CONFIG_FSCACHE_STATS
52911- atomic_inc(&fscache_n_marks);
52912+ atomic_inc_unchecked(&fscache_n_marks);
52913 #endif
52914
52915 _debug("- mark %p{%lx}", page, page->index);
52916diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
52917index 40d13c7..ddf52b9 100644
52918--- a/fs/fscache/stats.c
52919+++ b/fs/fscache/stats.c
52920@@ -18,99 +18,99 @@
52921 /*
52922 * operation counters
52923 */
52924-atomic_t fscache_n_op_pend;
52925-atomic_t fscache_n_op_run;
52926-atomic_t fscache_n_op_enqueue;
52927-atomic_t fscache_n_op_requeue;
52928-atomic_t fscache_n_op_deferred_release;
52929-atomic_t fscache_n_op_release;
52930-atomic_t fscache_n_op_gc;
52931-atomic_t fscache_n_op_cancelled;
52932-atomic_t fscache_n_op_rejected;
52933+atomic_unchecked_t fscache_n_op_pend;
52934+atomic_unchecked_t fscache_n_op_run;
52935+atomic_unchecked_t fscache_n_op_enqueue;
52936+atomic_unchecked_t fscache_n_op_requeue;
52937+atomic_unchecked_t fscache_n_op_deferred_release;
52938+atomic_unchecked_t fscache_n_op_release;
52939+atomic_unchecked_t fscache_n_op_gc;
52940+atomic_unchecked_t fscache_n_op_cancelled;
52941+atomic_unchecked_t fscache_n_op_rejected;
52942
52943-atomic_t fscache_n_attr_changed;
52944-atomic_t fscache_n_attr_changed_ok;
52945-atomic_t fscache_n_attr_changed_nobufs;
52946-atomic_t fscache_n_attr_changed_nomem;
52947-atomic_t fscache_n_attr_changed_calls;
52948+atomic_unchecked_t fscache_n_attr_changed;
52949+atomic_unchecked_t fscache_n_attr_changed_ok;
52950+atomic_unchecked_t fscache_n_attr_changed_nobufs;
52951+atomic_unchecked_t fscache_n_attr_changed_nomem;
52952+atomic_unchecked_t fscache_n_attr_changed_calls;
52953
52954-atomic_t fscache_n_allocs;
52955-atomic_t fscache_n_allocs_ok;
52956-atomic_t fscache_n_allocs_wait;
52957-atomic_t fscache_n_allocs_nobufs;
52958-atomic_t fscache_n_allocs_intr;
52959-atomic_t fscache_n_allocs_object_dead;
52960-atomic_t fscache_n_alloc_ops;
52961-atomic_t fscache_n_alloc_op_waits;
52962+atomic_unchecked_t fscache_n_allocs;
52963+atomic_unchecked_t fscache_n_allocs_ok;
52964+atomic_unchecked_t fscache_n_allocs_wait;
52965+atomic_unchecked_t fscache_n_allocs_nobufs;
52966+atomic_unchecked_t fscache_n_allocs_intr;
52967+atomic_unchecked_t fscache_n_allocs_object_dead;
52968+atomic_unchecked_t fscache_n_alloc_ops;
52969+atomic_unchecked_t fscache_n_alloc_op_waits;
52970
52971-atomic_t fscache_n_retrievals;
52972-atomic_t fscache_n_retrievals_ok;
52973-atomic_t fscache_n_retrievals_wait;
52974-atomic_t fscache_n_retrievals_nodata;
52975-atomic_t fscache_n_retrievals_nobufs;
52976-atomic_t fscache_n_retrievals_intr;
52977-atomic_t fscache_n_retrievals_nomem;
52978-atomic_t fscache_n_retrievals_object_dead;
52979-atomic_t fscache_n_retrieval_ops;
52980-atomic_t fscache_n_retrieval_op_waits;
52981+atomic_unchecked_t fscache_n_retrievals;
52982+atomic_unchecked_t fscache_n_retrievals_ok;
52983+atomic_unchecked_t fscache_n_retrievals_wait;
52984+atomic_unchecked_t fscache_n_retrievals_nodata;
52985+atomic_unchecked_t fscache_n_retrievals_nobufs;
52986+atomic_unchecked_t fscache_n_retrievals_intr;
52987+atomic_unchecked_t fscache_n_retrievals_nomem;
52988+atomic_unchecked_t fscache_n_retrievals_object_dead;
52989+atomic_unchecked_t fscache_n_retrieval_ops;
52990+atomic_unchecked_t fscache_n_retrieval_op_waits;
52991
52992-atomic_t fscache_n_stores;
52993-atomic_t fscache_n_stores_ok;
52994-atomic_t fscache_n_stores_again;
52995-atomic_t fscache_n_stores_nobufs;
52996-atomic_t fscache_n_stores_oom;
52997-atomic_t fscache_n_store_ops;
52998-atomic_t fscache_n_store_calls;
52999-atomic_t fscache_n_store_pages;
53000-atomic_t fscache_n_store_radix_deletes;
53001-atomic_t fscache_n_store_pages_over_limit;
53002+atomic_unchecked_t fscache_n_stores;
53003+atomic_unchecked_t fscache_n_stores_ok;
53004+atomic_unchecked_t fscache_n_stores_again;
53005+atomic_unchecked_t fscache_n_stores_nobufs;
53006+atomic_unchecked_t fscache_n_stores_oom;
53007+atomic_unchecked_t fscache_n_store_ops;
53008+atomic_unchecked_t fscache_n_store_calls;
53009+atomic_unchecked_t fscache_n_store_pages;
53010+atomic_unchecked_t fscache_n_store_radix_deletes;
53011+atomic_unchecked_t fscache_n_store_pages_over_limit;
53012
53013-atomic_t fscache_n_store_vmscan_not_storing;
53014-atomic_t fscache_n_store_vmscan_gone;
53015-atomic_t fscache_n_store_vmscan_busy;
53016-atomic_t fscache_n_store_vmscan_cancelled;
53017-atomic_t fscache_n_store_vmscan_wait;
53018+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
53019+atomic_unchecked_t fscache_n_store_vmscan_gone;
53020+atomic_unchecked_t fscache_n_store_vmscan_busy;
53021+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
53022+atomic_unchecked_t fscache_n_store_vmscan_wait;
53023
53024-atomic_t fscache_n_marks;
53025-atomic_t fscache_n_uncaches;
53026+atomic_unchecked_t fscache_n_marks;
53027+atomic_unchecked_t fscache_n_uncaches;
53028
53029-atomic_t fscache_n_acquires;
53030-atomic_t fscache_n_acquires_null;
53031-atomic_t fscache_n_acquires_no_cache;
53032-atomic_t fscache_n_acquires_ok;
53033-atomic_t fscache_n_acquires_nobufs;
53034-atomic_t fscache_n_acquires_oom;
53035+atomic_unchecked_t fscache_n_acquires;
53036+atomic_unchecked_t fscache_n_acquires_null;
53037+atomic_unchecked_t fscache_n_acquires_no_cache;
53038+atomic_unchecked_t fscache_n_acquires_ok;
53039+atomic_unchecked_t fscache_n_acquires_nobufs;
53040+atomic_unchecked_t fscache_n_acquires_oom;
53041
53042-atomic_t fscache_n_invalidates;
53043-atomic_t fscache_n_invalidates_run;
53044+atomic_unchecked_t fscache_n_invalidates;
53045+atomic_unchecked_t fscache_n_invalidates_run;
53046
53047-atomic_t fscache_n_updates;
53048-atomic_t fscache_n_updates_null;
53049-atomic_t fscache_n_updates_run;
53050+atomic_unchecked_t fscache_n_updates;
53051+atomic_unchecked_t fscache_n_updates_null;
53052+atomic_unchecked_t fscache_n_updates_run;
53053
53054-atomic_t fscache_n_relinquishes;
53055-atomic_t fscache_n_relinquishes_null;
53056-atomic_t fscache_n_relinquishes_waitcrt;
53057-atomic_t fscache_n_relinquishes_retire;
53058+atomic_unchecked_t fscache_n_relinquishes;
53059+atomic_unchecked_t fscache_n_relinquishes_null;
53060+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
53061+atomic_unchecked_t fscache_n_relinquishes_retire;
53062
53063-atomic_t fscache_n_cookie_index;
53064-atomic_t fscache_n_cookie_data;
53065-atomic_t fscache_n_cookie_special;
53066+atomic_unchecked_t fscache_n_cookie_index;
53067+atomic_unchecked_t fscache_n_cookie_data;
53068+atomic_unchecked_t fscache_n_cookie_special;
53069
53070-atomic_t fscache_n_object_alloc;
53071-atomic_t fscache_n_object_no_alloc;
53072-atomic_t fscache_n_object_lookups;
53073-atomic_t fscache_n_object_lookups_negative;
53074-atomic_t fscache_n_object_lookups_positive;
53075-atomic_t fscache_n_object_lookups_timed_out;
53076-atomic_t fscache_n_object_created;
53077-atomic_t fscache_n_object_avail;
53078-atomic_t fscache_n_object_dead;
53079+atomic_unchecked_t fscache_n_object_alloc;
53080+atomic_unchecked_t fscache_n_object_no_alloc;
53081+atomic_unchecked_t fscache_n_object_lookups;
53082+atomic_unchecked_t fscache_n_object_lookups_negative;
53083+atomic_unchecked_t fscache_n_object_lookups_positive;
53084+atomic_unchecked_t fscache_n_object_lookups_timed_out;
53085+atomic_unchecked_t fscache_n_object_created;
53086+atomic_unchecked_t fscache_n_object_avail;
53087+atomic_unchecked_t fscache_n_object_dead;
53088
53089-atomic_t fscache_n_checkaux_none;
53090-atomic_t fscache_n_checkaux_okay;
53091-atomic_t fscache_n_checkaux_update;
53092-atomic_t fscache_n_checkaux_obsolete;
53093+atomic_unchecked_t fscache_n_checkaux_none;
53094+atomic_unchecked_t fscache_n_checkaux_okay;
53095+atomic_unchecked_t fscache_n_checkaux_update;
53096+atomic_unchecked_t fscache_n_checkaux_obsolete;
53097
53098 atomic_t fscache_n_cop_alloc_object;
53099 atomic_t fscache_n_cop_lookup_object;
53100@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
53101 seq_puts(m, "FS-Cache statistics\n");
53102
53103 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
53104- atomic_read(&fscache_n_cookie_index),
53105- atomic_read(&fscache_n_cookie_data),
53106- atomic_read(&fscache_n_cookie_special));
53107+ atomic_read_unchecked(&fscache_n_cookie_index),
53108+ atomic_read_unchecked(&fscache_n_cookie_data),
53109+ atomic_read_unchecked(&fscache_n_cookie_special));
53110
53111 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
53112- atomic_read(&fscache_n_object_alloc),
53113- atomic_read(&fscache_n_object_no_alloc),
53114- atomic_read(&fscache_n_object_avail),
53115- atomic_read(&fscache_n_object_dead));
53116+ atomic_read_unchecked(&fscache_n_object_alloc),
53117+ atomic_read_unchecked(&fscache_n_object_no_alloc),
53118+ atomic_read_unchecked(&fscache_n_object_avail),
53119+ atomic_read_unchecked(&fscache_n_object_dead));
53120 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
53121- atomic_read(&fscache_n_checkaux_none),
53122- atomic_read(&fscache_n_checkaux_okay),
53123- atomic_read(&fscache_n_checkaux_update),
53124- atomic_read(&fscache_n_checkaux_obsolete));
53125+ atomic_read_unchecked(&fscache_n_checkaux_none),
53126+ atomic_read_unchecked(&fscache_n_checkaux_okay),
53127+ atomic_read_unchecked(&fscache_n_checkaux_update),
53128+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
53129
53130 seq_printf(m, "Pages : mrk=%u unc=%u\n",
53131- atomic_read(&fscache_n_marks),
53132- atomic_read(&fscache_n_uncaches));
53133+ atomic_read_unchecked(&fscache_n_marks),
53134+ atomic_read_unchecked(&fscache_n_uncaches));
53135
53136 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
53137 " oom=%u\n",
53138- atomic_read(&fscache_n_acquires),
53139- atomic_read(&fscache_n_acquires_null),
53140- atomic_read(&fscache_n_acquires_no_cache),
53141- atomic_read(&fscache_n_acquires_ok),
53142- atomic_read(&fscache_n_acquires_nobufs),
53143- atomic_read(&fscache_n_acquires_oom));
53144+ atomic_read_unchecked(&fscache_n_acquires),
53145+ atomic_read_unchecked(&fscache_n_acquires_null),
53146+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
53147+ atomic_read_unchecked(&fscache_n_acquires_ok),
53148+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
53149+ atomic_read_unchecked(&fscache_n_acquires_oom));
53150
53151 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
53152- atomic_read(&fscache_n_object_lookups),
53153- atomic_read(&fscache_n_object_lookups_negative),
53154- atomic_read(&fscache_n_object_lookups_positive),
53155- atomic_read(&fscache_n_object_created),
53156- atomic_read(&fscache_n_object_lookups_timed_out));
53157+ atomic_read_unchecked(&fscache_n_object_lookups),
53158+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
53159+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
53160+ atomic_read_unchecked(&fscache_n_object_created),
53161+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
53162
53163 seq_printf(m, "Invals : n=%u run=%u\n",
53164- atomic_read(&fscache_n_invalidates),
53165- atomic_read(&fscache_n_invalidates_run));
53166+ atomic_read_unchecked(&fscache_n_invalidates),
53167+ atomic_read_unchecked(&fscache_n_invalidates_run));
53168
53169 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
53170- atomic_read(&fscache_n_updates),
53171- atomic_read(&fscache_n_updates_null),
53172- atomic_read(&fscache_n_updates_run));
53173+ atomic_read_unchecked(&fscache_n_updates),
53174+ atomic_read_unchecked(&fscache_n_updates_null),
53175+ atomic_read_unchecked(&fscache_n_updates_run));
53176
53177 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
53178- atomic_read(&fscache_n_relinquishes),
53179- atomic_read(&fscache_n_relinquishes_null),
53180- atomic_read(&fscache_n_relinquishes_waitcrt),
53181- atomic_read(&fscache_n_relinquishes_retire));
53182+ atomic_read_unchecked(&fscache_n_relinquishes),
53183+ atomic_read_unchecked(&fscache_n_relinquishes_null),
53184+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
53185+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
53186
53187 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
53188- atomic_read(&fscache_n_attr_changed),
53189- atomic_read(&fscache_n_attr_changed_ok),
53190- atomic_read(&fscache_n_attr_changed_nobufs),
53191- atomic_read(&fscache_n_attr_changed_nomem),
53192- atomic_read(&fscache_n_attr_changed_calls));
53193+ atomic_read_unchecked(&fscache_n_attr_changed),
53194+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
53195+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
53196+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
53197+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
53198
53199 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
53200- atomic_read(&fscache_n_allocs),
53201- atomic_read(&fscache_n_allocs_ok),
53202- atomic_read(&fscache_n_allocs_wait),
53203- atomic_read(&fscache_n_allocs_nobufs),
53204- atomic_read(&fscache_n_allocs_intr));
53205+ atomic_read_unchecked(&fscache_n_allocs),
53206+ atomic_read_unchecked(&fscache_n_allocs_ok),
53207+ atomic_read_unchecked(&fscache_n_allocs_wait),
53208+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
53209+ atomic_read_unchecked(&fscache_n_allocs_intr));
53210 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
53211- atomic_read(&fscache_n_alloc_ops),
53212- atomic_read(&fscache_n_alloc_op_waits),
53213- atomic_read(&fscache_n_allocs_object_dead));
53214+ atomic_read_unchecked(&fscache_n_alloc_ops),
53215+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
53216+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
53217
53218 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
53219 " int=%u oom=%u\n",
53220- atomic_read(&fscache_n_retrievals),
53221- atomic_read(&fscache_n_retrievals_ok),
53222- atomic_read(&fscache_n_retrievals_wait),
53223- atomic_read(&fscache_n_retrievals_nodata),
53224- atomic_read(&fscache_n_retrievals_nobufs),
53225- atomic_read(&fscache_n_retrievals_intr),
53226- atomic_read(&fscache_n_retrievals_nomem));
53227+ atomic_read_unchecked(&fscache_n_retrievals),
53228+ atomic_read_unchecked(&fscache_n_retrievals_ok),
53229+ atomic_read_unchecked(&fscache_n_retrievals_wait),
53230+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
53231+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
53232+ atomic_read_unchecked(&fscache_n_retrievals_intr),
53233+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
53234 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
53235- atomic_read(&fscache_n_retrieval_ops),
53236- atomic_read(&fscache_n_retrieval_op_waits),
53237- atomic_read(&fscache_n_retrievals_object_dead));
53238+ atomic_read_unchecked(&fscache_n_retrieval_ops),
53239+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
53240+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
53241
53242 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
53243- atomic_read(&fscache_n_stores),
53244- atomic_read(&fscache_n_stores_ok),
53245- atomic_read(&fscache_n_stores_again),
53246- atomic_read(&fscache_n_stores_nobufs),
53247- atomic_read(&fscache_n_stores_oom));
53248+ atomic_read_unchecked(&fscache_n_stores),
53249+ atomic_read_unchecked(&fscache_n_stores_ok),
53250+ atomic_read_unchecked(&fscache_n_stores_again),
53251+ atomic_read_unchecked(&fscache_n_stores_nobufs),
53252+ atomic_read_unchecked(&fscache_n_stores_oom));
53253 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
53254- atomic_read(&fscache_n_store_ops),
53255- atomic_read(&fscache_n_store_calls),
53256- atomic_read(&fscache_n_store_pages),
53257- atomic_read(&fscache_n_store_radix_deletes),
53258- atomic_read(&fscache_n_store_pages_over_limit));
53259+ atomic_read_unchecked(&fscache_n_store_ops),
53260+ atomic_read_unchecked(&fscache_n_store_calls),
53261+ atomic_read_unchecked(&fscache_n_store_pages),
53262+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
53263+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
53264
53265 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
53266- atomic_read(&fscache_n_store_vmscan_not_storing),
53267- atomic_read(&fscache_n_store_vmscan_gone),
53268- atomic_read(&fscache_n_store_vmscan_busy),
53269- atomic_read(&fscache_n_store_vmscan_cancelled),
53270- atomic_read(&fscache_n_store_vmscan_wait));
53271+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
53272+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
53273+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
53274+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
53275+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
53276
53277 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
53278- atomic_read(&fscache_n_op_pend),
53279- atomic_read(&fscache_n_op_run),
53280- atomic_read(&fscache_n_op_enqueue),
53281- atomic_read(&fscache_n_op_cancelled),
53282- atomic_read(&fscache_n_op_rejected));
53283+ atomic_read_unchecked(&fscache_n_op_pend),
53284+ atomic_read_unchecked(&fscache_n_op_run),
53285+ atomic_read_unchecked(&fscache_n_op_enqueue),
53286+ atomic_read_unchecked(&fscache_n_op_cancelled),
53287+ atomic_read_unchecked(&fscache_n_op_rejected));
53288 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
53289- atomic_read(&fscache_n_op_deferred_release),
53290- atomic_read(&fscache_n_op_release),
53291- atomic_read(&fscache_n_op_gc));
53292+ atomic_read_unchecked(&fscache_n_op_deferred_release),
53293+ atomic_read_unchecked(&fscache_n_op_release),
53294+ atomic_read_unchecked(&fscache_n_op_gc));
53295
53296 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
53297 atomic_read(&fscache_n_cop_alloc_object),
53298diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
53299index aef34b1..59bfd7b 100644
53300--- a/fs/fuse/cuse.c
53301+++ b/fs/fuse/cuse.c
53302@@ -600,10 +600,12 @@ static int __init cuse_init(void)
53303 INIT_LIST_HEAD(&cuse_conntbl[i]);
53304
53305 /* inherit and extend fuse_dev_operations */
53306- cuse_channel_fops = fuse_dev_operations;
53307- cuse_channel_fops.owner = THIS_MODULE;
53308- cuse_channel_fops.open = cuse_channel_open;
53309- cuse_channel_fops.release = cuse_channel_release;
53310+ pax_open_kernel();
53311+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
53312+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
53313+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
53314+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
53315+ pax_close_kernel();
53316
53317 cuse_class = class_create(THIS_MODULE, "cuse");
53318 if (IS_ERR(cuse_class))
53319diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
53320index 1d55f94..088da65 100644
53321--- a/fs/fuse/dev.c
53322+++ b/fs/fuse/dev.c
53323@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53324 ret = 0;
53325 pipe_lock(pipe);
53326
53327- if (!pipe->readers) {
53328+ if (!atomic_read(&pipe->readers)) {
53329 send_sig(SIGPIPE, current, 0);
53330 if (!ret)
53331 ret = -EPIPE;
53332@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53333 page_nr++;
53334 ret += buf->len;
53335
53336- if (pipe->files)
53337+ if (atomic_read(&pipe->files))
53338 do_wakeup = 1;
53339 }
53340
53341diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
53342index f3f783d..bf11a8e 100644
53343--- a/fs/fuse/dir.c
53344+++ b/fs/fuse/dir.c
53345@@ -1415,7 +1415,7 @@ static char *read_link(struct dentry *dentry)
53346 return link;
53347 }
53348
53349-static void free_link(char *link)
53350+static void free_link(const char *link)
53351 {
53352 if (!IS_ERR(link))
53353 free_page((unsigned long) link);
53354diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
53355index 62b484e..0f9a140 100644
53356--- a/fs/gfs2/inode.c
53357+++ b/fs/gfs2/inode.c
53358@@ -1441,7 +1441,7 @@ out:
53359
53360 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53361 {
53362- char *s = nd_get_link(nd);
53363+ const char *s = nd_get_link(nd);
53364 if (!IS_ERR(s))
53365 kfree(s);
53366 }
53367diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
53368index a3f868a..bb308ae 100644
53369--- a/fs/hugetlbfs/inode.c
53370+++ b/fs/hugetlbfs/inode.c
53371@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53372 struct mm_struct *mm = current->mm;
53373 struct vm_area_struct *vma;
53374 struct hstate *h = hstate_file(file);
53375+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
53376 struct vm_unmapped_area_info info;
53377
53378 if (len & ~huge_page_mask(h))
53379@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53380 return addr;
53381 }
53382
53383+#ifdef CONFIG_PAX_RANDMMAP
53384+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53385+#endif
53386+
53387 if (addr) {
53388 addr = ALIGN(addr, huge_page_size(h));
53389 vma = find_vma(mm, addr);
53390- if (TASK_SIZE - len >= addr &&
53391- (!vma || addr + len <= vma->vm_start))
53392+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
53393 return addr;
53394 }
53395
53396 info.flags = 0;
53397 info.length = len;
53398 info.low_limit = TASK_UNMAPPED_BASE;
53399+
53400+#ifdef CONFIG_PAX_RANDMMAP
53401+ if (mm->pax_flags & MF_PAX_RANDMMAP)
53402+ info.low_limit += mm->delta_mmap;
53403+#endif
53404+
53405 info.high_limit = TASK_SIZE;
53406 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
53407 info.align_offset = 0;
53408@@ -898,7 +908,7 @@ static struct file_system_type hugetlbfs_fs_type = {
53409 };
53410 MODULE_ALIAS_FS("hugetlbfs");
53411
53412-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53413+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53414
53415 static int can_do_hugetlb_shm(void)
53416 {
53417diff --git a/fs/inode.c b/fs/inode.c
53418index 00d5fc3..98ce7d7 100644
53419--- a/fs/inode.c
53420+++ b/fs/inode.c
53421@@ -878,8 +878,8 @@ unsigned int get_next_ino(void)
53422
53423 #ifdef CONFIG_SMP
53424 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
53425- static atomic_t shared_last_ino;
53426- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
53427+ static atomic_unchecked_t shared_last_ino;
53428+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
53429
53430 res = next - LAST_INO_BATCH;
53431 }
53432diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
53433index 4a6cf28..d3a29d3 100644
53434--- a/fs/jffs2/erase.c
53435+++ b/fs/jffs2/erase.c
53436@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
53437 struct jffs2_unknown_node marker = {
53438 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
53439 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53440- .totlen = cpu_to_je32(c->cleanmarker_size)
53441+ .totlen = cpu_to_je32(c->cleanmarker_size),
53442+ .hdr_crc = cpu_to_je32(0)
53443 };
53444
53445 jffs2_prealloc_raw_node_refs(c, jeb, 1);
53446diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
53447index a6597d6..41b30ec 100644
53448--- a/fs/jffs2/wbuf.c
53449+++ b/fs/jffs2/wbuf.c
53450@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
53451 {
53452 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
53453 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53454- .totlen = constant_cpu_to_je32(8)
53455+ .totlen = constant_cpu_to_je32(8),
53456+ .hdr_crc = constant_cpu_to_je32(0)
53457 };
53458
53459 /*
53460diff --git a/fs/jfs/super.c b/fs/jfs/super.c
53461index 788e0a9..8433098 100644
53462--- a/fs/jfs/super.c
53463+++ b/fs/jfs/super.c
53464@@ -878,7 +878,7 @@ static int __init init_jfs_fs(void)
53465
53466 jfs_inode_cachep =
53467 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
53468- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
53469+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
53470 init_once);
53471 if (jfs_inode_cachep == NULL)
53472 return -ENOMEM;
53473diff --git a/fs/libfs.c b/fs/libfs.c
53474index 916da8c..1588998 100644
53475--- a/fs/libfs.c
53476+++ b/fs/libfs.c
53477@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53478
53479 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
53480 struct dentry *next;
53481+ char d_name[sizeof(next->d_iname)];
53482+ const unsigned char *name;
53483+
53484 next = list_entry(p, struct dentry, d_u.d_child);
53485 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
53486 if (!simple_positive(next)) {
53487@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53488
53489 spin_unlock(&next->d_lock);
53490 spin_unlock(&dentry->d_lock);
53491- if (filldir(dirent, next->d_name.name,
53492+ name = next->d_name.name;
53493+ if (name == next->d_iname) {
53494+ memcpy(d_name, name, next->d_name.len);
53495+ name = d_name;
53496+ }
53497+ if (filldir(dirent, name,
53498 next->d_name.len, filp->f_pos,
53499 next->d_inode->i_ino,
53500 dt_type(next->d_inode)) < 0)
53501diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
53502index 9760ecb..9b838ef 100644
53503--- a/fs/lockd/clntproc.c
53504+++ b/fs/lockd/clntproc.c
53505@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
53506 /*
53507 * Cookie counter for NLM requests
53508 */
53509-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
53510+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
53511
53512 void nlmclnt_next_cookie(struct nlm_cookie *c)
53513 {
53514- u32 cookie = atomic_inc_return(&nlm_cookie);
53515+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
53516
53517 memcpy(c->data, &cookie, 4);
53518 c->len=4;
53519diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
53520index a2aa97d..10d6c41 100644
53521--- a/fs/lockd/svc.c
53522+++ b/fs/lockd/svc.c
53523@@ -305,7 +305,7 @@ static int lockd_start_svc(struct svc_serv *serv)
53524 svc_sock_update_bufs(serv);
53525 serv->sv_maxconn = nlm_max_connections;
53526
53527- nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name);
53528+ nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, "%s", serv->sv_name);
53529 if (IS_ERR(nlmsvc_task)) {
53530 error = PTR_ERR(nlmsvc_task);
53531 printk(KERN_WARNING
53532diff --git a/fs/locks.c b/fs/locks.c
53533index cb424a4..850e4dd 100644
53534--- a/fs/locks.c
53535+++ b/fs/locks.c
53536@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
53537 return;
53538
53539 if (filp->f_op && filp->f_op->flock) {
53540- struct file_lock fl = {
53541+ struct file_lock flock = {
53542 .fl_pid = current->tgid,
53543 .fl_file = filp,
53544 .fl_flags = FL_FLOCK,
53545 .fl_type = F_UNLCK,
53546 .fl_end = OFFSET_MAX,
53547 };
53548- filp->f_op->flock(filp, F_SETLKW, &fl);
53549- if (fl.fl_ops && fl.fl_ops->fl_release_private)
53550- fl.fl_ops->fl_release_private(&fl);
53551+ filp->f_op->flock(filp, F_SETLKW, &flock);
53552+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
53553+ flock.fl_ops->fl_release_private(&flock);
53554 }
53555
53556 lock_flocks();
53557diff --git a/fs/namei.c b/fs/namei.c
53558index 9ed9361..2b72db1 100644
53559--- a/fs/namei.c
53560+++ b/fs/namei.c
53561@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
53562 if (ret != -EACCES)
53563 return ret;
53564
53565+#ifdef CONFIG_GRKERNSEC
53566+ /* we'll block if we have to log due to a denied capability use */
53567+ if (mask & MAY_NOT_BLOCK)
53568+ return -ECHILD;
53569+#endif
53570+
53571 if (S_ISDIR(inode->i_mode)) {
53572 /* DACs are overridable for directories */
53573- if (inode_capable(inode, CAP_DAC_OVERRIDE))
53574- return 0;
53575 if (!(mask & MAY_WRITE))
53576- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53577+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53578+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53579 return 0;
53580+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
53581+ return 0;
53582 return -EACCES;
53583 }
53584 /*
53585+ * Searching includes executable on directories, else just read.
53586+ */
53587+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53588+ if (mask == MAY_READ)
53589+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53590+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53591+ return 0;
53592+
53593+ /*
53594 * Read/write DACs are always overridable.
53595 * Executable DACs are overridable when there is
53596 * at least one exec bit set.
53597@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
53598 if (inode_capable(inode, CAP_DAC_OVERRIDE))
53599 return 0;
53600
53601- /*
53602- * Searching includes executable on directories, else just read.
53603- */
53604- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53605- if (mask == MAY_READ)
53606- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53607- return 0;
53608-
53609 return -EACCES;
53610 }
53611
53612@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53613 {
53614 struct dentry *dentry = link->dentry;
53615 int error;
53616- char *s;
53617+ const char *s;
53618
53619 BUG_ON(nd->flags & LOOKUP_RCU);
53620
53621@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53622 if (error)
53623 goto out_put_nd_path;
53624
53625+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53626+ dentry->d_inode, dentry, nd->path.mnt)) {
53627+ error = -EACCES;
53628+ goto out_put_nd_path;
53629+ }
53630+
53631 nd->last_type = LAST_BIND;
53632 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53633 error = PTR_ERR(*p);
53634@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53635 if (res)
53636 break;
53637 res = walk_component(nd, path, LOOKUP_FOLLOW);
53638+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53639+ res = -EACCES;
53640 put_link(nd, &link, cookie);
53641 } while (res > 0);
53642
53643@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
53644 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53645 {
53646 unsigned long a, b, adata, bdata, mask, hash, len;
53647- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53648+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53649
53650 hash = a = 0;
53651 len = -sizeof(unsigned long);
53652@@ -1968,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
53653 if (err)
53654 break;
53655 err = lookup_last(nd, &path);
53656+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53657+ err = -EACCES;
53658 put_link(nd, &link, cookie);
53659 }
53660 }
53661@@ -1975,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
53662 if (!err)
53663 err = complete_walk(nd);
53664
53665+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53666+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53667+ path_put(&nd->path);
53668+ err = -ENOENT;
53669+ }
53670+ }
53671+
53672 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53673 if (!can_lookup(nd->inode)) {
53674 path_put(&nd->path);
53675@@ -2002,8 +2027,15 @@ static int filename_lookup(int dfd, struct filename *name,
53676 retval = path_lookupat(dfd, name->name,
53677 flags | LOOKUP_REVAL, nd);
53678
53679- if (likely(!retval))
53680+ if (likely(!retval)) {
53681 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53682+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53683+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53684+ path_put(&nd->path);
53685+ return -ENOENT;
53686+ }
53687+ }
53688+ }
53689 return retval;
53690 }
53691
53692@@ -2381,6 +2413,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53693 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53694 return -EPERM;
53695
53696+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53697+ return -EPERM;
53698+ if (gr_handle_rawio(inode))
53699+ return -EPERM;
53700+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53701+ return -EACCES;
53702+
53703 return 0;
53704 }
53705
53706@@ -2602,7 +2641,7 @@ looked_up:
53707 * cleared otherwise prior to returning.
53708 */
53709 static int lookup_open(struct nameidata *nd, struct path *path,
53710- struct file *file,
53711+ struct path *link, struct file *file,
53712 const struct open_flags *op,
53713 bool got_write, int *opened)
53714 {
53715@@ -2637,6 +2676,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53716 /* Negative dentry, just create the file */
53717 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53718 umode_t mode = op->mode;
53719+
53720+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53721+ error = -EACCES;
53722+ goto out_dput;
53723+ }
53724+
53725+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53726+ error = -EACCES;
53727+ goto out_dput;
53728+ }
53729+
53730 if (!IS_POSIXACL(dir->d_inode))
53731 mode &= ~current_umask();
53732 /*
53733@@ -2658,6 +2708,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53734 nd->flags & LOOKUP_EXCL);
53735 if (error)
53736 goto out_dput;
53737+ else
53738+ gr_handle_create(dentry, nd->path.mnt);
53739 }
53740 out_no_open:
53741 path->dentry = dentry;
53742@@ -2672,7 +2724,7 @@ out_dput:
53743 /*
53744 * Handle the last step of open()
53745 */
53746-static int do_last(struct nameidata *nd, struct path *path,
53747+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53748 struct file *file, const struct open_flags *op,
53749 int *opened, struct filename *name)
53750 {
53751@@ -2701,16 +2753,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53752 error = complete_walk(nd);
53753 if (error)
53754 return error;
53755+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53756+ error = -ENOENT;
53757+ goto out;
53758+ }
53759 audit_inode(name, nd->path.dentry, 0);
53760 if (open_flag & O_CREAT) {
53761 error = -EISDIR;
53762 goto out;
53763 }
53764+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53765+ error = -EACCES;
53766+ goto out;
53767+ }
53768 goto finish_open;
53769 case LAST_BIND:
53770 error = complete_walk(nd);
53771 if (error)
53772 return error;
53773+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53774+ error = -ENOENT;
53775+ goto out;
53776+ }
53777+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53778+ error = -EACCES;
53779+ goto out;
53780+ }
53781 audit_inode(name, dir, 0);
53782 goto finish_open;
53783 }
53784@@ -2759,7 +2827,7 @@ retry_lookup:
53785 */
53786 }
53787 mutex_lock(&dir->d_inode->i_mutex);
53788- error = lookup_open(nd, path, file, op, got_write, opened);
53789+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53790 mutex_unlock(&dir->d_inode->i_mutex);
53791
53792 if (error <= 0) {
53793@@ -2783,11 +2851,28 @@ retry_lookup:
53794 goto finish_open_created;
53795 }
53796
53797+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53798+ error = -ENOENT;
53799+ goto exit_dput;
53800+ }
53801+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53802+ error = -EACCES;
53803+ goto exit_dput;
53804+ }
53805+
53806 /*
53807 * create/update audit record if it already exists.
53808 */
53809- if (path->dentry->d_inode)
53810+ if (path->dentry->d_inode) {
53811+ /* only check if O_CREAT is specified, all other checks need to go
53812+ into may_open */
53813+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53814+ error = -EACCES;
53815+ goto exit_dput;
53816+ }
53817+
53818 audit_inode(name, path->dentry, 0);
53819+ }
53820
53821 /*
53822 * If atomic_open() acquired write access it is dropped now due to
53823@@ -2828,6 +2913,11 @@ finish_lookup:
53824 }
53825 }
53826 BUG_ON(inode != path->dentry->d_inode);
53827+ /* if we're resolving a symlink to another symlink */
53828+ if (link && gr_handle_symlink_owner(link, inode)) {
53829+ error = -EACCES;
53830+ goto out;
53831+ }
53832 return 1;
53833 }
53834
53835@@ -2837,7 +2927,6 @@ finish_lookup:
53836 save_parent.dentry = nd->path.dentry;
53837 save_parent.mnt = mntget(path->mnt);
53838 nd->path.dentry = path->dentry;
53839-
53840 }
53841 nd->inode = inode;
53842 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53843@@ -2846,6 +2935,16 @@ finish_lookup:
53844 path_put(&save_parent);
53845 return error;
53846 }
53847+
53848+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53849+ error = -ENOENT;
53850+ goto out;
53851+ }
53852+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53853+ error = -EACCES;
53854+ goto out;
53855+ }
53856+
53857 error = -EISDIR;
53858 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53859 goto out;
53860@@ -2944,7 +3043,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53861 if (unlikely(error))
53862 goto out;
53863
53864- error = do_last(nd, &path, file, op, &opened, pathname);
53865+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53866 while (unlikely(error > 0)) { /* trailing symlink */
53867 struct path link = path;
53868 void *cookie;
53869@@ -2962,7 +3061,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53870 error = follow_link(&link, nd, &cookie);
53871 if (unlikely(error))
53872 break;
53873- error = do_last(nd, &path, file, op, &opened, pathname);
53874+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53875 put_link(nd, &link, cookie);
53876 }
53877 out:
53878@@ -3062,8 +3161,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53879 goto unlock;
53880
53881 error = -EEXIST;
53882- if (dentry->d_inode)
53883+ if (dentry->d_inode) {
53884+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53885+ error = -ENOENT;
53886+ }
53887 goto fail;
53888+ }
53889 /*
53890 * Special case - lookup gave negative, but... we had foo/bar/
53891 * From the vfs_mknod() POV we just have a negative dentry -
53892@@ -3115,6 +3218,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53893 }
53894 EXPORT_SYMBOL(user_path_create);
53895
53896+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53897+{
53898+ struct filename *tmp = getname(pathname);
53899+ struct dentry *res;
53900+ if (IS_ERR(tmp))
53901+ return ERR_CAST(tmp);
53902+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53903+ if (IS_ERR(res))
53904+ putname(tmp);
53905+ else
53906+ *to = tmp;
53907+ return res;
53908+}
53909+
53910 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53911 {
53912 int error = may_create(dir, dentry);
53913@@ -3177,6 +3294,17 @@ retry:
53914
53915 if (!IS_POSIXACL(path.dentry->d_inode))
53916 mode &= ~current_umask();
53917+
53918+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
53919+ error = -EPERM;
53920+ goto out;
53921+ }
53922+
53923+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
53924+ error = -EACCES;
53925+ goto out;
53926+ }
53927+
53928 error = security_path_mknod(&path, dentry, mode, dev);
53929 if (error)
53930 goto out;
53931@@ -3193,6 +3321,8 @@ retry:
53932 break;
53933 }
53934 out:
53935+ if (!error)
53936+ gr_handle_create(dentry, path.mnt);
53937 done_path_create(&path, dentry);
53938 if (retry_estale(error, lookup_flags)) {
53939 lookup_flags |= LOOKUP_REVAL;
53940@@ -3245,9 +3375,16 @@ retry:
53941
53942 if (!IS_POSIXACL(path.dentry->d_inode))
53943 mode &= ~current_umask();
53944+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
53945+ error = -EACCES;
53946+ goto out;
53947+ }
53948 error = security_path_mkdir(&path, dentry, mode);
53949 if (!error)
53950 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
53951+ if (!error)
53952+ gr_handle_create(dentry, path.mnt);
53953+out:
53954 done_path_create(&path, dentry);
53955 if (retry_estale(error, lookup_flags)) {
53956 lookup_flags |= LOOKUP_REVAL;
53957@@ -3328,6 +3465,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
53958 struct filename *name;
53959 struct dentry *dentry;
53960 struct nameidata nd;
53961+ ino_t saved_ino = 0;
53962+ dev_t saved_dev = 0;
53963 unsigned int lookup_flags = 0;
53964 retry:
53965 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53966@@ -3360,10 +3499,21 @@ retry:
53967 error = -ENOENT;
53968 goto exit3;
53969 }
53970+
53971+ saved_ino = dentry->d_inode->i_ino;
53972+ saved_dev = gr_get_dev_from_dentry(dentry);
53973+
53974+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
53975+ error = -EACCES;
53976+ goto exit3;
53977+ }
53978+
53979 error = security_path_rmdir(&nd.path, dentry);
53980 if (error)
53981 goto exit3;
53982 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
53983+ if (!error && (saved_dev || saved_ino))
53984+ gr_handle_delete(saved_ino, saved_dev);
53985 exit3:
53986 dput(dentry);
53987 exit2:
53988@@ -3429,6 +3579,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
53989 struct dentry *dentry;
53990 struct nameidata nd;
53991 struct inode *inode = NULL;
53992+ ino_t saved_ino = 0;
53993+ dev_t saved_dev = 0;
53994 unsigned int lookup_flags = 0;
53995 retry:
53996 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53997@@ -3455,10 +3607,22 @@ retry:
53998 if (!inode)
53999 goto slashes;
54000 ihold(inode);
54001+
54002+ if (inode->i_nlink <= 1) {
54003+ saved_ino = inode->i_ino;
54004+ saved_dev = gr_get_dev_from_dentry(dentry);
54005+ }
54006+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
54007+ error = -EACCES;
54008+ goto exit2;
54009+ }
54010+
54011 error = security_path_unlink(&nd.path, dentry);
54012 if (error)
54013 goto exit2;
54014 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
54015+ if (!error && (saved_ino || saved_dev))
54016+ gr_handle_delete(saved_ino, saved_dev);
54017 exit2:
54018 dput(dentry);
54019 }
54020@@ -3536,9 +3700,17 @@ retry:
54021 if (IS_ERR(dentry))
54022 goto out_putname;
54023
54024+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
54025+ error = -EACCES;
54026+ goto out;
54027+ }
54028+
54029 error = security_path_symlink(&path, dentry, from->name);
54030 if (!error)
54031 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
54032+ if (!error)
54033+ gr_handle_create(dentry, path.mnt);
54034+out:
54035 done_path_create(&path, dentry);
54036 if (retry_estale(error, lookup_flags)) {
54037 lookup_flags |= LOOKUP_REVAL;
54038@@ -3612,6 +3784,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
54039 {
54040 struct dentry *new_dentry;
54041 struct path old_path, new_path;
54042+ struct filename *to = NULL;
54043 int how = 0;
54044 int error;
54045
54046@@ -3635,7 +3808,7 @@ retry:
54047 if (error)
54048 return error;
54049
54050- new_dentry = user_path_create(newdfd, newname, &new_path,
54051+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
54052 (how & LOOKUP_REVAL));
54053 error = PTR_ERR(new_dentry);
54054 if (IS_ERR(new_dentry))
54055@@ -3647,11 +3820,28 @@ retry:
54056 error = may_linkat(&old_path);
54057 if (unlikely(error))
54058 goto out_dput;
54059+
54060+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
54061+ old_path.dentry->d_inode,
54062+ old_path.dentry->d_inode->i_mode, to)) {
54063+ error = -EACCES;
54064+ goto out_dput;
54065+ }
54066+
54067+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
54068+ old_path.dentry, old_path.mnt, to)) {
54069+ error = -EACCES;
54070+ goto out_dput;
54071+ }
54072+
54073 error = security_path_link(old_path.dentry, &new_path, new_dentry);
54074 if (error)
54075 goto out_dput;
54076 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
54077+ if (!error)
54078+ gr_handle_create(new_dentry, new_path.mnt);
54079 out_dput:
54080+ putname(to);
54081 done_path_create(&new_path, new_dentry);
54082 if (retry_estale(error, how)) {
54083 how |= LOOKUP_REVAL;
54084@@ -3897,12 +4087,21 @@ retry:
54085 if (new_dentry == trap)
54086 goto exit5;
54087
54088+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
54089+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
54090+ to);
54091+ if (error)
54092+ goto exit5;
54093+
54094 error = security_path_rename(&oldnd.path, old_dentry,
54095 &newnd.path, new_dentry);
54096 if (error)
54097 goto exit5;
54098 error = vfs_rename(old_dir->d_inode, old_dentry,
54099 new_dir->d_inode, new_dentry);
54100+ if (!error)
54101+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
54102+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
54103 exit5:
54104 dput(new_dentry);
54105 exit4:
54106@@ -3934,6 +4133,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
54107
54108 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
54109 {
54110+ char tmpbuf[64];
54111+ const char *newlink;
54112 int len;
54113
54114 len = PTR_ERR(link);
54115@@ -3943,7 +4144,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
54116 len = strlen(link);
54117 if (len > (unsigned) buflen)
54118 len = buflen;
54119- if (copy_to_user(buffer, link, len))
54120+
54121+ if (len < sizeof(tmpbuf)) {
54122+ memcpy(tmpbuf, link, len);
54123+ newlink = tmpbuf;
54124+ } else
54125+ newlink = link;
54126+
54127+ if (copy_to_user(buffer, newlink, len))
54128 len = -EFAULT;
54129 out:
54130 return len;
54131diff --git a/fs/namespace.c b/fs/namespace.c
54132index 7b1ca9b..6faeccf 100644
54133--- a/fs/namespace.c
54134+++ b/fs/namespace.c
54135@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
54136 if (!(sb->s_flags & MS_RDONLY))
54137 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
54138 up_write(&sb->s_umount);
54139+
54140+ gr_log_remount(mnt->mnt_devname, retval);
54141+
54142 return retval;
54143 }
54144
54145@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
54146 }
54147 br_write_unlock(&vfsmount_lock);
54148 namespace_unlock();
54149+
54150+ gr_log_unmount(mnt->mnt_devname, retval);
54151+
54152 return retval;
54153 }
54154
54155@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
54156 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
54157 */
54158
54159-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
54160+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
54161 {
54162 struct path path;
54163 struct mount *mnt;
54164@@ -1342,7 +1348,7 @@ out:
54165 /*
54166 * The 2.0 compatible umount. No flags.
54167 */
54168-SYSCALL_DEFINE1(oldumount, char __user *, name)
54169+SYSCALL_DEFINE1(oldumount, const char __user *, name)
54170 {
54171 return sys_umount(name, 0);
54172 }
54173@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
54174 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
54175 MS_STRICTATIME);
54176
54177+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
54178+ retval = -EPERM;
54179+ goto dput_out;
54180+ }
54181+
54182+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
54183+ retval = -EPERM;
54184+ goto dput_out;
54185+ }
54186+
54187 if (flags & MS_REMOUNT)
54188 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
54189 data_page);
54190@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
54191 dev_name, data_page);
54192 dput_out:
54193 path_put(&path);
54194+
54195+ gr_log_mount(dev_name, dir_name, retval);
54196+
54197 return retval;
54198 }
54199
54200@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
54201 }
54202 EXPORT_SYMBOL(mount_subtree);
54203
54204-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
54205- char __user *, type, unsigned long, flags, void __user *, data)
54206+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
54207+ const char __user *, type, unsigned long, flags, void __user *, data)
54208 {
54209 int ret;
54210 char *kernel_type;
54211@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
54212 if (error)
54213 goto out2;
54214
54215+ if (gr_handle_chroot_pivot()) {
54216+ error = -EPERM;
54217+ goto out2;
54218+ }
54219+
54220 get_fs_root(current->fs, &root);
54221 old_mp = lock_mount(&old);
54222 error = PTR_ERR(old_mp);
54223@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
54224 !nsown_capable(CAP_SYS_ADMIN))
54225 return -EPERM;
54226
54227- if (fs->users != 1)
54228+ if (atomic_read(&fs->users) != 1)
54229 return -EINVAL;
54230
54231 get_mnt_ns(mnt_ns);
54232diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
54233index cff089a..4c3d57a 100644
54234--- a/fs/nfs/callback.c
54235+++ b/fs/nfs/callback.c
54236@@ -211,7 +211,6 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
54237 struct svc_rqst *rqstp;
54238 int (*callback_svc)(void *vrqstp);
54239 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
54240- char svc_name[12];
54241 int ret;
54242
54243 nfs_callback_bc_serv(minorversion, xprt, serv);
54244@@ -235,10 +234,9 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
54245
54246 svc_sock_update_bufs(serv);
54247
54248- sprintf(svc_name, "nfsv4.%u-svc", minorversion);
54249 cb_info->serv = serv;
54250 cb_info->rqst = rqstp;
54251- cb_info->task = kthread_run(callback_svc, cb_info->rqst, svc_name);
54252+ cb_info->task = kthread_run(callback_svc, cb_info->rqst, "nfsv4.%u-svc", minorversion);
54253 if (IS_ERR(cb_info->task)) {
54254 ret = PTR_ERR(cb_info->task);
54255 svc_exit_thread(cb_info->rqst);
54256diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
54257index a35582c..ebbdcd5 100644
54258--- a/fs/nfs/callback_xdr.c
54259+++ b/fs/nfs/callback_xdr.c
54260@@ -51,7 +51,7 @@ struct callback_op {
54261 callback_decode_arg_t decode_args;
54262 callback_encode_res_t encode_res;
54263 long res_maxsize;
54264-};
54265+} __do_const;
54266
54267 static struct callback_op callback_ops[];
54268
54269diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
54270index c1c7a9d..7afa0b8 100644
54271--- a/fs/nfs/inode.c
54272+++ b/fs/nfs/inode.c
54273@@ -1043,16 +1043,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
54274 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
54275 }
54276
54277-static atomic_long_t nfs_attr_generation_counter;
54278+static atomic_long_unchecked_t nfs_attr_generation_counter;
54279
54280 static unsigned long nfs_read_attr_generation_counter(void)
54281 {
54282- return atomic_long_read(&nfs_attr_generation_counter);
54283+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
54284 }
54285
54286 unsigned long nfs_inc_attr_generation_counter(void)
54287 {
54288- return atomic_long_inc_return(&nfs_attr_generation_counter);
54289+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
54290 }
54291
54292 void nfs_fattr_init(struct nfs_fattr *fattr)
54293diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
54294index 2c37442..9b9538b 100644
54295--- a/fs/nfs/nfs4state.c
54296+++ b/fs/nfs/nfs4state.c
54297@@ -1193,7 +1193,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp)
54298 snprintf(buf, sizeof(buf), "%s-manager",
54299 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
54300 rcu_read_unlock();
54301- task = kthread_run(nfs4_run_state_manager, clp, buf);
54302+ task = kthread_run(nfs4_run_state_manager, clp, "%s", buf);
54303 if (IS_ERR(task)) {
54304 printk(KERN_ERR "%s: kthread_run: %ld\n",
54305 __func__, PTR_ERR(task));
54306diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
54307index 27d74a2..c4c2a73 100644
54308--- a/fs/nfsd/nfs4proc.c
54309+++ b/fs/nfsd/nfs4proc.c
54310@@ -1126,7 +1126,7 @@ struct nfsd4_operation {
54311 nfsd4op_rsize op_rsize_bop;
54312 stateid_getter op_get_currentstateid;
54313 stateid_setter op_set_currentstateid;
54314-};
54315+} __do_const;
54316
54317 static struct nfsd4_operation nfsd4_ops[];
54318
54319diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
54320index 582321a..0224663 100644
54321--- a/fs/nfsd/nfs4xdr.c
54322+++ b/fs/nfsd/nfs4xdr.c
54323@@ -1458,7 +1458,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
54324
54325 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
54326
54327-static nfsd4_dec nfsd4_dec_ops[] = {
54328+static const nfsd4_dec nfsd4_dec_ops[] = {
54329 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54330 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54331 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54332@@ -1498,7 +1498,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
54333 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
54334 };
54335
54336-static nfsd4_dec nfsd41_dec_ops[] = {
54337+static const nfsd4_dec nfsd41_dec_ops[] = {
54338 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54339 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54340 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54341@@ -1560,7 +1560,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
54342 };
54343
54344 struct nfsd4_minorversion_ops {
54345- nfsd4_dec *decoders;
54346+ const nfsd4_dec *decoders;
54347 int nops;
54348 };
54349
54350diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
54351index e76244e..9fe8f2f1 100644
54352--- a/fs/nfsd/nfscache.c
54353+++ b/fs/nfsd/nfscache.c
54354@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
54355 {
54356 struct svc_cacherep *rp = rqstp->rq_cacherep;
54357 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
54358- int len;
54359+ long len;
54360 size_t bufsize = 0;
54361
54362 if (!rp)
54363 return;
54364
54365- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
54366- len >>= 2;
54367+ if (statp) {
54368+ len = (char*)statp - (char*)resv->iov_base;
54369+ len = resv->iov_len - len;
54370+ len >>= 2;
54371+ }
54372
54373 /* Don't cache excessive amounts of data and XDR failures */
54374 if (!statp || len > (256 >> 2)) {
54375diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
54376index 84ce601..633d226 100644
54377--- a/fs/nfsd/vfs.c
54378+++ b/fs/nfsd/vfs.c
54379@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54380 } else {
54381 oldfs = get_fs();
54382 set_fs(KERNEL_DS);
54383- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
54384+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
54385 set_fs(oldfs);
54386 }
54387
54388@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54389
54390 /* Write the data. */
54391 oldfs = get_fs(); set_fs(KERNEL_DS);
54392- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
54393+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
54394 set_fs(oldfs);
54395 if (host_err < 0)
54396 goto out_nfserr;
54397@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
54398 */
54399
54400 oldfs = get_fs(); set_fs(KERNEL_DS);
54401- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
54402+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
54403 set_fs(oldfs);
54404
54405 if (host_err < 0)
54406diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
54407index fea6bd5..8ee9d81 100644
54408--- a/fs/nls/nls_base.c
54409+++ b/fs/nls/nls_base.c
54410@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
54411
54412 int register_nls(struct nls_table * nls)
54413 {
54414- struct nls_table ** tmp = &tables;
54415+ struct nls_table *tmp = tables;
54416
54417 if (nls->next)
54418 return -EBUSY;
54419
54420 spin_lock(&nls_lock);
54421- while (*tmp) {
54422- if (nls == *tmp) {
54423+ while (tmp) {
54424+ if (nls == tmp) {
54425 spin_unlock(&nls_lock);
54426 return -EBUSY;
54427 }
54428- tmp = &(*tmp)->next;
54429+ tmp = tmp->next;
54430 }
54431- nls->next = tables;
54432+ pax_open_kernel();
54433+ *(struct nls_table **)&nls->next = tables;
54434+ pax_close_kernel();
54435 tables = nls;
54436 spin_unlock(&nls_lock);
54437 return 0;
54438@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
54439
54440 int unregister_nls(struct nls_table * nls)
54441 {
54442- struct nls_table ** tmp = &tables;
54443+ struct nls_table * const * tmp = &tables;
54444
54445 spin_lock(&nls_lock);
54446 while (*tmp) {
54447 if (nls == *tmp) {
54448- *tmp = nls->next;
54449+ pax_open_kernel();
54450+ *(struct nls_table **)tmp = nls->next;
54451+ pax_close_kernel();
54452 spin_unlock(&nls_lock);
54453 return 0;
54454 }
54455diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
54456index 7424929..35f6be5 100644
54457--- a/fs/nls/nls_euc-jp.c
54458+++ b/fs/nls/nls_euc-jp.c
54459@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
54460 p_nls = load_nls("cp932");
54461
54462 if (p_nls) {
54463- table.charset2upper = p_nls->charset2upper;
54464- table.charset2lower = p_nls->charset2lower;
54465+ pax_open_kernel();
54466+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54467+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54468+ pax_close_kernel();
54469 return register_nls(&table);
54470 }
54471
54472diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
54473index e7bc1d7..06bd4bb 100644
54474--- a/fs/nls/nls_koi8-ru.c
54475+++ b/fs/nls/nls_koi8-ru.c
54476@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
54477 p_nls = load_nls("koi8-u");
54478
54479 if (p_nls) {
54480- table.charset2upper = p_nls->charset2upper;
54481- table.charset2lower = p_nls->charset2lower;
54482+ pax_open_kernel();
54483+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54484+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54485+ pax_close_kernel();
54486 return register_nls(&table);
54487 }
54488
54489diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
54490index 6c80083..a1e6299 100644
54491--- a/fs/notify/fanotify/fanotify_user.c
54492+++ b/fs/notify/fanotify/fanotify_user.c
54493@@ -122,6 +122,7 @@ static int fill_event_metadata(struct fsnotify_group *group,
54494 metadata->event_len = FAN_EVENT_METADATA_LEN;
54495 metadata->metadata_len = FAN_EVENT_METADATA_LEN;
54496 metadata->vers = FANOTIFY_METADATA_VERSION;
54497+ metadata->reserved = 0;
54498 metadata->mask = event->mask & FAN_ALL_OUTGOING_EVENTS;
54499 metadata->pid = pid_vnr(event->tgid);
54500 if (unlikely(event->mask & FAN_Q_OVERFLOW))
54501@@ -252,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
54502
54503 fd = fanotify_event_metadata.fd;
54504 ret = -EFAULT;
54505- if (copy_to_user(buf, &fanotify_event_metadata,
54506- fanotify_event_metadata.event_len))
54507+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
54508+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
54509 goto out_close_fd;
54510
54511 ret = prepare_for_access_response(group, event, fd);
54512diff --git a/fs/notify/notification.c b/fs/notify/notification.c
54513index 7b51b05..5ea5ef6 100644
54514--- a/fs/notify/notification.c
54515+++ b/fs/notify/notification.c
54516@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
54517 * get set to 0 so it will never get 'freed'
54518 */
54519 static struct fsnotify_event *q_overflow_event;
54520-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54521+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54522
54523 /**
54524 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
54525@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54526 */
54527 u32 fsnotify_get_cookie(void)
54528 {
54529- return atomic_inc_return(&fsnotify_sync_cookie);
54530+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
54531 }
54532 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
54533
54534diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
54535index aa411c3..c260a84 100644
54536--- a/fs/ntfs/dir.c
54537+++ b/fs/ntfs/dir.c
54538@@ -1329,7 +1329,7 @@ find_next_index_buffer:
54539 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
54540 ~(s64)(ndir->itype.index.block_size - 1)));
54541 /* Bounds checks. */
54542- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54543+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54544 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
54545 "inode 0x%lx or driver bug.", vdir->i_ino);
54546 goto err_out;
54547diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
54548index c5670b8..01a3656 100644
54549--- a/fs/ntfs/file.c
54550+++ b/fs/ntfs/file.c
54551@@ -2241,6 +2241,6 @@ const struct inode_operations ntfs_file_inode_ops = {
54552 #endif /* NTFS_RW */
54553 };
54554
54555-const struct file_operations ntfs_empty_file_ops = {};
54556+const struct file_operations ntfs_empty_file_ops __read_only;
54557
54558-const struct inode_operations ntfs_empty_inode_ops = {};
54559+const struct inode_operations ntfs_empty_inode_ops __read_only;
54560diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
54561index aebeacd..0dcdd26 100644
54562--- a/fs/ocfs2/localalloc.c
54563+++ b/fs/ocfs2/localalloc.c
54564@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
54565 goto bail;
54566 }
54567
54568- atomic_inc(&osb->alloc_stats.moves);
54569+ atomic_inc_unchecked(&osb->alloc_stats.moves);
54570
54571 bail:
54572 if (handle)
54573diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
54574index d355e6e..578d905 100644
54575--- a/fs/ocfs2/ocfs2.h
54576+++ b/fs/ocfs2/ocfs2.h
54577@@ -235,11 +235,11 @@ enum ocfs2_vol_state
54578
54579 struct ocfs2_alloc_stats
54580 {
54581- atomic_t moves;
54582- atomic_t local_data;
54583- atomic_t bitmap_data;
54584- atomic_t bg_allocs;
54585- atomic_t bg_extends;
54586+ atomic_unchecked_t moves;
54587+ atomic_unchecked_t local_data;
54588+ atomic_unchecked_t bitmap_data;
54589+ atomic_unchecked_t bg_allocs;
54590+ atomic_unchecked_t bg_extends;
54591 };
54592
54593 enum ocfs2_local_alloc_state
54594diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
54595index b7e74b5..19c6536 100644
54596--- a/fs/ocfs2/suballoc.c
54597+++ b/fs/ocfs2/suballoc.c
54598@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
54599 mlog_errno(status);
54600 goto bail;
54601 }
54602- atomic_inc(&osb->alloc_stats.bg_extends);
54603+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
54604
54605 /* You should never ask for this much metadata */
54606 BUG_ON(bits_wanted >
54607@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
54608 mlog_errno(status);
54609 goto bail;
54610 }
54611- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54612+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54613
54614 *suballoc_loc = res.sr_bg_blkno;
54615 *suballoc_bit_start = res.sr_bit_offset;
54616@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
54617 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
54618 res->sr_bits);
54619
54620- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54621+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54622
54623 BUG_ON(res->sr_bits != 1);
54624
54625@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
54626 mlog_errno(status);
54627 goto bail;
54628 }
54629- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54630+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54631
54632 BUG_ON(res.sr_bits != 1);
54633
54634@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54635 cluster_start,
54636 num_clusters);
54637 if (!status)
54638- atomic_inc(&osb->alloc_stats.local_data);
54639+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
54640 } else {
54641 if (min_clusters > (osb->bitmap_cpg - 1)) {
54642 /* The only paths asking for contiguousness
54643@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54644 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
54645 res.sr_bg_blkno,
54646 res.sr_bit_offset);
54647- atomic_inc(&osb->alloc_stats.bitmap_data);
54648+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
54649 *num_clusters = res.sr_bits;
54650 }
54651 }
54652diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
54653index 01b8516..579c4df 100644
54654--- a/fs/ocfs2/super.c
54655+++ b/fs/ocfs2/super.c
54656@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
54657 "%10s => GlobalAllocs: %d LocalAllocs: %d "
54658 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
54659 "Stats",
54660- atomic_read(&osb->alloc_stats.bitmap_data),
54661- atomic_read(&osb->alloc_stats.local_data),
54662- atomic_read(&osb->alloc_stats.bg_allocs),
54663- atomic_read(&osb->alloc_stats.moves),
54664- atomic_read(&osb->alloc_stats.bg_extends));
54665+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
54666+ atomic_read_unchecked(&osb->alloc_stats.local_data),
54667+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
54668+ atomic_read_unchecked(&osb->alloc_stats.moves),
54669+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
54670
54671 out += snprintf(buf + out, len - out,
54672 "%10s => State: %u Descriptor: %llu Size: %u bits "
54673@@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
54674 spin_lock_init(&osb->osb_xattr_lock);
54675 ocfs2_init_steal_slots(osb);
54676
54677- atomic_set(&osb->alloc_stats.moves, 0);
54678- atomic_set(&osb->alloc_stats.local_data, 0);
54679- atomic_set(&osb->alloc_stats.bitmap_data, 0);
54680- atomic_set(&osb->alloc_stats.bg_allocs, 0);
54681- atomic_set(&osb->alloc_stats.bg_extends, 0);
54682+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
54683+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
54684+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
54685+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
54686+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
54687
54688 /* Copy the blockcheck stats from the superblock probe */
54689 osb->osb_ecc_stats = *stats;
54690diff --git a/fs/open.c b/fs/open.c
54691index 8c74100..4239c48 100644
54692--- a/fs/open.c
54693+++ b/fs/open.c
54694@@ -32,6 +32,8 @@
54695 #include <linux/dnotify.h>
54696 #include <linux/compat.h>
54697
54698+#define CREATE_TRACE_POINTS
54699+#include <trace/events/fs.h>
54700 #include "internal.h"
54701
54702 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54703@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
54704 error = locks_verify_truncate(inode, NULL, length);
54705 if (!error)
54706 error = security_path_truncate(path);
54707+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54708+ error = -EACCES;
54709 if (!error)
54710 error = do_truncate(path->dentry, length, 0, NULL);
54711
54712@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54713 error = locks_verify_truncate(inode, f.file, length);
54714 if (!error)
54715 error = security_path_truncate(&f.file->f_path);
54716+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54717+ error = -EACCES;
54718 if (!error)
54719 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54720 sb_end_write(inode->i_sb);
54721@@ -360,6 +366,9 @@ retry:
54722 if (__mnt_is_readonly(path.mnt))
54723 res = -EROFS;
54724
54725+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54726+ res = -EACCES;
54727+
54728 out_path_release:
54729 path_put(&path);
54730 if (retry_estale(res, lookup_flags)) {
54731@@ -391,6 +400,8 @@ retry:
54732 if (error)
54733 goto dput_and_out;
54734
54735+ gr_log_chdir(path.dentry, path.mnt);
54736+
54737 set_fs_pwd(current->fs, &path);
54738
54739 dput_and_out:
54740@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54741 goto out_putf;
54742
54743 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54744+
54745+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54746+ error = -EPERM;
54747+
54748+ if (!error)
54749+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54750+
54751 if (!error)
54752 set_fs_pwd(current->fs, &f.file->f_path);
54753 out_putf:
54754@@ -449,7 +467,13 @@ retry:
54755 if (error)
54756 goto dput_and_out;
54757
54758+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54759+ goto dput_and_out;
54760+
54761 set_fs_root(current->fs, &path);
54762+
54763+ gr_handle_chroot_chdir(&path);
54764+
54765 error = 0;
54766 dput_and_out:
54767 path_put(&path);
54768@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
54769 if (error)
54770 return error;
54771 mutex_lock(&inode->i_mutex);
54772+
54773+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54774+ error = -EACCES;
54775+ goto out_unlock;
54776+ }
54777+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54778+ error = -EACCES;
54779+ goto out_unlock;
54780+ }
54781+
54782 error = security_path_chmod(path, mode);
54783 if (error)
54784 goto out_unlock;
54785@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54786 uid = make_kuid(current_user_ns(), user);
54787 gid = make_kgid(current_user_ns(), group);
54788
54789+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54790+ return -EACCES;
54791+
54792 newattrs.ia_valid = ATTR_CTIME;
54793 if (user != (uid_t) -1) {
54794 if (!uid_valid(uid))
54795@@ -946,6 +983,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54796 } else {
54797 fsnotify_open(f);
54798 fd_install(fd, f);
54799+ trace_do_sys_open(tmp->name, flags, mode);
54800 }
54801 }
54802 putname(tmp);
54803diff --git a/fs/pipe.c b/fs/pipe.c
54804index d2c45e1..009fe1c 100644
54805--- a/fs/pipe.c
54806+++ b/fs/pipe.c
54807@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
54808
54809 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
54810 {
54811- if (pipe->files)
54812+ if (atomic_read(&pipe->files))
54813 mutex_lock_nested(&pipe->mutex, subclass);
54814 }
54815
54816@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
54817
54818 void pipe_unlock(struct pipe_inode_info *pipe)
54819 {
54820- if (pipe->files)
54821+ if (atomic_read(&pipe->files))
54822 mutex_unlock(&pipe->mutex);
54823 }
54824 EXPORT_SYMBOL(pipe_unlock);
54825@@ -449,9 +449,9 @@ redo:
54826 }
54827 if (bufs) /* More to do? */
54828 continue;
54829- if (!pipe->writers)
54830+ if (!atomic_read(&pipe->writers))
54831 break;
54832- if (!pipe->waiting_writers) {
54833+ if (!atomic_read(&pipe->waiting_writers)) {
54834 /* syscall merging: Usually we must not sleep
54835 * if O_NONBLOCK is set, or if we got some data.
54836 * But if a writer sleeps in kernel space, then
54837@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54838 ret = 0;
54839 __pipe_lock(pipe);
54840
54841- if (!pipe->readers) {
54842+ if (!atomic_read(&pipe->readers)) {
54843 send_sig(SIGPIPE, current, 0);
54844 ret = -EPIPE;
54845 goto out;
54846@@ -562,7 +562,7 @@ redo1:
54847 for (;;) {
54848 int bufs;
54849
54850- if (!pipe->readers) {
54851+ if (!atomic_read(&pipe->readers)) {
54852 send_sig(SIGPIPE, current, 0);
54853 if (!ret)
54854 ret = -EPIPE;
54855@@ -653,9 +653,9 @@ redo2:
54856 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54857 do_wakeup = 0;
54858 }
54859- pipe->waiting_writers++;
54860+ atomic_inc(&pipe->waiting_writers);
54861 pipe_wait(pipe);
54862- pipe->waiting_writers--;
54863+ atomic_dec(&pipe->waiting_writers);
54864 }
54865 out:
54866 __pipe_unlock(pipe);
54867@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54868 mask = 0;
54869 if (filp->f_mode & FMODE_READ) {
54870 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54871- if (!pipe->writers && filp->f_version != pipe->w_counter)
54872+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54873 mask |= POLLHUP;
54874 }
54875
54876@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54877 * Most Unices do not set POLLERR for FIFOs but on Linux they
54878 * behave exactly like pipes for poll().
54879 */
54880- if (!pipe->readers)
54881+ if (!atomic_read(&pipe->readers))
54882 mask |= POLLERR;
54883 }
54884
54885@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
54886
54887 __pipe_lock(pipe);
54888 if (file->f_mode & FMODE_READ)
54889- pipe->readers--;
54890+ atomic_dec(&pipe->readers);
54891 if (file->f_mode & FMODE_WRITE)
54892- pipe->writers--;
54893+ atomic_dec(&pipe->writers);
54894
54895- if (pipe->readers || pipe->writers) {
54896+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
54897 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54898 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54899 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
54900 }
54901 spin_lock(&inode->i_lock);
54902- if (!--pipe->files) {
54903+ if (atomic_dec_and_test(&pipe->files)) {
54904 inode->i_pipe = NULL;
54905 kill = 1;
54906 }
54907@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
54908 kfree(pipe);
54909 }
54910
54911-static struct vfsmount *pipe_mnt __read_mostly;
54912+struct vfsmount *pipe_mnt __read_mostly;
54913
54914 /*
54915 * pipefs_dname() is called from d_path().
54916@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
54917 goto fail_iput;
54918
54919 inode->i_pipe = pipe;
54920- pipe->files = 2;
54921- pipe->readers = pipe->writers = 1;
54922+ atomic_set(&pipe->files, 2);
54923+ atomic_set(&pipe->readers, 1);
54924+ atomic_set(&pipe->writers, 1);
54925 inode->i_fop = &pipefifo_fops;
54926
54927 /*
54928@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
54929 spin_lock(&inode->i_lock);
54930 if (inode->i_pipe) {
54931 pipe = inode->i_pipe;
54932- pipe->files++;
54933+ atomic_inc(&pipe->files);
54934 spin_unlock(&inode->i_lock);
54935 } else {
54936 spin_unlock(&inode->i_lock);
54937 pipe = alloc_pipe_info();
54938 if (!pipe)
54939 return -ENOMEM;
54940- pipe->files = 1;
54941+ atomic_set(&pipe->files, 1);
54942 spin_lock(&inode->i_lock);
54943 if (unlikely(inode->i_pipe)) {
54944- inode->i_pipe->files++;
54945+ atomic_inc(&inode->i_pipe->files);
54946 spin_unlock(&inode->i_lock);
54947 free_pipe_info(pipe);
54948 pipe = inode->i_pipe;
54949@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
54950 * opened, even when there is no process writing the FIFO.
54951 */
54952 pipe->r_counter++;
54953- if (pipe->readers++ == 0)
54954+ if (atomic_inc_return(&pipe->readers) == 1)
54955 wake_up_partner(pipe);
54956
54957- if (!is_pipe && !pipe->writers) {
54958+ if (!is_pipe && !atomic_read(&pipe->writers)) {
54959 if ((filp->f_flags & O_NONBLOCK)) {
54960 /* suppress POLLHUP until we have
54961 * seen a writer */
54962@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
54963 * errno=ENXIO when there is no process reading the FIFO.
54964 */
54965 ret = -ENXIO;
54966- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
54967+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
54968 goto err;
54969
54970 pipe->w_counter++;
54971- if (!pipe->writers++)
54972+ if (atomic_inc_return(&pipe->writers) == 1)
54973 wake_up_partner(pipe);
54974
54975- if (!is_pipe && !pipe->readers) {
54976+ if (!is_pipe && !atomic_read(&pipe->readers)) {
54977 if (wait_for_partner(pipe, &pipe->r_counter))
54978 goto err_wr;
54979 }
54980@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
54981 * the process can at least talk to itself.
54982 */
54983
54984- pipe->readers++;
54985- pipe->writers++;
54986+ atomic_inc(&pipe->readers);
54987+ atomic_inc(&pipe->writers);
54988 pipe->r_counter++;
54989 pipe->w_counter++;
54990- if (pipe->readers == 1 || pipe->writers == 1)
54991+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
54992 wake_up_partner(pipe);
54993 break;
54994
54995@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
54996 return 0;
54997
54998 err_rd:
54999- if (!--pipe->readers)
55000+ if (atomic_dec_and_test(&pipe->readers))
55001 wake_up_interruptible(&pipe->wait);
55002 ret = -ERESTARTSYS;
55003 goto err;
55004
55005 err_wr:
55006- if (!--pipe->writers)
55007+ if (atomic_dec_and_test(&pipe->writers))
55008 wake_up_interruptible(&pipe->wait);
55009 ret = -ERESTARTSYS;
55010 goto err;
55011
55012 err:
55013 spin_lock(&inode->i_lock);
55014- if (!--pipe->files) {
55015+ if (atomic_dec_and_test(&pipe->files)) {
55016 inode->i_pipe = NULL;
55017 kill = 1;
55018 }
55019diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
55020index 15af622..0e9f4467 100644
55021--- a/fs/proc/Kconfig
55022+++ b/fs/proc/Kconfig
55023@@ -30,12 +30,12 @@ config PROC_FS
55024
55025 config PROC_KCORE
55026 bool "/proc/kcore support" if !ARM
55027- depends on PROC_FS && MMU
55028+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
55029
55030 config PROC_VMCORE
55031 bool "/proc/vmcore support"
55032- depends on PROC_FS && CRASH_DUMP
55033- default y
55034+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
55035+ default n
55036 help
55037 Exports the dump image of crashed kernel in ELF format.
55038
55039@@ -59,8 +59,8 @@ config PROC_SYSCTL
55040 limited in memory.
55041
55042 config PROC_PAGE_MONITOR
55043- default y
55044- depends on PROC_FS && MMU
55045+ default n
55046+ depends on PROC_FS && MMU && !GRKERNSEC
55047 bool "Enable /proc page monitoring" if EXPERT
55048 help
55049 Various /proc files exist to monitor process memory utilization:
55050diff --git a/fs/proc/array.c b/fs/proc/array.c
55051index cbd0f1b..adec3f0 100644
55052--- a/fs/proc/array.c
55053+++ b/fs/proc/array.c
55054@@ -60,6 +60,7 @@
55055 #include <linux/tty.h>
55056 #include <linux/string.h>
55057 #include <linux/mman.h>
55058+#include <linux/grsecurity.h>
55059 #include <linux/proc_fs.h>
55060 #include <linux/ioport.h>
55061 #include <linux/uaccess.h>
55062@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
55063 seq_putc(m, '\n');
55064 }
55065
55066+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55067+static inline void task_pax(struct seq_file *m, struct task_struct *p)
55068+{
55069+ if (p->mm)
55070+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
55071+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
55072+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
55073+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
55074+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
55075+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
55076+ else
55077+ seq_printf(m, "PaX:\t-----\n");
55078+}
55079+#endif
55080+
55081 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55082 struct pid *pid, struct task_struct *task)
55083 {
55084@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55085 task_cpus_allowed(m, task);
55086 cpuset_task_status_allowed(m, task);
55087 task_context_switch_counts(m, task);
55088+
55089+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55090+ task_pax(m, task);
55091+#endif
55092+
55093+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
55094+ task_grsec_rbac(m, task);
55095+#endif
55096+
55097 return 0;
55098 }
55099
55100+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55101+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55102+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55103+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55104+#endif
55105+
55106 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55107 struct pid *pid, struct task_struct *task, int whole)
55108 {
55109@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55110 char tcomm[sizeof(task->comm)];
55111 unsigned long flags;
55112
55113+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55114+ if (current->exec_id != m->exec_id) {
55115+ gr_log_badprocpid("stat");
55116+ return 0;
55117+ }
55118+#endif
55119+
55120 state = *get_task_state(task);
55121 vsize = eip = esp = 0;
55122 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55123@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55124 gtime = task_gtime(task);
55125 }
55126
55127+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55128+ if (PAX_RAND_FLAGS(mm)) {
55129+ eip = 0;
55130+ esp = 0;
55131+ wchan = 0;
55132+ }
55133+#endif
55134+#ifdef CONFIG_GRKERNSEC_HIDESYM
55135+ wchan = 0;
55136+ eip =0;
55137+ esp =0;
55138+#endif
55139+
55140 /* scale priority and nice values from timeslices to -20..20 */
55141 /* to make it look like a "normal" Unix priority/nice value */
55142 priority = task_prio(task);
55143@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55144 seq_put_decimal_ull(m, ' ', vsize);
55145 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
55146 seq_put_decimal_ull(m, ' ', rsslim);
55147+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55148+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
55149+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
55150+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
55151+#else
55152 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
55153 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
55154 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
55155+#endif
55156 seq_put_decimal_ull(m, ' ', esp);
55157 seq_put_decimal_ull(m, ' ', eip);
55158 /* The signal information here is obsolete.
55159@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55160 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
55161 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
55162
55163- if (mm && permitted) {
55164+ if (mm && permitted
55165+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55166+ && !PAX_RAND_FLAGS(mm)
55167+#endif
55168+ ) {
55169 seq_put_decimal_ull(m, ' ', mm->start_data);
55170 seq_put_decimal_ull(m, ' ', mm->end_data);
55171 seq_put_decimal_ull(m, ' ', mm->start_brk);
55172@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55173 struct pid *pid, struct task_struct *task)
55174 {
55175 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
55176- struct mm_struct *mm = get_task_mm(task);
55177+ struct mm_struct *mm;
55178
55179+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55180+ if (current->exec_id != m->exec_id) {
55181+ gr_log_badprocpid("statm");
55182+ return 0;
55183+ }
55184+#endif
55185+ mm = get_task_mm(task);
55186 if (mm) {
55187 size = task_statm(mm, &shared, &text, &data, &resident);
55188 mmput(mm);
55189@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55190 return 0;
55191 }
55192
55193+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55194+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
55195+{
55196+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
55197+}
55198+#endif
55199+
55200 #ifdef CONFIG_CHECKPOINT_RESTORE
55201 static struct pid *
55202 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
55203diff --git a/fs/proc/base.c b/fs/proc/base.c
55204index c3834da..b402b2b 100644
55205--- a/fs/proc/base.c
55206+++ b/fs/proc/base.c
55207@@ -113,6 +113,14 @@ struct pid_entry {
55208 union proc_op op;
55209 };
55210
55211+struct getdents_callback {
55212+ struct linux_dirent __user * current_dir;
55213+ struct linux_dirent __user * previous;
55214+ struct file * file;
55215+ int count;
55216+ int error;
55217+};
55218+
55219 #define NOD(NAME, MODE, IOP, FOP, OP) { \
55220 .name = (NAME), \
55221 .len = sizeof(NAME) - 1, \
55222@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
55223 if (!mm->arg_end)
55224 goto out_mm; /* Shh! No looking before we're done */
55225
55226+ if (gr_acl_handle_procpidmem(task))
55227+ goto out_mm;
55228+
55229 len = mm->arg_end - mm->arg_start;
55230
55231 if (len > PAGE_SIZE)
55232@@ -237,12 +248,28 @@ out:
55233 return res;
55234 }
55235
55236+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55237+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55238+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55239+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55240+#endif
55241+
55242 static int proc_pid_auxv(struct task_struct *task, char *buffer)
55243 {
55244 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
55245 int res = PTR_ERR(mm);
55246 if (mm && !IS_ERR(mm)) {
55247 unsigned int nwords = 0;
55248+
55249+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55250+ /* allow if we're currently ptracing this task */
55251+ if (PAX_RAND_FLAGS(mm) &&
55252+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
55253+ mmput(mm);
55254+ return 0;
55255+ }
55256+#endif
55257+
55258 do {
55259 nwords += 2;
55260 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
55261@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
55262 }
55263
55264
55265-#ifdef CONFIG_KALLSYMS
55266+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55267 /*
55268 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
55269 * Returns the resolved symbol. If that fails, simply return the address.
55270@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
55271 mutex_unlock(&task->signal->cred_guard_mutex);
55272 }
55273
55274-#ifdef CONFIG_STACKTRACE
55275+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55276
55277 #define MAX_STACK_TRACE_DEPTH 64
55278
55279@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
55280 return count;
55281 }
55282
55283-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55284+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55285 static int proc_pid_syscall(struct task_struct *task, char *buffer)
55286 {
55287 long nr;
55288@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
55289 /************************************************************************/
55290
55291 /* permission checks */
55292-static int proc_fd_access_allowed(struct inode *inode)
55293+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
55294 {
55295 struct task_struct *task;
55296 int allowed = 0;
55297@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
55298 */
55299 task = get_proc_task(inode);
55300 if (task) {
55301- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55302+ if (log)
55303+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55304+ else
55305+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55306 put_task_struct(task);
55307 }
55308 return allowed;
55309@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
55310 struct task_struct *task,
55311 int hide_pid_min)
55312 {
55313+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55314+ return false;
55315+
55316+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55317+ rcu_read_lock();
55318+ {
55319+ const struct cred *tmpcred = current_cred();
55320+ const struct cred *cred = __task_cred(task);
55321+
55322+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
55323+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55324+ || in_group_p(grsec_proc_gid)
55325+#endif
55326+ ) {
55327+ rcu_read_unlock();
55328+ return true;
55329+ }
55330+ }
55331+ rcu_read_unlock();
55332+
55333+ if (!pid->hide_pid)
55334+ return false;
55335+#endif
55336+
55337 if (pid->hide_pid < hide_pid_min)
55338 return true;
55339 if (in_group_p(pid->pid_gid))
55340 return true;
55341+
55342 return ptrace_may_access(task, PTRACE_MODE_READ);
55343 }
55344
55345@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
55346 put_task_struct(task);
55347
55348 if (!has_perms) {
55349+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55350+ {
55351+#else
55352 if (pid->hide_pid == 2) {
55353+#endif
55354 /*
55355 * Let's make getdents(), stat(), and open()
55356 * consistent with each other. If a process
55357@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55358 if (!task)
55359 return -ESRCH;
55360
55361+ if (gr_acl_handle_procpidmem(task)) {
55362+ put_task_struct(task);
55363+ return -EPERM;
55364+ }
55365+
55366 mm = mm_access(task, mode);
55367 put_task_struct(task);
55368
55369@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55370
55371 file->private_data = mm;
55372
55373+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55374+ file->f_version = current->exec_id;
55375+#endif
55376+
55377 return 0;
55378 }
55379
55380@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55381 ssize_t copied;
55382 char *page;
55383
55384+#ifdef CONFIG_GRKERNSEC
55385+ if (write)
55386+ return -EPERM;
55387+#endif
55388+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55389+ if (file->f_version != current->exec_id) {
55390+ gr_log_badprocpid("mem");
55391+ return 0;
55392+ }
55393+#endif
55394+
55395 if (!mm)
55396 return 0;
55397
55398@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55399 goto free;
55400
55401 while (count > 0) {
55402- int this_len = min_t(int, count, PAGE_SIZE);
55403+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
55404
55405 if (write && copy_from_user(page, buf, this_len)) {
55406 copied = -EFAULT;
55407@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55408 if (!mm)
55409 return 0;
55410
55411+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55412+ if (file->f_version != current->exec_id) {
55413+ gr_log_badprocpid("environ");
55414+ return 0;
55415+ }
55416+#endif
55417+
55418 page = (char *)__get_free_page(GFP_TEMPORARY);
55419 if (!page)
55420 return -ENOMEM;
55421@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55422 goto free;
55423 while (count > 0) {
55424 size_t this_len, max_len;
55425- int retval;
55426+ ssize_t retval;
55427
55428 if (src >= (mm->env_end - mm->env_start))
55429 break;
55430@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
55431 int error = -EACCES;
55432
55433 /* Are we allowed to snoop on the tasks file descriptors? */
55434- if (!proc_fd_access_allowed(inode))
55435+ if (!proc_fd_access_allowed(inode, 0))
55436 goto out;
55437
55438 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55439@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
55440 struct path path;
55441
55442 /* Are we allowed to snoop on the tasks file descriptors? */
55443- if (!proc_fd_access_allowed(inode))
55444- goto out;
55445+ /* logging this is needed for learning on chromium to work properly,
55446+ but we don't want to flood the logs from 'ps' which does a readlink
55447+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
55448+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
55449+ */
55450+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
55451+ if (!proc_fd_access_allowed(inode,0))
55452+ goto out;
55453+ } else {
55454+ if (!proc_fd_access_allowed(inode,1))
55455+ goto out;
55456+ }
55457
55458 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55459 if (error)
55460@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
55461 rcu_read_lock();
55462 cred = __task_cred(task);
55463 inode->i_uid = cred->euid;
55464+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55465+ inode->i_gid = grsec_proc_gid;
55466+#else
55467 inode->i_gid = cred->egid;
55468+#endif
55469 rcu_read_unlock();
55470 }
55471 security_task_to_inode(task, inode);
55472@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55473 return -ENOENT;
55474 }
55475 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55476+#ifdef CONFIG_GRKERNSEC_PROC_USER
55477+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55478+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55479+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55480+#endif
55481 task_dumpable(task)) {
55482 cred = __task_cred(task);
55483 stat->uid = cred->euid;
55484+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55485+ stat->gid = grsec_proc_gid;
55486+#else
55487 stat->gid = cred->egid;
55488+#endif
55489 }
55490 }
55491 rcu_read_unlock();
55492@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
55493
55494 if (task) {
55495 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55496+#ifdef CONFIG_GRKERNSEC_PROC_USER
55497+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55498+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55499+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55500+#endif
55501 task_dumpable(task)) {
55502 rcu_read_lock();
55503 cred = __task_cred(task);
55504 inode->i_uid = cred->euid;
55505+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55506+ inode->i_gid = grsec_proc_gid;
55507+#else
55508 inode->i_gid = cred->egid;
55509+#endif
55510 rcu_read_unlock();
55511 } else {
55512 inode->i_uid = GLOBAL_ROOT_UID;
55513@@ -2196,6 +2314,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
55514 if (!task)
55515 goto out_no_task;
55516
55517+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55518+ goto out;
55519+
55520 /*
55521 * Yes, it does not scale. And it should not. Don't add
55522 * new entries into /proc/<tgid>/ without very good reasons.
55523@@ -2240,6 +2361,9 @@ static int proc_pident_readdir(struct file *filp,
55524 if (!task)
55525 goto out_no_task;
55526
55527+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55528+ goto out;
55529+
55530 ret = 0;
55531 i = filp->f_pos;
55532 switch (i) {
55533@@ -2653,7 +2777,7 @@ static const struct pid_entry tgid_base_stuff[] = {
55534 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
55535 #endif
55536 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55537-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55538+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55539 INF("syscall", S_IRUGO, proc_pid_syscall),
55540 #endif
55541 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55542@@ -2678,10 +2802,10 @@ static const struct pid_entry tgid_base_stuff[] = {
55543 #ifdef CONFIG_SECURITY
55544 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55545 #endif
55546-#ifdef CONFIG_KALLSYMS
55547+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55548 INF("wchan", S_IRUGO, proc_pid_wchan),
55549 #endif
55550-#ifdef CONFIG_STACKTRACE
55551+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55552 ONE("stack", S_IRUGO, proc_pid_stack),
55553 #endif
55554 #ifdef CONFIG_SCHEDSTATS
55555@@ -2715,6 +2839,9 @@ static const struct pid_entry tgid_base_stuff[] = {
55556 #ifdef CONFIG_HARDWALL
55557 INF("hardwall", S_IRUGO, proc_pid_hardwall),
55558 #endif
55559+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55560+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
55561+#endif
55562 #ifdef CONFIG_USER_NS
55563 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
55564 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
55565@@ -2847,7 +2974,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
55566 if (!inode)
55567 goto out;
55568
55569+#ifdef CONFIG_GRKERNSEC_PROC_USER
55570+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
55571+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55572+ inode->i_gid = grsec_proc_gid;
55573+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
55574+#else
55575 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
55576+#endif
55577 inode->i_op = &proc_tgid_base_inode_operations;
55578 inode->i_fop = &proc_tgid_base_operations;
55579 inode->i_flags|=S_IMMUTABLE;
55580@@ -2885,7 +3019,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
55581 if (!task)
55582 goto out;
55583
55584+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55585+ goto out_put_task;
55586+
55587 result = proc_pid_instantiate(dir, dentry, task, NULL);
55588+out_put_task:
55589 put_task_struct(task);
55590 out:
55591 return result;
55592@@ -2948,6 +3086,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
55593 static int fake_filldir(void *buf, const char *name, int namelen,
55594 loff_t offset, u64 ino, unsigned d_type)
55595 {
55596+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
55597+ __buf->error = -EINVAL;
55598 return 0;
55599 }
55600
55601@@ -3007,7 +3147,7 @@ static const struct pid_entry tid_base_stuff[] = {
55602 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
55603 #endif
55604 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55605-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55606+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55607 INF("syscall", S_IRUGO, proc_pid_syscall),
55608 #endif
55609 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55610@@ -3034,10 +3174,10 @@ static const struct pid_entry tid_base_stuff[] = {
55611 #ifdef CONFIG_SECURITY
55612 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55613 #endif
55614-#ifdef CONFIG_KALLSYMS
55615+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55616 INF("wchan", S_IRUGO, proc_pid_wchan),
55617 #endif
55618-#ifdef CONFIG_STACKTRACE
55619+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55620 ONE("stack", S_IRUGO, proc_pid_stack),
55621 #endif
55622 #ifdef CONFIG_SCHEDSTATS
55623diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
55624index 82676e3..5f8518a 100644
55625--- a/fs/proc/cmdline.c
55626+++ b/fs/proc/cmdline.c
55627@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
55628
55629 static int __init proc_cmdline_init(void)
55630 {
55631+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55632+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
55633+#else
55634 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
55635+#endif
55636 return 0;
55637 }
55638 module_init(proc_cmdline_init);
55639diff --git a/fs/proc/devices.c b/fs/proc/devices.c
55640index b143471..bb105e5 100644
55641--- a/fs/proc/devices.c
55642+++ b/fs/proc/devices.c
55643@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
55644
55645 static int __init proc_devices_init(void)
55646 {
55647+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55648+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
55649+#else
55650 proc_create("devices", 0, NULL, &proc_devinfo_operations);
55651+#endif
55652 return 0;
55653 }
55654 module_init(proc_devices_init);
55655diff --git a/fs/proc/fd.c b/fs/proc/fd.c
55656index d7a4a28..0201742 100644
55657--- a/fs/proc/fd.c
55658+++ b/fs/proc/fd.c
55659@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
55660 if (!task)
55661 return -ENOENT;
55662
55663- files = get_files_struct(task);
55664+ if (!gr_acl_handle_procpidmem(task))
55665+ files = get_files_struct(task);
55666 put_task_struct(task);
55667
55668 if (files) {
55669@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
55670 */
55671 int proc_fd_permission(struct inode *inode, int mask)
55672 {
55673+ struct task_struct *task;
55674 int rv = generic_permission(inode, mask);
55675- if (rv == 0)
55676- return 0;
55677+
55678 if (task_pid(current) == proc_pid(inode))
55679 rv = 0;
55680+
55681+ task = get_proc_task(inode);
55682+ if (task == NULL)
55683+ return rv;
55684+
55685+ if (gr_acl_handle_procpidmem(task))
55686+ rv = -EACCES;
55687+
55688+ put_task_struct(task);
55689+
55690 return rv;
55691 }
55692
55693diff --git a/fs/proc/inode.c b/fs/proc/inode.c
55694index 073aea6..0630370 100644
55695--- a/fs/proc/inode.c
55696+++ b/fs/proc/inode.c
55697@@ -23,11 +23,17 @@
55698 #include <linux/slab.h>
55699 #include <linux/mount.h>
55700 #include <linux/magic.h>
55701+#include <linux/grsecurity.h>
55702
55703 #include <asm/uaccess.h>
55704
55705 #include "internal.h"
55706
55707+#ifdef CONFIG_PROC_SYSCTL
55708+extern const struct inode_operations proc_sys_inode_operations;
55709+extern const struct inode_operations proc_sys_dir_operations;
55710+#endif
55711+
55712 static void proc_evict_inode(struct inode *inode)
55713 {
55714 struct proc_dir_entry *de;
55715@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
55716 ns = PROC_I(inode)->ns.ns;
55717 if (ns_ops && ns)
55718 ns_ops->put(ns);
55719+
55720+#ifdef CONFIG_PROC_SYSCTL
55721+ if (inode->i_op == &proc_sys_inode_operations ||
55722+ inode->i_op == &proc_sys_dir_operations)
55723+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
55724+#endif
55725+
55726 }
55727
55728 static struct kmem_cache * proc_inode_cachep;
55729@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
55730 if (de->mode) {
55731 inode->i_mode = de->mode;
55732 inode->i_uid = de->uid;
55733+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55734+ inode->i_gid = grsec_proc_gid;
55735+#else
55736 inode->i_gid = de->gid;
55737+#endif
55738 }
55739 if (de->size)
55740 inode->i_size = de->size;
55741diff --git a/fs/proc/internal.h b/fs/proc/internal.h
55742index d600fb0..3b495fe 100644
55743--- a/fs/proc/internal.h
55744+++ b/fs/proc/internal.h
55745@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
55746 struct pid *, struct task_struct *);
55747 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
55748 struct pid *, struct task_struct *);
55749+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55750+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
55751+#endif
55752
55753 /*
55754 * base.c
55755diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
55756index 0a22194..a9fc8c1 100644
55757--- a/fs/proc/kcore.c
55758+++ b/fs/proc/kcore.c
55759@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55760 * the addresses in the elf_phdr on our list.
55761 */
55762 start = kc_offset_to_vaddr(*fpos - elf_buflen);
55763- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
55764+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
55765+ if (tsz > buflen)
55766 tsz = buflen;
55767-
55768+
55769 while (buflen) {
55770 struct kcore_list *m;
55771
55772@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55773 kfree(elf_buf);
55774 } else {
55775 if (kern_addr_valid(start)) {
55776- unsigned long n;
55777+ char *elf_buf;
55778+ mm_segment_t oldfs;
55779
55780- n = copy_to_user(buffer, (char *)start, tsz);
55781- /*
55782- * We cannot distinguish between fault on source
55783- * and fault on destination. When this happens
55784- * we clear too and hope it will trigger the
55785- * EFAULT again.
55786- */
55787- if (n) {
55788- if (clear_user(buffer + tsz - n,
55789- n))
55790+ elf_buf = kmalloc(tsz, GFP_KERNEL);
55791+ if (!elf_buf)
55792+ return -ENOMEM;
55793+ oldfs = get_fs();
55794+ set_fs(KERNEL_DS);
55795+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
55796+ set_fs(oldfs);
55797+ if (copy_to_user(buffer, elf_buf, tsz)) {
55798+ kfree(elf_buf);
55799 return -EFAULT;
55800+ }
55801 }
55802+ set_fs(oldfs);
55803+ kfree(elf_buf);
55804 } else {
55805 if (clear_user(buffer, tsz))
55806 return -EFAULT;
55807@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55808
55809 static int open_kcore(struct inode *inode, struct file *filp)
55810 {
55811+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55812+ return -EPERM;
55813+#endif
55814 if (!capable(CAP_SYS_RAWIO))
55815 return -EPERM;
55816 if (kcore_need_update)
55817diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55818index 5aa847a..f77c8d4 100644
55819--- a/fs/proc/meminfo.c
55820+++ b/fs/proc/meminfo.c
55821@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55822 vmi.used >> 10,
55823 vmi.largest_chunk >> 10
55824 #ifdef CONFIG_MEMORY_FAILURE
55825- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55826+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55827 #endif
55828 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55829 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
55830diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
55831index ccfd99b..1b7e255 100644
55832--- a/fs/proc/nommu.c
55833+++ b/fs/proc/nommu.c
55834@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
55835 if (len < 1)
55836 len = 1;
55837 seq_printf(m, "%*c", len, ' ');
55838- seq_path(m, &file->f_path, "");
55839+ seq_path(m, &file->f_path, "\n\\");
55840 }
55841
55842 seq_putc(m, '\n');
55843diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
55844index 986e832..6e8e859 100644
55845--- a/fs/proc/proc_net.c
55846+++ b/fs/proc/proc_net.c
55847@@ -23,6 +23,7 @@
55848 #include <linux/nsproxy.h>
55849 #include <net/net_namespace.h>
55850 #include <linux/seq_file.h>
55851+#include <linux/grsecurity.h>
55852
55853 #include "internal.h"
55854
55855@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
55856 struct task_struct *task;
55857 struct nsproxy *ns;
55858 struct net *net = NULL;
55859+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55860+ const struct cred *cred = current_cred();
55861+#endif
55862+
55863+#ifdef CONFIG_GRKERNSEC_PROC_USER
55864+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
55865+ return net;
55866+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55867+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
55868+ return net;
55869+#endif
55870
55871 rcu_read_lock();
55872 task = pid_task(proc_pid(dir), PIDTYPE_PID);
55873diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
55874index ac05f33..1e6dc7e 100644
55875--- a/fs/proc/proc_sysctl.c
55876+++ b/fs/proc/proc_sysctl.c
55877@@ -13,11 +13,15 @@
55878 #include <linux/module.h>
55879 #include "internal.h"
55880
55881+extern int gr_handle_chroot_sysctl(const int op);
55882+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
55883+ const int op);
55884+
55885 static const struct dentry_operations proc_sys_dentry_operations;
55886 static const struct file_operations proc_sys_file_operations;
55887-static const struct inode_operations proc_sys_inode_operations;
55888+const struct inode_operations proc_sys_inode_operations;
55889 static const struct file_operations proc_sys_dir_file_operations;
55890-static const struct inode_operations proc_sys_dir_operations;
55891+const struct inode_operations proc_sys_dir_operations;
55892
55893 void proc_sys_poll_notify(struct ctl_table_poll *poll)
55894 {
55895@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
55896
55897 err = NULL;
55898 d_set_d_op(dentry, &proc_sys_dentry_operations);
55899+
55900+ gr_handle_proc_create(dentry, inode);
55901+
55902 d_add(dentry, inode);
55903
55904 out:
55905@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55906 struct inode *inode = file_inode(filp);
55907 struct ctl_table_header *head = grab_header(inode);
55908 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
55909+ int op = write ? MAY_WRITE : MAY_READ;
55910 ssize_t error;
55911 size_t res;
55912
55913@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55914 * and won't be until we finish.
55915 */
55916 error = -EPERM;
55917- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
55918+ if (sysctl_perm(head, table, op))
55919 goto out;
55920
55921 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55922@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55923 if (!table->proc_handler)
55924 goto out;
55925
55926+#ifdef CONFIG_GRKERNSEC
55927+ error = -EPERM;
55928+ if (gr_handle_chroot_sysctl(op))
55929+ goto out;
55930+ dget(filp->f_path.dentry);
55931+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55932+ dput(filp->f_path.dentry);
55933+ goto out;
55934+ }
55935+ dput(filp->f_path.dentry);
55936+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55937+ goto out;
55938+ if (write && !capable(CAP_SYS_ADMIN))
55939+ goto out;
55940+#endif
55941+
55942 /* careful: calling conventions are nasty here */
55943 res = count;
55944 error = table->proc_handler(table, write, buf, &res, ppos);
55945@@ -598,6 +622,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55946 return -ENOMEM;
55947 } else {
55948 d_set_d_op(child, &proc_sys_dentry_operations);
55949+
55950+ gr_handle_proc_create(child, inode);
55951+
55952 d_add(child, inode);
55953 }
55954 } else {
55955@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55956 if ((*pos)++ < file->f_pos)
55957 return 0;
55958
55959+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55960+ return 0;
55961+
55962 if (unlikely(S_ISLNK(table->mode)))
55963 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55964 else
55965@@ -751,6 +781,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55966 if (IS_ERR(head))
55967 return PTR_ERR(head);
55968
55969+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55970+ return -ENOENT;
55971+
55972 generic_fillattr(inode, stat);
55973 if (table)
55974 stat->mode = (stat->mode & S_IFMT) | table->mode;
55975@@ -773,13 +806,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55976 .llseek = generic_file_llseek,
55977 };
55978
55979-static const struct inode_operations proc_sys_inode_operations = {
55980+const struct inode_operations proc_sys_inode_operations = {
55981 .permission = proc_sys_permission,
55982 .setattr = proc_sys_setattr,
55983 .getattr = proc_sys_getattr,
55984 };
55985
55986-static const struct inode_operations proc_sys_dir_operations = {
55987+const struct inode_operations proc_sys_dir_operations = {
55988 .lookup = proc_sys_lookup,
55989 .permission = proc_sys_permission,
55990 .setattr = proc_sys_setattr,
55991@@ -855,7 +888,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55992 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55993 const char *name, int namelen)
55994 {
55995- struct ctl_table *table;
55996+ ctl_table_no_const *table;
55997 struct ctl_dir *new;
55998 struct ctl_node *node;
55999 char *new_name;
56000@@ -867,7 +900,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
56001 return NULL;
56002
56003 node = (struct ctl_node *)(new + 1);
56004- table = (struct ctl_table *)(node + 1);
56005+ table = (ctl_table_no_const *)(node + 1);
56006 new_name = (char *)(table + 2);
56007 memcpy(new_name, name, namelen);
56008 new_name[namelen] = '\0';
56009@@ -1036,7 +1069,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
56010 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
56011 struct ctl_table_root *link_root)
56012 {
56013- struct ctl_table *link_table, *entry, *link;
56014+ ctl_table_no_const *link_table, *link;
56015+ struct ctl_table *entry;
56016 struct ctl_table_header *links;
56017 struct ctl_node *node;
56018 char *link_name;
56019@@ -1059,7 +1093,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
56020 return NULL;
56021
56022 node = (struct ctl_node *)(links + 1);
56023- link_table = (struct ctl_table *)(node + nr_entries);
56024+ link_table = (ctl_table_no_const *)(node + nr_entries);
56025 link_name = (char *)&link_table[nr_entries + 1];
56026
56027 for (link = link_table, entry = table; entry->procname; link++, entry++) {
56028@@ -1307,8 +1341,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56029 struct ctl_table_header ***subheader, struct ctl_table_set *set,
56030 struct ctl_table *table)
56031 {
56032- struct ctl_table *ctl_table_arg = NULL;
56033- struct ctl_table *entry, *files;
56034+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
56035+ struct ctl_table *entry;
56036 int nr_files = 0;
56037 int nr_dirs = 0;
56038 int err = -ENOMEM;
56039@@ -1320,10 +1354,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56040 nr_files++;
56041 }
56042
56043- files = table;
56044 /* If there are mixed files and directories we need a new table */
56045 if (nr_dirs && nr_files) {
56046- struct ctl_table *new;
56047+ ctl_table_no_const *new;
56048 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
56049 GFP_KERNEL);
56050 if (!files)
56051@@ -1341,7 +1374,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56052 /* Register everything except a directory full of subdirectories */
56053 if (nr_files || !nr_dirs) {
56054 struct ctl_table_header *header;
56055- header = __register_sysctl_table(set, path, files);
56056+ header = __register_sysctl_table(set, path, files ? files : table);
56057 if (!header) {
56058 kfree(ctl_table_arg);
56059 goto out;
56060diff --git a/fs/proc/root.c b/fs/proc/root.c
56061index 41a6ea9..23eaa92 100644
56062--- a/fs/proc/root.c
56063+++ b/fs/proc/root.c
56064@@ -182,7 +182,15 @@ void __init proc_root_init(void)
56065 #ifdef CONFIG_PROC_DEVICETREE
56066 proc_device_tree_init();
56067 #endif
56068+#ifdef CONFIG_GRKERNSEC_PROC_ADD
56069+#ifdef CONFIG_GRKERNSEC_PROC_USER
56070+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
56071+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56072+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
56073+#endif
56074+#else
56075 proc_mkdir("bus", NULL);
56076+#endif
56077 proc_sys_init();
56078 }
56079
56080diff --git a/fs/proc/self.c b/fs/proc/self.c
56081index 6b6a993..807cccc 100644
56082--- a/fs/proc/self.c
56083+++ b/fs/proc/self.c
56084@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
56085 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
56086 void *cookie)
56087 {
56088- char *s = nd_get_link(nd);
56089+ const char *s = nd_get_link(nd);
56090 if (!IS_ERR(s))
56091 kfree(s);
56092 }
56093diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
56094index 3e636d8..83e3b71 100644
56095--- a/fs/proc/task_mmu.c
56096+++ b/fs/proc/task_mmu.c
56097@@ -11,12 +11,19 @@
56098 #include <linux/rmap.h>
56099 #include <linux/swap.h>
56100 #include <linux/swapops.h>
56101+#include <linux/grsecurity.h>
56102
56103 #include <asm/elf.h>
56104 #include <asm/uaccess.h>
56105 #include <asm/tlbflush.h>
56106 #include "internal.h"
56107
56108+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56109+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
56110+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
56111+ _mm->pax_flags & MF_PAX_SEGMEXEC))
56112+#endif
56113+
56114 void task_mem(struct seq_file *m, struct mm_struct *mm)
56115 {
56116 unsigned long data, text, lib, swap;
56117@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56118 "VmExe:\t%8lu kB\n"
56119 "VmLib:\t%8lu kB\n"
56120 "VmPTE:\t%8lu kB\n"
56121- "VmSwap:\t%8lu kB\n",
56122- hiwater_vm << (PAGE_SHIFT-10),
56123+ "VmSwap:\t%8lu kB\n"
56124+
56125+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56126+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
56127+#endif
56128+
56129+ ,hiwater_vm << (PAGE_SHIFT-10),
56130 total_vm << (PAGE_SHIFT-10),
56131 mm->locked_vm << (PAGE_SHIFT-10),
56132 mm->pinned_vm << (PAGE_SHIFT-10),
56133@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56134 data << (PAGE_SHIFT-10),
56135 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
56136 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
56137- swap << (PAGE_SHIFT-10));
56138+ swap << (PAGE_SHIFT-10)
56139+
56140+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56141+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56142+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
56143+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
56144+#else
56145+ , mm->context.user_cs_base
56146+ , mm->context.user_cs_limit
56147+#endif
56148+#endif
56149+
56150+ );
56151 }
56152
56153 unsigned long task_vsize(struct mm_struct *mm)
56154@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56155 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
56156 }
56157
56158- /* We don't show the stack guard page in /proc/maps */
56159+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56160+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
56161+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
56162+#else
56163 start = vma->vm_start;
56164- if (stack_guard_page_start(vma, start))
56165- start += PAGE_SIZE;
56166 end = vma->vm_end;
56167- if (stack_guard_page_end(vma, end))
56168- end -= PAGE_SIZE;
56169+#endif
56170
56171 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
56172 start,
56173@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56174 flags & VM_WRITE ? 'w' : '-',
56175 flags & VM_EXEC ? 'x' : '-',
56176 flags & VM_MAYSHARE ? 's' : 'p',
56177+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56178+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
56179+#else
56180 pgoff,
56181+#endif
56182 MAJOR(dev), MINOR(dev), ino, &len);
56183
56184 /*
56185@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56186 */
56187 if (file) {
56188 pad_len_spaces(m, len);
56189- seq_path(m, &file->f_path, "\n");
56190+ seq_path(m, &file->f_path, "\n\\");
56191 goto done;
56192 }
56193
56194@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56195 * Thread stack in /proc/PID/task/TID/maps or
56196 * the main process stack.
56197 */
56198- if (!is_pid || (vma->vm_start <= mm->start_stack &&
56199- vma->vm_end >= mm->start_stack)) {
56200+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
56201+ (vma->vm_start <= mm->start_stack &&
56202+ vma->vm_end >= mm->start_stack)) {
56203 name = "[stack]";
56204 } else {
56205 /* Thread stack in /proc/PID/maps */
56206@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
56207 struct proc_maps_private *priv = m->private;
56208 struct task_struct *task = priv->task;
56209
56210+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56211+ if (current->exec_id != m->exec_id) {
56212+ gr_log_badprocpid("maps");
56213+ return 0;
56214+ }
56215+#endif
56216+
56217 show_map_vma(m, vma, is_pid);
56218
56219 if (m->count < m->size) /* vma is copied successfully */
56220@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56221 .private = &mss,
56222 };
56223
56224+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56225+ if (current->exec_id != m->exec_id) {
56226+ gr_log_badprocpid("smaps");
56227+ return 0;
56228+ }
56229+#endif
56230 memset(&mss, 0, sizeof mss);
56231- mss.vma = vma;
56232- /* mmap_sem is held in m_start */
56233- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56234- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56235-
56236+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56237+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
56238+#endif
56239+ mss.vma = vma;
56240+ /* mmap_sem is held in m_start */
56241+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56242+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56243+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56244+ }
56245+#endif
56246 show_map_vma(m, vma, is_pid);
56247
56248 seq_printf(m,
56249@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56250 "KernelPageSize: %8lu kB\n"
56251 "MMUPageSize: %8lu kB\n"
56252 "Locked: %8lu kB\n",
56253+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56254+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
56255+#else
56256 (vma->vm_end - vma->vm_start) >> 10,
56257+#endif
56258 mss.resident >> 10,
56259 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
56260 mss.shared_clean >> 10,
56261@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56262 int n;
56263 char buffer[50];
56264
56265+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56266+ if (current->exec_id != m->exec_id) {
56267+ gr_log_badprocpid("numa_maps");
56268+ return 0;
56269+ }
56270+#endif
56271+
56272 if (!mm)
56273 return 0;
56274
56275@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56276 mpol_to_str(buffer, sizeof(buffer), pol);
56277 mpol_cond_put(pol);
56278
56279+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56280+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
56281+#else
56282 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
56283+#endif
56284
56285 if (file) {
56286 seq_printf(m, " file=");
56287- seq_path(m, &file->f_path, "\n\t= ");
56288+ seq_path(m, &file->f_path, "\n\t\\= ");
56289 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
56290 seq_printf(m, " heap");
56291 } else {
56292diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
56293index 56123a6..5a2f6ec 100644
56294--- a/fs/proc/task_nommu.c
56295+++ b/fs/proc/task_nommu.c
56296@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56297 else
56298 bytes += kobjsize(mm);
56299
56300- if (current->fs && current->fs->users > 1)
56301+ if (current->fs && atomic_read(&current->fs->users) > 1)
56302 sbytes += kobjsize(current->fs);
56303 else
56304 bytes += kobjsize(current->fs);
56305@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
56306
56307 if (file) {
56308 pad_len_spaces(m, len);
56309- seq_path(m, &file->f_path, "");
56310+ seq_path(m, &file->f_path, "\n\\");
56311 } else if (mm) {
56312 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
56313
56314diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
56315index 17f7e08..e4b1529 100644
56316--- a/fs/proc/vmcore.c
56317+++ b/fs/proc/vmcore.c
56318@@ -99,9 +99,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
56319 nr_bytes = count;
56320
56321 /* If pfn is not ram, return zeros for sparse dump files */
56322- if (pfn_is_ram(pfn) == 0)
56323- memset(buf, 0, nr_bytes);
56324- else {
56325+ if (pfn_is_ram(pfn) == 0) {
56326+ if (userbuf) {
56327+ if (clear_user((char __force_user *)buf, nr_bytes))
56328+ return -EFAULT;
56329+ } else
56330+ memset(buf, 0, nr_bytes);
56331+ } else {
56332 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
56333 offset, userbuf);
56334 if (tmp < 0)
56335@@ -186,7 +190,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
56336 if (tsz > nr_bytes)
56337 tsz = nr_bytes;
56338
56339- tmp = read_from_oldmem(buffer, tsz, &start, 1);
56340+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
56341 if (tmp < 0)
56342 return tmp;
56343 buflen -= tsz;
56344diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
56345index b00fcc9..e0c6381 100644
56346--- a/fs/qnx6/qnx6.h
56347+++ b/fs/qnx6/qnx6.h
56348@@ -74,7 +74,7 @@ enum {
56349 BYTESEX_BE,
56350 };
56351
56352-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56353+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56354 {
56355 if (sbi->s_bytesex == BYTESEX_LE)
56356 return le64_to_cpu((__force __le64)n);
56357@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
56358 return (__force __fs64)cpu_to_be64(n);
56359 }
56360
56361-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56362+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56363 {
56364 if (sbi->s_bytesex == BYTESEX_LE)
56365 return le32_to_cpu((__force __le32)n);
56366diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
56367index 16e8abb..2dcf914 100644
56368--- a/fs/quota/netlink.c
56369+++ b/fs/quota/netlink.c
56370@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
56371 void quota_send_warning(struct kqid qid, dev_t dev,
56372 const char warntype)
56373 {
56374- static atomic_t seq;
56375+ static atomic_unchecked_t seq;
56376 struct sk_buff *skb;
56377 void *msg_head;
56378 int ret;
56379@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
56380 "VFS: Not enough memory to send quota warning.\n");
56381 return;
56382 }
56383- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
56384+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
56385 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
56386 if (!msg_head) {
56387 printk(KERN_ERR
56388diff --git a/fs/read_write.c b/fs/read_write.c
56389index 2cefa41..c7e2fe0 100644
56390--- a/fs/read_write.c
56391+++ b/fs/read_write.c
56392@@ -411,7 +411,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
56393
56394 old_fs = get_fs();
56395 set_fs(get_ds());
56396- p = (__force const char __user *)buf;
56397+ p = (const char __force_user *)buf;
56398 if (count > MAX_RW_COUNT)
56399 count = MAX_RW_COUNT;
56400 if (file->f_op->write)
56401diff --git a/fs/readdir.c b/fs/readdir.c
56402index fee38e0..12fdf47 100644
56403--- a/fs/readdir.c
56404+++ b/fs/readdir.c
56405@@ -17,6 +17,7 @@
56406 #include <linux/security.h>
56407 #include <linux/syscalls.h>
56408 #include <linux/unistd.h>
56409+#include <linux/namei.h>
56410
56411 #include <asm/uaccess.h>
56412
56413@@ -67,6 +68,7 @@ struct old_linux_dirent {
56414
56415 struct readdir_callback {
56416 struct old_linux_dirent __user * dirent;
56417+ struct file * file;
56418 int result;
56419 };
56420
56421@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
56422 buf->result = -EOVERFLOW;
56423 return -EOVERFLOW;
56424 }
56425+
56426+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56427+ return 0;
56428+
56429 buf->result++;
56430 dirent = buf->dirent;
56431 if (!access_ok(VERIFY_WRITE, dirent,
56432@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
56433
56434 buf.result = 0;
56435 buf.dirent = dirent;
56436+ buf.file = f.file;
56437
56438 error = vfs_readdir(f.file, fillonedir, &buf);
56439 if (buf.result)
56440@@ -139,6 +146,7 @@ struct linux_dirent {
56441 struct getdents_callback {
56442 struct linux_dirent __user * current_dir;
56443 struct linux_dirent __user * previous;
56444+ struct file * file;
56445 int count;
56446 int error;
56447 };
56448@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
56449 buf->error = -EOVERFLOW;
56450 return -EOVERFLOW;
56451 }
56452+
56453+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56454+ return 0;
56455+
56456 dirent = buf->previous;
56457 if (dirent) {
56458 if (__put_user(offset, &dirent->d_off))
56459@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56460 buf.previous = NULL;
56461 buf.count = count;
56462 buf.error = 0;
56463+ buf.file = f.file;
56464
56465 error = vfs_readdir(f.file, filldir, &buf);
56466 if (error >= 0)
56467@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56468 struct getdents_callback64 {
56469 struct linux_dirent64 __user * current_dir;
56470 struct linux_dirent64 __user * previous;
56471+ struct file *file;
56472 int count;
56473 int error;
56474 };
56475@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
56476 buf->error = -EINVAL; /* only used if we fail.. */
56477 if (reclen > buf->count)
56478 return -EINVAL;
56479+
56480+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56481+ return 0;
56482+
56483 dirent = buf->previous;
56484 if (dirent) {
56485 if (__put_user(offset, &dirent->d_off))
56486@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56487
56488 buf.current_dir = dirent;
56489 buf.previous = NULL;
56490+ buf.file = f.file;
56491 buf.count = count;
56492 buf.error = 0;
56493
56494@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56495 error = buf.error;
56496 lastdirent = buf.previous;
56497 if (lastdirent) {
56498- typeof(lastdirent->d_off) d_off = f.file->f_pos;
56499+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
56500 if (__put_user(d_off, &lastdirent->d_off))
56501 error = -EFAULT;
56502 else
56503diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
56504index 2b7882b..1c5ef48 100644
56505--- a/fs/reiserfs/do_balan.c
56506+++ b/fs/reiserfs/do_balan.c
56507@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
56508 return;
56509 }
56510
56511- atomic_inc(&(fs_generation(tb->tb_sb)));
56512+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
56513 do_balance_starts(tb);
56514
56515 /* balance leaf returns 0 except if combining L R and S into
56516diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
56517index 33532f7..4846ade 100644
56518--- a/fs/reiserfs/procfs.c
56519+++ b/fs/reiserfs/procfs.c
56520@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
56521 "SMALL_TAILS " : "NO_TAILS ",
56522 replay_only(sb) ? "REPLAY_ONLY " : "",
56523 convert_reiserfs(sb) ? "CONV " : "",
56524- atomic_read(&r->s_generation_counter),
56525+ atomic_read_unchecked(&r->s_generation_counter),
56526 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
56527 SF(s_do_balance), SF(s_unneeded_left_neighbor),
56528 SF(s_good_search_by_key_reada), SF(s_bmaps),
56529diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
56530index 157e474..65a6114 100644
56531--- a/fs/reiserfs/reiserfs.h
56532+++ b/fs/reiserfs/reiserfs.h
56533@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
56534 /* Comment? -Hans */
56535 wait_queue_head_t s_wait;
56536 /* To be obsoleted soon by per buffer seals.. -Hans */
56537- atomic_t s_generation_counter; // increased by one every time the
56538+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56539 // tree gets re-balanced
56540 unsigned long s_properties; /* File system properties. Currently holds
56541 on-disk FS format */
56542@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
56543 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56544
56545 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56546-#define get_generation(s) atomic_read (&fs_generation(s))
56547+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56548 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56549 #define __fs_changed(gen,s) (gen != get_generation (s))
56550 #define fs_changed(gen,s) \
56551diff --git a/fs/select.c b/fs/select.c
56552index 8c1c96c..a0f9b6d 100644
56553--- a/fs/select.c
56554+++ b/fs/select.c
56555@@ -20,6 +20,7 @@
56556 #include <linux/export.h>
56557 #include <linux/slab.h>
56558 #include <linux/poll.h>
56559+#include <linux/security.h>
56560 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
56561 #include <linux/file.h>
56562 #include <linux/fdtable.h>
56563@@ -827,6 +828,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
56564 struct poll_list *walk = head;
56565 unsigned long todo = nfds;
56566
56567+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
56568 if (nfds > rlimit(RLIMIT_NOFILE))
56569 return -EINVAL;
56570
56571diff --git a/fs/seq_file.c b/fs/seq_file.c
56572index 774c1eb..b67582a 100644
56573--- a/fs/seq_file.c
56574+++ b/fs/seq_file.c
56575@@ -10,6 +10,7 @@
56576 #include <linux/seq_file.h>
56577 #include <linux/slab.h>
56578 #include <linux/cred.h>
56579+#include <linux/sched.h>
56580
56581 #include <asm/uaccess.h>
56582 #include <asm/page.h>
56583@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
56584 #ifdef CONFIG_USER_NS
56585 p->user_ns = file->f_cred->user_ns;
56586 #endif
56587+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56588+ p->exec_id = current->exec_id;
56589+#endif
56590
56591 /*
56592 * Wrappers around seq_open(e.g. swaps_open) need to be
56593@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56594 return 0;
56595 }
56596 if (!m->buf) {
56597- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56598+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56599 if (!m->buf)
56600 return -ENOMEM;
56601 }
56602@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56603 Eoverflow:
56604 m->op->stop(m, p);
56605 kfree(m->buf);
56606- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56607+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56608 return !m->buf ? -ENOMEM : -EAGAIN;
56609 }
56610
56611@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56612
56613 /* grab buffer if we didn't have one */
56614 if (!m->buf) {
56615- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56616+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56617 if (!m->buf)
56618 goto Enomem;
56619 }
56620@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56621 goto Fill;
56622 m->op->stop(m, p);
56623 kfree(m->buf);
56624- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56625+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56626 if (!m->buf)
56627 goto Enomem;
56628 m->count = 0;
56629@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
56630 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
56631 void *data)
56632 {
56633- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
56634+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
56635 int res = -ENOMEM;
56636
56637 if (op) {
56638diff --git a/fs/splice.c b/fs/splice.c
56639index d37431d..81c3044 100644
56640--- a/fs/splice.c
56641+++ b/fs/splice.c
56642@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56643 pipe_lock(pipe);
56644
56645 for (;;) {
56646- if (!pipe->readers) {
56647+ if (!atomic_read(&pipe->readers)) {
56648 send_sig(SIGPIPE, current, 0);
56649 if (!ret)
56650 ret = -EPIPE;
56651@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56652 page_nr++;
56653 ret += buf->len;
56654
56655- if (pipe->files)
56656+ if (atomic_read(&pipe->files))
56657 do_wakeup = 1;
56658
56659 if (!--spd->nr_pages)
56660@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56661 do_wakeup = 0;
56662 }
56663
56664- pipe->waiting_writers++;
56665+ atomic_inc(&pipe->waiting_writers);
56666 pipe_wait(pipe);
56667- pipe->waiting_writers--;
56668+ atomic_dec(&pipe->waiting_writers);
56669 }
56670
56671 pipe_unlock(pipe);
56672@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
56673 old_fs = get_fs();
56674 set_fs(get_ds());
56675 /* The cast to a user pointer is valid due to the set_fs() */
56676- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
56677+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
56678 set_fs(old_fs);
56679
56680 return res;
56681@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
56682 old_fs = get_fs();
56683 set_fs(get_ds());
56684 /* The cast to a user pointer is valid due to the set_fs() */
56685- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
56686+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
56687 set_fs(old_fs);
56688
56689 return res;
56690@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
56691 goto err;
56692
56693 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
56694- vec[i].iov_base = (void __user *) page_address(page);
56695+ vec[i].iov_base = (void __force_user *) page_address(page);
56696 vec[i].iov_len = this_len;
56697 spd.pages[i] = page;
56698 spd.nr_pages++;
56699@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
56700 ops->release(pipe, buf);
56701 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
56702 pipe->nrbufs--;
56703- if (pipe->files)
56704+ if (atomic_read(&pipe->files))
56705 sd->need_wakeup = true;
56706 }
56707
56708@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
56709 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
56710 {
56711 while (!pipe->nrbufs) {
56712- if (!pipe->writers)
56713+ if (!atomic_read(&pipe->writers))
56714 return 0;
56715
56716- if (!pipe->waiting_writers && sd->num_spliced)
56717+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
56718 return 0;
56719
56720 if (sd->flags & SPLICE_F_NONBLOCK)
56721@@ -1193,7 +1193,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
56722 * out of the pipe right after the splice_to_pipe(). So set
56723 * PIPE_READERS appropriately.
56724 */
56725- pipe->readers = 1;
56726+ atomic_set(&pipe->readers, 1);
56727
56728 current->splice_pipe = pipe;
56729 }
56730@@ -1769,9 +1769,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56731 ret = -ERESTARTSYS;
56732 break;
56733 }
56734- if (!pipe->writers)
56735+ if (!atomic_read(&pipe->writers))
56736 break;
56737- if (!pipe->waiting_writers) {
56738+ if (!atomic_read(&pipe->waiting_writers)) {
56739 if (flags & SPLICE_F_NONBLOCK) {
56740 ret = -EAGAIN;
56741 break;
56742@@ -1803,7 +1803,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56743 pipe_lock(pipe);
56744
56745 while (pipe->nrbufs >= pipe->buffers) {
56746- if (!pipe->readers) {
56747+ if (!atomic_read(&pipe->readers)) {
56748 send_sig(SIGPIPE, current, 0);
56749 ret = -EPIPE;
56750 break;
56751@@ -1816,9 +1816,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56752 ret = -ERESTARTSYS;
56753 break;
56754 }
56755- pipe->waiting_writers++;
56756+ atomic_inc(&pipe->waiting_writers);
56757 pipe_wait(pipe);
56758- pipe->waiting_writers--;
56759+ atomic_dec(&pipe->waiting_writers);
56760 }
56761
56762 pipe_unlock(pipe);
56763@@ -1854,14 +1854,14 @@ retry:
56764 pipe_double_lock(ipipe, opipe);
56765
56766 do {
56767- if (!opipe->readers) {
56768+ if (!atomic_read(&opipe->readers)) {
56769 send_sig(SIGPIPE, current, 0);
56770 if (!ret)
56771 ret = -EPIPE;
56772 break;
56773 }
56774
56775- if (!ipipe->nrbufs && !ipipe->writers)
56776+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
56777 break;
56778
56779 /*
56780@@ -1958,7 +1958,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56781 pipe_double_lock(ipipe, opipe);
56782
56783 do {
56784- if (!opipe->readers) {
56785+ if (!atomic_read(&opipe->readers)) {
56786 send_sig(SIGPIPE, current, 0);
56787 if (!ret)
56788 ret = -EPIPE;
56789@@ -2003,7 +2003,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56790 * return EAGAIN if we have the potential of some data in the
56791 * future, otherwise just return 0
56792 */
56793- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
56794+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
56795 ret = -EAGAIN;
56796
56797 pipe_unlock(ipipe);
56798diff --git a/fs/stat.c b/fs/stat.c
56799index 04ce1ac..a13dd1e 100644
56800--- a/fs/stat.c
56801+++ b/fs/stat.c
56802@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
56803 stat->gid = inode->i_gid;
56804 stat->rdev = inode->i_rdev;
56805 stat->size = i_size_read(inode);
56806- stat->atime = inode->i_atime;
56807- stat->mtime = inode->i_mtime;
56808+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56809+ stat->atime = inode->i_ctime;
56810+ stat->mtime = inode->i_ctime;
56811+ } else {
56812+ stat->atime = inode->i_atime;
56813+ stat->mtime = inode->i_mtime;
56814+ }
56815 stat->ctime = inode->i_ctime;
56816 stat->blksize = (1 << inode->i_blkbits);
56817 stat->blocks = inode->i_blocks;
56818@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
56819 if (retval)
56820 return retval;
56821
56822- if (inode->i_op->getattr)
56823- return inode->i_op->getattr(path->mnt, path->dentry, stat);
56824+ if (inode->i_op->getattr) {
56825+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
56826+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56827+ stat->atime = stat->ctime;
56828+ stat->mtime = stat->ctime;
56829+ }
56830+ return retval;
56831+ }
56832
56833 generic_fillattr(inode, stat);
56834 return 0;
56835diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
56836index 15c68f9..36a8b3e 100644
56837--- a/fs/sysfs/bin.c
56838+++ b/fs/sysfs/bin.c
56839@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
56840 return ret;
56841 }
56842
56843-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
56844- void *buf, int len, int write)
56845+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
56846+ void *buf, size_t len, int write)
56847 {
56848 struct file *file = vma->vm_file;
56849 struct bin_buffer *bb = file->private_data;
56850 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
56851- int ret;
56852+ ssize_t ret;
56853
56854 if (!bb->vm_ops)
56855 return -EINVAL;
56856diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
56857index e8e0e71..79c28ac5 100644
56858--- a/fs/sysfs/dir.c
56859+++ b/fs/sysfs/dir.c
56860@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
56861 *
56862 * Returns 31 bit hash of ns + name (so it fits in an off_t )
56863 */
56864-static unsigned int sysfs_name_hash(const void *ns, const char *name)
56865+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
56866 {
56867 unsigned long hash = init_name_hash();
56868 unsigned int len = strlen(name);
56869@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
56870 struct sysfs_dirent *sd;
56871 int rc;
56872
56873+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
56874+ const char *parent_name = parent_sd->s_name;
56875+
56876+ mode = S_IFDIR | S_IRWXU;
56877+
56878+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
56879+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
56880+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
56881+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
56882+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
56883+#endif
56884+
56885 /* allocate */
56886 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
56887 if (!sd)
56888diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
56889index 602f56d..6853db8 100644
56890--- a/fs/sysfs/file.c
56891+++ b/fs/sysfs/file.c
56892@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
56893
56894 struct sysfs_open_dirent {
56895 atomic_t refcnt;
56896- atomic_t event;
56897+ atomic_unchecked_t event;
56898 wait_queue_head_t poll;
56899 struct list_head buffers; /* goes through sysfs_buffer.list */
56900 };
56901@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
56902 if (!sysfs_get_active(attr_sd))
56903 return -ENODEV;
56904
56905- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
56906+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
56907 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
56908
56909 sysfs_put_active(attr_sd);
56910@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
56911 return -ENOMEM;
56912
56913 atomic_set(&new_od->refcnt, 0);
56914- atomic_set(&new_od->event, 1);
56915+ atomic_set_unchecked(&new_od->event, 1);
56916 init_waitqueue_head(&new_od->poll);
56917 INIT_LIST_HEAD(&new_od->buffers);
56918 goto retry;
56919@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
56920
56921 sysfs_put_active(attr_sd);
56922
56923- if (buffer->event != atomic_read(&od->event))
56924+ if (buffer->event != atomic_read_unchecked(&od->event))
56925 goto trigger;
56926
56927 return DEFAULT_POLLMASK;
56928@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
56929
56930 od = sd->s_attr.open;
56931 if (od) {
56932- atomic_inc(&od->event);
56933+ atomic_inc_unchecked(&od->event);
56934 wake_up_interruptible(&od->poll);
56935 }
56936
56937diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
56938index 8c940df..25b733e 100644
56939--- a/fs/sysfs/symlink.c
56940+++ b/fs/sysfs/symlink.c
56941@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56942
56943 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
56944 {
56945- char *page = nd_get_link(nd);
56946+ const char *page = nd_get_link(nd);
56947 if (!IS_ERR(page))
56948 free_page((unsigned long)page);
56949 }
56950diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
56951index 69d4889..a810bd4 100644
56952--- a/fs/sysv/sysv.h
56953+++ b/fs/sysv/sysv.h
56954@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
56955 #endif
56956 }
56957
56958-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56959+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56960 {
56961 if (sbi->s_bytesex == BYTESEX_PDP)
56962 return PDP_swab((__force __u32)n);
56963diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
56964index e18b988..f1d4ad0f 100644
56965--- a/fs/ubifs/io.c
56966+++ b/fs/ubifs/io.c
56967@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
56968 return err;
56969 }
56970
56971-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56972+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56973 {
56974 int err;
56975
56976diff --git a/fs/udf/misc.c b/fs/udf/misc.c
56977index c175b4d..8f36a16 100644
56978--- a/fs/udf/misc.c
56979+++ b/fs/udf/misc.c
56980@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
56981
56982 u8 udf_tag_checksum(const struct tag *t)
56983 {
56984- u8 *data = (u8 *)t;
56985+ const u8 *data = (const u8 *)t;
56986 u8 checksum = 0;
56987 int i;
56988 for (i = 0; i < sizeof(struct tag); ++i)
56989diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
56990index 8d974c4..b82f6ec 100644
56991--- a/fs/ufs/swab.h
56992+++ b/fs/ufs/swab.h
56993@@ -22,7 +22,7 @@ enum {
56994 BYTESEX_BE
56995 };
56996
56997-static inline u64
56998+static inline u64 __intentional_overflow(-1)
56999 fs64_to_cpu(struct super_block *sbp, __fs64 n)
57000 {
57001 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
57002@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
57003 return (__force __fs64)cpu_to_be64(n);
57004 }
57005
57006-static inline u32
57007+static inline u32 __intentional_overflow(-1)
57008 fs32_to_cpu(struct super_block *sbp, __fs32 n)
57009 {
57010 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
57011diff --git a/fs/utimes.c b/fs/utimes.c
57012index f4fb7ec..3fe03c0 100644
57013--- a/fs/utimes.c
57014+++ b/fs/utimes.c
57015@@ -1,6 +1,7 @@
57016 #include <linux/compiler.h>
57017 #include <linux/file.h>
57018 #include <linux/fs.h>
57019+#include <linux/security.h>
57020 #include <linux/linkage.h>
57021 #include <linux/mount.h>
57022 #include <linux/namei.h>
57023@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
57024 goto mnt_drop_write_and_out;
57025 }
57026 }
57027+
57028+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
57029+ error = -EACCES;
57030+ goto mnt_drop_write_and_out;
57031+ }
57032+
57033 mutex_lock(&inode->i_mutex);
57034 error = notify_change(path->dentry, &newattrs);
57035 mutex_unlock(&inode->i_mutex);
57036diff --git a/fs/xattr.c b/fs/xattr.c
57037index 3377dff..4d074d9 100644
57038--- a/fs/xattr.c
57039+++ b/fs/xattr.c
57040@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
57041 return rc;
57042 }
57043
57044+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
57045+ssize_t
57046+pax_getxattr(struct dentry *dentry, void *value, size_t size)
57047+{
57048+ struct inode *inode = dentry->d_inode;
57049+ ssize_t error;
57050+
57051+ error = inode_permission(inode, MAY_EXEC);
57052+ if (error)
57053+ return error;
57054+
57055+ if (inode->i_op->getxattr)
57056+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
57057+ else
57058+ error = -EOPNOTSUPP;
57059+
57060+ return error;
57061+}
57062+EXPORT_SYMBOL(pax_getxattr);
57063+#endif
57064+
57065 ssize_t
57066 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
57067 {
57068@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
57069 * Extended attribute SET operations
57070 */
57071 static long
57072-setxattr(struct dentry *d, const char __user *name, const void __user *value,
57073+setxattr(struct path *path, const char __user *name, const void __user *value,
57074 size_t size, int flags)
57075 {
57076 int error;
57077@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
57078 posix_acl_fix_xattr_from_user(kvalue, size);
57079 }
57080
57081- error = vfs_setxattr(d, kname, kvalue, size, flags);
57082+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
57083+ error = -EACCES;
57084+ goto out;
57085+ }
57086+
57087+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
57088 out:
57089 if (vvalue)
57090 vfree(vvalue);
57091@@ -377,7 +403,7 @@ retry:
57092 return error;
57093 error = mnt_want_write(path.mnt);
57094 if (!error) {
57095- error = setxattr(path.dentry, name, value, size, flags);
57096+ error = setxattr(&path, name, value, size, flags);
57097 mnt_drop_write(path.mnt);
57098 }
57099 path_put(&path);
57100@@ -401,7 +427,7 @@ retry:
57101 return error;
57102 error = mnt_want_write(path.mnt);
57103 if (!error) {
57104- error = setxattr(path.dentry, name, value, size, flags);
57105+ error = setxattr(&path, name, value, size, flags);
57106 mnt_drop_write(path.mnt);
57107 }
57108 path_put(&path);
57109@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
57110 const void __user *,value, size_t, size, int, flags)
57111 {
57112 struct fd f = fdget(fd);
57113- struct dentry *dentry;
57114 int error = -EBADF;
57115
57116 if (!f.file)
57117 return error;
57118- dentry = f.file->f_path.dentry;
57119- audit_inode(NULL, dentry, 0);
57120+ audit_inode(NULL, f.file->f_path.dentry, 0);
57121 error = mnt_want_write_file(f.file);
57122 if (!error) {
57123- error = setxattr(dentry, name, value, size, flags);
57124+ error = setxattr(&f.file->f_path, name, value, size, flags);
57125 mnt_drop_write_file(f.file);
57126 }
57127 fdput(f);
57128diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
57129index 9fbea87..6b19972 100644
57130--- a/fs/xattr_acl.c
57131+++ b/fs/xattr_acl.c
57132@@ -76,8 +76,8 @@ struct posix_acl *
57133 posix_acl_from_xattr(struct user_namespace *user_ns,
57134 const void *value, size_t size)
57135 {
57136- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
57137- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
57138+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
57139+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
57140 int count;
57141 struct posix_acl *acl;
57142 struct posix_acl_entry *acl_e;
57143diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
57144index 8904284..ee0e14b 100644
57145--- a/fs/xfs/xfs_bmap.c
57146+++ b/fs/xfs/xfs_bmap.c
57147@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
57148
57149 #else
57150 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
57151-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
57152+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
57153 #endif /* DEBUG */
57154
57155 /*
57156diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
57157index 6157424..ac98f6d 100644
57158--- a/fs/xfs/xfs_dir2_sf.c
57159+++ b/fs/xfs/xfs_dir2_sf.c
57160@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
57161 }
57162
57163 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
57164- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57165+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
57166+ char name[sfep->namelen];
57167+ memcpy(name, sfep->name, sfep->namelen);
57168+ if (filldir(dirent, name, sfep->namelen,
57169+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
57170+ *offset = off & 0x7fffffff;
57171+ return 0;
57172+ }
57173+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57174 off & 0x7fffffff, ino, DT_UNKNOWN)) {
57175 *offset = off & 0x7fffffff;
57176 return 0;
57177diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
57178index 5e99968..45bd327 100644
57179--- a/fs/xfs/xfs_ioctl.c
57180+++ b/fs/xfs/xfs_ioctl.c
57181@@ -127,7 +127,7 @@ xfs_find_handle(
57182 }
57183
57184 error = -EFAULT;
57185- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
57186+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
57187 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
57188 goto out_put;
57189
57190diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
57191index ca9ecaa..60100c7 100644
57192--- a/fs/xfs/xfs_iops.c
57193+++ b/fs/xfs/xfs_iops.c
57194@@ -395,7 +395,7 @@ xfs_vn_put_link(
57195 struct nameidata *nd,
57196 void *p)
57197 {
57198- char *s = nd_get_link(nd);
57199+ const char *s = nd_get_link(nd);
57200
57201 if (!IS_ERR(s))
57202 kfree(s);
57203diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
57204new file mode 100644
57205index 0000000..c9c4ac3
57206--- /dev/null
57207+++ b/grsecurity/Kconfig
57208@@ -0,0 +1,1054 @@
57209+#
57210+# grecurity configuration
57211+#
57212+menu "Memory Protections"
57213+depends on GRKERNSEC
57214+
57215+config GRKERNSEC_KMEM
57216+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
57217+ default y if GRKERNSEC_CONFIG_AUTO
57218+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
57219+ help
57220+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
57221+ be written to or read from to modify or leak the contents of the running
57222+ kernel. /dev/port will also not be allowed to be opened and support
57223+ for /dev/cpu/*/msr will be removed. If you have module
57224+ support disabled, enabling this will close up five ways that are
57225+ currently used to insert malicious code into the running kernel.
57226+
57227+ Even with all these features enabled, we still highly recommend that
57228+ you use the RBAC system, as it is still possible for an attacker to
57229+ modify the running kernel through privileged I/O granted by ioperm/iopl.
57230+
57231+ If you are not using XFree86, you may be able to stop this additional
57232+ case by enabling the 'Disable privileged I/O' option. Though nothing
57233+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
57234+ but only to video memory, which is the only writing we allow in this
57235+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
57236+ not be allowed to mprotect it with PROT_WRITE later.
57237+ Enabling this feature will prevent the "cpupower" and "powertop" tools
57238+ from working.
57239+
57240+ It is highly recommended that you say Y here if you meet all the
57241+ conditions above.
57242+
57243+config GRKERNSEC_VM86
57244+ bool "Restrict VM86 mode"
57245+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57246+ depends on X86_32
57247+
57248+ help
57249+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
57250+ make use of a special execution mode on 32bit x86 processors called
57251+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
57252+ video cards and will still work with this option enabled. The purpose
57253+ of the option is to prevent exploitation of emulation errors in
57254+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
57255+ Nearly all users should be able to enable this option.
57256+
57257+config GRKERNSEC_IO
57258+ bool "Disable privileged I/O"
57259+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57260+ depends on X86
57261+ select RTC_CLASS
57262+ select RTC_INTF_DEV
57263+ select RTC_DRV_CMOS
57264+
57265+ help
57266+ If you say Y here, all ioperm and iopl calls will return an error.
57267+ Ioperm and iopl can be used to modify the running kernel.
57268+ Unfortunately, some programs need this access to operate properly,
57269+ the most notable of which are XFree86 and hwclock. hwclock can be
57270+ remedied by having RTC support in the kernel, so real-time
57271+ clock support is enabled if this option is enabled, to ensure
57272+ that hwclock operates correctly. XFree86 still will not
57273+ operate correctly with this option enabled, so DO NOT CHOOSE Y
57274+ IF YOU USE XFree86. If you use XFree86 and you still want to
57275+ protect your kernel against modification, use the RBAC system.
57276+
57277+config GRKERNSEC_JIT_HARDEN
57278+ bool "Harden BPF JIT against spray attacks"
57279+ default y if GRKERNSEC_CONFIG_AUTO
57280+ depends on BPF_JIT
57281+ help
57282+ If you say Y here, the native code generated by the kernel's Berkeley
57283+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
57284+ attacks that attempt to fit attacker-beneficial instructions in
57285+ 32bit immediate fields of JIT-generated native instructions. The
57286+ attacker will generally aim to cause an unintended instruction sequence
57287+ of JIT-generated native code to execute by jumping into the middle of
57288+ a generated instruction. This feature effectively randomizes the 32bit
57289+ immediate constants present in the generated code to thwart such attacks.
57290+
57291+ If you're using KERNEXEC, it's recommended that you enable this option
57292+ to supplement the hardening of the kernel.
57293+
57294+config GRKERNSEC_PERF_HARDEN
57295+ bool "Disable unprivileged PERF_EVENTS usage by default"
57296+ default y if GRKERNSEC_CONFIG_AUTO
57297+ depends on PERF_EVENTS
57298+ help
57299+ If you say Y here, the range of acceptable values for the
57300+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
57301+ default to a new value: 3. When the sysctl is set to this value, no
57302+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
57303+
57304+ Though PERF_EVENTS can be used legitimately for performance monitoring
57305+ and low-level application profiling, it is forced on regardless of
57306+ configuration, has been at fault for several vulnerabilities, and
57307+ creates new opportunities for side channels and other information leaks.
57308+
57309+ This feature puts PERF_EVENTS into a secure default state and permits
57310+ the administrator to change out of it temporarily if unprivileged
57311+ application profiling is needed.
57312+
57313+config GRKERNSEC_RAND_THREADSTACK
57314+ bool "Insert random gaps between thread stacks"
57315+ default y if GRKERNSEC_CONFIG_AUTO
57316+ depends on PAX_RANDMMAP && !PPC
57317+ help
57318+ If you say Y here, a random-sized gap will be enforced between allocated
57319+ thread stacks. Glibc's NPTL and other threading libraries that
57320+ pass MAP_STACK to the kernel for thread stack allocation are supported.
57321+ The implementation currently provides 8 bits of entropy for the gap.
57322+
57323+ Many distributions do not compile threaded remote services with the
57324+ -fstack-check argument to GCC, causing the variable-sized stack-based
57325+ allocator, alloca(), to not probe the stack on allocation. This
57326+ permits an unbounded alloca() to skip over any guard page and potentially
57327+ modify another thread's stack reliably. An enforced random gap
57328+ reduces the reliability of such an attack and increases the chance
57329+ that such a read/write to another thread's stack instead lands in
57330+ an unmapped area, causing a crash and triggering grsecurity's
57331+ anti-bruteforcing logic.
57332+
57333+config GRKERNSEC_PROC_MEMMAP
57334+ bool "Harden ASLR against information leaks and entropy reduction"
57335+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
57336+ depends on PAX_NOEXEC || PAX_ASLR
57337+ help
57338+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
57339+ give no information about the addresses of its mappings if
57340+ PaX features that rely on random addresses are enabled on the task.
57341+ In addition to sanitizing this information and disabling other
57342+ dangerous sources of information, this option causes reads of sensitive
57343+ /proc/<pid> entries where the file descriptor was opened in a different
57344+ task than the one performing the read. Such attempts are logged.
57345+ This option also limits argv/env strings for suid/sgid binaries
57346+ to 512KB to prevent a complete exhaustion of the stack entropy provided
57347+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
57348+ binaries to prevent alternative mmap layouts from being abused.
57349+
57350+ If you use PaX it is essential that you say Y here as it closes up
57351+ several holes that make full ASLR useless locally.
57352+
57353+config GRKERNSEC_BRUTE
57354+ bool "Deter exploit bruteforcing"
57355+ default y if GRKERNSEC_CONFIG_AUTO
57356+ help
57357+ If you say Y here, attempts to bruteforce exploits against forking
57358+ daemons such as apache or sshd, as well as against suid/sgid binaries
57359+ will be deterred. When a child of a forking daemon is killed by PaX
57360+ or crashes due to an illegal instruction or other suspicious signal,
57361+ the parent process will be delayed 30 seconds upon every subsequent
57362+ fork until the administrator is able to assess the situation and
57363+ restart the daemon.
57364+ In the suid/sgid case, the attempt is logged, the user has all their
57365+ existing instances of the suid/sgid binary terminated and will
57366+ be unable to execute any suid/sgid binaries for 15 minutes.
57367+
57368+ It is recommended that you also enable signal logging in the auditing
57369+ section so that logs are generated when a process triggers a suspicious
57370+ signal.
57371+ If the sysctl option is enabled, a sysctl option with name
57372+ "deter_bruteforce" is created.
57373+
57374+
57375+config GRKERNSEC_MODHARDEN
57376+ bool "Harden module auto-loading"
57377+ default y if GRKERNSEC_CONFIG_AUTO
57378+ depends on MODULES
57379+ help
57380+ If you say Y here, module auto-loading in response to use of some
57381+ feature implemented by an unloaded module will be restricted to
57382+ root users. Enabling this option helps defend against attacks
57383+ by unprivileged users who abuse the auto-loading behavior to
57384+ cause a vulnerable module to load that is then exploited.
57385+
57386+ If this option prevents a legitimate use of auto-loading for a
57387+ non-root user, the administrator can execute modprobe manually
57388+ with the exact name of the module mentioned in the alert log.
57389+ Alternatively, the administrator can add the module to the list
57390+ of modules loaded at boot by modifying init scripts.
57391+
57392+ Modification of init scripts will most likely be needed on
57393+ Ubuntu servers with encrypted home directory support enabled,
57394+ as the first non-root user logging in will cause the ecb(aes),
57395+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
57396+
57397+config GRKERNSEC_HIDESYM
57398+ bool "Hide kernel symbols"
57399+ default y if GRKERNSEC_CONFIG_AUTO
57400+ select PAX_USERCOPY_SLABS
57401+ help
57402+ If you say Y here, getting information on loaded modules, and
57403+ displaying all kernel symbols through a syscall will be restricted
57404+ to users with CAP_SYS_MODULE. For software compatibility reasons,
57405+ /proc/kallsyms will be restricted to the root user. The RBAC
57406+ system can hide that entry even from root.
57407+
57408+ This option also prevents leaking of kernel addresses through
57409+ several /proc entries.
57410+
57411+ Note that this option is only effective provided the following
57412+ conditions are met:
57413+ 1) The kernel using grsecurity is not precompiled by some distribution
57414+ 2) You have also enabled GRKERNSEC_DMESG
57415+ 3) You are using the RBAC system and hiding other files such as your
57416+ kernel image and System.map. Alternatively, enabling this option
57417+ causes the permissions on /boot, /lib/modules, and the kernel
57418+ source directory to change at compile time to prevent
57419+ reading by non-root users.
57420+ If the above conditions are met, this option will aid in providing a
57421+ useful protection against local kernel exploitation of overflows
57422+ and arbitrary read/write vulnerabilities.
57423+
57424+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
57425+ in addition to this feature.
57426+
57427+config GRKERNSEC_KERN_LOCKOUT
57428+ bool "Active kernel exploit response"
57429+ default y if GRKERNSEC_CONFIG_AUTO
57430+ depends on X86 || ARM || PPC || SPARC
57431+ help
57432+ If you say Y here, when a PaX alert is triggered due to suspicious
57433+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
57434+ or an OOPS occurs due to bad memory accesses, instead of just
57435+ terminating the offending process (and potentially allowing
57436+ a subsequent exploit from the same user), we will take one of two
57437+ actions:
57438+ If the user was root, we will panic the system
57439+ If the user was non-root, we will log the attempt, terminate
57440+ all processes owned by the user, then prevent them from creating
57441+ any new processes until the system is restarted
57442+ This deters repeated kernel exploitation/bruteforcing attempts
57443+ and is useful for later forensics.
57444+
57445+endmenu
57446+menu "Role Based Access Control Options"
57447+depends on GRKERNSEC
57448+
57449+config GRKERNSEC_RBAC_DEBUG
57450+ bool
57451+
57452+config GRKERNSEC_NO_RBAC
57453+ bool "Disable RBAC system"
57454+ help
57455+ If you say Y here, the /dev/grsec device will be removed from the kernel,
57456+ preventing the RBAC system from being enabled. You should only say Y
57457+ here if you have no intention of using the RBAC system, so as to prevent
57458+ an attacker with root access from misusing the RBAC system to hide files
57459+ and processes when loadable module support and /dev/[k]mem have been
57460+ locked down.
57461+
57462+config GRKERNSEC_ACL_HIDEKERN
57463+ bool "Hide kernel processes"
57464+ help
57465+ If you say Y here, all kernel threads will be hidden to all
57466+ processes but those whose subject has the "view hidden processes"
57467+ flag.
57468+
57469+config GRKERNSEC_ACL_MAXTRIES
57470+ int "Maximum tries before password lockout"
57471+ default 3
57472+ help
57473+ This option enforces the maximum number of times a user can attempt
57474+ to authorize themselves with the grsecurity RBAC system before being
57475+ denied the ability to attempt authorization again for a specified time.
57476+ The lower the number, the harder it will be to brute-force a password.
57477+
57478+config GRKERNSEC_ACL_TIMEOUT
57479+ int "Time to wait after max password tries, in seconds"
57480+ default 30
57481+ help
57482+ This option specifies the time the user must wait after attempting to
57483+ authorize to the RBAC system with the maximum number of invalid
57484+ passwords. The higher the number, the harder it will be to brute-force
57485+ a password.
57486+
57487+endmenu
57488+menu "Filesystem Protections"
57489+depends on GRKERNSEC
57490+
57491+config GRKERNSEC_PROC
57492+ bool "Proc restrictions"
57493+ default y if GRKERNSEC_CONFIG_AUTO
57494+ help
57495+ If you say Y here, the permissions of the /proc filesystem
57496+ will be altered to enhance system security and privacy. You MUST
57497+ choose either a user only restriction or a user and group restriction.
57498+ Depending upon the option you choose, you can either restrict users to
57499+ see only the processes they themselves run, or choose a group that can
57500+ view all processes and files normally restricted to root if you choose
57501+ the "restrict to user only" option. NOTE: If you're running identd or
57502+ ntpd as a non-root user, you will have to run it as the group you
57503+ specify here.
57504+
57505+config GRKERNSEC_PROC_USER
57506+ bool "Restrict /proc to user only"
57507+ depends on GRKERNSEC_PROC
57508+ help
57509+ If you say Y here, non-root users will only be able to view their own
57510+ processes, and restricts them from viewing network-related information,
57511+ and viewing kernel symbol and module information.
57512+
57513+config GRKERNSEC_PROC_USERGROUP
57514+ bool "Allow special group"
57515+ default y if GRKERNSEC_CONFIG_AUTO
57516+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
57517+ help
57518+ If you say Y here, you will be able to select a group that will be
57519+ able to view all processes and network-related information. If you've
57520+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
57521+ remain hidden. This option is useful if you want to run identd as
57522+ a non-root user. The group you select may also be chosen at boot time
57523+ via "grsec_proc_gid=" on the kernel commandline.
57524+
57525+config GRKERNSEC_PROC_GID
57526+ int "GID for special group"
57527+ depends on GRKERNSEC_PROC_USERGROUP
57528+ default 1001
57529+
57530+config GRKERNSEC_PROC_ADD
57531+ bool "Additional restrictions"
57532+ default y if GRKERNSEC_CONFIG_AUTO
57533+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
57534+ help
57535+ If you say Y here, additional restrictions will be placed on
57536+ /proc that keep normal users from viewing device information and
57537+ slabinfo information that could be useful for exploits.
57538+
57539+config GRKERNSEC_LINK
57540+ bool "Linking restrictions"
57541+ default y if GRKERNSEC_CONFIG_AUTO
57542+ help
57543+ If you say Y here, /tmp race exploits will be prevented, since users
57544+ will no longer be able to follow symlinks owned by other users in
57545+ world-writable +t directories (e.g. /tmp), unless the owner of the
57546+ symlink is the owner of the directory. users will also not be
57547+ able to hardlink to files they do not own. If the sysctl option is
57548+ enabled, a sysctl option with name "linking_restrictions" is created.
57549+
57550+config GRKERNSEC_SYMLINKOWN
57551+ bool "Kernel-enforced SymlinksIfOwnerMatch"
57552+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57553+ help
57554+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
57555+ that prevents it from being used as a security feature. As Apache
57556+ verifies the symlink by performing a stat() against the target of
57557+ the symlink before it is followed, an attacker can setup a symlink
57558+ to point to a same-owned file, then replace the symlink with one
57559+ that targets another user's file just after Apache "validates" the
57560+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
57561+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
57562+ will be in place for the group you specify. If the sysctl option
57563+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
57564+ created.
57565+
57566+config GRKERNSEC_SYMLINKOWN_GID
57567+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
57568+ depends on GRKERNSEC_SYMLINKOWN
57569+ default 1006
57570+ help
57571+ Setting this GID determines what group kernel-enforced
57572+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
57573+ is enabled, a sysctl option with name "symlinkown_gid" is created.
57574+
57575+config GRKERNSEC_FIFO
57576+ bool "FIFO restrictions"
57577+ default y if GRKERNSEC_CONFIG_AUTO
57578+ help
57579+ If you say Y here, users will not be able to write to FIFOs they don't
57580+ own in world-writable +t directories (e.g. /tmp), unless the owner of
57581+ the FIFO is the same owner of the directory it's held in. If the sysctl
57582+ option is enabled, a sysctl option with name "fifo_restrictions" is
57583+ created.
57584+
57585+config GRKERNSEC_SYSFS_RESTRICT
57586+ bool "Sysfs/debugfs restriction"
57587+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57588+ depends on SYSFS
57589+ help
57590+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
57591+ any filesystem normally mounted under it (e.g. debugfs) will be
57592+ mostly accessible only by root. These filesystems generally provide access
57593+ to hardware and debug information that isn't appropriate for unprivileged
57594+ users of the system. Sysfs and debugfs have also become a large source
57595+ of new vulnerabilities, ranging from infoleaks to local compromise.
57596+ There has been very little oversight with an eye toward security involved
57597+ in adding new exporters of information to these filesystems, so their
57598+ use is discouraged.
57599+ For reasons of compatibility, a few directories have been whitelisted
57600+ for access by non-root users:
57601+ /sys/fs/selinux
57602+ /sys/fs/fuse
57603+ /sys/devices/system/cpu
57604+
57605+config GRKERNSEC_ROFS
57606+ bool "Runtime read-only mount protection"
57607+ help
57608+ If you say Y here, a sysctl option with name "romount_protect" will
57609+ be created. By setting this option to 1 at runtime, filesystems
57610+ will be protected in the following ways:
57611+ * No new writable mounts will be allowed
57612+ * Existing read-only mounts won't be able to be remounted read/write
57613+ * Write operations will be denied on all block devices
57614+ This option acts independently of grsec_lock: once it is set to 1,
57615+ it cannot be turned off. Therefore, please be mindful of the resulting
57616+ behavior if this option is enabled in an init script on a read-only
57617+ filesystem. This feature is mainly intended for secure embedded systems.
57618+
57619+config GRKERNSEC_DEVICE_SIDECHANNEL
57620+ bool "Eliminate stat/notify-based device sidechannels"
57621+ default y if GRKERNSEC_CONFIG_AUTO
57622+ help
57623+ If you say Y here, timing analyses on block or character
57624+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
57625+ will be thwarted for unprivileged users. If a process without
57626+ CAP_MKNOD stats such a device, the last access and last modify times
57627+ will match the device's create time. No access or modify events
57628+ will be triggered through inotify/dnotify/fanotify for such devices.
57629+ This feature will prevent attacks that may at a minimum
57630+ allow an attacker to determine the administrator's password length.
57631+
57632+config GRKERNSEC_CHROOT
57633+ bool "Chroot jail restrictions"
57634+ default y if GRKERNSEC_CONFIG_AUTO
57635+ help
57636+ If you say Y here, you will be able to choose several options that will
57637+ make breaking out of a chrooted jail much more difficult. If you
57638+ encounter no software incompatibilities with the following options, it
57639+ is recommended that you enable each one.
57640+
57641+config GRKERNSEC_CHROOT_MOUNT
57642+ bool "Deny mounts"
57643+ default y if GRKERNSEC_CONFIG_AUTO
57644+ depends on GRKERNSEC_CHROOT
57645+ help
57646+ If you say Y here, processes inside a chroot will not be able to
57647+ mount or remount filesystems. If the sysctl option is enabled, a
57648+ sysctl option with name "chroot_deny_mount" is created.
57649+
57650+config GRKERNSEC_CHROOT_DOUBLE
57651+ bool "Deny double-chroots"
57652+ default y if GRKERNSEC_CONFIG_AUTO
57653+ depends on GRKERNSEC_CHROOT
57654+ help
57655+ If you say Y here, processes inside a chroot will not be able to chroot
57656+ again outside the chroot. This is a widely used method of breaking
57657+ out of a chroot jail and should not be allowed. If the sysctl
57658+ option is enabled, a sysctl option with name
57659+ "chroot_deny_chroot" is created.
57660+
57661+config GRKERNSEC_CHROOT_PIVOT
57662+ bool "Deny pivot_root in chroot"
57663+ default y if GRKERNSEC_CONFIG_AUTO
57664+ depends on GRKERNSEC_CHROOT
57665+ help
57666+ If you say Y here, processes inside a chroot will not be able to use
57667+ a function called pivot_root() that was introduced in Linux 2.3.41. It
57668+ works similar to chroot in that it changes the root filesystem. This
57669+ function could be misused in a chrooted process to attempt to break out
57670+ of the chroot, and therefore should not be allowed. If the sysctl
57671+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
57672+ created.
57673+
57674+config GRKERNSEC_CHROOT_CHDIR
57675+ bool "Enforce chdir(\"/\") on all chroots"
57676+ default y if GRKERNSEC_CONFIG_AUTO
57677+ depends on GRKERNSEC_CHROOT
57678+ help
57679+ If you say Y here, the current working directory of all newly-chrooted
57680+ applications will be set to the the root directory of the chroot.
57681+ The man page on chroot(2) states:
57682+ Note that this call does not change the current working
57683+ directory, so that `.' can be outside the tree rooted at
57684+ `/'. In particular, the super-user can escape from a
57685+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
57686+
57687+ It is recommended that you say Y here, since it's not known to break
57688+ any software. If the sysctl option is enabled, a sysctl option with
57689+ name "chroot_enforce_chdir" is created.
57690+
57691+config GRKERNSEC_CHROOT_CHMOD
57692+ bool "Deny (f)chmod +s"
57693+ default y if GRKERNSEC_CONFIG_AUTO
57694+ depends on GRKERNSEC_CHROOT
57695+ help
57696+ If you say Y here, processes inside a chroot will not be able to chmod
57697+ or fchmod files to make them have suid or sgid bits. This protects
57698+ against another published method of breaking a chroot. If the sysctl
57699+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
57700+ created.
57701+
57702+config GRKERNSEC_CHROOT_FCHDIR
57703+ bool "Deny fchdir out of chroot"
57704+ default y if GRKERNSEC_CONFIG_AUTO
57705+ depends on GRKERNSEC_CHROOT
57706+ help
57707+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
57708+ to a file descriptor of the chrooting process that points to a directory
57709+ outside the filesystem will be stopped. If the sysctl option
57710+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
57711+
57712+config GRKERNSEC_CHROOT_MKNOD
57713+ bool "Deny mknod"
57714+ default y if GRKERNSEC_CONFIG_AUTO
57715+ depends on GRKERNSEC_CHROOT
57716+ help
57717+ If you say Y here, processes inside a chroot will not be allowed to
57718+ mknod. The problem with using mknod inside a chroot is that it
57719+ would allow an attacker to create a device entry that is the same
57720+ as one on the physical root of your system, which could range from
57721+ anything from the console device to a device for your harddrive (which
57722+ they could then use to wipe the drive or steal data). It is recommended
57723+ that you say Y here, unless you run into software incompatibilities.
57724+ If the sysctl option is enabled, a sysctl option with name
57725+ "chroot_deny_mknod" is created.
57726+
57727+config GRKERNSEC_CHROOT_SHMAT
57728+ bool "Deny shmat() out of chroot"
57729+ default y if GRKERNSEC_CONFIG_AUTO
57730+ depends on GRKERNSEC_CHROOT
57731+ help
57732+ If you say Y here, processes inside a chroot will not be able to attach
57733+ to shared memory segments that were created outside of the chroot jail.
57734+ It is recommended that you say Y here. If the sysctl option is enabled,
57735+ a sysctl option with name "chroot_deny_shmat" is created.
57736+
57737+config GRKERNSEC_CHROOT_UNIX
57738+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
57739+ default y if GRKERNSEC_CONFIG_AUTO
57740+ depends on GRKERNSEC_CHROOT
57741+ help
57742+ If you say Y here, processes inside a chroot will not be able to
57743+ connect to abstract (meaning not belonging to a filesystem) Unix
57744+ domain sockets that were bound outside of a chroot. It is recommended
57745+ that you say Y here. If the sysctl option is enabled, a sysctl option
57746+ with name "chroot_deny_unix" is created.
57747+
57748+config GRKERNSEC_CHROOT_FINDTASK
57749+ bool "Protect outside processes"
57750+ default y if GRKERNSEC_CONFIG_AUTO
57751+ depends on GRKERNSEC_CHROOT
57752+ help
57753+ If you say Y here, processes inside a chroot will not be able to
57754+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
57755+ getsid, or view any process outside of the chroot. If the sysctl
57756+ option is enabled, a sysctl option with name "chroot_findtask" is
57757+ created.
57758+
57759+config GRKERNSEC_CHROOT_NICE
57760+ bool "Restrict priority changes"
57761+ default y if GRKERNSEC_CONFIG_AUTO
57762+ depends on GRKERNSEC_CHROOT
57763+ help
57764+ If you say Y here, processes inside a chroot will not be able to raise
57765+ the priority of processes in the chroot, or alter the priority of
57766+ processes outside the chroot. This provides more security than simply
57767+ removing CAP_SYS_NICE from the process' capability set. If the
57768+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
57769+ is created.
57770+
57771+config GRKERNSEC_CHROOT_SYSCTL
57772+ bool "Deny sysctl writes"
57773+ default y if GRKERNSEC_CONFIG_AUTO
57774+ depends on GRKERNSEC_CHROOT
57775+ help
57776+ If you say Y here, an attacker in a chroot will not be able to
57777+ write to sysctl entries, either by sysctl(2) or through a /proc
57778+ interface. It is strongly recommended that you say Y here. If the
57779+ sysctl option is enabled, a sysctl option with name
57780+ "chroot_deny_sysctl" is created.
57781+
57782+config GRKERNSEC_CHROOT_CAPS
57783+ bool "Capability restrictions"
57784+ default y if GRKERNSEC_CONFIG_AUTO
57785+ depends on GRKERNSEC_CHROOT
57786+ help
57787+ If you say Y here, the capabilities on all processes within a
57788+ chroot jail will be lowered to stop module insertion, raw i/o,
57789+ system and net admin tasks, rebooting the system, modifying immutable
57790+ files, modifying IPC owned by another, and changing the system time.
57791+ This is left an option because it can break some apps. Disable this
57792+ if your chrooted apps are having problems performing those kinds of
57793+ tasks. If the sysctl option is enabled, a sysctl option with
57794+ name "chroot_caps" is created.
57795+
57796+config GRKERNSEC_CHROOT_INITRD
57797+ bool "Exempt initrd tasks from restrictions"
57798+ default y if GRKERNSEC_CONFIG_AUTO
57799+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
57800+ help
57801+ If you say Y here, tasks started prior to init will be exempted from
57802+ grsecurity's chroot restrictions. This option is mainly meant to
57803+ resolve Plymouth's performing privileged operations unnecessarily
57804+ in a chroot.
57805+
57806+endmenu
57807+menu "Kernel Auditing"
57808+depends on GRKERNSEC
57809+
57810+config GRKERNSEC_AUDIT_GROUP
57811+ bool "Single group for auditing"
57812+ help
57813+ If you say Y here, the exec and chdir logging features will only operate
57814+ on a group you specify. This option is recommended if you only want to
57815+ watch certain users instead of having a large amount of logs from the
57816+ entire system. If the sysctl option is enabled, a sysctl option with
57817+ name "audit_group" is created.
57818+
57819+config GRKERNSEC_AUDIT_GID
57820+ int "GID for auditing"
57821+ depends on GRKERNSEC_AUDIT_GROUP
57822+ default 1007
57823+
57824+config GRKERNSEC_EXECLOG
57825+ bool "Exec logging"
57826+ help
57827+ If you say Y here, all execve() calls will be logged (since the
57828+ other exec*() calls are frontends to execve(), all execution
57829+ will be logged). Useful for shell-servers that like to keep track
57830+ of their users. If the sysctl option is enabled, a sysctl option with
57831+ name "exec_logging" is created.
57832+ WARNING: This option when enabled will produce a LOT of logs, especially
57833+ on an active system.
57834+
57835+config GRKERNSEC_RESLOG
57836+ bool "Resource logging"
57837+ default y if GRKERNSEC_CONFIG_AUTO
57838+ help
57839+ If you say Y here, all attempts to overstep resource limits will
57840+ be logged with the resource name, the requested size, and the current
57841+ limit. It is highly recommended that you say Y here. If the sysctl
57842+ option is enabled, a sysctl option with name "resource_logging" is
57843+ created. If the RBAC system is enabled, the sysctl value is ignored.
57844+
57845+config GRKERNSEC_CHROOT_EXECLOG
57846+ bool "Log execs within chroot"
57847+ help
57848+ If you say Y here, all executions inside a chroot jail will be logged
57849+ to syslog. This can cause a large amount of logs if certain
57850+ applications (eg. djb's daemontools) are installed on the system, and
57851+ is therefore left as an option. If the sysctl option is enabled, a
57852+ sysctl option with name "chroot_execlog" is created.
57853+
57854+config GRKERNSEC_AUDIT_PTRACE
57855+ bool "Ptrace logging"
57856+ help
57857+ If you say Y here, all attempts to attach to a process via ptrace
57858+ will be logged. If the sysctl option is enabled, a sysctl option
57859+ with name "audit_ptrace" is created.
57860+
57861+config GRKERNSEC_AUDIT_CHDIR
57862+ bool "Chdir logging"
57863+ help
57864+ If you say Y here, all chdir() calls will be logged. If the sysctl
57865+ option is enabled, a sysctl option with name "audit_chdir" is created.
57866+
57867+config GRKERNSEC_AUDIT_MOUNT
57868+ bool "(Un)Mount logging"
57869+ help
57870+ If you say Y here, all mounts and unmounts will be logged. If the
57871+ sysctl option is enabled, a sysctl option with name "audit_mount" is
57872+ created.
57873+
57874+config GRKERNSEC_SIGNAL
57875+ bool "Signal logging"
57876+ default y if GRKERNSEC_CONFIG_AUTO
57877+ help
57878+ If you say Y here, certain important signals will be logged, such as
57879+ SIGSEGV, which will as a result inform you of when a error in a program
57880+ occurred, which in some cases could mean a possible exploit attempt.
57881+ If the sysctl option is enabled, a sysctl option with name
57882+ "signal_logging" is created.
57883+
57884+config GRKERNSEC_FORKFAIL
57885+ bool "Fork failure logging"
57886+ help
57887+ If you say Y here, all failed fork() attempts will be logged.
57888+ This could suggest a fork bomb, or someone attempting to overstep
57889+ their process limit. If the sysctl option is enabled, a sysctl option
57890+ with name "forkfail_logging" is created.
57891+
57892+config GRKERNSEC_TIME
57893+ bool "Time change logging"
57894+ default y if GRKERNSEC_CONFIG_AUTO
57895+ help
57896+ If you say Y here, any changes of the system clock will be logged.
57897+ If the sysctl option is enabled, a sysctl option with name
57898+ "timechange_logging" is created.
57899+
57900+config GRKERNSEC_PROC_IPADDR
57901+ bool "/proc/<pid>/ipaddr support"
57902+ default y if GRKERNSEC_CONFIG_AUTO
57903+ help
57904+ If you say Y here, a new entry will be added to each /proc/<pid>
57905+ directory that contains the IP address of the person using the task.
57906+ The IP is carried across local TCP and AF_UNIX stream sockets.
57907+ This information can be useful for IDS/IPSes to perform remote response
57908+ to a local attack. The entry is readable by only the owner of the
57909+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
57910+ the RBAC system), and thus does not create privacy concerns.
57911+
57912+config GRKERNSEC_RWXMAP_LOG
57913+ bool 'Denied RWX mmap/mprotect logging'
57914+ default y if GRKERNSEC_CONFIG_AUTO
57915+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
57916+ help
57917+ If you say Y here, calls to mmap() and mprotect() with explicit
57918+ usage of PROT_WRITE and PROT_EXEC together will be logged when
57919+ denied by the PAX_MPROTECT feature. If the sysctl option is
57920+ enabled, a sysctl option with name "rwxmap_logging" is created.
57921+
57922+config GRKERNSEC_AUDIT_TEXTREL
57923+ bool 'ELF text relocations logging (READ HELP)'
57924+ depends on PAX_MPROTECT
57925+ help
57926+ If you say Y here, text relocations will be logged with the filename
57927+ of the offending library or binary. The purpose of the feature is
57928+ to help Linux distribution developers get rid of libraries and
57929+ binaries that need text relocations which hinder the future progress
57930+ of PaX. Only Linux distribution developers should say Y here, and
57931+ never on a production machine, as this option creates an information
57932+ leak that could aid an attacker in defeating the randomization of
57933+ a single memory region. If the sysctl option is enabled, a sysctl
57934+ option with name "audit_textrel" is created.
57935+
57936+endmenu
57937+
57938+menu "Executable Protections"
57939+depends on GRKERNSEC
57940+
57941+config GRKERNSEC_DMESG
57942+ bool "Dmesg(8) restriction"
57943+ default y if GRKERNSEC_CONFIG_AUTO
57944+ help
57945+ If you say Y here, non-root users will not be able to use dmesg(8)
57946+ to view the contents of the kernel's circular log buffer.
57947+ The kernel's log buffer often contains kernel addresses and other
57948+ identifying information useful to an attacker in fingerprinting a
57949+ system for a targeted exploit.
57950+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
57951+ created.
57952+
57953+config GRKERNSEC_HARDEN_PTRACE
57954+ bool "Deter ptrace-based process snooping"
57955+ default y if GRKERNSEC_CONFIG_AUTO
57956+ help
57957+ If you say Y here, TTY sniffers and other malicious monitoring
57958+ programs implemented through ptrace will be defeated. If you
57959+ have been using the RBAC system, this option has already been
57960+ enabled for several years for all users, with the ability to make
57961+ fine-grained exceptions.
57962+
57963+ This option only affects the ability of non-root users to ptrace
57964+ processes that are not a descendent of the ptracing process.
57965+ This means that strace ./binary and gdb ./binary will still work,
57966+ but attaching to arbitrary processes will not. If the sysctl
57967+ option is enabled, a sysctl option with name "harden_ptrace" is
57968+ created.
57969+
57970+config GRKERNSEC_PTRACE_READEXEC
57971+ bool "Require read access to ptrace sensitive binaries"
57972+ default y if GRKERNSEC_CONFIG_AUTO
57973+ help
57974+ If you say Y here, unprivileged users will not be able to ptrace unreadable
57975+ binaries. This option is useful in environments that
57976+ remove the read bits (e.g. file mode 4711) from suid binaries to
57977+ prevent infoleaking of their contents. This option adds
57978+ consistency to the use of that file mode, as the binary could normally
57979+ be read out when run without privileges while ptracing.
57980+
57981+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
57982+ is created.
57983+
57984+config GRKERNSEC_SETXID
57985+ bool "Enforce consistent multithreaded privileges"
57986+ default y if GRKERNSEC_CONFIG_AUTO
57987+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
57988+ help
57989+ If you say Y here, a change from a root uid to a non-root uid
57990+ in a multithreaded application will cause the resulting uids,
57991+ gids, supplementary groups, and capabilities in that thread
57992+ to be propagated to the other threads of the process. In most
57993+ cases this is unnecessary, as glibc will emulate this behavior
57994+ on behalf of the application. Other libcs do not act in the
57995+ same way, allowing the other threads of the process to continue
57996+ running with root privileges. If the sysctl option is enabled,
57997+ a sysctl option with name "consistent_setxid" is created.
57998+
57999+config GRKERNSEC_TPE
58000+ bool "Trusted Path Execution (TPE)"
58001+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
58002+ help
58003+ If you say Y here, you will be able to choose a gid to add to the
58004+ supplementary groups of users you want to mark as "untrusted."
58005+ These users will not be able to execute any files that are not in
58006+ root-owned directories writable only by root. If the sysctl option
58007+ is enabled, a sysctl option with name "tpe" is created.
58008+
58009+config GRKERNSEC_TPE_ALL
58010+ bool "Partially restrict all non-root users"
58011+ depends on GRKERNSEC_TPE
58012+ help
58013+ If you say Y here, all non-root users will be covered under
58014+ a weaker TPE restriction. This is separate from, and in addition to,
58015+ the main TPE options that you have selected elsewhere. Thus, if a
58016+ "trusted" GID is chosen, this restriction applies to even that GID.
58017+ Under this restriction, all non-root users will only be allowed to
58018+ execute files in directories they own that are not group or
58019+ world-writable, or in directories owned by root and writable only by
58020+ root. If the sysctl option is enabled, a sysctl option with name
58021+ "tpe_restrict_all" is created.
58022+
58023+config GRKERNSEC_TPE_INVERT
58024+ bool "Invert GID option"
58025+ depends on GRKERNSEC_TPE
58026+ help
58027+ If you say Y here, the group you specify in the TPE configuration will
58028+ decide what group TPE restrictions will be *disabled* for. This
58029+ option is useful if you want TPE restrictions to be applied to most
58030+ users on the system. If the sysctl option is enabled, a sysctl option
58031+ with name "tpe_invert" is created. Unlike other sysctl options, this
58032+ entry will default to on for backward-compatibility.
58033+
58034+config GRKERNSEC_TPE_GID
58035+ int
58036+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
58037+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
58038+
58039+config GRKERNSEC_TPE_UNTRUSTED_GID
58040+ int "GID for TPE-untrusted users"
58041+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
58042+ default 1005
58043+ help
58044+ Setting this GID determines what group TPE restrictions will be
58045+ *enabled* for. If the sysctl option is enabled, a sysctl option
58046+ with name "tpe_gid" is created.
58047+
58048+config GRKERNSEC_TPE_TRUSTED_GID
58049+ int "GID for TPE-trusted users"
58050+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
58051+ default 1005
58052+ help
58053+ Setting this GID determines what group TPE restrictions will be
58054+ *disabled* for. If the sysctl option is enabled, a sysctl option
58055+ with name "tpe_gid" is created.
58056+
58057+endmenu
58058+menu "Network Protections"
58059+depends on GRKERNSEC
58060+
58061+config GRKERNSEC_RANDNET
58062+ bool "Larger entropy pools"
58063+ default y if GRKERNSEC_CONFIG_AUTO
58064+ help
58065+ If you say Y here, the entropy pools used for many features of Linux
58066+ and grsecurity will be doubled in size. Since several grsecurity
58067+ features use additional randomness, it is recommended that you say Y
58068+ here. Saying Y here has a similar effect as modifying
58069+ /proc/sys/kernel/random/poolsize.
58070+
58071+config GRKERNSEC_BLACKHOLE
58072+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
58073+ default y if GRKERNSEC_CONFIG_AUTO
58074+ depends on NET
58075+ help
58076+ If you say Y here, neither TCP resets nor ICMP
58077+ destination-unreachable packets will be sent in response to packets
58078+ sent to ports for which no associated listening process exists.
58079+ This feature supports both IPV4 and IPV6 and exempts the
58080+ loopback interface from blackholing. Enabling this feature
58081+ makes a host more resilient to DoS attacks and reduces network
58082+ visibility against scanners.
58083+
58084+ The blackhole feature as-implemented is equivalent to the FreeBSD
58085+ blackhole feature, as it prevents RST responses to all packets, not
58086+ just SYNs. Under most application behavior this causes no
58087+ problems, but applications (like haproxy) may not close certain
58088+ connections in a way that cleanly terminates them on the remote
58089+ end, leaving the remote host in LAST_ACK state. Because of this
58090+ side-effect and to prevent intentional LAST_ACK DoSes, this
58091+ feature also adds automatic mitigation against such attacks.
58092+ The mitigation drastically reduces the amount of time a socket
58093+ can spend in LAST_ACK state. If you're using haproxy and not
58094+ all servers it connects to have this option enabled, consider
58095+ disabling this feature on the haproxy host.
58096+
58097+ If the sysctl option is enabled, two sysctl options with names
58098+ "ip_blackhole" and "lastack_retries" will be created.
58099+ While "ip_blackhole" takes the standard zero/non-zero on/off
58100+ toggle, "lastack_retries" uses the same kinds of values as
58101+ "tcp_retries1" and "tcp_retries2". The default value of 4
58102+ prevents a socket from lasting more than 45 seconds in LAST_ACK
58103+ state.
58104+
58105+config GRKERNSEC_NO_SIMULT_CONNECT
58106+ bool "Disable TCP Simultaneous Connect"
58107+ default y if GRKERNSEC_CONFIG_AUTO
58108+ depends on NET
58109+ help
58110+ If you say Y here, a feature by Willy Tarreau will be enabled that
58111+ removes a weakness in Linux's strict implementation of TCP that
58112+ allows two clients to connect to each other without either entering
58113+ a listening state. The weakness allows an attacker to easily prevent
58114+ a client from connecting to a known server provided the source port
58115+ for the connection is guessed correctly.
58116+
58117+ As the weakness could be used to prevent an antivirus or IPS from
58118+ fetching updates, or prevent an SSL gateway from fetching a CRL,
58119+ it should be eliminated by enabling this option. Though Linux is
58120+ one of few operating systems supporting simultaneous connect, it
58121+ has no legitimate use in practice and is rarely supported by firewalls.
58122+
58123+config GRKERNSEC_SOCKET
58124+ bool "Socket restrictions"
58125+ depends on NET
58126+ help
58127+ If you say Y here, you will be able to choose from several options.
58128+ If you assign a GID on your system and add it to the supplementary
58129+ groups of users you want to restrict socket access to, this patch
58130+ will perform up to three things, based on the option(s) you choose.
58131+
58132+config GRKERNSEC_SOCKET_ALL
58133+ bool "Deny any sockets to group"
58134+ depends on GRKERNSEC_SOCKET
58135+ help
58136+ If you say Y here, you will be able to choose a GID of whose users will
58137+ be unable to connect to other hosts from your machine or run server
58138+ applications from your machine. If the sysctl option is enabled, a
58139+ sysctl option with name "socket_all" is created.
58140+
58141+config GRKERNSEC_SOCKET_ALL_GID
58142+ int "GID to deny all sockets for"
58143+ depends on GRKERNSEC_SOCKET_ALL
58144+ default 1004
58145+ help
58146+ Here you can choose the GID to disable socket access for. Remember to
58147+ add the users you want socket access disabled for to the GID
58148+ specified here. If the sysctl option is enabled, a sysctl option
58149+ with name "socket_all_gid" is created.
58150+
58151+config GRKERNSEC_SOCKET_CLIENT
58152+ bool "Deny client sockets to group"
58153+ depends on GRKERNSEC_SOCKET
58154+ help
58155+ If you say Y here, you will be able to choose a GID of whose users will
58156+ be unable to connect to other hosts from your machine, but will be
58157+ able to run servers. If this option is enabled, all users in the group
58158+ you specify will have to use passive mode when initiating ftp transfers
58159+ from the shell on your machine. If the sysctl option is enabled, a
58160+ sysctl option with name "socket_client" is created.
58161+
58162+config GRKERNSEC_SOCKET_CLIENT_GID
58163+ int "GID to deny client sockets for"
58164+ depends on GRKERNSEC_SOCKET_CLIENT
58165+ default 1003
58166+ help
58167+ Here you can choose the GID to disable client socket access for.
58168+ Remember to add the users you want client socket access disabled for to
58169+ the GID specified here. If the sysctl option is enabled, a sysctl
58170+ option with name "socket_client_gid" is created.
58171+
58172+config GRKERNSEC_SOCKET_SERVER
58173+ bool "Deny server sockets to group"
58174+ depends on GRKERNSEC_SOCKET
58175+ help
58176+ If you say Y here, you will be able to choose a GID of whose users will
58177+ be unable to run server applications from your machine. If the sysctl
58178+ option is enabled, a sysctl option with name "socket_server" is created.
58179+
58180+config GRKERNSEC_SOCKET_SERVER_GID
58181+ int "GID to deny server sockets for"
58182+ depends on GRKERNSEC_SOCKET_SERVER
58183+ default 1002
58184+ help
58185+ Here you can choose the GID to disable server socket access for.
58186+ Remember to add the users you want server socket access disabled for to
58187+ the GID specified here. If the sysctl option is enabled, a sysctl
58188+ option with name "socket_server_gid" is created.
58189+
58190+endmenu
58191+menu "Sysctl Support"
58192+depends on GRKERNSEC && SYSCTL
58193+
58194+config GRKERNSEC_SYSCTL
58195+ bool "Sysctl support"
58196+ default y if GRKERNSEC_CONFIG_AUTO
58197+ help
58198+ If you say Y here, you will be able to change the options that
58199+ grsecurity runs with at bootup, without having to recompile your
58200+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
58201+ to enable (1) or disable (0) various features. All the sysctl entries
58202+ are mutable until the "grsec_lock" entry is set to a non-zero value.
58203+ All features enabled in the kernel configuration are disabled at boot
58204+ if you do not say Y to the "Turn on features by default" option.
58205+ All options should be set at startup, and the grsec_lock entry should
58206+ be set to a non-zero value after all the options are set.
58207+ *THIS IS EXTREMELY IMPORTANT*
58208+
58209+config GRKERNSEC_SYSCTL_DISTRO
58210+ bool "Extra sysctl support for distro makers (READ HELP)"
58211+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
58212+ help
58213+ If you say Y here, additional sysctl options will be created
58214+ for features that affect processes running as root. Therefore,
58215+ it is critical when using this option that the grsec_lock entry be
58216+ enabled after boot. Only distros with prebuilt kernel packages
58217+ with this option enabled that can ensure grsec_lock is enabled
58218+ after boot should use this option.
58219+ *Failure to set grsec_lock after boot makes all grsec features
58220+ this option covers useless*
58221+
58222+ Currently this option creates the following sysctl entries:
58223+ "Disable Privileged I/O": "disable_priv_io"
58224+
58225+config GRKERNSEC_SYSCTL_ON
58226+ bool "Turn on features by default"
58227+ default y if GRKERNSEC_CONFIG_AUTO
58228+ depends on GRKERNSEC_SYSCTL
58229+ help
58230+ If you say Y here, instead of having all features enabled in the
58231+ kernel configuration disabled at boot time, the features will be
58232+ enabled at boot time. It is recommended you say Y here unless
58233+ there is some reason you would want all sysctl-tunable features to
58234+ be disabled by default. As mentioned elsewhere, it is important
58235+ to enable the grsec_lock entry once you have finished modifying
58236+ the sysctl entries.
58237+
58238+endmenu
58239+menu "Logging Options"
58240+depends on GRKERNSEC
58241+
58242+config GRKERNSEC_FLOODTIME
58243+ int "Seconds in between log messages (minimum)"
58244+ default 10
58245+ help
58246+ This option allows you to enforce the number of seconds between
58247+ grsecurity log messages. The default should be suitable for most
58248+ people, however, if you choose to change it, choose a value small enough
58249+ to allow informative logs to be produced, but large enough to
58250+ prevent flooding.
58251+
58252+config GRKERNSEC_FLOODBURST
58253+ int "Number of messages in a burst (maximum)"
58254+ default 6
58255+ help
58256+ This option allows you to choose the maximum number of messages allowed
58257+ within the flood time interval you chose in a separate option. The
58258+ default should be suitable for most people, however if you find that
58259+ many of your logs are being interpreted as flooding, you may want to
58260+ raise this value.
58261+
58262+endmenu
58263diff --git a/grsecurity/Makefile b/grsecurity/Makefile
58264new file mode 100644
58265index 0000000..1b9afa9
58266--- /dev/null
58267+++ b/grsecurity/Makefile
58268@@ -0,0 +1,38 @@
58269+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
58270+# during 2001-2009 it has been completely redesigned by Brad Spengler
58271+# into an RBAC system
58272+#
58273+# All code in this directory and various hooks inserted throughout the kernel
58274+# are copyright Brad Spengler - Open Source Security, Inc., and released
58275+# under the GPL v2 or higher
58276+
58277+KBUILD_CFLAGS += -Werror
58278+
58279+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
58280+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
58281+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
58282+
58283+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
58284+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
58285+ gracl_learn.o grsec_log.o
58286+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
58287+
58288+ifdef CONFIG_NET
58289+obj-y += grsec_sock.o
58290+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
58291+endif
58292+
58293+ifndef CONFIG_GRKERNSEC
58294+obj-y += grsec_disabled.o
58295+endif
58296+
58297+ifdef CONFIG_GRKERNSEC_HIDESYM
58298+extra-y := grsec_hidesym.o
58299+$(obj)/grsec_hidesym.o:
58300+ @-chmod -f 500 /boot
58301+ @-chmod -f 500 /lib/modules
58302+ @-chmod -f 500 /lib64/modules
58303+ @-chmod -f 500 /lib32/modules
58304+ @-chmod -f 700 .
58305+ @echo ' grsec: protected kernel image paths'
58306+endif
58307diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
58308new file mode 100644
58309index 0000000..0d5c602
58310--- /dev/null
58311+++ b/grsecurity/gracl.c
58312@@ -0,0 +1,4073 @@
58313+#include <linux/kernel.h>
58314+#include <linux/module.h>
58315+#include <linux/sched.h>
58316+#include <linux/mm.h>
58317+#include <linux/file.h>
58318+#include <linux/fs.h>
58319+#include <linux/namei.h>
58320+#include <linux/mount.h>
58321+#include <linux/tty.h>
58322+#include <linux/proc_fs.h>
58323+#include <linux/lglock.h>
58324+#include <linux/slab.h>
58325+#include <linux/vmalloc.h>
58326+#include <linux/types.h>
58327+#include <linux/sysctl.h>
58328+#include <linux/netdevice.h>
58329+#include <linux/ptrace.h>
58330+#include <linux/gracl.h>
58331+#include <linux/gralloc.h>
58332+#include <linux/security.h>
58333+#include <linux/grinternal.h>
58334+#include <linux/pid_namespace.h>
58335+#include <linux/stop_machine.h>
58336+#include <linux/fdtable.h>
58337+#include <linux/percpu.h>
58338+#include <linux/lglock.h>
58339+#include <linux/hugetlb.h>
58340+#include <linux/posix-timers.h>
58341+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58342+#include <linux/magic.h>
58343+#include <linux/pagemap.h>
58344+#include "../fs/btrfs/async-thread.h"
58345+#include "../fs/btrfs/ctree.h"
58346+#include "../fs/btrfs/btrfs_inode.h"
58347+#endif
58348+#include "../fs/mount.h"
58349+
58350+#include <asm/uaccess.h>
58351+#include <asm/errno.h>
58352+#include <asm/mman.h>
58353+
58354+extern struct lglock vfsmount_lock;
58355+
58356+static struct acl_role_db acl_role_set;
58357+static struct name_db name_set;
58358+static struct inodev_db inodev_set;
58359+
58360+/* for keeping track of userspace pointers used for subjects, so we
58361+ can share references in the kernel as well
58362+*/
58363+
58364+static struct path real_root;
58365+
58366+static struct acl_subj_map_db subj_map_set;
58367+
58368+static struct acl_role_label *default_role;
58369+
58370+static struct acl_role_label *role_list;
58371+
58372+static u16 acl_sp_role_value;
58373+
58374+extern char *gr_shared_page[4];
58375+static DEFINE_MUTEX(gr_dev_mutex);
58376+DEFINE_RWLOCK(gr_inode_lock);
58377+
58378+struct gr_arg *gr_usermode;
58379+
58380+static unsigned int gr_status __read_only = GR_STATUS_INIT;
58381+
58382+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
58383+extern void gr_clear_learn_entries(void);
58384+
58385+unsigned char *gr_system_salt;
58386+unsigned char *gr_system_sum;
58387+
58388+static struct sprole_pw **acl_special_roles = NULL;
58389+static __u16 num_sprole_pws = 0;
58390+
58391+static struct acl_role_label *kernel_role = NULL;
58392+
58393+static unsigned int gr_auth_attempts = 0;
58394+static unsigned long gr_auth_expires = 0UL;
58395+
58396+#ifdef CONFIG_NET
58397+extern struct vfsmount *sock_mnt;
58398+#endif
58399+
58400+extern struct vfsmount *pipe_mnt;
58401+extern struct vfsmount *shm_mnt;
58402+
58403+#ifdef CONFIG_HUGETLBFS
58404+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58405+#endif
58406+
58407+static struct acl_object_label *fakefs_obj_rw;
58408+static struct acl_object_label *fakefs_obj_rwx;
58409+
58410+extern int gr_init_uidset(void);
58411+extern void gr_free_uidset(void);
58412+extern void gr_remove_uid(uid_t uid);
58413+extern int gr_find_uid(uid_t uid);
58414+
58415+__inline__ int
58416+gr_acl_is_enabled(void)
58417+{
58418+ return (gr_status & GR_READY);
58419+}
58420+
58421+static inline dev_t __get_dev(const struct dentry *dentry)
58422+{
58423+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58424+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
58425+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
58426+ else
58427+#endif
58428+ return dentry->d_sb->s_dev;
58429+}
58430+
58431+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58432+{
58433+ return __get_dev(dentry);
58434+}
58435+
58436+static char gr_task_roletype_to_char(struct task_struct *task)
58437+{
58438+ switch (task->role->roletype &
58439+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
58440+ GR_ROLE_SPECIAL)) {
58441+ case GR_ROLE_DEFAULT:
58442+ return 'D';
58443+ case GR_ROLE_USER:
58444+ return 'U';
58445+ case GR_ROLE_GROUP:
58446+ return 'G';
58447+ case GR_ROLE_SPECIAL:
58448+ return 'S';
58449+ }
58450+
58451+ return 'X';
58452+}
58453+
58454+char gr_roletype_to_char(void)
58455+{
58456+ return gr_task_roletype_to_char(current);
58457+}
58458+
58459+__inline__ int
58460+gr_acl_tpe_check(void)
58461+{
58462+ if (unlikely(!(gr_status & GR_READY)))
58463+ return 0;
58464+ if (current->role->roletype & GR_ROLE_TPE)
58465+ return 1;
58466+ else
58467+ return 0;
58468+}
58469+
58470+int
58471+gr_handle_rawio(const struct inode *inode)
58472+{
58473+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58474+ if (inode && S_ISBLK(inode->i_mode) &&
58475+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58476+ !capable(CAP_SYS_RAWIO))
58477+ return 1;
58478+#endif
58479+ return 0;
58480+}
58481+
58482+static int
58483+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
58484+{
58485+ if (likely(lena != lenb))
58486+ return 0;
58487+
58488+ return !memcmp(a, b, lena);
58489+}
58490+
58491+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
58492+{
58493+ *buflen -= namelen;
58494+ if (*buflen < 0)
58495+ return -ENAMETOOLONG;
58496+ *buffer -= namelen;
58497+ memcpy(*buffer, str, namelen);
58498+ return 0;
58499+}
58500+
58501+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
58502+{
58503+ return prepend(buffer, buflen, name->name, name->len);
58504+}
58505+
58506+static int prepend_path(const struct path *path, struct path *root,
58507+ char **buffer, int *buflen)
58508+{
58509+ struct dentry *dentry = path->dentry;
58510+ struct vfsmount *vfsmnt = path->mnt;
58511+ struct mount *mnt = real_mount(vfsmnt);
58512+ bool slash = false;
58513+ int error = 0;
58514+
58515+ while (dentry != root->dentry || vfsmnt != root->mnt) {
58516+ struct dentry * parent;
58517+
58518+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
58519+ /* Global root? */
58520+ if (!mnt_has_parent(mnt)) {
58521+ goto out;
58522+ }
58523+ dentry = mnt->mnt_mountpoint;
58524+ mnt = mnt->mnt_parent;
58525+ vfsmnt = &mnt->mnt;
58526+ continue;
58527+ }
58528+ parent = dentry->d_parent;
58529+ prefetch(parent);
58530+ spin_lock(&dentry->d_lock);
58531+ error = prepend_name(buffer, buflen, &dentry->d_name);
58532+ spin_unlock(&dentry->d_lock);
58533+ if (!error)
58534+ error = prepend(buffer, buflen, "/", 1);
58535+ if (error)
58536+ break;
58537+
58538+ slash = true;
58539+ dentry = parent;
58540+ }
58541+
58542+out:
58543+ if (!error && !slash)
58544+ error = prepend(buffer, buflen, "/", 1);
58545+
58546+ return error;
58547+}
58548+
58549+/* this must be called with vfsmount_lock and rename_lock held */
58550+
58551+static char *__our_d_path(const struct path *path, struct path *root,
58552+ char *buf, int buflen)
58553+{
58554+ char *res = buf + buflen;
58555+ int error;
58556+
58557+ prepend(&res, &buflen, "\0", 1);
58558+ error = prepend_path(path, root, &res, &buflen);
58559+ if (error)
58560+ return ERR_PTR(error);
58561+
58562+ return res;
58563+}
58564+
58565+static char *
58566+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
58567+{
58568+ char *retval;
58569+
58570+ retval = __our_d_path(path, root, buf, buflen);
58571+ if (unlikely(IS_ERR(retval)))
58572+ retval = strcpy(buf, "<path too long>");
58573+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
58574+ retval[1] = '\0';
58575+
58576+ return retval;
58577+}
58578+
58579+static char *
58580+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58581+ char *buf, int buflen)
58582+{
58583+ struct path path;
58584+ char *res;
58585+
58586+ path.dentry = (struct dentry *)dentry;
58587+ path.mnt = (struct vfsmount *)vfsmnt;
58588+
58589+ /* we can use real_root.dentry, real_root.mnt, because this is only called
58590+ by the RBAC system */
58591+ res = gen_full_path(&path, &real_root, buf, buflen);
58592+
58593+ return res;
58594+}
58595+
58596+static char *
58597+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58598+ char *buf, int buflen)
58599+{
58600+ char *res;
58601+ struct path path;
58602+ struct path root;
58603+ struct task_struct *reaper = init_pid_ns.child_reaper;
58604+
58605+ path.dentry = (struct dentry *)dentry;
58606+ path.mnt = (struct vfsmount *)vfsmnt;
58607+
58608+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
58609+ get_fs_root(reaper->fs, &root);
58610+
58611+ br_read_lock(&vfsmount_lock);
58612+ write_seqlock(&rename_lock);
58613+ res = gen_full_path(&path, &root, buf, buflen);
58614+ write_sequnlock(&rename_lock);
58615+ br_read_unlock(&vfsmount_lock);
58616+
58617+ path_put(&root);
58618+ return res;
58619+}
58620+
58621+static char *
58622+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58623+{
58624+ char *ret;
58625+ br_read_lock(&vfsmount_lock);
58626+ write_seqlock(&rename_lock);
58627+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58628+ PAGE_SIZE);
58629+ write_sequnlock(&rename_lock);
58630+ br_read_unlock(&vfsmount_lock);
58631+ return ret;
58632+}
58633+
58634+static char *
58635+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58636+{
58637+ char *ret;
58638+ char *buf;
58639+ int buflen;
58640+
58641+ br_read_lock(&vfsmount_lock);
58642+ write_seqlock(&rename_lock);
58643+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
58644+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
58645+ buflen = (int)(ret - buf);
58646+ if (buflen >= 5)
58647+ prepend(&ret, &buflen, "/proc", 5);
58648+ else
58649+ ret = strcpy(buf, "<path too long>");
58650+ write_sequnlock(&rename_lock);
58651+ br_read_unlock(&vfsmount_lock);
58652+ return ret;
58653+}
58654+
58655+char *
58656+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
58657+{
58658+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58659+ PAGE_SIZE);
58660+}
58661+
58662+char *
58663+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
58664+{
58665+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58666+ PAGE_SIZE);
58667+}
58668+
58669+char *
58670+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
58671+{
58672+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
58673+ PAGE_SIZE);
58674+}
58675+
58676+char *
58677+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
58678+{
58679+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
58680+ PAGE_SIZE);
58681+}
58682+
58683+char *
58684+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
58685+{
58686+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
58687+ PAGE_SIZE);
58688+}
58689+
58690+__inline__ __u32
58691+to_gr_audit(const __u32 reqmode)
58692+{
58693+ /* masks off auditable permission flags, then shifts them to create
58694+ auditing flags, and adds the special case of append auditing if
58695+ we're requesting write */
58696+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
58697+}
58698+
58699+struct acl_subject_label *
58700+lookup_subject_map(const struct acl_subject_label *userp)
58701+{
58702+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
58703+ struct subject_map *match;
58704+
58705+ match = subj_map_set.s_hash[index];
58706+
58707+ while (match && match->user != userp)
58708+ match = match->next;
58709+
58710+ if (match != NULL)
58711+ return match->kernel;
58712+ else
58713+ return NULL;
58714+}
58715+
58716+static void
58717+insert_subj_map_entry(struct subject_map *subjmap)
58718+{
58719+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
58720+ struct subject_map **curr;
58721+
58722+ subjmap->prev = NULL;
58723+
58724+ curr = &subj_map_set.s_hash[index];
58725+ if (*curr != NULL)
58726+ (*curr)->prev = subjmap;
58727+
58728+ subjmap->next = *curr;
58729+ *curr = subjmap;
58730+
58731+ return;
58732+}
58733+
58734+static struct acl_role_label *
58735+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
58736+ const gid_t gid)
58737+{
58738+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
58739+ struct acl_role_label *match;
58740+ struct role_allowed_ip *ipp;
58741+ unsigned int x;
58742+ u32 curr_ip = task->signal->curr_ip;
58743+
58744+ task->signal->saved_ip = curr_ip;
58745+
58746+ match = acl_role_set.r_hash[index];
58747+
58748+ while (match) {
58749+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
58750+ for (x = 0; x < match->domain_child_num; x++) {
58751+ if (match->domain_children[x] == uid)
58752+ goto found;
58753+ }
58754+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
58755+ break;
58756+ match = match->next;
58757+ }
58758+found:
58759+ if (match == NULL) {
58760+ try_group:
58761+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
58762+ match = acl_role_set.r_hash[index];
58763+
58764+ while (match) {
58765+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
58766+ for (x = 0; x < match->domain_child_num; x++) {
58767+ if (match->domain_children[x] == gid)
58768+ goto found2;
58769+ }
58770+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
58771+ break;
58772+ match = match->next;
58773+ }
58774+found2:
58775+ if (match == NULL)
58776+ match = default_role;
58777+ if (match->allowed_ips == NULL)
58778+ return match;
58779+ else {
58780+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58781+ if (likely
58782+ ((ntohl(curr_ip) & ipp->netmask) ==
58783+ (ntohl(ipp->addr) & ipp->netmask)))
58784+ return match;
58785+ }
58786+ match = default_role;
58787+ }
58788+ } else if (match->allowed_ips == NULL) {
58789+ return match;
58790+ } else {
58791+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58792+ if (likely
58793+ ((ntohl(curr_ip) & ipp->netmask) ==
58794+ (ntohl(ipp->addr) & ipp->netmask)))
58795+ return match;
58796+ }
58797+ goto try_group;
58798+ }
58799+
58800+ return match;
58801+}
58802+
58803+struct acl_subject_label *
58804+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
58805+ const struct acl_role_label *role)
58806+{
58807+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58808+ struct acl_subject_label *match;
58809+
58810+ match = role->subj_hash[index];
58811+
58812+ while (match && (match->inode != ino || match->device != dev ||
58813+ (match->mode & GR_DELETED))) {
58814+ match = match->next;
58815+ }
58816+
58817+ if (match && !(match->mode & GR_DELETED))
58818+ return match;
58819+ else
58820+ return NULL;
58821+}
58822+
58823+struct acl_subject_label *
58824+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
58825+ const struct acl_role_label *role)
58826+{
58827+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58828+ struct acl_subject_label *match;
58829+
58830+ match = role->subj_hash[index];
58831+
58832+ while (match && (match->inode != ino || match->device != dev ||
58833+ !(match->mode & GR_DELETED))) {
58834+ match = match->next;
58835+ }
58836+
58837+ if (match && (match->mode & GR_DELETED))
58838+ return match;
58839+ else
58840+ return NULL;
58841+}
58842+
58843+static struct acl_object_label *
58844+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
58845+ const struct acl_subject_label *subj)
58846+{
58847+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58848+ struct acl_object_label *match;
58849+
58850+ match = subj->obj_hash[index];
58851+
58852+ while (match && (match->inode != ino || match->device != dev ||
58853+ (match->mode & GR_DELETED))) {
58854+ match = match->next;
58855+ }
58856+
58857+ if (match && !(match->mode & GR_DELETED))
58858+ return match;
58859+ else
58860+ return NULL;
58861+}
58862+
58863+static struct acl_object_label *
58864+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
58865+ const struct acl_subject_label *subj)
58866+{
58867+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58868+ struct acl_object_label *match;
58869+
58870+ match = subj->obj_hash[index];
58871+
58872+ while (match && (match->inode != ino || match->device != dev ||
58873+ !(match->mode & GR_DELETED))) {
58874+ match = match->next;
58875+ }
58876+
58877+ if (match && (match->mode & GR_DELETED))
58878+ return match;
58879+
58880+ match = subj->obj_hash[index];
58881+
58882+ while (match && (match->inode != ino || match->device != dev ||
58883+ (match->mode & GR_DELETED))) {
58884+ match = match->next;
58885+ }
58886+
58887+ if (match && !(match->mode & GR_DELETED))
58888+ return match;
58889+ else
58890+ return NULL;
58891+}
58892+
58893+static struct name_entry *
58894+lookup_name_entry(const char *name)
58895+{
58896+ unsigned int len = strlen(name);
58897+ unsigned int key = full_name_hash(name, len);
58898+ unsigned int index = key % name_set.n_size;
58899+ struct name_entry *match;
58900+
58901+ match = name_set.n_hash[index];
58902+
58903+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
58904+ match = match->next;
58905+
58906+ return match;
58907+}
58908+
58909+static struct name_entry *
58910+lookup_name_entry_create(const char *name)
58911+{
58912+ unsigned int len = strlen(name);
58913+ unsigned int key = full_name_hash(name, len);
58914+ unsigned int index = key % name_set.n_size;
58915+ struct name_entry *match;
58916+
58917+ match = name_set.n_hash[index];
58918+
58919+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58920+ !match->deleted))
58921+ match = match->next;
58922+
58923+ if (match && match->deleted)
58924+ return match;
58925+
58926+ match = name_set.n_hash[index];
58927+
58928+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58929+ match->deleted))
58930+ match = match->next;
58931+
58932+ if (match && !match->deleted)
58933+ return match;
58934+ else
58935+ return NULL;
58936+}
58937+
58938+static struct inodev_entry *
58939+lookup_inodev_entry(const ino_t ino, const dev_t dev)
58940+{
58941+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
58942+ struct inodev_entry *match;
58943+
58944+ match = inodev_set.i_hash[index];
58945+
58946+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
58947+ match = match->next;
58948+
58949+ return match;
58950+}
58951+
58952+static void
58953+insert_inodev_entry(struct inodev_entry *entry)
58954+{
58955+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
58956+ inodev_set.i_size);
58957+ struct inodev_entry **curr;
58958+
58959+ entry->prev = NULL;
58960+
58961+ curr = &inodev_set.i_hash[index];
58962+ if (*curr != NULL)
58963+ (*curr)->prev = entry;
58964+
58965+ entry->next = *curr;
58966+ *curr = entry;
58967+
58968+ return;
58969+}
58970+
58971+static void
58972+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
58973+{
58974+ unsigned int index =
58975+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
58976+ struct acl_role_label **curr;
58977+ struct acl_role_label *tmp, *tmp2;
58978+
58979+ curr = &acl_role_set.r_hash[index];
58980+
58981+ /* simple case, slot is empty, just set it to our role */
58982+ if (*curr == NULL) {
58983+ *curr = role;
58984+ } else {
58985+ /* example:
58986+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
58987+ 2 -> 3
58988+ */
58989+ /* first check to see if we can already be reached via this slot */
58990+ tmp = *curr;
58991+ while (tmp && tmp != role)
58992+ tmp = tmp->next;
58993+ if (tmp == role) {
58994+ /* we don't need to add ourselves to this slot's chain */
58995+ return;
58996+ }
58997+ /* we need to add ourselves to this chain, two cases */
58998+ if (role->next == NULL) {
58999+ /* simple case, append the current chain to our role */
59000+ role->next = *curr;
59001+ *curr = role;
59002+ } else {
59003+ /* 1 -> 2 -> 3 -> 4
59004+ 2 -> 3 -> 4
59005+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
59006+ */
59007+ /* trickier case: walk our role's chain until we find
59008+ the role for the start of the current slot's chain */
59009+ tmp = role;
59010+ tmp2 = *curr;
59011+ while (tmp->next && tmp->next != tmp2)
59012+ tmp = tmp->next;
59013+ if (tmp->next == tmp2) {
59014+ /* from example above, we found 3, so just
59015+ replace this slot's chain with ours */
59016+ *curr = role;
59017+ } else {
59018+ /* we didn't find a subset of our role's chain
59019+ in the current slot's chain, so append their
59020+ chain to ours, and set us as the first role in
59021+ the slot's chain
59022+
59023+ we could fold this case with the case above,
59024+ but making it explicit for clarity
59025+ */
59026+ tmp->next = tmp2;
59027+ *curr = role;
59028+ }
59029+ }
59030+ }
59031+
59032+ return;
59033+}
59034+
59035+static void
59036+insert_acl_role_label(struct acl_role_label *role)
59037+{
59038+ int i;
59039+
59040+ if (role_list == NULL) {
59041+ role_list = role;
59042+ role->prev = NULL;
59043+ } else {
59044+ role->prev = role_list;
59045+ role_list = role;
59046+ }
59047+
59048+ /* used for hash chains */
59049+ role->next = NULL;
59050+
59051+ if (role->roletype & GR_ROLE_DOMAIN) {
59052+ for (i = 0; i < role->domain_child_num; i++)
59053+ __insert_acl_role_label(role, role->domain_children[i]);
59054+ } else
59055+ __insert_acl_role_label(role, role->uidgid);
59056+}
59057+
59058+static int
59059+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
59060+{
59061+ struct name_entry **curr, *nentry;
59062+ struct inodev_entry *ientry;
59063+ unsigned int len = strlen(name);
59064+ unsigned int key = full_name_hash(name, len);
59065+ unsigned int index = key % name_set.n_size;
59066+
59067+ curr = &name_set.n_hash[index];
59068+
59069+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
59070+ curr = &((*curr)->next);
59071+
59072+ if (*curr != NULL)
59073+ return 1;
59074+
59075+ nentry = acl_alloc(sizeof (struct name_entry));
59076+ if (nentry == NULL)
59077+ return 0;
59078+ ientry = acl_alloc(sizeof (struct inodev_entry));
59079+ if (ientry == NULL)
59080+ return 0;
59081+ ientry->nentry = nentry;
59082+
59083+ nentry->key = key;
59084+ nentry->name = name;
59085+ nentry->inode = inode;
59086+ nentry->device = device;
59087+ nentry->len = len;
59088+ nentry->deleted = deleted;
59089+
59090+ nentry->prev = NULL;
59091+ curr = &name_set.n_hash[index];
59092+ if (*curr != NULL)
59093+ (*curr)->prev = nentry;
59094+ nentry->next = *curr;
59095+ *curr = nentry;
59096+
59097+ /* insert us into the table searchable by inode/dev */
59098+ insert_inodev_entry(ientry);
59099+
59100+ return 1;
59101+}
59102+
59103+static void
59104+insert_acl_obj_label(struct acl_object_label *obj,
59105+ struct acl_subject_label *subj)
59106+{
59107+ unsigned int index =
59108+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
59109+ struct acl_object_label **curr;
59110+
59111+
59112+ obj->prev = NULL;
59113+
59114+ curr = &subj->obj_hash[index];
59115+ if (*curr != NULL)
59116+ (*curr)->prev = obj;
59117+
59118+ obj->next = *curr;
59119+ *curr = obj;
59120+
59121+ return;
59122+}
59123+
59124+static void
59125+insert_acl_subj_label(struct acl_subject_label *obj,
59126+ struct acl_role_label *role)
59127+{
59128+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
59129+ struct acl_subject_label **curr;
59130+
59131+ obj->prev = NULL;
59132+
59133+ curr = &role->subj_hash[index];
59134+ if (*curr != NULL)
59135+ (*curr)->prev = obj;
59136+
59137+ obj->next = *curr;
59138+ *curr = obj;
59139+
59140+ return;
59141+}
59142+
59143+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
59144+
59145+static void *
59146+create_table(__u32 * len, int elementsize)
59147+{
59148+ unsigned int table_sizes[] = {
59149+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
59150+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
59151+ 4194301, 8388593, 16777213, 33554393, 67108859
59152+ };
59153+ void *newtable = NULL;
59154+ unsigned int pwr = 0;
59155+
59156+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
59157+ table_sizes[pwr] <= *len)
59158+ pwr++;
59159+
59160+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
59161+ return newtable;
59162+
59163+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
59164+ newtable =
59165+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
59166+ else
59167+ newtable = vmalloc(table_sizes[pwr] * elementsize);
59168+
59169+ *len = table_sizes[pwr];
59170+
59171+ return newtable;
59172+}
59173+
59174+static int
59175+init_variables(const struct gr_arg *arg)
59176+{
59177+ struct task_struct *reaper = init_pid_ns.child_reaper;
59178+ unsigned int stacksize;
59179+
59180+ subj_map_set.s_size = arg->role_db.num_subjects;
59181+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
59182+ name_set.n_size = arg->role_db.num_objects;
59183+ inodev_set.i_size = arg->role_db.num_objects;
59184+
59185+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
59186+ !name_set.n_size || !inodev_set.i_size)
59187+ return 1;
59188+
59189+ if (!gr_init_uidset())
59190+ return 1;
59191+
59192+ /* set up the stack that holds allocation info */
59193+
59194+ stacksize = arg->role_db.num_pointers + 5;
59195+
59196+ if (!acl_alloc_stack_init(stacksize))
59197+ return 1;
59198+
59199+ /* grab reference for the real root dentry and vfsmount */
59200+ get_fs_root(reaper->fs, &real_root);
59201+
59202+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59203+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
59204+#endif
59205+
59206+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
59207+ if (fakefs_obj_rw == NULL)
59208+ return 1;
59209+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
59210+
59211+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
59212+ if (fakefs_obj_rwx == NULL)
59213+ return 1;
59214+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
59215+
59216+ subj_map_set.s_hash =
59217+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
59218+ acl_role_set.r_hash =
59219+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
59220+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
59221+ inodev_set.i_hash =
59222+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
59223+
59224+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
59225+ !name_set.n_hash || !inodev_set.i_hash)
59226+ return 1;
59227+
59228+ memset(subj_map_set.s_hash, 0,
59229+ sizeof(struct subject_map *) * subj_map_set.s_size);
59230+ memset(acl_role_set.r_hash, 0,
59231+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
59232+ memset(name_set.n_hash, 0,
59233+ sizeof (struct name_entry *) * name_set.n_size);
59234+ memset(inodev_set.i_hash, 0,
59235+ sizeof (struct inodev_entry *) * inodev_set.i_size);
59236+
59237+ return 0;
59238+}
59239+
59240+/* free information not needed after startup
59241+ currently contains user->kernel pointer mappings for subjects
59242+*/
59243+
59244+static void
59245+free_init_variables(void)
59246+{
59247+ __u32 i;
59248+
59249+ if (subj_map_set.s_hash) {
59250+ for (i = 0; i < subj_map_set.s_size; i++) {
59251+ if (subj_map_set.s_hash[i]) {
59252+ kfree(subj_map_set.s_hash[i]);
59253+ subj_map_set.s_hash[i] = NULL;
59254+ }
59255+ }
59256+
59257+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
59258+ PAGE_SIZE)
59259+ kfree(subj_map_set.s_hash);
59260+ else
59261+ vfree(subj_map_set.s_hash);
59262+ }
59263+
59264+ return;
59265+}
59266+
59267+static void
59268+free_variables(void)
59269+{
59270+ struct acl_subject_label *s;
59271+ struct acl_role_label *r;
59272+ struct task_struct *task, *task2;
59273+ unsigned int x;
59274+
59275+ gr_clear_learn_entries();
59276+
59277+ read_lock(&tasklist_lock);
59278+ do_each_thread(task2, task) {
59279+ task->acl_sp_role = 0;
59280+ task->acl_role_id = 0;
59281+ task->acl = NULL;
59282+ task->role = NULL;
59283+ } while_each_thread(task2, task);
59284+ read_unlock(&tasklist_lock);
59285+
59286+ /* release the reference to the real root dentry and vfsmount */
59287+ path_put(&real_root);
59288+ memset(&real_root, 0, sizeof(real_root));
59289+
59290+ /* free all object hash tables */
59291+
59292+ FOR_EACH_ROLE_START(r)
59293+ if (r->subj_hash == NULL)
59294+ goto next_role;
59295+ FOR_EACH_SUBJECT_START(r, s, x)
59296+ if (s->obj_hash == NULL)
59297+ break;
59298+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59299+ kfree(s->obj_hash);
59300+ else
59301+ vfree(s->obj_hash);
59302+ FOR_EACH_SUBJECT_END(s, x)
59303+ FOR_EACH_NESTED_SUBJECT_START(r, s)
59304+ if (s->obj_hash == NULL)
59305+ break;
59306+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59307+ kfree(s->obj_hash);
59308+ else
59309+ vfree(s->obj_hash);
59310+ FOR_EACH_NESTED_SUBJECT_END(s)
59311+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
59312+ kfree(r->subj_hash);
59313+ else
59314+ vfree(r->subj_hash);
59315+ r->subj_hash = NULL;
59316+next_role:
59317+ FOR_EACH_ROLE_END(r)
59318+
59319+ acl_free_all();
59320+
59321+ if (acl_role_set.r_hash) {
59322+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
59323+ PAGE_SIZE)
59324+ kfree(acl_role_set.r_hash);
59325+ else
59326+ vfree(acl_role_set.r_hash);
59327+ }
59328+ if (name_set.n_hash) {
59329+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
59330+ PAGE_SIZE)
59331+ kfree(name_set.n_hash);
59332+ else
59333+ vfree(name_set.n_hash);
59334+ }
59335+
59336+ if (inodev_set.i_hash) {
59337+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
59338+ PAGE_SIZE)
59339+ kfree(inodev_set.i_hash);
59340+ else
59341+ vfree(inodev_set.i_hash);
59342+ }
59343+
59344+ gr_free_uidset();
59345+
59346+ memset(&name_set, 0, sizeof (struct name_db));
59347+ memset(&inodev_set, 0, sizeof (struct inodev_db));
59348+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
59349+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
59350+
59351+ default_role = NULL;
59352+ kernel_role = NULL;
59353+ role_list = NULL;
59354+
59355+ return;
59356+}
59357+
59358+static __u32
59359+count_user_objs(struct acl_object_label *userp)
59360+{
59361+ struct acl_object_label o_tmp;
59362+ __u32 num = 0;
59363+
59364+ while (userp) {
59365+ if (copy_from_user(&o_tmp, userp,
59366+ sizeof (struct acl_object_label)))
59367+ break;
59368+
59369+ userp = o_tmp.prev;
59370+ num++;
59371+ }
59372+
59373+ return num;
59374+}
59375+
59376+static struct acl_subject_label *
59377+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
59378+
59379+static int
59380+copy_user_glob(struct acl_object_label *obj)
59381+{
59382+ struct acl_object_label *g_tmp, **guser;
59383+ unsigned int len;
59384+ char *tmp;
59385+
59386+ if (obj->globbed == NULL)
59387+ return 0;
59388+
59389+ guser = &obj->globbed;
59390+ while (*guser) {
59391+ g_tmp = (struct acl_object_label *)
59392+ acl_alloc(sizeof (struct acl_object_label));
59393+ if (g_tmp == NULL)
59394+ return -ENOMEM;
59395+
59396+ if (copy_from_user(g_tmp, *guser,
59397+ sizeof (struct acl_object_label)))
59398+ return -EFAULT;
59399+
59400+ len = strnlen_user(g_tmp->filename, PATH_MAX);
59401+
59402+ if (!len || len >= PATH_MAX)
59403+ return -EINVAL;
59404+
59405+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59406+ return -ENOMEM;
59407+
59408+ if (copy_from_user(tmp, g_tmp->filename, len))
59409+ return -EFAULT;
59410+ tmp[len-1] = '\0';
59411+ g_tmp->filename = tmp;
59412+
59413+ *guser = g_tmp;
59414+ guser = &(g_tmp->next);
59415+ }
59416+
59417+ return 0;
59418+}
59419+
59420+static int
59421+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
59422+ struct acl_role_label *role)
59423+{
59424+ struct acl_object_label *o_tmp;
59425+ unsigned int len;
59426+ int ret;
59427+ char *tmp;
59428+
59429+ while (userp) {
59430+ if ((o_tmp = (struct acl_object_label *)
59431+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
59432+ return -ENOMEM;
59433+
59434+ if (copy_from_user(o_tmp, userp,
59435+ sizeof (struct acl_object_label)))
59436+ return -EFAULT;
59437+
59438+ userp = o_tmp->prev;
59439+
59440+ len = strnlen_user(o_tmp->filename, PATH_MAX);
59441+
59442+ if (!len || len >= PATH_MAX)
59443+ return -EINVAL;
59444+
59445+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59446+ return -ENOMEM;
59447+
59448+ if (copy_from_user(tmp, o_tmp->filename, len))
59449+ return -EFAULT;
59450+ tmp[len-1] = '\0';
59451+ o_tmp->filename = tmp;
59452+
59453+ insert_acl_obj_label(o_tmp, subj);
59454+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
59455+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
59456+ return -ENOMEM;
59457+
59458+ ret = copy_user_glob(o_tmp);
59459+ if (ret)
59460+ return ret;
59461+
59462+ if (o_tmp->nested) {
59463+ int already_copied;
59464+
59465+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
59466+ if (IS_ERR(o_tmp->nested))
59467+ return PTR_ERR(o_tmp->nested);
59468+
59469+ /* insert into nested subject list if we haven't copied this one yet
59470+ to prevent duplicate entries */
59471+ if (!already_copied) {
59472+ o_tmp->nested->next = role->hash->first;
59473+ role->hash->first = o_tmp->nested;
59474+ }
59475+ }
59476+ }
59477+
59478+ return 0;
59479+}
59480+
59481+static __u32
59482+count_user_subjs(struct acl_subject_label *userp)
59483+{
59484+ struct acl_subject_label s_tmp;
59485+ __u32 num = 0;
59486+
59487+ while (userp) {
59488+ if (copy_from_user(&s_tmp, userp,
59489+ sizeof (struct acl_subject_label)))
59490+ break;
59491+
59492+ userp = s_tmp.prev;
59493+ }
59494+
59495+ return num;
59496+}
59497+
59498+static int
59499+copy_user_allowedips(struct acl_role_label *rolep)
59500+{
59501+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
59502+
59503+ ruserip = rolep->allowed_ips;
59504+
59505+ while (ruserip) {
59506+ rlast = rtmp;
59507+
59508+ if ((rtmp = (struct role_allowed_ip *)
59509+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
59510+ return -ENOMEM;
59511+
59512+ if (copy_from_user(rtmp, ruserip,
59513+ sizeof (struct role_allowed_ip)))
59514+ return -EFAULT;
59515+
59516+ ruserip = rtmp->prev;
59517+
59518+ if (!rlast) {
59519+ rtmp->prev = NULL;
59520+ rolep->allowed_ips = rtmp;
59521+ } else {
59522+ rlast->next = rtmp;
59523+ rtmp->prev = rlast;
59524+ }
59525+
59526+ if (!ruserip)
59527+ rtmp->next = NULL;
59528+ }
59529+
59530+ return 0;
59531+}
59532+
59533+static int
59534+copy_user_transitions(struct acl_role_label *rolep)
59535+{
59536+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
59537+
59538+ unsigned int len;
59539+ char *tmp;
59540+
59541+ rusertp = rolep->transitions;
59542+
59543+ while (rusertp) {
59544+ rlast = rtmp;
59545+
59546+ if ((rtmp = (struct role_transition *)
59547+ acl_alloc(sizeof (struct role_transition))) == NULL)
59548+ return -ENOMEM;
59549+
59550+ if (copy_from_user(rtmp, rusertp,
59551+ sizeof (struct role_transition)))
59552+ return -EFAULT;
59553+
59554+ rusertp = rtmp->prev;
59555+
59556+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
59557+
59558+ if (!len || len >= GR_SPROLE_LEN)
59559+ return -EINVAL;
59560+
59561+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59562+ return -ENOMEM;
59563+
59564+ if (copy_from_user(tmp, rtmp->rolename, len))
59565+ return -EFAULT;
59566+ tmp[len-1] = '\0';
59567+ rtmp->rolename = tmp;
59568+
59569+ if (!rlast) {
59570+ rtmp->prev = NULL;
59571+ rolep->transitions = rtmp;
59572+ } else {
59573+ rlast->next = rtmp;
59574+ rtmp->prev = rlast;
59575+ }
59576+
59577+ if (!rusertp)
59578+ rtmp->next = NULL;
59579+ }
59580+
59581+ return 0;
59582+}
59583+
59584+static struct acl_subject_label *
59585+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
59586+{
59587+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
59588+ unsigned int len;
59589+ char *tmp;
59590+ __u32 num_objs;
59591+ struct acl_ip_label **i_tmp, *i_utmp2;
59592+ struct gr_hash_struct ghash;
59593+ struct subject_map *subjmap;
59594+ unsigned int i_num;
59595+ int err;
59596+
59597+ if (already_copied != NULL)
59598+ *already_copied = 0;
59599+
59600+ s_tmp = lookup_subject_map(userp);
59601+
59602+ /* we've already copied this subject into the kernel, just return
59603+ the reference to it, and don't copy it over again
59604+ */
59605+ if (s_tmp) {
59606+ if (already_copied != NULL)
59607+ *already_copied = 1;
59608+ return(s_tmp);
59609+ }
59610+
59611+ if ((s_tmp = (struct acl_subject_label *)
59612+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
59613+ return ERR_PTR(-ENOMEM);
59614+
59615+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
59616+ if (subjmap == NULL)
59617+ return ERR_PTR(-ENOMEM);
59618+
59619+ subjmap->user = userp;
59620+ subjmap->kernel = s_tmp;
59621+ insert_subj_map_entry(subjmap);
59622+
59623+ if (copy_from_user(s_tmp, userp,
59624+ sizeof (struct acl_subject_label)))
59625+ return ERR_PTR(-EFAULT);
59626+
59627+ len = strnlen_user(s_tmp->filename, PATH_MAX);
59628+
59629+ if (!len || len >= PATH_MAX)
59630+ return ERR_PTR(-EINVAL);
59631+
59632+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59633+ return ERR_PTR(-ENOMEM);
59634+
59635+ if (copy_from_user(tmp, s_tmp->filename, len))
59636+ return ERR_PTR(-EFAULT);
59637+ tmp[len-1] = '\0';
59638+ s_tmp->filename = tmp;
59639+
59640+ if (!strcmp(s_tmp->filename, "/"))
59641+ role->root_label = s_tmp;
59642+
59643+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
59644+ return ERR_PTR(-EFAULT);
59645+
59646+ /* copy user and group transition tables */
59647+
59648+ if (s_tmp->user_trans_num) {
59649+ uid_t *uidlist;
59650+
59651+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
59652+ if (uidlist == NULL)
59653+ return ERR_PTR(-ENOMEM);
59654+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
59655+ return ERR_PTR(-EFAULT);
59656+
59657+ s_tmp->user_transitions = uidlist;
59658+ }
59659+
59660+ if (s_tmp->group_trans_num) {
59661+ gid_t *gidlist;
59662+
59663+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
59664+ if (gidlist == NULL)
59665+ return ERR_PTR(-ENOMEM);
59666+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
59667+ return ERR_PTR(-EFAULT);
59668+
59669+ s_tmp->group_transitions = gidlist;
59670+ }
59671+
59672+ /* set up object hash table */
59673+ num_objs = count_user_objs(ghash.first);
59674+
59675+ s_tmp->obj_hash_size = num_objs;
59676+ s_tmp->obj_hash =
59677+ (struct acl_object_label **)
59678+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
59679+
59680+ if (!s_tmp->obj_hash)
59681+ return ERR_PTR(-ENOMEM);
59682+
59683+ memset(s_tmp->obj_hash, 0,
59684+ s_tmp->obj_hash_size *
59685+ sizeof (struct acl_object_label *));
59686+
59687+ /* add in objects */
59688+ err = copy_user_objs(ghash.first, s_tmp, role);
59689+
59690+ if (err)
59691+ return ERR_PTR(err);
59692+
59693+ /* set pointer for parent subject */
59694+ if (s_tmp->parent_subject) {
59695+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
59696+
59697+ if (IS_ERR(s_tmp2))
59698+ return s_tmp2;
59699+
59700+ s_tmp->parent_subject = s_tmp2;
59701+ }
59702+
59703+ /* add in ip acls */
59704+
59705+ if (!s_tmp->ip_num) {
59706+ s_tmp->ips = NULL;
59707+ goto insert;
59708+ }
59709+
59710+ i_tmp =
59711+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
59712+ sizeof (struct acl_ip_label *));
59713+
59714+ if (!i_tmp)
59715+ return ERR_PTR(-ENOMEM);
59716+
59717+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
59718+ *(i_tmp + i_num) =
59719+ (struct acl_ip_label *)
59720+ acl_alloc(sizeof (struct acl_ip_label));
59721+ if (!*(i_tmp + i_num))
59722+ return ERR_PTR(-ENOMEM);
59723+
59724+ if (copy_from_user
59725+ (&i_utmp2, s_tmp->ips + i_num,
59726+ sizeof (struct acl_ip_label *)))
59727+ return ERR_PTR(-EFAULT);
59728+
59729+ if (copy_from_user
59730+ (*(i_tmp + i_num), i_utmp2,
59731+ sizeof (struct acl_ip_label)))
59732+ return ERR_PTR(-EFAULT);
59733+
59734+ if ((*(i_tmp + i_num))->iface == NULL)
59735+ continue;
59736+
59737+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
59738+ if (!len || len >= IFNAMSIZ)
59739+ return ERR_PTR(-EINVAL);
59740+ tmp = acl_alloc(len);
59741+ if (tmp == NULL)
59742+ return ERR_PTR(-ENOMEM);
59743+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
59744+ return ERR_PTR(-EFAULT);
59745+ (*(i_tmp + i_num))->iface = tmp;
59746+ }
59747+
59748+ s_tmp->ips = i_tmp;
59749+
59750+insert:
59751+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
59752+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
59753+ return ERR_PTR(-ENOMEM);
59754+
59755+ return s_tmp;
59756+}
59757+
59758+static int
59759+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
59760+{
59761+ struct acl_subject_label s_pre;
59762+ struct acl_subject_label * ret;
59763+ int err;
59764+
59765+ while (userp) {
59766+ if (copy_from_user(&s_pre, userp,
59767+ sizeof (struct acl_subject_label)))
59768+ return -EFAULT;
59769+
59770+ ret = do_copy_user_subj(userp, role, NULL);
59771+
59772+ err = PTR_ERR(ret);
59773+ if (IS_ERR(ret))
59774+ return err;
59775+
59776+ insert_acl_subj_label(ret, role);
59777+
59778+ userp = s_pre.prev;
59779+ }
59780+
59781+ return 0;
59782+}
59783+
59784+static int
59785+copy_user_acl(struct gr_arg *arg)
59786+{
59787+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
59788+ struct acl_subject_label *subj_list;
59789+ struct sprole_pw *sptmp;
59790+ struct gr_hash_struct *ghash;
59791+ uid_t *domainlist;
59792+ unsigned int r_num;
59793+ unsigned int len;
59794+ char *tmp;
59795+ int err = 0;
59796+ __u16 i;
59797+ __u32 num_subjs;
59798+
59799+ /* we need a default and kernel role */
59800+ if (arg->role_db.num_roles < 2)
59801+ return -EINVAL;
59802+
59803+ /* copy special role authentication info from userspace */
59804+
59805+ num_sprole_pws = arg->num_sprole_pws;
59806+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
59807+
59808+ if (!acl_special_roles && num_sprole_pws)
59809+ return -ENOMEM;
59810+
59811+ for (i = 0; i < num_sprole_pws; i++) {
59812+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
59813+ if (!sptmp)
59814+ return -ENOMEM;
59815+ if (copy_from_user(sptmp, arg->sprole_pws + i,
59816+ sizeof (struct sprole_pw)))
59817+ return -EFAULT;
59818+
59819+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
59820+
59821+ if (!len || len >= GR_SPROLE_LEN)
59822+ return -EINVAL;
59823+
59824+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59825+ return -ENOMEM;
59826+
59827+ if (copy_from_user(tmp, sptmp->rolename, len))
59828+ return -EFAULT;
59829+
59830+ tmp[len-1] = '\0';
59831+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59832+ printk(KERN_ALERT "Copying special role %s\n", tmp);
59833+#endif
59834+ sptmp->rolename = tmp;
59835+ acl_special_roles[i] = sptmp;
59836+ }
59837+
59838+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
59839+
59840+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
59841+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
59842+
59843+ if (!r_tmp)
59844+ return -ENOMEM;
59845+
59846+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
59847+ sizeof (struct acl_role_label *)))
59848+ return -EFAULT;
59849+
59850+ if (copy_from_user(r_tmp, r_utmp2,
59851+ sizeof (struct acl_role_label)))
59852+ return -EFAULT;
59853+
59854+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
59855+
59856+ if (!len || len >= PATH_MAX)
59857+ return -EINVAL;
59858+
59859+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59860+ return -ENOMEM;
59861+
59862+ if (copy_from_user(tmp, r_tmp->rolename, len))
59863+ return -EFAULT;
59864+
59865+ tmp[len-1] = '\0';
59866+ r_tmp->rolename = tmp;
59867+
59868+ if (!strcmp(r_tmp->rolename, "default")
59869+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
59870+ default_role = r_tmp;
59871+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
59872+ kernel_role = r_tmp;
59873+ }
59874+
59875+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
59876+ return -ENOMEM;
59877+
59878+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
59879+ return -EFAULT;
59880+
59881+ r_tmp->hash = ghash;
59882+
59883+ num_subjs = count_user_subjs(r_tmp->hash->first);
59884+
59885+ r_tmp->subj_hash_size = num_subjs;
59886+ r_tmp->subj_hash =
59887+ (struct acl_subject_label **)
59888+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
59889+
59890+ if (!r_tmp->subj_hash)
59891+ return -ENOMEM;
59892+
59893+ err = copy_user_allowedips(r_tmp);
59894+ if (err)
59895+ return err;
59896+
59897+ /* copy domain info */
59898+ if (r_tmp->domain_children != NULL) {
59899+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
59900+ if (domainlist == NULL)
59901+ return -ENOMEM;
59902+
59903+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
59904+ return -EFAULT;
59905+
59906+ r_tmp->domain_children = domainlist;
59907+ }
59908+
59909+ err = copy_user_transitions(r_tmp);
59910+ if (err)
59911+ return err;
59912+
59913+ memset(r_tmp->subj_hash, 0,
59914+ r_tmp->subj_hash_size *
59915+ sizeof (struct acl_subject_label *));
59916+
59917+ /* acquire the list of subjects, then NULL out
59918+ the list prior to parsing the subjects for this role,
59919+ as during this parsing the list is replaced with a list
59920+ of *nested* subjects for the role
59921+ */
59922+ subj_list = r_tmp->hash->first;
59923+
59924+ /* set nested subject list to null */
59925+ r_tmp->hash->first = NULL;
59926+
59927+ err = copy_user_subjs(subj_list, r_tmp);
59928+
59929+ if (err)
59930+ return err;
59931+
59932+ insert_acl_role_label(r_tmp);
59933+ }
59934+
59935+ if (default_role == NULL || kernel_role == NULL)
59936+ return -EINVAL;
59937+
59938+ return err;
59939+}
59940+
59941+static int
59942+gracl_init(struct gr_arg *args)
59943+{
59944+ int error = 0;
59945+
59946+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
59947+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
59948+
59949+ if (init_variables(args)) {
59950+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
59951+ error = -ENOMEM;
59952+ free_variables();
59953+ goto out;
59954+ }
59955+
59956+ error = copy_user_acl(args);
59957+ free_init_variables();
59958+ if (error) {
59959+ free_variables();
59960+ goto out;
59961+ }
59962+
59963+ if ((error = gr_set_acls(0))) {
59964+ free_variables();
59965+ goto out;
59966+ }
59967+
59968+ pax_open_kernel();
59969+ gr_status |= GR_READY;
59970+ pax_close_kernel();
59971+
59972+ out:
59973+ return error;
59974+}
59975+
59976+/* derived from glibc fnmatch() 0: match, 1: no match*/
59977+
59978+static int
59979+glob_match(const char *p, const char *n)
59980+{
59981+ char c;
59982+
59983+ while ((c = *p++) != '\0') {
59984+ switch (c) {
59985+ case '?':
59986+ if (*n == '\0')
59987+ return 1;
59988+ else if (*n == '/')
59989+ return 1;
59990+ break;
59991+ case '\\':
59992+ if (*n != c)
59993+ return 1;
59994+ break;
59995+ case '*':
59996+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
59997+ if (*n == '/')
59998+ return 1;
59999+ else if (c == '?') {
60000+ if (*n == '\0')
60001+ return 1;
60002+ else
60003+ ++n;
60004+ }
60005+ }
60006+ if (c == '\0') {
60007+ return 0;
60008+ } else {
60009+ const char *endp;
60010+
60011+ if ((endp = strchr(n, '/')) == NULL)
60012+ endp = n + strlen(n);
60013+
60014+ if (c == '[') {
60015+ for (--p; n < endp; ++n)
60016+ if (!glob_match(p, n))
60017+ return 0;
60018+ } else if (c == '/') {
60019+ while (*n != '\0' && *n != '/')
60020+ ++n;
60021+ if (*n == '/' && !glob_match(p, n + 1))
60022+ return 0;
60023+ } else {
60024+ for (--p; n < endp; ++n)
60025+ if (*n == c && !glob_match(p, n))
60026+ return 0;
60027+ }
60028+
60029+ return 1;
60030+ }
60031+ case '[':
60032+ {
60033+ int not;
60034+ char cold;
60035+
60036+ if (*n == '\0' || *n == '/')
60037+ return 1;
60038+
60039+ not = (*p == '!' || *p == '^');
60040+ if (not)
60041+ ++p;
60042+
60043+ c = *p++;
60044+ for (;;) {
60045+ unsigned char fn = (unsigned char)*n;
60046+
60047+ if (c == '\0')
60048+ return 1;
60049+ else {
60050+ if (c == fn)
60051+ goto matched;
60052+ cold = c;
60053+ c = *p++;
60054+
60055+ if (c == '-' && *p != ']') {
60056+ unsigned char cend = *p++;
60057+
60058+ if (cend == '\0')
60059+ return 1;
60060+
60061+ if (cold <= fn && fn <= cend)
60062+ goto matched;
60063+
60064+ c = *p++;
60065+ }
60066+ }
60067+
60068+ if (c == ']')
60069+ break;
60070+ }
60071+ if (!not)
60072+ return 1;
60073+ break;
60074+ matched:
60075+ while (c != ']') {
60076+ if (c == '\0')
60077+ return 1;
60078+
60079+ c = *p++;
60080+ }
60081+ if (not)
60082+ return 1;
60083+ }
60084+ break;
60085+ default:
60086+ if (c != *n)
60087+ return 1;
60088+ }
60089+
60090+ ++n;
60091+ }
60092+
60093+ if (*n == '\0')
60094+ return 0;
60095+
60096+ if (*n == '/')
60097+ return 0;
60098+
60099+ return 1;
60100+}
60101+
60102+static struct acl_object_label *
60103+chk_glob_label(struct acl_object_label *globbed,
60104+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
60105+{
60106+ struct acl_object_label *tmp;
60107+
60108+ if (*path == NULL)
60109+ *path = gr_to_filename_nolock(dentry, mnt);
60110+
60111+ tmp = globbed;
60112+
60113+ while (tmp) {
60114+ if (!glob_match(tmp->filename, *path))
60115+ return tmp;
60116+ tmp = tmp->next;
60117+ }
60118+
60119+ return NULL;
60120+}
60121+
60122+static struct acl_object_label *
60123+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60124+ const ino_t curr_ino, const dev_t curr_dev,
60125+ const struct acl_subject_label *subj, char **path, const int checkglob)
60126+{
60127+ struct acl_subject_label *tmpsubj;
60128+ struct acl_object_label *retval;
60129+ struct acl_object_label *retval2;
60130+
60131+ tmpsubj = (struct acl_subject_label *) subj;
60132+ read_lock(&gr_inode_lock);
60133+ do {
60134+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
60135+ if (retval) {
60136+ if (checkglob && retval->globbed) {
60137+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
60138+ if (retval2)
60139+ retval = retval2;
60140+ }
60141+ break;
60142+ }
60143+ } while ((tmpsubj = tmpsubj->parent_subject));
60144+ read_unlock(&gr_inode_lock);
60145+
60146+ return retval;
60147+}
60148+
60149+static __inline__ struct acl_object_label *
60150+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60151+ struct dentry *curr_dentry,
60152+ const struct acl_subject_label *subj, char **path, const int checkglob)
60153+{
60154+ int newglob = checkglob;
60155+ ino_t inode;
60156+ dev_t device;
60157+
60158+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
60159+ as we don't want a / * rule to match instead of the / object
60160+ don't do this for create lookups that call this function though, since they're looking up
60161+ on the parent and thus need globbing checks on all paths
60162+ */
60163+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
60164+ newglob = GR_NO_GLOB;
60165+
60166+ spin_lock(&curr_dentry->d_lock);
60167+ inode = curr_dentry->d_inode->i_ino;
60168+ device = __get_dev(curr_dentry);
60169+ spin_unlock(&curr_dentry->d_lock);
60170+
60171+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
60172+}
60173+
60174+#ifdef CONFIG_HUGETLBFS
60175+static inline bool
60176+is_hugetlbfs_mnt(const struct vfsmount *mnt)
60177+{
60178+ int i;
60179+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
60180+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
60181+ return true;
60182+ }
60183+
60184+ return false;
60185+}
60186+#endif
60187+
60188+static struct acl_object_label *
60189+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60190+ const struct acl_subject_label *subj, char *path, const int checkglob)
60191+{
60192+ struct dentry *dentry = (struct dentry *) l_dentry;
60193+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60194+ struct mount *real_mnt = real_mount(mnt);
60195+ struct acl_object_label *retval;
60196+ struct dentry *parent;
60197+
60198+ br_read_lock(&vfsmount_lock);
60199+ write_seqlock(&rename_lock);
60200+
60201+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
60202+#ifdef CONFIG_NET
60203+ mnt == sock_mnt ||
60204+#endif
60205+#ifdef CONFIG_HUGETLBFS
60206+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
60207+#endif
60208+ /* ignore Eric Biederman */
60209+ IS_PRIVATE(l_dentry->d_inode))) {
60210+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
60211+ goto out;
60212+ }
60213+
60214+ for (;;) {
60215+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60216+ break;
60217+
60218+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60219+ if (!mnt_has_parent(real_mnt))
60220+ break;
60221+
60222+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60223+ if (retval != NULL)
60224+ goto out;
60225+
60226+ dentry = real_mnt->mnt_mountpoint;
60227+ real_mnt = real_mnt->mnt_parent;
60228+ mnt = &real_mnt->mnt;
60229+ continue;
60230+ }
60231+
60232+ parent = dentry->d_parent;
60233+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60234+ if (retval != NULL)
60235+ goto out;
60236+
60237+ dentry = parent;
60238+ }
60239+
60240+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60241+
60242+ /* real_root is pinned so we don't have to hold a reference */
60243+ if (retval == NULL)
60244+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
60245+out:
60246+ write_sequnlock(&rename_lock);
60247+ br_read_unlock(&vfsmount_lock);
60248+
60249+ BUG_ON(retval == NULL);
60250+
60251+ return retval;
60252+}
60253+
60254+static __inline__ struct acl_object_label *
60255+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60256+ const struct acl_subject_label *subj)
60257+{
60258+ char *path = NULL;
60259+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
60260+}
60261+
60262+static __inline__ struct acl_object_label *
60263+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60264+ const struct acl_subject_label *subj)
60265+{
60266+ char *path = NULL;
60267+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
60268+}
60269+
60270+static __inline__ struct acl_object_label *
60271+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60272+ const struct acl_subject_label *subj, char *path)
60273+{
60274+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
60275+}
60276+
60277+static struct acl_subject_label *
60278+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60279+ const struct acl_role_label *role)
60280+{
60281+ struct dentry *dentry = (struct dentry *) l_dentry;
60282+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60283+ struct mount *real_mnt = real_mount(mnt);
60284+ struct acl_subject_label *retval;
60285+ struct dentry *parent;
60286+
60287+ br_read_lock(&vfsmount_lock);
60288+ write_seqlock(&rename_lock);
60289+
60290+ for (;;) {
60291+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60292+ break;
60293+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60294+ if (!mnt_has_parent(real_mnt))
60295+ break;
60296+
60297+ spin_lock(&dentry->d_lock);
60298+ read_lock(&gr_inode_lock);
60299+ retval =
60300+ lookup_acl_subj_label(dentry->d_inode->i_ino,
60301+ __get_dev(dentry), role);
60302+ read_unlock(&gr_inode_lock);
60303+ spin_unlock(&dentry->d_lock);
60304+ if (retval != NULL)
60305+ goto out;
60306+
60307+ dentry = real_mnt->mnt_mountpoint;
60308+ real_mnt = real_mnt->mnt_parent;
60309+ mnt = &real_mnt->mnt;
60310+ continue;
60311+ }
60312+
60313+ spin_lock(&dentry->d_lock);
60314+ read_lock(&gr_inode_lock);
60315+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60316+ __get_dev(dentry), role);
60317+ read_unlock(&gr_inode_lock);
60318+ parent = dentry->d_parent;
60319+ spin_unlock(&dentry->d_lock);
60320+
60321+ if (retval != NULL)
60322+ goto out;
60323+
60324+ dentry = parent;
60325+ }
60326+
60327+ spin_lock(&dentry->d_lock);
60328+ read_lock(&gr_inode_lock);
60329+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60330+ __get_dev(dentry), role);
60331+ read_unlock(&gr_inode_lock);
60332+ spin_unlock(&dentry->d_lock);
60333+
60334+ if (unlikely(retval == NULL)) {
60335+ /* real_root is pinned, we don't need to hold a reference */
60336+ read_lock(&gr_inode_lock);
60337+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
60338+ __get_dev(real_root.dentry), role);
60339+ read_unlock(&gr_inode_lock);
60340+ }
60341+out:
60342+ write_sequnlock(&rename_lock);
60343+ br_read_unlock(&vfsmount_lock);
60344+
60345+ BUG_ON(retval == NULL);
60346+
60347+ return retval;
60348+}
60349+
60350+static void
60351+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
60352+{
60353+ struct task_struct *task = current;
60354+ const struct cred *cred = current_cred();
60355+
60356+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
60357+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60358+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60359+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
60360+
60361+ return;
60362+}
60363+
60364+static void
60365+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
60366+{
60367+ struct task_struct *task = current;
60368+ const struct cred *cred = current_cred();
60369+
60370+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60371+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60372+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60373+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
60374+
60375+ return;
60376+}
60377+
60378+static void
60379+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
60380+{
60381+ struct task_struct *task = current;
60382+ const struct cred *cred = current_cred();
60383+
60384+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60385+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60386+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60387+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
60388+
60389+ return;
60390+}
60391+
60392+__u32
60393+gr_search_file(const struct dentry * dentry, const __u32 mode,
60394+ const struct vfsmount * mnt)
60395+{
60396+ __u32 retval = mode;
60397+ struct acl_subject_label *curracl;
60398+ struct acl_object_label *currobj;
60399+
60400+ if (unlikely(!(gr_status & GR_READY)))
60401+ return (mode & ~GR_AUDITS);
60402+
60403+ curracl = current->acl;
60404+
60405+ currobj = chk_obj_label(dentry, mnt, curracl);
60406+ retval = currobj->mode & mode;
60407+
60408+ /* if we're opening a specified transfer file for writing
60409+ (e.g. /dev/initctl), then transfer our role to init
60410+ */
60411+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
60412+ current->role->roletype & GR_ROLE_PERSIST)) {
60413+ struct task_struct *task = init_pid_ns.child_reaper;
60414+
60415+ if (task->role != current->role) {
60416+ task->acl_sp_role = 0;
60417+ task->acl_role_id = current->acl_role_id;
60418+ task->role = current->role;
60419+ rcu_read_lock();
60420+ read_lock(&grsec_exec_file_lock);
60421+ gr_apply_subject_to_task(task);
60422+ read_unlock(&grsec_exec_file_lock);
60423+ rcu_read_unlock();
60424+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
60425+ }
60426+ }
60427+
60428+ if (unlikely
60429+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
60430+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
60431+ __u32 new_mode = mode;
60432+
60433+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60434+
60435+ retval = new_mode;
60436+
60437+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
60438+ new_mode |= GR_INHERIT;
60439+
60440+ if (!(mode & GR_NOLEARN))
60441+ gr_log_learn(dentry, mnt, new_mode);
60442+ }
60443+
60444+ return retval;
60445+}
60446+
60447+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
60448+ const struct dentry *parent,
60449+ const struct vfsmount *mnt)
60450+{
60451+ struct name_entry *match;
60452+ struct acl_object_label *matchpo;
60453+ struct acl_subject_label *curracl;
60454+ char *path;
60455+
60456+ if (unlikely(!(gr_status & GR_READY)))
60457+ return NULL;
60458+
60459+ preempt_disable();
60460+ path = gr_to_filename_rbac(new_dentry, mnt);
60461+ match = lookup_name_entry_create(path);
60462+
60463+ curracl = current->acl;
60464+
60465+ if (match) {
60466+ read_lock(&gr_inode_lock);
60467+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
60468+ read_unlock(&gr_inode_lock);
60469+
60470+ if (matchpo) {
60471+ preempt_enable();
60472+ return matchpo;
60473+ }
60474+ }
60475+
60476+ // lookup parent
60477+
60478+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
60479+
60480+ preempt_enable();
60481+ return matchpo;
60482+}
60483+
60484+__u32
60485+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
60486+ const struct vfsmount * mnt, const __u32 mode)
60487+{
60488+ struct acl_object_label *matchpo;
60489+ __u32 retval;
60490+
60491+ if (unlikely(!(gr_status & GR_READY)))
60492+ return (mode & ~GR_AUDITS);
60493+
60494+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
60495+
60496+ retval = matchpo->mode & mode;
60497+
60498+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
60499+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60500+ __u32 new_mode = mode;
60501+
60502+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60503+
60504+ gr_log_learn(new_dentry, mnt, new_mode);
60505+ return new_mode;
60506+ }
60507+
60508+ return retval;
60509+}
60510+
60511+__u32
60512+gr_check_link(const struct dentry * new_dentry,
60513+ const struct dentry * parent_dentry,
60514+ const struct vfsmount * parent_mnt,
60515+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
60516+{
60517+ struct acl_object_label *obj;
60518+ __u32 oldmode, newmode;
60519+ __u32 needmode;
60520+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
60521+ GR_DELETE | GR_INHERIT;
60522+
60523+ if (unlikely(!(gr_status & GR_READY)))
60524+ return (GR_CREATE | GR_LINK);
60525+
60526+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
60527+ oldmode = obj->mode;
60528+
60529+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
60530+ newmode = obj->mode;
60531+
60532+ needmode = newmode & checkmodes;
60533+
60534+ // old name for hardlink must have at least the permissions of the new name
60535+ if ((oldmode & needmode) != needmode)
60536+ goto bad;
60537+
60538+ // if old name had restrictions/auditing, make sure the new name does as well
60539+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
60540+
60541+ // don't allow hardlinking of suid/sgid/fcapped files without permission
60542+ if (is_privileged_binary(old_dentry))
60543+ needmode |= GR_SETID;
60544+
60545+ if ((newmode & needmode) != needmode)
60546+ goto bad;
60547+
60548+ // enforce minimum permissions
60549+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
60550+ return newmode;
60551+bad:
60552+ needmode = oldmode;
60553+ if (is_privileged_binary(old_dentry))
60554+ needmode |= GR_SETID;
60555+
60556+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
60557+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
60558+ return (GR_CREATE | GR_LINK);
60559+ } else if (newmode & GR_SUPPRESS)
60560+ return GR_SUPPRESS;
60561+ else
60562+ return 0;
60563+}
60564+
60565+int
60566+gr_check_hidden_task(const struct task_struct *task)
60567+{
60568+ if (unlikely(!(gr_status & GR_READY)))
60569+ return 0;
60570+
60571+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
60572+ return 1;
60573+
60574+ return 0;
60575+}
60576+
60577+int
60578+gr_check_protected_task(const struct task_struct *task)
60579+{
60580+ if (unlikely(!(gr_status & GR_READY) || !task))
60581+ return 0;
60582+
60583+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60584+ task->acl != current->acl)
60585+ return 1;
60586+
60587+ return 0;
60588+}
60589+
60590+int
60591+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60592+{
60593+ struct task_struct *p;
60594+ int ret = 0;
60595+
60596+ if (unlikely(!(gr_status & GR_READY) || !pid))
60597+ return ret;
60598+
60599+ read_lock(&tasklist_lock);
60600+ do_each_pid_task(pid, type, p) {
60601+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60602+ p->acl != current->acl) {
60603+ ret = 1;
60604+ goto out;
60605+ }
60606+ } while_each_pid_task(pid, type, p);
60607+out:
60608+ read_unlock(&tasklist_lock);
60609+
60610+ return ret;
60611+}
60612+
60613+void
60614+gr_copy_label(struct task_struct *tsk)
60615+{
60616+ tsk->signal->used_accept = 0;
60617+ tsk->acl_sp_role = 0;
60618+ tsk->acl_role_id = current->acl_role_id;
60619+ tsk->acl = current->acl;
60620+ tsk->role = current->role;
60621+ tsk->signal->curr_ip = current->signal->curr_ip;
60622+ tsk->signal->saved_ip = current->signal->saved_ip;
60623+ if (current->exec_file)
60624+ get_file(current->exec_file);
60625+ tsk->exec_file = current->exec_file;
60626+ tsk->is_writable = current->is_writable;
60627+ if (unlikely(current->signal->used_accept)) {
60628+ current->signal->curr_ip = 0;
60629+ current->signal->saved_ip = 0;
60630+ }
60631+
60632+ return;
60633+}
60634+
60635+static void
60636+gr_set_proc_res(struct task_struct *task)
60637+{
60638+ struct acl_subject_label *proc;
60639+ unsigned short i;
60640+
60641+ proc = task->acl;
60642+
60643+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
60644+ return;
60645+
60646+ for (i = 0; i < RLIM_NLIMITS; i++) {
60647+ if (!(proc->resmask & (1U << i)))
60648+ continue;
60649+
60650+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
60651+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
60652+
60653+ if (i == RLIMIT_CPU)
60654+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
60655+ }
60656+
60657+ return;
60658+}
60659+
60660+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
60661+
60662+int
60663+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
60664+{
60665+ unsigned int i;
60666+ __u16 num;
60667+ uid_t *uidlist;
60668+ uid_t curuid;
60669+ int realok = 0;
60670+ int effectiveok = 0;
60671+ int fsok = 0;
60672+ uid_t globalreal, globaleffective, globalfs;
60673+
60674+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
60675+ struct user_struct *user;
60676+
60677+ if (!uid_valid(real))
60678+ goto skipit;
60679+
60680+ /* find user based on global namespace */
60681+
60682+ globalreal = GR_GLOBAL_UID(real);
60683+
60684+ user = find_user(make_kuid(&init_user_ns, globalreal));
60685+ if (user == NULL)
60686+ goto skipit;
60687+
60688+ if (gr_process_kernel_setuid_ban(user)) {
60689+ /* for find_user */
60690+ free_uid(user);
60691+ return 1;
60692+ }
60693+
60694+ /* for find_user */
60695+ free_uid(user);
60696+
60697+skipit:
60698+#endif
60699+
60700+ if (unlikely(!(gr_status & GR_READY)))
60701+ return 0;
60702+
60703+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60704+ gr_log_learn_uid_change(real, effective, fs);
60705+
60706+ num = current->acl->user_trans_num;
60707+ uidlist = current->acl->user_transitions;
60708+
60709+ if (uidlist == NULL)
60710+ return 0;
60711+
60712+ if (!uid_valid(real)) {
60713+ realok = 1;
60714+ globalreal = (uid_t)-1;
60715+ } else {
60716+ globalreal = GR_GLOBAL_UID(real);
60717+ }
60718+ if (!uid_valid(effective)) {
60719+ effectiveok = 1;
60720+ globaleffective = (uid_t)-1;
60721+ } else {
60722+ globaleffective = GR_GLOBAL_UID(effective);
60723+ }
60724+ if (!uid_valid(fs)) {
60725+ fsok = 1;
60726+ globalfs = (uid_t)-1;
60727+ } else {
60728+ globalfs = GR_GLOBAL_UID(fs);
60729+ }
60730+
60731+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
60732+ for (i = 0; i < num; i++) {
60733+ curuid = uidlist[i];
60734+ if (globalreal == curuid)
60735+ realok = 1;
60736+ if (globaleffective == curuid)
60737+ effectiveok = 1;
60738+ if (globalfs == curuid)
60739+ fsok = 1;
60740+ }
60741+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
60742+ for (i = 0; i < num; i++) {
60743+ curuid = uidlist[i];
60744+ if (globalreal == curuid)
60745+ break;
60746+ if (globaleffective == curuid)
60747+ break;
60748+ if (globalfs == curuid)
60749+ break;
60750+ }
60751+ /* not in deny list */
60752+ if (i == num) {
60753+ realok = 1;
60754+ effectiveok = 1;
60755+ fsok = 1;
60756+ }
60757+ }
60758+
60759+ if (realok && effectiveok && fsok)
60760+ return 0;
60761+ else {
60762+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60763+ return 1;
60764+ }
60765+}
60766+
60767+int
60768+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
60769+{
60770+ unsigned int i;
60771+ __u16 num;
60772+ gid_t *gidlist;
60773+ gid_t curgid;
60774+ int realok = 0;
60775+ int effectiveok = 0;
60776+ int fsok = 0;
60777+ gid_t globalreal, globaleffective, globalfs;
60778+
60779+ if (unlikely(!(gr_status & GR_READY)))
60780+ return 0;
60781+
60782+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60783+ gr_log_learn_gid_change(real, effective, fs);
60784+
60785+ num = current->acl->group_trans_num;
60786+ gidlist = current->acl->group_transitions;
60787+
60788+ if (gidlist == NULL)
60789+ return 0;
60790+
60791+ if (!gid_valid(real)) {
60792+ realok = 1;
60793+ globalreal = (gid_t)-1;
60794+ } else {
60795+ globalreal = GR_GLOBAL_GID(real);
60796+ }
60797+ if (!gid_valid(effective)) {
60798+ effectiveok = 1;
60799+ globaleffective = (gid_t)-1;
60800+ } else {
60801+ globaleffective = GR_GLOBAL_GID(effective);
60802+ }
60803+ if (!gid_valid(fs)) {
60804+ fsok = 1;
60805+ globalfs = (gid_t)-1;
60806+ } else {
60807+ globalfs = GR_GLOBAL_GID(fs);
60808+ }
60809+
60810+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
60811+ for (i = 0; i < num; i++) {
60812+ curgid = gidlist[i];
60813+ if (globalreal == curgid)
60814+ realok = 1;
60815+ if (globaleffective == curgid)
60816+ effectiveok = 1;
60817+ if (globalfs == curgid)
60818+ fsok = 1;
60819+ }
60820+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
60821+ for (i = 0; i < num; i++) {
60822+ curgid = gidlist[i];
60823+ if (globalreal == curgid)
60824+ break;
60825+ if (globaleffective == curgid)
60826+ break;
60827+ if (globalfs == curgid)
60828+ break;
60829+ }
60830+ /* not in deny list */
60831+ if (i == num) {
60832+ realok = 1;
60833+ effectiveok = 1;
60834+ fsok = 1;
60835+ }
60836+ }
60837+
60838+ if (realok && effectiveok && fsok)
60839+ return 0;
60840+ else {
60841+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60842+ return 1;
60843+ }
60844+}
60845+
60846+extern int gr_acl_is_capable(const int cap);
60847+
60848+void
60849+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
60850+{
60851+ struct acl_role_label *role = task->role;
60852+ struct acl_subject_label *subj = NULL;
60853+ struct acl_object_label *obj;
60854+ struct file *filp;
60855+ uid_t uid;
60856+ gid_t gid;
60857+
60858+ if (unlikely(!(gr_status & GR_READY)))
60859+ return;
60860+
60861+ uid = GR_GLOBAL_UID(kuid);
60862+ gid = GR_GLOBAL_GID(kgid);
60863+
60864+ filp = task->exec_file;
60865+
60866+ /* kernel process, we'll give them the kernel role */
60867+ if (unlikely(!filp)) {
60868+ task->role = kernel_role;
60869+ task->acl = kernel_role->root_label;
60870+ return;
60871+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
60872+ role = lookup_acl_role_label(task, uid, gid);
60873+
60874+ /* don't change the role if we're not a privileged process */
60875+ if (role && task->role != role &&
60876+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
60877+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
60878+ return;
60879+
60880+ /* perform subject lookup in possibly new role
60881+ we can use this result below in the case where role == task->role
60882+ */
60883+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
60884+
60885+ /* if we changed uid/gid, but result in the same role
60886+ and are using inheritance, don't lose the inherited subject
60887+ if current subject is other than what normal lookup
60888+ would result in, we arrived via inheritance, don't
60889+ lose subject
60890+ */
60891+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
60892+ (subj == task->acl)))
60893+ task->acl = subj;
60894+
60895+ task->role = role;
60896+
60897+ task->is_writable = 0;
60898+
60899+ /* ignore additional mmap checks for processes that are writable
60900+ by the default ACL */
60901+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60902+ if (unlikely(obj->mode & GR_WRITE))
60903+ task->is_writable = 1;
60904+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60905+ if (unlikely(obj->mode & GR_WRITE))
60906+ task->is_writable = 1;
60907+
60908+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60909+ 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);
60910+#endif
60911+
60912+ gr_set_proc_res(task);
60913+
60914+ return;
60915+}
60916+
60917+int
60918+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60919+ const int unsafe_flags)
60920+{
60921+ struct task_struct *task = current;
60922+ struct acl_subject_label *newacl;
60923+ struct acl_object_label *obj;
60924+ __u32 retmode;
60925+
60926+ if (unlikely(!(gr_status & GR_READY)))
60927+ return 0;
60928+
60929+ newacl = chk_subj_label(dentry, mnt, task->role);
60930+
60931+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
60932+ did an exec
60933+ */
60934+ rcu_read_lock();
60935+ read_lock(&tasklist_lock);
60936+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
60937+ (task->parent->acl->mode & GR_POVERRIDE))) {
60938+ read_unlock(&tasklist_lock);
60939+ rcu_read_unlock();
60940+ goto skip_check;
60941+ }
60942+ read_unlock(&tasklist_lock);
60943+ rcu_read_unlock();
60944+
60945+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
60946+ !(task->role->roletype & GR_ROLE_GOD) &&
60947+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
60948+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60949+ if (unsafe_flags & LSM_UNSAFE_SHARE)
60950+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
60951+ else
60952+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
60953+ return -EACCES;
60954+ }
60955+
60956+skip_check:
60957+
60958+ obj = chk_obj_label(dentry, mnt, task->acl);
60959+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
60960+
60961+ if (!(task->acl->mode & GR_INHERITLEARN) &&
60962+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
60963+ if (obj->nested)
60964+ task->acl = obj->nested;
60965+ else
60966+ task->acl = newacl;
60967+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
60968+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
60969+
60970+ task->is_writable = 0;
60971+
60972+ /* ignore additional mmap checks for processes that are writable
60973+ by the default ACL */
60974+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
60975+ if (unlikely(obj->mode & GR_WRITE))
60976+ task->is_writable = 1;
60977+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
60978+ if (unlikely(obj->mode & GR_WRITE))
60979+ task->is_writable = 1;
60980+
60981+ gr_set_proc_res(task);
60982+
60983+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60984+ 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);
60985+#endif
60986+ return 0;
60987+}
60988+
60989+/* always called with valid inodev ptr */
60990+static void
60991+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
60992+{
60993+ struct acl_object_label *matchpo;
60994+ struct acl_subject_label *matchps;
60995+ struct acl_subject_label *subj;
60996+ struct acl_role_label *role;
60997+ unsigned int x;
60998+
60999+ FOR_EACH_ROLE_START(role)
61000+ FOR_EACH_SUBJECT_START(role, subj, x)
61001+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
61002+ matchpo->mode |= GR_DELETED;
61003+ FOR_EACH_SUBJECT_END(subj,x)
61004+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61005+ /* nested subjects aren't in the role's subj_hash table */
61006+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
61007+ matchpo->mode |= GR_DELETED;
61008+ FOR_EACH_NESTED_SUBJECT_END(subj)
61009+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
61010+ matchps->mode |= GR_DELETED;
61011+ FOR_EACH_ROLE_END(role)
61012+
61013+ inodev->nentry->deleted = 1;
61014+
61015+ return;
61016+}
61017+
61018+void
61019+gr_handle_delete(const ino_t ino, const dev_t dev)
61020+{
61021+ struct inodev_entry *inodev;
61022+
61023+ if (unlikely(!(gr_status & GR_READY)))
61024+ return;
61025+
61026+ write_lock(&gr_inode_lock);
61027+ inodev = lookup_inodev_entry(ino, dev);
61028+ if (inodev != NULL)
61029+ do_handle_delete(inodev, ino, dev);
61030+ write_unlock(&gr_inode_lock);
61031+
61032+ return;
61033+}
61034+
61035+static void
61036+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
61037+ const ino_t newinode, const dev_t newdevice,
61038+ struct acl_subject_label *subj)
61039+{
61040+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
61041+ struct acl_object_label *match;
61042+
61043+ match = subj->obj_hash[index];
61044+
61045+ while (match && (match->inode != oldinode ||
61046+ match->device != olddevice ||
61047+ !(match->mode & GR_DELETED)))
61048+ match = match->next;
61049+
61050+ if (match && (match->inode == oldinode)
61051+ && (match->device == olddevice)
61052+ && (match->mode & GR_DELETED)) {
61053+ if (match->prev == NULL) {
61054+ subj->obj_hash[index] = match->next;
61055+ if (match->next != NULL)
61056+ match->next->prev = NULL;
61057+ } else {
61058+ match->prev->next = match->next;
61059+ if (match->next != NULL)
61060+ match->next->prev = match->prev;
61061+ }
61062+ match->prev = NULL;
61063+ match->next = NULL;
61064+ match->inode = newinode;
61065+ match->device = newdevice;
61066+ match->mode &= ~GR_DELETED;
61067+
61068+ insert_acl_obj_label(match, subj);
61069+ }
61070+
61071+ return;
61072+}
61073+
61074+static void
61075+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
61076+ const ino_t newinode, const dev_t newdevice,
61077+ struct acl_role_label *role)
61078+{
61079+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
61080+ struct acl_subject_label *match;
61081+
61082+ match = role->subj_hash[index];
61083+
61084+ while (match && (match->inode != oldinode ||
61085+ match->device != olddevice ||
61086+ !(match->mode & GR_DELETED)))
61087+ match = match->next;
61088+
61089+ if (match && (match->inode == oldinode)
61090+ && (match->device == olddevice)
61091+ && (match->mode & GR_DELETED)) {
61092+ if (match->prev == NULL) {
61093+ role->subj_hash[index] = match->next;
61094+ if (match->next != NULL)
61095+ match->next->prev = NULL;
61096+ } else {
61097+ match->prev->next = match->next;
61098+ if (match->next != NULL)
61099+ match->next->prev = match->prev;
61100+ }
61101+ match->prev = NULL;
61102+ match->next = NULL;
61103+ match->inode = newinode;
61104+ match->device = newdevice;
61105+ match->mode &= ~GR_DELETED;
61106+
61107+ insert_acl_subj_label(match, role);
61108+ }
61109+
61110+ return;
61111+}
61112+
61113+static void
61114+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
61115+ const ino_t newinode, const dev_t newdevice)
61116+{
61117+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
61118+ struct inodev_entry *match;
61119+
61120+ match = inodev_set.i_hash[index];
61121+
61122+ while (match && (match->nentry->inode != oldinode ||
61123+ match->nentry->device != olddevice || !match->nentry->deleted))
61124+ match = match->next;
61125+
61126+ if (match && (match->nentry->inode == oldinode)
61127+ && (match->nentry->device == olddevice) &&
61128+ match->nentry->deleted) {
61129+ if (match->prev == NULL) {
61130+ inodev_set.i_hash[index] = match->next;
61131+ if (match->next != NULL)
61132+ match->next->prev = NULL;
61133+ } else {
61134+ match->prev->next = match->next;
61135+ if (match->next != NULL)
61136+ match->next->prev = match->prev;
61137+ }
61138+ match->prev = NULL;
61139+ match->next = NULL;
61140+ match->nentry->inode = newinode;
61141+ match->nentry->device = newdevice;
61142+ match->nentry->deleted = 0;
61143+
61144+ insert_inodev_entry(match);
61145+ }
61146+
61147+ return;
61148+}
61149+
61150+static void
61151+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
61152+{
61153+ struct acl_subject_label *subj;
61154+ struct acl_role_label *role;
61155+ unsigned int x;
61156+
61157+ FOR_EACH_ROLE_START(role)
61158+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
61159+
61160+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61161+ if ((subj->inode == ino) && (subj->device == dev)) {
61162+ subj->inode = ino;
61163+ subj->device = dev;
61164+ }
61165+ /* nested subjects aren't in the role's subj_hash table */
61166+ update_acl_obj_label(matchn->inode, matchn->device,
61167+ ino, dev, subj);
61168+ FOR_EACH_NESTED_SUBJECT_END(subj)
61169+ FOR_EACH_SUBJECT_START(role, subj, x)
61170+ update_acl_obj_label(matchn->inode, matchn->device,
61171+ ino, dev, subj);
61172+ FOR_EACH_SUBJECT_END(subj,x)
61173+ FOR_EACH_ROLE_END(role)
61174+
61175+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
61176+
61177+ return;
61178+}
61179+
61180+static void
61181+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
61182+ const struct vfsmount *mnt)
61183+{
61184+ ino_t ino = dentry->d_inode->i_ino;
61185+ dev_t dev = __get_dev(dentry);
61186+
61187+ __do_handle_create(matchn, ino, dev);
61188+
61189+ return;
61190+}
61191+
61192+void
61193+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61194+{
61195+ struct name_entry *matchn;
61196+
61197+ if (unlikely(!(gr_status & GR_READY)))
61198+ return;
61199+
61200+ preempt_disable();
61201+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
61202+
61203+ if (unlikely((unsigned long)matchn)) {
61204+ write_lock(&gr_inode_lock);
61205+ do_handle_create(matchn, dentry, mnt);
61206+ write_unlock(&gr_inode_lock);
61207+ }
61208+ preempt_enable();
61209+
61210+ return;
61211+}
61212+
61213+void
61214+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61215+{
61216+ struct name_entry *matchn;
61217+
61218+ if (unlikely(!(gr_status & GR_READY)))
61219+ return;
61220+
61221+ preempt_disable();
61222+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
61223+
61224+ if (unlikely((unsigned long)matchn)) {
61225+ write_lock(&gr_inode_lock);
61226+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
61227+ write_unlock(&gr_inode_lock);
61228+ }
61229+ preempt_enable();
61230+
61231+ return;
61232+}
61233+
61234+void
61235+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61236+ struct dentry *old_dentry,
61237+ struct dentry *new_dentry,
61238+ struct vfsmount *mnt, const __u8 replace)
61239+{
61240+ struct name_entry *matchn;
61241+ struct inodev_entry *inodev;
61242+ struct inode *inode = new_dentry->d_inode;
61243+ ino_t old_ino = old_dentry->d_inode->i_ino;
61244+ dev_t old_dev = __get_dev(old_dentry);
61245+
61246+ /* vfs_rename swaps the name and parent link for old_dentry and
61247+ new_dentry
61248+ at this point, old_dentry has the new name, parent link, and inode
61249+ for the renamed file
61250+ if a file is being replaced by a rename, new_dentry has the inode
61251+ and name for the replaced file
61252+ */
61253+
61254+ if (unlikely(!(gr_status & GR_READY)))
61255+ return;
61256+
61257+ preempt_disable();
61258+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
61259+
61260+ /* we wouldn't have to check d_inode if it weren't for
61261+ NFS silly-renaming
61262+ */
61263+
61264+ write_lock(&gr_inode_lock);
61265+ if (unlikely(replace && inode)) {
61266+ ino_t new_ino = inode->i_ino;
61267+ dev_t new_dev = __get_dev(new_dentry);
61268+
61269+ inodev = lookup_inodev_entry(new_ino, new_dev);
61270+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
61271+ do_handle_delete(inodev, new_ino, new_dev);
61272+ }
61273+
61274+ inodev = lookup_inodev_entry(old_ino, old_dev);
61275+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
61276+ do_handle_delete(inodev, old_ino, old_dev);
61277+
61278+ if (unlikely((unsigned long)matchn))
61279+ do_handle_create(matchn, old_dentry, mnt);
61280+
61281+ write_unlock(&gr_inode_lock);
61282+ preempt_enable();
61283+
61284+ return;
61285+}
61286+
61287+static int
61288+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
61289+ unsigned char **sum)
61290+{
61291+ struct acl_role_label *r;
61292+ struct role_allowed_ip *ipp;
61293+ struct role_transition *trans;
61294+ unsigned int i;
61295+ int found = 0;
61296+ u32 curr_ip = current->signal->curr_ip;
61297+
61298+ current->signal->saved_ip = curr_ip;
61299+
61300+ /* check transition table */
61301+
61302+ for (trans = current->role->transitions; trans; trans = trans->next) {
61303+ if (!strcmp(rolename, trans->rolename)) {
61304+ found = 1;
61305+ break;
61306+ }
61307+ }
61308+
61309+ if (!found)
61310+ return 0;
61311+
61312+ /* handle special roles that do not require authentication
61313+ and check ip */
61314+
61315+ FOR_EACH_ROLE_START(r)
61316+ if (!strcmp(rolename, r->rolename) &&
61317+ (r->roletype & GR_ROLE_SPECIAL)) {
61318+ found = 0;
61319+ if (r->allowed_ips != NULL) {
61320+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
61321+ if ((ntohl(curr_ip) & ipp->netmask) ==
61322+ (ntohl(ipp->addr) & ipp->netmask))
61323+ found = 1;
61324+ }
61325+ } else
61326+ found = 2;
61327+ if (!found)
61328+ return 0;
61329+
61330+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
61331+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
61332+ *salt = NULL;
61333+ *sum = NULL;
61334+ return 1;
61335+ }
61336+ }
61337+ FOR_EACH_ROLE_END(r)
61338+
61339+ for (i = 0; i < num_sprole_pws; i++) {
61340+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
61341+ *salt = acl_special_roles[i]->salt;
61342+ *sum = acl_special_roles[i]->sum;
61343+ return 1;
61344+ }
61345+ }
61346+
61347+ return 0;
61348+}
61349+
61350+static void
61351+assign_special_role(char *rolename)
61352+{
61353+ struct acl_object_label *obj;
61354+ struct acl_role_label *r;
61355+ struct acl_role_label *assigned = NULL;
61356+ struct task_struct *tsk;
61357+ struct file *filp;
61358+
61359+ FOR_EACH_ROLE_START(r)
61360+ if (!strcmp(rolename, r->rolename) &&
61361+ (r->roletype & GR_ROLE_SPECIAL)) {
61362+ assigned = r;
61363+ break;
61364+ }
61365+ FOR_EACH_ROLE_END(r)
61366+
61367+ if (!assigned)
61368+ return;
61369+
61370+ read_lock(&tasklist_lock);
61371+ read_lock(&grsec_exec_file_lock);
61372+
61373+ tsk = current->real_parent;
61374+ if (tsk == NULL)
61375+ goto out_unlock;
61376+
61377+ filp = tsk->exec_file;
61378+ if (filp == NULL)
61379+ goto out_unlock;
61380+
61381+ tsk->is_writable = 0;
61382+
61383+ tsk->acl_sp_role = 1;
61384+ tsk->acl_role_id = ++acl_sp_role_value;
61385+ tsk->role = assigned;
61386+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
61387+
61388+ /* ignore additional mmap checks for processes that are writable
61389+ by the default ACL */
61390+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61391+ if (unlikely(obj->mode & GR_WRITE))
61392+ tsk->is_writable = 1;
61393+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
61394+ if (unlikely(obj->mode & GR_WRITE))
61395+ tsk->is_writable = 1;
61396+
61397+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61398+ 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));
61399+#endif
61400+
61401+out_unlock:
61402+ read_unlock(&grsec_exec_file_lock);
61403+ read_unlock(&tasklist_lock);
61404+ return;
61405+}
61406+
61407+int gr_check_secure_terminal(struct task_struct *task)
61408+{
61409+ struct task_struct *p, *p2, *p3;
61410+ struct files_struct *files;
61411+ struct fdtable *fdt;
61412+ struct file *our_file = NULL, *file;
61413+ int i;
61414+
61415+ if (task->signal->tty == NULL)
61416+ return 1;
61417+
61418+ files = get_files_struct(task);
61419+ if (files != NULL) {
61420+ rcu_read_lock();
61421+ fdt = files_fdtable(files);
61422+ for (i=0; i < fdt->max_fds; i++) {
61423+ file = fcheck_files(files, i);
61424+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
61425+ get_file(file);
61426+ our_file = file;
61427+ }
61428+ }
61429+ rcu_read_unlock();
61430+ put_files_struct(files);
61431+ }
61432+
61433+ if (our_file == NULL)
61434+ return 1;
61435+
61436+ read_lock(&tasklist_lock);
61437+ do_each_thread(p2, p) {
61438+ files = get_files_struct(p);
61439+ if (files == NULL ||
61440+ (p->signal && p->signal->tty == task->signal->tty)) {
61441+ if (files != NULL)
61442+ put_files_struct(files);
61443+ continue;
61444+ }
61445+ rcu_read_lock();
61446+ fdt = files_fdtable(files);
61447+ for (i=0; i < fdt->max_fds; i++) {
61448+ file = fcheck_files(files, i);
61449+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
61450+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
61451+ p3 = task;
61452+ while (task_pid_nr(p3) > 0) {
61453+ if (p3 == p)
61454+ break;
61455+ p3 = p3->real_parent;
61456+ }
61457+ if (p3 == p)
61458+ break;
61459+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
61460+ gr_handle_alertkill(p);
61461+ rcu_read_unlock();
61462+ put_files_struct(files);
61463+ read_unlock(&tasklist_lock);
61464+ fput(our_file);
61465+ return 0;
61466+ }
61467+ }
61468+ rcu_read_unlock();
61469+ put_files_struct(files);
61470+ } while_each_thread(p2, p);
61471+ read_unlock(&tasklist_lock);
61472+
61473+ fput(our_file);
61474+ return 1;
61475+}
61476+
61477+static int gr_rbac_disable(void *unused)
61478+{
61479+ pax_open_kernel();
61480+ gr_status &= ~GR_READY;
61481+ pax_close_kernel();
61482+
61483+ return 0;
61484+}
61485+
61486+ssize_t
61487+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
61488+{
61489+ struct gr_arg_wrapper uwrap;
61490+ unsigned char *sprole_salt = NULL;
61491+ unsigned char *sprole_sum = NULL;
61492+ int error = sizeof (struct gr_arg_wrapper);
61493+ int error2 = 0;
61494+
61495+ mutex_lock(&gr_dev_mutex);
61496+
61497+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
61498+ error = -EPERM;
61499+ goto out;
61500+ }
61501+
61502+ if (count != sizeof (struct gr_arg_wrapper)) {
61503+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
61504+ error = -EINVAL;
61505+ goto out;
61506+ }
61507+
61508+
61509+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
61510+ gr_auth_expires = 0;
61511+ gr_auth_attempts = 0;
61512+ }
61513+
61514+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
61515+ error = -EFAULT;
61516+ goto out;
61517+ }
61518+
61519+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
61520+ error = -EINVAL;
61521+ goto out;
61522+ }
61523+
61524+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
61525+ error = -EFAULT;
61526+ goto out;
61527+ }
61528+
61529+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61530+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61531+ time_after(gr_auth_expires, get_seconds())) {
61532+ error = -EBUSY;
61533+ goto out;
61534+ }
61535+
61536+ /* if non-root trying to do anything other than use a special role,
61537+ do not attempt authentication, do not count towards authentication
61538+ locking
61539+ */
61540+
61541+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
61542+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61543+ gr_is_global_nonroot(current_uid())) {
61544+ error = -EPERM;
61545+ goto out;
61546+ }
61547+
61548+ /* ensure pw and special role name are null terminated */
61549+
61550+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
61551+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
61552+
61553+ /* Okay.
61554+ * We have our enough of the argument structure..(we have yet
61555+ * to copy_from_user the tables themselves) . Copy the tables
61556+ * only if we need them, i.e. for loading operations. */
61557+
61558+ switch (gr_usermode->mode) {
61559+ case GR_STATUS:
61560+ if (gr_status & GR_READY) {
61561+ error = 1;
61562+ if (!gr_check_secure_terminal(current))
61563+ error = 3;
61564+ } else
61565+ error = 2;
61566+ goto out;
61567+ case GR_SHUTDOWN:
61568+ if ((gr_status & GR_READY)
61569+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61570+ stop_machine(gr_rbac_disable, NULL, NULL);
61571+ free_variables();
61572+ memset(gr_usermode, 0, sizeof (struct gr_arg));
61573+ memset(gr_system_salt, 0, GR_SALT_LEN);
61574+ memset(gr_system_sum, 0, GR_SHA_LEN);
61575+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
61576+ } else if (gr_status & GR_READY) {
61577+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
61578+ error = -EPERM;
61579+ } else {
61580+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
61581+ error = -EAGAIN;
61582+ }
61583+ break;
61584+ case GR_ENABLE:
61585+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
61586+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
61587+ else {
61588+ if (gr_status & GR_READY)
61589+ error = -EAGAIN;
61590+ else
61591+ error = error2;
61592+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
61593+ }
61594+ break;
61595+ case GR_RELOAD:
61596+ if (!(gr_status & GR_READY)) {
61597+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
61598+ error = -EAGAIN;
61599+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61600+ stop_machine(gr_rbac_disable, NULL, NULL);
61601+ free_variables();
61602+ error2 = gracl_init(gr_usermode);
61603+ if (!error2)
61604+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
61605+ else {
61606+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61607+ error = error2;
61608+ }
61609+ } else {
61610+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61611+ error = -EPERM;
61612+ }
61613+ break;
61614+ case GR_SEGVMOD:
61615+ if (unlikely(!(gr_status & GR_READY))) {
61616+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
61617+ error = -EAGAIN;
61618+ break;
61619+ }
61620+
61621+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61622+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
61623+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
61624+ struct acl_subject_label *segvacl;
61625+ segvacl =
61626+ lookup_acl_subj_label(gr_usermode->segv_inode,
61627+ gr_usermode->segv_device,
61628+ current->role);
61629+ if (segvacl) {
61630+ segvacl->crashes = 0;
61631+ segvacl->expires = 0;
61632+ }
61633+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
61634+ gr_remove_uid(gr_usermode->segv_uid);
61635+ }
61636+ } else {
61637+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
61638+ error = -EPERM;
61639+ }
61640+ break;
61641+ case GR_SPROLE:
61642+ case GR_SPROLEPAM:
61643+ if (unlikely(!(gr_status & GR_READY))) {
61644+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
61645+ error = -EAGAIN;
61646+ break;
61647+ }
61648+
61649+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
61650+ current->role->expires = 0;
61651+ current->role->auth_attempts = 0;
61652+ }
61653+
61654+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61655+ time_after(current->role->expires, get_seconds())) {
61656+ error = -EBUSY;
61657+ goto out;
61658+ }
61659+
61660+ if (lookup_special_role_auth
61661+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
61662+ && ((!sprole_salt && !sprole_sum)
61663+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
61664+ char *p = "";
61665+ assign_special_role(gr_usermode->sp_role);
61666+ read_lock(&tasklist_lock);
61667+ if (current->real_parent)
61668+ p = current->real_parent->role->rolename;
61669+ read_unlock(&tasklist_lock);
61670+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
61671+ p, acl_sp_role_value);
61672+ } else {
61673+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
61674+ error = -EPERM;
61675+ if(!(current->role->auth_attempts++))
61676+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61677+
61678+ goto out;
61679+ }
61680+ break;
61681+ case GR_UNSPROLE:
61682+ if (unlikely(!(gr_status & GR_READY))) {
61683+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
61684+ error = -EAGAIN;
61685+ break;
61686+ }
61687+
61688+ if (current->role->roletype & GR_ROLE_SPECIAL) {
61689+ char *p = "";
61690+ int i = 0;
61691+
61692+ read_lock(&tasklist_lock);
61693+ if (current->real_parent) {
61694+ p = current->real_parent->role->rolename;
61695+ i = current->real_parent->acl_role_id;
61696+ }
61697+ read_unlock(&tasklist_lock);
61698+
61699+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
61700+ gr_set_acls(1);
61701+ } else {
61702+ error = -EPERM;
61703+ goto out;
61704+ }
61705+ break;
61706+ default:
61707+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
61708+ error = -EINVAL;
61709+ break;
61710+ }
61711+
61712+ if (error != -EPERM)
61713+ goto out;
61714+
61715+ if(!(gr_auth_attempts++))
61716+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61717+
61718+ out:
61719+ mutex_unlock(&gr_dev_mutex);
61720+ return error;
61721+}
61722+
61723+/* must be called with
61724+ rcu_read_lock();
61725+ read_lock(&tasklist_lock);
61726+ read_lock(&grsec_exec_file_lock);
61727+*/
61728+int gr_apply_subject_to_task(struct task_struct *task)
61729+{
61730+ struct acl_object_label *obj;
61731+ char *tmpname;
61732+ struct acl_subject_label *tmpsubj;
61733+ struct file *filp;
61734+ struct name_entry *nmatch;
61735+
61736+ filp = task->exec_file;
61737+ if (filp == NULL)
61738+ return 0;
61739+
61740+ /* the following is to apply the correct subject
61741+ on binaries running when the RBAC system
61742+ is enabled, when the binaries have been
61743+ replaced or deleted since their execution
61744+ -----
61745+ when the RBAC system starts, the inode/dev
61746+ from exec_file will be one the RBAC system
61747+ is unaware of. It only knows the inode/dev
61748+ of the present file on disk, or the absence
61749+ of it.
61750+ */
61751+ preempt_disable();
61752+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
61753+
61754+ nmatch = lookup_name_entry(tmpname);
61755+ preempt_enable();
61756+ tmpsubj = NULL;
61757+ if (nmatch) {
61758+ if (nmatch->deleted)
61759+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
61760+ else
61761+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
61762+ if (tmpsubj != NULL)
61763+ task->acl = tmpsubj;
61764+ }
61765+ if (tmpsubj == NULL)
61766+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
61767+ task->role);
61768+ if (task->acl) {
61769+ task->is_writable = 0;
61770+ /* ignore additional mmap checks for processes that are writable
61771+ by the default ACL */
61772+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61773+ if (unlikely(obj->mode & GR_WRITE))
61774+ task->is_writable = 1;
61775+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61776+ if (unlikely(obj->mode & GR_WRITE))
61777+ task->is_writable = 1;
61778+
61779+ gr_set_proc_res(task);
61780+
61781+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61782+ 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);
61783+#endif
61784+ } else {
61785+ return 1;
61786+ }
61787+
61788+ return 0;
61789+}
61790+
61791+int
61792+gr_set_acls(const int type)
61793+{
61794+ struct task_struct *task, *task2;
61795+ struct acl_role_label *role = current->role;
61796+ __u16 acl_role_id = current->acl_role_id;
61797+ const struct cred *cred;
61798+ int ret;
61799+
61800+ rcu_read_lock();
61801+ read_lock(&tasklist_lock);
61802+ read_lock(&grsec_exec_file_lock);
61803+ do_each_thread(task2, task) {
61804+ /* check to see if we're called from the exit handler,
61805+ if so, only replace ACLs that have inherited the admin
61806+ ACL */
61807+
61808+ if (type && (task->role != role ||
61809+ task->acl_role_id != acl_role_id))
61810+ continue;
61811+
61812+ task->acl_role_id = 0;
61813+ task->acl_sp_role = 0;
61814+
61815+ if (task->exec_file) {
61816+ cred = __task_cred(task);
61817+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
61818+ ret = gr_apply_subject_to_task(task);
61819+ if (ret) {
61820+ read_unlock(&grsec_exec_file_lock);
61821+ read_unlock(&tasklist_lock);
61822+ rcu_read_unlock();
61823+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
61824+ return ret;
61825+ }
61826+ } else {
61827+ // it's a kernel process
61828+ task->role = kernel_role;
61829+ task->acl = kernel_role->root_label;
61830+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
61831+ task->acl->mode &= ~GR_PROCFIND;
61832+#endif
61833+ }
61834+ } while_each_thread(task2, task);
61835+ read_unlock(&grsec_exec_file_lock);
61836+ read_unlock(&tasklist_lock);
61837+ rcu_read_unlock();
61838+
61839+ return 0;
61840+}
61841+
61842+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
61843+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
61844+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
61845+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
61846+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
61847+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
61848+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
61849+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
61850+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
61851+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
61852+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
61853+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
61854+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
61855+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
61856+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
61857+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
61858+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
61859+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
61860+};
61861+
61862+void
61863+gr_learn_resource(const struct task_struct *task,
61864+ const int res, const unsigned long wanted, const int gt)
61865+{
61866+ struct acl_subject_label *acl;
61867+ const struct cred *cred;
61868+
61869+ if (unlikely((gr_status & GR_READY) &&
61870+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
61871+ goto skip_reslog;
61872+
61873+ gr_log_resource(task, res, wanted, gt);
61874+skip_reslog:
61875+
61876+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
61877+ return;
61878+
61879+ acl = task->acl;
61880+
61881+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
61882+ !(acl->resmask & (1U << (unsigned short) res))))
61883+ return;
61884+
61885+ if (wanted >= acl->res[res].rlim_cur) {
61886+ unsigned long res_add;
61887+
61888+ res_add = wanted + res_learn_bumps[res];
61889+
61890+ acl->res[res].rlim_cur = res_add;
61891+
61892+ if (wanted > acl->res[res].rlim_max)
61893+ acl->res[res].rlim_max = res_add;
61894+
61895+ /* only log the subject filename, since resource logging is supported for
61896+ single-subject learning only */
61897+ rcu_read_lock();
61898+ cred = __task_cred(task);
61899+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61900+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
61901+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
61902+ "", (unsigned long) res, &task->signal->saved_ip);
61903+ rcu_read_unlock();
61904+ }
61905+
61906+ return;
61907+}
61908+EXPORT_SYMBOL(gr_learn_resource);
61909+#endif
61910+
61911+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
61912+void
61913+pax_set_initial_flags(struct linux_binprm *bprm)
61914+{
61915+ struct task_struct *task = current;
61916+ struct acl_subject_label *proc;
61917+ unsigned long flags;
61918+
61919+ if (unlikely(!(gr_status & GR_READY)))
61920+ return;
61921+
61922+ flags = pax_get_flags(task);
61923+
61924+ proc = task->acl;
61925+
61926+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
61927+ flags &= ~MF_PAX_PAGEEXEC;
61928+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
61929+ flags &= ~MF_PAX_SEGMEXEC;
61930+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
61931+ flags &= ~MF_PAX_RANDMMAP;
61932+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
61933+ flags &= ~MF_PAX_EMUTRAMP;
61934+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
61935+ flags &= ~MF_PAX_MPROTECT;
61936+
61937+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
61938+ flags |= MF_PAX_PAGEEXEC;
61939+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
61940+ flags |= MF_PAX_SEGMEXEC;
61941+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
61942+ flags |= MF_PAX_RANDMMAP;
61943+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
61944+ flags |= MF_PAX_EMUTRAMP;
61945+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
61946+ flags |= MF_PAX_MPROTECT;
61947+
61948+ pax_set_flags(task, flags);
61949+
61950+ return;
61951+}
61952+#endif
61953+
61954+int
61955+gr_handle_proc_ptrace(struct task_struct *task)
61956+{
61957+ struct file *filp;
61958+ struct task_struct *tmp = task;
61959+ struct task_struct *curtemp = current;
61960+ __u32 retmode;
61961+
61962+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61963+ if (unlikely(!(gr_status & GR_READY)))
61964+ return 0;
61965+#endif
61966+
61967+ read_lock(&tasklist_lock);
61968+ read_lock(&grsec_exec_file_lock);
61969+ filp = task->exec_file;
61970+
61971+ while (task_pid_nr(tmp) > 0) {
61972+ if (tmp == curtemp)
61973+ break;
61974+ tmp = tmp->real_parent;
61975+ }
61976+
61977+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61978+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
61979+ read_unlock(&grsec_exec_file_lock);
61980+ read_unlock(&tasklist_lock);
61981+ return 1;
61982+ }
61983+
61984+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61985+ if (!(gr_status & GR_READY)) {
61986+ read_unlock(&grsec_exec_file_lock);
61987+ read_unlock(&tasklist_lock);
61988+ return 0;
61989+ }
61990+#endif
61991+
61992+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
61993+ read_unlock(&grsec_exec_file_lock);
61994+ read_unlock(&tasklist_lock);
61995+
61996+ if (retmode & GR_NOPTRACE)
61997+ return 1;
61998+
61999+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
62000+ && (current->acl != task->acl || (current->acl != current->role->root_label
62001+ && task_pid_nr(current) != task_pid_nr(task))))
62002+ return 1;
62003+
62004+ return 0;
62005+}
62006+
62007+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
62008+{
62009+ if (unlikely(!(gr_status & GR_READY)))
62010+ return;
62011+
62012+ if (!(current->role->roletype & GR_ROLE_GOD))
62013+ return;
62014+
62015+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
62016+ p->role->rolename, gr_task_roletype_to_char(p),
62017+ p->acl->filename);
62018+}
62019+
62020+int
62021+gr_handle_ptrace(struct task_struct *task, const long request)
62022+{
62023+ struct task_struct *tmp = task;
62024+ struct task_struct *curtemp = current;
62025+ __u32 retmode;
62026+
62027+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
62028+ if (unlikely(!(gr_status & GR_READY)))
62029+ return 0;
62030+#endif
62031+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
62032+ read_lock(&tasklist_lock);
62033+ while (task_pid_nr(tmp) > 0) {
62034+ if (tmp == curtemp)
62035+ break;
62036+ tmp = tmp->real_parent;
62037+ }
62038+
62039+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
62040+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
62041+ read_unlock(&tasklist_lock);
62042+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62043+ return 1;
62044+ }
62045+ read_unlock(&tasklist_lock);
62046+ }
62047+
62048+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62049+ if (!(gr_status & GR_READY))
62050+ return 0;
62051+#endif
62052+
62053+ read_lock(&grsec_exec_file_lock);
62054+ if (unlikely(!task->exec_file)) {
62055+ read_unlock(&grsec_exec_file_lock);
62056+ return 0;
62057+ }
62058+
62059+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
62060+ read_unlock(&grsec_exec_file_lock);
62061+
62062+ if (retmode & GR_NOPTRACE) {
62063+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62064+ return 1;
62065+ }
62066+
62067+ if (retmode & GR_PTRACERD) {
62068+ switch (request) {
62069+ case PTRACE_SEIZE:
62070+ case PTRACE_POKETEXT:
62071+ case PTRACE_POKEDATA:
62072+ case PTRACE_POKEUSR:
62073+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
62074+ case PTRACE_SETREGS:
62075+ case PTRACE_SETFPREGS:
62076+#endif
62077+#ifdef CONFIG_X86
62078+ case PTRACE_SETFPXREGS:
62079+#endif
62080+#ifdef CONFIG_ALTIVEC
62081+ case PTRACE_SETVRREGS:
62082+#endif
62083+ return 1;
62084+ default:
62085+ return 0;
62086+ }
62087+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
62088+ !(current->role->roletype & GR_ROLE_GOD) &&
62089+ (current->acl != task->acl)) {
62090+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62091+ return 1;
62092+ }
62093+
62094+ return 0;
62095+}
62096+
62097+static int is_writable_mmap(const struct file *filp)
62098+{
62099+ struct task_struct *task = current;
62100+ struct acl_object_label *obj, *obj2;
62101+
62102+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
62103+ !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))) {
62104+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
62105+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
62106+ task->role->root_label);
62107+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
62108+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
62109+ return 1;
62110+ }
62111+ }
62112+ return 0;
62113+}
62114+
62115+int
62116+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
62117+{
62118+ __u32 mode;
62119+
62120+ if (unlikely(!file || !(prot & PROT_EXEC)))
62121+ return 1;
62122+
62123+ if (is_writable_mmap(file))
62124+ return 0;
62125+
62126+ mode =
62127+ gr_search_file(file->f_path.dentry,
62128+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62129+ file->f_path.mnt);
62130+
62131+ if (!gr_tpe_allow(file))
62132+ return 0;
62133+
62134+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62135+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62136+ return 0;
62137+ } else if (unlikely(!(mode & GR_EXEC))) {
62138+ return 0;
62139+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62140+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62141+ return 1;
62142+ }
62143+
62144+ return 1;
62145+}
62146+
62147+int
62148+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62149+{
62150+ __u32 mode;
62151+
62152+ if (unlikely(!file || !(prot & PROT_EXEC)))
62153+ return 1;
62154+
62155+ if (is_writable_mmap(file))
62156+ return 0;
62157+
62158+ mode =
62159+ gr_search_file(file->f_path.dentry,
62160+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62161+ file->f_path.mnt);
62162+
62163+ if (!gr_tpe_allow(file))
62164+ return 0;
62165+
62166+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62167+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62168+ return 0;
62169+ } else if (unlikely(!(mode & GR_EXEC))) {
62170+ return 0;
62171+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62172+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62173+ return 1;
62174+ }
62175+
62176+ return 1;
62177+}
62178+
62179+void
62180+gr_acl_handle_psacct(struct task_struct *task, const long code)
62181+{
62182+ unsigned long runtime;
62183+ unsigned long cputime;
62184+ unsigned int wday, cday;
62185+ __u8 whr, chr;
62186+ __u8 wmin, cmin;
62187+ __u8 wsec, csec;
62188+ struct timespec timeval;
62189+
62190+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
62191+ !(task->acl->mode & GR_PROCACCT)))
62192+ return;
62193+
62194+ do_posix_clock_monotonic_gettime(&timeval);
62195+ runtime = timeval.tv_sec - task->start_time.tv_sec;
62196+ wday = runtime / (3600 * 24);
62197+ runtime -= wday * (3600 * 24);
62198+ whr = runtime / 3600;
62199+ runtime -= whr * 3600;
62200+ wmin = runtime / 60;
62201+ runtime -= wmin * 60;
62202+ wsec = runtime;
62203+
62204+ cputime = (task->utime + task->stime) / HZ;
62205+ cday = cputime / (3600 * 24);
62206+ cputime -= cday * (3600 * 24);
62207+ chr = cputime / 3600;
62208+ cputime -= chr * 3600;
62209+ cmin = cputime / 60;
62210+ cputime -= cmin * 60;
62211+ csec = cputime;
62212+
62213+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
62214+
62215+ return;
62216+}
62217+
62218+void gr_set_kernel_label(struct task_struct *task)
62219+{
62220+ if (gr_status & GR_READY) {
62221+ task->role = kernel_role;
62222+ task->acl = kernel_role->root_label;
62223+ }
62224+ return;
62225+}
62226+
62227+#ifdef CONFIG_TASKSTATS
62228+int gr_is_taskstats_denied(int pid)
62229+{
62230+ struct task_struct *task;
62231+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62232+ const struct cred *cred;
62233+#endif
62234+ int ret = 0;
62235+
62236+ /* restrict taskstats viewing to un-chrooted root users
62237+ who have the 'view' subject flag if the RBAC system is enabled
62238+ */
62239+
62240+ rcu_read_lock();
62241+ read_lock(&tasklist_lock);
62242+ task = find_task_by_vpid(pid);
62243+ if (task) {
62244+#ifdef CONFIG_GRKERNSEC_CHROOT
62245+ if (proc_is_chrooted(task))
62246+ ret = -EACCES;
62247+#endif
62248+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62249+ cred = __task_cred(task);
62250+#ifdef CONFIG_GRKERNSEC_PROC_USER
62251+ if (gr_is_global_nonroot(cred->uid))
62252+ ret = -EACCES;
62253+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62254+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
62255+ ret = -EACCES;
62256+#endif
62257+#endif
62258+ if (gr_status & GR_READY) {
62259+ if (!(task->acl->mode & GR_VIEW))
62260+ ret = -EACCES;
62261+ }
62262+ } else
62263+ ret = -ENOENT;
62264+
62265+ read_unlock(&tasklist_lock);
62266+ rcu_read_unlock();
62267+
62268+ return ret;
62269+}
62270+#endif
62271+
62272+/* AUXV entries are filled via a descendant of search_binary_handler
62273+ after we've already applied the subject for the target
62274+*/
62275+int gr_acl_enable_at_secure(void)
62276+{
62277+ if (unlikely(!(gr_status & GR_READY)))
62278+ return 0;
62279+
62280+ if (current->acl->mode & GR_ATSECURE)
62281+ return 1;
62282+
62283+ return 0;
62284+}
62285+
62286+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
62287+{
62288+ struct task_struct *task = current;
62289+ struct dentry *dentry = file->f_path.dentry;
62290+ struct vfsmount *mnt = file->f_path.mnt;
62291+ struct acl_object_label *obj, *tmp;
62292+ struct acl_subject_label *subj;
62293+ unsigned int bufsize;
62294+ int is_not_root;
62295+ char *path;
62296+ dev_t dev = __get_dev(dentry);
62297+
62298+ if (unlikely(!(gr_status & GR_READY)))
62299+ return 1;
62300+
62301+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
62302+ return 1;
62303+
62304+ /* ignore Eric Biederman */
62305+ if (IS_PRIVATE(dentry->d_inode))
62306+ return 1;
62307+
62308+ subj = task->acl;
62309+ read_lock(&gr_inode_lock);
62310+ do {
62311+ obj = lookup_acl_obj_label(ino, dev, subj);
62312+ if (obj != NULL) {
62313+ read_unlock(&gr_inode_lock);
62314+ return (obj->mode & GR_FIND) ? 1 : 0;
62315+ }
62316+ } while ((subj = subj->parent_subject));
62317+ read_unlock(&gr_inode_lock);
62318+
62319+ /* this is purely an optimization since we're looking for an object
62320+ for the directory we're doing a readdir on
62321+ if it's possible for any globbed object to match the entry we're
62322+ filling into the directory, then the object we find here will be
62323+ an anchor point with attached globbed objects
62324+ */
62325+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
62326+ if (obj->globbed == NULL)
62327+ return (obj->mode & GR_FIND) ? 1 : 0;
62328+
62329+ is_not_root = ((obj->filename[0] == '/') &&
62330+ (obj->filename[1] == '\0')) ? 0 : 1;
62331+ bufsize = PAGE_SIZE - namelen - is_not_root;
62332+
62333+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
62334+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
62335+ return 1;
62336+
62337+ preempt_disable();
62338+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62339+ bufsize);
62340+
62341+ bufsize = strlen(path);
62342+
62343+ /* if base is "/", don't append an additional slash */
62344+ if (is_not_root)
62345+ *(path + bufsize) = '/';
62346+ memcpy(path + bufsize + is_not_root, name, namelen);
62347+ *(path + bufsize + namelen + is_not_root) = '\0';
62348+
62349+ tmp = obj->globbed;
62350+ while (tmp) {
62351+ if (!glob_match(tmp->filename, path)) {
62352+ preempt_enable();
62353+ return (tmp->mode & GR_FIND) ? 1 : 0;
62354+ }
62355+ tmp = tmp->next;
62356+ }
62357+ preempt_enable();
62358+ return (obj->mode & GR_FIND) ? 1 : 0;
62359+}
62360+
62361+void gr_put_exec_file(struct task_struct *task)
62362+{
62363+ struct file *filp;
62364+
62365+ write_lock(&grsec_exec_file_lock);
62366+ filp = task->exec_file;
62367+ task->exec_file = NULL;
62368+ write_unlock(&grsec_exec_file_lock);
62369+
62370+ if (filp)
62371+ fput(filp);
62372+
62373+ return;
62374+}
62375+
62376+
62377+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
62378+EXPORT_SYMBOL(gr_acl_is_enabled);
62379+#endif
62380+EXPORT_SYMBOL(gr_set_kernel_label);
62381+#ifdef CONFIG_SECURITY
62382+EXPORT_SYMBOL(gr_check_user_change);
62383+EXPORT_SYMBOL(gr_check_group_change);
62384+#endif
62385+
62386diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
62387new file mode 100644
62388index 0000000..34fefda
62389--- /dev/null
62390+++ b/grsecurity/gracl_alloc.c
62391@@ -0,0 +1,105 @@
62392+#include <linux/kernel.h>
62393+#include <linux/mm.h>
62394+#include <linux/slab.h>
62395+#include <linux/vmalloc.h>
62396+#include <linux/gracl.h>
62397+#include <linux/grsecurity.h>
62398+
62399+static unsigned long alloc_stack_next = 1;
62400+static unsigned long alloc_stack_size = 1;
62401+static void **alloc_stack;
62402+
62403+static __inline__ int
62404+alloc_pop(void)
62405+{
62406+ if (alloc_stack_next == 1)
62407+ return 0;
62408+
62409+ kfree(alloc_stack[alloc_stack_next - 2]);
62410+
62411+ alloc_stack_next--;
62412+
62413+ return 1;
62414+}
62415+
62416+static __inline__ int
62417+alloc_push(void *buf)
62418+{
62419+ if (alloc_stack_next >= alloc_stack_size)
62420+ return 1;
62421+
62422+ alloc_stack[alloc_stack_next - 1] = buf;
62423+
62424+ alloc_stack_next++;
62425+
62426+ return 0;
62427+}
62428+
62429+void *
62430+acl_alloc(unsigned long len)
62431+{
62432+ void *ret = NULL;
62433+
62434+ if (!len || len > PAGE_SIZE)
62435+ goto out;
62436+
62437+ ret = kmalloc(len, GFP_KERNEL);
62438+
62439+ if (ret) {
62440+ if (alloc_push(ret)) {
62441+ kfree(ret);
62442+ ret = NULL;
62443+ }
62444+ }
62445+
62446+out:
62447+ return ret;
62448+}
62449+
62450+void *
62451+acl_alloc_num(unsigned long num, unsigned long len)
62452+{
62453+ if (!len || (num > (PAGE_SIZE / len)))
62454+ return NULL;
62455+
62456+ return acl_alloc(num * len);
62457+}
62458+
62459+void
62460+acl_free_all(void)
62461+{
62462+ if (gr_acl_is_enabled() || !alloc_stack)
62463+ return;
62464+
62465+ while (alloc_pop()) ;
62466+
62467+ if (alloc_stack) {
62468+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
62469+ kfree(alloc_stack);
62470+ else
62471+ vfree(alloc_stack);
62472+ }
62473+
62474+ alloc_stack = NULL;
62475+ alloc_stack_size = 1;
62476+ alloc_stack_next = 1;
62477+
62478+ return;
62479+}
62480+
62481+int
62482+acl_alloc_stack_init(unsigned long size)
62483+{
62484+ if ((size * sizeof (void *)) <= PAGE_SIZE)
62485+ alloc_stack =
62486+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
62487+ else
62488+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
62489+
62490+ alloc_stack_size = size;
62491+
62492+ if (!alloc_stack)
62493+ return 0;
62494+ else
62495+ return 1;
62496+}
62497diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
62498new file mode 100644
62499index 0000000..bdd51ea
62500--- /dev/null
62501+++ b/grsecurity/gracl_cap.c
62502@@ -0,0 +1,110 @@
62503+#include <linux/kernel.h>
62504+#include <linux/module.h>
62505+#include <linux/sched.h>
62506+#include <linux/gracl.h>
62507+#include <linux/grsecurity.h>
62508+#include <linux/grinternal.h>
62509+
62510+extern const char *captab_log[];
62511+extern int captab_log_entries;
62512+
62513+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62514+{
62515+ struct acl_subject_label *curracl;
62516+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62517+ kernel_cap_t cap_audit = __cap_empty_set;
62518+
62519+ if (!gr_acl_is_enabled())
62520+ return 1;
62521+
62522+ curracl = task->acl;
62523+
62524+ cap_drop = curracl->cap_lower;
62525+ cap_mask = curracl->cap_mask;
62526+ cap_audit = curracl->cap_invert_audit;
62527+
62528+ while ((curracl = curracl->parent_subject)) {
62529+ /* if the cap isn't specified in the current computed mask but is specified in the
62530+ current level subject, and is lowered in the current level subject, then add
62531+ it to the set of dropped capabilities
62532+ otherwise, add the current level subject's mask to the current computed mask
62533+ */
62534+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62535+ cap_raise(cap_mask, cap);
62536+ if (cap_raised(curracl->cap_lower, cap))
62537+ cap_raise(cap_drop, cap);
62538+ if (cap_raised(curracl->cap_invert_audit, cap))
62539+ cap_raise(cap_audit, cap);
62540+ }
62541+ }
62542+
62543+ if (!cap_raised(cap_drop, cap)) {
62544+ if (cap_raised(cap_audit, cap))
62545+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
62546+ return 1;
62547+ }
62548+
62549+ curracl = task->acl;
62550+
62551+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
62552+ && cap_raised(cred->cap_effective, cap)) {
62553+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62554+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
62555+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
62556+ gr_to_filename(task->exec_file->f_path.dentry,
62557+ task->exec_file->f_path.mnt) : curracl->filename,
62558+ curracl->filename, 0UL,
62559+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
62560+ return 1;
62561+ }
62562+
62563+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
62564+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
62565+
62566+ return 0;
62567+}
62568+
62569+int
62570+gr_acl_is_capable(const int cap)
62571+{
62572+ return gr_task_acl_is_capable(current, current_cred(), cap);
62573+}
62574+
62575+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
62576+{
62577+ struct acl_subject_label *curracl;
62578+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62579+
62580+ if (!gr_acl_is_enabled())
62581+ return 1;
62582+
62583+ curracl = task->acl;
62584+
62585+ cap_drop = curracl->cap_lower;
62586+ cap_mask = curracl->cap_mask;
62587+
62588+ while ((curracl = curracl->parent_subject)) {
62589+ /* if the cap isn't specified in the current computed mask but is specified in the
62590+ current level subject, and is lowered in the current level subject, then add
62591+ it to the set of dropped capabilities
62592+ otherwise, add the current level subject's mask to the current computed mask
62593+ */
62594+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62595+ cap_raise(cap_mask, cap);
62596+ if (cap_raised(curracl->cap_lower, cap))
62597+ cap_raise(cap_drop, cap);
62598+ }
62599+ }
62600+
62601+ if (!cap_raised(cap_drop, cap))
62602+ return 1;
62603+
62604+ return 0;
62605+}
62606+
62607+int
62608+gr_acl_is_capable_nolog(const int cap)
62609+{
62610+ return gr_task_acl_is_capable_nolog(current, cap);
62611+}
62612+
62613diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
62614new file mode 100644
62615index 0000000..a340c17
62616--- /dev/null
62617+++ b/grsecurity/gracl_fs.c
62618@@ -0,0 +1,431 @@
62619+#include <linux/kernel.h>
62620+#include <linux/sched.h>
62621+#include <linux/types.h>
62622+#include <linux/fs.h>
62623+#include <linux/file.h>
62624+#include <linux/stat.h>
62625+#include <linux/grsecurity.h>
62626+#include <linux/grinternal.h>
62627+#include <linux/gracl.h>
62628+
62629+umode_t
62630+gr_acl_umask(void)
62631+{
62632+ if (unlikely(!gr_acl_is_enabled()))
62633+ return 0;
62634+
62635+ return current->role->umask;
62636+}
62637+
62638+__u32
62639+gr_acl_handle_hidden_file(const struct dentry * dentry,
62640+ const struct vfsmount * mnt)
62641+{
62642+ __u32 mode;
62643+
62644+ if (unlikely(!dentry->d_inode))
62645+ return GR_FIND;
62646+
62647+ mode =
62648+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
62649+
62650+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
62651+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62652+ return mode;
62653+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
62654+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62655+ return 0;
62656+ } else if (unlikely(!(mode & GR_FIND)))
62657+ return 0;
62658+
62659+ return GR_FIND;
62660+}
62661+
62662+__u32
62663+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62664+ int acc_mode)
62665+{
62666+ __u32 reqmode = GR_FIND;
62667+ __u32 mode;
62668+
62669+ if (unlikely(!dentry->d_inode))
62670+ return reqmode;
62671+
62672+ if (acc_mode & MAY_APPEND)
62673+ reqmode |= GR_APPEND;
62674+ else if (acc_mode & MAY_WRITE)
62675+ reqmode |= GR_WRITE;
62676+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
62677+ reqmode |= GR_READ;
62678+
62679+ mode =
62680+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62681+ mnt);
62682+
62683+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62684+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62685+ reqmode & GR_READ ? " reading" : "",
62686+ reqmode & GR_WRITE ? " writing" : reqmode &
62687+ GR_APPEND ? " appending" : "");
62688+ return reqmode;
62689+ } else
62690+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62691+ {
62692+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62693+ reqmode & GR_READ ? " reading" : "",
62694+ reqmode & GR_WRITE ? " writing" : reqmode &
62695+ GR_APPEND ? " appending" : "");
62696+ return 0;
62697+ } else if (unlikely((mode & reqmode) != reqmode))
62698+ return 0;
62699+
62700+ return reqmode;
62701+}
62702+
62703+__u32
62704+gr_acl_handle_creat(const struct dentry * dentry,
62705+ const struct dentry * p_dentry,
62706+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
62707+ const int imode)
62708+{
62709+ __u32 reqmode = GR_WRITE | GR_CREATE;
62710+ __u32 mode;
62711+
62712+ if (acc_mode & MAY_APPEND)
62713+ reqmode |= GR_APPEND;
62714+ // if a directory was required or the directory already exists, then
62715+ // don't count this open as a read
62716+ if ((acc_mode & MAY_READ) &&
62717+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
62718+ reqmode |= GR_READ;
62719+ if ((open_flags & O_CREAT) &&
62720+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62721+ reqmode |= GR_SETID;
62722+
62723+ mode =
62724+ gr_check_create(dentry, p_dentry, p_mnt,
62725+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62726+
62727+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62728+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62729+ reqmode & GR_READ ? " reading" : "",
62730+ reqmode & GR_WRITE ? " writing" : reqmode &
62731+ GR_APPEND ? " appending" : "");
62732+ return reqmode;
62733+ } else
62734+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62735+ {
62736+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62737+ reqmode & GR_READ ? " reading" : "",
62738+ reqmode & GR_WRITE ? " writing" : reqmode &
62739+ GR_APPEND ? " appending" : "");
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_access(const struct dentry * dentry, const struct vfsmount * mnt,
62749+ const int fmode)
62750+{
62751+ __u32 mode, reqmode = GR_FIND;
62752+
62753+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
62754+ reqmode |= GR_EXEC;
62755+ if (fmode & S_IWOTH)
62756+ reqmode |= GR_WRITE;
62757+ if (fmode & S_IROTH)
62758+ reqmode |= GR_READ;
62759+
62760+ mode =
62761+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62762+ mnt);
62763+
62764+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62765+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62766+ reqmode & GR_READ ? " reading" : "",
62767+ reqmode & GR_WRITE ? " writing" : "",
62768+ reqmode & GR_EXEC ? " executing" : "");
62769+ return reqmode;
62770+ } else
62771+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62772+ {
62773+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62774+ reqmode & GR_READ ? " reading" : "",
62775+ reqmode & GR_WRITE ? " writing" : "",
62776+ reqmode & GR_EXEC ? " executing" : "");
62777+ return 0;
62778+ } else if (unlikely((mode & reqmode) != reqmode))
62779+ return 0;
62780+
62781+ return reqmode;
62782+}
62783+
62784+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
62785+{
62786+ __u32 mode;
62787+
62788+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
62789+
62790+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62791+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
62792+ return mode;
62793+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62794+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
62795+ return 0;
62796+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62797+ return 0;
62798+
62799+ return (reqmode);
62800+}
62801+
62802+__u32
62803+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62804+{
62805+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
62806+}
62807+
62808+__u32
62809+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
62810+{
62811+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
62812+}
62813+
62814+__u32
62815+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
62816+{
62817+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
62818+}
62819+
62820+__u32
62821+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
62822+{
62823+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
62824+}
62825+
62826+__u32
62827+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
62828+ umode_t *modeptr)
62829+{
62830+ umode_t mode;
62831+
62832+ *modeptr &= ~gr_acl_umask();
62833+ mode = *modeptr;
62834+
62835+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
62836+ return 1;
62837+
62838+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
62839+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
62840+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
62841+ GR_CHMOD_ACL_MSG);
62842+ } else {
62843+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
62844+ }
62845+}
62846+
62847+__u32
62848+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
62849+{
62850+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
62851+}
62852+
62853+__u32
62854+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
62855+{
62856+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
62857+}
62858+
62859+__u32
62860+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
62861+{
62862+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
62863+}
62864+
62865+__u32
62866+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
62867+{
62868+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
62869+ GR_UNIXCONNECT_ACL_MSG);
62870+}
62871+
62872+/* hardlinks require at minimum create and link permission,
62873+ any additional privilege required is based on the
62874+ privilege of the file being linked to
62875+*/
62876+__u32
62877+gr_acl_handle_link(const struct dentry * new_dentry,
62878+ const struct dentry * parent_dentry,
62879+ const struct vfsmount * parent_mnt,
62880+ const struct dentry * old_dentry,
62881+ const struct vfsmount * old_mnt, const struct filename *to)
62882+{
62883+ __u32 mode;
62884+ __u32 needmode = GR_CREATE | GR_LINK;
62885+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
62886+
62887+ mode =
62888+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
62889+ old_mnt);
62890+
62891+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
62892+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62893+ return mode;
62894+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62895+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62896+ return 0;
62897+ } else if (unlikely((mode & needmode) != needmode))
62898+ return 0;
62899+
62900+ return 1;
62901+}
62902+
62903+__u32
62904+gr_acl_handle_symlink(const struct dentry * new_dentry,
62905+ const struct dentry * parent_dentry,
62906+ const struct vfsmount * parent_mnt, const struct filename *from)
62907+{
62908+ __u32 needmode = GR_WRITE | GR_CREATE;
62909+ __u32 mode;
62910+
62911+ mode =
62912+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
62913+ GR_CREATE | GR_AUDIT_CREATE |
62914+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
62915+
62916+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
62917+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62918+ return mode;
62919+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62920+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62921+ return 0;
62922+ } else if (unlikely((mode & needmode) != needmode))
62923+ return 0;
62924+
62925+ return (GR_WRITE | GR_CREATE);
62926+}
62927+
62928+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)
62929+{
62930+ __u32 mode;
62931+
62932+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62933+
62934+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62935+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
62936+ return mode;
62937+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62938+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
62939+ return 0;
62940+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62941+ return 0;
62942+
62943+ return (reqmode);
62944+}
62945+
62946+__u32
62947+gr_acl_handle_mknod(const struct dentry * new_dentry,
62948+ const struct dentry * parent_dentry,
62949+ const struct vfsmount * parent_mnt,
62950+ const int mode)
62951+{
62952+ __u32 reqmode = GR_WRITE | GR_CREATE;
62953+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62954+ reqmode |= GR_SETID;
62955+
62956+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62957+ reqmode, GR_MKNOD_ACL_MSG);
62958+}
62959+
62960+__u32
62961+gr_acl_handle_mkdir(const struct dentry *new_dentry,
62962+ const struct dentry *parent_dentry,
62963+ const struct vfsmount *parent_mnt)
62964+{
62965+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62966+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
62967+}
62968+
62969+#define RENAME_CHECK_SUCCESS(old, new) \
62970+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
62971+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
62972+
62973+int
62974+gr_acl_handle_rename(struct dentry *new_dentry,
62975+ struct dentry *parent_dentry,
62976+ const struct vfsmount *parent_mnt,
62977+ struct dentry *old_dentry,
62978+ struct inode *old_parent_inode,
62979+ struct vfsmount *old_mnt, const struct filename *newname)
62980+{
62981+ __u32 comp1, comp2;
62982+ int error = 0;
62983+
62984+ if (unlikely(!gr_acl_is_enabled()))
62985+ return 0;
62986+
62987+ if (!new_dentry->d_inode) {
62988+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
62989+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
62990+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
62991+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
62992+ GR_DELETE | GR_AUDIT_DELETE |
62993+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62994+ GR_SUPPRESS, old_mnt);
62995+ } else {
62996+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
62997+ GR_CREATE | GR_DELETE |
62998+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
62999+ GR_AUDIT_READ | GR_AUDIT_WRITE |
63000+ GR_SUPPRESS, parent_mnt);
63001+ comp2 =
63002+ gr_search_file(old_dentry,
63003+ GR_READ | GR_WRITE | GR_AUDIT_READ |
63004+ GR_DELETE | GR_AUDIT_DELETE |
63005+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
63006+ }
63007+
63008+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
63009+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
63010+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
63011+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
63012+ && !(comp2 & GR_SUPPRESS)) {
63013+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
63014+ error = -EACCES;
63015+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
63016+ error = -EACCES;
63017+
63018+ return error;
63019+}
63020+
63021+void
63022+gr_acl_handle_exit(void)
63023+{
63024+ u16 id;
63025+ char *rolename;
63026+
63027+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
63028+ !(current->role->roletype & GR_ROLE_PERSIST))) {
63029+ id = current->acl_role_id;
63030+ rolename = current->role->rolename;
63031+ gr_set_acls(1);
63032+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
63033+ }
63034+
63035+ gr_put_exec_file(current);
63036+ return;
63037+}
63038+
63039+int
63040+gr_acl_handle_procpidmem(const struct task_struct *task)
63041+{
63042+ if (unlikely(!gr_acl_is_enabled()))
63043+ return 0;
63044+
63045+ if (task != current && task->acl->mode & GR_PROTPROCFD)
63046+ return -EACCES;
63047+
63048+ return 0;
63049+}
63050diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
63051new file mode 100644
63052index 0000000..8132048
63053--- /dev/null
63054+++ b/grsecurity/gracl_ip.c
63055@@ -0,0 +1,387 @@
63056+#include <linux/kernel.h>
63057+#include <asm/uaccess.h>
63058+#include <asm/errno.h>
63059+#include <net/sock.h>
63060+#include <linux/file.h>
63061+#include <linux/fs.h>
63062+#include <linux/net.h>
63063+#include <linux/in.h>
63064+#include <linux/skbuff.h>
63065+#include <linux/ip.h>
63066+#include <linux/udp.h>
63067+#include <linux/types.h>
63068+#include <linux/sched.h>
63069+#include <linux/netdevice.h>
63070+#include <linux/inetdevice.h>
63071+#include <linux/gracl.h>
63072+#include <linux/grsecurity.h>
63073+#include <linux/grinternal.h>
63074+
63075+#define GR_BIND 0x01
63076+#define GR_CONNECT 0x02
63077+#define GR_INVERT 0x04
63078+#define GR_BINDOVERRIDE 0x08
63079+#define GR_CONNECTOVERRIDE 0x10
63080+#define GR_SOCK_FAMILY 0x20
63081+
63082+static const char * gr_protocols[IPPROTO_MAX] = {
63083+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
63084+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
63085+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
63086+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
63087+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
63088+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
63089+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
63090+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
63091+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
63092+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
63093+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
63094+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
63095+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
63096+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
63097+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
63098+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
63099+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
63100+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
63101+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
63102+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
63103+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
63104+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
63105+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
63106+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
63107+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
63108+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
63109+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
63110+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
63111+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
63112+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
63113+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
63114+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
63115+ };
63116+
63117+static const char * gr_socktypes[SOCK_MAX] = {
63118+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
63119+ "unknown:7", "unknown:8", "unknown:9", "packet"
63120+ };
63121+
63122+static const char * gr_sockfamilies[AF_MAX+1] = {
63123+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
63124+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
63125+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
63126+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
63127+ };
63128+
63129+const char *
63130+gr_proto_to_name(unsigned char proto)
63131+{
63132+ return gr_protocols[proto];
63133+}
63134+
63135+const char *
63136+gr_socktype_to_name(unsigned char type)
63137+{
63138+ return gr_socktypes[type];
63139+}
63140+
63141+const char *
63142+gr_sockfamily_to_name(unsigned char family)
63143+{
63144+ return gr_sockfamilies[family];
63145+}
63146+
63147+int
63148+gr_search_socket(const int domain, const int type, const int protocol)
63149+{
63150+ struct acl_subject_label *curr;
63151+ const struct cred *cred = current_cred();
63152+
63153+ if (unlikely(!gr_acl_is_enabled()))
63154+ goto exit;
63155+
63156+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
63157+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
63158+ goto exit; // let the kernel handle it
63159+
63160+ curr = current->acl;
63161+
63162+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
63163+ /* the family is allowed, if this is PF_INET allow it only if
63164+ the extra sock type/protocol checks pass */
63165+ if (domain == PF_INET)
63166+ goto inet_check;
63167+ goto exit;
63168+ } else {
63169+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63170+ __u32 fakeip = 0;
63171+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63172+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63173+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63174+ gr_to_filename(current->exec_file->f_path.dentry,
63175+ current->exec_file->f_path.mnt) :
63176+ curr->filename, curr->filename,
63177+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
63178+ &current->signal->saved_ip);
63179+ goto exit;
63180+ }
63181+ goto exit_fail;
63182+ }
63183+
63184+inet_check:
63185+ /* the rest of this checking is for IPv4 only */
63186+ if (!curr->ips)
63187+ goto exit;
63188+
63189+ if ((curr->ip_type & (1U << type)) &&
63190+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
63191+ goto exit;
63192+
63193+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63194+ /* we don't place acls on raw sockets , and sometimes
63195+ dgram/ip sockets are opened for ioctl and not
63196+ bind/connect, so we'll fake a bind learn log */
63197+ if (type == SOCK_RAW || type == SOCK_PACKET) {
63198+ __u32 fakeip = 0;
63199+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63200+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63201+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63202+ gr_to_filename(current->exec_file->f_path.dentry,
63203+ current->exec_file->f_path.mnt) :
63204+ curr->filename, curr->filename,
63205+ &fakeip, 0, type,
63206+ protocol, GR_CONNECT, &current->signal->saved_ip);
63207+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
63208+ __u32 fakeip = 0;
63209+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63210+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63211+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63212+ gr_to_filename(current->exec_file->f_path.dentry,
63213+ current->exec_file->f_path.mnt) :
63214+ curr->filename, curr->filename,
63215+ &fakeip, 0, type,
63216+ protocol, GR_BIND, &current->signal->saved_ip);
63217+ }
63218+ /* we'll log when they use connect or bind */
63219+ goto exit;
63220+ }
63221+
63222+exit_fail:
63223+ if (domain == PF_INET)
63224+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
63225+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
63226+ else
63227+#ifndef CONFIG_IPV6
63228+ if (domain != PF_INET6)
63229+#endif
63230+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
63231+ gr_socktype_to_name(type), protocol);
63232+
63233+ return 0;
63234+exit:
63235+ return 1;
63236+}
63237+
63238+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)
63239+{
63240+ if ((ip->mode & mode) &&
63241+ (ip_port >= ip->low) &&
63242+ (ip_port <= ip->high) &&
63243+ ((ntohl(ip_addr) & our_netmask) ==
63244+ (ntohl(our_addr) & our_netmask))
63245+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
63246+ && (ip->type & (1U << type))) {
63247+ if (ip->mode & GR_INVERT)
63248+ return 2; // specifically denied
63249+ else
63250+ return 1; // allowed
63251+ }
63252+
63253+ return 0; // not specifically allowed, may continue parsing
63254+}
63255+
63256+static int
63257+gr_search_connectbind(const int full_mode, struct sock *sk,
63258+ struct sockaddr_in *addr, const int type)
63259+{
63260+ char iface[IFNAMSIZ] = {0};
63261+ struct acl_subject_label *curr;
63262+ struct acl_ip_label *ip;
63263+ struct inet_sock *isk;
63264+ struct net_device *dev;
63265+ struct in_device *idev;
63266+ unsigned long i;
63267+ int ret;
63268+ int mode = full_mode & (GR_BIND | GR_CONNECT);
63269+ __u32 ip_addr = 0;
63270+ __u32 our_addr;
63271+ __u32 our_netmask;
63272+ char *p;
63273+ __u16 ip_port = 0;
63274+ const struct cred *cred = current_cred();
63275+
63276+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
63277+ return 0;
63278+
63279+ curr = current->acl;
63280+ isk = inet_sk(sk);
63281+
63282+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
63283+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
63284+ addr->sin_addr.s_addr = curr->inaddr_any_override;
63285+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
63286+ struct sockaddr_in saddr;
63287+ int err;
63288+
63289+ saddr.sin_family = AF_INET;
63290+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
63291+ saddr.sin_port = isk->inet_sport;
63292+
63293+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63294+ if (err)
63295+ return err;
63296+
63297+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63298+ if (err)
63299+ return err;
63300+ }
63301+
63302+ if (!curr->ips)
63303+ return 0;
63304+
63305+ ip_addr = addr->sin_addr.s_addr;
63306+ ip_port = ntohs(addr->sin_port);
63307+
63308+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63309+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63310+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63311+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63312+ gr_to_filename(current->exec_file->f_path.dentry,
63313+ current->exec_file->f_path.mnt) :
63314+ curr->filename, curr->filename,
63315+ &ip_addr, ip_port, type,
63316+ sk->sk_protocol, mode, &current->signal->saved_ip);
63317+ return 0;
63318+ }
63319+
63320+ for (i = 0; i < curr->ip_num; i++) {
63321+ ip = *(curr->ips + i);
63322+ if (ip->iface != NULL) {
63323+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
63324+ p = strchr(iface, ':');
63325+ if (p != NULL)
63326+ *p = '\0';
63327+ dev = dev_get_by_name(sock_net(sk), iface);
63328+ if (dev == NULL)
63329+ continue;
63330+ idev = in_dev_get(dev);
63331+ if (idev == NULL) {
63332+ dev_put(dev);
63333+ continue;
63334+ }
63335+ rcu_read_lock();
63336+ for_ifa(idev) {
63337+ if (!strcmp(ip->iface, ifa->ifa_label)) {
63338+ our_addr = ifa->ifa_address;
63339+ our_netmask = 0xffffffff;
63340+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63341+ if (ret == 1) {
63342+ rcu_read_unlock();
63343+ in_dev_put(idev);
63344+ dev_put(dev);
63345+ return 0;
63346+ } else if (ret == 2) {
63347+ rcu_read_unlock();
63348+ in_dev_put(idev);
63349+ dev_put(dev);
63350+ goto denied;
63351+ }
63352+ }
63353+ } endfor_ifa(idev);
63354+ rcu_read_unlock();
63355+ in_dev_put(idev);
63356+ dev_put(dev);
63357+ } else {
63358+ our_addr = ip->addr;
63359+ our_netmask = ip->netmask;
63360+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63361+ if (ret == 1)
63362+ return 0;
63363+ else if (ret == 2)
63364+ goto denied;
63365+ }
63366+ }
63367+
63368+denied:
63369+ if (mode == GR_BIND)
63370+ 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));
63371+ else if (mode == GR_CONNECT)
63372+ 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));
63373+
63374+ return -EACCES;
63375+}
63376+
63377+int
63378+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
63379+{
63380+ /* always allow disconnection of dgram sockets with connect */
63381+ if (addr->sin_family == AF_UNSPEC)
63382+ return 0;
63383+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
63384+}
63385+
63386+int
63387+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
63388+{
63389+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
63390+}
63391+
63392+int gr_search_listen(struct socket *sock)
63393+{
63394+ struct sock *sk = sock->sk;
63395+ struct sockaddr_in addr;
63396+
63397+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63398+ addr.sin_port = inet_sk(sk)->inet_sport;
63399+
63400+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63401+}
63402+
63403+int gr_search_accept(struct socket *sock)
63404+{
63405+ struct sock *sk = sock->sk;
63406+ struct sockaddr_in addr;
63407+
63408+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63409+ addr.sin_port = inet_sk(sk)->inet_sport;
63410+
63411+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63412+}
63413+
63414+int
63415+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
63416+{
63417+ if (addr)
63418+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
63419+ else {
63420+ struct sockaddr_in sin;
63421+ const struct inet_sock *inet = inet_sk(sk);
63422+
63423+ sin.sin_addr.s_addr = inet->inet_daddr;
63424+ sin.sin_port = inet->inet_dport;
63425+
63426+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63427+ }
63428+}
63429+
63430+int
63431+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
63432+{
63433+ struct sockaddr_in sin;
63434+
63435+ if (unlikely(skb->len < sizeof (struct udphdr)))
63436+ return 0; // skip this packet
63437+
63438+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
63439+ sin.sin_port = udp_hdr(skb)->source;
63440+
63441+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63442+}
63443diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
63444new file mode 100644
63445index 0000000..25f54ef
63446--- /dev/null
63447+++ b/grsecurity/gracl_learn.c
63448@@ -0,0 +1,207 @@
63449+#include <linux/kernel.h>
63450+#include <linux/mm.h>
63451+#include <linux/sched.h>
63452+#include <linux/poll.h>
63453+#include <linux/string.h>
63454+#include <linux/file.h>
63455+#include <linux/types.h>
63456+#include <linux/vmalloc.h>
63457+#include <linux/grinternal.h>
63458+
63459+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
63460+ size_t count, loff_t *ppos);
63461+extern int gr_acl_is_enabled(void);
63462+
63463+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
63464+static int gr_learn_attached;
63465+
63466+/* use a 512k buffer */
63467+#define LEARN_BUFFER_SIZE (512 * 1024)
63468+
63469+static DEFINE_SPINLOCK(gr_learn_lock);
63470+static DEFINE_MUTEX(gr_learn_user_mutex);
63471+
63472+/* we need to maintain two buffers, so that the kernel context of grlearn
63473+ uses a semaphore around the userspace copying, and the other kernel contexts
63474+ use a spinlock when copying into the buffer, since they cannot sleep
63475+*/
63476+static char *learn_buffer;
63477+static char *learn_buffer_user;
63478+static int learn_buffer_len;
63479+static int learn_buffer_user_len;
63480+
63481+static ssize_t
63482+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
63483+{
63484+ DECLARE_WAITQUEUE(wait, current);
63485+ ssize_t retval = 0;
63486+
63487+ add_wait_queue(&learn_wait, &wait);
63488+ set_current_state(TASK_INTERRUPTIBLE);
63489+ do {
63490+ mutex_lock(&gr_learn_user_mutex);
63491+ spin_lock(&gr_learn_lock);
63492+ if (learn_buffer_len)
63493+ break;
63494+ spin_unlock(&gr_learn_lock);
63495+ mutex_unlock(&gr_learn_user_mutex);
63496+ if (file->f_flags & O_NONBLOCK) {
63497+ retval = -EAGAIN;
63498+ goto out;
63499+ }
63500+ if (signal_pending(current)) {
63501+ retval = -ERESTARTSYS;
63502+ goto out;
63503+ }
63504+
63505+ schedule();
63506+ } while (1);
63507+
63508+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
63509+ learn_buffer_user_len = learn_buffer_len;
63510+ retval = learn_buffer_len;
63511+ learn_buffer_len = 0;
63512+
63513+ spin_unlock(&gr_learn_lock);
63514+
63515+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
63516+ retval = -EFAULT;
63517+
63518+ mutex_unlock(&gr_learn_user_mutex);
63519+out:
63520+ set_current_state(TASK_RUNNING);
63521+ remove_wait_queue(&learn_wait, &wait);
63522+ return retval;
63523+}
63524+
63525+static unsigned int
63526+poll_learn(struct file * file, poll_table * wait)
63527+{
63528+ poll_wait(file, &learn_wait, wait);
63529+
63530+ if (learn_buffer_len)
63531+ return (POLLIN | POLLRDNORM);
63532+
63533+ return 0;
63534+}
63535+
63536+void
63537+gr_clear_learn_entries(void)
63538+{
63539+ char *tmp;
63540+
63541+ mutex_lock(&gr_learn_user_mutex);
63542+ spin_lock(&gr_learn_lock);
63543+ tmp = learn_buffer;
63544+ learn_buffer = NULL;
63545+ spin_unlock(&gr_learn_lock);
63546+ if (tmp)
63547+ vfree(tmp);
63548+ if (learn_buffer_user != NULL) {
63549+ vfree(learn_buffer_user);
63550+ learn_buffer_user = NULL;
63551+ }
63552+ learn_buffer_len = 0;
63553+ mutex_unlock(&gr_learn_user_mutex);
63554+
63555+ return;
63556+}
63557+
63558+void
63559+gr_add_learn_entry(const char *fmt, ...)
63560+{
63561+ va_list args;
63562+ unsigned int len;
63563+
63564+ if (!gr_learn_attached)
63565+ return;
63566+
63567+ spin_lock(&gr_learn_lock);
63568+
63569+ /* leave a gap at the end so we know when it's "full" but don't have to
63570+ compute the exact length of the string we're trying to append
63571+ */
63572+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
63573+ spin_unlock(&gr_learn_lock);
63574+ wake_up_interruptible(&learn_wait);
63575+ return;
63576+ }
63577+ if (learn_buffer == NULL) {
63578+ spin_unlock(&gr_learn_lock);
63579+ return;
63580+ }
63581+
63582+ va_start(args, fmt);
63583+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
63584+ va_end(args);
63585+
63586+ learn_buffer_len += len + 1;
63587+
63588+ spin_unlock(&gr_learn_lock);
63589+ wake_up_interruptible(&learn_wait);
63590+
63591+ return;
63592+}
63593+
63594+static int
63595+open_learn(struct inode *inode, struct file *file)
63596+{
63597+ if (file->f_mode & FMODE_READ && gr_learn_attached)
63598+ return -EBUSY;
63599+ if (file->f_mode & FMODE_READ) {
63600+ int retval = 0;
63601+ mutex_lock(&gr_learn_user_mutex);
63602+ if (learn_buffer == NULL)
63603+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
63604+ if (learn_buffer_user == NULL)
63605+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
63606+ if (learn_buffer == NULL) {
63607+ retval = -ENOMEM;
63608+ goto out_error;
63609+ }
63610+ if (learn_buffer_user == NULL) {
63611+ retval = -ENOMEM;
63612+ goto out_error;
63613+ }
63614+ learn_buffer_len = 0;
63615+ learn_buffer_user_len = 0;
63616+ gr_learn_attached = 1;
63617+out_error:
63618+ mutex_unlock(&gr_learn_user_mutex);
63619+ return retval;
63620+ }
63621+ return 0;
63622+}
63623+
63624+static int
63625+close_learn(struct inode *inode, struct file *file)
63626+{
63627+ if (file->f_mode & FMODE_READ) {
63628+ char *tmp = NULL;
63629+ mutex_lock(&gr_learn_user_mutex);
63630+ spin_lock(&gr_learn_lock);
63631+ tmp = learn_buffer;
63632+ learn_buffer = NULL;
63633+ spin_unlock(&gr_learn_lock);
63634+ if (tmp)
63635+ vfree(tmp);
63636+ if (learn_buffer_user != NULL) {
63637+ vfree(learn_buffer_user);
63638+ learn_buffer_user = NULL;
63639+ }
63640+ learn_buffer_len = 0;
63641+ learn_buffer_user_len = 0;
63642+ gr_learn_attached = 0;
63643+ mutex_unlock(&gr_learn_user_mutex);
63644+ }
63645+
63646+ return 0;
63647+}
63648+
63649+const struct file_operations grsec_fops = {
63650+ .read = read_learn,
63651+ .write = write_grsec_handler,
63652+ .open = open_learn,
63653+ .release = close_learn,
63654+ .poll = poll_learn,
63655+};
63656diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
63657new file mode 100644
63658index 0000000..39645c9
63659--- /dev/null
63660+++ b/grsecurity/gracl_res.c
63661@@ -0,0 +1,68 @@
63662+#include <linux/kernel.h>
63663+#include <linux/sched.h>
63664+#include <linux/gracl.h>
63665+#include <linux/grinternal.h>
63666+
63667+static const char *restab_log[] = {
63668+ [RLIMIT_CPU] = "RLIMIT_CPU",
63669+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
63670+ [RLIMIT_DATA] = "RLIMIT_DATA",
63671+ [RLIMIT_STACK] = "RLIMIT_STACK",
63672+ [RLIMIT_CORE] = "RLIMIT_CORE",
63673+ [RLIMIT_RSS] = "RLIMIT_RSS",
63674+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
63675+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
63676+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
63677+ [RLIMIT_AS] = "RLIMIT_AS",
63678+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
63679+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
63680+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
63681+ [RLIMIT_NICE] = "RLIMIT_NICE",
63682+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
63683+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
63684+ [GR_CRASH_RES] = "RLIMIT_CRASH"
63685+};
63686+
63687+void
63688+gr_log_resource(const struct task_struct *task,
63689+ const int res, const unsigned long wanted, const int gt)
63690+{
63691+ const struct cred *cred;
63692+ unsigned long rlim;
63693+
63694+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
63695+ return;
63696+
63697+ // not yet supported resource
63698+ if (unlikely(!restab_log[res]))
63699+ return;
63700+
63701+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
63702+ rlim = task_rlimit_max(task, res);
63703+ else
63704+ rlim = task_rlimit(task, res);
63705+
63706+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
63707+ return;
63708+
63709+ rcu_read_lock();
63710+ cred = __task_cred(task);
63711+
63712+ if (res == RLIMIT_NPROC &&
63713+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
63714+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
63715+ goto out_rcu_unlock;
63716+ else if (res == RLIMIT_MEMLOCK &&
63717+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
63718+ goto out_rcu_unlock;
63719+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
63720+ goto out_rcu_unlock;
63721+ rcu_read_unlock();
63722+
63723+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
63724+
63725+ return;
63726+out_rcu_unlock:
63727+ rcu_read_unlock();
63728+ return;
63729+}
63730diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
63731new file mode 100644
63732index 0000000..3c38bfe
63733--- /dev/null
63734+++ b/grsecurity/gracl_segv.c
63735@@ -0,0 +1,305 @@
63736+#include <linux/kernel.h>
63737+#include <linux/mm.h>
63738+#include <asm/uaccess.h>
63739+#include <asm/errno.h>
63740+#include <asm/mman.h>
63741+#include <net/sock.h>
63742+#include <linux/file.h>
63743+#include <linux/fs.h>
63744+#include <linux/net.h>
63745+#include <linux/in.h>
63746+#include <linux/slab.h>
63747+#include <linux/types.h>
63748+#include <linux/sched.h>
63749+#include <linux/timer.h>
63750+#include <linux/gracl.h>
63751+#include <linux/grsecurity.h>
63752+#include <linux/grinternal.h>
63753+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63754+#include <linux/magic.h>
63755+#include <linux/pagemap.h>
63756+#include "../fs/btrfs/async-thread.h"
63757+#include "../fs/btrfs/ctree.h"
63758+#include "../fs/btrfs/btrfs_inode.h"
63759+#endif
63760+
63761+static struct crash_uid *uid_set;
63762+static unsigned short uid_used;
63763+static DEFINE_SPINLOCK(gr_uid_lock);
63764+extern rwlock_t gr_inode_lock;
63765+extern struct acl_subject_label *
63766+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
63767+ struct acl_role_label *role);
63768+
63769+static inline dev_t __get_dev(const struct dentry *dentry)
63770+{
63771+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63772+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
63773+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
63774+ else
63775+#endif
63776+ return dentry->d_sb->s_dev;
63777+}
63778+
63779+int
63780+gr_init_uidset(void)
63781+{
63782+ uid_set =
63783+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
63784+ uid_used = 0;
63785+
63786+ return uid_set ? 1 : 0;
63787+}
63788+
63789+void
63790+gr_free_uidset(void)
63791+{
63792+ if (uid_set)
63793+ kfree(uid_set);
63794+
63795+ return;
63796+}
63797+
63798+int
63799+gr_find_uid(const uid_t uid)
63800+{
63801+ struct crash_uid *tmp = uid_set;
63802+ uid_t buid;
63803+ int low = 0, high = uid_used - 1, mid;
63804+
63805+ while (high >= low) {
63806+ mid = (low + high) >> 1;
63807+ buid = tmp[mid].uid;
63808+ if (buid == uid)
63809+ return mid;
63810+ if (buid > uid)
63811+ high = mid - 1;
63812+ if (buid < uid)
63813+ low = mid + 1;
63814+ }
63815+
63816+ return -1;
63817+}
63818+
63819+static __inline__ void
63820+gr_insertsort(void)
63821+{
63822+ unsigned short i, j;
63823+ struct crash_uid index;
63824+
63825+ for (i = 1; i < uid_used; i++) {
63826+ index = uid_set[i];
63827+ j = i;
63828+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
63829+ uid_set[j] = uid_set[j - 1];
63830+ j--;
63831+ }
63832+ uid_set[j] = index;
63833+ }
63834+
63835+ return;
63836+}
63837+
63838+static __inline__ void
63839+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
63840+{
63841+ int loc;
63842+ uid_t uid = GR_GLOBAL_UID(kuid);
63843+
63844+ if (uid_used == GR_UIDTABLE_MAX)
63845+ return;
63846+
63847+ loc = gr_find_uid(uid);
63848+
63849+ if (loc >= 0) {
63850+ uid_set[loc].expires = expires;
63851+ return;
63852+ }
63853+
63854+ uid_set[uid_used].uid = uid;
63855+ uid_set[uid_used].expires = expires;
63856+ uid_used++;
63857+
63858+ gr_insertsort();
63859+
63860+ return;
63861+}
63862+
63863+void
63864+gr_remove_uid(const unsigned short loc)
63865+{
63866+ unsigned short i;
63867+
63868+ for (i = loc + 1; i < uid_used; i++)
63869+ uid_set[i - 1] = uid_set[i];
63870+
63871+ uid_used--;
63872+
63873+ return;
63874+}
63875+
63876+int
63877+gr_check_crash_uid(const kuid_t kuid)
63878+{
63879+ int loc;
63880+ int ret = 0;
63881+ uid_t uid;
63882+
63883+ if (unlikely(!gr_acl_is_enabled()))
63884+ return 0;
63885+
63886+ uid = GR_GLOBAL_UID(kuid);
63887+
63888+ spin_lock(&gr_uid_lock);
63889+ loc = gr_find_uid(uid);
63890+
63891+ if (loc < 0)
63892+ goto out_unlock;
63893+
63894+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
63895+ gr_remove_uid(loc);
63896+ else
63897+ ret = 1;
63898+
63899+out_unlock:
63900+ spin_unlock(&gr_uid_lock);
63901+ return ret;
63902+}
63903+
63904+static __inline__ int
63905+proc_is_setxid(const struct cred *cred)
63906+{
63907+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
63908+ !uid_eq(cred->uid, cred->fsuid))
63909+ return 1;
63910+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
63911+ !gid_eq(cred->gid, cred->fsgid))
63912+ return 1;
63913+
63914+ return 0;
63915+}
63916+
63917+extern int gr_fake_force_sig(int sig, struct task_struct *t);
63918+
63919+void
63920+gr_handle_crash(struct task_struct *task, const int sig)
63921+{
63922+ struct acl_subject_label *curr;
63923+ struct task_struct *tsk, *tsk2;
63924+ const struct cred *cred;
63925+ const struct cred *cred2;
63926+
63927+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
63928+ return;
63929+
63930+ if (unlikely(!gr_acl_is_enabled()))
63931+ return;
63932+
63933+ curr = task->acl;
63934+
63935+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
63936+ return;
63937+
63938+ if (time_before_eq(curr->expires, get_seconds())) {
63939+ curr->expires = 0;
63940+ curr->crashes = 0;
63941+ }
63942+
63943+ curr->crashes++;
63944+
63945+ if (!curr->expires)
63946+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
63947+
63948+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63949+ time_after(curr->expires, get_seconds())) {
63950+ rcu_read_lock();
63951+ cred = __task_cred(task);
63952+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
63953+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63954+ spin_lock(&gr_uid_lock);
63955+ gr_insert_uid(cred->uid, curr->expires);
63956+ spin_unlock(&gr_uid_lock);
63957+ curr->expires = 0;
63958+ curr->crashes = 0;
63959+ read_lock(&tasklist_lock);
63960+ do_each_thread(tsk2, tsk) {
63961+ cred2 = __task_cred(tsk);
63962+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
63963+ gr_fake_force_sig(SIGKILL, tsk);
63964+ } while_each_thread(tsk2, tsk);
63965+ read_unlock(&tasklist_lock);
63966+ } else {
63967+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63968+ read_lock(&tasklist_lock);
63969+ read_lock(&grsec_exec_file_lock);
63970+ do_each_thread(tsk2, tsk) {
63971+ if (likely(tsk != task)) {
63972+ // if this thread has the same subject as the one that triggered
63973+ // RES_CRASH and it's the same binary, kill it
63974+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
63975+ gr_fake_force_sig(SIGKILL, tsk);
63976+ }
63977+ } while_each_thread(tsk2, tsk);
63978+ read_unlock(&grsec_exec_file_lock);
63979+ read_unlock(&tasklist_lock);
63980+ }
63981+ rcu_read_unlock();
63982+ }
63983+
63984+ return;
63985+}
63986+
63987+int
63988+gr_check_crash_exec(const struct file *filp)
63989+{
63990+ struct acl_subject_label *curr;
63991+
63992+ if (unlikely(!gr_acl_is_enabled()))
63993+ return 0;
63994+
63995+ read_lock(&gr_inode_lock);
63996+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
63997+ __get_dev(filp->f_path.dentry),
63998+ current->role);
63999+ read_unlock(&gr_inode_lock);
64000+
64001+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
64002+ (!curr->crashes && !curr->expires))
64003+ return 0;
64004+
64005+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
64006+ time_after(curr->expires, get_seconds()))
64007+ return 1;
64008+ else if (time_before_eq(curr->expires, get_seconds())) {
64009+ curr->crashes = 0;
64010+ curr->expires = 0;
64011+ }
64012+
64013+ return 0;
64014+}
64015+
64016+void
64017+gr_handle_alertkill(struct task_struct *task)
64018+{
64019+ struct acl_subject_label *curracl;
64020+ __u32 curr_ip;
64021+ struct task_struct *p, *p2;
64022+
64023+ if (unlikely(!gr_acl_is_enabled()))
64024+ return;
64025+
64026+ curracl = task->acl;
64027+ curr_ip = task->signal->curr_ip;
64028+
64029+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
64030+ read_lock(&tasklist_lock);
64031+ do_each_thread(p2, p) {
64032+ if (p->signal->curr_ip == curr_ip)
64033+ gr_fake_force_sig(SIGKILL, p);
64034+ } while_each_thread(p2, p);
64035+ read_unlock(&tasklist_lock);
64036+ } else if (curracl->mode & GR_KILLPROC)
64037+ gr_fake_force_sig(SIGKILL, task);
64038+
64039+ return;
64040+}
64041diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
64042new file mode 100644
64043index 0000000..98011b0
64044--- /dev/null
64045+++ b/grsecurity/gracl_shm.c
64046@@ -0,0 +1,40 @@
64047+#include <linux/kernel.h>
64048+#include <linux/mm.h>
64049+#include <linux/sched.h>
64050+#include <linux/file.h>
64051+#include <linux/ipc.h>
64052+#include <linux/gracl.h>
64053+#include <linux/grsecurity.h>
64054+#include <linux/grinternal.h>
64055+
64056+int
64057+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64058+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64059+{
64060+ struct task_struct *task;
64061+
64062+ if (!gr_acl_is_enabled())
64063+ return 1;
64064+
64065+ rcu_read_lock();
64066+ read_lock(&tasklist_lock);
64067+
64068+ task = find_task_by_vpid(shm_cprid);
64069+
64070+ if (unlikely(!task))
64071+ task = find_task_by_vpid(shm_lapid);
64072+
64073+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
64074+ (task_pid_nr(task) == shm_lapid)) &&
64075+ (task->acl->mode & GR_PROTSHM) &&
64076+ (task->acl != current->acl))) {
64077+ read_unlock(&tasklist_lock);
64078+ rcu_read_unlock();
64079+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
64080+ return 0;
64081+ }
64082+ read_unlock(&tasklist_lock);
64083+ rcu_read_unlock();
64084+
64085+ return 1;
64086+}
64087diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
64088new file mode 100644
64089index 0000000..bc0be01
64090--- /dev/null
64091+++ b/grsecurity/grsec_chdir.c
64092@@ -0,0 +1,19 @@
64093+#include <linux/kernel.h>
64094+#include <linux/sched.h>
64095+#include <linux/fs.h>
64096+#include <linux/file.h>
64097+#include <linux/grsecurity.h>
64098+#include <linux/grinternal.h>
64099+
64100+void
64101+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
64102+{
64103+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64104+ if ((grsec_enable_chdir && grsec_enable_group &&
64105+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
64106+ !grsec_enable_group)) {
64107+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
64108+ }
64109+#endif
64110+ return;
64111+}
64112diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
64113new file mode 100644
64114index 0000000..bd6e105
64115--- /dev/null
64116+++ b/grsecurity/grsec_chroot.c
64117@@ -0,0 +1,370 @@
64118+#include <linux/kernel.h>
64119+#include <linux/module.h>
64120+#include <linux/sched.h>
64121+#include <linux/file.h>
64122+#include <linux/fs.h>
64123+#include <linux/mount.h>
64124+#include <linux/types.h>
64125+#include "../fs/mount.h"
64126+#include <linux/grsecurity.h>
64127+#include <linux/grinternal.h>
64128+
64129+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64130+static int gr_init_ran;
64131+#endif
64132+
64133+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
64134+{
64135+#ifdef CONFIG_GRKERNSEC
64136+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
64137+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
64138+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64139+ && gr_init_ran
64140+#endif
64141+ )
64142+ task->gr_is_chrooted = 1;
64143+ else {
64144+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64145+ if (task_pid_nr(task) == 1 && !gr_init_ran)
64146+ gr_init_ran = 1;
64147+#endif
64148+ task->gr_is_chrooted = 0;
64149+ }
64150+
64151+ task->gr_chroot_dentry = path->dentry;
64152+#endif
64153+ return;
64154+}
64155+
64156+void gr_clear_chroot_entries(struct task_struct *task)
64157+{
64158+#ifdef CONFIG_GRKERNSEC
64159+ task->gr_is_chrooted = 0;
64160+ task->gr_chroot_dentry = NULL;
64161+#endif
64162+ return;
64163+}
64164+
64165+int
64166+gr_handle_chroot_unix(const pid_t pid)
64167+{
64168+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64169+ struct task_struct *p;
64170+
64171+ if (unlikely(!grsec_enable_chroot_unix))
64172+ return 1;
64173+
64174+ if (likely(!proc_is_chrooted(current)))
64175+ return 1;
64176+
64177+ rcu_read_lock();
64178+ read_lock(&tasklist_lock);
64179+ p = find_task_by_vpid_unrestricted(pid);
64180+ if (unlikely(p && !have_same_root(current, p))) {
64181+ read_unlock(&tasklist_lock);
64182+ rcu_read_unlock();
64183+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
64184+ return 0;
64185+ }
64186+ read_unlock(&tasklist_lock);
64187+ rcu_read_unlock();
64188+#endif
64189+ return 1;
64190+}
64191+
64192+int
64193+gr_handle_chroot_nice(void)
64194+{
64195+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64196+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
64197+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
64198+ return -EPERM;
64199+ }
64200+#endif
64201+ return 0;
64202+}
64203+
64204+int
64205+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
64206+{
64207+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64208+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
64209+ && proc_is_chrooted(current)) {
64210+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
64211+ return -EACCES;
64212+ }
64213+#endif
64214+ return 0;
64215+}
64216+
64217+int
64218+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
64219+{
64220+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64221+ struct task_struct *p;
64222+ int ret = 0;
64223+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
64224+ return ret;
64225+
64226+ read_lock(&tasklist_lock);
64227+ do_each_pid_task(pid, type, p) {
64228+ if (!have_same_root(current, p)) {
64229+ ret = 1;
64230+ goto out;
64231+ }
64232+ } while_each_pid_task(pid, type, p);
64233+out:
64234+ read_unlock(&tasklist_lock);
64235+ return ret;
64236+#endif
64237+ return 0;
64238+}
64239+
64240+int
64241+gr_pid_is_chrooted(struct task_struct *p)
64242+{
64243+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64244+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
64245+ return 0;
64246+
64247+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
64248+ !have_same_root(current, p)) {
64249+ return 1;
64250+ }
64251+#endif
64252+ return 0;
64253+}
64254+
64255+EXPORT_SYMBOL(gr_pid_is_chrooted);
64256+
64257+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
64258+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
64259+{
64260+ struct path path, currentroot;
64261+ int ret = 0;
64262+
64263+ path.dentry = (struct dentry *)u_dentry;
64264+ path.mnt = (struct vfsmount *)u_mnt;
64265+ get_fs_root(current->fs, &currentroot);
64266+ if (path_is_under(&path, &currentroot))
64267+ ret = 1;
64268+ path_put(&currentroot);
64269+
64270+ return ret;
64271+}
64272+#endif
64273+
64274+int
64275+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
64276+{
64277+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64278+ if (!grsec_enable_chroot_fchdir)
64279+ return 1;
64280+
64281+ if (!proc_is_chrooted(current))
64282+ return 1;
64283+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
64284+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
64285+ return 0;
64286+ }
64287+#endif
64288+ return 1;
64289+}
64290+
64291+int
64292+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64293+ const time_t shm_createtime)
64294+{
64295+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64296+ struct task_struct *p;
64297+ time_t starttime;
64298+
64299+ if (unlikely(!grsec_enable_chroot_shmat))
64300+ return 1;
64301+
64302+ if (likely(!proc_is_chrooted(current)))
64303+ return 1;
64304+
64305+ rcu_read_lock();
64306+ read_lock(&tasklist_lock);
64307+
64308+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
64309+ starttime = p->start_time.tv_sec;
64310+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
64311+ if (have_same_root(current, p)) {
64312+ goto allow;
64313+ } else {
64314+ read_unlock(&tasklist_lock);
64315+ rcu_read_unlock();
64316+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64317+ return 0;
64318+ }
64319+ }
64320+ /* creator exited, pid reuse, fall through to next check */
64321+ }
64322+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
64323+ if (unlikely(!have_same_root(current, p))) {
64324+ read_unlock(&tasklist_lock);
64325+ rcu_read_unlock();
64326+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64327+ return 0;
64328+ }
64329+ }
64330+
64331+allow:
64332+ read_unlock(&tasklist_lock);
64333+ rcu_read_unlock();
64334+#endif
64335+ return 1;
64336+}
64337+
64338+void
64339+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
64340+{
64341+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64342+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
64343+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
64344+#endif
64345+ return;
64346+}
64347+
64348+int
64349+gr_handle_chroot_mknod(const struct dentry *dentry,
64350+ const struct vfsmount *mnt, const int mode)
64351+{
64352+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64353+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
64354+ proc_is_chrooted(current)) {
64355+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
64356+ return -EPERM;
64357+ }
64358+#endif
64359+ return 0;
64360+}
64361+
64362+int
64363+gr_handle_chroot_mount(const struct dentry *dentry,
64364+ const struct vfsmount *mnt, const char *dev_name)
64365+{
64366+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64367+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
64368+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
64369+ return -EPERM;
64370+ }
64371+#endif
64372+ return 0;
64373+}
64374+
64375+int
64376+gr_handle_chroot_pivot(void)
64377+{
64378+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64379+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
64380+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
64381+ return -EPERM;
64382+ }
64383+#endif
64384+ return 0;
64385+}
64386+
64387+int
64388+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
64389+{
64390+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64391+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
64392+ !gr_is_outside_chroot(dentry, mnt)) {
64393+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
64394+ return -EPERM;
64395+ }
64396+#endif
64397+ return 0;
64398+}
64399+
64400+extern const char *captab_log[];
64401+extern int captab_log_entries;
64402+
64403+int
64404+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64405+{
64406+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64407+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64408+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64409+ if (cap_raised(chroot_caps, cap)) {
64410+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
64411+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
64412+ }
64413+ return 0;
64414+ }
64415+ }
64416+#endif
64417+ return 1;
64418+}
64419+
64420+int
64421+gr_chroot_is_capable(const int cap)
64422+{
64423+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64424+ return gr_task_chroot_is_capable(current, current_cred(), cap);
64425+#endif
64426+ return 1;
64427+}
64428+
64429+int
64430+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
64431+{
64432+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64433+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64434+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64435+ if (cap_raised(chroot_caps, cap)) {
64436+ return 0;
64437+ }
64438+ }
64439+#endif
64440+ return 1;
64441+}
64442+
64443+int
64444+gr_chroot_is_capable_nolog(const int cap)
64445+{
64446+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64447+ return gr_task_chroot_is_capable_nolog(current, cap);
64448+#endif
64449+ return 1;
64450+}
64451+
64452+int
64453+gr_handle_chroot_sysctl(const int op)
64454+{
64455+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64456+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
64457+ proc_is_chrooted(current))
64458+ return -EACCES;
64459+#endif
64460+ return 0;
64461+}
64462+
64463+void
64464+gr_handle_chroot_chdir(const struct path *path)
64465+{
64466+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64467+ if (grsec_enable_chroot_chdir)
64468+ set_fs_pwd(current->fs, path);
64469+#endif
64470+ return;
64471+}
64472+
64473+int
64474+gr_handle_chroot_chmod(const struct dentry *dentry,
64475+ const struct vfsmount *mnt, const int mode)
64476+{
64477+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64478+ /* allow chmod +s on directories, but not files */
64479+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
64480+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
64481+ proc_is_chrooted(current)) {
64482+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
64483+ return -EPERM;
64484+ }
64485+#endif
64486+ return 0;
64487+}
64488diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
64489new file mode 100644
64490index 0000000..ce65ceb
64491--- /dev/null
64492+++ b/grsecurity/grsec_disabled.c
64493@@ -0,0 +1,434 @@
64494+#include <linux/kernel.h>
64495+#include <linux/module.h>
64496+#include <linux/sched.h>
64497+#include <linux/file.h>
64498+#include <linux/fs.h>
64499+#include <linux/kdev_t.h>
64500+#include <linux/net.h>
64501+#include <linux/in.h>
64502+#include <linux/ip.h>
64503+#include <linux/skbuff.h>
64504+#include <linux/sysctl.h>
64505+
64506+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64507+void
64508+pax_set_initial_flags(struct linux_binprm *bprm)
64509+{
64510+ return;
64511+}
64512+#endif
64513+
64514+#ifdef CONFIG_SYSCTL
64515+__u32
64516+gr_handle_sysctl(const struct ctl_table * table, const int op)
64517+{
64518+ return 0;
64519+}
64520+#endif
64521+
64522+#ifdef CONFIG_TASKSTATS
64523+int gr_is_taskstats_denied(int pid)
64524+{
64525+ return 0;
64526+}
64527+#endif
64528+
64529+int
64530+gr_acl_is_enabled(void)
64531+{
64532+ return 0;
64533+}
64534+
64535+void
64536+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64537+{
64538+ return;
64539+}
64540+
64541+int
64542+gr_handle_rawio(const struct inode *inode)
64543+{
64544+ return 0;
64545+}
64546+
64547+void
64548+gr_acl_handle_psacct(struct task_struct *task, const long code)
64549+{
64550+ return;
64551+}
64552+
64553+int
64554+gr_handle_ptrace(struct task_struct *task, const long request)
64555+{
64556+ return 0;
64557+}
64558+
64559+int
64560+gr_handle_proc_ptrace(struct task_struct *task)
64561+{
64562+ return 0;
64563+}
64564+
64565+int
64566+gr_set_acls(const int type)
64567+{
64568+ return 0;
64569+}
64570+
64571+int
64572+gr_check_hidden_task(const struct task_struct *tsk)
64573+{
64574+ return 0;
64575+}
64576+
64577+int
64578+gr_check_protected_task(const struct task_struct *task)
64579+{
64580+ return 0;
64581+}
64582+
64583+int
64584+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64585+{
64586+ return 0;
64587+}
64588+
64589+void
64590+gr_copy_label(struct task_struct *tsk)
64591+{
64592+ return;
64593+}
64594+
64595+void
64596+gr_set_pax_flags(struct task_struct *task)
64597+{
64598+ return;
64599+}
64600+
64601+int
64602+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64603+ const int unsafe_share)
64604+{
64605+ return 0;
64606+}
64607+
64608+void
64609+gr_handle_delete(const ino_t ino, const dev_t dev)
64610+{
64611+ return;
64612+}
64613+
64614+void
64615+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64616+{
64617+ return;
64618+}
64619+
64620+void
64621+gr_handle_crash(struct task_struct *task, const int sig)
64622+{
64623+ return;
64624+}
64625+
64626+int
64627+gr_check_crash_exec(const struct file *filp)
64628+{
64629+ return 0;
64630+}
64631+
64632+int
64633+gr_check_crash_uid(const kuid_t uid)
64634+{
64635+ return 0;
64636+}
64637+
64638+void
64639+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64640+ struct dentry *old_dentry,
64641+ struct dentry *new_dentry,
64642+ struct vfsmount *mnt, const __u8 replace)
64643+{
64644+ return;
64645+}
64646+
64647+int
64648+gr_search_socket(const int family, const int type, const int protocol)
64649+{
64650+ return 1;
64651+}
64652+
64653+int
64654+gr_search_connectbind(const int mode, const struct socket *sock,
64655+ const struct sockaddr_in *addr)
64656+{
64657+ return 0;
64658+}
64659+
64660+void
64661+gr_handle_alertkill(struct task_struct *task)
64662+{
64663+ return;
64664+}
64665+
64666+__u32
64667+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
64668+{
64669+ return 1;
64670+}
64671+
64672+__u32
64673+gr_acl_handle_hidden_file(const struct dentry * dentry,
64674+ const struct vfsmount * mnt)
64675+{
64676+ return 1;
64677+}
64678+
64679+__u32
64680+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
64681+ int acc_mode)
64682+{
64683+ return 1;
64684+}
64685+
64686+__u32
64687+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
64688+{
64689+ return 1;
64690+}
64691+
64692+__u32
64693+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
64694+{
64695+ return 1;
64696+}
64697+
64698+int
64699+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
64700+ unsigned int *vm_flags)
64701+{
64702+ return 1;
64703+}
64704+
64705+__u32
64706+gr_acl_handle_truncate(const struct dentry * dentry,
64707+ const struct vfsmount * mnt)
64708+{
64709+ return 1;
64710+}
64711+
64712+__u32
64713+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
64714+{
64715+ return 1;
64716+}
64717+
64718+__u32
64719+gr_acl_handle_access(const struct dentry * dentry,
64720+ const struct vfsmount * mnt, const int fmode)
64721+{
64722+ return 1;
64723+}
64724+
64725+__u32
64726+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
64727+ umode_t *mode)
64728+{
64729+ return 1;
64730+}
64731+
64732+__u32
64733+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
64734+{
64735+ return 1;
64736+}
64737+
64738+__u32
64739+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
64740+{
64741+ return 1;
64742+}
64743+
64744+void
64745+grsecurity_init(void)
64746+{
64747+ return;
64748+}
64749+
64750+umode_t gr_acl_umask(void)
64751+{
64752+ return 0;
64753+}
64754+
64755+__u32
64756+gr_acl_handle_mknod(const struct dentry * new_dentry,
64757+ const struct dentry * parent_dentry,
64758+ const struct vfsmount * parent_mnt,
64759+ const int mode)
64760+{
64761+ return 1;
64762+}
64763+
64764+__u32
64765+gr_acl_handle_mkdir(const struct dentry * new_dentry,
64766+ const struct dentry * parent_dentry,
64767+ const struct vfsmount * parent_mnt)
64768+{
64769+ return 1;
64770+}
64771+
64772+__u32
64773+gr_acl_handle_symlink(const struct dentry * new_dentry,
64774+ const struct dentry * parent_dentry,
64775+ const struct vfsmount * parent_mnt, const struct filename *from)
64776+{
64777+ return 1;
64778+}
64779+
64780+__u32
64781+gr_acl_handle_link(const struct dentry * new_dentry,
64782+ const struct dentry * parent_dentry,
64783+ const struct vfsmount * parent_mnt,
64784+ const struct dentry * old_dentry,
64785+ const struct vfsmount * old_mnt, const struct filename *to)
64786+{
64787+ return 1;
64788+}
64789+
64790+int
64791+gr_acl_handle_rename(const struct dentry *new_dentry,
64792+ const struct dentry *parent_dentry,
64793+ const struct vfsmount *parent_mnt,
64794+ const struct dentry *old_dentry,
64795+ const struct inode *old_parent_inode,
64796+ const struct vfsmount *old_mnt, const struct filename *newname)
64797+{
64798+ return 0;
64799+}
64800+
64801+int
64802+gr_acl_handle_filldir(const struct file *file, const char *name,
64803+ const int namelen, const ino_t ino)
64804+{
64805+ return 1;
64806+}
64807+
64808+int
64809+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64810+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64811+{
64812+ return 1;
64813+}
64814+
64815+int
64816+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
64817+{
64818+ return 0;
64819+}
64820+
64821+int
64822+gr_search_accept(const struct socket *sock)
64823+{
64824+ return 0;
64825+}
64826+
64827+int
64828+gr_search_listen(const struct socket *sock)
64829+{
64830+ return 0;
64831+}
64832+
64833+int
64834+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
64835+{
64836+ return 0;
64837+}
64838+
64839+__u32
64840+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
64841+{
64842+ return 1;
64843+}
64844+
64845+__u32
64846+gr_acl_handle_creat(const struct dentry * dentry,
64847+ const struct dentry * p_dentry,
64848+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
64849+ const int imode)
64850+{
64851+ return 1;
64852+}
64853+
64854+void
64855+gr_acl_handle_exit(void)
64856+{
64857+ return;
64858+}
64859+
64860+int
64861+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
64862+{
64863+ return 1;
64864+}
64865+
64866+void
64867+gr_set_role_label(const kuid_t uid, const kgid_t gid)
64868+{
64869+ return;
64870+}
64871+
64872+int
64873+gr_acl_handle_procpidmem(const struct task_struct *task)
64874+{
64875+ return 0;
64876+}
64877+
64878+int
64879+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
64880+{
64881+ return 0;
64882+}
64883+
64884+int
64885+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
64886+{
64887+ return 0;
64888+}
64889+
64890+void
64891+gr_set_kernel_label(struct task_struct *task)
64892+{
64893+ return;
64894+}
64895+
64896+int
64897+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64898+{
64899+ return 0;
64900+}
64901+
64902+int
64903+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64904+{
64905+ return 0;
64906+}
64907+
64908+int gr_acl_enable_at_secure(void)
64909+{
64910+ return 0;
64911+}
64912+
64913+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
64914+{
64915+ return dentry->d_sb->s_dev;
64916+}
64917+
64918+void gr_put_exec_file(struct task_struct *task)
64919+{
64920+ return;
64921+}
64922+
64923+EXPORT_SYMBOL(gr_set_kernel_label);
64924+#ifdef CONFIG_SECURITY
64925+EXPORT_SYMBOL(gr_check_user_change);
64926+EXPORT_SYMBOL(gr_check_group_change);
64927+#endif
64928diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
64929new file mode 100644
64930index 0000000..387032b
64931--- /dev/null
64932+++ b/grsecurity/grsec_exec.c
64933@@ -0,0 +1,187 @@
64934+#include <linux/kernel.h>
64935+#include <linux/sched.h>
64936+#include <linux/file.h>
64937+#include <linux/binfmts.h>
64938+#include <linux/fs.h>
64939+#include <linux/types.h>
64940+#include <linux/grdefs.h>
64941+#include <linux/grsecurity.h>
64942+#include <linux/grinternal.h>
64943+#include <linux/capability.h>
64944+#include <linux/module.h>
64945+#include <linux/compat.h>
64946+
64947+#include <asm/uaccess.h>
64948+
64949+#ifdef CONFIG_GRKERNSEC_EXECLOG
64950+static char gr_exec_arg_buf[132];
64951+static DEFINE_MUTEX(gr_exec_arg_mutex);
64952+#endif
64953+
64954+struct user_arg_ptr {
64955+#ifdef CONFIG_COMPAT
64956+ bool is_compat;
64957+#endif
64958+ union {
64959+ const char __user *const __user *native;
64960+#ifdef CONFIG_COMPAT
64961+ const compat_uptr_t __user *compat;
64962+#endif
64963+ } ptr;
64964+};
64965+
64966+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
64967+
64968+void
64969+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
64970+{
64971+#ifdef CONFIG_GRKERNSEC_EXECLOG
64972+ char *grarg = gr_exec_arg_buf;
64973+ unsigned int i, x, execlen = 0;
64974+ char c;
64975+
64976+ if (!((grsec_enable_execlog && grsec_enable_group &&
64977+ in_group_p(grsec_audit_gid))
64978+ || (grsec_enable_execlog && !grsec_enable_group)))
64979+ return;
64980+
64981+ mutex_lock(&gr_exec_arg_mutex);
64982+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
64983+
64984+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
64985+ const char __user *p;
64986+ unsigned int len;
64987+
64988+ p = get_user_arg_ptr(argv, i);
64989+ if (IS_ERR(p))
64990+ goto log;
64991+
64992+ len = strnlen_user(p, 128 - execlen);
64993+ if (len > 128 - execlen)
64994+ len = 128 - execlen;
64995+ else if (len > 0)
64996+ len--;
64997+ if (copy_from_user(grarg + execlen, p, len))
64998+ goto log;
64999+
65000+ /* rewrite unprintable characters */
65001+ for (x = 0; x < len; x++) {
65002+ c = *(grarg + execlen + x);
65003+ if (c < 32 || c > 126)
65004+ *(grarg + execlen + x) = ' ';
65005+ }
65006+
65007+ execlen += len;
65008+ *(grarg + execlen) = ' ';
65009+ *(grarg + execlen + 1) = '\0';
65010+ execlen++;
65011+ }
65012+
65013+ log:
65014+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
65015+ bprm->file->f_path.mnt, grarg);
65016+ mutex_unlock(&gr_exec_arg_mutex);
65017+#endif
65018+ return;
65019+}
65020+
65021+#ifdef CONFIG_GRKERNSEC
65022+extern int gr_acl_is_capable(const int cap);
65023+extern int gr_acl_is_capable_nolog(const int cap);
65024+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65025+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
65026+extern int gr_chroot_is_capable(const int cap);
65027+extern int gr_chroot_is_capable_nolog(const int cap);
65028+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65029+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
65030+#endif
65031+
65032+const char *captab_log[] = {
65033+ "CAP_CHOWN",
65034+ "CAP_DAC_OVERRIDE",
65035+ "CAP_DAC_READ_SEARCH",
65036+ "CAP_FOWNER",
65037+ "CAP_FSETID",
65038+ "CAP_KILL",
65039+ "CAP_SETGID",
65040+ "CAP_SETUID",
65041+ "CAP_SETPCAP",
65042+ "CAP_LINUX_IMMUTABLE",
65043+ "CAP_NET_BIND_SERVICE",
65044+ "CAP_NET_BROADCAST",
65045+ "CAP_NET_ADMIN",
65046+ "CAP_NET_RAW",
65047+ "CAP_IPC_LOCK",
65048+ "CAP_IPC_OWNER",
65049+ "CAP_SYS_MODULE",
65050+ "CAP_SYS_RAWIO",
65051+ "CAP_SYS_CHROOT",
65052+ "CAP_SYS_PTRACE",
65053+ "CAP_SYS_PACCT",
65054+ "CAP_SYS_ADMIN",
65055+ "CAP_SYS_BOOT",
65056+ "CAP_SYS_NICE",
65057+ "CAP_SYS_RESOURCE",
65058+ "CAP_SYS_TIME",
65059+ "CAP_SYS_TTY_CONFIG",
65060+ "CAP_MKNOD",
65061+ "CAP_LEASE",
65062+ "CAP_AUDIT_WRITE",
65063+ "CAP_AUDIT_CONTROL",
65064+ "CAP_SETFCAP",
65065+ "CAP_MAC_OVERRIDE",
65066+ "CAP_MAC_ADMIN",
65067+ "CAP_SYSLOG",
65068+ "CAP_WAKE_ALARM"
65069+};
65070+
65071+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
65072+
65073+int gr_is_capable(const int cap)
65074+{
65075+#ifdef CONFIG_GRKERNSEC
65076+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
65077+ return 1;
65078+ return 0;
65079+#else
65080+ return 1;
65081+#endif
65082+}
65083+
65084+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
65085+{
65086+#ifdef CONFIG_GRKERNSEC
65087+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
65088+ return 1;
65089+ return 0;
65090+#else
65091+ return 1;
65092+#endif
65093+}
65094+
65095+int gr_is_capable_nolog(const int cap)
65096+{
65097+#ifdef CONFIG_GRKERNSEC
65098+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
65099+ return 1;
65100+ return 0;
65101+#else
65102+ return 1;
65103+#endif
65104+}
65105+
65106+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
65107+{
65108+#ifdef CONFIG_GRKERNSEC
65109+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
65110+ return 1;
65111+ return 0;
65112+#else
65113+ return 1;
65114+#endif
65115+}
65116+
65117+EXPORT_SYMBOL(gr_is_capable);
65118+EXPORT_SYMBOL(gr_is_capable_nolog);
65119+EXPORT_SYMBOL(gr_task_is_capable);
65120+EXPORT_SYMBOL(gr_task_is_capable_nolog);
65121diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
65122new file mode 100644
65123index 0000000..06cc6ea
65124--- /dev/null
65125+++ b/grsecurity/grsec_fifo.c
65126@@ -0,0 +1,24 @@
65127+#include <linux/kernel.h>
65128+#include <linux/sched.h>
65129+#include <linux/fs.h>
65130+#include <linux/file.h>
65131+#include <linux/grinternal.h>
65132+
65133+int
65134+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
65135+ const struct dentry *dir, const int flag, const int acc_mode)
65136+{
65137+#ifdef CONFIG_GRKERNSEC_FIFO
65138+ const struct cred *cred = current_cred();
65139+
65140+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
65141+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
65142+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
65143+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
65144+ if (!inode_permission(dentry->d_inode, acc_mode))
65145+ 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));
65146+ return -EACCES;
65147+ }
65148+#endif
65149+ return 0;
65150+}
65151diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
65152new file mode 100644
65153index 0000000..8ca18bf
65154--- /dev/null
65155+++ b/grsecurity/grsec_fork.c
65156@@ -0,0 +1,23 @@
65157+#include <linux/kernel.h>
65158+#include <linux/sched.h>
65159+#include <linux/grsecurity.h>
65160+#include <linux/grinternal.h>
65161+#include <linux/errno.h>
65162+
65163+void
65164+gr_log_forkfail(const int retval)
65165+{
65166+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65167+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
65168+ switch (retval) {
65169+ case -EAGAIN:
65170+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
65171+ break;
65172+ case -ENOMEM:
65173+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
65174+ break;
65175+ }
65176+ }
65177+#endif
65178+ return;
65179+}
65180diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
65181new file mode 100644
65182index 0000000..a862e9f
65183--- /dev/null
65184+++ b/grsecurity/grsec_init.c
65185@@ -0,0 +1,283 @@
65186+#include <linux/kernel.h>
65187+#include <linux/sched.h>
65188+#include <linux/mm.h>
65189+#include <linux/gracl.h>
65190+#include <linux/slab.h>
65191+#include <linux/vmalloc.h>
65192+#include <linux/percpu.h>
65193+#include <linux/module.h>
65194+
65195+int grsec_enable_ptrace_readexec;
65196+int grsec_enable_setxid;
65197+int grsec_enable_symlinkown;
65198+kgid_t grsec_symlinkown_gid;
65199+int grsec_enable_brute;
65200+int grsec_enable_link;
65201+int grsec_enable_dmesg;
65202+int grsec_enable_harden_ptrace;
65203+int grsec_enable_fifo;
65204+int grsec_enable_execlog;
65205+int grsec_enable_signal;
65206+int grsec_enable_forkfail;
65207+int grsec_enable_audit_ptrace;
65208+int grsec_enable_time;
65209+int grsec_enable_audit_textrel;
65210+int grsec_enable_group;
65211+kgid_t grsec_audit_gid;
65212+int grsec_enable_chdir;
65213+int grsec_enable_mount;
65214+int grsec_enable_rofs;
65215+int grsec_enable_chroot_findtask;
65216+int grsec_enable_chroot_mount;
65217+int grsec_enable_chroot_shmat;
65218+int grsec_enable_chroot_fchdir;
65219+int grsec_enable_chroot_double;
65220+int grsec_enable_chroot_pivot;
65221+int grsec_enable_chroot_chdir;
65222+int grsec_enable_chroot_chmod;
65223+int grsec_enable_chroot_mknod;
65224+int grsec_enable_chroot_nice;
65225+int grsec_enable_chroot_execlog;
65226+int grsec_enable_chroot_caps;
65227+int grsec_enable_chroot_sysctl;
65228+int grsec_enable_chroot_unix;
65229+int grsec_enable_tpe;
65230+kgid_t grsec_tpe_gid;
65231+int grsec_enable_blackhole;
65232+#ifdef CONFIG_IPV6_MODULE
65233+EXPORT_SYMBOL(grsec_enable_blackhole);
65234+#endif
65235+int grsec_lastack_retries;
65236+int grsec_enable_tpe_all;
65237+int grsec_enable_tpe_invert;
65238+int grsec_enable_socket_all;
65239+kgid_t grsec_socket_all_gid;
65240+int grsec_enable_socket_client;
65241+kgid_t grsec_socket_client_gid;
65242+int grsec_enable_socket_server;
65243+kgid_t grsec_socket_server_gid;
65244+int grsec_resource_logging;
65245+int grsec_disable_privio;
65246+int grsec_enable_log_rwxmaps;
65247+int grsec_lock;
65248+
65249+DEFINE_SPINLOCK(grsec_alert_lock);
65250+unsigned long grsec_alert_wtime = 0;
65251+unsigned long grsec_alert_fyet = 0;
65252+
65253+DEFINE_SPINLOCK(grsec_audit_lock);
65254+
65255+DEFINE_RWLOCK(grsec_exec_file_lock);
65256+
65257+char *gr_shared_page[4];
65258+
65259+char *gr_alert_log_fmt;
65260+char *gr_audit_log_fmt;
65261+char *gr_alert_log_buf;
65262+char *gr_audit_log_buf;
65263+
65264+extern struct gr_arg *gr_usermode;
65265+extern unsigned char *gr_system_salt;
65266+extern unsigned char *gr_system_sum;
65267+
65268+void __init
65269+grsecurity_init(void)
65270+{
65271+ int j;
65272+ /* create the per-cpu shared pages */
65273+
65274+#ifdef CONFIG_X86
65275+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
65276+#endif
65277+
65278+ for (j = 0; j < 4; j++) {
65279+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
65280+ if (gr_shared_page[j] == NULL) {
65281+ panic("Unable to allocate grsecurity shared page");
65282+ return;
65283+ }
65284+ }
65285+
65286+ /* allocate log buffers */
65287+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
65288+ if (!gr_alert_log_fmt) {
65289+ panic("Unable to allocate grsecurity alert log format buffer");
65290+ return;
65291+ }
65292+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
65293+ if (!gr_audit_log_fmt) {
65294+ panic("Unable to allocate grsecurity audit log format buffer");
65295+ return;
65296+ }
65297+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65298+ if (!gr_alert_log_buf) {
65299+ panic("Unable to allocate grsecurity alert log buffer");
65300+ return;
65301+ }
65302+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65303+ if (!gr_audit_log_buf) {
65304+ panic("Unable to allocate grsecurity audit log buffer");
65305+ return;
65306+ }
65307+
65308+ /* allocate memory for authentication structure */
65309+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
65310+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
65311+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
65312+
65313+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
65314+ panic("Unable to allocate grsecurity authentication structure");
65315+ return;
65316+ }
65317+
65318+
65319+#ifdef CONFIG_GRKERNSEC_IO
65320+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
65321+ grsec_disable_privio = 1;
65322+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65323+ grsec_disable_privio = 1;
65324+#else
65325+ grsec_disable_privio = 0;
65326+#endif
65327+#endif
65328+
65329+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65330+ /* for backward compatibility, tpe_invert always defaults to on if
65331+ enabled in the kernel
65332+ */
65333+ grsec_enable_tpe_invert = 1;
65334+#endif
65335+
65336+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65337+#ifndef CONFIG_GRKERNSEC_SYSCTL
65338+ grsec_lock = 1;
65339+#endif
65340+
65341+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65342+ grsec_enable_audit_textrel = 1;
65343+#endif
65344+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65345+ grsec_enable_log_rwxmaps = 1;
65346+#endif
65347+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65348+ grsec_enable_group = 1;
65349+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
65350+#endif
65351+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65352+ grsec_enable_ptrace_readexec = 1;
65353+#endif
65354+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65355+ grsec_enable_chdir = 1;
65356+#endif
65357+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65358+ grsec_enable_harden_ptrace = 1;
65359+#endif
65360+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65361+ grsec_enable_mount = 1;
65362+#endif
65363+#ifdef CONFIG_GRKERNSEC_LINK
65364+ grsec_enable_link = 1;
65365+#endif
65366+#ifdef CONFIG_GRKERNSEC_BRUTE
65367+ grsec_enable_brute = 1;
65368+#endif
65369+#ifdef CONFIG_GRKERNSEC_DMESG
65370+ grsec_enable_dmesg = 1;
65371+#endif
65372+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65373+ grsec_enable_blackhole = 1;
65374+ grsec_lastack_retries = 4;
65375+#endif
65376+#ifdef CONFIG_GRKERNSEC_FIFO
65377+ grsec_enable_fifo = 1;
65378+#endif
65379+#ifdef CONFIG_GRKERNSEC_EXECLOG
65380+ grsec_enable_execlog = 1;
65381+#endif
65382+#ifdef CONFIG_GRKERNSEC_SETXID
65383+ grsec_enable_setxid = 1;
65384+#endif
65385+#ifdef CONFIG_GRKERNSEC_SIGNAL
65386+ grsec_enable_signal = 1;
65387+#endif
65388+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65389+ grsec_enable_forkfail = 1;
65390+#endif
65391+#ifdef CONFIG_GRKERNSEC_TIME
65392+ grsec_enable_time = 1;
65393+#endif
65394+#ifdef CONFIG_GRKERNSEC_RESLOG
65395+ grsec_resource_logging = 1;
65396+#endif
65397+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65398+ grsec_enable_chroot_findtask = 1;
65399+#endif
65400+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65401+ grsec_enable_chroot_unix = 1;
65402+#endif
65403+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65404+ grsec_enable_chroot_mount = 1;
65405+#endif
65406+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65407+ grsec_enable_chroot_fchdir = 1;
65408+#endif
65409+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65410+ grsec_enable_chroot_shmat = 1;
65411+#endif
65412+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65413+ grsec_enable_audit_ptrace = 1;
65414+#endif
65415+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65416+ grsec_enable_chroot_double = 1;
65417+#endif
65418+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65419+ grsec_enable_chroot_pivot = 1;
65420+#endif
65421+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65422+ grsec_enable_chroot_chdir = 1;
65423+#endif
65424+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65425+ grsec_enable_chroot_chmod = 1;
65426+#endif
65427+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65428+ grsec_enable_chroot_mknod = 1;
65429+#endif
65430+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65431+ grsec_enable_chroot_nice = 1;
65432+#endif
65433+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65434+ grsec_enable_chroot_execlog = 1;
65435+#endif
65436+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65437+ grsec_enable_chroot_caps = 1;
65438+#endif
65439+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65440+ grsec_enable_chroot_sysctl = 1;
65441+#endif
65442+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65443+ grsec_enable_symlinkown = 1;
65444+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
65445+#endif
65446+#ifdef CONFIG_GRKERNSEC_TPE
65447+ grsec_enable_tpe = 1;
65448+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
65449+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65450+ grsec_enable_tpe_all = 1;
65451+#endif
65452+#endif
65453+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65454+ grsec_enable_socket_all = 1;
65455+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
65456+#endif
65457+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65458+ grsec_enable_socket_client = 1;
65459+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
65460+#endif
65461+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65462+ grsec_enable_socket_server = 1;
65463+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
65464+#endif
65465+#endif
65466+
65467+ return;
65468+}
65469diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
65470new file mode 100644
65471index 0000000..5e05e20
65472--- /dev/null
65473+++ b/grsecurity/grsec_link.c
65474@@ -0,0 +1,58 @@
65475+#include <linux/kernel.h>
65476+#include <linux/sched.h>
65477+#include <linux/fs.h>
65478+#include <linux/file.h>
65479+#include <linux/grinternal.h>
65480+
65481+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
65482+{
65483+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65484+ const struct inode *link_inode = link->dentry->d_inode;
65485+
65486+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
65487+ /* ignore root-owned links, e.g. /proc/self */
65488+ gr_is_global_nonroot(link_inode->i_uid) && target &&
65489+ !uid_eq(link_inode->i_uid, target->i_uid)) {
65490+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
65491+ return 1;
65492+ }
65493+#endif
65494+ return 0;
65495+}
65496+
65497+int
65498+gr_handle_follow_link(const struct inode *parent,
65499+ const struct inode *inode,
65500+ const struct dentry *dentry, const struct vfsmount *mnt)
65501+{
65502+#ifdef CONFIG_GRKERNSEC_LINK
65503+ const struct cred *cred = current_cred();
65504+
65505+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
65506+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
65507+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
65508+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
65509+ return -EACCES;
65510+ }
65511+#endif
65512+ return 0;
65513+}
65514+
65515+int
65516+gr_handle_hardlink(const struct dentry *dentry,
65517+ const struct vfsmount *mnt,
65518+ struct inode *inode, const int mode, const struct filename *to)
65519+{
65520+#ifdef CONFIG_GRKERNSEC_LINK
65521+ const struct cred *cred = current_cred();
65522+
65523+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
65524+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
65525+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
65526+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
65527+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
65528+ return -EPERM;
65529+ }
65530+#endif
65531+ return 0;
65532+}
65533diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
65534new file mode 100644
65535index 0000000..7c06085
65536--- /dev/null
65537+++ b/grsecurity/grsec_log.c
65538@@ -0,0 +1,326 @@
65539+#include <linux/kernel.h>
65540+#include <linux/sched.h>
65541+#include <linux/file.h>
65542+#include <linux/tty.h>
65543+#include <linux/fs.h>
65544+#include <linux/grinternal.h>
65545+
65546+#ifdef CONFIG_TREE_PREEMPT_RCU
65547+#define DISABLE_PREEMPT() preempt_disable()
65548+#define ENABLE_PREEMPT() preempt_enable()
65549+#else
65550+#define DISABLE_PREEMPT()
65551+#define ENABLE_PREEMPT()
65552+#endif
65553+
65554+#define BEGIN_LOCKS(x) \
65555+ DISABLE_PREEMPT(); \
65556+ rcu_read_lock(); \
65557+ read_lock(&tasklist_lock); \
65558+ read_lock(&grsec_exec_file_lock); \
65559+ if (x != GR_DO_AUDIT) \
65560+ spin_lock(&grsec_alert_lock); \
65561+ else \
65562+ spin_lock(&grsec_audit_lock)
65563+
65564+#define END_LOCKS(x) \
65565+ if (x != GR_DO_AUDIT) \
65566+ spin_unlock(&grsec_alert_lock); \
65567+ else \
65568+ spin_unlock(&grsec_audit_lock); \
65569+ read_unlock(&grsec_exec_file_lock); \
65570+ read_unlock(&tasklist_lock); \
65571+ rcu_read_unlock(); \
65572+ ENABLE_PREEMPT(); \
65573+ if (x == GR_DONT_AUDIT) \
65574+ gr_handle_alertkill(current)
65575+
65576+enum {
65577+ FLOODING,
65578+ NO_FLOODING
65579+};
65580+
65581+extern char *gr_alert_log_fmt;
65582+extern char *gr_audit_log_fmt;
65583+extern char *gr_alert_log_buf;
65584+extern char *gr_audit_log_buf;
65585+
65586+static int gr_log_start(int audit)
65587+{
65588+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
65589+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
65590+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65591+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
65592+ unsigned long curr_secs = get_seconds();
65593+
65594+ if (audit == GR_DO_AUDIT)
65595+ goto set_fmt;
65596+
65597+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
65598+ grsec_alert_wtime = curr_secs;
65599+ grsec_alert_fyet = 0;
65600+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
65601+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
65602+ grsec_alert_fyet++;
65603+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
65604+ grsec_alert_wtime = curr_secs;
65605+ grsec_alert_fyet++;
65606+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
65607+ return FLOODING;
65608+ }
65609+ else return FLOODING;
65610+
65611+set_fmt:
65612+#endif
65613+ memset(buf, 0, PAGE_SIZE);
65614+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
65615+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
65616+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65617+ } else if (current->signal->curr_ip) {
65618+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
65619+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
65620+ } else if (gr_acl_is_enabled()) {
65621+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
65622+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65623+ } else {
65624+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
65625+ strcpy(buf, fmt);
65626+ }
65627+
65628+ return NO_FLOODING;
65629+}
65630+
65631+static void gr_log_middle(int audit, const char *msg, va_list ap)
65632+ __attribute__ ((format (printf, 2, 0)));
65633+
65634+static void gr_log_middle(int audit, const char *msg, va_list ap)
65635+{
65636+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65637+ unsigned int len = strlen(buf);
65638+
65639+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65640+
65641+ return;
65642+}
65643+
65644+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65645+ __attribute__ ((format (printf, 2, 3)));
65646+
65647+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65648+{
65649+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65650+ unsigned int len = strlen(buf);
65651+ va_list ap;
65652+
65653+ va_start(ap, msg);
65654+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65655+ va_end(ap);
65656+
65657+ return;
65658+}
65659+
65660+static void gr_log_end(int audit, int append_default)
65661+{
65662+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65663+ if (append_default) {
65664+ struct task_struct *task = current;
65665+ struct task_struct *parent = task->real_parent;
65666+ const struct cred *cred = __task_cred(task);
65667+ const struct cred *pcred = __task_cred(parent);
65668+ unsigned int len = strlen(buf);
65669+
65670+ 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));
65671+ }
65672+
65673+ printk("%s\n", buf);
65674+
65675+ return;
65676+}
65677+
65678+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
65679+{
65680+ int logtype;
65681+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
65682+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
65683+ void *voidptr = NULL;
65684+ int num1 = 0, num2 = 0;
65685+ unsigned long ulong1 = 0, ulong2 = 0;
65686+ struct dentry *dentry = NULL;
65687+ struct vfsmount *mnt = NULL;
65688+ struct file *file = NULL;
65689+ struct task_struct *task = NULL;
65690+ const struct cred *cred, *pcred;
65691+ va_list ap;
65692+
65693+ BEGIN_LOCKS(audit);
65694+ logtype = gr_log_start(audit);
65695+ if (logtype == FLOODING) {
65696+ END_LOCKS(audit);
65697+ return;
65698+ }
65699+ va_start(ap, argtypes);
65700+ switch (argtypes) {
65701+ case GR_TTYSNIFF:
65702+ task = va_arg(ap, struct task_struct *);
65703+ 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));
65704+ break;
65705+ case GR_SYSCTL_HIDDEN:
65706+ str1 = va_arg(ap, char *);
65707+ gr_log_middle_varargs(audit, msg, result, str1);
65708+ break;
65709+ case GR_RBAC:
65710+ dentry = va_arg(ap, struct dentry *);
65711+ mnt = va_arg(ap, struct vfsmount *);
65712+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
65713+ break;
65714+ case GR_RBAC_STR:
65715+ dentry = va_arg(ap, struct dentry *);
65716+ mnt = va_arg(ap, struct vfsmount *);
65717+ str1 = va_arg(ap, char *);
65718+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
65719+ break;
65720+ case GR_STR_RBAC:
65721+ str1 = va_arg(ap, char *);
65722+ dentry = va_arg(ap, struct dentry *);
65723+ mnt = va_arg(ap, struct vfsmount *);
65724+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
65725+ break;
65726+ case GR_RBAC_MODE2:
65727+ dentry = va_arg(ap, struct dentry *);
65728+ mnt = va_arg(ap, struct vfsmount *);
65729+ str1 = va_arg(ap, char *);
65730+ str2 = va_arg(ap, char *);
65731+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
65732+ break;
65733+ case GR_RBAC_MODE3:
65734+ dentry = va_arg(ap, struct dentry *);
65735+ mnt = va_arg(ap, struct vfsmount *);
65736+ str1 = va_arg(ap, char *);
65737+ str2 = va_arg(ap, char *);
65738+ str3 = va_arg(ap, char *);
65739+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
65740+ break;
65741+ case GR_FILENAME:
65742+ dentry = va_arg(ap, struct dentry *);
65743+ mnt = va_arg(ap, struct vfsmount *);
65744+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
65745+ break;
65746+ case GR_STR_FILENAME:
65747+ str1 = va_arg(ap, char *);
65748+ dentry = va_arg(ap, struct dentry *);
65749+ mnt = va_arg(ap, struct vfsmount *);
65750+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
65751+ break;
65752+ case GR_FILENAME_STR:
65753+ dentry = va_arg(ap, struct dentry *);
65754+ mnt = va_arg(ap, struct vfsmount *);
65755+ str1 = va_arg(ap, char *);
65756+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
65757+ break;
65758+ case GR_FILENAME_TWO_INT:
65759+ dentry = va_arg(ap, struct dentry *);
65760+ mnt = va_arg(ap, struct vfsmount *);
65761+ num1 = va_arg(ap, int);
65762+ num2 = va_arg(ap, int);
65763+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
65764+ break;
65765+ case GR_FILENAME_TWO_INT_STR:
65766+ dentry = va_arg(ap, struct dentry *);
65767+ mnt = va_arg(ap, struct vfsmount *);
65768+ num1 = va_arg(ap, int);
65769+ num2 = va_arg(ap, int);
65770+ str1 = va_arg(ap, char *);
65771+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
65772+ break;
65773+ case GR_TEXTREL:
65774+ file = va_arg(ap, struct file *);
65775+ ulong1 = va_arg(ap, unsigned long);
65776+ ulong2 = va_arg(ap, unsigned long);
65777+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
65778+ break;
65779+ case GR_PTRACE:
65780+ task = va_arg(ap, struct task_struct *);
65781+ 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));
65782+ break;
65783+ case GR_RESOURCE:
65784+ task = va_arg(ap, struct task_struct *);
65785+ cred = __task_cred(task);
65786+ pcred = __task_cred(task->real_parent);
65787+ ulong1 = va_arg(ap, unsigned long);
65788+ str1 = va_arg(ap, char *);
65789+ ulong2 = va_arg(ap, unsigned long);
65790+ 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));
65791+ break;
65792+ case GR_CAP:
65793+ task = va_arg(ap, struct task_struct *);
65794+ cred = __task_cred(task);
65795+ pcred = __task_cred(task->real_parent);
65796+ str1 = va_arg(ap, char *);
65797+ 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));
65798+ break;
65799+ case GR_SIG:
65800+ str1 = va_arg(ap, char *);
65801+ voidptr = va_arg(ap, void *);
65802+ gr_log_middle_varargs(audit, msg, str1, voidptr);
65803+ break;
65804+ case GR_SIG2:
65805+ task = va_arg(ap, struct task_struct *);
65806+ cred = __task_cred(task);
65807+ pcred = __task_cred(task->real_parent);
65808+ num1 = va_arg(ap, int);
65809+ 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));
65810+ break;
65811+ case GR_CRASH1:
65812+ task = va_arg(ap, struct task_struct *);
65813+ cred = __task_cred(task);
65814+ pcred = __task_cred(task->real_parent);
65815+ ulong1 = va_arg(ap, unsigned long);
65816+ 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);
65817+ break;
65818+ case GR_CRASH2:
65819+ task = va_arg(ap, struct task_struct *);
65820+ cred = __task_cred(task);
65821+ pcred = __task_cred(task->real_parent);
65822+ ulong1 = va_arg(ap, unsigned long);
65823+ 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);
65824+ break;
65825+ case GR_RWXMAP:
65826+ file = va_arg(ap, struct file *);
65827+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
65828+ break;
65829+ case GR_PSACCT:
65830+ {
65831+ unsigned int wday, cday;
65832+ __u8 whr, chr;
65833+ __u8 wmin, cmin;
65834+ __u8 wsec, csec;
65835+ char cur_tty[64] = { 0 };
65836+ char parent_tty[64] = { 0 };
65837+
65838+ task = va_arg(ap, struct task_struct *);
65839+ wday = va_arg(ap, unsigned int);
65840+ cday = va_arg(ap, unsigned int);
65841+ whr = va_arg(ap, int);
65842+ chr = va_arg(ap, int);
65843+ wmin = va_arg(ap, int);
65844+ cmin = va_arg(ap, int);
65845+ wsec = va_arg(ap, int);
65846+ csec = va_arg(ap, int);
65847+ ulong1 = va_arg(ap, unsigned long);
65848+ cred = __task_cred(task);
65849+ pcred = __task_cred(task->real_parent);
65850+
65851+ 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));
65852+ }
65853+ break;
65854+ default:
65855+ gr_log_middle(audit, msg, ap);
65856+ }
65857+ va_end(ap);
65858+ // these don't need DEFAULTSECARGS printed on the end
65859+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
65860+ gr_log_end(audit, 0);
65861+ else
65862+ gr_log_end(audit, 1);
65863+ END_LOCKS(audit);
65864+}
65865diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
65866new file mode 100644
65867index 0000000..f536303
65868--- /dev/null
65869+++ b/grsecurity/grsec_mem.c
65870@@ -0,0 +1,40 @@
65871+#include <linux/kernel.h>
65872+#include <linux/sched.h>
65873+#include <linux/mm.h>
65874+#include <linux/mman.h>
65875+#include <linux/grinternal.h>
65876+
65877+void
65878+gr_handle_ioperm(void)
65879+{
65880+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
65881+ return;
65882+}
65883+
65884+void
65885+gr_handle_iopl(void)
65886+{
65887+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
65888+ return;
65889+}
65890+
65891+void
65892+gr_handle_mem_readwrite(u64 from, u64 to)
65893+{
65894+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
65895+ return;
65896+}
65897+
65898+void
65899+gr_handle_vm86(void)
65900+{
65901+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
65902+ return;
65903+}
65904+
65905+void
65906+gr_log_badprocpid(const char *entry)
65907+{
65908+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
65909+ return;
65910+}
65911diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
65912new file mode 100644
65913index 0000000..2131422
65914--- /dev/null
65915+++ b/grsecurity/grsec_mount.c
65916@@ -0,0 +1,62 @@
65917+#include <linux/kernel.h>
65918+#include <linux/sched.h>
65919+#include <linux/mount.h>
65920+#include <linux/grsecurity.h>
65921+#include <linux/grinternal.h>
65922+
65923+void
65924+gr_log_remount(const char *devname, const int retval)
65925+{
65926+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65927+ if (grsec_enable_mount && (retval >= 0))
65928+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
65929+#endif
65930+ return;
65931+}
65932+
65933+void
65934+gr_log_unmount(const char *devname, const int retval)
65935+{
65936+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65937+ if (grsec_enable_mount && (retval >= 0))
65938+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
65939+#endif
65940+ return;
65941+}
65942+
65943+void
65944+gr_log_mount(const char *from, const char *to, const int retval)
65945+{
65946+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65947+ if (grsec_enable_mount && (retval >= 0))
65948+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
65949+#endif
65950+ return;
65951+}
65952+
65953+int
65954+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
65955+{
65956+#ifdef CONFIG_GRKERNSEC_ROFS
65957+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
65958+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
65959+ return -EPERM;
65960+ } else
65961+ return 0;
65962+#endif
65963+ return 0;
65964+}
65965+
65966+int
65967+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
65968+{
65969+#ifdef CONFIG_GRKERNSEC_ROFS
65970+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
65971+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
65972+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
65973+ return -EPERM;
65974+ } else
65975+ return 0;
65976+#endif
65977+ return 0;
65978+}
65979diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
65980new file mode 100644
65981index 0000000..a3b12a0
65982--- /dev/null
65983+++ b/grsecurity/grsec_pax.c
65984@@ -0,0 +1,36 @@
65985+#include <linux/kernel.h>
65986+#include <linux/sched.h>
65987+#include <linux/mm.h>
65988+#include <linux/file.h>
65989+#include <linux/grinternal.h>
65990+#include <linux/grsecurity.h>
65991+
65992+void
65993+gr_log_textrel(struct vm_area_struct * vma)
65994+{
65995+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65996+ if (grsec_enable_audit_textrel)
65997+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
65998+#endif
65999+ return;
66000+}
66001+
66002+void
66003+gr_log_rwxmmap(struct file *file)
66004+{
66005+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66006+ if (grsec_enable_log_rwxmaps)
66007+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
66008+#endif
66009+ return;
66010+}
66011+
66012+void
66013+gr_log_rwxmprotect(struct file *file)
66014+{
66015+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66016+ if (grsec_enable_log_rwxmaps)
66017+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
66018+#endif
66019+ return;
66020+}
66021diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
66022new file mode 100644
66023index 0000000..f7f29aa
66024--- /dev/null
66025+++ b/grsecurity/grsec_ptrace.c
66026@@ -0,0 +1,30 @@
66027+#include <linux/kernel.h>
66028+#include <linux/sched.h>
66029+#include <linux/grinternal.h>
66030+#include <linux/security.h>
66031+
66032+void
66033+gr_audit_ptrace(struct task_struct *task)
66034+{
66035+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66036+ if (grsec_enable_audit_ptrace)
66037+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
66038+#endif
66039+ return;
66040+}
66041+
66042+int
66043+gr_ptrace_readexec(struct file *file, int unsafe_flags)
66044+{
66045+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66046+ const struct dentry *dentry = file->f_path.dentry;
66047+ const struct vfsmount *mnt = file->f_path.mnt;
66048+
66049+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
66050+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
66051+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
66052+ return -EACCES;
66053+ }
66054+#endif
66055+ return 0;
66056+}
66057diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
66058new file mode 100644
66059index 0000000..4e29cc7
66060--- /dev/null
66061+++ b/grsecurity/grsec_sig.c
66062@@ -0,0 +1,246 @@
66063+#include <linux/kernel.h>
66064+#include <linux/sched.h>
66065+#include <linux/fs.h>
66066+#include <linux/delay.h>
66067+#include <linux/grsecurity.h>
66068+#include <linux/grinternal.h>
66069+#include <linux/hardirq.h>
66070+
66071+char *signames[] = {
66072+ [SIGSEGV] = "Segmentation fault",
66073+ [SIGILL] = "Illegal instruction",
66074+ [SIGABRT] = "Abort",
66075+ [SIGBUS] = "Invalid alignment/Bus error"
66076+};
66077+
66078+void
66079+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
66080+{
66081+#ifdef CONFIG_GRKERNSEC_SIGNAL
66082+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
66083+ (sig == SIGABRT) || (sig == SIGBUS))) {
66084+ if (task_pid_nr(t) == task_pid_nr(current)) {
66085+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
66086+ } else {
66087+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
66088+ }
66089+ }
66090+#endif
66091+ return;
66092+}
66093+
66094+int
66095+gr_handle_signal(const struct task_struct *p, const int sig)
66096+{
66097+#ifdef CONFIG_GRKERNSEC
66098+ /* ignore the 0 signal for protected task checks */
66099+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
66100+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
66101+ return -EPERM;
66102+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
66103+ return -EPERM;
66104+ }
66105+#endif
66106+ return 0;
66107+}
66108+
66109+#ifdef CONFIG_GRKERNSEC
66110+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
66111+
66112+int gr_fake_force_sig(int sig, struct task_struct *t)
66113+{
66114+ unsigned long int flags;
66115+ int ret, blocked, ignored;
66116+ struct k_sigaction *action;
66117+
66118+ spin_lock_irqsave(&t->sighand->siglock, flags);
66119+ action = &t->sighand->action[sig-1];
66120+ ignored = action->sa.sa_handler == SIG_IGN;
66121+ blocked = sigismember(&t->blocked, sig);
66122+ if (blocked || ignored) {
66123+ action->sa.sa_handler = SIG_DFL;
66124+ if (blocked) {
66125+ sigdelset(&t->blocked, sig);
66126+ recalc_sigpending_and_wake(t);
66127+ }
66128+ }
66129+ if (action->sa.sa_handler == SIG_DFL)
66130+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
66131+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
66132+
66133+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
66134+
66135+ return ret;
66136+}
66137+#endif
66138+
66139+#ifdef CONFIG_GRKERNSEC_BRUTE
66140+#define GR_USER_BAN_TIME (15 * 60)
66141+#define GR_DAEMON_BRUTE_TIME (30 * 60)
66142+
66143+static int __get_dumpable(unsigned long mm_flags)
66144+{
66145+ int ret;
66146+
66147+ ret = mm_flags & MMF_DUMPABLE_MASK;
66148+ return (ret >= 2) ? 2 : ret;
66149+}
66150+#endif
66151+
66152+void gr_handle_brute_attach(unsigned long mm_flags)
66153+{
66154+#ifdef CONFIG_GRKERNSEC_BRUTE
66155+ struct task_struct *p = current;
66156+ kuid_t uid = GLOBAL_ROOT_UID;
66157+ int daemon = 0;
66158+
66159+ if (!grsec_enable_brute)
66160+ return;
66161+
66162+ rcu_read_lock();
66163+ read_lock(&tasklist_lock);
66164+ read_lock(&grsec_exec_file_lock);
66165+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
66166+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
66167+ p->real_parent->brute = 1;
66168+ daemon = 1;
66169+ } else {
66170+ const struct cred *cred = __task_cred(p), *cred2;
66171+ struct task_struct *tsk, *tsk2;
66172+
66173+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
66174+ struct user_struct *user;
66175+
66176+ uid = cred->uid;
66177+
66178+ /* this is put upon execution past expiration */
66179+ user = find_user(uid);
66180+ if (user == NULL)
66181+ goto unlock;
66182+ user->suid_banned = 1;
66183+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
66184+ if (user->suid_ban_expires == ~0UL)
66185+ user->suid_ban_expires--;
66186+
66187+ /* only kill other threads of the same binary, from the same user */
66188+ do_each_thread(tsk2, tsk) {
66189+ cred2 = __task_cred(tsk);
66190+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
66191+ gr_fake_force_sig(SIGKILL, tsk);
66192+ } while_each_thread(tsk2, tsk);
66193+ }
66194+ }
66195+unlock:
66196+ read_unlock(&grsec_exec_file_lock);
66197+ read_unlock(&tasklist_lock);
66198+ rcu_read_unlock();
66199+
66200+ if (gr_is_global_nonroot(uid))
66201+ 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);
66202+ else if (daemon)
66203+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
66204+
66205+#endif
66206+ return;
66207+}
66208+
66209+void gr_handle_brute_check(void)
66210+{
66211+#ifdef CONFIG_GRKERNSEC_BRUTE
66212+ struct task_struct *p = current;
66213+
66214+ if (unlikely(p->brute)) {
66215+ if (!grsec_enable_brute)
66216+ p->brute = 0;
66217+ else if (time_before(get_seconds(), p->brute_expires))
66218+ msleep(30 * 1000);
66219+ }
66220+#endif
66221+ return;
66222+}
66223+
66224+void gr_handle_kernel_exploit(void)
66225+{
66226+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66227+ const struct cred *cred;
66228+ struct task_struct *tsk, *tsk2;
66229+ struct user_struct *user;
66230+ kuid_t uid;
66231+
66232+ if (in_irq() || in_serving_softirq() || in_nmi())
66233+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
66234+
66235+ uid = current_uid();
66236+
66237+ if (gr_is_global_root(uid))
66238+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
66239+ else {
66240+ /* kill all the processes of this user, hold a reference
66241+ to their creds struct, and prevent them from creating
66242+ another process until system reset
66243+ */
66244+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
66245+ GR_GLOBAL_UID(uid));
66246+ /* we intentionally leak this ref */
66247+ user = get_uid(current->cred->user);
66248+ if (user)
66249+ user->kernel_banned = 1;
66250+
66251+ /* kill all processes of this user */
66252+ read_lock(&tasklist_lock);
66253+ do_each_thread(tsk2, tsk) {
66254+ cred = __task_cred(tsk);
66255+ if (uid_eq(cred->uid, uid))
66256+ gr_fake_force_sig(SIGKILL, tsk);
66257+ } while_each_thread(tsk2, tsk);
66258+ read_unlock(&tasklist_lock);
66259+ }
66260+#endif
66261+}
66262+
66263+#ifdef CONFIG_GRKERNSEC_BRUTE
66264+static bool suid_ban_expired(struct user_struct *user)
66265+{
66266+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
66267+ user->suid_banned = 0;
66268+ user->suid_ban_expires = 0;
66269+ free_uid(user);
66270+ return true;
66271+ }
66272+
66273+ return false;
66274+}
66275+#endif
66276+
66277+int gr_process_kernel_exec_ban(void)
66278+{
66279+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66280+ if (unlikely(current->cred->user->kernel_banned))
66281+ return -EPERM;
66282+#endif
66283+ return 0;
66284+}
66285+
66286+int gr_process_kernel_setuid_ban(struct user_struct *user)
66287+{
66288+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66289+ if (unlikely(user->kernel_banned))
66290+ gr_fake_force_sig(SIGKILL, current);
66291+#endif
66292+ return 0;
66293+}
66294+
66295+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
66296+{
66297+#ifdef CONFIG_GRKERNSEC_BRUTE
66298+ struct user_struct *user = current->cred->user;
66299+ if (unlikely(user->suid_banned)) {
66300+ if (suid_ban_expired(user))
66301+ return 0;
66302+ /* disallow execution of suid binaries only */
66303+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
66304+ return -EPERM;
66305+ }
66306+#endif
66307+ return 0;
66308+}
66309diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
66310new file mode 100644
66311index 0000000..4030d57
66312--- /dev/null
66313+++ b/grsecurity/grsec_sock.c
66314@@ -0,0 +1,244 @@
66315+#include <linux/kernel.h>
66316+#include <linux/module.h>
66317+#include <linux/sched.h>
66318+#include <linux/file.h>
66319+#include <linux/net.h>
66320+#include <linux/in.h>
66321+#include <linux/ip.h>
66322+#include <net/sock.h>
66323+#include <net/inet_sock.h>
66324+#include <linux/grsecurity.h>
66325+#include <linux/grinternal.h>
66326+#include <linux/gracl.h>
66327+
66328+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
66329+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
66330+
66331+EXPORT_SYMBOL(gr_search_udp_recvmsg);
66332+EXPORT_SYMBOL(gr_search_udp_sendmsg);
66333+
66334+#ifdef CONFIG_UNIX_MODULE
66335+EXPORT_SYMBOL(gr_acl_handle_unix);
66336+EXPORT_SYMBOL(gr_acl_handle_mknod);
66337+EXPORT_SYMBOL(gr_handle_chroot_unix);
66338+EXPORT_SYMBOL(gr_handle_create);
66339+#endif
66340+
66341+#ifdef CONFIG_GRKERNSEC
66342+#define gr_conn_table_size 32749
66343+struct conn_table_entry {
66344+ struct conn_table_entry *next;
66345+ struct signal_struct *sig;
66346+};
66347+
66348+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
66349+DEFINE_SPINLOCK(gr_conn_table_lock);
66350+
66351+extern const char * gr_socktype_to_name(unsigned char type);
66352+extern const char * gr_proto_to_name(unsigned char proto);
66353+extern const char * gr_sockfamily_to_name(unsigned char family);
66354+
66355+static __inline__ int
66356+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
66357+{
66358+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
66359+}
66360+
66361+static __inline__ int
66362+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
66363+ __u16 sport, __u16 dport)
66364+{
66365+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
66366+ sig->gr_sport == sport && sig->gr_dport == dport))
66367+ return 1;
66368+ else
66369+ return 0;
66370+}
66371+
66372+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
66373+{
66374+ struct conn_table_entry **match;
66375+ unsigned int index;
66376+
66377+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66378+ sig->gr_sport, sig->gr_dport,
66379+ gr_conn_table_size);
66380+
66381+ newent->sig = sig;
66382+
66383+ match = &gr_conn_table[index];
66384+ newent->next = *match;
66385+ *match = newent;
66386+
66387+ return;
66388+}
66389+
66390+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
66391+{
66392+ struct conn_table_entry *match, *last = NULL;
66393+ unsigned int index;
66394+
66395+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66396+ sig->gr_sport, sig->gr_dport,
66397+ gr_conn_table_size);
66398+
66399+ match = gr_conn_table[index];
66400+ while (match && !conn_match(match->sig,
66401+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
66402+ sig->gr_dport)) {
66403+ last = match;
66404+ match = match->next;
66405+ }
66406+
66407+ if (match) {
66408+ if (last)
66409+ last->next = match->next;
66410+ else
66411+ gr_conn_table[index] = NULL;
66412+ kfree(match);
66413+ }
66414+
66415+ return;
66416+}
66417+
66418+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
66419+ __u16 sport, __u16 dport)
66420+{
66421+ struct conn_table_entry *match;
66422+ unsigned int index;
66423+
66424+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
66425+
66426+ match = gr_conn_table[index];
66427+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
66428+ match = match->next;
66429+
66430+ if (match)
66431+ return match->sig;
66432+ else
66433+ return NULL;
66434+}
66435+
66436+#endif
66437+
66438+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
66439+{
66440+#ifdef CONFIG_GRKERNSEC
66441+ struct signal_struct *sig = task->signal;
66442+ struct conn_table_entry *newent;
66443+
66444+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
66445+ if (newent == NULL)
66446+ return;
66447+ /* no bh lock needed since we are called with bh disabled */
66448+ spin_lock(&gr_conn_table_lock);
66449+ gr_del_task_from_ip_table_nolock(sig);
66450+ sig->gr_saddr = inet->inet_rcv_saddr;
66451+ sig->gr_daddr = inet->inet_daddr;
66452+ sig->gr_sport = inet->inet_sport;
66453+ sig->gr_dport = inet->inet_dport;
66454+ gr_add_to_task_ip_table_nolock(sig, newent);
66455+ spin_unlock(&gr_conn_table_lock);
66456+#endif
66457+ return;
66458+}
66459+
66460+void gr_del_task_from_ip_table(struct task_struct *task)
66461+{
66462+#ifdef CONFIG_GRKERNSEC
66463+ spin_lock_bh(&gr_conn_table_lock);
66464+ gr_del_task_from_ip_table_nolock(task->signal);
66465+ spin_unlock_bh(&gr_conn_table_lock);
66466+#endif
66467+ return;
66468+}
66469+
66470+void
66471+gr_attach_curr_ip(const struct sock *sk)
66472+{
66473+#ifdef CONFIG_GRKERNSEC
66474+ struct signal_struct *p, *set;
66475+ const struct inet_sock *inet = inet_sk(sk);
66476+
66477+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
66478+ return;
66479+
66480+ set = current->signal;
66481+
66482+ spin_lock_bh(&gr_conn_table_lock);
66483+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
66484+ inet->inet_dport, inet->inet_sport);
66485+ if (unlikely(p != NULL)) {
66486+ set->curr_ip = p->curr_ip;
66487+ set->used_accept = 1;
66488+ gr_del_task_from_ip_table_nolock(p);
66489+ spin_unlock_bh(&gr_conn_table_lock);
66490+ return;
66491+ }
66492+ spin_unlock_bh(&gr_conn_table_lock);
66493+
66494+ set->curr_ip = inet->inet_daddr;
66495+ set->used_accept = 1;
66496+#endif
66497+ return;
66498+}
66499+
66500+int
66501+gr_handle_sock_all(const int family, const int type, const int protocol)
66502+{
66503+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66504+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
66505+ (family != AF_UNIX)) {
66506+ if (family == AF_INET)
66507+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
66508+ else
66509+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
66510+ return -EACCES;
66511+ }
66512+#endif
66513+ return 0;
66514+}
66515+
66516+int
66517+gr_handle_sock_server(const struct sockaddr *sck)
66518+{
66519+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66520+ if (grsec_enable_socket_server &&
66521+ in_group_p(grsec_socket_server_gid) &&
66522+ sck && (sck->sa_family != AF_UNIX) &&
66523+ (sck->sa_family != AF_LOCAL)) {
66524+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66525+ return -EACCES;
66526+ }
66527+#endif
66528+ return 0;
66529+}
66530+
66531+int
66532+gr_handle_sock_server_other(const struct sock *sck)
66533+{
66534+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66535+ if (grsec_enable_socket_server &&
66536+ in_group_p(grsec_socket_server_gid) &&
66537+ sck && (sck->sk_family != AF_UNIX) &&
66538+ (sck->sk_family != AF_LOCAL)) {
66539+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66540+ return -EACCES;
66541+ }
66542+#endif
66543+ return 0;
66544+}
66545+
66546+int
66547+gr_handle_sock_client(const struct sockaddr *sck)
66548+{
66549+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66550+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
66551+ sck && (sck->sa_family != AF_UNIX) &&
66552+ (sck->sa_family != AF_LOCAL)) {
66553+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
66554+ return -EACCES;
66555+ }
66556+#endif
66557+ return 0;
66558+}
66559diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
66560new file mode 100644
66561index 0000000..f55ef0f
66562--- /dev/null
66563+++ b/grsecurity/grsec_sysctl.c
66564@@ -0,0 +1,469 @@
66565+#include <linux/kernel.h>
66566+#include <linux/sched.h>
66567+#include <linux/sysctl.h>
66568+#include <linux/grsecurity.h>
66569+#include <linux/grinternal.h>
66570+
66571+int
66572+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
66573+{
66574+#ifdef CONFIG_GRKERNSEC_SYSCTL
66575+ if (dirname == NULL || name == NULL)
66576+ return 0;
66577+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
66578+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
66579+ return -EACCES;
66580+ }
66581+#endif
66582+ return 0;
66583+}
66584+
66585+#ifdef CONFIG_GRKERNSEC_ROFS
66586+static int __maybe_unused one = 1;
66587+#endif
66588+
66589+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66590+struct ctl_table grsecurity_table[] = {
66591+#ifdef CONFIG_GRKERNSEC_SYSCTL
66592+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
66593+#ifdef CONFIG_GRKERNSEC_IO
66594+ {
66595+ .procname = "disable_priv_io",
66596+ .data = &grsec_disable_privio,
66597+ .maxlen = sizeof(int),
66598+ .mode = 0600,
66599+ .proc_handler = &proc_dointvec,
66600+ },
66601+#endif
66602+#endif
66603+#ifdef CONFIG_GRKERNSEC_LINK
66604+ {
66605+ .procname = "linking_restrictions",
66606+ .data = &grsec_enable_link,
66607+ .maxlen = sizeof(int),
66608+ .mode = 0600,
66609+ .proc_handler = &proc_dointvec,
66610+ },
66611+#endif
66612+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
66613+ {
66614+ .procname = "enforce_symlinksifowner",
66615+ .data = &grsec_enable_symlinkown,
66616+ .maxlen = sizeof(int),
66617+ .mode = 0600,
66618+ .proc_handler = &proc_dointvec,
66619+ },
66620+ {
66621+ .procname = "symlinkown_gid",
66622+ .data = &grsec_symlinkown_gid,
66623+ .maxlen = sizeof(int),
66624+ .mode = 0600,
66625+ .proc_handler = &proc_dointvec,
66626+ },
66627+#endif
66628+#ifdef CONFIG_GRKERNSEC_BRUTE
66629+ {
66630+ .procname = "deter_bruteforce",
66631+ .data = &grsec_enable_brute,
66632+ .maxlen = sizeof(int),
66633+ .mode = 0600,
66634+ .proc_handler = &proc_dointvec,
66635+ },
66636+#endif
66637+#ifdef CONFIG_GRKERNSEC_FIFO
66638+ {
66639+ .procname = "fifo_restrictions",
66640+ .data = &grsec_enable_fifo,
66641+ .maxlen = sizeof(int),
66642+ .mode = 0600,
66643+ .proc_handler = &proc_dointvec,
66644+ },
66645+#endif
66646+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66647+ {
66648+ .procname = "ptrace_readexec",
66649+ .data = &grsec_enable_ptrace_readexec,
66650+ .maxlen = sizeof(int),
66651+ .mode = 0600,
66652+ .proc_handler = &proc_dointvec,
66653+ },
66654+#endif
66655+#ifdef CONFIG_GRKERNSEC_SETXID
66656+ {
66657+ .procname = "consistent_setxid",
66658+ .data = &grsec_enable_setxid,
66659+ .maxlen = sizeof(int),
66660+ .mode = 0600,
66661+ .proc_handler = &proc_dointvec,
66662+ },
66663+#endif
66664+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
66665+ {
66666+ .procname = "ip_blackhole",
66667+ .data = &grsec_enable_blackhole,
66668+ .maxlen = sizeof(int),
66669+ .mode = 0600,
66670+ .proc_handler = &proc_dointvec,
66671+ },
66672+ {
66673+ .procname = "lastack_retries",
66674+ .data = &grsec_lastack_retries,
66675+ .maxlen = sizeof(int),
66676+ .mode = 0600,
66677+ .proc_handler = &proc_dointvec,
66678+ },
66679+#endif
66680+#ifdef CONFIG_GRKERNSEC_EXECLOG
66681+ {
66682+ .procname = "exec_logging",
66683+ .data = &grsec_enable_execlog,
66684+ .maxlen = sizeof(int),
66685+ .mode = 0600,
66686+ .proc_handler = &proc_dointvec,
66687+ },
66688+#endif
66689+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66690+ {
66691+ .procname = "rwxmap_logging",
66692+ .data = &grsec_enable_log_rwxmaps,
66693+ .maxlen = sizeof(int),
66694+ .mode = 0600,
66695+ .proc_handler = &proc_dointvec,
66696+ },
66697+#endif
66698+#ifdef CONFIG_GRKERNSEC_SIGNAL
66699+ {
66700+ .procname = "signal_logging",
66701+ .data = &grsec_enable_signal,
66702+ .maxlen = sizeof(int),
66703+ .mode = 0600,
66704+ .proc_handler = &proc_dointvec,
66705+ },
66706+#endif
66707+#ifdef CONFIG_GRKERNSEC_FORKFAIL
66708+ {
66709+ .procname = "forkfail_logging",
66710+ .data = &grsec_enable_forkfail,
66711+ .maxlen = sizeof(int),
66712+ .mode = 0600,
66713+ .proc_handler = &proc_dointvec,
66714+ },
66715+#endif
66716+#ifdef CONFIG_GRKERNSEC_TIME
66717+ {
66718+ .procname = "timechange_logging",
66719+ .data = &grsec_enable_time,
66720+ .maxlen = sizeof(int),
66721+ .mode = 0600,
66722+ .proc_handler = &proc_dointvec,
66723+ },
66724+#endif
66725+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
66726+ {
66727+ .procname = "chroot_deny_shmat",
66728+ .data = &grsec_enable_chroot_shmat,
66729+ .maxlen = sizeof(int),
66730+ .mode = 0600,
66731+ .proc_handler = &proc_dointvec,
66732+ },
66733+#endif
66734+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
66735+ {
66736+ .procname = "chroot_deny_unix",
66737+ .data = &grsec_enable_chroot_unix,
66738+ .maxlen = sizeof(int),
66739+ .mode = 0600,
66740+ .proc_handler = &proc_dointvec,
66741+ },
66742+#endif
66743+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
66744+ {
66745+ .procname = "chroot_deny_mount",
66746+ .data = &grsec_enable_chroot_mount,
66747+ .maxlen = sizeof(int),
66748+ .mode = 0600,
66749+ .proc_handler = &proc_dointvec,
66750+ },
66751+#endif
66752+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
66753+ {
66754+ .procname = "chroot_deny_fchdir",
66755+ .data = &grsec_enable_chroot_fchdir,
66756+ .maxlen = sizeof(int),
66757+ .mode = 0600,
66758+ .proc_handler = &proc_dointvec,
66759+ },
66760+#endif
66761+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
66762+ {
66763+ .procname = "chroot_deny_chroot",
66764+ .data = &grsec_enable_chroot_double,
66765+ .maxlen = sizeof(int),
66766+ .mode = 0600,
66767+ .proc_handler = &proc_dointvec,
66768+ },
66769+#endif
66770+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
66771+ {
66772+ .procname = "chroot_deny_pivot",
66773+ .data = &grsec_enable_chroot_pivot,
66774+ .maxlen = sizeof(int),
66775+ .mode = 0600,
66776+ .proc_handler = &proc_dointvec,
66777+ },
66778+#endif
66779+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
66780+ {
66781+ .procname = "chroot_enforce_chdir",
66782+ .data = &grsec_enable_chroot_chdir,
66783+ .maxlen = sizeof(int),
66784+ .mode = 0600,
66785+ .proc_handler = &proc_dointvec,
66786+ },
66787+#endif
66788+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
66789+ {
66790+ .procname = "chroot_deny_chmod",
66791+ .data = &grsec_enable_chroot_chmod,
66792+ .maxlen = sizeof(int),
66793+ .mode = 0600,
66794+ .proc_handler = &proc_dointvec,
66795+ },
66796+#endif
66797+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
66798+ {
66799+ .procname = "chroot_deny_mknod",
66800+ .data = &grsec_enable_chroot_mknod,
66801+ .maxlen = sizeof(int),
66802+ .mode = 0600,
66803+ .proc_handler = &proc_dointvec,
66804+ },
66805+#endif
66806+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
66807+ {
66808+ .procname = "chroot_restrict_nice",
66809+ .data = &grsec_enable_chroot_nice,
66810+ .maxlen = sizeof(int),
66811+ .mode = 0600,
66812+ .proc_handler = &proc_dointvec,
66813+ },
66814+#endif
66815+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
66816+ {
66817+ .procname = "chroot_execlog",
66818+ .data = &grsec_enable_chroot_execlog,
66819+ .maxlen = sizeof(int),
66820+ .mode = 0600,
66821+ .proc_handler = &proc_dointvec,
66822+ },
66823+#endif
66824+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66825+ {
66826+ .procname = "chroot_caps",
66827+ .data = &grsec_enable_chroot_caps,
66828+ .maxlen = sizeof(int),
66829+ .mode = 0600,
66830+ .proc_handler = &proc_dointvec,
66831+ },
66832+#endif
66833+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
66834+ {
66835+ .procname = "chroot_deny_sysctl",
66836+ .data = &grsec_enable_chroot_sysctl,
66837+ .maxlen = sizeof(int),
66838+ .mode = 0600,
66839+ .proc_handler = &proc_dointvec,
66840+ },
66841+#endif
66842+#ifdef CONFIG_GRKERNSEC_TPE
66843+ {
66844+ .procname = "tpe",
66845+ .data = &grsec_enable_tpe,
66846+ .maxlen = sizeof(int),
66847+ .mode = 0600,
66848+ .proc_handler = &proc_dointvec,
66849+ },
66850+ {
66851+ .procname = "tpe_gid",
66852+ .data = &grsec_tpe_gid,
66853+ .maxlen = sizeof(int),
66854+ .mode = 0600,
66855+ .proc_handler = &proc_dointvec,
66856+ },
66857+#endif
66858+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66859+ {
66860+ .procname = "tpe_invert",
66861+ .data = &grsec_enable_tpe_invert,
66862+ .maxlen = sizeof(int),
66863+ .mode = 0600,
66864+ .proc_handler = &proc_dointvec,
66865+ },
66866+#endif
66867+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66868+ {
66869+ .procname = "tpe_restrict_all",
66870+ .data = &grsec_enable_tpe_all,
66871+ .maxlen = sizeof(int),
66872+ .mode = 0600,
66873+ .proc_handler = &proc_dointvec,
66874+ },
66875+#endif
66876+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66877+ {
66878+ .procname = "socket_all",
66879+ .data = &grsec_enable_socket_all,
66880+ .maxlen = sizeof(int),
66881+ .mode = 0600,
66882+ .proc_handler = &proc_dointvec,
66883+ },
66884+ {
66885+ .procname = "socket_all_gid",
66886+ .data = &grsec_socket_all_gid,
66887+ .maxlen = sizeof(int),
66888+ .mode = 0600,
66889+ .proc_handler = &proc_dointvec,
66890+ },
66891+#endif
66892+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66893+ {
66894+ .procname = "socket_client",
66895+ .data = &grsec_enable_socket_client,
66896+ .maxlen = sizeof(int),
66897+ .mode = 0600,
66898+ .proc_handler = &proc_dointvec,
66899+ },
66900+ {
66901+ .procname = "socket_client_gid",
66902+ .data = &grsec_socket_client_gid,
66903+ .maxlen = sizeof(int),
66904+ .mode = 0600,
66905+ .proc_handler = &proc_dointvec,
66906+ },
66907+#endif
66908+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66909+ {
66910+ .procname = "socket_server",
66911+ .data = &grsec_enable_socket_server,
66912+ .maxlen = sizeof(int),
66913+ .mode = 0600,
66914+ .proc_handler = &proc_dointvec,
66915+ },
66916+ {
66917+ .procname = "socket_server_gid",
66918+ .data = &grsec_socket_server_gid,
66919+ .maxlen = sizeof(int),
66920+ .mode = 0600,
66921+ .proc_handler = &proc_dointvec,
66922+ },
66923+#endif
66924+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
66925+ {
66926+ .procname = "audit_group",
66927+ .data = &grsec_enable_group,
66928+ .maxlen = sizeof(int),
66929+ .mode = 0600,
66930+ .proc_handler = &proc_dointvec,
66931+ },
66932+ {
66933+ .procname = "audit_gid",
66934+ .data = &grsec_audit_gid,
66935+ .maxlen = sizeof(int),
66936+ .mode = 0600,
66937+ .proc_handler = &proc_dointvec,
66938+ },
66939+#endif
66940+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
66941+ {
66942+ .procname = "audit_chdir",
66943+ .data = &grsec_enable_chdir,
66944+ .maxlen = sizeof(int),
66945+ .mode = 0600,
66946+ .proc_handler = &proc_dointvec,
66947+ },
66948+#endif
66949+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66950+ {
66951+ .procname = "audit_mount",
66952+ .data = &grsec_enable_mount,
66953+ .maxlen = sizeof(int),
66954+ .mode = 0600,
66955+ .proc_handler = &proc_dointvec,
66956+ },
66957+#endif
66958+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
66959+ {
66960+ .procname = "audit_textrel",
66961+ .data = &grsec_enable_audit_textrel,
66962+ .maxlen = sizeof(int),
66963+ .mode = 0600,
66964+ .proc_handler = &proc_dointvec,
66965+ },
66966+#endif
66967+#ifdef CONFIG_GRKERNSEC_DMESG
66968+ {
66969+ .procname = "dmesg",
66970+ .data = &grsec_enable_dmesg,
66971+ .maxlen = sizeof(int),
66972+ .mode = 0600,
66973+ .proc_handler = &proc_dointvec,
66974+ },
66975+#endif
66976+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66977+ {
66978+ .procname = "chroot_findtask",
66979+ .data = &grsec_enable_chroot_findtask,
66980+ .maxlen = sizeof(int),
66981+ .mode = 0600,
66982+ .proc_handler = &proc_dointvec,
66983+ },
66984+#endif
66985+#ifdef CONFIG_GRKERNSEC_RESLOG
66986+ {
66987+ .procname = "resource_logging",
66988+ .data = &grsec_resource_logging,
66989+ .maxlen = sizeof(int),
66990+ .mode = 0600,
66991+ .proc_handler = &proc_dointvec,
66992+ },
66993+#endif
66994+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66995+ {
66996+ .procname = "audit_ptrace",
66997+ .data = &grsec_enable_audit_ptrace,
66998+ .maxlen = sizeof(int),
66999+ .mode = 0600,
67000+ .proc_handler = &proc_dointvec,
67001+ },
67002+#endif
67003+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67004+ {
67005+ .procname = "harden_ptrace",
67006+ .data = &grsec_enable_harden_ptrace,
67007+ .maxlen = sizeof(int),
67008+ .mode = 0600,
67009+ .proc_handler = &proc_dointvec,
67010+ },
67011+#endif
67012+ {
67013+ .procname = "grsec_lock",
67014+ .data = &grsec_lock,
67015+ .maxlen = sizeof(int),
67016+ .mode = 0600,
67017+ .proc_handler = &proc_dointvec,
67018+ },
67019+#endif
67020+#ifdef CONFIG_GRKERNSEC_ROFS
67021+ {
67022+ .procname = "romount_protect",
67023+ .data = &grsec_enable_rofs,
67024+ .maxlen = sizeof(int),
67025+ .mode = 0600,
67026+ .proc_handler = &proc_dointvec_minmax,
67027+ .extra1 = &one,
67028+ .extra2 = &one,
67029+ },
67030+#endif
67031+ { }
67032+};
67033+#endif
67034diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
67035new file mode 100644
67036index 0000000..0dc13c3
67037--- /dev/null
67038+++ b/grsecurity/grsec_time.c
67039@@ -0,0 +1,16 @@
67040+#include <linux/kernel.h>
67041+#include <linux/sched.h>
67042+#include <linux/grinternal.h>
67043+#include <linux/module.h>
67044+
67045+void
67046+gr_log_timechange(void)
67047+{
67048+#ifdef CONFIG_GRKERNSEC_TIME
67049+ if (grsec_enable_time)
67050+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
67051+#endif
67052+ return;
67053+}
67054+
67055+EXPORT_SYMBOL(gr_log_timechange);
67056diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
67057new file mode 100644
67058index 0000000..ee57dcf
67059--- /dev/null
67060+++ b/grsecurity/grsec_tpe.c
67061@@ -0,0 +1,73 @@
67062+#include <linux/kernel.h>
67063+#include <linux/sched.h>
67064+#include <linux/file.h>
67065+#include <linux/fs.h>
67066+#include <linux/grinternal.h>
67067+
67068+extern int gr_acl_tpe_check(void);
67069+
67070+int
67071+gr_tpe_allow(const struct file *file)
67072+{
67073+#ifdef CONFIG_GRKERNSEC
67074+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
67075+ const struct cred *cred = current_cred();
67076+ char *msg = NULL;
67077+ char *msg2 = NULL;
67078+
67079+ // never restrict root
67080+ if (gr_is_global_root(cred->uid))
67081+ return 1;
67082+
67083+ if (grsec_enable_tpe) {
67084+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
67085+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
67086+ msg = "not being in trusted group";
67087+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
67088+ msg = "being in untrusted group";
67089+#else
67090+ if (in_group_p(grsec_tpe_gid))
67091+ msg = "being in untrusted group";
67092+#endif
67093+ }
67094+ if (!msg && gr_acl_tpe_check())
67095+ msg = "being in untrusted role";
67096+
67097+ // not in any affected group/role
67098+ if (!msg)
67099+ goto next_check;
67100+
67101+ if (gr_is_global_nonroot(inode->i_uid))
67102+ msg2 = "file in non-root-owned directory";
67103+ else if (inode->i_mode & S_IWOTH)
67104+ msg2 = "file in world-writable directory";
67105+ else if (inode->i_mode & S_IWGRP)
67106+ msg2 = "file in group-writable directory";
67107+
67108+ if (msg && msg2) {
67109+ char fullmsg[70] = {0};
67110+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
67111+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
67112+ return 0;
67113+ }
67114+ msg = NULL;
67115+next_check:
67116+#ifdef CONFIG_GRKERNSEC_TPE_ALL
67117+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
67118+ return 1;
67119+
67120+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
67121+ msg = "directory not owned by user";
67122+ else if (inode->i_mode & S_IWOTH)
67123+ msg = "file in world-writable directory";
67124+ else if (inode->i_mode & S_IWGRP)
67125+ msg = "file in group-writable directory";
67126+
67127+ if (msg) {
67128+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
67129+ return 0;
67130+ }
67131+#endif
67132+#endif
67133+ return 1;
67134+}
67135diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
67136new file mode 100644
67137index 0000000..9f7b1ac
67138--- /dev/null
67139+++ b/grsecurity/grsum.c
67140@@ -0,0 +1,61 @@
67141+#include <linux/err.h>
67142+#include <linux/kernel.h>
67143+#include <linux/sched.h>
67144+#include <linux/mm.h>
67145+#include <linux/scatterlist.h>
67146+#include <linux/crypto.h>
67147+#include <linux/gracl.h>
67148+
67149+
67150+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
67151+#error "crypto and sha256 must be built into the kernel"
67152+#endif
67153+
67154+int
67155+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
67156+{
67157+ char *p;
67158+ struct crypto_hash *tfm;
67159+ struct hash_desc desc;
67160+ struct scatterlist sg;
67161+ unsigned char temp_sum[GR_SHA_LEN];
67162+ volatile int retval = 0;
67163+ volatile int dummy = 0;
67164+ unsigned int i;
67165+
67166+ sg_init_table(&sg, 1);
67167+
67168+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
67169+ if (IS_ERR(tfm)) {
67170+ /* should never happen, since sha256 should be built in */
67171+ return 1;
67172+ }
67173+
67174+ desc.tfm = tfm;
67175+ desc.flags = 0;
67176+
67177+ crypto_hash_init(&desc);
67178+
67179+ p = salt;
67180+ sg_set_buf(&sg, p, GR_SALT_LEN);
67181+ crypto_hash_update(&desc, &sg, sg.length);
67182+
67183+ p = entry->pw;
67184+ sg_set_buf(&sg, p, strlen(p));
67185+
67186+ crypto_hash_update(&desc, &sg, sg.length);
67187+
67188+ crypto_hash_final(&desc, temp_sum);
67189+
67190+ memset(entry->pw, 0, GR_PW_LEN);
67191+
67192+ for (i = 0; i < GR_SHA_LEN; i++)
67193+ if (sum[i] != temp_sum[i])
67194+ retval = 1;
67195+ else
67196+ dummy = 1; // waste a cycle
67197+
67198+ crypto_free_hash(tfm);
67199+
67200+ return retval;
67201+}
67202diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
67203index 77ff547..181834f 100644
67204--- a/include/asm-generic/4level-fixup.h
67205+++ b/include/asm-generic/4level-fixup.h
67206@@ -13,8 +13,10 @@
67207 #define pmd_alloc(mm, pud, address) \
67208 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
67209 NULL: pmd_offset(pud, address))
67210+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
67211
67212 #define pud_alloc(mm, pgd, address) (pgd)
67213+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
67214 #define pud_offset(pgd, start) (pgd)
67215 #define pud_none(pud) 0
67216 #define pud_bad(pud) 0
67217diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
67218index b7babf0..04ad282 100644
67219--- a/include/asm-generic/atomic-long.h
67220+++ b/include/asm-generic/atomic-long.h
67221@@ -22,6 +22,12 @@
67222
67223 typedef atomic64_t atomic_long_t;
67224
67225+#ifdef CONFIG_PAX_REFCOUNT
67226+typedef atomic64_unchecked_t atomic_long_unchecked_t;
67227+#else
67228+typedef atomic64_t atomic_long_unchecked_t;
67229+#endif
67230+
67231 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
67232
67233 static inline long atomic_long_read(atomic_long_t *l)
67234@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67235 return (long)atomic64_read(v);
67236 }
67237
67238+#ifdef CONFIG_PAX_REFCOUNT
67239+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67240+{
67241+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67242+
67243+ return (long)atomic64_read_unchecked(v);
67244+}
67245+#endif
67246+
67247 static inline void atomic_long_set(atomic_long_t *l, long i)
67248 {
67249 atomic64_t *v = (atomic64_t *)l;
67250@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67251 atomic64_set(v, i);
67252 }
67253
67254+#ifdef CONFIG_PAX_REFCOUNT
67255+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67256+{
67257+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67258+
67259+ atomic64_set_unchecked(v, i);
67260+}
67261+#endif
67262+
67263 static inline void atomic_long_inc(atomic_long_t *l)
67264 {
67265 atomic64_t *v = (atomic64_t *)l;
67266@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67267 atomic64_inc(v);
67268 }
67269
67270+#ifdef CONFIG_PAX_REFCOUNT
67271+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67272+{
67273+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67274+
67275+ atomic64_inc_unchecked(v);
67276+}
67277+#endif
67278+
67279 static inline void atomic_long_dec(atomic_long_t *l)
67280 {
67281 atomic64_t *v = (atomic64_t *)l;
67282@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67283 atomic64_dec(v);
67284 }
67285
67286+#ifdef CONFIG_PAX_REFCOUNT
67287+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67288+{
67289+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67290+
67291+ atomic64_dec_unchecked(v);
67292+}
67293+#endif
67294+
67295 static inline void atomic_long_add(long i, atomic_long_t *l)
67296 {
67297 atomic64_t *v = (atomic64_t *)l;
67298@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67299 atomic64_add(i, v);
67300 }
67301
67302+#ifdef CONFIG_PAX_REFCOUNT
67303+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67304+{
67305+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67306+
67307+ atomic64_add_unchecked(i, v);
67308+}
67309+#endif
67310+
67311 static inline void atomic_long_sub(long i, atomic_long_t *l)
67312 {
67313 atomic64_t *v = (atomic64_t *)l;
67314@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67315 atomic64_sub(i, v);
67316 }
67317
67318+#ifdef CONFIG_PAX_REFCOUNT
67319+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67320+{
67321+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67322+
67323+ atomic64_sub_unchecked(i, v);
67324+}
67325+#endif
67326+
67327 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67328 {
67329 atomic64_t *v = (atomic64_t *)l;
67330@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67331 return (long)atomic64_add_return(i, v);
67332 }
67333
67334+#ifdef CONFIG_PAX_REFCOUNT
67335+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67336+{
67337+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67338+
67339+ return (long)atomic64_add_return_unchecked(i, v);
67340+}
67341+#endif
67342+
67343 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67344 {
67345 atomic64_t *v = (atomic64_t *)l;
67346@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67347 return (long)atomic64_inc_return(v);
67348 }
67349
67350+#ifdef CONFIG_PAX_REFCOUNT
67351+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67352+{
67353+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67354+
67355+ return (long)atomic64_inc_return_unchecked(v);
67356+}
67357+#endif
67358+
67359 static inline long atomic_long_dec_return(atomic_long_t *l)
67360 {
67361 atomic64_t *v = (atomic64_t *)l;
67362@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67363
67364 typedef atomic_t atomic_long_t;
67365
67366+#ifdef CONFIG_PAX_REFCOUNT
67367+typedef atomic_unchecked_t atomic_long_unchecked_t;
67368+#else
67369+typedef atomic_t atomic_long_unchecked_t;
67370+#endif
67371+
67372 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
67373 static inline long atomic_long_read(atomic_long_t *l)
67374 {
67375@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67376 return (long)atomic_read(v);
67377 }
67378
67379+#ifdef CONFIG_PAX_REFCOUNT
67380+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67381+{
67382+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67383+
67384+ return (long)atomic_read_unchecked(v);
67385+}
67386+#endif
67387+
67388 static inline void atomic_long_set(atomic_long_t *l, long i)
67389 {
67390 atomic_t *v = (atomic_t *)l;
67391@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67392 atomic_set(v, i);
67393 }
67394
67395+#ifdef CONFIG_PAX_REFCOUNT
67396+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67397+{
67398+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67399+
67400+ atomic_set_unchecked(v, i);
67401+}
67402+#endif
67403+
67404 static inline void atomic_long_inc(atomic_long_t *l)
67405 {
67406 atomic_t *v = (atomic_t *)l;
67407@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67408 atomic_inc(v);
67409 }
67410
67411+#ifdef CONFIG_PAX_REFCOUNT
67412+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67413+{
67414+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67415+
67416+ atomic_inc_unchecked(v);
67417+}
67418+#endif
67419+
67420 static inline void atomic_long_dec(atomic_long_t *l)
67421 {
67422 atomic_t *v = (atomic_t *)l;
67423@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67424 atomic_dec(v);
67425 }
67426
67427+#ifdef CONFIG_PAX_REFCOUNT
67428+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67429+{
67430+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67431+
67432+ atomic_dec_unchecked(v);
67433+}
67434+#endif
67435+
67436 static inline void atomic_long_add(long i, atomic_long_t *l)
67437 {
67438 atomic_t *v = (atomic_t *)l;
67439@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67440 atomic_add(i, v);
67441 }
67442
67443+#ifdef CONFIG_PAX_REFCOUNT
67444+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67445+{
67446+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67447+
67448+ atomic_add_unchecked(i, v);
67449+}
67450+#endif
67451+
67452 static inline void atomic_long_sub(long i, atomic_long_t *l)
67453 {
67454 atomic_t *v = (atomic_t *)l;
67455@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67456 atomic_sub(i, v);
67457 }
67458
67459+#ifdef CONFIG_PAX_REFCOUNT
67460+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67461+{
67462+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67463+
67464+ atomic_sub_unchecked(i, v);
67465+}
67466+#endif
67467+
67468 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67469 {
67470 atomic_t *v = (atomic_t *)l;
67471@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67472 return (long)atomic_add_return(i, v);
67473 }
67474
67475+#ifdef CONFIG_PAX_REFCOUNT
67476+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67477+{
67478+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67479+
67480+ return (long)atomic_add_return_unchecked(i, v);
67481+}
67482+
67483+#endif
67484+
67485 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67486 {
67487 atomic_t *v = (atomic_t *)l;
67488@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67489 return (long)atomic_inc_return(v);
67490 }
67491
67492+#ifdef CONFIG_PAX_REFCOUNT
67493+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67494+{
67495+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67496+
67497+ return (long)atomic_inc_return_unchecked(v);
67498+}
67499+#endif
67500+
67501 static inline long atomic_long_dec_return(atomic_long_t *l)
67502 {
67503 atomic_t *v = (atomic_t *)l;
67504@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67505
67506 #endif /* BITS_PER_LONG == 64 */
67507
67508+#ifdef CONFIG_PAX_REFCOUNT
67509+static inline void pax_refcount_needs_these_functions(void)
67510+{
67511+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
67512+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
67513+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
67514+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
67515+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
67516+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
67517+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
67518+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
67519+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
67520+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
67521+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
67522+#ifdef CONFIG_X86
67523+ atomic_clear_mask_unchecked(0, NULL);
67524+ atomic_set_mask_unchecked(0, NULL);
67525+#endif
67526+
67527+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
67528+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
67529+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
67530+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
67531+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
67532+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
67533+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
67534+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
67535+}
67536+#else
67537+#define atomic_read_unchecked(v) atomic_read(v)
67538+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
67539+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
67540+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
67541+#define atomic_inc_unchecked(v) atomic_inc(v)
67542+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
67543+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
67544+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
67545+#define atomic_dec_unchecked(v) atomic_dec(v)
67546+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
67547+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
67548+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
67549+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
67550+
67551+#define atomic_long_read_unchecked(v) atomic_long_read(v)
67552+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
67553+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
67554+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
67555+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
67556+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
67557+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
67558+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
67559+#endif
67560+
67561 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
67562diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
67563index 33bd2de..f31bff97 100644
67564--- a/include/asm-generic/atomic.h
67565+++ b/include/asm-generic/atomic.h
67566@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
67567 * Atomically clears the bits set in @mask from @v
67568 */
67569 #ifndef atomic_clear_mask
67570-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
67571+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
67572 {
67573 unsigned long flags;
67574
67575diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
67576index b18ce4f..2ee2843 100644
67577--- a/include/asm-generic/atomic64.h
67578+++ b/include/asm-generic/atomic64.h
67579@@ -16,6 +16,8 @@ typedef struct {
67580 long long counter;
67581 } atomic64_t;
67582
67583+typedef atomic64_t atomic64_unchecked_t;
67584+
67585 #define ATOMIC64_INIT(i) { (i) }
67586
67587 extern long long atomic64_read(const atomic64_t *v);
67588@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
67589 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
67590 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
67591
67592+#define atomic64_read_unchecked(v) atomic64_read(v)
67593+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
67594+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
67595+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
67596+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
67597+#define atomic64_inc_unchecked(v) atomic64_inc(v)
67598+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
67599+#define atomic64_dec_unchecked(v) atomic64_dec(v)
67600+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
67601+
67602 #endif /* _ASM_GENERIC_ATOMIC64_H */
67603diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
67604index 1bfcfe5..e04c5c9 100644
67605--- a/include/asm-generic/cache.h
67606+++ b/include/asm-generic/cache.h
67607@@ -6,7 +6,7 @@
67608 * cache lines need to provide their own cache.h.
67609 */
67610
67611-#define L1_CACHE_SHIFT 5
67612-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
67613+#define L1_CACHE_SHIFT 5UL
67614+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
67615
67616 #endif /* __ASM_GENERIC_CACHE_H */
67617diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
67618index 0d68a1e..b74a761 100644
67619--- a/include/asm-generic/emergency-restart.h
67620+++ b/include/asm-generic/emergency-restart.h
67621@@ -1,7 +1,7 @@
67622 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
67623 #define _ASM_GENERIC_EMERGENCY_RESTART_H
67624
67625-static inline void machine_emergency_restart(void)
67626+static inline __noreturn void machine_emergency_restart(void)
67627 {
67628 machine_restart(NULL);
67629 }
67630diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
67631index 90f99c7..00ce236 100644
67632--- a/include/asm-generic/kmap_types.h
67633+++ b/include/asm-generic/kmap_types.h
67634@@ -2,9 +2,9 @@
67635 #define _ASM_GENERIC_KMAP_TYPES_H
67636
67637 #ifdef __WITH_KM_FENCE
67638-# define KM_TYPE_NR 41
67639+# define KM_TYPE_NR 42
67640 #else
67641-# define KM_TYPE_NR 20
67642+# define KM_TYPE_NR 21
67643 #endif
67644
67645 #endif
67646diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
67647index 9ceb03b..62b0b8f 100644
67648--- a/include/asm-generic/local.h
67649+++ b/include/asm-generic/local.h
67650@@ -23,24 +23,37 @@ typedef struct
67651 atomic_long_t a;
67652 } local_t;
67653
67654+typedef struct {
67655+ atomic_long_unchecked_t a;
67656+} local_unchecked_t;
67657+
67658 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
67659
67660 #define local_read(l) atomic_long_read(&(l)->a)
67661+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
67662 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
67663+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
67664 #define local_inc(l) atomic_long_inc(&(l)->a)
67665+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
67666 #define local_dec(l) atomic_long_dec(&(l)->a)
67667+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
67668 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
67669+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
67670 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
67671+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
67672
67673 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
67674 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
67675 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
67676 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
67677 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
67678+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
67679 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
67680 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
67681+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
67682
67683 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67684+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67685 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
67686 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
67687 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
67688diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
67689index 725612b..9cc513a 100644
67690--- a/include/asm-generic/pgtable-nopmd.h
67691+++ b/include/asm-generic/pgtable-nopmd.h
67692@@ -1,14 +1,19 @@
67693 #ifndef _PGTABLE_NOPMD_H
67694 #define _PGTABLE_NOPMD_H
67695
67696-#ifndef __ASSEMBLY__
67697-
67698 #include <asm-generic/pgtable-nopud.h>
67699
67700-struct mm_struct;
67701-
67702 #define __PAGETABLE_PMD_FOLDED
67703
67704+#define PMD_SHIFT PUD_SHIFT
67705+#define PTRS_PER_PMD 1
67706+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
67707+#define PMD_MASK (~(PMD_SIZE-1))
67708+
67709+#ifndef __ASSEMBLY__
67710+
67711+struct mm_struct;
67712+
67713 /*
67714 * Having the pmd type consist of a pud gets the size right, and allows
67715 * us to conceptually access the pud entry that this pmd is folded into
67716@@ -16,11 +21,6 @@ struct mm_struct;
67717 */
67718 typedef struct { pud_t pud; } pmd_t;
67719
67720-#define PMD_SHIFT PUD_SHIFT
67721-#define PTRS_PER_PMD 1
67722-#define PMD_SIZE (1UL << PMD_SHIFT)
67723-#define PMD_MASK (~(PMD_SIZE-1))
67724-
67725 /*
67726 * The "pud_xxx()" functions here are trivial for a folded two-level
67727 * setup: the pmd is never bad, and a pmd always exists (as it's folded
67728diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
67729index 810431d..0ec4804f 100644
67730--- a/include/asm-generic/pgtable-nopud.h
67731+++ b/include/asm-generic/pgtable-nopud.h
67732@@ -1,10 +1,15 @@
67733 #ifndef _PGTABLE_NOPUD_H
67734 #define _PGTABLE_NOPUD_H
67735
67736-#ifndef __ASSEMBLY__
67737-
67738 #define __PAGETABLE_PUD_FOLDED
67739
67740+#define PUD_SHIFT PGDIR_SHIFT
67741+#define PTRS_PER_PUD 1
67742+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
67743+#define PUD_MASK (~(PUD_SIZE-1))
67744+
67745+#ifndef __ASSEMBLY__
67746+
67747 /*
67748 * Having the pud type consist of a pgd gets the size right, and allows
67749 * us to conceptually access the pgd entry that this pud is folded into
67750@@ -12,11 +17,6 @@
67751 */
67752 typedef struct { pgd_t pgd; } pud_t;
67753
67754-#define PUD_SHIFT PGDIR_SHIFT
67755-#define PTRS_PER_PUD 1
67756-#define PUD_SIZE (1UL << PUD_SHIFT)
67757-#define PUD_MASK (~(PUD_SIZE-1))
67758-
67759 /*
67760 * The "pgd_xxx()" functions here are trivial for a folded two-level
67761 * setup: the pud is never bad, and a pud always exists (as it's folded
67762@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
67763 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
67764
67765 #define pgd_populate(mm, pgd, pud) do { } while (0)
67766+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
67767 /*
67768 * (puds are folded into pgds so this doesn't get actually called,
67769 * but the define is needed for a generic inline function.)
67770diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
67771index a59ff51..2594a70 100644
67772--- a/include/asm-generic/pgtable.h
67773+++ b/include/asm-generic/pgtable.h
67774@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
67775 }
67776 #endif /* CONFIG_NUMA_BALANCING */
67777
67778+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
67779+static inline unsigned long pax_open_kernel(void) { return 0; }
67780+#endif
67781+
67782+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
67783+static inline unsigned long pax_close_kernel(void) { return 0; }
67784+#endif
67785+
67786 #endif /* CONFIG_MMU */
67787
67788 #endif /* !__ASSEMBLY__ */
67789diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
67790index eb58d2d..df131bf 100644
67791--- a/include/asm-generic/vmlinux.lds.h
67792+++ b/include/asm-generic/vmlinux.lds.h
67793@@ -239,6 +239,7 @@
67794 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
67795 VMLINUX_SYMBOL(__start_rodata) = .; \
67796 *(.rodata) *(.rodata.*) \
67797+ *(.data..read_only) \
67798 *(__vermagic) /* Kernel version magic */ \
67799 . = ALIGN(8); \
67800 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
67801@@ -749,17 +750,18 @@
67802 * section in the linker script will go there too. @phdr should have
67803 * a leading colon.
67804 *
67805- * Note that this macros defines __per_cpu_load as an absolute symbol.
67806+ * Note that this macros defines per_cpu_load as an absolute symbol.
67807 * If there is no need to put the percpu section at a predetermined
67808 * address, use PERCPU_SECTION.
67809 */
67810 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
67811- VMLINUX_SYMBOL(__per_cpu_load) = .; \
67812- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
67813+ per_cpu_load = .; \
67814+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
67815 - LOAD_OFFSET) { \
67816+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
67817 PERCPU_INPUT(cacheline) \
67818 } phdr \
67819- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
67820+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
67821
67822 /**
67823 * PERCPU_SECTION - define output section for percpu area, simple version
67824diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
67825index 418d270..bfd2794 100644
67826--- a/include/crypto/algapi.h
67827+++ b/include/crypto/algapi.h
67828@@ -34,7 +34,7 @@ struct crypto_type {
67829 unsigned int maskclear;
67830 unsigned int maskset;
67831 unsigned int tfmsize;
67832-};
67833+} __do_const;
67834
67835 struct crypto_instance {
67836 struct crypto_alg alg;
67837diff --git a/include/drm/drmP.h b/include/drm/drmP.h
67838index 63d17ee..716de2b 100644
67839--- a/include/drm/drmP.h
67840+++ b/include/drm/drmP.h
67841@@ -72,6 +72,7 @@
67842 #include <linux/workqueue.h>
67843 #include <linux/poll.h>
67844 #include <asm/pgalloc.h>
67845+#include <asm/local.h>
67846 #include <drm/drm.h>
67847 #include <drm/drm_sarea.h>
67848
67849@@ -296,10 +297,12 @@ do { \
67850 * \param cmd command.
67851 * \param arg argument.
67852 */
67853-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
67854+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
67855+ struct drm_file *file_priv);
67856+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
67857 struct drm_file *file_priv);
67858
67859-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67860+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
67861 unsigned long arg);
67862
67863 #define DRM_IOCTL_NR(n) _IOC_NR(n)
67864@@ -314,10 +317,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67865 struct drm_ioctl_desc {
67866 unsigned int cmd;
67867 int flags;
67868- drm_ioctl_t *func;
67869+ drm_ioctl_t func;
67870 unsigned int cmd_drv;
67871 const char *name;
67872-};
67873+} __do_const;
67874
67875 /**
67876 * Creates a driver or general drm_ioctl_desc array entry for the given
67877@@ -1015,7 +1018,7 @@ struct drm_info_list {
67878 int (*show)(struct seq_file*, void*); /** show callback */
67879 u32 driver_features; /**< Required driver features for this entry */
67880 void *data;
67881-};
67882+} __do_const;
67883
67884 /**
67885 * debugfs node structure. This structure represents a debugfs file.
67886@@ -1088,7 +1091,7 @@ struct drm_device {
67887
67888 /** \name Usage Counters */
67889 /*@{ */
67890- int open_count; /**< Outstanding files open */
67891+ local_t open_count; /**< Outstanding files open */
67892 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
67893 atomic_t vma_count; /**< Outstanding vma areas open */
67894 int buf_use; /**< Buffers in use -- cannot alloc */
67895@@ -1099,7 +1102,7 @@ struct drm_device {
67896 /*@{ */
67897 unsigned long counters;
67898 enum drm_stat_type types[15];
67899- atomic_t counts[15];
67900+ atomic_unchecked_t counts[15];
67901 /*@} */
67902
67903 struct list_head filelist;
67904diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
67905index f43d556..94d9343 100644
67906--- a/include/drm/drm_crtc_helper.h
67907+++ b/include/drm/drm_crtc_helper.h
67908@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
67909 struct drm_connector *connector);
67910 /* disable encoder when not in use - more explicit than dpms off */
67911 void (*disable)(struct drm_encoder *encoder);
67912-};
67913+} __no_const;
67914
67915 /**
67916 * drm_connector_helper_funcs - helper operations for connectors
67917diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
67918index 72dcbe8..8db58d7 100644
67919--- a/include/drm/ttm/ttm_memory.h
67920+++ b/include/drm/ttm/ttm_memory.h
67921@@ -48,7 +48,7 @@
67922
67923 struct ttm_mem_shrink {
67924 int (*do_shrink) (struct ttm_mem_shrink *);
67925-};
67926+} __no_const;
67927
67928 /**
67929 * struct ttm_mem_global - Global memory accounting structure.
67930diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
67931index 4b840e8..155d235 100644
67932--- a/include/keys/asymmetric-subtype.h
67933+++ b/include/keys/asymmetric-subtype.h
67934@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
67935 /* Verify the signature on a key of this subtype (optional) */
67936 int (*verify_signature)(const struct key *key,
67937 const struct public_key_signature *sig);
67938-};
67939+} __do_const;
67940
67941 /**
67942 * asymmetric_key_subtype - Get the subtype from an asymmetric key
67943diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
67944index c1da539..1dcec55 100644
67945--- a/include/linux/atmdev.h
67946+++ b/include/linux/atmdev.h
67947@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
67948 #endif
67949
67950 struct k_atm_aal_stats {
67951-#define __HANDLE_ITEM(i) atomic_t i
67952+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67953 __AAL_STAT_ITEMS
67954 #undef __HANDLE_ITEM
67955 };
67956@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
67957 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
67958 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
67959 struct module *owner;
67960-};
67961+} __do_const ;
67962
67963 struct atmphy_ops {
67964 int (*start)(struct atm_dev *dev);
67965diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
67966index 70cf138..cabb82e 100644
67967--- a/include/linux/binfmts.h
67968+++ b/include/linux/binfmts.h
67969@@ -73,8 +73,9 @@ struct linux_binfmt {
67970 int (*load_binary)(struct linux_binprm *);
67971 int (*load_shlib)(struct file *);
67972 int (*core_dump)(struct coredump_params *cprm);
67973+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
67974 unsigned long min_coredump; /* minimal dump size */
67975-};
67976+} __do_const;
67977
67978 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
67979
67980diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
67981index 2fdb4a4..54aad7e 100644
67982--- a/include/linux/blkdev.h
67983+++ b/include/linux/blkdev.h
67984@@ -1526,7 +1526,7 @@ struct block_device_operations {
67985 /* this callback is with swap_lock and sometimes page table lock held */
67986 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
67987 struct module *owner;
67988-};
67989+} __do_const;
67990
67991 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
67992 unsigned long);
67993diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
67994index 7c2e030..b72475d 100644
67995--- a/include/linux/blktrace_api.h
67996+++ b/include/linux/blktrace_api.h
67997@@ -23,7 +23,7 @@ struct blk_trace {
67998 struct dentry *dir;
67999 struct dentry *dropped_file;
68000 struct dentry *msg_file;
68001- atomic_t dropped;
68002+ atomic_unchecked_t dropped;
68003 };
68004
68005 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
68006diff --git a/include/linux/cache.h b/include/linux/cache.h
68007index 4c57065..4307975 100644
68008--- a/include/linux/cache.h
68009+++ b/include/linux/cache.h
68010@@ -16,6 +16,10 @@
68011 #define __read_mostly
68012 #endif
68013
68014+#ifndef __read_only
68015+#define __read_only __read_mostly
68016+#endif
68017+
68018 #ifndef ____cacheline_aligned
68019 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
68020 #endif
68021diff --git a/include/linux/capability.h b/include/linux/capability.h
68022index d9a4f7f4..19f77d6 100644
68023--- a/include/linux/capability.h
68024+++ b/include/linux/capability.h
68025@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
68026 extern bool nsown_capable(int cap);
68027 extern bool inode_capable(const struct inode *inode, int cap);
68028 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
68029+extern bool capable_nolog(int cap);
68030+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
68031+extern bool inode_capable_nolog(const struct inode *inode, int cap);
68032
68033 /* audit system wants to get cap info from files as well */
68034 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
68035
68036+extern int is_privileged_binary(const struct dentry *dentry);
68037+
68038 #endif /* !_LINUX_CAPABILITY_H */
68039diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
68040index 8609d57..86e4d79 100644
68041--- a/include/linux/cdrom.h
68042+++ b/include/linux/cdrom.h
68043@@ -87,7 +87,6 @@ struct cdrom_device_ops {
68044
68045 /* driver specifications */
68046 const int capability; /* capability flags */
68047- int n_minors; /* number of active minor devices */
68048 /* handle uniform packets for scsi type devices (scsi,atapi) */
68049 int (*generic_packet) (struct cdrom_device_info *,
68050 struct packet_command *);
68051diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
68052index 4ce9056..86caac6 100644
68053--- a/include/linux/cleancache.h
68054+++ b/include/linux/cleancache.h
68055@@ -31,7 +31,7 @@ struct cleancache_ops {
68056 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
68057 void (*invalidate_inode)(int, struct cleancache_filekey);
68058 void (*invalidate_fs)(int);
68059-};
68060+} __no_const;
68061
68062 extern struct cleancache_ops *
68063 cleancache_register_ops(struct cleancache_ops *ops);
68064diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
68065index 1186098..f87e53d 100644
68066--- a/include/linux/clk-provider.h
68067+++ b/include/linux/clk-provider.h
68068@@ -132,6 +132,7 @@ struct clk_ops {
68069 unsigned long);
68070 void (*init)(struct clk_hw *hw);
68071 };
68072+typedef struct clk_ops __no_const clk_ops_no_const;
68073
68074 /**
68075 * struct clk_init_data - holds init data that's common to all clocks and is
68076diff --git a/include/linux/compat.h b/include/linux/compat.h
68077index 7f0c1dd..b5729c6 100644
68078--- a/include/linux/compat.h
68079+++ b/include/linux/compat.h
68080@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
68081 compat_size_t __user *len_ptr);
68082
68083 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
68084-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
68085+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
68086 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
68087 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
68088 compat_ssize_t msgsz, int msgflg);
68089@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
68090 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
68091 compat_ulong_t addr, compat_ulong_t data);
68092 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68093- compat_long_t addr, compat_long_t data);
68094+ compat_ulong_t addr, compat_ulong_t data);
68095
68096 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
68097 /*
68098diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
68099index 842de22..7f3a41f 100644
68100--- a/include/linux/compiler-gcc4.h
68101+++ b/include/linux/compiler-gcc4.h
68102@@ -39,9 +39,29 @@
68103 # define __compiletime_warning(message) __attribute__((warning(message)))
68104 # define __compiletime_error(message) __attribute__((error(message)))
68105 #endif /* __CHECKER__ */
68106+
68107+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
68108+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
68109+#define __bos0(ptr) __bos((ptr), 0)
68110+#define __bos1(ptr) __bos((ptr), 1)
68111 #endif /* GCC_VERSION >= 40300 */
68112
68113 #if GCC_VERSION >= 40500
68114+
68115+#ifdef CONSTIFY_PLUGIN
68116+#define __no_const __attribute__((no_const))
68117+#define __do_const __attribute__((do_const))
68118+#endif
68119+
68120+#ifdef SIZE_OVERFLOW_PLUGIN
68121+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
68122+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
68123+#endif
68124+
68125+#ifdef LATENT_ENTROPY_PLUGIN
68126+#define __latent_entropy __attribute__((latent_entropy))
68127+#endif
68128+
68129 /*
68130 * Mark a position in code as unreachable. This can be used to
68131 * suppress control flow warnings after asm blocks that transfer
68132diff --git a/include/linux/compiler.h b/include/linux/compiler.h
68133index 92669cd..1771a15 100644
68134--- a/include/linux/compiler.h
68135+++ b/include/linux/compiler.h
68136@@ -5,11 +5,14 @@
68137
68138 #ifdef __CHECKER__
68139 # define __user __attribute__((noderef, address_space(1)))
68140+# define __force_user __force __user
68141 # define __kernel __attribute__((address_space(0)))
68142+# define __force_kernel __force __kernel
68143 # define __safe __attribute__((safe))
68144 # define __force __attribute__((force))
68145 # define __nocast __attribute__((nocast))
68146 # define __iomem __attribute__((noderef, address_space(2)))
68147+# define __force_iomem __force __iomem
68148 # define __must_hold(x) __attribute__((context(x,1,1)))
68149 # define __acquires(x) __attribute__((context(x,0,1)))
68150 # define __releases(x) __attribute__((context(x,1,0)))
68151@@ -17,20 +20,37 @@
68152 # define __release(x) __context__(x,-1)
68153 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
68154 # define __percpu __attribute__((noderef, address_space(3)))
68155+# define __force_percpu __force __percpu
68156 #ifdef CONFIG_SPARSE_RCU_POINTER
68157 # define __rcu __attribute__((noderef, address_space(4)))
68158+# define __force_rcu __force __rcu
68159 #else
68160 # define __rcu
68161+# define __force_rcu
68162 #endif
68163 extern void __chk_user_ptr(const volatile void __user *);
68164 extern void __chk_io_ptr(const volatile void __iomem *);
68165 #else
68166-# define __user
68167-# define __kernel
68168+# ifdef CHECKER_PLUGIN
68169+//# define __user
68170+//# define __force_user
68171+//# define __kernel
68172+//# define __force_kernel
68173+# else
68174+# ifdef STRUCTLEAK_PLUGIN
68175+# define __user __attribute__((user))
68176+# else
68177+# define __user
68178+# endif
68179+# define __force_user
68180+# define __kernel
68181+# define __force_kernel
68182+# endif
68183 # define __safe
68184 # define __force
68185 # define __nocast
68186 # define __iomem
68187+# define __force_iomem
68188 # define __chk_user_ptr(x) (void)0
68189 # define __chk_io_ptr(x) (void)0
68190 # define __builtin_warning(x, y...) (1)
68191@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
68192 # define __release(x) (void)0
68193 # define __cond_lock(x,c) (c)
68194 # define __percpu
68195+# define __force_percpu
68196 # define __rcu
68197+# define __force_rcu
68198 #endif
68199
68200 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
68201@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68202 # define __attribute_const__ /* unimplemented */
68203 #endif
68204
68205+#ifndef __no_const
68206+# define __no_const
68207+#endif
68208+
68209+#ifndef __do_const
68210+# define __do_const
68211+#endif
68212+
68213+#ifndef __size_overflow
68214+# define __size_overflow(...)
68215+#endif
68216+
68217+#ifndef __intentional_overflow
68218+# define __intentional_overflow(...)
68219+#endif
68220+
68221+#ifndef __latent_entropy
68222+# define __latent_entropy
68223+#endif
68224+
68225 /*
68226 * Tell gcc if a function is cold. The compiler will assume any path
68227 * directly leading to the call is unlikely.
68228@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68229 #define __cold
68230 #endif
68231
68232+#ifndef __alloc_size
68233+#define __alloc_size(...)
68234+#endif
68235+
68236+#ifndef __bos
68237+#define __bos(ptr, arg)
68238+#endif
68239+
68240+#ifndef __bos0
68241+#define __bos0(ptr)
68242+#endif
68243+
68244+#ifndef __bos1
68245+#define __bos1(ptr)
68246+#endif
68247+
68248 /* Simple shorthand for a section definition */
68249 #ifndef __section
68250 # define __section(S) __attribute__ ((__section__(#S)))
68251@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68252 * use is to mediate communication between process-level code and irq/NMI
68253 * handlers, all running on the same CPU.
68254 */
68255-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
68256+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
68257+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
68258
68259 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
68260 #ifdef CONFIG_KPROBES
68261diff --git a/include/linux/completion.h b/include/linux/completion.h
68262index 33f0280..35c6568 100644
68263--- a/include/linux/completion.h
68264+++ b/include/linux/completion.h
68265@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
68266 extern void wait_for_completion(struct completion *);
68267 extern void wait_for_completion_io(struct completion *);
68268 extern int wait_for_completion_interruptible(struct completion *x);
68269-extern int wait_for_completion_killable(struct completion *x);
68270+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
68271 extern unsigned long wait_for_completion_timeout(struct completion *x,
68272 unsigned long timeout);
68273 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
68274 unsigned long timeout);
68275 extern long wait_for_completion_interruptible_timeout(
68276- struct completion *x, unsigned long timeout);
68277+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68278 extern long wait_for_completion_killable_timeout(
68279- struct completion *x, unsigned long timeout);
68280+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68281 extern bool try_wait_for_completion(struct completion *x);
68282 extern bool completion_done(struct completion *x);
68283
68284diff --git a/include/linux/configfs.h b/include/linux/configfs.h
68285index 34025df..d94bbbc 100644
68286--- a/include/linux/configfs.h
68287+++ b/include/linux/configfs.h
68288@@ -125,7 +125,7 @@ struct configfs_attribute {
68289 const char *ca_name;
68290 struct module *ca_owner;
68291 umode_t ca_mode;
68292-};
68293+} __do_const;
68294
68295 /*
68296 * Users often need to create attribute structures for their configurable
68297diff --git a/include/linux/cpu.h b/include/linux/cpu.h
68298index 9f3c7e8..a18c7b6 100644
68299--- a/include/linux/cpu.h
68300+++ b/include/linux/cpu.h
68301@@ -115,7 +115,7 @@ enum {
68302 /* Need to know about CPUs going up/down? */
68303 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
68304 #define cpu_notifier(fn, pri) { \
68305- static struct notifier_block fn##_nb __cpuinitdata = \
68306+ static struct notifier_block fn##_nb = \
68307 { .notifier_call = fn, .priority = pri }; \
68308 register_cpu_notifier(&fn##_nb); \
68309 }
68310diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
68311index 037d36a..ca5fe6e 100644
68312--- a/include/linux/cpufreq.h
68313+++ b/include/linux/cpufreq.h
68314@@ -262,7 +262,7 @@ struct cpufreq_driver {
68315 int (*suspend) (struct cpufreq_policy *policy);
68316 int (*resume) (struct cpufreq_policy *policy);
68317 struct freq_attr **attr;
68318-};
68319+} __do_const;
68320
68321 /* flags */
68322
68323@@ -321,6 +321,7 @@ struct global_attr {
68324 ssize_t (*store)(struct kobject *a, struct attribute *b,
68325 const char *c, size_t count);
68326 };
68327+typedef struct global_attr __no_const global_attr_no_const;
68328
68329 #define define_one_global_ro(_name) \
68330 static struct global_attr _name = \
68331diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
68332index 8f04062..900239a 100644
68333--- a/include/linux/cpuidle.h
68334+++ b/include/linux/cpuidle.h
68335@@ -52,7 +52,8 @@ struct cpuidle_state {
68336 int index);
68337
68338 int (*enter_dead) (struct cpuidle_device *dev, int index);
68339-};
68340+} __do_const;
68341+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
68342
68343 /* Idle State Flags */
68344 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
68345@@ -191,7 +192,7 @@ struct cpuidle_governor {
68346 void (*reflect) (struct cpuidle_device *dev, int index);
68347
68348 struct module *owner;
68349-};
68350+} __do_const;
68351
68352 #ifdef CONFIG_CPU_IDLE
68353
68354diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
68355index d08e4d2..95fad61 100644
68356--- a/include/linux/cpumask.h
68357+++ b/include/linux/cpumask.h
68358@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68359 }
68360
68361 /* Valid inputs for n are -1 and 0. */
68362-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68363+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68364 {
68365 return n+1;
68366 }
68367
68368-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68369+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68370 {
68371 return n+1;
68372 }
68373
68374-static inline unsigned int cpumask_next_and(int n,
68375+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
68376 const struct cpumask *srcp,
68377 const struct cpumask *andp)
68378 {
68379@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68380 *
68381 * Returns >= nr_cpu_ids if no further cpus set.
68382 */
68383-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68384+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68385 {
68386 /* -1 is a legal arg here. */
68387 if (n != -1)
68388@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68389 *
68390 * Returns >= nr_cpu_ids if no further cpus unset.
68391 */
68392-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68393+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68394 {
68395 /* -1 is a legal arg here. */
68396 if (n != -1)
68397@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68398 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
68399 }
68400
68401-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
68402+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
68403 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
68404
68405 /**
68406diff --git a/include/linux/cred.h b/include/linux/cred.h
68407index 04421e8..6bce4ef 100644
68408--- a/include/linux/cred.h
68409+++ b/include/linux/cred.h
68410@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
68411 static inline void validate_process_creds(void)
68412 {
68413 }
68414+static inline void validate_task_creds(struct task_struct *task)
68415+{
68416+}
68417 #endif
68418
68419 /**
68420diff --git a/include/linux/crypto.h b/include/linux/crypto.h
68421index b92eadf..b4ecdc1 100644
68422--- a/include/linux/crypto.h
68423+++ b/include/linux/crypto.h
68424@@ -373,7 +373,7 @@ struct cipher_tfm {
68425 const u8 *key, unsigned int keylen);
68426 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68427 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68428-};
68429+} __no_const;
68430
68431 struct hash_tfm {
68432 int (*init)(struct hash_desc *desc);
68433@@ -394,13 +394,13 @@ struct compress_tfm {
68434 int (*cot_decompress)(struct crypto_tfm *tfm,
68435 const u8 *src, unsigned int slen,
68436 u8 *dst, unsigned int *dlen);
68437-};
68438+} __no_const;
68439
68440 struct rng_tfm {
68441 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
68442 unsigned int dlen);
68443 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
68444-};
68445+} __no_const;
68446
68447 #define crt_ablkcipher crt_u.ablkcipher
68448 #define crt_aead crt_u.aead
68449diff --git a/include/linux/ctype.h b/include/linux/ctype.h
68450index 653589e..4ef254a 100644
68451--- a/include/linux/ctype.h
68452+++ b/include/linux/ctype.h
68453@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
68454 * Fast implementation of tolower() for internal usage. Do not use in your
68455 * code.
68456 */
68457-static inline char _tolower(const char c)
68458+static inline unsigned char _tolower(const unsigned char c)
68459 {
68460 return c | 0x20;
68461 }
68462diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
68463index 7925bf0..d5143d2 100644
68464--- a/include/linux/decompress/mm.h
68465+++ b/include/linux/decompress/mm.h
68466@@ -77,7 +77,7 @@ static void free(void *where)
68467 * warnings when not needed (indeed large_malloc / large_free are not
68468 * needed by inflate */
68469
68470-#define malloc(a) kmalloc(a, GFP_KERNEL)
68471+#define malloc(a) kmalloc((a), GFP_KERNEL)
68472 #define free(a) kfree(a)
68473
68474 #define large_malloc(a) vmalloc(a)
68475diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
68476index fe8c447..bdc1f33 100644
68477--- a/include/linux/devfreq.h
68478+++ b/include/linux/devfreq.h
68479@@ -114,7 +114,7 @@ struct devfreq_governor {
68480 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
68481 int (*event_handler)(struct devfreq *devfreq,
68482 unsigned int event, void *data);
68483-};
68484+} __do_const;
68485
68486 /**
68487 * struct devfreq - Device devfreq structure
68488diff --git a/include/linux/device.h b/include/linux/device.h
68489index c0a1261..dba7569 100644
68490--- a/include/linux/device.h
68491+++ b/include/linux/device.h
68492@@ -290,7 +290,7 @@ struct subsys_interface {
68493 struct list_head node;
68494 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
68495 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
68496-};
68497+} __do_const;
68498
68499 int subsys_interface_register(struct subsys_interface *sif);
68500 void subsys_interface_unregister(struct subsys_interface *sif);
68501@@ -473,7 +473,7 @@ struct device_type {
68502 void (*release)(struct device *dev);
68503
68504 const struct dev_pm_ops *pm;
68505-};
68506+} __do_const;
68507
68508 /* interface for exporting device attributes */
68509 struct device_attribute {
68510@@ -483,11 +483,12 @@ struct device_attribute {
68511 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
68512 const char *buf, size_t count);
68513 };
68514+typedef struct device_attribute __no_const device_attribute_no_const;
68515
68516 struct dev_ext_attribute {
68517 struct device_attribute attr;
68518 void *var;
68519-};
68520+} __do_const;
68521
68522 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
68523 char *buf);
68524diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
68525index 94af418..b1ca7a2 100644
68526--- a/include/linux/dma-mapping.h
68527+++ b/include/linux/dma-mapping.h
68528@@ -54,7 +54,7 @@ struct dma_map_ops {
68529 u64 (*get_required_mask)(struct device *dev);
68530 #endif
68531 int is_phys;
68532-};
68533+} __do_const;
68534
68535 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
68536
68537diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
68538index 96d3e4a..dc36433 100644
68539--- a/include/linux/dmaengine.h
68540+++ b/include/linux/dmaengine.h
68541@@ -1035,9 +1035,9 @@ struct dma_pinned_list {
68542 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
68543 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
68544
68545-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68546+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68547 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
68548-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68549+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68550 struct dma_pinned_list *pinned_list, struct page *page,
68551 unsigned int offset, size_t len);
68552
68553diff --git a/include/linux/efi.h b/include/linux/efi.h
68554index 2bc0ad7..3f7b006 100644
68555--- a/include/linux/efi.h
68556+++ b/include/linux/efi.h
68557@@ -745,6 +745,7 @@ struct efivar_operations {
68558 efi_set_variable_t *set_variable;
68559 efi_query_variable_store_t *query_variable_store;
68560 };
68561+typedef struct efivar_operations __no_const efivar_operations_no_const;
68562
68563 struct efivars {
68564 /*
68565diff --git a/include/linux/elf.h b/include/linux/elf.h
68566index 40a3c0e..4c45a38 100644
68567--- a/include/linux/elf.h
68568+++ b/include/linux/elf.h
68569@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
68570 #define elf_note elf32_note
68571 #define elf_addr_t Elf32_Off
68572 #define Elf_Half Elf32_Half
68573+#define elf_dyn Elf32_Dyn
68574
68575 #else
68576
68577@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
68578 #define elf_note elf64_note
68579 #define elf_addr_t Elf64_Off
68580 #define Elf_Half Elf64_Half
68581+#define elf_dyn Elf64_Dyn
68582
68583 #endif
68584
68585diff --git a/include/linux/err.h b/include/linux/err.h
68586index f2edce2..cc2082c 100644
68587--- a/include/linux/err.h
68588+++ b/include/linux/err.h
68589@@ -19,12 +19,12 @@
68590
68591 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
68592
68593-static inline void * __must_check ERR_PTR(long error)
68594+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
68595 {
68596 return (void *) error;
68597 }
68598
68599-static inline long __must_check PTR_ERR(const void *ptr)
68600+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
68601 {
68602 return (long) ptr;
68603 }
68604diff --git a/include/linux/extcon.h b/include/linux/extcon.h
68605index fcb51c8..bdafcf6 100644
68606--- a/include/linux/extcon.h
68607+++ b/include/linux/extcon.h
68608@@ -134,7 +134,7 @@ struct extcon_dev {
68609 /* /sys/class/extcon/.../mutually_exclusive/... */
68610 struct attribute_group attr_g_muex;
68611 struct attribute **attrs_muex;
68612- struct device_attribute *d_attrs_muex;
68613+ device_attribute_no_const *d_attrs_muex;
68614 };
68615
68616 /**
68617diff --git a/include/linux/fb.h b/include/linux/fb.h
68618index d49c60f..2834fbe 100644
68619--- a/include/linux/fb.h
68620+++ b/include/linux/fb.h
68621@@ -304,7 +304,7 @@ struct fb_ops {
68622 /* called at KDB enter and leave time to prepare the console */
68623 int (*fb_debug_enter)(struct fb_info *info);
68624 int (*fb_debug_leave)(struct fb_info *info);
68625-};
68626+} __do_const;
68627
68628 #ifdef CONFIG_FB_TILEBLITTING
68629 #define FB_TILE_CURSOR_NONE 0
68630diff --git a/include/linux/filter.h b/include/linux/filter.h
68631index f65f5a6..2f4f93a 100644
68632--- a/include/linux/filter.h
68633+++ b/include/linux/filter.h
68634@@ -20,6 +20,7 @@ struct compat_sock_fprog {
68635
68636 struct sk_buff;
68637 struct sock;
68638+struct bpf_jit_work;
68639
68640 struct sk_filter
68641 {
68642@@ -27,6 +28,9 @@ struct sk_filter
68643 unsigned int len; /* Number of filter blocks */
68644 unsigned int (*bpf_func)(const struct sk_buff *skb,
68645 const struct sock_filter *filter);
68646+#ifdef CONFIG_BPF_JIT
68647+ struct bpf_jit_work *work;
68648+#endif
68649 struct rcu_head rcu;
68650 struct sock_filter insns[0];
68651 };
68652diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
68653index 8293262..2b3b8bd 100644
68654--- a/include/linux/frontswap.h
68655+++ b/include/linux/frontswap.h
68656@@ -11,7 +11,7 @@ struct frontswap_ops {
68657 int (*load)(unsigned, pgoff_t, struct page *);
68658 void (*invalidate_page)(unsigned, pgoff_t);
68659 void (*invalidate_area)(unsigned);
68660-};
68661+} __no_const;
68662
68663 extern bool frontswap_enabled;
68664 extern struct frontswap_ops *
68665diff --git a/include/linux/fs.h b/include/linux/fs.h
68666index 65c2be2..4c53f6e 100644
68667--- a/include/linux/fs.h
68668+++ b/include/linux/fs.h
68669@@ -1543,7 +1543,8 @@ struct file_operations {
68670 long (*fallocate)(struct file *file, int mode, loff_t offset,
68671 loff_t len);
68672 int (*show_fdinfo)(struct seq_file *m, struct file *f);
68673-};
68674+} __do_const;
68675+typedef struct file_operations __no_const file_operations_no_const;
68676
68677 struct inode_operations {
68678 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
68679@@ -2688,4 +2689,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
68680 inode->i_flags |= S_NOSEC;
68681 }
68682
68683+static inline bool is_sidechannel_device(const struct inode *inode)
68684+{
68685+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
68686+ umode_t mode = inode->i_mode;
68687+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
68688+#else
68689+ return false;
68690+#endif
68691+}
68692+
68693 #endif /* _LINUX_FS_H */
68694diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
68695index 2b93a9a..855d94a 100644
68696--- a/include/linux/fs_struct.h
68697+++ b/include/linux/fs_struct.h
68698@@ -6,7 +6,7 @@
68699 #include <linux/seqlock.h>
68700
68701 struct fs_struct {
68702- int users;
68703+ atomic_t users;
68704 spinlock_t lock;
68705 seqcount_t seq;
68706 int umask;
68707diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
68708index 5dfa0aa..6acf322 100644
68709--- a/include/linux/fscache-cache.h
68710+++ b/include/linux/fscache-cache.h
68711@@ -112,7 +112,7 @@ struct fscache_operation {
68712 fscache_operation_release_t release;
68713 };
68714
68715-extern atomic_t fscache_op_debug_id;
68716+extern atomic_unchecked_t fscache_op_debug_id;
68717 extern void fscache_op_work_func(struct work_struct *work);
68718
68719 extern void fscache_enqueue_operation(struct fscache_operation *);
68720@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
68721 INIT_WORK(&op->work, fscache_op_work_func);
68722 atomic_set(&op->usage, 1);
68723 op->state = FSCACHE_OP_ST_INITIALISED;
68724- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
68725+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
68726 op->processor = processor;
68727 op->release = release;
68728 INIT_LIST_HEAD(&op->pend_link);
68729diff --git a/include/linux/fscache.h b/include/linux/fscache.h
68730index 7a08623..4c07b0f 100644
68731--- a/include/linux/fscache.h
68732+++ b/include/linux/fscache.h
68733@@ -152,7 +152,7 @@ struct fscache_cookie_def {
68734 * - this is mandatory for any object that may have data
68735 */
68736 void (*now_uncached)(void *cookie_netfs_data);
68737-};
68738+} __do_const;
68739
68740 /*
68741 * fscache cached network filesystem type
68742diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
68743index a78680a..87bd73e 100644
68744--- a/include/linux/fsnotify.h
68745+++ b/include/linux/fsnotify.h
68746@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
68747 struct inode *inode = path->dentry->d_inode;
68748 __u32 mask = FS_ACCESS;
68749
68750+ if (is_sidechannel_device(inode))
68751+ return;
68752+
68753 if (S_ISDIR(inode->i_mode))
68754 mask |= FS_ISDIR;
68755
68756@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
68757 struct inode *inode = path->dentry->d_inode;
68758 __u32 mask = FS_MODIFY;
68759
68760+ if (is_sidechannel_device(inode))
68761+ return;
68762+
68763 if (S_ISDIR(inode->i_mode))
68764 mask |= FS_ISDIR;
68765
68766@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
68767 */
68768 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
68769 {
68770- return kstrdup(name, GFP_KERNEL);
68771+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
68772 }
68773
68774 /*
68775diff --git a/include/linux/genhd.h b/include/linux/genhd.h
68776index 9f3c275..911b591 100644
68777--- a/include/linux/genhd.h
68778+++ b/include/linux/genhd.h
68779@@ -194,7 +194,7 @@ struct gendisk {
68780 struct kobject *slave_dir;
68781
68782 struct timer_rand_state *random;
68783- atomic_t sync_io; /* RAID */
68784+ atomic_unchecked_t sync_io; /* RAID */
68785 struct disk_events *ev;
68786 #ifdef CONFIG_BLK_DEV_INTEGRITY
68787 struct blk_integrity *integrity;
68788diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
68789index 023bc34..b02b46a 100644
68790--- a/include/linux/genl_magic_func.h
68791+++ b/include/linux/genl_magic_func.h
68792@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
68793 },
68794
68795 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
68796-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
68797+static struct genl_ops ZZZ_genl_ops[] = {
68798 #include GENL_MAGIC_INCLUDE_FILE
68799 };
68800
68801diff --git a/include/linux/gfp.h b/include/linux/gfp.h
68802index 0f615eb..5c3832f 100644
68803--- a/include/linux/gfp.h
68804+++ b/include/linux/gfp.h
68805@@ -35,6 +35,13 @@ struct vm_area_struct;
68806 #define ___GFP_NO_KSWAPD 0x400000u
68807 #define ___GFP_OTHER_NODE 0x800000u
68808 #define ___GFP_WRITE 0x1000000u
68809+
68810+#ifdef CONFIG_PAX_USERCOPY_SLABS
68811+#define ___GFP_USERCOPY 0x2000000u
68812+#else
68813+#define ___GFP_USERCOPY 0
68814+#endif
68815+
68816 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
68817
68818 /*
68819@@ -92,6 +99,7 @@ struct vm_area_struct;
68820 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
68821 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
68822 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
68823+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
68824
68825 /*
68826 * This may seem redundant, but it's a way of annotating false positives vs.
68827@@ -99,7 +107,7 @@ struct vm_area_struct;
68828 */
68829 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
68830
68831-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
68832+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
68833 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
68834
68835 /* This equals 0, but use constants in case they ever change */
68836@@ -153,6 +161,8 @@ struct vm_area_struct;
68837 /* 4GB DMA on some platforms */
68838 #define GFP_DMA32 __GFP_DMA32
68839
68840+#define GFP_USERCOPY __GFP_USERCOPY
68841+
68842 /* Convert GFP flags to their corresponding migrate type */
68843 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
68844 {
68845diff --git a/include/linux/gracl.h b/include/linux/gracl.h
68846new file mode 100644
68847index 0000000..ebe6d72
68848--- /dev/null
68849+++ b/include/linux/gracl.h
68850@@ -0,0 +1,319 @@
68851+#ifndef GR_ACL_H
68852+#define GR_ACL_H
68853+
68854+#include <linux/grdefs.h>
68855+#include <linux/resource.h>
68856+#include <linux/capability.h>
68857+#include <linux/dcache.h>
68858+#include <asm/resource.h>
68859+
68860+/* Major status information */
68861+
68862+#define GR_VERSION "grsecurity 2.9.1"
68863+#define GRSECURITY_VERSION 0x2901
68864+
68865+enum {
68866+ GR_SHUTDOWN = 0,
68867+ GR_ENABLE = 1,
68868+ GR_SPROLE = 2,
68869+ GR_RELOAD = 3,
68870+ GR_SEGVMOD = 4,
68871+ GR_STATUS = 5,
68872+ GR_UNSPROLE = 6,
68873+ GR_PASSSET = 7,
68874+ GR_SPROLEPAM = 8,
68875+};
68876+
68877+/* Password setup definitions
68878+ * kernel/grhash.c */
68879+enum {
68880+ GR_PW_LEN = 128,
68881+ GR_SALT_LEN = 16,
68882+ GR_SHA_LEN = 32,
68883+};
68884+
68885+enum {
68886+ GR_SPROLE_LEN = 64,
68887+};
68888+
68889+enum {
68890+ GR_NO_GLOB = 0,
68891+ GR_REG_GLOB,
68892+ GR_CREATE_GLOB
68893+};
68894+
68895+#define GR_NLIMITS 32
68896+
68897+/* Begin Data Structures */
68898+
68899+struct sprole_pw {
68900+ unsigned char *rolename;
68901+ unsigned char salt[GR_SALT_LEN];
68902+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
68903+};
68904+
68905+struct name_entry {
68906+ __u32 key;
68907+ ino_t inode;
68908+ dev_t device;
68909+ char *name;
68910+ __u16 len;
68911+ __u8 deleted;
68912+ struct name_entry *prev;
68913+ struct name_entry *next;
68914+};
68915+
68916+struct inodev_entry {
68917+ struct name_entry *nentry;
68918+ struct inodev_entry *prev;
68919+ struct inodev_entry *next;
68920+};
68921+
68922+struct acl_role_db {
68923+ struct acl_role_label **r_hash;
68924+ __u32 r_size;
68925+};
68926+
68927+struct inodev_db {
68928+ struct inodev_entry **i_hash;
68929+ __u32 i_size;
68930+};
68931+
68932+struct name_db {
68933+ struct name_entry **n_hash;
68934+ __u32 n_size;
68935+};
68936+
68937+struct crash_uid {
68938+ uid_t uid;
68939+ unsigned long expires;
68940+};
68941+
68942+struct gr_hash_struct {
68943+ void **table;
68944+ void **nametable;
68945+ void *first;
68946+ __u32 table_size;
68947+ __u32 used_size;
68948+ int type;
68949+};
68950+
68951+/* Userspace Grsecurity ACL data structures */
68952+
68953+struct acl_subject_label {
68954+ char *filename;
68955+ ino_t inode;
68956+ dev_t device;
68957+ __u32 mode;
68958+ kernel_cap_t cap_mask;
68959+ kernel_cap_t cap_lower;
68960+ kernel_cap_t cap_invert_audit;
68961+
68962+ struct rlimit res[GR_NLIMITS];
68963+ __u32 resmask;
68964+
68965+ __u8 user_trans_type;
68966+ __u8 group_trans_type;
68967+ uid_t *user_transitions;
68968+ gid_t *group_transitions;
68969+ __u16 user_trans_num;
68970+ __u16 group_trans_num;
68971+
68972+ __u32 sock_families[2];
68973+ __u32 ip_proto[8];
68974+ __u32 ip_type;
68975+ struct acl_ip_label **ips;
68976+ __u32 ip_num;
68977+ __u32 inaddr_any_override;
68978+
68979+ __u32 crashes;
68980+ unsigned long expires;
68981+
68982+ struct acl_subject_label *parent_subject;
68983+ struct gr_hash_struct *hash;
68984+ struct acl_subject_label *prev;
68985+ struct acl_subject_label *next;
68986+
68987+ struct acl_object_label **obj_hash;
68988+ __u32 obj_hash_size;
68989+ __u16 pax_flags;
68990+};
68991+
68992+struct role_allowed_ip {
68993+ __u32 addr;
68994+ __u32 netmask;
68995+
68996+ struct role_allowed_ip *prev;
68997+ struct role_allowed_ip *next;
68998+};
68999+
69000+struct role_transition {
69001+ char *rolename;
69002+
69003+ struct role_transition *prev;
69004+ struct role_transition *next;
69005+};
69006+
69007+struct acl_role_label {
69008+ char *rolename;
69009+ uid_t uidgid;
69010+ __u16 roletype;
69011+
69012+ __u16 auth_attempts;
69013+ unsigned long expires;
69014+
69015+ struct acl_subject_label *root_label;
69016+ struct gr_hash_struct *hash;
69017+
69018+ struct acl_role_label *prev;
69019+ struct acl_role_label *next;
69020+
69021+ struct role_transition *transitions;
69022+ struct role_allowed_ip *allowed_ips;
69023+ uid_t *domain_children;
69024+ __u16 domain_child_num;
69025+
69026+ umode_t umask;
69027+
69028+ struct acl_subject_label **subj_hash;
69029+ __u32 subj_hash_size;
69030+};
69031+
69032+struct user_acl_role_db {
69033+ struct acl_role_label **r_table;
69034+ __u32 num_pointers; /* Number of allocations to track */
69035+ __u32 num_roles; /* Number of roles */
69036+ __u32 num_domain_children; /* Number of domain children */
69037+ __u32 num_subjects; /* Number of subjects */
69038+ __u32 num_objects; /* Number of objects */
69039+};
69040+
69041+struct acl_object_label {
69042+ char *filename;
69043+ ino_t inode;
69044+ dev_t device;
69045+ __u32 mode;
69046+
69047+ struct acl_subject_label *nested;
69048+ struct acl_object_label *globbed;
69049+
69050+ /* next two structures not used */
69051+
69052+ struct acl_object_label *prev;
69053+ struct acl_object_label *next;
69054+};
69055+
69056+struct acl_ip_label {
69057+ char *iface;
69058+ __u32 addr;
69059+ __u32 netmask;
69060+ __u16 low, high;
69061+ __u8 mode;
69062+ __u32 type;
69063+ __u32 proto[8];
69064+
69065+ /* next two structures not used */
69066+
69067+ struct acl_ip_label *prev;
69068+ struct acl_ip_label *next;
69069+};
69070+
69071+struct gr_arg {
69072+ struct user_acl_role_db role_db;
69073+ unsigned char pw[GR_PW_LEN];
69074+ unsigned char salt[GR_SALT_LEN];
69075+ unsigned char sum[GR_SHA_LEN];
69076+ unsigned char sp_role[GR_SPROLE_LEN];
69077+ struct sprole_pw *sprole_pws;
69078+ dev_t segv_device;
69079+ ino_t segv_inode;
69080+ uid_t segv_uid;
69081+ __u16 num_sprole_pws;
69082+ __u16 mode;
69083+};
69084+
69085+struct gr_arg_wrapper {
69086+ struct gr_arg *arg;
69087+ __u32 version;
69088+ __u32 size;
69089+};
69090+
69091+struct subject_map {
69092+ struct acl_subject_label *user;
69093+ struct acl_subject_label *kernel;
69094+ struct subject_map *prev;
69095+ struct subject_map *next;
69096+};
69097+
69098+struct acl_subj_map_db {
69099+ struct subject_map **s_hash;
69100+ __u32 s_size;
69101+};
69102+
69103+/* End Data Structures Section */
69104+
69105+/* Hash functions generated by empirical testing by Brad Spengler
69106+ Makes good use of the low bits of the inode. Generally 0-1 times
69107+ in loop for successful match. 0-3 for unsuccessful match.
69108+ Shift/add algorithm with modulus of table size and an XOR*/
69109+
69110+static __inline__ unsigned int
69111+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
69112+{
69113+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
69114+}
69115+
69116+ static __inline__ unsigned int
69117+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
69118+{
69119+ return ((const unsigned long)userp % sz);
69120+}
69121+
69122+static __inline__ unsigned int
69123+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
69124+{
69125+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
69126+}
69127+
69128+static __inline__ unsigned int
69129+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
69130+{
69131+ return full_name_hash((const unsigned char *)name, len) % sz;
69132+}
69133+
69134+#define FOR_EACH_ROLE_START(role) \
69135+ role = role_list; \
69136+ while (role) {
69137+
69138+#define FOR_EACH_ROLE_END(role) \
69139+ role = role->prev; \
69140+ }
69141+
69142+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
69143+ subj = NULL; \
69144+ iter = 0; \
69145+ while (iter < role->subj_hash_size) { \
69146+ if (subj == NULL) \
69147+ subj = role->subj_hash[iter]; \
69148+ if (subj == NULL) { \
69149+ iter++; \
69150+ continue; \
69151+ }
69152+
69153+#define FOR_EACH_SUBJECT_END(subj,iter) \
69154+ subj = subj->next; \
69155+ if (subj == NULL) \
69156+ iter++; \
69157+ }
69158+
69159+
69160+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
69161+ subj = role->hash->first; \
69162+ while (subj != NULL) {
69163+
69164+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
69165+ subj = subj->next; \
69166+ }
69167+
69168+#endif
69169+
69170diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
69171new file mode 100644
69172index 0000000..323ecf2
69173--- /dev/null
69174+++ b/include/linux/gralloc.h
69175@@ -0,0 +1,9 @@
69176+#ifndef __GRALLOC_H
69177+#define __GRALLOC_H
69178+
69179+void acl_free_all(void);
69180+int acl_alloc_stack_init(unsigned long size);
69181+void *acl_alloc(unsigned long len);
69182+void *acl_alloc_num(unsigned long num, unsigned long len);
69183+
69184+#endif
69185diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
69186new file mode 100644
69187index 0000000..be66033
69188--- /dev/null
69189+++ b/include/linux/grdefs.h
69190@@ -0,0 +1,140 @@
69191+#ifndef GRDEFS_H
69192+#define GRDEFS_H
69193+
69194+/* Begin grsecurity status declarations */
69195+
69196+enum {
69197+ GR_READY = 0x01,
69198+ GR_STATUS_INIT = 0x00 // disabled state
69199+};
69200+
69201+/* Begin ACL declarations */
69202+
69203+/* Role flags */
69204+
69205+enum {
69206+ GR_ROLE_USER = 0x0001,
69207+ GR_ROLE_GROUP = 0x0002,
69208+ GR_ROLE_DEFAULT = 0x0004,
69209+ GR_ROLE_SPECIAL = 0x0008,
69210+ GR_ROLE_AUTH = 0x0010,
69211+ GR_ROLE_NOPW = 0x0020,
69212+ GR_ROLE_GOD = 0x0040,
69213+ GR_ROLE_LEARN = 0x0080,
69214+ GR_ROLE_TPE = 0x0100,
69215+ GR_ROLE_DOMAIN = 0x0200,
69216+ GR_ROLE_PAM = 0x0400,
69217+ GR_ROLE_PERSIST = 0x0800
69218+};
69219+
69220+/* ACL Subject and Object mode flags */
69221+enum {
69222+ GR_DELETED = 0x80000000
69223+};
69224+
69225+/* ACL Object-only mode flags */
69226+enum {
69227+ GR_READ = 0x00000001,
69228+ GR_APPEND = 0x00000002,
69229+ GR_WRITE = 0x00000004,
69230+ GR_EXEC = 0x00000008,
69231+ GR_FIND = 0x00000010,
69232+ GR_INHERIT = 0x00000020,
69233+ GR_SETID = 0x00000040,
69234+ GR_CREATE = 0x00000080,
69235+ GR_DELETE = 0x00000100,
69236+ GR_LINK = 0x00000200,
69237+ GR_AUDIT_READ = 0x00000400,
69238+ GR_AUDIT_APPEND = 0x00000800,
69239+ GR_AUDIT_WRITE = 0x00001000,
69240+ GR_AUDIT_EXEC = 0x00002000,
69241+ GR_AUDIT_FIND = 0x00004000,
69242+ GR_AUDIT_INHERIT= 0x00008000,
69243+ GR_AUDIT_SETID = 0x00010000,
69244+ GR_AUDIT_CREATE = 0x00020000,
69245+ GR_AUDIT_DELETE = 0x00040000,
69246+ GR_AUDIT_LINK = 0x00080000,
69247+ GR_PTRACERD = 0x00100000,
69248+ GR_NOPTRACE = 0x00200000,
69249+ GR_SUPPRESS = 0x00400000,
69250+ GR_NOLEARN = 0x00800000,
69251+ GR_INIT_TRANSFER= 0x01000000
69252+};
69253+
69254+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
69255+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
69256+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
69257+
69258+/* ACL subject-only mode flags */
69259+enum {
69260+ GR_KILL = 0x00000001,
69261+ GR_VIEW = 0x00000002,
69262+ GR_PROTECTED = 0x00000004,
69263+ GR_LEARN = 0x00000008,
69264+ GR_OVERRIDE = 0x00000010,
69265+ /* just a placeholder, this mode is only used in userspace */
69266+ GR_DUMMY = 0x00000020,
69267+ GR_PROTSHM = 0x00000040,
69268+ GR_KILLPROC = 0x00000080,
69269+ GR_KILLIPPROC = 0x00000100,
69270+ /* just a placeholder, this mode is only used in userspace */
69271+ GR_NOTROJAN = 0x00000200,
69272+ GR_PROTPROCFD = 0x00000400,
69273+ GR_PROCACCT = 0x00000800,
69274+ GR_RELAXPTRACE = 0x00001000,
69275+ //GR_NESTED = 0x00002000,
69276+ GR_INHERITLEARN = 0x00004000,
69277+ GR_PROCFIND = 0x00008000,
69278+ GR_POVERRIDE = 0x00010000,
69279+ GR_KERNELAUTH = 0x00020000,
69280+ GR_ATSECURE = 0x00040000,
69281+ GR_SHMEXEC = 0x00080000
69282+};
69283+
69284+enum {
69285+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
69286+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
69287+ GR_PAX_ENABLE_MPROTECT = 0x0004,
69288+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
69289+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
69290+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
69291+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
69292+ GR_PAX_DISABLE_MPROTECT = 0x0400,
69293+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
69294+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
69295+};
69296+
69297+enum {
69298+ GR_ID_USER = 0x01,
69299+ GR_ID_GROUP = 0x02,
69300+};
69301+
69302+enum {
69303+ GR_ID_ALLOW = 0x01,
69304+ GR_ID_DENY = 0x02,
69305+};
69306+
69307+#define GR_CRASH_RES 31
69308+#define GR_UIDTABLE_MAX 500
69309+
69310+/* begin resource learning section */
69311+enum {
69312+ GR_RLIM_CPU_BUMP = 60,
69313+ GR_RLIM_FSIZE_BUMP = 50000,
69314+ GR_RLIM_DATA_BUMP = 10000,
69315+ GR_RLIM_STACK_BUMP = 1000,
69316+ GR_RLIM_CORE_BUMP = 10000,
69317+ GR_RLIM_RSS_BUMP = 500000,
69318+ GR_RLIM_NPROC_BUMP = 1,
69319+ GR_RLIM_NOFILE_BUMP = 5,
69320+ GR_RLIM_MEMLOCK_BUMP = 50000,
69321+ GR_RLIM_AS_BUMP = 500000,
69322+ GR_RLIM_LOCKS_BUMP = 2,
69323+ GR_RLIM_SIGPENDING_BUMP = 5,
69324+ GR_RLIM_MSGQUEUE_BUMP = 10000,
69325+ GR_RLIM_NICE_BUMP = 1,
69326+ GR_RLIM_RTPRIO_BUMP = 1,
69327+ GR_RLIM_RTTIME_BUMP = 1000000
69328+};
69329+
69330+#endif
69331diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
69332new file mode 100644
69333index 0000000..12994b5
69334--- /dev/null
69335+++ b/include/linux/grinternal.h
69336@@ -0,0 +1,227 @@
69337+#ifndef __GRINTERNAL_H
69338+#define __GRINTERNAL_H
69339+
69340+#ifdef CONFIG_GRKERNSEC
69341+
69342+#include <linux/fs.h>
69343+#include <linux/mnt_namespace.h>
69344+#include <linux/nsproxy.h>
69345+#include <linux/gracl.h>
69346+#include <linux/grdefs.h>
69347+#include <linux/grmsg.h>
69348+
69349+void gr_add_learn_entry(const char *fmt, ...)
69350+ __attribute__ ((format (printf, 1, 2)));
69351+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
69352+ const struct vfsmount *mnt);
69353+__u32 gr_check_create(const struct dentry *new_dentry,
69354+ const struct dentry *parent,
69355+ const struct vfsmount *mnt, const __u32 mode);
69356+int gr_check_protected_task(const struct task_struct *task);
69357+__u32 to_gr_audit(const __u32 reqmode);
69358+int gr_set_acls(const int type);
69359+int gr_apply_subject_to_task(struct task_struct *task);
69360+int gr_acl_is_enabled(void);
69361+char gr_roletype_to_char(void);
69362+
69363+void gr_handle_alertkill(struct task_struct *task);
69364+char *gr_to_filename(const struct dentry *dentry,
69365+ const struct vfsmount *mnt);
69366+char *gr_to_filename1(const struct dentry *dentry,
69367+ const struct vfsmount *mnt);
69368+char *gr_to_filename2(const struct dentry *dentry,
69369+ const struct vfsmount *mnt);
69370+char *gr_to_filename3(const struct dentry *dentry,
69371+ const struct vfsmount *mnt);
69372+
69373+extern int grsec_enable_ptrace_readexec;
69374+extern int grsec_enable_harden_ptrace;
69375+extern int grsec_enable_link;
69376+extern int grsec_enable_fifo;
69377+extern int grsec_enable_execve;
69378+extern int grsec_enable_shm;
69379+extern int grsec_enable_execlog;
69380+extern int grsec_enable_signal;
69381+extern int grsec_enable_audit_ptrace;
69382+extern int grsec_enable_forkfail;
69383+extern int grsec_enable_time;
69384+extern int grsec_enable_rofs;
69385+extern int grsec_enable_chroot_shmat;
69386+extern int grsec_enable_chroot_mount;
69387+extern int grsec_enable_chroot_double;
69388+extern int grsec_enable_chroot_pivot;
69389+extern int grsec_enable_chroot_chdir;
69390+extern int grsec_enable_chroot_chmod;
69391+extern int grsec_enable_chroot_mknod;
69392+extern int grsec_enable_chroot_fchdir;
69393+extern int grsec_enable_chroot_nice;
69394+extern int grsec_enable_chroot_execlog;
69395+extern int grsec_enable_chroot_caps;
69396+extern int grsec_enable_chroot_sysctl;
69397+extern int grsec_enable_chroot_unix;
69398+extern int grsec_enable_symlinkown;
69399+extern kgid_t grsec_symlinkown_gid;
69400+extern int grsec_enable_tpe;
69401+extern kgid_t grsec_tpe_gid;
69402+extern int grsec_enable_tpe_all;
69403+extern int grsec_enable_tpe_invert;
69404+extern int grsec_enable_socket_all;
69405+extern kgid_t grsec_socket_all_gid;
69406+extern int grsec_enable_socket_client;
69407+extern kgid_t grsec_socket_client_gid;
69408+extern int grsec_enable_socket_server;
69409+extern kgid_t grsec_socket_server_gid;
69410+extern kgid_t grsec_audit_gid;
69411+extern int grsec_enable_group;
69412+extern int grsec_enable_audit_textrel;
69413+extern int grsec_enable_log_rwxmaps;
69414+extern int grsec_enable_mount;
69415+extern int grsec_enable_chdir;
69416+extern int grsec_resource_logging;
69417+extern int grsec_enable_blackhole;
69418+extern int grsec_lastack_retries;
69419+extern int grsec_enable_brute;
69420+extern int grsec_lock;
69421+
69422+extern spinlock_t grsec_alert_lock;
69423+extern unsigned long grsec_alert_wtime;
69424+extern unsigned long grsec_alert_fyet;
69425+
69426+extern spinlock_t grsec_audit_lock;
69427+
69428+extern rwlock_t grsec_exec_file_lock;
69429+
69430+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
69431+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
69432+ (tsk)->exec_file->f_path.mnt) : "/")
69433+
69434+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
69435+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
69436+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
69437+
69438+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
69439+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
69440+ (tsk)->exec_file->f_path.mnt) : "/")
69441+
69442+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
69443+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
69444+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
69445+
69446+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
69447+
69448+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
69449+
69450+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
69451+{
69452+ if (file1 && file2) {
69453+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
69454+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
69455+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
69456+ return true;
69457+ }
69458+
69459+ return false;
69460+}
69461+
69462+#define GR_CHROOT_CAPS {{ \
69463+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
69464+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
69465+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
69466+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
69467+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
69468+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
69469+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
69470+
69471+#define security_learn(normal_msg,args...) \
69472+({ \
69473+ read_lock(&grsec_exec_file_lock); \
69474+ gr_add_learn_entry(normal_msg "\n", ## args); \
69475+ read_unlock(&grsec_exec_file_lock); \
69476+})
69477+
69478+enum {
69479+ GR_DO_AUDIT,
69480+ GR_DONT_AUDIT,
69481+ /* used for non-audit messages that we shouldn't kill the task on */
69482+ GR_DONT_AUDIT_GOOD
69483+};
69484+
69485+enum {
69486+ GR_TTYSNIFF,
69487+ GR_RBAC,
69488+ GR_RBAC_STR,
69489+ GR_STR_RBAC,
69490+ GR_RBAC_MODE2,
69491+ GR_RBAC_MODE3,
69492+ GR_FILENAME,
69493+ GR_SYSCTL_HIDDEN,
69494+ GR_NOARGS,
69495+ GR_ONE_INT,
69496+ GR_ONE_INT_TWO_STR,
69497+ GR_ONE_STR,
69498+ GR_STR_INT,
69499+ GR_TWO_STR_INT,
69500+ GR_TWO_INT,
69501+ GR_TWO_U64,
69502+ GR_THREE_INT,
69503+ GR_FIVE_INT_TWO_STR,
69504+ GR_TWO_STR,
69505+ GR_THREE_STR,
69506+ GR_FOUR_STR,
69507+ GR_STR_FILENAME,
69508+ GR_FILENAME_STR,
69509+ GR_FILENAME_TWO_INT,
69510+ GR_FILENAME_TWO_INT_STR,
69511+ GR_TEXTREL,
69512+ GR_PTRACE,
69513+ GR_RESOURCE,
69514+ GR_CAP,
69515+ GR_SIG,
69516+ GR_SIG2,
69517+ GR_CRASH1,
69518+ GR_CRASH2,
69519+ GR_PSACCT,
69520+ GR_RWXMAP
69521+};
69522+
69523+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
69524+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
69525+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
69526+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
69527+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
69528+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
69529+#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)
69530+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
69531+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
69532+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
69533+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
69534+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
69535+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
69536+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
69537+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
69538+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
69539+#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)
69540+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
69541+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
69542+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
69543+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
69544+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
69545+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
69546+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
69547+#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)
69548+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
69549+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
69550+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
69551+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
69552+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
69553+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
69554+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
69555+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
69556+#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)
69557+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
69558+
69559+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
69560+
69561+#endif
69562+
69563+#endif
69564diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
69565new file mode 100644
69566index 0000000..2f159b5
69567--- /dev/null
69568+++ b/include/linux/grmsg.h
69569@@ -0,0 +1,112 @@
69570+#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"
69571+#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"
69572+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
69573+#define GR_STOPMOD_MSG "denied modification of module state by "
69574+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
69575+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
69576+#define GR_IOPERM_MSG "denied use of ioperm() by "
69577+#define GR_IOPL_MSG "denied use of iopl() by "
69578+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
69579+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
69580+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
69581+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
69582+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
69583+#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"
69584+#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"
69585+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
69586+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
69587+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
69588+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
69589+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
69590+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
69591+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
69592+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
69593+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
69594+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
69595+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
69596+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
69597+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
69598+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
69599+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
69600+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
69601+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
69602+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
69603+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
69604+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
69605+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
69606+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
69607+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
69608+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
69609+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
69610+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
69611+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
69612+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
69613+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
69614+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
69615+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
69616+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
69617+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
69618+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
69619+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
69620+#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"
69621+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
69622+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
69623+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
69624+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
69625+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
69626+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
69627+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
69628+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
69629+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
69630+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
69631+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
69632+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
69633+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
69634+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
69635+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
69636+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
69637+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
69638+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
69639+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
69640+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
69641+#define GR_FAILFORK_MSG "failed fork with errno %s by "
69642+#define GR_NICE_CHROOT_MSG "denied priority change by "
69643+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
69644+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
69645+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
69646+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
69647+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
69648+#define GR_TIME_MSG "time set by "
69649+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
69650+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
69651+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
69652+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
69653+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
69654+#define GR_BIND_MSG "denied bind() by "
69655+#define GR_CONNECT_MSG "denied connect() by "
69656+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
69657+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
69658+#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"
69659+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
69660+#define GR_CAP_ACL_MSG "use of %s denied for "
69661+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
69662+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
69663+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
69664+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
69665+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
69666+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
69667+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
69668+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
69669+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
69670+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
69671+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
69672+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
69673+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
69674+#define GR_VM86_MSG "denied use of vm86 by "
69675+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
69676+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
69677+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
69678+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
69679+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
69680+#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 "
69681+#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 "
69682diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
69683new file mode 100644
69684index 0000000..d957f6d
69685--- /dev/null
69686+++ b/include/linux/grsecurity.h
69687@@ -0,0 +1,241 @@
69688+#ifndef GR_SECURITY_H
69689+#define GR_SECURITY_H
69690+#include <linux/fs.h>
69691+#include <linux/fs_struct.h>
69692+#include <linux/binfmts.h>
69693+#include <linux/gracl.h>
69694+
69695+/* notify of brain-dead configs */
69696+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69697+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
69698+#endif
69699+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
69700+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
69701+#endif
69702+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
69703+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
69704+#endif
69705+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
69706+#error "CONFIG_PAX enabled, but no PaX options are enabled."
69707+#endif
69708+
69709+void gr_handle_brute_attach(unsigned long mm_flags);
69710+void gr_handle_brute_check(void);
69711+void gr_handle_kernel_exploit(void);
69712+
69713+char gr_roletype_to_char(void);
69714+
69715+int gr_acl_enable_at_secure(void);
69716+
69717+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
69718+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
69719+
69720+void gr_del_task_from_ip_table(struct task_struct *p);
69721+
69722+int gr_pid_is_chrooted(struct task_struct *p);
69723+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
69724+int gr_handle_chroot_nice(void);
69725+int gr_handle_chroot_sysctl(const int op);
69726+int gr_handle_chroot_setpriority(struct task_struct *p,
69727+ const int niceval);
69728+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
69729+int gr_handle_chroot_chroot(const struct dentry *dentry,
69730+ const struct vfsmount *mnt);
69731+void gr_handle_chroot_chdir(const struct path *path);
69732+int gr_handle_chroot_chmod(const struct dentry *dentry,
69733+ const struct vfsmount *mnt, const int mode);
69734+int gr_handle_chroot_mknod(const struct dentry *dentry,
69735+ const struct vfsmount *mnt, const int mode);
69736+int gr_handle_chroot_mount(const struct dentry *dentry,
69737+ const struct vfsmount *mnt,
69738+ const char *dev_name);
69739+int gr_handle_chroot_pivot(void);
69740+int gr_handle_chroot_unix(const pid_t pid);
69741+
69742+int gr_handle_rawio(const struct inode *inode);
69743+
69744+void gr_handle_ioperm(void);
69745+void gr_handle_iopl(void);
69746+
69747+umode_t gr_acl_umask(void);
69748+
69749+int gr_tpe_allow(const struct file *file);
69750+
69751+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
69752+void gr_clear_chroot_entries(struct task_struct *task);
69753+
69754+void gr_log_forkfail(const int retval);
69755+void gr_log_timechange(void);
69756+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
69757+void gr_log_chdir(const struct dentry *dentry,
69758+ const struct vfsmount *mnt);
69759+void gr_log_chroot_exec(const struct dentry *dentry,
69760+ const struct vfsmount *mnt);
69761+void gr_log_remount(const char *devname, const int retval);
69762+void gr_log_unmount(const char *devname, const int retval);
69763+void gr_log_mount(const char *from, const char *to, const int retval);
69764+void gr_log_textrel(struct vm_area_struct *vma);
69765+void gr_log_rwxmmap(struct file *file);
69766+void gr_log_rwxmprotect(struct file *file);
69767+
69768+int gr_handle_follow_link(const struct inode *parent,
69769+ const struct inode *inode,
69770+ const struct dentry *dentry,
69771+ const struct vfsmount *mnt);
69772+int gr_handle_fifo(const struct dentry *dentry,
69773+ const struct vfsmount *mnt,
69774+ const struct dentry *dir, const int flag,
69775+ const int acc_mode);
69776+int gr_handle_hardlink(const struct dentry *dentry,
69777+ const struct vfsmount *mnt,
69778+ struct inode *inode,
69779+ const int mode, const struct filename *to);
69780+
69781+int gr_is_capable(const int cap);
69782+int gr_is_capable_nolog(const int cap);
69783+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69784+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
69785+
69786+void gr_copy_label(struct task_struct *tsk);
69787+void gr_handle_crash(struct task_struct *task, const int sig);
69788+int gr_handle_signal(const struct task_struct *p, const int sig);
69789+int gr_check_crash_uid(const kuid_t uid);
69790+int gr_check_protected_task(const struct task_struct *task);
69791+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
69792+int gr_acl_handle_mmap(const struct file *file,
69793+ const unsigned long prot);
69794+int gr_acl_handle_mprotect(const struct file *file,
69795+ const unsigned long prot);
69796+int gr_check_hidden_task(const struct task_struct *tsk);
69797+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
69798+ const struct vfsmount *mnt);
69799+__u32 gr_acl_handle_utime(const struct dentry *dentry,
69800+ const struct vfsmount *mnt);
69801+__u32 gr_acl_handle_access(const struct dentry *dentry,
69802+ const struct vfsmount *mnt, const int fmode);
69803+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
69804+ const struct vfsmount *mnt, umode_t *mode);
69805+__u32 gr_acl_handle_chown(const struct dentry *dentry,
69806+ const struct vfsmount *mnt);
69807+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
69808+ const struct vfsmount *mnt);
69809+int gr_handle_ptrace(struct task_struct *task, const long request);
69810+int gr_handle_proc_ptrace(struct task_struct *task);
69811+__u32 gr_acl_handle_execve(const struct dentry *dentry,
69812+ const struct vfsmount *mnt);
69813+int gr_check_crash_exec(const struct file *filp);
69814+int gr_acl_is_enabled(void);
69815+void gr_set_kernel_label(struct task_struct *task);
69816+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
69817+ const kgid_t gid);
69818+int gr_set_proc_label(const struct dentry *dentry,
69819+ const struct vfsmount *mnt,
69820+ const int unsafe_flags);
69821+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
69822+ const struct vfsmount *mnt);
69823+__u32 gr_acl_handle_open(const struct dentry *dentry,
69824+ const struct vfsmount *mnt, int acc_mode);
69825+__u32 gr_acl_handle_creat(const struct dentry *dentry,
69826+ const struct dentry *p_dentry,
69827+ const struct vfsmount *p_mnt,
69828+ int open_flags, int acc_mode, const int imode);
69829+void gr_handle_create(const struct dentry *dentry,
69830+ const struct vfsmount *mnt);
69831+void gr_handle_proc_create(const struct dentry *dentry,
69832+ const struct inode *inode);
69833+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
69834+ const struct dentry *parent_dentry,
69835+ const struct vfsmount *parent_mnt,
69836+ const int mode);
69837+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
69838+ const struct dentry *parent_dentry,
69839+ const struct vfsmount *parent_mnt);
69840+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
69841+ const struct vfsmount *mnt);
69842+void gr_handle_delete(const ino_t ino, const dev_t dev);
69843+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
69844+ const struct vfsmount *mnt);
69845+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
69846+ const struct dentry *parent_dentry,
69847+ const struct vfsmount *parent_mnt,
69848+ const struct filename *from);
69849+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
69850+ const struct dentry *parent_dentry,
69851+ const struct vfsmount *parent_mnt,
69852+ const struct dentry *old_dentry,
69853+ const struct vfsmount *old_mnt, const struct filename *to);
69854+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
69855+int gr_acl_handle_rename(struct dentry *new_dentry,
69856+ struct dentry *parent_dentry,
69857+ const struct vfsmount *parent_mnt,
69858+ struct dentry *old_dentry,
69859+ struct inode *old_parent_inode,
69860+ struct vfsmount *old_mnt, const struct filename *newname);
69861+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69862+ struct dentry *old_dentry,
69863+ struct dentry *new_dentry,
69864+ struct vfsmount *mnt, const __u8 replace);
69865+__u32 gr_check_link(const struct dentry *new_dentry,
69866+ const struct dentry *parent_dentry,
69867+ const struct vfsmount *parent_mnt,
69868+ const struct dentry *old_dentry,
69869+ const struct vfsmount *old_mnt);
69870+int gr_acl_handle_filldir(const struct file *file, const char *name,
69871+ const unsigned int namelen, const ino_t ino);
69872+
69873+__u32 gr_acl_handle_unix(const struct dentry *dentry,
69874+ const struct vfsmount *mnt);
69875+void gr_acl_handle_exit(void);
69876+void gr_acl_handle_psacct(struct task_struct *task, const long code);
69877+int gr_acl_handle_procpidmem(const struct task_struct *task);
69878+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
69879+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
69880+void gr_audit_ptrace(struct task_struct *task);
69881+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
69882+void gr_put_exec_file(struct task_struct *task);
69883+
69884+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
69885+
69886+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
69887+extern void gr_learn_resource(const struct task_struct *task, const int res,
69888+ const unsigned long wanted, const int gt);
69889+#else
69890+static inline void gr_learn_resource(const struct task_struct *task, const int res,
69891+ const unsigned long wanted, const int gt)
69892+{
69893+}
69894+#endif
69895+
69896+#ifdef CONFIG_GRKERNSEC_RESLOG
69897+extern void gr_log_resource(const struct task_struct *task, const int res,
69898+ const unsigned long wanted, const int gt);
69899+#else
69900+static inline void gr_log_resource(const struct task_struct *task, const int res,
69901+ const unsigned long wanted, const int gt)
69902+{
69903+}
69904+#endif
69905+
69906+#ifdef CONFIG_GRKERNSEC
69907+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
69908+void gr_handle_vm86(void);
69909+void gr_handle_mem_readwrite(u64 from, u64 to);
69910+
69911+void gr_log_badprocpid(const char *entry);
69912+
69913+extern int grsec_enable_dmesg;
69914+extern int grsec_disable_privio;
69915+
69916+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69917+extern kgid_t grsec_proc_gid;
69918+#endif
69919+
69920+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69921+extern int grsec_enable_chroot_findtask;
69922+#endif
69923+#ifdef CONFIG_GRKERNSEC_SETXID
69924+extern int grsec_enable_setxid;
69925+#endif
69926+#endif
69927+
69928+#endif
69929diff --git a/include/linux/grsock.h b/include/linux/grsock.h
69930new file mode 100644
69931index 0000000..e7ffaaf
69932--- /dev/null
69933+++ b/include/linux/grsock.h
69934@@ -0,0 +1,19 @@
69935+#ifndef __GRSOCK_H
69936+#define __GRSOCK_H
69937+
69938+extern void gr_attach_curr_ip(const struct sock *sk);
69939+extern int gr_handle_sock_all(const int family, const int type,
69940+ const int protocol);
69941+extern int gr_handle_sock_server(const struct sockaddr *sck);
69942+extern int gr_handle_sock_server_other(const struct sock *sck);
69943+extern int gr_handle_sock_client(const struct sockaddr *sck);
69944+extern int gr_search_connect(struct socket * sock,
69945+ struct sockaddr_in * addr);
69946+extern int gr_search_bind(struct socket * sock,
69947+ struct sockaddr_in * addr);
69948+extern int gr_search_listen(struct socket * sock);
69949+extern int gr_search_accept(struct socket * sock);
69950+extern int gr_search_socket(const int domain, const int type,
69951+ const int protocol);
69952+
69953+#endif
69954diff --git a/include/linux/highmem.h b/include/linux/highmem.h
69955index 7fb31da..08b5114 100644
69956--- a/include/linux/highmem.h
69957+++ b/include/linux/highmem.h
69958@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
69959 kunmap_atomic(kaddr);
69960 }
69961
69962+static inline void sanitize_highpage(struct page *page)
69963+{
69964+ void *kaddr;
69965+ unsigned long flags;
69966+
69967+ local_irq_save(flags);
69968+ kaddr = kmap_atomic(page);
69969+ clear_page(kaddr);
69970+ kunmap_atomic(kaddr);
69971+ local_irq_restore(flags);
69972+}
69973+
69974 static inline void zero_user_segments(struct page *page,
69975 unsigned start1, unsigned end1,
69976 unsigned start2, unsigned end2)
69977diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
69978index 1c7b89a..7f52502 100644
69979--- a/include/linux/hwmon-sysfs.h
69980+++ b/include/linux/hwmon-sysfs.h
69981@@ -25,7 +25,8 @@
69982 struct sensor_device_attribute{
69983 struct device_attribute dev_attr;
69984 int index;
69985-};
69986+} __do_const;
69987+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
69988 #define to_sensor_dev_attr(_dev_attr) \
69989 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
69990
69991@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
69992 struct device_attribute dev_attr;
69993 u8 index;
69994 u8 nr;
69995-};
69996+} __do_const;
69997 #define to_sensor_dev_attr_2(_dev_attr) \
69998 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
69999
70000diff --git a/include/linux/i2c.h b/include/linux/i2c.h
70001index e988fa9..ff9f17e 100644
70002--- a/include/linux/i2c.h
70003+++ b/include/linux/i2c.h
70004@@ -366,6 +366,7 @@ struct i2c_algorithm {
70005 /* To determine what the adapter supports */
70006 u32 (*functionality) (struct i2c_adapter *);
70007 };
70008+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
70009
70010 /**
70011 * struct i2c_bus_recovery_info - I2C bus recovery information
70012diff --git a/include/linux/i2o.h b/include/linux/i2o.h
70013index d23c3c2..eb63c81 100644
70014--- a/include/linux/i2o.h
70015+++ b/include/linux/i2o.h
70016@@ -565,7 +565,7 @@ struct i2o_controller {
70017 struct i2o_device *exec; /* Executive */
70018 #if BITS_PER_LONG == 64
70019 spinlock_t context_list_lock; /* lock for context_list */
70020- atomic_t context_list_counter; /* needed for unique contexts */
70021+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
70022 struct list_head context_list; /* list of context id's
70023 and pointers */
70024 #endif
70025diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
70026index aff7ad8..3942bbd 100644
70027--- a/include/linux/if_pppox.h
70028+++ b/include/linux/if_pppox.h
70029@@ -76,7 +76,7 @@ struct pppox_proto {
70030 int (*ioctl)(struct socket *sock, unsigned int cmd,
70031 unsigned long arg);
70032 struct module *owner;
70033-};
70034+} __do_const;
70035
70036 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
70037 extern void unregister_pppox_proto(int proto_num);
70038diff --git a/include/linux/init.h b/include/linux/init.h
70039index 8618147..0821126 100644
70040--- a/include/linux/init.h
70041+++ b/include/linux/init.h
70042@@ -39,9 +39,36 @@
70043 * Also note, that this data cannot be "const".
70044 */
70045
70046+#ifdef MODULE
70047+#define add_init_latent_entropy
70048+#define add_devinit_latent_entropy
70049+#define add_cpuinit_latent_entropy
70050+#define add_meminit_latent_entropy
70051+#else
70052+#define add_init_latent_entropy __latent_entropy
70053+
70054+#ifdef CONFIG_HOTPLUG
70055+#define add_devinit_latent_entropy
70056+#else
70057+#define add_devinit_latent_entropy __latent_entropy
70058+#endif
70059+
70060+#ifdef CONFIG_HOTPLUG_CPU
70061+#define add_cpuinit_latent_entropy
70062+#else
70063+#define add_cpuinit_latent_entropy __latent_entropy
70064+#endif
70065+
70066+#ifdef CONFIG_MEMORY_HOTPLUG
70067+#define add_meminit_latent_entropy
70068+#else
70069+#define add_meminit_latent_entropy __latent_entropy
70070+#endif
70071+#endif
70072+
70073 /* These are for everybody (although not all archs will actually
70074 discard it in modules) */
70075-#define __init __section(.init.text) __cold notrace
70076+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
70077 #define __initdata __section(.init.data)
70078 #define __initconst __constsection(.init.rodata)
70079 #define __exitdata __section(.exit.data)
70080@@ -94,7 +121,7 @@
70081 #define __exit __section(.exit.text) __exitused __cold notrace
70082
70083 /* Used for HOTPLUG_CPU */
70084-#define __cpuinit __section(.cpuinit.text) __cold notrace
70085+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
70086 #define __cpuinitdata __section(.cpuinit.data)
70087 #define __cpuinitconst __constsection(.cpuinit.rodata)
70088 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
70089@@ -102,7 +129,7 @@
70090 #define __cpuexitconst __constsection(.cpuexit.rodata)
70091
70092 /* Used for MEMORY_HOTPLUG */
70093-#define __meminit __section(.meminit.text) __cold notrace
70094+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
70095 #define __meminitdata __section(.meminit.data)
70096 #define __meminitconst __constsection(.meminit.rodata)
70097 #define __memexit __section(.memexit.text) __exitused __cold notrace
70098diff --git a/include/linux/init_task.h b/include/linux/init_task.h
70099index 5cd0f09..c9f67cc 100644
70100--- a/include/linux/init_task.h
70101+++ b/include/linux/init_task.h
70102@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
70103
70104 #define INIT_TASK_COMM "swapper"
70105
70106+#ifdef CONFIG_X86
70107+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
70108+#else
70109+#define INIT_TASK_THREAD_INFO
70110+#endif
70111+
70112 /*
70113 * INIT_TASK is used to set up the first task table, touch at
70114 * your own risk!. Base=0, limit=0x1fffff (=2MB)
70115@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
70116 RCU_POINTER_INITIALIZER(cred, &init_cred), \
70117 .comm = INIT_TASK_COMM, \
70118 .thread = INIT_THREAD, \
70119+ INIT_TASK_THREAD_INFO \
70120 .fs = &init_fs, \
70121 .files = &init_files, \
70122 .signal = &init_signals, \
70123diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
70124index 5fa5afe..ac55b25 100644
70125--- a/include/linux/interrupt.h
70126+++ b/include/linux/interrupt.h
70127@@ -430,7 +430,7 @@ enum
70128 /* map softirq index to softirq name. update 'softirq_to_name' in
70129 * kernel/softirq.c when adding a new softirq.
70130 */
70131-extern char *softirq_to_name[NR_SOFTIRQS];
70132+extern const char * const softirq_to_name[NR_SOFTIRQS];
70133
70134 /* softirq mask and active fields moved to irq_cpustat_t in
70135 * asm/hardirq.h to get better cache usage. KAO
70136@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
70137
70138 struct softirq_action
70139 {
70140- void (*action)(struct softirq_action *);
70141-};
70142+ void (*action)(void);
70143+} __no_const;
70144
70145 asmlinkage void do_softirq(void);
70146 asmlinkage void __do_softirq(void);
70147-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
70148+extern void open_softirq(int nr, void (*action)(void));
70149 extern void softirq_init(void);
70150 extern void __raise_softirq_irqoff(unsigned int nr);
70151
70152diff --git a/include/linux/iommu.h b/include/linux/iommu.h
70153index 3aeb730..2177f39 100644
70154--- a/include/linux/iommu.h
70155+++ b/include/linux/iommu.h
70156@@ -113,7 +113,7 @@ struct iommu_ops {
70157 u32 (*domain_get_windows)(struct iommu_domain *domain);
70158
70159 unsigned long pgsize_bitmap;
70160-};
70161+} __do_const;
70162
70163 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
70164 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
70165diff --git a/include/linux/ioport.h b/include/linux/ioport.h
70166index 89b7c24..382af74 100644
70167--- a/include/linux/ioport.h
70168+++ b/include/linux/ioport.h
70169@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
70170 int adjust_resource(struct resource *res, resource_size_t start,
70171 resource_size_t size);
70172 resource_size_t resource_alignment(struct resource *res);
70173-static inline resource_size_t resource_size(const struct resource *res)
70174+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
70175 {
70176 return res->end - res->start + 1;
70177 }
70178diff --git a/include/linux/irq.h b/include/linux/irq.h
70179index bc4e066..50468a9 100644
70180--- a/include/linux/irq.h
70181+++ b/include/linux/irq.h
70182@@ -328,7 +328,8 @@ struct irq_chip {
70183 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
70184
70185 unsigned long flags;
70186-};
70187+} __do_const;
70188+typedef struct irq_chip __no_const irq_chip_no_const;
70189
70190 /*
70191 * irq_chip specific flags
70192diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
70193index 3e203eb..3fe68d0 100644
70194--- a/include/linux/irqchip/arm-gic.h
70195+++ b/include/linux/irqchip/arm-gic.h
70196@@ -59,9 +59,11 @@
70197
70198 #ifndef __ASSEMBLY__
70199
70200+#include <linux/irq.h>
70201+
70202 struct device_node;
70203
70204-extern struct irq_chip gic_arch_extn;
70205+extern irq_chip_no_const gic_arch_extn;
70206
70207 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
70208 u32 offset, struct device_node *);
70209diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
70210index 6883e19..06992b1 100644
70211--- a/include/linux/kallsyms.h
70212+++ b/include/linux/kallsyms.h
70213@@ -15,7 +15,8 @@
70214
70215 struct module;
70216
70217-#ifdef CONFIG_KALLSYMS
70218+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
70219+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70220 /* Lookup the address for a symbol. Returns 0 if not found. */
70221 unsigned long kallsyms_lookup_name(const char *name);
70222
70223@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
70224 /* Stupid that this does nothing, but I didn't create this mess. */
70225 #define __print_symbol(fmt, addr)
70226 #endif /*CONFIG_KALLSYMS*/
70227+#else /* when included by kallsyms.c, vsnprintf.c, or
70228+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
70229+extern void __print_symbol(const char *fmt, unsigned long address);
70230+extern int sprint_backtrace(char *buffer, unsigned long address);
70231+extern int sprint_symbol(char *buffer, unsigned long address);
70232+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
70233+const char *kallsyms_lookup(unsigned long addr,
70234+ unsigned long *symbolsize,
70235+ unsigned long *offset,
70236+ char **modname, char *namebuf);
70237+#endif
70238
70239 /* This macro allows us to keep printk typechecking */
70240 static __printf(1, 2)
70241diff --git a/include/linux/key-type.h b/include/linux/key-type.h
70242index 518a53a..5e28358 100644
70243--- a/include/linux/key-type.h
70244+++ b/include/linux/key-type.h
70245@@ -125,7 +125,7 @@ struct key_type {
70246 /* internal fields */
70247 struct list_head link; /* link in types list */
70248 struct lock_class_key lock_class; /* key->sem lock class */
70249-};
70250+} __do_const;
70251
70252 extern struct key_type key_type_keyring;
70253
70254diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
70255index c6e091b..a940adf 100644
70256--- a/include/linux/kgdb.h
70257+++ b/include/linux/kgdb.h
70258@@ -52,7 +52,7 @@ extern int kgdb_connected;
70259 extern int kgdb_io_module_registered;
70260
70261 extern atomic_t kgdb_setting_breakpoint;
70262-extern atomic_t kgdb_cpu_doing_single_step;
70263+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
70264
70265 extern struct task_struct *kgdb_usethread;
70266 extern struct task_struct *kgdb_contthread;
70267@@ -254,7 +254,7 @@ struct kgdb_arch {
70268 void (*correct_hw_break)(void);
70269
70270 void (*enable_nmi)(bool on);
70271-};
70272+} __do_const;
70273
70274 /**
70275 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
70276@@ -279,7 +279,7 @@ struct kgdb_io {
70277 void (*pre_exception) (void);
70278 void (*post_exception) (void);
70279 int is_console;
70280-};
70281+} __do_const;
70282
70283 extern struct kgdb_arch arch_kgdb_ops;
70284
70285diff --git a/include/linux/kmod.h b/include/linux/kmod.h
70286index 0555cc6..b16a7a4 100644
70287--- a/include/linux/kmod.h
70288+++ b/include/linux/kmod.h
70289@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
70290 * usually useless though. */
70291 extern __printf(2, 3)
70292 int __request_module(bool wait, const char *name, ...);
70293+extern __printf(3, 4)
70294+int ___request_module(bool wait, char *param_name, const char *name, ...);
70295 #define request_module(mod...) __request_module(true, mod)
70296 #define request_module_nowait(mod...) __request_module(false, mod)
70297 #define try_then_request_module(x, mod...) \
70298diff --git a/include/linux/kobject.h b/include/linux/kobject.h
70299index 939b112..ed6ed51 100644
70300--- a/include/linux/kobject.h
70301+++ b/include/linux/kobject.h
70302@@ -111,7 +111,7 @@ struct kobj_type {
70303 struct attribute **default_attrs;
70304 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
70305 const void *(*namespace)(struct kobject *kobj);
70306-};
70307+} __do_const;
70308
70309 struct kobj_uevent_env {
70310 char *envp[UEVENT_NUM_ENVP];
70311@@ -134,6 +134,7 @@ struct kobj_attribute {
70312 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
70313 const char *buf, size_t count);
70314 };
70315+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
70316
70317 extern const struct sysfs_ops kobj_sysfs_ops;
70318
70319diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
70320index f66b065..c2c29b4 100644
70321--- a/include/linux/kobject_ns.h
70322+++ b/include/linux/kobject_ns.h
70323@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
70324 const void *(*netlink_ns)(struct sock *sk);
70325 const void *(*initial_ns)(void);
70326 void (*drop_ns)(void *);
70327-};
70328+} __do_const;
70329
70330 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
70331 int kobj_ns_type_registered(enum kobj_ns_type type);
70332diff --git a/include/linux/kref.h b/include/linux/kref.h
70333index 484604d..0f6c5b6 100644
70334--- a/include/linux/kref.h
70335+++ b/include/linux/kref.h
70336@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
70337 static inline int kref_sub(struct kref *kref, unsigned int count,
70338 void (*release)(struct kref *kref))
70339 {
70340- WARN_ON(release == NULL);
70341+ BUG_ON(release == NULL);
70342
70343 if (atomic_sub_and_test((int) count, &kref->refcount)) {
70344 release(kref);
70345diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
70346index 8db53cf..c21121d 100644
70347--- a/include/linux/kvm_host.h
70348+++ b/include/linux/kvm_host.h
70349@@ -444,7 +444,7 @@ static inline void kvm_irqfd_exit(void)
70350 {
70351 }
70352 #endif
70353-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70354+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70355 struct module *module);
70356 void kvm_exit(void);
70357
70358@@ -616,7 +616,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
70359 struct kvm_guest_debug *dbg);
70360 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
70361
70362-int kvm_arch_init(void *opaque);
70363+int kvm_arch_init(const void *opaque);
70364 void kvm_arch_exit(void);
70365
70366 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
70367diff --git a/include/linux/libata.h b/include/linux/libata.h
70368index eae7a05..2cdd875 100644
70369--- a/include/linux/libata.h
70370+++ b/include/linux/libata.h
70371@@ -919,7 +919,7 @@ struct ata_port_operations {
70372 * fields must be pointers.
70373 */
70374 const struct ata_port_operations *inherits;
70375-};
70376+} __do_const;
70377
70378 struct ata_port_info {
70379 unsigned long flags;
70380diff --git a/include/linux/list.h b/include/linux/list.h
70381index b83e565..baa6c1d 100644
70382--- a/include/linux/list.h
70383+++ b/include/linux/list.h
70384@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
70385 extern void list_del(struct list_head *entry);
70386 #endif
70387
70388+extern void __pax_list_add(struct list_head *new,
70389+ struct list_head *prev,
70390+ struct list_head *next);
70391+static inline void pax_list_add(struct list_head *new, struct list_head *head)
70392+{
70393+ __pax_list_add(new, head, head->next);
70394+}
70395+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
70396+{
70397+ __pax_list_add(new, head->prev, head);
70398+}
70399+extern void pax_list_del(struct list_head *entry);
70400+
70401 /**
70402 * list_replace - replace old entry by new one
70403 * @old : the element to be replaced
70404@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
70405 INIT_LIST_HEAD(entry);
70406 }
70407
70408+extern void pax_list_del_init(struct list_head *entry);
70409+
70410 /**
70411 * list_move - delete from one list and add as another's head
70412 * @list: the entry to move
70413diff --git a/include/linux/math64.h b/include/linux/math64.h
70414index 2913b86..4209244 100644
70415--- a/include/linux/math64.h
70416+++ b/include/linux/math64.h
70417@@ -15,7 +15,7 @@
70418 * This is commonly provided by 32bit archs to provide an optimized 64bit
70419 * divide.
70420 */
70421-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70422+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70423 {
70424 *remainder = dividend % divisor;
70425 return dividend / divisor;
70426@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
70427 #define div64_ul(x, y) div_u64((x), (y))
70428
70429 #ifndef div_u64_rem
70430-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70431+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70432 {
70433 *remainder = do_div(dividend, divisor);
70434 return dividend;
70435@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
70436 * divide.
70437 */
70438 #ifndef div_u64
70439-static inline u64 div_u64(u64 dividend, u32 divisor)
70440+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
70441 {
70442 u32 remainder;
70443 return div_u64_rem(dividend, divisor, &remainder);
70444diff --git a/include/linux/mm.h b/include/linux/mm.h
70445index e0c8528..bcf0c29 100644
70446--- a/include/linux/mm.h
70447+++ b/include/linux/mm.h
70448@@ -104,6 +104,11 @@ extern unsigned int kobjsize(const void *objp);
70449 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
70450 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
70451 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
70452+
70453+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70454+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
70455+#endif
70456+
70457 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
70458
70459 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
70460@@ -205,8 +210,8 @@ struct vm_operations_struct {
70461 /* called by access_process_vm when get_user_pages() fails, typically
70462 * for use by special VMAs that can switch between memory and hardware
70463 */
70464- int (*access)(struct vm_area_struct *vma, unsigned long addr,
70465- void *buf, int len, int write);
70466+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
70467+ void *buf, size_t len, int write);
70468 #ifdef CONFIG_NUMA
70469 /*
70470 * set_policy() op must add a reference to any non-NULL @new mempolicy
70471@@ -236,6 +241,7 @@ struct vm_operations_struct {
70472 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
70473 unsigned long size, pgoff_t pgoff);
70474 };
70475+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
70476
70477 struct mmu_gather;
70478 struct inode;
70479@@ -980,8 +986,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
70480 unsigned long *pfn);
70481 int follow_phys(struct vm_area_struct *vma, unsigned long address,
70482 unsigned int flags, unsigned long *prot, resource_size_t *phys);
70483-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70484- void *buf, int len, int write);
70485+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70486+ void *buf, size_t len, int write);
70487
70488 static inline void unmap_shared_mapping_range(struct address_space *mapping,
70489 loff_t const holebegin, loff_t const holelen)
70490@@ -1020,9 +1026,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
70491 }
70492 #endif
70493
70494-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
70495-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
70496- void *buf, int len, int write);
70497+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
70498+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
70499+ void *buf, size_t len, int write);
70500
70501 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70502 unsigned long start, unsigned long nr_pages,
70503@@ -1053,34 +1059,6 @@ int set_page_dirty(struct page *page);
70504 int set_page_dirty_lock(struct page *page);
70505 int clear_page_dirty_for_io(struct page *page);
70506
70507-/* Is the vma a continuation of the stack vma above it? */
70508-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
70509-{
70510- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
70511-}
70512-
70513-static inline int stack_guard_page_start(struct vm_area_struct *vma,
70514- unsigned long addr)
70515-{
70516- return (vma->vm_flags & VM_GROWSDOWN) &&
70517- (vma->vm_start == addr) &&
70518- !vma_growsdown(vma->vm_prev, addr);
70519-}
70520-
70521-/* Is the vma a continuation of the stack vma below it? */
70522-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
70523-{
70524- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
70525-}
70526-
70527-static inline int stack_guard_page_end(struct vm_area_struct *vma,
70528- unsigned long addr)
70529-{
70530- return (vma->vm_flags & VM_GROWSUP) &&
70531- (vma->vm_end == addr) &&
70532- !vma_growsup(vma->vm_next, addr);
70533-}
70534-
70535 extern pid_t
70536 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
70537
70538@@ -1180,6 +1158,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
70539 }
70540 #endif
70541
70542+#ifdef CONFIG_MMU
70543+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
70544+#else
70545+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70546+{
70547+ return __pgprot(0);
70548+}
70549+#endif
70550+
70551 int vma_wants_writenotify(struct vm_area_struct *vma);
70552
70553 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
70554@@ -1198,8 +1185,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
70555 {
70556 return 0;
70557 }
70558+
70559+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
70560+ unsigned long address)
70561+{
70562+ return 0;
70563+}
70564 #else
70565 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70566+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70567 #endif
70568
70569 #ifdef __PAGETABLE_PMD_FOLDED
70570@@ -1208,8 +1202,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
70571 {
70572 return 0;
70573 }
70574+
70575+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
70576+ unsigned long address)
70577+{
70578+ return 0;
70579+}
70580 #else
70581 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
70582+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
70583 #endif
70584
70585 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
70586@@ -1227,11 +1228,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
70587 NULL: pud_offset(pgd, address);
70588 }
70589
70590+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70591+{
70592+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
70593+ NULL: pud_offset(pgd, address);
70594+}
70595+
70596 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70597 {
70598 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
70599 NULL: pmd_offset(pud, address);
70600 }
70601+
70602+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70603+{
70604+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
70605+ NULL: pmd_offset(pud, address);
70606+}
70607 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
70608
70609 #if USE_SPLIT_PTLOCKS
70610@@ -1517,6 +1530,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70611 unsigned long len, unsigned long prot, unsigned long flags,
70612 unsigned long pgoff, unsigned long *populate);
70613 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
70614+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
70615
70616 #ifdef CONFIG_MMU
70617 extern int __mm_populate(unsigned long addr, unsigned long len,
70618@@ -1545,10 +1559,11 @@ struct vm_unmapped_area_info {
70619 unsigned long high_limit;
70620 unsigned long align_mask;
70621 unsigned long align_offset;
70622+ unsigned long threadstack_offset;
70623 };
70624
70625-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
70626-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
70627+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
70628+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
70629
70630 /*
70631 * Search for an unmapped address range.
70632@@ -1560,7 +1575,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
70633 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
70634 */
70635 static inline unsigned long
70636-vm_unmapped_area(struct vm_unmapped_area_info *info)
70637+vm_unmapped_area(const struct vm_unmapped_area_info *info)
70638 {
70639 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
70640 return unmapped_area(info);
70641@@ -1623,6 +1638,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
70642 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
70643 struct vm_area_struct **pprev);
70644
70645+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
70646+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
70647+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
70648+
70649 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
70650 NULL if none. Assume start_addr < end_addr. */
70651 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
70652@@ -1651,15 +1670,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
70653 return vma;
70654 }
70655
70656-#ifdef CONFIG_MMU
70657-pgprot_t vm_get_page_prot(unsigned long vm_flags);
70658-#else
70659-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
70660-{
70661- return __pgprot(0);
70662-}
70663-#endif
70664-
70665 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
70666 unsigned long change_prot_numa(struct vm_area_struct *vma,
70667 unsigned long start, unsigned long end);
70668@@ -1711,6 +1721,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
70669 static inline void vm_stat_account(struct mm_struct *mm,
70670 unsigned long flags, struct file *file, long pages)
70671 {
70672+
70673+#ifdef CONFIG_PAX_RANDMMAP
70674+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
70675+#endif
70676+
70677 mm->total_vm += pages;
70678 }
70679 #endif /* CONFIG_PROC_FS */
70680@@ -1791,7 +1806,7 @@ extern int unpoison_memory(unsigned long pfn);
70681 extern int sysctl_memory_failure_early_kill;
70682 extern int sysctl_memory_failure_recovery;
70683 extern void shake_page(struct page *p, int access);
70684-extern atomic_long_t num_poisoned_pages;
70685+extern atomic_long_unchecked_t num_poisoned_pages;
70686 extern int soft_offline_page(struct page *page, int flags);
70687
70688 extern void dump_page(struct page *page);
70689@@ -1828,5 +1843,11 @@ void __init setup_nr_node_ids(void);
70690 static inline void setup_nr_node_ids(void) {}
70691 #endif
70692
70693+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70694+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
70695+#else
70696+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
70697+#endif
70698+
70699 #endif /* __KERNEL__ */
70700 #endif /* _LINUX_MM_H */
70701diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
70702index ace9a5f..81bdb59 100644
70703--- a/include/linux/mm_types.h
70704+++ b/include/linux/mm_types.h
70705@@ -289,6 +289,8 @@ struct vm_area_struct {
70706 #ifdef CONFIG_NUMA
70707 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
70708 #endif
70709+
70710+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
70711 };
70712
70713 struct core_thread {
70714@@ -437,6 +439,24 @@ struct mm_struct {
70715 int first_nid;
70716 #endif
70717 struct uprobes_state uprobes_state;
70718+
70719+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70720+ unsigned long pax_flags;
70721+#endif
70722+
70723+#ifdef CONFIG_PAX_DLRESOLVE
70724+ unsigned long call_dl_resolve;
70725+#endif
70726+
70727+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
70728+ unsigned long call_syscall;
70729+#endif
70730+
70731+#ifdef CONFIG_PAX_ASLR
70732+ unsigned long delta_mmap; /* randomized offset */
70733+ unsigned long delta_stack; /* randomized offset */
70734+#endif
70735+
70736 };
70737
70738 /* first nid will either be a valid NID or one of these values */
70739diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
70740index c5d5278..f0b68c8 100644
70741--- a/include/linux/mmiotrace.h
70742+++ b/include/linux/mmiotrace.h
70743@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
70744 /* Called from ioremap.c */
70745 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
70746 void __iomem *addr);
70747-extern void mmiotrace_iounmap(volatile void __iomem *addr);
70748+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
70749
70750 /* For anyone to insert markers. Remember trailing newline. */
70751 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
70752@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
70753 {
70754 }
70755
70756-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
70757+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
70758 {
70759 }
70760
70761diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
70762index 5c76737..61f518e 100644
70763--- a/include/linux/mmzone.h
70764+++ b/include/linux/mmzone.h
70765@@ -396,7 +396,7 @@ struct zone {
70766 unsigned long flags; /* zone flags, see below */
70767
70768 /* Zone statistics */
70769- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70770+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70771
70772 /*
70773 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
70774diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
70775index b508016..237cfe5 100644
70776--- a/include/linux/mod_devicetable.h
70777+++ b/include/linux/mod_devicetable.h
70778@@ -13,7 +13,7 @@
70779 typedef unsigned long kernel_ulong_t;
70780 #endif
70781
70782-#define PCI_ANY_ID (~0)
70783+#define PCI_ANY_ID ((__u16)~0)
70784
70785 struct pci_device_id {
70786 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
70787@@ -139,7 +139,7 @@ struct usb_device_id {
70788 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
70789 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
70790
70791-#define HID_ANY_ID (~0)
70792+#define HID_ANY_ID (~0U)
70793 #define HID_BUS_ANY 0xffff
70794 #define HID_GROUP_ANY 0x0000
70795
70796@@ -465,7 +465,7 @@ struct dmi_system_id {
70797 const char *ident;
70798 struct dmi_strmatch matches[4];
70799 void *driver_data;
70800-};
70801+} __do_const;
70802 /*
70803 * struct dmi_device_id appears during expansion of
70804 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
70805diff --git a/include/linux/module.h b/include/linux/module.h
70806index 46f1ea0..a34ca37 100644
70807--- a/include/linux/module.h
70808+++ b/include/linux/module.h
70809@@ -17,9 +17,11 @@
70810 #include <linux/moduleparam.h>
70811 #include <linux/tracepoint.h>
70812 #include <linux/export.h>
70813+#include <linux/fs.h>
70814
70815 #include <linux/percpu.h>
70816 #include <asm/module.h>
70817+#include <asm/pgtable.h>
70818
70819 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
70820 #define MODULE_SIG_STRING "~Module signature appended~\n"
70821@@ -54,12 +56,13 @@ struct module_attribute {
70822 int (*test)(struct module *);
70823 void (*free)(struct module *);
70824 };
70825+typedef struct module_attribute __no_const module_attribute_no_const;
70826
70827 struct module_version_attribute {
70828 struct module_attribute mattr;
70829 const char *module_name;
70830 const char *version;
70831-} __attribute__ ((__aligned__(sizeof(void *))));
70832+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
70833
70834 extern ssize_t __modver_version_show(struct module_attribute *,
70835 struct module_kobject *, char *);
70836@@ -232,7 +235,7 @@ struct module
70837
70838 /* Sysfs stuff. */
70839 struct module_kobject mkobj;
70840- struct module_attribute *modinfo_attrs;
70841+ module_attribute_no_const *modinfo_attrs;
70842 const char *version;
70843 const char *srcversion;
70844 struct kobject *holders_dir;
70845@@ -281,19 +284,16 @@ struct module
70846 int (*init)(void);
70847
70848 /* If this is non-NULL, vfree after init() returns */
70849- void *module_init;
70850+ void *module_init_rx, *module_init_rw;
70851
70852 /* Here is the actual code + data, vfree'd on unload. */
70853- void *module_core;
70854+ void *module_core_rx, *module_core_rw;
70855
70856 /* Here are the sizes of the init and core sections */
70857- unsigned int init_size, core_size;
70858+ unsigned int init_size_rw, core_size_rw;
70859
70860 /* The size of the executable code in each section. */
70861- unsigned int init_text_size, core_text_size;
70862-
70863- /* Size of RO sections of the module (text+rodata) */
70864- unsigned int init_ro_size, core_ro_size;
70865+ unsigned int init_size_rx, core_size_rx;
70866
70867 /* Arch-specific module values */
70868 struct mod_arch_specific arch;
70869@@ -349,6 +349,10 @@ struct module
70870 #ifdef CONFIG_EVENT_TRACING
70871 struct ftrace_event_call **trace_events;
70872 unsigned int num_trace_events;
70873+ struct file_operations trace_id;
70874+ struct file_operations trace_enable;
70875+ struct file_operations trace_format;
70876+ struct file_operations trace_filter;
70877 #endif
70878 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
70879 unsigned int num_ftrace_callsites;
70880@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
70881 bool is_module_percpu_address(unsigned long addr);
70882 bool is_module_text_address(unsigned long addr);
70883
70884+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
70885+{
70886+
70887+#ifdef CONFIG_PAX_KERNEXEC
70888+ if (ktla_ktva(addr) >= (unsigned long)start &&
70889+ ktla_ktva(addr) < (unsigned long)start + size)
70890+ return 1;
70891+#endif
70892+
70893+ return ((void *)addr >= start && (void *)addr < start + size);
70894+}
70895+
70896+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
70897+{
70898+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
70899+}
70900+
70901+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
70902+{
70903+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
70904+}
70905+
70906+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
70907+{
70908+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
70909+}
70910+
70911+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
70912+{
70913+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
70914+}
70915+
70916 static inline int within_module_core(unsigned long addr, const struct module *mod)
70917 {
70918- return (unsigned long)mod->module_core <= addr &&
70919- addr < (unsigned long)mod->module_core + mod->core_size;
70920+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
70921 }
70922
70923 static inline int within_module_init(unsigned long addr, const struct module *mod)
70924 {
70925- return (unsigned long)mod->module_init <= addr &&
70926- addr < (unsigned long)mod->module_init + mod->init_size;
70927+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
70928 }
70929
70930 /* Search for module by name: must hold module_mutex. */
70931diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
70932index 560ca53..ef621ef 100644
70933--- a/include/linux/moduleloader.h
70934+++ b/include/linux/moduleloader.h
70935@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
70936 sections. Returns NULL on failure. */
70937 void *module_alloc(unsigned long size);
70938
70939+#ifdef CONFIG_PAX_KERNEXEC
70940+void *module_alloc_exec(unsigned long size);
70941+#else
70942+#define module_alloc_exec(x) module_alloc(x)
70943+#endif
70944+
70945 /* Free memory returned from module_alloc. */
70946 void module_free(struct module *mod, void *module_region);
70947
70948+#ifdef CONFIG_PAX_KERNEXEC
70949+void module_free_exec(struct module *mod, void *module_region);
70950+#else
70951+#define module_free_exec(x, y) module_free((x), (y))
70952+#endif
70953+
70954 /*
70955 * Apply the given relocation to the (simplified) ELF. Return -error
70956 * or 0.
70957@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
70958 unsigned int relsec,
70959 struct module *me)
70960 {
70961+#ifdef CONFIG_MODULES
70962 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70963+#endif
70964 return -ENOEXEC;
70965 }
70966 #endif
70967@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
70968 unsigned int relsec,
70969 struct module *me)
70970 {
70971+#ifdef CONFIG_MODULES
70972 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70973+#endif
70974 return -ENOEXEC;
70975 }
70976 #endif
70977diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
70978index 137b419..fe663ec 100644
70979--- a/include/linux/moduleparam.h
70980+++ b/include/linux/moduleparam.h
70981@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
70982 * @len is usually just sizeof(string).
70983 */
70984 #define module_param_string(name, string, len, perm) \
70985- static const struct kparam_string __param_string_##name \
70986+ static const struct kparam_string __param_string_##name __used \
70987 = { len, string }; \
70988 __module_param_call(MODULE_PARAM_PREFIX, name, \
70989 &param_ops_string, \
70990@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
70991 */
70992 #define module_param_array_named(name, array, type, nump, perm) \
70993 param_check_##type(name, &(array)[0]); \
70994- static const struct kparam_array __param_arr_##name \
70995+ static const struct kparam_array __param_arr_##name __used \
70996 = { .max = ARRAY_SIZE(array), .num = nump, \
70997 .ops = &param_ops_##type, \
70998 .elemsize = sizeof(array[0]), .elem = array }; \
70999diff --git a/include/linux/namei.h b/include/linux/namei.h
71000index 5a5ff57..5ae5070 100644
71001--- a/include/linux/namei.h
71002+++ b/include/linux/namei.h
71003@@ -19,7 +19,7 @@ struct nameidata {
71004 unsigned seq;
71005 int last_type;
71006 unsigned depth;
71007- char *saved_names[MAX_NESTED_LINKS + 1];
71008+ const char *saved_names[MAX_NESTED_LINKS + 1];
71009 };
71010
71011 /*
71012@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
71013
71014 extern void nd_jump_link(struct nameidata *nd, struct path *path);
71015
71016-static inline void nd_set_link(struct nameidata *nd, char *path)
71017+static inline void nd_set_link(struct nameidata *nd, const char *path)
71018 {
71019 nd->saved_names[nd->depth] = path;
71020 }
71021
71022-static inline char *nd_get_link(struct nameidata *nd)
71023+static inline const char *nd_get_link(const struct nameidata *nd)
71024 {
71025 return nd->saved_names[nd->depth];
71026 }
71027diff --git a/include/linux/net.h b/include/linux/net.h
71028index 99c9f0c..e1cf296 100644
71029--- a/include/linux/net.h
71030+++ b/include/linux/net.h
71031@@ -183,7 +183,7 @@ struct net_proto_family {
71032 int (*create)(struct net *net, struct socket *sock,
71033 int protocol, int kern);
71034 struct module *owner;
71035-};
71036+} __do_const;
71037
71038 struct iovec;
71039 struct kvec;
71040diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
71041index 96e4c21..9cc8278 100644
71042--- a/include/linux/netdevice.h
71043+++ b/include/linux/netdevice.h
71044@@ -1026,6 +1026,7 @@ struct net_device_ops {
71045 int (*ndo_change_carrier)(struct net_device *dev,
71046 bool new_carrier);
71047 };
71048+typedef struct net_device_ops __no_const net_device_ops_no_const;
71049
71050 /*
71051 * The DEVICE structure.
71052@@ -1094,7 +1095,7 @@ struct net_device {
71053 int iflink;
71054
71055 struct net_device_stats stats;
71056- atomic_long_t rx_dropped; /* dropped packets by core network
71057+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
71058 * Do not use this in drivers.
71059 */
71060
71061diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
71062index 0060fde..481c6ae 100644
71063--- a/include/linux/netfilter.h
71064+++ b/include/linux/netfilter.h
71065@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
71066 #endif
71067 /* Use the module struct to lock set/get code in place */
71068 struct module *owner;
71069-};
71070+} __do_const;
71071
71072 /* Function to register/unregister hook points. */
71073 int nf_register_hook(struct nf_hook_ops *reg);
71074diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
71075index d80e275..c3510b8 100644
71076--- a/include/linux/netfilter/ipset/ip_set.h
71077+++ b/include/linux/netfilter/ipset/ip_set.h
71078@@ -124,7 +124,7 @@ struct ip_set_type_variant {
71079 /* Return true if "b" set is the same as "a"
71080 * according to the create set parameters */
71081 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
71082-};
71083+} __do_const;
71084
71085 /* The core set type structure */
71086 struct ip_set_type {
71087diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
71088index cadb740..d7c37c0 100644
71089--- a/include/linux/netfilter/nfnetlink.h
71090+++ b/include/linux/netfilter/nfnetlink.h
71091@@ -16,7 +16,7 @@ struct nfnl_callback {
71092 const struct nlattr * const cda[]);
71093 const struct nla_policy *policy; /* netlink attribute policy */
71094 const u_int16_t attr_count; /* number of nlattr's */
71095-};
71096+} __do_const;
71097
71098 struct nfnetlink_subsystem {
71099 const char *name;
71100diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
71101new file mode 100644
71102index 0000000..33f4af8
71103--- /dev/null
71104+++ b/include/linux/netfilter/xt_gradm.h
71105@@ -0,0 +1,9 @@
71106+#ifndef _LINUX_NETFILTER_XT_GRADM_H
71107+#define _LINUX_NETFILTER_XT_GRADM_H 1
71108+
71109+struct xt_gradm_mtinfo {
71110+ __u16 flags;
71111+ __u16 invflags;
71112+};
71113+
71114+#endif
71115diff --git a/include/linux/nls.h b/include/linux/nls.h
71116index 5dc635f..35f5e11 100644
71117--- a/include/linux/nls.h
71118+++ b/include/linux/nls.h
71119@@ -31,7 +31,7 @@ struct nls_table {
71120 const unsigned char *charset2upper;
71121 struct module *owner;
71122 struct nls_table *next;
71123-};
71124+} __do_const;
71125
71126 /* this value hold the maximum octet of charset */
71127 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
71128diff --git a/include/linux/notifier.h b/include/linux/notifier.h
71129index d14a4c3..a078786 100644
71130--- a/include/linux/notifier.h
71131+++ b/include/linux/notifier.h
71132@@ -54,7 +54,8 @@ struct notifier_block {
71133 notifier_fn_t notifier_call;
71134 struct notifier_block __rcu *next;
71135 int priority;
71136-};
71137+} __do_const;
71138+typedef struct notifier_block __no_const notifier_block_no_const;
71139
71140 struct atomic_notifier_head {
71141 spinlock_t lock;
71142diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
71143index a4c5624..79d6d88 100644
71144--- a/include/linux/oprofile.h
71145+++ b/include/linux/oprofile.h
71146@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
71147 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
71148 char const * name, ulong * val);
71149
71150-/** Create a file for read-only access to an atomic_t. */
71151+/** Create a file for read-only access to an atomic_unchecked_t. */
71152 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
71153- char const * name, atomic_t * val);
71154+ char const * name, atomic_unchecked_t * val);
71155
71156 /** create a directory */
71157 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
71158diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
71159index 8db71dc..a76bf2c 100644
71160--- a/include/linux/pci_hotplug.h
71161+++ b/include/linux/pci_hotplug.h
71162@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
71163 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
71164 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
71165 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
71166-};
71167+} __do_const;
71168+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
71169
71170 /**
71171 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
71172diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
71173index c5b6dbf..b124155 100644
71174--- a/include/linux/perf_event.h
71175+++ b/include/linux/perf_event.h
71176@@ -318,8 +318,8 @@ struct perf_event {
71177
71178 enum perf_event_active_state state;
71179 unsigned int attach_state;
71180- local64_t count;
71181- atomic64_t child_count;
71182+ local64_t count; /* PaX: fix it one day */
71183+ atomic64_unchecked_t child_count;
71184
71185 /*
71186 * These are the total time in nanoseconds that the event
71187@@ -370,8 +370,8 @@ struct perf_event {
71188 * These accumulate total time (in nanoseconds) that children
71189 * events have been enabled and running, respectively.
71190 */
71191- atomic64_t child_total_time_enabled;
71192- atomic64_t child_total_time_running;
71193+ atomic64_unchecked_t child_total_time_enabled;
71194+ atomic64_unchecked_t child_total_time_running;
71195
71196 /*
71197 * Protect attach/detach and child_list:
71198@@ -692,7 +692,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
71199 entry->ip[entry->nr++] = ip;
71200 }
71201
71202-extern int sysctl_perf_event_paranoid;
71203+extern int sysctl_perf_event_legitimately_concerned;
71204 extern int sysctl_perf_event_mlock;
71205 extern int sysctl_perf_event_sample_rate;
71206
71207@@ -700,19 +700,24 @@ extern int perf_proc_update_handler(struct ctl_table *table, int write,
71208 void __user *buffer, size_t *lenp,
71209 loff_t *ppos);
71210
71211+static inline bool perf_paranoid_any(void)
71212+{
71213+ return sysctl_perf_event_legitimately_concerned > 2;
71214+}
71215+
71216 static inline bool perf_paranoid_tracepoint_raw(void)
71217 {
71218- return sysctl_perf_event_paranoid > -1;
71219+ return sysctl_perf_event_legitimately_concerned > -1;
71220 }
71221
71222 static inline bool perf_paranoid_cpu(void)
71223 {
71224- return sysctl_perf_event_paranoid > 0;
71225+ return sysctl_perf_event_legitimately_concerned > 0;
71226 }
71227
71228 static inline bool perf_paranoid_kernel(void)
71229 {
71230- return sysctl_perf_event_paranoid > 1;
71231+ return sysctl_perf_event_legitimately_concerned > 1;
71232 }
71233
71234 extern void perf_event_init(void);
71235@@ -806,7 +811,7 @@ static inline void perf_restore_debug_store(void) { }
71236 */
71237 #define perf_cpu_notifier(fn) \
71238 do { \
71239- static struct notifier_block fn##_nb __cpuinitdata = \
71240+ static struct notifier_block fn##_nb = \
71241 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
71242 unsigned long cpu = smp_processor_id(); \
71243 unsigned long flags; \
71244@@ -826,7 +831,7 @@ struct perf_pmu_events_attr {
71245 struct device_attribute attr;
71246 u64 id;
71247 const char *event_str;
71248-};
71249+} __do_const;
71250
71251 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
71252 static struct perf_pmu_events_attr _var = { \
71253diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
71254index b8809fe..ae4ccd0 100644
71255--- a/include/linux/pipe_fs_i.h
71256+++ b/include/linux/pipe_fs_i.h
71257@@ -47,10 +47,10 @@ struct pipe_inode_info {
71258 struct mutex mutex;
71259 wait_queue_head_t wait;
71260 unsigned int nrbufs, curbuf, buffers;
71261- unsigned int readers;
71262- unsigned int writers;
71263- unsigned int files;
71264- unsigned int waiting_writers;
71265+ atomic_t readers;
71266+ atomic_t writers;
71267+ atomic_t files;
71268+ atomic_t waiting_writers;
71269 unsigned int r_counter;
71270 unsigned int w_counter;
71271 struct page *tmp_page;
71272diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
71273index 5f28cae..3d23723 100644
71274--- a/include/linux/platform_data/usb-ehci-s5p.h
71275+++ b/include/linux/platform_data/usb-ehci-s5p.h
71276@@ -14,7 +14,7 @@
71277 struct s5p_ehci_platdata {
71278 int (*phy_init)(struct platform_device *pdev, int type);
71279 int (*phy_exit)(struct platform_device *pdev, int type);
71280-};
71281+} __no_const;
71282
71283 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
71284
71285diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
71286index c256c59..8ea94c7 100644
71287--- a/include/linux/platform_data/usb-ohci-exynos.h
71288+++ b/include/linux/platform_data/usb-ohci-exynos.h
71289@@ -14,7 +14,7 @@
71290 struct exynos4_ohci_platdata {
71291 int (*phy_init)(struct platform_device *pdev, int type);
71292 int (*phy_exit)(struct platform_device *pdev, int type);
71293-};
71294+} __no_const;
71295
71296 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
71297
71298diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
71299index 7c1d252..c5c773e 100644
71300--- a/include/linux/pm_domain.h
71301+++ b/include/linux/pm_domain.h
71302@@ -48,7 +48,7 @@ struct gpd_dev_ops {
71303
71304 struct gpd_cpu_data {
71305 unsigned int saved_exit_latency;
71306- struct cpuidle_state *idle_state;
71307+ cpuidle_state_no_const *idle_state;
71308 };
71309
71310 struct generic_pm_domain {
71311diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
71312index 7d7e09e..8671ef8 100644
71313--- a/include/linux/pm_runtime.h
71314+++ b/include/linux/pm_runtime.h
71315@@ -104,7 +104,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
71316
71317 static inline void pm_runtime_mark_last_busy(struct device *dev)
71318 {
71319- ACCESS_ONCE(dev->power.last_busy) = jiffies;
71320+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
71321 }
71322
71323 #else /* !CONFIG_PM_RUNTIME */
71324diff --git a/include/linux/pnp.h b/include/linux/pnp.h
71325index 195aafc..49a7bc2 100644
71326--- a/include/linux/pnp.h
71327+++ b/include/linux/pnp.h
71328@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
71329 struct pnp_fixup {
71330 char id[7];
71331 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
71332-};
71333+} __do_const;
71334
71335 /* config parameters */
71336 #define PNP_CONFIG_NORMAL 0x0001
71337diff --git a/include/linux/poison.h b/include/linux/poison.h
71338index 2110a81..13a11bb 100644
71339--- a/include/linux/poison.h
71340+++ b/include/linux/poison.h
71341@@ -19,8 +19,8 @@
71342 * under normal circumstances, used to verify that nobody uses
71343 * non-initialized list entries.
71344 */
71345-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
71346-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
71347+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
71348+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
71349
71350 /********** include/linux/timer.h **********/
71351 /*
71352diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
71353index c0f44c2..1572583 100644
71354--- a/include/linux/power/smartreflex.h
71355+++ b/include/linux/power/smartreflex.h
71356@@ -238,7 +238,7 @@ struct omap_sr_class_data {
71357 int (*notify)(struct omap_sr *sr, u32 status);
71358 u8 notify_flags;
71359 u8 class_type;
71360-};
71361+} __do_const;
71362
71363 /**
71364 * struct omap_sr_nvalue_table - Smartreflex n-target value info
71365diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
71366index 4ea1d37..80f4b33 100644
71367--- a/include/linux/ppp-comp.h
71368+++ b/include/linux/ppp-comp.h
71369@@ -84,7 +84,7 @@ struct compressor {
71370 struct module *owner;
71371 /* Extra skb space needed by the compressor algorithm */
71372 unsigned int comp_extra;
71373-};
71374+} __do_const;
71375
71376 /*
71377 * The return value from decompress routine is the length of the
71378diff --git a/include/linux/printk.h b/include/linux/printk.h
71379index 22c7052..ad3fa0a 100644
71380--- a/include/linux/printk.h
71381+++ b/include/linux/printk.h
71382@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
71383 void early_printk(const char *s, ...) { }
71384 #endif
71385
71386+extern int kptr_restrict;
71387+
71388 #ifdef CONFIG_PRINTK
71389 asmlinkage __printf(5, 0)
71390 int vprintk_emit(int facility, int level,
71391@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
71392
71393 extern int printk_delay_msec;
71394 extern int dmesg_restrict;
71395-extern int kptr_restrict;
71396
71397 extern void wake_up_klogd(void);
71398
71399diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
71400index 608e60a..c26f864 100644
71401--- a/include/linux/proc_fs.h
71402+++ b/include/linux/proc_fs.h
71403@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
71404 return proc_create_data(name, mode, parent, proc_fops, NULL);
71405 }
71406
71407+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
71408+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
71409+{
71410+#ifdef CONFIG_GRKERNSEC_PROC_USER
71411+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
71412+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71413+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
71414+#else
71415+ return proc_create_data(name, mode, parent, proc_fops, NULL);
71416+#endif
71417+}
71418+
71419+
71420 extern void proc_set_size(struct proc_dir_entry *, loff_t);
71421 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
71422 extern void *PDE_DATA(const struct inode *);
71423diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
71424index 34a1e10..03a6d03 100644
71425--- a/include/linux/proc_ns.h
71426+++ b/include/linux/proc_ns.h
71427@@ -14,7 +14,7 @@ struct proc_ns_operations {
71428 void (*put)(void *ns);
71429 int (*install)(struct nsproxy *nsproxy, void *ns);
71430 unsigned int (*inum)(void *ns);
71431-};
71432+} __do_const;
71433
71434 struct proc_ns {
71435 void *ns;
71436diff --git a/include/linux/random.h b/include/linux/random.h
71437index 3b9377d..61b506a 100644
71438--- a/include/linux/random.h
71439+++ b/include/linux/random.h
71440@@ -32,6 +32,11 @@ void prandom_seed(u32 seed);
71441 u32 prandom_u32_state(struct rnd_state *);
71442 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
71443
71444+static inline unsigned long pax_get_random_long(void)
71445+{
71446+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
71447+}
71448+
71449 /*
71450 * Handle minimum values for seeds
71451 */
71452diff --git a/include/linux/rculist.h b/include/linux/rculist.h
71453index f4b1001..8ddb2b6 100644
71454--- a/include/linux/rculist.h
71455+++ b/include/linux/rculist.h
71456@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
71457 struct list_head *prev, struct list_head *next);
71458 #endif
71459
71460+extern void __pax_list_add_rcu(struct list_head *new,
71461+ struct list_head *prev, struct list_head *next);
71462+
71463 /**
71464 * list_add_rcu - add a new entry to rcu-protected list
71465 * @new: new entry to be added
71466@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
71467 __list_add_rcu(new, head, head->next);
71468 }
71469
71470+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
71471+{
71472+ __pax_list_add_rcu(new, head, head->next);
71473+}
71474+
71475 /**
71476 * list_add_tail_rcu - add a new entry to rcu-protected list
71477 * @new: new entry to be added
71478@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
71479 __list_add_rcu(new, head->prev, head);
71480 }
71481
71482+static inline void pax_list_add_tail_rcu(struct list_head *new,
71483+ struct list_head *head)
71484+{
71485+ __pax_list_add_rcu(new, head->prev, head);
71486+}
71487+
71488 /**
71489 * list_del_rcu - deletes entry from list without re-initialization
71490 * @entry: the element to delete from the list.
71491@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
71492 entry->prev = LIST_POISON2;
71493 }
71494
71495+extern void pax_list_del_rcu(struct list_head *entry);
71496+
71497 /**
71498 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
71499 * @n: the element to delete from the hash list.
71500diff --git a/include/linux/reboot.h b/include/linux/reboot.h
71501index 23b3630..e1bc12b 100644
71502--- a/include/linux/reboot.h
71503+++ b/include/linux/reboot.h
71504@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
71505 * Architecture-specific implementations of sys_reboot commands.
71506 */
71507
71508-extern void machine_restart(char *cmd);
71509-extern void machine_halt(void);
71510-extern void machine_power_off(void);
71511+extern void machine_restart(char *cmd) __noreturn;
71512+extern void machine_halt(void) __noreturn;
71513+extern void machine_power_off(void) __noreturn;
71514
71515 extern void machine_shutdown(void);
71516 struct pt_regs;
71517@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
71518 */
71519
71520 extern void kernel_restart_prepare(char *cmd);
71521-extern void kernel_restart(char *cmd);
71522-extern void kernel_halt(void);
71523-extern void kernel_power_off(void);
71524+extern void kernel_restart(char *cmd) __noreturn;
71525+extern void kernel_halt(void) __noreturn;
71526+extern void kernel_power_off(void) __noreturn;
71527
71528 extern int C_A_D; /* for sysctl */
71529 void ctrl_alt_del(void);
71530@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
71531 * Emergency restart, callable from an interrupt handler.
71532 */
71533
71534-extern void emergency_restart(void);
71535+extern void emergency_restart(void) __noreturn;
71536 #include <asm/emergency-restart.h>
71537
71538 #endif /* _LINUX_REBOOT_H */
71539diff --git a/include/linux/regset.h b/include/linux/regset.h
71540index 8e0c9fe..ac4d221 100644
71541--- a/include/linux/regset.h
71542+++ b/include/linux/regset.h
71543@@ -161,7 +161,8 @@ struct user_regset {
71544 unsigned int align;
71545 unsigned int bias;
71546 unsigned int core_note_type;
71547-};
71548+} __do_const;
71549+typedef struct user_regset __no_const user_regset_no_const;
71550
71551 /**
71552 * struct user_regset_view - available regsets
71553diff --git a/include/linux/relay.h b/include/linux/relay.h
71554index d7c8359..818daf5 100644
71555--- a/include/linux/relay.h
71556+++ b/include/linux/relay.h
71557@@ -157,7 +157,7 @@ struct rchan_callbacks
71558 * The callback should return 0 if successful, negative if not.
71559 */
71560 int (*remove_buf_file)(struct dentry *dentry);
71561-};
71562+} __no_const;
71563
71564 /*
71565 * CONFIG_RELAY kernel API, kernel/relay.c
71566diff --git a/include/linux/rio.h b/include/linux/rio.h
71567index 18e0993..8ab5b21 100644
71568--- a/include/linux/rio.h
71569+++ b/include/linux/rio.h
71570@@ -345,7 +345,7 @@ struct rio_ops {
71571 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
71572 u64 rstart, u32 size, u32 flags);
71573 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
71574-};
71575+} __no_const;
71576
71577 #define RIO_RESOURCE_MEM 0x00000100
71578 #define RIO_RESOURCE_DOORBELL 0x00000200
71579diff --git a/include/linux/rmap.h b/include/linux/rmap.h
71580index 6dacb93..6174423 100644
71581--- a/include/linux/rmap.h
71582+++ b/include/linux/rmap.h
71583@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
71584 void anon_vma_init(void); /* create anon_vma_cachep */
71585 int anon_vma_prepare(struct vm_area_struct *);
71586 void unlink_anon_vmas(struct vm_area_struct *);
71587-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
71588-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
71589+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
71590+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
71591
71592 static inline void anon_vma_merge(struct vm_area_struct *vma,
71593 struct vm_area_struct *next)
71594diff --git a/include/linux/sched.h b/include/linux/sched.h
71595index 178a8d9..52e71a3 100644
71596--- a/include/linux/sched.h
71597+++ b/include/linux/sched.h
71598@@ -62,6 +62,7 @@ struct bio_list;
71599 struct fs_struct;
71600 struct perf_event_context;
71601 struct blk_plug;
71602+struct linux_binprm;
71603
71604 /*
71605 * List of flags we want to share for kernel threads,
71606@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
71607 extern int in_sched_functions(unsigned long addr);
71608
71609 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
71610-extern signed long schedule_timeout(signed long timeout);
71611+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
71612 extern signed long schedule_timeout_interruptible(signed long timeout);
71613 extern signed long schedule_timeout_killable(signed long timeout);
71614 extern signed long schedule_timeout_uninterruptible(signed long timeout);
71615@@ -314,6 +315,19 @@ struct nsproxy;
71616 struct user_namespace;
71617
71618 #ifdef CONFIG_MMU
71619+
71620+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
71621+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
71622+#else
71623+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
71624+{
71625+ return 0;
71626+}
71627+#endif
71628+
71629+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
71630+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
71631+
71632 extern void arch_pick_mmap_layout(struct mm_struct *mm);
71633 extern unsigned long
71634 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
71635@@ -591,6 +605,17 @@ struct signal_struct {
71636 #ifdef CONFIG_TASKSTATS
71637 struct taskstats *stats;
71638 #endif
71639+
71640+#ifdef CONFIG_GRKERNSEC
71641+ u32 curr_ip;
71642+ u32 saved_ip;
71643+ u32 gr_saddr;
71644+ u32 gr_daddr;
71645+ u16 gr_sport;
71646+ u16 gr_dport;
71647+ u8 used_accept:1;
71648+#endif
71649+
71650 #ifdef CONFIG_AUDIT
71651 unsigned audit_tty;
71652 unsigned audit_tty_log_passwd;
71653@@ -671,6 +696,14 @@ struct user_struct {
71654 struct key *session_keyring; /* UID's default session keyring */
71655 #endif
71656
71657+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71658+ unsigned char kernel_banned;
71659+#endif
71660+#ifdef CONFIG_GRKERNSEC_BRUTE
71661+ unsigned char suid_banned;
71662+ unsigned long suid_ban_expires;
71663+#endif
71664+
71665 /* Hash table maintenance information */
71666 struct hlist_node uidhash_node;
71667 kuid_t uid;
71668@@ -1158,8 +1191,8 @@ struct task_struct {
71669 struct list_head thread_group;
71670
71671 struct completion *vfork_done; /* for vfork() */
71672- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
71673- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71674+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
71675+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71676
71677 cputime_t utime, stime, utimescaled, stimescaled;
71678 cputime_t gtime;
71679@@ -1184,11 +1217,6 @@ struct task_struct {
71680 struct task_cputime cputime_expires;
71681 struct list_head cpu_timers[3];
71682
71683-/* process credentials */
71684- const struct cred __rcu *real_cred; /* objective and real subjective task
71685- * credentials (COW) */
71686- const struct cred __rcu *cred; /* effective (overridable) subjective task
71687- * credentials (COW) */
71688 char comm[TASK_COMM_LEN]; /* executable name excluding path
71689 - access with [gs]et_task_comm (which lock
71690 it with task_lock())
71691@@ -1205,6 +1233,10 @@ struct task_struct {
71692 #endif
71693 /* CPU-specific state of this task */
71694 struct thread_struct thread;
71695+/* thread_info moved to task_struct */
71696+#ifdef CONFIG_X86
71697+ struct thread_info tinfo;
71698+#endif
71699 /* filesystem information */
71700 struct fs_struct *fs;
71701 /* open file information */
71702@@ -1278,6 +1310,10 @@ struct task_struct {
71703 gfp_t lockdep_reclaim_gfp;
71704 #endif
71705
71706+/* process credentials */
71707+ const struct cred __rcu *real_cred; /* objective and real subjective task
71708+ * credentials (COW) */
71709+
71710 /* journalling filesystem info */
71711 void *journal_info;
71712
71713@@ -1316,6 +1352,10 @@ struct task_struct {
71714 /* cg_list protected by css_set_lock and tsk->alloc_lock */
71715 struct list_head cg_list;
71716 #endif
71717+
71718+ const struct cred __rcu *cred; /* effective (overridable) subjective task
71719+ * credentials (COW) */
71720+
71721 #ifdef CONFIG_FUTEX
71722 struct robust_list_head __user *robust_list;
71723 #ifdef CONFIG_COMPAT
71724@@ -1416,8 +1456,74 @@ struct task_struct {
71725 unsigned int sequential_io;
71726 unsigned int sequential_io_avg;
71727 #endif
71728+
71729+#ifdef CONFIG_GRKERNSEC
71730+ /* grsecurity */
71731+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71732+ u64 exec_id;
71733+#endif
71734+#ifdef CONFIG_GRKERNSEC_SETXID
71735+ const struct cred *delayed_cred;
71736+#endif
71737+ struct dentry *gr_chroot_dentry;
71738+ struct acl_subject_label *acl;
71739+ struct acl_role_label *role;
71740+ struct file *exec_file;
71741+ unsigned long brute_expires;
71742+ u16 acl_role_id;
71743+ /* is this the task that authenticated to the special role */
71744+ u8 acl_sp_role;
71745+ u8 is_writable;
71746+ u8 brute;
71747+ u8 gr_is_chrooted;
71748+#endif
71749+
71750 };
71751
71752+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
71753+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
71754+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
71755+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
71756+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
71757+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
71758+
71759+#ifdef CONFIG_PAX_SOFTMODE
71760+extern int pax_softmode;
71761+#endif
71762+
71763+extern int pax_check_flags(unsigned long *);
71764+
71765+/* if tsk != current then task_lock must be held on it */
71766+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
71767+static inline unsigned long pax_get_flags(struct task_struct *tsk)
71768+{
71769+ if (likely(tsk->mm))
71770+ return tsk->mm->pax_flags;
71771+ else
71772+ return 0UL;
71773+}
71774+
71775+/* if tsk != current then task_lock must be held on it */
71776+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
71777+{
71778+ if (likely(tsk->mm)) {
71779+ tsk->mm->pax_flags = flags;
71780+ return 0;
71781+ }
71782+ return -EINVAL;
71783+}
71784+#endif
71785+
71786+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
71787+extern void pax_set_initial_flags(struct linux_binprm *bprm);
71788+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
71789+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
71790+#endif
71791+
71792+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
71793+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
71794+extern void pax_report_refcount_overflow(struct pt_regs *regs);
71795+
71796 /* Future-safe accessor for struct task_struct's cpus_allowed. */
71797 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
71798
71799@@ -1476,7 +1582,7 @@ struct pid_namespace;
71800 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
71801 struct pid_namespace *ns);
71802
71803-static inline pid_t task_pid_nr(struct task_struct *tsk)
71804+static inline pid_t task_pid_nr(const struct task_struct *tsk)
71805 {
71806 return tsk->pid;
71807 }
71808@@ -1919,7 +2025,9 @@ void yield(void);
71809 extern struct exec_domain default_exec_domain;
71810
71811 union thread_union {
71812+#ifndef CONFIG_X86
71813 struct thread_info thread_info;
71814+#endif
71815 unsigned long stack[THREAD_SIZE/sizeof(long)];
71816 };
71817
71818@@ -1952,6 +2060,7 @@ extern struct pid_namespace init_pid_ns;
71819 */
71820
71821 extern struct task_struct *find_task_by_vpid(pid_t nr);
71822+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
71823 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
71824 struct pid_namespace *ns);
71825
71826@@ -2118,7 +2227,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
71827 extern void exit_itimers(struct signal_struct *);
71828 extern void flush_itimer_signals(void);
71829
71830-extern void do_group_exit(int);
71831+extern __noreturn void do_group_exit(int);
71832
71833 extern int allow_signal(int);
71834 extern int disallow_signal(int);
71835@@ -2309,9 +2418,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
71836
71837 #endif
71838
71839-static inline int object_is_on_stack(void *obj)
71840+static inline int object_starts_on_stack(void *obj)
71841 {
71842- void *stack = task_stack_page(current);
71843+ const void *stack = task_stack_page(current);
71844
71845 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
71846 }
71847diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
71848index bf8086b..962b035 100644
71849--- a/include/linux/sched/sysctl.h
71850+++ b/include/linux/sched/sysctl.h
71851@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
71852 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
71853
71854 extern int sysctl_max_map_count;
71855+extern unsigned long sysctl_heap_stack_gap;
71856
71857 extern unsigned int sysctl_sched_latency;
71858 extern unsigned int sysctl_sched_min_granularity;
71859diff --git a/include/linux/security.h b/include/linux/security.h
71860index 4686491..2bd210e 100644
71861--- a/include/linux/security.h
71862+++ b/include/linux/security.h
71863@@ -26,6 +26,7 @@
71864 #include <linux/capability.h>
71865 #include <linux/slab.h>
71866 #include <linux/err.h>
71867+#include <linux/grsecurity.h>
71868
71869 struct linux_binprm;
71870 struct cred;
71871diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
71872index 2da29ac..aac448ec 100644
71873--- a/include/linux/seq_file.h
71874+++ b/include/linux/seq_file.h
71875@@ -26,6 +26,9 @@ struct seq_file {
71876 struct mutex lock;
71877 const struct seq_operations *op;
71878 int poll_event;
71879+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71880+ u64 exec_id;
71881+#endif
71882 #ifdef CONFIG_USER_NS
71883 struct user_namespace *user_ns;
71884 #endif
71885@@ -38,6 +41,7 @@ struct seq_operations {
71886 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
71887 int (*show) (struct seq_file *m, void *v);
71888 };
71889+typedef struct seq_operations __no_const seq_operations_no_const;
71890
71891 #define SEQ_SKIP 1
71892
71893diff --git a/include/linux/shm.h b/include/linux/shm.h
71894index 429c199..4d42e38 100644
71895--- a/include/linux/shm.h
71896+++ b/include/linux/shm.h
71897@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
71898
71899 /* The task created the shm object. NULL if the task is dead. */
71900 struct task_struct *shm_creator;
71901+#ifdef CONFIG_GRKERNSEC
71902+ time_t shm_createtime;
71903+ pid_t shm_lapid;
71904+#endif
71905 };
71906
71907 /* shm_mode upper byte flags */
71908diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
71909index dec1748..112c1f9 100644
71910--- a/include/linux/skbuff.h
71911+++ b/include/linux/skbuff.h
71912@@ -640,7 +640,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
71913 extern struct sk_buff *__alloc_skb(unsigned int size,
71914 gfp_t priority, int flags, int node);
71915 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
71916-static inline struct sk_buff *alloc_skb(unsigned int size,
71917+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
71918 gfp_t priority)
71919 {
71920 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
71921@@ -756,7 +756,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
71922 */
71923 static inline int skb_queue_empty(const struct sk_buff_head *list)
71924 {
71925- return list->next == (struct sk_buff *)list;
71926+ return list->next == (const struct sk_buff *)list;
71927 }
71928
71929 /**
71930@@ -769,7 +769,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
71931 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71932 const struct sk_buff *skb)
71933 {
71934- return skb->next == (struct sk_buff *)list;
71935+ return skb->next == (const struct sk_buff *)list;
71936 }
71937
71938 /**
71939@@ -782,7 +782,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71940 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
71941 const struct sk_buff *skb)
71942 {
71943- return skb->prev == (struct sk_buff *)list;
71944+ return skb->prev == (const struct sk_buff *)list;
71945 }
71946
71947 /**
71948@@ -1848,7 +1848,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
71949 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
71950 */
71951 #ifndef NET_SKB_PAD
71952-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
71953+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
71954 #endif
71955
71956 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
71957@@ -2443,7 +2443,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
71958 int noblock, int *err);
71959 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
71960 struct poll_table_struct *wait);
71961-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
71962+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
71963 int offset, struct iovec *to,
71964 int size);
71965 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
71966@@ -2733,6 +2733,9 @@ static inline void nf_reset(struct sk_buff *skb)
71967 nf_bridge_put(skb->nf_bridge);
71968 skb->nf_bridge = NULL;
71969 #endif
71970+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
71971+ skb->nf_trace = 0;
71972+#endif
71973 }
71974
71975 static inline void nf_reset_trace(struct sk_buff *skb)
71976diff --git a/include/linux/slab.h b/include/linux/slab.h
71977index 0c62175..9ece3d8 100644
71978--- a/include/linux/slab.h
71979+++ b/include/linux/slab.h
71980@@ -12,13 +12,20 @@
71981 #include <linux/gfp.h>
71982 #include <linux/types.h>
71983 #include <linux/workqueue.h>
71984-
71985+#include <linux/err.h>
71986
71987 /*
71988 * Flags to pass to kmem_cache_create().
71989 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
71990 */
71991 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
71992+
71993+#ifdef CONFIG_PAX_USERCOPY_SLABS
71994+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
71995+#else
71996+#define SLAB_USERCOPY 0x00000000UL
71997+#endif
71998+
71999 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
72000 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
72001 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
72002@@ -89,10 +96,13 @@
72003 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
72004 * Both make kfree a no-op.
72005 */
72006-#define ZERO_SIZE_PTR ((void *)16)
72007+#define ZERO_SIZE_PTR \
72008+({ \
72009+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
72010+ (void *)(-MAX_ERRNO-1L); \
72011+})
72012
72013-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
72014- (unsigned long)ZERO_SIZE_PTR)
72015+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
72016
72017
72018 struct mem_cgroup;
72019@@ -132,6 +142,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
72020 void kfree(const void *);
72021 void kzfree(const void *);
72022 size_t ksize(const void *);
72023+const char *check_heap_object(const void *ptr, unsigned long n);
72024+bool is_usercopy_object(const void *ptr);
72025
72026 /*
72027 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
72028@@ -164,7 +176,7 @@ struct kmem_cache {
72029 unsigned int align; /* Alignment as calculated */
72030 unsigned long flags; /* Active flags on the slab */
72031 const char *name; /* Slab name for sysfs */
72032- int refcount; /* Use counter */
72033+ atomic_t refcount; /* Use counter */
72034 void (*ctor)(void *); /* Called on object slot creation */
72035 struct list_head list; /* List of all slab caches on the system */
72036 };
72037@@ -226,6 +238,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
72038 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
72039 #endif
72040
72041+#ifdef CONFIG_PAX_USERCOPY_SLABS
72042+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
72043+#endif
72044+
72045 /*
72046 * Figure out which kmalloc slab an allocation of a certain size
72047 * belongs to.
72048@@ -234,7 +250,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
72049 * 2 = 120 .. 192 bytes
72050 * n = 2^(n-1) .. 2^n -1
72051 */
72052-static __always_inline int kmalloc_index(size_t size)
72053+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
72054 {
72055 if (!size)
72056 return 0;
72057@@ -406,6 +422,7 @@ void print_slabinfo_header(struct seq_file *m);
72058 * for general use, and so are not documented here. For a full list of
72059 * potential flags, always refer to linux/gfp.h.
72060 */
72061+
72062 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
72063 {
72064 if (size != 0 && n > SIZE_MAX / size)
72065@@ -465,7 +482,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
72066 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
72067 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
72068 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
72069-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
72070+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
72071 #define kmalloc_track_caller(size, flags) \
72072 __kmalloc_track_caller(size, flags, _RET_IP_)
72073 #else
72074@@ -485,7 +502,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
72075 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
72076 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
72077 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
72078-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
72079+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
72080 #define kmalloc_node_track_caller(size, flags, node) \
72081 __kmalloc_node_track_caller(size, flags, node, \
72082 _RET_IP_)
72083diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
72084index cd40158..d9dc02c 100644
72085--- a/include/linux/slab_def.h
72086+++ b/include/linux/slab_def.h
72087@@ -50,7 +50,7 @@ struct kmem_cache {
72088 /* 4) cache creation/removal */
72089 const char *name;
72090 struct list_head list;
72091- int refcount;
72092+ atomic_t refcount;
72093 int object_size;
72094 int align;
72095
72096@@ -66,10 +66,10 @@ struct kmem_cache {
72097 unsigned long node_allocs;
72098 unsigned long node_frees;
72099 unsigned long node_overflow;
72100- atomic_t allochit;
72101- atomic_t allocmiss;
72102- atomic_t freehit;
72103- atomic_t freemiss;
72104+ atomic_unchecked_t allochit;
72105+ atomic_unchecked_t allocmiss;
72106+ atomic_unchecked_t freehit;
72107+ atomic_unchecked_t freemiss;
72108
72109 /*
72110 * If debugging is enabled, then the allocator can add additional
72111@@ -103,7 +103,7 @@ struct kmem_cache {
72112 };
72113
72114 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
72115-void *__kmalloc(size_t size, gfp_t flags);
72116+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
72117
72118 #ifdef CONFIG_TRACING
72119 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
72120@@ -136,6 +136,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72121 cachep = kmalloc_dma_caches[i];
72122 else
72123 #endif
72124+
72125+#ifdef CONFIG_PAX_USERCOPY_SLABS
72126+ if (flags & GFP_USERCOPY)
72127+ cachep = kmalloc_usercopy_caches[i];
72128+ else
72129+#endif
72130+
72131 cachep = kmalloc_caches[i];
72132
72133 ret = kmem_cache_alloc_trace(cachep, flags, size);
72134@@ -146,7 +153,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72135 }
72136
72137 #ifdef CONFIG_NUMA
72138-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
72139+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72140 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72141
72142 #ifdef CONFIG_TRACING
72143@@ -185,6 +192,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
72144 cachep = kmalloc_dma_caches[i];
72145 else
72146 #endif
72147+
72148+#ifdef CONFIG_PAX_USERCOPY_SLABS
72149+ if (flags & GFP_USERCOPY)
72150+ cachep = kmalloc_usercopy_caches[i];
72151+ else
72152+#endif
72153+
72154 cachep = kmalloc_caches[i];
72155
72156 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
72157diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
72158index f28e14a..7831211 100644
72159--- a/include/linux/slob_def.h
72160+++ b/include/linux/slob_def.h
72161@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
72162 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
72163 }
72164
72165-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72166+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72167
72168 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
72169 {
72170@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72171 return __kmalloc_node(size, flags, NUMA_NO_NODE);
72172 }
72173
72174-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
72175+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
72176 {
72177 return kmalloc(size, flags);
72178 }
72179diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
72180index 027276f..092bfe8 100644
72181--- a/include/linux/slub_def.h
72182+++ b/include/linux/slub_def.h
72183@@ -80,7 +80,7 @@ struct kmem_cache {
72184 struct kmem_cache_order_objects max;
72185 struct kmem_cache_order_objects min;
72186 gfp_t allocflags; /* gfp flags to use on each alloc */
72187- int refcount; /* Refcount for slab cache destroy */
72188+ atomic_t refcount; /* Refcount for slab cache destroy */
72189 void (*ctor)(void *);
72190 int inuse; /* Offset to metadata */
72191 int align; /* Alignment */
72192@@ -105,7 +105,7 @@ struct kmem_cache {
72193 };
72194
72195 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
72196-void *__kmalloc(size_t size, gfp_t flags);
72197+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
72198
72199 static __always_inline void *
72200 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
72201@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
72202 }
72203 #endif
72204
72205-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
72206+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
72207 {
72208 unsigned int order = get_order(size);
72209 return kmalloc_order_trace(size, flags, order);
72210@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72211 }
72212
72213 #ifdef CONFIG_NUMA
72214-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72215+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72216 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72217
72218 #ifdef CONFIG_TRACING
72219diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
72220index 54f91d3..be2c379 100644
72221--- a/include/linux/sock_diag.h
72222+++ b/include/linux/sock_diag.h
72223@@ -11,7 +11,7 @@ struct sock;
72224 struct sock_diag_handler {
72225 __u8 family;
72226 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
72227-};
72228+} __do_const;
72229
72230 int sock_diag_register(const struct sock_diag_handler *h);
72231 void sock_diag_unregister(const struct sock_diag_handler *h);
72232diff --git a/include/linux/sonet.h b/include/linux/sonet.h
72233index 680f9a3..f13aeb0 100644
72234--- a/include/linux/sonet.h
72235+++ b/include/linux/sonet.h
72236@@ -7,7 +7,7 @@
72237 #include <uapi/linux/sonet.h>
72238
72239 struct k_sonet_stats {
72240-#define __HANDLE_ITEM(i) atomic_t i
72241+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72242 __SONET_ITEMS
72243 #undef __HANDLE_ITEM
72244 };
72245diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
72246index 07d8e53..dc934c9 100644
72247--- a/include/linux/sunrpc/addr.h
72248+++ b/include/linux/sunrpc/addr.h
72249@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
72250 {
72251 switch (sap->sa_family) {
72252 case AF_INET:
72253- return ntohs(((struct sockaddr_in *)sap)->sin_port);
72254+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
72255 case AF_INET6:
72256- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
72257+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
72258 }
72259 return 0;
72260 }
72261@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
72262 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
72263 const struct sockaddr *src)
72264 {
72265- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
72266+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
72267 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
72268
72269 dsin->sin_family = ssin->sin_family;
72270@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
72271 if (sa->sa_family != AF_INET6)
72272 return 0;
72273
72274- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
72275+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
72276 }
72277
72278 #endif /* _LINUX_SUNRPC_ADDR_H */
72279diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
72280index bfe11be..12bc8c4 100644
72281--- a/include/linux/sunrpc/clnt.h
72282+++ b/include/linux/sunrpc/clnt.h
72283@@ -96,7 +96,7 @@ struct rpc_procinfo {
72284 unsigned int p_timer; /* Which RTT timer to use */
72285 u32 p_statidx; /* Which procedure to account */
72286 const char * p_name; /* name of procedure */
72287-};
72288+} __do_const;
72289
72290 #ifdef __KERNEL__
72291
72292diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
72293index 1f0216b..6a4fa50 100644
72294--- a/include/linux/sunrpc/svc.h
72295+++ b/include/linux/sunrpc/svc.h
72296@@ -411,7 +411,7 @@ struct svc_procedure {
72297 unsigned int pc_count; /* call count */
72298 unsigned int pc_cachetype; /* cache info (NFS) */
72299 unsigned int pc_xdrressize; /* maximum size of XDR reply */
72300-};
72301+} __do_const;
72302
72303 /*
72304 * Function prototypes.
72305diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
72306index 0b8e3e6..33e0a01 100644
72307--- a/include/linux/sunrpc/svc_rdma.h
72308+++ b/include/linux/sunrpc/svc_rdma.h
72309@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
72310 extern unsigned int svcrdma_max_requests;
72311 extern unsigned int svcrdma_max_req_size;
72312
72313-extern atomic_t rdma_stat_recv;
72314-extern atomic_t rdma_stat_read;
72315-extern atomic_t rdma_stat_write;
72316-extern atomic_t rdma_stat_sq_starve;
72317-extern atomic_t rdma_stat_rq_starve;
72318-extern atomic_t rdma_stat_rq_poll;
72319-extern atomic_t rdma_stat_rq_prod;
72320-extern atomic_t rdma_stat_sq_poll;
72321-extern atomic_t rdma_stat_sq_prod;
72322+extern atomic_unchecked_t rdma_stat_recv;
72323+extern atomic_unchecked_t rdma_stat_read;
72324+extern atomic_unchecked_t rdma_stat_write;
72325+extern atomic_unchecked_t rdma_stat_sq_starve;
72326+extern atomic_unchecked_t rdma_stat_rq_starve;
72327+extern atomic_unchecked_t rdma_stat_rq_poll;
72328+extern atomic_unchecked_t rdma_stat_rq_prod;
72329+extern atomic_unchecked_t rdma_stat_sq_poll;
72330+extern atomic_unchecked_t rdma_stat_sq_prod;
72331
72332 #define RPCRDMA_VERSION 1
72333
72334diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
72335index ff374ab..7fd2ecb 100644
72336--- a/include/linux/sunrpc/svcauth.h
72337+++ b/include/linux/sunrpc/svcauth.h
72338@@ -109,7 +109,7 @@ struct auth_ops {
72339 int (*release)(struct svc_rqst *rq);
72340 void (*domain_release)(struct auth_domain *);
72341 int (*set_client)(struct svc_rqst *rq);
72342-};
72343+} __do_const;
72344
72345 #define SVC_GARBAGE 1
72346 #define SVC_SYSERR 2
72347diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
72348index a5ffd32..0935dea 100644
72349--- a/include/linux/swiotlb.h
72350+++ b/include/linux/swiotlb.h
72351@@ -60,7 +60,8 @@ extern void
72352
72353 extern void
72354 swiotlb_free_coherent(struct device *hwdev, size_t size,
72355- void *vaddr, dma_addr_t dma_handle);
72356+ void *vaddr, dma_addr_t dma_handle,
72357+ struct dma_attrs *attrs);
72358
72359 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
72360 unsigned long offset, size_t size,
72361diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
72362index 4147d70..31a1791 100644
72363--- a/include/linux/syscalls.h
72364+++ b/include/linux/syscalls.h
72365@@ -362,11 +362,11 @@ asmlinkage long sys_sync(void);
72366 asmlinkage long sys_fsync(unsigned int fd);
72367 asmlinkage long sys_fdatasync(unsigned int fd);
72368 asmlinkage long sys_bdflush(int func, long data);
72369-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
72370- char __user *type, unsigned long flags,
72371+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
72372+ const char __user *type, unsigned long flags,
72373 void __user *data);
72374-asmlinkage long sys_umount(char __user *name, int flags);
72375-asmlinkage long sys_oldumount(char __user *name);
72376+asmlinkage long sys_umount(const char __user *name, int flags);
72377+asmlinkage long sys_oldumount(const char __user *name);
72378 asmlinkage long sys_truncate(const char __user *path, long length);
72379 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
72380 asmlinkage long sys_stat(const char __user *filename,
72381@@ -578,7 +578,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
72382 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
72383 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
72384 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
72385- struct sockaddr __user *, int);
72386+ struct sockaddr __user *, int) __intentional_overflow(0);
72387 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
72388 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
72389 unsigned int vlen, unsigned flags);
72390diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
72391index 27b3b0b..e093dd9 100644
72392--- a/include/linux/syscore_ops.h
72393+++ b/include/linux/syscore_ops.h
72394@@ -16,7 +16,7 @@ struct syscore_ops {
72395 int (*suspend)(void);
72396 void (*resume)(void);
72397 void (*shutdown)(void);
72398-};
72399+} __do_const;
72400
72401 extern void register_syscore_ops(struct syscore_ops *ops);
72402 extern void unregister_syscore_ops(struct syscore_ops *ops);
72403diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
72404index 14a8ff2..af52bad 100644
72405--- a/include/linux/sysctl.h
72406+++ b/include/linux/sysctl.h
72407@@ -34,13 +34,13 @@ struct ctl_table_root;
72408 struct ctl_table_header;
72409 struct ctl_dir;
72410
72411-typedef struct ctl_table ctl_table;
72412-
72413 typedef int proc_handler (struct ctl_table *ctl, int write,
72414 void __user *buffer, size_t *lenp, loff_t *ppos);
72415
72416 extern int proc_dostring(struct ctl_table *, int,
72417 void __user *, size_t *, loff_t *);
72418+extern int proc_dostring_modpriv(struct ctl_table *, int,
72419+ void __user *, size_t *, loff_t *);
72420 extern int proc_dointvec(struct ctl_table *, int,
72421 void __user *, size_t *, loff_t *);
72422 extern int proc_dointvec_minmax(struct ctl_table *, int,
72423@@ -115,7 +115,9 @@ struct ctl_table
72424 struct ctl_table_poll *poll;
72425 void *extra1;
72426 void *extra2;
72427-};
72428+} __do_const;
72429+typedef struct ctl_table __no_const ctl_table_no_const;
72430+typedef struct ctl_table ctl_table;
72431
72432 struct ctl_node {
72433 struct rb_node node;
72434diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
72435index e2cee22..3ddb921 100644
72436--- a/include/linux/sysfs.h
72437+++ b/include/linux/sysfs.h
72438@@ -31,7 +31,8 @@ struct attribute {
72439 struct lock_class_key *key;
72440 struct lock_class_key skey;
72441 #endif
72442-};
72443+} __do_const;
72444+typedef struct attribute __no_const attribute_no_const;
72445
72446 /**
72447 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
72448@@ -59,8 +60,8 @@ struct attribute_group {
72449 umode_t (*is_visible)(struct kobject *,
72450 struct attribute *, int);
72451 struct attribute **attrs;
72452-};
72453-
72454+} __do_const;
72455+typedef struct attribute_group __no_const attribute_group_no_const;
72456
72457
72458 /**
72459@@ -107,7 +108,8 @@ struct bin_attribute {
72460 char *, loff_t, size_t);
72461 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
72462 struct vm_area_struct *vma);
72463-};
72464+} __do_const;
72465+typedef struct bin_attribute __no_const bin_attribute_no_const;
72466
72467 /**
72468 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
72469diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
72470index 7faf933..9b85a0c 100644
72471--- a/include/linux/sysrq.h
72472+++ b/include/linux/sysrq.h
72473@@ -16,6 +16,7 @@
72474
72475 #include <linux/errno.h>
72476 #include <linux/types.h>
72477+#include <linux/compiler.h>
72478
72479 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
72480 #define SYSRQ_DEFAULT_ENABLE 1
72481@@ -36,7 +37,7 @@ struct sysrq_key_op {
72482 char *help_msg;
72483 char *action_msg;
72484 int enable_mask;
72485-};
72486+} __do_const;
72487
72488 #ifdef CONFIG_MAGIC_SYSRQ
72489
72490diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
72491index e7e0473..7989295 100644
72492--- a/include/linux/thread_info.h
72493+++ b/include/linux/thread_info.h
72494@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
72495 #error "no set_restore_sigmask() provided and default one won't work"
72496 #endif
72497
72498+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
72499+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
72500+{
72501+#ifndef CONFIG_PAX_USERCOPY_DEBUG
72502+ if (!__builtin_constant_p(n))
72503+#endif
72504+ __check_object_size(ptr, n, to_user);
72505+}
72506+
72507 #endif /* __KERNEL__ */
72508
72509 #endif /* _LINUX_THREAD_INFO_H */
72510diff --git a/include/linux/tty.h b/include/linux/tty.h
72511index 8780bd2..d1ae08b 100644
72512--- a/include/linux/tty.h
72513+++ b/include/linux/tty.h
72514@@ -194,7 +194,7 @@ struct tty_port {
72515 const struct tty_port_operations *ops; /* Port operations */
72516 spinlock_t lock; /* Lock protecting tty field */
72517 int blocked_open; /* Waiting to open */
72518- int count; /* Usage count */
72519+ atomic_t count; /* Usage count */
72520 wait_queue_head_t open_wait; /* Open waiters */
72521 wait_queue_head_t close_wait; /* Close waiters */
72522 wait_queue_head_t delta_msr_wait; /* Modem status change */
72523@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
72524 struct tty_struct *tty, struct file *filp);
72525 static inline int tty_port_users(struct tty_port *port)
72526 {
72527- return port->count + port->blocked_open;
72528+ return atomic_read(&port->count) + port->blocked_open;
72529 }
72530
72531 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
72532diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
72533index 756a609..b302dd6 100644
72534--- a/include/linux/tty_driver.h
72535+++ b/include/linux/tty_driver.h
72536@@ -285,7 +285,7 @@ struct tty_operations {
72537 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
72538 #endif
72539 const struct file_operations *proc_fops;
72540-};
72541+} __do_const;
72542
72543 struct tty_driver {
72544 int magic; /* magic number for this structure */
72545diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
72546index 58390c7..95e214c 100644
72547--- a/include/linux/tty_ldisc.h
72548+++ b/include/linux/tty_ldisc.h
72549@@ -146,7 +146,7 @@ struct tty_ldisc_ops {
72550
72551 struct module *owner;
72552
72553- int refcount;
72554+ atomic_t refcount;
72555 };
72556
72557 struct tty_ldisc {
72558diff --git a/include/linux/types.h b/include/linux/types.h
72559index 4d118ba..c3ee9bf 100644
72560--- a/include/linux/types.h
72561+++ b/include/linux/types.h
72562@@ -176,10 +176,26 @@ typedef struct {
72563 int counter;
72564 } atomic_t;
72565
72566+#ifdef CONFIG_PAX_REFCOUNT
72567+typedef struct {
72568+ int counter;
72569+} atomic_unchecked_t;
72570+#else
72571+typedef atomic_t atomic_unchecked_t;
72572+#endif
72573+
72574 #ifdef CONFIG_64BIT
72575 typedef struct {
72576 long counter;
72577 } atomic64_t;
72578+
72579+#ifdef CONFIG_PAX_REFCOUNT
72580+typedef struct {
72581+ long counter;
72582+} atomic64_unchecked_t;
72583+#else
72584+typedef atomic64_t atomic64_unchecked_t;
72585+#endif
72586 #endif
72587
72588 struct list_head {
72589diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
72590index 5ca0951..ab496a5 100644
72591--- a/include/linux/uaccess.h
72592+++ b/include/linux/uaccess.h
72593@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
72594 long ret; \
72595 mm_segment_t old_fs = get_fs(); \
72596 \
72597- set_fs(KERNEL_DS); \
72598 pagefault_disable(); \
72599- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
72600- pagefault_enable(); \
72601+ set_fs(KERNEL_DS); \
72602+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
72603 set_fs(old_fs); \
72604+ pagefault_enable(); \
72605 ret; \
72606 })
72607
72608diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
72609index 8e522cbc..aa8572d 100644
72610--- a/include/linux/uidgid.h
72611+++ b/include/linux/uidgid.h
72612@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
72613
72614 #endif /* CONFIG_USER_NS */
72615
72616+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
72617+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
72618+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
72619+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
72620+
72621 #endif /* _LINUX_UIDGID_H */
72622diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
72623index 99c1b4d..562e6f3 100644
72624--- a/include/linux/unaligned/access_ok.h
72625+++ b/include/linux/unaligned/access_ok.h
72626@@ -4,34 +4,34 @@
72627 #include <linux/kernel.h>
72628 #include <asm/byteorder.h>
72629
72630-static inline u16 get_unaligned_le16(const void *p)
72631+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
72632 {
72633- return le16_to_cpup((__le16 *)p);
72634+ return le16_to_cpup((const __le16 *)p);
72635 }
72636
72637-static inline u32 get_unaligned_le32(const void *p)
72638+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
72639 {
72640- return le32_to_cpup((__le32 *)p);
72641+ return le32_to_cpup((const __le32 *)p);
72642 }
72643
72644-static inline u64 get_unaligned_le64(const void *p)
72645+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
72646 {
72647- return le64_to_cpup((__le64 *)p);
72648+ return le64_to_cpup((const __le64 *)p);
72649 }
72650
72651-static inline u16 get_unaligned_be16(const void *p)
72652+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
72653 {
72654- return be16_to_cpup((__be16 *)p);
72655+ return be16_to_cpup((const __be16 *)p);
72656 }
72657
72658-static inline u32 get_unaligned_be32(const void *p)
72659+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
72660 {
72661- return be32_to_cpup((__be32 *)p);
72662+ return be32_to_cpup((const __be32 *)p);
72663 }
72664
72665-static inline u64 get_unaligned_be64(const void *p)
72666+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
72667 {
72668- return be64_to_cpup((__be64 *)p);
72669+ return be64_to_cpup((const __be64 *)p);
72670 }
72671
72672 static inline void put_unaligned_le16(u16 val, void *p)
72673diff --git a/include/linux/usb.h b/include/linux/usb.h
72674index a0bee5a..5533a52 100644
72675--- a/include/linux/usb.h
72676+++ b/include/linux/usb.h
72677@@ -552,7 +552,7 @@ struct usb_device {
72678 int maxchild;
72679
72680 u32 quirks;
72681- atomic_t urbnum;
72682+ atomic_unchecked_t urbnum;
72683
72684 unsigned long active_duration;
72685
72686@@ -1607,7 +1607,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
72687
72688 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
72689 __u8 request, __u8 requesttype, __u16 value, __u16 index,
72690- void *data, __u16 size, int timeout);
72691+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
72692 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
72693 void *data, int len, int *actual_length, int timeout);
72694 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
72695diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
72696index e452ba6..78f8e80 100644
72697--- a/include/linux/usb/renesas_usbhs.h
72698+++ b/include/linux/usb/renesas_usbhs.h
72699@@ -39,7 +39,7 @@ enum {
72700 */
72701 struct renesas_usbhs_driver_callback {
72702 int (*notify_hotplug)(struct platform_device *pdev);
72703-};
72704+} __no_const;
72705
72706 /*
72707 * callback functions for platform
72708diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
72709index 6f8fbcf..8259001 100644
72710--- a/include/linux/vermagic.h
72711+++ b/include/linux/vermagic.h
72712@@ -25,9 +25,35 @@
72713 #define MODULE_ARCH_VERMAGIC ""
72714 #endif
72715
72716+#ifdef CONFIG_PAX_REFCOUNT
72717+#define MODULE_PAX_REFCOUNT "REFCOUNT "
72718+#else
72719+#define MODULE_PAX_REFCOUNT ""
72720+#endif
72721+
72722+#ifdef CONSTIFY_PLUGIN
72723+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
72724+#else
72725+#define MODULE_CONSTIFY_PLUGIN ""
72726+#endif
72727+
72728+#ifdef STACKLEAK_PLUGIN
72729+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
72730+#else
72731+#define MODULE_STACKLEAK_PLUGIN ""
72732+#endif
72733+
72734+#ifdef CONFIG_GRKERNSEC
72735+#define MODULE_GRSEC "GRSEC "
72736+#else
72737+#define MODULE_GRSEC ""
72738+#endif
72739+
72740 #define VERMAGIC_STRING \
72741 UTS_RELEASE " " \
72742 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
72743 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
72744- MODULE_ARCH_VERMAGIC
72745+ MODULE_ARCH_VERMAGIC \
72746+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
72747+ MODULE_GRSEC
72748
72749diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
72750index 7d5773a..541c01c 100644
72751--- a/include/linux/vmalloc.h
72752+++ b/include/linux/vmalloc.h
72753@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
72754 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
72755 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
72756 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
72757+
72758+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72759+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
72760+#endif
72761+
72762 /* bits [20..32] reserved for arch specific ioremap internals */
72763
72764 /*
72765@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
72766 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
72767 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
72768 unsigned long start, unsigned long end, gfp_t gfp_mask,
72769- pgprot_t prot, int node, const void *caller);
72770+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
72771 extern void vfree(const void *addr);
72772
72773 extern void *vmap(struct page **pages, unsigned int count,
72774@@ -137,8 +142,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
72775 extern void free_vm_area(struct vm_struct *area);
72776
72777 /* for /dev/kmem */
72778-extern long vread(char *buf, char *addr, unsigned long count);
72779-extern long vwrite(char *buf, char *addr, unsigned long count);
72780+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
72781+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
72782
72783 /*
72784 * Internals. Dont't use..
72785diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
72786index c586679..f06b389 100644
72787--- a/include/linux/vmstat.h
72788+++ b/include/linux/vmstat.h
72789@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
72790 /*
72791 * Zone based page accounting with per cpu differentials.
72792 */
72793-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72794+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72795
72796 static inline void zone_page_state_add(long x, struct zone *zone,
72797 enum zone_stat_item item)
72798 {
72799- atomic_long_add(x, &zone->vm_stat[item]);
72800- atomic_long_add(x, &vm_stat[item]);
72801+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
72802+ atomic_long_add_unchecked(x, &vm_stat[item]);
72803 }
72804
72805 static inline unsigned long global_page_state(enum zone_stat_item item)
72806 {
72807- long x = atomic_long_read(&vm_stat[item]);
72808+ long x = atomic_long_read_unchecked(&vm_stat[item]);
72809 #ifdef CONFIG_SMP
72810 if (x < 0)
72811 x = 0;
72812@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
72813 static inline unsigned long zone_page_state(struct zone *zone,
72814 enum zone_stat_item item)
72815 {
72816- long x = atomic_long_read(&zone->vm_stat[item]);
72817+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72818 #ifdef CONFIG_SMP
72819 if (x < 0)
72820 x = 0;
72821@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
72822 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
72823 enum zone_stat_item item)
72824 {
72825- long x = atomic_long_read(&zone->vm_stat[item]);
72826+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72827
72828 #ifdef CONFIG_SMP
72829 int cpu;
72830@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
72831
72832 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
72833 {
72834- atomic_long_inc(&zone->vm_stat[item]);
72835- atomic_long_inc(&vm_stat[item]);
72836+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
72837+ atomic_long_inc_unchecked(&vm_stat[item]);
72838 }
72839
72840 static inline void __inc_zone_page_state(struct page *page,
72841@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
72842
72843 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
72844 {
72845- atomic_long_dec(&zone->vm_stat[item]);
72846- atomic_long_dec(&vm_stat[item]);
72847+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
72848+ atomic_long_dec_unchecked(&vm_stat[item]);
72849 }
72850
72851 static inline void __dec_zone_page_state(struct page *page,
72852diff --git a/include/linux/xattr.h b/include/linux/xattr.h
72853index fdbafc6..49dfe4f 100644
72854--- a/include/linux/xattr.h
72855+++ b/include/linux/xattr.h
72856@@ -28,7 +28,7 @@ struct xattr_handler {
72857 size_t size, int handler_flags);
72858 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
72859 size_t size, int flags, int handler_flags);
72860-};
72861+} __do_const;
72862
72863 struct xattr {
72864 char *name;
72865@@ -37,6 +37,9 @@ struct xattr {
72866 };
72867
72868 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
72869+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
72870+ssize_t pax_getxattr(struct dentry *, void *, size_t);
72871+#endif
72872 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
72873 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
72874 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
72875diff --git a/include/linux/zlib.h b/include/linux/zlib.h
72876index 9c5a6b4..09c9438 100644
72877--- a/include/linux/zlib.h
72878+++ b/include/linux/zlib.h
72879@@ -31,6 +31,7 @@
72880 #define _ZLIB_H
72881
72882 #include <linux/zconf.h>
72883+#include <linux/compiler.h>
72884
72885 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
72886 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
72887@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
72888
72889 /* basic functions */
72890
72891-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
72892+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
72893 /*
72894 Returns the number of bytes that needs to be allocated for a per-
72895 stream workspace with the specified parameters. A pointer to this
72896diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
72897index 95d1c91..6798cca 100644
72898--- a/include/media/v4l2-dev.h
72899+++ b/include/media/v4l2-dev.h
72900@@ -76,7 +76,7 @@ struct v4l2_file_operations {
72901 int (*mmap) (struct file *, struct vm_area_struct *);
72902 int (*open) (struct file *);
72903 int (*release) (struct file *);
72904-};
72905+} __do_const;
72906
72907 /*
72908 * Newer version of video_device, handled by videodev2.c
72909diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
72910index adcbb20..62c2559 100644
72911--- a/include/net/9p/transport.h
72912+++ b/include/net/9p/transport.h
72913@@ -57,7 +57,7 @@ struct p9_trans_module {
72914 int (*cancel) (struct p9_client *, struct p9_req_t *req);
72915 int (*zc_request)(struct p9_client *, struct p9_req_t *,
72916 char *, char *, int , int, int, int);
72917-};
72918+} __do_const;
72919
72920 void v9fs_register_trans(struct p9_trans_module *m);
72921 void v9fs_unregister_trans(struct p9_trans_module *m);
72922diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
72923index fb94cf1..7c0c987 100644
72924--- a/include/net/bluetooth/l2cap.h
72925+++ b/include/net/bluetooth/l2cap.h
72926@@ -551,7 +551,7 @@ struct l2cap_ops {
72927 void (*defer) (struct l2cap_chan *chan);
72928 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
72929 unsigned long len, int nb);
72930-};
72931+} __do_const;
72932
72933 struct l2cap_conn {
72934 struct hci_conn *hcon;
72935diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
72936index f2ae33d..c457cf0 100644
72937--- a/include/net/caif/cfctrl.h
72938+++ b/include/net/caif/cfctrl.h
72939@@ -52,7 +52,7 @@ struct cfctrl_rsp {
72940 void (*radioset_rsp)(void);
72941 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
72942 struct cflayer *client_layer);
72943-};
72944+} __no_const;
72945
72946 /* Link Setup Parameters for CAIF-Links. */
72947 struct cfctrl_link_param {
72948@@ -101,8 +101,8 @@ struct cfctrl_request_info {
72949 struct cfctrl {
72950 struct cfsrvl serv;
72951 struct cfctrl_rsp res;
72952- atomic_t req_seq_no;
72953- atomic_t rsp_seq_no;
72954+ atomic_unchecked_t req_seq_no;
72955+ atomic_unchecked_t rsp_seq_no;
72956 struct list_head list;
72957 /* Protects from simultaneous access to first_req list */
72958 spinlock_t info_list_lock;
72959diff --git a/include/net/flow.h b/include/net/flow.h
72960index 628e11b..4c475df 100644
72961--- a/include/net/flow.h
72962+++ b/include/net/flow.h
72963@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
72964
72965 extern void flow_cache_flush(void);
72966 extern void flow_cache_flush_deferred(void);
72967-extern atomic_t flow_cache_genid;
72968+extern atomic_unchecked_t flow_cache_genid;
72969
72970 #endif
72971diff --git a/include/net/genetlink.h b/include/net/genetlink.h
72972index 93024a4..eeb6b6e 100644
72973--- a/include/net/genetlink.h
72974+++ b/include/net/genetlink.h
72975@@ -119,7 +119,7 @@ struct genl_ops {
72976 struct netlink_callback *cb);
72977 int (*done)(struct netlink_callback *cb);
72978 struct list_head ops_list;
72979-};
72980+} __do_const;
72981
72982 extern int genl_register_family(struct genl_family *family);
72983 extern int genl_register_family_with_ops(struct genl_family *family,
72984diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
72985index 734d9b5..48a9a4b 100644
72986--- a/include/net/gro_cells.h
72987+++ b/include/net/gro_cells.h
72988@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
72989 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
72990
72991 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
72992- atomic_long_inc(&dev->rx_dropped);
72993+ atomic_long_inc_unchecked(&dev->rx_dropped);
72994 kfree_skb(skb);
72995 return;
72996 }
72997diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
72998index de2c785..0588a6b 100644
72999--- a/include/net/inet_connection_sock.h
73000+++ b/include/net/inet_connection_sock.h
73001@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
73002 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
73003 int (*bind_conflict)(const struct sock *sk,
73004 const struct inet_bind_bucket *tb, bool relax);
73005-};
73006+} __do_const;
73007
73008 /** inet_connection_sock - INET connection oriented sock
73009 *
73010diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
73011index 53f464d..ba76aaa 100644
73012--- a/include/net/inetpeer.h
73013+++ b/include/net/inetpeer.h
73014@@ -47,8 +47,8 @@ struct inet_peer {
73015 */
73016 union {
73017 struct {
73018- atomic_t rid; /* Frag reception counter */
73019- atomic_t ip_id_count; /* IP ID for the next packet */
73020+ atomic_unchecked_t rid; /* Frag reception counter */
73021+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
73022 };
73023 struct rcu_head rcu;
73024 struct inet_peer *gc_next;
73025@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
73026 more++;
73027 inet_peer_refcheck(p);
73028 do {
73029- old = atomic_read(&p->ip_id_count);
73030+ old = atomic_read_unchecked(&p->ip_id_count);
73031 new = old + more;
73032 if (!new)
73033 new = 1;
73034- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
73035+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
73036 return new;
73037 }
73038
73039diff --git a/include/net/ip.h b/include/net/ip.h
73040index a68f838..74518ab 100644
73041--- a/include/net/ip.h
73042+++ b/include/net/ip.h
73043@@ -202,7 +202,7 @@ extern struct local_ports {
73044 } sysctl_local_ports;
73045 extern void inet_get_local_port_range(int *low, int *high);
73046
73047-extern unsigned long *sysctl_local_reserved_ports;
73048+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
73049 static inline int inet_is_reserved_local_port(int port)
73050 {
73051 return test_bit(port, sysctl_local_reserved_ports);
73052diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
73053index e49db91..76a81de 100644
73054--- a/include/net/ip_fib.h
73055+++ b/include/net/ip_fib.h
73056@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
73057
73058 #define FIB_RES_SADDR(net, res) \
73059 ((FIB_RES_NH(res).nh_saddr_genid == \
73060- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
73061+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
73062 FIB_RES_NH(res).nh_saddr : \
73063 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
73064 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
73065diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
73066index 4c062cc..3562c31 100644
73067--- a/include/net/ip_vs.h
73068+++ b/include/net/ip_vs.h
73069@@ -612,7 +612,7 @@ struct ip_vs_conn {
73070 struct ip_vs_conn *control; /* Master control connection */
73071 atomic_t n_control; /* Number of controlled ones */
73072 struct ip_vs_dest *dest; /* real server */
73073- atomic_t in_pkts; /* incoming packet counter */
73074+ atomic_unchecked_t in_pkts; /* incoming packet counter */
73075
73076 /* packet transmitter for different forwarding methods. If it
73077 mangles the packet, it must return NF_DROP or better NF_STOLEN,
73078@@ -761,7 +761,7 @@ struct ip_vs_dest {
73079 __be16 port; /* port number of the server */
73080 union nf_inet_addr addr; /* IP address of the server */
73081 volatile unsigned int flags; /* dest status flags */
73082- atomic_t conn_flags; /* flags to copy to conn */
73083+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
73084 atomic_t weight; /* server weight */
73085
73086 atomic_t refcnt; /* reference counter */
73087@@ -1013,11 +1013,11 @@ struct netns_ipvs {
73088 /* ip_vs_lblc */
73089 int sysctl_lblc_expiration;
73090 struct ctl_table_header *lblc_ctl_header;
73091- struct ctl_table *lblc_ctl_table;
73092+ ctl_table_no_const *lblc_ctl_table;
73093 /* ip_vs_lblcr */
73094 int sysctl_lblcr_expiration;
73095 struct ctl_table_header *lblcr_ctl_header;
73096- struct ctl_table *lblcr_ctl_table;
73097+ ctl_table_no_const *lblcr_ctl_table;
73098 /* ip_vs_est */
73099 struct list_head est_list; /* estimator list */
73100 spinlock_t est_lock;
73101diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
73102index 80ffde3..968b0f4 100644
73103--- a/include/net/irda/ircomm_tty.h
73104+++ b/include/net/irda/ircomm_tty.h
73105@@ -35,6 +35,7 @@
73106 #include <linux/termios.h>
73107 #include <linux/timer.h>
73108 #include <linux/tty.h> /* struct tty_struct */
73109+#include <asm/local.h>
73110
73111 #include <net/irda/irias_object.h>
73112 #include <net/irda/ircomm_core.h>
73113diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
73114index 714cc9a..ea05f3e 100644
73115--- a/include/net/iucv/af_iucv.h
73116+++ b/include/net/iucv/af_iucv.h
73117@@ -149,7 +149,7 @@ struct iucv_skb_cb {
73118 struct iucv_sock_list {
73119 struct hlist_head head;
73120 rwlock_t lock;
73121- atomic_t autobind_name;
73122+ atomic_unchecked_t autobind_name;
73123 };
73124
73125 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
73126diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
73127index df83f69..9b640b8 100644
73128--- a/include/net/llc_c_ac.h
73129+++ b/include/net/llc_c_ac.h
73130@@ -87,7 +87,7 @@
73131 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
73132 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
73133
73134-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73135+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73136
73137 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
73138 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
73139diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
73140index 6ca3113..f8026dd 100644
73141--- a/include/net/llc_c_ev.h
73142+++ b/include/net/llc_c_ev.h
73143@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
73144 return (struct llc_conn_state_ev *)skb->cb;
73145 }
73146
73147-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73148-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73149+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73150+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73151
73152 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
73153 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
73154diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
73155index 0e79cfb..f46db31 100644
73156--- a/include/net/llc_c_st.h
73157+++ b/include/net/llc_c_st.h
73158@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
73159 u8 next_state;
73160 llc_conn_ev_qfyr_t *ev_qualifiers;
73161 llc_conn_action_t *ev_actions;
73162-};
73163+} __do_const;
73164
73165 struct llc_conn_state {
73166 u8 current_state;
73167diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
73168index 37a3bbd..55a4241 100644
73169--- a/include/net/llc_s_ac.h
73170+++ b/include/net/llc_s_ac.h
73171@@ -23,7 +23,7 @@
73172 #define SAP_ACT_TEST_IND 9
73173
73174 /* All action functions must look like this */
73175-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73176+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73177
73178 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
73179 struct sk_buff *skb);
73180diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
73181index 567c681..cd73ac0 100644
73182--- a/include/net/llc_s_st.h
73183+++ b/include/net/llc_s_st.h
73184@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
73185 llc_sap_ev_t ev;
73186 u8 next_state;
73187 llc_sap_action_t *ev_actions;
73188-};
73189+} __do_const;
73190
73191 struct llc_sap_state {
73192 u8 curr_state;
73193diff --git a/include/net/mac80211.h b/include/net/mac80211.h
73194index 885898a..cdace34 100644
73195--- a/include/net/mac80211.h
73196+++ b/include/net/mac80211.h
73197@@ -4205,7 +4205,7 @@ struct rate_control_ops {
73198 void (*add_sta_debugfs)(void *priv, void *priv_sta,
73199 struct dentry *dir);
73200 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
73201-};
73202+} __do_const;
73203
73204 static inline int rate_supported(struct ieee80211_sta *sta,
73205 enum ieee80211_band band,
73206diff --git a/include/net/neighbour.h b/include/net/neighbour.h
73207index 7e748ad..5c6229b 100644
73208--- a/include/net/neighbour.h
73209+++ b/include/net/neighbour.h
73210@@ -123,7 +123,7 @@ struct neigh_ops {
73211 void (*error_report)(struct neighbour *, struct sk_buff *);
73212 int (*output)(struct neighbour *, struct sk_buff *);
73213 int (*connected_output)(struct neighbour *, struct sk_buff *);
73214-};
73215+} __do_const;
73216
73217 struct pneigh_entry {
73218 struct pneigh_entry *next;
73219diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
73220index b176978..ea169f4 100644
73221--- a/include/net/net_namespace.h
73222+++ b/include/net/net_namespace.h
73223@@ -117,7 +117,7 @@ struct net {
73224 #endif
73225 struct netns_ipvs *ipvs;
73226 struct sock *diag_nlsk;
73227- atomic_t rt_genid;
73228+ atomic_unchecked_t rt_genid;
73229 };
73230
73231 /*
73232@@ -274,7 +274,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
73233 #define __net_init __init
73234 #define __net_exit __exit_refok
73235 #define __net_initdata __initdata
73236+#ifdef CONSTIFY_PLUGIN
73237 #define __net_initconst __initconst
73238+#else
73239+#define __net_initconst __initdata
73240+#endif
73241 #endif
73242
73243 struct pernet_operations {
73244@@ -284,7 +288,7 @@ struct pernet_operations {
73245 void (*exit_batch)(struct list_head *net_exit_list);
73246 int *id;
73247 size_t size;
73248-};
73249+} __do_const;
73250
73251 /*
73252 * Use these carefully. If you implement a network device and it
73253@@ -332,12 +336,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
73254
73255 static inline int rt_genid(struct net *net)
73256 {
73257- return atomic_read(&net->rt_genid);
73258+ return atomic_read_unchecked(&net->rt_genid);
73259 }
73260
73261 static inline void rt_genid_bump(struct net *net)
73262 {
73263- atomic_inc(&net->rt_genid);
73264+ atomic_inc_unchecked(&net->rt_genid);
73265 }
73266
73267 #endif /* __NET_NET_NAMESPACE_H */
73268diff --git a/include/net/netdma.h b/include/net/netdma.h
73269index 8ba8ce2..99b7fff 100644
73270--- a/include/net/netdma.h
73271+++ b/include/net/netdma.h
73272@@ -24,7 +24,7 @@
73273 #include <linux/dmaengine.h>
73274 #include <linux/skbuff.h>
73275
73276-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73277+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73278 struct sk_buff *skb, int offset, struct iovec *to,
73279 size_t len, struct dma_pinned_list *pinned_list);
73280
73281diff --git a/include/net/netlink.h b/include/net/netlink.h
73282index 9690b0f..87aded7 100644
73283--- a/include/net/netlink.h
73284+++ b/include/net/netlink.h
73285@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
73286 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
73287 {
73288 if (mark)
73289- skb_trim(skb, (unsigned char *) mark - skb->data);
73290+ skb_trim(skb, (const unsigned char *) mark - skb->data);
73291 }
73292
73293 /**
73294diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
73295index c9c0c53..53f24c3 100644
73296--- a/include/net/netns/conntrack.h
73297+++ b/include/net/netns/conntrack.h
73298@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
73299 struct nf_proto_net {
73300 #ifdef CONFIG_SYSCTL
73301 struct ctl_table_header *ctl_table_header;
73302- struct ctl_table *ctl_table;
73303+ ctl_table_no_const *ctl_table;
73304 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
73305 struct ctl_table_header *ctl_compat_header;
73306- struct ctl_table *ctl_compat_table;
73307+ ctl_table_no_const *ctl_compat_table;
73308 #endif
73309 #endif
73310 unsigned int users;
73311@@ -58,7 +58,7 @@ struct nf_ip_net {
73312 struct nf_icmp_net icmpv6;
73313 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
73314 struct ctl_table_header *ctl_table_header;
73315- struct ctl_table *ctl_table;
73316+ ctl_table_no_const *ctl_table;
73317 #endif
73318 };
73319
73320diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
73321index 2ba9de8..47bd6c7 100644
73322--- a/include/net/netns/ipv4.h
73323+++ b/include/net/netns/ipv4.h
73324@@ -67,7 +67,7 @@ struct netns_ipv4 {
73325 kgid_t sysctl_ping_group_range[2];
73326 long sysctl_tcp_mem[3];
73327
73328- atomic_t dev_addr_genid;
73329+ atomic_unchecked_t dev_addr_genid;
73330
73331 #ifdef CONFIG_IP_MROUTE
73332 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
73333diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
73334index 005e2c2..023d340 100644
73335--- a/include/net/netns/ipv6.h
73336+++ b/include/net/netns/ipv6.h
73337@@ -71,7 +71,7 @@ struct netns_ipv6 {
73338 struct fib_rules_ops *mr6_rules_ops;
73339 #endif
73340 #endif
73341- atomic_t dev_addr_genid;
73342+ atomic_unchecked_t dev_addr_genid;
73343 };
73344
73345 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
73346diff --git a/include/net/protocol.h b/include/net/protocol.h
73347index 047c047..b9dad15 100644
73348--- a/include/net/protocol.h
73349+++ b/include/net/protocol.h
73350@@ -44,7 +44,7 @@ struct net_protocol {
73351 void (*err_handler)(struct sk_buff *skb, u32 info);
73352 unsigned int no_policy:1,
73353 netns_ok:1;
73354-};
73355+} __do_const;
73356
73357 #if IS_ENABLED(CONFIG_IPV6)
73358 struct inet6_protocol {
73359@@ -57,7 +57,7 @@ struct inet6_protocol {
73360 u8 type, u8 code, int offset,
73361 __be32 info);
73362 unsigned int flags; /* INET6_PROTO_xxx */
73363-};
73364+} __do_const;
73365
73366 #define INET6_PROTO_NOPOLICY 0x1
73367 #define INET6_PROTO_FINAL 0x2
73368diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
73369index 7026648..584cc8c 100644
73370--- a/include/net/rtnetlink.h
73371+++ b/include/net/rtnetlink.h
73372@@ -81,7 +81,7 @@ struct rtnl_link_ops {
73373 const struct net_device *dev);
73374 unsigned int (*get_num_tx_queues)(void);
73375 unsigned int (*get_num_rx_queues)(void);
73376-};
73377+} __do_const;
73378
73379 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
73380 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
73381diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
73382index cd89510..d67810f 100644
73383--- a/include/net/sctp/sctp.h
73384+++ b/include/net/sctp/sctp.h
73385@@ -330,9 +330,9 @@ do { \
73386
73387 #else /* SCTP_DEBUG */
73388
73389-#define SCTP_DEBUG_PRINTK(whatever...)
73390-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
73391-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
73392+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
73393+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
73394+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
73395 #define SCTP_ENABLE_DEBUG
73396 #define SCTP_DISABLE_DEBUG
73397 #define SCTP_ASSERT(expr, str, func)
73398diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
73399index 2a82d13..62a31c2 100644
73400--- a/include/net/sctp/sm.h
73401+++ b/include/net/sctp/sm.h
73402@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
73403 typedef struct {
73404 sctp_state_fn_t *fn;
73405 const char *name;
73406-} sctp_sm_table_entry_t;
73407+} __do_const sctp_sm_table_entry_t;
73408
73409 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
73410 * currently in use.
73411@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
73412 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
73413
73414 /* Extern declarations for major data structures. */
73415-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73416+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73417
73418
73419 /* Get the size of a DATA chunk payload. */
73420diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
73421index 1bd4c41..9250b5b 100644
73422--- a/include/net/sctp/structs.h
73423+++ b/include/net/sctp/structs.h
73424@@ -516,7 +516,7 @@ struct sctp_pf {
73425 struct sctp_association *asoc);
73426 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
73427 struct sctp_af *af;
73428-};
73429+} __do_const;
73430
73431
73432 /* Structure to track chunk fragments that have been acked, but peer
73433diff --git a/include/net/sock.h b/include/net/sock.h
73434index 66772cf..25bc45b 100644
73435--- a/include/net/sock.h
73436+++ b/include/net/sock.h
73437@@ -325,7 +325,7 @@ struct sock {
73438 #ifdef CONFIG_RPS
73439 __u32 sk_rxhash;
73440 #endif
73441- atomic_t sk_drops;
73442+ atomic_unchecked_t sk_drops;
73443 int sk_rcvbuf;
73444
73445 struct sk_filter __rcu *sk_filter;
73446@@ -1797,7 +1797,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
73447 }
73448
73449 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
73450- char __user *from, char *to,
73451+ char __user *from, unsigned char *to,
73452 int copy, int offset)
73453 {
73454 if (skb->ip_summed == CHECKSUM_NONE) {
73455@@ -2056,7 +2056,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
73456 }
73457 }
73458
73459-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73460+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73461
73462 /**
73463 * sk_page_frag - return an appropriate page_frag
73464diff --git a/include/net/tcp.h b/include/net/tcp.h
73465index 5bba80f..8520a82 100644
73466--- a/include/net/tcp.h
73467+++ b/include/net/tcp.h
73468@@ -524,7 +524,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
73469 extern void tcp_xmit_retransmit_queue(struct sock *);
73470 extern void tcp_simple_retransmit(struct sock *);
73471 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
73472-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73473+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73474
73475 extern void tcp_send_probe0(struct sock *);
73476 extern void tcp_send_partial(struct sock *);
73477@@ -697,8 +697,8 @@ struct tcp_skb_cb {
73478 struct inet6_skb_parm h6;
73479 #endif
73480 } header; /* For incoming frames */
73481- __u32 seq; /* Starting sequence number */
73482- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
73483+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
73484+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
73485 __u32 when; /* used to compute rtt's */
73486 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
73487
73488@@ -712,7 +712,7 @@ struct tcp_skb_cb {
73489
73490 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
73491 /* 1 byte hole */
73492- __u32 ack_seq; /* Sequence number ACK'd */
73493+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
73494 };
73495
73496 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
73497diff --git a/include/net/udp.h b/include/net/udp.h
73498index 065f379..ad99eed 100644
73499--- a/include/net/udp.h
73500+++ b/include/net/udp.h
73501@@ -181,6 +181,7 @@ extern int udp_get_port(struct sock *sk, unsigned short snum,
73502 extern void udp_err(struct sk_buff *, u32);
73503 extern int udp_sendmsg(struct kiocb *iocb, struct sock *sk,
73504 struct msghdr *msg, size_t len);
73505+extern int udp_push_pending_frames(struct sock *sk);
73506 extern void udp_flush_pending_frames(struct sock *sk);
73507 extern int udp_rcv(struct sk_buff *skb);
73508 extern int udp_ioctl(struct sock *sk, int cmd, unsigned long arg);
73509diff --git a/include/net/xfrm.h b/include/net/xfrm.h
73510index 94ce082..62b278d 100644
73511--- a/include/net/xfrm.h
73512+++ b/include/net/xfrm.h
73513@@ -305,7 +305,7 @@ struct xfrm_policy_afinfo {
73514 struct net_device *dev,
73515 const struct flowi *fl);
73516 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
73517-};
73518+} __do_const;
73519
73520 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
73521 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
73522@@ -341,7 +341,7 @@ struct xfrm_state_afinfo {
73523 struct sk_buff *skb);
73524 int (*transport_finish)(struct sk_buff *skb,
73525 int async);
73526-};
73527+} __do_const;
73528
73529 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
73530 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
73531@@ -424,7 +424,7 @@ struct xfrm_mode {
73532 struct module *owner;
73533 unsigned int encap;
73534 int flags;
73535-};
73536+} __do_const;
73537
73538 /* Flags for xfrm_mode. */
73539 enum {
73540@@ -521,7 +521,7 @@ struct xfrm_policy {
73541 struct timer_list timer;
73542
73543 struct flow_cache_object flo;
73544- atomic_t genid;
73545+ atomic_unchecked_t genid;
73546 u32 priority;
73547 u32 index;
73548 struct xfrm_mark mark;
73549diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
73550index 1a046b1..ee0bef0 100644
73551--- a/include/rdma/iw_cm.h
73552+++ b/include/rdma/iw_cm.h
73553@@ -122,7 +122,7 @@ struct iw_cm_verbs {
73554 int backlog);
73555
73556 int (*destroy_listen)(struct iw_cm_id *cm_id);
73557-};
73558+} __no_const;
73559
73560 /**
73561 * iw_create_cm_id - Create an IW CM identifier.
73562diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
73563index e1379b4..67eafbe 100644
73564--- a/include/scsi/libfc.h
73565+++ b/include/scsi/libfc.h
73566@@ -762,6 +762,7 @@ struct libfc_function_template {
73567 */
73568 void (*disc_stop_final) (struct fc_lport *);
73569 };
73570+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
73571
73572 /**
73573 * struct fc_disc - Discovery context
73574@@ -866,7 +867,7 @@ struct fc_lport {
73575 struct fc_vport *vport;
73576
73577 /* Operational Information */
73578- struct libfc_function_template tt;
73579+ libfc_function_template_no_const tt;
73580 u8 link_up;
73581 u8 qfull;
73582 enum fc_lport_state state;
73583diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
73584index cc64587..608f523 100644
73585--- a/include/scsi/scsi_device.h
73586+++ b/include/scsi/scsi_device.h
73587@@ -171,9 +171,9 @@ struct scsi_device {
73588 unsigned int max_device_blocked; /* what device_blocked counts down from */
73589 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
73590
73591- atomic_t iorequest_cnt;
73592- atomic_t iodone_cnt;
73593- atomic_t ioerr_cnt;
73594+ atomic_unchecked_t iorequest_cnt;
73595+ atomic_unchecked_t iodone_cnt;
73596+ atomic_unchecked_t ioerr_cnt;
73597
73598 struct device sdev_gendev,
73599 sdev_dev;
73600diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
73601index b797e8f..8e2c3aa 100644
73602--- a/include/scsi/scsi_transport_fc.h
73603+++ b/include/scsi/scsi_transport_fc.h
73604@@ -751,7 +751,8 @@ struct fc_function_template {
73605 unsigned long show_host_system_hostname:1;
73606
73607 unsigned long disable_target_scan:1;
73608-};
73609+} __do_const;
73610+typedef struct fc_function_template __no_const fc_function_template_no_const;
73611
73612
73613 /**
73614diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
73615index 9031a26..750d592 100644
73616--- a/include/sound/compress_driver.h
73617+++ b/include/sound/compress_driver.h
73618@@ -128,7 +128,7 @@ struct snd_compr_ops {
73619 struct snd_compr_caps *caps);
73620 int (*get_codec_caps) (struct snd_compr_stream *stream,
73621 struct snd_compr_codec_caps *codec);
73622-};
73623+} __no_const;
73624
73625 /**
73626 * struct snd_compr: Compressed device
73627diff --git a/include/sound/soc.h b/include/sound/soc.h
73628index 85c1522..f44bad1 100644
73629--- a/include/sound/soc.h
73630+++ b/include/sound/soc.h
73631@@ -781,7 +781,7 @@ struct snd_soc_codec_driver {
73632 /* probe ordering - for components with runtime dependencies */
73633 int probe_order;
73634 int remove_order;
73635-};
73636+} __do_const;
73637
73638 /* SoC platform interface */
73639 struct snd_soc_platform_driver {
73640@@ -827,7 +827,7 @@ struct snd_soc_platform_driver {
73641 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
73642 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
73643 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
73644-};
73645+} __do_const;
73646
73647 struct snd_soc_platform {
73648 const char *name;
73649diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
73650index 4ea4f98..a63629b 100644
73651--- a/include/target/target_core_base.h
73652+++ b/include/target/target_core_base.h
73653@@ -653,7 +653,7 @@ struct se_device {
73654 spinlock_t stats_lock;
73655 /* Active commands on this virtual SE device */
73656 atomic_t simple_cmds;
73657- atomic_t dev_ordered_id;
73658+ atomic_unchecked_t dev_ordered_id;
73659 atomic_t dev_ordered_sync;
73660 atomic_t dev_qf_count;
73661 int export_count;
73662diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
73663new file mode 100644
73664index 0000000..fb634b7
73665--- /dev/null
73666+++ b/include/trace/events/fs.h
73667@@ -0,0 +1,53 @@
73668+#undef TRACE_SYSTEM
73669+#define TRACE_SYSTEM fs
73670+
73671+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
73672+#define _TRACE_FS_H
73673+
73674+#include <linux/fs.h>
73675+#include <linux/tracepoint.h>
73676+
73677+TRACE_EVENT(do_sys_open,
73678+
73679+ TP_PROTO(const char *filename, int flags, int mode),
73680+
73681+ TP_ARGS(filename, flags, mode),
73682+
73683+ TP_STRUCT__entry(
73684+ __string( filename, filename )
73685+ __field( int, flags )
73686+ __field( int, mode )
73687+ ),
73688+
73689+ TP_fast_assign(
73690+ __assign_str(filename, filename);
73691+ __entry->flags = flags;
73692+ __entry->mode = mode;
73693+ ),
73694+
73695+ TP_printk("\"%s\" %x %o",
73696+ __get_str(filename), __entry->flags, __entry->mode)
73697+);
73698+
73699+TRACE_EVENT(open_exec,
73700+
73701+ TP_PROTO(const char *filename),
73702+
73703+ TP_ARGS(filename),
73704+
73705+ TP_STRUCT__entry(
73706+ __string( filename, filename )
73707+ ),
73708+
73709+ TP_fast_assign(
73710+ __assign_str(filename, filename);
73711+ ),
73712+
73713+ TP_printk("\"%s\"",
73714+ __get_str(filename))
73715+);
73716+
73717+#endif /* _TRACE_FS_H */
73718+
73719+/* This part must be outside protection */
73720+#include <trace/define_trace.h>
73721diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
73722index 1c09820..7f5ec79 100644
73723--- a/include/trace/events/irq.h
73724+++ b/include/trace/events/irq.h
73725@@ -36,7 +36,7 @@ struct softirq_action;
73726 */
73727 TRACE_EVENT(irq_handler_entry,
73728
73729- TP_PROTO(int irq, struct irqaction *action),
73730+ TP_PROTO(int irq, const struct irqaction *action),
73731
73732 TP_ARGS(irq, action),
73733
73734@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
73735 */
73736 TRACE_EVENT(irq_handler_exit,
73737
73738- TP_PROTO(int irq, struct irqaction *action, int ret),
73739+ TP_PROTO(int irq, const struct irqaction *action, int ret),
73740
73741 TP_ARGS(irq, action, ret),
73742
73743diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
73744index 7caf44c..23c6f27 100644
73745--- a/include/uapi/linux/a.out.h
73746+++ b/include/uapi/linux/a.out.h
73747@@ -39,6 +39,14 @@ enum machine_type {
73748 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
73749 };
73750
73751+/* Constants for the N_FLAGS field */
73752+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73753+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
73754+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
73755+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
73756+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73757+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73758+
73759 #if !defined (N_MAGIC)
73760 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
73761 #endif
73762diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
73763index d876736..ccce5c0 100644
73764--- a/include/uapi/linux/byteorder/little_endian.h
73765+++ b/include/uapi/linux/byteorder/little_endian.h
73766@@ -42,51 +42,51 @@
73767
73768 static inline __le64 __cpu_to_le64p(const __u64 *p)
73769 {
73770- return (__force __le64)*p;
73771+ return (__force const __le64)*p;
73772 }
73773-static inline __u64 __le64_to_cpup(const __le64 *p)
73774+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
73775 {
73776- return (__force __u64)*p;
73777+ return (__force const __u64)*p;
73778 }
73779 static inline __le32 __cpu_to_le32p(const __u32 *p)
73780 {
73781- return (__force __le32)*p;
73782+ return (__force const __le32)*p;
73783 }
73784 static inline __u32 __le32_to_cpup(const __le32 *p)
73785 {
73786- return (__force __u32)*p;
73787+ return (__force const __u32)*p;
73788 }
73789 static inline __le16 __cpu_to_le16p(const __u16 *p)
73790 {
73791- return (__force __le16)*p;
73792+ return (__force const __le16)*p;
73793 }
73794 static inline __u16 __le16_to_cpup(const __le16 *p)
73795 {
73796- return (__force __u16)*p;
73797+ return (__force const __u16)*p;
73798 }
73799 static inline __be64 __cpu_to_be64p(const __u64 *p)
73800 {
73801- return (__force __be64)__swab64p(p);
73802+ return (__force const __be64)__swab64p(p);
73803 }
73804 static inline __u64 __be64_to_cpup(const __be64 *p)
73805 {
73806- return __swab64p((__u64 *)p);
73807+ return __swab64p((const __u64 *)p);
73808 }
73809 static inline __be32 __cpu_to_be32p(const __u32 *p)
73810 {
73811- return (__force __be32)__swab32p(p);
73812+ return (__force const __be32)__swab32p(p);
73813 }
73814-static inline __u32 __be32_to_cpup(const __be32 *p)
73815+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
73816 {
73817- return __swab32p((__u32 *)p);
73818+ return __swab32p((const __u32 *)p);
73819 }
73820 static inline __be16 __cpu_to_be16p(const __u16 *p)
73821 {
73822- return (__force __be16)__swab16p(p);
73823+ return (__force const __be16)__swab16p(p);
73824 }
73825 static inline __u16 __be16_to_cpup(const __be16 *p)
73826 {
73827- return __swab16p((__u16 *)p);
73828+ return __swab16p((const __u16 *)p);
73829 }
73830 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
73831 #define __le64_to_cpus(x) do { (void)(x); } while (0)
73832diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
73833index ef6103b..d4e65dd 100644
73834--- a/include/uapi/linux/elf.h
73835+++ b/include/uapi/linux/elf.h
73836@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
73837 #define PT_GNU_EH_FRAME 0x6474e550
73838
73839 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
73840+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
73841+
73842+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
73843+
73844+/* Constants for the e_flags field */
73845+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73846+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
73847+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
73848+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
73849+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73850+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73851
73852 /*
73853 * Extended Numbering
73854@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
73855 #define DT_DEBUG 21
73856 #define DT_TEXTREL 22
73857 #define DT_JMPREL 23
73858+#define DT_FLAGS 30
73859+ #define DF_TEXTREL 0x00000004
73860 #define DT_ENCODING 32
73861 #define OLD_DT_LOOS 0x60000000
73862 #define DT_LOOS 0x6000000d
73863@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
73864 #define PF_W 0x2
73865 #define PF_X 0x1
73866
73867+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
73868+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
73869+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
73870+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
73871+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
73872+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
73873+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
73874+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
73875+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
73876+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
73877+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
73878+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
73879+
73880 typedef struct elf32_phdr{
73881 Elf32_Word p_type;
73882 Elf32_Off p_offset;
73883@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
73884 #define EI_OSABI 7
73885 #define EI_PAD 8
73886
73887+#define EI_PAX 14
73888+
73889 #define ELFMAG0 0x7f /* EI_MAG */
73890 #define ELFMAG1 'E'
73891 #define ELFMAG2 'L'
73892diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
73893index aa169c4..6a2771d 100644
73894--- a/include/uapi/linux/personality.h
73895+++ b/include/uapi/linux/personality.h
73896@@ -30,6 +30,7 @@ enum {
73897 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
73898 ADDR_NO_RANDOMIZE | \
73899 ADDR_COMPAT_LAYOUT | \
73900+ ADDR_LIMIT_3GB | \
73901 MMAP_PAGE_ZERO)
73902
73903 /*
73904diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
73905index 7530e74..e714828 100644
73906--- a/include/uapi/linux/screen_info.h
73907+++ b/include/uapi/linux/screen_info.h
73908@@ -43,7 +43,8 @@ struct screen_info {
73909 __u16 pages; /* 0x32 */
73910 __u16 vesa_attributes; /* 0x34 */
73911 __u32 capabilities; /* 0x36 */
73912- __u8 _reserved[6]; /* 0x3a */
73913+ __u16 vesapm_size; /* 0x3a */
73914+ __u8 _reserved[4]; /* 0x3c */
73915 } __attribute__((packed));
73916
73917 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
73918diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
73919index 0e011eb..82681b1 100644
73920--- a/include/uapi/linux/swab.h
73921+++ b/include/uapi/linux/swab.h
73922@@ -43,7 +43,7 @@
73923 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
73924 */
73925
73926-static inline __attribute_const__ __u16 __fswab16(__u16 val)
73927+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
73928 {
73929 #ifdef __HAVE_BUILTIN_BSWAP16__
73930 return __builtin_bswap16(val);
73931@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
73932 #endif
73933 }
73934
73935-static inline __attribute_const__ __u32 __fswab32(__u32 val)
73936+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
73937 {
73938 #ifdef __HAVE_BUILTIN_BSWAP32__
73939 return __builtin_bswap32(val);
73940@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
73941 #endif
73942 }
73943
73944-static inline __attribute_const__ __u64 __fswab64(__u64 val)
73945+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
73946 {
73947 #ifdef __HAVE_BUILTIN_BSWAP64__
73948 return __builtin_bswap64(val);
73949diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
73950index 6d67213..8dab561 100644
73951--- a/include/uapi/linux/sysctl.h
73952+++ b/include/uapi/linux/sysctl.h
73953@@ -155,7 +155,11 @@ enum
73954 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
73955 };
73956
73957-
73958+#ifdef CONFIG_PAX_SOFTMODE
73959+enum {
73960+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
73961+};
73962+#endif
73963
73964 /* CTL_VM names: */
73965 enum
73966diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
73967index e4629b9..6958086 100644
73968--- a/include/uapi/linux/xattr.h
73969+++ b/include/uapi/linux/xattr.h
73970@@ -63,5 +63,9 @@
73971 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
73972 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
73973
73974+/* User namespace */
73975+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
73976+#define XATTR_PAX_FLAGS_SUFFIX "flags"
73977+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
73978
73979 #endif /* _UAPI_LINUX_XATTR_H */
73980diff --git a/include/video/udlfb.h b/include/video/udlfb.h
73981index f9466fa..f4e2b81 100644
73982--- a/include/video/udlfb.h
73983+++ b/include/video/udlfb.h
73984@@ -53,10 +53,10 @@ struct dlfb_data {
73985 u32 pseudo_palette[256];
73986 int blank_mode; /*one of FB_BLANK_ */
73987 /* blit-only rendering path metrics, exposed through sysfs */
73988- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73989- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
73990- atomic_t bytes_sent; /* to usb, after compression including overhead */
73991- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
73992+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73993+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
73994+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
73995+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
73996 };
73997
73998 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
73999diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
74000index 1a91850..28573f8 100644
74001--- a/include/video/uvesafb.h
74002+++ b/include/video/uvesafb.h
74003@@ -122,6 +122,7 @@ struct uvesafb_par {
74004 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
74005 u8 pmi_setpal; /* PMI for palette changes */
74006 u16 *pmi_base; /* protected mode interface location */
74007+ u8 *pmi_code; /* protected mode code location */
74008 void *pmi_start;
74009 void *pmi_pal;
74010 u8 *vbe_state_orig; /*
74011diff --git a/init/Kconfig b/init/Kconfig
74012index 2d9b831..ae4c8ac 100644
74013--- a/init/Kconfig
74014+++ b/init/Kconfig
74015@@ -1029,6 +1029,7 @@ endif # CGROUPS
74016
74017 config CHECKPOINT_RESTORE
74018 bool "Checkpoint/restore support" if EXPERT
74019+ depends on !GRKERNSEC
74020 default n
74021 help
74022 Enables additional kernel features in a sake of checkpoint/restore.
74023@@ -1516,7 +1517,7 @@ config SLUB_DEBUG
74024
74025 config COMPAT_BRK
74026 bool "Disable heap randomization"
74027- default y
74028+ default n
74029 help
74030 Randomizing heap placement makes heap exploits harder, but it
74031 also breaks ancient binaries (including anything libc5 based).
74032@@ -1779,7 +1780,7 @@ config INIT_ALL_POSSIBLE
74033 config STOP_MACHINE
74034 bool
74035 default y
74036- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
74037+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
74038 help
74039 Need stop_machine() primitive.
74040
74041diff --git a/init/Makefile b/init/Makefile
74042index 7bc47ee..6da2dc7 100644
74043--- a/init/Makefile
74044+++ b/init/Makefile
74045@@ -2,6 +2,9 @@
74046 # Makefile for the linux kernel.
74047 #
74048
74049+ccflags-y := $(GCC_PLUGINS_CFLAGS)
74050+asflags-y := $(GCC_PLUGINS_AFLAGS)
74051+
74052 obj-y := main.o version.o mounts.o
74053 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
74054 obj-y += noinitramfs.o
74055diff --git a/init/do_mounts.c b/init/do_mounts.c
74056index a2b49f2..03a0e17c 100644
74057--- a/init/do_mounts.c
74058+++ b/init/do_mounts.c
74059@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
74060 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
74061 {
74062 struct super_block *s;
74063- int err = sys_mount(name, "/root", fs, flags, data);
74064+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
74065 if (err)
74066 return err;
74067
74068- sys_chdir("/root");
74069+ sys_chdir((const char __force_user *)"/root");
74070 s = current->fs->pwd.dentry->d_sb;
74071 ROOT_DEV = s->s_dev;
74072 printk(KERN_INFO
74073@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
74074 va_start(args, fmt);
74075 vsprintf(buf, fmt, args);
74076 va_end(args);
74077- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
74078+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
74079 if (fd >= 0) {
74080 sys_ioctl(fd, FDEJECT, 0);
74081 sys_close(fd);
74082 }
74083 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
74084- fd = sys_open("/dev/console", O_RDWR, 0);
74085+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
74086 if (fd >= 0) {
74087 sys_ioctl(fd, TCGETS, (long)&termios);
74088 termios.c_lflag &= ~ICANON;
74089 sys_ioctl(fd, TCSETSF, (long)&termios);
74090- sys_read(fd, &c, 1);
74091+ sys_read(fd, (char __user *)&c, 1);
74092 termios.c_lflag |= ICANON;
74093 sys_ioctl(fd, TCSETSF, (long)&termios);
74094 sys_close(fd);
74095@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
74096 mount_root();
74097 out:
74098 devtmpfs_mount("dev");
74099- sys_mount(".", "/", NULL, MS_MOVE, NULL);
74100- sys_chroot(".");
74101+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
74102+ sys_chroot((const char __force_user *)".");
74103 }
74104diff --git a/init/do_mounts.h b/init/do_mounts.h
74105index f5b978a..69dbfe8 100644
74106--- a/init/do_mounts.h
74107+++ b/init/do_mounts.h
74108@@ -15,15 +15,15 @@ extern int root_mountflags;
74109
74110 static inline int create_dev(char *name, dev_t dev)
74111 {
74112- sys_unlink(name);
74113- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
74114+ sys_unlink((char __force_user *)name);
74115+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
74116 }
74117
74118 #if BITS_PER_LONG == 32
74119 static inline u32 bstat(char *name)
74120 {
74121 struct stat64 stat;
74122- if (sys_stat64(name, &stat) != 0)
74123+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
74124 return 0;
74125 if (!S_ISBLK(stat.st_mode))
74126 return 0;
74127@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
74128 static inline u32 bstat(char *name)
74129 {
74130 struct stat stat;
74131- if (sys_newstat(name, &stat) != 0)
74132+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
74133 return 0;
74134 if (!S_ISBLK(stat.st_mode))
74135 return 0;
74136diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
74137index 3e0878e..8a9d7a0 100644
74138--- a/init/do_mounts_initrd.c
74139+++ b/init/do_mounts_initrd.c
74140@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
74141 {
74142 sys_unshare(CLONE_FS | CLONE_FILES);
74143 /* stdin/stdout/stderr for /linuxrc */
74144- sys_open("/dev/console", O_RDWR, 0);
74145+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
74146 sys_dup(0);
74147 sys_dup(0);
74148 /* move initrd over / and chdir/chroot in initrd root */
74149- sys_chdir("/root");
74150- sys_mount(".", "/", NULL, MS_MOVE, NULL);
74151- sys_chroot(".");
74152+ sys_chdir((const char __force_user *)"/root");
74153+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
74154+ sys_chroot((const char __force_user *)".");
74155 sys_setsid();
74156 return 0;
74157 }
74158@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
74159 create_dev("/dev/root.old", Root_RAM0);
74160 /* mount initrd on rootfs' /root */
74161 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
74162- sys_mkdir("/old", 0700);
74163- sys_chdir("/old");
74164+ sys_mkdir((const char __force_user *)"/old", 0700);
74165+ sys_chdir((const char __force_user *)"/old");
74166
74167 /* try loading default modules from initrd */
74168 load_default_modules();
74169@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
74170 current->flags &= ~PF_FREEZER_SKIP;
74171
74172 /* move initrd to rootfs' /old */
74173- sys_mount("..", ".", NULL, MS_MOVE, NULL);
74174+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
74175 /* switch root and cwd back to / of rootfs */
74176- sys_chroot("..");
74177+ sys_chroot((const char __force_user *)"..");
74178
74179 if (new_decode_dev(real_root_dev) == Root_RAM0) {
74180- sys_chdir("/old");
74181+ sys_chdir((const char __force_user *)"/old");
74182 return;
74183 }
74184
74185- sys_chdir("/");
74186+ sys_chdir((const char __force_user *)"/");
74187 ROOT_DEV = new_decode_dev(real_root_dev);
74188 mount_root();
74189
74190 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
74191- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
74192+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
74193 if (!error)
74194 printk("okay\n");
74195 else {
74196- int fd = sys_open("/dev/root.old", O_RDWR, 0);
74197+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
74198 if (error == -ENOENT)
74199 printk("/initrd does not exist. Ignored.\n");
74200 else
74201 printk("failed\n");
74202 printk(KERN_NOTICE "Unmounting old root\n");
74203- sys_umount("/old", MNT_DETACH);
74204+ sys_umount((char __force_user *)"/old", MNT_DETACH);
74205 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
74206 if (fd < 0) {
74207 error = fd;
74208@@ -127,11 +127,11 @@ int __init initrd_load(void)
74209 * mounted in the normal path.
74210 */
74211 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
74212- sys_unlink("/initrd.image");
74213+ sys_unlink((const char __force_user *)"/initrd.image");
74214 handle_initrd();
74215 return 1;
74216 }
74217 }
74218- sys_unlink("/initrd.image");
74219+ sys_unlink((const char __force_user *)"/initrd.image");
74220 return 0;
74221 }
74222diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
74223index 8cb6db5..d729f50 100644
74224--- a/init/do_mounts_md.c
74225+++ b/init/do_mounts_md.c
74226@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
74227 partitioned ? "_d" : "", minor,
74228 md_setup_args[ent].device_names);
74229
74230- fd = sys_open(name, 0, 0);
74231+ fd = sys_open((char __force_user *)name, 0, 0);
74232 if (fd < 0) {
74233 printk(KERN_ERR "md: open failed - cannot start "
74234 "array %s\n", name);
74235@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
74236 * array without it
74237 */
74238 sys_close(fd);
74239- fd = sys_open(name, 0, 0);
74240+ fd = sys_open((char __force_user *)name, 0, 0);
74241 sys_ioctl(fd, BLKRRPART, 0);
74242 }
74243 sys_close(fd);
74244@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
74245
74246 wait_for_device_probe();
74247
74248- fd = sys_open("/dev/md0", 0, 0);
74249+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
74250 if (fd >= 0) {
74251 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
74252 sys_close(fd);
74253diff --git a/init/init_task.c b/init/init_task.c
74254index ba0a7f36..2bcf1d5 100644
74255--- a/init/init_task.c
74256+++ b/init/init_task.c
74257@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
74258 * Initial thread structure. Alignment of this is handled by a special
74259 * linker map entry.
74260 */
74261+#ifdef CONFIG_X86
74262+union thread_union init_thread_union __init_task_data;
74263+#else
74264 union thread_union init_thread_union __init_task_data =
74265 { INIT_THREAD_INFO(init_task) };
74266+#endif
74267diff --git a/init/initramfs.c b/init/initramfs.c
74268index a67ef9d..2d17ed9 100644
74269--- a/init/initramfs.c
74270+++ b/init/initramfs.c
74271@@ -84,7 +84,7 @@ static void __init free_hash(void)
74272 }
74273 }
74274
74275-static long __init do_utime(char *filename, time_t mtime)
74276+static long __init do_utime(char __force_user *filename, time_t mtime)
74277 {
74278 struct timespec t[2];
74279
74280@@ -119,7 +119,7 @@ static void __init dir_utime(void)
74281 struct dir_entry *de, *tmp;
74282 list_for_each_entry_safe(de, tmp, &dir_list, list) {
74283 list_del(&de->list);
74284- do_utime(de->name, de->mtime);
74285+ do_utime((char __force_user *)de->name, de->mtime);
74286 kfree(de->name);
74287 kfree(de);
74288 }
74289@@ -281,7 +281,7 @@ static int __init maybe_link(void)
74290 if (nlink >= 2) {
74291 char *old = find_link(major, minor, ino, mode, collected);
74292 if (old)
74293- return (sys_link(old, collected) < 0) ? -1 : 1;
74294+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
74295 }
74296 return 0;
74297 }
74298@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
74299 {
74300 struct stat st;
74301
74302- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
74303+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
74304 if (S_ISDIR(st.st_mode))
74305- sys_rmdir(path);
74306+ sys_rmdir((char __force_user *)path);
74307 else
74308- sys_unlink(path);
74309+ sys_unlink((char __force_user *)path);
74310 }
74311 }
74312
74313@@ -315,7 +315,7 @@ static int __init do_name(void)
74314 int openflags = O_WRONLY|O_CREAT;
74315 if (ml != 1)
74316 openflags |= O_TRUNC;
74317- wfd = sys_open(collected, openflags, mode);
74318+ wfd = sys_open((char __force_user *)collected, openflags, mode);
74319
74320 if (wfd >= 0) {
74321 sys_fchown(wfd, uid, gid);
74322@@ -327,17 +327,17 @@ static int __init do_name(void)
74323 }
74324 }
74325 } else if (S_ISDIR(mode)) {
74326- sys_mkdir(collected, mode);
74327- sys_chown(collected, uid, gid);
74328- sys_chmod(collected, mode);
74329+ sys_mkdir((char __force_user *)collected, mode);
74330+ sys_chown((char __force_user *)collected, uid, gid);
74331+ sys_chmod((char __force_user *)collected, mode);
74332 dir_add(collected, mtime);
74333 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
74334 S_ISFIFO(mode) || S_ISSOCK(mode)) {
74335 if (maybe_link() == 0) {
74336- sys_mknod(collected, mode, rdev);
74337- sys_chown(collected, uid, gid);
74338- sys_chmod(collected, mode);
74339- do_utime(collected, mtime);
74340+ sys_mknod((char __force_user *)collected, mode, rdev);
74341+ sys_chown((char __force_user *)collected, uid, gid);
74342+ sys_chmod((char __force_user *)collected, mode);
74343+ do_utime((char __force_user *)collected, mtime);
74344 }
74345 }
74346 return 0;
74347@@ -346,15 +346,15 @@ static int __init do_name(void)
74348 static int __init do_copy(void)
74349 {
74350 if (count >= body_len) {
74351- sys_write(wfd, victim, body_len);
74352+ sys_write(wfd, (char __force_user *)victim, body_len);
74353 sys_close(wfd);
74354- do_utime(vcollected, mtime);
74355+ do_utime((char __force_user *)vcollected, mtime);
74356 kfree(vcollected);
74357 eat(body_len);
74358 state = SkipIt;
74359 return 0;
74360 } else {
74361- sys_write(wfd, victim, count);
74362+ sys_write(wfd, (char __force_user *)victim, count);
74363 body_len -= count;
74364 eat(count);
74365 return 1;
74366@@ -365,9 +365,9 @@ static int __init do_symlink(void)
74367 {
74368 collected[N_ALIGN(name_len) + body_len] = '\0';
74369 clean_path(collected, 0);
74370- sys_symlink(collected + N_ALIGN(name_len), collected);
74371- sys_lchown(collected, uid, gid);
74372- do_utime(collected, mtime);
74373+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
74374+ sys_lchown((char __force_user *)collected, uid, gid);
74375+ do_utime((char __force_user *)collected, mtime);
74376 state = SkipIt;
74377 next_state = Reset;
74378 return 0;
74379@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
74380 {
74381 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
74382 if (err)
74383- panic(err); /* Failed to decompress INTERNAL initramfs */
74384+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
74385 if (initrd_start) {
74386 #ifdef CONFIG_BLK_DEV_RAM
74387 int fd;
74388diff --git a/init/main.c b/init/main.c
74389index 9484f4b..4c01430 100644
74390--- a/init/main.c
74391+++ b/init/main.c
74392@@ -100,6 +100,8 @@ static inline void mark_rodata_ro(void) { }
74393 extern void tc_init(void);
74394 #endif
74395
74396+extern void grsecurity_init(void);
74397+
74398 /*
74399 * Debug helper: via this flag we know that we are in 'early bootup code'
74400 * where only the boot processor is running with IRQ disabled. This means
74401@@ -153,6 +155,64 @@ static int __init set_reset_devices(char *str)
74402
74403 __setup("reset_devices", set_reset_devices);
74404
74405+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74406+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
74407+static int __init setup_grsec_proc_gid(char *str)
74408+{
74409+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
74410+ return 1;
74411+}
74412+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
74413+#endif
74414+
74415+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
74416+unsigned long pax_user_shadow_base __read_only = 1UL << TASK_SIZE_MAX_SHIFT;
74417+EXPORT_SYMBOL(pax_user_shadow_base);
74418+extern char pax_enter_kernel_user[];
74419+extern char pax_exit_kernel_user[];
74420+extern pgdval_t clone_pgd_mask;
74421+#endif
74422+
74423+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
74424+static int __init setup_pax_nouderef(char *str)
74425+{
74426+#ifdef CONFIG_X86_32
74427+ unsigned int cpu;
74428+ struct desc_struct *gdt;
74429+
74430+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
74431+ gdt = get_cpu_gdt_table(cpu);
74432+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
74433+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
74434+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
74435+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
74436+ }
74437+ loadsegment(ds, __KERNEL_DS);
74438+ loadsegment(es, __KERNEL_DS);
74439+ loadsegment(ss, __KERNEL_DS);
74440+#else
74441+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
74442+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
74443+ clone_pgd_mask = ~(pgdval_t)0UL;
74444+ pax_user_shadow_base = 0UL;
74445+#endif
74446+
74447+ return 0;
74448+}
74449+early_param("pax_nouderef", setup_pax_nouderef);
74450+#endif
74451+
74452+#ifdef CONFIG_PAX_SOFTMODE
74453+int pax_softmode;
74454+
74455+static int __init setup_pax_softmode(char *str)
74456+{
74457+ get_option(&str, &pax_softmode);
74458+ return 1;
74459+}
74460+__setup("pax_softmode=", setup_pax_softmode);
74461+#endif
74462+
74463 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
74464 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
74465 static const char *panic_later, *panic_param;
74466@@ -655,8 +715,6 @@ static void __init do_ctors(void)
74467 bool initcall_debug;
74468 core_param(initcall_debug, initcall_debug, bool, 0644);
74469
74470-static char msgbuf[64];
74471-
74472 static int __init_or_module do_one_initcall_debug(initcall_t fn)
74473 {
74474 ktime_t calltime, delta, rettime;
74475@@ -679,23 +737,22 @@ int __init_or_module do_one_initcall(initcall_t fn)
74476 {
74477 int count = preempt_count();
74478 int ret;
74479+ const char *msg1 = "", *msg2 = "";
74480
74481 if (initcall_debug)
74482 ret = do_one_initcall_debug(fn);
74483 else
74484 ret = fn();
74485
74486- msgbuf[0] = 0;
74487-
74488 if (preempt_count() != count) {
74489- sprintf(msgbuf, "preemption imbalance ");
74490+ msg1 = " preemption imbalance";
74491 preempt_count() = count;
74492 }
74493 if (irqs_disabled()) {
74494- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
74495+ msg2 = " disabled interrupts";
74496 local_irq_enable();
74497 }
74498- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
74499+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
74500
74501 return ret;
74502 }
74503@@ -748,8 +805,14 @@ static void __init do_initcall_level(int level)
74504 level, level,
74505 &repair_env_string);
74506
74507- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
74508+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
74509 do_one_initcall(*fn);
74510+
74511+#ifdef LATENT_ENTROPY_PLUGIN
74512+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74513+#endif
74514+
74515+ }
74516 }
74517
74518 static void __init do_initcalls(void)
74519@@ -783,8 +846,14 @@ static void __init do_pre_smp_initcalls(void)
74520 {
74521 initcall_t *fn;
74522
74523- for (fn = __initcall_start; fn < __initcall0_start; fn++)
74524+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
74525 do_one_initcall(*fn);
74526+
74527+#ifdef LATENT_ENTROPY_PLUGIN
74528+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74529+#endif
74530+
74531+ }
74532 }
74533
74534 /*
74535@@ -802,8 +871,8 @@ static int run_init_process(const char *init_filename)
74536 {
74537 argv_init[0] = init_filename;
74538 return do_execve(init_filename,
74539- (const char __user *const __user *)argv_init,
74540- (const char __user *const __user *)envp_init);
74541+ (const char __user *const __force_user *)argv_init,
74542+ (const char __user *const __force_user *)envp_init);
74543 }
74544
74545 static noinline void __init kernel_init_freeable(void);
74546@@ -880,7 +949,7 @@ static noinline void __init kernel_init_freeable(void)
74547 do_basic_setup();
74548
74549 /* Open the /dev/console on the rootfs, this should never fail */
74550- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
74551+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
74552 pr_err("Warning: unable to open an initial console.\n");
74553
74554 (void) sys_dup(0);
74555@@ -893,11 +962,13 @@ static noinline void __init kernel_init_freeable(void)
74556 if (!ramdisk_execute_command)
74557 ramdisk_execute_command = "/init";
74558
74559- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
74560+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
74561 ramdisk_execute_command = NULL;
74562 prepare_namespace();
74563 }
74564
74565+ grsecurity_init();
74566+
74567 /*
74568 * Ok, we have completed the initial bootup, and
74569 * we're essentially up and running. Get rid of the
74570diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
74571index 130dfec..cc88451 100644
74572--- a/ipc/ipc_sysctl.c
74573+++ b/ipc/ipc_sysctl.c
74574@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
74575 static int proc_ipc_dointvec(ctl_table *table, int write,
74576 void __user *buffer, size_t *lenp, loff_t *ppos)
74577 {
74578- struct ctl_table ipc_table;
74579+ ctl_table_no_const ipc_table;
74580
74581 memcpy(&ipc_table, table, sizeof(ipc_table));
74582 ipc_table.data = get_ipc(table);
74583@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
74584 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
74585 void __user *buffer, size_t *lenp, loff_t *ppos)
74586 {
74587- struct ctl_table ipc_table;
74588+ ctl_table_no_const ipc_table;
74589
74590 memcpy(&ipc_table, table, sizeof(ipc_table));
74591 ipc_table.data = get_ipc(table);
74592@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
74593 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74594 void __user *buffer, size_t *lenp, loff_t *ppos)
74595 {
74596- struct ctl_table ipc_table;
74597+ ctl_table_no_const ipc_table;
74598 size_t lenp_bef = *lenp;
74599 int rc;
74600
74601@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74602 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
74603 void __user *buffer, size_t *lenp, loff_t *ppos)
74604 {
74605- struct ctl_table ipc_table;
74606+ ctl_table_no_const ipc_table;
74607 memcpy(&ipc_table, table, sizeof(ipc_table));
74608 ipc_table.data = get_ipc(table);
74609
74610@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
74611 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
74612 void __user *buffer, size_t *lenp, loff_t *ppos)
74613 {
74614- struct ctl_table ipc_table;
74615+ ctl_table_no_const ipc_table;
74616 size_t lenp_bef = *lenp;
74617 int oldval;
74618 int rc;
74619diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
74620index 383d638..943fdbb 100644
74621--- a/ipc/mq_sysctl.c
74622+++ b/ipc/mq_sysctl.c
74623@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
74624 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
74625 void __user *buffer, size_t *lenp, loff_t *ppos)
74626 {
74627- struct ctl_table mq_table;
74628+ ctl_table_no_const mq_table;
74629 memcpy(&mq_table, table, sizeof(mq_table));
74630 mq_table.data = get_mq(table);
74631
74632diff --git a/ipc/mqueue.c b/ipc/mqueue.c
74633index e4e47f6..a85e0ad 100644
74634--- a/ipc/mqueue.c
74635+++ b/ipc/mqueue.c
74636@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
74637 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
74638 info->attr.mq_msgsize);
74639
74640+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
74641 spin_lock(&mq_lock);
74642 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
74643 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
74644diff --git a/ipc/msg.c b/ipc/msg.c
74645index d0c6d96..69a893c 100644
74646--- a/ipc/msg.c
74647+++ b/ipc/msg.c
74648@@ -296,18 +296,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
74649 return security_msg_queue_associate(msq, msgflg);
74650 }
74651
74652+static struct ipc_ops msg_ops = {
74653+ .getnew = newque,
74654+ .associate = msg_security,
74655+ .more_checks = NULL
74656+};
74657+
74658 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
74659 {
74660 struct ipc_namespace *ns;
74661- struct ipc_ops msg_ops;
74662 struct ipc_params msg_params;
74663
74664 ns = current->nsproxy->ipc_ns;
74665
74666- msg_ops.getnew = newque;
74667- msg_ops.associate = msg_security;
74668- msg_ops.more_checks = NULL;
74669-
74670 msg_params.key = key;
74671 msg_params.flg = msgflg;
74672
74673diff --git a/ipc/sem.c b/ipc/sem.c
74674index 70480a3..f4e8262 100644
74675--- a/ipc/sem.c
74676+++ b/ipc/sem.c
74677@@ -460,10 +460,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
74678 return 0;
74679 }
74680
74681+static struct ipc_ops sem_ops = {
74682+ .getnew = newary,
74683+ .associate = sem_security,
74684+ .more_checks = sem_more_checks
74685+};
74686+
74687 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74688 {
74689 struct ipc_namespace *ns;
74690- struct ipc_ops sem_ops;
74691 struct ipc_params sem_params;
74692
74693 ns = current->nsproxy->ipc_ns;
74694@@ -471,10 +476,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74695 if (nsems < 0 || nsems > ns->sc_semmsl)
74696 return -EINVAL;
74697
74698- sem_ops.getnew = newary;
74699- sem_ops.associate = sem_security;
74700- sem_ops.more_checks = sem_more_checks;
74701-
74702 sem_params.key = key;
74703 sem_params.flg = semflg;
74704 sem_params.u.nsems = nsems;
74705diff --git a/ipc/shm.c b/ipc/shm.c
74706index 7e199fa..180a1ca 100644
74707--- a/ipc/shm.c
74708+++ b/ipc/shm.c
74709@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
74710 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
74711 #endif
74712
74713+#ifdef CONFIG_GRKERNSEC
74714+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74715+ const time_t shm_createtime, const kuid_t cuid,
74716+ const int shmid);
74717+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74718+ const time_t shm_createtime);
74719+#endif
74720+
74721 void shm_init_ns(struct ipc_namespace *ns)
74722 {
74723 ns->shm_ctlmax = SHMMAX;
74724@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
74725 shp->shm_lprid = 0;
74726 shp->shm_atim = shp->shm_dtim = 0;
74727 shp->shm_ctim = get_seconds();
74728+#ifdef CONFIG_GRKERNSEC
74729+ {
74730+ struct timespec timeval;
74731+ do_posix_clock_monotonic_gettime(&timeval);
74732+
74733+ shp->shm_createtime = timeval.tv_sec;
74734+ }
74735+#endif
74736 shp->shm_segsz = size;
74737 shp->shm_nattch = 0;
74738 shp->shm_file = file;
74739@@ -582,18 +598,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
74740 return 0;
74741 }
74742
74743+static struct ipc_ops shm_ops = {
74744+ .getnew = newseg,
74745+ .associate = shm_security,
74746+ .more_checks = shm_more_checks
74747+};
74748+
74749 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
74750 {
74751 struct ipc_namespace *ns;
74752- struct ipc_ops shm_ops;
74753 struct ipc_params shm_params;
74754
74755 ns = current->nsproxy->ipc_ns;
74756
74757- shm_ops.getnew = newseg;
74758- shm_ops.associate = shm_security;
74759- shm_ops.more_checks = shm_more_checks;
74760-
74761 shm_params.key = key;
74762 shm_params.flg = shmflg;
74763 shm_params.u.size = size;
74764@@ -1014,6 +1031,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74765 f_mode = FMODE_READ | FMODE_WRITE;
74766 }
74767 if (shmflg & SHM_EXEC) {
74768+
74769+#ifdef CONFIG_PAX_MPROTECT
74770+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
74771+ goto out;
74772+#endif
74773+
74774 prot |= PROT_EXEC;
74775 acc_mode |= S_IXUGO;
74776 }
74777@@ -1037,9 +1060,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74778 if (err)
74779 goto out_unlock;
74780
74781+#ifdef CONFIG_GRKERNSEC
74782+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
74783+ shp->shm_perm.cuid, shmid) ||
74784+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
74785+ err = -EACCES;
74786+ goto out_unlock;
74787+ }
74788+#endif
74789+
74790 path = shp->shm_file->f_path;
74791 path_get(&path);
74792 shp->shm_nattch++;
74793+#ifdef CONFIG_GRKERNSEC
74794+ shp->shm_lapid = current->pid;
74795+#endif
74796 size = i_size_read(path.dentry->d_inode);
74797 shm_unlock(shp);
74798
74799diff --git a/kernel/acct.c b/kernel/acct.c
74800index 8d6e145..33e0b1e 100644
74801--- a/kernel/acct.c
74802+++ b/kernel/acct.c
74803@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
74804 */
74805 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
74806 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
74807- file->f_op->write(file, (char *)&ac,
74808+ file->f_op->write(file, (char __force_user *)&ac,
74809 sizeof(acct_t), &file->f_pos);
74810 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
74811 set_fs(fs);
74812diff --git a/kernel/audit.c b/kernel/audit.c
74813index 91e53d0..d9e3ec4 100644
74814--- a/kernel/audit.c
74815+++ b/kernel/audit.c
74816@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
74817 3) suppressed due to audit_rate_limit
74818 4) suppressed due to audit_backlog_limit
74819 */
74820-static atomic_t audit_lost = ATOMIC_INIT(0);
74821+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
74822
74823 /* The netlink socket. */
74824 static struct sock *audit_sock;
74825@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
74826 unsigned long now;
74827 int print;
74828
74829- atomic_inc(&audit_lost);
74830+ atomic_inc_unchecked(&audit_lost);
74831
74832 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
74833
74834@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
74835 printk(KERN_WARNING
74836 "audit: audit_lost=%d audit_rate_limit=%d "
74837 "audit_backlog_limit=%d\n",
74838- atomic_read(&audit_lost),
74839+ atomic_read_unchecked(&audit_lost),
74840 audit_rate_limit,
74841 audit_backlog_limit);
74842 audit_panic(message);
74843@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
74844 status_set.pid = audit_pid;
74845 status_set.rate_limit = audit_rate_limit;
74846 status_set.backlog_limit = audit_backlog_limit;
74847- status_set.lost = atomic_read(&audit_lost);
74848+ status_set.lost = atomic_read_unchecked(&audit_lost);
74849 status_set.backlog = skb_queue_len(&audit_skb_queue);
74850 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
74851 &status_set, sizeof(status_set));
74852diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
74853index 6bd4a90..0ee9eff 100644
74854--- a/kernel/auditfilter.c
74855+++ b/kernel/auditfilter.c
74856@@ -423,7 +423,7 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
74857 f->lsm_rule = NULL;
74858
74859 /* Support legacy tests for a valid loginuid */
74860- if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295)) {
74861+ if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295U)) {
74862 f->type = AUDIT_LOGINUID_SET;
74863 f->val = 0;
74864 }
74865diff --git a/kernel/auditsc.c b/kernel/auditsc.c
74866index 3c8a601..3a416f6 100644
74867--- a/kernel/auditsc.c
74868+++ b/kernel/auditsc.c
74869@@ -1956,7 +1956,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
74870 }
74871
74872 /* global counter which is incremented every time something logs in */
74873-static atomic_t session_id = ATOMIC_INIT(0);
74874+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
74875
74876 /**
74877 * audit_set_loginuid - set current task's audit_context loginuid
74878@@ -1980,7 +1980,7 @@ int audit_set_loginuid(kuid_t loginuid)
74879 return -EPERM;
74880 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
74881
74882- sessionid = atomic_inc_return(&session_id);
74883+ sessionid = atomic_inc_return_unchecked(&session_id);
74884 if (context && context->in_syscall) {
74885 struct audit_buffer *ab;
74886
74887diff --git a/kernel/capability.c b/kernel/capability.c
74888index f6c2ce5..982c0f9 100644
74889--- a/kernel/capability.c
74890+++ b/kernel/capability.c
74891@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
74892 * before modification is attempted and the application
74893 * fails.
74894 */
74895+ if (tocopy > ARRAY_SIZE(kdata))
74896+ return -EFAULT;
74897+
74898 if (copy_to_user(dataptr, kdata, tocopy
74899 * sizeof(struct __user_cap_data_struct))) {
74900 return -EFAULT;
74901@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
74902 int ret;
74903
74904 rcu_read_lock();
74905- ret = security_capable(__task_cred(t), ns, cap);
74906+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
74907+ gr_task_is_capable(t, __task_cred(t), cap);
74908 rcu_read_unlock();
74909
74910- return (ret == 0);
74911+ return ret;
74912 }
74913
74914 /**
74915@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
74916 int ret;
74917
74918 rcu_read_lock();
74919- ret = security_capable_noaudit(__task_cred(t), ns, cap);
74920+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
74921 rcu_read_unlock();
74922
74923- return (ret == 0);
74924+ return ret;
74925 }
74926
74927 /**
74928@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
74929 BUG();
74930 }
74931
74932- if (security_capable(current_cred(), ns, cap) == 0) {
74933+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
74934 current->flags |= PF_SUPERPRIV;
74935 return true;
74936 }
74937@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
74938 }
74939 EXPORT_SYMBOL(ns_capable);
74940
74941+bool ns_capable_nolog(struct user_namespace *ns, int cap)
74942+{
74943+ if (unlikely(!cap_valid(cap))) {
74944+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
74945+ BUG();
74946+ }
74947+
74948+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
74949+ current->flags |= PF_SUPERPRIV;
74950+ return true;
74951+ }
74952+ return false;
74953+}
74954+EXPORT_SYMBOL(ns_capable_nolog);
74955+
74956 /**
74957 * file_ns_capable - Determine if the file's opener had a capability in effect
74958 * @file: The file we want to check
74959@@ -432,6 +451,12 @@ bool capable(int cap)
74960 }
74961 EXPORT_SYMBOL(capable);
74962
74963+bool capable_nolog(int cap)
74964+{
74965+ return ns_capable_nolog(&init_user_ns, cap);
74966+}
74967+EXPORT_SYMBOL(capable_nolog);
74968+
74969 /**
74970 * nsown_capable - Check superior capability to one's own user_ns
74971 * @cap: The capability in question
74972@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
74973
74974 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74975 }
74976+
74977+bool inode_capable_nolog(const struct inode *inode, int cap)
74978+{
74979+ struct user_namespace *ns = current_user_ns();
74980+
74981+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74982+}
74983diff --git a/kernel/cgroup.c b/kernel/cgroup.c
74984index c6e77ef..af531a0 100644
74985--- a/kernel/cgroup.c
74986+++ b/kernel/cgroup.c
74987@@ -5391,7 +5391,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
74988 struct css_set *cg = link->cg;
74989 struct task_struct *task;
74990 int count = 0;
74991- seq_printf(seq, "css_set %p\n", cg);
74992+ seq_printf(seq, "css_set %pK\n", cg);
74993 list_for_each_entry(task, &cg->tasks, cg_list) {
74994 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
74995 seq_puts(seq, " ...\n");
74996diff --git a/kernel/compat.c b/kernel/compat.c
74997index 0a09e48..f44f3f0 100644
74998--- a/kernel/compat.c
74999+++ b/kernel/compat.c
75000@@ -13,6 +13,7 @@
75001
75002 #include <linux/linkage.h>
75003 #include <linux/compat.h>
75004+#include <linux/module.h>
75005 #include <linux/errno.h>
75006 #include <linux/time.h>
75007 #include <linux/signal.h>
75008@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
75009 mm_segment_t oldfs;
75010 long ret;
75011
75012- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
75013+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
75014 oldfs = get_fs();
75015 set_fs(KERNEL_DS);
75016 ret = hrtimer_nanosleep_restart(restart);
75017@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
75018 oldfs = get_fs();
75019 set_fs(KERNEL_DS);
75020 ret = hrtimer_nanosleep(&tu,
75021- rmtp ? (struct timespec __user *)&rmt : NULL,
75022+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
75023 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
75024 set_fs(oldfs);
75025
75026@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
75027 mm_segment_t old_fs = get_fs();
75028
75029 set_fs(KERNEL_DS);
75030- ret = sys_sigpending((old_sigset_t __user *) &s);
75031+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
75032 set_fs(old_fs);
75033 if (ret == 0)
75034 ret = put_user(s, set);
75035@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
75036 mm_segment_t old_fs = get_fs();
75037
75038 set_fs(KERNEL_DS);
75039- ret = sys_old_getrlimit(resource, &r);
75040+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
75041 set_fs(old_fs);
75042
75043 if (!ret) {
75044@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
75045 set_fs (KERNEL_DS);
75046 ret = sys_wait4(pid,
75047 (stat_addr ?
75048- (unsigned int __user *) &status : NULL),
75049- options, (struct rusage __user *) &r);
75050+ (unsigned int __force_user *) &status : NULL),
75051+ options, (struct rusage __force_user *) &r);
75052 set_fs (old_fs);
75053
75054 if (ret > 0) {
75055@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
75056 memset(&info, 0, sizeof(info));
75057
75058 set_fs(KERNEL_DS);
75059- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
75060- uru ? (struct rusage __user *)&ru : NULL);
75061+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
75062+ uru ? (struct rusage __force_user *)&ru : NULL);
75063 set_fs(old_fs);
75064
75065 if ((ret < 0) || (info.si_signo == 0))
75066@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
75067 oldfs = get_fs();
75068 set_fs(KERNEL_DS);
75069 err = sys_timer_settime(timer_id, flags,
75070- (struct itimerspec __user *) &newts,
75071- (struct itimerspec __user *) &oldts);
75072+ (struct itimerspec __force_user *) &newts,
75073+ (struct itimerspec __force_user *) &oldts);
75074 set_fs(oldfs);
75075 if (!err && old && put_compat_itimerspec(old, &oldts))
75076 return -EFAULT;
75077@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
75078 oldfs = get_fs();
75079 set_fs(KERNEL_DS);
75080 err = sys_timer_gettime(timer_id,
75081- (struct itimerspec __user *) &ts);
75082+ (struct itimerspec __force_user *) &ts);
75083 set_fs(oldfs);
75084 if (!err && put_compat_itimerspec(setting, &ts))
75085 return -EFAULT;
75086@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
75087 oldfs = get_fs();
75088 set_fs(KERNEL_DS);
75089 err = sys_clock_settime(which_clock,
75090- (struct timespec __user *) &ts);
75091+ (struct timespec __force_user *) &ts);
75092 set_fs(oldfs);
75093 return err;
75094 }
75095@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
75096 oldfs = get_fs();
75097 set_fs(KERNEL_DS);
75098 err = sys_clock_gettime(which_clock,
75099- (struct timespec __user *) &ts);
75100+ (struct timespec __force_user *) &ts);
75101 set_fs(oldfs);
75102 if (!err && put_compat_timespec(&ts, tp))
75103 return -EFAULT;
75104@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
75105
75106 oldfs = get_fs();
75107 set_fs(KERNEL_DS);
75108- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
75109+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
75110 set_fs(oldfs);
75111
75112 err = compat_put_timex(utp, &txc);
75113@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
75114 oldfs = get_fs();
75115 set_fs(KERNEL_DS);
75116 err = sys_clock_getres(which_clock,
75117- (struct timespec __user *) &ts);
75118+ (struct timespec __force_user *) &ts);
75119 set_fs(oldfs);
75120 if (!err && tp && put_compat_timespec(&ts, tp))
75121 return -EFAULT;
75122@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
75123 long err;
75124 mm_segment_t oldfs;
75125 struct timespec tu;
75126- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
75127+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
75128
75129- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
75130+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
75131 oldfs = get_fs();
75132 set_fs(KERNEL_DS);
75133 err = clock_nanosleep_restart(restart);
75134@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
75135 oldfs = get_fs();
75136 set_fs(KERNEL_DS);
75137 err = sys_clock_nanosleep(which_clock, flags,
75138- (struct timespec __user *) &in,
75139- (struct timespec __user *) &out);
75140+ (struct timespec __force_user *) &in,
75141+ (struct timespec __force_user *) &out);
75142 set_fs(oldfs);
75143
75144 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
75145diff --git a/kernel/configs.c b/kernel/configs.c
75146index c18b1f1..b9a0132 100644
75147--- a/kernel/configs.c
75148+++ b/kernel/configs.c
75149@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
75150 struct proc_dir_entry *entry;
75151
75152 /* create the current config file */
75153+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
75154+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
75155+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
75156+ &ikconfig_file_ops);
75157+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75158+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
75159+ &ikconfig_file_ops);
75160+#endif
75161+#else
75162 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
75163 &ikconfig_file_ops);
75164+#endif
75165+
75166 if (!entry)
75167 return -ENOMEM;
75168
75169diff --git a/kernel/cred.c b/kernel/cred.c
75170index e0573a4..3874e41 100644
75171--- a/kernel/cred.c
75172+++ b/kernel/cred.c
75173@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
75174 validate_creds(cred);
75175 alter_cred_subscribers(cred, -1);
75176 put_cred(cred);
75177+
75178+#ifdef CONFIG_GRKERNSEC_SETXID
75179+ cred = (struct cred *) tsk->delayed_cred;
75180+ if (cred != NULL) {
75181+ tsk->delayed_cred = NULL;
75182+ validate_creds(cred);
75183+ alter_cred_subscribers(cred, -1);
75184+ put_cred(cred);
75185+ }
75186+#endif
75187 }
75188
75189 /**
75190@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
75191 * Always returns 0 thus allowing this function to be tail-called at the end
75192 * of, say, sys_setgid().
75193 */
75194-int commit_creds(struct cred *new)
75195+static int __commit_creds(struct cred *new)
75196 {
75197 struct task_struct *task = current;
75198 const struct cred *old = task->real_cred;
75199@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
75200
75201 get_cred(new); /* we will require a ref for the subj creds too */
75202
75203+ gr_set_role_label(task, new->uid, new->gid);
75204+
75205 /* dumpability changes */
75206 if (!uid_eq(old->euid, new->euid) ||
75207 !gid_eq(old->egid, new->egid) ||
75208@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
75209 put_cred(old);
75210 return 0;
75211 }
75212+#ifdef CONFIG_GRKERNSEC_SETXID
75213+extern int set_user(struct cred *new);
75214+
75215+void gr_delayed_cred_worker(void)
75216+{
75217+ const struct cred *new = current->delayed_cred;
75218+ struct cred *ncred;
75219+
75220+ current->delayed_cred = NULL;
75221+
75222+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
75223+ // from doing get_cred on it when queueing this
75224+ put_cred(new);
75225+ return;
75226+ } else if (new == NULL)
75227+ return;
75228+
75229+ ncred = prepare_creds();
75230+ if (!ncred)
75231+ goto die;
75232+ // uids
75233+ ncred->uid = new->uid;
75234+ ncred->euid = new->euid;
75235+ ncred->suid = new->suid;
75236+ ncred->fsuid = new->fsuid;
75237+ // gids
75238+ ncred->gid = new->gid;
75239+ ncred->egid = new->egid;
75240+ ncred->sgid = new->sgid;
75241+ ncred->fsgid = new->fsgid;
75242+ // groups
75243+ if (set_groups(ncred, new->group_info) < 0) {
75244+ abort_creds(ncred);
75245+ goto die;
75246+ }
75247+ // caps
75248+ ncred->securebits = new->securebits;
75249+ ncred->cap_inheritable = new->cap_inheritable;
75250+ ncred->cap_permitted = new->cap_permitted;
75251+ ncred->cap_effective = new->cap_effective;
75252+ ncred->cap_bset = new->cap_bset;
75253+
75254+ if (set_user(ncred)) {
75255+ abort_creds(ncred);
75256+ goto die;
75257+ }
75258+
75259+ // from doing get_cred on it when queueing this
75260+ put_cred(new);
75261+
75262+ __commit_creds(ncred);
75263+ return;
75264+die:
75265+ // from doing get_cred on it when queueing this
75266+ put_cred(new);
75267+ do_group_exit(SIGKILL);
75268+}
75269+#endif
75270+
75271+int commit_creds(struct cred *new)
75272+{
75273+#ifdef CONFIG_GRKERNSEC_SETXID
75274+ int ret;
75275+ int schedule_it = 0;
75276+ struct task_struct *t;
75277+
75278+ /* we won't get called with tasklist_lock held for writing
75279+ and interrupts disabled as the cred struct in that case is
75280+ init_cred
75281+ */
75282+ if (grsec_enable_setxid && !current_is_single_threaded() &&
75283+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
75284+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
75285+ schedule_it = 1;
75286+ }
75287+ ret = __commit_creds(new);
75288+ if (schedule_it) {
75289+ rcu_read_lock();
75290+ read_lock(&tasklist_lock);
75291+ for (t = next_thread(current); t != current;
75292+ t = next_thread(t)) {
75293+ if (t->delayed_cred == NULL) {
75294+ t->delayed_cred = get_cred(new);
75295+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
75296+ set_tsk_need_resched(t);
75297+ }
75298+ }
75299+ read_unlock(&tasklist_lock);
75300+ rcu_read_unlock();
75301+ }
75302+ return ret;
75303+#else
75304+ return __commit_creds(new);
75305+#endif
75306+}
75307+
75308 EXPORT_SYMBOL(commit_creds);
75309
75310 /**
75311diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
75312index 0506d44..2c20034 100644
75313--- a/kernel/debug/debug_core.c
75314+++ b/kernel/debug/debug_core.c
75315@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
75316 */
75317 static atomic_t masters_in_kgdb;
75318 static atomic_t slaves_in_kgdb;
75319-static atomic_t kgdb_break_tasklet_var;
75320+static atomic_unchecked_t kgdb_break_tasklet_var;
75321 atomic_t kgdb_setting_breakpoint;
75322
75323 struct task_struct *kgdb_usethread;
75324@@ -133,7 +133,7 @@ int kgdb_single_step;
75325 static pid_t kgdb_sstep_pid;
75326
75327 /* to keep track of the CPU which is doing the single stepping*/
75328-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75329+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75330
75331 /*
75332 * If you are debugging a problem where roundup (the collection of
75333@@ -541,7 +541,7 @@ return_normal:
75334 * kernel will only try for the value of sstep_tries before
75335 * giving up and continuing on.
75336 */
75337- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
75338+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
75339 (kgdb_info[cpu].task &&
75340 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
75341 atomic_set(&kgdb_active, -1);
75342@@ -635,8 +635,8 @@ cpu_master_loop:
75343 }
75344
75345 kgdb_restore:
75346- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
75347- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
75348+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
75349+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
75350 if (kgdb_info[sstep_cpu].task)
75351 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
75352 else
75353@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
75354 static void kgdb_tasklet_bpt(unsigned long ing)
75355 {
75356 kgdb_breakpoint();
75357- atomic_set(&kgdb_break_tasklet_var, 0);
75358+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
75359 }
75360
75361 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
75362
75363 void kgdb_schedule_breakpoint(void)
75364 {
75365- if (atomic_read(&kgdb_break_tasklet_var) ||
75366+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
75367 atomic_read(&kgdb_active) != -1 ||
75368 atomic_read(&kgdb_setting_breakpoint))
75369 return;
75370- atomic_inc(&kgdb_break_tasklet_var);
75371+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
75372 tasklet_schedule(&kgdb_tasklet_breakpoint);
75373 }
75374 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
75375diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
75376index 00eb8f7..d7e3244 100644
75377--- a/kernel/debug/kdb/kdb_main.c
75378+++ b/kernel/debug/kdb/kdb_main.c
75379@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
75380 continue;
75381
75382 kdb_printf("%-20s%8u 0x%p ", mod->name,
75383- mod->core_size, (void *)mod);
75384+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
75385 #ifdef CONFIG_MODULE_UNLOAD
75386 kdb_printf("%4ld ", module_refcount(mod));
75387 #endif
75388@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
75389 kdb_printf(" (Loading)");
75390 else
75391 kdb_printf(" (Live)");
75392- kdb_printf(" 0x%p", mod->module_core);
75393+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
75394
75395 #ifdef CONFIG_MODULE_UNLOAD
75396 {
75397diff --git a/kernel/events/core.c b/kernel/events/core.c
75398index b391907..a0e2372 100644
75399--- a/kernel/events/core.c
75400+++ b/kernel/events/core.c
75401@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
75402 * 0 - disallow raw tracepoint access for unpriv
75403 * 1 - disallow cpu events for unpriv
75404 * 2 - disallow kernel profiling for unpriv
75405+ * 3 - disallow all unpriv perf event use
75406 */
75407-int sysctl_perf_event_paranoid __read_mostly = 1;
75408+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
75409+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
75410+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
75411+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
75412+#else
75413+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
75414+#endif
75415
75416 /* Minimum for 512 kiB + 1 user control page */
75417 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
75418@@ -184,7 +191,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
75419 return 0;
75420 }
75421
75422-static atomic64_t perf_event_id;
75423+static atomic64_unchecked_t perf_event_id;
75424
75425 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
75426 enum event_type_t event_type);
75427@@ -2725,7 +2732,7 @@ static void __perf_event_read(void *info)
75428
75429 static inline u64 perf_event_count(struct perf_event *event)
75430 {
75431- return local64_read(&event->count) + atomic64_read(&event->child_count);
75432+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
75433 }
75434
75435 static u64 perf_event_read(struct perf_event *event)
75436@@ -3071,9 +3078,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
75437 mutex_lock(&event->child_mutex);
75438 total += perf_event_read(event);
75439 *enabled += event->total_time_enabled +
75440- atomic64_read(&event->child_total_time_enabled);
75441+ atomic64_read_unchecked(&event->child_total_time_enabled);
75442 *running += event->total_time_running +
75443- atomic64_read(&event->child_total_time_running);
75444+ atomic64_read_unchecked(&event->child_total_time_running);
75445
75446 list_for_each_entry(child, &event->child_list, child_list) {
75447 total += perf_event_read(child);
75448@@ -3459,10 +3466,10 @@ void perf_event_update_userpage(struct perf_event *event)
75449 userpg->offset -= local64_read(&event->hw.prev_count);
75450
75451 userpg->time_enabled = enabled +
75452- atomic64_read(&event->child_total_time_enabled);
75453+ atomic64_read_unchecked(&event->child_total_time_enabled);
75454
75455 userpg->time_running = running +
75456- atomic64_read(&event->child_total_time_running);
75457+ atomic64_read_unchecked(&event->child_total_time_running);
75458
75459 arch_perf_update_userpage(userpg, now);
75460
75461@@ -4012,7 +4019,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
75462
75463 /* Data. */
75464 sp = perf_user_stack_pointer(regs);
75465- rem = __output_copy_user(handle, (void *) sp, dump_size);
75466+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
75467 dyn_size = dump_size - rem;
75468
75469 perf_output_skip(handle, rem);
75470@@ -4100,11 +4107,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
75471 values[n++] = perf_event_count(event);
75472 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
75473 values[n++] = enabled +
75474- atomic64_read(&event->child_total_time_enabled);
75475+ atomic64_read_unchecked(&event->child_total_time_enabled);
75476 }
75477 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
75478 values[n++] = running +
75479- atomic64_read(&event->child_total_time_running);
75480+ atomic64_read_unchecked(&event->child_total_time_running);
75481 }
75482 if (read_format & PERF_FORMAT_ID)
75483 values[n++] = primary_event_id(event);
75484@@ -4813,12 +4820,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
75485 * need to add enough zero bytes after the string to handle
75486 * the 64bit alignment we do later.
75487 */
75488- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
75489+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
75490 if (!buf) {
75491 name = strncpy(tmp, "//enomem", sizeof(tmp));
75492 goto got_name;
75493 }
75494- name = d_path(&file->f_path, buf, PATH_MAX);
75495+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
75496 if (IS_ERR(name)) {
75497 name = strncpy(tmp, "//toolong", sizeof(tmp));
75498 goto got_name;
75499@@ -6240,7 +6247,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
75500 event->parent = parent_event;
75501
75502 event->ns = get_pid_ns(task_active_pid_ns(current));
75503- event->id = atomic64_inc_return(&perf_event_id);
75504+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
75505
75506 event->state = PERF_EVENT_STATE_INACTIVE;
75507
75508@@ -6550,6 +6557,11 @@ SYSCALL_DEFINE5(perf_event_open,
75509 if (flags & ~PERF_FLAG_ALL)
75510 return -EINVAL;
75511
75512+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
75513+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
75514+ return -EACCES;
75515+#endif
75516+
75517 err = perf_copy_attr(attr_uptr, &attr);
75518 if (err)
75519 return err;
75520@@ -6882,10 +6894,10 @@ static void sync_child_event(struct perf_event *child_event,
75521 /*
75522 * Add back the child's count to the parent's count:
75523 */
75524- atomic64_add(child_val, &parent_event->child_count);
75525- atomic64_add(child_event->total_time_enabled,
75526+ atomic64_add_unchecked(child_val, &parent_event->child_count);
75527+ atomic64_add_unchecked(child_event->total_time_enabled,
75528 &parent_event->child_total_time_enabled);
75529- atomic64_add(child_event->total_time_running,
75530+ atomic64_add_unchecked(child_event->total_time_running,
75531 &parent_event->child_total_time_running);
75532
75533 /*
75534diff --git a/kernel/events/internal.h b/kernel/events/internal.h
75535index ca65997..cc8cee4 100644
75536--- a/kernel/events/internal.h
75537+++ b/kernel/events/internal.h
75538@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
75539 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
75540 }
75541
75542-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
75543+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
75544 static inline unsigned int \
75545 func_name(struct perf_output_handle *handle, \
75546- const void *buf, unsigned int len) \
75547+ const void user *buf, unsigned int len) \
75548 { \
75549 unsigned long size, written; \
75550 \
75551@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
75552 return n;
75553 }
75554
75555-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
75556+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
75557
75558 #define MEMCPY_SKIP(dst, src, n) (n)
75559
75560-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
75561+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
75562
75563 #ifndef arch_perf_out_copy_user
75564 #define arch_perf_out_copy_user __copy_from_user_inatomic
75565 #endif
75566
75567-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
75568+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
75569
75570 /* Callchain handling */
75571 extern struct perf_callchain_entry *
75572diff --git a/kernel/exit.c b/kernel/exit.c
75573index 7bb73f9..d7978ed 100644
75574--- a/kernel/exit.c
75575+++ b/kernel/exit.c
75576@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
75577 struct task_struct *leader;
75578 int zap_leader;
75579 repeat:
75580+#ifdef CONFIG_NET
75581+ gr_del_task_from_ip_table(p);
75582+#endif
75583+
75584 /* don't need to get the RCU readlock here - the process is dead and
75585 * can't be modifying its own credentials. But shut RCU-lockdep up */
75586 rcu_read_lock();
75587@@ -340,7 +344,7 @@ int allow_signal(int sig)
75588 * know it'll be handled, so that they don't get converted to
75589 * SIGKILL or just silently dropped.
75590 */
75591- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
75592+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
75593 recalc_sigpending();
75594 spin_unlock_irq(&current->sighand->siglock);
75595 return 0;
75596@@ -709,6 +713,8 @@ void do_exit(long code)
75597 struct task_struct *tsk = current;
75598 int group_dead;
75599
75600+ set_fs(USER_DS);
75601+
75602 profile_task_exit(tsk);
75603
75604 WARN_ON(blk_needs_flush_plug(tsk));
75605@@ -725,7 +731,6 @@ void do_exit(long code)
75606 * mm_release()->clear_child_tid() from writing to a user-controlled
75607 * kernel address.
75608 */
75609- set_fs(USER_DS);
75610
75611 ptrace_event(PTRACE_EVENT_EXIT, code);
75612
75613@@ -784,6 +789,9 @@ void do_exit(long code)
75614 tsk->exit_code = code;
75615 taskstats_exit(tsk, group_dead);
75616
75617+ gr_acl_handle_psacct(tsk, code);
75618+ gr_acl_handle_exit();
75619+
75620 exit_mm(tsk);
75621
75622 if (group_dead)
75623@@ -905,7 +913,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
75624 * Take down every thread in the group. This is called by fatal signals
75625 * as well as by sys_exit_group (below).
75626 */
75627-void
75628+__noreturn void
75629 do_group_exit(int exit_code)
75630 {
75631 struct signal_struct *sig = current->signal;
75632diff --git a/kernel/fork.c b/kernel/fork.c
75633index 987b28a..4e03c05 100644
75634--- a/kernel/fork.c
75635+++ b/kernel/fork.c
75636@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
75637 *stackend = STACK_END_MAGIC; /* for overflow detection */
75638
75639 #ifdef CONFIG_CC_STACKPROTECTOR
75640- tsk->stack_canary = get_random_int();
75641+ tsk->stack_canary = pax_get_random_long();
75642 #endif
75643
75644 /*
75645@@ -345,13 +345,81 @@ free_tsk:
75646 }
75647
75648 #ifdef CONFIG_MMU
75649+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
75650+{
75651+ struct vm_area_struct *tmp;
75652+ unsigned long charge;
75653+ struct mempolicy *pol;
75654+ struct file *file;
75655+
75656+ charge = 0;
75657+ if (mpnt->vm_flags & VM_ACCOUNT) {
75658+ unsigned long len = vma_pages(mpnt);
75659+
75660+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75661+ goto fail_nomem;
75662+ charge = len;
75663+ }
75664+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75665+ if (!tmp)
75666+ goto fail_nomem;
75667+ *tmp = *mpnt;
75668+ tmp->vm_mm = mm;
75669+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
75670+ pol = mpol_dup(vma_policy(mpnt));
75671+ if (IS_ERR(pol))
75672+ goto fail_nomem_policy;
75673+ vma_set_policy(tmp, pol);
75674+ if (anon_vma_fork(tmp, mpnt))
75675+ goto fail_nomem_anon_vma_fork;
75676+ tmp->vm_flags &= ~VM_LOCKED;
75677+ tmp->vm_next = tmp->vm_prev = NULL;
75678+ tmp->vm_mirror = NULL;
75679+ file = tmp->vm_file;
75680+ if (file) {
75681+ struct inode *inode = file_inode(file);
75682+ struct address_space *mapping = file->f_mapping;
75683+
75684+ get_file(file);
75685+ if (tmp->vm_flags & VM_DENYWRITE)
75686+ atomic_dec(&inode->i_writecount);
75687+ mutex_lock(&mapping->i_mmap_mutex);
75688+ if (tmp->vm_flags & VM_SHARED)
75689+ mapping->i_mmap_writable++;
75690+ flush_dcache_mmap_lock(mapping);
75691+ /* insert tmp into the share list, just after mpnt */
75692+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75693+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
75694+ else
75695+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
75696+ flush_dcache_mmap_unlock(mapping);
75697+ mutex_unlock(&mapping->i_mmap_mutex);
75698+ }
75699+
75700+ /*
75701+ * Clear hugetlb-related page reserves for children. This only
75702+ * affects MAP_PRIVATE mappings. Faults generated by the child
75703+ * are not guaranteed to succeed, even if read-only
75704+ */
75705+ if (is_vm_hugetlb_page(tmp))
75706+ reset_vma_resv_huge_pages(tmp);
75707+
75708+ return tmp;
75709+
75710+fail_nomem_anon_vma_fork:
75711+ mpol_put(pol);
75712+fail_nomem_policy:
75713+ kmem_cache_free(vm_area_cachep, tmp);
75714+fail_nomem:
75715+ vm_unacct_memory(charge);
75716+ return NULL;
75717+}
75718+
75719 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75720 {
75721 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
75722 struct rb_node **rb_link, *rb_parent;
75723 int retval;
75724- unsigned long charge;
75725- struct mempolicy *pol;
75726
75727 uprobe_start_dup_mmap();
75728 down_write(&oldmm->mmap_sem);
75729@@ -365,8 +433,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75730 mm->locked_vm = 0;
75731 mm->mmap = NULL;
75732 mm->mmap_cache = NULL;
75733- mm->free_area_cache = oldmm->mmap_base;
75734- mm->cached_hole_size = ~0UL;
75735+ mm->free_area_cache = oldmm->free_area_cache;
75736+ mm->cached_hole_size = oldmm->cached_hole_size;
75737 mm->map_count = 0;
75738 cpumask_clear(mm_cpumask(mm));
75739 mm->mm_rb = RB_ROOT;
75740@@ -382,57 +450,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75741
75742 prev = NULL;
75743 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
75744- struct file *file;
75745-
75746 if (mpnt->vm_flags & VM_DONTCOPY) {
75747 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
75748 -vma_pages(mpnt));
75749 continue;
75750 }
75751- charge = 0;
75752- if (mpnt->vm_flags & VM_ACCOUNT) {
75753- unsigned long len = vma_pages(mpnt);
75754-
75755- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75756- goto fail_nomem;
75757- charge = len;
75758- }
75759- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75760- if (!tmp)
75761- goto fail_nomem;
75762- *tmp = *mpnt;
75763- INIT_LIST_HEAD(&tmp->anon_vma_chain);
75764- pol = mpol_dup(vma_policy(mpnt));
75765- retval = PTR_ERR(pol);
75766- if (IS_ERR(pol))
75767- goto fail_nomem_policy;
75768- vma_set_policy(tmp, pol);
75769- tmp->vm_mm = mm;
75770- if (anon_vma_fork(tmp, mpnt))
75771- goto fail_nomem_anon_vma_fork;
75772- tmp->vm_flags &= ~VM_LOCKED;
75773- tmp->vm_next = tmp->vm_prev = NULL;
75774- file = tmp->vm_file;
75775- if (file) {
75776- struct inode *inode = file_inode(file);
75777- struct address_space *mapping = file->f_mapping;
75778-
75779- get_file(file);
75780- if (tmp->vm_flags & VM_DENYWRITE)
75781- atomic_dec(&inode->i_writecount);
75782- mutex_lock(&mapping->i_mmap_mutex);
75783- if (tmp->vm_flags & VM_SHARED)
75784- mapping->i_mmap_writable++;
75785- flush_dcache_mmap_lock(mapping);
75786- /* insert tmp into the share list, just after mpnt */
75787- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75788- vma_nonlinear_insert(tmp,
75789- &mapping->i_mmap_nonlinear);
75790- else
75791- vma_interval_tree_insert_after(tmp, mpnt,
75792- &mapping->i_mmap);
75793- flush_dcache_mmap_unlock(mapping);
75794- mutex_unlock(&mapping->i_mmap_mutex);
75795+ tmp = dup_vma(mm, oldmm, mpnt);
75796+ if (!tmp) {
75797+ retval = -ENOMEM;
75798+ goto out;
75799 }
75800
75801 /*
75802@@ -464,6 +490,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75803 if (retval)
75804 goto out;
75805 }
75806+
75807+#ifdef CONFIG_PAX_SEGMEXEC
75808+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
75809+ struct vm_area_struct *mpnt_m;
75810+
75811+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
75812+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
75813+
75814+ if (!mpnt->vm_mirror)
75815+ continue;
75816+
75817+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
75818+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
75819+ mpnt->vm_mirror = mpnt_m;
75820+ } else {
75821+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
75822+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
75823+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
75824+ mpnt->vm_mirror->vm_mirror = mpnt;
75825+ }
75826+ }
75827+ BUG_ON(mpnt_m);
75828+ }
75829+#endif
75830+
75831 /* a new mm has just been created */
75832 arch_dup_mmap(oldmm, mm);
75833 retval = 0;
75834@@ -473,14 +524,6 @@ out:
75835 up_write(&oldmm->mmap_sem);
75836 uprobe_end_dup_mmap();
75837 return retval;
75838-fail_nomem_anon_vma_fork:
75839- mpol_put(pol);
75840-fail_nomem_policy:
75841- kmem_cache_free(vm_area_cachep, tmp);
75842-fail_nomem:
75843- retval = -ENOMEM;
75844- vm_unacct_memory(charge);
75845- goto out;
75846 }
75847
75848 static inline int mm_alloc_pgd(struct mm_struct *mm)
75849@@ -695,8 +738,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
75850 return ERR_PTR(err);
75851
75852 mm = get_task_mm(task);
75853- if (mm && mm != current->mm &&
75854- !ptrace_may_access(task, mode)) {
75855+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
75856+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
75857 mmput(mm);
75858 mm = ERR_PTR(-EACCES);
75859 }
75860@@ -918,13 +961,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
75861 spin_unlock(&fs->lock);
75862 return -EAGAIN;
75863 }
75864- fs->users++;
75865+ atomic_inc(&fs->users);
75866 spin_unlock(&fs->lock);
75867 return 0;
75868 }
75869 tsk->fs = copy_fs_struct(fs);
75870 if (!tsk->fs)
75871 return -ENOMEM;
75872+ /* Carry through gr_chroot_dentry and is_chrooted instead
75873+ of recomputing it here. Already copied when the task struct
75874+ is duplicated. This allows pivot_root to not be treated as
75875+ a chroot
75876+ */
75877+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
75878+
75879 return 0;
75880 }
75881
75882@@ -1197,10 +1247,13 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75883 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
75884 #endif
75885 retval = -EAGAIN;
75886+
75887+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
75888+
75889 if (atomic_read(&p->real_cred->user->processes) >=
75890 task_rlimit(p, RLIMIT_NPROC)) {
75891- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
75892- p->real_cred->user != INIT_USER)
75893+ if (p->real_cred->user != INIT_USER &&
75894+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
75895 goto bad_fork_free;
75896 }
75897 current->flags &= ~PF_NPROC_EXCEEDED;
75898@@ -1446,6 +1499,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75899 goto bad_fork_free_pid;
75900 }
75901
75902+ /* synchronizes with gr_set_acls()
75903+ we need to call this past the point of no return for fork()
75904+ */
75905+ gr_copy_label(p);
75906+
75907 if (clone_flags & CLONE_THREAD) {
75908 current->signal->nr_threads++;
75909 atomic_inc(&current->signal->live);
75910@@ -1529,6 +1587,8 @@ bad_fork_cleanup_count:
75911 bad_fork_free:
75912 free_task(p);
75913 fork_out:
75914+ gr_log_forkfail(retval);
75915+
75916 return ERR_PTR(retval);
75917 }
75918
75919@@ -1579,6 +1639,23 @@ long do_fork(unsigned long clone_flags,
75920 return -EINVAL;
75921 }
75922
75923+#ifdef CONFIG_GRKERNSEC
75924+ if (clone_flags & CLONE_NEWUSER) {
75925+ /*
75926+ * This doesn't really inspire confidence:
75927+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
75928+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
75929+ * Increases kernel attack surface in areas developers
75930+ * previously cared little about ("low importance due
75931+ * to requiring "root" capability")
75932+ * To be removed when this code receives *proper* review
75933+ */
75934+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
75935+ !capable(CAP_SETGID))
75936+ return -EPERM;
75937+ }
75938+#endif
75939+
75940 /*
75941 * Determine whether and which event to report to ptracer. When
75942 * called from kernel_thread or CLONE_UNTRACED is explicitly
75943@@ -1613,6 +1690,8 @@ long do_fork(unsigned long clone_flags,
75944 if (clone_flags & CLONE_PARENT_SETTID)
75945 put_user(nr, parent_tidptr);
75946
75947+ gr_handle_brute_check();
75948+
75949 if (clone_flags & CLONE_VFORK) {
75950 p->vfork_done = &vfork;
75951 init_completion(&vfork);
75952@@ -1763,7 +1842,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
75953 return 0;
75954
75955 /* don't need lock here; in the worst case we'll do useless copy */
75956- if (fs->users == 1)
75957+ if (atomic_read(&fs->users) == 1)
75958 return 0;
75959
75960 *new_fsp = copy_fs_struct(fs);
75961@@ -1875,7 +1954,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
75962 fs = current->fs;
75963 spin_lock(&fs->lock);
75964 current->fs = new_fs;
75965- if (--fs->users)
75966+ gr_set_chroot_entries(current, &current->fs->root);
75967+ if (atomic_dec_return(&fs->users))
75968 new_fs = NULL;
75969 else
75970 new_fs = fs;
75971diff --git a/kernel/futex.c b/kernel/futex.c
75972index 49dacfb..5c6b450 100644
75973--- a/kernel/futex.c
75974+++ b/kernel/futex.c
75975@@ -54,6 +54,7 @@
75976 #include <linux/mount.h>
75977 #include <linux/pagemap.h>
75978 #include <linux/syscalls.h>
75979+#include <linux/ptrace.h>
75980 #include <linux/signal.h>
75981 #include <linux/export.h>
75982 #include <linux/magic.h>
75983@@ -242,6 +243,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
75984 struct page *page, *page_head;
75985 int err, ro = 0;
75986
75987+#ifdef CONFIG_PAX_SEGMEXEC
75988+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
75989+ return -EFAULT;
75990+#endif
75991+
75992 /*
75993 * The futex address must be "naturally" aligned.
75994 */
75995@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
75996 {
75997 u32 curval;
75998 int i;
75999+ mm_segment_t oldfs;
76000
76001 /*
76002 * This will fail and we want it. Some arch implementations do
76003@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
76004 * implementation, the non-functional ones will return
76005 * -ENOSYS.
76006 */
76007+ oldfs = get_fs();
76008+ set_fs(USER_DS);
76009 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
76010 futex_cmpxchg_enabled = 1;
76011+ set_fs(oldfs);
76012
76013 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
76014 plist_head_init(&futex_queues[i].chain);
76015diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
76016index f9f44fd..29885e4 100644
76017--- a/kernel/futex_compat.c
76018+++ b/kernel/futex_compat.c
76019@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
76020 return 0;
76021 }
76022
76023-static void __user *futex_uaddr(struct robust_list __user *entry,
76024+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
76025 compat_long_t futex_offset)
76026 {
76027 compat_uptr_t base = ptr_to_compat(entry);
76028diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
76029index 9b22d03..6295b62 100644
76030--- a/kernel/gcov/base.c
76031+++ b/kernel/gcov/base.c
76032@@ -102,11 +102,6 @@ void gcov_enable_events(void)
76033 }
76034
76035 #ifdef CONFIG_MODULES
76036-static inline int within(void *addr, void *start, unsigned long size)
76037-{
76038- return ((addr >= start) && (addr < start + size));
76039-}
76040-
76041 /* Update list and generate events when modules are unloaded. */
76042 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
76043 void *data)
76044@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
76045 prev = NULL;
76046 /* Remove entries located in module from linked list. */
76047 for (info = gcov_info_head; info; info = info->next) {
76048- if (within(info, mod->module_core, mod->core_size)) {
76049+ if (within_module_core_rw((unsigned long)info, mod)) {
76050 if (prev)
76051 prev->next = info->next;
76052 else
76053diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
76054index fd4b13b..09a5ccb 100644
76055--- a/kernel/hrtimer.c
76056+++ b/kernel/hrtimer.c
76057@@ -1430,7 +1430,7 @@ void hrtimer_peek_ahead_timers(void)
76058 local_irq_restore(flags);
76059 }
76060
76061-static void run_hrtimer_softirq(struct softirq_action *h)
76062+static void run_hrtimer_softirq(void)
76063 {
76064 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
76065
76066@@ -1772,7 +1772,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
76067 return NOTIFY_OK;
76068 }
76069
76070-static struct notifier_block __cpuinitdata hrtimers_nb = {
76071+static struct notifier_block hrtimers_nb = {
76072 .notifier_call = hrtimer_cpu_notify,
76073 };
76074
76075diff --git a/kernel/irq_work.c b/kernel/irq_work.c
76076index 55fcce6..0e4cf34 100644
76077--- a/kernel/irq_work.c
76078+++ b/kernel/irq_work.c
76079@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
76080 return NOTIFY_OK;
76081 }
76082
76083-static struct notifier_block cpu_notify;
76084+static struct notifier_block cpu_notify = {
76085+ .notifier_call = irq_work_cpu_notify,
76086+ .priority = 0,
76087+};
76088
76089 static __init int irq_work_init_cpu_notifier(void)
76090 {
76091- cpu_notify.notifier_call = irq_work_cpu_notify;
76092- cpu_notify.priority = 0;
76093 register_cpu_notifier(&cpu_notify);
76094 return 0;
76095 }
76096diff --git a/kernel/jump_label.c b/kernel/jump_label.c
76097index 60f48fa..7f3a770 100644
76098--- a/kernel/jump_label.c
76099+++ b/kernel/jump_label.c
76100@@ -13,6 +13,7 @@
76101 #include <linux/sort.h>
76102 #include <linux/err.h>
76103 #include <linux/static_key.h>
76104+#include <linux/mm.h>
76105
76106 #ifdef HAVE_JUMP_LABEL
76107
76108@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
76109
76110 size = (((unsigned long)stop - (unsigned long)start)
76111 / sizeof(struct jump_entry));
76112+ pax_open_kernel();
76113 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
76114+ pax_close_kernel();
76115 }
76116
76117 static void jump_label_update(struct static_key *key, int enable);
76118@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
76119 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
76120 struct jump_entry *iter;
76121
76122+ pax_open_kernel();
76123 for (iter = iter_start; iter < iter_stop; iter++) {
76124 if (within_module_init(iter->code, mod))
76125 iter->code = 0;
76126 }
76127+ pax_close_kernel();
76128 }
76129
76130 static int
76131diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
76132index 3127ad5..159d880 100644
76133--- a/kernel/kallsyms.c
76134+++ b/kernel/kallsyms.c
76135@@ -11,6 +11,9 @@
76136 * Changed the compression method from stem compression to "table lookup"
76137 * compression (see scripts/kallsyms.c for a more complete description)
76138 */
76139+#ifdef CONFIG_GRKERNSEC_HIDESYM
76140+#define __INCLUDED_BY_HIDESYM 1
76141+#endif
76142 #include <linux/kallsyms.h>
76143 #include <linux/module.h>
76144 #include <linux/init.h>
76145@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
76146
76147 static inline int is_kernel_inittext(unsigned long addr)
76148 {
76149+ if (system_state != SYSTEM_BOOTING)
76150+ return 0;
76151+
76152 if (addr >= (unsigned long)_sinittext
76153 && addr <= (unsigned long)_einittext)
76154 return 1;
76155 return 0;
76156 }
76157
76158+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76159+#ifdef CONFIG_MODULES
76160+static inline int is_module_text(unsigned long addr)
76161+{
76162+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
76163+ return 1;
76164+
76165+ addr = ktla_ktva(addr);
76166+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
76167+}
76168+#else
76169+static inline int is_module_text(unsigned long addr)
76170+{
76171+ return 0;
76172+}
76173+#endif
76174+#endif
76175+
76176 static inline int is_kernel_text(unsigned long addr)
76177 {
76178 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
76179@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
76180
76181 static inline int is_kernel(unsigned long addr)
76182 {
76183+
76184+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76185+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
76186+ return 1;
76187+
76188+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
76189+#else
76190 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
76191+#endif
76192+
76193 return 1;
76194 return in_gate_area_no_mm(addr);
76195 }
76196
76197 static int is_ksym_addr(unsigned long addr)
76198 {
76199+
76200+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76201+ if (is_module_text(addr))
76202+ return 0;
76203+#endif
76204+
76205 if (all_var)
76206 return is_kernel(addr);
76207
76208@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
76209
76210 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
76211 {
76212- iter->name[0] = '\0';
76213 iter->nameoff = get_symbol_offset(new_pos);
76214 iter->pos = new_pos;
76215 }
76216@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
76217 {
76218 struct kallsym_iter *iter = m->private;
76219
76220+#ifdef CONFIG_GRKERNSEC_HIDESYM
76221+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
76222+ return 0;
76223+#endif
76224+
76225 /* Some debugging symbols have no name. Ignore them. */
76226 if (!iter->name[0])
76227 return 0;
76228@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
76229 */
76230 type = iter->exported ? toupper(iter->type) :
76231 tolower(iter->type);
76232+
76233 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
76234 type, iter->name, iter->module_name);
76235 } else
76236@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
76237 struct kallsym_iter *iter;
76238 int ret;
76239
76240- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
76241+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
76242 if (!iter)
76243 return -ENOMEM;
76244 reset_iter(iter, 0);
76245diff --git a/kernel/kcmp.c b/kernel/kcmp.c
76246index e30ac0f..3528cac 100644
76247--- a/kernel/kcmp.c
76248+++ b/kernel/kcmp.c
76249@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
76250 struct task_struct *task1, *task2;
76251 int ret;
76252
76253+#ifdef CONFIG_GRKERNSEC
76254+ return -ENOSYS;
76255+#endif
76256+
76257 rcu_read_lock();
76258
76259 /*
76260diff --git a/kernel/kexec.c b/kernel/kexec.c
76261index 59f7b55..4022f65 100644
76262--- a/kernel/kexec.c
76263+++ b/kernel/kexec.c
76264@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
76265 unsigned long flags)
76266 {
76267 struct compat_kexec_segment in;
76268- struct kexec_segment out, __user *ksegments;
76269+ struct kexec_segment out;
76270+ struct kexec_segment __user *ksegments;
76271 unsigned long i, result;
76272
76273 /* Don't allow clients that don't understand the native
76274diff --git a/kernel/kmod.c b/kernel/kmod.c
76275index 8241906..d625f2c 100644
76276--- a/kernel/kmod.c
76277+++ b/kernel/kmod.c
76278@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
76279 kfree(info->argv);
76280 }
76281
76282-static int call_modprobe(char *module_name, int wait)
76283+static int call_modprobe(char *module_name, char *module_param, int wait)
76284 {
76285 struct subprocess_info *info;
76286 static char *envp[] = {
76287@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
76288 NULL
76289 };
76290
76291- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
76292+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
76293 if (!argv)
76294 goto out;
76295
76296@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
76297 argv[1] = "-q";
76298 argv[2] = "--";
76299 argv[3] = module_name; /* check free_modprobe_argv() */
76300- argv[4] = NULL;
76301+ argv[4] = module_param;
76302+ argv[5] = NULL;
76303
76304 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
76305 NULL, free_modprobe_argv, NULL);
76306@@ -129,9 +130,8 @@ out:
76307 * If module auto-loading support is disabled then this function
76308 * becomes a no-operation.
76309 */
76310-int __request_module(bool wait, const char *fmt, ...)
76311+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
76312 {
76313- va_list args;
76314 char module_name[MODULE_NAME_LEN];
76315 unsigned int max_modprobes;
76316 int ret;
76317@@ -147,9 +147,7 @@ int __request_module(bool wait, const char *fmt, ...)
76318 */
76319 WARN_ON_ONCE(wait && current_is_async());
76320
76321- va_start(args, fmt);
76322- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
76323- va_end(args);
76324+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
76325 if (ret >= MODULE_NAME_LEN)
76326 return -ENAMETOOLONG;
76327
76328@@ -157,6 +155,20 @@ int __request_module(bool wait, const char *fmt, ...)
76329 if (ret)
76330 return ret;
76331
76332+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76333+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
76334+ /* hack to workaround consolekit/udisks stupidity */
76335+ read_lock(&tasklist_lock);
76336+ if (!strcmp(current->comm, "mount") &&
76337+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
76338+ read_unlock(&tasklist_lock);
76339+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
76340+ return -EPERM;
76341+ }
76342+ read_unlock(&tasklist_lock);
76343+ }
76344+#endif
76345+
76346 /* If modprobe needs a service that is in a module, we get a recursive
76347 * loop. Limit the number of running kmod threads to max_threads/2 or
76348 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
76349@@ -185,11 +197,52 @@ int __request_module(bool wait, const char *fmt, ...)
76350
76351 trace_module_request(module_name, wait, _RET_IP_);
76352
76353- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
76354+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
76355
76356 atomic_dec(&kmod_concurrent);
76357 return ret;
76358 }
76359+
76360+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
76361+{
76362+ va_list args;
76363+ int ret;
76364+
76365+ va_start(args, fmt);
76366+ ret = ____request_module(wait, module_param, fmt, args);
76367+ va_end(args);
76368+
76369+ return ret;
76370+}
76371+
76372+int __request_module(bool wait, const char *fmt, ...)
76373+{
76374+ va_list args;
76375+ int ret;
76376+
76377+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76378+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
76379+ char module_param[MODULE_NAME_LEN];
76380+
76381+ memset(module_param, 0, sizeof(module_param));
76382+
76383+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
76384+
76385+ va_start(args, fmt);
76386+ ret = ____request_module(wait, module_param, fmt, args);
76387+ va_end(args);
76388+
76389+ return ret;
76390+ }
76391+#endif
76392+
76393+ va_start(args, fmt);
76394+ ret = ____request_module(wait, NULL, fmt, args);
76395+ va_end(args);
76396+
76397+ return ret;
76398+}
76399+
76400 EXPORT_SYMBOL(__request_module);
76401 #endif /* CONFIG_MODULES */
76402
76403@@ -300,7 +353,7 @@ static int wait_for_helper(void *data)
76404 *
76405 * Thus the __user pointer cast is valid here.
76406 */
76407- sys_wait4(pid, (int __user *)&ret, 0, NULL);
76408+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
76409
76410 /*
76411 * If ret is 0, either ____call_usermodehelper failed and the
76412@@ -651,7 +704,7 @@ EXPORT_SYMBOL(call_usermodehelper);
76413 static int proc_cap_handler(struct ctl_table *table, int write,
76414 void __user *buffer, size_t *lenp, loff_t *ppos)
76415 {
76416- struct ctl_table t;
76417+ ctl_table_no_const t;
76418 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
76419 kernel_cap_t new_cap;
76420 int err, i;
76421diff --git a/kernel/kprobes.c b/kernel/kprobes.c
76422index bddf3b2..07b90dd 100644
76423--- a/kernel/kprobes.c
76424+++ b/kernel/kprobes.c
76425@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
76426 * kernel image and loaded module images reside. This is required
76427 * so x86_64 can correctly handle the %rip-relative fixups.
76428 */
76429- kip->insns = module_alloc(PAGE_SIZE);
76430+ kip->insns = module_alloc_exec(PAGE_SIZE);
76431 if (!kip->insns) {
76432 kfree(kip);
76433 return NULL;
76434@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
76435 */
76436 if (!list_is_singular(&kip->list)) {
76437 list_del(&kip->list);
76438- module_free(NULL, kip->insns);
76439+ module_free_exec(NULL, kip->insns);
76440 kfree(kip);
76441 }
76442 return 1;
76443@@ -2083,7 +2083,7 @@ static int __init init_kprobes(void)
76444 {
76445 int i, err = 0;
76446 unsigned long offset = 0, size = 0;
76447- char *modname, namebuf[128];
76448+ char *modname, namebuf[KSYM_NAME_LEN];
76449 const char *symbol_name;
76450 void *addr;
76451 struct kprobe_blackpoint *kb;
76452@@ -2168,11 +2168,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
76453 kprobe_type = "k";
76454
76455 if (sym)
76456- seq_printf(pi, "%p %s %s+0x%x %s ",
76457+ seq_printf(pi, "%pK %s %s+0x%x %s ",
76458 p->addr, kprobe_type, sym, offset,
76459 (modname ? modname : " "));
76460 else
76461- seq_printf(pi, "%p %s %p ",
76462+ seq_printf(pi, "%pK %s %pK ",
76463 p->addr, kprobe_type, p->addr);
76464
76465 if (!pp)
76466@@ -2209,7 +2209,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
76467 const char *sym = NULL;
76468 unsigned int i = *(loff_t *) v;
76469 unsigned long offset = 0;
76470- char *modname, namebuf[128];
76471+ char *modname, namebuf[KSYM_NAME_LEN];
76472
76473 head = &kprobe_table[i];
76474 preempt_disable();
76475diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
76476index 6ada93c..dce7d5d 100644
76477--- a/kernel/ksysfs.c
76478+++ b/kernel/ksysfs.c
76479@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
76480 {
76481 if (count+1 > UEVENT_HELPER_PATH_LEN)
76482 return -ENOENT;
76483+ if (!capable(CAP_SYS_ADMIN))
76484+ return -EPERM;
76485 memcpy(uevent_helper, buf, count);
76486 uevent_helper[count] = '\0';
76487 if (count && uevent_helper[count-1] == '\n')
76488@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
76489 return count;
76490 }
76491
76492-static struct bin_attribute notes_attr = {
76493+static bin_attribute_no_const notes_attr __read_only = {
76494 .attr = {
76495 .name = "notes",
76496 .mode = S_IRUGO,
76497diff --git a/kernel/lockdep.c b/kernel/lockdep.c
76498index 1f3186b..bb7dbc6 100644
76499--- a/kernel/lockdep.c
76500+++ b/kernel/lockdep.c
76501@@ -596,6 +596,10 @@ static int static_obj(void *obj)
76502 end = (unsigned long) &_end,
76503 addr = (unsigned long) obj;
76504
76505+#ifdef CONFIG_PAX_KERNEXEC
76506+ start = ktla_ktva(start);
76507+#endif
76508+
76509 /*
76510 * static variable?
76511 */
76512@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
76513 if (!static_obj(lock->key)) {
76514 debug_locks_off();
76515 printk("INFO: trying to register non-static key.\n");
76516+ printk("lock:%pS key:%pS.\n", lock, lock->key);
76517 printk("the code is fine but needs lockdep annotation.\n");
76518 printk("turning off the locking correctness validator.\n");
76519 dump_stack();
76520@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
76521 if (!class)
76522 return 0;
76523 }
76524- atomic_inc((atomic_t *)&class->ops);
76525+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
76526 if (very_verbose(class)) {
76527 printk("\nacquire class [%p] %s", class->key, class->name);
76528 if (class->name_version > 1)
76529diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
76530index b2c71c5..7b88d63 100644
76531--- a/kernel/lockdep_proc.c
76532+++ b/kernel/lockdep_proc.c
76533@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
76534 return 0;
76535 }
76536
76537- seq_printf(m, "%p", class->key);
76538+ seq_printf(m, "%pK", class->key);
76539 #ifdef CONFIG_DEBUG_LOCKDEP
76540 seq_printf(m, " OPS:%8ld", class->ops);
76541 #endif
76542@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
76543
76544 list_for_each_entry(entry, &class->locks_after, entry) {
76545 if (entry->distance == 1) {
76546- seq_printf(m, " -> [%p] ", entry->class->key);
76547+ seq_printf(m, " -> [%pK] ", entry->class->key);
76548 print_name(m, entry->class);
76549 seq_puts(m, "\n");
76550 }
76551@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
76552 if (!class->key)
76553 continue;
76554
76555- seq_printf(m, "[%p] ", class->key);
76556+ seq_printf(m, "[%pK] ", class->key);
76557 print_name(m, class);
76558 seq_puts(m, "\n");
76559 }
76560@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76561 if (!i)
76562 seq_line(m, '-', 40-namelen, namelen);
76563
76564- snprintf(ip, sizeof(ip), "[<%p>]",
76565+ snprintf(ip, sizeof(ip), "[<%pK>]",
76566 (void *)class->contention_point[i]);
76567 seq_printf(m, "%40s %14lu %29s %pS\n",
76568 name, stats->contention_point[i],
76569@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76570 if (!i)
76571 seq_line(m, '-', 40-namelen, namelen);
76572
76573- snprintf(ip, sizeof(ip), "[<%p>]",
76574+ snprintf(ip, sizeof(ip), "[<%pK>]",
76575 (void *)class->contending_point[i]);
76576 seq_printf(m, "%40s %14lu %29s %pS\n",
76577 name, stats->contending_point[i],
76578diff --git a/kernel/module.c b/kernel/module.c
76579index fa53db8..6f17200 100644
76580--- a/kernel/module.c
76581+++ b/kernel/module.c
76582@@ -61,6 +61,7 @@
76583 #include <linux/pfn.h>
76584 #include <linux/bsearch.h>
76585 #include <linux/fips.h>
76586+#include <linux/grsecurity.h>
76587 #include <uapi/linux/module.h>
76588 #include "module-internal.h"
76589
76590@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
76591
76592 /* Bounds of module allocation, for speeding __module_address.
76593 * Protected by module_mutex. */
76594-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
76595+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
76596+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
76597
76598 int register_module_notifier(struct notifier_block * nb)
76599 {
76600@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76601 return true;
76602
76603 list_for_each_entry_rcu(mod, &modules, list) {
76604- struct symsearch arr[] = {
76605+ struct symsearch modarr[] = {
76606 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
76607 NOT_GPL_ONLY, false },
76608 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
76609@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76610 if (mod->state == MODULE_STATE_UNFORMED)
76611 continue;
76612
76613- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
76614+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
76615 return true;
76616 }
76617 return false;
76618@@ -485,7 +487,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
76619 static int percpu_modalloc(struct module *mod,
76620 unsigned long size, unsigned long align)
76621 {
76622- if (align > PAGE_SIZE) {
76623+ if (align-1 >= PAGE_SIZE) {
76624 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
76625 mod->name, align, PAGE_SIZE);
76626 align = PAGE_SIZE;
76627@@ -1089,7 +1091,7 @@ struct module_attribute module_uevent =
76628 static ssize_t show_coresize(struct module_attribute *mattr,
76629 struct module_kobject *mk, char *buffer)
76630 {
76631- return sprintf(buffer, "%u\n", mk->mod->core_size);
76632+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
76633 }
76634
76635 static struct module_attribute modinfo_coresize =
76636@@ -1098,7 +1100,7 @@ static struct module_attribute modinfo_coresize =
76637 static ssize_t show_initsize(struct module_attribute *mattr,
76638 struct module_kobject *mk, char *buffer)
76639 {
76640- return sprintf(buffer, "%u\n", mk->mod->init_size);
76641+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
76642 }
76643
76644 static struct module_attribute modinfo_initsize =
76645@@ -1313,7 +1315,7 @@ resolve_symbol_wait(struct module *mod,
76646 */
76647 #ifdef CONFIG_SYSFS
76648
76649-#ifdef CONFIG_KALLSYMS
76650+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76651 static inline bool sect_empty(const Elf_Shdr *sect)
76652 {
76653 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
76654@@ -1453,7 +1455,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
76655 {
76656 unsigned int notes, loaded, i;
76657 struct module_notes_attrs *notes_attrs;
76658- struct bin_attribute *nattr;
76659+ bin_attribute_no_const *nattr;
76660
76661 /* failed to create section attributes, so can't create notes */
76662 if (!mod->sect_attrs)
76663@@ -1565,7 +1567,7 @@ static void del_usage_links(struct module *mod)
76664 static int module_add_modinfo_attrs(struct module *mod)
76665 {
76666 struct module_attribute *attr;
76667- struct module_attribute *temp_attr;
76668+ module_attribute_no_const *temp_attr;
76669 int error = 0;
76670 int i;
76671
76672@@ -1779,21 +1781,21 @@ static void set_section_ro_nx(void *base,
76673
76674 static void unset_module_core_ro_nx(struct module *mod)
76675 {
76676- set_page_attributes(mod->module_core + mod->core_text_size,
76677- mod->module_core + mod->core_size,
76678+ set_page_attributes(mod->module_core_rw,
76679+ mod->module_core_rw + mod->core_size_rw,
76680 set_memory_x);
76681- set_page_attributes(mod->module_core,
76682- mod->module_core + mod->core_ro_size,
76683+ set_page_attributes(mod->module_core_rx,
76684+ mod->module_core_rx + mod->core_size_rx,
76685 set_memory_rw);
76686 }
76687
76688 static void unset_module_init_ro_nx(struct module *mod)
76689 {
76690- set_page_attributes(mod->module_init + mod->init_text_size,
76691- mod->module_init + mod->init_size,
76692+ set_page_attributes(mod->module_init_rw,
76693+ mod->module_init_rw + mod->init_size_rw,
76694 set_memory_x);
76695- set_page_attributes(mod->module_init,
76696- mod->module_init + mod->init_ro_size,
76697+ set_page_attributes(mod->module_init_rx,
76698+ mod->module_init_rx + mod->init_size_rx,
76699 set_memory_rw);
76700 }
76701
76702@@ -1806,14 +1808,14 @@ void set_all_modules_text_rw(void)
76703 list_for_each_entry_rcu(mod, &modules, list) {
76704 if (mod->state == MODULE_STATE_UNFORMED)
76705 continue;
76706- if ((mod->module_core) && (mod->core_text_size)) {
76707- set_page_attributes(mod->module_core,
76708- mod->module_core + mod->core_text_size,
76709+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76710+ set_page_attributes(mod->module_core_rx,
76711+ mod->module_core_rx + mod->core_size_rx,
76712 set_memory_rw);
76713 }
76714- if ((mod->module_init) && (mod->init_text_size)) {
76715- set_page_attributes(mod->module_init,
76716- mod->module_init + mod->init_text_size,
76717+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76718+ set_page_attributes(mod->module_init_rx,
76719+ mod->module_init_rx + mod->init_size_rx,
76720 set_memory_rw);
76721 }
76722 }
76723@@ -1829,14 +1831,14 @@ void set_all_modules_text_ro(void)
76724 list_for_each_entry_rcu(mod, &modules, list) {
76725 if (mod->state == MODULE_STATE_UNFORMED)
76726 continue;
76727- if ((mod->module_core) && (mod->core_text_size)) {
76728- set_page_attributes(mod->module_core,
76729- mod->module_core + mod->core_text_size,
76730+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76731+ set_page_attributes(mod->module_core_rx,
76732+ mod->module_core_rx + mod->core_size_rx,
76733 set_memory_ro);
76734 }
76735- if ((mod->module_init) && (mod->init_text_size)) {
76736- set_page_attributes(mod->module_init,
76737- mod->module_init + mod->init_text_size,
76738+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76739+ set_page_attributes(mod->module_init_rx,
76740+ mod->module_init_rx + mod->init_size_rx,
76741 set_memory_ro);
76742 }
76743 }
76744@@ -1887,16 +1889,19 @@ static void free_module(struct module *mod)
76745
76746 /* This may be NULL, but that's OK */
76747 unset_module_init_ro_nx(mod);
76748- module_free(mod, mod->module_init);
76749+ module_free(mod, mod->module_init_rw);
76750+ module_free_exec(mod, mod->module_init_rx);
76751 kfree(mod->args);
76752 percpu_modfree(mod);
76753
76754 /* Free lock-classes: */
76755- lockdep_free_key_range(mod->module_core, mod->core_size);
76756+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
76757+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
76758
76759 /* Finally, free the core (containing the module structure) */
76760 unset_module_core_ro_nx(mod);
76761- module_free(mod, mod->module_core);
76762+ module_free_exec(mod, mod->module_core_rx);
76763+ module_free(mod, mod->module_core_rw);
76764
76765 #ifdef CONFIG_MPU
76766 update_protections(current->mm);
76767@@ -1966,9 +1971,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76768 int ret = 0;
76769 const struct kernel_symbol *ksym;
76770
76771+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76772+ int is_fs_load = 0;
76773+ int register_filesystem_found = 0;
76774+ char *p;
76775+
76776+ p = strstr(mod->args, "grsec_modharden_fs");
76777+ if (p) {
76778+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
76779+ /* copy \0 as well */
76780+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
76781+ is_fs_load = 1;
76782+ }
76783+#endif
76784+
76785 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
76786 const char *name = info->strtab + sym[i].st_name;
76787
76788+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76789+ /* it's a real shame this will never get ripped and copied
76790+ upstream! ;(
76791+ */
76792+ if (is_fs_load && !strcmp(name, "register_filesystem"))
76793+ register_filesystem_found = 1;
76794+#endif
76795+
76796 switch (sym[i].st_shndx) {
76797 case SHN_COMMON:
76798 /* We compiled with -fno-common. These are not
76799@@ -1989,7 +2016,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76800 ksym = resolve_symbol_wait(mod, info, name);
76801 /* Ok if resolved. */
76802 if (ksym && !IS_ERR(ksym)) {
76803+ pax_open_kernel();
76804 sym[i].st_value = ksym->value;
76805+ pax_close_kernel();
76806 break;
76807 }
76808
76809@@ -2008,11 +2037,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76810 secbase = (unsigned long)mod_percpu(mod);
76811 else
76812 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
76813+ pax_open_kernel();
76814 sym[i].st_value += secbase;
76815+ pax_close_kernel();
76816 break;
76817 }
76818 }
76819
76820+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76821+ if (is_fs_load && !register_filesystem_found) {
76822+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
76823+ ret = -EPERM;
76824+ }
76825+#endif
76826+
76827 return ret;
76828 }
76829
76830@@ -2096,22 +2134,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
76831 || s->sh_entsize != ~0UL
76832 || strstarts(sname, ".init"))
76833 continue;
76834- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
76835+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76836+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
76837+ else
76838+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
76839 pr_debug("\t%s\n", sname);
76840 }
76841- switch (m) {
76842- case 0: /* executable */
76843- mod->core_size = debug_align(mod->core_size);
76844- mod->core_text_size = mod->core_size;
76845- break;
76846- case 1: /* RO: text and ro-data */
76847- mod->core_size = debug_align(mod->core_size);
76848- mod->core_ro_size = mod->core_size;
76849- break;
76850- case 3: /* whole core */
76851- mod->core_size = debug_align(mod->core_size);
76852- break;
76853- }
76854 }
76855
76856 pr_debug("Init section allocation order:\n");
76857@@ -2125,23 +2153,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
76858 || s->sh_entsize != ~0UL
76859 || !strstarts(sname, ".init"))
76860 continue;
76861- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
76862- | INIT_OFFSET_MASK);
76863+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76864+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
76865+ else
76866+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
76867+ s->sh_entsize |= INIT_OFFSET_MASK;
76868 pr_debug("\t%s\n", sname);
76869 }
76870- switch (m) {
76871- case 0: /* executable */
76872- mod->init_size = debug_align(mod->init_size);
76873- mod->init_text_size = mod->init_size;
76874- break;
76875- case 1: /* RO: text and ro-data */
76876- mod->init_size = debug_align(mod->init_size);
76877- mod->init_ro_size = mod->init_size;
76878- break;
76879- case 3: /* whole init */
76880- mod->init_size = debug_align(mod->init_size);
76881- break;
76882- }
76883 }
76884 }
76885
76886@@ -2314,7 +2332,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76887
76888 /* Put symbol section at end of init part of module. */
76889 symsect->sh_flags |= SHF_ALLOC;
76890- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
76891+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
76892 info->index.sym) | INIT_OFFSET_MASK;
76893 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
76894
76895@@ -2331,13 +2349,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76896 }
76897
76898 /* Append room for core symbols at end of core part. */
76899- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
76900- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
76901- mod->core_size += strtab_size;
76902+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
76903+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
76904+ mod->core_size_rx += strtab_size;
76905
76906 /* Put string table section at end of init part of module. */
76907 strsect->sh_flags |= SHF_ALLOC;
76908- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
76909+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
76910 info->index.str) | INIT_OFFSET_MASK;
76911 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
76912 }
76913@@ -2355,12 +2373,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76914 /* Make sure we get permanent strtab: don't use info->strtab. */
76915 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
76916
76917+ pax_open_kernel();
76918+
76919 /* Set types up while we still have access to sections. */
76920 for (i = 0; i < mod->num_symtab; i++)
76921 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
76922
76923- mod->core_symtab = dst = mod->module_core + info->symoffs;
76924- mod->core_strtab = s = mod->module_core + info->stroffs;
76925+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
76926+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
76927 src = mod->symtab;
76928 for (ndst = i = 0; i < mod->num_symtab; i++) {
76929 if (i == 0 ||
76930@@ -2372,6 +2392,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76931 }
76932 }
76933 mod->core_num_syms = ndst;
76934+
76935+ pax_close_kernel();
76936 }
76937 #else
76938 static inline void layout_symtab(struct module *mod, struct load_info *info)
76939@@ -2405,17 +2427,33 @@ void * __weak module_alloc(unsigned long size)
76940 return vmalloc_exec(size);
76941 }
76942
76943-static void *module_alloc_update_bounds(unsigned long size)
76944+static void *module_alloc_update_bounds_rw(unsigned long size)
76945 {
76946 void *ret = module_alloc(size);
76947
76948 if (ret) {
76949 mutex_lock(&module_mutex);
76950 /* Update module bounds. */
76951- if ((unsigned long)ret < module_addr_min)
76952- module_addr_min = (unsigned long)ret;
76953- if ((unsigned long)ret + size > module_addr_max)
76954- module_addr_max = (unsigned long)ret + size;
76955+ if ((unsigned long)ret < module_addr_min_rw)
76956+ module_addr_min_rw = (unsigned long)ret;
76957+ if ((unsigned long)ret + size > module_addr_max_rw)
76958+ module_addr_max_rw = (unsigned long)ret + size;
76959+ mutex_unlock(&module_mutex);
76960+ }
76961+ return ret;
76962+}
76963+
76964+static void *module_alloc_update_bounds_rx(unsigned long size)
76965+{
76966+ void *ret = module_alloc_exec(size);
76967+
76968+ if (ret) {
76969+ mutex_lock(&module_mutex);
76970+ /* Update module bounds. */
76971+ if ((unsigned long)ret < module_addr_min_rx)
76972+ module_addr_min_rx = (unsigned long)ret;
76973+ if ((unsigned long)ret + size > module_addr_max_rx)
76974+ module_addr_max_rx = (unsigned long)ret + size;
76975 mutex_unlock(&module_mutex);
76976 }
76977 return ret;
76978@@ -2691,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
76979 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76980 {
76981 const char *modmagic = get_modinfo(info, "vermagic");
76982+ const char *license = get_modinfo(info, "license");
76983 int err;
76984
76985+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
76986+ if (!license || !license_is_gpl_compatible(license))
76987+ return -ENOEXEC;
76988+#endif
76989+
76990 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
76991 modmagic = NULL;
76992
76993@@ -2718,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76994 }
76995
76996 /* Set up license info based on the info section */
76997- set_license(mod, get_modinfo(info, "license"));
76998+ set_license(mod, license);
76999
77000 return 0;
77001 }
77002@@ -2799,7 +2843,7 @@ static int move_module(struct module *mod, struct load_info *info)
77003 void *ptr;
77004
77005 /* Do the allocs. */
77006- ptr = module_alloc_update_bounds(mod->core_size);
77007+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
77008 /*
77009 * The pointer to this block is stored in the module structure
77010 * which is inside the block. Just mark it as not being a
77011@@ -2809,11 +2853,11 @@ static int move_module(struct module *mod, struct load_info *info)
77012 if (!ptr)
77013 return -ENOMEM;
77014
77015- memset(ptr, 0, mod->core_size);
77016- mod->module_core = ptr;
77017+ memset(ptr, 0, mod->core_size_rw);
77018+ mod->module_core_rw = ptr;
77019
77020- if (mod->init_size) {
77021- ptr = module_alloc_update_bounds(mod->init_size);
77022+ if (mod->init_size_rw) {
77023+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
77024 /*
77025 * The pointer to this block is stored in the module structure
77026 * which is inside the block. This block doesn't need to be
77027@@ -2822,13 +2866,45 @@ static int move_module(struct module *mod, struct load_info *info)
77028 */
77029 kmemleak_ignore(ptr);
77030 if (!ptr) {
77031- module_free(mod, mod->module_core);
77032+ module_free(mod, mod->module_core_rw);
77033 return -ENOMEM;
77034 }
77035- memset(ptr, 0, mod->init_size);
77036- mod->module_init = ptr;
77037+ memset(ptr, 0, mod->init_size_rw);
77038+ mod->module_init_rw = ptr;
77039 } else
77040- mod->module_init = NULL;
77041+ mod->module_init_rw = NULL;
77042+
77043+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
77044+ kmemleak_not_leak(ptr);
77045+ if (!ptr) {
77046+ if (mod->module_init_rw)
77047+ module_free(mod, mod->module_init_rw);
77048+ module_free(mod, mod->module_core_rw);
77049+ return -ENOMEM;
77050+ }
77051+
77052+ pax_open_kernel();
77053+ memset(ptr, 0, mod->core_size_rx);
77054+ pax_close_kernel();
77055+ mod->module_core_rx = ptr;
77056+
77057+ if (mod->init_size_rx) {
77058+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
77059+ kmemleak_ignore(ptr);
77060+ if (!ptr && mod->init_size_rx) {
77061+ module_free_exec(mod, mod->module_core_rx);
77062+ if (mod->module_init_rw)
77063+ module_free(mod, mod->module_init_rw);
77064+ module_free(mod, mod->module_core_rw);
77065+ return -ENOMEM;
77066+ }
77067+
77068+ pax_open_kernel();
77069+ memset(ptr, 0, mod->init_size_rx);
77070+ pax_close_kernel();
77071+ mod->module_init_rx = ptr;
77072+ } else
77073+ mod->module_init_rx = NULL;
77074
77075 /* Transfer each section which specifies SHF_ALLOC */
77076 pr_debug("final section addresses:\n");
77077@@ -2839,16 +2915,45 @@ static int move_module(struct module *mod, struct load_info *info)
77078 if (!(shdr->sh_flags & SHF_ALLOC))
77079 continue;
77080
77081- if (shdr->sh_entsize & INIT_OFFSET_MASK)
77082- dest = mod->module_init
77083- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77084- else
77085- dest = mod->module_core + shdr->sh_entsize;
77086+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
77087+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
77088+ dest = mod->module_init_rw
77089+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77090+ else
77091+ dest = mod->module_init_rx
77092+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77093+ } else {
77094+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
77095+ dest = mod->module_core_rw + shdr->sh_entsize;
77096+ else
77097+ dest = mod->module_core_rx + shdr->sh_entsize;
77098+ }
77099+
77100+ if (shdr->sh_type != SHT_NOBITS) {
77101+
77102+#ifdef CONFIG_PAX_KERNEXEC
77103+#ifdef CONFIG_X86_64
77104+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
77105+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
77106+#endif
77107+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
77108+ pax_open_kernel();
77109+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
77110+ pax_close_kernel();
77111+ } else
77112+#endif
77113
77114- if (shdr->sh_type != SHT_NOBITS)
77115 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
77116+ }
77117 /* Update sh_addr to point to copy in image. */
77118- shdr->sh_addr = (unsigned long)dest;
77119+
77120+#ifdef CONFIG_PAX_KERNEXEC
77121+ if (shdr->sh_flags & SHF_EXECINSTR)
77122+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
77123+ else
77124+#endif
77125+
77126+ shdr->sh_addr = (unsigned long)dest;
77127 pr_debug("\t0x%lx %s\n",
77128 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
77129 }
77130@@ -2905,12 +3010,12 @@ static void flush_module_icache(const struct module *mod)
77131 * Do it before processing of module parameters, so the module
77132 * can provide parameter accessor functions of its own.
77133 */
77134- if (mod->module_init)
77135- flush_icache_range((unsigned long)mod->module_init,
77136- (unsigned long)mod->module_init
77137- + mod->init_size);
77138- flush_icache_range((unsigned long)mod->module_core,
77139- (unsigned long)mod->module_core + mod->core_size);
77140+ if (mod->module_init_rx)
77141+ flush_icache_range((unsigned long)mod->module_init_rx,
77142+ (unsigned long)mod->module_init_rx
77143+ + mod->init_size_rx);
77144+ flush_icache_range((unsigned long)mod->module_core_rx,
77145+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
77146
77147 set_fs(old_fs);
77148 }
77149@@ -2977,8 +3082,10 @@ static int alloc_module_percpu(struct module *mod, struct load_info *info)
77150 static void module_deallocate(struct module *mod, struct load_info *info)
77151 {
77152 percpu_modfree(mod);
77153- module_free(mod, mod->module_init);
77154- module_free(mod, mod->module_core);
77155+ module_free_exec(mod, mod->module_init_rx);
77156+ module_free_exec(mod, mod->module_core_rx);
77157+ module_free(mod, mod->module_init_rw);
77158+ module_free(mod, mod->module_core_rw);
77159 }
77160
77161 int __weak module_finalize(const Elf_Ehdr *hdr,
77162@@ -2991,7 +3098,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
77163 static int post_relocation(struct module *mod, const struct load_info *info)
77164 {
77165 /* Sort exception table now relocations are done. */
77166+ pax_open_kernel();
77167 sort_extable(mod->extable, mod->extable + mod->num_exentries);
77168+ pax_close_kernel();
77169
77170 /* Copy relocated percpu area over. */
77171 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
77172@@ -3045,16 +3154,16 @@ static int do_init_module(struct module *mod)
77173 MODULE_STATE_COMING, mod);
77174
77175 /* Set RO and NX regions for core */
77176- set_section_ro_nx(mod->module_core,
77177- mod->core_text_size,
77178- mod->core_ro_size,
77179- mod->core_size);
77180+ set_section_ro_nx(mod->module_core_rx,
77181+ mod->core_size_rx,
77182+ mod->core_size_rx,
77183+ mod->core_size_rx);
77184
77185 /* Set RO and NX regions for init */
77186- set_section_ro_nx(mod->module_init,
77187- mod->init_text_size,
77188- mod->init_ro_size,
77189- mod->init_size);
77190+ set_section_ro_nx(mod->module_init_rx,
77191+ mod->init_size_rx,
77192+ mod->init_size_rx,
77193+ mod->init_size_rx);
77194
77195 do_mod_ctors(mod);
77196 /* Start the module */
77197@@ -3116,11 +3225,12 @@ static int do_init_module(struct module *mod)
77198 mod->strtab = mod->core_strtab;
77199 #endif
77200 unset_module_init_ro_nx(mod);
77201- module_free(mod, mod->module_init);
77202- mod->module_init = NULL;
77203- mod->init_size = 0;
77204- mod->init_ro_size = 0;
77205- mod->init_text_size = 0;
77206+ module_free(mod, mod->module_init_rw);
77207+ module_free_exec(mod, mod->module_init_rx);
77208+ mod->module_init_rw = NULL;
77209+ mod->module_init_rx = NULL;
77210+ mod->init_size_rw = 0;
77211+ mod->init_size_rx = 0;
77212 mutex_unlock(&module_mutex);
77213 wake_up_all(&module_wq);
77214
77215@@ -3252,9 +3362,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
77216 if (err)
77217 goto free_unload;
77218
77219+ /* Now copy in args */
77220+ mod->args = strndup_user(uargs, ~0UL >> 1);
77221+ if (IS_ERR(mod->args)) {
77222+ err = PTR_ERR(mod->args);
77223+ goto free_unload;
77224+ }
77225+
77226 /* Set up MODINFO_ATTR fields */
77227 setup_modinfo(mod, info);
77228
77229+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77230+ {
77231+ char *p, *p2;
77232+
77233+ if (strstr(mod->args, "grsec_modharden_netdev")) {
77234+ 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);
77235+ err = -EPERM;
77236+ goto free_modinfo;
77237+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
77238+ p += sizeof("grsec_modharden_normal") - 1;
77239+ p2 = strstr(p, "_");
77240+ if (p2) {
77241+ *p2 = '\0';
77242+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
77243+ *p2 = '_';
77244+ }
77245+ err = -EPERM;
77246+ goto free_modinfo;
77247+ }
77248+ }
77249+#endif
77250+
77251 /* Fix up syms, so that st_value is a pointer to location. */
77252 err = simplify_symbols(mod, info);
77253 if (err < 0)
77254@@ -3270,13 +3409,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
77255
77256 flush_module_icache(mod);
77257
77258- /* Now copy in args */
77259- mod->args = strndup_user(uargs, ~0UL >> 1);
77260- if (IS_ERR(mod->args)) {
77261- err = PTR_ERR(mod->args);
77262- goto free_arch_cleanup;
77263- }
77264-
77265 dynamic_debug_setup(info->debug, info->num_debug);
77266
77267 /* Finally it's fully formed, ready to start executing. */
77268@@ -3311,11 +3443,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
77269 ddebug_cleanup:
77270 dynamic_debug_remove(info->debug);
77271 synchronize_sched();
77272- kfree(mod->args);
77273- free_arch_cleanup:
77274 module_arch_cleanup(mod);
77275 free_modinfo:
77276 free_modinfo(mod);
77277+ kfree(mod->args);
77278 free_unload:
77279 module_unload_free(mod);
77280 unlink_mod:
77281@@ -3398,10 +3529,16 @@ static const char *get_ksymbol(struct module *mod,
77282 unsigned long nextval;
77283
77284 /* At worse, next value is at end of module */
77285- if (within_module_init(addr, mod))
77286- nextval = (unsigned long)mod->module_init+mod->init_text_size;
77287+ if (within_module_init_rx(addr, mod))
77288+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
77289+ else if (within_module_init_rw(addr, mod))
77290+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
77291+ else if (within_module_core_rx(addr, mod))
77292+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
77293+ else if (within_module_core_rw(addr, mod))
77294+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
77295 else
77296- nextval = (unsigned long)mod->module_core+mod->core_text_size;
77297+ return NULL;
77298
77299 /* Scan for closest preceding symbol, and next symbol. (ELF
77300 starts real symbols at 1). */
77301@@ -3654,7 +3791,7 @@ static int m_show(struct seq_file *m, void *p)
77302 return 0;
77303
77304 seq_printf(m, "%s %u",
77305- mod->name, mod->init_size + mod->core_size);
77306+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
77307 print_unload_info(m, mod);
77308
77309 /* Informative for users. */
77310@@ -3663,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
77311 mod->state == MODULE_STATE_COMING ? "Loading":
77312 "Live");
77313 /* Used by oprofile and other similar tools. */
77314- seq_printf(m, " 0x%pK", mod->module_core);
77315+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
77316
77317 /* Taints info */
77318 if (mod->taints)
77319@@ -3699,7 +3836,17 @@ static const struct file_operations proc_modules_operations = {
77320
77321 static int __init proc_modules_init(void)
77322 {
77323+#ifndef CONFIG_GRKERNSEC_HIDESYM
77324+#ifdef CONFIG_GRKERNSEC_PROC_USER
77325+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
77326+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77327+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
77328+#else
77329 proc_create("modules", 0, NULL, &proc_modules_operations);
77330+#endif
77331+#else
77332+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
77333+#endif
77334 return 0;
77335 }
77336 module_init(proc_modules_init);
77337@@ -3760,14 +3907,14 @@ struct module *__module_address(unsigned long addr)
77338 {
77339 struct module *mod;
77340
77341- if (addr < module_addr_min || addr > module_addr_max)
77342+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
77343+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
77344 return NULL;
77345
77346 list_for_each_entry_rcu(mod, &modules, list) {
77347 if (mod->state == MODULE_STATE_UNFORMED)
77348 continue;
77349- if (within_module_core(addr, mod)
77350- || within_module_init(addr, mod))
77351+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
77352 return mod;
77353 }
77354 return NULL;
77355@@ -3802,11 +3949,20 @@ bool is_module_text_address(unsigned long addr)
77356 */
77357 struct module *__module_text_address(unsigned long addr)
77358 {
77359- struct module *mod = __module_address(addr);
77360+ struct module *mod;
77361+
77362+#ifdef CONFIG_X86_32
77363+ addr = ktla_ktva(addr);
77364+#endif
77365+
77366+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
77367+ return NULL;
77368+
77369+ mod = __module_address(addr);
77370+
77371 if (mod) {
77372 /* Make sure it's within the text section. */
77373- if (!within(addr, mod->module_init, mod->init_text_size)
77374- && !within(addr, mod->module_core, mod->core_text_size))
77375+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
77376 mod = NULL;
77377 }
77378 return mod;
77379diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
77380index 7e3443f..b2a1e6b 100644
77381--- a/kernel/mutex-debug.c
77382+++ b/kernel/mutex-debug.c
77383@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
77384 }
77385
77386 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77387- struct thread_info *ti)
77388+ struct task_struct *task)
77389 {
77390 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
77391
77392 /* Mark the current thread as blocked on the lock: */
77393- ti->task->blocked_on = waiter;
77394+ task->blocked_on = waiter;
77395 }
77396
77397 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77398- struct thread_info *ti)
77399+ struct task_struct *task)
77400 {
77401 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
77402- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
77403- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
77404- ti->task->blocked_on = NULL;
77405+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
77406+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
77407+ task->blocked_on = NULL;
77408
77409 list_del_init(&waiter->list);
77410 waiter->task = NULL;
77411diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
77412index 0799fd3..d06ae3b 100644
77413--- a/kernel/mutex-debug.h
77414+++ b/kernel/mutex-debug.h
77415@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
77416 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
77417 extern void debug_mutex_add_waiter(struct mutex *lock,
77418 struct mutex_waiter *waiter,
77419- struct thread_info *ti);
77420+ struct task_struct *task);
77421 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77422- struct thread_info *ti);
77423+ struct task_struct *task);
77424 extern void debug_mutex_unlock(struct mutex *lock);
77425 extern void debug_mutex_init(struct mutex *lock, const char *name,
77426 struct lock_class_key *key);
77427diff --git a/kernel/mutex.c b/kernel/mutex.c
77428index ad53a66..f1bf8bc 100644
77429--- a/kernel/mutex.c
77430+++ b/kernel/mutex.c
77431@@ -134,7 +134,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
77432 node->locked = 1;
77433 return;
77434 }
77435- ACCESS_ONCE(prev->next) = node;
77436+ ACCESS_ONCE_RW(prev->next) = node;
77437 smp_wmb();
77438 /* Wait until the lock holder passes the lock down */
77439 while (!ACCESS_ONCE(node->locked))
77440@@ -155,7 +155,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
77441 while (!(next = ACCESS_ONCE(node->next)))
77442 arch_mutex_cpu_relax();
77443 }
77444- ACCESS_ONCE(next->locked) = 1;
77445+ ACCESS_ONCE_RW(next->locked) = 1;
77446 smp_wmb();
77447 }
77448
77449@@ -341,7 +341,7 @@ slowpath:
77450 spin_lock_mutex(&lock->wait_lock, flags);
77451
77452 debug_mutex_lock_common(lock, &waiter);
77453- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
77454+ debug_mutex_add_waiter(lock, &waiter, task);
77455
77456 /* add waiting tasks to the end of the waitqueue (FIFO): */
77457 list_add_tail(&waiter.list, &lock->wait_list);
77458@@ -371,8 +371,7 @@ slowpath:
77459 * TASK_UNINTERRUPTIBLE case.)
77460 */
77461 if (unlikely(signal_pending_state(state, task))) {
77462- mutex_remove_waiter(lock, &waiter,
77463- task_thread_info(task));
77464+ mutex_remove_waiter(lock, &waiter, task);
77465 mutex_release(&lock->dep_map, 1, ip);
77466 spin_unlock_mutex(&lock->wait_lock, flags);
77467
77468@@ -391,7 +390,7 @@ slowpath:
77469 done:
77470 lock_acquired(&lock->dep_map, ip);
77471 /* got the lock - rejoice! */
77472- mutex_remove_waiter(lock, &waiter, current_thread_info());
77473+ mutex_remove_waiter(lock, &waiter, task);
77474 mutex_set_owner(lock);
77475
77476 /* set it to 0 if there are no waiters left: */
77477diff --git a/kernel/notifier.c b/kernel/notifier.c
77478index 2d5cc4c..d9ea600 100644
77479--- a/kernel/notifier.c
77480+++ b/kernel/notifier.c
77481@@ -5,6 +5,7 @@
77482 #include <linux/rcupdate.h>
77483 #include <linux/vmalloc.h>
77484 #include <linux/reboot.h>
77485+#include <linux/mm.h>
77486
77487 /*
77488 * Notifier list for kernel code which wants to be called
77489@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
77490 while ((*nl) != NULL) {
77491 if (n->priority > (*nl)->priority)
77492 break;
77493- nl = &((*nl)->next);
77494+ nl = (struct notifier_block **)&((*nl)->next);
77495 }
77496- n->next = *nl;
77497+ pax_open_kernel();
77498+ *(const void **)&n->next = *nl;
77499 rcu_assign_pointer(*nl, n);
77500+ pax_close_kernel();
77501 return 0;
77502 }
77503
77504@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
77505 return 0;
77506 if (n->priority > (*nl)->priority)
77507 break;
77508- nl = &((*nl)->next);
77509+ nl = (struct notifier_block **)&((*nl)->next);
77510 }
77511- n->next = *nl;
77512+ pax_open_kernel();
77513+ *(const void **)&n->next = *nl;
77514 rcu_assign_pointer(*nl, n);
77515+ pax_close_kernel();
77516 return 0;
77517 }
77518
77519@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
77520 {
77521 while ((*nl) != NULL) {
77522 if ((*nl) == n) {
77523+ pax_open_kernel();
77524 rcu_assign_pointer(*nl, n->next);
77525+ pax_close_kernel();
77526 return 0;
77527 }
77528- nl = &((*nl)->next);
77529+ nl = (struct notifier_block **)&((*nl)->next);
77530 }
77531 return -ENOENT;
77532 }
77533diff --git a/kernel/panic.c b/kernel/panic.c
77534index 167ec09..0dda5f9 100644
77535--- a/kernel/panic.c
77536+++ b/kernel/panic.c
77537@@ -400,7 +400,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
77538 unsigned taint, struct slowpath_args *args)
77539 {
77540 printk(KERN_WARNING "------------[ cut here ]------------\n");
77541- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
77542+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
77543
77544 if (args)
77545 vprintk(args->fmt, args->args);
77546@@ -453,7 +453,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
77547 */
77548 void __stack_chk_fail(void)
77549 {
77550- panic("stack-protector: Kernel stack is corrupted in: %p\n",
77551+ dump_stack();
77552+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
77553 __builtin_return_address(0));
77554 }
77555 EXPORT_SYMBOL(__stack_chk_fail);
77556diff --git a/kernel/pid.c b/kernel/pid.c
77557index 0db3e79..95b9dc2 100644
77558--- a/kernel/pid.c
77559+++ b/kernel/pid.c
77560@@ -33,6 +33,7 @@
77561 #include <linux/rculist.h>
77562 #include <linux/bootmem.h>
77563 #include <linux/hash.h>
77564+#include <linux/security.h>
77565 #include <linux/pid_namespace.h>
77566 #include <linux/init_task.h>
77567 #include <linux/syscalls.h>
77568@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
77569
77570 int pid_max = PID_MAX_DEFAULT;
77571
77572-#define RESERVED_PIDS 300
77573+#define RESERVED_PIDS 500
77574
77575 int pid_max_min = RESERVED_PIDS + 1;
77576 int pid_max_max = PID_MAX_LIMIT;
77577@@ -442,10 +443,18 @@ EXPORT_SYMBOL(pid_task);
77578 */
77579 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
77580 {
77581+ struct task_struct *task;
77582+
77583 rcu_lockdep_assert(rcu_read_lock_held(),
77584 "find_task_by_pid_ns() needs rcu_read_lock()"
77585 " protection");
77586- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77587+
77588+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77589+
77590+ if (gr_pid_is_chrooted(task))
77591+ return NULL;
77592+
77593+ return task;
77594 }
77595
77596 struct task_struct *find_task_by_vpid(pid_t vnr)
77597@@ -453,6 +462,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
77598 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
77599 }
77600
77601+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
77602+{
77603+ rcu_lockdep_assert(rcu_read_lock_held(),
77604+ "find_task_by_pid_ns() needs rcu_read_lock()"
77605+ " protection");
77606+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
77607+}
77608+
77609 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
77610 {
77611 struct pid *pid;
77612diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
77613index 6917e8e..9909aeb 100644
77614--- a/kernel/pid_namespace.c
77615+++ b/kernel/pid_namespace.c
77616@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
77617 void __user *buffer, size_t *lenp, loff_t *ppos)
77618 {
77619 struct pid_namespace *pid_ns = task_active_pid_ns(current);
77620- struct ctl_table tmp = *table;
77621+ ctl_table_no_const tmp = *table;
77622
77623 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
77624 return -EPERM;
77625diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
77626index 42670e9..8719c2f 100644
77627--- a/kernel/posix-cpu-timers.c
77628+++ b/kernel/posix-cpu-timers.c
77629@@ -1636,14 +1636,14 @@ struct k_clock clock_posix_cpu = {
77630
77631 static __init int init_posix_cpu_timers(void)
77632 {
77633- struct k_clock process = {
77634+ static struct k_clock process = {
77635 .clock_getres = process_cpu_clock_getres,
77636 .clock_get = process_cpu_clock_get,
77637 .timer_create = process_cpu_timer_create,
77638 .nsleep = process_cpu_nsleep,
77639 .nsleep_restart = process_cpu_nsleep_restart,
77640 };
77641- struct k_clock thread = {
77642+ static struct k_clock thread = {
77643 .clock_getres = thread_cpu_clock_getres,
77644 .clock_get = thread_cpu_clock_get,
77645 .timer_create = thread_cpu_timer_create,
77646diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
77647index 424c2d4..a9194f7 100644
77648--- a/kernel/posix-timers.c
77649+++ b/kernel/posix-timers.c
77650@@ -43,6 +43,7 @@
77651 #include <linux/hash.h>
77652 #include <linux/posix-clock.h>
77653 #include <linux/posix-timers.h>
77654+#include <linux/grsecurity.h>
77655 #include <linux/syscalls.h>
77656 #include <linux/wait.h>
77657 #include <linux/workqueue.h>
77658@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
77659 * which we beg off on and pass to do_sys_settimeofday().
77660 */
77661
77662-static struct k_clock posix_clocks[MAX_CLOCKS];
77663+static struct k_clock *posix_clocks[MAX_CLOCKS];
77664
77665 /*
77666 * These ones are defined below.
77667@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
77668 */
77669 static __init int init_posix_timers(void)
77670 {
77671- struct k_clock clock_realtime = {
77672+ static struct k_clock clock_realtime = {
77673 .clock_getres = hrtimer_get_res,
77674 .clock_get = posix_clock_realtime_get,
77675 .clock_set = posix_clock_realtime_set,
77676@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
77677 .timer_get = common_timer_get,
77678 .timer_del = common_timer_del,
77679 };
77680- struct k_clock clock_monotonic = {
77681+ static struct k_clock clock_monotonic = {
77682 .clock_getres = hrtimer_get_res,
77683 .clock_get = posix_ktime_get_ts,
77684 .nsleep = common_nsleep,
77685@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
77686 .timer_get = common_timer_get,
77687 .timer_del = common_timer_del,
77688 };
77689- struct k_clock clock_monotonic_raw = {
77690+ static struct k_clock clock_monotonic_raw = {
77691 .clock_getres = hrtimer_get_res,
77692 .clock_get = posix_get_monotonic_raw,
77693 };
77694- struct k_clock clock_realtime_coarse = {
77695+ static struct k_clock clock_realtime_coarse = {
77696 .clock_getres = posix_get_coarse_res,
77697 .clock_get = posix_get_realtime_coarse,
77698 };
77699- struct k_clock clock_monotonic_coarse = {
77700+ static struct k_clock clock_monotonic_coarse = {
77701 .clock_getres = posix_get_coarse_res,
77702 .clock_get = posix_get_monotonic_coarse,
77703 };
77704- struct k_clock clock_tai = {
77705+ static struct k_clock clock_tai = {
77706 .clock_getres = hrtimer_get_res,
77707 .clock_get = posix_get_tai,
77708 .nsleep = common_nsleep,
77709@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
77710 .timer_get = common_timer_get,
77711 .timer_del = common_timer_del,
77712 };
77713- struct k_clock clock_boottime = {
77714+ static struct k_clock clock_boottime = {
77715 .clock_getres = hrtimer_get_res,
77716 .clock_get = posix_get_boottime,
77717 .nsleep = common_nsleep,
77718@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
77719 return;
77720 }
77721
77722- posix_clocks[clock_id] = *new_clock;
77723+ posix_clocks[clock_id] = new_clock;
77724 }
77725 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
77726
77727@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
77728 return (id & CLOCKFD_MASK) == CLOCKFD ?
77729 &clock_posix_dynamic : &clock_posix_cpu;
77730
77731- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
77732+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
77733 return NULL;
77734- return &posix_clocks[id];
77735+ return posix_clocks[id];
77736 }
77737
77738 static int common_timer_create(struct k_itimer *new_timer)
77739@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
77740 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
77741 return -EFAULT;
77742
77743+ /* only the CLOCK_REALTIME clock can be set, all other clocks
77744+ have their clock_set fptr set to a nosettime dummy function
77745+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
77746+ call common_clock_set, which calls do_sys_settimeofday, which
77747+ we hook
77748+ */
77749+
77750 return kc->clock_set(which_clock, &new_tp);
77751 }
77752
77753diff --git a/kernel/power/process.c b/kernel/power/process.c
77754index 98088e0..aaf95c0 100644
77755--- a/kernel/power/process.c
77756+++ b/kernel/power/process.c
77757@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
77758 u64 elapsed_csecs64;
77759 unsigned int elapsed_csecs;
77760 bool wakeup = false;
77761+ bool timedout = false;
77762
77763 do_gettimeofday(&start);
77764
77765@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
77766
77767 while (true) {
77768 todo = 0;
77769+ if (time_after(jiffies, end_time))
77770+ timedout = true;
77771 read_lock(&tasklist_lock);
77772 do_each_thread(g, p) {
77773 if (p == current || !freeze_task(p))
77774 continue;
77775
77776- if (!freezer_should_skip(p))
77777+ if (!freezer_should_skip(p)) {
77778 todo++;
77779+ if (timedout) {
77780+ printk(KERN_ERR "Task refusing to freeze:\n");
77781+ sched_show_task(p);
77782+ }
77783+ }
77784 } while_each_thread(g, p);
77785 read_unlock(&tasklist_lock);
77786
77787@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
77788 todo += wq_busy;
77789 }
77790
77791- if (!todo || time_after(jiffies, end_time))
77792+ if (!todo || timedout)
77793 break;
77794
77795 if (pm_wakeup_pending()) {
77796diff --git a/kernel/printk.c b/kernel/printk.c
77797index 8212c1a..eb61021 100644
77798--- a/kernel/printk.c
77799+++ b/kernel/printk.c
77800@@ -390,6 +390,11 @@ static int check_syslog_permissions(int type, bool from_file)
77801 if (from_file && type != SYSLOG_ACTION_OPEN)
77802 return 0;
77803
77804+#ifdef CONFIG_GRKERNSEC_DMESG
77805+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
77806+ return -EPERM;
77807+#endif
77808+
77809 if (syslog_action_restricted(type)) {
77810 if (capable(CAP_SYSLOG))
77811 return 0;
77812diff --git a/kernel/profile.c b/kernel/profile.c
77813index 0bf4007..6234708 100644
77814--- a/kernel/profile.c
77815+++ b/kernel/profile.c
77816@@ -37,7 +37,7 @@ struct profile_hit {
77817 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
77818 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
77819
77820-static atomic_t *prof_buffer;
77821+static atomic_unchecked_t *prof_buffer;
77822 static unsigned long prof_len, prof_shift;
77823
77824 int prof_on __read_mostly;
77825@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
77826 hits[i].pc = 0;
77827 continue;
77828 }
77829- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77830+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77831 hits[i].hits = hits[i].pc = 0;
77832 }
77833 }
77834@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77835 * Add the current hit(s) and flush the write-queue out
77836 * to the global buffer:
77837 */
77838- atomic_add(nr_hits, &prof_buffer[pc]);
77839+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
77840 for (i = 0; i < NR_PROFILE_HIT; ++i) {
77841- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77842+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77843 hits[i].pc = hits[i].hits = 0;
77844 }
77845 out:
77846@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77847 {
77848 unsigned long pc;
77849 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
77850- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77851+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77852 }
77853 #endif /* !CONFIG_SMP */
77854
77855@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
77856 return -EFAULT;
77857 buf++; p++; count--; read++;
77858 }
77859- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
77860+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
77861 if (copy_to_user(buf, (void *)pnt, count))
77862 return -EFAULT;
77863 read += count;
77864@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
77865 }
77866 #endif
77867 profile_discard_flip_buffers();
77868- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
77869+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
77870 return count;
77871 }
77872
77873diff --git a/kernel/ptrace.c b/kernel/ptrace.c
77874index 335a7ae..3bbbceb 100644
77875--- a/kernel/ptrace.c
77876+++ b/kernel/ptrace.c
77877@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
77878 if (seize)
77879 flags |= PT_SEIZED;
77880 rcu_read_lock();
77881- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77882+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77883 flags |= PT_PTRACE_CAP;
77884 rcu_read_unlock();
77885 task->ptrace = flags;
77886@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
77887 break;
77888 return -EIO;
77889 }
77890- if (copy_to_user(dst, buf, retval))
77891+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
77892 return -EFAULT;
77893 copied += retval;
77894 src += retval;
77895@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
77896 bool seized = child->ptrace & PT_SEIZED;
77897 int ret = -EIO;
77898 siginfo_t siginfo, *si;
77899- void __user *datavp = (void __user *) data;
77900+ void __user *datavp = (__force void __user *) data;
77901 unsigned long __user *datalp = datavp;
77902 unsigned long flags;
77903
77904@@ -1011,14 +1011,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
77905 goto out;
77906 }
77907
77908+ if (gr_handle_ptrace(child, request)) {
77909+ ret = -EPERM;
77910+ goto out_put_task_struct;
77911+ }
77912+
77913 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77914 ret = ptrace_attach(child, request, addr, data);
77915 /*
77916 * Some architectures need to do book-keeping after
77917 * a ptrace attach.
77918 */
77919- if (!ret)
77920+ if (!ret) {
77921 arch_ptrace_attach(child);
77922+ gr_audit_ptrace(child);
77923+ }
77924 goto out_put_task_struct;
77925 }
77926
77927@@ -1046,7 +1053,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
77928 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
77929 if (copied != sizeof(tmp))
77930 return -EIO;
77931- return put_user(tmp, (unsigned long __user *)data);
77932+ return put_user(tmp, (__force unsigned long __user *)data);
77933 }
77934
77935 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
77936@@ -1140,7 +1147,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
77937 }
77938
77939 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77940- compat_long_t addr, compat_long_t data)
77941+ compat_ulong_t addr, compat_ulong_t data)
77942 {
77943 struct task_struct *child;
77944 long ret;
77945@@ -1156,14 +1163,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77946 goto out;
77947 }
77948
77949+ if (gr_handle_ptrace(child, request)) {
77950+ ret = -EPERM;
77951+ goto out_put_task_struct;
77952+ }
77953+
77954 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77955 ret = ptrace_attach(child, request, addr, data);
77956 /*
77957 * Some architectures need to do book-keeping after
77958 * a ptrace attach.
77959 */
77960- if (!ret)
77961+ if (!ret) {
77962 arch_ptrace_attach(child);
77963+ gr_audit_ptrace(child);
77964+ }
77965 goto out_put_task_struct;
77966 }
77967
77968diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
77969index 48ab703..07561d4 100644
77970--- a/kernel/rcupdate.c
77971+++ b/kernel/rcupdate.c
77972@@ -439,10 +439,10 @@ int rcu_jiffies_till_stall_check(void)
77973 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
77974 */
77975 if (till_stall_check < 3) {
77976- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
77977+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
77978 till_stall_check = 3;
77979 } else if (till_stall_check > 300) {
77980- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
77981+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
77982 till_stall_check = 300;
77983 }
77984 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
77985diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
77986index a0714a5..2ab5e34 100644
77987--- a/kernel/rcutiny.c
77988+++ b/kernel/rcutiny.c
77989@@ -46,7 +46,7 @@
77990 struct rcu_ctrlblk;
77991 static void invoke_rcu_callbacks(void);
77992 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
77993-static void rcu_process_callbacks(struct softirq_action *unused);
77994+static void rcu_process_callbacks(void);
77995 static void __call_rcu(struct rcu_head *head,
77996 void (*func)(struct rcu_head *rcu),
77997 struct rcu_ctrlblk *rcp);
77998@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
77999 rcu_is_callbacks_kthread()));
78000 }
78001
78002-static void rcu_process_callbacks(struct softirq_action *unused)
78003+static void rcu_process_callbacks(void)
78004 {
78005 __rcu_process_callbacks(&rcu_sched_ctrlblk);
78006 __rcu_process_callbacks(&rcu_bh_ctrlblk);
78007diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
78008index 8a23300..4255818 100644
78009--- a/kernel/rcutiny_plugin.h
78010+++ b/kernel/rcutiny_plugin.h
78011@@ -945,7 +945,7 @@ static int rcu_kthread(void *arg)
78012 have_rcu_kthread_work = morework;
78013 local_irq_restore(flags);
78014 if (work)
78015- rcu_process_callbacks(NULL);
78016+ rcu_process_callbacks();
78017 schedule_timeout_interruptible(1); /* Leave CPU for others. */
78018 }
78019
78020diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
78021index e1f3a8c..42c94a2 100644
78022--- a/kernel/rcutorture.c
78023+++ b/kernel/rcutorture.c
78024@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
78025 { 0 };
78026 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
78027 { 0 };
78028-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
78029-static atomic_t n_rcu_torture_alloc;
78030-static atomic_t n_rcu_torture_alloc_fail;
78031-static atomic_t n_rcu_torture_free;
78032-static atomic_t n_rcu_torture_mberror;
78033-static atomic_t n_rcu_torture_error;
78034+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
78035+static atomic_unchecked_t n_rcu_torture_alloc;
78036+static atomic_unchecked_t n_rcu_torture_alloc_fail;
78037+static atomic_unchecked_t n_rcu_torture_free;
78038+static atomic_unchecked_t n_rcu_torture_mberror;
78039+static atomic_unchecked_t n_rcu_torture_error;
78040 static long n_rcu_torture_barrier_error;
78041 static long n_rcu_torture_boost_ktrerror;
78042 static long n_rcu_torture_boost_rterror;
78043@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
78044
78045 spin_lock_bh(&rcu_torture_lock);
78046 if (list_empty(&rcu_torture_freelist)) {
78047- atomic_inc(&n_rcu_torture_alloc_fail);
78048+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
78049 spin_unlock_bh(&rcu_torture_lock);
78050 return NULL;
78051 }
78052- atomic_inc(&n_rcu_torture_alloc);
78053+ atomic_inc_unchecked(&n_rcu_torture_alloc);
78054 p = rcu_torture_freelist.next;
78055 list_del_init(p);
78056 spin_unlock_bh(&rcu_torture_lock);
78057@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
78058 static void
78059 rcu_torture_free(struct rcu_torture *p)
78060 {
78061- atomic_inc(&n_rcu_torture_free);
78062+ atomic_inc_unchecked(&n_rcu_torture_free);
78063 spin_lock_bh(&rcu_torture_lock);
78064 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
78065 spin_unlock_bh(&rcu_torture_lock);
78066@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
78067 i = rp->rtort_pipe_count;
78068 if (i > RCU_TORTURE_PIPE_LEN)
78069 i = RCU_TORTURE_PIPE_LEN;
78070- atomic_inc(&rcu_torture_wcount[i]);
78071+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78072 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
78073 rp->rtort_mbtest = 0;
78074 rcu_torture_free(rp);
78075@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
78076 i = rp->rtort_pipe_count;
78077 if (i > RCU_TORTURE_PIPE_LEN)
78078 i = RCU_TORTURE_PIPE_LEN;
78079- atomic_inc(&rcu_torture_wcount[i]);
78080+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78081 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
78082 rp->rtort_mbtest = 0;
78083 list_del(&rp->rtort_free);
78084@@ -990,7 +990,7 @@ rcu_torture_writer(void *arg)
78085 i = old_rp->rtort_pipe_count;
78086 if (i > RCU_TORTURE_PIPE_LEN)
78087 i = RCU_TORTURE_PIPE_LEN;
78088- atomic_inc(&rcu_torture_wcount[i]);
78089+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78090 old_rp->rtort_pipe_count++;
78091 cur_ops->deferred_free(old_rp);
78092 }
78093@@ -1076,7 +1076,7 @@ static void rcu_torture_timer(unsigned long unused)
78094 return;
78095 }
78096 if (p->rtort_mbtest == 0)
78097- atomic_inc(&n_rcu_torture_mberror);
78098+ atomic_inc_unchecked(&n_rcu_torture_mberror);
78099 spin_lock(&rand_lock);
78100 cur_ops->read_delay(&rand);
78101 n_rcu_torture_timers++;
78102@@ -1146,7 +1146,7 @@ rcu_torture_reader(void *arg)
78103 continue;
78104 }
78105 if (p->rtort_mbtest == 0)
78106- atomic_inc(&n_rcu_torture_mberror);
78107+ atomic_inc_unchecked(&n_rcu_torture_mberror);
78108 cur_ops->read_delay(&rand);
78109 preempt_disable();
78110 pipe_count = p->rtort_pipe_count;
78111@@ -1209,11 +1209,11 @@ rcu_torture_printk(char *page)
78112 rcu_torture_current,
78113 rcu_torture_current_version,
78114 list_empty(&rcu_torture_freelist),
78115- atomic_read(&n_rcu_torture_alloc),
78116- atomic_read(&n_rcu_torture_alloc_fail),
78117- atomic_read(&n_rcu_torture_free));
78118+ atomic_read_unchecked(&n_rcu_torture_alloc),
78119+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
78120+ atomic_read_unchecked(&n_rcu_torture_free));
78121 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
78122- atomic_read(&n_rcu_torture_mberror),
78123+ atomic_read_unchecked(&n_rcu_torture_mberror),
78124 n_rcu_torture_boost_ktrerror,
78125 n_rcu_torture_boost_rterror);
78126 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
78127@@ -1232,14 +1232,14 @@ rcu_torture_printk(char *page)
78128 n_barrier_attempts,
78129 n_rcu_torture_barrier_error);
78130 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
78131- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
78132+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
78133 n_rcu_torture_barrier_error != 0 ||
78134 n_rcu_torture_boost_ktrerror != 0 ||
78135 n_rcu_torture_boost_rterror != 0 ||
78136 n_rcu_torture_boost_failure != 0 ||
78137 i > 1) {
78138 cnt += sprintf(&page[cnt], "!!! ");
78139- atomic_inc(&n_rcu_torture_error);
78140+ atomic_inc_unchecked(&n_rcu_torture_error);
78141 WARN_ON_ONCE(1);
78142 }
78143 cnt += sprintf(&page[cnt], "Reader Pipe: ");
78144@@ -1253,7 +1253,7 @@ rcu_torture_printk(char *page)
78145 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
78146 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
78147 cnt += sprintf(&page[cnt], " %d",
78148- atomic_read(&rcu_torture_wcount[i]));
78149+ atomic_read_unchecked(&rcu_torture_wcount[i]));
78150 }
78151 cnt += sprintf(&page[cnt], "\n");
78152 if (cur_ops->stats)
78153@@ -1962,7 +1962,7 @@ rcu_torture_cleanup(void)
78154
78155 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
78156
78157- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
78158+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
78159 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
78160 else if (n_online_successes != n_online_attempts ||
78161 n_offline_successes != n_offline_attempts)
78162@@ -2031,18 +2031,18 @@ rcu_torture_init(void)
78163
78164 rcu_torture_current = NULL;
78165 rcu_torture_current_version = 0;
78166- atomic_set(&n_rcu_torture_alloc, 0);
78167- atomic_set(&n_rcu_torture_alloc_fail, 0);
78168- atomic_set(&n_rcu_torture_free, 0);
78169- atomic_set(&n_rcu_torture_mberror, 0);
78170- atomic_set(&n_rcu_torture_error, 0);
78171+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
78172+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
78173+ atomic_set_unchecked(&n_rcu_torture_free, 0);
78174+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
78175+ atomic_set_unchecked(&n_rcu_torture_error, 0);
78176 n_rcu_torture_barrier_error = 0;
78177 n_rcu_torture_boost_ktrerror = 0;
78178 n_rcu_torture_boost_rterror = 0;
78179 n_rcu_torture_boost_failure = 0;
78180 n_rcu_torture_boosts = 0;
78181 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
78182- atomic_set(&rcu_torture_wcount[i], 0);
78183+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
78184 for_each_possible_cpu(cpu) {
78185 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
78186 per_cpu(rcu_torture_count, cpu)[i] = 0;
78187diff --git a/kernel/rcutree.c b/kernel/rcutree.c
78188index 3538001..e379e0b 100644
78189--- a/kernel/rcutree.c
78190+++ b/kernel/rcutree.c
78191@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
78192 rcu_prepare_for_idle(smp_processor_id());
78193 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78194 smp_mb__before_atomic_inc(); /* See above. */
78195- atomic_inc(&rdtp->dynticks);
78196+ atomic_inc_unchecked(&rdtp->dynticks);
78197 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
78198- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78199+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78200
78201 /*
78202 * It is illegal to enter an extended quiescent state while
78203@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
78204 int user)
78205 {
78206 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
78207- atomic_inc(&rdtp->dynticks);
78208+ atomic_inc_unchecked(&rdtp->dynticks);
78209 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78210 smp_mb__after_atomic_inc(); /* See above. */
78211- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78212+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78213 rcu_cleanup_after_idle(smp_processor_id());
78214 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
78215 if (!user && !is_idle_task(current)) {
78216@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
78217 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
78218
78219 if (rdtp->dynticks_nmi_nesting == 0 &&
78220- (atomic_read(&rdtp->dynticks) & 0x1))
78221+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
78222 return;
78223 rdtp->dynticks_nmi_nesting++;
78224 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
78225- atomic_inc(&rdtp->dynticks);
78226+ atomic_inc_unchecked(&rdtp->dynticks);
78227 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78228 smp_mb__after_atomic_inc(); /* See above. */
78229- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78230+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78231 }
78232
78233 /**
78234@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
78235 return;
78236 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78237 smp_mb__before_atomic_inc(); /* See above. */
78238- atomic_inc(&rdtp->dynticks);
78239+ atomic_inc_unchecked(&rdtp->dynticks);
78240 smp_mb__after_atomic_inc(); /* Force delay to next write. */
78241- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78242+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78243 }
78244
78245 /**
78246@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
78247 int ret;
78248
78249 preempt_disable();
78250- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78251+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78252 preempt_enable();
78253 return ret;
78254 }
78255@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
78256 */
78257 static int dyntick_save_progress_counter(struct rcu_data *rdp)
78258 {
78259- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
78260+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78261 return (rdp->dynticks_snap & 0x1) == 0;
78262 }
78263
78264@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
78265 unsigned int curr;
78266 unsigned int snap;
78267
78268- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
78269+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78270 snap = (unsigned int)rdp->dynticks_snap;
78271
78272 /*
78273@@ -1440,9 +1440,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
78274 rdp = this_cpu_ptr(rsp->rda);
78275 rcu_preempt_check_blocked_tasks(rnp);
78276 rnp->qsmask = rnp->qsmaskinit;
78277- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
78278+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
78279 WARN_ON_ONCE(rnp->completed != rsp->completed);
78280- ACCESS_ONCE(rnp->completed) = rsp->completed;
78281+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
78282 if (rnp == rdp->mynode)
78283 rcu_start_gp_per_cpu(rsp, rnp, rdp);
78284 rcu_preempt_boost_start_gp(rnp);
78285@@ -1524,7 +1524,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
78286 */
78287 rcu_for_each_node_breadth_first(rsp, rnp) {
78288 raw_spin_lock_irq(&rnp->lock);
78289- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
78290+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
78291 rdp = this_cpu_ptr(rsp->rda);
78292 if (rnp == rdp->mynode)
78293 __rcu_process_gp_end(rsp, rnp, rdp);
78294@@ -1855,7 +1855,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
78295 rsp->qlen += rdp->qlen;
78296 rdp->n_cbs_orphaned += rdp->qlen;
78297 rdp->qlen_lazy = 0;
78298- ACCESS_ONCE(rdp->qlen) = 0;
78299+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78300 }
78301
78302 /*
78303@@ -2101,7 +2101,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
78304 }
78305 smp_mb(); /* List handling before counting for rcu_barrier(). */
78306 rdp->qlen_lazy -= count_lazy;
78307- ACCESS_ONCE(rdp->qlen) -= count;
78308+ ACCESS_ONCE_RW(rdp->qlen) -= count;
78309 rdp->n_cbs_invoked += count;
78310
78311 /* Reinstate batch limit if we have worked down the excess. */
78312@@ -2295,7 +2295,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
78313 /*
78314 * Do RCU core processing for the current CPU.
78315 */
78316-static void rcu_process_callbacks(struct softirq_action *unused)
78317+static void rcu_process_callbacks(void)
78318 {
78319 struct rcu_state *rsp;
78320
78321@@ -2419,7 +2419,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
78322 local_irq_restore(flags);
78323 return;
78324 }
78325- ACCESS_ONCE(rdp->qlen)++;
78326+ ACCESS_ONCE_RW(rdp->qlen)++;
78327 if (lazy)
78328 rdp->qlen_lazy++;
78329 else
78330@@ -2628,11 +2628,11 @@ void synchronize_sched_expedited(void)
78331 * counter wrap on a 32-bit system. Quite a few more CPUs would of
78332 * course be required on a 64-bit system.
78333 */
78334- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
78335+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
78336 (ulong)atomic_long_read(&rsp->expedited_done) +
78337 ULONG_MAX / 8)) {
78338 synchronize_sched();
78339- atomic_long_inc(&rsp->expedited_wrap);
78340+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
78341 return;
78342 }
78343
78344@@ -2640,7 +2640,7 @@ void synchronize_sched_expedited(void)
78345 * Take a ticket. Note that atomic_inc_return() implies a
78346 * full memory barrier.
78347 */
78348- snap = atomic_long_inc_return(&rsp->expedited_start);
78349+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
78350 firstsnap = snap;
78351 get_online_cpus();
78352 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
78353@@ -2653,14 +2653,14 @@ void synchronize_sched_expedited(void)
78354 synchronize_sched_expedited_cpu_stop,
78355 NULL) == -EAGAIN) {
78356 put_online_cpus();
78357- atomic_long_inc(&rsp->expedited_tryfail);
78358+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
78359
78360 /* Check to see if someone else did our work for us. */
78361 s = atomic_long_read(&rsp->expedited_done);
78362 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
78363 /* ensure test happens before caller kfree */
78364 smp_mb__before_atomic_inc(); /* ^^^ */
78365- atomic_long_inc(&rsp->expedited_workdone1);
78366+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
78367 return;
78368 }
78369
78370@@ -2669,7 +2669,7 @@ void synchronize_sched_expedited(void)
78371 udelay(trycount * num_online_cpus());
78372 } else {
78373 wait_rcu_gp(call_rcu_sched);
78374- atomic_long_inc(&rsp->expedited_normal);
78375+ atomic_long_inc_unchecked(&rsp->expedited_normal);
78376 return;
78377 }
78378
78379@@ -2678,7 +2678,7 @@ void synchronize_sched_expedited(void)
78380 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
78381 /* ensure test happens before caller kfree */
78382 smp_mb__before_atomic_inc(); /* ^^^ */
78383- atomic_long_inc(&rsp->expedited_workdone2);
78384+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
78385 return;
78386 }
78387
78388@@ -2690,10 +2690,10 @@ void synchronize_sched_expedited(void)
78389 * period works for us.
78390 */
78391 get_online_cpus();
78392- snap = atomic_long_read(&rsp->expedited_start);
78393+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
78394 smp_mb(); /* ensure read is before try_stop_cpus(). */
78395 }
78396- atomic_long_inc(&rsp->expedited_stoppedcpus);
78397+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
78398
78399 /*
78400 * Everyone up to our most recent fetch is covered by our grace
78401@@ -2702,16 +2702,16 @@ void synchronize_sched_expedited(void)
78402 * than we did already did their update.
78403 */
78404 do {
78405- atomic_long_inc(&rsp->expedited_done_tries);
78406+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
78407 s = atomic_long_read(&rsp->expedited_done);
78408 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
78409 /* ensure test happens before caller kfree */
78410 smp_mb__before_atomic_inc(); /* ^^^ */
78411- atomic_long_inc(&rsp->expedited_done_lost);
78412+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
78413 break;
78414 }
78415 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
78416- atomic_long_inc(&rsp->expedited_done_exit);
78417+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
78418
78419 put_online_cpus();
78420 }
78421@@ -2893,7 +2893,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78422 * ACCESS_ONCE() to prevent the compiler from speculating
78423 * the increment to precede the early-exit check.
78424 */
78425- ACCESS_ONCE(rsp->n_barrier_done)++;
78426+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78427 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
78428 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
78429 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
78430@@ -2943,7 +2943,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78431
78432 /* Increment ->n_barrier_done to prevent duplicate work. */
78433 smp_mb(); /* Keep increment after above mechanism. */
78434- ACCESS_ONCE(rsp->n_barrier_done)++;
78435+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78436 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
78437 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
78438 smp_mb(); /* Keep increment before caller's subsequent code. */
78439@@ -2988,10 +2988,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
78440 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
78441 init_callback_list(rdp);
78442 rdp->qlen_lazy = 0;
78443- ACCESS_ONCE(rdp->qlen) = 0;
78444+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78445 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
78446 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
78447- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
78448+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
78449 rdp->cpu = cpu;
78450 rdp->rsp = rsp;
78451 rcu_boot_init_nocb_percpu_data(rdp);
78452@@ -3024,8 +3024,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
78453 rdp->blimit = blimit;
78454 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
78455 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
78456- atomic_set(&rdp->dynticks->dynticks,
78457- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
78458+ atomic_set_unchecked(&rdp->dynticks->dynticks,
78459+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
78460 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
78461
78462 /* Add CPU to rcu_node bitmasks. */
78463@@ -3120,7 +3120,7 @@ static int __init rcu_spawn_gp_kthread(void)
78464 struct task_struct *t;
78465
78466 for_each_rcu_flavor(rsp) {
78467- t = kthread_run(rcu_gp_kthread, rsp, rsp->name);
78468+ t = kthread_run(rcu_gp_kthread, rsp, "%s", rsp->name);
78469 BUG_ON(IS_ERR(t));
78470 rnp = rcu_get_root(rsp);
78471 raw_spin_lock_irqsave(&rnp->lock, flags);
78472diff --git a/kernel/rcutree.h b/kernel/rcutree.h
78473index 4df5034..5ee93f2 100644
78474--- a/kernel/rcutree.h
78475+++ b/kernel/rcutree.h
78476@@ -87,7 +87,7 @@ struct rcu_dynticks {
78477 long long dynticks_nesting; /* Track irq/process nesting level. */
78478 /* Process level is worth LLONG_MAX/2. */
78479 int dynticks_nmi_nesting; /* Track NMI nesting level. */
78480- atomic_t dynticks; /* Even value for idle, else odd. */
78481+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
78482 #ifdef CONFIG_RCU_FAST_NO_HZ
78483 bool all_lazy; /* Are all CPU's CBs lazy? */
78484 unsigned long nonlazy_posted;
78485@@ -414,17 +414,17 @@ struct rcu_state {
78486 /* _rcu_barrier(). */
78487 /* End of fields guarded by barrier_mutex. */
78488
78489- atomic_long_t expedited_start; /* Starting ticket. */
78490- atomic_long_t expedited_done; /* Done ticket. */
78491- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
78492- atomic_long_t expedited_tryfail; /* # acquisition failures. */
78493- atomic_long_t expedited_workdone1; /* # done by others #1. */
78494- atomic_long_t expedited_workdone2; /* # done by others #2. */
78495- atomic_long_t expedited_normal; /* # fallbacks to normal. */
78496- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
78497- atomic_long_t expedited_done_tries; /* # tries to update _done. */
78498- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
78499- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
78500+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
78501+ atomic_long_t expedited_done; /* Done ticket. */
78502+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
78503+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
78504+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
78505+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
78506+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
78507+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
78508+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
78509+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
78510+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
78511
78512 unsigned long jiffies_force_qs; /* Time at which to invoke */
78513 /* force_quiescent_state(). */
78514diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
78515index 3db5a37..b395fb35 100644
78516--- a/kernel/rcutree_plugin.h
78517+++ b/kernel/rcutree_plugin.h
78518@@ -903,7 +903,7 @@ void synchronize_rcu_expedited(void)
78519
78520 /* Clean up and exit. */
78521 smp_mb(); /* ensure expedited GP seen before counter increment. */
78522- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
78523+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
78524 unlock_mb_ret:
78525 mutex_unlock(&sync_rcu_preempt_exp_mutex);
78526 mb_ret:
78527@@ -1451,7 +1451,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
78528 free_cpumask_var(cm);
78529 }
78530
78531-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
78532+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
78533 .store = &rcu_cpu_kthread_task,
78534 .thread_should_run = rcu_cpu_kthread_should_run,
78535 .thread_fn = rcu_cpu_kthread,
78536@@ -1916,7 +1916,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
78537 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
78538 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
78539 cpu, ticks_value, ticks_title,
78540- atomic_read(&rdtp->dynticks) & 0xfff,
78541+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
78542 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
78543 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
78544 fast_no_hz);
78545@@ -2079,7 +2079,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
78546
78547 /* Enqueue the callback on the nocb list and update counts. */
78548 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
78549- ACCESS_ONCE(*old_rhpp) = rhp;
78550+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
78551 atomic_long_add(rhcount, &rdp->nocb_q_count);
78552 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
78553
78554@@ -2219,12 +2219,12 @@ static int rcu_nocb_kthread(void *arg)
78555 * Extract queued callbacks, update counts, and wait
78556 * for a grace period to elapse.
78557 */
78558- ACCESS_ONCE(rdp->nocb_head) = NULL;
78559+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
78560 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
78561 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
78562 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
78563- ACCESS_ONCE(rdp->nocb_p_count) += c;
78564- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
78565+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
78566+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
78567 rcu_nocb_wait_gp(rdp);
78568
78569 /* Each pass through the following loop invokes a callback. */
78570@@ -2246,8 +2246,8 @@ static int rcu_nocb_kthread(void *arg)
78571 list = next;
78572 }
78573 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
78574- ACCESS_ONCE(rdp->nocb_p_count) -= c;
78575- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
78576+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
78577+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
78578 rdp->n_nocbs_invoked += c;
78579 }
78580 return 0;
78581@@ -2274,7 +2274,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
78582 t = kthread_run(rcu_nocb_kthread, rdp,
78583 "rcuo%c/%d", rsp->abbr, cpu);
78584 BUG_ON(IS_ERR(t));
78585- ACCESS_ONCE(rdp->nocb_kthread) = t;
78586+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
78587 }
78588 }
78589
78590diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
78591index cf6c174..a8f4b50 100644
78592--- a/kernel/rcutree_trace.c
78593+++ b/kernel/rcutree_trace.c
78594@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
78595 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
78596 rdp->passed_quiesce, rdp->qs_pending);
78597 seq_printf(m, " dt=%d/%llx/%d df=%lu",
78598- atomic_read(&rdp->dynticks->dynticks),
78599+ atomic_read_unchecked(&rdp->dynticks->dynticks),
78600 rdp->dynticks->dynticks_nesting,
78601 rdp->dynticks->dynticks_nmi_nesting,
78602 rdp->dynticks_fqs);
78603@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
78604 struct rcu_state *rsp = (struct rcu_state *)m->private;
78605
78606 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",
78607- atomic_long_read(&rsp->expedited_start),
78608+ atomic_long_read_unchecked(&rsp->expedited_start),
78609 atomic_long_read(&rsp->expedited_done),
78610- atomic_long_read(&rsp->expedited_wrap),
78611- atomic_long_read(&rsp->expedited_tryfail),
78612- atomic_long_read(&rsp->expedited_workdone1),
78613- atomic_long_read(&rsp->expedited_workdone2),
78614- atomic_long_read(&rsp->expedited_normal),
78615- atomic_long_read(&rsp->expedited_stoppedcpus),
78616- atomic_long_read(&rsp->expedited_done_tries),
78617- atomic_long_read(&rsp->expedited_done_lost),
78618- atomic_long_read(&rsp->expedited_done_exit));
78619+ atomic_long_read_unchecked(&rsp->expedited_wrap),
78620+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
78621+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
78622+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
78623+ atomic_long_read_unchecked(&rsp->expedited_normal),
78624+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
78625+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
78626+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
78627+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
78628 return 0;
78629 }
78630
78631diff --git a/kernel/resource.c b/kernel/resource.c
78632index d738698..5f8e60a 100644
78633--- a/kernel/resource.c
78634+++ b/kernel/resource.c
78635@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
78636
78637 static int __init ioresources_init(void)
78638 {
78639+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78640+#ifdef CONFIG_GRKERNSEC_PROC_USER
78641+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
78642+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
78643+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78644+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
78645+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
78646+#endif
78647+#else
78648 proc_create("ioports", 0, NULL, &proc_ioports_operations);
78649 proc_create("iomem", 0, NULL, &proc_iomem_operations);
78650+#endif
78651 return 0;
78652 }
78653 __initcall(ioresources_init);
78654diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
78655index 1d96dd0..994ff19 100644
78656--- a/kernel/rtmutex-tester.c
78657+++ b/kernel/rtmutex-tester.c
78658@@ -22,7 +22,7 @@
78659 #define MAX_RT_TEST_MUTEXES 8
78660
78661 static spinlock_t rttest_lock;
78662-static atomic_t rttest_event;
78663+static atomic_unchecked_t rttest_event;
78664
78665 struct test_thread_data {
78666 int opcode;
78667@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78668
78669 case RTTEST_LOCKCONT:
78670 td->mutexes[td->opdata] = 1;
78671- td->event = atomic_add_return(1, &rttest_event);
78672+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78673 return 0;
78674
78675 case RTTEST_RESET:
78676@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78677 return 0;
78678
78679 case RTTEST_RESETEVENT:
78680- atomic_set(&rttest_event, 0);
78681+ atomic_set_unchecked(&rttest_event, 0);
78682 return 0;
78683
78684 default:
78685@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78686 return ret;
78687
78688 td->mutexes[id] = 1;
78689- td->event = atomic_add_return(1, &rttest_event);
78690+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78691 rt_mutex_lock(&mutexes[id]);
78692- td->event = atomic_add_return(1, &rttest_event);
78693+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78694 td->mutexes[id] = 4;
78695 return 0;
78696
78697@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78698 return ret;
78699
78700 td->mutexes[id] = 1;
78701- td->event = atomic_add_return(1, &rttest_event);
78702+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78703 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
78704- td->event = atomic_add_return(1, &rttest_event);
78705+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78706 td->mutexes[id] = ret ? 0 : 4;
78707 return ret ? -EINTR : 0;
78708
78709@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78710 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
78711 return ret;
78712
78713- td->event = atomic_add_return(1, &rttest_event);
78714+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78715 rt_mutex_unlock(&mutexes[id]);
78716- td->event = atomic_add_return(1, &rttest_event);
78717+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78718 td->mutexes[id] = 0;
78719 return 0;
78720
78721@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78722 break;
78723
78724 td->mutexes[dat] = 2;
78725- td->event = atomic_add_return(1, &rttest_event);
78726+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78727 break;
78728
78729 default:
78730@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78731 return;
78732
78733 td->mutexes[dat] = 3;
78734- td->event = atomic_add_return(1, &rttest_event);
78735+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78736 break;
78737
78738 case RTTEST_LOCKNOWAIT:
78739@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78740 return;
78741
78742 td->mutexes[dat] = 1;
78743- td->event = atomic_add_return(1, &rttest_event);
78744+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78745 return;
78746
78747 default:
78748diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
78749index 64de5f8..7735e12 100644
78750--- a/kernel/sched/auto_group.c
78751+++ b/kernel/sched/auto_group.c
78752@@ -11,7 +11,7 @@
78753
78754 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
78755 static struct autogroup autogroup_default;
78756-static atomic_t autogroup_seq_nr;
78757+static atomic_unchecked_t autogroup_seq_nr;
78758
78759 void __init autogroup_init(struct task_struct *init_task)
78760 {
78761@@ -81,7 +81,7 @@ static inline struct autogroup *autogroup_create(void)
78762
78763 kref_init(&ag->kref);
78764 init_rwsem(&ag->lock);
78765- ag->id = atomic_inc_return(&autogroup_seq_nr);
78766+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
78767 ag->tg = tg;
78768 #ifdef CONFIG_RT_GROUP_SCHED
78769 /*
78770diff --git a/kernel/sched/core.c b/kernel/sched/core.c
78771index e8b3350..d83d44e 100644
78772--- a/kernel/sched/core.c
78773+++ b/kernel/sched/core.c
78774@@ -3440,7 +3440,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
78775 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78776 * positive (at least 1, or number of jiffies left till timeout) if completed.
78777 */
78778-long __sched
78779+long __sched __intentional_overflow(-1)
78780 wait_for_completion_interruptible_timeout(struct completion *x,
78781 unsigned long timeout)
78782 {
78783@@ -3457,7 +3457,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
78784 *
78785 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
78786 */
78787-int __sched wait_for_completion_killable(struct completion *x)
78788+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
78789 {
78790 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
78791 if (t == -ERESTARTSYS)
78792@@ -3478,7 +3478,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
78793 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78794 * positive (at least 1, or number of jiffies left till timeout) if completed.
78795 */
78796-long __sched
78797+long __sched __intentional_overflow(-1)
78798 wait_for_completion_killable_timeout(struct completion *x,
78799 unsigned long timeout)
78800 {
78801@@ -3704,6 +3704,8 @@ int can_nice(const struct task_struct *p, const int nice)
78802 /* convert nice value [19,-20] to rlimit style value [1,40] */
78803 int nice_rlim = 20 - nice;
78804
78805+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
78806+
78807 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
78808 capable(CAP_SYS_NICE));
78809 }
78810@@ -3737,7 +3739,8 @@ SYSCALL_DEFINE1(nice, int, increment)
78811 if (nice > 19)
78812 nice = 19;
78813
78814- if (increment < 0 && !can_nice(current, nice))
78815+ if (increment < 0 && (!can_nice(current, nice) ||
78816+ gr_handle_chroot_nice()))
78817 return -EPERM;
78818
78819 retval = security_task_setnice(current, nice);
78820@@ -3891,6 +3894,7 @@ recheck:
78821 unsigned long rlim_rtprio =
78822 task_rlimit(p, RLIMIT_RTPRIO);
78823
78824+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
78825 /* can't set/change the rt policy */
78826 if (policy != p->policy && !rlim_rtprio)
78827 return -EPERM;
78828@@ -4988,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
78829
78830 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
78831
78832-static struct ctl_table sd_ctl_dir[] = {
78833+static ctl_table_no_const sd_ctl_dir[] __read_only = {
78834 {
78835 .procname = "sched_domain",
78836 .mode = 0555,
78837@@ -5005,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
78838 {}
78839 };
78840
78841-static struct ctl_table *sd_alloc_ctl_entry(int n)
78842+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
78843 {
78844- struct ctl_table *entry =
78845+ ctl_table_no_const *entry =
78846 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
78847
78848 return entry;
78849 }
78850
78851-static void sd_free_ctl_entry(struct ctl_table **tablep)
78852+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
78853 {
78854- struct ctl_table *entry;
78855+ ctl_table_no_const *entry;
78856
78857 /*
78858 * In the intermediate directories, both the child directory and
78859@@ -5023,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
78860 * will always be set. In the lowest directory the names are
78861 * static strings and all have proc handlers.
78862 */
78863- for (entry = *tablep; entry->mode; entry++) {
78864- if (entry->child)
78865- sd_free_ctl_entry(&entry->child);
78866+ for (entry = tablep; entry->mode; entry++) {
78867+ if (entry->child) {
78868+ sd_free_ctl_entry(entry->child);
78869+ pax_open_kernel();
78870+ entry->child = NULL;
78871+ pax_close_kernel();
78872+ }
78873 if (entry->proc_handler == NULL)
78874 kfree(entry->procname);
78875 }
78876
78877- kfree(*tablep);
78878- *tablep = NULL;
78879+ kfree(tablep);
78880 }
78881
78882 static int min_load_idx = 0;
78883 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
78884
78885 static void
78886-set_table_entry(struct ctl_table *entry,
78887+set_table_entry(ctl_table_no_const *entry,
78888 const char *procname, void *data, int maxlen,
78889 umode_t mode, proc_handler *proc_handler,
78890 bool load_idx)
78891@@ -5058,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
78892 static struct ctl_table *
78893 sd_alloc_ctl_domain_table(struct sched_domain *sd)
78894 {
78895- struct ctl_table *table = sd_alloc_ctl_entry(13);
78896+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
78897
78898 if (table == NULL)
78899 return NULL;
78900@@ -5093,9 +5100,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
78901 return table;
78902 }
78903
78904-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
78905+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
78906 {
78907- struct ctl_table *entry, *table;
78908+ ctl_table_no_const *entry, *table;
78909 struct sched_domain *sd;
78910 int domain_num = 0, i;
78911 char buf[32];
78912@@ -5122,11 +5129,13 @@ static struct ctl_table_header *sd_sysctl_header;
78913 static void register_sched_domain_sysctl(void)
78914 {
78915 int i, cpu_num = num_possible_cpus();
78916- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
78917+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
78918 char buf[32];
78919
78920 WARN_ON(sd_ctl_dir[0].child);
78921+ pax_open_kernel();
78922 sd_ctl_dir[0].child = entry;
78923+ pax_close_kernel();
78924
78925 if (entry == NULL)
78926 return;
78927@@ -5149,8 +5158,12 @@ static void unregister_sched_domain_sysctl(void)
78928 if (sd_sysctl_header)
78929 unregister_sysctl_table(sd_sysctl_header);
78930 sd_sysctl_header = NULL;
78931- if (sd_ctl_dir[0].child)
78932- sd_free_ctl_entry(&sd_ctl_dir[0].child);
78933+ if (sd_ctl_dir[0].child) {
78934+ sd_free_ctl_entry(sd_ctl_dir[0].child);
78935+ pax_open_kernel();
78936+ sd_ctl_dir[0].child = NULL;
78937+ pax_close_kernel();
78938+ }
78939 }
78940 #else
78941 static void register_sched_domain_sysctl(void)
78942@@ -5249,7 +5262,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
78943 * happens before everything else. This has to be lower priority than
78944 * the notifier in the perf_event subsystem, though.
78945 */
78946-static struct notifier_block __cpuinitdata migration_notifier = {
78947+static struct notifier_block migration_notifier = {
78948 .notifier_call = migration_call,
78949 .priority = CPU_PRI_MIGRATION,
78950 };
78951diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
78952index c61a614..d7f3d7e 100644
78953--- a/kernel/sched/fair.c
78954+++ b/kernel/sched/fair.c
78955@@ -831,7 +831,7 @@ void task_numa_fault(int node, int pages, bool migrated)
78956
78957 static void reset_ptenuma_scan(struct task_struct *p)
78958 {
78959- ACCESS_ONCE(p->mm->numa_scan_seq)++;
78960+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
78961 p->mm->numa_scan_offset = 0;
78962 }
78963
78964@@ -5686,7 +5686,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
78965 * run_rebalance_domains is triggered when needed from the scheduler tick.
78966 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
78967 */
78968-static void run_rebalance_domains(struct softirq_action *h)
78969+static void run_rebalance_domains(void)
78970 {
78971 int this_cpu = smp_processor_id();
78972 struct rq *this_rq = cpu_rq(this_cpu);
78973diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
78974index ce39224..0e09343 100644
78975--- a/kernel/sched/sched.h
78976+++ b/kernel/sched/sched.h
78977@@ -1009,7 +1009,7 @@ struct sched_class {
78978 #ifdef CONFIG_FAIR_GROUP_SCHED
78979 void (*task_move_group) (struct task_struct *p, int on_rq);
78980 #endif
78981-};
78982+} __do_const;
78983
78984 #define sched_class_highest (&stop_sched_class)
78985 #define for_each_class(class) \
78986diff --git a/kernel/signal.c b/kernel/signal.c
78987index 113411b..17190e2 100644
78988--- a/kernel/signal.c
78989+++ b/kernel/signal.c
78990@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
78991
78992 int print_fatal_signals __read_mostly;
78993
78994-static void __user *sig_handler(struct task_struct *t, int sig)
78995+static __sighandler_t sig_handler(struct task_struct *t, int sig)
78996 {
78997 return t->sighand->action[sig - 1].sa.sa_handler;
78998 }
78999
79000-static int sig_handler_ignored(void __user *handler, int sig)
79001+static int sig_handler_ignored(__sighandler_t handler, int sig)
79002 {
79003 /* Is it explicitly or implicitly ignored? */
79004 return handler == SIG_IGN ||
79005@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
79006
79007 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
79008 {
79009- void __user *handler;
79010+ __sighandler_t handler;
79011
79012 handler = sig_handler(t, sig);
79013
79014@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
79015 atomic_inc(&user->sigpending);
79016 rcu_read_unlock();
79017
79018+ if (!override_rlimit)
79019+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
79020+
79021 if (override_rlimit ||
79022 atomic_read(&user->sigpending) <=
79023 task_rlimit(t, RLIMIT_SIGPENDING)) {
79024@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
79025
79026 int unhandled_signal(struct task_struct *tsk, int sig)
79027 {
79028- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
79029+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
79030 if (is_global_init(tsk))
79031 return 1;
79032 if (handler != SIG_IGN && handler != SIG_DFL)
79033@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
79034 }
79035 }
79036
79037+ /* allow glibc communication via tgkill to other threads in our
79038+ thread group */
79039+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
79040+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
79041+ && gr_handle_signal(t, sig))
79042+ return -EPERM;
79043+
79044 return security_task_kill(t, info, sig, 0);
79045 }
79046
79047@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
79048 return send_signal(sig, info, p, 1);
79049 }
79050
79051-static int
79052+int
79053 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79054 {
79055 return send_signal(sig, info, t, 0);
79056@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79057 unsigned long int flags;
79058 int ret, blocked, ignored;
79059 struct k_sigaction *action;
79060+ int is_unhandled = 0;
79061
79062 spin_lock_irqsave(&t->sighand->siglock, flags);
79063 action = &t->sighand->action[sig-1];
79064@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79065 }
79066 if (action->sa.sa_handler == SIG_DFL)
79067 t->signal->flags &= ~SIGNAL_UNKILLABLE;
79068+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
79069+ is_unhandled = 1;
79070 ret = specific_send_sig_info(sig, info, t);
79071 spin_unlock_irqrestore(&t->sighand->siglock, flags);
79072
79073+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
79074+ normal operation */
79075+ if (is_unhandled) {
79076+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
79077+ gr_handle_crash(t, sig);
79078+ }
79079+
79080 return ret;
79081 }
79082
79083@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
79084 ret = check_kill_permission(sig, info, p);
79085 rcu_read_unlock();
79086
79087- if (!ret && sig)
79088+ if (!ret && sig) {
79089 ret = do_send_sig_info(sig, info, p, true);
79090+ if (!ret)
79091+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
79092+ }
79093
79094 return ret;
79095 }
79096@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
79097 int error = -ESRCH;
79098
79099 rcu_read_lock();
79100- p = find_task_by_vpid(pid);
79101+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79102+ /* allow glibc communication via tgkill to other threads in our
79103+ thread group */
79104+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
79105+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
79106+ p = find_task_by_vpid_unrestricted(pid);
79107+ else
79108+#endif
79109+ p = find_task_by_vpid(pid);
79110 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
79111 error = check_kill_permission(sig, info, p);
79112 /*
79113@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
79114 }
79115 seg = get_fs();
79116 set_fs(KERNEL_DS);
79117- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
79118- (stack_t __force __user *) &uoss,
79119+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
79120+ (stack_t __force_user *) &uoss,
79121 compat_user_stack_pointer());
79122 set_fs(seg);
79123 if (ret >= 0 && uoss_ptr) {
79124diff --git a/kernel/smp.c b/kernel/smp.c
79125index 4dba0f7..fe9f773 100644
79126--- a/kernel/smp.c
79127+++ b/kernel/smp.c
79128@@ -73,7 +73,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
79129 return NOTIFY_OK;
79130 }
79131
79132-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
79133+static struct notifier_block hotplug_cfd_notifier = {
79134 .notifier_call = hotplug_cfd,
79135 };
79136
79137diff --git a/kernel/smpboot.c b/kernel/smpboot.c
79138index 02fc5c9..e54c335 100644
79139--- a/kernel/smpboot.c
79140+++ b/kernel/smpboot.c
79141@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
79142 }
79143 smpboot_unpark_thread(plug_thread, cpu);
79144 }
79145- list_add(&plug_thread->list, &hotplug_threads);
79146+ pax_list_add(&plug_thread->list, &hotplug_threads);
79147 out:
79148 mutex_unlock(&smpboot_threads_lock);
79149 return ret;
79150@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
79151 {
79152 get_online_cpus();
79153 mutex_lock(&smpboot_threads_lock);
79154- list_del(&plug_thread->list);
79155+ pax_list_del(&plug_thread->list);
79156 smpboot_destroy_threads(plug_thread);
79157 mutex_unlock(&smpboot_threads_lock);
79158 put_online_cpus();
79159diff --git a/kernel/softirq.c b/kernel/softirq.c
79160index 3d6833f..da6d93d 100644
79161--- a/kernel/softirq.c
79162+++ b/kernel/softirq.c
79163@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
79164 EXPORT_SYMBOL(irq_stat);
79165 #endif
79166
79167-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
79168+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
79169
79170 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
79171
79172-char *softirq_to_name[NR_SOFTIRQS] = {
79173+const char * const softirq_to_name[NR_SOFTIRQS] = {
79174 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
79175 "TASKLET", "SCHED", "HRTIMER", "RCU"
79176 };
79177@@ -250,7 +250,7 @@ restart:
79178 kstat_incr_softirqs_this_cpu(vec_nr);
79179
79180 trace_softirq_entry(vec_nr);
79181- h->action(h);
79182+ h->action();
79183 trace_softirq_exit(vec_nr);
79184 if (unlikely(prev_count != preempt_count())) {
79185 printk(KERN_ERR "huh, entered softirq %u %s %p"
79186@@ -405,7 +405,7 @@ void __raise_softirq_irqoff(unsigned int nr)
79187 or_softirq_pending(1UL << nr);
79188 }
79189
79190-void open_softirq(int nr, void (*action)(struct softirq_action *))
79191+void __init open_softirq(int nr, void (*action)(void))
79192 {
79193 softirq_vec[nr].action = action;
79194 }
79195@@ -461,7 +461,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
79196
79197 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
79198
79199-static void tasklet_action(struct softirq_action *a)
79200+static void tasklet_action(void)
79201 {
79202 struct tasklet_struct *list;
79203
79204@@ -496,7 +496,7 @@ static void tasklet_action(struct softirq_action *a)
79205 }
79206 }
79207
79208-static void tasklet_hi_action(struct softirq_action *a)
79209+static void tasklet_hi_action(void)
79210 {
79211 struct tasklet_struct *list;
79212
79213@@ -730,7 +730,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
79214 return NOTIFY_OK;
79215 }
79216
79217-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
79218+static struct notifier_block remote_softirq_cpu_notifier = {
79219 .notifier_call = remote_softirq_cpu_notify,
79220 };
79221
79222@@ -847,11 +847,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
79223 return NOTIFY_OK;
79224 }
79225
79226-static struct notifier_block __cpuinitdata cpu_nfb = {
79227+static struct notifier_block cpu_nfb = {
79228 .notifier_call = cpu_callback
79229 };
79230
79231-static struct smp_hotplug_thread softirq_threads = {
79232+static struct smp_hotplug_thread softirq_threads __read_only = {
79233 .store = &ksoftirqd,
79234 .thread_should_run = ksoftirqd_should_run,
79235 .thread_fn = run_ksoftirqd,
79236diff --git a/kernel/srcu.c b/kernel/srcu.c
79237index 01d5ccb..cdcbee6 100644
79238--- a/kernel/srcu.c
79239+++ b/kernel/srcu.c
79240@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
79241
79242 idx = ACCESS_ONCE(sp->completed) & 0x1;
79243 preempt_disable();
79244- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79245+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79246 smp_mb(); /* B */ /* Avoid leaking the critical section. */
79247- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79248+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79249 preempt_enable();
79250 return idx;
79251 }
79252diff --git a/kernel/sys.c b/kernel/sys.c
79253index 2bbd9a7..0875671 100644
79254--- a/kernel/sys.c
79255+++ b/kernel/sys.c
79256@@ -163,6 +163,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
79257 error = -EACCES;
79258 goto out;
79259 }
79260+
79261+ if (gr_handle_chroot_setpriority(p, niceval)) {
79262+ error = -EACCES;
79263+ goto out;
79264+ }
79265+
79266 no_nice = security_task_setnice(p, niceval);
79267 if (no_nice) {
79268 error = no_nice;
79269@@ -626,6 +632,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
79270 goto error;
79271 }
79272
79273+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
79274+ goto error;
79275+
79276 if (rgid != (gid_t) -1 ||
79277 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
79278 new->sgid = new->egid;
79279@@ -661,6 +670,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
79280 old = current_cred();
79281
79282 retval = -EPERM;
79283+
79284+ if (gr_check_group_change(kgid, kgid, kgid))
79285+ goto error;
79286+
79287 if (nsown_capable(CAP_SETGID))
79288 new->gid = new->egid = new->sgid = new->fsgid = kgid;
79289 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
79290@@ -678,7 +691,7 @@ error:
79291 /*
79292 * change the user struct in a credentials set to match the new UID
79293 */
79294-static int set_user(struct cred *new)
79295+int set_user(struct cred *new)
79296 {
79297 struct user_struct *new_user;
79298
79299@@ -758,6 +771,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
79300 goto error;
79301 }
79302
79303+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
79304+ goto error;
79305+
79306 if (!uid_eq(new->uid, old->uid)) {
79307 retval = set_user(new);
79308 if (retval < 0)
79309@@ -808,6 +824,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
79310 old = current_cred();
79311
79312 retval = -EPERM;
79313+
79314+ if (gr_check_crash_uid(kuid))
79315+ goto error;
79316+ if (gr_check_user_change(kuid, kuid, kuid))
79317+ goto error;
79318+
79319 if (nsown_capable(CAP_SETUID)) {
79320 new->suid = new->uid = kuid;
79321 if (!uid_eq(kuid, old->uid)) {
79322@@ -877,6 +899,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
79323 goto error;
79324 }
79325
79326+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
79327+ goto error;
79328+
79329 if (ruid != (uid_t) -1) {
79330 new->uid = kruid;
79331 if (!uid_eq(kruid, old->uid)) {
79332@@ -959,6 +984,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
79333 goto error;
79334 }
79335
79336+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
79337+ goto error;
79338+
79339 if (rgid != (gid_t) -1)
79340 new->gid = krgid;
79341 if (egid != (gid_t) -1)
79342@@ -1020,12 +1048,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
79343 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
79344 nsown_capable(CAP_SETUID)) {
79345 if (!uid_eq(kuid, old->fsuid)) {
79346+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
79347+ goto error;
79348+
79349 new->fsuid = kuid;
79350 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
79351 goto change_okay;
79352 }
79353 }
79354
79355+error:
79356 abort_creds(new);
79357 return old_fsuid;
79358
79359@@ -1058,12 +1090,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
79360 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
79361 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
79362 nsown_capable(CAP_SETGID)) {
79363+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
79364+ goto error;
79365+
79366 if (!gid_eq(kgid, old->fsgid)) {
79367 new->fsgid = kgid;
79368 goto change_okay;
79369 }
79370 }
79371
79372+error:
79373 abort_creds(new);
79374 return old_fsgid;
79375
79376@@ -1432,19 +1468,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
79377 return -EFAULT;
79378
79379 down_read(&uts_sem);
79380- error = __copy_to_user(&name->sysname, &utsname()->sysname,
79381+ error = __copy_to_user(name->sysname, &utsname()->sysname,
79382 __OLD_UTS_LEN);
79383 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
79384- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
79385+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
79386 __OLD_UTS_LEN);
79387 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
79388- error |= __copy_to_user(&name->release, &utsname()->release,
79389+ error |= __copy_to_user(name->release, &utsname()->release,
79390 __OLD_UTS_LEN);
79391 error |= __put_user(0, name->release + __OLD_UTS_LEN);
79392- error |= __copy_to_user(&name->version, &utsname()->version,
79393+ error |= __copy_to_user(name->version, &utsname()->version,
79394 __OLD_UTS_LEN);
79395 error |= __put_user(0, name->version + __OLD_UTS_LEN);
79396- error |= __copy_to_user(&name->machine, &utsname()->machine,
79397+ error |= __copy_to_user(name->machine, &utsname()->machine,
79398 __OLD_UTS_LEN);
79399 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
79400 up_read(&uts_sem);
79401@@ -1646,6 +1682,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
79402 */
79403 new_rlim->rlim_cur = 1;
79404 }
79405+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
79406+ is changed to a lower value. Since tasks can be created by the same
79407+ user in between this limit change and an execve by this task, force
79408+ a recheck only for this task by setting PF_NPROC_EXCEEDED
79409+ */
79410+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
79411+ tsk->flags |= PF_NPROC_EXCEEDED;
79412 }
79413 if (!retval) {
79414 if (old_rlim)
79415diff --git a/kernel/sysctl.c b/kernel/sysctl.c
79416index 9edcf45..713c960 100644
79417--- a/kernel/sysctl.c
79418+++ b/kernel/sysctl.c
79419@@ -93,7 +93,6 @@
79420
79421
79422 #if defined(CONFIG_SYSCTL)
79423-
79424 /* External variables not in a header file. */
79425 extern int sysctl_overcommit_memory;
79426 extern int sysctl_overcommit_ratio;
79427@@ -119,18 +118,18 @@ extern int blk_iopoll_enabled;
79428
79429 /* Constants used for minimum and maximum */
79430 #ifdef CONFIG_LOCKUP_DETECTOR
79431-static int sixty = 60;
79432-static int neg_one = -1;
79433+static int sixty __read_only = 60;
79434 #endif
79435
79436-static int zero;
79437-static int __maybe_unused one = 1;
79438-static int __maybe_unused two = 2;
79439-static int __maybe_unused three = 3;
79440-static unsigned long one_ul = 1;
79441-static int one_hundred = 100;
79442+static int neg_one __read_only = -1;
79443+static int zero __read_only = 0;
79444+static int __maybe_unused one __read_only = 1;
79445+static int __maybe_unused two __read_only = 2;
79446+static int __maybe_unused three __read_only = 3;
79447+static unsigned long one_ul __read_only = 1;
79448+static int one_hundred __read_only = 100;
79449 #ifdef CONFIG_PRINTK
79450-static int ten_thousand = 10000;
79451+static int ten_thousand __read_only = 10000;
79452 #endif
79453
79454 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
79455@@ -177,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
79456 void __user *buffer, size_t *lenp, loff_t *ppos);
79457 #endif
79458
79459-#ifdef CONFIG_PRINTK
79460 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79461 void __user *buffer, size_t *lenp, loff_t *ppos);
79462-#endif
79463
79464 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
79465 void __user *buffer, size_t *lenp, loff_t *ppos);
79466@@ -211,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
79467
79468 #endif
79469
79470+extern struct ctl_table grsecurity_table[];
79471+
79472 static struct ctl_table kern_table[];
79473 static struct ctl_table vm_table[];
79474 static struct ctl_table fs_table[];
79475@@ -225,6 +224,20 @@ extern struct ctl_table epoll_table[];
79476 int sysctl_legacy_va_layout;
79477 #endif
79478
79479+#ifdef CONFIG_PAX_SOFTMODE
79480+static ctl_table pax_table[] = {
79481+ {
79482+ .procname = "softmode",
79483+ .data = &pax_softmode,
79484+ .maxlen = sizeof(unsigned int),
79485+ .mode = 0600,
79486+ .proc_handler = &proc_dointvec,
79487+ },
79488+
79489+ { }
79490+};
79491+#endif
79492+
79493 /* The default sysctl tables: */
79494
79495 static struct ctl_table sysctl_base_table[] = {
79496@@ -273,6 +286,22 @@ static int max_extfrag_threshold = 1000;
79497 #endif
79498
79499 static struct ctl_table kern_table[] = {
79500+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
79501+ {
79502+ .procname = "grsecurity",
79503+ .mode = 0500,
79504+ .child = grsecurity_table,
79505+ },
79506+#endif
79507+
79508+#ifdef CONFIG_PAX_SOFTMODE
79509+ {
79510+ .procname = "pax",
79511+ .mode = 0500,
79512+ .child = pax_table,
79513+ },
79514+#endif
79515+
79516 {
79517 .procname = "sched_child_runs_first",
79518 .data = &sysctl_sched_child_runs_first,
79519@@ -607,7 +636,7 @@ static struct ctl_table kern_table[] = {
79520 .data = &modprobe_path,
79521 .maxlen = KMOD_PATH_LEN,
79522 .mode = 0644,
79523- .proc_handler = proc_dostring,
79524+ .proc_handler = proc_dostring_modpriv,
79525 },
79526 {
79527 .procname = "modules_disabled",
79528@@ -774,16 +803,20 @@ static struct ctl_table kern_table[] = {
79529 .extra1 = &zero,
79530 .extra2 = &one,
79531 },
79532+#endif
79533 {
79534 .procname = "kptr_restrict",
79535 .data = &kptr_restrict,
79536 .maxlen = sizeof(int),
79537 .mode = 0644,
79538 .proc_handler = proc_dointvec_minmax_sysadmin,
79539+#ifdef CONFIG_GRKERNSEC_HIDESYM
79540+ .extra1 = &two,
79541+#else
79542 .extra1 = &zero,
79543+#endif
79544 .extra2 = &two,
79545 },
79546-#endif
79547 {
79548 .procname = "ngroups_max",
79549 .data = &ngroups_max,
79550@@ -1025,10 +1058,17 @@ static struct ctl_table kern_table[] = {
79551 */
79552 {
79553 .procname = "perf_event_paranoid",
79554- .data = &sysctl_perf_event_paranoid,
79555- .maxlen = sizeof(sysctl_perf_event_paranoid),
79556+ .data = &sysctl_perf_event_legitimately_concerned,
79557+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
79558 .mode = 0644,
79559- .proc_handler = proc_dointvec,
79560+ /* go ahead, be a hero */
79561+ .proc_handler = proc_dointvec_minmax_sysadmin,
79562+ .extra1 = &neg_one,
79563+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
79564+ .extra2 = &three,
79565+#else
79566+ .extra2 = &two,
79567+#endif
79568 },
79569 {
79570 .procname = "perf_event_mlock_kb",
79571@@ -1282,6 +1322,13 @@ static struct ctl_table vm_table[] = {
79572 .proc_handler = proc_dointvec_minmax,
79573 .extra1 = &zero,
79574 },
79575+ {
79576+ .procname = "heap_stack_gap",
79577+ .data = &sysctl_heap_stack_gap,
79578+ .maxlen = sizeof(sysctl_heap_stack_gap),
79579+ .mode = 0644,
79580+ .proc_handler = proc_doulongvec_minmax,
79581+ },
79582 #else
79583 {
79584 .procname = "nr_trim_pages",
79585@@ -1746,6 +1793,16 @@ int proc_dostring(struct ctl_table *table, int write,
79586 buffer, lenp, ppos);
79587 }
79588
79589+int proc_dostring_modpriv(struct ctl_table *table, int write,
79590+ void __user *buffer, size_t *lenp, loff_t *ppos)
79591+{
79592+ if (write && !capable(CAP_SYS_MODULE))
79593+ return -EPERM;
79594+
79595+ return _proc_do_string(table->data, table->maxlen, write,
79596+ buffer, lenp, ppos);
79597+}
79598+
79599 static size_t proc_skip_spaces(char **buf)
79600 {
79601 size_t ret;
79602@@ -1851,6 +1908,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
79603 len = strlen(tmp);
79604 if (len > *size)
79605 len = *size;
79606+ if (len > sizeof(tmp))
79607+ len = sizeof(tmp);
79608 if (copy_to_user(*buf, tmp, len))
79609 return -EFAULT;
79610 *size -= len;
79611@@ -2015,7 +2074,7 @@ int proc_dointvec(struct ctl_table *table, int write,
79612 static int proc_taint(struct ctl_table *table, int write,
79613 void __user *buffer, size_t *lenp, loff_t *ppos)
79614 {
79615- struct ctl_table t;
79616+ ctl_table_no_const t;
79617 unsigned long tmptaint = get_taint();
79618 int err;
79619
79620@@ -2043,7 +2102,6 @@ static int proc_taint(struct ctl_table *table, int write,
79621 return err;
79622 }
79623
79624-#ifdef CONFIG_PRINTK
79625 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79626 void __user *buffer, size_t *lenp, loff_t *ppos)
79627 {
79628@@ -2052,7 +2110,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79629
79630 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
79631 }
79632-#endif
79633
79634 struct do_proc_dointvec_minmax_conv_param {
79635 int *min;
79636@@ -2199,8 +2256,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
79637 *i = val;
79638 } else {
79639 val = convdiv * (*i) / convmul;
79640- if (!first)
79641+ if (!first) {
79642 err = proc_put_char(&buffer, &left, '\t');
79643+ if (err)
79644+ break;
79645+ }
79646 err = proc_put_long(&buffer, &left, val, false);
79647 if (err)
79648 break;
79649@@ -2592,6 +2652,12 @@ int proc_dostring(struct ctl_table *table, int write,
79650 return -ENOSYS;
79651 }
79652
79653+int proc_dostring_modpriv(struct ctl_table *table, int write,
79654+ void __user *buffer, size_t *lenp, loff_t *ppos)
79655+{
79656+ return -ENOSYS;
79657+}
79658+
79659 int proc_dointvec(struct ctl_table *table, int write,
79660 void __user *buffer, size_t *lenp, loff_t *ppos)
79661 {
79662@@ -2648,5 +2714,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
79663 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
79664 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
79665 EXPORT_SYMBOL(proc_dostring);
79666+EXPORT_SYMBOL(proc_dostring_modpriv);
79667 EXPORT_SYMBOL(proc_doulongvec_minmax);
79668 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
79669diff --git a/kernel/taskstats.c b/kernel/taskstats.c
79670index 145bb4d..b2aa969 100644
79671--- a/kernel/taskstats.c
79672+++ b/kernel/taskstats.c
79673@@ -28,9 +28,12 @@
79674 #include <linux/fs.h>
79675 #include <linux/file.h>
79676 #include <linux/pid_namespace.h>
79677+#include <linux/grsecurity.h>
79678 #include <net/genetlink.h>
79679 #include <linux/atomic.h>
79680
79681+extern int gr_is_taskstats_denied(int pid);
79682+
79683 /*
79684 * Maximum length of a cpumask that can be specified in
79685 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
79686@@ -570,6 +573,9 @@ err:
79687
79688 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
79689 {
79690+ if (gr_is_taskstats_denied(current->pid))
79691+ return -EACCES;
79692+
79693 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
79694 return cmd_attr_register_cpumask(info);
79695 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
79696diff --git a/kernel/time.c b/kernel/time.c
79697index d3617db..c98bbe9 100644
79698--- a/kernel/time.c
79699+++ b/kernel/time.c
79700@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
79701 return error;
79702
79703 if (tz) {
79704+ /* we log in do_settimeofday called below, so don't log twice
79705+ */
79706+ if (!tv)
79707+ gr_log_timechange();
79708+
79709 sys_tz = *tz;
79710 update_vsyscall_tz();
79711 if (firsttime) {
79712@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
79713 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
79714 * value to a scaled second value.
79715 */
79716-unsigned long
79717+unsigned long __intentional_overflow(-1)
79718 timespec_to_jiffies(const struct timespec *value)
79719 {
79720 unsigned long sec = value->tv_sec;
79721diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
79722index f11d83b..d016d91 100644
79723--- a/kernel/time/alarmtimer.c
79724+++ b/kernel/time/alarmtimer.c
79725@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
79726 struct platform_device *pdev;
79727 int error = 0;
79728 int i;
79729- struct k_clock alarm_clock = {
79730+ static struct k_clock alarm_clock = {
79731 .clock_getres = alarm_clock_getres,
79732 .clock_get = alarm_clock_get,
79733 .timer_create = alarm_timer_create,
79734diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
79735index 20d6fba..09e103a 100644
79736--- a/kernel/time/tick-broadcast.c
79737+++ b/kernel/time/tick-broadcast.c
79738@@ -147,7 +147,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
79739 * then clear the broadcast bit.
79740 */
79741 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
79742- int cpu = smp_processor_id();
79743+ cpu = smp_processor_id();
79744 cpumask_clear_cpu(cpu, tick_broadcast_mask);
79745 tick_broadcast_clear_oneshot(cpu);
79746 } else {
79747diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
79748index baeeb5c..c22704a 100644
79749--- a/kernel/time/timekeeping.c
79750+++ b/kernel/time/timekeeping.c
79751@@ -15,6 +15,7 @@
79752 #include <linux/init.h>
79753 #include <linux/mm.h>
79754 #include <linux/sched.h>
79755+#include <linux/grsecurity.h>
79756 #include <linux/syscore_ops.h>
79757 #include <linux/clocksource.h>
79758 #include <linux/jiffies.h>
79759@@ -495,6 +496,8 @@ int do_settimeofday(const struct timespec *tv)
79760 if (!timespec_valid_strict(tv))
79761 return -EINVAL;
79762
79763+ gr_log_timechange();
79764+
79765 raw_spin_lock_irqsave(&timekeeper_lock, flags);
79766 write_seqcount_begin(&timekeeper_seq);
79767
79768diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
79769index 3bdf283..cc68d83 100644
79770--- a/kernel/time/timer_list.c
79771+++ b/kernel/time/timer_list.c
79772@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
79773
79774 static void print_name_offset(struct seq_file *m, void *sym)
79775 {
79776+#ifdef CONFIG_GRKERNSEC_HIDESYM
79777+ SEQ_printf(m, "<%p>", NULL);
79778+#else
79779 char symname[KSYM_NAME_LEN];
79780
79781 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
79782 SEQ_printf(m, "<%pK>", sym);
79783 else
79784 SEQ_printf(m, "%s", symname);
79785+#endif
79786 }
79787
79788 static void
79789@@ -119,7 +123,11 @@ next_one:
79790 static void
79791 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
79792 {
79793+#ifdef CONFIG_GRKERNSEC_HIDESYM
79794+ SEQ_printf(m, " .base: %p\n", NULL);
79795+#else
79796 SEQ_printf(m, " .base: %pK\n", base);
79797+#endif
79798 SEQ_printf(m, " .index: %d\n",
79799 base->index);
79800 SEQ_printf(m, " .resolution: %Lu nsecs\n",
79801@@ -355,7 +363,11 @@ static int __init init_timer_list_procfs(void)
79802 {
79803 struct proc_dir_entry *pe;
79804
79805+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79806+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
79807+#else
79808 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
79809+#endif
79810 if (!pe)
79811 return -ENOMEM;
79812 return 0;
79813diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
79814index 0b537f2..40d6c20 100644
79815--- a/kernel/time/timer_stats.c
79816+++ b/kernel/time/timer_stats.c
79817@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
79818 static unsigned long nr_entries;
79819 static struct entry entries[MAX_ENTRIES];
79820
79821-static atomic_t overflow_count;
79822+static atomic_unchecked_t overflow_count;
79823
79824 /*
79825 * The entries are in a hash-table, for fast lookup:
79826@@ -140,7 +140,7 @@ static void reset_entries(void)
79827 nr_entries = 0;
79828 memset(entries, 0, sizeof(entries));
79829 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
79830- atomic_set(&overflow_count, 0);
79831+ atomic_set_unchecked(&overflow_count, 0);
79832 }
79833
79834 static struct entry *alloc_entry(void)
79835@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79836 if (likely(entry))
79837 entry->count++;
79838 else
79839- atomic_inc(&overflow_count);
79840+ atomic_inc_unchecked(&overflow_count);
79841
79842 out_unlock:
79843 raw_spin_unlock_irqrestore(lock, flags);
79844@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79845
79846 static void print_name_offset(struct seq_file *m, unsigned long addr)
79847 {
79848+#ifdef CONFIG_GRKERNSEC_HIDESYM
79849+ seq_printf(m, "<%p>", NULL);
79850+#else
79851 char symname[KSYM_NAME_LEN];
79852
79853 if (lookup_symbol_name(addr, symname) < 0)
79854- seq_printf(m, "<%p>", (void *)addr);
79855+ seq_printf(m, "<%pK>", (void *)addr);
79856 else
79857 seq_printf(m, "%s", symname);
79858+#endif
79859 }
79860
79861 static int tstats_show(struct seq_file *m, void *v)
79862@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
79863
79864 seq_puts(m, "Timer Stats Version: v0.2\n");
79865 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
79866- if (atomic_read(&overflow_count))
79867+ if (atomic_read_unchecked(&overflow_count))
79868 seq_printf(m, "Overflow: %d entries\n",
79869- atomic_read(&overflow_count));
79870+ atomic_read_unchecked(&overflow_count));
79871
79872 for (i = 0; i < nr_entries; i++) {
79873 entry = entries + i;
79874@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
79875 {
79876 struct proc_dir_entry *pe;
79877
79878+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79879+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
79880+#else
79881 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
79882+#endif
79883 if (!pe)
79884 return -ENOMEM;
79885 return 0;
79886diff --git a/kernel/timer.c b/kernel/timer.c
79887index 15bc1b4..32da49c 100644
79888--- a/kernel/timer.c
79889+++ b/kernel/timer.c
79890@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
79891 /*
79892 * This function runs timers and the timer-tq in bottom half context.
79893 */
79894-static void run_timer_softirq(struct softirq_action *h)
79895+static void run_timer_softirq(void)
79896 {
79897 struct tvec_base *base = __this_cpu_read(tvec_bases);
79898
79899@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
79900 *
79901 * In all cases the return value is guaranteed to be non-negative.
79902 */
79903-signed long __sched schedule_timeout(signed long timeout)
79904+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
79905 {
79906 struct timer_list timer;
79907 unsigned long expire;
79908@@ -1635,7 +1635,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
79909 return NOTIFY_OK;
79910 }
79911
79912-static struct notifier_block __cpuinitdata timers_nb = {
79913+static struct notifier_block timers_nb = {
79914 .notifier_call = timer_cpu_notify,
79915 };
79916
79917diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
79918index b8b8560..75b1a09 100644
79919--- a/kernel/trace/blktrace.c
79920+++ b/kernel/trace/blktrace.c
79921@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
79922 struct blk_trace *bt = filp->private_data;
79923 char buf[16];
79924
79925- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
79926+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
79927
79928 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
79929 }
79930@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
79931 return 1;
79932
79933 bt = buf->chan->private_data;
79934- atomic_inc(&bt->dropped);
79935+ atomic_inc_unchecked(&bt->dropped);
79936 return 0;
79937 }
79938
79939@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
79940
79941 bt->dir = dir;
79942 bt->dev = dev;
79943- atomic_set(&bt->dropped, 0);
79944+ atomic_set_unchecked(&bt->dropped, 0);
79945
79946 ret = -EIO;
79947 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
79948diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
79949index 6c508ff..ee55a13 100644
79950--- a/kernel/trace/ftrace.c
79951+++ b/kernel/trace/ftrace.c
79952@@ -1915,12 +1915,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
79953 if (unlikely(ftrace_disabled))
79954 return 0;
79955
79956+ ret = ftrace_arch_code_modify_prepare();
79957+ FTRACE_WARN_ON(ret);
79958+ if (ret)
79959+ return 0;
79960+
79961 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
79962+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
79963 if (ret) {
79964 ftrace_bug(ret, ip);
79965- return 0;
79966 }
79967- return 1;
79968+ return ret ? 0 : 1;
79969 }
79970
79971 /*
79972@@ -3931,8 +3936,10 @@ static int ftrace_process_locs(struct module *mod,
79973 if (!count)
79974 return 0;
79975
79976+ pax_open_kernel();
79977 sort(start, count, sizeof(*start),
79978 ftrace_cmp_ips, ftrace_swap_ips);
79979+ pax_close_kernel();
79980
79981 start_pg = ftrace_allocate_pages(count);
79982 if (!start_pg)
79983@@ -4655,8 +4662,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
79984 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
79985
79986 static int ftrace_graph_active;
79987-static struct notifier_block ftrace_suspend_notifier;
79988-
79989 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
79990 {
79991 return 0;
79992@@ -4800,6 +4805,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
79993 return NOTIFY_DONE;
79994 }
79995
79996+static struct notifier_block ftrace_suspend_notifier = {
79997+ .notifier_call = ftrace_suspend_notifier_call
79998+};
79999+
80000 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
80001 trace_func_graph_ent_t entryfunc)
80002 {
80003@@ -4813,7 +4822,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
80004 goto out;
80005 }
80006
80007- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
80008 register_pm_notifier(&ftrace_suspend_notifier);
80009
80010 ftrace_graph_active++;
80011diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
80012index e444ff8..438b8f4 100644
80013--- a/kernel/trace/ring_buffer.c
80014+++ b/kernel/trace/ring_buffer.c
80015@@ -352,9 +352,9 @@ struct buffer_data_page {
80016 */
80017 struct buffer_page {
80018 struct list_head list; /* list of buffer pages */
80019- local_t write; /* index for next write */
80020+ local_unchecked_t write; /* index for next write */
80021 unsigned read; /* index for next read */
80022- local_t entries; /* entries on this page */
80023+ local_unchecked_t entries; /* entries on this page */
80024 unsigned long real_end; /* real end of data */
80025 struct buffer_data_page *page; /* Actual data page */
80026 };
80027@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
80028 unsigned long last_overrun;
80029 local_t entries_bytes;
80030 local_t entries;
80031- local_t overrun;
80032- local_t commit_overrun;
80033+ local_unchecked_t overrun;
80034+ local_unchecked_t commit_overrun;
80035 local_t dropped_events;
80036 local_t committing;
80037 local_t commits;
80038@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
80039 *
80040 * We add a counter to the write field to denote this.
80041 */
80042- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
80043- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
80044+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
80045+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
80046
80047 /*
80048 * Just make sure we have seen our old_write and synchronize
80049@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
80050 * cmpxchg to only update if an interrupt did not already
80051 * do it for us. If the cmpxchg fails, we don't care.
80052 */
80053- (void)local_cmpxchg(&next_page->write, old_write, val);
80054- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
80055+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
80056+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
80057
80058 /*
80059 * No need to worry about races with clearing out the commit.
80060@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
80061
80062 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
80063 {
80064- return local_read(&bpage->entries) & RB_WRITE_MASK;
80065+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
80066 }
80067
80068 static inline unsigned long rb_page_write(struct buffer_page *bpage)
80069 {
80070- return local_read(&bpage->write) & RB_WRITE_MASK;
80071+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
80072 }
80073
80074 static int
80075@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
80076 * bytes consumed in ring buffer from here.
80077 * Increment overrun to account for the lost events.
80078 */
80079- local_add(page_entries, &cpu_buffer->overrun);
80080+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
80081 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
80082 }
80083
80084@@ -2063,7 +2063,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
80085 * it is our responsibility to update
80086 * the counters.
80087 */
80088- local_add(entries, &cpu_buffer->overrun);
80089+ local_add_unchecked(entries, &cpu_buffer->overrun);
80090 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
80091
80092 /*
80093@@ -2213,7 +2213,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80094 if (tail == BUF_PAGE_SIZE)
80095 tail_page->real_end = 0;
80096
80097- local_sub(length, &tail_page->write);
80098+ local_sub_unchecked(length, &tail_page->write);
80099 return;
80100 }
80101
80102@@ -2248,7 +2248,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80103 rb_event_set_padding(event);
80104
80105 /* Set the write back to the previous setting */
80106- local_sub(length, &tail_page->write);
80107+ local_sub_unchecked(length, &tail_page->write);
80108 return;
80109 }
80110
80111@@ -2260,7 +2260,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80112
80113 /* Set write to end of buffer */
80114 length = (tail + length) - BUF_PAGE_SIZE;
80115- local_sub(length, &tail_page->write);
80116+ local_sub_unchecked(length, &tail_page->write);
80117 }
80118
80119 /*
80120@@ -2286,7 +2286,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
80121 * about it.
80122 */
80123 if (unlikely(next_page == commit_page)) {
80124- local_inc(&cpu_buffer->commit_overrun);
80125+ local_inc_unchecked(&cpu_buffer->commit_overrun);
80126 goto out_reset;
80127 }
80128
80129@@ -2342,7 +2342,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
80130 cpu_buffer->tail_page) &&
80131 (cpu_buffer->commit_page ==
80132 cpu_buffer->reader_page))) {
80133- local_inc(&cpu_buffer->commit_overrun);
80134+ local_inc_unchecked(&cpu_buffer->commit_overrun);
80135 goto out_reset;
80136 }
80137 }
80138@@ -2390,7 +2390,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
80139 length += RB_LEN_TIME_EXTEND;
80140
80141 tail_page = cpu_buffer->tail_page;
80142- write = local_add_return(length, &tail_page->write);
80143+ write = local_add_return_unchecked(length, &tail_page->write);
80144
80145 /* set write to only the index of the write */
80146 write &= RB_WRITE_MASK;
80147@@ -2407,7 +2407,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
80148 kmemcheck_annotate_bitfield(event, bitfield);
80149 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
80150
80151- local_inc(&tail_page->entries);
80152+ local_inc_unchecked(&tail_page->entries);
80153
80154 /*
80155 * If this is the first commit on the page, then update
80156@@ -2440,7 +2440,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
80157
80158 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
80159 unsigned long write_mask =
80160- local_read(&bpage->write) & ~RB_WRITE_MASK;
80161+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
80162 unsigned long event_length = rb_event_length(event);
80163 /*
80164 * This is on the tail page. It is possible that
80165@@ -2450,7 +2450,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
80166 */
80167 old_index += write_mask;
80168 new_index += write_mask;
80169- index = local_cmpxchg(&bpage->write, old_index, new_index);
80170+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
80171 if (index == old_index) {
80172 /* update counters */
80173 local_sub(event_length, &cpu_buffer->entries_bytes);
80174@@ -2842,7 +2842,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
80175
80176 /* Do the likely case first */
80177 if (likely(bpage->page == (void *)addr)) {
80178- local_dec(&bpage->entries);
80179+ local_dec_unchecked(&bpage->entries);
80180 return;
80181 }
80182
80183@@ -2854,7 +2854,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
80184 start = bpage;
80185 do {
80186 if (bpage->page == (void *)addr) {
80187- local_dec(&bpage->entries);
80188+ local_dec_unchecked(&bpage->entries);
80189 return;
80190 }
80191 rb_inc_page(cpu_buffer, &bpage);
80192@@ -3138,7 +3138,7 @@ static inline unsigned long
80193 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
80194 {
80195 return local_read(&cpu_buffer->entries) -
80196- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
80197+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
80198 }
80199
80200 /**
80201@@ -3227,7 +3227,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
80202 return 0;
80203
80204 cpu_buffer = buffer->buffers[cpu];
80205- ret = local_read(&cpu_buffer->overrun);
80206+ ret = local_read_unchecked(&cpu_buffer->overrun);
80207
80208 return ret;
80209 }
80210@@ -3250,7 +3250,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
80211 return 0;
80212
80213 cpu_buffer = buffer->buffers[cpu];
80214- ret = local_read(&cpu_buffer->commit_overrun);
80215+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
80216
80217 return ret;
80218 }
80219@@ -3335,7 +3335,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
80220 /* if you care about this being correct, lock the buffer */
80221 for_each_buffer_cpu(buffer, cpu) {
80222 cpu_buffer = buffer->buffers[cpu];
80223- overruns += local_read(&cpu_buffer->overrun);
80224+ overruns += local_read_unchecked(&cpu_buffer->overrun);
80225 }
80226
80227 return overruns;
80228@@ -3511,8 +3511,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80229 /*
80230 * Reset the reader page to size zero.
80231 */
80232- local_set(&cpu_buffer->reader_page->write, 0);
80233- local_set(&cpu_buffer->reader_page->entries, 0);
80234+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80235+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80236 local_set(&cpu_buffer->reader_page->page->commit, 0);
80237 cpu_buffer->reader_page->real_end = 0;
80238
80239@@ -3546,7 +3546,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80240 * want to compare with the last_overrun.
80241 */
80242 smp_mb();
80243- overwrite = local_read(&(cpu_buffer->overrun));
80244+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
80245
80246 /*
80247 * Here's the tricky part.
80248@@ -4116,8 +4116,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80249
80250 cpu_buffer->head_page
80251 = list_entry(cpu_buffer->pages, struct buffer_page, list);
80252- local_set(&cpu_buffer->head_page->write, 0);
80253- local_set(&cpu_buffer->head_page->entries, 0);
80254+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
80255+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
80256 local_set(&cpu_buffer->head_page->page->commit, 0);
80257
80258 cpu_buffer->head_page->read = 0;
80259@@ -4127,14 +4127,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80260
80261 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
80262 INIT_LIST_HEAD(&cpu_buffer->new_pages);
80263- local_set(&cpu_buffer->reader_page->write, 0);
80264- local_set(&cpu_buffer->reader_page->entries, 0);
80265+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80266+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80267 local_set(&cpu_buffer->reader_page->page->commit, 0);
80268 cpu_buffer->reader_page->read = 0;
80269
80270 local_set(&cpu_buffer->entries_bytes, 0);
80271- local_set(&cpu_buffer->overrun, 0);
80272- local_set(&cpu_buffer->commit_overrun, 0);
80273+ local_set_unchecked(&cpu_buffer->overrun, 0);
80274+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
80275 local_set(&cpu_buffer->dropped_events, 0);
80276 local_set(&cpu_buffer->entries, 0);
80277 local_set(&cpu_buffer->committing, 0);
80278@@ -4538,8 +4538,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
80279 rb_init_page(bpage);
80280 bpage = reader->page;
80281 reader->page = *data_page;
80282- local_set(&reader->write, 0);
80283- local_set(&reader->entries, 0);
80284+ local_set_unchecked(&reader->write, 0);
80285+ local_set_unchecked(&reader->entries, 0);
80286 reader->read = 0;
80287 *data_page = bpage;
80288
80289diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
80290index e71a8be..948710a 100644
80291--- a/kernel/trace/trace.c
80292+++ b/kernel/trace/trace.c
80293@@ -3201,7 +3201,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
80294 return 0;
80295 }
80296
80297-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
80298+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
80299 {
80300 /* do nothing if flag is already set */
80301 if (!!(trace_flags & mask) == !!enabled)
80302diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
80303index 20572ed..fe55cf3 100644
80304--- a/kernel/trace/trace.h
80305+++ b/kernel/trace/trace.h
80306@@ -1030,7 +1030,7 @@ extern const char *__stop___trace_bprintk_fmt[];
80307 void trace_printk_init_buffers(void);
80308 void trace_printk_start_comm(void);
80309 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
80310-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
80311+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
80312
80313 /*
80314 * Normal trace_printk() and friends allocates special buffers
80315diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
80316index 27963e2..5a6936f 100644
80317--- a/kernel/trace/trace_events.c
80318+++ b/kernel/trace/trace_events.c
80319@@ -1637,10 +1637,6 @@ static LIST_HEAD(ftrace_module_file_list);
80320 struct ftrace_module_file_ops {
80321 struct list_head list;
80322 struct module *mod;
80323- struct file_operations id;
80324- struct file_operations enable;
80325- struct file_operations format;
80326- struct file_operations filter;
80327 };
80328
80329 static struct ftrace_module_file_ops *
80330@@ -1681,17 +1677,12 @@ trace_create_file_ops(struct module *mod)
80331
80332 file_ops->mod = mod;
80333
80334- file_ops->id = ftrace_event_id_fops;
80335- file_ops->id.owner = mod;
80336-
80337- file_ops->enable = ftrace_enable_fops;
80338- file_ops->enable.owner = mod;
80339-
80340- file_ops->filter = ftrace_event_filter_fops;
80341- file_ops->filter.owner = mod;
80342-
80343- file_ops->format = ftrace_event_format_fops;
80344- file_ops->format.owner = mod;
80345+ pax_open_kernel();
80346+ mod->trace_id.owner = mod;
80347+ mod->trace_enable.owner = mod;
80348+ mod->trace_filter.owner = mod;
80349+ mod->trace_format.owner = mod;
80350+ pax_close_kernel();
80351
80352 list_add(&file_ops->list, &ftrace_module_file_list);
80353
80354@@ -1782,8 +1773,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
80355 struct ftrace_module_file_ops *file_ops)
80356 {
80357 return __trace_add_new_event(call, tr,
80358- &file_ops->id, &file_ops->enable,
80359- &file_ops->filter, &file_ops->format);
80360+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
80361+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
80362 }
80363
80364 #else
80365diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
80366index a5e8f48..a9690d2 100644
80367--- a/kernel/trace/trace_mmiotrace.c
80368+++ b/kernel/trace/trace_mmiotrace.c
80369@@ -24,7 +24,7 @@ struct header_iter {
80370 static struct trace_array *mmio_trace_array;
80371 static bool overrun_detected;
80372 static unsigned long prev_overruns;
80373-static atomic_t dropped_count;
80374+static atomic_unchecked_t dropped_count;
80375
80376 static void mmio_reset_data(struct trace_array *tr)
80377 {
80378@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
80379
80380 static unsigned long count_overruns(struct trace_iterator *iter)
80381 {
80382- unsigned long cnt = atomic_xchg(&dropped_count, 0);
80383+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
80384 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
80385
80386 if (over > prev_overruns)
80387@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
80388 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
80389 sizeof(*entry), 0, pc);
80390 if (!event) {
80391- atomic_inc(&dropped_count);
80392+ atomic_inc_unchecked(&dropped_count);
80393 return;
80394 }
80395 entry = ring_buffer_event_data(event);
80396@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
80397 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
80398 sizeof(*entry), 0, pc);
80399 if (!event) {
80400- atomic_inc(&dropped_count);
80401+ atomic_inc_unchecked(&dropped_count);
80402 return;
80403 }
80404 entry = ring_buffer_event_data(event);
80405diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
80406index bb922d9..2a54a257 100644
80407--- a/kernel/trace/trace_output.c
80408+++ b/kernel/trace/trace_output.c
80409@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
80410
80411 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
80412 if (!IS_ERR(p)) {
80413- p = mangle_path(s->buffer + s->len, p, "\n");
80414+ p = mangle_path(s->buffer + s->len, p, "\n\\");
80415 if (p) {
80416 s->len = p - s->buffer;
80417 return 1;
80418@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
80419 goto out;
80420 }
80421
80422+ pax_open_kernel();
80423 if (event->funcs->trace == NULL)
80424- event->funcs->trace = trace_nop_print;
80425+ *(void **)&event->funcs->trace = trace_nop_print;
80426 if (event->funcs->raw == NULL)
80427- event->funcs->raw = trace_nop_print;
80428+ *(void **)&event->funcs->raw = trace_nop_print;
80429 if (event->funcs->hex == NULL)
80430- event->funcs->hex = trace_nop_print;
80431+ *(void **)&event->funcs->hex = trace_nop_print;
80432 if (event->funcs->binary == NULL)
80433- event->funcs->binary = trace_nop_print;
80434+ *(void **)&event->funcs->binary = trace_nop_print;
80435+ pax_close_kernel();
80436
80437 key = event->type & (EVENT_HASHSIZE - 1);
80438
80439diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
80440index b20428c..4845a10 100644
80441--- a/kernel/trace/trace_stack.c
80442+++ b/kernel/trace/trace_stack.c
80443@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
80444 return;
80445
80446 /* we do not handle interrupt stacks yet */
80447- if (!object_is_on_stack(stack))
80448+ if (!object_starts_on_stack(stack))
80449 return;
80450
80451 local_irq_save(flags);
80452diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
80453index d8c30db..e065e89 100644
80454--- a/kernel/user_namespace.c
80455+++ b/kernel/user_namespace.c
80456@@ -853,7 +853,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
80457 if (atomic_read(&current->mm->mm_users) > 1)
80458 return -EINVAL;
80459
80460- if (current->fs->users != 1)
80461+ if (atomic_read(&current->fs->users) != 1)
80462 return -EINVAL;
80463
80464 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
80465diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
80466index 4f69f9a..7c6f8f8 100644
80467--- a/kernel/utsname_sysctl.c
80468+++ b/kernel/utsname_sysctl.c
80469@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
80470 static int proc_do_uts_string(ctl_table *table, int write,
80471 void __user *buffer, size_t *lenp, loff_t *ppos)
80472 {
80473- struct ctl_table uts_table;
80474+ ctl_table_no_const uts_table;
80475 int r;
80476 memcpy(&uts_table, table, sizeof(uts_table));
80477 uts_table.data = get_uts(table, write);
80478diff --git a/kernel/watchdog.c b/kernel/watchdog.c
80479index 05039e3..17490c7 100644
80480--- a/kernel/watchdog.c
80481+++ b/kernel/watchdog.c
80482@@ -531,7 +531,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
80483 }
80484 #endif /* CONFIG_SYSCTL */
80485
80486-static struct smp_hotplug_thread watchdog_threads = {
80487+static struct smp_hotplug_thread watchdog_threads __read_only = {
80488 .store = &softlockup_watchdog,
80489 .thread_should_run = watchdog_should_run,
80490 .thread_fn = watchdog,
80491diff --git a/kernel/workqueue.c b/kernel/workqueue.c
80492index ee8e29a..410568e 100644
80493--- a/kernel/workqueue.c
80494+++ b/kernel/workqueue.c
80495@@ -4584,7 +4584,7 @@ static void rebind_workers(struct worker_pool *pool)
80496 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
80497 worker_flags |= WORKER_REBOUND;
80498 worker_flags &= ~WORKER_UNBOUND;
80499- ACCESS_ONCE(worker->flags) = worker_flags;
80500+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
80501 }
80502
80503 spin_unlock_irq(&pool->lock);
80504diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
80505index 566cf2b..fdaa52c 100644
80506--- a/lib/Kconfig.debug
80507+++ b/lib/Kconfig.debug
80508@@ -549,7 +549,7 @@ config DEBUG_MUTEXES
80509
80510 config DEBUG_LOCK_ALLOC
80511 bool "Lock debugging: detect incorrect freeing of live locks"
80512- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80513+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80514 select DEBUG_SPINLOCK
80515 select DEBUG_MUTEXES
80516 select LOCKDEP
80517@@ -563,7 +563,7 @@ config DEBUG_LOCK_ALLOC
80518
80519 config PROVE_LOCKING
80520 bool "Lock debugging: prove locking correctness"
80521- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80522+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80523 select LOCKDEP
80524 select DEBUG_SPINLOCK
80525 select DEBUG_MUTEXES
80526@@ -614,7 +614,7 @@ config LOCKDEP
80527
80528 config LOCK_STAT
80529 bool "Lock usage statistics"
80530- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80531+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80532 select LOCKDEP
80533 select DEBUG_SPINLOCK
80534 select DEBUG_MUTEXES
80535@@ -1282,6 +1282,7 @@ config LATENCYTOP
80536 depends on DEBUG_KERNEL
80537 depends on STACKTRACE_SUPPORT
80538 depends on PROC_FS
80539+ depends on !GRKERNSEC_HIDESYM
80540 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
80541 select KALLSYMS
80542 select KALLSYMS_ALL
80543@@ -1298,7 +1299,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
80544 config DEBUG_STRICT_USER_COPY_CHECKS
80545 bool "Strict user copy size checks"
80546 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
80547- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
80548+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
80549 help
80550 Enabling this option turns a certain set of sanity checks for user
80551 copy operations into compile time failures.
80552@@ -1328,7 +1329,7 @@ config INTERVAL_TREE_TEST
80553
80554 config PROVIDE_OHCI1394_DMA_INIT
80555 bool "Remote debugging over FireWire early on boot"
80556- depends on PCI && X86
80557+ depends on PCI && X86 && !GRKERNSEC
80558 help
80559 If you want to debug problems which hang or crash the kernel early
80560 on boot and the crashing machine has a FireWire port, you can use
80561@@ -1357,7 +1358,7 @@ config PROVIDE_OHCI1394_DMA_INIT
80562
80563 config FIREWIRE_OHCI_REMOTE_DMA
80564 bool "Remote debugging over FireWire with firewire-ohci"
80565- depends on FIREWIRE_OHCI
80566+ depends on FIREWIRE_OHCI && !GRKERNSEC
80567 help
80568 This option lets you use the FireWire bus for remote debugging
80569 with help of the firewire-ohci driver. It enables unfiltered
80570diff --git a/lib/Makefile b/lib/Makefile
80571index c55a037..fb46e3b 100644
80572--- a/lib/Makefile
80573+++ b/lib/Makefile
80574@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
80575
80576 obj-$(CONFIG_BTREE) += btree.o
80577 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
80578-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
80579+obj-y += list_debug.o
80580 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
80581
80582 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
80583diff --git a/lib/bitmap.c b/lib/bitmap.c
80584index 06f7e4f..f3cf2b0 100644
80585--- a/lib/bitmap.c
80586+++ b/lib/bitmap.c
80587@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
80588 {
80589 int c, old_c, totaldigits, ndigits, nchunks, nbits;
80590 u32 chunk;
80591- const char __user __force *ubuf = (const char __user __force *)buf;
80592+ const char __user *ubuf = (const char __force_user *)buf;
80593
80594 bitmap_zero(maskp, nmaskbits);
80595
80596@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
80597 {
80598 if (!access_ok(VERIFY_READ, ubuf, ulen))
80599 return -EFAULT;
80600- return __bitmap_parse((const char __force *)ubuf,
80601+ return __bitmap_parse((const char __force_kernel *)ubuf,
80602 ulen, 1, maskp, nmaskbits);
80603
80604 }
80605@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
80606 {
80607 unsigned a, b;
80608 int c, old_c, totaldigits;
80609- const char __user __force *ubuf = (const char __user __force *)buf;
80610+ const char __user *ubuf = (const char __force_user *)buf;
80611 int exp_digit, in_range;
80612
80613 totaldigits = c = 0;
80614@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
80615 {
80616 if (!access_ok(VERIFY_READ, ubuf, ulen))
80617 return -EFAULT;
80618- return __bitmap_parselist((const char __force *)ubuf,
80619+ return __bitmap_parselist((const char __force_kernel *)ubuf,
80620 ulen, 1, maskp, nmaskbits);
80621 }
80622 EXPORT_SYMBOL(bitmap_parselist_user);
80623diff --git a/lib/bug.c b/lib/bug.c
80624index 1686034..a9c00c8 100644
80625--- a/lib/bug.c
80626+++ b/lib/bug.c
80627@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
80628 return BUG_TRAP_TYPE_NONE;
80629
80630 bug = find_bug(bugaddr);
80631+ if (!bug)
80632+ return BUG_TRAP_TYPE_NONE;
80633
80634 file = NULL;
80635 line = 0;
80636diff --git a/lib/debugobjects.c b/lib/debugobjects.c
80637index 37061ed..da83f48 100644
80638--- a/lib/debugobjects.c
80639+++ b/lib/debugobjects.c
80640@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
80641 if (limit > 4)
80642 return;
80643
80644- is_on_stack = object_is_on_stack(addr);
80645+ is_on_stack = object_starts_on_stack(addr);
80646 if (is_on_stack == onstack)
80647 return;
80648
80649diff --git a/lib/devres.c b/lib/devres.c
80650index 8235331..5881053 100644
80651--- a/lib/devres.c
80652+++ b/lib/devres.c
80653@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
80654 void devm_iounmap(struct device *dev, void __iomem *addr)
80655 {
80656 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
80657- (void *)addr));
80658+ (void __force *)addr));
80659 iounmap(addr);
80660 }
80661 EXPORT_SYMBOL(devm_iounmap);
80662@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
80663 {
80664 ioport_unmap(addr);
80665 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
80666- devm_ioport_map_match, (void *)addr));
80667+ devm_ioport_map_match, (void __force *)addr));
80668 }
80669 EXPORT_SYMBOL(devm_ioport_unmap);
80670 #endif /* CONFIG_HAS_IOPORT */
80671diff --git a/lib/div64.c b/lib/div64.c
80672index a163b6c..9618fa5 100644
80673--- a/lib/div64.c
80674+++ b/lib/div64.c
80675@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
80676 EXPORT_SYMBOL(__div64_32);
80677
80678 #ifndef div_s64_rem
80679-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80680+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80681 {
80682 u64 quotient;
80683
80684@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
80685 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
80686 */
80687 #ifndef div64_u64
80688-u64 div64_u64(u64 dividend, u64 divisor)
80689+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80690 {
80691 u32 high = divisor >> 32;
80692 u64 quot;
80693diff --git a/lib/dma-debug.c b/lib/dma-debug.c
80694index d87a17a..ac0d79a 100644
80695--- a/lib/dma-debug.c
80696+++ b/lib/dma-debug.c
80697@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
80698
80699 void dma_debug_add_bus(struct bus_type *bus)
80700 {
80701- struct notifier_block *nb;
80702+ notifier_block_no_const *nb;
80703
80704 if (global_disable)
80705 return;
80706@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
80707
80708 static void check_for_stack(struct device *dev, void *addr)
80709 {
80710- if (object_is_on_stack(addr))
80711+ if (object_starts_on_stack(addr))
80712 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
80713 "stack [addr=%p]\n", addr);
80714 }
80715diff --git a/lib/inflate.c b/lib/inflate.c
80716index 013a761..c28f3fc 100644
80717--- a/lib/inflate.c
80718+++ b/lib/inflate.c
80719@@ -269,7 +269,7 @@ static void free(void *where)
80720 malloc_ptr = free_mem_ptr;
80721 }
80722 #else
80723-#define malloc(a) kmalloc(a, GFP_KERNEL)
80724+#define malloc(a) kmalloc((a), GFP_KERNEL)
80725 #define free(a) kfree(a)
80726 #endif
80727
80728diff --git a/lib/ioremap.c b/lib/ioremap.c
80729index 0c9216c..863bd89 100644
80730--- a/lib/ioremap.c
80731+++ b/lib/ioremap.c
80732@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
80733 unsigned long next;
80734
80735 phys_addr -= addr;
80736- pmd = pmd_alloc(&init_mm, pud, addr);
80737+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
80738 if (!pmd)
80739 return -ENOMEM;
80740 do {
80741@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
80742 unsigned long next;
80743
80744 phys_addr -= addr;
80745- pud = pud_alloc(&init_mm, pgd, addr);
80746+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
80747 if (!pud)
80748 return -ENOMEM;
80749 do {
80750diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
80751index bd2bea9..6b3c95e 100644
80752--- a/lib/is_single_threaded.c
80753+++ b/lib/is_single_threaded.c
80754@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
80755 struct task_struct *p, *t;
80756 bool ret;
80757
80758+ if (!mm)
80759+ return true;
80760+
80761 if (atomic_read(&task->signal->live) != 1)
80762 return false;
80763
80764diff --git a/lib/kobject.c b/lib/kobject.c
80765index b7e29a6..2f3ca75 100644
80766--- a/lib/kobject.c
80767+++ b/lib/kobject.c
80768@@ -805,7 +805,7 @@ static struct kset *kset_create(const char *name,
80769 kset = kzalloc(sizeof(*kset), GFP_KERNEL);
80770 if (!kset)
80771 return NULL;
80772- retval = kobject_set_name(&kset->kobj, name);
80773+ retval = kobject_set_name(&kset->kobj, "%s", name);
80774 if (retval) {
80775 kfree(kset);
80776 return NULL;
80777@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
80778
80779
80780 static DEFINE_SPINLOCK(kobj_ns_type_lock);
80781-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
80782+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
80783
80784-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80785+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80786 {
80787 enum kobj_ns_type type = ops->type;
80788 int error;
80789diff --git a/lib/list_debug.c b/lib/list_debug.c
80790index c24c2f7..06e070b 100644
80791--- a/lib/list_debug.c
80792+++ b/lib/list_debug.c
80793@@ -11,7 +11,9 @@
80794 #include <linux/bug.h>
80795 #include <linux/kernel.h>
80796 #include <linux/rculist.h>
80797+#include <linux/mm.h>
80798
80799+#ifdef CONFIG_DEBUG_LIST
80800 /*
80801 * Insert a new entry between two known consecutive entries.
80802 *
80803@@ -19,21 +21,32 @@
80804 * the prev/next entries already!
80805 */
80806
80807-void __list_add(struct list_head *new,
80808- struct list_head *prev,
80809- struct list_head *next)
80810+static bool __list_add_debug(struct list_head *new,
80811+ struct list_head *prev,
80812+ struct list_head *next)
80813 {
80814- WARN(next->prev != prev,
80815+ if (WARN(next->prev != prev,
80816 "list_add corruption. next->prev should be "
80817 "prev (%p), but was %p. (next=%p).\n",
80818- prev, next->prev, next);
80819- WARN(prev->next != next,
80820+ prev, next->prev, next) ||
80821+ WARN(prev->next != next,
80822 "list_add corruption. prev->next should be "
80823 "next (%p), but was %p. (prev=%p).\n",
80824- next, prev->next, prev);
80825- WARN(new == prev || new == next,
80826- "list_add double add: new=%p, prev=%p, next=%p.\n",
80827- new, prev, next);
80828+ next, prev->next, prev) ||
80829+ WARN(new == prev || new == next,
80830+ "list_add double add: new=%p, prev=%p, next=%p.\n",
80831+ new, prev, next))
80832+ return false;
80833+ return true;
80834+}
80835+
80836+void __list_add(struct list_head *new,
80837+ struct list_head *prev,
80838+ struct list_head *next)
80839+{
80840+ if (!__list_add_debug(new, prev, next))
80841+ return;
80842+
80843 next->prev = new;
80844 new->next = next;
80845 new->prev = prev;
80846@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
80847 }
80848 EXPORT_SYMBOL(__list_add);
80849
80850-void __list_del_entry(struct list_head *entry)
80851+static bool __list_del_entry_debug(struct list_head *entry)
80852 {
80853 struct list_head *prev, *next;
80854
80855@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
80856 WARN(next->prev != entry,
80857 "list_del corruption. next->prev should be %p, "
80858 "but was %p\n", entry, next->prev))
80859+ return false;
80860+ return true;
80861+}
80862+
80863+void __list_del_entry(struct list_head *entry)
80864+{
80865+ if (!__list_del_entry_debug(entry))
80866 return;
80867
80868- __list_del(prev, next);
80869+ __list_del(entry->prev, entry->next);
80870 }
80871 EXPORT_SYMBOL(__list_del_entry);
80872
80873@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
80874 void __list_add_rcu(struct list_head *new,
80875 struct list_head *prev, struct list_head *next)
80876 {
80877- WARN(next->prev != prev,
80878- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
80879- prev, next->prev, next);
80880- WARN(prev->next != next,
80881- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
80882- next, prev->next, prev);
80883+ if (!__list_add_debug(new, prev, next))
80884+ return;
80885+
80886 new->next = next;
80887 new->prev = prev;
80888 rcu_assign_pointer(list_next_rcu(prev), new);
80889 next->prev = new;
80890 }
80891 EXPORT_SYMBOL(__list_add_rcu);
80892+#endif
80893+
80894+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
80895+{
80896+#ifdef CONFIG_DEBUG_LIST
80897+ if (!__list_add_debug(new, prev, next))
80898+ return;
80899+#endif
80900+
80901+ pax_open_kernel();
80902+ next->prev = new;
80903+ new->next = next;
80904+ new->prev = prev;
80905+ prev->next = new;
80906+ pax_close_kernel();
80907+}
80908+EXPORT_SYMBOL(__pax_list_add);
80909+
80910+void pax_list_del(struct list_head *entry)
80911+{
80912+#ifdef CONFIG_DEBUG_LIST
80913+ if (!__list_del_entry_debug(entry))
80914+ return;
80915+#endif
80916+
80917+ pax_open_kernel();
80918+ __list_del(entry->prev, entry->next);
80919+ entry->next = LIST_POISON1;
80920+ entry->prev = LIST_POISON2;
80921+ pax_close_kernel();
80922+}
80923+EXPORT_SYMBOL(pax_list_del);
80924+
80925+void pax_list_del_init(struct list_head *entry)
80926+{
80927+ pax_open_kernel();
80928+ __list_del(entry->prev, entry->next);
80929+ INIT_LIST_HEAD(entry);
80930+ pax_close_kernel();
80931+}
80932+EXPORT_SYMBOL(pax_list_del_init);
80933+
80934+void __pax_list_add_rcu(struct list_head *new,
80935+ struct list_head *prev, struct list_head *next)
80936+{
80937+#ifdef CONFIG_DEBUG_LIST
80938+ if (!__list_add_debug(new, prev, next))
80939+ return;
80940+#endif
80941+
80942+ pax_open_kernel();
80943+ new->next = next;
80944+ new->prev = prev;
80945+ rcu_assign_pointer(list_next_rcu(prev), new);
80946+ next->prev = new;
80947+ pax_close_kernel();
80948+}
80949+EXPORT_SYMBOL(__pax_list_add_rcu);
80950+
80951+void pax_list_del_rcu(struct list_head *entry)
80952+{
80953+#ifdef CONFIG_DEBUG_LIST
80954+ if (!__list_del_entry_debug(entry))
80955+ return;
80956+#endif
80957+
80958+ pax_open_kernel();
80959+ __list_del(entry->prev, entry->next);
80960+ entry->next = LIST_POISON1;
80961+ entry->prev = LIST_POISON2;
80962+ pax_close_kernel();
80963+}
80964+EXPORT_SYMBOL(pax_list_del_rcu);
80965diff --git a/lib/radix-tree.c b/lib/radix-tree.c
80966index e796429..6e38f9f 100644
80967--- a/lib/radix-tree.c
80968+++ b/lib/radix-tree.c
80969@@ -92,7 +92,7 @@ struct radix_tree_preload {
80970 int nr;
80971 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
80972 };
80973-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
80974+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
80975
80976 static inline void *ptr_to_indirect(void *ptr)
80977 {
80978diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
80979index bb2b201..46abaf9 100644
80980--- a/lib/strncpy_from_user.c
80981+++ b/lib/strncpy_from_user.c
80982@@ -21,7 +21,7 @@
80983 */
80984 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
80985 {
80986- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80987+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80988 long res = 0;
80989
80990 /*
80991diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
80992index a28df52..3d55877 100644
80993--- a/lib/strnlen_user.c
80994+++ b/lib/strnlen_user.c
80995@@ -26,7 +26,7 @@
80996 */
80997 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
80998 {
80999- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
81000+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
81001 long align, res = 0;
81002 unsigned long c;
81003
81004diff --git a/lib/swiotlb.c b/lib/swiotlb.c
81005index d23762e..e21eab2 100644
81006--- a/lib/swiotlb.c
81007+++ b/lib/swiotlb.c
81008@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
81009
81010 void
81011 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
81012- dma_addr_t dev_addr)
81013+ dma_addr_t dev_addr, struct dma_attrs *attrs)
81014 {
81015 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
81016
81017diff --git a/lib/usercopy.c b/lib/usercopy.c
81018index 4f5b1dd..7cab418 100644
81019--- a/lib/usercopy.c
81020+++ b/lib/usercopy.c
81021@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
81022 WARN(1, "Buffer overflow detected!\n");
81023 }
81024 EXPORT_SYMBOL(copy_from_user_overflow);
81025+
81026+void copy_to_user_overflow(void)
81027+{
81028+ WARN(1, "Buffer overflow detected!\n");
81029+}
81030+EXPORT_SYMBOL(copy_to_user_overflow);
81031diff --git a/lib/vsprintf.c b/lib/vsprintf.c
81032index e149c64..24aa71a 100644
81033--- a/lib/vsprintf.c
81034+++ b/lib/vsprintf.c
81035@@ -16,6 +16,9 @@
81036 * - scnprintf and vscnprintf
81037 */
81038
81039+#ifdef CONFIG_GRKERNSEC_HIDESYM
81040+#define __INCLUDED_BY_HIDESYM 1
81041+#endif
81042 #include <stdarg.h>
81043 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
81044 #include <linux/types.h>
81045@@ -981,7 +984,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
81046 return number(buf, end, *(const netdev_features_t *)addr, spec);
81047 }
81048
81049+#ifdef CONFIG_GRKERNSEC_HIDESYM
81050+int kptr_restrict __read_mostly = 2;
81051+#else
81052 int kptr_restrict __read_mostly;
81053+#endif
81054
81055 /*
81056 * Show a '%p' thing. A kernel extension is that the '%p' is followed
81057@@ -994,6 +1001,7 @@ int kptr_restrict __read_mostly;
81058 * - 'f' For simple symbolic function names without offset
81059 * - 'S' For symbolic direct pointers with offset
81060 * - 's' For symbolic direct pointers without offset
81061+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
81062 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
81063 * - 'B' For backtraced symbolic direct pointers with offset
81064 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
81065@@ -1052,12 +1060,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81066
81067 if (!ptr && *fmt != 'K') {
81068 /*
81069- * Print (null) with the same width as a pointer so it makes
81070+ * Print (nil) with the same width as a pointer so it makes
81071 * tabular output look nice.
81072 */
81073 if (spec.field_width == -1)
81074 spec.field_width = default_width;
81075- return string(buf, end, "(null)", spec);
81076+ return string(buf, end, "(nil)", spec);
81077 }
81078
81079 switch (*fmt) {
81080@@ -1067,6 +1075,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81081 /* Fallthrough */
81082 case 'S':
81083 case 's':
81084+#ifdef CONFIG_GRKERNSEC_HIDESYM
81085+ break;
81086+#else
81087+ return symbol_string(buf, end, ptr, spec, fmt);
81088+#endif
81089+ case 'A':
81090 case 'B':
81091 return symbol_string(buf, end, ptr, spec, fmt);
81092 case 'R':
81093@@ -1107,6 +1121,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81094 va_end(va);
81095 return buf;
81096 }
81097+ case 'P':
81098+ break;
81099 case 'K':
81100 /*
81101 * %pK cannot be used in IRQ context because its test
81102@@ -1136,6 +1152,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81103 return number(buf, end,
81104 (unsigned long long) *((phys_addr_t *)ptr), spec);
81105 }
81106+
81107+#ifdef CONFIG_GRKERNSEC_HIDESYM
81108+ /* 'P' = approved pointers to copy to userland,
81109+ as in the /proc/kallsyms case, as we make it display nothing
81110+ for non-root users, and the real contents for root users
81111+ Also ignore 'K' pointers, since we force their NULLing for non-root users
81112+ above
81113+ */
81114+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
81115+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
81116+ dump_stack();
81117+ ptr = NULL;
81118+ }
81119+#endif
81120+
81121 spec.flags |= SMALL;
81122 if (spec.field_width == -1) {
81123 spec.field_width = default_width;
81124@@ -1857,11 +1888,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
81125 typeof(type) value; \
81126 if (sizeof(type) == 8) { \
81127 args = PTR_ALIGN(args, sizeof(u32)); \
81128- *(u32 *)&value = *(u32 *)args; \
81129- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
81130+ *(u32 *)&value = *(const u32 *)args; \
81131+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
81132 } else { \
81133 args = PTR_ALIGN(args, sizeof(type)); \
81134- value = *(typeof(type) *)args; \
81135+ value = *(const typeof(type) *)args; \
81136 } \
81137 args += sizeof(type); \
81138 value; \
81139@@ -1924,7 +1955,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
81140 case FORMAT_TYPE_STR: {
81141 const char *str_arg = args;
81142 args += strlen(str_arg) + 1;
81143- str = string(str, end, (char *)str_arg, spec);
81144+ str = string(str, end, str_arg, spec);
81145 break;
81146 }
81147
81148diff --git a/localversion-grsec b/localversion-grsec
81149new file mode 100644
81150index 0000000..7cd6065
81151--- /dev/null
81152+++ b/localversion-grsec
81153@@ -0,0 +1 @@
81154+-grsec
81155diff --git a/mm/Kconfig b/mm/Kconfig
81156index e742d06..c56fdd8 100644
81157--- a/mm/Kconfig
81158+++ b/mm/Kconfig
81159@@ -317,10 +317,10 @@ config KSM
81160 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
81161
81162 config DEFAULT_MMAP_MIN_ADDR
81163- int "Low address space to protect from user allocation"
81164+ int "Low address space to protect from user allocation"
81165 depends on MMU
81166- default 4096
81167- help
81168+ default 65536
81169+ help
81170 This is the portion of low virtual memory which should be protected
81171 from userspace allocation. Keeping a user from writing to low pages
81172 can help reduce the impact of kernel NULL pointer bugs.
81173@@ -351,7 +351,7 @@ config MEMORY_FAILURE
81174
81175 config HWPOISON_INJECT
81176 tristate "HWPoison pages injector"
81177- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
81178+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
81179 select PROC_PAGE_MONITOR
81180
81181 config NOMMU_INITIAL_TRIM_EXCESS
81182diff --git a/mm/backing-dev.c b/mm/backing-dev.c
81183index 5025174..9fc1c5c 100644
81184--- a/mm/backing-dev.c
81185+++ b/mm/backing-dev.c
81186@@ -515,7 +515,6 @@ EXPORT_SYMBOL(bdi_destroy);
81187 int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
81188 unsigned int cap)
81189 {
81190- char tmp[32];
81191 int err;
81192
81193 bdi->name = name;
81194@@ -524,8 +523,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
81195 if (err)
81196 return err;
81197
81198- sprintf(tmp, "%.28s%s", name, "-%d");
81199- err = bdi_register(bdi, NULL, tmp, atomic_long_inc_return(&bdi_seq));
81200+ err = bdi_register(bdi, NULL, "%.28s-%ld", name, atomic_long_inc_return(&bdi_seq));
81201 if (err) {
81202 bdi_destroy(bdi);
81203 return err;
81204diff --git a/mm/filemap.c b/mm/filemap.c
81205index 7905fe7..e60faa8 100644
81206--- a/mm/filemap.c
81207+++ b/mm/filemap.c
81208@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
81209 struct address_space *mapping = file->f_mapping;
81210
81211 if (!mapping->a_ops->readpage)
81212- return -ENOEXEC;
81213+ return -ENODEV;
81214 file_accessed(file);
81215 vma->vm_ops = &generic_file_vm_ops;
81216 return 0;
81217@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
81218 *pos = i_size_read(inode);
81219
81220 if (limit != RLIM_INFINITY) {
81221+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
81222 if (*pos >= limit) {
81223 send_sig(SIGXFSZ, current, 0);
81224 return -EFBIG;
81225diff --git a/mm/fremap.c b/mm/fremap.c
81226index 87da359..3f41cb1 100644
81227--- a/mm/fremap.c
81228+++ b/mm/fremap.c
81229@@ -158,6 +158,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
81230 retry:
81231 vma = find_vma(mm, start);
81232
81233+#ifdef CONFIG_PAX_SEGMEXEC
81234+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
81235+ goto out;
81236+#endif
81237+
81238 /*
81239 * Make sure the vma is shared, that it supports prefaulting,
81240 * and that the remapped range is valid and fully within
81241diff --git a/mm/highmem.c b/mm/highmem.c
81242index b32b70c..e512eb0 100644
81243--- a/mm/highmem.c
81244+++ b/mm/highmem.c
81245@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
81246 * So no dangers, even with speculative execution.
81247 */
81248 page = pte_page(pkmap_page_table[i]);
81249+ pax_open_kernel();
81250 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
81251-
81252+ pax_close_kernel();
81253 set_page_address(page, NULL);
81254 need_flush = 1;
81255 }
81256@@ -198,9 +199,11 @@ start:
81257 }
81258 }
81259 vaddr = PKMAP_ADDR(last_pkmap_nr);
81260+
81261+ pax_open_kernel();
81262 set_pte_at(&init_mm, vaddr,
81263 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
81264-
81265+ pax_close_kernel();
81266 pkmap_count[last_pkmap_nr] = 1;
81267 set_page_address(page, (void *)vaddr);
81268
81269diff --git a/mm/hugetlb.c b/mm/hugetlb.c
81270index 5cf99bf..28634c8 100644
81271--- a/mm/hugetlb.c
81272+++ b/mm/hugetlb.c
81273@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
81274 struct hstate *h = &default_hstate;
81275 unsigned long tmp;
81276 int ret;
81277+ ctl_table_no_const hugetlb_table;
81278
81279 tmp = h->max_huge_pages;
81280
81281 if (write && h->order >= MAX_ORDER)
81282 return -EINVAL;
81283
81284- table->data = &tmp;
81285- table->maxlen = sizeof(unsigned long);
81286- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
81287+ hugetlb_table = *table;
81288+ hugetlb_table.data = &tmp;
81289+ hugetlb_table.maxlen = sizeof(unsigned long);
81290+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
81291 if (ret)
81292 goto out;
81293
81294@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
81295 struct hstate *h = &default_hstate;
81296 unsigned long tmp;
81297 int ret;
81298+ ctl_table_no_const hugetlb_table;
81299
81300 tmp = h->nr_overcommit_huge_pages;
81301
81302 if (write && h->order >= MAX_ORDER)
81303 return -EINVAL;
81304
81305- table->data = &tmp;
81306- table->maxlen = sizeof(unsigned long);
81307- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
81308+ hugetlb_table = *table;
81309+ hugetlb_table.data = &tmp;
81310+ hugetlb_table.maxlen = sizeof(unsigned long);
81311+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
81312 if (ret)
81313 goto out;
81314
81315@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
81316 return 1;
81317 }
81318
81319+#ifdef CONFIG_PAX_SEGMEXEC
81320+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
81321+{
81322+ struct mm_struct *mm = vma->vm_mm;
81323+ struct vm_area_struct *vma_m;
81324+ unsigned long address_m;
81325+ pte_t *ptep_m;
81326+
81327+ vma_m = pax_find_mirror_vma(vma);
81328+ if (!vma_m)
81329+ return;
81330+
81331+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81332+ address_m = address + SEGMEXEC_TASK_SIZE;
81333+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
81334+ get_page(page_m);
81335+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
81336+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
81337+}
81338+#endif
81339+
81340 /*
81341 * Hugetlb_cow() should be called with page lock of the original hugepage held.
81342 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
81343@@ -2663,6 +2688,11 @@ retry_avoidcopy:
81344 make_huge_pte(vma, new_page, 1));
81345 page_remove_rmap(old_page);
81346 hugepage_add_new_anon_rmap(new_page, vma, address);
81347+
81348+#ifdef CONFIG_PAX_SEGMEXEC
81349+ pax_mirror_huge_pte(vma, address, new_page);
81350+#endif
81351+
81352 /* Make the old page be freed below */
81353 new_page = old_page;
81354 }
81355@@ -2821,6 +2851,10 @@ retry:
81356 && (vma->vm_flags & VM_SHARED)));
81357 set_huge_pte_at(mm, address, ptep, new_pte);
81358
81359+#ifdef CONFIG_PAX_SEGMEXEC
81360+ pax_mirror_huge_pte(vma, address, page);
81361+#endif
81362+
81363 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
81364 /* Optimization, do the COW without a second fault */
81365 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
81366@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81367 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
81368 struct hstate *h = hstate_vma(vma);
81369
81370+#ifdef CONFIG_PAX_SEGMEXEC
81371+ struct vm_area_struct *vma_m;
81372+#endif
81373+
81374 address &= huge_page_mask(h);
81375
81376 ptep = huge_pte_offset(mm, address);
81377@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81378 VM_FAULT_SET_HINDEX(hstate_index(h));
81379 }
81380
81381+#ifdef CONFIG_PAX_SEGMEXEC
81382+ vma_m = pax_find_mirror_vma(vma);
81383+ if (vma_m) {
81384+ unsigned long address_m;
81385+
81386+ if (vma->vm_start > vma_m->vm_start) {
81387+ address_m = address;
81388+ address -= SEGMEXEC_TASK_SIZE;
81389+ vma = vma_m;
81390+ h = hstate_vma(vma);
81391+ } else
81392+ address_m = address + SEGMEXEC_TASK_SIZE;
81393+
81394+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
81395+ return VM_FAULT_OOM;
81396+ address_m &= HPAGE_MASK;
81397+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
81398+ }
81399+#endif
81400+
81401 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
81402 if (!ptep)
81403 return VM_FAULT_OOM;
81404diff --git a/mm/internal.h b/mm/internal.h
81405index 8562de0..7fdfe92 100644
81406--- a/mm/internal.h
81407+++ b/mm/internal.h
81408@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
81409 * in mm/page_alloc.c
81410 */
81411 extern void __free_pages_bootmem(struct page *page, unsigned int order);
81412+extern void free_compound_page(struct page *page);
81413 extern void prep_compound_page(struct page *page, unsigned long order);
81414 #ifdef CONFIG_MEMORY_FAILURE
81415 extern bool is_free_buddy_page(struct page *page);
81416diff --git a/mm/kmemleak.c b/mm/kmemleak.c
81417index c8d7f31..2dbeffd 100644
81418--- a/mm/kmemleak.c
81419+++ b/mm/kmemleak.c
81420@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
81421
81422 for (i = 0; i < object->trace_len; i++) {
81423 void *ptr = (void *)object->trace[i];
81424- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
81425+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
81426 }
81427 }
81428
81429@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
81430 return -ENOMEM;
81431 }
81432
81433- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
81434+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
81435 &kmemleak_fops);
81436 if (!dentry)
81437 pr_warning("Failed to create the debugfs kmemleak file\n");
81438diff --git a/mm/maccess.c b/mm/maccess.c
81439index d53adf9..03a24bf 100644
81440--- a/mm/maccess.c
81441+++ b/mm/maccess.c
81442@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
81443 set_fs(KERNEL_DS);
81444 pagefault_disable();
81445 ret = __copy_from_user_inatomic(dst,
81446- (__force const void __user *)src, size);
81447+ (const void __force_user *)src, size);
81448 pagefault_enable();
81449 set_fs(old_fs);
81450
81451@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
81452
81453 set_fs(KERNEL_DS);
81454 pagefault_disable();
81455- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
81456+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
81457 pagefault_enable();
81458 set_fs(old_fs);
81459
81460diff --git a/mm/madvise.c b/mm/madvise.c
81461index 7055883..aafb1ed 100644
81462--- a/mm/madvise.c
81463+++ b/mm/madvise.c
81464@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
81465 pgoff_t pgoff;
81466 unsigned long new_flags = vma->vm_flags;
81467
81468+#ifdef CONFIG_PAX_SEGMEXEC
81469+ struct vm_area_struct *vma_m;
81470+#endif
81471+
81472 switch (behavior) {
81473 case MADV_NORMAL:
81474 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
81475@@ -126,6 +130,13 @@ success:
81476 /*
81477 * vm_flags is protected by the mmap_sem held in write mode.
81478 */
81479+
81480+#ifdef CONFIG_PAX_SEGMEXEC
81481+ vma_m = pax_find_mirror_vma(vma);
81482+ if (vma_m)
81483+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
81484+#endif
81485+
81486 vma->vm_flags = new_flags;
81487
81488 out:
81489@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81490 struct vm_area_struct ** prev,
81491 unsigned long start, unsigned long end)
81492 {
81493+
81494+#ifdef CONFIG_PAX_SEGMEXEC
81495+ struct vm_area_struct *vma_m;
81496+#endif
81497+
81498 *prev = vma;
81499 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
81500 return -EINVAL;
81501@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81502 zap_page_range(vma, start, end - start, &details);
81503 } else
81504 zap_page_range(vma, start, end - start, NULL);
81505+
81506+#ifdef CONFIG_PAX_SEGMEXEC
81507+ vma_m = pax_find_mirror_vma(vma);
81508+ if (vma_m) {
81509+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
81510+ struct zap_details details = {
81511+ .nonlinear_vma = vma_m,
81512+ .last_index = ULONG_MAX,
81513+ };
81514+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
81515+ } else
81516+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
81517+ }
81518+#endif
81519+
81520 return 0;
81521 }
81522
81523@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
81524 if (end < start)
81525 return error;
81526
81527+#ifdef CONFIG_PAX_SEGMEXEC
81528+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81529+ if (end > SEGMEXEC_TASK_SIZE)
81530+ return error;
81531+ } else
81532+#endif
81533+
81534+ if (end > TASK_SIZE)
81535+ return error;
81536+
81537 error = 0;
81538 if (end == start)
81539 return error;
81540diff --git a/mm/memory-failure.c b/mm/memory-failure.c
81541index ceb0c7f..b2b8e94 100644
81542--- a/mm/memory-failure.c
81543+++ b/mm/memory-failure.c
81544@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
81545
81546 int sysctl_memory_failure_recovery __read_mostly = 1;
81547
81548-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
81549+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
81550
81551 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
81552
81553@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
81554 pfn, t->comm, t->pid);
81555 si.si_signo = SIGBUS;
81556 si.si_errno = 0;
81557- si.si_addr = (void *)addr;
81558+ si.si_addr = (void __user *)addr;
81559 #ifdef __ARCH_SI_TRAPNO
81560 si.si_trapno = trapno;
81561 #endif
81562@@ -760,7 +760,7 @@ static struct page_state {
81563 unsigned long res;
81564 char *msg;
81565 int (*action)(struct page *p, unsigned long pfn);
81566-} error_states[] = {
81567+} __do_const error_states[] = {
81568 { reserved, reserved, "reserved kernel", me_kernel },
81569 /*
81570 * free pages are specially detected outside this table:
81571@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81572 nr_pages = 1 << compound_order(hpage);
81573 else /* normal page or thp */
81574 nr_pages = 1;
81575- atomic_long_add(nr_pages, &num_poisoned_pages);
81576+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
81577
81578 /*
81579 * We need/can do nothing about count=0 pages.
81580@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81581 if (!PageHWPoison(hpage)
81582 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
81583 || (p != hpage && TestSetPageHWPoison(hpage))) {
81584- atomic_long_sub(nr_pages, &num_poisoned_pages);
81585+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81586 return 0;
81587 }
81588 set_page_hwpoison_huge_page(hpage);
81589@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81590 }
81591 if (hwpoison_filter(p)) {
81592 if (TestClearPageHWPoison(p))
81593- atomic_long_sub(nr_pages, &num_poisoned_pages);
81594+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81595 unlock_page(hpage);
81596 put_page(hpage);
81597 return 0;
81598@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
81599 return 0;
81600 }
81601 if (TestClearPageHWPoison(p))
81602- atomic_long_sub(nr_pages, &num_poisoned_pages);
81603+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81604 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
81605 return 0;
81606 }
81607@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
81608 */
81609 if (TestClearPageHWPoison(page)) {
81610 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
81611- atomic_long_sub(nr_pages, &num_poisoned_pages);
81612+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81613 freeit = 1;
81614 if (PageHuge(page))
81615 clear_page_hwpoison_huge_page(page);
81616@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
81617 } else {
81618 set_page_hwpoison_huge_page(hpage);
81619 dequeue_hwpoisoned_huge_page(hpage);
81620- atomic_long_add(1 << compound_trans_order(hpage),
81621+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81622 &num_poisoned_pages);
81623 }
81624 /* keep elevated page count for bad page */
81625@@ -1552,11 +1552,11 @@ int soft_offline_page(struct page *page, int flags)
81626 if (PageHuge(page)) {
81627 set_page_hwpoison_huge_page(hpage);
81628 dequeue_hwpoisoned_huge_page(hpage);
81629- atomic_long_add(1 << compound_trans_order(hpage),
81630+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81631 &num_poisoned_pages);
81632 } else {
81633 SetPageHWPoison(page);
81634- atomic_long_inc(&num_poisoned_pages);
81635+ atomic_long_inc_unchecked(&num_poisoned_pages);
81636 }
81637 }
81638 /* keep elevated page count for bad page */
81639@@ -1596,7 +1596,7 @@ static int __soft_offline_page(struct page *page, int flags)
81640 put_page(page);
81641 pr_info("soft_offline: %#lx: invalidated\n", pfn);
81642 SetPageHWPoison(page);
81643- atomic_long_inc(&num_poisoned_pages);
81644+ atomic_long_inc_unchecked(&num_poisoned_pages);
81645 return 0;
81646 }
81647
81648@@ -1626,7 +1626,7 @@ static int __soft_offline_page(struct page *page, int flags)
81649 ret = -EIO;
81650 } else {
81651 SetPageHWPoison(page);
81652- atomic_long_inc(&num_poisoned_pages);
81653+ atomic_long_inc_unchecked(&num_poisoned_pages);
81654 }
81655 } else {
81656 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
81657diff --git a/mm/memory.c b/mm/memory.c
81658index 61a262b..77a94d1 100644
81659--- a/mm/memory.c
81660+++ b/mm/memory.c
81661@@ -429,6 +429,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81662 free_pte_range(tlb, pmd, addr);
81663 } while (pmd++, addr = next, addr != end);
81664
81665+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
81666 start &= PUD_MASK;
81667 if (start < floor)
81668 return;
81669@@ -443,6 +444,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81670 pmd = pmd_offset(pud, start);
81671 pud_clear(pud);
81672 pmd_free_tlb(tlb, pmd, start);
81673+#endif
81674+
81675 }
81676
81677 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81678@@ -462,6 +465,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81679 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
81680 } while (pud++, addr = next, addr != end);
81681
81682+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
81683 start &= PGDIR_MASK;
81684 if (start < floor)
81685 return;
81686@@ -476,6 +480,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81687 pud = pud_offset(pgd, start);
81688 pgd_clear(pgd);
81689 pud_free_tlb(tlb, pud, start);
81690+#endif
81691+
81692 }
81693
81694 /*
81695@@ -1635,12 +1641,6 @@ no_page_table:
81696 return page;
81697 }
81698
81699-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
81700-{
81701- return stack_guard_page_start(vma, addr) ||
81702- stack_guard_page_end(vma, addr+PAGE_SIZE);
81703-}
81704-
81705 /**
81706 * __get_user_pages() - pin user pages in memory
81707 * @tsk: task_struct of target task
81708@@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81709
81710 i = 0;
81711
81712- do {
81713+ while (nr_pages) {
81714 struct vm_area_struct *vma;
81715
81716- vma = find_extend_vma(mm, start);
81717+ vma = find_vma(mm, start);
81718 if (!vma && in_gate_area(mm, start)) {
81719 unsigned long pg = start & PAGE_MASK;
81720 pgd_t *pgd;
81721@@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81722 goto next_page;
81723 }
81724
81725- if (!vma ||
81726+ if (!vma || start < vma->vm_start ||
81727 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
81728 !(vm_flags & vma->vm_flags))
81729 return i ? : -EFAULT;
81730@@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81731 int ret;
81732 unsigned int fault_flags = 0;
81733
81734- /* For mlock, just skip the stack guard page. */
81735- if (foll_flags & FOLL_MLOCK) {
81736- if (stack_guard_page(vma, start))
81737- goto next_page;
81738- }
81739 if (foll_flags & FOLL_WRITE)
81740 fault_flags |= FAULT_FLAG_WRITE;
81741 if (nonblocking)
81742@@ -1892,7 +1887,7 @@ next_page:
81743 start += page_increm * PAGE_SIZE;
81744 nr_pages -= page_increm;
81745 } while (nr_pages && start < vma->vm_end);
81746- } while (nr_pages);
81747+ }
81748 return i;
81749 }
81750 EXPORT_SYMBOL(__get_user_pages);
81751@@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
81752 page_add_file_rmap(page);
81753 set_pte_at(mm, addr, pte, mk_pte(page, prot));
81754
81755+#ifdef CONFIG_PAX_SEGMEXEC
81756+ pax_mirror_file_pte(vma, addr, page, ptl);
81757+#endif
81758+
81759 retval = 0;
81760 pte_unmap_unlock(pte, ptl);
81761 return retval;
81762@@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
81763 if (!page_count(page))
81764 return -EINVAL;
81765 if (!(vma->vm_flags & VM_MIXEDMAP)) {
81766+
81767+#ifdef CONFIG_PAX_SEGMEXEC
81768+ struct vm_area_struct *vma_m;
81769+#endif
81770+
81771 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
81772 BUG_ON(vma->vm_flags & VM_PFNMAP);
81773 vma->vm_flags |= VM_MIXEDMAP;
81774+
81775+#ifdef CONFIG_PAX_SEGMEXEC
81776+ vma_m = pax_find_mirror_vma(vma);
81777+ if (vma_m)
81778+ vma_m->vm_flags |= VM_MIXEDMAP;
81779+#endif
81780+
81781 }
81782 return insert_page(vma, addr, page, vma->vm_page_prot);
81783 }
81784@@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
81785 unsigned long pfn)
81786 {
81787 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
81788+ BUG_ON(vma->vm_mirror);
81789
81790 if (addr < vma->vm_start || addr >= vma->vm_end)
81791 return -EFAULT;
81792@@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
81793
81794 BUG_ON(pud_huge(*pud));
81795
81796- pmd = pmd_alloc(mm, pud, addr);
81797+ pmd = (mm == &init_mm) ?
81798+ pmd_alloc_kernel(mm, pud, addr) :
81799+ pmd_alloc(mm, pud, addr);
81800 if (!pmd)
81801 return -ENOMEM;
81802 do {
81803@@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
81804 unsigned long next;
81805 int err;
81806
81807- pud = pud_alloc(mm, pgd, addr);
81808+ pud = (mm == &init_mm) ?
81809+ pud_alloc_kernel(mm, pgd, addr) :
81810+ pud_alloc(mm, pgd, addr);
81811 if (!pud)
81812 return -ENOMEM;
81813 do {
81814@@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
81815 copy_user_highpage(dst, src, va, vma);
81816 }
81817
81818+#ifdef CONFIG_PAX_SEGMEXEC
81819+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
81820+{
81821+ struct mm_struct *mm = vma->vm_mm;
81822+ spinlock_t *ptl;
81823+ pte_t *pte, entry;
81824+
81825+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
81826+ entry = *pte;
81827+ if (!pte_present(entry)) {
81828+ if (!pte_none(entry)) {
81829+ BUG_ON(pte_file(entry));
81830+ free_swap_and_cache(pte_to_swp_entry(entry));
81831+ pte_clear_not_present_full(mm, address, pte, 0);
81832+ }
81833+ } else {
81834+ struct page *page;
81835+
81836+ flush_cache_page(vma, address, pte_pfn(entry));
81837+ entry = ptep_clear_flush(vma, address, pte);
81838+ BUG_ON(pte_dirty(entry));
81839+ page = vm_normal_page(vma, address, entry);
81840+ if (page) {
81841+ update_hiwater_rss(mm);
81842+ if (PageAnon(page))
81843+ dec_mm_counter_fast(mm, MM_ANONPAGES);
81844+ else
81845+ dec_mm_counter_fast(mm, MM_FILEPAGES);
81846+ page_remove_rmap(page);
81847+ page_cache_release(page);
81848+ }
81849+ }
81850+ pte_unmap_unlock(pte, ptl);
81851+}
81852+
81853+/* PaX: if vma is mirrored, synchronize the mirror's PTE
81854+ *
81855+ * the ptl of the lower mapped page is held on entry and is not released on exit
81856+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
81857+ */
81858+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81859+{
81860+ struct mm_struct *mm = vma->vm_mm;
81861+ unsigned long address_m;
81862+ spinlock_t *ptl_m;
81863+ struct vm_area_struct *vma_m;
81864+ pmd_t *pmd_m;
81865+ pte_t *pte_m, entry_m;
81866+
81867+ BUG_ON(!page_m || !PageAnon(page_m));
81868+
81869+ vma_m = pax_find_mirror_vma(vma);
81870+ if (!vma_m)
81871+ return;
81872+
81873+ BUG_ON(!PageLocked(page_m));
81874+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81875+ address_m = address + SEGMEXEC_TASK_SIZE;
81876+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81877+ pte_m = pte_offset_map(pmd_m, address_m);
81878+ ptl_m = pte_lockptr(mm, pmd_m);
81879+ if (ptl != ptl_m) {
81880+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81881+ if (!pte_none(*pte_m))
81882+ goto out;
81883+ }
81884+
81885+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81886+ page_cache_get(page_m);
81887+ page_add_anon_rmap(page_m, vma_m, address_m);
81888+ inc_mm_counter_fast(mm, MM_ANONPAGES);
81889+ set_pte_at(mm, address_m, pte_m, entry_m);
81890+ update_mmu_cache(vma_m, address_m, pte_m);
81891+out:
81892+ if (ptl != ptl_m)
81893+ spin_unlock(ptl_m);
81894+ pte_unmap(pte_m);
81895+ unlock_page(page_m);
81896+}
81897+
81898+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81899+{
81900+ struct mm_struct *mm = vma->vm_mm;
81901+ unsigned long address_m;
81902+ spinlock_t *ptl_m;
81903+ struct vm_area_struct *vma_m;
81904+ pmd_t *pmd_m;
81905+ pte_t *pte_m, entry_m;
81906+
81907+ BUG_ON(!page_m || PageAnon(page_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(page_to_pfn(page_m), vma_m->vm_page_prot);
81925+ page_cache_get(page_m);
81926+ page_add_file_rmap(page_m);
81927+ inc_mm_counter_fast(mm, MM_FILEPAGES);
81928+ set_pte_at(mm, address_m, pte_m, entry_m);
81929+ update_mmu_cache(vma_m, address_m, pte_m);
81930+out:
81931+ if (ptl != ptl_m)
81932+ spin_unlock(ptl_m);
81933+ pte_unmap(pte_m);
81934+}
81935+
81936+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
81937+{
81938+ struct mm_struct *mm = vma->vm_mm;
81939+ unsigned long address_m;
81940+ spinlock_t *ptl_m;
81941+ struct vm_area_struct *vma_m;
81942+ pmd_t *pmd_m;
81943+ pte_t *pte_m, entry_m;
81944+
81945+ vma_m = pax_find_mirror_vma(vma);
81946+ if (!vma_m)
81947+ return;
81948+
81949+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81950+ address_m = address + SEGMEXEC_TASK_SIZE;
81951+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81952+ pte_m = pte_offset_map(pmd_m, address_m);
81953+ ptl_m = pte_lockptr(mm, pmd_m);
81954+ if (ptl != ptl_m) {
81955+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81956+ if (!pte_none(*pte_m))
81957+ goto out;
81958+ }
81959+
81960+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
81961+ set_pte_at(mm, address_m, pte_m, entry_m);
81962+out:
81963+ if (ptl != ptl_m)
81964+ spin_unlock(ptl_m);
81965+ pte_unmap(pte_m);
81966+}
81967+
81968+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
81969+{
81970+ struct page *page_m;
81971+ pte_t entry;
81972+
81973+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
81974+ goto out;
81975+
81976+ entry = *pte;
81977+ page_m = vm_normal_page(vma, address, entry);
81978+ if (!page_m)
81979+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
81980+ else if (PageAnon(page_m)) {
81981+ if (pax_find_mirror_vma(vma)) {
81982+ pte_unmap_unlock(pte, ptl);
81983+ lock_page(page_m);
81984+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
81985+ if (pte_same(entry, *pte))
81986+ pax_mirror_anon_pte(vma, address, page_m, ptl);
81987+ else
81988+ unlock_page(page_m);
81989+ }
81990+ } else
81991+ pax_mirror_file_pte(vma, address, page_m, ptl);
81992+
81993+out:
81994+ pte_unmap_unlock(pte, ptl);
81995+}
81996+#endif
81997+
81998 /*
81999 * This routine handles present pages, when users try to write
82000 * to a shared page. It is done by copying the page to a new address
82001@@ -2799,6 +2995,12 @@ gotten:
82002 */
82003 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
82004 if (likely(pte_same(*page_table, orig_pte))) {
82005+
82006+#ifdef CONFIG_PAX_SEGMEXEC
82007+ if (pax_find_mirror_vma(vma))
82008+ BUG_ON(!trylock_page(new_page));
82009+#endif
82010+
82011 if (old_page) {
82012 if (!PageAnon(old_page)) {
82013 dec_mm_counter_fast(mm, MM_FILEPAGES);
82014@@ -2850,6 +3052,10 @@ gotten:
82015 page_remove_rmap(old_page);
82016 }
82017
82018+#ifdef CONFIG_PAX_SEGMEXEC
82019+ pax_mirror_anon_pte(vma, address, new_page, ptl);
82020+#endif
82021+
82022 /* Free the old page.. */
82023 new_page = old_page;
82024 ret |= VM_FAULT_WRITE;
82025@@ -3125,6 +3331,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
82026 swap_free(entry);
82027 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
82028 try_to_free_swap(page);
82029+
82030+#ifdef CONFIG_PAX_SEGMEXEC
82031+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
82032+#endif
82033+
82034 unlock_page(page);
82035 if (page != swapcache) {
82036 /*
82037@@ -3148,6 +3359,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
82038
82039 /* No need to invalidate - it was non-present before */
82040 update_mmu_cache(vma, address, page_table);
82041+
82042+#ifdef CONFIG_PAX_SEGMEXEC
82043+ pax_mirror_anon_pte(vma, address, page, ptl);
82044+#endif
82045+
82046 unlock:
82047 pte_unmap_unlock(page_table, ptl);
82048 out:
82049@@ -3167,40 +3383,6 @@ out_release:
82050 }
82051
82052 /*
82053- * This is like a special single-page "expand_{down|up}wards()",
82054- * except we must first make sure that 'address{-|+}PAGE_SIZE'
82055- * doesn't hit another vma.
82056- */
82057-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
82058-{
82059- address &= PAGE_MASK;
82060- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
82061- struct vm_area_struct *prev = vma->vm_prev;
82062-
82063- /*
82064- * Is there a mapping abutting this one below?
82065- *
82066- * That's only ok if it's the same stack mapping
82067- * that has gotten split..
82068- */
82069- if (prev && prev->vm_end == address)
82070- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
82071-
82072- expand_downwards(vma, address - PAGE_SIZE);
82073- }
82074- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
82075- struct vm_area_struct *next = vma->vm_next;
82076-
82077- /* As VM_GROWSDOWN but s/below/above/ */
82078- if (next && next->vm_start == address + PAGE_SIZE)
82079- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
82080-
82081- expand_upwards(vma, address + PAGE_SIZE);
82082- }
82083- return 0;
82084-}
82085-
82086-/*
82087 * We enter with non-exclusive mmap_sem (to exclude vma changes,
82088 * but allow concurrent faults), and pte mapped but not yet locked.
82089 * We return with mmap_sem still held, but pte unmapped and unlocked.
82090@@ -3209,27 +3391,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
82091 unsigned long address, pte_t *page_table, pmd_t *pmd,
82092 unsigned int flags)
82093 {
82094- struct page *page;
82095+ struct page *page = NULL;
82096 spinlock_t *ptl;
82097 pte_t entry;
82098
82099- pte_unmap(page_table);
82100-
82101- /* Check if we need to add a guard page to the stack */
82102- if (check_stack_guard_page(vma, address) < 0)
82103- return VM_FAULT_SIGBUS;
82104-
82105- /* Use the zero-page for reads */
82106 if (!(flags & FAULT_FLAG_WRITE)) {
82107 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
82108 vma->vm_page_prot));
82109- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
82110+ ptl = pte_lockptr(mm, pmd);
82111+ spin_lock(ptl);
82112 if (!pte_none(*page_table))
82113 goto unlock;
82114 goto setpte;
82115 }
82116
82117 /* Allocate our own private page. */
82118+ pte_unmap(page_table);
82119+
82120 if (unlikely(anon_vma_prepare(vma)))
82121 goto oom;
82122 page = alloc_zeroed_user_highpage_movable(vma, address);
82123@@ -3253,6 +3431,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
82124 if (!pte_none(*page_table))
82125 goto release;
82126
82127+#ifdef CONFIG_PAX_SEGMEXEC
82128+ if (pax_find_mirror_vma(vma))
82129+ BUG_ON(!trylock_page(page));
82130+#endif
82131+
82132 inc_mm_counter_fast(mm, MM_ANONPAGES);
82133 page_add_new_anon_rmap(page, vma, address);
82134 setpte:
82135@@ -3260,6 +3443,12 @@ setpte:
82136
82137 /* No need to invalidate - it was non-present before */
82138 update_mmu_cache(vma, address, page_table);
82139+
82140+#ifdef CONFIG_PAX_SEGMEXEC
82141+ if (page)
82142+ pax_mirror_anon_pte(vma, address, page, ptl);
82143+#endif
82144+
82145 unlock:
82146 pte_unmap_unlock(page_table, ptl);
82147 return 0;
82148@@ -3403,6 +3592,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82149 */
82150 /* Only go through if we didn't race with anybody else... */
82151 if (likely(pte_same(*page_table, orig_pte))) {
82152+
82153+#ifdef CONFIG_PAX_SEGMEXEC
82154+ if (anon && pax_find_mirror_vma(vma))
82155+ BUG_ON(!trylock_page(page));
82156+#endif
82157+
82158 flush_icache_page(vma, page);
82159 entry = mk_pte(page, vma->vm_page_prot);
82160 if (flags & FAULT_FLAG_WRITE)
82161@@ -3422,6 +3617,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82162
82163 /* no need to invalidate: a not-present page won't be cached */
82164 update_mmu_cache(vma, address, page_table);
82165+
82166+#ifdef CONFIG_PAX_SEGMEXEC
82167+ if (anon)
82168+ pax_mirror_anon_pte(vma, address, page, ptl);
82169+ else
82170+ pax_mirror_file_pte(vma, address, page, ptl);
82171+#endif
82172+
82173 } else {
82174 if (cow_page)
82175 mem_cgroup_uncharge_page(cow_page);
82176@@ -3743,6 +3946,12 @@ int handle_pte_fault(struct mm_struct *mm,
82177 if (flags & FAULT_FLAG_WRITE)
82178 flush_tlb_fix_spurious_fault(vma, address);
82179 }
82180+
82181+#ifdef CONFIG_PAX_SEGMEXEC
82182+ pax_mirror_pte(vma, address, pte, pmd, ptl);
82183+ return 0;
82184+#endif
82185+
82186 unlock:
82187 pte_unmap_unlock(pte, ptl);
82188 return 0;
82189@@ -3759,6 +3968,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82190 pmd_t *pmd;
82191 pte_t *pte;
82192
82193+#ifdef CONFIG_PAX_SEGMEXEC
82194+ struct vm_area_struct *vma_m;
82195+#endif
82196+
82197 __set_current_state(TASK_RUNNING);
82198
82199 count_vm_event(PGFAULT);
82200@@ -3770,6 +3983,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82201 if (unlikely(is_vm_hugetlb_page(vma)))
82202 return hugetlb_fault(mm, vma, address, flags);
82203
82204+#ifdef CONFIG_PAX_SEGMEXEC
82205+ vma_m = pax_find_mirror_vma(vma);
82206+ if (vma_m) {
82207+ unsigned long address_m;
82208+ pgd_t *pgd_m;
82209+ pud_t *pud_m;
82210+ pmd_t *pmd_m;
82211+
82212+ if (vma->vm_start > vma_m->vm_start) {
82213+ address_m = address;
82214+ address -= SEGMEXEC_TASK_SIZE;
82215+ vma = vma_m;
82216+ } else
82217+ address_m = address + SEGMEXEC_TASK_SIZE;
82218+
82219+ pgd_m = pgd_offset(mm, address_m);
82220+ pud_m = pud_alloc(mm, pgd_m, address_m);
82221+ if (!pud_m)
82222+ return VM_FAULT_OOM;
82223+ pmd_m = pmd_alloc(mm, pud_m, address_m);
82224+ if (!pmd_m)
82225+ return VM_FAULT_OOM;
82226+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
82227+ return VM_FAULT_OOM;
82228+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
82229+ }
82230+#endif
82231+
82232 retry:
82233 pgd = pgd_offset(mm, address);
82234 pud = pud_alloc(mm, pgd, address);
82235@@ -3868,6 +4109,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82236 spin_unlock(&mm->page_table_lock);
82237 return 0;
82238 }
82239+
82240+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82241+{
82242+ pud_t *new = pud_alloc_one(mm, address);
82243+ if (!new)
82244+ return -ENOMEM;
82245+
82246+ smp_wmb(); /* See comment in __pte_alloc */
82247+
82248+ spin_lock(&mm->page_table_lock);
82249+ if (pgd_present(*pgd)) /* Another has populated it */
82250+ pud_free(mm, new);
82251+ else
82252+ pgd_populate_kernel(mm, pgd, new);
82253+ spin_unlock(&mm->page_table_lock);
82254+ return 0;
82255+}
82256 #endif /* __PAGETABLE_PUD_FOLDED */
82257
82258 #ifndef __PAGETABLE_PMD_FOLDED
82259@@ -3898,6 +4156,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
82260 spin_unlock(&mm->page_table_lock);
82261 return 0;
82262 }
82263+
82264+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
82265+{
82266+ pmd_t *new = pmd_alloc_one(mm, address);
82267+ if (!new)
82268+ return -ENOMEM;
82269+
82270+ smp_wmb(); /* See comment in __pte_alloc */
82271+
82272+ spin_lock(&mm->page_table_lock);
82273+#ifndef __ARCH_HAS_4LEVEL_HACK
82274+ if (pud_present(*pud)) /* Another has populated it */
82275+ pmd_free(mm, new);
82276+ else
82277+ pud_populate_kernel(mm, pud, new);
82278+#else
82279+ if (pgd_present(*pud)) /* Another has populated it */
82280+ pmd_free(mm, new);
82281+ else
82282+ pgd_populate_kernel(mm, pud, new);
82283+#endif /* __ARCH_HAS_4LEVEL_HACK */
82284+ spin_unlock(&mm->page_table_lock);
82285+ return 0;
82286+}
82287 #endif /* __PAGETABLE_PMD_FOLDED */
82288
82289 #if !defined(__HAVE_ARCH_GATE_AREA)
82290@@ -3911,7 +4193,7 @@ static int __init gate_vma_init(void)
82291 gate_vma.vm_start = FIXADDR_USER_START;
82292 gate_vma.vm_end = FIXADDR_USER_END;
82293 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
82294- gate_vma.vm_page_prot = __P101;
82295+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
82296
82297 return 0;
82298 }
82299@@ -4045,8 +4327,8 @@ out:
82300 return ret;
82301 }
82302
82303-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82304- void *buf, int len, int write)
82305+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82306+ void *buf, size_t len, int write)
82307 {
82308 resource_size_t phys_addr;
82309 unsigned long prot = 0;
82310@@ -4071,8 +4353,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82311 * Access another process' address space as given in mm. If non-NULL, use the
82312 * given task for page fault accounting.
82313 */
82314-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82315- unsigned long addr, void *buf, int len, int write)
82316+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82317+ unsigned long addr, void *buf, size_t len, int write)
82318 {
82319 struct vm_area_struct *vma;
82320 void *old_buf = buf;
82321@@ -4080,7 +4362,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82322 down_read(&mm->mmap_sem);
82323 /* ignore errors, just check how much was successfully transferred */
82324 while (len) {
82325- int bytes, ret, offset;
82326+ ssize_t bytes, ret, offset;
82327 void *maddr;
82328 struct page *page = NULL;
82329
82330@@ -4139,8 +4421,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82331 *
82332 * The caller must hold a reference on @mm.
82333 */
82334-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82335- void *buf, int len, int write)
82336+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
82337+ void *buf, size_t len, int write)
82338 {
82339 return __access_remote_vm(NULL, mm, addr, buf, len, write);
82340 }
82341@@ -4150,11 +4432,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82342 * Source/target buffer must be kernel space,
82343 * Do not walk the page table directly, use get_user_pages
82344 */
82345-int access_process_vm(struct task_struct *tsk, unsigned long addr,
82346- void *buf, int len, int write)
82347+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
82348+ void *buf, size_t len, int write)
82349 {
82350 struct mm_struct *mm;
82351- int ret;
82352+ ssize_t ret;
82353
82354 mm = get_task_mm(tsk);
82355 if (!mm)
82356diff --git a/mm/mempolicy.c b/mm/mempolicy.c
82357index 7431001..0f8344e 100644
82358--- a/mm/mempolicy.c
82359+++ b/mm/mempolicy.c
82360@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82361 unsigned long vmstart;
82362 unsigned long vmend;
82363
82364+#ifdef CONFIG_PAX_SEGMEXEC
82365+ struct vm_area_struct *vma_m;
82366+#endif
82367+
82368 vma = find_vma(mm, start);
82369 if (!vma || vma->vm_start > start)
82370 return -EFAULT;
82371@@ -744,9 +748,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82372 if (err)
82373 goto out;
82374 }
82375+
82376 err = vma_replace_policy(vma, new_pol);
82377 if (err)
82378 goto out;
82379+
82380+#ifdef CONFIG_PAX_SEGMEXEC
82381+ vma_m = pax_find_mirror_vma(vma);
82382+ if (vma_m) {
82383+ err = vma_replace_policy(vma_m, new_pol);
82384+ if (err)
82385+ goto out;
82386+ }
82387+#endif
82388+
82389 }
82390
82391 out:
82392@@ -1202,6 +1217,17 @@ static long do_mbind(unsigned long start, unsigned long len,
82393
82394 if (end < start)
82395 return -EINVAL;
82396+
82397+#ifdef CONFIG_PAX_SEGMEXEC
82398+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82399+ if (end > SEGMEXEC_TASK_SIZE)
82400+ return -EINVAL;
82401+ } else
82402+#endif
82403+
82404+ if (end > TASK_SIZE)
82405+ return -EINVAL;
82406+
82407 if (end == start)
82408 return 0;
82409
82410@@ -1430,8 +1456,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82411 */
82412 tcred = __task_cred(task);
82413 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82414- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82415- !capable(CAP_SYS_NICE)) {
82416+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82417 rcu_read_unlock();
82418 err = -EPERM;
82419 goto out_put;
82420@@ -1462,6 +1487,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82421 goto out;
82422 }
82423
82424+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82425+ if (mm != current->mm &&
82426+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
82427+ mmput(mm);
82428+ err = -EPERM;
82429+ goto out;
82430+ }
82431+#endif
82432+
82433 err = do_migrate_pages(mm, old, new,
82434 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
82435
82436diff --git a/mm/migrate.c b/mm/migrate.c
82437index 6f0c244..6d1ae32 100644
82438--- a/mm/migrate.c
82439+++ b/mm/migrate.c
82440@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
82441 */
82442 tcred = __task_cred(task);
82443 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82444- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82445- !capable(CAP_SYS_NICE)) {
82446+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82447 rcu_read_unlock();
82448 err = -EPERM;
82449 goto out;
82450diff --git a/mm/mlock.c b/mm/mlock.c
82451index 79b7cf7..9944291 100644
82452--- a/mm/mlock.c
82453+++ b/mm/mlock.c
82454@@ -13,6 +13,7 @@
82455 #include <linux/pagemap.h>
82456 #include <linux/mempolicy.h>
82457 #include <linux/syscalls.h>
82458+#include <linux/security.h>
82459 #include <linux/sched.h>
82460 #include <linux/export.h>
82461 #include <linux/rmap.h>
82462@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
82463 {
82464 unsigned long nstart, end, tmp;
82465 struct vm_area_struct * vma, * prev;
82466- int error;
82467+ int error = 0;
82468
82469 VM_BUG_ON(start & ~PAGE_MASK);
82470 VM_BUG_ON(len != PAGE_ALIGN(len));
82471@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
82472 return -EINVAL;
82473 if (end == start)
82474 return 0;
82475+ if (end > TASK_SIZE)
82476+ return -EINVAL;
82477+
82478 vma = find_vma(current->mm, start);
82479 if (!vma || vma->vm_start > start)
82480 return -ENOMEM;
82481@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
82482 for (nstart = start ; ; ) {
82483 vm_flags_t newflags;
82484
82485+#ifdef CONFIG_PAX_SEGMEXEC
82486+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82487+ break;
82488+#endif
82489+
82490 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
82491
82492 newflags = vma->vm_flags & ~VM_LOCKED;
82493@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
82494 lock_limit >>= PAGE_SHIFT;
82495
82496 /* check against resource limits */
82497+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
82498 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
82499 error = do_mlock(start, len, 1);
82500 up_write(&current->mm->mmap_sem);
82501@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
82502 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
82503 vm_flags_t newflags;
82504
82505+#ifdef CONFIG_PAX_SEGMEXEC
82506+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82507+ break;
82508+#endif
82509+
82510 newflags = vma->vm_flags & ~VM_LOCKED;
82511 if (flags & MCL_CURRENT)
82512 newflags |= VM_LOCKED;
82513@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
82514 lock_limit >>= PAGE_SHIFT;
82515
82516 ret = -ENOMEM;
82517+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
82518 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
82519 capable(CAP_IPC_LOCK))
82520 ret = do_mlockall(flags);
82521diff --git a/mm/mmap.c b/mm/mmap.c
82522index f681e18..4c2577f 100644
82523--- a/mm/mmap.c
82524+++ b/mm/mmap.c
82525@@ -36,6 +36,7 @@
82526 #include <linux/sched/sysctl.h>
82527 #include <linux/notifier.h>
82528 #include <linux/memory.h>
82529+#include <linux/random.h>
82530
82531 #include <asm/uaccess.h>
82532 #include <asm/cacheflush.h>
82533@@ -52,6 +53,16 @@
82534 #define arch_rebalance_pgtables(addr, len) (addr)
82535 #endif
82536
82537+static inline void verify_mm_writelocked(struct mm_struct *mm)
82538+{
82539+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
82540+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82541+ up_read(&mm->mmap_sem);
82542+ BUG();
82543+ }
82544+#endif
82545+}
82546+
82547 static void unmap_region(struct mm_struct *mm,
82548 struct vm_area_struct *vma, struct vm_area_struct *prev,
82549 unsigned long start, unsigned long end);
82550@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
82551 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
82552 *
82553 */
82554-pgprot_t protection_map[16] = {
82555+pgprot_t protection_map[16] __read_only = {
82556 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
82557 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
82558 };
82559
82560-pgprot_t vm_get_page_prot(unsigned long vm_flags)
82561+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
82562 {
82563- return __pgprot(pgprot_val(protection_map[vm_flags &
82564+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
82565 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
82566 pgprot_val(arch_vm_get_page_prot(vm_flags)));
82567+
82568+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82569+ if (!(__supported_pte_mask & _PAGE_NX) &&
82570+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
82571+ (vm_flags & (VM_READ | VM_WRITE)))
82572+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
82573+#endif
82574+
82575+ return prot;
82576 }
82577 EXPORT_SYMBOL(vm_get_page_prot);
82578
82579@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
82580 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
82581 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
82582 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
82583+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
82584 /*
82585 * Make sure vm_committed_as in one cacheline and not cacheline shared with
82586 * other variables. It can be updated by several CPUs frequently.
82587@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
82588 struct vm_area_struct *next = vma->vm_next;
82589
82590 might_sleep();
82591+ BUG_ON(vma->vm_mirror);
82592 if (vma->vm_ops && vma->vm_ops->close)
82593 vma->vm_ops->close(vma);
82594 if (vma->vm_file)
82595@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
82596 * not page aligned -Ram Gupta
82597 */
82598 rlim = rlimit(RLIMIT_DATA);
82599+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
82600 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
82601 (mm->end_data - mm->start_data) > rlim)
82602 goto out;
82603@@ -933,6 +956,12 @@ static int
82604 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
82605 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82606 {
82607+
82608+#ifdef CONFIG_PAX_SEGMEXEC
82609+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
82610+ return 0;
82611+#endif
82612+
82613 if (is_mergeable_vma(vma, file, vm_flags) &&
82614 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82615 if (vma->vm_pgoff == vm_pgoff)
82616@@ -952,6 +981,12 @@ static int
82617 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82618 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82619 {
82620+
82621+#ifdef CONFIG_PAX_SEGMEXEC
82622+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
82623+ return 0;
82624+#endif
82625+
82626 if (is_mergeable_vma(vma, file, vm_flags) &&
82627 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82628 pgoff_t vm_pglen;
82629@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82630 struct vm_area_struct *vma_merge(struct mm_struct *mm,
82631 struct vm_area_struct *prev, unsigned long addr,
82632 unsigned long end, unsigned long vm_flags,
82633- struct anon_vma *anon_vma, struct file *file,
82634+ struct anon_vma *anon_vma, struct file *file,
82635 pgoff_t pgoff, struct mempolicy *policy)
82636 {
82637 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
82638 struct vm_area_struct *area, *next;
82639 int err;
82640
82641+#ifdef CONFIG_PAX_SEGMEXEC
82642+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
82643+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
82644+
82645+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
82646+#endif
82647+
82648 /*
82649 * We later require that vma->vm_flags == vm_flags,
82650 * so this tests vma->vm_flags & VM_SPECIAL, too.
82651@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82652 if (next && next->vm_end == end) /* cases 6, 7, 8 */
82653 next = next->vm_next;
82654
82655+#ifdef CONFIG_PAX_SEGMEXEC
82656+ if (prev)
82657+ prev_m = pax_find_mirror_vma(prev);
82658+ if (area)
82659+ area_m = pax_find_mirror_vma(area);
82660+ if (next)
82661+ next_m = pax_find_mirror_vma(next);
82662+#endif
82663+
82664 /*
82665 * Can it merge with the predecessor?
82666 */
82667@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82668 /* cases 1, 6 */
82669 err = vma_adjust(prev, prev->vm_start,
82670 next->vm_end, prev->vm_pgoff, NULL);
82671- } else /* cases 2, 5, 7 */
82672+
82673+#ifdef CONFIG_PAX_SEGMEXEC
82674+ if (!err && prev_m)
82675+ err = vma_adjust(prev_m, prev_m->vm_start,
82676+ next_m->vm_end, prev_m->vm_pgoff, NULL);
82677+#endif
82678+
82679+ } else { /* cases 2, 5, 7 */
82680 err = vma_adjust(prev, prev->vm_start,
82681 end, prev->vm_pgoff, NULL);
82682+
82683+#ifdef CONFIG_PAX_SEGMEXEC
82684+ if (!err && prev_m)
82685+ err = vma_adjust(prev_m, prev_m->vm_start,
82686+ end_m, prev_m->vm_pgoff, NULL);
82687+#endif
82688+
82689+ }
82690 if (err)
82691 return NULL;
82692 khugepaged_enter_vma_merge(prev);
82693@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82694 mpol_equal(policy, vma_policy(next)) &&
82695 can_vma_merge_before(next, vm_flags,
82696 anon_vma, file, pgoff+pglen)) {
82697- if (prev && addr < prev->vm_end) /* case 4 */
82698+ if (prev && addr < prev->vm_end) { /* case 4 */
82699 err = vma_adjust(prev, prev->vm_start,
82700 addr, prev->vm_pgoff, NULL);
82701- else /* cases 3, 8 */
82702+
82703+#ifdef CONFIG_PAX_SEGMEXEC
82704+ if (!err && prev_m)
82705+ err = vma_adjust(prev_m, prev_m->vm_start,
82706+ addr_m, prev_m->vm_pgoff, NULL);
82707+#endif
82708+
82709+ } else { /* cases 3, 8 */
82710 err = vma_adjust(area, addr, next->vm_end,
82711 next->vm_pgoff - pglen, NULL);
82712+
82713+#ifdef CONFIG_PAX_SEGMEXEC
82714+ if (!err && area_m)
82715+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
82716+ next_m->vm_pgoff - pglen, NULL);
82717+#endif
82718+
82719+ }
82720 if (err)
82721 return NULL;
82722 khugepaged_enter_vma_merge(area);
82723@@ -1165,8 +1246,10 @@ none:
82724 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82725 struct file *file, long pages)
82726 {
82727- const unsigned long stack_flags
82728- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
82729+
82730+#ifdef CONFIG_PAX_RANDMMAP
82731+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82732+#endif
82733
82734 mm->total_vm += pages;
82735
82736@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82737 mm->shared_vm += pages;
82738 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
82739 mm->exec_vm += pages;
82740- } else if (flags & stack_flags)
82741+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
82742 mm->stack_vm += pages;
82743 }
82744 #endif /* CONFIG_PROC_FS */
82745@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82746 * (the exception is when the underlying filesystem is noexec
82747 * mounted, in which case we dont add PROT_EXEC.)
82748 */
82749- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82750+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82751 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
82752 prot |= PROT_EXEC;
82753
82754@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82755 /* Obtain the address to map to. we verify (or select) it and ensure
82756 * that it represents a valid section of the address space.
82757 */
82758- addr = get_unmapped_area(file, addr, len, pgoff, flags);
82759+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
82760 if (addr & ~PAGE_MASK)
82761 return addr;
82762
82763@@ -1250,6 +1333,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82764 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
82765 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
82766
82767+#ifdef CONFIG_PAX_MPROTECT
82768+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82769+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82770+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
82771+ gr_log_rwxmmap(file);
82772+
82773+#ifdef CONFIG_PAX_EMUPLT
82774+ vm_flags &= ~VM_EXEC;
82775+#else
82776+ return -EPERM;
82777+#endif
82778+
82779+ }
82780+
82781+ if (!(vm_flags & VM_EXEC))
82782+ vm_flags &= ~VM_MAYEXEC;
82783+#else
82784+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82785+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82786+#endif
82787+ else
82788+ vm_flags &= ~VM_MAYWRITE;
82789+ }
82790+#endif
82791+
82792+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82793+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
82794+ vm_flags &= ~VM_PAGEEXEC;
82795+#endif
82796+
82797 if (flags & MAP_LOCKED)
82798 if (!can_do_mlock())
82799 return -EPERM;
82800@@ -1261,6 +1374,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82801 locked += mm->locked_vm;
82802 lock_limit = rlimit(RLIMIT_MEMLOCK);
82803 lock_limit >>= PAGE_SHIFT;
82804+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82805 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
82806 return -EAGAIN;
82807 }
82808@@ -1341,6 +1455,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82809 vm_flags |= VM_NORESERVE;
82810 }
82811
82812+ if (!gr_acl_handle_mmap(file, prot))
82813+ return -EACCES;
82814+
82815 addr = mmap_region(file, addr, len, vm_flags, pgoff);
82816 if (!IS_ERR_VALUE(addr) &&
82817 ((vm_flags & VM_LOCKED) ||
82818@@ -1432,7 +1549,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
82819 vm_flags_t vm_flags = vma->vm_flags;
82820
82821 /* If it was private or non-writable, the write bit is already clear */
82822- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
82823+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
82824 return 0;
82825
82826 /* The backer wishes to know when pages are first written to? */
82827@@ -1480,7 +1597,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82828 unsigned long charged = 0;
82829 struct inode *inode = file ? file_inode(file) : NULL;
82830
82831+#ifdef CONFIG_PAX_SEGMEXEC
82832+ struct vm_area_struct *vma_m = NULL;
82833+#endif
82834+
82835+ /*
82836+ * mm->mmap_sem is required to protect against another thread
82837+ * changing the mappings in case we sleep.
82838+ */
82839+ verify_mm_writelocked(mm);
82840+
82841 /* Check against address space limit. */
82842+
82843+#ifdef CONFIG_PAX_RANDMMAP
82844+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82845+#endif
82846+
82847 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
82848 unsigned long nr_pages;
82849
82850@@ -1499,11 +1631,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82851
82852 /* Clear old maps */
82853 error = -ENOMEM;
82854-munmap_back:
82855 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82856 if (do_munmap(mm, addr, len))
82857 return -ENOMEM;
82858- goto munmap_back;
82859+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82860 }
82861
82862 /*
82863@@ -1534,6 +1665,16 @@ munmap_back:
82864 goto unacct_error;
82865 }
82866
82867+#ifdef CONFIG_PAX_SEGMEXEC
82868+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
82869+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82870+ if (!vma_m) {
82871+ error = -ENOMEM;
82872+ goto free_vma;
82873+ }
82874+ }
82875+#endif
82876+
82877 vma->vm_mm = mm;
82878 vma->vm_start = addr;
82879 vma->vm_end = addr + len;
82880@@ -1558,6 +1699,13 @@ munmap_back:
82881 if (error)
82882 goto unmap_and_free_vma;
82883
82884+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82885+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
82886+ vma->vm_flags |= VM_PAGEEXEC;
82887+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82888+ }
82889+#endif
82890+
82891 /* Can addr have changed??
82892 *
82893 * Answer: Yes, several device drivers can do it in their
82894@@ -1596,6 +1744,11 @@ munmap_back:
82895 vma_link(mm, vma, prev, rb_link, rb_parent);
82896 file = vma->vm_file;
82897
82898+#ifdef CONFIG_PAX_SEGMEXEC
82899+ if (vma_m)
82900+ BUG_ON(pax_mirror_vma(vma_m, vma));
82901+#endif
82902+
82903 /* Once vma denies write, undo our temporary denial count */
82904 if (correct_wcount)
82905 atomic_inc(&inode->i_writecount);
82906@@ -1603,6 +1756,7 @@ out:
82907 perf_event_mmap(vma);
82908
82909 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
82910+ track_exec_limit(mm, addr, addr + len, vm_flags);
82911 if (vm_flags & VM_LOCKED) {
82912 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
82913 vma == get_gate_vma(current->mm)))
82914@@ -1626,6 +1780,12 @@ unmap_and_free_vma:
82915 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
82916 charged = 0;
82917 free_vma:
82918+
82919+#ifdef CONFIG_PAX_SEGMEXEC
82920+ if (vma_m)
82921+ kmem_cache_free(vm_area_cachep, vma_m);
82922+#endif
82923+
82924 kmem_cache_free(vm_area_cachep, vma);
82925 unacct_error:
82926 if (charged)
82927@@ -1633,7 +1793,63 @@ unacct_error:
82928 return error;
82929 }
82930
82931-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82932+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82933+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82934+{
82935+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
82936+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
82937+
82938+ return 0;
82939+}
82940+#endif
82941+
82942+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
82943+{
82944+ if (!vma) {
82945+#ifdef CONFIG_STACK_GROWSUP
82946+ if (addr > sysctl_heap_stack_gap)
82947+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
82948+ else
82949+ vma = find_vma(current->mm, 0);
82950+ if (vma && (vma->vm_flags & VM_GROWSUP))
82951+ return false;
82952+#endif
82953+ return true;
82954+ }
82955+
82956+ if (addr + len > vma->vm_start)
82957+ return false;
82958+
82959+ if (vma->vm_flags & VM_GROWSDOWN)
82960+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
82961+#ifdef CONFIG_STACK_GROWSUP
82962+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
82963+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
82964+#endif
82965+ else if (offset)
82966+ return offset <= vma->vm_start - addr - len;
82967+
82968+ return true;
82969+}
82970+
82971+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
82972+{
82973+ if (vma->vm_start < len)
82974+ return -ENOMEM;
82975+
82976+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
82977+ if (offset <= vma->vm_start - len)
82978+ return vma->vm_start - len - offset;
82979+ else
82980+ return -ENOMEM;
82981+ }
82982+
82983+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
82984+ return vma->vm_start - len - sysctl_heap_stack_gap;
82985+ return -ENOMEM;
82986+}
82987+
82988+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
82989 {
82990 /*
82991 * We implement the search by looking for an rbtree node that
82992@@ -1681,11 +1897,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82993 }
82994 }
82995
82996- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
82997+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
82998 check_current:
82999 /* Check if current node has a suitable gap */
83000 if (gap_start > high_limit)
83001 return -ENOMEM;
83002+
83003+ if (gap_end - gap_start > info->threadstack_offset)
83004+ gap_start += info->threadstack_offset;
83005+ else
83006+ gap_start = gap_end;
83007+
83008+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
83009+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83010+ gap_start += sysctl_heap_stack_gap;
83011+ else
83012+ gap_start = gap_end;
83013+ }
83014+ if (vma->vm_flags & VM_GROWSDOWN) {
83015+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83016+ gap_end -= sysctl_heap_stack_gap;
83017+ else
83018+ gap_end = gap_start;
83019+ }
83020 if (gap_end >= low_limit && gap_end - gap_start >= length)
83021 goto found;
83022
83023@@ -1735,7 +1969,7 @@ found:
83024 return gap_start;
83025 }
83026
83027-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
83028+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
83029 {
83030 struct mm_struct *mm = current->mm;
83031 struct vm_area_struct *vma;
83032@@ -1789,6 +2023,24 @@ check_current:
83033 gap_end = vma->vm_start;
83034 if (gap_end < low_limit)
83035 return -ENOMEM;
83036+
83037+ if (gap_end - gap_start > info->threadstack_offset)
83038+ gap_end -= info->threadstack_offset;
83039+ else
83040+ gap_end = gap_start;
83041+
83042+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
83043+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83044+ gap_start += sysctl_heap_stack_gap;
83045+ else
83046+ gap_start = gap_end;
83047+ }
83048+ if (vma->vm_flags & VM_GROWSDOWN) {
83049+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83050+ gap_end -= sysctl_heap_stack_gap;
83051+ else
83052+ gap_end = gap_start;
83053+ }
83054 if (gap_start <= high_limit && gap_end - gap_start >= length)
83055 goto found;
83056
83057@@ -1852,6 +2104,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
83058 struct mm_struct *mm = current->mm;
83059 struct vm_area_struct *vma;
83060 struct vm_unmapped_area_info info;
83061+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
83062
83063 if (len > TASK_SIZE)
83064 return -ENOMEM;
83065@@ -1859,29 +2112,45 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
83066 if (flags & MAP_FIXED)
83067 return addr;
83068
83069+#ifdef CONFIG_PAX_RANDMMAP
83070+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
83071+#endif
83072+
83073 if (addr) {
83074 addr = PAGE_ALIGN(addr);
83075 vma = find_vma(mm, addr);
83076- if (TASK_SIZE - len >= addr &&
83077- (!vma || addr + len <= vma->vm_start))
83078+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
83079 return addr;
83080 }
83081
83082 info.flags = 0;
83083 info.length = len;
83084 info.low_limit = TASK_UNMAPPED_BASE;
83085+
83086+#ifdef CONFIG_PAX_RANDMMAP
83087+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83088+ info.low_limit += mm->delta_mmap;
83089+#endif
83090+
83091 info.high_limit = TASK_SIZE;
83092 info.align_mask = 0;
83093+ info.threadstack_offset = offset;
83094 return vm_unmapped_area(&info);
83095 }
83096 #endif
83097
83098 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
83099 {
83100+
83101+#ifdef CONFIG_PAX_SEGMEXEC
83102+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
83103+ return;
83104+#endif
83105+
83106 /*
83107 * Is this a new hole at the lowest possible address?
83108 */
83109- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
83110+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
83111 mm->free_area_cache = addr;
83112 }
83113
83114@@ -1899,6 +2168,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83115 struct mm_struct *mm = current->mm;
83116 unsigned long addr = addr0;
83117 struct vm_unmapped_area_info info;
83118+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
83119
83120 /* requested length too big for entire address space */
83121 if (len > TASK_SIZE)
83122@@ -1907,12 +2177,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83123 if (flags & MAP_FIXED)
83124 return addr;
83125
83126+#ifdef CONFIG_PAX_RANDMMAP
83127+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
83128+#endif
83129+
83130 /* requesting a specific address */
83131 if (addr) {
83132 addr = PAGE_ALIGN(addr);
83133 vma = find_vma(mm, addr);
83134- if (TASK_SIZE - len >= addr &&
83135- (!vma || addr + len <= vma->vm_start))
83136+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
83137 return addr;
83138 }
83139
83140@@ -1921,6 +2194,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83141 info.low_limit = PAGE_SIZE;
83142 info.high_limit = mm->mmap_base;
83143 info.align_mask = 0;
83144+ info.threadstack_offset = offset;
83145 addr = vm_unmapped_area(&info);
83146
83147 /*
83148@@ -1933,6 +2207,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83149 VM_BUG_ON(addr != -ENOMEM);
83150 info.flags = 0;
83151 info.low_limit = TASK_UNMAPPED_BASE;
83152+
83153+#ifdef CONFIG_PAX_RANDMMAP
83154+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83155+ info.low_limit += mm->delta_mmap;
83156+#endif
83157+
83158 info.high_limit = TASK_SIZE;
83159 addr = vm_unmapped_area(&info);
83160 }
83161@@ -1943,6 +2223,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83162
83163 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
83164 {
83165+
83166+#ifdef CONFIG_PAX_SEGMEXEC
83167+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
83168+ return;
83169+#endif
83170+
83171 /*
83172 * Is this a new hole at the highest possible address?
83173 */
83174@@ -1950,8 +2236,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
83175 mm->free_area_cache = addr;
83176
83177 /* dont allow allocations above current base */
83178- if (mm->free_area_cache > mm->mmap_base)
83179+ if (mm->free_area_cache > mm->mmap_base) {
83180 mm->free_area_cache = mm->mmap_base;
83181+ mm->cached_hole_size = ~0UL;
83182+ }
83183 }
83184
83185 unsigned long
83186@@ -2047,6 +2335,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
83187 return vma;
83188 }
83189
83190+#ifdef CONFIG_PAX_SEGMEXEC
83191+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
83192+{
83193+ struct vm_area_struct *vma_m;
83194+
83195+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
83196+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
83197+ BUG_ON(vma->vm_mirror);
83198+ return NULL;
83199+ }
83200+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
83201+ vma_m = vma->vm_mirror;
83202+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
83203+ BUG_ON(vma->vm_file != vma_m->vm_file);
83204+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
83205+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
83206+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
83207+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
83208+ return vma_m;
83209+}
83210+#endif
83211+
83212 /*
83213 * Verify that the stack growth is acceptable and
83214 * update accounting. This is shared with both the
83215@@ -2063,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83216 return -ENOMEM;
83217
83218 /* Stack limit test */
83219+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
83220 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
83221 return -ENOMEM;
83222
83223@@ -2073,6 +2384,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83224 locked = mm->locked_vm + grow;
83225 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
83226 limit >>= PAGE_SHIFT;
83227+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
83228 if (locked > limit && !capable(CAP_IPC_LOCK))
83229 return -ENOMEM;
83230 }
83231@@ -2102,37 +2414,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83232 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
83233 * vma is the last one with address > vma->vm_end. Have to extend vma.
83234 */
83235+#ifndef CONFIG_IA64
83236+static
83237+#endif
83238 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83239 {
83240 int error;
83241+ bool locknext;
83242
83243 if (!(vma->vm_flags & VM_GROWSUP))
83244 return -EFAULT;
83245
83246+ /* Also guard against wrapping around to address 0. */
83247+ if (address < PAGE_ALIGN(address+1))
83248+ address = PAGE_ALIGN(address+1);
83249+ else
83250+ return -ENOMEM;
83251+
83252 /*
83253 * We must make sure the anon_vma is allocated
83254 * so that the anon_vma locking is not a noop.
83255 */
83256 if (unlikely(anon_vma_prepare(vma)))
83257 return -ENOMEM;
83258+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
83259+ if (locknext && anon_vma_prepare(vma->vm_next))
83260+ return -ENOMEM;
83261 vma_lock_anon_vma(vma);
83262+ if (locknext)
83263+ vma_lock_anon_vma(vma->vm_next);
83264
83265 /*
83266 * vma->vm_start/vm_end cannot change under us because the caller
83267 * is required to hold the mmap_sem in read mode. We need the
83268- * anon_vma lock to serialize against concurrent expand_stacks.
83269- * Also guard against wrapping around to address 0.
83270+ * anon_vma locks to serialize against concurrent expand_stacks
83271+ * and expand_upwards.
83272 */
83273- if (address < PAGE_ALIGN(address+4))
83274- address = PAGE_ALIGN(address+4);
83275- else {
83276- vma_unlock_anon_vma(vma);
83277- return -ENOMEM;
83278- }
83279 error = 0;
83280
83281 /* Somebody else might have raced and expanded it already */
83282- if (address > vma->vm_end) {
83283+ 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)
83284+ error = -ENOMEM;
83285+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
83286 unsigned long size, grow;
83287
83288 size = address - vma->vm_start;
83289@@ -2167,6 +2490,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83290 }
83291 }
83292 }
83293+ if (locknext)
83294+ vma_unlock_anon_vma(vma->vm_next);
83295 vma_unlock_anon_vma(vma);
83296 khugepaged_enter_vma_merge(vma);
83297 validate_mm(vma->vm_mm);
83298@@ -2181,6 +2506,8 @@ int expand_downwards(struct vm_area_struct *vma,
83299 unsigned long address)
83300 {
83301 int error;
83302+ bool lockprev = false;
83303+ struct vm_area_struct *prev;
83304
83305 /*
83306 * We must make sure the anon_vma is allocated
83307@@ -2194,6 +2521,15 @@ int expand_downwards(struct vm_area_struct *vma,
83308 if (error)
83309 return error;
83310
83311+ prev = vma->vm_prev;
83312+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
83313+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
83314+#endif
83315+ if (lockprev && anon_vma_prepare(prev))
83316+ return -ENOMEM;
83317+ if (lockprev)
83318+ vma_lock_anon_vma(prev);
83319+
83320 vma_lock_anon_vma(vma);
83321
83322 /*
83323@@ -2203,9 +2539,17 @@ int expand_downwards(struct vm_area_struct *vma,
83324 */
83325
83326 /* Somebody else might have raced and expanded it already */
83327- if (address < vma->vm_start) {
83328+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
83329+ error = -ENOMEM;
83330+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
83331 unsigned long size, grow;
83332
83333+#ifdef CONFIG_PAX_SEGMEXEC
83334+ struct vm_area_struct *vma_m;
83335+
83336+ vma_m = pax_find_mirror_vma(vma);
83337+#endif
83338+
83339 size = vma->vm_end - address;
83340 grow = (vma->vm_start - address) >> PAGE_SHIFT;
83341
83342@@ -2230,13 +2574,27 @@ int expand_downwards(struct vm_area_struct *vma,
83343 vma->vm_pgoff -= grow;
83344 anon_vma_interval_tree_post_update_vma(vma);
83345 vma_gap_update(vma);
83346+
83347+#ifdef CONFIG_PAX_SEGMEXEC
83348+ if (vma_m) {
83349+ anon_vma_interval_tree_pre_update_vma(vma_m);
83350+ vma_m->vm_start -= grow << PAGE_SHIFT;
83351+ vma_m->vm_pgoff -= grow;
83352+ anon_vma_interval_tree_post_update_vma(vma_m);
83353+ vma_gap_update(vma_m);
83354+ }
83355+#endif
83356+
83357 spin_unlock(&vma->vm_mm->page_table_lock);
83358
83359+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
83360 perf_event_mmap(vma);
83361 }
83362 }
83363 }
83364 vma_unlock_anon_vma(vma);
83365+ if (lockprev)
83366+ vma_unlock_anon_vma(prev);
83367 khugepaged_enter_vma_merge(vma);
83368 validate_mm(vma->vm_mm);
83369 return error;
83370@@ -2334,6 +2692,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
83371 do {
83372 long nrpages = vma_pages(vma);
83373
83374+#ifdef CONFIG_PAX_SEGMEXEC
83375+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
83376+ vma = remove_vma(vma);
83377+ continue;
83378+ }
83379+#endif
83380+
83381 if (vma->vm_flags & VM_ACCOUNT)
83382 nr_accounted += nrpages;
83383 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
83384@@ -2379,6 +2744,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
83385 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
83386 vma->vm_prev = NULL;
83387 do {
83388+
83389+#ifdef CONFIG_PAX_SEGMEXEC
83390+ if (vma->vm_mirror) {
83391+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
83392+ vma->vm_mirror->vm_mirror = NULL;
83393+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
83394+ vma->vm_mirror = NULL;
83395+ }
83396+#endif
83397+
83398 vma_rb_erase(vma, &mm->mm_rb);
83399 mm->map_count--;
83400 tail_vma = vma;
83401@@ -2410,14 +2785,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83402 struct vm_area_struct *new;
83403 int err = -ENOMEM;
83404
83405+#ifdef CONFIG_PAX_SEGMEXEC
83406+ struct vm_area_struct *vma_m, *new_m = NULL;
83407+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
83408+#endif
83409+
83410 if (is_vm_hugetlb_page(vma) && (addr &
83411 ~(huge_page_mask(hstate_vma(vma)))))
83412 return -EINVAL;
83413
83414+#ifdef CONFIG_PAX_SEGMEXEC
83415+ vma_m = pax_find_mirror_vma(vma);
83416+#endif
83417+
83418 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
83419 if (!new)
83420 goto out_err;
83421
83422+#ifdef CONFIG_PAX_SEGMEXEC
83423+ if (vma_m) {
83424+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
83425+ if (!new_m) {
83426+ kmem_cache_free(vm_area_cachep, new);
83427+ goto out_err;
83428+ }
83429+ }
83430+#endif
83431+
83432 /* most fields are the same, copy all, and then fixup */
83433 *new = *vma;
83434
83435@@ -2430,6 +2824,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83436 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
83437 }
83438
83439+#ifdef CONFIG_PAX_SEGMEXEC
83440+ if (vma_m) {
83441+ *new_m = *vma_m;
83442+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
83443+ new_m->vm_mirror = new;
83444+ new->vm_mirror = new_m;
83445+
83446+ if (new_below)
83447+ new_m->vm_end = addr_m;
83448+ else {
83449+ new_m->vm_start = addr_m;
83450+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
83451+ }
83452+ }
83453+#endif
83454+
83455 pol = mpol_dup(vma_policy(vma));
83456 if (IS_ERR(pol)) {
83457 err = PTR_ERR(pol);
83458@@ -2452,6 +2862,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83459 else
83460 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
83461
83462+#ifdef CONFIG_PAX_SEGMEXEC
83463+ if (!err && vma_m) {
83464+ if (anon_vma_clone(new_m, vma_m))
83465+ goto out_free_mpol;
83466+
83467+ mpol_get(pol);
83468+ vma_set_policy(new_m, pol);
83469+
83470+ if (new_m->vm_file)
83471+ get_file(new_m->vm_file);
83472+
83473+ if (new_m->vm_ops && new_m->vm_ops->open)
83474+ new_m->vm_ops->open(new_m);
83475+
83476+ if (new_below)
83477+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
83478+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
83479+ else
83480+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
83481+
83482+ if (err) {
83483+ if (new_m->vm_ops && new_m->vm_ops->close)
83484+ new_m->vm_ops->close(new_m);
83485+ if (new_m->vm_file)
83486+ fput(new_m->vm_file);
83487+ mpol_put(pol);
83488+ }
83489+ }
83490+#endif
83491+
83492 /* Success. */
83493 if (!err)
83494 return 0;
83495@@ -2461,10 +2901,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83496 new->vm_ops->close(new);
83497 if (new->vm_file)
83498 fput(new->vm_file);
83499- unlink_anon_vmas(new);
83500 out_free_mpol:
83501 mpol_put(pol);
83502 out_free_vma:
83503+
83504+#ifdef CONFIG_PAX_SEGMEXEC
83505+ if (new_m) {
83506+ unlink_anon_vmas(new_m);
83507+ kmem_cache_free(vm_area_cachep, new_m);
83508+ }
83509+#endif
83510+
83511+ unlink_anon_vmas(new);
83512 kmem_cache_free(vm_area_cachep, new);
83513 out_err:
83514 return err;
83515@@ -2477,6 +2925,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83516 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83517 unsigned long addr, int new_below)
83518 {
83519+
83520+#ifdef CONFIG_PAX_SEGMEXEC
83521+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
83522+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
83523+ if (mm->map_count >= sysctl_max_map_count-1)
83524+ return -ENOMEM;
83525+ } else
83526+#endif
83527+
83528 if (mm->map_count >= sysctl_max_map_count)
83529 return -ENOMEM;
83530
83531@@ -2488,11 +2945,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83532 * work. This now handles partial unmappings.
83533 * Jeremy Fitzhardinge <jeremy@goop.org>
83534 */
83535+#ifdef CONFIG_PAX_SEGMEXEC
83536 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83537 {
83538+ int ret = __do_munmap(mm, start, len);
83539+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
83540+ return ret;
83541+
83542+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
83543+}
83544+
83545+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83546+#else
83547+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83548+#endif
83549+{
83550 unsigned long end;
83551 struct vm_area_struct *vma, *prev, *last;
83552
83553+ /*
83554+ * mm->mmap_sem is required to protect against another thread
83555+ * changing the mappings in case we sleep.
83556+ */
83557+ verify_mm_writelocked(mm);
83558+
83559 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
83560 return -EINVAL;
83561
83562@@ -2567,6 +3043,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83563 /* Fix up all other VM information */
83564 remove_vma_list(mm, vma);
83565
83566+ track_exec_limit(mm, start, end, 0UL);
83567+
83568 return 0;
83569 }
83570
83571@@ -2575,6 +3053,13 @@ int vm_munmap(unsigned long start, size_t len)
83572 int ret;
83573 struct mm_struct *mm = current->mm;
83574
83575+
83576+#ifdef CONFIG_PAX_SEGMEXEC
83577+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
83578+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
83579+ return -EINVAL;
83580+#endif
83581+
83582 down_write(&mm->mmap_sem);
83583 ret = do_munmap(mm, start, len);
83584 up_write(&mm->mmap_sem);
83585@@ -2588,16 +3073,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
83586 return vm_munmap(addr, len);
83587 }
83588
83589-static inline void verify_mm_writelocked(struct mm_struct *mm)
83590-{
83591-#ifdef CONFIG_DEBUG_VM
83592- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
83593- WARN_ON(1);
83594- up_read(&mm->mmap_sem);
83595- }
83596-#endif
83597-}
83598-
83599 /*
83600 * this is really a simplified "do_mmap". it only handles
83601 * anonymous maps. eventually we may be able to do some
83602@@ -2611,6 +3086,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83603 struct rb_node ** rb_link, * rb_parent;
83604 pgoff_t pgoff = addr >> PAGE_SHIFT;
83605 int error;
83606+ unsigned long charged;
83607
83608 len = PAGE_ALIGN(len);
83609 if (!len)
83610@@ -2618,16 +3094,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83611
83612 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
83613
83614+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
83615+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
83616+ flags &= ~VM_EXEC;
83617+
83618+#ifdef CONFIG_PAX_MPROTECT
83619+ if (mm->pax_flags & MF_PAX_MPROTECT)
83620+ flags &= ~VM_MAYEXEC;
83621+#endif
83622+
83623+ }
83624+#endif
83625+
83626 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
83627 if (error & ~PAGE_MASK)
83628 return error;
83629
83630+ charged = len >> PAGE_SHIFT;
83631+
83632 /*
83633 * mlock MCL_FUTURE?
83634 */
83635 if (mm->def_flags & VM_LOCKED) {
83636 unsigned long locked, lock_limit;
83637- locked = len >> PAGE_SHIFT;
83638+ locked = charged;
83639 locked += mm->locked_vm;
83640 lock_limit = rlimit(RLIMIT_MEMLOCK);
83641 lock_limit >>= PAGE_SHIFT;
83642@@ -2644,21 +3134,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83643 /*
83644 * Clear old maps. this also does some error checking for us
83645 */
83646- munmap_back:
83647 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
83648 if (do_munmap(mm, addr, len))
83649 return -ENOMEM;
83650- goto munmap_back;
83651+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
83652 }
83653
83654 /* Check against address space limits *after* clearing old maps... */
83655- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
83656+ if (!may_expand_vm(mm, charged))
83657 return -ENOMEM;
83658
83659 if (mm->map_count > sysctl_max_map_count)
83660 return -ENOMEM;
83661
83662- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
83663+ if (security_vm_enough_memory_mm(mm, charged))
83664 return -ENOMEM;
83665
83666 /* Can we just expand an old private anonymous mapping? */
83667@@ -2672,7 +3161,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83668 */
83669 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83670 if (!vma) {
83671- vm_unacct_memory(len >> PAGE_SHIFT);
83672+ vm_unacct_memory(charged);
83673 return -ENOMEM;
83674 }
83675
83676@@ -2686,9 +3175,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83677 vma_link(mm, vma, prev, rb_link, rb_parent);
83678 out:
83679 perf_event_mmap(vma);
83680- mm->total_vm += len >> PAGE_SHIFT;
83681+ mm->total_vm += charged;
83682 if (flags & VM_LOCKED)
83683- mm->locked_vm += (len >> PAGE_SHIFT);
83684+ mm->locked_vm += charged;
83685+ track_exec_limit(mm, addr, addr + len, flags);
83686 return addr;
83687 }
83688
83689@@ -2750,6 +3240,7 @@ void exit_mmap(struct mm_struct *mm)
83690 while (vma) {
83691 if (vma->vm_flags & VM_ACCOUNT)
83692 nr_accounted += vma_pages(vma);
83693+ vma->vm_mirror = NULL;
83694 vma = remove_vma(vma);
83695 }
83696 vm_unacct_memory(nr_accounted);
83697@@ -2766,6 +3257,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83698 struct vm_area_struct *prev;
83699 struct rb_node **rb_link, *rb_parent;
83700
83701+#ifdef CONFIG_PAX_SEGMEXEC
83702+ struct vm_area_struct *vma_m = NULL;
83703+#endif
83704+
83705+ if (security_mmap_addr(vma->vm_start))
83706+ return -EPERM;
83707+
83708 /*
83709 * The vm_pgoff of a purely anonymous vma should be irrelevant
83710 * until its first write fault, when page's anon_vma and index
83711@@ -2789,7 +3287,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83712 security_vm_enough_memory_mm(mm, vma_pages(vma)))
83713 return -ENOMEM;
83714
83715+#ifdef CONFIG_PAX_SEGMEXEC
83716+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
83717+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83718+ if (!vma_m)
83719+ return -ENOMEM;
83720+ }
83721+#endif
83722+
83723 vma_link(mm, vma, prev, rb_link, rb_parent);
83724+
83725+#ifdef CONFIG_PAX_SEGMEXEC
83726+ if (vma_m)
83727+ BUG_ON(pax_mirror_vma(vma_m, vma));
83728+#endif
83729+
83730 return 0;
83731 }
83732
83733@@ -2809,6 +3321,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83734 struct mempolicy *pol;
83735 bool faulted_in_anon_vma = true;
83736
83737+ BUG_ON(vma->vm_mirror);
83738+
83739 /*
83740 * If anonymous vma has not yet been faulted, update new pgoff
83741 * to match new location, to increase its chance of merging.
83742@@ -2875,6 +3389,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83743 return NULL;
83744 }
83745
83746+#ifdef CONFIG_PAX_SEGMEXEC
83747+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
83748+{
83749+ struct vm_area_struct *prev_m;
83750+ struct rb_node **rb_link_m, *rb_parent_m;
83751+ struct mempolicy *pol_m;
83752+
83753+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
83754+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
83755+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
83756+ *vma_m = *vma;
83757+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
83758+ if (anon_vma_clone(vma_m, vma))
83759+ return -ENOMEM;
83760+ pol_m = vma_policy(vma_m);
83761+ mpol_get(pol_m);
83762+ vma_set_policy(vma_m, pol_m);
83763+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
83764+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
83765+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
83766+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
83767+ if (vma_m->vm_file)
83768+ get_file(vma_m->vm_file);
83769+ if (vma_m->vm_ops && vma_m->vm_ops->open)
83770+ vma_m->vm_ops->open(vma_m);
83771+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
83772+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
83773+ vma_m->vm_mirror = vma;
83774+ vma->vm_mirror = vma_m;
83775+ return 0;
83776+}
83777+#endif
83778+
83779 /*
83780 * Return true if the calling process may expand its vm space by the passed
83781 * number of pages
83782@@ -2886,6 +3433,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
83783
83784 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
83785
83786+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
83787 if (cur + npages > lim)
83788 return 0;
83789 return 1;
83790@@ -2956,6 +3504,22 @@ int install_special_mapping(struct mm_struct *mm,
83791 vma->vm_start = addr;
83792 vma->vm_end = addr + len;
83793
83794+#ifdef CONFIG_PAX_MPROTECT
83795+ if (mm->pax_flags & MF_PAX_MPROTECT) {
83796+#ifndef CONFIG_PAX_MPROTECT_COMPAT
83797+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
83798+ return -EPERM;
83799+ if (!(vm_flags & VM_EXEC))
83800+ vm_flags &= ~VM_MAYEXEC;
83801+#else
83802+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
83803+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
83804+#endif
83805+ else
83806+ vm_flags &= ~VM_MAYWRITE;
83807+ }
83808+#endif
83809+
83810 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
83811 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
83812
83813diff --git a/mm/mprotect.c b/mm/mprotect.c
83814index 94722a4..07d9926 100644
83815--- a/mm/mprotect.c
83816+++ b/mm/mprotect.c
83817@@ -23,10 +23,18 @@
83818 #include <linux/mmu_notifier.h>
83819 #include <linux/migrate.h>
83820 #include <linux/perf_event.h>
83821+#include <linux/sched/sysctl.h>
83822+
83823+#ifdef CONFIG_PAX_MPROTECT
83824+#include <linux/elf.h>
83825+#include <linux/binfmts.h>
83826+#endif
83827+
83828 #include <asm/uaccess.h>
83829 #include <asm/pgtable.h>
83830 #include <asm/cacheflush.h>
83831 #include <asm/tlbflush.h>
83832+#include <asm/mmu_context.h>
83833
83834 #ifndef pgprot_modify
83835 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
83836@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
83837 return pages;
83838 }
83839
83840+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83841+/* called while holding the mmap semaphor for writing except stack expansion */
83842+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
83843+{
83844+ unsigned long oldlimit, newlimit = 0UL;
83845+
83846+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
83847+ return;
83848+
83849+ spin_lock(&mm->page_table_lock);
83850+ oldlimit = mm->context.user_cs_limit;
83851+ if ((prot & VM_EXEC) && oldlimit < end)
83852+ /* USER_CS limit moved up */
83853+ newlimit = end;
83854+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
83855+ /* USER_CS limit moved down */
83856+ newlimit = start;
83857+
83858+ if (newlimit) {
83859+ mm->context.user_cs_limit = newlimit;
83860+
83861+#ifdef CONFIG_SMP
83862+ wmb();
83863+ cpus_clear(mm->context.cpu_user_cs_mask);
83864+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
83865+#endif
83866+
83867+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
83868+ }
83869+ spin_unlock(&mm->page_table_lock);
83870+ if (newlimit == end) {
83871+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
83872+
83873+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
83874+ if (is_vm_hugetlb_page(vma))
83875+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
83876+ else
83877+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
83878+ }
83879+}
83880+#endif
83881+
83882 int
83883 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83884 unsigned long start, unsigned long end, unsigned long newflags)
83885@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83886 int error;
83887 int dirty_accountable = 0;
83888
83889+#ifdef CONFIG_PAX_SEGMEXEC
83890+ struct vm_area_struct *vma_m = NULL;
83891+ unsigned long start_m, end_m;
83892+
83893+ start_m = start + SEGMEXEC_TASK_SIZE;
83894+ end_m = end + SEGMEXEC_TASK_SIZE;
83895+#endif
83896+
83897 if (newflags == oldflags) {
83898 *pprev = vma;
83899 return 0;
83900 }
83901
83902+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
83903+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
83904+
83905+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
83906+ return -ENOMEM;
83907+
83908+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
83909+ return -ENOMEM;
83910+ }
83911+
83912 /*
83913 * If we make a private mapping writable we increase our commit;
83914 * but (without finer accounting) cannot reduce our commit if we
83915@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83916 }
83917 }
83918
83919+#ifdef CONFIG_PAX_SEGMEXEC
83920+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
83921+ if (start != vma->vm_start) {
83922+ error = split_vma(mm, vma, start, 1);
83923+ if (error)
83924+ goto fail;
83925+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
83926+ *pprev = (*pprev)->vm_next;
83927+ }
83928+
83929+ if (end != vma->vm_end) {
83930+ error = split_vma(mm, vma, end, 0);
83931+ if (error)
83932+ goto fail;
83933+ }
83934+
83935+ if (pax_find_mirror_vma(vma)) {
83936+ error = __do_munmap(mm, start_m, end_m - start_m);
83937+ if (error)
83938+ goto fail;
83939+ } else {
83940+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83941+ if (!vma_m) {
83942+ error = -ENOMEM;
83943+ goto fail;
83944+ }
83945+ vma->vm_flags = newflags;
83946+ error = pax_mirror_vma(vma_m, vma);
83947+ if (error) {
83948+ vma->vm_flags = oldflags;
83949+ goto fail;
83950+ }
83951+ }
83952+ }
83953+#endif
83954+
83955 /*
83956 * First try to merge with previous and/or next vma.
83957 */
83958@@ -296,9 +400,21 @@ success:
83959 * vm_flags and vm_page_prot are protected by the mmap_sem
83960 * held in write mode.
83961 */
83962+
83963+#ifdef CONFIG_PAX_SEGMEXEC
83964+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
83965+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
83966+#endif
83967+
83968 vma->vm_flags = newflags;
83969+
83970+#ifdef CONFIG_PAX_MPROTECT
83971+ if (mm->binfmt && mm->binfmt->handle_mprotect)
83972+ mm->binfmt->handle_mprotect(vma, newflags);
83973+#endif
83974+
83975 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
83976- vm_get_page_prot(newflags));
83977+ vm_get_page_prot(vma->vm_flags));
83978
83979 if (vma_wants_writenotify(vma)) {
83980 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
83981@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83982 end = start + len;
83983 if (end <= start)
83984 return -ENOMEM;
83985+
83986+#ifdef CONFIG_PAX_SEGMEXEC
83987+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
83988+ if (end > SEGMEXEC_TASK_SIZE)
83989+ return -EINVAL;
83990+ } else
83991+#endif
83992+
83993+ if (end > TASK_SIZE)
83994+ return -EINVAL;
83995+
83996 if (!arch_validate_prot(prot))
83997 return -EINVAL;
83998
83999@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84000 /*
84001 * Does the application expect PROT_READ to imply PROT_EXEC:
84002 */
84003- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
84004+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
84005 prot |= PROT_EXEC;
84006
84007 vm_flags = calc_vm_prot_bits(prot);
84008@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84009 if (start > vma->vm_start)
84010 prev = vma;
84011
84012+#ifdef CONFIG_PAX_MPROTECT
84013+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
84014+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
84015+#endif
84016+
84017 for (nstart = start ; ; ) {
84018 unsigned long newflags;
84019
84020@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84021
84022 /* newflags >> 4 shift VM_MAY% in place of VM_% */
84023 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
84024+ if (prot & (PROT_WRITE | PROT_EXEC))
84025+ gr_log_rwxmprotect(vma->vm_file);
84026+
84027+ error = -EACCES;
84028+ goto out;
84029+ }
84030+
84031+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
84032 error = -EACCES;
84033 goto out;
84034 }
84035@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84036 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
84037 if (error)
84038 goto out;
84039+
84040+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
84041+
84042 nstart = tmp;
84043
84044 if (nstart < prev->vm_end)
84045diff --git a/mm/mremap.c b/mm/mremap.c
84046index 463a257..c0c7a92 100644
84047--- a/mm/mremap.c
84048+++ b/mm/mremap.c
84049@@ -126,6 +126,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
84050 continue;
84051 pte = ptep_get_and_clear(mm, old_addr, old_pte);
84052 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
84053+
84054+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
84055+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
84056+ pte = pte_exprotect(pte);
84057+#endif
84058+
84059 set_pte_at(mm, new_addr, new_pte, pte);
84060 }
84061
84062@@ -318,6 +324,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
84063 if (is_vm_hugetlb_page(vma))
84064 goto Einval;
84065
84066+#ifdef CONFIG_PAX_SEGMEXEC
84067+ if (pax_find_mirror_vma(vma))
84068+ goto Einval;
84069+#endif
84070+
84071 /* We can't remap across vm area boundaries */
84072 if (old_len > vma->vm_end - addr)
84073 goto Efault;
84074@@ -373,20 +384,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
84075 unsigned long ret = -EINVAL;
84076 unsigned long charged = 0;
84077 unsigned long map_flags;
84078+ unsigned long pax_task_size = TASK_SIZE;
84079
84080 if (new_addr & ~PAGE_MASK)
84081 goto out;
84082
84083- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
84084+#ifdef CONFIG_PAX_SEGMEXEC
84085+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
84086+ pax_task_size = SEGMEXEC_TASK_SIZE;
84087+#endif
84088+
84089+ pax_task_size -= PAGE_SIZE;
84090+
84091+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
84092 goto out;
84093
84094 /* Check if the location we're moving into overlaps the
84095 * old location at all, and fail if it does.
84096 */
84097- if ((new_addr <= addr) && (new_addr+new_len) > addr)
84098- goto out;
84099-
84100- if ((addr <= new_addr) && (addr+old_len) > new_addr)
84101+ if (addr + old_len > new_addr && new_addr + new_len > addr)
84102 goto out;
84103
84104 ret = do_munmap(mm, new_addr, new_len);
84105@@ -455,6 +471,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84106 unsigned long ret = -EINVAL;
84107 unsigned long charged = 0;
84108 bool locked = false;
84109+ unsigned long pax_task_size = TASK_SIZE;
84110
84111 down_write(&current->mm->mmap_sem);
84112
84113@@ -475,6 +492,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84114 if (!new_len)
84115 goto out;
84116
84117+#ifdef CONFIG_PAX_SEGMEXEC
84118+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
84119+ pax_task_size = SEGMEXEC_TASK_SIZE;
84120+#endif
84121+
84122+ pax_task_size -= PAGE_SIZE;
84123+
84124+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
84125+ old_len > pax_task_size || addr > pax_task_size-old_len)
84126+ goto out;
84127+
84128 if (flags & MREMAP_FIXED) {
84129 if (flags & MREMAP_MAYMOVE)
84130 ret = mremap_to(addr, old_len, new_addr, new_len,
84131@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84132 new_addr = addr;
84133 }
84134 ret = addr;
84135+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
84136 goto out;
84137 }
84138 }
84139@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84140 goto out;
84141 }
84142
84143+ map_flags = vma->vm_flags;
84144 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
84145+ if (!(ret & ~PAGE_MASK)) {
84146+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
84147+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
84148+ }
84149 }
84150 out:
84151 if (ret & ~PAGE_MASK)
84152diff --git a/mm/nommu.c b/mm/nommu.c
84153index 298884d..5f74980 100644
84154--- a/mm/nommu.c
84155+++ b/mm/nommu.c
84156@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
84157 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
84158 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
84159 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
84160-int heap_stack_gap = 0;
84161
84162 atomic_long_t mmap_pages_allocated;
84163
84164@@ -842,15 +841,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
84165 EXPORT_SYMBOL(find_vma);
84166
84167 /*
84168- * find a VMA
84169- * - we don't extend stack VMAs under NOMMU conditions
84170- */
84171-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
84172-{
84173- return find_vma(mm, addr);
84174-}
84175-
84176-/*
84177 * expand a stack to a given address
84178 * - not supported under NOMMU conditions
84179 */
84180@@ -1561,6 +1551,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
84181
84182 /* most fields are the same, copy all, and then fixup */
84183 *new = *vma;
84184+ INIT_LIST_HEAD(&new->anon_vma_chain);
84185 *region = *vma->vm_region;
84186 new->vm_region = region;
84187
84188@@ -1995,8 +1986,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
84189 }
84190 EXPORT_SYMBOL(generic_file_remap_pages);
84191
84192-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84193- unsigned long addr, void *buf, int len, int write)
84194+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84195+ unsigned long addr, void *buf, size_t len, int write)
84196 {
84197 struct vm_area_struct *vma;
84198
84199@@ -2037,8 +2028,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84200 *
84201 * The caller must hold a reference on @mm.
84202 */
84203-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84204- void *buf, int len, int write)
84205+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
84206+ void *buf, size_t len, int write)
84207 {
84208 return __access_remote_vm(NULL, mm, addr, buf, len, write);
84209 }
84210@@ -2047,7 +2038,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84211 * Access another process' address space.
84212 * - source/target buffer must be kernel space
84213 */
84214-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
84215+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
84216 {
84217 struct mm_struct *mm;
84218
84219diff --git a/mm/page-writeback.c b/mm/page-writeback.c
84220index 4514ad7..92eaa1c 100644
84221--- a/mm/page-writeback.c
84222+++ b/mm/page-writeback.c
84223@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
84224 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
84225 * - the bdi dirty thresh drops quickly due to change of JBOD workload
84226 */
84227-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
84228+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
84229 unsigned long thresh,
84230 unsigned long bg_thresh,
84231 unsigned long dirty,
84232@@ -1634,7 +1634,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
84233 }
84234 }
84235
84236-static struct notifier_block __cpuinitdata ratelimit_nb = {
84237+static struct notifier_block ratelimit_nb = {
84238 .notifier_call = ratelimit_handler,
84239 .next = NULL,
84240 };
84241diff --git a/mm/page_alloc.c b/mm/page_alloc.c
84242index 2ee0fd3..6e2edfb 100644
84243--- a/mm/page_alloc.c
84244+++ b/mm/page_alloc.c
84245@@ -60,6 +60,7 @@
84246 #include <linux/page-debug-flags.h>
84247 #include <linux/hugetlb.h>
84248 #include <linux/sched/rt.h>
84249+#include <linux/random.h>
84250
84251 #include <asm/tlbflush.h>
84252 #include <asm/div64.h>
84253@@ -345,7 +346,7 @@ out:
84254 * This usage means that zero-order pages may not be compound.
84255 */
84256
84257-static void free_compound_page(struct page *page)
84258+void free_compound_page(struct page *page)
84259 {
84260 __free_pages_ok(page, compound_order(page));
84261 }
84262@@ -702,6 +703,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
84263 int i;
84264 int bad = 0;
84265
84266+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84267+ unsigned long index = 1UL << order;
84268+#endif
84269+
84270 trace_mm_page_free(page, order);
84271 kmemcheck_free_shadow(page, order);
84272
84273@@ -717,6 +722,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
84274 debug_check_no_obj_freed(page_address(page),
84275 PAGE_SIZE << order);
84276 }
84277+
84278+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84279+ for (; index; --index)
84280+ sanitize_highpage(page + index - 1);
84281+#endif
84282+
84283 arch_free_page(page, order);
84284 kernel_map_pages(page, 1 << order, 0);
84285
84286@@ -739,6 +750,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
84287 local_irq_restore(flags);
84288 }
84289
84290+#ifdef CONFIG_PAX_LATENT_ENTROPY
84291+bool __meminitdata extra_latent_entropy;
84292+
84293+static int __init setup_pax_extra_latent_entropy(char *str)
84294+{
84295+ extra_latent_entropy = true;
84296+ return 0;
84297+}
84298+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
84299+
84300+volatile u64 latent_entropy;
84301+#endif
84302+
84303 /*
84304 * Read access to zone->managed_pages is safe because it's unsigned long,
84305 * but we still need to serialize writers. Currently all callers of
84306@@ -761,6 +785,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
84307 set_page_count(p, 0);
84308 }
84309
84310+#ifdef CONFIG_PAX_LATENT_ENTROPY
84311+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
84312+ u64 hash = 0;
84313+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
84314+ const u64 *data = lowmem_page_address(page);
84315+
84316+ for (index = 0; index < end; index++)
84317+ hash ^= hash + data[index];
84318+ latent_entropy ^= hash;
84319+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84320+ }
84321+#endif
84322+
84323 page_zone(page)->managed_pages += 1 << order;
84324 set_page_refcounted(page);
84325 __free_pages(page, order);
84326@@ -870,8 +907,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
84327 arch_alloc_page(page, order);
84328 kernel_map_pages(page, 1 << order, 1);
84329
84330+#ifndef CONFIG_PAX_MEMORY_SANITIZE
84331 if (gfp_flags & __GFP_ZERO)
84332 prep_zero_page(page, order, gfp_flags);
84333+#endif
84334
84335 if (order && (gfp_flags & __GFP_COMP))
84336 prep_compound_page(page, order);
84337diff --git a/mm/page_io.c b/mm/page_io.c
84338index a8a3ef4..7260a60 100644
84339--- a/mm/page_io.c
84340+++ b/mm/page_io.c
84341@@ -214,7 +214,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
84342 struct file *swap_file = sis->swap_file;
84343 struct address_space *mapping = swap_file->f_mapping;
84344 struct iovec iov = {
84345- .iov_base = kmap(page),
84346+ .iov_base = (void __force_user *)kmap(page),
84347 .iov_len = PAGE_SIZE,
84348 };
84349
84350diff --git a/mm/percpu.c b/mm/percpu.c
84351index 8c8e08f..73a5cda 100644
84352--- a/mm/percpu.c
84353+++ b/mm/percpu.c
84354@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
84355 static unsigned int pcpu_high_unit_cpu __read_mostly;
84356
84357 /* the address of the first chunk which starts with the kernel static area */
84358-void *pcpu_base_addr __read_mostly;
84359+void *pcpu_base_addr __read_only;
84360 EXPORT_SYMBOL_GPL(pcpu_base_addr);
84361
84362 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
84363diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
84364index fd26d04..0cea1b0 100644
84365--- a/mm/process_vm_access.c
84366+++ b/mm/process_vm_access.c
84367@@ -13,6 +13,7 @@
84368 #include <linux/uio.h>
84369 #include <linux/sched.h>
84370 #include <linux/highmem.h>
84371+#include <linux/security.h>
84372 #include <linux/ptrace.h>
84373 #include <linux/slab.h>
84374 #include <linux/syscalls.h>
84375@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
84376 size_t iov_l_curr_offset = 0;
84377 ssize_t iov_len;
84378
84379+ return -ENOSYS; // PaX: until properly audited
84380+
84381 /*
84382 * Work out how many pages of struct pages we're going to need
84383 * when eventually calling get_user_pages
84384 */
84385 for (i = 0; i < riovcnt; i++) {
84386 iov_len = rvec[i].iov_len;
84387- if (iov_len > 0) {
84388- nr_pages_iov = ((unsigned long)rvec[i].iov_base
84389- + iov_len)
84390- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
84391- / PAGE_SIZE + 1;
84392- nr_pages = max(nr_pages, nr_pages_iov);
84393- }
84394+ if (iov_len <= 0)
84395+ continue;
84396+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
84397+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
84398+ nr_pages = max(nr_pages, nr_pages_iov);
84399 }
84400
84401 if (nr_pages == 0)
84402@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
84403 goto free_proc_pages;
84404 }
84405
84406+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
84407+ rc = -EPERM;
84408+ goto put_task_struct;
84409+ }
84410+
84411 mm = mm_access(task, PTRACE_MODE_ATTACH);
84412 if (!mm || IS_ERR(mm)) {
84413 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
84414diff --git a/mm/rmap.c b/mm/rmap.c
84415index 6280da8..ecce194 100644
84416--- a/mm/rmap.c
84417+++ b/mm/rmap.c
84418@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84419 struct anon_vma *anon_vma = vma->anon_vma;
84420 struct anon_vma_chain *avc;
84421
84422+#ifdef CONFIG_PAX_SEGMEXEC
84423+ struct anon_vma_chain *avc_m = NULL;
84424+#endif
84425+
84426 might_sleep();
84427 if (unlikely(!anon_vma)) {
84428 struct mm_struct *mm = vma->vm_mm;
84429@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84430 if (!avc)
84431 goto out_enomem;
84432
84433+#ifdef CONFIG_PAX_SEGMEXEC
84434+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
84435+ if (!avc_m)
84436+ goto out_enomem_free_avc;
84437+#endif
84438+
84439 anon_vma = find_mergeable_anon_vma(vma);
84440 allocated = NULL;
84441 if (!anon_vma) {
84442@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84443 /* page_table_lock to protect against threads */
84444 spin_lock(&mm->page_table_lock);
84445 if (likely(!vma->anon_vma)) {
84446+
84447+#ifdef CONFIG_PAX_SEGMEXEC
84448+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
84449+
84450+ if (vma_m) {
84451+ BUG_ON(vma_m->anon_vma);
84452+ vma_m->anon_vma = anon_vma;
84453+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
84454+ avc_m = NULL;
84455+ }
84456+#endif
84457+
84458 vma->anon_vma = anon_vma;
84459 anon_vma_chain_link(vma, avc, anon_vma);
84460 allocated = NULL;
84461@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84462
84463 if (unlikely(allocated))
84464 put_anon_vma(allocated);
84465+
84466+#ifdef CONFIG_PAX_SEGMEXEC
84467+ if (unlikely(avc_m))
84468+ anon_vma_chain_free(avc_m);
84469+#endif
84470+
84471 if (unlikely(avc))
84472 anon_vma_chain_free(avc);
84473 }
84474 return 0;
84475
84476 out_enomem_free_avc:
84477+
84478+#ifdef CONFIG_PAX_SEGMEXEC
84479+ if (avc_m)
84480+ anon_vma_chain_free(avc_m);
84481+#endif
84482+
84483 anon_vma_chain_free(avc);
84484 out_enomem:
84485 return -ENOMEM;
84486@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
84487 * Attach the anon_vmas from src to dst.
84488 * Returns 0 on success, -ENOMEM on failure.
84489 */
84490-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84491+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
84492 {
84493 struct anon_vma_chain *avc, *pavc;
84494 struct anon_vma *root = NULL;
84495@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84496 * the corresponding VMA in the parent process is attached to.
84497 * Returns 0 on success, non-zero on failure.
84498 */
84499-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
84500+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
84501 {
84502 struct anon_vma_chain *avc;
84503 struct anon_vma *anon_vma;
84504diff --git a/mm/shmem.c b/mm/shmem.c
84505index 5e6a842..b41916e 100644
84506--- a/mm/shmem.c
84507+++ b/mm/shmem.c
84508@@ -33,7 +33,7 @@
84509 #include <linux/swap.h>
84510 #include <linux/aio.h>
84511
84512-static struct vfsmount *shm_mnt;
84513+struct vfsmount *shm_mnt;
84514
84515 #ifdef CONFIG_SHMEM
84516 /*
84517@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
84518 #define BOGO_DIRENT_SIZE 20
84519
84520 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
84521-#define SHORT_SYMLINK_LEN 128
84522+#define SHORT_SYMLINK_LEN 64
84523
84524 /*
84525 * shmem_fallocate and shmem_writepage communicate via inode->i_private
84526@@ -2203,6 +2203,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
84527 static int shmem_xattr_validate(const char *name)
84528 {
84529 struct { const char *prefix; size_t len; } arr[] = {
84530+
84531+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84532+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
84533+#endif
84534+
84535 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
84536 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
84537 };
84538@@ -2258,6 +2263,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
84539 if (err)
84540 return err;
84541
84542+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84543+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
84544+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
84545+ return -EOPNOTSUPP;
84546+ if (size > 8)
84547+ return -EINVAL;
84548+ }
84549+#endif
84550+
84551 return simple_xattr_set(&info->xattrs, name, value, size, flags);
84552 }
84553
84554@@ -2570,8 +2584,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
84555 int err = -ENOMEM;
84556
84557 /* Round up to L1_CACHE_BYTES to resist false sharing */
84558- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
84559- L1_CACHE_BYTES), GFP_KERNEL);
84560+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
84561 if (!sbinfo)
84562 return -ENOMEM;
84563
84564diff --git a/mm/slab.c b/mm/slab.c
84565index bd88411..8371a16 100644
84566--- a/mm/slab.c
84567+++ b/mm/slab.c
84568@@ -366,10 +366,10 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
84569 if ((x)->max_freeable < i) \
84570 (x)->max_freeable = i; \
84571 } while (0)
84572-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
84573-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
84574-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
84575-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
84576+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
84577+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
84578+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
84579+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
84580 #else
84581 #define STATS_INC_ACTIVE(x) do { } while (0)
84582 #define STATS_DEC_ACTIVE(x) do { } while (0)
84583@@ -477,7 +477,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
84584 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
84585 */
84586 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
84587- const struct slab *slab, void *obj)
84588+ const struct slab *slab, const void *obj)
84589 {
84590 u32 offset = (obj - slab->s_mem);
84591 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
84592@@ -1384,7 +1384,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
84593 return notifier_from_errno(err);
84594 }
84595
84596-static struct notifier_block __cpuinitdata cpucache_notifier = {
84597+static struct notifier_block cpucache_notifier = {
84598 &cpuup_callback, NULL, 0
84599 };
84600
84601@@ -1565,12 +1565,12 @@ void __init kmem_cache_init(void)
84602 */
84603
84604 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
84605- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
84606+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
84607
84608 if (INDEX_AC != INDEX_NODE)
84609 kmalloc_caches[INDEX_NODE] =
84610 create_kmalloc_cache("kmalloc-node",
84611- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
84612+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
84613
84614 slab_early_init = 0;
84615
84616@@ -3800,6 +3800,7 @@ void kfree(const void *objp)
84617
84618 if (unlikely(ZERO_OR_NULL_PTR(objp)))
84619 return;
84620+ VM_BUG_ON(!virt_addr_valid(objp));
84621 local_irq_save(flags);
84622 kfree_debugcheck(objp);
84623 c = virt_to_cache(objp);
84624@@ -4241,10 +4242,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
84625 }
84626 /* cpu stats */
84627 {
84628- unsigned long allochit = atomic_read(&cachep->allochit);
84629- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
84630- unsigned long freehit = atomic_read(&cachep->freehit);
84631- unsigned long freemiss = atomic_read(&cachep->freemiss);
84632+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
84633+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
84634+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
84635+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
84636
84637 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
84638 allochit, allocmiss, freehit, freemiss);
84639@@ -4476,13 +4477,71 @@ static const struct file_operations proc_slabstats_operations = {
84640 static int __init slab_proc_init(void)
84641 {
84642 #ifdef CONFIG_DEBUG_SLAB_LEAK
84643- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
84644+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
84645 #endif
84646 return 0;
84647 }
84648 module_init(slab_proc_init);
84649 #endif
84650
84651+bool is_usercopy_object(const void *ptr)
84652+{
84653+ struct page *page;
84654+ struct kmem_cache *cachep;
84655+
84656+ if (ZERO_OR_NULL_PTR(ptr))
84657+ return false;
84658+
84659+ if (!slab_is_available())
84660+ return false;
84661+
84662+ if (!virt_addr_valid(ptr))
84663+ return false;
84664+
84665+ page = virt_to_head_page(ptr);
84666+
84667+ if (!PageSlab(page))
84668+ return false;
84669+
84670+ cachep = page->slab_cache;
84671+ return cachep->flags & SLAB_USERCOPY;
84672+}
84673+
84674+#ifdef CONFIG_PAX_USERCOPY
84675+const char *check_heap_object(const void *ptr, unsigned long n)
84676+{
84677+ struct page *page;
84678+ struct kmem_cache *cachep;
84679+ struct slab *slabp;
84680+ unsigned int objnr;
84681+ unsigned long offset;
84682+
84683+ if (ZERO_OR_NULL_PTR(ptr))
84684+ return "<null>";
84685+
84686+ if (!virt_addr_valid(ptr))
84687+ return NULL;
84688+
84689+ page = virt_to_head_page(ptr);
84690+
84691+ if (!PageSlab(page))
84692+ return NULL;
84693+
84694+ cachep = page->slab_cache;
84695+ if (!(cachep->flags & SLAB_USERCOPY))
84696+ return cachep->name;
84697+
84698+ slabp = page->slab_page;
84699+ objnr = obj_to_index(cachep, slabp, ptr);
84700+ BUG_ON(objnr >= cachep->num);
84701+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
84702+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
84703+ return NULL;
84704+
84705+ return cachep->name;
84706+}
84707+#endif
84708+
84709 /**
84710 * ksize - get the actual amount of memory allocated for a given object
84711 * @objp: Pointer to the object
84712diff --git a/mm/slab.h b/mm/slab.h
84713index f96b49e..5634e90 100644
84714--- a/mm/slab.h
84715+++ b/mm/slab.h
84716@@ -67,7 +67,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84717
84718 /* Legal flag mask for kmem_cache_create(), for various configurations */
84719 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
84720- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
84721+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
84722
84723 #if defined(CONFIG_DEBUG_SLAB)
84724 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
84725@@ -229,6 +229,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
84726 return s;
84727
84728 page = virt_to_head_page(x);
84729+
84730+ BUG_ON(!PageSlab(page));
84731+
84732 cachep = page->slab_cache;
84733 if (slab_equal_or_root(cachep, s))
84734 return cachep;
84735diff --git a/mm/slab_common.c b/mm/slab_common.c
84736index 2d41450..e22088e 100644
84737--- a/mm/slab_common.c
84738+++ b/mm/slab_common.c
84739@@ -22,7 +22,7 @@
84740
84741 #include "slab.h"
84742
84743-enum slab_state slab_state;
84744+enum slab_state slab_state __read_only;
84745 LIST_HEAD(slab_caches);
84746 DEFINE_MUTEX(slab_mutex);
84747 struct kmem_cache *kmem_cache;
84748@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
84749
84750 err = __kmem_cache_create(s, flags);
84751 if (!err) {
84752- s->refcount = 1;
84753+ atomic_set(&s->refcount, 1);
84754 list_add(&s->list, &slab_caches);
84755 memcg_cache_list_add(memcg, s);
84756 } else {
84757@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
84758
84759 get_online_cpus();
84760 mutex_lock(&slab_mutex);
84761- s->refcount--;
84762- if (!s->refcount) {
84763+ if (atomic_dec_and_test(&s->refcount)) {
84764 list_del(&s->list);
84765
84766 if (!__kmem_cache_shutdown(s)) {
84767@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
84768 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
84769 name, size, err);
84770
84771- s->refcount = -1; /* Exempt from merging for now */
84772+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
84773 }
84774
84775 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84776@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84777
84778 create_boot_cache(s, name, size, flags);
84779 list_add(&s->list, &slab_caches);
84780- s->refcount = 1;
84781+ atomic_set(&s->refcount, 1);
84782 return s;
84783 }
84784
84785@@ -327,6 +326,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
84786 EXPORT_SYMBOL(kmalloc_dma_caches);
84787 #endif
84788
84789+#ifdef CONFIG_PAX_USERCOPY_SLABS
84790+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
84791+EXPORT_SYMBOL(kmalloc_usercopy_caches);
84792+#endif
84793+
84794 /*
84795 * Conversion table for small slabs sizes / 8 to the index in the
84796 * kmalloc array. This is necessary for slabs < 192 since we have non power
84797@@ -391,6 +395,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
84798 return kmalloc_dma_caches[index];
84799
84800 #endif
84801+
84802+#ifdef CONFIG_PAX_USERCOPY_SLABS
84803+ if (unlikely((flags & GFP_USERCOPY)))
84804+ return kmalloc_usercopy_caches[index];
84805+
84806+#endif
84807+
84808 return kmalloc_caches[index];
84809 }
84810
84811@@ -447,7 +458,7 @@ void __init create_kmalloc_caches(unsigned long flags)
84812 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
84813 if (!kmalloc_caches[i]) {
84814 kmalloc_caches[i] = create_kmalloc_cache(NULL,
84815- 1 << i, flags);
84816+ 1 << i, SLAB_USERCOPY | flags);
84817 }
84818
84819 /*
84820@@ -456,10 +467,10 @@ void __init create_kmalloc_caches(unsigned long flags)
84821 * earlier power of two caches
84822 */
84823 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
84824- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
84825+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
84826
84827 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
84828- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
84829+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
84830 }
84831
84832 /* Kmalloc array is now usable */
84833@@ -492,6 +503,23 @@ void __init create_kmalloc_caches(unsigned long flags)
84834 }
84835 }
84836 #endif
84837+
84838+#ifdef CONFIG_PAX_USERCOPY_SLABS
84839+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
84840+ struct kmem_cache *s = kmalloc_caches[i];
84841+
84842+ if (s) {
84843+ int size = kmalloc_size(i);
84844+ char *n = kasprintf(GFP_NOWAIT,
84845+ "usercopy-kmalloc-%d", size);
84846+
84847+ BUG_ON(!n);
84848+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
84849+ size, SLAB_USERCOPY | flags);
84850+ }
84851+ }
84852+#endif
84853+
84854 }
84855 #endif /* !CONFIG_SLOB */
84856
84857diff --git a/mm/slob.c b/mm/slob.c
84858index eeed4a0..c414c12 100644
84859--- a/mm/slob.c
84860+++ b/mm/slob.c
84861@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
84862 /*
84863 * Return the size of a slob block.
84864 */
84865-static slobidx_t slob_units(slob_t *s)
84866+static slobidx_t slob_units(const slob_t *s)
84867 {
84868 if (s->units > 0)
84869 return s->units;
84870@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
84871 /*
84872 * Return the next free slob block pointer after this one.
84873 */
84874-static slob_t *slob_next(slob_t *s)
84875+static slob_t *slob_next(const slob_t *s)
84876 {
84877 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
84878 slobidx_t next;
84879@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
84880 /*
84881 * Returns true if s is the last free block in its page.
84882 */
84883-static int slob_last(slob_t *s)
84884+static int slob_last(const slob_t *s)
84885 {
84886 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
84887 }
84888
84889-static void *slob_new_pages(gfp_t gfp, int order, int node)
84890+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
84891 {
84892- void *page;
84893+ struct page *page;
84894
84895 #ifdef CONFIG_NUMA
84896 if (node != NUMA_NO_NODE)
84897@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
84898 if (!page)
84899 return NULL;
84900
84901- return page_address(page);
84902+ __SetPageSlab(page);
84903+ return page;
84904 }
84905
84906-static void slob_free_pages(void *b, int order)
84907+static void slob_free_pages(struct page *sp, int order)
84908 {
84909 if (current->reclaim_state)
84910 current->reclaim_state->reclaimed_slab += 1 << order;
84911- free_pages((unsigned long)b, order);
84912+ __ClearPageSlab(sp);
84913+ page_mapcount_reset(sp);
84914+ sp->private = 0;
84915+ __free_pages(sp, order);
84916 }
84917
84918 /*
84919@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
84920
84921 /* Not enough space: must allocate a new page */
84922 if (!b) {
84923- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84924- if (!b)
84925+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84926+ if (!sp)
84927 return NULL;
84928- sp = virt_to_page(b);
84929- __SetPageSlab(sp);
84930+ b = page_address(sp);
84931
84932 spin_lock_irqsave(&slob_lock, flags);
84933 sp->units = SLOB_UNITS(PAGE_SIZE);
84934 sp->freelist = b;
84935+ sp->private = 0;
84936 INIT_LIST_HEAD(&sp->list);
84937 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
84938 set_slob_page_free(sp, slob_list);
84939@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
84940 if (slob_page_free(sp))
84941 clear_slob_page_free(sp);
84942 spin_unlock_irqrestore(&slob_lock, flags);
84943- __ClearPageSlab(sp);
84944- page_mapcount_reset(sp);
84945- slob_free_pages(b, 0);
84946+ slob_free_pages(sp, 0);
84947 return;
84948 }
84949
84950@@ -424,11 +426,10 @@ out:
84951 */
84952
84953 static __always_inline void *
84954-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84955+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
84956 {
84957- unsigned int *m;
84958- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84959- void *ret;
84960+ slob_t *m;
84961+ void *ret = NULL;
84962
84963 gfp &= gfp_allowed_mask;
84964
84965@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84966
84967 if (!m)
84968 return NULL;
84969- *m = size;
84970+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
84971+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
84972+ m[0].units = size;
84973+ m[1].units = align;
84974 ret = (void *)m + align;
84975
84976 trace_kmalloc_node(caller, ret,
84977 size, size + align, gfp, node);
84978 } else {
84979 unsigned int order = get_order(size);
84980+ struct page *page;
84981
84982 if (likely(order))
84983 gfp |= __GFP_COMP;
84984- ret = slob_new_pages(gfp, order, node);
84985+ page = slob_new_pages(gfp, order, node);
84986+ if (page) {
84987+ ret = page_address(page);
84988+ page->private = size;
84989+ }
84990
84991 trace_kmalloc_node(caller, ret,
84992 size, PAGE_SIZE << order, gfp, node);
84993 }
84994
84995- kmemleak_alloc(ret, size, 1, gfp);
84996+ return ret;
84997+}
84998+
84999+static __always_inline void *
85000+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
85001+{
85002+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85003+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
85004+
85005+ if (!ZERO_OR_NULL_PTR(ret))
85006+ kmemleak_alloc(ret, size, 1, gfp);
85007 return ret;
85008 }
85009
85010@@ -493,34 +512,112 @@ void kfree(const void *block)
85011 return;
85012 kmemleak_free(block);
85013
85014+ VM_BUG_ON(!virt_addr_valid(block));
85015 sp = virt_to_page(block);
85016- if (PageSlab(sp)) {
85017+ VM_BUG_ON(!PageSlab(sp));
85018+ if (!sp->private) {
85019 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85020- unsigned int *m = (unsigned int *)(block - align);
85021- slob_free(m, *m + align);
85022- } else
85023+ slob_t *m = (slob_t *)(block - align);
85024+ slob_free(m, m[0].units + align);
85025+ } else {
85026+ __ClearPageSlab(sp);
85027+ page_mapcount_reset(sp);
85028+ sp->private = 0;
85029 __free_pages(sp, compound_order(sp));
85030+ }
85031 }
85032 EXPORT_SYMBOL(kfree);
85033
85034+bool is_usercopy_object(const void *ptr)
85035+{
85036+ if (!slab_is_available())
85037+ return false;
85038+
85039+ // PAX: TODO
85040+
85041+ return false;
85042+}
85043+
85044+#ifdef CONFIG_PAX_USERCOPY
85045+const char *check_heap_object(const void *ptr, unsigned long n)
85046+{
85047+ struct page *page;
85048+ const slob_t *free;
85049+ const void *base;
85050+ unsigned long flags;
85051+
85052+ if (ZERO_OR_NULL_PTR(ptr))
85053+ return "<null>";
85054+
85055+ if (!virt_addr_valid(ptr))
85056+ return NULL;
85057+
85058+ page = virt_to_head_page(ptr);
85059+ if (!PageSlab(page))
85060+ return NULL;
85061+
85062+ if (page->private) {
85063+ base = page;
85064+ if (base <= ptr && n <= page->private - (ptr - base))
85065+ return NULL;
85066+ return "<slob>";
85067+ }
85068+
85069+ /* some tricky double walking to find the chunk */
85070+ spin_lock_irqsave(&slob_lock, flags);
85071+ base = (void *)((unsigned long)ptr & PAGE_MASK);
85072+ free = page->freelist;
85073+
85074+ while (!slob_last(free) && (void *)free <= ptr) {
85075+ base = free + slob_units(free);
85076+ free = slob_next(free);
85077+ }
85078+
85079+ while (base < (void *)free) {
85080+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
85081+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
85082+ int offset;
85083+
85084+ if (ptr < base + align)
85085+ break;
85086+
85087+ offset = ptr - base - align;
85088+ if (offset >= m) {
85089+ base += size;
85090+ continue;
85091+ }
85092+
85093+ if (n > m - offset)
85094+ break;
85095+
85096+ spin_unlock_irqrestore(&slob_lock, flags);
85097+ return NULL;
85098+ }
85099+
85100+ spin_unlock_irqrestore(&slob_lock, flags);
85101+ return "<slob>";
85102+}
85103+#endif
85104+
85105 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
85106 size_t ksize(const void *block)
85107 {
85108 struct page *sp;
85109 int align;
85110- unsigned int *m;
85111+ slob_t *m;
85112
85113 BUG_ON(!block);
85114 if (unlikely(block == ZERO_SIZE_PTR))
85115 return 0;
85116
85117 sp = virt_to_page(block);
85118- if (unlikely(!PageSlab(sp)))
85119- return PAGE_SIZE << compound_order(sp);
85120+ VM_BUG_ON(!PageSlab(sp));
85121+ if (sp->private)
85122+ return sp->private;
85123
85124 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85125- m = (unsigned int *)(block - align);
85126- return SLOB_UNITS(*m) * SLOB_UNIT;
85127+ m = (slob_t *)(block - align);
85128+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
85129 }
85130 EXPORT_SYMBOL(ksize);
85131
85132@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
85133
85134 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
85135 {
85136- void *b;
85137+ void *b = NULL;
85138
85139 flags &= gfp_allowed_mask;
85140
85141 lockdep_trace_alloc(flags);
85142
85143+#ifdef CONFIG_PAX_USERCOPY_SLABS
85144+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
85145+#else
85146 if (c->size < PAGE_SIZE) {
85147 b = slob_alloc(c->size, flags, c->align, node);
85148 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
85149 SLOB_UNITS(c->size) * SLOB_UNIT,
85150 flags, node);
85151 } else {
85152- b = slob_new_pages(flags, get_order(c->size), node);
85153+ struct page *sp;
85154+
85155+ sp = slob_new_pages(flags, get_order(c->size), node);
85156+ if (sp) {
85157+ b = page_address(sp);
85158+ sp->private = c->size;
85159+ }
85160 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
85161 PAGE_SIZE << get_order(c->size),
85162 flags, node);
85163 }
85164+#endif
85165
85166 if (c->ctor)
85167 c->ctor(b);
85168@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
85169
85170 static void __kmem_cache_free(void *b, int size)
85171 {
85172- if (size < PAGE_SIZE)
85173+ struct page *sp;
85174+
85175+ sp = virt_to_page(b);
85176+ BUG_ON(!PageSlab(sp));
85177+ if (!sp->private)
85178 slob_free(b, size);
85179 else
85180- slob_free_pages(b, get_order(size));
85181+ slob_free_pages(sp, get_order(size));
85182 }
85183
85184 static void kmem_rcu_free(struct rcu_head *head)
85185@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
85186
85187 void kmem_cache_free(struct kmem_cache *c, void *b)
85188 {
85189+ int size = c->size;
85190+
85191+#ifdef CONFIG_PAX_USERCOPY_SLABS
85192+ if (size + c->align < PAGE_SIZE) {
85193+ size += c->align;
85194+ b -= c->align;
85195+ }
85196+#endif
85197+
85198 kmemleak_free_recursive(b, c->flags);
85199 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
85200 struct slob_rcu *slob_rcu;
85201- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
85202- slob_rcu->size = c->size;
85203+ slob_rcu = b + (size - sizeof(struct slob_rcu));
85204+ slob_rcu->size = size;
85205 call_rcu(&slob_rcu->head, kmem_rcu_free);
85206 } else {
85207- __kmem_cache_free(b, c->size);
85208+ __kmem_cache_free(b, size);
85209 }
85210
85211+#ifdef CONFIG_PAX_USERCOPY_SLABS
85212+ trace_kfree(_RET_IP_, b);
85213+#else
85214 trace_kmem_cache_free(_RET_IP_, b);
85215+#endif
85216+
85217 }
85218 EXPORT_SYMBOL(kmem_cache_free);
85219
85220diff --git a/mm/slub.c b/mm/slub.c
85221index 57707f0..c28619b 100644
85222--- a/mm/slub.c
85223+++ b/mm/slub.c
85224@@ -198,7 +198,7 @@ struct track {
85225
85226 enum track_item { TRACK_ALLOC, TRACK_FREE };
85227
85228-#ifdef CONFIG_SYSFS
85229+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85230 static int sysfs_slab_add(struct kmem_cache *);
85231 static int sysfs_slab_alias(struct kmem_cache *, const char *);
85232 static void sysfs_slab_remove(struct kmem_cache *);
85233@@ -519,7 +519,7 @@ static void print_track(const char *s, struct track *t)
85234 if (!t->addr)
85235 return;
85236
85237- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
85238+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
85239 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
85240 #ifdef CONFIG_STACKTRACE
85241 {
85242@@ -2661,7 +2661,7 @@ static int slub_min_objects;
85243 * Merge control. If this is set then no merging of slab caches will occur.
85244 * (Could be removed. This was introduced to pacify the merge skeptics.)
85245 */
85246-static int slub_nomerge;
85247+static int slub_nomerge = 1;
85248
85249 /*
85250 * Calculate the order of allocation given an slab object size.
85251@@ -3283,6 +3283,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
85252 EXPORT_SYMBOL(__kmalloc_node);
85253 #endif
85254
85255+bool is_usercopy_object(const void *ptr)
85256+{
85257+ struct page *page;
85258+ struct kmem_cache *s;
85259+
85260+ if (ZERO_OR_NULL_PTR(ptr))
85261+ return false;
85262+
85263+ if (!slab_is_available())
85264+ return false;
85265+
85266+ if (!virt_addr_valid(ptr))
85267+ return false;
85268+
85269+ page = virt_to_head_page(ptr);
85270+
85271+ if (!PageSlab(page))
85272+ return false;
85273+
85274+ s = page->slab_cache;
85275+ return s->flags & SLAB_USERCOPY;
85276+}
85277+
85278+#ifdef CONFIG_PAX_USERCOPY
85279+const char *check_heap_object(const void *ptr, unsigned long n)
85280+{
85281+ struct page *page;
85282+ struct kmem_cache *s;
85283+ unsigned long offset;
85284+
85285+ if (ZERO_OR_NULL_PTR(ptr))
85286+ return "<null>";
85287+
85288+ if (!virt_addr_valid(ptr))
85289+ return NULL;
85290+
85291+ page = virt_to_head_page(ptr);
85292+
85293+ if (!PageSlab(page))
85294+ return NULL;
85295+
85296+ s = page->slab_cache;
85297+ if (!(s->flags & SLAB_USERCOPY))
85298+ return s->name;
85299+
85300+ offset = (ptr - page_address(page)) % s->size;
85301+ if (offset <= s->object_size && n <= s->object_size - offset)
85302+ return NULL;
85303+
85304+ return s->name;
85305+}
85306+#endif
85307+
85308 size_t ksize(const void *object)
85309 {
85310 struct page *page;
85311@@ -3347,6 +3400,7 @@ void kfree(const void *x)
85312 if (unlikely(ZERO_OR_NULL_PTR(x)))
85313 return;
85314
85315+ VM_BUG_ON(!virt_addr_valid(x));
85316 page = virt_to_head_page(x);
85317 if (unlikely(!PageSlab(page))) {
85318 BUG_ON(!PageCompound(page));
85319@@ -3652,7 +3706,7 @@ static int slab_unmergeable(struct kmem_cache *s)
85320 /*
85321 * We may have set a slab to be unmergeable during bootstrap.
85322 */
85323- if (s->refcount < 0)
85324+ if (atomic_read(&s->refcount) < 0)
85325 return 1;
85326
85327 return 0;
85328@@ -3710,7 +3764,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85329
85330 s = find_mergeable(memcg, size, align, flags, name, ctor);
85331 if (s) {
85332- s->refcount++;
85333+ atomic_inc(&s->refcount);
85334 /*
85335 * Adjust the object sizes so that we clear
85336 * the complete object on kzalloc.
85337@@ -3719,7 +3773,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85338 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
85339
85340 if (sysfs_slab_alias(s, name)) {
85341- s->refcount--;
85342+ atomic_dec(&s->refcount);
85343 s = NULL;
85344 }
85345 }
85346@@ -3781,7 +3835,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
85347 return NOTIFY_OK;
85348 }
85349
85350-static struct notifier_block __cpuinitdata slab_notifier = {
85351+static struct notifier_block slab_notifier = {
85352 .notifier_call = slab_cpuup_callback
85353 };
85354
85355@@ -3839,7 +3893,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
85356 }
85357 #endif
85358
85359-#ifdef CONFIG_SYSFS
85360+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85361 static int count_inuse(struct page *page)
85362 {
85363 return page->inuse;
85364@@ -4226,12 +4280,12 @@ static void resiliency_test(void)
85365 validate_slab_cache(kmalloc_caches[9]);
85366 }
85367 #else
85368-#ifdef CONFIG_SYSFS
85369+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85370 static void resiliency_test(void) {};
85371 #endif
85372 #endif
85373
85374-#ifdef CONFIG_SYSFS
85375+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85376 enum slab_stat_type {
85377 SL_ALL, /* All slabs */
85378 SL_PARTIAL, /* Only partially allocated slabs */
85379@@ -4475,7 +4529,7 @@ SLAB_ATTR_RO(ctor);
85380
85381 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
85382 {
85383- return sprintf(buf, "%d\n", s->refcount - 1);
85384+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
85385 }
85386 SLAB_ATTR_RO(aliases);
85387
85388@@ -4563,6 +4617,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
85389 SLAB_ATTR_RO(cache_dma);
85390 #endif
85391
85392+#ifdef CONFIG_PAX_USERCOPY_SLABS
85393+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
85394+{
85395+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
85396+}
85397+SLAB_ATTR_RO(usercopy);
85398+#endif
85399+
85400 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
85401 {
85402 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
85403@@ -4897,6 +4959,9 @@ static struct attribute *slab_attrs[] = {
85404 #ifdef CONFIG_ZONE_DMA
85405 &cache_dma_attr.attr,
85406 #endif
85407+#ifdef CONFIG_PAX_USERCOPY_SLABS
85408+ &usercopy_attr.attr,
85409+#endif
85410 #ifdef CONFIG_NUMA
85411 &remote_node_defrag_ratio_attr.attr,
85412 #endif
85413@@ -5128,6 +5193,7 @@ static char *create_unique_id(struct kmem_cache *s)
85414 return name;
85415 }
85416
85417+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85418 static int sysfs_slab_add(struct kmem_cache *s)
85419 {
85420 int err;
85421@@ -5151,7 +5217,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
85422 }
85423
85424 s->kobj.kset = slab_kset;
85425- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
85426+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
85427 if (err) {
85428 kobject_put(&s->kobj);
85429 return err;
85430@@ -5185,6 +5251,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
85431 kobject_del(&s->kobj);
85432 kobject_put(&s->kobj);
85433 }
85434+#endif
85435
85436 /*
85437 * Need to buffer aliases during bootup until sysfs becomes
85438@@ -5198,6 +5265,7 @@ struct saved_alias {
85439
85440 static struct saved_alias *alias_list;
85441
85442+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85443 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85444 {
85445 struct saved_alias *al;
85446@@ -5220,6 +5288,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85447 alias_list = al;
85448 return 0;
85449 }
85450+#endif
85451
85452 static int __init slab_sysfs_init(void)
85453 {
85454diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
85455index 27eeab3..7c3f7f2 100644
85456--- a/mm/sparse-vmemmap.c
85457+++ b/mm/sparse-vmemmap.c
85458@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
85459 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85460 if (!p)
85461 return NULL;
85462- pud_populate(&init_mm, pud, p);
85463+ pud_populate_kernel(&init_mm, pud, p);
85464 }
85465 return pud;
85466 }
85467@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
85468 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85469 if (!p)
85470 return NULL;
85471- pgd_populate(&init_mm, pgd, p);
85472+ pgd_populate_kernel(&init_mm, pgd, p);
85473 }
85474 return pgd;
85475 }
85476diff --git a/mm/sparse.c b/mm/sparse.c
85477index 1c91f0d3..485470a 100644
85478--- a/mm/sparse.c
85479+++ b/mm/sparse.c
85480@@ -761,7 +761,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
85481
85482 for (i = 0; i < PAGES_PER_SECTION; i++) {
85483 if (PageHWPoison(&memmap[i])) {
85484- atomic_long_sub(1, &num_poisoned_pages);
85485+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
85486 ClearPageHWPoison(&memmap[i]);
85487 }
85488 }
85489diff --git a/mm/swap.c b/mm/swap.c
85490index dfd7d71..ccdf688 100644
85491--- a/mm/swap.c
85492+++ b/mm/swap.c
85493@@ -31,6 +31,7 @@
85494 #include <linux/memcontrol.h>
85495 #include <linux/gfp.h>
85496 #include <linux/uio.h>
85497+#include <linux/hugetlb.h>
85498
85499 #include "internal.h"
85500
85501@@ -73,6 +74,8 @@ static void __put_compound_page(struct page *page)
85502
85503 __page_cache_release(page);
85504 dtor = get_compound_page_dtor(page);
85505+ if (!PageHuge(page))
85506+ BUG_ON(dtor != free_compound_page);
85507 (*dtor)(page);
85508 }
85509
85510diff --git a/mm/swapfile.c b/mm/swapfile.c
85511index 746af55b..7ac94ae 100644
85512--- a/mm/swapfile.c
85513+++ b/mm/swapfile.c
85514@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
85515
85516 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
85517 /* Activity counter to indicate that a swapon or swapoff has occurred */
85518-static atomic_t proc_poll_event = ATOMIC_INIT(0);
85519+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
85520
85521 static inline unsigned char swap_count(unsigned char ent)
85522 {
85523@@ -1684,7 +1684,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
85524 }
85525 filp_close(swap_file, NULL);
85526 err = 0;
85527- atomic_inc(&proc_poll_event);
85528+ atomic_inc_unchecked(&proc_poll_event);
85529 wake_up_interruptible(&proc_poll_wait);
85530
85531 out_dput:
85532@@ -1701,8 +1701,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
85533
85534 poll_wait(file, &proc_poll_wait, wait);
85535
85536- if (seq->poll_event != atomic_read(&proc_poll_event)) {
85537- seq->poll_event = atomic_read(&proc_poll_event);
85538+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
85539+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85540 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
85541 }
85542
85543@@ -1800,7 +1800,7 @@ static int swaps_open(struct inode *inode, struct file *file)
85544 return ret;
85545
85546 seq = file->private_data;
85547- seq->poll_event = atomic_read(&proc_poll_event);
85548+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85549 return 0;
85550 }
85551
85552@@ -2143,7 +2143,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
85553 (frontswap_map) ? "FS" : "");
85554
85555 mutex_unlock(&swapon_mutex);
85556- atomic_inc(&proc_poll_event);
85557+ atomic_inc_unchecked(&proc_poll_event);
85558 wake_up_interruptible(&proc_poll_wait);
85559
85560 if (S_ISREG(inode->i_mode))
85561diff --git a/mm/util.c b/mm/util.c
85562index ab1424d..7c5bd5a 100644
85563--- a/mm/util.c
85564+++ b/mm/util.c
85565@@ -294,6 +294,12 @@ done:
85566 void arch_pick_mmap_layout(struct mm_struct *mm)
85567 {
85568 mm->mmap_base = TASK_UNMAPPED_BASE;
85569+
85570+#ifdef CONFIG_PAX_RANDMMAP
85571+ if (mm->pax_flags & MF_PAX_RANDMMAP)
85572+ mm->mmap_base += mm->delta_mmap;
85573+#endif
85574+
85575 mm->get_unmapped_area = arch_get_unmapped_area;
85576 mm->unmap_area = arch_unmap_area;
85577 }
85578diff --git a/mm/vmalloc.c b/mm/vmalloc.c
85579index d365724..6cae7c2 100644
85580--- a/mm/vmalloc.c
85581+++ b/mm/vmalloc.c
85582@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
85583
85584 pte = pte_offset_kernel(pmd, addr);
85585 do {
85586- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85587- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85588+
85589+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85590+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
85591+ BUG_ON(!pte_exec(*pte));
85592+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
85593+ continue;
85594+ }
85595+#endif
85596+
85597+ {
85598+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85599+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85600+ }
85601 } while (pte++, addr += PAGE_SIZE, addr != end);
85602 }
85603
85604@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
85605 pte = pte_alloc_kernel(pmd, addr);
85606 if (!pte)
85607 return -ENOMEM;
85608+
85609+ pax_open_kernel();
85610 do {
85611 struct page *page = pages[*nr];
85612
85613- if (WARN_ON(!pte_none(*pte)))
85614+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85615+ if (pgprot_val(prot) & _PAGE_NX)
85616+#endif
85617+
85618+ if (!pte_none(*pte)) {
85619+ pax_close_kernel();
85620+ WARN_ON(1);
85621 return -EBUSY;
85622- if (WARN_ON(!page))
85623+ }
85624+ if (!page) {
85625+ pax_close_kernel();
85626+ WARN_ON(1);
85627 return -ENOMEM;
85628+ }
85629 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
85630 (*nr)++;
85631 } while (pte++, addr += PAGE_SIZE, addr != end);
85632+ pax_close_kernel();
85633 return 0;
85634 }
85635
85636@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
85637 pmd_t *pmd;
85638 unsigned long next;
85639
85640- pmd = pmd_alloc(&init_mm, pud, addr);
85641+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85642 if (!pmd)
85643 return -ENOMEM;
85644 do {
85645@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
85646 pud_t *pud;
85647 unsigned long next;
85648
85649- pud = pud_alloc(&init_mm, pgd, addr);
85650+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85651 if (!pud)
85652 return -ENOMEM;
85653 do {
85654@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
85655 if (addr >= MODULES_VADDR && addr < MODULES_END)
85656 return 1;
85657 #endif
85658+
85659+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85660+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
85661+ return 1;
85662+#endif
85663+
85664 return is_vmalloc_addr(x);
85665 }
85666
85667@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
85668
85669 if (!pgd_none(*pgd)) {
85670 pud_t *pud = pud_offset(pgd, addr);
85671+#ifdef CONFIG_X86
85672+ if (!pud_large(*pud))
85673+#endif
85674 if (!pud_none(*pud)) {
85675 pmd_t *pmd = pmd_offset(pud, addr);
85676+#ifdef CONFIG_X86
85677+ if (!pmd_large(*pmd))
85678+#endif
85679 if (!pmd_none(*pmd)) {
85680 pte_t *ptep, pte;
85681
85682@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
85683 * Allocate a region of KVA of the specified size and alignment, within the
85684 * vstart and vend.
85685 */
85686-static struct vmap_area *alloc_vmap_area(unsigned long size,
85687+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
85688 unsigned long align,
85689 unsigned long vstart, unsigned long vend,
85690 int node, gfp_t gfp_mask)
85691@@ -1337,6 +1373,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
85692 struct vm_struct *area;
85693
85694 BUG_ON(in_interrupt());
85695+
85696+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85697+ if (flags & VM_KERNEXEC) {
85698+ if (start != VMALLOC_START || end != VMALLOC_END)
85699+ return NULL;
85700+ start = (unsigned long)MODULES_EXEC_VADDR;
85701+ end = (unsigned long)MODULES_EXEC_END;
85702+ }
85703+#endif
85704+
85705 if (flags & VM_IOREMAP) {
85706 int bit = fls(size);
85707
85708@@ -1581,6 +1627,11 @@ void *vmap(struct page **pages, unsigned int count,
85709 if (count > totalram_pages)
85710 return NULL;
85711
85712+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85713+ if (!(pgprot_val(prot) & _PAGE_NX))
85714+ flags |= VM_KERNEXEC;
85715+#endif
85716+
85717 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
85718 __builtin_return_address(0));
85719 if (!area)
85720@@ -1682,6 +1733,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
85721 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
85722 goto fail;
85723
85724+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85725+ if (!(pgprot_val(prot) & _PAGE_NX))
85726+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
85727+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
85728+ else
85729+#endif
85730+
85731 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
85732 start, end, node, gfp_mask, caller);
85733 if (!area)
85734@@ -1858,10 +1916,9 @@ EXPORT_SYMBOL(vzalloc_node);
85735 * For tight control over page level allocator and protection flags
85736 * use __vmalloc() instead.
85737 */
85738-
85739 void *vmalloc_exec(unsigned long size)
85740 {
85741- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
85742+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
85743 NUMA_NO_NODE, __builtin_return_address(0));
85744 }
85745
85746@@ -2168,6 +2225,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
85747 unsigned long uaddr = vma->vm_start;
85748 unsigned long usize = vma->vm_end - vma->vm_start;
85749
85750+ BUG_ON(vma->vm_mirror);
85751+
85752 if ((PAGE_SIZE-1) & (unsigned long)addr)
85753 return -EINVAL;
85754
85755@@ -2629,7 +2688,11 @@ static int s_show(struct seq_file *m, void *p)
85756 v->addr, v->addr + v->size, v->size);
85757
85758 if (v->caller)
85759+#ifdef CONFIG_GRKERNSEC_HIDESYM
85760+ seq_printf(m, " %pK", v->caller);
85761+#else
85762 seq_printf(m, " %pS", v->caller);
85763+#endif
85764
85765 if (v->nr_pages)
85766 seq_printf(m, " pages=%d", v->nr_pages);
85767diff --git a/mm/vmstat.c b/mm/vmstat.c
85768index f42745e..62f8346 100644
85769--- a/mm/vmstat.c
85770+++ b/mm/vmstat.c
85771@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
85772 *
85773 * vm_stat contains the global counters
85774 */
85775-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85776+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85777 EXPORT_SYMBOL(vm_stat);
85778
85779 #ifdef CONFIG_SMP
85780@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
85781 v = p->vm_stat_diff[i];
85782 p->vm_stat_diff[i] = 0;
85783 local_irq_restore(flags);
85784- atomic_long_add(v, &zone->vm_stat[i]);
85785+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85786 global_diff[i] += v;
85787 #ifdef CONFIG_NUMA
85788 /* 3 seconds idle till flush */
85789@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
85790
85791 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
85792 if (global_diff[i])
85793- atomic_long_add(global_diff[i], &vm_stat[i]);
85794+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
85795 }
85796
85797 /*
85798@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85799 if (pset->vm_stat_diff[i]) {
85800 int v = pset->vm_stat_diff[i];
85801 pset->vm_stat_diff[i] = 0;
85802- atomic_long_add(v, &zone->vm_stat[i]);
85803- atomic_long_add(v, &vm_stat[i]);
85804+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85805+ atomic_long_add_unchecked(v, &vm_stat[i]);
85806 }
85807 }
85808 #endif
85809@@ -1226,7 +1226,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
85810 return NOTIFY_OK;
85811 }
85812
85813-static struct notifier_block __cpuinitdata vmstat_notifier =
85814+static struct notifier_block vmstat_notifier =
85815 { &vmstat_cpuup_callback, NULL, 0 };
85816 #endif
85817
85818@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
85819 start_cpu_timer(cpu);
85820 #endif
85821 #ifdef CONFIG_PROC_FS
85822- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
85823- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
85824- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
85825- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
85826+ {
85827+ mode_t gr_mode = S_IRUGO;
85828+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85829+ gr_mode = S_IRUSR;
85830+#endif
85831+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
85832+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
85833+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85834+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
85835+#else
85836+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
85837+#endif
85838+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
85839+ }
85840 #endif
85841 return 0;
85842 }
85843diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
85844index 9424f37..6aabf19 100644
85845--- a/net/8021q/vlan.c
85846+++ b/net/8021q/vlan.c
85847@@ -469,7 +469,7 @@ out:
85848 return NOTIFY_DONE;
85849 }
85850
85851-static struct notifier_block vlan_notifier_block __read_mostly = {
85852+static struct notifier_block vlan_notifier_block = {
85853 .notifier_call = vlan_device_event,
85854 };
85855
85856@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
85857 err = -EPERM;
85858 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
85859 break;
85860- if ((args.u.name_type >= 0) &&
85861- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
85862+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
85863 struct vlan_net *vn;
85864
85865 vn = net_generic(net, vlan_net_id);
85866diff --git a/net/9p/mod.c b/net/9p/mod.c
85867index 6ab36ae..6f1841b 100644
85868--- a/net/9p/mod.c
85869+++ b/net/9p/mod.c
85870@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
85871 void v9fs_register_trans(struct p9_trans_module *m)
85872 {
85873 spin_lock(&v9fs_trans_lock);
85874- list_add_tail(&m->list, &v9fs_trans_list);
85875+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
85876 spin_unlock(&v9fs_trans_lock);
85877 }
85878 EXPORT_SYMBOL(v9fs_register_trans);
85879@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
85880 void v9fs_unregister_trans(struct p9_trans_module *m)
85881 {
85882 spin_lock(&v9fs_trans_lock);
85883- list_del_init(&m->list);
85884+ pax_list_del_init((struct list_head *)&m->list);
85885 spin_unlock(&v9fs_trans_lock);
85886 }
85887 EXPORT_SYMBOL(v9fs_unregister_trans);
85888diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
85889index 02efb25..41541a9 100644
85890--- a/net/9p/trans_fd.c
85891+++ b/net/9p/trans_fd.c
85892@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
85893 oldfs = get_fs();
85894 set_fs(get_ds());
85895 /* The cast to a user pointer is valid due to the set_fs() */
85896- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
85897+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
85898 set_fs(oldfs);
85899
85900 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
85901diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
85902index 876fbe8..8bbea9f 100644
85903--- a/net/atm/atm_misc.c
85904+++ b/net/atm/atm_misc.c
85905@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
85906 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
85907 return 1;
85908 atm_return(vcc, truesize);
85909- atomic_inc(&vcc->stats->rx_drop);
85910+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85911 return 0;
85912 }
85913 EXPORT_SYMBOL(atm_charge);
85914@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
85915 }
85916 }
85917 atm_return(vcc, guess);
85918- atomic_inc(&vcc->stats->rx_drop);
85919+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85920 return NULL;
85921 }
85922 EXPORT_SYMBOL(atm_alloc_charge);
85923@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
85924
85925 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85926 {
85927-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85928+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85929 __SONET_ITEMS
85930 #undef __HANDLE_ITEM
85931 }
85932@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
85933
85934 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85935 {
85936-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85937+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
85938 __SONET_ITEMS
85939 #undef __HANDLE_ITEM
85940 }
85941diff --git a/net/atm/lec.h b/net/atm/lec.h
85942index 4149db1..f2ab682 100644
85943--- a/net/atm/lec.h
85944+++ b/net/atm/lec.h
85945@@ -48,7 +48,7 @@ struct lane2_ops {
85946 const u8 *tlvs, u32 sizeoftlvs);
85947 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
85948 const u8 *tlvs, u32 sizeoftlvs);
85949-};
85950+} __no_const;
85951
85952 /*
85953 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
85954diff --git a/net/atm/proc.c b/net/atm/proc.c
85955index bbb6461..cf04016 100644
85956--- a/net/atm/proc.c
85957+++ b/net/atm/proc.c
85958@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
85959 const struct k_atm_aal_stats *stats)
85960 {
85961 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
85962- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
85963- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
85964- atomic_read(&stats->rx_drop));
85965+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
85966+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
85967+ atomic_read_unchecked(&stats->rx_drop));
85968 }
85969
85970 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
85971diff --git a/net/atm/resources.c b/net/atm/resources.c
85972index 0447d5d..3cf4728 100644
85973--- a/net/atm/resources.c
85974+++ b/net/atm/resources.c
85975@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
85976 static void copy_aal_stats(struct k_atm_aal_stats *from,
85977 struct atm_aal_stats *to)
85978 {
85979-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85980+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85981 __AAL_STAT_ITEMS
85982 #undef __HANDLE_ITEM
85983 }
85984@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
85985 static void subtract_aal_stats(struct k_atm_aal_stats *from,
85986 struct atm_aal_stats *to)
85987 {
85988-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85989+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
85990 __AAL_STAT_ITEMS
85991 #undef __HANDLE_ITEM
85992 }
85993diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
85994index d5744b7..506bae3 100644
85995--- a/net/ax25/sysctl_net_ax25.c
85996+++ b/net/ax25/sysctl_net_ax25.c
85997@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
85998 {
85999 char path[sizeof("net/ax25/") + IFNAMSIZ];
86000 int k;
86001- struct ctl_table *table;
86002+ ctl_table_no_const *table;
86003
86004 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
86005 if (!table)
86006diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
86007index f680ee1..97e3542 100644
86008--- a/net/batman-adv/bat_iv_ogm.c
86009+++ b/net/batman-adv/bat_iv_ogm.c
86010@@ -79,7 +79,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
86011
86012 /* randomize initial seqno to avoid collision */
86013 get_random_bytes(&random_seqno, sizeof(random_seqno));
86014- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
86015+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
86016
86017 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
86018 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
86019@@ -627,9 +627,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
86020 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
86021
86022 /* change sequence number to network order */
86023- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
86024+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
86025 batadv_ogm_packet->seqno = htonl(seqno);
86026- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
86027+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
86028
86029 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
86030 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
86031@@ -1037,7 +1037,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
86032 return;
86033
86034 /* could be changed by schedule_own_packet() */
86035- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
86036+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
86037
86038 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
86039 has_directlink_flag = 1;
86040diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
86041index 522243a..b48c0ef 100644
86042--- a/net/batman-adv/hard-interface.c
86043+++ b/net/batman-adv/hard-interface.c
86044@@ -401,7 +401,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
86045 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
86046 dev_add_pack(&hard_iface->batman_adv_ptype);
86047
86048- atomic_set(&hard_iface->frag_seqno, 1);
86049+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
86050 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
86051 hard_iface->net_dev->name);
86052
86053@@ -550,7 +550,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
86054 /* This can't be called via a bat_priv callback because
86055 * we have no bat_priv yet.
86056 */
86057- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
86058+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
86059 hard_iface->bat_iv.ogm_buff = NULL;
86060
86061 return hard_iface;
86062diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
86063index 819dfb0..9a672d1 100644
86064--- a/net/batman-adv/soft-interface.c
86065+++ b/net/batman-adv/soft-interface.c
86066@@ -253,7 +253,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
86067 primary_if->net_dev->dev_addr, ETH_ALEN);
86068
86069 /* set broadcast sequence number */
86070- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
86071+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
86072 bcast_packet->seqno = htonl(seqno);
86073
86074 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
86075@@ -472,7 +472,7 @@ static int batadv_softif_init_late(struct net_device *dev)
86076 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
86077
86078 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
86079- atomic_set(&bat_priv->bcast_seqno, 1);
86080+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
86081 atomic_set(&bat_priv->tt.vn, 0);
86082 atomic_set(&bat_priv->tt.local_changes, 0);
86083 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
86084diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
86085index aba8364..50fcbb8 100644
86086--- a/net/batman-adv/types.h
86087+++ b/net/batman-adv/types.h
86088@@ -51,7 +51,7 @@
86089 struct batadv_hard_iface_bat_iv {
86090 unsigned char *ogm_buff;
86091 int ogm_buff_len;
86092- atomic_t ogm_seqno;
86093+ atomic_unchecked_t ogm_seqno;
86094 };
86095
86096 /**
86097@@ -75,7 +75,7 @@ struct batadv_hard_iface {
86098 int16_t if_num;
86099 char if_status;
86100 struct net_device *net_dev;
86101- atomic_t frag_seqno;
86102+ atomic_unchecked_t frag_seqno;
86103 struct kobject *hardif_obj;
86104 atomic_t refcount;
86105 struct packet_type batman_adv_ptype;
86106@@ -558,7 +558,7 @@ struct batadv_priv {
86107 #ifdef CONFIG_BATMAN_ADV_DEBUG
86108 atomic_t log_level;
86109 #endif
86110- atomic_t bcast_seqno;
86111+ atomic_unchecked_t bcast_seqno;
86112 atomic_t bcast_queue_left;
86113 atomic_t batman_queue_left;
86114 char num_ifaces;
86115diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
86116index 0bb3b59..ffcbf2f 100644
86117--- a/net/batman-adv/unicast.c
86118+++ b/net/batman-adv/unicast.c
86119@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
86120 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
86121 frag2->flags = large_tail;
86122
86123- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
86124+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
86125 frag1->seqno = htons(seqno - 1);
86126 frag2->seqno = htons(seqno);
86127
86128diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
86129index ace5e55..a65a1c0 100644
86130--- a/net/bluetooth/hci_core.c
86131+++ b/net/bluetooth/hci_core.c
86132@@ -2211,16 +2211,16 @@ int hci_register_dev(struct hci_dev *hdev)
86133 list_add(&hdev->list, &hci_dev_list);
86134 write_unlock(&hci_dev_list_lock);
86135
86136- hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND |
86137- WQ_MEM_RECLAIM, 1);
86138+ hdev->workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
86139+ WQ_MEM_RECLAIM, 1, hdev->name);
86140 if (!hdev->workqueue) {
86141 error = -ENOMEM;
86142 goto err;
86143 }
86144
86145- hdev->req_workqueue = alloc_workqueue(hdev->name,
86146+ hdev->req_workqueue = alloc_workqueue("%s",
86147 WQ_HIGHPRI | WQ_UNBOUND |
86148- WQ_MEM_RECLAIM, 1);
86149+ WQ_MEM_RECLAIM, 1, hdev->name);
86150 if (!hdev->req_workqueue) {
86151 destroy_workqueue(hdev->workqueue);
86152 error = -ENOMEM;
86153diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
86154index 9bd7d95..6c4884f 100644
86155--- a/net/bluetooth/hci_sock.c
86156+++ b/net/bluetooth/hci_sock.c
86157@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
86158 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
86159 }
86160
86161- len = min_t(unsigned int, len, sizeof(uf));
86162+ len = min((size_t)len, sizeof(uf));
86163 if (copy_from_user(&uf, optval, len)) {
86164 err = -EFAULT;
86165 break;
86166diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
86167index 68843a2..30e9342 100644
86168--- a/net/bluetooth/l2cap_core.c
86169+++ b/net/bluetooth/l2cap_core.c
86170@@ -3507,8 +3507,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
86171 break;
86172
86173 case L2CAP_CONF_RFC:
86174- if (olen == sizeof(rfc))
86175- memcpy(&rfc, (void *)val, olen);
86176+ if (olen != sizeof(rfc))
86177+ break;
86178+
86179+ memcpy(&rfc, (void *)val, olen);
86180
86181 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
86182 rfc.mode != chan->mode)
86183diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
86184index 36fed40..be2eeb2 100644
86185--- a/net/bluetooth/l2cap_sock.c
86186+++ b/net/bluetooth/l2cap_sock.c
86187@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
86188 struct sock *sk = sock->sk;
86189 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
86190 struct l2cap_options opts;
86191- int len, err = 0;
86192+ int err = 0;
86193+ size_t len = optlen;
86194 u32 opt;
86195
86196 BT_DBG("sk %p", sk);
86197@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
86198 opts.max_tx = chan->max_tx;
86199 opts.txwin_size = chan->tx_win;
86200
86201- len = min_t(unsigned int, sizeof(opts), optlen);
86202+ len = min(sizeof(opts), len);
86203 if (copy_from_user((char *) &opts, optval, len)) {
86204 err = -EFAULT;
86205 break;
86206@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86207 struct bt_security sec;
86208 struct bt_power pwr;
86209 struct l2cap_conn *conn;
86210- int len, err = 0;
86211+ int err = 0;
86212+ size_t len = optlen;
86213 u32 opt;
86214
86215 BT_DBG("sk %p", sk);
86216@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86217
86218 sec.level = BT_SECURITY_LOW;
86219
86220- len = min_t(unsigned int, sizeof(sec), optlen);
86221+ len = min(sizeof(sec), len);
86222 if (copy_from_user((char *) &sec, optval, len)) {
86223 err = -EFAULT;
86224 break;
86225@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86226
86227 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
86228
86229- len = min_t(unsigned int, sizeof(pwr), optlen);
86230+ len = min(sizeof(pwr), len);
86231 if (copy_from_user((char *) &pwr, optval, len)) {
86232 err = -EFAULT;
86233 break;
86234diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
86235index 30b3721..c1bd0a0 100644
86236--- a/net/bluetooth/rfcomm/sock.c
86237+++ b/net/bluetooth/rfcomm/sock.c
86238@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
86239 struct sock *sk = sock->sk;
86240 struct bt_security sec;
86241 int err = 0;
86242- size_t len;
86243+ size_t len = optlen;
86244 u32 opt;
86245
86246 BT_DBG("sk %p", sk);
86247@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
86248
86249 sec.level = BT_SECURITY_LOW;
86250
86251- len = min_t(unsigned int, sizeof(sec), optlen);
86252+ len = min(sizeof(sec), len);
86253 if (copy_from_user((char *) &sec, optval, len)) {
86254 err = -EFAULT;
86255 break;
86256diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
86257index b6e44ad..5b0d514 100644
86258--- a/net/bluetooth/rfcomm/tty.c
86259+++ b/net/bluetooth/rfcomm/tty.c
86260@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
86261 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
86262
86263 spin_lock_irqsave(&dev->port.lock, flags);
86264- if (dev->port.count > 0) {
86265+ if (atomic_read(&dev->port.count) > 0) {
86266 spin_unlock_irqrestore(&dev->port.lock, flags);
86267 return;
86268 }
86269@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
86270 return -ENODEV;
86271
86272 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
86273- dev->channel, dev->port.count);
86274+ dev->channel, atomic_read(&dev->port.count));
86275
86276 spin_lock_irqsave(&dev->port.lock, flags);
86277- if (++dev->port.count > 1) {
86278+ if (atomic_inc_return(&dev->port.count) > 1) {
86279 spin_unlock_irqrestore(&dev->port.lock, flags);
86280 return 0;
86281 }
86282@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
86283 return;
86284
86285 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
86286- dev->port.count);
86287+ atomic_read(&dev->port.count));
86288
86289 spin_lock_irqsave(&dev->port.lock, flags);
86290- if (!--dev->port.count) {
86291+ if (!atomic_dec_return(&dev->port.count)) {
86292 spin_unlock_irqrestore(&dev->port.lock, flags);
86293 if (dev->tty_dev->parent)
86294 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
86295diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
86296index 3d110c4..4e1b2eb 100644
86297--- a/net/bridge/netfilter/ebtables.c
86298+++ b/net/bridge/netfilter/ebtables.c
86299@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86300 tmp.valid_hooks = t->table->valid_hooks;
86301 }
86302 mutex_unlock(&ebt_mutex);
86303- if (copy_to_user(user, &tmp, *len) != 0){
86304+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
86305 BUGPRINT("c2u Didn't work\n");
86306 ret = -EFAULT;
86307 break;
86308@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
86309 goto out;
86310 tmp.valid_hooks = t->valid_hooks;
86311
86312- if (copy_to_user(user, &tmp, *len) != 0) {
86313+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
86314 ret = -EFAULT;
86315 break;
86316 }
86317@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
86318 tmp.entries_size = t->table->entries_size;
86319 tmp.valid_hooks = t->table->valid_hooks;
86320
86321- if (copy_to_user(user, &tmp, *len) != 0) {
86322+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
86323 ret = -EFAULT;
86324 break;
86325 }
86326diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
86327index 2bd4b58..0dc30a1 100644
86328--- a/net/caif/cfctrl.c
86329+++ b/net/caif/cfctrl.c
86330@@ -10,6 +10,7 @@
86331 #include <linux/spinlock.h>
86332 #include <linux/slab.h>
86333 #include <linux/pkt_sched.h>
86334+#include <linux/sched.h>
86335 #include <net/caif/caif_layer.h>
86336 #include <net/caif/cfpkt.h>
86337 #include <net/caif/cfctrl.h>
86338@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
86339 memset(&dev_info, 0, sizeof(dev_info));
86340 dev_info.id = 0xff;
86341 cfsrvl_init(&this->serv, 0, &dev_info, false);
86342- atomic_set(&this->req_seq_no, 1);
86343- atomic_set(&this->rsp_seq_no, 1);
86344+ atomic_set_unchecked(&this->req_seq_no, 1);
86345+ atomic_set_unchecked(&this->rsp_seq_no, 1);
86346 this->serv.layer.receive = cfctrl_recv;
86347 sprintf(this->serv.layer.name, "ctrl");
86348 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
86349@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
86350 struct cfctrl_request_info *req)
86351 {
86352 spin_lock_bh(&ctrl->info_list_lock);
86353- atomic_inc(&ctrl->req_seq_no);
86354- req->sequence_no = atomic_read(&ctrl->req_seq_no);
86355+ atomic_inc_unchecked(&ctrl->req_seq_no);
86356+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
86357 list_add_tail(&req->list, &ctrl->list);
86358 spin_unlock_bh(&ctrl->info_list_lock);
86359 }
86360@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
86361 if (p != first)
86362 pr_warn("Requests are not received in order\n");
86363
86364- atomic_set(&ctrl->rsp_seq_no,
86365+ atomic_set_unchecked(&ctrl->rsp_seq_no,
86366 p->sequence_no);
86367 list_del(&p->list);
86368 goto out;
86369diff --git a/net/can/af_can.c b/net/can/af_can.c
86370index c4e5085..aa9efdf 100644
86371--- a/net/can/af_can.c
86372+++ b/net/can/af_can.c
86373@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
86374 };
86375
86376 /* notifier block for netdevice event */
86377-static struct notifier_block can_netdev_notifier __read_mostly = {
86378+static struct notifier_block can_netdev_notifier = {
86379 .notifier_call = can_notifier,
86380 };
86381
86382diff --git a/net/can/gw.c b/net/can/gw.c
86383index 3ee690e..00d581b 100644
86384--- a/net/can/gw.c
86385+++ b/net/can/gw.c
86386@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
86387 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
86388
86389 static HLIST_HEAD(cgw_list);
86390-static struct notifier_block notifier;
86391
86392 static struct kmem_cache *cgw_cache __read_mostly;
86393
86394@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
86395 return err;
86396 }
86397
86398+static struct notifier_block notifier = {
86399+ .notifier_call = cgw_notifier
86400+};
86401+
86402 static __init int cgw_module_init(void)
86403 {
86404 /* sanitize given module parameter */
86405@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
86406 return -ENOMEM;
86407
86408 /* set notifier */
86409- notifier.notifier_call = cgw_notifier;
86410 register_netdevice_notifier(&notifier);
86411
86412 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
86413diff --git a/net/compat.c b/net/compat.c
86414index f0a1ba6..0541331 100644
86415--- a/net/compat.c
86416+++ b/net/compat.c
86417@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
86418 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
86419 __get_user(kmsg->msg_flags, &umsg->msg_flags))
86420 return -EFAULT;
86421- kmsg->msg_name = compat_ptr(tmp1);
86422- kmsg->msg_iov = compat_ptr(tmp2);
86423- kmsg->msg_control = compat_ptr(tmp3);
86424+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
86425+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
86426+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
86427 return 0;
86428 }
86429
86430@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86431
86432 if (kern_msg->msg_namelen) {
86433 if (mode == VERIFY_READ) {
86434- int err = move_addr_to_kernel(kern_msg->msg_name,
86435+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
86436 kern_msg->msg_namelen,
86437 kern_address);
86438 if (err < 0)
86439@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86440 kern_msg->msg_name = NULL;
86441
86442 tot_len = iov_from_user_compat_to_kern(kern_iov,
86443- (struct compat_iovec __user *)kern_msg->msg_iov,
86444+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
86445 kern_msg->msg_iovlen);
86446 if (tot_len >= 0)
86447 kern_msg->msg_iov = kern_iov;
86448@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86449
86450 #define CMSG_COMPAT_FIRSTHDR(msg) \
86451 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
86452- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
86453+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
86454 (struct compat_cmsghdr __user *)NULL)
86455
86456 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
86457 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
86458 (ucmlen) <= (unsigned long) \
86459 ((mhdr)->msg_controllen - \
86460- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
86461+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
86462
86463 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
86464 struct compat_cmsghdr __user *cmsg, int cmsg_len)
86465 {
86466 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
86467- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
86468+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
86469 msg->msg_controllen)
86470 return NULL;
86471 return (struct compat_cmsghdr __user *)ptr;
86472@@ -219,7 +219,7 @@ Efault:
86473
86474 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
86475 {
86476- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86477+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86478 struct compat_cmsghdr cmhdr;
86479 struct compat_timeval ctv;
86480 struct compat_timespec cts[3];
86481@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
86482
86483 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
86484 {
86485- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86486+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86487 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
86488 int fdnum = scm->fp->count;
86489 struct file **fp = scm->fp->fp;
86490@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
86491 return -EFAULT;
86492 old_fs = get_fs();
86493 set_fs(KERNEL_DS);
86494- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
86495+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
86496 set_fs(old_fs);
86497
86498 return err;
86499@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
86500 len = sizeof(ktime);
86501 old_fs = get_fs();
86502 set_fs(KERNEL_DS);
86503- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
86504+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
86505 set_fs(old_fs);
86506
86507 if (!err) {
86508@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86509 case MCAST_JOIN_GROUP:
86510 case MCAST_LEAVE_GROUP:
86511 {
86512- struct compat_group_req __user *gr32 = (void *)optval;
86513+ struct compat_group_req __user *gr32 = (void __user *)optval;
86514 struct group_req __user *kgr =
86515 compat_alloc_user_space(sizeof(struct group_req));
86516 u32 interface;
86517@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86518 case MCAST_BLOCK_SOURCE:
86519 case MCAST_UNBLOCK_SOURCE:
86520 {
86521- struct compat_group_source_req __user *gsr32 = (void *)optval;
86522+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
86523 struct group_source_req __user *kgsr = compat_alloc_user_space(
86524 sizeof(struct group_source_req));
86525 u32 interface;
86526@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86527 }
86528 case MCAST_MSFILTER:
86529 {
86530- struct compat_group_filter __user *gf32 = (void *)optval;
86531+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86532 struct group_filter __user *kgf;
86533 u32 interface, fmode, numsrc;
86534
86535@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
86536 char __user *optval, int __user *optlen,
86537 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
86538 {
86539- struct compat_group_filter __user *gf32 = (void *)optval;
86540+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86541 struct group_filter __user *kgf;
86542 int __user *koptlen;
86543 u32 interface, fmode, numsrc;
86544@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
86545
86546 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
86547 return -EINVAL;
86548- if (copy_from_user(a, args, nas[call]))
86549+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
86550 return -EFAULT;
86551 a0 = a[0];
86552 a1 = a[1];
86553diff --git a/net/core/datagram.c b/net/core/datagram.c
86554index b71423d..0360434 100644
86555--- a/net/core/datagram.c
86556+++ b/net/core/datagram.c
86557@@ -295,7 +295,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
86558 }
86559
86560 kfree_skb(skb);
86561- atomic_inc(&sk->sk_drops);
86562+ atomic_inc_unchecked(&sk->sk_drops);
86563 sk_mem_reclaim_partial(sk);
86564
86565 return err;
86566diff --git a/net/core/dev.c b/net/core/dev.c
86567index faebb39..a38fb42 100644
86568--- a/net/core/dev.c
86569+++ b/net/core/dev.c
86570@@ -1649,7 +1649,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86571 {
86572 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
86573 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
86574- atomic_long_inc(&dev->rx_dropped);
86575+ atomic_long_inc_unchecked(&dev->rx_dropped);
86576 kfree_skb(skb);
86577 return NET_RX_DROP;
86578 }
86579@@ -1658,7 +1658,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86580 skb_orphan(skb);
86581
86582 if (unlikely(!is_skb_forwardable(dev, skb))) {
86583- atomic_long_inc(&dev->rx_dropped);
86584+ atomic_long_inc_unchecked(&dev->rx_dropped);
86585 kfree_skb(skb);
86586 return NET_RX_DROP;
86587 }
86588@@ -2404,7 +2404,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
86589
86590 struct dev_gso_cb {
86591 void (*destructor)(struct sk_buff *skb);
86592-};
86593+} __no_const;
86594
86595 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
86596
86597@@ -3139,7 +3139,7 @@ enqueue:
86598
86599 local_irq_restore(flags);
86600
86601- atomic_long_inc(&skb->dev->rx_dropped);
86602+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86603 kfree_skb(skb);
86604 return NET_RX_DROP;
86605 }
86606@@ -3211,7 +3211,7 @@ int netif_rx_ni(struct sk_buff *skb)
86607 }
86608 EXPORT_SYMBOL(netif_rx_ni);
86609
86610-static void net_tx_action(struct softirq_action *h)
86611+static void net_tx_action(void)
86612 {
86613 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86614
86615@@ -3538,7 +3538,7 @@ ncls:
86616 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
86617 } else {
86618 drop:
86619- atomic_long_inc(&skb->dev->rx_dropped);
86620+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86621 kfree_skb(skb);
86622 /* Jamal, now you will not able to escape explaining
86623 * me how you were going to use this. :-)
86624@@ -4146,7 +4146,7 @@ void netif_napi_del(struct napi_struct *napi)
86625 }
86626 EXPORT_SYMBOL(netif_napi_del);
86627
86628-static void net_rx_action(struct softirq_action *h)
86629+static void net_rx_action(void)
86630 {
86631 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86632 unsigned long time_limit = jiffies + 2;
86633@@ -5583,7 +5583,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
86634 } else {
86635 netdev_stats_to_stats64(storage, &dev->stats);
86636 }
86637- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
86638+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
86639 return storage;
86640 }
86641 EXPORT_SYMBOL(dev_get_stats);
86642diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
86643index 5b7d0e1..cb960fc 100644
86644--- a/net/core/dev_ioctl.c
86645+++ b/net/core/dev_ioctl.c
86646@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
86647 if (no_module && capable(CAP_NET_ADMIN))
86648 no_module = request_module("netdev-%s", name);
86649 if (no_module && capable(CAP_SYS_MODULE)) {
86650+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86651+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
86652+#else
86653 if (!request_module("%s", name))
86654 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
86655 name);
86656+#endif
86657 }
86658 }
86659 EXPORT_SYMBOL(dev_load);
86660diff --git a/net/core/ethtool.c b/net/core/ethtool.c
86661index ce91766..3b71cdb 100644
86662--- a/net/core/ethtool.c
86663+++ b/net/core/ethtool.c
86664@@ -1319,10 +1319,19 @@ static int ethtool_get_dump_data(struct net_device *dev,
86665 if (ret)
86666 return ret;
86667
86668- len = (tmp.len > dump.len) ? dump.len : tmp.len;
86669+ len = min(tmp.len, dump.len);
86670 if (!len)
86671 return -EFAULT;
86672
86673+ /* Don't ever let the driver think there's more space available
86674+ * than it requested with .get_dump_flag().
86675+ */
86676+ dump.len = len;
86677+
86678+ /* Always allocate enough space to hold the whole thing so that the
86679+ * driver does not need to check the length and bother with partial
86680+ * dumping.
86681+ */
86682 data = vzalloc(tmp.len);
86683 if (!data)
86684 return -ENOMEM;
86685@@ -1330,6 +1339,16 @@ static int ethtool_get_dump_data(struct net_device *dev,
86686 if (ret)
86687 goto out;
86688
86689+ /* There are two sane possibilities:
86690+ * 1. The driver's .get_dump_data() does not touch dump.len.
86691+ * 2. Or it may set dump.len to how much it really writes, which
86692+ * should be tmp.len (or len if it can do a partial dump).
86693+ * In any case respond to userspace with the actual length of data
86694+ * it's receiving.
86695+ */
86696+ WARN_ON(dump.len != len && dump.len != tmp.len);
86697+ dump.len = len;
86698+
86699 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
86700 ret = -EFAULT;
86701 goto out;
86702diff --git a/net/core/flow.c b/net/core/flow.c
86703index 7102f16..146b4bd 100644
86704--- a/net/core/flow.c
86705+++ b/net/core/flow.c
86706@@ -61,7 +61,7 @@ struct flow_cache {
86707 struct timer_list rnd_timer;
86708 };
86709
86710-atomic_t flow_cache_genid = ATOMIC_INIT(0);
86711+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
86712 EXPORT_SYMBOL(flow_cache_genid);
86713 static struct flow_cache flow_cache_global;
86714 static struct kmem_cache *flow_cachep __read_mostly;
86715@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
86716
86717 static int flow_entry_valid(struct flow_cache_entry *fle)
86718 {
86719- if (atomic_read(&flow_cache_genid) != fle->genid)
86720+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
86721 return 0;
86722 if (fle->object && !fle->object->ops->check(fle->object))
86723 return 0;
86724@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
86725 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
86726 fcp->hash_count++;
86727 }
86728- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
86729+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
86730 flo = fle->object;
86731 if (!flo)
86732 goto ret_object;
86733@@ -279,7 +279,7 @@ nocache:
86734 }
86735 flo = resolver(net, key, family, dir, flo, ctx);
86736 if (fle) {
86737- fle->genid = atomic_read(&flow_cache_genid);
86738+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
86739 if (!IS_ERR(flo))
86740 fle->object = flo;
86741 else
86742diff --git a/net/core/iovec.c b/net/core/iovec.c
86743index de178e4..1dabd8b 100644
86744--- a/net/core/iovec.c
86745+++ b/net/core/iovec.c
86746@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86747 if (m->msg_namelen) {
86748 if (mode == VERIFY_READ) {
86749 void __user *namep;
86750- namep = (void __user __force *) m->msg_name;
86751+ namep = (void __force_user *) m->msg_name;
86752 err = move_addr_to_kernel(namep, m->msg_namelen,
86753 address);
86754 if (err < 0)
86755@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86756 }
86757
86758 size = m->msg_iovlen * sizeof(struct iovec);
86759- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
86760+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
86761 return -EFAULT;
86762
86763 m->msg_iov = iov;
86764diff --git a/net/core/neighbour.c b/net/core/neighbour.c
86765index 5c56b21..8766fbf 100644
86766--- a/net/core/neighbour.c
86767+++ b/net/core/neighbour.c
86768@@ -2769,7 +2769,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
86769 size_t *lenp, loff_t *ppos)
86770 {
86771 int size, ret;
86772- ctl_table tmp = *ctl;
86773+ ctl_table_no_const tmp = *ctl;
86774
86775 tmp.extra1 = &zero;
86776 tmp.extra2 = &unres_qlen_max;
86777diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
86778index 569d355..79cf2d0 100644
86779--- a/net/core/net-procfs.c
86780+++ b/net/core/net-procfs.c
86781@@ -271,8 +271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
86782 else
86783 seq_printf(seq, "%04x", ntohs(pt->type));
86784
86785+#ifdef CONFIG_GRKERNSEC_HIDESYM
86786+ seq_printf(seq, " %-8s %pf\n",
86787+ pt->dev ? pt->dev->name : "", NULL);
86788+#else
86789 seq_printf(seq, " %-8s %pf\n",
86790 pt->dev ? pt->dev->name : "", pt->func);
86791+#endif
86792 }
86793
86794 return 0;
86795diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
86796index 981fed3..536af34 100644
86797--- a/net/core/net-sysfs.c
86798+++ b/net/core/net-sysfs.c
86799@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
86800 }
86801 EXPORT_SYMBOL(netdev_class_remove_file);
86802
86803-int netdev_kobject_init(void)
86804+int __init netdev_kobject_init(void)
86805 {
86806 kobj_ns_type_register(&net_ns_type_operations);
86807 return class_register(&net_class);
86808diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
86809index f9765203..9feaef8 100644
86810--- a/net/core/net_namespace.c
86811+++ b/net/core/net_namespace.c
86812@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
86813 int error;
86814 LIST_HEAD(net_exit_list);
86815
86816- list_add_tail(&ops->list, list);
86817+ pax_list_add_tail((struct list_head *)&ops->list, list);
86818 if (ops->init || (ops->id && ops->size)) {
86819 for_each_net(net) {
86820 error = ops_init(ops, net);
86821@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
86822
86823 out_undo:
86824 /* If I have an error cleanup all namespaces I initialized */
86825- list_del(&ops->list);
86826+ pax_list_del((struct list_head *)&ops->list);
86827 ops_exit_list(ops, &net_exit_list);
86828 ops_free_list(ops, &net_exit_list);
86829 return error;
86830@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
86831 struct net *net;
86832 LIST_HEAD(net_exit_list);
86833
86834- list_del(&ops->list);
86835+ pax_list_del((struct list_head *)&ops->list);
86836 for_each_net(net)
86837 list_add_tail(&net->exit_list, &net_exit_list);
86838 ops_exit_list(ops, &net_exit_list);
86839@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
86840 mutex_lock(&net_mutex);
86841 error = register_pernet_operations(&pernet_list, ops);
86842 if (!error && (first_device == &pernet_list))
86843- first_device = &ops->list;
86844+ first_device = (struct list_head *)&ops->list;
86845 mutex_unlock(&net_mutex);
86846 return error;
86847 }
86848diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
86849index a08bd2b..4e8f43c 100644
86850--- a/net/core/rtnetlink.c
86851+++ b/net/core/rtnetlink.c
86852@@ -58,7 +58,7 @@ struct rtnl_link {
86853 rtnl_doit_func doit;
86854 rtnl_dumpit_func dumpit;
86855 rtnl_calcit_func calcit;
86856-};
86857+} __no_const;
86858
86859 static DEFINE_MUTEX(rtnl_mutex);
86860
86861@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
86862 if (rtnl_link_ops_get(ops->kind))
86863 return -EEXIST;
86864
86865- if (!ops->dellink)
86866- ops->dellink = unregister_netdevice_queue;
86867+ if (!ops->dellink) {
86868+ pax_open_kernel();
86869+ *(void **)&ops->dellink = unregister_netdevice_queue;
86870+ pax_close_kernel();
86871+ }
86872
86873- list_add_tail(&ops->list, &link_ops);
86874+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
86875 return 0;
86876 }
86877 EXPORT_SYMBOL_GPL(__rtnl_link_register);
86878@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
86879 for_each_net(net) {
86880 __rtnl_kill_links(net, ops);
86881 }
86882- list_del(&ops->list);
86883+ pax_list_del((struct list_head *)&ops->list);
86884 }
86885 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
86886
86887diff --git a/net/core/scm.c b/net/core/scm.c
86888index 03795d0..eaf7368 100644
86889--- a/net/core/scm.c
86890+++ b/net/core/scm.c
86891@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
86892 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86893 {
86894 struct cmsghdr __user *cm
86895- = (__force struct cmsghdr __user *)msg->msg_control;
86896+ = (struct cmsghdr __force_user *)msg->msg_control;
86897 struct cmsghdr cmhdr;
86898 int cmlen = CMSG_LEN(len);
86899 int err;
86900@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86901 err = -EFAULT;
86902 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
86903 goto out;
86904- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
86905+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
86906 goto out;
86907 cmlen = CMSG_SPACE(len);
86908 if (msg->msg_controllen < cmlen)
86909@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
86910 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86911 {
86912 struct cmsghdr __user *cm
86913- = (__force struct cmsghdr __user*)msg->msg_control;
86914+ = (struct cmsghdr __force_user *)msg->msg_control;
86915
86916 int fdmax = 0;
86917 int fdnum = scm->fp->count;
86918@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86919 if (fdnum < fdmax)
86920 fdmax = fdnum;
86921
86922- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
86923+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
86924 i++, cmfptr++)
86925 {
86926 struct socket *sock;
86927diff --git a/net/core/sock.c b/net/core/sock.c
86928index d6d024c..6ea7ab4 100644
86929--- a/net/core/sock.c
86930+++ b/net/core/sock.c
86931@@ -390,7 +390,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86932 struct sk_buff_head *list = &sk->sk_receive_queue;
86933
86934 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
86935- atomic_inc(&sk->sk_drops);
86936+ atomic_inc_unchecked(&sk->sk_drops);
86937 trace_sock_rcvqueue_full(sk, skb);
86938 return -ENOMEM;
86939 }
86940@@ -400,7 +400,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86941 return err;
86942
86943 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
86944- atomic_inc(&sk->sk_drops);
86945+ atomic_inc_unchecked(&sk->sk_drops);
86946 return -ENOBUFS;
86947 }
86948
86949@@ -420,7 +420,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86950 skb_dst_force(skb);
86951
86952 spin_lock_irqsave(&list->lock, flags);
86953- skb->dropcount = atomic_read(&sk->sk_drops);
86954+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86955 __skb_queue_tail(list, skb);
86956 spin_unlock_irqrestore(&list->lock, flags);
86957
86958@@ -440,7 +440,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86959 skb->dev = NULL;
86960
86961 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
86962- atomic_inc(&sk->sk_drops);
86963+ atomic_inc_unchecked(&sk->sk_drops);
86964 goto discard_and_relse;
86965 }
86966 if (nested)
86967@@ -458,7 +458,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86968 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
86969 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
86970 bh_unlock_sock(sk);
86971- atomic_inc(&sk->sk_drops);
86972+ atomic_inc_unchecked(&sk->sk_drops);
86973 goto discard_and_relse;
86974 }
86975
86976@@ -933,12 +933,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86977 struct timeval tm;
86978 } v;
86979
86980- int lv = sizeof(int);
86981- int len;
86982+ unsigned int lv = sizeof(int);
86983+ unsigned int len;
86984
86985 if (get_user(len, optlen))
86986 return -EFAULT;
86987- if (len < 0)
86988+ if (len > INT_MAX)
86989 return -EINVAL;
86990
86991 memset(&v, 0, sizeof(v));
86992@@ -1090,11 +1090,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86993
86994 case SO_PEERNAME:
86995 {
86996- char address[128];
86997+ char address[_K_SS_MAXSIZE];
86998
86999 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
87000 return -ENOTCONN;
87001- if (lv < len)
87002+ if (lv < len || sizeof address < len)
87003 return -EINVAL;
87004 if (copy_to_user(optval, address, len))
87005 return -EFAULT;
87006@@ -1161,7 +1161,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
87007
87008 if (len > lv)
87009 len = lv;
87010- if (copy_to_user(optval, &v, len))
87011+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
87012 return -EFAULT;
87013 lenout:
87014 if (put_user(len, optlen))
87015@@ -2277,7 +2277,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
87016 */
87017 smp_wmb();
87018 atomic_set(&sk->sk_refcnt, 1);
87019- atomic_set(&sk->sk_drops, 0);
87020+ atomic_set_unchecked(&sk->sk_drops, 0);
87021 }
87022 EXPORT_SYMBOL(sock_init_data);
87023
87024diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
87025index a0e9cf6..ef7f9ed 100644
87026--- a/net/core/sock_diag.c
87027+++ b/net/core/sock_diag.c
87028@@ -9,26 +9,33 @@
87029 #include <linux/inet_diag.h>
87030 #include <linux/sock_diag.h>
87031
87032-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
87033+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
87034 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
87035 static DEFINE_MUTEX(sock_diag_table_mutex);
87036
87037 int sock_diag_check_cookie(void *sk, __u32 *cookie)
87038 {
87039+#ifndef CONFIG_GRKERNSEC_HIDESYM
87040 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
87041 cookie[1] != INET_DIAG_NOCOOKIE) &&
87042 ((u32)(unsigned long)sk != cookie[0] ||
87043 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
87044 return -ESTALE;
87045 else
87046+#endif
87047 return 0;
87048 }
87049 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
87050
87051 void sock_diag_save_cookie(void *sk, __u32 *cookie)
87052 {
87053+#ifdef CONFIG_GRKERNSEC_HIDESYM
87054+ cookie[0] = 0;
87055+ cookie[1] = 0;
87056+#else
87057 cookie[0] = (u32)(unsigned long)sk;
87058 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
87059+#endif
87060 }
87061 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
87062
87063@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
87064 mutex_lock(&sock_diag_table_mutex);
87065 if (sock_diag_handlers[hndl->family])
87066 err = -EBUSY;
87067- else
87068+ else {
87069+ pax_open_kernel();
87070 sock_diag_handlers[hndl->family] = hndl;
87071+ pax_close_kernel();
87072+ }
87073 mutex_unlock(&sock_diag_table_mutex);
87074
87075 return err;
87076@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
87077
87078 mutex_lock(&sock_diag_table_mutex);
87079 BUG_ON(sock_diag_handlers[family] != hnld);
87080+ pax_open_kernel();
87081 sock_diag_handlers[family] = NULL;
87082+ pax_close_kernel();
87083 mutex_unlock(&sock_diag_table_mutex);
87084 }
87085 EXPORT_SYMBOL_GPL(sock_diag_unregister);
87086diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
87087index cfdb46a..cef55e1 100644
87088--- a/net/core/sysctl_net_core.c
87089+++ b/net/core/sysctl_net_core.c
87090@@ -28,7 +28,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
87091 {
87092 unsigned int orig_size, size;
87093 int ret, i;
87094- ctl_table tmp = {
87095+ ctl_table_no_const tmp = {
87096 .data = &size,
87097 .maxlen = sizeof(size),
87098 .mode = table->mode
87099@@ -211,13 +211,12 @@ static struct ctl_table netns_core_table[] = {
87100
87101 static __net_init int sysctl_core_net_init(struct net *net)
87102 {
87103- struct ctl_table *tbl;
87104+ ctl_table_no_const *tbl = NULL;
87105
87106 net->core.sysctl_somaxconn = SOMAXCONN;
87107
87108- tbl = netns_core_table;
87109 if (!net_eq(net, &init_net)) {
87110- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
87111+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
87112 if (tbl == NULL)
87113 goto err_dup;
87114
87115@@ -227,17 +226,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
87116 if (net->user_ns != &init_user_ns) {
87117 tbl[0].procname = NULL;
87118 }
87119- }
87120-
87121- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
87122+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
87123+ } else
87124+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
87125 if (net->core.sysctl_hdr == NULL)
87126 goto err_reg;
87127
87128 return 0;
87129
87130 err_reg:
87131- if (tbl != netns_core_table)
87132- kfree(tbl);
87133+ kfree(tbl);
87134 err_dup:
87135 return -ENOMEM;
87136 }
87137@@ -252,7 +250,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
87138 kfree(tbl);
87139 }
87140
87141-static __net_initdata struct pernet_operations sysctl_core_ops = {
87142+static __net_initconst struct pernet_operations sysctl_core_ops = {
87143 .init = sysctl_core_net_init,
87144 .exit = sysctl_core_net_exit,
87145 };
87146diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
87147index c21f200..bc4565b 100644
87148--- a/net/decnet/af_decnet.c
87149+++ b/net/decnet/af_decnet.c
87150@@ -465,6 +465,7 @@ static struct proto dn_proto = {
87151 .sysctl_rmem = sysctl_decnet_rmem,
87152 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
87153 .obj_size = sizeof(struct dn_sock),
87154+ .slab_flags = SLAB_USERCOPY,
87155 };
87156
87157 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
87158diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
87159index a55eecc..dd8428c 100644
87160--- a/net/decnet/sysctl_net_decnet.c
87161+++ b/net/decnet/sysctl_net_decnet.c
87162@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
87163
87164 if (len > *lenp) len = *lenp;
87165
87166- if (copy_to_user(buffer, addr, len))
87167+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
87168 return -EFAULT;
87169
87170 *lenp = len;
87171@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
87172
87173 if (len > *lenp) len = *lenp;
87174
87175- if (copy_to_user(buffer, devname, len))
87176+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
87177 return -EFAULT;
87178
87179 *lenp = len;
87180diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
87181index d01be2a..8976537 100644
87182--- a/net/ipv4/af_inet.c
87183+++ b/net/ipv4/af_inet.c
87184@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
87185
87186 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
87187
87188- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
87189- if (!sysctl_local_reserved_ports)
87190- goto out;
87191-
87192 rc = proto_register(&tcp_prot, 1);
87193 if (rc)
87194- goto out_free_reserved_ports;
87195+ goto out;
87196
87197 rc = proto_register(&udp_prot, 1);
87198 if (rc)
87199@@ -1818,8 +1814,6 @@ out_unregister_udp_proto:
87200 proto_unregister(&udp_prot);
87201 out_unregister_tcp_proto:
87202 proto_unregister(&tcp_prot);
87203-out_free_reserved_ports:
87204- kfree(sysctl_local_reserved_ports);
87205 goto out;
87206 }
87207
87208diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
87209index 2e7f194..0fa4d6d 100644
87210--- a/net/ipv4/ah4.c
87211+++ b/net/ipv4/ah4.c
87212@@ -420,7 +420,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
87213 return;
87214
87215 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87216- atomic_inc(&flow_cache_genid);
87217+ atomic_inc_unchecked(&flow_cache_genid);
87218 rt_genid_bump(net);
87219
87220 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
87221diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
87222index dfc39d4..0b82c4d 100644
87223--- a/net/ipv4/devinet.c
87224+++ b/net/ipv4/devinet.c
87225@@ -1529,7 +1529,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
87226 idx = 0;
87227 head = &net->dev_index_head[h];
87228 rcu_read_lock();
87229- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
87230+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
87231 net->dev_base_seq;
87232 hlist_for_each_entry_rcu(dev, head, index_hlist) {
87233 if (idx < s_idx)
87234@@ -1840,7 +1840,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
87235 idx = 0;
87236 head = &net->dev_index_head[h];
87237 rcu_read_lock();
87238- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
87239+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
87240 net->dev_base_seq;
87241 hlist_for_each_entry_rcu(dev, head, index_hlist) {
87242 if (idx < s_idx)
87243@@ -2065,7 +2065,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
87244 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
87245 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
87246
87247-static struct devinet_sysctl_table {
87248+static const struct devinet_sysctl_table {
87249 struct ctl_table_header *sysctl_header;
87250 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
87251 } devinet_sysctl = {
87252@@ -2183,7 +2183,7 @@ static __net_init int devinet_init_net(struct net *net)
87253 int err;
87254 struct ipv4_devconf *all, *dflt;
87255 #ifdef CONFIG_SYSCTL
87256- struct ctl_table *tbl = ctl_forward_entry;
87257+ ctl_table_no_const *tbl = NULL;
87258 struct ctl_table_header *forw_hdr;
87259 #endif
87260
87261@@ -2201,7 +2201,7 @@ static __net_init int devinet_init_net(struct net *net)
87262 goto err_alloc_dflt;
87263
87264 #ifdef CONFIG_SYSCTL
87265- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
87266+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
87267 if (tbl == NULL)
87268 goto err_alloc_ctl;
87269
87270@@ -2221,7 +2221,10 @@ static __net_init int devinet_init_net(struct net *net)
87271 goto err_reg_dflt;
87272
87273 err = -ENOMEM;
87274- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
87275+ if (!net_eq(net, &init_net))
87276+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
87277+ else
87278+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
87279 if (forw_hdr == NULL)
87280 goto err_reg_ctl;
87281 net->ipv4.forw_hdr = forw_hdr;
87282@@ -2237,8 +2240,7 @@ err_reg_ctl:
87283 err_reg_dflt:
87284 __devinet_sysctl_unregister(all);
87285 err_reg_all:
87286- if (tbl != ctl_forward_entry)
87287- kfree(tbl);
87288+ kfree(tbl);
87289 err_alloc_ctl:
87290 #endif
87291 if (dflt != &ipv4_devconf_dflt)
87292diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
87293index 4cfe34d..a6ba66e 100644
87294--- a/net/ipv4/esp4.c
87295+++ b/net/ipv4/esp4.c
87296@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
87297 return;
87298
87299 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87300- atomic_inc(&flow_cache_genid);
87301+ atomic_inc_unchecked(&flow_cache_genid);
87302 rt_genid_bump(net);
87303
87304 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
87305diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
87306index c7629a2..b62d139 100644
87307--- a/net/ipv4/fib_frontend.c
87308+++ b/net/ipv4/fib_frontend.c
87309@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
87310 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87311 fib_sync_up(dev);
87312 #endif
87313- atomic_inc(&net->ipv4.dev_addr_genid);
87314+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87315 rt_cache_flush(dev_net(dev));
87316 break;
87317 case NETDEV_DOWN:
87318 fib_del_ifaddr(ifa, NULL);
87319- atomic_inc(&net->ipv4.dev_addr_genid);
87320+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87321 if (ifa->ifa_dev->ifa_list == NULL) {
87322 /* Last address was deleted from this interface.
87323 * Disable IP.
87324@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
87325 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87326 fib_sync_up(dev);
87327 #endif
87328- atomic_inc(&net->ipv4.dev_addr_genid);
87329+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87330 rt_cache_flush(net);
87331 break;
87332 case NETDEV_DOWN:
87333diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
87334index 8f6cb7a..34507f9 100644
87335--- a/net/ipv4/fib_semantics.c
87336+++ b/net/ipv4/fib_semantics.c
87337@@ -765,7 +765,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
87338 nh->nh_saddr = inet_select_addr(nh->nh_dev,
87339 nh->nh_gw,
87340 nh->nh_parent->fib_scope);
87341- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
87342+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
87343
87344 return nh->nh_saddr;
87345 }
87346diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
87347index 6acb541..9ea617d 100644
87348--- a/net/ipv4/inet_connection_sock.c
87349+++ b/net/ipv4/inet_connection_sock.c
87350@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
87351 .range = { 32768, 61000 },
87352 };
87353
87354-unsigned long *sysctl_local_reserved_ports;
87355+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
87356 EXPORT_SYMBOL(sysctl_local_reserved_ports);
87357
87358 void inet_get_local_port_range(int *low, int *high)
87359diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
87360index 6af375a..c493c74 100644
87361--- a/net/ipv4/inet_hashtables.c
87362+++ b/net/ipv4/inet_hashtables.c
87363@@ -18,12 +18,15 @@
87364 #include <linux/sched.h>
87365 #include <linux/slab.h>
87366 #include <linux/wait.h>
87367+#include <linux/security.h>
87368
87369 #include <net/inet_connection_sock.h>
87370 #include <net/inet_hashtables.h>
87371 #include <net/secure_seq.h>
87372 #include <net/ip.h>
87373
87374+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
87375+
87376 /*
87377 * Allocate and initialize a new local port bind bucket.
87378 * The bindhash mutex for snum's hash chain must be held here.
87379@@ -554,6 +557,8 @@ ok:
87380 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
87381 spin_unlock(&head->lock);
87382
87383+ gr_update_task_in_ip_table(current, inet_sk(sk));
87384+
87385 if (tw) {
87386 inet_twsk_deschedule(tw, death_row);
87387 while (twrefcnt) {
87388diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
87389index 000e3d2..5472da3 100644
87390--- a/net/ipv4/inetpeer.c
87391+++ b/net/ipv4/inetpeer.c
87392@@ -503,8 +503,8 @@ relookup:
87393 if (p) {
87394 p->daddr = *daddr;
87395 atomic_set(&p->refcnt, 1);
87396- atomic_set(&p->rid, 0);
87397- atomic_set(&p->ip_id_count,
87398+ atomic_set_unchecked(&p->rid, 0);
87399+ atomic_set_unchecked(&p->ip_id_count,
87400 (daddr->family == AF_INET) ?
87401 secure_ip_id(daddr->addr.a4) :
87402 secure_ipv6_id(daddr->addr.a6));
87403diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
87404index b66910a..cfe416e 100644
87405--- a/net/ipv4/ip_fragment.c
87406+++ b/net/ipv4/ip_fragment.c
87407@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
87408 return 0;
87409
87410 start = qp->rid;
87411- end = atomic_inc_return(&peer->rid);
87412+ end = atomic_inc_return_unchecked(&peer->rid);
87413 qp->rid = end;
87414
87415 rc = qp->q.fragments && (end - start) > max;
87416@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
87417
87418 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87419 {
87420- struct ctl_table *table;
87421+ ctl_table_no_const *table = NULL;
87422 struct ctl_table_header *hdr;
87423
87424- table = ip4_frags_ns_ctl_table;
87425 if (!net_eq(net, &init_net)) {
87426- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87427+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87428 if (table == NULL)
87429 goto err_alloc;
87430
87431@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87432 /* Don't export sysctls to unprivileged users */
87433 if (net->user_ns != &init_user_ns)
87434 table[0].procname = NULL;
87435- }
87436+ hdr = register_net_sysctl(net, "net/ipv4", table);
87437+ } else
87438+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
87439
87440- hdr = register_net_sysctl(net, "net/ipv4", table);
87441 if (hdr == NULL)
87442 goto err_reg;
87443
87444@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87445 return 0;
87446
87447 err_reg:
87448- if (!net_eq(net, &init_net))
87449- kfree(table);
87450+ kfree(table);
87451 err_alloc:
87452 return -ENOMEM;
87453 }
87454diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
87455index 2a83591..68e7458 100644
87456--- a/net/ipv4/ip_gre.c
87457+++ b/net/ipv4/ip_gre.c
87458@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
87459 module_param(log_ecn_error, bool, 0644);
87460 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87461
87462-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
87463+static struct rtnl_link_ops ipgre_link_ops;
87464 static int ipgre_tunnel_init(struct net_device *dev);
87465
87466 static int ipgre_net_id __read_mostly;
87467@@ -503,10 +503,11 @@ static int ipgre_tunnel_ioctl(struct net_device *dev,
87468
87469 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
87470 return -EFAULT;
87471- if (p.iph.version != 4 || p.iph.protocol != IPPROTO_GRE ||
87472- p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)) ||
87473- ((p.i_flags|p.o_flags)&(GRE_VERSION|GRE_ROUTING))) {
87474- return -EINVAL;
87475+ if (cmd == SIOCADDTUNNEL || cmd == SIOCCHGTUNNEL) {
87476+ if (p.iph.version != 4 || p.iph.protocol != IPPROTO_GRE ||
87477+ p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)) ||
87478+ ((p.i_flags|p.o_flags)&(GRE_VERSION|GRE_ROUTING)))
87479+ return -EINVAL;
87480 }
87481 p.i_flags = gre_flags_to_tnl_flags(p.i_flags);
87482 p.o_flags = gre_flags_to_tnl_flags(p.o_flags);
87483@@ -918,7 +919,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
87484 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
87485 };
87486
87487-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87488+static struct rtnl_link_ops ipgre_link_ops = {
87489 .kind = "gre",
87490 .maxtype = IFLA_GRE_MAX,
87491 .policy = ipgre_policy,
87492@@ -932,7 +933,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87493 .fill_info = ipgre_fill_info,
87494 };
87495
87496-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
87497+static struct rtnl_link_ops ipgre_tap_ops = {
87498 .kind = "gretap",
87499 .maxtype = IFLA_GRE_MAX,
87500 .policy = ipgre_policy,
87501diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
87502index d9c4f11..02b82dbc 100644
87503--- a/net/ipv4/ip_sockglue.c
87504+++ b/net/ipv4/ip_sockglue.c
87505@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87506 len = min_t(unsigned int, len, opt->optlen);
87507 if (put_user(len, optlen))
87508 return -EFAULT;
87509- if (copy_to_user(optval, opt->__data, len))
87510+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
87511+ copy_to_user(optval, opt->__data, len))
87512 return -EFAULT;
87513 return 0;
87514 }
87515@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87516 if (sk->sk_type != SOCK_STREAM)
87517 return -ENOPROTOOPT;
87518
87519- msg.msg_control = optval;
87520+ msg.msg_control = (void __force_kernel *)optval;
87521 msg.msg_controllen = len;
87522 msg.msg_flags = flags;
87523
87524diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
87525index c118f6b..63856c4 100644
87526--- a/net/ipv4/ip_vti.c
87527+++ b/net/ipv4/ip_vti.c
87528@@ -47,7 +47,7 @@
87529 #define HASH_SIZE 16
87530 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
87531
87532-static struct rtnl_link_ops vti_link_ops __read_mostly;
87533+static struct rtnl_link_ops vti_link_ops;
87534
87535 static int vti_net_id __read_mostly;
87536 struct vti_net {
87537@@ -606,17 +606,10 @@ static int __net_init vti_fb_tunnel_init(struct net_device *dev)
87538 struct iphdr *iph = &tunnel->parms.iph;
87539 struct vti_net *ipn = net_generic(dev_net(dev), vti_net_id);
87540
87541- tunnel->dev = dev;
87542- strcpy(tunnel->parms.name, dev->name);
87543-
87544 iph->version = 4;
87545 iph->protocol = IPPROTO_IPIP;
87546 iph->ihl = 5;
87547
87548- dev->tstats = alloc_percpu(struct pcpu_tstats);
87549- if (!dev->tstats)
87550- return -ENOMEM;
87551-
87552 dev_hold(dev);
87553 rcu_assign_pointer(ipn->tunnels_wc[0], tunnel);
87554 return 0;
87555@@ -847,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
87556 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
87557 };
87558
87559-static struct rtnl_link_ops vti_link_ops __read_mostly = {
87560+static struct rtnl_link_ops vti_link_ops = {
87561 .kind = "vti",
87562 .maxtype = IFLA_VTI_MAX,
87563 .policy = vti_policy,
87564diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
87565index 59cb8c7..a72160c 100644
87566--- a/net/ipv4/ipcomp.c
87567+++ b/net/ipv4/ipcomp.c
87568@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
87569 return;
87570
87571 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87572- atomic_inc(&flow_cache_genid);
87573+ atomic_inc_unchecked(&flow_cache_genid);
87574 rt_genid_bump(net);
87575
87576 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
87577diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
87578index efa1138..20dbba0 100644
87579--- a/net/ipv4/ipconfig.c
87580+++ b/net/ipv4/ipconfig.c
87581@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
87582
87583 mm_segment_t oldfs = get_fs();
87584 set_fs(get_ds());
87585- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87586+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87587 set_fs(oldfs);
87588 return res;
87589 }
87590@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
87591
87592 mm_segment_t oldfs = get_fs();
87593 set_fs(get_ds());
87594- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87595+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87596 set_fs(oldfs);
87597 return res;
87598 }
87599@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
87600
87601 mm_segment_t oldfs = get_fs();
87602 set_fs(get_ds());
87603- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
87604+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
87605 set_fs(oldfs);
87606 return res;
87607 }
87608diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
87609index 77bfcce..64a55d4 100644
87610--- a/net/ipv4/ipip.c
87611+++ b/net/ipv4/ipip.c
87612@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87613 static int ipip_net_id __read_mostly;
87614
87615 static int ipip_tunnel_init(struct net_device *dev);
87616-static struct rtnl_link_ops ipip_link_ops __read_mostly;
87617+static struct rtnl_link_ops ipip_link_ops;
87618
87619 static int ipip_err(struct sk_buff *skb, u32 info)
87620 {
87621@@ -404,7 +404,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
87622 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
87623 };
87624
87625-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
87626+static struct rtnl_link_ops ipip_link_ops = {
87627 .kind = "ipip",
87628 .maxtype = IFLA_IPTUN_MAX,
87629 .policy = ipip_policy,
87630diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
87631index 85a4f21..1beb1f5 100644
87632--- a/net/ipv4/netfilter/arp_tables.c
87633+++ b/net/ipv4/netfilter/arp_tables.c
87634@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
87635 #endif
87636
87637 static int get_info(struct net *net, void __user *user,
87638- const int *len, int compat)
87639+ int len, int compat)
87640 {
87641 char name[XT_TABLE_MAXNAMELEN];
87642 struct xt_table *t;
87643 int ret;
87644
87645- if (*len != sizeof(struct arpt_getinfo)) {
87646- duprintf("length %u != %Zu\n", *len,
87647+ if (len != sizeof(struct arpt_getinfo)) {
87648+ duprintf("length %u != %Zu\n", len,
87649 sizeof(struct arpt_getinfo));
87650 return -EINVAL;
87651 }
87652@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
87653 info.size = private->size;
87654 strcpy(info.name, name);
87655
87656- if (copy_to_user(user, &info, *len) != 0)
87657+ if (copy_to_user(user, &info, len) != 0)
87658 ret = -EFAULT;
87659 else
87660 ret = 0;
87661@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
87662
87663 switch (cmd) {
87664 case ARPT_SO_GET_INFO:
87665- ret = get_info(sock_net(sk), user, len, 1);
87666+ ret = get_info(sock_net(sk), user, *len, 1);
87667 break;
87668 case ARPT_SO_GET_ENTRIES:
87669 ret = compat_get_entries(sock_net(sk), user, len);
87670@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
87671
87672 switch (cmd) {
87673 case ARPT_SO_GET_INFO:
87674- ret = get_info(sock_net(sk), user, len, 0);
87675+ ret = get_info(sock_net(sk), user, *len, 0);
87676 break;
87677
87678 case ARPT_SO_GET_ENTRIES:
87679diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
87680index d23118d..6ad7277 100644
87681--- a/net/ipv4/netfilter/ip_tables.c
87682+++ b/net/ipv4/netfilter/ip_tables.c
87683@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
87684 #endif
87685
87686 static int get_info(struct net *net, void __user *user,
87687- const int *len, int compat)
87688+ int len, int compat)
87689 {
87690 char name[XT_TABLE_MAXNAMELEN];
87691 struct xt_table *t;
87692 int ret;
87693
87694- if (*len != sizeof(struct ipt_getinfo)) {
87695- duprintf("length %u != %zu\n", *len,
87696+ if (len != sizeof(struct ipt_getinfo)) {
87697+ duprintf("length %u != %zu\n", len,
87698 sizeof(struct ipt_getinfo));
87699 return -EINVAL;
87700 }
87701@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
87702 info.size = private->size;
87703 strcpy(info.name, name);
87704
87705- if (copy_to_user(user, &info, *len) != 0)
87706+ if (copy_to_user(user, &info, len) != 0)
87707 ret = -EFAULT;
87708 else
87709 ret = 0;
87710@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87711
87712 switch (cmd) {
87713 case IPT_SO_GET_INFO:
87714- ret = get_info(sock_net(sk), user, len, 1);
87715+ ret = get_info(sock_net(sk), user, *len, 1);
87716 break;
87717 case IPT_SO_GET_ENTRIES:
87718 ret = compat_get_entries(sock_net(sk), user, len);
87719@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87720
87721 switch (cmd) {
87722 case IPT_SO_GET_INFO:
87723- ret = get_info(sock_net(sk), user, len, 0);
87724+ ret = get_info(sock_net(sk), user, *len, 0);
87725 break;
87726
87727 case IPT_SO_GET_ENTRIES:
87728diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
87729index 7d93d62..cbbf2a3 100644
87730--- a/net/ipv4/ping.c
87731+++ b/net/ipv4/ping.c
87732@@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
87733 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87734 0, sock_i_ino(sp),
87735 atomic_read(&sp->sk_refcnt), sp,
87736- atomic_read(&sp->sk_drops), len);
87737+ atomic_read_unchecked(&sp->sk_drops), len);
87738 }
87739
87740 static int ping_seq_show(struct seq_file *seq, void *v)
87741diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
87742index dd44e0a..06dcca4 100644
87743--- a/net/ipv4/raw.c
87744+++ b/net/ipv4/raw.c
87745@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
87746 int raw_rcv(struct sock *sk, struct sk_buff *skb)
87747 {
87748 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
87749- atomic_inc(&sk->sk_drops);
87750+ atomic_inc_unchecked(&sk->sk_drops);
87751 kfree_skb(skb);
87752 return NET_RX_DROP;
87753 }
87754@@ -745,16 +745,20 @@ static int raw_init(struct sock *sk)
87755
87756 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
87757 {
87758+ struct icmp_filter filter;
87759+
87760 if (optlen > sizeof(struct icmp_filter))
87761 optlen = sizeof(struct icmp_filter);
87762- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
87763+ if (copy_from_user(&filter, optval, optlen))
87764 return -EFAULT;
87765+ raw_sk(sk)->filter = filter;
87766 return 0;
87767 }
87768
87769 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
87770 {
87771 int len, ret = -EFAULT;
87772+ struct icmp_filter filter;
87773
87774 if (get_user(len, optlen))
87775 goto out;
87776@@ -764,8 +768,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
87777 if (len > sizeof(struct icmp_filter))
87778 len = sizeof(struct icmp_filter);
87779 ret = -EFAULT;
87780- if (put_user(len, optlen) ||
87781- copy_to_user(optval, &raw_sk(sk)->filter, len))
87782+ filter = raw_sk(sk)->filter;
87783+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
87784 goto out;
87785 ret = 0;
87786 out: return ret;
87787@@ -994,7 +998,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87788 0, 0L, 0,
87789 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87790 0, sock_i_ino(sp),
87791- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87792+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87793 }
87794
87795 static int raw_seq_show(struct seq_file *seq, void *v)
87796diff --git a/net/ipv4/route.c b/net/ipv4/route.c
87797index d35bbf0..faa3ab8 100644
87798--- a/net/ipv4/route.c
87799+++ b/net/ipv4/route.c
87800@@ -2558,34 +2558,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
87801 .maxlen = sizeof(int),
87802 .mode = 0200,
87803 .proc_handler = ipv4_sysctl_rtcache_flush,
87804+ .extra1 = &init_net,
87805 },
87806 { },
87807 };
87808
87809 static __net_init int sysctl_route_net_init(struct net *net)
87810 {
87811- struct ctl_table *tbl;
87812+ ctl_table_no_const *tbl = NULL;
87813
87814- tbl = ipv4_route_flush_table;
87815 if (!net_eq(net, &init_net)) {
87816- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87817+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87818 if (tbl == NULL)
87819 goto err_dup;
87820
87821 /* Don't export sysctls to unprivileged users */
87822 if (net->user_ns != &init_user_ns)
87823 tbl[0].procname = NULL;
87824- }
87825- tbl[0].extra1 = net;
87826+ tbl[0].extra1 = net;
87827+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87828+ } else
87829+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
87830
87831- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87832 if (net->ipv4.route_hdr == NULL)
87833 goto err_reg;
87834 return 0;
87835
87836 err_reg:
87837- if (tbl != ipv4_route_flush_table)
87838- kfree(tbl);
87839+ kfree(tbl);
87840 err_dup:
87841 return -ENOMEM;
87842 }
87843@@ -2608,7 +2608,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
87844
87845 static __net_init int rt_genid_init(struct net *net)
87846 {
87847- atomic_set(&net->rt_genid, 0);
87848+ atomic_set_unchecked(&net->rt_genid, 0);
87849 get_random_bytes(&net->ipv4.dev_addr_genid,
87850 sizeof(net->ipv4.dev_addr_genid));
87851 return 0;
87852diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
87853index fa2f63f..6554815 100644
87854--- a/net/ipv4/sysctl_net_ipv4.c
87855+++ b/net/ipv4/sysctl_net_ipv4.c
87856@@ -55,7 +55,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
87857 {
87858 int ret;
87859 int range[2];
87860- ctl_table tmp = {
87861+ ctl_table_no_const tmp = {
87862 .data = &range,
87863 .maxlen = sizeof(range),
87864 .mode = table->mode,
87865@@ -108,7 +108,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
87866 int ret;
87867 gid_t urange[2];
87868 kgid_t low, high;
87869- ctl_table tmp = {
87870+ ctl_table_no_const tmp = {
87871 .data = &urange,
87872 .maxlen = sizeof(urange),
87873 .mode = table->mode,
87874@@ -139,7 +139,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
87875 void __user *buffer, size_t *lenp, loff_t *ppos)
87876 {
87877 char val[TCP_CA_NAME_MAX];
87878- ctl_table tbl = {
87879+ ctl_table_no_const tbl = {
87880 .data = val,
87881 .maxlen = TCP_CA_NAME_MAX,
87882 };
87883@@ -158,7 +158,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
87884 void __user *buffer, size_t *lenp,
87885 loff_t *ppos)
87886 {
87887- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
87888+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
87889 int ret;
87890
87891 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87892@@ -175,7 +175,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
87893 void __user *buffer, size_t *lenp,
87894 loff_t *ppos)
87895 {
87896- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
87897+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
87898 int ret;
87899
87900 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87901@@ -201,15 +201,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87902 struct mem_cgroup *memcg;
87903 #endif
87904
87905- ctl_table tmp = {
87906+ ctl_table_no_const tmp = {
87907 .data = &vec,
87908 .maxlen = sizeof(vec),
87909 .mode = ctl->mode,
87910 };
87911
87912 if (!write) {
87913- ctl->data = &net->ipv4.sysctl_tcp_mem;
87914- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
87915+ ctl_table_no_const tcp_mem = *ctl;
87916+
87917+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
87918+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
87919 }
87920
87921 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
87922@@ -236,7 +238,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87923 static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
87924 size_t *lenp, loff_t *ppos)
87925 {
87926- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87927+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87928 struct tcp_fastopen_context *ctxt;
87929 int ret;
87930 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
87931@@ -477,7 +479,7 @@ static struct ctl_table ipv4_table[] = {
87932 },
87933 {
87934 .procname = "ip_local_reserved_ports",
87935- .data = NULL, /* initialized in sysctl_ipv4_init */
87936+ .data = sysctl_local_reserved_ports,
87937 .maxlen = 65536,
87938 .mode = 0644,
87939 .proc_handler = proc_do_large_bitmap,
87940@@ -842,11 +844,10 @@ static struct ctl_table ipv4_net_table[] = {
87941
87942 static __net_init int ipv4_sysctl_init_net(struct net *net)
87943 {
87944- struct ctl_table *table;
87945+ ctl_table_no_const *table = NULL;
87946
87947- table = ipv4_net_table;
87948 if (!net_eq(net, &init_net)) {
87949- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
87950+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
87951 if (table == NULL)
87952 goto err_alloc;
87953
87954@@ -881,15 +882,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
87955
87956 tcp_init_mem(net);
87957
87958- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87959+ if (!net_eq(net, &init_net))
87960+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87961+ else
87962+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
87963 if (net->ipv4.ipv4_hdr == NULL)
87964 goto err_reg;
87965
87966 return 0;
87967
87968 err_reg:
87969- if (!net_eq(net, &init_net))
87970- kfree(table);
87971+ kfree(table);
87972 err_alloc:
87973 return -ENOMEM;
87974 }
87975@@ -911,16 +914,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
87976 static __init int sysctl_ipv4_init(void)
87977 {
87978 struct ctl_table_header *hdr;
87979- struct ctl_table *i;
87980-
87981- for (i = ipv4_table; i->procname; i++) {
87982- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
87983- i->data = sysctl_local_reserved_ports;
87984- break;
87985- }
87986- }
87987- if (!i->procname)
87988- return -EINVAL;
87989
87990 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
87991 if (hdr == NULL)
87992diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
87993index 9c62257..651cc27 100644
87994--- a/net/ipv4/tcp_input.c
87995+++ b/net/ipv4/tcp_input.c
87996@@ -4436,7 +4436,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
87997 * simplifies code)
87998 */
87999 static void
88000-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
88001+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
88002 struct sk_buff *head, struct sk_buff *tail,
88003 u32 start, u32 end)
88004 {
88005@@ -5522,6 +5522,7 @@ discard:
88006 tcp_paws_reject(&tp->rx_opt, 0))
88007 goto discard_and_undo;
88008
88009+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
88010 if (th->syn) {
88011 /* We see SYN without ACK. It is attempt of
88012 * simultaneous connect with crossed SYNs.
88013@@ -5572,6 +5573,7 @@ discard:
88014 goto discard;
88015 #endif
88016 }
88017+#endif
88018 /* "fifth, if neither of the SYN or RST bits is set then
88019 * drop the segment and return."
88020 */
88021@@ -5616,7 +5618,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
88022 goto discard;
88023
88024 if (th->syn) {
88025- if (th->fin)
88026+ if (th->fin || th->urg || th->psh)
88027 goto discard;
88028 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
88029 return 1;
88030diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
88031index 7999fc5..c812f42 100644
88032--- a/net/ipv4/tcp_ipv4.c
88033+++ b/net/ipv4/tcp_ipv4.c
88034@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
88035 EXPORT_SYMBOL(sysctl_tcp_low_latency);
88036
88037
88038+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88039+extern int grsec_enable_blackhole;
88040+#endif
88041+
88042 #ifdef CONFIG_TCP_MD5SIG
88043 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
88044 __be32 daddr, __be32 saddr, const struct tcphdr *th);
88045@@ -1855,6 +1859,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
88046 return 0;
88047
88048 reset:
88049+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88050+ if (!grsec_enable_blackhole)
88051+#endif
88052 tcp_v4_send_reset(rsk, skb);
88053 discard:
88054 kfree_skb(skb);
88055@@ -2000,12 +2007,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
88056 TCP_SKB_CB(skb)->sacked = 0;
88057
88058 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88059- if (!sk)
88060+ if (!sk) {
88061+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88062+ ret = 1;
88063+#endif
88064 goto no_tcp_socket;
88065-
88066+ }
88067 process:
88068- if (sk->sk_state == TCP_TIME_WAIT)
88069+ if (sk->sk_state == TCP_TIME_WAIT) {
88070+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88071+ ret = 2;
88072+#endif
88073 goto do_time_wait;
88074+ }
88075
88076 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
88077 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88078@@ -2058,6 +2072,10 @@ csum_error:
88079 bad_packet:
88080 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88081 } else {
88082+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88083+ if (!grsec_enable_blackhole || (ret == 1 &&
88084+ (skb->dev->flags & IFF_LOOPBACK)))
88085+#endif
88086 tcp_v4_send_reset(NULL, skb);
88087 }
88088
88089diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
88090index 0f01788..d52a859 100644
88091--- a/net/ipv4/tcp_minisocks.c
88092+++ b/net/ipv4/tcp_minisocks.c
88093@@ -27,6 +27,10 @@
88094 #include <net/inet_common.h>
88095 #include <net/xfrm.h>
88096
88097+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88098+extern int grsec_enable_blackhole;
88099+#endif
88100+
88101 int sysctl_tcp_syncookies __read_mostly = 1;
88102 EXPORT_SYMBOL(sysctl_tcp_syncookies);
88103
88104@@ -717,7 +721,10 @@ embryonic_reset:
88105 * avoid becoming vulnerable to outside attack aiming at
88106 * resetting legit local connections.
88107 */
88108- req->rsk_ops->send_reset(sk, skb);
88109+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88110+ if (!grsec_enable_blackhole)
88111+#endif
88112+ req->rsk_ops->send_reset(sk, skb);
88113 } else if (fastopen) { /* received a valid RST pkt */
88114 reqsk_fastopen_remove(sk, req, true);
88115 tcp_reset(sk);
88116diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
88117index d4943f6..e7a74a5 100644
88118--- a/net/ipv4/tcp_probe.c
88119+++ b/net/ipv4/tcp_probe.c
88120@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
88121 if (cnt + width >= len)
88122 break;
88123
88124- if (copy_to_user(buf + cnt, tbuf, width))
88125+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
88126 return -EFAULT;
88127 cnt += width;
88128 }
88129diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
88130index 4b85e6f..22f9ac9 100644
88131--- a/net/ipv4/tcp_timer.c
88132+++ b/net/ipv4/tcp_timer.c
88133@@ -22,6 +22,10 @@
88134 #include <linux/gfp.h>
88135 #include <net/tcp.h>
88136
88137+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88138+extern int grsec_lastack_retries;
88139+#endif
88140+
88141 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
88142 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
88143 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
88144@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
88145 }
88146 }
88147
88148+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88149+ if ((sk->sk_state == TCP_LAST_ACK) &&
88150+ (grsec_lastack_retries > 0) &&
88151+ (grsec_lastack_retries < retry_until))
88152+ retry_until = grsec_lastack_retries;
88153+#endif
88154+
88155 if (retransmits_timed_out(sk, retry_until,
88156 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
88157 /* Has it gone just too far? */
88158diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
88159index 0bf5d399..5a2dd92 100644
88160--- a/net/ipv4/udp.c
88161+++ b/net/ipv4/udp.c
88162@@ -87,6 +87,7 @@
88163 #include <linux/types.h>
88164 #include <linux/fcntl.h>
88165 #include <linux/module.h>
88166+#include <linux/security.h>
88167 #include <linux/socket.h>
88168 #include <linux/sockios.h>
88169 #include <linux/igmp.h>
88170@@ -111,6 +112,10 @@
88171 #include <trace/events/skb.h>
88172 #include "udp_impl.h"
88173
88174+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88175+extern int grsec_enable_blackhole;
88176+#endif
88177+
88178 struct udp_table udp_table __read_mostly;
88179 EXPORT_SYMBOL(udp_table);
88180
88181@@ -594,6 +599,9 @@ found:
88182 return s;
88183 }
88184
88185+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
88186+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
88187+
88188 /*
88189 * This routine is called by the ICMP module when it gets some
88190 * sort of error condition. If err < 0 then the socket should
88191@@ -799,7 +807,7 @@ send:
88192 /*
88193 * Push out all pending data as one UDP datagram. Socket is locked.
88194 */
88195-static int udp_push_pending_frames(struct sock *sk)
88196+int udp_push_pending_frames(struct sock *sk)
88197 {
88198 struct udp_sock *up = udp_sk(sk);
88199 struct inet_sock *inet = inet_sk(sk);
88200@@ -818,6 +826,7 @@ out:
88201 up->pending = 0;
88202 return err;
88203 }
88204+EXPORT_SYMBOL(udp_push_pending_frames);
88205
88206 int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
88207 size_t len)
88208@@ -889,9 +898,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
88209 dport = usin->sin_port;
88210 if (dport == 0)
88211 return -EINVAL;
88212+
88213+ err = gr_search_udp_sendmsg(sk, usin);
88214+ if (err)
88215+ return err;
88216 } else {
88217 if (sk->sk_state != TCP_ESTABLISHED)
88218 return -EDESTADDRREQ;
88219+
88220+ err = gr_search_udp_sendmsg(sk, NULL);
88221+ if (err)
88222+ return err;
88223+
88224 daddr = inet->inet_daddr;
88225 dport = inet->inet_dport;
88226 /* Open fast path for connected socket.
88227@@ -1135,7 +1153,7 @@ static unsigned int first_packet_length(struct sock *sk)
88228 IS_UDPLITE(sk));
88229 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88230 IS_UDPLITE(sk));
88231- atomic_inc(&sk->sk_drops);
88232+ atomic_inc_unchecked(&sk->sk_drops);
88233 __skb_unlink(skb, rcvq);
88234 __skb_queue_tail(&list_kill, skb);
88235 }
88236@@ -1221,6 +1239,10 @@ try_again:
88237 if (!skb)
88238 goto out;
88239
88240+ err = gr_search_udp_recvmsg(sk, skb);
88241+ if (err)
88242+ goto out_free;
88243+
88244 ulen = skb->len - sizeof(struct udphdr);
88245 copied = len;
88246 if (copied > ulen)
88247@@ -1254,7 +1276,7 @@ try_again:
88248 if (unlikely(err)) {
88249 trace_kfree_skb(skb, udp_recvmsg);
88250 if (!peeked) {
88251- atomic_inc(&sk->sk_drops);
88252+ atomic_inc_unchecked(&sk->sk_drops);
88253 UDP_INC_STATS_USER(sock_net(sk),
88254 UDP_MIB_INERRORS, is_udplite);
88255 }
88256@@ -1541,7 +1563,7 @@ csum_error:
88257 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
88258 drop:
88259 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88260- atomic_inc(&sk->sk_drops);
88261+ atomic_inc_unchecked(&sk->sk_drops);
88262 kfree_skb(skb);
88263 return -1;
88264 }
88265@@ -1560,7 +1582,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88266 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88267
88268 if (!skb1) {
88269- atomic_inc(&sk->sk_drops);
88270+ atomic_inc_unchecked(&sk->sk_drops);
88271 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88272 IS_UDPLITE(sk));
88273 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88274@@ -1729,6 +1751,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88275 goto csum_error;
88276
88277 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88278+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88279+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88280+#endif
88281 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
88282
88283 /*
88284@@ -2159,7 +2184,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
88285 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
88286 0, sock_i_ino(sp),
88287 atomic_read(&sp->sk_refcnt), sp,
88288- atomic_read(&sp->sk_drops), len);
88289+ atomic_read_unchecked(&sp->sk_drops), len);
88290 }
88291
88292 int udp4_seq_show(struct seq_file *seq, void *v)
88293diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
88294index 9a459be..086b866 100644
88295--- a/net/ipv4/xfrm4_policy.c
88296+++ b/net/ipv4/xfrm4_policy.c
88297@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
88298
88299 static int __net_init xfrm4_net_init(struct net *net)
88300 {
88301- struct ctl_table *table;
88302+ ctl_table_no_const *table = NULL;
88303 struct ctl_table_header *hdr;
88304
88305- table = xfrm4_policy_table;
88306 if (!net_eq(net, &init_net)) {
88307- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
88308+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
88309 if (!table)
88310 goto err_alloc;
88311
88312 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
88313- }
88314-
88315- hdr = register_net_sysctl(net, "net/ipv4", table);
88316+ hdr = register_net_sysctl(net, "net/ipv4", table);
88317+ } else
88318+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
88319 if (!hdr)
88320 goto err_reg;
88321
88322@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
88323 return 0;
88324
88325 err_reg:
88326- if (!net_eq(net, &init_net))
88327- kfree(table);
88328+ kfree(table);
88329 err_alloc:
88330 return -ENOMEM;
88331 }
88332diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
88333index 4ab4c38..1533b2d 100644
88334--- a/net/ipv6/addrconf.c
88335+++ b/net/ipv6/addrconf.c
88336@@ -621,7 +621,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
88337 idx = 0;
88338 head = &net->dev_index_head[h];
88339 rcu_read_lock();
88340- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
88341+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
88342 net->dev_base_seq;
88343 hlist_for_each_entry_rcu(dev, head, index_hlist) {
88344 if (idx < s_idx)
88345@@ -2372,7 +2372,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
88346 p.iph.ihl = 5;
88347 p.iph.protocol = IPPROTO_IPV6;
88348 p.iph.ttl = 64;
88349- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
88350+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
88351
88352 if (ops->ndo_do_ioctl) {
88353 mm_segment_t oldfs = get_fs();
88354@@ -3994,7 +3994,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
88355 s_ip_idx = ip_idx = cb->args[2];
88356
88357 rcu_read_lock();
88358- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
88359+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
88360 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
88361 idx = 0;
88362 head = &net->dev_index_head[h];
88363@@ -4579,7 +4579,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
88364 dst_free(&ifp->rt->dst);
88365 break;
88366 }
88367- atomic_inc(&net->ipv6.dev_addr_genid);
88368+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
88369 }
88370
88371 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
88372@@ -4599,7 +4599,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
88373 int *valp = ctl->data;
88374 int val = *valp;
88375 loff_t pos = *ppos;
88376- ctl_table lctl;
88377+ ctl_table_no_const lctl;
88378 int ret;
88379
88380 /*
88381@@ -4681,7 +4681,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
88382 int *valp = ctl->data;
88383 int val = *valp;
88384 loff_t pos = *ppos;
88385- ctl_table lctl;
88386+ ctl_table_no_const lctl;
88387 int ret;
88388
88389 /*
88390diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
88391index b4ff0a4..db9b764 100644
88392--- a/net/ipv6/icmp.c
88393+++ b/net/ipv6/icmp.c
88394@@ -980,7 +980,7 @@ ctl_table ipv6_icmp_table_template[] = {
88395
88396 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
88397 {
88398- struct ctl_table *table;
88399+ ctl_table_no_const *table;
88400
88401 table = kmemdup(ipv6_icmp_table_template,
88402 sizeof(ipv6_icmp_table_template),
88403diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
88404index 192dd1a..5fc9c7a 100644
88405--- a/net/ipv6/ip6_fib.c
88406+++ b/net/ipv6/ip6_fib.c
88407@@ -632,6 +632,12 @@ insert_above:
88408 return ln;
88409 }
88410
88411+static inline bool rt6_qualify_for_ecmp(struct rt6_info *rt)
88412+{
88413+ return (rt->rt6i_flags & (RTF_GATEWAY|RTF_ADDRCONF|RTF_DYNAMIC)) ==
88414+ RTF_GATEWAY;
88415+}
88416+
88417 /*
88418 * Insert routing information in a node.
88419 */
88420@@ -646,6 +652,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
88421 int add = (!info->nlh ||
88422 (info->nlh->nlmsg_flags & NLM_F_CREATE));
88423 int found = 0;
88424+ bool rt_can_ecmp = rt6_qualify_for_ecmp(rt);
88425
88426 ins = &fn->leaf;
88427
88428@@ -691,9 +698,8 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
88429 * To avoid long list, we only had siblings if the
88430 * route have a gateway.
88431 */
88432- if (rt->rt6i_flags & RTF_GATEWAY &&
88433- !(rt->rt6i_flags & RTF_EXPIRES) &&
88434- !(iter->rt6i_flags & RTF_EXPIRES))
88435+ if (rt_can_ecmp &&
88436+ rt6_qualify_for_ecmp(iter))
88437 rt->rt6i_nsiblings++;
88438 }
88439
88440@@ -715,7 +721,8 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
88441 /* Find the first route that have the same metric */
88442 sibling = fn->leaf;
88443 while (sibling) {
88444- if (sibling->rt6i_metric == rt->rt6i_metric) {
88445+ if (sibling->rt6i_metric == rt->rt6i_metric &&
88446+ rt6_qualify_for_ecmp(sibling)) {
88447 list_add_tail(&rt->rt6i_siblings,
88448 &sibling->rt6i_siblings);
88449 break;
88450diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
88451index ecd6073..58162ae 100644
88452--- a/net/ipv6/ip6_gre.c
88453+++ b/net/ipv6/ip6_gre.c
88454@@ -74,7 +74,7 @@ struct ip6gre_net {
88455 struct net_device *fb_tunnel_dev;
88456 };
88457
88458-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
88459+static struct rtnl_link_ops ip6gre_link_ops;
88460 static int ip6gre_tunnel_init(struct net_device *dev);
88461 static void ip6gre_tunnel_setup(struct net_device *dev);
88462 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
88463@@ -1283,7 +1283,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
88464 }
88465
88466
88467-static struct inet6_protocol ip6gre_protocol __read_mostly = {
88468+static struct inet6_protocol ip6gre_protocol = {
88469 .handler = ip6gre_rcv,
88470 .err_handler = ip6gre_err,
88471 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
88472@@ -1617,7 +1617,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
88473 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
88474 };
88475
88476-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
88477+static struct rtnl_link_ops ip6gre_link_ops = {
88478 .kind = "ip6gre",
88479 .maxtype = IFLA_GRE_MAX,
88480 .policy = ip6gre_policy,
88481@@ -1630,7 +1630,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
88482 .fill_info = ip6gre_fill_info,
88483 };
88484
88485-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
88486+static struct rtnl_link_ops ip6gre_tap_ops = {
88487 .kind = "ip6gretap",
88488 .maxtype = IFLA_GRE_MAX,
88489 .policy = ip6gre_policy,
88490diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
88491index d5d20cd..6e3ddf8 100644
88492--- a/net/ipv6/ip6_output.c
88493+++ b/net/ipv6/ip6_output.c
88494@@ -1098,11 +1098,12 @@ static inline struct ipv6_rt_hdr *ip6_rthdr_dup(struct ipv6_rt_hdr *src,
88495 return src ? kmemdup(src, (src->hdrlen + 1) * 8, gfp) : NULL;
88496 }
88497
88498-static void ip6_append_data_mtu(int *mtu,
88499+static void ip6_append_data_mtu(unsigned int *mtu,
88500 int *maxfraglen,
88501 unsigned int fragheaderlen,
88502 struct sk_buff *skb,
88503- struct rt6_info *rt)
88504+ struct rt6_info *rt,
88505+ bool pmtuprobe)
88506 {
88507 if (!(rt->dst.flags & DST_XFRM_TUNNEL)) {
88508 if (skb == NULL) {
88509@@ -1114,7 +1115,9 @@ static void ip6_append_data_mtu(int *mtu,
88510 * this fragment is not first, the headers
88511 * space is regarded as data space.
88512 */
88513- *mtu = dst_mtu(rt->dst.path);
88514+ *mtu = min(*mtu, pmtuprobe ?
88515+ rt->dst.dev->mtu :
88516+ dst_mtu(rt->dst.path));
88517 }
88518 *maxfraglen = ((*mtu - fragheaderlen) & ~7)
88519 + fragheaderlen - sizeof(struct frag_hdr);
88520@@ -1131,11 +1134,10 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
88521 struct ipv6_pinfo *np = inet6_sk(sk);
88522 struct inet_cork *cork;
88523 struct sk_buff *skb, *skb_prev = NULL;
88524- unsigned int maxfraglen, fragheaderlen;
88525+ unsigned int maxfraglen, fragheaderlen, mtu;
88526 int exthdrlen;
88527 int dst_exthdrlen;
88528 int hh_len;
88529- int mtu;
88530 int copy;
88531 int err;
88532 int offset = 0;
88533@@ -1292,7 +1294,9 @@ alloc_new_skb:
88534 /* update mtu and maxfraglen if necessary */
88535 if (skb == NULL || skb_prev == NULL)
88536 ip6_append_data_mtu(&mtu, &maxfraglen,
88537- fragheaderlen, skb, rt);
88538+ fragheaderlen, skb, rt,
88539+ np->pmtudisc ==
88540+ IPV6_PMTUDISC_PROBE);
88541
88542 skb_prev = skb;
88543
88544diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
88545index 1e55866..b398dab 100644
88546--- a/net/ipv6/ip6_tunnel.c
88547+++ b/net/ipv6/ip6_tunnel.c
88548@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
88549
88550 static int ip6_tnl_dev_init(struct net_device *dev);
88551 static void ip6_tnl_dev_setup(struct net_device *dev);
88552-static struct rtnl_link_ops ip6_link_ops __read_mostly;
88553+static struct rtnl_link_ops ip6_link_ops;
88554
88555 static int ip6_tnl_net_id __read_mostly;
88556 struct ip6_tnl_net {
88557@@ -1672,7 +1672,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
88558 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
88559 };
88560
88561-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
88562+static struct rtnl_link_ops ip6_link_ops = {
88563 .kind = "ip6tnl",
88564 .maxtype = IFLA_IPTUN_MAX,
88565 .policy = ip6_tnl_policy,
88566diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
88567index d1e2e8e..51c19ae 100644
88568--- a/net/ipv6/ipv6_sockglue.c
88569+++ b/net/ipv6/ipv6_sockglue.c
88570@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
88571 if (sk->sk_type != SOCK_STREAM)
88572 return -ENOPROTOOPT;
88573
88574- msg.msg_control = optval;
88575+ msg.msg_control = (void __force_kernel *)optval;
88576 msg.msg_controllen = len;
88577 msg.msg_flags = flags;
88578
88579diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
88580index 44400c2..8e11f52 100644
88581--- a/net/ipv6/netfilter/ip6_tables.c
88582+++ b/net/ipv6/netfilter/ip6_tables.c
88583@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
88584 #endif
88585
88586 static int get_info(struct net *net, void __user *user,
88587- const int *len, int compat)
88588+ int len, int compat)
88589 {
88590 char name[XT_TABLE_MAXNAMELEN];
88591 struct xt_table *t;
88592 int ret;
88593
88594- if (*len != sizeof(struct ip6t_getinfo)) {
88595- duprintf("length %u != %zu\n", *len,
88596+ if (len != sizeof(struct ip6t_getinfo)) {
88597+ duprintf("length %u != %zu\n", len,
88598 sizeof(struct ip6t_getinfo));
88599 return -EINVAL;
88600 }
88601@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
88602 info.size = private->size;
88603 strcpy(info.name, name);
88604
88605- if (copy_to_user(user, &info, *len) != 0)
88606+ if (copy_to_user(user, &info, len) != 0)
88607 ret = -EFAULT;
88608 else
88609 ret = 0;
88610@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88611
88612 switch (cmd) {
88613 case IP6T_SO_GET_INFO:
88614- ret = get_info(sock_net(sk), user, len, 1);
88615+ ret = get_info(sock_net(sk), user, *len, 1);
88616 break;
88617 case IP6T_SO_GET_ENTRIES:
88618 ret = compat_get_entries(sock_net(sk), user, len);
88619@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88620
88621 switch (cmd) {
88622 case IP6T_SO_GET_INFO:
88623- ret = get_info(sock_net(sk), user, len, 0);
88624+ ret = get_info(sock_net(sk), user, *len, 0);
88625 break;
88626
88627 case IP6T_SO_GET_ENTRIES:
88628diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
88629index dffdc1a..ccc6678 100644
88630--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
88631+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
88632@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
88633
88634 static int nf_ct_frag6_sysctl_register(struct net *net)
88635 {
88636- struct ctl_table *table;
88637+ ctl_table_no_const *table = NULL;
88638 struct ctl_table_header *hdr;
88639
88640- table = nf_ct_frag6_sysctl_table;
88641 if (!net_eq(net, &init_net)) {
88642- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
88643+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
88644 GFP_KERNEL);
88645 if (table == NULL)
88646 goto err_alloc;
88647@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88648 table[0].data = &net->nf_frag.frags.timeout;
88649 table[1].data = &net->nf_frag.frags.low_thresh;
88650 table[2].data = &net->nf_frag.frags.high_thresh;
88651- }
88652-
88653- hdr = register_net_sysctl(net, "net/netfilter", table);
88654+ hdr = register_net_sysctl(net, "net/netfilter", table);
88655+ } else
88656+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
88657 if (hdr == NULL)
88658 goto err_reg;
88659
88660@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88661 return 0;
88662
88663 err_reg:
88664- if (!net_eq(net, &init_net))
88665- kfree(table);
88666+ kfree(table);
88667 err_alloc:
88668 return -ENOMEM;
88669 }
88670diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
88671index eedff8c..6e13a47 100644
88672--- a/net/ipv6/raw.c
88673+++ b/net/ipv6/raw.c
88674@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
88675 {
88676 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
88677 skb_checksum_complete(skb)) {
88678- atomic_inc(&sk->sk_drops);
88679+ atomic_inc_unchecked(&sk->sk_drops);
88680 kfree_skb(skb);
88681 return NET_RX_DROP;
88682 }
88683@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88684 struct raw6_sock *rp = raw6_sk(sk);
88685
88686 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
88687- atomic_inc(&sk->sk_drops);
88688+ atomic_inc_unchecked(&sk->sk_drops);
88689 kfree_skb(skb);
88690 return NET_RX_DROP;
88691 }
88692@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88693
88694 if (inet->hdrincl) {
88695 if (skb_checksum_complete(skb)) {
88696- atomic_inc(&sk->sk_drops);
88697+ atomic_inc_unchecked(&sk->sk_drops);
88698 kfree_skb(skb);
88699 return NET_RX_DROP;
88700 }
88701@@ -602,7 +602,7 @@ out:
88702 return err;
88703 }
88704
88705-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
88706+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
88707 struct flowi6 *fl6, struct dst_entry **dstp,
88708 unsigned int flags)
88709 {
88710@@ -914,12 +914,15 @@ do_confirm:
88711 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
88712 char __user *optval, int optlen)
88713 {
88714+ struct icmp6_filter filter;
88715+
88716 switch (optname) {
88717 case ICMPV6_FILTER:
88718 if (optlen > sizeof(struct icmp6_filter))
88719 optlen = sizeof(struct icmp6_filter);
88720- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
88721+ if (copy_from_user(&filter, optval, optlen))
88722 return -EFAULT;
88723+ raw6_sk(sk)->filter = filter;
88724 return 0;
88725 default:
88726 return -ENOPROTOOPT;
88727@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88728 char __user *optval, int __user *optlen)
88729 {
88730 int len;
88731+ struct icmp6_filter filter;
88732
88733 switch (optname) {
88734 case ICMPV6_FILTER:
88735@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88736 len = sizeof(struct icmp6_filter);
88737 if (put_user(len, optlen))
88738 return -EFAULT;
88739- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
88740+ filter = raw6_sk(sk)->filter;
88741+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
88742 return -EFAULT;
88743 return 0;
88744 default:
88745@@ -1251,7 +1256,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
88746 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
88747 0,
88748 sock_i_ino(sp),
88749- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
88750+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
88751 }
88752
88753 static int raw6_seq_show(struct seq_file *seq, void *v)
88754diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
88755index 790d9f4..68ae078 100644
88756--- a/net/ipv6/reassembly.c
88757+++ b/net/ipv6/reassembly.c
88758@@ -621,12 +621,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
88759
88760 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88761 {
88762- struct ctl_table *table;
88763+ ctl_table_no_const *table = NULL;
88764 struct ctl_table_header *hdr;
88765
88766- table = ip6_frags_ns_ctl_table;
88767 if (!net_eq(net, &init_net)) {
88768- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88769+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88770 if (table == NULL)
88771 goto err_alloc;
88772
88773@@ -637,9 +636,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88774 /* Don't export sysctls to unprivileged users */
88775 if (net->user_ns != &init_user_ns)
88776 table[0].procname = NULL;
88777- }
88778+ hdr = register_net_sysctl(net, "net/ipv6", table);
88779+ } else
88780+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
88781
88782- hdr = register_net_sysctl(net, "net/ipv6", table);
88783 if (hdr == NULL)
88784 goto err_reg;
88785
88786@@ -647,8 +647,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88787 return 0;
88788
88789 err_reg:
88790- if (!net_eq(net, &init_net))
88791- kfree(table);
88792+ kfree(table);
88793 err_alloc:
88794 return -ENOMEM;
88795 }
88796diff --git a/net/ipv6/route.c b/net/ipv6/route.c
88797index ad0aa6b..beaef03 100644
88798--- a/net/ipv6/route.c
88799+++ b/net/ipv6/route.c
88800@@ -2881,7 +2881,7 @@ ctl_table ipv6_route_table_template[] = {
88801
88802 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
88803 {
88804- struct ctl_table *table;
88805+ ctl_table_no_const *table;
88806
88807 table = kmemdup(ipv6_route_table_template,
88808 sizeof(ipv6_route_table_template),
88809diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
88810index 3353634..3d5084a 100644
88811--- a/net/ipv6/sit.c
88812+++ b/net/ipv6/sit.c
88813@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
88814 static void ipip6_dev_free(struct net_device *dev);
88815 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
88816 __be32 *v4dst);
88817-static struct rtnl_link_ops sit_link_ops __read_mostly;
88818+static struct rtnl_link_ops sit_link_ops;
88819
88820 static int sit_net_id __read_mostly;
88821 struct sit_net {
88822@@ -1453,7 +1453,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
88823 #endif
88824 };
88825
88826-static struct rtnl_link_ops sit_link_ops __read_mostly = {
88827+static struct rtnl_link_ops sit_link_ops = {
88828 .kind = "sit",
88829 .maxtype = IFLA_IPTUN_MAX,
88830 .policy = ipip6_policy,
88831diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
88832index e85c48b..b8268d3 100644
88833--- a/net/ipv6/sysctl_net_ipv6.c
88834+++ b/net/ipv6/sysctl_net_ipv6.c
88835@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
88836
88837 static int __net_init ipv6_sysctl_net_init(struct net *net)
88838 {
88839- struct ctl_table *ipv6_table;
88840+ ctl_table_no_const *ipv6_table;
88841 struct ctl_table *ipv6_route_table;
88842 struct ctl_table *ipv6_icmp_table;
88843 int err;
88844diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
88845index 0a17ed9..2526cc3 100644
88846--- a/net/ipv6/tcp_ipv6.c
88847+++ b/net/ipv6/tcp_ipv6.c
88848@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
88849 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
88850 }
88851
88852+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88853+extern int grsec_enable_blackhole;
88854+#endif
88855+
88856 static void tcp_v6_hash(struct sock *sk)
88857 {
88858 if (sk->sk_state != TCP_CLOSE) {
88859@@ -1398,6 +1402,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
88860 return 0;
88861
88862 reset:
88863+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88864+ if (!grsec_enable_blackhole)
88865+#endif
88866 tcp_v6_send_reset(sk, skb);
88867 discard:
88868 if (opt_skb)
88869@@ -1480,12 +1487,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
88870 TCP_SKB_CB(skb)->sacked = 0;
88871
88872 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88873- if (!sk)
88874+ if (!sk) {
88875+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88876+ ret = 1;
88877+#endif
88878 goto no_tcp_socket;
88879+ }
88880
88881 process:
88882- if (sk->sk_state == TCP_TIME_WAIT)
88883+ if (sk->sk_state == TCP_TIME_WAIT) {
88884+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88885+ ret = 2;
88886+#endif
88887 goto do_time_wait;
88888+ }
88889
88890 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
88891 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88892@@ -1536,6 +1551,10 @@ csum_error:
88893 bad_packet:
88894 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88895 } else {
88896+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88897+ if (!grsec_enable_blackhole || (ret == 1 &&
88898+ (skb->dev->flags & IFF_LOOPBACK)))
88899+#endif
88900 tcp_v6_send_reset(NULL, skb);
88901 }
88902
88903diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
88904index 42923b1..d09c290 100644
88905--- a/net/ipv6/udp.c
88906+++ b/net/ipv6/udp.c
88907@@ -52,6 +52,10 @@
88908 #include <trace/events/skb.h>
88909 #include "udp_impl.h"
88910
88911+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88912+extern int grsec_enable_blackhole;
88913+#endif
88914+
88915 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
88916 {
88917 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
88918@@ -419,7 +423,7 @@ try_again:
88919 if (unlikely(err)) {
88920 trace_kfree_skb(skb, udpv6_recvmsg);
88921 if (!peeked) {
88922- atomic_inc(&sk->sk_drops);
88923+ atomic_inc_unchecked(&sk->sk_drops);
88924 if (is_udp4)
88925 UDP_INC_STATS_USER(sock_net(sk),
88926 UDP_MIB_INERRORS,
88927@@ -665,7 +669,7 @@ csum_error:
88928 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
88929 drop:
88930 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88931- atomic_inc(&sk->sk_drops);
88932+ atomic_inc_unchecked(&sk->sk_drops);
88933 kfree_skb(skb);
88934 return -1;
88935 }
88936@@ -723,7 +727,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88937 if (likely(skb1 == NULL))
88938 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88939 if (!skb1) {
88940- atomic_inc(&sk->sk_drops);
88941+ atomic_inc_unchecked(&sk->sk_drops);
88942 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88943 IS_UDPLITE(sk));
88944 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88945@@ -860,6 +864,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88946 goto csum_error;
88947
88948 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88949+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88950+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88951+#endif
88952 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
88953
88954 kfree_skb(skb);
88955@@ -955,11 +962,16 @@ static int udp_v6_push_pending_frames(struct sock *sk)
88956 struct udphdr *uh;
88957 struct udp_sock *up = udp_sk(sk);
88958 struct inet_sock *inet = inet_sk(sk);
88959- struct flowi6 *fl6 = &inet->cork.fl.u.ip6;
88960+ struct flowi6 *fl6;
88961 int err = 0;
88962 int is_udplite = IS_UDPLITE(sk);
88963 __wsum csum = 0;
88964
88965+ if (up->pending == AF_INET)
88966+ return udp_push_pending_frames(sk);
88967+
88968+ fl6 = &inet->cork.fl.u.ip6;
88969+
88970 /* Grab the skbuff where UDP header space exists. */
88971 if ((skb = skb_peek(&sk->sk_write_queue)) == NULL)
88972 goto out;
88973@@ -1387,7 +1399,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
88974 0,
88975 sock_i_ino(sp),
88976 atomic_read(&sp->sk_refcnt), sp,
88977- atomic_read(&sp->sk_drops));
88978+ atomic_read_unchecked(&sp->sk_drops));
88979 }
88980
88981 int udp6_seq_show(struct seq_file *seq, void *v)
88982diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
88983index 23ed03d..465a71d 100644
88984--- a/net/ipv6/xfrm6_policy.c
88985+++ b/net/ipv6/xfrm6_policy.c
88986@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
88987
88988 static int __net_init xfrm6_net_init(struct net *net)
88989 {
88990- struct ctl_table *table;
88991+ ctl_table_no_const *table = NULL;
88992 struct ctl_table_header *hdr;
88993
88994- table = xfrm6_policy_table;
88995 if (!net_eq(net, &init_net)) {
88996- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
88997+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
88998 if (!table)
88999 goto err_alloc;
89000
89001 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
89002- }
89003+ hdr = register_net_sysctl(net, "net/ipv6", table);
89004+ } else
89005+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
89006
89007- hdr = register_net_sysctl(net, "net/ipv6", table);
89008 if (!hdr)
89009 goto err_reg;
89010
89011@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
89012 return 0;
89013
89014 err_reg:
89015- if (!net_eq(net, &init_net))
89016- kfree(table);
89017+ kfree(table);
89018 err_alloc:
89019 return -ENOMEM;
89020 }
89021diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
89022index 41ac7938..75e3bb1 100644
89023--- a/net/irda/ircomm/ircomm_tty.c
89024+++ b/net/irda/ircomm/ircomm_tty.c
89025@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
89026 add_wait_queue(&port->open_wait, &wait);
89027
89028 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
89029- __FILE__, __LINE__, tty->driver->name, port->count);
89030+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
89031
89032 spin_lock_irqsave(&port->lock, flags);
89033 if (!tty_hung_up_p(filp))
89034- port->count--;
89035+ atomic_dec(&port->count);
89036 port->blocked_open++;
89037 spin_unlock_irqrestore(&port->lock, flags);
89038
89039@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
89040 }
89041
89042 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
89043- __FILE__, __LINE__, tty->driver->name, port->count);
89044+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
89045
89046 schedule();
89047 }
89048@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
89049
89050 spin_lock_irqsave(&port->lock, flags);
89051 if (!tty_hung_up_p(filp))
89052- port->count++;
89053+ atomic_inc(&port->count);
89054 port->blocked_open--;
89055 spin_unlock_irqrestore(&port->lock, flags);
89056
89057 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
89058- __FILE__, __LINE__, tty->driver->name, port->count);
89059+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
89060
89061 if (!retval)
89062 port->flags |= ASYNC_NORMAL_ACTIVE;
89063@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
89064
89065 /* ++ is not atomic, so this should be protected - Jean II */
89066 spin_lock_irqsave(&self->port.lock, flags);
89067- self->port.count++;
89068+ atomic_inc(&self->port.count);
89069 spin_unlock_irqrestore(&self->port.lock, flags);
89070 tty_port_tty_set(&self->port, tty);
89071
89072 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
89073- self->line, self->port.count);
89074+ self->line, atomic_read(&self->port.count));
89075
89076 /* Not really used by us, but lets do it anyway */
89077 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
89078@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
89079 tty_kref_put(port->tty);
89080 }
89081 port->tty = NULL;
89082- port->count = 0;
89083+ atomic_set(&port->count, 0);
89084 spin_unlock_irqrestore(&port->lock, flags);
89085
89086 wake_up_interruptible(&port->open_wait);
89087@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
89088 seq_putc(m, '\n');
89089
89090 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
89091- seq_printf(m, "Open count: %d\n", self->port.count);
89092+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
89093 seq_printf(m, "Max data size: %d\n", self->max_data_size);
89094 seq_printf(m, "Max header size: %d\n", self->max_header_size);
89095
89096diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
89097index ae69165..c8b82d8 100644
89098--- a/net/iucv/af_iucv.c
89099+++ b/net/iucv/af_iucv.c
89100@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
89101
89102 write_lock_bh(&iucv_sk_list.lock);
89103
89104- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
89105+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
89106 while (__iucv_get_sock_by_name(name)) {
89107 sprintf(name, "%08x",
89108- atomic_inc_return(&iucv_sk_list.autobind_name));
89109+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
89110 }
89111
89112 write_unlock_bh(&iucv_sk_list.lock);
89113diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
89114index 4fe76ff..426a904 100644
89115--- a/net/iucv/iucv.c
89116+++ b/net/iucv/iucv.c
89117@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
89118 return NOTIFY_OK;
89119 }
89120
89121-static struct notifier_block __refdata iucv_cpu_notifier = {
89122+static struct notifier_block iucv_cpu_notifier = {
89123 .notifier_call = iucv_cpu_notify,
89124 };
89125
89126diff --git a/net/key/af_key.c b/net/key/af_key.c
89127index 9da8620..97070ad 100644
89128--- a/net/key/af_key.c
89129+++ b/net/key/af_key.c
89130@@ -3047,10 +3047,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
89131 static u32 get_acqseq(void)
89132 {
89133 u32 res;
89134- static atomic_t acqseq;
89135+ static atomic_unchecked_t acqseq;
89136
89137 do {
89138- res = atomic_inc_return(&acqseq);
89139+ res = atomic_inc_return_unchecked(&acqseq);
89140 } while (!res);
89141 return res;
89142 }
89143diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
89144index 8dec687..5ebee2d 100644
89145--- a/net/l2tp/l2tp_ppp.c
89146+++ b/net/l2tp/l2tp_ppp.c
89147@@ -1793,7 +1793,8 @@ static const struct proto_ops pppol2tp_ops = {
89148
89149 static const struct pppox_proto pppol2tp_proto = {
89150 .create = pppol2tp_create,
89151- .ioctl = pppol2tp_ioctl
89152+ .ioctl = pppol2tp_ioctl,
89153+ .owner = THIS_MODULE,
89154 };
89155
89156 #ifdef CONFIG_L2TP_V3
89157diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
89158index 4fdb306e..920086a 100644
89159--- a/net/mac80211/cfg.c
89160+++ b/net/mac80211/cfg.c
89161@@ -804,7 +804,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
89162 ret = ieee80211_vif_use_channel(sdata, chandef,
89163 IEEE80211_CHANCTX_EXCLUSIVE);
89164 }
89165- } else if (local->open_count == local->monitors) {
89166+ } else if (local_read(&local->open_count) == local->monitors) {
89167 local->_oper_chandef = *chandef;
89168 ieee80211_hw_config(local, 0);
89169 }
89170@@ -2920,7 +2920,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
89171 else
89172 local->probe_req_reg--;
89173
89174- if (!local->open_count)
89175+ if (!local_read(&local->open_count))
89176 break;
89177
89178 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
89179@@ -3383,8 +3383,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
89180 if (chanctx_conf) {
89181 *chandef = chanctx_conf->def;
89182 ret = 0;
89183- } else if (local->open_count > 0 &&
89184- local->open_count == local->monitors &&
89185+ } else if (local_read(&local->open_count) > 0 &&
89186+ local_read(&local->open_count) == local->monitors &&
89187 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
89188 if (local->use_chanctx)
89189 *chandef = local->monitor_chandef;
89190diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
89191index 9ca8e32..48e4a9b 100644
89192--- a/net/mac80211/ieee80211_i.h
89193+++ b/net/mac80211/ieee80211_i.h
89194@@ -28,6 +28,7 @@
89195 #include <net/ieee80211_radiotap.h>
89196 #include <net/cfg80211.h>
89197 #include <net/mac80211.h>
89198+#include <asm/local.h>
89199 #include "key.h"
89200 #include "sta_info.h"
89201 #include "debug.h"
89202@@ -891,7 +892,7 @@ struct ieee80211_local {
89203 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
89204 spinlock_t queue_stop_reason_lock;
89205
89206- int open_count;
89207+ local_t open_count;
89208 int monitors, cooked_mntrs;
89209 /* number of interfaces with corresponding FIF_ flags */
89210 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
89211diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
89212index 98d20c0..586675b 100644
89213--- a/net/mac80211/iface.c
89214+++ b/net/mac80211/iface.c
89215@@ -502,7 +502,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89216 break;
89217 }
89218
89219- if (local->open_count == 0) {
89220+ if (local_read(&local->open_count) == 0) {
89221 res = drv_start(local);
89222 if (res)
89223 goto err_del_bss;
89224@@ -545,7 +545,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89225 break;
89226 }
89227
89228- if (local->monitors == 0 && local->open_count == 0) {
89229+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
89230 res = ieee80211_add_virtual_monitor(local);
89231 if (res)
89232 goto err_stop;
89233@@ -653,7 +653,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89234 atomic_inc(&local->iff_promiscs);
89235
89236 if (coming_up)
89237- local->open_count++;
89238+ local_inc(&local->open_count);
89239
89240 if (hw_reconf_flags)
89241 ieee80211_hw_config(local, hw_reconf_flags);
89242@@ -691,7 +691,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89243 err_del_interface:
89244 drv_remove_interface(local, sdata);
89245 err_stop:
89246- if (!local->open_count)
89247+ if (!local_read(&local->open_count))
89248 drv_stop(local);
89249 err_del_bss:
89250 sdata->bss = NULL;
89251@@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89252 }
89253
89254 if (going_down)
89255- local->open_count--;
89256+ local_dec(&local->open_count);
89257
89258 switch (sdata->vif.type) {
89259 case NL80211_IFTYPE_AP_VLAN:
89260@@ -895,7 +895,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89261 }
89262 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
89263
89264- if (local->open_count == 0)
89265+ if (local_read(&local->open_count) == 0)
89266 ieee80211_clear_tx_pending(local);
89267
89268 /*
89269@@ -931,7 +931,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89270
89271 ieee80211_recalc_ps(local, -1);
89272
89273- if (local->open_count == 0) {
89274+ if (local_read(&local->open_count) == 0) {
89275 ieee80211_stop_device(local);
89276
89277 /* no reconfiguring after stop! */
89278@@ -942,7 +942,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89279 ieee80211_configure_filter(local);
89280 ieee80211_hw_config(local, hw_reconf_flags);
89281
89282- if (local->monitors == local->open_count)
89283+ if (local->monitors == local_read(&local->open_count))
89284 ieee80211_add_virtual_monitor(local);
89285 }
89286
89287diff --git a/net/mac80211/main.c b/net/mac80211/main.c
89288index 8a7bfc4..4407cd0 100644
89289--- a/net/mac80211/main.c
89290+++ b/net/mac80211/main.c
89291@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
89292 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
89293 IEEE80211_CONF_CHANGE_POWER);
89294
89295- if (changed && local->open_count) {
89296+ if (changed && local_read(&local->open_count)) {
89297 ret = drv_config(local, changed);
89298 /*
89299 * Goal:
89300diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
89301index 7fc5d0d..07ea536 100644
89302--- a/net/mac80211/pm.c
89303+++ b/net/mac80211/pm.c
89304@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89305 struct ieee80211_sub_if_data *sdata;
89306 struct sta_info *sta;
89307
89308- if (!local->open_count)
89309+ if (!local_read(&local->open_count))
89310 goto suspend;
89311
89312 ieee80211_scan_cancel(local);
89313@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89314 cancel_work_sync(&local->dynamic_ps_enable_work);
89315 del_timer_sync(&local->dynamic_ps_timer);
89316
89317- local->wowlan = wowlan && local->open_count;
89318+ local->wowlan = wowlan && local_read(&local->open_count);
89319 if (local->wowlan) {
89320 int err = drv_suspend(local, wowlan);
89321 if (err < 0) {
89322@@ -113,7 +113,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89323 WARN_ON(!list_empty(&local->chanctx_list));
89324
89325 /* stop hardware - this must stop RX */
89326- if (local->open_count)
89327+ if (local_read(&local->open_count))
89328 ieee80211_stop_device(local);
89329
89330 suspend:
89331diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
89332index a02bef3..f2f38dd 100644
89333--- a/net/mac80211/rate.c
89334+++ b/net/mac80211/rate.c
89335@@ -712,7 +712,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
89336
89337 ASSERT_RTNL();
89338
89339- if (local->open_count)
89340+ if (local_read(&local->open_count))
89341 return -EBUSY;
89342
89343 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
89344diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
89345index c97a065..ff61928 100644
89346--- a/net/mac80211/rc80211_pid_debugfs.c
89347+++ b/net/mac80211/rc80211_pid_debugfs.c
89348@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
89349
89350 spin_unlock_irqrestore(&events->lock, status);
89351
89352- if (copy_to_user(buf, pb, p))
89353+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
89354 return -EFAULT;
89355
89356 return p;
89357diff --git a/net/mac80211/util.c b/net/mac80211/util.c
89358index 72e6292..e6319eb 100644
89359--- a/net/mac80211/util.c
89360+++ b/net/mac80211/util.c
89361@@ -1472,7 +1472,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
89362 }
89363 #endif
89364 /* everything else happens only if HW was up & running */
89365- if (!local->open_count)
89366+ if (!local_read(&local->open_count))
89367 goto wake_up;
89368
89369 /*
89370@@ -1696,7 +1696,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
89371 local->in_reconfig = false;
89372 barrier();
89373
89374- if (local->monitors == local->open_count && local->monitors > 0)
89375+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
89376 ieee80211_add_virtual_monitor(local);
89377
89378 /*
89379diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
89380index 56d22ca..87c778f 100644
89381--- a/net/netfilter/Kconfig
89382+++ b/net/netfilter/Kconfig
89383@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
89384
89385 To compile it as a module, choose M here. If unsure, say N.
89386
89387+config NETFILTER_XT_MATCH_GRADM
89388+ tristate '"gradm" match support'
89389+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
89390+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
89391+ ---help---
89392+ The gradm match allows to match on grsecurity RBAC being enabled.
89393+ It is useful when iptables rules are applied early on bootup to
89394+ prevent connections to the machine (except from a trusted host)
89395+ while the RBAC system is disabled.
89396+
89397 config NETFILTER_XT_MATCH_HASHLIMIT
89398 tristate '"hashlimit" match support'
89399 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
89400diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
89401index a1abf87..dbcb7ee 100644
89402--- a/net/netfilter/Makefile
89403+++ b/net/netfilter/Makefile
89404@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
89405 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
89406 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
89407 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
89408+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
89409 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
89410 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
89411 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
89412diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
89413index f771390..145b765 100644
89414--- a/net/netfilter/ipset/ip_set_core.c
89415+++ b/net/netfilter/ipset/ip_set_core.c
89416@@ -1820,7 +1820,7 @@ done:
89417 return ret;
89418 }
89419
89420-static struct nf_sockopt_ops so_set __read_mostly = {
89421+static struct nf_sockopt_ops so_set = {
89422 .pf = PF_INET,
89423 .get_optmin = SO_IP_SET,
89424 .get_optmax = SO_IP_SET + 1,
89425diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
89426index a083bda..da661c3 100644
89427--- a/net/netfilter/ipvs/ip_vs_conn.c
89428+++ b/net/netfilter/ipvs/ip_vs_conn.c
89429@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
89430 /* Increase the refcnt counter of the dest */
89431 ip_vs_dest_hold(dest);
89432
89433- conn_flags = atomic_read(&dest->conn_flags);
89434+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
89435 if (cp->protocol != IPPROTO_UDP)
89436 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
89437 flags = cp->flags;
89438@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
89439
89440 cp->control = NULL;
89441 atomic_set(&cp->n_control, 0);
89442- atomic_set(&cp->in_pkts, 0);
89443+ atomic_set_unchecked(&cp->in_pkts, 0);
89444
89445 cp->packet_xmit = NULL;
89446 cp->app = NULL;
89447@@ -1190,7 +1190,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
89448
89449 /* Don't drop the entry if its number of incoming packets is not
89450 located in [0, 8] */
89451- i = atomic_read(&cp->in_pkts);
89452+ i = atomic_read_unchecked(&cp->in_pkts);
89453 if (i > 8 || i < 0) return 0;
89454
89455 if (!todrop_rate[i]) return 0;
89456diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
89457index 23b8eb5..48a8959 100644
89458--- a/net/netfilter/ipvs/ip_vs_core.c
89459+++ b/net/netfilter/ipvs/ip_vs_core.c
89460@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
89461 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
89462 /* do not touch skb anymore */
89463
89464- atomic_inc(&cp->in_pkts);
89465+ atomic_inc_unchecked(&cp->in_pkts);
89466 ip_vs_conn_put(cp);
89467 return ret;
89468 }
89469@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
89470 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
89471 pkts = sysctl_sync_threshold(ipvs);
89472 else
89473- pkts = atomic_add_return(1, &cp->in_pkts);
89474+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89475
89476 if (ipvs->sync_state & IP_VS_STATE_MASTER)
89477 ip_vs_sync_conn(net, cp, pkts);
89478diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
89479index 9e6c2a0..28552e2 100644
89480--- a/net/netfilter/ipvs/ip_vs_ctl.c
89481+++ b/net/netfilter/ipvs/ip_vs_ctl.c
89482@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
89483 */
89484 ip_vs_rs_hash(ipvs, dest);
89485 }
89486- atomic_set(&dest->conn_flags, conn_flags);
89487+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
89488
89489 /* bind the service */
89490 if (!dest->svc) {
89491@@ -1657,7 +1657,7 @@ proc_do_sync_ports(ctl_table *table, int write,
89492 * align with netns init in ip_vs_control_net_init()
89493 */
89494
89495-static struct ctl_table vs_vars[] = {
89496+static ctl_table_no_const vs_vars[] __read_only = {
89497 {
89498 .procname = "amemthresh",
89499 .maxlen = sizeof(int),
89500@@ -2060,7 +2060,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
89501 " %-7s %-6d %-10d %-10d\n",
89502 &dest->addr.in6,
89503 ntohs(dest->port),
89504- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
89505+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
89506 atomic_read(&dest->weight),
89507 atomic_read(&dest->activeconns),
89508 atomic_read(&dest->inactconns));
89509@@ -2071,7 +2071,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
89510 "%-7s %-6d %-10d %-10d\n",
89511 ntohl(dest->addr.ip),
89512 ntohs(dest->port),
89513- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
89514+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
89515 atomic_read(&dest->weight),
89516 atomic_read(&dest->activeconns),
89517 atomic_read(&dest->inactconns));
89518@@ -2549,7 +2549,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
89519
89520 entry.addr = dest->addr.ip;
89521 entry.port = dest->port;
89522- entry.conn_flags = atomic_read(&dest->conn_flags);
89523+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
89524 entry.weight = atomic_read(&dest->weight);
89525 entry.u_threshold = dest->u_threshold;
89526 entry.l_threshold = dest->l_threshold;
89527@@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
89528 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
89529 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
89530 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
89531- (atomic_read(&dest->conn_flags) &
89532+ (atomic_read_unchecked(&dest->conn_flags) &
89533 IP_VS_CONN_F_FWD_MASK)) ||
89534 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
89535 atomic_read(&dest->weight)) ||
89536@@ -3682,7 +3682,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
89537 {
89538 int idx;
89539 struct netns_ipvs *ipvs = net_ipvs(net);
89540- struct ctl_table *tbl;
89541+ ctl_table_no_const *tbl;
89542
89543 atomic_set(&ipvs->dropentry, 0);
89544 spin_lock_init(&ipvs->dropentry_lock);
89545diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
89546index 5ea26bd..c9bc65f 100644
89547--- a/net/netfilter/ipvs/ip_vs_lblc.c
89548+++ b/net/netfilter/ipvs/ip_vs_lblc.c
89549@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
89550 * IPVS LBLC sysctl table
89551 */
89552 #ifdef CONFIG_SYSCTL
89553-static ctl_table vs_vars_table[] = {
89554+static ctl_table_no_const vs_vars_table[] __read_only = {
89555 {
89556 .procname = "lblc_expiration",
89557 .data = NULL,
89558diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
89559index 50123c2..067c773 100644
89560--- a/net/netfilter/ipvs/ip_vs_lblcr.c
89561+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
89562@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
89563 * IPVS LBLCR sysctl table
89564 */
89565
89566-static ctl_table vs_vars_table[] = {
89567+static ctl_table_no_const vs_vars_table[] __read_only = {
89568 {
89569 .procname = "lblcr_expiration",
89570 .data = NULL,
89571diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
89572index f6046d9..4f10cfd 100644
89573--- a/net/netfilter/ipvs/ip_vs_sync.c
89574+++ b/net/netfilter/ipvs/ip_vs_sync.c
89575@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
89576 cp = cp->control;
89577 if (cp) {
89578 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
89579- pkts = atomic_add_return(1, &cp->in_pkts);
89580+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89581 else
89582 pkts = sysctl_sync_threshold(ipvs);
89583 ip_vs_sync_conn(net, cp->control, pkts);
89584@@ -758,7 +758,7 @@ control:
89585 if (!cp)
89586 return;
89587 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
89588- pkts = atomic_add_return(1, &cp->in_pkts);
89589+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89590 else
89591 pkts = sysctl_sync_threshold(ipvs);
89592 goto sloop;
89593@@ -882,7 +882,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
89594
89595 if (opt)
89596 memcpy(&cp->in_seq, opt, sizeof(*opt));
89597- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
89598+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
89599 cp->state = state;
89600 cp->old_state = cp->state;
89601 /*
89602diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
89603index b75ff64..0c51bbe 100644
89604--- a/net/netfilter/ipvs/ip_vs_xmit.c
89605+++ b/net/netfilter/ipvs/ip_vs_xmit.c
89606@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
89607 else
89608 rc = NF_ACCEPT;
89609 /* do not touch skb anymore */
89610- atomic_inc(&cp->in_pkts);
89611+ atomic_inc_unchecked(&cp->in_pkts);
89612 goto out;
89613 }
89614
89615@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
89616 else
89617 rc = NF_ACCEPT;
89618 /* do not touch skb anymore */
89619- atomic_inc(&cp->in_pkts);
89620+ atomic_inc_unchecked(&cp->in_pkts);
89621 goto out;
89622 }
89623
89624diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
89625index 2d3030a..7ba1c0a 100644
89626--- a/net/netfilter/nf_conntrack_acct.c
89627+++ b/net/netfilter/nf_conntrack_acct.c
89628@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
89629 #ifdef CONFIG_SYSCTL
89630 static int nf_conntrack_acct_init_sysctl(struct net *net)
89631 {
89632- struct ctl_table *table;
89633+ ctl_table_no_const *table;
89634
89635 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
89636 GFP_KERNEL);
89637diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
89638index 0283bae..5febcb0 100644
89639--- a/net/netfilter/nf_conntrack_core.c
89640+++ b/net/netfilter/nf_conntrack_core.c
89641@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
89642 #define DYING_NULLS_VAL ((1<<30)+1)
89643 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
89644
89645+#ifdef CONFIG_GRKERNSEC_HIDESYM
89646+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
89647+#endif
89648+
89649 int nf_conntrack_init_net(struct net *net)
89650 {
89651 int ret;
89652@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
89653 goto err_stat;
89654 }
89655
89656+#ifdef CONFIG_GRKERNSEC_HIDESYM
89657+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
89658+#else
89659 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
89660+#endif
89661 if (!net->ct.slabname) {
89662 ret = -ENOMEM;
89663 goto err_slabname;
89664diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
89665index 1df1761..ce8b88a 100644
89666--- a/net/netfilter/nf_conntrack_ecache.c
89667+++ b/net/netfilter/nf_conntrack_ecache.c
89668@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
89669 #ifdef CONFIG_SYSCTL
89670 static int nf_conntrack_event_init_sysctl(struct net *net)
89671 {
89672- struct ctl_table *table;
89673+ ctl_table_no_const *table;
89674
89675 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
89676 GFP_KERNEL);
89677diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
89678index 974a2a4..52cc6ff 100644
89679--- a/net/netfilter/nf_conntrack_helper.c
89680+++ b/net/netfilter/nf_conntrack_helper.c
89681@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
89682
89683 static int nf_conntrack_helper_init_sysctl(struct net *net)
89684 {
89685- struct ctl_table *table;
89686+ ctl_table_no_const *table;
89687
89688 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
89689 GFP_KERNEL);
89690diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
89691index 0ab9636..cea3c6a 100644
89692--- a/net/netfilter/nf_conntrack_proto.c
89693+++ b/net/netfilter/nf_conntrack_proto.c
89694@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
89695
89696 static void
89697 nf_ct_unregister_sysctl(struct ctl_table_header **header,
89698- struct ctl_table **table,
89699+ ctl_table_no_const **table,
89700 unsigned int users)
89701 {
89702 if (users > 0)
89703diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
89704index a99b6c3..3841268 100644
89705--- a/net/netfilter/nf_conntrack_proto_dccp.c
89706+++ b/net/netfilter/nf_conntrack_proto_dccp.c
89707@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
89708 out_invalid:
89709 if (LOG_INVALID(net, IPPROTO_DCCP))
89710 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
89711- NULL, msg);
89712+ NULL, "%s", msg);
89713 return false;
89714 }
89715
89716@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
89717
89718 out_invalid:
89719 if (LOG_INVALID(net, IPPROTO_DCCP))
89720- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
89721+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
89722 return -NF_ACCEPT;
89723 }
89724
89725diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
89726index bd700b4..4a3dc61 100644
89727--- a/net/netfilter/nf_conntrack_standalone.c
89728+++ b/net/netfilter/nf_conntrack_standalone.c
89729@@ -471,7 +471,7 @@ static ctl_table nf_ct_netfilter_table[] = {
89730
89731 static int nf_conntrack_standalone_init_sysctl(struct net *net)
89732 {
89733- struct ctl_table *table;
89734+ ctl_table_no_const *table;
89735
89736 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
89737 GFP_KERNEL);
89738diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
89739index 902fb0a..87f7fdb 100644
89740--- a/net/netfilter/nf_conntrack_timestamp.c
89741+++ b/net/netfilter/nf_conntrack_timestamp.c
89742@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
89743 #ifdef CONFIG_SYSCTL
89744 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
89745 {
89746- struct ctl_table *table;
89747+ ctl_table_no_const *table;
89748
89749 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
89750 GFP_KERNEL);
89751diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
89752index 3b18dd1..f79e0ca 100644
89753--- a/net/netfilter/nf_log.c
89754+++ b/net/netfilter/nf_log.c
89755@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
89756
89757 #ifdef CONFIG_SYSCTL
89758 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
89759-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
89760+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
89761
89762 static int nf_log_proc_dostring(ctl_table *table, int write,
89763 void __user *buffer, size_t *lenp, loff_t *ppos)
89764@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
89765 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
89766 mutex_unlock(&nf_log_mutex);
89767 } else {
89768+ ctl_table_no_const nf_log_table = *table;
89769+
89770 mutex_lock(&nf_log_mutex);
89771 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
89772 lockdep_is_held(&nf_log_mutex));
89773 if (!logger)
89774- table->data = "NONE";
89775+ nf_log_table.data = "NONE";
89776 else
89777- table->data = logger->name;
89778- r = proc_dostring(table, write, buffer, lenp, ppos);
89779+ nf_log_table.data = logger->name;
89780+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
89781 mutex_unlock(&nf_log_mutex);
89782 }
89783
89784diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
89785index f042ae5..30ea486 100644
89786--- a/net/netfilter/nf_sockopt.c
89787+++ b/net/netfilter/nf_sockopt.c
89788@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
89789 }
89790 }
89791
89792- list_add(&reg->list, &nf_sockopts);
89793+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
89794 out:
89795 mutex_unlock(&nf_sockopt_mutex);
89796 return ret;
89797@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
89798 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
89799 {
89800 mutex_lock(&nf_sockopt_mutex);
89801- list_del(&reg->list);
89802+ pax_list_del((struct list_head *)&reg->list);
89803 mutex_unlock(&nf_sockopt_mutex);
89804 }
89805 EXPORT_SYMBOL(nf_unregister_sockopt);
89806diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
89807index 962e979..d4ae2e9 100644
89808--- a/net/netfilter/nfnetlink_log.c
89809+++ b/net/netfilter/nfnetlink_log.c
89810@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
89811 struct nfnl_log_net {
89812 spinlock_t instances_lock;
89813 struct hlist_head instance_table[INSTANCE_BUCKETS];
89814- atomic_t global_seq;
89815+ atomic_unchecked_t global_seq;
89816 };
89817
89818 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
89819@@ -559,7 +559,7 @@ __build_packet_message(struct nfnl_log_net *log,
89820 /* global sequence number */
89821 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
89822 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
89823- htonl(atomic_inc_return(&log->global_seq))))
89824+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
89825 goto nla_put_failure;
89826
89827 if (data_len) {
89828diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
89829new file mode 100644
89830index 0000000..c566332
89831--- /dev/null
89832+++ b/net/netfilter/xt_gradm.c
89833@@ -0,0 +1,51 @@
89834+/*
89835+ * gradm match for netfilter
89836